diff --git a/patches/minecraft/net/minecraft/entity/EntityLivingBase.java.patch b/patches/minecraft/net/minecraft/entity/EntityLivingBase.java.patch index 44624b070e..6af6395ade 100644 --- a/patches/minecraft/net/minecraft/entity/EntityLivingBase.java.patch +++ b/patches/minecraft/net/minecraft/entity/EntityLivingBase.java.patch @@ -401,7 +401,11 @@ public abstract EnumHandSide func_184591_cq(); public boolean func_184587_cr() -@@ -2595,12 +2670,19 @@ +@@ -2592,15 +2667,23 @@ + if (this.func_184587_cr()) + { + ItemStack itemstack = this.func_184586_b(this.func_184600_cs()); ++ if (net.minecraftforge.common.ForgeHooks.canContinueUsing(this.field_184627_bm, itemstack)) this.field_184627_bm = itemstack; if (itemstack == this.field_184627_bm) { @@ -422,7 +426,7 @@ { this.func_71036_o(); } -@@ -2618,8 +2700,10 @@ +@@ -2618,8 +2701,10 @@ if (!itemstack.func_190926_b() && !this.func_184587_cr()) { @@ -434,7 +438,7 @@ if (!this.field_70170_p.field_72995_K) { -@@ -2700,7 +2784,10 @@ +@@ -2700,7 +2785,10 @@ if (!this.field_184627_bm.func_190926_b() && this.func_184587_cr()) { this.func_184584_a(this.field_184627_bm, 16); @@ -446,7 +450,7 @@ this.func_184602_cy(); } } -@@ -2724,7 +2811,8 @@ +@@ -2724,7 +2812,8 @@ { if (!this.field_184627_bm.func_190926_b()) { @@ -456,7 +460,7 @@ } this.func_184602_cy(); -@@ -2852,6 +2940,31 @@ +@@ -2852,6 +2941,31 @@ return true; } @@ -488,7 +492,7 @@ public boolean func_190631_cK() { return true; -@@ -2861,4 +2974,30 @@ +@@ -2861,4 +2975,30 @@ public void func_191987_a(BlockPos p_191987_1_, boolean p_191987_2_) { } diff --git a/patches/minecraft/net/minecraft/item/Item.java.patch b/patches/minecraft/net/minecraft/item/Item.java.patch index 982b55282f..2cd2c8085f 100644 --- a/patches/minecraft/net/minecraft/item/Item.java.patch +++ b/patches/minecraft/net/minecraft/item/Item.java.patch @@ -68,7 +68,7 @@ CreativeTabs creativetabs = this.func_77640_w(); return creativetabs != null && (p_194125_1_ == CreativeTabs.field_78027_g || p_194125_1_ == creativetabs); } -@@ -435,11 +441,766 @@ +@@ -435,11 +441,779 @@ return false; } @@ -698,6 +698,19 @@ + } + + /** ++ * Called while an item is in 'active' use to determine if usage should continue. ++ * Allows items to continue being used while sustaining damage, for example. ++ * ++ * @param oldStack the previous 'active' stack ++ * @param newStack the stack currently in the active hand ++ * @return true to set the new stack to active and continue using it ++ */ ++ public boolean canContinueUsing(ItemStack oldStack, ItemStack newStack) ++ { ++ return oldStack.equals(newStack); ++ } ++ ++ /** + * Called to get the Mod ID of the mod that *created* the ItemStack, + * instead of the real Mod ID that *registered* it. + * @@ -835,7 +848,7 @@ public static void func_150900_l() { func_179214_a(Blocks.field_150350_a, new ItemAir(Blocks.field_150350_a)); -@@ -999,6 +1760,8 @@ +@@ -999,6 +1773,8 @@ private final float field_78010_h; private final float field_78011_i; private final int field_78008_j; @@ -844,7 +857,7 @@ private ToolMaterial(int p_i1874_3_, int p_i1874_4_, float p_i1874_5_, float p_i1874_6_, int p_i1874_7_) { -@@ -1034,6 +1797,7 @@ +@@ -1034,6 +1810,7 @@ return this.field_78008_j; } @@ -852,7 +865,7 @@ public Item func_150995_f() { if (this == WOOD) -@@ -1057,5 +1821,21 @@ +@@ -1057,5 +1834,21 @@ return this == DIAMOND ? Items.field_151045_i : null; } } diff --git a/src/main/java/net/minecraftforge/common/ForgeHooks.java b/src/main/java/net/minecraftforge/common/ForgeHooks.java index cf14b94cf3..f192a84a00 100644 --- a/src/main/java/net/minecraftforge/common/ForgeHooks.java +++ b/src/main/java/net/minecraftforge/common/ForgeHooks.java @@ -195,6 +195,15 @@ public class ForgeHooks return entry.getStack(rand, fortune); } + public static boolean canContinueUsing(@Nonnull ItemStack from, @Nonnull ItemStack to) + { + if (!from.isEmpty() && !to.isEmpty()) + { + return from.getItem().canContinueUsing(from, to); + } + return false; + } + private static boolean toolInit = false; //static HashSet toolEffectiveness = new HashSet(); diff --git a/src/test/java/net/minecraftforge/debug/item/ContinuousUseItemTest.java b/src/test/java/net/minecraftforge/debug/item/ContinuousUseItemTest.java new file mode 100644 index 0000000000..02c02db268 --- /dev/null +++ b/src/test/java/net/minecraftforge/debug/item/ContinuousUseItemTest.java @@ -0,0 +1,133 @@ +/* + * Minecraft Forge + * Copyright (c) 2016-2018. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +package net.minecraftforge.debug.item; + +import net.minecraft.client.renderer.block.model.ModelResourceLocation; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.EnumAction; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ActionResult; +import net.minecraft.util.EnumActionResult; +import net.minecraft.util.EnumHand; +import net.minecraft.world.World; +import net.minecraftforge.client.event.ModelRegistryEvent; +import net.minecraftforge.client.model.ModelLoader; +import net.minecraftforge.event.RegistryEvent; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.registry.GameRegistry; +import net.minecraftforge.fml.relauncher.Side; + +@Mod(modid = ContinuousUseItemTest.MOD_ID, name = "Test for canContinueUsing", version = "1.0", acceptableRemoteVersions = "*") +@Mod.EventBusSubscriber +public class ContinuousUseItemTest +{ + static final String MOD_ID = "continuous_use_item_test"; + static final boolean ENABLED = false; + + @GameRegistry.ObjectHolder(TestItem.NAME) + public static final Item TEST_ITEM = null; + + @SubscribeEvent + public static void registerItem(RegistryEvent.Register event) + { + if (ENABLED) + { + event.getRegistry().register( + new TestItem().setRegistryName(MOD_ID, TestItem.NAME) + .setUnlocalizedName(MOD_ID + "." + TestItem.NAME) + .setCreativeTab(CreativeTabs.MISC) + ); + } + } + + @Mod.EventBusSubscriber(value = Side.CLIENT, modid = MOD_ID) + public static class ClientEventHandler + { + @SubscribeEvent + public static void registerModels(ModelRegistryEvent event) + { + if (ENABLED) + { + ModelLoader.setCustomModelResourceLocation(TEST_ITEM, 0, new ModelResourceLocation("minecraft:stick", "inventory")); + } + } + } + + static class TestItem extends Item + { + static final String NAME = "test_item"; + + TestItem() + { + maxStackSize = 1; + setMaxDamage(60); + } + + @Override + public boolean hasEffect(ItemStack stack) + { + return true; + } + + @Override + public EnumAction getItemUseAction(ItemStack stack) + { + return EnumAction.BOW; + } + + @Override + public int getMaxItemUseDuration(ItemStack stack) + { + return 72000; + } + + @Override + public ActionResult onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) + { + playerIn.setActiveHand(handIn); + return new ActionResult<>(EnumActionResult.SUCCESS, playerIn.getHeldItem(handIn)); + } + + @Override + public void onUsingTick(ItemStack stack, EntityLivingBase living, int count) + { + if (count % 10 == 0) + { + stack.damageItem(1, living); + } + } + + @Override + public boolean shouldCauseReequipAnimation(ItemStack oldStack, ItemStack newStack, boolean slotChanged) + { + return slotChanged || oldStack.getItem() != newStack.getItem(); + } + + @Override + public boolean canContinueUsing(ItemStack oldStack, ItemStack newStack) + { + return oldStack.getItem() == newStack.getItem(); + } + } +}