From ec2ad06561558fd026d558146635c7ddd8059366 Mon Sep 17 00:00:00 2001 From: raoulvdberge Date: Tue, 31 Oct 2023 20:32:15 +0100 Subject: [PATCH] refactor: class hierarchy of network node containers Introduced NetworkNodeContainerBlockEntityImpl, that inherits from the API block entity. It only has code for activeness checking. Modified AbstractInternalNetworkNodeContainerBlockEntity to have redstone mode, placed by and configuration card code. Modified cable and network receiver to inherit from NetworkNodeContainerBlockEntityImpl since they don't need redstone mode and especially not configuration card support. --- .../platform/api/grid/Grid.java | 2 +- .../common/AbstractModInitializer.java | 11 +- .../platform/common/block/CableBlock.java | 25 ++--- .../common/block/NetworkReceiverBlock.java | 9 +- ...actingNetworkNodeContainerBlockEntity.java | 2 +- ...neModeNetworkNodeContainerBlockEntity.java | 100 ++++++++++++++++++ .../block/entity/ControllerBlockEntity.java | 2 +- ... NetworkNodeContainerBlockEntityImpl.java} | 96 ++--------------- ...SimpleNetworkNodeContainerBlockEntity.java | 18 ---- .../entity/detector/DetectorBlockEntity.java | 4 +- .../AbstractDiskDriveBlockEntity.java | 4 +- .../ExternalStorageBlockEntity.java | 4 +- .../entity/grid/AbstractGridBlockEntity.java | 7 +- .../entity/iface/InterfaceBlockEntity.java | 4 +- .../AbstractStorageBlockBlockEntity.java | 4 +- .../StorageMonitorBlockEntity.java | 4 +- .../WirelessTransmitterBlockEntity.java | 5 +- .../ticker/NetworkNodeBlockEntityTicker.java | 4 +- .../grid/AbstractGridContainerMenu.java | 8 +- .../common/content/BlockEntities.java | 19 ++-- .../common/internal/grid/WirelessGrid.java | 2 +- .../common/menu/GridExtendedMenuProvider.java | 2 +- 22 files changed, 175 insertions(+), 161 deletions(-) create mode 100644 refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/AbstractRedstoneModeNetworkNodeContainerBlockEntity.java rename refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/{AbstractInternalNetworkNodeContainerBlockEntity.java => NetworkNodeContainerBlockEntityImpl.java} (59%) delete mode 100644 refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/SimpleNetworkNodeContainerBlockEntity.java diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/grid/Grid.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/grid/Grid.java index 3248a1016..17c6d34ac 100644 --- a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/grid/Grid.java +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/grid/Grid.java @@ -21,7 +21,7 @@ public interface Grid { Storage getItemStorage(); - boolean isActive(); + boolean isGridActive(); List> getResources(StorageChannelType type, Class actorType); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/AbstractModInitializer.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/AbstractModInitializer.java index 4479dfe6e..ae08e3872 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/AbstractModInitializer.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/AbstractModInitializer.java @@ -5,6 +5,7 @@ import com.refinedmods.refinedstorage2.api.network.impl.component.EnergyNetworkComponentImpl; import com.refinedmods.refinedstorage2.api.network.impl.component.GraphNetworkComponent; import com.refinedmods.refinedstorage2.api.network.impl.component.StorageNetworkComponentImpl; +import com.refinedmods.refinedstorage2.api.network.impl.node.SimpleNetworkNode; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; import com.refinedmods.refinedstorage2.platform.api.PlatformApiProxy; import com.refinedmods.refinedstorage2.platform.common.block.ControllerType; @@ -16,7 +17,7 @@ import com.refinedmods.refinedstorage2.platform.common.block.StorageMonitorBlock; import com.refinedmods.refinedstorage2.platform.common.block.entity.ControllerBlockEntity; import com.refinedmods.refinedstorage2.platform.common.block.entity.ImporterBlockEntity; -import com.refinedmods.refinedstorage2.platform.common.block.entity.SimpleNetworkNodeContainerBlockEntity; +import com.refinedmods.refinedstorage2.platform.common.block.entity.NetworkNodeContainerBlockEntityImpl; import com.refinedmods.refinedstorage2.platform.common.block.entity.constructor.ConstructorBlockEntity; import com.refinedmods.refinedstorage2.platform.common.block.entity.constructor.ItemDropConstructorStrategyFactory; import com.refinedmods.refinedstorage2.platform.common.block.entity.constructor.PlaceBlockConstructorStrategy; @@ -479,11 +480,11 @@ protected final void registerBlockEntities( ) { BlockEntities.INSTANCE.setCable(callback.register( CABLE, - () -> typeFactory.create((pos, state) -> new SimpleNetworkNodeContainerBlockEntity( + () -> typeFactory.create((pos, state) -> new NetworkNodeContainerBlockEntityImpl<>( BlockEntities.INSTANCE.getCable(), pos, state, - Platform.INSTANCE.getConfig().getCable().getEnergyUsage() + new SimpleNetworkNode(Platform.INSTANCE.getConfig().getCable().getEnergyUsage()) ), Blocks.INSTANCE.getCable().toArray()) )); BlockEntities.INSTANCE.setController(callback.register( @@ -573,11 +574,11 @@ protected final void registerBlockEntities( )); BlockEntities.INSTANCE.setNetworkReceiver(callback.register( NETWORK_RECEIVER, - () -> typeFactory.create((pos, state) -> new SimpleNetworkNodeContainerBlockEntity( + () -> typeFactory.create((pos, state) -> new NetworkNodeContainerBlockEntityImpl<>( BlockEntities.INSTANCE.getNetworkReceiver(), pos, state, - Platform.INSTANCE.getConfig().getNetworkReceiver().getEnergyUsage() + new SimpleNetworkNode(Platform.INSTANCE.getConfig().getNetworkReceiver().getEnergyUsage()) ), Blocks.INSTANCE.getNetworkReceiver().toArray()) )); } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/CableBlock.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/CableBlock.java index b74a74646..b8beaee66 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/CableBlock.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/CableBlock.java @@ -1,7 +1,8 @@ package com.refinedmods.refinedstorage2.platform.common.block; +import com.refinedmods.refinedstorage2.api.network.impl.node.SimpleNetworkNode; import com.refinedmods.refinedstorage2.platform.common.Platform; -import com.refinedmods.refinedstorage2.platform.common.block.entity.SimpleNetworkNodeContainerBlockEntity; +import com.refinedmods.refinedstorage2.platform.common.block.entity.NetworkNodeContainerBlockEntityImpl; import com.refinedmods.refinedstorage2.platform.common.block.ticker.AbstractBlockEntityTicker; import com.refinedmods.refinedstorage2.platform.common.block.ticker.NetworkNodeBlockEntityTicker; import com.refinedmods.refinedstorage2.platform.common.content.BlockColorMap; @@ -38,7 +39,7 @@ public class CableBlock extends AbstractBaseBlock implements ColorableBlock, SimpleWaterloggedBlock, EntityBlock, BlockItemProvider { - private static final AbstractBlockEntityTicker TICKER = + private static final AbstractBlockEntityTicker> TICKER = new NetworkNodeBlockEntityTicker<>(BlockEntities.INSTANCE::getCable); private final DyeColor color; @@ -116,22 +117,14 @@ public VoxelShape getShape(final BlockState state, @Override public BlockEntity newBlockEntity(final BlockPos pos, final BlockState state) { - return new SimpleNetworkNodeContainerBlockEntity( + return new NetworkNodeContainerBlockEntityImpl<>( BlockEntities.INSTANCE.getCable(), pos, state, - Platform.INSTANCE.getConfig().getCable().getEnergyUsage() + new SimpleNetworkNode(Platform.INSTANCE.getConfig().getCable().getEnergyUsage()) ); } - @Nullable - @Override - public BlockEntityTicker getTicker(final Level level, - final BlockState blockState, - final BlockEntityType type) { - return TICKER.get(level, type); - } - @Override public BlockColorMap getBlockColorMap() { return Blocks.INSTANCE.getCable(); @@ -146,4 +139,12 @@ public MutableComponent getName() { public BlockItem createBlockItem() { return new NamedBlockItem(this, new Item.Properties(), name); } + + @Nullable + @Override + public BlockEntityTicker getTicker(final Level level, + final BlockState blockState, + final BlockEntityType type) { + return TICKER.get(level, type); + } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/NetworkReceiverBlock.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/NetworkReceiverBlock.java index ffbc8faaf..32188673f 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/NetworkReceiverBlock.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/NetworkReceiverBlock.java @@ -1,7 +1,8 @@ package com.refinedmods.refinedstorage2.platform.common.block; +import com.refinedmods.refinedstorage2.api.network.impl.node.SimpleNetworkNode; import com.refinedmods.refinedstorage2.platform.common.Platform; -import com.refinedmods.refinedstorage2.platform.common.block.entity.SimpleNetworkNodeContainerBlockEntity; +import com.refinedmods.refinedstorage2.platform.common.block.entity.NetworkNodeContainerBlockEntityImpl; import com.refinedmods.refinedstorage2.platform.common.block.ticker.AbstractBlockEntityTicker; import com.refinedmods.refinedstorage2.platform.common.block.ticker.NetworkNodeBlockEntityTicker; import com.refinedmods.refinedstorage2.platform.common.content.BlockColorMap; @@ -30,7 +31,7 @@ public class NetworkReceiverBlock extends AbstractBaseBlock implements Colorable BlockItemProvider, EntityBlock { public static final BooleanProperty ACTIVE = BooleanProperty.create("active"); - private static final AbstractBlockEntityTicker TICKER = + private static final AbstractBlockEntityTicker> TICKER = new NetworkNodeBlockEntityTicker<>(BlockEntities.INSTANCE::getNetworkReceiver, ACTIVE); private final DyeColor color; @@ -76,11 +77,11 @@ public BlockItem createBlockItem() { @Nullable @Override public BlockEntity newBlockEntity(final BlockPos pos, final BlockState state) { - return new SimpleNetworkNodeContainerBlockEntity( + return new NetworkNodeContainerBlockEntityImpl<>( BlockEntities.INSTANCE.getNetworkReceiver(), pos, state, - Platform.INSTANCE.getConfig().getNetworkReceiver().getEnergyUsage() + new SimpleNetworkNode(Platform.INSTANCE.getConfig().getNetworkReceiver().getEnergyUsage()) ); } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/AbstractLevelInteractingNetworkNodeContainerBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/AbstractLevelInteractingNetworkNodeContainerBlockEntity.java index a0904f263..e0c9fa77b 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/AbstractLevelInteractingNetworkNodeContainerBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/AbstractLevelInteractingNetworkNodeContainerBlockEntity.java @@ -12,7 +12,7 @@ import org.slf4j.LoggerFactory; public abstract class AbstractLevelInteractingNetworkNodeContainerBlockEntity - extends AbstractInternalNetworkNodeContainerBlockEntity { + extends AbstractRedstoneModeNetworkNodeContainerBlockEntity { private static final Logger LOGGER = LoggerFactory.getLogger( AbstractLevelInteractingNetworkNodeContainerBlockEntity.class ); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/AbstractRedstoneModeNetworkNodeContainerBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/AbstractRedstoneModeNetworkNodeContainerBlockEntity.java new file mode 100644 index 000000000..b35d96dac --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/AbstractRedstoneModeNetworkNodeContainerBlockEntity.java @@ -0,0 +1,100 @@ +package com.refinedmods.refinedstorage2.platform.common.block.entity; + +import com.refinedmods.refinedstorage2.api.network.node.AbstractNetworkNode; +import com.refinedmods.refinedstorage2.platform.api.blockentity.ConfigurationCardTarget; +import com.refinedmods.refinedstorage2.platform.common.Platform; +import com.refinedmods.refinedstorage2.platform.common.util.RedstoneMode; + +import java.util.Collections; +import java.util.List; +import java.util.UUID; +import javax.annotation.Nullable; + +import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.Item; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.level.block.state.BlockState; + +public abstract class AbstractRedstoneModeNetworkNodeContainerBlockEntity + extends NetworkNodeContainerBlockEntityImpl implements PlayerAware, ConfigurationCardTarget { + private static final String TAG_REDSTONE_MODE = "rm"; + private static final String TAG_PLACED_BY_PLAYER_ID = "pbpid"; + + private RedstoneMode redstoneMode = RedstoneMode.IGNORE; + @Nullable + private UUID placedByPlayerId; + + protected AbstractRedstoneModeNetworkNodeContainerBlockEntity(final BlockEntityType type, + final BlockPos pos, + final BlockState state, + final T node) { + super(type, pos, state, node); + } + + @Override + protected boolean isActive() { + return super.isActive() && level != null && redstoneMode.isActive(level.hasNeighborSignal(worldPosition)); + } + + @Override + public void saveAdditional(final CompoundTag tag) { + super.saveAdditional(tag); + writeConfiguration(tag); + if (placedByPlayerId != null) { + tag.putUUID(TAG_PLACED_BY_PLAYER_ID, placedByPlayerId); + } + } + + @Override + public void writeConfiguration(final CompoundTag tag) { + tag.putInt(TAG_REDSTONE_MODE, RedstoneModeSettings.getRedstoneMode(getRedstoneMode())); + } + + @Override + public void load(final CompoundTag tag) { + super.load(tag); + readConfiguration(tag); + if (tag.hasUUID(TAG_PLACED_BY_PLAYER_ID)) { + placedByPlayerId = tag.getUUID(TAG_PLACED_BY_PLAYER_ID); + } + } + + @Override + public void readConfiguration(final CompoundTag tag) { + if (tag.contains(TAG_REDSTONE_MODE)) { + redstoneMode = RedstoneModeSettings.getRedstoneMode(tag.getInt(TAG_REDSTONE_MODE)); + } + } + + @Override + public List getUpgradeItems() { + return Collections.emptyList(); + } + + @Override + public boolean addUpgradeItem(final Item upgradeItem) { + return false; + } + + public RedstoneMode getRedstoneMode() { + return redstoneMode; + } + + public void setRedstoneMode(final RedstoneMode redstoneMode) { + this.redstoneMode = redstoneMode; + setChanged(); + } + + @Override + public void setPlacedBy(final UUID playerId) { + this.placedByPlayerId = playerId; + setChanged(); + } + + protected final Player getFakePlayer(final ServerLevel serverLevel) { + return Platform.INSTANCE.getFakePlayer(serverLevel, placedByPlayerId); + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/ControllerBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/ControllerBlockEntity.java index f45ad0545..86287650b 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/ControllerBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/ControllerBlockEntity.java @@ -29,7 +29,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class ControllerBlockEntity extends AbstractInternalNetworkNodeContainerBlockEntity +public class ControllerBlockEntity extends AbstractRedstoneModeNetworkNodeContainerBlockEntity implements ExtendedMenuProvider, EnergyBlockEntity { private static final Logger LOGGER = LoggerFactory.getLogger(ControllerBlockEntity.class); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/AbstractInternalNetworkNodeContainerBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/NetworkNodeContainerBlockEntityImpl.java similarity index 59% rename from refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/AbstractInternalNetworkNodeContainerBlockEntity.java rename to refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/NetworkNodeContainerBlockEntityImpl.java index 1785ad4e3..4e03b0369 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/AbstractInternalNetworkNodeContainerBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/NetworkNodeContainerBlockEntityImpl.java @@ -3,101 +3,42 @@ import com.refinedmods.refinedstorage2.api.network.component.EnergyNetworkComponent; import com.refinedmods.refinedstorage2.api.network.node.AbstractNetworkNode; import com.refinedmods.refinedstorage2.platform.api.blockentity.AbstractNetworkNodeContainerBlockEntity; -import com.refinedmods.refinedstorage2.platform.api.blockentity.ConfigurationCardTarget; -import com.refinedmods.refinedstorage2.platform.common.Platform; import com.refinedmods.refinedstorage2.platform.common.block.AbstractDirectionalBlock; import com.refinedmods.refinedstorage2.platform.common.block.ColorableBlock; -import com.refinedmods.refinedstorage2.platform.common.util.RedstoneMode; -import java.util.Collections; -import java.util.List; -import java.util.UUID; import javax.annotation.Nullable; import com.google.common.util.concurrent.RateLimiter; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.Item; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.properties.BooleanProperty; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -// TODO: inherit from simple network node container block entity -public abstract class AbstractInternalNetworkNodeContainerBlockEntity - extends AbstractNetworkNodeContainerBlockEntity - implements PlayerAware, ConfigurationCardTarget { - private static final Logger LOGGER = LoggerFactory.getLogger(AbstractInternalNetworkNodeContainerBlockEntity.class); - - private static final String TAG_REDSTONE_MODE = "rm"; - private static final String TAG_PLACED_BY_PLAYER_ID = "pbpid"; +public class NetworkNodeContainerBlockEntityImpl + extends AbstractNetworkNodeContainerBlockEntity { + private static final Logger LOGGER = LoggerFactory.getLogger(NetworkNodeContainerBlockEntityImpl.class); private final RateLimiter activenessChangeRateLimiter = RateLimiter.create(1); private boolean lastActive; - private RedstoneMode redstoneMode = RedstoneMode.IGNORE; - @Nullable - private UUID placedByPlayerId; - protected AbstractInternalNetworkNodeContainerBlockEntity(final BlockEntityType type, - final BlockPos pos, - final BlockState state, - final T node) { - super(type, pos, state, node); + public NetworkNodeContainerBlockEntityImpl(final BlockEntityType type, + final BlockPos pos, + final BlockState state, + final T networkNode) { + super(type, pos, state, networkNode); } - private boolean isActive() { + protected boolean isActive() { final long energyUsage = getNode().getEnergyUsage(); final boolean hasLevel = level != null && level.isLoaded(worldPosition); return hasLevel - && redstoneMode.isActive(level.hasNeighborSignal(worldPosition)) && getNode().getNetwork() != null && getNode().getNetwork().getComponent(EnergyNetworkComponent.class).getStored() >= energyUsage; } - @Override - public void saveAdditional(final CompoundTag tag) { - super.saveAdditional(tag); - writeConfiguration(tag); - if (placedByPlayerId != null) { - tag.putUUID(TAG_PLACED_BY_PLAYER_ID, placedByPlayerId); - } - } - - @Override - public void writeConfiguration(final CompoundTag tag) { - tag.putInt(TAG_REDSTONE_MODE, RedstoneModeSettings.getRedstoneMode(getRedstoneMode())); - } - - @Override - public void load(final CompoundTag tag) { - super.load(tag); - readConfiguration(tag); - if (tag.hasUUID(TAG_PLACED_BY_PLAYER_ID)) { - placedByPlayerId = tag.getUUID(TAG_PLACED_BY_PLAYER_ID); - } - } - - @Override - public void readConfiguration(final CompoundTag tag) { - if (tag.contains(TAG_REDSTONE_MODE)) { - redstoneMode = RedstoneModeSettings.getRedstoneMode(tag.getInt(TAG_REDSTONE_MODE)); - } - } - - @Override - public List getUpgradeItems() { - return Collections.emptyList(); - } - - @Override - public boolean addUpgradeItem(final Item upgradeItem) { - return false; - } - public void updateActiveness(final BlockState state, @Nullable final BooleanProperty activenessProperty) { final boolean newActive = isActive(); @@ -130,15 +71,6 @@ private void updateActivenessState(final BlockState state, } } - public RedstoneMode getRedstoneMode() { - return redstoneMode; - } - - public void setRedstoneMode(final RedstoneMode redstoneMode) { - this.redstoneMode = redstoneMode; - setChanged(); - } - public void doWork() { getNode().doWork(); } @@ -193,14 +125,4 @@ protected final Direction getDirection() { } return directionalBlock.extractDirection(blockState); } - - @Override - public void setPlacedBy(final UUID playerId) { - this.placedByPlayerId = playerId; - setChanged(); - } - - protected final Player getFakePlayer(final ServerLevel serverLevel) { - return Platform.INSTANCE.getFakePlayer(serverLevel, placedByPlayerId); - } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/SimpleNetworkNodeContainerBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/SimpleNetworkNodeContainerBlockEntity.java deleted file mode 100644 index c90e7ad4b..000000000 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/SimpleNetworkNodeContainerBlockEntity.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.refinedmods.refinedstorage2.platform.common.block.entity; - -import com.refinedmods.refinedstorage2.api.network.impl.node.SimpleNetworkNode; - -import net.minecraft.core.BlockPos; -import net.minecraft.world.level.block.entity.BlockEntityType; -import net.minecraft.world.level.block.state.BlockState; - -// TODO: fix inheritance (no need for RedstoneMode here!) -public final class SimpleNetworkNodeContainerBlockEntity - extends AbstractInternalNetworkNodeContainerBlockEntity { - public SimpleNetworkNodeContainerBlockEntity(final BlockEntityType type, - final BlockPos pos, - final BlockState state, - final long energyUsage) { - super(type, pos, state, new SimpleNetworkNode(energyUsage)); - } -} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/detector/DetectorBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/detector/DetectorBlockEntity.java index 4391e381e..d3ba29d42 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/detector/DetectorBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/detector/DetectorBlockEntity.java @@ -8,7 +8,7 @@ import com.refinedmods.refinedstorage2.platform.api.resource.ResourceContainer; import com.refinedmods.refinedstorage2.platform.common.Platform; import com.refinedmods.refinedstorage2.platform.common.block.DetectorBlock; -import com.refinedmods.refinedstorage2.platform.common.block.entity.AbstractInternalNetworkNodeContainerBlockEntity; +import com.refinedmods.refinedstorage2.platform.common.block.entity.AbstractRedstoneModeNetworkNodeContainerBlockEntity; import com.refinedmods.refinedstorage2.platform.common.block.entity.FilterWithFuzzyMode; import com.refinedmods.refinedstorage2.platform.common.containermenu.AbstractSingleAmountContainerMenu; import com.refinedmods.refinedstorage2.platform.common.containermenu.detector.DetectorContainerMenu; @@ -34,7 +34,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class DetectorBlockEntity extends AbstractInternalNetworkNodeContainerBlockEntity +public class DetectorBlockEntity extends AbstractRedstoneModeNetworkNodeContainerBlockEntity implements ExtendedMenuProvider { private static final Logger LOGGER = LoggerFactory.getLogger(DetectorBlockEntity.class); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/diskdrive/AbstractDiskDriveBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/diskdrive/AbstractDiskDriveBlockEntity.java index 625bcd74d..cbf9409ed 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/diskdrive/AbstractDiskDriveBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/diskdrive/AbstractDiskDriveBlockEntity.java @@ -6,7 +6,7 @@ import com.refinedmods.refinedstorage2.api.network.impl.node.multistorage.MultiStorageStorageState; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; import com.refinedmods.refinedstorage2.platform.common.Platform; -import com.refinedmods.refinedstorage2.platform.common.block.entity.AbstractInternalNetworkNodeContainerBlockEntity; +import com.refinedmods.refinedstorage2.platform.common.block.entity.AbstractRedstoneModeNetworkNodeContainerBlockEntity; import com.refinedmods.refinedstorage2.platform.common.block.entity.BlockEntityWithDrops; import com.refinedmods.refinedstorage2.platform.common.block.entity.FilterWithFuzzyMode; import com.refinedmods.refinedstorage2.platform.common.block.entity.StorageConfigurationContainerImpl; @@ -47,7 +47,7 @@ import org.slf4j.LoggerFactory; public abstract class AbstractDiskDriveBlockEntity - extends AbstractInternalNetworkNodeContainerBlockEntity + extends AbstractRedstoneModeNetworkNodeContainerBlockEntity implements BlockEntityWithDrops, MultiStorageListener, ExtendedMenuProvider { public static final int AMOUNT_OF_DISKS = 8; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/externalstorage/ExternalStorageBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/externalstorage/ExternalStorageBlockEntity.java index d16595b60..37b7b9711 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/externalstorage/ExternalStorageBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/externalstorage/ExternalStorageBlockEntity.java @@ -6,7 +6,7 @@ import com.refinedmods.refinedstorage2.api.storage.external.ExternalStorageProvider; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; import com.refinedmods.refinedstorage2.platform.common.Platform; -import com.refinedmods.refinedstorage2.platform.common.block.entity.AbstractInternalNetworkNodeContainerBlockEntity; +import com.refinedmods.refinedstorage2.platform.common.block.entity.AbstractRedstoneModeNetworkNodeContainerBlockEntity; import com.refinedmods.refinedstorage2.platform.common.block.entity.FilterWithFuzzyMode; import com.refinedmods.refinedstorage2.platform.common.block.entity.StorageConfigurationContainerImpl; import com.refinedmods.refinedstorage2.platform.common.containermenu.storage.ExternalStorageContainerMenu; @@ -35,7 +35,7 @@ import org.slf4j.LoggerFactory; public class ExternalStorageBlockEntity - extends AbstractInternalNetworkNodeContainerBlockEntity + extends AbstractRedstoneModeNetworkNodeContainerBlockEntity implements ExtendedMenuProvider { private static final Logger LOGGER = LoggerFactory.getLogger(ExternalStorageBlockEntity.class); private static final String TAG_TRACKED_RESOURCES = "tr"; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/grid/AbstractGridBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/grid/AbstractGridBlockEntity.java index 0c252a86d..b56d17283 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/grid/AbstractGridBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/grid/AbstractGridBlockEntity.java @@ -14,7 +14,7 @@ import com.refinedmods.refinedstorage2.platform.api.grid.Grid; import com.refinedmods.refinedstorage2.platform.api.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; -import com.refinedmods.refinedstorage2.platform.common.block.entity.AbstractInternalNetworkNodeContainerBlockEntity; +import com.refinedmods.refinedstorage2.platform.common.block.entity.AbstractRedstoneModeNetworkNodeContainerBlockEntity; import com.refinedmods.refinedstorage2.platform.common.internal.storage.channel.StorageChannelTypes; import java.util.List; @@ -25,7 +25,8 @@ import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; -public abstract class AbstractGridBlockEntity extends AbstractInternalNetworkNodeContainerBlockEntity +public abstract class AbstractGridBlockEntity + extends AbstractRedstoneModeNetworkNodeContainerBlockEntity implements Grid, MenuProvider { protected AbstractGridBlockEntity(final BlockEntityType type, final BlockPos pos, @@ -55,7 +56,7 @@ public GridOperations createOperations(final PlatformStorageChannelType + extends AbstractRedstoneModeNetworkNodeContainerBlockEntity implements ExtendedMenuProvider, BlockEntityWithDrops { private static final String TAG_EXPORT_ITEMS = "ei"; private static final int EXPORT_SLOTS = 9; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storage/AbstractStorageBlockBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storage/AbstractStorageBlockBlockEntity.java index df47b9537..aaa2d791a 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storage/AbstractStorageBlockBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storage/AbstractStorageBlockBlockEntity.java @@ -6,7 +6,7 @@ import com.refinedmods.refinedstorage2.platform.api.resource.ResourceContainer; import com.refinedmods.refinedstorage2.platform.api.resource.ResourceFactory; import com.refinedmods.refinedstorage2.platform.api.storage.StorageRepository; -import com.refinedmods.refinedstorage2.platform.common.block.entity.AbstractInternalNetworkNodeContainerBlockEntity; +import com.refinedmods.refinedstorage2.platform.common.block.entity.AbstractRedstoneModeNetworkNodeContainerBlockEntity; import com.refinedmods.refinedstorage2.platform.common.block.entity.FilterWithFuzzyMode; import com.refinedmods.refinedstorage2.platform.common.block.entity.StorageConfigurationContainerImpl; import com.refinedmods.refinedstorage2.platform.common.internal.resource.ResourceContainerImpl; @@ -27,7 +27,7 @@ import org.slf4j.LoggerFactory; public abstract class AbstractStorageBlockBlockEntity - extends AbstractInternalNetworkNodeContainerBlockEntity> + extends AbstractRedstoneModeNetworkNodeContainerBlockEntity> implements ExtendedMenuProvider { private static final Logger LOGGER = LoggerFactory.getLogger(AbstractStorageBlockBlockEntity.class); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storagemonitor/StorageMonitorBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storagemonitor/StorageMonitorBlockEntity.java index caee98062..19b42690d 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storagemonitor/StorageMonitorBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storagemonitor/StorageMonitorBlockEntity.java @@ -12,7 +12,7 @@ import com.refinedmods.refinedstorage2.platform.api.storage.PlayerActor; import com.refinedmods.refinedstorage2.platform.api.storage.channel.FuzzyStorageChannel; import com.refinedmods.refinedstorage2.platform.common.Platform; -import com.refinedmods.refinedstorage2.platform.common.block.entity.AbstractInternalNetworkNodeContainerBlockEntity; +import com.refinedmods.refinedstorage2.platform.common.block.entity.AbstractRedstoneModeNetworkNodeContainerBlockEntity; import com.refinedmods.refinedstorage2.platform.common.block.entity.FilterWithFuzzyMode; import com.refinedmods.refinedstorage2.platform.common.containermenu.StorageMonitorContainerMenu; import com.refinedmods.refinedstorage2.platform.common.content.BlockEntities; @@ -42,7 +42,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class StorageMonitorBlockEntity extends AbstractInternalNetworkNodeContainerBlockEntity +public class StorageMonitorBlockEntity extends AbstractRedstoneModeNetworkNodeContainerBlockEntity implements ExtendedMenuProvider { private static final Logger LOGGER = LoggerFactory.getLogger(StorageMonitorBlockEntity.class); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/wirelesstransmitter/WirelessTransmitterBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/wirelesstransmitter/WirelessTransmitterBlockEntity.java index a45aede31..6b2e78e1d 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/wirelesstransmitter/WirelessTransmitterBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/wirelesstransmitter/WirelessTransmitterBlockEntity.java @@ -4,7 +4,7 @@ import com.refinedmods.refinedstorage2.platform.api.PlatformApi; import com.refinedmods.refinedstorage2.platform.api.blockentity.wirelesstransmitter.WirelessTransmitter; import com.refinedmods.refinedstorage2.platform.common.Platform; -import com.refinedmods.refinedstorage2.platform.common.block.entity.AbstractInternalNetworkNodeContainerBlockEntity; +import com.refinedmods.refinedstorage2.platform.common.block.entity.AbstractRedstoneModeNetworkNodeContainerBlockEntity; import com.refinedmods.refinedstorage2.platform.common.block.entity.UpgradeContainer; import com.refinedmods.refinedstorage2.platform.common.containermenu.WirelessTransmitterContainerMenu; import com.refinedmods.refinedstorage2.platform.common.content.BlockEntities; @@ -29,7 +29,8 @@ import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.Vec3; -public class WirelessTransmitterBlockEntity extends AbstractInternalNetworkNodeContainerBlockEntity +public class WirelessTransmitterBlockEntity + extends AbstractRedstoneModeNetworkNodeContainerBlockEntity implements ExtendedMenuProvider, WirelessTransmitter { private static final String TAG_UPGRADES = "u"; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/ticker/NetworkNodeBlockEntityTicker.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/ticker/NetworkNodeBlockEntityTicker.java index f2e9a10fa..6fce3d6c7 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/ticker/NetworkNodeBlockEntityTicker.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/ticker/NetworkNodeBlockEntityTicker.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.platform.common.block.ticker; import com.refinedmods.refinedstorage2.api.network.node.AbstractNetworkNode; -import com.refinedmods.refinedstorage2.platform.common.block.entity.AbstractInternalNetworkNodeContainerBlockEntity; +import com.refinedmods.refinedstorage2.platform.common.block.entity.NetworkNodeContainerBlockEntityImpl; import java.util.function.Supplier; import javax.annotation.Nullable; @@ -14,7 +14,7 @@ public class NetworkNodeBlockEntityTicker< N extends AbstractNetworkNode, - T extends AbstractInternalNetworkNodeContainerBlockEntity + T extends NetworkNodeContainerBlockEntityImpl > extends AbstractBlockEntityTicker { @Nullable private final BooleanProperty activenessProperty; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/grid/AbstractGridContainerMenu.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/grid/AbstractGridContainerMenu.java index 71f13a5c4..c77697a1e 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/grid/AbstractGridContainerMenu.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/grid/AbstractGridContainerMenu.java @@ -389,7 +389,7 @@ public void toggleStorageChannelType() { @Override public boolean onInsert(final GridInsertMode insertMode, final boolean tryAlternatives) { - if (grid != null && !grid.isActive()) { + if (grid != null && !grid.isGridActive()) { return false; } return insertionStrategy.onInsert(insertMode, tryAlternatives); @@ -400,7 +400,7 @@ public boolean onExtract(final PlatformStorageChannelType storageChannelT final T resource, final GridExtractMode extractMode, final boolean cursor) { - if (grid != null && !grid.isActive()) { + if (grid != null && !grid.isGridActive()) { return false; } return extractionStrategy.onExtract(storageChannelType, resource, extractMode, cursor); @@ -411,7 +411,7 @@ public boolean onScroll(final PlatformStorageChannelType storageChannelTy final T resource, final GridScrollMode scrollMode, final int slotIndex) { - if (grid != null && !grid.isActive()) { + if (grid != null && !grid.isGridActive()) { return false; } return scrollingStrategy.onScroll(storageChannelType, resource, scrollMode, slotIndex); @@ -424,7 +424,7 @@ public boolean onTransfer(final int slotIndex) { @Override public ItemStack quickMoveStack(final Player playerEntity, final int slotIndex) { - if (!playerEntity.level().isClientSide() && grid != null && grid.isActive()) { + if (!playerEntity.level().isClientSide() && grid != null && grid.isGridActive()) { final Slot slot = getSlot(slotIndex); if (slot.hasItem()) { insertionStrategy.onTransfer(slot.index); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/BlockEntities.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/BlockEntities.java index 65e74664d..f200fb29b 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/BlockEntities.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/BlockEntities.java @@ -1,8 +1,9 @@ package com.refinedmods.refinedstorage2.platform.common.content; +import com.refinedmods.refinedstorage2.api.network.impl.node.SimpleNetworkNode; import com.refinedmods.refinedstorage2.platform.common.block.entity.ControllerBlockEntity; import com.refinedmods.refinedstorage2.platform.common.block.entity.ImporterBlockEntity; -import com.refinedmods.refinedstorage2.platform.common.block.entity.SimpleNetworkNodeContainerBlockEntity; +import com.refinedmods.refinedstorage2.platform.common.block.entity.NetworkNodeContainerBlockEntityImpl; import com.refinedmods.refinedstorage2.platform.common.block.entity.constructor.ConstructorBlockEntity; import com.refinedmods.refinedstorage2.platform.common.block.entity.destructor.DestructorBlockEntity; import com.refinedmods.refinedstorage2.platform.common.block.entity.detector.DetectorBlockEntity; @@ -31,7 +32,7 @@ public final class BlockEntities { public static final BlockEntities INSTANCE = new BlockEntities(); @Nullable - private Supplier> cable; + private Supplier>> cable; @Nullable private Supplier> diskDrive; @Nullable @@ -65,16 +66,18 @@ public final class BlockEntities { @Nullable private Supplier> storageMonitor; @Nullable - private Supplier> networkReceiver; + private Supplier>> networkReceiver; private BlockEntities() { } - public BlockEntityType getCable() { + public BlockEntityType> getCable() { return Objects.requireNonNull(cable).get(); } - public void setCable(final Supplier> supplier) { + public void setCable( + final Supplier>> supplier + ) { this.cable = supplier; } @@ -208,11 +211,13 @@ public void setStorageMonitor(final Supplier getNetworkReceiver() { + public BlockEntityType> getNetworkReceiver() { return Objects.requireNonNull(networkReceiver).get(); } - public void setNetworkReceiver(final Supplier> supplier) { + public void setNetworkReceiver( + final Supplier>> supplier + ) { this.networkReceiver = supplier; } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/grid/WirelessGrid.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/grid/WirelessGrid.java index c624df9ba..0090b8c2e 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/grid/WirelessGrid.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/grid/WirelessGrid.java @@ -57,7 +57,7 @@ public Storage getItemStorage() { } @Override - public boolean isActive() { + public boolean isGridActive() { final boolean networkActive = session.resolveNetwork().map( network -> network.getComponent(EnergyNetworkComponent.class).getStored() > 0 ).orElse(false); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/menu/GridExtendedMenuProvider.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/menu/GridExtendedMenuProvider.java index 364ec831b..a8e97e1b1 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/menu/GridExtendedMenuProvider.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/menu/GridExtendedMenuProvider.java @@ -34,7 +34,7 @@ public GridExtendedMenuProvider(final Grid grid, @Override public void writeScreenOpeningData(final ServerPlayer player, final FriendlyByteBuf buf) { - buf.writeBoolean(grid.isActive()); + buf.writeBoolean(grid.isGridActive()); final List> types = storageChannelTypeRegistry.getAll(); buf.writeInt(types.size()); types.forEach(type -> writeStorageChannel(type, buf));