diff --git a/src/main/java/electroblob/wizardry/CommonProxy.java b/src/main/java/electroblob/wizardry/CommonProxy.java
index ef778f9e..a3d959b0 100644
--- a/src/main/java/electroblob/wizardry/CommonProxy.java
+++ b/src/main/java/electroblob/wizardry/CommonProxy.java
@@ -284,13 +284,21 @@ public class CommonProxy {
public void loadShader(EntityPlayer player, ResourceLocation shader){}
/**
- * Gets the client side world using Minecraft.getMinecraft().world. Only to be called client side! Returns
- * null on the server side.
+ * Gets the client-side world using {@code Minecraft.getMinecraft().world}. Only to be called client side!
+ * Returns null on the server side.
*/
public World getTheWorld(){
return null;
}
+ /**
+ * Gets the client-side player using Minecraft.getMinecraft().player. Only to be called client side! Returns
+ * null on the server side.
+ */
+ public EntityPlayer getThePlayer(){
+ return null;
+ }
+
/**
* Returns true if the game is being viewed from the perspective of the given entity and is set to first-person
* view. Always returns false on the server side.
diff --git a/src/main/java/electroblob/wizardry/client/ClientProxy.java b/src/main/java/electroblob/wizardry/client/ClientProxy.java
index 62c9f26b..3aa9a980 100644
--- a/src/main/java/electroblob/wizardry/client/ClientProxy.java
+++ b/src/main/java/electroblob/wizardry/client/ClientProxy.java
@@ -190,6 +190,11 @@ public class ClientProxy extends CommonProxy {
return Minecraft.getMinecraft().world;
}
+ @Override
+ public EntityPlayer getThePlayer(){
+ return Minecraft.getMinecraft().player;
+ }
+
@Override
public boolean isFirstPerson(Entity entity){
return entity == Minecraft.getMinecraft().getRenderViewEntity() && Minecraft.getMinecraft().gameSettings.thirdPersonView == 0;
@@ -261,6 +266,9 @@ public class ClientProxy extends CommonProxy {
if(player == null) return false;
// Displayed recipe
+ // Weirdly, the gui is actually the only way of accessing the current IMerchant or their recipes, other than a
+ // brute-force search through all the entities in the world to find the merchant interacting with the player
+ // Since we only need this client-side anyway, we might as well go via the gui
if(Minecraft.getMinecraft().currentScreen instanceof GuiMerchant){
// It doesn't actually matter if the recipe is selected or not, since the itemstack will only ever
// match one of them anyway - and we'd have to reflect into GuiMerchant to get the selected recipe
diff --git a/src/main/java/electroblob/wizardry/client/WizardryClientEventHandler.java b/src/main/java/electroblob/wizardry/client/WizardryClientEventHandler.java
index c85a8c22..5167635b 100644
--- a/src/main/java/electroblob/wizardry/client/WizardryClientEventHandler.java
+++ b/src/main/java/electroblob/wizardry/client/WizardryClientEventHandler.java
@@ -3,38 +3,46 @@ package electroblob.wizardry.client;
import electroblob.wizardry.client.renderer.overlay.RenderBlinkEffect;
import electroblob.wizardry.data.DispenserCastingData;
import electroblob.wizardry.data.SpellEmitterData;
+import electroblob.wizardry.data.WizardData;
import electroblob.wizardry.item.ItemArtefact;
import electroblob.wizardry.item.ItemSpectralBow;
+import electroblob.wizardry.item.ItemSpellBook;
import electroblob.wizardry.item.ItemWand;
import electroblob.wizardry.potion.PotionSlowTime;
import electroblob.wizardry.registry.WizardryItems;
import electroblob.wizardry.registry.WizardryPotions;
-import electroblob.wizardry.spell.Possession;
-import electroblob.wizardry.spell.SixthSense;
-import electroblob.wizardry.spell.SlowTime;
-import electroblob.wizardry.spell.Transience;
+import electroblob.wizardry.spell.*;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiMerchant;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.GlStateManager;
+import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.entity.EntityLiving;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.inventory.ContainerMerchant;
import net.minecraft.inventory.Slot;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityDispenser;
import net.minecraft.util.ResourceLocation;
import net.minecraft.village.MerchantRecipe;
+import net.minecraft.village.MerchantRecipeList;
import net.minecraft.world.World;
import net.minecraftforge.client.event.*;
+import net.minecraftforge.client.event.GuiScreenEvent.ActionPerformedEvent;
+import net.minecraftforge.fml.client.config.GuiUtils;
import net.minecraftforge.fml.common.Mod;
+import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import net.minecraftforge.fml.relauncher.Side;
import org.lwjgl.opengl.GL11;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
/**
@@ -180,32 +188,6 @@ public final class WizardryClientEventHandler {
}
}
- // Brute-force fix for crystals not showing up when a wizard is given a spell book in the trade GUI.
- @SubscribeEvent
- public static void onGuiDrawForegroundEvent(GuiContainerEvent.DrawForeground event){
-
- if(event.getGuiContainer() instanceof GuiMerchant){
-
- GuiMerchant gui = (GuiMerchant)event.getGuiContainer();
- // Note that gui.getMerchant() returns an NpcMerchant, not an EntityWizard.
-
- // Using == the specific item rather than instanceof because that's how trades do it.
- if(gui.inventorySlots.getSlot(0).getStack().getItem() == WizardryItems.spell_book
- || gui.inventorySlots.getSlot(1).getStack().getItem() == WizardryItems.spell_book){
-
- for(MerchantRecipe trade : gui.getMerchant().getRecipes(Minecraft.getMinecraft().player)){
- if(trade.getItemToBuy().getItem() == WizardryItems.spell_book && trade.getSecondItemToBuy().isEmpty()){
- Slot slot = gui.inventorySlots.getSlot(2);
- // It still doesn't look quite right because the slot highlight is behind the item, but it'll do
- // until/unless I find a better solution.
- DrawingUtils.drawItemAndTooltip(gui, trade.getItemToSell(), slot.xPos, slot.yPos, event.getMouseX(), event.getMouseY(),
- gui.getSlotUnderMouse() == slot);
- }
- }
- }
- }
- }
-
/**
* Renders an overlay across the entire screen.
* @param resolution The screen resolution
diff --git a/src/main/java/electroblob/wizardry/client/gui/WizardTradeTweaksHandler.java b/src/main/java/electroblob/wizardry/client/gui/WizardTradeTweaksHandler.java
new file mode 100644
index 00000000..dbf2fec3
--- /dev/null
+++ b/src/main/java/electroblob/wizardry/client/gui/WizardTradeTweaksHandler.java
@@ -0,0 +1,118 @@
+package electroblob.wizardry.client.gui;
+
+import electroblob.wizardry.Wizardry;
+import electroblob.wizardry.client.DrawingUtils;
+import electroblob.wizardry.data.WizardData;
+import electroblob.wizardry.item.ItemSpellBook;
+import electroblob.wizardry.registry.WizardryItems;
+import electroblob.wizardry.spell.Spell;
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.gui.GuiMerchant;
+import net.minecraft.client.renderer.GlStateManager;
+import net.minecraft.client.renderer.RenderHelper;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.inventory.ContainerMerchant;
+import net.minecraft.inventory.Slot;
+import net.minecraft.util.ResourceLocation;
+import net.minecraft.village.MerchantRecipe;
+import net.minecraft.village.MerchantRecipeList;
+import net.minecraftforge.client.event.GuiContainerEvent;
+import net.minecraftforge.client.event.GuiOpenEvent;
+import net.minecraftforge.client.event.GuiScreenEvent.ActionPerformedEvent;
+import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
+import net.minecraftforge.fml.common.eventhandler.EventPriority;
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
+
+@EventBusSubscriber
+public class WizardTradeTweaksHandler {
+
+ private static final ResourceLocation NEW_SPELL_ICON = new ResourceLocation(Wizardry.MODID, "textures/gui/container/new_spell_indicator.png");
+
+ private static int tradeIndex; // Mirrors GuiMerchant#selectedMerchantRecipe (don't want to reflect into it every frame)
+
+ @SubscribeEvent(priority = EventPriority.LOWEST)
+ public static void onGuiOpenEvent(GuiOpenEvent event){
+ if(event.getGui() instanceof GuiMerchant) tradeIndex = 0;
+ }
+
+ @SubscribeEvent
+ public static void onActionPerformedPostEvent(ActionPerformedEvent.Post event){
+
+ if(event.getGui() instanceof GuiMerchant){
+
+ MerchantRecipeList recipes = ((GuiMerchant)event.getGui()).getMerchant().getRecipes(Minecraft.getMinecraft().player);
+
+ if(recipes == null) return;
+
+ if(event.getButton().id == 1){ // Next
+ tradeIndex = Math.min(tradeIndex + 1, recipes.size());
+ }else if(event.getButton().id == 2){ // Previous
+ tradeIndex = Math.max(tradeIndex - 1, 0);
+ }
+ }
+ }
+
+ // Brute-force fix for crystals not showing up when a wizard is given a spell book in the trade GUI.
+ @SubscribeEvent
+ public static void onGuiDrawForegroundEvent(GuiContainerEvent.DrawForeground event){
+
+ if(event.getGuiContainer() instanceof GuiMerchant){
+
+ GuiMerchant gui = (GuiMerchant)event.getGuiContainer();
+ // Note that gui.getMerchant() returns an NpcMerchant, not an EntityWizard.
+ MerchantRecipeList trades = gui.getMerchant().getRecipes(Minecraft.getMinecraft().player);
+
+ if(trades == null) return;
+
+ // Using == the specific item rather than instanceof because that's how trades do it.
+ if(gui.inventorySlots.getSlot(0).getStack().getItem() == WizardryItems.spell_book
+ || gui.inventorySlots.getSlot(1).getStack().getItem() == WizardryItems.spell_book){
+
+ for(MerchantRecipe trade : trades){
+ if(trade.getItemToBuy().getItem() == WizardryItems.spell_book && trade.getSecondItemToBuy().isEmpty()){
+ Slot slot = gui.inventorySlots.getSlot(2);
+ // It still doesn't look quite right because the slot highlight is behind the item, but it'll do
+ // until/unless I find a better solution.
+ DrawingUtils.drawItemAndTooltip(gui, trade.getItemToSell(), slot.xPos, slot.yPos, event.getMouseX(), event.getMouseY(),
+ gui.getSlotUnderMouse() == slot);
+ }
+ }
+ }
+
+ // New spell indicator
+ if(gui.inventorySlots instanceof ContainerMerchant){
+
+ // Can't use getCurrentRecipe because that only gets updated when the correct items are given
+ MerchantRecipe recipe = trades.get(tradeIndex);
+
+ if(recipe != null && recipe.getItemToSell().getItem() instanceof ItemSpellBook){
+
+ EntityPlayer player = Minecraft.getMinecraft().player;
+
+ if(!WizardData.get(player).hasSpellBeenDiscovered(Spell.byMetadata(recipe.getItemToSell().getMetadata()))){
+
+ int x = gui.inventorySlots.getSlot(2).xPos + 14;
+ int y = gui.inventorySlots.getSlot(2).yPos - 17;
+ int w = 8;
+ int h = 8;
+
+ RenderHelper.enableGUIStandardItemLighting();
+ GlStateManager.color(1, 1, 1);
+ Minecraft.getMinecraft().renderEngine.bindTexture(NEW_SPELL_ICON);
+ DrawingUtils.drawTexturedRect(x, y, 0, Math.max(player.ticksExisted/2 % 40 - 36, 0) * 8, w, h, 8, 32);
+ RenderHelper.disableStandardItemLighting();
+
+// int mouseX = event.getMouseX() - gui.getGuiLeft();
+// int mouseY = event.getMouseY() - gui.getGuiTop();
+//
+// if(mouseX >= x + 1 && mouseX < x + w + 1 && mouseY >= y - 1 && mouseY < y + h + 1){
+// GuiUtils.drawHoveringText(Collections.singletonList("You haven't discovered this spell yet"), mouseX,
+// mouseY, gui.width, gui.height, 150, Minecraft.getMinecraft().fontRenderer);
+// }
+ }
+ }
+ }
+ }
+ }
+
+}
diff --git a/src/main/java/electroblob/wizardry/item/ItemSpellBook.java b/src/main/java/electroblob/wizardry/item/ItemSpellBook.java
index 7cb48615..2a2435ab 100644
--- a/src/main/java/electroblob/wizardry/item/ItemSpellBook.java
+++ b/src/main/java/electroblob/wizardry/item/ItemSpellBook.java
@@ -5,6 +5,7 @@ import electroblob.wizardry.Wizardry;
import electroblob.wizardry.WizardryGuiHandler;
import electroblob.wizardry.constants.Tier;
import electroblob.wizardry.data.SpellGlyphData;
+import electroblob.wizardry.data.WizardData;
import electroblob.wizardry.registry.WizardryTabs;
import electroblob.wizardry.spell.Spell;
import net.minecraft.creativetab.CreativeTabs;
@@ -12,6 +13,8 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.*;
+import net.minecraft.util.text.Style;
+import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@@ -80,6 +83,14 @@ public class ItemSpellBook extends Item {
tooltip.add(spell.getTier().getDisplayNameWithFormatting());
+ EntityPlayer player = Wizardry.proxy.getThePlayer();
+
+ // If the spell should *appear* discovered but isn't *actually* discovered, show a 'new spell' message
+ // A bit annoying to check this again but it's the easiest way
+ if(discovered && WizardData.get(player) != null && !WizardData.get(player).hasSpellBeenDiscovered(spell)){
+ tooltip.add(Wizardry.proxy.translate("item." + this.getRegistryName() + ".new", new Style().setColor(TextFormatting.LIGHT_PURPLE)));
+ }
+
// Advanced tooltips display more information, mainly for searching purposes in creative
if(discovered && advanced.isAdvanced()){ // No cheating!
tooltip.add(spell.getElement().getDisplayName());
diff --git a/src/main/java/electroblob/wizardry/misc/WildcardTradeList.java b/src/main/java/electroblob/wizardry/misc/WildcardTradeList.java
index 991a99fd..46d24d07 100644
--- a/src/main/java/electroblob/wizardry/misc/WildcardTradeList.java
+++ b/src/main/java/electroblob/wizardry/misc/WildcardTradeList.java
@@ -16,6 +16,8 @@ import net.minecraftforge.oredict.OreDictionary;
@SuppressWarnings("serial")
public class WildcardTradeList extends MerchantRecipeList {
+ private int currentIndex;
+
public WildcardTradeList(){
super();
}
@@ -24,19 +26,26 @@ public class WildcardTradeList extends MerchantRecipeList {
super(tag);
}
+ /** Returns the current recipe */
+ public MerchantRecipe getCurrentRecipe(){
+ return get(currentIndex); // Allows events to access the selected recipe without reflection
+ }
+
@Override
public MerchantRecipe canRecipeBeUsed(ItemStack offer1, ItemStack offer2, int index){
+
+ currentIndex = index; // Update the index
if(index > 0 && index < this.size()){
- MerchantRecipe merchantrecipe1 = (MerchantRecipe)this.get(index);
+ MerchantRecipe merchantrecipe1 = this.get(index);
return !this.areItemStacksExactlyEqual(offer1, merchantrecipe1.getItemToBuy()) || (!offer2.isEmpty() || merchantrecipe1.hasSecondItemToBuy()) && (!merchantrecipe1.hasSecondItemToBuy() || !this.areItemStacksExactlyEqual(offer2, merchantrecipe1.getSecondItemToBuy())) || offer1.getCount() < merchantrecipe1.getItemToBuy().getCount() || merchantrecipe1.hasSecondItemToBuy() && offer2.getCount() < merchantrecipe1.getSecondItemToBuy().getCount() ? null : merchantrecipe1;
}else{
for(int i = 0; i < this.size(); ++i){
- MerchantRecipe merchantrecipe = (MerchantRecipe)this.get(i);
+ MerchantRecipe merchantrecipe = this.get(i);
if (this.areItemStacksExactlyEqual(offer1, merchantrecipe.getItemToBuy()) && offer1.getCount() >= merchantrecipe.getItemToBuy().getCount() && (!merchantrecipe.hasSecondItemToBuy() && offer2.isEmpty() || merchantrecipe.hasSecondItemToBuy() && this.areItemStacksExactlyEqual(offer2, merchantrecipe.getSecondItemToBuy()) && offer2.getCount() >= merchantrecipe.getSecondItemToBuy().getCount())){
return merchantrecipe;
diff --git a/src/main/resources/assets/ebwizardry/lang/en_gb.lang b/src/main/resources/assets/ebwizardry/lang/en_gb.lang
index ddb92cc7..85558c2a 100644
--- a/src/main/resources/assets/ebwizardry/lang/en_gb.lang
+++ b/src/main/resources/assets/ebwizardry/lang/en_gb.lang
@@ -69,7 +69,7 @@ item.ebwizardry\:crystal_healing.desc=A crystal that glints a golden yellow in t
item.ebwizardry\:spell_book.name=Spell Book
item.ebwizardry\:spell_book.desc=A book filled with the runes and glyphs of an ancient script. Perhaps with dedication, one might be able to decipher its contents...\n\nRight-click while holding this book to read it.
-
+item.ebwizardry\:spell_book.new=Not yet discovered!
item.ebwizardry\:spell_book.apply_to_wizard=Replaced %1$s's spell %2$s with %3$s
item.ebwizardry\:arcane_tome.name=Tome of Arcana
diff --git a/src/main/resources/assets/ebwizardry/lang/en_us.lang b/src/main/resources/assets/ebwizardry/lang/en_us.lang
index 6b582389..080042b8 100644
--- a/src/main/resources/assets/ebwizardry/lang/en_us.lang
+++ b/src/main/resources/assets/ebwizardry/lang/en_us.lang
@@ -69,7 +69,7 @@ item.ebwizardry\:crystal_healing.desc=A crystal that glints a golden yellow in t
item.ebwizardry\:spell_book.name=Spell Book
item.ebwizardry\:spell_book.desc=A book filled with the runes and glyphs of an ancient script. Perhaps with dedication, one might be able to decipher its contents...\n\nRight-click while holding this book to read it.
-
+item.ebwizardry\:spell_book.new=Not yet discovered!
item.ebwizardry\:spell_book.apply_to_wizard=Replaced %1$s's spell %2$s with %3$s
item.ebwizardry\:arcane_tome.name=Tome of Arcana
diff --git a/src/main/resources/assets/ebwizardry/textures/gui/container/new_spell_indicator.png b/src/main/resources/assets/ebwizardry/textures/gui/container/new_spell_indicator.png
new file mode 100644
index 00000000..62381a81
Binary files /dev/null and b/src/main/resources/assets/ebwizardry/textures/gui/container/new_spell_indicator.png differ