Skip to content

Commit

Permalink
Merge pull request #510 from refinedmods/feat/GH-86/security-card-cle…
Browse files Browse the repository at this point in the history
…anup

Security card cleanup
  • Loading branch information
raoulvdberge authored Apr 1, 2024
2 parents 3cabe48 + 3def5dd commit 8ce67c7
Show file tree
Hide file tree
Showing 47 changed files with 421 additions and 448 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ eclipse/
*.ipr
*.iws
.idea/
!.idea/dictionaries/refinedstorage2.xml
!.idea/icon.png
out/
/bin/
logs/
Expand Down
8 changes: 8 additions & 0 deletions .idea/dictionaries/refinedstorage2.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added .idea/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}

Expand All @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ public interface PlatformRegistry<T> {
*/
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
Expand All @@ -38,28 +33,14 @@ public interface PlatformRegistry<T> {
*/
Optional<T> get(ResourceLocation id);

/**
* @return the default value
*/
T getDefault();

/**
* @return an unmodifiable list of all values
*/
List<T> getAll();

/**
* 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<GridContainerMenu>::new);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -316,16 +319,7 @@ protected final void registerBlocks(
)));
}

protected final void registerItems(
final RegistryCallback<Item> callback,
final Supplier<AbstractUpgradeItem> regulatorUpgradeItemSupplier,
final Supplier<WirelessGridItem> wirelessGridItemSupplier,
final Supplier<WirelessGridItem> creativeWirelessGridItemSupplier,
final Supplier<PortableGridBlockItem> portableGridBlockItemSupplier,
final Supplier<PortableGridBlockItem> creativePortableGridBlockItemSupplier,
final Supplier<SecurityCardItem> securityCardItemSupplier,
final Supplier<FallbackSecurityCardItem> fallbackSecurityCardItemSupplier
) {
protected final void registerItems(final RegistryCallback<Item> callback) {
registerSimpleItems(callback);
Blocks.INSTANCE.getGrid().registerItems(callback);
Blocks.INSTANCE.getCraftingGrid().registerItems(callback);
Expand All @@ -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<Item> callback) {
Expand All @@ -373,6 +351,7 @@ private void registerSimpleItems(final RegistryCallback<Item> 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));
Expand Down Expand Up @@ -435,10 +414,7 @@ private void registerFluidStorageItems(final RegistryCallback<Item> callback,
);
}

private void registerUpgrades(
final RegistryCallback<Item> callback,
final Supplier<AbstractUpgradeItem> regulatorUpgradeItemSupplier
) {
private void registerUpgrades(final RegistryCallback<Item> callback) {
Items.INSTANCE.setUpgrade(callback.register(
ContentIds.UPGRADE,
SimpleItem::new
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -774,6 +746,13 @@ protected final void registerRecipeSerializers(final RegistryCallback<RecipeSeri
);
}

protected void registerSlotReferenceProviders() {
PlatformApi.INSTANCE.getSlotReferenceFactoryRegistry().register(
createIdentifier("inventory"),
InventorySlotReferenceFactory.INSTANCE
);
}

protected static boolean allowNbtUpdateAnimation(final ItemStack oldStack, final ItemStack newStack) {
return oldStack.getItem() != newStack.getItem();
}
Expand Down
Loading

0 comments on commit 8ce67c7

Please sign in to comment.