2015-03-11 21:34:37 +01:00
|
|
|
package com.pahimar.ee3.inventory;
|
|
|
|
|
2015-05-07 19:45:06 +02:00
|
|
|
import com.pahimar.ee3.api.exchange.EnergyValueRegistryProxy;
|
2016-05-18 19:53:13 +02:00
|
|
|
import com.pahimar.ee3.api.knowledge.AbilityRegistryProxy;
|
2015-04-03 06:39:52 +02:00
|
|
|
import com.pahimar.ee3.inventory.element.IElementButtonHandler;
|
2015-04-02 07:26:01 +02:00
|
|
|
import com.pahimar.ee3.inventory.element.IElementSliderHandler;
|
|
|
|
import com.pahimar.ee3.inventory.element.IElementTextFieldHandler;
|
2015-11-28 05:07:45 +01:00
|
|
|
import com.pahimar.ee3.item.ItemAlchenomicon;
|
2015-03-19 02:52:53 +01:00
|
|
|
import com.pahimar.ee3.item.ItemMiniumStone;
|
|
|
|
import com.pahimar.ee3.item.ItemPhilosophersStone;
|
2015-04-02 07:26:01 +02:00
|
|
|
import com.pahimar.ee3.knowledge.TransmutationKnowledge;
|
|
|
|
import com.pahimar.ee3.knowledge.TransmutationKnowledgeRegistry;
|
|
|
|
import com.pahimar.ee3.network.PacketHandler;
|
|
|
|
import com.pahimar.ee3.network.message.MessageTransmutationKnowledgeUpdate;
|
2015-04-05 15:57:46 +02:00
|
|
|
import com.pahimar.ee3.reference.Comparators;
|
2015-03-19 02:52:53 +01:00
|
|
|
import com.pahimar.ee3.tileentity.TileEntityTransmutationTablet;
|
2015-04-02 07:26:01 +02:00
|
|
|
import com.pahimar.ee3.util.FilterUtils;
|
2015-03-22 03:02:35 +01:00
|
|
|
import com.pahimar.ee3.util.ItemHelper;
|
2016-05-19 03:18:24 +02:00
|
|
|
import com.pahimar.repackage.cofh.lib.util.helpers.MathHelper;
|
2015-05-01 20:21:59 +02:00
|
|
|
import cpw.mods.fml.common.FMLCommonHandler;
|
2015-04-02 07:26:01 +02:00
|
|
|
import cpw.mods.fml.common.network.NetworkRegistry;
|
2015-03-26 23:12:22 +01:00
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
2015-03-22 03:02:35 +01:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2015-03-11 21:34:37 +01:00
|
|
|
import net.minecraft.entity.player.InventoryPlayer;
|
2015-04-02 07:26:01 +02:00
|
|
|
import net.minecraft.inventory.ICrafting;
|
2015-03-24 00:10:46 +01:00
|
|
|
import net.minecraft.inventory.IInventory;
|
2015-03-11 21:34:37 +01:00
|
|
|
import net.minecraft.inventory.Slot;
|
2015-03-19 02:52:53 +01:00
|
|
|
import net.minecraft.item.ItemStack;
|
2015-03-11 21:34:37 +01:00
|
|
|
|
2015-04-02 07:26:01 +02:00
|
|
|
import java.util.*;
|
|
|
|
|
2015-04-03 06:39:52 +02:00
|
|
|
public class ContainerTransmutationTablet extends ContainerEE implements IElementTextFieldHandler, IElementSliderHandler, IElementButtonHandler
|
2015-03-11 21:34:37 +01:00
|
|
|
{
|
2015-04-02 07:26:01 +02:00
|
|
|
private InventoryTransmutationTablet inventoryTransmutationTablet;
|
2015-04-03 01:30:02 +02:00
|
|
|
public final TileEntityTransmutationTablet tileEntityTransmutationTablet;
|
2015-04-02 07:26:01 +02:00
|
|
|
private float energyValue;
|
2015-03-19 02:52:53 +01:00
|
|
|
private String searchTerm;
|
2015-05-03 20:12:18 +02:00
|
|
|
private int sortOption;
|
2015-05-05 03:08:06 +02:00
|
|
|
private int sortOrder;
|
2015-04-05 15:57:46 +02:00
|
|
|
private int scrollBarPosition;
|
2015-03-19 02:52:53 +01:00
|
|
|
|
|
|
|
public ContainerTransmutationTablet(InventoryPlayer inventoryPlayer, TileEntityTransmutationTablet tileEntityTransmutationTablet)
|
2015-03-11 21:34:37 +01:00
|
|
|
{
|
2015-03-19 02:52:53 +01:00
|
|
|
this.tileEntityTransmutationTablet = tileEntityTransmutationTablet;
|
|
|
|
|
2015-05-05 04:36:39 +02:00
|
|
|
TreeSet<ItemStack> knownTransmutations = new TreeSet<ItemStack>(Comparators.displayNameComparator);
|
2015-11-28 05:07:45 +01:00
|
|
|
if (tileEntityTransmutationTablet.getStackInSlot(TileEntityTransmutationTablet.ALCHENOMICON_INDEX) != null)
|
2015-03-19 02:52:53 +01:00
|
|
|
{
|
2015-11-28 05:07:45 +01:00
|
|
|
ItemStack itemStack = tileEntityTransmutationTablet.getStackInSlot(TileEntityTransmutationTablet.ALCHENOMICON_INDEX);
|
|
|
|
if (itemStack.getItem() instanceof ItemAlchenomicon && ItemHelper.hasOwnerUUID(itemStack))
|
2015-03-19 02:52:53 +01:00
|
|
|
{
|
2015-04-02 07:26:01 +02:00
|
|
|
knownTransmutations.addAll(TransmutationKnowledgeRegistry.getInstance().getPlayersKnownTransmutations(ItemHelper.getOwnerUUID(itemStack)));
|
2015-03-19 02:52:53 +01:00
|
|
|
}
|
2015-04-02 07:26:01 +02:00
|
|
|
}
|
|
|
|
inventoryTransmutationTablet = new InventoryTransmutationTablet(knownTransmutations);
|
2015-03-19 02:52:53 +01:00
|
|
|
|
2015-05-03 20:12:18 +02:00
|
|
|
this.sortOption = 0;
|
2015-04-05 15:57:46 +02:00
|
|
|
this.scrollBarPosition = 0;
|
2015-04-19 21:01:35 +02:00
|
|
|
this.energyValue = tileEntityTransmutationTablet.getAvailableEnergyValue().getValue();
|
2015-04-02 07:26:01 +02:00
|
|
|
|
|
|
|
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_3, 26, 61));
|
|
|
|
this.addSlotToContainer(new SlotTabletInput(this, tileEntityTransmutationTablet, TileEntityTransmutationTablet.ITEM_INPUT_4, 35, 87));
|
|
|
|
this.addSlotToContainer(new SlotTabletInput(this, tileEntityTransmutationTablet, TileEntityTransmutationTablet.ITEM_INPUT_5, 62, 99));
|
|
|
|
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)
|
2015-03-19 02:52:53 +01:00
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public int getSlotStackLimit()
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isItemValid(ItemStack itemStack)
|
|
|
|
{
|
2015-04-02 07:26:01 +02:00
|
|
|
return itemStack.getItem() instanceof ItemMiniumStone || itemStack.getItem() instanceof ItemPhilosophersStone;
|
2015-03-26 23:12:22 +01:00
|
|
|
}
|
2015-03-19 02:52:53 +01:00
|
|
|
});
|
2015-11-28 05:07:45 +01:00
|
|
|
this.addSlotToContainer(new SlotAlchenomicon(this, tileEntityTransmutationTablet, TileEntityTransmutationTablet.ALCHENOMICON_INDEX, 152, 15));
|
2015-03-19 02:52:53 +01:00
|
|
|
|
2015-03-25 23:20:57 +01:00
|
|
|
for (int i = 0; i < 10; i++)
|
2015-03-24 22:45:14 +01:00
|
|
|
{
|
|
|
|
for (int j = 0; j < 3; j++)
|
|
|
|
{
|
2015-04-02 07:26:01 +02:00
|
|
|
this.addSlotToContainer(new SlotTabletOutput(this, inventoryTransmutationTablet, i * 3 + j, 175 + j * 20, 38 + i * 20));
|
2015-03-24 22:45:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-11 21:34:37 +01:00
|
|
|
// 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)
|
|
|
|
{
|
2015-03-25 23:20:57 +01:00
|
|
|
this.addSlotToContainer(new Slot(inventoryPlayer, inventoryColumnIndex + inventoryRowIndex * 9 + 9, 8 + inventoryColumnIndex * 18, 164 + inventoryRowIndex * 18));
|
2015-03-11 21:34:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add the player's action bar slots to the container
|
|
|
|
for (int actionBarSlotIndex = 0; actionBarSlotIndex < PLAYER_INVENTORY_COLUMNS; ++actionBarSlotIndex)
|
|
|
|
{
|
2015-03-25 23:20:57 +01:00
|
|
|
this.addSlotToContainer(new Slot(inventoryPlayer, actionBarSlotIndex, 8 + actionBarSlotIndex * 18, 222));
|
2015-03-11 21:34:37 +01:00
|
|
|
}
|
2015-04-02 07:26:01 +02:00
|
|
|
|
|
|
|
this.updateInventory();
|
2015-03-11 21:34:37 +01:00
|
|
|
}
|
2015-03-19 02:52:53 +01:00
|
|
|
|
2015-05-01 20:21:59 +02:00
|
|
|
@Override
|
|
|
|
public boolean canInteractWith(EntityPlayer entityPlayer)
|
|
|
|
{
|
|
|
|
return this.tileEntityTransmutationTablet != null && this.tileEntityTransmutationTablet.isStructureValid();
|
|
|
|
}
|
|
|
|
|
2015-03-19 02:52:53 +01:00
|
|
|
@Override
|
|
|
|
public void detectAndSendChanges()
|
|
|
|
{
|
|
|
|
super.detectAndSendChanges();
|
2015-04-02 07:26:01 +02:00
|
|
|
|
|
|
|
for (Object crafter : this.crafters)
|
|
|
|
{
|
|
|
|
ICrafting iCrafting = (ICrafting) crafter;
|
|
|
|
|
2015-04-19 21:01:35 +02:00
|
|
|
if (this.energyValue != this.tileEntityTransmutationTablet.getAvailableEnergyValue().getValue())
|
2015-04-02 07:26:01 +02:00
|
|
|
{
|
2015-04-19 21:01:35 +02:00
|
|
|
this.energyValue = this.tileEntityTransmutationTablet.getAvailableEnergyValue().getValue();
|
2015-04-02 07:26:01 +02:00
|
|
|
this.updateInventory();
|
2015-04-19 21:01:35 +02:00
|
|
|
int energyValueAsInt = Float.floatToRawIntBits(this.tileEntityTransmutationTablet.getAvailableEnergyValue().getValue());
|
2015-04-02 07:26:01 +02:00
|
|
|
iCrafting.sendProgressBarUpdate(this, 0, energyValueAsInt & 0xffff);
|
|
|
|
iCrafting.sendProgressBarUpdate(this, 1, energyValueAsInt >>> 16);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
int energyValueAsInt = Float.floatToRawIntBits(energyValue);
|
|
|
|
energyValueAsInt = (energyValueAsInt & 0xffff) | (updatedValue << 16);
|
|
|
|
energyValue = Float.intBitsToFloat(energyValueAsInt);
|
|
|
|
}
|
2015-04-03 06:39:52 +02:00
|
|
|
else if (valueType == 2)
|
|
|
|
{
|
2015-05-03 20:12:18 +02:00
|
|
|
sortOption = updatedValue;
|
2015-04-03 06:39:52 +02:00
|
|
|
}
|
2015-04-05 15:57:46 +02:00
|
|
|
else if (valueType == 3)
|
|
|
|
{
|
|
|
|
scrollBarPosition = updatedValue;
|
|
|
|
}
|
2015-05-05 04:36:39 +02:00
|
|
|
else if (valueType == 4)
|
|
|
|
{
|
|
|
|
sortOrder = updatedValue;
|
|
|
|
}
|
2015-04-02 07:26:01 +02:00
|
|
|
|
2015-05-05 04:36:39 +02:00
|
|
|
if (valueType >= 0 && valueType <= 4)
|
2015-04-02 07:26:01 +02:00
|
|
|
{
|
2015-04-03 06:39:52 +02:00
|
|
|
updateInventory();
|
2015-04-02 07:26:01 +02:00
|
|
|
}
|
2015-03-19 02:52:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-02 07:26:01 +02:00
|
|
|
public void handleElementTextFieldUpdate(String elementName, String updatedText)
|
2015-03-19 02:52:53 +01:00
|
|
|
{
|
2015-04-02 07:26:01 +02:00
|
|
|
if (elementName.equalsIgnoreCase("searchField"))
|
2015-03-19 02:52:53 +01:00
|
|
|
{
|
|
|
|
this.searchTerm = updatedText;
|
|
|
|
updateInventory();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-02 07:26:01 +02:00
|
|
|
@Override
|
|
|
|
public void handleElementSliderUpdate(String elementName, int elementValue)
|
|
|
|
{
|
2015-04-05 15:57:46 +02:00
|
|
|
if (elementName.equals("scrollBar"))
|
|
|
|
{
|
|
|
|
this.scrollBarPosition = elementValue;
|
|
|
|
updateInventory();
|
|
|
|
}
|
2015-04-02 07:26:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void handleTransmutationKnowledgeUpdate(TransmutationKnowledge transmutationKnowledge)
|
|
|
|
{
|
|
|
|
if (transmutationKnowledge != null)
|
|
|
|
{
|
|
|
|
this.inventoryTransmutationTablet = new InventoryTransmutationTablet(transmutationKnowledge.getKnownTransmutations());
|
|
|
|
this.updateInventory();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-19 02:52:53 +01:00
|
|
|
private void updateInventory()
|
|
|
|
{
|
2015-04-02 07:26:01 +02:00
|
|
|
ItemStack[] newInventory = new ItemStack[30];
|
|
|
|
|
|
|
|
Set<ItemStack> filteredSet = FilterUtils.filterByNameContains(this.inventoryTransmutationTablet.getKnownTransmutations(), searchTerm);
|
|
|
|
List<ItemStack> filteredList = new ArrayList(FilterUtils.filterByEnergyValue(filteredSet, energyValue));
|
2015-04-03 06:39:52 +02:00
|
|
|
|
2015-04-05 15:57:46 +02:00
|
|
|
int adjustedStartIndex = (int) ((scrollBarPosition / 187f) * filteredList.size());
|
|
|
|
|
2015-05-05 04:36:39 +02:00
|
|
|
if (sortOption == 0)
|
|
|
|
{
|
|
|
|
if (sortOrder == 0)
|
|
|
|
{
|
|
|
|
Collections.sort(filteredList, Comparators.displayNameComparator);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Collections.sort(filteredList, Comparators.reverseDisplayNameComparator);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (sortOption == 1)
|
|
|
|
{
|
|
|
|
if (sortOrder == 0)
|
|
|
|
{
|
|
|
|
Collections.sort(filteredList, Comparators.energyValueItemStackComparator);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Collections.sort(filteredList, Comparators.reverseEnergyValueComparator);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (sortOption == 2)
|
2015-04-03 06:39:52 +02:00
|
|
|
{
|
2015-05-05 04:36:39 +02:00
|
|
|
if (sortOrder == 0)
|
|
|
|
{
|
|
|
|
Collections.sort(filteredList, Comparators.idComparator);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Collections.sort(filteredList, Comparators.reverseIdComparator);
|
|
|
|
}
|
2015-04-03 06:39:52 +02:00
|
|
|
}
|
2015-04-02 07:26:01 +02:00
|
|
|
|
|
|
|
if (filteredList.size() <= 30)
|
|
|
|
{
|
|
|
|
newInventory = filteredList.toArray(newInventory);
|
|
|
|
}
|
2015-04-05 15:57:46 +02:00
|
|
|
else if (adjustedStartIndex + 30 <= filteredList.size())
|
|
|
|
{
|
|
|
|
newInventory = filteredList.subList(adjustedStartIndex, adjustedStartIndex + 30).toArray(newInventory);
|
|
|
|
}
|
2015-04-02 07:26:01 +02:00
|
|
|
else
|
|
|
|
{
|
2015-04-05 15:57:46 +02:00
|
|
|
newInventory = filteredList.subList(filteredList.size() - 30, filteredList.size()).toArray(newInventory);
|
2015-04-02 07:26:01 +02:00
|
|
|
}
|
2015-03-25 23:20:57 +01:00
|
|
|
|
2015-04-02 07:26:01 +02:00
|
|
|
for (int i = 0; i < 30; i++)
|
|
|
|
{
|
|
|
|
this.getSlot(i + 10).putStack(newInventory[i]);
|
|
|
|
}
|
2015-03-19 02:52:53 +01:00
|
|
|
}
|
2015-03-22 03:02:35 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public ItemStack transferStackInSlot(EntityPlayer entityPlayer, int slotIndex)
|
|
|
|
{
|
|
|
|
ItemStack itemStack = null;
|
|
|
|
Slot slot = (Slot) inventorySlots.get(slotIndex);
|
|
|
|
|
|
|
|
if (slot != null && slot.getHasStack())
|
|
|
|
{
|
|
|
|
ItemStack slotItemStack = slot.getStack();
|
|
|
|
itemStack = slotItemStack.copy();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If we are shift-clicking an item out of the Transmutation Tablet's container,
|
|
|
|
* 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))
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2015-04-21 03:16:48 +02:00
|
|
|
else if (slotIndex >= TileEntityTransmutationTablet.INVENTORY_SIZE && slotIndex < 40)
|
|
|
|
{
|
2016-05-19 03:18:24 +02:00
|
|
|
if (!this.mergeTransmutedItemStack(entityPlayer, slot, slotItemStack, 40, inventorySlots.size(), false))
|
2015-04-21 06:06:44 +02:00
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
2015-04-21 03:16:48 +02:00
|
|
|
}
|
2015-03-22 03:02:35 +01:00
|
|
|
else
|
|
|
|
{
|
2015-11-28 05:07:45 +01:00
|
|
|
if (slotItemStack.getItem() instanceof ItemAlchenomicon)
|
2015-03-22 03:02:35 +01:00
|
|
|
{
|
2015-11-28 05:07:45 +01:00
|
|
|
if (!this.mergeItemStack(slotItemStack, TileEntityTransmutationTablet.ALCHENOMICON_INDEX, TileEntityTransmutationTablet.INVENTORY_SIZE, false))
|
2015-03-22 03:02:35 +01:00
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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))
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (slotItemStack.stackSize == 0)
|
|
|
|
{
|
|
|
|
slot.putStack(null);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
slot.onSlotChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return itemStack;
|
|
|
|
}
|
2015-03-24 00:10:46 +01:00
|
|
|
|
2016-05-19 03:18:24 +02:00
|
|
|
protected 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 numTransmuted = 0;
|
|
|
|
|
|
|
|
ItemStack itemStack1 = itemStack.copy();
|
|
|
|
itemStack1.stackSize = Math.min(numCanTransmute, itemStack1.getMaxStackSize());
|
|
|
|
|
|
|
|
if (numCanTransmute <= 0) {
|
2015-04-21 06:06:44 +02:00
|
|
|
return false;
|
2015-04-21 03:16:48 +02:00
|
|
|
}
|
2015-04-21 06:06:44 +02:00
|
|
|
|
|
|
|
int currentSlotIndex = ascending ? slotMax - 1 : slotMin;
|
|
|
|
|
|
|
|
Slot slot;
|
|
|
|
ItemStack stackInSlot;
|
|
|
|
|
2016-05-19 03:18:24 +02:00
|
|
|
while (itemStack1.stackSize > 0 && (!ascending && currentSlotIndex < slotMax || ascending && currentSlotIndex >= slotMin)) {
|
2015-04-21 06:06:44 +02:00
|
|
|
|
2016-05-19 03:18:24 +02:00
|
|
|
slot = (Slot) this.inventorySlots.get(currentSlotIndex);
|
|
|
|
stackInSlot = slot.getStack();
|
2015-04-21 06:06:44 +02:00
|
|
|
|
2016-05-19 03:18:24 +02:00
|
|
|
if (stackInSlot == null) {
|
2015-04-21 06:06:44 +02:00
|
|
|
|
2016-05-19 03:18:24 +02:00
|
|
|
stackInSlot = new ItemStack(itemStack1.getItem());
|
|
|
|
stackInSlot.stackSize = itemStack1.stackSize;
|
|
|
|
slot.putStack(stackInSlot);
|
|
|
|
numTransmuted = itemStack1.stackSize;
|
|
|
|
itemStack1.stackSize = 0;
|
|
|
|
slot.onSlotChanged();
|
2015-04-21 06:06:44 +02:00
|
|
|
}
|
2016-05-19 03:18:24 +02:00
|
|
|
else if (slot.isItemValid(itemStack1) && ItemHelper.equalsIgnoreStackSize(itemStack1, stackInSlot)) {
|
2015-04-21 03:16:48 +02:00
|
|
|
|
2016-05-19 03:18:24 +02:00
|
|
|
int slotStackSizeLimit = Math.min(stackInSlot.getMaxStackSize(), slot.getSlotStackLimit());
|
|
|
|
int combinedStackSize = stackInSlot.stackSize + itemStack1.stackSize;
|
2015-04-21 06:06:44 +02:00
|
|
|
|
2016-05-19 03:18:24 +02:00
|
|
|
if (combinedStackSize <= slotStackSizeLimit) {
|
2015-04-21 06:06:44 +02:00
|
|
|
|
2016-05-19 03:18:24 +02:00
|
|
|
stackInSlot.stackSize = combinedStackSize;
|
|
|
|
numTransmuted = stackInSlot.stackSize - itemStack1.stackSize;
|
|
|
|
itemStack1.stackSize = 0;
|
2015-04-21 06:06:44 +02:00
|
|
|
slot.onSlotChanged();
|
|
|
|
}
|
2016-05-19 03:18:24 +02:00
|
|
|
else if (stackInSlot.stackSize < slotStackSizeLimit) {
|
2015-04-21 06:06:44 +02:00
|
|
|
|
2016-05-19 03:18:24 +02:00
|
|
|
itemStack1.stackSize -= slotStackSizeLimit - stackInSlot.stackSize;
|
|
|
|
stackInSlot.stackSize = slotStackSizeLimit;
|
|
|
|
numTransmuted = stackInSlot.stackSize - itemStack1.stackSize;
|
|
|
|
slot.onSlotChanged();
|
|
|
|
}
|
2015-04-21 06:06:44 +02:00
|
|
|
}
|
2016-05-19 03:18:24 +02:00
|
|
|
|
|
|
|
currentSlotIndex += ascending ? -1 : 1;
|
2015-04-21 06:06:44 +02:00
|
|
|
}
|
2016-05-19 03:18:24 +02:00
|
|
|
|
|
|
|
transmutationOutputSlot.onPickupFromSlot(entityPlayer, new ItemStack(itemStack.getItem(), numTransmuted));
|
|
|
|
|
|
|
|
return false;
|
2015-04-21 03:16:48 +02:00
|
|
|
}
|
|
|
|
|
2015-04-03 06:39:52 +02:00
|
|
|
@Override
|
|
|
|
public void handleElementButtonClick(String elementName, int mouseButton)
|
|
|
|
{
|
2015-05-03 20:12:18 +02:00
|
|
|
if (elementName.equals("sortOption"))
|
2015-04-03 06:39:52 +02:00
|
|
|
{
|
|
|
|
if (mouseButton == 0)
|
|
|
|
{
|
2015-05-03 20:12:18 +02:00
|
|
|
if (sortOption == 0)
|
2015-04-03 06:39:52 +02:00
|
|
|
{
|
2015-05-03 20:12:18 +02:00
|
|
|
sortOption = 1;
|
2015-04-03 06:39:52 +02:00
|
|
|
}
|
2015-05-03 20:12:18 +02:00
|
|
|
else if (sortOption == 1)
|
2015-04-03 06:39:52 +02:00
|
|
|
{
|
2015-05-03 20:12:18 +02:00
|
|
|
sortOption = 2;
|
2015-04-03 06:39:52 +02:00
|
|
|
}
|
2015-05-03 20:12:18 +02:00
|
|
|
else if (sortOption == 2)
|
2015-04-03 06:39:52 +02:00
|
|
|
{
|
2015-05-03 20:12:18 +02:00
|
|
|
sortOption = 0;
|
2015-04-03 06:39:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (mouseButton == 1)
|
|
|
|
{
|
2015-05-03 20:12:18 +02:00
|
|
|
if (sortOption == 0)
|
2015-04-03 06:39:52 +02:00
|
|
|
{
|
2015-05-03 20:12:18 +02:00
|
|
|
sortOption = 2;
|
2015-04-03 06:39:52 +02:00
|
|
|
}
|
2015-05-03 20:12:18 +02:00
|
|
|
else if (sortOption == 1)
|
2015-04-03 06:39:52 +02:00
|
|
|
{
|
2015-05-03 20:12:18 +02:00
|
|
|
sortOption = 0;
|
2015-04-03 06:39:52 +02:00
|
|
|
}
|
2015-05-03 20:12:18 +02:00
|
|
|
else if (sortOption == 2)
|
2015-04-03 06:39:52 +02:00
|
|
|
{
|
2015-05-03 20:12:18 +02:00
|
|
|
sortOption = 1;
|
2015-04-03 06:39:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-05-05 04:36:39 +02:00
|
|
|
else if (elementName.equals("sortOrder"))
|
2015-05-05 03:08:06 +02:00
|
|
|
{
|
2015-05-05 04:36:39 +02:00
|
|
|
if (sortOrder == 0)
|
|
|
|
{
|
|
|
|
sortOrder = 1;
|
|
|
|
}
|
|
|
|
else if (sortOrder == 1)
|
|
|
|
{
|
|
|
|
sortOrder = 0;
|
|
|
|
}
|
2015-05-05 03:08:06 +02:00
|
|
|
}
|
2015-04-05 15:57:46 +02:00
|
|
|
|
|
|
|
for (Object crafter : this.crafters)
|
|
|
|
{
|
|
|
|
ICrafting iCrafting = (ICrafting) crafter;
|
2015-05-03 20:12:18 +02:00
|
|
|
iCrafting.sendProgressBarUpdate(this, 2, sortOption);
|
2015-05-05 04:36:39 +02:00
|
|
|
iCrafting.sendProgressBarUpdate(this, 4, sortOrder);
|
2015-04-05 15:57:46 +02:00
|
|
|
}
|
2015-04-03 06:39:52 +02:00
|
|
|
}
|
|
|
|
|
2015-06-29 02:26:12 +02:00
|
|
|
@Override
|
|
|
|
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);
|
|
|
|
}
|
2015-11-28 05:07:45 +01:00
|
|
|
|
|
|
|
private class SlotAlchenomicon extends Slot
|
2015-04-02 07:26:01 +02:00
|
|
|
{
|
|
|
|
private ContainerTransmutationTablet containerTransmutationTablet;
|
|
|
|
private TileEntityTransmutationTablet tileEntityTransmutationTablet;
|
|
|
|
|
2015-11-28 05:07:45 +01:00
|
|
|
public SlotAlchenomicon(ContainerTransmutationTablet containerTransmutationTablet, IInventory iInventory, int slotIndex, int x, int y)
|
2015-04-02 07:26:01 +02:00
|
|
|
{
|
|
|
|
super(iInventory, slotIndex, x, y);
|
|
|
|
this.containerTransmutationTablet = containerTransmutationTablet;
|
|
|
|
this.tileEntityTransmutationTablet = containerTransmutationTablet.tileEntityTransmutationTablet;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getSlotStackLimit()
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isItemValid(ItemStack itemStack)
|
|
|
|
{
|
2015-11-28 05:07:45 +01:00
|
|
|
return itemStack.getItem() instanceof ItemAlchenomicon;
|
2015-04-02 07:26:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPickupFromSlot(EntityPlayer entityPlayer, ItemStack itemStack)
|
|
|
|
{
|
|
|
|
super.onPickupFromSlot(entityPlayer, itemStack);
|
|
|
|
|
2015-04-02 21:14:31 +02:00
|
|
|
this.containerTransmutationTablet.inventoryTransmutationTablet = new InventoryTransmutationTablet();
|
2015-04-02 07:26:01 +02:00
|
|
|
this.containerTransmutationTablet.updateInventory();
|
|
|
|
|
2015-11-28 05:07:45 +01:00
|
|
|
if (!this.tileEntityTransmutationTablet.getWorldObj().isRemote && itemStack != null && itemStack.getItem() instanceof ItemAlchenomicon && ItemHelper.hasOwnerUUID(itemStack))
|
2015-04-02 07:26:01 +02:00
|
|
|
{
|
2015-04-03 01:30:02 +02:00
|
|
|
PacketHandler.INSTANCE.sendToAllAround(new MessageTransmutationKnowledgeUpdate(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));
|
2015-04-02 07:26:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void putStack(ItemStack itemStack)
|
|
|
|
{
|
|
|
|
super.putStack(itemStack);
|
2015-04-03 01:30:02 +02:00
|
|
|
|
2015-11-28 05:07:45 +01:00
|
|
|
if (!this.tileEntityTransmutationTablet.getWorldObj().isRemote && itemStack != null && itemStack.getItem() instanceof ItemAlchenomicon && ItemHelper.hasOwnerUUID(itemStack))
|
2015-04-02 07:26:01 +02:00
|
|
|
{
|
2015-04-03 06:39:52 +02:00
|
|
|
Set<ItemStack> knownTransmutations = TransmutationKnowledgeRegistry.getInstance().getPlayersKnownTransmutations(ItemHelper.getOwnerUUID(itemStack));
|
|
|
|
this.containerTransmutationTablet.inventoryTransmutationTablet = new InventoryTransmutationTablet(knownTransmutations);
|
|
|
|
this.containerTransmutationTablet.updateInventory();
|
2015-04-03 01:30:02 +02:00
|
|
|
PacketHandler.INSTANCE.sendToAllAround(new MessageTransmutationKnowledgeUpdate(this.containerTransmutationTablet.tileEntityTransmutationTablet, knownTransmutations), new NetworkRegistry.TargetPoint(this.tileEntityTransmutationTablet.getWorldObj().provider.dimensionId, (double) this.tileEntityTransmutationTablet.xCoord, (double) this.tileEntityTransmutationTablet.yCoord, (double) this.tileEntityTransmutationTablet.zCoord, 5d));
|
2015-04-02 07:26:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-24 00:10:46 +01:00
|
|
|
private class SlotTabletOutput extends Slot
|
|
|
|
{
|
2015-04-02 07:26:01 +02:00
|
|
|
private ContainerTransmutationTablet containerTransmutationTablet;
|
|
|
|
|
|
|
|
public SlotTabletOutput(ContainerTransmutationTablet containerTransmutationTablet, IInventory iInventory, int slotIndex, int x, int y)
|
2015-03-24 00:10:46 +01:00
|
|
|
{
|
|
|
|
super(iInventory, slotIndex, x, y);
|
2015-04-02 07:26:01 +02:00
|
|
|
this.containerTransmutationTablet = containerTransmutationTablet;
|
2015-03-24 00:10:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isItemValid(ItemStack itemStack)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2015-04-02 07:26:01 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canTakeStack(EntityPlayer entityPlayer)
|
|
|
|
{
|
2015-05-01 20:21:59 +02:00
|
|
|
return this.getHasStack();
|
2015-04-02 07:26:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPickupFromSlot(EntityPlayer entityPlayer, ItemStack itemStack)
|
|
|
|
{
|
|
|
|
super.onPickupFromSlot(entityPlayer, itemStack);
|
2015-05-01 20:21:59 +02:00
|
|
|
|
|
|
|
if (this.getHasStack())
|
|
|
|
{
|
|
|
|
this.containerTransmutationTablet.tileEntityTransmutationTablet.consumeInventoryForEnergyValue(itemStack);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSlotChanged()
|
|
|
|
{
|
|
|
|
super.onSlotChanged();
|
|
|
|
|
|
|
|
if (FMLCommonHandler.instance().getEffectiveSide().isServer())
|
|
|
|
{
|
|
|
|
this.containerTransmutationTablet.tileEntityTransmutationTablet.updateEnergyValueFromInventory();
|
|
|
|
}
|
2015-04-02 07:26:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public boolean func_111238_b()
|
|
|
|
{
|
|
|
|
return this.getHasStack();
|
|
|
|
}
|
2015-03-24 00:10:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private class SlotTabletInput extends Slot
|
|
|
|
{
|
2015-04-02 07:26:01 +02:00
|
|
|
private ContainerTransmutationTablet containerTransmutationTablet;
|
|
|
|
|
|
|
|
public SlotTabletInput(ContainerTransmutationTablet containerTransmutationTablet, IInventory iInventory, int slotIndex, int x, int y)
|
2015-03-24 00:10:46 +01:00
|
|
|
{
|
|
|
|
super(iInventory, slotIndex, x, y);
|
2015-04-02 07:26:01 +02:00
|
|
|
this.containerTransmutationTablet = containerTransmutationTablet;
|
2015-03-24 00:10:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isItemValid(ItemStack itemStack)
|
|
|
|
{
|
2016-05-18 19:53:13 +02:00
|
|
|
return EnergyValueRegistryProxy.hasEnergyValue(itemStack) && AbilityRegistryProxy.isRecoverable(itemStack);
|
2015-03-24 00:10:46 +01:00
|
|
|
}
|
2015-04-02 07:26:01 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPickupFromSlot(EntityPlayer entityPlayer, ItemStack itemStack)
|
|
|
|
{
|
|
|
|
super.onPickupFromSlot(entityPlayer, itemStack);
|
|
|
|
this.containerTransmutationTablet.tileEntityTransmutationTablet.updateEnergyValueFromInventory();
|
|
|
|
this.containerTransmutationTablet.updateInventory();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void putStack(ItemStack itemStack)
|
|
|
|
{
|
|
|
|
super.putStack(itemStack);
|
|
|
|
this.containerTransmutationTablet.tileEntityTransmutationTablet.updateEnergyValueFromInventory();
|
|
|
|
this.containerTransmutationTablet.updateInventory();
|
|
|
|
}
|
2015-03-24 00:10:46 +01:00
|
|
|
}
|
2015-03-11 21:34:37 +01:00
|
|
|
}
|