Search in sources :

Example 1 with CraftWorld

use of org.bukkit.craftbukkit.v.CraftWorld in project Arclight by IzzelAliz.

the class ServerPlayerEntityMixin method setWorld.

@Override
public void setWorld(World world) {
    super.setWorld(world);
    if (world == null) {
        this.removed = false;
        Vec3d position = null;
        if (this.spawnWorld != null && !this.spawnWorld.equals("")) {
            CraftWorld cworld = (CraftWorld) Bukkit.getServer().getWorld(this.spawnWorld);
            if (cworld != null && this.getBedLocation() != null) {
                world = cworld.getHandle();
                position = PlayerEntity.checkBedValidRespawnPosition(cworld.getHandle(), this.getBedLocation(), false).orElse(null);
            }
        }
        if (world == null || position == null) {
            world = ((CraftWorld) Bukkit.getServer().getWorlds().get(0)).getHandle();
            position = new Vec3d(world.getSpawnPoint());
        }
        this.world = world;
        this.setPosition(position.getX(), position.getY(), position.getZ());
    }
    this.dimension = this.world.getDimension().getType();
    this.interactionManager.setWorld((ServerWorld) world);
}
Also used : CraftWorld(org.bukkit.craftbukkit.v.CraftWorld) Vec3d(net.minecraft.util.math.Vec3d)

Example 2 with CraftWorld

use of org.bukkit.craftbukkit.v.CraftWorld in project Arclight by IzzelAliz.

the class EntityTypeMixin method setup.

@SuppressWarnings("unchecked")
private void setup() {
    if (this.spec.entityClass != null) {
        try {
            Class<?> cl = Class.forName(this.spec.entityClass);
            if (!Entity.class.isAssignableFrom(cl)) {
                throw LocalizedException.checked("registry.entity.not-subclass", cl, Entity.class);
            }
            this.clazz = (Class<? extends Entity>) cl;
        } catch (Exception e) {
            if (e instanceof LocalizedException) {
                ArclightMod.LOGGER.warn(((LocalizedException) e).node(), ((LocalizedException) e).args());
            } else {
                ArclightMod.LOGGER.warn("registry.entity.error", this, this.spec.entityClass, e);
            }
        }
    }
    this.factory = loc -> {
        if (loc != null && loc.getWorld() != null) {
            ServerWorld world = ((CraftWorld) loc.getWorld()).getHandle();
            net.minecraft.entity.Entity entity = handleType.create(world);
            if (entity != null) {
                entity.setPositionAndRotation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
            }
            return entity;
        } else
            return null;
    };
}
Also used : ServerWorld(net.minecraft.world.server.ServerWorld) Entity(org.bukkit.entity.Entity) LocalizedException(io.izzel.arclight.i18n.LocalizedException) CraftWorld(org.bukkit.craftbukkit.v.CraftWorld) LocalizedException(io.izzel.arclight.i18n.LocalizedException)

Example 3 with CraftWorld

use of org.bukkit.craftbukkit.v.CraftWorld in project Arclight by IzzelAliz.

the class WorldMixin method getWorld.

public CraftWorld getWorld() {
    if (this.world == null) {
        if (generator == null) {
            generator = getServer().getGenerator(getWorldInfo().getWorldName());
        }
        if (environment == null) {
            environment = org.bukkit.World.Environment.getEnvironment(getDimension().getType().getId());
        }
        this.world = new CraftWorld((ServerWorld) (Object) this, generator, environment);
        getServer().addWorld(this.world);
    }
    return this.world;
}
Also used : ServerWorld(net.minecraft.world.server.ServerWorld) CraftWorld(org.bukkit.craftbukkit.v.CraftWorld)

Example 4 with CraftWorld

use of org.bukkit.craftbukkit.v.CraftWorld in project Arclight by IzzelAliz.

the class MapDataMixin method arclight$storeDimension.

@Inject(method = "write", at = @At("HEAD"))
public void arclight$storeDimension(CompoundNBT compound, CallbackInfoReturnable<CompoundNBT> cir) {
    if (this.dimension.getId() >= CraftWorld.CUSTOM_DIMENSION_OFFSET) {
        if (this.uniqueId == null) {
            for (org.bukkit.World world : server.getWorlds()) {
                CraftWorld cWorld = (CraftWorld) world;
                if (cWorld.getHandle().dimension.getType() == this.dimension) {
                    this.uniqueId = cWorld.getUID();
                    break;
                }
            }
        }
        /* Perform a second check to see if a matching world was found, this is a necessary
               change incase Maps are forcefully unlinked from a World and lack a UID.*/
        if (this.uniqueId != null) {
            compound.putLong("UUIDLeast", this.uniqueId.getLeastSignificantBits());
            compound.putLong("UUIDMost", this.uniqueId.getMostSignificantBits());
        }
    }
}
Also used : CraftWorld(org.bukkit.craftbukkit.v.CraftWorld) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 5 with CraftWorld

use of org.bukkit.craftbukkit.v.CraftWorld in project Arclight by IzzelAliz.

the class MapDataMixin method arclight$customDimension.

@Redirect(method = "read", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/dimension/DimensionType;getById(I)Lnet/minecraft/world/dimension/DimensionType;"))
public DimensionType arclight$customDimension(int id, CompoundNBT nbt) {
    DimensionType type;
    long least = nbt.getLong("UUIDLeast");
    long most = nbt.getLong("UUIDMost");
    if (least != 0L && most != 0L) {
        this.uniqueId = new UUID(most, least);
        CraftWorld world = (CraftWorld) server.getWorld(this.uniqueId);
        // Check if the stored world details are correct.
        if (world == null) {
            type = DimensionType.getById(id);
            if (type == null) {
                /* All Maps which do not have their valid world loaded are set to a dimension which hopefully won't be reached.
                       This is to prevent them being corrupted with the wrong map data. */
                type = this.bridge$dimension(ArclightConstants.ARCLIGHT_DIMENSION, "", "", OverworldDimension::new, false);
                ((DimensionTypeBridge) type).bridge$setType(DimensionType.OVERWORLD);
            }
        } else {
            type = world.getHandle().dimension.getType();
        }
    } else {
        type = DimensionType.getById(id);
    }
    return type;
}
Also used : DimensionType(net.minecraft.world.dimension.DimensionType) DimensionTypeBridge(io.izzel.arclight.common.bridge.world.dimension.DimensionTypeBridge) UUID(java.util.UUID) CraftWorld(org.bukkit.craftbukkit.v.CraftWorld) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Aggregations

CraftWorld (org.bukkit.craftbukkit.v.CraftWorld)10 ServerWorld (net.minecraft.world.server.ServerWorld)5 BlockPos (net.minecraft.util.math.BlockPos)4 Vec3d (net.minecraft.util.math.Vec3d)4 WorldBridge (io.izzel.arclight.common.bridge.world.WorldBridge)3 DimensionTypeBridge (io.izzel.arclight.common.bridge.world.dimension.DimensionTypeBridge)3 MobEntity (net.minecraft.entity.MobEntity)3 EntityBridge (io.izzel.arclight.common.bridge.entity.EntityBridge)2 InternalEntityBridge (io.izzel.arclight.common.bridge.entity.InternalEntityBridge)2 ServerPlayerEntityBridge (io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge)2 ServerPlayNetHandlerBridge (io.izzel.arclight.common.bridge.network.play.ServerPlayNetHandlerBridge)2 ServerWorldBridge (io.izzel.arclight.common.bridge.world.server.ServerWorldBridge)2 UUID (java.util.UUID)2 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)2 SChangeGameStatePacket (net.minecraft.network.play.server.SChangeGameStatePacket)2 SServerDifficultyPacket (net.minecraft.network.play.server.SServerDifficultyPacket)2 SSetExperiencePacket (net.minecraft.network.play.server.SSetExperiencePacket)2 SSpawnPositionPacket (net.minecraft.network.play.server.SSpawnPositionPacket)2 SUpdateViewDistancePacket (net.minecraft.network.play.server.SUpdateViewDistancePacket)2 MinecraftServer (net.minecraft.server.MinecraftServer)2