diff --git a/src/main/java/net/F53/HorseBuff/ClientInit.java b/src/main/java/net/F53/HorseBuff/ClientInit.java index 1cf37af..a31ba38 100644 --- a/src/main/java/net/F53/HorseBuff/ClientInit.java +++ b/src/main/java/net/F53/HorseBuff/ClientInit.java @@ -7,7 +7,6 @@ import org.lwjgl.glfw.GLFW; public class ClientInit implements ClientModInitializer { - public static KeyBinding horsePlayerInventory = KeyBindingHelper.registerKeyBinding(new KeyBinding( "text.HorseBuff.keybinding.horsePlayerInventory", InputUtil.Type.KEYSYM, diff --git a/src/main/java/net/F53/HorseBuff/mixin/Client/HorseRenderer.java b/src/main/java/net/F53/HorseBuff/mixin/Client/HorseRenderer.java index 07e4c3e..bea86d2 100644 --- a/src/main/java/net/F53/HorseBuff/mixin/Client/HorseRenderer.java +++ b/src/main/java/net/F53/HorseBuff/mixin/Client/HorseRenderer.java @@ -13,54 +13,62 @@ import net.minecraft.entity.LivingEntity; import net.minecraft.entity.passive.AbstractHorseEntity; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.*; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.ModifyArgs; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.invoke.arg.Args; import java.awt.*; -import static net.F53.HorseBuff.utils.RenderUtils.*; +import static net.F53.HorseBuff.utils.RenderUtils.getOpacity; +import static net.F53.HorseBuff.utils.RenderUtils.isJeb; @Mixin(value = LivingEntityRenderer.class, priority = 960) public abstract class HorseRenderer> { + @Unique + private boolean hb$isHorse; - private boolean isHorse; + @Unique + private float hb$opacity; - private float opacity; - - private float r; - private float g; - private float b; + @Unique + private float hb$r; + @Unique + private float hb$g; + @Unique + private float hb$b; @Inject(method = "render(Lnet/minecraft/entity/LivingEntity;FFLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V", - at = @At("HEAD")) + at = @At("HEAD")) void fetchOpacityAndJeb(T livingEntity, float yaw, float tickDelta, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int light, CallbackInfo ci) { - isHorse = false; - opacity = 1; - r = 1; - g = 1; - b = 1; + hb$isHorse = false; + hb$opacity = 1; + hb$r = 1; + hb$g = 1; + hb$b = 1; if (livingEntity instanceof AbstractHorseEntity) { - isHorse = true; + hb$isHorse = true; if (ModConfig.getInstance().pitchFade.enabled && livingEntity.hasPassenger(MinecraftClient.getInstance().player)) { ClientPlayerEntity player = MinecraftClient.getInstance().player; assert player != null; - opacity = getOpacity(player); + hb$opacity = getOpacity(player); } if (isJeb(livingEntity)) { - float hueOffset = (livingEntity.getUuid().hashCode()%5000)/5000f + (System.currentTimeMillis()%5000)/5000f; + float hueOffset = (livingEntity.getUuid().hashCode() % 5000) / 5000f + (System.currentTimeMillis() % 5000) / 5000f; Color color = new Color(Color.HSBtoRGB(hueOffset, 0.8f, 1)); - r = color.getRed()/255f; - g = color.getGreen()/255f; - b = color.getBlue()/255f; + hb$r = color.getRed() / 255f; + hb$g = color.getGreen() / 255f; + hb$b = color.getBlue() / 255f; } } } @WrapOperation(method = "render(Lnet/minecraft/entity/LivingEntity;FFLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V", - at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/entity/LivingEntityRenderer;getRenderLayer(Lnet/minecraft/entity/LivingEntity;ZZZ)Lnet/minecraft/client/render/RenderLayer;")) + at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/entity/LivingEntityRenderer;getRenderLayer(Lnet/minecraft/entity/LivingEntity;ZZZ)Lnet/minecraft/client/render/RenderLayer;")) RenderLayer makeRenderLayerTranslucent(LivingEntityRenderer> instance, T entity, boolean showBody, boolean translucent, boolean showOutline, Operation original) { - if (showBody && entity instanceof AbstractHorseEntity && opacity < 1) { + if (showBody && entity instanceof AbstractHorseEntity && hb$opacity < 1) { return RenderLayer.getItemEntityTranslucentCull(instance.getTexture(entity)); } else { return original.call(instance, entity, showBody, translucent, showOutline); @@ -68,13 +76,13 @@ RenderLayer makeRenderLayerTranslucent(LivingEntityRenderer horseInstance.getSwimHeight()) { horseInstance.addVelocity(0, 0.08, 0); @@ -28,7 +28,7 @@ private void fakeSwim(PlayerEntity controllingPlayer, Vec3d movementInput, Callb } @Unique - private boolean shouldSwim(AbstractHorseEntity horseInstance) { + private boolean hb$shouldSwim(AbstractHorseEntity horseInstance) { if (horseInstance instanceof HorseEntity || horseInstance instanceof DonkeyEntity || horseInstance instanceof MuleEntity) { diff --git a/src/main/java/net/F53/HorseBuff/mixin/PortalHorse/AllowPortalUse.java b/src/main/java/net/F53/HorseBuff/mixin/PortalHorse/AllowPortalUse.java index 2995f3b..3050282 100644 --- a/src/main/java/net/F53/HorseBuff/mixin/PortalHorse/AllowPortalUse.java +++ b/src/main/java/net/F53/HorseBuff/mixin/PortalHorse/AllowPortalUse.java @@ -10,10 +10,12 @@ import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; @Mixin(AbstractHorseEntity.class) public abstract class AllowPortalUse extends LivingEntity { - @Shadow public abstract @Nullable LivingEntity getControllingPassenger(); + @Shadow + public abstract @Nullable LivingEntity getControllingPassenger(); // constructor to make compiler happy protected AllowPortalUse(EntityType entityType, World world) { @@ -22,7 +24,7 @@ protected AllowPortalUse(EntityType entityType, World wo @Override public boolean canUsePortals() { - if (!this.portalPatchApplies()) + if (!this.hb$portalPatchApplies()) return super.canUsePortals(); return true; @@ -31,7 +33,7 @@ public boolean canUsePortals() { @Override public void setInNetherPortal(BlockPos pos) { // make player inherit horse portal position when mounted - if (this.portalPatchApplies()) + if (this.hb$portalPatchApplies()) this.getControllingPassenger().setInNetherPortal(pos); super.setInNetherPortal(pos); @@ -39,7 +41,7 @@ public void setInNetherPortal(BlockPos pos) { @Override public void resetPortalCooldown() { - if (this.portalPatchApplies()) { + if (this.hb$portalPatchApplies()) { // inherit portal cooldown of controlling passenger this.setPortalCooldown(this.getControllingPassenger().getDefaultPortalCooldown()); return; @@ -47,9 +49,10 @@ public void resetPortalCooldown() { super.resetPortalCooldown(); } - private boolean portalPatchApplies() { + @Unique + private boolean hb$portalPatchApplies() { return (ModConfig.getInstance().portalPatch - && this.hasControllingPassenger() - && this.getControllingPassenger() instanceof PlayerEntity); + && this.hasControllingPassenger() + && this.getControllingPassenger() instanceof PlayerEntity); } } diff --git a/src/main/java/net/F53/HorseBuff/mixin/PortalHorse/OnCollideEnd.java b/src/main/java/net/F53/HorseBuff/mixin/PortalHorse/OnCollideEnd.java index 37b2989..68e4874 100644 --- a/src/main/java/net/F53/HorseBuff/mixin/PortalHorse/OnCollideEnd.java +++ b/src/main/java/net/F53/HorseBuff/mixin/PortalHorse/OnCollideEnd.java @@ -18,8 +18,8 @@ public class OnCollideEnd { public Entity bringRider(Entity vehicle, ServerWorld destination, Operation original) { // guard clause to make vanilla handle natural teleportations if (!(ModConfig.getInstance().portalPatch - && vehicle instanceof AbstractHorseEntity - && vehicle.hasControllingPassenger())) + && vehicle instanceof AbstractHorseEntity + && vehicle.hasControllingPassenger())) return original.call(vehicle, destination); // Teleport then safely rejoin player and vehicle once the game is ready diff --git a/src/main/java/net/F53/HorseBuff/mixin/PortalHorse/TickNether.java b/src/main/java/net/F53/HorseBuff/mixin/PortalHorse/TickNether.java index 5f8b8eb..58b620a 100644 --- a/src/main/java/net/F53/HorseBuff/mixin/PortalHorse/TickNether.java +++ b/src/main/java/net/F53/HorseBuff/mixin/PortalHorse/TickNether.java @@ -1,27 +1,26 @@ package net.F53.HorseBuff.mixin.PortalHorse; import com.llamalad7.mixinextras.sugar.Local; - import net.F53.HorseBuff.config.ModConfig; import net.minecraft.block.BlockState; import net.minecraft.entity.Entity; import net.minecraft.entity.passive.AbstractHorseEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.server.MinecraftServer; -import net.minecraft.server.command.CommandOutput; import net.minecraft.server.world.ServerWorld; -import net.minecraft.util.Nameable; import net.minecraft.util.math.BlockPos; -import net.minecraft.world.entity.EntityLike; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.*; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; import static net.F53.HorseBuff.utils.TeleportHandler.tpAndRemount; @Mixin(Entity.class) -public abstract class TickNether implements Nameable, EntityLike, CommandOutput { - @Shadow protected abstract void fall(double heightDifference, boolean onGround, BlockState state, BlockPos landedPosition); +public abstract class TickNether { + @Shadow + protected abstract void fall(double heightDifference, boolean onGround, BlockState state, BlockPos landedPosition); @Redirect(method = "tickPortal", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;isNetherAllowed()Z")) private boolean tickNether(MinecraftServer minecraftServer, @Local(ordinal = 1) ServerWorld destination) { @@ -30,13 +29,13 @@ private boolean tickNether(MinecraftServer minecraftServer, @Local(ordinal = 1) return false; // ensure horse - if (!((Object) this instanceof AbstractHorseEntity vehicle)) + if (!(hb$thiz() instanceof AbstractHorseEntity vehicle)) return true; // ensure Patch is enabled and player is controlling if (!(ModConfig.getInstance().portalPatch - && vehicle.hasControllingPassenger() - && vehicle.getControllingPassenger() instanceof PlayerEntity player)) + && vehicle.hasControllingPassenger() + && vehicle.getControllingPassenger() instanceof PlayerEntity player)) return true; // manually tick player portal time (it cant go up naturally due to being mounted) @@ -51,4 +50,9 @@ private boolean tickNether(MinecraftServer minecraftServer, @Local(ordinal = 1) // prevent vanilla handling teleportation return false; } + + @Unique + private Entity hb$thiz() { + return ((Entity) (Object) this); + } } diff --git a/src/main/java/net/F53/HorseBuff/mixin/Server/AllowRaft.java b/src/main/java/net/F53/HorseBuff/mixin/Server/AllowRaft.java index 56d5e14..fce8a02 100644 --- a/src/main/java/net/F53/HorseBuff/mixin/Server/AllowRaft.java +++ b/src/main/java/net/F53/HorseBuff/mixin/Server/AllowRaft.java @@ -6,14 +6,20 @@ import net.minecraft.entity.passive.AbstractHorseEntity; import net.minecraft.entity.vehicle.BoatEntity; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; @Mixin(BoatEntity.class) public abstract class AllowRaft { @ModifyReturnValue(method = "isSmallerThanBoat", at = @At("RETURN")) private boolean allowRaft(boolean original, @Local(argsOnly = true)Entity entity){ - if (entity instanceof AbstractHorseEntity && ((BoatEntity)(Object)this).getVariant() == BoatEntity.Type.BAMBOO) + if (entity instanceof AbstractHorseEntity && hb$thiz().getVariant() == BoatEntity.Type.BAMBOO) return true; return original; } + + @Unique + private BoatEntity hb$thiz() { + return ((BoatEntity)(Object)this); + } } diff --git a/src/main/java/net/F53/HorseBuff/mixin/Server/MountedModifiers.java b/src/main/java/net/F53/HorseBuff/mixin/Server/MountedModifiers.java index 8d27199..e1f769f 100644 --- a/src/main/java/net/F53/HorseBuff/mixin/Server/MountedModifiers.java +++ b/src/main/java/net/F53/HorseBuff/mixin/Server/MountedModifiers.java @@ -19,51 +19,51 @@ // - remove BreakSpeed debuff from not being grounded (when enabled) @Mixin(value = PlayerEntity.class, priority = 960) public abstract class MountedModifiers extends LivingEntity { - protected MountedModifiers(EntityType entityType, World world) { - super(entityType, world); - } + protected MountedModifiers(EntityType entityType, World world) { + super(entityType, world); + } - @Unique - EntityAttributeModifier mountedStepHeight = new EntityAttributeModifier("HorseBuff-MountedStepHeight", 0.1, EntityAttributeModifier.Operation.ADD_VALUE); - @Unique - EntityAttributeModifier mountedBreakSpeed = new EntityAttributeModifier("HorseBuff-MountedBreakSpeed", 5, EntityAttributeModifier.Operation.ADD_MULTIPLIED_BASE); + @Unique + EntityAttributeModifier mountedStepHeight = new EntityAttributeModifier("HorseBuff-MountedStepHeight", 0.1, EntityAttributeModifier.Operation.ADD_VALUE); + @Unique + EntityAttributeModifier mountedBreakSpeed = new EntityAttributeModifier("HorseBuff-MountedBreakSpeed", 5, EntityAttributeModifier.Operation.ADD_MULTIPLIED_BASE); - @Unique - public boolean startRiding(Entity entity, boolean force) { - boolean result = super.startRiding(entity, force); - if (!(super.getWorld() instanceof ServerWorld && entity instanceof AbstractHorseEntity horse)) - return result; + @Override + public boolean startRiding(Entity entity, boolean force) { + boolean result = super.startRiding(entity, force); + if (!(super.getWorld() instanceof ServerWorld && entity instanceof AbstractHorseEntity horse)) + return result; - if (ModConfig.getInstance().stepHeight) { - EntityAttributeInstance stepHeight = horse.getAttributeInstance(EntityAttributes.GENERIC_STEP_HEIGHT); - if (stepHeight != null) stepHeight.addTemporaryModifier(mountedStepHeight); - } + if (ModConfig.getInstance().stepHeight) { + EntityAttributeInstance stepHeight = horse.getAttributeInstance(EntityAttributes.GENERIC_STEP_HEIGHT); + if (stepHeight != null) stepHeight.addTemporaryModifier(mountedStepHeight); + } - if (ModConfig.getInstance().breakSpeed) { - EntityAttributeInstance breakSpeed = getAttributeInstance(EntityAttributes.PLAYER_BLOCK_BREAK_SPEED); - if (breakSpeed != null) breakSpeed.addTemporaryModifier(mountedBreakSpeed); - } - return result; - } + if (ModConfig.getInstance().breakSpeed) { + EntityAttributeInstance breakSpeed = getAttributeInstance(EntityAttributes.PLAYER_BLOCK_BREAK_SPEED); + if (breakSpeed != null) breakSpeed.addTemporaryModifier(mountedBreakSpeed); + } + return result; + } - @Unique - public boolean startRiding(Entity entity) { - return this.startRiding(entity, false); - } + @Override + public boolean startRiding(Entity entity) { + return this.startRiding(entity, false); + } - @Unique - public void stopRiding() { - if (!(super.getWorld() instanceof ServerWorld && getVehicle() instanceof AbstractHorseEntity horse)) { + @Override + public void stopRiding() { + if (!(super.getWorld() instanceof ServerWorld && getVehicle() instanceof AbstractHorseEntity horse)) { super.stopRiding(); return; } - EntityAttributeInstance stepHeight = horse.getAttributeInstance(EntityAttributes.GENERIC_STEP_HEIGHT); - if (stepHeight != null) stepHeight.removeModifier(mountedStepHeight); + EntityAttributeInstance stepHeight = horse.getAttributeInstance(EntityAttributes.GENERIC_STEP_HEIGHT); + if (stepHeight != null) stepHeight.removeModifier(mountedStepHeight); - EntityAttributeInstance breakSpeed = getAttributeInstance(EntityAttributes.PLAYER_BLOCK_BREAK_SPEED); - if (breakSpeed != null) breakSpeed.removeModifier(mountedBreakSpeed); + EntityAttributeInstance breakSpeed = getAttributeInstance(EntityAttributes.PLAYER_BLOCK_BREAK_SPEED); + if (breakSpeed != null) breakSpeed.removeModifier(mountedBreakSpeed); - super.stopRiding(); - } + super.stopRiding(); + } } diff --git a/src/main/java/net/F53/HorseBuff/mixin/Server/NoBuck.java b/src/main/java/net/F53/HorseBuff/mixin/Server/NoBuck.java index cf4d333..9eeca1f 100644 --- a/src/main/java/net/F53/HorseBuff/mixin/Server/NoBuck.java +++ b/src/main/java/net/F53/HorseBuff/mixin/Server/NoBuck.java @@ -2,15 +2,17 @@ import com.llamalad7.mixinextras.injector.ModifyReturnValue; import net.F53.HorseBuff.config.ModConfig; +import net.minecraft.entity.LivingEntity; import net.minecraft.entity.passive.AbstractHorseEntity; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; @Mixin(value = AbstractHorseEntity.class, priority = 960) public class NoBuck { @ModifyReturnValue(method = "isAngry", at = @At("RETURN")) private boolean isAngry(boolean original) { - AbstractHorseEntity instance = ((AbstractHorseEntity)(Object)this); + AbstractHorseEntity instance = hb$thiz(); if (ModConfig.getInstance().noBuck && !instance.jumping && instance.isTame() @@ -19,4 +21,9 @@ private boolean isAngry(boolean original) { } return original; } + + @Unique + private AbstractHorseEntity hb$thiz() { + return ((AbstractHorseEntity)(Object)this); + } } diff --git a/src/main/java/net/F53/HorseBuff/mixin/Server/NoWander.java b/src/main/java/net/F53/HorseBuff/mixin/Server/NoWander.java index 1fe268e..baad7dd 100644 --- a/src/main/java/net/F53/HorseBuff/mixin/Server/NoWander.java +++ b/src/main/java/net/F53/HorseBuff/mixin/Server/NoWander.java @@ -5,6 +5,7 @@ import net.minecraft.entity.passive.AbstractHorseEntity; import net.minecraft.util.math.Vec3d; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.ModifyArg; @@ -13,11 +14,15 @@ public abstract class NoWander { @ModifyArg(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;travel(Lnet/minecraft/util/math/Vec3d;)V")) private Vec3d lowerWanderSpeed(Vec3d input) { - // ignore the "always false", it thinks LivingEntities will never be AbstractHorseEntity for no good reason if (ModConfig.getInstance().noWander - && ((LivingEntity)(Object)this) instanceof AbstractHorseEntity - && ((AbstractHorseEntity)(Object)this).isSaddled()) + && (hb$thiz() instanceof AbstractHorseEntity horse + && horse.isSaddled())) return(Vec3d.ZERO); return input; } + + @Unique + private LivingEntity hb$thiz() { + return ((LivingEntity)(Object)this); + } } diff --git a/src/main/java/net/F53/HorseBuff/utils/TickScheduler.java b/src/main/java/net/F53/HorseBuff/utils/TickScheduler.java index a1584e9..cf84de7 100644 --- a/src/main/java/net/F53/HorseBuff/utils/TickScheduler.java +++ b/src/main/java/net/F53/HorseBuff/utils/TickScheduler.java @@ -14,10 +14,10 @@ public static void initialize() { ServerTickEvents.END_SERVER_TICK.register(server -> endServerTick()); } - public static void endServerTick(){ + public static void endServerTick() { toRun.addAll(runNextTick); runNextTick.clear(); - while (toRun.size()>0){ + while (!toRun.isEmpty()) { toRun.get(0).run(); toRun.remove(0); }