mirror of
https://github.com/squeek502/Squake.git
synced 2025-08-03 09:47:22 -04:00
Add client-side keybind for toggling the movement system on/off
- Unbound by default - The setting will persist between save/quits (saved to the config) Closes #11 and closes #17
This commit is contained in:
parent
bca6db8289
commit
bb45d2fc3d
@ -2,6 +2,7 @@ package squeek.quakemovement;
|
||||
|
||||
import java.io.File;
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
import net.minecraftforge.common.config.Property;
|
||||
|
||||
public class ModConfig
|
||||
{
|
||||
@ -59,6 +60,11 @@ public class ModConfig
|
||||
private static final String MAX_AIR_ACCEL_PER_TICK_NAME = "maxAirAccelerationPerTick";
|
||||
private static final double MAX_AIR_ACCEL_PER_TICK_DEFAULT = 0.045D;
|
||||
|
||||
public static boolean ENABLED;
|
||||
private static Property ENABLED_PROPERTY;
|
||||
private static final String ENABLED_NAME = "enabled";
|
||||
private static final boolean ENABLED_DEFAULT = true;
|
||||
|
||||
private static Configuration config;
|
||||
|
||||
public static void init(File file)
|
||||
@ -84,6 +90,16 @@ public class ModConfig
|
||||
|
||||
INCREASED_FALL_DISTANCE = (float) (config.get(CATEGORY_MOVEMENT, INCREASED_FALL_DISTANCE_NAME, INCREASED_FALL_DISTANCE_DEFAULT, "increases the distance needed to fall in order to take fall damage; this is a server-side setting").getDouble(INCREASED_FALL_DISTANCE_DEFAULT));
|
||||
|
||||
ENABLED_PROPERTY = config.get(CATEGORY_MOVEMENT, ENABLED_NAME, ENABLED_DEFAULT, "turns off/on the quake-style movement for the client (essentially the saved value of the ingame toggle keybind)");
|
||||
ENABLED = ENABLED_PROPERTY.getBoolean(ENABLED_DEFAULT);
|
||||
|
||||
save();
|
||||
}
|
||||
|
||||
public static void setEnabled(boolean enabled)
|
||||
{
|
||||
ModConfig.ENABLED = enabled;
|
||||
ENABLED_PROPERTY.set(enabled);
|
||||
save();
|
||||
}
|
||||
|
||||
|
@ -26,6 +26,10 @@ public class ModQuakeMovement
|
||||
{
|
||||
ModConfig.init(event.getSuggestedConfigurationFile());
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
if (event.getSide() == Side.CLIENT)
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.register(new ToggleKeyHandler());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
@ -48,6 +48,12 @@ public class QuakeClientPlayer extends ClientPlayerBase
|
||||
@Override
|
||||
public void moveEntityWithHeading(float sidemove, float forwardmove)
|
||||
{
|
||||
if (!ModConfig.ENABLED)
|
||||
{
|
||||
super.moveEntityWithHeading(sidemove, forwardmove);
|
||||
return;
|
||||
}
|
||||
|
||||
double d0 = this.player.posX;
|
||||
double d1 = this.player.posY;
|
||||
double d2 = this.player.posZ;
|
||||
@ -103,6 +109,12 @@ public class QuakeClientPlayer extends ClientPlayerBase
|
||||
@Override
|
||||
public void moveFlying(float sidemove, float forwardmove, float wishspeed)
|
||||
{
|
||||
if (!ModConfig.ENABLED)
|
||||
{
|
||||
super.moveFlying(sidemove, forwardmove, wishspeed);
|
||||
return;
|
||||
}
|
||||
|
||||
if ((this.player.capabilities.isFlying && this.player.getRidingEntity() == null) || this.player.isInWater() || this.player.isInLava() || this.player.isOnLadder())
|
||||
{
|
||||
super.moveFlying(sidemove, forwardmove, wishspeed);
|
||||
@ -121,6 +133,9 @@ public class QuakeClientPlayer extends ClientPlayerBase
|
||||
{
|
||||
super.jump();
|
||||
|
||||
if (!ModConfig.ENABLED)
|
||||
return;
|
||||
|
||||
// undo this dumb thing
|
||||
if (this.player.isSprinting())
|
||||
{
|
||||
|
37
java/squeek/quakemovement/ToggleKeyHandler.java
Normal file
37
java/squeek/quakemovement/ToggleKeyHandler.java
Normal file
@ -0,0 +1,37 @@
|
||||
package squeek.quakemovement;
|
||||
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
import net.minecraftforge.fml.client.FMLClientHandler;
|
||||
import net.minecraftforge.fml.client.registry.ClientRegistry;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.InputEvent;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class ToggleKeyHandler
|
||||
{
|
||||
private static final KeyBinding TOGGLE_KEY = new KeyBinding("squake.key.toggle", Keyboard.CHAR_NONE, ModInfo.MODID);
|
||||
|
||||
static
|
||||
{
|
||||
ClientRegistry.registerKeyBinding(TOGGLE_KEY);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onKeyEvent(InputEvent.KeyInputEvent event)
|
||||
{
|
||||
if (TOGGLE_KEY.isPressed())
|
||||
{
|
||||
ModConfig.setEnabled(!ModConfig.ENABLED);
|
||||
|
||||
EntityPlayer player = FMLClientHandler.instance().getClientPlayerEntity();
|
||||
String feedback = ModConfig.ENABLED ? I18n.format("squake.key.toggle.enabled") : I18n.format("squake.key.toggle.disabled");
|
||||
player.addChatMessage(new TextComponentString("[" + ModInfo.MODID + "] " + feedback));
|
||||
}
|
||||
}
|
||||
}
|
4
resources/assets/squake/lang/en_US.lang
Normal file
4
resources/assets/squake/lang/en_US.lang
Normal file
@ -0,0 +1,4 @@
|
||||
# Keybinds
|
||||
squake.key.toggle=Toggle Movement System On/Off
|
||||
squake.key.toggle.enabled=Movement system enabled
|
||||
squake.key.toggle.disabled=Movement system disabled
|
Loading…
x
Reference in New Issue
Block a user