This commit is contained in:
Daniel Mills
2020-10-20 09:22:14 -04:00
parent 743a4f97ba
commit d47da11ce8
29 changed files with 2066 additions and 680 deletions

View File

@@ -0,0 +1,66 @@
package com.volmit.iris.gen.nms;
import org.bukkit.Bukkit;
import com.volmit.iris.Iris;
import com.volmit.iris.gen.nms.v16_2.NMSBinding16_2;
import com.volmit.iris.gen.nms.v1X.NMSBinding1X;
import com.volmit.iris.util.KMap;
public class INMS
{
//@builder
private static final KMap<String, Class<? extends INMSBinding>> bindings = new KMap<String, Class<? extends INMSBinding>>()
.qput("v1_16_R2", NMSBinding16_2.class);
//@done
private static final INMSBinding binding = bind();
public static INMSBinding get()
{
return binding;
}
private static final String getNMSTag()
{
try
{
return Bukkit.getServer().getClass().getCanonicalName().split("\\Q.\\E")[3];
}
catch(Throwable e)
{
Iris.error("Failed to determine server nms version!");
e.printStackTrace();
}
return "BUKKIT";
}
private static final INMSBinding bind()
{
String code = getNMSTag();
Iris.info("Locating NMS Binding for " + code);
if(bindings.containsKey(code))
{
try
{
INMSBinding b = bindings.get(code).getConstructor().newInstance();
Iris.info("Craftbukkit " + code + " <-> " + b.getClass().getSimpleName() + " Successfully Bound");
return b;
}
catch(Throwable e)
{
e.printStackTrace();
}
}
Iris.info("Craftbukkit " + code + " <-> " + NMSBinding1X.class.getSimpleName() + " Successfully Bound");
Iris.warn("Note: Some features of Iris may not work the same since you are on an unsupported version of Minecraft.");
Iris.warn("Note: If this is a new version, expect an update soon.");
return new NMSBinding1X();
}
}

View File

@@ -0,0 +1,19 @@
package com.volmit.iris.gen.nms;
import org.bukkit.World;
import org.bukkit.WorldCreator;
public interface INMSBinding
{
public INMSCreator getCreator();
default World createWorld(WorldCreator creator)
{
return getCreator().createWorld(creator);
}
default World createWorld(WorldCreator creator, boolean loadSpawn)
{
return getCreator().createWorld(creator, loadSpawn);
}
}

View File

@@ -0,0 +1,14 @@
package com.volmit.iris.gen.nms;
import org.bukkit.World;
import org.bukkit.WorldCreator;
public interface INMSCreator
{
default World createWorld(WorldCreator creator)
{
return createWorld(creator, false);
}
public World createWorld(WorldCreator creator, boolean loadSpawn);
}

View File

@@ -1,56 +0,0 @@
package com.volmit.iris.gen.nms;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.WorldCreator;
import com.volmit.iris.Iris;
import com.volmit.iris.IrisSettings;
import io.papermc.lib.PaperLib;
public class NMSCreator
{
public static World createWorld(WorldCreator creator)
{
return createWorld(creator, true);
}
public static World createWorld(WorldCreator creator, boolean loadSpawn)
{
if(IrisSettings.get().isSkipPrepareSpawnNMS())
{
if(!PaperLib.isPaper())
{
try
{
String code = Iris.nmsTag();
if(code.equals("v1_16_R2"))
{
return NMSCreator162.createWorld(creator, loadSpawn);
}
else if(code.equals("v1_16_R1"))
{
return NMSCreator161.createWorld(creator, loadSpawn);
}
else if(code.equals("v1_15_R1"))
{
return NMSCreator151.createWorld(creator, loadSpawn);
}
else if(code.equals("v1_14_R1"))
{
return NMSCreator141.createWorld(creator, loadSpawn);
}
}
catch(Throwable e)
{
}
}
}
return Bukkit.createWorld(creator);
}
}

View File

@@ -1,35 +0,0 @@
package com.volmit.iris.gen.nms;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_16_R2.CraftWorld;
import net.minecraft.server.v1_16_R2.ChunkGenerator;
import net.minecraft.server.v1_16_R2.DimensionManager;
import net.minecraft.server.v1_16_R2.IChunkAccess;
import net.minecraft.server.v1_16_R2.MinecraftServer;
import net.minecraft.server.v1_16_R2.RegistryMaterials;
import net.minecraft.server.v1_16_R2.StructureManager;
import net.minecraft.server.v1_16_R2.StructureSettings;
import net.minecraft.server.v1_16_R2.WorldChunkManager;
import net.minecraft.server.v1_16_R2.WorldDataServer;
import net.minecraft.server.v1_16_R2.WorldDimension;
import net.minecraft.server.v1_16_R2.WorldServer;
public class WorldCracker162
{
@SuppressWarnings("unused")
public static void printSignature(World world, int x, int z) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException
{
WorldServer ws = ((CraftWorld) world).getHandle();
MinecraftServer server = ws.getMinecraftServer();
WorldDataServer wds = ws.worldDataServer;
StructureManager sm = ws.getStructureManager();
RegistryMaterials<WorldDimension> registrymaterials = wds.getGeneratorSettings().d();
WorldDimension wdm = (WorldDimension) registrymaterials.a(WorldDimension.OVERWORLD);
DimensionManager dm = wdm.b();
ChunkGenerator cg = wdm.c();
StructureSettings ss = cg.getSettings();
IChunkAccess ica = ws.getChunkAt(x, z);
WorldChunkManager wcm = cg.getWorldChunkManager();
}
}

View File

@@ -1,144 +0,0 @@
package com.volmit.iris.gen.nms;
import java.io.File;
import java.util.Locale;
import java.util.Map;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.WorldCreator;
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
import org.bukkit.craftbukkit.v1_14_R1.CraftWorld;
import org.bukkit.event.Event;
import org.bukkit.event.world.WorldInitEvent;
import org.bukkit.event.world.WorldLoadEvent;
import org.bukkit.generator.ChunkGenerator;
import com.google.common.base.Preconditions;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import com.volmit.iris.util.V;
import net.minecraft.server.v1_14_R1.DedicatedServer;
import net.minecraft.server.v1_14_R1.DimensionManager;
import net.minecraft.server.v1_14_R1.EnumDifficulty;
import net.minecraft.server.v1_14_R1.EnumGamemode;
import net.minecraft.server.v1_14_R1.GameProfilerFiller;
import net.minecraft.server.v1_14_R1.MinecraftServer;
import net.minecraft.server.v1_14_R1.WorldData;
import net.minecraft.server.v1_14_R1.WorldNBTStorage;
import net.minecraft.server.v1_14_R1.WorldProvider;
import net.minecraft.server.v1_14_R1.WorldServer;
import net.minecraft.server.v1_14_R1.WorldSettings;
import net.minecraft.server.v1_14_R1.ChunkCoordIntPair;
import net.minecraft.server.v1_14_R1.TicketType;
import net.minecraft.server.v1_14_R1.Unit;
public class NMSCreator141
{
public static void addStartTicket(Location center, int size)
{
((CraftWorld) center.getWorld()).getHandle().getChunkProvider().addTicket(TicketType.START, new ChunkCoordIntPair(center.getBlockX() >> 4, center.getBlockZ() >> 4), size, Unit.INSTANCE);
}
@SuppressWarnings({"resource", "deprecation"})
public static World createWorld(WorldCreator creator, boolean loadSpawn)
{
CraftServer server = ((CraftServer) Bukkit.getServer());
Map<String, World> worlds = new V(server).get("worlds");
DedicatedServer console = new V(server).get("console");
WorldSettings worldSettings;
Preconditions.checkState((boolean) (!console.worldServer.isEmpty()), (Object) "Cannot create additional worlds on STARTUP");
Validate.notNull((Object) creator, (String) "Creator may not be null");
String name = creator.name();
ChunkGenerator generator = creator.generator();
File folder = new File(server.getWorldContainer(), name);
World world = server.getWorld(name);
net.minecraft.server.v1_14_R1.WorldType type = net.minecraft.server.v1_14_R1.WorldType.getType((String) creator.type().getName());
boolean generateStructures = creator.generateStructures();
if(world != null)
{
return world;
}
if(folder.exists() && !folder.isDirectory())
{
throw new IllegalArgumentException("File exists with the name '" + name + "' and isn't a folder");
}
if(generator == null)
{
generator = server.getGenerator(name);
}
console.convertWorld(name);
int dimension = 10 + console.worldServer.size();
boolean used = false;
block0: do
{
for(WorldServer ss : console.getWorlds())
{
@SuppressWarnings("unused")
boolean bl = used = ss.getWorldProvider().getDimensionManager().getDimensionID() == dimension;
if(!used)
continue;
++dimension;
continue block0;
}
}
while(used);
boolean hardcore = false;
WorldNBTStorage sdm = new WorldNBTStorage(server.getWorldContainer(), name, (MinecraftServer) server.getServer(), server.getHandle().getServer().dataConverterManager);
WorldData worlddata = sdm.getWorldData();
if(worlddata == null)
{
worldSettings = new WorldSettings(creator.seed(), EnumGamemode.getById((int) server.getDefaultGameMode().getValue()), generateStructures, hardcore, type);
JsonElement parsedSettings = new JsonParser().parse(creator.generatorSettings());
if(parsedSettings.isJsonObject())
{
worldSettings.setGeneratorSettings((JsonElement) parsedSettings.getAsJsonObject());
}
worlddata = new WorldData(worldSettings, name);
}
else
{
worlddata.setName(name);
worldSettings = new WorldSettings(worlddata);
}
DimensionManager actualDimension = DimensionManager.a((int) creator.environment().getId());
DimensionManager internalDimension = DimensionManager.register((String) name.toLowerCase(Locale.ENGLISH), (DimensionManager) new DimensionManager(dimension, actualDimension.getSuffix(), actualDimension.folder, (w, manager) -> (WorldProvider) manager.providerFactory.apply(w, manager), actualDimension.hasSkyLight(), actualDimension));
//@builder
WorldServer internal = new WorldServer(
(MinecraftServer)console,
console.executorService,
sdm,
worlddata,
internalDimension,
(GameProfilerFiller)console.getMethodProfiler(),
server.getServer().worldLoadListenerFactory.create(11),
creator.environment(),
generator);
//@done
if(!worlds.containsKey(name.toLowerCase(Locale.ENGLISH)))
{
return null;
}
console.initWorld(internal, worlddata, worldSettings);
internal.worldData.setDifficulty(EnumDifficulty.EASY);
internal.setSpawnFlags(true, true);
console.worldServer.put(internal.getWorldProvider().getDimensionManager(), internal);
server.getPluginManager().callEvent((Event) new WorldInitEvent((World) internal.getWorld()));
if(loadSpawn)
{
server.getServer().loadSpawn(internal.getChunkProvider().playerChunkMap.worldLoadListener, internal);
}
else
{
MinecraftServer.LOGGER.info("Preparing start region for dimens... Oh wait, We don't do that here anymore.");
}
server.getPluginManager().callEvent((Event) new WorldLoadEvent((World) internal.getWorld()));
return internal.getWorld();
}
}

View File

@@ -1,144 +0,0 @@
package com.volmit.iris.gen.nms;
import java.io.File;
import java.util.Locale;
import java.util.Map;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.WorldCreator;
import org.bukkit.craftbukkit.v1_15_R1.CraftServer;
import org.bukkit.craftbukkit.v1_15_R1.CraftWorld;
import org.bukkit.event.Event;
import org.bukkit.event.world.WorldInitEvent;
import org.bukkit.event.world.WorldLoadEvent;
import org.bukkit.generator.ChunkGenerator;
import com.google.common.base.Preconditions;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import com.volmit.iris.util.V;
import net.minecraft.server.v1_15_R1.DedicatedServer;
import net.minecraft.server.v1_15_R1.DimensionManager;
import net.minecraft.server.v1_15_R1.EnumDifficulty;
import net.minecraft.server.v1_15_R1.EnumGamemode;
import net.minecraft.server.v1_15_R1.GameProfilerFiller;
import net.minecraft.server.v1_15_R1.MinecraftServer;
import net.minecraft.server.v1_15_R1.WorldData;
import net.minecraft.server.v1_15_R1.WorldNBTStorage;
import net.minecraft.server.v1_15_R1.WorldProvider;
import net.minecraft.server.v1_15_R1.WorldServer;
import net.minecraft.server.v1_15_R1.WorldSettings;
import net.minecraft.server.v1_15_R1.ChunkCoordIntPair;
import net.minecraft.server.v1_15_R1.TicketType;
import net.minecraft.server.v1_15_R1.Unit;
public class NMSCreator151
{
public static void addStartTicket(Location center, int size)
{
((CraftWorld) center.getWorld()).getHandle().getChunkProvider().addTicket(TicketType.START, new ChunkCoordIntPair(center.getBlockX() >> 4, center.getBlockZ() >> 4), size, Unit.INSTANCE);
}
@SuppressWarnings({"resource", "deprecation"})
public static World createWorld(WorldCreator creator, boolean loadSpawn)
{
CraftServer server = ((CraftServer) Bukkit.getServer());
Map<String, World> worlds = new V(server).get("worlds");
DedicatedServer console = new V(server).get("console");
WorldSettings worldSettings;
Preconditions.checkState((boolean) (!console.worldServer.isEmpty()), (Object) "Cannot create additional worlds on STARTUP");
Validate.notNull((Object) creator, (String) "Creator may not be null");
String name = creator.name();
ChunkGenerator generator = creator.generator();
File folder = new File(server.getWorldContainer(), name);
World world = server.getWorld(name);
net.minecraft.server.v1_15_R1.WorldType type = net.minecraft.server.v1_15_R1.WorldType.getType((String) creator.type().getName());
boolean generateStructures = creator.generateStructures();
if(world != null)
{
return world;
}
if(folder.exists() && !folder.isDirectory())
{
throw new IllegalArgumentException("File exists with the name '" + name + "' and isn't a folder");
}
if(generator == null)
{
generator = server.getGenerator(name);
}
console.convertWorld(name);
int dimension = 10 + console.worldServer.size();
boolean used = false;
block0: do
{
for(WorldServer ss : console.getWorlds())
{
@SuppressWarnings("unused")
boolean bl = used = ss.getWorldProvider().getDimensionManager().getDimensionID() == dimension;
if(!used)
continue;
++dimension;
continue block0;
}
}
while(used);
boolean hardcore = false;
WorldNBTStorage sdm = new WorldNBTStorage(server.getWorldContainer(), name, (MinecraftServer) server.getServer(), server.getHandle().getServer().dataConverterManager);
WorldData worlddata = sdm.getWorldData();
if(worlddata == null)
{
worldSettings = new WorldSettings(creator.seed(), EnumGamemode.getById((int) server.getDefaultGameMode().getValue()), generateStructures, hardcore, type);
JsonElement parsedSettings = new JsonParser().parse(creator.generatorSettings());
if(parsedSettings.isJsonObject())
{
worldSettings.setGeneratorSettings((JsonElement) parsedSettings.getAsJsonObject());
}
worlddata = new WorldData(worldSettings, name);
}
else
{
worlddata.setName(name);
worldSettings = new WorldSettings(worlddata);
}
DimensionManager actualDimension = DimensionManager.a((int) creator.environment().getId());
DimensionManager internalDimension = DimensionManager.register((String) name.toLowerCase(Locale.ENGLISH), (DimensionManager) new DimensionManager(dimension, actualDimension.getSuffix(), actualDimension.folder, (w, manager) -> (WorldProvider) manager.providerFactory.apply(w, manager), actualDimension.hasSkyLight(), actualDimension.getGenLayerZoomer(), actualDimension));
//@builder
WorldServer internal = new WorldServer(
(MinecraftServer)console,
console.executorService,
sdm,
worlddata,
internalDimension,
(GameProfilerFiller)console.getMethodProfiler(),
server.getServer().worldLoadListenerFactory.create(11),
creator.environment(),
generator);
//@done
if(!worlds.containsKey(name.toLowerCase(Locale.ENGLISH)))
{
return null;
}
console.initWorld(internal, worlddata, worldSettings);
internal.worldData.setDifficulty(EnumDifficulty.EASY);
internal.setSpawnFlags(true, true);
console.worldServer.put(internal.getWorldProvider().getDimensionManager(), internal);
server.getPluginManager().callEvent((Event) new WorldInitEvent((World) internal.getWorld()));
if(loadSpawn)
{
server.getServer().loadSpawn(internal.getChunkProvider().playerChunkMap.worldLoadListener, internal);
}
else
{
MinecraftServer.LOGGER.info("Preparing start region for dimens... Oh wait, We don't do that here anymore.");
}
server.getPluginManager().callEvent((Event) new WorldLoadEvent((World) internal.getWorld()));
return internal.getWorld();
}
}

View File

@@ -1,218 +0,0 @@
package com.volmit.iris.gen.nms;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Properties;
import java.util.Random;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.WorldCreator;
import org.bukkit.craftbukkit.v1_16_R1.CraftServer;
import org.bukkit.craftbukkit.v1_16_R1.CraftWorld;
import org.bukkit.event.Event;
import org.bukkit.event.world.WorldInitEvent;
import org.bukkit.event.world.WorldLoadEvent;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.mojang.serialization.DynamicOps;
import com.mojang.serialization.Lifecycle;
import com.volmit.iris.util.V;
import net.minecraft.server.v1_16_R1.BiomeManager;
import net.minecraft.server.v1_16_R1.Convertable;
import net.minecraft.server.v1_16_R1.DedicatedServer;
import net.minecraft.server.v1_16_R1.DimensionManager;
import net.minecraft.server.v1_16_R1.DynamicOpsNBT;
import net.minecraft.server.v1_16_R1.EnumDifficulty;
import net.minecraft.server.v1_16_R1.EnumGamemode;
import net.minecraft.server.v1_16_R1.GameRules;
import net.minecraft.server.v1_16_R1.GeneratorSettings;
import net.minecraft.server.v1_16_R1.IRegistry;
import net.minecraft.server.v1_16_R1.IWorldDataServer;
import net.minecraft.server.v1_16_R1.MinecraftKey;
import net.minecraft.server.v1_16_R1.MinecraftServer;
import net.minecraft.server.v1_16_R1.MobSpawner;
import net.minecraft.server.v1_16_R1.MobSpawnerCat;
import net.minecraft.server.v1_16_R1.MobSpawnerPatrol;
import net.minecraft.server.v1_16_R1.MobSpawnerPhantom;
import net.minecraft.server.v1_16_R1.MobSpawnerTrader;
import net.minecraft.server.v1_16_R1.NBTBase;
import net.minecraft.server.v1_16_R1.RegistryMaterials;
import net.minecraft.server.v1_16_R1.RegistryReadOps;
import net.minecraft.server.v1_16_R1.ResourceKey;
import net.minecraft.server.v1_16_R1.SaveData;
import net.minecraft.server.v1_16_R1.VillageSiege;
import net.minecraft.server.v1_16_R1.WorldDataServer;
import net.minecraft.server.v1_16_R1.WorldDimension;
import net.minecraft.server.v1_16_R1.WorldServer;
import net.minecraft.server.v1_16_R1.WorldSettings;
import net.minecraft.server.v1_16_R1.ChunkCoordIntPair;
import net.minecraft.server.v1_16_R1.TicketType;
import net.minecraft.server.v1_16_R1.Unit;
public class NMSCreator161
{
public static void addStartTicket(Location center, int size)
{
((CraftWorld) center.getWorld()).getHandle().getChunkProvider().addTicket(TicketType.START, new ChunkCoordIntPair(center.getBlockX() >> 4, center.getBlockZ() >> 4), size, Unit.INSTANCE);
}
@SuppressWarnings({"unchecked", "rawtypes", "resource"})
public static World createWorld(WorldCreator creator, boolean loadSpawn)
{
CraftServer server = ((CraftServer) Bukkit.getServer());
Map<String, World> worlds = new V(server).get("worlds");
DedicatedServer console = new V(server).get("console");
Preconditions.checkState(!console.worldServer.isEmpty(), (Object) "Cannot create additional worlds on STARTUP");
Validate.notNull((Object) creator, "Creator may not be null");
final String name = creator.name();
org.bukkit.generator.ChunkGenerator generator = creator.generator();
final File folder = new File(server.getWorldContainer(), name);
final World world = server.getWorld(name);
if(world != null)
{
return world;
}
if(folder.exists() && !folder.isDirectory())
{
throw new IllegalArgumentException("File exists with the name '" + name + "' and isn't a folder");
}
if(generator == null)
{
generator = server.getGenerator(name);
}
ResourceKey<WorldDimension> actualDimension = null;
switch(creator.environment())
{
case NORMAL:
{
actualDimension = (ResourceKey<WorldDimension>) WorldDimension.OVERWORLD;
break;
}
case NETHER:
{
actualDimension = (ResourceKey<WorldDimension>) WorldDimension.THE_NETHER;
break;
}
case THE_END:
{
actualDimension = (ResourceKey<WorldDimension>) WorldDimension.THE_END;
break;
}
default:
{
throw new IllegalArgumentException("Illegal dimension");
}
}
Convertable.ConversionSession worldSession;
try
{
worldSession = Convertable.a(server.getWorldContainer().toPath()).c(name, (ResourceKey) actualDimension);
}
catch(IOException ex)
{
throw new RuntimeException(ex);
}
MinecraftServer.convertWorld(worldSession);
final boolean hardcore = creator.hardcore();
final RegistryReadOps<NBTBase> registryreadops = (RegistryReadOps<NBTBase>) RegistryReadOps.a((DynamicOps) DynamicOpsNBT.a, console.dataPackResources.h(), console.f);
WorldDataServer worlddata = (WorldDataServer) worldSession.a((DynamicOps) registryreadops, console.datapackconfiguration);
if(worlddata == null)
{
final Properties properties = new Properties();
properties.put("generator-settings", Objects.toString(creator.generatorSettings()));
properties.put("level-seed", Objects.toString(creator.seed()));
properties.put("generate-structures", Objects.toString(creator.generateStructures()));
properties.put("level-type", Objects.toString(creator.type().getName()));
GeneratorSettings generatorsettings = GeneratorSettings.a((Properties) properties);
@SuppressWarnings("deprecation")
final WorldSettings worldSettings = new WorldSettings(name, EnumGamemode.getById(server.getDefaultGameMode().getValue()), hardcore, EnumDifficulty.EASY, false, new GameRules(), console.datapackconfiguration);
worlddata = new WorldDataServer(worldSettings, generatorsettings, Lifecycle.stable());
}
worlddata.checkName(name);
worlddata.a(console.getServerModName(), console.getModded().isPresent());
final long j = BiomeManager.a(creator.seed());
final List<MobSpawner> list = (List<MobSpawner>) ImmutableList.of((MobSpawner) new MobSpawnerPhantom(), (MobSpawner) new MobSpawnerPatrol(), (MobSpawner) new MobSpawnerCat(), (MobSpawner) new VillageSiege(), (MobSpawner) new MobSpawnerTrader((IWorldDataServer) worlddata));
RegistryMaterials registrymaterials = worlddata.getGeneratorSettings().e();
final WorldDimension worlddimension = (WorldDimension) registrymaterials.a((ResourceKey) actualDimension);
DimensionManager dimensionmanager;
net.minecraft.server.v1_16_R1.ChunkGenerator chunkgenerator;
if(worlddimension == null)
{
dimensionmanager = DimensionManager.a();
chunkgenerator = GeneratorSettings.a((long) new Random().nextLong());
}
else
{
dimensionmanager = worlddimension.b();
chunkgenerator = worlddimension.c();
}
ResourceKey typeKey = (ResourceKey) console.f.a().c(dimensionmanager).orElseThrow(() -> new IllegalStateException("Unregistered dimension type: " + (Object) dimensionmanager));
ResourceKey worldKey = ResourceKey.a((ResourceKey) IRegistry.ae, (MinecraftKey) new MinecraftKey(name.toLowerCase(Locale.ENGLISH)));
//@builder
WorldServer internal = new WorldServer(
(MinecraftServer)console,
console.executorService,
worldSession,
(IWorldDataServer)worlddata,
worldKey,
typeKey,
dimensionmanager,
server.getServer().worldLoadListenerFactory.create(11),
chunkgenerator,
worlddata.getGeneratorSettings().isDebugWorld(),
j,
(List)(creator.environment() == World.Environment.NORMAL ? list : ImmutableList.of()),
true,
creator.environment(),
generator);
//@done
if(!worlds.containsKey(name.toLowerCase(Locale.ENGLISH)))
{
try
{
internal.close();
}
catch(IOException e)
{
e.printStackTrace();
}
return null;
}
console.initWorld(internal, (IWorldDataServer) worlddata, (SaveData) worlddata, worlddata.getGeneratorSettings());
internal.setSpawnFlags(true, true);
console.worldServer.put(internal.getDimensionKey(), internal);
server.getPluginManager().callEvent((Event) new WorldInitEvent((World) internal.getWorld()));
if(loadSpawn)
{
server.getServer().loadSpawn(internal.getChunkProvider().playerChunkMap.worldLoadListener, internal);
}
else
{
MinecraftServer.LOGGER.info("Preparing start region for dimens... Oh wait, We don't do that here anymore.");
}
server.getPluginManager().callEvent((Event) new WorldLoadEvent((World) internal.getWorld()));
return (World) internal.getWorld();
}
}

View File

@@ -0,0 +1,16 @@
package com.volmit.iris.gen.nms.v16_2;
import com.volmit.iris.gen.atomics.AtomicCache;
import com.volmit.iris.gen.nms.INMSBinding;
import com.volmit.iris.gen.nms.INMSCreator;
public class NMSBinding16_2 implements INMSBinding
{
private final AtomicCache<INMSCreator> creator = new AtomicCache<>();
@Override
public INMSCreator getCreator()
{
return creator.aquire(() -> new NMSCreator16_2());
}
}

View File

@@ -0,0 +1,981 @@
package com.volmit.iris.gen.nms.v16_2;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.stream.IntStream;
import javax.annotation.Nullable;
import org.bukkit.Material;
import org.bukkit.block.Biome;
import org.bukkit.block.data.BlockData;
import org.bukkit.craftbukkit.v1_16_R2.block.CraftBlock;
import org.bukkit.craftbukkit.v1_16_R2.block.data.CraftBlockData;
import org.bukkit.craftbukkit.v1_16_R2.util.CraftMagicNumbers;
import org.bukkit.generator.ChunkGenerator.BiomeGrid;
import org.bukkit.generator.ChunkGenerator.ChunkData;
import org.bukkit.material.MaterialData;
import com.mojang.serialization.Codec;
import com.volmit.iris.gen.IrisTerrainProvider;
import com.volmit.iris.gen.provisions.ProvisionBukkit;
import com.volmit.iris.gen.scaffold.GeneratedChunk;
import com.volmit.iris.gen.scaffold.Provisioned;
import com.volmit.iris.util.O;
import com.volmit.iris.util.V;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import it.unimi.dsi.fastutil.objects.ObjectList;
import it.unimi.dsi.fastutil.objects.ObjectListIterator;
import net.minecraft.server.v1_16_R2.BiomeBase;
import net.minecraft.server.v1_16_R2.BiomeManager;
import net.minecraft.server.v1_16_R2.BiomeSettingsGeneration;
import net.minecraft.server.v1_16_R2.BiomeSettingsMobs;
import net.minecraft.server.v1_16_R2.Block;
import net.minecraft.server.v1_16_R2.BlockColumn;
import net.minecraft.server.v1_16_R2.BlockPosition;
import net.minecraft.server.v1_16_R2.Blocks;
import net.minecraft.server.v1_16_R2.ChunkCoordIntPair;
import net.minecraft.server.v1_16_R2.ChunkGenerator;
import net.minecraft.server.v1_16_R2.ChunkGeneratorAbstract;
import net.minecraft.server.v1_16_R2.CrashReport;
import net.minecraft.server.v1_16_R2.CrashReportSystemDetails;
import net.minecraft.server.v1_16_R2.DefinedStructureManager;
import net.minecraft.server.v1_16_R2.EnumCreatureType;
import net.minecraft.server.v1_16_R2.GeneratorAccess;
import net.minecraft.server.v1_16_R2.GeneratorAccessSeed;
import net.minecraft.server.v1_16_R2.GeneratorSettingBase;
import net.minecraft.server.v1_16_R2.HeightMap;
import net.minecraft.server.v1_16_R2.IBlockAccess;
import net.minecraft.server.v1_16_R2.IBlockData;
import net.minecraft.server.v1_16_R2.IChunkAccess;
import net.minecraft.server.v1_16_R2.IRegistry;
import net.minecraft.server.v1_16_R2.IRegistryCustom;
import net.minecraft.server.v1_16_R2.IStructureAccess;
import net.minecraft.server.v1_16_R2.MathHelper;
import net.minecraft.server.v1_16_R2.NoiseGenerator;
import net.minecraft.server.v1_16_R2.NoiseGenerator3;
import net.minecraft.server.v1_16_R2.NoiseGenerator3Handler;
import net.minecraft.server.v1_16_R2.NoiseGeneratorOctaves;
import net.minecraft.server.v1_16_R2.NoiseGeneratorPerlin;
import net.minecraft.server.v1_16_R2.NoiseSettings;
import net.minecraft.server.v1_16_R2.PacketDebug;
import net.minecraft.server.v1_16_R2.ProtoChunk;
import net.minecraft.server.v1_16_R2.RegionLimitedWorldAccess;
import net.minecraft.server.v1_16_R2.ReportedException;
import net.minecraft.server.v1_16_R2.ResourceKey;
import net.minecraft.server.v1_16_R2.SectionPosition;
import net.minecraft.server.v1_16_R2.SeededRandom;
import net.minecraft.server.v1_16_R2.SpawnerCreature;
import net.minecraft.server.v1_16_R2.StructureBoundingBox;
import net.minecraft.server.v1_16_R2.StructureFeature;
import net.minecraft.server.v1_16_R2.StructureFeatures;
import net.minecraft.server.v1_16_R2.StructureGenerator;
import net.minecraft.server.v1_16_R2.StructureManager;
import net.minecraft.server.v1_16_R2.StructurePiece;
import net.minecraft.server.v1_16_R2.StructureSettingsFeature;
import net.minecraft.server.v1_16_R2.StructureStart;
import net.minecraft.server.v1_16_R2.SystemUtils;
import net.minecraft.server.v1_16_R2.WorldChunkManager;
import net.minecraft.server.v1_16_R2.WorldChunkManagerTheEnd;
import net.minecraft.server.v1_16_R2.WorldGenFeatureConfigured;
import net.minecraft.server.v1_16_R2.WorldGenFeatureDefinedStructureJigsawJunction;
import net.minecraft.server.v1_16_R2.WorldGenFeatureDefinedStructurePoolTemplate;
import net.minecraft.server.v1_16_R2.WorldGenFeaturePillagerOutpostPoolPiece;
import net.minecraft.server.v1_16_R2.WorldGenStage;
import net.minecraft.server.v1_16_R2.WorldServer;
public class NMSChunkGenerator16_2 extends ChunkGenerator
{
private static final float[] i = SystemUtils.a((new float[13824]), (afloat) ->
{ // CraftBukkit - decompile error
for(int i = 0; i < 24; ++i)
{
for(int j = 0; j < 24; ++j)
{
for(int k = 0; k < 24; ++k)
{
afloat[i * 24 * 24 + j * 24 + k] = (float) b(j - 12, k - 12, i - 12);
}
}
}
});
private static final float[] j = SystemUtils.a((new float[25]), (afloat) ->
{ // CraftBukkit - decompile error
for(int i = -2; i <= 2; ++i)
{
for(int j = -2; j <= 2; ++j)
{
float f = 10.0F / MathHelper.c((float) (i * i + j * j) + 0.2F);
afloat[i + 2 + (j + 2) * 5] = f;
}
}
});
private static final IBlockData k = Blocks.AIR.getBlockData();
private final Provisioned provisioned;
private final int maxHeight;
private final int m;
private final int n;
private final int xzSize;
private final int p;
protected final SeededRandom e;
private final NoiseGeneratorOctaves q;
private final NoiseGeneratorOctaves r;
private final NoiseGeneratorOctaves s;
private final NoiseGenerator t;
private final NoiseGeneratorOctaves u;
private final NoiseGenerator3Handler v;
protected final IBlockData f;
protected final IBlockData g;
private final long w;
protected final Supplier<GeneratorSettingBase> h;
private final O<WorldServer> ws;
public NMSChunkGenerator16_2(Provisioned p, O<WorldServer> ws, WorldChunkManager worldchunkmanager, long i, Supplier<GeneratorSettingBase> supplier)
{
this(p, ws, worldchunkmanager, worldchunkmanager, i, supplier);
}
private NMSChunkGenerator16_2(Provisioned p, O<WorldServer> ws, WorldChunkManager worldchunkmanager, WorldChunkManager worldchunkmanager1, long i, Supplier<GeneratorSettingBase> supplier)
{
super(worldchunkmanager, worldchunkmanager1, supplier.get().a(), i);
this.provisioned = p;
this.ws = ws;
this.w = i;
GeneratorSettingBase generatorsettingbase = supplier.get();
this.h = supplier;
NoiseSettings noisesettings = generatorsettingbase.b();
this.maxHeight = noisesettings.f() * 4;
this.m = noisesettings.e() * 4;
this.f = generatorsettingbase.c();
this.g = generatorsettingbase.d();
this.n = 16 / this.m;
this.xzSize = noisesettings.a() / this.maxHeight;
this.p = 16 / this.m;
this.e = new SeededRandom(i);
this.q = new NoiseGeneratorOctaves(this.e, IntStream.rangeClosed(-15, 0));
this.r = new NoiseGeneratorOctaves(this.e, IntStream.rangeClosed(-15, 0));
this.s = new NoiseGeneratorOctaves(this.e, IntStream.rangeClosed(-7, 0));
this.t = (NoiseGenerator) (noisesettings.i() ? new NoiseGenerator3(this.e, IntStream.rangeClosed(-3, 0)) : new NoiseGeneratorOctaves(this.e, IntStream.rangeClosed(-3, 0)));
this.e.a(2620);
this.u = new NoiseGeneratorOctaves(this.e, IntStream.rangeClosed(-15, 0));
if(noisesettings.k())
{
SeededRandom seededrandom = new SeededRandom(i);
seededrandom.a(17292);
this.v = new NoiseGenerator3Handler(seededrandom);
}
else
{
this.v = null;
}
}
public int getSpawnHeight()
{
return getSeaLevel() + 8;
}
public WorldChunkManager getWorldChunkManager()
{
return this.c;
}
public int getGenerationDepth()
{
return 256;
}
public void doCarving(long i, BiomeManager biomemanager, IChunkAccess ichunkaccess, WorldGenStage.Features worldgenstage_features)
{
if(((IrisTerrainProvider) provisioned.getProvider()).getDimension().isVanillaCaves())
{
super.doCarving(i, biomemanager, ichunkaccess, worldgenstage_features);
}
}
@Override
protected Codec<? extends ChunkGenerator> a()
{
return ChunkGeneratorAbstract.d;
}
public boolean a(long i, ResourceKey<GeneratorSettingBase> resourcekey)
{
return this.w == i && this.h.get().a(resourcekey);
}
private double a(int i, int j, int k, double d0, double d1, double d2, double d3)
{
double d4 = 0.0D;
double d5 = 0.0D;
double d6 = 0.0D;
double d7 = 1.0D;
for(int l = 0; l < 16; ++l)
{
double d8 = NoiseGeneratorOctaves.a((double) i * d0 * d7);
double d9 = NoiseGeneratorOctaves.a((double) j * d1 * d7);
double d10 = NoiseGeneratorOctaves.a((double) k * d0 * d7);
double d11 = d1 * d7;
NoiseGeneratorPerlin noisegeneratorperlin = this.q.a(l);
if(noisegeneratorperlin != null)
{
d4 += noisegeneratorperlin.a(d8, d9, d10, d11, (double) j * d11) / d7;
}
NoiseGeneratorPerlin noisegeneratorperlin1 = this.r.a(l);
if(noisegeneratorperlin1 != null)
{
d5 += noisegeneratorperlin1.a(d8, d9, d10, d11, (double) j * d11) / d7;
}
if(l < 8)
{
NoiseGeneratorPerlin noisegeneratorperlin2 = this.s.a(l);
if(noisegeneratorperlin2 != null)
{
d6 += noisegeneratorperlin2.a(NoiseGeneratorOctaves.a((double) i * d2 * d7), NoiseGeneratorOctaves.a((double) j * d3 * d7), NoiseGeneratorOctaves.a((double) k * d2 * d7), d3 * d7, (double) j * d3 * d7) / d7;
}
}
d7 /= 2.0D;
}
return MathHelper.b(d4 / 512.0D, d5 / 512.0D, (d6 / 10.0D + 1.0D) / 2.0D);
}
private double[] getFilledNoiseArray(int x, int z)
{
double[] noiseArray = new double[this.xzSize + 1];
this.fillNoiseArray(noiseArray, x, z);
return noiseArray;
}
private void fillNoiseArray(double[] noiseArray, int x, int z)
{
NoiseSettings noisesettings = this.h.get().b();
double d0;
double d1;
double d2;
double d3;
if(this.v != null)
{
d0 = (double) (WorldChunkManagerTheEnd.a(this.v, x, z) - 8.0F);
if(d0 > 0.0D)
{
d1 = 0.25D;
}
else
{
d1 = 1.0D;
}
}
else
{
float f = 0.0F;
float f1 = 0.0F;
float f2 = 0.0F;
int k = this.getSeaLevel();
float f3 = this.b.getBiome(x, k, z).h();
for(int l = -2; l <= 2; ++l)
{
for(int i1 = -2; i1 <= 2; ++i1)
{
BiomeBase biomebase = this.b.getBiome(x + l, k, z + i1);
float f4 = biomebase.h();
float f5 = biomebase.j();
float f6;
float f7;
if(noisesettings.l() && f4 > 0.0F)
{
f6 = 1.0F + f4 * 2.0F;
f7 = 1.0F + f5 * 4.0F;
}
else
{
f6 = f4;
f7 = f5;
}
// CraftBukkit start - fix MC-54738
if(f6 < -1.8F)
{
f6 = -1.8F;
}
// CraftBukkit end
float f8 = f4 > f3 ? 0.5F : 1.0F;
float f9 = f8 * NMSChunkGenerator16_2.j[l + 2 + (i1 + 2) * 5] / (f6 + 2.0F);
f += f7 * f9;
f1 += f6 * f9;
f2 += f9;
}
}
float f10 = f1 / f2;
float f11 = f / f2;
d2 = (double) (f10 * 0.5F - 0.125F);
d3 = (double) (f11 * 0.9F + 0.1F);
d0 = d2 * 0.265625D;
d1 = 96.0D / d3;
}
double d4 = 684.412D * noisesettings.b().a();
double d5 = 684.412D * noisesettings.b().b();
double d6 = d4 / noisesettings.b().c();
double d7 = d5 / noisesettings.b().d();
d2 = (double) noisesettings.c().a();
d3 = (double) noisesettings.c().b();
double d8 = (double) noisesettings.c().c();
double d9 = (double) noisesettings.d().a();
double d10 = (double) noisesettings.d().b();
double d11 = (double) noisesettings.d().c();
double d12 = noisesettings.j() ? this.c(x, z) : 0.0D;
double d13 = noisesettings.g();
double d14 = noisesettings.h();
for(int j1 = 0; j1 <= this.xzSize; ++j1)
{
double d15 = this.a(x, j1, z, d4, d5, d6, d7);
double d16 = 1.0D - (double) j1 * 2.0D / (double) this.xzSize + d12;
double d17 = d16 * d13 + d14;
double d18 = (d17 + d0) * d1;
if(d18 > 0.0D)
{
d15 += d18 * 4.0D;
}
else
{
d15 += d18;
}
double d19;
if(d3 > 0.0D)
{
d19 = ((double) (this.xzSize - j1) - d8) / d3;
d15 = MathHelper.b(d2, d15, d19);
}
if(d10 > 0.0D)
{
d19 = ((double) j1 - d11) / d10;
d15 = MathHelper.b(d9, d15, d19);
}
noiseArray[j1] = d15;
}
}
private double c(int x, int z)
{
double noiseOrSomething = this.u.a((double) (x * 200), 10.0D, (double) (z * 200), 1.0D, 0.0D, true);
double noiseOrSomething2;
if(noiseOrSomething < 0.0D)
{
noiseOrSomething2 = -noiseOrSomething * 0.3D;
}
else
{
noiseOrSomething2 = noiseOrSomething;
}
double result = noiseOrSomething2 * 24.575625D - 2.0D;
return result < 0.0D ? result * 0.009486607142857142D : Math.min(result, 1.0D) * 0.006640625D;
}
@Override
public int getBaseHeight(int i, int j, HeightMap.Type heightmap_type)
{
return this.a(i, j, (IBlockData[]) null, heightmap_type.e());
}
@Override
public IBlockAccess a(int x, int z)
{
IBlockData[] aiblockdata = new IBlockData[this.xzSize * this.maxHeight];
this.a(x, z, aiblockdata, (Predicate<IBlockData>) null);
return new BlockColumn(aiblockdata);
}
private int a(int i, int j, @Nullable IBlockData[] aiblockdata, @Nullable Predicate<IBlockData> predicate)
{
int k = Math.floorDiv(i, this.m);
int l = Math.floorDiv(j, this.m);
int i1 = Math.floorMod(i, this.m);
int j1 = Math.floorMod(j, this.m);
double d0 = (double) i1 / (double) this.m;
double d1 = (double) j1 / (double) this.m;
double[][] noiseArrayNeighbors = new double[][] {this.getFilledNoiseArray(k, l), this.getFilledNoiseArray(k, l + 1), this.getFilledNoiseArray(k + 1, l), this.getFilledNoiseArray(k + 1, l + 1)};
for(int k1 = this.xzSize - 1; k1 >= 0; --k1)
{
double d2 = noiseArrayNeighbors[0][k1];
double d3 = noiseArrayNeighbors[1][k1];
double d4 = noiseArrayNeighbors[2][k1];
double d5 = noiseArrayNeighbors[3][k1];
double d6 = noiseArrayNeighbors[0][k1 + 1];
double d7 = noiseArrayNeighbors[1][k1 + 1];
double d8 = noiseArrayNeighbors[2][k1 + 1];
double d9 = noiseArrayNeighbors[3][k1 + 1];
for(int l1 = this.maxHeight - 1; l1 >= 0; --l1)
{
double d10 = (double) l1 / (double) this.maxHeight;
double d11 = MathHelper.a(d10, d0, d1, d2, d6, d4, d8, d3, d7, d5, d9);
int i2 = k1 * this.maxHeight + l1;
IBlockData iblockdata = this.a(d11, i2);
if(aiblockdata != null)
{
aiblockdata[i2] = iblockdata;
}
if(predicate != null && predicate.test(iblockdata))
{
return i2 + 1;
}
}
}
return 0;
}
protected IBlockData a(double d0, int i)
{
IBlockData iblockdata;
if(d0 > 0.0D)
{
iblockdata = this.f;
}
else if(i < this.getSeaLevel())
{
iblockdata = this.g;
}
else
{
iblockdata = NMSChunkGenerator16_2.k;
}
return iblockdata;
}
@Override
public void buildBase(RegionLimitedWorldAccess regionlimitedworldaccess, IChunkAccess ichunkaccess)
{
}
@Override
public void buildNoise(GeneratorAccess generatoraccess, StructureManager structuremanager, IChunkAccess ichunkaccess)
{
ObjectList<StructurePiece> objectlist = new ObjectArrayList<StructurePiece>(10);
ObjectList<WorldGenFeatureDefinedStructureJigsawJunction> objectlist1 = new ObjectArrayList<WorldGenFeatureDefinedStructureJigsawJunction>(32);
ChunkCoordIntPair chunkcoordintpair = ichunkaccess.getPos();
int i = chunkcoordintpair.x;
int j = chunkcoordintpair.z;
if(((IrisTerrainProvider) provisioned.getProvider()).shouldGenerateVanillaStructures())
{
int k = i << 4;
int l = j << 4;
Iterator<?> iterator = StructureGenerator.t.iterator();
while(iterator.hasNext())
{
StructureGenerator<?> structuregenerator = (StructureGenerator<?>) iterator.next();
structuremanager.a(SectionPosition.a(chunkcoordintpair, 0), structuregenerator).forEach((structurestart) ->
{
Iterator<?> iterator1 = structurestart.d().iterator();
while(iterator1.hasNext())
{
StructurePiece structurepiece = (StructurePiece) iterator1.next();
if(structurepiece.a(chunkcoordintpair, 12))
{
if(structurepiece instanceof WorldGenFeaturePillagerOutpostPoolPiece)
{
WorldGenFeaturePillagerOutpostPoolPiece worldgenfeaturepillageroutpostpoolpiece = (WorldGenFeaturePillagerOutpostPoolPiece) structurepiece;
WorldGenFeatureDefinedStructurePoolTemplate.Matching worldgenfeaturedefinedstructurepooltemplate_matching = worldgenfeaturepillageroutpostpoolpiece.b().e();
if(worldgenfeaturedefinedstructurepooltemplate_matching == WorldGenFeatureDefinedStructurePoolTemplate.Matching.RIGID)
{
objectlist.add(worldgenfeaturepillageroutpostpoolpiece);
}
Iterator<?> iterator2 = worldgenfeaturepillageroutpostpoolpiece.e().iterator();
while(iterator2.hasNext())
{
WorldGenFeatureDefinedStructureJigsawJunction worldgenfeaturedefinedstructurejigsawjunction = (WorldGenFeatureDefinedStructureJigsawJunction) iterator2.next();
int i1 = worldgenfeaturedefinedstructurejigsawjunction.a();
int j1 = worldgenfeaturedefinedstructurejigsawjunction.c();
if(i1 > k - 12 && j1 > l - 12 && i1 < k + 15 + 12 && j1 < l + 15 + 12)
{
objectlist1.add(worldgenfeaturedefinedstructurejigsawjunction);
}
}
}
else
{
objectlist.add(structurepiece);
}
}
}
});
}
}
ProtoChunk protochunk = (ProtoChunk) ichunkaccess;
HeightMap heightmap = protochunk.a(HeightMap.Type.OCEAN_FLOOR_WG);
HeightMap heightmap1 = protochunk.a(HeightMap.Type.WORLD_SURFACE_WG);
BlockPosition.MutableBlockPosition blockposition_mutableblockposition = new BlockPosition.MutableBlockPosition();
ObjectListIterator<StructurePiece> objectlistiterator = objectlist.iterator();
ObjectListIterator<WorldGenFeatureDefinedStructureJigsawJunction> objectlistiterator1 = objectlist1.iterator();
GeneratedChunk gc = ((ProvisionBukkit) provisioned).generateNMSChunkData(ws.get().getWorld(), new Random(i + j), i, j, new ChunkData()
{
public int getMaxHeight()
{
return 256;
}
public void setBlock(int x, int y, int z, Material material)
{
this.setBlock(x, y, z, material.createBlockData());
}
@SuppressWarnings("deprecation")
public void setBlock(int x, int y, int z, MaterialData material)
{
this.setBlock(x, y, z, CraftMagicNumbers.getBlock((MaterialData) material));
}
public void setBlock(int x, int y, int z, BlockData blockData)
{
this.setBlock(x, y, z, ((CraftBlockData) blockData).getState());
}
public void setRegion(int xMin, int yMin, int zMin, int xMax, int yMax, int zMax, Material material)
{
this.setRegion(xMin, yMin, zMin, xMax, yMax, zMax, material.createBlockData());
}
@SuppressWarnings("deprecation")
public void setRegion(int xMin, int yMin, int zMin, int xMax, int yMax, int zMax, MaterialData material)
{
this.setRegion(xMin, yMin, zMin, xMax, yMax, zMax, CraftMagicNumbers.getBlock((MaterialData) material));
}
public void setRegion(int xMin, int yMin, int zMin, int xMax, int yMax, int zMax, BlockData blockData)
{
this.setRegion(xMin, yMin, zMin, xMax, yMax, zMax, ((CraftBlockData) blockData).getState());
}
public Material getType(int x, int y, int z)
{
return CraftMagicNumbers.getMaterial((Block) this.getTypeId(x, y, z).getBlock());
}
@SuppressWarnings("deprecation")
public MaterialData getTypeAndData(int x, int y, int z)
{
return CraftMagicNumbers.getMaterial((IBlockData) this.getTypeId(x, y, z));
}
public BlockData getBlockData(int x, int y, int z)
{
return CraftBlockData.fromData((IBlockData) this.getTypeId(x, y, z));
}
public void setRegion(int xMin, int yMin, int zMin, int xMax, int yMax, int zMax, IBlockData type)
{
if(xMin > 15 || yMin >= getMaxHeight() || zMin > 15)
{
return;
}
if(xMin < 0)
{
xMin = 0;
}
if(yMin < 0)
{
yMin = 0;
}
if(zMin < 0)
{
zMin = 0;
}
if(xMax > 16)
{
xMax = 16;
}
if(yMax > getMaxHeight())
{
yMax = getMaxHeight();
}
if(zMax > 16)
{
zMax = 16;
}
if(xMin >= xMax || yMin >= yMax || zMin >= zMax)
{
return;
}
int y = yMin;
while(y < yMax)
{
int x = xMin;
while(x < xMax)
{
int z = zMin;
while(z < zMax)
{
protochunk.setType(new BlockPosition(x, y, z), type, false);
++z;
}
++x;
}
++y;
}
}
public IBlockData getTypeId(int x, int y, int z)
{
if(x != (x & 15) || y < 0 || y >= getMaxHeight() || z != (z & 15))
{
return Blocks.AIR.getBlockData();
}
return protochunk.getType(new BlockPosition(x, y, z));
}
public byte getData(int x, int y, int z)
{
return CraftMagicNumbers.toLegacyData((IBlockData) this.getTypeId(x, y, z));
}
private void setBlock(int x, int y, int z, IBlockData type)
{
if(x != (x & 15) || y < 0 || y >= getMaxHeight() || z != (z & 15))
{
return;
}
protochunk.setType(new BlockPosition(x, y, z), type, false);
if(type.getBlock().isTileEntity())
{
// if (this.tiles == null) {
// this.tiles = new HashSet<BlockPosition>();
// }
// this.tiles.add(new BlockPosition(x, y, z));
}
}
}, new BiomeGrid()
{
@Override
public void setBiome(int x, int y, int z, Biome bio)
{
protochunk.getBiomeIndex().setBiome(x, y, z, CraftBlock.biomeToBiomeBase(ws.get().r().b(IRegistry.ay), bio));
}
@Override
public void setBiome(int x, int z, Biome bio)
{
protochunk.getBiomeIndex().setBiome(x, 0, z, CraftBlock.biomeToBiomeBase(ws.get().r().b(IRegistry.ay), bio));
}
@Override
public Biome getBiome(int x, int y, int z)
{
return CraftBlock.biomeBaseToBiome(ws.get().r().b(IRegistry.ay), protochunk.getBiomeIndex().getBiome(x, y, z));
}
@Override
public Biome getBiome(int x, int z)
{
return CraftBlock.biomeBaseToBiome(ws.get().r().b(IRegistry.ay), protochunk.getBiomeIndex().getBiome(x, 0, z));
}
});
for(int xx = 0; xx < 16; xx++)
{
for(int zz = 0; zz < 16; zz++)
{
int y = gc.getHeight().getHeight(xx, zz);
if(y < getSeaLevel())
{
heightmap.a(xx, y, zz, Blocks.STONE.getBlockData());
}
heightmap1.a(xx, Math.max(y, getSeaLevel()), zz, Blocks.STONE.getBlockData());
}
}
}
public void addDecorations(RegionLimitedWorldAccess regionlimitedworldaccess, StructureManager structuremanager)
{
if(((IrisTerrainProvider) provisioned.getProvider()).shouldGenerateVanillaStructures())
{
int i = regionlimitedworldaccess.a();
int j = regionlimitedworldaccess.b();
int k = i * 16;
int l = j * 16;
BlockPosition blockposition = new BlockPosition(k, 0, l);
BiomeBase biomebase = this.b.getBiome((i << 2) + 2, 2, (j << 2) + 2);
SeededRandom seededrandom = new SeededRandom();
long i1 = seededrandom.a(regionlimitedworldaccess.getSeed(), k, l);
try
{
a(biomebase, structuremanager, this, regionlimitedworldaccess, i1, seededrandom, blockposition);
}
catch(Exception exception)
{
}
}
}
public void a(BiomeBase bbase, StructureManager var0, ChunkGenerator var1, RegionLimitedWorldAccess var2, long var3, SeededRandom var5, BlockPosition var6)
{
if(!((IrisTerrainProvider) provisioned.getProvider()).shouldGenerateVanillaStructures())
{
return;
}
int stages = WorldGenStage.Decoration.values().length;
for(int stage = 0; stage < stages; ++stage)
{
WorldGenStage.Decoration st = WorldGenStage.Decoration.values()[stage];
if(st.equals(WorldGenStage.Decoration.LAKES))
{
continue;
}
if(st.equals(WorldGenStage.Decoration.LOCAL_MODIFICATIONS))
{
continue;
}
if(st.equals(WorldGenStage.Decoration.RAW_GENERATION))
{
continue;
}
if(st.equals(WorldGenStage.Decoration.TOP_LAYER_MODIFICATION))
{
continue;
}
if(st.equals(WorldGenStage.Decoration.UNDERGROUND_DECORATION))
{
continue;
}
if(st.equals(WorldGenStage.Decoration.UNDERGROUND_ORES))
{
continue;
}
if(st.equals(WorldGenStage.Decoration.VEGETAL_DECORATION))
{
continue;
}
StructureGenerator<?> var13;
int var10 = 0;
if(var0.a())
{
@SuppressWarnings("unchecked")
List<StructureGenerator<?>> structureGenerators = ((Map<Integer, List<StructureGenerator<?>>>) new V(bbase).get("g")).getOrDefault(stage, Collections.emptyList());
Iterator<StructureGenerator<?>> iterator = structureGenerators.iterator();
while(iterator.hasNext())
{
var13 = (StructureGenerator<?>) iterator.next();
var5.b(var3, var10, stage);
int var14 = var6.getX() >> 4;
int var15 = var6.getZ() >> 4;
int var16 = var14 << 4;
int var17 = var15 << 4;
try
{
var0.a(SectionPosition.a((BlockPosition) var6), var13).forEach(var8 -> var8.a((GeneratorAccessSeed) var2, var0, var1, (Random) var5, new StructureBoundingBox(var16, var17, var16 + 15, var17 + 15), new ChunkCoordIntPair(var14, var15)));
}
catch(Exception var18)
{
}
++var10;
}
}
}
}
private static double b(int i, int j, int k)
{
double d0 = (double) (i * i + k * k);
double d1 = (double) j + 0.5D;
double d2 = d1 * d1;
double d3 = Math.pow(2.718281828459045D, -(d2 / 16.0D + d0 / 16.0D));
double d4 = -d1 * MathHelper.i(d2 / 2.0D + d0 / 2.0D) / 2.0D;
return d4 * d3;
}
@Override
public int getSeaLevel()
{
return ((IrisTerrainProvider) provisioned.getProvider()).getFluidHeight();
}
@Override
public List<BiomeSettingsMobs.c> getMobsFor(BiomeBase biomebase, StructureManager structuremanager, EnumCreatureType enumcreaturetype, BlockPosition blockposition)
{
if(structuremanager.a(blockposition, true, StructureGenerator.SWAMP_HUT).e())
{
if(enumcreaturetype == EnumCreatureType.MONSTER)
{
return StructureGenerator.SWAMP_HUT.c();
}
if(enumcreaturetype == EnumCreatureType.CREATURE)
{
return StructureGenerator.SWAMP_HUT.j();
}
}
if(enumcreaturetype == EnumCreatureType.MONSTER)
{
if(structuremanager.a(blockposition, false, StructureGenerator.PILLAGER_OUTPOST).e())
{
return StructureGenerator.PILLAGER_OUTPOST.c();
}
if(structuremanager.a(blockposition, false, StructureGenerator.MONUMENT).e())
{
return StructureGenerator.MONUMENT.c();
}
if(structuremanager.a(blockposition, true, StructureGenerator.FORTRESS).e())
{
return StructureGenerator.FORTRESS.c();
}
}
return super.getMobsFor(biomebase, structuremanager, enumcreaturetype, blockposition);
}
@Override
public void addMobs(RegionLimitedWorldAccess regionlimitedworldaccess)
{
int i = regionlimitedworldaccess.a();
int j = regionlimitedworldaccess.b();
BiomeBase biomebase = regionlimitedworldaccess.getBiome((new ChunkCoordIntPair(i, j)).l());
SeededRandom seededrandom = new SeededRandom();
seededrandom.a(regionlimitedworldaccess.getSeed(), i << 4, j << 4);
SpawnerCreature.a(regionlimitedworldaccess, biomebase, i, j, seededrandom);
}
public void createStructures(IRegistryCustom iregistrycustom, StructureManager structuremanager, IChunkAccess ichunkaccess, DefinedStructureManager definedstructuremanager, long i)
{
ChunkCoordIntPair chunkcoordintpair = ichunkaccess.getPos();
BiomeBase biomebase = this.b.getBiome((chunkcoordintpair.x << 2) + 2, 0, (chunkcoordintpair.z << 2) + 2);
this.a(StructureFeatures.k, iregistrycustom, structuremanager, ichunkaccess, definedstructuremanager, i, chunkcoordintpair, biomebase);
for(Supplier supplier : biomebase.e().a())
{
StructureFeature structurefeature = (StructureFeature) supplier.get();
if(StructureFeature.c == StructureGenerator.STRONGHOLD)
{
StructureFeature structureFeature = structurefeature;
synchronized(structureFeature)
{
this.a(structurefeature, iregistrycustom, structuremanager, ichunkaccess, definedstructuremanager, i, chunkcoordintpair, biomebase);
continue;
}
}
this.a(structurefeature, iregistrycustom, structuremanager, ichunkaccess, definedstructuremanager, i, chunkcoordintpair, biomebase);
}
}
private void a(StructureFeature<?, ?> structurefeature, IRegistryCustom iregistrycustom, StructureManager structuremanager, IChunkAccess ichunkaccess, DefinedStructureManager definedstructuremanager, long i, ChunkCoordIntPair chunkcoordintpair, BiomeBase biomebase)
{
StructureStart structurestart = structuremanager.a(SectionPosition.a((ChunkCoordIntPair) ichunkaccess.getPos(), (int) 0), structurefeature.d, (IStructureAccess) ichunkaccess);
int j = structurestart != null ? structurestart.j() : 0;
StructureSettingsFeature structuresettingsfeature = getSettings().a(structurefeature.d);
if(structuresettingsfeature != null)
{
StructureStart structurestart1 = structurefeature.a(iregistrycustom, this, this.b, definedstructuremanager, i, chunkcoordintpair, biomebase, j, structuresettingsfeature);
structuremanager.a(SectionPosition.a((ChunkCoordIntPair) ichunkaccess.getPos(), (int) 0), structurefeature.d, structurestart1, (IStructureAccess) ichunkaccess);
}
}
public void storeStructures(GeneratorAccessSeed generatoraccessseed, StructureManager structuremanager, IChunkAccess ichunkaccess)
{
boolean flag = true;
int i = ichunkaccess.getPos().x;
int j = ichunkaccess.getPos().z;
int k = i << 4;
int l = j << 4;
SectionPosition sectionposition = SectionPosition.a((ChunkCoordIntPair) ichunkaccess.getPos(), (int) 0);
int i1 = i - 8;
while(i1 <= i + 8)
{
int j1 = j - 8;
while(j1 <= j + 8)
{
long k1 = ChunkCoordIntPair.pair((int) i1, (int) j1);
for(StructureStart structurestart : generatoraccessseed.getChunkAt(i1, j1).h().values())
{
try
{
if(structurestart == StructureStart.a || !structurestart.c().a(k, l, k + 15, l + 15))
continue;
structuremanager.a(sectionposition, structurestart.l(), k1, (IStructureAccess) ichunkaccess);
PacketDebug.a((GeneratorAccessSeed) generatoraccessseed, (StructureStart) structurestart);
}
catch(Exception exception)
{
CrashReport crashreport = CrashReport.a((Throwable) exception, (String) "Generating structure reference");
CrashReportSystemDetails crashreportsystemdetails = crashreport.a("Structure");
crashreportsystemdetails.a("Name", () -> structurestart.l().i());
crashreportsystemdetails.a("Class", () -> structurestart.l().getClass().getCanonicalName());
throw new ReportedException(crashreport);
}
}
++j1;
}
++i1;
}
}
}

View File

@@ -0,0 +1,793 @@
package com.volmit.iris.gen.nms.v16_2;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.stream.IntStream;
import javax.annotation.Nullable;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import it.unimi.dsi.fastutil.objects.ObjectList;
import it.unimi.dsi.fastutil.objects.ObjectListIterator;
import net.minecraft.server.v1_16_R2.BiomeBase;
import net.minecraft.server.v1_16_R2.BiomeSettingsMobs;
import net.minecraft.server.v1_16_R2.BlockColumn;
import net.minecraft.server.v1_16_R2.BlockPosition;
import net.minecraft.server.v1_16_R2.Blocks;
import net.minecraft.server.v1_16_R2.ChunkCoordIntPair;
import net.minecraft.server.v1_16_R2.ChunkGenerator;
import net.minecraft.server.v1_16_R2.ChunkGeneratorAbstract;
import net.minecraft.server.v1_16_R2.ChunkSection;
import net.minecraft.server.v1_16_R2.EnumCreatureType;
import net.minecraft.server.v1_16_R2.GeneratorAccess;
import net.minecraft.server.v1_16_R2.GeneratorSettingBase;
import net.minecraft.server.v1_16_R2.HeightMap;
import net.minecraft.server.v1_16_R2.IBlockAccess;
import net.minecraft.server.v1_16_R2.IBlockData;
import net.minecraft.server.v1_16_R2.IChunkAccess;
import net.minecraft.server.v1_16_R2.MathHelper;
import net.minecraft.server.v1_16_R2.NoiseGenerator;
import net.minecraft.server.v1_16_R2.NoiseGenerator3;
import net.minecraft.server.v1_16_R2.NoiseGenerator3Handler;
import net.minecraft.server.v1_16_R2.NoiseGeneratorOctaves;
import net.minecraft.server.v1_16_R2.NoiseGeneratorPerlin;
import net.minecraft.server.v1_16_R2.NoiseSettings;
import net.minecraft.server.v1_16_R2.ProtoChunk;
import net.minecraft.server.v1_16_R2.RegionLimitedWorldAccess;
import net.minecraft.server.v1_16_R2.ResourceKey;
import net.minecraft.server.v1_16_R2.SectionPosition;
import net.minecraft.server.v1_16_R2.SeededRandom;
import net.minecraft.server.v1_16_R2.SpawnerCreature;
import net.minecraft.server.v1_16_R2.StructureBoundingBox;
import net.minecraft.server.v1_16_R2.StructureGenerator;
import net.minecraft.server.v1_16_R2.StructureManager;
import net.minecraft.server.v1_16_R2.StructurePiece;
import net.minecraft.server.v1_16_R2.SystemUtils;
import net.minecraft.server.v1_16_R2.WorldChunkManager;
import net.minecraft.server.v1_16_R2.WorldChunkManagerTheEnd;
import net.minecraft.server.v1_16_R2.WorldGenFeatureDefinedStructureJigsawJunction;
import net.minecraft.server.v1_16_R2.WorldGenFeatureDefinedStructurePoolTemplate;
import net.minecraft.server.v1_16_R2.WorldGenFeaturePillagerOutpostPoolPiece;
public class NMSChunkGenerator16_2_BACKUP extends ChunkGenerator
{
//@builder
public static final Codec<NMSChunkGenerator16_2_BACKUP> d = RecordCodecBuilder.create((instance) -> {
return instance.group(WorldChunkManager.a.fieldOf("biome_source").forGetter((chunkgeneratorabstract) -> {
return chunkgeneratorabstract.b;
}), Codec.LONG.fieldOf("seed").stable().forGetter((chunkgeneratorabstract) -> {
return chunkgeneratorabstract.w;
}), GeneratorSettingBase.b.fieldOf("settings").forGetter((chunkgeneratorabstract) -> {
return chunkgeneratorabstract.h;
})).apply(instance, instance.stable(NMSChunkGenerator16_2_BACKUP::new));
});
//@done
private static final float[] i = SystemUtils.a((new float[13824]), (afloat) ->
{ // CraftBukkit - decompile error
for(int i = 0; i < 24; ++i)
{
for(int j = 0; j < 24; ++j)
{
for(int k = 0; k < 24; ++k)
{
afloat[i * 24 * 24 + j * 24 + k] = (float) b(j - 12, k - 12, i - 12);
}
}
}
});
private static final float[] j = SystemUtils.a((new float[25]), (afloat) ->
{ // CraftBukkit - decompile error
for(int i = -2; i <= 2; ++i)
{
for(int j = -2; j <= 2; ++j)
{
float f = 10.0F / MathHelper.c((float) (i * i + j * j) + 0.2F);
afloat[i + 2 + (j + 2) * 5] = f;
}
}
});
private static final IBlockData k = Blocks.AIR.getBlockData();
private final int l;
private final int m;
private final int n;
private final int o;
private final int p;
protected final SeededRandom e;
private final NoiseGeneratorOctaves q;
private final NoiseGeneratorOctaves r;
private final NoiseGeneratorOctaves s;
private final NoiseGenerator t;
private final NoiseGeneratorOctaves u;
private final NoiseGenerator3Handler v;
protected final IBlockData f;
protected final IBlockData g;
private final long w;
protected final Supplier<GeneratorSettingBase> h;
private final int x;
public NMSChunkGenerator16_2_BACKUP(WorldChunkManager worldchunkmanager, long i, Supplier<GeneratorSettingBase> supplier)
{
this(worldchunkmanager, worldchunkmanager, i, supplier);
}
private NMSChunkGenerator16_2_BACKUP(WorldChunkManager worldchunkmanager, WorldChunkManager worldchunkmanager1, long i, Supplier<GeneratorSettingBase> supplier)
{
super(worldchunkmanager, worldchunkmanager1, supplier.get().a(), i);
this.w = i;
GeneratorSettingBase generatorsettingbase = supplier.get();
this.h = supplier;
NoiseSettings noisesettings = generatorsettingbase.b();
this.x = noisesettings.a();
this.l = noisesettings.f() * 4;
this.m = noisesettings.e() * 4;
this.f = generatorsettingbase.c();
this.g = generatorsettingbase.d();
this.n = 16 / this.m;
this.o = noisesettings.a() / this.l;
this.p = 16 / this.m;
this.e = new SeededRandom(i);
this.q = new NoiseGeneratorOctaves(this.e, IntStream.rangeClosed(-15, 0));
this.r = new NoiseGeneratorOctaves(this.e, IntStream.rangeClosed(-15, 0));
this.s = new NoiseGeneratorOctaves(this.e, IntStream.rangeClosed(-7, 0));
this.t = (NoiseGenerator) (noisesettings.i() ? new NoiseGenerator3(this.e, IntStream.rangeClosed(-3, 0)) : new NoiseGeneratorOctaves(this.e, IntStream.rangeClosed(-3, 0)));
this.e.a(2620);
this.u = new NoiseGeneratorOctaves(this.e, IntStream.rangeClosed(-15, 0));
if(noisesettings.k())
{
SeededRandom seededrandom = new SeededRandom(i);
seededrandom.a(17292);
this.v = new NoiseGenerator3Handler(seededrandom);
}
else
{
this.v = null;
}
}
@Override
protected Codec<? extends ChunkGenerator> a()
{
return ChunkGeneratorAbstract.d;
}
public boolean a(long i, ResourceKey<GeneratorSettingBase> resourcekey)
{
return this.w == i && this.h.get().a(resourcekey);
}
private double a(int i, int j, int k, double d0, double d1, double d2, double d3)
{
double d4 = 0.0D;
double d5 = 0.0D;
double d6 = 0.0D;
double d7 = 1.0D;
for(int l = 0; l < 16; ++l)
{
double d8 = NoiseGeneratorOctaves.a((double) i * d0 * d7);
double d9 = NoiseGeneratorOctaves.a((double) j * d1 * d7);
double d10 = NoiseGeneratorOctaves.a((double) k * d0 * d7);
double d11 = d1 * d7;
NoiseGeneratorPerlin noisegeneratorperlin = this.q.a(l);
if(noisegeneratorperlin != null)
{
d4 += noisegeneratorperlin.a(d8, d9, d10, d11, (double) j * d11) / d7;
}
NoiseGeneratorPerlin noisegeneratorperlin1 = this.r.a(l);
if(noisegeneratorperlin1 != null)
{
d5 += noisegeneratorperlin1.a(d8, d9, d10, d11, (double) j * d11) / d7;
}
if(l < 8)
{
NoiseGeneratorPerlin noisegeneratorperlin2 = this.s.a(l);
if(noisegeneratorperlin2 != null)
{
d6 += noisegeneratorperlin2.a(NoiseGeneratorOctaves.a((double) i * d2 * d7), NoiseGeneratorOctaves.a((double) j * d3 * d7), NoiseGeneratorOctaves.a((double) k * d2 * d7), d3 * d7, (double) j * d3 * d7) / d7;
}
}
d7 /= 2.0D;
}
return MathHelper.b(d4 / 512.0D, d5 / 512.0D, (d6 / 10.0D + 1.0D) / 2.0D);
}
private double[] b(int i, int j)
{
double[] adouble = new double[this.o + 1];
this.a(adouble, i, j);
return adouble;
}
private void a(double[] adouble, int i, int j)
{
NoiseSettings noisesettings = this.h.get().b();
double d0;
double d1;
double d2;
double d3;
if(this.v != null)
{
d0 = (double) (WorldChunkManagerTheEnd.a(this.v, i, j) - 8.0F);
if(d0 > 0.0D)
{
d1 = 0.25D;
}
else
{
d1 = 1.0D;
}
}
else
{
float f = 0.0F;
float f1 = 0.0F;
float f2 = 0.0F;
int k = this.getSeaLevel();
float f3 = this.b.getBiome(i, k, j).h();
for(int l = -2; l <= 2; ++l)
{
for(int i1 = -2; i1 <= 2; ++i1)
{
BiomeBase biomebase = this.b.getBiome(i + l, k, j + i1);
float f4 = biomebase.h();
float f5 = biomebase.j();
float f6;
float f7;
if(noisesettings.l() && f4 > 0.0F)
{
f6 = 1.0F + f4 * 2.0F;
f7 = 1.0F + f5 * 4.0F;
}
else
{
f6 = f4;
f7 = f5;
}
// CraftBukkit start - fix MC-54738
if(f6 < -1.8F)
{
f6 = -1.8F;
}
// CraftBukkit end
float f8 = f4 > f3 ? 0.5F : 1.0F;
float f9 = f8 * NMSChunkGenerator16_2_BACKUP.j[l + 2 + (i1 + 2) * 5] / (f6 + 2.0F);
f += f7 * f9;
f1 += f6 * f9;
f2 += f9;
}
}
float f10 = f1 / f2;
float f11 = f / f2;
d2 = (double) (f10 * 0.5F - 0.125F);
d3 = (double) (f11 * 0.9F + 0.1F);
d0 = d2 * 0.265625D;
d1 = 96.0D / d3;
}
double d4 = 684.412D * noisesettings.b().a();
double d5 = 684.412D * noisesettings.b().b();
double d6 = d4 / noisesettings.b().c();
double d7 = d5 / noisesettings.b().d();
d2 = (double) noisesettings.c().a();
d3 = (double) noisesettings.c().b();
double d8 = (double) noisesettings.c().c();
double d9 = (double) noisesettings.d().a();
double d10 = (double) noisesettings.d().b();
double d11 = (double) noisesettings.d().c();
double d12 = noisesettings.j() ? this.c(i, j) : 0.0D;
double d13 = noisesettings.g();
double d14 = noisesettings.h();
for(int j1 = 0; j1 <= this.o; ++j1)
{
double d15 = this.a(i, j1, j, d4, d5, d6, d7);
double d16 = 1.0D - (double) j1 * 2.0D / (double) this.o + d12;
double d17 = d16 * d13 + d14;
double d18 = (d17 + d0) * d1;
if(d18 > 0.0D)
{
d15 += d18 * 4.0D;
}
else
{
d15 += d18;
}
double d19;
if(d3 > 0.0D)
{
d19 = ((double) (this.o - j1) - d8) / d3;
d15 = MathHelper.b(d2, d15, d19);
}
if(d10 > 0.0D)
{
d19 = ((double) j1 - d11) / d10;
d15 = MathHelper.b(d9, d15, d19);
}
adouble[j1] = d15;
}
}
private double c(int i, int j)
{
double d0 = this.u.a((double) (i * 200), 10.0D, (double) (j * 200), 1.0D, 0.0D, true);
double d1;
if(d0 < 0.0D)
{
d1 = -d0 * 0.3D;
}
else
{
d1 = d0;
}
double d2 = d1 * 24.575625D - 2.0D;
return d2 < 0.0D ? d2 * 0.009486607142857142D : Math.min(d2, 1.0D) * 0.006640625D;
}
@Override
public int getBaseHeight(int i, int j, HeightMap.Type heightmap_type)
{
return this.a(i, j, (IBlockData[]) null, heightmap_type.e());
}
@Override
public IBlockAccess a(int i, int j)
{
IBlockData[] aiblockdata = new IBlockData[this.o * this.l];
this.a(i, j, aiblockdata, (Predicate<IBlockData>) null);
return new BlockColumn(aiblockdata);
}
private int a(int i, int j, @Nullable IBlockData[] aiblockdata, @Nullable Predicate<IBlockData> predicate)
{
int k = Math.floorDiv(i, this.m);
int l = Math.floorDiv(j, this.m);
int i1 = Math.floorMod(i, this.m);
int j1 = Math.floorMod(j, this.m);
double d0 = (double) i1 / (double) this.m;
double d1 = (double) j1 / (double) this.m;
double[][] adouble = new double[][] {this.b(k, l), this.b(k, l + 1), this.b(k + 1, l), this.b(k + 1, l + 1)};
for(int k1 = this.o - 1; k1 >= 0; --k1)
{
double d2 = adouble[0][k1];
double d3 = adouble[1][k1];
double d4 = adouble[2][k1];
double d5 = adouble[3][k1];
double d6 = adouble[0][k1 + 1];
double d7 = adouble[1][k1 + 1];
double d8 = adouble[2][k1 + 1];
double d9 = adouble[3][k1 + 1];
for(int l1 = this.l - 1; l1 >= 0; --l1)
{
double d10 = (double) l1 / (double) this.l;
double d11 = MathHelper.a(d10, d0, d1, d2, d6, d4, d8, d3, d7, d5, d9);
int i2 = k1 * this.l + l1;
IBlockData iblockdata = this.a(d11, i2);
if(aiblockdata != null)
{
aiblockdata[i2] = iblockdata;
}
if(predicate != null && predicate.test(iblockdata))
{
return i2 + 1;
}
}
}
return 0;
}
protected IBlockData a(double d0, int i)
{
IBlockData iblockdata;
if(d0 > 0.0D)
{
iblockdata = this.f;
}
else if(i < this.getSeaLevel())
{
iblockdata = this.g;
}
else
{
iblockdata = NMSChunkGenerator16_2_BACKUP.k;
}
return iblockdata;
}
@Override
public void buildBase(RegionLimitedWorldAccess regionlimitedworldaccess, IChunkAccess ichunkaccess)
{
ChunkCoordIntPair chunkcoordintpair = ichunkaccess.getPos();
int i = chunkcoordintpair.x;
int j = chunkcoordintpair.z;
SeededRandom seededrandom = new SeededRandom();
seededrandom.a(i, j);
ChunkCoordIntPair chunkcoordintpair1 = ichunkaccess.getPos();
int k = chunkcoordintpair1.d();
int l = chunkcoordintpair1.e();
// double d0 = 0.0625D;
BlockPosition.MutableBlockPosition blockposition_mutableblockposition = new BlockPosition.MutableBlockPosition();
for(int i1 = 0; i1 < 16; ++i1)
{
for(int j1 = 0; j1 < 16; ++j1)
{
int k1 = k + i1;
int l1 = l + j1;
int i2 = ichunkaccess.getHighestBlock(HeightMap.Type.WORLD_SURFACE_WG, i1, j1) + 1;
double d1 = this.t.a((double) k1 * 0.0625D, (double) l1 * 0.0625D, 0.0625D, (double) i1 * 0.0625D) * 15.0D;
regionlimitedworldaccess.getBiome(blockposition_mutableblockposition.d(k + i1, i2, l + j1)).a(seededrandom, ichunkaccess, k1, l1, i2, d1, this.f, this.g, this.getSeaLevel(), regionlimitedworldaccess.getSeed());
}
}
this.a(ichunkaccess, seededrandom);
}
private void a(IChunkAccess ichunkaccess, Random random)
{
BlockPosition.MutableBlockPosition blockposition_mutableblockposition = new BlockPosition.MutableBlockPosition();
int i = ichunkaccess.getPos().d();
int j = ichunkaccess.getPos().e();
GeneratorSettingBase generatorsettingbase = this.h.get();
int k = generatorsettingbase.f();
int l = this.x - 1 - generatorsettingbase.e();
boolean flag1 = l + 4 >= 0 && l < this.x;
boolean flag2 = k + 4 >= 0 && k < this.x;
if(flag1 || flag2)
{
Iterator<BlockPosition> iterator = BlockPosition.b(i, 0, j, i + 15, 0, j + 15).iterator();
while(iterator.hasNext())
{
BlockPosition blockposition = iterator.next();
int i1;
if(flag1)
{
for(i1 = 0; i1 < 5; ++i1)
{
if(i1 <= random.nextInt(5))
{
ichunkaccess.setType(blockposition_mutableblockposition.d(blockposition.getX(), l - i1, blockposition.getZ()), Blocks.BEDROCK.getBlockData(), false);
}
}
}
if(flag2)
{
for(i1 = 4; i1 >= 0; --i1)
{
if(i1 <= random.nextInt(5))
{
ichunkaccess.setType(blockposition_mutableblockposition.d(blockposition.getX(), k + i1, blockposition.getZ()), Blocks.BEDROCK.getBlockData(), false);
}
}
}
}
}
}
@Override
public void buildNoise(GeneratorAccess generatoraccess, StructureManager structuremanager, IChunkAccess ichunkaccess)
{
ObjectList<StructurePiece> objectlist = new ObjectArrayList<StructurePiece>(10);
ObjectList<WorldGenFeatureDefinedStructureJigsawJunction> objectlist1 = new ObjectArrayList<WorldGenFeatureDefinedStructureJigsawJunction>(32);
ChunkCoordIntPair chunkcoordintpair = ichunkaccess.getPos();
int i = chunkcoordintpair.x;
int j = chunkcoordintpair.z;
int k = i << 4;
int l = j << 4;
Iterator<?> iterator = StructureGenerator.t.iterator();
while(iterator.hasNext())
{
StructureGenerator<?> structuregenerator = (StructureGenerator<?>) iterator.next();
structuremanager.a(SectionPosition.a(chunkcoordintpair, 0), structuregenerator).forEach((structurestart) ->
{
Iterator<?> iterator1 = structurestart.d().iterator();
while(iterator1.hasNext())
{
StructurePiece structurepiece = (StructurePiece) iterator1.next();
if(structurepiece.a(chunkcoordintpair, 12))
{
if(structurepiece instanceof WorldGenFeaturePillagerOutpostPoolPiece)
{
WorldGenFeaturePillagerOutpostPoolPiece worldgenfeaturepillageroutpostpoolpiece = (WorldGenFeaturePillagerOutpostPoolPiece) structurepiece;
WorldGenFeatureDefinedStructurePoolTemplate.Matching worldgenfeaturedefinedstructurepooltemplate_matching = worldgenfeaturepillageroutpostpoolpiece.b().e();
if(worldgenfeaturedefinedstructurepooltemplate_matching == WorldGenFeatureDefinedStructurePoolTemplate.Matching.RIGID)
{
objectlist.add(worldgenfeaturepillageroutpostpoolpiece);
}
Iterator<?> iterator2 = worldgenfeaturepillageroutpostpoolpiece.e().iterator();
while(iterator2.hasNext())
{
WorldGenFeatureDefinedStructureJigsawJunction worldgenfeaturedefinedstructurejigsawjunction = (WorldGenFeatureDefinedStructureJigsawJunction) iterator2.next();
int i1 = worldgenfeaturedefinedstructurejigsawjunction.a();
int j1 = worldgenfeaturedefinedstructurejigsawjunction.c();
if(i1 > k - 12 && j1 > l - 12 && i1 < k + 15 + 12 && j1 < l + 15 + 12)
{
objectlist1.add(worldgenfeaturedefinedstructurejigsawjunction);
}
}
}
else
{
objectlist.add(structurepiece);
}
}
}
});
}
double[][][] adouble = new double[2][this.p + 1][this.o + 1];
for(int i1 = 0; i1 < this.p + 1; ++i1)
{
adouble[0][i1] = new double[this.o + 1];
this.a(adouble[0][i1], i * this.n, j * this.p + i1);
adouble[1][i1] = new double[this.o + 1];
}
ProtoChunk protochunk = (ProtoChunk) ichunkaccess;
HeightMap heightmap = protochunk.a(HeightMap.Type.OCEAN_FLOOR_WG);
HeightMap heightmap1 = protochunk.a(HeightMap.Type.WORLD_SURFACE_WG);
BlockPosition.MutableBlockPosition blockposition_mutableblockposition = new BlockPosition.MutableBlockPosition();
ObjectListIterator<StructurePiece> objectlistiterator = objectlist.iterator();
ObjectListIterator<WorldGenFeatureDefinedStructureJigsawJunction> objectlistiterator1 = objectlist1.iterator();
for(int j1 = 0; j1 < this.n; ++j1)
{
int k1;
for(k1 = 0; k1 < this.p + 1; ++k1)
{
this.a(adouble[1][k1], i * this.n + j1 + 1, j * this.p + k1);
}
for(k1 = 0; k1 < this.p; ++k1)
{
ChunkSection chunksection = protochunk.a(15);
chunksection.a();
for(int l1 = this.o - 1; l1 >= 0; --l1)
{
double d0 = adouble[0][k1][l1];
double d1 = adouble[0][k1 + 1][l1];
double d2 = adouble[1][k1][l1];
double d3 = adouble[1][k1 + 1][l1];
double d4 = adouble[0][k1][l1 + 1];
double d5 = adouble[0][k1 + 1][l1 + 1];
double d6 = adouble[1][k1][l1 + 1];
double d7 = adouble[1][k1 + 1][l1 + 1];
for(int i2 = this.l - 1; i2 >= 0; --i2)
{
int j2 = l1 * this.l + i2;
int k2 = j2 & 15;
int l2 = j2 >> 4;
if(chunksection.getYPosition() >> 4 != l2)
{
chunksection.b();
chunksection = protochunk.a(l2);
chunksection.a();
}
double d8 = (double) i2 / (double) this.l;
double d9 = MathHelper.d(d8, d0, d4);
double d10 = MathHelper.d(d8, d2, d6);
double d11 = MathHelper.d(d8, d1, d5);
double d12 = MathHelper.d(d8, d3, d7);
for(int i3 = 0; i3 < this.m; ++i3)
{
int j3 = k + j1 * this.m + i3;
int k3 = j3 & 15;
double d13 = (double) i3 / (double) this.m;
double d14 = MathHelper.d(d13, d9, d10);
double d15 = MathHelper.d(d13, d11, d12);
for(int l3 = 0; l3 < this.m; ++l3)
{
int i4 = l + k1 * this.m + l3;
int j4 = i4 & 15;
double d16 = (double) l3 / (double) this.m;
double d17 = MathHelper.d(d16, d14, d15);
double d18 = MathHelper.a(d17 / 200.0D, -1.0D, 1.0D);
int k4;
int l4;
int i5;
for(d18 = d18 / 2.0D - d18 * d18 * d18 / 24.0D; objectlistiterator.hasNext(); d18 += a(k4, l4, i5) * 0.8D)
{
StructurePiece structurepiece = objectlistiterator.next();
StructureBoundingBox structureboundingbox = structurepiece.g();
k4 = Math.max(0, Math.max(structureboundingbox.a - j3, j3 - structureboundingbox.d));
l4 = j2 - (structureboundingbox.b + (structurepiece instanceof WorldGenFeaturePillagerOutpostPoolPiece ? ((WorldGenFeaturePillagerOutpostPoolPiece) structurepiece).d() : 0));
i5 = Math.max(0, Math.max(structureboundingbox.c - i4, i4 - structureboundingbox.f));
}
objectlistiterator.back(objectlist.size());
while(objectlistiterator1.hasNext())
{
WorldGenFeatureDefinedStructureJigsawJunction worldgenfeaturedefinedstructurejigsawjunction = objectlistiterator1.next();
int j5 = j3 - worldgenfeaturedefinedstructurejigsawjunction.a();
k4 = j2 - worldgenfeaturedefinedstructurejigsawjunction.b();
l4 = i4 - worldgenfeaturedefinedstructurejigsawjunction.c();
d18 += a(j5, k4, l4) * 0.4D;
}
objectlistiterator1.back(objectlist1.size());
IBlockData iblockdata = this.a(d18, j2);
if(iblockdata != NMSChunkGenerator16_2_BACKUP.k)
{
if(iblockdata.f() != 0)
{
blockposition_mutableblockposition.d(j3, j2, i4);
protochunk.k(blockposition_mutableblockposition);
}
chunksection.setType(k3, k2, j4, iblockdata, false);
heightmap.a(k3, j2, j4, iblockdata);
heightmap1.a(k3, j2, j4, iblockdata);
}
}
}
}
}
chunksection.b();
}
double[][] adouble1 = adouble[0];
adouble[0] = adouble[1];
adouble[1] = adouble1;
}
}
private static double a(int i, int j, int k)
{
int l = i + 12;
int i1 = j + 12;
int j1 = k + 12;
return l >= 0 && l < 24 ? (i1 >= 0 && i1 < 24 ? (j1 >= 0 && j1 < 24 ? (double) NMSChunkGenerator16_2_BACKUP.i[j1 * 24 * 24 + l * 24 + i1] : 0.0D) : 0.0D) : 0.0D;
}
private static double b(int i, int j, int k)
{
double d0 = (double) (i * i + k * k);
double d1 = (double) j + 0.5D;
double d2 = d1 * d1;
double d3 = Math.pow(2.718281828459045D, -(d2 / 16.0D + d0 / 16.0D));
double d4 = -d1 * MathHelper.i(d2 / 2.0D + d0 / 2.0D) / 2.0D;
return d4 * d3;
}
@Override
public int getGenerationDepth()
{
return this.x;
}
@Override
public int getSeaLevel()
{
return this.h.get().g();
}
@Override
public List<BiomeSettingsMobs.c> getMobsFor(BiomeBase biomebase, StructureManager structuremanager, EnumCreatureType enumcreaturetype, BlockPosition blockposition)
{
if(structuremanager.a(blockposition, true, StructureGenerator.SWAMP_HUT).e())
{
if(enumcreaturetype == EnumCreatureType.MONSTER)
{
return StructureGenerator.SWAMP_HUT.c();
}
if(enumcreaturetype == EnumCreatureType.CREATURE)
{
return StructureGenerator.SWAMP_HUT.j();
}
}
if(enumcreaturetype == EnumCreatureType.MONSTER)
{
if(structuremanager.a(blockposition, false, StructureGenerator.PILLAGER_OUTPOST).e())
{
return StructureGenerator.PILLAGER_OUTPOST.c();
}
if(structuremanager.a(blockposition, false, StructureGenerator.MONUMENT).e())
{
return StructureGenerator.MONUMENT.c();
}
if(structuremanager.a(blockposition, true, StructureGenerator.FORTRESS).e())
{
return StructureGenerator.FORTRESS.c();
}
}
return super.getMobsFor(biomebase, structuremanager, enumcreaturetype, blockposition);
}
@Override
public void addMobs(RegionLimitedWorldAccess regionlimitedworldaccess)
{
int i = regionlimitedworldaccess.a();
int j = regionlimitedworldaccess.b();
BiomeBase biomebase = regionlimitedworldaccess.getBiome((new ChunkCoordIntPair(i, j)).l());
SeededRandom seededrandom = new SeededRandom();
seededrandom.a(regionlimitedworldaccess.getSeed(), i << 4, j << 4);
SpawnerCreature.a(regionlimitedworldaccess, biomebase, i, j, seededrandom);
}
}

View File

@@ -1,4 +1,4 @@
package com.volmit.iris.gen.nms;
package com.volmit.iris.gen.nms.v16_2;
import java.io.File;
import java.io.IOException;
@@ -23,8 +23,12 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.mojang.serialization.DynamicOps;
import com.mojang.serialization.Lifecycle;
import com.volmit.iris.gen.nms.INMSCreator;
import com.volmit.iris.gen.scaffold.Provisioned;
import com.volmit.iris.util.O;
import com.volmit.iris.util.V;
import io.papermc.lib.PaperLib;
import net.minecraft.server.v1_16_R2.BiomeBase;
import net.minecraft.server.v1_16_R2.BiomeManager;
import net.minecraft.server.v1_16_R2.Convertable;
@@ -38,6 +42,7 @@ import net.minecraft.server.v1_16_R2.GameRules;
import net.minecraft.server.v1_16_R2.GeneratorSettingBase;
import net.minecraft.server.v1_16_R2.GeneratorSettings;
import net.minecraft.server.v1_16_R2.IRegistry;
import net.minecraft.server.v1_16_R2.IRegistryCustom.Dimension;
import net.minecraft.server.v1_16_R2.IWorldDataServer;
import net.minecraft.server.v1_16_R2.MinecraftKey;
import net.minecraft.server.v1_16_R2.MinecraftServer;
@@ -52,16 +57,19 @@ import net.minecraft.server.v1_16_R2.RegistryReadOps;
import net.minecraft.server.v1_16_R2.ResourceKey;
import net.minecraft.server.v1_16_R2.SaveData;
import net.minecraft.server.v1_16_R2.VillageSiege;
import net.minecraft.server.v1_16_R2.WorldChunkManager;
import net.minecraft.server.v1_16_R2.WorldChunkManagerOverworld;
import net.minecraft.server.v1_16_R2.WorldDataServer;
import net.minecraft.server.v1_16_R2.WorldDimension;
import net.minecraft.server.v1_16_R2.WorldServer;
import net.minecraft.server.v1_16_R2.WorldSettings;
public class NMSCreator162
class NMSCreator16_2 implements INMSCreator
{
@SuppressWarnings({"unchecked", "rawtypes", "resource"})
public static World createWorld(WorldCreator creator, boolean loadSpawn)
public World createWorld(WorldCreator creator, boolean loadSpawn)
{
Provisioned pro = (Provisioned) creator.generator();
CraftServer server = ((CraftServer) Bukkit.getServer());
Map<String, World> worlds = new V(server).get("worlds");
DedicatedServer console = new V(server).get("console");
@@ -121,7 +129,7 @@ public class NMSCreator162
}
MinecraftServer.convertWorld(worldSession);
final boolean hardcore = creator.hardcore();
final RegistryReadOps<NBTBase> registryreadops = (RegistryReadOps<NBTBase>) RegistryReadOps.a((DynamicOps) DynamicOpsNBT.a, console.dataPackResources.h(), console.f);
final RegistryReadOps<NBTBase> registryreadops = (RegistryReadOps<NBTBase>) RegistryReadOps.a((DynamicOps) DynamicOpsNBT.a, console.dataPackResources.h(), getConsoleDimension(console));
WorldDataServer worlddata = (WorldDataServer) worldSession.a((DynamicOps) registryreadops, console.datapackconfiguration);
if(worlddata == null)
{
@@ -130,7 +138,7 @@ public class NMSCreator162
properties.put("level-seed", Objects.toString(creator.seed()));
properties.put("generate-structures", Objects.toString(creator.generateStructures()));
properties.put("level-type", Objects.toString(creator.type().getName()));
final GeneratorSettings generatorsettings = GeneratorSettings.a(console.aX(), properties);
final GeneratorSettings generatorsettings = GeneratorSettings.a(getConsoleDimension(console), properties);
@SuppressWarnings("deprecation")
final WorldSettings worldSettings = new WorldSettings(name, EnumGamemode.getById(server.getDefaultGameMode().getValue()), hardcore, EnumDifficulty.EASY, false, new GameRules(), console.datapackconfiguration);
worlddata = new WorldDataServer(worldSettings, generatorsettings, Lifecycle.stable());
@@ -147,18 +155,10 @@ public class NMSCreator162
final WorldDimension worlddimension = (WorldDimension) registrymaterials.a((ResourceKey) actualDimension);
DimensionManager dimensionmanager;
net.minecraft.server.v1_16_R2.ChunkGenerator chunkgenerator;
if(worlddimension == null)
{
dimensionmanager = (DimensionManager) console.f.a().d(DimensionManager.OVERWORLD);
chunkgenerator = (net.minecraft.server.v1_16_R2.ChunkGenerator) GeneratorSettings.a((IRegistry<BiomeBase>) console.f.b(IRegistry.ay), (IRegistry<GeneratorSettingBase>) console.f.b(IRegistry.ar), new Random().nextLong());
}
else
{
dimensionmanager = worlddimension.b();
chunkgenerator = worlddimension.c();
}
long ll = new Random().nextLong();
dimensionmanager = (DimensionManager) getConsoleDimension(console).a().d(DimensionManager.OVERWORLD);
O<WorldServer> ws = new O<WorldServer>();
chunkgenerator = new NMSChunkGenerator16_2(pro, ws, (WorldChunkManager) new WorldChunkManagerOverworld(ll, false, false, (IRegistry<BiomeBase>) getConsoleDimension(console).b(IRegistry.ay)), ll, () -> (GeneratorSettingBase) getConsoleDimension(console).b(IRegistry.ar).d(GeneratorSettingBase.c));
final ResourceKey<net.minecraft.server.v1_16_R2.World> worldKey = (ResourceKey<net.minecraft.server.v1_16_R2.World>) ResourceKey.a(IRegistry.L, new MinecraftKey(name.toLowerCase(Locale.ENGLISH)));
//@builder
final WorldServer internal = new WorldServer((MinecraftServer) console,
@@ -173,8 +173,9 @@ public class NMSCreator162
(List) ((creator.environment() == World.Environment.NORMAL) ? list : ImmutableList.of()),
true,
creator.environment(),
generator);
server.getGenerator(name));
//@done
ws.set(internal);
if(!worlds.containsKey(name.toLowerCase(Locale.ENGLISH)))
{
try
@@ -189,10 +190,12 @@ public class NMSCreator162
return null;
}
console.initWorld(internal, (IWorldDataServer) worlddata, (SaveData) worlddata, worlddata.getGeneratorSettings());
internal.setSpawnFlags(true, true);
console.worldServer.put(internal.getDimensionKey(), internal);
server.getPluginManager().callEvent((Event) new WorldInitEvent((World) internal.getWorld()));
if(loadSpawn)
{
server.getServer().loadSpawn(internal.getChunkProvider().playerChunkMap.worldLoadListener, internal);
@@ -206,4 +209,14 @@ public class NMSCreator162
server.getPluginManager().callEvent((Event) new WorldLoadEvent((World) internal.getWorld()));
return (World) internal.getWorld();
}
private Dimension getConsoleDimension(DedicatedServer console)
{
if(PaperLib.isPaper())
{
return new V((MinecraftServer) console, true).get("customRegistry");
}
return console.f;
}
}

View File

@@ -0,0 +1,16 @@
package com.volmit.iris.gen.nms.v1X;
import com.volmit.iris.gen.atomics.AtomicCache;
import com.volmit.iris.gen.nms.INMSBinding;
import com.volmit.iris.gen.nms.INMSCreator;
public class NMSBinding1X implements INMSBinding
{
private final AtomicCache<INMSCreator> creator = new AtomicCache<>();
@Override
public INMSCreator getCreator()
{
return creator.aquire(() -> new NMSCreator1X());
}
}

View File

@@ -0,0 +1,14 @@
package com.volmit.iris.gen.nms.v1X;
import org.bukkit.World;
import org.bukkit.WorldCreator;
import com.volmit.iris.gen.nms.INMSCreator;
class NMSCreator1X implements INMSCreator
{
public World createWorld(WorldCreator creator, boolean loadSpawn)
{
return creator.createWorld();
}
}