Rewrite keybinding system

@Arcaratus, I don't even know what you were thinking with that...

I'm still not happy with IKeybindable, but the system is at least better than it was
This commit is contained in:
Nicholas Ignoffo 2016-08-26 15:56:32 -07:00
parent 4c514224d5
commit 5240755a05
10 changed files with 149 additions and 102 deletions

View file

@ -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
}
}

View file

@ -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);
}

View file

@ -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<BMKeyBinding> keyBindings = new ArrayList<BMKeyBinding>();
public static final List<HUDElement> hudElements = new ArrayList<HUDElement>();
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)