public override void Initialize(ICoreAPI api)
        {
            base.Initialize(api);

            if (FullyRepaired)
            {
                setupGameTickers();
            }

            ownBlock = Block as BlockStaticTranslocator;
            posvec   = new Vec3d(Pos.X + 0.5, Pos.Y, Pos.Z + 0.5);

            if (api.World.Side == EnumAppSide.Client)
            {
                float rotY = Block.Shape.rotateY;
                animUtil.InitializeAnimator("translocator", new Vec3f(0, rotY, 0));

                translocatingSound = (api as ICoreClientAPI).World.LoadSound(new SoundParams()
                {
                    Location         = new AssetLocation("sounds/effect/translocate-active.ogg"),
                    ShouldLoop       = true,
                    Position         = Pos.ToVec3f(),
                    RelativePosition = false,
                    DisposeOnFinish  = false,
                    Volume           = 0.5f
                });
            }
        }
예제 #2
0
        private BlockPos HasExitPoint(BlockPos nearpos)
        {
            IServerChunk chunk = api.World.BlockAccessor.GetChunkAtBlockPos(nearpos) as IServerChunk;
            List <GeneratedStructure> structures = chunk?.MapChunk?.MapRegion?.GeneratedStructures;

            if (structures == null)
            {
                return(null);
            }

            foreach (var structure in structures)
            {
                if (structure.Code.Contains("gates"))
                {
                    Cuboidi  loc      = structure.Location;
                    BlockPos foundPos = null;
                    api.World.BlockAccessor.WalkBlocks(loc.Start.AsBlockPos, loc.End.AsBlockPos, (block, pos) =>
                    {
                        BlockStaticTranslocator transBlock = block as BlockStaticTranslocator;

                        if (transBlock != null && !transBlock.Repaired)
                        {
                            foundPos = pos.Copy();
                        }
                    });

                    if (foundPos != null)
                    {
                        return(foundPos);
                    }
                }
            }

            return(null);
        }
        private void exitChunkLoaded(BlockPos exitPos)
        {
            BlockStaticTranslocator exitBlock = Api.World.BlockAccessor.GetBlock(exitPos) as BlockStaticTranslocator;

            if (exitBlock == null)
            {
                // Cheap hax: Pre v1.10 chunks do not have translocators at the same location and maybe future versions will also have a changed location
                // So let's still try to find something useful in the chunk we generated, with any luck we come across an old one.
                exitPos = HasExitPoint(exitPos);
                if (exitPos != null)
                {
                    exitBlock = Api.World.BlockAccessor.GetBlock(exitPos) as BlockStaticTranslocator;
                }
            }

            if (exitBlock != null && !exitBlock.Repaired)
            {
                // Repair it
                Api.World.BlockAccessor.SetBlock(ownBlock.Id, exitPos);
                BlockEntityStaticTranslocator beExit = Api.World.BlockAccessor.GetBlockEntity(exitPos) as BlockEntityStaticTranslocator;

                // Connect remote
                beExit.tpLocation    = Pos.Copy();
                beExit.canTeleport   = true;
                beExit.findNextChunk = false;
                beExit.activated     = true;
                if (!beExit.FullyRepaired)
                {
                    beExit.repairState = 4;
                    beExit.setupGameTickers();
                }
                Api.World.BlockAccessor.MarkBlockEntityDirty(exitPos);
                Api.World.BlockAccessor.MarkBlockDirty(exitPos);

                Api.World.Logger.Debug("Connected translocator at {0} (chunkpos: {2}) to my location: {1}", exitPos, Pos, exitPos / 32);

                // Connect self
                MarkDirty(true);
                tpLocation  = exitPos;
                canTeleport = true;
            }
            else
            {
                Api.World.Logger.Warning("Translocator: Regen chunk but broken translocator is gone. Structure generation perhaps seed not consistent? May also just be pre-v1.10 chunk, so probably nothing to worry about. Searching again...");
                findNextChunk = true;
            }
        }
        public override void Initialize(ICoreAPI api)
        {
            base.Initialize(api);
            manager = api.ModLoader.GetModSystem <TeleporterManager>();

            if (FullyRepaired)
            {
                setupGameTickers();
            }

            ownBlock = Block as BlockStaticTranslocator;
            posvec   = new Vec3d(Pos.X + 0.5, Pos.Y, Pos.Z + 0.5);

            if (api.World.Side == EnumAppSide.Client)
            {
                float rotY = Block.Shape.rotateY;
                animUtil.InitializeAnimator("translocator", new Vec3f(0, rotY, 0));

                temporalGearStack = new ItemStack(api.World.GetItem(new AssetLocation("gear-temporal")));
            }
        }
        private BlockPos FindTranslocator(Cuboidi location, Dictionary <Vec2i, IServerChunk[]> columnsByChunkCoordinate, int centerCx, int centerCz)
        {
            int chunksize = Api.World.BlockAccessor.ChunkSize;

            for (int x = location.X1; x < location.X2; x++)
            {
                for (int y = location.Y1; y < location.Y2; y++)
                {
                    for (int z = location.Z1; z < location.Z2; z++)
                    {
                        int cx = x / chunksize;
                        int cy = y / chunksize;
                        int cz = z / chunksize;

                        IServerChunk[] chunks = null;
                        if (!columnsByChunkCoordinate.TryGetValue(new Vec2i(cx, cz), out chunks))
                        {
                            continue;
                        }

                        IServerChunk chunk = chunks[y / chunksize];

                        int lx = x % chunksize;
                        int ly = y % chunksize;
                        int lz = z % chunksize;

                        int   index3d = (ly * chunksize + lz) * chunksize + lx;
                        Block block   = Api.World.Blocks[chunk.Blocks[index3d]];

                        BlockStaticTranslocator transBlock = block as BlockStaticTranslocator;
                        if (transBlock != null && !transBlock.Repaired)
                        {
                            return(new BlockPos(x, y, z));
                        }
                    }
                }
            }

            return(null);
        }