protected MeshData getContentMesh(ItemStack stack, BlockPos forBlockPos, string shapefilename) { ICoreClientAPI capi = api as ICoreClientAPI; WaterTightContainableProps props = GetContainableProps(stack); ITexPositionSource contentSource; float fillHeight; if (props != null) { contentSource = new ContainerTextureSource(capi, stack, props.Texture); fillHeight = GameMath.Min(1f, stack.StackSize / props.ItemsPerLitre / Math.Max(50, props.MaxStackSize)) * 10f / 16f; if (props.Texture == null) { return(null); } } else { contentSource = getContentTexture(capi, stack, out fillHeight); } 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?.ClimateColorMap != null) { int col = capi.World.ApplyColorMapOnRgba(props.ClimateColorMap, null, ColorUtil.WhiteArgb, 196, 128, false); if (forBlockPos != null) { col = capi.World.ApplyColorMapOnRgba(props.ClimateColorMap, null, 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); }
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); }