public void ServeIntoBowl(BlockPos pos, IItemSlot potslot, IWorldAccessor world) { if (world.Side == EnumAppSide.Client) { return; } Block mealblock = api.World.GetBlock(new AssetLocation("bowl-meal")); world.BlockAccessor.SetBlock(mealblock.BlockId, pos); BlockEntityMeal bemeal = api.World.BlockAccessor.GetBlockEntity(pos) as BlockEntityMeal; if (bemeal == null) { return; } bemeal.RecipeCode = GetRecipeCode(world, potslot.Itemstack); ItemStack[] stacks = GetContents(api.World, potslot.Itemstack); for (int i = 0; i < stacks.Length; i++) { bemeal.inventory.GetSlot(i).Itemstack = stacks[i].Clone(); } int quantityServings = GetServings(world, potslot.Itemstack); SetServings(world, potslot.Itemstack, quantityServings - 1); if (quantityServings <= 0) { potslot.Itemstack = new ItemStack(api.World.GetBlock(new AssetLocation(FirstCodePart() + "-burned"))); } potslot.MarkDirty(); bemeal.MarkDirty(true); }
public override void OnBlockInteractStop(float secondsUsed, IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel) { if (!byPlayer.Entity.Controls.Sneak) { return; } ItemStack stack = OnPickBlock(world, blockSel.Position); if (world.Side == EnumAppSide.Server && secondsUsed >= 1.45f) { BlockEntityMeal bemeal = world.BlockAccessor.GetBlockEntity(blockSel.Position) as BlockEntityMeal; DummySlot dummySlot = new DummySlot(stack, bemeal.inventory); dummySlot.MarkedDirty += () => true; ItemStack[] contents = GetNonEmptyContents(world, stack); if (contents.Length > 0) { float servingsLeft = Consume(world, byPlayer, dummySlot, contents, GetQuantityServings(world, stack), GetRecipeCode(world, stack) == null); bemeal.QuantityServings = servingsLeft; } else { bemeal.QuantityServings = 0; } if (bemeal.QuantityServings <= 0) { Block block = world.GetBlock(new AssetLocation(Attributes["eatenBlock"].AsString())); world.BlockAccessor.SetBlock(block.BlockId, blockSel.Position); } else { bemeal.MarkDirty(true); } } }