protected bool putOrGetItemStacking(IPlayer byPlayer, BlockSelection bs) { BlockPos abovePos = Pos.UpCopy(); BlockEntity be = Api.World.BlockAccessor.GetBlockEntity(abovePos); if (be is BlockEntityGroundStorage beg) { return(beg.OnPlayerInteractStart(byPlayer, bs)); } bool sneaking = byPlayer.Entity.Controls.Sneak; ItemSlot hotbarSlot = byPlayer.InventoryManager.ActiveHotbarSlot; if (sneaking && TotalStackSize >= Capacity) { Block pileblock = Api.World.BlockAccessor.GetBlock(Pos); Block aboveblock = Api.World.BlockAccessor.GetBlock(abovePos); if (aboveblock.IsReplacableBy(pileblock)) { BlockGroundStorage bgs = pileblock as BlockGroundStorage; var bsc = bs.Clone(); bsc.Position.Up(); bsc.Face = null; return(bgs.CreateStorage(Api.World, bsc, byPlayer)); } return(false); } bool equalStack = inventory[0].Empty || hotbarSlot.Itemstack != null && hotbarSlot.Itemstack.Equals(Api.World, inventory[0].Itemstack, GlobalConstants.IgnoredStackAttributes); if (sneaking && !equalStack) { return(false); } lock (inventoryLock) { if (sneaking) { return(TryPutItem(byPlayer)); } else { return(TryTakeItem(byPlayer)); } } }
public static void Interact(ItemSlot itemslot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handHandling, ref EnumHandling handling) { IWorldAccessor world = byEntity?.World; if (blockSel == null || world == null || !byEntity.Controls.Sneak) { return; } IPlayer byPlayer = null; if (byEntity is EntityPlayer) { byPlayer = world.PlayerByUid(((EntityPlayer)byEntity).PlayerUID); } if (byPlayer == null) { return; } if (!world.Claims.TryAccess(byPlayer, blockSel.Position, EnumBlockAccessFlags.BuildOrBreak)) { itemslot.MarkDirty(); return; } BlockGroundStorage blockgs = world.GetBlock(new AssetLocation("groundstorage")) as BlockGroundStorage; if (blockgs == null) { return; } BlockEntity be = world.BlockAccessor.GetBlockEntity(blockSel.Position); BlockEntity beAbove = world.BlockAccessor.GetBlockEntity(blockSel.Position.UpCopy()); if (be is BlockEntityGroundStorage || beAbove is BlockEntityGroundStorage) { if (((be as BlockEntityGroundStorage) ?? (beAbove as BlockEntityGroundStorage)).OnPlayerInteractStart(byPlayer, blockSel)) { handHandling = EnumHandHandling.PreventDefault; } return; } // Must be aiming at the up face if (blockSel.Face != BlockFacing.UP) { return; } Block onBlock = world.BlockAccessor.GetBlock(blockSel.Position); // Must have a support below if (!onBlock.CanAttachBlockAt(world.BlockAccessor, blockgs, blockSel.Position, BlockFacing.UP)) { return; } // Must have empty space above BlockPos pos = blockSel.Position.AddCopy(blockSel.Face); if (world.BlockAccessor.GetBlock(pos).Replaceable < 6000) { return; } if (blockgs.CreateStorage(byEntity.World, blockSel, byPlayer)) { handHandling = EnumHandHandling.PreventDefault; } }