示例#1
0
        private void OnClientTick(float dt)
        {
            if (!lit)
            {
                return;
            }

            BlockPos pos = new BlockPos();

            foreach (var val in smokeLocations)
            {
                if (Api.World.Rand.NextDouble() < 0.2f && Block.ParticleProperties.Length > 0)
                {
                    pos.Set(val.Key.X, val.Value + 1, val.Key.Z);

                    Block upblock = Api.World.BlockAccessor.GetBlock(pos);
                    AdvancedParticleProperties particles = Block.ParticleProperties[0];
                    particles.basePos = BlockEntityFire.RandomBlockPos(Api.World.BlockAccessor, pos, upblock, BlockFacing.UP);

                    particles.Quantity.avg = 1;
                    Api.World.SpawnParticles(particles);
                    particles.Quantity.avg = 0;
                }
            }
        }
示例#2
0
        private void OnServerTick(float dt)
        {
            if (!lit)
            {
                return;
            }

            if (startingAfterTotalHours <= Api.World.Calendar.TotalHours && state == 0)
            {
                finishedAfterTotalHours = Api.World.Calendar.TotalHours + BurnHours;
                state = 1;
                MarkDirty(false);
            }

            if (state == 0)
            {
                return;
            }


            BlockPos holePos = FindHoleInPit();

            if (holePos != null)
            {
                finishedAfterTotalHours = Api.World.Calendar.TotalHours + BurnHours;

                BlockPos    tmpPos     = new BlockPos();
                BlockFacing firefacing = BlockFacing.UP;

                Block block = Api.World.BlockAccessor.GetBlock(holePos);
                if (block.BlockId != 0 && block.BlockId != Block.BlockId)
                {
                    foreach (BlockFacing facing in BlockFacing.ALLFACES)
                    {
                        tmpPos.Set(holePos).Add(facing);
                        if (Api.World.BlockAccessor.GetBlock(tmpPos).BlockId == 0)
                        {
                            holePos.Set(tmpPos);
                            firefacing = facing;
                            break;
                        }
                    }
                }

                Block fireblock = Api.World.GetBlock(new AssetLocation("fire"));
                Api.World.BlockAccessor.SetBlock(fireblock.BlockId, holePos);

                BlockEntityFire befire = Api.World.BlockAccessor.GetBlockEntity(holePos) as BlockEntityFire;
                befire?.Init(firefacing, startedByPlayerUid);

                return;
            }

            if (finishedAfterTotalHours <= Api.World.Calendar.TotalHours)
            {
                ConvertPit();
            }
        }
示例#3
0
        public override bool OnHeldInteractStep(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, ref EnumHandling handling)
        {
            if (blockSel == null)
            {
                return(false);
            }

            IPlayer byPlayer = (byEntity as EntityPlayer)?.Player;

            if (!byEntity.World.Claims.TryAccess(byPlayer, blockSel.Position, EnumBlockAccessFlags.BuildOrBreak))
            {
                return(false);
            }


            Block block = byEntity.World.BlockAccessor.GetBlock(blockSel.Position);

            EnumHandling igniteHandled = EnumHandling.PassThrough;
            bool         handledResult = block.OnTryIgniteBlock(byEntity, blockSel.Position, secondsUsed, ref igniteHandled);

            if (igniteHandled == EnumHandling.PassThrough && !byEntity.Controls.Sneak)
            {
                return(false);
            }

            handling = EnumHandling.PreventDefault;

            if (byEntity.World is IClientWorldAccessor)
            {
                ModelTransform tf = new ModelTransform();
                tf.EnsureDefaultValues();

                tf.Translation.Set(0, -Math.Min(1.1f / 3, secondsUsed * 4 / 3f), -Math.Min(1.1f, secondsUsed * 4));
                tf.Rotation.X = -Math.Min(85, secondsUsed * 90 * 4f);
                byEntity.Controls.UsingHeldItemTransformBefore = tf;


                if (igniteHandled == EnumHandling.PassThrough && secondsUsed > 0.25f && (int)(30 * secondsUsed) % 2 == 1)
                {
                    Vec3d pos = BlockEntityFire.RandomBlockPos(byEntity.World.BlockAccessor, blockSel.Position, block, blockSel.Face);

                    Block blockFire = byEntity.World.GetBlock(new AssetLocation("fire"));

                    AdvancedParticleProperties props = blockFire.ParticleProperties[blockFire.ParticleProperties.Length - 1];
                    props.basePos      = pos;
                    props.Quantity.avg = 1;

                    byEntity.World.SpawnParticles(props, byPlayer);

                    props.Quantity.avg = 0;
                }
            }

            return(igniteHandled != EnumHandling.PassThrough ? handledResult : secondsUsed <= 3.1);
        }
示例#4
0
        private void OnTick(float dt)
        {
            if (api.Side == EnumAppSide.Server)
            {
                remainingBurnDuration -= dt;

                if (remainingBurnDuration <= 0)
                {
                    BlockPos fuelPos   = pos.AddCopy(fromFacing.GetOpposite());
                    Block    fuelBlock = api.World.BlockAccessor.GetBlock(fuelPos);

                    if (fuelBlock.CombustibleProps != null && fuelBlock.CombustibleProps.BurnDuration > 0)
                    {
                        api.World.BlockAccessor.SetBlock(fireBlock.BlockId, fuelPos);
                        BlockEntityFire befire = api.World.BlockAccessor.GetBlockEntity(pos.AddCopy(fromFacing.GetOpposite())) as BlockEntityFire;
                        if (befire != null)
                        {
                            befire.Init(fromFacing);
                        }
                    }
                    else
                    {
                    }

                    api.World.BlockAccessor.SetBlock(0, pos);
                    api.World.BlockAccessor.RemoveBlockEntity(pos); // Sometimes block entities don't get removed properly o.O
                    return;
                }

                float spreadChance = (TimePassed - 2.5f) / 500f;

                if (spreadChance > api.World.Rand.NextDouble())
                {
                    TrySpreadFire();
                }
            }

            if (api.Side == EnumAppSide.Client)
            {
                int index = Math.Min(fireBlock.ParticleProperties.Length - 1, api.World.Rand.Next(fireBlock.ParticleProperties.Length + 1));
                AdvancedParticleProperties particles = fireBlock.ParticleProperties[index];
                particles.basePos = RandomBlockPos(api.World.BlockAccessor, pos.AddCopy(fromFacing.GetOpposite()), neibBlock, fromFacing);

                particles.Quantity.avg     = 0.75f;
                particles.TerrainCollision = false;
                api.World.SpawnParticles(particles);
                particles.Quantity.avg = 0;
            }
        }
示例#5
0
        private void TrySpreadFire()
        {
            BlockPos opos = pos.AddCopy(fromFacing.GetOpposite());

            foreach (BlockFacing facing in BlockFacing.ALLFACES)
            {
                BlockPos npos   = opos.AddCopy(facing);
                Block    nBlock = api.World.BlockAccessor.GetBlock(npos);
                if (nBlock.CombustibleProps != null && nBlock.CombustibleProps.BurnDuration > 0)
                {
                    if (api.World.BlockAccessor.GetBlock(npos.AddCopy(fromFacing)).BlockId == 0)
                    {
                        api.World.BlockAccessor.SetBlock(fireBlock.BlockId, npos.AddCopy(fromFacing));

                        BlockEntityFire befire = api.World.BlockAccessor.GetBlockEntity(npos.AddCopy(fromFacing)) as BlockEntityFire;
                        if (befire != null)
                        {
                            befire.Init(fromFacing);
                        }

                        break;
                    }

                    bool dobreak = false;
                    foreach (BlockFacing firefacing in BlockFacing.ALLFACES)
                    {
                        if (api.World.BlockAccessor.GetBlock(npos.AddCopy(firefacing)).BlockId == 0)
                        {
                            api.World.BlockAccessor.SetBlock(fireBlock.BlockId, npos.AddCopy(firefacing));

                            BlockEntityFire befire = api.World.BlockAccessor.GetBlockEntity(npos.AddCopy(firefacing)) as BlockEntityFire;
                            if (befire != null)
                            {
                                befire.Init(firefacing);
                            }

                            dobreak = true;
                            break;
                        }
                    }

                    if (dobreak)
                    {
                        break;
                    }
                }
            }
        }
        public override void OnHeldInteractStop(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, ref EnumHandling handling)
        {
            if (blockSel == null || secondsUsed < 3)
            {
                return;
            }

            IPlayer byPlayer = (byEntity as EntityPlayer)?.Player;

            if (!byEntity.World.Claims.TryAccess(byPlayer, blockSel.Position, EnumBlockAccessFlags.Use))
            {
                return;
            }


            EnumHandling handled = EnumHandling.PassThrough;
            Block        block   = byEntity.World.BlockAccessor.GetBlock(blockSel.Position);

            block.OnTryIgniteBlockOver(byEntity, blockSel.Position, secondsUsed, ref handled);

            if (handled != EnumHandling.PassThrough)
            {
                return;
            }

            handling = EnumHandling.PreventDefault;

            if (!byEntity.World.Claims.TryAccess(byPlayer, blockSel.Position, EnumBlockAccessFlags.BuildOrBreak))
            {
                return;
            }

            if (blockSel != null && byEntity.World.Side == EnumAppSide.Server)
            {
                BlockPos bpos = blockSel.Position.AddCopy(blockSel.Face);
                block = byEntity.World.BlockAccessor.GetBlock(bpos);

                if (block.BlockId == 0)
                {
                    byEntity.World.BlockAccessor.SetBlock(byEntity.World.GetBlock(new AssetLocation("fire")).BlockId, bpos);
                    BlockEntityFire befire = byEntity.World.BlockAccessor.GetBlockEntity(bpos) as BlockEntityFire;
                    if (befire != null)
                    {
                        befire.Init(blockSel.Face, (byEntity as EntityPlayer).PlayerUID);
                    }
                }
            }
        }
示例#7
0
        public override void OnServerGameTick(IWorldAccessor world, BlockPos pos, object extra = null)
        {
            base.OnServerGameTick(world, pos, extra);

            if (blockFire == null)
            {
                blockFire = world.GetBlock(new AssetLocation("fire"));
            }
            FireLocation fireLocation = (FireLocation)extra;

            world.BlockAccessor.SetBlock(blockFire.BlockId, fireLocation.firePos);
            BlockEntityFire befire = world.BlockAccessor.GetBlockEntity(fireLocation.firePos) as BlockEntityFire;

            if (befire != null)
            {
                befire.Init(fireLocation.facing);
            }
        }
示例#8
0
        public bool TrySpreadTo(BlockPos pos, BlockFacing facing)
        {
            IPlayer player = api.World.PlayerByUid(startedByPlayerUid);

            if (player != null && api.World.Claims.TestAccess(player, pos, EnumBlockAccessFlags.BuildOrBreak) != EnumWorldAccessResponse.Granted)
            {
                return(false);
            }

            api.World.BlockAccessor.SetBlock(fireBlock.BlockId, pos);

            BlockEntityFire befire = api.World.BlockAccessor.GetBlockEntity(pos) as BlockEntityFire;

            if (befire != null)
            {
                befire.Init(facing, startedByPlayerUid);
            }

            return(true);
        }
        public override void OnHeldInteractStop(float secondsUsed, IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, ref EnumHandling handling)
        {
            if (blockSel == null)
            {
                return;
            }

            EnumHandling handled = EnumHandling.NotHandled;
            Block        block   = byEntity.World.BlockAccessor.GetBlock(blockSel.Position);

            block.OnTryIgniteBlockOver(byEntity, blockSel.Position, secondsUsed, ref handled);

            if (handled != EnumHandling.NotHandled)
            {
                return;
            }

            handling = EnumHandling.PreventDefault;

            if (secondsUsed >= 3 && blockSel != null)
            {
                BlockPos bpos = blockSel.Position.AddCopy(blockSel.Face);
                block = byEntity.World.BlockAccessor.GetBlock(bpos);

                if (block.BlockId == 0)
                {
                    byEntity.World.BlockAccessor.SetBlock(byEntity.World.GetBlock(new AssetLocation("fire")).BlockId, bpos);

                    BlockEntityFire befire = byEntity.World.BlockAccessor.GetBlockEntity(bpos) as BlockEntityFire;
                    if (befire != null)
                    {
                        befire.Init(blockSel.Face);
                    }
                }
            }
        }