public override void OnLoaded(ICoreAPI api) { base.OnLoaded(api); ItemStack[] stickStack = new ItemStack[] { new ItemStack(api.World.GetItem(new AssetLocation("stick"))) }; ItemStack[] saltStack = new ItemStack[] { new ItemStack(api.World.GetItem(new AssetLocation("salt")), 5) }; interactions = new WorldInteraction[] { new WorldInteraction() { ActionLangCode = "blockhelp-curdbundle-addstick", MouseButton = EnumMouseButton.Right, Itemstacks = stickStack, GetMatchingStacks = (WorldInteraction wi, BlockSelection blockSelection, EntitySelection entitySelection) => { BECheeseCurdsBundle beccb = api.World.BlockAccessor.GetBlockEntity(blockSelection.Position) as BECheeseCurdsBundle; return(beccb?.State == EnumCurdsBundleState.Bundled ? stickStack : null); } }, new WorldInteraction() { ActionLangCode = "blockhelp-curdbundle-squeeze", MouseButton = EnumMouseButton.Right, Itemstacks = null, ShouldApply = (WorldInteraction wi, BlockSelection blockSelection, EntitySelection entitySelection) => { BECheeseCurdsBundle beccb = api.World.BlockAccessor.GetBlockEntity(blockSelection.Position) as BECheeseCurdsBundle; return(beccb?.State == EnumCurdsBundleState.BundledStick && !beccb.Squuezed); } }, new WorldInteraction() { ActionLangCode = "blockhelp-curdbundle-open", MouseButton = EnumMouseButton.Right, Itemstacks = null, ShouldApply = (WorldInteraction wi, BlockSelection blockSelection, EntitySelection entitySelection) => { BECheeseCurdsBundle beccb = api.World.BlockAccessor.GetBlockEntity(blockSelection.Position) as BECheeseCurdsBundle; return(beccb?.State == EnumCurdsBundleState.BundledStick && beccb.Squuezed); } }, new WorldInteraction() { ActionLangCode = "blockhelp-curdbundle-addsalt", MouseButton = EnumMouseButton.Right, Itemstacks = saltStack, GetMatchingStacks = (WorldInteraction wi, BlockSelection blockSelection, EntitySelection entitySelection) => { BECheeseCurdsBundle beccb = api.World.BlockAccessor.GetBlockEntity(blockSelection.Position) as BECheeseCurdsBundle; return(beccb?.State == EnumCurdsBundleState.Opened ? saltStack : null); } }, new WorldInteraction() { ActionLangCode = "blockhelp-curdbundle-pickupcheese", MouseButton = EnumMouseButton.Right, Itemstacks = null, ShouldApply = (WorldInteraction wi, BlockSelection blockSelection, EntitySelection entitySelection) => { BECheeseCurdsBundle beccb = api.World.BlockAccessor.GetBlockEntity(blockSelection.Position) as BECheeseCurdsBundle; return(beccb?.State == EnumCurdsBundleState.OpenedSalted); } } }; }
public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel) { BECheeseCurdsBundle beccb = api.World.BlockAccessor.GetBlockEntity(blockSel.Position) as BECheeseCurdsBundle; ItemSlot hotbarSlot = byPlayer.InventoryManager.ActiveHotbarSlot; if (beccb == null) { return(false); } if (beccb.State == EnumCurdsBundleState.Bundled) { if (hotbarSlot.Itemstack?.Collectible.Code.Path == "stick") { beccb.State = EnumCurdsBundleState.BundledStick; hotbarSlot.TakeOut(1); hotbarSlot.MarkDirty(); } return(true); } if (beccb.State == EnumCurdsBundleState.BundledStick && !beccb.Squuezed) { beccb.StartSqueeze(byPlayer); return(true); } if (beccb.State == EnumCurdsBundleState.BundledStick && beccb.Squuezed) { beccb.State = EnumCurdsBundleState.Opened; api.World.PlaySoundAt(Sounds.Place, blockSel.Position.X + 0.5, blockSel.Position.Y, blockSel.Position.Z + 0.5, byPlayer); return(true); } if (beccb.State == EnumCurdsBundleState.Opened) { if (hotbarSlot.Itemstack?.Collectible.Code.Path == "salt" && hotbarSlot.StackSize >= 5) { beccb.State = EnumCurdsBundleState.OpenedSalted; hotbarSlot.TakeOut(5); hotbarSlot.MarkDirty(); } return(true); } if (beccb.State == EnumCurdsBundleState.OpenedSalted) { ItemStack cheeseRoll = new ItemStack(api.World.GetItem(new AssetLocation("rawcheese-salted"))); if (!byPlayer.InventoryManager.TryGiveItemstack(cheeseRoll, true)) { api.World.SpawnItemEntity(cheeseRoll, byPlayer.Entity.Pos.XYZ.Add(0, 0.5, 0)); } api.World.BlockAccessor.SetBlock(api.World.GetBlock(new AssetLocation("linen-normal-down")).Id, blockSel.Position); return(true); } return(true); }