Пример #1
0
        public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel)
        {
            EnumTool?tool = byPlayer.InventoryManager.ActiveHotbarSlot?.Itemstack?.Collectible.Tool;

            if (tool == EnumTool.Knife || tool == EnumTool.Sword)
            {
                BECheese bec = world.BlockAccessor.GetBlockEntity(blockSel.Position) as BECheese;

                if (bec.Inventory[0].Itemstack?.Collectible.Variant["type"] == "waxedcheddar")
                {
                    var newStack = new ItemStack(api.World.GetItem(bec.Inventory[0].Itemstack?.Collectible.CodeWithVariant("type", "cheddar")));

                    TransitionableProperties[] tprops = newStack.Collectible.GetTransitionableProperties(api.World, newStack, null);

                    var perishProps = tprops.FirstOrDefault(p => p.Type == EnumTransitionType.Perish);
                    perishProps.TransitionedStack.Resolve(api.World, "pie perished stack");

                    CarryOverFreshness(api, bec.Inventory[0], newStack, perishProps);

                    bec.Inventory[0].Itemstack = newStack;
                    bec.Inventory[0].MarkDirty();

                    bec.MarkDirty(true);
                    return(true);
                }

                ItemStack stack = bec?.TakeSlice();
                if (stack != null)
                {
                    if (!byPlayer.InventoryManager.TryGiveItemstack(stack, true))
                    {
                        world.SpawnItemEntity(stack, blockSel.Position.ToVec3d().Add(0.5, 0.5, 0.5));
                    }
                }

                return(true);
            }
            else
            {
                BECheese bec   = world.BlockAccessor.GetBlockEntity(blockSel.Position) as BECheese;
                var      stack = bec.Inventory[0].Itemstack;
                if (stack != null)
                {
                    if (!byPlayer.InventoryManager.TryGiveItemstack(stack, true))
                    {
                        world.SpawnItemEntity(stack, blockSel.Position.ToVec3d().Add(0.5, 0.5, 0.5));
                    }
                }

                world.BlockAccessor.SetBlock(0, blockSel.Position);
                return(true);
            }
        }
Пример #2
0
        public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel)
        {
            if (byPlayer.InventoryManager.ActiveHotbarSlot?.Itemstack?.Collectible.Tool == EnumTool.Knife)
            {
                BECheese bec = world.BlockAccessor.GetBlockEntity(blockSel.Position) as BECheese;

                if (bec.Inventory[0].Itemstack?.Collectible.Variant["type"] == "waxedcheddar")
                {
                    bec.Inventory[0].Itemstack = new ItemStack(api.World.GetItem(bec.Inventory[0].Itemstack?.Collectible.CodeWithVariant("type", "cheddar")));
                    bec.Inventory[0].MarkDirty();
                    bec.MarkDirty(true);
                    return(true);
                }

                ItemStack stack = bec?.TakeSlice();
                if (stack != null)
                {
                    if (!byPlayer.InventoryManager.TryGiveItemstack(stack, true))
                    {
                        world.SpawnItemEntity(stack, blockSel.Position.ToVec3d().Add(0.5, 0.5, 0.5));
                    }
                }

                return(true);
            }
            else
            {
                BECheese bec   = world.BlockAccessor.GetBlockEntity(blockSel.Position) as BECheese;
                var      stack = bec.Inventory[0].Itemstack;
                if (stack != null)
                {
                    if (!byPlayer.InventoryManager.TryGiveItemstack(stack, true))
                    {
                        world.SpawnItemEntity(stack, blockSel.Position.ToVec3d().Add(0.5, 0.5, 0.5));
                    }
                }

                world.BlockAccessor.SetBlock(0, blockSel.Position);
                return(true);
            }
        }