From bb87654862554ed38acdce3fd964fbfe2754f021 Mon Sep 17 00:00:00 2001 From: Jason Mitchell Date: Wed, 4 Jan 2023 07:36:50 -0800 Subject: [PATCH] Fix slimeboots & slimesling (#63) * Fix slimeboots & slimesling * Use vec3 instead of Vector3d which isn't found on the server * set entity.motionXYZ manually, as setVelocity is ClientOnly * spotlessApply (#64) Co-authored-by: Jason Mitchell Co-authored-by: GitHub GTNH Actions <> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .../java/tconstruct/gadgets/TinkerGadgets.java | 5 +++-- .../tconstruct/gadgets/item/ItemSlimeBoots.java | 16 ++++++++++------ .../tconstruct/library/SlimeBounceHandler.java | 11 ++++++----- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/main/java/tconstruct/gadgets/TinkerGadgets.java b/src/main/java/tconstruct/gadgets/TinkerGadgets.java index f756205fc45..63db7a60e76 100644 --- a/src/main/java/tconstruct/gadgets/TinkerGadgets.java +++ b/src/main/java/tconstruct/gadgets/TinkerGadgets.java @@ -20,7 +20,7 @@ import tconstruct.library.SlimeBounceHandler; import tconstruct.library.TConstructRegistry; -@Pulse(id = "Tinkers' Gadgets", description = "All the fun toys.") +@Pulse(id = "Tinkers' Gadgets", description = "All the fun toys.", forced = true) public class TinkerGadgets { public static final String PulseId = "TinkerGadgets"; @@ -32,7 +32,7 @@ public class TinkerGadgets { @Handler public void preInit(FMLPreInitializationEvent event) { - + log.info("Pre Init"); SlimeBounceHandler.init(); slimeSling = registerItem(new ItemSlimeSling(), "slimesling"); slimeBoots = registerItem(new ItemSlimeBoots(), "slime_boots"); @@ -40,6 +40,7 @@ public void preInit(FMLPreInitializationEvent event) { @Handler public void init(FMLInitializationEvent event) { + log.info("Init"); String ore = "blockSlime"; GameRegistry.addRecipe( diff --git a/src/main/java/tconstruct/gadgets/item/ItemSlimeBoots.java b/src/main/java/tconstruct/gadgets/item/ItemSlimeBoots.java index bb5c6f57a62..5710d7df7d0 100644 --- a/src/main/java/tconstruct/gadgets/item/ItemSlimeBoots.java +++ b/src/main/java/tconstruct/gadgets/item/ItemSlimeBoots.java @@ -4,7 +4,6 @@ import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import java.util.List; -import javax.vecmath.Vector3d; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.client.resources.I18n; @@ -19,6 +18,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.util.DamageSource; import net.minecraft.util.IIcon; +import net.minecraft.util.Vec3; import net.minecraft.world.World; import net.minecraftforge.common.ISpecialArmor; import net.minecraftforge.common.util.EnumHelper; @@ -76,7 +76,7 @@ public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPl @SubscribeEvent // RUBBERY BOUNCY BOUNCERY WOOOOO public void onFall(LivingFallEvent event) { - EntityLivingBase living = event.entityLiving; + final EntityLivingBase living = event.entityLiving; // TinkerGadgets.log.info("Fall event."); // using fall distance as the event distance could be reduced by jump boost if (living == null || living.fallDistance <= 2f) { @@ -109,13 +109,15 @@ public void onFall(LivingFallEvent event) { // server players behave differently than non-server players, they have no // velocity during the event, so we need to reverse engineer it - Vector3d motion = SlimeBounceHandler.getMotion(living); + Vec3 motion = SlimeBounceHandler.getMotion(living); if (living instanceof EntityPlayerMP) { // velocity is lost on server players, but we dont have to defer the bounce double gravity = 0.2353455252; double time = Math.sqrt(living.fallDistance / gravity); double velocity = gravity * time; - living.setVelocity(motion.x / 0.95f, velocity, motion.z / 0.95f); + living.motionX = motion.xCoord / 0.95f; + living.motionY = velocity; + living.motionZ = motion.zCoord / 0.95f; living.velocityChanged = true; // preserve momentum SlimeBounceHandler.addBounceHandler(living); @@ -123,8 +125,10 @@ public void onFall(LivingFallEvent event) { } else { // for non-players, need to defer the bounce // only slow down half as much when bouncing - living.setVelocity(motion.x / 0.95f, motion.y * -0.9, motion.z / 0.95f); - SlimeBounceHandler.addBounceHandler(living, SlimeBounceHandler.getMotion(living).y); + living.motionX = motion.xCoord / 0.95f; + living.motionY = motion.yCoord * -0.9; + living.motionZ = motion.zCoord / 0.95f; + SlimeBounceHandler.addBounceHandler(living, SlimeBounceHandler.getMotion(living).yCoord); // TinkerGadgets.log.info("Not Player"); } // TinkerGadgets.log.info("Server Fall Handler."); diff --git a/src/main/java/tconstruct/library/SlimeBounceHandler.java b/src/main/java/tconstruct/library/SlimeBounceHandler.java index 9b91df90a78..bbce654ed3b 100644 --- a/src/main/java/tconstruct/library/SlimeBounceHandler.java +++ b/src/main/java/tconstruct/library/SlimeBounceHandler.java @@ -3,9 +3,9 @@ import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import java.util.IdentityHashMap; -import javax.vecmath.Vector3d; import net.minecraft.entity.EntityLivingBase; import net.minecraft.item.ItemStack; +import net.minecraft.util.Vec3; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.util.FakePlayer; import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent; @@ -122,7 +122,7 @@ public void onLivingTick(LivingUpdateEvent event) { // resets y motion after landing if (entity.ticksExisted == info.bounceTick) { TinkerGadgets.log.info("Bounce Tick?"); - entity.setVelocity(entity.motionX, info.bounce, entity.motionZ); + entity.motionY = info.bounce; info.bounceTick = 0; } @@ -145,7 +145,8 @@ public void onLivingTick(LivingUpdateEvent event) { // preserve 95% of former speed double boost = Math.sqrt(info.lastMagSq / motionSq) * 0.95f; if (boost > 1) { - entity.setVelocity(entity.motionX * boost, entity.motionY, entity.motionZ * boost); + entity.motionX *= boost; + entity.motionZ *= boost; entity.isAirBorne = true; info.lastMagSq = info.lastMagSq * 0.95f * 0.95f; // play sound if we had a big angle change @@ -181,8 +182,8 @@ public void onLivingTick(LivingUpdateEvent event) { } } - public static Vector3d getMotion(EntityLivingBase aEntity) { - return new Vector3d(aEntity.motionX, aEntity.motionY, aEntity.motionZ); + public static Vec3 getMotion(EntityLivingBase aEntity) { + return Vec3.createVectorHelper(aEntity.motionX, aEntity.motionY, aEntity.motionZ); } public static boolean hasSlimeBoots(EntityLivingBase entity) {