Jump to content

[1.11.2] Item model not loading


oMilky

Recommended Posts

I tried what you suggested and changed my block_tube.json to

{
    "forge_marker": 1,
    "defaults": {
       
    },
    "variants": {
        "normal": [{
	         "textures": {
	            "all": "indfab:blocks/block_tube"
	        },
	        "model": "indfab:block_tube",
	        "uvlock": true
        }],
        "inventory": [{
	         "textures": {
	            "all": "indfab:blocks/block_tube"
	        },
	        "model": "indfab:block_tube",
	        "uvlock": true
        }]
    }
}

 

And now I don't get anything showing at all

 

2017-03-23_17_09_56.png.0c164c237bbb9b540ebc5a6571708220.png

Link to comment
Share on other sites

From my understanding with the new ForgeBlockStates format the blockstate file can be used as a model for the Item and Block.

 

that is here: block_tube.json

{
    "forge_marker": 1,
    "defaults": {
       "textures": {
	            "all": "indfab:blocks/block_tube"
	        },
	        "model": "indfab:block_tube",
	        "uvlock": true
    },
    "variants": {
        
    }
}

 

My code for the model of my tube is all in the class TileTubeRenderer.java: 

package mod.indfab.client.render;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

import javax.vecmath.Matrix4f;

import org.apache.commons.lang3.tuple.Pair;

import com.google.common.base.Function;
import com.google.common.collect.ImmutableSet;

import mod.indfab.IndFab;
import mod.indfab.common.block.BlockTube;
import mod.indfab.common.tile.TileTube;
import mod.indfab.common.tube.TubeItem;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
import net.minecraft.client.renderer.block.model.ItemOverrideList;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.client.renderer.block.model.ItemCameraTransforms.TransformType;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.client.renderer.vertex.VertexFormat;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.client.model.IModel;
import net.minecraftforge.client.model.IPerspectiveAwareModel;
import net.minecraftforge.client.model.pipeline.UnpackedBakedQuad;
import net.minecraftforge.common.model.IModelState;
import net.minecraftforge.common.model.TRSRTransformation;
import net.minecraftforge.common.property.IExtendedBlockState;

public class TileTubeRenderer extends TileEntitySpecialRenderer<TileTube> implements IPerspectiveAwareModel {

	private static final int EXT_MIN_U = 0;
	private static final int EXT_MIN_V = 0;
	private static final int EXT_MAX_U = 8;
	private static final int EXT_MAX_V = 4;

	private static final int CORE_MIN_U = 0;
	private static final int CORE_MIN_V = 4;
	private static final int CORE_MAX_U = 8;
	private static final int CORE_MAX_V = 12;

	private static final int OPO_MIN_U = 8;
	private static final int OPO_MIN_V = 0;
	private static final int OPO_MAX_U = 16;
	private static final int OPO_MAX_V = 16;

	public static final ModelResourceLocation BLOCK_STATES_FILE_LOC = new ModelResourceLocation("indfab:block_tube");
	public static final ModelResourceLocation BLOCK_MRL_NOMAL = new ModelResourceLocation("indfab:block_tube", "normal");
	public static final ModelResourceLocation BLOCK_MRL_INV = new ModelResourceLocation("indfab:block_tube", "inventory");

	private TextureAtlasSprite texture;
	private VertexFormat format;

	public TileTubeRenderer() {
	}

	public TileTubeRenderer(TextureAtlasSprite tex) {
		this.format = DefaultVertexFormats.BLOCK;
		this.texture = tex;
	}

	private void renderTubeItems(TileTube tile, double x, double y, double z, float parTicks) {

		for (TubeItem item : tile.getItemList()) {

			if (item.getItemStack() == null)
				continue;

			GlStateManager.pushMatrix();
			GlStateManager.translate(x, y, z);
			ItemStack stack = item.getItemStack();
			IBakedModel model = Minecraft.getMinecraft().getRenderItem().getItemModelMesher().getItemModel(stack);
			model = model.getOverrides().handleItemState(model, stack, null, null);

			bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
			float xPos = item.getItemX(parTicks);
			float yPos = item.getItemY(parTicks);
			float zPos = item.getItemZ(parTicks);

			GlStateManager.translate(xPos, yPos, zPos);
			GlStateManager.scale(0.39, 0.39, 0.39);
			Minecraft.getMinecraft().getRenderItem().renderItem(stack, model);
			GlStateManager.popMatrix();
		}
	}

	@Override
	public void renderTileEntityAt(TileTube te, double x, double y, double z, float partialTicks, int destroyStage) {
		if (te != null)
			renderTubeItems(te, x, y, z, partialTicks);

		super.renderTileEntityAt(te, x, y, z, partialTicks, destroyStage);
	}

	@Override
	public List<BakedQuad> getQuads(IBlockState state, EnumFacing side, long rand) {
		List<BakedQuad> result = new ArrayList<BakedQuad>();

		if (state instanceof IExtendedBlockState) {

			IExtendedBlockState extState = (IExtendedBlockState) state;

			// Render as one if 2 connections

			boolean up = extState.getValue(BlockTube.UP);
			boolean down = extState.getValue(BlockTube.DOWN);
			boolean north = extState.getValue(BlockTube.NORTH);
			boolean south = extState.getValue(BlockTube.SOUTH);
			boolean east = extState.getValue(BlockTube.EAST);
			boolean west = extState.getValue(BlockTube.WEST);

			// Just UP and DOWN connects
			if (up && down && !north && !south && !east && !west) {
				result.add(createQuad(new Vec3d(0.25, 0, 0.75), new Vec3d(0.25, 1, 0.75), new Vec3d(0.25, 1, 0.25), new Vec3d(0.25, 0, 0.25), texture, OPO_MIN_U, OPO_MIN_V, OPO_MAX_U, OPO_MAX_V));
				result.add(createQuad(new Vec3d(0.25, 0, 0.25), new Vec3d(0.25, 1, 0.25), new Vec3d(0.25, 1, 0.75), new Vec3d(0.25, 0, 0.75), texture, OPO_MIN_U, OPO_MIN_V, OPO_MAX_U, OPO_MAX_V));

				result.add(createQuad(new Vec3d(0.75, 0, 0.75), new Vec3d(0.75, 1, 0.75), new Vec3d(0.75, 1, 0.25), new Vec3d(0.75, 0, 0.25), texture, OPO_MIN_U, OPO_MIN_V, OPO_MAX_U, OPO_MAX_V));
				result.add(createQuad(new Vec3d(0.75, 0, 0.25), new Vec3d(0.75, 1, 0.25), new Vec3d(0.75, 1, 0.75), new Vec3d(0.75, 0, 0.75), texture, OPO_MIN_U, OPO_MIN_V, OPO_MAX_U, OPO_MAX_V));

				result.add(createQuad(new Vec3d(0.75, 0, 0.75), new Vec3d(0.75, 1, 0.75), new Vec3d(0.25, 1, 0.75), new Vec3d(0.25, 0, 0.75), texture, OPO_MIN_U, OPO_MIN_V, OPO_MAX_U, OPO_MAX_V));
				result.add(createQuad(new Vec3d(0.25, 0, 0.75), new Vec3d(0.25, 1, 0.75), new Vec3d(0.75, 1, 0.75), new Vec3d(0.75, 0, 0.75), texture, OPO_MIN_U, OPO_MIN_V, OPO_MAX_U, OPO_MAX_V));

				result.add(createQuad(new Vec3d(0.75, 0, 0.25), new Vec3d(0.75, 1, 0.25), new Vec3d(0.25, 1, 0.25), new Vec3d(0.25, 0, 0.25), texture, OPO_MIN_U, OPO_MIN_V, OPO_MAX_U, OPO_MAX_V));
				result.add(createQuad(new Vec3d(0.25, 0, 0.25), new Vec3d(0.25, 1, 0.25), new Vec3d(0.75, 1, 0.25), new Vec3d(0.75, 0, 0.25), texture, OPO_MIN_U, OPO_MIN_V, OPO_MAX_U, OPO_MAX_V));

				return result;
			}

			// Just NORTH and SOUTH connects
			if (!up && !down && north && south && !east && !west) {
				result.add(createQuad(new Vec3d(0.25, 0.75, 0), new Vec3d(0.25, 0.75, 1), new Vec3d(0.25, 0.25, 1), new Vec3d(0.25, 0.25, 0), texture, OPO_MIN_U, OPO_MIN_V, OPO_MAX_U, OPO_MAX_V));
				result.add(createQuad(new Vec3d(0.25, 0.75, 1), new Vec3d(0.25, 0.75, 0), new Vec3d(0.25, 0.25, 0), new Vec3d(0.25, 0.25, 1), texture, OPO_MIN_U, OPO_MIN_V, OPO_MAX_U, OPO_MAX_V));

				result.add(createQuad(new Vec3d(0.75, 0.75, 0), new Vec3d(0.75, 0.75, 1), new Vec3d(0.75, 0.25, 1), new Vec3d(0.75, 0.25, 0), texture, OPO_MIN_U, OPO_MIN_V, OPO_MAX_U, OPO_MAX_V));
				result.add(createQuad(new Vec3d(0.75, 0.75, 1), new Vec3d(0.75, 0.75, 0), new Vec3d(0.75, 0.25, 0), new Vec3d(0.75, 0.25, 1), texture, OPO_MIN_U, OPO_MIN_V, OPO_MAX_U, OPO_MAX_V));

				result.add(createQuad(new Vec3d(0.75, 0.75, 0), new Vec3d(0.75, 0.75, 1), new Vec3d(0.25, 0.75, 1), new Vec3d(0.25, 0.75, 0), texture, OPO_MIN_U, OPO_MIN_V, OPO_MAX_U, OPO_MAX_V));
				result.add(createQuad(new Vec3d(0.75, 0.75, 1), new Vec3d(0.75, 0.75, 0), new Vec3d(0.25, 0.75, 0), new Vec3d(0.25, 0.75, 1), texture, OPO_MIN_U, OPO_MIN_V, OPO_MAX_U, OPO_MAX_V));

				result.add(createQuad(new Vec3d(0.75, 0.25, 0), new Vec3d(0.75, 0.25, 1), new Vec3d(0.25, 0.25, 1), new Vec3d(0.25, 0.25, 0), texture, OPO_MIN_U, OPO_MIN_V, OPO_MAX_U, OPO_MAX_V));
				result.add(createQuad(new Vec3d(0.75, 0.25, 1), new Vec3d(0.75, 0.25, 0), new Vec3d(0.25, 0.25, 0), new Vec3d(0.25, 0.25, 1), texture, OPO_MIN_U, OPO_MIN_V, OPO_MAX_U, OPO_MAX_V));

				return result;
			}

			// Just EAST and WESt connect
			if (!up && !down && !north && !south && east && west) {
				result.add(createQuad(new Vec3d(0, 0.75, 0.25), new Vec3d(1, 0.75, 0.25), new Vec3d(1, 0.25, 0.25), new Vec3d(0, 0.25, 0.25), texture, OPO_MIN_U, OPO_MIN_V, OPO_MAX_U, OPO_MAX_V));
				result.add(createQuad(new Vec3d(1, 0.75, 0.25), new Vec3d(0, 0.75, 0.25), new Vec3d(0, 0.25, 0.25), new Vec3d(1, 0.25, 0.25), texture, OPO_MIN_U, OPO_MIN_V, OPO_MAX_U, OPO_MAX_V));

				result.add(createQuad(new Vec3d(0, 0.75, 0.75), new Vec3d(1, 0.75, 0.75), new Vec3d(1, 0.25, 0.75), new Vec3d(0, 0.25, 0.75), texture, OPO_MIN_U, OPO_MIN_V, OPO_MAX_U, OPO_MAX_V));
				result.add(createQuad(new Vec3d(1, 0.75, 0.75), new Vec3d(0, 0.75, 0.75), new Vec3d(0, 0.25, 0.75), new Vec3d(1, 0.25, 0.75), texture, OPO_MIN_U, OPO_MIN_V, OPO_MAX_U, OPO_MAX_V));

				result.add(createQuad(new Vec3d(0, 0.25, 0.75), new Vec3d(1, 0.25, 0.75), new Vec3d(1, 0.25, 0.25), new Vec3d(0, 0.25, 0.25), texture, OPO_MIN_U, OPO_MIN_V, OPO_MAX_U, OPO_MAX_V));
				result.add(createQuad(new Vec3d(1, 0.25, 0.75), new Vec3d(0, 0.25, 0.75), new Vec3d(0, 0.25, 0.25), new Vec3d(1, 0.25, 0.25), texture, OPO_MIN_U, OPO_MIN_V, OPO_MAX_U, OPO_MAX_V));

				result.add(createQuad(new Vec3d(0, 0.75, 0.75), new Vec3d(1, 0.75, 0.75), new Vec3d(1, 0.75, 0.25), new Vec3d(0, 0.75, 0.25), texture, OPO_MIN_U, OPO_MIN_V, OPO_MAX_U, OPO_MAX_V));
				result.add(createQuad(new Vec3d(1, 0.75, 0.75), new Vec3d(0, 0.75, 0.75), new Vec3d(0, 0.75, 0.25), new Vec3d(1, 0.75, 0.25), texture, OPO_MIN_U, OPO_MIN_V, OPO_MAX_U, OPO_MAX_V));

				return result;
			}

			// Render as intersection if more than 2 connections
			if (up) {
				result.add(createQuad(new Vec3d(0.25, 0.75, 0.25), new Vec3d(0.25, 1, 0.25), new Vec3d(0.75, 1, 0.25), new Vec3d(0.75, 0.75, 0.25), texture, EXT_MIN_U, EXT_MIN_V, EXT_MAX_U, EXT_MAX_V));
				result.add(createQuad(new Vec3d(0.25, 1, 0.25), new Vec3d(0.25, 0.75, 0.25), new Vec3d(0.75, 0.75, 0.25), new Vec3d(0.75, 1, 0.25), texture, EXT_MIN_U, EXT_MIN_V, EXT_MAX_U, EXT_MAX_V));

				result.add(createQuad(new Vec3d(0.25, 0.75, 0.75), new Vec3d(0.25, 1, 0.75), new Vec3d(0.75, 1, 0.75), new Vec3d(0.75, 0.75, 0.75), texture, EXT_MIN_U, EXT_MIN_V, EXT_MAX_U, EXT_MAX_V));
				result.add(createQuad(new Vec3d(0.25, 1, 0.75), new Vec3d(0.25, 0.75, 0.75), new Vec3d(0.75, 0.75, 0.75), new Vec3d(0.75, 1, 0.75), texture, EXT_MIN_U, EXT_MIN_V, EXT_MAX_U, EXT_MAX_V));

				result.add(createQuad(new Vec3d(0.25, 1, 0.25), new Vec3d(0.25, 0.75, 0.25), new Vec3d(0.25, 0.75, 0.75), new Vec3d(0.25, 1, 0.75), texture, EXT_MIN_U, EXT_MIN_V, EXT_MAX_U, EXT_MAX_V));
				result.add(createQuad(new Vec3d(0.25, 0.75, 0.25), new Vec3d(0.25, 1, 0.25), new Vec3d(0.25, 1, 0.75), new Vec3d(0.25, 0.75, 0.75), texture, EXT_MIN_U, EXT_MIN_V, EXT_MAX_U, EXT_MAX_V));

				result.add(createQuad(new Vec3d(0.75, 1, 0.25), new Vec3d(0.75, 0.75, 0.25), new Vec3d(0.75, 0.75, 0.75), new Vec3d(0.75, 1, 0.75), texture, EXT_MIN_U, EXT_MIN_V, EXT_MAX_U, EXT_MAX_V));
				result.add(createQuad(new Vec3d(0.75, 0.75, 0.25), new Vec3d(0.75, 1, 0.25), new Vec3d(0.75, 1, 0.75), new Vec3d(0.75, 0.75, 0.75), texture, EXT_MIN_U, EXT_MIN_V, EXT_MAX_U, EXT_MAX_V));
			} else {
				result.add(createQuad(new Vec3d(0.25, 0.75, 0.25), new Vec3d(0.25, 0.75, 0.75), new Vec3d(0.75, 0.75, 0.75), new Vec3d(0.75, 0.75, 0.25), texture, CORE_MIN_U, CORE_MIN_V, CORE_MAX_U, CORE_MAX_V));
				result.add(createQuad(new Vec3d(0.25, 0.75, 0.25), new Vec3d(0.75, 0.75, 0.25), new Vec3d(0.75, 0.75, 0.75), new Vec3d(0.25, 0.75, 0.75), texture, CORE_MIN_U, CORE_MIN_V, CORE_MAX_U, CORE_MAX_V));
			}

			if (down) {
				result.add(createQuad(new Vec3d(0.25, 0.25, 0.25), new Vec3d(0.25, 0, 0.25), new Vec3d(0.75, 0, 0.25), new Vec3d(0.75, 0.25, 0.25), texture, EXT_MIN_U, EXT_MIN_V, EXT_MAX_U, EXT_MAX_V));
				result.add(createQuad(new Vec3d(0.25, 0, 0.25), new Vec3d(0.25, 0.25, 0.25), new Vec3d(0.75, 0.25, 0.25), new Vec3d(0.75, 0, 0.25), texture, EXT_MIN_U, EXT_MIN_V, EXT_MAX_U, EXT_MAX_V));

				result.add(createQuad(new Vec3d(0.25, 0.25, 0.75), new Vec3d(0.25, 0, 0.75), new Vec3d(0.75, 0, 0.75), new Vec3d(0.75, 0.25, 0.75), texture, EXT_MIN_U, EXT_MIN_V, EXT_MAX_U, EXT_MAX_V));
				result.add(createQuad(new Vec3d(0.25, 0, 0.75), new Vec3d(0.25, 0.25, 0.75), new Vec3d(0.75, 0.25, 0.75), new Vec3d(0.75, 0, 0.75), texture, EXT_MIN_U, EXT_MIN_V, EXT_MAX_U, EXT_MAX_V));

				result.add(createQuad(new Vec3d(0.25, 0, 0.25), new Vec3d(0.25, 0.25, 0.25), new Vec3d(0.25, 0.25, 0.75), new Vec3d(0.25, 0, 0.75), texture, EXT_MIN_U, EXT_MIN_V, EXT_MAX_U, EXT_MAX_V));
				result.add(createQuad(new Vec3d(0.25, 0.25, 0.25), new Vec3d(0.25, 0, 0.25), new Vec3d(0.25, 0, 0.75), new Vec3d(0.25, 0.25, 0.75), texture, EXT_MIN_U, EXT_MIN_V, EXT_MAX_U, EXT_MAX_V));

				result.add(createQuad(new Vec3d(0.75, 0, 0.25), new Vec3d(0.75, 0.25, 0.25), new Vec3d(0.75, 0.25, 0.75), new Vec3d(0.75, 0, 0.75), texture, EXT_MIN_U, EXT_MIN_V, EXT_MAX_U, EXT_MAX_V));
				result.add(createQuad(new Vec3d(0.75, 0.25, 0.25), new Vec3d(0.75, 0, 0.25), new Vec3d(0.75, 0, 0.75), new Vec3d(0.75, 0.25, 0.75), texture, EXT_MIN_U, EXT_MIN_V, EXT_MAX_U, EXT_MAX_V));
			} else {
				result.add(createQuad(new Vec3d(0.25, 0.25, 0.25), new Vec3d(0.75, 0.25, 0.25), new Vec3d(0.75, 0.25, 0.75), new Vec3d(0.25, 0.25, 0.75), texture, CORE_MIN_U, CORE_MIN_V, CORE_MAX_U, CORE_MAX_V));
				result.add(createQuad(new Vec3d(0.25, 0.25, 0.25), new Vec3d(0.25, 0.25, 0.75), new Vec3d(0.75, 0.25, 0.75), new Vec3d(0.75, 0.25, 0.25), texture, CORE_MIN_U, CORE_MIN_V, CORE_MAX_U, CORE_MAX_V));
			}

			if (north) {
				result.add(createQuad(new Vec3d(0.25, 0.25, 0.25), new Vec3d(0.25, 0.25, 0), new Vec3d(0.75, 0.25, 0), new Vec3d(0.75, 0.25, 0.25), texture, EXT_MIN_U, EXT_MIN_V, EXT_MAX_U, EXT_MAX_V));
				result.add(createQuad(new Vec3d(0.25, 0.25, 0), new Vec3d(0.25, 0.25, 0.25), new Vec3d(0.75, 0.25, 0.25), new Vec3d(0.75, 0.25, 0), texture, EXT_MIN_U, EXT_MIN_V, EXT_MAX_U, EXT_MAX_V));

				result.add(createQuad(new Vec3d(0.25, 0.75, 0.25), new Vec3d(0.25, 0.75, 0), new Vec3d(0.75, 0.75, 0), new Vec3d(0.75, 0.75, 0.25), texture, EXT_MIN_U, EXT_MIN_V, EXT_MAX_U, EXT_MAX_V));
				result.add(createQuad(new Vec3d(0.25, 0.75, 0), new Vec3d(0.25, 0.75, 0.25), new Vec3d(0.75, 0.75, 0.25), new Vec3d(0.75, 0.75, 0), texture, EXT_MIN_U, EXT_MIN_V, EXT_MAX_U, EXT_MAX_V));

				result.add(createQuad(new Vec3d(0.25, 0.25, 0), new Vec3d(0.25, 0.25, 0.25), new Vec3d(0.25, 0.75, 0.25), new Vec3d(0.25, 0.75, 0), texture, EXT_MIN_U, EXT_MIN_V, EXT_MAX_U, EXT_MAX_V));
				result.add(createQuad(new Vec3d(0.25, 0.25, 0.25), new Vec3d(0.25, 0.25, 0), new Vec3d(0.25, 0.75, 0), new Vec3d(0.25, 0.75, 0.25), texture, EXT_MIN_U, EXT_MIN_V, EXT_MAX_U, EXT_MAX_V));

				result.add(createQuad(new Vec3d(0.75, 0.25, 0), new Vec3d(0.75, 0.25, 0.25), new Vec3d(0.75, 0.75, 0.25), new Vec3d(0.75, 0.75, 0), texture, EXT_MIN_U, EXT_MIN_V, EXT_MAX_U, EXT_MAX_V));
				result.add(createQuad(new Vec3d(0.75, 0.25, 0.25), new Vec3d(0.75, 0.25, 0), new Vec3d(0.75, 0.75, 0), new Vec3d(0.75, 0.75, 0.25), texture, EXT_MIN_U, EXT_MIN_V, EXT_MAX_U, EXT_MAX_V));
			} else {
				result.add(createQuad(new Vec3d(0.25, 0.25, 0.25), new Vec3d(0.25, 0.75, 0.25), new Vec3d(0.75, 0.75, 0.25), new Vec3d(0.75, 0.25, 0.25), texture, CORE_MIN_U, CORE_MIN_V, CORE_MAX_U, CORE_MAX_V));
				result.add(createQuad(new Vec3d(0.25, 0.25, 0.25), new Vec3d(0.75, 0.25, 0.25), new Vec3d(0.75, 0.75, 0.25), new Vec3d(0.25, 0.75, 0.25), texture, CORE_MIN_U, CORE_MIN_V, CORE_MAX_U, CORE_MAX_V));
			}

			if (south) {
				result.add(createQuad(new Vec3d(0.25, 0.25, 0.75), new Vec3d(0.25, 0.25, 1), new Vec3d(0.75, 0.25, 1), new Vec3d(0.75, 0.25, 0.75), texture, EXT_MIN_U, EXT_MIN_V, EXT_MAX_U, EXT_MAX_V));
				result.add(createQuad(new Vec3d(0.25, 0.25, 1), new Vec3d(0.25, 0.25, 0.75), new Vec3d(0.75, 0.25, 0.75), new Vec3d(0.75, 0.25, 1), texture, EXT_MIN_U, EXT_MIN_V, EXT_MAX_U, EXT_MAX_V));

				result.add(createQuad(new Vec3d(0.25, 0.75, 0.75), new Vec3d(0.25, 0.75, 1), new Vec3d(0.75, 0.75, 1), new Vec3d(0.75, 0.75, 0.75), texture, EXT_MIN_U, EXT_MIN_V, EXT_MAX_U, EXT_MAX_V));
				result.add(createQuad(new Vec3d(0.25, 0.75, 1), new Vec3d(0.25, 0.75, 0.75), new Vec3d(0.75, 0.75, 0.75), new Vec3d(0.75, 0.75, 1), texture, EXT_MIN_U, EXT_MIN_V, EXT_MAX_U, EXT_MAX_V));

				result.add(createQuad(new Vec3d(0.25, 0.25, 1), new Vec3d(0.25, 0.25, 0.75), new Vec3d(0.25, 0.75, 0.75), new Vec3d(0.25, 0.75, 1), texture, EXT_MIN_U, EXT_MIN_V, EXT_MAX_U, EXT_MAX_V));
				result.add(createQuad(new Vec3d(0.25, 0.25, 0.75), new Vec3d(0.25, 0.25, 1), new Vec3d(0.25, 0.75, 1), new Vec3d(0.25, 0.75, 0.75), texture, EXT_MIN_U, EXT_MIN_V, EXT_MAX_U, EXT_MAX_V));

				result.add(createQuad(new Vec3d(0.75, 0.25, 1), new Vec3d(0.75, 0.25, 0.75), new Vec3d(0.75, 0.75, 0.75), new Vec3d(0.75, 0.75, 1), texture, EXT_MIN_U, EXT_MIN_V, EXT_MAX_U, EXT_MAX_V));
				result.add(createQuad(new Vec3d(0.75, 0.25, 0.75), new Vec3d(0.75, 0.25, 1), new Vec3d(0.75, 0.75, 1), new Vec3d(0.75, 0.75, 0.75), texture, EXT_MIN_U, EXT_MIN_V, EXT_MAX_U, EXT_MAX_V));
			} else {
				result.add(createQuad(new Vec3d(0.25, 0.25, 0.75), new Vec3d(0.75, 0.25, 0.75), new Vec3d(0.75, 0.75, 0.75), new Vec3d(0.25, 0.75, 0.75), texture, CORE_MIN_U, CORE_MIN_V, CORE_MAX_U, CORE_MAX_V));
				result.add(createQuad(new Vec3d(0.25, 0.25, 0.75), new Vec3d(0.25, 0.75, 0.75), new Vec3d(0.75, 0.75, 0.75), new Vec3d(0.75, 0.25, 0.75), texture, CORE_MIN_U, CORE_MIN_V, CORE_MAX_U, CORE_MAX_V));
			}

			if (east) {
				result.add(createQuad(new Vec3d(0.75, 0.25, 0.25), new Vec3d(1, 0.25, 0.25), new Vec3d(1, 0.75, 0.25), new Vec3d(0.75, 0.75, 0.25), texture, EXT_MIN_U, EXT_MIN_V, EXT_MAX_U, EXT_MAX_V));
				result.add(createQuad(new Vec3d(1, 0.25, 0.25), new Vec3d(0.75, 0.25, 0.25), new Vec3d(0.75, 0.75, 0.25), new Vec3d(1, 0.75, 0.25), texture, EXT_MIN_U, EXT_MIN_V, EXT_MAX_U, EXT_MAX_V));

				result.add(createQuad(new Vec3d(0.75, 0.25, 0.75), new Vec3d(1, 0.25, 0.75), new Vec3d(1, 0.75, 0.75), new Vec3d(0.75, 0.75, 0.75), texture, EXT_MIN_U, EXT_MIN_V, EXT_MAX_U, EXT_MAX_V));
				result.add(createQuad(new Vec3d(1, 0.25, 0.75), new Vec3d(0.75, 0.25, 0.75), new Vec3d(0.75, 0.75, 0.75), new Vec3d(1, 0.75, 0.75), texture, EXT_MIN_U, EXT_MIN_V, EXT_MAX_U, EXT_MAX_V));

				result.add(createQuad(new Vec3d(1, 0.25, 0.25), new Vec3d(0.75, 0.25, 0.25), new Vec3d(0.75, 0.25, 0.75), new Vec3d(1, 0.25, 0.75), texture, EXT_MIN_U, EXT_MIN_V, EXT_MAX_U, EXT_MAX_V));
				result.add(createQuad(new Vec3d(0.75, 0.25, 0.25), new Vec3d(1, 0.25, 0.25), new Vec3d(1, 0.25, 0.75), new Vec3d(0.75, 0.25, 0.75), texture, EXT_MIN_U, EXT_MIN_V, EXT_MAX_U, EXT_MAX_V));

				result.add(createQuad(new Vec3d(1, 0.75, 0.25), new Vec3d(0.75, 0.75, 0.25), new Vec3d(0.75, 0.75, 0.75), new Vec3d(1, 0.75, 0.75), texture, EXT_MIN_U, EXT_MIN_V, EXT_MAX_U, EXT_MAX_V));
				result.add(createQuad(new Vec3d(0.75, 0.75, 0.25), new Vec3d(1, 0.75, 0.25), new Vec3d(1, 0.75, 0.75), new Vec3d(0.75, 0.75, 0.75), texture, EXT_MIN_U, EXT_MIN_V, EXT_MAX_U, EXT_MAX_V));
			} else {
				result.add(createQuad(new Vec3d(0.75, 0.25, 0.25), new Vec3d(0.75, 0.75, 0.25), new Vec3d(0.75, 0.75, 0.75), new Vec3d(0.75, 0.25, 0.75), texture, CORE_MIN_U, CORE_MIN_V, CORE_MAX_U, CORE_MAX_V));
				result.add(createQuad(new Vec3d(0.75, 0.25, 0.25), new Vec3d(0.75, 0.25, 0.75), new Vec3d(0.75, 0.75, 0.75), new Vec3d(0.75, 0.75, 0.25), texture, CORE_MIN_U, CORE_MIN_V, CORE_MAX_U, CORE_MAX_V));
			}

			if (west) {
				result.add(createQuad(new Vec3d(0.25, 0.25, 0.25), new Vec3d(0, 0.25, 0.25), new Vec3d(0, 0.75, 0.25), new Vec3d(0.25, 0.75, 0.25), texture, EXT_MIN_U, EXT_MIN_V, EXT_MAX_U, EXT_MAX_V));
				result.add(createQuad(new Vec3d(0, 0.25, 0.25), new Vec3d(0.25, 0.25, 0.25), new Vec3d(0.25, 0.75, 0.25), new Vec3d(0, 0.75, 0.25), texture, EXT_MIN_U, EXT_MIN_V, EXT_MAX_U, EXT_MAX_V));

				result.add(createQuad(new Vec3d(0.25, 0.25, 0.75), new Vec3d(0, 0.25, 0.75), new Vec3d(0, 0.75, 0.75), new Vec3d(0.25, 0.75, 0.75), texture, EXT_MIN_U, EXT_MIN_V, EXT_MAX_U, EXT_MAX_V));
				result.add(createQuad(new Vec3d(0, 0.25, 0.75), new Vec3d(0.25, 0.25, 0.75), new Vec3d(0.25, 0.75, 0.75), new Vec3d(0, 0.75, 0.75), texture, EXT_MIN_U, EXT_MIN_V, EXT_MAX_U, EXT_MAX_V));

				result.add(createQuad(new Vec3d(0, 0.25, 0.25), new Vec3d(0.25, 0.25, 0.25), new Vec3d(0.25, 0.25, 0.75), new Vec3d(0, 0.25, 0.75), texture, EXT_MIN_U, EXT_MIN_V, EXT_MAX_U, EXT_MAX_V));
				result.add(createQuad(new Vec3d(0.25, 0.25, 0.25), new Vec3d(0, 0.25, 0.25), new Vec3d(0, 0.25, 0.75), new Vec3d(0.25, 0.25, 0.75), texture, EXT_MIN_U, EXT_MIN_V, EXT_MAX_U, EXT_MAX_V));
				result.add(createQuad(new Vec3d(0, 0.75, 0.25), new Vec3d(0.25, 0.75, 0.25), new Vec3d(0.25, 0.75, 0.75), new Vec3d(0, 0.75, 0.75), texture, EXT_MIN_U, EXT_MIN_V, EXT_MAX_U, EXT_MAX_V));
				result.add(createQuad(new Vec3d(0.25, 0.75, 0.25), new Vec3d(0, 0.75, 0.25), new Vec3d(0, 0.75, 0.75), new Vec3d(0.25, 0.75, 0.75), texture, EXT_MIN_U, EXT_MIN_V, EXT_MAX_U, EXT_MAX_V));
			} else {
				result.add(createQuad(new Vec3d(0.25, 0.25, 0.25), new Vec3d(0.25, 0.25, 0.75), new Vec3d(0.25, 0.75, 0.75), new Vec3d(0.25, 0.75, 0.25), texture, CORE_MIN_U, CORE_MIN_V, CORE_MAX_U, CORE_MAX_V));
				result.add(createQuad(new Vec3d(0.25, 0.25, 0.25), new Vec3d(0.25, 0.75, 0.25), new Vec3d(0.25, 0.75, 0.75), new Vec3d(0.25, 0.25, 0.75), texture, CORE_MIN_U, CORE_MIN_V, CORE_MAX_U, CORE_MAX_V));
			}

			return result;
		}
		return result;
	}

	@Override
	public boolean isAmbientOcclusion() {
		return true;
	}

	@Override
	public boolean isGui3d() {
		return true;
	}

	@Override
	public boolean isBuiltInRenderer() {
		return false;
	}

	@Override
	public TextureAtlasSprite getParticleTexture() {
		return this.texture;
	}

	@Override
	public ItemCameraTransforms getItemCameraTransforms() {
		return ItemCameraTransforms.DEFAULT;
	}

	@Override
	public ItemOverrideList getOverrides() {
		return ItemOverrideList.NONE;
	}

	@Override
	public Pair<? extends IBakedModel, Matrix4f> handlePerspective(TransformType cameraTransformType) {
		return MapWrapper.handlePerspective(this, MapWrapper.getTransforms(getItemCameraTransforms()), cameraTransformType);
	}

	private void putVertex(UnpackedBakedQuad.Builder builder, Vec3d normal, double x, double y, double z, float u, float v, TextureAtlasSprite sprite) {
		for (int e = 0; e < format.getElementCount(); e++) {
			switch (format.getElement(e).getUsage()) {
				case POSITION:
					builder.put(e, (float) x, (float) y, (float) z, 1.0f);
					break;
				case COLOR:
					builder.put(e, 1.0f, 1.0f, 1.0f, 1.0f);
					break;
				case UV:
					if (format.getElement(e).getIndex() == 0) {
						u = sprite.getInterpolatedU(u);
						v = sprite.getInterpolatedV(v);
						builder.put(e, u, v, 0f, 1f);
						break;
					}
				case NORMAL:
					builder.put(e, (float) normal.xCoord, (float) normal.yCoord, (float) normal.zCoord, 0f);
					break;
				default:
					builder.put(e);
					break;
			}
		}
	}

	private BakedQuad createQuad(Vec3d v1, Vec3d v2, Vec3d v3, Vec3d v4, TextureAtlasSprite sprite, float uMin, float vMin, float uMax, float vMax) {
		Vec3d normal = v1.subtract(v2).crossProduct(v3.subtract(v2));
		UnpackedBakedQuad.Builder builder = new UnpackedBakedQuad.Builder(format);
		builder.setTexture(sprite);
		builder.setApplyDiffuseLighting(false);
		putVertex(builder, normal, v1.xCoord, v1.yCoord, v1.zCoord, uMin, vMin, sprite);
		putVertex(builder, normal, v2.xCoord, v2.yCoord, v2.zCoord, uMin, vMax, sprite);
		putVertex(builder, normal, v3.xCoord, v3.yCoord, v3.zCoord, uMax, vMax, sprite);
		putVertex(builder, normal, v4.xCoord, v4.yCoord, v4.zCoord, uMax, vMin, sprite);
		return builder.build();
	}
}

 

To register the mode I use a ModelBakeEvent in the class ModelEventHandler.java

package mod.indfab.client;

import mod.indfab.IndFab;
import mod.indfab.client.render.TileTubeRenderer;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.event.ModelBakeEvent;
import net.minecraftforge.client.event.TextureStitchEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

public class ModelEventHandler {

	private static final ResourceLocation TUBE_TEX = new ResourceLocation(IndFab.MOD_ID, "blocks/block_tube");

	@SubscribeEvent
	public void onTextureStichEvent(TextureStitchEvent.Pre event) {
		if (event.isCanceled())
			return;

		event.getMap().registerSprite(TUBE_TEX);
	}

	@SubscribeEvent
	public void onModelBakeEvet(ModelBakeEvent event) {

		Object modelObj = event.getModelRegistry().getObject(TileTubeRenderer.BLOCK_MRL_NOMAL);

		if (modelObj instanceof IBakedModel) {
			TextureAtlasSprite tex = Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(TUBE_TEX.toString());
			event.getModelRegistry().putObject(TileTubeRenderer.BLOCK_MRL_NOMAL, new TileTubeRenderer(tex));
		}

	}

}

 

I have also  tried to register the "inventory" variant from the event but it also doesn't show the model as an item

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.