Skip to content

Commit

Permalink
added player references to capabilities container and added checks fo…
Browse files Browse the repository at this point in the history
…r item validity. Closes #185
  • Loading branch information
Azanor committed Jan 30, 2017
1 parent 9ee698d commit 7fc2086
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 14 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
14 changes: 10 additions & 4 deletions src/main/java/baubles/api/BaublesApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
24 changes: 21 additions & 3 deletions src/main/java/baubles/api/cap/BaublesContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -73,5 +86,10 @@ public void setChanged(int slot, boolean change) {
}
this.changed[slot] = change;
}

@Override
public void setPlayer(EntityLivingBase player) {
this.player=player;
}

}
3 changes: 3 additions & 0 deletions src/main/java/baubles/api/cap/IBaublesItemHandler.java
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -21,4 +22,6 @@ public interface IBaublesItemHandler extends IItemHandlerModifiable {
*/
boolean isChanged(int slot);
void setChanged(int slot, boolean changed);

public void setPlayer(EntityLivingBase player);
}
2 changes: 1 addition & 1 deletion src/main/java/baubles/api/package-info.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/baubles/common/Baubles.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 1 addition & 4 deletions src/main/java/baubles/common/container/SlotBauble.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/changelog.txt
Original file line number Diff line number Diff line change
@@ -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

Expand Down

0 comments on commit 7fc2086

Please sign in to comment.