From 59cef838efb8f85800087852a828cbe9ea31643c Mon Sep 17 00:00:00 2001 From: raoulvdberge Date: Sun, 29 May 2022 23:50:25 +0200 Subject: [PATCH] Fix some Sonar issues. --- .../node/diskdrive/DiskDriveNetworkNode.java | 1 + ...ckItem.java => StorageBlockBlockItem.java} | 4 +- .../platform/common/block/StorageBlock.java | 6 +- .../diskdrive/DiskDriveBlockEntity.java | 32 ++- .../storage/ItemStorageBlockEntity.java | 6 +- ...tity.java => StorageBlockBlockEntity.java} | 13 +- .../common/containermenu/StorageAccessor.java | 11 - .../diskdrive/DiskDriveContainerMenu.java | 258 ------------------ .../storage/StorageAccessor.java | 18 ++ .../storage/StorageContainerMenu.java | 120 +------- .../storage/StorageSettingsProvider.java | 27 ++ .../ItemStorageBlockContainerMenu.java} | 12 +- .../block/StorageBlockContainerMenu.java | 73 +++++ .../diskdrive/DiskDriveContainerMenu.java | 135 +++++++++ .../diskdrive/StorageDiskInfoAccessor.java | 2 +- .../StorageDiskInfoAccessorImpl.java | 2 +- .../platform/common/content/Menus.java | 10 +- .../item/block/ItemStorageBlockItem.java | 8 +- .../common/screen/DiskDriveScreen.java | 2 +- .../common/screen/StorageBlockScreen.java | 6 +- .../platform/common/screen/StorageScreen.java | 2 +- .../platform/fabric/ModInitializerImpl.java | 6 +- .../platform/forge/ModInitializer.java | 6 +- 23 files changed, 335 insertions(+), 425 deletions(-) rename refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/item/block/{StorageBlockItem.java => StorageBlockBlockItem.java} (94%) rename refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storage/{StorageBlockEntity.java => StorageBlockBlockEntity.java} (93%) delete mode 100644 refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/StorageAccessor.java delete mode 100644 refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/diskdrive/DiskDriveContainerMenu.java create mode 100644 refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/StorageAccessor.java create mode 100644 refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/StorageSettingsProvider.java rename refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/{ItemStorageContainerMenu.java => block/ItemStorageBlockContainerMenu.java} (63%) create mode 100644 refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/block/StorageBlockContainerMenu.java create mode 100644 refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/diskdrive/DiskDriveContainerMenu.java rename refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/{ => storage}/diskdrive/StorageDiskInfoAccessor.java (92%) rename refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/{ => storage}/diskdrive/StorageDiskInfoAccessorImpl.java (96%) diff --git a/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/node/diskdrive/DiskDriveNetworkNode.java b/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/node/diskdrive/DiskDriveNetworkNode.java index e9c57f3dd..b29dd7f07 100644 --- a/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/node/diskdrive/DiskDriveNetworkNode.java +++ b/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/node/diskdrive/DiskDriveNetworkNode.java @@ -218,6 +218,7 @@ public int getPriority() { return priority; } + // TODO: do we need this? And the composite listener stuff? @Override public Optional> getStorageForChannel(StorageChannelType channelType) { DiskDriveCompositeStorage composite = compositeStorages.get(channelType); diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/item/block/StorageBlockItem.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/item/block/StorageBlockBlockItem.java similarity index 94% rename from refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/item/block/StorageBlockItem.java rename to refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/item/block/StorageBlockBlockItem.java index 313e9dd71..e68434585 100644 --- a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/item/block/StorageBlockItem.java +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/item/block/StorageBlockBlockItem.java @@ -19,8 +19,8 @@ import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; -public abstract class StorageBlockItem extends BlockItem { - protected StorageBlockItem(Block block, Properties properties) { +public abstract class StorageBlockBlockItem extends BlockItem { + protected StorageBlockBlockItem(Block block, Properties properties) { super(block, properties); } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/StorageBlock.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/StorageBlock.java index 5e67aa93b..b6eee1617 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/StorageBlock.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/StorageBlock.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.platform.common.block; import com.refinedmods.refinedstorage2.platform.api.item.StorageItemHelper; -import com.refinedmods.refinedstorage2.platform.common.block.entity.storage.StorageBlockEntity; +import com.refinedmods.refinedstorage2.platform.common.block.entity.storage.StorageBlockBlockEntity; import com.refinedmods.refinedstorage2.platform.common.content.LootFunctions; import java.util.UUID; @@ -35,13 +35,13 @@ public LootItemFunctionType getType() { @Override public ItemStack apply(ItemStack stack, LootContext lootContext) { BlockEntity blockEntity = lootContext.getParam(LootContextParams.BLOCK_ENTITY); - if (blockEntity instanceof StorageBlockEntity storageBlockEntity) { + if (blockEntity instanceof StorageBlockBlockEntity storageBlockEntity) { apply(stack, storageBlockEntity); } return stack; } - private void apply(ItemStack stack, StorageBlockEntity storageBlockEntity) { + private void apply(ItemStack stack, StorageBlockBlockEntity storageBlockEntity) { UUID storageId = storageBlockEntity.getStorageId(); if (storageId != null) { LOGGER.info("Transferred storage {} at {} to stack", storageId, storageBlockEntity.getBlockPos()); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/diskdrive/DiskDriveBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/diskdrive/DiskDriveBlockEntity.java index cc1d2d6f6..a37e6a5b9 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/diskdrive/DiskDriveBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/diskdrive/DiskDriveBlockEntity.java @@ -16,7 +16,8 @@ import com.refinedmods.refinedstorage2.platform.common.block.entity.BlockEntityWithDrops; import com.refinedmods.refinedstorage2.platform.common.block.entity.FilterModeSettings; import com.refinedmods.refinedstorage2.platform.common.block.entity.InternalNetworkNodeContainerBlockEntity; -import com.refinedmods.refinedstorage2.platform.common.containermenu.diskdrive.DiskDriveContainerMenu; +import com.refinedmods.refinedstorage2.platform.common.containermenu.storage.StorageSettingsProvider; +import com.refinedmods.refinedstorage2.platform.common.containermenu.storage.diskdrive.DiskDriveContainerMenu; import com.refinedmods.refinedstorage2.platform.common.content.BlockEntities; import com.refinedmods.refinedstorage2.platform.common.util.ContainerUtil; import com.refinedmods.refinedstorage2.platform.common.util.LevelUtil; @@ -35,7 +36,6 @@ import net.minecraft.network.protocol.game.ClientGamePacketListener; import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket; import net.minecraft.server.level.ServerPlayer; -import net.minecraft.world.MenuProvider; import net.minecraft.world.SimpleContainer; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; @@ -50,7 +50,7 @@ import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; -public abstract class DiskDriveBlockEntity extends InternalNetworkNodeContainerBlockEntity implements MenuProvider, BlockEntityWithDrops, DiskDriveListener, ExtendedMenuProvider { +public abstract class DiskDriveBlockEntity extends InternalNetworkNodeContainerBlockEntity implements BlockEntityWithDrops, DiskDriveListener, ExtendedMenuProvider, StorageSettingsProvider { private static final Logger LOGGER = LogManager.getLogger(); private static final String TAG_PRIORITY = "pri"; @@ -207,34 +207,51 @@ public SimpleContainer getDiskInventory() { return diskInventory; } + @Override public FilterMode getFilterMode() { return getNode().getFilterMode(); } + @Override public void setFilterMode(FilterMode mode) { getNode().setFilterMode(mode); setChanged(); } + @Override public boolean isExactMode() { return exactMode; } + @Override public void setExactMode(boolean exactMode) { this.exactMode = exactMode; initializeResourceFilter(); setChanged(); } + @Override public AccessMode getAccessMode() { return getNode().getAccessMode(); } + @Override public void setAccessMode(AccessMode accessMode) { getNode().setAccessMode(accessMode); setChanged(); } + @Override + public int getPriority() { + return getNode().getPriority(); + } + + @Override + public void setPriority(int priority) { + getNode().setPriority(priority); + setChanged(); + } + void onDiskChanged(int slot) { getNode().onDiskChanged(slot); LevelUtil.updateBlock(level, worldPosition, this.getBlockState()); @@ -318,15 +335,6 @@ public NonNullList getDrops() { return drops; } - public int getPriority() { - return getNode().getPriority(); - } - - public void setPriority(int priority) { - getNode().setPriority(priority); - setChanged(); - } - @Override public void onDiskChanged() { this.syncRequested = true; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storage/ItemStorageBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storage/ItemStorageBlockEntity.java index d4c03c668..8c11b5c38 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storage/ItemStorageBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storage/ItemStorageBlockEntity.java @@ -10,7 +10,7 @@ import com.refinedmods.refinedstorage2.platform.api.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.api.storage.PlatformLimitedStorage; import com.refinedmods.refinedstorage2.platform.api.storage.PlatformStorage; -import com.refinedmods.refinedstorage2.platform.common.containermenu.storage.ItemStorageContainerMenu; +import com.refinedmods.refinedstorage2.platform.common.containermenu.storage.block.ItemStorageBlockContainerMenu; import com.refinedmods.refinedstorage2.platform.common.content.BlockEntities; import com.refinedmods.refinedstorage2.platform.common.internal.resource.ItemResourceType; import com.refinedmods.refinedstorage2.platform.common.internal.storage.channel.StorageChannelTypes; @@ -25,7 +25,7 @@ import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; -public class ItemStorageBlockEntity extends StorageBlockEntity { +public class ItemStorageBlockEntity extends StorageBlockBlockEntity { private final ItemStorageType.Variant variant; private final Component displayName; @@ -80,7 +80,7 @@ public Component getDisplayName() { @Override public AbstractContainerMenu createMenu(int syncId, Inventory inventory, Player player) { - return new ItemStorageContainerMenu( + return new ItemStorageBlockContainerMenu( syncId, player, resourceFilterContainer, diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storage/StorageBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storage/StorageBlockBlockEntity.java similarity index 93% rename from refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storage/StorageBlockEntity.java rename to refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storage/StorageBlockBlockEntity.java index de73eb272..26ff6f697 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storage/StorageBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storage/StorageBlockBlockEntity.java @@ -14,6 +14,7 @@ import com.refinedmods.refinedstorage2.platform.common.block.entity.AccessModeSettings; import com.refinedmods.refinedstorage2.platform.common.block.entity.FilterModeSettings; import com.refinedmods.refinedstorage2.platform.common.block.entity.InternalNetworkNodeContainerBlockEntity; +import com.refinedmods.refinedstorage2.platform.common.containermenu.storage.StorageSettingsProvider; import java.util.UUID; @@ -27,7 +28,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -public abstract class StorageBlockEntity extends InternalNetworkNodeContainerBlockEntity> implements ExtendedMenuProvider { +public abstract class StorageBlockBlockEntity extends InternalNetworkNodeContainerBlockEntity> implements ExtendedMenuProvider, StorageSettingsProvider { private static final Logger LOGGER = LogManager.getLogger(); private static final String TAG_STORAGE_ID = "sid"; @@ -42,7 +43,7 @@ public abstract class StorageBlockEntity extends InternalNetworkNodeContainer private UUID storageId; private boolean exactMode; - protected StorageBlockEntity(BlockEntityType type, BlockPos pos, BlockState state, StorageNetworkNode node, ResourceType resourceType) { + protected StorageBlockBlockEntity(BlockEntityType type, BlockPos pos, BlockState state, StorageNetworkNode node, ResourceType resourceType) { super(type, pos, state, node); node.setNormalizer(this::normalize); this.resourceFilterContainer = new FilteredResourceFilterContainer(9, this::resourceFilterContainerChanged, resourceType); @@ -165,38 +166,46 @@ public UUID getStorageId() { return storageId; } + @Override public AccessMode getAccessMode() { return getNode().getAccessMode(); } + @Override public void setAccessMode(AccessMode accessMode) { getNode().setAccessMode(accessMode); setChanged(); } + @Override public boolean isExactMode() { return exactMode; } + @Override public void setExactMode(boolean exactMode) { this.exactMode = exactMode; initializeResourceFilter(); setChanged(); } + @Override public int getPriority() { return getNode().getPriority(); } + @Override public void setPriority(int priority) { getNode().setPriority(priority); setChanged(); } + @Override public FilterMode getFilterMode() { return getNode().getFilterMode(); } + @Override public void setFilterMode(FilterMode mode) { getNode().setFilterMode(mode); setChanged(); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/StorageAccessor.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/StorageAccessor.java deleted file mode 100644 index 9084567ae..000000000 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/StorageAccessor.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.refinedmods.refinedstorage2.platform.common.containermenu; - -public interface StorageAccessor extends PriorityAccessor, FilterModeAccessor, ExactModeAccessor, AccessModeAccessor, RedstoneModeAccessor, ResourceTypeAccessor { - long getStored(); - - long getCapacity(); - - double getProgress(); - - boolean hasCapacity(); -} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/diskdrive/DiskDriveContainerMenu.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/diskdrive/DiskDriveContainerMenu.java deleted file mode 100644 index 757ee6ea4..000000000 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/diskdrive/DiskDriveContainerMenu.java +++ /dev/null @@ -1,258 +0,0 @@ -package com.refinedmods.refinedstorage2.platform.common.containermenu.diskdrive; - -import com.refinedmods.refinedstorage2.api.core.filter.FilterMode; -import com.refinedmods.refinedstorage2.api.network.node.diskdrive.DiskDriveNetworkNode; -import com.refinedmods.refinedstorage2.api.storage.AccessMode; -import com.refinedmods.refinedstorage2.api.storage.StorageInfo; -import com.refinedmods.refinedstorage2.platform.api.network.node.RedstoneMode; -import com.refinedmods.refinedstorage2.platform.api.resource.filter.ResourceFilterContainer; -import com.refinedmods.refinedstorage2.platform.api.storage.item.StorageDiskItem; -import com.refinedmods.refinedstorage2.platform.common.block.entity.AccessModeSettings; -import com.refinedmods.refinedstorage2.platform.common.block.entity.FilterModeSettings; -import com.refinedmods.refinedstorage2.platform.common.block.entity.RedstoneModeSettings; -import com.refinedmods.refinedstorage2.platform.common.block.entity.diskdrive.DiskDriveBlockEntity; -import com.refinedmods.refinedstorage2.platform.common.containermenu.ResourceFilterableContainerMenu; -import com.refinedmods.refinedstorage2.platform.common.containermenu.StorageAccessor; -import com.refinedmods.refinedstorage2.platform.common.containermenu.property.TwoWaySyncProperty; -import com.refinedmods.refinedstorage2.platform.common.containermenu.slot.ResourceFilterSlot; -import com.refinedmods.refinedstorage2.platform.common.containermenu.slot.ValidatedSlot; -import com.refinedmods.refinedstorage2.platform.common.content.Menus; - -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import java.util.stream.Stream; - -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.world.SimpleContainer; -import net.minecraft.world.entity.player.Inventory; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.inventory.Slot; -import net.minecraft.world.item.ItemStack; - -public class DiskDriveContainerMenu extends ResourceFilterableContainerMenu implements StorageAccessor { - private static final int DISK_SLOT_X = 61; - private static final int DISK_SLOT_Y = 54; - - private static final int FILTER_SLOT_X = 8; - private static final int FILTER_SLOT_Y = 20; - - private final StorageDiskInfoAccessor storageInfoAccessor; - private final List diskSlots = new ArrayList<>(); - private final TwoWaySyncProperty priorityProperty; - private final TwoWaySyncProperty filterModeProperty; - private final TwoWaySyncProperty exactModeProperty; - private final TwoWaySyncProperty accessModeProperty; - private final TwoWaySyncProperty redstoneModeProperty; - - public DiskDriveContainerMenu(int syncId, Inventory playerInventory, FriendlyByteBuf buf) { - super(Menus.INSTANCE.getDiskDrive(), syncId); - - this.priorityProperty = TwoWaySyncProperty.integerForClient(0); - this.filterModeProperty = FilterModeSettings.createClientSyncProperty(1); - this.exactModeProperty = TwoWaySyncProperty.booleanForClient(2); - this.accessModeProperty = AccessModeSettings.createClientSyncProperty(3); - this.redstoneModeProperty = RedstoneModeSettings.createClientSyncProperty(4); - - addDataSlot(priorityProperty); - addDataSlot(filterModeProperty); - addDataSlot(exactModeProperty); - addDataSlot(accessModeProperty); - addDataSlot(redstoneModeProperty); - - this.storageInfoAccessor = new StorageDiskInfoAccessorImpl(playerInventory.player.getCommandSenderWorld()); - - addSlots( - playerInventory.player, - new SimpleContainer(DiskDriveNetworkNode.DISK_COUNT), - new ResourceFilterContainer(9, () -> { - }) - ); - - initializeResourceFilterSlots(buf); - } - - public DiskDriveContainerMenu(int syncId, - Player player, - SimpleContainer diskInventory, - ResourceFilterContainer resourceFilterContainer, - DiskDriveBlockEntity diskDrive, - StorageDiskInfoAccessor storageInfoAccessor) { - super(Menus.INSTANCE.getDiskDrive(), syncId, player, resourceFilterContainer); - - this.priorityProperty = TwoWaySyncProperty.forServer( - 0, - priority -> priority, - priority -> priority, - diskDrive::getPriority, - diskDrive::setPriority - ); - this.filterModeProperty = TwoWaySyncProperty.forServer( - 1, - FilterModeSettings::getFilterMode, - FilterModeSettings::getFilterMode, - diskDrive::getFilterMode, - diskDrive::setFilterMode - ); - this.exactModeProperty = TwoWaySyncProperty.forServer( - 2, - value -> Boolean.TRUE.equals(value) ? 0 : 1, - value -> value == 0, - diskDrive::isExactMode, - diskDrive::setExactMode - ); - this.accessModeProperty = TwoWaySyncProperty.forServer( - 3, - AccessModeSettings::getAccessMode, - AccessModeSettings::getAccessMode, - diskDrive::getAccessMode, - diskDrive::setAccessMode - ); - this.redstoneModeProperty = TwoWaySyncProperty.forServer( - 4, - RedstoneModeSettings::getRedstoneMode, - RedstoneModeSettings::getRedstoneMode, - diskDrive::getRedstoneMode, - diskDrive::setRedstoneMode - ); - - addDataSlot(priorityProperty); - addDataSlot(filterModeProperty); - addDataSlot(exactModeProperty); - addDataSlot(accessModeProperty); - addDataSlot(redstoneModeProperty); - - this.storageInfoAccessor = storageInfoAccessor; - - addSlots(player, diskInventory, resourceFilterContainer); - } - - private void addSlots(Player player, SimpleContainer diskInventory, ResourceFilterContainer resourceFilterContainer) { - for (int i = 0; i < DiskDriveNetworkNode.DISK_COUNT; ++i) { - diskSlots.add(addSlot(createDiskSlot(diskInventory, i))); - } - for (int i = 0; i < 9; ++i) { - addSlot(createFilterSlot(resourceFilterContainer, i)); - } - addPlayerInventory(player.getInventory(), 8, 141); - } - - private Slot createFilterSlot(ResourceFilterContainer resourceFilterContainer, int i) { - int x = FILTER_SLOT_X + (18 * i); - return new ResourceFilterSlot(resourceFilterContainer, i, x, FILTER_SLOT_Y); - } - - private Slot createDiskSlot(SimpleContainer diskInventory, int i) { - int x = DISK_SLOT_X + ((i % 2) * 18); - int y = DISK_SLOT_Y + Math.floorDiv(i, 2) * 18; - return new ValidatedSlot(diskInventory, i, x, y, stack -> stack.getItem() instanceof StorageDiskItem); - } - - @Override - public boolean hasCapacity() { - return getStorageDiskInfo().allMatch(info -> info.capacity() > 0); - } - - @Override - public double getProgress() { - if (!hasCapacity()) { - return 0; - } - return (double) getStored() / (double) getCapacity(); - } - - @Override - public long getCapacity() { - return getStorageDiskInfo().mapToLong(StorageInfo::capacity).sum(); - } - - @Override - public long getStored() { - return getStorageDiskInfo().mapToLong(StorageInfo::stored).sum(); - } - - private Stream getStorageDiskInfo() { - return diskSlots - .stream() - .map(Slot::getItem) - .filter(stack -> !stack.isEmpty()) - .map(storageInfoAccessor::getInfo) - .flatMap(Optional::stream); - } - - @Override - public ItemStack quickMoveStack(Player player, int index) { - ItemStack originalStack = ItemStack.EMPTY; - Slot slot = this.slots.get(index); - if (slot.hasItem()) { - ItemStack stackInSlot = slot.getItem(); - originalStack = stackInSlot.copy(); - - if (index < 8) { - if (!moveItemStackTo(stackInSlot, 8, slots.size(), true)) { - return ItemStack.EMPTY; - } - } else if (!moveItemStackTo(stackInSlot, 0, 8, false)) { - return ItemStack.EMPTY; - } - - if (stackInSlot.isEmpty()) { - slot.set(ItemStack.EMPTY); - } else { - slot.setChanged(); - } - } - - return originalStack; - } - - @Override - public int getPriority() { - return priorityProperty.getDeserialized(); - } - - @Override - public void setPriority(int priority) { - priorityProperty.syncToServer(priority); - } - - @Override - public FilterMode getFilterMode() { - return filterModeProperty.getDeserialized(); - } - - @Override - public void setFilterMode(FilterMode filterMode) { - filterModeProperty.syncToServer(filterMode); - } - - @Override - public boolean isExactMode() { - return exactModeProperty.getDeserialized(); - } - - @Override - public void setExactMode(boolean exactMode) { - exactModeProperty.syncToServer(exactMode); - } - - @Override - public AccessMode getAccessMode() { - return accessModeProperty.getDeserialized(); - } - - @Override - public void setAccessMode(AccessMode accessMode) { - accessModeProperty.syncToServer(accessMode); - } - - @Override - public RedstoneMode getRedstoneMode() { - return redstoneModeProperty.getDeserialized(); - } - - @Override - public void setRedstoneMode(RedstoneMode redstoneMode) { - redstoneModeProperty.syncToServer(redstoneMode); - } -} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/StorageAccessor.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/StorageAccessor.java new file mode 100644 index 000000000..4d4c35048 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/StorageAccessor.java @@ -0,0 +1,18 @@ +package com.refinedmods.refinedstorage2.platform.common.containermenu.storage; + +import com.refinedmods.refinedstorage2.platform.common.containermenu.AccessModeAccessor; +import com.refinedmods.refinedstorage2.platform.common.containermenu.ExactModeAccessor; +import com.refinedmods.refinedstorage2.platform.common.containermenu.FilterModeAccessor; +import com.refinedmods.refinedstorage2.platform.common.containermenu.PriorityAccessor; +import com.refinedmods.refinedstorage2.platform.common.containermenu.RedstoneModeAccessor; +import com.refinedmods.refinedstorage2.platform.common.containermenu.ResourceTypeAccessor; + +public interface StorageAccessor extends PriorityAccessor, FilterModeAccessor, ExactModeAccessor, AccessModeAccessor, RedstoneModeAccessor, ResourceTypeAccessor { + long getStored(); + + long getCapacity(); + + double getProgress(); + + boolean hasCapacity(); +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/StorageContainerMenu.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/StorageContainerMenu.java index 7e9ca1f1a..bc3160184 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/StorageContainerMenu.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/StorageContainerMenu.java @@ -3,39 +3,22 @@ import com.refinedmods.refinedstorage2.api.core.filter.FilterMode; import com.refinedmods.refinedstorage2.api.storage.AccessMode; import com.refinedmods.refinedstorage2.platform.api.network.node.RedstoneMode; -import com.refinedmods.refinedstorage2.platform.api.resource.filter.FilteredResourceFilterContainer; -import com.refinedmods.refinedstorage2.platform.api.resource.filter.ResourceFilterContainer; -import com.refinedmods.refinedstorage2.platform.api.resource.filter.ResourceType; import com.refinedmods.refinedstorage2.platform.common.block.entity.AccessModeSettings; import com.refinedmods.refinedstorage2.platform.common.block.entity.FilterModeSettings; import com.refinedmods.refinedstorage2.platform.common.block.entity.RedstoneModeSettings; -import com.refinedmods.refinedstorage2.platform.common.block.entity.storage.StorageBlockEntity; import com.refinedmods.refinedstorage2.platform.common.containermenu.ResourceFilterableContainerMenu; -import com.refinedmods.refinedstorage2.platform.common.containermenu.StorageAccessor; import com.refinedmods.refinedstorage2.platform.common.containermenu.property.TwoWaySyncProperty; -import com.refinedmods.refinedstorage2.platform.common.containermenu.slot.ResourceFilterSlot; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.world.entity.player.Inventory; -import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.MenuType; -import net.minecraft.world.inventory.Slot; -import net.minecraft.world.item.ItemStack; - -public abstract class StorageContainerMenu extends ResourceFilterableContainerMenu implements StorageAccessor { - private static final int FILTER_SLOT_X = 8; - private static final int FILTER_SLOT_Y = 20; +public abstract class StorageContainerMenu extends ResourceFilterableContainerMenu implements StorageAccessor { private final TwoWaySyncProperty priorityProperty; private final TwoWaySyncProperty filterModeProperty; private final TwoWaySyncProperty exactModeProperty; private final TwoWaySyncProperty accessModeProperty; private final TwoWaySyncProperty redstoneModeProperty; - private long stored; - private long capacity; - - protected StorageContainerMenu(MenuType type, int syncId, Inventory playerInventory, FriendlyByteBuf buf, ResourceType resourceType) { + protected StorageContainerMenu(MenuType type, int syncId) { super(type, syncId); this.priorityProperty = TwoWaySyncProperty.integerForClient(0); @@ -49,57 +32,45 @@ protected StorageContainerMenu(MenuType type, int syncId, Inventory playerInv addDataSlot(exactModeProperty); addDataSlot(accessModeProperty); addDataSlot(redstoneModeProperty); - - stored = buf.readLong(); - capacity = buf.readLong(); - - addSlots(playerInventory.player, new FilteredResourceFilterContainer(9, () -> { - }, resourceType)); - - initializeResourceFilterSlots(buf); } - protected StorageContainerMenu(MenuType type, - int syncId, - Player player, - ResourceFilterContainer resourceFilterContainer, - StorageBlockEntity storageBlock) { - super(type, syncId, player, resourceFilterContainer); + protected StorageContainerMenu(MenuType type, int syncId, StorageSettingsProvider storageSettingsProvider) { + super(type, syncId); this.priorityProperty = TwoWaySyncProperty.forServer( 0, priority -> priority, priority -> priority, - storageBlock::getPriority, - storageBlock::setPriority + storageSettingsProvider::getPriority, + storageSettingsProvider::setPriority ); this.filterModeProperty = TwoWaySyncProperty.forServer( 1, FilterModeSettings::getFilterMode, FilterModeSettings::getFilterMode, - storageBlock::getFilterMode, - storageBlock::setFilterMode + storageSettingsProvider::getFilterMode, + storageSettingsProvider::setFilterMode ); this.exactModeProperty = TwoWaySyncProperty.forServer( 2, value -> Boolean.TRUE.equals(value) ? 0 : 1, value -> value == 0, - storageBlock::isExactMode, - storageBlock::setExactMode + storageSettingsProvider::isExactMode, + storageSettingsProvider::setExactMode ); this.accessModeProperty = TwoWaySyncProperty.forServer( 3, AccessModeSettings::getAccessMode, AccessModeSettings::getAccessMode, - storageBlock::getAccessMode, - storageBlock::setAccessMode + storageSettingsProvider::getAccessMode, + storageSettingsProvider::setAccessMode ); this.redstoneModeProperty = TwoWaySyncProperty.forServer( 4, RedstoneModeSettings::getRedstoneMode, RedstoneModeSettings::getRedstoneMode, - storageBlock::getRedstoneMode, - storageBlock::setRedstoneMode + storageSettingsProvider::getRedstoneMode, + storageSettingsProvider::setRedstoneMode ); addDataSlot(priorityProperty); @@ -107,69 +78,6 @@ protected StorageContainerMenu(MenuType type, addDataSlot(exactModeProperty); addDataSlot(accessModeProperty); addDataSlot(redstoneModeProperty); - - addSlots(player, resourceFilterContainer); - } - - private void addSlots(Player player, ResourceFilterContainer resourceFilterContainer) { - for (int i = 0; i < 9; ++i) { - addSlot(createFilterSlot(resourceFilterContainer, i)); - } - addPlayerInventory(player.getInventory(), 8, 141); - } - - private Slot createFilterSlot(ResourceFilterContainer resourceFilterContainer, int i) { - int x = FILTER_SLOT_X + (18 * i); - return new ResourceFilterSlot(resourceFilterContainer, i, x, FILTER_SLOT_Y); - } - - @Override - public boolean hasCapacity() { - return capacity > 0; - } - - @Override - public double getProgress() { - if (!hasCapacity()) { - return 0; - } - return (double) getStored() / (double) getCapacity(); - } - - @Override - public long getCapacity() { - return capacity; - } - - @Override - public long getStored() { - return stored; - } - - @Override - public ItemStack quickMoveStack(Player player, int index) { - ItemStack originalStack = ItemStack.EMPTY; - Slot slot = this.slots.get(index); - if (slot.hasItem()) { - ItemStack stackInSlot = slot.getItem(); - originalStack = stackInSlot.copy(); - - if (index < 8) { - if (!moveItemStackTo(stackInSlot, 8, slots.size(), true)) { - return ItemStack.EMPTY; - } - } else if (!moveItemStackTo(stackInSlot, 0, 8, false)) { - return ItemStack.EMPTY; - } - - if (stackInSlot.isEmpty()) { - slot.set(ItemStack.EMPTY); - } else { - slot.setChanged(); - } - } - - return originalStack; } @Override diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/StorageSettingsProvider.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/StorageSettingsProvider.java new file mode 100644 index 000000000..513026604 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/StorageSettingsProvider.java @@ -0,0 +1,27 @@ +package com.refinedmods.refinedstorage2.platform.common.containermenu.storage; + +import com.refinedmods.refinedstorage2.api.core.filter.FilterMode; +import com.refinedmods.refinedstorage2.api.storage.AccessMode; +import com.refinedmods.refinedstorage2.platform.api.network.node.RedstoneMode; + +public interface StorageSettingsProvider { + int getPriority(); + + void setPriority(int priority); + + FilterMode getFilterMode(); + + void setFilterMode(FilterMode filterMode); + + boolean isExactMode(); + + void setExactMode(boolean exactMode); + + AccessMode getAccessMode(); + + void setAccessMode(AccessMode accessMode); + + RedstoneMode getRedstoneMode(); + + void setRedstoneMode(RedstoneMode redstoneMode); +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/ItemStorageContainerMenu.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/block/ItemStorageBlockContainerMenu.java similarity index 63% rename from refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/ItemStorageContainerMenu.java rename to refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/block/ItemStorageBlockContainerMenu.java index f5e7898ab..09bce9943 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/ItemStorageContainerMenu.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/block/ItemStorageBlockContainerMenu.java @@ -1,8 +1,8 @@ -package com.refinedmods.refinedstorage2.platform.common.containermenu.storage; +package com.refinedmods.refinedstorage2.platform.common.containermenu.storage.block; import com.refinedmods.refinedstorage2.platform.api.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.api.resource.filter.ResourceFilterContainer; -import com.refinedmods.refinedstorage2.platform.common.block.entity.storage.StorageBlockEntity; +import com.refinedmods.refinedstorage2.platform.common.block.entity.storage.StorageBlockBlockEntity; import com.refinedmods.refinedstorage2.platform.common.content.Menus; import com.refinedmods.refinedstorage2.platform.common.internal.resource.ItemResourceType; @@ -10,12 +10,12 @@ import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; -public class ItemStorageContainerMenu extends StorageContainerMenu { - public ItemStorageContainerMenu(int syncId, Inventory playerInventory, FriendlyByteBuf buf) { - super(Menus.INSTANCE.getItemStorage(), syncId, playerInventory, buf, ItemResourceType.INSTANCE); +public class ItemStorageBlockContainerMenu extends StorageBlockContainerMenu { + public ItemStorageBlockContainerMenu(int syncId, Inventory playerInventory, FriendlyByteBuf buf) { + super(Menus.INSTANCE.getItemStorage(), syncId, playerInventory.player, buf, ItemResourceType.INSTANCE); } - public ItemStorageContainerMenu(int syncId, Player player, ResourceFilterContainer resourceFilterContainer, StorageBlockEntity storageBlock) { + public ItemStorageBlockContainerMenu(int syncId, Player player, ResourceFilterContainer resourceFilterContainer, StorageBlockBlockEntity storageBlock) { super(Menus.INSTANCE.getItemStorage(), syncId, player, resourceFilterContainer, storageBlock); } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/block/StorageBlockContainerMenu.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/block/StorageBlockContainerMenu.java new file mode 100644 index 000000000..a608d7ced --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/block/StorageBlockContainerMenu.java @@ -0,0 +1,73 @@ +package com.refinedmods.refinedstorage2.platform.common.containermenu.storage.block; + +import com.refinedmods.refinedstorage2.platform.api.resource.filter.FilteredResourceFilterContainer; +import com.refinedmods.refinedstorage2.platform.api.resource.filter.ResourceFilterContainer; +import com.refinedmods.refinedstorage2.platform.api.resource.filter.ResourceType; +import com.refinedmods.refinedstorage2.platform.common.block.entity.storage.StorageBlockBlockEntity; +import com.refinedmods.refinedstorage2.platform.common.containermenu.slot.ResourceFilterSlot; +import com.refinedmods.refinedstorage2.platform.common.containermenu.storage.StorageContainerMenu; + +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.Slot; + +public abstract class StorageBlockContainerMenu extends StorageContainerMenu { + private static final int FILTER_SLOT_X = 8; + private static final int FILTER_SLOT_Y = 20; + + private long stored; + private long capacity; + + protected StorageBlockContainerMenu(MenuType type, int syncId, Player player, FriendlyByteBuf buf, ResourceType resourceType) { + super(type, syncId); + + this.stored = buf.readLong(); + this.capacity = buf.readLong(); + + addSlots(player, new FilteredResourceFilterContainer(9, () -> { + }, resourceType)); + + initializeResourceFilterSlots(buf); + } + + protected StorageBlockContainerMenu(MenuType type, int syncId, Player player, ResourceFilterContainer resourceFilterContainer, StorageBlockBlockEntity storageBlock) { + super(type, syncId, storageBlock); + addSlots(player, resourceFilterContainer); + } + + private void addSlots(Player player, ResourceFilterContainer resourceFilterContainer) { + for (int i = 0; i < 9; ++i) { + addSlot(createFilterSlot(resourceFilterContainer, i)); + } + addPlayerInventory(player.getInventory(), 8, 141); + } + + private Slot createFilterSlot(ResourceFilterContainer resourceFilterContainer, int i) { + int x = FILTER_SLOT_X + (18 * i); + return new ResourceFilterSlot(resourceFilterContainer, i, x, FILTER_SLOT_Y); + } + + @Override + public boolean hasCapacity() { + return capacity > 0; + } + + @Override + public double getProgress() { + if (!hasCapacity()) { + return 0; + } + return (double) getStored() / (double) getCapacity(); + } + + @Override + public long getCapacity() { + return capacity; + } + + @Override + public long getStored() { + return stored; + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/diskdrive/DiskDriveContainerMenu.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/diskdrive/DiskDriveContainerMenu.java new file mode 100644 index 000000000..650de778d --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/diskdrive/DiskDriveContainerMenu.java @@ -0,0 +1,135 @@ +package com.refinedmods.refinedstorage2.platform.common.containermenu.storage.diskdrive; + +import com.refinedmods.refinedstorage2.api.network.node.diskdrive.DiskDriveNetworkNode; +import com.refinedmods.refinedstorage2.api.storage.StorageInfo; +import com.refinedmods.refinedstorage2.platform.api.resource.filter.ResourceFilterContainer; +import com.refinedmods.refinedstorage2.platform.api.storage.item.StorageDiskItem; +import com.refinedmods.refinedstorage2.platform.common.block.entity.diskdrive.DiskDriveBlockEntity; +import com.refinedmods.refinedstorage2.platform.common.containermenu.slot.ResourceFilterSlot; +import com.refinedmods.refinedstorage2.platform.common.containermenu.slot.ValidatedSlot; +import com.refinedmods.refinedstorage2.platform.common.containermenu.storage.StorageContainerMenu; +import com.refinedmods.refinedstorage2.platform.common.content.Menus; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import java.util.stream.Stream; + +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.world.SimpleContainer; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.Slot; +import net.minecraft.world.item.ItemStack; + +public class DiskDriveContainerMenu extends StorageContainerMenu { + private static final int DISK_SLOT_X = 61; + private static final int DISK_SLOT_Y = 54; + + private static final int FILTER_SLOT_X = 8; + private static final int FILTER_SLOT_Y = 20; + + private final StorageDiskInfoAccessor storageInfoAccessor; + + private final List diskSlots = new ArrayList<>(); + + public DiskDriveContainerMenu(int syncId, Inventory playerInventory, FriendlyByteBuf buf) { + super(Menus.INSTANCE.getDiskDrive(), syncId); + + this.storageInfoAccessor = new StorageDiskInfoAccessorImpl(playerInventory.player.getCommandSenderWorld()); + + addSlots( + playerInventory.player, + new SimpleContainer(DiskDriveNetworkNode.DISK_COUNT), + new ResourceFilterContainer(9, () -> { + }) + ); + + initializeResourceFilterSlots(buf); + } + + public DiskDriveContainerMenu(int syncId, Player player, SimpleContainer diskInventory, ResourceFilterContainer resourceFilterContainer, DiskDriveBlockEntity diskDrive, StorageDiskInfoAccessor storageInfoAccessor) { + super(Menus.INSTANCE.getDiskDrive(), syncId, diskDrive); + this.storageInfoAccessor = storageInfoAccessor; + addSlots(player, diskInventory, resourceFilterContainer); + } + + private void addSlots(Player player, SimpleContainer diskInventory, ResourceFilterContainer resourceFilterContainer) { + for (int i = 0; i < DiskDriveNetworkNode.DISK_COUNT; ++i) { + diskSlots.add(addSlot(createDiskSlot(diskInventory, i))); + } + for (int i = 0; i < 9; ++i) { + addSlot(createFilterSlot(resourceFilterContainer, i)); + } + addPlayerInventory(player.getInventory(), 8, 141); + } + + private Slot createFilterSlot(ResourceFilterContainer resourceFilterContainer, int i) { + int x = FILTER_SLOT_X + (18 * i); + return new ResourceFilterSlot(resourceFilterContainer, i, x, FILTER_SLOT_Y); + } + + private Slot createDiskSlot(SimpleContainer diskInventory, int i) { + int x = DISK_SLOT_X + ((i % 2) * 18); + int y = DISK_SLOT_Y + Math.floorDiv(i, 2) * 18; + return new ValidatedSlot(diskInventory, i, x, y, stack -> stack.getItem() instanceof StorageDiskItem); + } + + @Override + public boolean hasCapacity() { + return getStorageDiskInfo().allMatch(info -> info.capacity() > 0); + } + + @Override + public double getProgress() { + if (!hasCapacity()) { + return 0; + } + return (double) getStored() / (double) getCapacity(); + } + + @Override + public long getCapacity() { + return getStorageDiskInfo().mapToLong(StorageInfo::capacity).sum(); + } + + @Override + public long getStored() { + return getStorageDiskInfo().mapToLong(StorageInfo::stored).sum(); + } + + private Stream getStorageDiskInfo() { + return diskSlots + .stream() + .map(Slot::getItem) + .filter(stack -> !stack.isEmpty()) + .map(storageInfoAccessor::getInfo) + .flatMap(Optional::stream); + } + + @Override + public ItemStack quickMoveStack(Player player, int index) { + ItemStack originalStack = ItemStack.EMPTY; + Slot slot = this.slots.get(index); + if (slot.hasItem()) { + ItemStack stackInSlot = slot.getItem(); + originalStack = stackInSlot.copy(); + + if (index < 8) { + if (!moveItemStackTo(stackInSlot, 8, slots.size(), true)) { + return ItemStack.EMPTY; + } + } else if (!moveItemStackTo(stackInSlot, 0, 8, false)) { + return ItemStack.EMPTY; + } + + if (stackInSlot.isEmpty()) { + slot.set(ItemStack.EMPTY); + } else { + slot.setChanged(); + } + } + + return originalStack; + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/diskdrive/StorageDiskInfoAccessor.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/diskdrive/StorageDiskInfoAccessor.java similarity index 92% rename from refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/diskdrive/StorageDiskInfoAccessor.java rename to refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/diskdrive/StorageDiskInfoAccessor.java index f3dff26ad..92aaae356 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/diskdrive/StorageDiskInfoAccessor.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/diskdrive/StorageDiskInfoAccessor.java @@ -1,4 +1,4 @@ -package com.refinedmods.refinedstorage2.platform.common.containermenu.diskdrive; +package com.refinedmods.refinedstorage2.platform.common.containermenu.storage.diskdrive; import com.refinedmods.refinedstorage2.api.storage.StorageInfo; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/diskdrive/StorageDiskInfoAccessorImpl.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/diskdrive/StorageDiskInfoAccessorImpl.java similarity index 96% rename from refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/diskdrive/StorageDiskInfoAccessorImpl.java rename to refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/diskdrive/StorageDiskInfoAccessorImpl.java index adee4a8b1..08df49f1c 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/diskdrive/StorageDiskInfoAccessorImpl.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/diskdrive/StorageDiskInfoAccessorImpl.java @@ -1,4 +1,4 @@ -package com.refinedmods.refinedstorage2.platform.common.containermenu.diskdrive; +package com.refinedmods.refinedstorage2.platform.common.containermenu.storage.diskdrive; import com.refinedmods.refinedstorage2.api.storage.StorageInfo; import com.refinedmods.refinedstorage2.platform.api.storage.item.StorageDiskItem; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/Menus.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/Menus.java index 0fe26ea77..403aa0276 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/Menus.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/Menus.java @@ -1,10 +1,10 @@ package com.refinedmods.refinedstorage2.platform.common.content; import com.refinedmods.refinedstorage2.platform.common.containermenu.ControllerContainerMenu; -import com.refinedmods.refinedstorage2.platform.common.containermenu.diskdrive.DiskDriveContainerMenu; import com.refinedmods.refinedstorage2.platform.common.containermenu.grid.FluidGridContainerMenu; import com.refinedmods.refinedstorage2.platform.common.containermenu.grid.ItemGridContainerMenu; -import com.refinedmods.refinedstorage2.platform.common.containermenu.storage.ItemStorageContainerMenu; +import com.refinedmods.refinedstorage2.platform.common.containermenu.storage.block.ItemStorageBlockContainerMenu; +import com.refinedmods.refinedstorage2.platform.common.containermenu.storage.diskdrive.DiskDriveContainerMenu; import net.minecraft.world.inventory.MenuType; @@ -15,7 +15,7 @@ public final class Menus { private MenuType grid; private MenuType fluidGrid; private MenuType controller; - private MenuType itemStorage; + private MenuType itemStorage; private Menus() { } @@ -52,11 +52,11 @@ public void setController(MenuType controller) { this.controller = controller; } - public MenuType getItemStorage() { + public MenuType getItemStorage() { return itemStorage; } - public void setItemStorage(MenuType itemStorage) { + public void setItemStorage(MenuType itemStorage) { this.itemStorage = itemStorage; } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/item/block/ItemStorageBlockItem.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/item/block/ItemStorageBlockItem.java index c36a74360..680781cf3 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/item/block/ItemStorageBlockItem.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/item/block/ItemStorageBlockItem.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.platform.common.item.block; -import com.refinedmods.refinedstorage2.platform.api.item.block.StorageBlockItem; -import com.refinedmods.refinedstorage2.platform.common.block.entity.storage.StorageBlockEntity; +import com.refinedmods.refinedstorage2.platform.api.item.block.StorageBlockBlockItem; +import com.refinedmods.refinedstorage2.platform.common.block.entity.storage.StorageBlockBlockEntity; import com.refinedmods.refinedstorage2.platform.common.content.Blocks; import com.refinedmods.refinedstorage2.platform.common.content.Items; import com.refinedmods.refinedstorage2.platform.common.internal.storage.type.ItemStorageType; @@ -15,7 +15,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -public class ItemStorageBlockItem extends StorageBlockItem { +public class ItemStorageBlockItem extends StorageBlockBlockItem { private static final Logger LOGGER = LogManager.getLogger(); private final ItemStorageType.Variant variant; @@ -40,7 +40,7 @@ protected ItemStack createSecondaryDisassemblyByproduct(int count) { @Override protected void updateBlockEntityWithStorageId(BlockPos pos, BlockEntity blockEntity, UUID id) { - if (blockEntity instanceof StorageBlockEntity storageBlockEntity) { + if (blockEntity instanceof StorageBlockBlockEntity storageBlockEntity) { LOGGER.info("Transferred storage {} to block at {}", id, pos); storageBlockEntity.modifyStorageIdAfterAlreadyInitialized(id); } else { diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/DiskDriveScreen.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/DiskDriveScreen.java index 26df984df..91f068250 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/DiskDriveScreen.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/DiskDriveScreen.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage2.platform.common.screen; -import com.refinedmods.refinedstorage2.platform.common.containermenu.diskdrive.DiskDriveContainerMenu; +import com.refinedmods.refinedstorage2.platform.common.containermenu.storage.diskdrive.DiskDriveContainerMenu; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/StorageBlockScreen.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/StorageBlockScreen.java index 4e36630b4..14d62c993 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/StorageBlockScreen.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/StorageBlockScreen.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage2.platform.common.screen; -import com.refinedmods.refinedstorage2.platform.common.containermenu.storage.StorageContainerMenu; +import com.refinedmods.refinedstorage2.platform.common.containermenu.storage.block.StorageBlockContainerMenu; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; @@ -10,10 +10,10 @@ import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createIdentifier; -public class StorageBlockScreen extends StorageScreen> { +public class StorageBlockScreen extends StorageScreen> { private static final ResourceLocation TEXTURE = createIdentifier("textures/gui/storage.png"); - public StorageBlockScreen(StorageContainerMenu menu, Inventory inventory, Component title) { + public StorageBlockScreen(StorageBlockContainerMenu menu, Inventory inventory, Component title) { super(menu, inventory, title, 80); } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/StorageScreen.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/StorageScreen.java index 0c9e34460..34b9aebb6 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/StorageScreen.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/StorageScreen.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.platform.common.screen; import com.refinedmods.refinedstorage2.api.core.QuantityFormatter; -import com.refinedmods.refinedstorage2.platform.common.containermenu.StorageAccessor; +import com.refinedmods.refinedstorage2.platform.common.containermenu.storage.StorageAccessor; import com.refinedmods.refinedstorage2.platform.common.screen.widget.AccessModeSideButtonWidget; import com.refinedmods.refinedstorage2.platform.common.screen.widget.ExactModeSideButtonWidget; import com.refinedmods.refinedstorage2.platform.common.screen.widget.FilterModeSideButtonWidget; diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/ModInitializerImpl.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/ModInitializerImpl.java index 845042bf3..bcaea983e 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/ModInitializerImpl.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/ModInitializerImpl.java @@ -19,10 +19,10 @@ import com.refinedmods.refinedstorage2.platform.common.block.entity.grid.ItemGridBlockEntity; import com.refinedmods.refinedstorage2.platform.common.block.entity.storage.ItemStorageBlockEntity; import com.refinedmods.refinedstorage2.platform.common.containermenu.ControllerContainerMenu; -import com.refinedmods.refinedstorage2.platform.common.containermenu.diskdrive.DiskDriveContainerMenu; import com.refinedmods.refinedstorage2.platform.common.containermenu.grid.FluidGridContainerMenu; import com.refinedmods.refinedstorage2.platform.common.containermenu.grid.ItemGridContainerMenu; -import com.refinedmods.refinedstorage2.platform.common.containermenu.storage.ItemStorageContainerMenu; +import com.refinedmods.refinedstorage2.platform.common.containermenu.storage.block.ItemStorageBlockContainerMenu; +import com.refinedmods.refinedstorage2.platform.common.containermenu.storage.diskdrive.DiskDriveContainerMenu; import com.refinedmods.refinedstorage2.platform.common.content.BlockEntities; import com.refinedmods.refinedstorage2.platform.common.content.Blocks; import com.refinedmods.refinedstorage2.platform.common.content.Items; @@ -235,7 +235,7 @@ private void registerMenus() { Menus.INSTANCE.setGrid(ScreenHandlerRegistry.registerExtended(GRID, ItemGridContainerMenu::new)); Menus.INSTANCE.setFluidGrid(ScreenHandlerRegistry.registerExtended(FLUID_GRID, FluidGridContainerMenu::new)); Menus.INSTANCE.setController(ScreenHandlerRegistry.registerExtended(CONTROLLER, ControllerContainerMenu::new)); - Menus.INSTANCE.setItemStorage(ScreenHandlerRegistry.registerExtended(createIdentifier("item_storage"), ItemStorageContainerMenu::new)); + Menus.INSTANCE.setItemStorage(ScreenHandlerRegistry.registerExtended(createIdentifier("item_storage"), ItemStorageBlockContainerMenu::new)); } private void registerLootFunctions() { diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/ModInitializer.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/ModInitializer.java index 2af6bbfa5..a8751565f 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/ModInitializer.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/ModInitializer.java @@ -18,10 +18,10 @@ import com.refinedmods.refinedstorage2.platform.common.block.entity.grid.ItemGridBlockEntity; import com.refinedmods.refinedstorage2.platform.common.block.entity.storage.ItemStorageBlockEntity; import com.refinedmods.refinedstorage2.platform.common.containermenu.ControllerContainerMenu; -import com.refinedmods.refinedstorage2.platform.common.containermenu.diskdrive.DiskDriveContainerMenu; import com.refinedmods.refinedstorage2.platform.common.containermenu.grid.FluidGridContainerMenu; import com.refinedmods.refinedstorage2.platform.common.containermenu.grid.ItemGridContainerMenu; -import com.refinedmods.refinedstorage2.platform.common.containermenu.storage.ItemStorageContainerMenu; +import com.refinedmods.refinedstorage2.platform.common.containermenu.storage.block.ItemStorageBlockContainerMenu; +import com.refinedmods.refinedstorage2.platform.common.containermenu.storage.diskdrive.DiskDriveContainerMenu; import com.refinedmods.refinedstorage2.platform.common.content.BlockEntities; import com.refinedmods.refinedstorage2.platform.common.content.Blocks; import com.refinedmods.refinedstorage2.platform.common.content.Items; @@ -370,7 +370,7 @@ public void registerMenus(RegistryEvent.Register> e) { e.getRegistry().register(fluidGridMenuType); Menus.INSTANCE.setFluidGrid(fluidGridMenuType); - MenuType storageMenuType = IForgeMenuType.create(ItemStorageContainerMenu::new); + MenuType storageMenuType = IForgeMenuType.create(ItemStorageBlockContainerMenu::new); storageMenuType.setRegistryName(createIdentifier("storage")); e.getRegistry().register(storageMenuType); Menus.INSTANCE.setItemStorage(storageMenuType);