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,34 +29,33 @@ 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;
|
for (int i = 0; i < inventory.getSizeInventory(); ++i) {
|
||||||
|
ItemStack slot = inventory.getStackInSlot(i);
|
||||||
|
|
||||||
if (ticks % RefinedStorageUtils.getSpeed(upgradesInventory) == 0) {
|
if (slot != null) {
|
||||||
for (int i = 0; i < inventory.getSizeInventory(); ++i) {
|
ItemStack taking = slot.copy();
|
||||||
ItemStack slot = inventory.getStackInSlot(i);
|
taking.stackSize = 1;
|
||||||
|
|
||||||
if (slot != null) {
|
ItemStack took = controller.take(taking, compare);
|
||||||
ItemStack toTake = slot.copy();
|
|
||||||
toTake.stackSize = 1;
|
|
||||||
|
|
||||||
ItemStack took = controller.take(toTake, compare);
|
if (took != null) {
|
||||||
|
scheduler.resetSchedule();
|
||||||
|
|
||||||
if (took != null) {
|
for (int j = 0; j < handler.getSlots(); ++j) {
|
||||||
scheduler.resetSchedule();
|
// If we have no remainder
|
||||||
|
if (handler.insertItem(j, took, true) == null) {
|
||||||
ItemStack remaining = TileEntityHopper.putStackInInventoryAllSlots(connectedInventory, took, getDirection().getOpposite());
|
handler.insertItem(j, took, false);
|
||||||
|
} else {
|
||||||
if (remaining != null) {
|
break;
|
||||||
controller.push(remaining);
|
|
||||||
}
|
|
||||||
} else if (RefinedStorageUtils.hasUpgrade(upgradesInventory, ItemUpgrade.TYPE_CRAFTING)) {
|
|
||||||
if (scheduler.canSchedule(compare, slot)) {
|
|
||||||
scheduler.schedule(controller, compare, slot);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} 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