Background
There are some general practices for figuring out how to upgrade your code which I've explained in Jabelar's Updating Your Mod tutorial.
Also see williewillus' guide to updating from 1.8.9 to 1.9.
Otherwise, here is a list of some specific things I've noticed about transitioning from 1.8.x to 1.9.x and 1.10.x. Hopefully these will give you some ideas to further help upgrade your own code.
Packages Rearranged -- Need To Update Your Imports
You might find that some classes you are sure are still used show up as not being recognized. This may be because some of the imports needed have changed.
Here are some examples.
- net.minecraft.util has been reorganized to have sub-packages so you may have to update your imports. In particular, there is now a net.minecraft.util.math package that contains:
- BlockPos
- AxisAlignedBB
- MathHelper.
Constants Now Capitalized
It is standard coding style to all-capitalize the names of fields that are meant to be constant. This is now implemented more consistently. Here are some examples:
- Blocks class has now capitalized constants such as Blocks.farmland is now Blocks.FARMLAND.
- Items class now has capitalized constants such as Items.wheat is now Items.WHEAT
- Block.blockRegistery is changed to Block.REGISTRY.
- CreativeTabs class now capitalizes its constants. For example, CreativeTabs.blocks has changed to CreativeTabs.BUILDING_BLOCKS.
- Statlist class now capitalizes its constants. For example StatList.animalsBredStat is now StatList.ANIMALS_BRED.
- SharedMonsterAttributes class now capitalizes its constants. For example, ShareMonsterAttributes.followRange is now SharedMonsterAttributes.FOLLOW_RANGE.
- Material class now capitalizes constants such as Material.wood is now Material.WOOD.
- Block sound types now have their own SoundType class with constants so soundTypeSnow is now SoundType.SNOW.
- MapColor class now capitalizes its constants, such as MapColor.snowColor is now MapColor.SNOW.
"Magic" Numbers Now Managed In Classes
Sometimes when coding values that are "magic" meaning that they don't really tell you what they are unless you know how to decode them (e.g. if slot 3 is meant to mean the leg armor slot, that is a "magic" number). So it is generally an improved coding style to move those to something more readable like enums or constants. Here are some examples where this improvement has been made:
- ItemArmor has changed constructor's armor type from an int value to an EntityEquipmentSlot class.
- EnumPushAction replaces the previous int values in the Block class' methods.
Method And Field Name Changes
Sometimes methods and fields that operate pretty much the same as previously get new names. This is usually to improve consistency, clarity or brevity. Here are some examples:
- EntityPlayer.triggerAcheivement() has changed to EntityPlayer.addStat()
- GameRules.getGameRulesBooleanValue() has changed to GameRules.getBoolean()
- EntityPlayerMP.itemInWorldManger has changed to EntityPlayerMP.interactionManager.
- EntityPlayerMP.getServerForPlayer() method has been renamed to EntityPlayerMP.getServer().
- BlockState class (not to be confused with IBlockState interface) has been renamed to BlockStateContainer.
- EnumChatFormatting class has been renamed TextFormatting. Other references to "chat" have been removed in class and method names, so ChatComponentText is now TextComponentString and setChatStyle() is setStyle() and so on.
- MovingObjectPosition class has been renamed to RayTraceResult.
- ICommand interface has changed significantly with renamed methods and changed method prototypes.
- World.markBlockForUpdate() method has been renamed to notifyBlockUpdate() with additional parameters..
- EntityFX subclasses (for particles) have been renamed to be Particle subclasses.
- The terrain gen ChunkProviderEvent class is renamed to ChunkGeneratorEvent.
- IInventory.getStackInSlotOnClosing() method is renamed removeStackFromSlot().
- INameable.getCommandSenderName() method is renamed getName().
More Fields Now Have "Setter" and "Getter" Methods
It is good programming practice to "encapsulate" your fields so they are not accessed directly as public fields but rather made private and accessed through methods. This provides better control of any data validation and timing impacts of using the value. Here are some examples:
- Block.stepsound field is now accessed with setter setSoundType() and getter getSoundType() methods.
- Many events have replaced the public fields with getter and setter methods. For example, MouseEvent.button is now MouseEvent.getButton() and Event.entityLiving is now Event.getEntityLiving().
- StatList uses setter and getters now.
Block-Specific Stuff
- BlockState class (not to be confused with IBlockState interface) has been renamed to BlockStateContainer.
- Block.createBlockState() method now returns a BlockStateContainer.
- Some methods like isFullBlock() have been moved to IBlockState.
- Block bounding box is now final so the setBoundingBox() method is no longer available and there is no the longer min and max x, y, z fields, but you can still @Override the getBoundingBox() method in your own custom blocks.
- Block.stepSound has changed to Block.blockSoundType.
- EnumWorldBlockLayer is now BlockRenderLayer.
- BlockModelRenderer.renderModelStandard() method has been renamed to BlockModelRenderer.renderModelFlat().
- Block.isOpaqueCube() method has been moved to IBlockState class.
- Most Block class' methods now take an additional IBlockState parameter, such as:
- getMaterial()
- getMobilityFlag() (also returns an EnumPushReaction instead of an int).
- isSideSolid()
- isNormalCube()
- isFullCube()
- isReplaceableOreGen() (also other parameter changes)
- canCreatureSpawn()
- shouldCheckWeakPower()
- canSustainPlant()
- getRenderType() (also returns a EnumBlockRenderType)
- hasComparatorOverride()
- getItem() (also returns an ItemStack instead of Item)
- getRenderType() (also returns an EnumBlockRenderType instead of an int)
- BlockBush.canPlaceBlockOn() method has been renamed to BlockBush.canSustainBush() and parameter has been changed to IBlockState.
- getComparatorInputOverride()
- hasComparatorInputOverride()
- getItem() (also returns an ItemStack instead of an Item)
- Block.canPlaceBlockAt() method has changed parameter to an IBlockAccess.
- Block.onNeighborBlockChange() method is renamed to onNeighborChange() and the parameters have been changed.
- Block.onBlockActivated() takes many more parameters such as ItemStack and EnumHand.
- Block.randomDisplayTick() has rearranged its parameters.
- EnumWorldBlockLayer is renamed to BlockRenderLayer.
Entity- and Player-Related Stuff
- Items can now be wielded in both hands, so the getHeldItem() method now takes an EnumHand parameter, and also there is a getHeldItemMainHand() and getHeldItemOffHand() method.
- EntityPlayer.addChatMessage() method now takes an ITextComponent parameter.
- The Entity.interact() method has changed substantially. There is also now a processInitialInteract() and an applyPlayerInteraction() method.
- IBossDisplayData has been replaced with BossInfoServer class which is an extension of BossInfo class and rendered by the GuiBossOverlay class.
- BossStatus is no longer used to indicate an entity is a boss, rather you need to @Override the Entity.isNonBoss() method instead.
- Entity.playSound() method now takes a SoundEvent parameter, which in turn takes a ResourceLocation. If possible you should not create a new SoundEvent each time, rather create a static final constant that you play as needed.
- Entity.getEquipmentFromSlot() method has changed to Entity.getItemStackFromSlot() which takes EntityEquipmentSlot as a parameter which has a SlotType depending on where it is.
- Potion effect fields are now MobEffect class constants.
- IEntity.allowLeashing() has been moved to EntityLiving.canBeLeashedToPlayer().
- Mob spawners no longer contain different colors for the spots and base in the class -- I need to find where this is now?
- EntityPlayerMP.getServerForPlayer() method has been renamed to EntityPlayerMP.getServer().
- EntityPlayerMP.hasItem() method has been replaced by EntityPlayerMP.inventory.hasItemStack() method. Note that the number of items doesn't matter in the ItemStack passed to the method.
- EntityPlayer no longer has a getCurrentArmor() method, rather you use getItemStackFromSlot() method and pass an EntityEquipmentSlot parameter.
- IExtendedEntityProperties has been entirely removed and replaced with Capabilities.
- For entity renderers, the registration method of directly passing the renderer is now deprecated and a "factory" method using IEnityRenderFactory interface is now preferred.
- RenderLiving no longer has a passSpecialRender() method, rather you need to @Override the renderName() method directly.
- EntityPlayer.dropPlayerItemWithRandomChoice() method has been renamed to EntityPlayer.dropItem().
Item-Related Stuff
- Item.onItemRightClick() method now takes an EnumHand parameter. and returns an ActionResult.
- Item.getMovingObjectPositionFromPlayer() method is renamed to rayTrace().
- ArmorMaterial class no longer seems to be used.
Sounds
- In 1.9.x the sound system changed to a registry-based system. See details in Jabelar's Tips On Sounds.
Registries
- Objects like Block, Item, etc. now implement IForgeRegistryEntry.
- Methods like GameRegistry.registerBlock() are now simply register() (where the parameter passed is an object implementing IForgeRegistryEntry.
Miscellaneous
- ICommand interface has changed significantly with renamed methods and changed method prototypes.
- World.markBlockForUpdate() method has been renamed to notifyBlockUpdate() with additional parameters..
- EntityFX subclasses (for particles) have been renamed to be Particle subclasses.
- Most writeToNBT() type methods (e.g. TileEntity.writeToNBT()) now return NBTTagCompound instead of void, to allow method chaining.
- The terrain gen ChunkProviderEvent class is renamed to ChunkGeneratorEvent.
- Vec3 has been renamed Vec3d\
Events
- Many events have replaced the public fields with getter and setter methods. For example, MouseEvent.button is now MouseEvent.getButton() and Event.entityLiving is now Event.getEntityLiving().
- The FML event bus is now merged to the Forge event bus so your FML event handler should now be registered on MinecraftForge.EVENT_BUS instead of FMLCommonHandler.instance().bus().
Renderers
- For entity renderers, the registration method of directly passing the renderer is now deprecated and a "factory" method using IEnityRenderFactory interface is now preferred.
- RenderLiving no longer has a passSpecialRender() method, rather you need to @Override the renderName() method directly.
- EnumWorldBlockLayer is now BlockRenderLayer.
- BlockModelRenderer.renderModelStandard() method has been renamed to BlockModelRenderer.renderModelFlat().
Item Models
- Thanks to Choonster for this information.
- 1.9 added the item/generated model, which extends builtin/generated and defines the standard display transformations. Most vanilla item models extend this, yours should too. Only define display transformations in your models if they're different to the standard ones.
- 1.9 also split the first-person and third-person display transformations into separate left- and right-hand versions. The first- and third-person display transformations only apply when an entity is holding the item.
- ItemEntity uses the ground display transformation.
Block Models
- In addition to item/generated, there's now the block/block model that defines the standard display transformations for blocks. Most vanilla block models (including "abstract" models like block/cube_all) extend this.
IEEP Needs To Be Converted To Capabilities
If you're upgrading your mod you may need to convert your IEEP to Capabilities. The official Forge documentation explains how to convert.
Commands
- Most of the ICommand methods now take a MinecraftServer parameter.
- Most of the ICommand methods have been renamed.
No comments:
Post a Comment