public override void OnBlockBroken(IWorldAccessor world, BlockPos pos, IPlayer byPlayer, float dropQuantityMultiplier = 1f) { BlockEntityItemPile be = world.BlockAccessor.GetBlockEntity(pos) as BlockEntityItemPile; be?.OnBlockBroken(); base.OnBlockBroken(world, pos, byPlayer); }
public virtual bool OnPlayerInteract(IPlayer byPlayer) { BlockPos abovePos = Pos.UpCopy(); BlockEntity be = Api.World.BlockAccessor.GetBlockEntity(abovePos); if (be is BlockEntityItemPile) { return(((BlockEntityItemPile)be).OnPlayerInteract(byPlayer)); } bool sneaking = byPlayer.Entity.Controls.Sneak; ItemSlot hotbarSlot = byPlayer.InventoryManager.ActiveHotbarSlot; bool equalStack = hotbarSlot.Itemstack != null && hotbarSlot.Itemstack.Equals(Api.World, inventory[0].Itemstack, GlobalConstants.IgnoredStackAttributes); if (sneaking && !equalStack) { return(false); } if (sneaking && equalStack && OwnStackSize >= MaxStackSize) { Block pileblock = Api.World.BlockAccessor.GetBlock(Pos); Block aboveblock = Api.World.BlockAccessor.GetBlock(abovePos); if (aboveblock.IsReplacableBy(pileblock)) { if (Api.World is IServerWorldAccessor) { Api.World.BlockAccessor.SetBlock((ushort)pileblock.Id, abovePos); BlockEntityItemPile bep = Api.World.BlockAccessor.GetBlockEntity(abovePos) as BlockEntityItemPile; if (bep != null) { bep.TryPutItem(byPlayer); } } return(true); } return(false); } lock (inventoryLock) { if (sneaking) { return(TryPutItem(byPlayer)); } else { return(TryTakeItem(byPlayer)); } } }