mirror of
https://github.com/chylex/Better-Sprinting.git
synced 2025-04-09 18:15:41 +02:00
Update to 1.11 and refactor some code
This commit is contained in:
parent
a663936928
commit
c54b0bc323
src/main/java/chylex/bettersprinting/client/player
@ -9,36 +9,44 @@ public class CustomMovementInput{
|
||||
public int stoptime = 0;
|
||||
public boolean sprint, sprintToggle, sneakToggle, hasToggledSprint, hasToggledSneak;
|
||||
|
||||
// UPDATE | MovementInputFromOptions.updatePlayerMoveState | 1.10.2
|
||||
public void update(Minecraft mc, MovementInputFromOptions options){
|
||||
options.moveStrafe = 0F;
|
||||
options.moveForward = 0F;
|
||||
|
||||
// UPDATE | MovementInputFromOptions.updatePlayerMoveState | 1.11
|
||||
public void update(Minecraft mc, MovementInputFromOptions $this){
|
||||
GameSettings settings = mc.gameSettings;
|
||||
|
||||
$this.moveStrafe = 0F;
|
||||
$this.moveForward = 0F;
|
||||
|
||||
if (settings.keyBindForward.isKeyDown()){
|
||||
++options.moveForward;
|
||||
options.forwardKeyDown = true;
|
||||
++$this.moveForward;
|
||||
$this.forwardKeyDown = true;
|
||||
}
|
||||
else{
|
||||
$this.forwardKeyDown = false;
|
||||
}
|
||||
else options.forwardKeyDown = false;
|
||||
|
||||
if (settings.keyBindBack.isKeyDown()){
|
||||
--options.moveForward;
|
||||
options.backKeyDown = true;
|
||||
--$this.moveForward;
|
||||
$this.backKeyDown = true;
|
||||
}
|
||||
else{
|
||||
$this.backKeyDown = false;
|
||||
}
|
||||
else options.backKeyDown = false;
|
||||
|
||||
if (settings.keyBindLeft.isKeyDown()){
|
||||
++options.moveStrafe;
|
||||
options.leftKeyDown = true;
|
||||
++$this.moveStrafe;
|
||||
$this.leftKeyDown = true;
|
||||
}
|
||||
else{
|
||||
$this.leftKeyDown = false;
|
||||
}
|
||||
else options.leftKeyDown = false;
|
||||
|
||||
if (settings.keyBindRight.isKeyDown()){
|
||||
--options.moveStrafe;
|
||||
options.rightKeyDown = true;
|
||||
--$this.moveStrafe;
|
||||
$this.rightKeyDown = true;
|
||||
}
|
||||
else{
|
||||
$this.rightKeyDown = false;
|
||||
}
|
||||
else options.rightKeyDown = false;
|
||||
|
||||
// custom handling
|
||||
sprint = ClientModManager.keyBindSprintHold.isKeyDown();
|
||||
@ -56,10 +64,10 @@ public class CustomMovementInput{
|
||||
}
|
||||
else sprintToggle = false;
|
||||
|
||||
options.jump = settings.keyBindJump.isKeyDown();
|
||||
options.sneak = settings.keyBindSneak.isKeyDown();
|
||||
$this.jump = settings.keyBindJump.isKeyDown();
|
||||
$this.sneak = settings.keyBindSneak.isKeyDown();
|
||||
|
||||
if (!options.sneak){
|
||||
if (!$this.sneak){
|
||||
if (!ClientModManager.isModDisabled() && ClientModManager.keyBindSneakToggle.isKeyDown()){
|
||||
if (!hasToggledSneak){
|
||||
sneakToggle = !sneakToggle;
|
||||
@ -68,12 +76,12 @@ public class CustomMovementInput{
|
||||
}
|
||||
else hasToggledSneak = false;
|
||||
|
||||
options.sneak = sneakToggle;
|
||||
$this.sneak = sneakToggle;
|
||||
}
|
||||
|
||||
if (options.sneak){
|
||||
options.moveStrafe = options.moveStrafe*0.3F;
|
||||
options.moveForward = options.moveForward*0.3F;
|
||||
if ($this.sneak){
|
||||
$this.moveStrafe = $this.moveStrafe*0.3F;
|
||||
$this.moveForward = $this.moveForward*0.3F;
|
||||
}
|
||||
|
||||
if (ClientModManager.isModDisabled()){
|
||||
|
@ -30,14 +30,14 @@ public class PlayerLogicHandler{
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
// UPDATE | EntityPlayerSP.onLivingUpdate | 1.10.2
|
||||
// UPDATE | EntityPlayerSP.onLivingUpdate | 1.11
|
||||
public void updateMovementInput(){
|
||||
wasMovingForward = player.movementInput.moveForward >= 0.8F;
|
||||
wasSneaking = player.movementInput.sneak;
|
||||
customMovementInput.update(mc, (MovementInputFromOptions)player.movementInput);
|
||||
}
|
||||
|
||||
// UPDATE | EntityPlayerSP.onLivingUpdate | 1.10.2
|
||||
// UPDATE | EntityPlayerSP.onLivingUpdate | 1.11
|
||||
public void updateLiving(){
|
||||
boolean enoughHunger = player.getFoodStats().getFoodLevel() > 6F || player.capabilities.allowFlying;
|
||||
|
||||
@ -61,7 +61,9 @@ public class PlayerLogicHandler{
|
||||
boolean sprint = customMovementInput.sprint;
|
||||
boolean dblTap = ClientSettings.enableDoubleTap;
|
||||
|
||||
if (!player.capabilities.isFlying && ((MovementInputFromOptions)player.movementInput).sneak)sprint = false;
|
||||
if (!player.capabilities.isFlying && ((MovementInputFromOptions)player.movementInput).sneak){
|
||||
sprint = false;
|
||||
}
|
||||
|
||||
if (((dblTap && !player.isSprinting()) || !dblTap) && player.onGround && enoughHunger && !player.isHandActive() && !player.isPotionActive(MobEffects.BLINDNESS)){
|
||||
player.setSprinting(sprint);
|
||||
@ -80,7 +82,9 @@ public class PlayerLogicHandler{
|
||||
}
|
||||
|
||||
if (dblTap){
|
||||
if (prevHeld && !customMovementInput.held)customMovementInput.stoptime = 1;
|
||||
if (prevHeld && !customMovementInput.held){
|
||||
customMovementInput.stoptime = 1;
|
||||
}
|
||||
|
||||
if (customMovementInput.stoptime > 0){
|
||||
customMovementInput.stoptime--;
|
||||
@ -105,7 +109,9 @@ public class PlayerLogicHandler{
|
||||
else if (player.capabilities.getFlySpeed() > 0.05F)player.capabilities.setFlySpeed(0.05F);
|
||||
}
|
||||
|
||||
if (ClientModManager.keyBindOptionsMenu.isKeyDown())mc.displayGuiScreen(new GuiSprint(null));
|
||||
if (ClientModManager.keyBindOptionsMenu.isKeyDown()){
|
||||
mc.displayGuiScreen(new GuiSprint(null));
|
||||
}
|
||||
|
||||
if (player.isSprinting() && player.isSneaking() && !player.capabilities.isFlying){
|
||||
player.setSprinting(false);
|
||||
|
@ -19,10 +19,13 @@ import chylex.bettersprinting.client.player.PlayerLogicHandler;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
final class LivingUpdate{
|
||||
// UPDATE | EntityPlayerSP.onLivingUpdate | 1.10.2
|
||||
// UPDATE | EntityPlayerSP.onLivingUpdate | 1.11
|
||||
public static void callPreSuper(EntityPlayerSP player, Minecraft mc, PlayerLogicHandler logic){
|
||||
++player.sprintingTicksLeft;
|
||||
if (player.sprintToggleTimer > 0)--player.sprintToggleTimer;
|
||||
|
||||
if (player.sprintToggleTimer > 0){
|
||||
--player.sprintToggleTimer;
|
||||
}
|
||||
|
||||
player.prevTimeInPortal = player.timeInPortal;
|
||||
|
||||
@ -45,14 +48,19 @@ final class LivingUpdate{
|
||||
}
|
||||
else if (player.isPotionActive(MobEffects.NAUSEA) && player.getActivePotionEffect(MobEffects.NAUSEA).getDuration() > 60){
|
||||
player.timeInPortal += 0.006666667F;
|
||||
if (player.timeInPortal > 1F)player.timeInPortal = 1F;
|
||||
|
||||
if (player.timeInPortal > 1F){
|
||||
player.timeInPortal = 1F;
|
||||
}
|
||||
}
|
||||
else{
|
||||
if (player.timeInPortal > 0F)player.timeInPortal -= 0.05F;
|
||||
if (player.timeInPortal < 0F)player.timeInPortal = 0F;
|
||||
}
|
||||
|
||||
if (player.timeUntilPortal > 0)--player.timeUntilPortal;
|
||||
if (player.timeUntilPortal > 0){
|
||||
--player.timeUntilPortal;
|
||||
}
|
||||
|
||||
boolean wasJumping = player.movementInput.jump;
|
||||
logic.updateMovementInput();
|
||||
@ -101,7 +109,7 @@ final class LivingUpdate{
|
||||
if (player.movementInput.jump && !wasJumping && !player.onGround && player.motionY < 0D && !player.isElytraFlying() && !player.capabilities.isFlying){
|
||||
ItemStack chestIS = player.getItemStackFromSlot(EntityEquipmentSlot.CHEST);
|
||||
|
||||
if (chestIS != null && chestIS.getItem() == Items.ELYTRA && ItemElytra.isBroken(chestIS)){
|
||||
if (chestIS.getItem() == Items.ELYTRA && ItemElytra.isBroken(chestIS)){
|
||||
player.connection.sendPacket(new CPacketEntityAction(player, CPacketEntityAction.Action.START_FALL_FLYING));
|
||||
}
|
||||
}
|
||||
@ -145,10 +153,12 @@ final class LivingUpdate{
|
||||
}
|
||||
}
|
||||
}
|
||||
else player.horseJumpPower = 0F;
|
||||
else{
|
||||
player.horseJumpPower = 0F;
|
||||
}
|
||||
}
|
||||
|
||||
// UPDATE | EntityPlayerSP.onLivingUpdate | 1.10.2
|
||||
// UPDATE | EntityPlayerSP.onLivingUpdate | 1.11
|
||||
public static void callPostSuper(EntityPlayerSP player, Minecraft mc, PlayerLogicHandler logic){
|
||||
if (player.onGround && player.capabilities.isFlying && !mc.playerController.isSpectatorMode()){
|
||||
player.capabilities.isFlying = false;
|
||||
@ -156,9 +166,11 @@ final class LivingUpdate{
|
||||
}
|
||||
}
|
||||
|
||||
// UPDATE | EntityPlayerSP.pushOutOfBlocks | 1.10.2
|
||||
// UPDATE | EntityPlayerSP.pushOutOfBlocks | 1.11
|
||||
protected static boolean pushOutOfBlocks(EntityPlayerSP player, double x, double y, double z){
|
||||
if (player.noClip)return false;
|
||||
if (player.noClip){
|
||||
return false;
|
||||
}
|
||||
|
||||
BlockPos pos = new BlockPos(x, y, z);
|
||||
double xDiff = x-pos.getX();
|
||||
@ -190,24 +202,25 @@ final class LivingUpdate{
|
||||
side = 5;
|
||||
}
|
||||
|
||||
if (side == 0)player.motionX = -0.1F;
|
||||
if (side == 1)player.motionX = 0.1F;
|
||||
if (side == 4)player.motionZ = -0.1F;
|
||||
if (side == 5)player.motionZ = 0.1F;
|
||||
if (side == 0)player.motionX = -0.1D;
|
||||
else if (side == 1)player.motionX = 0.1D;
|
||||
else if (side == 4)player.motionZ = -0.1D;
|
||||
else if (side == 5)player.motionZ = 0.1D;
|
||||
// added 'else' to the statements
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// UPDATE | EntityPlayerSP.isOpenBlockSpace | 1.10.2
|
||||
// UPDATE | EntityPlayerSP.isOpenBlockSpace | 1.11
|
||||
private static boolean isOpenBlockSpace(EntityPlayerSP player, BlockPos pos){
|
||||
return !player.world.getBlockState(pos).isNormalCube();
|
||||
}
|
||||
|
||||
// UPDATE | EntityPlayerSP.isHeadspaceFree | 1.10.2
|
||||
// UPDATE | EntityPlayerSP.isHeadspaceFree | 1.11
|
||||
private static boolean isHeadspaceFree(EntityPlayerSP player, BlockPos pos, int height){
|
||||
for(int yOffset = 0; yOffset < height; yOffset++){
|
||||
if (!isOpenBlockSpace(player, pos.add(0, yOffset, 0)))return false;
|
||||
for(int y = 0; y < height; y++){
|
||||
if (!isOpenBlockSpace(player, pos.add(0, y, 0)))return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -35,10 +35,9 @@ public final class LogicImplOverride{
|
||||
@SubscribeEvent
|
||||
public void onGuiOpen(GuiOpenEvent e){
|
||||
if (e.getGui() != null && e.getGui().getClass() == GuiDownloadTerrain.class && Minecraft.getMinecraft().playerController.getClass() != PlayerControllerMPOverride.class){
|
||||
// UPDATE | Minecraft.setDimensionAndSpawnPlayer | 1.10.2
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
mc.playerController = new PlayerControllerMPOverride(mc, (NetHandlerPlayClient)FMLClientHandler.instance().getClientPlayHandler());
|
||||
|
||||
// UPDATE | Minecraft.setDimensionAndSpawnPlayer | 1.11
|
||||
EntityPlayerSP prevPlayer = mc.player;
|
||||
mc.world.removeEntity(prevPlayer);
|
||||
|
||||
|
@ -22,6 +22,7 @@ import chylex.bettersprinting.client.player.PlayerLogicHandler;
|
||||
public class PlayerOverride extends EntityPlayerSP{
|
||||
private final PlayerLogicHandler logic;
|
||||
|
||||
// UPDATE | EntityLivingBase.jumpTicks | Check if still only used in onLivingUpdate | 1.11
|
||||
private int jumpTicks;
|
||||
|
||||
public PlayerOverride(Minecraft mc, World world, NetHandlerPlayClient netHandler, StatisticsManager statFile){
|
||||
@ -39,9 +40,11 @@ public class PlayerOverride extends EntityPlayerSP{
|
||||
LivingUpdate.callPostSuper(this, mc, logic);
|
||||
}
|
||||
|
||||
// UPDATE | EntityPlayer.onLivingUpdate | 1.10.2
|
||||
// UPDATE | EntityPlayer.onLivingUpdate | 1.11
|
||||
private void onLivingUpdate$EntityPlayer(){
|
||||
if (flyToggleTimer > 0)--flyToggleTimer;
|
||||
if (flyToggleTimer > 0){
|
||||
--flyToggleTimer;
|
||||
}
|
||||
|
||||
if (world.getDifficulty() == EnumDifficulty.PEACEFUL && world.getGameRules().getBoolean("naturalRegeneration")){
|
||||
if (getHealth() < getMaxHealth() && ticksExisted%20 == 0){
|
||||
@ -74,7 +77,9 @@ public class PlayerOverride extends EntityPlayerSP{
|
||||
float moveDist = MathHelper.sqrt(motionX*motionX+motionZ*motionZ);
|
||||
float motYFactor = (float)(Math.atan(-motionY*0.2D)*15D);
|
||||
|
||||
if (moveDist > 0.1F)moveDist = 0.1F;
|
||||
if (moveDist > 0.1F){
|
||||
moveDist = 0.1F;
|
||||
}
|
||||
|
||||
if (!onGround || getHealth() <= 0F)moveDist = 0F;
|
||||
if (onGround || getHealth() <= 0F)motYFactor = 0F;
|
||||
@ -93,14 +98,18 @@ public class PlayerOverride extends EntityPlayerSP{
|
||||
}
|
||||
|
||||
for(Entity entity:world.getEntitiesWithinAABBExcludingEntity(this, aabb)){
|
||||
if (!entity.isDead)entity.onCollideWithPlayer(this); // uses collideWithPlayer but it's private
|
||||
if (!entity.isDead){
|
||||
entity.onCollideWithPlayer(this); // uses collideWithPlayer but it's private
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// UPDATE | EntityLivingBase.onLivingUpdate | 1.10.2
|
||||
// UPDATE | EntityLivingBase.onLivingUpdate | 1.11
|
||||
private void onLivingUpdate$EntityLivingBase(){
|
||||
if (jumpTicks > 0)--jumpTicks;
|
||||
if (jumpTicks > 0){
|
||||
--jumpTicks;
|
||||
}
|
||||
|
||||
if (newPosRotationIncrements > 0 && !canPassengerSteer()){
|
||||
double setPosX = posX+(interpTargetX-posX)/newPosRotationIncrements;
|
||||
@ -151,7 +160,9 @@ public class PlayerOverride extends EntityPlayerSP{
|
||||
jumpTicks = 10;
|
||||
}
|
||||
}
|
||||
else jumpTicks = 0;
|
||||
else{
|
||||
jumpTicks = 0;
|
||||
}
|
||||
|
||||
world.theProfiler.endSection();
|
||||
world.theProfiler.startSection("travel");
|
||||
@ -170,23 +181,27 @@ public class PlayerOverride extends EntityPlayerSP{
|
||||
world.theProfiler.endSection();
|
||||
}
|
||||
|
||||
// UPDATE | EntityLivingBase.updateElytra | 1.10.2
|
||||
// UPDATE | EntityLivingBase.updateElytra | 1.11
|
||||
private void updateElytra$EntityLivingBase(){
|
||||
boolean flag = getFlag(7);
|
||||
|
||||
if (flag && !onGround && !isRiding()){
|
||||
ItemStack is = getItemStackFromSlot(EntityEquipmentSlot.CHEST);
|
||||
|
||||
if (is != null && is.getItem() == Items.ELYTRA && ItemElytra.isBroken(is)){
|
||||
if (is.getItem() == Items.ELYTRA && ItemElytra.isBroken(is)){
|
||||
flag = true;
|
||||
|
||||
if (!world.isRemote && (ticksElytraFlying+1)%20 == 0){
|
||||
is.damageItem(1, this);
|
||||
}
|
||||
}
|
||||
else flag = false;
|
||||
else{
|
||||
flag = false;
|
||||
}
|
||||
}
|
||||
else{
|
||||
flag = false;
|
||||
}
|
||||
else flag = false;
|
||||
|
||||
if (!world.isRemote){
|
||||
setFlag(7, flag);
|
||||
|
Loading…
Reference in New Issue
Block a user