Fizzixnerd Posted January 15, 2019 Posted January 15, 2019 I'm adapting this tutorial (which is quite old) to a newer Forge version. One of the things you do in it is make a "wheat and steel" item. This is a damageable item that plants a seed. Tutorial suggests as an extension that we add the ability to hoe the ground first before attempting to place the seed. I thought I would try to just reuse the implementations of ItemHoe and ItemSeeds. Here is my code (Scala). package com.fizzixnerd.mymod import net.minecraft.creativetab.CreativeTabs import net.minecraft.entity.player.EntityPlayer import net.minecraft.item.{Item, ItemHoe, ItemSeeds, ItemStack} import net.minecraft.util.{EnumActionResult, EnumFacing, EnumHand, ResourceLocation} import net.minecraft.util.math.BlockPos import net.minecraft.world.World import net.minecraftforge.common.IPlantable import net.minecraftforge.fml.common.registry.GameRegistry object ItemWheatAndSteel extends Item { setRegistryName("wheat_and_steel") maxStackSize = 1 setMaxDamage(64) setCreativeTab(CreativeTabs.TOOLS) private val virtualSeeds = GameRegistry.findRegistry(classOf[Item]).getValue(new ResourceLocation(("minecraft:wheat_seeds"))) override def onItemUse(player: EntityPlayer, world: World, pos: BlockPos, hand: EnumHand, side: EnumFacing, hitX: Float, hitY: Float, hitZ: Float): EnumActionResult = { val itemStack = player.getHeldItem(hand) if (!player.canPlayerEdit(pos.offset(side), side, itemStack)) { EnumActionResult.FAIL } else { // Create a virtual hoe to till the ground first. val virtualHoe = new ItemHoe(Item.ToolMaterial.IRON) val success = virtualHoe.onItemUse(player, world, pos, hand, side, hitX, hitY, hitZ) if (success == EnumActionResult.SUCCESS) { val success = virtualSeeds.onItemUse(player, world, pos, hand, side, hitX, hitY, hitZ) if (success == EnumActionResult.SUCCESS) { itemStack.damageItem(1, player) } success } else { success } } } } This does not give the desired behavior. After using the item once, it disappears from the players inventory. What happens is that inside ItemSeeds class is that at the end of planting the seed, it decrements the number of items the player is holding, whatever that happens to be. Is there a way to reuse the behavior of ItemSeeds and ItemHoe without reimplementing them directly in my own class? Quote
Cadiboo Posted January 15, 2019 Posted January 15, 2019 You can’t create a new item, this usually crashed the game - you want an ItemStack. I would just copy the code from ItemHoe Quote About Me Spoiler My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.github.io/tutorials Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support. When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible. Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)
Recommended Posts
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.