Beispiel #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);
            }
        }
Beispiel #2
0
        public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel, ref EnumHandling handling)
        {
            handling = EnumHandling.PreventDefault;
            var      active = byPlayer.InventoryManager.ActiveHotbarSlot;
            BlockPos pos    = blockSel.Position;

            t = false;
            if (active.Itemstack != null)
            {
                foreach (var val in createBlocks)
                {
                    if (active.Itemstack.Collectible.WildCardMatch(new AssetLocation(val[0].ToString())))
                    {
                        makes = new AssetLocation(val[1].ToString());
                        count = Convert.ToInt32(val[2]);
                        t     = true;
                        break;
                    }
                }
                if (t && active.Itemstack.StackSize >= count)
                {
                    if (world.Side == EnumAppSide.Client)
                    {
                        world.PlaySoundAt(block.Sounds.Place, pos.X, pos.Y, pos.Z);
                    }
                    if (count < 0 && active.Itemstack.StackSize >= 64)
                    {
                        world.SpawnItemEntity(new ItemStack(active.Itemstack.Collectible, -count), pos.ToVec3d().Add(0.5, 0.5, 0.5), new Vec3d(0.0, 0.1, 0.0));
                    }
                    else
                    {
                        active.Itemstack.StackSize -= count;
                    }
                    if (active.Itemstack.StackSize <= 0)
                    {
                        active.Itemstack = null;
                    }
                    world.SpawnItemEntity(new ItemStack(world.GetBlock(makes)), pos.ToVec3d().Add(0.5, 0.5, 0.5), new Vec3d(0.0, 0.1, 0.0));
                    if (world.Side.IsServer())
                    {
                        world.SpawnCubeParticles(pos.ToVec3d().Add(0.5, 0.5, 0.5), active.Itemstack, 2, 16);
                    }
                    active.MarkDirty();
                    return(true);
                }
            }
            return(true);
        }
Beispiel #3
0
        public override void OnBlockBroken(IWorldAccessor world, BlockPos pos, IPlayer byPlayer, float dropQuantityMultiplier = 1f)
        {
            if (world.Side == EnumAppSide.Server && (byPlayer == null || byPlayer.WorldData.CurrentGameMode != EnumGameMode.Creative))
            {
                ItemStack drop = null;
                if (Variant["state"] == "normal")
                {
                    drop = new ItemStack(world.GetItem(new AssetLocation("reeds")), 10);
                }
                else
                {
                    drop = new ItemStack(world.GetItem(new AssetLocation("giantreedsroot")));
                }
                if (drop != null)
                {
                    world.SpawnItemEntity(drop, new Vec3d(pos.X + 0.5, pos.Y + 0.5, pos.Z + 0.5), null);
                }
            }
            if (byPlayer != null && Variant["state"] == "normal" && byPlayer.InventoryManager.ActiveTool == EnumTool.Knife)
            {
                world.BlockAccessor.SetBlock(world.GetBlock(CodeWithParts("harvested")).BlockId, pos);
                return;
            }

            if (Variant["habitat"] != "free")
            {
                world.BlockAccessor.SetBlock(world.GetBlock(new AssetLocation("water-still-7")).BlockId, pos);
            }
            else
            {
                world.BlockAccessor.SetBlock(0, pos);
            }
        }
        public override void OnGroundIdle(EntityItem entityItem)
        {
            base.OnGroundIdle(entityItem);

            IWorldAccessor world = entityItem.World;

            if (world.Side != EnumAppSide.Server)
            {
                return;
            }

            if (entityItem.Swimming && world.Rand.NextDouble() < 0.03)
            {
                TryFillFromBlock(entityItem, entityItem.SidedPos.AsBlockPos);
            }

            if (entityItem.Swimming && world.Rand.NextDouble() < 0.01)
            {
                ItemStack[] stacks = GetContents(world, entityItem.Itemstack);
                if (MealMeshCache.ContentsRotten(stacks))
                {
                    for (int i = 0; i < stacks.Length; i++)
                    {
                        if (stacks[i] != null && stacks[i].StackSize > 0 && stacks[i].Collectible.Code.Path == "rot")
                        {
                            world.SpawnItemEntity(stacks[i], entityItem.ServerPos.XYZ);
                        }
                    }

                    SetContent(entityItem.Itemstack, null);
                }
            }
        }
Beispiel #5
0
        public override void OnGroundIdle(EntityItem entityItem)
        {
            base.OnGroundIdle(entityItem);

            IWorldAccessor world = entityItem.World;

            if (world.Side != EnumAppSide.Server)
            {
                return;
            }

            if (entityItem.Swimming && world.Rand.NextDouble() < 0.01)
            {
                ItemStack[] stacks = GetContents(world, entityItem.Itemstack);

                if (MealMeshCache.ContentsRotten(stacks))
                {
                    for (int i = 0; i < stacks.Length; i++)
                    {
                        if (stacks[i] != null && stacks[i].StackSize > 0 && stacks[i].Collectible.Code.Path == "rot")
                        {
                            world.SpawnItemEntity(stacks[i], entityItem.ServerPos.XYZ);
                        }
                    }

                    Block block = world.GetBlock(new AssetLocation(Attributes["eatenBlock"].AsString()));
                    entityItem.Itemstack = new ItemStack(block);
                    entityItem.WatchedAttributes.MarkPathDirty("itemstack");
                }
            }
        }
Beispiel #6
0
 public static void SpawnItemEntity(this IWorldAccessor world, ItemStack[] stacks, Vec3d Pos, Vec3d velocity = null)
 {
     foreach (ItemStack stack in stacks)
     {
         world.SpawnItemEntity(stack, Pos, velocity);
     }
 }
        public bool RemoveResource(IWorldAccessor world, IPlayer byplayer, BlockSelection blockSel, string stype, int quant)
        {
            if (storedType == "" || storedtypes[stype] <= 0)
            {
                return(false);
            }
            if (quant > storedtypes[stype])
            {
                quant = storedtypes[stype];
            }

            ItemStack givestack;

            if (stype == "sand" || stype == "gravel")
            {
                Block filler = world.GetBlock(new AssetLocation("game", stype + "-" + storedType));
                givestack = new ItemStack(filler, Math.Min(filler.MaxStackSize, quant));
            }
            else
            {
                Item filler = world.GetItem(new AssetLocation("game", stype + "-" + storedType));
                givestack = new ItemStack(filler, Math.Min(filler.MaxStackSize, quant));
            }

            if (!byplayer.InventoryManager.TryGiveItemstack(givestack.Clone()))
            {
                world.SpawnItemEntity(givestack.Clone(), blockSel.HitPosition + (blockSel.HitPosition.Normalize() * .5) + blockSel.Position.ToVec3d(), blockSel.HitPosition.Normalize() * .05);
            }
            storedtypes[stype] -= givestack.StackSize;
            return(true);
        }
Beispiel #8
0
        public override void OnGroundIdle(EntityItem entityItem)
        {
            base.OnGroundIdle(entityItem);

            IWorldAccessor world = entityItem.World;

            if (world.Side != EnumAppSide.Server)
            {
                return;
            }

            if (entityItem.Swimming && world.Rand.NextDouble() < 0.01)
            {
                ItemStack[] stacks = GetContents(world, entityItem.Itemstack);
                if (MealMeshCache.ContentsRotten(stacks))
                {
                    for (int i = 0; i < stacks.Length; i++)
                    {
                        if (stacks[i] != null && stacks[i].StackSize > 0 && stacks[i].Collectible.Code.Path == "rot")
                        {
                            world.SpawnItemEntity(stacks[i], entityItem.ServerPos.XYZ);
                        }
                    }

                    entityItem.Itemstack.Attributes.RemoveAttribute("recipeCode");
                    entityItem.Itemstack.Attributes.RemoveAttribute("quantityServings");
                    entityItem.Itemstack.Attributes.RemoveAttribute("contents");
                }
            }
        }
Beispiel #9
0
        // Override to drop the barrel empty and drop its contents instead
        public override void OnBlockBroken(IWorldAccessor world, BlockPos pos, IPlayer byPlayer, float dropQuantityMultiplier = 1)
        {
            if (world.Side == EnumAppSide.Server && (byPlayer == null || byPlayer.WorldData.CurrentGameMode != EnumGameMode.Creative))
            {
                ItemStack[] drops = new ItemStack[] { new ItemStack(this) };

                for (int i = 0; i < drops.Length; i++)
                {
                    world.SpawnItemEntity(drops[i], new Vec3d(pos.X + 0.5, pos.Y + 0.5, pos.Z + 0.5), null);
                }

                world.PlaySoundAt(Sounds.GetBreakSound(byPlayer), pos.X, pos.Y, pos.Z, byPlayer);
            }

            if (EntityClass != null)
            {
                BlockEntity entity = world.BlockAccessor.GetBlockEntity(pos);
                if (entity != null)
                {
                    entity.OnBlockBroken();
                }
            }

            world.BlockAccessor.SetBlock(0, pos);
        }
Beispiel #10
0
        public override void OnBlockBroken(IWorldAccessor world, BlockPos pos, IPlayer byPlayer, float dropQuantityMultiplier = 1f)
        {
            if (world.Side == EnumAppSide.Server && (byPlayer == null || byPlayer.WorldData.CurrentGameMode != EnumGameMode.Creative))
            {
                foreach (var bdrop in Drops)
                {
                    ItemStack drop = bdrop.GetNextItemStack();
                    if (drop != null)
                    {
                        world.SpawnItemEntity(drop, new Vec3d(pos.X + 0.5, pos.Y + 0.5, pos.Z + 0.5), null);
                    }
                }

                world.PlaySoundAt(Sounds.GetBreakSound(byPlayer), pos.X, pos.Y, pos.Z, byPlayer);
            }

            if (byPlayer != null && Variant["state"] == "normal" && (byPlayer.InventoryManager.ActiveTool == EnumTool.Knife || byPlayer.InventoryManager.ActiveTool == EnumTool.Sickle || byPlayer.InventoryManager.ActiveTool == EnumTool.Scythe))
            {
                world.BlockAccessor.SetBlock(world.GetBlock(this.habitat == EnumReedsHabitat.Ice ? CodeWithVariants(new string[] { "habitat", "state" }, new string[] { "water", "harvested" })  : CodeWithVariant("state", "harvested")).BlockId, pos);
                return;
            }

            if (habitat != 0)
            {
                world.BlockAccessor.SetBlock(world.GetBlock(new AssetLocation("water-still-7")).BlockId, pos);
                world.BlockAccessor.GetBlock(pos).OnNeighbourBlockChange(world, pos, pos);
            }
            else
            {
                world.BlockAccessor.SetBlock(0, pos);
            }
        }
        public override void OnBlockBroken(IWorldAccessor world, BlockPos pos, IPlayer byPlayer, float dropQuantityMultiplier = 1f)
        {
            Block prev = GetPrevLayer(world);

            if (prev != null)
            {
                if (world.Side == EnumAppSide.Server && (byPlayer == null || byPlayer.WorldData.CurrentGameMode != EnumGameMode.Creative))
                {
                    ItemStack[] drops = GetDrops(world, pos, byPlayer, dropQuantityMultiplier);

                    if (drops != null)
                    {
                        for (int i = 0; i < drops.Length; i++)
                        {
                            world.SpawnItemEntity(drops[i], new Vec3d(pos.X + 0.5, pos.Y + 0.5, pos.Z + 0.5), null);
                        }
                    }

                    world.PlaySoundAt(Sounds.GetBreakSound(byPlayer), pos.X, pos.Y, pos.Z, byPlayer);
                }

                if (byPlayer == null || byPlayer.WorldData.CurrentGameMode != EnumGameMode.Creative)
                {
                    world.BlockAccessor.SetBlock(prev.BlockId, pos);
                }
                else
                {
                    world.BlockAccessor.SetBlock(0, pos);
                }

                return;
            }

            base.OnBlockBroken(world, pos, byPlayer);
        }
        public override void OnBlockInteractStop(float secondsUsed, IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel, ref EnumHandling handled)
        {
            handled = EnumHandling.PreventDefault;


            if (secondsUsed > harvestTime - 0.05f && harvestedStack != null && world.Side == EnumAppSide.Server)
            {
                float dropRate = 1;

                if (block.Attributes?.IsTrue("forageStatAffected") == true)
                {
                    dropRate *= byPlayer.Entity.Stats.GetBlended("forageDropRate");
                }

                ItemStack stack = harvestedStack.GetNextItemStack(dropRate);

                if (!byPlayer.InventoryManager.TryGiveItemstack(stack))
                {
                    world.SpawnItemEntity(stack, blockSel.Position.ToVec3d().Add(0.5, 0.5, 0.5));
                }

                if (harvestedBlock != null)
                {
                    world.BlockAccessor.SetBlock(harvestedBlock.BlockId, blockSel.Position);
                }

                world.PlaySoundAt(harvestingSound, blockSel.Position.X, blockSel.Position.Y, blockSel.Position.Z, byPlayer);
            }
        }
        public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel, ref EnumHandling handling)
        {
            if (!world.Claims.TryAccess(byPlayer, blockSel.Position, EnumBlockAccessFlags.Use))
            {
                return(false);
            }
            if (!block.Code.Path.Contains("empty"))
            {
                handling = EnumHandling.PreventDefault;

                //handles the collection of items, and the transformation of the block.
                world.Logger.VerboseDebug("Collecting item(s) from target block at {0}.", blockSel.Position);

                if (block.Drops != null && block.Drops.Length > 1)
                {
                    BlockDropItemStack drop  = block.Drops[0];
                    ItemStack          stack = drop.GetNextItemStack();

                    if (!byPlayer.InventoryManager.TryGiveItemstack(stack))
                    {
                        world.SpawnItemEntity(drop.GetNextItemStack(), blockSel.Position.ToVec3d().Add(0.5, 0.5, 0.5));
                    }

                    AssetLocation loc = block.Code.CopyWithPath(block.Code.Path.Replace(block.Code.Path.Split('-').Last(), "empty"));

                    world.BlockAccessor.SetBlock(world.GetBlock(loc).BlockId, blockSel.Position);

                    world.PlaySoundAt(new AssetLocation("sounds/player/collect"), blockSel.Position.X, blockSel.Position.Y, blockSel.Position.Z, byPlayer);
                }

                return(true);
            }

            return(false);
        }
        public override void OnBlockBroken(IWorldAccessor world, BlockPos pos, IPlayer byPlayer, float dropQuantityMultiplier = 1)
        {
            PlugnFeatherBE be = world.BlockAccessor.GetBlockEntity(pos) as PlugnFeatherBE;

            if (be == null || be.master == null)
            {
                Debug.WriteLine("master is null");
                base.OnBlockBroken(world, pos, byPlayer, dropQuantityMultiplier);
            }
            else
            {
                //Debug.WriteLine(world.Side);

                PlugnFeatherBE masterEntity = world.BlockAccessor.GetBlockEntity(be.master.AsBlockPos) as PlugnFeatherBE;
                ItemStack[]    drops        = GetDrops(world, pos, byPlayer);

                if (masterEntity != null)
                {
                    if (drops != null)
                    {
                        ItemStack drop = drops[0];
                        drop.StackSize = masterEntity.slaveCount + 1;
                        world.SpawnItemEntity(drop, byPlayer.Entity.Pos.XYZ);
                    }

                    foreach (Vec3i slave in masterEntity.slaves)
                    {
                        world.BlockAccessor.SetBlock(0, slave.AsBlockPos);
                        world.BlockAccessor.MarkBlockDirty(slave.AsBlockPos);
                    }
                    world.BlockAccessor.SetBlock(0, be.master.AsBlockPos);
                    world.BlockAccessor.MarkBlockDirty(be.master.AsBlockPos);
                }
            }
        }
        public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel,
                                                  ref EnumHandling handling)
        {
            handling = EnumHandling.PreventSubsequent;

            BlockEntity entity = world.BlockAccessor.GetBlockEntity(blockSel.Position);

            if (entity is BlockEntityResinVessel)
            {
                BlockEntityResinVessel vessel = (BlockEntityResinVessel)entity;

                if (!vessel.Inventory.Empty)
                {
                    ItemStack stack = vessel.Inventory[0].TakeOutWhole();
                    if (!byPlayer.InventoryManager.TryGiveItemstack(stack))
                    {
                        world.SpawnItemEntity(stack, blockSel.Position.ToVec3d().Add(0.5, 0.5, 0.5));
                    }

                    vessel.UpdateAsset();
                    return(true);
                }
                else
                {
                    return(false);
                }
            }

            return(false);
        }
Beispiel #16
0
        public override void OnBlockExploded(IWorldAccessor world, BlockPos pos, BlockPos explosionCenter, EnumBlastType blastType)
        {
            EnumHandling handled = EnumHandling.PassThrough;

            foreach (BlockBehavior behavior in BlockBehaviors)
            {
                behavior.OnBlockExploded(world, pos, explosionCenter, blastType, ref handled);
                if (handled == EnumHandling.PreventSubsequent)
                {
                    break;
                }
            }

            if (handled == EnumHandling.PreventDefault)
            {
                return;
            }



            double dropChancce = ExplosionDropChance(world, pos, blastType);

            if (world.Rand.NextDouble() < dropChancce)
            {
                ItemStack[] drops = GetDrops(world, pos, null);

                if (drops == null)
                {
                    return;
                }

                for (int i = 0; i < drops.Length; i++)
                {
                    if (SplitDropStacks)
                    {
                        for (int k = 0; k < drops[i].StackSize; k++)
                        {
                            ItemStack stack = drops[i].Clone();

                            if (stack.Collectible.Code.Path.Contains("crystal"))
                            {
                                continue;                                                  // Do not drop crystalized ores when the ore is being blown up
                            }
                            stack.StackSize = 1;
                            world.SpawnItemEntity(stack, new Vec3d(pos.X + 0.5, pos.Y + 0.5, pos.Z + 0.5), null);
                        }
                    }
                }
            }

            if (EntityClass != null)
            {
                BlockEntity entity = world.BlockAccessor.GetBlockEntity(pos);
                if (entity != null)
                {
                    entity.OnBlockBroken();
                }
            }
        }
        public override void OnBlockBroken(IWorldAccessor world, BlockPos pos, IPlayer byPlayer, float dropQuantityMultiplier = 1f)
        {
            base.OnBlockBroken(world, pos, byPlayer);

            Block block = GetPottedPlant(world);

            if (block != null)
            {
                world.SpawnItemEntity(new ItemStack(block), pos.ToVec3d().Add(0.5, 0.5, 0.5));
            }
        }
Beispiel #18
0
        public override void OnBlockBroken(IWorldAccessor world, BlockPos pos, IPlayer byPlayer, float dropQuantityMultiplier = 1f)
        {
            base.OnBlockBroken(world, pos, byPlayer);

            ItemStack contents = GetContents(world, pos);

            if (contents != null)
            {
                world.SpawnItemEntity(contents, pos.ToVec3d().Add(0.5, 0.5, 0.5));
            }
        }
        protected bool TryCollectLowest(IPlayer byPlayer, IWorldAccessor world, BlockPos pos)
        {
            Block ladderBlock = world.BlockAccessor.GetBlock(pos);

            if (ladderBlock.FirstCodePart() != ownFirstCodePart)
            {
                return(false);
            }

            BlockPos belowPos = pos.DownCopy();
            Block    belowBlock;

            while (belowPos.Y > 0)
            {
                belowBlock = world.BlockAccessor.GetBlock(belowPos);
                if (belowBlock.FirstCodePart() != ownFirstCodePart)
                {
                    break;
                }

                belowPos.Down();
            }

            belowPos.Up();
            Block collectBlock = world.BlockAccessor.GetBlock(belowPos);

            var bh = collectBlock.GetBehavior <BlockBehaviorLadder>();

            if (bh == null || !bh.isFlexible)
            {
                return(false);
            }

            if (!world.Claims.TryAccess(byPlayer, belowPos, EnumBlockAccessFlags.BuildOrBreak))
            {
                return(false);
            }

            ItemStack[] stacks = collectBlock.GetDrops(world, pos, byPlayer);

            world.BlockAccessor.SetBlock(0, belowPos);
            world.PlaySoundAt(collectBlock.Sounds.Break, pos.X + 0.5, pos.Y + 0.5, pos.Z + 0.5, byPlayer);

            if (stacks.Length > 0)
            {
                if (!byPlayer.InventoryManager.TryGiveItemstack(stacks[0], true))
                {
                    world.SpawnItemEntity(stacks[0], byPlayer.Entity.Pos.XYZ);
                }
            }


            return(true);
        }
Beispiel #20
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);
            }
        }
Beispiel #21
0
 public static void SpawnItemEntity(this IWorldAccessor world, JsonItemStack[] stacks, Vec3d Pos, Vec3d velocity = null)
 {
     foreach (JsonItemStack stack in stacks)
     {
         string err = "";
         stack.Resolve(world, err);
         if (stack.ResolvedItemstack != null)
         {
             world.SpawnItemEntity(stack.ResolvedItemstack, Pos, velocity);
         }
     }
 }
        public bool Drench(IWorldAccessor world, BlockSelection blockSel)
        {
            Block dropblock = world.GetBlock(new AssetLocation("game", "muddygravel"));

            if (storedtypes["gravel"] > 0)
            {
                ItemStack dropStack = new ItemStack(dropblock, Math.Min(dropblock.MaxStackSize / 4, storedtypes["gravel"]));//Deviding max stack drop by four because not doing so created a mess.
                world.SpawnItemEntity(dropStack.Clone(), blockSel.Position.ToVec3d() + blockSel.HitPosition, (blockSel.Face.Normalf.ToVec3d() * .05) + new Vec3d(0, .08, 0));
                storedtypes["gravel"] -= Math.Min(dropblock.MaxStackSize / 4, storedtypes["gravel"]);
                return(true);
            }
            return(false);
        }
        public override void OnBlockBroken(IWorldAccessor world, BlockPos pos, IPlayer byPlayer, float dropQuantityMultiplier = 1)
        {
            bool preventDefault = false;

            foreach (BlockBehavior behavior in BlockBehaviors)
            {
                EnumHandling handled = EnumHandling.PassThrough;

                behavior.OnBlockBroken(world, pos, byPlayer, ref handled);
                if (handled == EnumHandling.PreventDefault)
                {
                    preventDefault = true;
                }
                if (handled == EnumHandling.PreventSubsequent)
                {
                    return;
                }
            }

            if (preventDefault)
            {
                return;
            }


            if (world.Side == EnumAppSide.Server && (byPlayer == null || byPlayer.WorldData.CurrentGameMode != EnumGameMode.Creative))
            {
                ItemStack[] drops = new ItemStack[] { OnPickBlock(world, pos) };

                if (this.Attributes["drop"]?[GetType(world.BlockAccessor, pos)]?.AsBool() == true && drops != null)
                {
                    for (int i = 0; i < drops.Length; i++)
                    {
                        world.SpawnItemEntity(drops[i], new Vec3d(pos.X + 0.5, pos.Y + 0.5, pos.Z + 0.5), null);
                    }
                }

                world.PlaySoundAt(Sounds.GetBreakSound(byPlayer), pos.X, pos.Y, pos.Z, byPlayer);
            }

            if (EntityClass != null)
            {
                BlockEntity entity = world.BlockAccessor.GetBlockEntity(pos);
                if (entity != null)
                {
                    entity.OnBlockBroken();
                }
            }

            world.BlockAccessor.SetBlock(0, pos);
        }
Beispiel #24
0
        public override void OnBlockExploded(IWorldAccessor world, BlockPos pos, BlockPos explosionCenter, EnumBlastType blastType)
        {
            if (world.Rand.NextDouble() < 0.25)
            {
                ItemStack stack = new ItemStack(this);
                stack.StackSize = 1;
                world.SpawnItemEntity(stack, new Vec3d(pos.X + 0.5, pos.Y + 0.5, pos.Z + 0.5), null);
            }
            else
            {
                int startquantity = 3;
                if (Variant["variant"] == "cluster1" || Variant["variant"] == "cluster2")
                {
                    startquantity = 5;
                }
                if (Variant["variant"] == "large1" || Variant["variant"] == "large2")
                {
                    startquantity = 7;
                }

                int quantity = (int)(startquantity * Math.Min(1, world.Rand.NextDouble() * 0.31f + 0.7f));

                string type = Variant["type"];
                if (Variant["type"] == "milkyquartz")
                {
                    type = "clearquartz";
                }

                ItemStack stack = new ItemStack(api.World.GetItem(new AssetLocation(type)));

                for (int k = 0; k < quantity; k++)
                {
                    ItemStack drop = stack.Clone();
                    drop.StackSize = 1;
                    world.SpawnItemEntity(drop, new Vec3d(pos.X + 0.5, pos.Y + 0.5, pos.Z + 0.5), null);
                }
            }
        }
Beispiel #25
0
        public override void OnBlockBroken(IWorldAccessor world, BlockPos pos, IPlayer byPlayer, float dropQuantityMultiplier = 1)
        {
            //base.OnBlockBroken(world, pos, byPlayer, dropQuantityMultiplier);
            // Ugly: copy pasted from Block so EnumHandled.Last prevents placement of empty rock

            dropQuantityMultiplier *= byPlayer?.Entity.Stats.GetBlended("oreDropRate") ?? 1;

            EnumHandling handled = EnumHandling.PassThrough;

            foreach (BlockBehavior behavior in BlockBehaviors)
            {
                behavior.OnBlockBroken(world, pos, byPlayer, ref handled);
                if (handled == EnumHandling.PreventSubsequent)
                {
                    return;
                }
            }

            if (handled == EnumHandling.PreventDefault)
            {
                return;
            }

            if (world.Side == EnumAppSide.Server && (byPlayer == null || byPlayer.WorldData.CurrentGameMode != EnumGameMode.Creative))
            {
                ItemStack[] drops = GetDrops(world, pos, byPlayer, dropQuantityMultiplier);

                if (drops != null)
                {
                    for (int i = 0; i < drops.Length; i++)
                    {
                        world.SpawnItemEntity(drops[i], new Vec3d(pos.X + 0.5, pos.Y + 0.5, pos.Z + 0.5), null);
                    }
                }

                world.PlaySoundAt(Sounds.GetBreakSound(byPlayer), pos.X, pos.Y, pos.Z, byPlayer);
            }

            world.BlockAccessor.SetBlock(0, pos);


            if (byPlayer != null && byPlayer.WorldData.CurrentGameMode != EnumGameMode.Creative)
            {
                CollectibleObject coll = byPlayer?.InventoryManager.ActiveHotbarSlot.Itemstack?.Collectible;
                if (LastCodePart(1) == "flint" && (coll == null || coll.ToolTier == 0))
                {
                    world.BlockAccessor.SetBlock(world.GetBlock(new AssetLocation("rock-" + LastCodePart())).BlockId, pos);
                }
            }
        }
Beispiel #26
0
        public void TryFillBucketFromBlock(EntityItem byEntityItem, BlockPos pos)
        {
            IWorldAccessor world = byEntityItem.World;

            Block block = world.BlockAccessor.GetBlock(pos);

            if (block.Attributes?["waterTightContainerProps"].Exists == false)
            {
                return;
            }
            WaterTightContainableProps props = block.Attributes?["waterTightContainerProps"].AsObject <WaterTightContainableProps>();

            if (props?.WhenFilled == null || !props.Containable)
            {
                return;
            }

            if (props.WhenFilled.Stack.ResolvedItemstack == null)
            {
                props.WhenFilled.Stack.Resolve(world, "blockbucket");
            }

            ItemStack whenFilledStack = props.WhenFilled.Stack.ResolvedItemstack;
            ItemStack contentStack    = GetContent(world, byEntityItem.Itemstack);
            bool      canFill         = contentStack == null || (contentStack.Equals(world, whenFilledStack, GlobalConstants.IgnoredStackAttributes) && GetCurrentLitres(world, byEntityItem.Itemstack) < BucketCapacityLitres);

            if (!canFill)
            {
                return;
            }

            whenFilledStack.StackSize = (int)(props.ItemsPerLitre * BucketCapacityLitres);

            ItemStack fullBucketStack = new ItemStack(this);

            SetContent(fullBucketStack, whenFilledStack);

            if (byEntityItem.Itemstack.StackSize <= 1)
            {
                byEntityItem.Itemstack = fullBucketStack;
            }
            else
            {
                byEntityItem.Itemstack.StackSize--;
                world.SpawnItemEntity(fullBucketStack, byEntityItem.LocalPos.XYZ);
            }

            world.PlaySoundAt(props.FillSpillSound, pos.X, pos.Y, pos.Z, null);
        }
Beispiel #27
0
        public override void OnBlockBroken(IWorldAccessor world, BlockPos pos, IPlayer byPlayer, float dropQuantityMultiplier = 1)
        {
            if (world.Side == EnumAppSide.Server && (byPlayer == null || byPlayer.WorldData.CurrentGameMode != EnumGameMode.Creative))
            {
                ItemStack stack = OnPickBlock(world, pos);

                if (stack != null)
                {
                    world.SpawnItemEntity(stack, new Vec3d(pos.X + 0.5, pos.Y + 0.5, pos.Z + 0.5), null);
                }

                world.PlaySoundAt(Sounds.GetBreakSound(byPlayer), pos.X, pos.Y, pos.Z, byPlayer);
            }

            world.BlockAccessor.SetBlock(0, pos);
        }
Beispiel #28
0
        public override void OnBlockBroken(IWorldAccessor world, BlockPos Pos, IPlayer byPlayer, float dropQuantityMultiplier = 1)
        {
            base.OnBlockBroken(world, Pos, byPlayer, dropQuantityMultiplier);
            ItemSlot itemslot = byPlayer?.InventoryManager?.ActiveHotbarSlot;

            if (FirstCodePart() == "palmlog")
            {
                if (itemslot?.Itemstack == null || !Code.ToString().Contains("grown") || !world.Side.IsServer())
                {
                    return;
                }
                if (itemslot?.Itemstack.Collectible.Tool == EnumTool.Axe)
                {
                    int numfelled = 0;
                    for (int x = -2; x <= 2; x++)
                    {
                        for (int z = -2; z <= 2; z++)
                        {
                            for (int y = 0; y <= 16; y++)
                            {
                                BlockPos bPos   = new BlockPos(Pos.X + x, Pos.Y + y, Pos.Z + z);
                                Block    bBlock = world.BlockAccessor.GetBlock(bPos);
                                if (bBlock is BlockPalmTree || bBlock.FirstCodePart() == "palmfruits")
                                {
                                    if (itemslot.Itemstack == null)
                                    {
                                        return;
                                    }

                                    foreach (ItemStack item in GetDrops(world, bPos, byPlayer))
                                    {
                                        world.SpawnItemEntity(item, bPos.ToVec3d());
                                    }
                                    world.BlockAccessor.SetBlock(0, bPos);
                                    numfelled++;
                                }
                            }
                        }
                    }
                    if (numfelled > 15)
                    {
                        Vec3d vec3d = Pos.MidPoint();
                        this.api.World.PlaySoundAt(new AssetLocation("sounds/effect/treefell"), vec3d.X, vec3d.Y, vec3d.Z, null, false, 32f, GameMath.Clamp((float)numfelled / 30, 0.25f, 1f));
                    }
                }
            }
        }
        public override void OnBlockBroken(IWorldAccessor world, BlockPos pos, IPlayer byPlayer, float dropQuantityMultiplier = 1)
        {
            BlockEntity be = world.BlockAccessor.GetBlockEntity(pos);

            if (be is GenericStorageCapBE)
            {
                be = world.BlockAccessor.GetBlockEntity((be as GenericStorageCapBE).core);
            }

            var rcbe = be as RoughCutStorageBE;

            if (rcbe != null && rcbe.blockStack.Attributes.GetInt("stonestored") > 0)
            {
                world.SpawnItemEntity(rcbe.blockStack.Clone(), pos.ToVec3d());
            }

            base.OnBlockBroken(world, pos, byPlayer, dropQuantityMultiplier);
        }
        public override void OnBlockBroken(
            IWorldAccessor world, BlockPos pos,
            IPlayer byPlayer, ref EnumHandling handling)
        {
            // Execute default behavior if broken in creative mode.
            if (byPlayer?.WorldData.CurrentGameMode == EnumGameMode.Creative)
            {
                return;
            }

            // Replace branch block with non-leafy version.
            var newCode  = block.Code.ToString().Replace("leafybranch", "branch");
            var newBlock = world.GetBlock(new AssetLocation(newCode));

            // If there is no associated non-leafy block, execute default behavior.
            if (newBlock == null)
            {
                return;
            }
            // Otherwise continue and replace with non-leafy version.
            world.BlockAccessor.SetBlock(newBlock.BlockId, pos);

            // On server, drop items from the destroyed leaves. Like saplings!
            if (world.Side == EnumAppSide.Server)
            {
                var center = new Vec3d(pos.X + 0.5, pos.Y + 0.5, pos.Z + 0.5);
                var drops  = block.GetDrops(world, pos, byPlayer, 1.0F) ?? new ItemStack[0];
                foreach (var stack in drops)
                {
                    var maxStackSize = (block.SplitDropStacks ? 1 : stack.StackSize);
                    for (int i = 0; i < stack.StackSize; i += maxStackSize)
                    {
                        var dropStack = stack.Clone();
                        dropStack.StackSize = Math.Min(maxStackSize, stack.StackSize - i);
                        world.SpawnItemEntity(dropStack, center, null);
                    }
                }
                world.PlaySoundAt(this.block.Sounds?.GetBreakSound(byPlayer),
                                  center.X, center.Y, center.Z, byPlayer);
            }

            // Override default behavior.
            handling = EnumHandling.PreventDefault;
        }