Jump to content

How to register TileEntity in 1.12?


MineDen

Recommended Posts

Today I copied and edited furnace tileentity and then started testing. But now I have "TileEntity is missing a mapping! This is a bug!" exception. In 1.9 I can fix it by registering TE with GameRegistry.registerTileEntity(...) but in 1.12 I should use RegistryEvents and here is described types of events, and there is no TileEntity! So how I can register my TE?

Edited by MineDen
Link to comment
Share on other sites

5 minutes ago, V0idWa1k3r said:

It's still GameRegistry#registerTileEntity. Use the overload which takes a ResourceLocation as the second argument though.

 

Okay, I'll try this.
UPD: there is no overloads, only string. Is this should be like "testmod:my_tileentity"?

Edited by MineDen
Link to comment
Share on other sites

If there are no overloads then you are using a forge version which doesn't have that introduced. In the newer version GameRegistry#registerTileEntity(Class<? extends TileEntity> tileEntityClass, String key) is deprecated with a comment that it'll be removed in 1.13. 

Link to comment
Share on other sites

9 minutes ago, V0idWa1k3r said:

If there are no overloads then you are using a forge version which doesn't have that introduced. In the newer version GameRegistry#registerTileEntity(Class<? extends TileEntity> tileEntityClass, String key) is deprecated with a comment that it'll be removed in 1.13. 

Also I want to open furnace GUI but it doesn't open. Here is my code:

 

Block:

public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
        if (worldIn.isRemote) {
            return true;
        } else {
            TileEntity tileentity = worldIn.getTileEntity(pos);

            if (tileentity instanceof TileEntityFurnace) {
                playerIn.displayGUIChest((TileEntityFurnace) tileentity);
                playerIn.addStat(TestMod.CHEMICAL_LABORATORY_INTERACT);
            }

            return true;
        }
    }

 

TileEntity:

@Nonnull
    public String getGuiID() {
        return "minecraft:furnace";
    }

    @Nonnull
    public Container createContainer(@Nonnull InventoryPlayer playerInventory, @Nonnull EntityPlayer playerIn) {
        return new ContainerFurnace(playerInventory, this);
    }

 

Link to comment
Share on other sites

Use IGuiHandler with EntityPlayer#openGui(Object mod, int modGuiId, World world, int x, int y, int z) for your custom GUIs. Your solution will open a gui/container pair of a vanilla furnace which is likely not what you want. If you do want that you can

  • Still use IGuiHandler. Just return vanilla's ContainerFurnace and GuiFurnace in corresponding methods.
  • Make sure that your TE implements IInteractionObject. I do not see Override annotations in your code(Code-style issue #2)
Link to comment
Share on other sites

42 minutes ago, V0idWa1k3r said:

Use IGuiHandler with EntityPlayer#openGui(Object mod, int modGuiId, World world, int x, int y, int z) for your custom GUIs. Your solution will open a gui/container pair of a vanilla furnace which is likely not what you want. If you do want that you can

  • Still use IGuiHandler. Just return vanilla's ContainerFurnace and GuiFurnace in corresponding methods.
  • Make sure that your TE implements IInteractionObject. I do not see Override annotations in your code(Code-style issue #2)

Oh, I forgot that my TE doesn't extend TileEntityFurnace, and I also forgot to change checking in block code!

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.