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
|
@ -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.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
|
||||||
public interface IKeybindable
|
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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,7 +3,7 @@ package WayofTime.bloodmagic.item.sigil;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import WayofTime.bloodmagic.client.KeyBindingBloodMagic;
|
import WayofTime.bloodmagic.client.key.KeyBindings;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
@ -27,7 +27,7 @@ import WayofTime.bloodmagic.api.iface.IAltarReader;
|
||||||
import WayofTime.bloodmagic.api.iface.IBindable;
|
import WayofTime.bloodmagic.api.iface.IBindable;
|
||||||
import WayofTime.bloodmagic.api.util.helper.NBTHelper;
|
import WayofTime.bloodmagic.api.util.helper.NBTHelper;
|
||||||
import WayofTime.bloodmagic.util.Utils;
|
import WayofTime.bloodmagic.util.Utils;
|
||||||
import WayofTime.bloodmagic.client.IKeybindable;
|
import WayofTime.bloodmagic.client.key.IKeybindable;
|
||||||
import WayofTime.bloodmagic.util.helper.TextHelper;
|
import WayofTime.bloodmagic.util.helper.TextHelper;
|
||||||
|
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
|
@ -42,9 +42,9 @@ public class ItemSigilHolding extends ItemSigilBase implements IKeybindable, IAl
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onKeyPressed(ItemStack stack, EntityPlayer player, KeyBindingBloodMagic.KeyBindings key, boolean showInChat)
|
public void onKeyPressed(ItemStack stack, EntityPlayer player, KeyBindings key, boolean showInChat)
|
||||||
{
|
{
|
||||||
if (stack == player.getHeldItemMainhand() && stack.getItem() instanceof ItemSigilHolding && key.equals(KeyBindingBloodMagic.KeyBindings.OPEN_HOLDING))
|
if (stack == player.getHeldItemMainhand() && stack.getItem() instanceof ItemSigilHolding && key.equals(KeyBindings.OPEN_HOLDING))
|
||||||
{
|
{
|
||||||
Utils.setUUID(stack);
|
Utils.setUUID(stack);
|
||||||
player.openGui(BloodMagic.instance, Constants.Gui.SIGIL_HOLDING_GUI, player.worldObj, (int) player.posX, (int) player.posY, (int) player.posZ);
|
player.openGui(BloodMagic.instance, Constants.Gui.SIGIL_HOLDING_GUI, player.worldObj, (int) player.posX, (int) player.posY, (int) player.posZ);
|
||||||
|
@ -73,7 +73,7 @@ public class ItemSigilHolding extends ItemSigilBase implements IKeybindable, IAl
|
||||||
public void addInformation(ItemStack stack, EntityPlayer player, List<String> tooltip, boolean advanced)
|
public void addInformation(ItemStack stack, EntityPlayer player, List<String> tooltip, boolean advanced)
|
||||||
{
|
{
|
||||||
super.addInformation(stack, player, tooltip, advanced);
|
super.addInformation(stack, player, tooltip, advanced);
|
||||||
tooltip.add(TextHelper.localizeEffect("tooltip.BloodMagic.sigil.holding.press", KeyBindingBloodMagic.KeyBindings.OPEN_HOLDING.getKey().getDisplayName()));
|
tooltip.add(TextHelper.localizeEffect("tooltip.BloodMagic.sigil.holding.press", KeyBindings.OPEN_HOLDING.getKey().getDisplayName()));
|
||||||
|
|
||||||
if (!stack.hasTagCompound())
|
if (!stack.hasTagCompound())
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package WayofTime.bloodmagic.network;
|
package WayofTime.bloodmagic.network;
|
||||||
|
|
||||||
import WayofTime.bloodmagic.client.KeyBindingBloodMagic;
|
import WayofTime.bloodmagic.client.key.IKeybindable;
|
||||||
import WayofTime.bloodmagic.client.IKeybindable;
|
import WayofTime.bloodmagic.client.key.KeyBindings;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
@ -18,7 +18,7 @@ public class KeyProcessor implements IMessage, IMessageHandler<KeyProcessor, IMe
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public KeyProcessor(KeyBindingBloodMagic.KeyBindings key, boolean showInChat)
|
public KeyProcessor(KeyBindings key, boolean showInChat)
|
||||||
{
|
{
|
||||||
this.keyId = key.ordinal();
|
this.keyId = key.ordinal();
|
||||||
this.showInChat = showInChat;
|
this.showInChat = showInChat;
|
||||||
|
@ -48,11 +48,11 @@ public class KeyProcessor implements IMessage, IMessageHandler<KeyProcessor, IMe
|
||||||
ItemStack heldStack = entityPlayer.getHeldItemMainhand();
|
ItemStack heldStack = entityPlayer.getHeldItemMainhand();
|
||||||
if (heldStack.getItem() instanceof IKeybindable)
|
if (heldStack.getItem() instanceof IKeybindable)
|
||||||
{
|
{
|
||||||
if (msg.keyId < 0 || msg.keyId >= KeyBindingBloodMagic.KeyBindings.values().length)
|
if (msg.keyId < 0 || msg.keyId >= KeyBindings.values().length)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
KeyBindingBloodMagic.KeyBindings key = KeyBindingBloodMagic.KeyBindings.values()[msg.keyId];
|
KeyBindings key = KeyBindings.values()[msg.keyId];
|
||||||
((IKeybindable) heldStack.getItem()).onKeyPressed(heldStack, entityPlayer, key, msg.showInChat);
|
((IKeybindable) heldStack.getItem()).onKeyPressed(heldStack, entityPlayer, key, msg.showInChat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ import java.util.Set;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import WayofTime.bloodmagic.client.KeyBindingBloodMagic;
|
import WayofTime.bloodmagic.client.key.KeyBindings;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.entity.EntityPlayerSP;
|
import net.minecraft.client.entity.EntityPlayerSP;
|
||||||
import net.minecraft.client.renderer.GlStateManager;
|
import net.minecraft.client.renderer.GlStateManager;
|
||||||
|
@ -210,7 +210,7 @@ public class ClientHandler
|
||||||
if (!minecraft.inGameHasFocus)
|
if (!minecraft.inGameHasFocus)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (KeyBindingBloodMagic.KeyBindings keyBinding : KeyBindingBloodMagic.KeyBindings.values())
|
for (KeyBindings keyBinding : KeyBindings.values())
|
||||||
if (keyBinding.getKey().isPressed())
|
if (keyBinding.getKey().isPressed())
|
||||||
keyBinding.handleKeybind();
|
keyBinding.handleKeybind();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue