Expose reader cap
This commit is contained in:
@@ -6,6 +6,7 @@ import com.raoulvdberge.refinedstorage.api.autocrafting.task.ICraftingTask;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.IFluidGridHandler;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.IItemGridHandler;
|
||||
import com.raoulvdberge.refinedstorage.api.network.item.INetworkItemHandler;
|
||||
import com.raoulvdberge.refinedstorage.api.network.readerwriter.IReaderWriterChannel;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.fluid.IFluidStorageCache;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.item.IItemStorageCache;
|
||||
import com.raoulvdberge.refinedstorage.api.util.IComparer;
|
||||
@@ -225,6 +226,13 @@ public interface INetworkMaster {
|
||||
*/
|
||||
void sendCraftingMonitorUpdate(EntityPlayerMP player);
|
||||
|
||||
/**
|
||||
* @param name the name of the reader writer channel
|
||||
* @return the reader writer channel, or null if nothing was found
|
||||
*/
|
||||
@Nullable
|
||||
IReaderWriterChannel getReaderWriterChannel(String name);
|
||||
|
||||
/**
|
||||
* Adds a new reader writer channel.
|
||||
*
|
||||
@@ -300,9 +308,9 @@ public interface INetworkMaster {
|
||||
/**
|
||||
* Extracts a fluid from this network.
|
||||
*
|
||||
* @param stack the prototype of the stack to extract, do NOT modify
|
||||
* @param size the amount of that prototype that has to be extracted
|
||||
* @param flags the flags to compare on, see {@link IComparer}
|
||||
* @param stack the prototype of the stack to extract, do NOT modify
|
||||
* @param size the amount of that prototype that has to be extracted
|
||||
* @param flags the flags to compare on, see {@link IComparer}
|
||||
* @param simulate true if we are simulating, false otherwise
|
||||
* @return null if we didn't extract anything, or a stack with the result
|
||||
*/
|
||||
@@ -312,8 +320,8 @@ public interface INetworkMaster {
|
||||
/**
|
||||
* Extracts a fluid from this network.
|
||||
*
|
||||
* @param stack the prototype of the stack to extract, do NOT modify
|
||||
* @param size the amount of that prototype that has to be extracted
|
||||
* @param stack the prototype of the stack to extract, do NOT modify
|
||||
* @param size the amount of that prototype that has to be extracted
|
||||
* @param simulate true if we are simulating, false otherwise
|
||||
* @return null if we didn't extract anything, or a stack with the result
|
||||
*/
|
||||
|
||||
@@ -33,24 +33,26 @@ public class ReaderWriterHandlerItems implements IReaderWriterHandler {
|
||||
for (IWriter writer : channel.getWriters()) {
|
||||
IItemHandler handler = RSUtils.getItemHandler(writer.getNodeWorld().getTileEntity(writer.getPosition().offset(writer.getDirection())), writer.getDirection().getOpposite());
|
||||
|
||||
if (handler != null) {
|
||||
for (int i = 0; i < internalInv.getSlots(); ++i) {
|
||||
ItemStack slot = internalInv.getStackInSlot(i);
|
||||
if (handler == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (slot != null) {
|
||||
ItemStack toInsert = ItemHandlerHelper.copyStackWithSize(slot, writer.hasStackUpgrade() ? 64 : 1);
|
||||
for (int i = 0; i < internalInv.getSlots(); ++i) {
|
||||
ItemStack slot = internalInv.getStackInSlot(i);
|
||||
|
||||
if (ItemHandlerHelper.insertItem(handler, toInsert, true) == null) {
|
||||
ItemHandlerHelper.insertItem(handler, toInsert, false);
|
||||
if (slot == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
internalInv.getStackInSlot(i).stackSize -= toInsert.stackSize;
|
||||
ItemStack toInsert = ItemHandlerHelper.copyStackWithSize(slot, writer.hasStackUpgrade() ? 64 : 1);
|
||||
|
||||
if (internalInv.getStackInSlot(i).stackSize <= 0) {
|
||||
internalInv.setStackInSlot(i, null);
|
||||
}
|
||||
}
|
||||
if (ItemHandlerHelper.insertItem(handler, toInsert, true) == null) {
|
||||
ItemHandlerHelper.insertItem(handler, toInsert, false);
|
||||
|
||||
break;
|
||||
internalInv.getStackInSlot(i).stackSize -= toInsert.stackSize;
|
||||
|
||||
if (internalInv.getStackInSlot(i).stackSize <= 0) {
|
||||
internalInv.setStackInSlot(i, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -569,6 +569,12 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
|
||||
RS.INSTANCE.network.sendTo(new MessageCraftingMonitorElements(getElements()), player);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IReaderWriterChannel getReaderWriterChannel(String name) {
|
||||
return readerWriterChannels.get(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addReaderWriterChannel(String name) {
|
||||
readerWriterChannels.put(name, API.instance().createReaderWriterChannel(name, this));
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.raoulvdberge.refinedstorage.tile;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.api.network.readerwriter.IReader;
|
||||
import com.raoulvdberge.refinedstorage.api.network.readerwriter.IReaderWriterChannel;
|
||||
import com.raoulvdberge.refinedstorage.api.network.readerwriter.IReaderWriterHandler;
|
||||
import com.raoulvdberge.refinedstorage.gui.GuiReaderWriter;
|
||||
import com.raoulvdberge.refinedstorage.tile.data.ITileDataConsumer;
|
||||
import com.raoulvdberge.refinedstorage.tile.data.ITileDataProducer;
|
||||
@@ -11,7 +13,9 @@ import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.datasync.DataSerializers;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
|
||||
public class TileReader extends TileNode implements IReader, IReaderWriter {
|
||||
private static final String NBT_CHANNEL = "Channel";
|
||||
@@ -106,6 +110,57 @@ public class TileReader extends TileNode implements IReader, IReaderWriter {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
|
||||
if (!super.hasCapability(capability, facing)) {
|
||||
if (network == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
IReaderWriterChannel foundChannel = network.getReaderWriterChannel(channel);
|
||||
|
||||
if (foundChannel == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (IReaderWriterHandler handler : foundChannel.getHandlers()) {
|
||||
if (handler.hasCapability(capability, facing)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
|
||||
T foundCap = super.getCapability(capability, facing);
|
||||
|
||||
if (foundCap == null) {
|
||||
if (network == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
IReaderWriterChannel foundChannel = network.getReaderWriterChannel(channel);
|
||||
|
||||
if (foundChannel == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (IReaderWriterHandler handler : foundChannel.getHandlers()) {
|
||||
foundCap = handler.getCapability(capability, facing);
|
||||
|
||||
if (foundCap != null) {
|
||||
return foundCap;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return foundCap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(NBTTagCompound tag) {
|
||||
|
||||
Reference in New Issue
Block a user