Created
December 30, 2013 21:44
-
-
Save anonymous/8188707 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package fr.Knux14.Electools.Block; | |
import ic2.api.energy.EnergyNet; | |
import java.util.Random; | |
import net.minecraft.block.BlockContainer; | |
import net.minecraft.block.material.Material; | |
import net.minecraft.client.renderer.texture.IconRegister; | |
import net.minecraft.entity.item.EntityItem; | |
import net.minecraft.entity.player.EntityPlayer; | |
import net.minecraft.inventory.IInventory; | |
import net.minecraft.item.ItemStack; | |
import net.minecraft.nbt.NBTTagCompound; | |
import net.minecraft.tileentity.TileEntity; | |
import net.minecraft.world.World; | |
import cpw.mods.fml.relauncher.Side; | |
import cpw.mods.fml.relauncher.SideOnly; | |
import fr.Knux14.Electools.Electools; | |
import fr.Knux14.Electools.Vars; | |
import fr.Knux14.Electools.TileEntity.TileEntityTeleportBlock; | |
public class BlockTeleport extends BlockContainer { | |
public BlockTeleport(int par1) { | |
super(par1, Material.iron); | |
setCreativeTab(Electools.tab); | |
setHardness(2F); | |
setUnlocalizedName("TeleporterBlock"); | |
} | |
@Override | |
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int metadata, float what, float these, float are) { | |
TileEntity tileEntity = world.getBlockTileEntity(x, y, z); | |
if (tileEntity == null || player.isSneaking()) { | |
return false; | |
} | |
player.openGui(Electools.instance, 1, world, x, y, z); | |
return true; | |
} | |
@Override | |
public TileEntity createNewTileEntity(World world) { | |
return null; | |
} | |
@Override | |
public TileEntity createTileEntity(World world, int meta) { | |
return new TileEntityTeleportBlock(); | |
} | |
@Override | |
@SideOnly(Side.CLIENT) | |
public void registerIcons(IconRegister iconRegister) | |
{ | |
this.blockIcon = iconRegister.registerIcon(Vars.modid.toLowerCase() + ":" + this.getUnlocalizedName().substring(5)); | |
} | |
@Override | |
public void breakBlock(World world, int x, int y, int z, int par5, int par6) { | |
TileEntityTeleportBlock tile = (TileEntityTeleportBlock) world.getBlockTileEntity(x, y, z); | |
dropItems(world, tile); | |
super.breakBlock(world, x, y, z, par5, par6); | |
} | |
private void dropItems(World world, TileEntityTeleportBlock tile){ | |
Random random = new Random(); | |
for (int l = 0; l < tile.getSizeInventory(); l++) { | |
ItemStack itemstack = tile.getStackInSlot(l); | |
if (itemstack == null) { | |
continue; | |
} | |
float f = random.nextFloat() * 0.8F + 0.1F; | |
float f1 = random.nextFloat() * 0.8F + 0.1F; | |
float f2 = random.nextFloat() * 0.8F + 0.1F; | |
while (itemstack.stackSize > 0) { | |
int i1 = random.nextInt(21) + 10; | |
if (i1 > itemstack.stackSize) { | |
i1 = itemstack.stackSize; | |
} | |
itemstack.stackSize -= i1; | |
EntityItem entityitem = new EntityItem(world, tile.xCoord + f, tile.yCoord + f1, tile.zCoord + f2, new ItemStack(itemstack.itemID, i1, itemstack.getItemDamage())); | |
float f3 = 0.05F; | |
entityitem.motionX = ((float)random.nextGaussian() * f3); | |
entityitem.motionY = ((float)random.nextGaussian() * f3 + 0.2F); | |
entityitem.motionZ = ((float)random.nextGaussian() * f3); | |
if (itemstack.hasTagCompound()) { | |
entityitem.getEntityItem().setTagCompound((NBTTagCompound)itemstack.getTagCompound().copy()); | |
} | |
world.spawnEntityInWorld(entityitem); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment