From a981cd28c28396b9209f3551fb3164950e5a538f Mon Sep 17 00:00:00 2001 From: quat1024 Date: Tue, 4 Jul 2023 03:15:46 -0400 Subject: [PATCH] Hardcode the particle The default texture is hardcoded and making that settable per-block would be a big pain. Just hardcode it. --- README.md | 6 ++---- .../cottonmc/templates/api/TemplateInteractionUtil.java | 2 +- .../templates/model/RetexturedJsonModelBakedModel.java | 5 +++++ .../templates/model/RetexturedMeshBakedModel.java | 5 +++++ .../templates/model/TemplateAppearanceManager.java | 8 +++----- .../resources/assets/templates/models/block/cube.json | 3 +-- .../assets/templates/models/block/slab_bottom.json | 3 +-- .../resources/assets/templates/models/block/slab_top.json | 3 +-- .../assets/templates/models/block/slope_base.json | 3 --- 9 files changed, 19 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index d15d917..5ec8891 100644 --- a/README.md +++ b/README.md @@ -51,9 +51,7 @@ If possible, I don't recommend making a wholly *new* json model. If you have an "north": "templates:templates_special/north", "south": "templates:templates_special/south", "west": "templates:templates_special/west", - "east": "templates:templates_special/east", - - "particle": "minecraft:block/scaffolding_top" + "east": "templates:templates_special/east" } } ``` @@ -70,7 +68,7 @@ If you have a shape in mind that can't be represented with a json model (like a We will construct a `RetexturedMeshUnbakedModel`. You need two things - the ID of a parent model, and a `Supplier<>` of a `Mesh` to retexture. -Ideally, the parent model should have a parent of `block/block`, or at least define *some* non-default rotations (smokey the bear voice *Only You Can Prevent Weirdly Rotated First-Person Models*), set `"gui_light": "front"` (lest the item model look weird), and define a particle texture. You should use a json model for this, but keep in mind that no quads will be read from the json model - it's only used to source all the miscellaneous `BakedModel` options. +Ideally, the parent model should have a parent of `block/block`, or at least define *some* non-default rotations (smokey the bear voice *Only You Can Prevent Weirdly Rotated First-Person Models*) and set `"gui_light": "front"` (lest the item model look weird). You should use a json model for this, but keep in mind that no quads will be read from the json model - it's only used to source all the miscellaneous `BakedModel` options. When building the `Mesh`, if you want a face to be dynamically retextured, `.tag()` it with the `.ordinal() + 1` of the `Direction` it corresponds to, and give the face UV coordinates ranging from 0 to 1. (For example, if you tag a face with `3` (`Direction.NORTH.ordinal() + 1`), it will be retextured to the north side of the template's theme.) diff --git a/src/main/java/io/github/cottonmc/templates/api/TemplateInteractionUtil.java b/src/main/java/io/github/cottonmc/templates/api/TemplateInteractionUtil.java index c746b9a..e62ea53 100644 --- a/src/main/java/io/github/cottonmc/templates/api/TemplateInteractionUtil.java +++ b/src/main/java/io/github/cottonmc/templates/api/TemplateInteractionUtil.java @@ -90,7 +90,7 @@ public class TemplateInteractionUtil { .with(REDSTONE, be.hasSpentRedstoneTorch() || placementState.getWeakRedstonePower(world, pos, Direction.NORTH) != 0)); if(!player.isCreative()) held.decrement(1); - world.playSound(player, pos, state.getSoundGroup().getPlaceSound(), SoundCategory.BLOCKS, 1f, 1f); + world.playSound(player, pos, placementState.getSoundGroup().getPlaceSound(), SoundCategory.BLOCKS, 1f, 1.1f); return ActionResult.SUCCESS; } } diff --git a/src/main/java/io/github/cottonmc/templates/model/RetexturedJsonModelBakedModel.java b/src/main/java/io/github/cottonmc/templates/model/RetexturedJsonModelBakedModel.java index 33a27f3..f3b5964 100644 --- a/src/main/java/io/github/cottonmc/templates/model/RetexturedJsonModelBakedModel.java +++ b/src/main/java/io/github/cottonmc/templates/model/RetexturedJsonModelBakedModel.java @@ -83,6 +83,11 @@ public class RetexturedJsonModelBakedModel extends ForwardingBakedModel { context.meshConsumer().accept(meshCache.computeIfAbsent(key, this::makeMesh)); } + @Override + public Sprite getParticleSprite() { + return tam.getDefaultAppearance().getParticleSprite(); + } + protected Mesh makeMesh(CacheKey key) { Renderer r = TemplatesClient.getFabricRenderer(); MeshBuilder builder = r.meshBuilder(); diff --git a/src/main/java/io/github/cottonmc/templates/model/RetexturedMeshBakedModel.java b/src/main/java/io/github/cottonmc/templates/model/RetexturedMeshBakedModel.java index 18be0ce..71ba545 100644 --- a/src/main/java/io/github/cottonmc/templates/model/RetexturedMeshBakedModel.java +++ b/src/main/java/io/github/cottonmc/templates/model/RetexturedMeshBakedModel.java @@ -56,6 +56,11 @@ public final class RetexturedMeshBakedModel extends ForwardingBakedModel { context.popTransform(); } + @Override + public Sprite getParticleSprite() { + return tam.getDefaultAppearance().getParticleSprite(); + } + public @NotNull RenderContext.QuadTransform retexturingBlockTransformer(BlockRenderView blockView, BlockState state, BlockPos pos, Supplier randomSupplier) { BlockState theme = (((RenderAttachedBlockView) blockView).getBlockEntityRenderAttachment(pos) instanceof BlockState s) ? s : null; if(theme == null || theme.isAir()) return new RetexturingTransformer(tam.getDefaultAppearance(), 0xFFFFFFFF, facePermutation); diff --git a/src/main/java/io/github/cottonmc/templates/model/TemplateAppearanceManager.java b/src/main/java/io/github/cottonmc/templates/model/TemplateAppearanceManager.java index ff01967..db735fb 100644 --- a/src/main/java/io/github/cottonmc/templates/model/TemplateAppearanceManager.java +++ b/src/main/java/io/github/cottonmc/templates/model/TemplateAppearanceManager.java @@ -25,19 +25,17 @@ import java.util.function.Function; public class TemplateAppearanceManager { public TemplateAppearanceManager(Function spriteLookup) { - SpriteIdentifier defaultSpriteId = new SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, new Identifier("minecraft:block/scaffolding_top")); - Sprite defaultSprite = spriteLookup.apply(defaultSpriteId); - if(defaultSprite == null) throw new IllegalStateException("Couldn't locate " + defaultSpriteId + " !"); - MaterialFinder finder = TemplatesClient.getFabricRenderer().materialFinder(); - for(BlendMode blend : BlendMode.values()) { blockMaterials.put(blend, finder.clear().disableDiffuse(false).ambientOcclusion(TriState.FALSE).blendMode(blend).find()); } + Sprite defaultSprite = spriteLookup.apply(DEFAULT_SPRITE_ID); + if(defaultSprite == null) throw new IllegalStateException("Couldn't locate " + DEFAULT_SPRITE_ID + " !"); this.defaultAppearance = new SingleSpriteAppearance(defaultSprite, blockMaterials.get(BlendMode.CUTOUT)); } + public static final SpriteIdentifier DEFAULT_SPRITE_ID = new SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, new Identifier("minecraft:block/scaffolding_top")); private final TemplateAppearance defaultAppearance; //Mutable, append-only cache: diff --git a/src/main/resources/assets/templates/models/block/cube.json b/src/main/resources/assets/templates/models/block/cube.json index ae7024a..5a4cec8 100644 --- a/src/main/resources/assets/templates/models/block/cube.json +++ b/src/main/resources/assets/templates/models/block/cube.json @@ -6,7 +6,6 @@ "north": "templates:templates_special/north", "south": "templates:templates_special/south", "west": "templates:templates_special/west", - "east": "templates:templates_special/east", - "particle": "minecraft:block/scaffolding_top" + "east": "templates:templates_special/east" } } \ No newline at end of file diff --git a/src/main/resources/assets/templates/models/block/slab_bottom.json b/src/main/resources/assets/templates/models/block/slab_bottom.json index 453fb66..6263a74 100644 --- a/src/main/resources/assets/templates/models/block/slab_bottom.json +++ b/src/main/resources/assets/templates/models/block/slab_bottom.json @@ -6,8 +6,7 @@ "north": "templates:templates_special/north", "south": "templates:templates_special/south", "west": "templates:templates_special/west", - "east": "templates:templates_special/east", - "particle": "minecraft:block/scaffolding_top" + "east": "templates:templates_special/east" }, "elements": [ { diff --git a/src/main/resources/assets/templates/models/block/slab_top.json b/src/main/resources/assets/templates/models/block/slab_top.json index 0bea2d9..bed7609 100644 --- a/src/main/resources/assets/templates/models/block/slab_top.json +++ b/src/main/resources/assets/templates/models/block/slab_top.json @@ -6,8 +6,7 @@ "north": "templates:templates_special/north", "south": "templates:templates_special/south", "west": "templates:templates_special/west", - "east": "templates:templates_special/east", - "particle": "minecraft:block/scaffolding_top" + "east": "templates:templates_special/east" }, "elements": [ { diff --git a/src/main/resources/assets/templates/models/block/slope_base.json b/src/main/resources/assets/templates/models/block/slope_base.json index 7936f14..72a5a34 100644 --- a/src/main/resources/assets/templates/models/block/slope_base.json +++ b/src/main/resources/assets/templates/models/block/slope_base.json @@ -1,9 +1,6 @@ { "parent": "minecraft:block/block", "gui_light": "front", - "textures": { - "particle": "minecraft:block/scaffolding_top" - }, "display": { "firstperson_righthand": { "rotation": [ 0, 135, 0 ],