From cbe8ec4c063eaf6b9dd7945340c4e3e1f862b8e2 Mon Sep 17 00:00:00 2001 From: Hileb <107909747+Ecdcaeb@users.noreply.github.com> Date: Sun, 21 Jan 2024 10:06:18 +0800 Subject: [PATCH 1/4] set up IForgeAction --- .../renderer/entity/RenderPlayer.java.patch | 24 +++++++++++++---- .../entity/EntityLivingBase.java.patch | 22 ++++++++++----- .../net/minecraft/item/EnumAction.java.patch | 27 +++++++++++++++++++ .../minecraftforge/common/IForgeAction.java | 25 +++++++++++++++++ 4 files changed, 86 insertions(+), 12 deletions(-) create mode 100644 patches/minecraft/net/minecraft/item/EnumAction.java.patch create mode 100644 src/main/java/net/minecraftforge/common/IForgeAction.java diff --git a/patches/minecraft/net/minecraft/client/renderer/entity/RenderPlayer.java.patch b/patches/minecraft/net/minecraft/client/renderer/entity/RenderPlayer.java.patch index cffb4b249..0a4475fd9 100644 --- a/patches/minecraft/net/minecraft/client/renderer/entity/RenderPlayer.java.patch +++ b/patches/minecraft/net/minecraft/client/renderer/entity/RenderPlayer.java.patch @@ -24,7 +24,21 @@ } private void func_177137_d(AbstractClientPlayer p_177137_1_) -@@ -128,6 +130,11 @@ +@@ -104,6 +106,7 @@ + if (p_177137_1_.func_184605_cv() > 0) + { + EnumAction enumaction = itemstack.func_77975_n(); ++ modelbiped$armpose=enumaction.getBipedArmPose(); + + if (enumaction == EnumAction.BLOCK) + { +@@ -123,11 +126,17 @@ + if (p_177137_1_.func_184605_cv() > 0) + { + EnumAction enumaction1 = itemstack1.func_77975_n(); ++ modelbiped$armpose1=enumaction1.getBipedArmPose(); + + if (enumaction1 == EnumAction.BLOCK) { modelbiped$armpose1 = ModelBiped.ArmPose.BLOCK; } @@ -36,7 +50,7 @@ } } -@@ -149,7 +156,6 @@ +@@ -149,7 +158,6 @@ return p_110775_1_.func_110306_p(); } @@ -44,7 +58,7 @@ public void func_82422_c() { GlStateManager.func_179109_b(0.0F, 0.1875F, 0.0F); -@@ -161,11 +167,9 @@ +@@ -161,11 +169,9 @@ GlStateManager.func_179152_a(0.9375F, 0.9375F, 0.9375F); } @@ -58,7 +72,7 @@ { Scoreboard scoreboard = p_188296_1_.func_96123_co(); ScoreObjective scoreobjective = scoreboard.func_96539_a(2); -@@ -221,12 +225,7 @@ +@@ -221,12 +227,7 @@ { if (p_77039_1_.func_70089_S() && p_77039_1_.func_70608_bn()) { @@ -72,7 +86,7 @@ } else { -@@ -252,11 +251,11 @@ +@@ -252,11 +253,11 @@ double d0 = p_77043_1_.field_70159_w * p_77043_1_.field_70159_w + p_77043_1_.field_70179_y * p_77043_1_.field_70179_y; double d1 = vec3d.field_72450_a * vec3d.field_72450_a + vec3d.field_72449_c * vec3d.field_72449_c; diff --git a/patches/minecraft/net/minecraft/entity/EntityLivingBase.java.patch b/patches/minecraft/net/minecraft/entity/EntityLivingBase.java.patch index 8292bcab7..53d4aecaf 100644 --- a/patches/minecraft/net/minecraft/entity/EntityLivingBase.java.patch +++ b/patches/minecraft/net/minecraft/entity/EntityLivingBase.java.patch @@ -1458,7 +1458,15 @@ public void func_184206_a(DataParameter p_184206_1_) { super.func_184206_a(p_184206_1_); -@@ -2785,51 +2756,26 @@ +@@ -2776,6 +2747,7 @@ + { + if (!p_184584_1_.func_190926_b() && this.func_184587_cr()) + { ++ p_184584_1_.func_77975_n().updateItemUse(p_184584_1_,p_184584_2_); + if (p_184584_1_.func_77975_n() == EnumAction.DRINK) + { + this.func_184185_a(SoundEvents.field_187664_bz, 0.5F, this.field_70170_p.field_73012_v.nextFloat() * 0.1F + 0.9F); +@@ -2785,51 +2757,26 @@ { for (int i = 0; i < p_184584_2_; ++i) { @@ -1520,7 +1528,7 @@ } } } -@@ -2839,7 +2785,10 @@ +@@ -2839,7 +2786,10 @@ if (!this.field_184627_bm.func_190926_b() && this.func_184587_cr()) { this.func_184584_a(this.field_184627_bm, 16); @@ -1532,7 +1540,7 @@ this.func_184602_cy(); } } -@@ -2863,7 +2812,8 @@ +@@ -2863,7 +2813,8 @@ { if (!this.field_184627_bm.func_190926_b()) { @@ -1542,7 +1550,7 @@ } this.func_184602_cy(); -@@ -2873,7 +2823,7 @@ +@@ -2873,7 +2824,7 @@ { if (!this.field_70170_p.field_72995_K) { @@ -1551,7 +1559,7 @@ } this.field_184627_bm = ItemStack.field_190927_a; -@@ -2967,13 +2917,13 @@ +@@ -2967,13 +2918,13 @@ for (int j = 0; j < 128; ++j) { @@ -1568,7 +1576,7 @@ world.func_175688_a(EnumParticleTypes.PORTAL, d3, d4, d5, (double)f, (double)f1, (double)f2); } -@@ -2991,6 +2941,31 @@ +@@ -2991,6 +2942,31 @@ return true; } @@ -1600,7 +1608,7 @@ public boolean func_190631_cK() { return true; -@@ -2999,5 +2974,31 @@ +@@ -2999,5 +2975,31 @@ @SideOnly(Side.CLIENT) public void func_191987_a(BlockPos p_191987_1_, boolean p_191987_2_) { diff --git a/patches/minecraft/net/minecraft/item/EnumAction.java.patch b/patches/minecraft/net/minecraft/item/EnumAction.java.patch new file mode 100644 index 000000000..0bf9f5c99 --- /dev/null +++ b/patches/minecraft/net/minecraft/item/EnumAction.java.patch @@ -0,0 +1,27 @@ +--- before/net/minecraft/item/EnumAction.java ++++ after/net/minecraft/item/EnumAction.java +@@ -1,10 +1,23 @@ + package net.minecraft.item; + +-public enum EnumAction ++public enum EnumAction implements net.minecraftforge.common.IForgeAction + { + NONE, + EAT, + DRINK, + BLOCK, + BOW; ++ //========FORGE START========// ++ private final net.minecraftforge.common.IForgeAction action; ++ EnumAction(net.minecraftforge.common.IForgeAction actionIn){action=actionIn;} ++ EnumAction(){this(net.minecraftforge.common.IForgeAction.EMPTY);} ++ @Override ++ public void updateItemUse(ItemStack stack, int eatingParticleCount) { ++ action.updateItemUse(stack,eatingParticleCount); ++ } ++ @net.minecraftforge.fml.relauncher.SideOnly(net.minecraftforge.fml.relauncher.Side.CLIENT) ++ @Override ++ public net.minecraft.client.model.ModelBiped.ArmPose getBipedArmPose() { ++ return action.getBipedArmPose(); ++ } + } diff --git a/src/main/java/net/minecraftforge/common/IForgeAction.java b/src/main/java/net/minecraftforge/common/IForgeAction.java new file mode 100644 index 000000000..083bcf404 --- /dev/null +++ b/src/main/java/net/minecraftforge/common/IForgeAction.java @@ -0,0 +1,25 @@ +package net.minecraftforge.common; + +import net.minecraft.client.model.ModelBiped; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +public interface IForgeAction { + IForgeAction EMPTY=new IForgeAction() {}; + + /** + * @return The ArmPose used for render.
+ * for example {@link ModelBiped.ArmPose#BOW_AND_ARROW} for {@link net.minecraft.init.Items#BOW} + */ + @SideOnly(Side.CLIENT) + default ModelBiped.ArmPose getBipedArmPose(){ + return ModelBiped.ArmPose.ITEM; + } + + /** + * @param stack the stack is being used by player. + * @param eatingParticleCount count.
Use finish:16.
When the usage time does not exceed 25 hours, one quarter of every 4 is 4, and the rest is 0 + */ + default void updateItemUse(ItemStack stack, int eatingParticleCount){} +} From a7bfb142bc62e0d7a728060b2fd05d62389b3f12 Mon Sep 17 00:00:00 2001 From: Hileb <107909747+Ecdcaeb@users.noreply.github.com> Date: Sun, 21 Jan 2024 10:52:19 +0800 Subject: [PATCH 2/4] IForgeArmPose --- .../client/model/ModelBiped.java.patch | 33 +++++++++++++++++++ .../client/EnumHelperClient.java | 8 +++++ .../client/model/IForgeArmPose.java | 15 +++++++++ .../common/util/EnumHelper.java | 8 +++++ 4 files changed, 64 insertions(+) create mode 100644 patches/minecraft/net/minecraft/client/model/ModelBiped.java.patch create mode 100644 src/main/java/net/minecraftforge/client/model/IForgeArmPose.java diff --git a/patches/minecraft/net/minecraft/client/model/ModelBiped.java.patch b/patches/minecraft/net/minecraft/client/model/ModelBiped.java.patch new file mode 100644 index 000000000..f65af7fa4 --- /dev/null +++ b/patches/minecraft/net/minecraft/client/model/ModelBiped.java.patch @@ -0,0 +1,33 @@ +--- before/net/minecraft/client/model/ModelBiped.java ++++ after/net/minecraft/client/model/ModelBiped.java +@@ -267,6 +267,8 @@ + this.field_178723_h.field_78795_f = (float)(-Math.PI / 2) + this.field_78116_c.field_78795_f; + this.field_178724_i.field_78795_f = (float)(-Math.PI / 2) + this.field_78116_c.field_78795_f; + } ++ this.field_187075_l.setRotationAnglesLeftHand(this,p_78087_1_,p_78087_2_,p_78087_3_,p_78087_4_,p_78087_5_,p_78087_6_,p_78087_7_); ++ this.field_187076_m.setRotationAnglesRightHand(this,p_78087_1_,p_78087_2_,p_78087_3_,p_78087_4_,p_78087_5_,p_78087_6_,p_78087_7_); + + func_178685_a(this.field_78116_c, this.field_178720_f); + } +@@ -321,11 +323,20 @@ + } + + @SideOnly(Side.CLIENT) +- public static enum ArmPose ++ public static enum ArmPose implements net.minecraftforge.client.model.IForgeArmPose + { + EMPTY, + ITEM, + BLOCK, + BOW_AND_ARROW; ++ //=======FORGE START=======// ++ private final net.minecraftforge.client.model.IForgeArmPose pose; ++ ArmPose(net.minecraftforge.client.model.IForgeArmPose poseIn){pose=poseIn;} ++ ArmPose(){this(net.minecraftforge.client.model.IForgeArmPose.EMPTY);} ++ @Override ++ public void setRotationAnglesLeftHand(net.minecraft.client.model.ModelBiped modelBiped, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch, float scaleFactor, net.minecraft.entity.Entity entityIn) {pose.setRotationAnglesLeftHand(modelBiped, limbSwing, limbSwingAmount, ageInTicks, netHeadYaw, headPitch, scaleFactor, entityIn);} ++ @Override ++ public void setRotationAnglesRightHand(net.minecraft.client.model.ModelBiped modelBiped, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch, float scaleFactor, net.minecraft.entity.Entity entityIn) {pose.setRotationAnglesRightHand(modelBiped, limbSwing, limbSwingAmount, ageInTicks, netHeadYaw, headPitch, scaleFactor, entityIn);} ++ //=======FORGE END=========// + } + } diff --git a/src/main/java/net/minecraftforge/client/EnumHelperClient.java b/src/main/java/net/minecraftforge/client/EnumHelperClient.java index 4117cc0d7..69c84f229 100644 --- a/src/main/java/net/minecraftforge/client/EnumHelperClient.java +++ b/src/main/java/net/minecraftforge/client/EnumHelperClient.java @@ -21,10 +21,12 @@ import com.cleanroommc.hackery.enums.EnumHackery; import net.minecraft.client.audio.MusicTicker; +import net.minecraft.client.model.ModelBiped; import net.minecraft.util.SoundEvent; import net.minecraft.util.Util.EnumOS; import net.minecraft.world.GameType; import net.minecraft.client.settings.GameSettings.Options; +import net.minecraftforge.client.model.IForgeArmPose; import net.minecraftforge.common.util.EnumHelper; import javax.annotation.Nullable; @@ -39,6 +41,12 @@ public class EnumHelperClient extends EnumHelper {MusicTicker.MusicType.class, SoundEvent.class, int.class, int.class} }; + public static ModelBiped.ArmPose addArmPose(String name, IForgeArmPose pose){ + return EnumHackery.addEnumEntry(ModelBiped.ArmPose.class, name, + new Class[]{IForgeArmPose.class}, + new Object[]{pose}); + } + @Nullable public static GameType addGameType(String name, int id, String displayName, String shortName) { diff --git a/src/main/java/net/minecraftforge/client/model/IForgeArmPose.java b/src/main/java/net/minecraftforge/client/model/IForgeArmPose.java new file mode 100644 index 000000000..3c0317f98 --- /dev/null +++ b/src/main/java/net/minecraftforge/client/model/IForgeArmPose.java @@ -0,0 +1,15 @@ +package net.minecraftforge.client.model; + +import net.minecraft.client.model.ModelBiped; +import net.minecraft.entity.Entity; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +@SideOnly(Side.CLIENT) +public interface IForgeArmPose { + IForgeArmPose EMPTY=new IForgeArmPose() {}; + default void setRotationAnglesLeftHand(ModelBiped modelBiped,float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch, float scaleFactor, Entity entityIn) { + } + default void setRotationAnglesRightHand(ModelBiped modelBiped,float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch, float scaleFactor, Entity entityIn) { + } +} diff --git a/src/main/java/net/minecraftforge/common/util/EnumHelper.java b/src/main/java/net/minecraftforge/common/util/EnumHelper.java index 1559d6703..36912adf9 100644 --- a/src/main/java/net/minecraftforge/common/util/EnumHelper.java +++ b/src/main/java/net/minecraftforge/common/util/EnumHelper.java @@ -28,6 +28,7 @@ import com.google.common.base.Predicate; import com.google.common.collect.Lists; +import net.minecraftforge.common.IForgeAction; import net.minecraftforge.fml.common.EnhancedRuntimeException; import net.minecraftforge.fml.common.FMLLog; import net.minecraft.block.BlockPressurePlate.Sensitivity; @@ -86,6 +87,13 @@ public static EnumAction addAction(String name) return EnumHackery.addEnumEntry(EnumAction.class, name); } @Nullable + public static EnumAction addAction(String name, IForgeAction action) + { + return EnumHackery.addEnumEntry(EnumAction.class, name, + new Class[]{IForgeAction.class}, + new Object[]{action}); + } + @Nullable public static ArmorMaterial addArmorMaterial(String name, String textureName, int durability, int[] reductionAmounts, int enchantability, SoundEvent soundOnEquip, float toughness) { return EnumHackery.addEnumEntry(ArmorMaterial.class, name, From 19f3e02885e5376320204e4a33212365f0ba8b78 Mon Sep 17 00:00:00 2001 From: Hileb <107909747+Ecdcaeb@users.noreply.github.com> Date: Sun, 21 Jan 2024 11:15:04 +0800 Subject: [PATCH 3/4] Update IForgeAction.java --- src/main/java/net/minecraftforge/common/IForgeAction.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/minecraftforge/common/IForgeAction.java b/src/main/java/net/minecraftforge/common/IForgeAction.java index 083bcf404..b62f83f71 100644 --- a/src/main/java/net/minecraftforge/common/IForgeAction.java +++ b/src/main/java/net/minecraftforge/common/IForgeAction.java @@ -19,7 +19,7 @@ default ModelBiped.ArmPose getBipedArmPose(){ /** * @param stack the stack is being used by player. - * @param eatingParticleCount count.
Use finish:16.
When the usage time does not exceed 25 hours, one quarter of every 4 is 4, and the rest is 0 + * @param eatingParticleCount count.
Use finish:16.
When the usage time does not exceed 25 ticks, one tick of every 4 ticks is 4, and the rest is 0 */ default void updateItemUse(ItemStack stack, int eatingParticleCount){} } From 03b7f5127ab80aa18752b7a89dbb85f43875297d Mon Sep 17 00:00:00 2001 From: Hileb <107909747+Ecdcaeb@users.noreply.github.com> Date: Sat, 26 Oct 2024 20:24:06 +0800 Subject: [PATCH 4/4] reformat --- .../net/minecraft/client/model/ModelBiped.java.patch | 6 +++--- .../client/renderer/entity/RenderPlayer.java.patch | 4 ++-- .../java/net/minecraftforge/client/model/IForgeArmPose.java | 2 +- src/main/java/net/minecraftforge/common/IForgeAction.java | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/patches/minecraft/net/minecraft/client/model/ModelBiped.java.patch b/patches/minecraft/net/minecraft/client/model/ModelBiped.java.patch index f65af7fa4..782f08c3a 100644 --- a/patches/minecraft/net/minecraft/client/model/ModelBiped.java.patch +++ b/patches/minecraft/net/minecraft/client/model/ModelBiped.java.patch @@ -4,8 +4,8 @@ this.field_178723_h.field_78795_f = (float)(-Math.PI / 2) + this.field_78116_c.field_78795_f; this.field_178724_i.field_78795_f = (float)(-Math.PI / 2) + this.field_78116_c.field_78795_f; } -+ this.field_187075_l.setRotationAnglesLeftHand(this,p_78087_1_,p_78087_2_,p_78087_3_,p_78087_4_,p_78087_5_,p_78087_6_,p_78087_7_); -+ this.field_187076_m.setRotationAnglesRightHand(this,p_78087_1_,p_78087_2_,p_78087_3_,p_78087_4_,p_78087_5_,p_78087_6_,p_78087_7_); ++ this.field_187075_l.setRotationAnglesLeftHand(this,p_78087_1_, p_78087_2_, p_78087_3_, p_78087_4_, p_78087_5_, p_78087_6_, p_78087_7_); ++ this.field_187076_m.setRotationAnglesRightHand(this,p_78087_1_, p_78087_2_, p_78087_3_, p_78087_4_, p_78087_5_, p_78087_6_, p_78087_7_); func_178685_a(this.field_78116_c, this.field_178720_f); } @@ -22,7 +22,7 @@ BOW_AND_ARROW; + //=======FORGE START=======// + private final net.minecraftforge.client.model.IForgeArmPose pose; -+ ArmPose(net.minecraftforge.client.model.IForgeArmPose poseIn){pose=poseIn;} ++ ArmPose(net.minecraftforge.client.model.IForgeArmPose poseIn){pose = poseIn;} + ArmPose(){this(net.minecraftforge.client.model.IForgeArmPose.EMPTY);} + @Override + public void setRotationAnglesLeftHand(net.minecraft.client.model.ModelBiped modelBiped, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch, float scaleFactor, net.minecraft.entity.Entity entityIn) {pose.setRotationAnglesLeftHand(modelBiped, limbSwing, limbSwingAmount, ageInTicks, netHeadYaw, headPitch, scaleFactor, entityIn);} diff --git a/patches/minecraft/net/minecraft/client/renderer/entity/RenderPlayer.java.patch b/patches/minecraft/net/minecraft/client/renderer/entity/RenderPlayer.java.patch index 0a4475fd9..dada6a88f 100644 --- a/patches/minecraft/net/minecraft/client/renderer/entity/RenderPlayer.java.patch +++ b/patches/minecraft/net/minecraft/client/renderer/entity/RenderPlayer.java.patch @@ -28,7 +28,7 @@ if (p_177137_1_.func_184605_cv() > 0) { EnumAction enumaction = itemstack.func_77975_n(); -+ modelbiped$armpose=enumaction.getBipedArmPose(); ++ modelbiped$armpose = enumaction.getBipedArmPose(); if (enumaction == EnumAction.BLOCK) { @@ -36,7 +36,7 @@ if (p_177137_1_.func_184605_cv() > 0) { EnumAction enumaction1 = itemstack1.func_77975_n(); -+ modelbiped$armpose1=enumaction1.getBipedArmPose(); ++ modelbiped$armpose1 = enumaction1.getBipedArmPose(); if (enumaction1 == EnumAction.BLOCK) { diff --git a/src/main/java/net/minecraftforge/client/model/IForgeArmPose.java b/src/main/java/net/minecraftforge/client/model/IForgeArmPose.java index 3c0317f98..e2081cebd 100644 --- a/src/main/java/net/minecraftforge/client/model/IForgeArmPose.java +++ b/src/main/java/net/minecraftforge/client/model/IForgeArmPose.java @@ -7,7 +7,7 @@ @SideOnly(Side.CLIENT) public interface IForgeArmPose { - IForgeArmPose EMPTY=new IForgeArmPose() {}; + IForgeArmPose EMPTY = new IForgeArmPose() {}; default void setRotationAnglesLeftHand(ModelBiped modelBiped,float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch, float scaleFactor, Entity entityIn) { } default void setRotationAnglesRightHand(ModelBiped modelBiped,float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch, float scaleFactor, Entity entityIn) { diff --git a/src/main/java/net/minecraftforge/common/IForgeAction.java b/src/main/java/net/minecraftforge/common/IForgeAction.java index b62f83f71..f64d4b3c0 100644 --- a/src/main/java/net/minecraftforge/common/IForgeAction.java +++ b/src/main/java/net/minecraftforge/common/IForgeAction.java @@ -6,7 +6,7 @@ import net.minecraftforge.fml.relauncher.SideOnly; public interface IForgeAction { - IForgeAction EMPTY=new IForgeAction() {}; + IForgeAction EMPTY = new IForgeAction() {}; /** * @return The ArmPose used for render.