use of net.minecraft.world.WorldProvider in project MinecraftForge by MinecraftForge.
the class DimensionManager method createProviderFor.
public static WorldProvider createProviderFor(int dim) {
try {
if (dimensions.containsKey(dim)) {
WorldProvider ret = getProviderType(dim).createDimension();
ret.setDimension(dim);
return ret;
} else {
//It's going to crash anyway at this point. Might as well be informative
throw new RuntimeException(String.format("No WorldProvider bound for dimension %d", dim));
}
} catch (Exception e) {
FMLCommonHandler.instance().getFMLLogger().log(Level.ERROR, String.format("An error occurred trying to create an instance of WorldProvider %d (%s)", dim, getProviderType(dim)), e);
throw new RuntimeException(e);
}
}
use of net.minecraft.world.WorldProvider in project RFToolsDimensions by McJty.
the class ForgeEventHandlers method onOreGenEvent.
@SubscribeEvent
public void onOreGenEvent(OreGenEvent.GenerateMinable event) {
World world = event.getWorld();
if (world == null) {
return;
}
WorldProvider provider = world.provider;
if (!(provider instanceof GenericWorldProvider))
return;
DimensionInformation information = ((GenericWorldProvider) provider).getDimensionInformation();
if (information != null && information.hasFeatureType(FeatureType.FEATURE_CLEAN)) {
event.setResult(Event.Result.DENY);
}
}
use of net.minecraft.world.WorldProvider in project SpongeCommon by SpongePowered.
the class EntityUtil method adjustEntityPostionForTeleport.
public static void adjustEntityPostionForTeleport(IMixinPlayerList playerList, Entity entity, WorldServer fromWorld, WorldServer toWorld) {
fromWorld.profiler.startSection("moving");
WorldProvider pOld = fromWorld.provider;
WorldProvider pNew = toWorld.provider;
double moveFactor = playerList.getMovementFactor(pOld) / playerList.getMovementFactor(pNew);
double x = entity.posX * moveFactor;
double y = entity.posY;
double z = entity.posZ * moveFactor;
if (pNew instanceof WorldProviderEnd) {
BlockPos blockpos;
if (pOld instanceof WorldProviderEnd) {
blockpos = toWorld.getSpawnPoint();
} else {
blockpos = toWorld.getSpawnCoordinate();
}
x = blockpos.getX();
y = blockpos.getY();
z = blockpos.getZ();
entity.setLocationAndAngles(x, y, z, 90.0F, 0.0F);
}
if (!(pOld instanceof WorldProviderEnd)) {
fromWorld.profiler.startSection("placing");
x = MathHelper.clamp((int) x, -29999872, 29999872);
z = MathHelper.clamp((int) z, -29999872, 29999872);
if (entity.isEntityAlive()) {
entity.setLocationAndAngles(x, y, z, entity.rotationYaw, entity.rotationPitch);
}
fromWorld.profiler.endSection();
}
if (entity.isEntityAlive()) {
fromWorld.updateEntityWithOptionalForce(entity, false);
}
fromWorld.profiler.endSection();
}
use of net.minecraft.world.WorldProvider in project SpongeCommon by SpongePowered.
the class MixinMinecraftServer method onUpdateTimeLightAndEntitiesHead.
// All chunk unload queuing needs to be processed BEFORE the future tasks are run as mods/plugins may have tasks that request chunks.
// This prevents a situation where a chunk is requested to load then unloads at end of tick.
@Inject(method = "updateTimeLightAndEntities", at = @At("HEAD"))
public void onUpdateTimeLightAndEntitiesHead(CallbackInfo ci) {
for (int i = 0; i < this.worlds.length; ++i) {
WorldServer worldServer = this.worlds[i];
// ChunkGC needs to be processed before a world tick in order to guarantee any chunk queued for unload
// can still be marked active and avoid unload if accessed during the same tick.
// Note: This injection must come before Forge's pre world tick event or it will cause issues with mods.
IMixinWorldServer spongeWorld = (IMixinWorldServer) worldServer;
if (spongeWorld.getChunkGCTickInterval() > 0) {
spongeWorld.doChunkGC();
}
// Moved from PlayerChunkMap to avoid chunks from unloading after being requested in same tick
if (worldServer.getPlayerChunkMap().players.isEmpty()) {
WorldProvider worldprovider = worldServer.provider;
if (!worldprovider.canRespawnHere()) {
worldServer.getChunkProvider().queueUnloadAll();
}
}
}
}
use of net.minecraft.world.WorldProvider in project SpongeCommon by SpongePowered.
the class MixinWorldServer method createWorldGenerator.
@Override
public SpongeWorldGenerator createWorldGenerator(String settings) {
final WorldServer worldServer = (WorldServer) (Object) this;
final WorldType worldType = worldServer.getWorldType();
final IChunkGenerator chunkGenerator;
final BiomeProvider biomeProvider;
if (worldType instanceof SpongeWorldType) {
chunkGenerator = ((SpongeWorldType) worldType).getChunkGenerator(worldServer, settings);
biomeProvider = ((SpongeWorldType) worldType).getBiomeProvider(worldServer);
} else {
final IChunkGenerator currentGenerator = this.getChunkProvider().chunkGenerator;
if (currentGenerator != null) {
chunkGenerator = currentGenerator;
} else {
final WorldProvider worldProvider = worldServer.provider;
((IMixinWorldProvider) worldProvider).setGeneratorSettings(settings);
chunkGenerator = worldProvider.createChunkGenerator();
}
biomeProvider = worldServer.provider.biomeProvider;
}
return new SpongeWorldGenerator(worldServer, (BiomeGenerator) biomeProvider, SpongeGenerationPopulator.of(worldServer, chunkGenerator));
}
Aggregations