public virtual bool OnPlayerInteractStart(IPlayer player, BlockSelection bs) { ItemSlot hotbarSlot = player.InventoryManager.ActiveHotbarSlot; if (!hotbarSlot.Empty && !hotbarSlot.Itemstack.Collectible.HasBehavior <CollectibleBehaviorGroundStorable>()) { return(false); } if (!BlockBehaviorReinforcable.AllowRightClickPickup(Api.World, Pos, player)) { return(false); } DetermineStorageProperties(hotbarSlot); bool ok = false; if (StorageProps != null) { if (StorageProps.Layout == EnumGroundStorageLayout.Quadrants && inventory.Empty) { double dx = Math.Abs(bs.HitPosition.X - 0.5); double dz = Math.Abs(bs.HitPosition.X - 0.5); if (dx < 2 / 16f && dz < 2 / 16f) { overrideLayout = EnumGroundStorageLayout.SingleCenter; DetermineStorageProperties(hotbarSlot); } } switch (StorageProps.Layout) { case EnumGroundStorageLayout.SingleCenter: ok = putOrGetItemSingle(inventory[0], player, bs); break; case EnumGroundStorageLayout.Halves: if (bs.HitPosition.X < 0.5) { ok = putOrGetItemSingle(inventory[0], player, bs); } else { ok = putOrGetItemSingle(inventory[1], player, bs); } break; case EnumGroundStorageLayout.Quadrants: int pos = ((bs.HitPosition.X > 0.5) ? 2 : 0) + ((bs.HitPosition.Z > 0.5) ? 1 : 0); ok = putOrGetItemSingle(inventory[pos], player, bs); break; case EnumGroundStorageLayout.Stacking: ok = putOrGetItemStacking(player, bs); break; } } if (ok) { MarkDirty(true); updateMeshes(); } if (inventory.Empty) { Api.World.BlockAccessor.SetBlock(0, Pos); } return(ok); }
public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel, ref EnumHandling handling) { ItemStack[] dropStacks = new ItemStack[] { block.OnPickBlock(world, blockSel.Position) }; ItemSlot activeSlot = byPlayer.InventoryManager.ActiveHotbarSlot; bool heldSlotSuitable = activeSlot.Empty || (dropStacks.Length >= 1 && activeSlot.Itemstack.Equals(world, dropStacks[0], GlobalConstants.IgnoredStackAttributes)); if (dropsPickupMode) { float dropMul = 1f; if (block.Attributes?.IsTrue("forageStatAffected") == true) { dropMul *= byPlayer.Entity.Stats.GetBlended("forageDropRate"); } dropStacks = block.GetDrops(world, blockSel.Position, byPlayer, dropMul); var alldrops = block.GetDropsForHandbook(new ItemStack(block), byPlayer); if (!heldSlotSuitable) { foreach (var drop in alldrops) { heldSlotSuitable |= activeSlot.Itemstack.Equals(world, drop.ResolvedItemstack, GlobalConstants.IgnoredStackAttributes); } } } if (!heldSlotSuitable || !world.Claims.TryAccess(byPlayer, blockSel.Position, EnumBlockAccessFlags.BuildOrBreak)) { return(false); } if (!byPlayer.Entity.Controls.Sneak) { if (world.Side == EnumAppSide.Server && BlockBehaviorReinforcable.AllowRightClickPickup(world, blockSel.Position, byPlayer)) { bool blockToBreak = true; foreach (var stack in dropStacks) { if (!byPlayer.InventoryManager.TryGiveItemstack(stack, true)) { world.SpawnItemEntity(stack, blockSel.Position.ToVec3d().AddCopy(0.5, 0.1, 0.5)); } if (blockToBreak) { blockToBreak = false; world.BlockAccessor.SetBlock(0, blockSel.Position); world.BlockAccessor.TriggerNeighbourBlockUpdate(blockSel.Position); } world.PlaySoundAt(pickupSound ?? block.GetSounds(world.BlockAccessor, blockSel.Position).Place, byPlayer, null); } } handling = EnumHandling.PreventDefault; return(true); } return(false); }