That's one heck of a commit you've got there...
I may have got a bit behind with version control. A lot behind, in fact. Maybe I'll go back and split this sometime - then again, I probably won't. But hey, at least it's here!
This commit is contained in:
@@ -1,14 +1,11 @@
|
||||
package electroblob.wizardry.client;
|
||||
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import electroblob.wizardry.Wizardry;
|
||||
import electroblob.wizardry.client.gui.GuiSpellDisplay;
|
||||
import electroblob.wizardry.item.ItemWand;
|
||||
import electroblob.wizardry.item.ISpellCastingItem;
|
||||
import electroblob.wizardry.packet.PacketControlInput;
|
||||
import electroblob.wizardry.packet.WizardryPacketHandler;
|
||||
import electroblob.wizardry.registry.WizardrySounds;
|
||||
import electroblob.wizardry.util.WandHelper;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.audio.PositionedSoundRecord;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -16,72 +13,54 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.client.event.MouseEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.InputEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.TickEvent;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
/** Event handler class responsible for handling wizardry's controls. */
|
||||
@SideOnly(Side.CLIENT)
|
||||
//@SideOnly(Side.CLIENT)
|
||||
@Mod.EventBusSubscriber(Side.CLIENT)
|
||||
public class WizardryControlHandler {
|
||||
|
||||
static boolean NkeyPressed = false;
|
||||
static boolean BkeyPressed = false;
|
||||
static boolean NkeyAlreadyPressed = false;
|
||||
static boolean BkeyAlreadyPressed = false;
|
||||
|
||||
// Changed to a tick event to allow mouse button keybinds
|
||||
// The 'lag' that happened previously was actually because the code only fired when a keyboard key was pressed!
|
||||
@SubscribeEvent
|
||||
public static void onKeyInput(InputEvent.KeyInputEvent event){
|
||||
public static void onTickEvent(TickEvent.ClientTickEvent event){
|
||||
|
||||
// Key pressed
|
||||
if(Keyboard.getEventKeyState()){
|
||||
if(event.phase == TickEvent.Phase.END) return; // Only really needs to be once per tick
|
||||
|
||||
if(Wizardry.proxy instanceof ClientProxy){
|
||||
|
||||
EntityPlayer player = Minecraft.getMinecraft().player;
|
||||
ItemStack wand = player.getHeldItemMainhand();
|
||||
if(Wizardry.proxy instanceof ClientProxy){
|
||||
|
||||
if(!(wand.getItem() instanceof ItemWand)){
|
||||
wand = player.getHeldItemOffhand();
|
||||
// If the player isn't holding a wand, then nothing else needs to be done.
|
||||
if(!(wand.getItem() instanceof ItemWand)) return;
|
||||
}
|
||||
EntityPlayer player = Minecraft.getMinecraft().player;
|
||||
|
||||
if(ClientProxy.NEXT_SPELL.isPressed() && Minecraft.getMinecraft().inGameHasFocus){
|
||||
if(player != null){
|
||||
|
||||
ItemStack wand = getWandInUse(player);
|
||||
if(wand == null) return;
|
||||
|
||||
if(ClientProxy.NEXT_SPELL.isKeyDown() && Minecraft.getMinecraft().inGameHasFocus){
|
||||
if(!NkeyPressed){
|
||||
NkeyPressed = true;
|
||||
}else{
|
||||
NkeyAlreadyPressed = true;
|
||||
}
|
||||
if(!NkeyAlreadyPressed){
|
||||
selectNextSpell(wand);
|
||||
}
|
||||
}else{
|
||||
NkeyPressed = false;
|
||||
}
|
||||
|
||||
if(ClientProxy.PREVIOUS_SPELL.isPressed() && Minecraft.getMinecraft().inGameHasFocus){
|
||||
if(ClientProxy.PREVIOUS_SPELL.isKeyDown() && Minecraft.getMinecraft().inGameHasFocus){
|
||||
if(!BkeyPressed){
|
||||
BkeyPressed = true;
|
||||
}else{
|
||||
BkeyAlreadyPressed = true;
|
||||
}
|
||||
if(!BkeyAlreadyPressed){
|
||||
// Packet building
|
||||
selectPreviousSpell(wand);
|
||||
}
|
||||
}else{
|
||||
BkeyPressed = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Key released
|
||||
else{
|
||||
if(NkeyPressed){
|
||||
NkeyPressed = false;
|
||||
NkeyAlreadyPressed = false;
|
||||
}else if(BkeyPressed){
|
||||
BkeyPressed = false;
|
||||
BkeyAlreadyPressed = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Shift-scrolling to change spells
|
||||
@@ -89,16 +68,11 @@ public class WizardryControlHandler {
|
||||
public static void onMouseEvent(MouseEvent event){
|
||||
|
||||
EntityPlayer player = Minecraft.getMinecraft().player;
|
||||
ItemStack wand = player.getHeldItemMainhand();
|
||||
|
||||
if(!(wand.getItem() instanceof ItemWand)){
|
||||
wand = player.getHeldItemOffhand();
|
||||
// If the player isn't holding a wand, then nothing else needs to be done.
|
||||
if(!(wand.getItem() instanceof ItemWand)) return;
|
||||
}
|
||||
ItemStack wand = getWandInUse(player);
|
||||
if(wand == null) return;
|
||||
|
||||
if(Minecraft.getMinecraft().inGameHasFocus && !wand.isEmpty() && event.getDwheel() != 0 && player.isSneaking()
|
||||
&& Wizardry.settings.enableShiftScrolling){
|
||||
&& Wizardry.settings.shiftScrolling){
|
||||
|
||||
event.setCanceled(true);
|
||||
|
||||
@@ -111,15 +85,28 @@ public class WizardryControlHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static ItemStack getWandInUse(EntityPlayer player){
|
||||
|
||||
ItemStack wand = player.getHeldItemMainhand();
|
||||
|
||||
// Only bother sending packets if the player is holding a spellcasting item with more than one spell slot
|
||||
if(!(wand.getItem() instanceof ISpellCastingItem) || ((ISpellCastingItem)wand.getItem()).getSpells(wand).length < 2){
|
||||
wand = player.getHeldItemOffhand();
|
||||
if(!(wand.getItem() instanceof ISpellCastingItem) || ((ISpellCastingItem)wand.getItem()).getSpells(wand).length < 2) return null;
|
||||
}
|
||||
|
||||
return wand;
|
||||
}
|
||||
|
||||
private static void selectNextSpell(ItemStack wand){
|
||||
// Packet building
|
||||
IMessage msg = new PacketControlInput.Message(PacketControlInput.ControlType.NEXT_SPELL_KEY);
|
||||
WizardryPacketHandler.net.sendToServer(msg);
|
||||
// GUI switch animation
|
||||
WandHelper.selectNextSpell(wand); // Makes sure the spell is set immediately for the client
|
||||
((ISpellCastingItem)wand.getItem()).selectNextSpell(wand); // Makes sure the spell is set immediately for the client
|
||||
GuiSpellDisplay.playSpellSwitchAnimation(true);
|
||||
Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.getMasterRecord(WizardrySounds.SELECT_SPELL, 1));
|
||||
Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.getMasterRecord(WizardrySounds.ITEM_WAND_SWITCH_SPELL, 1));
|
||||
}
|
||||
|
||||
private static void selectPreviousSpell(ItemStack wand){
|
||||
@@ -127,8 +114,8 @@ public class WizardryControlHandler {
|
||||
IMessage msg = new PacketControlInput.Message(PacketControlInput.ControlType.PREVIOUS_SPELL_KEY);
|
||||
WizardryPacketHandler.net.sendToServer(msg);
|
||||
// GUI switch animation
|
||||
WandHelper.selectPreviousSpell(wand); // Makes sure the spell is set immediately for the client
|
||||
((ISpellCastingItem)wand.getItem()).selectPreviousSpell(wand); // Makes sure the spell is set immediately for the client
|
||||
GuiSpellDisplay.playSpellSwitchAnimation(false);
|
||||
Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.getMasterRecord(WizardrySounds.SELECT_SPELL, 1));
|
||||
Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.getMasterRecord(WizardrySounds.ITEM_WAND_SWITCH_SPELL, 1));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user