diff --git a/resources/assets/enderio/lang/de_DE.lang b/resources/assets/enderio/lang/de_DE.lang index 7745e140..cead18f8 100644 --- a/resources/assets/enderio/lang/de_DE.lang +++ b/resources/assets/enderio/lang/de_DE.lang @@ -167,6 +167,7 @@ tile.blockAlloySmelter.tooltip.detailed.line5=Geschw. und Energiespeicher erhöh tile.blockSolarPanel.name=Photovoltaikzelle tile.blockSolarPanel.advanced.name=Fortgeschrittene Photovoltaikzelle +tile.blockSolarPanel.tooltip.common.line1=Solarenergie! tile.blockSolarPanel.tooltip.detailed.line1=Produziert Energie am Tag tile.blockSolarPanel.tooltip.detailed.line2=Braucht klare Sicht tile.blockSolarPanel.tooltip.detailed.line3=zum Himmel diff --git a/resources/assets/enderio/lang/en_US.lang b/resources/assets/enderio/lang/en_US.lang index d93db6e0..9d67b10d 100644 --- a/resources/assets/enderio/lang/en_US.lang +++ b/resources/assets/enderio/lang/en_US.lang @@ -244,6 +244,7 @@ tile.blockAlloySmelter.tooltip.detailed.line5=speed and energy storage tile.blockSolarPanel.name=Photovoltaic Cell tile.blockSolarPanel.advanced.name=Advanced Photovoltaic Cell +tile.blockSolarPanel.tooltip.common.line1=Solar power! tile.blockSolarPanel.tooltip.detailed.line1=Produces power during daylight hours tile.blockSolarPanel.tooltip.detailed.line2=Must have a clear line of sight to tile.blockSolarPanel.tooltip.detailed.line3=the sky @@ -880,6 +881,10 @@ enderio.gui.conduit.item.roundRobinEnabled=Round Robin Enabled enderio.gui.conduit.item.roundRobinDisabled=Round Robin Disabled enderio.gui.conduit.item.priority=Priority +enderio.gui.conduit.item.filterupgrade=Insert Item Filter +enderio.gui.conduit.item.speedupgrade=Insert Item Conduit Speed Up-/ Downgrade +enderio.gui.conduit.item.speedupgrade2=Max upgrades is 15; Max downgrades is 1 + enderio.gui.conduit.redstone.signalColor=Signal Color enderio.gui.conduit.redstone.color=Color enderio.gui.conduit.redstone.signalStrengh=Strong Signal diff --git a/src/main/java/crazypants/enderio/api/IMC.java b/src/main/java/crazypants/enderio/api/IMC.java index d157e02a..2abc339e 100644 --- a/src/main/java/crazypants/enderio/api/IMC.java +++ b/src/main/java/crazypants/enderio/api/IMC.java @@ -66,14 +66,14 @@ public final class IMC { /** * Key for an ItemStack message to add an item to the Painters paint source * whitelist. Calls - * {@link PaintSourceValidator#addToWhitelist(net.minecraft.item.ItemStack) + * {@link PaintSourceValidator#addToWhitelist(net.minecraft.item.ItemStack)} */ public static final String PAINTER_WHITELIST_ADD = "painter:whitelist:add"; /** * Key for an ItemStack message to add an item to the Painters paint source * blacklist. Calls - * {@link PaintSourceValidator#addToBlacklist(net.minecraft.item.ItemStack) + * {@link PaintSourceValidator#addToBlacklist(net.minecraft.item.ItemStack)} */ public static final String PAINTER_BLACKLIST_ADD = "painter:blacklist:add"; diff --git a/src/main/java/crazypants/enderio/gui/TooltipAddera.java b/src/main/java/crazypants/enderio/gui/TooltipAddera.java index ede5a5a7..1e83d649 100644 --- a/src/main/java/crazypants/enderio/gui/TooltipAddera.java +++ b/src/main/java/crazypants/enderio/gui/TooltipAddera.java @@ -285,23 +285,29 @@ public class TooltipAddera { } } + private static String getUnlocalizedNameForTooltip(ItemStack itemstack) { + String unlocalizedNameForTooltip = null; + if (itemstack.getItem() instanceof IResourceTooltipProvider) { + unlocalizedNameForTooltip = ((IResourceTooltipProvider)itemstack.getItem()).getUnlocalizedNameForTooltip(itemstack); + } + if(unlocalizedNameForTooltip == null) { + unlocalizedNameForTooltip = itemstack.getItem().getUnlocalizedName(itemstack); + } + return unlocalizedNameForTooltip; + } + + public static void addCommonTooltipFromResources(List list, ItemStack itemstack) { + if(itemstack.getItem() == null) { + return; + } + addCommonTooltipFromResources(list, getUnlocalizedNameForTooltip(itemstack)); + } + public static void addDetailedTooltipFromResources(List list, ItemStack itemstack) { if(itemstack.getItem() == null) { return; } - String unloc = null; - // Block blk = Block.getBlockFromItem(itemstack.getItem()); - // if(blk != null && blk != Blocks.air) { - // unlock = blk.getUnlocalizedName(); - // } - - if (itemstack.getItem() instanceof IResourceTooltipProvider) { - unloc = ((IResourceTooltipProvider)itemstack.getItem()).getUnlocalizedNameForTooltip(itemstack); - } - if(unloc == null) { - unloc = itemstack.getItem().getUnlocalizedName(itemstack); - } - addDetailedTooltipFromResources(list, unloc); + addDetailedTooltipFromResources(list, getUnlocalizedNameForTooltip(itemstack)); } private static class BallTipProvider implements IAdvancedTooltipProvider { diff --git a/src/main/java/crazypants/enderio/machine/solar/BlockItemSolarPanel.java b/src/main/java/crazypants/enderio/machine/solar/BlockItemSolarPanel.java index 90060cd2..a15ec040 100644 --- a/src/main/java/crazypants/enderio/machine/solar/BlockItemSolarPanel.java +++ b/src/main/java/crazypants/enderio/machine/solar/BlockItemSolarPanel.java @@ -12,11 +12,12 @@ import crazypants.enderio.EnderIO; import crazypants.enderio.EnderIOTab; import crazypants.enderio.config.Config; import crazypants.enderio.gui.IAdvancedTooltipProvider; +import crazypants.enderio.gui.IResourceTooltipProvider; import crazypants.enderio.gui.TooltipAddera; import crazypants.enderio.machine.power.PowerDisplayUtil; import crazypants.util.Lang; -public class BlockItemSolarPanel extends ItemBlockWithMetadata implements IAdvancedTooltipProvider{ +public class BlockItemSolarPanel extends ItemBlockWithMetadata implements IAdvancedTooltipProvider, IResourceTooltipProvider { public BlockItemSolarPanel() { super(EnderIO.blockSolarPanel, EnderIO.blockSolarPanel); @@ -52,6 +53,7 @@ public class BlockItemSolarPanel extends ItemBlockWithMetadata implements IAdvan @SuppressWarnings("rawtypes") @Override public void addCommonEntries(ItemStack itemstack, EntityPlayer entityplayer, List list, boolean flag) { + TooltipAddera.addCommonTooltipFromResources(list, itemstack); } @SuppressWarnings("rawtypes") @@ -70,4 +72,9 @@ public class BlockItemSolarPanel extends ItemBlockWithMetadata implements IAdvan list.add(Lang.localize("maxSolorProduction") + " " + PowerDisplayUtil.formatPowerPerTick(prod)); } + @Override + public String getUnlocalizedNameForTooltip(ItemStack itemStack) { + return super.getUnlocalizedName(itemStack); + } + } diff --git a/src/main/java/crazypants/enderio/machine/vacuum/BlockVacuumChest.java b/src/main/java/crazypants/enderio/machine/vacuum/BlockVacuumChest.java index 8f27803c..cfc231eb 100644 --- a/src/main/java/crazypants/enderio/machine/vacuum/BlockVacuumChest.java +++ b/src/main/java/crazypants/enderio/machine/vacuum/BlockVacuumChest.java @@ -40,7 +40,8 @@ public class BlockVacuumChest extends BlockEio implements IGuiHandler, IResource protected boolean openGui(World world, int x, int y, int z, EntityPlayer entityPlayer, int side) { if(!world.isRemote) { entityPlayer.openGui(EnderIO.instance, GuiHandler.GUI_ID_VACUUM_CHEST, world, x, y, z); - } return super.openGui(world, x, y, z, entityPlayer, side); + } + return true; } @Override diff --git a/src/main/java/crazypants/enderio/machine/vacuum/TileVacuumChest.java b/src/main/java/crazypants/enderio/machine/vacuum/TileVacuumChest.java index 57a49c9f..4219f7c6 100644 --- a/src/main/java/crazypants/enderio/machine/vacuum/TileVacuumChest.java +++ b/src/main/java/crazypants/enderio/machine/vacuum/TileVacuumChest.java @@ -80,7 +80,7 @@ public class TileVacuumChest extends TileEntityEio implements IEntitySelector, I EntityItem item = (EntityItem) entity; ItemStack stack = item.getEntityItem().copy(); - int numInserted = ItemUtil.doInsertItem(this, stack); + int numInserted = ItemUtil.doInsertItem(this, stack, null); stack.stackSize -= numInserted; item.setEntityItemStack(stack); if(stack.stackSize == 0) { diff --git a/src/main/java/crazypants/util/ItemUtil.java b/src/main/java/crazypants/util/ItemUtil.java index f1840d10..d15cc760 100644 --- a/src/main/java/crazypants/util/ItemUtil.java +++ b/src/main/java/crazypants/util/ItemUtil.java @@ -47,9 +47,9 @@ public class ItemUtil { return 0; } if(into instanceof ISidedInventory) { - return ItemUtil.doInsertItem((ISidedInventory) into, item, side); + return ItemUtil.doInsertItemInv((ISidedInventory) into, item, side); } else if(into instanceof IInventory) { - return ItemUtil.doInsertItem(getInventory((IInventory) into), item); + return ItemUtil.doInsertItemInv(getInventory((IInventory) into), item, side); } else if(into instanceof IItemDuct) { return ItemUtil.doInsertItem((IItemDuct) into, item, side); } @@ -72,93 +72,77 @@ public class ItemUtil { return startedWith - remaining.stackSize; } - public static int doInsertItem(ISidedInventory sidedInv, ItemStack item, ForgeDirection inventorySide) { + /* + * Insert items into an IInventory or an ISidedInventory. + */ + private static int doInsertItemInv(IInventory inv, ItemStack item, ForgeDirection inventorySide) { + ISidedInventory sidedInv = inv instanceof ISidedInventory ? (ISidedInventory) inv : null; + ISlotIterator slots; - if(inventorySide == null) { - inventorySide = ForgeDirection.UNKNOWN; - } - - int[] slots = sidedInv.getAccessibleSlotsFromSide(inventorySide.ordinal()); - if(slots == null) { - return 0; + if (sidedInv != null) { + if(inventorySide == null) { + inventorySide = ForgeDirection.UNKNOWN; + } + slots = new sidedSlotter(sidedInv.getAccessibleSlotsFromSide(inventorySide.ordinal())); + } else { + slots = new invSlotter(inv.getSizeInventory()); } + int numInserted = 0; int numToInsert = item.stackSize; - for (int i = 0; i < slots.length && numToInsert > 0; i++) { - int slot = slots[i]; - if(sidedInv.canInsertItem(slot, item, inventorySide.ordinal())) { - ItemStack contents = sidedInv.getStackInSlot(slot); - ItemStack toInsert = item.copy(); - toInsert.stackSize = Math.min(toInsert.stackSize, sidedInv.getInventoryStackLimit()); - toInsert.stackSize = Math.min(toInsert.stackSize, toInsert.getMaxStackSize()); // some inventories like using itemstacks with invalid stack sizes - toInsert.stackSize = Math.min(toInsert.stackSize, numToInsert); - int inserted = 0; - if(contents == null) { - inserted = toInsert.stackSize; - } else { - if(contents.isItemEqual(item) && ItemStack.areItemStackTagsEqual(contents, item)) { - int space = sidedInv.getInventoryStackLimit() - contents.stackSize; - space = Math.min(space, contents.getMaxStackSize() - contents.stackSize); - inserted += Math.min(space, toInsert.stackSize); - toInsert.stackSize = contents.stackSize + inserted; - } else { - toInsert.stackSize = 0; - } - } - if(inserted > 0) { - numInserted += inserted; - numToInsert -= inserted; - sidedInv.setInventorySlotContents(slot, toInsert); + // PASS1: Try to add to an existing stack + while (numToInsert > 0 && slots.hasNext()) { + int slot = slots.nextSlot(); + if(sidedInv == null || sidedInv.canInsertItem(slot, item, inventorySide.ordinal())) { + ItemStack contents = inv.getStackInSlot(slot); + if(contents != null && areStackMergable(contents, item)) { + int freeSpace = Math.min(inv.getInventoryStackLimit(), contents.getMaxStackSize()) - contents.stackSize; // some inventories like using itemstacks with invalid stack sizes + if (freeSpace > 0) { + int noToInsert = Math.min(numToInsert, freeSpace); + ItemStack toInsert = item.copy(); + toInsert.stackSize = contents.stackSize + noToInsert; + // isItemValidForSlot() may check the stacksize, so give it the number the stack would have in the end. + // If it does something funny, like "only even numbers", we are screwed. + if(sidedInv != null || inv.isItemValidForSlot(slot, toInsert)) { + numInserted += noToInsert; + numToInsert -= noToInsert; + inv.setInventorySlotContents(slot, toInsert); + } + } } } } - if(numInserted > 0) { - sidedInv.markDirty(); - } - return numInserted; - } - public static int doInsertItem(IInventory inv, ItemStack item) { - int numInserted = 0; - int numToInsert = item.stackSize; - for (int slot = 0; slot < inv.getSizeInventory() && numToInsert > 0; slot++) { - ItemStack contents = inv.getStackInSlot(slot); - if(!isStackFull(contents)) { - ItemStack toInsert = item.copy(); - toInsert.stackSize = Math.min(toInsert.stackSize, inv.getInventoryStackLimit()); - toInsert.stackSize = Math.min(toInsert.stackSize, toInsert.getMaxStackSize()); // some inventories like using itemstacks with invalid stack sizes - toInsert.stackSize = Math.min(toInsert.stackSize, numToInsert); - int inserted = 0; + slots.reset(); + // PASS2: Try to insert into an empty slot + while (numToInsert > 0 && slots.hasNext()) { + int slot = slots.nextSlot(); + if(sidedInv == null || sidedInv.canInsertItem(slot, item, inventorySide.ordinal())) { + ItemStack contents = inv.getStackInSlot(slot); if(contents == null) { - inserted = toInsert.stackSize; - } else { - if(contents.isItemEqual(item) && ItemStack.areItemStackTagsEqual(contents, item)) { - int space = inv.getInventoryStackLimit() - contents.stackSize; - space = Math.min(space, contents.getMaxStackSize() - contents.stackSize); - inserted += Math.min(space, toInsert.stackSize); - toInsert.stackSize = contents.stackSize + inserted; - } else { - toInsert.stackSize = 0; + ItemStack toInsert = item.copy(); + toInsert.stackSize = min(numToInsert, inv.getInventoryStackLimit(), toInsert.getMaxStackSize()); // some inventories like using itemstacks with invalid stack sizes + if(sidedInv != null || inv.isItemValidForSlot(slot, toInsert)) { + numInserted += toInsert.stackSize; + numToInsert -= toInsert.stackSize; + inv.setInventorySlotContents(slot, toInsert); } } - if(!inv.isItemValidForSlot(slot, toInsert)) { - inserted = 0; - } - - if(inserted > 0) { - numInserted += inserted; - numToInsert -= inserted; - inv.setInventorySlotContents(slot, toInsert); - } } } + if(numInserted > 0) { inv.markDirty(); } return numInserted; + } + private static int min(int i1, int i2, int i3) { + return i1 < i2 ? (i1 < i3 ? i1 : i3) : (i2 < i3 ? i2 : i3); + } + public static boolean isStackFull(ItemStack contents) { if(contents == null) { return false; @@ -221,4 +205,52 @@ public class ItemUtil { return ItemStack.areItemStackTagsEqual(s1, s2); } + private interface ISlotIterator { + int nextSlot(); + boolean hasNext(); + void reset(); + } + + private static class invSlotter implements ISlotIterator { + final private int size; + private int current; + invSlotter(int size) { + this.size = size; + this.current = 0; + } + @Override + public int nextSlot() { + return current++; + } + @Override + public void reset() { + current = 0; + } + @Override + public boolean hasNext() { + return current < size; + } + } + + private static class sidedSlotter implements ISlotIterator { + final private int[] slots; + private int current; + sidedSlotter(int[] slots) { + this.slots = slots; + this.current = 0; + } + @Override + public int nextSlot() { + return slots[current++]; + } + @Override + public void reset() { + current = 0; + } + @Override + public boolean hasNext() { + return slots != null && current < slots.length; + } + } + }