2015-03-11 21:34:37 +01:00
|
|
|
package com.pahimar.ee3.inventory;
|
|
|
|
|
2016-05-30 16:53:39 +02:00
|
|
|
import com.pahimar.ee3.EquivalentExchange3;
|
2016-05-23 23:47:31 +02:00
|
|
|
import com.pahimar.ee3.api.blacklist.BlacklistRegistryProxy;
|
2016-05-30 04:10:32 +02:00
|
|
|
import com.pahimar.ee3.api.exchange.EnergyValue;
|
2015-05-07 19:45:06 +02:00
|
|
|
import com.pahimar.ee3.api.exchange.EnergyValueRegistryProxy;
|
2016-05-22 19:21:46 +02:00
|
|
|
import com.pahimar.ee3.api.knowledge.PlayerKnowledgeRegistryProxy;
|
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;
|
2016-05-22 19:21:46 +02:00
|
|
|
import com.pahimar.ee3.knowledge.PlayerKnowledge;
|
2015-04-02 07:26:01 +02:00
|
|
|
import com.pahimar.ee3.network.PacketHandler;
|
2016-05-22 19:21:46 +02:00
|
|
|
import com.pahimar.ee3.network.message.MessagePlayerKnowledge;
|
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;
|
2016-05-27 22:03:14 +02:00
|
|
|
import com.pahimar.ee3.util.ItemStackUtils;
|
2016-05-30 16:53:39 +02:00
|
|
|
import com.pahimar.ee3.util.LogHelper;
|
|
|
|
import com.pahimar.ee3.util.containers.LinearProgressHandler;
|
|
|
|
import com.pahimar.ee3.util.containers.ProgressMessage;
|
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-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;
|
2016-05-30 04:10:32 +02:00
|
|
|
import net.minecraft.world.World;
|
2015-03-11 21:34:37 +01:00
|
|
|
|
2015-04-02 07:26:01 +02:00
|
|
|
import java.util.*;
|
|
|
|
|
2016-05-30 04:10:32 +02:00
|
|
|
/**
|
|
|
|
* FIXME Continue integrating PR#881
|
|
|
|
*/
|
|
|
|
public class ContainerTransmutationTablet extends ContainerEE implements IElementTextFieldHandler, IElementSliderHandler, IElementButtonHandler {
|
|
|
|
|
2015-04-02 07:26:01 +02:00
|
|
|
private InventoryTransmutationTablet inventoryTransmutationTablet;
|
2016-05-30 16:53:39 +02:00
|
|
|
private final TileEntityTransmutationTablet transmutationTablet;
|
2016-05-30 04:10:32 +02:00
|
|
|
private final World world;
|
|
|
|
private EnergyValue energyValue;
|
2015-03-19 02:52:53 +01:00
|
|
|
private String searchTerm;
|
2016-05-30 16:53:39 +02:00
|
|
|
private int sortOption, sortOrder, scrollBarPosition;
|
|
|
|
private LinearProgressHandler<ProgressUpdate> progressHandler;
|
2015-03-19 02:52:53 +01:00
|
|
|
|
2016-05-30 16:53:39 +02:00
|
|
|
public ContainerTransmutationTablet(InventoryPlayer inventoryPlayer, TileEntityTransmutationTablet transmutationTablet) {
|
2016-05-30 04:10:32 +02:00
|
|
|
|
2016-05-30 16:53:39 +02:00
|
|
|
this.transmutationTablet = transmutationTablet;
|
|
|
|
this.world = transmutationTablet.getWorldObj();
|
2015-03-19 02:52:53 +01:00
|
|
|
|
2016-05-30 16:53:39 +02:00
|
|
|
if (EquivalentExchange3.proxy.getClientProxy() != null) {
|
|
|
|
this.progressHandler = new LinearProgressHandler<ProgressUpdate>(ProgressUpdate.class) {
|
|
|
|
@Override
|
|
|
|
public void handle(ProgressMessage<ProgressUpdate> message) {
|
|
|
|
handleProgressUpdate(message);
|
|
|
|
}
|
|
|
|
};
|
2015-04-02 07:26:01 +02:00
|
|
|
}
|
2016-05-30 16:53:39 +02:00
|
|
|
|
|
|
|
handleTomeSync(transmutationTablet.getStackInSlot(TileEntityTransmutationTablet.ALCHENOMICON_INDEX));
|
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;
|
2016-05-30 16:53:39 +02:00
|
|
|
this.energyValue = transmutationTablet.getAvailableEnergy();
|
|
|
|
|
|
|
|
this.addSlotToContainer(new SlotTabletInput(this, transmutationTablet, TileEntityTransmutationTablet.ITEM_INPUT_1, 62, 24));
|
|
|
|
this.addSlotToContainer(new SlotTabletInput(this, transmutationTablet, TileEntityTransmutationTablet.ITEM_INPUT_2, 35, 35));
|
|
|
|
this.addSlotToContainer(new SlotTabletInput(this, transmutationTablet, TileEntityTransmutationTablet.ITEM_INPUT_3, 26, 61));
|
|
|
|
this.addSlotToContainer(new SlotTabletInput(this, transmutationTablet, TileEntityTransmutationTablet.ITEM_INPUT_4, 35, 87));
|
|
|
|
this.addSlotToContainer(new SlotTabletInput(this, transmutationTablet, TileEntityTransmutationTablet.ITEM_INPUT_5, 62, 99));
|
|
|
|
this.addSlotToContainer(new SlotTabletInput(this, transmutationTablet, TileEntityTransmutationTablet.ITEM_INPUT_6, 89, 87));
|
|
|
|
this.addSlotToContainer(new SlotTabletInput(this, transmutationTablet, TileEntityTransmutationTablet.ITEM_INPUT_7, 98, 61));
|
|
|
|
this.addSlotToContainer(new SlotTabletInput(this, transmutationTablet, TileEntityTransmutationTablet.ITEM_INPUT_8, 89, 35));
|
|
|
|
this.addSlotToContainer(new Slot(transmutationTablet, TileEntityTransmutationTablet.STONE_INDEX, 62, 61) {
|
2015-03-19 02:52:53 +01:00
|
|
|
@Override
|
2016-05-30 04:10:32 +02:00
|
|
|
public int getSlotStackLimit() {
|
2015-03-19 02:52:53 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-05-30 04:10:32 +02:00
|
|
|
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
|
|
|
});
|
2016-05-30 16:53:39 +02:00
|
|
|
this.addSlotToContainer(new SlotAlchenomicon(transmutationTablet, TileEntityTransmutationTablet.ALCHENOMICON_INDEX, 152, 15));
|
2015-03-19 02:52:53 +01:00
|
|
|
|
2016-05-30 04:10:32 +02:00
|
|
|
for (int i = 0; i < 10; i++) {
|
|
|
|
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
|
2016-05-30 04:10:32 +02:00
|
|
|
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
|
2016-05-30 04:10:32 +02:00
|
|
|
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
|
|
|
|
2016-05-30 04:10:32 +02:00
|
|
|
updateInventory();
|
2015-03-11 21:34:37 +01:00
|
|
|
}
|
2015-03-19 02:52:53 +01:00
|
|
|
|
2016-05-30 16:53:39 +02:00
|
|
|
public EnergyValue getEnergyValue() {
|
|
|
|
return energyValue;
|
|
|
|
}
|
|
|
|
|
2015-05-01 20:21:59 +02:00
|
|
|
@Override
|
2016-05-30 04:10:32 +02:00
|
|
|
public boolean canInteractWith(EntityPlayer entityPlayer) {
|
2016-05-30 16:53:39 +02:00
|
|
|
return transmutationTablet != null && transmutationTablet.isUseableByPlayer(entityPlayer);
|
2015-05-01 20:21:59 +02:00
|
|
|
}
|
|
|
|
|
2015-03-19 02:52:53 +01:00
|
|
|
@Override
|
2016-05-30 04:10:32 +02:00
|
|
|
public void detectAndSendChanges() {
|
|
|
|
|
2015-03-19 02:52:53 +01:00
|
|
|
super.detectAndSendChanges();
|
2015-04-02 07:26:01 +02:00
|
|
|
|
2016-05-30 04:10:32 +02:00
|
|
|
this.updateInventory();
|
|
|
|
|
2016-05-30 16:53:39 +02:00
|
|
|
EnergyValue tileEnergyValue = transmutationTablet.getAvailableEnergy();
|
|
|
|
if (energyValue.compareTo(tileEnergyValue) != 0) {
|
|
|
|
energyValue = tileEnergyValue;
|
|
|
|
ProgressUpdate.getMessage(ProgressUpdate.EnergyUpdate, tileEnergyValue.getValue()).send(this, this.crafters);
|
2015-04-02 07:26:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
2016-05-30 04:10:32 +02:00
|
|
|
public void updateProgressBar(int valueType, int updatedValue) {
|
|
|
|
|
2016-05-30 16:53:39 +02:00
|
|
|
progressHandler.handle(valueType, updatedValue);
|
|
|
|
}
|
2016-05-30 04:10:32 +02:00
|
|
|
|
2016-05-30 16:53:39 +02:00
|
|
|
private void sendKnowledgeToClient(Collection<ItemStack> knownItemStacks) {
|
2016-05-30 04:10:32 +02:00
|
|
|
|
2016-05-30 16:53:39 +02:00
|
|
|
PacketHandler.INSTANCE.sendToAllAround(
|
|
|
|
new MessagePlayerKnowledge(transmutationTablet, knownItemStacks),
|
|
|
|
new NetworkRegistry.TargetPoint(world.provider.dimensionId, transmutationTablet.xCoord, transmutationTablet.yCoord, transmutationTablet.zCoord, 5d)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void handleTomeSync(ItemStack itemStack) {
|
|
|
|
|
|
|
|
if (itemStack != null && itemStack.getItem() instanceof ItemAlchenomicon && ItemStackUtils.getOwnerName(itemStack) != null) {
|
|
|
|
|
|
|
|
if (!world.isRemote) {
|
|
|
|
|
|
|
|
Set<ItemStack> knownItemStacks = PlayerKnowledgeRegistryProxy.getKnownItemStacks(ItemStackUtils.getOwnerName(itemStack));
|
|
|
|
inventoryTransmutationTablet = new InventoryTransmutationTablet(knownItemStacks);
|
|
|
|
sendKnowledgeToClient(knownItemStacks);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.inventoryTransmutationTablet = new InventoryTransmutationTablet(transmutationTablet.getPlayerKnowledge());
|
|
|
|
}
|
2015-04-05 15:57:46 +02:00
|
|
|
}
|
2016-05-30 16:53:39 +02:00
|
|
|
else {
|
|
|
|
|
|
|
|
this.inventoryTransmutationTablet = new InventoryTransmutationTablet();
|
|
|
|
if (!world.isRemote) {
|
|
|
|
sendKnowledgeToClient(null);
|
|
|
|
}
|
2015-05-05 04:36:39 +02:00
|
|
|
}
|
2016-05-30 16:53:39 +02:00
|
|
|
}
|
2015-04-02 07:26:01 +02:00
|
|
|
|
2016-05-30 16:53:39 +02:00
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public void handleProgressUpdate(ProgressMessage<ProgressUpdate> message) {
|
|
|
|
|
|
|
|
switch (message.getType()) {
|
|
|
|
case EnergyUpdate: {
|
|
|
|
energyValue = new EnergyValue(message.getFloat());
|
|
|
|
LogHelper.trace("Got energy: {}", message.getFloat());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SortTypeUpdate: {
|
|
|
|
sortOption = message.getInt();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SortOrderUpdate: {
|
|
|
|
sortOrder = message.getInt();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ScrollBarUpdate: {
|
|
|
|
break;
|
|
|
|
}
|
2015-04-02 07:26:01 +02:00
|
|
|
}
|
2016-05-30 16:53:39 +02:00
|
|
|
|
|
|
|
updateInventory();
|
2015-03-19 02:52:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-05-30 04:10:32 +02:00
|
|
|
public void handleElementTextFieldUpdate(String elementName, String updatedText) {
|
|
|
|
|
|
|
|
if (elementName.equalsIgnoreCase("searchField")) {
|
2016-05-30 16:53:39 +02:00
|
|
|
searchTerm = updatedText;
|
2015-03-19 02:52:53 +01:00
|
|
|
updateInventory();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-02 07:26:01 +02:00
|
|
|
@Override
|
2016-05-30 04:10:32 +02:00
|
|
|
public void handleElementSliderUpdate(String elementName, int elementValue) {
|
|
|
|
|
|
|
|
if (elementName.equals("scrollBar")) {
|
2016-05-30 16:53:39 +02:00
|
|
|
scrollBarPosition = elementValue;
|
2015-04-05 15:57:46 +02:00
|
|
|
updateInventory();
|
|
|
|
}
|
2015-04-02 07:26:01 +02:00
|
|
|
}
|
|
|
|
|
2016-05-22 19:21:46 +02:00
|
|
|
public void handlePlayerKnowledgeUpdate(PlayerKnowledge playerKnowledge) {
|
|
|
|
|
|
|
|
if (playerKnowledge != null) {
|
2016-05-30 16:53:39 +02:00
|
|
|
inventoryTransmutationTablet = new InventoryTransmutationTablet(playerKnowledge.getKnownItemStacks());
|
|
|
|
updateInventory();
|
2015-04-02 07:26:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-20 03:10:55 +02:00
|
|
|
private void updateInventory() {
|
|
|
|
|
2015-04-02 07:26:01 +02:00
|
|
|
ItemStack[] newInventory = new ItemStack[30];
|
|
|
|
|
2016-05-30 16:53:39 +02:00
|
|
|
Set<ItemStack> filteredSet = FilterUtils.filterByDisplayName(inventoryTransmutationTablet.getKnownTransmutations(), searchTerm, FilterUtils.NameFilterType.CONTAINS);
|
|
|
|
List<ItemStack> filteredList = new ArrayList<>(FilterUtils.filterByEnergyValue(filteredSet, energyValue));
|
2016-05-20 03:10:55 +02:00
|
|
|
|
2016-05-30 16:53:39 +02:00
|
|
|
if (sortOption == 0 && sortOrder == 0) {
|
|
|
|
Collections.sort(filteredList, Comparators.DISPLAY_NAME_COMPARATOR);
|
2015-05-05 04:36:39 +02:00
|
|
|
}
|
2016-05-30 16:53:39 +02:00
|
|
|
else if (sortOption == 0 && sortOrder == 1) {
|
|
|
|
Collections.sort(filteredList, Comparators.DISPLAY_NAME_COMPARATOR.reversed());
|
2015-05-05 04:36:39 +02:00
|
|
|
}
|
2016-05-30 16:53:39 +02:00
|
|
|
else if (sortOption == 1 && sortOrder == 0) {
|
|
|
|
Collections.sort(filteredList, Comparators.ENERGY_VALUE_ITEM_STACK_COMPARATOR);
|
|
|
|
}
|
|
|
|
else if (sortOption == 1 && sortOrder == 1) {
|
|
|
|
Collections.sort(filteredList, Comparators.ENERGY_VALUE_ITEM_STACK_COMPARATOR.reversed());
|
|
|
|
}
|
|
|
|
else if (sortOption == 2 && sortOrder == 0) {
|
|
|
|
Collections.sort(filteredList, Comparators.ID_COMPARATOR);
|
|
|
|
}
|
|
|
|
else if (sortOption == 2 && sortOrder == 1) {
|
|
|
|
Collections.sort(filteredList, Comparators.ID_COMPARATOR.reversed());
|
2015-04-03 06:39:52 +02:00
|
|
|
}
|
2015-04-02 07:26:01 +02:00
|
|
|
|
2016-05-20 03:10:55 +02:00
|
|
|
if (filteredList.size() <= 30) {
|
2016-05-30 16:53:39 +02:00
|
|
|
this.scrollBarPosition = 0;
|
2015-04-02 07:26:01 +02:00
|
|
|
}
|
2016-05-30 16:53:39 +02:00
|
|
|
|
|
|
|
int adjustedStartIndex = (int) ((scrollBarPosition / 187f) * filteredList.size());
|
|
|
|
adjustedStartIndex -= adjustedStartIndex % 3; // Paginate by 3 elements.
|
|
|
|
|
|
|
|
int startIndex = Math.max(0, Math.min(adjustedStartIndex, filteredList.size() - 30));
|
|
|
|
int endIndex = Math.min(adjustedStartIndex + 30, filteredList.size());
|
|
|
|
|
|
|
|
if (world.isRemote) {
|
|
|
|
LogHelper.trace("updateInventory called");
|
|
|
|
LogHelper.trace(String.format("known transmutations count: %d", this.inventoryTransmutationTablet.getKnownTransmutations().size()));
|
|
|
|
LogHelper.trace(String.format("(from, to): (%d, %d)", startIndex, endIndex));
|
2015-04-02 07:26:01 +02:00
|
|
|
}
|
2015-03-25 23:20:57 +01:00
|
|
|
|
2016-05-30 16:53:39 +02:00
|
|
|
filteredList.subList(startIndex, endIndex).toArray(newInventory);
|
|
|
|
|
2016-05-20 03:10:55 +02:00
|
|
|
for (int i = 0; i < 30; i++) {
|
2015-04-02 07:26:01 +02:00
|
|
|
this.getSlot(i + 10).putStack(newInventory[i]);
|
|
|
|
}
|
2015-03-19 02:52:53 +01:00
|
|
|
}
|
2015-03-22 03:02:35 +01:00
|
|
|
|
|
|
|
@Override
|
2016-05-30 04:10:32 +02:00
|
|
|
public ItemStack transferStackInSlot(EntityPlayer entityPlayer, int slotIndex) {
|
|
|
|
|
2015-03-22 03:02:35 +01:00
|
|
|
ItemStack itemStack = null;
|
|
|
|
Slot slot = (Slot) inventorySlots.get(slotIndex);
|
|
|
|
|
2016-05-30 04:10:32 +02:00
|
|
|
if (slot != null && slot.getHasStack()) {
|
|
|
|
|
2015-03-22 03:02:35 +01:00
|
|
|
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
|
|
|
|
*/
|
2016-05-30 04:10:32 +02:00
|
|
|
if (slotIndex < TileEntityTransmutationTablet.INVENTORY_SIZE) {
|
|
|
|
|
|
|
|
if (!this.mergeItemStack(slotItemStack, TileEntityTransmutationTablet.INVENTORY_SIZE, inventorySlots.size(), false)) {
|
2015-03-22 03:02:35 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2016-05-30 04:10:32 +02:00
|
|
|
else if (slotIndex >= TileEntityTransmutationTablet.INVENTORY_SIZE && slotIndex < 40) {
|
|
|
|
|
|
|
|
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
|
|
|
}
|
2016-05-30 04:10:32 +02:00
|
|
|
else {
|
|
|
|
|
|
|
|
if (slotItemStack.getItem() instanceof ItemAlchenomicon) {
|
|
|
|
|
|
|
|
if (!this.mergeItemStack(slotItemStack, TileEntityTransmutationTablet.ALCHENOMICON_INDEX, TileEntityTransmutationTablet.INVENTORY_SIZE, false)) {
|
2015-03-22 03:02:35 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2016-05-30 04:10:32 +02:00
|
|
|
else if (slotItemStack.getItem() instanceof ItemMiniumStone || slotItemStack.getItem() instanceof ItemPhilosophersStone) {
|
|
|
|
|
|
|
|
if (!this.mergeItemStack(slotItemStack, TileEntityTransmutationTablet.STONE_INDEX, TileEntityTransmutationTablet.INVENTORY_SIZE, false)) {
|
2015-03-22 03:02:35 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2016-05-30 04:10:32 +02:00
|
|
|
else {
|
|
|
|
|
|
|
|
if (!this.mergeItemStack(slotItemStack, TileEntityTransmutationTablet.ITEM_INPUT_1, TileEntityTransmutationTablet.INVENTORY_SIZE, false)) {
|
2015-03-22 03:02:35 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-30 04:10:32 +02:00
|
|
|
if (slotItemStack.stackSize == 0) {
|
2015-03-22 03:02:35 +01:00
|
|
|
slot.putStack(null);
|
|
|
|
}
|
2016-05-30 04:10:32 +02:00
|
|
|
else {
|
2015-03-22 03:02:35 +01:00
|
|
|
slot.onSlotChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return itemStack;
|
|
|
|
}
|
2015-03-24 00:10:46 +01:00
|
|
|
|
2016-05-30 04:10:32 +02:00
|
|
|
private boolean mergeTransmutedItemStack(EntityPlayer entityPlayer, Slot transmutationOutputSlot, ItemStack itemStack, int slotMin, int slotMax, boolean ascending) {
|
2016-05-19 03:18:24 +02:00
|
|
|
|
|
|
|
// Calculate how many items can be transmuted
|
2016-05-30 16:53:39 +02:00
|
|
|
int numCanTransmute = MathHelper.floor(this.transmutationTablet.getAvailableEnergy().getValue() / EnergyValueRegistryProxy.getEnergyValue(itemStack).getValue());
|
2016-05-19 03:18:24 +02:00
|
|
|
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) {
|
2016-05-30 04:10:32 +02:00
|
|
|
|
2016-05-23 05:55:30 +02:00
|
|
|
stackInSlot = itemStack1.copy();
|
2016-05-19 03:18:24 +02:00
|
|
|
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-27 22:03:14 +02:00
|
|
|
else if (slot.isItemValid(itemStack1) && ItemStackUtils.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
|
|
|
|
2016-05-27 22:03:14 +02:00
|
|
|
transmutationOutputSlot.onPickupFromSlot(entityPlayer, ItemStackUtils.clone(itemStack, numTransmuted));
|
2016-05-19 03:18:24 +02:00
|
|
|
|
|
|
|
return false;
|
2015-04-21 03:16:48 +02:00
|
|
|
}
|
|
|
|
|
2015-04-03 06:39:52 +02:00
|
|
|
@Override
|
2016-05-30 04:10:32 +02:00
|
|
|
public void handleElementButtonClick(String elementName, int mouseButton) {
|
|
|
|
|
|
|
|
if (elementName.equals("sortOption")) {
|
|
|
|
if (mouseButton == 0) {
|
2016-05-30 16:53:39 +02:00
|
|
|
sortOption = (sortOption + 1) % 3;
|
2015-04-03 06:39:52 +02:00
|
|
|
}
|
2016-05-30 04:10:32 +02:00
|
|
|
else if (mouseButton == 1) {
|
2016-05-30 16:53:39 +02:00
|
|
|
sortOption = (sortOption + (3 - 1)) % 3;
|
2015-04-03 06:39:52 +02:00
|
|
|
}
|
|
|
|
}
|
2016-05-30 04:10:32 +02:00
|
|
|
else if (elementName.equals("sortOrder")) {
|
2016-05-30 16:53:39 +02:00
|
|
|
sortOrder = 1 - sortOrder; // Toggle between 0 and 1
|
2015-05-05 03:08:06 +02:00
|
|
|
}
|
2015-04-05 15:57:46 +02:00
|
|
|
|
2016-05-30 16:53:39 +02:00
|
|
|
ProgressUpdate.getMessage(ProgressUpdate.SortTypeUpdate, sortOption).send(this, this.crafters);
|
|
|
|
ProgressUpdate.getMessage(ProgressUpdate.SortOrderUpdate, sortOrder).send(this, this.crafters);
|
2015-04-03 06:39:52 +02:00
|
|
|
}
|
|
|
|
|
2015-06-29 02:26:12 +02:00
|
|
|
@Override
|
2016-05-30 04:10:32 +02:00
|
|
|
public ItemStack slotClick(int slot, int button, int flag, EntityPlayer player) {
|
|
|
|
|
2016-05-30 16:53:39 +02:00
|
|
|
if (button == 0 && flag == 6) {
|
2015-06-29 02:26:12 +02:00
|
|
|
return null;
|
|
|
|
}
|
2016-05-30 04:10:32 +02:00
|
|
|
|
2015-06-29 02:26:12 +02:00
|
|
|
return super.slotClick(slot, button, flag, player);
|
|
|
|
}
|
2015-11-28 05:07:45 +01:00
|
|
|
|
2016-05-30 04:10:32 +02:00
|
|
|
private class SlotAlchenomicon extends Slot {
|
|
|
|
|
2016-05-30 16:53:39 +02:00
|
|
|
public SlotAlchenomicon(IInventory iInventory, int slotIndex, int x, int y) {
|
2015-04-02 07:26:01 +02:00
|
|
|
super(iInventory, slotIndex, x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-05-30 04:10:32 +02:00
|
|
|
public int getSlotStackLimit() {
|
2015-04-02 07:26:01 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-05-30 04:10:32 +02:00
|
|
|
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
|
2016-05-30 16:53:39 +02:00
|
|
|
public void onSlotChanged() {
|
2016-05-30 04:10:32 +02:00
|
|
|
|
2016-05-30 16:53:39 +02:00
|
|
|
super.onSlotChanged();
|
|
|
|
handleTomeSync(getStack());
|
|
|
|
updateInventory();
|
2015-04-02 07:26:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-30 04:10:32 +02:00
|
|
|
private class SlotTabletOutput extends Slot {
|
|
|
|
|
2015-04-02 07:26:01 +02:00
|
|
|
private ContainerTransmutationTablet containerTransmutationTablet;
|
|
|
|
|
2016-05-30 04:10:32 +02:00
|
|
|
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
|
2016-05-30 04:10:32 +02:00
|
|
|
public boolean isItemValid(ItemStack itemStack) {
|
2015-03-24 00:10:46 +01:00
|
|
|
return false;
|
|
|
|
}
|
2015-04-02 07:26:01 +02:00
|
|
|
|
|
|
|
@Override
|
2016-05-30 04:10:32 +02:00
|
|
|
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
|
2016-05-30 04:10:32 +02:00
|
|
|
public void onPickupFromSlot(EntityPlayer entityPlayer, ItemStack itemStack) {
|
|
|
|
|
2015-04-02 07:26:01 +02:00
|
|
|
super.onPickupFromSlot(entityPlayer, itemStack);
|
2015-05-01 20:21:59 +02:00
|
|
|
|
2016-05-30 16:53:39 +02:00
|
|
|
if (getHasStack()) {
|
|
|
|
containerTransmutationTablet.transmutationTablet.consumeInventoryForEnergyValue(itemStack);
|
2015-05-01 20:21:59 +02:00
|
|
|
}
|
2016-05-30 16:53:39 +02:00
|
|
|
|
|
|
|
containerTransmutationTablet.updateInventory();
|
2015-05-01 20:21:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-05-30 04:10:32 +02:00
|
|
|
public void onSlotChanged() {
|
|
|
|
|
2015-05-01 20:21:59 +02:00
|
|
|
super.onSlotChanged();
|
|
|
|
|
2016-05-30 04:10:32 +02:00
|
|
|
if (FMLCommonHandler.instance().getEffectiveSide().isServer()) {
|
2016-05-30 16:53:39 +02:00
|
|
|
containerTransmutationTablet.transmutationTablet.updateEnergyValueFromInventory();
|
2015-05-01 20:21:59 +02:00
|
|
|
}
|
2015-04-02 07:26:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@SideOnly(Side.CLIENT)
|
2016-05-30 04:10:32 +02:00
|
|
|
public boolean func_111238_b() {
|
2015-04-02 07:26:01 +02:00
|
|
|
return this.getHasStack();
|
|
|
|
}
|
2015-03-24 00:10:46 +01:00
|
|
|
}
|
|
|
|
|
2016-05-30 04:10:32 +02:00
|
|
|
private class SlotTabletInput extends Slot {
|
|
|
|
|
2015-04-02 07:26:01 +02:00
|
|
|
private ContainerTransmutationTablet containerTransmutationTablet;
|
|
|
|
|
2016-05-30 04:10:32 +02:00
|
|
|
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
|
2016-05-30 04:10:32 +02:00
|
|
|
public boolean isItemValid(ItemStack itemStack) {
|
2016-05-23 23:47:31 +02:00
|
|
|
return EnergyValueRegistryProxy.hasEnergyValue(itemStack) && BlacklistRegistryProxy.isExchangeable(itemStack);
|
2015-03-24 00:10:46 +01:00
|
|
|
}
|
2015-04-02 07:26:01 +02:00
|
|
|
|
|
|
|
@Override
|
2016-05-30 04:10:32 +02:00
|
|
|
public void onPickupFromSlot(EntityPlayer entityPlayer, ItemStack itemStack) {
|
|
|
|
|
2015-04-02 07:26:01 +02:00
|
|
|
super.onPickupFromSlot(entityPlayer, itemStack);
|
2016-05-30 16:53:39 +02:00
|
|
|
this.containerTransmutationTablet.transmutationTablet.updateEnergyValueFromInventory();
|
2015-04-02 07:26:01 +02:00
|
|
|
this.containerTransmutationTablet.updateInventory();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-05-30 04:10:32 +02:00
|
|
|
public void putStack(ItemStack itemStack) {
|
|
|
|
|
2015-04-02 07:26:01 +02:00
|
|
|
super.putStack(itemStack);
|
2016-05-30 16:53:39 +02:00
|
|
|
this.containerTransmutationTablet.transmutationTablet.updateEnergyValueFromInventory();
|
2015-04-02 07:26:01 +02:00
|
|
|
this.containerTransmutationTablet.updateInventory();
|
|
|
|
}
|
2015-03-24 00:10:46 +01:00
|
|
|
}
|
2016-05-30 16:53:39 +02:00
|
|
|
|
|
|
|
enum ProgressUpdate {
|
|
|
|
EnergyUpdate,
|
|
|
|
SortTypeUpdate,
|
|
|
|
SortOrderUpdate,
|
|
|
|
ScrollBarUpdate;
|
|
|
|
|
|
|
|
public static ProgressMessage<ProgressUpdate> getMessage(ProgressUpdate type, int data) {
|
|
|
|
return new ProgressMessage<>(ProgressUpdate.class, type, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static ProgressMessage<ProgressUpdate> getMessage(ProgressUpdate type, float data) {
|
|
|
|
return new ProgressMessage<>(ProgressUpdate.class, type, data);
|
|
|
|
}
|
|
|
|
}
|
2015-03-11 21:34:37 +01:00
|
|
|
}
|