Use ItemHandlerHelper some more
This commit is contained in:
		| @@ -161,7 +161,7 @@ public class GuiGrid extends GuiBase { | |||||||
|  |  | ||||||
|     public boolean isHoveringOverCreatePattern(int mouseX, int mouseY) { |     public boolean isHoveringOverCreatePattern(int mouseX, int mouseY) { | ||||||
|         if (grid.getType() == EnumGridType.PATTERN) { |         if (grid.getType() == EnumGridType.PATTERN) { | ||||||
|             return inBounds(152, 124, 16, 16, mouseX, mouseY) && ((TileGrid) grid).canCreatePattern(); |             return inBounds(152, 124, 16, 16, mouseX, mouseY) && ((TileGrid) grid).mayCreatePattern(); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         return false; |         return false; | ||||||
| @@ -186,7 +186,7 @@ public class GuiGrid extends GuiBase { | |||||||
|                 ty = 1; |                 ty = 1; | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             if (!((TileGrid) grid).canCreatePattern()) { |             if (!((TileGrid) grid).mayCreatePattern()) { | ||||||
|                 ty = 2; |                 ty = 2; | ||||||
|             } |             } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -27,7 +27,7 @@ public class GuiProcessingPatternEncoder extends GuiBase { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public boolean isHoveringOverCreatePattern(int mouseX, int mouseY) { |     public boolean isHoveringOverCreatePattern(int mouseX, int mouseY) { | ||||||
|         return inBounds(152, 38, 16, 16, mouseX, mouseY) && ppEncoder.canCreatePattern(); |         return inBounds(152, 38, 16, 16, mouseX, mouseY) && ppEncoder.mayCreatePattern(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
| @@ -42,7 +42,7 @@ public class GuiProcessingPatternEncoder extends GuiBase { | |||||||
|             ty = 1; |             ty = 1; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         if (!ppEncoder.canCreatePattern()) { |         if (!ppEncoder.mayCreatePattern()) { | ||||||
|             ty = 2; |             ty = 2; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -21,6 +21,6 @@ public class DiskStorage extends NBTStorage { | |||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public boolean mayPush(ItemStack stack) { |     public boolean mayPush(ItemStack stack) { | ||||||
|         return ModeFilter.violatesMode(diskDrive.getInventory(), diskDrive.getModeConfig(), diskDrive.getCompare(), stack) && super.mayPush(stack); |         return ModeFilter.respectsMode(diskDrive.getInventory(), diskDrive.getModeConfig(), diskDrive.getCompare(), stack) && super.mayPush(stack); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -4,6 +4,7 @@ import net.minecraft.item.Item; | |||||||
| import net.minecraft.item.ItemStack; | import net.minecraft.item.ItemStack; | ||||||
| import net.minecraft.nbt.NBTTagCompound; | import net.minecraft.nbt.NBTTagCompound; | ||||||
| import net.minecraft.nbt.NBTTagList; | import net.minecraft.nbt.NBTTagList; | ||||||
|  | import net.minecraftforge.items.ItemHandlerHelper; | ||||||
|  |  | ||||||
| import java.util.ArrayList; | import java.util.ArrayList; | ||||||
| import java.util.List; | import java.util.List; | ||||||
| @@ -110,13 +111,9 @@ public abstract class NBTStorage implements IStorage { | |||||||
|  |  | ||||||
|                 tag.setInteger(NBT_STORED, getStored(tag) - quantity); |                 tag.setInteger(NBT_STORED, getStored(tag) - quantity); | ||||||
|  |  | ||||||
|                 ItemStack result = group.toStack(); |  | ||||||
|  |  | ||||||
|                 result.stackSize = quantity; |  | ||||||
|  |  | ||||||
|                 markDirty(); |                 markDirty(); | ||||||
|  |  | ||||||
|                 return result; |                 return ItemHandlerHelper.copyStackWithSize(group.toStack(), quantity); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -20,6 +20,6 @@ public class StorageBlockStorage extends NBTStorage { | |||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public boolean mayPush(ItemStack stack) { |     public boolean mayPush(ItemStack stack) { | ||||||
|         return ModeFilter.violatesMode(storage.getInventory(), storage, storage.getCompare(), stack) && super.mayPush(stack); |         return ModeFilter.respectsMode(storage.getInventory(), storage, storage.getCompare(), stack) && super.mayPush(stack); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -50,10 +50,10 @@ public class TileConstructor extends TileMachine implements ICompareConfig { | |||||||
|                     SoundType blockSound = block.getStepSound(); |                     SoundType blockSound = block.getStepSound(); | ||||||
|                     worldObj.playSound(null, front, blockSound.getPlaceSound(), SoundCategory.BLOCKS, (blockSound.getVolume() + 1.0F) / 2.0F, blockSound.getPitch() * 0.8F); |                     worldObj.playSound(null, front, blockSound.getPlaceSound(), SoundCategory.BLOCKS, (blockSound.getVolume() + 1.0F) / 2.0F, blockSound.getPitch() * 0.8F); | ||||||
|                 } else if (RefinedStorageUtils.hasUpgrade(upgradesInventory, ItemUpgrade.TYPE_CRAFTING)) { |                 } else if (RefinedStorageUtils.hasUpgrade(upgradesInventory, ItemUpgrade.TYPE_CRAFTING)) { | ||||||
|                     ItemStack toCraft = inventory.getStackInSlot(0); |                     ItemStack craft = inventory.getStackInSlot(0); | ||||||
|  |  | ||||||
|                     if (scheduler.canSchedule(compare, toCraft)) { |                     if (scheduler.canSchedule(compare, craft)) { | ||||||
|                         scheduler.schedule(controller, compare, toCraft); |                         scheduler.schedule(controller, compare, craft); | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|   | |||||||
| @@ -44,13 +44,16 @@ public class TileController extends TileBase implements IEnergyReceiver, ISynchr | |||||||
|         public int energyUsage; |         public int energyUsage; | ||||||
|  |  | ||||||
|         @Override |         @Override | ||||||
|         public boolean equals(Object o) { |         public boolean equals(Object other) { | ||||||
|             if (this == o) return true; |             if (this == other) { | ||||||
|             if (o == null || getClass() != o.getClass()) return false; |                 return true; | ||||||
|  |             } | ||||||
|  |  | ||||||
|             ClientSideMachine other = (ClientSideMachine) o; |             if (!(other instanceof ClientSideMachine)) { | ||||||
|  |                 return false; | ||||||
|  |             } | ||||||
|  |  | ||||||
|             return energyUsage == other.energyUsage && RefinedStorageUtils.compareStack(stack, other.stack); |             return energyUsage == ((ClientSideMachine) other).energyUsage && RefinedStorageUtils.compareStack(stack, ((ClientSideMachine) other).stack); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         @Override |         @Override | ||||||
|   | |||||||
| @@ -45,7 +45,7 @@ public class TileDestructor extends TileMachine implements ICompareConfig, IMode | |||||||
|             Block frontBlock = frontBlockState.getBlock(); |             Block frontBlock = frontBlockState.getBlock(); | ||||||
|  |  | ||||||
|             if (Item.getItemFromBlock(frontBlock) != null && !frontBlock.isAir(frontBlockState, worldObj, front)) { |             if (Item.getItemFromBlock(frontBlock) != null && !frontBlock.isAir(frontBlockState, worldObj, front)) { | ||||||
|                 if (ModeFilter.violatesMode(inventory, this, compare, new ItemStack(frontBlock, 1, frontBlock.getMetaFromState(frontBlockState)))) { |                 if (ModeFilter.respectsMode(inventory, this, compare, new ItemStack(frontBlock, 1, frontBlock.getMetaFromState(frontBlockState)))) { | ||||||
|                     List<ItemStack> drops = frontBlock.getDrops(worldObj, front, frontBlockState, 0); |                     List<ItemStack> drops = frontBlock.getDrops(worldObj, front, frontBlockState, 0); | ||||||
|  |  | ||||||
|                     worldObj.playAuxSFXAtEntity(null, 2001, front, Block.getStateId(frontBlockState)); |                     worldObj.playAuxSFXAtEntity(null, 2001, front, Block.getStateId(frontBlockState)); | ||||||
|   | |||||||
| @@ -6,6 +6,7 @@ import net.minecraft.inventory.IInventory; | |||||||
| import net.minecraft.item.ItemStack; | import net.minecraft.item.ItemStack; | ||||||
| import net.minecraft.nbt.NBTTagCompound; | import net.minecraft.nbt.NBTTagCompound; | ||||||
| import net.minecraftforge.items.IItemHandler; | import net.minecraftforge.items.IItemHandler; | ||||||
|  | import net.minecraftforge.items.ItemHandlerHelper; | ||||||
| import refinedstorage.RefinedStorageUtils; | import refinedstorage.RefinedStorageUtils; | ||||||
| import refinedstorage.container.ContainerExporter; | import refinedstorage.container.ContainerExporter; | ||||||
| import refinedstorage.inventory.InventorySimple; | import refinedstorage.inventory.InventorySimple; | ||||||
| @@ -36,21 +37,16 @@ public class TileExporter extends TileMachine implements ICompareConfig { | |||||||
|                 ItemStack slot = inventory.getStackInSlot(i); |                 ItemStack slot = inventory.getStackInSlot(i); | ||||||
|  |  | ||||||
|                 if (slot != null) { |                 if (slot != null) { | ||||||
|                     ItemStack taking = slot.copy(); |                     ItemStack took = controller.take(ItemHandlerHelper.copyStackWithSize(slot, 1), compare); | ||||||
|                     taking.stackSize = 1; |  | ||||||
|  |  | ||||||
|                     ItemStack took = controller.take(taking, compare); |  | ||||||
|  |  | ||||||
|                     if (took != null) { |                     if (took != null) { | ||||||
|                         scheduler.resetSchedule(); |                         scheduler.resetSchedule(); | ||||||
|  |  | ||||||
|                         for (int j = 0; j < handler.getSlots(); ++j) { |                         if (ItemHandlerHelper.insertItem(handler, took, true) == null) { | ||||||
|                             if (handler.insertItem(j, took, true) == null) { |                             ItemHandlerHelper.insertItem(handler, took, false); | ||||||
|                                 handler.insertItem(j, took, false); |  | ||||||
|  |  | ||||||
|                             return; |                             return; | ||||||
|                         } |                         } | ||||||
|                         } |  | ||||||
|  |  | ||||||
|                         controller.push(took); |                         controller.push(took); | ||||||
|                     } else if (RefinedStorageUtils.hasUpgrade(upgradesInventory, ItemUpgrade.TYPE_CRAFTING)) { |                     } else if (RefinedStorageUtils.hasUpgrade(upgradesInventory, ItemUpgrade.TYPE_CRAFTING)) { | ||||||
|   | |||||||
| @@ -6,6 +6,7 @@ import net.minecraft.inventory.IInventory; | |||||||
| import net.minecraft.item.ItemStack; | import net.minecraft.item.ItemStack; | ||||||
| import net.minecraft.nbt.NBTTagCompound; | import net.minecraft.nbt.NBTTagCompound; | ||||||
| import net.minecraftforge.items.IItemHandler; | import net.minecraftforge.items.IItemHandler; | ||||||
|  | import net.minecraftforge.items.ItemHandlerHelper; | ||||||
| import powercrystals.minefactoryreloaded.api.IDeepStorageUnit; | import powercrystals.minefactoryreloaded.api.IDeepStorageUnit; | ||||||
| import refinedstorage.RefinedStorage; | import refinedstorage.RefinedStorage; | ||||||
| import refinedstorage.RefinedStorageUtils; | import refinedstorage.RefinedStorageUtils; | ||||||
| @@ -80,10 +81,8 @@ public class TileExternalStorage extends TileMachine implements IStorageProvider | |||||||
|             IItemHandler handler = getItemHandler(); |             IItemHandler handler = getItemHandler(); | ||||||
|  |  | ||||||
|             if (handler != null) { |             if (handler != null) { | ||||||
|                 for (int i = 0; i < handler.getSlots(); ++i) { |                 if (ItemHandlerHelper.insertItem(handler, stack, false) == null) { | ||||||
|                     if (handler.insertItem(i, stack, false) == null) { |                     return; | ||||||
|                         break; |  | ||||||
|                     } |  | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
| @@ -136,7 +135,7 @@ public class TileExternalStorage extends TileMachine implements IStorageProvider | |||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public boolean mayPush(ItemStack stack) { |     public boolean mayPush(ItemStack stack) { | ||||||
|         if (ModeFilter.violatesMode(inventory, this, compare, stack)) { |         if (ModeFilter.respectsMode(inventory, this, compare, stack)) { | ||||||
|             IDeepStorageUnit storageUnit = getStorageUnit(); |             IDeepStorageUnit storageUnit = getStorageUnit(); | ||||||
|  |  | ||||||
|             if (storageUnit != null) { |             if (storageUnit != null) { | ||||||
| @@ -149,14 +148,12 @@ public class TileExternalStorage extends TileMachine implements IStorageProvider | |||||||
|                 IItemHandler handler = getItemHandler(); |                 IItemHandler handler = getItemHandler(); | ||||||
|  |  | ||||||
|                 if (handler != null) { |                 if (handler != null) { | ||||||
|                     for (int i = 0; i < handler.getSlots(); ++i) { |                     if (ItemHandlerHelper.insertItem(handler, stack, false) == null) { | ||||||
|                         if (handler.insertItem(i, stack, true) == null) { |  | ||||||
|                         return true; |                         return true; | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         } |  | ||||||
|  |  | ||||||
|         return false; |         return false; | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -9,6 +9,7 @@ import net.minecraft.item.ItemStack; | |||||||
| import net.minecraft.nbt.NBTTagCompound; | import net.minecraft.nbt.NBTTagCompound; | ||||||
| import net.minecraft.util.EnumFacing; | import net.minecraft.util.EnumFacing; | ||||||
| import net.minecraft.util.text.ITextComponent; | import net.minecraft.util.text.ITextComponent; | ||||||
|  | import net.minecraftforge.items.ItemHandlerHelper; | ||||||
| import refinedstorage.RefinedStorageUtils; | import refinedstorage.RefinedStorageUtils; | ||||||
| import refinedstorage.container.ContainerInterface; | import refinedstorage.container.ContainerInterface; | ||||||
| import refinedstorage.inventory.InventorySimple; | import refinedstorage.inventory.InventorySimple; | ||||||
| @@ -48,10 +49,7 @@ public class TileInterface extends TileMachine implements ICompareConfig, ISided | |||||||
|             currentSlot++; |             currentSlot++; | ||||||
|         } else { |         } else { | ||||||
|             if (ticks % RefinedStorageUtils.getSpeed(upgradesInventory) == 0) { |             if (ticks % RefinedStorageUtils.getSpeed(upgradesInventory) == 0) { | ||||||
|                 ItemStack toPush = slot.copy(); |                 if (controller.push(ItemHandlerHelper.copyStackWithSize(slot, 1))) { | ||||||
|                 toPush.stackSize = 1; |  | ||||||
|  |  | ||||||
|                 if (controller.push(toPush)) { |  | ||||||
|                     decrStackSize(currentSlot, 1); |                     decrStackSize(currentSlot, 1); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
| @@ -82,10 +80,7 @@ public class TileInterface extends TileMachine implements ICompareConfig, ISided | |||||||
|                     int needed = got == null ? wanted.stackSize : wanted.stackSize - got.stackSize; |                     int needed = got == null ? wanted.stackSize : wanted.stackSize - got.stackSize; | ||||||
|  |  | ||||||
|                     if (needed > 0) { |                     if (needed > 0) { | ||||||
|                         ItemStack goingToTake = wanted.copy(); |                         ItemStack took = controller.take(ItemHandlerHelper.copyStackWithSize(wanted, needed), compare); | ||||||
|                         goingToTake.stackSize = needed; |  | ||||||
|  |  | ||||||
|                         ItemStack took = controller.take(goingToTake, compare); |  | ||||||
|  |  | ||||||
|                         if (took != null) { |                         if (took != null) { | ||||||
|                             if (got == null) { |                             if (got == null) { | ||||||
|   | |||||||
| @@ -150,7 +150,7 @@ public class TileProcessingPatternEncoder extends TileBase implements ISidedInve | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void onCreatePattern() { |     public void onCreatePattern() { | ||||||
|         if (canCreatePattern()) { |         if (mayCreatePattern()) { | ||||||
|             ItemStack pattern = new ItemStack(RefinedStorageItems.PATTERN); |             ItemStack pattern = new ItemStack(RefinedStorageItems.PATTERN); | ||||||
|  |  | ||||||
|             ItemPattern.setProcessing(pattern, true); |             ItemPattern.setProcessing(pattern, true); | ||||||
| @@ -171,7 +171,7 @@ public class TileProcessingPatternEncoder extends TileBase implements ISidedInve | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public boolean canCreatePattern() { |     public boolean mayCreatePattern() { | ||||||
|         int inputsFilled = 0, outputsFilled = 0; |         int inputsFilled = 0, outputsFilled = 0; | ||||||
|  |  | ||||||
|         for (int i = 0; i < 9; ++i) { |         for (int i = 0; i < 9; ++i) { | ||||||
|   | |||||||
| @@ -4,6 +4,7 @@ import net.minecraft.item.ItemStack; | |||||||
| import net.minecraft.nbt.NBTTagCompound; | import net.minecraft.nbt.NBTTagCompound; | ||||||
| import net.minecraft.util.text.TextFormatting; | import net.minecraft.util.text.TextFormatting; | ||||||
| import net.minecraftforge.items.IItemHandler; | import net.minecraftforge.items.IItemHandler; | ||||||
|  | import net.minecraftforge.items.ItemHandlerHelper; | ||||||
| import refinedstorage.RefinedStorageUtils; | import refinedstorage.RefinedStorageUtils; | ||||||
| import refinedstorage.tile.TileController; | import refinedstorage.tile.TileController; | ||||||
| import refinedstorage.tile.autocrafting.CraftingPattern; | import refinedstorage.tile.autocrafting.CraftingPattern; | ||||||
| @@ -52,17 +53,11 @@ public class ProcessingCraftingTask implements ICraftingTask { | |||||||
|                     ItemStack took = controller.take(input); |                     ItemStack took = controller.take(input); | ||||||
|  |  | ||||||
|                     if (took != null) { |                     if (took != null) { | ||||||
|                         for (int j = 0; j < handler.getSlots(); ++j) { |                         if (ItemHandlerHelper.insertItem(handler, took, true) == null) { | ||||||
|                             if (handler.insertItem(j, took, true) == null) { |                             ItemHandlerHelper.insertItem(handler, took, false); | ||||||
|                                 handler.insertItem(j, took, false); |  | ||||||
|  |  | ||||||
|                             inserted[i] = true; |                             inserted[i] = true; | ||||||
|  |                         } else { | ||||||
|                                 break; |  | ||||||
|                             } |  | ||||||
|                         } |  | ||||||
|  |  | ||||||
|                         if (!inserted[i]) { |  | ||||||
|                             controller.push(took); |                             controller.push(took); | ||||||
|                         } |                         } | ||||||
|                     } else if (!childTasks[i]) { |                     } else if (!childTasks[i]) { | ||||||
|   | |||||||
| @@ -5,7 +5,7 @@ import net.minecraft.item.ItemStack; | |||||||
| import refinedstorage.RefinedStorageUtils; | import refinedstorage.RefinedStorageUtils; | ||||||
|  |  | ||||||
| public class ModeFilter { | public class ModeFilter { | ||||||
|     public static boolean violatesMode(IInventory filters, IModeConfig mode, int compare, ItemStack stack) { |     public static boolean respectsMode(IInventory filters, IModeConfig mode, int compare, ItemStack stack) { | ||||||
|         if (mode.isWhitelist()) { |         if (mode.isWhitelist()) { | ||||||
|             int slots = 0; |             int slots = 0; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -169,7 +169,7 @@ public class TileGrid extends TileMachine implements IGrid { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void onCreatePattern() { |     public void onCreatePattern() { | ||||||
|         if (canCreatePattern()) { |         if (mayCreatePattern()) { | ||||||
|             patternsInventory.decrStackSize(0, 1); |             patternsInventory.decrStackSize(0, 1); | ||||||
|  |  | ||||||
|             ItemStack pattern = new ItemStack(RefinedStorageItems.PATTERN); |             ItemStack pattern = new ItemStack(RefinedStorageItems.PATTERN); | ||||||
| @@ -190,7 +190,7 @@ public class TileGrid extends TileMachine implements IGrid { | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public boolean canCreatePattern() { |     public boolean mayCreatePattern() { | ||||||
|         return craftingResultInventory.getStackInSlot(0) != null && patternsInventory.getStackInSlot(1) == null && patternsInventory.getStackInSlot(0) != null; |         return craftingResultInventory.getStackInSlot(0) != null && patternsInventory.getStackInSlot(1) == null && patternsInventory.getStackInSlot(0) != null; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Raoul Van den Berge
					Raoul Van den Berge