Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package phnxflms.unidye;
- 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.creativetab.CreativeTabs;
- 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 ic2.api.energy.prefab.BasicSink;
- import ic2.api.tile.IWrenchable;
- import phnxflms.unidye.TileEntityWoolDyer;
- public class BlockWoolDyer extends BlockContainer {
- public BlockWoolDyer(int id, Material material) {
- super(id, material);
- this.setCreativeTab(CreativeTabs.tabBlock);
- }
- @Override
- public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9){
- if(world.isRemote) return true;
- TileEntityWoolDyer te = (TileEntityWoolDyer) world.getBlockTileEntity(x, y , z);
- if (te != null){
- if (player.isSneaking()) {
- te.ic2EnergySink.setEnergyStored(0.0D);
- te.woolCount++;
- }
- player.addChatMessage("Current Energy: " + te.ic2EnergySink.getEnergyStored());
- player.addChatMessage("WoolCount: " + te.woolCount);
- player.openGui(Unidye.instance, 0, world, x, y, z);
- }
- return true;
- }
- @SideOnly(Side.CLIENT) //Only done client-side
- public void registerIcons(IconRegister par1IconRegister)//Assigns a texture
- {
- this.blockIcon = par1IconRegister.registerIcon(Unidye.modid + ":" + (this.getUnlocalizedName().substring(5)));
- }
- @Override
- public TileEntity createNewTileEntity(World world) {
- return null;
- }
- @Override
- public TileEntity createTileEntity(World world, int meta) {
- return new TileEntityWoolDyer();
- }
- @Override
- public void breakBlock(World world, int x, int y, int z, int par5, int par6) {
- dropItems(world, x, y, z);
- super.breakBlock(world, x, y, z, par5, par6);
- }
- private void dropItems(World world, int x, int y, int z){
- Random rand = new Random();
- TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
- if (!(tileEntity instanceof IInventory)) {
- return;
- }
- IInventory inventory = (IInventory) tileEntity;
- for (int i = 0; i < inventory.getSizeInventory(); i++) {
- ItemStack item = inventory.getStackInSlot(i);
- if (item != null && item.stackSize > 0) {
- float rx = rand.nextFloat() * 0.8F + 0.1F;
- float ry = rand.nextFloat() * 0.8F + 0.1F;
- float rz = rand.nextFloat() * 0.8F + 0.1F;
- EntityItem entityItem = new EntityItem(world,
- x + rx, y + ry, z + rz,
- new ItemStack(item.itemID, item.stackSize, item.getItemDamage()));
- if (item.hasTagCompound()) {
- entityItem.getEntityItem().setTagCompound((NBTTagCompound) item.getTagCompound().copy());
- }
- float factor = 0.05F;
- entityItem.motionX = rand.nextGaussian() * factor;
- entityItem.motionY = rand.nextGaussian() * factor + 0.2F;
- entityItem.motionZ = rand.nextGaussian() * factor;
- world.spawnEntityInWorld(entityItem);
- item.stackSize = 0;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement