Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.15.2] How to create 3D item models with attachments?


Recommended Posts

14 hours ago, ChampionAsh5357 said:

You can store variables onto itemstacks by either using nbt data or capabilities. Choose one of the two systems you wish to use and run with it. If the data is correctly synced with the client then you can also use a property override to update the model.

Can you show me an example? Or point me to some documentation?

Edit:

What if I wanted to render the model via java? How would that work?

Edited by ken2020
Link to post
Share on other sites
1 hour ago, ChampionAsh5357 said:

Capabilities and Item Property Overrides

 

You would need to use a ISTER (ItemStackTileEntityRenderer) for that. However, it seems pointless since you're not using any data that requires a part of some other existing item or block to render in your scene. Stick to using json models.

The thing is the gun models have interchangable attachments and some can have more than one type of attachment. How do I render the gun and attachments. 

Link to post
Share on other sites
4 hours ago, ChampionAsh5357 said:

I thought I just explained that using some combination of capabilities and item property overrides. My guess is you haven't read the documentation on either.

I dont think you understand what I am getting at... I am asking if the player is just holding the gun, the game renders only the gun. But if the player puts on a scope, the game renders both the gun and scope. What if the scope and gun are two different json models? How would I render both of them on the same Item? 

Link to post
Share on other sites

Howdy

 

You might find this working example useful

https://github.com/TheGreyGhost/MinecraftByExample/tree/master/src/main/java/minecraftbyexample/mbe15_item_dynamic_item_model

It changes the appearance of the item depending on the item's properties.

In your case, you could merge the model of the gun and the model of whichever scope you have attached to the gun (using NBT or a Capability).

mbe04 also shows ways of combining two existing json models together.

 

-TGG

Link to post
Share on other sites
On 5/19/2020 at 12:05 AM, ChampionAsh5357 said:

You either do one of two things: you create a json model that contains both the gun and scope combined or you json model holds a parent location to one model and the adds elements to create the other portion of the model.

Could you point me to an example of what you are talking about. I get the idea, but I have never tried it before.

Link to post
Share on other sites
On 5/19/2020 at 5:56 AM, TheGreyGhost said:

Howdy

 

You might find this working example useful

https://github.com/TheGreyGhost/MinecraftByExample/tree/master/src/main/java/minecraftbyexample/mbe15_item_dynamic_item_model

It changes the appearance of the item depending on the item's properties.

In your case, you could merge the model of the gun and the model of whichever scope you have attached to the gun (using NBT or a Capability).

mbe04 also shows ways of combining two existing json models together.

 

-TGG

where in mbe04 does it show how to combine json models? I can't seem to find it.

Link to post
Share on other sites

Ok so I am trying this:

package com.kenmod_main.objects.items.guns.glock;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import net.minecraft.block.BlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BlockRendererDispatcher;
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.util.Direction;
import net.minecraft.util.ResourceLocation;

public class ItemGlockBakedModel implements IBakedModel{

	private IBakedModel baseModel;
	private ResourceLocation barrelLocation = new ResourceLocation("kenmod:item/glock_barrel");
	
	@Override
	public List<BakedQuad> getQuads(BlockState state, Direction side, Random rand) {
		throw new AssertionError("IBakedModel::getQuads should never be called, only IForgeBakedModel::getQuads");
	}
	
	public List<BakedQuad> barrelQuads (boolean hasBarrel){
		
		List<BakedQuad> barrel = new ArrayList<BakedQuad>();
		
		if(hasBarrel) {
			
		}
		
		return barrel;
	}
	
	
	@Override
	public boolean isAmbientOcclusion() {
		return baseModel.isAmbientOcclusion();
	}

	@Override
	public boolean isGui3d() {
		return baseModel.isGui3d();
	}

	@Override
	public boolean func_230044_c_() {
		return baseModel.func_230044_c_();
	}

	@Override
	public boolean isBuiltInRenderer() {
		return baseModel.isBuiltInRenderer();
	}

	@SuppressWarnings("deprecation")
	@Override
	public TextureAtlasSprite getParticleTexture() {
		return baseModel.getParticleTexture();
	}

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

}

 

TGG's code from

 

private List<BakedQuad> getArrowQuads(BlockAltimeter.GPScoordinate gpScoordinate, Direction whichFace)  {
    // we construct the needle from a number of needle models (each needle model is a single cube 1x1x1)
    // the needle is made up of a central cube plus further cubes radiating out to a 6 texel radius

    // retrieve the needle model which we previously manually added to the model registry in StartupClientOnly::onModelRegistryEvent
    Minecraft mc = Minecraft.getInstance();
    BlockRendererDispatcher blockRendererDispatcher = mc.getBlockRendererDispatcher();
    IBakedModel needleModel = blockRendererDispatcher.getBlockModelShapes().getModelManager().getModel(needleModelRL);

    // our needle model has its minX, minY, minZ at [0,0,0] and its size is [1,1,1], so to put it at the centre of the top
    //  of our altimeter, we need to translate it to [7.5F, 10F, 7.5F] in modelspace coordinates
    final float CONVERT_MODEL_SPACE_TO_WORLD_SPACE = 1.0F/16.0F;
    Vector3f centrePos = new Vector3f(7.5F, 10F, 7.5F);
    centrePos.mul(CONVERT_MODEL_SPACE_TO_WORLD_SPACE);

    ImmutableList.Builder<BakedQuad> retval = new ImmutableList.Builder<>();
    addTranslatedModelQuads(needleModel, centrePos, whichFace, retval);

    // make a line of needle cubes radiating out from the centre, pointing towards the origin.
    double bearingToOriginRadians = Math.toRadians(gpScoordinate.bearingToOrigin);  // degrees clockwise from north
    float deltaX = (float)Math.sin(bearingToOriginRadians);
    float deltaZ = -(float)Math.cos(bearingToOriginRadians);
    if (Math.abs(deltaX) < Math.abs(deltaZ)) {
      deltaX /= Math.abs(deltaZ);
      deltaZ /= Math.abs(deltaZ);
    } else {
      deltaZ /= Math.abs(deltaX);
      deltaX /= Math.abs(deltaX);
    }
    float xoffset = 0;
    float zoffset = 0;
    final int NUMBER_OF_NEEDLE_BLOCKS = 6; // not including centre
    for (int i = 0; i < NUMBER_OF_NEEDLE_BLOCKS; ++i) {
      xoffset += deltaX * CONVERT_MODEL_SPACE_TO_WORLD_SPACE;
      zoffset += deltaZ * CONVERT_MODEL_SPACE_TO_WORLD_SPACE;
      Vector3f moveTo = centrePos.copy();
      moveTo.add(xoffset, 0, zoffset);
      addTranslatedModelQuads(needleModel, moveTo, whichFace, retval);
    }

 

uses something to do with block rendering. What should I change to make it work for items?

Link to post
Share on other sites

Howdy

Items and Blocks use the same models (just lists of quads really) so the same code should work for both.

 

You merge the models just by combining the list of quads

i.e. this part

  @Override
  public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand) {
    // our chess pieces are only drawn when side is NULL.
    if (side != null) {
      return parentModel.getQuads(state, side, rand);
    }

    List<BakedQuad> combinedQuadsList = new ArrayList(parentModel.getQuads(state, side, rand));
    combinedQuadsList.addAll(getChessPiecesQuads(numberOfChessPieces));
    return combinedQuadsList;
  }

 

-TGG

  • Like 1
Link to post
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.

Guest
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 Privacy Policy.