diff --git a/src/main/java/mchorse/metamorph/api/MorphAPI.java b/src/main/java/mchorse/metamorph/api/MorphAPI.java index e28456a4..a58fc3b9 100644 --- a/src/main/java/mchorse/metamorph/api/MorphAPI.java +++ b/src/main/java/mchorse/metamorph/api/MorphAPI.java @@ -102,8 +102,8 @@ public static boolean selectMorph(AbstractMorph morph) if (morph != null) { EntityPlayer player = Minecraft.getMinecraft().player; - IMorphing cap = Morphing.get(player); - List acquiredMorphs = cap.getAcquiredMorphs(); + IMorphing morphing = Morphing.get(player); + List acquiredMorphs = morphing.getAcquiredMorphs(); for (int i = 0; i < acquiredMorphs.size(); i++) { AbstractMorph acquiredMorph = acquiredMorphs.get(i); @@ -117,6 +117,8 @@ public static boolean selectMorph(AbstractMorph morph) { return false; } + + morphing.setLastSelectedMorph(morph); } Dispatcher.sendToServer(new PacketSelectMorph(index)); diff --git a/src/main/java/mchorse/metamorph/capabilities/CapabilityHandler.java b/src/main/java/mchorse/metamorph/capabilities/CapabilityHandler.java index f90d610b..a7e3ba6d 100644 --- a/src/main/java/mchorse/metamorph/capabilities/CapabilityHandler.java +++ b/src/main/java/mchorse/metamorph/capabilities/CapabilityHandler.java @@ -144,6 +144,6 @@ private void sendAcquiredMorphs(IMorphing cap, EntityPlayer player) EntityPlayerMP mp = (EntityPlayerMP) player; Dispatcher.sendTo(new PacketMorph(cap.getCurrentMorph()), mp); - Dispatcher.sendTo(new PacketAcquiredMorphs(cap.getAcquiredMorphs()), mp); + Dispatcher.sendTo(new PacketAcquiredMorphs(cap.getAcquiredMorphs(), cap.getLastSelectedMorph()), mp); } } \ No newline at end of file diff --git a/src/main/java/mchorse/metamorph/capabilities/morphing/IMorphing.java b/src/main/java/mchorse/metamorph/capabilities/morphing/IMorphing.java index a33d82f7..576b5259 100644 --- a/src/main/java/mchorse/metamorph/capabilities/morphing/IMorphing.java +++ b/src/main/java/mchorse/metamorph/capabilities/morphing/IMorphing.java @@ -83,6 +83,16 @@ public interface IMorphing */ public boolean setCurrentMorph(AbstractMorph morph, EntityPlayer player, boolean force); + /** + * Get morph of last survival morph attempt + */ + public AbstractMorph getLastSelectedMorph(); + + /** + * Set morph of last survival morph attempt + */ + public void setLastSelectedMorph(AbstractMorph morph); + /** * Demorph this capability */ diff --git a/src/main/java/mchorse/metamorph/capabilities/morphing/Morphing.java b/src/main/java/mchorse/metamorph/capabilities/morphing/Morphing.java index f682b52d..119cd7ea 100644 --- a/src/main/java/mchorse/metamorph/capabilities/morphing/Morphing.java +++ b/src/main/java/mchorse/metamorph/capabilities/morphing/Morphing.java @@ -41,6 +41,11 @@ public class Morphing implements IMorphing */ private AbstractMorph previousMorph; + /** + * Used for recent morph hotkey + */ + private AbstractMorph lastSelectedMorph; + /** * Animation timer */ @@ -287,6 +292,22 @@ public boolean setCurrentMorph(AbstractMorph morph, EntityPlayer player, boolean return false; } + /** + * Get morph of last survival morph attempt + */ + public AbstractMorph getLastSelectedMorph() + { + return lastSelectedMorph; + } + + /** + * Set morph of last survival morph attempt + */ + public void setLastSelectedMorph(AbstractMorph morph) + { + this.lastSelectedMorph = morph; + } + @Override public void demorph(EntityPlayer player) { diff --git a/src/main/java/mchorse/metamorph/capabilities/morphing/MorphingStorage.java b/src/main/java/mchorse/metamorph/capabilities/morphing/MorphingStorage.java index 09c64bb2..ddfb1a54 100644 --- a/src/main/java/mchorse/metamorph/capabilities/morphing/MorphingStorage.java +++ b/src/main/java/mchorse/metamorph/capabilities/morphing/MorphingStorage.java @@ -45,6 +45,14 @@ public NBTBase writeNBT(Capability capability, IMorphing instance, En tag.setTag("Morph", morph); } + if (instance.getLastSelectedMorph() != null) + { + NBTTagCompound selectedMorph = new NBTTagCompound(); + instance.getLastSelectedMorph().toNBT(selectedMorph); + + tag.setTag("RecentMorph", selectedMorph); + } + tag.setTag("Morphs", acquired); for (AbstractMorph acquiredMorph : instance.getAcquiredMorphs()) @@ -66,6 +74,7 @@ public void readNBT(Capability capability, IMorphing instance, EnumFa NBTTagCompound tag = (NBTTagCompound) nbt; NBTTagList acquired = tag.getTagList("Morphs", 10); NBTTagCompound morphTag = tag.getCompoundTag("Morph"); + NBTTagCompound selectedMorphTag = tag.getCompoundTag("RecentMorph"); instance.setLastHealthRatio(tag.getFloat("LastHealthRatio")); instance.setHasSquidAir(tag.getBoolean("HasSquidAir")); @@ -75,6 +84,7 @@ public void readNBT(Capability capability, IMorphing instance, EnumFa if (!tag.hasNoTags()) { instance.setCurrentMorph(MorphManager.INSTANCE.morphFromNBT(morphTag), null, true); + instance.setLastSelectedMorph(MorphManager.INSTANCE.morphFromNBT(selectedMorphTag)); } List acquiredMorphs = new ArrayList(); diff --git a/src/main/java/mchorse/metamorph/client/KeyboardHandler.java b/src/main/java/mchorse/metamorph/client/KeyboardHandler.java index 05a05988..b6a5fd67 100644 --- a/src/main/java/mchorse/metamorph/client/KeyboardHandler.java +++ b/src/main/java/mchorse/metamorph/client/KeyboardHandler.java @@ -37,6 +37,7 @@ public class KeyboardHandler public KeyBinding keySurvivalMenu; /* Morph related keys */ + public KeyBinding keyMorphRecent; public KeyBinding keyDemorph; public KeyboardHandler() @@ -49,6 +50,7 @@ public KeyboardHandler() keySelectorMenu = new KeyBinding("key.metamorph.selector_menu", Keyboard.KEY_MINUS, category); keySurvivalMenu = new KeyBinding("key.metamorph.survival_menu", Keyboard.KEY_X, category); + keyMorphRecent = new KeyBinding("key.metamorph.morph_recent", Keyboard.KEY_RETURN, category); keyDemorph = new KeyBinding("key.metamorph.demorph", Keyboard.KEY_PERIOD, category); /* Register them in the client registry */ @@ -57,6 +59,7 @@ public KeyboardHandler() ClientRegistry.registerKeyBinding(keySelectorMenu); ClientRegistry.registerKeyBinding(keySurvivalMenu); + ClientRegistry.registerKeyBinding(keyMorphRecent); ClientRegistry.registerKeyBinding(keyDemorph); } @@ -100,6 +103,16 @@ public void onKey(InputEvent.KeyInputEvent event) mc.displayGuiScreen(ClientProxy.getSurvivalScreen().open()); wasUsed = true; } + + /* Morph into the most recent attempted morph */ + if (this.keyMorphRecent.isPressed() && !spectator) + { + if (morphing != null && morphing.getLastSelectedMorph() != null) + { + MorphAPI.selectMorph(morphing.getLastSelectedMorph()); + wasUsed = true; + } + } /* Demorph from current morph */ if (this.keyDemorph.isPressed() && !spectator) diff --git a/src/main/java/mchorse/metamorph/network/client/survival/ClientHandlerAcquiredMorphs.java b/src/main/java/mchorse/metamorph/network/client/survival/ClientHandlerAcquiredMorphs.java index 31abe647..05919829 100644 --- a/src/main/java/mchorse/metamorph/network/client/survival/ClientHandlerAcquiredMorphs.java +++ b/src/main/java/mchorse/metamorph/network/client/survival/ClientHandlerAcquiredMorphs.java @@ -17,5 +17,6 @@ public void run(EntityPlayerSP player, PacketAcquiredMorphs message) IMorphing morphing = Morphing.get(player); morphing.setAcquiredMorphs(message.morphs); + morphing.setLastSelectedMorph(message.lastSelectedMorph); } } \ No newline at end of file diff --git a/src/main/java/mchorse/metamorph/network/common/survival/PacketAcquiredMorphs.java b/src/main/java/mchorse/metamorph/network/common/survival/PacketAcquiredMorphs.java index d7869405..21e798fb 100644 --- a/src/main/java/mchorse/metamorph/network/common/survival/PacketAcquiredMorphs.java +++ b/src/main/java/mchorse/metamorph/network/common/survival/PacketAcquiredMorphs.java @@ -14,15 +14,17 @@ public class PacketAcquiredMorphs implements IMessage { public List morphs; + public AbstractMorph lastSelectedMorph; public PacketAcquiredMorphs() { this.morphs = new ArrayList(); } - public PacketAcquiredMorphs(List morphs) + public PacketAcquiredMorphs(List morphs, AbstractMorph lastSelectedMorph) { this.morphs = morphs; + this.lastSelectedMorph = lastSelectedMorph; } @Override @@ -37,6 +39,8 @@ public void fromBytes(ByteBuf buf) this.morphs.add(morph); } } + + this.lastSelectedMorph = MorphUtils.morphFromBuf(buf); } @Override @@ -48,5 +52,7 @@ public void toBytes(ByteBuf buf) { MorphUtils.morphToBuf(buf, morph); } + + MorphUtils.morphToBuf(buf, lastSelectedMorph); } } diff --git a/src/main/java/mchorse/metamorph/network/server/survival/ServerHandlerSelectMorph.java b/src/main/java/mchorse/metamorph/network/server/survival/ServerHandlerSelectMorph.java index ba84779b..cc121032 100644 --- a/src/main/java/mchorse/metamorph/network/server/survival/ServerHandlerSelectMorph.java +++ b/src/main/java/mchorse/metamorph/network/server/survival/ServerHandlerSelectMorph.java @@ -33,6 +33,10 @@ public void run(EntityPlayerMP player, PacketSelectMorph message) morph = morphs.get(index); } + if (morph != null) + { + capability.setLastSelectedMorph(morph); + } MorphAPI.morph(player, MorphUtils.copy(morph), false); } } \ No newline at end of file diff --git a/src/main/resources/assets/metamorph/lang/en_US.lang b/src/main/resources/assets/metamorph/lang/en_US.lang index 8180dd4b..dbd6450f 100644 --- a/src/main/resources/assets/metamorph/lang/en_US.lang +++ b/src/main/resources/assets/metamorph/lang/en_US.lang @@ -9,6 +9,7 @@ key.metamorph.action=Use action key.metamorph.creative_menu=Open creative morph menu key.metamorph.selector_menu=Open entity selectors menu key.metamorph.survival_menu=Open survival morph menu +key.metamorph.morph_recent=Morph most recent key.metamorph.demorph=Demorph (turn back to player) # GUI