From 87996c76b16220b834f3fd007b607649d1f6e377 Mon Sep 17 00:00:00 2001 From: Alex Emelyanov Date: Sun, 5 May 2024 19:02:02 +0300 Subject: [PATCH 1/2] port last patch 1.19->1.20 --- .../mcjty/xnet/apiimpl/ConnectedBlock.java | 40 ++++++- .../xnet/apiimpl/ConnectedInventory.java | 24 ++++ .../apiimpl/energy/EnergyChannelSettings.java | 73 +++++++----- .../apiimpl/energy/EnergyConnectedBlock.java | 17 ++- .../apiimpl/fluids/FluidChannelSettings.java | 93 +++++++++------- .../apiimpl/items/ItemChannelSettings.java | 87 +++++++++------ .../apiimpl/items/ItemConnectorSettings.java | 3 + .../apiimpl/logic/LogicChannelSettings.java | 104 +++++++++++------- .../java/mcjty/xnet/compat/jei/JeiCompat.java | 40 +++++++ .../compat/jei/JeiGhostIngredientHandler.java | 88 +++++++++++++++ .../modules/cables/blocks/ConnectorBlock.java | 2 +- .../blocks/TileEntityController.java | 7 +- .../client/AbstractEditorPanel.java | 6 +- .../controller/client/GuiController.java | 9 +- .../resources/assets/xnet/lang/ru_ru.json | 12 +- 15 files changed, 446 insertions(+), 159 deletions(-) create mode 100644 src/main/java/mcjty/xnet/apiimpl/ConnectedInventory.java create mode 100644 src/main/java/mcjty/xnet/compat/jei/JeiCompat.java create mode 100644 src/main/java/mcjty/xnet/compat/jei/JeiGhostIngredientHandler.java diff --git a/src/main/java/mcjty/xnet/apiimpl/ConnectedBlock.java b/src/main/java/mcjty/xnet/apiimpl/ConnectedBlock.java index 98b2724d..b8c9a516 100644 --- a/src/main/java/mcjty/xnet/apiimpl/ConnectedBlock.java +++ b/src/main/java/mcjty/xnet/apiimpl/ConnectedBlock.java @@ -1,7 +1,45 @@ package mcjty.xnet.apiimpl; import mcjty.rftoolsbase.api.xnet.keys.SidedConsumer; +import mcjty.xnet.modules.cables.blocks.ConnectorTileEntity; import net.minecraft.core.BlockPos; +import net.minecraft.world.level.block.entity.BlockEntity; + +import javax.annotation.Nonnull; + + +public class ConnectedBlock { + @Nonnull private final SidedConsumer sidedConsumer; + @Nonnull private final T settings; + @Nonnull private final BlockPos connectorPos; + @Nonnull private final BlockEntity connectedEntity; + @Nonnull private final ConnectorTileEntity connectorEntity; + + public ConnectedBlock(@Nonnull SidedConsumer sidedConsumer, @Nonnull T settings, @Nonnull BlockPos connectorPos, @Nonnull BlockEntity connectedEntity, @Nonnull ConnectorTileEntity connectorEntity) { + this.sidedConsumer = sidedConsumer; + this.settings = settings; + this.connectorPos = connectorPos; + this.connectedEntity = connectedEntity; + this.connectorEntity = connectorEntity; + } + + @Nonnull + public SidedConsumer sidedConsumer() {return sidedConsumer;} + + @Nonnull + public T settings() {return settings;} + + @Nonnull + public BlockPos connectorPos() {return connectorPos;} + + @Nonnull + public BlockEntity getConnectedEntity() { + return connectedEntity; + } + + @Nonnull + public ConnectorTileEntity getConnectorEntity() { + return connectorEntity; + } -public record ConnectedBlock(SidedConsumer sidedConsumer, T settings, BlockPos connectorPos){ } diff --git a/src/main/java/mcjty/xnet/apiimpl/ConnectedInventory.java b/src/main/java/mcjty/xnet/apiimpl/ConnectedInventory.java new file mode 100644 index 00000000..d2cc94b1 --- /dev/null +++ b/src/main/java/mcjty/xnet/apiimpl/ConnectedInventory.java @@ -0,0 +1,24 @@ +package mcjty.xnet.apiimpl; + +import mcjty.rftoolsbase.api.xnet.keys.SidedConsumer; +import mcjty.xnet.modules.cables.blocks.ConnectorTileEntity; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.block.entity.BlockEntity; + +import javax.annotation.Nonnull; + +public class ConnectedInventory extends ConnectedBlock { + @Nonnull private final H handler; + + public ConnectedInventory(@Nonnull SidedConsumer sidedConsumer, @Nonnull T settings, @Nonnull BlockPos connectorPos, + @Nonnull BlockEntity connectedEntity, @Nonnull ConnectorTileEntity connectorEntity, + @Nonnull H handler) { + super(sidedConsumer, settings, connectorPos, connectedEntity, connectorEntity); + this.handler = handler; + } + + @Nonnull + public H getHandler() { + return handler; + } +} diff --git a/src/main/java/mcjty/xnet/apiimpl/energy/EnergyChannelSettings.java b/src/main/java/mcjty/xnet/apiimpl/energy/EnergyChannelSettings.java index f3f3a363..21b361df 100644 --- a/src/main/java/mcjty/xnet/apiimpl/energy/EnergyChannelSettings.java +++ b/src/main/java/mcjty/xnet/apiimpl/energy/EnergyChannelSettings.java @@ -31,6 +31,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Optional; public class EnergyChannelSettings extends DefaultChannelSettings implements IChannelSettings { @@ -81,26 +82,19 @@ public void tick(int channel, IControllerContext context) { List> energyProducers = new ArrayList<>(); for (EnergyConnectedBlock extractor : energyExtractors) { BlockPos connectorPos = extractor.connectorPos(); - if (connectorPos == null) { - continue; - } Direction side = extractor.sidedConsumer().side(); - BlockPos energyPos = connectorPos.relative(side); - if (!LevelTools.isLoaded(world, energyPos)) { + if (!LevelTools.isLoaded(world, extractor.getConnectedEntity().getBlockPos())) { continue; } - BlockEntity te = world.getBlockEntity(energyPos); + BlockEntity te = extractor.getConnectedEntity(); // @todo report error somewhere? if (!isEnergyTE(te, side.getOpposite())) { continue; } EnergyConnectorSettings settings = extractor.settings(); - ConnectorTileEntity connectorTE = (ConnectorTileEntity) world.getBlockEntity(connectorPos); - if (connectorTE == null) { - continue; - } + ConnectorTileEntity connectorTE = extractor.getConnectorEntity(); if (checkRedstone(world, settings, connectorPos) || !context.matchColor(settings.getColorsMask())) { continue; @@ -165,18 +159,12 @@ private long insertEnergy(@Nonnull IControllerContext context, long energy) { Level world = context.getControllerWorld(); for (EnergyConnectedBlock consumer : energyConsumers) { EnergyConnectorSettings settings = consumer.settings(); - BlockPos connectorPos = consumer.connectorPos(); - if (connectorPos == null) { + if (!LevelTools.isLoaded(world, consumer.getConnectedEntity().getBlockPos())) { continue; } - Direction side = consumer.sidedConsumer().side(); - BlockPos connectedBlockPos = connectorPos.relative(side); - if (!LevelTools.isLoaded(world, connectedBlockPos)) { - continue; - } - BlockEntity te = world.getBlockEntity(connectedBlockPos); + BlockEntity te = consumer.getConnectedEntity(); // @todo report error somewhere? - if (!isEnergyTE(te, settings.getFacing()) || checkRedstone(world, settings, connectorPos) || !context.matchColor(settings.getColorsMask())) { + if (!isEnergyTE(te, settings.getFacing()) || checkRedstone(world, settings, consumer.connectorPos()) || !context.matchColor(settings.getColorsMask())) { continue; } @@ -232,24 +220,28 @@ private void updateCache(int channel, IControllerContext context) { Level world = context.getControllerWorld(); for (var entry : connectors.entrySet()) { EnergyConnectorSettings con = (EnergyConnectorSettings) entry.getValue(); - BlockPos connectorPos = context.findConsumerPosition(entry.getKey().consumerId()); - Integer rate = getRateOrMax(con, connectorPos, world); + EnergyConnectedBlock connectedBlock = getConnectedBlockInfo(context, entry, world, con); + if (connectedBlock == null) { + continue; + } if (con.getEnergyMode() == InsExtMode.EXT) { - energyExtractors.add(new EnergyConnectedBlock(entry.getKey(), con, connectorPos, rate)); + energyExtractors.add(connectedBlock); } else { - energyConsumers.add(new EnergyConnectedBlock(entry.getKey(), con, connectorPos, rate)); - maxConsume += rate; + energyConsumers.add(connectedBlock); + maxConsume += connectedBlock.rate(); } } connectors = context.getRoutedConnectors(channel); for (var entry : connectors.entrySet()) { EnergyConnectorSettings con = (EnergyConnectorSettings) entry.getValue(); - BlockPos connectorPos = context.findConsumerPosition(entry.getKey().consumerId()); - Integer rate = getRateOrMax(con, connectorPos, world); + EnergyConnectedBlock connectedBlock = getConnectedBlockInfo(context, entry, world, con); + if (connectedBlock == null) { + continue; + } if (con.getEnergyMode() == InsExtMode.INS) { - energyConsumers.add(new EnergyConnectedBlock(entry.getKey(), con, connectorPos, rate)); - maxConsume += rate; + energyConsumers.add(connectedBlock); + maxConsume += connectedBlock.rate(); } } @@ -258,7 +250,30 @@ private void updateCache(int channel, IControllerContext context) { } } - private static Integer getRateOrMax(EnergyConnectorSettings con, BlockPos connectorPos, Level world) { + @Nullable + private EnergyConnectedBlock getConnectedBlockInfo( + IControllerContext context, Map.Entry entry, @Nonnull Level world, @Nonnull EnergyConnectorSettings con + ) { + BlockPos connectorPos = context.findConsumerPosition(entry.getKey().consumerId()); + if (connectorPos == null) { + return null; + } + ConnectorTileEntity connectorTileEntity = (ConnectorTileEntity) world.getBlockEntity(connectorPos); + if (connectorTileEntity == null) { + return null; + } + + BlockPos connectedBlockPos = connectorPos.relative(entry.getKey().side()); + BlockEntity connectedEntity = world.getBlockEntity(connectedBlockPos); + if (connectedEntity == null) { + return null; + } + Integer rate = getRateOrMax(con, connectorPos, world); + return new EnergyConnectedBlock(entry.getKey(), con, connectorPos, connectedEntity, connectorTileEntity, rate); + } + + private static Integer getRateOrMax(@Nonnull EnergyConnectorSettings con, @Nonnull BlockPos connectorPos, + @Nonnull Level world) { Integer rate = con.getRate(); if (rate == null) { boolean advanced = ConnectorBlock.isAdvancedConnector(world, connectorPos); diff --git a/src/main/java/mcjty/xnet/apiimpl/energy/EnergyConnectedBlock.java b/src/main/java/mcjty/xnet/apiimpl/energy/EnergyConnectedBlock.java index a8a16687..c9327da2 100644 --- a/src/main/java/mcjty/xnet/apiimpl/energy/EnergyConnectedBlock.java +++ b/src/main/java/mcjty/xnet/apiimpl/energy/EnergyConnectedBlock.java @@ -1,7 +1,22 @@ package mcjty.xnet.apiimpl.energy; import mcjty.rftoolsbase.api.xnet.keys.SidedConsumer; +import mcjty.xnet.apiimpl.ConnectedBlock; +import mcjty.xnet.modules.cables.blocks.ConnectorTileEntity; import net.minecraft.core.BlockPos; +import net.minecraft.world.level.block.entity.BlockEntity; -public record EnergyConnectedBlock (SidedConsumer sidedConsumer, EnergyConnectorSettings settings, BlockPos connectorPos, int rate) { +import javax.annotation.Nonnull; + +public final class EnergyConnectedBlock extends ConnectedBlock { + private final int rate; + + public EnergyConnectedBlock(@Nonnull SidedConsumer sidedConsumer, @Nonnull EnergyConnectorSettings settings, + @Nonnull BlockPos connectorPos, @Nonnull BlockEntity connectedEntity, + @Nonnull ConnectorTileEntity connectorEntity, int rate) { + super(sidedConsumer, settings, connectorPos, connectedEntity, connectorEntity); + this.rate = rate; + } + + public int rate() {return rate;} } diff --git a/src/main/java/mcjty/xnet/apiimpl/fluids/FluidChannelSettings.java b/src/main/java/mcjty/xnet/apiimpl/fluids/FluidChannelSettings.java index e37275e3..bc7df003 100644 --- a/src/main/java/mcjty/xnet/apiimpl/fluids/FluidChannelSettings.java +++ b/src/main/java/mcjty/xnet/apiimpl/fluids/FluidChannelSettings.java @@ -11,10 +11,11 @@ import mcjty.rftoolsbase.api.xnet.helper.DefaultChannelSettings; import mcjty.rftoolsbase.api.xnet.keys.SidedConsumer; import mcjty.xnet.XNet; -import mcjty.xnet.apiimpl.ConnectedBlock; +import mcjty.xnet.apiimpl.ConnectedInventory; import mcjty.xnet.apiimpl.EnumStringTranslators; import mcjty.xnet.apiimpl.enums.ChannelMode; import mcjty.xnet.apiimpl.enums.InsExtMode; +import mcjty.xnet.modules.cables.blocks.ConnectorTileEntity; import mcjty.xnet.setup.Config; import mcjty.xnet.utils.CastTools; import net.minecraft.core.BlockPos; @@ -33,6 +34,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.Optional; import static mcjty.xnet.apiimpl.Constants.TAG_DELAY; import static mcjty.xnet.apiimpl.Constants.TAG_MODE; @@ -46,8 +48,8 @@ public class FluidChannelSettings extends DefaultChannelSettings implements ICha private int roundRobinOffset = 0; // Cache data - private List> fluidExtractors = null; - private List> fluidConsumers = null; + private List> fluidExtractors = null; + private List> fluidConsumers = null; public ChannelMode getChannelMode() { return channelMode; @@ -92,40 +94,23 @@ public void tick(int channel, IControllerContext context) { int d = delay / 10; updateCache(channel, context); - Level world = context.getControllerWorld(); - for (ConnectedBlock extractor : fluidExtractors) { + for (ConnectedInventory extractor : fluidExtractors) { FluidConnectorSettings settings = extractor.settings(); if (d % settings.getSpeed() != 0) { continue; } - BlockPos extractorPos = extractor.connectorPos(); - if (extractorPos == null) { - continue; - } - - Direction side = extractor.sidedConsumer().side(); - BlockPos pos = extractorPos.relative(side); - if (!LevelTools.isLoaded(world, pos)) { + if (!LevelTools.isLoaded(world, extractor.getConnectedEntity().getBlockPos())) { continue; } - - BlockEntity te = world.getBlockEntity(pos); - // @todo ugly code! - IFluidHandler handler = getFluidHandlerAt(te, settings.getFacing()).resolve().orElse(null); - // @todo report error somewhere? - if (handler == null) { - continue; - } - - if (checkRedstone(world, settings, extractorPos)) { + if (checkRedstone(world, settings, extractor.connectorPos())) { continue; } if (!context.matchColor(settings.getColorsMask())) { continue; } - + IFluidHandler handler = extractor.getHandler(); tickFluidHandler(context, settings, handler); } @@ -191,25 +176,17 @@ private int insertFluid(@Nonnull IControllerContext context, @Nonnull FluidStack int amount = stack.getAmount(); for (int j = 0 ; j < fluidConsumers.size() ; j++) { int i = (j + roundRobinOffset) % fluidConsumers.size(); - ConnectedBlock consumer = fluidConsumers.get(i); + ConnectedInventory consumer = fluidConsumers.get(i); FluidConnectorSettings settings = consumer.settings(); - BlockPos consumerPos = consumer.connectorPos(); - Direction side = consumer.sidedConsumer().side(); - BlockPos connectedBlockPos = consumerPos.relative(side); - if (!LevelTools.isLoaded(world, connectedBlockPos)) { - continue; - } - BlockEntity te = world.getBlockEntity(connectedBlockPos); - IFluidHandler destination = getFluidHandlerAt(te, settings.getFacing()).resolve().orElse(null); - // @todo report error somewhere? - if (destination == null) { + if (!LevelTools.isLoaded(world, consumer.getConnectedEntity().getBlockPos())) { continue; } + IFluidHandler destination = consumer.getHandler(); FluidStack matcher = settings.getMatcher(); if (matcher != null && !matcher.equals(stack)) { continue; } - if (checkRedstone(world, settings, consumerPos) || !context.matchColor(settings.getColorsMask())) { + if (checkRedstone(world, settings, consumer.connectorPos()) || !context.matchColor(settings.getColorsMask())) { continue; } @@ -255,14 +232,19 @@ private void updateCache(int channel, IControllerContext context) { if (fluidExtractors == null) { fluidExtractors = new ArrayList<>(); fluidConsumers = new ArrayList<>(); + Level world = context.getControllerWorld(); Map connectors = context.getConnectors(channel); for (var entry : connectors.entrySet()) { FluidConnectorSettings con = (FluidConnectorSettings) entry.getValue(); - BlockPos connectorPos = context.findConsumerPosition(entry.getKey().consumerId()); + ConnectedInventory connectedInventory; + connectedInventory = getConnectedInventoryInfo(context, entry, world, con); + if (connectedInventory == null) { + continue; + } if (con.getFluidMode() == InsExtMode.EXT) { - fluidExtractors.add(new ConnectedBlock<>(entry.getKey(), con, connectorPos)); + fluidExtractors.add(connectedInventory); } else { - fluidConsumers.add(new ConnectedBlock<>(entry.getKey(), con, connectorPos)); + fluidConsumers.add(connectedInventory); } } @@ -270,8 +252,12 @@ private void updateCache(int channel, IControllerContext context) { for (var entry : connectors.entrySet()) { FluidConnectorSettings con = (FluidConnectorSettings) entry.getValue(); if (con.getFluidMode() == InsExtMode.INS) { - BlockPos connectorPos = context.findConsumerPosition(entry.getKey().consumerId()); - fluidConsumers.add(new ConnectedBlock<>(entry.getKey(), con, connectorPos)); + ConnectedInventory connectedInventory; + connectedInventory = getConnectedInventoryInfo(context, entry, world, con); + if (connectedInventory == null) { + continue; + } + fluidConsumers.add(connectedInventory); } } @@ -279,6 +265,31 @@ private void updateCache(int channel, IControllerContext context) { } } + @Nullable + private ConnectedInventory getConnectedInventoryInfo( + IControllerContext context, Map.Entry entry, @Nonnull Level world, @Nonnull FluidConnectorSettings con + ) { + BlockPos connectorPos = context.findConsumerPosition(entry.getKey().consumerId()); + if (connectorPos == null) { + return null; + } + ConnectorTileEntity connectorTileEntity = (ConnectorTileEntity) world.getBlockEntity(connectorPos); + if (connectorTileEntity == null) { + return null; + } + BlockPos connectedBlockPos = connectorPos.relative(entry.getKey().side()); + BlockEntity connectedEntity = world.getBlockEntity(connectedBlockPos); + if (connectedEntity == null) { + return null; + } + Optional fluidHandlerOptional = getFluidHandlerAt(connectedEntity, con.getFacing()).resolve(); + if (fluidHandlerOptional.isEmpty()) { + return null; + } + IFluidHandler fluidHandler = fluidHandlerOptional.get(); + return new ConnectedInventory<>(entry.getKey(), con, connectorPos, connectedEntity, connectorTileEntity, fluidHandler); + } + @Override public boolean isEnabled(String tag) { return true; diff --git a/src/main/java/mcjty/xnet/apiimpl/items/ItemChannelSettings.java b/src/main/java/mcjty/xnet/apiimpl/items/ItemChannelSettings.java index 7acd6ace..c0df4f8a 100644 --- a/src/main/java/mcjty/xnet/apiimpl/items/ItemChannelSettings.java +++ b/src/main/java/mcjty/xnet/apiimpl/items/ItemChannelSettings.java @@ -13,11 +13,13 @@ import mcjty.rftoolsbase.api.xnet.keys.SidedConsumer; import mcjty.xnet.XNet; import mcjty.xnet.apiimpl.ConnectedBlock; +import mcjty.xnet.apiimpl.ConnectedInventory; import mcjty.xnet.apiimpl.EnumStringTranslators; import mcjty.xnet.apiimpl.enums.ChannelMode; import mcjty.xnet.apiimpl.enums.InsExtMode; import mcjty.xnet.apiimpl.items.enums.StackMode; import mcjty.xnet.compat.RFToolsSupport; +import mcjty.xnet.modules.cables.blocks.ConnectorTileEntity; import mcjty.xnet.setup.Config; import mcjty.xnet.utils.CastTools; import net.minecraft.core.BlockPos; @@ -53,8 +55,8 @@ public class ItemChannelSettings extends DefaultChannelSettings implements IChan // Cache data - private List> itemExtractors = null; - private List> itemConsumers = null; + private List> itemExtractors = null; + private List> itemConsumers = null; private boolean[] consumerFull; // ΐrray of filled consumers in which you don't have to try to insert private ChannelMode channelMode = ChannelMode.PRIORITY; private int delay = 0; @@ -162,40 +164,29 @@ public void tick(int channel, IControllerContext context) { Level world = context.getControllerWorld(); consumerFull = new boolean[itemConsumers.size()]; for (int i = 0; i < itemExtractors.size(); i++) { - ConnectedBlock extractor = itemExtractors.get(i); + ConnectedInventory extractor = itemExtractors.get(i); ItemConnectorSettings settings = extractor.settings(); if (d % settings.getSpeed() != 0) { continue; } ConsumerId consumerId = extractor.sidedConsumer().consumerId(); - BlockPos extractorPos = extractor.connectorPos(); - if (extractorPos == null) { - continue; - } - Direction side = extractor.sidedConsumer().side(); - BlockPos pos = extractorPos.relative(side); - if (!LevelTools.isLoaded(world, pos)) { + if (!LevelTools.isLoaded(world, extractor.getConnectedEntity().getBlockPos())) { continue; } - if (checkRedstone(world, settings, extractorPos)) { + if (checkRedstone(world, settings, extractor.connectorPos())) { continue; } if (!context.matchColor(settings.getColorsMask())) { continue; } - BlockEntity te = world.getBlockEntity(pos); - - if (RFToolsSupport.isStorageScanner(te)) { - RFToolsSupport.tickStorageScanner(context, settings, te, this, world); + if (RFToolsSupport.isStorageScanner(extractor.getConnectedEntity())) { + RFToolsSupport.tickStorageScanner(context, settings, extractor.getConnectedEntity(), this, world); } else { - IItemHandler handler = getItemHandlerAt(te, settings.getFacing()); - if (handler == null) { - continue; - } + IItemHandler handler = extractor.getHandler(); int idx = getStartExtractIndex(settings, consumerId, handler); idx = tickItemHandler(context, settings, handler, world, idx, i); if (handler.getSlots() > 0) { @@ -305,26 +296,19 @@ public int insertStack(@Nonnull IControllerContext context, @Nonnull ItemStack s if (consumerFull[i]) { continue; } - ConnectedBlock consumer = itemConsumers.get(i); + ConnectedInventory consumer = itemConsumers.get(i); ItemConnectorSettings settings = consumer.settings(); - BlockPos connectorPos = consumer.connectorPos(); - Direction side = consumer.sidedConsumer().side(); - BlockPos connectedBlockPos = connectorPos.relative(side); - if (!LevelTools.isLoaded(world, connectedBlockPos)) { + if (!LevelTools.isLoaded(world, consumer.getConnectedEntity().getBlockPos())) { continue; } - BlockEntity te = world.getBlockEntity(connectedBlockPos); ItemStack remaining; - IItemHandler destination = getItemHandlerAt(te, settings.getFacing()); - if (destination == null) { - continue; - } + IItemHandler destination = consumer.getHandler(); Predicate matcher = settings.getMatcher(context); - if (!matcher.test(source) || checkRedstone(world, settings, connectorPos) || !context.matchColor(settings.getColorsMask())) { + if (!matcher.test(source) || checkRedstone(world, settings, consumer.connectorPos()) || !context.matchColor(settings.getColorsMask())) { continue; } @@ -379,7 +363,7 @@ public int insertStackToStorageScanner(@Nonnull IControllerContext context, @Non int consumersSize = itemConsumers.size(); for (int j = 0; j < consumersSize; j++) { int i = (j + roundRobinOffset) % consumersSize; - ConnectedBlock consumer = itemConsumers.get(i); + ConnectedInventory consumer = itemConsumers.get(i); ItemConnectorSettings settings = consumer.settings(); BlockPos connectorPos = consumer.connectorPos(); @@ -485,22 +469,32 @@ private void updateCache(int channel, IControllerContext context) { if (itemExtractors == null) { itemExtractors = new ArrayList<>(); itemConsumers = new ArrayList<>(); + Level world = context.getControllerWorld(); Map connectors = context.getConnectors(channel); for (Map.Entry entry : connectors.entrySet()) { ItemConnectorSettings con = (ItemConnectorSettings) entry.getValue(); - BlockPos connectorPos = context.findConsumerPosition(entry.getKey().consumerId()); + ConnectedInventory connectedInventory; + connectedInventory = getConnectedInventoryInfo(context, entry, world, con); + if (connectedInventory == null) { + continue; + } if (con.getItemMode() == InsExtMode.EXT) { - itemExtractors.add(new ConnectedBlock<>(entry.getKey(), con, connectorPos)); + itemExtractors.add(connectedInventory); } else { - itemConsumers.add(new ConnectedBlock<>(entry.getKey(), con, connectorPos)); + itemConsumers.add(connectedInventory); } + } connectors = context.getRoutedConnectors(channel); for (Map.Entry entry : connectors.entrySet()) { ItemConnectorSettings con = (ItemConnectorSettings) entry.getValue(); if (con.getItemMode() == InsExtMode.INS) { - BlockPos connectorPos = context.findConsumerPosition(entry.getKey().consumerId()); - itemConsumers.add(new ConnectedBlock<>(entry.getKey(), con, connectorPos)); + ConnectedInventory connectedInventory; + connectedInventory = getConnectedInventoryInfo(context, entry, world, con); + if (connectedInventory == null) { + continue; + } + itemConsumers.add(connectedInventory); } } @@ -508,6 +502,27 @@ private void updateCache(int channel, IControllerContext context) { } } + @Nullable + private ConnectedInventory getConnectedInventoryInfo( + IControllerContext context, Map.Entry entry, Level world, ItemConnectorSettings con + ) { + BlockPos connectorPos = context.findConsumerPosition(entry.getKey().consumerId()); + if (connectorPos == null) { + return null; + } + ConnectorTileEntity connectorEntity = (ConnectorTileEntity) world.getBlockEntity(connectorPos); + if (connectorEntity == null) { + return null; + } + BlockPos connectedBlockPos = connectorPos.relative(entry.getKey().side()); + BlockEntity connectedEntity = world.getBlockEntity(connectedBlockPos); + if (connectedEntity == null) { + return null; + } + IItemHandler connectedInventory = getItemHandlerAt(connectedEntity, con.getFacing()); + return new ConnectedInventory<>(entry.getKey(), con, connectorPos, connectedEntity, connectorEntity, connectedInventory); + } + @Override public void cleanCache() { itemExtractors = null; diff --git a/src/main/java/mcjty/xnet/apiimpl/items/ItemConnectorSettings.java b/src/main/java/mcjty/xnet/apiimpl/items/ItemConnectorSettings.java index 74f55dae..57184e10 100644 --- a/src/main/java/mcjty/xnet/apiimpl/items/ItemConnectorSettings.java +++ b/src/main/java/mcjty/xnet/apiimpl/items/ItemConnectorSettings.java @@ -159,6 +159,9 @@ public void createGui(IEditorGui gui) { ITEM_FILTER_OFF.i18n(), "1", "2", "3", "4") .nl(); for (int i = 0 ; i < FILTER_SIZE ; i++) { + if (i > 0 && i % 9 == 0) { + gui.nl(); + } gui.ghostSlot(TAG_FLT + i, filters.get(i)); } } diff --git a/src/main/java/mcjty/xnet/apiimpl/logic/LogicChannelSettings.java b/src/main/java/mcjty/xnet/apiimpl/logic/LogicChannelSettings.java index f3ad6369..6bcfc334 100644 --- a/src/main/java/mcjty/xnet/apiimpl/logic/LogicChannelSettings.java +++ b/src/main/java/mcjty/xnet/apiimpl/logic/LogicChannelSettings.java @@ -22,6 +22,7 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; +import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.util.ArrayList; import java.util.List; @@ -67,32 +68,28 @@ public void tick(int channel, IControllerContext context) { Level world = context.getControllerWorld(); colors = 0; - for (ConnectedBlock connector : sensors) { - LogicConnectorSettings settings = connector.settings(); + for (ConnectedBlock connectedBlock : sensors) { + LogicConnectorSettings settings = connectedBlock.settings(); int sensorColors = 0; - BlockPos connectorPos = connector.connectorPos(); - if (connectorPos != null) { - Direction side = connector.sidedConsumer().side(); - BlockPos pos = connectorPos.relative(side); - if (!LevelTools.isLoaded(world, pos)) { - // If it is not chunkloaded we just use the color settings as we last remembered it - colors |= settings.getColorMask(); - continue; - } + BlockPos pos = connectedBlock.getConnectedEntity().getBlockPos(); + if (!LevelTools.isLoaded(world, pos)) { + // If it is not chunkloaded we just use the color settings as we last remembered it + colors |= settings.getColorMask(); + continue; + } - boolean sense = !checkRedstone(world, settings, connectorPos); - if (sense && !context.matchColor(settings.getColorsMask())) { - sense = false; - } + boolean sense = !checkRedstone(world, settings, connectedBlock.connectorPos()); + if (sense && !context.matchColor(settings.getColorsMask())) { + sense = false; + } - // If sense is false the sensor is disabled which means the colors from it will also be disabled - if (sense) { - BlockEntity te = world.getBlockEntity(pos); + // If sense is false the sensor is disabled which means the colors from it will also be disabled + if (sense) { + BlockEntity te = connectedBlock.getConnectedEntity(); - for (RSSensor sensor : settings.getSensors()) { - if (sensor.test(te, world, pos, settings)) { - sensorColors |= 1 << sensor.getOutputColor().ordinal(); - } + for (RSSensor sensor : settings.getSensors()) { + if (sensor.test(te, world, pos, settings)) { + sensorColors |= 1 << sensor.getOutputColor().ordinal(); } } } @@ -109,20 +106,18 @@ public void tick(int channel, IControllerContext context) { } Direction side = connector.sidedConsumer().side(); - BlockEntity te = world.getBlockEntity(connectorPos); - if (te instanceof ConnectorTileEntity connectorTE) { - int powerOut; - if (checkRedstone(world, settings, connectorPos) || !context.matchColor(settings.getColorsMask())) { - powerOut = 0; - } else { - RSOutput output = settings.getOutput(); - boolean[] colorsArray = LogicTools.intToBinary(colors); - boolean input1 = colorsArray[output.getInputChannel1().ordinal()]; - boolean input2 = colorsArray[output.getInputChannel2().ordinal()]; - powerOut = LogicOperations.applyFilter(output, input1, input2) ? output.getRedstoneOut() : 0; - } - connectorTE.setPowerOut(side, powerOut); + ConnectorTileEntity connectorTileEntity = connector.getConnectorEntity(); + int powerOut; + if (checkRedstone(world, settings, connectorPos) || !context.matchColor(settings.getColorsMask())) { + powerOut = 0; + } else { + RSOutput output = settings.getOutput(); + boolean[] colorsArray = LogicTools.intToBinary(colors); + boolean input1 = colorsArray[output.getInputChannel1().ordinal()]; + boolean input2 = colorsArray[output.getInputChannel2().ordinal()]; + powerOut = LogicOperations.applyFilter(output, input1, input2) ? output.getRedstoneOut() : 0; } + connectorTileEntity.setPowerOut(side, powerOut); } } @@ -130,14 +125,19 @@ private void updateCache(int channel, IControllerContext context) { if (sensors == null) { sensors = new ArrayList<>(); outputs = new ArrayList<>(); + Level world = context.getControllerWorld(); Map connectors = context.getConnectors(channel); for (Map.Entry entry : connectors.entrySet()) { LogicConnectorSettings con = (LogicConnectorSettings) entry.getValue(); - BlockPos connectorPos = context.findConsumerPosition(entry.getKey().consumerId()); + ConnectedBlock connectedBlock; + connectedBlock = getConnectedBlockInfo(context, entry, world, con); + if (connectedBlock == null) { + continue; + } if (con.getLogicMode() == LogicMode.SENSOR) { - sensors.add(new ConnectedBlock<>(entry.getKey(), con, connectorPos)); + sensors.add(connectedBlock); } else { - outputs.add(new ConnectedBlock<>(entry.getKey(), con, connectorPos)); + outputs.add(connectedBlock); } } @@ -145,13 +145,37 @@ private void updateCache(int channel, IControllerContext context) { for (Map.Entry entry : connectors.entrySet()) { LogicConnectorSettings con = (LogicConnectorSettings) entry.getValue(); if (con.getLogicMode() == LogicMode.OUTPUT) { - BlockPos connectorPos = context.findConsumerPosition(entry.getKey().consumerId()); - outputs.add(new ConnectedBlock<>(entry.getKey(), con, connectorPos)); + ConnectedBlock connectedBlock; + connectedBlock = getConnectedBlockInfo(context, entry, world, con); + if (connectedBlock == null) { + continue; + } + outputs.add(connectedBlock); } } } } + @Nullable + private ConnectedBlock getConnectedBlockInfo( + IControllerContext context, Map.Entry entry, @Nonnull Level world, @Nonnull LogicConnectorSettings con + ) { + BlockPos connectorPos = context.findConsumerPosition(entry.getKey().consumerId()); + if (connectorPos == null) { + return null; + } + BlockPos connectedBlockPos = connectorPos.relative(entry.getKey().side()); + BlockEntity connectedEntity = world.getBlockEntity(connectedBlockPos); + if (connectedEntity == null) { + return null; + } + ConnectorTileEntity connectorEntity = (ConnectorTileEntity) world.getBlockEntity(connectorPos); + if (connectorEntity == null) { + return null; + } + return new ConnectedBlock<>(entry.getKey(), con, connectorPos, connectedEntity, connectorEntity); + } + @Override public void cleanCache() { sensors = null; diff --git a/src/main/java/mcjty/xnet/compat/jei/JeiCompat.java b/src/main/java/mcjty/xnet/compat/jei/JeiCompat.java new file mode 100644 index 00000000..47cc5718 --- /dev/null +++ b/src/main/java/mcjty/xnet/compat/jei/JeiCompat.java @@ -0,0 +1,40 @@ +package mcjty.xnet.compat.jei; + +import mcjty.lib.McJtyLib; +import mcjty.lib.container.GenericContainer; +import mcjty.lib.gui.GenericGuiContainer; +import mezz.jei.api.IModPlugin; +import mezz.jei.api.JeiPlugin; +import mezz.jei.api.gui.handlers.IGuiContainerHandler; +import mezz.jei.api.registration.IGuiHandlerRegistration; +import net.minecraft.client.renderer.Rect2i; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.inventory.AbstractContainerMenu; + +import javax.annotation.Nonnull; +import java.util.List; + +@JeiPlugin +public class JeiCompat implements IModPlugin { + + @Nonnull + @Override + public ResourceLocation getPluginUid() { + return new ResourceLocation(McJtyLib.MODID, "xnet"); + } + + @Override + public void registerGuiHandlers(IGuiHandlerRegistration registration) { + registration.addGenericGuiContainerHandler(GenericGuiContainer.class, new JeiCompat.Handler()); + registration.addGhostIngredientHandler(GenericGuiContainer.class, new JeiGhostIngredientHandler<>()); + } + + static class Handler implements IGuiContainerHandler> { + @Nonnull + @Override + public List getGuiExtraAreas(GenericGuiContainer containerScreen) { + return containerScreen.getExtraWindowBounds(); + } + } + +} diff --git a/src/main/java/mcjty/xnet/compat/jei/JeiGhostIngredientHandler.java b/src/main/java/mcjty/xnet/compat/jei/JeiGhostIngredientHandler.java new file mode 100644 index 00000000..80403438 --- /dev/null +++ b/src/main/java/mcjty/xnet/compat/jei/JeiGhostIngredientHandler.java @@ -0,0 +1,88 @@ +package mcjty.xnet.compat.jei; + +import com.google.common.collect.ImmutableList; +import mcjty.lib.gui.GenericGuiContainer; +import mcjty.lib.gui.widgets.BlockRender; +import mcjty.lib.gui.widgets.Panel; +import mcjty.lib.gui.widgets.Widget; +import mcjty.xnet.modules.controller.client.GuiController; +import mezz.jei.api.constants.VanillaTypes; +import mezz.jei.api.gui.handlers.IGhostIngredientHandler; +import mezz.jei.api.ingredients.ITypedIngredient; +import net.minecraft.client.renderer.Rect2i; +import net.minecraft.world.item.ItemStack; +import org.jetbrains.annotations.NotNull; + +import java.util.List; +import java.util.Optional; + +public class JeiGhostIngredientHandler> implements IGhostIngredientHandler { + + + @Override + public List> getTargetsTyped(GUI gui, ITypedIngredient ingredient, boolean b) { + Optional optionalItemStack = ingredient.getIngredient(VanillaTypes.ITEM_STACK); + if (optionalItemStack.isEmpty()) { + return ImmutableList.of(); + } else { + ItemStack itemStack = optionalItemStack.get(); + if (itemStack.isEmpty()) { + return ImmutableList.of(); + } + ImmutableList.Builder> builder = ImmutableList.builder(); + + if (gui instanceof GuiController guiController) { + for (Widget widget : guiController.getConnectorEditPanel().getChildren()) { + if (widget instanceof BlockRender blockRender) { + builder.add((Target) new GhostSlotTarget(blockRender, (GuiController) gui)); + } + } + } + return builder.build(); + } + } + + @Override + public void onComplete() { + + } + + private static class GhostSlotTarget implements Target { + + public static final int SIDE_WIDTH = 80; // width of sidegui.png + + final BlockRender slot; + final GuiController gui; + Rect2i area; + int lastGuiLeft, lastGuiTop; + + public GhostSlotTarget(BlockRender slot, GuiController gui) { + this.slot = slot; + this.gui = gui; + initRectangle(); + } + + private void initRectangle() { + Panel connectorEditPanel = gui.getConnectorEditPanel(); + int pointX = connectorEditPanel.getBounds().x + slot.getBounds().x - SIDE_WIDTH; + int pointY = connectorEditPanel.getBounds().y + slot.getBounds().y; + area = new Rect2i(gui.getGuiLeft() + pointX, gui.getGuiTop() + pointY, 16, 16); + lastGuiLeft = gui.getGuiLeft(); + lastGuiTop = gui.getGuiTop(); + } + + @Override + public @NotNull Rect2i getArea() { + if (lastGuiLeft != gui.getGuiLeft() || lastGuiTop != gui.getGuiTop()) { + initRectangle(); + } + return area; + } + + @Override + public void accept(@NotNull ItemStack ingredient) { + slot.fireDraggedEvents(ingredient); + } + + } +} diff --git a/src/main/java/mcjty/xnet/modules/cables/blocks/ConnectorBlock.java b/src/main/java/mcjty/xnet/modules/cables/blocks/ConnectorBlock.java index 33510f96..28a4ea04 100644 --- a/src/main/java/mcjty/xnet/modules/cables/blocks/ConnectorBlock.java +++ b/src/main/java/mcjty/xnet/modules/cables/blocks/ConnectorBlock.java @@ -366,7 +366,7 @@ public void createCableSegment(Level world, BlockPos pos, ConsumerId consumer) { blobData.save(); } - public static boolean isAdvancedConnector(Level world, BlockPos pos) { + public static boolean isAdvancedConnector(@Nonnull Level world, @Nonnull BlockPos pos) { Block block = world.getBlockState(pos).getBlock(); if (block instanceof GenericCableBlock) { return ((GenericCableBlock) block).isAdvancedConnector(); diff --git a/src/main/java/mcjty/xnet/modules/controller/blocks/TileEntityController.java b/src/main/java/mcjty/xnet/modules/controller/blocks/TileEntityController.java index f51ca689..f48258fd 100644 --- a/src/main/java/mcjty/xnet/modules/controller/blocks/TileEntityController.java +++ b/src/main/java/mcjty/xnet/modules/controller/blocks/TileEntityController.java @@ -142,6 +142,7 @@ public final class TileEntityController extends TickingTileEntity implements ICo .playerSlots(91, 157)); private NetworkId networkId; + private WorldBlob worldBlob; private int wirelessVersion = -1; // To invalidate wireless channels if needed private final ChannelInfo[] channels = new ChannelInfo[MAX_CHANNELS]; @@ -214,7 +215,7 @@ protected void createBlockStateDefinition(@Nonnull StateDefinition.Builder { checker.add(worldBlob.getNetworksAt(router.getBlockPos())); // We're only interested in one network. The other router networks are all same topology @@ -296,7 +297,9 @@ public int getColors() { @Override public void tickServer() { - WorldBlob worldBlob = XNetBlobData.get(level).getWorldBlob(level); + if (worldBlob == null) { + worldBlob = XNetBlobData.get(level).getWorldBlob(level); + } BlockState state = level.getBlockState(worldPosition); if (worldBlob.getNetworksAt(getBlockPos()).size() > 1) { diff --git a/src/main/java/mcjty/xnet/modules/controller/client/AbstractEditorPanel.java b/src/main/java/mcjty/xnet/modules/controller/client/AbstractEditorPanel.java index 482a7158..e9c0f07d 100644 --- a/src/main/java/mcjty/xnet/modules/controller/client/AbstractEditorPanel.java +++ b/src/main/java/mcjty/xnet/modules/controller/client/AbstractEditorPanel.java @@ -356,7 +356,7 @@ public void select() { ItemStack holding = Minecraft.getInstance().player.containerMenu.getCarried(); if (holding.isEmpty()) { update(tag, holding); - blockRender.renderItem(null); + blockRender.renderItem(holding); } else { ItemStack copy = holding.copy(); copy.setCount(1); @@ -370,6 +370,10 @@ public void doubleClick() { } }); + blockRender.event(itemStack -> { + update(tag, itemStack); + blockRender.renderItem(itemStack); + }); blockRender.hint(x, y-1, 17, 17); data.put(tag, stack); panel.children(blockRender); diff --git a/src/main/java/mcjty/xnet/modules/controller/client/GuiController.java b/src/main/java/mcjty/xnet/modules/controller/client/GuiController.java index 7767dc3f..62c45b9e 100644 --- a/src/main/java/mcjty/xnet/modules/controller/client/GuiController.java +++ b/src/main/java/mcjty/xnet/modules/controller/client/GuiController.java @@ -185,6 +185,14 @@ private void setupEvents() { } } + public TileEntityController getController() { + return tileEntity; + } + + public Panel getConnectorEditPanel() { + return connectorEditPanel; + } + private void initializeFields() { channelEditPanel = window.findChild(WIDGET_CHANNEL_EDIT_PANEL); connectorEditPanel = window.findChild(WIDGET_CONNECTOR_EDIT_PANEL); @@ -428,7 +436,6 @@ private void refreshChannelEditor() { ChannelChoiceLabel type = new ChannelChoiceLabel() .hint(5, 3, 95, 14); IChannelType[] channels = XNet.xNetApi.getChannels().values().toArray(new IChannelType[]{}); - System.out.println(Arrays.toString(channels)); type.choices(channels); Button create = button(100, 3, 53, 14, CREATE_LABEL.i18n()) .event(() -> createChannel(type.getCurrentChoice())); diff --git a/src/main/resources/assets/xnet/lang/ru_ru.json b/src/main/resources/assets/xnet/lang/ru_ru.json index f0b629c5..18c1a7a9 100644 --- a/src/main/resources/assets/xnet/lang/ru_ru.json +++ b/src/main/resources/assets/xnet/lang/ru_ru.json @@ -147,21 +147,21 @@ "xnet.enum.channelmode.priority.tooltip": "Π Π΅ΠΆΠΈΠΌ распрСдСлСния ΠΏΡ€Π΅Π΄ΠΌΠ΅Ρ‚ΠΎΠ²|По ΠΏΡ€ΠΈΠΎΡ€ΠΈΡ‚Π΅Ρ‚Ρƒ (Π²Ρ‹ΡˆΠ΅-Ρ€Π°Π½ΡŒΡˆΠ΅)", "xnet.enum.channelmode.roundrobin": "Π Π°Π²Π½ΠΎΠΌΠ΅Ρ€Π½ΠΎ", "xnet.enum.channelmode.roundrobin.tooltip": "Π Π΅ΠΆΠΈΠΌ распрСдСлСния ΠΏΡ€Π΅Π΄ΠΌΠ΅Ρ‚ΠΎΠ²|Π Π°Π²Π½ΠΎΠΌΠ΅Ρ€Π½ΠΎΠ΅ распрСдСлСниС", - "xnet.enum.insextmode.ins": "ΠŸΠΎΠΌΠ΅Ρ‰Π°Ρ‚ΡŒ", + "xnet.enum.insextmode.ins": "Пом.", "xnet.enum.insextmode.ins.tooltip": "ΠŸΠΎΠΌΠ΅Ρ‰Π°Ρ‚ΡŒ Π² ΠΏΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π΅Π½Π½Ρ‹ΠΉ Π±Π»ΠΎΠΊ", - "xnet.enum.insextmode.ext": "Π˜Π·Π²Π»Π΅ΠΊΠ°Ρ‚ΡŒ", + "xnet.enum.insextmode.ext": "Изв.", "xnet.enum.insextmode.ext.tooltip": "Π˜Π·Π²Π»Π΅ΠΊΠ°Ρ‚ΡŒ ΠΈΠ· ΠΏΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π΅Π½Π½ΠΎΠ³ΠΎ Π±Π»ΠΎΠΊΠ°", - "xnet.enum.items.extractmode.first": "ΠŸΠ΅Ρ€Π²Ρ‹ΠΉ", + "xnet.enum.items.extractmode.first": "ΠŸΠ΅Ρ€Π².", "xnet.enum.items.extractmode.first.tooltip": "Π˜Π·Π²Π»Π΅ΠΊΠ°Ρ‚ΡŒ ΠΈΠ· ΠΏΠ΅Ρ€Π²ΠΎΠ³ΠΎ|доступного слота", - "xnet.enum.items.extractmode.rnd": "Π Π°Π½Π΄ΠΎΠΌ", + "xnet.enum.items.extractmode.rnd": "Π Π°Π½Π΄.", "xnet.enum.items.extractmode.rnd.tooltip": "Π˜Π·Π²Π»Π΅ΠΊΠ°Ρ‚ΡŒ ΠΈΠ· Ρ€Π°Π½Π΄ΠΎΠΌΠ½ΠΎΠ³ΠΎ слота", - "xnet.enum.items.extractmode.order": "ПослСд.", + "xnet.enum.items.extractmode.order": "Посл.", "xnet.enum.items.extractmode.order.tooltip": "Π˜Π·Π²Π»Π΅ΠΊΠ°Ρ‚ΡŒ ΠΈΠ· всСх слотов|ΠΏΠΎΡΠ»Π΅Π΄ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒΠ½ΠΎ", "xnet.enum.items.stackmode.single": "Один", "xnet.enum.items.stackmode.single.tooltip": "ΠŸΡ€Π΅Π΄ΠΌΠ΅Ρ‚ΠΎΠ² Π·Π° ΠΎΠΏΠ΅Ρ€Π°Ρ†ΠΈΡŽ|Один ΠΏΡ€Π΅Π΄ΠΌΠ΅Ρ‚", "xnet.enum.items.stackmode.stack": "Π‘Ρ‚Π°ΠΊ", "xnet.enum.items.stackmode.stack.tooltip": "ΠŸΡ€Π΅Π΄ΠΌΠ΅Ρ‚ΠΎΠ² Π·Π° ΠΎΠΏΠ΅Ρ€Π°Ρ†ΠΈΡŽ|Π‘Ρ‚Π°ΠΊ", - "xnet.enum.items.stackmode.count": "Кол-Π²ΠΎ", + "xnet.enum.items.stackmode.count": "Π£ΠΊΠ°Π·.", "xnet.enum.items.stackmode.count.tooltip": "ΠŸΡ€Π΅Π΄ΠΌΠ΅Ρ‚ΠΎΠ² Π·Π° ΠΎΠΏΠ΅Ρ€Π°Ρ†ΠΈΡŽ|Π£ΠΊΠ°Π·Π°Π½Π½ΠΎΠ΅ количСство", "xnet.enum.logic.logicfilter.off.tooltip": "Π“Π΅Π½Π΅Ρ€ΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ Π²Ρ‹Ρ…ΠΎΠ΄Π½ΠΎΠΉ сигнал, Ссли Π°ΠΊΡ‚ΠΈΠ²Π΅Π½", "xnet.enum.logic.logicfilter.not.tooltip": "ΠŸΡ€ΠΈΠΌΠ΅Π½ΠΈΡ‚ΡŒ ΠΊ Π²Ρ…ΠΎΠ΄Π½ΠΎΠΌΡƒ сигналу|ЛогичСскоС NOT", From b9fb9dead88141832adb3a296dc4817414d0d98d Mon Sep 17 00:00:00 2001 From: Alex Emelyanov Date: Fri, 17 May 2024 19:03:00 +0300 Subject: [PATCH 2/2] patch from 1.19 --- .../mcjty/xnet/apiimpl/ConnectedBlock.java | 12 +-- .../xnet/apiimpl/ConnectedInventory.java | 9 +- .../apiimpl/energy/EnergyChannelSettings.java | 21 +++-- .../apiimpl/energy/EnergyConnectedBlock.java | 22 ----- .../apiimpl/energy/EnergyConnectedEntity.java | 22 +++++ .../apiimpl/fluids/FluidChannelSettings.java | 6 +- .../apiimpl/items/ItemChannelSettings.java | 84 +++---------------- .../xnet/apiimpl/logic/ConnectedEntity.java | 34 ++++++++ .../apiimpl/logic/LogicChannelSettings.java | 35 +++++--- .../mcjty/xnet/compat/RFToolsSupport.java | 2 +- .../resources/assets/xnet/lang/ru_ru.json | 8 +- 11 files changed, 122 insertions(+), 133 deletions(-) delete mode 100644 src/main/java/mcjty/xnet/apiimpl/energy/EnergyConnectedBlock.java create mode 100644 src/main/java/mcjty/xnet/apiimpl/energy/EnergyConnectedEntity.java create mode 100644 src/main/java/mcjty/xnet/apiimpl/logic/ConnectedEntity.java diff --git a/src/main/java/mcjty/xnet/apiimpl/ConnectedBlock.java b/src/main/java/mcjty/xnet/apiimpl/ConnectedBlock.java index b8c9a516..24a9f3c1 100644 --- a/src/main/java/mcjty/xnet/apiimpl/ConnectedBlock.java +++ b/src/main/java/mcjty/xnet/apiimpl/ConnectedBlock.java @@ -3,7 +3,6 @@ import mcjty.rftoolsbase.api.xnet.keys.SidedConsumer; import mcjty.xnet.modules.cables.blocks.ConnectorTileEntity; import net.minecraft.core.BlockPos; -import net.minecraft.world.level.block.entity.BlockEntity; import javax.annotation.Nonnull; @@ -12,14 +11,15 @@ public class ConnectedBlock { @Nonnull private final SidedConsumer sidedConsumer; @Nonnull private final T settings; @Nonnull private final BlockPos connectorPos; - @Nonnull private final BlockEntity connectedEntity; + @Nonnull private final BlockPos blockPos; @Nonnull private final ConnectorTileEntity connectorEntity; - public ConnectedBlock(@Nonnull SidedConsumer sidedConsumer, @Nonnull T settings, @Nonnull BlockPos connectorPos, @Nonnull BlockEntity connectedEntity, @Nonnull ConnectorTileEntity connectorEntity) { + public ConnectedBlock(@Nonnull SidedConsumer sidedConsumer, @Nonnull T settings, @Nonnull BlockPos connectorPos, + @Nonnull BlockPos blockPos, @Nonnull ConnectorTileEntity connectorEntity) { this.sidedConsumer = sidedConsumer; this.settings = settings; this.connectorPos = connectorPos; - this.connectedEntity = connectedEntity; + this.blockPos = blockPos; this.connectorEntity = connectorEntity; } @@ -33,8 +33,8 @@ public ConnectedBlock(@Nonnull SidedConsumer sidedConsumer, @Nonnull T settings, public BlockPos connectorPos() {return connectorPos;} @Nonnull - public BlockEntity getConnectedEntity() { - return connectedEntity; + public BlockPos getBlockPos() { + return blockPos; } @Nonnull diff --git a/src/main/java/mcjty/xnet/apiimpl/ConnectedInventory.java b/src/main/java/mcjty/xnet/apiimpl/ConnectedInventory.java index d2cc94b1..8c9d2e9d 100644 --- a/src/main/java/mcjty/xnet/apiimpl/ConnectedInventory.java +++ b/src/main/java/mcjty/xnet/apiimpl/ConnectedInventory.java @@ -1,19 +1,20 @@ package mcjty.xnet.apiimpl; import mcjty.rftoolsbase.api.xnet.keys.SidedConsumer; +import mcjty.xnet.apiimpl.logic.ConnectedEntity; import mcjty.xnet.modules.cables.blocks.ConnectorTileEntity; import net.minecraft.core.BlockPos; import net.minecraft.world.level.block.entity.BlockEntity; import javax.annotation.Nonnull; -public class ConnectedInventory extends ConnectedBlock { +public class ConnectedInventory extends ConnectedEntity { @Nonnull private final H handler; public ConnectedInventory(@Nonnull SidedConsumer sidedConsumer, @Nonnull T settings, @Nonnull BlockPos connectorPos, - @Nonnull BlockEntity connectedEntity, @Nonnull ConnectorTileEntity connectorEntity, - @Nonnull H handler) { - super(sidedConsumer, settings, connectorPos, connectedEntity, connectorEntity); + @Nonnull BlockPos blockPos, @Nonnull BlockEntity connectedEntity, + @Nonnull ConnectorTileEntity connectorEntity, @Nonnull H handler) { + super(sidedConsumer, settings, connectorPos, blockPos, connectedEntity, connectorEntity); this.handler = handler; } diff --git a/src/main/java/mcjty/xnet/apiimpl/energy/EnergyChannelSettings.java b/src/main/java/mcjty/xnet/apiimpl/energy/EnergyChannelSettings.java index 21b361df..fa94cd1d 100644 --- a/src/main/java/mcjty/xnet/apiimpl/energy/EnergyChannelSettings.java +++ b/src/main/java/mcjty/xnet/apiimpl/energy/EnergyChannelSettings.java @@ -31,15 +31,14 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Optional; public class EnergyChannelSettings extends DefaultChannelSettings implements IChannelSettings { public static final ResourceLocation iconGuiElements = new ResourceLocation(XNet.MODID, "textures/gui/guielements.png"); // Cache data - private List energyExtractors = null; - private List energyConsumers = null; + private List energyExtractors = null; + private List energyConsumers = null; private long maxConsume = 0; // Maximum RF that all consumers can accept per tick @Override @@ -80,11 +79,11 @@ public void tick(int channel, IControllerContext context) { Map alreadyHandled = new HashMap<>(); List> energyProducers = new ArrayList<>(); - for (EnergyConnectedBlock extractor : energyExtractors) { + for (EnergyConnectedEntity extractor : energyExtractors) { BlockPos connectorPos = extractor.connectorPos(); Direction side = extractor.sidedConsumer().side(); - if (!LevelTools.isLoaded(world, extractor.getConnectedEntity().getBlockPos())) { + if (!LevelTools.isLoaded(world, extractor.getBlockPos())) { continue; } @@ -157,9 +156,9 @@ public void tick(int channel, IControllerContext context) { private long insertEnergy(@Nonnull IControllerContext context, long energy) { long total = 0; Level world = context.getControllerWorld(); - for (EnergyConnectedBlock consumer : energyConsumers) { + for (EnergyConnectedEntity consumer : energyConsumers) { EnergyConnectorSettings settings = consumer.settings(); - if (!LevelTools.isLoaded(world, consumer.getConnectedEntity().getBlockPos())) { + if (!LevelTools.isLoaded(world, consumer.getBlockPos())) { continue; } BlockEntity te = consumer.getConnectedEntity(); @@ -220,7 +219,7 @@ private void updateCache(int channel, IControllerContext context) { Level world = context.getControllerWorld(); for (var entry : connectors.entrySet()) { EnergyConnectorSettings con = (EnergyConnectorSettings) entry.getValue(); - EnergyConnectedBlock connectedBlock = getConnectedBlockInfo(context, entry, world, con); + EnergyConnectedEntity connectedBlock = getConnectedBlockInfo(context, entry, world, con); if (connectedBlock == null) { continue; } @@ -235,7 +234,7 @@ private void updateCache(int channel, IControllerContext context) { connectors = context.getRoutedConnectors(channel); for (var entry : connectors.entrySet()) { EnergyConnectorSettings con = (EnergyConnectorSettings) entry.getValue(); - EnergyConnectedBlock connectedBlock = getConnectedBlockInfo(context, entry, world, con); + EnergyConnectedEntity connectedBlock = getConnectedBlockInfo(context, entry, world, con); if (connectedBlock == null) { continue; } @@ -251,7 +250,7 @@ private void updateCache(int channel, IControllerContext context) { } @Nullable - private EnergyConnectedBlock getConnectedBlockInfo( + private EnergyConnectedEntity getConnectedBlockInfo( IControllerContext context, Map.Entry entry, @Nonnull Level world, @Nonnull EnergyConnectorSettings con ) { BlockPos connectorPos = context.findConsumerPosition(entry.getKey().consumerId()); @@ -269,7 +268,7 @@ private EnergyConnectedBlock getConnectedBlockInfo( return null; } Integer rate = getRateOrMax(con, connectorPos, world); - return new EnergyConnectedBlock(entry.getKey(), con, connectorPos, connectedEntity, connectorTileEntity, rate); + return new EnergyConnectedEntity(entry.getKey(), con, connectorPos, connectedBlockPos, connectedEntity, connectorTileEntity, rate); } private static Integer getRateOrMax(@Nonnull EnergyConnectorSettings con, @Nonnull BlockPos connectorPos, diff --git a/src/main/java/mcjty/xnet/apiimpl/energy/EnergyConnectedBlock.java b/src/main/java/mcjty/xnet/apiimpl/energy/EnergyConnectedBlock.java deleted file mode 100644 index c9327da2..00000000 --- a/src/main/java/mcjty/xnet/apiimpl/energy/EnergyConnectedBlock.java +++ /dev/null @@ -1,22 +0,0 @@ -package mcjty.xnet.apiimpl.energy; - -import mcjty.rftoolsbase.api.xnet.keys.SidedConsumer; -import mcjty.xnet.apiimpl.ConnectedBlock; -import mcjty.xnet.modules.cables.blocks.ConnectorTileEntity; -import net.minecraft.core.BlockPos; -import net.minecraft.world.level.block.entity.BlockEntity; - -import javax.annotation.Nonnull; - -public final class EnergyConnectedBlock extends ConnectedBlock { - private final int rate; - - public EnergyConnectedBlock(@Nonnull SidedConsumer sidedConsumer, @Nonnull EnergyConnectorSettings settings, - @Nonnull BlockPos connectorPos, @Nonnull BlockEntity connectedEntity, - @Nonnull ConnectorTileEntity connectorEntity, int rate) { - super(sidedConsumer, settings, connectorPos, connectedEntity, connectorEntity); - this.rate = rate; - } - - public int rate() {return rate;} -} diff --git a/src/main/java/mcjty/xnet/apiimpl/energy/EnergyConnectedEntity.java b/src/main/java/mcjty/xnet/apiimpl/energy/EnergyConnectedEntity.java new file mode 100644 index 00000000..fcccbfa5 --- /dev/null +++ b/src/main/java/mcjty/xnet/apiimpl/energy/EnergyConnectedEntity.java @@ -0,0 +1,22 @@ +package mcjty.xnet.apiimpl.energy; + +import mcjty.rftoolsbase.api.xnet.keys.SidedConsumer; +import mcjty.xnet.apiimpl.logic.ConnectedEntity; +import mcjty.xnet.modules.cables.blocks.ConnectorTileEntity; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.block.entity.BlockEntity; + +import javax.annotation.Nonnull; + +public final class EnergyConnectedEntity extends ConnectedEntity { + private final int rate; + + public EnergyConnectedEntity(@Nonnull SidedConsumer sidedConsumer, @Nonnull EnergyConnectorSettings settings, + @Nonnull BlockPos connectorPos, @Nonnull BlockPos blockPos, @Nonnull BlockEntity connectedEntity, + @Nonnull ConnectorTileEntity connectorEntity, int rate) { + super(sidedConsumer, settings, connectorPos, blockPos, connectedEntity, connectorEntity); + this.rate = rate; + } + + public int rate() {return rate;} +} diff --git a/src/main/java/mcjty/xnet/apiimpl/fluids/FluidChannelSettings.java b/src/main/java/mcjty/xnet/apiimpl/fluids/FluidChannelSettings.java index bc7df003..f0e83f2a 100644 --- a/src/main/java/mcjty/xnet/apiimpl/fluids/FluidChannelSettings.java +++ b/src/main/java/mcjty/xnet/apiimpl/fluids/FluidChannelSettings.java @@ -101,7 +101,7 @@ public void tick(int channel, IControllerContext context) { continue; } - if (!LevelTools.isLoaded(world, extractor.getConnectedEntity().getBlockPos())) { + if (!LevelTools.isLoaded(world, extractor.getBlockPos())) { continue; } if (checkRedstone(world, settings, extractor.connectorPos())) { @@ -178,7 +178,7 @@ private int insertFluid(@Nonnull IControllerContext context, @Nonnull FluidStack int i = (j + roundRobinOffset) % fluidConsumers.size(); ConnectedInventory consumer = fluidConsumers.get(i); FluidConnectorSettings settings = consumer.settings(); - if (!LevelTools.isLoaded(world, consumer.getConnectedEntity().getBlockPos())) { + if (!LevelTools.isLoaded(world, consumer.getBlockPos())) { continue; } IFluidHandler destination = consumer.getHandler(); @@ -287,7 +287,7 @@ private ConnectedInventory getConnectedIn return null; } IFluidHandler fluidHandler = fluidHandlerOptional.get(); - return new ConnectedInventory<>(entry.getKey(), con, connectorPos, connectedEntity, connectorTileEntity, fluidHandler); + return new ConnectedInventory<>(entry.getKey(), con, connectorPos, connectedBlockPos, connectedEntity, connectorTileEntity, fluidHandler); } @Override diff --git a/src/main/java/mcjty/xnet/apiimpl/items/ItemChannelSettings.java b/src/main/java/mcjty/xnet/apiimpl/items/ItemChannelSettings.java index c0df4f8a..f9c2d144 100644 --- a/src/main/java/mcjty/xnet/apiimpl/items/ItemChannelSettings.java +++ b/src/main/java/mcjty/xnet/apiimpl/items/ItemChannelSettings.java @@ -12,7 +12,6 @@ import mcjty.rftoolsbase.api.xnet.keys.ConsumerId; import mcjty.rftoolsbase.api.xnet.keys.SidedConsumer; import mcjty.xnet.XNet; -import mcjty.xnet.apiimpl.ConnectedBlock; import mcjty.xnet.apiimpl.ConnectedInventory; import mcjty.xnet.apiimpl.EnumStringTranslators; import mcjty.xnet.apiimpl.enums.ChannelMode; @@ -30,7 +29,6 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraftforge.common.capabilities.ForgeCapabilities; -import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.ItemHandlerHelper; @@ -40,7 +38,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Optional; import java.util.Random; import java.util.function.Predicate; @@ -48,6 +45,7 @@ import static mcjty.xnet.apiimpl.Constants.TAG_EXTIDX; import static mcjty.xnet.apiimpl.Constants.TAG_MODE; import static mcjty.xnet.apiimpl.Constants.TAG_OFFSET; +import static mcjty.xnet.compat.RFToolsSupport.isStorageScanner; public class ItemChannelSettings extends DefaultChannelSettings implements IChannelSettings { @@ -172,7 +170,7 @@ public void tick(int channel, IControllerContext context) { ConsumerId consumerId = extractor.sidedConsumer().consumerId(); - if (!LevelTools.isLoaded(world, extractor.getConnectedEntity().getBlockPos())) { + if (!LevelTools.isLoaded(world, extractor.getBlockPos())) { continue; } @@ -183,7 +181,7 @@ public void tick(int channel, IControllerContext context) { continue; } - if (RFToolsSupport.isStorageScanner(extractor.getConnectedEntity())) { + if (isStorageScanner(extractor.getConnectedEntity())) { RFToolsSupport.tickStorageScanner(context, settings, extractor.getConnectedEntity(), this, world); } else { IItemHandler handler = extractor.getHandler(); @@ -299,7 +297,7 @@ public int insertStack(@Nonnull IControllerContext context, @Nonnull ItemStack s ConnectedInventory consumer = itemConsumers.get(i); ItemConnectorSettings settings = consumer.settings(); - if (!LevelTools.isLoaded(world, consumer.getConnectedEntity().getBlockPos())) { + if (!LevelTools.isLoaded(world, consumer.getBlockPos())) { continue; } @@ -311,11 +309,13 @@ public int insertStack(@Nonnull IControllerContext context, @Nonnull ItemStack s if (!matcher.test(source) || checkRedstone(world, settings, consumer.connectorPos()) || !context.matchColor(settings.getColorsMask())) { continue; } - + BlockEntity te = consumer.getConnectedEntity(); int toinsert = total; Integer count = settings.getCount(); if (count != null) { - int amount = countItems(destination, matcher); + int amount = isStorageScanner(te) + ? RFToolsSupport.countItems(te, matcher, count) + : countItems(destination, matcher); int caninsert = count - amount; if (caninsert <= 0) { continue; @@ -325,7 +325,9 @@ public int insertStack(@Nonnull IControllerContext context, @Nonnull ItemStack s source.setCount(toinsert); } - remaining = ItemHandlerHelper.insertItem(destination, source, false); + remaining = isStorageScanner(te) + ? RFToolsSupport.insertItem(te, source, false) + : ItemHandlerHelper.insertItem(destination, source, false); int actuallyinserted = toinsert - remaining.getCount(); if (count == null) { @@ -354,68 +356,6 @@ public int insertStack(@Nonnull IControllerContext context, @Nonnull ItemStack s return total; } - - public int insertStackToStorageScanner(@Nonnull IControllerContext context, @Nonnull ItemStack source, @Nonnull Level world) { - if (channelMode == ChannelMode.PRIORITY) { - roundRobinOffset = 0; // Always start at 0 - } - int total = source.getCount(); - int consumersSize = itemConsumers.size(); - for (int j = 0; j < consumersSize; j++) { - int i = (j + roundRobinOffset) % consumersSize; - ConnectedInventory consumer = itemConsumers.get(i); - ItemConnectorSettings settings = consumer.settings(); - - BlockPos connectorPos = consumer.connectorPos(); - Direction side = consumer.sidedConsumer().side(); - BlockPos connectedBlockPos = connectorPos.relative(side); - if (!LevelTools.isLoaded(world, connectedBlockPos)) { - continue; - } - - BlockEntity te = world.getBlockEntity(connectedBlockPos); - ItemStack remaining; - - Predicate matcher = settings.getMatcher(context); - if (!matcher.test(source) || checkRedstone(world, settings, connectorPos) || !context.matchColor(settings.getColorsMask())) { - continue; - } - - int toinsert = total; - Integer count = settings.getCount(); - if (count != null) { - int amount = RFToolsSupport.countItems(te, matcher, count); - int caninsert = count - amount; - if (caninsert <= 0) { - continue; - } - toinsert = Math.min(toinsert, caninsert); - source = source.copy(); - source.setCount(toinsert); - } - - remaining = RFToolsSupport.insertItem(te, source, false); - - int actuallyinserted = toinsert - remaining.getCount(); - if (count == null) { - // If we are not using a count then we restore 'stack' here as that is what - // we actually have to keep inserting until it is empty. If we are using a count - // then we don't do this as we don't want to risk stack getting null (on 1.10.2) - // from the insertItem() and then not being able to set stacksize a few lines - // above this - source = remaining; - } - if (actuallyinserted > 0) { - roundRobinOffset = (roundRobinOffset + 1) % consumersSize; - total -= actuallyinserted; - if (total <= 0) { - return 0; - } - } - } - return total; - } - private boolean isFull(IItemHandler itemHandler) { for (int i = 0; i < itemHandler.getSlots(); i++) { ItemStack stackInSlot = itemHandler.getStackInSlot(i); @@ -520,7 +460,7 @@ private ConnectedInventory getConnectedInve return null; } IItemHandler connectedInventory = getItemHandlerAt(connectedEntity, con.getFacing()); - return new ConnectedInventory<>(entry.getKey(), con, connectorPos, connectedEntity, connectorEntity, connectedInventory); + return new ConnectedInventory<>(entry.getKey(), con, connectorPos, connectedBlockPos, connectedEntity, connectorEntity, connectedInventory); } @Override diff --git a/src/main/java/mcjty/xnet/apiimpl/logic/ConnectedEntity.java b/src/main/java/mcjty/xnet/apiimpl/logic/ConnectedEntity.java new file mode 100644 index 00000000..2d3085a9 --- /dev/null +++ b/src/main/java/mcjty/xnet/apiimpl/logic/ConnectedEntity.java @@ -0,0 +1,34 @@ +package mcjty.xnet.apiimpl.logic; + +import mcjty.rftoolsbase.api.xnet.keys.SidedConsumer; +import mcjty.xnet.apiimpl.ConnectedBlock; +import mcjty.xnet.modules.cables.blocks.ConnectorTileEntity; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.block.entity.BlockEntity; + +import javax.annotation.Nonnull; + +public class ConnectedEntity extends ConnectedBlock { + + @Nonnull private final BlockEntity connectedEntity; + + public ConnectedEntity(@Nonnull SidedConsumer sidedConsumer, @Nonnull T settings, @Nonnull BlockPos connectorPos, + @Nonnull BlockPos blockPos, @Nonnull BlockEntity connectedEntity, + @Nonnull ConnectorTileEntity connectorEntity) { + super(sidedConsumer, settings, connectorPos, blockPos, connectorEntity); + this.connectedEntity = connectedEntity; + } + + public ConnectedEntity(@Nonnull ConnectedBlock connectedBlock, @Nonnull BlockEntity connectedEntity) { + super( + connectedBlock.sidedConsumer(), connectedBlock.settings(), connectedBlock.connectorPos(), + connectedBlock.getBlockPos(), connectedBlock.getConnectorEntity() + ); + this.connectedEntity = connectedEntity; + } + + @Nonnull + public BlockEntity getConnectedEntity() { + return connectedEntity; + } +} diff --git a/src/main/java/mcjty/xnet/apiimpl/logic/LogicChannelSettings.java b/src/main/java/mcjty/xnet/apiimpl/logic/LogicChannelSettings.java index 6bcfc334..393ce18c 100644 --- a/src/main/java/mcjty/xnet/apiimpl/logic/LogicChannelSettings.java +++ b/src/main/java/mcjty/xnet/apiimpl/logic/LogicChannelSettings.java @@ -34,7 +34,7 @@ public class LogicChannelSettings extends DefaultChannelSettings implements ICha public static final ResourceLocation iconGuiElements = new ResourceLocation(XNet.MODID, "textures/gui/guielements.png"); private int colors = 0; // Colors for this channel - private List> sensors = null; + private List> sensors = null; private List> outputs = null; @Override @@ -68,10 +68,10 @@ public void tick(int channel, IControllerContext context) { Level world = context.getControllerWorld(); colors = 0; - for (ConnectedBlock connectedBlock : sensors) { + for (ConnectedEntity connectedBlock : sensors) { LogicConnectorSettings settings = connectedBlock.settings(); int sensorColors = 0; - BlockPos pos = connectedBlock.getConnectedEntity().getBlockPos(); + BlockPos pos = connectedBlock.getBlockPos(); if (!LevelTools.isLoaded(world, pos)) { // If it is not chunkloaded we just use the color settings as we last remembered it colors |= settings.getColorMask(); @@ -135,7 +135,11 @@ private void updateCache(int channel, IControllerContext context) { continue; } if (con.getLogicMode() == LogicMode.SENSOR) { - sensors.add(connectedBlock); + ConnectedEntity connectedEntity = getConnectedEntity(connectedBlock, world); + if (connectedEntity == null) { + continue; + } + sensors.add(connectedEntity); } else { outputs.add(connectedBlock); } @@ -156,6 +160,17 @@ private void updateCache(int channel, IControllerContext context) { } } + @Nullable + private ConnectedEntity getConnectedEntity( + @Nonnull ConnectedBlock connectedBlock, @Nonnull Level world + ) { + BlockEntity connectedEntity = world.getBlockEntity(connectedBlock.getBlockPos()); + if (connectedEntity == null) { + return null; + } + return new ConnectedEntity<>(connectedBlock, connectedEntity); + } + @Nullable private ConnectedBlock getConnectedBlockInfo( IControllerContext context, Map.Entry entry, @Nonnull Level world, @Nonnull LogicConnectorSettings con @@ -164,16 +179,16 @@ private ConnectedBlock getConnectedBlockInfo( if (connectorPos == null) { return null; } - BlockPos connectedBlockPos = connectorPos.relative(entry.getKey().side()); - BlockEntity connectedEntity = world.getBlockEntity(connectedBlockPos); - if (connectedEntity == null) { - return null; - } ConnectorTileEntity connectorEntity = (ConnectorTileEntity) world.getBlockEntity(connectorPos); if (connectorEntity == null) { return null; } - return new ConnectedBlock<>(entry.getKey(), con, connectorPos, connectedEntity, connectorEntity); + BlockPos connectedBlockPos = connectorPos.relative(entry.getKey().side()); + BlockEntity connectedEntity = world.getBlockEntity(connectedBlockPos); + if (connectedEntity == null) { + return new ConnectedBlock<>(entry.getKey(), con, connectorPos, connectedBlockPos, connectorEntity); + } + return new ConnectedEntity<>(entry.getKey(), con, connectorPos, connectedBlockPos, connectedEntity, connectorEntity); } @Override diff --git a/src/main/java/mcjty/xnet/compat/RFToolsSupport.java b/src/main/java/mcjty/xnet/compat/RFToolsSupport.java index ad5d399f..706ca51c 100644 --- a/src/main/java/mcjty/xnet/compat/RFToolsSupport.java +++ b/src/main/java/mcjty/xnet/compat/RFToolsSupport.java @@ -54,7 +54,7 @@ public static void tickStorageScanner(IControllerContext context, ItemConnectorS } if (context.checkAndConsumeRF(Config.controllerOperationRFT.get())) { - int remaining = channelSettings.insertStackToStorageScanner(context, stack, world); + int remaining = channelSettings.insertStack(context, stack, world, -1); if (remaining != toextract) { scanner.requestItem(extractMatcher, false, toextract - remaining, true); } diff --git a/src/main/resources/assets/xnet/lang/ru_ru.json b/src/main/resources/assets/xnet/lang/ru_ru.json index 18c1a7a9..36463f36 100644 --- a/src/main/resources/assets/xnet/lang/ru_ru.json +++ b/src/main/resources/assets/xnet/lang/ru_ru.json @@ -180,13 +180,13 @@ "xnet.enum.logic.logicmode.output.tooltip": "Π“Π΅Π½Π΅Ρ€ΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ Π²Ρ‹Ρ…ΠΎΠ΄Π½ΠΎΠΉ сигнал|для ΠΏΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π΅Π½Π½ΠΎΠ³ΠΎ Π±Π»ΠΎΠΊΠ°", "xnet.enum.logic.sensormode.off": "НСт", "xnet.enum.logic.sensormode.off.tooltip": "НС настроСн", - "xnet.enum.logic.sensormode.item": "ΠŸΡ€Π΅Π΄ΠΌΠ΅Ρ‚", + "xnet.enum.logic.sensormode.item": "ΠŸΡ€Π΅Π΄ΠΌ.", "xnet.enum.logic.sensormode.item.tooltip": "ΠžΡ‚ΡΠ»Π΅ΠΆΠΈΠ²Π°Ρ‚ΡŒ ΠΈΠ·ΠΌΠ΅Π½Π΅Π½ΠΈΠ΅ количСства|ΠΏΡ€Π΅Π΄ΠΌΠ΅Ρ‚ΠΎΠ² Π² ΠΏΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π΅Π½Π½ΠΎΠΌ Π±Π»ΠΎΠΊΠ΅|МоТно ΡƒΡΡ‚Π°Π½ΠΎΠ²ΠΈΡ‚ΡŒ Ρ„ΠΈΠ»ΡŒΡ‚Ρ€ ΠΏΡ€Π΅Π΄ΠΌΠ΅Ρ‚ΠΎΠ²", - "xnet.enum.logic.sensormode.fluid": "Π–ΠΈΠ΄ΠΊΠΎΡΡ‚ΡŒ", + "xnet.enum.logic.sensormode.fluid": "Π–ΠΈΠ΄ΠΊ.", "xnet.enum.logic.sensormode.fluid.tooltip": "ΠžΡ‚ΡΠ»Π΅ΠΆΠΈΠ²Π°Ρ‚ΡŒ ΠΈΠ·ΠΌΠ΅Π½Π΅Π½ΠΈΠ΅ количСства|Тидкости Π² ΠΏΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π΅Π½Π½ΠΎΠΌ Π±Π»ΠΎΠΊΠ΅ (mb)", - "xnet.enum.logic.sensormode.energy": "ЭнСргия", + "xnet.enum.logic.sensormode.energy": "Π­Π½Π΅Ρ€Π³.", "xnet.enum.logic.sensormode.energy.tooltip": "ΠžΡ‚ΡΠ»Π΅ΠΆΠΈΠ²Π°Ρ‚ΡŒ ΠΈΠ·ΠΌΠ΅Π½Π΅Π½ΠΈΠ΅ количСства|энСргии Π² ΠΏΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π΅Π½Π½ΠΎΠΌ Π±Π»ΠΎΠΊΠ΅", - "xnet.enum.logic.sensormode.rs": "РСдстоун", + "xnet.enum.logic.sensormode.rs": "РСдст.", "xnet.enum.logic.sensormode.rs.tooltip": "ΠžΡ‚ΡΠ»Π΅ΠΆΠΈΠ²Π°Ρ‚ΡŒ ΠΈΠ·ΠΌΠ΅Π½Π΅Π½ΠΈΠ΅ рСдстоун|сигнала Π² ΠΏΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π΅Π½Π½ΠΎΠΌ Π±Π»ΠΎΠΊΠ΅", "xnet.message.block.highlighted": "Π‘Π»ΠΎΠΊ Π²Ρ‹Π΄Π΅Π»Π΅Π½", "xnet.message.channel.copied": "Канал скопирован",