Another whack of stuff with varying levels of won't break

This commit is contained in:
pahimar 2015-03-25 18:20:57 -04:00
parent 68c89ae7b5
commit 97b032605c
6 changed files with 78 additions and 40 deletions

View file

@ -13,6 +13,8 @@ import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.entity.player.InventoryPlayer;
import java.text.DecimalFormat;
@SideOnly(Side.CLIENT)
public class GuiTransmutationTablet extends GuiBase
{
@ -21,6 +23,8 @@ public class GuiTransmutationTablet extends GuiBase
private ElementTextField searchTextField;
private ElementSlider slider;
private static DecimalFormat energyValueDecimalFormat = new DecimalFormat("###,###,###,###,###.###");
public GuiTransmutationTablet(InventoryPlayer inventoryPlayer, TileEntityTransmutationTablet tileEntityTransmutationTablet)
{
super(new ContainerTransmutationTablet(inventoryPlayer, tileEntityTransmutationTablet), Textures.Gui.TRANSMUTATION_TABLET);
@ -37,12 +41,12 @@ public class GuiTransmutationTablet extends GuiBase
this.drawTitle = false;
this.drawInventory = false;
searchTextField = new ElementSearchField(this, 173, 145, "searchField", 78, 10);
searchTextField = new ElementSearchField(this, 173, 18, "searchField", 78, 10);
searchTextField.backgroundColor = new GuiColor(0, 0, 0, 0).getColor();
searchTextField.borderColor = new GuiColor(0, 0, 0, 0).getColor();
searchTextField.setFocused(true);
slider = new ElementSlider(this, 239, 163, 12, 74, 59, 0)
slider = new ElementSlider(this, 239, 36, 12, 74, 187, 0)
{
@Override
protected void dragSlider(int x, int y)
@ -75,9 +79,7 @@ public class GuiTransmutationTablet extends GuiBase
protected void drawGuiContainerForegroundLayer(int x, int y)
{
super.drawGuiContainerForegroundLayer(x, y);
fontRendererObj.drawString("Energy Value:", 8, 140, Integer.parseInt(Colors.PURE_WHITE, 16));
// TODO Nicer text formatting of the value
fontRendererObj.drawString(String.format("%s", tileEntityTransmutationTablet.getEnergyValue().getEnergyValue()), 8, 150, Integer.parseInt(Colors.PURE_WHITE, 16));
fontRendererObj.drawString("Energy Value:", 8, 140, Integer.parseInt(Colors.PURE_WHITE, 16)); // TODO Localize
fontRendererObj.drawString(String.format("%s", energyValueDecimalFormat.format(tileEntityTransmutationTablet.getStoredEnergyValue().getEnergyValue())), 8, 150, Integer.parseInt(Colors.PURE_WHITE, 16));
}
}

View file

@ -343,7 +343,7 @@ public class EnergyValueRegistry implements INBTTaggable, JsonSerializer<EnergyV
// Increment the pass counter
passNumber++;
// Set the values for getEnergyValue calls in the auto-assignment computation
// Set the values for getStoredEnergyValue calls in the auto-assignment computation
stackMappingsBuilder = ImmutableSortedMap.naturalOrder();
stackMappingsBuilder.putAll(stackValueMap);
stackMappings = stackMappingsBuilder.build();
@ -401,9 +401,9 @@ public class EnergyValueRegistry implements INBTTaggable, JsonSerializer<EnergyV
// float computedValue = 0f;
// for (WrappedStack stack : postAssignedDependentMappings.get(wrappedStack))
// {
// if (getEnergyValue(stack) != null)
// if (getStoredEnergyValue(stack) != null)
// {
// computedValue += getEnergyValue(stack).getEnergyValue() * stack.getStackSize();
// computedValue += getStoredEnergyValue(stack).getStoredEnergyValue() * stack.getStackSize();
// }
// else
// {

View file

@ -8,6 +8,7 @@ import com.pahimar.ee3.item.ItemPhilosophersStone;
import com.pahimar.ee3.knowledge.AbilityRegistry;
import com.pahimar.ee3.knowledge.TransmutationKnowledgeRegistry;
import com.pahimar.ee3.tileentity.TileEntityTransmutationTablet;
import com.pahimar.ee3.util.FilterUtils;
import com.pahimar.ee3.util.ItemHelper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
@ -15,11 +16,14 @@ import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
public class ContainerTransmutationTablet extends ContainerEE implements ITextFieldElementHandler
{
private final InventoryTransmutationTablet inventoryTransmutationTablet;
private InventoryTransmutationTablet inventoryTransmutationTablet;
private TileEntityTransmutationTablet tileEntityTransmutationTablet;
private EnergyValue energyValue;
private String searchTerm;
@ -28,18 +32,26 @@ public class ContainerTransmutationTablet extends ContainerEE implements ITextFi
{
this.tileEntityTransmutationTablet = tileEntityTransmutationTablet;
TreeSet<ItemStack> knownTransmutations = new TreeSet<ItemStack>(ItemHelper.displayNameComparator);
knownTransmutations.addAll(TransmutationKnowledgeRegistry.getInstance().getPlayersKnownTransmutations(inventoryPlayer.player.getUniqueID()));
if (tileEntityTransmutationTablet.getStackInSlot(TileEntityTransmutationTablet.ALCHEMICAL_TOME_INDEX) != null)
{
ItemStack itemStack = tileEntityTransmutationTablet.getStackInSlot(TileEntityTransmutationTablet.ALCHEMICAL_TOME_INDEX);
if (itemStack.getItem() instanceof ItemAlchemicalTome && ItemHelper.hasOwnerUUID(itemStack))
{
knownTransmutations.addAll(TransmutationKnowledgeRegistry.getInstance().getPlayersKnownTransmutations(ItemHelper.getOwnerUUID(itemStack)));
}
}
inventoryTransmutationTablet = new InventoryTransmutationTablet(knownTransmutations);
this.addSlotToContainer(new SlotTabletInput(tileEntityTransmutationTablet, TileEntityTransmutationTablet.ITEM_INPUT_1, 120, 27));
this.addSlotToContainer(new SlotTabletInput(tileEntityTransmutationTablet, TileEntityTransmutationTablet.ITEM_INPUT_2, 93, 38));
this.addSlotToContainer(new SlotTabletInput(tileEntityTransmutationTablet, TileEntityTransmutationTablet.ITEM_INPUT_3, 84, 64));
this.addSlotToContainer(new SlotTabletInput(tileEntityTransmutationTablet, TileEntityTransmutationTablet.ITEM_INPUT_4, 93, 90));
this.addSlotToContainer(new SlotTabletInput(tileEntityTransmutationTablet, TileEntityTransmutationTablet.ITEM_INPUT_5, 120, 102));
this.addSlotToContainer(new SlotTabletInput(tileEntityTransmutationTablet, TileEntityTransmutationTablet.ITEM_INPUT_6, 147, 90));
this.addSlotToContainer(new SlotTabletInput(tileEntityTransmutationTablet, TileEntityTransmutationTablet.ITEM_INPUT_7, 156, 64));
this.addSlotToContainer(new SlotTabletInput(tileEntityTransmutationTablet, TileEntityTransmutationTablet.ITEM_INPUT_8, 147, 38));
this.addSlotToContainer(new Slot(tileEntityTransmutationTablet, TileEntityTransmutationTablet.STONE_INDEX, 120, 64)
this.addSlotToContainer(new SlotTabletInput(tileEntityTransmutationTablet, TileEntityTransmutationTablet.ITEM_INPUT_1, 62, 24));
this.addSlotToContainer(new SlotTabletInput(tileEntityTransmutationTablet, TileEntityTransmutationTablet.ITEM_INPUT_2, 35, 35));
this.addSlotToContainer(new SlotTabletInput(tileEntityTransmutationTablet, TileEntityTransmutationTablet.ITEM_INPUT_3, 26, 61));
this.addSlotToContainer(new SlotTabletInput(tileEntityTransmutationTablet, TileEntityTransmutationTablet.ITEM_INPUT_4, 35, 87));
this.addSlotToContainer(new SlotTabletInput(tileEntityTransmutationTablet, TileEntityTransmutationTablet.ITEM_INPUT_5, 62, 99));
this.addSlotToContainer(new SlotTabletInput(tileEntityTransmutationTablet, TileEntityTransmutationTablet.ITEM_INPUT_6, 89, 87));
this.addSlotToContainer(new SlotTabletInput(tileEntityTransmutationTablet, TileEntityTransmutationTablet.ITEM_INPUT_7, 98, 61));
this.addSlotToContainer(new SlotTabletInput(tileEntityTransmutationTablet, TileEntityTransmutationTablet.ITEM_INPUT_8, 89, 35));
this.addSlotToContainer(new Slot(tileEntityTransmutationTablet, TileEntityTransmutationTablet.STONE_INDEX, 62, 61)
{
@Override
public int getSlotStackLimit()
@ -53,7 +65,7 @@ public class ContainerTransmutationTablet extends ContainerEE implements ITextFi
return itemStack.getItem() instanceof ItemMiniumStone || itemStack.getItem() instanceof ItemPhilosophersStone;
}
});
this.addSlotToContainer(new Slot(tileEntityTransmutationTablet, TileEntityTransmutationTablet.ALCHEMICAL_TOME_INDEX, 152, 142)
this.addSlotToContainer(new Slot(tileEntityTransmutationTablet, TileEntityTransmutationTablet.ALCHEMICAL_TOME_INDEX, 152, 15)
{
@Override
public int getSlotStackLimit()
@ -68,11 +80,11 @@ public class ContainerTransmutationTablet extends ContainerEE implements ITextFi
}
});
for (int i = 0; i < 4; i++)
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 3; j++)
{
this.addSlotToContainer(new SlotTabletOutput(inventoryTransmutationTablet, i * 4 + j + 10, 175 + j * 20, 163 + i * 19));
this.addSlotToContainer(new SlotTabletOutput(inventoryTransmutationTablet, i * 4 + j + 10, 175 + j * 20, 38 + i * 20));
}
}
@ -81,14 +93,14 @@ public class ContainerTransmutationTablet extends ContainerEE implements ITextFi
{
for (int inventoryColumnIndex = 0; inventoryColumnIndex < PLAYER_INVENTORY_COLUMNS; ++inventoryColumnIndex)
{
this.addSlotToContainer(new Slot(inventoryPlayer, inventoryColumnIndex + inventoryRowIndex * 9 + 9, 8 + inventoryColumnIndex * 18, 163 + 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
for (int actionBarSlotIndex = 0; actionBarSlotIndex < PLAYER_INVENTORY_COLUMNS; ++actionBarSlotIndex)
{
this.addSlotToContainer(new Slot(inventoryPlayer, actionBarSlotIndex, 8 + actionBarSlotIndex * 18, 221));
this.addSlotToContainer(new Slot(inventoryPlayer, actionBarSlotIndex, 8 + actionBarSlotIndex * 18, 222));
}
}
@ -96,7 +108,7 @@ public class ContainerTransmutationTablet extends ContainerEE implements ITextFi
public void detectAndSendChanges()
{
super.detectAndSendChanges();
this.energyValue = this.tileEntityTransmutationTablet.getEnergyValue();
this.energyValue = this.tileEntityTransmutationTablet.getStoredEnergyValue();
}
@Override
@ -111,7 +123,31 @@ public class ContainerTransmutationTablet extends ContainerEE implements ITextFi
private void updateInventory()
{
boolean shouldUpdateInventory = false;
ItemStack[] newInventory = new ItemStack[inventoryTransmutationTablet.getSizeInventory()];
Set<ItemStack> sets = inventoryTransmutationTablet.getKnownTransmutations();
List<ItemStack> filteredList = new ArrayList(FilterUtils.filterByNameContains(sets, searchTerm, ItemHelper.displayNameComparator));
FilterUtils.filterOutListItemsWithInvalidIcons(filteredList, ItemHelper.displayNameComparator);
if (filteredList.size() <= inventoryTransmutationTablet.getSizeInventory())
{
newInventory = filteredList.toArray(newInventory);
shouldUpdateInventory = true;
}
else
{
newInventory = filteredList.subList(0, inventoryTransmutationTablet.getSizeInventory()).toArray(newInventory);
shouldUpdateInventory = true;
}
if (shouldUpdateInventory)
{
for (int i = 0; i < 30; i++)
{
inventoryTransmutationTablet.setInventorySlotContents(i, newInventory[i]);
inventoryTransmutationTablet.markDirty();
}
}
}
@Override

View file

@ -16,7 +16,7 @@ public class InventoryTransmutationTablet implements IInventory
public InventoryTransmutationTablet(Set<ItemStack> knownTransmutations)
{
inventory = new ItemStack[12];
inventory = new ItemStack[30];
if (knownTransmutations != null)
{
this.knownTransmutations = knownTransmutations;

View file

@ -35,7 +35,7 @@ public class TileEntityTransmutationTablet extends TileEntityEE implements ISide
public static final int STONE_INDEX = 8;
public static final int ALCHEMICAL_TOME_INDEX = 9;
private EnergyValue energyValue;
private EnergyValue storedEnergyValue;
private ForgeDirection rotation;
private ItemStack[] inventory;
@ -43,18 +43,18 @@ public class TileEntityTransmutationTablet extends TileEntityEE implements ISide
{
super();
rotation = ForgeDirection.UNKNOWN;
energyValue = new EnergyValue(0);
storedEnergyValue = new EnergyValue(0);
inventory = new ItemStack[INVENTORY_SIZE];
}
public EnergyValue getEnergyValue()
public EnergyValue getStoredEnergyValue()
{
return energyValue;
return storedEnergyValue;
}
public void setEnergyValue(EnergyValue energyValue)
public void setStoredEnergyValue(EnergyValue storedEnergyValue)
{
this.energyValue = energyValue;
this.storedEnergyValue = storedEnergyValue;
}
public ForgeDirection getRotation()
@ -117,14 +117,14 @@ public class TileEntityTransmutationTablet extends TileEntityEE implements ISide
}
}
NBTTagCompound energyValueTagCompound = nbtTagCompound.getCompoundTag("energyValue");
NBTTagCompound energyValueTagCompound = nbtTagCompound.getCompoundTag("storedEnergyValue");
if (!energyValueTagCompound.hasNoTags())
{
energyValue = EnergyValue.loadEnergyValueFromNBT(energyValueTagCompound);
storedEnergyValue = EnergyValue.loadEnergyValueFromNBT(energyValueTagCompound);
}
else
{
energyValue = new EnergyValue(0);
storedEnergyValue = new EnergyValue(0);
}
}
@ -149,11 +149,11 @@ public class TileEntityTransmutationTablet extends TileEntityEE implements ISide
nbtTagCompound.setTag(Names.NBT.ITEMS, tagList);
NBTTagCompound energyValueTagCompound = new NBTTagCompound();
if (energyValue != null)
if (storedEnergyValue != null)
{
energyValue.writeToNBT(energyValueTagCompound);
storedEnergyValue.writeToNBT(energyValueTagCompound);
}
nbtTagCompound.setTag("energyValue", energyValueTagCompound);
nbtTagCompound.setTag("storedEnergyValue", energyValueTagCompound);
}
@Override
@ -221,7 +221,7 @@ public class TileEntityTransmutationTablet extends TileEntityEE implements ISide
newEnergyValue += EnergyValueRegistry.getInstance().getEnergyValue(inventory[i]).getEnergyValue() * inventory[i].stackSize;
}
}
this.energyValue = new EnergyValue(newEnergyValue);
this.storedEnergyValue = new EnergyValue(newEnergyValue);
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 46 KiB