diff --git a/Block/BlockGroundStorage.cs b/Block/BlockGroundStorage.cs index 64519940..6b3523c6 100644 --- a/Block/BlockGroundStorage.cs +++ b/Block/BlockGroundStorage.cs @@ -379,6 +379,13 @@ public override WorldInteraction[] GetPlacedBlockInteractionHelp(IWorldAccessor var beg = world.BlockAccessor.GetBlockEntity(selection.Position) as BlockEntityGroundStorage; if (beg?.StorageProps != null) { + WorldInteraction[] liquidInteractions = Array.Empty(); + ItemSlot slotLiquidContainer = beg.Inventory.FirstOrDefault(slot => !slot.Empty && slot.Itemstack.Collectible is BlockLiquidContainerBase); + if (slotLiquidContainer != null) + { + liquidInteractions = (slotLiquidContainer.Itemstack.Collectible as BlockLiquidContainerBase).interactions; + } + int bulkquantity = beg.StorageProps.BulkTransferQuantity; if (beg.StorageProps.Layout == EnumGroundStorageLayout.Stacking && !beg.Inventory.Empty) @@ -432,7 +439,7 @@ public override WorldInteraction[] GetPlacedBlockInteractionHelp(IWorldAccessor MouseButton = EnumMouseButton.Right } - }.Append(base.GetPlacedBlockInteractionHelp(world, selection, forPlayer)); + }.Append(base.GetPlacedBlockInteractionHelp(world, selection, forPlayer)).Append(liquidInteractions); } if (beg.StorageProps.Layout == EnumGroundStorageLayout.SingleCenter) @@ -445,7 +452,7 @@ public override WorldInteraction[] GetPlacedBlockInteractionHelp(IWorldAccessor MouseButton = EnumMouseButton.Right }, - }.Append(base.GetPlacedBlockInteractionHelp(world, selection, forPlayer)); + }.Append(base.GetPlacedBlockInteractionHelp(world, selection, forPlayer)).Append(liquidInteractions); } if (beg.StorageProps.Layout == EnumGroundStorageLayout.Halves || beg.StorageProps.Layout == EnumGroundStorageLayout.Quadrants) @@ -466,9 +473,8 @@ public override WorldInteraction[] GetPlacedBlockInteractionHelp(IWorldAccessor HotKeyCode = null } - }.Append(base.GetPlacedBlockInteractionHelp(world, selection, forPlayer)); + }.Append(base.GetPlacedBlockInteractionHelp(world, selection, forPlayer)).Append(liquidInteractions); } - } return base.GetPlacedBlockInteractionHelp(world, selection, forPlayer); diff --git a/BlockEntity/BEGroundStorage.cs b/BlockEntity/BEGroundStorage.cs index 41e9a4af..c084c87a 100644 --- a/BlockEntity/BEGroundStorage.cs +++ b/BlockEntity/BEGroundStorage.cs @@ -960,6 +960,61 @@ public bool putOrGetItemSingle(ItemSlot ourSlot, IPlayer player, BlockSelection } ItemSlot hotbarSlot = player.InventoryManager.ActiveHotbarSlot; + + if (ourSlot?.Itemstack?.Collectible is ILiquidInterface liquidCnt1 && hotbarSlot?.Itemstack?.Collectible is ILiquidInterface liquidCnt2) + { + BlockLiquidContainerBase heldLiquidContainer = hotbarSlot.Itemstack.Collectible as BlockLiquidContainerBase; + + CollectibleObject obj = hotbarSlot.Itemstack.Collectible; + bool singleTake = player.WorldData.EntityControls.ShiftKey; + bool singlePut = player.WorldData.EntityControls.CtrlKey; + + + if (obj is ILiquidSource liquidSource && liquidSource.AllowHeldLiquidTransfer && !singleTake) + { + ItemStack contentStackToMove = liquidSource.GetContent(hotbarSlot.Itemstack); + + int moved = heldLiquidContainer.TryPutLiquid( + containerStack: ourSlot.Itemstack, + liquidStack: contentStackToMove, + desiredLitres: singlePut ? liquidSource.TransferSizeLitres : liquidSource.CapacityLitres); + + if (moved > 0) + { + heldLiquidContainer.SplitStackAndPerformAction(player.Entity, hotbarSlot, delegate (ItemStack stack) + { + liquidSource.TryTakeContent(stack, moved); + return moved; + }); + heldLiquidContainer.DoLiquidMovedEffects(player, contentStackToMove, moved, BlockLiquidContainerBase.EnumLiquidDirection.Pour); + + BlockGroundStorage.IsUsingContainedBlock = true; + isUsingSlot = ourSlot; + return true; + } + } + + if (obj is ILiquidSink liquidSink && liquidSink.AllowHeldLiquidTransfer && !singlePut) + { + ItemStack owncontentStack = heldLiquidContainer.GetContent(ourSlot.Itemstack); + if (owncontentStack != null) + { + ItemStack liquidStackForParticles = owncontentStack.Clone(); + float litres = (singleTake ? liquidSink.TransferSizeLitres : liquidSink.CapacityLitres); + int moved = heldLiquidContainer.SplitStackAndPerformAction(player.Entity, hotbarSlot, (ItemStack stack) => liquidSink.TryPutLiquid(stack, owncontentStack, litres)); + if (moved > 0) + { + heldLiquidContainer.TryTakeContent(ourSlot.Itemstack, moved); + heldLiquidContainer.DoLiquidMovedEffects(player, liquidStackForParticles, moved, BlockLiquidContainerBase.EnumLiquidDirection.Fill); + + BlockGroundStorage.IsUsingContainedBlock = true; + isUsingSlot = ourSlot; + return true; + } + } + } + } + if (!hotbarSlot.Empty && !inventory.Empty) { bool layoutEqual = StorageProps.Layout == hotbarSlot.Itemstack.Collectible.GetBehavior()?.StorageProps.Layout; diff --git a/Systems/Liquid/BlockLiquidContainerBase.cs b/Systems/Liquid/BlockLiquidContainerBase.cs index 50a97d9f..e5ed50a8 100644 --- a/Systems/Liquid/BlockLiquidContainerBase.cs +++ b/Systems/Liquid/BlockLiquidContainerBase.cs @@ -106,7 +106,7 @@ public virtual int GetContainerSlotId(ItemStack containerStack) } #region Interaction help - protected WorldInteraction[] interactions; + public WorldInteraction[] interactions { get; private set; } public override void OnLoaded(ICoreAPI api) { @@ -642,6 +642,15 @@ protected override void tryEatBegin(ItemSlot slot, EntityAgent byEntity, ref Enu public override void OnHeldInteractStart(ItemSlot itemslot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handHandling) { + if (blockSel != null && api.World.BlockAccessor.GetBlockEntity(blockSel.Position) is BlockEntityGroundStorage begs) + { + ItemSlot gslot = begs.GetSlotAt(blockSel); + if (!gslot.Empty && gslot.Itemstack.Collectible is ILiquidInterface) + { + return; + } + } + if (blockSel == null || byEntity.Controls.ShiftKey) { if (byEntity.Controls.ShiftKey) base.OnHeldInteractStart(itemslot, byEntity, blockSel, entitySel, firstEvent, ref handHandling);