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) { | ||||
|         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; | ||||
| @@ -186,7 +186,7 @@ public class GuiGrid extends GuiBase { | ||||
|                 ty = 1; | ||||
|             } | ||||
|  | ||||
|             if (!((TileGrid) grid).canCreatePattern()) { | ||||
|             if (!((TileGrid) grid).mayCreatePattern()) { | ||||
|                 ty = 2; | ||||
|             } | ||||
|  | ||||
|   | ||||
| @@ -27,7 +27,7 @@ public class GuiProcessingPatternEncoder extends GuiBase { | ||||
|     } | ||||
|  | ||||
|     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 | ||||
| @@ -42,7 +42,7 @@ public class GuiProcessingPatternEncoder extends GuiBase { | ||||
|             ty = 1; | ||||
|         } | ||||
|  | ||||
|         if (!ppEncoder.canCreatePattern()) { | ||||
|         if (!ppEncoder.mayCreatePattern()) { | ||||
|             ty = 2; | ||||
|         } | ||||
|  | ||||
|   | ||||
| @@ -21,6 +21,6 @@ public class DiskStorage extends NBTStorage { | ||||
|  | ||||
|     @Override | ||||
|     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.nbt.NBTTagCompound; | ||||
| import net.minecraft.nbt.NBTTagList; | ||||
| import net.minecraftforge.items.ItemHandlerHelper; | ||||
|  | ||||
| import java.util.ArrayList; | ||||
| import java.util.List; | ||||
| @@ -110,13 +111,9 @@ public abstract class NBTStorage implements IStorage { | ||||
|  | ||||
|                 tag.setInteger(NBT_STORED, getStored(tag) - quantity); | ||||
|  | ||||
|                 ItemStack result = group.toStack(); | ||||
|  | ||||
|                 result.stackSize = quantity; | ||||
|  | ||||
|                 markDirty(); | ||||
|  | ||||
|                 return result; | ||||
|                 return ItemHandlerHelper.copyStackWithSize(group.toStack(), quantity); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|   | ||||
| @@ -20,6 +20,6 @@ public class StorageBlockStorage extends NBTStorage { | ||||
|  | ||||
|     @Override | ||||
|     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(); | ||||
|                     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)) { | ||||
|                     ItemStack toCraft = inventory.getStackInSlot(0); | ||||
|                     ItemStack craft = inventory.getStackInSlot(0); | ||||
|  | ||||
|                     if (scheduler.canSchedule(compare, toCraft)) { | ||||
|                         scheduler.schedule(controller, compare, toCraft); | ||||
|                     if (scheduler.canSchedule(compare, craft)) { | ||||
|                         scheduler.schedule(controller, compare, craft); | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|   | ||||
| @@ -44,13 +44,16 @@ public class TileController extends TileBase implements IEnergyReceiver, ISynchr | ||||
|         public int energyUsage; | ||||
|  | ||||
|         @Override | ||||
|         public boolean equals(Object o) { | ||||
|             if (this == o) return true; | ||||
|             if (o == null || getClass() != o.getClass()) return false; | ||||
|         public boolean equals(Object other) { | ||||
|             if (this == other) { | ||||
|                 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 | ||||
|   | ||||
| @@ -45,7 +45,7 @@ public class TileDestructor extends TileMachine implements ICompareConfig, IMode | ||||
|             Block frontBlock = frontBlockState.getBlock(); | ||||
|  | ||||
|             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); | ||||
|  | ||||
|                     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.nbt.NBTTagCompound; | ||||
| import net.minecraftforge.items.IItemHandler; | ||||
| import net.minecraftforge.items.ItemHandlerHelper; | ||||
| import refinedstorage.RefinedStorageUtils; | ||||
| import refinedstorage.container.ContainerExporter; | ||||
| import refinedstorage.inventory.InventorySimple; | ||||
| @@ -36,21 +37,16 @@ public class TileExporter extends TileMachine implements ICompareConfig { | ||||
|                 ItemStack slot = inventory.getStackInSlot(i); | ||||
|  | ||||
|                 if (slot != null) { | ||||
|                     ItemStack taking = slot.copy(); | ||||
|                     taking.stackSize = 1; | ||||
|  | ||||
|                     ItemStack took = controller.take(taking, compare); | ||||
|                     ItemStack took = controller.take(ItemHandlerHelper.copyStackWithSize(slot, 1), compare); | ||||
|  | ||||
|                     if (took != null) { | ||||
|                         scheduler.resetSchedule(); | ||||
|  | ||||
|                         for (int j = 0; j < handler.getSlots(); ++j) { | ||||
|                             if (handler.insertItem(j, took, true) == null) { | ||||
|                                 handler.insertItem(j, took, false); | ||||
|                         if (ItemHandlerHelper.insertItem(handler, took, true) == null) { | ||||
|                             ItemHandlerHelper.insertItem(handler, took, false); | ||||
|  | ||||
|                             return; | ||||
|                         } | ||||
|                         } | ||||
|  | ||||
|                         controller.push(took); | ||||
|                     } 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.nbt.NBTTagCompound; | ||||
| import net.minecraftforge.items.IItemHandler; | ||||
| import net.minecraftforge.items.ItemHandlerHelper; | ||||
| import powercrystals.minefactoryreloaded.api.IDeepStorageUnit; | ||||
| import refinedstorage.RefinedStorage; | ||||
| import refinedstorage.RefinedStorageUtils; | ||||
| @@ -80,10 +81,8 @@ public class TileExternalStorage extends TileMachine implements IStorageProvider | ||||
|             IItemHandler handler = getItemHandler(); | ||||
|  | ||||
|             if (handler != null) { | ||||
|                 for (int i = 0; i < handler.getSlots(); ++i) { | ||||
|                     if (handler.insertItem(i, stack, false) == null) { | ||||
|                         break; | ||||
|                     } | ||||
|                 if (ItemHandlerHelper.insertItem(handler, stack, false) == null) { | ||||
|                     return; | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
| @@ -136,7 +135,7 @@ public class TileExternalStorage extends TileMachine implements IStorageProvider | ||||
|  | ||||
|     @Override | ||||
|     public boolean mayPush(ItemStack stack) { | ||||
|         if (ModeFilter.violatesMode(inventory, this, compare, stack)) { | ||||
|         if (ModeFilter.respectsMode(inventory, this, compare, stack)) { | ||||
|             IDeepStorageUnit storageUnit = getStorageUnit(); | ||||
|  | ||||
|             if (storageUnit != null) { | ||||
| @@ -149,14 +148,12 @@ public class TileExternalStorage extends TileMachine implements IStorageProvider | ||||
|                 IItemHandler handler = getItemHandler(); | ||||
|  | ||||
|                 if (handler != null) { | ||||
|                     for (int i = 0; i < handler.getSlots(); ++i) { | ||||
|                         if (handler.insertItem(i, stack, true) == null) { | ||||
|                     if (ItemHandlerHelper.insertItem(handler, stack, false) == null) { | ||||
|                         return true; | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|         } | ||||
|  | ||||
|         return false; | ||||
|     } | ||||
|   | ||||
| @@ -9,6 +9,7 @@ import net.minecraft.item.ItemStack; | ||||
| import net.minecraft.nbt.NBTTagCompound; | ||||
| import net.minecraft.util.EnumFacing; | ||||
| import net.minecraft.util.text.ITextComponent; | ||||
| import net.minecraftforge.items.ItemHandlerHelper; | ||||
| import refinedstorage.RefinedStorageUtils; | ||||
| import refinedstorage.container.ContainerInterface; | ||||
| import refinedstorage.inventory.InventorySimple; | ||||
| @@ -48,10 +49,7 @@ public class TileInterface extends TileMachine implements ICompareConfig, ISided | ||||
|             currentSlot++; | ||||
|         } else { | ||||
|             if (ticks % RefinedStorageUtils.getSpeed(upgradesInventory) == 0) { | ||||
|                 ItemStack toPush = slot.copy(); | ||||
|                 toPush.stackSize = 1; | ||||
|  | ||||
|                 if (controller.push(toPush)) { | ||||
|                 if (controller.push(ItemHandlerHelper.copyStackWithSize(slot, 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; | ||||
|  | ||||
|                     if (needed > 0) { | ||||
|                         ItemStack goingToTake = wanted.copy(); | ||||
|                         goingToTake.stackSize = needed; | ||||
|  | ||||
|                         ItemStack took = controller.take(goingToTake, compare); | ||||
|                         ItemStack took = controller.take(ItemHandlerHelper.copyStackWithSize(wanted, needed), compare); | ||||
|  | ||||
|                         if (took != null) { | ||||
|                             if (got == null) { | ||||
|   | ||||
| @@ -150,7 +150,7 @@ public class TileProcessingPatternEncoder extends TileBase implements ISidedInve | ||||
|     } | ||||
|  | ||||
|     public void onCreatePattern() { | ||||
|         if (canCreatePattern()) { | ||||
|         if (mayCreatePattern()) { | ||||
|             ItemStack pattern = new ItemStack(RefinedStorageItems.PATTERN); | ||||
|  | ||||
|             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; | ||||
|  | ||||
|         for (int i = 0; i < 9; ++i) { | ||||
|   | ||||
| @@ -4,6 +4,7 @@ import net.minecraft.item.ItemStack; | ||||
| import net.minecraft.nbt.NBTTagCompound; | ||||
| import net.minecraft.util.text.TextFormatting; | ||||
| import net.minecraftforge.items.IItemHandler; | ||||
| import net.minecraftforge.items.ItemHandlerHelper; | ||||
| import refinedstorage.RefinedStorageUtils; | ||||
| import refinedstorage.tile.TileController; | ||||
| import refinedstorage.tile.autocrafting.CraftingPattern; | ||||
| @@ -52,17 +53,11 @@ public class ProcessingCraftingTask implements ICraftingTask { | ||||
|                     ItemStack took = controller.take(input); | ||||
|  | ||||
|                     if (took != null) { | ||||
|                         for (int j = 0; j < handler.getSlots(); ++j) { | ||||
|                             if (handler.insertItem(j, took, true) == null) { | ||||
|                                 handler.insertItem(j, took, false); | ||||
|                         if (ItemHandlerHelper.insertItem(handler, took, true) == null) { | ||||
|                             ItemHandlerHelper.insertItem(handler, took, false); | ||||
|  | ||||
|                             inserted[i] = true; | ||||
|  | ||||
|                                 break; | ||||
|                             } | ||||
|                         } | ||||
|  | ||||
|                         if (!inserted[i]) { | ||||
|                         } else { | ||||
|                             controller.push(took); | ||||
|                         } | ||||
|                     } else if (!childTasks[i]) { | ||||
|   | ||||
| @@ -5,7 +5,7 @@ import net.minecraft.item.ItemStack; | ||||
| import refinedstorage.RefinedStorageUtils; | ||||
|  | ||||
| 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()) { | ||||
|             int slots = 0; | ||||
|  | ||||
|   | ||||
| @@ -169,7 +169,7 @@ public class TileGrid extends TileMachine implements IGrid { | ||||
|     } | ||||
|  | ||||
|     public void onCreatePattern() { | ||||
|         if (canCreatePattern()) { | ||||
|         if (mayCreatePattern()) { | ||||
|             patternsInventory.decrStackSize(0, 1); | ||||
|  | ||||
|             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; | ||||
|     } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Raoul Van den Berge
					Raoul Van den Berge