use of mcjty.xnet.api.keys.SidedConsumer in project RFTools by McJty.
the class StorageChannelSettings method tick.
@Override
public void tick(int channel, IControllerContext context) {
if (updateCache(channel, context)) {
// If cache was updated we send new state immediatelly
delay = 0;
}
delay--;
if (delay > 0) {
return;
}
delay = 10;
World world = context.getControllerWorld();
for (Pair<SidedConsumer, StorageConnectorSettings> entry : storageControllers) {
BlockPos extractorPos = context.findConsumerPosition(entry.getKey().getConsumerId());
if (extractorPos != null) {
EnumFacing side = entry.getKey().getSide();
BlockPos pos = extractorPos.offset(side);
if (!WorldTools.chunkLoaded(world, pos)) {
continue;
}
TileEntity te = world.getTileEntity(pos);
if (te instanceof StorageScannerTileEntity) {
StorageScannerTileEntity scanner = (StorageScannerTileEntity) te;
scanner.register(access);
}
}
}
}
use of mcjty.xnet.api.keys.SidedConsumer in project XNet by McJty.
the class TileEntityController method removeConnector.
private void removeConnector(int channel, SidedPos pos) {
WorldBlob worldBlob = XNetBlobData.getBlobData(getWorld()).getWorldBlob(getWorld());
ConsumerId consumerId = worldBlob.getConsumerAt(pos.getPos().offset(pos.getSide()));
SidedConsumer toremove = null;
for (Map.Entry<SidedConsumer, ConnectorInfo> entry : channels[channel].getConnectors().entrySet()) {
SidedConsumer key = entry.getKey();
if (key.getSide().getOpposite().equals(pos.getSide())) {
if (key.getConsumerId().equals(consumerId)) {
toremove = key;
break;
}
}
}
if (toremove != null) {
channels[channel].getConnectors().remove(toremove);
networkDirty();
markDirtyQuick();
}
}
use of mcjty.xnet.api.keys.SidedConsumer in project XNet by McJty.
the class FluidChannelSettings method insertFluidSimulate.
// Returns what could not be filled
private int insertFluidSimulate(@Nonnull List<Pair<SidedConsumer, FluidConnectorSettings>> inserted, @Nonnull IControllerContext context, @Nonnull FluidStack stack) {
World world = context.getControllerWorld();
if (channelMode == ChannelMode.PRIORITY) {
// Always start at 0
roundRobinOffset = 0;
}
int amount = stack.amount;
for (int j = 0; j < fluidConsumers.size(); j++) {
int i = (j + roundRobinOffset) % fluidConsumers.size();
Pair<SidedConsumer, FluidConnectorSettings> entry = fluidConsumers.get(i);
FluidConnectorSettings settings = entry.getValue();
if (settings.getMatcher() == null || settings.getMatcher().equals(stack)) {
BlockPos consumerPos = context.findConsumerPosition(entry.getKey().getConsumerId());
if (consumerPos != null) {
if (!WorldTools.chunkLoaded(world, consumerPos)) {
continue;
}
if (checkRedstone(world, settings, consumerPos)) {
continue;
}
if (!context.matchColor(settings.getColorsMask())) {
continue;
}
EnumFacing side = entry.getKey().getSide();
BlockPos pos = consumerPos.offset(side);
TileEntity te = world.getTileEntity(pos);
IFluidHandler handler = getFluidHandlerAt(te, settings.getFacing());
// @todo report error somewhere?
if (handler != null) {
int toinsert = Math.min(settings.getRate(), amount);
Integer count = settings.getMinmax();
if (count != null) {
int a = countFluid(handler, settings.getMatcher());
int caninsert = count - a;
if (caninsert <= 0) {
continue;
}
toinsert = Math.min(toinsert, caninsert);
}
FluidStack copy = stack.copy();
copy.amount = toinsert;
int filled = handler.fill(copy, false);
if (filled > 0) {
inserted.add(entry);
amount -= filled;
if (amount <= 0) {
return 0;
}
}
}
}
}
}
return amount;
}
use of mcjty.xnet.api.keys.SidedConsumer in project XNet by McJty.
the class FluidChannelSettings method tick.
@Override
public void tick(int channel, IControllerContext context) {
delay--;
if (delay <= 0) {
// Multiply of the different speeds we have
delay = 200 * 6;
}
if (delay % 10 != 0) {
return;
}
int d = delay / 10;
updateCache(channel, context);
// @todo optimize
World world = context.getControllerWorld();
for (Map.Entry<SidedConsumer, FluidConnectorSettings> entry : fluidExtractors.entrySet()) {
FluidConnectorSettings settings = entry.getValue();
if (d % settings.getSpeed() != 0) {
continue;
}
BlockPos extractorPos = context.findConsumerPosition(entry.getKey().getConsumerId());
if (extractorPos != null) {
EnumFacing side = entry.getKey().getSide();
BlockPos pos = extractorPos.offset(side);
if (!WorldTools.chunkLoaded(world, pos)) {
continue;
}
TileEntity te = world.getTileEntity(pos);
IFluidHandler handler = getFluidHandlerAt(te, settings.getFacing());
// @todo report error somewhere?
if (handler != null) {
if (checkRedstone(world, settings, extractorPos)) {
continue;
}
if (!context.matchColor(settings.getColorsMask())) {
continue;
}
FluidStack extractMatcher = settings.getMatcher();
int toextract = settings.getRate();
Integer count = settings.getMinmax();
if (count != null) {
int amount = countFluid(handler, extractMatcher);
int canextract = amount - count;
if (canextract <= 0) {
continue;
}
toextract = Math.min(toextract, canextract);
}
FluidStack stack = fetchFluid(handler, true, extractMatcher, toextract);
if (stack != null) {
List<Pair<SidedConsumer, FluidConnectorSettings>> inserted = new ArrayList<>();
int remaining = insertFluidSimulate(inserted, context, stack);
if (!inserted.isEmpty()) {
if (context.checkAndConsumeRF(GeneralConfiguration.controllerOperationRFT)) {
insertFluidReal(context, inserted, fetchFluid(handler, false, extractMatcher, stack.amount - remaining));
}
}
}
}
}
}
}
use of mcjty.xnet.api.keys.SidedConsumer in project XNet by McJty.
the class ItemChannelSettings method tick.
@Override
public void tick(int channel, IControllerContext context) {
delay--;
if (delay <= 0) {
// Multiply of the different speeds we have
delay = 200 * 6;
}
if (delay % 5 != 0) {
return;
}
int d = delay / 5;
updateCache(channel, context);
World world = context.getControllerWorld();
for (Map.Entry<SidedConsumer, ItemConnectorSettings> entry : itemExtractors.entrySet()) {
ItemConnectorSettings settings = entry.getValue();
if (d % settings.getSpeed() != 0) {
continue;
}
ConsumerId consumerId = entry.getKey().getConsumerId();
BlockPos extractorPos = context.findConsumerPosition(consumerId);
if (extractorPos != null) {
EnumFacing side = entry.getKey().getSide();
BlockPos pos = extractorPos.offset(side);
if (!WorldTools.chunkLoaded(world, pos)) {
continue;
}
if (checkRedstone(world, settings, extractorPos)) {
return;
}
if (!context.matchColor(settings.getColorsMask())) {
return;
}
TileEntity te = world.getTileEntity(pos);
if (XNet.rftools && RFToolsSupport.isStorageScanner(te)) {
RFToolsSupport.tickStorageScanner(context, settings, te, this);
} else {
IItemHandler handler = getItemHandlerAt(te, settings.getFacing());
if (handler != null) {
int idx = getStartExtractIndex(settings, consumerId, handler);
idx = tickItemHandler(context, settings, handler, idx);
if (handler.getSlots() > 0) {
rememberExtractIndex(consumerId, (idx + 1) % handler.getSlots());
}
}
}
}
}
}
Aggregations