DimensionsInTime Posted June 5, 2017 Posted June 5, 2017 (edited) Is setting hasContainerItem() and getContainerItem() not enough to keep an item in the table on latest forge versions? Found posts for previous versions where it worked in older versions. I have an ItemTool extended class that I want to stay in the table and just have some damage after crafting. Thanks for any help! Item Class: Spoiler package dimensionsintime.expandedplates.items; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Sets; import dimensionsintime.expandedplates.creativetabs.ModCreativeTab; import dimensionsintime.expandedplates.init.ModMaterials; import dimensionsintime.expandedplates.util.Log; import mcp.MethodsReturnNonnullByDefault; import net.minecraft.block.Block; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import javax.annotation.ParametersAreNonnullByDefault; import java.util.Set; @MethodsReturnNonnullByDefault public class ModAlluviumHammer extends ModItemTool{ private static final Set<Block> EFFECTIVE_ON = Sets.newHashSet(Blocks.ACTIVATOR_RAIL, Blocks.COAL_ORE, Blocks.COBBLESTONE, Blocks.DETECTOR_RAIL, Blocks.DIAMOND_BLOCK, Blocks.DIAMOND_ORE, Blocks.DOUBLE_STONE_SLAB, Blocks.GOLDEN_RAIL, Blocks.GOLD_BLOCK, Blocks.GOLD_ORE, Blocks.ICE, Blocks.IRON_BLOCK, Blocks.IRON_ORE, Blocks.LAPIS_BLOCK, Blocks.LAPIS_ORE, Blocks.LIT_REDSTONE_ORE, Blocks.MOSSY_COBBLESTONE, Blocks.NETHERRACK, Blocks.PACKED_ICE, Blocks.RAIL, Blocks.REDSTONE_ORE, Blocks.SANDSTONE, Blocks.RED_SANDSTONE, Blocks.STONE, Blocks.STONE_SLAB, Blocks.STONE_BUTTON, Blocks.STONE_PRESSURE_PLATE,Blocks.CLAY, Blocks.DIRT, Blocks.FARMLAND, Blocks.GRASS, Blocks.GRAVEL, Blocks.MYCELIUM, Blocks.SAND, Blocks.SNOW, Blocks.SNOW_LAYER, Blocks.SOUL_SAND, Blocks.GRASS_PATH,Blocks.PLANKS, Blocks.BOOKSHELF, Blocks.LOG, Blocks.LOG2, Blocks.CHEST, Blocks.PUMPKIN, Blocks.LIT_PUMPKIN, Blocks.MELON_BLOCK, Blocks.LADDER, Blocks.WOODEN_BUTTON, Blocks.WOODEN_PRESSURE_PLATE); public ModAlluviumHammer(){ super("ep_alluvium_hammer", ModMaterials.MOD_HARDENED_ALLUVIUM, EFFECTIVE_ON, 1.0F, 1.0F, 1, 100); setContainerItem(this); setCreativeTab(ModCreativeTab.EP_TAB); } @Override public Set<String> getToolClasses(ItemStack stack){ return ImmutableSet.of("pickaxe", "axe","spade"); } @SuppressWarnings("deprecation") @Override public boolean hasContainerItem(){ return true; } @ParametersAreNonnullByDefault @Override public ItemStack getContainerItem(ItemStack itemStack){ Log.info("itemStack: " + itemStack.getDisplayName()); Log.info("- damage: " + itemStack.getItemDamage()); Log.info("- attempting damage..."); itemStack.attemptDamageItem(10, itemRand); Log.info("- damage: " + itemStack.getItemDamage()); return itemStack; } } ItemTool Extension Class: Spoiler package dimensionsintime.expandedplates.items; import com.google.common.collect.Sets; import dimensionsintime.expandedplates.creativetabs.ModCreativeTab; import net.minecraft.block.Block; import net.minecraft.init.Blocks; import net.minecraft.item.ItemTool; import java.util.Set; public class ModItemTool extends ItemTool{ // generic pick axe effective set private static final Set<Block> EFFECTIVE_ON = Sets.newHashSet(Blocks.ACTIVATOR_RAIL, Blocks.COAL_ORE, Blocks.COBBLESTONE, Blocks.DETECTOR_RAIL, Blocks.DIAMOND_BLOCK, Blocks.DIAMOND_ORE, Blocks.DOUBLE_STONE_SLAB, Blocks.GOLDEN_RAIL, Blocks.GOLD_BLOCK, Blocks.GOLD_ORE, Blocks.ICE, Blocks.IRON_BLOCK, Blocks.IRON_ORE, Blocks.LAPIS_BLOCK, Blocks.LAPIS_ORE, Blocks.LIT_REDSTONE_ORE, Blocks.MOSSY_COBBLESTONE, Blocks.NETHERRACK, Blocks.PACKED_ICE, Blocks.RAIL, Blocks.REDSTONE_ORE, Blocks.SANDSTONE, Blocks.RED_SANDSTONE, Blocks.STONE, Blocks.STONE_SLAB, Blocks.STONE_BUTTON, Blocks.STONE_PRESSURE_PLATE); public ModItemTool(String itemName){ this(itemName, ToolMaterial.IRON, EFFECTIVE_ON, 1.0F, 1.0F, 64, 100); } public ModItemTool(String itemName, ToolMaterial material, Set<Block> effectiveBlocks){ this(itemName, material, effectiveBlocks, 1.0F, 1.0F, 64, 100); } public ModItemTool(String itemName, ToolMaterial material, Set<Block> effectiveBlocks, int maxStackSize, int maxDamage){ this(itemName, material, effectiveBlocks, 1.0F, 1.0F, maxStackSize, maxDamage); } public ModItemTool(String itemName, ToolMaterial material, Set<Block> effectiveBlocks, float attackSpeed, float attackDamage, int maxStackSize, int maxDamage){ super(attackDamage, attackSpeed, material, effectiveBlocks); setItemName(this, itemName); setMaxStackSize(maxStackSize); setMaxDamage(maxDamage); setCreativeTab(ModCreativeTab.EP_TAB); } public static void setItemName(ItemTool item, String itemName){ item.setRegistryName(itemName); item.setUnlocalizedName(String.valueOf(item.getRegistryName())); } } Edited June 5, 2017 by DimensionsInTime Quote
DimensionsInTime Posted June 5, 2017 Author Posted June 5, 2017 Whoops, missed that new method. Fixed. Thanks. The hammer item still disappears on crafting. Recipe is a shapeless where a stack of another item is given when you place the hammer and a block/item in the table. In the hook code I see it checks for container and returns the stack if not empty, has max damage, etc. Looks as if this is called on crafting, so is that the right place to return the stack to keep it in the table? Recipes: Spoiler GameRegistry.addShapelessRecipe(new ItemStack(ModItems.MOD_GLASS_SHARD,4), new ItemStack(ModItems.MOD_ALLUVIUM_HAMMER, 1, OreDictionary.WILDCARD_VALUE), new ItemStack(Blocks.GLASS, 1)); GameRegistry.addShapelessRecipe(new ItemStack(ModItems.MOD_EMERALD_SHARD,4), new ItemStack(ModItems.MOD_ALLUVIUM_HAMMER, 1, OreDictionary.WILDCARD_VALUE), new ItemStack(Items.EMERALD, 1)); GameRegistry.addShapelessRecipe(new ItemStack(ModItems.MOD_DIAMOND_SHARD,4), new ItemStack(ModItems.MOD_ALLUVIUM_HAMMER, 1, OreDictionary.WILDCARD_VALUE), new ItemStack(Items.DIAMOND, 1)); GameRegistry.addShapelessRecipe(new ItemStack(ModItems.MOD_OBSIDIAN_SHARD,4), new ItemStack(ModItems.MOD_ALLUVIUM_HAMMER, 1, OreDictionary.WILDCARD_VALUE), new ItemStack(Blocks.OBSIDIAN, 1)); Quote
DimensionsInTime Posted June 5, 2017 Author Posted June 5, 2017 (edited) Solved. I was making it harder than it was I guess. @Override public ItemStack getContainerItem(@Nonnull ItemStack stack){ return stack.getItemDamage() < stack.getMaxDamage() ? new ItemStack(stack.getItem(), 1,stack.getItemDamage() + 10) : ItemStack.EMPTY; } Works great. Edited June 5, 2017 by DimensionsInTime code format Quote
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.