public override void FromBytes(BinaryReader reader, bool forClient)
        {
            base.FromBytes(reader, forClient);

            initialPos   = new BlockPos();
            initialPos.X = reader.ReadInt32();
            initialPos.Y = reader.ReadInt32();
            initialPos.Z = reader.ReadInt32();
            blockCode    = new AssetLocation(reader.ReadString());

            bool beIsNull = reader.ReadBoolean();

            if (!beIsNull)
            {
                blockEntityAttributes = new TreeAttribute();
                blockEntityAttributes.FromBytes(reader);
                blockEntityClass = reader.ReadString();
            }

            if (WatchedAttributes.HasAttribute("fallSound"))
            {
                fallSound = new AssetLocation(WatchedAttributes.GetString("fallSound"));
            }

            canFallSideways = WatchedAttributes.GetBool("canFallSideways");
            dustIntensity   = WatchedAttributes.GetFloat("dustIntensity");

            DoRemoveBlock = reader.ReadBoolean();
        }
        public override void Initialize(EntityProperties properties, ICoreAPI api, long InChunkIndex3d)
        {
            if (removedBlockentity != null)
            {
                this.blockEntityAttributes = new TreeAttribute();
                removedBlockentity.ToTreeAttributes(blockEntityAttributes);
                blockEntityClass = api.World.ClassRegistry.GetBlockEntityClass(removedBlockentity.GetType());
            }

            SimulationRange = (int)(0.75f * GlobalConstants.DefaultTrackingRange);
            base.Initialize(properties, api, InChunkIndex3d);

            // Need to capture this now before we remove the block and start to fall
            drops = Block.GetDrops(api.World, initialPos, null);

            lightHsv = Block.GetLightHsv(World.BlockAccessor, initialPos);

            SidedPos.Motion.Y = -0.02;
            blockAsStack      = new ItemStack(Block);


            if (api.Side == EnumAppSide.Client && fallSound != null && fallingNow.Count < 100)
            {
                fallingNow.Add(EntityId);
                ICoreClientAPI capi = api as ICoreClientAPI;
                sound = capi.World.LoadSound(new SoundParams()
                {
                    Location  = fallSound.WithPathPrefixOnce("sounds/").WithPathAppendixOnce(".ogg"),
                    Position  = new Vec3f((float)Pos.X, (float)Pos.Y, (float)Pos.Z),
                    Range     = 32,
                    Pitch     = 0.8f + (float)capi.World.Rand.NextDouble() * 0.3f,
                    Volume    = 1,
                    SoundType = EnumSoundType.Ambient
                });
                sound.Start();
                soundStartDelay = 0.05f + (float)capi.World.Rand.NextDouble() / 3f;
            }

            canFallSideways = WatchedAttributes.GetBool("canFallSideways");
            dustIntensity   = WatchedAttributes.GetFloat("dustIntensity");


            if (WatchedAttributes.HasAttribute("fallSound"))
            {
                fallSound = new AssetLocation(WatchedAttributes.GetString("fallSound"));
            }

            if (api.World.Side == EnumAppSide.Client)
            {
                particleSys = api.ModLoader.GetModSystem <FallingBlockParticlesModSystem>();
                particleSys.Register(this);
                physicsBh = GetBehavior <EntityBehaviorPassivePhysics>();
            }
        }
        public override void Initialize(EntityProperties properties, ICoreAPI api, long InChunkIndex3d)
        {
            base.Initialize(properties, api, InChunkIndex3d);

            if (api.Side == EnumAppSide.Server)
            {
                GetBehavior <EntityBehaviorTaskAI>().taskManager.OnTaskStarted += EntityGlowingAgent_OnTaskStarted;
            }
            else
            {
                WatchedAttributes.RegisterModifiedListener("aggroTime", () => { aggroTime = WatchedAttributes.GetFloat("aggroTime"); });
            }

            aggroTime = WatchedAttributes.GetFloat("aggroTime");
        }
Ejemplo n.º 4
0
        public override void Initialize(EntityProperties properties, ICoreAPI api, long InChunkIndex3d)
        {
            base.Initialize(properties, api, InChunkIndex3d);

            if (api.Side == EnumAppSide.Server)
            {
                GetBehavior <EntityBehaviorTaskAI>().TaskManager.OnTaskStarted += EntityGlowingAgent_OnTaskStarted;
            }
            else
            {
                WatchedAttributes.RegisterModifiedListener("aggroTime", () => { aggroTime = WatchedAttributes.GetFloat("aggroTime"); });
            }

            aggroTime       = WatchedAttributes.GetFloat("aggroTime");
            lightHsv        = properties.Attributes["lightHsv"].AsObject <byte[]>(new byte[] { 10, 5, 10 });
            onlyWhenAggroed = properties.Attributes["onlyWhenAggroed"].AsBool(true);
        }