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..9dcb50317 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,10 @@ 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.AbstractPortableGridBlockEntity; +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 +126,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 +142,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; @@ -244,7 +250,9 @@ private void registerWirelessTransmitterRangeModifiers() { protected final void registerBlocks( final RegistryCallback callback, - final BiFunction diskDriveBlockEntityFactory + final BiFunction diskDriveBlockEntityFactory, + final BiFunction portableGridBlockEntityFactory, + final BiFunction creativePortableGridBlockEntityFactory ) { Blocks.INSTANCE.setQuartzEnrichedIronBlock(callback.register(QUARTZ_ENRICHED_IRON_BLOCK, SimpleBlock::new)); Blocks.INSTANCE.setDiskDrive( @@ -279,6 +287,14 @@ 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, + portableGridBlockEntityFactory + ))); + Blocks.INSTANCE.setCreativePortableGrid(callback.register(CREATIVE_PORTABLE_GRID, () -> new PortableGridBlock( + PortableGridType.CREATIVE, + creativePortableGridBlockEntityFactory + ))); } protected final void registerItems( @@ -310,6 +326,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) { @@ -481,7 +505,11 @@ protected final void registerBlockEntities( final RegistryCallback> callback, final BlockEntityTypeFactory typeFactory, final BlockEntityTypeFactory.BlockEntitySupplier - diskDriveBlockEntitySupplier + diskDriveBlockEntitySupplier, + final BlockEntityTypeFactory.BlockEntitySupplier + portableGridBlockEntitySupplier, + final BlockEntityTypeFactory.BlockEntitySupplier + creativePortableGridBlockEntitySupplier ) { BlockEntities.INSTANCE.setCable(callback.register( CABLE, @@ -588,6 +616,17 @@ protected final void registerBlockEntities( Blocks.INSTANCE.getNetworkTransmitter().toArray() ) )); + BlockEntities.INSTANCE.setPortableGrid(callback.register( + PORTABLE_GRID, + () -> typeFactory.create(portableGridBlockEntitySupplier::create, Blocks.INSTANCE.getPortableGrid()) + )); + BlockEntities.INSTANCE.setCreativePortableGrid(callback.register( + CREATIVE_PORTABLE_GRID, + () -> typeFactory.create( + creativePortableGridBlockEntitySupplier::create, + Blocks.INSTANCE.getCreativePortableGrid() + ) + )); } protected final void registerMenus(final RegistryCallback> callback, diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/BlockEntities.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/BlockEntities.java index e6ba28b83..4730b18fe 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/BlockEntities.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/BlockEntities.java @@ -12,6 +12,7 @@ import com.refinedmods.refinedstorage2.platform.common.importer.ImporterBlockEntity; import com.refinedmods.refinedstorage2.platform.common.networking.NetworkReceiverBlockEntity; import com.refinedmods.refinedstorage2.platform.common.networking.NetworkTransmitterBlockEntity; +import com.refinedmods.refinedstorage2.platform.common.portablegrid.AbstractPortableGridBlockEntity; import com.refinedmods.refinedstorage2.platform.common.storage.FluidStorageType; import com.refinedmods.refinedstorage2.platform.common.storage.ItemStorageType; import com.refinedmods.refinedstorage2.platform.common.storage.diskdrive.AbstractDiskDriveBlockEntity; @@ -24,12 +25,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.level.block.entity.BlockEntityType; +import static java.util.Objects.requireNonNull; + public final class BlockEntities { public static final BlockEntities INSTANCE = new BlockEntities(); @@ -71,12 +73,16 @@ public final class BlockEntities { private Supplier> networkReceiver; @Nullable private Supplier> networkTransmitter; + @Nullable + private Supplier> portableGrid; + @Nullable + private Supplier> creativePortableGrid; private BlockEntities() { } public BlockEntityType> getCable() { - return Objects.requireNonNull(cable).get(); + return requireNonNull(cable).get(); } public void setCable( @@ -86,7 +92,7 @@ public void setCable( } public BlockEntityType getDiskDrive() { - return Objects.requireNonNull(diskDrive).get(); + return requireNonNull(diskDrive).get(); } public void setDiskDrive(final Supplier> supplier) { @@ -94,7 +100,7 @@ public void setDiskDrive(final Supplier getGrid() { - return Objects.requireNonNull(grid).get(); + return requireNonNull(grid).get(); } public void setGrid(final Supplier> supplier) { @@ -102,7 +108,7 @@ public void setGrid(final Supplier> supplier) { } public BlockEntityType getCraftingGrid() { - return Objects.requireNonNull(craftingGrid).get(); + return requireNonNull(craftingGrid).get(); } public void setCraftingGrid(final Supplier> supplier) { @@ -110,7 +116,7 @@ public void setCraftingGrid(final Supplier getController() { - return Objects.requireNonNull(controller).get(); + return requireNonNull(controller).get(); } public void setController(final Supplier> supplier) { @@ -118,7 +124,7 @@ public void setController(final Supplier> } public BlockEntityType getCreativeController() { - return Objects.requireNonNull(creativeController).get(); + return requireNonNull(creativeController).get(); } public void setCreativeController(final Supplier> supplier) { @@ -144,7 +150,7 @@ public BlockEntityType getFluidStorageBlock(final } public BlockEntityType getImporter() { - return Objects.requireNonNull(importer).get(); + return requireNonNull(importer).get(); } public void setImporter(final Supplier> supplier) { @@ -152,7 +158,7 @@ public void setImporter(final Supplier> sup } public BlockEntityType getExporter() { - return Objects.requireNonNull(exporter).get(); + return requireNonNull(exporter).get(); } public void setExporter(final Supplier> supplier) { @@ -160,7 +166,7 @@ public void setExporter(final Supplier> sup } public BlockEntityType getInterface() { - return Objects.requireNonNull(iface).get(); + return requireNonNull(iface).get(); } public void setInterface(final Supplier> supplier) { @@ -168,7 +174,7 @@ public void setInterface(final Supplier> s } public BlockEntityType getExternalStorage() { - return Objects.requireNonNull(externalStorage).get(); + return requireNonNull(externalStorage).get(); } public void setExternalStorage(final Supplier> supplier) { @@ -176,7 +182,7 @@ public void setExternalStorage(final Supplier getDetector() { - return Objects.requireNonNull(detector).get(); + return requireNonNull(detector).get(); } public void setDetector(final Supplier> supplier) { @@ -184,7 +190,7 @@ public void setDetector(final Supplier> sup } public BlockEntityType getDestructor() { - return Objects.requireNonNull(destructor).get(); + return requireNonNull(destructor).get(); } public void setDestructor(final Supplier> supplier) { @@ -192,7 +198,7 @@ public void setDestructor(final Supplier> } public BlockEntityType getConstructor() { - return Objects.requireNonNull(constructor).get(); + return requireNonNull(constructor).get(); } public void setConstructor(final Supplier> supplier) { @@ -200,7 +206,7 @@ public void setConstructor(final Supplier getWirelessTransmitter() { - return Objects.requireNonNull(wirelessTransmitter).get(); + return requireNonNull(wirelessTransmitter).get(); } public void setWirelessTransmitter(final Supplier> supplier) { @@ -208,7 +214,7 @@ public void setWirelessTransmitter(final Supplier getStorageMonitor() { - return Objects.requireNonNull(storageMonitor).get(); + return requireNonNull(storageMonitor).get(); } public void setStorageMonitor(final Supplier> supplier) { @@ -216,7 +222,7 @@ public void setStorageMonitor(final Supplier getNetworkReceiver() { - return Objects.requireNonNull(networkReceiver).get(); + return requireNonNull(networkReceiver).get(); } public void setNetworkReceiver(final Supplier> supplier) { @@ -224,12 +230,26 @@ public void setNetworkReceiver(final Supplier getNetworkTransmitter() { - return Objects.requireNonNull(networkTransmitter).get(); + return requireNonNull(networkTransmitter).get(); } - public void setNetworkTransmitter( - final Supplier> supplier - ) { + public void setNetworkTransmitter(final Supplier> supplier) { this.networkTransmitter = supplier; } + + public BlockEntityType getPortableGrid() { + return requireNonNull(portableGrid).get(); + } + + public void setPortableGrid(final Supplier> supplier) { + this.portableGrid = supplier; + } + + public BlockEntityType 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/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/AbstractPortableGridBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/portablegrid/AbstractPortableGridBlockEntity.java new file mode 100644 index 000000000..55bdd2dda --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/portablegrid/AbstractPortableGridBlockEntity.java @@ -0,0 +1,40 @@ +package com.refinedmods.refinedstorage2.platform.common.portablegrid; + +import com.refinedmods.refinedstorage2.api.network.impl.node.StorageState; +import com.refinedmods.refinedstorage2.platform.common.content.BlockEntities; +import com.refinedmods.refinedstorage2.platform.common.content.Items; +import com.refinedmods.refinedstorage2.platform.common.storage.Disk; +import com.refinedmods.refinedstorage2.platform.common.storage.ItemStorageType; + +import javax.annotation.Nullable; + +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.level.block.state.BlockState; + +public abstract class AbstractPortableGridBlockEntity extends BlockEntity { + @Nullable + protected Disk disk = new Disk( + Items.INSTANCE.getItemStorageDisk(ItemStorageType.Variant.ONE_K), + StorageState.NEAR_CAPACITY + ); + + protected AbstractPortableGridBlockEntity(final PortableGridType type, final BlockPos pos, final BlockState state) { + super(getBlockEntityType(type), pos, state); + } + + protected void onDriveStateUpdated() { + if (level == null) { + return; + } + level.sendBlockUpdated(getBlockPos(), getBlockState(), getBlockState(), Block.UPDATE_ALL); + } + + private static BlockEntityType getBlockEntityType(final PortableGridType type) { + return type == PortableGridType.CREATIVE + ? BlockEntities.INSTANCE.getCreativePortableGrid() + : BlockEntities.INSTANCE.getPortableGrid(); + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/portablegrid/AbstractPortableGridBlockEntityRenderer.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/portablegrid/AbstractPortableGridBlockEntityRenderer.java new file mode 100644 index 000000000..1cbc7f811 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/portablegrid/AbstractPortableGridBlockEntityRenderer.java @@ -0,0 +1,65 @@ +package com.refinedmods.refinedstorage2.platform.common.portablegrid; + +import com.refinedmods.refinedstorage2.platform.common.storage.Disk; +import com.refinedmods.refinedstorage2.platform.common.support.direction.BiDirection; +import com.refinedmods.refinedstorage2.platform.common.support.render.AbstractDiskLedBlockEntityRenderer; + +import javax.annotation.Nullable; + +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.blaze3d.vertex.VertexConsumer; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.core.Direction; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.state.BlockState; + +public abstract class AbstractPortableGridBlockEntityRenderer + extends AbstractDiskLedBlockEntityRenderer { + private final RenderType renderType; + + protected AbstractPortableGridBlockEntityRenderer(final RenderType renderType) { + this.renderType = renderType; + } + + @Nullable + protected abstract Disk getDisk(T blockEntity); + + @Override + public void render(final T entity, + final float tickDelta, + final PoseStack poseStack, + final MultiBufferSource vertexConsumers, + final int light, + final int overlay) { + final Level level = entity.getLevel(); + if (level == null) { + return; + } + final BlockState blockState = level.getBlockState(entity.getBlockPos()); + if (!(blockState.getBlock() instanceof PortableGridBlock portableGridBlock)) { + return; + } + final BiDirection direction = portableGridBlock.getDirection(blockState); + if (direction == null) { + return; + } + render(entity, poseStack, vertexConsumers, direction); + } + + private void render(final T entity, + final PoseStack poseStack, + final MultiBufferSource vertexConsumers, + final BiDirection direction) { + final Disk disk = getDisk(entity); + poseStack.pushPose(); + poseStack.translate(0.5F, 0.5F, 0.5F); + poseStack.mulPose(direction.getQuaternion()); + poseStack.translate(-0.5F, -0.5F, -0.5F); + final VertexConsumer vertexConsumer = vertexConsumers.getBuffer(renderType); + if (disk != null) { + renderLed(poseStack, vertexConsumer, -1, 2, 12, disk, Direction.EAST); + } + poseStack.popPose(); + } +} 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..a5c927d9f --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/portablegrid/PortableGridBlock.java @@ -0,0 +1,64 @@ +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 java.util.function.BiFunction; + +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.block.EntityBlock; +import net.minecraft.world.level.block.entity.BlockEntity; +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 implements EntityBlock { + 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; + private final BiFunction blockEntityFactory; + + public PortableGridBlock(final PortableGridType type, + final BiFunction factory) { + super(BlockConstants.PROPERTIES); + this.type = type; + this.blockEntityFactory = factory; + } + + @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; + }; + } + + @Override + public BlockEntity newBlockEntity(final BlockPos blockPos, final BlockState blockState) { + return blockEntityFactory.apply(blockPos, blockState); + } +} 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-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/externalstorage/package-info.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/portablegrid/package-info.java similarity index 74% rename from refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/externalstorage/package-info.java rename to refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/portablegrid/package-info.java index 304720869..cc5747491 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/externalstorage/package-info.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/portablegrid/package-info.java @@ -1,6 +1,6 @@ @ParametersAreNonnullByDefault @FieldsAndMethodsAreNonnullByDefault -package com.refinedmods.refinedstorage2.platform.forge.externalstorage; +package com.refinedmods.refinedstorage2.platform.common.portablegrid; import com.refinedmods.refinedstorage2.api.core.FieldsAndMethodsAreNonnullByDefault; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/diskdrive/DiskDriveDisk.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/Disk.java similarity index 51% rename from refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/diskdrive/DiskDriveDisk.java rename to refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/Disk.java index 1353b3cc2..242b3a4c3 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/diskdrive/DiskDriveDisk.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/Disk.java @@ -1,4 +1,4 @@ -package com.refinedmods.refinedstorage2.platform.common.storage.diskdrive; +package com.refinedmods.refinedstorage2.platform.common.storage; import com.refinedmods.refinedstorage2.api.network.impl.node.StorageState; @@ -6,5 +6,5 @@ import net.minecraft.world.item.Item; -public record DiskDriveDisk(@Nullable Item item, StorageState state) { +public record Disk(@Nullable Item item, StorageState state) { } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/diskdrive/AbstractDiskDriveBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/diskdrive/AbstractDiskDriveBlockEntity.java index 75cf6ea63..ccba183c4 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/diskdrive/AbstractDiskDriveBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/diskdrive/AbstractDiskDriveBlockEntity.java @@ -7,6 +7,7 @@ import com.refinedmods.refinedstorage2.platform.common.Platform; import com.refinedmods.refinedstorage2.platform.common.content.BlockEntities; import com.refinedmods.refinedstorage2.platform.common.content.ContentNames; +import com.refinedmods.refinedstorage2.platform.common.storage.Disk; import com.refinedmods.refinedstorage2.platform.common.storage.StorageConfigurationContainerImpl; import com.refinedmods.refinedstorage2.platform.common.support.AbstractDirectionalBlock; import com.refinedmods.refinedstorage2.platform.common.support.BlockEntityWithDrops; @@ -56,7 +57,7 @@ public abstract class AbstractDiskDriveBlockEntity private static final String TAG_DISK_ITEM_ID = "i"; @Nullable - protected DiskDriveDisk[] disks; + protected Disk[] disks; private final DiskDriveInventory diskInventory; private final FilterWithFuzzyMode filter; @@ -215,12 +216,12 @@ private void fromClientTag(final CompoundTag tag) { return; } final ListTag disksList = tag.getList(TAG_DISKS, Tag.TAG_COMPOUND); - disks = new DiskDriveDisk[disksList.size()]; + disks = new Disk[disksList.size()]; for (int i = 0; i < disksList.size(); ++i) { final CompoundTag diskTag = disksList.getCompound(i); disks[i] = BuiltInRegistries.ITEM.getHolder(diskTag.getInt(TAG_DISK_ITEM_ID)) - .map(item -> new DiskDriveDisk(item.value(), getState(diskTag))) - .orElse(new DiskDriveDisk(null, StorageState.NONE)); + .map(item -> new Disk(item.value(), getState(diskTag))) + .orElse(new Disk(null, StorageState.NONE)); } onDriveStateUpdated(); } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/diskdrive/AbstractDiskDriveBlockEntityRenderer.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/diskdrive/AbstractDiskDriveBlockEntityRenderer.java index 6b3010051..114e8f100 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/diskdrive/AbstractDiskDriveBlockEntityRenderer.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/diskdrive/AbstractDiskDriveBlockEntityRenderer.java @@ -1,8 +1,8 @@ package com.refinedmods.refinedstorage2.platform.common.storage.diskdrive; -import com.refinedmods.refinedstorage2.api.network.impl.node.StorageState; +import com.refinedmods.refinedstorage2.platform.common.storage.Disk; import com.refinedmods.refinedstorage2.platform.common.support.direction.BiDirection; -import com.refinedmods.refinedstorage2.platform.common.support.render.CubeBuilder; +import com.refinedmods.refinedstorage2.platform.common.support.render.AbstractDiskLedBlockEntityRenderer; import javax.annotation.Nullable; @@ -10,21 +10,12 @@ import com.mojang.blaze3d.vertex.VertexConsumer; import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.RenderType; -import net.minecraft.client.renderer.blockentity.BlockEntityRenderer; import net.minecraft.core.Direction; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.state.BlockState; public abstract class AbstractDiskDriveBlockEntityRenderer - implements BlockEntityRenderer { - private static final int LED_X1 = 10; - private static final int LED_Y1 = 12; - private static final int LED_Z1 = -1; - - private static final int LED_X2 = 11; - private static final int LED_Y2 = 13; - private static final int LED_Z2 = 0; - + extends AbstractDiskLedBlockEntityRenderer { private final RenderType renderType; protected AbstractDiskDriveBlockEntityRenderer(final RenderType renderType) { @@ -32,7 +23,7 @@ protected AbstractDiskDriveBlockEntityRenderer(final RenderType renderType) { } @Nullable - protected abstract DiskDriveDisk[] getDisks(T blockEntity); + protected abstract Disk[] getDisks(T blockEntity); @Override public void render(final T entity, @@ -45,87 +36,42 @@ public void render(final T entity, if (level == null) { return; } - - // Always sanity check the block state first, these may not always be correct and can cause crashes (see #20). final BlockState blockState = level.getBlockState(entity.getBlockPos()); - if (blockState.getBlock() instanceof DiskDriveBlock diskDriveBlock) { - final BiDirection direction = diskDriveBlock.getDirection(blockState); - if (direction != null) { - render(entity, poseStack, vertexConsumers, direction); - } + if (!(blockState.getBlock() instanceof DiskDriveBlock diskDriveBlock)) { + return; } + final BiDirection direction = diskDriveBlock.getDirection(blockState); + if (direction == null) { + return; + } + render(entity, poseStack, vertexConsumers, direction); } private void render(final T entity, final PoseStack poseStack, final MultiBufferSource vertexConsumers, final BiDirection direction) { - final DiskDriveDisk[] disks = getDisks(entity); - + final Disk[] disks = getDisks(entity); poseStack.pushPose(); - poseStack.translate(0.5F, 0.5F, 0.5F); poseStack.mulPose(direction.getQuaternion()); poseStack.translate(-0.5F, -0.5F, -0.5F); - final VertexConsumer vertexConsumer = vertexConsumers.getBuffer(renderType); - if (disks != null) { - renderDisks(poseStack, disks, vertexConsumer); + renderDiskLeds(poseStack, disks, vertexConsumer); } - poseStack.popPose(); } - private void renderDisks(final PoseStack poseStack, - final DiskDriveDisk[] disks, - final VertexConsumer vertexConsumer) { + private void renderDiskLeds(final PoseStack poseStack, + final Disk[] disks, + final VertexConsumer vertexConsumer) { int i = 0; for (int y = 0; y < 4; ++y) { for (int x = 0; x < 2; ++x) { - final DiskDriveDisk disk = disks[i++]; - renderDisk(poseStack, vertexConsumer, y, x, disk); + final Disk disk = disks[i++]; + renderLed(poseStack, vertexConsumer, 10 - (x * 7), 12 - (y * 3), -1, disk, Direction.SOUTH); } } } - - private void renderDisk(final PoseStack poseStack, - final VertexConsumer vertexConsumer, - final int y, - final int x, - final DiskDriveDisk disk) { - if (disk.state() == StorageState.NONE) { - return; - } - final int color = getColor(disk.state()); - final float x1 = LED_X1 - (x * 7F); - final float y1 = LED_Y1 - (y * 3F); - final float x2 = LED_X2 - (x * 7F); - final float y2 = LED_Y2 - (y * 3F); - CubeBuilder.INSTANCE.putCube( - poseStack, - vertexConsumer, - x1 / 16F, - y1 / 16F, - LED_Z1 / 16F, - x2 / 16F, - y2 / 16F, - LED_Z2 / 16F, - color >> 16 & 0xFF, - color >> 8 & 0xFF, - color & 0xFF, - 255, - Direction.SOUTH - ); - } - - private int getColor(final StorageState state) { - return switch (state) { - case NONE -> 0; - case INACTIVE -> 0x323232; - case NORMAL -> 0x00E9FF; - case NEAR_CAPACITY -> 0xFFB700; - case FULL -> 0xDA4B40; - }; - } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/render/AbstractDiskLedBlockEntityRenderer.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/render/AbstractDiskLedBlockEntityRenderer.java new file mode 100644 index 000000000..69120652a --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/render/AbstractDiskLedBlockEntityRenderer.java @@ -0,0 +1,50 @@ +package com.refinedmods.refinedstorage2.platform.common.support.render; + +import com.refinedmods.refinedstorage2.api.network.impl.node.StorageState; +import com.refinedmods.refinedstorage2.platform.common.storage.Disk; + +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.blaze3d.vertex.VertexConsumer; +import net.minecraft.client.renderer.blockentity.BlockEntityRenderer; +import net.minecraft.core.Direction; +import net.minecraft.world.level.block.entity.BlockEntity; + +public abstract class AbstractDiskLedBlockEntityRenderer implements BlockEntityRenderer { + protected void renderLed(final PoseStack poseStack, + final VertexConsumer vertexConsumer, + final int x, + final int y, + final int z, + final Disk disk, + final Direction excludeDirection) { + if (disk.state() == StorageState.NONE) { + return; + } + final int color = getColor(disk.state()); + CubeBuilder.putCube( + poseStack, + vertexConsumer, + x / 16F, + y / 16F, + z / 16F, + (x + 1) / 16F, + (y + 1) / 16F, + (z + 1) / 16F, + color >> 16 & 0xFF, + color >> 8 & 0xFF, + color & 0xFF, + 255, + excludeDirection + ); + } + + private int getColor(final StorageState state) { + return switch (state) { + case NONE -> 0; + case INACTIVE -> 0x323232; + case NORMAL -> 0x00E9FF; + case NEAR_CAPACITY -> 0xFFB700; + case FULL -> 0xDA4B40; + }; + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/render/CubeBuilder.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/render/CubeBuilder.java index b173c350e..89a113e16 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/render/CubeBuilder.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/render/CubeBuilder.java @@ -4,25 +4,23 @@ import com.mojang.blaze3d.vertex.VertexConsumer; import net.minecraft.core.Direction; -public class CubeBuilder { - public static final CubeBuilder INSTANCE = new CubeBuilder(); - +public final class CubeBuilder { private CubeBuilder() { } - public void putCube(final PoseStack poseStack, - final VertexConsumer builder, - final float x1, - final float y1, - final float z1, - final float x2, - final float y2, - final float z2, - final int r, - final int g, - final int b, - final int a, - final Direction exclude) { + public static void putCube(final PoseStack poseStack, + final VertexConsumer builder, + final float x1, + final float y1, + final float z1, + final float x2, + final float y2, + final float z2, + final int r, + final int g, + final int b, + final int a, + final Direction exclude) { poseStack.pushPose(); for (final Direction face : Direction.values()) { if (face == exclude) { @@ -33,68 +31,68 @@ public void putCube(final PoseStack poseStack, poseStack.popPose(); } - public void putFace(final PoseStack poseStack, - final VertexConsumer builder, - final float x1, - final float y1, - final float z1, - final float x2, - final float y2, - final float z2, - final int r, - final int g, - final int b, - final int a, - final Direction face) { + private static void putFace(final PoseStack poseStack, + final VertexConsumer builder, + final float x1, + final float y1, + final float z1, + final float x2, + final float y2, + final float z2, + final int r, + final int g, + final int b, + final int a, + final Direction face) { switch (face) { case DOWN -> { - this.putVertex(builder, poseStack, r, g, b, a, x2, y1, z1); - this.putVertex(builder, poseStack, r, g, b, a, x2, y1, z2); - this.putVertex(builder, poseStack, r, g, b, a, x1, y1, z2); - this.putVertex(builder, poseStack, r, g, b, a, x1, y1, z1); + putVertex(builder, poseStack, r, g, b, a, x2, y1, z1); + putVertex(builder, poseStack, r, g, b, a, x2, y1, z2); + putVertex(builder, poseStack, r, g, b, a, x1, y1, z2); + putVertex(builder, poseStack, r, g, b, a, x1, y1, z1); } case UP -> { - this.putVertex(builder, poseStack, r, g, b, a, x1, y2, z1); - this.putVertex(builder, poseStack, r, g, b, a, x1, y2, z2); - this.putVertex(builder, poseStack, r, g, b, a, x2, y2, z2); - this.putVertex(builder, poseStack, r, g, b, a, x2, y2, z1); + putVertex(builder, poseStack, r, g, b, a, x1, y2, z1); + putVertex(builder, poseStack, r, g, b, a, x1, y2, z2); + putVertex(builder, poseStack, r, g, b, a, x2, y2, z2); + putVertex(builder, poseStack, r, g, b, a, x2, y2, z1); } case NORTH -> { - this.putVertex(builder, poseStack, r, g, b, a, x2, y2, z1); - this.putVertex(builder, poseStack, r, g, b, a, x2, y1, z1); - this.putVertex(builder, poseStack, r, g, b, a, x1, y1, z1); - this.putVertex(builder, poseStack, r, g, b, a, x1, y2, z1); + putVertex(builder, poseStack, r, g, b, a, x2, y2, z1); + putVertex(builder, poseStack, r, g, b, a, x2, y1, z1); + putVertex(builder, poseStack, r, g, b, a, x1, y1, z1); + putVertex(builder, poseStack, r, g, b, a, x1, y2, z1); } case SOUTH -> { - this.putVertex(builder, poseStack, r, g, b, a, x1, y2, z2); - this.putVertex(builder, poseStack, r, g, b, a, x1, y1, z2); - this.putVertex(builder, poseStack, r, g, b, a, x2, y1, z2); - this.putVertex(builder, poseStack, r, g, b, a, x2, y2, z2); + putVertex(builder, poseStack, r, g, b, a, x1, y2, z2); + putVertex(builder, poseStack, r, g, b, a, x1, y1, z2); + putVertex(builder, poseStack, r, g, b, a, x2, y1, z2); + putVertex(builder, poseStack, r, g, b, a, x2, y2, z2); } case WEST -> { - this.putVertex(builder, poseStack, r, g, b, a, x1, y1, z1); - this.putVertex(builder, poseStack, r, g, b, a, x1, y1, z2); - this.putVertex(builder, poseStack, r, g, b, a, x1, y2, z2); - this.putVertex(builder, poseStack, r, g, b, a, x1, y2, z1); + putVertex(builder, poseStack, r, g, b, a, x1, y1, z1); + putVertex(builder, poseStack, r, g, b, a, x1, y1, z2); + putVertex(builder, poseStack, r, g, b, a, x1, y2, z2); + putVertex(builder, poseStack, r, g, b, a, x1, y2, z1); } case EAST -> { - this.putVertex(builder, poseStack, r, g, b, a, x2, y2, z1); - this.putVertex(builder, poseStack, r, g, b, a, x2, y2, z2); - this.putVertex(builder, poseStack, r, g, b, a, x2, y1, z2); - this.putVertex(builder, poseStack, r, g, b, a, x2, y1, z1); + putVertex(builder, poseStack, r, g, b, a, x2, y2, z1); + putVertex(builder, poseStack, r, g, b, a, x2, y2, z2); + putVertex(builder, poseStack, r, g, b, a, x2, y1, z2); + putVertex(builder, poseStack, r, g, b, a, x2, y1, z1); } } } - private void putVertex(final VertexConsumer builder, - final PoseStack poseStack, - final int r, - final int g, - final int b, - final int a, - final float x, - final float y, - final float z) { + private static void putVertex(final VertexConsumer builder, + final PoseStack poseStack, + final int r, + final int g, + final int b, + final int a, + final float x, + final float y, + final float z) { builder.vertex(poseStack.last().pose(), x, y, z).color(r, g, b, a).endVertex(); } } 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/creative_portable_grid.json b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/creative_portable_grid.json new file mode 100644 index 000000000..c8b32b4d1 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/creative_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/disk/disk.json b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/disk/disk.json index 01371e8ae..6c6d7f93c 100644 --- a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/disk/disk.json +++ b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/disk/disk.json @@ -84,15 +84,6 @@ 16, 0 ], - "rotation": { - "angle": 0, - "axis": "y", - "origin": [ - 6, - 8, - 8 - ] - }, "faces": { "north": { "uv": [ @@ -162,15 +153,6 @@ 16, 0 ], - "rotation": { - "angle": 0, - "axis": "y", - "origin": [ - 20, - 23, - 7 - ] - }, "faces": { "north": { "uv": [ diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/disk/fluid_disk.json b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/disk/fluid_disk.json index 96c2083af..07a270cc6 100644 --- a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/disk/fluid_disk.json +++ b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/disk/fluid_disk.json @@ -84,15 +84,6 @@ 16, 0 ], - "rotation": { - "angle": 0, - "axis": "y", - "origin": [ - 6, - 8, - 8 - ] - }, "faces": { "north": { "uv": [ @@ -162,15 +153,6 @@ 16, 0 ], - "rotation": { - "angle": 0, - "axis": "y", - "origin": [ - 20, - 23, - 7 - ] - }, "faces": { "north": { "uv": [ 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/creative_portable_grid.json b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/item/creative_portable_grid.json new file mode 100644 index 000000000..e0a8b5268 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/item/creative_portable_grid.json @@ -0,0 +1,3 @@ +{ + "parent": "refinedstorage2:block/creative_portable_grid" +} 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 99bc5968e..9ca328ff4 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,10 @@ 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.PortableGridBlockEntityRendererImpl; +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 +115,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) { @@ -289,6 +294,14 @@ private void registerBlockEntityRenderers() { BlockEntities.INSTANCE.getStorageMonitor(), ctx -> new StorageMonitorBlockEntityRenderer() ); + BlockEntityRenderers.register( + BlockEntities.INSTANCE.getPortableGrid(), + ctx -> new PortableGridBlockEntityRendererImpl<>() + ); + BlockEntityRenderers.register( + BlockEntities.INSTANCE.getCreativePortableGrid(), + ctx -> new PortableGridBlockEntityRendererImpl<>() + ); } private void registerCustomModels() { @@ -297,9 +310,22 @@ 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/ModInitializerImpl.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/ModInitializerImpl.java index df9396002..052fbd26f 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 @@ -16,6 +16,7 @@ import com.refinedmods.refinedstorage2.platform.common.grid.WirelessGridItem; import com.refinedmods.refinedstorage2.platform.common.iface.InterfaceBlockEntity; import com.refinedmods.refinedstorage2.platform.common.iface.InterfacePlatformExternalStorageProviderFactory; +import com.refinedmods.refinedstorage2.platform.common.portablegrid.PortableGridType; import com.refinedmods.refinedstorage2.platform.common.storage.channel.StorageChannelTypes; import com.refinedmods.refinedstorage2.platform.common.storage.diskdrive.AbstractDiskDriveBlockEntity; import com.refinedmods.refinedstorage2.platform.common.support.AbstractBaseBlock; @@ -42,6 +43,7 @@ import com.refinedmods.refinedstorage2.platform.fabric.packet.c2s.UseNetworkBoundItemPacket; import com.refinedmods.refinedstorage2.platform.fabric.storage.diskdrive.FabricDiskDriveBlockEntity; import com.refinedmods.refinedstorage2.platform.fabric.storage.externalstorage.FabricStoragePlatformExternalStorageProviderFactory; +import com.refinedmods.refinedstorage2.platform.fabric.storage.portablegrid.FabricPortableGridBlockEntity; import com.refinedmods.refinedstorage2.platform.fabric.support.energy.EnergyStorageAdapter; import com.refinedmods.refinedstorage2.platform.fabric.support.network.bounditem.TrinketsSlotReferenceFactory; import com.refinedmods.refinedstorage2.platform.fabric.support.network.bounditem.TrinketsSlotReferenceProvider; @@ -202,7 +204,12 @@ private void registerExternalStorageProviderFactories() { } private void registerContent() { - registerBlocks(new DirectRegistryCallback<>(BuiltInRegistries.BLOCK), FabricDiskDriveBlockEntity::new); + registerBlocks( + new DirectRegistryCallback<>(BuiltInRegistries.BLOCK), + FabricDiskDriveBlockEntity::new, + (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()) { @@ -244,7 +251,9 @@ public BlockEntityType create(final BlockEntitySuppli return new BlockEntityType<>(factory::create, new HashSet<>(Arrays.asList(allowedBlocks)), null); } }, - FabricDiskDriveBlockEntity::new + 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 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 7649b29e0..36ed45695 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 @@ -1,14 +1,13 @@ package com.refinedmods.refinedstorage2.platform.fabric.storage.diskdrive; import com.refinedmods.refinedstorage2.api.network.impl.node.StorageState; +import com.refinedmods.refinedstorage2.platform.common.storage.Disk; import com.refinedmods.refinedstorage2.platform.common.storage.diskdrive.AbstractDiskDriveBlockEntity; import com.refinedmods.refinedstorage2.platform.common.storage.diskdrive.DiskDriveBlock; -import com.refinedmods.refinedstorage2.platform.common.storage.diskdrive.DiskDriveDisk; 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 javax.annotation.Nullable; @@ -28,7 +27,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; @@ -41,21 +39,20 @@ class DiskDriveBakedModel extends ForwardingBakedModel { ); } } - - for (final BiDirection direction : BiDirection.values()) { - ROTATORS.put(direction, new QuadRotator(direction)); - } } private final Map diskModels; private final BakedModel inactiveLedModel; + private final QuadRotators quadRotators; DiskDriveBakedModel(final BakedModel baseModel, final Map diskModels, - final BakedModel inactiveLedModel) { + final BakedModel inactiveLedModel, + final QuadRotators quadRotators) { this.wrapped = baseModel; this.diskModels = diskModels; this.inactiveLedModel = inactiveLedModel; + this.quadRotators = quadRotators; } @Override @@ -91,19 +88,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 DiskDriveDisk[] disks) { + if (renderAttachment instanceof Disk[] disks) { emitDiskQuads(blockView, state, pos, randomSupplier, context, disks); } } - context.popTransform(); } @@ -112,9 +104,9 @@ private void emitDiskQuads(final BlockAndTintGetter blockView, final BlockPos pos, final Supplier randomSupplier, final RenderContext context, - final DiskDriveDisk[] disks) { + final Disk[] disks) { for (int i = 0; i < TRANSLATORS.length; ++i) { - final DiskDriveDisk disk = disks[i]; + final Disk disk = disks[i]; emitDiskQuads(blockView, state, pos, randomSupplier, context, disk, i); } } @@ -124,7 +116,7 @@ private void emitDiskQuads(final BlockAndTintGetter blockView, final BlockPos pos, final Supplier randomSupplier, final RenderContext context, - final DiskDriveDisk disk, + final Disk disk, final int index) { if (disk.state() == StorageState.NONE) { return; diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/storage/diskdrive/DiskDriveBlockEntityRendererImpl.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/storage/diskdrive/DiskDriveBlockEntityRendererImpl.java index f99f168ce..9590df8f8 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/storage/diskdrive/DiskDriveBlockEntityRendererImpl.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/storage/diskdrive/DiskDriveBlockEntityRendererImpl.java @@ -1,39 +1,22 @@ package com.refinedmods.refinedstorage2.platform.fabric.storage.diskdrive; +import com.refinedmods.refinedstorage2.platform.common.storage.Disk; import com.refinedmods.refinedstorage2.platform.common.storage.diskdrive.AbstractDiskDriveBlockEntity; import com.refinedmods.refinedstorage2.platform.common.storage.diskdrive.AbstractDiskDriveBlockEntityRenderer; -import com.refinedmods.refinedstorage2.platform.common.storage.diskdrive.DiskDriveDisk; - -import com.mojang.blaze3d.vertex.DefaultVertexFormat; -import com.mojang.blaze3d.vertex.VertexFormat; -import net.minecraft.client.renderer.GameRenderer; -import net.minecraft.client.renderer.RenderStateShard; -import net.minecraft.client.renderer.RenderType; +import com.refinedmods.refinedstorage2.platform.fabric.support.render.RenderTypes; public class DiskDriveBlockEntityRendererImpl extends AbstractDiskDriveBlockEntityRenderer { - private static final RenderType RENDER_TYPE = RenderType.create( - "drive_leds", - DefaultVertexFormat.POSITION_COLOR, - VertexFormat.Mode.QUADS, - 32565, - false, - true, - RenderType.CompositeState.builder() - .setShaderState(new RenderStateShard.ShaderStateShard(GameRenderer::getPositionColorShader)) - .createCompositeState(false) - ); - public DiskDriveBlockEntityRendererImpl() { - super(RENDER_TYPE); + super(RenderTypes.DISK_LED); } @Override - protected DiskDriveDisk[] getDisks(final AbstractDiskDriveBlockEntity blockEntity) { + protected Disk[] getDisks(final AbstractDiskDriveBlockEntity blockEntity) { if (!(blockEntity instanceof FabricDiskDriveBlockEntity fabricDiskDriveBlockEntity)) { return null; } - if (fabricDiskDriveBlockEntity.getRenderAttachmentData() instanceof DiskDriveDisk[] disks) { + if (fabricDiskDriveBlockEntity.getRenderAttachmentData() instanceof Disk[] disks) { return disks; } return null; 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 7c2c1900a..fb99ff660 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,6 +1,7 @@ package com.refinedmods.refinedstorage2.platform.fabric.storage.diskdrive; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; +import com.refinedmods.refinedstorage2.platform.fabric.support.render.QuadRotators; import java.util.Collection; import java.util.HashSet; @@ -26,6 +27,12 @@ public class DiskDriveUnbakedModel implements UnbakedModel { private static final ResourceLocation BASE_MODEL = createIdentifier("block/disk_drive/base"); private static final ResourceLocation LED_INACTIVE_MODEL = createIdentifier("block/disk/led_inactive"); + private final QuadRotators quadRotators; + + public DiskDriveUnbakedModel(final QuadRotators quadRotators) { + this.quadRotators = quadRotators; + } + @Override public Collection getDependencies() { final Set dependencies = new HashSet<>(); @@ -61,7 +68,8 @@ public BakedModel bake(final ModelBaker baker, return new DiskDriveBakedModel( requireNonNull(baker.bake(BASE_MODEL, state)), diskModels, - requireNonNull(baker.bake(LED_INACTIVE_MODEL, state)) + requireNonNull(baker.bake(LED_INACTIVE_MODEL, state)), + quadRotators ); } } diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/storage/portablegrid/FabricPortableGridBlockEntity.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/storage/portablegrid/FabricPortableGridBlockEntity.java new file mode 100644 index 000000000..e9b0f2ed1 --- /dev/null +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/storage/portablegrid/FabricPortableGridBlockEntity.java @@ -0,0 +1,23 @@ +package com.refinedmods.refinedstorage2.platform.fabric.storage.portablegrid; + +import com.refinedmods.refinedstorage2.platform.common.portablegrid.AbstractPortableGridBlockEntity; +import com.refinedmods.refinedstorage2.platform.common.portablegrid.PortableGridType; + +import javax.annotation.Nullable; + +import net.fabricmc.fabric.api.rendering.data.v1.RenderAttachmentBlockEntity; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.block.state.BlockState; + +public class FabricPortableGridBlockEntity extends AbstractPortableGridBlockEntity + implements RenderAttachmentBlockEntity { + public FabricPortableGridBlockEntity(final PortableGridType type, final BlockPos pos, final BlockState state) { + super(type, pos, state); + } + + @Override + @Nullable + public Object getRenderAttachmentData() { + return disk; + } +} 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..90e7f0626 --- /dev/null +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/storage/portablegrid/PortableGridBakedModel.java @@ -0,0 +1,77 @@ +package com.refinedmods.refinedstorage2.platform.fabric.storage.portablegrid; + +import com.refinedmods.refinedstorage2.platform.common.content.Items; +import com.refinedmods.refinedstorage2.platform.common.portablegrid.PortableGridBlock; +import com.refinedmods.refinedstorage2.platform.common.storage.ItemStorageType; +import com.refinedmods.refinedstorage2.platform.common.support.direction.BiDirection; +import com.refinedmods.refinedstorage2.platform.fabric.support.render.QuadRotators; +import com.refinedmods.refinedstorage2.platform.fabric.support.render.QuadTranslator; + +import java.util.Map; +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.Item; +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 static final QuadTranslator MOVE_TO_DISK_LOCATION = new QuadTranslator(0, -12 / 16F, 9 / 16F); + + private final BakedModel activeModel; + private final BakedModel inactiveModel; + private final Map diskModels; + private final QuadRotators quadRotators; + + public PortableGridBakedModel(final BakedModel activeModel, + final BakedModel inactiveModel, + final Map diskModels, + final QuadRotators quadRotators) { + this.wrapped = inactiveModel; + this.activeModel = activeModel; + this.inactiveModel = inactiveModel; + this.diskModels = diskModels; + 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)); + context.pushTransform(MOVE_TO_DISK_LOCATION); + context.pushTransform(quadRotators.forDirection(BiDirection.WEST)); + diskModels.get(Items.INSTANCE.getItemStorageDisk(ItemStorageType.Variant.ONE_K)) + .emitBlockQuads(blockView, state, pos, randomSupplier, context); + context.popTransform(); + context.popTransform(); + 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/PortableGridBlockEntityRendererImpl.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/storage/portablegrid/PortableGridBlockEntityRendererImpl.java new file mode 100644 index 000000000..c6a9c6402 --- /dev/null +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/storage/portablegrid/PortableGridBlockEntityRendererImpl.java @@ -0,0 +1,27 @@ +package com.refinedmods.refinedstorage2.platform.fabric.storage.portablegrid; + +import com.refinedmods.refinedstorage2.platform.common.portablegrid.AbstractPortableGridBlockEntity; +import com.refinedmods.refinedstorage2.platform.common.portablegrid.AbstractPortableGridBlockEntityRenderer; +import com.refinedmods.refinedstorage2.platform.common.storage.Disk; +import com.refinedmods.refinedstorage2.platform.fabric.support.render.RenderTypes; + +import javax.annotation.Nullable; + +public class PortableGridBlockEntityRendererImpl + extends AbstractPortableGridBlockEntityRenderer { + public PortableGridBlockEntityRendererImpl() { + super(RenderTypes.DISK_LED); + } + + @Override + @Nullable + protected Disk getDisk(final T blockEntity) { + if (!(blockEntity instanceof FabricPortableGridBlockEntity fabricDiskDriveBlockEntity)) { + return null; + } + if (fabricDiskDriveBlockEntity.getRenderAttachmentData() instanceof Disk disk) { + return disk; + } + return null; + } +} 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..11c6136b8 --- /dev/null +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/storage/portablegrid/PortableGridUnbakedModel.java @@ -0,0 +1,68 @@ +package com.refinedmods.refinedstorage2.platform.fabric.storage.portablegrid; + +import com.refinedmods.refinedstorage2.platform.api.PlatformApi; +import com.refinedmods.refinedstorage2.platform.fabric.support.render.QuadRotators; + +import java.util.Collection; +import java.util.Map; +import java.util.Set; +import java.util.function.Function; +import java.util.stream.Collectors; + +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 net.minecraft.world.item.Item; + +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); + PlatformApi.INSTANCE.getStorageContainerItemHelper().getDiskModels().forEach( + diskModel -> modelGetter.apply(diskModel).resolveParents(modelGetter) + ); + } + + @Override + public BakedModel bake(final ModelBaker baker, + final Function spriteGetter, + final ModelState state, + final ResourceLocation location) { + final Map diskModels = PlatformApi.INSTANCE.getStorageContainerItemHelper() + .getDiskModelsByItem() + .entrySet() + .stream() + .collect(Collectors.toMap( + Map.Entry::getKey, + entry -> requireNonNull(baker.bake(entry.getValue(), state)) + )); + return new PortableGridBakedModel( + requireNonNull(baker.bake(ACTIVE_MODEL, state)), + requireNonNull(baker.bake(INACTIVE_MODEL, state)), + diskModels, + 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); + } +} diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/support/render/RenderTypes.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/support/render/RenderTypes.java new file mode 100644 index 000000000..1233eb05e --- /dev/null +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/support/render/RenderTypes.java @@ -0,0 +1,24 @@ +package com.refinedmods.refinedstorage2.platform.fabric.support.render; + +import com.mojang.blaze3d.vertex.DefaultVertexFormat; +import com.mojang.blaze3d.vertex.VertexFormat; +import net.minecraft.client.renderer.GameRenderer; +import net.minecraft.client.renderer.RenderStateShard; +import net.minecraft.client.renderer.RenderType; + +public final class RenderTypes { + public static final RenderType DISK_LED = RenderType.create( + "disk_led", + DefaultVertexFormat.POSITION_COLOR, + VertexFormat.Mode.QUADS, + 32565, + false, + true, + RenderType.CompositeState.builder() + .setShaderState(new RenderStateShard.ShaderStateShard(GameRenderer::getPositionColorShader)) + .createCompositeState(false) + ); + + private RenderTypes() { + } +} 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 ab7fccf62..b263d2a08 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 @@ -23,6 +23,8 @@ import com.refinedmods.refinedstorage2.platform.forge.recipemod.rei.ReiProxy; import com.refinedmods.refinedstorage2.platform.forge.storage.diskdrive.DiskDriveBlockEntityRendererImpl; import com.refinedmods.refinedstorage2.platform.forge.storage.diskdrive.DiskDriveGeometryLoader; +import com.refinedmods.refinedstorage2.platform.forge.storage.portablegrid.PortableGridBlockEntityRendererImpl; +import com.refinedmods.refinedstorage2.platform.forge.storage.portablegrid.PortableGridGeometryLoader; import java.util.List; @@ -51,6 +53,7 @@ import org.slf4j.LoggerFactory; import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.DISK_DRIVE; +import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.PORTABLE_GRID; import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createIdentifier; import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslationKey; @@ -99,6 +102,7 @@ private static void registerModelPredicates() { public static void onRegisterModelGeometry(final ModelEvent.RegisterGeometryLoaders e) { registerDiskModels(); e.register(DISK_DRIVE.getPath(), new DiskDriveGeometryLoader()); + e.register(PORTABLE_GRID.getPath(), new PortableGridGeometryLoader()); } @SubscribeEvent @@ -150,6 +154,14 @@ private static void registerBlockEntityRenderer() { BlockEntities.INSTANCE.getStorageMonitor(), ctx -> new StorageMonitorBlockEntityRenderer() ); + BlockEntityRenderers.register( + BlockEntities.INSTANCE.getPortableGrid(), + ctx -> new PortableGridBlockEntityRendererImpl<>() + ); + BlockEntityRenderers.register( + BlockEntities.INSTANCE.getCreativePortableGrid(), + ctx -> new PortableGridBlockEntityRendererImpl<>() + ); } private static void registerGridSynchronizers() { 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 d7babe29a..11890e63f 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 @@ -15,6 +15,7 @@ import com.refinedmods.refinedstorage2.platform.common.grid.WirelessGridItem; import com.refinedmods.refinedstorage2.platform.common.iface.InterfaceBlockEntity; import com.refinedmods.refinedstorage2.platform.common.iface.InterfacePlatformExternalStorageProviderFactory; +import com.refinedmods.refinedstorage2.platform.common.portablegrid.PortableGridType; import com.refinedmods.refinedstorage2.platform.common.storage.diskdrive.AbstractDiskDriveBlockEntity; import com.refinedmods.refinedstorage2.platform.common.support.AbstractBaseBlock; import com.refinedmods.refinedstorage2.platform.common.upgrade.RegulatorUpgradeItem; @@ -22,8 +23,6 @@ import com.refinedmods.refinedstorage2.platform.common.util.ServerEventQueue; import com.refinedmods.refinedstorage2.platform.forge.exporter.FluidHandlerExporterTransferStrategyFactory; import com.refinedmods.refinedstorage2.platform.forge.exporter.ItemHandlerExporterTransferStrategyFactory; -import com.refinedmods.refinedstorage2.platform.forge.externalstorage.FluidHandlerPlatformExternalStorageProviderFactory; -import com.refinedmods.refinedstorage2.platform.forge.externalstorage.ItemHandlerPlatformExternalStorageProviderFactory; import com.refinedmods.refinedstorage2.platform.forge.grid.strategy.FluidGridExtractionStrategy; import com.refinedmods.refinedstorage2.platform.forge.grid.strategy.FluidGridInsertionStrategy; import com.refinedmods.refinedstorage2.platform.forge.grid.strategy.ItemGridExtractionStrategy; @@ -32,6 +31,9 @@ import com.refinedmods.refinedstorage2.platform.forge.importer.ItemHandlerImporterTransferStrategyFactory; import com.refinedmods.refinedstorage2.platform.forge.packet.NetworkManager; import com.refinedmods.refinedstorage2.platform.forge.storage.diskdrive.ForgeDiskDriveBlockEntity; +import com.refinedmods.refinedstorage2.platform.forge.storage.externalstorage.FluidHandlerPlatformExternalStorageProviderFactory; +import com.refinedmods.refinedstorage2.platform.forge.storage.externalstorage.ItemHandlerPlatformExternalStorageProviderFactory; +import com.refinedmods.refinedstorage2.platform.forge.storage.portablegrid.ForgePortableGridBlockEntity; import com.refinedmods.refinedstorage2.platform.forge.support.energy.EnergyStorageAdapter; import com.refinedmods.refinedstorage2.platform.forge.support.network.bounditem.CuriosSlotReferenceFactory; import com.refinedmods.refinedstorage2.platform.forge.support.network.bounditem.CuriosSlotReferenceProvider; @@ -184,7 +186,12 @@ private void registerContent() { } private void registerBlocks() { - registerBlocks(new ForgeRegistryCallback<>(blockRegistry), ForgeDiskDriveBlockEntity::new); + registerBlocks( + new ForgeRegistryCallback<>(blockRegistry), + ForgeDiskDriveBlockEntity::new, + (pos, state) -> new ForgePortableGridBlockEntity(PortableGridType.NORMAL, pos, state), + (pos, state) -> new ForgePortableGridBlockEntity(PortableGridType.CREATIVE, pos, state) + ); blockRegistry.register(FMLJavaModLoadingContext.get().getModEventBus()); } @@ -229,7 +236,9 @@ public BlockEntityType create(final BlockEntitySuppli return new BlockEntityType<>(factory::create, new HashSet<>(Arrays.asList(allowedBlocks)), null); } }, - ForgeDiskDriveBlockEntity::new + ForgeDiskDriveBlockEntity::new, + (pos, state) -> new ForgePortableGridBlockEntity(PortableGridType.NORMAL, pos, state), + (pos, state) -> new ForgePortableGridBlockEntity(PortableGridType.CREATIVE, pos, state) ); blockEntityTypeRegistry.register(FMLJavaModLoadingContext.get().getModEventBus()); } diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/diskdrive/DiskDriveBakedModel.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/diskdrive/DiskDriveBakedModel.java index 9dd223a3d..8816c67f4 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/diskdrive/DiskDriveBakedModel.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/diskdrive/DiskDriveBakedModel.java @@ -1,9 +1,9 @@ package com.refinedmods.refinedstorage2.platform.forge.storage.diskdrive; import com.refinedmods.refinedstorage2.api.network.impl.node.StorageState; +import com.refinedmods.refinedstorage2.platform.common.storage.Disk; import com.refinedmods.refinedstorage2.platform.common.storage.diskdrive.AbstractDiskDriveBlockEntity; import com.refinedmods.refinedstorage2.platform.common.storage.diskdrive.DiskDriveBlock; -import com.refinedmods.refinedstorage2.platform.common.storage.diskdrive.DiskDriveDisk; import com.refinedmods.refinedstorage2.platform.common.support.direction.BiDirection; import java.util.ArrayList; @@ -15,7 +15,6 @@ import java.util.Objects; import java.util.function.BiFunction; import java.util.function.Function; -import javax.annotation.Nonnull; import javax.annotation.Nullable; import com.google.common.cache.CacheBuilder; @@ -85,12 +84,11 @@ public ItemOverrides getOverrides() { return overrides; } - @Nonnull @Override public List getQuads(@Nullable final BlockState state, @Nullable final Direction side, - @Nonnull final RandomSource rand, - @Nonnull final ModelData extraData, + final RandomSource rand, + final ModelData extraData, @Nullable final RenderType renderType) { if (state == null || !(state.getBlock() instanceof DiskDriveBlock diskDriveBlock)) { return super.getQuads(state, side, rand); @@ -99,7 +97,7 @@ public List getQuads(@Nullable final BlockState state, if (direction == null) { return super.getQuads(state, side, rand); } - final DiskDriveDisk[] disks = extraData.get(ForgeDiskDriveBlockEntity.DISKS_PROPERTY); + final Disk[] disks = extraData.get(ForgeDiskDriveBlockEntity.DISKS_PROPERTY); if (disks == null) { return super.getQuads(state, side, rand); } @@ -144,13 +142,13 @@ private static final class DiskDriveStateCacheKey { private final BlockState state; @Nullable private final Direction side; - private final DiskDriveDisk[] disks; + private final Disk[] disks; private final RandomSource random; private final BiDirection direction; DiskDriveStateCacheKey(final BlockState state, @Nullable final Direction side, - final DiskDriveDisk[] disks, + final Disk[] disks, final RandomSource random, final BiDirection direction) { this.state = state; @@ -185,7 +183,7 @@ private class DiskDriveCacheLoader extends CacheLoader load(final DiskDriveStateCacheKey key) { final List quads = new ArrayList<>(getBaseQuads(key.state, key.random, key.side, key.direction)); for (int i = 0; i < TRANSLATORS.length; ++i) { - final DiskDriveDisk disk = key.disks[i]; + final Disk disk = key.disks[i]; quads.addAll(getDiskQuads(key, disk, i)); } return quads; @@ -193,7 +191,7 @@ public List load(final DiskDriveStateCacheKey key) { @SuppressWarnings("deprecation") private List getDiskQuads(final DiskDriveStateCacheKey key, - final DiskDriveDisk disk, + final Disk disk, final int index) { if (disk.state() == StorageState.NONE) { return Collections.emptyList(); diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/diskdrive/DiskDriveBlockEntityRendererImpl.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/diskdrive/DiskDriveBlockEntityRendererImpl.java index d8af4eafe..3469f6361 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/diskdrive/DiskDriveBlockEntityRendererImpl.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/diskdrive/DiskDriveBlockEntityRendererImpl.java @@ -1,35 +1,18 @@ package com.refinedmods.refinedstorage2.platform.forge.storage.diskdrive; +import com.refinedmods.refinedstorage2.platform.common.storage.Disk; import com.refinedmods.refinedstorage2.platform.common.storage.diskdrive.AbstractDiskDriveBlockEntity; import com.refinedmods.refinedstorage2.platform.common.storage.diskdrive.AbstractDiskDriveBlockEntityRenderer; -import com.refinedmods.refinedstorage2.platform.common.storage.diskdrive.DiskDriveDisk; - -import com.mojang.blaze3d.vertex.DefaultVertexFormat; -import com.mojang.blaze3d.vertex.VertexFormat; -import net.minecraft.client.renderer.GameRenderer; -import net.minecraft.client.renderer.RenderStateShard; -import net.minecraft.client.renderer.RenderType; +import com.refinedmods.refinedstorage2.platform.forge.support.render.RenderTypes; public class DiskDriveBlockEntityRendererImpl extends AbstractDiskDriveBlockEntityRenderer { - private static final RenderType RENDER_TYPE = RenderType.create( - "drive_leds", - DefaultVertexFormat.POSITION_COLOR, - VertexFormat.Mode.QUADS, - 32565, - false, - true, - RenderType.CompositeState.builder() - .setShaderState(new RenderStateShard.ShaderStateShard(GameRenderer::getPositionColorShader)) - .createCompositeState(false) - ); - public DiskDriveBlockEntityRendererImpl() { - super(RENDER_TYPE); + super(RenderTypes.DISK_LED); } @Override - protected DiskDriveDisk[] getDisks(final AbstractDiskDriveBlockEntity blockEntity) { + protected Disk[] getDisks(final AbstractDiskDriveBlockEntity blockEntity) { return blockEntity.getModelData().get(ForgeDiskDriveBlockEntity.DISKS_PROPERTY); } } diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/diskdrive/ForgeDiskDriveBlockEntity.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/diskdrive/ForgeDiskDriveBlockEntity.java index 057b8e344..50dade2cd 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/diskdrive/ForgeDiskDriveBlockEntity.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/diskdrive/ForgeDiskDriveBlockEntity.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.platform.forge.storage.diskdrive; +import com.refinedmods.refinedstorage2.platform.common.storage.Disk; import com.refinedmods.refinedstorage2.platform.common.storage.diskdrive.AbstractDiskDriveBlockEntity; -import com.refinedmods.refinedstorage2.platform.common.storage.diskdrive.DiskDriveDisk; import javax.annotation.Nonnull; @@ -11,7 +11,7 @@ import net.minecraftforge.client.model.data.ModelProperty; public class ForgeDiskDriveBlockEntity extends AbstractDiskDriveBlockEntity { - public static final ModelProperty DISKS_PROPERTY = new ModelProperty<>(); + public static final ModelProperty DISKS_PROPERTY = new ModelProperty<>(); public ForgeDiskDriveBlockEntity(final BlockPos pos, final BlockState state) { super(pos, state); diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/externalstorage/FluidHandlerExternalStorageProvider.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/externalstorage/FluidHandlerExternalStorageProvider.java similarity index 96% rename from refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/externalstorage/FluidHandlerExternalStorageProvider.java rename to refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/externalstorage/FluidHandlerExternalStorageProvider.java index c976243a3..3ee239795 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/externalstorage/FluidHandlerExternalStorageProvider.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/externalstorage/FluidHandlerExternalStorageProvider.java @@ -1,4 +1,4 @@ -package com.refinedmods.refinedstorage2.platform.forge.externalstorage; +package com.refinedmods.refinedstorage2.platform.forge.storage.externalstorage; import com.refinedmods.refinedstorage2.api.core.Action; import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/externalstorage/FluidHandlerPlatformExternalStorageProviderFactory.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/externalstorage/FluidHandlerPlatformExternalStorageProviderFactory.java similarity index 92% rename from refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/externalstorage/FluidHandlerPlatformExternalStorageProviderFactory.java rename to refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/externalstorage/FluidHandlerPlatformExternalStorageProviderFactory.java index 297ee315c..08d4928d3 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/externalstorage/FluidHandlerPlatformExternalStorageProviderFactory.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/externalstorage/FluidHandlerPlatformExternalStorageProviderFactory.java @@ -1,4 +1,4 @@ -package com.refinedmods.refinedstorage2.platform.forge.externalstorage; +package com.refinedmods.refinedstorage2.platform.forge.storage.externalstorage; import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannelType; import com.refinedmods.refinedstorage2.api.storage.external.ExternalStorageProvider; diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/externalstorage/ItemHandlerExternalStorageProvider.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/externalstorage/ItemHandlerExternalStorageProvider.java similarity index 96% rename from refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/externalstorage/ItemHandlerExternalStorageProvider.java rename to refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/externalstorage/ItemHandlerExternalStorageProvider.java index 0080daa6f..c176ea173 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/externalstorage/ItemHandlerExternalStorageProvider.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/externalstorage/ItemHandlerExternalStorageProvider.java @@ -1,4 +1,4 @@ -package com.refinedmods.refinedstorage2.platform.forge.externalstorage; +package com.refinedmods.refinedstorage2.platform.forge.storage.externalstorage; import com.refinedmods.refinedstorage2.api.core.Action; import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/externalstorage/ItemHandlerPlatformExternalStorageProviderFactory.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/externalstorage/ItemHandlerPlatformExternalStorageProviderFactory.java similarity index 92% rename from refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/externalstorage/ItemHandlerPlatformExternalStorageProviderFactory.java rename to refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/externalstorage/ItemHandlerPlatformExternalStorageProviderFactory.java index 37da61f22..96ff121dc 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/externalstorage/ItemHandlerPlatformExternalStorageProviderFactory.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/externalstorage/ItemHandlerPlatformExternalStorageProviderFactory.java @@ -1,4 +1,4 @@ -package com.refinedmods.refinedstorage2.platform.forge.externalstorage; +package com.refinedmods.refinedstorage2.platform.forge.storage.externalstorage; import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannelType; import com.refinedmods.refinedstorage2.api.storage.external.ExternalStorageProvider; diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/externalstorage/package-info.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/externalstorage/package-info.java new file mode 100644 index 000000000..03a5fada8 --- /dev/null +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/externalstorage/package-info.java @@ -0,0 +1,7 @@ +@ParametersAreNonnullByDefault +@FieldsAndMethodsAreNonnullByDefault +package com.refinedmods.refinedstorage2.platform.forge.storage.externalstorage; + +import com.refinedmods.refinedstorage2.api.core.FieldsAndMethodsAreNonnullByDefault; + +import javax.annotation.ParametersAreNonnullByDefault; diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/portablegrid/ForgePortableGridBlockEntity.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/portablegrid/ForgePortableGridBlockEntity.java new file mode 100644 index 000000000..41911a271 --- /dev/null +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/portablegrid/ForgePortableGridBlockEntity.java @@ -0,0 +1,32 @@ +package com.refinedmods.refinedstorage2.platform.forge.storage.portablegrid; + +import com.refinedmods.refinedstorage2.platform.common.portablegrid.AbstractPortableGridBlockEntity; +import com.refinedmods.refinedstorage2.platform.common.portablegrid.PortableGridType; +import com.refinedmods.refinedstorage2.platform.common.storage.Disk; + +import javax.annotation.Nonnull; + +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraftforge.client.model.data.ModelData; +import net.minecraftforge.client.model.data.ModelProperty; + +public class ForgePortableGridBlockEntity extends AbstractPortableGridBlockEntity { + public static final ModelProperty DISK_PROPERTY = new ModelProperty<>(); + + public ForgePortableGridBlockEntity(final PortableGridType type, final BlockPos pos, final BlockState state) { + super(type, pos, state); + } + + @Override + protected void onDriveStateUpdated() { + requestModelDataUpdate(); + super.onDriveStateUpdated(); + } + + @Nonnull + @Override + public ModelData getModelData() { + return ModelData.builder().with(DISK_PROPERTY, disk).build(); + } +} diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/portablegrid/PortableGridBakedModel.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/portablegrid/PortableGridBakedModel.java new file mode 100644 index 000000000..7e87ec907 --- /dev/null +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/portablegrid/PortableGridBakedModel.java @@ -0,0 +1,117 @@ +package com.refinedmods.refinedstorage2.platform.forge.storage.portablegrid; + +import com.refinedmods.refinedstorage2.api.network.impl.node.StorageState; +import com.refinedmods.refinedstorage2.platform.common.content.Items; +import com.refinedmods.refinedstorage2.platform.common.portablegrid.PortableGridBlock; +import com.refinedmods.refinedstorage2.platform.common.storage.Disk; +import com.refinedmods.refinedstorage2.platform.common.storage.FluidStorageType; +import com.refinedmods.refinedstorage2.platform.common.support.direction.BiDirection; +import com.refinedmods.refinedstorage2.platform.forge.support.render.DiskModelBaker; +import com.refinedmods.refinedstorage2.platform.forge.support.render.ItemBakedModel; +import com.refinedmods.refinedstorage2.platform.forge.support.render.RotationTranslationModelBaker; +import com.refinedmods.refinedstorage2.platform.forge.support.render.TransformationBuilder; + +import java.util.ArrayList; +import java.util.List; +import javax.annotation.Nullable; + +import com.google.common.cache.CacheBuilder; +import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; +import net.minecraft.client.multiplayer.ClientLevel; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.block.model.BakedQuad; +import net.minecraft.client.renderer.block.model.ItemOverrides; +import net.minecraft.client.resources.model.BakedModel; +import net.minecraft.core.Direction; +import net.minecraft.util.RandomSource; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraftforge.client.model.BakedModelWrapper; +import net.minecraftforge.client.model.data.ModelData; +import org.joml.Vector3f; + +public class PortableGridBakedModel extends BakedModelWrapper { + private static final Vector3f MOVE_TO_DISK_LOCATION = new Vector3f(0, -12 / 16F, 9 / 16F); + + private final LoadingCache> cache; + private final PortableGridItemOverrides itemOverrides = new PortableGridItemOverrides(); + + public PortableGridBakedModel(final BakedModel baseModel, + final RotationTranslationModelBaker activeModelBaker, + final RotationTranslationModelBaker inactiveModelBaker, + final DiskModelBaker diskModelBaker) { + super(baseModel); + this.cache = CacheBuilder.newBuilder().build(CacheLoader.from(cacheKey -> { + final RotationTranslationModelBaker baseModelBaker = cacheKey.active + ? activeModelBaker + : inactiveModelBaker; + final List quads = new ArrayList<>(baseModelBaker.bake(TransformationBuilder.create() + .rotate(cacheKey.direction) + .build()) + .getQuads(null, cacheKey.side(), RandomSource.create(0))); + if (cacheKey.disk.item() == null) { + return quads; + } + final RotationTranslationModelBaker diskBaker = diskModelBaker.forDisk(cacheKey.disk.item()); + if (diskBaker != null) { + quads.addAll(diskBaker.bake(TransformationBuilder.create() + .rotate(cacheKey.direction) + .translate(MOVE_TO_DISK_LOCATION) + .rotate(BiDirection.WEST) + .build()) + .getQuads(null, cacheKey.side(), RandomSource.create(0))); + } + return quads; + })); + } + + @Override + public List getQuads(@Nullable final BlockState state, + @Nullable final Direction side, + final RandomSource randomSource, + final ModelData extraData, + @Nullable final RenderType renderType) { + if (state == null || !(state.getBlock() instanceof PortableGridBlock portableGridBlock)) { + return super.getQuads(state, side, randomSource); + } + final BiDirection direction = portableGridBlock.getDirection(state); + if (direction == null) { + return super.getQuads(state, side, randomSource); + } + final Disk disk = extraData.get(ForgePortableGridBlockEntity.DISK_PROPERTY); + if (disk == null) { + return super.getQuads(state, side, randomSource); + } + return cache.getUnchecked(new CacheKey(side, direction, true, disk)); + } + + @Override + public ItemOverrides getOverrides() { + return itemOverrides; + } + + private class PortableGridItemOverrides extends ItemOverrides { + private final LoadingCache itemCache = CacheBuilder.newBuilder().build( + CacheLoader.from(cacheKey -> new ItemBakedModel(originalModel, cache.getUnchecked(cacheKey))) + ); + + @Override + @Nullable + public BakedModel resolve(final BakedModel bakedModel, + final ItemStack stack, + @Nullable final ClientLevel level, + @Nullable final LivingEntity entity, + final int seed) { + final Disk disk = new Disk( + Items.INSTANCE.getFluidStorageDisk(FluidStorageType.Variant.SIXTY_FOUR_B), + StorageState.NEAR_CAPACITY + ); + return itemCache.getUnchecked(new CacheKey(null, BiDirection.NORTH, true, disk)); + } + } + + private record CacheKey(@Nullable Direction side, BiDirection direction, boolean active, Disk disk) { + } +} diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/portablegrid/PortableGridBlockEntityRendererImpl.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/portablegrid/PortableGridBlockEntityRendererImpl.java new file mode 100644 index 000000000..34b14e57b --- /dev/null +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/portablegrid/PortableGridBlockEntityRendererImpl.java @@ -0,0 +1,21 @@ +package com.refinedmods.refinedstorage2.platform.forge.storage.portablegrid; + +import com.refinedmods.refinedstorage2.platform.common.portablegrid.AbstractPortableGridBlockEntity; +import com.refinedmods.refinedstorage2.platform.common.portablegrid.AbstractPortableGridBlockEntityRenderer; +import com.refinedmods.refinedstorage2.platform.common.storage.Disk; +import com.refinedmods.refinedstorage2.platform.forge.support.render.RenderTypes; + +import javax.annotation.Nullable; + +public class PortableGridBlockEntityRendererImpl + extends AbstractPortableGridBlockEntityRenderer { + public PortableGridBlockEntityRendererImpl() { + super(RenderTypes.DISK_LED); + } + + @Override + @Nullable + protected Disk getDisk(final T blockEntity) { + return blockEntity.getModelData().get(ForgePortableGridBlockEntity.DISK_PROPERTY); + } +} diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/portablegrid/PortableGridGeometryLoader.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/portablegrid/PortableGridGeometryLoader.java new file mode 100644 index 000000000..1e32ebdfc --- /dev/null +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/portablegrid/PortableGridGeometryLoader.java @@ -0,0 +1,13 @@ +package com.refinedmods.refinedstorage2.platform.forge.storage.portablegrid; + +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonObject; +import net.minecraftforge.client.model.geometry.IGeometryLoader; + +public class PortableGridGeometryLoader implements IGeometryLoader { + @Override + public PortableGridUnbakedGeometry read(final JsonObject jsonObject, + final JsonDeserializationContext deserializationContext) { + return new PortableGridUnbakedGeometry(); + } +} diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/portablegrid/PortableGridUnbakedGeometry.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/portablegrid/PortableGridUnbakedGeometry.java new file mode 100644 index 000000000..ad9581f4f --- /dev/null +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/portablegrid/PortableGridUnbakedGeometry.java @@ -0,0 +1,55 @@ +package com.refinedmods.refinedstorage2.platform.forge.storage.portablegrid; + +import com.refinedmods.refinedstorage2.platform.api.PlatformApi; +import com.refinedmods.refinedstorage2.platform.forge.support.render.DiskModelBaker; +import com.refinedmods.refinedstorage2.platform.forge.support.render.RotationTranslationModelBaker; + +import java.util.function.Function; + +import net.minecraft.client.renderer.block.model.ItemOverrides; +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 net.minecraftforge.client.model.geometry.IGeometryBakingContext; +import net.minecraftforge.client.model.geometry.IUnbakedGeometry; + +import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createIdentifier; +import static java.util.Objects.requireNonNull; + +// TODO: Cleanup model rendering code. +public class PortableGridUnbakedGeometry implements IUnbakedGeometry { + private static final ResourceLocation ACTIVE_MODEL = createIdentifier("block/portable_grid/active"); + private static final ResourceLocation INACTIVE_MODEL = createIdentifier("block/portable_grid/inactive"); + + PortableGridUnbakedGeometry() { + } + + @Override + public void resolveParents(final Function modelGetter, + final IGeometryBakingContext context) { + modelGetter.apply(ACTIVE_MODEL).resolveParents(modelGetter); + modelGetter.apply(INACTIVE_MODEL).resolveParents(modelGetter); + PlatformApi.INSTANCE.getStorageContainerItemHelper().getDiskModels().forEach( + diskModel -> modelGetter.apply(diskModel).resolveParents(modelGetter) + ); + } + + @Override + public BakedModel bake(final IGeometryBakingContext context, + final ModelBaker baker, + final Function spriteGetter, + final ModelState modelState, + final ItemOverrides overrides, + final ResourceLocation modelLocation) { + return new PortableGridBakedModel( + requireNonNull(baker.bake(INACTIVE_MODEL, modelState, spriteGetter)), + new RotationTranslationModelBaker(modelState, baker, spriteGetter, ACTIVE_MODEL), + new RotationTranslationModelBaker(modelState, baker, spriteGetter, INACTIVE_MODEL), + new DiskModelBaker(modelState, baker, spriteGetter) + ); + } +} diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/portablegrid/package-info.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/portablegrid/package-info.java new file mode 100644 index 000000000..5e7b5c9cf --- /dev/null +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/portablegrid/package-info.java @@ -0,0 +1,7 @@ +@ParametersAreNonnullByDefault +@FieldsAndMethodsAreNonnullByDefault +package com.refinedmods.refinedstorage2.platform.forge.storage.portablegrid; + +import com.refinedmods.refinedstorage2.api.core.FieldsAndMethodsAreNonnullByDefault; + +import javax.annotation.ParametersAreNonnullByDefault; diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/render/DiskModelBaker.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/render/DiskModelBaker.java new file mode 100644 index 000000000..403e18d52 --- /dev/null +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/render/DiskModelBaker.java @@ -0,0 +1,37 @@ +package com.refinedmods.refinedstorage2.platform.forge.support.render; + +import com.refinedmods.refinedstorage2.platform.api.PlatformApi; + +import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; +import javax.annotation.Nullable; + +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.client.resources.model.Material; +import net.minecraft.client.resources.model.ModelBaker; +import net.minecraft.client.resources.model.ModelState; +import net.minecraft.world.item.Item; + +// TODO: Loot function for portable grid. +public class DiskModelBaker { + private final Map bakers; + + public DiskModelBaker(final ModelState state, + final ModelBaker baker, + final Function spriteGetter) { + this.bakers = PlatformApi.INSTANCE.getStorageContainerItemHelper() + .getDiskModelsByItem() + .entrySet() + .stream() + .collect(Collectors.toMap( + Map.Entry::getKey, + entry -> new RotationTranslationModelBaker(state, baker, spriteGetter, entry.getValue()) + )); + } + + @Nullable + public RotationTranslationModelBaker forDisk(final Item item) { + return bakers.get(item); + } +} diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/render/ItemBakedModel.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/render/ItemBakedModel.java new file mode 100644 index 000000000..75d2fae71 --- /dev/null +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/render/ItemBakedModel.java @@ -0,0 +1,49 @@ +package com.refinedmods.refinedstorage2.platform.forge.support.render; + +import java.util.List; +import javax.annotation.Nullable; + +import com.mojang.blaze3d.vertex.PoseStack; +import net.minecraft.client.renderer.block.model.BakedQuad; +import net.minecraft.client.renderer.block.model.ItemOverrides; +import net.minecraft.client.resources.model.BakedModel; +import net.minecraft.core.Direction; +import net.minecraft.util.RandomSource; +import net.minecraft.world.item.ItemDisplayContext; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraftforge.client.model.BakedModelWrapper; + +public class ItemBakedModel extends BakedModelWrapper { + private final List quads; + + public ItemBakedModel(final BakedModel originalModel, final List quads) { + super(originalModel); + this.quads = quads; + } + + @Override + public List getQuads(@Nullable final BlockState state, + @Nullable final Direction side, + final RandomSource rand) { + return quads; + } + + @Override + public ItemOverrides getOverrides() { + return ItemOverrides.EMPTY; + } + + @Override + public List getRenderPasses(final ItemStack itemStack, final boolean fabulous) { + return List.of(this); + } + + @Override + public BakedModel applyTransform(final ItemDisplayContext cameraTransformType, + final PoseStack poseStack, + final boolean applyLeftHandTransform) { + originalModel.applyTransform(cameraTransformType, poseStack, applyLeftHandTransform); + return this; + } +} diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/render/RenderTypes.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/render/RenderTypes.java new file mode 100644 index 000000000..7a219bfdd --- /dev/null +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/render/RenderTypes.java @@ -0,0 +1,24 @@ +package com.refinedmods.refinedstorage2.platform.forge.support.render; + +import com.mojang.blaze3d.vertex.DefaultVertexFormat; +import com.mojang.blaze3d.vertex.VertexFormat; +import net.minecraft.client.renderer.GameRenderer; +import net.minecraft.client.renderer.RenderStateShard; +import net.minecraft.client.renderer.RenderType; + +public final class RenderTypes { + public static final RenderType DISK_LED = RenderType.create( + "disk_led", + DefaultVertexFormat.POSITION_COLOR, + VertexFormat.Mode.QUADS, + 32565, + false, + true, + RenderType.CompositeState.builder() + .setShaderState(new RenderStateShard.ShaderStateShard(GameRenderer::getPositionColorShader)) + .createCompositeState(false) + ); + + private RenderTypes() { + } +} diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/render/RotationTranslationModelBaker.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/render/RotationTranslationModelBaker.java new file mode 100644 index 000000000..21b3e5da3 --- /dev/null +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/render/RotationTranslationModelBaker.java @@ -0,0 +1,36 @@ +package com.refinedmods.refinedstorage2.platform.forge.support.render; + +import java.util.function.Function; +import javax.annotation.Nullable; + +import com.mojang.math.Transformation; +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.resources.ResourceLocation; +import net.minecraftforge.client.model.SimpleModelState; + +public class RotationTranslationModelBaker { + private final ModelState state; + private final ModelBaker baker; + private final Function spriterGetter; + private final ResourceLocation model; + + public RotationTranslationModelBaker(final ModelState state, + final ModelBaker baker, + final Function spriterGetter, + final ResourceLocation model) { + this.state = state; + this.baker = baker; + this.spriterGetter = spriterGetter; + this.model = model; + } + + @Nullable + public BakedModel bake(final Transformation transformation) { + final ModelState wrappedState = new SimpleModelState(transformation, state.isUvLocked()); + return baker.bake(model, wrappedState, spriterGetter); + } +} diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/render/TransformationBuilder.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/render/TransformationBuilder.java new file mode 100644 index 000000000..76459fee5 --- /dev/null +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/render/TransformationBuilder.java @@ -0,0 +1,38 @@ +package com.refinedmods.refinedstorage2.platform.forge.support.render; + +import com.refinedmods.refinedstorage2.platform.common.support.direction.BiDirection; + +import java.util.ArrayList; +import java.util.List; + +import com.mojang.math.Transformation; +import org.joml.Vector3f; + +public class TransformationBuilder { + private final List transforms = new ArrayList<>(); + + private TransformationBuilder() { + } + + public static TransformationBuilder create() { + return new TransformationBuilder(); + } + + public TransformationBuilder translate(final Vector3f translation) { + transforms.add(new Transformation(translation, null, null, null)); + return this; + } + + public TransformationBuilder rotate(final BiDirection direction) { + transforms.add(new Transformation(null, direction.getQuaternion(), null, null)); + return this; + } + + public Transformation build() { + Transformation result = Transformation.identity(); + for (final Transformation child : transforms) { + result = result.compose(child); + } + return result; + } +}