Search in sources :

Example 16 with WorldBridge

use of io.izzel.arclight.common.bridge.world.WorldBridge in project Arclight by IzzelAliz.

the class PlayerListMixin method recreatePlayerEntity.

/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite
public ServerPlayerEntity recreatePlayerEntity(ServerPlayerEntity playerIn, DimensionType dimension, boolean conqueredEnd) {
    Location location = arclight$loc;
    arclight$loc = null;
    boolean avoidSuffocation = arclight$suffo == null ? true : arclight$suffo;
    arclight$suffo = null;
    playerIn.stopRiding();
    org.bukkit.World fromWorld = ((ServerPlayerEntityBridge) playerIn).bridge$getBukkitEntity().getWorld();
    ServerWorld world = server.getWorld(dimension);
    if (world == null)
        dimension = playerIn.getSpawnDimension();
    else if (!world.getDimension().canRespawnHere())
        dimension = world.getDimension().getRespawnDimension(playerIn);
    if (server.getWorld(dimension) == null)
        dimension = DimensionType.OVERWORLD;
    this.removePlayer(playerIn);
    // Forge: keep data until copyFrom called
    playerIn.getServerWorld().removePlayer(playerIn, true);
    BlockPos blockpos = playerIn.getBedLocation(dimension);
    boolean flag = playerIn.isSpawnForced(dimension);
    // playerIn.dimension = dimension;
    PlayerInteractionManager playerinteractionmanager;
    if (this.server.isDemo()) {
        playerinteractionmanager = new DemoPlayerInteractionManager(this.server.getWorld(playerIn.dimension));
    } else {
        playerinteractionmanager = new PlayerInteractionManager(this.server.getWorld(playerIn.dimension));
    }
    playerIn.queuedEndExit = false;
    if (location == null) {
        boolean isBedSpawn = false;
        CraftWorld cworld = (CraftWorld) Bukkit.getWorld(((PlayerEntityBridge) playerIn).bridge$getSpawnWorld());
        if (cworld != null && blockpos != null) {
            Optional<Vec3d> optional = PlayerEntity.checkBedValidRespawnPosition(cworld.getHandle(), blockpos, flag);
            if (optional.isPresent()) {
                Vec3d vec3d = optional.get();
                isBedSpawn = true;
                location = new Location(cworld, vec3d.x, vec3d.y, vec3d.z);
            } else {
                this.bridge$setSpawnPoint(playerIn, null, true, playerIn.dimension, false);
                playerIn.connection.sendPacket(new SChangeGameStatePacket(0, 0.0f));
            }
        }
        if (location == null) {
            cworld = (CraftWorld) Bukkit.getWorlds().get(0);
            blockpos = ((ServerPlayerEntityBridge) playerIn).bridge$getSpawnPoint(cworld.getHandle());
            location = new Location(cworld, blockpos.getX() + 0.5f, blockpos.getY() + 0.1f, blockpos.getZ() + 0.5f);
        }
        Player respawnPlayer = this.cserver.getPlayer(playerIn);
        PlayerRespawnEvent respawnEvent = new PlayerRespawnEvent(respawnPlayer, location, isBedSpawn);
        this.cserver.getPluginManager().callEvent(respawnEvent);
        if (((ServerPlayNetHandlerBridge) playerIn.connection).bridge$isDisconnected()) {
            return playerIn;
        }
        location = respawnEvent.getRespawnLocation();
        if (location.getWorld() == null) {
            location.setWorld(((WorldBridge) this.server.getWorld(dimension)).bridge$getWorld());
        }
        dimension = ((CraftWorld) location.getWorld()).getHandle().dimension.getType();
        if (!flag) {
            ((ServerPlayerEntityBridge) playerIn).bridge$reset();
        }
    } else {
        location.setWorld(((WorldBridge) this.server.getWorld(dimension)).bridge$getWorld());
    }
    playerIn.dimension = dimension;
    ServerPlayerEntity serverplayerentity = new ServerPlayerEntity(this.server, this.server.getWorld(playerIn.dimension), playerIn.getGameProfile(), playerinteractionmanager);
    // Forward to new player instance
    ((InternalEntityBridge) playerIn).internal$getBukkitEntity().setHandle(serverplayerentity);
    ((EntityBridge) serverplayerentity).bridge$setBukkitEntity(((InternalEntityBridge) playerIn).internal$getBukkitEntity());
    if ((Object) serverplayerentity instanceof MobEntity) {
        ((MobEntity) (Object) serverplayerentity).clearLeashed(true, false);
    }
    serverplayerentity.connection = playerIn.connection;
    serverplayerentity.copyFrom(playerIn, conqueredEnd);
    // Forge: clone event had a chance to see old data, now discard it
    playerIn.remove(false);
    serverplayerentity.dimension = dimension;
    serverplayerentity.setEntityId(playerIn.getEntityId());
    serverplayerentity.setPrimaryHand(playerIn.getPrimaryHand());
    for (String s : playerIn.getTags()) {
        serverplayerentity.addTag(s);
    }
    ServerWorld serverworld = ((CraftWorld) location.getWorld()).getHandle();
    serverplayerentity.setPositionAndRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
    serverplayerentity.connection.captureCurrentPosition();
    this.setPlayerGameTypeBasedOnOther(serverplayerentity, playerIn, serverworld);
    while (avoidSuffocation && !this.bridge$worldNoCollision(serverworld, serverplayerentity) && serverplayerentity.posY < 256.0D) {
        serverplayerentity.setPosition(serverplayerentity.posX, serverplayerentity.posY + 1.0D, serverplayerentity.posZ);
    }
    if (fromWorld.getEnvironment() == ((WorldBridge) serverworld).bridge$getWorld().getEnvironment()) {
        serverplayerentity.connection.sendPacket(this.bridge$respawnPacket((((DimensionTypeBridge) serverplayerentity.dimension).bridge$getType().getId() >= 0) ? DimensionType.THE_NETHER : DimensionType.OVERWORLD, serverworld.getWorldInfo().getSeed(), serverworld.getWorldInfo().getGenerator(), playerIn.interactionManager.getGameType()));
    }
    WorldInfo worldinfo = serverplayerentity.world.getWorldInfo();
    NetworkHooks.sendDimensionDataPacket(serverplayerentity.connection.netManager, serverplayerentity);
    serverplayerentity.connection.sendPacket(this.bridge$respawnPacket(((DimensionTypeBridge) serverplayerentity.dimension).bridge$getType(), worldinfo.getSeed(), worldinfo.getGenerator(), serverplayerentity.interactionManager.getGameType()));
    serverplayerentity.connection.sendPacket(new SUpdateViewDistancePacket(((WorldBridge) serverworld).bridge$spigotConfig().viewDistance));
    BlockPos blockpos1 = serverworld.getSpawnPoint();
    serverplayerentity.connection.setPlayerLocation(serverplayerentity.posX, serverplayerentity.posY, serverplayerentity.posZ, serverplayerentity.rotationYaw, serverplayerentity.rotationPitch);
    serverplayerentity.connection.sendPacket(new SSpawnPositionPacket(blockpos1));
    serverplayerentity.connection.sendPacket(new SServerDifficultyPacket(worldinfo.getDifficulty(), worldinfo.isDifficultyLocked()));
    serverplayerentity.connection.sendPacket(new SSetExperiencePacket(serverplayerentity.experience, serverplayerentity.experienceTotal, serverplayerentity.experienceLevel));
    this.sendWorldInfo(serverplayerentity, serverworld);
    this.updatePermissionLevel(serverplayerentity);
    if (!((ServerPlayNetHandlerBridge) serverplayerentity.connection).bridge$isDisconnected()) {
        serverworld.addRespawnedPlayer(serverplayerentity);
        this.addPlayer(serverplayerentity);
        this.uuidToPlayerMap.put(serverplayerentity.getUniqueID(), serverplayerentity);
    }
    serverplayerentity.addSelfToInternalCraftingInventory();
    serverplayerentity.setHealth(serverplayerentity.getHealth());
    this.sendInventory(serverplayerentity);
    serverplayerentity.sendPlayerAbilities();
    serverplayerentity.func_213846_b(((CraftWorld) fromWorld).getHandle());
    if (fromWorld != location.getWorld()) {
        PlayerChangedWorldEvent event = new PlayerChangedWorldEvent(((ServerPlayerEntityBridge) playerIn).bridge$getBukkitEntity(), fromWorld);
        Bukkit.getPluginManager().callEvent(event);
    }
    BasicEventHooks.firePlayerRespawnEvent(serverplayerentity, conqueredEnd);
    System.out.println("pos " + serverplayerentity.getBedLocation());
    return serverplayerentity;
}
Also used : DimensionTypeBridge(io.izzel.arclight.common.bridge.world.dimension.DimensionTypeBridge) ServerPlayNetHandlerBridge(io.izzel.arclight.common.bridge.network.play.ServerPlayNetHandlerBridge) PlayerRespawnEvent(org.bukkit.event.player.PlayerRespawnEvent) SChangeGameStatePacket(net.minecraft.network.play.server.SChangeGameStatePacket) ServerPlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge) ServerWorld(net.minecraft.world.server.ServerWorld) WorldBridge(io.izzel.arclight.common.bridge.world.WorldBridge) ServerWorldBridge(io.izzel.arclight.common.bridge.world.server.ServerWorldBridge) WorldInfo(net.minecraft.world.storage.WorldInfo) BlockPos(net.minecraft.util.math.BlockPos) CraftWorld(org.bukkit.craftbukkit.v.CraftWorld) InternalEntityBridge(io.izzel.arclight.common.bridge.entity.InternalEntityBridge) ServerPlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge) EntityBridge(io.izzel.arclight.common.bridge.entity.EntityBridge) PlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge) SSetExperiencePacket(net.minecraft.network.play.server.SSetExperiencePacket) Player(org.bukkit.entity.Player) SUpdateViewDistancePacket(net.minecraft.network.play.server.SUpdateViewDistancePacket) ServerPlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge) PlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) Vec3d(net.minecraft.util.math.Vec3d) SServerDifficultyPacket(net.minecraft.network.play.server.SServerDifficultyPacket) PlayerChangedWorldEvent(org.bukkit.event.player.PlayerChangedWorldEvent) PlayerInteractionManager(net.minecraft.server.management.PlayerInteractionManager) DemoPlayerInteractionManager(net.minecraft.server.management.DemoPlayerInteractionManager) DemoPlayerInteractionManager(net.minecraft.server.management.DemoPlayerInteractionManager) MobEntity(net.minecraft.entity.MobEntity) SSpawnPositionPacket(net.minecraft.network.play.server.SSpawnPositionPacket) Location(org.bukkit.Location) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 17 with WorldBridge

use of io.izzel.arclight.common.bridge.world.WorldBridge in project Arclight by IzzelAliz.

the class MinecraftServerMixin method loadSpawn.

public void loadSpawn(IChunkStatusListener listener, ServerWorld serverWorld) {
    if (!((WorldBridge) serverWorld).bridge$getWorld().getKeepSpawnInMemory()) {
        return;
    }
    this.setUserMessage(new TranslationTextComponent("menu.generatingTerrain"));
    this.forceTicks = true;
    LOGGER.info("Preparing start region for dimension '{}'/{}", serverWorld.getWorldInfo().getWorldName(), DimensionType.getKey(((DimensionTypeBridge) serverWorld.dimension.getType()).bridge$getType()));
    BlockPos pos = serverWorld.getSpawnPoint();
    listener.start(new ChunkPos(pos));
    ServerChunkProvider chunkProvider = serverWorld.getChunkProvider();
    chunkProvider.getLightManager().func_215598_a(500);
    this.serverTime = Util.milliTime();
    chunkProvider.registerTicket(TicketType.START, new ChunkPos(pos), 11, Unit.INSTANCE);
    while (chunkProvider.getLoadedChunksCount() != 441) {
        this.executeModerately();
    }
    this.executeModerately();
    DimensionType type = serverWorld.dimension.getType();
    ForcedChunksSaveData chunks = serverWorld.getSavedData().get(ForcedChunksSaveData::new, "chunks");
    if (chunks != null) {
        ServerWorld world = this.getWorld(type);
        LongIterator iterator = chunks.getChunks().iterator();
        while (iterator.hasNext()) {
            long i = iterator.nextLong();
            ChunkPos chunkPos = new ChunkPos(i);
            world.getChunkProvider().forceChunk(chunkPos, true);
        }
    }
    this.executeModerately();
    listener.stop();
    chunkProvider.getLightManager().func_215598_a(5);
    this.forceTicks = false;
}
Also used : ServerWorld(net.minecraft.world.server.ServerWorld) DimensionType(net.minecraft.world.dimension.DimensionType) WorldBridge(io.izzel.arclight.common.bridge.world.WorldBridge) DimensionTypeBridge(io.izzel.arclight.common.bridge.world.dimension.DimensionTypeBridge) ForcedChunksSaveData(net.minecraft.world.ForcedChunksSaveData) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) BlockPos(net.minecraft.util.math.BlockPos) ChunkPos(net.minecraft.util.math.ChunkPos) LongIterator(it.unimi.dsi.fastutil.longs.LongIterator) ServerChunkProvider(net.minecraft.world.server.ServerChunkProvider)

Example 18 with WorldBridge

use of io.izzel.arclight.common.bridge.world.WorldBridge in project Arclight by IzzelAliz.

the class MinecraftServerMixin method loadInitialChunks.

/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite
public void loadInitialChunks(IChunkStatusListener listener) {
    this.setUserMessage(new TranslationTextComponent("menu.generatingTerrain"));
    ServerWorld serverworld = this.getWorld(DimensionType.OVERWORLD);
    this.forceTicks = true;
    LOGGER.info("Preparing start region for dimension " + DimensionType.getKey(serverworld.dimension.getType()));
    BlockPos blockpos = serverworld.getSpawnPoint();
    listener.start(new ChunkPos(blockpos));
    ServerChunkProvider serverchunkprovider = serverworld.getChunkProvider();
    serverchunkprovider.getLightManager().func_215598_a(500);
    this.serverTime = Util.milliTime();
    serverchunkprovider.registerTicket(TicketType.START, new ChunkPos(blockpos), 11, Unit.INSTANCE);
    while (serverchunkprovider.getLoadedChunksCount() != 441) {
        this.executeModerately();
    }
    this.executeModerately();
    for (DimensionType dimensiontype : DimensionType.getAll()) {
        ServerWorld serverWorld = this.getWorld(dimensiontype);
        if (((WorldBridge) serverWorld).bridge$getWorld().getKeepSpawnInMemory()) {
            ForcedChunksSaveData forcedchunkssavedata = serverWorld.getSavedData().get(ForcedChunksSaveData::new, "chunks");
            if (forcedchunkssavedata != null) {
                LongIterator longiterator = forcedchunkssavedata.getChunks().iterator();
                while (longiterator.hasNext()) {
                    long i = longiterator.nextLong();
                    ChunkPos chunkpos = new ChunkPos(i);
                    serverWorld.getChunkProvider().forceChunk(chunkpos, true);
                }
            }
        }
        Bukkit.getPluginManager().callEvent(new WorldLoadEvent(((WorldBridge) serverWorld).bridge$getWorld()));
    }
    this.executeModerately();
    listener.stop();
    serverchunkprovider.getLightManager().func_215598_a(5);
    this.forceTicks = false;
}
Also used : ServerWorld(net.minecraft.world.server.ServerWorld) DimensionType(net.minecraft.world.dimension.DimensionType) WorldBridge(io.izzel.arclight.common.bridge.world.WorldBridge) ForcedChunksSaveData(net.minecraft.world.ForcedChunksSaveData) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) BlockPos(net.minecraft.util.math.BlockPos) ChunkPos(net.minecraft.util.math.ChunkPos) WorldLoadEvent(org.bukkit.event.world.WorldLoadEvent) LongIterator(it.unimi.dsi.fastutil.longs.LongIterator) ServerChunkProvider(net.minecraft.world.server.ServerChunkProvider) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 19 with WorldBridge

use of io.izzel.arclight.common.bridge.world.WorldBridge in project Arclight by IzzelAliz.

the class ExplosionMixin method bridge$callBlockExplodeEvent.

@Override
public float bridge$callBlockExplodeEvent() {
    org.bukkit.World world = ((WorldBridge) this.world).bridge$getWorld();
    org.bukkit.entity.Entity exploder = this.exploder == null ? null : ((EntityBridge) this.exploder).bridge$getBukkitEntity();
    Location location = new Location(world, this.x, this.y, this.z);
    List<org.bukkit.block.Block> blockList = Lists.newArrayList();
    for (int i = this.affectedBlockPositions.size() - 1; i >= 0; i--) {
        BlockPos blockPos = this.affectedBlockPositions.get(i);
        org.bukkit.block.Block block = world.getBlockAt(blockPos.getX(), blockPos.getY(), blockPos.getZ());
        if (!block.getType().isAir()) {
            blockList.add(block);
        }
    }
    boolean cancelled;
    List<org.bukkit.block.Block> bukkitBlocks;
    float yield;
    if (exploder != null) {
        EntityExplodeEvent event = new EntityExplodeEvent(exploder, location, blockList, this.mode == Explosion.Mode.DESTROY ? 1.0F / this.size : 1.0F);
        Bukkit.getPluginManager().callEvent(event);
        cancelled = event.isCancelled();
        bukkitBlocks = event.blockList();
        yield = event.getYield();
    } else {
        BlockExplodeEvent event = new BlockExplodeEvent(location.getBlock(), blockList, this.mode == Explosion.Mode.DESTROY ? 1.0F / this.size : 1.0F);
        Bukkit.getPluginManager().callEvent(event);
        cancelled = event.isCancelled();
        bukkitBlocks = event.blockList();
        yield = event.getYield();
    }
    this.affectedBlockPositions.clear();
    for (org.bukkit.block.Block block : bukkitBlocks) {
        BlockPos blockPos = new BlockPos(block.getX(), block.getY(), block.getZ());
        this.affectedBlockPositions.add(blockPos);
    }
    return cancelled ? Float.NaN : yield;
}
Also used : BlockExplodeEvent(org.bukkit.event.block.BlockExplodeEvent) EntityExplodeEvent(org.bukkit.event.entity.EntityExplodeEvent) WorldBridge(io.izzel.arclight.common.bridge.world.WorldBridge) BlockPos(net.minecraft.util.math.BlockPos) Location(org.bukkit.Location)

Example 20 with WorldBridge

use of io.izzel.arclight.common.bridge.world.WorldBridge in project Arclight by IzzelAliz.

the class LivingEntityMixin method arclight$entityTeleport.

@Inject(method = "attemptTeleport", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/entity/LivingEntity;setPositionAndUpdate(DDD)V"))
public void arclight$entityTeleport(double d0, double d1, double d2, boolean flag, CallbackInfoReturnable<Boolean> cir, double d3, double d4, double d5) {
    EntityTeleportEvent event = new EntityTeleportEvent(getBukkitEntity(), new Location(((WorldBridge) this.world).bridge$getWorld(), d3, d4, d5), new Location(((WorldBridge) this.world).bridge$getWorld(), this.posX, this.posY, this.posZ));
    Bukkit.getPluginManager().callEvent(event);
    if (!event.isCancelled()) {
        this.posX = event.getTo().getX();
        this.posY = event.getTo().getY();
        this.posZ = event.getTo().getZ();
    } else {
        this.setPositionAndUpdate(d3, d4, d5);
        cir.setReturnValue(false);
    }
}
Also used : WorldBridge(io.izzel.arclight.common.bridge.world.WorldBridge) EntityTeleportEvent(org.bukkit.event.entity.EntityTeleportEvent) Location(org.bukkit.Location) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

WorldBridge (io.izzel.arclight.common.bridge.world.WorldBridge)24 BlockPos (net.minecraft.util.math.BlockPos)12 Location (org.bukkit.Location)11 Overwrite (org.spongepowered.asm.mixin.Overwrite)9 Inject (org.spongepowered.asm.mixin.injection.Inject)7 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)6 ServerWorld (net.minecraft.world.server.ServerWorld)6 DimensionTypeBridge (io.izzel.arclight.common.bridge.world.dimension.DimensionTypeBridge)4 WorldInfo (net.minecraft.world.storage.WorldInfo)4 Player (org.bukkit.entity.Player)4 ServerPlayerEntityBridge (io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge)3 SChangeGameStatePacket (net.minecraft.network.play.server.SChangeGameStatePacket)3 SServerDifficultyPacket (net.minecraft.network.play.server.SServerDifficultyPacket)3 EffectInstance (net.minecraft.potion.EffectInstance)3 ChunkPos (net.minecraft.util.math.ChunkPos)3 Vec3d (net.minecraft.util.math.Vec3d)3 DimensionType (net.minecraft.world.dimension.DimensionType)3 CraftWorld (org.bukkit.craftbukkit.v.CraftWorld)3 PlayerChangedWorldEvent (org.bukkit.event.player.PlayerChangedWorldEvent)3 PortalCreateEvent (org.bukkit.event.world.PortalCreateEvent)3