more poking, deprecate a RetexturingBakedModel method

This commit is contained in:
quat1024 2023-08-31 21:47:00 -04:00
parent 11e24ef876
commit a58562c8a0
6 changed files with 19 additions and 17 deletions

View File

@ -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:

View File

@ -3,4 +3,4 @@ org.gradle.jvmargs=-Xmx6G
archivesBaseName=templates
group=io.github.cottonmc
version=2.1.2+1.20.1
version=2.2.0+1.20.1

View File

@ -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<TemplateEntity> TEMPLATE_BLOCK_ENTITY = Registry.register(
Registries.BLOCK_ENTITY_TYPE, id("slope"),
FabricBlockEntityTypeBuilder.create(Templates::makeTemplateBlockEntity,

View File

@ -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);
}
}

View File

@ -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);
}

View File

@ -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<CacheKey, Mesh> retexturedMeshes = new ConcurrentHashMap<>(); //mutable, append-only cache
protected final ConcurrentMap<CacheKey, Mesh> 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;