Jump to content

Updating your mod to 1.8


Eternaldoom

Recommended Posts

How to update your mod to 1.8

 

Forge for Minecraft 1.8 has been released, and a few things have changed in vanilla. Updating your mod to 1.8 shouldn't be too hard though. I will go over a few major changes that affect modders and explain how to update your code. Before you update, I highly recommend going through your code and inserting @Override where you have forgotten it.

 

Blocks and Items

For simple blocks, not much has changed except that the

setBlockTextureName()

method is gone. You can delete this from your code, as well as

registerBlockIcons

. If you override methods such as

onBlockActivated()

or

onEntityCollidedWithBlock()

(anything that excepts coordinates as an argument), you need to replace the coordinates with a

BlockPos

. To change the position of the BlockPos, you can use the methods

add

(to add to or subtract from the coordinates), or the offset methods to offset the position. Also, the arguments that once were metadata are now

IBlockState

s. You can easily get an IBlockState from a metadata value with

Block.getStateFromMeta()

. Finally, the side argument (int) in many methods has been replaced with an EnumFacing value. In items, anything with coords also uses a BlockPos now, and the setTextureName method is gone.

 

Why the texture methods are gone, and how to replace them:

In 1.8, textures are set in the block/item's model file. This is a JSON file that defines the shape of the block/item, as well as its texture. For a block, you will need three files to make it load a texture: a blockstate file in assets/modid/blockstates, a block model (the name is defined in the blockstate file) in assets/modid/models/block, and an item model file in assets/models/item. The blockstate file and the item model file must be the name that the block is registered as. The block model can be called whatever you want, as long as you put the name in the blockstate file. For item models, you only need one file, an item model file. NOTE: if it seems tedious to manually create all these files (especially if your mod has a ton of blocks), you can get a tool that I wrote called ModelGenerator here. All you have to do is enter a name when prompted, and it will generate model files for you. Note that this tool may not work on windows. Another good tool (written in java), made by sheenrox82, can be found here.

 

To get the blocks/items to render in your inventory, you need to register the models with:

Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(YourItem, metadata, new ModelResourceLocation("modid:items_registered_name", "inventory"));

If they are metadata items, you also need:

ModelBakery.addVariantName(yourItem, new String[]{"different", "variant", "namesOfModelFiles"});

 

Entities

Entities are mostly unchanged, but any logic that requires getting blocks will have to be updated to use BlockPos's instead of coordinates.

 

Rendering

TileEntitySpecialRenderers still exist and can be used like normal. If you have custom block models drawn with the Tessellator, it would be best to use the new JSON model files to draw your model. Have a look at the vanilla assets. Code that still uses the tesselator must be updated, as most of the Tessellator functions have been moved to WorldRenderer. Here's an example of how to update this:

Tessellator tess = Tessellator.instance;
tess.startDrawingQuads();
tess.addVertexWithUV ...
...
tess.draw();

This should be updated to:

Tessellator tess = Tessellator.getInstance();
WorldRenderer worldrenderer = tess.getWorldRenderer();
worldrenderer.addVertexWithUV ...
...
tess.draw();

 

World Generation

Because of the BlockPos changes, big worldgen classes will have tons of errors. However, these can be easily fixed by creating helper methods and using find and replace.

 

Good luck updating to 1.8! Feel free to leave questions on this thread.

Check out my mod, Realms of Chaos, here.

 

If I helped you, be sure to press the "Thank You" button!

Link to comment
Share on other sites

  • 4 weeks later...

Looks like there is a few changes for tile entities as well with a good bit of functions been changed into interfaces instead of being in the base class.

 

edit: And correct me if I'm wrong but it looks as if containers and GUIs have changed a bit as well...

Link to comment
Share on other sites

Look at RenderItem.registerItems. That is where Items & Blocks with subtypes are mapped to their model file. You should be able to do that in your normal init method (through your ClientProxy method of course). You get the renderer via Minecraft#getRenderItem. All the new render code is pretty complex to read, but I think that's where it happens.

Nope, that didn't help. I'm presuming you mean use the register method in the item model mesher?

In addition, no error messages are outputted to the client log.

 

for (int i = 0; i < 16; ++i)
modelMesher.register(CppItems.stained_glass_shard, i, new ModelResourceLocation(CppReferences.MODID + ":" + "stained_glass_shard_" + ItemStainedGlassShard.getColorFromMeta(i), "inventory"));

Maker of the Craft++ mod.

Link to comment
Share on other sites

Metadata item files are the same as normal ones. Register them for meshing with:

Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, metadata, new ModelResourceLocation(itemName, "inventory"));

 

Then add the variants with:

ModelBakery.addVariantName(item, new String[]{"your", "different", "subitems", "here"});

Check out my mod, Realms of Chaos, here.

 

If I helped you, be sure to press the "Thank You" button!

Link to comment
Share on other sites

Metadata item files are the same as normal ones. Register them for meshing with:

Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, metadata, new ModelResourceLocation(itemName, "inventory"));

 

Then add the variants with:

ModelBakery.addVariantName(item, new String[]{"your", "different", "subitems", "here"});

Thanks, I just need a couple of things clarified.

Does the item name in the model mesh registration refer to the name with metadata? And the subitems are in the format "stained_glass_shard_red" right? Thanks again.

Maker of the Craft++ mod.

Link to comment
Share on other sites

is there something specific needed for entity textures?

 

i've been fighting with this for a while, but each time i attempt to spawn an entity, all i get is a crash:

 

[Client thread/ERROR]: Couldn't render entity

java.lang.NullPointerException

at net.minecraft.client.renderer.entity.Render.bindTexture(Render.java:86) ~[Render.class:?]

at net.minecraft.client.renderer.entity.Render.bindEntityTexture(Render.java:79) ~[Render.class:?]

at net.minecraft.client.renderer.entity.RendererLivingEntity.renderModel(RendererLivingEntity.java:252) ~[RendererLivingEntity.class:?]

at net.minecraft.client.renderer.entity.RendererLivingEntity.doRender(RendererLivingEntity.java:168) [RendererLivingEntity.class:?]

at net.minecraft.client.renderer.entity.RenderLiving.doRender(RenderLiving.java:50) [RenderLiving.class:?]

at net.minecraft.client.renderer.entity.RenderLiving.doRender(RenderLiving.java:172) [RenderLiving.class:?]

at net.minecraft.client.renderer.entity.RenderManager.doRenderEntity(RenderManager.java:370) [RenderManager.class:?]

at net.minecraft.client.renderer.entity.RenderManager.renderEntityStatic(RenderManager.java:327) [RenderManager.class:?]

at net.minecraft.client.renderer.entity.RenderManager.renderEntitySimple(RenderManager.java:294) [RenderManager.class:?]

at net.minecraft.client.renderer.RenderGlobal.func_180446_a(RenderGlobal.java:631) [RenderGlobal.class:?]

at net.minecraft.client.renderer.EntityRenderer.func_175068_a(EntityRenderer.java:1294) [EntityRenderer.class:?]

at net.minecraft.client.renderer.EntityRenderer.renderWorld(EntityRenderer.java:1207) [EntityRenderer.class:?]

at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1032) [EntityRenderer.class:?]

at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1048) [Minecraft.class:?]

at net.minecraft.client.Minecraft.run(Minecraft.java:345) [Minecraft.class:?]

at net.minecraft.client.main.Main.main(Main.java:117) [Main.class:?]

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_25]

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_25]

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_25]

at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_25]

at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.11.jar:?]

at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.11.jar:?]

at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:78) [start/:?]

at GradleStart.main(GradleStart.java:45) [start/:?]

 

 

i'm pretty sure i have the texture defined with private static final ResourceLocation and later on a ResourceLocation getEntityTexture that refers to it, but i still get that the moment the entity's spawned.

 

edit: apparently i should've waited a few more hours before posting this. i didn't initialize the rendering correctly, my old method doesn't seem to work anymore. i fixed the problem.

Link to comment
Share on other sites

edit: apparently i should've waited a few more hours before posting this. i didn't initialize the rendering correctly, my old method doesn't seem to work anymore. i fixed the problem.

 

Could you explain how you fixed your problem? I get the exact same error and it's likely I made the same mistake as you.

Thanks.

 

Edit:Fixed.

Link to comment
Share on other sites

  • 2 weeks later...

Forgive me if this is a newb question, but the getItemModelMesher().register accepts Item as its first argument, what do I do for blocks to make them render in my inventory? The block I'm talking about already has its json files set up, and renders fine in the world.

Item.getItemFromBlock(Block)

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

Any guess how the change to updateEntity in TileEntity effect things? I was a little confused when i took a look at one of my tile entities and tried to fix the error with onUpdate. I had to look at TileEntityFurnace to figure out that you now need to implement IUpdatePlayerListBox (That seems like a weird name?) and implement its "update" method which seems to replace updateEntity.

 

My only guess is it is to make non-updating tileEntitys more efficient but im guessing thats not why it was changed.

I am the author of Draconic Evolution

Link to comment
Share on other sites

Also, there have been changes to item rendering. RenderItem has been changed to require a TextureManager and ModelManager argument, but you can get an instance of the RenderItem in Minecraft#getRenderItem(). It appears the rendering bit isn't deobfuscated, but RenderItem#func_175042_a(ItemStack, int, int) will draw your item. Args: item stack to draw, x coord, y coord. This also seems to draw any effects, combining the two separate methods in 1.7.

 

GuiScreens can now throw exceptions on key and mouse inputs, so those will need to be handled accordingly too.

Link to comment
Share on other sites

  • 4 weeks later...

A trap to watch out for - in 1.8, your IMessageHandler now runs in a separate thread (i.e. not in the client or server thread).  If you try to access vanilla objects in your handler, it will cause concurrency bugs (i.e. crashes, corruption and general weirdness).

 

This link talks a bit more about how to modify for 1.8

http://greyminecraftcoder.blogspot.com.au/2015/01/thread-safety-with-network-messages.html

 

-TGG

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.