From 3ce4d477270b8e858d9e9d5c6a03fb3d725b29f4 Mon Sep 17 00:00:00 2001 From: raoulvdberge Date: Sat, 4 Nov 2023 18:24:52 +0100 Subject: [PATCH 1/4] refactor: remove resource list indexing as it wasn't used --- .../list/AbstractProxyResourceList.java | 6 -- .../api/resource/list/ResourceList.java | 9 --- .../api/resource/list/ResourceListImpl.java | 36 ++------- .../list/ResourceListOperationResult.java | 8 +- .../list/AbstractResourceListTest.java | 78 ++----------------- .../ListenableResourceListTest.java | 4 - 6 files changed, 15 insertions(+), 126 deletions(-) diff --git a/refinedstorage2-resource-api/src/main/java/com/refinedmods/refinedstorage2/api/resource/list/AbstractProxyResourceList.java b/refinedstorage2-resource-api/src/main/java/com/refinedmods/refinedstorage2/api/resource/list/AbstractProxyResourceList.java index 516958e4e..0d78f05ee 100644 --- a/refinedstorage2-resource-api/src/main/java/com/refinedmods/refinedstorage2/api/resource/list/AbstractProxyResourceList.java +++ b/refinedstorage2-resource-api/src/main/java/com/refinedmods/refinedstorage2/api/resource/list/AbstractProxyResourceList.java @@ -4,7 +4,6 @@ import java.util.Collection; import java.util.Optional; -import java.util.UUID; import org.apiguardian.api.API; @@ -36,11 +35,6 @@ public Optional> get(final T resource) { return delegate.get(resource); } - @Override - public Optional> get(final UUID id) { - return delegate.get(id); - } - @Override public Collection> getAll() { return delegate.getAll(); diff --git a/refinedstorage2-resource-api/src/main/java/com/refinedmods/refinedstorage2/api/resource/list/ResourceList.java b/refinedstorage2-resource-api/src/main/java/com/refinedmods/refinedstorage2/api/resource/list/ResourceList.java index e5f677d58..3077e3d7f 100644 --- a/refinedstorage2-resource-api/src/main/java/com/refinedmods/refinedstorage2/api/resource/list/ResourceList.java +++ b/refinedstorage2-resource-api/src/main/java/com/refinedmods/refinedstorage2/api/resource/list/ResourceList.java @@ -4,7 +4,6 @@ import java.util.Collection; import java.util.Optional; -import java.util.UUID; import org.apiguardian.api.API; @@ -66,14 +65,6 @@ default Optional> remove(ResourceAmount resour */ Optional> get(T resource); - /** - * Retrieves the resource and its amount from the list, identified by ID. - * - * @param id the id - * @return the resource amount if it's present in the list, otherwise an empty {@link Optional} - */ - Optional> get(UUID id); - /** * Retrieves all resources and their amounts from the list. * diff --git a/refinedstorage2-resource-api/src/main/java/com/refinedmods/refinedstorage2/api/resource/list/ResourceListImpl.java b/refinedstorage2-resource-api/src/main/java/com/refinedmods/refinedstorage2/api/resource/list/ResourceListImpl.java index f46e0dcb0..0c90d1275 100644 --- a/refinedstorage2-resource-api/src/main/java/com/refinedmods/refinedstorage2/api/resource/list/ResourceListImpl.java +++ b/refinedstorage2-resource-api/src/main/java/com/refinedmods/refinedstorage2/api/resource/list/ResourceListImpl.java @@ -6,7 +6,6 @@ import java.util.HashMap; import java.util.Map; import java.util.Optional; -import java.util.UUID; import org.apiguardian.api.API; @@ -19,8 +18,6 @@ @API(status = API.Status.STABLE, since = "2.0.0-milestone.1.2") public class ResourceListImpl implements ResourceList { private final Map> entries = new HashMap<>(); - private final Map> index = new HashMap<>(); - private final Map, UUID> inverseIndex = new HashMap<>(); @Override public ResourceListOperationResult add(final T resource, final long amount) { @@ -35,19 +32,13 @@ public ResourceListOperationResult add(final T resource, final long amount) { private ResourceListOperationResult addToExisting(final ResourceAmount resourceAmount, final long amount) { resourceAmount.increment(amount); - return new ResourceListOperationResult<>(resourceAmount, amount, inverseIndex.get(resourceAmount), true); + return new ResourceListOperationResult<>(resourceAmount, amount, true); } private ResourceListOperationResult addNew(final T resource, final long amount) { final ResourceAmount resourceAmount = new ResourceAmount<>(resource, amount); - - final UUID id = UUID.randomUUID(); - - index.put(id, resourceAmount); - inverseIndex.put(resourceAmount, id); entries.put(resource, resourceAmount); - - return new ResourceListOperationResult<>(resourceAmount, amount, id, true); + return new ResourceListOperationResult<>(resourceAmount, amount, true); } @Override @@ -56,12 +47,10 @@ public Optional> remove(final T resource, final l final ResourceAmount existing = entries.get(resource); if (existing != null) { - final UUID id = inverseIndex.get(existing); - if (existing.getAmount() - amount <= 0) { - return removeCompletely(existing, id); + return removeCompletely(existing); } else { - return removePartly(amount, existing, id); + return removePartly(amount, existing); } } @@ -69,23 +58,18 @@ public Optional> remove(final T resource, final l } private Optional> removePartly(final long amount, - final ResourceAmount resourceAmount, - final UUID id) { + final ResourceAmount resourceAmount) { resourceAmount.decrement(amount); - return Optional.of(new ResourceListOperationResult<>(resourceAmount, -amount, id, true)); + return Optional.of(new ResourceListOperationResult<>(resourceAmount, -amount, true)); } - private Optional> removeCompletely(final ResourceAmount resourceAmount, - final UUID id) { - index.remove(id); - inverseIndex.remove(resourceAmount); + private Optional> removeCompletely(final ResourceAmount resourceAmount) { entries.remove(resourceAmount.getResource()); return Optional.of(new ResourceListOperationResult<>( resourceAmount, -resourceAmount.getAmount(), - id, false )); } @@ -95,11 +79,6 @@ public Optional> get(final T resource) { return Optional.ofNullable(entries.get(resource)); } - @Override - public Optional> get(final UUID id) { - return Optional.ofNullable(index.get(id)); - } - @Override public Collection> getAll() { return entries.values(); @@ -107,7 +86,6 @@ public Collection> getAll() { @Override public void clear() { - index.clear(); entries.clear(); } } diff --git a/refinedstorage2-resource-api/src/main/java/com/refinedmods/refinedstorage2/api/resource/list/ResourceListOperationResult.java b/refinedstorage2-resource-api/src/main/java/com/refinedmods/refinedstorage2/api/resource/list/ResourceListOperationResult.java index 1cc3421ce..c6aa484a9 100644 --- a/refinedstorage2-resource-api/src/main/java/com/refinedmods/refinedstorage2/api/resource/list/ResourceListOperationResult.java +++ b/refinedstorage2-resource-api/src/main/java/com/refinedmods/refinedstorage2/api/resource/list/ResourceListOperationResult.java @@ -2,8 +2,6 @@ import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; -import java.util.UUID; - import org.apiguardian.api.API; /** @@ -12,12 +10,8 @@ * @param the type of resource * @param resourceAmount the current resource amount in the list * @param change the delta caused by the operation - * @param id the id of the resource in the list * @param available whether this resource is still available in the list, or if it was removed */ @API(status = API.Status.STABLE, since = "2.0.0-milestone.1.2") -public record ResourceListOperationResult(ResourceAmount resourceAmount, - long change, - UUID id, - boolean available) { +public record ResourceListOperationResult(ResourceAmount resourceAmount, long change, boolean available) { } diff --git a/refinedstorage2-resource-api/src/test/java/com/refinedmods/refinedstorage2/api/resource/list/AbstractResourceListTest.java b/refinedstorage2-resource-api/src/test/java/com/refinedmods/refinedstorage2/api/resource/list/AbstractResourceListTest.java index 188af2b78..36927cec5 100644 --- a/refinedstorage2-resource-api/src/test/java/com/refinedmods/refinedstorage2/api/resource/list/AbstractResourceListTest.java +++ b/refinedstorage2-resource-api/src/test/java/com/refinedmods/refinedstorage2/api/resource/list/AbstractResourceListTest.java @@ -5,7 +5,6 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Optional; -import java.util.UUID; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -30,7 +29,6 @@ void shouldAddNewResource() { final ResourceListOperationResult result = list.add("A", 10); // Assert - assertThat(result.id()).isNotNull(); assertThat(result.change()).isEqualTo(10); assertThat(result.resourceAmount().getAmount()).isEqualTo(10); assertThat(result.resourceAmount().getResource()).isEqualTo("A"); @@ -47,7 +45,6 @@ void shouldAddNewResourceWithResourceAmountDirectly() { final ResourceListOperationResult result = list.add(new ResourceAmount<>("A", 10)); // Assert - assertThat(result.id()).isNotNull(); assertThat(result.change()).isEqualTo(10); assertThat(result.resourceAmount().getAmount()).isEqualTo(10); assertThat(result.resourceAmount().getResource()).isEqualTo("A"); @@ -65,13 +62,11 @@ void shouldAddMultipleOfSameResource() { final ResourceListOperationResult result2 = list.add("A", 5); // Assert - assertThat(result1.id()).isNotNull(); assertThat(result1.change()).isEqualTo(10); assertThat(result1.resourceAmount().getAmount()).isEqualTo(15); assertThat(result1.resourceAmount().getResource()).isEqualTo("A"); assertThat(result1.available()).isTrue(); - assertThat(result2.id()).isEqualTo(result1.id()); assertThat(result2.change()).isEqualTo(5); assertThat(result1.resourceAmount().getAmount()).isEqualTo(15); assertThat(result1.resourceAmount().getResource()).isEqualTo("A"); @@ -90,19 +85,16 @@ void shouldAddMultipleOfDifferentResources() { final ResourceListOperationResult result3 = list.add("B", 3); // Assert - assertThat(result1.id()).isNotNull(); assertThat(result1.change()).isEqualTo(10); assertThat(result1.resourceAmount().getAmount()).isEqualTo(15); assertThat(result1.resourceAmount().getResource()).isEqualTo("A"); assertThat(result1.available()).isTrue(); - assertThat(result2.id()).isEqualTo(result1.id()); assertThat(result2.change()).isEqualTo(5); assertThat(result2.resourceAmount().getAmount()).isEqualTo(15); assertThat(result2.resourceAmount().getResource()).isEqualTo("A"); assertThat(result2.available()).isTrue(); - assertThat(result3.id()).isEqualTo(result3.id()); assertThat(result3.change()).isEqualTo(3); assertThat(result3.resourceAmount().getAmount()).isEqualTo(3); assertThat(result3.resourceAmount().getResource()).isEqualTo("B"); @@ -140,7 +132,7 @@ void shouldNotRemoveResourceWhenItIsNotAvailable() { @Test void shouldRemoveResourcePartly() { // Arrange - final ResourceListOperationResult result1 = list.add("A", 20); + list.add("A", 20); list.add("B", 6); // Act @@ -148,7 +140,6 @@ void shouldRemoveResourcePartly() { // Assert assertThat(result2).isPresent(); - assertThat(result2.get().id()).isEqualTo(result1.id()); assertThat(result2.get().change()).isEqualTo(-5); assertThat(result2.get().resourceAmount().getAmount()).isEqualTo(15); assertThat(result2.get().resourceAmount().getResource()).isEqualTo("A"); @@ -163,7 +154,7 @@ void shouldRemoveResourcePartly() { @Test void shouldRemoveResourcePartlyWithResourceAmountDirectly() { // Arrange - final ResourceListOperationResult result1 = list.add("A", 20); + list.add("A", 20); list.add("B", 6); // Act @@ -174,7 +165,6 @@ void shouldRemoveResourcePartlyWithResourceAmountDirectly() { // Assert assertThat(result2).isPresent(); - assertThat(result2.get().id()).isEqualTo(result1.id()); assertThat(result2.get().change()).isEqualTo(-5); assertThat(result2.get().resourceAmount().getAmount()).isEqualTo(15); assertThat(result2.get().resourceAmount().getResource()).isEqualTo("A"); @@ -189,7 +179,7 @@ void shouldRemoveResourcePartlyWithResourceAmountDirectly() { @Test void shouldRemoveResourceCompletely() { // Arrange - final ResourceListOperationResult result1 = list.add("A", 20); + list.add("A", 20); list.add("B", 6); // Act @@ -197,7 +187,6 @@ void shouldRemoveResourceCompletely() { // Assert assertThat(result2).isPresent(); - assertThat(result2.get().id()).isEqualTo(result1.id()); assertThat(result2.get().change()).isEqualTo(-20); assertThat(result2.get().resourceAmount().getAmount()).isEqualTo(20); assertThat(result2.get().resourceAmount().getResource()).isEqualTo("A"); @@ -211,7 +200,7 @@ void shouldRemoveResourceCompletely() { @Test void shouldRemoveResourceCompletelyWithResourceAmountDirectly() { // Arrange - final ResourceListOperationResult result1 = list.add("A", 20); + list.add("A", 20); list.add("B", 6); // Act @@ -222,7 +211,6 @@ void shouldRemoveResourceCompletelyWithResourceAmountDirectly() { // Assert assertThat(result2).isPresent(); - assertThat(result2.get().id()).isEqualTo(result1.id()); assertThat(result2.get().change()).isEqualTo(-20); assertThat(result2.get().resourceAmount().getAmount()).isEqualTo(20); assertThat(result2.get().resourceAmount().getResource()).isEqualTo("A"); @@ -236,7 +224,7 @@ void shouldRemoveResourceCompletelyWithResourceAmountDirectly() { @Test void shouldNotRemoveResourceWithMoreThanIsAvailable() { // Arrange - final ResourceListOperationResult result1 = list.add("A", 20); + list.add("A", 20); list.add("B", 6); // Act @@ -244,7 +232,6 @@ void shouldNotRemoveResourceWithMoreThanIsAvailable() { // Assert assertThat(result2).isPresent(); - assertThat(result2.get().id()).isEqualTo(result1.id()); assertThat(result2.get().change()).isEqualTo(-20); assertThat(result2.get().resourceAmount().getAmount()).isEqualTo(20); assertThat(result2.get().resourceAmount().getResource()).isEqualTo("A"); @@ -283,35 +270,6 @@ void shouldBeAbleToRetrieveByResourceAfterAdding() { assertThat(resourceAmount.get().getAmount()).isEqualTo(6); } - @Test - void shouldBeAbleToRetrieveByIdAfterAdding() { - // Arrange - final ResourceListOperationResult result = list.add("A", 3); - - // Act - final Optional> resourceAmount = list.get(result.id()); - - // Assert - assertThat(resourceAmount).isPresent(); - assertThat(resourceAmount.get().getResource()).isEqualTo("A"); - assertThat(resourceAmount.get().getAmount()).isEqualTo(3); - } - - @Test - void shouldStillBeAbleToRetrieveByIdWhenRemovingPartly() { - // Arrange - final ResourceListOperationResult result = list.add("A", 10); - list.remove("A", 3); - - // Act - final Optional> resourceAmount = list.get(result.id()); - - // Assert - assertThat(resourceAmount).isPresent(); - assertThat(resourceAmount.get().getResource()).isEqualTo("A"); - assertThat(resourceAmount.get().getAmount()).isEqualTo(7); - } - @Test void shouldStillBeAbleToRetrieveByResourceWhenRemovingPartly() { // Arrange @@ -340,43 +298,21 @@ void shouldNotBeAbleToRetrieveByResourceWhenRemovingCompletely() { assertThat(resourceAmount).isNotPresent(); } - @Test - void shouldNotBeAbleToRetrieveByIdWhenRemovingCompletely() { - // Arrange - final ResourceListOperationResult result = list.add("A", 10); - list.remove("A", 10); - - // Act - final Optional> resourceAmount = list.get(result.id()); - - // Assert - assertThat(resourceAmount).isNotPresent(); - } - @Test void shouldClearList() { // Arrange - final UUID id1 = list.add("A", 10).id(); - final UUID id2 = list.add("B", 5).id(); + list.add("A", 10); + list.add("B", 5); final Collection> contentsBeforeClear = new ArrayList<>(list.getAll()); - final Optional> aBeforeClear = list.get(id1); - final Optional> bBeforeClear = list.get(id2); // Act list.clear(); // Assert final Collection> contentsAfterClear = list.getAll(); - final Optional> aAfterClear = list.get(id1); - final Optional> bAfterClear = list.get(id2); assertThat(contentsBeforeClear).hasSize(2); - assertThat(aBeforeClear).isPresent(); - assertThat(bBeforeClear).isPresent(); - assertThat(contentsAfterClear).isEmpty(); - assertThat(aAfterClear).isEmpty(); - assertThat(bAfterClear).isEmpty(); } } diff --git a/refinedstorage2-resource-api/src/test/java/com/refinedmods/refinedstorage2/api/resource/list/listenable/ListenableResourceListTest.java b/refinedstorage2-resource-api/src/test/java/com/refinedmods/refinedstorage2/api/resource/list/listenable/ListenableResourceListTest.java index bdbe396eb..c7fc98868 100644 --- a/refinedstorage2-resource-api/src/test/java/com/refinedmods/refinedstorage2/api/resource/list/listenable/ListenableResourceListTest.java +++ b/refinedstorage2-resource-api/src/test/java/com/refinedmods/refinedstorage2/api/resource/list/listenable/ListenableResourceListTest.java @@ -33,7 +33,6 @@ void shouldCallListenerWhenAdding() { final ResourceListOperationResult result = sut.add("A", 10); // Assert - assertThat(result.id()).isNotNull(); assertThat(result.change()).isEqualTo(10); assertThat(result.resourceAmount().getAmount()).isEqualTo(10); assertThat(result.resourceAmount().getResource()).isEqualTo("A"); @@ -47,7 +46,6 @@ void shouldNotCallListenerWhenAddingWithoutListener() { final ResourceListOperationResult result = sut.add("A", 10); // Assert - assertThat(result.id()).isNotNull(); assertThat(result.change()).isEqualTo(10); assertThat(result.resourceAmount().getAmount()).isEqualTo(10); assertThat(result.resourceAmount().getResource()).isEqualTo("A"); @@ -66,7 +64,6 @@ void shouldCallListenerWhenRemoving() { // Assert assertThat(result).isPresent(); - assertThat(result.get().id()).isNotNull(); assertThat(result.get().change()).isEqualTo(-10); assertThat(result.get().resourceAmount().getAmount()).isEqualTo(10); assertThat(result.get().resourceAmount().getResource()).isEqualTo("A"); @@ -84,7 +81,6 @@ void shouldNotCallListenerWhenRemovingWithoutListener() { // Assert assertThat(result).isPresent(); - assertThat(result.get().id()).isNotNull(); assertThat(result.get().change()).isEqualTo(-10); assertThat(result.get().resourceAmount().getAmount()).isEqualTo(10); assertThat(result.get().resourceAmount().getResource()).isEqualTo("A"); From e24705a43155cbfc31cdc743ee3b255f988d35a2 Mon Sep 17 00:00:00 2001 From: raoulvdberge Date: Sat, 4 Nov 2023 20:06:39 +0100 Subject: [PATCH 2/4] feat: content for portable grid Block, recipe and models. --- CHANGELOG.md | 1 + .../refinedstorage2/api/grid/GridWatcher.java | 4 +- .../grid/operations/GridOperationsImpl.java | 3 +- .../node/grid/GridWatcherRegistration.java | 8 +- .../network/impl/node/grid/GridWatchers.java | 2 +- .../impl/PriorityNetworkBuilderImplTest.java | 2 +- .../impl/node/grid/GridNetworkNodeTest.java | 2 +- .../common/AbstractModInitializer.java | 43 +- .../common/content/BlockEntities.java | 62 +- .../platform/common/content/Blocks.java | 34 +- .../platform/common/content/ContentIds.java | 2 + .../common/content/CreativeModeTabItems.java | 2 + .../platform/common/content/Items.java | 67 ++- .../grid/AbstractGridContainerMenu.java | 2 +- .../AbstractPortableGridBlockEntity.java | 40 ++ ...stractPortableGridBlockEntityRenderer.java | 65 ++ .../portablegrid/PortableGridBlock.java | 64 ++ .../common/portablegrid/PortableGridItem.java | 11 + .../common/portablegrid/PortableGridType.java | 6 + .../common/portablegrid}/package-info.java | 2 +- .../DiskDriveDisk.java => Disk.java} | 4 +- .../AbstractDiskDriveBlockEntity.java | 9 +- .../AbstractDiskDriveBlockEntityRenderer.java | 90 +-- .../AbstractDiskLedBlockEntityRenderer.java | 50 ++ .../common/support/render/CubeBuilder.java | 122 ++-- .../blockstates/creative_portable_grid.json | 7 + .../blockstates/portable_grid.json | 7 + .../assets/refinedstorage2/lang/en_us.json | 6 +- .../models/block/creative_portable_grid.json | 4 + .../models/block/disk/disk.json | 18 - .../models/block/disk/fluid_disk.json | 18 - .../models/block/portable_grid.json | 4 + .../models/block/portable_grid/active.json | 6 + .../models/block/portable_grid/base.json | 558 ++++++++++++++++++ .../models/block/portable_grid/inactive.json | 6 + .../models/item/creative_portable_grid.json | 3 + .../models/item/portable_grid.json | 3 + .../block/portable_grid/portable_grid_1.png | Bin 0 -> 439 bytes .../block/portable_grid/portable_grid_2.png | Bin 0 -> 462 bytes .../portable_grid_2_inactive.png | Bin 0 -> 557 bytes .../block/portable_grid/portable_grid_3.png | Bin 0 -> 616 bytes .../block/portable_grid/portable_grid_4.png | Bin 0 -> 324 bytes .../block/portable_grid/portable_grid_5.png | Bin 0 -> 485 bytes .../block/portable_grid/portable_grid_6.png | Bin 0 -> 220 bytes .../block/portable_grid/portable_grid_7.png | Bin 0 -> 522 bytes .../block/portable_grid/portable_grid_8.png | Bin 0 -> 150 bytes .../advancements/portable_storage.json | 28 + .../blocks/creative_portable_grid.json | 19 + .../loot_tables/blocks/portable_grid.json | 19 + .../recipes/portable_grid.json | 22 + .../fabric/ClientModInitializerImpl.java | 28 +- .../platform/fabric/ModInitializerImpl.java | 13 +- .../diskdrive/DiskDriveBakedModel.java | 30 +- .../DiskDriveBlockEntityRendererImpl.java | 27 +- .../diskdrive/DiskDriveUnbakedModel.java | 10 +- .../FabricPortableGridBlockEntity.java | 23 + .../portablegrid/PortableGridBakedModel.java | 77 +++ .../PortableGridBlockEntityRendererImpl.java | 27 + .../PortableGridUnbakedModel.java | 68 +++ .../storage/portablegrid/package-info.java | 7 + .../fabric/support/render/QuadRotators.java | 20 + .../fabric/support/render/RenderTypes.java | 24 + .../platform/forge/ClientModInitializer.java | 12 + .../platform/forge/ModInitializer.java | 17 +- .../diskdrive/DiskDriveBakedModel.java | 18 +- .../DiskDriveBlockEntityRendererImpl.java | 25 +- .../diskdrive/ForgeDiskDriveBlockEntity.java | 4 +- .../FluidHandlerExternalStorageProvider.java | 2 +- ...latformExternalStorageProviderFactory.java | 2 +- .../ItemHandlerExternalStorageProvider.java | 2 +- ...latformExternalStorageProviderFactory.java | 2 +- .../storage/externalstorage/package-info.java | 7 + .../ForgePortableGridBlockEntity.java | 32 + .../portablegrid/PortableGridBakedModel.java | 117 ++++ .../PortableGridBlockEntityRendererImpl.java | 21 + .../PortableGridGeometryLoader.java | 13 + .../PortableGridUnbakedGeometry.java | 55 ++ .../storage/portablegrid/package-info.java | 7 + .../forge/support/render/DiskModelBaker.java | 37 ++ .../forge/support/render/ItemBakedModel.java | 49 ++ .../forge/support/render/RenderTypes.java | 24 + .../render/RotationTranslationModelBaker.java | 36 ++ .../support/render/TransformationBuilder.java | 38 ++ 83 files changed, 1972 insertions(+), 327 deletions(-) create mode 100644 refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/portablegrid/AbstractPortableGridBlockEntity.java create mode 100644 refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/portablegrid/AbstractPortableGridBlockEntityRenderer.java create mode 100644 refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/portablegrid/PortableGridBlock.java create mode 100644 refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/portablegrid/PortableGridItem.java create mode 100644 refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/portablegrid/PortableGridType.java rename {refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/externalstorage => refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/portablegrid}/package-info.java (74%) rename refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/{diskdrive/DiskDriveDisk.java => Disk.java} (51%) create mode 100644 refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/render/AbstractDiskLedBlockEntityRenderer.java create mode 100644 refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/blockstates/creative_portable_grid.json create mode 100644 refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/blockstates/portable_grid.json create mode 100644 refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/creative_portable_grid.json create mode 100644 refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/portable_grid.json create mode 100644 refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/portable_grid/active.json create mode 100644 refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/portable_grid/base.json create mode 100644 refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/block/portable_grid/inactive.json create mode 100644 refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/item/creative_portable_grid.json create mode 100644 refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/item/portable_grid.json create mode 100644 refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/portable_grid/portable_grid_1.png create mode 100644 refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/portable_grid/portable_grid_2.png create mode 100644 refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/portable_grid/portable_grid_2_inactive.png create mode 100644 refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/portable_grid/portable_grid_3.png create mode 100644 refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/portable_grid/portable_grid_4.png create mode 100644 refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/portable_grid/portable_grid_5.png create mode 100644 refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/portable_grid/portable_grid_6.png create mode 100644 refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/portable_grid/portable_grid_7.png create mode 100644 refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/portable_grid/portable_grid_8.png create mode 100644 refinedstorage2-platform-common/src/main/resources/data/refinedstorage2/advancements/portable_storage.json create mode 100644 refinedstorage2-platform-common/src/main/resources/data/refinedstorage2/loot_tables/blocks/creative_portable_grid.json create mode 100644 refinedstorage2-platform-common/src/main/resources/data/refinedstorage2/loot_tables/blocks/portable_grid.json create mode 100644 refinedstorage2-platform-common/src/main/resources/data/refinedstorage2/recipes/portable_grid.json create mode 100644 refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/storage/portablegrid/FabricPortableGridBlockEntity.java create mode 100644 refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/storage/portablegrid/PortableGridBakedModel.java create mode 100644 refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/storage/portablegrid/PortableGridBlockEntityRendererImpl.java create mode 100644 refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/storage/portablegrid/PortableGridUnbakedModel.java create mode 100644 refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/storage/portablegrid/package-info.java create mode 100644 refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/support/render/QuadRotators.java create mode 100644 refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/support/render/RenderTypes.java rename refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/{ => storage}/externalstorage/FluidHandlerExternalStorageProvider.java (96%) rename refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/{ => storage}/externalstorage/FluidHandlerPlatformExternalStorageProviderFactory.java (92%) rename refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/{ => storage}/externalstorage/ItemHandlerExternalStorageProvider.java (96%) rename refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/{ => storage}/externalstorage/ItemHandlerPlatformExternalStorageProviderFactory.java (92%) create mode 100644 refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/externalstorage/package-info.java create mode 100644 refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/portablegrid/ForgePortableGridBlockEntity.java create mode 100644 refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/portablegrid/PortableGridBakedModel.java create mode 100644 refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/portablegrid/PortableGridBlockEntityRendererImpl.java create mode 100644 refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/portablegrid/PortableGridGeometryLoader.java create mode 100644 refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/portablegrid/PortableGridUnbakedGeometry.java create mode 100644 refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/portablegrid/package-info.java create mode 100644 refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/render/DiskModelBaker.java create mode 100644 refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/render/ItemBakedModel.java create mode 100644 refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/render/RenderTypes.java create mode 100644 refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/render/RotationTranslationModelBaker.java create mode 100644 refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/render/TransformationBuilder.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 07d5e4033..50d7f0f8e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ### Added - Custom disk models. Fluid disks now have a different model. +- Portable Grid ## [2.0.0-milestone.3.2] - 2023-11-03 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 0000000000000000000000000000000000000000..a6b7645a0ba4c8ce51d1544b7229057d7e3c4a52 GIT binary patch literal 439 zcmV;o0Z9IdP)_MYgTK^mXAJ^x@V`Wy1GZ})oL}XR4PKT zShP~9qzJgn<#Ngkg@RvGE|;xZt*X{*G#WM@k8Ly>S+Cc#>2#{|a5%Jnzps2gpWAl3 zwe@;!o6W`+i-qm?dkK0dwOTE!*Xz1OXf~Uv0OIL%vfXZHx7$s)Ua!_}x9$0SehOfd z&J;sJeYINoIo}V5gK$2d;e hT`B$vTH?R|jUO6=#dFNPs8Ij_002ovPDHLkV1hnh$hiOj literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..d6ee53cd935fe7e26120e988e83f9e26a6881bb9 GIT binary patch literal 462 zcmV;<0WtoGP)2M-b4MeyK)D+q#@Aov3j{Gs`uKE6p6wCHFCrlF`#ce-9x zUdPDga$=gMoK7clGMOYW&tx($jCJGp*zI=Q==FNC-|uBMn-TN*oIIIKWH=m(ZQGJa zB;Ezq>oo-~m&>1(_1>GnYPI6VbUKxIJT9G1hZRxz*$Du*ZvxBZl9djJ16^FNSMu?A zlt!cRfZ;cg8xBx)G#W{_+m%QpBK>|}DwT?q%Vok>01>nUbOM6l^ZCrmrBX@i^}4?c zue$PDso(&e7z_sd9^>(t2O$6l)oS&#Kq{3|o6SZ!jw7vBOS0MQNBBm7fEPpEZa1+k zOK`FB`8-i97U=-&E09j7)nc(w_xoMi?Y1 zpaBV;uq#i^X_(qS5FBc*X&J z5Ww2=Gh^Wr;fteHUL1D8>kQ}kfeM8J=K$W-?*Q2Q0eZ<`(d&VVBLDyZ07*qoM6N<$ Eg78_@R{#J2 literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..b492fb8b9ff939d0445624e49a0444034a6d3cb7 GIT binary patch literal 557 zcmV+|0@D47P)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D02y>eSaefwW^{L9 za%BK;VQFr3E^cLXAT%y8E-^MlX|MGF00EszL_t(IPmNQ@sscd}^oz_OW?d78qaHjc zm__hlzzBliMFf99!OxsyJ5|i8`_}h(4Moq+bf}u1^<**`iO1t|JRa#|u^54MDwT40 z?0bINcDv<4x7(H7ZYR^}l$gzC^yBeZ27`gLS}lo2qwWH$)rti!m&>1>?K6}1w&ilk zgUMtfkw`?^?KV52^CuGkY)#tR7K;Tt?e}}KxL&XHhr>at)#?i-+-=Ye2Ix8*4yDuS zNH7?bUau#`Vo?f(0%5}41_?F;OacYrPp1<*=ks}~R4Tu-(A||Dr2+#?qTlcHK1QPv z6Hx#RN~O~G0*ORIt=DUHKA)x0Xh=Gp{t6TBHWbh@)ct;!dc7`qSlMir$mMcm0B^$G zmP{tqd_Gr?$3vRUrqpUR0-9}KE|)3Cq&N-w^{mzHcB2I7)sdWl4X}VWDNX}}&1R!; z>tJBE|8HOb2|k}sfIuMN@HYH@Kli*|FW2zc=ie9(hxvFyq0kHXMuMFPVDIyrvhav- v;~15e!zt*=aE%|xvMjCv#M&`{Wm)nBLknP`n9TvB00000NkvXXu0mjfPVn?F literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..a8bfc4a33a9bbc121ae59f6ec6c1528d9660dded GIT binary patch literal 616 zcmV-u0+;=XP)l_lJAC+P%ZDtk725o>SH7DA8z?!r`!3 zAP^v<(I{v#nJAG+P$(1bF0}DYc?9xsMo)(UaL{9TBY~5Hz6>a%`bv8t0T3`d)LDU(i9lVb*hffS4i1cQEG zR8>XH9jeFz_H+K(Y?c~KC_P9s8^*Zjw69#kmCL~t@EhF+qWi!t3#{2+u>goLRs~B0 zcBo(@r_-s_iFpGNQ~d#V9~b+aZMj^Q^;WPXTUN^DazcUwKwJPBE~%t#?hVSo8_9Do zu)PY>z#%lH+wID7Ko!{HMpk)j@PTL=x{tFUlSOj5T;z7UWv^jct(Fke>2$L9_zyl% zqtSey!y4OcwpR~gu^7eUae1QZQw9Fd)Tgif{rmy3Y6S^(i-+3)0000ioMFHRUKNC=gzVEq-=%O6Kdm0000Z9yPTN0P~;SQOar_p;e+B*ZEfi~2YciD)u7nM@=Y49aLUlIe7+_INy&;czJZeqRQIfpoiF ziAJMhF$Pn3JRV7IIKR9?liMXrIPN-{!GH|jDI{H6<@EH zd_Es}KA&>G-{t%L%H#3S7>%u3ttRjHTSubE^?Fq#fx^4p&Mpck@HCsvbe&u-_s0Rj z<#MSLz=Og0e6Bpe2Rt}=B8RtH0AUp1AfSXFY@(_BvKK99HSfCNGKGt ziB$5;hqF?tXpl(=8Z4K~+8G_Poj$t&=U`+4j09p+)cDEa5ju_V+Xc9DySVtJP8;NSqk9(d`24hL~#<3I$tt`klI- b@85hs;WUNR3=AZ+00000NkvXXu0mjf3x4JT literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..b16403740ca26a26aaead4b8859f31db0698f5d0 GIT binary patch literal 220 zcmV<203-j2P)0_sjPcbIvEU#()igP)q zM+*W$42Ab+h=Sn3iwL6FJ65dNd&7o`|Nk2K9?aq)JF}VO<-JVCE0s!CE|)Er%UL#? zwL+m__$rl(6^ljrG5na@yBLqp<#Ms>_3E$h_uFo_oBrK;I2>%d-P-ANvi*K9U$t5_ zFA|AZGMTjTcx^xlEfx#QWHOe|=S3Z6Sglr* zMEpohrBVWc4N`mtpcB;Z_iZ>Fs>*COv*~oIgwbeZtyW7Q$nY7U1IOd>uui9AgTX*a z%jHr=rS*F4gVgJF6+K{eu~H1D7Oe;<(0 zY&LDP*~n<9#}&DIr_1z!Bodr<3_k@LjfOv1VgQPpEaX6uV2pmSqMhcUIh{_6na_Zk zW{`Hfoh1?p%>uGuMg`8fYW5^BY%roIF?tKoM>`;&&qob)Z{z=+kc1J-Ke|ES9N?_7GXMYp M07*qoM6N<$f>B=j=l}o! literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..d2e2fdcf3d86c29959167137e194f4515a669fac GIT binary patch literal 150 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`v7RoDAr-gY_Iq<3FyL_6J7NEC zc|FBeO<~{fu_+2GR-EtL@w=mAqtf$^nLEFpeY2AF5u3AL07G~V!@d(6xE%g6y)s}+ zhz&L8cs83kuI23I!{4PA#QoaT7qf0%-BQlJ>rG|_->3QjEn@I=^>bP0l+XkK)ebq^ literal 0 HcmV?d00001 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; + } +} From a2f0140a81b4c62bffbdce471b0ad91cf31548d3 Mon Sep 17 00:00:00 2001 From: raoulvdberge Date: Fri, 29 Dec 2023 13:08:10 +0100 Subject: [PATCH 3/4] refactor: improve disk drive model baking in forge --- .../diskdrive/DiskDriveBakedModel.java | 214 ++++++++---------- .../diskdrive/DiskDriveItemBakedModel.java | 113 --------- .../diskdrive/DiskDriveUnbakedGeometry.java | 70 +----- .../portablegrid/PortableGridBakedModel.java | 31 +-- .../PortableGridUnbakedGeometry.java | 1 - .../forge/support/render/ItemBakedModel.java | 14 +- 6 files changed, 131 insertions(+), 312 deletions(-) delete mode 100644 refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/diskdrive/DiskDriveItemBakedModel.java 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 8816c67f4..9918af879 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 @@ -5,21 +5,23 @@ import com.refinedmods.refinedstorage2.platform.common.storage.diskdrive.AbstractDiskDriveBlockEntity; import com.refinedmods.refinedstorage2.platform.common.storage.diskdrive.DiskDriveBlock; import com.refinedmods.refinedstorage2.platform.common.support.direction.BiDirection; +import com.refinedmods.refinedstorage2.platform.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.Arrays; import java.util.Collections; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.function.BiFunction; -import java.util.function.Function; import javax.annotation.Nullable; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; +import com.mojang.math.Transformation; import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.block.model.BakedQuad; @@ -38,50 +40,46 @@ import org.joml.Vector3f; class DiskDriveBakedModel extends BakedModelWrapper { - private static final Vector3f[] TRANSLATORS = new Vector3f[8]; - - static { + private final LoadingCache> cache; + private final ItemOverrides itemOverrides = new DiskDriveItemOverrides(); + private final Vector3f[] diskTranslations = new Vector3f[8]; + + DiskDriveBakedModel(final BakedModel baseModel, + final RotationTranslationModelBaker baseModelBaker, + final DiskModelBaker diskModelBaker, + final RotationTranslationModelBaker ledInactiveModelBaker) { + super(baseModel); int i = 0; for (int y = 0; y < 4; ++y) { for (int x = 0; x < 2; ++x) { - TRANSLATORS[i++] = new Vector3f( - x == 0 ? -(2F / 16F) : -(9F / 16F), - -((y * 3F) / 16F) - (2F / 16F), - 0 - ); + this.diskTranslations[i++] = getDiskTranslation(x, y); } } - } - - private final BakedModel baseModel; - private final Function baseModelBakery; - private final Map> diskModelBakeries; - private final Map> diskItemModelBakeries; - private final Function ledInactiveModelBakery; - - private final ItemOverrides overrides = new DiskDriveItemOverrides(); - - private final LoadingCache> cache = CacheBuilder - .newBuilder() - .build(new DiskDriveCacheLoader()); - private final Map, DiskDriveItemBakedModel> itemCache = new HashMap<>(); - - DiskDriveBakedModel(final Function baseModelBakery, - final BakedModel baseModel, - final Map> diskModelBakeries, - final Map> diskItemModelBakeries, - final Function ledInactiveModelBakery) { - super(baseModel); - this.baseModel = baseModel; - this.baseModelBakery = baseModelBakery; - this.diskModelBakeries = diskModelBakeries; - this.diskItemModelBakeries = diskItemModelBakeries; - this.ledInactiveModelBakery = ledInactiveModelBakery; + this.cache = CacheBuilder.newBuilder().build(CacheLoader.from(cacheKey -> { + final Transformation rotation = TransformationBuilder.create().rotate(cacheKey.direction).build(); + final RandomSource rand = RandomSource.create(); + final List quads = new ArrayList<>( + baseModelBaker.bake(rotation).getQuads(null, cacheKey.side, rand) + ); + for (int j = 0; j < diskTranslations.length; ++j) { + final Disk disk = cacheKey.disks[j]; + quads.addAll(getDiskQuads(diskModelBaker, cacheKey, disk, j)); + if (cacheKey.withInactiveLed && disk.state() == StorageState.INACTIVE) { + final Transformation ledTransform = TransformationBuilder + .create() + .rotate(cacheKey.direction) + .translate(diskTranslations[j]) + .build(); + quads.addAll(ledInactiveModelBaker.bake(ledTransform).getQuads(null, cacheKey.side, rand)); + } + } + return quads; + })); } @Override public ItemOverrides getOverrides() { - return overrides; + return itemOverrides; } @Override @@ -101,17 +99,51 @@ public List getQuads(@Nullable final BlockState state, if (disks == null) { return super.getQuads(state, side, rand); } - final DiskDriveStateCacheKey cacheKey = new DiskDriveStateCacheKey( - state, - side, - disks, - rand, - direction + return cache.getUnchecked(new CacheKey(side, false, direction, disks)); + } + + private List getDiskQuads(final DiskModelBaker diskBakers, + final CacheKey cacheKey, + final Disk disk, + final int index) { + if (disk.state() == StorageState.NONE || disk.item() == null) { + return Collections.emptyList(); + } + final RotationTranslationModelBaker diskBaker = diskBakers.forDisk(disk.item()); + if (diskBaker == null) { + return Collections.emptyList(); + } + final Transformation diskTransform = TransformationBuilder.create() + .rotate(cacheKey.direction) + .translate(diskTranslations[index]) + .build(); + return diskBaker.bake(diskTransform).getQuads(null, cacheKey.side, RandomSource.create()); + } + + private static Vector3f getDiskTranslation(final int x, final int y) { + return new Vector3f( + x == 0 ? -(2F / 16F) : -(9F / 16F), + -((y * 3F) / 16F) - (2F / 16F), + 0 ); - return cache.getUnchecked(cacheKey); } private class DiskDriveItemOverrides extends ItemOverrides { + private final LoadingCache itemCache = CacheBuilder.newBuilder().build( + CacheLoader.from(cacheKey -> new ItemBakedModel( + originalModel, + cache.getUnchecked(cacheKey), + Map.of( + Direction.NORTH, cache.getUnchecked(cacheKey.withSide(Direction.NORTH)), + Direction.EAST, cache.getUnchecked(cacheKey.withSide(Direction.EAST)), + Direction.SOUTH, cache.getUnchecked(cacheKey.withSide(Direction.SOUTH)), + Direction.WEST, cache.getUnchecked(cacheKey.withSide(Direction.WEST)), + Direction.UP, cache.getUnchecked(cacheKey.withSide(Direction.UP)), + Direction.DOWN, cache.getUnchecked(cacheKey.withSide(Direction.DOWN)) + ) + )) + ); + @Nullable @Override public BakedModel resolve(final BakedModel bakedModel, @@ -121,41 +153,20 @@ public BakedModel resolve(final BakedModel bakedModel, final int seed) { final CompoundTag tag = BlockItem.getBlockEntityData(stack); if (tag == null) { - return baseModel.getOverrides().resolve(bakedModel, stack, level, entity, seed); + return originalModel.getOverrides().resolve(bakedModel, stack, level, entity, seed); } - final List disks = new ArrayList<>(); - for (int i = 0; i < TRANSLATORS.length; ++i) { - final Item disk = AbstractDiskDriveBlockEntity.getDisk(tag, i); - disks.add(disk); + final Disk[] disks = new Disk[8]; + for (int i = 0; i < diskTranslations.length; ++i) { + final Item diskItem = AbstractDiskDriveBlockEntity.getDisk(tag, i); + disks[i] = new Disk(diskItem, diskItem == null ? StorageState.NONE : StorageState.INACTIVE); } - return itemCache.computeIfAbsent(disks, key -> new DiskDriveItemBakedModel( - bakedModel, - diskItemModelBakeries, - ledInactiveModelBakery, - TRANSLATORS, - disks - )); + return itemCache.getUnchecked(new CacheKey(null, true, BiDirection.NORTH, disks)); } } - private static final class DiskDriveStateCacheKey { - private final BlockState state; - @Nullable - private final Direction side; - private final Disk[] disks; - private final RandomSource random; - private final BiDirection direction; - - DiskDriveStateCacheKey(final BlockState state, - @Nullable final Direction side, - final Disk[] disks, - final RandomSource random, - final BiDirection direction) { - this.state = state; - this.side = side; - this.disks = disks; - this.random = random; - this.direction = direction; + private record CacheKey(@Nullable Direction side, boolean withInactiveLed, BiDirection direction, Disk[] disks) { + CacheKey withSide(final Direction newSide) { + return new CacheKey(newSide, withInactiveLed, direction, disks); } @Override @@ -166,57 +177,26 @@ public boolean equals(final Object o) { if (o == null || getClass() != o.getClass()) { return false; } - final DiskDriveStateCacheKey that = (DiskDriveStateCacheKey) o; - return state.equals(that.state) && side == that.side && Arrays.equals(disks, that.disks); + final CacheKey cacheKey = (CacheKey) o; + return side == cacheKey.side && direction == cacheKey.direction && Arrays.equals(disks, cacheKey.disks) + && withInactiveLed == cacheKey.withInactiveLed; } @Override public int hashCode() { - int result = Objects.hash(state, side); + int result = Objects.hash(side, direction, withInactiveLed); result = 31 * result + Arrays.hashCode(disks); return result; } - } - private class DiskDriveCacheLoader extends CacheLoader> { @Override - public List 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 Disk disk = key.disks[i]; - quads.addAll(getDiskQuads(key, disk, i)); - } - return quads; - } - - @SuppressWarnings("deprecation") - private List getDiskQuads(final DiskDriveStateCacheKey key, - final Disk disk, - final int index) { - if (disk.state() == StorageState.NONE) { - return Collections.emptyList(); - } - final var diskModelBakery = diskModelBakeries.get(disk.item()); - if (diskModelBakery == null) { - return Collections.emptyList(); - } - return diskModelBakery.apply(key.direction, TRANSLATORS[index]).getQuads( - key.state, - key.side, - key.random - ); - } - - @SuppressWarnings("deprecation") - private List getBaseQuads(final BlockState state, - final RandomSource rand, - @Nullable final Direction side, - final BiDirection direction) { - return baseModelBakery.apply(direction).getQuads( - state, - side, - rand - ); + public String toString() { + return "CacheKey{" + + "side=" + side + + ", withInactiveLed=" + withInactiveLed + + ", direction=" + direction + + ", disks=" + Arrays.toString(disks) + + '}'; } } } diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/diskdrive/DiskDriveItemBakedModel.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/diskdrive/DiskDriveItemBakedModel.java deleted file mode 100644 index e4c106763..000000000 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/diskdrive/DiskDriveItemBakedModel.java +++ /dev/null @@ -1,113 +0,0 @@ -package com.refinedmods.refinedstorage2.platform.forge.storage.diskdrive; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.EnumMap; -import java.util.List; -import java.util.Map; -import java.util.function.Function; -import javax.annotation.Nonnull; -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.Item; -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; -import org.joml.Vector3f; - -class DiskDriveItemBakedModel extends BakedModelWrapper { - private final BakedModel baseModel; - private final Map> diskItemModelBakeries; - private final Function inactiveLedBakery; - private final Vector3f[] translators; - private final Map> cache = new EnumMap<>(Direction.class); - @Nullable - private List noSideCache; - private final List disks; - - DiskDriveItemBakedModel(final BakedModel baseModel, - final Map> diskItemModelBakeries, - final Function inactiveLedBakery, - final Vector3f[] translators, - final List disks) { - super(baseModel); - this.baseModel = baseModel; - this.diskItemModelBakeries = diskItemModelBakeries; - this.inactiveLedBakery = inactiveLedBakery; - this.translators = translators; - this.disks = disks; - } - - @Override - public ItemOverrides getOverrides() { - return ItemOverrides.EMPTY; - } - - @Override - @Nonnull - public List getQuads(@Nullable final BlockState state, - @Nullable final Direction side, - @Nonnull final RandomSource rand) { - if (side == null) { - if (noSideCache == null) { - noSideCache = createQuads(state, null, rand); - } - return noSideCache; - } - return cache.computeIfAbsent(side, key -> createQuads(state, side, rand)); - } - - @SuppressWarnings("deprecation") - private List createQuads(@Nullable final BlockState state, - @Nullable final Direction side, - final RandomSource rand) { - final List quads = new ArrayList<>(super.getQuads( - state, - side, - rand - )); - for (int i = 0; i < translators.length; ++i) { - final Item disk = disks.get(i); - final List diskQuads = getDiskQuads(state, side, rand, disk, i); - quads.addAll(diskQuads); - quads.addAll(inactiveLedBakery.apply(translators[i]).getQuads(state, side, rand)); - } - return quads; - } - - @SuppressWarnings("deprecation") - private List getDiskQuads(@Nullable final BlockState state, - @Nullable final Direction side, - final RandomSource rand, - @Nullable final Item diskItem, - final int i) { - if (diskItem == null) { - return Collections.emptyList(); - } - final Function diskModelBakery = diskItemModelBakeries.get(diskItem); - if (diskModelBakery == null) { - return Collections.emptyList(); - } - return diskModelBakery.apply(translators[i]).getQuads(state, side, rand); - } - - @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) { - baseModel.applyTransform(cameraTransformType, poseStack, applyLeftHandTransform); - return this; - } -} diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/diskdrive/DiskDriveUnbakedGeometry.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/diskdrive/DiskDriveUnbakedGeometry.java index b97915ade..481de4f96 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/diskdrive/DiskDriveUnbakedGeometry.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/diskdrive/DiskDriveUnbakedGeometry.java @@ -1,15 +1,11 @@ package com.refinedmods.refinedstorage2.platform.forge.storage.diskdrive; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; -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.RotationTranslationModelBaker; -import java.util.Map; -import java.util.Objects; -import java.util.function.BiFunction; import java.util.function.Function; -import java.util.stream.Collectors; -import com.mojang.math.Transformation; import net.minecraft.client.renderer.block.model.ItemOverrides; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.resources.model.BakedModel; @@ -18,12 +14,11 @@ import net.minecraft.client.resources.model.ModelState; import net.minecraft.client.resources.model.UnbakedModel; import net.minecraft.resources.ResourceLocation; -import net.minecraftforge.client.model.SimpleModelState; import net.minecraftforge.client.model.geometry.IGeometryBakingContext; import net.minecraftforge.client.model.geometry.IUnbakedGeometry; -import org.joml.Vector3f; import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createIdentifier; +import static java.util.Objects.requireNonNull; public class DiskDriveUnbakedGeometry implements IUnbakedGeometry { private static final ResourceLocation BASE_MODEL = createIdentifier("block/disk_drive/base"); @@ -49,62 +44,11 @@ public BakedModel bake(final IGeometryBakingContext context, final ModelState modelState, final ItemOverrides overrides, final ResourceLocation modelLocation) { - final var diskModelBakeries = PlatformApi.INSTANCE.getStorageContainerItemHelper() - .getDiskModelsByItem() - .entrySet() - .stream() - .collect(Collectors.toMap( - Map.Entry::getKey, - entry -> getDiskModelBakery(modelState, baker, spriteGetter, entry.getValue()) - )); - final var diskItemModelBakeries = PlatformApi.INSTANCE.getStorageContainerItemHelper() - .getDiskModelsByItem() - .entrySet() - .stream() - .collect(Collectors.toMap( - Map.Entry::getKey, - entry -> getItemModelBakery(modelState, baker, spriteGetter, entry.getValue()) - )); return new DiskDriveBakedModel( - getBaseModelBakery(modelState, baker, spriteGetter), - Objects.requireNonNull(baker.bake(BASE_MODEL, modelState, spriteGetter)), - diskModelBakeries, - diskItemModelBakeries, - getItemModelBakery(modelState, baker, spriteGetter, LED_INACTIVE_MODEL) + requireNonNull(baker.bake(BASE_MODEL, modelState, spriteGetter)), + new RotationTranslationModelBaker(modelState, baker, spriteGetter, BASE_MODEL), + new DiskModelBaker(modelState, baker, spriteGetter), + new RotationTranslationModelBaker(modelState, baker, spriteGetter, LED_INACTIVE_MODEL) ); } - - private Function getBaseModelBakery(final ModelState state, - final ModelBaker baker, - final Function sg) { - return direction -> { - final Transformation rotation = new Transformation(null, direction.getQuaternion(), null, null); - final ModelState wrappedState = new SimpleModelState(rotation, state.isUvLocked()); - return baker.bake(BASE_MODEL, wrappedState, sg); - }; - } - - private BiFunction getDiskModelBakery(final ModelState state, - final ModelBaker baker, - final Function - sg, - final ResourceLocation model) { - return (direction, trans) -> { - final Transformation translation = new Transformation(trans, null, null, null); - final Transformation rotation = new Transformation(null, direction.getQuaternion(), null, null); - final ModelState wrappedState = new SimpleModelState(rotation.compose(translation), state.isUvLocked()); - return baker.bake(model, wrappedState, sg); - }; - } - - private Function getItemModelBakery(final ModelState state, - final ModelBaker baker, - final Function sg, - final ResourceLocation model) { - return trans -> { - final Transformation translation = new Transformation(trans, null, null, null); - final ModelState wrappedState = new SimpleModelState(translation, state.isUvLocked()); - return baker.bake(model, wrappedState, sg); - }; - } } 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 index 7e87ec907..fa805b886 100644 --- 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 @@ -12,6 +12,7 @@ import com.refinedmods.refinedstorage2.platform.forge.support.render.TransformationBuilder; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import javax.annotation.Nullable; @@ -32,36 +33,34 @@ import net.minecraftforge.client.model.data.ModelData; import org.joml.Vector3f; -public class PortableGridBakedModel extends BakedModelWrapper { +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) { + 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))); + .rotate(cacheKey.direction) + .build()).getQuads(null, cacheKey.side(), RandomSource.create())); 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))); + .rotate(cacheKey.direction) + .translate(MOVE_TO_DISK_LOCATION) + .rotate(BiDirection.WEST) + .build()).getQuads(null, cacheKey.side(), RandomSource.create())); } return quads; })); @@ -94,7 +93,11 @@ public ItemOverrides getOverrides() { private class PortableGridItemOverrides extends ItemOverrides { private final LoadingCache itemCache = CacheBuilder.newBuilder().build( - CacheLoader.from(cacheKey -> new ItemBakedModel(originalModel, cache.getUnchecked(cacheKey))) + CacheLoader.from(cacheKey -> new ItemBakedModel( + originalModel, + cache.getUnchecked(cacheKey), + Collections.emptyMap() + )) ); @Override 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 index ad9581f4f..c031be700 100644 --- 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 @@ -20,7 +20,6 @@ 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"); 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 index 75d2fae71..8ea0e223f 100644 --- 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 @@ -1,6 +1,8 @@ package com.refinedmods.refinedstorage2.platform.forge.support.render; +import java.util.Collections; import java.util.List; +import java.util.Map; import javax.annotation.Nullable; import com.mojang.blaze3d.vertex.PoseStack; @@ -15,18 +17,22 @@ import net.minecraftforge.client.model.BakedModelWrapper; public class ItemBakedModel extends BakedModelWrapper { - private final List quads; + private final List unculledFaces; + private final Map> faces; - public ItemBakedModel(final BakedModel originalModel, final List quads) { + public ItemBakedModel(final BakedModel originalModel, + final List unculledFaces, + final Map> faces) { super(originalModel); - this.quads = quads; + this.unculledFaces = unculledFaces; + this.faces = faces; } @Override public List getQuads(@Nullable final BlockState state, @Nullable final Direction side, final RandomSource rand) { - return quads; + return side == null ? unculledFaces : faces.getOrDefault(side, Collections.emptyList()); } @Override From 6ea0f4322a4db092c913da0b580ed850ddfd9a69 Mon Sep 17 00:00:00 2001 From: raoulvdberge Date: Fri, 29 Dec 2023 13:35:17 +0100 Subject: [PATCH 4/4] chore: add loot item function for portable grid --- .../common/AbstractModInitializer.java | 13 +++++++---- .../common/content/BlockEntities.java | 2 +- .../platform/common/content/Blocks.java | 2 +- .../common/content/LootFunctions.java | 17 +++++++++++--- .../common/portablegrid/PortableGridType.java | 6 ----- .../AbstractPortableGridBlockEntity.java | 2 +- ...stractPortableGridBlockEntityRenderer.java | 2 +- .../portablegrid/PortableGridBlock.java | 2 +- .../portablegrid/PortableGridItem.java | 2 +- .../PortableGridLootItemFunction.java | 21 ++++++++++++++++++ ...ortableGridLootItemFunctionSerializer.java | 22 +++++++++++++++++++ .../portablegrid/PortableGridType.java | 6 +++++ .../portablegrid/package-info.java | 2 +- .../platform/fabric/ModInitializerImpl.java | 2 +- .../FabricPortableGridBlockEntity.java | 4 ++-- .../portablegrid/PortableGridBakedModel.java | 4 ++-- .../PortableGridBlockEntityRendererImpl.java | 4 ++-- .../platform/forge/ModInitializer.java | 2 +- .../ForgePortableGridBlockEntity.java | 4 ++-- .../portablegrid/PortableGridBakedModel.java | 2 +- .../PortableGridBlockEntityRendererImpl.java | 4 ++-- .../forge/support/render/DiskModelBaker.java | 1 - 22 files changed, 92 insertions(+), 34 deletions(-) delete mode 100644 refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/portablegrid/PortableGridType.java rename refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/{ => storage}/portablegrid/AbstractPortableGridBlockEntity.java (95%) rename refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/{ => storage}/portablegrid/AbstractPortableGridBlockEntityRenderer.java (96%) rename refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/{ => storage}/portablegrid/PortableGridBlock.java (97%) rename refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/{ => storage}/portablegrid/PortableGridItem.java (78%) create mode 100644 refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/portablegrid/PortableGridLootItemFunction.java create mode 100644 refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/portablegrid/PortableGridLootItemFunctionSerializer.java create mode 100644 refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/portablegrid/PortableGridType.java rename refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/{ => storage}/portablegrid/package-info.java (72%) 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 9dcb50317..77038c01e 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,10 +55,6 @@ 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; @@ -68,6 +64,11 @@ import com.refinedmods.refinedstorage2.platform.common.storage.diskdrive.DiskDriveContainerMenu; import com.refinedmods.refinedstorage2.platform.common.storage.externalstorage.ExternalStorageBlockEntity; import com.refinedmods.refinedstorage2.platform.common.storage.externalstorage.ExternalStorageContainerMenu; +import com.refinedmods.refinedstorage2.platform.common.storage.portablegrid.AbstractPortableGridBlockEntity; +import com.refinedmods.refinedstorage2.platform.common.storage.portablegrid.PortableGridBlock; +import com.refinedmods.refinedstorage2.platform.common.storage.portablegrid.PortableGridItem; +import com.refinedmods.refinedstorage2.platform.common.storage.portablegrid.PortableGridLootItemFunctionSerializer; +import com.refinedmods.refinedstorage2.platform.common.storage.portablegrid.PortableGridType; import com.refinedmods.refinedstorage2.platform.common.storage.storageblock.FluidStorageBlock; import com.refinedmods.refinedstorage2.platform.common.storage.storageblock.FluidStorageBlockBlockEntity; import com.refinedmods.refinedstorage2.platform.common.storage.storageblock.FluidStorageBlockBlockItem; @@ -710,6 +711,10 @@ protected final void registerLootFunctions(final RegistryCallback new LootItemFunctionType(new StorageBlockLootItemFunctionSerializer()) )); + LootFunctions.INSTANCE.setPortableGrid(callback.register( + PORTABLE_GRID, + () -> new LootItemFunctionType(new PortableGridLootItemFunctionSerializer()) + )); LootFunctions.INSTANCE.setEnergy(callback.register( createIdentifier("energy"), () -> new LootItemFunctionType(new EnergyLootItemFunctionSerializer()) 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 4730b18fe..b635e6cd6 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,11 +12,11 @@ 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; import com.refinedmods.refinedstorage2.platform.common.storage.externalstorage.ExternalStorageBlockEntity; +import com.refinedmods.refinedstorage2.platform.common.storage.portablegrid.AbstractPortableGridBlockEntity; import com.refinedmods.refinedstorage2.platform.common.storage.storageblock.FluidStorageBlockBlockEntity; import com.refinedmods.refinedstorage2.platform.common.storage.storageblock.ItemStorageBlockBlockEntity; import com.refinedmods.refinedstorage2.platform.common.storagemonitor.StorageMonitorBlockEntity; 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 dc0951d89..b7bac5c9b 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,11 +14,11 @@ 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; import com.refinedmods.refinedstorage2.platform.common.storage.externalstorage.ExternalStorageBlock; +import com.refinedmods.refinedstorage2.platform.common.storage.portablegrid.PortableGridBlock; import com.refinedmods.refinedstorage2.platform.common.storage.storageblock.FluidStorageBlock; import com.refinedmods.refinedstorage2.platform.common.storage.storageblock.ItemStorageBlock; import com.refinedmods.refinedstorage2.platform.common.storagemonitor.StorageMonitorBlock; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/LootFunctions.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/LootFunctions.java index c89eedec0..a033282ea 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/LootFunctions.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/LootFunctions.java @@ -1,11 +1,12 @@ package com.refinedmods.refinedstorage2.platform.common.content; -import java.util.Objects; import java.util.function.Supplier; import javax.annotation.Nullable; import net.minecraft.world.level.storage.loot.functions.LootItemFunctionType; +import static java.util.Objects.requireNonNull; + public final class LootFunctions { public static final LootFunctions INSTANCE = new LootFunctions(); @@ -13,12 +14,14 @@ public final class LootFunctions { private Supplier storageBlock; @Nullable private Supplier energy; + @Nullable + private Supplier portableGrid; private LootFunctions() { } public LootItemFunctionType getStorageBlock() { - return Objects.requireNonNull(storageBlock).get(); + return requireNonNull(storageBlock).get(); } public void setStorageBlock(final Supplier supplier) { @@ -26,10 +29,18 @@ public void setStorageBlock(final Supplier supplier) { } public LootItemFunctionType getEnergy() { - return Objects.requireNonNull(energy).get(); + return requireNonNull(energy).get(); } public void setEnergy(final Supplier supplier) { this.energy = supplier; } + + public LootItemFunctionType getPortableGrid() { + return requireNonNull(portableGrid).get(); + } + + public void setPortableGrid(final Supplier portableGrid) { + this.portableGrid = portableGrid; + } } 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 deleted file mode 100644 index 93cd284d4..000000000 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/portablegrid/PortableGridType.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.refinedmods.refinedstorage2.platform.common.portablegrid; - -public enum PortableGridType { - NORMAL, - CREATIVE -} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/portablegrid/AbstractPortableGridBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/portablegrid/AbstractPortableGridBlockEntity.java similarity index 95% rename from refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/portablegrid/AbstractPortableGridBlockEntity.java rename to refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/portablegrid/AbstractPortableGridBlockEntity.java index 55bdd2dda..53164b721 100644 --- 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/storage/portablegrid/AbstractPortableGridBlockEntity.java @@ -1,4 +1,4 @@ -package com.refinedmods.refinedstorage2.platform.common.portablegrid; +package com.refinedmods.refinedstorage2.platform.common.storage.portablegrid; import com.refinedmods.refinedstorage2.api.network.impl.node.StorageState; import com.refinedmods.refinedstorage2.platform.common.content.BlockEntities; 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/storage/portablegrid/AbstractPortableGridBlockEntityRenderer.java similarity index 96% rename from refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/portablegrid/AbstractPortableGridBlockEntityRenderer.java rename to refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/portablegrid/AbstractPortableGridBlockEntityRenderer.java index 1cbc7f811..d3b4497c6 100644 --- 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/storage/portablegrid/AbstractPortableGridBlockEntityRenderer.java @@ -1,4 +1,4 @@ -package com.refinedmods.refinedstorage2.platform.common.portablegrid; +package com.refinedmods.refinedstorage2.platform.common.storage.portablegrid; import com.refinedmods.refinedstorage2.platform.common.storage.Disk; import com.refinedmods.refinedstorage2.platform.common.support.direction.BiDirection; 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/storage/portablegrid/PortableGridBlock.java similarity index 97% rename from refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/portablegrid/PortableGridBlock.java rename to refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/portablegrid/PortableGridBlock.java index a5c927d9f..55526d16b 100644 --- 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/storage/portablegrid/PortableGridBlock.java @@ -1,4 +1,4 @@ -package com.refinedmods.refinedstorage2.platform.common.portablegrid; +package com.refinedmods.refinedstorage2.platform.common.storage.portablegrid; import com.refinedmods.refinedstorage2.platform.common.content.BlockConstants; import com.refinedmods.refinedstorage2.platform.common.support.AbstractDirectionalBlock; 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/storage/portablegrid/PortableGridItem.java similarity index 78% rename from refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/portablegrid/PortableGridItem.java rename to refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/portablegrid/PortableGridItem.java index 84324e9d7..fa69b1a7a 100644 --- 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/storage/portablegrid/PortableGridItem.java @@ -1,4 +1,4 @@ -package com.refinedmods.refinedstorage2.platform.common.portablegrid; +package com.refinedmods.refinedstorage2.platform.common.storage.portablegrid; import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.Item; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/portablegrid/PortableGridLootItemFunction.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/portablegrid/PortableGridLootItemFunction.java new file mode 100644 index 000000000..0eeaca775 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/portablegrid/PortableGridLootItemFunction.java @@ -0,0 +1,21 @@ +package com.refinedmods.refinedstorage2.platform.common.storage.portablegrid; + +import com.refinedmods.refinedstorage2.platform.common.content.LootFunctions; + +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.storage.loot.LootContext; +import net.minecraft.world.level.storage.loot.functions.LootItemFunction; +import net.minecraft.world.level.storage.loot.functions.LootItemFunctionType; + +class PortableGridLootItemFunction implements LootItemFunction { + @Override + public LootItemFunctionType getType() { + return LootFunctions.INSTANCE.getPortableGrid(); + } + + @Override + public ItemStack apply(final ItemStack itemStack, final LootContext lootContext) { + // todo ! + return itemStack; + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/portablegrid/PortableGridLootItemFunctionSerializer.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/portablegrid/PortableGridLootItemFunctionSerializer.java new file mode 100644 index 000000000..19e1c12cf --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/portablegrid/PortableGridLootItemFunctionSerializer.java @@ -0,0 +1,22 @@ +package com.refinedmods.refinedstorage2.platform.common.storage.portablegrid; + +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonObject; +import com.google.gson.JsonSerializationContext; +import net.minecraft.world.level.storage.loot.Serializer; +import net.minecraft.world.level.storage.loot.functions.LootItemFunction; + +public class PortableGridLootItemFunctionSerializer implements Serializer { + @Override + public void serialize(final JsonObject jsonObject, + final LootItemFunction lootItemFunction, + final JsonSerializationContext jsonSerializationContext) { + // no op + } + + @Override + public LootItemFunction deserialize(final JsonObject jsonObject, + final JsonDeserializationContext jsonDeserializationContext) { + return new PortableGridLootItemFunction(); + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/portablegrid/PortableGridType.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/portablegrid/PortableGridType.java new file mode 100644 index 000000000..89bf1fecd --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/portablegrid/PortableGridType.java @@ -0,0 +1,6 @@ +package com.refinedmods.refinedstorage2.platform.common.storage.portablegrid; + +public enum PortableGridType { + NORMAL, + CREATIVE +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/portablegrid/package-info.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/portablegrid/package-info.java similarity index 72% rename from refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/portablegrid/package-info.java rename to refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/portablegrid/package-info.java index cc5747491..531db12cd 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/portablegrid/package-info.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/portablegrid/package-info.java @@ -1,6 +1,6 @@ @ParametersAreNonnullByDefault @FieldsAndMethodsAreNonnullByDefault -package com.refinedmods.refinedstorage2.platform.common.portablegrid; +package com.refinedmods.refinedstorage2.platform.common.storage.portablegrid; import com.refinedmods.refinedstorage2.api.core.FieldsAndMethodsAreNonnullByDefault; 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 052fbd26f..3f30879be 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,9 +16,9 @@ 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.storage.portablegrid.PortableGridType; import com.refinedmods.refinedstorage2.platform.common.support.AbstractBaseBlock; import com.refinedmods.refinedstorage2.platform.common.upgrade.RegulatorUpgradeItem; import com.refinedmods.refinedstorage2.platform.common.util.ServerEventQueue; 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 index e9b0f2ed1..07e40a0d0 100644 --- 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 @@ -1,7 +1,7 @@ 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 com.refinedmods.refinedstorage2.platform.common.storage.portablegrid.AbstractPortableGridBlockEntity; +import com.refinedmods.refinedstorage2.platform.common.storage.portablegrid.PortableGridType; import javax.annotation.Nullable; 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 index 90e7f0626..181d856a8 100644 --- 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 @@ -1,8 +1,8 @@ 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.storage.portablegrid.PortableGridBlock; 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; @@ -22,7 +22,7 @@ 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; 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 index c6a9c6402..9fb9e6bad 100644 --- 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 @@ -1,8 +1,8 @@ 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.common.storage.portablegrid.AbstractPortableGridBlockEntity; +import com.refinedmods.refinedstorage2.platform.common.storage.portablegrid.AbstractPortableGridBlockEntityRenderer; import com.refinedmods.refinedstorage2.platform.fabric.support.render.RenderTypes; import javax.annotation.Nullable; 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 11890e63f..e89360b73 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,8 +15,8 @@ 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.storage.portablegrid.PortableGridType; import com.refinedmods.refinedstorage2.platform.common.support.AbstractBaseBlock; import com.refinedmods.refinedstorage2.platform.common.upgrade.RegulatorUpgradeItem; import com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil; 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 index 41911a271..d0033bb30 100644 --- 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 @@ -1,8 +1,8 @@ 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 com.refinedmods.refinedstorage2.platform.common.storage.portablegrid.AbstractPortableGridBlockEntity; +import com.refinedmods.refinedstorage2.platform.common.storage.portablegrid.PortableGridType; import javax.annotation.Nonnull; 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 index fa805b886..e307c8db3 100644 --- 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 @@ -2,9 +2,9 @@ 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.storage.portablegrid.PortableGridBlock; 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; 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 index 34b14e57b..d4ba2585f 100644 --- 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 @@ -1,8 +1,8 @@ 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.common.storage.portablegrid.AbstractPortableGridBlockEntity; +import com.refinedmods.refinedstorage2.platform.common.storage.portablegrid.AbstractPortableGridBlockEntityRenderer; import com.refinedmods.refinedstorage2.platform.forge.support.render.RenderTypes; import javax.annotation.Nullable; 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 index 403e18d52..8bbaf11e5 100644 --- 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 @@ -13,7 +13,6 @@ 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;