Exemple #1
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);
        }
Exemple #2
0
        private bool TryFalling(IWorldAccessor world, BlockPos pos, ref EnumHandling handling, ref string failureCode)
        {
            if (world.Side != EnumAppSide.Server)
            {
                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);
        }
        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;
        }
Exemple #4
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);
        }