Jump to content

Copy minecraft block and use rendering.


Recommended Posts

Hey there,

For our mod we want to copy the minecraft blockChest code and create a proxy between it.
The idea would be that the player thinks he is interacting with a normal chest, while he is really interacting with our special chest.

 ModelLoader.setCustomStateMapper(ModBlocks.blockMinecoloniesChest, new StateMapperBase() {
            protected ModelResourceLocation getModelResourceLocation(final IBlockState state)
                return new ModelResourceLocation(ModItems.permTool.getRegistryName(), INVENTORY) ;
        itemModelMesher.register(Item.getItemFromBlock(ModBlocks.blockMinecoloniesChest), 0,
                new ModelResourceLocation(Blocks.CHEST.getRegistryName(), INVENTORY));

I used these two to register the renderer.

And I made a copy of the tileEntity and the block.

But, unfortunately, I'm not able to see the block in my inventory (the world block renders just fine)

Exception on loading:



[11:38:33] [Client thread/ERROR] [FML]: Exception loading model for variant minecolonies:blockChest#facing=east for blockstate "minecolonies:blockChest[facing=east]"
net.minecraftforge.client.model.ModelLoaderRegistry$LoaderException: Exception loading model minecolonies:blockChest#facing=east with loader VariantLoader.INSTANCE, skipping
    at net.minecraftforge.client.model.ModelLoaderRegistry.getModel(ModelLoaderRegistry.java:153) ~[ModelLoaderRegistry.class:?]
    at net.minecraftforge.client.model.ModelLoader.registerVariant(ModelLoader.java:241) ~[ModelLoader.class:?]
    at net.minecraft.client.renderer.block.model.ModelBakery.loadBlock(ModelBakery.java:145) ~[ModelBakery.class:?]
    at net.minecraftforge.client.model.ModelLoader.loadBlocks(ModelLoader.java:229) ~[ModelLoader.class:?]
    at net.minecraftforge.client.model.ModelLoader.setupModelRegistry(ModelLoader.java:146) ~[ModelLoader.class:?]
    at net.minecraft.client.renderer.block.model.ModelManager.onResourceManagerReload(ModelManager.java:28) [ModelManager.class:?]
    at net.minecraft.client.resources.SimpleReloadableResourceManager.notifyReloadListeners(SimpleReloadableResourceManager.java:132) [SimpleReloadableResourceManager.class:?]
    at net.minecraft.client.resources.SimpleReloadableResourceManager.reloadResources(SimpleReloadableResourceManager.java:113) [SimpleReloadableResourceManager.class:?]
    at net.minecraft.client.Minecraft.refreshResources(Minecraft.java:799) [Minecraft.class:?]
    at net.minecraftforge.fml.client.FMLClientHandler.finishMinecraftLoading(FMLClientHandler.java:340) [FMLClientHandler.class:?]
    at net.minecraft.client.Minecraft.startGame(Minecraft.java:561) [Minecraft.class:?]
    at net.minecraft.client.Minecraft.run(Minecraft.java:386) [Minecraft.class:?]
    at net.minecraft.client.main.Main.main(Main.java:118) [Main.class:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_121]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_121]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_121]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_121]
    at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?]
    at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_121]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_121]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_121]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_121]
    at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) [start/:?]
    at GradleStart.main(GradleStart.java:26) [start/:?]
Caused by: net.minecraft.client.renderer.block.model.ModelBlockDefinition$MissingVariantException
    at net.minecraft.client.renderer.block.model.ModelBlockDefinition.getVariant(ModelBlockDefinition.java:78) ~[ModelBlockDefinition.class:?]
    at net.minecraftforge.client.model.ModelLoader$VariantLoader.loadModel(ModelLoader.java:1184) ~[ModelLoader$VariantLoader.class:?]
    at net.minecraftforge.client.model.ModelLoaderRegistry.getModel(ModelLoaderRegistry.java:149) ~[ModelLoaderRegistry.class:?]
    ... 24 more




public void readFromNBT(NBTTagCompound compound)

when I call super.readFromNbt it does give me an exception:



[11:45:49] [Server thread/ERROR] [FML]: A TileEntity type com.minecolonies.coremod.tileentities.TileEntityMinecoloniesChest has throw an exception trying to write state. It will not persist. Report this to the mod author
java.lang.RuntimeException: class com.minecolonies.coremod.tileentities.TileEntityMinecoloniesChest is missing a mapping! This is a bug!
    at net.minecraft.tileentity.TileEntity.writeInternal(TileEntity.java:95) ~[TileEntity.class:?]
    at net.minecraft.tileentity.TileEntity.writeToNBT(TileEntity.java:86) ~[TileEntity.class:?]
    at net.minecraft.tileentity.TileEntityLockable.writeToNBT(TileEntityLockable.java:23) ~[TileEntityLockable.class:?]
    at net.minecraft.tileentity.TileEntityChest.writeToNBT(TileEntityChest.java:175) ~[TileEntityChest.class:?]
    at com.minecolonies.coremod.tileentities.TileEntityMinecoloniesChest.writeToNBT(TileEntityMinecoloniesChest.java:107) ~[TileEntityMinecoloniesChest.class:?]
    at net.minecraft.world.chunk.storage.AnvilChunkLoader.writeChunkToNBT(AnvilChunkLoader.java:409) [AnvilChunkLoader.class:?]
    at net.minecraft.world.chunk.storage.AnvilChunkLoader.saveChunk(AnvilChunkLoader.java:182) [AnvilChunkLoader.class:?]
    at net.minecraft.world.gen.ChunkProviderServer.saveChunkData(ChunkProviderServer.java:205) [ChunkProviderServer.class:?]
    at net.minecraft.world.gen.ChunkProviderServer.saveChunks(ChunkProviderServer.java:233) [ChunkProviderServer.class:?]
    at net.minecraft.world.WorldServer.saveAllChunks(WorldServer.java:1062) [WorldServer.class:?]
    at net.minecraft.server.MinecraftServer.saveAllWorlds(MinecraftServer.java:414) [MinecraftServer.class:?]
    at net.minecraft.server.integrated.IntegratedServer.saveAllWorlds(IntegratedServer.java:238) [IntegratedServer.class:?]
    at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:710) [MinecraftServer.class:?]
    at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:156) [IntegratedServer.class:?]
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:536) [MinecraftServer.class:?]
    at java.lang.Thread.run(Thread.java:745) [?:1.8.0_121]



Link to comment
Share on other sites

You can create your own model that would seem just like a chest. I mean, a chest model isn't that complicated, it is a 14x14x14 cube with a 1x2x1 lock :)

There is a way to bind TileEntitySpecialRenderers to Item+meta pairs(ForgeHooksClient::registerTESRItemStack) but it is marked as deprecated and is commented as 'Will be removed as soon as possible', so I wouldn't use it.

Link to comment
Share on other sites

You can't. There is no model or a blockstate file for a chest, because Mojang hardcoded the rendering of the chest into the game's code. See TileEntityItemStackRenderer::renderByItem. It literally checks if the block if the itemstack being rendered is a chest and renders it as a tile entity if it is

Link to comment
Share on other sites

okay, I just remembered I can simply drop a normal chest. I won't need the chest item in the inventory.
I just have to replace the chest on placement.

Anyway, here:


 ModelLoader.setCustomStateMapper(ModBlocks.blockMinecoloniesChest, new StateMapperBase() {
            protected ModelResourceLocation getModelResourceLocation(final IBlockState state)
                return new ModelResourceLocation(ModItems.permTool.getRegistryName(), INVENTORY) ;

I have "inventory". I think that isn't completely right. How do I get the ModelResourceLocation for the correct block?

(It works already quite well, the only problem are the particle effects)

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.

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.


  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Falling victim to a scam is a distressing reality many face. I found myself in such a predicament not too long ago, having invested a significant amount of money in what I believed to be a promising platform, only to discover it was nothing more than a fraudulent scheme. The devastating realization that my hard-earned funds had vanished and left me feeling helpless and vulnerable until I found a glimmer of hope in the form of TECHNOCRATE RECOVERY. Discovering TECHNOCRATE RECOVERY felt like stumbling upon a lifeline amidst the turbulent sea of financial fraud. Their reputation as a remarkable team of professionals specializing in assisting individuals in recovering funds lost to scams preceded them, offering a ray of hope in my darkest hour. With trepidation and a flicker of optimism, I reached out to them, hoping against hope for a chance at redemption. From the very first interaction, TECHNOCRATE RECOVERY proved themselves to be true lifesavers. Their compassion, professionalism, and unwavering dedication to my cause were evident from the outset, instilling a sense of trust and reassurance in their abilities. They wasted no time in springing into action, meticulously gathering the necessary information, and laying out a strategic plan for the recovery process. What followed was nothing short of miraculous. With precision and expertise, TECHNOCRATE RECOVERY navigated the complexities of cryptocurrency scams, uncovering the deceit and reclaiming what was rightfully mine. MAIL BOX: Technocratrecovery(@)contractor(.)net   WEBSITE INFO: www (.)technocraterecovery(.)site
    • Hello, I have been suffering with consistent crashes either during load up or during play-time. I have updated all drivers, updated and reinstalled java versions, and tried curseforge, GDLauncher, and PrismLauncher. I am struggling to find the issue of the crash as it is inhibiting me from playing. Please help, thanks. https://pastebin.com/GnQHr6sZ https://pastebin.com/6EyR1Sgk
    • Hello, I am trying to join a server with mods, specifically a Custom Profile Modpack I made. I have no idea how to identify the problem, please help. I attached the error, Modpack, and the Crash Report it gave me. Mods: https://ibb.co/N7p6Pgr Modpack: https://drive.google.com/file/d/1KCEyq_sGAF9q7tilKbdGOubpKeUdHRHx/view?usp=sharing Minecraft Crash Report: https://paste.ee/p/zISCN Minecraft Launcher Error Image: https://ibb.co/sbwQRb4
    • Thanks for the response. I ended up going with this:   public class PlayerDeathHandler { @SubscribeEvent public void playerKilled(LivingDeathEvent event) { if (event.getEntity() instanceof Player player) { ItemStack poppetStack = new ItemStack(ModItems.DEATH_PROTECTION_POPPET.get()); if (player.getInventory().contains(poppetStack)) { event.setCanceled(true); player.setHealth(player.getMaxHealth()); for (int i = 0; i < player.getInventory().getContainerSize(); i++) { ItemStack stackInSlot = player.getInventory().getItem(i); if (stackInSlot.getItem() == poppetStack.getItem()) { stackInSlot.shrink(1); if (stackInSlot.isEmpty()) { player.getInventory().setItem(i, ItemStack.EMPTY); } break; } } } } } } It works like a charm, but are there any issues that COULD arise using this? I don't have much experience with Forge, so I'm not sure about the common issues and whatnot.
  • Topics

  • Create New...

Important Information

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