From a58562c8a04736565b019917d220225ccaa425ae Mon Sep 17 00:00:00 2001 From: quat1024 Date: Thu, 31 Aug 2023 21:47:00 -0400 Subject: [PATCH] more poking, deprecate a RetexturingBakedModel method --- CHANGELOG.md | 3 ++- gradle.properties | 2 +- .../github/cottonmc/templates/Templates.java | 2 +- .../templates/TemplatesModelProvider.java | 5 ++--- .../templates/block/TemplateEntity.java | 4 +++- .../model/RetexturingBakedModel.java | 20 +++++++++---------- 6 files changed, 19 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b3f613..8ecebee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,9 @@ Versions before 2.1.2 have been backfilled; I gotta be more on top of changelogs. -# 2.1.2 (unreleased) +# next version (unreleased) * Remove some unused stuff from the jar +* Code cleanups, hopefully without breaking ABI compat (i don't have an ABI checker in the pipeline tho) road map: diff --git a/gradle.properties b/gradle.properties index 409437e..2a2f2f8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,4 +3,4 @@ org.gradle.jvmargs=-Xmx6G archivesBaseName=templates group=io.github.cottonmc -version=2.1.2+1.20.1 \ No newline at end of file +version=2.2.0+1.20.1 \ No newline at end of file diff --git a/src/main/java/io/github/cottonmc/templates/Templates.java b/src/main/java/io/github/cottonmc/templates/Templates.java index 031b8bd..53f4a3e 100644 --- a/src/main/java/io/github/cottonmc/templates/Templates.java +++ b/src/main/java/io/github/cottonmc/templates/Templates.java @@ -90,7 +90,7 @@ public class Templates implements ModInitializer { }); //For addon devs: Just make your own BlockEntityType instead of trying to add more blocks to this one. - //You can even reuse the same TemplateEntity class. + //You can even re-register the same TemplateEntity class if you like. It's an extensible block entity. public static final BlockEntityType TEMPLATE_BLOCK_ENTITY = Registry.register( Registries.BLOCK_ENTITY_TYPE, id("slope"), FabricBlockEntityTypeBuilder.create(Templates::makeTemplateBlockEntity, diff --git a/src/main/java/io/github/cottonmc/templates/TemplatesModelProvider.java b/src/main/java/io/github/cottonmc/templates/TemplatesModelProvider.java index 8e39e76..1d2d775 100644 --- a/src/main/java/io/github/cottonmc/templates/TemplatesModelProvider.java +++ b/src/main/java/io/github/cottonmc/templates/TemplatesModelProvider.java @@ -36,8 +36,7 @@ public class TemplatesModelProvider implements ModelResourceProvider, ModelVaria //Item models don't have that layer of indirection; it always wants to load the hardcoded "item:id#inventory" model. //You *would* be able to create a model json for it and set the "parent" field to the custom model, //but json models are never allowed to have non-json models as a parent, and template unbaked models are not json models. Ah well. - //So, instead, we use a ModelVariantProvider to clunkily redirect the item:id#inventory model to the blockmodel. - //Not my favorite solution but we'll live. + //So, instead, we use a ModelVariantProvider to redirect attempts to load the item:id#inventory model. @Override public @Nullable UnbakedModel loadModelVariant(ModelIdentifier modelId, ModelProviderContext context) { Identifier customModelId = itemAssignments.get(modelId); @@ -61,7 +60,7 @@ public class TemplatesModelProvider implements ModelResourceProvider, ModelVaria //while we were waiting for it, so we do another volatile field read (the "double check"): read = appearanceManager; if(read == null) { - //If no-one has initialized it still, I guess we should do it + //If no-one has initialized it still, I guess it falls to us read = appearanceManager = new TemplateAppearanceManager(spriteLookup); } } diff --git a/src/main/java/io/github/cottonmc/templates/block/TemplateEntity.java b/src/main/java/io/github/cottonmc/templates/block/TemplateEntity.java index 3627a45..ec7f420 100644 --- a/src/main/java/io/github/cottonmc/templates/block/TemplateEntity.java +++ b/src/main/java/io/github/cottonmc/templates/block/TemplateEntity.java @@ -23,6 +23,9 @@ import org.jetbrains.annotations.Nullable; import javax.annotation.Nonnull; import java.util.Objects; +//Keeping the weight of this block entity down, both in terms of memory consumption and NBT sync traffic, +//is pretty important since players might place a lot of them. There were tons and tons of these at Blanketcon. +//To that end, most of the state has been crammed into a bitfield. public class TemplateEntity extends BlockEntity implements ThemeableBlockEntity { protected BlockState renderedState = Blocks.AIR.getDefaultState(); protected byte bitfield = DEFAULT_BITFIELD; @@ -64,7 +67,6 @@ public class TemplateEntity extends BlockEntity implements ThemeableBlockEntity } //Force a chunk remesh on the client if the displayed blockstate has changed - //TODO: doors? (need remeshing when the *other* party changes) if(world != null && world.isClient && !Objects.equals(lastRenderedState, renderedState)) { Templates.chunkRerenderProxy.accept(world, pos); } 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 425d0f6..93a71f1 100644 --- a/src/main/java/io/github/cottonmc/templates/model/RetexturingBakedModel.java +++ b/src/main/java/io/github/cottonmc/templates/model/RetexturingBakedModel.java @@ -25,13 +25,13 @@ import java.util.concurrent.ConcurrentMap; import java.util.function.Supplier; public abstract class RetexturingBakedModel extends ForwardingBakedModel { - @Deprecated(forRemoval = true) //binary-compat from before there was an AO boolean + @Deprecated(forRemoval = true) //Kept for ABI compat. From before there was an AO boolean (<2.1.1) public RetexturingBakedModel(BakedModel baseModel, TemplateAppearanceManager tam, ModelBakeSettings settings, BlockState itemModelState) { this(baseModel, tam, settings, itemModelState, true); } public RetexturingBakedModel(BakedModel baseModel, TemplateAppearanceManager tam, ModelBakeSettings settings, BlockState itemModelState, boolean ao) { - this.wrapped = baseModel; + this.wrapped = baseModel; //field from the superclass; vanilla getQuads etc will delegate through to this this.tam = tam; this.facePermutation = MeshTransformUtil.facePermutation(settings); @@ -47,7 +47,7 @@ public abstract class RetexturingBakedModel extends ForwardingBakedModel { protected final boolean ao; protected record CacheKey(BlockState state, TemplateAppearance appearance) {} - private final ConcurrentMap retexturedMeshes = new ConcurrentHashMap<>(); //mutable, append-only cache + protected final ConcurrentMap retexturedMeshes = new ConcurrentHashMap<>(); //mutable, append-only cache protected static final Direction[] DIRECTIONS = Direction.values(); protected static final Direction[] DIRECTIONS_AND_NULL = new Direction[DIRECTIONS.length + 1]; @@ -123,18 +123,20 @@ public abstract class RetexturingBakedModel extends ForwardingBakedModel { } protected Mesh createUntintedRetexturedMesh(CacheKey key) { - return MeshTransformUtil.pretransformMesh(getBaseMesh(key.state), new RetexturingTransformer(key.appearance, 0xFFFFFFFF)); + return MeshTransformUtil.pretransformMesh(getBaseMesh(key.state), new RetexturingTransformer(key.appearance)); } protected class RetexturingTransformer implements RenderContext.QuadTransform { - //TODO: remove the "tint" parameter, it's been kicked to TintingTransformer - protected RetexturingTransformer(TemplateAppearance ta, int tint) { + protected RetexturingTransformer(TemplateAppearance ta) { this.ta = ta; - this.tint = tint; + } + + @Deprecated(forRemoval = true) //Kept for ABI compat (<2.2). Use TintingTransformer for retinting, it works better anyway + protected RetexturingTransformer(TemplateAppearance ta, int ignoredTint) { + this(ta); } protected final TemplateAppearance ta; - protected final int tint; @Override public boolean transform(MutableQuadView quad) { @@ -145,8 +147,6 @@ public abstract class RetexturingBakedModel extends ForwardingBakedModel { //The quad tag numbers were selected so this magic trick works: Direction dir = facePermutation.get(DIRECTIONS[quad.tag() - 1]); - if(ta.hasColor(dir)) quad.color(tint, tint, tint, tint); - quad.spriteBake(ta.getSprite(dir), MutableQuadView.BAKE_NORMALIZED | ta.getBakeFlags(dir) | (uvlock ? MutableQuadView.BAKE_LOCK_UV : 0)); return true;