feat: Tint microblock breaking particles by material colour

Covers whose texture is greyscale and coloured at render time broke into
grey particles. A grass cover hit on the top face gave stone coloured
particles while its sides and bottom looked right, and a leaves cover was
wrong on every face. The cover itself rendered correctly, because
BlockMicroMaterial.renderMicroFace already feeds colorMultiplier to the
face renderer, but nothing carried that tint through to the particles.

Add getBreakingColour to IMicroMaterial, defaulting to no tint.
BlockMicroMaterial returns the block colour multiplier and
GrassMicroMaterial restricts it to the top face, since grass_side and
dirt are already coloured, matching the carve out in vanilla
EntityDiggingFX. JIconHitEffects gains matching getBreakingColour and
getBrokenColour defaults, IconHitEffects passes them to the colour aware
EntityDigIconFX overloads, and McBlockPart uses the colour multiplier of
the block it wraps.

Microblock carries the part level override rather than the
MicroblockClient trait. A new Scala trait member is abstract on the
compiled interface, so mixins built against older FMP would fail with
AbstractMethodError, which the frozen ReferenceScalaMicroblockTraits
fixture caught. A concrete method on the class is inherited by those
mixins instead, and still wins over the interface default.

Characterization expectations are updated for the added signatures and
for the hit effect evaluation order, which now reads the colour from the
material right after the icon for the same side.

Needs the CodeChickenCore build that adds the colour aware
EntityDigIconFX overloads.
This commit is contained in:
Algent committed 2026-09-14 11:28:11 +02:00
1 parent 367ecac68c
commit f86a31d908
17 files changed
+299 -9

No files matched your search

+1 -1
View File
@@ -13,7 +13,7 @@ dependencies {
functionalTestImplementation("org.junit.platform:junit-platform-launcher")
functionalTestImplementation("org.junit.platform:junit-platform-reporting")
implementation("com.github.GTNewHorizons:CodeChickenCore:1.4.19:dev")
implementation("com.github.GTNewHorizons:CodeChickenCore:1.4.20:dev")
compileOnly("com.github.GTNewHorizons:Angelica:2.1.19:dev")
compileOnly("com.github.GTNewHorizons:Postea:1.2.5:dev") {transitive = false}
devOnlyNonPublishable("com.github.GTNewHorizons:NotEnoughItems:2.8.93-GTNH:dev") {
@@ -7,6 +7,7 @@ import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;
import codechicken.lib.render.CCRenderState;
import codechicken.lib.render.uv.MultiIconTransformation;
@@ -163,6 +164,17 @@ public class BlockMicroMaterial implements IMicroMaterial {
return block().getIcon(side, meta());
}
/**
* Resolves the block tint with this material's block and metadata at the particle origin. Neighbor and biome
* lookups still use the supplied world; the multipart host's metadata must not select the material's colour.
*/
@Override
@SideOnly(Side.CLIENT)
public int getBreakingColour(int side, IBlockAccess world, int x, int y, int z) {
Block materialBlock = block();
return materialBlock.colorMultiplier(new MaterialBlockAccess(world, materialBlock, meta(), x, y, z), x, y, z);
}
@Override
public ItemStack getItem() {
return new ItemStack(block(), 1, meta());
@@ -2,14 +2,18 @@ package codechicken.microblock;
import net.minecraft.block.BlockGrass;
import net.minecraft.init.Blocks;
import net.minecraft.world.IBlockAccess;
import codechicken.lib.render.BlockRenderer.BlockFace;
import codechicken.lib.render.CCRenderState;
import codechicken.lib.render.EntityDigIconFX;
import codechicken.lib.render.uv.IconTransformation;
import codechicken.lib.render.uv.UVTransformation;
import codechicken.lib.render.uv.UVTranslation;
import codechicken.lib.vec.Cuboid6;
import codechicken.lib.vec.Vector3;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class GrassMicroMaterial extends BlockMicroMaterial {
@@ -33,6 +37,16 @@ public class GrassMicroMaterial extends BlockMicroMaterial {
sideIconT_$eq(new IconTransformation(BlockGrass.getIconSideOverlay()));
}
/**
* Only grass_top is greyscale and needs the biome tint. Side 0 is dirt and sides 2-5 are grass_side, both already
* coloured, so tinting them would double up. Matches the carve-out in vanilla EntityDiggingFX.
*/
@Override
@SideOnly(Side.CLIENT)
public int getBreakingColour(int side, IBlockAccess world, int x, int y, int z) {
return side == 1 ? super.getBreakingColour(side, world, x, y, z) : EntityDigIconFX.NO_TINT;
}
@Override
public void renderMicroFace(Vector3 pos, int pass, Cuboid6 bounds) {
BlockFace face = (BlockFace) CCRenderState.instance().model;
@@ -0,0 +1,82 @@
package codechicken.microblock;
import net.minecraft.block.Block;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraftforge.common.util.ForgeDirection;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/** Read-only tint lookup: substitute the material at one position, retaining the surrounding world. */
@SideOnly(Side.CLIENT)
final class MaterialBlockAccess implements IBlockAccess {
private final IBlockAccess world;
private final Block block;
private final int meta, x, y, z;
MaterialBlockAccess(IBlockAccess world, Block block, int meta, int x, int y, int z) {
this.world = world;
this.block = block;
this.meta = meta;
this.x = x;
this.y = y;
this.z = z;
}
private boolean isOrigin(int x, int y, int z) {
return this.x == x && this.y == y && this.z == z;
}
@Override
public Block getBlock(int x, int y, int z) {
return isOrigin(x, y, z) ? block : world.getBlock(x, y, z);
}
@Override
public int getBlockMetadata(int x, int y, int z) {
return isOrigin(x, y, z) ? meta : world.getBlockMetadata(x, y, z);
}
@Override
public TileEntity getTileEntity(int x, int y, int z) {
return world.getTileEntity(x, y, z);
}
@Override
public int getLightBrightnessForSkyBlocks(int x, int y, int z, int minimum) {
return world.getLightBrightnessForSkyBlocks(x, y, z, minimum);
}
@Override
public int isBlockProvidingPowerTo(int x, int y, int z, int side) {
return world.isBlockProvidingPowerTo(x, y, z, side);
}
@Override
public boolean isAirBlock(int x, int y, int z) {
return isOrigin(x, y, z) ? block.isAir(this, x, y, z) : world.isAirBlock(x, y, z);
}
@Override
public BiomeGenBase getBiomeGenForCoords(int x, int z) {
return world.getBiomeGenForCoords(x, z);
}
@Override
public int getHeight() {
return world.getHeight();
}
@Override
public boolean extendedLevelsInChunkCache() {
return world.extendedLevelsInChunkCache();
}
@Override
public boolean isSideSolid(int x, int y, int z, ForgeDirection side, boolean fallback) {
return world.isSideSolid(x, y, z, side, fallback);
}
}
@@ -14,10 +14,12 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.IBlockAccess;
import codechicken.lib.data.MCDataInput;
import codechicken.lib.data.MCDataOutput;
import codechicken.lib.packet.PacketCustom;
import codechicken.lib.render.EntityDigIconFX;
import codechicken.lib.vec.Cuboid6;
import codechicken.lib.vec.Vector3;
import codechicken.microblock.handler.MicroblockProxy;
@@ -36,6 +38,18 @@ public final class MicroMaterialRegistry {
@SideOnly(Side.CLIENT)
IIcon getBreakingIcon(int side);
/**
* The 0xRRGGBB tint to multiply breaking particles on side by, {@link EntityDigIconFX#NO_TINT} for none.
* <p>
* A material whose icon for side is greyscale and gets its colour at render time (leaves, grass tops) must
* override this, or it breaks into grey particles. Defaults to no tint, which is correct for any material whose
* texture is already coloured.
*/
@SideOnly(Side.CLIENT)
default int getBreakingColour(int side, IBlockAccess world, int x, int y, int z) {
return EntityDigIconFX.NO_TINT;
}
/**
* Supported material extension callback to load icons from the underlying block/etc., invoked by FMP on the
* client.
@@ -9,14 +9,18 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.IBlockAccess;
import codechicken.lib.data.MCDataInput;
import codechicken.lib.data.MCDataOutput;
import codechicken.lib.raytracer.IndexedCuboid6;
import codechicken.lib.render.EntityDigIconFX;
import codechicken.lib.vec.Cuboid6;
import codechicken.multipart.JCuboidPart;
import codechicken.multipart.TCuboidPart;
import codechicken.multipart.TMultiPart;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public abstract class Microblock extends TMultiPart implements TCuboidPart {
@@ -100,6 +104,20 @@ public abstract class Microblock extends TMultiPart implements TCuboidPart {
return MicroMaterialRegistry.getMaterial(material());
}
/**
* Satisfies {@link codechicken.multipart.JIconHitEffects#getBrokenColour} for every microblock, pairing with the
* icon {@link MicroblockClient} resolves for the same side.
* <p>
* Declared on this class rather than on the MicroblockClient trait on purpose: a new Scala trait member is abstract
* on the compiled interface, so mixins built against older FMP would fail with AbstractMethodError. A concrete
* method here is inherited by those classes instead.
*/
@SideOnly(Side.CLIENT)
public int getBrokenColour(int side, IBlockAccess world, int x, int y, int z) {
MicroMaterialRegistry.IMicroMaterial material = getIMaterial();
return material == null ? EntityDigIconFX.NO_TINT : material.getBreakingColour(side, world, x, y, z);
}
public abstract int itemClassID();
@Override
@@ -17,7 +17,7 @@ import scala.collection.JavaConversions;
modid = "ForgeMicroblock",
name = "Forge Microblocks",
acceptedMinecraftVersions = "[1.7.10]",
dependencies = "required-after:CodeChickenCore@[1.4.3,);required-after:ForgeMultipart",
dependencies = "required-after:CodeChickenCore@[1.4.20,);required-after:ForgeMultipart",
version = Tags.VERSION,
modLanguage = "scala")
public final class MicroblockMod$ {
@@ -13,7 +13,7 @@ import cpw.mods.fml.common.event.FMLServerAboutToStartEvent;
modid = "ForgeMicroblock",
name = "Forge Microblocks",
acceptedMinecraftVersions = "[1.7.10]",
dependencies = "required-after:CodeChickenCore@[1.4.3,);required-after:ForgeMultipart",
dependencies = "required-after:CodeChickenCore@[1.4.20,);required-after:ForgeMultipart",
version = Tags.VERSION,
modLanguage = "scala")
public final class MicroblockMod {
@@ -3,6 +3,7 @@ package codechicken.multipart;
import net.minecraft.client.particle.EffectRenderer;
import net.minecraft.util.IIcon;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
import codechicken.lib.raytracer.ExtendedMOP;
import codechicken.lib.render.EntityDigIconFX;
@@ -23,11 +24,19 @@ public final class IconHitEffects {
public static void addHitEffects(JIconHitEffects part, MovingObjectPosition hit, EffectRenderer effectRenderer) {
TileMultipart tile = ((TMultiPart) part).tile();
World world = tile.getWorldObj();
EntityDigIconFX.addBlockHitEffects(
tile.getWorldObj(),
world,
part.getBounds().copy().add(Vector3.fromTileEntity(tile)),
hit.sideHit,
part.getBreakingIcon(ExtendedMOP.getData(hit), hit.sideHit),
part.getBreakingColour(
ExtendedMOP.getData(hit),
hit.sideHit,
world,
tile.xCoord,
tile.yCoord,
tile.zCoord),
effectRenderer);
}
@@ -43,10 +52,16 @@ public final class IconHitEffects {
Cuboid6 bounds = scaleDensity ? part.getBounds().copy() : Cuboid6.full.copy();
// The tile is read only here, after the icons and bounds, matching the reference evaluation order.
TileMultipart tile = ((TMultiPart) part).tile();
World world = tile.getWorldObj();
int[] colours = new int[6];
for (int i = 0; i < 6; i++) {
colours[i] = part.getBrokenColour(i, world, tile.xCoord, tile.yCoord, tile.zCoord);
}
EntityDigIconFX.addBlockDestroyEffects(
tile.getWorldObj(),
world,
bounds.add(Vector3.fromTileEntity(tile)),
icons,
colours,
effectRenderer);
}
}
@@ -1,7 +1,9 @@
package codechicken.multipart;
import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;
import codechicken.lib.render.EntityDigIconFX;
import codechicken.lib.vec.Cuboid6;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@@ -21,4 +23,23 @@ public interface JIconHitEffects {
@SideOnly(Side.CLIENT)
IIcon getBrokenIcon(int side);
/**
* The 0xRRGGBB tint for the hit particle on side, mirroring {@link #getBreakingIcon(Object, int)}. Defaults to the
* whole-part tint.
*/
@SideOnly(Side.CLIENT)
default int getBreakingColour(Object subPart, int side, IBlockAccess world, int x, int y, int z) {
return getBrokenColour(side, world, x, y, z);
}
/**
* The 0xRRGGBB tint to multiply the particle for side by, {@link EntityDigIconFX#NO_TINT} for none. Override
* alongside {@link #getBrokenIcon(int)} whenever that icon is greyscale and coloured at render time, or the part
* breaks into grey particles.
*/
@SideOnly(Side.CLIENT)
default int getBrokenColour(int side, IBlockAccess world, int x, int y, int z) {
return EntityDigIconFX.NO_TINT;
}
}
@@ -9,6 +9,7 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.IBlockAccess;
import codechicken.lib.vec.Cuboid6;
import codechicken.multipart.IconHitEffects;
@@ -66,6 +67,12 @@ public abstract class McBlockPart extends JCuboidPart implements JNormalOcclusio
return getBlock().getIcon(0, 0);
}
@Override
@SideOnly(Side.CLIENT)
public int getBrokenColour(int side, IBlockAccess world, int x, int y, int z) {
return getBlock().colorMultiplier(world, x, y, z);
}
@Override
public void addHitEffects(MovingObjectPosition hit, EffectRenderer effectRenderer) {
IconHitEffects.addHitEffects(this, hit, effectRenderer);
@@ -123,6 +123,7 @@ class BlockMicroMaterialCharacterizationTest {
"canRenderInPass(I)Z",
"codechicken$microblock$BlockMicroMaterial$$safeIcon$1(Lnet/minecraft/block/Block;I)Lnet/minecraft/util/IIcon;",
"explosionResistance(Lnet/minecraft/entity/Entity;)F",
"getBreakingColour(ILnet/minecraft/world/IBlockAccess;III)I",
"getBreakingIcon(I)Lnet/minecraft/util/IIcon;",
"getColour(I)I",
"getCutterStrength()I",
@@ -175,7 +176,8 @@ class BlockMicroMaterialCharacterizationTest {
void keepsTheExactClientOnlyBoundary() throws Exception {
for (Method method : BlockMicroMaterial.class.getDeclaredMethods()) {
SideOnly annotation = method.getAnnotation(SideOnly.class);
if (method.getName().equals("loadIcons") || method.getName().equals("getBreakingIcon")) {
if (method.getName().equals("loadIcons") || method.getName().equals("getBreakingIcon")
|| method.getName().equals("getBreakingColour")) {
assertSideOnly(annotation);
} else {
assertNull(annotation, method.toString());
@@ -33,12 +33,14 @@ import codechicken.lib.render.uv.UVTransformationList;
import codechicken.lib.render.uv.UVTranslation;
import codechicken.lib.vec.Cuboid6;
import codechicken.lib.vec.Vector3;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
class GrassMicroMaterialCharacterizationTest {
private static final Set<String> GRASS_METHODS = new TreeSet<>(
Arrays.asList(
"getBreakingColour(ILnet/minecraft/world/IBlockAccess;III)I",
"loadIcons()V",
"renderMicroFace(Lcodechicken/lib/vec/Vector3;ILcodechicken/lib/vec/Cuboid6;)V",
"sideIconT()Lcodechicken/lib/render/uv/IconTransformation;",
@@ -105,7 +107,11 @@ class GrassMicroMaterialCharacterizationTest {
void keepsRenderingMethodsAndOverlayAccessorsOnTheCommonSide() {
for (Class<?> type : Arrays.asList(GrassMicroMaterial.class, TopMicroMaterial.class)) {
for (Method method : type.getDeclaredMethods()) {
assertNull(method.getAnnotation(SideOnly.class), method.toString());
if (method.getName().equals("getBreakingColour")) {
assertEquals(Side.CLIENT, method.getAnnotation(SideOnly.class).value());
} else {
assertNull(method.getAnnotation(SideOnly.class), method.toString());
}
}
}
assertNull(GrassMicroMaterial.class.getDeclaredFields()[0].getAnnotation(SideOnly.class));
@@ -56,6 +56,7 @@ class MicroblockCharacterizationTest {
"explosionResistance(Lnet/minecraft/entity/Entity;)F",
"getCollisionBoxes()Ljava/lang/Iterable;",
"getDrops()Ljava/lang/Iterable;",
"getBrokenColour(ILnet/minecraft/world/IBlockAccess;III)I",
"getDrops()Ljava/util/List;",
"getIMaterial()Lcodechicken/microblock/MicroMaterialRegistry$IMicroMaterial;",
"getLightValue()I",
@@ -19,6 +19,7 @@ import net.minecraft.util.Vec3;
import org.junit.jupiter.api.Test;
import codechicken.lib.render.EntityDigIconFX;
import codechicken.lib.vec.Cuboid6;
import codechicken.lib.vec.Vector3;
import codechicken.microblock.MicroMaterialRegistry.IMicroMaterial;
@@ -149,6 +150,10 @@ class MicroblockTraitsCharacterizationTest {
void particleForwardersReachIconEffectsAndPreserveEvaluationOrder() throws Exception {
Fixture fixture = new Fixture();
fixture.material((method, args) -> {
if (method.equals("getBreakingColour")) {
fixture.events.add("colour:" + args[0]);
return EntityDigIconFX.NO_TINT;
}
assertEquals("getBreakingIcon", method);
fixture.events.add("icon:" + args[0]);
return null;
@@ -174,7 +179,8 @@ class MicroblockTraitsCharacterizationTest {
fixture.events.clear();
MovingObjectPosition hit = new MovingObjectPosition(0, 0, 0, 3, Vec3.createVectorHelper(0, 0, 0));
assertThrows(NullPointerException.class, () -> fixture.part.addHitEffects(hit, null));
assertEquals(Arrays.asList("bounds", "material", "icon:3"), fixture.events);
// The colour is resolved from the material right after the icon, for the same side.
assertEquals(Arrays.asList("bounds", "material", "icon:3", "material", "colour:3"), fixture.events);
}
private static void assertFaces(List<Object[]> faces, int count, Vector3 position, int pass, Cuboid6 bounds) {
@@ -0,0 +1,92 @@
package codechicken.microblock;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertSame;
import java.lang.reflect.Proxy;
import net.minecraft.block.Block;
import net.minecraft.block.BlockOldLeaf;
import net.minecraft.block.material.Material;
import net.minecraft.world.ColorizerFoliage;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.biome.BiomeGenBase;
import org.junit.jupiter.api.Test;
class ParticleTintTest {
@Test
void leafVariantsUseMaterialMetadataInsteadOfMultipartMetadata() {
IBlockAccess host = access((method, args) -> {
if (method.equals("getBlockMetadata")) return 0;
throw new AssertionError("Fixed leaf tints must not read the biome: " + method);
});
Block leaves = new BlockOldLeaf();
assertEquals(
ColorizerFoliage.getFoliageColorPine(),
new BlockMicroMaterial(leaves, 1).getBreakingColour(1, host, 10, 64, 20));
assertEquals(
ColorizerFoliage.getFoliageColorBirch(),
new BlockMicroMaterial(leaves, 2).getBreakingColour(1, host, 10, 64, 20));
}
@Test
void tintSeesMaterialAtOriginAndRealNeighborsAndBiome() {
Block neighbor = new Block(Material.rock) {};
IBlockAccess host = access((method, args) -> {
if (method.equals("getBiomeGenForCoords")) {
assertEquals(10, args[0]);
assertEquals(20, args[1]);
return BiomeGenBase.plains;
}
assertEquals(11, args[0]);
assertEquals(64, args[1]);
assertEquals(20, args[2]);
if (method.equals("getBlock")) return neighbor;
if (method.equals("getBlockMetadata")) return 7;
throw new AssertionError(method);
});
Block tinted = new Block(Material.rock) {
@Override
public int colorMultiplier(IBlockAccess world, int x, int y, int z) {
assertSame(this, world.getBlock(x, y, z));
assertEquals(2, world.getBlockMetadata(x, y, z));
assertSame(neighbor, world.getBlock(x + 1, y, z));
assertEquals(7, world.getBlockMetadata(x + 1, y, z));
assertSame(BiomeGenBase.plains, world.getBiomeGenForCoords(x, z));
return 0x123456;
}
};
assertEquals(0x123456, new BlockMicroMaterial(tinted, 2).getBreakingColour(1, host, 10, 64, 20));
}
@Test
void grassTintsOnlyItsTopFace() {
Block tinted = new Block(Material.grass) {
@Override
public int colorMultiplier(IBlockAccess world, int x, int y, int z) {
return 0x123456;
}
};
GrassMicroMaterial grass = new GrassMicroMaterial() {
@Override
public Block block() {
return tinted;
}
};
for (int side = 0; side < 6; side++) {
assertEquals(side == 1 ? 0x123456 : 0xFFFFFF, grass.getBreakingColour(side, null, 0, 0, 0));
}
}
private static IBlockAccess access(java.util.function.BiFunction<String, Object[], Object> callback) {
return (IBlockAccess) Proxy.newProxyInstance(
IBlockAccess.class.getClassLoader(),
new Class<?>[] { IBlockAccess.class },
(proxy, method, args) -> callback.apply(method.getName(), args));
}
}
@@ -76,7 +76,7 @@ class MicroblockModCharacterizationTest {
assertEquals("ForgeMicroblock", mod.modid());
assertEquals("Forge Microblocks", mod.name());
assertEquals("[1.7.10]", mod.acceptedMinecraftVersions());
assertEquals("required-after:CodeChickenCore@[1.4.3,);required-after:ForgeMultipart", mod.dependencies());
assertEquals("required-after:CodeChickenCore@[1.4.20,);required-after:ForgeMultipart", mod.dependencies());
assertEquals(Tags.VERSION, mod.version());
assertEquals("scala", mod.modLanguage());