Skip to content

Commit

Permalink
Prefix all unique fields with viaFabricPlus$
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianMichael committed Dec 11, 2023
1 parent a861237 commit 736ac43
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private void onUpdateEyeHeight(CallbackInfo ci) {
cameraY = 1.62F;
} else if (cameraY < 1.62F) {
float delta = 1.62F - cameraY;
delta *= 0.4;
delta *= 0.4F;
cameraY = 1.62F - delta;
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public abstract class MixinAbstractBlock_AbstractBlockState {

/**
* @author RK_01
* @reason Change block break speed for protocol hack
* @reason Change break speed for shulker blocks in < 1.14
*/
@Overwrite
public boolean isToolRequired() {
Expand All @@ -58,23 +58,25 @@ public boolean isToolRequired() {

@Inject(method = "getHardness", at = @At("RETURN"), cancellable = true)
private void changeHardness(BlockView world, BlockPos pos, CallbackInfoReturnable<Float> cir) {
final Block block = this.getBlock();
final var targetVersion = ProtocolHack.getTargetVersion();
final var block = this.getBlock();

if (block.equals(Blocks.END_STONE_BRICKS) || block.equals(Blocks.END_STONE_BRICK_SLAB) || block.equals(Blocks.END_STONE_BRICK_STAIRS) || block.equals(Blocks.END_STONE_BRICK_WALL)) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_14_4)) {
if (targetVersion.isOlderThanOrEqualTo(VersionEnum.r1_14_4)) {
cir.setReturnValue(0.8F);
}
} else if (block.equals(Blocks.PISTON) || block.equals(Blocks.STICKY_PISTON) || block.equals(Blocks.PISTON_HEAD)) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_15_2)) {
if (targetVersion.isOlderThanOrEqualTo(VersionEnum.r1_15_2)) {
cir.setReturnValue(0.5F);
}
} else if (block instanceof InfestedBlock) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_12_2)) {
if (targetVersion.isOlderThanOrEqualTo(VersionEnum.r1_12_2)) {
cir.setReturnValue(0.75F);
} else if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_16_4tor1_16_5)) {
} else if (targetVersion.isOlderThanOrEqualTo(VersionEnum.r1_16_4tor1_16_5)) {
cir.setReturnValue(0F);
}
} else if (block.equals(Blocks.OBSIDIAN)) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.b1_8tob1_8_1)) {
if (targetVersion.isOlderThanOrEqualTo(VersionEnum.b1_8tob1_8_1)) {
cir.setReturnValue(10.0F);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ public abstract class MixinBoatEntity extends VehicleEntity {
public abstract LivingEntity getControllingPassenger();

@Unique
private double speedMultiplier = 0.07D;
private double viaFabricPlus$speedMultiplier = 0.07D;

@Unique
private int boatInterpolationSteps;
private int viaFabricPlus$boatInterpolationSteps;

@Unique
private Vec3d boatVelocity = Vec3d.ZERO;
private Vec3d viaFabricPlus$boatVelocity = Vec3d.ZERO;

public MixinBoatEntity(EntityType<?> type, World world) {
super(type, world);
Expand All @@ -99,27 +99,27 @@ private void updateTrackedPositionAndAngles1_8(double x, double y, double z, flo
this.prevX = x;
this.prevY = y;
this.prevZ = z;
this.boatInterpolationSteps = 0;
this.viaFabricPlus$boatInterpolationSteps = 0;
this.setPosition(x, y, z);
this.setRotation(yaw, pitch);
this.setVelocity(Vec3d.ZERO);
this.boatVelocity = Vec3d.ZERO;
this.viaFabricPlus$boatVelocity = Vec3d.ZERO;
} else {
if (!this.hasPassengers()) {
this.boatInterpolationSteps = interpolationSteps + 5;
this.viaFabricPlus$boatInterpolationSteps = interpolationSteps + 5;
} else {
if (this.squaredDistanceTo(x, y, z) <= 1) {
return;
}
this.boatInterpolationSteps = 3;
this.viaFabricPlus$boatInterpolationSteps = 3;
}

this.x = x;
this.y = y;
this.z = z;
this.boatYaw = yaw;
this.boatPitch = pitch;
this.setVelocity(this.boatVelocity);
this.setVelocity(this.viaFabricPlus$boatVelocity);
}
}
}
Expand All @@ -129,7 +129,7 @@ public void setVelocityClient(double x, double y, double z) {
super.setVelocityClient(x, y, z);

if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_8)) {
this.boatVelocity = new Vec3d(x, y, z);
this.viaFabricPlus$boatVelocity = new Vec3d(x, y, z);
}
}

Expand Down Expand Up @@ -180,13 +180,13 @@ private void tick1_8(CallbackInfo ci) {
}

if (this.getWorld().isClient && !this.hasPassengers()) {
if (this.boatInterpolationSteps > 0) {
final double newX = this.getX() + (this.x - this.getX()) / this.boatInterpolationSteps;
final double newY = this.getY() + (this.y - this.getY()) / this.boatInterpolationSteps;
final double newZ = this.getZ() + (this.z - this.getZ()) / this.boatInterpolationSteps;
final double newYaw = this.getYaw() + MathHelper.wrapDegrees(this.boatYaw - this.getYaw()) / this.boatInterpolationSteps;
final double newPitch = this.getPitch() + (this.boatPitch - this.getPitch()) / this.boatInterpolationSteps;
this.boatInterpolationSteps--;
if (this.viaFabricPlus$boatInterpolationSteps > 0) {
final double newX = this.getX() + (this.x - this.getX()) / this.viaFabricPlus$boatInterpolationSteps;
final double newY = this.getY() + (this.y - this.getY()) / this.viaFabricPlus$boatInterpolationSteps;
final double newZ = this.getZ() + (this.z - this.getZ()) / this.viaFabricPlus$boatInterpolationSteps;
final double newYaw = this.getYaw() + MathHelper.wrapDegrees(this.boatYaw - this.getYaw()) / this.viaFabricPlus$boatInterpolationSteps;
final double newPitch = this.getPitch() + (this.boatPitch - this.getPitch()) / this.viaFabricPlus$boatInterpolationSteps;
this.viaFabricPlus$boatInterpolationSteps--;
this.setPosition(newX, newY, newZ);
this.setRotation((float) newYaw, (float) newPitch);
} else {
Expand All @@ -210,19 +210,19 @@ private void tick1_8(CallbackInfo ci) {
if (this.getControllingPassenger() != null) {
final LivingEntity passenger = this.getControllingPassenger();
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_5_2)) {
final double xAcceleration = passenger.getVelocity().x * this.speedMultiplier;
final double zAcceleration = passenger.getVelocity().z * this.speedMultiplier;
final double xAcceleration = passenger.getVelocity().x * this.viaFabricPlus$speedMultiplier;
final double zAcceleration = passenger.getVelocity().z * this.viaFabricPlus$speedMultiplier;
this.setVelocity(this.getVelocity().add(xAcceleration, 0, zAcceleration));
} else if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_6_4)) {
if (passenger.forwardSpeed > 0) {
final double xAcceleration = -Math.sin(passenger.getYaw() * Math.PI / 180) * this.speedMultiplier * 0.05D;
final double zAcceleration = Math.cos(passenger.getYaw() * Math.PI / 180) * this.speedMultiplier * 0.05D;
final double xAcceleration = -Math.sin(passenger.getYaw() * Math.PI / 180) * this.viaFabricPlus$speedMultiplier * 0.05D;
final double zAcceleration = Math.cos(passenger.getYaw() * Math.PI / 180) * this.viaFabricPlus$speedMultiplier * 0.05D;
this.setVelocity(this.getVelocity().add(xAcceleration, 0, zAcceleration));
}
} else {
final float boatAngle = passenger.getYaw() - passenger.sidewaysSpeed * 90F;
final double xAcceleration = -Math.sin(boatAngle * Math.PI / 180) * this.speedMultiplier * passenger.forwardSpeed * 0.05D;
final double zAcceleration = Math.cos(boatAngle * Math.PI / 180) * this.speedMultiplier * passenger.forwardSpeed * 0.05D;
final double xAcceleration = -Math.sin(boatAngle * Math.PI / 180) * this.viaFabricPlus$speedMultiplier * passenger.forwardSpeed * 0.05D;
final double zAcceleration = Math.cos(boatAngle * Math.PI / 180) * this.viaFabricPlus$speedMultiplier * passenger.forwardSpeed * 0.05D;
this.setVelocity(this.getVelocity().add(xAcceleration, 0, zAcceleration));
}
}
Expand All @@ -234,15 +234,15 @@ private void tick1_8(CallbackInfo ci) {
newHorizontalSpeed = 0.35D;
}

if (newHorizontalSpeed > oldHorizontalSpeed && this.speedMultiplier < 0.35D) {
this.speedMultiplier += (0.35D - this.speedMultiplier) / 35;
if (this.speedMultiplier > 0.35D) {
this.speedMultiplier = 0.35D;
if (newHorizontalSpeed > oldHorizontalSpeed && this.viaFabricPlus$speedMultiplier < 0.35D) {
this.viaFabricPlus$speedMultiplier += (0.35D - this.viaFabricPlus$speedMultiplier) / 35;
if (this.viaFabricPlus$speedMultiplier > 0.35D) {
this.viaFabricPlus$speedMultiplier = 0.35D;
}
} else {
this.speedMultiplier -= (this.speedMultiplier - 0.07D) / 35;
if (this.speedMultiplier < 0.07D) {
this.speedMultiplier = 0.07D;
this.viaFabricPlus$speedMultiplier -= (this.viaFabricPlus$speedMultiplier - 0.07D) / 35;
if (this.viaFabricPlus$speedMultiplier < 0.07D) {
this.viaFabricPlus$speedMultiplier = 0.07D;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ private double changeMagnitude(double n) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_18tor1_18_1)) {
return 9.0E-4D;
}

return MathHelper.square(n);
}

Expand Down Expand Up @@ -190,7 +189,6 @@ private boolean disableSprintSneak(Input input) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_14_1)) {
return input.movementForward >= 0.8F;
}

return input.hasForwardMovement();
}

Expand All @@ -210,7 +208,6 @@ private boolean redirectTickMovement(ClientPlayerEntity self) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_12_2)) {
return false; // Disable all water related movement
}

return self.isTouchingWater();
}

Expand All @@ -220,7 +217,6 @@ private int revertLastPositionPacketSentIncrementor(ClientPlayerEntity instance)
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_8)) {
return ticksSinceLastPositionPacketSent - 1;
}

return ticksSinceLastPositionPacketSent;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ private double fixLavaMovement(LivingEntity instance, TagKey<Fluid> tagKey) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_15_2)) {
return Double.MAX_VALUE;
}

return instance.getFluidHeight(tagKey);
}

Expand All @@ -136,7 +135,6 @@ private boolean disableJumpOnLadder(LivingEntity self) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_13_2)) {
return false;
}

return jumping;
}

Expand All @@ -147,7 +145,6 @@ private boolean disableClimbing(LivingEntity instance) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_13_2)) {
return false;
}

return instance.horizontalCollision;
}

Expand All @@ -156,7 +153,6 @@ private boolean modifyMovingDown(boolean movingDown) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_13_2)) {
return true;
}

return movingDown;
}

Expand All @@ -165,7 +161,6 @@ private void dontResetLevitationFallDistance(LivingEntity instance) {
if (!this.hasStatusEffect(StatusEffects.SLOW_FALLING) && ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_12_2)) {
return;
}

instance.onLanding();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,16 @@ public abstract class MixinPlayerEntityRenderer {
@Inject(method = "getPositionOffset(Lnet/minecraft/client/network/AbstractClientPlayerEntity;F)Lnet/minecraft/util/math/Vec3d;", at = @At("RETURN"), cancellable = true)
private void modifySleepingOffset(AbstractClientPlayerEntity player, float delta, CallbackInfoReturnable<Vec3d> cir) {
if (player.getPose() == EntityPose.SLEEPING) {
final Direction sleepingDir = player.getSleepingDirection();
final var targetVersion = ProtocolHack.getTargetVersion();
final var sleepingDir = player.getSleepingDirection();
if (sleepingDir != null) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_13_2)) {
if (targetVersion.isOlderThanOrEqualTo(VersionEnum.r1_13_2)) {
cir.setReturnValue(cir.getReturnValue().subtract(sleepingDir.getOffsetX() * 0.4, 0, sleepingDir.getOffsetZ() * 0.4));
}
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.b1_5tob1_5_2)) {
if (targetVersion.isOlderThanOrEqualTo(VersionEnum.b1_5tob1_5_2)) {
cir.setReturnValue(cir.getReturnValue().subtract(sleepingDir.getOffsetX() * 0.1, 0, sleepingDir.getOffsetZ() * 0.1));
}
if (ProtocolHack.getTargetVersion().isBetweenInclusive(VersionEnum.b1_6tob1_6_6, VersionEnum.r1_7_6tor1_7_10)) {
if (targetVersion.isBetweenInclusive(VersionEnum.b1_6tob1_6_6, VersionEnum.r1_7_6tor1_7_10)) {
cir.setReturnValue(cir.getReturnValue().subtract(0, 0.3F, 0));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private void fixWolfInteract(PlayerEntity player, Hand hand, CallbackInfoReturna
final Item item = itemStack.getItem();
if (this.isTamed()) {
if (item.isFood()) {
if (item.getFoodComponent().isMeat() && this.getWolfHealth() < 20.0F) {
if (item.getFoodComponent().isMeat() && this.viaFabricPlus$getWolfHealth() < 20.0F) {
if (!player.getAbilities().creativeMode) itemStack.decrement(1);
this.heal((float) item.getFoodComponent().getHunger());
cir.setReturnValue(ActionResult.SUCCESS);
Expand Down Expand Up @@ -91,14 +91,13 @@ private void fixWolfInteract(PlayerEntity player, Hand hand, CallbackInfoReturna
@Redirect(method = "*", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/passive/WolfEntity;getHealth()F"))
private float fixWolfHealth(WolfEntity instance) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_14_4)) {
return this.getWolfHealth();
return this.viaFabricPlus$getWolfHealth();
}

return instance.getHealth();
}

@Unique
private float getWolfHealth() {
private float viaFabricPlus$getWolfHealth() {
return WolfHealthTracker.get(ProtocolHack.getPlayNetworkUserConnection()).getWolfHealth(this.getId(), this.getHealth());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ public boolean isSuitableFor(BlockState state) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_16_4tor1_16_5)) {
return false;
}

return super.isSuitableFor(state);
}

Expand All @@ -76,7 +75,6 @@ public float getMiningSpeedMultiplier(ItemStack stack, BlockState state) {
} else if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_16_4tor1_16_5)) {
return viaFabricPlus$effective_materials_r1_16_5.contains(Material1_19_4.getMaterial(state)) ? this.miningSpeed : viaFabricPlus$effective_blocks_r1_16_5.contains(state.getBlock()) ? this.miningSpeed : 1.0F;
}

return super.getMiningSpeedMultiplier(stack, state);
}

Expand Down

0 comments on commit 736ac43

Please sign in to comment.