Skip to content

Commit

Permalink
Fix block colors regression
Browse files Browse the repository at this point in the history
  • Loading branch information
hlysine committed Jan 21, 2025
1 parent 684c630 commit bdd6724
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public enum Mods {
DIAGONAL_WALLS("diagonalwalls"),
FLYWHEEL("flywheel"),
SODIUM("sodium"),
RUBIDIUM("rubidium"),
ATHENA("athena"),
INDIUM("indium"),
STARLIGHT("starlight"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
@Retention(RetentionPolicy.RUNTIME)
public @interface ModMixin {

/**
* The mixin should only be enabled if any of these mods are present
*/
Mods[] requiredMods();

boolean applyIfPresent() default true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,35 @@ public class CopycatExternalContext {
/**
* Stores the currently rendering property for multi-state copycats. The stored value is thread-local.
* <p>
* This is used when determining block colors and when block shape calculation results in a valid rendering property for getAppearance
* This is used when determining block colors
*/
private static final ThreadLocal<String> renderingProperty = new ThreadLocal<>();
private static final ThreadLocal<String> propertyForBlockColor = new ThreadLocal<>();
/**
* Stores the currently rendering property for multi-state copycats. The stored value is thread-local.
* <p>
* This is used when block shape calculation results in a valid rendering property for getAppearance
*/
private static final ThreadLocal<String> propertyForAppearance = new ThreadLocal<>();
/**
* Used to determine whether a {@link ICopycatBlock#getAppearance} call is made for determining blocking logic,
* which causes the method to return appearances differently.
*/
private static final ThreadLocal<Boolean> forBlockingLogic = ThreadLocal.withInitial(() -> false);

public static void setRenderingProperty(String property) {
renderingProperty.set(property);
public static void setPropertyForBlockColor(String property) {
propertyForBlockColor.set(property);
}

public static String getPropertyForBlockColor() {
return propertyForBlockColor.get();
}

public static void setPropertyForAppearance(String property) {
propertyForAppearance.set(property);
}

public static String getRenderingProperty() {
return renderingProperty.get();
public static String getPropertyForAppearance() {
return propertyForAppearance.get();
}

public static void setForBlockingLogic(boolean value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -600,14 +600,14 @@ static boolean hidesNeighborFace(BlockGetter level,
BlockPos toPos = pos.relative(dir);

if (level instanceof ScaledBlockAndTintGetter scaledLevel && state.getBlock() instanceof IMultiStateCopycatBlock) {
CopycatExternalContext.setRenderingProperty(scaledLevel.getPropertyForRender(state, pos));
CopycatExternalContext.setPropertyForAppearance(scaledLevel.getPropertyForRender(state, pos));
} else {
CopycatExternalContext.setRenderingProperty(null);
CopycatExternalContext.setPropertyForAppearance(null);
}

if (BlockFaceUtils.canOcclude(level, neighborState, toPos, state, pos, dir.getOpposite())) {
BlockState material = state.getBlock() instanceof IMultiStateCopycatBlock
? IMultiStateCopycatBlock.getMaterial(level, pos, CopycatExternalContext.getRenderingProperty())
? IMultiStateCopycatBlock.getMaterial(level, pos, CopycatExternalContext.getPropertyForAppearance())
: state.getBlock() instanceof ICopycatBlock ? ICopycatBlock.getMaterial(level, pos) : state;
BlockState neighborMaterial = neighborState.getBlock() instanceof IMultiStateCopycatBlock && level instanceof ScaledBlockAndTintGetter scaledLevel
? IMultiStateCopycatBlock.getMaterial(level, toPos, scaledLevel.getPropertyForRender(neighborState, toPos))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,16 +397,16 @@ static BlockState getAppearance(IMultiStateCopycatBlock block, BlockState state,
BlockAndTintGetter reader = Mods.ATHENA.runIfInstalled(() -> () -> AthenaCompat.unwrapAthenaGetter(level)).orElse(level);

if (reader instanceof ScaledBlockAndTintGetter scaledLevel && state.getBlock() instanceof IMultiStateCopycatBlock) {
CopycatExternalContext.setRenderingProperty(scaledLevel.getPropertyForRender(state, pos));
CopycatExternalContext.setPropertyForAppearance(scaledLevel.getPropertyForRender(state, pos));
} else {
CopycatExternalContext.setRenderingProperty(block.defaultProperty());
CopycatExternalContext.setPropertyForAppearance(block.defaultProperty());
}

if (block.isIgnoredConnectivitySide(reader, state, side, pos, queryPos, queryState))
return state;

String property;
property = CopycatExternalContext.getRenderingProperty();
property = CopycatExternalContext.getPropertyForAppearance();
if (property == null)
property = block.defaultProperty();
BlockState material = IMultiStateCopycatBlock.getMaterial(reader, pos, property);
Expand Down Expand Up @@ -495,7 +495,7 @@ public int getColor(BlockState pState, @Nullable BlockAndTintGetter pLevel, @Nul
if (pLevel == null || pPos == null)
return GrassColor.get(0.5D, 1.0D);

String renderingProperty = CopycatExternalContext.getRenderingProperty();
String renderingProperty = CopycatExternalContext.getPropertyForBlockColor();
if (renderingProperty != null) {
return Minecraft.getInstance()
.getBlockColors()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* <p>
* Rubidium compatible version of {@link com.copycatsplus.copycats.mixin.foundation.copycat.multistate.ModelBlockRendererMixin}.
*/
@ModMixin(requiredMods = Mods.SODIUM)
@ModMixin(requiredMods = {Mods.RUBIDIUM, Mods.SODIUM})
@Mixin(BlockRenderer.class)
@Pseudo
public class BlockRendererMixin {
Expand All @@ -34,7 +34,7 @@ public class BlockRendererMixin {
)
private void beforeColor(BlockRenderContext ctx, ColorProvider<BlockState> colorProvider, BakedQuadView quad, CallbackInfoReturnable<int[]> cir) {
if (quad.getSprite() instanceof MultiStateTextureAtlasSprite sprite)
CopycatExternalContext.setRenderingProperty(sprite.getProperty());
CopycatExternalContext.setPropertyForBlockColor(sprite.getProperty());
}

@Inject(
Expand All @@ -47,6 +47,6 @@ private void beforeColor(BlockRenderContext ctx, ColorProvider<BlockState> color
require = 0
)
private void afterColor(BlockRenderContext ctx, ColorProvider<BlockState> colorProvider, BakedQuadView quad, CallbackInfoReturnable<int[]> cir) {
CopycatExternalContext.setRenderingProperty(null);
CopycatExternalContext.setPropertyForBlockColor(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class ModelBlockRendererMixin {
)
private void beforeColor(BlockAndTintGetter level, BlockState state, BlockPos pos, VertexConsumer consumer, PoseStack.Pose pose, BakedQuad quad, float brightness0, float brightness1, float brightness2, float brightness3, int lightmap0, int lightmap1, int lightmap2, int lightmap3, int packedOverlay, CallbackInfo ci) {
if (quad.getSprite() instanceof MultiStateTextureAtlasSprite sprite)
CopycatExternalContext.setRenderingProperty(sprite.getProperty());
CopycatExternalContext.setPropertyForBlockColor(sprite.getProperty());
}

@Inject(
Expand All @@ -44,6 +44,6 @@ private void beforeColor(BlockAndTintGetter level, BlockState state, BlockPos po
require = 0
)
private void afterColor(BlockAndTintGetter level, BlockState state, BlockPos pos, VertexConsumer consumer, PoseStack.Pose pose, BakedQuad quad, float brightness0, float brightness1, float brightness2, float brightness3, int lightmap0, int lightmap1, int lightmap2, int lightmap3, int packedOverlay, CallbackInfo ci) {
CopycatExternalContext.setRenderingProperty(null);
CopycatExternalContext.setPropertyForBlockColor(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,17 @@ private static boolean processBlockFace(BlockGetter level,
1.0 / toScale.getZ()
);
if (operation.apply(fromShape, toShape)) {
String property = CopycatExternalContext.getRenderingProperty();
String property = CopycatExternalContext.getPropertyForAppearance();
if (property == null) property = copycatBlock.defaultProperty();
CopycatExternalContext.setRenderingProperty(copycatBlock.getPropertyFromRender(property, toState, world, part, toTruePos));
CopycatExternalContext.setPropertyForAppearance(copycatBlock.getPropertyFromRender(property, toState, world, part, toTruePos));
return true;
}
}
}
if (toShape == null) {
toShape = toState.getFaceOcclusionShape(level, toPos, fromFace.getOpposite());
}
CopycatExternalContext.setRenderingProperty(null);
CopycatExternalContext.setPropertyForAppearance(null);
return operation.apply(fromShape, toShape);
}

Expand Down

0 comments on commit bdd6724

Please sign in to comment.