Files
MinecraftForge/patches/minecraft/net/minecraft/client/player/LocalPlayer.java.patch
T
2024-10-25 18:04:34 -07:00

100 lines
5.6 KiB
Diff

--- a/net/minecraft/client/player/LocalPlayer.java
+++ b/net/minecraft/client/player/LocalPlayer.java
@@ -303,6 +_,7 @@
ServerboundPlayerActionPacket.Action serverboundplayeractionpacket$action = p_108701_
? ServerboundPlayerActionPacket.Action.DROP_ALL_ITEMS
: ServerboundPlayerActionPacket.Action.DROP_ITEM;
+ if (isUsingItem() && getUsedItemHand() == InteractionHand.MAIN_HAND && (p_108701_ || getUseItem().getCount() == 1)) stopUsingItem(); // Forge: fix MC-231097 on the clientside
ItemStack itemstack = this.getInventory().removeFromSelected(p_108701_);
this.connection.send(new ServerboundPlayerActionPacket(serverboundplayeractionpacket$action, BlockPos.ZERO, Direction.DOWN));
return !itemstack.isEmpty();
@@ -488,7 +_,11 @@
@Override
public void playSound(SoundEvent p_108651_, float p_108652_, float p_108653_) {
- this.level().playLocalSound(this.getX(), this.getY(), this.getZ(), p_108651_, this.getSoundSource(), p_108652_, p_108653_, false);
+ var holder = net.minecraft.core.registries.BuiltInRegistries.SOUND_EVENT.wrapAsHolder(p_108651_);
+ var event = net.minecraftforge.event.ForgeEventFactory.onPlaySoundAtEntity(this, holder, this.getSoundSource(), p_108652_, p_108653_);
+ if (event.isCanceled() || event.getSound() == null) return;
+ this.level().playLocalSound(this.getX(), this.getY(), this.getZ(), event.getSound().get(), event.getSource(), event.getNewVolume(), event.getNewPitch(), false);
+
}
@Override
@@ -682,6 +_,7 @@
&& (this.isShiftKeyDown() || !this.isSleeping() && !this.canPlayerFitWithinBlocksAndEntitiesWhen(Pose.STANDING));
float f = (float)this.getAttributeValue(Attributes.SNEAKING_SPEED);
this.input.tick(this.isMovingSlowly(), f);
+ net.minecraftforge.client.ForgeHooksClient.onMovementInputUpdate(this, this.input);
this.minecraft.getTutorial().onInput(this.input);
if (this.isUsingItem() && !this.isPassenger()) {
this.input.leftImpulse *= 0.2F;
@@ -710,7 +_,7 @@
boolean flag4 = this.canStartSprinting();
boolean flag5 = this.isPassenger() ? this.getVehicle().onGround() : this.onGround();
boolean flag6 = !flag1 && !flag2;
- if ((flag5 || this.isUnderWater()) && flag6 && flag4) {
+ if ((flag5 || this.isUnderWater() || this.canStartSwimming()) && flag6 && flag4) {
if (this.sprintTriggerTime <= 0 && !this.minecraft.options.keySprint.isDown()) {
this.sprintTriggerTime = 7;
} else {
@@ -718,15 +_,15 @@
}
}
- if ((!this.isInWater() || this.isUnderWater()) && flag4 && this.minecraft.options.keySprint.isDown()) {
+ if (!this.isSprinting() && (!(this.isInWater() || this.isInFluidType((fluidType, height) -> this.canSwimInFluidType(fluidType))) || (this.isUnderWater() || this.canStartSwimming())) && this.hasEnoughImpulseToStartSprinting() && flag4 && !this.isUsingItem() && !this.hasEffect(MobEffects.BLINDNESS) && this.minecraft.options.keySprint.isDown()) {
this.setSprinting(true);
}
if (this.isSprinting()) {
boolean flag7 = !this.input.hasForwardImpulse() || !this.hasEnoughFoodToStartSprinting();
- boolean flag8 = flag7 || this.horizontalCollision && !this.minorHorizontalCollision || this.isInWater() && !this.isUnderWater();
+ boolean flag8 = flag7 || this.horizontalCollision && !this.minorHorizontalCollision || this.isInWater() && !this.isUnderWater() || (this.isInFluidType((fluidType, height) -> this.canSwimInFluidType(fluidType)) && !this.canStartSwimming());
if (this.isSwimming()) {
- if (!this.onGround() && !this.input.keyPresses.shift() && flag7 || !this.isInWater()) {
+ if (!this.onGround() && !this.input.keyPresses.shift() && flag7 || !(this.isInWater() || this.isInFluidType((fluidType, height) -> this.canSwimInFluidType(fluidType)))) {
this.setSprinting(false);
}
} else if (flag8) {
@@ -763,8 +_,9 @@
}
this.wasFallFlying = this.isFallFlying();
- if (this.isInWater() && this.input.keyPresses.shift() && this.isAffectedByFluids()) {
- this.goDownInWater();
+ var fluidType = this.getMaxHeightFluidType();
+ if ((this.isInWater() || (!fluidType.isAir() && this.canSwimInFluidType(fluidType))) && this.input.keyPresses.shift() && this.isAffectedByFluids()) {
+ this.sinkInFluid(this.isInWater() ? net.minecraftforge.common.ForgeMod.WATER_TYPE.get() : fluidType);
}
if (this.isEyeInFluid(FluidTags.WATER)) {
@@ -870,6 +_,8 @@
@Override
public void rideTick() {
super.rideTick();
+ if (this.wantsToStopRiding() && this.isPassenger())
+ this.input.keyPresses = this.input.keyPresses.jump(false);
this.handsBusy = false;
if (this.getControlledVehicle() instanceof AbstractBoat abstractboat) {
abstractboat.setInput(
@@ -1146,6 +_,18 @@
@Override
public float getVisualRotationYInDegrees() {
return this.getYRot();
+ }
+
+ public void updateSyncFields(LocalPlayer old) {
+ this.xLast = old.xLast;
+ this.yLast = old.yLast;
+ this.zLast = old.zLast;
+ this.yRotLast = old.yRotLast;
+ this.xRotLast = old.xRotLast;
+ this.lastOnGround = old.lastOnGround;
+ this.wasShiftKeyDown = old.wasShiftKeyDown;
+ this.wasSprinting = old.wasSprinting;
+ this.positionReminder = old.positionReminder;
}
@Override