Merge master JSON model support into Java port

This commit is contained in:
Algent committed 2026-09-09 10:27:05 +02:00
commit b045c1bc4a
15 files changed
+303 -36

No files matched your search

+1 -1
View File
@@ -25,6 +25,6 @@ whitelist.json
*.iml
*.ipr
*.iws
src/main/resources/mixins.*.json
src/main/resources/mixins.*.refmap.json
*.bat
layout.json
+2 -1
View File
@@ -13,10 +13,11 @@ dependencies {
functionalTestImplementation("org.junit.platform:junit-platform-launcher")
functionalTestImplementation("org.junit.platform:junit-platform-reporting")
implementation("com.github.GTNewHorizons:CodeChickenCore:1.4.12:dev")
implementation("com.github.GTNewHorizons:CodeChickenCore:1.4.19: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") {
exclude group: 'com.github.GTNewHorizons', module: 'CodeChickenCore'
}
compileOnly("com.github.GTNewHorizons:GTNHLib:0.11.44:dev")
}
+4 -5
View File
@@ -107,12 +107,12 @@ apiPackage =
accessTransformersFile = multipart_at.cfg
# Provides setup for Mixins if enabled. If you don't know what mixins are: Keep it disabled!
usesMixins = false
usesMixins = true
# Set to a non-empty string to configure mixins in a separate source set under src/VALUE, instead of src/main.
# This can speed up compile times thanks to not running the mixin annotation processor on all input sources.
# Mixin classes will have access to "main" classes, but not the other way around.
separateMixinSourceSet =
separateMixinSourceSet = mixin
# Adds some debug arguments like verbose output and class export.
usesMixinDebug = false
@@ -123,12 +123,12 @@ mixinPlugin =
# Specify the package that contains all of your Mixins. The package must exist or
# the build will fail. If you have a package property defined in your mixins.<modid>.json,
# it must match with this or the build will fail.
mixinsPackage =
mixinsPackage = multipart.mixin
# Specify the core mod entry class if you use a core mod. This class must implement IFMLLoadingPlugin!
# This parameter is for legacy compatibility only
# Example value: (coreModClass = asm.FMLPlugin) + (modGroup = com.myname.mymodid) -> com.myname.mymodid.asm.FMLPlugin
coreModClass =
coreModClass = multipart.mixin.FMPMixinLoader
# If your project is only a consolidation of mixins or a core mod and does NOT contain a 'normal' mod ( = some class
# that is annotated with @Mod) you want this to be true. When in doubt: leave it on false!
@@ -232,4 +232,3 @@ curseForgeRelations =
# Whether IDEA should run spotless checks when pressing the Build button.
# This is meant to be set in $HOME/.gradle/gradle.properties.
# ideaCheckSpotlessOnBuild = true
@@ -0,0 +1,47 @@
package codechicken.multipart.mixin;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.gtnewhorizon.gtnhmixins.IEarlyMixinLoader;
import com.gtnewhorizon.gtnhmixins.builders.IMixins;
import cpw.mods.fml.relauncher.IFMLLoadingPlugin;
@IFMLLoadingPlugin.MCVersion("1.7.10")
public class FMPMixinLoader implements IFMLLoadingPlugin, IEarlyMixinLoader {
@Override
public String[] getASMTransformerClass() {
return null;
}
@Override
public String getModContainerClass() {
return null;
}
@Override
public String getSetupClass() {
return null;
}
@Override
public void injectData(Map<String, Object> data) {}
@Override
public String getAccessTransformerClass() {
return null;
}
@Override
public String getMixinConfig() {
return "mixins.ForgeMultipart.early.json";
}
@Override
public List<String> getMixins(Set<String> loadedCoreMods) {
return IMixins.getEarlyMixins(Mixins.class, loadedCoreMods);
}
}
@@ -0,0 +1,24 @@
package codechicken.multipart.mixin;
import javax.annotation.Nonnull;
import com.gtnewhorizon.gtnhmixins.builders.IMixins;
import com.gtnewhorizon.gtnhmixins.builders.MixinBuilder;
public enum Mixins implements IMixins {
RENDER_GLOBAL_MIXIN(new MixinBuilder("Redirects part block break renders to ISBRHModel")
.addClientMixins("MixinRenderGlobal").addRequiredMod(TargetedMod.GTNHLIB).setPhase(Phase.EARLY));
private final MixinBuilder builder;
Mixins(MixinBuilder builder) {
this.builder = builder;
}
@Nonnull
@Override
public MixinBuilder getBuilder() {
return this.builder;
}
}
@@ -0,0 +1,31 @@
package codechicken.multipart.mixin;
import javax.annotation.Nonnull;
import com.gtnewhorizon.gtnhmixins.builders.ITargetMod;
import com.gtnewhorizon.gtnhmixins.builders.TargetModBuilder;
public enum TargetedMod implements ITargetMod {
GTNHLIB("GTNHLib Core", "gtnhlib");
private final TargetModBuilder builder;
TargetedMod(String modId) {
this(null, modId, null);
}
TargetedMod(String coreModClass, String modId) {
this(coreModClass, modId, null);
}
TargetedMod(String coreModClass, String modId, String targetClass) {
this.builder = new TargetModBuilder().setCoreModClass(coreModClass).setModId(modId).setTargetClass(targetClass);
}
@Nonnull
@Override
public TargetModBuilder getBuilder() {
return builder;
}
}
@@ -0,0 +1,11 @@
{
"required": true,
"minVersion": "0.8.5-GTNH",
"package": "codechicken.multipart.mixin.early",
"refmap": "mixins.ForgeMultipart.refmap.json",
"target": "@env(DEFAULT)",
"mixinextras": {
"minVersion": "0.5.0"
},
"compatibilityLevel": "JAVA_8"
}
@@ -0,0 +1,7 @@
{
"required": true,
"minVersion": "0.8.5-GTNH",
"refmap": "mixins.ForgeMultipart.refmap.json",
"target": "@env(DEFAULT)",
"compatibilityLevel": "JAVA_8"
}
@@ -0,0 +1,18 @@
package codechicken.multipart;
import net.minecraft.block.Block;
import net.minecraft.world.IBlockAccess;
public interface JsonModeledPart {
Block getBlock();
/**
* Use to give your part a world that can be used to define properties for rendering. For example having your world
* returning your block with some specific state such as meta you can override the getMeta for the input location to
* be the meta you desire
*
* @return The world to use
*/
IBlockAccess getRenderWorld();
}
@@ -1,22 +1,18 @@
package codechicken.multipart;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.client.MinecraftForgeClient;
import codechicken.lib.raytracer.ExtendedMOP;
import codechicken.lib.render.CCRenderState;
import codechicken.lib.vec.Vector3;
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
import cpw.mods.fml.client.registry.RenderingRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import scala.Tuple2;
/**
* Internal class for rendering callbacks. Should be moved to the handler package.
@@ -72,7 +68,7 @@ public final class MultipartRenderer$ extends TileEntitySpecialRenderer implemen
}
if (renderer.hasOverrideBlockTexture()) {
drawBreakingPart(tile, x, y, z, renderer);
drawBreakingPart(world, x, y, z, renderer);
return false;
}
@@ -84,29 +80,12 @@ public final class MultipartRenderer$ extends TileEntitySpecialRenderer implemen
return b;
}
/**
* The hit data is a Scala Tuple2 whose first member is the struck part's index. It arrives erased, so both the
* tuple and the index are checked before use, exactly as the reference's pattern match did.
*/
private static void drawBreakingPart(TileMultipart tile, int x, int y, int z, RenderBlocks renderer) {
MovingObjectPosition hit = Minecraft.getMinecraft().objectMouseOver;
if (hit == null || hit.blockX != x || hit.blockY != y || hit.blockZ != z) {
return;
}
Object data = ExtendedMOP.getData(hit);
if (!(data instanceof Tuple2)) {
return;
}
Object index = ((Tuple2<?, ?>) data)._1();
if (!(index instanceof Integer)) {
return;
}
int i = (Integer) index;
if (i >= 0 && i < tile.partList().size()) {
tile.partList().apply(i).drawBreaking(renderer);
private static void drawBreakingPart(IBlockAccess world, int x, int y, int z, RenderBlocks renderer) {
TMultiPart part = RenderPartResolver.resolve(world, x, y, z);
if (part instanceof ISBRHPart) {
((ISBRHPart) part).renderWorldBlock(world, x, y, z, renderer);
} else if (part != null) {
part.drawBreaking(renderer);
}
}
@@ -0,0 +1,49 @@
package codechicken.multipart;
import java.util.List;
import net.minecraft.client.Minecraft;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.IBlockAccess;
import codechicken.lib.raytracer.ExtendedMOP;
import scala.Tuple2;
/** Resolves the multipart selected by Minecraft's current hit result. */
public final class RenderPartResolver {
public static TMultiPart resolve(IBlockAccess world, int x, int y, int z) {
if (world == null) {
return null;
}
// Make sure the hit is actually this block.
MovingObjectPosition hit = Minecraft.getMinecraft().objectMouseOver;
if (hit == null || hit.blockX != x || hit.blockY != y || hit.blockZ != z) {
return null;
}
Object data = ExtendedMOP.getData(hit);
if (!(data instanceof Tuple2)) {
return null;
}
Tuple2<?, ?> hitInfo = (Tuple2<?, ?>) data;
Object indexObject = hitInfo._1();
if (!(indexObject instanceof Integer)) {
return null;
}
TileMultipart tile = BlockMultipart.getClientTile(world, x, y, z);
if (tile == null) {
return null;
}
List<TMultiPart> parts = tile.jPartList();
int index = (Integer) indexObject;
if (index < 0 || index >= parts.size()) {
return null;
}
return parts.get(index);
}
}
@@ -9,6 +9,8 @@ import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.client.ForgeHooksClient;
import com.gtnewhorizon.gtnhlib.client.model.ModelISBRH;
import codechicken.lib.vec.Cuboid6;
import codechicken.lib.vec.Vector3;
import scala.collection.Iterator;
@@ -175,6 +177,17 @@ final class TileMultipartClientAccess {
if (part == null) {
return false;
}
if (part instanceof JsonModeledPart) {
JsonModeledPart modeledPart = (JsonModeledPart) part;
return ModelISBRH.INSTANCE.get().renderWorldBlock(
modeledPart.getRenderWorld(),
(int) vector.x,
(int) vector.y,
(int) vector.z,
modeledPart.getBlock(),
ModelISBRH.JSON_ISBRH_ID,
renderer);
}
if (part instanceof ISBRHPart) {
return ((ISBRHPart) part).renderWorldBlock(world, (int) vector.x, (int) vector.y, (int) vector.z, renderer);
}
@@ -78,7 +78,7 @@ public class MultipartProxy_serverImpl {
null,
"codechicken.multipart.scalatraits.TTileChangeTile");
GameRegistry.registerBlock(new BlockMultipart().setBlockName("multipart"), null, "block");
GameRegistry.registerBlock(new BlockMultipart().setBlockName("codechicken/multipart"), null, "block");
block = (BlockMultipart) Block.blockRegistry.getObject("ForgeMultipart:block");
MultipartSaveLoad.hookLoader();
@@ -0,0 +1,70 @@
package codechicken.multipart.mixin.early;
import net.minecraft.block.Block;
import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.RenderGlobal;
import net.minecraft.util.IIcon;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import com.gtnewhorizon.gtnhlib.client.model.ModelISBRH;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import codechicken.multipart.JsonModeledPart;
import codechicken.multipart.RenderPartResolver;
import codechicken.multipart.TMultiPart;
@Mixin(RenderGlobal.class)
public class MixinRenderGlobal {
@Shadow
private WorldClient theWorld;
@Redirect(
method = "drawBlockDamageTexture(Lnet/minecraft/client/renderer/Tessellator;Lnet/minecraft/entity/EntityLivingBase;F)V",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/multiplayer/WorldClient;getBlock(III)Lnet/minecraft/block/Block;"))
private Block forgemultipart$redirectDamageBlock(WorldClient world, int x, int y, int z) {
Block block = world.getBlock(x, y, z);
TMultiPart part = RenderPartResolver.resolve(world, x, y, z);
if (part instanceof JsonModeledPart) {
return ((JsonModeledPart) part).getBlock();
}
return block;
}
@WrapOperation(
method = "drawBlockDamageTexture(Lnet/minecraft/client/renderer/Tessellator;Lnet/minecraft/entity/EntityLivingBase;F)V",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/renderer/RenderBlocks;renderBlockUsingTexture(Lnet/minecraft/block/Block;IIILnet/minecraft/util/IIcon;)V"))
private void forgemultipart$redirectBreakingModeledPartDraw(RenderBlocks instance, Block block, int x, int y, int z,
IIcon overrideTexture, Operation<Void> original) {
TMultiPart candidatePart = RenderPartResolver.resolve(theWorld, x, y, z);
if (candidatePart instanceof JsonModeledPart) {
JsonModeledPart part = (JsonModeledPart) candidatePart;
instance.setOverrideBlockTexture(overrideTexture);
try {
ModelISBRH.INSTANCE.get().renderWorldBlock(
part.getRenderWorld(),
x,
y,
z,
part.getBlock(),
ModelISBRH.JSON_ISBRH_ID,
instance);
} finally {
instance.clearOverrideBlockTexture();
}
} else {
original.call(instance, block, x, y, z, overrideTexture);
}
}
}
@@ -1,6 +1,7 @@
package codechicken.multipart;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -115,6 +116,23 @@ class MultipartRendererCharacterizationTest {
}
}
@Test
void customAndJsonModelRenderContractsRemainAvailable() throws Exception {
assertSame(
boolean.class,
ISBRHPart.class.getMethod(
"renderWorldBlock",
IBlockAccess.class,
int.class,
int.class,
int.class,
RenderBlocks.class).getReturnType());
assertSame(Block.class, JsonModeledPart.class.getMethod("getBlock").getReturnType());
assertSame(IBlockAccess.class, JsonModeledPart.class.getMethod("getRenderWorld").getReturnType());
assertFalse(ISBRHPart.class.isAnnotationPresent(Deprecated.class));
assertFalse(JsonModeledPart.class.isAnnotationPresent(Deprecated.class));
}
private static void assertStatic(Method method, Class<?> returnType) {
assertSame(returnType, method.getReturnType(), method.getName());
assertTrue(Modifier.isPublic(method.getModifiers()), method.getName());