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);
}
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;
};
}
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;
}
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());
}
}
}
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;
}
Aggregations