I really need two monitors to properly examine how this PR works and what changes I want/should make to it. Continuing tomorrow.
This commit is contained in:
parent
adc3a79490
commit
fb355b72fe
|
@ -20,12 +20,10 @@ import cpw.mods.fml.relauncher.SideOnly;
|
|||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.util.StatCollector;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class GuiTransmutationTablet extends GuiBase
|
||||
{
|
||||
private TileEntityTransmutationTablet tileEntityTransmutationTablet;
|
||||
public class GuiTransmutationTablet extends GuiBase {
|
||||
|
||||
private ContainerTransmutationTablet containerTablet;
|
||||
|
||||
private ElementTextField searchTextField;
|
||||
private ElementStatefulButton sortOptionButton;
|
||||
|
@ -33,8 +31,6 @@ public class GuiTransmutationTablet extends GuiBase
|
|||
private ElementSlider slider;
|
||||
protected int tickCount;
|
||||
|
||||
private static DecimalFormat energyValueDecimalFormat = new DecimalFormat("###,###,###,###,###.###");
|
||||
|
||||
private static final int LEFT_MOUSE_BUTTON = 0;
|
||||
private static final int RIGHT_MOUSE_BUTTON = 1;
|
||||
|
||||
|
@ -48,7 +44,7 @@ public class GuiTransmutationTablet extends GuiBase
|
|||
public GuiTransmutationTablet(InventoryPlayer inventoryPlayer, TileEntityTransmutationTablet tileEntityTransmutationTablet)
|
||||
{
|
||||
super(new ContainerTransmutationTablet(inventoryPlayer, tileEntityTransmutationTablet), Textures.Gui.TRANSMUTATION_TABLET);
|
||||
this.tileEntityTransmutationTablet = tileEntityTransmutationTablet;
|
||||
this.containerTablet = (ContainerTransmutationTablet) this.inventorySlots;
|
||||
xSize = 256;
|
||||
ySize = 256;
|
||||
}
|
||||
|
@ -159,7 +155,7 @@ public class GuiTransmutationTablet extends GuiBase
|
|||
{
|
||||
super.drawGuiContainerForegroundLayer(x, y);
|
||||
fontRendererObj.drawString(String.format("%s:", StatCollector.translateToLocal(Messages.ENERGY_VALUE)), 10, 142, Integer.parseInt(Colors.PURE_WHITE, 16));
|
||||
fontRendererObj.drawString(String.format("%s", energyValueDecimalFormat.format(tileEntityTransmutationTablet.getAvailableEnergyValue().getValue())), 10, 152, Integer.parseInt(Colors.PURE_WHITE, 16));
|
||||
fontRendererObj.drawString(String.format("%s", containerTablet.tileEntityTransmutationTablet.getAvailableEnergy()), 10, 152, Integer.parseInt(Colors.PURE_WHITE, 16));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.pahimar.ee3.inventory;
|
||||
|
||||
import com.pahimar.ee3.api.blacklist.BlacklistRegistryProxy;
|
||||
import com.pahimar.ee3.api.exchange.EnergyValue;
|
||||
import com.pahimar.ee3.api.exchange.EnergyValueRegistryProxy;
|
||||
import com.pahimar.ee3.api.knowledge.PlayerKnowledgeRegistryProxy;
|
||||
import com.pahimar.ee3.inventory.element.IElementButtonHandler;
|
||||
|
@ -27,26 +28,31 @@ import net.minecraft.inventory.ICrafting;
|
|||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class ContainerTransmutationTablet extends ContainerEE implements IElementTextFieldHandler, IElementSliderHandler, IElementButtonHandler
|
||||
{
|
||||
/**
|
||||
* FIXME Continue integrating PR#881
|
||||
*/
|
||||
public class ContainerTransmutationTablet extends ContainerEE implements IElementTextFieldHandler, IElementSliderHandler, IElementButtonHandler {
|
||||
|
||||
private InventoryTransmutationTablet inventoryTransmutationTablet;
|
||||
public final TileEntityTransmutationTablet tileEntityTransmutationTablet;
|
||||
private float energyValue;
|
||||
private final TileEntityTransmutationTablet tileEntityTransmutationTablet;
|
||||
private final World world;
|
||||
private EnergyValue energyValue;
|
||||
private String searchTerm;
|
||||
private int sortOption;
|
||||
private int sortOrder;
|
||||
private int scrollBarPosition;
|
||||
|
||||
public ContainerTransmutationTablet(InventoryPlayer inventoryPlayer, TileEntityTransmutationTablet tileEntityTransmutationTablet)
|
||||
{
|
||||
public ContainerTransmutationTablet(InventoryPlayer inventoryPlayer, TileEntityTransmutationTablet tileEntityTransmutationTablet) {
|
||||
|
||||
this.tileEntityTransmutationTablet = tileEntityTransmutationTablet;
|
||||
this.world = tileEntityTransmutationTablet.getWorldObj();
|
||||
|
||||
TreeSet<ItemStack> knownTransmutations = new TreeSet<ItemStack>(Comparators.DISPLAY_NAME_COMPARATOR);
|
||||
if (tileEntityTransmutationTablet.getStackInSlot(TileEntityTransmutationTablet.ALCHENOMICON_INDEX) != null)
|
||||
{
|
||||
if (tileEntityTransmutationTablet.getStackInSlot(TileEntityTransmutationTablet.ALCHENOMICON_INDEX) != null) {
|
||||
ItemStack itemStack = tileEntityTransmutationTablet.getStackInSlot(TileEntityTransmutationTablet.ALCHENOMICON_INDEX);
|
||||
if (itemStack.getItem() instanceof ItemAlchenomicon && ItemStackUtils.getOwnerName(itemStack) != null) {
|
||||
knownTransmutations.addAll(PlayerKnowledgeRegistryProxy.getKnownItemStacks(ItemStackUtils.getOwnerName(itemStack)));
|
||||
|
@ -56,7 +62,7 @@ public class ContainerTransmutationTablet extends ContainerEE implements IElemen
|
|||
|
||||
this.sortOption = 0;
|
||||
this.scrollBarPosition = 0;
|
||||
this.energyValue = tileEntityTransmutationTablet.getAvailableEnergyValue().getValue();
|
||||
this.energyValue = tileEntityTransmutationTablet.getAvailableEnergy();
|
||||
|
||||
this.addSlotToContainer(new SlotTabletInput(this, tileEntityTransmutationTablet, TileEntityTransmutationTablet.ITEM_INPUT_1, 62, 24));
|
||||
this.addSlotToContainer(new SlotTabletInput(this, tileEntityTransmutationTablet, TileEntityTransmutationTablet.ITEM_INPUT_2, 35, 35));
|
||||
|
@ -66,68 +72,61 @@ public class ContainerTransmutationTablet extends ContainerEE implements IElemen
|
|||
this.addSlotToContainer(new SlotTabletInput(this, tileEntityTransmutationTablet, TileEntityTransmutationTablet.ITEM_INPUT_6, 89, 87));
|
||||
this.addSlotToContainer(new SlotTabletInput(this, tileEntityTransmutationTablet, TileEntityTransmutationTablet.ITEM_INPUT_7, 98, 61));
|
||||
this.addSlotToContainer(new SlotTabletInput(this, tileEntityTransmutationTablet, TileEntityTransmutationTablet.ITEM_INPUT_8, 89, 35));
|
||||
this.addSlotToContainer(new Slot(tileEntityTransmutationTablet, TileEntityTransmutationTablet.STONE_INDEX, 62, 61)
|
||||
{
|
||||
this.addSlotToContainer(new Slot(tileEntityTransmutationTablet, TileEntityTransmutationTablet.STONE_INDEX, 62, 61) {
|
||||
@Override
|
||||
public int getSlotStackLimit()
|
||||
{
|
||||
public int getSlotStackLimit() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack itemStack)
|
||||
{
|
||||
public boolean isItemValid(ItemStack itemStack) {
|
||||
return itemStack.getItem() instanceof ItemMiniumStone || itemStack.getItem() instanceof ItemPhilosophersStone;
|
||||
}
|
||||
});
|
||||
this.addSlotToContainer(new SlotAlchenomicon(this, tileEntityTransmutationTablet, TileEntityTransmutationTablet.ALCHENOMICON_INDEX, 152, 15));
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
for (int j = 0; j < 3; j++)
|
||||
{
|
||||
for (int i = 0; i < 10; i++) {
|
||||
for (int j = 0; j < 3; j++) {
|
||||
this.addSlotToContainer(new SlotTabletOutput(this, inventoryTransmutationTablet, i * 3 + j, 175 + j * 20, 38 + i * 20));
|
||||
}
|
||||
}
|
||||
|
||||
// Add the player's inventory slots to the container
|
||||
for (int inventoryRowIndex = 0; inventoryRowIndex < PLAYER_INVENTORY_ROWS; ++inventoryRowIndex)
|
||||
{
|
||||
for (int inventoryColumnIndex = 0; inventoryColumnIndex < PLAYER_INVENTORY_COLUMNS; ++inventoryColumnIndex)
|
||||
{
|
||||
for (int inventoryRowIndex = 0; inventoryRowIndex < PLAYER_INVENTORY_ROWS; ++inventoryRowIndex) {
|
||||
for (int inventoryColumnIndex = 0; inventoryColumnIndex < PLAYER_INVENTORY_COLUMNS; ++inventoryColumnIndex) {
|
||||
this.addSlotToContainer(new Slot(inventoryPlayer, inventoryColumnIndex + inventoryRowIndex * 9 + 9, 8 + inventoryColumnIndex * 18, 164 + inventoryRowIndex * 18));
|
||||
}
|
||||
}
|
||||
|
||||
// Add the player's action bar slots to the container
|
||||
for (int actionBarSlotIndex = 0; actionBarSlotIndex < PLAYER_INVENTORY_COLUMNS; ++actionBarSlotIndex)
|
||||
{
|
||||
for (int actionBarSlotIndex = 0; actionBarSlotIndex < PLAYER_INVENTORY_COLUMNS; ++actionBarSlotIndex) {
|
||||
this.addSlotToContainer(new Slot(inventoryPlayer, actionBarSlotIndex, 8 + actionBarSlotIndex * 18, 222));
|
||||
}
|
||||
|
||||
this.updateInventory();
|
||||
updateInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer entityPlayer)
|
||||
{
|
||||
public boolean canInteractWith(EntityPlayer entityPlayer) {
|
||||
return this.tileEntityTransmutationTablet != null && this.tileEntityTransmutationTablet.isStructureValid();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detectAndSendChanges()
|
||||
{
|
||||
public void detectAndSendChanges() {
|
||||
|
||||
super.detectAndSendChanges();
|
||||
|
||||
for (Object crafter : this.crafters)
|
||||
{
|
||||
this.updateInventory();
|
||||
|
||||
for (Object crafter : this.crafters) {
|
||||
|
||||
ICrafting iCrafting = (ICrafting) crafter;
|
||||
|
||||
if (this.energyValue != this.tileEntityTransmutationTablet.getAvailableEnergyValue().getValue())
|
||||
{
|
||||
this.energyValue = this.tileEntityTransmutationTablet.getAvailableEnergyValue().getValue();
|
||||
if (this.energyValue != this.tileEntityTransmutationTablet.getAvailableEnergy().getValue()) {
|
||||
|
||||
this.energyValue = this.tileEntityTransmutationTablet.getAvailableEnergy().getValue();
|
||||
this.updateInventory();
|
||||
int energyValueAsInt = Float.floatToRawIntBits(this.tileEntityTransmutationTablet.getAvailableEnergyValue().getValue());
|
||||
int energyValueAsInt = Float.floatToRawIntBits(this.tileEntityTransmutationTablet.getAvailableEnergy().getValue());
|
||||
iCrafting.sendProgressBarUpdate(this, 0, energyValueAsInt & 0xffff);
|
||||
iCrafting.sendProgressBarUpdate(this, 1, energyValueAsInt >>> 16);
|
||||
}
|
||||
|
@ -135,54 +134,48 @@ public class ContainerTransmutationTablet extends ContainerEE implements IElemen
|
|||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void updateProgressBar(int valueType, int updatedValue)
|
||||
{
|
||||
if (valueType == 0)
|
||||
{
|
||||
public void updateProgressBar(int valueType, int updatedValue) {
|
||||
|
||||
if (valueType == 0) {
|
||||
|
||||
int energyValueAsInt = Float.floatToRawIntBits(energyValue);
|
||||
energyValueAsInt = (energyValueAsInt & 0xffff0000) | updatedValue;
|
||||
energyValue = Float.intBitsToFloat(energyValueAsInt);
|
||||
}
|
||||
else if (valueType == 1)
|
||||
{
|
||||
else if (valueType == 1) {
|
||||
|
||||
int energyValueAsInt = Float.floatToRawIntBits(energyValue);
|
||||
energyValueAsInt = (energyValueAsInt & 0xffff) | (updatedValue << 16);
|
||||
energyValue = Float.intBitsToFloat(energyValueAsInt);
|
||||
}
|
||||
else if (valueType == 2)
|
||||
{
|
||||
else if (valueType == 2) {
|
||||
sortOption = updatedValue;
|
||||
}
|
||||
else if (valueType == 3)
|
||||
{
|
||||
else if (valueType == 3) {
|
||||
scrollBarPosition = updatedValue;
|
||||
}
|
||||
else if (valueType == 4)
|
||||
{
|
||||
else if (valueType == 4) {
|
||||
sortOrder = updatedValue;
|
||||
}
|
||||
|
||||
if (valueType >= 0 && valueType <= 4)
|
||||
{
|
||||
if (valueType >= 0 && valueType <= 4) {
|
||||
updateInventory();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleElementTextFieldUpdate(String elementName, String updatedText)
|
||||
{
|
||||
if (elementName.equalsIgnoreCase("searchField"))
|
||||
{
|
||||
public void handleElementTextFieldUpdate(String elementName, String updatedText) {
|
||||
|
||||
if (elementName.equalsIgnoreCase("searchField")) {
|
||||
this.searchTerm = updatedText;
|
||||
updateInventory();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleElementSliderUpdate(String elementName, int elementValue)
|
||||
{
|
||||
if (elementName.equals("scrollBar"))
|
||||
{
|
||||
public void handleElementSliderUpdate(String elementName, int elementValue) {
|
||||
|
||||
if (elementName.equals("scrollBar")) {
|
||||
this.scrollBarPosition = elementValue;
|
||||
updateInventory();
|
||||
}
|
||||
|
@ -249,13 +242,13 @@ public class ContainerTransmutationTablet extends ContainerEE implements IElemen
|
|||
}
|
||||
|
||||
@Override
|
||||
public ItemStack transferStackInSlot(EntityPlayer entityPlayer, int slotIndex)
|
||||
{
|
||||
public ItemStack transferStackInSlot(EntityPlayer entityPlayer, int slotIndex) {
|
||||
|
||||
ItemStack itemStack = null;
|
||||
Slot slot = (Slot) inventorySlots.get(slotIndex);
|
||||
|
||||
if (slot != null && slot.getHasStack())
|
||||
{
|
||||
if (slot != null && slot.getHasStack()) {
|
||||
|
||||
ItemStack slotItemStack = slot.getStack();
|
||||
itemStack = slotItemStack.copy();
|
||||
|
||||
|
@ -264,51 +257,44 @@ public class ContainerTransmutationTablet extends ContainerEE implements IElemen
|
|||
* attempt to put it in the first available slot in the entityPlayer's
|
||||
* inventory
|
||||
*/
|
||||
if (slotIndex < TileEntityTransmutationTablet.INVENTORY_SIZE)
|
||||
{
|
||||
if (!this.mergeItemStack(slotItemStack, TileEntityTransmutationTablet.INVENTORY_SIZE, inventorySlots.size(), false))
|
||||
{
|
||||
if (slotIndex < TileEntityTransmutationTablet.INVENTORY_SIZE) {
|
||||
|
||||
if (!this.mergeItemStack(slotItemStack, TileEntityTransmutationTablet.INVENTORY_SIZE, inventorySlots.size(), false)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if (slotIndex >= TileEntityTransmutationTablet.INVENTORY_SIZE && slotIndex < 40)
|
||||
{
|
||||
if (!this.mergeTransmutedItemStack(entityPlayer, slot, slotItemStack, 40, inventorySlots.size(), false))
|
||||
{
|
||||
else if (slotIndex >= TileEntityTransmutationTablet.INVENTORY_SIZE && slotIndex < 40) {
|
||||
|
||||
if (!this.mergeTransmutedItemStack(entityPlayer, slot, slotItemStack, 40, inventorySlots.size(), false)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (slotItemStack.getItem() instanceof ItemAlchenomicon)
|
||||
{
|
||||
if (!this.mergeItemStack(slotItemStack, TileEntityTransmutationTablet.ALCHENOMICON_INDEX, TileEntityTransmutationTablet.INVENTORY_SIZE, false))
|
||||
{
|
||||
else {
|
||||
|
||||
if (slotItemStack.getItem() instanceof ItemAlchenomicon) {
|
||||
|
||||
if (!this.mergeItemStack(slotItemStack, TileEntityTransmutationTablet.ALCHENOMICON_INDEX, TileEntityTransmutationTablet.INVENTORY_SIZE, false)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if (slotItemStack.getItem() instanceof ItemMiniumStone || slotItemStack.getItem() instanceof ItemPhilosophersStone)
|
||||
{
|
||||
if (!this.mergeItemStack(slotItemStack, TileEntityTransmutationTablet.STONE_INDEX, TileEntityTransmutationTablet.INVENTORY_SIZE, false))
|
||||
{
|
||||
else if (slotItemStack.getItem() instanceof ItemMiniumStone || slotItemStack.getItem() instanceof ItemPhilosophersStone) {
|
||||
|
||||
if (!this.mergeItemStack(slotItemStack, TileEntityTransmutationTablet.STONE_INDEX, TileEntityTransmutationTablet.INVENTORY_SIZE, false)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!this.mergeItemStack(slotItemStack, TileEntityTransmutationTablet.ITEM_INPUT_1, TileEntityTransmutationTablet.INVENTORY_SIZE, false))
|
||||
{
|
||||
else {
|
||||
|
||||
if (!this.mergeItemStack(slotItemStack, TileEntityTransmutationTablet.ITEM_INPUT_1, TileEntityTransmutationTablet.INVENTORY_SIZE, false)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (slotItemStack.stackSize == 0)
|
||||
{
|
||||
if (slotItemStack.stackSize == 0) {
|
||||
slot.putStack(null);
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
slot.onSlotChanged();
|
||||
}
|
||||
}
|
||||
|
@ -316,10 +302,10 @@ public class ContainerTransmutationTablet extends ContainerEE implements IElemen
|
|||
return itemStack;
|
||||
}
|
||||
|
||||
protected boolean mergeTransmutedItemStack(EntityPlayer entityPlayer, Slot transmutationOutputSlot, ItemStack itemStack, int slotMin, int slotMax, boolean ascending) {
|
||||
private boolean mergeTransmutedItemStack(EntityPlayer entityPlayer, Slot transmutationOutputSlot, ItemStack itemStack, int slotMin, int slotMax, boolean ascending) {
|
||||
|
||||
// Calculate how many items can be transmuted
|
||||
int numCanTransmute = MathHelper.floor(this.tileEntityTransmutationTablet.getAvailableEnergyValue().getValue() / EnergyValueRegistryProxy.getEnergyValue(itemStack).getValue());
|
||||
int numCanTransmute = MathHelper.floor(this.tileEntityTransmutationTablet.getAvailableEnergy().getValue() / EnergyValueRegistryProxy.getEnergyValue(itemStack).getValue());
|
||||
int numTransmuted = 0;
|
||||
|
||||
ItemStack itemStack1 = itemStack.copy();
|
||||
|
@ -340,6 +326,7 @@ public class ContainerTransmutationTablet extends ContainerEE implements IElemen
|
|||
stackInSlot = slot.getStack();
|
||||
|
||||
if (stackInSlot == null) {
|
||||
|
||||
stackInSlot = itemStack1.copy();
|
||||
stackInSlot.stackSize = itemStack1.stackSize;
|
||||
slot.putStack(stackInSlot);
|
||||
|
@ -371,62 +358,51 @@ public class ContainerTransmutationTablet extends ContainerEE implements IElemen
|
|||
currentSlotIndex += ascending ? -1 : 1;
|
||||
}
|
||||
|
||||
// transmutationOutputSlot.onPickupFromSlot(entityPlayer, new ItemStack(itemStack.getItem(), numTransmuted));
|
||||
transmutationOutputSlot.onPickupFromSlot(entityPlayer, ItemStackUtils.clone(itemStack, numTransmuted));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleElementButtonClick(String elementName, int mouseButton)
|
||||
{
|
||||
if (elementName.equals("sortOption"))
|
||||
{
|
||||
if (mouseButton == 0)
|
||||
{
|
||||
if (sortOption == 0)
|
||||
{
|
||||
public void handleElementButtonClick(String elementName, int mouseButton) {
|
||||
|
||||
if (elementName.equals("sortOption")) {
|
||||
if (mouseButton == 0) {
|
||||
if (sortOption == 0) {
|
||||
sortOption = 1;
|
||||
}
|
||||
else if (sortOption == 1)
|
||||
{
|
||||
else if (sortOption == 1) {
|
||||
sortOption = 2;
|
||||
}
|
||||
else if (sortOption == 2)
|
||||
{
|
||||
else if (sortOption == 2) {
|
||||
sortOption = 0;
|
||||
}
|
||||
}
|
||||
else if (mouseButton == 1)
|
||||
{
|
||||
if (sortOption == 0)
|
||||
{
|
||||
else if (mouseButton == 1) {
|
||||
|
||||
if (sortOption == 0) {
|
||||
sortOption = 2;
|
||||
}
|
||||
else if (sortOption == 1)
|
||||
{
|
||||
else if (sortOption == 1) {
|
||||
sortOption = 0;
|
||||
}
|
||||
else if (sortOption == 2)
|
||||
{
|
||||
else if (sortOption == 2) {
|
||||
sortOption = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (elementName.equals("sortOrder"))
|
||||
{
|
||||
if (sortOrder == 0)
|
||||
{
|
||||
else if (elementName.equals("sortOrder")) {
|
||||
|
||||
if (sortOrder == 0) {
|
||||
sortOrder = 1;
|
||||
}
|
||||
else if (sortOrder == 1)
|
||||
{
|
||||
else if (sortOrder == 1) {
|
||||
sortOrder = 0;
|
||||
}
|
||||
}
|
||||
|
||||
for (Object crafter : this.crafters)
|
||||
{
|
||||
for (Object crafter : this.crafters) {
|
||||
|
||||
ICrafting iCrafting = (ICrafting) crafter;
|
||||
iCrafting.sendProgressBarUpdate(this, 2, sortOption);
|
||||
iCrafting.sendProgressBarUpdate(this, 4, sortOrder);
|
||||
|
@ -434,60 +410,57 @@ public class ContainerTransmutationTablet extends ContainerEE implements IElemen
|
|||
}
|
||||
|
||||
@Override
|
||||
public ItemStack slotClick(int slot, int button, int flag, EntityPlayer player)
|
||||
{
|
||||
if(button==0 && flag==6)
|
||||
{
|
||||
public ItemStack slotClick(int slot, int button, int flag, EntityPlayer player) {
|
||||
|
||||
if (button==0 && flag==6) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return super.slotClick(slot, button, flag, player);
|
||||
}
|
||||
|
||||
private class SlotAlchenomicon extends Slot
|
||||
{
|
||||
private class SlotAlchenomicon extends Slot {
|
||||
|
||||
private ContainerTransmutationTablet containerTransmutationTablet;
|
||||
private TileEntityTransmutationTablet tileEntityTransmutationTablet;
|
||||
|
||||
public SlotAlchenomicon(ContainerTransmutationTablet containerTransmutationTablet, IInventory iInventory, int slotIndex, int x, int y)
|
||||
{
|
||||
public SlotAlchenomicon(ContainerTransmutationTablet containerTransmutationTablet, IInventory iInventory, int slotIndex, int x, int y) {
|
||||
|
||||
super(iInventory, slotIndex, x, y);
|
||||
this.containerTransmutationTablet = containerTransmutationTablet;
|
||||
this.tileEntityTransmutationTablet = containerTransmutationTablet.tileEntityTransmutationTablet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlotStackLimit()
|
||||
{
|
||||
public int getSlotStackLimit() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack itemStack)
|
||||
{
|
||||
public boolean isItemValid(ItemStack itemStack) {
|
||||
return itemStack.getItem() instanceof ItemAlchenomicon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPickupFromSlot(EntityPlayer entityPlayer, ItemStack itemStack)
|
||||
{
|
||||
public void onPickupFromSlot(EntityPlayer entityPlayer, ItemStack itemStack) {
|
||||
|
||||
super.onPickupFromSlot(entityPlayer, itemStack);
|
||||
|
||||
this.containerTransmutationTablet.inventoryTransmutationTablet = new InventoryTransmutationTablet();
|
||||
this.containerTransmutationTablet.updateInventory();
|
||||
|
||||
if (!this.tileEntityTransmutationTablet.getWorldObj().isRemote && itemStack != null && itemStack.getItem() instanceof ItemAlchenomicon && ItemStackUtils.getOwnerUUID(itemStack) != null)
|
||||
{
|
||||
if (!this.tileEntityTransmutationTablet.getWorldObj().isRemote && itemStack != null && itemStack.getItem() instanceof ItemAlchenomicon && ItemStackUtils.getOwnerUUID(itemStack) != null) {
|
||||
PacketHandler.INSTANCE.sendToAllAround(new MessagePlayerKnowledge(this.containerTransmutationTablet.tileEntityTransmutationTablet, null), new NetworkRegistry.TargetPoint(this.tileEntityTransmutationTablet.getWorldObj().provider.dimensionId, (double) this.tileEntityTransmutationTablet.xCoord, (double) this.tileEntityTransmutationTablet.yCoord, (double) this.tileEntityTransmutationTablet.zCoord, 5d));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putStack(ItemStack itemStack)
|
||||
{
|
||||
public void putStack(ItemStack itemStack) {
|
||||
|
||||
super.putStack(itemStack);
|
||||
|
||||
if (!this.tileEntityTransmutationTablet.getWorldObj().isRemote && itemStack != null && itemStack.getItem() instanceof ItemAlchenomicon && ItemStackUtils.getOwnerName(itemStack) != null)
|
||||
{
|
||||
if (!this.tileEntityTransmutationTablet.getWorldObj().isRemote && itemStack != null && itemStack.getItem() instanceof ItemAlchenomicon && ItemStackUtils.getOwnerName(itemStack) != null) {
|
||||
|
||||
Set<ItemStack> knownTransmutations = PlayerKnowledgeRegistryProxy.getKnownItemStacks(ItemStackUtils.getOwnerName(itemStack));
|
||||
this.containerTransmutationTablet.inventoryTransmutationTablet = new InventoryTransmutationTablet(knownTransmutations);
|
||||
this.containerTransmutationTablet.updateInventory();
|
||||
|
@ -496,85 +469,79 @@ public class ContainerTransmutationTablet extends ContainerEE implements IElemen
|
|||
}
|
||||
}
|
||||
|
||||
private class SlotTabletOutput extends Slot
|
||||
{
|
||||
private class SlotTabletOutput extends Slot {
|
||||
|
||||
private ContainerTransmutationTablet containerTransmutationTablet;
|
||||
|
||||
public SlotTabletOutput(ContainerTransmutationTablet containerTransmutationTablet, IInventory iInventory, int slotIndex, int x, int y)
|
||||
{
|
||||
public SlotTabletOutput(ContainerTransmutationTablet containerTransmutationTablet, IInventory iInventory, int slotIndex, int x, int y) {
|
||||
|
||||
super(iInventory, slotIndex, x, y);
|
||||
this.containerTransmutationTablet = containerTransmutationTablet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack itemStack)
|
||||
{
|
||||
public boolean isItemValid(ItemStack itemStack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canTakeStack(EntityPlayer entityPlayer)
|
||||
{
|
||||
public boolean canTakeStack(EntityPlayer entityPlayer) {
|
||||
return this.getHasStack();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPickupFromSlot(EntityPlayer entityPlayer, ItemStack itemStack)
|
||||
{
|
||||
public void onPickupFromSlot(EntityPlayer entityPlayer, ItemStack itemStack) {
|
||||
|
||||
super.onPickupFromSlot(entityPlayer, itemStack);
|
||||
|
||||
if (this.getHasStack())
|
||||
{
|
||||
if (this.getHasStack()) {
|
||||
this.containerTransmutationTablet.tileEntityTransmutationTablet.consumeInventoryForEnergyValue(itemStack);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSlotChanged()
|
||||
{
|
||||
public void onSlotChanged() {
|
||||
|
||||
super.onSlotChanged();
|
||||
|
||||
if (FMLCommonHandler.instance().getEffectiveSide().isServer())
|
||||
{
|
||||
if (FMLCommonHandler.instance().getEffectiveSide().isServer()) {
|
||||
this.containerTransmutationTablet.tileEntityTransmutationTablet.updateEnergyValueFromInventory();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public boolean func_111238_b()
|
||||
{
|
||||
public boolean func_111238_b() {
|
||||
return this.getHasStack();
|
||||
}
|
||||
}
|
||||
|
||||
private class SlotTabletInput extends Slot
|
||||
{
|
||||
private class SlotTabletInput extends Slot {
|
||||
|
||||
private ContainerTransmutationTablet containerTransmutationTablet;
|
||||
|
||||
public SlotTabletInput(ContainerTransmutationTablet containerTransmutationTablet, IInventory iInventory, int slotIndex, int x, int y)
|
||||
{
|
||||
public SlotTabletInput(ContainerTransmutationTablet containerTransmutationTablet, IInventory iInventory, int slotIndex, int x, int y) {
|
||||
|
||||
super(iInventory, slotIndex, x, y);
|
||||
this.containerTransmutationTablet = containerTransmutationTablet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack itemStack)
|
||||
{
|
||||
public boolean isItemValid(ItemStack itemStack) {
|
||||
return EnergyValueRegistryProxy.hasEnergyValue(itemStack) && BlacklistRegistryProxy.isExchangeable(itemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPickupFromSlot(EntityPlayer entityPlayer, ItemStack itemStack)
|
||||
{
|
||||
public void onPickupFromSlot(EntityPlayer entityPlayer, ItemStack itemStack) {
|
||||
|
||||
super.onPickupFromSlot(entityPlayer, itemStack);
|
||||
this.containerTransmutationTablet.tileEntityTransmutationTablet.updateEnergyValueFromInventory();
|
||||
this.containerTransmutationTablet.updateInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putStack(ItemStack itemStack)
|
||||
{
|
||||
public void putStack(ItemStack itemStack) {
|
||||
|
||||
super.putStack(itemStack);
|
||||
this.containerTransmutationTablet.tileEntityTransmutationTablet.updateEnergyValueFromInventory();
|
||||
this.containerTransmutationTablet.updateInventory();
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.pahimar.ee3.network.message;
|
||||
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import com.pahimar.ee3.inventory.ContainerTransmutationTablet;
|
||||
import com.pahimar.ee3.knowledge.PlayerKnowledge;
|
||||
import com.pahimar.ee3.tileentity.TileEntityTransmutationTablet;
|
||||
import com.pahimar.ee3.util.CompressionHelper;
|
||||
|
@ -11,8 +10,8 @@ import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
|||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -95,15 +94,11 @@ public class MessagePlayerKnowledge implements IMessage, IMessageHandler<Message
|
|||
public IMessage onMessage(MessagePlayerKnowledge message, MessageContext ctx) {
|
||||
|
||||
if (message.yCoord != Integer.MIN_VALUE) {
|
||||
if (FMLClientHandler.instance().getClient().currentScreen instanceof GuiContainer) {
|
||||
|
||||
GuiContainer guiContainer = (GuiContainer) FMLClientHandler.instance().getClient().currentScreen;
|
||||
TileEntity tileEntity = FMLClientHandler.instance().getWorldClient().getTileEntity(message.xCoord, message.yCoord, message.zCoord);
|
||||
|
||||
if (guiContainer.inventorySlots instanceof ContainerTransmutationTablet) {
|
||||
if (FMLClientHandler.instance().getWorldClient().getTileEntity(message.xCoord, message.yCoord, message.zCoord) instanceof TileEntityTransmutationTablet) {
|
||||
((ContainerTransmutationTablet) guiContainer.inventorySlots).handlePlayerKnowledgeUpdate(message.playerKnowledge);
|
||||
}
|
||||
}
|
||||
if (tileEntity instanceof TileEntityTransmutationTablet) {
|
||||
((TileEntityTransmutationTablet) tileEntity).handlePlayerKnowledgeUpdate(message.playerKnowledge);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.pahimar.ee3.network.message;
|
||||
|
||||
import com.pahimar.ee3.tileentity.TileEntityAlchemyArray;
|
||||
import com.pahimar.ee3.tileentity.TileEntityTransmutationTablet;
|
||||
import cpw.mods.fml.client.FMLClientHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
|
@ -14,88 +13,77 @@ import net.minecraft.tileentity.TileEntity;
|
|||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class MessageTileEntityTransmutationTablet implements IMessage, IMessageHandler<MessageTileEntityTransmutationTablet, IMessage>
|
||||
{
|
||||
public class MessageTileEntityTransmutationTablet implements IMessage, IMessageHandler<MessageTileEntityTransmutationTablet, IMessage> {
|
||||
|
||||
public NBTTagCompound tileEntityTransmutationTabletNBT;
|
||||
|
||||
public MessageTileEntityTransmutationTablet()
|
||||
{
|
||||
|
||||
public MessageTileEntityTransmutationTablet() {
|
||||
}
|
||||
|
||||
public MessageTileEntityTransmutationTablet(TileEntityTransmutationTablet tileEntityTransmutationTablet)
|
||||
{
|
||||
public MessageTileEntityTransmutationTablet(TileEntityTransmutationTablet tileEntityTransmutationTablet) {
|
||||
|
||||
tileEntityTransmutationTabletNBT = new NBTTagCompound();
|
||||
tileEntityTransmutationTablet.writeToNBT(tileEntityTransmutationTabletNBT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf)
|
||||
{
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
|
||||
byte[] compressedNBT = null;
|
||||
int readableBytes = buf.readInt();
|
||||
|
||||
if (readableBytes > 0)
|
||||
{
|
||||
if (readableBytes > 0) {
|
||||
compressedNBT = buf.readBytes(readableBytes).array();
|
||||
}
|
||||
|
||||
if (compressedNBT != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (compressedNBT != null) {
|
||||
|
||||
try {
|
||||
this.tileEntityTransmutationTabletNBT = CompressedStreamTools.readCompressed(new ByteArrayInputStream(compressedNBT));
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf)
|
||||
{
|
||||
public void toBytes(ByteBuf buf) {
|
||||
|
||||
byte[] compressedNBT = null;
|
||||
|
||||
try
|
||||
{
|
||||
if (tileEntityTransmutationTabletNBT != null)
|
||||
{
|
||||
try {
|
||||
if (tileEntityTransmutationTabletNBT != null) {
|
||||
compressedNBT = CompressedStreamTools.compress(tileEntityTransmutationTabletNBT);
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (compressedNBT != null)
|
||||
{
|
||||
if (compressedNBT != null) {
|
||||
buf.writeInt(compressedNBT.length);
|
||||
buf.writeBytes(compressedNBT);
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
buf.writeInt(0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(MessageTileEntityTransmutationTablet message, MessageContext ctx)
|
||||
{
|
||||
if (message.tileEntityTransmutationTabletNBT != null)
|
||||
{
|
||||
TileEntityAlchemyArray tileEntityAlchemyArray = new TileEntityAlchemyArray();
|
||||
tileEntityAlchemyArray.readFromNBT(message.tileEntityTransmutationTabletNBT);
|
||||
public IMessage onMessage(MessageTileEntityTransmutationTablet message, MessageContext ctx) {
|
||||
|
||||
TileEntity tileEntity = FMLClientHandler.instance().getClient().theWorld.getTileEntity(tileEntityAlchemyArray.xCoord, tileEntityAlchemyArray.yCoord, tileEntityAlchemyArray.zCoord);
|
||||
if (message.tileEntityTransmutationTabletNBT != null) {
|
||||
|
||||
if (tileEntity instanceof TileEntityTransmutationTablet)
|
||||
{
|
||||
TileEntityTransmutationTablet tileEntityTransmutationTablet = new TileEntityTransmutationTablet();
|
||||
tileEntityTransmutationTablet.readFromNBT(message.tileEntityTransmutationTabletNBT);
|
||||
|
||||
TileEntity tileEntity = FMLClientHandler.instance().getClient().theWorld.getTileEntity(tileEntityTransmutationTablet.xCoord, tileEntityTransmutationTablet.yCoord, tileEntityTransmutationTablet.zCoord);
|
||||
|
||||
if (tileEntity instanceof TileEntityTransmutationTablet) {
|
||||
tileEntity.readFromNBT(message.tileEntityTransmutationTabletNBT);
|
||||
//NAME UPDATE
|
||||
FMLClientHandler.instance().getClient().theWorld.func_147451_t(tileEntityAlchemyArray.xCoord, tileEntityAlchemyArray.yCoord, tileEntityAlchemyArray.zCoord);
|
||||
FMLClientHandler.instance().getClient().theWorld.func_147451_t(tileEntityTransmutationTablet.xCoord, tileEntityTransmutationTablet.yCoord, tileEntityTransmutationTablet.zCoord);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ import com.pahimar.ee3.block.BlockAshInfusedStoneSlab;
|
|||
import com.pahimar.ee3.item.ItemAlchenomicon;
|
||||
import com.pahimar.ee3.item.ItemMiniumStone;
|
||||
import com.pahimar.ee3.item.ItemPhilosophersStone;
|
||||
import com.pahimar.ee3.knowledge.PlayerKnowledge;
|
||||
import com.pahimar.ee3.network.PacketHandler;
|
||||
import com.pahimar.ee3.network.message.MessageTileEntityTransmutationTablet;
|
||||
import com.pahimar.ee3.reference.Names;
|
||||
|
@ -21,8 +22,11 @@ import net.minecraft.network.Packet;
|
|||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public class TileEntityTransmutationTablet extends TileEntityEE implements ISidedInventory
|
||||
{
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
public class TileEntityTransmutationTablet extends TileEntityEE implements ISidedInventory {
|
||||
|
||||
public static final int INVENTORY_SIZE = 10;
|
||||
public static final int ITEM_INPUT_1 = 0;
|
||||
public static final int ITEM_INPUT_2 = 1;
|
||||
|
@ -35,35 +39,55 @@ public class TileEntityTransmutationTablet extends TileEntityEE implements ISide
|
|||
public static final int STONE_INDEX = 8;
|
||||
public static final int ALCHENOMICON_INDEX = 9;
|
||||
|
||||
private EnergyValue storedEnergyValue;
|
||||
private EnergyValue availableEnergyValue;
|
||||
private EnergyValue storedEnergy, availableEnergy;
|
||||
private ForgeDirection rotation;
|
||||
private ItemStack[] inventory;
|
||||
public PlayerKnowledge playerKnowledge;
|
||||
|
||||
public TileEntityTransmutationTablet() {
|
||||
|
||||
public TileEntityTransmutationTablet()
|
||||
{
|
||||
super();
|
||||
rotation = ForgeDirection.UNKNOWN;
|
||||
availableEnergyValue = new EnergyValue(0);
|
||||
storedEnergyValue = new EnergyValue(0);
|
||||
availableEnergy = new EnergyValue(0);
|
||||
storedEnergy = new EnergyValue(0);
|
||||
inventory = new ItemStack[INVENTORY_SIZE];
|
||||
}
|
||||
|
||||
public EnergyValue getAvailableEnergyValue()
|
||||
public EnergyValue getAvailableEnergy()
|
||||
{
|
||||
return availableEnergyValue;
|
||||
return availableEnergy;
|
||||
}
|
||||
|
||||
public EnergyValue getStoredEnergyValue()
|
||||
public EnergyValue getStoredEnergy()
|
||||
{
|
||||
return storedEnergyValue;
|
||||
return storedEnergy;
|
||||
}
|
||||
|
||||
public void consumeInventoryForEnergyValue(ItemStack outputItemStack)
|
||||
{
|
||||
public ForgeDirection getRotation() {
|
||||
return rotation;
|
||||
}
|
||||
|
||||
public void setRotation(ForgeDirection rotation) {
|
||||
this.rotation = rotation;
|
||||
}
|
||||
|
||||
public Set<ItemStack> getPlayerKnowledge() {
|
||||
|
||||
if (playerKnowledge != null) {
|
||||
return playerKnowledge.getKnownItemStacks();
|
||||
}
|
||||
else {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
}
|
||||
|
||||
public void handlePlayerKnowledgeUpdate(PlayerKnowledge playerKnowledge) {
|
||||
this.playerKnowledge = playerKnowledge;
|
||||
}
|
||||
|
||||
public void consumeInventoryForEnergyValue(ItemStack outputItemStack) {
|
||||
|
||||
EnergyValue outputEnergyValue = EnergyValueRegistryProxy.getEnergyValueForStack(outputItemStack);
|
||||
EnergyValue ev2 = EnergyValueRegistryProxy.getEnergyValue(outputItemStack);
|
||||
|
||||
|
||||
/**
|
||||
* Algorithm:
|
||||
|
@ -74,66 +98,50 @@ public class TileEntityTransmutationTablet extends TileEntityEE implements ISide
|
|||
* 4) Profit
|
||||
*/
|
||||
|
||||
if (this.storedEnergyValue.compareTo(outputEnergyValue) >= 0)
|
||||
{
|
||||
this.storedEnergyValue = new EnergyValue(this.storedEnergyValue.getValue() - outputEnergyValue.getValue());
|
||||
if (this.storedEnergy.compareTo(outputEnergyValue) >= 0) {
|
||||
this.storedEnergy = new EnergyValue(this.storedEnergy.getValue() - outputEnergyValue.getValue());
|
||||
}
|
||||
else
|
||||
{
|
||||
while (this.storedEnergyValue.compareTo(outputEnergyValue) < 0 && this.availableEnergyValue.compareTo(outputEnergyValue) >= 0)
|
||||
{
|
||||
for (int i = 0; i < STONE_INDEX; i++)
|
||||
{
|
||||
else {
|
||||
|
||||
while (this.storedEnergy.compareTo(outputEnergyValue) < 0 && this.availableEnergy.compareTo(outputEnergyValue) >= 0) {
|
||||
|
||||
for (int i = 0; i < STONE_INDEX; i++) {
|
||||
|
||||
ItemStack stackInSlot = getStackInSlot(i);
|
||||
if (stackInSlot != null && EnergyValueRegistryProxy.hasEnergyValue(stackInSlot))
|
||||
{
|
||||
this.storedEnergyValue = new EnergyValue(this.storedEnergyValue.getValue() + EnergyValueRegistryProxy.getEnergyValue(stackInSlot).getValue());
|
||||
if (stackInSlot != null && EnergyValueRegistryProxy.hasEnergyValue(stackInSlot)) {
|
||||
this.storedEnergy = new EnergyValue(this.storedEnergy.getValue() + EnergyValueRegistryProxy.getEnergyValue(stackInSlot).getValue());
|
||||
decrStackSize(i, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.storedEnergyValue.getValue() >= outputEnergyValue.getValue())
|
||||
{
|
||||
this.storedEnergyValue = new EnergyValue(this.storedEnergyValue.getValue() - outputEnergyValue.getValue());
|
||||
if (this.storedEnergy.getValue() >= outputEnergyValue.getValue()) {
|
||||
this.storedEnergy = new EnergyValue(this.storedEnergy.getValue() - outputEnergyValue.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
updateEnergyValueFromInventory();
|
||||
}
|
||||
|
||||
public void updateEnergyValueFromInventory()
|
||||
{
|
||||
float newEnergyValue = storedEnergyValue.getValue();
|
||||
for (int i = 0; i <= STONE_INDEX; i++)
|
||||
{
|
||||
if (inventory[i] != null && EnergyValueRegistryProxy.hasEnergyValue(inventory[i]))
|
||||
{
|
||||
public void updateEnergyValueFromInventory() {
|
||||
|
||||
float newEnergyValue = storedEnergy.getValue();
|
||||
for (int i = 0; i <= STONE_INDEX; i++) {
|
||||
if (inventory[i] != null && EnergyValueRegistryProxy.hasEnergyValue(inventory[i])) {
|
||||
newEnergyValue += EnergyValueRegistryProxy.getEnergyValueForStack(inventory[i]).getValue();
|
||||
}
|
||||
}
|
||||
this.availableEnergyValue = new EnergyValue(newEnergyValue);
|
||||
}
|
||||
|
||||
public ForgeDirection getRotation()
|
||||
{
|
||||
return rotation;
|
||||
}
|
||||
|
||||
public void setRotation(ForgeDirection rotation)
|
||||
{
|
||||
this.rotation = rotation;
|
||||
this.availableEnergy = new EnergyValue(newEnergyValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public AxisAlignedBB getRenderBoundingBox()
|
||||
{
|
||||
public AxisAlignedBB getRenderBoundingBox() {
|
||||
return AxisAlignedBB.getBoundingBox(xCoord - 1.5d, yCoord - 1, zCoord - 1.5d, xCoord + 1.5d, yCoord + 1, zCoord + 1.5d);
|
||||
}
|
||||
|
||||
public boolean isStructureValid()
|
||||
{
|
||||
public boolean isStructureValid() {
|
||||
|
||||
return ((worldObj.getBlock(xCoord - 1, yCoord, zCoord - 1) instanceof BlockAshInfusedStoneSlab && worldObj.getBlockMetadata(xCoord - 1, yCoord, zCoord - 1) == 1) &&
|
||||
(worldObj.getBlock(xCoord, yCoord, zCoord - 1) instanceof BlockAshInfusedStoneSlab && worldObj.getBlockMetadata(xCoord, yCoord, zCoord - 1) == 2) &&
|
||||
(worldObj.getBlock(xCoord + 1, yCoord, zCoord - 1) instanceof BlockAshInfusedStoneSlab && worldObj.getBlockMetadata(xCoord + 1, yCoord, zCoord - 1) == 3) &&
|
||||
|
@ -145,60 +153,53 @@ public class TileEntityTransmutationTablet extends TileEntityEE implements ISide
|
|||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity()
|
||||
{
|
||||
public void updateEntity() {
|
||||
|
||||
super.updateEntity();
|
||||
updateEnergyValueFromInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Packet getDescriptionPacket()
|
||||
{
|
||||
public Packet getDescriptionPacket() {
|
||||
return PacketHandler.INSTANCE.getPacketFrom(new MessageTileEntityTransmutationTablet(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbtTagCompound)
|
||||
{
|
||||
public void readFromNBT(NBTTagCompound nbtTagCompound) {
|
||||
|
||||
super.readFromNBT(nbtTagCompound);
|
||||
rotation = ForgeDirection.getOrientation(nbtTagCompound.getInteger("rotation"));
|
||||
|
||||
// Read in the ItemStacks in the inventory from NBT
|
||||
NBTTagList tagList = nbtTagCompound.getTagList(Names.NBT.ITEMS, 10);
|
||||
inventory = new ItemStack[this.getSizeInventory()];
|
||||
for (int i = 0; i < tagList.tagCount(); ++i)
|
||||
{
|
||||
for (int i = 0; i < tagList.tagCount(); ++i) {
|
||||
NBTTagCompound tagCompound = tagList.getCompoundTagAt(i);
|
||||
byte slotIndex = tagCompound.getByte("Slot");
|
||||
if (slotIndex >= 0 && slotIndex < inventory.length)
|
||||
{
|
||||
if (slotIndex >= 0 && slotIndex < inventory.length) {
|
||||
inventory[slotIndex] = ItemStack.loadItemStackFromNBT(tagCompound);
|
||||
}
|
||||
}
|
||||
|
||||
NBTTagCompound energyValueTagCompound = nbtTagCompound.getCompoundTag("storedEnergyValue");
|
||||
if (!energyValueTagCompound.hasNoTags())
|
||||
{
|
||||
storedEnergyValue = EnergyValue.loadEnergyValueFromNBT(energyValueTagCompound);
|
||||
NBTTagCompound energyValueTagCompound = nbtTagCompound.getCompoundTag("storedEnergy");
|
||||
if (!energyValueTagCompound.hasNoTags()) {
|
||||
storedEnergy = EnergyValue.loadEnergyValueFromNBT(energyValueTagCompound);
|
||||
}
|
||||
else
|
||||
{
|
||||
storedEnergyValue = new EnergyValue(0);
|
||||
else {
|
||||
storedEnergy = new EnergyValue(0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbtTagCompound)
|
||||
{
|
||||
public void writeToNBT(NBTTagCompound nbtTagCompound) {
|
||||
|
||||
super.writeToNBT(nbtTagCompound);
|
||||
nbtTagCompound.setInteger("rotation", rotation.ordinal());
|
||||
|
||||
// Write the ItemStacks in the inventory to NBT
|
||||
NBTTagList tagList = new NBTTagList();
|
||||
for (int currentIndex = 0; currentIndex < inventory.length; ++currentIndex)
|
||||
{
|
||||
if (inventory[currentIndex] != null)
|
||||
{
|
||||
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);
|
||||
|
@ -208,11 +209,10 @@ public class TileEntityTransmutationTablet extends TileEntityEE implements ISide
|
|||
nbtTagCompound.setTag(Names.NBT.ITEMS, tagList);
|
||||
|
||||
NBTTagCompound energyValueTagCompound = new NBTTagCompound();
|
||||
if (storedEnergyValue != null)
|
||||
{
|
||||
storedEnergyValue.writeToNBT(energyValueTagCompound);
|
||||
if (storedEnergy != null) {
|
||||
storedEnergy.writeToNBT(energyValueTagCompound);
|
||||
}
|
||||
nbtTagCompound.setTag("storedEnergyValue", energyValueTagCompound);
|
||||
nbtTagCompound.setTag("storedEnergy", energyValueTagCompound);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
package com.pahimar.ee3.util.containers;
|
||||
|
||||
import com.pahimar.ee3.util.LogHelper;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* Originated from PR#881
|
||||
*/
|
||||
public abstract class LinearProgressHandler<MessageType extends Enum<MessageType>> {
|
||||
|
||||
private Class<MessageType> enumClass;
|
||||
private HashMap<Short, ProgressMessage<MessageType>> buffer;
|
||||
|
||||
public LinearProgressHandler(Class<MessageType> enumClass) {
|
||||
|
||||
this.enumClass = enumClass;
|
||||
buffer = new HashMap<>();
|
||||
}
|
||||
|
||||
public abstract void handle(ProgressMessage<MessageType> message);
|
||||
|
||||
public void handle(int messageId, int data) {
|
||||
|
||||
LogHelper.trace("Got data: {}", data);
|
||||
short id = (short)messageId;
|
||||
|
||||
ProgressMessage<MessageType> message;
|
||||
|
||||
if (buffer.containsKey(id)) {
|
||||
|
||||
message = buffer.remove(id);
|
||||
message = message.complete(data);
|
||||
LogHelper.trace("Completed message: ({}, {}, {})", message.getId(), message.getInt(), message.getFloat());
|
||||
handle(message);
|
||||
return;
|
||||
}
|
||||
|
||||
message = new ProgressMessage<>(enumClass, id, data & 0x0000ffff);
|
||||
|
||||
if (message.incomplete) {
|
||||
buffer.put(message.getId(), message);
|
||||
}
|
||||
else {
|
||||
LogHelper.trace("Instant message: ({}, {}, {})", message.getId(), message.getInt(), message.getFloat());
|
||||
handle(message);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
package com.pahimar.ee3.util.containers;
|
||||
|
||||
import com.pahimar.ee3.util.LogHelper;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.ICrafting;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Originated from PR#881
|
||||
*/
|
||||
public class ProgressMessage<MessageType extends Enum<MessageType>> {
|
||||
|
||||
Class<MessageType> enumClass;
|
||||
boolean incomplete;
|
||||
short messageId;
|
||||
int data;
|
||||
|
||||
public ProgressMessage(Class<MessageType> enumClass, short messageId, int data) {
|
||||
|
||||
this.enumClass = enumClass;
|
||||
this.incomplete = isInverted(messageId);
|
||||
this.messageId = incomplete ? invert(messageId) : messageId;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public ProgressMessage(Class<MessageType> enumClass, MessageType messageType, int data) {
|
||||
this(enumClass, (short)messageType.ordinal(), data);
|
||||
}
|
||||
|
||||
public ProgressMessage(Class<MessageType> enumClass, MessageType messageType, float data) {
|
||||
this(enumClass, (short)messageType.ordinal(), Float.floatToIntBits(data));
|
||||
}
|
||||
|
||||
public ProgressMessage<MessageType> complete(int data) {
|
||||
return new ProgressMessage<>(enumClass, messageId, this.data | (data << 16));
|
||||
}
|
||||
|
||||
public short getId() {
|
||||
return messageId;
|
||||
}
|
||||
|
||||
public MessageType getType() {
|
||||
return enumClass.getEnumConstants()[messageId];
|
||||
}
|
||||
|
||||
public int getInt() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public short getShort() {
|
||||
return (short) data;
|
||||
}
|
||||
|
||||
public float getFloat() {
|
||||
return Float.intBitsToFloat(data);
|
||||
}
|
||||
|
||||
private boolean isInverted(short messageId) {
|
||||
return messageId > Short.MAX_VALUE/2;
|
||||
}
|
||||
|
||||
private short invert(short messageId) {
|
||||
return (short)(Short.MAX_VALUE - messageId);
|
||||
}
|
||||
|
||||
public void send(Container container, List crafters) {
|
||||
|
||||
LogHelper.trace("Sending int: {}", data);
|
||||
sendAtom(container, crafters, invert(messageId), (short)(data & 0xffff));
|
||||
if ((data >>> 16) != 0) {
|
||||
sendAtom(container, crafters, messageId, (short)(data >>> 16));
|
||||
}
|
||||
}
|
||||
|
||||
private void sendAtom(Container container, List crafters, short messageId, short body) {
|
||||
|
||||
LogHelper.trace("Sending atom: {}", body);
|
||||
List<ICrafting> crafterList = (List<ICrafting>) crafters;
|
||||
for (ICrafting crafter: crafterList) {
|
||||
crafter.sendProgressBarUpdate(container, messageId, body);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue