Jump to content

Recommended Posts

Posted (edited)

Iv'e been trying to figure out how to change the texture of model elements independently, I followed TheGreyGhost's tutorial I'm moderately experienced at modding but, I haven't found many tutorials on how Imodels work or how to use the retexture method, Iv'e got the base model working, now I need the elements around the core to change texture depending on an int value, the int values will be set by the blocks around it. Also would I need it to be a tile entity if I want it to keep the texture changes? here is what I have so far

Block

import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.property.ExtendedBlockState;
import net.minecraftforge.common.property.IExtendedBlockState;
import net.minecraftforge.common.property.IUnlistedProperty;
import net.minecraftforge.common.property.Properties;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import omni.crystals.block.LinkBlock;

public class Core2Block extends LinkBlock
{
	public static final IUnlistedProperty<Boolean> LINK_NORTH = new Properties.PropertyAdapter<Boolean>(PropertyBool.create("link_north"));
	public static final IUnlistedProperty<Boolean> LINK_SOUTH = new Properties.PropertyAdapter<Boolean>(PropertyBool.create("link_south"));
	public static final IUnlistedProperty<Boolean> LINK_WEST = new Properties.PropertyAdapter<Boolean>(PropertyBool.create("link_west"));
	public static final IUnlistedProperty<Boolean> LINK_EAST = new Properties.PropertyAdapter<Boolean>(PropertyBool.create("link_east"));
	public static final IUnlistedProperty<Boolean> LINK_UP = new Properties.PropertyAdapter<Boolean>(PropertyBool.create("link_up"));
	public static final IUnlistedProperty<Boolean> LINK_DOWN = new Properties.PropertyAdapter<Boolean>(PropertyBool.create("link_down"));
	public static final IUnlistedProperty<Boolean> LINK_X = new Properties.PropertyAdapter<Boolean>(PropertyBool.create("link_x"));
	public static final IUnlistedProperty<Boolean> LINK_Y = new Properties.PropertyAdapter<Boolean>(PropertyBool.create("link_y"));
	public static final IUnlistedProperty<Boolean> LINK_Z = new Properties.PropertyAdapter<Boolean>(PropertyBool.create("link_z"));
	public static boolean linknorth;
	public static boolean linksouth;
	public static boolean linkwest;
	public static boolean linkeast;
	public static boolean linkup;
	public static boolean linkdown;
	public static boolean linkx = true;
	public static boolean linky = true;
	public static boolean linkz = true;
	public static int NWD;
	public static int ND;
	public static int NED;
	public static int WD;
	public static int D = 6;
	public static int ED;
	public static int SWD;
	public static int SD;
	public static int SED;
	public static int NW;
	public static int N = 6;
	public static int NE;
	public static int W = 6;
	public static int E = 6;
	public static int SW;
	public static int S = 6;
	public static int SE;
	public static int NWU;
	public static int NU;
	public static int NEU;
	public static int WU;
	public static int U = 6;
	public static int EU;
	public static int SWU;
	public static int SU;
	public static int SEU;
	public Core2Block(String name, Material material, float Hardness, float resistance, int energy)
	{
		super(name, material, Hardness, resistance, energy);
	}
	@SideOnly(Side.CLIENT)
	public BlockRenderLayer getBlockLayer()
	{
		return BlockRenderLayer.SOLID;
	}
	@Override
	public boolean isOpaqueCube(IBlockState blockState)
	{
		return false;
	}
	@Override
	public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn)
	{
	}
	@Override
	public boolean isFullCube(IBlockState blockState)
	{
		return false;
	}
	@Override
	public EnumBlockRenderType getRenderType(IBlockState iBlockState)
	{
		return EnumBlockRenderType.MODEL;
	}
	@Override
	protected BlockStateContainer createBlockState()
	{
		IProperty [] listedProperties = new IProperty[0];
		IUnlistedProperty [] unlistedProperties = new IUnlistedProperty[] {LINK_NORTH, LINK_SOUTH, LINK_EAST, LINK_WEST, LINK_UP, LINK_DOWN, LINK_X, LINK_Y, LINK_Z};
		return new ExtendedBlockState(this, listedProperties, unlistedProperties);
	}
	@Override
	public IBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos pos)
	{
		if (state instanceof IExtendedBlockState)
		{  // avoid crash in case of mismatch
			IExtendedBlockState retval = (IExtendedBlockState)state;
			retval = retval.withProperty(LINK_NORTH, linknorth);
			retval = retval.withProperty(LINK_SOUTH, linksouth);
			retval = retval.withProperty(LINK_EAST, linkeast);
			retval = retval.withProperty(LINK_WEST, linkwest);
			retval = retval.withProperty(LINK_UP, linkup);
			retval = retval.withProperty(LINK_DOWN, linkdown);
			retval = retval.withProperty(LINK_X, linkx);
			retval = retval.withProperty(LINK_Y, linky);
			retval = retval.withProperty(LINK_Z, linkz);
			return retval;
		}
		return state;
	}
}

 

 compositemodel


import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.model.*;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.client.model.IPerspectiveAwareModel;
import net.minecraftforge.common.model.TRSRTransformation;
import net.minecraftforge.common.property.IExtendedBlockState;
import net.minecraftforge.common.property.IUnlistedProperty;
import org.apache.commons.lang3.tuple.Pair;

import javax.annotation.Nullable;
import javax.vecmath.Matrix4f;
import java.util.LinkedList;
import java.util.List;

public class CompositeModel implements IPerspectiveAwareModel
{
	private IBakedModel modelCore;
	private IBakedModel modelNorth;
	private IBakedModel modelSouth;
	private IBakedModel modelWest;
	private IBakedModel modelEast;
	private IBakedModel modelUp;
	private IBakedModel modelDown;
	private IBakedModel modelX;
	private IBakedModel modelY;
	private IBakedModel modelZ;
	public CompositeModel(IBakedModel i_modelCore, IBakedModel i_modelNorth, IBakedModel i_modelSouth, IBakedModel i_modelWest, IBakedModel i_modelEast, IBakedModel i_modelUp, IBakedModel i_modelDown, IBakedModel i_modelX, IBakedModel i_modelY, IBakedModel i_modelZ)
	{
		modelCore = i_modelCore;
		modelNorth = i_modelNorth;
		modelSouth = i_modelSouth;
		modelWest = i_modelWest;
		modelEast = i_modelEast;
		modelUp = i_modelUp;
		modelDown = i_modelDown;
		modelX = i_modelX;
		modelY = i_modelY;
		modelZ = i_modelZ;
	}
	/**
	 * Compile a list of quads for rendering.  This is done by making a list of all the quads from the component
	 *   models, depending on which links are present.
	 * For example
	 * @param blockState
	 * @param side which side of the block is being rendered; null =
	 * @param rand
	 * @return
	 */
	@Override
	public List<BakedQuad> getQuads(@Nullable IBlockState blockState, @Nullable EnumFacing side, long rand)
	{
		List<BakedQuad> quadsList = new LinkedList<BakedQuad>();
		quadsList.addAll(modelCore.getQuads(blockState, side, rand));
		if (!(blockState instanceof IExtendedBlockState))
		{
			return quadsList;
		}
		IExtendedBlockState extendedBlockState = (IExtendedBlockState)blockState;
		if (isLinkPresent(extendedBlockState, Core2Block.LINK_NORTH))
		{
			quadsList.addAll(modelNorth.getQuads(extendedBlockState, side, rand));
		}
		if (isLinkPresent(extendedBlockState, Core2Block.LINK_SOUTH))
		{
			quadsList.addAll(modelSouth.getQuads(extendedBlockState, side, rand));
		}
		if (isLinkPresent(extendedBlockState, Core2Block.LINK_WEST))
		{
			quadsList.addAll(modelWest.getQuads(extendedBlockState, side, rand));
		}
		if (isLinkPresent(extendedBlockState, Core2Block.LINK_EAST))
		{
			quadsList.addAll(modelEast.getQuads(extendedBlockState, side, rand));
		}
		if (isLinkPresent(extendedBlockState, Core2Block.LINK_UP))
		{
			quadsList.addAll(modelUp.getQuads(extendedBlockState, side, rand));
		}
		if (isLinkPresent(extendedBlockState, Core2Block.LINK_DOWN))
		{
			quadsList.addAll(modelDown.getQuads(extendedBlockState, side, rand));
		}
		if (isLinkPresent(extendedBlockState, Core2Block.LINK_X))
		{
			quadsList.addAll(modelX.getQuads(extendedBlockState, side, rand));
		}
		if (isLinkPresent(extendedBlockState, Core2Block.LINK_Y))
		{
			quadsList.addAll(modelY.getQuads(extendedBlockState, side, rand));
		}
		if (isLinkPresent(extendedBlockState, Core2Block.LINK_Z))
		{
			quadsList.addAll(modelZ.getQuads(extendedBlockState, side, rand));
		}
		return quadsList;
	}
	@Override
	public boolean isAmbientOcclusion()
	{
		return modelCore.isAmbientOcclusion();
	}
	@Override
	public boolean isGui3d()
	{
		return modelCore.isGui3d();
	}
	@Override
	public boolean isBuiltInRenderer()
	{
		return false;
	}
	// used for block breaking shards
	@Override
	public TextureAtlasSprite getParticleTexture()
	{
		TextureAtlasSprite textureAtlasSprite = Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite("crystal:blocks/crysidian");
		return textureAtlasSprite;
	}
	@Override
	public ItemCameraTransforms getItemCameraTransforms()
	{
		return modelCore.getItemCameraTransforms();
	}
	/** this method is necessary because Forge has deprecated getItemCameraTransforms(), and modelCore.getItemCameraTransforms()
	 *    may not return anything meaningful.  But if the base model doesn't implement IPerspectiveAwareModel then you
	 *    need to generate it.
	 * @param cameraTransformType
	 * @return
	 */
	@Override
	public Pair<? extends IBakedModel, Matrix4f> handlePerspective(ItemCameraTransforms.TransformType cameraTransformType)
	{
		if (modelCore instanceof IPerspectiveAwareModel)
		{
			Matrix4f matrix4f = ((IPerspectiveAwareModel)modelCore).handlePerspective(cameraTransformType).getRight();
			return Pair.of(this, matrix4f);
		}
		else
		{
			// If the parent model isn't an IPerspectiveAware, we'll need to generate the correct matrix ourselves using the
			//  ItemCameraTransforms.
			ItemCameraTransforms itemCameraTransforms = modelCore.getItemCameraTransforms();
			ItemTransformVec3f itemTransformVec3f = itemCameraTransforms.getTransform(cameraTransformType);
			TRSRTransformation tr = new TRSRTransformation(itemTransformVec3f);
			Matrix4f mat = null;
			if (tr != null)
			{ 
				mat = tr.getMatrix();
			}
			// The TRSRTransformation for vanilla items have blockCenterToCorner() applied, however handlePerspective
			//  reverses it back again with blockCornerToCenter().  So we don't need to apply it here.

			return Pair.of(this, mat);
		}
	}
	@Override
	public ItemOverrideList getOverrides()
	{
		return null;
	}
	private boolean isLinkPresent(IExtendedBlockState iExtendedBlockState, IUnlistedProperty<Boolean> whichLink)
	{
		Boolean link = iExtendedBlockState.getValue(whichLink);
		if (link == null)
		{
			return false;
		}
		return link;
	}
}

Model

import com.google.common.base.Function;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;

import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.vertex.VertexFormat;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.model.IModel;
import net.minecraftforge.client.model.IRetexturableModel;
import net.minecraftforge.client.model.ModelLoaderRegistry;
import net.minecraftforge.common.model.IModelState;
import net.minecraftforge.fluids.Fluid;

import java.util.Collection;

import javax.annotation.Nullable;

/**
 * Created by TheGreyGhost on 22/04/2015.
 * WebModel is an intermediate step between the ModelResourceLocation and the final IBakedModel.
 * In this case, our IModel has a number of dependant sub-components.  We bake them all individually and store them
 *   in the CompositeModel.
 * Each of the submodels needs to be loaded by vanilla as a block model which means we need a blockstates file for each of them.
 *   see blockstates/mbe05_web_subblocks
 */
public class Core2Model implements IModel, IRetexturableModel
{
	public static final ResourceLocation TEXTURE_CORE = new ResourceLocation("crystal:blocks/crysidian");
	public static final ResourceLocation TEXTURE_RED = new ResourceLocation("crystal:blocks/crystal_red");
	public static final ResourceLocation TEXTURE_ORANGE = new ResourceLocation("crystal:blocks/crystal_orange");
	public static final ResourceLocation TEXTURE_YELLOW = new ResourceLocation("crystal:blocks/crystal_yellow");
	public static final ResourceLocation TEXTURE_GREEN = new ResourceLocation("crystal:blocks/crystal_green");
	public static final ResourceLocation TEXTURE_BLUE = new ResourceLocation("crystal:blocks/crystal_blue");
	public static final ResourceLocation TEXTURE_INDIGO = new ResourceLocation("crystal:blocks/crystal_indigo");
	public static final ResourceLocation TEXTURE_PURPLE = new ResourceLocation("crystal:blocks/crystal_purple");
	public static final ModelResourceLocation MODEL_CORE = new ModelResourceLocation("crystal:crystal_core");
	public static final ModelResourceLocation MODEL_NORTH = new ModelResourceLocation("crystal:core_link_north");
	public static final ModelResourceLocation MODEL_SOUTH = new ModelResourceLocation("crystal:core_link_south");
	public static final ModelResourceLocation MODEL_WEST = new ModelResourceLocation("crystal:core_link_west");
	public static final ModelResourceLocation MODEL_EAST = new ModelResourceLocation("crystal:core_link_east");
	public static final ModelResourceLocation MODEL_UP = new ModelResourceLocation("crystal:core_link_up");
	public static final ModelResourceLocation MODEL_DOWN = new ModelResourceLocation("crystal:core_link_down");
	public static final ModelResourceLocation MODEL_X = new ModelResourceLocation("crystal:core_link_x");
	public static final ModelResourceLocation MODEL_Y = new ModelResourceLocation("crystal:core_link_y");
	public static final ModelResourceLocation MODEL_Z = new ModelResourceLocation("crystal:core_link_z");

	@Nullable
	public final ResourceLocation NWD;
	@Nullable
	public final ResourceLocation ND;
	@Nullable
	public final ResourceLocation NED;
	@Nullable
	public final ResourceLocation WD;
	@Nullable
	public final ResourceLocation D;
	@Nullable
	public final ResourceLocation ED;
	@Nullable
	public final ResourceLocation SWD;
	@Nullable
	public final ResourceLocation SD;
	@Nullable
	public final ResourceLocation SED;
	@Nullable
	public final ResourceLocation NW;
	@Nullable
	public final ResourceLocation N;
	@Nullable
	public final ResourceLocation NE;
	@Nullable
	public final ResourceLocation W;
	@Nullable
	public final ResourceLocation E;
	@Nullable
	public final ResourceLocation SW;
	@Nullable
	public final ResourceLocation S;
	@Nullable
	public final ResourceLocation SE;
	@Nullable
	public final ResourceLocation NWU;
	@Nullable
	public final ResourceLocation NU;
	@Nullable
	public final ResourceLocation NEU;
	@Nullable
	public final ResourceLocation WU;
	@Nullable
	public final ResourceLocation U;
	@Nullable
	public final ResourceLocation EU;
	@Nullable
	public final ResourceLocation SWU;
	@Nullable
	public final ResourceLocation SU;
	@Nullable
	public final ResourceLocation SEU;
	public Core2Model()
	{
		this(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null);
	}
	public Core2Model(@Nullable ResourceLocation l1, @Nullable ResourceLocation l2, @Nullable ResourceLocation l3, @Nullable ResourceLocation l4, @Nullable ResourceLocation l5, @Nullable ResourceLocation l6, @Nullable ResourceLocation l7, @Nullable ResourceLocation l8, @Nullable ResourceLocation l9, @Nullable ResourceLocation l10, @Nullable ResourceLocation l11, @Nullable ResourceLocation l12, @Nullable ResourceLocation l13, @Nullable ResourceLocation l14, @Nullable ResourceLocation l15, @Nullable ResourceLocation l16, @Nullable ResourceLocation l17, @Nullable ResourceLocation l18, @Nullable ResourceLocation l19, @Nullable ResourceLocation l20, @Nullable ResourceLocation l21, @Nullable ResourceLocation l22, @Nullable ResourceLocation l23, @Nullable ResourceLocation l24, @Nullable ResourceLocation l25, @Nullable ResourceLocation l26)
	{
		this.NWD = l1; this.ND = l2; this.NED = l3; this.WD = l4; this.D = l5; this.ED = l6; this.SWD = l7; this.SD = l8;
		this.SED = l9; this.NW = l10; this.N = l11; this.NE = l12; this.W = l13; this.E = l14; this.SW = l15; this.S = l16;
		this.SE = l17; this.NWU = l18; this.NU = l19; this.NEU = l20; this.WU = l21; this.U = l22; this.EU = l23; this.SWU = l24;
		this.SU = l25; this.SEU = l26;
	}
	// return all other resources used by this model (not strictly needed for this example because we load all the subcomponent
	//   models during the bake anyway)
	@Override
	public Collection<ResourceLocation> getDependencies()
	{
		return ImmutableList.copyOf(new ResourceLocation[]{MODEL_CORE, MODEL_WEST, MODEL_EAST, MODEL_NORTH, MODEL_SOUTH, MODEL_UP, MODEL_DOWN, MODEL_X, MODEL_Y, MODEL_Z});
	}
	// return all the textures used by this model (not strictly needed for this example because we load all the subcomponent
	//   models during the bake anyway)
	@Override
	public Collection<ResourceLocation> getTextures()
	{
		return ImmutableList.copyOf(new ResourceLocation[]{TEXTURE_CORE, TEXTURE_RED, TEXTURE_ORANGE, TEXTURE_YELLOW, TEXTURE_GREEN, TEXTURE_BLUE, TEXTURE_INDIGO, TEXTURE_PURPLE});
	}
	//  Bake the subcomponents into a CompositeModel
	@Override
	public IBakedModel bake(IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter)
	{
		try
		{
			IModel subComponent = ModelLoaderRegistry.getModel(MODEL_CORE);
			IBakedModel bakedModelCore = subComponent.bake(state, format, bakedTextureGetter);
			subComponent = ModelLoaderRegistry.getModel(MODEL_NORTH);
			IBakedModel bakedModelNorth = subComponent.bake(state, format, bakedTextureGetter);
			subComponent = ModelLoaderRegistry.getModel(MODEL_SOUTH);
			IBakedModel bakedModelSouth = subComponent.bake(state, format, bakedTextureGetter);
			subComponent = ModelLoaderRegistry.getModel(MODEL_WEST);
			IBakedModel bakedModelWest = subComponent.bake(state, format, bakedTextureGetter);
			subComponent = ModelLoaderRegistry.getModel(MODEL_EAST);
			IBakedModel bakedModelEast = subComponent.bake(state, format, bakedTextureGetter);
			subComponent = ModelLoaderRegistry.getModel(MODEL_UP);
			IBakedModel bakedModelUp = subComponent.bake(state, format, bakedTextureGetter);
			subComponent = ModelLoaderRegistry.getModel(MODEL_DOWN);
			IBakedModel bakedModelDown = subComponent.bake(state, format, bakedTextureGetter);
			subComponent = ModelLoaderRegistry.getModel(MODEL_X);
			IBakedModel bakedModelX = subComponent.bake(state, format, bakedTextureGetter);
			subComponent = ModelLoaderRegistry.getModel(MODEL_Y);
			IBakedModel bakedModelY = subComponent.bake(state, format, bakedTextureGetter);
			subComponent = ModelLoaderRegistry.getModel(MODEL_Z);
			IBakedModel bakedModelZ = subComponent.bake(state, format, bakedTextureGetter);

			return new CompositeModel(bakedModelCore, bakedModelNorth, bakedModelSouth, bakedModelWest, bakedModelEast, bakedModelUp, bakedModelDown, bakedModelX, bakedModelY, bakedModelZ);
		}
		catch (Exception exception)
		{
			System.err.println("Core2Model.bake() failed due to exception:" + exception);
			return ModelLoaderRegistry.getMissingModel().bake(state, format, bakedTextureGetter);
		}
	}
	// Our custom loaded doesn't need a default state, just return null
	@Override
	public IModelState getDefaultState()
	{
		return null;
	}
	@Override
	public IModel retexture(ImmutableMap<String, String> textures)
	{
		ResourceLocation nwd = NWD;
		ResourceLocation nd = ND;
		ResourceLocation ned = NED;
		ResourceLocation wd = WD;
		ResourceLocation d = D;
		ResourceLocation ed = ED;
		ResourceLocation swd = SWD;
		ResourceLocation sd = SD;
		ResourceLocation sed = SED;
		ResourceLocation nw = NW;
		ResourceLocation n = N;
		ResourceLocation ne = NE;
		ResourceLocation w = W;
		ResourceLocation e = E;
		ResourceLocation sw = SW;
		ResourceLocation s = S;
		ResourceLocation se = SE;
		ResourceLocation nwu = NWU;
		ResourceLocation nu = NU;
		ResourceLocation neu = NEU;
		ResourceLocation wu = WU;
		ResourceLocation u = U;
		ResourceLocation eu = EU;
		ResourceLocation swu = SWU;
		ResourceLocation su = SU;
		ResourceLocation seu = SEU;
		ResourceLocation[] texs = new ResourceLocation[]{nwd,nd,ned,wd,d,ed,swd,sd,sed,nw,n,ne,w,e,sw,s,se,nwu,nu,neu,wu,u,eu,swu,su,seu};
		String[] links = new String[]{"0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25"};
		int[] locs = new int[]{Core2Block.NWD,Core2Block.ND,Core2Block.NED,Core2Block.WD,Core2Block.D,Core2Block.ED,Core2Block.SWD,Core2Block.SD,Core2Block.SED,Core2Block.NW,Core2Block.N,Core2Block.NE,Core2Block.W,Core2Block.E,Core2Block.SW,Core2Block.S,Core2Block.SE,Core2Block.NWU,Core2Block.NU,Core2Block.NEU,Core2Block.WU,Core2Block.U,Core2Block.EU,Core2Block.SWU,Core2Block.SU,Core2Block.SEU};
		for(String link : links)
		{
			for(int loc : locs)
			{
				for(ResourceLocation tex : texs)
				{
					if (textures.containsKey(link))
					{
						if(loc == 0){tex = TEXTURE_RED;}
						if(loc == 1){tex = TEXTURE_ORANGE;}
						if(loc == 2){tex = TEXTURE_YELLOW;}
						if(loc == 3){tex = TEXTURE_GREEN;}
						if(loc == 4){tex = TEXTURE_BLUE;}
						if(loc == 5){tex = TEXTURE_INDIGO;}
						if(loc == 6){tex = TEXTURE_PURPLE;}
					}
				}
			}
		}
		return new Core2Model(nwd, nd, ned, wd, d, ed, swd, sd, sed, nw, n, ne, w, e, sw, s, se, nwu, nu, neu, wu, u, eu, swu, su, seu);
	}
}

ModelLoader

import net.minecraft.client.resources.IResourceManager;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.model.ICustomModelLoader;
import net.minecraftforge.client.model.IModel;
import net.minecraftforge.client.model.ModelLoaderRegistry;

/**
 * Created by TheGreyGhost on 19/04/2015.
 * The ModelLoader3DWeb is used to "load" the Block3D's model instead of the Vanilla loader looking for a .json file
 *
 */
public class ModelLoaderCore2 implements ICustomModelLoader
{
  public final String SMART_MODEL_RESOURCE_LOCATION = "models/block/smartmodel/";

  // return true if our Model Loader accepts this ModelResourceLocation
  @Override
  public boolean accepts(ResourceLocation resourceLocation)
  {
    return resourceLocation.getResourceDomain().equals("crystal") && resourceLocation.getResourcePath().startsWith(SMART_MODEL_RESOURCE_LOCATION);
  }
  // When called for our Block3DWeb's ModelResourceLocation, return our WebModel.
  @Override
  public IModel loadModel(ResourceLocation resourceLocation)
  {
    String resourcePath = resourceLocation.getResourcePath();
    if (!resourcePath.startsWith(SMART_MODEL_RESOURCE_LOCATION))
    {
      assert false : "loadModel expected " + SMART_MODEL_RESOURCE_LOCATION + " but found " + resourcePath;
    }
    String modelName = resourcePath.substring(SMART_MODEL_RESOURCE_LOCATION.length());
    if (modelName.equals("coremodel"))
    {
      return new Core2Model();
    }
    else
    {
      return ModelLoaderRegistry.getMissingModel();
    }
  }
  // don't need it for this example; you might.  We have to implement it anyway.
  @Override
  public void onResourceManagerReload(IResourceManager resourceManager)
  {
    this.resourceManager = resourceManager;
  }
  private IResourceManager resourceManager;
}

any help is greatly appreciated!!!

Edited by Maurice753

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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hello, for several days I've been trying to find a way to add my animations in this style. @Override public void setupAnim(Entity entity, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch) { }   My current public class is : public class FakePlayerModelWithAnim<T extends FakePlayerEntity> extends EntityModel<EntityRenderState>   But i can't do that :  public class FakePlayerModelWithAnim<T extends FakePlayerEntity> extends EntityModel<T> Type parameter 'T' is not within its bound; should extend 'net.minecraft.client.renderer.entity.state.EntityRenderState' But with EntityRenderState it ok and it work !   But my setupAnim look like this :  @Override public void setupAnim(EntityRenderState p_370046_) { super.setupAnim(p_370046_); }   I don't have any access to my entity ! Look like 1.21.1 : @Override public void setupAnim(FakePlayerEntity entity, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch) { this.root().getAllParts().forEach(ModelPart::resetPose); this.applyHeadRotation(netHeadYaw, headPitch); this.animateWalk(FakePlayerEntityAnimations.ANIM_PLAYERS_WALKING, limbSwing, limbSwingAmount, 2f, 2.5f); this.animate(entity.idleAnimationState, FakePlayerEntityAnimations.ANIM_PLAYERS_IDLE, ageInTicks, 1f); } But i'm stuck with new version of Forge...
    • Looks like an issue with abyssalsovereigns - this mod has functions that are not working on a server (client-side-only mod)
    • I added some new mods and updated old ones to my forge server and they will run successfully but the moment I try to join ill briefly load into the world and get booted with the message, internal server error. The mods in question work fine on singleplayer and removing too many from the server causes it to stop working so I cant be sure which one is causing the problem... any ideas? server log: https://pastebin.com/hGH8UUjm client log (from modrinth app): https://mclo.gs/a3oOUGY
    • The level.dat contains an invalid tag ID (115) Try to load the world in singleplayer - then test this world on the server
    • Update your AMD/ATI drivers - get the drivers from their website - do not update via system  
×
×
  • Create New...

Important Information

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