Пример #1
0
        public override void OnBlockInteractStop(float secondsUsed, IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel)
        {
            if (!PlacedBlockEating)
            {
                base.OnBlockInteractStop(secondsUsed, world, byPlayer, blockSel);
            }
            if (!byPlayer.Entity.Controls.Sneak)
            {
                return;
            }

            BlockEntityMeal bemeal    = world.BlockAccessor.GetBlockEntity(blockSel.Position) as BlockEntityMeal;
            ItemStack       stack     = OnPickBlock(world, blockSel.Position);
            DummySlot       dummySlot = new DummySlot(stack, bemeal.inventory);

            dummySlot.MarkedDirty += () => true;


            if (tryFinishEatMeal(secondsUsed, dummySlot, byPlayer.Entity, false))
            {
                float servingsLeft = GetQuantityServings(world, stack);

                if (bemeal.QuantityServings <= 0)
                {
                    Block block = world.GetBlock(new AssetLocation(Attributes["eatenBlock"].AsString()));
                    world.BlockAccessor.SetBlock(block.BlockId, blockSel.Position);
                }
                else
                {
                    bemeal.QuantityServings = servingsLeft;
                    bemeal.MarkDirty(true);
                }
            }
        }
Пример #2
0
        public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel)
        {
            if (!PlacedBlockEating)
            {
                return(base.OnBlockInteractStart(world, byPlayer, blockSel));
            }

            ItemStack stack = OnPickBlock(world, blockSel.Position);

            if (!byPlayer.Entity.Controls.Sneak)
            {
                if (byPlayer.InventoryManager.TryGiveItemstack(stack, true))
                {
                    world.BlockAccessor.SetBlock(0, blockSel.Position);
                    world.PlaySoundAt(Sounds.Place, byPlayer, byPlayer);
                    return(true);
                }
                return(false);
            }

            BlockEntityMeal bemeal    = world.BlockAccessor.GetBlockEntity(blockSel.Position) as BlockEntityMeal;
            DummySlot       dummySlot = new DummySlot(stack, bemeal.inventory);

            dummySlot.MarkedDirty += () => true;

            return(tryPlacedBeginEatMeal(dummySlot, byPlayer));
        }
Пример #3
0
        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;

                float servingsLeft = Consume(world, byPlayer, GetContents(world, stack), GetQuantityServings(world, stack), GetRecipeCode(world, stack) == null);
                bemeal.QuantityServings = servingsLeft;

                if (bemeal.QuantityServings <= 0)
                {
                    Block block = world.GetBlock(new AssetLocation(Attributes["eatenBlock"].AsString()));
                    world.BlockAccessor.SetBlock(block.BlockId, blockSel.Position);
                }
                else
                {
                    bemeal.QuantityServings--;
                    bemeal.MarkDirty(true);
                }
            }
        }
Пример #4
0
        public override ItemStack OnPickBlock(IWorldAccessor world, BlockPos pos)
        {
            ItemStack stack = base.OnPickBlock(world, pos);

            BlockEntityMeal bem = world.BlockAccessor.GetBlockEntity(pos) as BlockEntityMeal;

            if (bem != null)
            {
                SetContents(bem.RecipeCode, stack, bem.GetNonEmptyContentStacks(), bem.QuantityServings);
            }

            return(stack);
        }
Пример #5
0
        public override int GetRandomColor(ICoreClientAPI capi, BlockPos pos, BlockFacing facing)
        {
            BlockEntityMeal bem = capi.World.BlockAccessor.GetBlockEntity(pos) as BlockEntityMeal;

            if (bem == null)
            {
                return(base.GetRandomColor(capi, pos, facing));
            }

            ItemStack[] stacks = bem.GetNonEmptyContentStacks(false);

            return(GetRandomBlockColor(capi, stacks));
        }
        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);
        }
Пример #7
0
        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);
                }
            }
        }
Пример #8
0
        public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel)
        {
            ItemStack stack = OnPickBlock(world, blockSel.Position);

            if (!byPlayer.Entity.Controls.Sneak)
            {
                if (byPlayer.InventoryManager.TryGiveItemstack(stack, true))
                {
                    world.BlockAccessor.SetBlock(0, blockSel.Position);
                    world.PlaySoundAt(this.Sounds.Place, byPlayer, byPlayer);
                    return(true);
                }
                return(false);
            }

            BlockEntityMeal bemeal    = world.BlockAccessor.GetBlockEntity(blockSel.Position) as BlockEntityMeal;
            DummySlot       dummySlot = new DummySlot(stack, bemeal.inventory);

            dummySlot.MarkedDirty += () => true;

            if (GetContentNutritionProperties(world, dummySlot, byPlayer.Entity) != null)
            {
                world.RegisterCallback((dt) =>
                {
                    if (byPlayer.Entity.Controls.HandUse == EnumHandInteract.BlockInteract)
                    {
                        byPlayer.Entity.PlayEntitySound("eat", byPlayer);
                    }
                }, 500);

                byPlayer.Entity.StartAnimation("eat");

                return(true);
            }

            return(false);
        }