Jump to content

[1.11.2] [SOLVED] Weird cycling through textures on top quad


Tschipp

Recommended Posts

I have an item that changes its appearance based on nbt. For that I made a custom IBakedModel with a custom ItemOverrideList

What i now do in the ItemOverrideList#handleItemState method is create a new SimpleBakedModel, that I create from the parent model of an itemstack. I know sounds confusing, let's just show the code:

ItemOverrideList:

public static class OverrideList extends ItemOverrideList
	{

		public OverrideList(List<ItemOverride> overridesIn) {
			super(overridesIn);
		}


		@Override
		public IBakedModel handleItemState(IBakedModel originalModel, ItemStack stack, World world, EntityLivingBase entity)
		{
			if(stack.hasTagCompound() && stack.getTagCompound().hasKey("block") && stack.getTagCompound().hasKey("meta"))
			{
				Block block = Block.getBlockFromName(stack.getTagCompound().getString("block"));
				int meta = stack.getTagCompound().getInteger("meta");

				IBlockState state = block.getDefaultState();

				meta = meta - 12;

				ItemStack blockstack = new ItemStack(block, 1, meta);

				IBakedModel parentmodel = Minecraft.getMinecraft().getRenderItem().getItemModelMesher().getItemModel(blockstack);

				TextureAtlasSprite side = parentmodel.getParticleTexture();

				Map<EnumFacing, List<BakedQuad>> map = new HashMap<EnumFacing, List<BakedQuad>>();
				
				List<BakedQuad> quadsup = parentmodel.getQuads(state, EnumFacing.UP, 0);
				BakedQuadRetextured up = new BakedQuadRetextured(quadsup.get(0), side);				
				quadsup.set(0,up);
				
				List<BakedQuad> quadsdown = parentmodel.getQuads(state, EnumFacing.DOWN, 0);
				BakedQuadRetextured down = new BakedQuadRetextured(quadsdown.get(0), side);				
				quadsdown.set(0,down); 
				
				map.put(EnumFacing.DOWN, quadsdown);
				map.put(EnumFacing.UP, quadsup);
				map.put(EnumFacing.NORTH, parentmodel.getQuads(state, EnumFacing.NORTH, 1));
				map.put(EnumFacing.SOUTH, parentmodel.getQuads(state, EnumFacing.SOUTH, 1));
				map.put(EnumFacing.WEST, parentmodel.getQuads(state, EnumFacing.WEST, 1));
				map.put(EnumFacing.EAST, parentmodel.getQuads(state, EnumFacing.EAST, 1));
				

				SimpleBakedModel model = new SimpleBakedModel(new ArrayList(), map, parentmodel.isAmbientOcclusion(), parentmodel.isGui3d(), side, parentmodel.getItemCameraTransforms(), ItemOverrideList.NONE);
				return model;
			}
			return Minecraft.getMinecraft().getRenderItem().getItemModelMesher().getItemModel(new ItemStack(Blocks.LOG));
		}


	}

So what's happening is I'm getting a block with metadata stored in nbt of the itemstack. Then I create an ItemStack from that block and metatdata. Then I get the BakedModel for that ItemStack, and also extract the particle texture. Then I create a new map which contains all the BakedQuads. The BakedQuads I get from the parentModel. I also edit the top and bottom quad, to change the texture, so I replace them in the list with a BakedQuadRetextured. Finally, I create the SimpleBakedModel and return it.

 

The problem now is this:

https://gyazo.com/29de5fec9915a801d0f4dae029bc37c4

 

First of all, it cycles through every texture for the top quad. The bottom quad remains unchanged. 

It also changes the top quad for vanilla log blocks, idk how that's happening.

 

I'm applying the BakedModel in the ModelBakeEvent:

@SubscribeEvent
	public void onModelBake(ModelBakeEvent event)
	{
		Object object =  event.getModelRegistry().getObject(new ModelResourceLocation("barkifier:barkified_log", "inventory"));
	    if (object instanceof IBakedModel) {
	      IBakedModel existingModel = (IBakedModel)object;
	      BarkifiedLogsRendering.Model customModel = new  BarkifiedLogsRendering.Model(existingModel);
	      event.getModelRegistry().putObject(new ModelResourceLocation("barkifier:barkified_log", "inventory"), customModel);
	    } 
	}

 

Also, my IBakedModel:

public static class Model implements IPerspectiveAwareModel
	{

		private IBakedModel base;
		private OverrideList overrides;

		public Model(IBakedModel base) {

			this.base = base;
			this.overrides = new OverrideList(Collections.EMPTY_LIST);

		}

		@Override
		public List<BakedQuad> getQuads(IBlockState state, EnumFacing side, long rand) {
			return base.getQuads(state, side, rand);
		}

		@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 ItemCameraTransforms getItemCameraTransforms() {
			return base.getItemCameraTransforms();
		}

		@Override
		public ItemOverrideList getOverrides() {
			return overrides;
		}

		@Override
		public Pair<? extends IBakedModel, Matrix4f> handlePerspective(ItemCameraTransforms.TransformType cameraTransformType) {
			if (base instanceof IPerspectiveAwareModel) {
				Matrix4f matrix4f = ((IPerspectiveAwareModel)base).handlePerspective(cameraTransformType).getRight();
				return Pair.of(this, matrix4f);
			} else {
				// If the base model isn't an IPerspectiveAware, we'll need to generate the correct matrix ourselves using the
				//  ItemCameraTransforms.

				ItemCameraTransforms itemCameraTransforms = base.getItemCameraTransforms();
				ItemTransformVec3f itemTransformVec3f = itemCameraTransforms.getTransform(cameraTransformType);
				TRSRTransformation tr = new TRSRTransformation(itemTransformVec3f);
				Matrix4f mat = null;
				if (tr != null) { // && tr != TRSRTransformation.identity()) {
					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);
			}
		}



	}

I really hope someone can help me with this, I cannot explain how this is happening.

Edited by Tschipp
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.

Announcements



×
×
  • Create New...

Important Information

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