Search in sources :

Example 6 with WorldBridge

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

the class ChunkMixin method loadCallback.

public void loadCallback() {
    org.bukkit.Server server = Bukkit.getServer();
    if (server != null) {
        /*
             * If it's a new world, the first few chunks are generated inside
             * the World constructor. We can't reliably alter that, so we have
             * no way of creating a CraftWorld/CraftServer at that point.
             */
        server.getPluginManager().callEvent(new ChunkLoadEvent(this.bukkitChunk, this.needsDecoration));
        if (this.needsDecoration) {
            this.needsDecoration = false;
            java.util.Random random = new java.util.Random();
            random.setSeed(world.getSeed());
            long xRand = random.nextLong() / 2L * 2L + 1L;
            long zRand = random.nextLong() / 2L * 2L + 1L;
            random.setSeed((long) this.pos.x * xRand + (long) this.pos.z * zRand ^ world.getSeed());
            org.bukkit.World world = ((WorldBridge) this.world).bridge$getWorld();
            if (world != null) {
                ((WorldBridge) this.world).bridge$setPopulating(true);
                try {
                    for (org.bukkit.generator.BlockPopulator populator : world.getPopulators()) {
                        populator.populate(world, random, bukkitChunk);
                    }
                } finally {
                    ((WorldBridge) this.world).bridge$setPopulating(false);
                }
            }
            server.getPluginManager().callEvent(new org.bukkit.event.world.ChunkPopulateEvent(bukkitChunk));
        }
    }
}
Also used : ChunkLoadEvent(org.bukkit.event.world.ChunkLoadEvent) WorldBridge(io.izzel.arclight.common.bridge.world.WorldBridge)

Example 7 with WorldBridge

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

the class MinecraftServerMixin method initWorld.

public void initWorld(ServerWorld serverWorld, WorldInfo worldInfo, WorldSettings worldSettings) {
    serverWorld.getWorldBorder().copyFrom(worldInfo);
    if (((WorldBridge) serverWorld).bridge$getGenerator() != null) {
        ((WorldBridge) serverWorld).bridge$getWorld().getPopulators().addAll(((WorldBridge) serverWorld).bridge$getGenerator().getDefaultPopulators(((WorldBridge) serverWorld).bridge$getWorld()));
    }
    if (!worldInfo.isInitialized()) {
        try {
            serverWorld.createSpawnPosition(worldSettings);
            if (worldInfo.getGenerator() == WorldType.DEBUG_ALL_BLOCK_STATES) {
                this.applyDebugWorldInfo(worldInfo);
            }
            worldInfo.setInitialized(true);
        } catch (Throwable throwable) {
            CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Exception initializing level");
            try {
                serverWorld.fillCrashReport(crashreport);
            } catch (Throwable ignored) {
            }
            throw new ReportedException(crashreport);
        }
        worldInfo.setInitialized(true);
    }
}
Also used : WorldBridge(io.izzel.arclight.common.bridge.world.WorldBridge) CrashReport(net.minecraft.crash.CrashReport) ReportedException(net.minecraft.crash.ReportedException)

Example 8 with WorldBridge

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

the class MinecraftServerMixin method arclight$worldInit.

@Redirect(method = "loadWorlds", at = @At(value = "INVOKE", remap = false, target = "Ljava/util/Map;put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"))
private Object arclight$worldInit(Map<Object, Object> map, Object key, Object value) {
    Object ret = map.put(key, value);
    ServerWorld serverWorld = (ServerWorld) value;
    if (((WorldBridge) serverWorld).bridge$getGenerator() != null) {
        ((WorldBridge) serverWorld).bridge$getWorld().getPopulators().addAll(((WorldBridge) serverWorld).bridge$getGenerator().getDefaultPopulators(((WorldBridge) serverWorld).bridge$getWorld()));
    }
    Bukkit.getPluginManager().callEvent(new WorldInitEvent(((WorldBridge) serverWorld).bridge$getWorld()));
    return ret;
}
Also used : ServerWorld(net.minecraft.world.server.ServerWorld) WorldBridge(io.izzel.arclight.common.bridge.world.WorldBridge) WorldInitEvent(org.bukkit.event.world.WorldInitEvent) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 9 with WorldBridge

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

the class PlayerEntityMixin_1_14 method arclight$wakeup.

@Inject(method = "wakeUpPlayer", locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "FIELD", target = "Lnet/minecraft/entity/player/PlayerEntity;sleepTimer:I"))
private void arclight$wakeup(boolean immediately, boolean updateWorldFlag, boolean setSpawn, CallbackInfo ci, Optional<BlockPos> optional) {
    if (this.bridge$getBukkitEntity() instanceof Player) {
        Player player = (Player) this.bridge$getBukkitEntity();
        BlockPos blockposition2 = optional.orElse(null);
        Block bed;
        if (blockposition2 != null) {
            bed = CraftBlock.at(this.world, blockposition2);
        } else {
            bed = ((WorldBridge) this.world).bridge$getWorld().getBlockAt(player.getLocation());
        }
        PlayerBedLeaveEvent event = new PlayerBedLeaveEvent(player, bed, setSpawn);
        Bukkit.getPluginManager().callEvent(event);
        arclight$setSpawn = event.shouldSetSpawnLocation();
    }
}
Also used : Player(org.bukkit.entity.Player) WorldBridge(io.izzel.arclight.common.bridge.world.WorldBridge) Block(org.bukkit.block.Block) CraftBlock(org.bukkit.craftbukkit.v.block.CraftBlock) BlockPos(net.minecraft.util.math.BlockPos) PlayerBedLeaveEvent(org.bukkit.event.player.PlayerBedLeaveEvent) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 10 with WorldBridge

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

the class ServerPlayerEntityMixin_1_14 method changeDimension.

/**
 * @author IzzelAliz
 * @reason
 */
@Nullable
@Overwrite
public Entity changeDimension(DimensionType dimensionmanager) {
    PlayerTeleportEvent.TeleportCause cause = bridge$getTeleportCause().orElse(PlayerTeleportEvent.TeleportCause.UNKNOWN);
    if (!net.minecraftforge.common.ForgeHooks.onTravelToDimension((ServerPlayerEntity) (Object) this, dimensionmanager))
        return null;
    if (this.isSleeping()) {
        return (ServerPlayerEntity) (Object) this;
    }
    DimensionType dimensionmanager2 = this.dimension;
    if (((DimensionTypeBridge) dimensionmanager2).bridge$getType() == DimensionType.THE_END && ((DimensionTypeBridge) dimensionmanager).bridge$getType() == DimensionType.OVERWORLD) {
        this.invulnerableDimensionChange = true;
        this.detach();
        this.func_71121_q().removePlayer((ServerPlayerEntity) (Object) this, true);
        if (!this.queuedEndExit) {
            this.queuedEndExit = true;
            this.connection.sendPacket(new SChangeGameStatePacket(4, this.seenCredits ? 0.0f : 1.0f));
            this.seenCredits = true;
        }
        return (ServerPlayerEntity) (Object) this;
    }
    ServerWorld worldserver = this.server.func_71218_a(dimensionmanager2);
    ServerWorld worldserver2 = this.server.func_71218_a(dimensionmanager);
    WorldInfo worlddata = this.world.getWorldInfo();
    double d0 = this.posX;
    double d2 = this.posY;
    double d3 = this.posZ;
    float f = this.rotationPitch;
    float f2 = this.rotationYaw;
    double d4 = 8.0;
    float f3 = f2;
    worldserver.getProfiler().startSection("moving");
    if (worldserver2 != null) {
        if (dimensionmanager2 == DimensionType.OVERWORLD && dimensionmanager == DimensionType.THE_NETHER) {
            this.enteredNetherPosition = new Vec3d(this.posX, this.posY, this.posZ);
            d0 /= 8.0;
            d3 /= 8.0;
        } else if (dimensionmanager2 == DimensionType.THE_NETHER && dimensionmanager == DimensionType.OVERWORLD) {
            d0 *= 8.0;
            d3 *= 8.0;
        } else if (dimensionmanager2 == DimensionType.OVERWORLD && dimensionmanager == DimensionType.THE_END) {
            BlockPos blockposition = worldserver2.getSpawnCoordinate();
            d0 = blockposition.getX();
            d2 = blockposition.getY();
            d3 = blockposition.getZ();
            f2 = 90.0f;
            f = 0.0f;
        }
    }
    Location enter = this.bridge$getBukkitEntity().getLocation();
    Location exit = (worldserver2 == null) ? null : new Location(((WorldBridge) worldserver2).bridge$getWorld(), d0, d2, d3, f2, f);
    PlayerPortalEvent event = new PlayerPortalEvent((Player) this.bridge$getBukkitEntity(), enter, exit, cause);
    Bukkit.getServer().getPluginManager().callEvent(event);
    if (event.isCancelled() || event.getTo() == null) {
        return null;
    }
    exit = event.getTo();
    if (exit == null) {
        return null;
    }
    PlayerTeleportEvent tpEvent = new PlayerTeleportEvent((Player) this.bridge$getBukkitEntity(), enter, exit, cause);
    Bukkit.getServer().getPluginManager().callEvent(tpEvent);
    if (tpEvent.isCancelled() || tpEvent.getTo() == null) {
        return null;
    }
    exit = tpEvent.getTo();
    if (exit == null) {
        return null;
    }
    worldserver2 = ((CraftWorld) exit.getWorld()).getHandle();
    d0 = exit.getX();
    d2 = exit.getY();
    d3 = exit.getZ();
    f2 = exit.getYaw();
    f = exit.getPitch();
    this.invulnerableDimensionChange = true;
    dimensionmanager = worldserver2.getDimension().getType();
    this.dimension = dimensionmanager;
    net.minecraftforge.fml.network.NetworkHooks.sendDimensionDataPacket(this.connection.netManager, (ServerPlayerEntity) (Object) this);
    this.connection.sendPacket(new SRespawnPacket(worldserver2.dimension.getType(), this.world.getWorldInfo().getGenerator(), this.interactionManager.getGameType()));
    this.connection.sendPacket(new SServerDifficultyPacket(this.world.getDifficulty(), this.world.getWorldInfo().isDifficultyLocked()));
    PlayerList playerlist = this.server.getPlayerList();
    playerlist.updatePermissionLevel((ServerPlayerEntity) (Object) this);
    worldserver.removePlayer((ServerPlayerEntity) (Object) this, true);
    this.removed = false;
    this.setLocationAndAngles(d0, d2, d3, f2, f);
    worldserver.getProfiler().endSection();
    worldserver.getProfiler().startSection("placing");
    double d5 = Math.min(-2.9999872E7, worldserver2.getWorldBorder().minX() + 16.0);
    double d6 = Math.min(-2.9999872E7, worldserver2.getWorldBorder().minZ() + 16.0);
    double d7 = Math.min(2.9999872E7, worldserver2.getWorldBorder().maxX() - 16.0);
    double d8 = Math.min(2.9999872E7, worldserver2.getWorldBorder().maxZ() - 16.0);
    d0 = MathHelper.clamp(d0, d5, d7);
    d3 = MathHelper.clamp(d3, d6, d8);
    this.setLocationAndAngles(d0, d2, d3, f2, f);
    if (((DimensionTypeBridge) dimensionmanager).bridge$getType() == DimensionType.THE_END) {
        int i = MathHelper.floor(this.posX);
        int j = MathHelper.floor(this.posY) - 1;
        int k = MathHelper.floor(this.posZ);
        boolean flag = true;
        boolean flag2 = false;
        BlockStateListPopulator blockList = new BlockStateListPopulator(worldserver2);
        for (int l = -2; l <= 2; ++l) {
            for (int i2 = -2; i2 <= 2; ++i2) {
                for (int j2 = -1; j2 < 3; ++j2) {
                    int k2 = i + i2 * 1 + l * 0;
                    int l2 = j + j2;
                    int i3 = k + i2 * 0 - l * 1;
                    boolean flag3 = j2 < 0;
                    blockList.setBlockState(new BlockPos(k2, l2, i3), flag3 ? Blocks.OBSIDIAN.getDefaultState() : Blocks.AIR.getDefaultState(), 3);
                }
            }
        }
        org.bukkit.World bworld = ((WorldBridge) worldserver2).bridge$getWorld();
        PortalCreateEvent portalEvent = new PortalCreateEvent((List) blockList.getList(), bworld, this.bridge$getBukkitEntity(), PortalCreateEvent.CreateReason.END_PLATFORM);
        Bukkit.getPluginManager().callEvent(portalEvent);
        if (!portalEvent.isCancelled()) {
            blockList.updateList();
        }
        this.setLocationAndAngles(i, j, k, f2, 0.0f);
        this.setMotion(Vec3d.ZERO);
    } else if (!worldserver2.getDefaultTeleporter().placeInPortal((ServerPlayerEntity) (Object) this, f3)) {
        worldserver2.getDefaultTeleporter().makePortal((ServerPlayerEntity) (Object) this);
        worldserver2.getDefaultTeleporter().placeInPortal((ServerPlayerEntity) (Object) this, f3);
    }
    worldserver.getProfiler().endSection();
    this.setWorld(worldserver2);
    worldserver2.func_217447_b((ServerPlayerEntity) (Object) this);
    this.func_213846_b(worldserver);
    this.connection.setPlayerLocation(this.posX, this.posY, this.posZ, f2, f);
    this.interactionManager.func_73080_a(worldserver2);
    this.connection.sendPacket(new SPlayerAbilitiesPacket(this.abilities));
    playerlist.func_72354_b((ServerPlayerEntity) (Object) this, worldserver2);
    playerlist.sendInventory((ServerPlayerEntity) (Object) this);
    for (EffectInstance mobeffect : this.getActivePotionEffects()) {
        this.connection.sendPacket(new SPlayEntityEffectPacket(this.getEntityId(), mobeffect));
    }
    this.connection.sendPacket(new SPlaySoundEventPacket(1032, BlockPos.ZERO, 0, false));
    this.lastExperience = -1;
    this.lastHealth = -1.0f;
    this.lastFoodLevel = -1;
    PlayerChangedWorldEvent changeEvent = new PlayerChangedWorldEvent((Player) this.bridge$getBukkitEntity(), ((WorldBridge) worldserver).bridge$getWorld());
    Bukkit.getPluginManager().callEvent(changeEvent);
    net.minecraftforge.fml.hooks.BasicEventHooks.firePlayerChangedDimensionEvent((ServerPlayerEntity) (Object) this, dimensionmanager2, dimensionmanager);
    return (ServerPlayerEntity) (Object) this;
}
Also used : DimensionType(net.minecraft.world.dimension.DimensionType) DimensionTypeBridge(io.izzel.arclight.common.bridge.world.dimension.DimensionTypeBridge) PlayerList(net.minecraft.server.management.PlayerList) SPlayEntityEffectPacket(net.minecraft.network.play.server.SPlayEntityEffectPacket) PlayerPortalEvent(org.bukkit.event.player.PlayerPortalEvent) SPlaySoundEventPacket(net.minecraft.network.play.server.SPlaySoundEventPacket) SChangeGameStatePacket(net.minecraft.network.play.server.SChangeGameStatePacket) ServerWorld(net.minecraft.world.server.ServerWorld) WorldBridge(io.izzel.arclight.common.bridge.world.WorldBridge) SPlayerAbilitiesPacket(net.minecraft.network.play.server.SPlayerAbilitiesPacket) SRespawnPacket(net.minecraft.network.play.server.SRespawnPacket) WorldInfo(net.minecraft.world.storage.WorldInfo) BlockPos(net.minecraft.util.math.BlockPos) PortalCreateEvent(org.bukkit.event.world.PortalCreateEvent) PlayerTeleportEvent(org.bukkit.event.player.PlayerTeleportEvent) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) BlockStateListPopulator(org.bukkit.craftbukkit.v.util.BlockStateListPopulator) Vec3d(net.minecraft.util.math.Vec3d) SServerDifficultyPacket(net.minecraft.network.play.server.SServerDifficultyPacket) PlayerChangedWorldEvent(org.bukkit.event.player.PlayerChangedWorldEvent) EffectInstance(net.minecraft.potion.EffectInstance) Location(org.bukkit.Location) Overwrite(org.spongepowered.asm.mixin.Overwrite) Nullable(javax.annotation.Nullable)

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