diff options
author | Draknyte1 <Draknyte1@hotmail.com> | 2016-12-28 16:00:53 +1000 |
---|---|---|
committer | Draknyte1 <Draknyte1@hotmail.com> | 2016-12-28 16:00:53 +1000 |
commit | f66fb1526fa85554842db425652545448495a2a0 (patch) | |
tree | a90cf67cd0f240e73f2d3ab2aa2c4b363b14b5bf /src/Java/gtPlusPlus/core/common | |
parent | d41a850da5a9bcfe7dda85dba2aad08387833d04 (diff) | |
download | GT5-Unofficial-f66fb1526fa85554842db425652545448495a2a0.tar.gz GT5-Unofficial-f66fb1526fa85554842db425652545448495a2a0.tar.bz2 GT5-Unofficial-f66fb1526fa85554842db425652545448495a2a0.zip |
+ Added framework based on opensource works for player movement modification.
+ Added support for the builders ring to toggle Sneak on and Sprinting off while worn.
+ Added PlayerAPI.
% Moved COFH api files into the same package as PlayerAPI.
Diffstat (limited to 'src/Java/gtPlusPlus/core/common')
-rw-r--r-- | src/Java/gtPlusPlus/core/common/BasePlayer.java | 346 |
1 files changed, 346 insertions, 0 deletions
diff --git a/src/Java/gtPlusPlus/core/common/BasePlayer.java b/src/Java/gtPlusPlus/core/common/BasePlayer.java new file mode 100644 index 0000000000..fb17480b8f --- /dev/null +++ b/src/Java/gtPlusPlus/core/common/BasePlayer.java @@ -0,0 +1,346 @@ +package gtPlusPlus.core.common; + +import gtPlusPlus.core.handler.events.CustomMovementHandler; +import gtPlusPlus.core.handler.events.SneakManager; +import net.minecraft.client.Minecraft; +import net.minecraft.client.audio.PositionedSoundRecord; +import net.minecraft.client.entity.EntityClientPlayerMP; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.settings.GameSettings; +import net.minecraft.network.play.client.C0BPacketEntityAction; +import net.minecraft.potion.Potion; +import net.minecraft.util.MovementInputFromOptions; +import net.minecraft.util.ResourceLocation; +import api.player.client.ClientPlayerAPI; +import api.player.client.ClientPlayerBase; + +public class BasePlayer extends ClientPlayerBase +{ + private final Minecraft mc = Minecraft.getMinecraft(); + private final CustomMovementHandler customMovementInput = new CustomMovementHandler(); + private final GameSettings settings = mc.gameSettings; + + public BasePlayer(ClientPlayerAPI api) + { + super(api); + } + + /* + * EntityPlayerSP.onLivingUpdate() - Adapted to PlayerAPI + */ + @Override + public void onLivingUpdate() + { + if(this.player.sprintingTicksLeft > 0) + { + --this.player.sprintingTicksLeft; + if(this.player.sprintingTicksLeft == 0) + { + this.player.setSprinting(false); + } + } + + if(this.playerAPI.getSprintToggleTimerField() > 0) + { + this.playerAPI.setSprintToggleTimerField(this.playerAPI.getSprintToggleTimerField() - 1); + } + + if(this.mc.playerController.enableEverythingIsScrewedUpMode()) + { + this.player.posX = this.player.posZ = 0.5D; + this.player.posX = 0.0D; + this.player.posZ = 0.0D; + this.player.rotationYaw = (float)this.player.ticksExisted / 12.0F; + this.player.rotationPitch = 10.0F; + this.player.posY = 68.5D; + } + else + { + this.player.prevTimeInPortal = this.player.timeInPortal; + if(this.playerAPI.getInPortalField()) + { + if(this.mc.currentScreen != null) + { + this.mc.displayGuiScreen((GuiScreen)null); + } + + if(this.player.timeInPortal == 0.0F) + { + this.mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("portal.trigger"), this.player.getRNG().nextFloat() * 0.4F + 0.8F)); + } + + this.player.timeInPortal += 0.0125F; + + if(this.player.timeInPortal >= 1.0F) + { + this.player.timeInPortal = 1.0F; + } + + this.playerAPI.setInPortalField(false); + } + else if(this.player.isPotionActive(Potion.confusion) && this.player.getActivePotionEffect(Potion.confusion).getDuration() > 60) + { + this.player.timeInPortal += 0.006666667F; + if(this.player.timeInPortal > 1.0F) + { + this.player.timeInPortal = 1.0F; + } + } + else + { + if(this.player.timeInPortal > 0.0F) + { + this.player.timeInPortal -= 0.05F; + } + + if(this.player.timeInPortal < 0.0F) + { + this.player.timeInPortal = 0.0F; + } + } + + + if(this.player.timeUntilPortal > 0) + { + --this.player.timeUntilPortal; + } + + boolean isJumping = this.player.movementInput.jump; + + float minSpeed = 0.8F; + boolean isMovingForward = this.player.movementInput.moveForward >= minSpeed; + this.customMovementInput.update(this.mc, (MovementInputFromOptions)this.player.movementInput, this.player); + + if(this.player.isUsingItem() && !this.player.isRiding()) + { + this.player.movementInput.moveStrafe *= 0.2F; + this.player.movementInput.moveForward *= 0.2F; + this.playerAPI.setSprintToggleTimerField(0); + } + + if(this.player.movementInput.sneak && this.player.ySize < 0.2F) + { + this.player.ySize = 0.2F; + } + + this.playerAPI.localPushOutOfBlocks(this.player.posX - (double)this.player.width * 0.35D, this.player.boundingBox.minY + 0.5D, this.player.posZ + (double)this.player.width * 0.35D); + this.playerAPI.localPushOutOfBlocks(this.player.posX - (double)this.player.width * 0.35D, this.player.boundingBox.minY + 0.5D, this.player.posZ - (double)this.player.width * 0.35D); + this.playerAPI.localPushOutOfBlocks(this.player.posX + (double)this.player.width * 0.35D, this.player.boundingBox.minY + 0.5D, this.player.posZ - (double)this.player.width * 0.35D); + this.playerAPI.localPushOutOfBlocks(this.player.posX + (double)this.player.width * 0.35D, this.player.boundingBox.minY + 0.5D, this.player.posZ + (double)this.player.width * 0.35D); + boolean enoughHunger = (float)this.player.getFoodStats().getFoodLevel() > 6.0F || this.player.capabilities.isFlying; + + /* + * Begin ToggleSneak Changes - ToggleSprint + */ + + boolean isSprintDisabled = !SneakManager.canSprint; + boolean canDoubleTap = SneakManager.optionDoubleTap; + + // Detect when ToggleSprint was disabled in the in-game options menu + if(SneakManager.wasSprintDisabled) + { + this.player.setSprinting(false); + customMovementInput.UpdateSprint(false, false); + SneakManager.wasSprintDisabled = false; + } + + // Default Sprint routine converted to PlayerAPI, use if ToggleSprint is disabled - TODO - Disable sprinting as a whole + if(isSprintDisabled) + { + if(SneakManager.optionDoubleTap && this.player.onGround && !isMovingForward && this.player.movementInput.moveForward >= minSpeed && !this.player.isSprinting() && enoughHunger && !this.player.isUsingItem() && !this.player.isPotionActive(Potion.blindness)) + { + if(this.playerAPI.getSprintToggleTimerField() <= 0 && !this.settings.keyBindSprint.getIsKeyPressed()) + { + this.playerAPI.setSprintToggleTimerField(7); + } + else + { + if (!SneakManager.SprintingDisabled()){ + this.player.setSprinting(true); + customMovementInput.UpdateSprint(true, false); + } + else { + this.player.setSprinting(false); + customMovementInput.UpdateSprint(false, false); + } + } + } + + if(!this.player.isSprinting() && this.player.movementInput.moveForward >= minSpeed && enoughHunger && !this.player.isUsingItem() && !this.player.isPotionActive(Potion.blindness) && this.settings.keyBindSprint.getIsKeyPressed()) + { + if (!SneakManager.SprintingDisabled()){ + this.player.setSprinting(true); + customMovementInput.UpdateSprint(true, false); + } + else { + this.player.setSprinting(false); + customMovementInput.UpdateSprint(false, false); + } + } + } + else + { + boolean state = this.customMovementInput.sprint; + + // Only handle changes in state under the following conditions: + // On ground, not hungry, not eating/using item, not blind, and not Vanilla + // + // 5/6/14 - onGround check removed to match vanilla's 'start sprint while jumping' behavior. + //if(this.player.onGround && enoughHunger && !this.player.isUsingItem() && !this.player.isPotionActive(Potion.blindness) && !this.customMovementInput.sprintHeldAndReleased) + + if(enoughHunger && !this.player.isUsingItem() && !this.player.isPotionActive(Potion.blindness) && !this.customMovementInput.sprintHeldAndReleased) + { + if(canDoubleTap && !this.player.isSprinting() || !canDoubleTap) + { + if (!SneakManager.SprintingDisabled()) + this.player.setSprinting(state); + else + this.player.setSprinting(false); + } + } + + if(canDoubleTap && !state && this.player.onGround && !isMovingForward && this.player.movementInput.moveForward >= minSpeed && !this.player.isSprinting() && enoughHunger && !this.player.isUsingItem() && !this.player.isPotionActive(Potion.blindness)) + { + if(this.playerAPI.getSprintToggleTimerField() == 0) + { + this.playerAPI.setSprintToggleTimerField(7); + } + else + { + if (!SneakManager.SprintingDisabled()){ + this.player.setSprinting(true); + customMovementInput.UpdateSprint(true, true); + this.playerAPI.setSprintToggleTimerField(0); + } + } + } + } + + // If sprinting, break the sprint in appropriate circumstances: + // Player stops moving forward, runs into something, or gets too hungry + if(this.player.isSprinting() && (this.player.movementInput.moveForward < minSpeed || this.player.isCollidedHorizontally || !enoughHunger)) + { + this.player.setSprinting(false); + + // Undo toggle if we resumed vanilla operation due to Hold&Release, DoubleTap, Fly, Ride + if (customMovementInput.sprintHeldAndReleased == true || isSprintDisabled || customMovementInput.sprintDoubleTapped || this.player.capabilities.isFlying || this.player.isRiding()) + { + customMovementInput.UpdateSprint(false, false); + } + } + + /* + * End ToggleSneak Changes - ToggleSprint + */ + + // // + // // Debug Framework - Added 5/7/2014 + // // + // if (this.showDebug && this.settings.keyBindPickBlock.getIsKeyPressed() && !this.handledDebugPress) + // { + // this.player.addChatMessage(new ChatComponentText("+--------------------------------------+")); + // this.player.addChatMessage(new ChatComponentText("| ToggleSneak Debug Info |")); + // this.player.addChatMessage(new ChatComponentText("+--------------------------------------+")); + // this.player.addChatMessage(new ChatComponentText(" ")); + // this.player.addChatMessage(new ChatComponentText("isFlying - " + (this.player.capabilities.isFlying == true ? "True" : "False"))); + // this.player.addChatMessage(new ChatComponentText("isCreative - " + (this.player.capabilities.isCreativeMode == true ? "True" : "False"))); + // this.player.addChatMessage(new ChatComponentText("enableFlyBoost - " + (SneakManager.optionEnableFlyBoost == true ? "True" : "False"))); + // this.player.addChatMessage(new ChatComponentText("flyBoostAmount - " + SneakManager.optionFlyBoostAmount)); + // this.player.addChatMessage(new ChatComponentText(" ")); + // this.player.addChatMessage(new ChatComponentText("keybindSprint - " + (this.settings.keyBindSprint.getIsKeyPressed() == true ? "True" : "False"))); + // this.player.addChatMessage(new ChatComponentText("keybindSneak - " + (this.settings.keyBindSneak.getIsKeyPressed() == true ? "True" : "False"))); + // this.player.addChatMessage(new ChatComponentText("keybindJump - " + (this.settings.keyBindJump.getIsKeyPressed() == true ? "True" : "False"))); + // this.player.addChatMessage(new ChatComponentText(" ")); + // this.player.addChatMessage(new ChatComponentText(" ")); + // + // this.handledDebugPress = true; + // } + // else if (this.showDebug && !this.settings.keyBindPickBlock.getIsKeyPressed() && this.handledDebugPress) + // { + // this.handledDebugPress = false; + // } + + // + // Fly Speed Boosting - Added 5/7/2014 + // + if(this.player.capabilities.getFlySpeed() != 0.05F) + { + this.player.capabilities.setFlySpeed(0.05F); + } + + + if(this.player.capabilities.allowFlying && !isJumping && this.player.movementInput.jump) + { + if(this.playerAPI.getFlyToggleTimerField() == 0) + { + this.playerAPI.setFlyToggleTimerField(7); + } + else + { + this.player.capabilities.isFlying = !this.player.capabilities.isFlying; + this.player.sendPlayerAbilities(); + this.playerAPI.setFlyToggleTimerField(0); + } + } + + if(this.player.capabilities.isFlying) + { + if(this.player.movementInput.sneak) + { + this.player.motionY -= 0.15D; + } + if(this.player.movementInput.jump) + { + this.player.motionY += 0.15D; + } + } + + if(this.player.isRidingHorse()) + { + if(this.playerAPI.getHorseJumpPowerCounterField() < 0) + { + this.playerAPI.setHorseJumpPowerCounterField(this.playerAPI.getHorseJumpPowerCounterField() + 1); + if(this.playerAPI.getHorseJumpPowerCounterField() == 0) + { + this.playerAPI.setHorseJumpPowerField(0.0F); + } + } + + if(isJumping && !this.player.movementInput.jump) + { + this.playerAPI.setHorseJumpPowerCounterField(this.playerAPI.getHorseJumpPowerCounterField() - 10); + this.playerAPI.setHorseJumpPowerCounterField(-10); + ((EntityClientPlayerMP)this.player).sendQueue.addToSendQueue(new C0BPacketEntityAction(this.player, 6, (int)(this.player.getHorseJumpPower() * 100.0F))); + } + else if(!isJumping && this.player.movementInput.jump) + { + this.playerAPI.setHorseJumpPowerCounterField(0); + this.playerAPI.setHorseJumpPowerField(0.0F); + } + else if(isJumping) + { + this.playerAPI.setHorseJumpPowerCounterField(this.playerAPI.getHorseJumpPowerCounterField() + 1); + if(this.playerAPI.getHorseJumpPowerCounterField() < 10) + { + this.playerAPI.setHorseJumpPowerField((float)this.playerAPI.getHorseJumpPowerCounterField() * 0.1F); + } + else + { + this.playerAPI.setHorseJumpPowerField(0.8F + 2.0F / (float)(this.playerAPI.getHorseJumpPowerCounterField() - 9) * 0.1F); + } + } + } + else + { + this.playerAPI.setHorseJumpPowerField(0.0F); + } + + this.playerAPI.superOnLivingUpdate(); + if(this.player.onGround && this.player.capabilities.isFlying) + { + this.player.capabilities.isFlying = false; + this.player.sendPlayerAbilities(); + } + } + } +}
\ No newline at end of file |