From 456a3cfa6b7cefb33a8d3c5c50980797edadeb76 Mon Sep 17 00:00:00 2001 From: raoulvdberge <raoulvdberge@gmail.com> 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. --- CHANGELOG.md | 6 +- .../platform/api/grid/Grid.java | 2 +- .../common/AbstractModInitializer.java | 11 +- .../common/block/AbstractColoredBlock.java | 36 +++++++ .../platform/common/block/CableBlock.java | 46 +++----- .../common/block/NetworkReceiverBlock.java | 37 ++----- ...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 +- 24 files changed, 215 insertions(+), 212 deletions(-) create mode 100644 refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/AbstractColoredBlock.java 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/CHANGELOG.md b/CHANGELOG.md index b6761925f..e41581516 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -337,9 +337,9 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ### Added - The Wrench now dismantles devices when crouching. - - The Disk Drive in item form now supports rendering of disks that were dismantled. - - In order to retain Controller energy, the Controller must now be dismantled. - - All config and upgrades are transferred to the item. + - The Disk Drive in item form now supports rendering of disks that were dismantled. + - In order to retain Controller energy, the Controller must now be dismantled. + - All config and upgrades are transferred to the item. - You can now use any Wrench from other mods in order to rotate or dismantle. - Item and fluid storage blocks. - Initial advancements. 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<ItemResource> getItemStorage(); - boolean isActive(); + boolean isGridActive(); <T> List<TrackedResourceAmount<T>> getResources(StorageChannelType<T> type, Class<? extends Actor> 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/AbstractColoredBlock.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/AbstractColoredBlock.java new file mode 100644 index 000000000..a674ae71f --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/AbstractColoredBlock.java @@ -0,0 +1,36 @@ +package com.refinedmods.refinedstorage2.platform.common.block; + +import com.refinedmods.refinedstorage2.platform.common.item.block.NamedBlockItem; + +import net.minecraft.network.chat.MutableComponent; +import net.minecraft.world.item.BlockItem; +import net.minecraft.world.item.DyeColor; +import net.minecraft.world.item.Item; +import net.minecraft.world.level.block.Block; + +public abstract class AbstractColoredBlock<T extends Block & BlockItemProvider> + extends AbstractBaseBlock implements ColorableBlock<T>, BlockItemProvider { + private final DyeColor color; + private final MutableComponent name; + + protected AbstractColoredBlock(final Properties properties, final DyeColor color, final MutableComponent name) { + super(properties); + this.color = color; + this.name = name; + } + + @Override + public MutableComponent getName() { + return name; + } + + @Override + public DyeColor getColor() { + return color; + } + + @Override + public BlockItem createBlockItem() { + return new NamedBlockItem(this, new Item.Properties(), name); + } +} 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..b74a819aa 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,22 +1,20 @@ 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; import com.refinedmods.refinedstorage2.platform.common.content.BlockEntities; import com.refinedmods.refinedstorage2.platform.common.content.Blocks; -import com.refinedmods.refinedstorage2.platform.common.item.block.NamedBlockItem; import javax.annotation.Nullable; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.network.chat.MutableComponent; -import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.DyeColor; -import net.minecraft.world.item.Item; import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; @@ -36,23 +34,13 @@ import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.VoxelShape; -public class CableBlock extends AbstractBaseBlock +public class CableBlock extends AbstractColoredBlock<CableBlock> implements ColorableBlock<CableBlock>, SimpleWaterloggedBlock, EntityBlock, BlockItemProvider { - private static final AbstractBlockEntityTicker<SimpleNetworkNodeContainerBlockEntity> TICKER = + private static final AbstractBlockEntityTicker<NetworkNodeContainerBlockEntityImpl<SimpleNetworkNode>> TICKER = new NetworkNodeBlockEntityTicker<>(BlockEntities.INSTANCE::getCable); - private final DyeColor color; - private final MutableComponent name; - public CableBlock(final DyeColor color, final MutableComponent name) { - super(BlockConstants.CABLE_PROPERTIES); - this.color = color; - this.name = name; - } - - @Override - public DyeColor getColor() { - return color; + super(BlockConstants.CABLE_PROPERTIES, color, name); } @Override @@ -116,34 +104,24 @@ 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 <T extends BlockEntity> BlockEntityTicker<T> getTicker(final Level level, - final BlockState blockState, - final BlockEntityType<T> type) { - return TICKER.get(level, type); - } - @Override public BlockColorMap<CableBlock> getBlockColorMap() { return Blocks.INSTANCE.getCable(); } + @Nullable @Override - public MutableComponent getName() { - return name; - } - - @Override - public BlockItem createBlockItem() { - return new NamedBlockItem(this, new Item.Properties(), name); + public <T extends BlockEntity> BlockEntityTicker<T> getTicker(final Level level, + final BlockState blockState, + final BlockEntityType<T> 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..90ced803f 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,21 +1,19 @@ 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; import com.refinedmods.refinedstorage2.platform.common.content.BlockEntities; import com.refinedmods.refinedstorage2.platform.common.content.Blocks; -import com.refinedmods.refinedstorage2.platform.common.item.block.NamedBlockItem; import javax.annotation.Nullable; import net.minecraft.core.BlockPos; import net.minecraft.network.chat.MutableComponent; -import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.DyeColor; -import net.minecraft.world.item.Item; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.EntityBlock; @@ -26,20 +24,14 @@ import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.properties.BooleanProperty; -public class NetworkReceiverBlock extends AbstractBaseBlock implements ColorableBlock<NetworkReceiverBlock>, - BlockItemProvider, EntityBlock { +public class NetworkReceiverBlock extends AbstractColoredBlock<NetworkReceiverBlock> implements EntityBlock { public static final BooleanProperty ACTIVE = BooleanProperty.create("active"); - private static final AbstractBlockEntityTicker<SimpleNetworkNodeContainerBlockEntity> TICKER = + private static final AbstractBlockEntityTicker<NetworkNodeContainerBlockEntityImpl<SimpleNetworkNode>> TICKER = new NetworkNodeBlockEntityTicker<>(BlockEntities.INSTANCE::getNetworkReceiver, ACTIVE); - private final DyeColor color; - private final MutableComponent name; - public NetworkReceiverBlock(final DyeColor color, final MutableComponent name) { - super(BlockConstants.PROPERTIES); - this.color = color; - this.name = name; + super(BlockConstants.PROPERTIES, color, name); } @Override @@ -53,34 +45,19 @@ protected void createBlockStateDefinition(final StateDefinition.Builder<Block, B builder.add(ACTIVE); } - @Override - public MutableComponent getName() { - return name; - } - @Override public BlockColorMap<NetworkReceiverBlock> getBlockColorMap() { return Blocks.INSTANCE.getNetworkReceiver(); } - @Override - public DyeColor getColor() { - return color; - } - - @Override - public BlockItem createBlockItem() { - return new NamedBlockItem(this, new Item.Properties(), name); - } - @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<T extends AbstractNetworkNode> - extends AbstractInternalNetworkNodeContainerBlockEntity<T> { + extends AbstractRedstoneModeNetworkNodeContainerBlockEntity<T> { 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<T extends AbstractNetworkNode> + extends NetworkNodeContainerBlockEntityImpl<T> 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<Item> 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<ControllerNetworkNode> +public class ControllerBlockEntity extends AbstractRedstoneModeNetworkNodeContainerBlockEntity<ControllerNetworkNode> 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<T extends AbstractNetworkNode> - extends AbstractNetworkNodeContainerBlockEntity<T> - 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<T extends AbstractNetworkNode> + extends AbstractNetworkNodeContainerBlockEntity<T> { + 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<Item> 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<SimpleNetworkNode> { - public SimpleNetworkNodeContainerBlockEntity(final BlockEntityType<SimpleNetworkNodeContainerBlockEntity> 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<DetectorNetworkNode> +public class DetectorBlockEntity extends AbstractRedstoneModeNetworkNodeContainerBlockEntity<DetectorNetworkNode> 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<MultiStorageNetworkNode> + extends AbstractRedstoneModeNetworkNodeContainerBlockEntity<MultiStorageNetworkNode> 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<ExternalStorageNetworkNode> + extends AbstractRedstoneModeNetworkNodeContainerBlockEntity<ExternalStorageNetworkNode> 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<GridNetworkNode> +public abstract class AbstractGridBlockEntity + extends AbstractRedstoneModeNetworkNodeContainerBlockEntity<GridNetworkNode> implements Grid, MenuProvider { protected AbstractGridBlockEntity(final BlockEntityType<? extends AbstractGridBlockEntity> type, final BlockPos pos, @@ -55,7 +56,7 @@ public <T> GridOperations<T> createOperations(final PlatformStorageChannelType<T } @Override - public boolean isActive() { + public boolean isGridActive() { return getNode().isActive(); } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/iface/InterfaceBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/iface/InterfaceBlockEntity.java index d08df7577..e0831d42a 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/iface/InterfaceBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/iface/InterfaceBlockEntity.java @@ -10,7 +10,7 @@ import com.refinedmods.refinedstorage2.platform.api.resource.ResourceContainerType; import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; 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.containermenu.InterfaceContainerMenu; @@ -37,7 +37,7 @@ import net.minecraft.world.level.block.state.BlockState; public class InterfaceBlockEntity - extends AbstractInternalNetworkNodeContainerBlockEntity<InterfaceNetworkNode> + extends AbstractRedstoneModeNetworkNodeContainerBlockEntity<InterfaceNetworkNode> 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<T> - extends AbstractInternalNetworkNodeContainerBlockEntity<StorageNetworkNode<T>> + extends AbstractRedstoneModeNetworkNodeContainerBlockEntity<StorageNetworkNode<T>> 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<SimpleNetworkNode> +public class StorageMonitorBlockEntity extends AbstractRedstoneModeNetworkNodeContainerBlockEntity<SimpleNetworkNode> 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<SimpleNetworkNode> +public class WirelessTransmitterBlockEntity + extends AbstractRedstoneModeNetworkNodeContainerBlockEntity<SimpleNetworkNode> 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<N> + T extends NetworkNodeContainerBlockEntityImpl<N> > extends AbstractBlockEntityTicker<T> { @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 <T> boolean onExtract(final PlatformStorageChannelType<T> 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 <T> boolean onScroll(final PlatformStorageChannelType<T> 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<BlockEntityType<SimpleNetworkNodeContainerBlockEntity>> cable; + private Supplier<BlockEntityType<NetworkNodeContainerBlockEntityImpl<SimpleNetworkNode>>> cable; @Nullable private Supplier<BlockEntityType<? extends AbstractDiskDriveBlockEntity>> diskDrive; @Nullable @@ -65,16 +66,18 @@ public final class BlockEntities { @Nullable private Supplier<BlockEntityType<StorageMonitorBlockEntity>> storageMonitor; @Nullable - private Supplier<BlockEntityType<SimpleNetworkNodeContainerBlockEntity>> networkReceiver; + private Supplier<BlockEntityType<NetworkNodeContainerBlockEntityImpl<SimpleNetworkNode>>> networkReceiver; private BlockEntities() { } - public BlockEntityType<SimpleNetworkNodeContainerBlockEntity> getCable() { + public BlockEntityType<NetworkNodeContainerBlockEntityImpl<SimpleNetworkNode>> getCable() { return Objects.requireNonNull(cable).get(); } - public void setCable(final Supplier<BlockEntityType<SimpleNetworkNodeContainerBlockEntity>> supplier) { + public void setCable( + final Supplier<BlockEntityType<NetworkNodeContainerBlockEntityImpl<SimpleNetworkNode>>> supplier + ) { this.cable = supplier; } @@ -208,11 +211,13 @@ public void setStorageMonitor(final Supplier<BlockEntityType<StorageMonitorBlock this.storageMonitor = supplier; } - public BlockEntityType<SimpleNetworkNodeContainerBlockEntity> getNetworkReceiver() { + public BlockEntityType<NetworkNodeContainerBlockEntityImpl<SimpleNetworkNode>> getNetworkReceiver() { return Objects.requireNonNull(networkReceiver).get(); } - public void setNetworkReceiver(final Supplier<BlockEntityType<SimpleNetworkNodeContainerBlockEntity>> supplier) { + public void setNetworkReceiver( + final Supplier<BlockEntityType<NetworkNodeContainerBlockEntityImpl<SimpleNetworkNode>>> 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<ItemResource> 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<PlatformStorageChannelType<?>> types = storageChannelTypeRegistry.getAll(); buf.writeInt(types.size()); types.forEach(type -> writeStorageChannel(type, buf));