コード例 #1
0
        public override void OnEntityCollide(IWorldAccessor world, Entity entity, BlockPos pos, BlockFacing facing, Vec3d collideSpeed, bool isImpact)
        {
            base.OnEntityCollide(world, entity, pos, facing, collideSpeed, isImpact);

            if (world.Side == EnumAppSide.Server)
            {
                BlockEntityCoalPile be = world.BlockAccessor.GetBlockEntity(pos) as BlockEntityCoalPile;
                if (be.IsBurning)
                {
                    long lastBurnMs = entity.Attributes.GetLong("lastCoalBurnTick");

                    if (world.ElapsedMilliseconds - lastBurnMs > 1000)
                    {
                        entity.ReceiveDamage(new DamageSource()
                        {
                            DamageTier = 0, Source = EnumDamageSource.Block, SourceBlock = this, SourcePos = pos.ToVec3d(), Type = EnumDamageType.Fire
                        }, 1f);
                        entity.Attributes.SetLong("lastCoalBurnTick", world.ElapsedMilliseconds);

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

                    if (lastBurnMs > world.ElapsedMilliseconds)
                    {
                        entity.Attributes.SetLong("lastCoalBurnTick", world.ElapsedMilliseconds);
                    }
                }
            }
        }
コード例 #2
0
        public int GetLayercount(IWorldAccessor world, BlockPos pos)
        {
            BlockEntityCoalPile bea = world.BlockAccessor.GetBlockEntity(pos) as BlockEntityCoalPile;

            if (bea != null)
            {
                return(bea.Layers);
            }
            return(0);
        }
コード例 #3
0
        public override ItemStack OnPickBlock(IWorldAccessor world, BlockPos pos)
        {
            BlockEntityCoalPile bea = world.BlockAccessor.GetBlockEntity(pos) as BlockEntityCoalPile;

            if (bea != null)
            {
                return(bea.inventory[0]?.Itemstack?.Clone());
            }

            return(base.OnPickBlock(world, pos));
        }
コード例 #4
0
        public override bool CanAttachBlockAt(IBlockAccessor blockAccessor, Block block, BlockPos pos, BlockFacing blockFace, Cuboidi attachmentArea = null)
        {
            BlockEntityCoalPile be = blockAccessor.GetBlockEntity(pos) as BlockEntityCoalPile;

            if (be != null)
            {
                return(be.OwnStackSize == be.MaxStackSize);
            }

            return(base.CanAttachBlockAt(blockAccessor, block, pos, blockFace, attachmentArea));
        }
コード例 #5
0
        public override Cuboidf[] GetSelectionBoxes(IBlockAccessor blockAccessor, BlockPos pos)
        {
            BlockEntityCoalPile bea = blockAccessor.GetBlockEntity(pos) as BlockEntityCoalPile;

            if (bea == null)
            {
                return(new Cuboidf[0]);
            }

            return(CollisionBoxesByFillLevel[bea.Layers]);
        }
コード例 #6
0
        public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel)
        {
            BlockEntity be = world.BlockAccessor.GetBlockEntity(blockSel.Position);

            if (be is BlockEntityCoalPile)
            {
                BlockEntityCoalPile pile = (BlockEntityCoalPile)be;
                return(pile.OnPlayerInteract(byPlayer));
            }

            return(false);
        }
コード例 #7
0
        public override bool OnFallOnto(IWorldAccessor world, BlockPos pos, Block block, TreeAttribute blockEntityAttributes)
        {
            if (block is BlockCoalPile)
            {
                BlockEntityCoalPile be = world.BlockAccessor.GetBlockEntity(pos) as BlockEntityCoalPile;
                if (be != null)
                {
                    return(be.MergeWith(blockEntityAttributes));
                }
            }

            return(base.OnFallOnto(world, pos, block, blockEntityAttributes));
        }
コード例 #8
0
        public override void GetDecal(IWorldAccessor world, BlockPos pos, ITexPositionSource decalTexSource, ref MeshData decalModelData, ref MeshData blockModelData)
        {
            BlockEntityCoalPile bea = world.BlockAccessor.GetBlockEntity(pos) as BlockEntityCoalPile;

            if (bea == null)
            {
                base.GetDecal(world, pos, decalTexSource, ref decalModelData, ref blockModelData);
                return;
            }

            decalModelData.Clear();
            bea.GetDecalMesh(decalTexSource, out decalModelData);
        }
コード例 #9
0
        public override byte[] GetLightHsv(IBlockAccessor blockAccessor, BlockPos pos, ItemStack stack = null)
        {
            if (pos == null)
            {
                return(base.GetLightHsv(blockAccessor, pos, stack));
            }

            BlockEntityCoalPile bea = blockAccessor.GetBlockEntity(pos) as BlockEntityCoalPile;

            if (bea?.IsBurning == true)
            {
                return new byte[] { 0, 7, 8 }
            }
            ;

            return(base.GetLightHsv(blockAccessor, pos, stack));
        }
コード例 #10
0
        public bool Construct(ItemSlot slot, IWorldAccessor world, BlockPos pos, IPlayer player)
        {
            Block block = world.BlockAccessor.GetBlock(pos);

            if (!block.IsReplacableBy(this))
            {
                return(false);
            }
            Block belowBlock = world.BlockAccessor.GetBlock(pos.DownCopy());

            if (!belowBlock.CanAttachBlockAt(world.BlockAccessor, this, pos.DownCopy(), BlockFacing.UP) /*&& (belowBlock != this || FillLevel(world.BlockAccessor, pos.DownCopy()) != 4)*/)
            {
                return(false);
            }

            world.BlockAccessor.SetBlock(BlockId, pos);

            BlockEntity be = world.BlockAccessor.GetBlockEntity(pos);

            if (be is BlockEntityCoalPile)
            {
                BlockEntityCoalPile pile = (BlockEntityCoalPile)be;
                if (player == null || player.WorldData.CurrentGameMode != EnumGameMode.Creative)
                {
                    pile.inventory[0].Itemstack = (ItemStack)slot.TakeOut(player?.Entity.Controls.Sprint == true ? pile.BulkTakeQuantity : pile.DefaultTakeQuantity);
                    slot.MarkDirty();
                }
                else
                {
                    pile.inventory[0].Itemstack           = (ItemStack)slot.Itemstack.Clone();
                    pile.inventory[0].Itemstack.StackSize = Math.Min(pile.inventory[0].Itemstack.StackSize, pile.MaxStackSize);
                }

                pile.MarkDirty();
                world.BlockAccessor.MarkBlockDirty(pos);
                world.PlaySoundAt(pile.SoundLocation, pos.X, pos.Y, pos.Z, player, true);
            }

            return(true);
        }
コード例 #11
0
        public override EnumIgniteState OnTryIgniteBlock(EntityAgent byEntity, BlockPos pos, float secondsIgniting)
        {
            BlockEntityCoalPile bea = byEntity.World.BlockAccessor.GetBlockEntity(pos) as BlockEntityCoalPile;

            if (bea == null || !bea.CanIgnite)
            {
                return(EnumIgniteState.NotIgnitablePreventDefault);
            }

            if (secondsIgniting > 0.25f && (int)(30 * secondsIgniting) % 9 == 1)
            {
                Random rand = byEntity.World.Rand;
                Vec3d  dpos = new Vec3d(pos.X + 2 / 8f + 4 / 8f * rand.NextDouble(), pos.Y + 7 / 8f, pos.Z + 2 / 8f + 4 / 8f * rand.NextDouble());

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

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

                IPlayer byPlayer = null;
                if (byEntity is EntityPlayer)
                {
                    byPlayer = byEntity.World.PlayerByUid(((EntityPlayer)byEntity).PlayerUID);
                }

                byEntity.World.SpawnParticles(props, byPlayer);

                props.Quantity.avg = 0;
            }

            if (secondsIgniting >= 1.5f)
            {
                return(EnumIgniteState.IgniteNow);
            }

            return(EnumIgniteState.Ignitable);
        }
コード例 #12
0
        public override void OnTryIgniteBlockOver(EntityAgent byEntity, BlockPos pos, float secondsIgniting, ref EnumHandling handling)
        {
            if (secondsIgniting < 1.45f)
            {
                return;
            }

            handling = EnumHandling.PreventDefault;

            IPlayer byPlayer = null;

            if (byEntity is EntityPlayer)
            {
                byPlayer = byEntity.World.PlayerByUid(((EntityPlayer)byEntity).PlayerUID);
            }
            if (byPlayer == null)
            {
                return;
            }

            BlockEntityCoalPile bea = byEntity.World.BlockAccessor.GetBlockEntity(pos) as BlockEntityCoalPile;

            bea?.TryIgnite();
        }
コード例 #13
0
        private void onServerTick3s(float dt)
        {
            BlockPos coalPilePos      = Pos.DownCopy(2);
            BlockPos othercoalPilePos = coalPilePos.AddCopy(blockScs.Orientation.Opposite);

            bool beforeReceiveHeat       = receivesHeat;
            bool beforeStructureComplete = structureComplete;

            if (!receivesHeat)
            {
                totalHoursLastUpdate = Api.World.Calendar.TotalHours;
            }

            BlockEntityCoalPile becp = Api.World.BlockAccessor.GetBlockEntity(coalPilePos) as BlockEntityCoalPile;
            float leftHeatHoursLeft  = (becp != null && becp.IsBurning) ? becp.GetHoursLeft(totalHoursLastUpdate) : 0f;

            becp = Api.World.BlockAccessor.GetBlockEntity(othercoalPilePos) as BlockEntityCoalPile;
            float rightHeatHoursLeft = (becp != null && becp.IsBurning) ? becp.GetHoursLeft(totalHoursLastUpdate) : 0f;

            receivesHeat = leftHeatHoursLeft > 0 && rightHeatHoursLeft > 0;


            if (processComplete || !IsFull || !hasLid())
            {
                return;
            }

            MultiblockStructure msInUse  = null;
            BlockPos            posInUse = null;

            structureComplete = false;
            if (ms.InCompleteBlockCount(Api.World, Pos) == 0)
            {
                msInUse           = ms;
                posInUse          = Pos;
                structureComplete = true;
            }
            else if (msOpp.InCompleteBlockCount(Api.World, Pos.AddCopy(blockScs.Orientation.Opposite)) == 0)
            {
                msInUse           = msOpp;
                posInUse          = Pos.AddCopy(blockScs.Orientation.Opposite);
                structureComplete = true;
            }

            if (beforeReceiveHeat != receivesHeat || beforeStructureComplete != structureComplete)
            {
                MarkDirty();
            }

            if (receivesHeat)
            {
                if (!structureComplete)
                {
                    return;
                }

                double hoursPassed       = Api.World.Calendar.TotalHours - totalHoursLastUpdate;
                double heatHoursReceived = Math.Max(0, Math.Min(hoursPassed, Math.Min(leftHeatHoursLeft, rightHeatHoursLeft)));

                progress            += heatHoursReceived / 160f;
                totalHoursLastUpdate = Api.World.Calendar.TotalHours;
                MarkDirty();
            }

            if (progress >= 1.0)
            {
                int stacksize = inv[1].Itemstack.StackSize;

                JsonItemStack jstack = inv[1].Itemstack.ItemAttributes?["carburizableProps"]["carburizedOutput"].AsObject <JsonItemStack>(null, Block.Code.Domain);
                if (jstack.Resolve(Api.World, "carburizable output"))
                {
                    inv[0].Itemstack.StackSize -= 8;
                    inv[1].Itemstack            = jstack.ResolvedItemstack.Clone();
                    inv[1].Itemstack.StackSize  = stacksize;
                }
                MarkDirty();

                msInUse.WalkMatchingBlocks(Api.World, posInUse, (block, pos) =>
                {
                    float resis = block.Attributes?["heatResistance"].AsFloat(1) ?? 1;

                    if (Api.World.Rand.NextDouble() > resis)
                    {
                        Block nowblock = Api.World.GetBlock(block.CodeWithVariant("state", "damaged"));
                        Api.World.BlockAccessor.SetBlock(nowblock.Id, pos);
                    }
                });

                processComplete = true;
            }
        }