2014-04-11 13:06:32 +02:00
|
|
|
package com.pahimar.ee3.tileentity;
|
|
|
|
|
2014-07-03 21:54:14 +02:00
|
|
|
import com.pahimar.ee3.item.ItemAlchemicalDust;
|
2014-07-03 22:00:25 +02:00
|
|
|
import com.pahimar.ee3.item.crafting.RecipeAludel;
|
2014-04-30 03:46:59 +02:00
|
|
|
import com.pahimar.ee3.network.PacketHandler;
|
|
|
|
import com.pahimar.ee3.network.message.MessageTileEntityAludel;
|
2014-07-03 22:00:25 +02:00
|
|
|
import com.pahimar.ee3.recipe.RecipesAludel;
|
2014-07-03 21:54:14 +02:00
|
|
|
import com.pahimar.ee3.reference.Names;
|
2014-07-03 22:00:25 +02:00
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
2014-04-11 13:06:32 +02:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.inventory.ISidedInventory;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2014-04-30 03:46:59 +02:00
|
|
|
import net.minecraft.network.Packet;
|
2014-07-03 21:54:14 +02:00
|
|
|
import net.minecraft.tileentity.TileEntityFurnace;
|
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
2014-04-11 13:06:32 +02:00
|
|
|
|
2014-04-30 03:46:59 +02:00
|
|
|
public class TileEntityAludel extends TileEntityEE implements ISidedInventory
|
2014-04-11 13:06:32 +02:00
|
|
|
{
|
|
|
|
public static final int INVENTORY_SIZE = 4;
|
|
|
|
public static final int FUEL_INVENTORY_INDEX = 0;
|
|
|
|
public static final int INPUT_INVENTORY_INDEX = 1;
|
|
|
|
public static final int DUST_INVENTORY_INDEX = 2;
|
|
|
|
public static final int OUTPUT_INVENTORY_INDEX = 3;
|
2014-07-03 21:54:14 +02:00
|
|
|
|
2014-04-11 13:06:32 +02:00
|
|
|
public int deviceCookTime; // How much longer the Aludel will cook
|
|
|
|
public int fuelBurnTime; // The fuel value for the currently burning fuel
|
|
|
|
public int itemCookTime; // How long the current item has been "cooking"
|
2014-07-03 21:54:14 +02:00
|
|
|
|
2014-04-11 13:06:32 +02:00
|
|
|
public ItemStack outputItemStack;
|
2014-07-03 21:54:14 +02:00
|
|
|
|
2014-04-11 13:06:32 +02:00
|
|
|
public boolean hasGlassBell = false;
|
|
|
|
/**
|
|
|
|
* The ItemStacks that hold the items currently being used in the Aludel
|
|
|
|
*/
|
|
|
|
private ItemStack[] inventory;
|
|
|
|
|
2014-04-30 03:46:59 +02:00
|
|
|
public TileEntityAludel()
|
2014-04-11 13:06:32 +02:00
|
|
|
{
|
|
|
|
inventory = new ItemStack[INVENTORY_SIZE];
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-07-03 21:54:14 +02:00
|
|
|
public int[] getAccessibleSlotsFromSide(int side)
|
2014-04-11 13:06:32 +02:00
|
|
|
{
|
2014-07-03 21:54:14 +02:00
|
|
|
return side == ForgeDirection.DOWN.ordinal() ? new int[]{FUEL_INVENTORY_INDEX, OUTPUT_INVENTORY_INDEX} : new int[]{INPUT_INVENTORY_INDEX, DUST_INVENTORY_INDEX, OUTPUT_INVENTORY_INDEX};
|
2014-04-11 13:06:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-07-03 21:54:14 +02:00
|
|
|
public boolean canInsertItem(int slotIndex, ItemStack itemStack, int side)
|
2014-04-11 13:06:32 +02:00
|
|
|
{
|
2014-07-03 21:54:14 +02:00
|
|
|
if (worldObj.getTileEntity(xCoord, yCoord + 1, zCoord) instanceof TileEntityGlassBell) {
|
|
|
|
return isItemValidForSlot(slotIndex, itemStack);
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2014-04-11 13:06:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-07-03 21:54:14 +02:00
|
|
|
public boolean canExtractItem(int slotIndex, ItemStack itemStack, int side)
|
2014-04-11 13:06:32 +02:00
|
|
|
{
|
2014-07-03 21:54:14 +02:00
|
|
|
return slotIndex == OUTPUT_INVENTORY_INDEX;
|
2014-04-11 13:06:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getSizeInventory()
|
|
|
|
{
|
2014-07-03 21:54:14 +02:00
|
|
|
return inventory.length;
|
2014-04-11 13:06:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-07-03 21:54:14 +02:00
|
|
|
public ItemStack getStackInSlot(int slotIndex)
|
2014-04-11 13:06:32 +02:00
|
|
|
{
|
2014-07-03 21:54:14 +02:00
|
|
|
return inventory[slotIndex];
|
2014-04-11 13:06:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-07-03 21:54:14 +02:00
|
|
|
public ItemStack decrStackSize(int slotIndex, int decrementAmount)
|
2014-04-11 13:06:32 +02:00
|
|
|
{
|
2014-07-03 21:54:14 +02:00
|
|
|
ItemStack itemStack = getStackInSlot(slotIndex);
|
|
|
|
if (itemStack != null) {
|
|
|
|
if (itemStack.stackSize <= decrementAmount) {
|
|
|
|
setInventorySlotContents(slotIndex, null);
|
|
|
|
} else {
|
|
|
|
itemStack = itemStack.splitStack(decrementAmount);
|
|
|
|
if (itemStack.stackSize == 0) {
|
|
|
|
setInventorySlotContents(slotIndex, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return itemStack;
|
2014-04-11 13:06:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-07-03 21:54:14 +02:00
|
|
|
public ItemStack getStackInSlotOnClosing(int slotIndex)
|
2014-04-11 13:06:32 +02:00
|
|
|
{
|
2014-07-03 21:54:14 +02:00
|
|
|
ItemStack itemStack = getStackInSlot(slotIndex);
|
|
|
|
if (itemStack != null) {
|
|
|
|
setInventorySlotContents(slotIndex, null);
|
|
|
|
}
|
|
|
|
return itemStack;
|
2014-04-11 13:06:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-07-03 21:54:14 +02:00
|
|
|
public void setInventorySlotContents(int slotIndex, ItemStack itemStack)
|
2014-04-11 13:06:32 +02:00
|
|
|
{
|
2014-07-03 21:54:14 +02:00
|
|
|
inventory[slotIndex] = itemStack;
|
|
|
|
if (itemStack != null && itemStack.stackSize > getInventoryStackLimit()) {
|
|
|
|
itemStack.stackSize = getInventoryStackLimit();
|
|
|
|
}
|
2014-04-11 13:06:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getInventoryName()
|
|
|
|
{
|
2014-07-03 21:54:14 +02:00
|
|
|
return this.hasCustomName() ? this.getCustomName() : Names.Containers.ALUDEL;
|
2014-04-11 13:06:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hasCustomInventoryName()
|
|
|
|
{
|
2014-07-03 21:54:14 +02:00
|
|
|
return this.hasCustomName();
|
2014-04-11 13:06:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getInventoryStackLimit()
|
|
|
|
{
|
2014-07-03 21:54:14 +02:00
|
|
|
return 64;
|
2014-04-11 13:06:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isUseableByPlayer(EntityPlayer var1)
|
|
|
|
{
|
2014-07-03 21:54:14 +02:00
|
|
|
return true;
|
2014-04-11 13:06:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void openInventory()
|
|
|
|
{
|
2014-07-03 21:54:14 +02:00
|
|
|
// NOOP
|
2014-04-11 13:06:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void closeInventory()
|
|
|
|
{
|
2014-07-03 21:54:14 +02:00
|
|
|
// NOOP
|
2014-04-11 13:06:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-07-03 21:54:14 +02:00
|
|
|
public boolean isItemValidForSlot(int slotIndex, ItemStack itemStack)
|
2014-04-11 13:06:32 +02:00
|
|
|
{
|
2014-07-03 21:54:14 +02:00
|
|
|
switch (slotIndex) {
|
|
|
|
case FUEL_INVENTORY_INDEX: {
|
|
|
|
return TileEntityFurnace.isItemFuel(itemStack);
|
|
|
|
}
|
|
|
|
case INPUT_INVENTORY_INDEX: {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
case DUST_INVENTORY_INDEX: {
|
|
|
|
return itemStack.getItem() instanceof ItemAlchemicalDust;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2014-04-11 13:06:32 +02:00
|
|
|
}
|
2014-04-30 03:46:59 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public Packet getDescriptionPacket()
|
|
|
|
{
|
|
|
|
return PacketHandler.INSTANCE.getPacketFrom(new MessageTileEntityAludel(this, null));
|
|
|
|
}
|
2014-07-03 22:00:25 +02:00
|
|
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public int getCookProgressScaled(int scale) {
|
|
|
|
return this.itemCookTime * scale / 200;
|
|
|
|
}
|
|
|
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public int getBurnTimeRemainingScaled(int scale) {
|
|
|
|
if (this.fuelBurnTime > 0) {
|
|
|
|
return this.deviceCookTime * scale / this.fuelBurnTime;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean canInfuse() {
|
|
|
|
if (!hasGlassBell || inventory[INPUT_INVENTORY_INDEX] == null || inventory[DUST_INVENTORY_INDEX] == null) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
ItemStack infusedItemStack = RecipesAludel.getInstance().getResult(inventory[INPUT_INVENTORY_INDEX], inventory[DUST_INVENTORY_INDEX]);
|
|
|
|
|
|
|
|
if (infusedItemStack == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (inventory[OUTPUT_INVENTORY_INDEX] == null) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
boolean outputEquals = this.inventory[OUTPUT_INVENTORY_INDEX].isItemEqual(infusedItemStack);
|
|
|
|
int mergedOutputStackSize = this.inventory[OUTPUT_INVENTORY_INDEX].stackSize + infusedItemStack.stackSize;
|
|
|
|
|
|
|
|
if (outputEquals) {
|
|
|
|
return mergedOutputStackSize <= getInventoryStackLimit() && mergedOutputStackSize <= infusedItemStack.getMaxStackSize();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void infuseItem() {
|
|
|
|
if (this.canInfuse()) {
|
|
|
|
RecipeAludel recipe = RecipesAludel.getInstance().getRecipe(inventory[INPUT_INVENTORY_INDEX], inventory[DUST_INVENTORY_INDEX]);
|
|
|
|
|
|
|
|
if (this.inventory[OUTPUT_INVENTORY_INDEX] == null) {
|
|
|
|
this.inventory[OUTPUT_INVENTORY_INDEX] = recipe.getRecipeOutput().copy();
|
|
|
|
} else if (this.inventory[OUTPUT_INVENTORY_INDEX].isItemEqual(recipe.getRecipeOutput())) {
|
|
|
|
inventory[OUTPUT_INVENTORY_INDEX].stackSize += recipe.getRecipeOutput().stackSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
decrStackSize(INPUT_INVENTORY_INDEX, recipe.getRecipeInputs()[0].getStackSize());
|
|
|
|
decrStackSize(DUST_INVENTORY_INDEX, recipe.getRecipeInputs()[1].getStackSize());
|
|
|
|
}
|
|
|
|
}
|
2014-04-11 13:06:32 +02:00
|
|
|
}
|