public MeshData GenMesh(ICoreClientAPI capi, ItemStack contentStack, BlockPos forBlockPos = null) { Shape shape = capi.Assets.TryGet("shapes/block/wood/bucket/empty.json").ToObject <Shape>(); MeshData bucketmesh; capi.Tesselator.TesselateShape(this, shape, out bucketmesh); if (contentStack != null) { WaterTightContainableProps props = GetInContainerProps(contentStack); ContainerTextureSource contentSource = new ContainerTextureSource(capi, contentStack, props.Texture); shape = capi.Assets.TryGet("shapes/block/wood/bucket/contents.json").ToObject <Shape>(); MeshData contentMesh; capi.Tesselator.TesselateShape("bucket", shape, out contentMesh, contentSource, new Vec3f(Shape.rotateX, Shape.rotateY, Shape.rotateZ)); contentMesh.Translate(0, GameMath.Min(7 / 16f, contentStack.StackSize / props.ItemsPerLitre * 0.7f / 16f), 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); } } for (int i = 0; i < contentMesh.Flags.Length; i++) { contentMesh.Flags[i] = contentMesh.Flags[i] & ~(1 << 12); // Remove water waving flag } bucketmesh.AddMeshData(contentMesh); // Water flags if (forBlockPos != null) { bucketmesh.CustomInts = new CustomMeshDataPartInt(bucketmesh.FlagsCount); bucketmesh.CustomInts.Count = bucketmesh.FlagsCount; bucketmesh.CustomInts.Values.Fill(0x4000000); // light foam only bucketmesh.CustomFloats = new CustomMeshDataPartFloat(bucketmesh.FlagsCount * 2); bucketmesh.CustomFloats.Count = bucketmesh.FlagsCount * 2; } } return(bucketmesh); }
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); }
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); }