Skip to content

Commit

Permalink
Merge branch 'refs/heads/1.20.2/dev' into 1.20.5/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
PepperCode1 committed Jul 7, 2024
2 parents 4199527 + f1e06b8 commit 21174ac
Show file tree
Hide file tree
Showing 56 changed files with 515 additions and 391 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ yarn_mappings = 1.20.5+build.1
loader_version = 0.15.10

# Mod Properties
mod_version = 3.0.0-beta.5
mod_version = 3.0.0-beta.6
mod_minecraft_version = 1.20.5
maven_group = me.pepperbell
archives_base_name = continuity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import net.minecraft.world.BlockRenderView;

public interface QuadProcessor {
ProcessingResult processQuad(MutableQuadView quad, Sprite sprite, BlockRenderView blockView, BlockState state, BlockPos pos, Supplier<Random> randomSupplier, int pass, ProcessingContext context);
ProcessingResult processQuad(MutableQuadView quad, Sprite sprite, BlockRenderView blockView, BlockState appearanceState, BlockState state, BlockPos pos, Supplier<Random> randomSupplier, int pass, ProcessingContext context);

interface ProcessingContext extends ProcessingDataProvider {
void addEmitterConsumer(Consumer<QuadEmitter> consumer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ abstract class AtlasLoaderMixin {
Map<Identifier, Identifier> emissiveIdMap = new Object2ObjectOpenHashMap<>();
suppliers.forEach((id, supplier) -> {
if (!id.getPath().endsWith(emissiveSuffix)) {
Identifier emissiveId = new Identifier(id.getNamespace(), id.getPath() + emissiveSuffix);
Identifier emissiveId = id.withPath(id.getPath() + emissiveSuffix);
if (!suppliers.containsKey(emissiveId)) {
Identifier emissiveLocation = emissiveId.withPath("textures/" + emissiveId.getPath() + ".png");
Optional<Resource> optionalResource = resourceManager.getResource(emissiveLocation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.texture.Sprite;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.random.Random;
import net.minecraft.world.BlockRenderView;

Expand Down Expand Up @@ -47,7 +48,24 @@ public void emitBlockQuads(BlockRenderView blockView, BlockState state, BlockPos
return;
}

quadTransform.prepare(blockView, state, pos, randomSupplier, context, ContinuityConfig.INSTANCE.useManualCulling.get(), getSliceFunc(state));
// The correct way to get the appearance of the origin state from within a block model is to (1) call
// getAppearance on the result of blockView.getBlockState(pos) instead of the passed state and (2) pass the
// pos and world state of the adjacent block as the source pos and source state.
// (1) is not followed here because at this point in execution, within this call to
// CtmBakedModel#emitBlockQuads, the state parameter must already contain the world state. Even if this
// CtmBakedModel is wrapped, then the wrapper must pass the same state as it received because not doing so can
// cause crashes when the wrapped model is a vanilla multipart model or delegates to one. Thus, getting the
// world state again is inefficient and unnecessary.
// (2) is not possible here because the appearance state is necessary to get the slice and only the processors
// within the slice actually perform checks on adjacent blocks. Likewise, the processors themselves cannot
// retrieve the appearance state since the correct processors can only be chosen with the initially correct
// appearance state.
// Additionally, the side is chosen to always be the first constant of the enum (DOWN) for simplicity. Querying
// the appearance for all six sides would be more correct, but less efficient. This may be fixed in the future,
// especially if there is an actual use case for it.
BlockState appearanceState = state.getAppearance(blockView, pos, Direction.DOWN, state, pos);

quadTransform.prepare(blockView, appearanceState, state, pos, randomSupplier, context, ContinuityConfig.INSTANCE.useManualCulling.get(), getSliceFunc(appearanceState));

context.pushTransform(quadTransform);
super.emitBlockQuads(blockView, state, pos, randomSupplier, context);
Expand Down Expand Up @@ -86,6 +104,7 @@ protected static class CtmQuadTransform implements RenderContext.QuadTransform {
protected final ProcessingContextImpl processingContext = new ProcessingContextImpl();

protected BlockRenderView blockView;
protected BlockState appearanceState;
protected BlockState state;
protected BlockPos pos;
protected Supplier<Random> randomSupplier;
Expand Down Expand Up @@ -116,7 +135,7 @@ protected Boolean transformOnce(MutableQuadView quad, int pass) {
QuadProcessors.Slice slice = sliceFunc.apply(sprite);
QuadProcessor[] processors = pass == 0 ? slice.processors() : slice.multipassProcessors();
for (QuadProcessor processor : processors) {
QuadProcessor.ProcessingResult result = processor.processQuad(quad, sprite, blockView, state, pos, randomSupplier, pass, processingContext);
QuadProcessor.ProcessingResult result = processor.processQuad(quad, sprite, blockView, appearanceState, state, pos, randomSupplier, pass, processingContext);
if (result == QuadProcessor.ProcessingResult.NEXT_PROCESSOR) {
continue;
}
Expand All @@ -137,8 +156,9 @@ public boolean isActive() {
return active;
}

public void prepare(BlockRenderView blockView, BlockState state, BlockPos pos, Supplier<Random> randomSupplier, RenderContext renderContext, boolean useManualCulling, Function<Sprite, QuadProcessors.Slice> sliceFunc) {
public void prepare(BlockRenderView blockView, BlockState appearanceState, BlockState state, BlockPos pos, Supplier<Random> randomSupplier, RenderContext renderContext, boolean useManualCulling, Function<Sprite, QuadProcessors.Slice> sliceFunc) {
this.blockView = blockView;
this.appearanceState = appearanceState;
this.state = state;
this.pos = pos;
this.randomSupplier = randomSupplier;
Expand All @@ -153,6 +173,7 @@ public void prepare(BlockRenderView blockView, BlockState state, BlockPos pos, S

public void reset() {
blockView = null;
appearanceState = null;
state = null;
pos = null;
randomSupplier = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ public AbstractQuadProcessor(Sprite[] sprites, ProcessingPredicate processingPre
}

@Override
public ProcessingResult processQuad(MutableQuadView quad, Sprite sprite, BlockRenderView blockView, BlockState state, BlockPos pos, Supplier<Random> randomSupplier, int pass, ProcessingContext context) {
if (!processingPredicate.shouldProcessQuad(quad, sprite, blockView, state, pos, context)) {
public ProcessingResult processQuad(MutableQuadView quad, Sprite sprite, BlockRenderView blockView, BlockState appearanceState, BlockState state, BlockPos pos, Supplier<Random> randomSupplier, int pass, ProcessingContext context) {
if (!processingPredicate.shouldProcessQuad(quad, sprite, blockView, appearanceState, state, pos, context)) {
return ProcessingResult.NEXT_PROCESSOR;
}
return processQuadInner(quad, sprite, blockView, state, pos, randomSupplier, pass, context);
return processQuadInner(quad, sprite, blockView, appearanceState, state, pos, randomSupplier, pass, context);
}

public abstract ProcessingResult processQuadInner(MutableQuadView quad, Sprite sprite, BlockRenderView blockView, BlockState state, BlockPos pos, Supplier<Random> randomSupplier, int pass, ProcessingContext context);
public abstract ProcessingResult processQuadInner(MutableQuadView quad, Sprite sprite, BlockRenderView blockView, BlockState appearanceState, BlockState state, BlockPos pos, Supplier<Random> randomSupplier, int pass, ProcessingContext context);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public QuadProcessor createProcessor(T properties, Function<SpriteIdentifier, Sp
int max = provided;

if (provided > textureAmount) {
ContinuityClient.LOGGER.warn("Method '" + properties.getMethod() + "' requires " + textureAmount + " tiles but " + provided + " were provided in file '" + properties.getResourceId() + "' in pack '" + properties.getPackName() + "'");
ContinuityClient.LOGGER.warn("Method '" + properties.getMethod() + "' requires " + textureAmount + " tiles but " + provided + " were provided in file '" + properties.getResourceId() + "' in pack '" + properties.getPackId() + "'");
max = textureAmount;
}

Expand All @@ -40,7 +40,7 @@ public QuadProcessor createProcessor(T properties, Function<SpriteIdentifier, Sp
}

if (provided < textureAmount) {
ContinuityClient.LOGGER.error("Method '" + properties.getMethod() + "' requires " + textureAmount + " tiles but only " + provided + " were provided in file '" + properties.getResourceId() + "' in pack '" + properties.getPackName() + "'");
ContinuityClient.LOGGER.error("Method '" + properties.getMethod() + "' requires " + textureAmount + " tiles but only " + provided + " were provided in file '" + properties.getResourceId() + "' in pack '" + properties.getPackId() + "'");
for (int i = provided; i < textureAmount; i++) {
sprites[i] = missingSprite;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ public BaseProcessingPredicate(@Nullable EnumSet<Direction> faces, @Nullable Pre
}

@Override
public boolean shouldProcessQuad(QuadView quad, Sprite sprite, BlockRenderView blockView, BlockState state, BlockPos pos, ProcessingDataProvider dataProvider) {
public boolean shouldProcessQuad(QuadView quad, Sprite sprite, BlockRenderView blockView, BlockState appearanceState, BlockState state, BlockPos pos, ProcessingDataProvider dataProvider) {
if (heightPredicate != null) {
if (!heightPredicate.test(pos.getY())) {
return false;
}
}
if (faces != null) {
Direction face = quad.lightFace();
if (state.contains(Properties.AXIS)) {
Direction.Axis axis = state.get(Properties.AXIS);
if (appearanceState.contains(Properties.AXIS)) {
Direction.Axis axis = appearanceState.get(Properties.AXIS);
if (axis == Direction.Axis.X) {
face = face.rotateClockwise(Direction.Axis.Z);
} else if (axis == Direction.Axis.Z) {
Expand All @@ -59,13 +59,13 @@ public boolean shouldProcessQuad(QuadView quad, Sprite sprite, BlockRenderView b
}
}
if (biomePredicate != null) {
Biome biome = dataProvider.getData(ProcessingDataKeys.BIOME_CACHE_KEY).get(blockView, pos);
Biome biome = dataProvider.getData(ProcessingDataKeys.BIOME_CACHE).get(blockView, pos);
if (biome == null || !biomePredicate.test(biome)) {
return false;
}
}
if (blockEntityNamePredicate != null) {
String blockEntityName = dataProvider.getData(ProcessingDataKeys.BLOCK_ENTITY_NAME_CACHE_KEY).get(blockView, pos);
String blockEntityName = dataProvider.getData(ProcessingDataKeys.BLOCK_ENTITY_NAME_CACHE).get(blockView, pos);
if (blockEntityName == null || !blockEntityNamePredicate.test(blockEntityName)) {
return false;
}
Expand All @@ -78,6 +78,7 @@ public static BaseProcessingPredicate fromProperties(BaseCtmProperties propertie
}

public static class BiomeCache {
@Nullable
protected Biome biome;
protected boolean invalid = true;

Expand All @@ -96,6 +97,7 @@ public void reset() {
}

public static class BlockEntityNameCache {
@Nullable
protected String blockEntityName;
protected boolean invalid = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ public CompactCtmQuadProcessor(Sprite[] sprites, ProcessingPredicate processingP
}

@Override
public ProcessingResult processQuadInner(MutableQuadView quad, Sprite sprite, BlockRenderView blockView, BlockState state, BlockPos pos, Supplier<Random> randomSupplier, int pass, ProcessingContext context) {
int orientation = orientationMode.getOrientation(quad, state);
public ProcessingResult processQuadInner(MutableQuadView quad, Sprite sprite, BlockRenderView blockView, BlockState appearanceState, BlockState state, BlockPos pos, Supplier<Random> randomSupplier, int pass, ProcessingContext context) {
int orientation = orientationMode.getOrientation(quad, appearanceState);
Direction[] directions = DirectionMaps.getMap(quad.lightFace())[orientation];
BlockPos.Mutable mutablePos = context.getData(ProcessingDataKeys.MUTABLE_POS_KEY);
int connections = CtmSpriteProvider.getConnections(connectionPredicate, innerSeams, directions, mutablePos, blockView, state, pos, quad.lightFace(), sprite);
BlockPos.Mutable mutablePos = context.getData(ProcessingDataKeys.MUTABLE_POS);
int connections = CtmSpriteProvider.getConnections(directions, connectionPredicate, innerSeams, mutablePos, blockView, appearanceState, state, pos, quad.lightFace(), sprite);

//

Expand Down Expand Up @@ -156,7 +156,7 @@ public ProcessingResult processQuadInner(MutableQuadView quad, Sprite sprite, Bl
return ProcessingResult.STOP;
}

VertexContainer vertexContainer = context.getData(ProcessingDataKeys.VERTEX_CONTAINER_KEY);
VertexContainer vertexContainer = context.getData(ProcessingDataKeys.VERTEX_CONTAINER);
vertexContainer.fillBaseVertices(quad);

QuadEmitter extraQuadEmitter = context.getExtraQuadEmitter();
Expand Down Expand Up @@ -382,7 +382,7 @@ public ProcessingResult processQuadInner(MutableQuadView quad, Sprite sprite, Bl
spriteIndexB = temp;
}

VertexContainer vertexContainer = context.getData(ProcessingDataKeys.VERTEX_CONTAINER_KEY);
VertexContainer vertexContainer = context.getData(ProcessingDataKeys.VERTEX_CONTAINER);
vertexContainer.fillBaseVertices(quad);

QuadEmitter extraQuadEmitter = context.getExtraQuadEmitter();
Expand Down Expand Up @@ -627,17 +627,17 @@ public QuadProcessor createProcessor(CompactConnectingCtmProperties properties,
if (value < provided) {
replacementSprites[key] = textureGetter.apply(spriteIds.get(value));
} else {
ContinuityClient.LOGGER.warn("Cannot replace tile " + key + " with tile " + value + " as only " + provided + " tiles were provided in file '" + properties.getResourceId() + "' in pack '" + properties.getPackName() + "'");
ContinuityClient.LOGGER.warn("Cannot replace tile " + key + " with tile " + value + " as only " + provided + " tiles were provided in file '" + properties.getResourceId() + "' in pack '" + properties.getPackId() + "'");
}
} else {
ContinuityClient.LOGGER.warn("Cannot replace tile " + key + " as method '" + properties.getMethod() + "' only supports " + replacementTextureAmount + " replacement tiles in file '" + properties.getResourceId() + "' in pack '" + properties.getPackName() + "'");
ContinuityClient.LOGGER.warn("Cannot replace tile " + key + " as method '" + properties.getMethod() + "' only supports " + replacementTextureAmount + " replacement tiles in file '" + properties.getResourceId() + "' in pack '" + properties.getPackId() + "'");
}
}
}

if (provided > textureAmount) {
if (replacementSprites == null) {
ContinuityClient.LOGGER.warn("Method '" + properties.getMethod() + "' requires " + textureAmount + " tiles but " + provided + " were provided in file '" + properties.getResourceId() + "' in pack '" + properties.getPackName() + "'");
ContinuityClient.LOGGER.warn("Method '" + properties.getMethod() + "' requires " + textureAmount + " tiles but " + provided + " were provided in file '" + properties.getResourceId() + "' in pack '" + properties.getPackId() + "'");
}
max = textureAmount;
}
Expand All @@ -659,7 +659,7 @@ public QuadProcessor createProcessor(CompactConnectingCtmProperties properties,
}

if (provided < textureAmount) {
ContinuityClient.LOGGER.error("Method '" + properties.getMethod() + "' requires at least " + textureAmount + " tiles but only " + provided + " were provided in file '" + properties.getResourceId() + "' in pack '" + properties.getPackName() + "'");
ContinuityClient.LOGGER.error("Method '" + properties.getMethod() + "' requires at least " + textureAmount + " tiles but only " + provided + " were provided in file '" + properties.getResourceId() + "' in pack '" + properties.getPackId() + "'");
for (int i = provided; i < textureAmount; i++) {
sprites[i] = missingSprite;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@
import net.minecraft.world.BlockRenderView;

public interface ConnectionPredicate {
boolean shouldConnect(BlockRenderView blockView, BlockState state, BlockPos pos, BlockState toState, Direction face, Sprite quadSprite);
boolean shouldConnect(BlockRenderView blockView, BlockState appearanceState, BlockState state, BlockPos pos, BlockState otherAppearanceState, BlockState otherState, BlockPos otherPos, Direction face, Sprite quadSprite);

default boolean shouldConnect(BlockRenderView blockView, BlockState state, BlockPos pos, BlockPos toPos, Direction face, Sprite quadSprite) {
return shouldConnect(blockView, state, pos, blockView.getBlockState(toPos), face, quadSprite);
default boolean shouldConnect(BlockRenderView blockView, BlockState appearanceState, BlockState state, BlockPos pos, BlockPos otherPos, Direction face, Sprite quadSprite) {
BlockState otherState = blockView.getBlockState(otherPos);
BlockState otherAppearanceState = otherState.getAppearance(blockView, otherPos, face, state, pos);
return shouldConnect(blockView, appearanceState, state, pos, otherAppearanceState, otherState, otherPos, face, quadSprite);
}

default boolean shouldConnect(BlockRenderView blockView, BlockState state, BlockPos pos, BlockPos.Mutable toPos, Direction face, Sprite quadSprite, boolean innerSeams) {
if (shouldConnect(blockView, state, pos, toPos, face, quadSprite)) {
default boolean shouldConnect(BlockRenderView blockView, BlockState appearanceState, BlockState state, BlockPos pos, BlockPos.Mutable otherPos, Direction face, Sprite quadSprite, boolean innerSeams) {
if (shouldConnect(blockView, appearanceState, state, pos, otherPos, face, quadSprite)) {
if (innerSeams) {
toPos.move(face);
return !shouldConnect(blockView, state, pos, toPos, face, quadSprite);
otherPos.move(face);
return !shouldConnect(blockView, appearanceState, state, pos, otherPos, face, quadSprite);
} else {
return true;
}
Expand Down
Loading

0 comments on commit 21174ac

Please sign in to comment.