diff --git a/build.gradle b/build.gradle index 7bdc078e..08871f0b 100644 --- a/build.gradle +++ b/build.gradle @@ -13,7 +13,7 @@ buildscript { apply plugin: 'net.minecraftforge.gradle.forge' -version = "1.11-1.4.2" +version = "1.11-1.4.3" group= "com.azanor.baubles" archivesBaseName = "Baubles" diff --git a/src/main/java/baubles/api/BaublesApi.java b/src/main/java/baubles/api/BaublesApi.java index 5e14513d..6f6329ca 100644 --- a/src/main/java/baubles/api/BaublesApi.java +++ b/src/main/java/baubles/api/BaublesApi.java @@ -11,20 +11,26 @@ */ public class BaublesApi { + /** * Retrieves the baubles inventory capability handler for the supplied player */ public static IBaublesItemHandler getBaublesHandler(EntityPlayer player) { - return player.getCapability(BaublesCapabilities.CAPABILITY_BAUBLES, null); - } - + IBaublesItemHandler handler = player.getCapability(BaublesCapabilities.CAPABILITY_BAUBLES, null); + handler.setPlayer(player); + return handler; + } + /** * Retrieves the baubles capability handler wrapped as a IInventory for the supplied player */ @Deprecated public static IInventory getBaubles(EntityPlayer player) { - return new BaublesInventoryWrapper(player.getCapability(BaublesCapabilities.CAPABILITY_BAUBLES, null), player); + IBaublesItemHandler handler = player.getCapability(BaublesCapabilities.CAPABILITY_BAUBLES, null); + handler.setPlayer(player); + return new BaublesInventoryWrapper(handler, player); } + } diff --git a/src/main/java/baubles/api/cap/BaublesContainer.java b/src/main/java/baubles/api/cap/BaublesContainer.java index debe1f39..948e210e 100644 --- a/src/main/java/baubles/api/cap/BaublesContainer.java +++ b/src/main/java/baubles/api/cap/BaublesContainer.java @@ -9,7 +9,8 @@ public class BaublesContainer extends ItemStackHandler implements IBaublesItemHa private final static int BAUBLE_SLOTS = 7; private boolean[] changed = new boolean[BAUBLE_SLOTS]; - private boolean blockEvents=false; + private boolean blockEvents=false; + private EntityLivingBase player; public BaublesContainer() { @@ -37,11 +38,23 @@ public void setSize(int size) public boolean isItemValidForSlot(int slot, ItemStack stack, EntityLivingBase player) { if (stack==null || stack.isEmpty() || !(stack.getItem() instanceof IBauble) || !((IBauble) stack.getItem()).canEquip(stack, player)) - return false; - + return false; return ((IBauble) stack.getItem()).getBaubleType(stack).hasSlot(slot); } + @Override + public void setStackInSlot(int slot, ItemStack stack) { + if (stack==null || stack.isEmpty() || this.isItemValidForSlot(slot, stack, player)) { + super.setStackInSlot(slot, stack); + } + } + + @Override + public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) { + if (!this.isItemValidForSlot(slot, stack, player)) return stack; + return super.insertItem(slot, stack, simulate); + } + @Override public boolean isEventBlocked() { return blockEvents; @@ -73,5 +86,10 @@ public void setChanged(int slot, boolean change) { } this.changed[slot] = change; } + + @Override + public void setPlayer(EntityLivingBase player) { + this.player=player; + } } diff --git a/src/main/java/baubles/api/cap/IBaublesItemHandler.java b/src/main/java/baubles/api/cap/IBaublesItemHandler.java index d7ffb491..ca4a53f3 100644 --- a/src/main/java/baubles/api/cap/IBaublesItemHandler.java +++ b/src/main/java/baubles/api/cap/IBaublesItemHandler.java @@ -1,6 +1,7 @@ package baubles.api.cap; import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraftforge.items.IItemHandlerModifiable; @@ -21,4 +22,6 @@ public interface IBaublesItemHandler extends IItemHandlerModifiable { */ boolean isChanged(int slot); void setChanged(int slot, boolean changed); + + public void setPlayer(EntityLivingBase player); } diff --git a/src/main/java/baubles/api/package-info.java b/src/main/java/baubles/api/package-info.java index 15e1dc94..0052d2ab 100644 --- a/src/main/java/baubles/api/package-info.java +++ b/src/main/java/baubles/api/package-info.java @@ -1,4 +1,4 @@ -@API(owner = "Baubles", apiVersion = "1.4.0.1", provides = "Baubles|API") +@API(owner = "Baubles", apiVersion = "1.4.0.2", provides = "Baubles|API") package baubles.api; import net.minecraftforge.fml.common.API; diff --git a/src/main/java/baubles/common/Baubles.java b/src/main/java/baubles/common/Baubles.java index 38709564..de354af6 100644 --- a/src/main/java/baubles/common/Baubles.java +++ b/src/main/java/baubles/common/Baubles.java @@ -33,7 +33,7 @@ public class Baubles { public static final String MODID = "baubles"; public static final String MODNAME = "Baubles"; - public static final String VERSION = "1.4.2"; + public static final String VERSION = "1.4.3"; @SidedProxy(clientSide = "baubles.client.ClientProxy", serverSide = "baubles.common.CommonProxy") public static CommonProxy proxy; diff --git a/src/main/java/baubles/common/container/SlotBauble.java b/src/main/java/baubles/common/container/SlotBauble.java index 0a47a5b6..3315ca2b 100644 --- a/src/main/java/baubles/common/container/SlotBauble.java +++ b/src/main/java/baubles/common/container/SlotBauble.java @@ -25,10 +25,7 @@ public SlotBauble(EntityPlayer player, IBaublesItemHandler itemHandler, int slot @Override public boolean isItemValid(ItemStack stack) { - return stack!=null && !stack.isEmpty() && stack.getItem() !=null && - stack.getItem() instanceof IBauble && - ((IBauble)stack.getItem()).getBaubleType(stack).hasSlot(baubleSlot) && - ((IBauble)stack.getItem()).canEquip(stack, player); + return ((IBaublesItemHandler)getItemHandler()).isItemValidForSlot(baubleSlot, stack, player); } @Override diff --git a/src/main/resources/changelog.txt b/src/main/resources/changelog.txt index a7b21921..2e5a8dda 100644 --- a/src/main/resources/changelog.txt +++ b/src/main/resources/changelog.txt @@ -1,3 +1,6 @@ +1.4.3 +- added player references to capabilities container and added checks for item validity. + 1.4.2 - fix for ticking entity crash