private void fullnessMeterDraw(Context ctx, ImageSurface surface, ElementBounds currentBounds) { ItemSlot liquidSlot = Inventory[1]; // Water ID Slot if (liquidSlot.Empty) { return; } BlockEntitySingleSink besink = capi.World.BlockAccessor.GetBlockEntity(BlockEntityPosition) as BlockEntitySingleSink; float itemsPerLitre = 1f; int capacity = besink.CapacityLitres; WaterTightContainableProps props = BlockLiquidContainerBase.GetInContainerProps(liquidSlot.Itemstack); if (props != null) { itemsPerLitre = props.ItemsPerLitre; capacity = Math.Max(capacity, props.MaxStackSize); } float fullnessRelative = liquidSlot.StackSize / itemsPerLitre / capacity; double offY = (1 - fullnessRelative) * currentBounds.InnerHeight; ctx.Rectangle(0, offY, currentBounds.InnerWidth, currentBounds.InnerHeight - offY); //ctx.SetSourceRGBA(ravg/255.0, gavg / 255.0, bavg / 255.0, aavg / 255.0); //ctx.Fill(); CompositeTexture tex = liquidSlot.Itemstack.Collectible.Attributes?["waterTightContainerProps"]?["texture"]?.AsObject <CompositeTexture>(null, liquidSlot.Itemstack.Collectible.Code.Domain); if (tex != null) { ctx.Save(); Matrix m = ctx.Matrix; m.Scale(GuiElement.scaled(3), GuiElement.scaled(3)); ctx.Matrix = m; AssetLocation loc = tex.Base.Clone().WithPathAppendixOnce(".png"); GuiElement.fillWithPattern(capi, ctx, loc.Path, true, false); ctx.Restore(); } }
public override void OnItemSlotModified(ItemStack stack) { base.OnItemSlotModified(stack); if (itemstack == null) { return; } ItemSlotLiquidOnly liquidSlot = inventory[1] as ItemSlotLiquidOnly; bool stackable = !liquidSlot.Empty && liquidSlot.Itemstack.Equals(inventory.Api.World, itemstack, GlobalConstants.IgnoredStackAttributes); if (stackable) { int remaining = liquidSlot.Itemstack.Collectible.MaxStackSize - liquidSlot.Itemstack.StackSize; WaterTightContainableProps props = BlockLiquidContainerBase.GetInContainerProps(liquidSlot.Itemstack); if (props != null) { int max = (int)(liquidSlot.CapacityLitres * props.ItemsPerLitre); int maxOverride = props.MaxStackSize; //allows 64 rot to be placed in barrel remaining = Math.Max(max, maxOverride) - liquidSlot.Itemstack.StackSize; } int moved = GameMath.Clamp(itemstack.StackSize, 0, remaining); liquidSlot.Itemstack.StackSize += moved; itemstack.StackSize -= moved; if (itemstack.StackSize <= 0) { itemstack = null; } liquidSlot.MarkDirty(); MarkDirty(); return; } if (itemstack.Collectible.Attributes?.IsTrue("barrelMoveToLiquidSlot") == true || itemstack.Collectible.Attributes?["waterTightContainerProps"].Exists == true) { if (stackable) { int remainingspace = itemstack.Collectible.MaxStackSize - liquidSlot.StackSize; int movableq = Math.Min(itemstack.StackSize, remainingspace); liquidSlot.Itemstack.StackSize += movableq; this.itemstack.StackSize -= movableq; if (StackSize <= 0) { itemstack = null; } MarkDirty(); liquidSlot.MarkDirty(); return; } if (liquidSlot.Empty) { liquidSlot.Itemstack = this.itemstack.Clone(); this.itemstack = null; MarkDirty(); liquidSlot.MarkDirty(); } } return; }