From 11e24ef8762985c82a41e9c39f907880be023471 Mon Sep 17 00:00:00 2001 From: quat1024 Date: Thu, 31 Aug 2023 21:27:02 -0400 Subject: [PATCH] code cleanups (great way to feel productive without doing much of anything) --- CHANGELOG.md | 48 +++++++++++++++++++ build.gradle | 8 ---- gradle.properties | 6 ++- .../cottonmc/templates/TemplatesClient.java | 3 +- .../templates/TemplatesModelProvider.java | 1 + .../block/TemplateVerticalSlabBlock.java | 3 +- .../templates/block/TemplateWallBlock.java | 6 +-- .../mixin/particles/AccessorParticle.java | 3 -- .../templates/model/MeshTransformUtil.java | 4 +- .../model/RetexturingBakedModel.java | 5 +- .../model/TemplateAppearanceManager.java | 9 +--- .../templates/util/StairShapeMaker.java | 1 + .../util => unused}/BbModelepic.java | 0 .../util => unused}/TattletaleRandom.java | 0 14 files changed, 67 insertions(+), 30 deletions(-) create mode 100644 CHANGELOG.md rename {src/main/java/io/github/cottonmc/templates/util => unused}/BbModelepic.java (100%) rename {src/main/java/io/github/cottonmc/templates/util => unused}/TattletaleRandom.java (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..1b3f613 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,48 @@ +Versions before 2.1.2 have been backfilled; I gotta be more on top of changelogs. + +# 2.1.2 (unreleased) + +* Remove some unused stuff from the jar + +road map: + +* want to fix texture orientation on vertical slabs/doors +* really want to fix the way vertical slabs place lmao (it's so buggy) +* clean up `StairShapeMaker` + +# 2.1.1 (Aug 2, 2023) + +Enable ambient-occlusion ("smooth lighting") on all Templates except for the slopes, which are still bugged + +# 2.1.0 (Jul 31, 2023) + +* Add a vertical slab template +* Add a "tiny slope" template +* Change the block entity NBT format to be much smaller +* Reduce memory footprint of the block entity +* Respect `doTileDrops` +* Improve creative ctrl-pick behavior on glowing Templates +* Adding a Barrier block to a Template makes it remove its model (not unbreakable) + +# 2.0.4 (Jul 25, 2023) + +* Apply more block tags +* Apply item tags + +# 2.0.3 (Jul 23, 2023) + +* add Door and Iron Door templates +* cool rivulet + +# 2.0.2 (Jul 20, 2023) + +* Add an Iron Trapdoor template +* Add some more mod metadata (change name to "Templates 2", add authors, fix sources link) + +# 2.0.1 (Jul 11, 2023) + +Fix a duplication glitch with the Stair Template, which was retaining its block entity after being broken. + +# 2.0.0 (Jul 11, 2023) + +Initial release \ No newline at end of file diff --git a/build.gradle b/build.gradle index 5de077a..f1aa739 100755 --- a/build.gradle +++ b/build.gradle @@ -24,14 +24,6 @@ tasks.withType(JavaCompile) { options.release = 17 } -if(rootProject.file("private.gradle").exists()) { //Publishing details - apply from: "private.gradle" -} - -archivesBaseName = "templates" -group = "io.github.cottonmc" -version = "2.1.1+1.20.1" - repositories { mavenCentral() diff --git a/gradle.properties b/gradle.properties index 100ffa6..409437e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,6 @@ # dedodated wam -org.gradle.jvmargs=-Xmx6G \ No newline at end of file +org.gradle.jvmargs=-Xmx6G + +archivesBaseName=templates +group=io.github.cottonmc +version=2.1.2+1.20.1 \ No newline at end of file diff --git a/src/main/java/io/github/cottonmc/templates/TemplatesClient.java b/src/main/java/io/github/cottonmc/templates/TemplatesClient.java index 3d75250..4a41c00 100644 --- a/src/main/java/io/github/cottonmc/templates/TemplatesClient.java +++ b/src/main/java/io/github/cottonmc/templates/TemplatesClient.java @@ -22,7 +22,8 @@ import org.jetbrains.annotations.NotNull; import java.util.Objects; public class TemplatesClient implements ClientModInitializer { - public static TemplatesModelProvider provider = new TemplatesModelProvider(); + //2.2 note: Yes, this wasn't final before, but it should have been + public static final TemplatesModelProvider provider = new TemplatesModelProvider(); public static @NotNull Renderer getFabricRenderer() { return Objects.requireNonNull(RendererAccess.INSTANCE.getRenderer(), "A Fabric Rendering API implementation is required to use Templates!"); diff --git a/src/main/java/io/github/cottonmc/templates/TemplatesModelProvider.java b/src/main/java/io/github/cottonmc/templates/TemplatesModelProvider.java index db7bac6..8e39e76 100644 --- a/src/main/java/io/github/cottonmc/templates/TemplatesModelProvider.java +++ b/src/main/java/io/github/cottonmc/templates/TemplatesModelProvider.java @@ -18,6 +18,7 @@ import java.util.Map; import java.util.Objects; import java.util.function.Function; +@SuppressWarnings("unused") //part of the api public class TemplatesModelProvider implements ModelResourceProvider, ModelVariantProvider { private final Map models = new HashMap<>(); private final Map itemAssignments = new HashMap<>(); diff --git a/src/main/java/io/github/cottonmc/templates/block/TemplateVerticalSlabBlock.java b/src/main/java/io/github/cottonmc/templates/block/TemplateVerticalSlabBlock.java index 0361661..b4498ea 100644 --- a/src/main/java/io/github/cottonmc/templates/block/TemplateVerticalSlabBlock.java +++ b/src/main/java/io/github/cottonmc/templates/block/TemplateVerticalSlabBlock.java @@ -5,7 +5,6 @@ import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.ShapeContext; import net.minecraft.block.enums.SlabType; -import net.minecraft.fluid.FluidState; import net.minecraft.fluid.Fluids; import net.minecraft.item.ItemPlacementContext; import net.minecraft.item.ItemStack; @@ -108,7 +107,7 @@ public class TemplateVerticalSlabBlock extends TemplateSlabBlock { } } - enum Affinity implements StringIdentifiable { + protected enum Affinity implements StringIdentifiable { X, Z; @Override diff --git a/src/main/java/io/github/cottonmc/templates/block/TemplateWallBlock.java b/src/main/java/io/github/cottonmc/templates/block/TemplateWallBlock.java index 12c4ce1..0023014 100644 --- a/src/main/java/io/github/cottonmc/templates/block/TemplateWallBlock.java +++ b/src/main/java/io/github/cottonmc/templates/block/TemplateWallBlock.java @@ -100,7 +100,7 @@ public class TemplateWallBlock extends WallBlock implements BlockEntityProvider //Shapemap heck (WallBlock has a map keyed on BlockState, but since we add more blockstates most of those map lookups fail) - protected static record ShapeKey(boolean up, WallShape north, WallShape east, WallShape south, WallShape west) { + protected record ShapeKey(boolean up, WallShape north, WallShape east, WallShape south, WallShape west) { static ShapeKey fromBlockstate(BlockState state) { return new ShapeKey( state.get(WallBlock.UP), @@ -112,8 +112,8 @@ public class TemplateWallBlock extends WallBlock implements BlockEntityProvider } } - protected Map newShapeMap = new HashMap<>(); - protected Map newCollisionShapeMap = new HashMap<>(); + protected final Map newShapeMap = new HashMap<>(); + protected final Map newCollisionShapeMap = new HashMap<>(); protected void initNewShapemaps() { initNewShapemap(((WallBlockAccessor) this).templates$getShapeMap(), newShapeMap); diff --git a/src/main/java/io/github/cottonmc/templates/mixin/particles/AccessorParticle.java b/src/main/java/io/github/cottonmc/templates/mixin/particles/AccessorParticle.java index c9a1597..35a0ac1 100644 --- a/src/main/java/io/github/cottonmc/templates/mixin/particles/AccessorParticle.java +++ b/src/main/java/io/github/cottonmc/templates/mixin/particles/AccessorParticle.java @@ -9,10 +9,7 @@ import org.spongepowered.asm.mixin.gen.Accessor; public interface AccessorParticle { @Accessor("random") Random templates$getRandom(); - @Accessor("red") float templates$red(); @Accessor("red") void templates$setRed(float red); - @Accessor("green") float templates$green(); @Accessor("green") void templates$setGreen(float green); - @Accessor("blue") float templates$blue(); @Accessor("blue") void templates$setBlue(float blue); } diff --git a/src/main/java/io/github/cottonmc/templates/model/MeshTransformUtil.java b/src/main/java/io/github/cottonmc/templates/model/MeshTransformUtil.java index 52c3caf..fad2796 100644 --- a/src/main/java/io/github/cottonmc/templates/model/MeshTransformUtil.java +++ b/src/main/java/io/github/cottonmc/templates/model/MeshTransformUtil.java @@ -28,11 +28,11 @@ public class MeshTransformUtil { } //Hard to explain what this is for... - //Basically, the previous incarnation of this mod assembled the north/south/east/west faces all individually. + //Basically, Templates 1.x manually emitted the north/south/east/west faces all individually. //This means it was easy to get the orientation of the block correct - to popular the north face of the slope, look at //the north texture of the theme block. In this version, there is only *one* slope model that is dynamically rotated //to form the other possible orientations. If I populate the north face of the model using the north face of the theme, - //that model will then be rotated so it's no longer facing the right way. + //then rotate the model, it's no longer facing the right way. So I need to "un-rotate" the face assignments first. // //This seems to work, but I'm kinda surprised I don't need to invert the transformation here, which is a clue that //I don't really understand all the math, loool diff --git a/src/main/java/io/github/cottonmc/templates/model/RetexturingBakedModel.java b/src/main/java/io/github/cottonmc/templates/model/RetexturingBakedModel.java index c55a8c2..425d0f6 100644 --- a/src/main/java/io/github/cottonmc/templates/model/RetexturingBakedModel.java +++ b/src/main/java/io/github/cottonmc/templates/model/RetexturingBakedModel.java @@ -1,10 +1,8 @@ package io.github.cottonmc.templates.model; -import io.github.cottonmc.templates.TemplatesClient; import io.github.cottonmc.templates.block.TemplateEntity; import io.github.cottonmc.templates.mixin.MinecraftAccessor; import net.fabricmc.fabric.api.renderer.v1.mesh.Mesh; -import net.fabricmc.fabric.api.renderer.v1.mesh.MeshBuilder; import net.fabricmc.fabric.api.renderer.v1.mesh.MutableQuadView; import net.fabricmc.fabric.api.renderer.v1.model.ForwardingBakedModel; import net.fabricmc.fabric.api.renderer.v1.render.RenderContext; @@ -48,7 +46,7 @@ public abstract class RetexturingBakedModel extends ForwardingBakedModel { protected final BlockState itemModelState; protected final boolean ao; - private static record CacheKey(BlockState state, TemplateAppearance appearance) {} + protected record CacheKey(BlockState state, TemplateAppearance appearance) {} private final ConcurrentMap retexturedMeshes = new ConcurrentHashMap<>(); //mutable, append-only cache protected static final Direction[] DIRECTIONS = Direction.values(); @@ -129,6 +127,7 @@ public abstract class RetexturingBakedModel extends ForwardingBakedModel { } protected class RetexturingTransformer implements RenderContext.QuadTransform { + //TODO: remove the "tint" parameter, it's been kicked to TintingTransformer protected RetexturingTransformer(TemplateAppearance ta, int tint) { this.ta = ta; this.tint = tint; 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 6a1d8f0..a05c555 100644 --- a/src/main/java/io/github/cottonmc/templates/model/TemplateAppearanceManager.java +++ b/src/main/java/io/github/cottonmc/templates/model/TemplateAppearanceManager.java @@ -1,7 +1,6 @@ package io.github.cottonmc.templates.model; import io.github.cottonmc.templates.TemplatesClient; -import io.github.cottonmc.templates.util.TattletaleRandom; import net.fabricmc.fabric.api.renderer.v1.material.BlendMode; import net.fabricmc.fabric.api.renderer.v1.material.MaterialFinder; import net.fabricmc.fabric.api.renderer.v1.material.RenderMaterial; @@ -83,7 +82,7 @@ public class TemplateAppearanceManager { private TemplateAppearance computeAppearance(BlockState state) { if(state.getBlock() == Blocks.BARRIER) return barrierItemAppearance; - TattletaleRandom rand = new TattletaleRandom(Random.create()); + Random rand = Random.create(42); BakedModel model = MinecraftClient.getInstance().getBlockRenderManager().getModel(state); //Only for parsing vanilla quads: @@ -102,7 +101,7 @@ public class TemplateAppearanceManager { BakedQuad arbitraryQuad = sideQuads.get(0); //TODO: maybe pick a largest quad instead? if(arbitraryQuad == null) continue; - if(arbitraryQuad.hasColor()) hasColorMask |= (1 << dir.ordinal()); + if(arbitraryQuad.hasColor()) hasColorMask |= (byte) (1 << dir.ordinal()); Sprite sprite = arbitraryQuad.getSprite(); if(sprite == null) continue; @@ -151,10 +150,6 @@ public class TemplateAppearanceManager { if(sprites[i] == null) sprites[i] = defaultAppearance.getParticleSprite(); } - if(rand.wasUsed) { - //System.err.println("State " + state + " makes use of a randomized model"); - } - return new ComputedApperance( sprites, bakeFlags, diff --git a/src/main/java/io/github/cottonmc/templates/util/StairShapeMaker.java b/src/main/java/io/github/cottonmc/templates/util/StairShapeMaker.java index 910762a..e6d6669 100644 --- a/src/main/java/io/github/cottonmc/templates/util/StairShapeMaker.java +++ b/src/main/java/io/github/cottonmc/templates/util/StairShapeMaker.java @@ -5,6 +5,7 @@ import net.minecraft.util.shape.VoxelShapes; import org.joml.Vector3d; public class StairShapeMaker { + //TODO: clean this the fuck up, maybe keep in mind that VoxelShapes can be rotated multiples of 90 degrees by just rotating their corners public static VoxelShape makeStair(Edge innerEdge, double stepIn, double initialStepRise, double stepRise, double stepRun, int stepCount) { Edge.CoordinateFrame frame = innerEdge.makeCoordinateFrame(); Vector3d origin = frame.origin(); diff --git a/src/main/java/io/github/cottonmc/templates/util/BbModelepic.java b/unused/BbModelepic.java similarity index 100% rename from src/main/java/io/github/cottonmc/templates/util/BbModelepic.java rename to unused/BbModelepic.java diff --git a/src/main/java/io/github/cottonmc/templates/util/TattletaleRandom.java b/unused/TattletaleRandom.java similarity index 100% rename from src/main/java/io/github/cottonmc/templates/util/TattletaleRandom.java rename to unused/TattletaleRandom.java