Make exporter use capabilities for inventories
This commit is contained in:
		| @@ -2,14 +2,21 @@ package refinedstorage; | |||||||
|  |  | ||||||
| import net.minecraft.entity.item.EntityItem; | import net.minecraft.entity.item.EntityItem; | ||||||
| import net.minecraft.inventory.IInventory; | import net.minecraft.inventory.IInventory; | ||||||
|  | import net.minecraft.inventory.ISidedInventory; | ||||||
| import net.minecraft.item.ItemStack; | import net.minecraft.item.ItemStack; | ||||||
| import net.minecraft.nbt.NBTTagCompound; | import net.minecraft.nbt.NBTTagCompound; | ||||||
| import net.minecraft.nbt.NBTTagIntArray; | import net.minecraft.nbt.NBTTagIntArray; | ||||||
| import net.minecraft.nbt.NBTTagList; | import net.minecraft.nbt.NBTTagList; | ||||||
|  | import net.minecraft.tileentity.TileEntity; | ||||||
|  | import net.minecraft.util.EnumFacing; | ||||||
| import net.minecraft.util.EnumHand; | import net.minecraft.util.EnumHand; | ||||||
| import net.minecraft.util.math.BlockPos; | import net.minecraft.util.math.BlockPos; | ||||||
| import net.minecraft.world.World; | import net.minecraft.world.World; | ||||||
| import net.minecraftforge.common.util.Constants; | import net.minecraftforge.common.util.Constants; | ||||||
|  | import net.minecraftforge.items.CapabilityItemHandler; | ||||||
|  | import net.minecraftforge.items.IItemHandler; | ||||||
|  | import net.minecraftforge.items.wrapper.InvWrapper; | ||||||
|  | import net.minecraftforge.items.wrapper.SidedInvWrapper; | ||||||
| import refinedstorage.inventory.InventorySimple; | import refinedstorage.inventory.InventorySimple; | ||||||
| import refinedstorage.item.ItemUpgrade; | import refinedstorage.item.ItemUpgrade; | ||||||
|  |  | ||||||
| @@ -304,4 +311,18 @@ public class RefinedStorageUtils { | |||||||
|     public static void updateBlock(World world, BlockPos pos) { |     public static void updateBlock(World world, BlockPos pos) { | ||||||
|         world.notifyBlockUpdate(pos, world.getBlockState(pos), world.getBlockState(pos), 1 | 2); |         world.notifyBlockUpdate(pos, world.getBlockState(pos), world.getBlockState(pos), 1 | 2); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     public static IItemHandler getItemHandler(TileEntity te, EnumFacing side) { | ||||||
|  |         IItemHandler handler = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side); | ||||||
|  |  | ||||||
|  |         if (handler == null) { | ||||||
|  |             if (side != null && te instanceof ISidedInventory) { | ||||||
|  |                 handler = new SidedInvWrapper((ISidedInventory) te, side); | ||||||
|  |             } else if (te instanceof IInventory) { | ||||||
|  |                 handler = new InvWrapper((IInventory) te); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         return handler; | ||||||
|  |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -5,8 +5,7 @@ import net.minecraft.inventory.Container; | |||||||
| import net.minecraft.inventory.IInventory; | 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.minecraft.tileentity.TileEntity; | import net.minecraftforge.items.IItemHandler; | ||||||
| import net.minecraft.tileentity.TileEntityHopper; |  | ||||||
| import refinedstorage.RefinedStorageUtils; | import refinedstorage.RefinedStorageUtils; | ||||||
| import refinedstorage.container.ContainerExporter; | import refinedstorage.container.ContainerExporter; | ||||||
| import refinedstorage.inventory.InventorySimple; | import refinedstorage.inventory.InventorySimple; | ||||||
| @@ -30,28 +29,28 @@ public class TileExporter extends TileMachine implements ICompareConfig { | |||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public void updateMachine() { |     public void updateMachine() { | ||||||
|         TileEntity connectedTile = worldObj.getTileEntity(pos.offset(getDirection())); |         IItemHandler handler = RefinedStorageUtils.getItemHandler(worldObj.getTileEntity(pos.offset(getDirection())), getDirection().getOpposite()); | ||||||
|  |  | ||||||
|         if (connectedTile instanceof IInventory) { |         if (handler != null && ticks % RefinedStorageUtils.getSpeed(upgradesInventory) == 0) { | ||||||
|             IInventory connectedInventory = (IInventory) connectedTile; |  | ||||||
|  |  | ||||||
|             if (ticks % RefinedStorageUtils.getSpeed(upgradesInventory) == 0) { |  | ||||||
|             for (int i = 0; i < inventory.getSizeInventory(); ++i) { |             for (int i = 0; i < inventory.getSizeInventory(); ++i) { | ||||||
|                 ItemStack slot = inventory.getStackInSlot(i); |                 ItemStack slot = inventory.getStackInSlot(i); | ||||||
|  |  | ||||||
|                 if (slot != null) { |                 if (slot != null) { | ||||||
|                         ItemStack toTake = slot.copy(); |                     ItemStack taking = slot.copy(); | ||||||
|                         toTake.stackSize = 1; |                     taking.stackSize = 1; | ||||||
|  |  | ||||||
|                         ItemStack took = controller.take(toTake, compare); |                     ItemStack took = controller.take(taking, compare); | ||||||
|  |  | ||||||
|                     if (took != null) { |                     if (took != null) { | ||||||
|                         scheduler.resetSchedule(); |                         scheduler.resetSchedule(); | ||||||
|  |  | ||||||
|                             ItemStack remaining = TileEntityHopper.putStackInInventoryAllSlots(connectedInventory, took, getDirection().getOpposite()); |                         for (int j = 0; j < handler.getSlots(); ++j) { | ||||||
|  |                             // If we have no remainder | ||||||
|                             if (remaining != null) { |                             if (handler.insertItem(j, took, true) == null) { | ||||||
|                                 controller.push(remaining); |                                 handler.insertItem(j, took, false); | ||||||
|  |                             } else { | ||||||
|  |                                 break; | ||||||
|  |                             } | ||||||
|                         } |                         } | ||||||
|                     } else if (RefinedStorageUtils.hasUpgrade(upgradesInventory, ItemUpgrade.TYPE_CRAFTING)) { |                     } else if (RefinedStorageUtils.hasUpgrade(upgradesInventory, ItemUpgrade.TYPE_CRAFTING)) { | ||||||
|                         if (scheduler.canSchedule(compare, slot)) { |                         if (scheduler.canSchedule(compare, slot)) { | ||||||
| @@ -62,7 +61,6 @@ public class TileExporter extends TileMachine implements ICompareConfig { | |||||||
|             } |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|     } |  | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public int getCompare() { |     public int getCompare() { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Raoul Van den Berge
					Raoul Van den Berge