package net.rustnotmc.client; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.network.NetHandlerPlayClient; import net.minecraft.stats.RecipeBook; import net.minecraft.stats.StatisticsManager; import net.minecraft.world.World; /** * Our player. * * The vanilla player with three things changed: the crouch is low enough to * squeeze through a hole of one and a half blocks, the hop from a standstill * is higher than the vanilla jump, and the eyes follow the lower crouch. * Everything else is the vanilla behaviour, so the player still walks, swims, * rides, fights and dies the way the game always did. * * The class exists so that the numbers of our movement live in our code and * not in the patches of the vanilla tree: the patches only have to say "the * player is ours", and everything else is here. */ public class RsxPlayer extends EntityPlayerSP { public RsxPlayer(Minecraft minecraft, World world, NetHandlerPlayClient connection, StatisticsManager statistics, RecipeBook recipeBook) { super(minecraft, world, connection, statistics, recipeBook); this.movementInput = new RsxMovementInput(minecraft.gameSettings); } /** * How high the player jumps. * * Jumping on the spot is the Rust-like hop and clears more than the * vanilla jump does. Jumping while moving keeps the vanilla height, so a * running jump stays the same as it always was. * * The override lives here and not in EntityLivingBase, because the mobs * have to keep jumping the way they always did. */ @Override protected float getJumpUpwardsMotion() { if (this.movementInput == null || !isMoving()) { return RsxPlayerTuning.jumpMotion(RsxPlayerTuning.jumpHeightStanding()); } return RsxPlayerTuning.jumpMotion(RsxPlayerTuning.jumpHeightMoving()); } /** True when the player is asking to move sideways or forward. */ private boolean isMoving() { return this.movementInput.moveStrafe != 0.0F || this.movementInput.moveForward != 0.0F; } /** * Where the eyes are. * * The vanilla crouch lowers the player to 1.65 and puts the eyes at 1.54. * Ours is lower, so the eyes have to come down with it, or they would sit * above the head. */ @Override public float getEyeHeight() { if (this.isSneaking() && !this.isPlayerSleeping() && !this.isElytraFlying()) { return RsxPlayerTuning.crouchHeight() - RsxPlayerTuning.CROUCH_EYE_OFFSET; } return super.getEyeHeight(); } }