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.inventory.IInventory;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagIntArray;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
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.item.ItemUpgrade;
|
||||
|
||||
@@ -304,4 +311,18 @@ public class RefinedStorageUtils {
|
||||
public static void updateBlock(World world, BlockPos pos) {
|
||||
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.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.tileentity.TileEntityHopper;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import refinedstorage.RefinedStorageUtils;
|
||||
import refinedstorage.container.ContainerExporter;
|
||||
import refinedstorage.inventory.InventorySimple;
|
||||
@@ -30,34 +29,33 @@ public class TileExporter extends TileMachine implements ICompareConfig {
|
||||
|
||||
@Override
|
||||
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) {
|
||||
IInventory connectedInventory = (IInventory) connectedTile;
|
||||
if (handler != null && ticks % RefinedStorageUtils.getSpeed(upgradesInventory) == 0) {
|
||||
for (int i = 0; i < inventory.getSizeInventory(); ++i) {
|
||||
ItemStack slot = inventory.getStackInSlot(i);
|
||||
|
||||
if (ticks % RefinedStorageUtils.getSpeed(upgradesInventory) == 0) {
|
||||
for (int i = 0; i < inventory.getSizeInventory(); ++i) {
|
||||
ItemStack slot = inventory.getStackInSlot(i);
|
||||
if (slot != null) {
|
||||
ItemStack taking = slot.copy();
|
||||
taking.stackSize = 1;
|
||||
|
||||
if (slot != null) {
|
||||
ItemStack toTake = slot.copy();
|
||||
toTake.stackSize = 1;
|
||||
ItemStack took = controller.take(taking, compare);
|
||||
|
||||
ItemStack took = controller.take(toTake, compare);
|
||||
if (took != null) {
|
||||
scheduler.resetSchedule();
|
||||
|
||||
if (took != null) {
|
||||
scheduler.resetSchedule();
|
||||
|
||||
ItemStack remaining = TileEntityHopper.putStackInInventoryAllSlots(connectedInventory, took, getDirection().getOpposite());
|
||||
|
||||
if (remaining != null) {
|
||||
controller.push(remaining);
|
||||
}
|
||||
} else if (RefinedStorageUtils.hasUpgrade(upgradesInventory, ItemUpgrade.TYPE_CRAFTING)) {
|
||||
if (scheduler.canSchedule(compare, slot)) {
|
||||
scheduler.schedule(controller, compare, slot);
|
||||
for (int j = 0; j < handler.getSlots(); ++j) {
|
||||
// If we have no remainder
|
||||
if (handler.insertItem(j, took, true) == null) {
|
||||
handler.insertItem(j, took, false);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (RefinedStorageUtils.hasUpgrade(upgradesInventory, ItemUpgrade.TYPE_CRAFTING)) {
|
||||
if (scheduler.canSchedule(compare, slot)) {
|
||||
scheduler.schedule(controller, compare, slot);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user