From e1b0a8c153f9c4466235912d19c7c186769f22b6 Mon Sep 17 00:00:00 2001 From: David Quintana Date: Sun, 29 Dec 2019 17:16:27 +0100 Subject: [PATCH] Fix LightUtil.unpack to set the 4th component to 1 when expanding an xyz position into a 4-component vector. Add TRSRTransformer test mod. Fix signature of the bindTileEntityRenderer method, to account for covariance. --- .../client/model/pipeline/LightUtil.java | 12 +- .../fml/client/registry/ClientRegistry.java | 3 +- .../client/model/TRSRTransformerTest.java | 135 ++++++++++++++++++ src/test/resources/META-INF/mods.toml | 4 +- .../blockstates/test.json | 7 + .../models/block/test.json | 6 + 6 files changed, 156 insertions(+), 11 deletions(-) create mode 100644 src/test/java/net/minecraftforge/debug/client/model/TRSRTransformerTest.java create mode 100644 src/test/resources/assets/trsr_transformer_test/blockstates/test.json create mode 100644 src/test/resources/assets/trsr_transformer_test/models/block/test.json diff --git a/src/main/java/net/minecraftforge/client/model/pipeline/LightUtil.java b/src/main/java/net/minecraftforge/client/model/pipeline/LightUtil.java index 19ba0d780..2f65908a9 100644 --- a/src/main/java/net/minecraftforge/client/model/pipeline/LightUtil.java +++ b/src/main/java/net/minecraftforge/client/model/pipeline/LightUtil.java @@ -24,18 +24,11 @@ import java.util.concurrent.ConcurrentMap; import org.apache.commons.lang3.tuple.Pair; -import com.mojang.blaze3d.matrix.MatrixStack; -import com.mojang.blaze3d.vertex.IVertexBuilder; - -import net.minecraft.client.renderer.BufferBuilder; -import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.model.BakedQuad; import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.client.renderer.vertex.VertexFormat; import net.minecraft.client.renderer.vertex.VertexFormatElement; -import net.minecraft.client.renderer.vertex.VertexFormatElement.Usage; import net.minecraft.util.Direction; -import net.minecraftforge.client.ForgeHooksClient; public class LightUtil { @@ -166,6 +159,7 @@ public class LightUtil int vertexStart = v * formatFrom.getSize() + formatFrom.getOffset(e); int count = element.getElementCount(); VertexFormatElement.Type type = element.getType(); + VertexFormatElement.Usage usage = element.getUsage(); int size = type.getSize(); int mask = (256 << (8 * (size - 1))) - 1; for(int i = 0; i < length; i++) @@ -209,7 +203,7 @@ public class LightUtil } else { - to[i] = 0; + to[i] = (i == 3 && usage == VertexFormatElement.Usage.POSITION) ? 1 : 0; } } } @@ -311,7 +305,7 @@ public class LightUtil @Override public void put(int element, float... data) { - if(getVertexFormat().func_227894_c_().get(element).getUsage() == Usage.COLOR) + if(getVertexFormat().func_227894_c_().get(element).getUsage() == VertexFormatElement.Usage.COLOR) { System.arraycopy(auxColor, 0, buf, 0, buf.length); int n = Math.min(4, data.length); diff --git a/src/main/java/net/minecraftforge/fml/client/registry/ClientRegistry.java b/src/main/java/net/minecraftforge/fml/client/registry/ClientRegistry.java index b5f655b6d..315fe2b88 100644 --- a/src/main/java/net/minecraftforge/fml/client/registry/ClientRegistry.java +++ b/src/main/java/net/minecraftforge/fml/client/registry/ClientRegistry.java @@ -43,7 +43,8 @@ public class ClientRegistry * Call this during {@link net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent}. * This method is safe to call during parallel mod loading. */ - public static synchronized void bindTileEntityRenderer(TileEntityType tileEntityType, Function> rendererFactory) + public static synchronized void bindTileEntityRenderer(TileEntityType tileEntityType, + Function> rendererFactory) { TileEntityRendererDispatcher.instance.setSpecialRendererInternal(tileEntityType, rendererFactory.apply(TileEntityRendererDispatcher.instance)); } diff --git a/src/test/java/net/minecraftforge/debug/client/model/TRSRTransformerTest.java b/src/test/java/net/minecraftforge/debug/client/model/TRSRTransformerTest.java new file mode 100644 index 000000000..314304215 --- /dev/null +++ b/src/test/java/net/minecraftforge/debug/client/model/TRSRTransformerTest.java @@ -0,0 +1,135 @@ +package net.minecraftforge.debug.client.model; + +import com.google.common.collect.ImmutableList; +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.block.material.Material; +import net.minecraft.client.renderer.Quaternion; +import net.minecraft.client.renderer.TransformationMatrix; +import net.minecraft.client.renderer.Vector3f; +import net.minecraft.client.renderer.model.BakedQuad; +import net.minecraft.client.renderer.model.IBakedModel; +import net.minecraft.client.renderer.model.ItemOverrideList; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.item.BlockItem; +import net.minecraft.item.Item; +import net.minecraft.item.ItemGroup; +import net.minecraft.util.Direction; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.client.event.ModelBakeEvent; +import net.minecraftforge.client.model.QuadTransformer; +import net.minecraftforge.client.model.pipeline.TRSRTransformer; +import net.minecraftforge.client.model.pipeline.UnpackedBakedQuad; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.common.model.TransformationHelper; +import net.minecraftforge.event.RegistryEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; +import net.minecraftforge.registries.ObjectHolder; + +import javax.annotation.Nullable; +import java.util.List; +import java.util.Random; + +@Mod(TRSRTransformerTest.MODID) +public class TRSRTransformerTest { + public static final String MODID = "trsr_transformer_test"; + + public TRSRTransformerTest() { + // Register ourselves for server and other game events we are interested in + MinecraftForge.EVENT_BUS.register(this); + + FMLJavaModLoadingContext.get().getModEventBus().addListener(this::onModelBake); + } + + @SubscribeEvent + public void onModelBake(ModelBakeEvent e) { + for (ResourceLocation id : e.getModelRegistry().keySet()) { + if ("trsr_transformer_test".equals(id.getNamespace()) && "test".equals(id.getPath())) { + e.getModelRegistry().put(id, new MyBakedModel(e.getModelRegistry().get(id))); + } + } + } + + public class MyBakedModel implements IBakedModel + { + private final IBakedModel base; + + public MyBakedModel(IBakedModel base) { + this.base = base; + } + + @Override + public List getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand) { + ImmutableList.Builder quads = new ImmutableList.Builder<>(); + + Quaternion rot = TransformationHelper.quatFromXYZ(new Vector3f(0, 45, 0), true); + Vector3f translation = new Vector3f(0, 0.33f, 0); + + TransformationMatrix trans = new TransformationMatrix(translation, rot, null, null).blockCenterToCorner(); + + for (BakedQuad quad : base.getQuads(state, side, rand)) { + + if(true) + { + UnpackedBakedQuad.Builder builder = new UnpackedBakedQuad.Builder(quad.getFormat()); + + TRSRTransformer transformer = new TRSRTransformer(builder, trans); + + quad.pipe(transformer); + + quads.add(builder.build()); + } + else + { + QuadTransformer qt = new QuadTransformer(quad.getFormat(), trans); + quads.add(qt.processOne(quad)); + } + } + + return quads.build(); + } + + @Override + public boolean isAmbientOcclusion() { + return base.isAmbientOcclusion(); + } + + @Override + public boolean isGui3d() { + return base.isGui3d(); + } + + @Override + public boolean isBuiltInRenderer() { + return base.isBuiltInRenderer(); + } + + @Override + public TextureAtlasSprite getParticleTexture() { + return base.getParticleTexture(); + } + + @Override + public ItemOverrideList getOverrides() { + return base.getOverrides(); + } + } + + @Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD) + public static class RegistryEvents { + @ObjectHolder("trsr_transformer_test:test") + public static Block testblock; + + @SubscribeEvent + public static void onBlocksRegistry(final RegistryEvent.Register blockRegistryEvent) { + blockRegistryEvent.getRegistry().register(new Block(Block.Properties.create(Material.ROCK)).setRegistryName("trsr_transformer_test", "test")); + } + + @SubscribeEvent + public static void onItemsRegistry(final RegistryEvent.Register itemRegistryEvent) { + itemRegistryEvent.getRegistry().register(new BlockItem(testblock, new Item.Properties().group(ItemGroup.MISC)).setRegistryName("trsr_transformer_test", "test")); + } + } +} diff --git a/src/test/resources/META-INF/mods.toml b/src/test/resources/META-INF/mods.toml index 7cc48bcb6..1c192d758 100644 --- a/src/test/resources/META-INF/mods.toml +++ b/src/test/resources/META-INF/mods.toml @@ -52,4 +52,6 @@ loaderVersion="[28,)" [[mods]] modId="new_model_loader_test" [[mods]] - modId="forgedebugmultilayermodel" \ No newline at end of file + modId="forgedebugmultilayermodel" +[[mods]] + modId="trsr_transformer_test" \ No newline at end of file diff --git a/src/test/resources/assets/trsr_transformer_test/blockstates/test.json b/src/test/resources/assets/trsr_transformer_test/blockstates/test.json new file mode 100644 index 000000000..b8f6209e3 --- /dev/null +++ b/src/test/resources/assets/trsr_transformer_test/blockstates/test.json @@ -0,0 +1,7 @@ +{ + "variants": { + "": { + "model": "examplemod:block/test" + } + } +} \ No newline at end of file diff --git a/src/test/resources/assets/trsr_transformer_test/models/block/test.json b/src/test/resources/assets/trsr_transformer_test/models/block/test.json new file mode 100644 index 000000000..78e18e12f --- /dev/null +++ b/src/test/resources/assets/trsr_transformer_test/models/block/test.json @@ -0,0 +1,6 @@ +{ + "parent": "block/cube_all", + "textures": { + "all": "minecraft:block/dirt" + } +}