mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-20 12:19:55 +00:00
Merge branch 'master' of https://github.com/CrazyPants/EnderIO.git
This commit is contained in:
commit
fb1cd698e8
8 files changed
+139
-87
No files matched your search
@@ -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";
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user