Porting-1.10-1.11

From McJty Modding
Jump to: navigation, search

In this chapter we go over all changes between 1.10.2 and 1.11.2. For most of these changes CompatLayer has a solution so this will also be mentioned in addition to the native 1.11.2 solution.

Resource names

In 1.11 all resource names and mod ID's must be lowercase. This has a number of consequences:

  • In your @Mod annotation you should refer to 'forge' instead of 'Forge'. If you use CompatLayer you can use both but then you need to use 'after' instead of 'required-after'. That way you can specify a dependency on the right version of forge depending on 1.10/1.11.
  • All filenames for jsons, textures and others must be lowercase.

worldObj

  • TileEntity.worldObj is now TileEntity.world. You can use getWorld() if you want code that compiles on 1.10 and 1.11
  • Entity.worldObj is now Entity.world. Use getEntityWorld() for a solution compatible with 1.10 and 1.11

Block changes

  • CompatBlock from CompatLayer has solutions for all the changes mentioned here:
  • neighbourChanged(): has an extra BlockPos parameter
  • onBlockActivated(): the heldItem parameter is gone
  • addCollisionBoxToList(): extra parameter (set to false for compatible behaviour)
  • onBlockPlaced(): renamed to getStateForPlacement()
  • getSubBlocks(): the List<ItemStack> parameter has changed to NonNullList<ItemStack>
  • getPropertyNames(): renamed to getPropertyKeys()

Item changes

  • CompatItem from CompatLayer has solutions for all the changes mentioned here:
  • onItemRightClick(): ItemStack parameter is removed
  • onItemUse(): ItemStack parameter is removed
  • onItemUseFirst(): ItemStack parameter is removed
  • getSubItems(): the List<ItemStack> parameter has changed to NonNullList<ItemStack>

EntityPlayer changes

  • addChatComponentMessage(): extra boolean parameter. Set to default to have old behaviour. ChatTools.addChatMessage() solves this

ItemStack changes

This is the most significant change. An empty itemstack (like a slot in a chest that is empty or the player's hand that is empty) is no longer equal to null but to ItemStack.EMPTY instead! In fact 'null' ItemStack's are no longer allowed. You have to carefully go over all your code (use annotations where appropriate) to find all places where you use null for itemstacks and replace them. Also where you compare with null you have to replace this with a isEmpty() call. Be careful with things like ItemStack[] items because these are initialized to null. You need to ensure that all these items are initialized to EMPTY instead of null. It is recommended to use NonNullList<ItemStack> for this on 1.11 or else use ItemStackList from CompatLayer.

If you use CompatLayer you can make abstraction of these changes by using ItemStackTools.

Entity changes

  • Entities are another area where things have changed a bit. When registering entities you now have to give a unique ResourceLocation() as an ID. The old string ID is still given. This change affects EntityRegistry.registerModEntity(). CompatLayer also has a 1.10/1.11 compatible solution for this problem in EntityTools.
  • World.spawnEntityInWorld() has been renamed to World.spawnEntity()

Command changes

  • CompatLayer has CompatCommand that you can use to solve the differences
  • getCommandName() has been renamed to getName()
  • getCommandUsage() has been renamed to getUsage()
  • getCommandAliases() has been renamed to getAliases()

MathHelper changes

Many functions in MathHelper have been renamed.

Smaller changes

There are many other smaller changes. Most of them are easy to handle and for many there are solutions in CompatLayer.