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.
This commit is contained in:
parent
fc189c9aaf
commit
e1b0a8c153
6 changed files with 156 additions and 11 deletions
|
@ -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);
|
||||
|
|
|
@ -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 <T extends TileEntity> void bindTileEntityRenderer(TileEntityType<T> tileEntityType, Function<TileEntityRendererDispatcher, TileEntityRenderer<? super T>> rendererFactory)
|
||||
public static synchronized <T extends TileEntity> void bindTileEntityRenderer(TileEntityType<T> tileEntityType,
|
||||
Function<? super TileEntityRendererDispatcher, ? extends TileEntityRenderer<? super T>> rendererFactory)
|
||||
{
|
||||
TileEntityRendererDispatcher.instance.setSpecialRendererInternal(tileEntityType, rendererFactory.apply(TileEntityRendererDispatcher.instance));
|
||||
}
|
||||
|
|
|
@ -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<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand) {
|
||||
ImmutableList.Builder<BakedQuad> 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<Block> blockRegistryEvent) {
|
||||
blockRegistryEvent.getRegistry().register(new Block(Block.Properties.create(Material.ROCK)).setRegistryName("trsr_transformer_test", "test"));
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onItemsRegistry(final RegistryEvent.Register<Item> itemRegistryEvent) {
|
||||
itemRegistryEvent.getRegistry().register(new BlockItem(testblock, new Item.Properties().group(ItemGroup.MISC)).setRegistryName("trsr_transformer_test", "test"));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -53,3 +53,5 @@ loaderVersion="[28,)"
|
|||
modId="new_model_loader_test"
|
||||
[[mods]]
|
||||
modId="forgedebugmultilayermodel"
|
||||
[[mods]]
|
||||
modId="trsr_transformer_test"
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"variants": {
|
||||
"": {
|
||||
"model": "examplemod:block/test"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"parent": "block/cube_all",
|
||||
"textures": {
|
||||
"all": "minecraft:block/dirt"
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue