-
Notifications
You must be signed in to change notification settings - Fork 51
Fix some issues with the 1.19 version of CTM #204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,13 +19,14 @@ | |
import net.minecraft.core.Direction; | ||
import net.minecraft.util.RandomSource; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraftforge.client.ChunkRenderTypeSet; | ||
import net.minecraftforge.client.model.data.ModelData; | ||
import net.minecraftforge.common.util.Lazy; | ||
import team.chisel.ctm.api.model.IModelCTM; | ||
import team.chisel.ctm.api.texture.ICTMTexture; | ||
import team.chisel.ctm.api.texture.ITextureContext; | ||
import team.chisel.ctm.api.util.RenderContextList; | ||
import team.chisel.ctm.client.util.BakedQuadRetextured; | ||
import team.chisel.ctm.client.util.CTMPackReloadListener; | ||
|
||
@ParametersAreNonnullByDefault | ||
public class ModelBakedCTM extends AbstractCTMBakedModel { | ||
|
@@ -42,6 +43,9 @@ protected AbstractCTMBakedModel createModel(@Nullable BlockState state, IModelCT | |
parent = castParent.getParent(rand); | ||
} | ||
|
||
BakedModel finalParent = parent; | ||
//Only use this if state is not null | ||
Lazy<ChunkRenderTypeSet> lazyParentTypes = Lazy.of(() -> finalParent.getRenderTypes(state, rand, data)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a benefit in this being lazily calculated? Is there a situation in which it fails or takes an inordinate amount of time to calculate? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There should not be any cases where this fails, but depending on how mods implement things in custom models there is a chance that this might be expensive if calling for every quad as depending on the implementation there is a good chance the other mod doesn't cache their returned result and instead calculates it every single time. Now are those models also used in combination with CTM I have no idea but I figured better safe than sorry. |
||
AbstractCTMBakedModel ret = new ModelBakedCTM(model, parent, layer); | ||
for (Direction facing : FACINGS) { | ||
List<BakedQuad> parentQuads = parent.getQuads(state, facing, rand, data, null); // NOTE: We pass null here so that all quads are always returned, layer filtering is done below | ||
|
@@ -77,10 +81,11 @@ protected AbstractCTMBakedModel createModel(@Nullable BlockState state, IModelCT | |
// Explore optimizations to quad goal (detecting overlaps??) | ||
int quadGoal = ctx == null ? 1 : texturemap.values().stream().mapToInt(tex -> tex.getType().getQuadsPerSide()).max().orElse(1); | ||
for (Entry<BakedQuad, ICTMTexture<?>> e : texturemap.entrySet()) { | ||
ICTMTexture<?> texture = e.getValue(); | ||
// If the layer is null, this is a wrapped vanilla texture, so passthrough the layer check to the block | ||
if (layer == null || (e.getValue().getLayer() != null && e.getValue().getLayer().getRenderType() == layer) || (e.getValue().getLayer() == null && (state == null || CTMPackReloadListener.canRenderInLayerFallback(state, layer)))) { | ||
ITextureContext tcx = ctx == null ? null : ctx.getRenderContext(e.getValue()); | ||
quads.addAll(e.getValue().transformQuad(e.getKey(), tcx, quadGoal)); | ||
if (layer == null || (texture.getLayer() != null && texture.getLayer().getRenderType() == layer) || (texture.getLayer() == null && (state == null || lazyParentTypes.get().contains(layer)))) { | ||
ITextureContext tcx = ctx == null ? null : ctx.getRenderContext(texture); | ||
quads.addAll(texture.transformQuad(e.getKey(), tcx, quadGoal)); | ||
} | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
import java.io.IOException; | ||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
|
@@ -66,7 +67,9 @@ public class ModelCTM implements IModelCTM { | |
protected Map<Pair<Integer, ResourceLocation>, ICTMTexture<?>> textureOverrides; | ||
|
||
private final Collection<ResourceLocation> textureDependencies; | ||
|
||
|
||
private final Set<RenderType> extraLayers = new HashSet<>(); | ||
private final Set<RenderType> extraLayersView = Collections.unmodifiableSet(extraLayers); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a purpose to keeping the old byte field? It was an optimization over exactly this sort of data structure, but since canRenderInLayer is no longer used... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mainly because I was unsure about how the implementation to if (getExtraLayers(state).contains(layer)) {
return true;
}
BakedModel bakedModel = Minecraft.getInstance().getModelManager().getBlockModelShaper().getBlockModel(state);
return bakedModel.getRenderTypes(state, RandomSource.create(42), ModelData.EMPTY).contains(layer); and that way it would at least be returning mostly accurate results (in theory replacing the byte with a boolean so that it can keep track of if there are some layers with no custom render lay would make it even more accurate but probably isn't needed. Would you like me to make the proposed change to the implementation of |
||
private transient byte layers; | ||
|
||
private Map<ResourceLocation, ICTMTexture<?>> textures = new HashMap<>(); | ||
|
@@ -162,7 +165,13 @@ public void initializeTextures(ModelBakery bakery, Function<Material, TextureAtl | |
} else { | ||
tex = meta.get().makeTexture(sprite, spriteGetter); | ||
} | ||
layers |= 1 << (tex.getLayer() == null ? 7 : tex.getLayer().ordinal()); | ||
BlockRenderLayer renderLayer = tex.getLayer(); | ||
if (renderLayer != null) { | ||
extraLayers.add(renderLayer.getRenderType()); | ||
layers |= 1 << renderLayer.ordinal(); | ||
} else { | ||
layers |= 1 << 7; | ||
} | ||
return tex; | ||
}); | ||
} | ||
|
@@ -190,7 +199,13 @@ public void initializeTextures(ModelBakery bakery, Function<Material, TextureAtl | |
sprite = spriteGetter.apply(new Material(TextureAtlas.LOCATION_BLOCKS, texLoc)); | ||
} | ||
ICTMTexture<?> tex = e.getValue().makeTexture(sprite, spriteGetter); | ||
layers |= 1 << (tex.getLayer() == null ? 7 : tex.getLayer().ordinal()); | ||
BlockRenderLayer renderLayer = tex.getLayer(); | ||
if (renderLayer != null) { | ||
extraLayers.add(renderLayer.getRenderType()); | ||
layers |= 1 << renderLayer.ordinal(); | ||
} else { | ||
layers |= 1 << 7; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This identical code should be extracted to a helper |
||
textureOverrides.put(Pair.of(e.getIntKey(), texLoc), tex); | ||
} | ||
} | ||
|
@@ -216,6 +231,11 @@ public boolean canRenderInLayer(BlockState state, RenderType layer) { | |
return (layers < 0 && CTMPackReloadListener.canRenderInLayerFallback(state, layer)) || ((layers >> BlockRenderLayer.fromType(layer).ordinal()) & 1) == 1; | ||
} | ||
|
||
@Override | ||
public Set<RenderType> getExtraLayers(BlockState state) { | ||
return extraLayersView; | ||
} | ||
|
||
@Override | ||
@Nullable | ||
public TextureAtlasSprite getOverrideSprite(int tintIndex) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should
canRenderInLayer
be deprecated?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe so, in fact I think it should be deprecated as for removal, but I held off on it as I figured it could be addressed when the question I asked in the PR description about defaulting the new
getExtraLayers
method and also how you want to handle breaking changes. There is also the fact that it returns a faulty value for purposes of things like sugar cane in your test pack ascanRenderInLayer
returns true for solid there.