Files
MagicBees/magicbees_src/magicbees/tileentity/TileEntityEffectJar.java
T

254 lines
5.9 KiB
Java
Raw Normal View History

2013-05-23 21:07:28 -07:00
package magicbees.tileentity;
2013-04-21 15:38:52 -07:00
2013-05-23 21:07:28 -07:00
import magicbees.bees.Allele;
2013-04-21 15:38:52 -07:00
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
2013-04-21 15:38:52 -07:00
import net.minecraft.tileentity.TileEntity;
import forestry.api.apiculture.BeeManager;
import forestry.api.apiculture.IAlleleBeeSpecies;
import forestry.api.apiculture.IBee;
import forestry.api.genetics.IEffectData;
2013-04-21 15:38:52 -07:00
public class TileEntityEffectJar extends TileEntity implements IInventory
{
private String ownerName;
private EffectJarHousing housingLogic;
private static final int SLOT_COUNT = 2;
public static final int DRONE_SLOT = 0;
public static final int QUEEN_SLOT = SLOT_COUNT - 1;
2013-04-21 15:38:52 -07:00
private ItemStack[] beeSlots;
private IEffectData[] effectData = new IEffectData[2];
private int throttle;
public int currentBeeHealth;
public int currentBeeColour;
2013-04-21 15:38:52 -07:00
public TileEntityEffectJar()
{
super();
this.beeSlots = new ItemStack[SLOT_COUNT];
2013-04-21 15:38:52 -07:00
}
public void setOwner(EntityPlayer player)
{
this.ownerName = player.username;
}
2013-05-15 10:41:48 -07:00
@Override
public boolean shouldRenderInPass(int pass)
{
return pass == 1;
}
2013-04-21 15:38:52 -07:00
public String getOwner()
{
return this.ownerName;
}
@Override
public int getSizeInventory()
{
// Last slot reserved for "queen"
return this.beeSlots.length - 1;
2013-04-21 15:38:52 -07:00
}
@Override
2013-04-22 16:03:27 -07:00
public ItemStack getStackInSlot(int slot)
2013-04-21 15:38:52 -07:00
{
return beeSlots[slot];
}
@Override
public void updateEntity()
{
if (this.beeSlots[QUEEN_SLOT] != null)
{
IBee queen = Allele.beeRoot.getMember(this.beeSlots[QUEEN_SLOT]);
currentBeeHealth = (queen.getHealth() * 100) / queen.getMaxHealth();
currentBeeColour = ((IAlleleBeeSpecies)queen.getGenome().getPrimary()).getIconColour(0);
EffectJarHousing housingLogic = EffectJarHousing.getFor(this);
this.effectData = queen.doEffect(this.effectData, housingLogic);
if (this.worldObj.getWorldTime() % 5 == 0)
{
this.effectData = queen.doFX(this.effectData, housingLogic);
}
// run the queen
if (throttle > 550)
{
throttle = 0;
queen.age(this.worldObj, 0.26f);
if (queen.getHealth() == 0)
{
this.beeSlots[QUEEN_SLOT] = null;
currentBeeHealth = 0;
currentBeeColour = 0x0ffffff;
}
else
{
queen.writeToNBT(this.beeSlots[QUEEN_SLOT].stackTagCompound);
}
this.onInventoryChanged();
}
else
{
throttle++;
}
}
else if (this.beeSlots[DRONE_SLOT] != null)
{
// make a queen
ItemStack droneStack = this.beeSlots[DRONE_SLOT];
if (Allele.beeRoot.isDrone(droneStack))
{
IBee bee = Allele.beeRoot.getMember(droneStack);
if (droneStack.stackSize == 1)
{
this.beeSlots[DRONE_SLOT] = null;
}
else
{
droneStack.stackSize--;
}
this.beeSlots[QUEEN_SLOT] = droneStack.copy();
this.beeSlots[QUEEN_SLOT].stackSize = 1;
int current = bee.getHealth();
int max = bee.getMaxHealth();
currentBeeHealth = (current * 100) / max;
currentBeeColour = ((IAlleleBeeSpecies)bee.getGenome().getPrimary()).getIconColour(0);
}
this.onInventoryChanged();
}
2013-04-21 15:38:52 -07:00
}
@Override
2013-04-22 16:03:27 -07:00
public ItemStack decrStackSize(int slot, int count)
2013-04-21 15:38:52 -07:00
{
2013-04-22 16:03:27 -07:00
ItemStack value = null;
if (this.beeSlots[slot] != null)
2013-04-22 16:03:27 -07:00
{
value = this.beeSlots[slot].copy();
value.stackSize = Math.min(count, this.beeSlots[slot].stackSize);
this.beeSlots[slot].stackSize -= value.stackSize;
if (this.beeSlots[slot].stackSize == 0)
2013-04-22 16:03:27 -07:00
{
this.beeSlots[slot] = null;
2013-04-22 16:03:27 -07:00
}
}
onInventoryChanged();
return value;
2013-04-21 15:38:52 -07:00
}
@Override
2013-04-22 16:03:27 -07:00
public ItemStack getStackInSlotOnClosing(int slot)
2013-04-21 15:38:52 -07:00
{
2013-04-22 16:03:27 -07:00
ItemStack value = null;
if (this.beeSlots[slot] != null)
2013-04-22 16:03:27 -07:00
{
value = this.beeSlots[slot];
this.beeSlots[slot] = null;
2013-04-22 16:03:27 -07:00
}
onInventoryChanged();
return value;
2013-04-21 15:38:52 -07:00
}
@Override
2013-04-22 16:03:27 -07:00
public void readFromNBT(NBTTagCompound tagRoot)
{
super.readFromNBT(tagRoot);
NBTTagList nbttaglist = tagRoot.getTagList("Items");
this.beeSlots = new ItemStack[SLOT_COUNT];
for (int i = 0; i < nbttaglist.tagCount(); ++i)
{
NBTTagCompound nbttagcompound1 = (NBTTagCompound)nbttaglist.tagAt(i);
byte b0 = nbttagcompound1.getByte("Slot");
if (b0 >= 0 && b0 < this.beeSlots.length)
{
this.beeSlots[b0] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
}
}
this.currentBeeHealth = tagRoot.getInteger("currentBeeHealth");
this.throttle = tagRoot.getInteger("throttle");
2013-04-21 15:38:52 -07:00
}
@Override
2013-04-22 16:03:27 -07:00
public void writeToNBT(NBTTagCompound tagRoot)
{
super.writeToNBT(tagRoot);
NBTTagList inventory = new NBTTagList();
for (int i = 0; i < this.beeSlots.length; ++i)
{
if (this.beeSlots[i] != null)
{
NBTTagCompound itemTag = new NBTTagCompound();
itemTag.setByte("Slot", (byte)i);
this.beeSlots[i].writeToNBT(itemTag);
inventory.appendTag(itemTag);
}
}
tagRoot.setTag("Items", inventory);
tagRoot.setInteger("currentBeeHealth", this.currentBeeHealth);
tagRoot.setInteger("throttle", this.throttle);
2013-04-21 15:38:52 -07:00
}
@Override
2013-04-22 16:03:27 -07:00
public void setInventorySlotContents(int slot, ItemStack itemStack)
2013-04-21 15:38:52 -07:00
{
this.beeSlots[slot] = itemStack;
if (this.beeSlots[slot] != null)
2013-04-22 16:03:27 -07:00
{
this.beeSlots[slot].stackSize = Math.min(this.beeSlots[slot].stackSize, this.beeSlots[slot].getItem().getItemStackLimit());
2013-04-22 16:03:27 -07:00
}
onInventoryChanged();
2013-04-21 15:38:52 -07:00
}
@Override
2013-04-22 16:03:27 -07:00
public String getInvName()
{
return "container.effectJar";
2013-04-21 15:38:52 -07:00
}
@Override
2013-04-22 16:03:27 -07:00
public boolean isInvNameLocalized()
{
2013-04-21 15:38:52 -07:00
return false;
}
@Override
2013-04-22 16:03:27 -07:00
public int getInventoryStackLimit()
{
return 64;
2013-04-21 15:38:52 -07:00
}
@Override
public boolean isUseableByPlayer(EntityPlayer entityplayer)
{
return true;
}
@Override
2013-04-22 16:03:27 -07:00
public boolean isStackValidForSlot(int i, ItemStack itemStack)
2013-04-21 15:38:52 -07:00
{
2013-04-22 16:03:27 -07:00
return true;
2013-04-21 15:38:52 -07:00
}
@Override
2013-04-22 16:03:27 -07:00
public void openChest() { }
2013-04-21 15:38:52 -07:00
@Override
public void closeChest() { }
}