public override WorldInteraction[] GetPlacedBlockInteractionHelp(IWorldAccessor world, BlockSelection selection, IPlayer forPlayer) { return(new WorldInteraction[] { new WorldInteraction() { ActionLangCode = "blockhelp-plankpile-add", MouseButton = EnumMouseButton.Right, HotKeyCode = "sneak", Itemstacks = new ItemStack[] { new ItemStack(this) }, GetMatchingStacks = (wi, bs, es) => { BlockEntityPlankPile pile = world.BlockAccessor.GetBlockEntity(bs.Position) as BlockEntityPlankPile; ItemStack stack = pile?.inventory[0].Itemstack?.Clone(); if (stack == null) { return null; } stack.StackSize = pile.BulkTakeQuantity; return pile != null && pile.MaxStackSize > pile.inventory[0].StackSize ? new ItemStack[] { stack } : null; } }, new WorldInteraction() { ActionLangCode = "blockhelp-plankpile-remove", MouseButton = EnumMouseButton.Right }, new WorldInteraction() { ActionLangCode = "blockhelp-plankpile-4add", MouseButton = EnumMouseButton.Right, HotKeyCodes = new string[] { "sprint", "sneak" }, Itemstacks = new ItemStack[] { new ItemStack(this) }, GetMatchingStacks = (wi, bs, es) => { BlockEntityPlankPile pile = world.BlockAccessor.GetBlockEntity(bs.Position) as BlockEntityPlankPile; ItemStack stack = pile?.inventory[0].Itemstack?.Clone(); if (stack == null) { return null; } stack.StackSize = pile.BulkTakeQuantity; return pile != null && pile.MaxStackSize > pile.inventory[0].StackSize ? new ItemStack[] { stack } : null; } }, new WorldInteraction() { ActionLangCode = "blockhelp-plankpile-4remove", HotKeyCode = "sprint", MouseButton = EnumMouseButton.Right } }); }
public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel) { BlockEntity be = world.BlockAccessor.GetBlockEntity(blockSel.Position); if (be is BlockEntityPlankPile) { BlockEntityPlankPile pile = (BlockEntityPlankPile)be; return(pile.OnPlayerInteract(byPlayer)); } return(false); }
public override ItemStack OnPickBlock(IWorldAccessor world, BlockPos pos) { BlockEntity be = world.BlockAccessor.GetBlockEntity(pos); if (be is BlockEntityPlankPile) { BlockEntityPlankPile pile = (BlockEntityPlankPile)be; ItemStack stack = pile.inventory[0].Itemstack; if (stack != null) { ItemStack pickstack = stack.Clone(); pickstack.StackSize = 1; return(pickstack); } } return(new ItemStack(this)); }
internal bool Construct(ItemSlot slot, IWorldAccessor world, BlockPos pos, IPlayer player) { Block belowBlock = world.BlockAccessor.GetBlock(pos.DownCopy()); if (!belowBlock.CanAttachBlockAt(world.BlockAccessor, this, pos.DownCopy(), BlockFacing.UP) && (belowBlock != this || FillLevel(world.BlockAccessor, pos.DownCopy()) != 16)) { return(false); } if (!world.BlockAccessor.GetBlock(pos).IsReplacableBy(this)) { return(false); } world.BlockAccessor.SetBlock(BlockId, pos); BlockEntity be = world.BlockAccessor.GetBlockEntity(pos); if (be is BlockEntityPlankPile) { BlockEntityPlankPile pile = (BlockEntityPlankPile)be; if (player.WorldData.CurrentGameMode == EnumGameMode.Creative) { pile.inventory[0].Itemstack = slot.Itemstack.Clone(); pile.inventory[0].Itemstack.StackSize = 1; } else { pile.inventory[0].Itemstack = slot.TakeOut(player.Entity.Controls.Sprint ? pile.BulkTakeQuantity : pile.DefaultTakeQuantity); } pile.MarkDirty(); world.BlockAccessor.MarkBlockDirty(pos); world.PlaySoundAt(new AssetLocation("sounds/block/planks"), pos.X, pos.Y, pos.Z, player, false); } return(true); }
public override void OnHeldInteractStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handling) { if (blockSel == null || byEntity?.World == null || !byEntity.Controls.Sneak) { return; } BlockPos onBlockPos = blockSel.Position; IPlayer byPlayer = null; if (byEntity is EntityPlayer) { byPlayer = byEntity.World.PlayerByUid(((EntityPlayer)byEntity).PlayerUID); } if (byPlayer == null) { return; } if (!byEntity.World.Claims.TryAccess(byPlayer, blockSel.Position, EnumBlockAccessFlags.BuildOrBreak)) { return; } BlockEntity be = byEntity.World.BlockAccessor.GetBlockEntity(onBlockPos); if (be is BlockEntityPlankPile) { BlockEntityPlankPile pile = (BlockEntityPlankPile)be; if (pile.OnPlayerInteract(byPlayer)) { handling = EnumHandHandling.PreventDefaultAction; ((byEntity as EntityPlayer)?.Player as IClientPlayer)?.TriggerFpAnimation(EnumHandInteract.HeldItemInteract); return; } } be = byEntity.World.BlockAccessor.GetBlockEntity(onBlockPos.AddCopy(blockSel.Face)); if (be is BlockEntityPlankPile) { BlockEntityPlankPile pile = (BlockEntityPlankPile)be; if (pile.OnPlayerInteract(byPlayer)) { handling = EnumHandHandling.PreventDefaultAction; ((byEntity as EntityPlayer)?.Player as IClientPlayer)?.TriggerFpAnimation(EnumHandInteract.HeldItemInteract); return; } } Block block = byEntity.World.GetBlock(new AssetLocation("plankpile")); if (block == null) { return; } BlockPos pos = onBlockPos.Copy(); if (byEntity.World.BlockAccessor.GetBlock(pos).Replaceable < 6000) { pos.Add(blockSel.Face); } bool ok = ((BlockPlankPile)block).Construct(slot, byEntity.World, pos, byPlayer); Cuboidf[] collisionBoxes = byEntity.World.BlockAccessor.GetBlock(pos).GetCollisionBoxes(byEntity.World.BlockAccessor, pos); if (collisionBoxes != null && collisionBoxes.Length > 0 && CollisionTester.AabbIntersect(collisionBoxes[0], pos.X, pos.Y, pos.Z, byPlayer.Entity.CollisionBox, byPlayer.Entity.SidedPos.XYZ)) { byPlayer.Entity.SidedPos.Y += collisionBoxes[0].Y2 - (byPlayer.Entity.SidedPos.Y - (int)byPlayer.Entity.SidedPos.Y); } if (ok) { handling = EnumHandHandling.PreventDefaultAction; ((byEntity as EntityPlayer)?.Player as IClientPlayer)?.TriggerFpAnimation(EnumHandInteract.HeldItemInteract); } }