diff --git a/.gitignore b/.gitignore index 924b02b7b..ae1892911 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,8 @@ eclipse/ *.ipr *.iws .idea/ +!.idea/dictionaries/refinedstorage2.xml +!.idea/icon.png out/ /bin/ logs/ diff --git a/.idea/dictionaries/refinedstorage2.xml b/.idea/dictionaries/refinedstorage2.xml new file mode 100644 index 000000000..358caf40a --- /dev/null +++ b/.idea/dictionaries/refinedstorage2.xml @@ -0,0 +1,8 @@ + + + + autocrafting + redstone + + + \ No newline at end of file diff --git a/.idea/icon.png b/.idea/icon.png new file mode 100644 index 000000000..242164c12 Binary files /dev/null and b/.idea/icon.png differ diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f90e9936..9c12c5019 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - The binding of a Security Card can now be cleared. - The Security Card tooltip and GUI now show whether the permission has been touched/changed in any way. - A global (fallback) permission set for a network can be defined using the Fallback Security Card instead of using an "unbound" Security Card. +- Smooth scrolling, screen size and max row stretch are no longer Grid-specific settings, but are now global settings. ### Fixed diff --git a/refinedstorage2-grid-api/src/main/java/com/refinedmods/refinedstorage2/api/grid/watcher/GridWatcherManagerImpl.java b/refinedstorage2-grid-api/src/main/java/com/refinedmods/refinedstorage2/api/grid/watcher/GridWatcherManagerImpl.java index c86437cab..a5b85402f 100644 --- a/refinedstorage2-grid-api/src/main/java/com/refinedmods/refinedstorage2/api/grid/watcher/GridWatcherManagerImpl.java +++ b/refinedstorage2-grid-api/src/main/java/com/refinedmods/refinedstorage2/api/grid/watcher/GridWatcherManagerImpl.java @@ -31,7 +31,7 @@ public void addWatcher( attach(registration, storageChannel, false); } watchers.put(watcher, registration); - LOGGER.info("Added watcher {}, new count is {}", watcher, watchers.size()); + LOGGER.debug("Added watcher {}, new count is {}", watcher, watchers.size()); } @Override @@ -57,7 +57,7 @@ private void attach( final StorageChannel storageChannel, final boolean replay ) { - LOGGER.info("Attaching {} to {}", registration, storageChannel); + LOGGER.debug("Attaching {} to {}", registration, storageChannel); registration.attach(storageChannel, replay); } @@ -71,17 +71,17 @@ public void removeWatcher(final GridWatcher watcher, @Nullable final StorageChan detach(registration, storageChannel); } watchers.remove(watcher); - LOGGER.info("Removed watcher {}, remaining {}", watcher, watchers.size()); + LOGGER.debug("Removed watcher {}, remaining {}", watcher, watchers.size()); } @Override public void detachAll(final StorageChannel storageChannel) { - LOGGER.info("Detaching {} watchers", watchers.size()); + LOGGER.debug("Detaching {} watchers", watchers.size()); watchers.values().forEach(watcher -> detach(watcher, storageChannel)); } private void detach(final GridWatcherRegistration registration, final StorageChannel storageChannel) { - LOGGER.info("Detaching {} from {}", registration, storageChannel); + LOGGER.debug("Detaching {} from {}", registration, storageChannel); registration.detach(storageChannel); } diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/registry/PlatformRegistry.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/registry/PlatformRegistry.java index 1e179ce6e..29a490e35 100644 --- a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/registry/PlatformRegistry.java +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/registry/PlatformRegistry.java @@ -21,11 +21,6 @@ public interface PlatformRegistry { */ void register(ResourceLocation id, T value); - /** - * @return whether if there is any other value, ignoring any default value - */ - boolean isEmpty(); - /** * @param value the value * @return the id of the value, if present @@ -38,11 +33,6 @@ public interface PlatformRegistry { */ Optional get(ResourceLocation id); - /** - * @return the default value - */ - T getDefault(); - /** * @return an unmodifiable list of all values */ @@ -50,16 +40,7 @@ public interface PlatformRegistry { /** * Returns the next value in the ordered list. - * If the value is not found, it will return the default value. - * - * @param value the given value - * @return the next value after the given value - */ - T next(T value); - - /** - * Returns the next value in the ordered list. - * If the value is not found, it will the default value. + * If the value is not found, it will return the first value. * If the value is the last value in the ordered list, it will return null. * * @param value the given value diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/AbstractClientModInitializer.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/AbstractClientModInitializer.java index 8c24202b4..b708c7a0b 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/AbstractClientModInitializer.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/AbstractClientModInitializer.java @@ -10,6 +10,7 @@ import com.refinedmods.refinedstorage2.platform.common.detector.DetectorScreen; import com.refinedmods.refinedstorage2.platform.common.exporter.ExporterScreen; import com.refinedmods.refinedstorage2.platform.common.grid.GridContainerMenu; +import com.refinedmods.refinedstorage2.platform.common.grid.NoopGridSynchronizer; import com.refinedmods.refinedstorage2.platform.common.grid.WirelessGridContainerMenu; import com.refinedmods.refinedstorage2.platform.common.grid.screen.CraftingGridScreen; import com.refinedmods.refinedstorage2.platform.common.grid.screen.GridScreen; @@ -48,6 +49,13 @@ import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createIdentifier; public abstract class AbstractClientModInitializer { + protected static void registerBaseGridSynchronizer() { + PlatformApi.INSTANCE.getGridSynchronizerRegistry().register( + createIdentifier("off"), + NoopGridSynchronizer.INSTANCE + ); + } + protected static void registerScreens(final ScreenRegistration registration) { registration.register(Menus.INSTANCE.getDiskDrive(), DiskDriveScreen::new); registration.register(Menus.INSTANCE.getGrid(), GridScreen::new); 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 e1d95c1a6..b5b1db776 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 @@ -43,7 +43,6 @@ import com.refinedmods.refinedstorage2.platform.common.grid.GridBlockEntity; import com.refinedmods.refinedstorage2.platform.common.grid.GridContainerMenu; import com.refinedmods.refinedstorage2.platform.common.grid.WirelessGridContainerMenu; -import com.refinedmods.refinedstorage2.platform.common.grid.WirelessGridItem; import com.refinedmods.refinedstorage2.platform.common.iface.InterfaceBlock; import com.refinedmods.refinedstorage2.platform.common.iface.InterfaceBlockEntity; import com.refinedmods.refinedstorage2.platform.common.iface.InterfaceContainerMenu; @@ -57,9 +56,7 @@ import com.refinedmods.refinedstorage2.platform.common.networking.NetworkTransmitterContainerMenu; import com.refinedmods.refinedstorage2.platform.common.security.BuiltinPermission; import com.refinedmods.refinedstorage2.platform.common.security.FallbackSecurityCardContainerMenu; -import com.refinedmods.refinedstorage2.platform.common.security.FallbackSecurityCardItem; import com.refinedmods.refinedstorage2.platform.common.security.SecurityCardContainerMenu; -import com.refinedmods.refinedstorage2.platform.common.security.SecurityCardItem; import com.refinedmods.refinedstorage2.platform.common.storage.FluidStorageType; import com.refinedmods.refinedstorage2.platform.common.storage.ItemStorageType; import com.refinedmods.refinedstorage2.platform.common.storage.StorageTypes; @@ -71,7 +68,6 @@ import com.refinedmods.refinedstorage2.platform.common.storage.portablegrid.AbstractPortableGridBlockEntity; import com.refinedmods.refinedstorage2.platform.common.storage.portablegrid.PortableGridBlock; import com.refinedmods.refinedstorage2.platform.common.storage.portablegrid.PortableGridBlockContainerMenu; -import com.refinedmods.refinedstorage2.platform.common.storage.portablegrid.PortableGridBlockItem; import com.refinedmods.refinedstorage2.platform.common.storage.portablegrid.PortableGridItemContainerMenu; import com.refinedmods.refinedstorage2.platform.common.storage.portablegrid.PortableGridLootItemFunction; import com.refinedmods.refinedstorage2.platform.common.storage.portablegrid.PortableGridType; @@ -98,6 +94,7 @@ import com.refinedmods.refinedstorage2.platform.common.support.SimpleItem; import com.refinedmods.refinedstorage2.platform.common.support.energy.EnergyLootItemFunction; import com.refinedmods.refinedstorage2.platform.common.support.network.NetworkNodeContainerBlockEntityImpl; +import com.refinedmods.refinedstorage2.platform.common.support.network.bounditem.InventorySlotReferenceFactory; import com.refinedmods.refinedstorage2.platform.common.support.network.component.PlatformStorageNetworkComponent; import com.refinedmods.refinedstorage2.platform.common.support.resource.FluidResourceFactory; import com.refinedmods.refinedstorage2.platform.common.support.resource.ResourceTypes; @@ -136,7 +133,6 @@ import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.CRAFTING_GRID; import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.CREATIVE_CONTROLLER; import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.CREATIVE_PORTABLE_GRID; -import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.CREATIVE_WIRELESS_GRID; import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.DESTRUCTION_CORE; import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.DESTRUCTOR; import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.DETECTOR; @@ -175,12 +171,13 @@ import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createIdentifier; public abstract class AbstractModInitializer { + private static final String ITEM_REGISTRY_KEY = "item"; private static final String FLUID_REGISTRY_KEY = "fluid"; protected final void initializePlatformApi() { ((PlatformApiProxy) PlatformApi.INSTANCE).setDelegate(new PlatformApiImpl()); - registerAdditionalStorageTypes(); - registerAdditionalResourceTypes(); + registerStorageTypes(); + registerResourceTypes(); registerAdditionalResourceFactories(); registerDestructorStrategyFactories(); registerConstructorStrategyFactories(); @@ -189,16 +186,25 @@ protected final void initializePlatformApi() { registerNetworkComponents(); registerWirelessTransmitterRangeModifiers(); registerPermissions(); + registerSlotReferenceProviders(); } - private void registerAdditionalStorageTypes() { + private void registerStorageTypes() { + PlatformApi.INSTANCE.getStorageTypeRegistry().register( + createIdentifier(ITEM_REGISTRY_KEY), + StorageTypes.ITEM + ); PlatformApi.INSTANCE.getStorageTypeRegistry().register( createIdentifier(FLUID_REGISTRY_KEY), StorageTypes.FLUID ); } - private void registerAdditionalResourceTypes() { + private void registerResourceTypes() { + PlatformApi.INSTANCE.getResourceTypeRegistry().register( + createIdentifier(ITEM_REGISTRY_KEY), + ResourceTypes.ITEM + ); PlatformApi.INSTANCE.getResourceTypeRegistry().register( createIdentifier(FLUID_REGISTRY_KEY), ResourceTypes.FLUID @@ -260,9 +266,6 @@ private void registerWirelessTransmitterRangeModifiers() { private void registerPermissions() { for (final BuiltinPermission permission : BuiltinPermission.values()) { - if (permission == BuiltinPermission.SECURITY) { - continue; - } PlatformApi.INSTANCE.getPermissionRegistry().register(permission.getId(), permission); } } @@ -316,16 +319,7 @@ protected final void registerBlocks( ))); } - protected final void registerItems( - final RegistryCallback callback, - final Supplier regulatorUpgradeItemSupplier, - final Supplier wirelessGridItemSupplier, - final Supplier creativeWirelessGridItemSupplier, - final Supplier portableGridBlockItemSupplier, - final Supplier creativePortableGridBlockItemSupplier, - final Supplier securityCardItemSupplier, - final Supplier fallbackSecurityCardItemSupplier - ) { + protected final void registerItems(final RegistryCallback callback) { registerSimpleItems(callback); Blocks.INSTANCE.getGrid().registerItems(callback); Blocks.INSTANCE.getCraftingGrid().registerItems(callback); @@ -342,23 +336,7 @@ protected final void registerItems( Blocks.INSTANCE.getNetworkReceiver().registerItems(callback, Items.INSTANCE::addNetworkReceiver); Blocks.INSTANCE.getNetworkTransmitter().registerItems(callback, Items.INSTANCE::addNetworkTransmitter); registerStorageItems(callback); - registerUpgrades(callback, regulatorUpgradeItemSupplier); - Items.INSTANCE.setWirelessGrid(callback.register(WIRELESS_GRID, wirelessGridItemSupplier)); - Items.INSTANCE.setCreativeWirelessGrid(callback.register( - CREATIVE_WIRELESS_GRID, - creativeWirelessGridItemSupplier - )); - callback.register(STORAGE_MONITOR, () -> new SimpleBlockItem(Blocks.INSTANCE.getStorageMonitor())); - Items.INSTANCE.setPortableGrid(callback.register(PORTABLE_GRID, portableGridBlockItemSupplier)); - Items.INSTANCE.setCreativePortableGrid(callback.register( - CREATIVE_PORTABLE_GRID, - creativePortableGridBlockItemSupplier - )); - Items.INSTANCE.setSecurityCard(callback.register(SECURITY_CARD, securityCardItemSupplier)); - Items.INSTANCE.setFallbackSecurityCard(callback.register( - FALLBACK_SECURITY_CARD, - fallbackSecurityCardItemSupplier - )); + registerUpgrades(callback); } private void registerSimpleItems(final RegistryCallback callback) { @@ -373,6 +351,7 @@ private void registerSimpleItems(final RegistryCallback callback) { Items.INSTANCE.setWrench(callback.register(WRENCH, WrenchItem::new)); Items.INSTANCE.setStorageHousing(callback.register(STORAGE_HOUSING, SimpleItem::new)); callback.register(MACHINE_CASING, () -> new SimpleBlockItem(Blocks.INSTANCE.getMachineCasing())); + callback.register(STORAGE_MONITOR, () -> new SimpleBlockItem(Blocks.INSTANCE.getStorageMonitor())); callback.register(INTERFACE, () -> Blocks.INSTANCE.getInterface().createBlockItem()); Items.INSTANCE.setConstructionCore(callback.register(CONSTRUCTION_CORE, SimpleItem::new)); Items.INSTANCE.setDestructionCore(callback.register(DESTRUCTION_CORE, SimpleItem::new)); @@ -435,10 +414,7 @@ private void registerFluidStorageItems(final RegistryCallback callback, ); } - private void registerUpgrades( - final RegistryCallback callback, - final Supplier regulatorUpgradeItemSupplier - ) { + private void registerUpgrades(final RegistryCallback callback) { Items.INSTANCE.setUpgrade(callback.register( ContentIds.UPGRADE, SimpleItem::new @@ -485,10 +461,6 @@ private void registerUpgrades( ) ); Items.INSTANCE.setSilkTouchUpgrade(silkTouchUpgrade); - Items.INSTANCE.setRegulatorUpgrade(callback.register( - ContentIds.REGULATOR_UPGRADE, - regulatorUpgradeItemSupplier - )); Items.INSTANCE.setRangeUpgrade(callback.register( ContentIds.RANGE_UPGRADE, () -> new RangeUpgradeItem(PlatformApi.INSTANCE.getUpgradeRegistry(), false) @@ -774,6 +746,13 @@ protected final void registerRecipeSerializers(final RegistryCallback networkComponentMapFactory = new ComponentMapFactory<>(); private final NetworkBuilder networkBuilder = new NetworkBuilderImpl(new NetworkFactory(networkComponentMapFactory)); - private final PlatformRegistry storageTypeRegistry = - new PlatformRegistryImpl<>(createIdentifier(ITEM_REGISTRY_KEY), StorageTypes.ITEM); - private final PlatformRegistry resourceTypeRegistry = - new PlatformRegistryImpl<>(createIdentifier(ITEM_REGISTRY_KEY), ResourceTypes.ITEM); - private final PlatformRegistry gridSynchronizerRegistry = - new PlatformRegistryImpl<>(createIdentifier("off"), new NoopGridSynchronizer()); + private final PlatformRegistry storageTypeRegistry = new PlatformRegistryImpl<>(); + private final PlatformRegistry resourceTypeRegistry = new PlatformRegistryImpl<>(); + private final PlatformRegistry gridSynchronizerRegistry = new PlatformRegistryImpl<>(); private final PlatformRegistry importerTransferStrategyRegistry = - new PlatformRegistryImpl<>(createIdentifier("noop"), - (level, pos, direction, upgradeState, amountOverride) -> (filter, actor, network) -> false); + new PlatformRegistryImpl<>(); private final PlatformRegistry exporterTransferStrategyRegistry = - new PlatformRegistryImpl<>(createIdentifier("noop"), - (level, pos, direction, upgradeState, amountOverride, fuzzyMode) -> (resource, actor, network) -> false); + new PlatformRegistryImpl<>(); private final UpgradeRegistry upgradeRegistry = new UpgradeRegistryImpl(); private final BuiltinUpgradeDestinations builtinUpgradeDestinations = new BuiltinUpgradeDestinationsImpl(); private final Queue externalStorageProviderFactories = new PriorityQueue<>( @@ -160,15 +148,9 @@ public class PlatformApiImpl implements PlatformApi { new CompositeWirelessTransmitterRangeModifier(); private final EnergyItemHelper energyItemHelper = new EnergyItemHelperImpl(); private final NetworkBoundItemHelper networkBoundItemHelper = new NetworkBoundItemHelperImpl(); - private final PlatformRegistry slotReferenceFactoryRegistry = new PlatformRegistryImpl<>( - createIdentifier("inventory"), - InventorySlotReferenceFactory.INSTANCE - ); + private final PlatformRegistry slotReferenceFactoryRegistry = new PlatformRegistryImpl<>(); private final CompositeSlotReferenceProvider slotReferenceProvider = new CompositeSlotReferenceProvider(); - private final PlatformRegistry permissionRegistry = new PlatformRegistryImpl<>( - BuiltinPermission.SECURITY.getId(), - BuiltinPermission.SECURITY - ); + private final PlatformRegistry permissionRegistry = new PlatformRegistryImpl<>(); @Override public PlatformRegistry getStorageTypeRegistry() { diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/ContentNames.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/ContentNames.java index 06afd3e37..7cfa030b9 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/ContentNames.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/ContentNames.java @@ -1,11 +1,14 @@ package com.refinedmods.refinedstorage2.platform.common.content; +import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; +import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.MOD_ID; import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; public final class ContentNames { - public static final MutableComponent MOD = createTranslation("itemGroup", "general"); + public static final String MOD_TRANSLATION_KEY = "mod." + MOD_ID; + public static final MutableComponent MOD = Component.translatable(MOD_TRANSLATION_KEY); public static final MutableComponent CABLE = name("cable"); public static final MutableComponent GRID = name("grid"); public static final MutableComponent CRAFTING_GRID = name("crafting_grid"); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/AbstractGridContainerMenu.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/AbstractGridContainerMenu.java index 0ca32b10f..589653507 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/AbstractGridContainerMenu.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/AbstractGridContainerMenu.java @@ -33,6 +33,7 @@ import com.refinedmods.refinedstorage2.platform.common.grid.strategy.ClientGridScrollingStrategy; import com.refinedmods.refinedstorage2.platform.common.grid.view.CompositeGridResourceFactory; import com.refinedmods.refinedstorage2.platform.common.support.AbstractBaseContainerMenu; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ResourceTypes; import com.refinedmods.refinedstorage2.platform.common.support.stretching.ScreenSizeListener; import com.refinedmods.refinedstorage2.platform.common.util.PacketUtil; import com.refinedmods.refinedstorage2.query.lexer.LexerTokenMappings; @@ -140,7 +141,7 @@ protected AbstractGridContainerMenu( this.grid = grid; this.grid.addWatcher(this, PlayerActor.class); - this.synchronizer = PlatformApi.INSTANCE.getGridSynchronizerRegistry().getDefault(); + this.synchronizer = NoopGridSynchronizer.INSTANCE; initStrategies(); } @@ -235,7 +236,7 @@ public void removed(final Player playerEntity) { } @Override - public void initSlots(final int playerInventoryY) { + public void onScreenReady(final int playerInventoryY) { resetSlots(); addPlayerInventory(playerInventory, 8, playerInventoryY); } @@ -261,7 +262,7 @@ public void onChanged( if (!(resource instanceof PlatformResourceKey platformResource)) { return; } - LOGGER.info("{} received a change of {} for {}", this, change, resource); + LOGGER.debug("{} received a change of {} for {}", this, change, resource); Platform.INSTANCE.getServerToClientCommunications().sendGridUpdate( (ServerPlayer) playerInventory.player, platformResource, @@ -322,7 +323,7 @@ private GridSynchronizer loadSynchronizer() { .getGrid() .getSynchronizer() .flatMap(id -> PlatformApi.INSTANCE.getGridSynchronizerRegistry().get(id)) - .orElse(PlatformApi.INSTANCE.getGridSynchronizerRegistry().getDefault()); + .orElse(NoopGridSynchronizer.INSTANCE); } @Nullable @@ -347,20 +348,20 @@ public ResourceType getResourceType() { public void toggleSynchronizer() { final PlatformRegistry registry = PlatformApi.INSTANCE.getGridSynchronizerRegistry(); final Config.GridEntry config = Platform.INSTANCE.getConfig().getGrid(); - final GridSynchronizer newSynchronizer = registry.next(getSynchronizer()); - if (newSynchronizer == registry.getDefault()) { + final GridSynchronizer newSynchronizer = registry.nextOrNullIfLast(getSynchronizer()); + if (newSynchronizer == null) { config.clearSynchronizer(); } else { registry.getId(newSynchronizer).ifPresent(config::setSynchronizer); } - this.synchronizer = newSynchronizer; + this.synchronizer = newSynchronizer == null ? NoopGridSynchronizer.INSTANCE : newSynchronizer; } public void toggleResourceType() { final PlatformRegistry registry = PlatformApi.INSTANCE.getResourceTypeRegistry(); final Config.GridEntry config = Platform.INSTANCE.getConfig().getGrid(); final ResourceType newResourceType = resourceTypeFilter == null - ? registry.getDefault() + ? ResourceTypes.ITEM : registry.nextOrNullIfLast(resourceTypeFilter); if (newResourceType == null) { config.clearResourceType(); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/CraftingGridContainerMenu.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/CraftingGridContainerMenu.java index 4ef029e92..4ce75a353 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/CraftingGridContainerMenu.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/CraftingGridContainerMenu.java @@ -41,7 +41,7 @@ public CraftingGridContainerMenu(final int syncId, final Inventory playerInvento super(Menus.INSTANCE.getCraftingGrid(), syncId, playerInventory, buf); this.source = new ClientCraftingGridSource(); this.player = playerInventory.player; - initSlots(0); + onScreenReady(0); registerProperty(new ClientProperty<>(PropertyTypes.REDSTONE_MODE, RedstoneMode.IGNORE)); } @@ -51,7 +51,7 @@ public CraftingGridContainerMenu(final int syncId, final Inventory playerInvento super(Menus.INSTANCE.getCraftingGrid(), syncId, playerInventory, grid); this.source = new CraftingGridSourceImpl(grid); this.player = playerInventory.player; - initSlots(0); + onScreenReady(0); registerProperty(new ServerProperty<>( PropertyTypes.REDSTONE_MODE, grid::getRedstoneMode, @@ -88,8 +88,8 @@ public ItemStack quickMoveStack(final Player actor, final int slotIndex) { } @Override - public void initSlots(final int playerInventoryY) { - super.initSlots(playerInventoryY); + public void onScreenReady(final int playerInventoryY) { + super.onScreenReady(playerInventoryY); craftingMatrixSlots.clear(); for (int y = 0; y < 3; ++y) { for (int x = 0; x < 3; ++x) { diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/GridContainerMenu.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/GridContainerMenu.java index d3ce3af2e..58270e006 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/GridContainerMenu.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/GridContainerMenu.java @@ -12,13 +12,13 @@ public class GridContainerMenu extends AbstractGridContainerMenu { public GridContainerMenu(final int syncId, final Inventory playerInventory, final FriendlyByteBuf buf) { super(Menus.INSTANCE.getGrid(), syncId, playerInventory, buf); - initSlots(0); + onScreenReady(0); registerProperty(new ClientProperty<>(PropertyTypes.REDSTONE_MODE, RedstoneMode.IGNORE)); } GridContainerMenu(final int syncId, final Inventory playerInventory, final GridBlockEntity grid) { super(Menus.INSTANCE.getGrid(), syncId, playerInventory, grid); - initSlots(0); + onScreenReady(0); registerProperty(new ServerProperty<>( PropertyTypes.REDSTONE_MODE, grid::getRedstoneMode, diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/NoopGridSynchronizer.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/NoopGridSynchronizer.java index 825f31698..e69cd08ff 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/NoopGridSynchronizer.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/NoopGridSynchronizer.java @@ -8,9 +8,14 @@ import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; public class NoopGridSynchronizer extends AbstractGridSynchronizer { + public static final NoopGridSynchronizer INSTANCE = new NoopGridSynchronizer(); + private static final MutableComponent TITLE = createTranslation("gui", "grid.synchronizer.off"); private static final Component HELP = createTranslation("gui", "grid.synchronizer.off.help"); + private NoopGridSynchronizer() { + } + @Override public MutableComponent getTitle() { return TITLE; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/WirelessGridContainerMenu.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/WirelessGridContainerMenu.java index 33ccc6987..9803393a5 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/WirelessGridContainerMenu.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/WirelessGridContainerMenu.java @@ -12,7 +12,7 @@ public class WirelessGridContainerMenu extends AbstractGridContainerMenu { public WirelessGridContainerMenu(final int syncId, final Inventory playerInventory, final FriendlyByteBuf buf) { super(Menus.INSTANCE.getWirelessGrid(), syncId, playerInventory, buf); this.disabledSlot = PlatformApi.INSTANCE.getSlotReference(buf).orElse(null); - initSlots(0); + onScreenReady(0); } WirelessGridContainerMenu(final int syncId, @@ -21,6 +21,6 @@ public WirelessGridContainerMenu(final int syncId, final Inventory playerInvento final SlotReference slotReference) { super(Menus.INSTANCE.getWirelessGrid(), syncId, playerInventory, grid); this.disabledSlot = slotReference; - initSlots(0); + onScreenReady(0); } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/screen/AbstractGridScreen.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/screen/AbstractGridScreen.java index dd20dde26..65910f8ac 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/screen/AbstractGridScreen.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/screen/AbstractGridScreen.java @@ -7,12 +7,11 @@ import com.refinedmods.refinedstorage2.api.storage.tracked.TrackedResource; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; import com.refinedmods.refinedstorage2.platform.api.grid.GridScrollMode; -import com.refinedmods.refinedstorage2.platform.api.grid.GridSynchronizer; import com.refinedmods.refinedstorage2.platform.api.grid.view.PlatformGridResource; -import com.refinedmods.refinedstorage2.platform.api.support.registry.PlatformRegistry; import com.refinedmods.refinedstorage2.platform.api.support.resource.PlatformResourceKey; import com.refinedmods.refinedstorage2.platform.common.Platform; import com.refinedmods.refinedstorage2.platform.common.grid.AbstractGridContainerMenu; +import com.refinedmods.refinedstorage2.platform.common.grid.NoopGridSynchronizer; import com.refinedmods.refinedstorage2.platform.common.grid.view.ItemGridResource; import com.refinedmods.refinedstorage2.platform.common.support.containermenu.DisabledSlot; import com.refinedmods.refinedstorage2.platform.common.support.containermenu.PropertyTypes; @@ -102,8 +101,11 @@ protected void init(final int rows) { addSideButton(new AutoSelectedSideButtonWidget(getMenu())); addSideButton(new ResourceTypeSideButtonWidget(getMenu())); - final PlatformRegistry synchronizers = PlatformApi.INSTANCE.getGridSynchronizerRegistry(); - if (!synchronizers.isEmpty()) { + final boolean onlyHasNoopSynchronizer = PlatformApi.INSTANCE.getGridSynchronizerRegistry() + .getAll() + .stream() + .allMatch(synchronizer -> synchronizer == NoopGridSynchronizer.INSTANCE); + if (!onlyHasNoopSynchronizer) { addSideButton(new SynchronizationSideButtonWidget(getMenu())); searchField.addListener(this::trySynchronizeFromGrid); } @@ -176,25 +178,23 @@ protected void renderRows(final GuiGraphics graphics, final int mouseY) { currentGridSlotIndex = -1; for (int row = 0; row < Math.max(totalRows, rows); ++row) { - renderRow(graphics, mouseX, mouseY, x, y, topHeight, row, rows); + final int rowX = x + 7; + final int rowY = y + topHeight + (row * ROW_SIZE) - getScrollbarOffset(); + final boolean isOutOfFrame = (rowY < y + topHeight - ROW_SIZE) + || (rowY > y + topHeight + (ROW_SIZE * rows)); + if (isOutOfFrame) { + continue; + } + renderRow(graphics, mouseX, mouseY, rowX, rowY, row); } } private void renderRow(final GuiGraphics graphics, final int mouseX, final int mouseY, - final int x, - final int y, - final int topHeight, - final int row, - final int visibleRows) { - final int rowX = x + 7; - final int rowY = y + topHeight + (row * ROW_SIZE) - getScrollbarOffset(); - final boolean isOutOfFrame = (rowY < y + topHeight - ROW_SIZE) - || (rowY > y + topHeight + (ROW_SIZE * visibleRows)); - if (isOutOfFrame) { - return; - } + final int rowX, + final int rowY, + final int row) { graphics.blit(getTexture(), rowX, rowY, 0, 238, 162, ROW_SIZE); for (int column = 0; column < COLUMNS; ++column) { renderCell(graphics, mouseX, mouseY, rowX, rowY, (row * COLUMNS) + column, column); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/NetworkTransmitterBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/NetworkTransmitterBlockEntity.java index 295f425cd..45fd2e0aa 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/NetworkTransmitterBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/NetworkTransmitterBlockEntity.java @@ -67,7 +67,7 @@ public NetworkTransmitterBlockEntity(final BlockPos pos, final BlockState state) setChanged(); updateReceiverLocation(); if (level != null) { - LOGGER.info("Network card was changed at {}, sending network update", worldPosition); + LOGGER.debug("Network card was changed at {}, sending network update", worldPosition); PlatformApi.INSTANCE.requestNetworkNodeUpdate(this, level); } }); @@ -86,7 +86,7 @@ public void updateStateInLevel(final BlockState state) { final NetworkTransmitterState currentState = state.getValue(NetworkTransmitterBlock.STATE); final NetworkTransmitterState newState = getState(); if (currentState != newState && level != null && stateChangeRateLimiter.tryAcquire()) { - LOGGER.info("Updating network transmitter at {} from {} to {}", worldPosition, currentState, newState); + LOGGER.debug("Updating network transmitter at {} from {} to {}", worldPosition, currentState, newState); level.setBlockAndUpdate(worldPosition, state.setValue(NetworkTransmitterBlock.STATE, newState)); } } @@ -142,7 +142,7 @@ private void tryReconnectingWithReceiver() { if (level == null) { return; } - LOGGER.info( + LOGGER.debug( "Receiver {} was not found in network for transmitter at {}, retrying and sending network update", receiverKey, worldPosition diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/recipemod/jei/RefinedStorageJeiModPlugin.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/recipemod/jei/RefinedStorageJeiModPlugin.java index 767208eb4..5f4657f2f 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/recipemod/jei/RefinedStorageJeiModPlugin.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/recipemod/jei/RefinedStorageJeiModPlugin.java @@ -69,7 +69,7 @@ public static IJeiRuntime getRuntime() { } private void initializePlatform(final IPlatformFluidHelper fluidHelper) { - LOGGER.info("Enabling JEI integration"); + LOGGER.debug("Enabling JEI integration"); registerIngredientConverters(fluidHelper); registerGridSynchronizers(); } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/AbstractSecurityCardContainerMenu.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/AbstractSecurityCardContainerMenu.java index 272153b45..f9127232f 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/AbstractSecurityCardContainerMenu.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/AbstractSecurityCardContainerMenu.java @@ -11,7 +11,6 @@ import java.util.List; import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.inventory.MenuType; @@ -35,10 +34,7 @@ protected AbstractSecurityCardContainerMenu(final MenuType menuType, final boolean allowed = buf.readBoolean(); final boolean dirty = buf.readBoolean(); PlatformApi.INSTANCE.getPermissionRegistry().get(id).ifPresent(permission -> permissions.add(new Permission( - id, - permission.getName(), - permission.getDescription(), - permission.getOwnerName(), + permission, allowed, dirty ))); @@ -59,7 +55,7 @@ List getPermissions() { } @Override - public void initSlots(final int playerInventoryY) { + public void onScreenReady(final int playerInventoryY) { resetSlots(); addPlayerInventory(playerInventory, 8, playerInventoryY); } @@ -78,46 +74,40 @@ private void setPermission(final ResourceLocation permissionId, final boolean al } } - public void resetPermissionServer(final ResourceLocation permissionId) { + public void resetPermission(final ResourceLocation permissionId) { if (disabledSlot == null) { return; } - disabledSlot.resolve(playerInventory.player).ifPresent(stack -> resetPermissionServer(permissionId, stack)); + disabledSlot.resolve(playerInventory.player).ifPresent(stack -> resetPermission(permissionId, stack)); } - private void resetPermissionServer(final ResourceLocation permissionId, final ItemStack stack) { + private void resetPermission(final ResourceLocation permissionId, final ItemStack stack) { if (stack.getItem() instanceof AbstractSecurityCardItem securityCardItem) { final SecurityCardModel model = securityCardItem.createModel(stack); model.resetPermission(permissionId); } } - Permission changePermission(final ResourceLocation permissionId, final boolean selected) { - Platform.INSTANCE.getClientToServerCommunications().sendSecurityCardPermission(permissionId, selected); - return updatePermissionLocally(permissionId, selected, true); - } - - Permission resetPermission(final ResourceLocation permissionId) { - final PlatformPermission permission = PlatformApi.INSTANCE.getPermissionRegistry() - .get(permissionId) - .orElseThrow(); + Permission resetPermission(final PlatformPermission permission) { final boolean allowed = permission.isAllowedByDefault(); - Platform.INSTANCE.getClientToServerCommunications().sendSecurityCardResetPermission(permissionId); - return updatePermissionLocally(permissionId, allowed, false); + Platform.INSTANCE.getClientToServerCommunications().sendSecurityCardResetPermission(permission); + return updatePermissionLocally(permission, allowed, false); + } + + Permission changePermission(final PlatformPermission permission, final boolean selected) { + Platform.INSTANCE.getClientToServerCommunications().sendSecurityCardPermission(permission, selected); + return updatePermissionLocally(permission, selected, true); } - private Permission updatePermissionLocally(final ResourceLocation permissionId, + private Permission updatePermissionLocally(final PlatformPermission permission, final boolean allowed, final boolean dirty) { - final Permission localPermission = permissions.stream().filter(p -> p.id().equals(permissionId)) + final Permission localPermission = permissions.stream().filter(p -> p.platformPermission == permission) .findFirst() .orElseThrow(); final int index = permissions.indexOf(localPermission); final Permission updatedLocalPermission = new Permission( - localPermission.id(), - localPermission.name(), - localPermission.description(), - localPermission.ownerName(), + localPermission.platformPermission, allowed, dirty ); @@ -125,11 +115,6 @@ private Permission updatePermissionLocally(final ResourceLocation permissionId, return updatedLocalPermission; } - record Permission(ResourceLocation id, - Component name, - Component description, - Component ownerName, - boolean allowed, - boolean dirty) { + record Permission(PlatformPermission platformPermission, boolean allowed, boolean dirty) { } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/AbstractSecurityCardItem.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/AbstractSecurityCardItem.java index 4a5f0b17f..509c158b1 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/AbstractSecurityCardItem.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/AbstractSecurityCardItem.java @@ -21,7 +21,7 @@ import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; -abstract class AbstractSecurityCardItem extends Item { +abstract class AbstractSecurityCardItem extends Item { protected AbstractSecurityCardItem(final Properties properties) { super(properties); } @@ -32,15 +32,14 @@ public void appendHoverText(final ItemStack stack, final List lines, final TooltipFlag flag) { super.appendHoverText(stack, level, lines, flag); - final M model = createModel(stack); - if (addTooltip(stack, lines, model)) { + final T model = createModel(stack); + addTooltip(lines, model); + if (model.isActive()) { addPermissions(lines, model); } } - protected boolean addTooltip(final ItemStack stack, final List lines, final M model) { - return true; - } + abstract void addTooltip(List lines, T model); private void addPermissions(final List lines, final SecurityCardModel model) { PlatformApi.INSTANCE.getPermissionRegistry().getAll().forEach(permission -> { @@ -61,13 +60,13 @@ private void addPermissions(final List lines, final SecurityCardModel public InteractionResultHolder use(final Level level, final Player player, final InteractionHand hand) { final ItemStack stack = player.getItemInHand(hand); if (player instanceof ServerPlayer serverPlayer) { - final M model = createModel(stack); - use(hand, serverPlayer, stack, model); + final T model = createModel(stack); + use(hand, serverPlayer, model); } return InteractionResultHolder.consume(stack); } - private void use(final InteractionHand hand, final ServerPlayer player, final ItemStack stack, final M model) { + private void use(final InteractionHand hand, final ServerPlayer player, final T model) { if (player.isCrouching()) { tryClear(player, model); return; @@ -78,15 +77,15 @@ private void use(final InteractionHand hand, final ServerPlayer player, final It )); } - void tryClear(final ServerPlayer player, final M model) { + void tryClear(final ServerPlayer player, final T model) { model.clear(); player.sendSystemMessage(createTranslation("item", "security_card.cleared")); } - abstract M createModel(ItemStack stack); + abstract T createModel(ItemStack stack); abstract AbstractSecurityCardExtendedMenuProvider createMenuProvider( SlotReference slotReference, - M model + T model ); } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/AbstractSecurityCardScreen.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/AbstractSecurityCardScreen.java index cdc1d2760..84d8e2b78 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/AbstractSecurityCardScreen.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/AbstractSecurityCardScreen.java @@ -1,5 +1,6 @@ package com.refinedmods.refinedstorage2.platform.common.security; +import com.refinedmods.refinedstorage2.platform.api.security.PlatformPermission; import com.refinedmods.refinedstorage2.platform.common.support.stretching.AbstractStretchingScreen; import com.refinedmods.refinedstorage2.platform.common.support.widget.CustomCheckboxWidget; @@ -31,7 +32,7 @@ public abstract class AbstractSecurityCardScreen permissions = new ArrayList<>(); - public AbstractSecurityCardScreen(final T menu, final Inventory playerInventory, final Component text) { + protected AbstractSecurityCardScreen(final T menu, final Inventory playerInventory, final Component text) { super(menu, playerInventory, text); this.inventoryLabelY = 97; this.imageWidth = 193; @@ -85,14 +86,18 @@ private void updatePermission(final AbstractSecurityCardContainerMenu.Permission final Button resetButton, final CustomCheckboxWidget checkbox, final boolean allowed) { - updateCheckboxAndResetButton(checkbox, resetButton, menu.changePermission(menuPermission.id(), allowed)); + updateCheckboxAndResetButton(checkbox, resetButton, menu.changePermission( + menuPermission.platformPermission(), + allowed + )); } private Tooltip getPermissionTooltip(final AbstractSecurityCardContainerMenu.Permission menuPermission) { - final MutableComponent ownerName = menuPermission.ownerName().copy().withStyle( + final PlatformPermission permission = menuPermission.platformPermission(); + final MutableComponent ownerName = permission.getOwnerName().copy().withStyle( Style.EMPTY.withItalic(true).withColor(ChatFormatting.GRAY) ); - final MutableComponent tooltip = menuPermission.description().copy().append("\n").append(ownerName); + final MutableComponent tooltip = permission.getDescription().copy().append("\n").append(ownerName); return Tooltip.create(menuPermission.dirty() ? tooltip.append("\n").append(MODIFIED_TITLE) : tooltip); } @@ -112,7 +117,7 @@ private Button createPermissionResetButton(final AbstractSecurityCardContainerMe private void resetPermission(final AbstractSecurityCardContainerMenu.Permission menuPermission, final CustomCheckboxWidget checkbox, final Button resetButton) { - updateCheckboxAndResetButton(checkbox, resetButton, menu.resetPermission(menuPermission.id())); + updateCheckboxAndResetButton(checkbox, resetButton, menu.resetPermission(menuPermission.platformPermission())); } private void updateCheckboxAndResetButton(final CustomCheckboxWidget checkbox, @@ -125,10 +130,11 @@ private void updateCheckboxAndResetButton(final CustomCheckboxWidget checkbox, } private Component getPermissionName(final AbstractSecurityCardContainerMenu.Permission menuPermission) { + final Component name = menuPermission.platformPermission().getName(); if (!menuPermission.dirty()) { - return menuPermission.name(); + return name; } - return menuPermission.name().copy().append(" (*)").setStyle(Style.EMPTY.withItalic(true)); + return name.copy().append(" (*)").setStyle(Style.EMPTY.withItalic(true)); } private int getPermissionY(final int index) { diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/FallbackSecurityCardItem.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/FallbackSecurityCardItem.java index 0fa8b8460..4bdd4a680 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/FallbackSecurityCardItem.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/FallbackSecurityCardItem.java @@ -3,6 +3,7 @@ import com.refinedmods.refinedstorage2.platform.api.support.HelpTooltipComponent; import com.refinedmods.refinedstorage2.platform.api.support.network.bounditem.SlotReference; +import java.util.List; import java.util.Optional; import net.minecraft.network.chat.Component; @@ -19,6 +20,11 @@ public FallbackSecurityCardItem() { super(new Item.Properties().stacksTo(1)); } + @Override + void addTooltip(final List lines, final SecurityCardModel model) { + // no op + } + @Override SecurityCardModel createModel(final ItemStack stack) { return new SecurityCardModel(stack); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/PlayerSecurityCardModel.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/PlayerSecurityCardModel.java index ffc0c8279..606b3ab7b 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/PlayerSecurityCardModel.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/PlayerSecurityCardModel.java @@ -42,7 +42,7 @@ void setBoundPlayer(@Nullable final ServerPlayer player) { @Override boolean isActive() { - return super.isActive() && isActive(stack); + return isActive(stack); } static boolean isActive(final ItemStack stack) { diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardItem.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardItem.java index c10b17af0..3347e5c5a 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardItem.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardItem.java @@ -23,6 +23,20 @@ public SecurityCardItem() { super(new Item.Properties().stacksTo(1)); } + @Override + void addTooltip(final List lines, final PlayerSecurityCardModel model) { + final String boundPlayerName = model.getBoundPlayerName(); + if (boundPlayerName == null) { + lines.add(createTranslation("item", "security_card.unbound").withStyle(ChatFormatting.GRAY)); + return; + } + lines.add(createTranslation( + "item", + "security_card.bound", + Component.literal(boundPlayerName).withStyle(ChatFormatting.YELLOW) + ).withStyle(ChatFormatting.GRAY)); + } + @Override void tryClear(final ServerPlayer player, final PlayerSecurityCardModel model) { if (model.isCleared()) { @@ -41,23 +55,6 @@ private void bind(final ServerPlayer player, final PlayerSecurityCardModel model )); } - @Override - protected boolean addTooltip(final ItemStack stack, - final List lines, - final PlayerSecurityCardModel model) { - final String boundPlayerName = model.getBoundPlayerName(); - if (boundPlayerName == null) { - lines.add(createTranslation("item", "security_card.unbound").withStyle(ChatFormatting.GRAY)); - return false; - } - lines.add(createTranslation( - "item", - "security_card.bound", - Component.literal(boundPlayerName).withStyle(ChatFormatting.YELLOW) - ).withStyle(ChatFormatting.GRAY)); - return true; - } - @Override public Optional getTooltipImage(final ItemStack stack) { return Optional.of(new HelpTooltipComponent(isActive(stack) ? BOUND_HELP : UNBOUND_HELP)); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardModel.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardModel.java index 8b6c09ba0..37d24223d 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardModel.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardModel.java @@ -50,7 +50,7 @@ void resetPermission(final ResourceLocation permissionId) { } boolean isActive() { - return stack.getTag() != null && stack.getTag().contains(TAG_PERMISSIONS); + return true; } boolean isCleared() { diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/portablegrid/AbstractPortableGridContainerMenu.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/portablegrid/AbstractPortableGridContainerMenu.java index 82dc1c709..814003ce2 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/portablegrid/AbstractPortableGridContainerMenu.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/portablegrid/AbstractPortableGridContainerMenu.java @@ -65,8 +65,8 @@ protected boolean canTransferSlot(final Slot slot) { } @Override - public void initSlots(final int playerInventoryY) { - super.initSlots(playerInventoryY); + public void onScreenReady(final int playerInventoryY) { + super.onScreenReady(playerInventoryY); diskSlot = new ValidatedSlot( diskInventory, 0, diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/portablegrid/PortableGridBlockContainerMenu.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/portablegrid/PortableGridBlockContainerMenu.java index 799c8ac19..047058204 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/portablegrid/PortableGridBlockContainerMenu.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/portablegrid/PortableGridBlockContainerMenu.java @@ -15,7 +15,7 @@ public PortableGridBlockContainerMenu(final int syncId, final FriendlyByteBuf buf) { super(Menus.INSTANCE.getPortableGridBlock(), syncId, playerInventory, buf); registerProperty(new ClientProperty<>(PropertyTypes.REDSTONE_MODE, RedstoneMode.IGNORE)); - initSlots(0); + this.onScreenReady(0); } PortableGridBlockContainerMenu(final int syncId, @@ -34,6 +34,6 @@ public PortableGridBlockContainerMenu(final int syncId, portableGrid::getRedstoneMode, portableGrid::setRedstoneMode )); - initSlots(0); + this.onScreenReady(0); } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/portablegrid/PortableGridItemContainerMenu.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/portablegrid/PortableGridItemContainerMenu.java index c6c58ffb2..32388cb79 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/portablegrid/PortableGridItemContainerMenu.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/portablegrid/PortableGridItemContainerMenu.java @@ -16,7 +16,7 @@ public PortableGridItemContainerMenu(final int syncId, final FriendlyByteBuf buf) { super(Menus.INSTANCE.getPortableGridItem(), syncId, playerInventory, buf); this.disabledSlot = PlatformApi.INSTANCE.getSlotReference(buf).orElse(null); - initSlots(0); + this.onScreenReady(0); } PortableGridItemContainerMenu(final int syncId, @@ -34,6 +34,6 @@ public PortableGridItemContainerMenu(final int syncId, energyStorage ); this.disabledSlot = slotReference; - initSlots(0); + this.onScreenReady(0); } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/ClientToServerCommunications.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/ClientToServerCommunications.java index c1d47204b..fd6489b7e 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/ClientToServerCommunications.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/ClientToServerCommunications.java @@ -3,6 +3,7 @@ import com.refinedmods.refinedstorage2.api.grid.operations.GridExtractMode; import com.refinedmods.refinedstorage2.api.grid.operations.GridInsertMode; import com.refinedmods.refinedstorage2.platform.api.grid.GridScrollMode; +import com.refinedmods.refinedstorage2.platform.api.security.PlatformPermission; import com.refinedmods.refinedstorage2.platform.api.support.network.bounditem.SlotReference; import com.refinedmods.refinedstorage2.platform.api.support.resource.PlatformResourceKey; import com.refinedmods.refinedstorage2.platform.common.support.containermenu.PropertyType; @@ -12,8 +13,6 @@ import java.util.UUID; import javax.annotation.Nullable; -import net.minecraft.resources.ResourceLocation; - public interface ClientToServerCommunications { void sendGridExtract(PlatformResourceKey resource, GridExtractMode mode, boolean cursor); @@ -39,9 +38,9 @@ public interface ClientToServerCommunications { void sendUseNetworkBoundItem(SlotReference slotReference); - void sendSecurityCardPermission(ResourceLocation permissionId, boolean allowed); + void sendSecurityCardPermission(PlatformPermission permission, boolean allowed); - void sendSecurityCardResetPermission(ResourceLocation permissionId); + void sendSecurityCardResetPermission(PlatformPermission permission); void sendSecurityCardBoundPlayer(@Nullable UUID playerId); } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/AbstractUpgradeableNetworkNodeContainerBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/AbstractUpgradeableNetworkNodeContainerBlockEntity.java index 3746b213e..69dc02d40 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/AbstractUpgradeableNetworkNodeContainerBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/AbstractUpgradeableNetworkNodeContainerBlockEntity.java @@ -103,7 +103,7 @@ public void load(final CompoundTag tag) { } private void configureAccordingToUpgrades() { - LOGGER.info("Reconfiguring {} for upgrades", getBlockPos()); + LOGGER.debug("Reconfiguring {} for upgrades", getBlockPos()); final int amountOfSpeedUpgrades = upgradeContainer.getAmount(Items.INSTANCE.getSpeedUpgrade()); this.rateLimiter = createRateLimiter(amountOfSpeedUpgrades); this.setEnergyUsage(upgradeContainer.getEnergyUsage()); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/ConnectionProviderImpl.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/ConnectionProviderImpl.java index 7d6f81382..4c0abfa92 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/ConnectionProviderImpl.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/ConnectionProviderImpl.java @@ -40,7 +40,11 @@ public Connections findConnections(final NetworkNodeContainer pivot, .filter(PlatformNetworkNodeContainer.class::isInstance) .map(PlatformNetworkNodeContainer.class::cast) .collect(Collectors.toSet()); - LOGGER.info("Finding connections for pivot {} with {} existing connections", pivot, existingConnections.size()); + LOGGER.debug( + "Finding connections for pivot {} with {} existing connections", + pivot, + existingConnections.size() + ); final ScanState scanState = new ScanState(existingPlatformConnections); addStartContainer(pivot, scanState); PlatformNetworkNodeContainer currentContainer; @@ -49,7 +53,7 @@ public Connections findConnections(final NetworkNodeContainer pivot, visit(scanState, new ScanEntry(currentContainer)); requests++; } - LOGGER.info( + LOGGER.debug( "Processed {} requests for pivot {} with {} found entries ({} removed and {} new)", requests, pivot, diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/registry/PlatformRegistryImpl.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/registry/PlatformRegistryImpl.java index 2873e2cfc..99e83daef 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/registry/PlatformRegistryImpl.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/registry/PlatformRegistryImpl.java @@ -4,6 +4,7 @@ import com.refinedmods.refinedstorage2.platform.api.support.registry.PlatformRegistry; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -19,12 +20,7 @@ public class PlatformRegistryImpl implements PlatformRegistry { private final Map idToValueMap = new HashMap<>(); private final Map valueToIdMap = new HashMap<>(); private final List order = new ArrayList<>(); - private final T defaultValue; - - public PlatformRegistryImpl(final ResourceLocation defaultValueId, final T defaultValue) { - this.register(defaultValueId, defaultValue); - this.defaultValue = defaultValue; - } + private final List viewList = Collections.unmodifiableList(order); @Override public void register(final ResourceLocation id, final T value) { @@ -38,11 +34,6 @@ public void register(final ResourceLocation id, final T value) { order.add(value); } - @Override - public boolean isEmpty() { - return order.size() == 1; - } - @Override public Optional getId(final T value) { CoreValidations.validateNotNull(value, VALUE_NOT_PRESENT_ERROR); @@ -55,29 +46,18 @@ public Optional get(final ResourceLocation id) { return Optional.ofNullable(idToValueMap.get(id)); } - @Override - public T getDefault() { - return defaultValue; - } - @Override public List getAll() { - return List.copyOf(order); - } - - @Override - public T next(final T value) { - final T nextValue = nextOrNullIfLast(value); - if (nextValue == null) { - return order.get(0); - } - return nextValue; + return viewList; } @Nullable @Override public T nextOrNullIfLast(final T value) { CoreValidations.validateNotNull(value, VALUE_NOT_PRESENT_ERROR); + if (order.isEmpty()) { + return null; + } final int index = order.indexOf(value); final int nextIndex = index + 1; if (nextIndex >= order.size()) { diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/stretching/AbstractStretchingScreen.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/stretching/AbstractStretchingScreen.java index 8c73972d9..7bbd61d55 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/stretching/AbstractStretchingScreen.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/stretching/AbstractStretchingScreen.java @@ -37,7 +37,7 @@ protected void init() { this.imageHeight = TOP_HEIGHT + (ROW_SIZE * visibleRows) + getBottomHeight(); this.inventoryLabelY = imageHeight - INVENTORY_INCLUDING_TITLE_HEIGHT + 4; - getMenu().initSlots(imageHeight - INVENTORY_INCLUDING_TITLE_HEIGHT + 17); + getMenu().onScreenReady(imageHeight - INVENTORY_INCLUDING_TITLE_HEIGHT + 17); super.init(); @@ -66,7 +66,7 @@ protected final int getScrollbarOffset() { } protected void scrollbarChanged(final int rows) { - // empty + // no op } @Override diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/stretching/ScreenSizeListener.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/stretching/ScreenSizeListener.java index f26c565bf..275a8bcbf 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/stretching/ScreenSizeListener.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/stretching/ScreenSizeListener.java @@ -1,5 +1,6 @@ package com.refinedmods.refinedstorage2.platform.common.support.stretching; +@FunctionalInterface public interface ScreenSizeListener { - void initSlots(int playerInventoryY); + void onScreenReady(int playerInventoryY); } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/widget/CustomCheckboxWidget.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/widget/CustomCheckboxWidget.java index ed1032afb..66d8b8fa5 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/widget/CustomCheckboxWidget.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/widget/CustomCheckboxWidget.java @@ -12,7 +12,7 @@ import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; -// A custom checkbox so we can change the font color. +// A custom checkbox so that we can change the font color. public class CustomCheckboxWidget extends AbstractButton { private static final ResourceLocation CHECKBOX_SELECTED_HIGHLIGHTED_SPRITE = new ResourceLocation( "widget/checkbox_selected_highlighted" @@ -66,6 +66,7 @@ public void updateWidgetNarration(final NarrationElementOutput output) { } } + @Override public void renderWidget(final GuiGraphics graphics, final int mouseX, final int mouseY, final float partialTicks) { final Minecraft minecraft = Minecraft.getInstance(); RenderSystem.enableDepthTest(); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/upgrade/UpgradeContainer.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/upgrade/UpgradeContainer.java index 9cd9caaf9..de42370b7 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/upgrade/UpgradeContainer.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/upgrade/UpgradeContainer.java @@ -82,7 +82,7 @@ public void fromTag(final ListTag tag) { } private void updateIndex() { - LOGGER.info("Updating upgrade index for {}", destination); + LOGGER.debug("Updating upgrade index for {}", destination); index.clear(); for (int i = 0; i < getContainerSize(); ++i) { updateIndex(i); diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/lang/en_us.json b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/lang/en_us.json index 5ccab4c59..afc6b3d08 100644 --- a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/lang/en_us.json +++ b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/lang/en_us.json @@ -1,5 +1,5 @@ { - "itemGroup.refinedstorage2.general": "Refined Storage 2", + "mod.refinedstorage2": "Refined Storage 2", "block.refinedstorage2.cable": "Cable", "block.refinedstorage2.quartz_enriched_iron_block": "Block of Quartz Enriched Iron", "block.refinedstorage2.disk_drive": "Disk Drive", @@ -254,7 +254,6 @@ "key.refinedstorage2.clear_crafting_grid_matrix_to_inventory": "Clear Crafting Grid matrix to inventory", "key.refinedstorage2.open_wireless_grid": "Open Wireless Grid", "refinedstorage2.subtitle.wrench": "Wrench used", - "category.refinedstorage2.key_bindings": "Refined Storage 2", "curios.identifier.refinedstorage2": "Refined Storage 2", "trinkets.slot.refinedstorage2.wireless": "Refined Storage 2", "permission.refinedstorage2.insert": "Insert", @@ -271,6 +270,8 @@ "permission.refinedstorage2.security.description": "Whether the player can manage the security options for a network.", "text.autoconfig.refinedstorage2.title": "Refined Storage 2", "text.autoconfig.refinedstorage2.option.smoothScrolling": "Smooth scrolling", + "text.autoconfig.refinedstorage2.option.screenSize": "Screen size", + "text.autoconfig.refinedstorage2.option.maxRowsStretch": "Maximum amount of rows when screen size is stretched", "text.autoconfig.refinedstorage2.option.grid": "Grid", "text.autoconfig.refinedstorage2.option.grid.largeFont": "Large font", "text.autoconfig.refinedstorage2.option.grid.preventSortingWhileShiftIsDown": "Prevent sorting while SHIFT is down", @@ -282,8 +283,6 @@ "text.autoconfig.refinedstorage2.option.grid.resourceTypeId": "Resource type", "text.autoconfig.refinedstorage2.option.grid.sortingDirection": "Sorting direction", "text.autoconfig.refinedstorage2.option.grid.sortingType": "Sorting type", - "text.autoconfig.refinedstorage2.option.screenSize": "Screen size", - "text.autoconfig.refinedstorage2.option.maxRowsStretch": "Maximum amount of rows when screen size is stretched", "text.autoconfig.refinedstorage2.option.craftingGrid": "Crafting Grid", "text.autoconfig.refinedstorage2.option.craftingGrid.energyUsage": "Energy usage", "text.autoconfig.refinedstorage2.option.craftingGrid.craftingMatrixCloseBehavior": "Crafting matrix close behavior", diff --git a/refinedstorage2-platform-common/src/test/java/com/refinedmods/refinedstorage2/platform/common/PlatformTestFixtures.java b/refinedstorage2-platform-common/src/test/java/com/refinedmods/refinedstorage2/platform/common/PlatformTestFixtures.java index 84b25d394..5c12ddd44 100644 --- a/refinedstorage2-platform-common/src/test/java/com/refinedmods/refinedstorage2/platform/common/PlatformTestFixtures.java +++ b/refinedstorage2-platform-common/src/test/java/com/refinedmods/refinedstorage2/platform/common/PlatformTestFixtures.java @@ -8,10 +8,11 @@ import net.minecraft.resources.ResourceLocation; public final class PlatformTestFixtures { - public static final PlatformRegistry STORAGE_TYPE_REGISTRY = new PlatformRegistryImpl<>( - new ResourceLocation("item"), - StorageTypes.ITEM - ); + public static final PlatformRegistry STORAGE_TYPE_REGISTRY = new PlatformRegistryImpl<>(); + + static { + STORAGE_TYPE_REGISTRY.register(new ResourceLocation("item"), StorageTypes.ITEM); + } private PlatformTestFixtures() { } diff --git a/refinedstorage2-platform-common/src/test/java/com/refinedmods/refinedstorage2/platform/common/support/registry/PlatformRegistryImplTest.java b/refinedstorage2-platform-common/src/test/java/com/refinedmods/refinedstorage2/platform/common/support/registry/PlatformRegistryImplTest.java index af72b8a35..fe2acd6c9 100644 --- a/refinedstorage2-platform-common/src/test/java/com/refinedmods/refinedstorage2/platform/common/support/registry/PlatformRegistryImplTest.java +++ b/refinedstorage2-platform-common/src/test/java/com/refinedmods/refinedstorage2/platform/common/support/registry/PlatformRegistryImplTest.java @@ -12,31 +12,24 @@ import static org.junit.jupiter.api.Assertions.assertThrows; class PlatformRegistryImplTest { - private static final ResourceLocation A = new ResourceLocation("minecraft:a"); - private static final ResourceLocation B = new ResourceLocation("minecraft:b"); - private static final ResourceLocation C = new ResourceLocation("minecraft:c"); + private static final ResourceLocation A = new ResourceLocation("a"); + private static final ResourceLocation B = new ResourceLocation("b"); + private static final ResourceLocation C = new ResourceLocation("c"); PlatformRegistry sut; @BeforeEach void setUp() { - sut = new PlatformRegistryImpl<>(A, 10); + sut = new PlatformRegistryImpl<>(); } @Test void testDefaults() { // Assert - assertThat(sut.getDefault()).isEqualTo(10); - assertThat(sut.getAll()).containsExactly(10); - assertThat(sut.get(A)).get().isEqualTo(10); - assertThat(sut.get(B)).isEmpty(); - assertThat(sut.getId(10)).get().isEqualTo(A); - assertThat(sut.getId(20)).isEmpty(); - assertThat(sut.next(10)).isEqualTo(10); + assertThat(sut.getAll()).isEmpty(); + assertThat(sut.get(A)).isEmpty(); + assertThat(sut.getId(10)).isEmpty(); assertThat(sut.nextOrNullIfLast(10)).isNull(); - assertThat(sut.next(20)).isEqualTo(10); - assertThat(sut.nextOrNullIfLast(20)).isEqualTo(10); - assertThat(sut.isEmpty()).isTrue(); } @Test @@ -46,25 +39,23 @@ void shouldNotBeAbleToModifyUnderlyingRegistryList() { // Act & assert assertThrows(UnsupportedOperationException.class, () -> list.add(1)); + assertThrows(UnsupportedOperationException.class, () -> list.remove(1)); } @Test void shouldRegisterAndRetrieve() { // Act + sut.register(A, 10); sut.register(B, 20); // Assert - assertThat(sut.getDefault()).isEqualTo(10); assertThat(sut.getAll()).containsExactly(10, 20); assertThat(sut.get(A)).get().isEqualTo(10); assertThat(sut.get(B)).get().isEqualTo(20); assertThat(sut.getId(10)).get().isEqualTo(A); assertThat(sut.getId(20)).get().isEqualTo(B); - assertThat(sut.next(10)).isEqualTo(20); assertThat(sut.nextOrNullIfLast(10)).isEqualTo(20); - assertThat(sut.next(20)).isEqualTo(10); assertThat(sut.nextOrNullIfLast(20)).isNull(); - assertThat(sut.isEmpty()).isFalse(); } @Test @@ -74,7 +65,7 @@ void shouldNotRegisterDuplicateId() { // Act & assert assertThrows(IllegalArgumentException.class, () -> sut.register(B, 20)); - assertThat(sut.getAll()).containsExactly(10, 20); + assertThat(sut.getAll()).containsExactly(20); } @Test @@ -84,7 +75,7 @@ void shouldNotRegisterDuplicateValue() { // Act & assert assertThrows(IllegalArgumentException.class, () -> sut.register(C, 20)); - assertThat(sut.getAll()).containsExactly(10, 20); + assertThat(sut.getAll()).containsExactly(20); } @Test @@ -96,19 +87,9 @@ void testInvalidRegistration() { assertThrows(NullPointerException.class, () -> sut.register(null, null)); } - @Test - @SuppressWarnings("ConstantConditions") - void testInvalidDefaults() { - // Act & assert - assertThrows(NullPointerException.class, () -> new PlatformRegistryImpl<>(null, 20)); - assertThrows(NullPointerException.class, () -> new PlatformRegistryImpl<>(B, null)); - assertThrows(NullPointerException.class, () -> new PlatformRegistryImpl<>(null, null)); - } - @Test @SuppressWarnings("ConstantConditions") void testInvalidNextValues() { - assertThrows(NullPointerException.class, () -> sut.next(null)); assertThrows(NullPointerException.class, () -> sut.nextOrNullIfLast(null)); } diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/ClientModInitializerImpl.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/ClientModInitializerImpl.java index 0d4f6ce6f..a61d27f12 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/ClientModInitializerImpl.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/ClientModInitializerImpl.java @@ -9,6 +9,7 @@ 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.content.ContentNames; import com.refinedmods.refinedstorage2.platform.common.content.Items; import com.refinedmods.refinedstorage2.platform.common.content.KeyMappings; import com.refinedmods.refinedstorage2.platform.common.controller.ControllerModelPredicateProvider; @@ -74,7 +75,6 @@ public class ClientModInitializerImpl extends AbstractClientModInitializer implements ClientModInitializer { private static final Logger LOGGER = LoggerFactory.getLogger(ClientModInitializerImpl.class); - private static final String KEY_BINDINGS_TRANSLATION_KEY = createTranslationKey("category", "key_bindings"); @Override public void onInitializeClient() { @@ -365,13 +365,13 @@ private void registerKeyBindings() { createTranslationKey("key", "focus_search_bar"), InputConstants.Type.KEYSYM, GLFW.GLFW_KEY_TAB, - KEY_BINDINGS_TRANSLATION_KEY + ContentNames.MOD_TRANSLATION_KEY ))); KeyMappings.INSTANCE.setOpenWirelessGrid(KeyBindingHelper.registerKeyBinding(new KeyMapping( createTranslationKey("key", "open_wireless_grid"), InputConstants.Type.KEYSYM, InputConstants.UNKNOWN.getValue(), - KEY_BINDINGS_TRANSLATION_KEY + ContentNames.MOD_TRANSLATION_KEY ))); ClientTickEvents.END_CLIENT_TICK.register(client -> handleInputEvents()); } @@ -385,6 +385,7 @@ private void registerModelPredicates() { } private void registerGridSynchronizers() { + registerBaseGridSynchronizer(); final FabricLoader loader = FabricLoader.getInstance(); if (loader.isModLoaded("roughlyenoughitems")) { registerReiGridSynchronizers(); @@ -392,7 +393,7 @@ private void registerGridSynchronizers() { } private void registerReiGridSynchronizers() { - LOGGER.info("Enabling REI grid synchronizers"); + LOGGER.debug("Enabling REI grid synchronizers"); // This is so the ingredient converters are only registered once // see https://github.com/refinedmods/refinedstorage2/pull/302#discussion_r1070015672 RefinedStorageREIClientPlugin.registerIngredientConverters(); 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 907e9a872..bc77c1b31 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 @@ -11,6 +11,7 @@ import com.refinedmods.refinedstorage2.platform.common.content.DirectRegistryCallback; import com.refinedmods.refinedstorage2.platform.common.content.Items; import com.refinedmods.refinedstorage2.platform.common.content.MenuTypeFactory; +import com.refinedmods.refinedstorage2.platform.common.content.RegistryCallback; import com.refinedmods.refinedstorage2.platform.common.grid.WirelessGridItem; import com.refinedmods.refinedstorage2.platform.common.iface.InterfaceBlockEntity; import com.refinedmods.refinedstorage2.platform.common.iface.InterfacePlatformExternalStorageProviderFactory; @@ -80,6 +81,7 @@ import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.inventory.MenuType; import net.minecraft.world.item.CreativeModeTab; +import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.entity.BlockEntity; @@ -89,6 +91,13 @@ import org.slf4j.LoggerFactory; import team.reborn.energy.api.EnergyStorage; +import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.CREATIVE_PORTABLE_GRID; +import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.CREATIVE_WIRELESS_GRID; +import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.FALLBACK_SECURITY_CARD; +import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.PORTABLE_GRID; +import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.REGULATOR_UPGRADE; +import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.SECURITY_CARD; +import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.WIRELESS_GRID; import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createIdentifier; public class ModInitializerImpl extends AbstractModInitializer implements ModInitializer { @@ -112,10 +121,9 @@ public void onInitialize() { registerRecipeSerializers(new DirectRegistryCallback<>(BuiltInRegistries.RECIPE_SERIALIZER)); registerSidedHandlers(); registerTickHandler(); - registerSlotReferenceProviders(); registerWrenchingEvent(); - LOGGER.info("Refined Storage 2 has loaded."); + LOGGER.debug("Refined Storage 2 has loaded."); } private void registerAdditionalGridInsertionStrategyFactories() { @@ -200,26 +208,56 @@ private void registerContent() { (pos, state) -> new FabricPortableGridBlockEntity(PortableGridType.NORMAL, pos, state), (pos, state) -> new FabricPortableGridBlockEntity(PortableGridType.CREATIVE, pos, state) ); - registerItems( - new DirectRegistryCallback<>(BuiltInRegistries.ITEM), - () -> new RegulatorUpgradeItem(PlatformApi.INSTANCE.getUpgradeRegistry()) { - @Override - public boolean allowNbtUpdateAnimation(final Player player, - final InteractionHand hand, - final ItemStack oldStack, - final ItemStack newStack) { - return AbstractModInitializer.allowNbtUpdateAnimation(oldStack, newStack); - } - }, - () -> new WirelessGridItem() { + final DirectRegistryCallback itemRegistryCallback = new DirectRegistryCallback<>(BuiltInRegistries.ITEM); + registerItems(itemRegistryCallback); + registerCustomItems(itemRegistryCallback); + registerUpgradeMappings(); + registerCreativeModeTab(); + registerBlockEntities( + new DirectRegistryCallback<>(BuiltInRegistries.BLOCK_ENTITY_TYPE), + new BlockEntityTypeFactory() { @Override - public boolean allowNbtUpdateAnimation(final Player player, - final InteractionHand hand, - final ItemStack oldStack, - final ItemStack newStack) { - return AbstractModInitializer.allowNbtUpdateAnimation(oldStack, newStack); + public BlockEntityType create(final BlockEntitySupplier factory, + final Block... allowedBlocks) { + return new BlockEntityType<>(factory::create, new HashSet<>(Arrays.asList(allowedBlocks)), null); } }, + FabricDiskDriveBlockEntity::new, + (pos, state) -> new FabricPortableGridBlockEntity(PortableGridType.NORMAL, pos, state), + (pos, state) -> new FabricPortableGridBlockEntity(PortableGridType.CREATIVE, pos, state) + ); + registerMenus(new DirectRegistryCallback<>(BuiltInRegistries.MENU), new MenuTypeFactory() { + @Override + public MenuType create(final MenuSupplier supplier) { + return new ExtendedScreenHandlerType<>(supplier::create); + } + }); + registerLootFunctions(new DirectRegistryCallback<>(BuiltInRegistries.LOOT_FUNCTION_TYPE)); + } + + private void registerCustomItems(final RegistryCallback callback) { + Items.INSTANCE.setRegulatorUpgrade(callback.register(REGULATOR_UPGRADE, () -> new RegulatorUpgradeItem( + PlatformApi.INSTANCE.getUpgradeRegistry() + ) { + @Override + public boolean allowNbtUpdateAnimation(final Player player, + final InteractionHand hand, + final ItemStack oldStack, + final ItemStack newStack) { + return AbstractModInitializer.allowNbtUpdateAnimation(oldStack, newStack); + } + })); + Items.INSTANCE.setWirelessGrid(callback.register(WIRELESS_GRID, () -> new WirelessGridItem() { + @Override + public boolean allowNbtUpdateAnimation(final Player player, + final InteractionHand hand, + final ItemStack oldStack, + final ItemStack newStack) { + return AbstractModInitializer.allowNbtUpdateAnimation(oldStack, newStack); + } + })); + Items.INSTANCE.setCreativeWirelessGrid(callback.register( + CREATIVE_WIRELESS_GRID, () -> new WirelessGridItem() { @Override public boolean allowNbtUpdateAnimation(final Player player, @@ -228,16 +266,21 @@ public boolean allowNbtUpdateAnimation(final Player player, final ItemStack newStack) { return AbstractModInitializer.allowNbtUpdateAnimation(oldStack, newStack); } - }, - () -> new PortableGridBlockItem(Blocks.INSTANCE.getPortableGrid(), PortableGridType.NORMAL) { - @Override - public boolean allowNbtUpdateAnimation(final Player player, - final InteractionHand hand, - final ItemStack oldStack, - final ItemStack newStack) { - return AbstractModInitializer.allowNbtUpdateAnimation(oldStack, newStack); - } - }, + } + )); + Items.INSTANCE.setPortableGrid(callback.register(PORTABLE_GRID, () -> new PortableGridBlockItem( + Blocks.INSTANCE.getPortableGrid(), PortableGridType.NORMAL + ) { + @Override + public boolean allowNbtUpdateAnimation(final Player player, + final InteractionHand hand, + final ItemStack oldStack, + final ItemStack newStack) { + return AbstractModInitializer.allowNbtUpdateAnimation(oldStack, newStack); + } + })); + Items.INSTANCE.setCreativePortableGrid(callback.register( + CREATIVE_PORTABLE_GRID, () -> new PortableGridBlockItem(Blocks.INSTANCE.getCreativePortableGrid(), PortableGridType.CREATIVE) { @Override public boolean allowNbtUpdateAnimation(final Player player, @@ -246,16 +289,19 @@ public boolean allowNbtUpdateAnimation(final Player player, final ItemStack newStack) { return AbstractModInitializer.allowNbtUpdateAnimation(oldStack, newStack); } - }, - () -> new SecurityCardItem() { - @Override - public boolean allowNbtUpdateAnimation(final Player player, - final InteractionHand hand, - final ItemStack oldStack, - final ItemStack newStack) { - return AbstractModInitializer.allowNbtUpdateAnimation(oldStack, newStack); - } - }, + } + )); + Items.INSTANCE.setSecurityCard(callback.register(SECURITY_CARD, () -> new SecurityCardItem() { + @Override + public boolean allowNbtUpdateAnimation(final Player player, + final InteractionHand hand, + final ItemStack oldStack, + final ItemStack newStack) { + return AbstractModInitializer.allowNbtUpdateAnimation(oldStack, newStack); + } + })); + Items.INSTANCE.setFallbackSecurityCard(callback.register( + FALLBACK_SECURITY_CARD, () -> new FallbackSecurityCardItem() { @Override public boolean allowNbtUpdateAnimation(final Player player, @@ -265,29 +311,7 @@ public boolean allowNbtUpdateAnimation(final Player player, return AbstractModInitializer.allowNbtUpdateAnimation(oldStack, newStack); } } - ); - registerUpgradeMappings(); - registerCreativeModeTab(); - registerBlockEntities( - new DirectRegistryCallback<>(BuiltInRegistries.BLOCK_ENTITY_TYPE), - new BlockEntityTypeFactory() { - @Override - public BlockEntityType create(final BlockEntitySupplier factory, - final Block... allowedBlocks) { - return new BlockEntityType<>(factory::create, new HashSet<>(Arrays.asList(allowedBlocks)), null); - } - }, - FabricDiskDriveBlockEntity::new, - (pos, state) -> new FabricPortableGridBlockEntity(PortableGridType.NORMAL, pos, state), - (pos, state) -> new FabricPortableGridBlockEntity(PortableGridType.CREATIVE, pos, state) - ); - registerMenus(new DirectRegistryCallback<>(BuiltInRegistries.MENU), new MenuTypeFactory() { - @Override - public MenuType create(final MenuSupplier supplier) { - return new ExtendedScreenHandlerType<>(supplier::create); - } - }); - registerLootFunctions(new DirectRegistryCallback<>(BuiltInRegistries.LOOT_FUNCTION_TYPE)); + )); } private void registerCreativeModeTab() { @@ -405,7 +429,9 @@ private void registerTickHandler() { ServerTickEvents.START_SERVER_TICK.register(server -> ServerEventQueue.runQueuedActions()); } - private void registerSlotReferenceProviders() { + @Override + protected void registerSlotReferenceProviders() { + super.registerSlotReferenceProviders(); TrinketsSlotReferenceProvider.create().ifPresent(slotReferenceProvider -> { PlatformApi.INSTANCE.getSlotReferenceFactoryRegistry().register( createIdentifier("trinkets"), diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/ClientToServerCommunicationsImpl.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/ClientToServerCommunicationsImpl.java index d61df1fc2..3ba6c6123 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/ClientToServerCommunicationsImpl.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/ClientToServerCommunicationsImpl.java @@ -4,6 +4,7 @@ import com.refinedmods.refinedstorage2.api.grid.operations.GridInsertMode; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; import com.refinedmods.refinedstorage2.platform.api.grid.GridScrollMode; +import com.refinedmods.refinedstorage2.platform.api.security.PlatformPermission; import com.refinedmods.refinedstorage2.platform.api.support.network.bounditem.SlotReference; import com.refinedmods.refinedstorage2.platform.api.support.resource.PlatformResourceKey; import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceType; @@ -131,19 +132,22 @@ public void sendUseNetworkBoundItem(final SlotReference slotReference) { } @Override - public void sendSecurityCardPermission(final ResourceLocation permissionId, final boolean allowed) { - sendToServer( + public void sendSecurityCardPermission(final PlatformPermission permission, final boolean allowed) { + PlatformApi.INSTANCE.getPermissionRegistry().getId(permission).ifPresent(id -> sendToServer( PacketIds.SECURITY_CARD_PERMISSION, buf -> { - buf.writeResourceLocation(permissionId); + buf.writeResourceLocation(id); buf.writeBoolean(allowed); } - ); + )); } @Override - public void sendSecurityCardResetPermission(final ResourceLocation permissionId) { - sendToServer(PacketIds.SECURITY_CARD_RESET_PERMISSION, buf -> buf.writeResourceLocation(permissionId)); + public void sendSecurityCardResetPermission(final PlatformPermission permission) { + PlatformApi.INSTANCE.getPermissionRegistry().getId(permission).ifPresent(id -> sendToServer( + PacketIds.SECURITY_CARD_RESET_PERMISSION, + buf -> buf.writeResourceLocation(id) + )); } @Override diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/SecurityCardResetPermissionPacket.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/SecurityCardResetPermissionPacket.java index ded155bf9..de26b2f54 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/SecurityCardResetPermissionPacket.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/SecurityCardResetPermissionPacket.java @@ -19,7 +19,7 @@ public void receive(final MinecraftServer server, final PacketSender responseSender) { final ResourceLocation permissionId = buf.readResourceLocation(); if (player.containerMenu instanceof AbstractSecurityCardContainerMenu securityCardContainerMenu) { - server.execute(() -> securityCardContainerMenu.resetPermissionServer(permissionId)); + server.execute(() -> securityCardContainerMenu.resetPermission(permissionId)); } } } diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/ClientModInitializer.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/ClientModInitializer.java index 7f0734f01..d0bbe2230 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/ClientModInitializer.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/ClientModInitializer.java @@ -7,6 +7,7 @@ import com.refinedmods.refinedstorage2.platform.common.AbstractClientModInitializer; import com.refinedmods.refinedstorage2.platform.common.configurationcard.ConfigurationCardItemPropertyFunction; import com.refinedmods.refinedstorage2.platform.common.content.BlockEntities; +import com.refinedmods.refinedstorage2.platform.common.content.ContentNames; import com.refinedmods.refinedstorage2.platform.common.content.Items; import com.refinedmods.refinedstorage2.platform.common.content.KeyMappings; import com.refinedmods.refinedstorage2.platform.common.controller.ControllerModelPredicateProvider; @@ -60,7 +61,6 @@ public final class ClientModInitializer extends AbstractClientModInitializer { private static final Logger LOGGER = LoggerFactory.getLogger(ClientModInitializer.class); - private static final String KEY_BINDINGS_TRANSLATION_KEY = createTranslationKey("category", "key_bindings"); private ClientModInitializer() { } @@ -116,7 +116,7 @@ public static void onRegisterKeyMappings(final RegisterKeyMappingsEvent e) { createTranslationKey("key", "focus_search_bar"), InputConstants.Type.KEYSYM, GLFW.GLFW_KEY_TAB, - KEY_BINDINGS_TRANSLATION_KEY + ContentNames.MOD_TRANSLATION_KEY ); e.register(focusSearchBarKeyBinding); KeyMappings.INSTANCE.setFocusSearchBar(focusSearchBarKeyBinding); @@ -127,7 +127,7 @@ public static void onRegisterKeyMappings(final RegisterKeyMappingsEvent e) { KeyModifier.CONTROL, InputConstants.Type.KEYSYM, GLFW.GLFW_KEY_X, - KEY_BINDINGS_TRANSLATION_KEY + ContentNames.MOD_TRANSLATION_KEY ); e.register(clearCraftingGridMatrixToNetwork); KeyMappings.INSTANCE.setClearCraftingGridMatrixToNetwork(clearCraftingGridMatrixToNetwork); @@ -135,7 +135,7 @@ public static void onRegisterKeyMappings(final RegisterKeyMappingsEvent e) { final KeyMapping clearCraftingGridMatrixToInventory = new KeyMapping( createTranslationKey("key", "clear_crafting_grid_matrix_to_inventory"), InputConstants.UNKNOWN.getValue(), - KEY_BINDINGS_TRANSLATION_KEY + ContentNames.MOD_TRANSLATION_KEY ); e.register(clearCraftingGridMatrixToInventory); KeyMappings.INSTANCE.setClearCraftingGridMatrixToInventory(clearCraftingGridMatrixToInventory); @@ -144,7 +144,7 @@ public static void onRegisterKeyMappings(final RegisterKeyMappingsEvent e) { createTranslationKey("key", "open_wireless_grid"), KeyConflictContext.IN_GAME, InputConstants.UNKNOWN, - KEY_BINDINGS_TRANSLATION_KEY + ContentNames.MOD_TRANSLATION_KEY ); e.register(openWirelessGrid); KeyMappings.INSTANCE.setOpenWirelessGrid(openWirelessGrid); @@ -170,6 +170,7 @@ private static void registerBlockEntityRenderer() { } private static void registerGridSynchronizers() { + registerBaseGridSynchronizer(); final ModList list = ModList.get(); // Give priority to REI, as REI requires a JEI compat mod on Forge. // This means that both JEI + REI support would be activated. We only want REI in that case. @@ -179,7 +180,7 @@ private static void registerGridSynchronizers() { } private static void registerReiGridSynchronizers() { - LOGGER.info("Enabling REI grid synchronizers"); + LOGGER.debug("Enabling REI grid synchronizers"); // This is so the ingredient converters are only registered once // see https://github.com/refinedmods/refinedstorage2/pull/302#discussion_r1070015672 RefinedStorageREIClientPlugin.registerIngredientConverters(); 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 af65f270d..79dade470 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 @@ -100,6 +100,13 @@ import net.neoforged.neoforge.registries.DeferredRegister; import net.neoforged.neoforge.registries.RegisterEvent; +import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.CREATIVE_PORTABLE_GRID; +import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.CREATIVE_WIRELESS_GRID; +import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.FALLBACK_SECURITY_CARD; +import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.PORTABLE_GRID; +import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.REGULATOR_UPGRADE; +import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.SECURITY_CARD; +import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.WIRELESS_GRID; import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.MOD_ID; import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createIdentifier; @@ -131,7 +138,6 @@ public ModInitializer(final IEventBus eventBus) { registerSounds(eventBus); registerRecipeSerializers(eventBus); registerTickHandler(); - registerSlotReferenceProviders(); if (FMLEnvironment.dist == Dist.CLIENT) { eventBus.addListener(ClientModInitializer::onClientSetup); @@ -209,24 +215,33 @@ private void registerBlocks(final IEventBus eventBus) { } private void registerItems(final IEventBus eventBus) { - registerItems( - new ForgeRegistryCallback<>(itemRegistry), - () -> new RegulatorUpgradeItem(PlatformApi.INSTANCE.getUpgradeRegistry()) { - @Override - public boolean shouldCauseReequipAnimation(final ItemStack oldStack, - final ItemStack newStack, - final boolean slotChanged) { - return AbstractModInitializer.allowNbtUpdateAnimation(oldStack, newStack); - } - }, - () -> new WirelessGridItem() { - @Override - public boolean shouldCauseReequipAnimation(final ItemStack oldStack, - final ItemStack newStack, - final boolean slotChanged) { - return AbstractModInitializer.allowNbtUpdateAnimation(oldStack, newStack); - } - }, + final RegistryCallback callback = new ForgeRegistryCallback<>(itemRegistry); + registerItems(callback); + registerCustomItems(callback); + itemRegistry.register(eventBus); + } + + private void registerCustomItems(final RegistryCallback callback) { + Items.INSTANCE.setRegulatorUpgrade(callback.register(REGULATOR_UPGRADE, () -> new RegulatorUpgradeItem( + PlatformApi.INSTANCE.getUpgradeRegistry() + ) { + @Override + public boolean shouldCauseReequipAnimation(final ItemStack oldStack, + final ItemStack newStack, + final boolean slotChanged) { + return AbstractModInitializer.allowNbtUpdateAnimation(oldStack, newStack); + } + })); + Items.INSTANCE.setWirelessGrid(callback.register(WIRELESS_GRID, () -> new WirelessGridItem() { + @Override + public boolean shouldCauseReequipAnimation(final ItemStack oldStack, + final ItemStack newStack, + final boolean slotChanged) { + return AbstractModInitializer.allowNbtUpdateAnimation(oldStack, newStack); + } + })); + Items.INSTANCE.setCreativeWirelessGrid(callback.register( + CREATIVE_WIRELESS_GRID, () -> new WirelessGridItem() { @Override public boolean shouldCauseReequipAnimation(final ItemStack oldStack, @@ -234,15 +249,20 @@ public boolean shouldCauseReequipAnimation(final ItemStack oldStack, final boolean slotChanged) { return AbstractModInitializer.allowNbtUpdateAnimation(oldStack, newStack); } - }, - () -> new PortableGridBlockItem(Blocks.INSTANCE.getPortableGrid(), PortableGridType.NORMAL) { - @Override - public boolean shouldCauseReequipAnimation(final ItemStack oldStack, - final ItemStack newStack, - final boolean slotChanged) { - return AbstractModInitializer.allowNbtUpdateAnimation(oldStack, newStack); - } - }, + } + )); + Items.INSTANCE.setPortableGrid(callback.register(PORTABLE_GRID, () -> new PortableGridBlockItem( + Blocks.INSTANCE.getPortableGrid(), PortableGridType.NORMAL + ) { + @Override + public boolean shouldCauseReequipAnimation(final ItemStack oldStack, + final ItemStack newStack, + final boolean slotChanged) { + return AbstractModInitializer.allowNbtUpdateAnimation(oldStack, newStack); + } + })); + Items.INSTANCE.setCreativePortableGrid(callback.register( + CREATIVE_PORTABLE_GRID, () -> new PortableGridBlockItem(Blocks.INSTANCE.getCreativePortableGrid(), PortableGridType.CREATIVE) { @Override public boolean shouldCauseReequipAnimation(final ItemStack oldStack, @@ -250,15 +270,18 @@ public boolean shouldCauseReequipAnimation(final ItemStack oldStack, final boolean slotChanged) { return AbstractModInitializer.allowNbtUpdateAnimation(oldStack, newStack); } - }, - () -> new SecurityCardItem() { - @Override - public boolean shouldCauseReequipAnimation(final ItemStack oldStack, - final ItemStack newStack, - final boolean slotChanged) { - return AbstractModInitializer.allowNbtUpdateAnimation(oldStack, newStack); - } - }, + } + )); + Items.INSTANCE.setSecurityCard(callback.register(SECURITY_CARD, () -> new SecurityCardItem() { + @Override + public boolean shouldCauseReequipAnimation(final ItemStack oldStack, + final ItemStack newStack, + final boolean slotChanged) { + return AbstractModInitializer.allowNbtUpdateAnimation(oldStack, newStack); + } + })); + Items.INSTANCE.setFallbackSecurityCard(callback.register( + FALLBACK_SECURITY_CARD, () -> new FallbackSecurityCardItem() { @Override public boolean shouldCauseReequipAnimation(final ItemStack oldStack, @@ -267,8 +290,7 @@ public boolean shouldCauseReequipAnimation(final ItemStack oldStack, return AbstractModInitializer.allowNbtUpdateAnimation(oldStack, newStack); } } - ); - itemRegistry.register(eventBus); + )); } private void registerBlockEntities(final IEventBus eventBus) { @@ -355,7 +377,9 @@ private void registerTickHandler() { NeoForge.EVENT_BUS.addListener(this::onServerTick); } + @Override protected void registerSlotReferenceProviders() { + super.registerSlotReferenceProviders(); CuriosSlotReferenceProvider.create().ifPresent(slotReferenceProvider -> { PlatformApi.INSTANCE.getSlotReferenceFactoryRegistry().register( createIdentifier("curios"), diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/ClientToServerCommunicationsImpl.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/ClientToServerCommunicationsImpl.java index 3380b0937..35b2f8b7c 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/ClientToServerCommunicationsImpl.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/ClientToServerCommunicationsImpl.java @@ -4,6 +4,7 @@ import com.refinedmods.refinedstorage2.api.grid.operations.GridInsertMode; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; import com.refinedmods.refinedstorage2.platform.api.grid.GridScrollMode; +import com.refinedmods.refinedstorage2.platform.api.security.PlatformPermission; import com.refinedmods.refinedstorage2.platform.api.support.network.bounditem.SlotReference; import com.refinedmods.refinedstorage2.platform.api.support.resource.PlatformResourceKey; import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceType; @@ -16,11 +17,10 @@ import javax.annotation.Nullable; import net.minecraft.network.protocol.common.custom.CustomPacketPayload; -import net.minecraft.resources.ResourceLocation; import net.neoforged.neoforge.network.PacketDistributor; public class ClientToServerCommunicationsImpl implements ClientToServerCommunications { - private void sendPacket(final CustomPacketPayload packet) { + private void sendToServer(final CustomPacketPayload packet) { PacketDistributor.SERVER.noArg().send(packet); } @@ -29,14 +29,9 @@ public void sendGridExtract(final PlatformResourceKey resource, final GridExtractMode mode, final boolean cursor) { final ResourceType resourceType = resource.getResourceType(); - PlatformApi.INSTANCE.getResourceTypeRegistry().getId(resourceType) - .ifPresent(id -> sendPacket(new GridExtractPacket( - resourceType, - id, - resource, - mode, - cursor - ))); + PlatformApi.INSTANCE.getResourceTypeRegistry().getId(resourceType).ifPresent(id -> sendToServer( + new GridExtractPacket(resourceType, id, resource, mode, cursor) + )); } @Override @@ -44,87 +39,80 @@ public void sendGridScroll(final PlatformResourceKey resource, final GridScrollMode mode, final int slotIndex) { final ResourceType resourceType = resource.getResourceType(); - PlatformApi.INSTANCE.getResourceTypeRegistry() - .getId(resourceType) - .ifPresent(id -> sendPacket(new GridScrollPacket( - resourceType, - id, - resource, - mode, - slotIndex - ))); + PlatformApi.INSTANCE.getResourceTypeRegistry().getId(resourceType).ifPresent(id -> sendToServer( + new GridScrollPacket(resourceType, id, resource, mode, slotIndex) + )); } @Override public void sendGridInsert(final GridInsertMode mode, final boolean tryAlternatives) { - sendPacket(new GridInsertPacket(mode == GridInsertMode.SINGLE_RESOURCE, tryAlternatives)); + sendToServer(new GridInsertPacket(mode == GridInsertMode.SINGLE_RESOURCE, tryAlternatives)); } @Override public void sendCraftingGridClear(final boolean toPlayerInventory) { - sendPacket(new CraftingGridClearPacket(toPlayerInventory)); + sendToServer(new CraftingGridClearPacket(toPlayerInventory)); } @Override public void sendCraftingGridRecipeTransfer(final List> recipe) { - sendPacket(new CraftingGridRecipeTransferPacket(recipe)); + sendToServer(new CraftingGridRecipeTransferPacket(recipe)); } @Override public void sendPropertyChange(final PropertyType type, final T value) { - sendPacket(new PropertyChangePacket(type.id(), type.serializer().apply(value))); + sendToServer(new PropertyChangePacket(type.id(), type.serializer().apply(value))); } @Override public void sendStorageInfoRequest(final UUID storageId) { - sendPacket(new StorageInfoRequestPacket(storageId)); + sendToServer(new StorageInfoRequestPacket(storageId)); } @Override public void sendResourceSlotChange(final int slotIndex, final boolean tryAlternatives) { - sendPacket(new ResourceSlotChangePacket(slotIndex, tryAlternatives)); + sendToServer(new ResourceSlotChangePacket(slotIndex, tryAlternatives)); } @Override public void sendResourceFilterSlotChange(final PlatformResourceKey resource, final int slotIndex) { final ResourceType resourceType = resource.getResourceType(); - PlatformApi.INSTANCE.getResourceTypeRegistry().getId(resourceType).ifPresent( - id -> sendPacket(new ResourceFilterSlotChangePacket( - slotIndex, - resource, - resourceType, - id - )) - ); + PlatformApi.INSTANCE.getResourceTypeRegistry().getId(resourceType).ifPresent(id -> sendToServer( + new ResourceFilterSlotChangePacket(slotIndex, resource, resourceType, id) + )); } @Override public void sendResourceSlotAmountChange(final int slotIndex, final long amount) { - sendPacket(new ResourceSlotAmountChangePacket(slotIndex, amount)); + sendToServer(new ResourceSlotAmountChangePacket(slotIndex, amount)); } @Override public void sendSingleAmountChange(final double amount) { - sendPacket(new SingleAmountChangePacket(amount)); + sendToServer(new SingleAmountChangePacket(amount)); } @Override public void sendUseNetworkBoundItem(final SlotReference slotReference) { - sendPacket(new UseNetworkBoundItemPacket(slotReference)); + sendToServer(new UseNetworkBoundItemPacket(slotReference)); } @Override - public void sendSecurityCardPermission(final ResourceLocation permissionId, final boolean allowed) { - sendPacket(new SecurityCardPermissionPacket(permissionId, allowed)); + public void sendSecurityCardPermission(final PlatformPermission permission, final boolean allowed) { + PlatformApi.INSTANCE.getPermissionRegistry().getId(permission).ifPresent(id -> sendToServer( + new SecurityCardPermissionPacket(id, allowed) + )); } @Override - public void sendSecurityCardResetPermission(final ResourceLocation permissionId) { - sendPacket(new SecurityCardResetPermissionPacket(permissionId)); + public void sendSecurityCardResetPermission(final PlatformPermission permission) { + PlatformApi.INSTANCE.getPermissionRegistry().getId(permission).ifPresent(id -> sendToServer( + new SecurityCardResetPermissionPacket(id) + )); } @Override public void sendSecurityCardBoundPlayer(@Nullable final UUID playerId) { - sendPacket(new SecurityCardBoundPlayerPacket(playerId)); + sendToServer(new SecurityCardBoundPlayerPacket(playerId)); } } diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/SecurityCardResetPermissionPacket.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/SecurityCardResetPermissionPacket.java index cdd621829..1831a87a1 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/SecurityCardResetPermissionPacket.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/SecurityCardResetPermissionPacket.java @@ -16,7 +16,7 @@ public static SecurityCardResetPermissionPacket decode(final FriendlyByteBuf buf public static void handle(final SecurityCardResetPermissionPacket packet, final PlayPayloadContext ctx) { ctx.player().ifPresent(player -> ctx.workHandler().submitAsync(() -> { if (player.containerMenu instanceof AbstractSecurityCardContainerMenu securityCardContainerMenu) { - securityCardContainerMenu.resetPermissionServer(packet.permissionId); + securityCardContainerMenu.resetPermission(packet.permissionId); } })); }