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.entity.player.InventoryPlayer;
|
||||||
import net.minecraft.util.StatCollector;
|
import net.minecraft.util.StatCollector;
|
||||||
|
|
||||||
import java.text.DecimalFormat;
|
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
public class GuiTransmutationTablet extends GuiBase
|
public class GuiTransmutationTablet extends GuiBase {
|
||||||
{
|
|
||||||
private TileEntityTransmutationTablet tileEntityTransmutationTablet;
|
private ContainerTransmutationTablet containerTablet;
|
||||||
|
|
||||||
private ElementTextField searchTextField;
|
private ElementTextField searchTextField;
|
||||||
private ElementStatefulButton sortOptionButton;
|
private ElementStatefulButton sortOptionButton;
|
||||||
|
@ -33,8 +31,6 @@ public class GuiTransmutationTablet extends GuiBase
|
||||||
private ElementSlider slider;
|
private ElementSlider slider;
|
||||||
protected int tickCount;
|
protected int tickCount;
|
||||||
|
|
||||||
private static DecimalFormat energyValueDecimalFormat = new DecimalFormat("###,###,###,###,###.###");
|
|
||||||
|
|
||||||
private static final int LEFT_MOUSE_BUTTON = 0;
|
private static final int LEFT_MOUSE_BUTTON = 0;
|
||||||
private static final int RIGHT_MOUSE_BUTTON = 1;
|
private static final int RIGHT_MOUSE_BUTTON = 1;
|
||||||
|
|
||||||
|
@ -48,7 +44,7 @@ public class GuiTransmutationTablet extends GuiBase
|
||||||
public GuiTransmutationTablet(InventoryPlayer inventoryPlayer, TileEntityTransmutationTablet tileEntityTransmutationTablet)
|
public GuiTransmutationTablet(InventoryPlayer inventoryPlayer, TileEntityTransmutationTablet tileEntityTransmutationTablet)
|
||||||
{
|
{
|
||||||
super(new ContainerTransmutationTablet(inventoryPlayer, tileEntityTransmutationTablet), Textures.Gui.TRANSMUTATION_TABLET);
|
super(new ContainerTransmutationTablet(inventoryPlayer, tileEntityTransmutationTablet), Textures.Gui.TRANSMUTATION_TABLET);
|
||||||
this.tileEntityTransmutationTablet = tileEntityTransmutationTablet;
|
this.containerTablet = (ContainerTransmutationTablet) this.inventorySlots;
|
||||||
xSize = 256;
|
xSize = 256;
|
||||||
ySize = 256;
|
ySize = 256;
|
||||||
}
|
}
|
||||||
|
@ -159,7 +155,7 @@ public class GuiTransmutationTablet extends GuiBase
|
||||||
{
|
{
|
||||||
super.drawGuiContainerForegroundLayer(x, y);
|
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:", 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
|
@Override
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.pahimar.ee3.inventory;
|
package com.pahimar.ee3.inventory;
|
||||||
|
|
||||||
import com.pahimar.ee3.api.blacklist.BlacklistRegistryProxy;
|
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.exchange.EnergyValueRegistryProxy;
|
||||||
import com.pahimar.ee3.api.knowledge.PlayerKnowledgeRegistryProxy;
|
import com.pahimar.ee3.api.knowledge.PlayerKnowledgeRegistryProxy;
|
||||||
import com.pahimar.ee3.inventory.element.IElementButtonHandler;
|
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.IInventory;
|
||||||
import net.minecraft.inventory.Slot;
|
import net.minecraft.inventory.Slot;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
import java.util.*;
|
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;
|
private InventoryTransmutationTablet inventoryTransmutationTablet;
|
||||||
public final TileEntityTransmutationTablet tileEntityTransmutationTablet;
|
private final TileEntityTransmutationTablet tileEntityTransmutationTablet;
|
||||||
private float energyValue;
|
private final World world;
|
||||||
|
private EnergyValue energyValue;
|
||||||
private String searchTerm;
|
private String searchTerm;
|
||||||
private int sortOption;
|
private int sortOption;
|
||||||
private int sortOrder;
|
private int sortOrder;
|
||||||
private int scrollBarPosition;
|
private int scrollBarPosition;
|
||||||
|
|
||||||
public ContainerTransmutationTablet(InventoryPlayer inventoryPlayer, TileEntityTransmutationTablet tileEntityTransmutationTablet)
|
public ContainerTransmutationTablet(InventoryPlayer inventoryPlayer, TileEntityTransmutationTablet tileEntityTransmutationTablet) {
|
||||||
{
|
|
||||||
this.tileEntityTransmutationTablet = tileEntityTransmutationTablet;
|
this.tileEntityTransmutationTablet = tileEntityTransmutationTablet;
|
||||||
|
this.world = tileEntityTransmutationTablet.getWorldObj();
|
||||||
|
|
||||||
TreeSet<ItemStack> knownTransmutations = new TreeSet<ItemStack>(Comparators.DISPLAY_NAME_COMPARATOR);
|
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);
|
ItemStack itemStack = tileEntityTransmutationTablet.getStackInSlot(TileEntityTransmutationTablet.ALCHENOMICON_INDEX);
|
||||||
if (itemStack.getItem() instanceof ItemAlchenomicon && ItemStackUtils.getOwnerName(itemStack) != null) {
|
if (itemStack.getItem() instanceof ItemAlchenomicon && ItemStackUtils.getOwnerName(itemStack) != null) {
|
||||||
knownTransmutations.addAll(PlayerKnowledgeRegistryProxy.getKnownItemStacks(ItemStackUtils.getOwnerName(itemStack)));
|
knownTransmutations.addAll(PlayerKnowledgeRegistryProxy.getKnownItemStacks(ItemStackUtils.getOwnerName(itemStack)));
|
||||||
|
@ -56,7 +62,7 @@ public class ContainerTransmutationTablet extends ContainerEE implements IElemen
|
||||||
|
|
||||||
this.sortOption = 0;
|
this.sortOption = 0;
|
||||||
this.scrollBarPosition = 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_1, 62, 24));
|
||||||
this.addSlotToContainer(new SlotTabletInput(this, tileEntityTransmutationTablet, TileEntityTransmutationTablet.ITEM_INPUT_2, 35, 35));
|
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_6, 89, 87));
|
||||||
this.addSlotToContainer(new SlotTabletInput(this, tileEntityTransmutationTablet, TileEntityTransmutationTablet.ITEM_INPUT_7, 98, 61));
|
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 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
|
@Override
|
||||||
public int getSlotStackLimit()
|
public int getSlotStackLimit() {
|
||||||
{
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isItemValid(ItemStack itemStack)
|
public boolean isItemValid(ItemStack itemStack) {
|
||||||
{
|
|
||||||
return itemStack.getItem() instanceof ItemMiniumStone || itemStack.getItem() instanceof ItemPhilosophersStone;
|
return itemStack.getItem() instanceof ItemMiniumStone || itemStack.getItem() instanceof ItemPhilosophersStone;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.addSlotToContainer(new SlotAlchenomicon(this, tileEntityTransmutationTablet, TileEntityTransmutationTablet.ALCHENOMICON_INDEX, 152, 15));
|
this.addSlotToContainer(new SlotAlchenomicon(this, tileEntityTransmutationTablet, TileEntityTransmutationTablet.ALCHENOMICON_INDEX, 152, 15));
|
||||||
|
|
||||||
for (int i = 0; i < 10; i++)
|
for (int i = 0; i < 10; i++) {
|
||||||
{
|
for (int j = 0; j < 3; j++) {
|
||||||
for (int j = 0; j < 3; j++)
|
|
||||||
{
|
|
||||||
this.addSlotToContainer(new SlotTabletOutput(this, inventoryTransmutationTablet, i * 3 + j, 175 + j * 20, 38 + i * 20));
|
this.addSlotToContainer(new SlotTabletOutput(this, inventoryTransmutationTablet, i * 3 + j, 175 + j * 20, 38 + i * 20));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the player's inventory slots to the container
|
// Add the player's inventory slots to the container
|
||||||
for (int inventoryRowIndex = 0; inventoryRowIndex < PLAYER_INVENTORY_ROWS; ++inventoryRowIndex)
|
for (int inventoryRowIndex = 0; inventoryRowIndex < PLAYER_INVENTORY_ROWS; ++inventoryRowIndex) {
|
||||||
{
|
for (int inventoryColumnIndex = 0; inventoryColumnIndex < PLAYER_INVENTORY_COLUMNS; ++inventoryColumnIndex) {
|
||||||
for (int inventoryColumnIndex = 0; inventoryColumnIndex < PLAYER_INVENTORY_COLUMNS; ++inventoryColumnIndex)
|
|
||||||
{
|
|
||||||
this.addSlotToContainer(new Slot(inventoryPlayer, inventoryColumnIndex + inventoryRowIndex * 9 + 9, 8 + inventoryColumnIndex * 18, 164 + inventoryRowIndex * 18));
|
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
|
// 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.addSlotToContainer(new Slot(inventoryPlayer, actionBarSlotIndex, 8 + actionBarSlotIndex * 18, 222));
|
||||||
}
|
}
|
||||||
|
|
||||||
this.updateInventory();
|
updateInventory();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canInteractWith(EntityPlayer entityPlayer)
|
public boolean canInteractWith(EntityPlayer entityPlayer) {
|
||||||
{
|
|
||||||
return this.tileEntityTransmutationTablet != null && this.tileEntityTransmutationTablet.isStructureValid();
|
return this.tileEntityTransmutationTablet != null && this.tileEntityTransmutationTablet.isStructureValid();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void detectAndSendChanges()
|
public void detectAndSendChanges() {
|
||||||
{
|
|
||||||
super.detectAndSendChanges();
|
super.detectAndSendChanges();
|
||||||
|
|
||||||
for (Object crafter : this.crafters)
|
this.updateInventory();
|
||||||
{
|
|
||||||
|
for (Object crafter : this.crafters) {
|
||||||
|
|
||||||
ICrafting iCrafting = (ICrafting) crafter;
|
ICrafting iCrafting = (ICrafting) crafter;
|
||||||
|
|
||||||
if (this.energyValue != this.tileEntityTransmutationTablet.getAvailableEnergyValue().getValue())
|
if (this.energyValue != this.tileEntityTransmutationTablet.getAvailableEnergy().getValue()) {
|
||||||
{
|
|
||||||
this.energyValue = this.tileEntityTransmutationTablet.getAvailableEnergyValue().getValue();
|
this.energyValue = this.tileEntityTransmutationTablet.getAvailableEnergy().getValue();
|
||||||
this.updateInventory();
|
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, 0, energyValueAsInt & 0xffff);
|
||||||
iCrafting.sendProgressBarUpdate(this, 1, energyValueAsInt >>> 16);
|
iCrafting.sendProgressBarUpdate(this, 1, energyValueAsInt >>> 16);
|
||||||
}
|
}
|
||||||
|
@ -135,54 +134,48 @@ public class ContainerTransmutationTablet extends ContainerEE implements IElemen
|
||||||
}
|
}
|
||||||
|
|
||||||
@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) {
|
||||||
{
|
|
||||||
int energyValueAsInt = Float.floatToRawIntBits(energyValue);
|
int energyValueAsInt = Float.floatToRawIntBits(energyValue);
|
||||||
energyValueAsInt = (energyValueAsInt & 0xffff0000) | updatedValue;
|
energyValueAsInt = (energyValueAsInt & 0xffff0000) | updatedValue;
|
||||||
energyValue = Float.intBitsToFloat(energyValueAsInt);
|
energyValue = Float.intBitsToFloat(energyValueAsInt);
|
||||||
}
|
}
|
||||||
else if (valueType == 1)
|
else if (valueType == 1) {
|
||||||
{
|
|
||||||
int energyValueAsInt = Float.floatToRawIntBits(energyValue);
|
int energyValueAsInt = Float.floatToRawIntBits(energyValue);
|
||||||
energyValueAsInt = (energyValueAsInt & 0xffff) | (updatedValue << 16);
|
energyValueAsInt = (energyValueAsInt & 0xffff) | (updatedValue << 16);
|
||||||
energyValue = Float.intBitsToFloat(energyValueAsInt);
|
energyValue = Float.intBitsToFloat(energyValueAsInt);
|
||||||
}
|
}
|
||||||
else if (valueType == 2)
|
else if (valueType == 2) {
|
||||||
{
|
|
||||||
sortOption = updatedValue;
|
sortOption = updatedValue;
|
||||||
}
|
}
|
||||||
else if (valueType == 3)
|
else if (valueType == 3) {
|
||||||
{
|
|
||||||
scrollBarPosition = updatedValue;
|
scrollBarPosition = updatedValue;
|
||||||
}
|
}
|
||||||
else if (valueType == 4)
|
else if (valueType == 4) {
|
||||||
{
|
|
||||||
sortOrder = updatedValue;
|
sortOrder = updatedValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (valueType >= 0 && valueType <= 4)
|
if (valueType >= 0 && valueType <= 4) {
|
||||||
{
|
|
||||||
updateInventory();
|
updateInventory();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleElementTextFieldUpdate(String elementName, String updatedText)
|
public void handleElementTextFieldUpdate(String elementName, String updatedText) {
|
||||||
{
|
|
||||||
if (elementName.equalsIgnoreCase("searchField"))
|
if (elementName.equalsIgnoreCase("searchField")) {
|
||||||
{
|
|
||||||
this.searchTerm = updatedText;
|
this.searchTerm = updatedText;
|
||||||
updateInventory();
|
updateInventory();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleElementSliderUpdate(String elementName, int elementValue)
|
public void handleElementSliderUpdate(String elementName, int elementValue) {
|
||||||
{
|
|
||||||
if (elementName.equals("scrollBar"))
|
if (elementName.equals("scrollBar")) {
|
||||||
{
|
|
||||||
this.scrollBarPosition = elementValue;
|
this.scrollBarPosition = elementValue;
|
||||||
updateInventory();
|
updateInventory();
|
||||||
}
|
}
|
||||||
|
@ -249,13 +242,13 @@ public class ContainerTransmutationTablet extends ContainerEE implements IElemen
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack transferStackInSlot(EntityPlayer entityPlayer, int slotIndex)
|
public ItemStack transferStackInSlot(EntityPlayer entityPlayer, int slotIndex) {
|
||||||
{
|
|
||||||
ItemStack itemStack = null;
|
ItemStack itemStack = null;
|
||||||
Slot slot = (Slot) inventorySlots.get(slotIndex);
|
Slot slot = (Slot) inventorySlots.get(slotIndex);
|
||||||
|
|
||||||
if (slot != null && slot.getHasStack())
|
if (slot != null && slot.getHasStack()) {
|
||||||
{
|
|
||||||
ItemStack slotItemStack = slot.getStack();
|
ItemStack slotItemStack = slot.getStack();
|
||||||
itemStack = slotItemStack.copy();
|
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
|
* attempt to put it in the first available slot in the entityPlayer's
|
||||||
* inventory
|
* inventory
|
||||||
*/
|
*/
|
||||||
if (slotIndex < TileEntityTransmutationTablet.INVENTORY_SIZE)
|
if (slotIndex < TileEntityTransmutationTablet.INVENTORY_SIZE) {
|
||||||
{
|
|
||||||
if (!this.mergeItemStack(slotItemStack, TileEntityTransmutationTablet.INVENTORY_SIZE, inventorySlots.size(), false))
|
if (!this.mergeItemStack(slotItemStack, TileEntityTransmutationTablet.INVENTORY_SIZE, inventorySlots.size(), false)) {
|
||||||
{
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (slotIndex >= TileEntityTransmutationTablet.INVENTORY_SIZE && slotIndex < 40)
|
else if (slotIndex >= TileEntityTransmutationTablet.INVENTORY_SIZE && slotIndex < 40) {
|
||||||
{
|
|
||||||
if (!this.mergeTransmutedItemStack(entityPlayer, slot, slotItemStack, 40, inventorySlots.size(), false))
|
if (!this.mergeTransmutedItemStack(entityPlayer, slot, slotItemStack, 40, inventorySlots.size(), false)) {
|
||||||
{
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
if (slotItemStack.getItem() instanceof ItemAlchenomicon)
|
if (slotItemStack.getItem() instanceof ItemAlchenomicon) {
|
||||||
{
|
|
||||||
if (!this.mergeItemStack(slotItemStack, TileEntityTransmutationTablet.ALCHENOMICON_INDEX, TileEntityTransmutationTablet.INVENTORY_SIZE, false))
|
if (!this.mergeItemStack(slotItemStack, TileEntityTransmutationTablet.ALCHENOMICON_INDEX, TileEntityTransmutationTablet.INVENTORY_SIZE, false)) {
|
||||||
{
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (slotItemStack.getItem() instanceof ItemMiniumStone || slotItemStack.getItem() instanceof ItemPhilosophersStone)
|
else if (slotItemStack.getItem() instanceof ItemMiniumStone || slotItemStack.getItem() instanceof ItemPhilosophersStone) {
|
||||||
{
|
|
||||||
if (!this.mergeItemStack(slotItemStack, TileEntityTransmutationTablet.STONE_INDEX, TileEntityTransmutationTablet.INVENTORY_SIZE, false))
|
if (!this.mergeItemStack(slotItemStack, TileEntityTransmutationTablet.STONE_INDEX, TileEntityTransmutationTablet.INVENTORY_SIZE, false)) {
|
||||||
{
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
if (!this.mergeItemStack(slotItemStack, TileEntityTransmutationTablet.ITEM_INPUT_1, TileEntityTransmutationTablet.INVENTORY_SIZE, false))
|
if (!this.mergeItemStack(slotItemStack, TileEntityTransmutationTablet.ITEM_INPUT_1, TileEntityTransmutationTablet.INVENTORY_SIZE, false)) {
|
||||||
{
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (slotItemStack.stackSize == 0)
|
if (slotItemStack.stackSize == 0) {
|
||||||
{
|
|
||||||
slot.putStack(null);
|
slot.putStack(null);
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
slot.onSlotChanged();
|
slot.onSlotChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -316,10 +302,10 @@ public class ContainerTransmutationTablet extends ContainerEE implements IElemen
|
||||||
return itemStack;
|
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
|
// 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;
|
int numTransmuted = 0;
|
||||||
|
|
||||||
ItemStack itemStack1 = itemStack.copy();
|
ItemStack itemStack1 = itemStack.copy();
|
||||||
|
@ -340,6 +326,7 @@ public class ContainerTransmutationTablet extends ContainerEE implements IElemen
|
||||||
stackInSlot = slot.getStack();
|
stackInSlot = slot.getStack();
|
||||||
|
|
||||||
if (stackInSlot == null) {
|
if (stackInSlot == null) {
|
||||||
|
|
||||||
stackInSlot = itemStack1.copy();
|
stackInSlot = itemStack1.copy();
|
||||||
stackInSlot.stackSize = itemStack1.stackSize;
|
stackInSlot.stackSize = itemStack1.stackSize;
|
||||||
slot.putStack(stackInSlot);
|
slot.putStack(stackInSlot);
|
||||||
|
@ -371,62 +358,51 @@ public class ContainerTransmutationTablet extends ContainerEE implements IElemen
|
||||||
currentSlotIndex += ascending ? -1 : 1;
|
currentSlotIndex += ascending ? -1 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// transmutationOutputSlot.onPickupFromSlot(entityPlayer, new ItemStack(itemStack.getItem(), numTransmuted));
|
|
||||||
transmutationOutputSlot.onPickupFromSlot(entityPlayer, ItemStackUtils.clone(itemStack, numTransmuted));
|
transmutationOutputSlot.onPickupFromSlot(entityPlayer, ItemStackUtils.clone(itemStack, numTransmuted));
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleElementButtonClick(String elementName, int mouseButton)
|
public void handleElementButtonClick(String elementName, int mouseButton) {
|
||||||
{
|
|
||||||
if (elementName.equals("sortOption"))
|
if (elementName.equals("sortOption")) {
|
||||||
{
|
if (mouseButton == 0) {
|
||||||
if (mouseButton == 0)
|
if (sortOption == 0) {
|
||||||
{
|
|
||||||
if (sortOption == 0)
|
|
||||||
{
|
|
||||||
sortOption = 1;
|
sortOption = 1;
|
||||||
}
|
}
|
||||||
else if (sortOption == 1)
|
else if (sortOption == 1) {
|
||||||
{
|
|
||||||
sortOption = 2;
|
sortOption = 2;
|
||||||
}
|
}
|
||||||
else if (sortOption == 2)
|
else if (sortOption == 2) {
|
||||||
{
|
|
||||||
sortOption = 0;
|
sortOption = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (mouseButton == 1)
|
else if (mouseButton == 1) {
|
||||||
{
|
|
||||||
if (sortOption == 0)
|
if (sortOption == 0) {
|
||||||
{
|
|
||||||
sortOption = 2;
|
sortOption = 2;
|
||||||
}
|
}
|
||||||
else if (sortOption == 1)
|
else if (sortOption == 1) {
|
||||||
{
|
|
||||||
sortOption = 0;
|
sortOption = 0;
|
||||||
}
|
}
|
||||||
else if (sortOption == 2)
|
else if (sortOption == 2) {
|
||||||
{
|
|
||||||
sortOption = 1;
|
sortOption = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (elementName.equals("sortOrder"))
|
else if (elementName.equals("sortOrder")) {
|
||||||
{
|
|
||||||
if (sortOrder == 0)
|
if (sortOrder == 0) {
|
||||||
{
|
|
||||||
sortOrder = 1;
|
sortOrder = 1;
|
||||||
}
|
}
|
||||||
else if (sortOrder == 1)
|
else if (sortOrder == 1) {
|
||||||
{
|
|
||||||
sortOrder = 0;
|
sortOrder = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Object crafter : this.crafters)
|
for (Object crafter : this.crafters) {
|
||||||
{
|
|
||||||
ICrafting iCrafting = (ICrafting) crafter;
|
ICrafting iCrafting = (ICrafting) crafter;
|
||||||
iCrafting.sendProgressBarUpdate(this, 2, sortOption);
|
iCrafting.sendProgressBarUpdate(this, 2, sortOption);
|
||||||
iCrafting.sendProgressBarUpdate(this, 4, sortOrder);
|
iCrafting.sendProgressBarUpdate(this, 4, sortOrder);
|
||||||
|
@ -434,60 +410,57 @@ public class ContainerTransmutationTablet extends ContainerEE implements IElemen
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack slotClick(int slot, int button, int flag, EntityPlayer player)
|
public ItemStack slotClick(int slot, int button, int flag, EntityPlayer player) {
|
||||||
{
|
|
||||||
if(button==0 && flag==6)
|
if (button==0 && flag==6) {
|
||||||
{
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.slotClick(slot, button, flag, player);
|
return super.slotClick(slot, button, flag, player);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class SlotAlchenomicon extends Slot
|
private class SlotAlchenomicon extends Slot {
|
||||||
{
|
|
||||||
private ContainerTransmutationTablet containerTransmutationTablet;
|
private ContainerTransmutationTablet containerTransmutationTablet;
|
||||||
private TileEntityTransmutationTablet tileEntityTransmutationTablet;
|
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);
|
super(iInventory, slotIndex, x, y);
|
||||||
this.containerTransmutationTablet = containerTransmutationTablet;
|
this.containerTransmutationTablet = containerTransmutationTablet;
|
||||||
this.tileEntityTransmutationTablet = containerTransmutationTablet.tileEntityTransmutationTablet;
|
this.tileEntityTransmutationTablet = containerTransmutationTablet.tileEntityTransmutationTablet;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getSlotStackLimit()
|
public int getSlotStackLimit() {
|
||||||
{
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isItemValid(ItemStack itemStack)
|
public boolean isItemValid(ItemStack itemStack) {
|
||||||
{
|
|
||||||
return itemStack.getItem() instanceof ItemAlchenomicon;
|
return itemStack.getItem() instanceof ItemAlchenomicon;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPickupFromSlot(EntityPlayer entityPlayer, ItemStack itemStack)
|
public void onPickupFromSlot(EntityPlayer entityPlayer, ItemStack itemStack) {
|
||||||
{
|
|
||||||
super.onPickupFromSlot(entityPlayer, itemStack);
|
super.onPickupFromSlot(entityPlayer, itemStack);
|
||||||
|
|
||||||
this.containerTransmutationTablet.inventoryTransmutationTablet = new InventoryTransmutationTablet();
|
this.containerTransmutationTablet.inventoryTransmutationTablet = new InventoryTransmutationTablet();
|
||||||
this.containerTransmutationTablet.updateInventory();
|
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));
|
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
|
@Override
|
||||||
public void putStack(ItemStack itemStack)
|
public void putStack(ItemStack itemStack) {
|
||||||
{
|
|
||||||
super.putStack(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));
|
Set<ItemStack> knownTransmutations = PlayerKnowledgeRegistryProxy.getKnownItemStacks(ItemStackUtils.getOwnerName(itemStack));
|
||||||
this.containerTransmutationTablet.inventoryTransmutationTablet = new InventoryTransmutationTablet(knownTransmutations);
|
this.containerTransmutationTablet.inventoryTransmutationTablet = new InventoryTransmutationTablet(knownTransmutations);
|
||||||
this.containerTransmutationTablet.updateInventory();
|
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;
|
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);
|
super(iInventory, slotIndex, x, y);
|
||||||
this.containerTransmutationTablet = containerTransmutationTablet;
|
this.containerTransmutationTablet = containerTransmutationTablet;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isItemValid(ItemStack itemStack)
|
public boolean isItemValid(ItemStack itemStack) {
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canTakeStack(EntityPlayer entityPlayer)
|
public boolean canTakeStack(EntityPlayer entityPlayer) {
|
||||||
{
|
|
||||||
return this.getHasStack();
|
return this.getHasStack();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPickupFromSlot(EntityPlayer entityPlayer, ItemStack itemStack)
|
public void onPickupFromSlot(EntityPlayer entityPlayer, ItemStack itemStack) {
|
||||||
{
|
|
||||||
super.onPickupFromSlot(entityPlayer, itemStack);
|
super.onPickupFromSlot(entityPlayer, itemStack);
|
||||||
|
|
||||||
if (this.getHasStack())
|
if (this.getHasStack()) {
|
||||||
{
|
|
||||||
this.containerTransmutationTablet.tileEntityTransmutationTablet.consumeInventoryForEnergyValue(itemStack);
|
this.containerTransmutationTablet.tileEntityTransmutationTablet.consumeInventoryForEnergyValue(itemStack);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSlotChanged()
|
public void onSlotChanged() {
|
||||||
{
|
|
||||||
super.onSlotChanged();
|
super.onSlotChanged();
|
||||||
|
|
||||||
if (FMLCommonHandler.instance().getEffectiveSide().isServer())
|
if (FMLCommonHandler.instance().getEffectiveSide().isServer()) {
|
||||||
{
|
|
||||||
this.containerTransmutationTablet.tileEntityTransmutationTablet.updateEnergyValueFromInventory();
|
this.containerTransmutationTablet.tileEntityTransmutationTablet.updateEnergyValueFromInventory();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
public boolean func_111238_b()
|
public boolean func_111238_b() {
|
||||||
{
|
|
||||||
return this.getHasStack();
|
return this.getHasStack();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class SlotTabletInput extends Slot
|
private class SlotTabletInput extends Slot {
|
||||||
{
|
|
||||||
private ContainerTransmutationTablet containerTransmutationTablet;
|
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);
|
super(iInventory, slotIndex, x, y);
|
||||||
this.containerTransmutationTablet = containerTransmutationTablet;
|
this.containerTransmutationTablet = containerTransmutationTablet;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isItemValid(ItemStack itemStack)
|
public boolean isItemValid(ItemStack itemStack) {
|
||||||
{
|
|
||||||
return EnergyValueRegistryProxy.hasEnergyValue(itemStack) && BlacklistRegistryProxy.isExchangeable(itemStack);
|
return EnergyValueRegistryProxy.hasEnergyValue(itemStack) && BlacklistRegistryProxy.isExchangeable(itemStack);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPickupFromSlot(EntityPlayer entityPlayer, ItemStack itemStack)
|
public void onPickupFromSlot(EntityPlayer entityPlayer, ItemStack itemStack) {
|
||||||
{
|
|
||||||
super.onPickupFromSlot(entityPlayer, itemStack);
|
super.onPickupFromSlot(entityPlayer, itemStack);
|
||||||
this.containerTransmutationTablet.tileEntityTransmutationTablet.updateEnergyValueFromInventory();
|
this.containerTransmutationTablet.tileEntityTransmutationTablet.updateEnergyValueFromInventory();
|
||||||
this.containerTransmutationTablet.updateInventory();
|
this.containerTransmutationTablet.updateInventory();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void putStack(ItemStack itemStack)
|
public void putStack(ItemStack itemStack) {
|
||||||
{
|
|
||||||
super.putStack(itemStack);
|
super.putStack(itemStack);
|
||||||
this.containerTransmutationTablet.tileEntityTransmutationTablet.updateEnergyValueFromInventory();
|
this.containerTransmutationTablet.tileEntityTransmutationTablet.updateEnergyValueFromInventory();
|
||||||
this.containerTransmutationTablet.updateInventory();
|
this.containerTransmutationTablet.updateInventory();
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package com.pahimar.ee3.network.message;
|
package com.pahimar.ee3.network.message;
|
||||||
|
|
||||||
import com.google.gson.JsonSyntaxException;
|
import com.google.gson.JsonSyntaxException;
|
||||||
import com.pahimar.ee3.inventory.ContainerTransmutationTablet;
|
|
||||||
import com.pahimar.ee3.knowledge.PlayerKnowledge;
|
import com.pahimar.ee3.knowledge.PlayerKnowledge;
|
||||||
import com.pahimar.ee3.tileentity.TileEntityTransmutationTablet;
|
import com.pahimar.ee3.tileentity.TileEntityTransmutationTablet;
|
||||||
import com.pahimar.ee3.util.CompressionHelper;
|
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.IMessageHandler;
|
||||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.tileentity.TileEntity;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
@ -95,15 +94,11 @@ public class MessagePlayerKnowledge implements IMessage, IMessageHandler<Message
|
||||||
public IMessage onMessage(MessagePlayerKnowledge message, MessageContext ctx) {
|
public IMessage onMessage(MessagePlayerKnowledge message, MessageContext ctx) {
|
||||||
|
|
||||||
if (message.yCoord != Integer.MIN_VALUE) {
|
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 (tileEntity instanceof TileEntityTransmutationTablet) {
|
||||||
if (FMLClientHandler.instance().getWorldClient().getTileEntity(message.xCoord, message.yCoord, message.zCoord) instanceof TileEntityTransmutationTablet) {
|
((TileEntityTransmutationTablet) tileEntity).handlePlayerKnowledgeUpdate(message.playerKnowledge);
|
||||||
((ContainerTransmutationTablet) guiContainer.inventorySlots).handlePlayerKnowledgeUpdate(message.playerKnowledge);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package com.pahimar.ee3.network.message;
|
package com.pahimar.ee3.network.message;
|
||||||
|
|
||||||
import com.pahimar.ee3.tileentity.TileEntityAlchemyArray;
|
|
||||||
import com.pahimar.ee3.tileentity.TileEntityTransmutationTablet;
|
import com.pahimar.ee3.tileentity.TileEntityTransmutationTablet;
|
||||||
import cpw.mods.fml.client.FMLClientHandler;
|
import cpw.mods.fml.client.FMLClientHandler;
|
||||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||||
|
@ -14,88 +13,77 @@ import net.minecraft.tileentity.TileEntity;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public class MessageTileEntityTransmutationTablet implements IMessage, IMessageHandler<MessageTileEntityTransmutationTablet, IMessage>
|
public class MessageTileEntityTransmutationTablet implements IMessage, IMessageHandler<MessageTileEntityTransmutationTablet, IMessage> {
|
||||||
{
|
|
||||||
public NBTTagCompound tileEntityTransmutationTabletNBT;
|
public NBTTagCompound tileEntityTransmutationTabletNBT;
|
||||||
|
|
||||||
public MessageTileEntityTransmutationTablet()
|
public MessageTileEntityTransmutationTablet() {
|
||||||
{
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public MessageTileEntityTransmutationTablet(TileEntityTransmutationTablet tileEntityTransmutationTablet)
|
public MessageTileEntityTransmutationTablet(TileEntityTransmutationTablet tileEntityTransmutationTablet) {
|
||||||
{
|
|
||||||
tileEntityTransmutationTabletNBT = new NBTTagCompound();
|
tileEntityTransmutationTabletNBT = new NBTTagCompound();
|
||||||
tileEntityTransmutationTablet.writeToNBT(tileEntityTransmutationTabletNBT);
|
tileEntityTransmutationTablet.writeToNBT(tileEntityTransmutationTabletNBT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fromBytes(ByteBuf buf)
|
public void fromBytes(ByteBuf buf) {
|
||||||
{
|
|
||||||
byte[] compressedNBT = null;
|
byte[] compressedNBT = null;
|
||||||
int readableBytes = buf.readInt();
|
int readableBytes = buf.readInt();
|
||||||
|
|
||||||
if (readableBytes > 0)
|
if (readableBytes > 0) {
|
||||||
{
|
|
||||||
compressedNBT = buf.readBytes(readableBytes).array();
|
compressedNBT = buf.readBytes(readableBytes).array();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (compressedNBT != null)
|
if (compressedNBT != null) {
|
||||||
{
|
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
this.tileEntityTransmutationTabletNBT = CompressedStreamTools.readCompressed(new ByteArrayInputStream(compressedNBT));
|
this.tileEntityTransmutationTabletNBT = CompressedStreamTools.readCompressed(new ByteArrayInputStream(compressedNBT));
|
||||||
}
|
}
|
||||||
catch (IOException e)
|
catch (IOException e) {
|
||||||
{
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void toBytes(ByteBuf buf)
|
public void toBytes(ByteBuf buf) {
|
||||||
{
|
|
||||||
byte[] compressedNBT = null;
|
byte[] compressedNBT = null;
|
||||||
|
|
||||||
try
|
try {
|
||||||
{
|
if (tileEntityTransmutationTabletNBT != null) {
|
||||||
if (tileEntityTransmutationTabletNBT != null)
|
|
||||||
{
|
|
||||||
compressedNBT = CompressedStreamTools.compress(tileEntityTransmutationTabletNBT);
|
compressedNBT = CompressedStreamTools.compress(tileEntityTransmutationTabletNBT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (IOException e)
|
catch (IOException e) {
|
||||||
{
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (compressedNBT != null)
|
if (compressedNBT != null) {
|
||||||
{
|
|
||||||
buf.writeInt(compressedNBT.length);
|
buf.writeInt(compressedNBT.length);
|
||||||
buf.writeBytes(compressedNBT);
|
buf.writeBytes(compressedNBT);
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
buf.writeInt(0);
|
buf.writeInt(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IMessage onMessage(MessageTileEntityTransmutationTablet message, MessageContext ctx)
|
public IMessage onMessage(MessageTileEntityTransmutationTablet message, MessageContext ctx) {
|
||||||
{
|
|
||||||
if (message.tileEntityTransmutationTabletNBT != null)
|
|
||||||
{
|
|
||||||
TileEntityAlchemyArray tileEntityAlchemyArray = new TileEntityAlchemyArray();
|
|
||||||
tileEntityAlchemyArray.readFromNBT(message.tileEntityTransmutationTabletNBT);
|
|
||||||
|
|
||||||
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);
|
tileEntity.readFromNBT(message.tileEntityTransmutationTabletNBT);
|
||||||
//NAME UPDATE
|
//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.ItemAlchenomicon;
|
||||||
import com.pahimar.ee3.item.ItemMiniumStone;
|
import com.pahimar.ee3.item.ItemMiniumStone;
|
||||||
import com.pahimar.ee3.item.ItemPhilosophersStone;
|
import com.pahimar.ee3.item.ItemPhilosophersStone;
|
||||||
|
import com.pahimar.ee3.knowledge.PlayerKnowledge;
|
||||||
import com.pahimar.ee3.network.PacketHandler;
|
import com.pahimar.ee3.network.PacketHandler;
|
||||||
import com.pahimar.ee3.network.message.MessageTileEntityTransmutationTablet;
|
import com.pahimar.ee3.network.message.MessageTileEntityTransmutationTablet;
|
||||||
import com.pahimar.ee3.reference.Names;
|
import com.pahimar.ee3.reference.Names;
|
||||||
|
@ -21,8 +22,11 @@ import net.minecraft.network.Packet;
|
||||||
import net.minecraft.util.AxisAlignedBB;
|
import net.minecraft.util.AxisAlignedBB;
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
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 INVENTORY_SIZE = 10;
|
||||||
public static final int ITEM_INPUT_1 = 0;
|
public static final int ITEM_INPUT_1 = 0;
|
||||||
public static final int ITEM_INPUT_2 = 1;
|
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 STONE_INDEX = 8;
|
||||||
public static final int ALCHENOMICON_INDEX = 9;
|
public static final int ALCHENOMICON_INDEX = 9;
|
||||||
|
|
||||||
private EnergyValue storedEnergyValue;
|
private EnergyValue storedEnergy, availableEnergy;
|
||||||
private EnergyValue availableEnergyValue;
|
|
||||||
private ForgeDirection rotation;
|
private ForgeDirection rotation;
|
||||||
private ItemStack[] inventory;
|
private ItemStack[] inventory;
|
||||||
|
public PlayerKnowledge playerKnowledge;
|
||||||
|
|
||||||
|
public TileEntityTransmutationTablet() {
|
||||||
|
|
||||||
public TileEntityTransmutationTablet()
|
|
||||||
{
|
|
||||||
super();
|
super();
|
||||||
rotation = ForgeDirection.UNKNOWN;
|
rotation = ForgeDirection.UNKNOWN;
|
||||||
availableEnergyValue = new EnergyValue(0);
|
availableEnergy = new EnergyValue(0);
|
||||||
storedEnergyValue = new EnergyValue(0);
|
storedEnergy = new EnergyValue(0);
|
||||||
inventory = new ItemStack[INVENTORY_SIZE];
|
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 outputEnergyValue = EnergyValueRegistryProxy.getEnergyValueForStack(outputItemStack);
|
||||||
EnergyValue ev2 = EnergyValueRegistryProxy.getEnergyValue(outputItemStack);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Algorithm:
|
* Algorithm:
|
||||||
|
@ -74,66 +98,50 @@ public class TileEntityTransmutationTablet extends TileEntityEE implements ISide
|
||||||
* 4) Profit
|
* 4) Profit
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (this.storedEnergyValue.compareTo(outputEnergyValue) >= 0)
|
if (this.storedEnergy.compareTo(outputEnergyValue) >= 0) {
|
||||||
{
|
this.storedEnergy = new EnergyValue(this.storedEnergy.getValue() - outputEnergyValue.getValue());
|
||||||
this.storedEnergyValue = new EnergyValue(this.storedEnergyValue.getValue() - outputEnergyValue.getValue());
|
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
while (this.storedEnergyValue.compareTo(outputEnergyValue) < 0 && this.availableEnergyValue.compareTo(outputEnergyValue) >= 0)
|
while (this.storedEnergy.compareTo(outputEnergyValue) < 0 && this.availableEnergy.compareTo(outputEnergyValue) >= 0) {
|
||||||
{
|
|
||||||
for (int i = 0; i < STONE_INDEX; i++)
|
for (int i = 0; i < STONE_INDEX; i++) {
|
||||||
{
|
|
||||||
ItemStack stackInSlot = getStackInSlot(i);
|
ItemStack stackInSlot = getStackInSlot(i);
|
||||||
if (stackInSlot != null && EnergyValueRegistryProxy.hasEnergyValue(stackInSlot))
|
if (stackInSlot != null && EnergyValueRegistryProxy.hasEnergyValue(stackInSlot)) {
|
||||||
{
|
this.storedEnergy = new EnergyValue(this.storedEnergy.getValue() + EnergyValueRegistryProxy.getEnergyValue(stackInSlot).getValue());
|
||||||
this.storedEnergyValue = new EnergyValue(this.storedEnergyValue.getValue() + EnergyValueRegistryProxy.getEnergyValue(stackInSlot).getValue());
|
|
||||||
decrStackSize(i, 1);
|
decrStackSize(i, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.storedEnergyValue.getValue() >= outputEnergyValue.getValue())
|
if (this.storedEnergy.getValue() >= outputEnergyValue.getValue()) {
|
||||||
{
|
this.storedEnergy = new EnergyValue(this.storedEnergy.getValue() - outputEnergyValue.getValue());
|
||||||
this.storedEnergyValue = new EnergyValue(this.storedEnergyValue.getValue() - outputEnergyValue.getValue());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
updateEnergyValueFromInventory();
|
updateEnergyValueFromInventory();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateEnergyValueFromInventory()
|
public void updateEnergyValueFromInventory() {
|
||||||
{
|
|
||||||
float newEnergyValue = storedEnergyValue.getValue();
|
float newEnergyValue = storedEnergy.getValue();
|
||||||
for (int i = 0; i <= STONE_INDEX; i++)
|
for (int i = 0; i <= STONE_INDEX; i++) {
|
||||||
{
|
if (inventory[i] != null && EnergyValueRegistryProxy.hasEnergyValue(inventory[i])) {
|
||||||
if (inventory[i] != null && EnergyValueRegistryProxy.hasEnergyValue(inventory[i]))
|
|
||||||
{
|
|
||||||
newEnergyValue += EnergyValueRegistryProxy.getEnergyValueForStack(inventory[i]).getValue();
|
newEnergyValue += EnergyValueRegistryProxy.getEnergyValueForStack(inventory[i]).getValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.availableEnergyValue = new EnergyValue(newEnergyValue);
|
this.availableEnergy = new EnergyValue(newEnergyValue);
|
||||||
}
|
|
||||||
|
|
||||||
public ForgeDirection getRotation()
|
|
||||||
{
|
|
||||||
return rotation;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRotation(ForgeDirection rotation)
|
|
||||||
{
|
|
||||||
this.rotation = rotation;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SideOnly(Side.CLIENT)
|
@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);
|
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) &&
|
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, 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) &&
|
(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
|
@Override
|
||||||
public void updateEntity()
|
public void updateEntity() {
|
||||||
{
|
|
||||||
super.updateEntity();
|
super.updateEntity();
|
||||||
updateEnergyValueFromInventory();
|
updateEnergyValueFromInventory();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Packet getDescriptionPacket()
|
public Packet getDescriptionPacket() {
|
||||||
{
|
|
||||||
return PacketHandler.INSTANCE.getPacketFrom(new MessageTileEntityTransmutationTablet(this));
|
return PacketHandler.INSTANCE.getPacketFrom(new MessageTileEntityTransmutationTablet(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readFromNBT(NBTTagCompound nbtTagCompound)
|
public void readFromNBT(NBTTagCompound nbtTagCompound) {
|
||||||
{
|
|
||||||
super.readFromNBT(nbtTagCompound);
|
super.readFromNBT(nbtTagCompound);
|
||||||
rotation = ForgeDirection.getOrientation(nbtTagCompound.getInteger("rotation"));
|
rotation = ForgeDirection.getOrientation(nbtTagCompound.getInteger("rotation"));
|
||||||
|
|
||||||
// Read in the ItemStacks in the inventory from NBT
|
// Read in the ItemStacks in the inventory from NBT
|
||||||
NBTTagList tagList = nbtTagCompound.getTagList(Names.NBT.ITEMS, 10);
|
NBTTagList tagList = nbtTagCompound.getTagList(Names.NBT.ITEMS, 10);
|
||||||
inventory = new ItemStack[this.getSizeInventory()];
|
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);
|
NBTTagCompound tagCompound = tagList.getCompoundTagAt(i);
|
||||||
byte slotIndex = tagCompound.getByte("Slot");
|
byte slotIndex = tagCompound.getByte("Slot");
|
||||||
if (slotIndex >= 0 && slotIndex < inventory.length)
|
if (slotIndex >= 0 && slotIndex < inventory.length) {
|
||||||
{
|
|
||||||
inventory[slotIndex] = ItemStack.loadItemStackFromNBT(tagCompound);
|
inventory[slotIndex] = ItemStack.loadItemStackFromNBT(tagCompound);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NBTTagCompound energyValueTagCompound = nbtTagCompound.getCompoundTag("storedEnergyValue");
|
NBTTagCompound energyValueTagCompound = nbtTagCompound.getCompoundTag("storedEnergy");
|
||||||
if (!energyValueTagCompound.hasNoTags())
|
if (!energyValueTagCompound.hasNoTags()) {
|
||||||
{
|
storedEnergy = EnergyValue.loadEnergyValueFromNBT(energyValueTagCompound);
|
||||||
storedEnergyValue = EnergyValue.loadEnergyValueFromNBT(energyValueTagCompound);
|
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
storedEnergy = new EnergyValue(0);
|
||||||
storedEnergyValue = new EnergyValue(0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeToNBT(NBTTagCompound nbtTagCompound)
|
public void writeToNBT(NBTTagCompound nbtTagCompound) {
|
||||||
{
|
|
||||||
super.writeToNBT(nbtTagCompound);
|
super.writeToNBT(nbtTagCompound);
|
||||||
nbtTagCompound.setInteger("rotation", rotation.ordinal());
|
nbtTagCompound.setInteger("rotation", rotation.ordinal());
|
||||||
|
|
||||||
// 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);
|
||||||
|
@ -208,11 +209,10 @@ public class TileEntityTransmutationTablet extends TileEntityEE implements ISide
|
||||||
nbtTagCompound.setTag(Names.NBT.ITEMS, tagList);
|
nbtTagCompound.setTag(Names.NBT.ITEMS, tagList);
|
||||||
|
|
||||||
NBTTagCompound energyValueTagCompound = new NBTTagCompound();
|
NBTTagCompound energyValueTagCompound = new NBTTagCompound();
|
||||||
if (storedEnergyValue != null)
|
if (storedEnergy != null) {
|
||||||
{
|
storedEnergy.writeToNBT(energyValueTagCompound);
|
||||||
storedEnergyValue.writeToNBT(energyValueTagCompound);
|
|
||||||
}
|
}
|
||||||
nbtTagCompound.setTag("storedEnergyValue", energyValueTagCompound);
|
nbtTagCompound.setTag("storedEnergy", energyValueTagCompound);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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