public static ITexPositionSource getContentTexture(ICoreClientAPI capi, ItemStack stack, out float fillHeight) { ITexPositionSource contentSource = null; fillHeight = 0; JsonObject obj = stack?.ItemAttributes?["inContainerTexture"]; if (obj != null && obj.Exists) { contentSource = new ContainerTextureSource(capi, stack, obj.AsObject <CompositeTexture>()); fillHeight = GameMath.Min(10 / 16f, 0.7f * stack.StackSize / stack.Collectible.MaxStackSize); } else { if (stack?.Block != null && (stack.Block.DrawType == EnumDrawType.Cube || stack.Block.Shape.Base.Path.Contains("basic/cube")) && capi.BlockTextureAtlas.GetPosition(stack.Block, "up", true) != null) { contentSource = new BlockTopTextureSource(capi, stack.Block); fillHeight = GameMath.Min(10 / 16f, 0.7f * stack.StackSize / stack.Collectible.MaxStackSize); } else if (stack != null) { if (stack.Class == EnumItemClass.Block) { if (stack.Block.Textures.Count > 1) { return(null); } contentSource = new ContainerTextureSource(capi, stack, stack.Block.Textures.FirstOrDefault().Value); } else { if (stack.Item.Textures.Count > 1) { return(null); } contentSource = new ContainerTextureSource(capi, stack, stack.Item.FirstTexture); } fillHeight = GameMath.Min(10 / 16f, 0.7f * stack.StackSize / stack.Collectible.MaxStackSize); } } return(contentSource); }
protected MeshData getContentMesh(ItemStack stack, BlockPos forBlockPos, string shapefilename) { ICoreClientAPI capi = api as ICoreClientAPI; WaterTightContainableProps props = GetStackProps(stack); ITexPositionSource contentSource = null; float fillHeight = 0; if (props != null) { contentSource = new ContainerTextureSource(capi, stack, props.Texture); fillHeight = GameMath.Min(10 / 16f, 0.2f * stack.StackSize / props.ItemsPerLitre / 16f); } else { JsonObject obj = stack?.ItemAttributes?["inContainerTexture"]; if (obj != null && obj.Exists) { contentSource = new ContainerTextureSource(capi, stack, obj.AsObject <CompositeTexture>()); fillHeight = GameMath.Min(10 / 16f, 0.7f * stack.StackSize / stack.Collectible.MaxStackSize); } else { if (stack?.Block != null && (stack.Block.DrawType == EnumDrawType.Cube || stack.Block.Shape.Base.Path.Contains("basic/cube"))) { contentSource = new BlockTopTextureSource(capi, stack.Block); fillHeight = GameMath.Min(10 / 16f, 0.7f * 1); } } } if (stack != null && contentSource != null) { Shape shape = capi.Assets.TryGet("shapes/block/wood/barrel/" + shapefilename).ToObject <Shape>(); MeshData contentMesh; capi.Tesselator.TesselateShape("barrel", shape, out contentMesh, contentSource, new Vec3f(Shape.rotateX, Shape.rotateY, Shape.rotateZ)); contentMesh.Translate(0, fillHeight, 0); if (props != null && props.TintIndex > 0) { int col = capi.ApplyColorTintOnRgba(props.TintIndex, ColorUtil.WhiteArgb, 196, 128, false); if (forBlockPos != null) { col = capi.ApplyColorTintOnRgba(props.TintIndex, ColorUtil.WhiteArgb, forBlockPos.X, forBlockPos.Y, forBlockPos.Z, false); } byte[] rgba = ColorUtil.ToBGRABytes(col); for (int i = 0; i < contentMesh.Rgba.Length; i++) { contentMesh.Rgba[i] = (byte)((contentMesh.Rgba[i] * rgba[i % 4]) / 255); } } return(contentMesh); } return(null); }