Fix some netsync stuff with the Calcinator, as well as the read/write NBT stuff. Also reformat some of the code

This commit is contained in:
Pahimar 2014-07-04 15:18:10 -04:00
parent 990dab6bf5
commit f48f9093ab
18 changed files with 960 additions and 608 deletions

View file

@ -12,24 +12,28 @@ import net.minecraft.util.StatCollector;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public class GuiCalcinator extends GuiContainer { public class GuiCalcinator extends GuiContainer
{
private TileEntityCalcinator tileEntityCalcinator; private TileEntityCalcinator tileEntityCalcinator;
public GuiCalcinator(InventoryPlayer inventoryPlayer, TileEntityCalcinator tileEntityCalcinator) { public GuiCalcinator(InventoryPlayer inventoryPlayer, TileEntityCalcinator tileEntityCalcinator)
{
super(new ContainerCalcinator(inventoryPlayer, tileEntityCalcinator)); super(new ContainerCalcinator(inventoryPlayer, tileEntityCalcinator));
ySize = 176; ySize = 176;
this.tileEntityCalcinator = tileEntityCalcinator; this.tileEntityCalcinator = tileEntityCalcinator;
} }
@Override @Override
protected void drawGuiContainerForegroundLayer(int x, int y) { protected void drawGuiContainerForegroundLayer(int x, int y)
{
String containerName = StatCollector.translateToLocal(tileEntityCalcinator.getInventoryName()); String containerName = StatCollector.translateToLocal(tileEntityCalcinator.getInventoryName());
fontRendererObj.drawString(containerName, xSize / 2 - fontRendererObj.getStringWidth(containerName) / 2, 6, 4210752); fontRendererObj.drawString(containerName, xSize / 2 - fontRendererObj.getStringWidth(containerName) / 2, 6, 4210752);
fontRendererObj.drawString(StatCollector.translateToLocal(Names.Containers.VANILLA_INVENTORY), 8, ySize - 96 + 2, 4210752); fontRendererObj.drawString(StatCollector.translateToLocal(Names.Containers.VANILLA_INVENTORY), 8, ySize - 96 + 2, 4210752);
} }
@Override @Override
protected void drawGuiContainerBackgroundLayer(float opacity, int x, int y) { protected void drawGuiContainerBackgroundLayer(float opacity, int x, int y)
{
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(Textures.GUI_CALCINATOR); this.mc.getTextureManager().bindTexture(Textures.GUI_CALCINATOR);
@ -39,7 +43,8 @@ public class GuiCalcinator extends GuiContainer {
this.drawTexturedModalRect(xStart, yStart, 0, 0, xSize, ySize); this.drawTexturedModalRect(xStart, yStart, 0, 0, xSize, ySize);
int scaleAdjustment; int scaleAdjustment;
if (this.tileEntityCalcinator.getState() == 1) { if (this.tileEntityCalcinator.getState() == 1)
{
scaleAdjustment = this.tileEntityCalcinator.getBurnTimeRemainingScaled(12); scaleAdjustment = this.tileEntityCalcinator.getBurnTimeRemainingScaled(12);
this.drawTexturedModalRect(xStart + 57, yStart + 36 + 23 - scaleAdjustment, 176, 12 - scaleAdjustment, 14, scaleAdjustment + 2); this.drawTexturedModalRect(xStart + 57, yStart + 36 + 23 - scaleAdjustment, 176, 12 - scaleAdjustment, 14, scaleAdjustment + 2);
} }

View file

@ -23,31 +23,6 @@ public class EnergyValue implements Comparable<EnergyValue>, JsonDeserializer<En
this(new float[EnergyType.TYPES.length]); this(new float[EnergyType.TYPES.length]);
} }
public EnergyValue(int value)
{
this((float) value);
}
public EnergyValue(float value)
{
this(value, EnergyType.DEFAULT);
}
public EnergyValue(float value, EnergyComponent component)
{
this(value, component.type);
}
public EnergyValue(int value, EnergyType energyType)
{
this((float) value, energyType);
}
public EnergyValue(float value, EnergyType energyType)
{
this(value, Arrays.asList(new EnergyComponent(energyType)));
}
public EnergyValue(float[] components) public EnergyValue(float[] components)
{ {
if (components.length == EnergyType.TYPES.length) if (components.length == EnergyType.TYPES.length)
@ -65,9 +40,19 @@ public class EnergyValue implements Comparable<EnergyValue>, JsonDeserializer<En
} }
} }
public EnergyValue(int value, List<EnergyComponent> componentList) public EnergyValue(int value)
{ {
this((float) value, componentList); this((float) value);
}
public EnergyValue(float value)
{
this(value, EnergyType.DEFAULT);
}
public EnergyValue(float value, EnergyType energyType)
{
this(value, Arrays.asList(new EnergyComponent(energyType)));
} }
public EnergyValue(float value, List<EnergyComponent> componentList) public EnergyValue(float value, List<EnergyComponent> componentList)
@ -108,34 +93,6 @@ public class EnergyValue implements Comparable<EnergyValue>, JsonDeserializer<En
} }
} }
/**
* Deserializes an EnergyValue object from the given serialized json String
*
* @param jsonEnergyValue
* Json encoded String representing a EnergyValue object
*
* @return The EnergyValue that was encoded as json, or null if a valid EnergyValue could not be decoded from given
* String
*/
@SuppressWarnings("unused")
public static EnergyValue createFromJson(String jsonEnergyValue)
{
try
{
return gsonSerializer.fromJson(jsonEnergyValue, EnergyValue.class);
}
catch (JsonSyntaxException exception)
{
LogHelper.error(exception.getMessage());
}
catch (JsonParseException exception)
{
LogHelper.error(exception.getMessage());
}
return null;
}
private static List<EnergyComponent> collateComponents(List<EnergyComponent> uncollatedComponents) private static List<EnergyComponent> collateComponents(List<EnergyComponent> uncollatedComponents)
{ {
Integer[] componentCount = new Integer[EnergyType.TYPES.length]; Integer[] componentCount = new Integer[EnergyType.TYPES.length];
@ -168,25 +125,59 @@ public class EnergyValue implements Comparable<EnergyValue>, JsonDeserializer<En
return collatedComponents; return collatedComponents;
} }
private static int compareComponents(float[] first, float[] second) public EnergyValue(float value, EnergyComponent component)
{ {
if (first.length == EnergyType.TYPES.length && second.length == EnergyType.TYPES.length) this(value, component.type);
{
for (EnergyType energyType : EnergyType.TYPES)
{
if (Float.compare(first[energyType.ordinal()], second[energyType.ordinal()]) != 0)
{
return Float.compare(first[energyType.ordinal()], second[energyType.ordinal()]);
}
} }
return 0; public EnergyValue(int value, EnergyType energyType)
}
else
{ {
throw new ArrayIndexOutOfBoundsException(); this((float) value, energyType);
} }
public EnergyValue(int value, List<EnergyComponent> componentList)
{
this((float) value, componentList);
}
/**
* Deserializes an EnergyValue object from the given serialized json String
*
* @param jsonEnergyValue Json encoded String representing a EnergyValue object
* @return The EnergyValue that was encoded as json, or null if a valid EnergyValue could not be decoded from given
* String
*/
@SuppressWarnings("unused")
public static EnergyValue createFromJson(String jsonEnergyValue)
{
try
{
return gsonSerializer.fromJson(jsonEnergyValue, EnergyValue.class);
}
catch (JsonSyntaxException exception)
{
LogHelper.error(exception.getMessage());
}
catch (JsonParseException exception)
{
LogHelper.error(exception.getMessage());
}
return null;
}
@Override
public int hashCode()
{
int hashCode = 1;
hashCode = 37 * hashCode + Float.floatToIntBits(getValue());
for (float subValue : components)
{
hashCode = 37 * hashCode + Float.floatToIntBits(subValue);
}
return hashCode;
} }
public float getValue() public float getValue()
@ -228,20 +219,6 @@ public class EnergyValue implements Comparable<EnergyValue>, JsonDeserializer<En
return stringBuilder.toString(); return stringBuilder.toString();
} }
@Override
public int hashCode()
{
int hashCode = 1;
hashCode = 37 * hashCode + Float.floatToIntBits(getValue());
for (float subValue : components)
{
hashCode = 37 * hashCode + Float.floatToIntBits(subValue);
}
return hashCode;
}
@Override @Override
public int compareTo(EnergyValue exchangeEnergyValue) public int compareTo(EnergyValue exchangeEnergyValue)
{ {
@ -255,6 +232,27 @@ public class EnergyValue implements Comparable<EnergyValue>, JsonDeserializer<En
} }
} }
private static int compareComponents(float[] first, float[] second)
{
if (first.length == EnergyType.TYPES.length && second.length == EnergyType.TYPES.length)
{
for (EnergyType energyType : EnergyType.TYPES)
{
if (Float.compare(first[energyType.ordinal()], second[energyType.ordinal()]) != 0)
{
return Float.compare(first[energyType.ordinal()], second[energyType.ordinal()]);
}
}
return 0;
}
else
{
throw new ArrayIndexOutOfBoundsException();
}
}
/** /**
* Returns this EnergyValue as a json serialized String * Returns this EnergyValue as a json serialized String
* *

View file

@ -58,17 +58,17 @@ public class OreStack implements Comparable<OreStack>
} }
}; };
public OreStack(String oreName)
{
this(oreName, 1);
}
public OreStack(String oreName, int stackSize) public OreStack(String oreName, int stackSize)
{ {
this.oreName = oreName; this.oreName = oreName;
this.stackSize = stackSize; this.stackSize = stackSize;
} }
public OreStack(String oreName)
{
this(oreName, 1);
}
public OreStack(ItemStack itemStack) public OreStack(ItemStack itemStack)
{ {
if (itemStack != null && OreDictionary.getOreIDs(itemStack).length > 0) if (itemStack != null && OreDictionary.getOreIDs(itemStack).length > 0)
@ -94,9 +94,7 @@ public class OreStack implements Comparable<OreStack>
/** /**
* Deserializes a OreStack object from the given serialized json String * Deserializes a OreStack object from the given serialized json String
* *
* @param jsonOreStack * @param jsonOreStack Json encoded String representing a OreStack object
* Json encoded String representing a OreStack object
*
* @return The OreStack that was encoded as json, or null if a valid OreStack could not be decoded from given String * @return The OreStack that was encoded as json, or null if a valid OreStack could not be decoded from given String
*/ */
@SuppressWarnings("unused") @SuppressWarnings("unused")
@ -146,18 +144,18 @@ public class OreStack implements Comparable<OreStack>
return comparator.compare(oreStack1, oreStack2); return comparator.compare(oreStack1, oreStack2);
} }
@Override
public String toString()
{
return String.format("%sxoreStack.%s", stackSize, oreName);
}
@Override @Override
public boolean equals(Object object) public boolean equals(Object object)
{ {
return object instanceof OreStack && (comparator.compare(this, (OreStack) object) == Compare.EQUALS); return object instanceof OreStack && (comparator.compare(this, (OreStack) object) == Compare.EQUALS);
} }
@Override
public String toString()
{
return String.format("%sxoreStack.%s", stackSize, oreName);
}
@Override @Override
public int compareTo(OreStack oreStack) public int compareTo(OreStack oreStack)
{ {

View file

@ -13,18 +13,27 @@ import cpw.mods.fml.common.network.IGuiHandler;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World; import net.minecraft.world.World;
public class GuiHandler implements IGuiHandler { public class GuiHandler implements IGuiHandler
{
@Override @Override
public Object getServerGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) { public Object getServerGuiElement(int id, EntityPlayer player, World world, int x, int y, int z)
if (id == GuiIds.ALCHEMICAL_CHEST) { {
if (id == GuiIds.ALCHEMICAL_CHEST)
{
TileEntityAlchemicalChest tileEntityAlchemicalChest = (TileEntityAlchemicalChest) world.getTileEntity(x, y, z); TileEntityAlchemicalChest tileEntityAlchemicalChest = (TileEntityAlchemicalChest) world.getTileEntity(x, y, z);
return new ContainerAlchemicalChest(player.inventory, tileEntityAlchemicalChest); return new ContainerAlchemicalChest(player.inventory, tileEntityAlchemicalChest);
} else if (id == GuiIds.GLASS_BELL) { }
else if (id == GuiIds.GLASS_BELL)
{
TileEntityGlassBell tileEntityGlassBell = (TileEntityGlassBell) world.getTileEntity(x, y, z); TileEntityGlassBell tileEntityGlassBell = (TileEntityGlassBell) world.getTileEntity(x, y, z);
return new ContainerGlassBell(player.inventory, tileEntityGlassBell); return new ContainerGlassBell(player.inventory, tileEntityGlassBell);
} else if (id == GuiIds.ALCHEMICAL_BAG) { }
else if (id == GuiIds.ALCHEMICAL_BAG)
{
return new ContainerAlchemicalBag(player, new InventoryAlchemicalBag(player.getHeldItem())); return new ContainerAlchemicalBag(player, new InventoryAlchemicalBag(player.getHeldItem()));
} else if (id == GuiIds.CALCINATOR) { }
else if (id == GuiIds.CALCINATOR)
{
TileEntityCalcinator tileEntityCalcinator = (TileEntityCalcinator) world.getTileEntity(x, y, z); TileEntityCalcinator tileEntityCalcinator = (TileEntityCalcinator) world.getTileEntity(x, y, z);
return new ContainerCalcinator(player.inventory, tileEntityCalcinator); return new ContainerCalcinator(player.inventory, tileEntityCalcinator);
} }
@ -33,16 +42,24 @@ public class GuiHandler implements IGuiHandler {
} }
@Override @Override
public Object getClientGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) { public Object getClientGuiElement(int id, EntityPlayer player, World world, int x, int y, int z)
if (id == GuiIds.ALCHEMICAL_CHEST) { {
if (id == GuiIds.ALCHEMICAL_CHEST)
{
TileEntityAlchemicalChest tileEntityAlchemicalChest = (TileEntityAlchemicalChest) world.getTileEntity(x, y, z); TileEntityAlchemicalChest tileEntityAlchemicalChest = (TileEntityAlchemicalChest) world.getTileEntity(x, y, z);
return new GuiAlchemicalChest(player.inventory, tileEntityAlchemicalChest); return new GuiAlchemicalChest(player.inventory, tileEntityAlchemicalChest);
} else if (id == GuiIds.GLASS_BELL) { }
else if (id == GuiIds.GLASS_BELL)
{
TileEntityGlassBell tileEntityGlassBell = (TileEntityGlassBell) world.getTileEntity(x, y, z); TileEntityGlassBell tileEntityGlassBell = (TileEntityGlassBell) world.getTileEntity(x, y, z);
return new GuiGlassBell(player.inventory, tileEntityGlassBell); return new GuiGlassBell(player.inventory, tileEntityGlassBell);
} else if (id == GuiIds.ALCHEMICAL_BAG) { }
else if (id == GuiIds.ALCHEMICAL_BAG)
{
return new GuiAlchemicalBag(player, new InventoryAlchemicalBag(player.getHeldItem())); return new GuiAlchemicalBag(player, new InventoryAlchemicalBag(player.getHeldItem()));
} else if (id == GuiIds.CALCINATOR) { }
else if (id == GuiIds.CALCINATOR)
{
TileEntityCalcinator tileEntityCalcinator = (TileEntityCalcinator) world.getTileEntity(x, y, z); TileEntityCalcinator tileEntityCalcinator = (TileEntityCalcinator) world.getTileEntity(x, y, z);
return new GuiCalcinator(player.inventory, tileEntityCalcinator); return new GuiCalcinator(player.inventory, tileEntityCalcinator);
} }

View file

@ -11,13 +11,15 @@ import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntityFurnace; import net.minecraft.tileentity.TileEntityFurnace;
public class ContainerCalcinator extends Container { public class ContainerCalcinator extends Container
{
private TileEntityCalcinator tileEntityCalcinator; private TileEntityCalcinator tileEntityCalcinator;
private int lastCookTime; // How much longer the Calcinator will burn private int lastCookTime; // How much longer the Calcinator will burn
private int lastBurnTime; // The fuel value for the currently burning fuel private int lastBurnTime; // The fuel value for the currently burning fuel
private int lastItemCookTime; // How long the current item has been "cooking" private int lastItemCookTime; // How long the current item has been "cooking"
public ContainerCalcinator(InventoryPlayer inventoryPlayer, TileEntityCalcinator tileEntityCalcinator) { public ContainerCalcinator(InventoryPlayer inventoryPlayer, TileEntityCalcinator tileEntityCalcinator)
{
this.tileEntityCalcinator = tileEntityCalcinator; this.tileEntityCalcinator = tileEntityCalcinator;
// Add the fuel slot to the container // Add the fuel slot to the container
@ -31,75 +33,24 @@ public class ContainerCalcinator extends Container {
this.addSlotToContainer(new SlotCalcinator(tileEntityCalcinator, TileEntityCalcinator.OUTPUT_RIGHT_INVENTORY_INDEX, 136, 35)); this.addSlotToContainer(new SlotCalcinator(tileEntityCalcinator, TileEntityCalcinator.OUTPUT_RIGHT_INVENTORY_INDEX, 136, 35));
// Add the player's inventory slots to the container // Add the player's inventory slots to the container
for (int inventoryRowIndex = 0; inventoryRowIndex < 3; ++inventoryRowIndex) { for (int inventoryRowIndex = 0; inventoryRowIndex < 3; ++inventoryRowIndex)
for (int inventoryColumnIndex = 0; inventoryColumnIndex < 9; ++inventoryColumnIndex) { {
for (int inventoryColumnIndex = 0; inventoryColumnIndex < 9; ++inventoryColumnIndex)
{
this.addSlotToContainer(new Slot(inventoryPlayer, inventoryColumnIndex + inventoryRowIndex * 9 + 9, 8 + inventoryColumnIndex * 18, 94 + inventoryRowIndex * 18)); this.addSlotToContainer(new Slot(inventoryPlayer, inventoryColumnIndex + inventoryRowIndex * 9 + 9, 8 + inventoryColumnIndex * 18, 94 + inventoryRowIndex * 18));
} }
} }
// Add the player's action bar slots to the container // Add the player's action bar slots to the container
for (int actionBarSlotIndex = 0; actionBarSlotIndex < 9; ++actionBarSlotIndex) { for (int actionBarSlotIndex = 0; actionBarSlotIndex < 9; ++actionBarSlotIndex)
{
this.addSlotToContainer(new Slot(inventoryPlayer, actionBarSlotIndex, 8 + actionBarSlotIndex * 18, 152)); this.addSlotToContainer(new Slot(inventoryPlayer, actionBarSlotIndex, 8 + actionBarSlotIndex * 18, 152));
} }
} }
@Override @Override
public boolean canInteractWith(EntityPlayer player) { public void addCraftingToCrafters(ICrafting iCrafting)
return true; {
}
@Override
public ItemStack transferStackInSlot(EntityPlayer entityPlayer, int slotIndex) {
ItemStack itemStack = null;
Slot slot = (Slot) inventorySlots.get(slotIndex);
if (slot != null && slot.getHasStack()) {
ItemStack slotItemStack = slot.getStack();
itemStack = slotItemStack.copy();
/**
* If we are shift-clicking an item out of the Aludel's container,
* attempt to put it in the first available slot in the player's
* inventory
*/
if (slotIndex < TileEntityCalcinator.INVENTORY_SIZE) {
if (!this.mergeItemStack(slotItemStack, TileEntityCalcinator.INVENTORY_SIZE, inventorySlots.size(), false)) {
return null;
}
} else {
/**
* If the stack being shift-clicked into the Aludel's container
* is a fuel, first try to put it in the fuel slot. If it cannot
* be merged into the fuel slot, try to put it in the input
* slot.
*/
if (TileEntityFurnace.isItemFuel(slotItemStack)) {
if (!this.mergeItemStack(slotItemStack, TileEntityCalcinator.FUEL_INVENTORY_INDEX, TileEntityCalcinator.OUTPUT_LEFT_INVENTORY_INDEX, false)) {
return null;
}
}
/**
* Finally, attempt to put stack into the input slot
*/
else if (!this.mergeItemStack(slotItemStack, TileEntityCalcinator.INPUT_INVENTORY_INDEX, TileEntityCalcinator.OUTPUT_LEFT_INVENTORY_INDEX, false)) {
return null;
}
}
if (slotItemStack.stackSize == 0) {
slot.putStack(null);
} else {
slot.onSlotChanged();
}
}
return itemStack;
}
@Override
public void addCraftingToCrafters(ICrafting iCrafting) {
super.addCraftingToCrafters(iCrafting); super.addCraftingToCrafters(iCrafting);
iCrafting.sendProgressBarUpdate(this, 0, this.tileEntityCalcinator.deviceCookTime); iCrafting.sendProgressBarUpdate(this, 0, this.tileEntityCalcinator.deviceCookTime);
iCrafting.sendProgressBarUpdate(this, 1, this.tileEntityCalcinator.fuelBurnTime); iCrafting.sendProgressBarUpdate(this, 1, this.tileEntityCalcinator.fuelBurnTime);
@ -107,21 +58,26 @@ public class ContainerCalcinator extends Container {
} }
@Override @Override
public void detectAndSendChanges() { public void detectAndSendChanges()
{
super.detectAndSendChanges(); super.detectAndSendChanges();
for (Object crafter : this.crafters) { for (Object crafter : this.crafters)
{
ICrafting icrafting = (ICrafting) crafter; ICrafting icrafting = (ICrafting) crafter;
if (this.lastCookTime != this.tileEntityCalcinator.deviceCookTime) { if (this.lastCookTime != this.tileEntityCalcinator.deviceCookTime)
{
icrafting.sendProgressBarUpdate(this, 0, this.tileEntityCalcinator.deviceCookTime); icrafting.sendProgressBarUpdate(this, 0, this.tileEntityCalcinator.deviceCookTime);
} }
if (this.lastBurnTime != this.tileEntityCalcinator.fuelBurnTime) { if (this.lastBurnTime != this.tileEntityCalcinator.fuelBurnTime)
{
icrafting.sendProgressBarUpdate(this, 1, this.tileEntityCalcinator.fuelBurnTime); icrafting.sendProgressBarUpdate(this, 1, this.tileEntityCalcinator.fuelBurnTime);
} }
if (this.lastItemCookTime != this.tileEntityCalcinator.itemCookTime) { if (this.lastItemCookTime != this.tileEntityCalcinator.itemCookTime)
{
icrafting.sendProgressBarUpdate(this, 2, this.tileEntityCalcinator.itemCookTime); icrafting.sendProgressBarUpdate(this, 2, this.tileEntityCalcinator.itemCookTime);
} }
} }
@ -131,18 +87,90 @@ public class ContainerCalcinator extends Container {
this.lastItemCookTime = this.tileEntityCalcinator.itemCookTime; this.lastItemCookTime = this.tileEntityCalcinator.itemCookTime;
} }
@Override
public ItemStack transferStackInSlot(EntityPlayer entityPlayer, int slotIndex)
{
ItemStack itemStack = null;
Slot slot = (Slot) inventorySlots.get(slotIndex);
if (slot != null && slot.getHasStack())
{
ItemStack slotItemStack = slot.getStack();
itemStack = slotItemStack.copy();
/**
* If we are shift-clicking an item out of the Aludel's container,
* attempt to put it in the first available slot in the player's
* inventory
*/
if (slotIndex < TileEntityCalcinator.INVENTORY_SIZE)
{
if (!this.mergeItemStack(slotItemStack, TileEntityCalcinator.INVENTORY_SIZE, inventorySlots.size(), false))
{
return null;
}
}
else
{
/**
* If the stack being shift-clicked into the Aludel's container
* is a fuel, first try to put it in the fuel slot. If it cannot
* be merged into the fuel slot, try to put it in the input
* slot.
*/
if (TileEntityFurnace.isItemFuel(slotItemStack))
{
if (!this.mergeItemStack(slotItemStack, TileEntityCalcinator.FUEL_INVENTORY_INDEX, TileEntityCalcinator.OUTPUT_LEFT_INVENTORY_INDEX, false))
{
return null;
}
}
/**
* Finally, attempt to put stack into the input slot
*/
else if (!this.mergeItemStack(slotItemStack, TileEntityCalcinator.INPUT_INVENTORY_INDEX, TileEntityCalcinator.OUTPUT_LEFT_INVENTORY_INDEX, false))
{
return null;
}
}
if (slotItemStack.stackSize == 0)
{
slot.putStack(null);
}
else
{
slot.onSlotChanged();
}
}
return itemStack;
}
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public void updateProgressBar(int valueType, int updatedValue) { public void updateProgressBar(int valueType, int updatedValue)
if (valueType == 0) { {
if (valueType == 0)
{
this.tileEntityCalcinator.deviceCookTime = updatedValue; this.tileEntityCalcinator.deviceCookTime = updatedValue;
} }
if (valueType == 1) { if (valueType == 1)
{
this.tileEntityCalcinator.fuelBurnTime = updatedValue; this.tileEntityCalcinator.fuelBurnTime = updatedValue;
} }
if (valueType == 2) { if (valueType == 2)
{
this.tileEntityCalcinator.itemCookTime = updatedValue; this.tileEntityCalcinator.itemCookTime = updatedValue;
} }
} }
@Override
public boolean canInteractWith(EntityPlayer player)
{
return true;
}
} }

View file

@ -6,19 +6,23 @@ import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot; import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
public class SlotCalcinator extends Slot { public class SlotCalcinator extends Slot
public SlotCalcinator(IInventory inventory, int x, int y, int z) { {
public SlotCalcinator(IInventory inventory, int x, int y, int z)
{
super(inventory, x, y, z); super(inventory, x, y, z);
} }
@Override @Override
public boolean isItemValid(ItemStack par1ItemStack) { public void onPickupFromSlot(EntityPlayer entityPlayer, ItemStack itemStack)
return false; {
}
@Override
public void onPickupFromSlot(EntityPlayer entityPlayer, ItemStack itemStack) {
super.onPickupFromSlot(entityPlayer, itemStack); super.onPickupFromSlot(entityPlayer, itemStack);
FMLCommonHandler.instance().firePlayerCraftingEvent(entityPlayer, itemStack, inventory); FMLCommonHandler.instance().firePlayerCraftingEvent(entityPlayer, itemStack, inventory);
} }
@Override
public boolean isItemValid(ItemStack par1ItemStack)
{
return false;
}
} }

View file

@ -9,34 +9,61 @@ import net.minecraftforge.oredict.OreDictionary;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class RecipeAludel { public class RecipeAludel
{
private ItemStack recipeOutput; private ItemStack recipeOutput;
private WrappedStack inputStack; private WrappedStack inputStack;
private ItemStack dustStack; private ItemStack dustStack;
public RecipeAludel(ItemStack recipeOutput, ItemStack inputStack, ItemStack dustStack) { public RecipeAludel(ItemStack recipeOutput, ItemStack inputStack, ItemStack dustStack)
{
this.recipeOutput = recipeOutput.copy(); this.recipeOutput = recipeOutput.copy();
this.inputStack = new WrappedStack(inputStack); this.inputStack = new WrappedStack(inputStack);
this.dustStack = dustStack.copy(); this.dustStack = dustStack.copy();
} }
public RecipeAludel(ItemStack recipeOutput, OreStack inputStack, ItemStack dustStack) { public RecipeAludel(ItemStack recipeOutput, OreStack inputStack, ItemStack dustStack)
{
this.recipeOutput = recipeOutput.copy(); this.recipeOutput = recipeOutput.copy();
this.inputStack = new WrappedStack(inputStack); this.inputStack = new WrappedStack(inputStack);
this.dustStack = dustStack.copy(); this.dustStack = dustStack.copy();
} }
private static boolean compareStacks(WrappedStack wrappedStack1, WrappedStack wrappedStack2) { public boolean matches(ItemStack inputStack, ItemStack dustStack)
if (wrappedStack1 != null && wrappedStack1.getWrappedStack() != null && wrappedStack2 != null && wrappedStack2.getWrappedStack() != null) { {
if (wrappedStack1.getWrappedStack() instanceof ItemStack && wrappedStack2.getWrappedStack() instanceof ItemStack) { if (OreDictionary.getOreID(inputStack) != -1)
{
if (matches(new WrappedStack(new OreStack(inputStack)), dustStack))
{
return matches(new WrappedStack(new OreStack(inputStack)), dustStack);
}
}
return matches(new WrappedStack(inputStack), dustStack);
}
public boolean matches(WrappedStack inputStack, ItemStack dustStack)
{
return compareStacks(this.inputStack, inputStack) && compareItemStacks(this.dustStack, dustStack);
}
private static boolean compareStacks(WrappedStack wrappedStack1, WrappedStack wrappedStack2)
{
if (wrappedStack1 != null && wrappedStack1.getWrappedStack() != null && wrappedStack2 != null && wrappedStack2.getWrappedStack() != null)
{
if (wrappedStack1.getWrappedStack() instanceof ItemStack && wrappedStack2.getWrappedStack() instanceof ItemStack)
{
ItemStack itemStack1 = (ItemStack) wrappedStack1.getWrappedStack(); ItemStack itemStack1 = (ItemStack) wrappedStack1.getWrappedStack();
itemStack1.stackSize = wrappedStack1.getStackSize(); itemStack1.stackSize = wrappedStack1.getStackSize();
ItemStack itemStack2 = (ItemStack) wrappedStack2.getWrappedStack(); ItemStack itemStack2 = (ItemStack) wrappedStack2.getWrappedStack();
itemStack2.stackSize = wrappedStack2.getStackSize(); itemStack2.stackSize = wrappedStack2.getStackSize();
return compareItemStacks(itemStack1, itemStack2); return compareItemStacks(itemStack1, itemStack2);
} else if (wrappedStack1.getWrappedStack() instanceof OreStack && wrappedStack2.getWrappedStack() instanceof OreStack) { }
if (((OreStack) wrappedStack1.getWrappedStack()).oreName.equalsIgnoreCase(((OreStack) wrappedStack2.getWrappedStack()).oreName)) { else if (wrappedStack1.getWrappedStack() instanceof OreStack && wrappedStack2.getWrappedStack() instanceof OreStack)
{
if (((OreStack) wrappedStack1.getWrappedStack()).oreName.equalsIgnoreCase(((OreStack) wrappedStack2.getWrappedStack()).oreName))
{
return wrappedStack2.getStackSize() >= wrappedStack1.getStackSize(); return wrappedStack2.getStackSize() >= wrappedStack1.getStackSize();
} }
} }
@ -45,37 +72,23 @@ public class RecipeAludel {
return false; return false;
} }
private static boolean compareItemStacks(ItemStack itemStack1, ItemStack itemStack2) { private static boolean compareItemStacks(ItemStack itemStack1, ItemStack itemStack2)
{
return ItemHelper.equals(itemStack1, itemStack2); return ItemHelper.equals(itemStack1, itemStack2);
} }
public boolean matches(RecipeAludel recipeAludel) { public ItemStack getRecipeOutput()
return compareItemStacks(this.recipeOutput, recipeAludel.recipeOutput) && matches(recipeAludel.inputStack, recipeAludel.dustStack); {
}
public boolean matches(ItemStack inputStack, ItemStack dustStack) {
if (OreDictionary.getOreID(inputStack) != -1) {
if (matches(new WrappedStack(new OreStack(inputStack)), dustStack)) {
return matches(new WrappedStack(new OreStack(inputStack)), dustStack);
}
}
return matches(new WrappedStack(inputStack), dustStack);
}
public boolean matches(WrappedStack inputStack, ItemStack dustStack) {
return compareStacks(this.inputStack, inputStack) && compareItemStacks(this.dustStack, dustStack);
}
public ItemStack getRecipeOutput() {
return this.recipeOutput; return this.recipeOutput;
} }
public WrappedStack[] getRecipeInputs() { public WrappedStack[] getRecipeInputs()
{
return new WrappedStack[]{inputStack, new WrappedStack(dustStack)}; return new WrappedStack[]{inputStack, new WrappedStack(dustStack)};
} }
public List<WrappedStack> getRecipeInputsAsWrappedStacks() { public List<WrappedStack> getRecipeInputsAsWrappedStacks()
{
List<WrappedStack> recipeInputs = new ArrayList<WrappedStack>(); List<WrappedStack> recipeInputs = new ArrayList<WrappedStack>();
recipeInputs.add(new WrappedStack(inputStack)); recipeInputs.add(new WrappedStack(inputStack));
recipeInputs.add(new WrappedStack(dustStack)); recipeInputs.add(new WrappedStack(dustStack));
@ -83,16 +96,24 @@ public class RecipeAludel {
} }
@Override @Override
public boolean equals(Object object) { public boolean equals(Object object)
if (object instanceof RecipeAludel) { {
if (object instanceof RecipeAludel)
{
return matches((RecipeAludel) object); return matches((RecipeAludel) object);
} }
return false; return false;
} }
public boolean matches(RecipeAludel recipeAludel)
{
return compareItemStacks(this.recipeOutput, recipeAludel.recipeOutput) && matches(recipeAludel.inputStack, recipeAludel.dustStack);
}
@Override @Override
public String toString() { public String toString()
{
return String.format("Output: %s, Input: %s, Dust: %s", recipeOutput, inputStack, dustStack); return String.format("Output: %s, Input: %s, Dust: %s", recipeOutput, inputStack, dustStack);
} }
} }

View file

@ -13,17 +13,21 @@ import net.minecraftforge.oredict.OreDictionary;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class RecipesAludel { public class RecipesAludel
{
private static RecipesAludel aludelRegistry = null; private static RecipesAludel aludelRegistry = null;
private List<RecipeAludel> aludelRecipes; private List<RecipeAludel> aludelRecipes;
private RecipesAludel() { private RecipesAludel()
{
aludelRecipes = new ArrayList<RecipeAludel>(); aludelRecipes = new ArrayList<RecipeAludel>();
} }
public static RecipesAludel getInstance() { public static RecipesAludel getInstance()
if (aludelRegistry == null) { {
if (aludelRegistry == null)
{
aludelRegistry = new RecipesAludel(); aludelRegistry = new RecipesAludel();
aludelRegistry.init(); aludelRegistry.init();
} }
@ -31,7 +35,8 @@ public class RecipesAludel {
return aludelRegistry; return aludelRegistry;
} }
private void init() { private void init()
{
// Ash + Verdant = Azure // Ash + Verdant = Azure
aludelRegistry.addRecipe(new ItemStack(ModItems.alchemicalDust, 1, 2), new ItemStack(ModItems.alchemicalDust, 1, 0), new ItemStack(ModItems.alchemicalDust, 32, 1)); aludelRegistry.addRecipe(new ItemStack(ModItems.alchemicalDust, 1, 2), new ItemStack(ModItems.alchemicalDust, 1, 0), new ItemStack(ModItems.alchemicalDust, 32, 1));
@ -64,25 +69,34 @@ public class RecipesAludel {
aludelRegistry.addRecipe(new ItemStack(ModItems.stoneMinium), new ItemStack(ModItems.stoneInert), new ItemStack(ModItems.alchemicalDust, 8, 3)); aludelRegistry.addRecipe(new ItemStack(ModItems.stoneMinium), new ItemStack(ModItems.stoneInert), new ItemStack(ModItems.alchemicalDust, 8, 3));
} }
public void addRecipe(ItemStack recipeOutput, ItemStack recipeInputStack, ItemStack recipeInputDust) { public void addRecipe(ItemStack recipeOutput, ItemStack recipeInputStack, ItemStack recipeInputDust)
{
addRecipe(new RecipeAludel(recipeOutput, recipeInputStack, recipeInputDust)); addRecipe(new RecipeAludel(recipeOutput, recipeInputStack, recipeInputDust));
} }
public void addRecipe(ItemStack recipeOutput, OreStack recipeInputStack, ItemStack recipeInputDust) { public void addRecipe(RecipeAludel recipeAludel)
addRecipe(new RecipeAludel(recipeOutput, recipeInputStack, recipeInputDust)); {
} if (!aludelRecipes.contains(recipeAludel))
{
public void addRecipe(RecipeAludel recipeAludel) {
if (!aludelRecipes.contains(recipeAludel)) {
aludelRecipes.add(recipeAludel); aludelRecipes.add(recipeAludel);
} else { }
else
{
LogHelper.debug(String.format("Attempted to add RecipeAludel '%s' but already exists in the recipe list", recipeAludel)); LogHelper.debug(String.format("Attempted to add RecipeAludel '%s' but already exists in the recipe list", recipeAludel));
} }
} }
public ItemStack getResult(ItemStack recipeInputStack, ItemStack recipeInputDust) { public void addRecipe(ItemStack recipeOutput, OreStack recipeInputStack, ItemStack recipeInputDust)
for (RecipeAludel recipeAludel : aludelRecipes) { {
if (recipeAludel.matches(recipeInputStack, recipeInputDust)) { addRecipe(new RecipeAludel(recipeOutput, recipeInputStack, recipeInputDust));
}
public ItemStack getResult(ItemStack recipeInputStack, ItemStack recipeInputDust)
{
for (RecipeAludel recipeAludel : aludelRecipes)
{
if (recipeAludel.matches(recipeInputStack, recipeInputDust))
{
return recipeAludel.getRecipeOutput(); return recipeAludel.getRecipeOutput();
} }
} }
@ -90,9 +104,12 @@ public class RecipesAludel {
return null; return null;
} }
public RecipeAludel getRecipe(ItemStack recipeInputStack, ItemStack recipeInputDust) { public RecipeAludel getRecipe(ItemStack recipeInputStack, ItemStack recipeInputDust)
for (RecipeAludel recipeAludel : aludelRecipes) { {
if (recipeAludel.matches(recipeInputStack, recipeInputDust)) { for (RecipeAludel recipeAludel : aludelRecipes)
{
if (recipeAludel.matches(recipeInputStack, recipeInputDust))
{
return recipeAludel; return recipeAludel;
} }
} }
@ -100,12 +117,15 @@ public class RecipesAludel {
return null; return null;
} }
public List<RecipeAludel> getRecipes() { public List<RecipeAludel> getRecipes()
{
return aludelRecipes; return aludelRecipes;
} }
public void debugDumpMap() { public void debugDumpMap()
for (RecipeAludel recipeAludel : aludelRecipes) { {
for (RecipeAludel recipeAludel : aludelRecipes)
{
LogHelper.debug(String.format("Output: %s, Input Stack: %s, Dust Stack: %s", recipeAludel.getRecipeOutput(), recipeAludel.getRecipeInputs()[0], recipeAludel.getRecipeInputs()[1])); LogHelper.debug(String.format("Output: %s, Input Stack: %s, Dust Stack: %s", recipeAludel.getRecipeOutput(), recipeAludel.getRecipeInputs()[0], recipeAludel.getRecipeInputs()[1]));
} }
} }

View file

@ -1,6 +1,7 @@
package com.pahimar.ee3.reference; package com.pahimar.ee3.reference;
public final class GuiIds { public final class GuiIds
{
public static final int PORTABLE_CRAFTING = 0; public static final int PORTABLE_CRAFTING = 0;
public static final int CALCINATOR = 1; public static final int CALCINATOR = 1;
public static final int ALUDEL = 2; public static final int ALUDEL = 2;

View file

@ -10,7 +10,8 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList; import net.minecraft.nbt.NBTTagList;
public class TileEntityAlchemicalChest extends TileEntityEE implements IInventory { public class TileEntityAlchemicalChest extends TileEntityEE implements IInventory
{
/** /**
* The current angle of the chest lid (between 0 and 1) * The current angle of the chest lid (between 0 and 1)
*/ */
@ -36,38 +37,71 @@ public class TileEntityAlchemicalChest extends TileEntityEE implements IInventor
*/ */
private ItemStack[] inventory; private ItemStack[] inventory;
public TileEntityAlchemicalChest(int metaData) { public TileEntityAlchemicalChest(int metaData)
{
super(); super();
this.state = (byte) metaData; this.state = (byte) metaData;
if (metaData == 0) { if (metaData == 0)
{
inventory = new ItemStack[ContainerAlchemicalChest.SMALL_INVENTORY_SIZE]; inventory = new ItemStack[ContainerAlchemicalChest.SMALL_INVENTORY_SIZE];
} else if (metaData == 1) { }
else if (metaData == 1)
{
inventory = new ItemStack[ContainerAlchemicalChest.MEDIUM_INVENTORY_SIZE]; inventory = new ItemStack[ContainerAlchemicalChest.MEDIUM_INVENTORY_SIZE];
} else if (metaData == 2) { }
else if (metaData == 2)
{
inventory = new ItemStack[ContainerAlchemicalChest.LARGE_INVENTORY_SIZE]; inventory = new ItemStack[ContainerAlchemicalChest.LARGE_INVENTORY_SIZE];
} }
} }
@Override @Override
public int getSizeInventory() { public void readFromNBT(NBTTagCompound nbtTagCompound)
{
super.readFromNBT(nbtTagCompound);
// Read in the ItemStacks in the inventory from NBT
NBTTagList tagList = nbtTagCompound.getTagList("Items", 10);
inventory = new ItemStack[this.getSizeInventory()];
for (int i = 0; i < tagList.tagCount(); ++i)
{
NBTTagCompound tagCompound = tagList.getCompoundTagAt(i);
byte slotIndex = tagCompound.getByte("Slot");
if (slotIndex >= 0 && slotIndex < inventory.length)
{
inventory[slotIndex] = ItemStack.loadItemStackFromNBT(tagCompound);
}
}
}
@Override
public int getSizeInventory()
{
return inventory.length; return inventory.length;
} }
@Override @Override
public ItemStack getStackInSlot(int slotIndex) { public ItemStack getStackInSlot(int slotIndex)
{
return inventory[slotIndex]; return inventory[slotIndex];
} }
@Override @Override
public ItemStack decrStackSize(int slotIndex, int decrementAmount) { public ItemStack decrStackSize(int slotIndex, int decrementAmount)
{
ItemStack itemStack = getStackInSlot(slotIndex); ItemStack itemStack = getStackInSlot(slotIndex);
if (itemStack != null) { if (itemStack != null)
if (itemStack.stackSize <= decrementAmount) { {
if (itemStack.stackSize <= decrementAmount)
{
setInventorySlotContents(slotIndex, null); setInventorySlotContents(slotIndex, null);
} else { }
else
{
itemStack = itemStack.splitStack(decrementAmount); itemStack = itemStack.splitStack(decrementAmount);
if (itemStack.stackSize == 0) { if (itemStack.stackSize == 0)
{
setInventorySlotContents(slotIndex, null); setInventorySlotContents(slotIndex, null);
} }
} }
@ -77,21 +111,27 @@ public class TileEntityAlchemicalChest extends TileEntityEE implements IInventor
} }
@Override @Override
public ItemStack getStackInSlotOnClosing(int slotIndex) { public ItemStack getStackInSlotOnClosing(int slotIndex)
if (inventory[slotIndex] != null) { {
if (inventory[slotIndex] != null)
{
ItemStack itemStack = inventory[slotIndex]; ItemStack itemStack = inventory[slotIndex];
inventory[slotIndex] = null; inventory[slotIndex] = null;
return itemStack; return itemStack;
} else { }
else
{
return null; return null;
} }
} }
@Override @Override
public void setInventorySlotContents(int slotIndex, ItemStack itemStack) { public void setInventorySlotContents(int slotIndex, ItemStack itemStack)
{
inventory[slotIndex] = itemStack; inventory[slotIndex] = itemStack;
if (itemStack != null && itemStack.stackSize > this.getInventoryStackLimit()) { if (itemStack != null && itemStack.stackSize > this.getInventoryStackLimit())
{
itemStack.stackSize = this.getInventoryStackLimit(); itemStack.stackSize = this.getInventoryStackLimit();
} }
@ -100,17 +140,20 @@ public class TileEntityAlchemicalChest extends TileEntityEE implements IInventor
} }
@Override @Override
public String getInventoryName() { public String getInventoryName()
{
return this.hasCustomName() ? this.getCustomName() : Names.Containers.ALCHEMICAL_CHEST; return this.hasCustomName() ? this.getCustomName() : Names.Containers.ALCHEMICAL_CHEST;
} }
@Override @Override
public boolean hasCustomInventoryName() { public boolean hasCustomInventoryName()
{
return this.hasCustomName(); return this.hasCustomName();
} }
@Override @Override
public int getInventoryStackLimit() { public int getInventoryStackLimit()
{
return 64; return 64;
} }
@ -120,64 +163,42 @@ public class TileEntityAlchemicalChest extends TileEntityEE implements IInventor
* @param entityplayer The player we are checking to see if they can use this chest * @param entityplayer The player we are checking to see if they can use this chest
*/ */
@Override @Override
public boolean isUseableByPlayer(EntityPlayer entityplayer) { public boolean isUseableByPlayer(EntityPlayer entityplayer)
return true; {
}
/**
* Called when a client event is received with the event number and argument, see World.sendClientEvent
*/
@Override
public boolean receiveClientEvent(int eventID, int numUsingPlayers) {
if (eventID == 1) {
this.numUsingPlayers = numUsingPlayers;
return true;
} else {
return super.receiveClientEvent(eventID, numUsingPlayers);
}
}
@Override
public boolean isItemValidForSlot(int slotIndex, ItemStack itemStack) {
return true; return true;
} }
@Override @Override
public void openInventory() { public void openInventory()
{
++numUsingPlayers; ++numUsingPlayers;
worldObj.addBlockEvent(xCoord, yCoord, zCoord, ModBlocks.alchemicalChest, 1, numUsingPlayers); worldObj.addBlockEvent(xCoord, yCoord, zCoord, ModBlocks.alchemicalChest, 1, numUsingPlayers);
} }
@Override @Override
public void closeInventory() { public void closeInventory()
{
--numUsingPlayers; --numUsingPlayers;
worldObj.addBlockEvent(xCoord, yCoord, zCoord, ModBlocks.alchemicalChest, 1, numUsingPlayers); worldObj.addBlockEvent(xCoord, yCoord, zCoord, ModBlocks.alchemicalChest, 1, numUsingPlayers);
} }
@Override @Override
public void readFromNBT(NBTTagCompound nbtTagCompound) { public boolean isItemValidForSlot(int slotIndex, ItemStack itemStack)
super.readFromNBT(nbtTagCompound); {
return true;
// Read in the ItemStacks in the inventory from NBT
NBTTagList tagList = nbtTagCompound.getTagList("Items", 10);
inventory = new ItemStack[this.getSizeInventory()];
for (int i = 0; i < tagList.tagCount(); ++i) {
NBTTagCompound tagCompound = tagList.getCompoundTagAt(i);
byte slotIndex = tagCompound.getByte("Slot");
if (slotIndex >= 0 && slotIndex < inventory.length) {
inventory[slotIndex] = ItemStack.loadItemStackFromNBT(tagCompound);
}
}
} }
@Override @Override
public void writeToNBT(NBTTagCompound nbtTagCompound) { public void writeToNBT(NBTTagCompound nbtTagCompound)
{
super.writeToNBT(nbtTagCompound); super.writeToNBT(nbtTagCompound);
// Write the ItemStacks in the inventory to NBT // Write the ItemStacks in the inventory to NBT
NBTTagList tagList = new NBTTagList(); NBTTagList tagList = new NBTTagList();
for (int currentIndex = 0; currentIndex < inventory.length; ++currentIndex) { for (int currentIndex = 0; currentIndex < inventory.length; ++currentIndex)
if (inventory[currentIndex] != null) { {
if (inventory[currentIndex] != null)
{
NBTTagCompound tagCompound = new NBTTagCompound(); NBTTagCompound tagCompound = new NBTTagCompound();
tagCompound.setByte("Slot", (byte) currentIndex); tagCompound.setByte("Slot", (byte) currentIndex);
inventory[currentIndex].writeToNBT(tagCompound); inventory[currentIndex].writeToNBT(tagCompound);
@ -192,10 +213,12 @@ public class TileEntityAlchemicalChest extends TileEntityEE implements IInventor
* ticks and creates a new spawn inside its implementation. * ticks and creates a new spawn inside its implementation.
*/ */
@Override @Override
public void updateEntity() { public void updateEntity()
{
super.updateEntity(); super.updateEntity();
if (++ticksSinceSync % 20 * 4 == 0) { if (++ticksSinceSync % 20 * 4 == 0)
{
worldObj.addBlockEvent(xCoord, yCoord, zCoord, ModBlocks.alchemicalChest, 1, numUsingPlayers); worldObj.addBlockEvent(xCoord, yCoord, zCoord, ModBlocks.alchemicalChest, 1, numUsingPlayers);
} }
@ -203,34 +226,59 @@ public class TileEntityAlchemicalChest extends TileEntityEE implements IInventor
float angleIncrement = 0.1F; float angleIncrement = 0.1F;
double adjustedXCoord, adjustedZCoord; double adjustedXCoord, adjustedZCoord;
if (numUsingPlayers > 0 && lidAngle == 0.0F) { if (numUsingPlayers > 0 && lidAngle == 0.0F)
{
adjustedXCoord = xCoord + 0.5D; adjustedXCoord = xCoord + 0.5D;
adjustedZCoord = zCoord + 0.5D; adjustedZCoord = zCoord + 0.5D;
worldObj.playSoundEffect(adjustedXCoord, yCoord + 0.5D, adjustedZCoord, Sounds.CHEST_OPEN, 0.5F, worldObj.rand.nextFloat() * 0.1F + 0.9F); worldObj.playSoundEffect(adjustedXCoord, yCoord + 0.5D, adjustedZCoord, Sounds.CHEST_OPEN, 0.5F, worldObj.rand.nextFloat() * 0.1F + 0.9F);
} }
if (numUsingPlayers == 0 && lidAngle > 0.0F || numUsingPlayers > 0 && lidAngle < 1.0F) { if (numUsingPlayers == 0 && lidAngle > 0.0F || numUsingPlayers > 0 && lidAngle < 1.0F)
{
float var8 = lidAngle; float var8 = lidAngle;
if (numUsingPlayers > 0) { if (numUsingPlayers > 0)
{
lidAngle += angleIncrement; lidAngle += angleIncrement;
} else { }
else
{
lidAngle -= angleIncrement; lidAngle -= angleIncrement;
} }
if (lidAngle > 1.0F) { if (lidAngle > 1.0F)
{
lidAngle = 1.0F; lidAngle = 1.0F;
} }
if (lidAngle < 0.5F && var8 >= 0.5F) { if (lidAngle < 0.5F && var8 >= 0.5F)
{
adjustedXCoord = xCoord + 0.5D; adjustedXCoord = xCoord + 0.5D;
adjustedZCoord = zCoord + 0.5D; adjustedZCoord = zCoord + 0.5D;
worldObj.playSoundEffect(adjustedXCoord, yCoord + 0.5D, adjustedZCoord, Sounds.CHEST_CLOSE, 0.5F, worldObj.rand.nextFloat() * 0.1F + 0.9F); worldObj.playSoundEffect(adjustedXCoord, yCoord + 0.5D, adjustedZCoord, Sounds.CHEST_CLOSE, 0.5F, worldObj.rand.nextFloat() * 0.1F + 0.9F);
} }
if (lidAngle < 0.0F) { if (lidAngle < 0.0F)
{
lidAngle = 0.0F; lidAngle = 0.0F;
} }
} }
} }
/**
* Called when a client event is received with the event number and argument, see World.sendClientEvent
*/
@Override
public boolean receiveClientEvent(int eventID, int numUsingPlayers)
{
if (eventID == 1)
{
this.numUsingPlayers = numUsingPlayers;
return true;
}
else
{
return super.receiveClientEvent(eventID, numUsingPlayers);
}
}
} }

View file

@ -49,9 +49,12 @@ public class TileEntityAludel extends TileEntityEE implements ISidedInventory
@Override @Override
public boolean canInsertItem(int slotIndex, ItemStack itemStack, int side) public boolean canInsertItem(int slotIndex, ItemStack itemStack, int side)
{ {
if (worldObj.getTileEntity(xCoord, yCoord + 1, zCoord) instanceof TileEntityGlassBell) { if (worldObj.getTileEntity(xCoord, yCoord + 1, zCoord) instanceof TileEntityGlassBell)
{
return isItemValidForSlot(slotIndex, itemStack); return isItemValidForSlot(slotIndex, itemStack);
} else { }
else
{
return false; return false;
} }
} }
@ -78,12 +81,17 @@ public class TileEntityAludel extends TileEntityEE implements ISidedInventory
public ItemStack decrStackSize(int slotIndex, int decrementAmount) public ItemStack decrStackSize(int slotIndex, int decrementAmount)
{ {
ItemStack itemStack = getStackInSlot(slotIndex); ItemStack itemStack = getStackInSlot(slotIndex);
if (itemStack != null) { if (itemStack != null)
if (itemStack.stackSize <= decrementAmount) { {
if (itemStack.stackSize <= decrementAmount)
{
setInventorySlotContents(slotIndex, null); setInventorySlotContents(slotIndex, null);
} else { }
else
{
itemStack = itemStack.splitStack(decrementAmount); itemStack = itemStack.splitStack(decrementAmount);
if (itemStack.stackSize == 0) { if (itemStack.stackSize == 0)
{
setInventorySlotContents(slotIndex, null); setInventorySlotContents(slotIndex, null);
} }
} }
@ -96,7 +104,8 @@ public class TileEntityAludel extends TileEntityEE implements ISidedInventory
public ItemStack getStackInSlotOnClosing(int slotIndex) public ItemStack getStackInSlotOnClosing(int slotIndex)
{ {
ItemStack itemStack = getStackInSlot(slotIndex); ItemStack itemStack = getStackInSlot(slotIndex);
if (itemStack != null) { if (itemStack != null)
{
setInventorySlotContents(slotIndex, null); setInventorySlotContents(slotIndex, null);
} }
return itemStack; return itemStack;
@ -106,7 +115,8 @@ public class TileEntityAludel extends TileEntityEE implements ISidedInventory
public void setInventorySlotContents(int slotIndex, ItemStack itemStack) public void setInventorySlotContents(int slotIndex, ItemStack itemStack)
{ {
inventory[slotIndex] = itemStack; inventory[slotIndex] = itemStack;
if (itemStack != null && itemStack.stackSize > getInventoryStackLimit()) { if (itemStack != null && itemStack.stackSize > getInventoryStackLimit())
{
itemStack.stackSize = getInventoryStackLimit(); itemStack.stackSize = getInventoryStackLimit();
} }
} }
@ -150,17 +160,22 @@ public class TileEntityAludel extends TileEntityEE implements ISidedInventory
@Override @Override
public boolean isItemValidForSlot(int slotIndex, ItemStack itemStack) public boolean isItemValidForSlot(int slotIndex, ItemStack itemStack)
{ {
switch (slotIndex) { switch (slotIndex)
case FUEL_INVENTORY_INDEX: { {
case FUEL_INVENTORY_INDEX:
{
return TileEntityFurnace.isItemFuel(itemStack); return TileEntityFurnace.isItemFuel(itemStack);
} }
case INPUT_INVENTORY_INDEX: { case INPUT_INVENTORY_INDEX:
{
return true; return true;
} }
case DUST_INVENTORY_INDEX: { case DUST_INVENTORY_INDEX:
{
return itemStack.getItem() instanceof ItemAlchemicalDust; return itemStack.getItem() instanceof ItemAlchemicalDust;
} }
default: { default:
{
return false; return false;
} }
} }
@ -173,50 +188,33 @@ public class TileEntityAludel extends TileEntityEE implements ISidedInventory
} }
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public int getCookProgressScaled(int scale) { public int getCookProgressScaled(int scale)
{
return this.itemCookTime * scale / 200; return this.itemCookTime * scale / 200;
} }
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public int getBurnTimeRemainingScaled(int scale) { public int getBurnTimeRemainingScaled(int scale)
if (this.fuelBurnTime > 0) { {
if (this.fuelBurnTime > 0)
{
return this.deviceCookTime * scale / this.fuelBurnTime; return this.deviceCookTime * scale / this.fuelBurnTime;
} }
return 0; return 0;
} }
private boolean canInfuse() { public void infuseItem()
if (!hasGlassBell || inventory[INPUT_INVENTORY_INDEX] == null || inventory[DUST_INVENTORY_INDEX] == null) { {
return false; if (this.canInfuse())
} 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]); RecipeAludel recipe = RecipesAludel.getInstance().getRecipe(inventory[INPUT_INVENTORY_INDEX], inventory[DUST_INVENTORY_INDEX]);
if (this.inventory[OUTPUT_INVENTORY_INDEX] == null) { if (this.inventory[OUTPUT_INVENTORY_INDEX] == null)
{
this.inventory[OUTPUT_INVENTORY_INDEX] = recipe.getRecipeOutput().copy(); this.inventory[OUTPUT_INVENTORY_INDEX] = recipe.getRecipeOutput().copy();
} else if (this.inventory[OUTPUT_INVENTORY_INDEX].isItemEqual(recipe.getRecipeOutput())) { }
else if (this.inventory[OUTPUT_INVENTORY_INDEX].isItemEqual(recipe.getRecipeOutput()))
{
inventory[OUTPUT_INVENTORY_INDEX].stackSize += recipe.getRecipeOutput().stackSize; inventory[OUTPUT_INVENTORY_INDEX].stackSize += recipe.getRecipeOutput().stackSize;
} }
@ -224,4 +222,38 @@ public class TileEntityAludel extends TileEntityEE implements ISidedInventory
decrStackSize(DUST_INVENTORY_INDEX, recipe.getRecipeInputs()[1].getStackSize()); decrStackSize(DUST_INVENTORY_INDEX, recipe.getRecipeInputs()[1].getStackSize());
} }
} }
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;
}
} }

View file

@ -10,12 +10,15 @@ import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ISidedInventory; import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.network.Packet; import net.minecraft.network.Packet;
import net.minecraft.tileentity.TileEntityFurnace; import net.minecraft.tileentity.TileEntityFurnace;
import net.minecraft.tileentity.TileEntityHopper; import net.minecraft.tileentity.TileEntityHopper;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityCalcinator extends TileEntityEE implements ISidedInventory { public class TileEntityCalcinator extends TileEntityEE implements ISidedInventory
{
public static final int INVENTORY_SIZE = 4; public static final int INVENTORY_SIZE = 4;
public static final int FUEL_INVENTORY_INDEX = 0; public static final int FUEL_INVENTORY_INDEX = 0;
public static final int INPUT_INVENTORY_INDEX = 1; public static final int INPUT_INVENTORY_INDEX = 1;
@ -34,51 +37,81 @@ public class TileEntityCalcinator extends TileEntityEE implements ISidedInventor
*/ */
private ItemStack[] inventory; private ItemStack[] inventory;
public TileEntityCalcinator() { public TileEntityCalcinator()
{
inventory = new ItemStack[INVENTORY_SIZE]; inventory = new ItemStack[INVENTORY_SIZE];
} }
public static boolean suckInItems(TileEntityCalcinator tileEntityCalcinator) {
EntityItem entityitem = TileEntityHopper.func_145897_a(tileEntityCalcinator.getWorldObj(), tileEntityCalcinator.xCoord, tileEntityCalcinator.yCoord + 1.0D, tileEntityCalcinator.zCoord);
return entityitem != null && TileEntityHopper.func_145898_a(tileEntityCalcinator, entityitem);
}
@Override @Override
public int[] getAccessibleSlotsFromSide(int side) { public int[] getAccessibleSlotsFromSide(int side)
{
return side == ForgeDirection.DOWN.ordinal() ? new int[]{FUEL_INVENTORY_INDEX, OUTPUT_LEFT_INVENTORY_INDEX, OUTPUT_RIGHT_INVENTORY_INDEX} : new int[]{INPUT_INVENTORY_INDEX, OUTPUT_LEFT_INVENTORY_INDEX, OUTPUT_RIGHT_INVENTORY_INDEX}; return side == ForgeDirection.DOWN.ordinal() ? new int[]{FUEL_INVENTORY_INDEX, OUTPUT_LEFT_INVENTORY_INDEX, OUTPUT_RIGHT_INVENTORY_INDEX} : new int[]{INPUT_INVENTORY_INDEX, OUTPUT_LEFT_INVENTORY_INDEX, OUTPUT_RIGHT_INVENTORY_INDEX};
} }
@Override @Override
public boolean canInsertItem(int slotIndex, ItemStack itemStack, int side) { public boolean canInsertItem(int slotIndex, ItemStack itemStack, int side)
{
return isItemValidForSlot(slotIndex, itemStack); return isItemValidForSlot(slotIndex, itemStack);
} }
@Override @Override
public boolean canExtractItem(int slotIndex, ItemStack itemStack, int side) { public boolean canExtractItem(int slotIndex, ItemStack itemStack, int side)
{
return slotIndex == OUTPUT_LEFT_INVENTORY_INDEX || slotIndex == OUTPUT_RIGHT_INVENTORY_INDEX; return slotIndex == OUTPUT_LEFT_INVENTORY_INDEX || slotIndex == OUTPUT_RIGHT_INVENTORY_INDEX;
} }
@Override @Override
public int getSizeInventory() { public void readFromNBT(NBTTagCompound nbtTagCompound)
{
super.readFromNBT(nbtTagCompound);
// Read in the ItemStacks in the inventory from NBT
NBTTagList tagList = nbtTagCompound.getTagList("Items", 10);
inventory = new ItemStack[this.getSizeInventory()];
for (int i = 0; i < tagList.tagCount(); ++i)
{
NBTTagCompound tagCompound = tagList.getCompoundTagAt(i);
byte slotIndex = tagCompound.getByte("Slot");
if (slotIndex >= 0 && slotIndex < inventory.length)
{
inventory[slotIndex] = ItemStack.loadItemStackFromNBT(tagCompound);
}
}
deviceCookTime = nbtTagCompound.getInteger("deviceCookTime");
fuelBurnTime = nbtTagCompound.getInteger("fuelBurnTime");
itemCookTime = nbtTagCompound.getInteger("itemCookTime");
itemSuckCoolDown = nbtTagCompound.getInteger("itemSuckCoolDown");
}
@Override
public int getSizeInventory()
{
return inventory.length; return inventory.length;
} }
@Override @Override
public ItemStack getStackInSlot(int slotIndex) { public ItemStack getStackInSlot(int slotIndex)
{
sendDustPileData(); sendDustPileData();
return inventory[slotIndex]; return inventory[slotIndex];
} }
@Override @Override
public ItemStack decrStackSize(int slotIndex, int decrementAmount) { public ItemStack decrStackSize(int slotIndex, int decrementAmount)
{
ItemStack itemStack = getStackInSlot(slotIndex); ItemStack itemStack = getStackInSlot(slotIndex);
if (itemStack != null) { if (itemStack != null)
if (itemStack.stackSize <= decrementAmount) { {
if (itemStack.stackSize <= decrementAmount)
{
setInventorySlotContents(slotIndex, null); setInventorySlotContents(slotIndex, null);
} else { }
else
{
itemStack = itemStack.splitStack(decrementAmount); itemStack = itemStack.splitStack(decrementAmount);
if (itemStack.stackSize == 0) { if (itemStack.stackSize == 0)
{
setInventorySlotContents(slotIndex, null); setInventorySlotContents(slotIndex, null);
} }
} }
@ -88,90 +121,161 @@ public class TileEntityCalcinator extends TileEntityEE implements ISidedInventor
} }
@Override @Override
public ItemStack getStackInSlotOnClosing(int slotIndex) { public ItemStack getStackInSlotOnClosing(int slotIndex)
{
ItemStack itemStack = getStackInSlot(slotIndex); ItemStack itemStack = getStackInSlot(slotIndex);
if (itemStack != null) { if (itemStack != null)
{
setInventorySlotContents(slotIndex, null); setInventorySlotContents(slotIndex, null);
} }
return itemStack; return itemStack;
} }
@Override @Override
public void setInventorySlotContents(int slotIndex, ItemStack itemStack) { public void setInventorySlotContents(int slotIndex, ItemStack itemStack)
{
inventory[slotIndex] = itemStack; inventory[slotIndex] = itemStack;
if (itemStack != null && itemStack.stackSize > getInventoryStackLimit()) { if (itemStack != null && itemStack.stackSize > getInventoryStackLimit())
{
itemStack.stackSize = getInventoryStackLimit(); itemStack.stackSize = getInventoryStackLimit();
} }
} }
@Override @Override
public String getInventoryName() { public String getInventoryName()
{
return this.hasCustomName() ? this.getCustomName() : Names.Containers.CALCINATOR; return this.hasCustomName() ? this.getCustomName() : Names.Containers.CALCINATOR;
} }
@Override @Override
public boolean hasCustomInventoryName() { public boolean hasCustomInventoryName()
{
return this.hasCustomName(); return this.hasCustomName();
} }
@Override @Override
public int getInventoryStackLimit() { public int getInventoryStackLimit()
{
return 64; return 64;
} }
@Override @Override
public boolean isUseableByPlayer(EntityPlayer entityplayer) { public boolean isUseableByPlayer(EntityPlayer entityplayer)
{
return true; return true;
} }
@Override @Override
public void openInventory() { public void openInventory()
{
// NOOP // NOOP
} }
@Override @Override
public void closeInventory() { public void closeInventory()
{
// NOOP // NOOP
} }
@Override @Override
public boolean isItemValidForSlot(int var1, ItemStack var2) { public boolean isItemValidForSlot(int var1, ItemStack var2)
{
return false; return false;
} }
@Override private void sendDustPileData()
public boolean receiveClientEvent(int eventId, int eventData) { {
if (eventId == 1) { if (this.getBlockType() != null)
this.state = (byte) eventData; {
// NAME UPDATE this.worldObj.addBlockEvent(this.xCoord, this.yCoord, this.zCoord, this.getBlockType(), 2, getLeftStackSize());
// this.worldObj.updateAllLightTypes(this.xCoord, this.yCoord, this.zCoord); this.worldObj.addBlockEvent(this.xCoord, this.yCoord, this.zCoord, this.getBlockType(), 3, getLeftStackMeta());
this.worldObj.func_147451_t(this.xCoord, this.yCoord, this.zCoord); this.worldObj.addBlockEvent(this.xCoord, this.yCoord, this.zCoord, this.getBlockType(), 4, getRightStackSize());
return true; this.worldObj.addBlockEvent(this.xCoord, this.yCoord, this.zCoord, this.getBlockType(), 5, getRightStackMeta());
} else if (eventId == 2) {
this.leftStackSize = (byte) eventData;
return true;
} else if (eventId == 3) {
this.leftStackMeta = (byte) eventData;
return true;
} else if (eventId == 4) {
this.rightStackSize = (byte) eventData;
return true;
} else if (eventId == 5) {
this.rightStackMeta = (byte) eventData;
return true;
} else {
return super.receiveClientEvent(eventId, eventData);
} }
} }
private int getLeftStackSize()
{
if (this.inventory[OUTPUT_LEFT_INVENTORY_INDEX] != null)
{
return this.inventory[OUTPUT_LEFT_INVENTORY_INDEX].stackSize;
}
return 0;
}
private int getLeftStackMeta()
{
if (this.inventory[OUTPUT_LEFT_INVENTORY_INDEX] != null)
{
return this.inventory[OUTPUT_LEFT_INVENTORY_INDEX].getItemDamage();
}
return 0;
}
private int getRightStackSize()
{
if (this.inventory[OUTPUT_RIGHT_INVENTORY_INDEX] != null)
{
return this.inventory[OUTPUT_RIGHT_INVENTORY_INDEX].stackSize;
}
return 0;
}
private int getRightStackMeta()
{
if (this.inventory[OUTPUT_RIGHT_INVENTORY_INDEX] != null)
{
return this.inventory[OUTPUT_RIGHT_INVENTORY_INDEX].getItemDamage();
}
return 0;
}
@Override
public void writeToNBT(NBTTagCompound nbtTagCompound)
{
super.writeToNBT(nbtTagCompound);
// Write the ItemStacks in the inventory to NBT
NBTTagList tagList = new NBTTagList();
for (int currentIndex = 0; currentIndex < inventory.length; ++currentIndex)
{
if (inventory[currentIndex] != null)
{
NBTTagCompound tagCompound = new NBTTagCompound();
tagCompound.setByte("Slot", (byte) currentIndex);
inventory[currentIndex].writeToNBT(tagCompound);
tagList.appendTag(tagCompound);
}
}
nbtTagCompound.setTag("Items", tagList);
nbtTagCompound.setInteger("deviceCookTime", deviceCookTime);
nbtTagCompound.setInteger("fuelBurnTime", fuelBurnTime);
nbtTagCompound.setInteger("itemCookTime", itemCookTime);
nbtTagCompound.setInteger("itemSuckCoolDown", itemSuckCoolDown);
}
@Override
public Packet getDescriptionPacket()
{
sendDustPileData();
return PacketHandler.INSTANCE.getPacketFrom(new MessageTileCalcinator(this));
}
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public int getCookProgressScaled(int scale) { public int getCookProgressScaled(int scale)
{
return this.itemCookTime * scale / 200; return this.itemCookTime * scale / 200;
} }
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public int getBurnTimeRemainingScaled(int scale) { public int getBurnTimeRemainingScaled(int scale)
if (this.fuelBurnTime > 0) { {
if (this.fuelBurnTime > 0)
{
return this.deviceCookTime * scale / this.fuelBurnTime; return this.deviceCookTime * scale / this.fuelBurnTime;
} }
@ -179,32 +283,34 @@ public class TileEntityCalcinator extends TileEntityEE implements ISidedInventor
} }
@Override @Override
public Packet getDescriptionPacket() { public void updateEntity()
return PacketHandler.INSTANCE.getPacketFrom(new MessageTileCalcinator(this)); {
}
@Override
public void updateEntity() {
boolean isBurning = this.deviceCookTime > 0; boolean isBurning = this.deviceCookTime > 0;
boolean sendUpdate = false; boolean sendUpdate = false;
// If the Calcinator still has burn time, decrement it // If the Calcinator still has burn time, decrement it
if (this.deviceCookTime > 0) { if (this.deviceCookTime > 0)
{
this.deviceCookTime--; this.deviceCookTime--;
} }
if (!this.worldObj.isRemote) { if (!this.worldObj.isRemote)
{
// Start "cooking" a new item, if we can // Start "cooking" a new item, if we can
if (this.deviceCookTime == 0 && this.canCalcinate()) { if (this.deviceCookTime == 0 && this.canCalcinate())
{
this.fuelBurnTime = this.deviceCookTime = TileEntityFurnace.getItemBurnTime(this.inventory[FUEL_INVENTORY_INDEX]); this.fuelBurnTime = this.deviceCookTime = TileEntityFurnace.getItemBurnTime(this.inventory[FUEL_INVENTORY_INDEX]);
if (this.deviceCookTime > 0) { if (this.deviceCookTime > 0)
{
sendUpdate = true; sendUpdate = true;
if (this.inventory[FUEL_INVENTORY_INDEX] != null) { if (this.inventory[FUEL_INVENTORY_INDEX] != null)
{
--this.inventory[FUEL_INVENTORY_INDEX].stackSize; --this.inventory[FUEL_INVENTORY_INDEX].stackSize;
if (this.inventory[FUEL_INVENTORY_INDEX].stackSize == 0) { if (this.inventory[FUEL_INVENTORY_INDEX].stackSize == 0)
{
this.inventory[FUEL_INVENTORY_INDEX] = this.inventory[FUEL_INVENTORY_INDEX].getItem().getContainerItem(inventory[FUEL_INVENTORY_INDEX]); this.inventory[FUEL_INVENTORY_INDEX] = this.inventory[FUEL_INVENTORY_INDEX].getItem().getContainerItem(inventory[FUEL_INVENTORY_INDEX]);
} }
} }
@ -212,35 +318,45 @@ public class TileEntityCalcinator extends TileEntityEE implements ISidedInventor
} }
// Continue "cooking" the same item, if we can // Continue "cooking" the same item, if we can
if (this.deviceCookTime > 0 && this.canCalcinate()) { if (this.deviceCookTime > 0 && this.canCalcinate())
{
this.itemCookTime++; this.itemCookTime++;
if (this.itemCookTime == 200) { if (this.itemCookTime == 200)
{
this.itemCookTime = 0; this.itemCookTime = 0;
this.calcinateItem(); this.calcinateItem();
sendUpdate = true; sendUpdate = true;
} }
} else { }
else
{
this.itemCookTime = 0; this.itemCookTime = 0;
} }
// If the state has changed, catch that something changed // If the state has changed, catch that something changed
if (isBurning != this.deviceCookTime > 0) { if (isBurning != this.deviceCookTime > 0)
{
sendUpdate = true; sendUpdate = true;
} }
//Item sucking //Item sucking
if (this.itemSuckCoolDown > 0) { if (this.itemSuckCoolDown > 0)
{
itemSuckCoolDown--; itemSuckCoolDown--;
} else { }
if (suckInItems(this)) { else
{
if (suckInItems(this))
{
markDirty(); markDirty();
} }
itemSuckCoolDown = DEFAULT_ITEM_SUCK_COOL_DOWN; itemSuckCoolDown = DEFAULT_ITEM_SUCK_COOL_DOWN;
} }
} }
if (sendUpdate) { if (sendUpdate)
{
this.markDirty(); this.markDirty();
this.state = this.deviceCookTime > 0 ? (byte) 1 : (byte) 0; this.state = this.deviceCookTime > 0 ? (byte) 1 : (byte) 0;
this.worldObj.addBlockEvent(this.xCoord, this.yCoord, this.zCoord, this.getBlockType(), 1, this.state); this.worldObj.addBlockEvent(this.xCoord, this.yCoord, this.zCoord, this.getBlockType(), 1, this.state);
@ -249,36 +365,66 @@ public class TileEntityCalcinator extends TileEntityEE implements ISidedInventor
} }
} }
public void calcinateItem() { @Override
if (this.canCalcinate()) { public boolean receiveClientEvent(int eventId, int eventData)
ItemStack alchemicalDustStack = CalcinationHelper.getCalcinationResult(this.inventory[INPUT_INVENTORY_INDEX]); {
addItemStackToOutput(alchemicalDustStack.copy()); if (eventId == 1)
{
this.inventory[INPUT_INVENTORY_INDEX].stackSize--; this.state = (byte) eventData;
// NAME UPDATE
if (this.inventory[INPUT_INVENTORY_INDEX].stackSize <= 0) { // this.worldObj.updateAllLightTypes(this.xCoord, this.yCoord, this.zCoord);
this.inventory[INPUT_INVENTORY_INDEX] = null; this.worldObj.func_147451_t(this.xCoord, this.yCoord, this.zCoord);
return true;
} }
else if (eventId == 2)
{
this.leftStackSize = (byte) eventData;
return true;
}
else if (eventId == 3)
{
this.leftStackMeta = (byte) eventData;
return true;
}
else if (eventId == 4)
{
this.rightStackSize = (byte) eventData;
return true;
}
else if (eventId == 5)
{
this.rightStackMeta = (byte) eventData;
return true;
}
else
{
return super.receiveClientEvent(eventId, eventData);
} }
} }
private boolean canCalcinate() { private boolean canCalcinate()
if (inventory[INPUT_INVENTORY_INDEX] == null) { {
if (inventory[INPUT_INVENTORY_INDEX] == null)
{
return false; return false;
} else { }
else
{
ItemStack alchemicalDustStack = CalcinationHelper.getCalcinationResult(this.inventory[INPUT_INVENTORY_INDEX]); ItemStack alchemicalDustStack = CalcinationHelper.getCalcinationResult(this.inventory[INPUT_INVENTORY_INDEX]);
/** /**
* If we don't get a calcination result, then return false * If we don't get a calcination result, then return false
*/ */
if (alchemicalDustStack == null) { if (alchemicalDustStack == null)
{
return false; return false;
} }
/** /**
* If either slot is empty, return true (we have a valid calcination result * If either slot is empty, return true (we have a valid calcination result
*/ */
if (this.inventory[OUTPUT_LEFT_INVENTORY_INDEX] == null || this.inventory[OUTPUT_RIGHT_INVENTORY_INDEX] == null) { if (this.inventory[OUTPUT_LEFT_INVENTORY_INDEX] == null || this.inventory[OUTPUT_RIGHT_INVENTORY_INDEX] == null)
{
return true; return true;
} }
@ -288,84 +434,79 @@ public class TileEntityCalcinator extends TileEntityEE implements ISidedInventor
boolean rightEquals = this.inventory[OUTPUT_RIGHT_INVENTORY_INDEX].isItemEqual(alchemicalDustStack); boolean rightEquals = this.inventory[OUTPUT_RIGHT_INVENTORY_INDEX].isItemEqual(alchemicalDustStack);
int rightResult = this.inventory[OUTPUT_RIGHT_INVENTORY_INDEX].stackSize + alchemicalDustStack.stackSize; int rightResult = this.inventory[OUTPUT_RIGHT_INVENTORY_INDEX].stackSize + alchemicalDustStack.stackSize;
if (!leftEquals && !rightEquals) { if (!leftEquals && !rightEquals)
{
return false; return false;
} else if (leftEquals && !rightEquals) { }
else if (leftEquals && !rightEquals)
{
return leftResult <= getInventoryStackLimit() && leftResult <= alchemicalDustStack.getMaxStackSize(); return leftResult <= getInventoryStackLimit() && leftResult <= alchemicalDustStack.getMaxStackSize();
} else if (!leftEquals) { }
else if (!leftEquals)
{
return rightResult <= getInventoryStackLimit() && rightResult <= alchemicalDustStack.getMaxStackSize(); return rightResult <= getInventoryStackLimit() && rightResult <= alchemicalDustStack.getMaxStackSize();
} else { }
else
{
return leftResult <= getInventoryStackLimit() && leftResult <= alchemicalDustStack.getMaxStackSize() || rightResult <= getInventoryStackLimit() && rightResult <= alchemicalDustStack.getMaxStackSize(); return leftResult <= getInventoryStackLimit() && leftResult <= alchemicalDustStack.getMaxStackSize() || rightResult <= getInventoryStackLimit() && rightResult <= alchemicalDustStack.getMaxStackSize();
} }
} }
} }
private void addItemStackToOutput(ItemStack alchemicalDustStack) { public void calcinateItem()
{
if (this.canCalcinate())
{
ItemStack alchemicalDustStack = CalcinationHelper.getCalcinationResult(this.inventory[INPUT_INVENTORY_INDEX]);
addItemStackToOutput(alchemicalDustStack.copy());
this.inventory[INPUT_INVENTORY_INDEX].stackSize--;
if (this.inventory[INPUT_INVENTORY_INDEX].stackSize <= 0)
{
this.inventory[INPUT_INVENTORY_INDEX] = null;
}
}
}
public static boolean suckInItems(TileEntityCalcinator tileEntityCalcinator)
{
EntityItem entityitem = TileEntityHopper.func_145897_a(tileEntityCalcinator.getWorldObj(), tileEntityCalcinator.xCoord, tileEntityCalcinator.yCoord + 1.0D, tileEntityCalcinator.zCoord);
return entityitem != null && TileEntityHopper.func_145898_a(tileEntityCalcinator, entityitem);
}
private void addItemStackToOutput(ItemStack alchemicalDustStack)
{
int maxStackSize = Math.min(getInventoryStackLimit(), alchemicalDustStack.getMaxStackSize()); int maxStackSize = Math.min(getInventoryStackLimit(), alchemicalDustStack.getMaxStackSize());
if (this.inventory[OUTPUT_LEFT_INVENTORY_INDEX] == null) { if (this.inventory[OUTPUT_LEFT_INVENTORY_INDEX] == null)
{
this.inventory[OUTPUT_LEFT_INVENTORY_INDEX] = alchemicalDustStack; this.inventory[OUTPUT_LEFT_INVENTORY_INDEX] = alchemicalDustStack;
return; return;
} }
if (this.inventory[OUTPUT_LEFT_INVENTORY_INDEX].isItemEqual(alchemicalDustStack) if (this.inventory[OUTPUT_LEFT_INVENTORY_INDEX].isItemEqual(alchemicalDustStack)
&& this.inventory[OUTPUT_LEFT_INVENTORY_INDEX].stackSize < maxStackSize) { && this.inventory[OUTPUT_LEFT_INVENTORY_INDEX].stackSize < maxStackSize)
{
int addedSize = Math.min(alchemicalDustStack.stackSize, maxStackSize - this.inventory[OUTPUT_LEFT_INVENTORY_INDEX].stackSize); int addedSize = Math.min(alchemicalDustStack.stackSize, maxStackSize - this.inventory[OUTPUT_LEFT_INVENTORY_INDEX].stackSize);
alchemicalDustStack.stackSize -= addedSize; alchemicalDustStack.stackSize -= addedSize;
this.inventory[OUTPUT_LEFT_INVENTORY_INDEX].stackSize += addedSize; this.inventory[OUTPUT_LEFT_INVENTORY_INDEX].stackSize += addedSize;
if (alchemicalDustStack == null || alchemicalDustStack.stackSize == 0) { if (alchemicalDustStack == null || alchemicalDustStack.stackSize == 0)
{
return; return;
} }
} }
if (this.inventory[OUTPUT_RIGHT_INVENTORY_INDEX] == null) { if (this.inventory[OUTPUT_RIGHT_INVENTORY_INDEX] == null)
{
this.inventory[OUTPUT_RIGHT_INVENTORY_INDEX] = alchemicalDustStack; this.inventory[OUTPUT_RIGHT_INVENTORY_INDEX] = alchemicalDustStack;
return; return;
} }
if (this.inventory[OUTPUT_RIGHT_INVENTORY_INDEX].isItemEqual(alchemicalDustStack) if (this.inventory[OUTPUT_RIGHT_INVENTORY_INDEX].isItemEqual(alchemicalDustStack)
&& this.inventory[OUTPUT_RIGHT_INVENTORY_INDEX].stackSize < maxStackSize) { && this.inventory[OUTPUT_RIGHT_INVENTORY_INDEX].stackSize < maxStackSize)
{
int addedSize = Math.min(alchemicalDustStack.stackSize, maxStackSize - this.inventory[OUTPUT_RIGHT_INVENTORY_INDEX].stackSize); int addedSize = Math.min(alchemicalDustStack.stackSize, maxStackSize - this.inventory[OUTPUT_RIGHT_INVENTORY_INDEX].stackSize);
alchemicalDustStack.stackSize -= addedSize; alchemicalDustStack.stackSize -= addedSize;
this.inventory[OUTPUT_RIGHT_INVENTORY_INDEX].stackSize += addedSize; this.inventory[OUTPUT_RIGHT_INVENTORY_INDEX].stackSize += addedSize;
} }
} }
private int getLeftStackSize() {
if (this.inventory[OUTPUT_LEFT_INVENTORY_INDEX] != null) {
return this.inventory[OUTPUT_LEFT_INVENTORY_INDEX].stackSize;
}
return 0;
}
private int getLeftStackMeta() {
if (this.inventory[OUTPUT_LEFT_INVENTORY_INDEX] != null) {
return this.inventory[OUTPUT_LEFT_INVENTORY_INDEX].getItemDamage();
}
return 0;
}
private int getRightStackSize() {
if (this.inventory[OUTPUT_RIGHT_INVENTORY_INDEX] != null) {
return this.inventory[OUTPUT_RIGHT_INVENTORY_INDEX].stackSize;
}
return 0;
}
private int getRightStackMeta() {
if (this.inventory[OUTPUT_RIGHT_INVENTORY_INDEX] != null) {
return this.inventory[OUTPUT_RIGHT_INVENTORY_INDEX].getItemDamage();
}
return 0;
}
private void sendDustPileData() {
if (this.getBlockType() != null) {
this.worldObj.addBlockEvent(this.xCoord, this.yCoord, this.zCoord, this.getBlockType(), 2, getLeftStackSize());
this.worldObj.addBlockEvent(this.xCoord, this.yCoord, this.zCoord, this.getBlockType(), 3, getLeftStackMeta());
this.worldObj.addBlockEvent(this.xCoord, this.yCoord, this.zCoord, this.getBlockType(), 4, getRightStackSize());
this.worldObj.addBlockEvent(this.xCoord, this.yCoord, this.zCoord, this.getBlockType(), 5, getRightStackMeta());
}
}
} }

View file

@ -48,11 +48,6 @@ public class TileEntityEE extends TileEntity
this.state = state; this.state = state;
} }
public boolean hasCustomName()
{
return customName != null && customName.length() > 0;
}
public String getCustomName() public String getCustomName()
{ {
return customName; return customName;
@ -63,11 +58,6 @@ public class TileEntityEE extends TileEntity
this.customName = customName; this.customName = customName;
} }
public boolean hasOwner()
{
return owner != null && owner.length() > 0;
}
public String getOwner() public String getOwner()
{ {
return owner; return owner;
@ -123,6 +113,16 @@ public class TileEntityEE extends TileEntity
} }
} }
public boolean hasCustomName()
{
return customName != null && customName.length() > 0;
}
public boolean hasOwner()
{
return owner != null && owner.length() > 0;
}
@Override @Override
public Packet getDescriptionPacket() public Packet getDescriptionPacket()
{ {

View file

@ -12,7 +12,8 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList; import net.minecraft.nbt.NBTTagList;
import net.minecraft.network.Packet; import net.minecraft.network.Packet;
public class TileEntityGlassBell extends TileEntityEE implements IInventory { public class TileEntityGlassBell extends TileEntityEE implements IInventory
{
public static final int INVENTORY_SIZE = 1; public static final int INVENTORY_SIZE = 1;
public static final int DISPLAY_SLOT_INVENTORY_INDEX = 0; public static final int DISPLAY_SLOT_INVENTORY_INDEX = 0;
public ItemStack outputItemStack; public ItemStack outputItemStack;
@ -22,29 +23,57 @@ public class TileEntityGlassBell extends TileEntityEE implements IInventory {
*/ */
private ItemStack[] inventory; private ItemStack[] inventory;
public TileEntityGlassBell() { public TileEntityGlassBell()
{
inventory = new ItemStack[INVENTORY_SIZE]; inventory = new ItemStack[INVENTORY_SIZE];
} }
@Override @Override
public int getSizeInventory() { public void readFromNBT(NBTTagCompound nbtTagCompound)
{
super.readFromNBT(nbtTagCompound);
// Read in the ItemStacks in the inventory from NBT
NBTTagList tagList = nbtTagCompound.getTagList("Items", 10);
inventory = new ItemStack[this.getSizeInventory()];
for (int i = 0; i < tagList.tagCount(); ++i)
{
NBTTagCompound tagCompound = tagList.getCompoundTagAt(i);
byte slotIndex = tagCompound.getByte("Slot");
if (slotIndex >= 0 && slotIndex < inventory.length)
{
inventory[slotIndex] = ItemStack.loadItemStackFromNBT(tagCompound);
}
}
}
@Override
public int getSizeInventory()
{
return inventory.length; return inventory.length;
} }
@Override @Override
public ItemStack getStackInSlot(int slotIndex) { public ItemStack getStackInSlot(int slotIndex)
{
return inventory[slotIndex]; return inventory[slotIndex];
} }
@Override @Override
public ItemStack decrStackSize(int slotIndex, int decrementAmount) { public ItemStack decrStackSize(int slotIndex, int decrementAmount)
{
ItemStack itemStack = getStackInSlot(slotIndex); ItemStack itemStack = getStackInSlot(slotIndex);
if (itemStack != null) { if (itemStack != null)
if (itemStack.stackSize <= decrementAmount) { {
if (itemStack.stackSize <= decrementAmount)
{
setInventorySlotContents(slotIndex, null); setInventorySlotContents(slotIndex, null);
} else { }
else
{
itemStack = itemStack.splitStack(decrementAmount); itemStack = itemStack.splitStack(decrementAmount);
if (itemStack.stackSize == 0) { if (itemStack.stackSize == 0)
{
setInventorySlotContents(slotIndex, null); setInventorySlotContents(slotIndex, null);
} }
} }
@ -54,28 +83,36 @@ public class TileEntityGlassBell extends TileEntityEE implements IInventory {
} }
@Override @Override
public ItemStack getStackInSlotOnClosing(int slotIndex) { public ItemStack getStackInSlotOnClosing(int slotIndex)
{
ItemStack itemStack = getStackInSlot(slotIndex); ItemStack itemStack = getStackInSlot(slotIndex);
if (itemStack != null) { if (itemStack != null)
{
setInventorySlotContents(slotIndex, null); setInventorySlotContents(slotIndex, null);
} }
return itemStack; return itemStack;
} }
@Override @Override
public void setInventorySlotContents(int slotIndex, ItemStack itemStack) { public void setInventorySlotContents(int slotIndex, ItemStack itemStack)
{
inventory[slotIndex] = itemStack; inventory[slotIndex] = itemStack;
if (itemStack != null && itemStack.stackSize > getInventoryStackLimit()) { if (itemStack != null && itemStack.stackSize > getInventoryStackLimit())
{
itemStack.stackSize = getInventoryStackLimit(); itemStack.stackSize = getInventoryStackLimit();
} }
if (!this.worldObj.isRemote) { if (!this.worldObj.isRemote)
{
ItemStack displayStack = this.inventory[DISPLAY_SLOT_INVENTORY_INDEX]; ItemStack displayStack = this.inventory[DISPLAY_SLOT_INVENTORY_INDEX];
if (displayStack != null) { if (displayStack != null)
{
this.state = (byte) Block.getBlockFromItem(displayStack.getItem()).getLightValue(); this.state = (byte) Block.getBlockFromItem(displayStack.getItem()).getLightValue();
} else { }
else
{
this.state = 0; this.state = 0;
} }
@ -86,62 +123,56 @@ public class TileEntityGlassBell extends TileEntityEE implements IInventory {
} }
@Override @Override
public String getInventoryName() { public String getInventoryName()
{
return this.hasCustomName() ? this.getCustomName() : Names.Containers.GLASS_BELL; return this.hasCustomName() ? this.getCustomName() : Names.Containers.GLASS_BELL;
} }
@Override @Override
public boolean hasCustomInventoryName() { public boolean hasCustomInventoryName()
{
return this.hasCustomName(); return this.hasCustomName();
} }
@Override @Override
public int getInventoryStackLimit() { public int getInventoryStackLimit()
{
return 64; return 64;
} }
@Override @Override
public boolean isUseableByPlayer(EntityPlayer entityPlayer) { public boolean isUseableByPlayer(EntityPlayer entityPlayer)
{
return true; return true;
} }
@Override @Override
public void openInventory() { public void openInventory()
{
} }
@Override @Override
public void closeInventory() { public void closeInventory()
{
} }
@Override @Override
public boolean isItemValidForSlot(int slotIndex, ItemStack itemStack) { public boolean isItemValidForSlot(int slotIndex, ItemStack itemStack)
{
return true; return true;
} }
@Override @Override
public void readFromNBT(NBTTagCompound nbtTagCompound) { public void writeToNBT(NBTTagCompound nbtTagCompound)
super.readFromNBT(nbtTagCompound); {
// Read in the ItemStacks in the inventory from NBT
NBTTagList tagList = nbtTagCompound.getTagList("Items", 10);
inventory = new ItemStack[this.getSizeInventory()];
for (int i = 0; i < tagList.tagCount(); ++i) {
NBTTagCompound tagCompound = tagList.getCompoundTagAt(i);
byte slotIndex = tagCompound.getByte("Slot");
if (slotIndex >= 0 && slotIndex < inventory.length) {
inventory[slotIndex] = ItemStack.loadItemStackFromNBT(tagCompound);
}
}
}
@Override
public void writeToNBT(NBTTagCompound nbtTagCompound) {
super.writeToNBT(nbtTagCompound); super.writeToNBT(nbtTagCompound);
// Write the ItemStacks in the inventory to NBT // Write the ItemStacks in the inventory to NBT
NBTTagList tagList = new NBTTagList(); NBTTagList tagList = new NBTTagList();
for (int currentIndex = 0; currentIndex < inventory.length; ++currentIndex) { for (int currentIndex = 0; currentIndex < inventory.length; ++currentIndex)
if (inventory[currentIndex] != null) { {
if (inventory[currentIndex] != null)
{
NBTTagCompound tagCompound = new NBTTagCompound(); NBTTagCompound tagCompound = new NBTTagCompound();
tagCompound.setByte("Slot", (byte) currentIndex); tagCompound.setByte("Slot", (byte) currentIndex);
inventory[currentIndex].writeToNBT(tagCompound); inventory[currentIndex].writeToNBT(tagCompound);
@ -152,8 +183,10 @@ public class TileEntityGlassBell extends TileEntityEE implements IInventory {
} }
@Override @Override
public Packet getDescriptionPacket() { public Packet getDescriptionPacket()
if (getStackInSlot(DISPLAY_SLOT_INVENTORY_INDEX) != null && getStackInSlot(DISPLAY_SLOT_INVENTORY_INDEX).stackSize > 0) { {
if (getStackInSlot(DISPLAY_SLOT_INVENTORY_INDEX) != null && getStackInSlot(DISPLAY_SLOT_INVENTORY_INDEX).stackSize > 0)
{
return PacketHandler.INSTANCE.getPacketFrom(new MessageTileEntityGlassBell(this, getStackInSlot(DISPLAY_SLOT_INVENTORY_INDEX))); return PacketHandler.INSTANCE.getPacketFrom(new MessageTileEntityGlassBell(this, getStackInSlot(DISPLAY_SLOT_INVENTORY_INDEX)));
} }

View file

@ -8,37 +8,51 @@ import net.minecraft.item.ItemStack;
import java.util.TreeMap; import java.util.TreeMap;
public class CalcinationHelper { public class CalcinationHelper
public static ItemStack getCalcinationResult(ItemStack calcinedStack) { {
public static ItemStack getCalcinationResult(ItemStack calcinedStack)
{
ItemStack itemStack = calcinedStack.copy(); ItemStack itemStack = calcinedStack.copy();
itemStack.stackSize = 1; itemStack.stackSize = 1;
TreeMap<EnergyValue, ItemStack> sortedItems = new TreeMap<EnergyValue, ItemStack>(); TreeMap<EnergyValue, ItemStack> sortedItems = new TreeMap<EnergyValue, ItemStack>();
for (ItemStack dustStack : ItemAlchemicalDust.getAlchemicalDusts()) { for (ItemStack dustStack : ItemAlchemicalDust.getAlchemicalDusts())
{
// If the item to be calcined is an alchemical dust, return null (you cannot calcine what's already been calcined) // If the item to be calcined is an alchemical dust, return null (you cannot calcine what's already been calcined)
if (ItemHelper.equals(itemStack, dustStack)) { if (ItemHelper.equals(itemStack, dustStack))
{
return null; return null;
} }
if (EnergyValueRegistry.getInstance().hasEnergyValue(dustStack)) { if (EnergyValueRegistry.getInstance().hasEnergyValue(dustStack))
{
sortedItems.put(EnergyValueRegistry.getInstance().getEnergyValue(dustStack), dustStack); sortedItems.put(EnergyValueRegistry.getInstance().getEnergyValue(dustStack), dustStack);
} }
} }
if (EnergyValueRegistry.getInstance().hasEnergyValue(itemStack)) { if (EnergyValueRegistry.getInstance().hasEnergyValue(itemStack))
if (sortedItems.containsKey(EnergyValueRegistry.getInstance().getEnergyValue(itemStack))) { {
if (sortedItems.containsKey(EnergyValueRegistry.getInstance().getEnergyValue(itemStack)))
{
return sortedItems.get(EnergyValueRegistry.getInstance().getEnergyValue(itemStack)); return sortedItems.get(EnergyValueRegistry.getInstance().getEnergyValue(itemStack));
} else { }
else
{
sortedItems.put(EnergyValueRegistry.getInstance().getEnergyValue(itemStack), itemStack); sortedItems.put(EnergyValueRegistry.getInstance().getEnergyValue(itemStack), itemStack);
if (sortedItems.lowerEntry(EnergyValueRegistry.getInstance().getEnergyValue(itemStack)) == null) { if (sortedItems.lowerEntry(EnergyValueRegistry.getInstance().getEnergyValue(itemStack)) == null)
{
return new ItemStack(ModItems.alchemicalDust, 1, 0); return new ItemStack(ModItems.alchemicalDust, 1, 0);
} else { }
else
{
return sortedItems.lowerEntry(EnergyValueRegistry.getInstance().getEnergyValue(itemStack)).getValue(); return sortedItems.lowerEntry(EnergyValueRegistry.getInstance().getEnergyValue(itemStack)).getValue();
} }
} }
} else { }
else
{
return new ItemStack(ModItems.alchemicalDust, 1, 0); return new ItemStack(ModItems.alchemicalDust, 1, 0);
} }
} }

View file

@ -75,11 +75,8 @@ public class ItemHelper
* Compares two ItemStacks for equality, testing itemID, metaData, stackSize, and their NBTTagCompounds (if they are * Compares two ItemStacks for equality, testing itemID, metaData, stackSize, and their NBTTagCompounds (if they are
* present) * present)
* *
* @param first * @param first The first ItemStack being tested for equality
* The first ItemStack being tested for equality * @param second The second ItemStack being tested for equality
* @param second
* The second ItemStack being tested for equality
*
* @return true if the two ItemStacks are equivalent, false otherwise * @return true if the two ItemStacks are equivalent, false otherwise
*/ */
public static boolean equals(ItemStack first, ItemStack second) public static boolean equals(ItemStack first, ItemStack second)

View file

@ -8,33 +8,6 @@ import java.util.UUID;
public class NBTHelper public class NBTHelper
{ {
/**
* Initializes the NBT Tag Compound for the given ItemStack if it is null
*
* @param itemStack
* The ItemStack for which its NBT Tag Compound is being checked for initialization
*/
private static void initNBTTagCompound(ItemStack itemStack)
{
if (itemStack.stackTagCompound == null)
{
itemStack.setTagCompound(new NBTTagCompound());
}
}
public static boolean hasTag(ItemStack itemStack, String keyName)
{
return itemStack != null && itemStack.stackTagCompound != null && itemStack.stackTagCompound.hasKey(keyName);
}
public static void removeTag(ItemStack itemStack, String keyName)
{
if (itemStack.stackTagCompound != null)
{
itemStack.stackTagCompound.removeTag(keyName);
}
}
public static void clearStatefulNBTTags(ItemStack itemStack) public static void clearStatefulNBTTags(ItemStack itemStack)
{ {
if (NBTHelper.hasTag(itemStack, Names.NBT.CRAFTING_GUI_OPEN)) if (NBTHelper.hasTag(itemStack, Names.NBT.CRAFTING_GUI_OPEN))
@ -51,6 +24,19 @@ public class NBTHelper
} }
} }
public static boolean hasTag(ItemStack itemStack, String keyName)
{
return itemStack != null && itemStack.stackTagCompound != null && itemStack.stackTagCompound.hasKey(keyName);
}
public static void removeTag(ItemStack itemStack, String keyName)
{
if (itemStack.stackTagCompound != null)
{
itemStack.stackTagCompound.removeTag(keyName);
}
}
public static boolean hasUUID(ItemStack itemStack) public static boolean hasUUID(ItemStack itemStack)
{ {
return hasTag(itemStack, Names.NBT.UUID_MOST_SIG) && hasTag(itemStack, Names.NBT.UUID_LEAST_SIG); return hasTag(itemStack, Names.NBT.UUID_MOST_SIG) && hasTag(itemStack, Names.NBT.UUID_LEAST_SIG);
@ -69,6 +55,26 @@ public class NBTHelper
} }
} }
/**
* Initializes the NBT Tag Compound for the given ItemStack if it is null
*
* @param itemStack The ItemStack for which its NBT Tag Compound is being checked for initialization
*/
private static void initNBTTagCompound(ItemStack itemStack)
{
if (itemStack.stackTagCompound == null)
{
itemStack.setTagCompound(new NBTTagCompound());
}
}
public static void setLong(ItemStack itemStack, String keyName, long keyValue)
{
initNBTTagCompound(itemStack);
itemStack.stackTagCompound.setLong(keyName, keyValue);
}
// String // String
public static String getString(ItemStack itemStack, String keyName) public static String getString(ItemStack itemStack, String keyName)
{ {
@ -182,13 +188,6 @@ public class NBTHelper
return itemStack.stackTagCompound.getLong(keyName); return itemStack.stackTagCompound.getLong(keyName);
} }
public static void setLong(ItemStack itemStack, String keyName, long keyValue)
{
initNBTTagCompound(itemStack);
itemStack.stackTagCompound.setLong(keyName, keyValue);
}
// float // float
public static float getFloat(ItemStack itemStack, String keyName) public static float getFloat(ItemStack itemStack, String keyName)
{ {

View file

@ -26,9 +26,7 @@ public class RecipeHelper
/** /**
* Returns a list of elements that constitute the input in a crafting recipe * Returns a list of elements that constitute the input in a crafting recipe
* *
* @param recipe * @param recipe The IRecipe being examined
* The IRecipe being examined
*
* @return List of elements that constitute the input of the given IRecipe. Could be an ItemStack or an Arraylist * @return List of elements that constitute the input of the given IRecipe. Could be an ItemStack or an Arraylist
*/ */
public static ArrayList<WrappedStack> getRecipeInputs(IRecipe recipe) public static ArrayList<WrappedStack> getRecipeInputs(IRecipe recipe)
@ -137,9 +135,7 @@ public class RecipeHelper
/** /**
* Collates an uncollated, unsorted List of Objects into a sorted, collated List of WrappedStacks * Collates an uncollated, unsorted List of Objects into a sorted, collated List of WrappedStacks
* *
* @param uncollatedStacks * @param uncollatedStacks List of objects for collating
* List of objects for collating
*
* @return A sorted, collated List of WrappedStacks * @return A sorted, collated List of WrappedStacks
*/ */
public static List<WrappedStack> collateInputStacks(List<?> uncollatedStacks) public static List<WrappedStack> collateInputStacks(List<?> uncollatedStacks)