From 6318fdece01d38cb9032d402fdc37e9e9022921f Mon Sep 17 00:00:00 2001 From: Adrien1106 Date: Tue, 16 Apr 2024 00:10:53 +0200 Subject: [PATCH 1/3] improved caching to use less per-model space and changed cache class for retextured elements --- .../java/fr/adrien1106/reframed/ReFramed.java | 2 +- .../reframed/block/ReFramedBlock.java | 7 - .../block/ReFramedHalfStairBlock.java | 5 - .../block/ReFramedHalfStairsSlabBlock.java | 5 - .../block/ReFramedHalfStairsStairBlock.java | 5 - .../reframed/block/ReFramedLayerBlock.java | 5 - .../reframed/block/ReFramedPillarBlock.java | 5 - .../reframed/block/ReFramedSlabBlock.java | 5 - .../block/ReFramedSlabsCubeBlock.java | 5 - .../block/ReFramedSmallCubeBlock.java | 5 - .../block/ReFramedSmallCubesStepBlock.java | 5 - .../reframed/block/ReFramedStairBlock.java | 5 - .../block/ReFramedStairsCubeBlock.java | 5 - .../reframed/block/ReFramedStepBlock.java | 5 - .../block/ReFramedStepsSlabBlock.java | 5 - .../reframed/block/ReframedWallBlock.java | 5 - .../reframed/client/ReFramedClient.java | 134 +++++++++--------- .../reframed/client/ReFramedClientHelper.java | 16 ++- .../client/model/RetexturingBakedModel.java | 36 ++--- .../model/UnbakedAutoRetexturedModel.java | 8 +- .../model/UnbakedJsonRetexturedModel.java | 8 +- .../client/model/UnbakedRetexturedModel.java | 7 +- .../client/model/apperance/Appearance.java | 2 +- .../model/apperance/CamoAppearance.java | 7 +- .../apperance/CamoAppearanceManager.java | 8 +- .../model/apperance/ComputedAppearance.java | 7 +- .../apperance/SingleSpriteAppearance.java | 6 + .../apperance/WeightedComputedAppearance.java | 6 + .../reframed/client/util/RenderHelper.java | 1 - 29 files changed, 141 insertions(+), 184 deletions(-) diff --git a/src/main/java/fr/adrien1106/reframed/ReFramed.java b/src/main/java/fr/adrien1106/reframed/ReFramed.java index 05d6fc3..f0aff35 100644 --- a/src/main/java/fr/adrien1106/reframed/ReFramed.java +++ b/src/main/java/fr/adrien1106/reframed/ReFramed.java @@ -32,7 +32,7 @@ import static fr.adrien1106.reframed.util.blocks.BlockProperties.LIGHT; * TODO add minecraft models like wall fence etc -> for v1.6 * TODO better connected textures -> maybe v1.6 ? * TODO support continuity overlays -> not scheduled - * TODO better state caching per models (e.g. wall only has 3 max per model) -> not scheduled + * TODO fence remove collision if popped chorus -> asap */ public class ReFramed implements ModInitializer { public static final String MODID = "reframed"; diff --git a/src/main/java/fr/adrien1106/reframed/block/ReFramedBlock.java b/src/main/java/fr/adrien1106/reframed/block/ReFramedBlock.java index 272b930..ba53c06 100644 --- a/src/main/java/fr/adrien1106/reframed/block/ReFramedBlock.java +++ b/src/main/java/fr/adrien1106/reframed/block/ReFramedBlock.java @@ -52,13 +52,6 @@ public class ReFramedBlock extends Block implements BlockEntityProvider { public Object getModelCacheKey(BlockState state) { return ""; } - - /** - * @return the amount of models the block can have prevents allocating too much space for a model - */ - public int getModelStateCount() { - return 1; - } //For addon devs: override this so your blocks don't end up trying to place my block entity, my BlockEntityType only handles blocks internal to the mod //Just make your own BlockEntityType, it's fine, you can even use the same ReFramedEntity class diff --git a/src/main/java/fr/adrien1106/reframed/block/ReFramedHalfStairBlock.java b/src/main/java/fr/adrien1106/reframed/block/ReFramedHalfStairBlock.java index f5b36e2..4f23964 100644 --- a/src/main/java/fr/adrien1106/reframed/block/ReFramedHalfStairBlock.java +++ b/src/main/java/fr/adrien1106/reframed/block/ReFramedHalfStairBlock.java @@ -41,11 +41,6 @@ public class ReFramedHalfStairBlock extends WaterloggableReFramedBlock { return new ModelCacheKey(state.get(CORNER), state.get(CORNER_FACE)); } - @Override - public int getModelStateCount() { - return 24; - } - @Override protected void appendProperties(StateManager.Builder builder) { super.appendProperties(builder.add(CORNER,CORNER_FACE)); diff --git a/src/main/java/fr/adrien1106/reframed/block/ReFramedHalfStairsSlabBlock.java b/src/main/java/fr/adrien1106/reframed/block/ReFramedHalfStairsSlabBlock.java index 934a8bf..85c99b5 100644 --- a/src/main/java/fr/adrien1106/reframed/block/ReFramedHalfStairsSlabBlock.java +++ b/src/main/java/fr/adrien1106/reframed/block/ReFramedHalfStairsSlabBlock.java @@ -34,11 +34,6 @@ public class ReFramedHalfStairsSlabBlock extends WaterloggableReFramedDoubleBloc return new ModelCacheKey(state.get(CORNER), state.get(CORNER_FACE)); } - @Override - public int getModelStateCount() { - return 24; - } - @Override protected void appendProperties(StateManager.Builder builder) { super.appendProperties(builder.add(CORNER,CORNER_FACE)); diff --git a/src/main/java/fr/adrien1106/reframed/block/ReFramedHalfStairsStairBlock.java b/src/main/java/fr/adrien1106/reframed/block/ReFramedHalfStairsStairBlock.java index 6da0e5d..e4eb07f 100644 --- a/src/main/java/fr/adrien1106/reframed/block/ReFramedHalfStairsStairBlock.java +++ b/src/main/java/fr/adrien1106/reframed/block/ReFramedHalfStairsStairBlock.java @@ -32,11 +32,6 @@ public class ReFramedHalfStairsStairBlock extends WaterloggableReFramedDoubleBlo return state.get(EDGE); } - @Override - public int getModelStateCount() { - return 12; - } - @Override protected void appendProperties(StateManager.Builder builder) { super.appendProperties(builder.add(EDGE)); diff --git a/src/main/java/fr/adrien1106/reframed/block/ReFramedLayerBlock.java b/src/main/java/fr/adrien1106/reframed/block/ReFramedLayerBlock.java index e2ee0d9..832183b 100644 --- a/src/main/java/fr/adrien1106/reframed/block/ReFramedLayerBlock.java +++ b/src/main/java/fr/adrien1106/reframed/block/ReFramedLayerBlock.java @@ -32,11 +32,6 @@ public class ReFramedLayerBlock extends ReFramedSlabBlock { return new ModelCacheKey(state.get(FACING), state.get(LAYERS)); } - @Override - public int getModelStateCount() { - return 48; - } - @Override protected void appendProperties(StateManager.Builder builder) { super.appendProperties(builder.add(LAYERS)); diff --git a/src/main/java/fr/adrien1106/reframed/block/ReFramedPillarBlock.java b/src/main/java/fr/adrien1106/reframed/block/ReFramedPillarBlock.java index 4bf272d..6e73175 100644 --- a/src/main/java/fr/adrien1106/reframed/block/ReFramedPillarBlock.java +++ b/src/main/java/fr/adrien1106/reframed/block/ReFramedPillarBlock.java @@ -31,11 +31,6 @@ public class ReFramedPillarBlock extends WaterloggableReFramedBlock { return state.get(AXIS); } - @Override - public int getModelStateCount() { - return 3; - } - @Override protected void appendProperties(StateManager.Builder builder) { super.appendProperties(builder.add(AXIS)); diff --git a/src/main/java/fr/adrien1106/reframed/block/ReFramedSlabBlock.java b/src/main/java/fr/adrien1106/reframed/block/ReFramedSlabBlock.java index c3d9970..3da8b48 100644 --- a/src/main/java/fr/adrien1106/reframed/block/ReFramedSlabBlock.java +++ b/src/main/java/fr/adrien1106/reframed/block/ReFramedSlabBlock.java @@ -37,11 +37,6 @@ public class ReFramedSlabBlock extends WaterloggableReFramedBlock { public Object getModelCacheKey(BlockState state) { return state.get(FACING); } - - @Override - public int getModelStateCount() { - return 6; - } @Override protected void appendProperties(StateManager.Builder builder) { diff --git a/src/main/java/fr/adrien1106/reframed/block/ReFramedSlabsCubeBlock.java b/src/main/java/fr/adrien1106/reframed/block/ReFramedSlabsCubeBlock.java index 380c1ad..e148ace 100644 --- a/src/main/java/fr/adrien1106/reframed/block/ReFramedSlabsCubeBlock.java +++ b/src/main/java/fr/adrien1106/reframed/block/ReFramedSlabsCubeBlock.java @@ -23,11 +23,6 @@ public class ReFramedSlabsCubeBlock extends ReFramedDoubleBlock { return state.get(AXIS); } - @Override - public int getModelStateCount() { - return 3; - } - @Override protected void appendProperties(StateManager.Builder builder) { super.appendProperties(builder.add(AXIS)); diff --git a/src/main/java/fr/adrien1106/reframed/block/ReFramedSmallCubeBlock.java b/src/main/java/fr/adrien1106/reframed/block/ReFramedSmallCubeBlock.java index 83ed280..892d2c7 100644 --- a/src/main/java/fr/adrien1106/reframed/block/ReFramedSmallCubeBlock.java +++ b/src/main/java/fr/adrien1106/reframed/block/ReFramedSmallCubeBlock.java @@ -39,11 +39,6 @@ public class ReFramedSmallCubeBlock extends WaterloggableReFramedBlock { return state.get(CORNER); } - @Override - public int getModelStateCount() { - return 8; - } - @Override protected void appendProperties(StateManager.Builder builder) { super.appendProperties(builder.add(CORNER)); diff --git a/src/main/java/fr/adrien1106/reframed/block/ReFramedSmallCubesStepBlock.java b/src/main/java/fr/adrien1106/reframed/block/ReFramedSmallCubesStepBlock.java index 4a6f153..76442e0 100644 --- a/src/main/java/fr/adrien1106/reframed/block/ReFramedSmallCubesStepBlock.java +++ b/src/main/java/fr/adrien1106/reframed/block/ReFramedSmallCubesStepBlock.java @@ -30,11 +30,6 @@ public class ReFramedSmallCubesStepBlock extends WaterloggableReFramedDoubleBloc return state.get(EDGE); } - @Override - public int getModelStateCount() { - return 12; - } - @Override protected void appendProperties(StateManager.Builder builder) { super.appendProperties(builder.add(EDGE)); diff --git a/src/main/java/fr/adrien1106/reframed/block/ReFramedStairBlock.java b/src/main/java/fr/adrien1106/reframed/block/ReFramedStairBlock.java index 3156f8e..0340543 100644 --- a/src/main/java/fr/adrien1106/reframed/block/ReFramedStairBlock.java +++ b/src/main/java/fr/adrien1106/reframed/block/ReFramedStairBlock.java @@ -42,11 +42,6 @@ public class ReFramedStairBlock extends WaterloggableReFramedBlock { public Object getModelCacheKey(BlockState state) { return new ModelCacheKey(state.get(EDGE), state.get(STAIR_SHAPE)); } - - @Override - public int getModelStateCount() { - return 108; // Has 12 * 9 state combination and 52 models still reduces cache size - } @Override protected void appendProperties(StateManager.Builder builder) { diff --git a/src/main/java/fr/adrien1106/reframed/block/ReFramedStairsCubeBlock.java b/src/main/java/fr/adrien1106/reframed/block/ReFramedStairsCubeBlock.java index 9267a39..4605087 100644 --- a/src/main/java/fr/adrien1106/reframed/block/ReFramedStairsCubeBlock.java +++ b/src/main/java/fr/adrien1106/reframed/block/ReFramedStairsCubeBlock.java @@ -34,11 +34,6 @@ public class ReFramedStairsCubeBlock extends ReFramedDoubleBlock { return new ModelCacheKey(state.get(EDGE), state.get(STAIR_SHAPE)); } - @Override - public int getModelStateCount() { - return 108; // Has 12 * 9 state combination and 52 models still reduces cache size - } - @Override protected void appendProperties(StateManager.Builder builder) { super.appendProperties(builder.add(EDGE, STAIR_SHAPE)); diff --git a/src/main/java/fr/adrien1106/reframed/block/ReFramedStepBlock.java b/src/main/java/fr/adrien1106/reframed/block/ReFramedStepBlock.java index f2d3ff1..d706124 100644 --- a/src/main/java/fr/adrien1106/reframed/block/ReFramedStepBlock.java +++ b/src/main/java/fr/adrien1106/reframed/block/ReFramedStepBlock.java @@ -39,11 +39,6 @@ public class ReFramedStepBlock extends WaterloggableReFramedBlock { return state.get(EDGE); } - @Override - public int getModelStateCount() { - return 12; - } - @Override protected void appendProperties(StateManager.Builder builder) { super.appendProperties(builder.add(EDGE)); diff --git a/src/main/java/fr/adrien1106/reframed/block/ReFramedStepsSlabBlock.java b/src/main/java/fr/adrien1106/reframed/block/ReFramedStepsSlabBlock.java index a23a987..6cfe71a 100644 --- a/src/main/java/fr/adrien1106/reframed/block/ReFramedStepsSlabBlock.java +++ b/src/main/java/fr/adrien1106/reframed/block/ReFramedStepsSlabBlock.java @@ -34,11 +34,6 @@ public class ReFramedStepsSlabBlock extends WaterloggableReFramedDoubleBlock { return new ModelCacheKey(state.get(FACING), state.get(AXIS)); } - @Override - public int getModelStateCount() { - return 18; - } - @Override protected void appendProperties(StateManager.Builder builder) { super.appendProperties(builder.add(FACING, AXIS)); diff --git a/src/main/java/fr/adrien1106/reframed/block/ReframedWallBlock.java b/src/main/java/fr/adrien1106/reframed/block/ReframedWallBlock.java index 561dbd3..5b54a0a 100644 --- a/src/main/java/fr/adrien1106/reframed/block/ReframedWallBlock.java +++ b/src/main/java/fr/adrien1106/reframed/block/ReframedWallBlock.java @@ -49,11 +49,6 @@ public class ReframedWallBlock extends WaterloggableReFramedBlock { ); } - @Override - public int getModelStateCount() { - return 162; - } - @Override protected void appendProperties(StateManager.Builder builder) { super.appendProperties(builder.add(UP, EAST_WALL_SHAPE, NORTH_WALL_SHAPE, SOUTH_WALL_SHAPE, WEST_WALL_SHAPE)); diff --git a/src/main/java/fr/adrien1106/reframed/client/ReFramedClient.java b/src/main/java/fr/adrien1106/reframed/client/ReFramedClient.java index c9bfc01..3ea82e9 100644 --- a/src/main/java/fr/adrien1106/reframed/client/ReFramedClient.java +++ b/src/main/java/fr/adrien1106/reframed/client/ReFramedClient.java @@ -14,6 +14,10 @@ import net.minecraft.resource.ResourceType; import net.minecraft.util.Identifier; import net.minecraft.util.math.ChunkSectionPos; +import static fr.adrien1106.reframed.util.blocks.BlockProperties.*; +import static fr.adrien1106.reframed.util.blocks.BlockProperties.STAIR_SHAPE; +import static net.minecraft.state.property.Properties.*; + public class ReFramedClient implements ClientModInitializer { public static final ReFramedModelProvider PROVIDER = new ReFramedModelProvider(); @@ -27,92 +31,92 @@ public class ReFramedClient implements ClientModInitializer { BlockRenderLayerMap.INSTANCE.putBlocks(RenderLayer.getCutout(), ReFramed.BLOCKS.toArray(new Block[0])); // CUBE - HELPER.addReFramedModel("cube" , HELPER.auto(new Identifier("block/cube"))); + HELPER.addReFramedModel("cube" , HELPER.auto(new Identifier("block/cube"), 2)); // SMALL_CUBE - HELPER.addReFramedModel("small_cube" , HELPER.auto(ReFramed.id("block/small_cube/base"))); + HELPER.addReFramedModel("small_cube" , HELPER.auto(ReFramed.id("block/small_cube/base"), 9, CORNER)); // SMALL_CUBES_STEP - HELPER.addReFramedModel("small_cubes_step" , HELPER.autoDouble(ReFramed.id("block/small_cube/base"), ReFramed.id("block/small_cube/step/base"))); - HELPER.addReFramedModel("small_cubes_step_reverse" , HELPER.autoDouble(ReFramed.id("block/small_cube/step/base"), ReFramed.id("block/small_cube/base"))); + HELPER.addReFramedModel("small_cubes_step" , HELPER.autoDouble(ReFramed.id("block/small_cube/base"), ReFramed.id("block/small_cube/step/base"), 9, EDGE)); + HELPER.addReFramedModel("small_cubes_step_reverse" , HELPER.autoDouble(ReFramed.id("block/small_cube/step/base"), ReFramed.id("block/small_cube/base"), 4, EDGE)); // SLAB - HELPER.addReFramedModel("slab" , HELPER.auto(new Identifier("block/slab"))); + HELPER.addReFramedModel("slab" , HELPER.auto(new Identifier("block/slab"), 7, FACING)); // SLAB_CUBE - HELPER.addReFramedModel("double_slab" , HELPER.autoDouble(new Identifier("block/slab"), new Identifier("block/slab_top"))); + HELPER.addReFramedModel("double_slab" , HELPER.autoDouble(new Identifier("block/slab"), new Identifier("block/slab_top"), 4, AXIS)); // STAIR - HELPER.addReFramedModel("stair" , HELPER.auto(ReFramed.id("block/stair/straight"))); - HELPER.addReFramedModel("outers_stair" , HELPER.auto(ReFramed.id("block/stair/double_outer"))); - HELPER.addReFramedModel("inner_stair" , HELPER.auto(ReFramed.id("block/stair/inner"))); - HELPER.addReFramedModel("outer_stair" , HELPER.auto(ReFramed.id("block/stair/outer"))); - HELPER.addReFramedModel("outer_side_stair" , HELPER.auto(ReFramed.id("block/stair/outer_side"))); + HELPER.addReFramedModel("stair" , HELPER.auto(ReFramed.id("block/stair/straight"), 13, EDGE)); + HELPER.addReFramedModel("outers_stair" , HELPER.auto(ReFramed.id("block/stair/double_outer"), 24, EDGE, STAIR_SHAPE)); + HELPER.addReFramedModel("inner_stair" , HELPER.auto(ReFramed.id("block/stair/inner"), 24, EDGE, STAIR_SHAPE)); + HELPER.addReFramedModel("outer_stair" , HELPER.auto(ReFramed.id("block/stair/outer"), 16, EDGE, STAIR_SHAPE)); + HELPER.addReFramedModel("outer_side_stair" , HELPER.auto(ReFramed.id("block/stair/outer_side"), 32, EDGE, STAIR_SHAPE)); // STAIRS_CUBE - HELPER.addReFramedModel("stairs_cube" , HELPER.autoDouble(ReFramed.id("block/stair/straight"), ReFramed.id("block/stair/cube/straight"))); - HELPER.addReFramedModel("outers_stairs_cube" , HELPER.autoDouble(ReFramed.id("block/stair/double_outer"), ReFramed.id("block/stair/cube/double_outer"))); - HELPER.addReFramedModel("inner_stairs_cube" , HELPER.autoDouble(ReFramed.id("block/stair/inner"), ReFramed.id("block/stair/cube/inner"))); - HELPER.addReFramedModel("outer_stairs_cube" , HELPER.autoDouble(ReFramed.id("block/stair/outer"), ReFramed.id("block/stair/cube/outer"))); - HELPER.addReFramedModel("outer_side_stairs_cube" , HELPER.autoDouble(ReFramed.id("block/stair/outer_side"), ReFramed.id("block/stair/cube/outer_side"))); + HELPER.addReFramedModel("stairs_cube" , HELPER.autoDouble(ReFramed.id("block/stair/straight"), ReFramed.id("block/stair/cube/straight"), 13, EDGE)); + HELPER.addReFramedModel("outers_stairs_cube" , HELPER.autoDouble(ReFramed.id("block/stair/double_outer"), ReFramed.id("block/stair/cube/double_outer"), 24, EDGE, STAIR_SHAPE)); + HELPER.addReFramedModel("inner_stairs_cube" , HELPER.autoDouble(ReFramed.id("block/stair/inner"), ReFramed.id("block/stair/cube/inner"), 24, EDGE, STAIR_SHAPE)); + HELPER.addReFramedModel("outer_stairs_cube" , HELPER.autoDouble(ReFramed.id("block/stair/outer"), ReFramed.id("block/stair/cube/outer"), 16, EDGE, STAIR_SHAPE)); + HELPER.addReFramedModel("outer_side_stairs_cube" , HELPER.autoDouble(ReFramed.id("block/stair/outer_side"), ReFramed.id("block/stair/cube/outer_side"), 32, EDGE, STAIR_SHAPE)); // HALF_STAIR - HELPER.addReFramedModel("half_stair_down" , HELPER.auto(ReFramed.id("block/half_stair/down"))); - HELPER.addReFramedModel("half_stair_side" , HELPER.auto(ReFramed.id("block/half_stair/side"))); + HELPER.addReFramedModel("half_stair_down" , HELPER.auto(ReFramed.id("block/half_stair/down"), 9, CORNER, CORNER_FACE)); + HELPER.addReFramedModel("half_stair_side" , HELPER.auto(ReFramed.id("block/half_stair/side"), 16, CORNER, CORNER_FACE)); // HALF_STAIRS_SLAB - HELPER.addReFramedModel("half_stairs_slab_down" , HELPER.autoDouble(ReFramed.id("block/half_stair/down"), ReFramed.id("block/half_stair/slab/down"))); - HELPER.addReFramedModel("half_stairs_slab_side" , HELPER.autoDouble(ReFramed.id("block/half_stair/side"), ReFramed.id("block/half_stair/slab/side"))); + HELPER.addReFramedModel("half_stairs_slab_down" , HELPER.autoDouble(ReFramed.id("block/half_stair/down"), ReFramed.id("block/half_stair/slab/down"), 9, CORNER, CORNER_FACE)); + HELPER.addReFramedModel("half_stairs_slab_side" , HELPER.autoDouble(ReFramed.id("block/half_stair/side"), ReFramed.id("block/half_stair/slab/side"), 16, CORNER, CORNER_FACE)); // HALF_STAIRS_STAIR - HELPER.addReFramedModel("half_stairs_stair_down" , HELPER.autoDouble(ReFramed.id("block/half_stair/down"), ReFramed.id("block/half_stair/stair/down"))); - HELPER.addReFramedModel("half_stairs_stair_side" , HELPER.autoDouble(ReFramed.id("block/half_stair/side"), ReFramed.id("block/half_stair/stair/side"))); - HELPER.addReFramedModel("half_stairs_stair_reverse" , HELPER.autoDouble(ReFramed.id("block/half_stair/stair/side"), ReFramed.id("block/half_stair/side"))); + HELPER.addReFramedModel("half_stairs_stair_down" , HELPER.autoDouble(ReFramed.id("block/half_stair/down"), ReFramed.id("block/half_stair/stair/down"), 5, EDGE)); + HELPER.addReFramedModel("half_stairs_stair_side" , HELPER.autoDouble(ReFramed.id("block/half_stair/side"), ReFramed.id("block/half_stair/stair/side"), 6, EDGE)); + HELPER.addReFramedModel("half_stairs_stair_reverse" , HELPER.autoDouble(ReFramed.id("block/half_stair/stair/side"), ReFramed.id("block/half_stair/side"), 2, EDGE)); // STEP - HELPER.addReFramedModel("step" , HELPER.auto(ReFramed.id("block/step/down"))); + HELPER.addReFramedModel("step" , HELPER.auto(ReFramed.id("block/step/down"), 13, EDGE)); // STEPS_SLAB - HELPER.addReFramedModel("steps_slab" , HELPER.autoDouble(ReFramed.id("block/step/down"), ReFramed.id("block/step/slab/down"))); - HELPER.addReFramedModel("steps_slab_side" , HELPER.autoDouble(ReFramed.id("block/step/side"), ReFramed.id("block/step/slab/side"))); + HELPER.addReFramedModel("steps_slab" , HELPER.autoDouble(ReFramed.id("block/step/down"), ReFramed.id("block/step/slab/down"), 5, FACING, AXIS)); + HELPER.addReFramedModel("steps_slab_side" , HELPER.autoDouble(ReFramed.id("block/step/side"), ReFramed.id("block/step/slab/side"), 8, FACING, AXIS)); // LAYER - HELPER.addReFramedModel("layer_1" , HELPER.auto(new Identifier("block/snow_height2"))); - HELPER.addReFramedModel("layer_2" , HELPER.auto(new Identifier("block/snow_height4"))); - HELPER.addReFramedModel("layer_3" , HELPER.auto(new Identifier("block/snow_height6"))); - HELPER.addReFramedModel("layer_4" , HELPER.auto(new Identifier("block/snow_height8"))); - HELPER.addReFramedModel("layer_5" , HELPER.auto(new Identifier("block/snow_height10"))); - HELPER.addReFramedModel("layer_6" , HELPER.auto(new Identifier("block/snow_height12"))); - HELPER.addReFramedModel("layer_7" , HELPER.auto(new Identifier("block/snow_height14"))); - HELPER.addReFramedModel("layer_8" , HELPER.auto(new Identifier("block/cube"))); + HELPER.addReFramedModel("layer_1" , HELPER.auto(new Identifier("block/snow_height2"), 7, FACING)); + HELPER.addReFramedModel("layer_2" , HELPER.auto(new Identifier("block/snow_height4"), 6, FACING)); + HELPER.addReFramedModel("layer_3" , HELPER.auto(new Identifier("block/snow_height6"), 6, FACING)); + HELPER.addReFramedModel("layer_4" , HELPER.auto(new Identifier("block/snow_height8"), 6, FACING)); + HELPER.addReFramedModel("layer_5" , HELPER.auto(new Identifier("block/snow_height10"), 6, FACING)); + HELPER.addReFramedModel("layer_6" , HELPER.auto(new Identifier("block/snow_height12"), 6, FACING)); + HELPER.addReFramedModel("layer_7" , HELPER.auto(new Identifier("block/snow_height14"), 6, FACING)); + HELPER.addReFramedModel("layer_8" , HELPER.auto(new Identifier("block/cube"), 1)); // PILLAR - HELPER.addReFramedModel("pillar" , HELPER.auto(ReFramed.id("block/pillar"))); + HELPER.addReFramedModel("pillar" , HELPER.auto(ReFramed.id("block/pillar"), 4, AXIS)); // WALL - HELPER.addReFramedModel("wall_inventory" , HELPER.auto(ReFramed.id("block/wall/inventory/default"))); + HELPER.addReFramedModel("wall_inventory" , HELPER.auto(ReFramed.id("block/wall/inventory/default"), 1)); // --------------------- pillar - HELPER.addReFramedModel("wall_core" , HELPER.auto(ReFramed.id("block/wall/pillar/core"))); - HELPER.addReFramedModel("wall_pillar_low" , HELPER.auto(ReFramed.id("block/wall/pillar/low"))); - HELPER.addReFramedModel("wall_pillar_tall" , HELPER.auto(ReFramed.id("block/wall/pillar/tall"))); - HELPER.addReFramedModel("wall_pillar_none" , HELPER.auto(ReFramed.id("block/wall/pillar/none"))); + HELPER.addReFramedModel("wall_core" , HELPER.auto(ReFramed.id("block/wall/pillar/core"), 1, UP)); + HELPER.addReFramedModel("wall_pillar_low" , HELPER.auto(ReFramed.id("block/wall/pillar/low"), 4, NORTH_WALL_SHAPE, EAST_WALL_SHAPE, SOUTH_WALL_SHAPE, WEST_WALL_SHAPE)); + HELPER.addReFramedModel("wall_pillar_tall" , HELPER.auto(ReFramed.id("block/wall/pillar/tall"), 4, NORTH_WALL_SHAPE, EAST_WALL_SHAPE, SOUTH_WALL_SHAPE, WEST_WALL_SHAPE)); + HELPER.addReFramedModel("wall_pillar_none" , HELPER.auto(ReFramed.id("block/wall/pillar/none"), 4, NORTH_WALL_SHAPE, EAST_WALL_SHAPE, SOUTH_WALL_SHAPE, WEST_WALL_SHAPE)); // --------------------- side - HELPER.addReFramedModel("wall_side_low" , HELPER.auto(ReFramed.id("block/wall/side/low"))); - HELPER.addReFramedModel("wall_side_tall" , HELPER.auto(ReFramed.id("block/wall/side/tall"))); + HELPER.addReFramedModel("wall_side_low" , HELPER.auto(ReFramed.id("block/wall/side/low"), 92, NORTH_WALL_SHAPE, EAST_WALL_SHAPE, SOUTH_WALL_SHAPE, WEST_WALL_SHAPE)); + HELPER.addReFramedModel("wall_side_tall" , HELPER.auto(ReFramed.id("block/wall/side/tall"), 92, NORTH_WALL_SHAPE, EAST_WALL_SHAPE, SOUTH_WALL_SHAPE, WEST_WALL_SHAPE)); // --------------------- junction - HELPER.addReFramedModel("wall_low_e" , HELPER.auto(ReFramed.id("block/wall/junction/low"))); - HELPER.addReFramedModel("wall_tall_e" , HELPER.auto(ReFramed.id("block/wall/junction/tall"))); + HELPER.addReFramedModel("wall_low_e" , HELPER.auto(ReFramed.id("block/wall/junction/low"), 4, NORTH_WALL_SHAPE, EAST_WALL_SHAPE, SOUTH_WALL_SHAPE, WEST_WALL_SHAPE)); + HELPER.addReFramedModel("wall_tall_e" , HELPER.auto(ReFramed.id("block/wall/junction/tall"), 4, NORTH_WALL_SHAPE, EAST_WALL_SHAPE, SOUTH_WALL_SHAPE, WEST_WALL_SHAPE)); // --------------------- junction_i - HELPER.addReFramedModel("wall_low_i" , HELPER.auto(ReFramed.id("block/wall/junction/low_i"))); - HELPER.addReFramedModel("wall_tall_i" , HELPER.auto(ReFramed.id("block/wall/junction/tall_i"))); - HELPER.addReFramedModel("wall_low_tall_i" , HELPER.auto(ReFramed.id("block/wall/junction/low_tall_i"))); + HELPER.addReFramedModel("wall_low_i" , HELPER.auto(ReFramed.id("block/wall/junction/low_i"), 4, NORTH_WALL_SHAPE, EAST_WALL_SHAPE, SOUTH_WALL_SHAPE, WEST_WALL_SHAPE)); + HELPER.addReFramedModel("wall_tall_i" , HELPER.auto(ReFramed.id("block/wall/junction/tall_i"), 4, NORTH_WALL_SHAPE, EAST_WALL_SHAPE, SOUTH_WALL_SHAPE, WEST_WALL_SHAPE)); + HELPER.addReFramedModel("wall_low_tall_i" , HELPER.auto(ReFramed.id("block/wall/junction/low_tall_i"), 4, NORTH_WALL_SHAPE, EAST_WALL_SHAPE, SOUTH_WALL_SHAPE, WEST_WALL_SHAPE)); // --------------------- junction_c - HELPER.addReFramedModel("wall_low_c" , HELPER.auto(ReFramed.id("block/wall/junction/low_c"))); - HELPER.addReFramedModel("wall_tall_c" , HELPER.auto(ReFramed.id("block/wall/junction/tall_c"))); - HELPER.addReFramedModel("wall_low_tall_c" , HELPER.auto(ReFramed.id("block/wall/junction/low_tall_c"))); - HELPER.addReFramedModel("wall_tall_low_c" , HELPER.auto(ReFramed.id("block/wall/junction/tall_low_c"))); + HELPER.addReFramedModel("wall_low_c" , HELPER.auto(ReFramed.id("block/wall/junction/low_c"), 4, NORTH_WALL_SHAPE, EAST_WALL_SHAPE, SOUTH_WALL_SHAPE, WEST_WALL_SHAPE)); + HELPER.addReFramedModel("wall_tall_c" , HELPER.auto(ReFramed.id("block/wall/junction/tall_c"), 4, NORTH_WALL_SHAPE, EAST_WALL_SHAPE, SOUTH_WALL_SHAPE, WEST_WALL_SHAPE)); + HELPER.addReFramedModel("wall_low_tall_c" , HELPER.auto(ReFramed.id("block/wall/junction/low_tall_c"), 4, NORTH_WALL_SHAPE, EAST_WALL_SHAPE, SOUTH_WALL_SHAPE, WEST_WALL_SHAPE)); + HELPER.addReFramedModel("wall_tall_low_c" , HELPER.auto(ReFramed.id("block/wall/junction/tall_low_c"), 4, NORTH_WALL_SHAPE, EAST_WALL_SHAPE, SOUTH_WALL_SHAPE, WEST_WALL_SHAPE)); // --------------------- junction_t - HELPER.addReFramedModel("wall_low_t" , HELPER.auto(ReFramed.id("block/wall/junction/low_t"))); - HELPER.addReFramedModel("wall_tall_t" , HELPER.auto(ReFramed.id("block/wall/junction/tall_t"))); - HELPER.addReFramedModel("wall_tall_low_c_t" , HELPER.auto(ReFramed.id("block/wall/junction/tall_low_c_t"))); - HELPER.addReFramedModel("wall_tall_i_low_t" , HELPER.auto(ReFramed.id("block/wall/junction/tall_i_low_t"))); - HELPER.addReFramedModel("wall_low_i_tall_t" , HELPER.auto(ReFramed.id("block/wall/junction/low_i_tall_t"))); - HELPER.addReFramedModel("wall_low_tall_c_t" , HELPER.auto(ReFramed.id("block/wall/junction/low_tall_c_t"))); - HELPER.addReFramedModel("wall_low_c_tall_t" , HELPER.auto(ReFramed.id("block/wall/junction/low_c_tall_t"))); - HELPER.addReFramedModel("wall_tall_c_low_t" , HELPER.auto(ReFramed.id("block/wall/junction/tall_c_low_t"))); + HELPER.addReFramedModel("wall_low_t" , HELPER.auto(ReFramed.id("block/wall/junction/low_t"), 4, NORTH_WALL_SHAPE, EAST_WALL_SHAPE, SOUTH_WALL_SHAPE, WEST_WALL_SHAPE)); + HELPER.addReFramedModel("wall_tall_t" , HELPER.auto(ReFramed.id("block/wall/junction/tall_t"), 4, NORTH_WALL_SHAPE, EAST_WALL_SHAPE, SOUTH_WALL_SHAPE, WEST_WALL_SHAPE)); + HELPER.addReFramedModel("wall_tall_low_c_t" , HELPER.auto(ReFramed.id("block/wall/junction/tall_low_c_t"), 4, NORTH_WALL_SHAPE, EAST_WALL_SHAPE, SOUTH_WALL_SHAPE, WEST_WALL_SHAPE)); + HELPER.addReFramedModel("wall_tall_i_low_t" , HELPER.auto(ReFramed.id("block/wall/junction/tall_i_low_t"), 4, NORTH_WALL_SHAPE, EAST_WALL_SHAPE, SOUTH_WALL_SHAPE, WEST_WALL_SHAPE)); + HELPER.addReFramedModel("wall_low_i_tall_t" , HELPER.auto(ReFramed.id("block/wall/junction/low_i_tall_t"), 4, NORTH_WALL_SHAPE, EAST_WALL_SHAPE, SOUTH_WALL_SHAPE, WEST_WALL_SHAPE)); + HELPER.addReFramedModel("wall_low_tall_c_t" , HELPER.auto(ReFramed.id("block/wall/junction/low_tall_c_t"), 4, NORTH_WALL_SHAPE, EAST_WALL_SHAPE, SOUTH_WALL_SHAPE, WEST_WALL_SHAPE)); + HELPER.addReFramedModel("wall_low_c_tall_t" , HELPER.auto(ReFramed.id("block/wall/junction/low_c_tall_t"), 4, NORTH_WALL_SHAPE, EAST_WALL_SHAPE, SOUTH_WALL_SHAPE, WEST_WALL_SHAPE)); + HELPER.addReFramedModel("wall_tall_c_low_t" , HELPER.auto(ReFramed.id("block/wall/junction/tall_c_low_t"), 4, NORTH_WALL_SHAPE, EAST_WALL_SHAPE, SOUTH_WALL_SHAPE, WEST_WALL_SHAPE)); // --------------------- junction_x - HELPER.addReFramedModel("wall_low_x" , HELPER.auto(ReFramed.id("block/wall/junction/low_x"))); - HELPER.addReFramedModel("wall_tall_x" , HELPER.auto(ReFramed.id("block/wall/junction/tall_x"))); - HELPER.addReFramedModel("wall_tall_i_low_i_x" , HELPER.auto(ReFramed.id("block/wall/junction/tall_i_low_i_x"))); - HELPER.addReFramedModel("wall_tall_low_t_x" , HELPER.auto(ReFramed.id("block/wall/junction/tall_low_t_x"))); - HELPER.addReFramedModel("wall_tall_c_low_c_x" , HELPER.auto(ReFramed.id("block/wall/junction/tall_c_low_c_x"))); - HELPER.addReFramedModel("wall_tall_t_low_x" , HELPER.auto(ReFramed.id("block/wall/junction/tall_t_low_x"))); + HELPER.addReFramedModel("wall_low_x" , HELPER.auto(ReFramed.id("block/wall/junction/low_x"), 4, NORTH_WALL_SHAPE, EAST_WALL_SHAPE, SOUTH_WALL_SHAPE, WEST_WALL_SHAPE)); + HELPER.addReFramedModel("wall_tall_x" , HELPER.auto(ReFramed.id("block/wall/junction/tall_x"), 4, NORTH_WALL_SHAPE, EAST_WALL_SHAPE, SOUTH_WALL_SHAPE, WEST_WALL_SHAPE)); + HELPER.addReFramedModel("wall_tall_i_low_i_x" , HELPER.auto(ReFramed.id("block/wall/junction/tall_i_low_i_x"), 4, NORTH_WALL_SHAPE, EAST_WALL_SHAPE, SOUTH_WALL_SHAPE, WEST_WALL_SHAPE)); + HELPER.addReFramedModel("wall_tall_low_t_x" , HELPER.auto(ReFramed.id("block/wall/junction/tall_low_t_x"), 4, NORTH_WALL_SHAPE, EAST_WALL_SHAPE, SOUTH_WALL_SHAPE, WEST_WALL_SHAPE)); + HELPER.addReFramedModel("wall_tall_c_low_c_x" , HELPER.auto(ReFramed.id("block/wall/junction/tall_c_low_c_x"), 4, NORTH_WALL_SHAPE, EAST_WALL_SHAPE, SOUTH_WALL_SHAPE, WEST_WALL_SHAPE)); + HELPER.addReFramedModel("wall_tall_t_low_x" , HELPER.auto(ReFramed.id("block/wall/junction/tall_t_low_x"), 4, NORTH_WALL_SHAPE, EAST_WALL_SHAPE, SOUTH_WALL_SHAPE, WEST_WALL_SHAPE)); //item model assignments (in lieu of models/item/___.json) diff --git a/src/main/java/fr/adrien1106/reframed/client/ReFramedClientHelper.java b/src/main/java/fr/adrien1106/reframed/client/ReFramedClientHelper.java index 7587275..547771e 100644 --- a/src/main/java/fr/adrien1106/reframed/client/ReFramedClientHelper.java +++ b/src/main/java/fr/adrien1106/reframed/client/ReFramedClientHelper.java @@ -13,6 +13,7 @@ import net.minecraft.client.render.model.UnbakedModel; import net.minecraft.client.texture.Sprite; import net.minecraft.client.util.SpriteIdentifier; import net.minecraft.item.ItemConvertible; +import net.minecraft.state.property.Property; import net.minecraft.util.Identifier; import org.jetbrains.annotations.NotNull; @@ -27,16 +28,19 @@ public class ReFramedClientHelper { private final ReFramedModelProvider prov; - public UnbakedRetexturedModel auto(Identifier parent) { - return new UnbakedAutoRetexturedModel(parent); + public UnbakedRetexturedModel auto(Identifier parent, int model_count, Property... properties) { + return new UnbakedAutoRetexturedModel(parent, model_count, properties); } - public UnbakedRetexturedModel json(Identifier parent) { - return new UnbakedJsonRetexturedModel(parent); + public UnbakedRetexturedModel json(Identifier parent, int model_count, Property... properties) { + return new UnbakedJsonRetexturedModel(parent, model_count, properties); } - public UnbakedModel autoDouble(Identifier first, Identifier second) { - return new UnbakedDoubleRetexturedModel(auto(first), auto(second)); + public UnbakedModel autoDouble(Identifier first, Identifier second, int model_count, Property... properties) { + return new UnbakedDoubleRetexturedModel( + auto(first, model_count, properties), + auto(second, model_count, properties) + ); } public void addReFramedModel(String id, UnbakedModel unbaked) { diff --git a/src/main/java/fr/adrien1106/reframed/client/model/RetexturingBakedModel.java b/src/main/java/fr/adrien1106/reframed/client/model/RetexturingBakedModel.java index 0b211fc..03cbe78 100644 --- a/src/main/java/fr/adrien1106/reframed/client/model/RetexturingBakedModel.java +++ b/src/main/java/fr/adrien1106/reframed/client/model/RetexturingBakedModel.java @@ -1,8 +1,11 @@ package fr.adrien1106.reframed.client.model; +import com.google.common.cache.Cache; +import com.google.common.cache.CacheBuilder; import fr.adrien1106.reframed.block.ReFramedBlock; import fr.adrien1106.reframed.block.ReFramedEntity; import fr.adrien1106.reframed.client.ReFramedClient; +import fr.adrien1106.reframed.client.util.RenderHelper; import fr.adrien1106.reframed.mixin.MinecraftAccessor; import fr.adrien1106.reframed.client.model.apperance.CamoAppearance; import fr.adrien1106.reframed.client.model.apperance.CamoAppearanceManager; @@ -19,27 +22,28 @@ import net.minecraft.client.render.model.BakedModel; import net.minecraft.client.render.model.ModelBakeSettings; import net.minecraft.client.texture.Sprite; import net.minecraft.item.ItemStack; +import net.minecraft.state.property.Property; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; import net.minecraft.util.math.random.Random; import net.minecraft.world.BlockRenderView; +import java.util.List; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Supplier; +import java.util.stream.Stream; public abstract class RetexturingBakedModel extends ForwardingBakedModel { - public RetexturingBakedModel(BakedModel base_model, CamoAppearanceManager tam, int theme_index, ModelBakeSettings settings, BlockState item_state, boolean ao) { + public RetexturingBakedModel(BakedModel base_model, CamoAppearanceManager tam, int theme_index, ModelBakeSettings settings, BlockState item_state, int model_count, Property... properties) { this.wrapped = base_model; //field from the superclass; vanilla getQuads etc. will delegate through to this this.appearance_manager = tam; this.theme_index = theme_index; this.uv_lock = settings.isUvLocked(); this.item_state = item_state; - this.ao = ao; + this.properties = properties; - int cache_size = 64; // default is 64 why don't ask me and it should get overwritten - if (item_state.getBlock() instanceof ReFramedBlock frame_block) cache_size = frame_block.getModelStateCount() + 1; - BASE_MESH_CACHE = new Object2ObjectLinkedOpenHashMap<>(cache_size, 0.25f) { + BASE_MESH_CACHE = new Object2ObjectLinkedOpenHashMap<>(model_count, 0.25f) { @Override protected void rehash(int v) {} }; @@ -48,16 +52,13 @@ public abstract class RetexturingBakedModel extends ForwardingBakedModel { protected final CamoAppearanceManager appearance_manager; protected final int theme_index; protected final boolean uv_lock; - protected final boolean ao; protected final BlockState item_state; + protected final Property[] properties; protected record MeshCacheKey(Object state_key, CamoAppearance appearance, int model_id) {} /** cache that store retextured models */ - protected final Object2ObjectLinkedOpenHashMap RETEXTURED_MESH_CACHE = - new Object2ObjectLinkedOpenHashMap<>(128, 0.25f) { - @Override - protected void rehash(int v) {} - }; + // self culling cache of the models not made thread local so that it is only computed once + protected final Cache RETEXTURED_MESH_CACHE = CacheBuilder.newBuilder().maximumSize(256).build(); /** cache that stores the base meshes which has the size of the amount of models */ protected final Object2ObjectLinkedOpenHashMap BASE_MESH_CACHE; @@ -91,14 +92,13 @@ public abstract class RetexturingBakedModel extends ForwardingBakedModel { @Override public void emitBlockQuads(BlockRenderView world, BlockState state, BlockPos pos, Supplier randomSupplier, RenderContext context) { - // skip render if block not a frame (which should always be the case - if (!(state.getBlock() instanceof ReFramedBlock frame_block)) return; BlockState theme = (world.getBlockEntity(pos) instanceof ThemeableBlockEntity s) ? s.getTheme(theme_index) : null; QuadEmitter quad_emitter = context.getEmitter(); + List model_key = Stream.of(properties).map(state::get).toList(); if(theme == null || theme.isAir()) { getRetexturedMesh( new MeshCacheKey( - frame_block.getModelCacheKey(state), + model_key, appearance_manager.getDefaultAppearance(theme_index), 0 ), @@ -114,7 +114,7 @@ public abstract class RetexturingBakedModel extends ForwardingBakedModel { if (camo instanceof WeightedComputedAppearance wca) model_id = wca.getAppearanceIndex(seed); int tint = 0xFF000000 | MinecraftClient.getInstance().getBlockColors().getColor(theme, world, pos, 0); - MeshCacheKey key = new MeshCacheKey(frame_block.getModelCacheKey(state), camo, model_id); + MeshCacheKey key = new MeshCacheKey(model_key, camo, model_id); // do not clutter the cache with single-use meshes Mesh untintedMesh = camo.hashCode() == -1 ? transformMesh(key, state) : getRetexturedMesh(key, state); @@ -157,9 +157,9 @@ public abstract class RetexturingBakedModel extends ForwardingBakedModel { } protected Mesh getRetexturedMesh(MeshCacheKey key, BlockState state) { - if (RETEXTURED_MESH_CACHE.containsKey(key)) return RETEXTURED_MESH_CACHE.getAndMoveToFirst(key); + if (RETEXTURED_MESH_CACHE.asMap().containsKey(key)) return RETEXTURED_MESH_CACHE.getIfPresent(key); Mesh mesh = transformMesh(key, state); - RETEXTURED_MESH_CACHE.putAndMoveToFirst(key, mesh); + RETEXTURED_MESH_CACHE.put(key, mesh); return mesh; } @@ -172,7 +172,7 @@ public abstract class RetexturingBakedModel extends ForwardingBakedModel { int i = -1; do { emitter.copyFrom(quad); - i = key.appearance.transformQuad(emitter, i, quad_index.get(), key.model_id, ao, uv_lock); + i = key.appearance.transformQuad(emitter, i, quad_index.get(), key.model_id, uv_lock); } while (i > 0); // kinda weird to do it like that but other directions don't use the quad_index so it doesn't matter if (quad.cullFace() == null) quad_index.getAndIncrement(); diff --git a/src/main/java/fr/adrien1106/reframed/client/model/UnbakedAutoRetexturedModel.java b/src/main/java/fr/adrien1106/reframed/client/model/UnbakedAutoRetexturedModel.java index 522d17a..ed0fcc1 100644 --- a/src/main/java/fr/adrien1106/reframed/client/model/UnbakedAutoRetexturedModel.java +++ b/src/main/java/fr/adrien1106/reframed/client/model/UnbakedAutoRetexturedModel.java @@ -14,6 +14,7 @@ import net.minecraft.client.render.model.Baker; import net.minecraft.client.render.model.ModelBakeSettings; import net.minecraft.client.texture.Sprite; import net.minecraft.client.util.SpriteIdentifier; +import net.minecraft.state.property.Property; import net.minecraft.util.Identifier; import net.minecraft.util.math.Direction; import net.minecraft.util.math.random.Random; @@ -23,8 +24,8 @@ import java.util.function.Function; public class UnbakedAutoRetexturedModel extends UnbakedRetexturedModel { - public UnbakedAutoRetexturedModel(Identifier parent) { - super(parent); + public UnbakedAutoRetexturedModel(Identifier parent, int state_count, Property... properties) { + super(parent, state_count, properties); item_state = Blocks.AIR.getDefaultState(); } @@ -37,7 +38,8 @@ public class UnbakedAutoRetexturedModel extends UnbakedRetexturedModel { theme_index, bake_settings, item_state, - ao + state_count, + properties ) { protected Mesh convertModel(BlockState state) { Renderer r = ReFramedClient.HELPER.getFabricRenderer(); diff --git a/src/main/java/fr/adrien1106/reframed/client/model/UnbakedJsonRetexturedModel.java b/src/main/java/fr/adrien1106/reframed/client/model/UnbakedJsonRetexturedModel.java index 15b2b62..285f141 100644 --- a/src/main/java/fr/adrien1106/reframed/client/model/UnbakedJsonRetexturedModel.java +++ b/src/main/java/fr/adrien1106/reframed/client/model/UnbakedJsonRetexturedModel.java @@ -15,6 +15,7 @@ import net.minecraft.client.render.model.ModelBakeSettings; import net.minecraft.client.texture.Sprite; import net.minecraft.client.util.SpriteIdentifier; import net.minecraft.screen.PlayerScreenHandler; +import net.minecraft.state.property.Property; import net.minecraft.util.Identifier; import net.minecraft.util.math.Direction; import net.minecraft.util.math.random.Random; @@ -24,8 +25,8 @@ import java.util.Objects; import java.util.function.Function; public class UnbakedJsonRetexturedModel extends UnbakedRetexturedModel { - public UnbakedJsonRetexturedModel(Identifier parent) { - super(parent); + public UnbakedJsonRetexturedModel(Identifier parent, int state_count, Property... properties) { + super(parent, state_count, properties); } @Nullable @@ -45,7 +46,8 @@ public class UnbakedJsonRetexturedModel extends UnbakedRetexturedModel { theme_index, bake_settings, item_state, - ao + state_count, + properties ) { protected Mesh convertModel(BlockState state) { Renderer r = ReFramedClient.HELPER.getFabricRenderer(); diff --git a/src/main/java/fr/adrien1106/reframed/client/model/UnbakedRetexturedModel.java b/src/main/java/fr/adrien1106/reframed/client/model/UnbakedRetexturedModel.java index 6355a30..46e6ec5 100644 --- a/src/main/java/fr/adrien1106/reframed/client/model/UnbakedRetexturedModel.java +++ b/src/main/java/fr/adrien1106/reframed/client/model/UnbakedRetexturedModel.java @@ -2,6 +2,7 @@ package fr.adrien1106.reframed.client.model; import net.minecraft.block.BlockState; import net.minecraft.client.render.model.UnbakedModel; +import net.minecraft.state.property.Property; import net.minecraft.util.Identifier; import java.util.Collection; @@ -15,9 +16,13 @@ public abstract class UnbakedRetexturedModel implements UnbakedModel { protected int theme_index = 1; protected BlockState item_state; protected final boolean ao = true; + protected final int state_count; + protected final Property[] properties; - public UnbakedRetexturedModel(Identifier parent) { + public UnbakedRetexturedModel(Identifier parent, int state_count, Property... properties) { this.parent = parent; + this.state_count = state_count; + this.properties = properties; } public UnbakedRetexturedModel setThemeIndex(int theme_index) { diff --git a/src/main/java/fr/adrien1106/reframed/client/model/apperance/Appearance.java b/src/main/java/fr/adrien1106/reframed/client/model/apperance/Appearance.java index 3b62525..f48bb3e 100644 --- a/src/main/java/fr/adrien1106/reframed/client/model/apperance/Appearance.java +++ b/src/main/java/fr/adrien1106/reframed/client/model/apperance/Appearance.java @@ -5,4 +5,4 @@ import net.minecraft.util.math.Direction; import java.util.List; import java.util.Map; -public record Appearance(Map> sprites) {} +public record Appearance(Map> sprites, boolean use_ao) {} diff --git a/src/main/java/fr/adrien1106/reframed/client/model/apperance/CamoAppearance.java b/src/main/java/fr/adrien1106/reframed/client/model/apperance/CamoAppearance.java index 5fcd555..4b5db61 100644 --- a/src/main/java/fr/adrien1106/reframed/client/model/apperance/CamoAppearance.java +++ b/src/main/java/fr/adrien1106/reframed/client/model/apperance/CamoAppearance.java @@ -26,12 +26,13 @@ public abstract class CamoAppearance { public abstract @NotNull List getSprites(Direction dir, int model_id); public abstract boolean hasColor(Direction dir, int model_id, int index); + public abstract boolean getAO(int model_id); public @NotNull RenderMaterial getRenderMaterial(boolean ao) { return ao && ao_material != null? ao_material : material; } - public int transformQuad(QuadEmitter quad, int i, int quad_index, int model_id, boolean ao, boolean uv_lock) { + public int transformQuad(QuadEmitter quad, int i, int quad_index, int model_id, boolean uv_lock) { if(quad.tag() == 0) return 0; // Pass the quad through unmodified. Direction direction = quad.nominalFace(); @@ -44,7 +45,7 @@ public abstract class CamoAppearance { QuadPosBounds bounds = properties.bounds(); if (bounds == null) { // sprite applies anywhere e.g. default behaviour - quad.material(getRenderMaterial(ao)); + quad.material(getRenderMaterial(getAO(model_id))); quad.spriteBake( properties.sprite(), MutableQuadView.BAKE_NORMALIZED @@ -61,7 +62,7 @@ public abstract class CamoAppearance { if (!bounds.matches(origin_bounds)) return i; // apply new quad shape - quad.material(getRenderMaterial(ao)); + quad.material(getRenderMaterial(getAO(model_id))); bounds.intersection(origin_bounds, direction.getAxis()).apply(quad, origin_bounds); quad.spriteBake( // seems to work without the flags and break with it properties.sprite(), diff --git a/src/main/java/fr/adrien1106/reframed/client/model/apperance/CamoAppearanceManager.java b/src/main/java/fr/adrien1106/reframed/client/model/apperance/CamoAppearanceManager.java index 665a5a2..f5d1b9d 100644 --- a/src/main/java/fr/adrien1106/reframed/client/model/apperance/CamoAppearanceManager.java +++ b/src/main/java/fr/adrien1106/reframed/client/model/apperance/CamoAppearanceManager.java @@ -64,12 +64,12 @@ public class CamoAppearanceManager { this.accent_appearance = new SingleSpriteAppearance(sprite, materials.get(BlendMode.CUTOUT), serial_number.getAndIncrement()); sprite = spriteLookup.apply(BARRIER_SPRITE_ID); - this.barrierItemAppearance = new SingleSpriteAppearance(sprite, materials.get(BlendMode.CUTOUT), serial_number.getAndIncrement()); + this.barrier_appearance = new SingleSpriteAppearance(sprite, materials.get(BlendMode.CUTOUT), serial_number.getAndIncrement()); } private final CamoAppearance default_appearance; private final CamoAppearance accent_appearance; - private final CamoAppearance barrierItemAppearance; + private final CamoAppearance barrier_appearance; private final AtomicInteger serial_number = new AtomicInteger(0); //Mutable @@ -119,7 +119,7 @@ public class CamoAppearanceManager { // The results are going to be the same, apart from their serialNumbers differing (= their equals & hashCode differing). // Tiny amount of wasted space in some caches if CamoAppearances are used as a map key, then. IMO it's not a critical issue. private CamoAppearance computeAppearance(BakedModel model, BlockState state, boolean is_dynamic) { - if(state.getBlock() == Blocks.BARRIER) return barrierItemAppearance; + if(state.getBlock() == Blocks.BARRIER) return barrier_appearance; if (!(model instanceof WeightedBakedModelAccessor weighted_model)) { return new ComputedAppearance( @@ -175,7 +175,7 @@ public class CamoAppearanceManager { }); }); - return new Appearance(sprites); + return new Appearance(sprites, model.useAmbientOcclusion()); } private static int getBakeFlags(QuadEmitter emitter, Sprite sprite) { diff --git a/src/main/java/fr/adrien1106/reframed/client/model/apperance/ComputedAppearance.java b/src/main/java/fr/adrien1106/reframed/client/model/apperance/ComputedAppearance.java index 3918144..aa2c91e 100644 --- a/src/main/java/fr/adrien1106/reframed/client/model/apperance/ComputedAppearance.java +++ b/src/main/java/fr/adrien1106/reframed/client/model/apperance/ComputedAppearance.java @@ -16,7 +16,6 @@ public class ComputedAppearance extends CamoAppearance { super(ao_material, material, id); this.appearance = appearance; } - @Override public @NotNull List getSprites(Direction dir, int model_id) { return appearance.sprites().get(dir); @@ -29,6 +28,12 @@ public class ComputedAppearance extends CamoAppearance { return properties.get(index).has_colors(); } + @Override + public boolean getAO(int model_id) { + return appearance.use_ao(); + } + + @Override public boolean equals(Object o) { if(this == o) return true; diff --git a/src/main/java/fr/adrien1106/reframed/client/model/apperance/SingleSpriteAppearance.java b/src/main/java/fr/adrien1106/reframed/client/model/apperance/SingleSpriteAppearance.java index 9c8054a..04fb4ef 100644 --- a/src/main/java/fr/adrien1106/reframed/client/model/apperance/SingleSpriteAppearance.java +++ b/src/main/java/fr/adrien1106/reframed/client/model/apperance/SingleSpriteAppearance.java @@ -35,6 +35,12 @@ public class SingleSpriteAppearance extends CamoAppearance { return id == that.id; } + @Override + public boolean getAO(int model_id) { + return false; + } + + @Override public String toString() { return "SingleSpriteAppearance[defaultSprite=%s, mat=%s, id=%d]".formatted(defaultSprite, material, id); diff --git a/src/main/java/fr/adrien1106/reframed/client/model/apperance/WeightedComputedAppearance.java b/src/main/java/fr/adrien1106/reframed/client/model/apperance/WeightedComputedAppearance.java index 443dd92..95f4c0e 100644 --- a/src/main/java/fr/adrien1106/reframed/client/model/apperance/WeightedComputedAppearance.java +++ b/src/main/java/fr/adrien1106/reframed/client/model/apperance/WeightedComputedAppearance.java @@ -46,6 +46,12 @@ public class WeightedComputedAppearance extends CamoAppearance { return properties.get(index).has_colors(); } + @Override + public boolean getAO(int model_id) { + return getAppearance(model_id).use_ao(); + } + + @Override public boolean equals(Object o) { if(this == o) return true; diff --git a/src/main/java/fr/adrien1106/reframed/client/util/RenderHelper.java b/src/main/java/fr/adrien1106/reframed/client/util/RenderHelper.java index 4df304b..12a4481 100644 --- a/src/main/java/fr/adrien1106/reframed/client/util/RenderHelper.java +++ b/src/main/java/fr/adrien1106/reframed/client/util/RenderHelper.java @@ -31,7 +31,6 @@ import static net.minecraft.util.shape.VoxelShapes.combine; @Environment(EnvType.CLIENT) public class RenderHelper { - // self culling cache of the models not made thread local so that it is only computed once private static final Cache INNER_CULL_MAP = CacheBuilder.newBuilder().maximumSize(1024).build(); private record CullElement(Block block, Object state_key, int model) {} From 78b8b6f6079c4ae3ca8921be0ef34be4ca1b2732 Mon Sep 17 00:00:00 2001 From: Adrien1106 Date: Tue, 16 Apr 2024 00:24:16 +0200 Subject: [PATCH 2/3] cleanup + fixed wall collision when using chorus --- .../java/fr/adrien1106/reframed/ReFramed.java | 1 - .../reframed/block/ReframedWallBlock.java | 15 +++++++++++---- .../client/model/RetexturingBakedModel.java | 2 -- .../client/model/UnbakedRetexturedModel.java | 1 - 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/main/java/fr/adrien1106/reframed/ReFramed.java b/src/main/java/fr/adrien1106/reframed/ReFramed.java index f0aff35..532f6e4 100644 --- a/src/main/java/fr/adrien1106/reframed/ReFramed.java +++ b/src/main/java/fr/adrien1106/reframed/ReFramed.java @@ -32,7 +32,6 @@ import static fr.adrien1106.reframed.util.blocks.BlockProperties.LIGHT; * TODO add minecraft models like wall fence etc -> for v1.6 * TODO better connected textures -> maybe v1.6 ? * TODO support continuity overlays -> not scheduled - * TODO fence remove collision if popped chorus -> asap */ public class ReFramed implements ModInitializer { public static final String MODID = "reframed"; diff --git a/src/main/java/fr/adrien1106/reframed/block/ReframedWallBlock.java b/src/main/java/fr/adrien1106/reframed/block/ReframedWallBlock.java index 5b54a0a..581f7db 100644 --- a/src/main/java/fr/adrien1106/reframed/block/ReframedWallBlock.java +++ b/src/main/java/fr/adrien1106/reframed/block/ReframedWallBlock.java @@ -79,9 +79,12 @@ public class ReframedWallBlock extends WaterloggableReFramedBlock { boolean side_full = other_state.isSideSolidFullSquare(world, moved, dir.getOpposite()); if (shouldConnectTo(other_state, side_full, dir.getOpposite())) { + Property wall_shape = getWallShape(dir); new_state = new_state.with( - getWallShape(dir), - fs || shouldUseTall(WALL_VOXELS[dir.ordinal() + 3], top_shape) + wall_shape, + fs + || (top_state.contains(wall_shape) && top_state.get(wall_shape) != WallShape.NONE) + || shouldUseTall(WALL_VOXELS[dir.ordinal() + 3], top_shape) ? WallShape.TALL : WallShape.LOW ); @@ -102,9 +105,12 @@ public class ReframedWallBlock extends WaterloggableReFramedBlock { BlockState neighbor = world.getBlockState(offset); boolean side_full = neighbor.isSideSolidFullSquare(world, offset, dir.getOpposite()); if (shouldConnectTo(neighbor, side_full, dir.getOpposite())) { + Property wall_shape = getWallShape(dir); state = state.with( - getWallShape(dir), - fs || shouldUseTall(WALL_VOXELS[dir.ordinal() + 3], top_shape) + wall_shape, + fs + || (top_state.contains(wall_shape) && top_state.get(wall_shape) != WallShape.NONE) + || shouldUseTall(WALL_VOXELS[dir.ordinal() + 3], top_shape) ? WallShape.TALL : WallShape.LOW ); @@ -133,6 +139,7 @@ public class ReframedWallBlock extends WaterloggableReFramedBlock { @Override public VoxelShape getCollisionShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ctx) { + if (isGhost(view, pos)) return VoxelShapes.empty(); VoxelShape shape = state.get(UP) ? WALL_VOXELS[9]: VoxelShapes.empty(); for (Direction dir : Direction.Type.HORIZONTAL) { if (state.get(getWallShape(dir)) != WallShape.NONE) diff --git a/src/main/java/fr/adrien1106/reframed/client/model/RetexturingBakedModel.java b/src/main/java/fr/adrien1106/reframed/client/model/RetexturingBakedModel.java index 03cbe78..9400b1a 100644 --- a/src/main/java/fr/adrien1106/reframed/client/model/RetexturingBakedModel.java +++ b/src/main/java/fr/adrien1106/reframed/client/model/RetexturingBakedModel.java @@ -2,10 +2,8 @@ package fr.adrien1106.reframed.client.model; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; -import fr.adrien1106.reframed.block.ReFramedBlock; import fr.adrien1106.reframed.block.ReFramedEntity; import fr.adrien1106.reframed.client.ReFramedClient; -import fr.adrien1106.reframed.client.util.RenderHelper; import fr.adrien1106.reframed.mixin.MinecraftAccessor; import fr.adrien1106.reframed.client.model.apperance.CamoAppearance; import fr.adrien1106.reframed.client.model.apperance.CamoAppearanceManager; diff --git a/src/main/java/fr/adrien1106/reframed/client/model/UnbakedRetexturedModel.java b/src/main/java/fr/adrien1106/reframed/client/model/UnbakedRetexturedModel.java index 46e6ec5..f60ac40 100644 --- a/src/main/java/fr/adrien1106/reframed/client/model/UnbakedRetexturedModel.java +++ b/src/main/java/fr/adrien1106/reframed/client/model/UnbakedRetexturedModel.java @@ -15,7 +15,6 @@ public abstract class UnbakedRetexturedModel implements UnbakedModel { protected int theme_index = 1; protected BlockState item_state; - protected final boolean ao = true; protected final int state_count; protected final Property[] properties; From fa44408836cd2cb3ff8b02dce3497a41aae9b12b Mon Sep 17 00:00:00 2001 From: Adrien1106 Date: Tue, 16 Apr 2024 19:20:52 +0200 Subject: [PATCH 3/3] Updated to v1.5.8 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index f8ef931..c49b920 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ loader_version=0.15.6 # Mod Properties modrinth_id = jCpoCBpn -mod_version = 1.5.7 +mod_version = 1.5.8 maven_group = fr.adrien1106 archives_base_name = ReFramed mod_id = reframed