Jump to content

[unsolved] strange bug with my tileEntity


tomtomtom0909

Recommended Posts

Hi I don't normally ask for help but after updating CampCraft to 1.3 I've been hit by a few strange bugs which I think its caused by the new lan feature in minecraft.

 

I made some pictures illustrating the bug as I'm dyslexic I'm not the best at explaining things :D

 

The real diamond spade and iron hammer

H6MXZ.png

 

I place both diamond spade and iron hammer in the right slots but creates duplicate items and I'm still left with the real items in the purple boxes *when the duplicate items are clicked they disappear.

VNFeL.png

 

The repairing still happens and the diamond spade is repaired but creates a duplicate spade which when clicked/shift clicked disappears as well.

vY56b.png

 

The main code *not all the code. left out the code for the anvil but can post more if needed

 

CampCraft

 

 

package CampCraft;

 

@Mod( modid = "CampCraft", name="CampCraftMod", version="[1.3.2] CampCraft ModPack V 1.01")

 

@NetworkMod(

    clientSideRequired = true,

    serverSideRequired = false,

    channels = {"CampCraftMod"},

    packetHandler = PacketHandler.class

    //connectionHandler = yourConnectionHandler.class,  // TODO

    //versionBounds = "[1.3]"

    )

 

public class CampCraft

{

@SidedProxy(clientSide = "CampCraft.ClientProxy", serverSide = "CampCraft.CommonProxy")

 

public static CommonProxy proxy;

 

@Instance

public static CampCraft instance;

   

@Init

public void load(FMLInitializationEvent evt)

{

NetworkRegistry.instance().registerGuiHandler(this, new GuiHandler());

proxy.initializeEntityRendering();

loadAnvil();

}

 

public void loadAnvil()

{

//Anvil

Anvil = (new BlockAnvil(500, 16, TileEntityAnvil.class)).setHardness(0.5F).setResistance(10F).setBlockName("Anvil");

 

                        AnvilItem = (new ItemAnvil(5000, Anvil)).setIconCoord(4, 1).setItemName("AnvilItem");   

LanguageRegistry.addName(AnvilItem, "Anvil");

}

 

 

 

 

ClientProxy

 

 

package CampCraft;

 

public class ClientProxy extends CommonProxy

{

 

public void initializeEntityRendering()

{

TileEntityAnvilRenderer anvilRenderer = new TileEntityAnvilRenderer();

ClientRegistry.registerTileEntity(TileEntityAnvil.class, "TileEntityAnvil", anvilRenderer);

}

 

    @Override

public World getClientWorld()

    {

return Minecraft.getMinecraft().theWorld;

}

   

    @Override

public EntityPlayer getClientPlayer()

    {

return Minecraft.getMinecraft().thePlayer;

}

}

 

 

 

GuiHandler

 

 

package CampCraft;

 

public class GuiHandler implements IGuiHandler

{

 

@Override

public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)

{

if (!world.blockExists(x, y, z))

{

return null;

}

else

{

if(ID == 1)

{

TileEntityAnvil tileAnvil = (TileEntityAnvil)world.getBlockTileEntity(x, y, z);

return new ContainerAnvil(player.inventory, tileAnvil);

}

else

{

return null;

}

}

}

 

@Override

public Object getClientGuiElement(int ID, EntityPlayer player, World world,int x, int y, int z)

{

if (!world.blockExists(x, y, z))

{

return null;

}

else

{

if(ID == 1)

{

TileEntityAnvil tileAnvil = (TileEntityAnvil)world.getBlockTileEntity(x, y, z);

return new GuiAnvil(player.inventory, tileAnvil);

}

else

{

return null;

}

}

}

 

}

 

 

 

Anvil Container

 

 

package CampCraft.common.AnvilPart;

 

public class ContainerAnvil extends Container

{

  private TileEntityAnvil anvil;

    private int RepairTime = 0;

    private int HammerTime = 0;

    private int temp = 0;

 

public ContainerAnvil(InventoryPlayer inventoryplayer, TileEntityAnvil tileentityanvil)

    {       

        anvil = tileentityanvil;

        addSlotToContainer(new Slot(tileentityanvil, 0, 48, 17)); //Item to Repair

        addSlotToContainer(new Slot(tileentityanvil, 1, 74, 42)); //Hammer 

        addSlotToContainer(new SlotAnvilOutput(inventoryplayer.player, tileentityanvil, 2, 137, 35));//Item Created

        addSlotToContainer(new Slot(tileentityanvil, 3, 22, 42)); //Material

       

        int var3;

 

        for (var3 = 0; var3 < 3; ++var3)

        {

            for (int var4 = 0; var4 < 9; ++var4)

            {

                this.addSlotToContainer(new Slot(inventoryplayer, var4 + var3 * 9 + 9, 8 + var4 * 18, 84 + var3 * 18));

            }

        }

 

        for (var3 = 0; var3 < 9; ++var3)

        {

            this.addSlotToContainer(new Slot(inventoryplayer, var3, 8 + var3 * 18, 142));

        }

    }

 

public void addCraftingToCrafters(ICrafting par1ICrafting)

    {

        super.addCraftingToCrafters(par1ICrafting);

        par1ICrafting.updateCraftingInventoryInfo(this, 0, this.anvil.AnvilHammerTime);

        par1ICrafting.updateCraftingInventoryInfo(this, 1, this.anvil.AnvilRepairTime);

        par1ICrafting.updateCraftingInventoryInfo(this, 2, this.anvil.temp);

    }

 

    public void updateCraftingResults()

    {

        super.updateCraftingResults();

        Iterator var1 = this.crafters.iterator();

       

        while (var1.hasNext())

        {

            ICrafting var2 = (ICrafting)var1.next();

 

            if (RepairTime != anvil.AnvilRepairTime)

            {

                var2.updateCraftingInventoryInfo(this, 0, anvil.AnvilRepairTime);

            }

 

            if (HammerTime != anvil.AnvilHammerTime)

            {

                var2.updateCraftingInventoryInfo(this, 1, anvil.AnvilHammerTime);

            }

 

            if (temp != anvil.temp)

            {

                var2.updateCraftingInventoryInfo(this, 2, anvil.temp);

            }

        }

    }

 

    @SideOnly(Side.CLIENT)

    public void updateProgressBar(int i, int j)

    {

        if(i == 0)

        {

            anvil.AnvilRepairTime = j;

        }

        if(i == 1)

        {

            anvil.AnvilHammerTime = j;

        }

        if(i == 2)

        {

            anvil.temp = j;

        }

    }

   

    public boolean canInteractWith(EntityPlayer entityplayer)

    {

        return anvil.isUseableByPlayer(entityplayer);

    }

   

    public ItemStack transferStackInSlot(int par1)

    {

        ItemStack var2 = null;

        Slot var3 = (Slot)this.inventorySlots.get(par1);

 

        if (var3 != null && var3.getHasStack())

        {

            ItemStack var4 = var3.getStack();

            var2 = var4.copy();

 

            if (par1 == 2)

            {

                if (!this.mergeItemStack(var4, 3, 39, true))

                {

                    return null;

                }

 

                var3.onSlotChange(var4, var2);

            }

            else if (par1 != 1 && par1 != 0)

            {

                if (FurnaceRecipes.smelting().getSmeltingResult(var4) != null)

                {

                    if (!this.mergeItemStack(var4, 0, 1, false))

                    {

                        return null;

                    }

                }

                else if (TileEntityFurnace.isItemFuel(var4))

                {

                    if (!this.mergeItemStack(var4, 1, 2, false))

                    {

                        return null;

                    }

                }

                else if (par1 >= 3 && par1 < 30)

                {

                    if (!this.mergeItemStack(var4, 30, 39, false))

                    {

                        return null;

                    }

                }

                else if (par1 >= 30 && par1 < 39 && !this.mergeItemStack(var4, 3, 30, false))

                {

                    return null;

                }

            }

            else if (!this.mergeItemStack(var4, 3, 39, false))

            {

                return null;

            }

 

            if (var4.stackSize == 0)

            {

                var3.putStack((ItemStack)null);

            }

            else

            {

                var3.onSlotChanged();

            }

 

            if (var4.stackSize == var2.stackSize)

            {

                return null;

            }

 

            var3.onPickupFromSlot(var4);

        }

 

        return var2;

    }

 

   

}

 

 

 

AnvilGui

 

 

package CampCraft.src.AnvilPart;

 

public class GuiAnvil extends GuiContainer

{

private TileEntityAnvil anvilInventory;

 

    public GuiAnvil(InventoryPlayer inventoryplayer, TileEntityAnvil tileentityanvil)

    {

        super(new ContainerAnvil(inventoryplayer, tileentityanvil));

        anvilInventory = tileentityanvil;

    }

 

    protected void drawGuiContainerForegroundLayer()

    {

        fontRenderer.drawString("Anvil", 70, 6, 0x404040);

        fontRenderer.drawString("Item", 23, 28, 0x404040);

        fontRenderer.drawString("Material", 8, 61, 0x404040);

        fontRenderer.drawString("Hammer", 70, 61, 0x404040);

        fontRenderer.drawString("Inventory", 60, 71, 0x404040);

    }

   

    protected void drawGuiContainerBackgroundLayer(float f, int i, int j)

    {

    int var4 = this.mc.renderEngine.getTexture("/Texture/GUIanvil.png");

        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);

        this.mc.renderEngine.bindTexture(var4);

        int var5 = (this.width - this.xSize) / 2;

        int var6 = (this.height - this.ySize) / 2;

        this.drawTexturedModalRect(var5, var6, 0, 0, this.xSize, this.ySize);

        int var7;

        if(this.anvilInventory.isBurning())

        {

            var7 = this.anvilInventory.getBurnTimeRemainingScaled(12);

            this.drawTexturedModalRect(var5 + 41, var6 + 55 - var7, 176, 12 - var7, 22, var7 + 2);

        }

        var7 = this.anvilInventory.getCookProgressScaled(24);

        this.drawTexturedModalRect(var5 + 101, var6 + 35, 177, 23, var7, 15);

    }

}

 

 

Link to comment
Share on other sites

Ya sure :)

 

First picture

This picture is the diamond spade I'm repairing and the iron hammer I'm using to repair the spade.

 

Second/Third picture

These two pictures are me pretty much trying to repair the diamond spade.

 

I place the diamond spade in the item slot, but when i place the item it places a duplicate diamond spade, same with the iron hammer when placed in the hammer slot places a duplicate hammer which when i click both the duplicate items they just disappear.

 

Does that make more sense at all?

Link to comment
Share on other sites

I had this bug updating my mod. I haven't seen your Block class but use EntityPlayer.openGui to open your gui's if you haven't already. Mine would would just cause the items to disappear.

Why do you have Furnace code? Though that isn't causing the Items to disappear, I suggest you remove it. From what happened to me, there should not be any problem with your Container, GUI or TileEntity, you just need the EntityPlayer.openGui
Link to comment
Share on other sites

Never noticed I had furnace code xD, I thought that bit of code was the problem at first as mine was different to the furnace so borrowed the furnace code for shift clicking but forgot to change some names around.

 

This is my onBlockActivated code in blockAnvil, I don't see this code being the problem as I've been using it since 1.1 part from a few edits.

 

 

 

public boolean onBlockActivated(World world, int i, int j, int k, EntityPlayer entityplayer, int var1, float var2, float var4, float var8)

    {

    if (world.isRemote)

        {

            return true;

        }

        else

        {

            TileEntityAnvil tileAnvil = (TileEntityAnvil)world.getBlockTileEntity(i, j, k);

 

            if (tileAnvil != null && !world.isRemote)

            {

                entityplayer.openGui(CampCraft.instance, 1, world, i, j, k);

                return true;

            }

            else

            {

                return true;

            }

        }

    }

 

 

Link to comment
Share on other sites

I guess the only thing left for you to do is implement ISidedInventory on your tiles. It is one thing that I did but im not sure if that actually fixed it, cause I have no idea what that interface does except every tile implements it.

ISidedInventory is used so mods like Redpower, buildcraft, or my mod(Assembly line) know which slot to dump items in.

 

Also at tomtomtom0909 you might just need to cause the TE inventory to update. Normally there is a method that the furnace uses to update all slots after doing a smelt. This way you don't get ghost items client side, also posting you TE code could help.

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
    • It is an issue with quark - update it to this build: https://www.curseforge.com/minecraft/mc-mods/quark/files/3642325
    • Remove Instant Massive Structures Mod from your server     Add new crash-reports with sites like https://paste.ee/  
    • Update your drivers: https://www.amd.com/en/support/graphics/amd-radeon-r9-series/amd-radeon-r9-200-series/amd-radeon-r9-280x
  • Topics

×
×
  • Create New...

Important Information

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