public override void OnHeldInteractStart(ItemSlot itemslot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handling) { if (blockSel == null || byEntity?.World == null || !byEntity.Controls.Sneak) { return; } 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)) { itemslot.MarkDirty(); return; } BlockEntity be = byEntity.World.BlockAccessor.GetBlockEntity(blockSel.Position); if (be is BlockEntityPlatePile) { BlockEntityPlatePile pile = (BlockEntityPlatePile)be; if (pile.OnPlayerInteract(byPlayer)) { handling = EnumHandHandling.PreventDefault; return; } } be = byEntity.World.BlockAccessor.GetBlockEntity(blockSel.Position.AddCopy(blockSel.Face)); if (be is BlockEntityPlatePile) { BlockEntityPlatePile pile = (BlockEntityPlatePile)be; if (pile.OnPlayerInteract(byPlayer)) { handling = EnumHandHandling.PreventDefault; return; } } Block block = byEntity.World.GetBlock(new AssetLocation("platepile")); if (block == null) { return; } if (((BlockPlatePile)block).Construct(itemslot, byEntity.World, blockSel.Position.AddCopy(blockSel.Face), byPlayer)) { handling = EnumHandHandling.PreventDefault; } }
public override WorldInteraction[] GetPlacedBlockInteractionHelp(IWorldAccessor world, BlockSelection selection, IPlayer forPlayer) { return(new WorldInteraction[] { new WorldInteraction() { ActionLangCode = "blockhelp-platepile-add", MouseButton = EnumMouseButton.Right, HotKeyCode = "sneak", Itemstacks = new ItemStack[] { new ItemStack(this) }, GetMatchingStacks = (wi, bs, es) => { BlockEntityPlatePile pile = world.BlockAccessor.GetBlockEntity(bs.Position) as BlockEntityPlatePile; if (pile != null && !pile.inventory[0].Empty && pile.MaxStackSize > pile.inventory[0].StackSize) { ItemStack stack = pile.inventory[0].Itemstack.Clone(); stack.StackSize = 1; return new ItemStack[] { stack }; } return null; } }, new WorldInteraction() { ActionLangCode = "blockhelp-platepile-remove", MouseButton = EnumMouseButton.Right }, new WorldInteraction() { ActionLangCode = "blockhelp-platepile-4add", MouseButton = EnumMouseButton.Right, HotKeyCodes = new string[] { "sprint", "sneak" }, Itemstacks = new ItemStack[] { new ItemStack(this) }, GetMatchingStacks = (wi, bs, es) => { BlockEntityPlatePile pile = world.BlockAccessor.GetBlockEntity(bs.Position) as BlockEntityPlatePile; if (pile != null && !pile.inventory[0].Empty && pile.MaxStackSize > pile.inventory[0].StackSize) { ItemStack stack = pile.inventory[0].Itemstack.Clone(); stack.StackSize = pile.BulkTakeQuantity; return new ItemStack[] { stack }; } return null; } }, new WorldInteraction() { ActionLangCode = "blockhelp-platepile-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 BlockEntityPlatePile) { BlockEntityPlatePile pile = (BlockEntityPlatePile)be; return(pile.OnPlayerInteract(byPlayer)); } return(false); }
public override ItemStack OnPickBlock(IWorldAccessor world, BlockPos pos) { BlockEntity be = world.BlockAccessor.GetBlockEntity(pos); if (be is BlockEntityPlatePile) { BlockEntityPlatePile pile = (BlockEntityPlatePile)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 BlockEntityPlatePile) { BlockEntityPlatePile pile = (BlockEntityPlatePile)be; int q = player.Entity.Controls.Sprint ? pile.BulkTakeQuantity : pile.DefaultTakeQuantity; pile.inventory[0].Itemstack = (ItemStack)slot.Itemstack.Clone(); pile.inventory[0].Itemstack.StackSize = Math.Min(slot.StackSize, q); if (player.WorldData.CurrentGameMode != EnumGameMode.Creative) { slot.TakeOut(q); } pile.MarkDirty(true); world.PlaySoundAt(new AssetLocation("sounds/block/plate"), pos.X, pos.Y, pos.Z, player, false); } return(true); }
public override WorldInteraction[] GetPlacedBlockInteractionHelp(IWorldAccessor world, BlockSelection selection, IPlayer forPlayer) { return(new WorldInteraction[] { new WorldInteraction() { ActionLangCode = "blockhelp-platepile-add", MouseButton = EnumMouseButton.Right, HotKeyCode = "sneak", Itemstacks = new ItemStack[] { new ItemStack(this) }, GetMatchingStacks = (wi, bs, es) => { BlockEntityPlatePile pile = world.BlockAccessor.GetBlockEntity(bs.Position) as BlockEntityPlatePile; return pile != null && pile.MaxStackSize > pile.inventory[0].StackSize ? new ItemStack[] { pile.inventory[0].Itemstack } : null; } }, new WorldInteraction() { ActionLangCode = "blockhelp-platepile-remove", MouseButton = EnumMouseButton.Right } }); }
internal bool Construct(ItemSlot slot, IWorldAccessor world, BlockPos pos, IPlayer player) { Block belowBlock = world.BlockAccessor.GetBlock(pos.DownCopy()); if (!belowBlock.SideSolid[BlockFacing.UP.Index] && (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 BlockEntityPlatePile) { BlockEntityPlatePile pile = (BlockEntityPlatePile)be; pile.inventory[0].Itemstack = (ItemStack)slot.Itemstack.Clone(); pile.inventory[0].Itemstack.StackSize = 1; if (player.WorldData.CurrentGameMode != EnumGameMode.Creative) { slot.TakeOut(1); } pile.MarkDirty(true); world.PlaySoundAt(new AssetLocation("sounds/block/ingot"), pos.X, pos.Y, pos.Z, player, false); } return(true); }