This repository has been archived by the owner on Dec 6, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added baubles api and change build.gradle for build
- Loading branch information
1 parent
68b3f2f
commit 733ba15
Showing
12 changed files
with
562 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package baubles.api; | ||
|
||
public enum BaubleType { | ||
AMULET(0), | ||
RING(1,2), | ||
BELT(3), | ||
TRINKET(0,1,2,3,4,5,6), | ||
HEAD(4), | ||
BODY(5), | ||
CHARM(6); | ||
|
||
int[] validSlots; | ||
|
||
private BaubleType(int ... validSlots) { | ||
this.validSlots = validSlots; | ||
} | ||
|
||
public boolean hasSlot(int slot) { | ||
for (int s:validSlots) { | ||
if (s == slot) return true; | ||
} | ||
return false; | ||
} | ||
|
||
public int[] getValidSlots() { | ||
return validSlots; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package baubles.api; | ||
|
||
import baubles.api.cap.BaublesCapabilities; | ||
import baubles.api.cap.IBaublesItemHandler; | ||
import baubles.api.inv.BaublesInventoryWrapper; | ||
import net.minecraft.entity.player.EntityPlayer; | ||
import net.minecraft.inventory.IInventory; | ||
|
||
/** | ||
* @author Azanor | ||
*/ | ||
public class BaublesApi | ||
{ | ||
|
||
/** | ||
* Retrieves the baubles inventory capability handler for the supplied player | ||
*/ | ||
public static IBaublesItemHandler getBaublesHandler(EntityPlayer player) | ||
{ | ||
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) | ||
{ | ||
IBaublesItemHandler handler = player.getCapability(BaublesCapabilities.CAPABILITY_BAUBLES, null); | ||
handler.setPlayer(player); | ||
return new BaublesInventoryWrapper(handler, player); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package baubles.api; | ||
|
||
import net.minecraft.entity.EntityLivingBase; | ||
import net.minecraft.item.ItemStack; | ||
|
||
/** | ||
* | ||
* This interface should be extended by items that can be worn in bauble slots | ||
* | ||
* @author Azanor | ||
*/ | ||
|
||
public interface IBauble { | ||
|
||
/** | ||
* This method return the type of bauble this is. | ||
* Type is used to determine the slots it can go into. | ||
*/ | ||
public BaubleType getBaubleType(ItemStack itemstack); | ||
|
||
/** | ||
* This method is called once per tick if the bauble is being worn by a player | ||
*/ | ||
public default void onWornTick(ItemStack itemstack, EntityLivingBase player) { | ||
} | ||
|
||
/** | ||
* This method is called when the bauble is equipped by a player | ||
*/ | ||
public default void onEquipped(ItemStack itemstack, EntityLivingBase player) { | ||
} | ||
|
||
/** | ||
* This method is called when the bauble is unequipped by a player | ||
*/ | ||
public default void onUnequipped(ItemStack itemstack, EntityLivingBase player) { | ||
} | ||
|
||
/** | ||
* can this bauble be placed in a bauble slot | ||
*/ | ||
public default boolean canEquip(ItemStack itemstack, EntityLivingBase player) { | ||
return true; | ||
} | ||
|
||
/** | ||
* Can this bauble be removed from a bauble slot | ||
*/ | ||
public default boolean canUnequip(ItemStack itemstack, EntityLivingBase player) { | ||
return true; | ||
} | ||
|
||
/** | ||
* Will bauble automatically sync to client if a change is detected in its NBT or damage values? | ||
* Default is off, so override and set to true if you want to auto sync. | ||
* This sync is not instant, but occurs every 10 ticks (.5 seconds). | ||
*/ | ||
public default boolean willAutoSync(ItemStack itemstack, EntityLivingBase player) { | ||
return false; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package baubles.api.cap; | ||
|
||
import net.minecraft.nbt.NBTBase; | ||
import net.minecraft.util.EnumFacing; | ||
import net.minecraftforge.common.capabilities.Capability; | ||
import net.minecraftforge.common.capabilities.Capability.IStorage; | ||
import net.minecraftforge.common.capabilities.CapabilityInject; | ||
|
||
public class BaublesCapabilities { | ||
|
||
/** | ||
* Access to the baubles capability. | ||
*/ | ||
@CapabilityInject(IBaublesItemHandler.class) | ||
public static final Capability<IBaublesItemHandler> CAPABILITY_BAUBLES = null; | ||
|
||
public static class CapabilityBaubles<T extends IBaublesItemHandler> implements IStorage<IBaublesItemHandler> { | ||
|
||
@Override | ||
public NBTBase writeNBT (Capability<IBaublesItemHandler> capability, IBaublesItemHandler instance, EnumFacing side) { | ||
|
||
return null; | ||
} | ||
|
||
@Override | ||
public void readNBT (Capability<IBaublesItemHandler> capability, IBaublesItemHandler instance, EnumFacing side, NBTBase nbt) { | ||
|
||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package baubles.api.cap; | ||
|
||
import baubles.api.IBauble; | ||
import net.minecraft.entity.EntityLivingBase; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraftforge.items.ItemStackHandler; | ||
|
||
public class BaublesContainer extends ItemStackHandler implements IBaublesItemHandler { | ||
|
||
private final static int BAUBLE_SLOTS = 7; | ||
private boolean[] changed = new boolean[BAUBLE_SLOTS]; | ||
private boolean blockEvents=false; | ||
private EntityLivingBase player; | ||
|
||
public BaublesContainer() | ||
{ | ||
super(BAUBLE_SLOTS); | ||
} | ||
|
||
@Override | ||
public void setSize(int size) | ||
{ | ||
if (size<BAUBLE_SLOTS) size = BAUBLE_SLOTS; | ||
super.setSize(size); | ||
boolean[] old = changed; | ||
changed = new boolean[size]; | ||
for(int i = 0;i<old.length && i<changed.length;i++) | ||
{ | ||
changed[i] = old[i]; | ||
} | ||
} | ||
|
||
/** | ||
* Returns true if automation is allowed to insert the given stack (ignoring | ||
* stack size) into the given slot. | ||
*/ | ||
@Override | ||
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 ((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; | ||
} | ||
|
||
@Override | ||
public void setEventBlock(boolean blockEvents) { | ||
this.blockEvents = blockEvents; | ||
} | ||
|
||
@Override | ||
protected void onContentsChanged(int slot) | ||
{ | ||
setChanged(slot,true); | ||
} | ||
|
||
@Override | ||
public boolean isChanged(int slot) { | ||
if (changed==null) { | ||
changed = new boolean[this.getSlots()]; | ||
} | ||
return changed[slot]; | ||
} | ||
|
||
@Override | ||
public void setChanged(int slot, boolean change) { | ||
if (changed==null) { | ||
changed = new boolean[this.getSlots()]; | ||
} | ||
this.changed[slot] = change; | ||
} | ||
|
||
@Override | ||
public void setPlayer(EntityLivingBase player) { | ||
this.player=player; | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
src/api/java/baubles/api/cap/BaublesContainerProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package baubles.api.cap; | ||
|
||
import net.minecraft.nbt.NBTTagCompound; | ||
import net.minecraft.util.EnumFacing; | ||
import net.minecraftforge.common.capabilities.Capability; | ||
import net.minecraftforge.common.capabilities.ICapabilityProvider; | ||
import net.minecraftforge.common.util.INBTSerializable; | ||
|
||
public class BaublesContainerProvider implements INBTSerializable<NBTTagCompound>, ICapabilityProvider { | ||
|
||
private final BaublesContainer container; | ||
|
||
public BaublesContainerProvider(BaublesContainer container) { | ||
this.container = container; | ||
} | ||
|
||
@Override | ||
public boolean hasCapability (Capability<?> capability, EnumFacing facing) { | ||
return capability == BaublesCapabilities.CAPABILITY_BAUBLES; | ||
} | ||
|
||
@Override | ||
@SuppressWarnings("unchecked") | ||
public <T> T getCapability (Capability<T> capability, EnumFacing facing) { | ||
if (capability == BaublesCapabilities.CAPABILITY_BAUBLES) return (T) this.container; | ||
return null; | ||
} | ||
|
||
@Override | ||
public NBTTagCompound serializeNBT () { | ||
return this.container.serializeNBT(); | ||
} | ||
|
||
@Override | ||
public void deserializeNBT (NBTTagCompound nbt) { | ||
this.container.deserializeNBT(nbt); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
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; | ||
|
||
public interface IBaublesItemHandler extends IItemHandlerModifiable { | ||
|
||
public boolean isItemValidForSlot(int slot, ItemStack stack, EntityLivingBase player); | ||
|
||
/** | ||
* Used internally to prevent equip/unequip events from triggering when they shouldn't | ||
*/ | ||
public boolean isEventBlocked(); | ||
public void setEventBlock(boolean blockEvents); | ||
|
||
/** | ||
* Used internally for syncing. Indicates if the inventory has changed since last sync | ||
*/ | ||
boolean isChanged(int slot); | ||
void setChanged(int slot, boolean changed); | ||
|
||
public void setPlayer(EntityLivingBase player); | ||
} |
Oops, something went wrong.