diff --git a/src/main/java/WayofTime/bloodmagic/client/IKeybindable.java b/src/main/java/WayofTime/bloodmagic/client/IKeybindable.java new file mode 100644 index 00000000..e4b41a74 --- /dev/null +++ b/src/main/java/WayofTime/bloodmagic/client/IKeybindable.java @@ -0,0 +1,9 @@ +package WayofTime.bloodmagic.client; + +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); +} diff --git a/src/main/java/WayofTime/bloodmagic/client/KeyBindingBloodMagic.java b/src/main/java/WayofTime/bloodmagic/client/KeyBindingBloodMagic.java new file mode 100644 index 00000000..b9742854 --- /dev/null +++ b/src/main/java/WayofTime/bloodmagic/client/KeyBindingBloodMagic.java @@ -0,0 +1,120 @@ +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); + } + } +} diff --git a/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilHolding.java b/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilHolding.java index 4e706ee6..40a81fba 100644 --- a/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilHolding.java +++ b/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilHolding.java @@ -3,8 +3,7 @@ package WayofTime.bloodmagic.item.sigil; import java.util.Collections; import java.util.List; -import WayofTime.bloodmagic.util.handler.event.ClientHandler; -import net.minecraft.client.settings.KeyBinding; +import WayofTime.bloodmagic.client.KeyBindingBloodMagic; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; @@ -17,7 +16,6 @@ import net.minecraft.util.EnumHand; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; import net.minecraft.world.World; -import net.minecraftforge.client.settings.KeyModifier; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @@ -29,12 +27,10 @@ import WayofTime.bloodmagic.api.iface.IAltarReader; import WayofTime.bloodmagic.api.iface.IBindable; import WayofTime.bloodmagic.api.util.helper.NBTHelper; import WayofTime.bloodmagic.util.Utils; -import WayofTime.bloodmagic.util.handler.BMKeyBinding; -import WayofTime.bloodmagic.util.handler.IKeybindable; +import WayofTime.bloodmagic.client.IKeybindable; import WayofTime.bloodmagic.util.helper.TextHelper; import com.google.common.base.Strings; -import org.lwjgl.input.Keyboard; public class ItemSigilHolding extends ItemSigilBase implements IKeybindable, IAltarReader { @@ -46,9 +42,9 @@ public class ItemSigilHolding extends ItemSigilBase implements IKeybindable, IAl } @Override - public void onKeyPressed(ItemStack stack, EntityPlayer player, BMKeyBinding.Key key, boolean showInChat) + public void onKeyPressed(ItemStack stack, EntityPlayer player, KeyBindingBloodMagic.KeyBindings key, boolean showInChat) { - if (stack == player.getHeldItemMainhand() && stack.getItem() instanceof ItemSigilHolding && key.equals(BMKeyBinding.Key.OPEN_SIGIL_HOLDING)) + if (stack == player.getHeldItemMainhand() && stack.getItem() instanceof ItemSigilHolding && key.equals(KeyBindingBloodMagic.KeyBindings.OPEN_HOLDING)) { Utils.setUUID(stack); player.openGui(BloodMagic.instance, Constants.Gui.SIGIL_HOLDING_GUI, player.worldObj, (int) player.posX, (int) player.posY, (int) player.posZ); @@ -77,7 +73,7 @@ public class ItemSigilHolding extends ItemSigilBase implements IKeybindable, IAl public void addInformation(ItemStack stack, EntityPlayer player, List tooltip, boolean advanced) { super.addInformation(stack, player, tooltip, advanced); - tooltip.add(TextHelper.localizeEffect("tooltip.BloodMagic.sigil.holding.press", ClientHandler.keyOpenSigilHolding.getDisplayName())); + tooltip.add(TextHelper.localizeEffect("tooltip.BloodMagic.sigil.holding.press", KeyBindingBloodMagic.KeyBindings.OPEN_HOLDING.getKey().getDisplayName())); ItemStack[] inv = getInternalInventory(stack); diff --git a/src/main/java/WayofTime/bloodmagic/network/KeyProcessor.java b/src/main/java/WayofTime/bloodmagic/network/KeyProcessor.java index 234f83b8..11f72ce4 100644 --- a/src/main/java/WayofTime/bloodmagic/network/KeyProcessor.java +++ b/src/main/java/WayofTime/bloodmagic/network/KeyProcessor.java @@ -1,7 +1,7 @@ package WayofTime.bloodmagic.network; -import WayofTime.bloodmagic.util.handler.BMKeyBinding; -import WayofTime.bloodmagic.util.handler.IKeybindable; +import WayofTime.bloodmagic.client.KeyBindingBloodMagic; +import WayofTime.bloodmagic.client.IKeybindable; import io.netty.buffer.ByteBuf; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; @@ -18,7 +18,7 @@ public class KeyProcessor implements IMessage, IMessageHandler= BMKeyBinding.Key.values().length) + if (msg.keyId < 0 || msg.keyId >= KeyBindingBloodMagic.KeyBindings.values().length) { return null; } - BMKeyBinding.Key key = BMKeyBinding.Key.values()[msg.keyId]; + KeyBindingBloodMagic.KeyBindings key = KeyBindingBloodMagic.KeyBindings.values()[msg.keyId]; ((IKeybindable) heldStack.getItem()).onKeyPressed(heldStack, entityPlayer, key, msg.showInChat); } } diff --git a/src/main/java/WayofTime/bloodmagic/util/handler/BMKeyBinding.java b/src/main/java/WayofTime/bloodmagic/util/handler/BMKeyBinding.java deleted file mode 100644 index 06977042..00000000 --- a/src/main/java/WayofTime/bloodmagic/util/handler/BMKeyBinding.java +++ /dev/null @@ -1,36 +0,0 @@ -package WayofTime.bloodmagic.util.handler; - -import WayofTime.bloodmagic.api.Constants; -import WayofTime.bloodmagic.network.BloodMagicPacketHandler; -import WayofTime.bloodmagic.network.KeyProcessor; -import WayofTime.bloodmagic.util.handler.event.ClientHandler; -import net.minecraft.client.settings.KeyBinding; -import net.minecraft.item.ItemStack; -import net.minecraftforge.fml.client.registry.ClientRegistry; - -public class BMKeyBinding extends KeyBinding -{ - private Key keyType; - - public BMKeyBinding(String name, int keyId, Key keyType) - { - super(Constants.Mod.MODID + ".keybind." + name, keyId, Constants.Mod.NAME); - this.keyType = keyType; - ClientRegistry.registerKeyBinding(this); - ClientHandler.keyBindings.add(this); - } - - public void handleKeyPress() - { - ItemStack itemStack = ClientHandler.minecraft.thePlayer.getHeldItemMainhand(); - if (itemStack != null && itemStack.getItem() instanceof IKeybindable) - { - BloodMagicPacketHandler.INSTANCE.sendToServer(new KeyProcessor(this.keyType, false)); - } - } - - public enum Key - { - OPEN_SIGIL_HOLDING - } -} \ No newline at end of file diff --git a/src/main/java/WayofTime/bloodmagic/util/handler/IKeybindable.java b/src/main/java/WayofTime/bloodmagic/util/handler/IKeybindable.java deleted file mode 100644 index ed3421c7..00000000 --- a/src/main/java/WayofTime/bloodmagic/util/handler/IKeybindable.java +++ /dev/null @@ -1,9 +0,0 @@ -package WayofTime.bloodmagic.util.handler; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; - -public interface IKeybindable -{ - void onKeyPressed(ItemStack stack, EntityPlayer player, BMKeyBinding.Key key, boolean showInChat); -} diff --git a/src/main/java/WayofTime/bloodmagic/util/handler/event/ClientHandler.java b/src/main/java/WayofTime/bloodmagic/util/handler/event/ClientHandler.java index 2a08ff33..0d0d12fe 100644 --- a/src/main/java/WayofTime/bloodmagic/util/handler/event/ClientHandler.java +++ b/src/main/java/WayofTime/bloodmagic/util/handler/event/ClientHandler.java @@ -8,13 +8,13 @@ import java.util.Set; import javax.annotation.Nullable; +import WayofTime.bloodmagic.client.KeyBindingBloodMagic; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.block.model.ModelResourceLocation; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.renderer.texture.TextureMap; -import net.minecraft.client.settings.KeyBinding; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -31,18 +31,14 @@ import net.minecraftforge.client.event.RenderWorldLastEvent; import net.minecraftforge.client.event.TextureStitchEvent; import net.minecraftforge.client.event.sound.PlaySoundEvent; import net.minecraftforge.client.model.ModelLoader; -import net.minecraftforge.client.settings.KeyConflictContext; -import net.minecraftforge.client.settings.KeyModifier; import net.minecraftforge.event.entity.player.ItemTooltipEvent; 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.ReflectionHelper; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; -import org.lwjgl.input.Keyboard; import org.lwjgl.opengl.GL11; import WayofTime.bloodmagic.BloodMagic; @@ -63,7 +59,6 @@ import WayofTime.bloodmagic.network.SigilHoldingPacketProcessor; import WayofTime.bloodmagic.registry.ModPotions; import WayofTime.bloodmagic.tile.TileMasterRitualStone; import WayofTime.bloodmagic.util.GhostItemHelper; -import WayofTime.bloodmagic.util.handler.BMKeyBinding; import WayofTime.bloodmagic.util.helper.TextHelper; import com.google.common.base.Stopwatch; @@ -92,7 +87,6 @@ public class ClientHandler public static TextureAtlasSprite crystalCluster; public static Minecraft minecraft = Minecraft.getMinecraft(); - public static final List keyBindings = new ArrayList(); public static final List hudElements = new ArrayList(); private static TileMasterRitualStone mrsHoloTile; @@ -103,17 +97,6 @@ public class ClientHandler boolean doCrystalRenderTest = true; public static ResourceLocation crystalResource = new ResourceLocation(Constants.Mod.DOMAIN + "textures/entities/defaultCrystalLayer.png"); - // Contrary to what your IDE tells you, this *is* actually needed. - // TODO - Rewrite this "BMKeyBinding" thing. Arc what the heck were you thinking... - public static final BMKeyBinding keyOpenSigilHolding = new BMKeyBinding("openSigilHolding", Keyboard.KEY_H, BMKeyBinding.Key.OPEN_SIGIL_HOLDING); - public static final KeyBinding KEY_HOLDING_CYCLE_POS = new KeyBinding(Constants.Mod.MODID + ".keybind.cycleHoldingPos", KeyConflictContext.IN_GAME, KeyModifier.SHIFT, Keyboard.KEY_EQUALS, Constants.Mod.NAME); - public static final KeyBinding KEY_HOLDING_CYCLE_NEG = new KeyBinding(Constants.Mod.MODID + ".keybind.cycleHoldingNeg", KeyConflictContext.IN_GAME, KeyModifier.SHIFT, Keyboard.KEY_MINUS, Constants.Mod.NAME); - - static { - ClientRegistry.registerKeyBinding(KEY_HOLDING_CYCLE_POS); - ClientRegistry.registerKeyBinding(KEY_HOLDING_CYCLE_NEG); - } - @SubscribeEvent public void onTooltipEvent(ItemTooltipEvent event) { @@ -227,25 +210,9 @@ public class ClientHandler if (!minecraft.inGameHasFocus) return; - EntityPlayerSP player = Minecraft.getMinecraft().thePlayer; - - for (BMKeyBinding key : keyBindings) - { - if (key.isPressed()) - key.handleKeyPress(); - } - - if (player != null) - { - ItemStack stack = player.getHeldItemMainhand(); - if (stack != null && stack.getItem() instanceof ItemSigilHolding) - { - if (KEY_HOLDING_CYCLE_POS.isPressed()) - cycleSigil(stack, player, -1); - else if (KEY_HOLDING_CYCLE_NEG.isPressed()) - cycleSigil(stack, player, 1); - } - } + for (KeyBindingBloodMagic.KeyBindings keyBinding : KeyBindingBloodMagic.KeyBindings.values()) + if (keyBinding.getKey().isPressed()) + keyBinding.handleKeybind(); } @SubscribeEvent @@ -329,7 +296,7 @@ public class ClientHandler BloodMagic.instance.getLogger().debug("Suppressed required texture errors in {}", stopwatch.stop()); } - private void cycleSigil(ItemStack stack, EntityPlayer player, int dWheel) + public static void cycleSigil(ItemStack stack, EntityPlayer player, int dWheel) { int mode = dWheel; if (!ConfigHandler.sigilHoldingSkipsEmptySlots) diff --git a/src/main/resources/assets/bloodmagic/lang/en_US.lang b/src/main/resources/assets/bloodmagic/lang/en_US.lang index 1fca51a1..88e4f390 100644 --- a/src/main/resources/assets/bloodmagic/lang/en_US.lang +++ b/src/main/resources/assets/bloodmagic/lang/en_US.lang @@ -664,9 +664,9 @@ commands.soulnetwork.fillMax.success=Successfully filled %s's Soul Network to th commands.soulnetwork.create.success=Successfully created %s's Soul Network (Orb tier: %d) # Keybinds -BloodMagic.keybind.openSigilHolding=Open Sigil of Holding -BloodMagic.keybind.cycleHoldingPos=Cycle Sigil (+) -BloodMagic.keybind.cycleHoldingNeg=Cycle Sigil (-) +BloodMagic.keybind.open_holding=Open Sigil of Holding +BloodMagic.keybind.cycle_holding_pos=Cycle Sigil (+) +BloodMagic.keybind.cycle_holding_neg=Cycle Sigil (-) # JustEnoughItems jei.BloodMagic.recipe.altar=Blood Altar diff --git a/src/main/resources/assets/bloodmagic/lang/ja_JP.lang b/src/main/resources/assets/bloodmagic/lang/ja_JP.lang index 2fc11146..083d5f91 100644 --- a/src/main/resources/assets/bloodmagic/lang/ja_JP.lang +++ b/src/main/resources/assets/bloodmagic/lang/ja_JP.lang @@ -629,7 +629,7 @@ commands.soulnetwork.fillMax.success=正常に%sのソウルネットワーク commands.soulnetwork.create.success=正常に%sのソウルネットワークを構築しました(オーブのグレード: %d) # Keybinds -BloodMagic.keybind.openSigilHolding=貯蔵の印章を開く +BloodMagic.keybind.open_holding=貯蔵の印章を開く # JustEnoughItems jei.BloodMagic.recipe.altar=血の祭壇 diff --git a/src/main/resources/assets/bloodmagic/lang/zh_CN.lang b/src/main/resources/assets/bloodmagic/lang/zh_CN.lang index 58406387..0dd92071 100644 --- a/src/main/resources/assets/bloodmagic/lang/zh_CN.lang +++ b/src/main/resources/assets/bloodmagic/lang/zh_CN.lang @@ -645,7 +645,7 @@ commands.soulnetwork.fillMax.success=成功将 %s 的灵魂网络填满至其宝 commands.soulnetwork.create.success=创建 %s 的灵魂网络成功 (宝珠等级: %d) # Keybinds -BloodMagic.keybind.openSigilHolding=打开集持印记 +BloodMagic.keybind.open_holding=打开集持印记 # JustEnoughItems jei.BloodMagic.recipe.altar=血之祭坛