Skip to content

Commit

Permalink
Fix slimeboots & slimesling (#63)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
Co-authored-by: GitHub GTNH Actions <>

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
mitchej123 and github-actions[bot] authored Jan 4, 2023
1 parent bdc7077 commit bb87654
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
5 changes: 3 additions & 2 deletions src/main/java/tconstruct/gadgets/TinkerGadgets.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -32,14 +32,15 @@ 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");
}

@Handler
public void init(FMLInitializationEvent event) {
log.info("Init");
String ore = "blockSlime";

GameRegistry.addRecipe(
Expand Down
16 changes: 10 additions & 6 deletions src/main/java/tconstruct/gadgets/item/ItemSlimeBoots.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -109,22 +109,26 @@ 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);
// TinkerGadgets.log.info("Player");
} 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.");
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/tconstruct/library/SlimeBounceHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit bb87654

Please sign in to comment.