private void OnSlowServerTick(float dt)
        {
            if (!canBurn(FuelPos))
            {
                KillFire(false);
                return;
            }

            Entity[] entities = Api.World.GetEntitiesAround(FirePos.ToVec3d().Add(0.5, 0.5, 0.5), 3, 3, (e) => true);
            Vec3d    ownPos   = FirePos.ToVec3d();

            for (int i = 0; i < entities.Length; i++)
            {
                Entity entity = entities[i];
                if (!CollisionTester.AabbIntersect(entity.SelectionBox, entity.ServerPos.X, entity.ServerPos.Y, entity.ServerPos.Z, fireCuboid, ownPos))
                {
                    continue;
                }

                if (entity.Alive)
                {
                    entity.ReceiveDamage(new DamageSource()
                    {
                        Source = EnumDamageSource.Block, SourceBlock = fireBlock, SourcePos = ownPos, Type = EnumDamageType.Fire
                    }, 2f);
                }

                if (Api.World.Rand.NextDouble() < 0.125)
                {
                    entity.Ignite();
                }
            }

            if (FuelPos != FirePos && Api.World.BlockAccessor.GetBlock(FirePos).LiquidCode == "water")
            {
                KillFire(false);
                return;
            }

            if (Api.World.BlockAccessor.GetRainMapHeightAt(FirePos.X, FirePos.Z) <= FirePos.Y)   // It's more efficient to do this quick check before GetPrecipitation
            {
                // Die on rainfall
                tmpPos.Set(FirePos.X + 0.5, FirePos.Y + 0.5, FirePos.Z + 0.5);
                double rain = wsys.GetPrecipitation(tmpPos);
                if (rain > 0.15)
                {
                    Api.World.PlaySoundAt(new AssetLocation("sounds/effect/extinguish"), FirePos.X + 0.5, FirePos.Y, FirePos.Z + 0.5, null, false, 16);

                    if (rand.NextDouble() < rain / 2)
                    {
                        KillFire(false);
                        return;
                    }
                }
            }
        }
Пример #2
0
 public void PlaySoundDispenseParticles(IWorldAccessor world, BlockPos pos, ItemSlot slot)
 {
     try
     {
         if (world.Side.IsServer())
         {
             world.SpawnCubeParticles(pos, pos.ToVec3d().Add(particleOrigin), pRadius, pQuantity);
             world.SpawnCubeParticles(pos.ToVec3d().Add(particleOrigin), slot.Itemstack, pRadius, pQuantity);
             world.PlaySoundAt(block.Sounds.Place, pos.X, pos.Y, pos.Z);
         }
     }
     catch (Exception) { }
 }
Пример #3
0
        public override void OnBlockPlaced(IWorldAccessor world, BlockPos blockPos, ref EnumHandling handled)
        {
            testBlockPos.Clear();
            lworld = world;
            if (world.Side != EnumAppSide.Server)
            {
                return;
            }
            BlockPos pos = blockPos;

            targetPos = world.GetNearestEntity(pos.ToVec3d(), 64, 64).Pos.AsBlockPos;
            Vec3d    posv = pos.ToVec3d();
            Vec3d    tgtv = targetPos.ToVec3d();
            BlockPos mP   = ((posv.Add(tgtv)) / 2).AsBlockPos;
            int      sR   = (int)mP.DistanceTo(pos) + 4;
            var      grid = new CubeGrid(sR * 2, sR * 2, sR * 2);

            if (!grid.isInBounds(world, targetPos) || !grid.isPassable(world, targetPos) || !grid.isWalkable(world, targetPos))
            {
                return;
            }
            for (int x = mP.X - sR; x <= mP.X + sR; x++)
            {
                for (int y = mP.Y - sR; y <= mP.Y + sR; y++)
                {
                    for (int z = mP.Z - sR; z <= mP.Z + sR; z++)
                    {
                        BlockPos currentPos = new BlockPos(x, y, z);
                        if (grid.isInBounds(world, currentPos) && grid.isPassable(world, currentPos) && grid.isWalkable(world, currentPos))
                        {
                            grid.air.Add(currentPos);
                        }
                        else
                        {
                            grid.walls.Add(currentPos);
                        }
                    }
                }
            }
            var astar = new AStarSearch(world, grid, pos, targetPos);

            DrawGrid(world, astar, mP, sR);
            world.BlockAccessor.SetBlock(2278, pos);
            //world.BlockAccessor.SetBlock(2279, mP);
            world.BlockAccessor.SetBlock(2278, targetPos);
            testBlockPos.Add(targetPos);
            testBlockPos.Add(pos);
            //testBlockPos.Add(mP);
            return;
        }
Пример #4
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);
        }
Пример #5
0
        public override bool ShouldExecute()
        {
            if (rand.NextDouble() > searchFrequency)
            {
                return(false);
            }

            double dx = rand.NextDouble() * 4 - 2;
            double dz = rand.NextDouble() * 4 - 2;

            tmpPos.Set((int)(entity.ServerPos.X + dx), 0, (int)(entity.ServerPos.Z + dz));
            tmpPos.Y = entity.World.BlockAccessor.GetTerrainMapheightAt(tmpPos) + 1;

            Block block = entity.World.BlockAccessor.GetBlock(tmpPos);

            if (block.IsLiquid() || block.Attributes == null)
            {
                return(false);
            }

            if (block.Attributes["butterflyFeed"].AsBool() == true)
            {
                double topPos = block.Attributes["sitHeight"].AsDouble(block.TopMiddlePos.Y);

                bool weak = block.VertexFlags.WindMode == EnumWindBitMode.WeakWind || block.VertexFlags.WindMode == EnumWindBitMode.TallBend;

                entity.WatchedAttributes.SetDouble("windWaveIntensity", block.VertexFlags.WindMode != EnumWindBitMode.NoWind ? (weak ? topPos / 2 : topPos) : 0);

                MainTarget = tmpPos.ToVec3d().Add(block.TopMiddlePos.X, topPos, block.TopMiddlePos.Z);
                return(true);
            }

            return(false);
        }
Пример #6
0
        protected override void DoDeviceComplete()
        {
            deviceState = enDeviceState.IDLE;
            BlockPos    bp              = Pos.Copy().Offset(outputFace);
            BlockEntity checkblock      = Api.World.BlockAccessor.GetBlockEntity(bp);
            var         outputContainer = checkblock as BlockEntityContainer;

            if (Api.World is IServerWorldAccessor)
            {
                DummyInventory dummy = new DummyInventory(Api);

                List <ItemStack> outputitems = MacerationRecipe.GetMacerate(workingitem, Api, MachineName);
                foreach (ItemStack outitem in outputitems)
                {
                    if (outitem == null)
                    {
                        continue;
                    }
                    dummy[0].Itemstack = outitem;
                    //no output conatiner, spitout stuff
                    if (outputContainer != null)
                    {
                        bool stoptrying    = false;
                        int  safetycounter = 0;
                        while (!stoptrying)
                        {
                            WeightedSlot tryoutput = outputContainer.Inventory.GetBestSuitedSlot(dummy[0]);

                            if (tryoutput.slot != null)
                            {
                                ItemStackMoveOperation op = new ItemStackMoveOperation(Api.World, EnumMouseButton.Left, 0, EnumMergePriority.DirectMerge, dummy[0].StackSize);

                                dummy[0].TryPutInto(tryoutput.slot, ref op);
                                tryoutput.slot.MarkDirty();
                                if (dummy[0] == null)
                                {
                                    stoptrying = true;
                                }
                                else if (dummy[0].StackSize == 0)
                                {
                                    stoptrying = true;
                                }
                            }
                            else
                            {
                                stoptrying = true;
                            }
                            safetycounter++;
                            if (safetycounter > 24)
                            {
                                stoptrying = true;
                            }
                        }
                    }
                    Vec3d pos = bp.ToVec3d();

                    dummy.DropAll(pos);
                }
            }
        }
        public override bool ShouldExecute()
        {
            if (rand.NextDouble() > searchFrequency)
            {
                return(false);
            }

            double dx = rand.NextDouble() * 4 - 2;
            double dz = rand.NextDouble() * 4 - 2;

            tmpPos.Set((int)(entity.ServerPos.X + dx), 0, (int)(entity.ServerPos.Z + dz));
            tmpPos.Y = entity.World.BlockAccessor.GetTerrainMapheightAt(tmpPos) + 1;

            Block block = entity.World.BlockAccessor.GetBlock(tmpPos);

            if (block.IsLiquid() || block.Attributes == null)
            {
                return(false);
            }

            if (block.Attributes["butterflyFeed"].AsBool() == true)
            {
                double topPos = block.Attributes["sitHeight"].AsDouble(block.TopMiddlePos.Y);

                entity.WatchedAttributes.SetDouble("sitHeight", topPos);

                MainTarget = tmpPos.ToVec3d().Add(block.TopMiddlePos.X, topPos, block.TopMiddlePos.Z);
                return(true);
            }

            return(false);
        }
        private bool TryFalling(IWorldAccessor world, BlockPos pos)
        {
            if (world.Side == EnumAppSide.Client)
            {
                return(false);
            }

            ICoreServerAPI sapi = (world as IServerWorldAccessor).Api as ICoreServerAPI;

            if (!sapi.Server.Config.AllowFallingBlocks)
            {
                return(false);
            }

            if (IsReplacableBeneath(world, pos))
            {
                // Prevents duplication
                Entity entity = world.GetNearestEntity(pos.ToVec3d().Add(0.5, 0.5, 0.5), 1, 3, (e) =>
                {
                    return(e is EntityBlockFalling && ((EntityBlockFalling)e).initialPos.Equals(pos));
                }
                                                       );

                if (entity == null)
                {
                    EntityBlockFalling entityblock = new EntityBlockFalling(block, world.BlockAccessor.GetBlockEntity(pos), pos);
                    world.SpawnEntity(entityblock);
                }

                return(true);
            }

            return(false);
        }
Пример #9
0
        public bool InBlockBounds(Vec3d vec, float height, out float suffocation)
        {
            suffocation = 0.0f;

            vec.Sub(0.5, 0, 0.5).Add(0, height / 2.0, 0);

            BlockPos pos         = new BlockPos((int)Math.Round(vec.X), (int)Math.Round(vec.Y), (int)Math.Round(vec.Z));
            Vec3d    blockCenter = pos.ToVec3d().AddCopy(0.5, 0.5, 0.5);
            Block    block       = sapi.World.BlockAccessor.GetBlock(pos);
            double   distance    = Math.Sqrt(vec.SquareDistanceTo(blockCenter));

            if (block.IsLiquid() && distance < 1.5)
            {
                suffocation = 0.01f;
                return(true);
            }
            if (block.Id == 0 || block.CollisionBoxes == null)
            {
                return(false);
            }

            for (int i = 0; i < block.CollisionBoxes.Length; i++)
            {
                suffocation = 0.5f;
                if ((block.CollisionBoxes[i].Area() > 0.512) && distance < 1.11)
                {
                    return(true);
                }
            }
            return(false);
        }
        private void GenerateSteamParticles(BlockPos pos, IWorldAccessor world)
        {
            float minQuantity   = 50;
            float maxQuantity   = 100;
            int   color         = ColorUtil.ToRgba(100, 225, 225, 225);
            Vec3d minPos        = new Vec3d();
            Vec3d addPos        = new Vec3d();
            Vec3f minVelocity   = new Vec3f(-0.25f, 0.1f, -0.25f);
            Vec3f maxVelocity   = new Vec3f(0.25f, 0.1f, 0.25f);
            float lifeLength    = 2.0f;
            float gravityEffect = -0.015f;
            float minSize       = 0.1f;
            float maxSize       = 0.1f;

            SimpleParticleProperties steamParticles = new SimpleParticleProperties(
                minQuantity, maxQuantity,
                color,
                minPos, addPos,
                minVelocity, maxVelocity,
                lifeLength,
                gravityEffect,
                minSize, maxSize,
                EnumParticleModel.Quad
                );

            steamParticles.minPos.Set(pos.ToVec3d().AddCopy(0.5, 1.1, 0.5));
            steamParticles.addPos.Set(new Vec3d(0.5, 1.0, 0.5));
            steamParticles.SizeEvolve = new EvolvingNatFloat(EnumTransformFunction.LINEARINCREASE, 1.0f);
            world.SpawnParticles(steamParticles);
        }
Пример #11
0
 public void TryGiveItem(ItemStack stack, ItemSlot slot, EntityAgent byEntity, WaterTightContainableProps props, BlockPos pos)
 {
     slot.TakeOut(1);
     if (!byEntity.TryGiveItemStack(stack))
     {
         api.World.SpawnItemEntity(stack, pos.ToVec3d());
     }
     api.World.PlaySoundAt(props.FillSpillSound, pos.X, pos.Y, pos.Z);
 }
Пример #12
0
        void HandleTeleporting(float dt)
        {
            toremove.Clear();

            foreach (var val in tpingEntities)
            {
                if (val.Value.Entity.Teleporting)
                {
                    continue;
                }

                val.Value.SecondsPassed += Math.Min(0.5f, dt);

                if (api.World.ElapsedMilliseconds - val.Value.LastCollideMs > 100)
                {
                    toremove.Add(val.Key);
                    continue;
                }

                if (val.Value.SecondsPassed > 1.5 && tpLocation != null)
                {
                    // Preload the chunk
                    sapi.WorldManager.LoadChunkColumnFast((int)tpLocation.X / api.World.BlockAccessor.ChunkSize, (int)tpLocation.Z / api.World.BlockAccessor.ChunkSize, new ChunkLoadOptions()
                    {
                        KeepLoaded = true
                    });
                }

                if (val.Value.SecondsPassed > 5 && tpLocation != null)
                {
                    val.Value.Entity.TeleportTo(tpLocation.ToVec3d().Add(0.5, 1, 0.5));

                    Entity e = val.Value.Entity;
                    if (e is EntityPlayer)
                    {
                        api.World.Logger.Debug("Teleporting player {0} to {1}", (e as EntityPlayer).GetBehavior <EntityBehaviorNameTag>().DisplayName, tpLocation);
                        manager.DidTranslocateServer((e as EntityPlayer).Player as IServerPlayer);
                    }
                    else
                    {
                        api.World.Logger.Debug("Teleporting entity {0} to {1}", e.Code, tpLocation);
                    }

                    toremove.Add(val.Key);

                    activated = false;

                    MarkDirty();
                }
            }

            foreach (long entityid in toremove)
            {
                tpingEntities.Remove(entityid);
            }
        }
Пример #13
0
        void DropPlantContainer(int blockid, BlockPos pos)
        {
            Block block = api.World.GetBlock(blockid);

            if (block.Code == null)
            {
                return;
            }

            string[] parts = block.Code.Path.Split(new char[] { '-' }, 3);
            if (parts.Length < 3)
            {
                return;
            }

            if ((parts[0] == "clayplanter" || parts[1] == "flowerpot") && parts.Length >= 3)
            {
                Block     potblock = api.World.GetBlock(new AssetLocation(parts[0] + "-" + parts[1]));
                ItemStack potStack = new ItemStack(potblock);
                api.World.SpawnItemEntity(potStack, pos.ToVec3d().Add(0.5, 0.5, 0.5));

                Block plantBlock = null;

                if (plantBlock == null)
                {
                    plantBlock = api.World.GetBlock(new AssetLocation("flower-" + parts[2]));
                }
                if (plantBlock == null)
                {
                    plantBlock = api.World.GetBlock(new AssetLocation("sapling-" + parts[2]));
                }
                if (plantBlock == null)
                {
                    plantBlock = api.World.GetBlock(new AssetLocation("mushroom-" + parts[2] + "-normal"));
                }

                if (plantBlock != null)
                {
                    ItemStack plantStack = new ItemStack(plantBlock);
                    api.World.SpawnItemEntity(plantStack, pos.ToVec3d().Add(0.5, 0.5, 0.5));
                }
            }
        }
Пример #14
0
 private void DropItems(BlockPos pos)
 {
     if (drops != null)
     {
         for (int i = 0; i < drops.Length; i++)
         {
             World.SpawnItemEntity(drops[i], pos.ToVec3d().Add(0.5, 0.5, 0.5));
         }
     }
 }
Пример #15
0
        public void RecentreMapOnPosition(string option, CmdArgs args)
        {
            var playerPos = Api.World.Player.Entity.Pos.AsBlockPos;
            var x         = args.PopInt().GetValueOrDefault(playerPos.X);
            var z         = args.PopInt().GetValueOrDefault(playerPos.Z);
            var pos       = new BlockPos(x, 1, z).Add(Api.World.DefaultSpawnPosition.AsBlockPos);

            Api.ShowChatMessage(LangEx.Message("RecentreOnPosition", x, z));
            RecentreMap(pos.ToVec3d());
        }
Пример #16
0
        private void PlayerSitDown(IWorldAccessor world, IPlayer byPlayer, BlockPos chairPosition)
        {
            PlayerData playerData = PlayerManager.Instance.GetOrAddPlayerData(byPlayer);

            // Sets the player to the center of the chair
            Vec3d centerOfChair = chairPosition.ToVec3d().Add(0.5, 0.5, 0.5);

            byPlayer.Entity.Pos.SetPos(centerOfChair);

            // Set player's status to sitting
            playerData.TogglePlayerSitting();
            playerData.SatChairPos = chairPosition;

            // If there is a table next to chair, set player to face chair
            BlockPos adjacentTable = GetAdjacentTable(world, chairPosition);

            // Send packet to server to sync all clients
            IClientNetworkChannel networkChannel = (IClientNetworkChannel)api.Network.GetChannel("networksit");

            networkChannel.SendPacket(new NetworkAnimationSit()
            {
                isSitting = true, playerUID = byPlayer.PlayerUID
            });

            // Modify eye height
            byPlayer.Entity.Properties.SetEyeHeight(SITTINGEYEHEIGHT);

            // Set player's sitting direction
            if (adjacentTable != null)
            {
                if (byPlayer.Entity.Pos.AsBlockPos.East().Equals(adjacentTable))
                {
                    playerData.SetSittingDirection(Cardinal.East);
                    ((ICoreClientAPI)api).Input.MouseYaw = 0;
                }

                if (byPlayer.Entity.Pos.AsBlockPos.West().Equals(adjacentTable))
                {
                    playerData.SetSittingDirection(Cardinal.West);
                    ((ICoreClientAPI)api).Input.MouseYaw = 0.5f * GameMath.TWOPI;
                }

                if (byPlayer.Entity.Pos.AsBlockPos.South().Equals(adjacentTable))
                {
                    playerData.SetSittingDirection(Cardinal.South);
                    ((ICoreClientAPI)api).Input.MouseYaw = 0.75f * GameMath.TWOPI;
                }

                if (byPlayer.Entity.Pos.AsBlockPos.North().Equals(adjacentTable))
                {
                    playerData.SetSittingDirection(Cardinal.North);
                    ((ICoreClientAPI)api).Input.MouseYaw = 0.25f * GameMath.TWOPI;
                }
            }
        }
Пример #17
0
        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));
            }
        }
Пример #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));
            }
        }
Пример #19
0
        public override void OnBlockBroken(IWorldAccessor world, BlockPos pos, IPlayer byPlayer, ref EnumHandling handling)
        {
            string curcover = block.Variant["cover"];

            if (curcover == "snow")
            {
                Block snowblock = world.GetBlock(new AssetLocation("snowblock"));
                if (snowblock != null)
                {
                    world.SpawnCubeParticles(pos.ToVec3d().Add(0.5, 0.5, 0.5), new ItemStack(snowblock), 1, 20, 1, byPlayer);
                }
            }
        }
Пример #20
0
        public void MarkWPForBlockInPos(Block block, BlockPos pos)
        {
            if (FloatyWaypointManagement.WaypointElements.Any(a => a.waypointPos.AsBlockPos.Equals(pos)))
            {
                return;
            }

            var           midPos = pos.ToVec3d().Add(0.5, 0.5, 0.5);
            AssetLocation loc    = GetClassifiedAssetLocation(block.Code, "block");

            var wp = WaypointClassifications[loc];

            MarkWP(wp, midPos);
        }
Пример #21
0
        public void discardCookingSlots()
        {
            Vec3d droppos = pos.ToVec3d().Add(0.5, 0.5, 0.5);

            for (int i = 0; i < cookingSlots.Length; i++)
            {
                if (cookingSlots[i] == null)
                {
                    continue;
                }
                Api.World.SpawnItemEntity(cookingSlots[i].Itemstack, droppos);
                cookingSlots[i].Itemstack = null;
            }
        }
Пример #22
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));
                    }
                }
            }
        }
        private void DropItems(BlockPos pos)
        {
            var dpos = pos.ToVec3d().Add(0.5, 0.5, 0.5);

            if (drops != null)
            {
                for (int i = 0; i < drops.Length; i++)
                {
                    World.SpawnItemEntity(drops[i], dpos);
                }
            }

            if (removedBlockentity is IBlockEntityContainer bec)
            {
                bec.DropContents(dpos);
            }
        }
        private bool TryFalling(IWorldAccessor world, BlockPos pos, ref EnumHandling handling, ref string failureCode)
        {
            if (world.Side != EnumAppSide.Server)
            {
                return(false);
            }
            if (!fallSideways && IsAttached(world.BlockAccessor, pos))
            {
                return(false);
            }

            ICoreServerAPI sapi = (world as IServerWorldAccessor).Api as ICoreServerAPI;

            if (!sapi.Server.Config.AllowFallingBlocks)
            {
                return(false);
            }


            if (IsReplacableBeneath(world, pos) || (fallSideways && world.Rand.NextDouble() < fallSidewaysChance && IsReplacableBeneathAndSideways(world, pos)))
            {
                // Prevents duplication
                Entity entity = world.GetNearestEntity(pos.ToVec3d().Add(0.5, 0.5, 0.5), 1, 1.5f, (e) =>
                {
                    return(e is EntityBlockFalling && ((EntityBlockFalling)e).initialPos.Equals(pos));
                });

                if (entity == null)
                {
                    EntityBlockFalling entityblock = new EntityBlockFalling(block, world.BlockAccessor.GetBlockEntity(pos), pos, fallSound, impactDamageMul, true, dustIntensity);
                    world.SpawnEntity(entityblock);
                }
                else
                {
                    handling    = EnumHandling.PreventDefault;
                    failureCode = "entityintersecting";
                    return(false);
                }

                handling = EnumHandling.PreventSubsequent;
                return(true);
            }

            handling = EnumHandling.PassThrough;
            return(false);
        }
Пример #25
0
        private bool TryPartialCollapse(BlockPos pos, int quantity)
        {
            if (inventory[0].Empty)
            {
                return(false);
            }

            IWorldAccessor world = Api.World;

            if (world.Side == EnumAppSide.Server)
            {
                ICoreServerAPI sapi = (world as IServerWorldAccessor).Api as ICoreServerAPI;
                if (!sapi.Server.Config.AllowFallingBlocks)
                {
                    return(false);
                }
            }

            if (IsReplacableBeneath(world, pos) || IsReplacableBeneathAndSideways(world, pos))
            {
                // Prevents duplication
                Entity entity = world.GetNearestEntity(pos.ToVec3d().Add(0.5, 0.5, 0.5), 1, 1.5f, (e) =>
                {
                    return(e is EntityBlockFalling && ((EntityBlockFalling)e).initialPos.Equals(pos));
                });

                if (entity == null)
                {
                    int prevstacksize = inventory[0].StackSize;

                    inventory[0].Itemstack.StackSize = quantity;
                    EntityBlockFalling entityblock = new EntityBlockFalling(Block, this, pos, null, 1, true, 0.05f);
                    entityblock.DoRemoveBlock = false; // We want to split the pile, not remove it
                    world.SpawnEntity(entityblock);
                    entityblock.ServerPos.Y -= 0.25f;
                    entityblock.Pos.Y       -= 0.25f;

                    inventory[0].Itemstack.StackSize = prevstacksize - quantity;
                    return(true);
                }
            }


            return(false);
        }
        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);
        }
        private bool OnClickItem(BlockPos targetPos)
        {
            var data = TPNetManager.GetTeleport(targetPos);

            if (data == null)
            {
                TryClose();
                return(false);
            }

            TPNetManager.TeleportTo(targetPos.ToVec3d(), blockEntityPos?.ToVec3d());

            double curr = capi.World.Player?.Entity?.WatchedAttributes.GetDouble("temporalStability") ?? 1;

            capi.World.Player?.Entity?.WatchedAttributes.SetDouble("temporalStability", Math.Max(0, (double)curr - 0.1));

            TryClose();

            return(true);
        }
Пример #28
0
        public static void Postfix(BlockBehaviorUnstableFalling __instance, IWorldAccessor world, BlockPos pos, ref EnumHandling handling, ref string failureCode)
        {
            if (world.Side == EnumAppSide.Client)
            {
                return;
            }

            Block block = __instance.block;

            BlockPhysics physics = new BlockPhysics(world.Api);

            if (physics.CanCollapse(pos, block))
            {
                AssetLocation fallSound       = __instance.GetField <AssetLocation>("fallSound");
                float         impactDamageMul = __instance.GetField <float>("impactDamageMul");
                float         dustIntensity   = __instance.GetField <float>("dustIntensity");

                // Prevents duplication
                Entity entity = world.GetNearestEntity(pos.ToVec3d().Add(0.5, 0.5, 0.5), 1, 1.5f, (e) =>
                {
                    return(e is EntityBlockFalling && ((EntityBlockFalling)e).initialPos.Equals(pos));
                });

                if (entity == null)
                {
                    EntityBlockFalling entityblock = new EntityBlockFalling(block, world.BlockAccessor.GetBlockEntity(pos), pos, fallSound, impactDamageMul, true, dustIntensity);
                    world.SpawnEntity(entityblock);
                }
                else
                {
                    handling    = EnumHandling.PreventDefault;
                    failureCode = "entityintersecting";
                    return;
                }

                handling = EnumHandling.PreventSubsequent;
                return;
            }

            handling = EnumHandling.PassThrough;
        }
Пример #29
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)
                {
                    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 = api.World.BlockAccessor.GetBlock(bPos);
                                if (bBlock is BlockPalmTree)
                                {
                                    if (itemslot.Itemstack == null)
                                    {
                                        return;
                                    }

                                    world.BlockAccessor.SetBlock(0, bPos);

                                    foreach (ItemStack item in GetDrops(world, bPos, byPlayer))
                                    {
                                        world.SpawnItemEntity(item, bPos.ToVec3d());
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #30
0
        private bool TryFalling(IWorldAccessor world, BlockPos pos)
        {
            if (IsReplacableBeneath(world, pos))
            {
                // Prevents duplication
                IEntity entity = world.GetNearestEntity(pos.ToVec3d().Add(0.5, 0.5, 0.5), 1, 3, (e) =>
                {
                    return(e is EntityBlockFalling && ((EntityBlockFalling)e).initialPos.Equals(pos));
                }
                                                        );

                if (entity == null)
                {
                    EntityBlockFalling entityblock = new EntityBlockFalling(block, world.BlockAccessor.GetBlockEntity(pos), pos);
                    world.SpawnEntity(entityblock);
                }

                return(true);
            }

            return(false);
        }