Fix server crash with holding sigil keybind (#915)
@Arcaratus, poking because this will break BA again. I separated things into new classes.
This commit is contained in:
parent
e9549fd9db
commit
d1f98be462
7 changed files with 143 additions and 134 deletions
|
@ -1,120 +0,0 @@
|
|||
package WayofTime.bloodmagic.client;
|
||||
|
||||
import WayofTime.bloodmagic.api.Constants;
|
||||
import WayofTime.bloodmagic.item.sigil.ItemSigilHolding;
|
||||
import WayofTime.bloodmagic.network.BloodMagicPacketHandler;
|
||||
import WayofTime.bloodmagic.network.KeyProcessor;
|
||||
import WayofTime.bloodmagic.util.handler.event.ClientHandler;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.entity.EntityPlayerSP;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.client.settings.IKeyConflictContext;
|
||||
import net.minecraftforge.client.settings.KeyConflictContext;
|
||||
import net.minecraftforge.client.settings.KeyModifier;
|
||||
import net.minecraftforge.fml.client.registry.ClientRegistry;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class KeyBindingBloodMagic extends KeyBinding
|
||||
{
|
||||
@SideOnly(Side.CLIENT)
|
||||
public KeyBindingBloodMagic(KeyBindings key)
|
||||
{
|
||||
super(key.getDescription(), key.getKeyConflictContext(), key.getKeyModifier(), key.getKeyCode(), Constants.Mod.NAME);
|
||||
|
||||
ClientRegistry.registerKeyBinding(this);
|
||||
}
|
||||
|
||||
// @formatter:off
|
||||
public enum KeyBindings
|
||||
{
|
||||
OPEN_HOLDING(KeyConflictContext.IN_GAME, KeyModifier.NONE, Keyboard.KEY_H)
|
||||
{
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void handleKeybind()
|
||||
{
|
||||
ItemStack itemStack = ClientHandler.minecraft.thePlayer.getHeldItemMainhand();
|
||||
if (itemStack != null && itemStack.getItem() instanceof IKeybindable)
|
||||
BloodMagicPacketHandler.INSTANCE.sendToServer(new KeyProcessor(this, false));
|
||||
}
|
||||
},
|
||||
CYCLE_HOLDING_POS(KeyConflictContext.IN_GAME, KeyModifier.SHIFT, Keyboard.KEY_EQUALS)
|
||||
{
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void handleKeybind()
|
||||
{
|
||||
EntityPlayerSP player = Minecraft.getMinecraft().thePlayer;
|
||||
if (player.getHeldItemMainhand() != null && player.getHeldItemMainhand().getItem() instanceof ItemSigilHolding)
|
||||
ClientHandler.cycleSigil(player.getHeldItemMainhand(), player, -1);
|
||||
}
|
||||
},
|
||||
CYCLE_HOLDING_NEG(KeyConflictContext.IN_GAME, KeyModifier.SHIFT, Keyboard.KEY_MINUS)
|
||||
{
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void handleKeybind()
|
||||
{
|
||||
EntityPlayerSP player = Minecraft.getMinecraft().thePlayer;
|
||||
if (player.getHeldItemMainhand() != null && player.getHeldItemMainhand().getItem() instanceof ItemSigilHolding)
|
||||
ClientHandler.cycleSigil(player.getHeldItemMainhand(), player, 1);
|
||||
}
|
||||
},
|
||||
;
|
||||
// @formatter:on
|
||||
|
||||
private final IKeyConflictContext keyConflictContext;
|
||||
private final KeyModifier keyModifier;
|
||||
private final int keyCode;
|
||||
|
||||
private KeyBinding key;
|
||||
|
||||
KeyBindings(IKeyConflictContext keyConflictContext, KeyModifier keyModifier, int keyCode)
|
||||
{
|
||||
this.keyConflictContext = keyConflictContext;
|
||||
this.keyModifier = keyModifier;
|
||||
this.keyCode = keyCode;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public abstract void handleKeybind();
|
||||
|
||||
public IKeyConflictContext getKeyConflictContext()
|
||||
{
|
||||
return keyConflictContext;
|
||||
}
|
||||
|
||||
public KeyModifier getKeyModifier()
|
||||
{
|
||||
return keyModifier;
|
||||
}
|
||||
|
||||
public int getKeyCode()
|
||||
{
|
||||
return keyCode;
|
||||
}
|
||||
|
||||
public KeyBinding getKey()
|
||||
{
|
||||
if (key == null)
|
||||
key = new KeyBindingBloodMagic(this);
|
||||
|
||||
return key;
|
||||
}
|
||||
|
||||
public void setKey(KeyBinding key)
|
||||
{
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public String getDescription()
|
||||
{
|
||||
return Constants.Mod.MODID + ".keybind." + name().toLowerCase(Locale.ENGLISH);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,9 +1,9 @@
|
|||
package WayofTime.bloodmagic.client;
|
||||
package WayofTime.bloodmagic.client.key;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public interface IKeybindable
|
||||
{
|
||||
void onKeyPressed(ItemStack stack, EntityPlayer player, KeyBindingBloodMagic.KeyBindings key, boolean showInChat);
|
||||
void onKeyPressed(ItemStack stack, EntityPlayer player, KeyBindings key, boolean showInChat);
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package WayofTime.bloodmagic.client.key;
|
||||
|
||||
import WayofTime.bloodmagic.api.Constants;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import net.minecraftforge.fml.client.registry.ClientRegistry;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class KeyBindingBloodMagic extends KeyBinding
|
||||
{
|
||||
public KeyBindingBloodMagic(KeyBindings key)
|
||||
{
|
||||
super(key.getDescription(), key.getKeyConflictContext(), key.getKeyModifier(), key.getKeyCode(), Constants.Mod.NAME);
|
||||
|
||||
ClientRegistry.registerKeyBinding(this);
|
||||
}
|
||||
}
|
111
src/main/java/WayofTime/bloodmagic/client/key/KeyBindings.java
Normal file
111
src/main/java/WayofTime/bloodmagic/client/key/KeyBindings.java
Normal file
|
@ -0,0 +1,111 @@
|
|||
package WayofTime.bloodmagic.client.key;
|
||||
|
||||
import WayofTime.bloodmagic.api.Constants;
|
||||
import WayofTime.bloodmagic.item.sigil.ItemSigilHolding;
|
||||
import WayofTime.bloodmagic.network.BloodMagicPacketHandler;
|
||||
import WayofTime.bloodmagic.network.KeyProcessor;
|
||||
import WayofTime.bloodmagic.util.handler.event.ClientHandler;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.entity.EntityPlayerSP;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.client.settings.IKeyConflictContext;
|
||||
import net.minecraftforge.client.settings.KeyConflictContext;
|
||||
import net.minecraftforge.client.settings.KeyModifier;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public enum KeyBindings
|
||||
{
|
||||
// @formatter:off
|
||||
OPEN_HOLDING(KeyConflictContext.IN_GAME, KeyModifier.NONE, Keyboard.KEY_H)
|
||||
{
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void handleKeybind()
|
||||
{
|
||||
ItemStack itemStack = ClientHandler.minecraft.thePlayer.getHeldItemMainhand();
|
||||
if (itemStack != null && itemStack.getItem() instanceof IKeybindable)
|
||||
BloodMagicPacketHandler.INSTANCE.sendToServer(new KeyProcessor(this, false));
|
||||
}
|
||||
},
|
||||
CYCLE_HOLDING_POS(KeyConflictContext.IN_GAME, KeyModifier.SHIFT, Keyboard.KEY_EQUALS)
|
||||
{
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void handleKeybind()
|
||||
{
|
||||
EntityPlayerSP player = Minecraft.getMinecraft().thePlayer;
|
||||
if (player.getHeldItemMainhand() != null && player.getHeldItemMainhand().getItem() instanceof ItemSigilHolding)
|
||||
ClientHandler.cycleSigil(player.getHeldItemMainhand(), player, -1);
|
||||
}
|
||||
},
|
||||
CYCLE_HOLDING_NEG(KeyConflictContext.IN_GAME, KeyModifier.SHIFT, Keyboard.KEY_MINUS)
|
||||
{
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void handleKeybind()
|
||||
{
|
||||
EntityPlayerSP player = Minecraft.getMinecraft().thePlayer;
|
||||
if (player.getHeldItemMainhand() != null && player.getHeldItemMainhand().getItem() instanceof ItemSigilHolding)
|
||||
ClientHandler.cycleSigil(player.getHeldItemMainhand(), player, 1);
|
||||
}
|
||||
},
|
||||
;
|
||||
// @formatter:on
|
||||
|
||||
private final IKeyConflictContext keyConflictContext;
|
||||
private final KeyModifier keyModifier;
|
||||
private final int keyCode;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
private KeyBinding key;
|
||||
|
||||
KeyBindings(IKeyConflictContext keyConflictContext, KeyModifier keyModifier, int keyCode)
|
||||
{
|
||||
this.keyConflictContext = keyConflictContext;
|
||||
this.keyModifier = keyModifier;
|
||||
this.keyCode = keyCode;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public abstract void handleKeybind();
|
||||
|
||||
public IKeyConflictContext getKeyConflictContext()
|
||||
{
|
||||
return keyConflictContext;
|
||||
}
|
||||
|
||||
public KeyModifier getKeyModifier()
|
||||
{
|
||||
return keyModifier;
|
||||
}
|
||||
|
||||
public int getKeyCode()
|
||||
{
|
||||
return keyCode;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public KeyBinding getKey()
|
||||
{
|
||||
if (key == null)
|
||||
key = new KeyBindingBloodMagic(this);
|
||||
|
||||
return key;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void setKey(KeyBinding key)
|
||||
{
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public String getDescription()
|
||||
{
|
||||
return Constants.Mod.MODID + ".keybind." + name().toLowerCase(Locale.ENGLISH);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue