fix: should also work with boats

This commit is contained in:
əlemi 2023-03-12 00:16:41 +01:00
parent 53e24b2e08
commit adb72b9c58
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -15,6 +15,8 @@ import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.client.util.InputMappings;
import net.minecraft.entity.Entity;
import net.minecraft.util.MovementInput;
import net.minecraftforge.client.event.InputUpdateEvent;
import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.eventbus.api.SubscribeEvent;
@ -59,19 +61,19 @@ public class GuiMove extends AbstractModule {
CustomizeSkinScreen.class,
};
private void forceMovementTick() {
private void forceMovementTick(MovementInput input) {
// TODO can we patch to make this always happen instead of duplicating code?
MC.player.input.up = this.isKeyDown(MC.options.keyUp);
MC.player.input.down = this.isKeyDown(MC.options.keyDown);
MC.player.input.left = this.isKeyDown(MC.options.keyLeft);
MC.player.input.right = this.isKeyDown(MC.options.keyRight);
MC.player.input.jumping = this.isKeyDown(MC.options.keyJump);
MC.player.input.shiftKeyDown = this.isKeyDown(MC.options.keyShift);
input.up = this.isKeyDown(MC.options.keyUp);
input.down = this.isKeyDown(MC.options.keyDown);
input.left = this.isKeyDown(MC.options.keyLeft);
input.right = this.isKeyDown(MC.options.keyRight);
input.jumping = this.isKeyDown(MC.options.keyJump);
input.shiftKeyDown = this.isKeyDown(MC.options.keyShift);
MC.player.input.forwardImpulse = MC.player.input.up == MC.player.input.down ? 0.0F : (MC.player.input.up ? 1.0F : -1.0F);
MC.player.input.leftImpulse = MC.player.input.left == MC.player.input.right ? 0.0F : (MC.player.input.left ? 1.0F : -1.0F);
input.forwardImpulse = input.up == input.down ? 0.0F : (input.up ? 1.0F : -1.0F);
input.leftImpulse = input.left == input.right ? 0.0F : (input.left ? 1.0F : -1.0F);
if (MC.player.input.shiftKeyDown && !MC.player.isSprinting()) {
if (input.shiftKeyDown && !MC.player.isSprinting()) {
MC.player.setSprinting(true);
}
}
@ -92,10 +94,18 @@ public class GuiMove extends AbstractModule {
}
}
private boolean overrideEntityInput(Entity in) {
if (MC.player == null) return false;
if (MC.player.getVehicle() != null) {
if (in.equals(MC.player.getVehicle())) return true;
}
if (in.equals(MC.player)) return true;
return false;
}
@SubscribeEvent
public void onInputUpdate(InputUpdateEvent event) {
if (MC.player == null) return;
if (event.getEntityLiving() != MC.player) return;
if (!this.overrideEntityInput(event.getEntityLiving())) return;
if (this.allowMovementOnThisScreen(MC.screen)) {
for (KeyBinding key : this.keys) {
@ -105,7 +115,7 @@ public class GuiMove extends AbstractModule {
key.setDown(state);
}
}
this.forceMovementTick();
this.forceMovementTick(MC.player.input);
}
}
}