diff --git a/refinedstorage2-grid-api/src/main/java/com/refinedmods/refinedstorage2/api/grid/GridWatcher.java b/refinedstorage2-grid-api/src/main/java/com/refinedmods/refinedstorage2/api/grid/GridWatcher.java index 7de609bd5..16febbd31 100644 --- a/refinedstorage2-grid-api/src/main/java/com/refinedmods/refinedstorage2/api/grid/GridWatcher.java +++ b/refinedstorage2-grid-api/src/main/java/com/refinedmods/refinedstorage2/api/grid/GridWatcher.java @@ -36,7 +36,7 @@ void onChanged( ); /** - * Called when the grid network has been changed. + * Usually called when the grid network has been changed. */ - void onNetworkChanged(); + void clear(); } diff --git a/refinedstorage2-grid-api/src/main/java/com/refinedmods/refinedstorage2/api/grid/operations/GridOperationsImpl.java b/refinedstorage2-grid-api/src/main/java/com/refinedmods/refinedstorage2/api/grid/operations/GridOperationsImpl.java index 8100984e8..77bb71bf3 100644 --- a/refinedstorage2-grid-api/src/main/java/com/refinedmods/refinedstorage2/api/grid/operations/GridOperationsImpl.java +++ b/refinedstorage2-grid-api/src/main/java/com/refinedmods/refinedstorage2/api/grid/operations/GridOperationsImpl.java @@ -36,7 +36,8 @@ public GridOperationsImpl(final StorageChannel storageChannel, } @Override - public boolean extract(final T resource, final GridExtractMode extractMode, + public boolean extract(final T resource, + final GridExtractMode extractMode, final InsertableStorage destination) { final long amount = getExtractableAmount(resource, extractMode); if (amount == 0) { diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/grid/GridWatcherRegistration.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/grid/GridWatcherRegistration.java index 08375eb5e..10cfa32bd 100644 --- a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/grid/GridWatcherRegistration.java +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/grid/GridWatcherRegistration.java @@ -9,17 +9,17 @@ import java.util.HashMap; import java.util.Map; -public class GridWatcherRegistration { +class GridWatcherRegistration { private final GridWatcher watcher; private final Class actorType; private final Map, ResourceListListener> listeners = new HashMap<>(); - public GridWatcherRegistration(final GridWatcher watcher, final Class actorType) { + GridWatcherRegistration(final GridWatcher watcher, final Class actorType) { this.watcher = watcher; this.actorType = actorType; } - public void attach(final StorageChannel storageChannel, final StorageChannelType storageChannelType) { + void attach(final StorageChannel storageChannel, final StorageChannelType storageChannelType) { final ResourceListListener listener = change -> watcher.onChanged( storageChannelType, change.resourceAmount().getResource(), @@ -34,7 +34,7 @@ public void attach(final StorageChannel storageChannel, final StorageChan } @SuppressWarnings("unchecked") - public void detach(final StorageChannel storageChannel, final StorageChannelType storageChannelType) { + void detach(final StorageChannel storageChannel, final StorageChannelType storageChannelType) { final ResourceListListener listener = (ResourceListListener) listeners.get(storageChannelType); storageChannel.removeListener(listener); listeners.remove(storageChannelType); diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/grid/GridWatchers.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/grid/GridWatchers.java index 1c2da61a2..583e650cb 100644 --- a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/grid/GridWatchers.java +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/grid/GridWatchers.java @@ -44,7 +44,7 @@ public void addWatcher( public void attachAll(final Network network) { watchers.forEach((watcher, registration) -> { - watcher.onNetworkChanged(); + watcher.clear(); attachAll(registration, network); }); } diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/PriorityNetworkBuilderImplTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/PriorityNetworkBuilderImplTest.java index 749d01af3..fd2223ed4 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/PriorityNetworkBuilderImplTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/PriorityNetworkBuilderImplTest.java @@ -76,7 +76,7 @@ void shouldRespectPriorityWhenSplitting() { // Here we ensure that container 4 (the grid) is initialized *after* container 3 (the storage), // according to the priority declared above. - verify(watcher, times(1)).onNetworkChanged(); + verify(watcher, times(1)).clear(); verify(watcher).onChanged( NetworkTestFixtures.STORAGE_CHANNEL_TYPE, "N3", diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/grid/GridNetworkNodeTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/grid/GridNetworkNodeTest.java index 76c337178..d50980f9e 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/grid/GridNetworkNodeTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/grid/GridNetworkNodeTest.java @@ -158,7 +158,7 @@ void shouldDetachWatchersFromOldNetworkAndReattachToNewNetwork( storageChannel.insert("D", 10, Action.EXECUTE, EmptyActor.INSTANCE); // Assert - verify(watcher, times(1)).onNetworkChanged(); + verify(watcher, times(1)).clear(); final ArgumentCaptor trackedResources1 = ArgumentCaptor.forClass(TrackedResource.class); verify(watcher, times(1)).onChanged( 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 a7db7f229..641f995fb 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 @@ -55,6 +55,9 @@ import com.refinedmods.refinedstorage2.platform.common.networking.NetworkReceiverBlockEntity; import com.refinedmods.refinedstorage2.platform.common.networking.NetworkTransmitterBlockEntity; import com.refinedmods.refinedstorage2.platform.common.networking.NetworkTransmitterContainerMenu; +import com.refinedmods.refinedstorage2.platform.common.portablegrid.PortableGridBlock; +import com.refinedmods.refinedstorage2.platform.common.portablegrid.PortableGridItem; +import com.refinedmods.refinedstorage2.platform.common.portablegrid.PortableGridType; import com.refinedmods.refinedstorage2.platform.common.storage.FluidStorageType; import com.refinedmods.refinedstorage2.platform.common.storage.ItemStorageType; import com.refinedmods.refinedstorage2.platform.common.storage.StorageTypes; @@ -122,6 +125,7 @@ import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.CONTROLLER; 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; @@ -137,6 +141,7 @@ import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.MACHINE_CASING; import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.NETWORK_RECEIVER; import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.NETWORK_TRANSMITTER; +import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.PORTABLE_GRID; import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.PROCESSOR_BINDING; import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.QUARTZ_ENRICHED_IRON; import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.QUARTZ_ENRICHED_IRON_BLOCK; @@ -279,6 +284,12 @@ protected final void registerBlocks( Blocks.INSTANCE.setStorageMonitor(callback.register(STORAGE_MONITOR, StorageMonitorBlock::new)); Blocks.INSTANCE.getNetworkReceiver().registerBlocks(callback); Blocks.INSTANCE.getNetworkTransmitter().registerBlocks(callback); + Blocks.INSTANCE.setPortableGrid(callback.register(PORTABLE_GRID, () -> new PortableGridBlock( + PortableGridType.NORMAL + ))); + Blocks.INSTANCE.setCreativePortableGrid(callback.register(CREATIVE_PORTABLE_GRID, () -> new PortableGridBlock( + PortableGridType.CREATIVE + ))); } protected final void registerItems( @@ -310,6 +321,14 @@ protected final void registerItems( creativeWirelessGridItemSupplier )); callback.register(STORAGE_MONITOR, () -> new SimpleBlockItem(Blocks.INSTANCE.getStorageMonitor())); + Items.INSTANCE.setPortableGrid(callback.register( + PORTABLE_GRID, + () -> new PortableGridItem(Blocks.INSTANCE.getPortableGrid()) + )); + Items.INSTANCE.setCreativePortableGrid(callback.register( + CREATIVE_PORTABLE_GRID, + () -> new PortableGridItem(Blocks.INSTANCE.getCreativePortableGrid()) + )); } private void registerSimpleItems(final RegistryCallback callback) { diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/Blocks.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/Blocks.java index a4697c046..dc0951d89 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/Blocks.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/Blocks.java @@ -14,6 +14,7 @@ import com.refinedmods.refinedstorage2.platform.common.networking.CableBlock; import com.refinedmods.refinedstorage2.platform.common.networking.NetworkReceiverBlock; import com.refinedmods.refinedstorage2.platform.common.networking.NetworkTransmitterBlock; +import com.refinedmods.refinedstorage2.platform.common.portablegrid.PortableGridBlock; import com.refinedmods.refinedstorage2.platform.common.storage.FluidStorageType; import com.refinedmods.refinedstorage2.platform.common.storage.ItemStorageType; import com.refinedmods.refinedstorage2.platform.common.storage.diskdrive.DiskDriveBlock; @@ -26,12 +27,13 @@ import java.util.EnumMap; import java.util.Map; -import java.util.Objects; import java.util.function.Supplier; import javax.annotation.Nullable; import net.minecraft.world.item.DyeColor; +import static java.util.Objects.requireNonNull; + public final class Blocks { public static final DyeColor COLOR = DyeColor.LIGHT_BLUE; public static final DyeColor CABLE_LIKE_COLOR = DyeColor.GRAY; @@ -146,6 +148,10 @@ public final class Blocks { private Supplier iface; @Nullable private Supplier storageMonitor; + @Nullable + private Supplier portableGrid; + @Nullable + private Supplier creativePortableGrid; private Blocks() { } @@ -155,15 +161,15 @@ public BlockColorMap getCable() { } public SimpleBlock getQuartzEnrichedIronBlock() { - return Objects.requireNonNull(quartzEnrichedIronBlock).get(); + return requireNonNull(quartzEnrichedIronBlock).get(); } public DiskDriveBlock getDiskDrive() { - return Objects.requireNonNull(diskDrive).get(); + return requireNonNull(diskDrive).get(); } public SimpleBlock getMachineCasing() { - return Objects.requireNonNull(machineCasing).get(); + return requireNonNull(machineCasing).get(); } public BlockColorMap getGrid() { @@ -224,7 +230,7 @@ public void setInterface(final Supplier interfaceSupplier) { } public InterfaceBlock getInterface() { - return Objects.requireNonNull(iface).get(); + return requireNonNull(iface).get(); } public BlockColorMap getExternalStorage() { @@ -252,7 +258,7 @@ public void setStorageMonitor(final Supplier supplier) { } public StorageMonitorBlock getStorageMonitor() { - return Objects.requireNonNull(storageMonitor).get(); + return requireNonNull(storageMonitor).get(); } public BlockColorMap getNetworkReceiver() { @@ -262,4 +268,20 @@ public BlockColorMap getNetworkReceiver() { public BlockColorMap getNetworkTransmitter() { return networkTransmitter; } + + public PortableGridBlock getPortableGrid() { + return requireNonNull(portableGrid).get(); + } + + public void setPortableGrid(final Supplier supplier) { + this.portableGrid = supplier; + } + + public PortableGridBlock getCreativePortableGrid() { + return requireNonNull(creativePortableGrid).get(); + } + + public void setCreativePortableGrid(final Supplier supplier) { + this.creativePortableGrid = supplier; + } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/ContentIds.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/ContentIds.java index 60a9b1567..0eb7ca2bb 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/ContentIds.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/ContentIds.java @@ -52,6 +52,8 @@ public final class ContentIds { public static final ResourceLocation NETWORK_RECEIVER = createIdentifier("network_receiver"); public static final ResourceLocation NETWORK_CARD = createIdentifier("network_card"); public static final ResourceLocation NETWORK_TRANSMITTER = createIdentifier("network_transmitter"); + public static final ResourceLocation PORTABLE_GRID = createIdentifier("portable_grid"); + public static final ResourceLocation CREATIVE_PORTABLE_GRID = createIdentifier("creative_portable_grid"); private ContentIds() { } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/CreativeModeTabItems.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/CreativeModeTabItems.java index cce630748..3922cecbd 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/CreativeModeTabItems.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/CreativeModeTabItems.java @@ -36,6 +36,8 @@ private static void appendBlocks(final Consumer consumer) { itemConsumer.accept(Blocks.INSTANCE.getDiskDrive()); appendBlockColors(consumer, Blocks.INSTANCE.getGrid()); appendBlockColors(consumer, Blocks.INSTANCE.getCraftingGrid()); + itemConsumer.accept(Items.INSTANCE.getPortableGrid()); + itemConsumer.accept(Items.INSTANCE.getCreativePortableGrid()); Items.INSTANCE.getDetectors().stream().map(Supplier::get).forEach(itemConsumer); itemConsumer.accept(Blocks.INSTANCE.getInterface()); Arrays.stream(ItemStorageType.Variant.values()).forEach(variant -> itemConsumer.accept( diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/Items.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/Items.java index 019ed46b0..0c70f63b7 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/Items.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/Items.java @@ -11,13 +11,14 @@ import java.util.EnumMap; import java.util.List; import java.util.Map; -import java.util.Objects; import java.util.function.Supplier; import javax.annotation.Nullable; import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.Item; +import static java.util.Objects.requireNonNull; + public final class Items { public static final Items INSTANCE = new Items(); @@ -84,6 +85,10 @@ public final class Items { private Supplier configurationCard; @Nullable private Supplier networkCard; + @Nullable + private Supplier portableGrid; + @Nullable + private Supplier creativePortableGrid; private Items() { } @@ -125,7 +130,7 @@ public void setQuartzEnrichedIron(final Supplier supplier) { } public Item getQuartzEnrichedIron() { - return Objects.requireNonNull(quartzEnrichedIron).get(); + return requireNonNull(quartzEnrichedIron).get(); } public void setSilicon(final Supplier supplier) { @@ -133,7 +138,7 @@ public void setSilicon(final Supplier supplier) { } public Item getSilicon() { - return Objects.requireNonNull(silicon).get(); + return requireNonNull(silicon).get(); } public void setProcessorBinding(final Supplier supplier) { @@ -141,7 +146,7 @@ public void setProcessorBinding(final Supplier supplier) { } public Item getProcessorBinding() { - return Objects.requireNonNull(processorBinding).get(); + return requireNonNull(processorBinding).get(); } public void setWrench(final Supplier supplier) { @@ -149,7 +154,7 @@ public void setWrench(final Supplier supplier) { } public Item getWrench() { - return Objects.requireNonNull(wrench).get(); + return requireNonNull(wrench).get(); } public void setProcessor(final ProcessorItem.Type type, final Supplier supplier) { @@ -157,7 +162,7 @@ public void setProcessor(final ProcessorItem.Type type, final Supplier sup } public Item getProcessor(final ProcessorItem.Type type) { - return Objects.requireNonNull(processors.get(type)).get(); + return requireNonNull(processors.get(type)).get(); } public void setConstructionCore(final Supplier supplier) { @@ -165,7 +170,7 @@ public void setConstructionCore(final Supplier supplier) { } public Item getConstructionCore() { - return Objects.requireNonNull(constructionCore).get(); + return requireNonNull(constructionCore).get(); } public void setDestructionCore(final Supplier supplier) { @@ -173,7 +178,7 @@ public void setDestructionCore(final Supplier supplier) { } public Item getDestructionCore() { - return Objects.requireNonNull(destructionCore).get(); + return requireNonNull(destructionCore).get(); } public void addCreativeController(final Supplier supplier) { @@ -257,7 +262,7 @@ public List> getWirelessTransmitters() { } public Item getStorageHousing() { - return Objects.requireNonNull(storageHousing).get(); + return requireNonNull(storageHousing).get(); } public void setStorageHousing(final Supplier supplier) { @@ -269,11 +274,11 @@ public void setUpgrade(final Supplier supplier) { } public Item getUpgrade() { - return Objects.requireNonNull(upgrade).get(); + return requireNonNull(upgrade).get(); } public AbstractUpgradeItem getSpeedUpgrade() { - return Objects.requireNonNull(speedUpgrade).get(); + return requireNonNull(speedUpgrade).get(); } public void setSpeedUpgrade(final Supplier supplier) { @@ -281,7 +286,7 @@ public void setSpeedUpgrade(final Supplier suppli } public AbstractUpgradeItem getStackUpgrade() { - return Objects.requireNonNull(stackUpgrade).get(); + return requireNonNull(stackUpgrade).get(); } public void setStackUpgrade(final Supplier supplier) { @@ -289,7 +294,7 @@ public void setStackUpgrade(final Supplier suppli } public AbstractUpgradeItem getFortune1Upgrade() { - return Objects.requireNonNull(fortune1Upgrade).get(); + return requireNonNull(fortune1Upgrade).get(); } public void setFortune1Upgrade(final Supplier fortune1Upgrade) { @@ -297,7 +302,7 @@ public void setFortune1Upgrade(final Supplier for } public AbstractUpgradeItem getFortune2Upgrade() { - return Objects.requireNonNull(fortune2Upgrade).get(); + return requireNonNull(fortune2Upgrade).get(); } public void setFortune2Upgrade(final Supplier fortune2Upgrade) { @@ -305,7 +310,7 @@ public void setFortune2Upgrade(final Supplier for } public AbstractUpgradeItem getFortune3Upgrade() { - return Objects.requireNonNull(fortune3Upgrade).get(); + return requireNonNull(fortune3Upgrade).get(); } public void setFortune3Upgrade(final Supplier fortune3Upgrade) { @@ -313,7 +318,7 @@ public void setFortune3Upgrade(final Supplier for } public AbstractUpgradeItem getSilkTouchUpgrade() { - return Objects.requireNonNull(silkTouchUpgrade).get(); + return requireNonNull(silkTouchUpgrade).get(); } public void setSilkTouchUpgrade(final Supplier silkTouchUpgrade) { @@ -321,7 +326,7 @@ public void setSilkTouchUpgrade(final Supplier si } public AbstractUpgradeItem getRegulatorUpgrade() { - return Objects.requireNonNull(regulatorUpgrade).get(); + return requireNonNull(regulatorUpgrade).get(); } public void setRegulatorUpgrade(final Supplier regulatorUpgrade) { @@ -329,7 +334,7 @@ public void setRegulatorUpgrade(final Supplier re } public AbstractUpgradeItem getRangeUpgrade() { - return Objects.requireNonNull(rangeUpgrade).get(); + return requireNonNull(rangeUpgrade).get(); } public void setRangeUpgrade(final Supplier rangeUpgrade) { @@ -337,7 +342,7 @@ public void setRangeUpgrade(final Supplier rangeU } public AbstractUpgradeItem getCreativeRangeUpgrade() { - return Objects.requireNonNull(creativeRangeUpgrade).get(); + return requireNonNull(creativeRangeUpgrade).get(); } public void setCreativeRangeUpgrade(final Supplier creativeRangeUpgrade) { @@ -345,7 +350,7 @@ public void setCreativeRangeUpgrade(final Supplier supplier) { @@ -353,7 +358,7 @@ public void setWirelessGrid(final Supplier supplier) { } public WirelessGridItem getCreativeWirelessGrid() { - return Objects.requireNonNull(creativeWirelessGrid).get(); + return requireNonNull(creativeWirelessGrid).get(); } public void setCreativeWirelessGrid(final Supplier supplier) { @@ -361,7 +366,7 @@ public void setCreativeWirelessGrid(final Supplier supplier) { } public Item getConfigurationCard() { - return Objects.requireNonNull(configurationCard).get(); + return requireNonNull(configurationCard).get(); } public void setConfigurationCard(final Supplier supplier) { @@ -385,10 +390,26 @@ public List> getNetworkTransmitters() { } public Item getNetworkCard() { - return Objects.requireNonNull(networkCard).get(); + return requireNonNull(networkCard).get(); } public void setNetworkCard(final Supplier supplier) { this.networkCard = supplier; } + + public Item getPortableGrid() { + return requireNonNull(portableGrid).get(); + } + + public void setPortableGrid(final Supplier supplier) { + this.portableGrid = supplier; + } + + public Item getCreativePortableGrid() { + return requireNonNull(creativePortableGrid).get(); + } + + public void setCreativePortableGrid(final Supplier supplier) { + this.creativePortableGrid = supplier; + } } 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 1b0d3691e..0af0e65c3 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 @@ -283,7 +283,7 @@ public void onChanged( } @Override - public void onNetworkChanged() { + public void clear() { if (playerInventory.player instanceof ServerPlayer serverPlayer) { initStrategies(); Platform.INSTANCE.getServerToClientCommunications().sendGridClear(serverPlayer); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/portablegrid/PortableGridBlock.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/portablegrid/PortableGridBlock.java new file mode 100644 index 000000000..7c56adf32 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/portablegrid/PortableGridBlock.java @@ -0,0 +1,52 @@ +package com.refinedmods.refinedstorage2.platform.common.portablegrid; + +import com.refinedmods.refinedstorage2.platform.common.content.BlockConstants; +import com.refinedmods.refinedstorage2.platform.common.support.AbstractDirectionalBlock; +import com.refinedmods.refinedstorage2.platform.common.support.direction.BiDirection; +import com.refinedmods.refinedstorage2.platform.common.support.direction.BiDirectionType; +import com.refinedmods.refinedstorage2.platform.common.support.direction.DirectionType; + +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.VoxelShape; + +public class PortableGridBlock extends AbstractDirectionalBlock { + private static final VoxelShape SHAPE_HORIZONTAL = box(0, 0, 0, 16, 13.2, 16); + private static final VoxelShape SHAPE_VERTICAL_SOUTH = box(0, 0, 0, 16, 16, 13.2); + private static final VoxelShape SHAPE_VERTICAL_NORTH = box(0, 0, 16 - 13.2, 16, 16, 16); + private static final VoxelShape SHAPE_VERTICAL_EAST = box(0, 0, 0, 13.2, 16, 16); + private static final VoxelShape SHAPE_VERTICAL_WEST = box(16 - 13.2, 0, 0, 16, 16, 16); + + private final PortableGridType type; + + public PortableGridBlock(final PortableGridType type) { + super(BlockConstants.PROPERTIES); + this.type = type; + } + + @Override + protected DirectionType getDirectionType() { + return BiDirectionType.INSTANCE; + } + + @Override + @SuppressWarnings("deprecation") + public VoxelShape getShape(final BlockState state, + final BlockGetter level, + final BlockPos pos, + final CollisionContext ctx) { + final BiDirection direction = getDirection(state); + if (direction == null) { + return SHAPE_HORIZONTAL; + } + return switch (direction) { + case UP_SOUTH, DOWN_SOUTH -> SHAPE_VERTICAL_SOUTH; + case UP_NORTH, DOWN_NORTH -> SHAPE_VERTICAL_NORTH; + case UP_EAST, DOWN_EAST -> SHAPE_VERTICAL_EAST; + case UP_WEST, DOWN_WEST -> SHAPE_VERTICAL_WEST; + default -> SHAPE_HORIZONTAL; + }; + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/portablegrid/PortableGridBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/portablegrid/PortableGridBlockEntity.java new file mode 100644 index 000000000..7d684927e --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/portablegrid/PortableGridBlockEntity.java @@ -0,0 +1,57 @@ +package com.refinedmods.refinedstorage2.platform.common.portablegrid; + +import com.refinedmods.refinedstorage2.api.grid.GridWatcher; +import com.refinedmods.refinedstorage2.api.grid.operations.GridOperations; +import com.refinedmods.refinedstorage2.api.storage.Actor; +import com.refinedmods.refinedstorage2.api.storage.Storage; +import com.refinedmods.refinedstorage2.api.storage.TrackedResourceAmount; +import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannelType; +import com.refinedmods.refinedstorage2.platform.api.grid.Grid; +import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; +import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; + +import java.util.List; + +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.BlockState; + +public class PortableGridBlockEntity extends BlockEntity implements Grid { + + + public PortableGridBlockEntity(final BlockPos pos, final BlockState state) { + super($$0, pos, state); + } + + @Override + public void addWatcher(final GridWatcher watcher, final Class actorType) { + + } + + @Override + public void removeWatcher(final GridWatcher watcher) { + + } + + @Override + public Storage getItemStorage() { + return null; + } + + @Override + public boolean isGridActive() { + return false; + } + + @Override + public List> getResources(final StorageChannelType type, + final Class actorType) { + return null; + } + + @Override + public GridOperations createOperations(final PlatformStorageChannelType storageChannelType, + final Actor actor) { + return null; + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/portablegrid/PortableGridItem.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/portablegrid/PortableGridItem.java new file mode 100644 index 000000000..84324e9d7 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/portablegrid/PortableGridItem.java @@ -0,0 +1,11 @@ +package com.refinedmods.refinedstorage2.platform.common.portablegrid; + +import net.minecraft.world.item.BlockItem; +import net.minecraft.world.item.Item; +import net.minecraft.world.level.block.Block; + +public class PortableGridItem extends BlockItem { + public PortableGridItem(final Block block) { + super(block, new Item.Properties().stacksTo(1)); + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/portablegrid/PortableGridType.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/portablegrid/PortableGridType.java new file mode 100644 index 000000000..93cd284d4 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/portablegrid/PortableGridType.java @@ -0,0 +1,6 @@ +package com.refinedmods.refinedstorage2.platform.common.portablegrid; + +public enum PortableGridType { + NORMAL, + CREATIVE +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/portablegrid/PortableGridWatcherRegistration.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/portablegrid/PortableGridWatcherRegistration.java new file mode 100644 index 000000000..2f53c1d90 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/portablegrid/PortableGridWatcherRegistration.java @@ -0,0 +1,7 @@ +package com.refinedmods.refinedstorage2.platform.common.portablegrid; + +import com.refinedmods.refinedstorage2.api.grid.GridWatcher; +import com.refinedmods.refinedstorage2.api.storage.Actor; + +record PortableGridWatcherRegistration(GridWatcher watcher, Class actorType) { +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/portablegrid/package-info.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/portablegrid/package-info.java new file mode 100644 index 000000000..cc5747491 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/portablegrid/package-info.java @@ -0,0 +1,7 @@ +@ParametersAreNonnullByDefault +@FieldsAndMethodsAreNonnullByDefault +package com.refinedmods.refinedstorage2.platform.common.portablegrid; + +import com.refinedmods.refinedstorage2.api.core.FieldsAndMethodsAreNonnullByDefault; + +import javax.annotation.ParametersAreNonnullByDefault; diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/blockstates/creative_portable_grid.json b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/blockstates/creative_portable_grid.json new file mode 100644 index 000000000..da5b59a5a --- /dev/null +++ b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/blockstates/creative_portable_grid.json @@ -0,0 +1,7 @@ +{ + "variants": { + "": { + "model": "refinedstorage2:block/portable_grid" + } + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/blockstates/portable_grid.json b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/blockstates/portable_grid.json new file mode 100644 index 000000000..da5b59a5a --- /dev/null +++ b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/blockstates/portable_grid.json @@ -0,0 +1,7 @@ +{ + "variants": { + "": { + "model": "refinedstorage2:block/portable_grid" + } + } +} \ No newline at end of file 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 6d4759f1a..e7ea7a9a2 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 @@ -30,6 +30,8 @@ "block.refinedstorage2.storage_monitor": "Storage Monitor", "block.refinedstorage2.network_receiver": "Network Receiver", "block.refinedstorage2.network_transmitter": "Network Transmitter", + "block.refinedstorage2.portable_grid": "Portable Grid", + "block.refinedstorage2.creative_portable_grid": "Creative Portable Grid", "gui.refinedstorage2.controller.redstone_mode_help": "When this device is inactive, the storage network will not be able to use this device as an energy source.", "gui.refinedstorage2.disk_drive.disks": "Disks", "gui.refinedstorage2.storage.redstone_mode_help": "When this device is inactive, the contained storage will no longer be accessible from within the storage network.", @@ -350,5 +352,7 @@ "advancements.refinedstorage2.better_than_a_barrel": "Better than a barrel", "advancements.refinedstorage2.better_than_a_barrel.description": "Craft a Storage Monitor to view, insert or extract resources in a storage network", "advancements.refinedstorage2.no_cables_required": "No cables required", - "advancements.refinedstorage2.no_cables_required.description": "Add extra components to your network without using cables by using a Network Transmitter, Network Receiver and Network Card" + "advancements.refinedstorage2.no_cables_required.description": "Add extra components to your network without using cables by using a Network Transmitter, Network Receiver and Network Card", + "advancements.refinedstorage2.portable_storage": "Portable storage", + "advancements.refinedstorage2.portable_storage.description": "Craft a Portable Grid to access the content of disks without requiring a storage network" } diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/portable_grid.json b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/portable_grid.json new file mode 100644 index 000000000..c8b32b4d1 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/portable_grid.json @@ -0,0 +1,4 @@ +{ + "__comment": "Forge-only", + "loader": "refinedstorage2:portable_grid" +} diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/portable_grid/active.json b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/portable_grid/active.json new file mode 100644 index 000000000..f25e04be6 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/portable_grid/active.json @@ -0,0 +1,6 @@ +{ + "parent": "refinedstorage2:block/portable_grid/base", + "textures": { + "texture1": "refinedstorage2:block/portable_grid/portable_grid_2" + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/portable_grid/base.json b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/portable_grid/base.json new file mode 100644 index 000000000..26581c128 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/portable_grid/base.json @@ -0,0 +1,558 @@ +{ + "render_type": "cutout", + "parent": "block/cube", + "textures": { + "particle": "refinedstorage2:block/portable_grid/portable_grid_1", + "texture0": "refinedstorage2:block/portable_grid/portable_grid_1", + "texture2": "refinedstorage2:block/portable_grid/portable_grid_3", + "texture3": "refinedstorage2:block/portable_grid/portable_grid_4", + "texture4": "refinedstorage2:block/portable_grid/portable_grid_5", + "texture5": "refinedstorage2:block/portable_grid/portable_grid_6", + "texture6": "refinedstorage2:block/portable_grid/portable_grid_7", + "texture7": "refinedstorage2:block/portable_grid/portable_grid_8" + }, + "display": { + "firstperson_lefthand": { + "rotation": [ + 10, + 130, + 0 + ], + "scale": [ + 0.4, + 0.4, + 0.4 + ], + "translation": [ + 2, + 3.5, + 0 + ] + }, + "firstperson_righthand": { + "rotation": [ + 10, + 130, + 0 + ], + "scale": [ + 0.4, + 0.4, + 0.4 + ], + "translation": [ + 2, + 3.5, + 0 + ] + }, + "thirdperson_lefthand": { + "rotation": [ + 10, + 180, + 0 + ], + "scale": [ + 0.4, + 0.4, + 0.4 + ], + "translation": [ + 0, + 3, + 1 + ] + }, + "thirdperson_righthand": { + "rotation": [ + 10, + 180, + 0 + ], + "scale": [ + 0.4, + 0.4, + 0.4 + ], + "translation": [ + 0, + 3, + 1 + ] + }, + "gui": { + "rotation": [ + 30, + 225, + 0 + ], + "scale": [ + 0.625, + 0.625, + 0.625 + ] + }, + "ground": { + "translation": [ + 0, + 3, + 0 + ], + "scale": [ + 0.25, + 0.25, + 0.25 + ] + }, + "fixed": { + "scale": [ + 0.75, + 0.75, + 0.75 + ] + } + }, + "elements": [ + { + "name": "cube", + "from": [ + 0, + 6, + 5 + ], + "to": [ + 16, + 13, + 7 + ], + "shade": true, + "faces": { + "north": { + "uv": [ + 0, + 7, + 16, + 14 + ], + "texture": "#texture0" + }, + "east": { + "uv": [ + 0, + 7, + 2, + 14 + ], + "texture": "#texture1" + }, + "south": { + "uv": [ + 0, + 0, + 16, + 7 + ], + "texture": "#texture0" + }, + "west": { + "uv": [ + 0, + 0, + 2, + 7 + ], + "texture": "#texture1" + }, + "up": { + "uv": [ + 0, + 0, + 16, + 2 + ], + "texture": "#texture0", + "rotation": 180 + }, + "down": { + "uv": [ + 0, + 13, + 16, + 15 + ], + "texture": "#texture1", + "rotation": 180 + } + }, + "rotation": { + "origin": [ + 8, + 6, + 7 + ], + "axis": "x", + "angle": 22.5 + } + }, + { + "name": "cube", + "from": [ + 0, + 4, + 7 + ], + "to": [ + 16, + 6, + 16 + ], + "shade": true, + "faces": { + "north": { + "uv": [ + 0, + 14, + 16, + 16 + ], + "texture": "#texture0" + }, + "east": { + "uv": [ + 3, + 2, + 12, + 4 + ], + "texture": "#texture1" + }, + "south": { + "uv": [ + 0, + 0, + 16, + 2 + ], + "texture": "#texture2" + }, + "west": { + "uv": [ + 3, + 0, + 12, + 2 + ], + "texture": "#texture1" + }, + "up": { + "uv": [ + 0, + 2, + 16, + 11 + ], + "texture": "#texture2", + "rotation": 180 + }, + "down": { + "uv": [ + 0, + 0, + 16, + 9 + ], + "texture": "#texture3", + "rotation": 180 + } + } + }, + { + "name": "cube", + "from": [ + 0, + 0, + 0 + ], + "to": [ + 16, + 4, + 16 + ], + "shade": true, + "faces": { + "north": { + "uv": [ + 0, + 9, + 16, + 13 + ], + "texture": "#texture3" + }, + "east": { + "uv": [ + 0, + 4, + 16, + 8 + ], + "texture": "#texture4" + }, + "south": { + "uv": [ + 0, + 11, + 16, + 15 + ], + "texture": "#texture2" + }, + "west": { + "uv": [ + 0, + 0, + 16, + 4 + ], + "texture": "#texture4" + }, + "up": { + "uv": [ + 0, + 0, + 16, + 16 + ], + "texture": "#texture5", + "rotation": 180 + }, + "down": { + "uv": [ + 0, + 0, + 16, + 16 + ], + "texture": "#texture6", + "rotation": 180 + } + } + }, + { + "name": "cube", + "from": [ + 1, + 4, + 1 + ], + "to": [ + 15, + 5, + 7 + ], + "shade": true, + "faces": { + "north": { + "uv": [ + 0, + 15, + 14, + 16 + ], + "texture": "#texture2" + }, + "east": { + "uv": [ + 4, + 9, + 10, + 10 + ], + "texture": "#texture1" + }, + "south": { + "uv": [ + 2, + 13, + 16, + 14 + ], + "texture": "#texture1" + }, + "west": { + "uv": [ + 4, + 8, + 10, + 9 + ], + "texture": "#texture1" + }, + "up": { + "uv": [ + 0, + 8, + 14, + 14 + ], + "texture": "#texture4", + "rotation": 180 + }, + "down": { + "uv": [ + 0, + 0, + 14, + 6 + ], + "texture": "#texture7", + "rotation": 180 + } + } + }, + { + "name": "cube", + "from": [ + 3, + 4.5, + 6 + ], + "to": [ + 4, + 6.5, + 8 + ], + "shade": true, + "faces": { + "north": { + "uv": [ + 5, + 10, + 6, + 12 + ], + "texture": "#texture1" + }, + "east": { + "uv": [ + 7, + 4, + 9, + 6 + ], + "texture": "#texture1" + }, + "south": { + "uv": [ + 4, + 10, + 5, + 12 + ], + "texture": "#texture1" + }, + "west": { + "uv": [ + 6, + 10, + 8, + 12 + ], + "texture": "#texture1" + }, + "up": { + "uv": [ + 7, + 6, + 8, + 8 + ], + "texture": "#texture1", + "rotation": 180 + }, + "down": { + "uv": [ + 8, + 6, + 9, + 8 + ], + "texture": "#texture1", + "rotation": 180 + } + } + }, + { + "name": "cube", + "from": [ + 12, + 4.5, + 6 + ], + "to": [ + 13, + 6.5, + 8 + ], + "shade": true, + "faces": { + "north": { + "uv": [ + 9, + 4, + 10, + 6 + ], + "texture": "#texture1" + }, + "east": { + "uv": [ + 9, + 10, + 11, + 12 + ], + "texture": "#texture1" + }, + "south": { + "uv": [ + 8, + 10, + 9, + 12 + ], + "texture": "#texture1" + }, + "west": { + "uv": [ + 9, + 6, + 11, + 8 + ], + "texture": "#texture1" + }, + "up": { + "uv": [ + 7, + 6, + 8, + 8 + ], + "texture": "#texture1", + "rotation": 180 + }, + "down": { + "uv": [ + 8, + 6, + 9, + 8 + ], + "texture": "#texture1", + "rotation": 180 + } + } + } + ] +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/portable_grid/inactive.json b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/portable_grid/inactive.json new file mode 100644 index 000000000..c058e99c2 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/portable_grid/inactive.json @@ -0,0 +1,6 @@ +{ + "parent": "refinedstorage2:block/portable_grid/base", + "textures": { + "texture1": "refinedstorage2:block/portable_grid/portable_grid_2_inactive" + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/item/portable_grid.json b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/item/portable_grid.json new file mode 100644 index 000000000..f5586dcf9 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/item/portable_grid.json @@ -0,0 +1,3 @@ +{ + "parent": "refinedstorage2:block/portable_grid" +} diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/portable_grid/portable_grid_1.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/portable_grid/portable_grid_1.png new file mode 100644 index 000000000..a6b7645a0 Binary files /dev/null and b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/portable_grid/portable_grid_1.png differ diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/portable_grid/portable_grid_2.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/portable_grid/portable_grid_2.png new file mode 100644 index 000000000..d6ee53cd9 Binary files /dev/null and b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/portable_grid/portable_grid_2.png differ diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/portable_grid/portable_grid_2_inactive.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/portable_grid/portable_grid_2_inactive.png new file mode 100644 index 000000000..b492fb8b9 Binary files /dev/null and b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/portable_grid/portable_grid_2_inactive.png differ diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/portable_grid/portable_grid_3.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/portable_grid/portable_grid_3.png new file mode 100644 index 000000000..a8bfc4a33 Binary files /dev/null and b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/portable_grid/portable_grid_3.png differ diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/portable_grid/portable_grid_4.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/portable_grid/portable_grid_4.png new file mode 100644 index 000000000..9988b143c Binary files /dev/null and b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/portable_grid/portable_grid_4.png differ diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/portable_grid/portable_grid_5.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/portable_grid/portable_grid_5.png new file mode 100644 index 000000000..caae64673 Binary files /dev/null and b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/portable_grid/portable_grid_5.png differ diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/portable_grid/portable_grid_6.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/portable_grid/portable_grid_6.png new file mode 100644 index 000000000..b16403740 Binary files /dev/null and b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/portable_grid/portable_grid_6.png differ diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/portable_grid/portable_grid_7.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/portable_grid/portable_grid_7.png new file mode 100644 index 000000000..c36053ec1 Binary files /dev/null and b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/portable_grid/portable_grid_7.png differ diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/portable_grid/portable_grid_8.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/portable_grid/portable_grid_8.png new file mode 100644 index 000000000..d2e2fdcf3 Binary files /dev/null and b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/portable_grid/portable_grid_8.png differ diff --git a/refinedstorage2-platform-common/src/main/resources/data/refinedstorage2/advancements/portable_storage.json b/refinedstorage2-platform-common/src/main/resources/data/refinedstorage2/advancements/portable_storage.json new file mode 100644 index 000000000..d17050d16 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/resources/data/refinedstorage2/advancements/portable_storage.json @@ -0,0 +1,28 @@ +{ + "display": { + "icon": { + "item": "refinedstorage2:portable_grid" + }, + "title": { + "translate": "advancements.refinedstorage2.portable_storage" + }, + "description": { + "translate": "advancements.refinedstorage2.portable_storage.description" + } + }, + "parent": "refinedstorage2:viewing_your_storage", + "criteria": { + "portable_grid_in_inventory": { + "trigger": "minecraft:inventory_changed", + "conditions": { + "items": [ + { + "items": [ + "refinedstorage2:portable_grid" + ] + } + ] + } + } + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/main/resources/data/refinedstorage2/loot_tables/blocks/creative_portable_grid.json b/refinedstorage2-platform-common/src/main/resources/data/refinedstorage2/loot_tables/blocks/creative_portable_grid.json new file mode 100644 index 000000000..ca74fa8fe --- /dev/null +++ b/refinedstorage2-platform-common/src/main/resources/data/refinedstorage2/loot_tables/blocks/creative_portable_grid.json @@ -0,0 +1,19 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "rolls": 1, + "entries": [ + { + "type": "minecraft:item", + "name": "refinedstorage2:creative_portable_grid", + "functions": [ + { + "function": "refinedstorage2:portable_grid" + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/main/resources/data/refinedstorage2/loot_tables/blocks/portable_grid.json b/refinedstorage2-platform-common/src/main/resources/data/refinedstorage2/loot_tables/blocks/portable_grid.json new file mode 100644 index 000000000..a23f17f2a --- /dev/null +++ b/refinedstorage2-platform-common/src/main/resources/data/refinedstorage2/loot_tables/blocks/portable_grid.json @@ -0,0 +1,19 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "rolls": 1, + "entries": [ + { + "type": "minecraft:item", + "name": "refinedstorage2:portable_grid", + "functions": [ + { + "function": "refinedstorage2:portable_grid" + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/main/resources/data/refinedstorage2/recipes/portable_grid.json b/refinedstorage2-platform-common/src/main/resources/data/refinedstorage2/recipes/portable_grid.json new file mode 100644 index 000000000..2fe492a7a --- /dev/null +++ b/refinedstorage2-platform-common/src/main/resources/data/refinedstorage2/recipes/portable_grid.json @@ -0,0 +1,22 @@ +{ + "type": "minecraft:crafting_shaped", + "pattern": [ + "EGE", + "ECE", + "EGE" + ], + "key": { + "E": { + "item": "refinedstorage2:quartz_enriched_iron" + }, + "G": { + "tag": "refinedstorage2:grids" + }, + "C": { + "tag": "refinedstorage2:controllers" + } + }, + "result": { + "item": "refinedstorage2:portable_grid" + } +} \ No newline at end of file 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 b258057b5..6d8533041 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 @@ -35,7 +35,9 @@ import com.refinedmods.refinedstorage2.platform.fabric.recipemod.rei.ReiProxy; import com.refinedmods.refinedstorage2.platform.fabric.storage.diskdrive.DiskDriveBlockEntityRendererImpl; import com.refinedmods.refinedstorage2.platform.fabric.storage.diskdrive.DiskDriveUnbakedModel; +import com.refinedmods.refinedstorage2.platform.fabric.storage.portablegrid.PortableGridUnbakedModel; import com.refinedmods.refinedstorage2.platform.fabric.support.render.EmissiveModelRegistry; +import com.refinedmods.refinedstorage2.platform.fabric.support.render.QuadRotators; import java.util.List; @@ -112,6 +114,8 @@ private void setRenderLayers() { setCutout(Blocks.INSTANCE.getWirelessTransmitter()); setCutout(Blocks.INSTANCE.getNetworkReceiver()); setCutout(Blocks.INSTANCE.getNetworkTransmitter()); + setCutout(Blocks.INSTANCE.getPortableGrid()); + setCutout(Blocks.INSTANCE.getCreativePortableGrid()); } private void setCutout(final BlockColorMap blockMap) { @@ -294,10 +298,23 @@ private void registerBlockEntityRenderers() { private void registerCustomModels() { final ResourceLocation diskDriveIdentifier = createIdentifier("block/disk_drive"); final ResourceLocation diskDriveIdentifierItem = createIdentifier("item/disk_drive"); + + final ResourceLocation portableGridIdentifier = createIdentifier("block/portable_grid"); + final ResourceLocation portableGridIdentifierItem = createIdentifier("item/portable_grid"); + final ResourceLocation creativePortableGridIdentifier = createIdentifier("block/creative_portable_grid"); + final ResourceLocation creativePortableGridIdentifierItem = createIdentifier("item/creative_portable_grid"); + + final QuadRotators quadRotators = new QuadRotators(); ModelLoadingPlugin.register(pluginContext -> pluginContext.resolveModel().register(context -> { if (context.id().equals(diskDriveIdentifier) || context.id().equals(diskDriveIdentifierItem)) { - return new DiskDriveUnbakedModel(); + return new DiskDriveUnbakedModel(quadRotators); + } + if (context.id().equals(portableGridIdentifier) + || context.id().equals(portableGridIdentifierItem) + || context.id().equals(creativePortableGridIdentifier) + || context.id().equals(creativePortableGridIdentifierItem)) { + return new PortableGridUnbakedModel(quadRotators); } return null; })); diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/storage/diskdrive/DiskDriveBakedModel.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/storage/diskdrive/DiskDriveBakedModel.java index 69fc70142..5cf88a38b 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/storage/diskdrive/DiskDriveBakedModel.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/storage/diskdrive/DiskDriveBakedModel.java @@ -5,11 +5,9 @@ import com.refinedmods.refinedstorage2.platform.common.storage.diskdrive.AbstractDiskDriveBlockEntity; import com.refinedmods.refinedstorage2.platform.common.storage.diskdrive.DiskDriveBlock; import com.refinedmods.refinedstorage2.platform.common.support.direction.BiDirection; -import com.refinedmods.refinedstorage2.platform.fabric.support.render.QuadRotator; +import com.refinedmods.refinedstorage2.platform.fabric.support.render.QuadRotators; import com.refinedmods.refinedstorage2.platform.fabric.support.render.QuadTranslator; -import java.util.EnumMap; -import java.util.Map; import java.util.function.Supplier; import net.fabricmc.fabric.api.renderer.v1.model.ForwardingBakedModel; @@ -26,7 +24,6 @@ class DiskDriveBakedModel extends ForwardingBakedModel { private static final QuadTranslator[] TRANSLATORS = new QuadTranslator[8]; - private static final Map ROTATORS = new EnumMap<>(BiDirection.class); static { int i = 0; @@ -39,21 +36,20 @@ class DiskDriveBakedModel extends ForwardingBakedModel { ); } } - - for (final BiDirection direction : BiDirection.values()) { - ROTATORS.put(direction, new QuadRotator(direction)); - } } private final BakedModel diskModel; private final BakedModel diskInactiveModel; + private final QuadRotators quadRotators; DiskDriveBakedModel(final BakedModel baseModel, final BakedModel diskModel, - final BakedModel diskInactiveModel) { + final BakedModel diskInactiveModel, + final QuadRotators quadRotators) { this.wrapped = baseModel; this.diskModel = diskModel; this.diskInactiveModel = diskInactiveModel; + this.quadRotators = quadRotators; } @Override @@ -93,19 +89,14 @@ public void emitBlockQuads(final BlockAndTintGetter blockView, if (direction == null) { return; } - - final QuadRotator rotator = ROTATORS.get(direction); - context.pushTransform(rotator); - + context.pushTransform(quadRotators.forDirection(direction)); super.emitBlockQuads(blockView, state, pos, randomSupplier, context); - if (blockView instanceof RenderAttachedBlockView renderAttachedBlockView) { final Object renderAttachment = renderAttachedBlockView.getBlockEntityRenderAttachment(pos); if (renderAttachment instanceof MultiStorageState states) { emitDiskQuads(blockView, state, pos, randomSupplier, context, states); } } - context.popTransform(); } diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/storage/diskdrive/DiskDriveUnbakedModel.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/storage/diskdrive/DiskDriveUnbakedModel.java index 176c7fa6c..be907191f 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/storage/diskdrive/DiskDriveUnbakedModel.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/storage/diskdrive/DiskDriveUnbakedModel.java @@ -1,7 +1,8 @@ package com.refinedmods.refinedstorage2.platform.fabric.storage.diskdrive; +import com.refinedmods.refinedstorage2.platform.fabric.support.render.QuadRotators; + import java.util.Collection; -import java.util.Objects; import java.util.Set; import java.util.function.Function; import javax.annotation.Nullable; @@ -15,12 +16,19 @@ import net.minecraft.resources.ResourceLocation; import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createIdentifier; +import static java.util.Objects.requireNonNull; public class DiskDriveUnbakedModel implements UnbakedModel { private static final ResourceLocation BASE_MODEL = createIdentifier("block/disk_drive_base"); private static final ResourceLocation DISK_MODEL = createIdentifier("block/disk"); private static final ResourceLocation DISK_INACTIVE_MODEL = createIdentifier("block/disk_inactive"); + private final QuadRotators quadRotators; + + public DiskDriveUnbakedModel(final QuadRotators quadRotators) { + this.quadRotators = quadRotators; + } + @Override public Collection getDependencies() { return Set.of(BASE_MODEL, DISK_MODEL, DISK_INACTIVE_MODEL); @@ -40,9 +48,10 @@ public BakedModel bake(final ModelBaker baker, final ModelState state, final ResourceLocation location) { return new DiskDriveBakedModel( - Objects.requireNonNull(baker.bake(BASE_MODEL, state)), - Objects.requireNonNull(baker.bake(DISK_MODEL, state)), - Objects.requireNonNull(baker.bake(DISK_INACTIVE_MODEL, state)) + requireNonNull(baker.bake(BASE_MODEL, state)), + requireNonNull(baker.bake(DISK_MODEL, state)), + requireNonNull(baker.bake(DISK_INACTIVE_MODEL, state)), + quadRotators ); } } diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/storage/portablegrid/PortableGridBakedModel.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/storage/portablegrid/PortableGridBakedModel.java new file mode 100644 index 000000000..d6d8e600d --- /dev/null +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/storage/portablegrid/PortableGridBakedModel.java @@ -0,0 +1,61 @@ +package com.refinedmods.refinedstorage2.platform.fabric.storage.portablegrid; + +import com.refinedmods.refinedstorage2.platform.common.portablegrid.PortableGridBlock; +import com.refinedmods.refinedstorage2.platform.common.support.direction.BiDirection; +import com.refinedmods.refinedstorage2.platform.fabric.support.render.QuadRotators; + +import java.util.function.Supplier; + +import net.fabricmc.fabric.api.renderer.v1.model.ForwardingBakedModel; +import net.fabricmc.fabric.api.renderer.v1.render.RenderContext; +import net.minecraft.client.resources.model.BakedModel; +import net.minecraft.core.BlockPos; +import net.minecraft.util.RandomSource; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.BlockAndTintGetter; +import net.minecraft.world.level.block.state.BlockState; + +public class PortableGridBakedModel extends ForwardingBakedModel { + private final BakedModel activeModel; + private final BakedModel inactiveModel; + private final QuadRotators quadRotators; + + public PortableGridBakedModel(final BakedModel activeModel, + final BakedModel inactiveModel, + final QuadRotators quadRotators) { + this.wrapped = inactiveModel; + this.activeModel = activeModel; + this.inactiveModel = inactiveModel; + this.quadRotators = quadRotators; + } + + @Override + public boolean isVanillaAdapter() { + return false; + } + + @Override + public void emitItemQuads(final ItemStack stack, + final Supplier randomSupplier, + final RenderContext context) { + inactiveModel.emitItemQuads(stack, randomSupplier, context); + } + + @Override + public void emitBlockQuads(final BlockAndTintGetter blockView, + final BlockState state, + final BlockPos pos, + final Supplier randomSupplier, + final RenderContext context) { + if (!(state.getBlock() instanceof PortableGridBlock portableGridBlock)) { + return; + } + final BiDirection direction = portableGridBlock.getDirection(state); + if (direction == null) { + return; + } + context.pushTransform(quadRotators.forDirection(direction)); + inactiveModel.emitBlockQuads(blockView, state, pos, randomSupplier, context); + context.popTransform(); + } +} diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/storage/portablegrid/PortableGridUnbakedModel.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/storage/portablegrid/PortableGridUnbakedModel.java new file mode 100644 index 000000000..662b17af1 --- /dev/null +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/storage/portablegrid/PortableGridUnbakedModel.java @@ -0,0 +1,52 @@ +package com.refinedmods.refinedstorage2.platform.fabric.storage.portablegrid; + +import com.refinedmods.refinedstorage2.platform.fabric.support.render.QuadRotators; + +import java.util.Collection; +import java.util.Set; +import java.util.function.Function; + +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.client.resources.model.BakedModel; +import net.minecraft.client.resources.model.Material; +import net.minecraft.client.resources.model.ModelBaker; +import net.minecraft.client.resources.model.ModelState; +import net.minecraft.client.resources.model.UnbakedModel; +import net.minecraft.resources.ResourceLocation; + +import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createIdentifier; +import static java.util.Objects.requireNonNull; + +public class PortableGridUnbakedModel implements UnbakedModel { + private static final ResourceLocation ACTIVE_MODEL = createIdentifier("block/portable_grid/active"); + private static final ResourceLocation INACTIVE_MODEL = createIdentifier("block/portable_grid/inactive"); + + private final QuadRotators quadRotators; + + public PortableGridUnbakedModel(final QuadRotators quadRotators) { + this.quadRotators = quadRotators; + } + + @Override + public Collection getDependencies() { + return Set.of(ACTIVE_MODEL, INACTIVE_MODEL); + } + + @Override + public void resolveParents(final Function modelGetter) { + modelGetter.apply(ACTIVE_MODEL).resolveParents(modelGetter); + modelGetter.apply(INACTIVE_MODEL).resolveParents(modelGetter); + } + + @Override + public BakedModel bake(final ModelBaker baker, + final Function spriteGetter, + final ModelState state, + final ResourceLocation location) { + return new PortableGridBakedModel( + requireNonNull(baker.bake(ACTIVE_MODEL, state)), + requireNonNull(baker.bake(INACTIVE_MODEL, state)), + quadRotators + ); + } +} diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/storage/portablegrid/package-info.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/storage/portablegrid/package-info.java new file mode 100644 index 000000000..3ada379be --- /dev/null +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/storage/portablegrid/package-info.java @@ -0,0 +1,7 @@ +@ParametersAreNonnullByDefault +@FieldsAndMethodsAreNonnullByDefault +package com.refinedmods.refinedstorage2.platform.fabric.storage.portablegrid; + +import com.refinedmods.refinedstorage2.api.core.FieldsAndMethodsAreNonnullByDefault; + +import javax.annotation.ParametersAreNonnullByDefault; diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/support/render/QuadRotators.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/support/render/QuadRotators.java new file mode 100644 index 000000000..4b2927cbf --- /dev/null +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/support/render/QuadRotators.java @@ -0,0 +1,20 @@ +package com.refinedmods.refinedstorage2.platform.fabric.support.render; + +import com.refinedmods.refinedstorage2.platform.common.support.direction.BiDirection; + +import java.util.EnumMap; +import java.util.Map; + +public class QuadRotators { + private final Map rotators = new EnumMap<>(BiDirection.class); + + public QuadRotators() { + for (final BiDirection direction : BiDirection.values()) { + rotators.put(direction, new QuadRotator(direction)); + } + } + + public QuadRotator forDirection(final BiDirection direction) { + return rotators.get(direction); + } +}