fix: GuiMove now works, I dug way more...
This commit is contained in:
parent
c55013ffcd
commit
2fd25d4709
1 changed files with 63 additions and 21 deletions
|
@ -5,25 +5,29 @@ import com.google.auto.service.AutoService;
|
||||||
import ftbsc.bscv.ICommons;
|
import ftbsc.bscv.ICommons;
|
||||||
import ftbsc.bscv.api.ILoadable;
|
import ftbsc.bscv.api.ILoadable;
|
||||||
import ftbsc.bscv.modules.AbstractModule;
|
import ftbsc.bscv.modules.AbstractModule;
|
||||||
|
import net.minecraft.client.gui.advancements.AdvancementsScreen;
|
||||||
|
import net.minecraft.client.gui.screen.CustomizeSkinScreen;
|
||||||
import net.minecraft.client.gui.screen.IngameMenuScreen;
|
import net.minecraft.client.gui.screen.IngameMenuScreen;
|
||||||
import net.minecraft.client.gui.screen.OptionsScreen;
|
import net.minecraft.client.gui.screen.OptionsScreen;
|
||||||
import net.minecraft.client.gui.screen.OptionsSoundsScreen;
|
import net.minecraft.client.gui.screen.OptionsSoundsScreen;
|
||||||
import net.minecraft.client.gui.screen.VideoSettingsScreen;
|
import net.minecraft.client.gui.screen.Screen;
|
||||||
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
|
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
|
||||||
import net.minecraft.client.settings.KeyBinding;
|
import net.minecraft.client.settings.KeyBinding;
|
||||||
import net.minecraft.client.util.InputMappings;
|
import net.minecraft.client.util.InputMappings;
|
||||||
import net.minecraftforge.event.entity.living.LivingEvent;
|
import net.minecraftforge.client.event.InputUpdateEvent;
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||||
|
import net.minecraftforge.fml.client.gui.screen.ModListScreen;
|
||||||
|
|
||||||
@AutoService(ILoadable.class)
|
@AutoService(ILoadable.class)
|
||||||
public class GuiMove extends AbstractModule implements ICommons {
|
public class GuiMove extends AbstractModule implements ICommons {
|
||||||
|
|
||||||
@SubscribeEvent
|
private boolean once = false;
|
||||||
public void onPlayerUpdate(LivingEvent.LivingUpdateEvent event) {
|
|
||||||
if (MC.player == null) return;
|
|
||||||
if (event.getEntityLiving() != MC.player) return;
|
|
||||||
|
|
||||||
KeyBinding[] keys = {
|
private boolean isKeyDown(KeyBinding key) {
|
||||||
|
return InputMappings.isKeyDown(MC.getWindow().getWindow(), key.getKey().getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
private KeyBinding[] keys = {
|
||||||
MC.options.keyUp,
|
MC.options.keyUp,
|
||||||
MC.options.keyDown,
|
MC.options.keyDown,
|
||||||
MC.options.keyLeft,
|
MC.options.keyLeft,
|
||||||
|
@ -31,19 +35,57 @@ public class GuiMove extends AbstractModule implements ICommons {
|
||||||
MC.options.keyJump,
|
MC.options.keyJump,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (
|
private Class<?>[] screens = {
|
||||||
MC.screen instanceof ContainerScreen
|
ContainerScreen.class,
|
||||||
|| MC.screen instanceof OptionsScreen
|
OptionsScreen.class,
|
||||||
|| MC.screen instanceof VideoSettingsScreen
|
OptionsSoundsScreen.class,
|
||||||
|| MC.screen instanceof OptionsSoundsScreen
|
IngameMenuScreen.class,
|
||||||
|| MC.screen instanceof IngameMenuScreen
|
AdvancementsScreen.class,
|
||||||
) {
|
ModListScreen.class,
|
||||||
for (KeyBinding key : keys) {
|
CustomizeSkinScreen.class,
|
||||||
|
};
|
||||||
|
|
||||||
|
private void forceMovementTick() {
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean allowMovementOnThisScreen(Screen screen) {
|
||||||
|
for (Class<?> clazz : this.screens) {
|
||||||
|
if (clazz.isInstance(screen)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public void onInputUpdate(InputUpdateEvent event) {
|
||||||
|
if (MC.player == null) return;
|
||||||
|
if (event.getEntityLiving() != MC.player) return;
|
||||||
|
|
||||||
|
if (this.allowMovementOnThisScreen(MC.screen)) {
|
||||||
|
once = true;
|
||||||
|
for (KeyBinding key : this.keys) {
|
||||||
boolean state = InputMappings.isKeyDown(MC.getWindow().getWindow(), key.getKey().getValue());
|
boolean state = InputMappings.isKeyDown(MC.getWindow().getWindow(), key.getKey().getValue());
|
||||||
|
if (state ^ key.isDown()) {
|
||||||
KeyBinding.set(key.getKey(), state);
|
KeyBinding.set(key.getKey(), state);
|
||||||
key.setDown(state);
|
key.setDown(state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this.forceMovementTick();
|
||||||
|
} else if (once) { // release all keys once we leave the screen
|
||||||
|
once = false;
|
||||||
|
KeyBinding.releaseAll(); // TODO maybe only release movement keys?
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue