Expose reader cap

This commit is contained in:
Raoul Van den Berge
2016-11-11 15:55:51 +01:00
parent 27e6826db5
commit aee42d2214
4 changed files with 89 additions and 18 deletions

View File

@@ -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.IFluidGridHandler;
import com.raoulvdberge.refinedstorage.api.network.grid.IItemGridHandler; import com.raoulvdberge.refinedstorage.api.network.grid.IItemGridHandler;
import com.raoulvdberge.refinedstorage.api.network.item.INetworkItemHandler; 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.fluid.IFluidStorageCache;
import com.raoulvdberge.refinedstorage.api.storage.item.IItemStorageCache; import com.raoulvdberge.refinedstorage.api.storage.item.IItemStorageCache;
import com.raoulvdberge.refinedstorage.api.util.IComparer; import com.raoulvdberge.refinedstorage.api.util.IComparer;
@@ -225,6 +226,13 @@ public interface INetworkMaster {
*/ */
void sendCraftingMonitorUpdate(EntityPlayerMP player); 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. * Adds a new reader writer channel.
* *
@@ -300,9 +308,9 @@ public interface INetworkMaster {
/** /**
* Extracts a fluid from this network. * Extracts a fluid from this network.
* *
* @param stack the prototype of the stack to extract, do NOT modify * @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 size the amount of that prototype that has to be extracted
* @param flags the flags to compare on, see {@link IComparer} * @param flags the flags to compare on, see {@link IComparer}
* @param simulate true if we are simulating, false otherwise * @param simulate true if we are simulating, false otherwise
* @return null if we didn't extract anything, or a stack with the result * @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. * Extracts a fluid from this network.
* *
* @param stack the prototype of the stack to extract, do NOT modify * @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 size the amount of that prototype that has to be extracted
* @param simulate true if we are simulating, false otherwise * @param simulate true if we are simulating, false otherwise
* @return null if we didn't extract anything, or a stack with the result * @return null if we didn't extract anything, or a stack with the result
*/ */

View File

@@ -33,24 +33,26 @@ public class ReaderWriterHandlerItems implements IReaderWriterHandler {
for (IWriter writer : channel.getWriters()) { for (IWriter writer : channel.getWriters()) {
IItemHandler handler = RSUtils.getItemHandler(writer.getNodeWorld().getTileEntity(writer.getPosition().offset(writer.getDirection())), writer.getDirection().getOpposite()); IItemHandler handler = RSUtils.getItemHandler(writer.getNodeWorld().getTileEntity(writer.getPosition().offset(writer.getDirection())), writer.getDirection().getOpposite());
if (handler != null) { if (handler == null) {
for (int i = 0; i < internalInv.getSlots(); ++i) { continue;
ItemStack slot = internalInv.getStackInSlot(i); }
if (slot != null) { for (int i = 0; i < internalInv.getSlots(); ++i) {
ItemStack toInsert = ItemHandlerHelper.copyStackWithSize(slot, writer.hasStackUpgrade() ? 64 : 1); ItemStack slot = internalInv.getStackInSlot(i);
if (ItemHandlerHelper.insertItem(handler, toInsert, true) == null) { if (slot == null) {
ItemHandlerHelper.insertItem(handler, toInsert, false); continue;
}
internalInv.getStackInSlot(i).stackSize -= toInsert.stackSize; ItemStack toInsert = ItemHandlerHelper.copyStackWithSize(slot, writer.hasStackUpgrade() ? 64 : 1);
if (internalInv.getStackInSlot(i).stackSize <= 0) { if (ItemHandlerHelper.insertItem(handler, toInsert, true) == null) {
internalInv.setStackInSlot(i, null); ItemHandlerHelper.insertItem(handler, toInsert, false);
}
}
break; internalInv.getStackInSlot(i).stackSize -= toInsert.stackSize;
if (internalInv.getStackInSlot(i).stackSize <= 0) {
internalInv.setStackInSlot(i, null);
} }
} }
} }

View File

@@ -569,6 +569,12 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
RS.INSTANCE.network.sendTo(new MessageCraftingMonitorElements(getElements()), player); RS.INSTANCE.network.sendTo(new MessageCraftingMonitorElements(getElements()), player);
} }
@Nullable
@Override
public IReaderWriterChannel getReaderWriterChannel(String name) {
return readerWriterChannels.get(name);
}
@Override @Override
public void addReaderWriterChannel(String name) { public void addReaderWriterChannel(String name) {
readerWriterChannels.put(name, API.instance().createReaderWriterChannel(name, this)); readerWriterChannels.put(name, API.instance().createReaderWriterChannel(name, this));

View File

@@ -1,6 +1,8 @@
package com.raoulvdberge.refinedstorage.tile; package com.raoulvdberge.refinedstorage.tile;
import com.raoulvdberge.refinedstorage.api.network.readerwriter.IReader; 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.gui.GuiReaderWriter;
import com.raoulvdberge.refinedstorage.tile.data.ITileDataConsumer; import com.raoulvdberge.refinedstorage.tile.data.ITileDataConsumer;
import com.raoulvdberge.refinedstorage.tile.data.ITileDataProducer; 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.nbt.NBTTagCompound;
import net.minecraft.network.datasync.DataSerializers; import net.minecraft.network.datasync.DataSerializers;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraftforge.common.capabilities.Capability;
public class TileReader extends TileNode implements IReader, IReaderWriter { public class TileReader extends TileNode implements IReader, IReaderWriter {
private static final String NBT_CHANNEL = "Channel"; private static final String NBT_CHANNEL = "Channel";
@@ -106,6 +110,57 @@ public class TileReader extends TileNode implements IReader, IReaderWriter {
return true; 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 @Override
public void read(NBTTagCompound tag) { public void read(NBTTagCompound tag) {