Jump to content

[1.7.10]Break block not working


slugslug

Recommended Posts

when i break my custom furnace the inventory does not not drop i have the break block method filled out.

 

Furnace

 

 


package com.professorvennie.core.block;

import java.util.Random;

import com.professorvennie.api.book.BookEntry;
import com.professorvennie.core.lib.BlockNames;
import com.professorvennie.core.lib.BookData;
import com.professorvennie.core.lib.Reference;
import com.professorvennie.core.main.MachineryCraft;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;

import com.professorvennie.core.block.tileEntity.TileEntitySaltFurnace;
import com.professorvennie.core.lib.LibGuiIds;

import cpw.mods.fml.common.network.internal.FMLNetworkHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class BlockSaltFurnace extends BlockBasicMachine{

public BlockSaltFurnace(boolean isActive) {
	super(BlockNames.SaltFurnace, isActive);
}

public Item getItemDropped(int par1, Random random, int par2) {
	return Item.getItemFromBlock(ModBlocks.SaltFurnaceIdle);
}

@Override
public TileEntity createNewTileEntity(World world, int var2) {
	return new TileEntitySaltFurnace();
}

    @SideOnly(Side.CLIENT)
    @Override
    public void registerBlockIcons(IIconRegister iiconRegister) {
        this.blockIcon = iiconRegister.registerIcon(Reference.MOD_ID + ":" + "saltFurnace_side");
        this.iconFront = iiconRegister.registerIcon(Reference.MOD_ID + ":" + (this.isActive ? "saltFurnace_front_on" : "saltFurnace_front_off"));
    }

    public boolean onBlockActivated(World world, int x, int y, int z,EntityPlayer player, int side, float hitx, float hity, float hitz) {
        if (!world.isRemote) {
            FMLNetworkHandler.openGui(player, MachineryCraft.instance, LibGuiIds.GUIID_SALTFURNACE, world, x, y, z);
        }
        return true;
    }

public boolean hasComparatorInputOverride() {
	return true;
}

@Override
public Item getItem(World world, int x, int y, int z) {
	return Item.getItemFromBlock(ModBlocks.SaltFurnaceIdle);
}

    @Override
    public BookEntry getEntry(World world, int x, int y, int z, EntityPlayer player, ItemStack lexicon) {
        return BookData.firstTierMachines;
    }

    public void breakBlock(World world, int x, int y, int z, Block block, int side){
        if(!keepInventory) {
            TileEntitySaltFurnace tileEntitySaltFurnace = (TileEntitySaltFurnace) world.getTileEntity(x, y, z);

            if (tileEntitySaltFurnace != null) {
                for (int i = 0; i < tileEntitySaltFurnace.getSizeInventory(); i++) {
                    ItemStack itemStack = tileEntitySaltFurnace.getStackInSlot(i);

                    if (itemStack != null) {
                        float f = this.rand.nextFloat() * 0.6F + 01F;//x
                        float f1 = this.rand.nextFloat() * 0.6F + 01F;//y
                        float f2 = this.rand.nextFloat() * 0.6F + 01F;//z

                        while (itemStack.stackSize > 0) {
                            int j = this.rand.nextInt(21) + 10;

                            if (j > itemStack.stackSize) {
                                j = itemStack.stackSize;
                            }

                            itemStack.stackSize -= j;
                            EntityItem entityItem = new EntityItem(world, (double) ((float) x + f), (double) ((float) y + f1), (double) ((float) z + f2), new ItemStack(itemStack.getItem(), j, itemStack.getItemDamage()));

                            if (itemStack.hasTagCompound()) {
                                entityItem.getEntityItem().setTagCompound((NBTTagCompound) itemStack.getTagCompound().copy());
                            }

                            float f3 = 0.025F;
                            entityItem.motionX = (double) ((float) this.rand.nextGaussian() * f3);
                            entityItem.motionY = (double) ((float) this.rand.nextGaussian() * f3 + 0.1F);
                            entityItem.motionZ = (double) ((float) this.rand.nextGaussian() * f3);

                            world.spawnEntityInWorld(entityItem);
                        }
                    }
                }
                world.func_147453_f(x, y, z, block);
            }
        }
        super.breakBlock(world, x, y, z, block, side);
    }
}

 

 

 

basic machine

 

 


package com.professorvennie.core.block;

import com.professorvennie.api.book.BookEntry;
import com.professorvennie.api.book.IBookable;
import com.professorvennie.core.block.tileEntity.TileEntitySaltFurnace;
import com.professorvennie.core.main.MachineryCraft;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;

import java.util.Random;

public class BlockBasicMachine extends BlockContainer implements IBookable{

    private static String Name;
    @SideOnly(Side.CLIENT)
    public IIcon iconFront;
    public boolean isActive;
    public static boolean keepInventory;
    public final Random rand = new Random();


    public BlockBasicMachine(String name, boolean isActive) {
        super(Material.iron);
        Name = name;
        this.isActive = isActive;
        if(isActive){
            setLightLevel(0.9F);
            setBlockName(name + "Active");
        }else if(!isActive){
            setCreativeTab(MachineryCraft.tabMachineryCraft);
            setBlockName(name + "Idle");
        }
    }

    @SideOnly(Side.CLIENT)
    public IIcon getIcon(int side, int metadata) {
        return metadata == 0 && side == 3 ? this.iconFront : (side == metadata ? this.iconFront : this.blockIcon);
    }

    public TileEntity createNewTileEntity(World world, int i) {
        return null;
    }

    public void onBlockAdded(World world, int x, int y, int z) {
        super.onBlockAdded(world, x, y, z);
        this.setDefualtDirection(world, x, y, z);
    }

    private void setDefualtDirection(World world, int x, int y, int z) {
        if (!world.isRemote) {
            Block l = world.getBlock(x, y, z - 1);
            Block il = world.getBlock(x, y, z + 1);
            Block jl = world.getBlock(x - 1, y, z);
            Block kl = world.getBlock(x + 1, y, z - 1);
            byte b0 = 3;

            if (l.isNormalCube() && !il.isNormalCube()) {
                b0 = 3;
            }

            if (il.isNormalCube() && !l.isNormalCube()) {
                b0 = 2;
            }

            if (kl.isNormalCube() && !jl.isNormalCube()) {
                b0 = 5;
            }

            if (jl.isNormalCube() && !kl.isNormalCube()) {
                b0 = 4;
            }
            world.setBlockMetadataWithNotify(x, y, z, b0, 2);

        }
    }

    public void onBlockPlacedBy(World world, int x, int y, int z,
        EntityLivingBase entityLivingBase, ItemStack itemstack) {
        int l = MathHelper.floor_double((double) (entityLivingBase.rotationYaw * 4.0f / 360.0f) + 0.5D) & 3;

        if (l == 0) {
            world.setBlockMetadataWithNotify(x, y, z, 2, 2);
        }

        if (l == 1) {
            world.setBlockMetadataWithNotify(x, y, z, 5, 2);
        }

        if (l == 2) {
            world.setBlockMetadataWithNotify(x, y, z, 3, 2);
        }

        if (l == 3) {
            world.setBlockMetadataWithNotify(x, y, z, 4, 2);
        }

        if (itemstack.hasDisplayName()) {
            ((TileEntitySaltFurnace) world.getTileEntity(x, y, z)).setGuiDisplayName(itemstack.getDisplayName());
        }
    }
    public static void updateBlockState(boolean active, World worldObj, int xCoord, int yCoord, int zCoord, Block blockActive, Block blockIdle) {
        int i = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
        TileEntity tileentity = worldObj.getTileEntity(xCoord, yCoord, zCoord);
        keepInventory = true;

        if (active) {
            worldObj.setBlock(xCoord, yCoord, zCoord, blockActive);
        } else {
            worldObj.setBlock(xCoord, yCoord, zCoord, blockIdle);
        }

        keepInventory = false;

        worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, i, 2);

        if (tileentity != null) {
            tileentity.validate();
            worldObj.setTileEntity(xCoord, yCoord, zCoord, tileentity);
        }
    }

    @SideOnly(Side.CLIENT)
    public void randomDisplayTick(World world, int x, int y, int z,
                                  Random random) {
        if (this.isActive) {
            int direction = world.getBlockMetadata(x, y, z);

            float x1 = (float) x + 0.5F;
            float y1 = (float) y + random.nextFloat();
            float z1 = (float) z + 0.5F;

            float f = 0.52F;
            float f1 = random.nextFloat() * 0.6F - 0.3F;

            if (direction == 4) {
                world.spawnParticle("smoke", (double) (x1 - f), (double) (y1), (double) (z1 + f1), 0.0D, 0.0D, 0.0D);
                world.spawnParticle("flame", (double) (x1 - f), (double) (y1), (double) (z1 + f1), 0.0D, 0.0D, 0.0D);
            } else if (direction == 5) {
                world.spawnParticle("smoke", (double) (x1 + f), (double) (y1), (double) (z1 + f1), 0.0D, 0.0D, 0.0D);
                world.spawnParticle("flame", (double) (x1 + f), (double) (y1), (double) (z1 + f1), 0.0D, 0.0D, 0.0D);
            } else if (direction == 2) {
                world.spawnParticle("smoke", (double) (x1 + f1), (double) (y1), (double) (z1 - f), 0.0D, 0.0D, 0.0D);
                world.spawnParticle("flame", (double) (x1 + f1), (double) (y1), (double) (z1 - f), 0.0D, 0.0D, 0.0D);
            } else if (direction == 3) {
                world.spawnParticle("smoke", (double) (x1 + f1), (double) (y1), (double) (z1 + f), 0.0D, 0.0D, 0.0D);
                world.spawnParticle("flame", (double) (x1 + f1), (double) (y1), (double) (z1 + f), 0.0D, 0.0D, 0.0D);
            }
        }
    }

    public void breakBlock(World world, int x, int y, int z, Block block, int side){
        //todo
//        if (!keepInventory)
//        {
//            TileEntitySaltFurnace TileEntitySaltFurnace = (TileEntitySaltFurnace)world.getTileEntity(x, y, z);
//
//            if (TileEntitySaltFurnace != null)
//            {
//                for (int i1 = 0; i1 < TileEntitySaltFurnace.getSizeInventory(); ++i1)
//                {
//                    ItemStack itemstack = TileEntitySaltFurnace.getStackInSlot(i1);
//
//                    if (itemstack != null)
//                    {
//                        float f = this.rand.nextFloat() * 0.8F + 0.1F;
//                        float f1 = this.rand.nextFloat() * 0.8F + 0.1F;
//                        float f2 = this.rand.nextFloat() * 0.8F + 0.1F;
//
//                        while (itemstack.stackSize > 0)
//                        {
//                            int j1 = this.rand.nextInt(21) + 10;
//
//                            if (j1 > itemstack.stackSize)
//                            {
//                                j1 = itemstack.stackSize;
//                            }
//
//                            itemstack.stackSize -= j1;
//                            EntityItem entityitem = new EntityItem(world, (double)((float)x + f), (double)((float)y + f1), (double)((float)z + f2), new ItemStack(itemstack.getItem(), j1, itemstack.getItemDamage()));
//
//                            if (itemstack.hasTagCompound())
//                            {
//                                entityitem.getEntityItem().setTagCompound((NBTTagCompound)itemstack.getTagCompound().copy());
//                            }
//
//                            float f3 = 0.05F;
//                            entityitem.motionX = (double)((float)this.rand.nextGaussian() * f3);
//                            entityitem.motionY = (double)((float)this.rand.nextGaussian() * f3 + 0.2F);
//                            entityitem.motionZ = (double)((float)this.rand.nextGaussian() * f3);
//                            world.spawnEntityInWorld(entityitem);
//                        }
//                    }
//                }
//
//                world.func_147453_f(x, y, z, block);
//            }
//        }
//
//        super.breakBlock(world, x, y, z, block, side);
    }

    @Override
    public BookEntry getEntry(World world, int x, int y, int z, EntityPlayer player, ItemStack lexicon) {
        return null;
    }
}
[/spoiler]

 

tileentity

 

 

 


package com.professorvennie.core.block.tileEntity;


import com.professorvennie.core.block.ModBlocks;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.Item;

import net.minecraft.item.ItemStack;

import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.Constants;

import com.professorvennie.core.block.BlockSaltFurnace;
import com.professorvennie.core.item.ModItems;

import cpw.mods.fml.common.registry.GameRegistry;

public class TileEntitySaltFurnace extends TileEntity implements ISidedInventory{

private String localizedName;

private static final int[] slots_top = new int[]{0};
private static final int[] slots_bottom = new int[]{2, 1};
private static final int[] slots_sides = new int[]{1};

private ItemStack[] slots = new ItemStack[3];

public int furnaceSpeed = 100;

public int burnTime;

public int currentItemBurnTime;

public int cookTime;

private int smeltItem;

public int getsizeInventory(){
	return this.slots.length;
}

public String getInvName(){
	return this.isInvNameLocalized() ? this.localizedName : "container.saltfurnace";
}

public boolean isInvNameLocalized(){
	return this.localizedName != null && this.localizedName.length() > 0;
}

public void setGuiDisplayName(String displayName) {

	this.localizedName= displayName;
}

@Override
public int getSizeInventory() {
	return 0;
}

@Override
public ItemStack getStackInSlot(int var1) {
	return this.slots[var1];
}

@Override
public ItemStack decrStackSize(int var1, int var2) {
	if(this.slots[var1] != null){
		ItemStack itemstack;
		if(this.slots[var1].stackSize <= var2){
			itemstack = this.slots[var1];
			this.slots[var1] = null;
			return itemstack;
		}else{
			itemstack = this.slots[var1].splitStack(var2);
			if(this.slots[var1].stackSize == 0){
				this.slots[var1] = null;
			}
			return itemstack;
		}
	}
	return null;
}

@Override
public ItemStack getStackInSlotOnClosing(int var1) {
	if(this.slots[var1] != null){
		ItemStack itemstack = this.slots[var1];
		this.slots[var1] = null;
		return itemstack;
	}

	return null;
}

@Override
public void setInventorySlotContents(int var1, ItemStack var2) {
	this.slots[var1]= var2;

	if(var2 != null && var2.stackSize > this.getInventoryStackLimit()){
		var2.stackSize = this.getInventoryStackLimit();
	}
}

@Override
public String getInventoryName() {
	// TODO Auto-generated method stub
	return null;
}

@Override
public boolean hasCustomInventoryName() {
	// TODO Auto-generated method stub
	return false;
}

@Override
public int getInventoryStackLimit() {
	// TODO Auto-generated method stub
	return 64;
}

public void readFromNBT(NBTTagCompound nbt){
	super.readFromNBT(nbt);

	NBTTagList list = nbt.getTagList("items", Constants.NBT.TAG_COMPOUND);
	this.slots = new ItemStack[this.getsizeInventory()];

	for(int i = 0; i < list.tagCount(); i ++){
		NBTTagCompound compound = list.getCompoundTagAt(i);
		 int j = compound.getByte("slot") & 0xff;

		if(j >= 0 && j < this.slots.length){
			this.slots[j] = ItemStack.loadItemStackFromNBT(compound);

		}
	}
	this.burnTime = (int)nbt.getShort("burntime");
	this.cookTime = (int)nbt.getShort("cooktime");
	this.currentItemBurnTime = (int)nbt.getShort("currentItemBurnTime");

	if(nbt.hasKey("customname")){
		this.localizedName = nbt.getString("customname");
	}

}

public void writeToNBT(NBTTagCompound nbt){
	super.writeToNBT(nbt);

	nbt.setShort("burntime", (short) this.burnTime);
	nbt.setShort("cooktime", (short) this.cookTime);
	nbt.setShort("currentItemBurnTime", (short) this.currentItemBurnTime);

	NBTTagList list = new NBTTagList();

	for(int i = 0; i < this.slots.length; i ++){
		if(this.slots[i] != null){
			NBTTagCompound compound = new NBTTagCompound();
			compound.setByte("slot", (byte) i);
			this.slots[i].writeToNBT(compound);
			list.appendTag(compound);
		}
	}
	nbt.setTag("items", list);
	if(this.isInvNameLocalized()){
		nbt.setString("customname", this.localizedName);
	}
}

@Override
public boolean isUseableByPlayer(EntityPlayer var1) {
	return this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : var1.getDistanceSq((double)this.xCoord + 0.5D, (double)this.yCoord + 0.5D, (double)this.zCoord + 0.5D) <= 64D;
}

@Override
public void openInventory() {
	// TODO Auto-generated method stub

}

@Override
public void closeInventory() {
	// TODO Auto-generated method stub

}

public boolean isBurning(){
	return this.burnTime > 0;
}

public void updateEntity(){
	boolean flag = this.burnTime > 0;
	boolean flag1 = false;

	if(this.burnTime > 0){
		this.burnTime--;
	}

	if(!this.worldObj.isRemote){
		if(this.burnTime == 0 && this.canSmelt()){
			this.currentItemBurnTime = this.burnTime = getItemBurnTime(this.slots[1]);

			if(this.burnTime > 0){
				flag1 = true;

				if(this.slots[1] != null){
					this.slots[1].stackSize--;

					if(this.slots[1].stackSize == 0){
						this.slots[1] = this.slots[1].getItem().getContainerItem(this.slots[1]);
					}
				}
			}

			}
		if(this.isBurning() && this.canSmelt()){
			this.cookTime++;

			if(this.cookTime == this.furnaceSpeed){
				this.cookTime = 0;
				this.smeltItem();
				flag1 = true;
			}
		}else{
			this.cookTime = 0;
		}

		if(flag != this.isBurning()){
			flag1 = true;
			BlockSaltFurnace.updateBlockState(this.burnTime > 0, this.worldObj, this.xCoord, this.yCoord, this.zCoord, ModBlocks.SaltFurnaceActive, ModBlocks.SaltFurnaceIdle);
		}

	}


if(flag1){
	this.markDirty();
}
}

private boolean canSmelt(){
	if(this.slots[0] == null){
		return false;
	}else{
		ItemStack itemstack = FurnaceRecipes.smelting().getSmeltingResult(this.slots[0]);

		if(itemstack == null) return false;
		if(this.slots[2] == null) return true;
		if(!this.slots[2].isItemEqual(itemstack)) return false;

		int result = this.slots[2].stackSize + itemstack.stackSize;

		return (result <= getInventoryStackLimit() && result <= itemstack.getMaxStackSize());


	}
}

public void smeltItem(){
	if(this.canSmelt()){
		ItemStack itemstack = FurnaceRecipes.smelting().getSmeltingResult(this.slots[0]);

		if(this.slots[2] == null){
			this.slots[2] = itemstack.copy();
		}else if(this.slots[2].isItemEqual(itemstack)){
			this.slots[2].stackSize += itemstack.stackSize;
		}

		this.slots[0].stackSize--;

		if(this.slots[0].stackSize <= 0){
			this.slots[0] = null;
	}
}
}

public static int getItemBurnTime(ItemStack itemstack){
	if(itemstack == null){
		return 0;
	}else{
		int i = itemstack.getItem().getIdFromItem(itemstack.getItem());

		Item item = itemstack.getItem();
		/*
		if(item instanceof ItemBlock && Block.blockRegistry != null){
			Block block = blockRegistry;

			if(block == Blocks.wooden_slab){
				return 150;
			}
			if(block.getMaterial().equals(Material.wood)){
				return 300;
			}

			if(block == Blocks.coal_block){
				return 16000;
			}
		*/

		//if(item instanceof ItemTool && ((ItemTool) item).getToolMaterialName().equals("WOOD")) return 200;
		//if(item instanceof ItemSword && ((ItemSword) item).getToolMaterialName().equals("WOOD")) return 200;
		//if(item instanceof ItemHoe && ((ItemHoe) item).getToolMaterialName().equals("WOOD")) return 200;
		//if(i == Items.stick.getIdFromItem(Items.stick)) return 100;
		if(i == Items.coal.getIdFromItem(Items.coal)) return 1600;
		if(i == Items.lava_bucket.getIdFromItem(Items.lava_bucket)) return 20000;
		//if(i == Blocks.sapling.getIdFromBlock(Blocks.sapling)) return 100;
		if(i == Blocks.coal_block.getIdFromBlock(Blocks.coal_block)) return 16000;
		//if(i == Blocks.wooden_slab.getIdFromBlock(Blocks.wooden_slab)) return 300;
		if(i == Items.blaze_rod.getIdFromItem(Items.blaze_rod)) return 2400;


		if(i == ModItems.saltcyrstals.getIdFromItem(ModItems.saltcyrstals)) return 500;

		return GameRegistry.getFuelValue(itemstack);
	}
}

public static boolean isItemFuel(ItemStack itemstack){
	return getItemBurnTime(itemstack) > 0;
}

@Override
public boolean isItemValidForSlot(int var1, ItemStack var2) {

	return var1 == 2 ? false : (var1 == 1 ? isItemFuel(var2) : true);
}

@Override
public int[] getAccessibleSlotsFromSide(int var1) {
	return var1 == 0 ? slots_bottom  : (var1 == 1 ? slots_top : slots_sides);
}

@Override
public boolean canInsertItem(int var1, ItemStack var2, int var3) {
	return this.isItemValidForSlot(var1, var2);
}

@Override
public boolean canExtractItem(int var1, ItemStack var2, int var3) {
	return var3 != 0 || var1 != 1 || var2.getItem() == Items.bucket;
}

public int getBurnTimeReamingScaled(int i) {
	if(this.currentItemBurnTime == 0){
		this.currentItemBurnTime = this.furnaceSpeed;
	}

	return this.burnTime * i / this.currentItemBurnTime;
}

public int getCookProgressSacled(int i){
	return this.cookTime * i / this.furnaceSpeed;
}
}

 

 

 

 

 

Link to comment
Share on other sites

I also found another problem.  When you break a furnace with something in the slots and place a new furnace in the same spot it will have the same inventory of the previous furnace that i broke.  Is that because of the break block method not working?

Link to comment
Share on other sites

We'll I got rid of the one method and made sure it over ride the getInventorySize and returned this.slots.lenght.  It now drops the item in the slots but when you replace a furnace in the same spot it will have one of that item or block in that slot.  If you break the furnace it does not drop but you can take that item out.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.