private void onSetTlPos(IServerPlayer player, int groupId, CmdArgs args)
        {
            BlockPos pos = player.CurrentBlockSelection.Position;
            BlockEntityStaticTranslocator bet = sapi.World.BlockAccessor.GetBlockEntity(pos) as BlockEntityStaticTranslocator;

            if (bet == null)
            {
                player.SendMessage(groupId, "Not looking at a translocator. Must look at one to set its target", EnumChatType.CommandError);
                return;
            }

            Vec3d spawnpos = sapi.World.DefaultSpawnPosition.XYZ;

            spawnpos.Y = 0;
            Vec3d targetpos = args.PopFlexiblePos(player.Entity.Pos.XYZ, spawnpos);

            if (targetpos == null)
            {
                player.SendMessage(groupId, "Invalid position supplied. Syntax: [coord] [coord] [coord] or =[abscoord] =[abscoord] =[abscoord]", EnumChatType.CommandError);
                return;
            }

            bet.tpLocation = targetpos.AsBlockPos;
            bet.MarkDirty(true);
            player.SendMessage(groupId, "Target position set.", EnumChatType.CommandError);
        }
Ejemplo n.º 2
0
        public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel)
        {
            ItemSlot slot = byPlayer.InventoryManager.ActiveHotbarSlot;

            if (slot.Empty)
            {
                return(base.OnBlockInteractStart(world, byPlayer, blockSel));
            }

            if (!Repaired)
            {
                if (slot.Itemstack.Collectible.Code.Path == "metal-parts" && slot.StackSize >= 2)
                {
                    slot.TakeOut(2);
                    world.PlaySoundAt(new AssetLocation("sounds/effect/latch"), blockSel.Position.X + 0.5, blockSel.Position.Y, blockSel.Position.Z + 0.5, byPlayer, true, 16);

                    Block block = world.GetBlock(CodeWithVariant("state", "normal"));
                    world.BlockAccessor.SetBlock(block.Id, blockSel.Position);

                    BlockEntityStaticTranslocator be = world.BlockAccessor.GetBlockEntity(blockSel.Position) as BlockEntityStaticTranslocator;
                    if (be != null)
                    {
                        be.DoRepair();
                    }

                    return(true);
                }
            }
            else
            {
                BlockEntityStaticTranslocator be = world.BlockAccessor.GetBlockEntity(blockSel.Position) as BlockEntityStaticTranslocator;
                if (be == null)
                {
                    return(false);
                }

                if (!be.FullyRepaired && slot.Itemstack.Collectible is ItemTemporalGear)
                {
                    be.DoRepair();
                    slot.TakeOut(1);
                    world.PlaySoundAt(new AssetLocation("sounds/effect/latch"), blockSel.Position.X + 0.5, blockSel.Position.Y, blockSel.Position.Z + 0.5, byPlayer, true, 16);

                    return(true);
                }

                if (!be.Activated && slot.Itemstack.Collectible.Code.Path == "gear-rusty")
                {
                    be.DoActivate();
                    slot.TakeOut(1);
                    world.PlaySoundAt(new AssetLocation("sounds/effect/latch"), blockSel.Position.X + 0.5, blockSel.Position.Y, blockSel.Position.Z + 0.5, byPlayer, true, 16);
                    return(true);
                }
            }

            return(base.OnBlockInteractStart(world, byPlayer, blockSel));
        }
Ejemplo n.º 3
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);

            BlockEntityStaticTranslocator be = world.BlockAccessor.GetBlockEntity(pos) as BlockEntityStaticTranslocator;

            if (be == null)
            {
                return;
            }
            be.OnEntityCollide(entity);
        }
Ejemplo n.º 4
0
        public override WorldInteraction[] GetPlacedBlockInteractionHelp(IWorldAccessor world, BlockSelection selection, IPlayer forPlayer)
        {
            if (!Repaired)
            {
                return(new WorldInteraction[] {
                    new WorldInteraction()
                    {
                        ActionLangCode = "blockhelp-translocator-repair-1",
                        Itemstacks = new ItemStack[] { new ItemStack(world.GetBlock(new AssetLocation("metal-parts")), 2) },
                        MouseButton = EnumMouseButton.Right
                    }
                });
            }
            else
            {
                BlockEntityStaticTranslocator be = world.BlockAccessor.GetBlockEntity(selection.Position) as BlockEntityStaticTranslocator;
                if (be == null)
                {
                    return(base.GetPlacedBlockInteractionHelp(world, selection, forPlayer));
                }

                if (!be.FullyRepaired)
                {
                    return(new WorldInteraction[]
                    {
                        new WorldInteraction()
                        {
                            ActionLangCode = "blockhelp-translocator-repair-2",
                            Itemstacks = new ItemStack[] { new ItemStack(world.GetItem(new AssetLocation("gear-temporal"))) },
                            MouseButton = EnumMouseButton.Right
                        }
                    });
                }

                if (!be.Activated)
                {
                    return(new WorldInteraction[]
                    {
                        new WorldInteraction()
                        {
                            ActionLangCode = "blockhelp-translocator-activate",
                            Itemstacks = new ItemStack[] { new ItemStack(world.GetItem(new AssetLocation("gear-rusty"))) },
                            MouseButton = EnumMouseButton.Right
                        }
                    });
                }
            }

            return(base.GetPlacedBlockInteractionHelp(world, selection, forPlayer));
        }
        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;
            }
        }
Ejemplo n.º 6
0
        public override string GetPlacedBlockName(IWorldAccessor world, BlockPos pos)
        {
            if (Repaired)
            {
                BlockEntityStaticTranslocator be = world.BlockAccessor.GetBlockEntity(pos) as BlockEntityStaticTranslocator;
                if (be == null)
                {
                    return(base.GetPlacedBlockName(world, pos));
                }

                if (!be.FullyRepaired)
                {
                    return(Lang.GetMatching("block-statictranslocator-broken-*"));
                }
            }

            return(base.GetPlacedBlockName(world, pos));
        }
Ejemplo n.º 7
0
        public override string GetPlacedBlockName(IWorldAccessor world, BlockPos pos)
        {
            if (Repaired)
            {
                BlockEntityStaticTranslocator be = world.BlockAccessor.GetBlockEntity(pos) as BlockEntityStaticTranslocator;
                if (be == null)
                {
                    return(base.GetPlacedBlockName(world, pos));
                }

                if (!be.FullyRepaired)
                {
                    return(world.GetBlock(CodeWithVariant("state", "broken")).GetPlacedBlockName(world, pos));
                }
            }

            return(base.GetPlacedBlockName(world, pos));
        }