Add tooltip to grid filter with the filtered items

This commit is contained in:
Raoul Van den Berge
2016-07-30 01:48:10 +02:00
parent 947ace31b8
commit bd89dd3c17
8 changed files with 40 additions and 29 deletions

View File

@@ -28,4 +28,8 @@ public class ItemHandlerGridFilter extends ItemStackHandler {
TileBase.writeItems(this, 0, stack.getTagCompound()); TileBase.writeItems(this, 0, stack.getTagCompound());
} }
public ItemStack[] getFilteredItems() {
return stacks;
}
} }

View File

@@ -2,7 +2,6 @@ package refinedstorage.inventory;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import refinedstorage.RefinedStorageItems; import refinedstorage.RefinedStorageItems;
import refinedstorage.tile.TileBase;
import java.util.List; import java.util.List;
@@ -23,14 +22,10 @@ public class ItemHandlerGridFilterInGrid extends ItemHandlerBasic {
ItemStack stack = getStackInSlot(slot); ItemStack stack = getStackInSlot(slot);
if (stack != null && stack.hasTagCompound()) { if (stack != null) {
ItemHandlerBasic items = new ItemHandlerBasic(9 * 3); ItemHandlerGridFilter items = new ItemHandlerGridFilter(stack);
TileBase.readItems(items, 0, stack.getTagCompound());
for (int i = 0; i < items.getSlots(); ++i) {
ItemStack item = items.getStackInSlot(i);
for (ItemStack item : items.getFilteredItems()) {
if (item != null) { if (item != null) {
filteredItems.add(item); filteredItems.add(item);
} }

View File

@@ -18,7 +18,7 @@ public class ItemBlockController extends ItemBlockBase {
} }
@Override @Override
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean b) { public void addInformation(ItemStack stack, EntityPlayer player, List<String> tooltip, boolean advanced) {
if (stack.getMetadata() != EnumControllerType.CREATIVE.getId()) { if (stack.getMetadata() != EnumControllerType.CREATIVE.getId()) {
int energyStored = 0; int energyStored = 0;
int energyCapacity = RefinedStorage.INSTANCE.controllerCapacity; int energyCapacity = RefinedStorage.INSTANCE.controllerCapacity;
@@ -33,7 +33,7 @@ public class ItemBlockController extends ItemBlockBase {
} }
} }
list.add(I18n.format("misc.refinedstorage:energy_stored", energyStored, energyCapacity)); tooltip.add(I18n.format("misc.refinedstorage:energy_stored", energyStored, energyCapacity));
} }
} }

View File

@@ -24,16 +24,16 @@ public class ItemBlockStorage extends ItemBlockBase {
} }
@Override @Override
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean b) { public void addInformation(ItemStack stack, EntityPlayer player, List<String> tooltip, boolean advanced) {
EnumStorageType type = EnumStorageType.getById(stack.getMetadata()); EnumStorageType type = EnumStorageType.getById(stack.getMetadata());
if (type != null && isValid(stack)) { if (type != null && isValid(stack)) {
NBTTagCompound tag = stack.getTagCompound().getCompoundTag(TileStorage.NBT_STORAGE); NBTTagCompound tag = stack.getTagCompound().getCompoundTag(TileStorage.NBT_STORAGE);
if (type == EnumStorageType.TYPE_CREATIVE) { if (type == EnumStorageType.TYPE_CREATIVE) {
list.add(I18n.format("misc.refinedstorage:storage.stored", NBTStorage.getStoredFromNBT(tag))); tooltip.add(I18n.format("misc.refinedstorage:storage.stored", NBTStorage.getStoredFromNBT(tag)));
} else { } else {
list.add(I18n.format("misc.refinedstorage:storage.stored_capacity", NBTStorage.getStoredFromNBT(tag), type.getCapacity())); tooltip.add(I18n.format("misc.refinedstorage:storage.stored_capacity", NBTStorage.getStoredFromNBT(tag), type.getCapacity()));
} }
} }
} }

View File

@@ -9,6 +9,9 @@ import net.minecraft.world.World;
import refinedstorage.RefinedStorage; import refinedstorage.RefinedStorage;
import refinedstorage.RefinedStorageGui; import refinedstorage.RefinedStorageGui;
import refinedstorage.RefinedStorageItems; import refinedstorage.RefinedStorageItems;
import refinedstorage.inventory.ItemHandlerGridFilter;
import java.util.List;
public class ItemGridFilter extends ItemBase { public class ItemGridFilter extends ItemBase {
public ItemGridFilter() { public ItemGridFilter() {
@@ -31,4 +34,13 @@ public class ItemGridFilter extends ItemBase {
return new ActionResult(EnumActionResult.PASS, stack); return new ActionResult(EnumActionResult.PASS, stack);
} }
@Override
public void addInformation(ItemStack stack, EntityPlayer player, List<String> tooltip, boolean advanced) {
super.addInformation(stack, player, tooltip, advanced);
ItemHandlerGridFilter items = new ItemHandlerGridFilter(stack);
ItemPattern.combineItems(tooltip, items.getFilteredItems());
}
} }

View File

@@ -30,25 +30,25 @@ public class ItemPattern extends ItemBase {
} }
@Override @Override
public void addInformation(ItemStack pattern, EntityPlayer player, List list, boolean b) { public void addInformation(ItemStack pattern, EntityPlayer player, List<String> tooltip, boolean advanced) {
if (isValid(pattern)) { if (isValid(pattern)) {
if (GuiScreen.isShiftKeyDown() || isProcessing(pattern)) { if (GuiScreen.isShiftKeyDown() || isProcessing(pattern)) {
list.add(TextFormatting.YELLOW + I18n.format("misc.refinedstorage:pattern.inputs") + TextFormatting.RESET); tooltip.add(TextFormatting.YELLOW + I18n.format("misc.refinedstorage:pattern.inputs") + TextFormatting.RESET);
combineItems(list, getInputs(pattern)); combineItems(tooltip, getInputs(pattern));
list.add(TextFormatting.YELLOW + I18n.format("misc.refinedstorage:pattern.outputs") + TextFormatting.RESET); tooltip.add(TextFormatting.YELLOW + I18n.format("misc.refinedstorage:pattern.outputs") + TextFormatting.RESET);
} }
combineItems(list, getOutputs(pattern)); combineItems(tooltip, getOutputs(pattern));
} }
} }
private void combineItems(List<String> lines, ItemStack... stacks) { public static void combineItems(List<String> tooltip, ItemStack... stacks) {
Set<Integer> combinedIndices = new HashSet<Integer>(); Set<Integer> combinedIndices = new HashSet<Integer>();
for (int i = 0; i < stacks.length; ++i) { for (int i = 0; i < stacks.length; ++i) {
if (!combinedIndices.contains(i)) { if (stacks[i] != null && !combinedIndices.contains(i)) {
String data = stacks[i].getDisplayName(); String data = stacks[i].getDisplayName();
int amount = stacks[i].stackSize; int amount = stacks[i].stackSize;
@@ -65,7 +65,7 @@ public class ItemPattern extends ItemBase {
data += " (" + amount + "x)"; data += " (" + amount + "x)";
} }
lines.add(data); tooltip.add(data);
} }
} }
} }

View File

@@ -92,14 +92,14 @@ public class ItemStorageDisk extends ItemBase {
} }
@Override @Override
public void addInformation(ItemStack disk, EntityPlayer player, List list, boolean b) { public void addInformation(ItemStack disk, EntityPlayer player, List<String> tooltip, boolean advanced) {
if (NBTStorage.isValid(disk)) { if (NBTStorage.isValid(disk)) {
int capacity = EnumStorageType.getById(disk.getItemDamage()).getCapacity(); int capacity = EnumStorageType.getById(disk.getItemDamage()).getCapacity();
if (capacity == -1) { if (capacity == -1) {
list.add(I18n.format("misc.refinedstorage:storage.stored", NBTStorage.getStoredFromNBT(disk.getTagCompound()))); tooltip.add(I18n.format("misc.refinedstorage:storage.stored", NBTStorage.getStoredFromNBT(disk.getTagCompound())));
} else { } else {
list.add(I18n.format("misc.refinedstorage:storage.stored_capacity", NBTStorage.getStoredFromNBT(disk.getTagCompound()), capacity)); tooltip.add(I18n.format("misc.refinedstorage:storage.stored_capacity", NBTStorage.getStoredFromNBT(disk.getTagCompound()), capacity));
} }
} }
} }

View File

@@ -106,15 +106,15 @@ public class ItemWirelessGrid extends ItemEnergyContainer implements ISpecialEle
} }
@Override @Override
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean b) { public void addInformation(ItemStack stack, EntityPlayer player, List<String> tooltip, boolean advanced) {
if (stack.getItemDamage() != TYPE_CREATIVE) { if (stack.getItemDamage() != TYPE_CREATIVE) {
list.add(I18n.format("misc.refinedstorage:energy_stored", getEnergyStored(stack), getMaxEnergyStored(stack))); tooltip.add(I18n.format("misc.refinedstorage:energy_stored", getEnergyStored(stack), getMaxEnergyStored(stack)));
} }
if (hasValidNBT(stack)) { if (hasValidNBT(stack)) {
list.add(I18n.format("misc.refinedstorage:wireless_grid.tooltip.0", getX(stack))); tooltip.add(I18n.format("misc.refinedstorage:wireless_grid.tooltip.0", getX(stack)));
list.add(I18n.format("misc.refinedstorage:wireless_grid.tooltip.1", getY(stack))); tooltip.add(I18n.format("misc.refinedstorage:wireless_grid.tooltip.1", getY(stack)));
list.add(I18n.format("misc.refinedstorage:wireless_grid.tooltip.2", getZ(stack))); tooltip.add(I18n.format("misc.refinedstorage:wireless_grid.tooltip.2", getZ(stack)));
} }
} }