diff --git a/pom.xml b/pom.xml index 91762b967..c5a5e6aef 100644 --- a/pom.xml +++ b/pom.xml @@ -1,10 +1,10 @@ - 4.0.0 bytecode.ninja Iris - 1.0.15 + 1.0.22 Iris false @@ -192,12 +192,6 @@ 1.16.2 provided - - org.bukkit.craftbukkit - cb-1.16.1 - 1.16.1 - provided - org.bukkit.craftbukkit cb-1.15.1 diff --git a/src/main/java/com/volmit/iris/Iris.java b/src/main/java/com/volmit/iris/Iris.java index f030aafee..b1d29e088 100644 --- a/src/main/java/com/volmit/iris/Iris.java +++ b/src/main/java/com/volmit/iris/Iris.java @@ -20,8 +20,10 @@ import org.bukkit.plugin.Plugin; import com.volmit.iris.command.CommandIris; import com.volmit.iris.command.PermissionIris; import com.volmit.iris.gen.IrisTerrainProvider; +import com.volmit.iris.gen.nms.INMS; import com.volmit.iris.gen.provisions.ProvisionBukkit; import com.volmit.iris.gen.scaffold.IrisGenConfiguration; +import com.volmit.iris.gen.scaffold.IrisWorlds; import com.volmit.iris.gen.scaffold.TerrainTarget; import com.volmit.iris.link.MultiverseCoreLink; import com.volmit.iris.link.MythicMobsLink; @@ -61,7 +63,6 @@ public class Iris extends MortarPlugin public static StructureManager struct; public static EditManager edit; public static IrisBoardManager board; - public static String nmsTag = findNMSTag(); public static MultiverseCoreLink linkMultiverseCore; public static MythicMobsLink linkMythicMobs; public static CitizensLink linkCitizens; @@ -81,6 +82,7 @@ public class Iris extends MortarPlugin public Iris() { + INMS.get(); IO.delete(new File("iris")); lowMemoryMode = Runtime.getRuntime().maxMemory() < 4000000000L; // 4 * 1000 * 1000 * 1000 // 4gb } @@ -99,22 +101,6 @@ public class Iris extends MortarPlugin return tc; } - private static String findNMSTag() - { - try - { - return Bukkit.getServer().getClass().getCanonicalName().split("\\Q.\\E")[3]; - } - - catch(Throwable e) - { - Iris.error("Failed to determine server nms version!"); - e.printStackTrace(); - } - - return "UNKNOWN NMS VERSION"; - } - public ProvisionBukkit createProvisionBukkit(IrisGenConfiguration config) { return new ProvisionBukkit(createIrisProvider(config)); @@ -240,7 +226,7 @@ public class Iris extends MortarPlugin { if(i.getGenerator() instanceof ProvisionBukkit) { - ((IrisTerrainProvider) ((ProvisionBukkit) i.getGenerator()).getProvider()).close(); + IrisWorlds.getProvider(i).close(); } } @@ -279,6 +265,13 @@ public class Iris extends MortarPlugin public static void msg(String string) { lock.lock(); + if(instance == null) + { + System.out.println("[Iris]: " + string); + lock.unlock(); + return; + } + String msg = C.GREEN + "[Iris]: " + C.GRAY + string; Bukkit.getConsoleSender().sendMessage(msg); lock.unlock(); @@ -440,11 +433,6 @@ public class Iris extends MortarPlugin } } - public static String nmsTag() - { - return nmsTag; - } - @SuppressWarnings("deprecation") public static void later(NastyRunnable object) { diff --git a/src/main/java/com/volmit/iris/IrisSettings.java b/src/main/java/com/volmit/iris/IrisSettings.java index a4a0acab3..c1e53f707 100644 --- a/src/main/java/com/volmit/iris/IrisSettings.java +++ b/src/main/java/com/volmit/iris/IrisSettings.java @@ -42,6 +42,10 @@ public class IrisSettings @Desc("Useful information when creating iris worlds. Shows object loads & more.") public boolean verbose = false; + @DontObfuscate + @Desc("If true, will not use world edit even if its on the server") + public boolean ignoreWorldEdit = false; + @DontObfuscate @Desc("System Effects") public boolean systemEffects = true; @@ -179,4 +183,12 @@ public class IrisSettings return settings; } + + public static void invalidate() + { + synchronized(settings) + { + settings = null; + } + } } diff --git a/src/main/java/com/volmit/iris/command/CommandIrisCTC.java b/src/main/java/com/volmit/iris/command/CommandIrisCTC.java index 7cfa48b69..f7933d0b8 100644 --- a/src/main/java/com/volmit/iris/command/CommandIrisCTC.java +++ b/src/main/java/com/volmit/iris/command/CommandIrisCTC.java @@ -6,6 +6,7 @@ import org.bukkit.entity.Player; import com.volmit.iris.Iris; import com.volmit.iris.gen.IrisTerrainProvider; import com.volmit.iris.gen.provisions.ProvisionBukkit; +import com.volmit.iris.gen.scaffold.IrisWorlds; import com.volmit.iris.util.MortarCommand; import com.volmit.iris.util.MortarSender; @@ -27,7 +28,7 @@ public class CommandIrisCTC extends MortarCommand sender.sendMessage("/iris ctc " + getArgsUsage()); return true; } - + if(sender.isPlayer()) { Player p = sender.player(); @@ -39,7 +40,7 @@ public class CommandIrisCTC extends MortarCommand return true; } - IrisTerrainProvider g = (IrisTerrainProvider) ((ProvisionBukkit) world.getGenerator()).getProvider(); + IrisTerrainProvider g = IrisWorlds.getProvider(world); int m = Math.min(Math.max(Integer.valueOf(args[0]), 2), 256); g.changeThreadCount(m); sender.sendMessage("Thread count changed to " + m); diff --git a/src/main/java/com/volmit/iris/command/CommandIrisCreate.java b/src/main/java/com/volmit/iris/command/CommandIrisCreate.java index 03c7eaee2..2c4ba2964 100644 --- a/src/main/java/com/volmit/iris/command/CommandIrisCreate.java +++ b/src/main/java/com/volmit/iris/command/CommandIrisCreate.java @@ -9,7 +9,7 @@ import org.bukkit.WorldType; import com.volmit.iris.Iris; import com.volmit.iris.gen.IrisTerrainProvider; -import com.volmit.iris.gen.nms.NMSCreator; +import com.volmit.iris.gen.nms.INMS; import com.volmit.iris.gen.provisions.ProvisionBukkit; import com.volmit.iris.gen.scaffold.IrisGenConfiguration; import com.volmit.iris.gen.scaffold.TerrainTarget; @@ -37,6 +37,7 @@ public class CommandIrisCreate extends MortarCommand if(args.length == 0) { sender.sendMessage("/iris create [type=overworld] [seed=1337] [pregen=5000] [-zip]"); + return true; } String worldName = args[0]; @@ -109,7 +110,7 @@ public class CommandIrisCreate extends MortarCommand WorldCreator wc = new WorldCreator(worldName).seed(seed).generator(gen).type(WorldType.NORMAL).environment(dim.getEnvironment()); - World world = NMSCreator.createWorld(wc, false); + World world = INMS.get().createWorld(wc, false); done.set(true); sender.sendMessage(worldName + " Spawn Area generated."); diff --git a/src/main/java/com/volmit/iris/command/CommandIrisMetrics.java b/src/main/java/com/volmit/iris/command/CommandIrisMetrics.java index 088523c01..eca178021 100644 --- a/src/main/java/com/volmit/iris/command/CommandIrisMetrics.java +++ b/src/main/java/com/volmit/iris/command/CommandIrisMetrics.java @@ -7,6 +7,7 @@ import com.volmit.iris.Iris; import com.volmit.iris.gen.IrisTerrainProvider; import com.volmit.iris.gen.provisions.ProvisionBukkit; import com.volmit.iris.gen.scaffold.IrisMetrics; +import com.volmit.iris.gen.scaffold.IrisWorlds; import com.volmit.iris.util.C; import com.volmit.iris.util.Form; import com.volmit.iris.util.MortarCommand; @@ -35,7 +36,7 @@ public class CommandIrisMetrics extends MortarCommand return true; } - IrisTerrainProvider g = (IrisTerrainProvider) ((ProvisionBukkit) world.getGenerator()).getProvider(); + IrisTerrainProvider g = IrisWorlds.getProvider(world); IrisMetrics m = g.getMetrics(); sender.sendMessage("Thread Count: " + C.BOLD + "" + C.WHITE + g.getThreads()); sender.sendMessage("Total : " + C.BOLD + "" + C.WHITE + Form.duration(m.getTotal().getAverage(), 2)); diff --git a/src/main/java/com/volmit/iris/command/CommandIrisObjectPaste.java b/src/main/java/com/volmit/iris/command/CommandIrisObjectPaste.java index 0ea74fa14..af81b2c43 100644 --- a/src/main/java/com/volmit/iris/command/CommandIrisObjectPaste.java +++ b/src/main/java/com/volmit/iris/command/CommandIrisObjectPaste.java @@ -56,7 +56,7 @@ public class CommandIrisObjectPaste extends MortarCommand if(file == null || !file.exists()) { - sender.sendMessage("Can't find " + args[0] + " in the " + ProjectManager.workspaceName + " folder"); + sender.sendMessage("Can't find " + args[0] + " in the " + ProjectManager.WORKSPACE_NAME + " folder"); } ItemStack wand = sender.player().getInventory().getItemInMainHand(); diff --git a/src/main/java/com/volmit/iris/command/CommandIrisPregen.java b/src/main/java/com/volmit/iris/command/CommandIrisPregen.java index 84f546e20..57db92c0e 100644 --- a/src/main/java/com/volmit/iris/command/CommandIrisPregen.java +++ b/src/main/java/com/volmit/iris/command/CommandIrisPregen.java @@ -35,11 +35,41 @@ public class CommandIrisPregen extends MortarCommand } else { - sender.sendMessage("Stopped all pregens."); + sender.sendMessage("Stopped All Pregens."); + PregenJob.stop(); } - PregenJob.stop(); return true; } + /* TODO: help + else if(args[0].equalsIgnoreCase("pause")) + { + if(PregenJob.task == -1) + { + sender.sendMessage("No Active Pregens"); + } + else + { + if (PregenJob.isPaused()) { + PregenJob.resume(); + } else { + PregenJob.pause(); + } + sender.sendMessage("Paused Active Pregen"); + } + return true; + } else if(args[0].equalsIgnoreCase("resume")){ + if(!PregenJob.isPaused()) + { + sender.sendMessage("No Paused Pregens"); + } + else + { + sender.sendMessage("Resumed Paused Pregen"); + PregenJob.resume(); + } + return true; + } + */ if(sender.isPlayer()) { diff --git a/src/main/java/com/volmit/iris/command/CommandIrisRegen.java b/src/main/java/com/volmit/iris/command/CommandIrisRegen.java index 4ac4d163a..29e06f92d 100644 --- a/src/main/java/com/volmit/iris/command/CommandIrisRegen.java +++ b/src/main/java/com/volmit/iris/command/CommandIrisRegen.java @@ -4,6 +4,7 @@ import org.bukkit.World; import org.bukkit.entity.Player; import com.volmit.iris.Iris; +import com.volmit.iris.gen.IrisTerrainProvider; import com.volmit.iris.gen.provisions.ProvisionBukkit; import com.volmit.iris.gen.scaffold.Provisioned; import com.volmit.iris.util.MortarCommand; @@ -34,6 +35,13 @@ public class CommandIrisRegen extends MortarCommand } Provisioned pr = (Provisioned) world.getGenerator(); + + if(((IrisTerrainProvider) pr.getProvider()).isFailing()) + { + sender.sendMessage("This world is in a failed state! Cannot Regenerate!"); + return true; + } + pr.clearRegeneratedLists(); if(args.length == 0) { @@ -53,6 +61,7 @@ public class CommandIrisRegen extends MortarCommand { sender.sendMessage("/iris regen [SIZE]"); } + return true; } diff --git a/src/main/java/com/volmit/iris/command/CommandIrisReload.java b/src/main/java/com/volmit/iris/command/CommandIrisReload.java new file mode 100644 index 000000000..fdd8c5a9f --- /dev/null +++ b/src/main/java/com/volmit/iris/command/CommandIrisReload.java @@ -0,0 +1,32 @@ +package com.volmit.iris.command; + +import com.volmit.iris.Iris; +import com.volmit.iris.IrisSettings; +import com.volmit.iris.util.MortarCommand; +import com.volmit.iris.util.MortarSender; + +public class CommandIrisReload extends MortarCommand +{ + public CommandIrisReload() + { + super("reload", "rld"); + requiresPermission(Iris.perm.studio); + setDescription("Reload configs"); + setCategory("Studio"); + } + + @Override + public boolean handle(MortarSender sender, String[] args) + { + IrisSettings.invalidate(); + IrisSettings.get(); + sender.sendMessage("settings.json Reloaded"); + return true; + } + + @Override + protected String getArgsUsage() + { + return " [-t/--trim]"; + } +} diff --git a/src/main/java/com/volmit/iris/command/CommandIrisStudio.java b/src/main/java/com/volmit/iris/command/CommandIrisStudio.java index c7d26c84d..c3b7b32f1 100644 --- a/src/main/java/com/volmit/iris/command/CommandIrisStudio.java +++ b/src/main/java/com/volmit/iris/command/CommandIrisStudio.java @@ -14,6 +14,9 @@ public class CommandIrisStudio extends MortarCommand @Command private CommandIrisStudioOpen open; + @Command + private CommandIrisStudioSummon summon; + @Command private CommandIrisStudioClose close; @@ -44,6 +47,9 @@ public class CommandIrisStudio extends MortarCommand @Command private CommandIrisStudioLoot loot; + @Command + private CommandIrisStudioTP tp; + public CommandIrisStudio() { super("studio", "std"); diff --git a/src/main/java/com/volmit/iris/command/CommandIrisStudioGoto.java b/src/main/java/com/volmit/iris/command/CommandIrisStudioGoto.java index 9db62d193..814da25d3 100644 --- a/src/main/java/com/volmit/iris/command/CommandIrisStudioGoto.java +++ b/src/main/java/com/volmit/iris/command/CommandIrisStudioGoto.java @@ -5,9 +5,9 @@ import org.bukkit.World; import org.bukkit.entity.Player; import com.volmit.iris.Iris; -import com.volmit.iris.IrisSettings; import com.volmit.iris.gen.IrisTerrainProvider; import com.volmit.iris.gen.provisions.ProvisionBukkit; +import com.volmit.iris.gen.scaffold.IrisWorlds; import com.volmit.iris.object.IrisBiome; import com.volmit.iris.util.MortarCommand; import com.volmit.iris.util.MortarSender; @@ -26,15 +26,9 @@ public class CommandIrisStudioGoto extends MortarCommand @Override public boolean handle(MortarSender sender, String[] args) { - if(!IrisSettings.get().isStudio()) - { - sender.sendMessage("To use Iris Studio, please enable studio in Iris/settings.json"); - return true; - } - if(args.length < 1) { - sender.sendMessage("/iris world goto " + getArgsUsage()); + sender.sendMessage("/iris std goto " + getArgsUsage()); return true; } @@ -49,7 +43,7 @@ public class CommandIrisStudioGoto extends MortarCommand return true; } - IrisTerrainProvider g = (IrisTerrainProvider) ((ProvisionBukkit) world.getGenerator()).getProvider(); + IrisTerrainProvider g = IrisWorlds.getProvider(world); int tries = 10000; boolean cave = false; IrisBiome biome2 = null; diff --git a/src/main/java/com/volmit/iris/command/CommandIrisStudioHotload.java b/src/main/java/com/volmit/iris/command/CommandIrisStudioHotload.java index 785f8a5cb..702d5fe94 100644 --- a/src/main/java/com/volmit/iris/command/CommandIrisStudioHotload.java +++ b/src/main/java/com/volmit/iris/command/CommandIrisStudioHotload.java @@ -7,6 +7,7 @@ import com.volmit.iris.Iris; import com.volmit.iris.IrisSettings; import com.volmit.iris.gen.IrisTerrainProvider; import com.volmit.iris.gen.provisions.ProvisionBukkit; +import com.volmit.iris.gen.scaffold.IrisWorlds; import com.volmit.iris.util.MortarCommand; import com.volmit.iris.util.MortarSender; @@ -39,7 +40,7 @@ public class CommandIrisStudioHotload extends MortarCommand return true; } - IrisTerrainProvider g = (IrisTerrainProvider) ((ProvisionBukkit) world.getGenerator()).getProvider(); + IrisTerrainProvider g = IrisWorlds.getProvider(world); g.onHotload(); sender.sendMessage("Hotloaded!"); return true; diff --git a/src/main/java/com/volmit/iris/command/CommandIrisStudioLoot.java b/src/main/java/com/volmit/iris/command/CommandIrisStudioLoot.java index 631494027..952c61307 100644 --- a/src/main/java/com/volmit/iris/command/CommandIrisStudioLoot.java +++ b/src/main/java/com/volmit/iris/command/CommandIrisStudioLoot.java @@ -7,6 +7,7 @@ import org.bukkit.inventory.Inventory; import com.volmit.iris.Iris; import com.volmit.iris.IrisSettings; +import com.volmit.iris.gen.IrisTerrainProvider; import com.volmit.iris.gen.scaffold.IrisWorlds; import com.volmit.iris.object.InventorySlotType; import com.volmit.iris.object.IrisLootTable; @@ -38,10 +39,44 @@ public class CommandIrisStudioLoot extends MortarCommand if(sender.isPlayer()) { Player p = sender.player(); - IrisWorlds.getProvider(sender.player().getWorld()).getPopulators(); - KList tables = IrisWorlds.getProvider(sender.player().getWorld()).getGlUpdate().getLootTables(RNG.r, p.getLocation().getBlock()); + IrisTerrainProvider prov = IrisWorlds.getProvider(sender.player().getWorld()); + + if(prov == null) + { + sender.sendMessage("You can only use /iris loot in a studio world of iris."); + return true; + } + + try + { + if(Iris.proj.getActiveProject().getActiveProvider().getGlUpdate() == null) + { + sender.sendMessage("You can only use /iris loot in a studio world of iris."); + return true; + } + } + + catch(Throwable e) + { + sender.sendMessage("You can only use /iris loot in a studio world of iris."); + return true; + } + + prov.initGLUpdate(); + KList tables = prov.getGlUpdate().getLootTables(RNG.r, p.getLocation().getBlock()); Inventory inv = Bukkit.createInventory(null, 27 * 2); - Iris.proj.getActiveProject().getActiveProvider().getGlUpdate().addItems(true, inv, RNG.r, tables, InventorySlotType.STORAGE, p.getLocation().getBlockX(), p.getLocation().getBlockY(), p.getLocation().getBlockZ(), 1); + + try + { + Iris.proj.getActiveProject().getActiveProvider().getGlUpdate().addItems(true, inv, RNG.r, tables, InventorySlotType.STORAGE, p.getLocation().getBlockX(), p.getLocation().getBlockY(), p.getLocation().getBlockZ(), 1); + } + + catch(Throwable e) + { + sender.sendMessage("You can only use /iris loot in a studio world of iris."); + return true; + } + p.openInventory(inv); for(IrisLootTable i : tables) diff --git a/src/main/java/com/volmit/iris/command/CommandIrisStudioSummon.java b/src/main/java/com/volmit/iris/command/CommandIrisStudioSummon.java new file mode 100644 index 000000000..0eb66b5ef --- /dev/null +++ b/src/main/java/com/volmit/iris/command/CommandIrisStudioSummon.java @@ -0,0 +1,80 @@ +package com.volmit.iris.command; + +import org.bukkit.World; +import org.bukkit.entity.Player; + +import com.volmit.iris.Iris; +import com.volmit.iris.IrisSettings; +import com.volmit.iris.gen.IrisTerrainProvider; +import com.volmit.iris.gen.provisions.ProvisionBukkit; +import com.volmit.iris.gen.scaffold.IrisWorlds; +import com.volmit.iris.object.IrisEntity; +import com.volmit.iris.util.MortarCommand; +import com.volmit.iris.util.MortarSender; + +public class CommandIrisStudioSummon extends MortarCommand +{ + public CommandIrisStudioSummon() + { + super("summon", "spawnmob"); + setDescription("Spawn an Iris entity"); + requiresPermission(Iris.perm.studio); + setCategory("Summon"); + } + + @Override + public boolean handle(MortarSender sender, String[] args) + { + if(!IrisSettings.get().isStudio()) + { + sender.sendMessage("To use Iris Studio, please enable studio in Iris/settings.json"); + return true; + } + + if(sender.isPlayer()) + { + Player p = sender.player(); + World world = p.getWorld(); + if(!(world.getGenerator() instanceof ProvisionBukkit)) + { + sender.sendMessage("You must be in an iris world."); + return true; + } + + IrisTerrainProvider g = IrisWorlds.getProvider(world); + if(args.length == 0) + { + for(String i : g.getData().getEntityLoader().getPossibleKeys()) + { + sender.sendMessage("- " + i); + } + } + + else + { + IrisEntity e = g.getData().getEntityLoader().load(args[0]); + + if(e == null) + { + sender.sendMessage("Couldnt find entity " + args[0] + ". Use '/iris std summon' to see a list of iris entities."); + return true; + } + + e.spawn(g, sender.player().getLocation().clone().add(0, 3, 0)); + } + } + + else + { + sender.sendMessage("Players only."); + } + + return true; + } + + @Override + protected String getArgsUsage() + { + return ""; + } +} diff --git a/src/main/java/com/volmit/iris/command/CommandIrisStudioTP.java b/src/main/java/com/volmit/iris/command/CommandIrisStudioTP.java new file mode 100644 index 000000000..43725d8f5 --- /dev/null +++ b/src/main/java/com/volmit/iris/command/CommandIrisStudioTP.java @@ -0,0 +1,52 @@ +package com.volmit.iris.command; + +import com.volmit.iris.Iris; +import com.volmit.iris.IrisSettings; +import com.volmit.iris.util.MortarCommand; +import com.volmit.iris.util.MortarSender; + +public class CommandIrisStudioTP extends MortarCommand +{ + public CommandIrisStudioTP() + { + super("tp"); + requiresPermission(Iris.perm.studio); + setDescription("Go to the spawn of the currently open studio world."); + setCategory("Studio"); + } + + @Override + public boolean handle(MortarSender sender, String[] args) + { + if(!IrisSettings.get().isStudio()) + { + sender.sendMessage("To use Iris Studio, please enable studio in Iris/settings.json"); + return true; + } + + if(!Iris.proj.isProjectOpen()) + { + sender.sendMessage("There is not a studio currently loaded."); + return true; + } + + try + { + sender.sendMessage("Teleporting you to the active studio world."); + sender.player().teleport(Iris.proj.getActiveProject().getActiveProvider().getTarget().getRealWorld().getSpawnLocation()); + } + + catch(Throwable e) + { + sender.sendMessage("Failed to teleport to the studio world. Try re-opening the project."); + } + + return true; + } + + @Override + protected String getArgsUsage() + { + return ""; + } +} diff --git a/src/main/java/com/volmit/iris/command/CommandIrisStudioUpdate.java b/src/main/java/com/volmit/iris/command/CommandIrisStudioUpdate.java index c08af922b..1c2ac6a39 100644 --- a/src/main/java/com/volmit/iris/command/CommandIrisStudioUpdate.java +++ b/src/main/java/com/volmit/iris/command/CommandIrisStudioUpdate.java @@ -31,7 +31,15 @@ public class CommandIrisStudioUpdate extends MortarCommand return true; } - new IrisProject(Iris.proj.getWorkspaceFolder(args[0])).updateWorkspace(); + if(new IrisProject(Iris.proj.getWorkspaceFolder(args[0])).updateWorkspace()) + { + sender.sendMessage("Updated Code Workspace for " + args[0]); + } + + else + { + sender.sendMessage("Invalid project: " + args[0] + ". Try deleting the code-workspace file and try again."); + } return true; } diff --git a/src/main/java/com/volmit/iris/command/CommandIrisWhat.java b/src/main/java/com/volmit/iris/command/CommandIrisWhat.java index b84313769..6c68de508 100644 --- a/src/main/java/com/volmit/iris/command/CommandIrisWhat.java +++ b/src/main/java/com/volmit/iris/command/CommandIrisWhat.java @@ -13,6 +13,9 @@ public class CommandIrisWhat extends MortarCommand @Command private CommandIrisWhatHand hand; + @Command + private CommandIrisWhatBiome biome; + public CommandIrisWhat() { super("what", "w", "?"); diff --git a/src/main/java/com/volmit/iris/command/CommandIrisWhatBiome.java b/src/main/java/com/volmit/iris/command/CommandIrisWhatBiome.java new file mode 100644 index 000000000..57b28b6ce --- /dev/null +++ b/src/main/java/com/volmit/iris/command/CommandIrisWhatBiome.java @@ -0,0 +1,59 @@ +package com.volmit.iris.command; + +import org.bukkit.World; +import org.bukkit.entity.Player; + +import com.volmit.iris.Iris; +import com.volmit.iris.gen.IrisTerrainProvider; +import com.volmit.iris.gen.scaffold.IrisWorlds; +import com.volmit.iris.object.IrisBiome; +import com.volmit.iris.util.MortarCommand; +import com.volmit.iris.util.MortarSender; + +public class CommandIrisWhatBiome extends MortarCommand +{ + public CommandIrisWhatBiome() + { + super("biome", "bi"); + setDescription("Get the biome data you are in."); + requiresPermission(Iris.perm.studio); + setCategory("Wut"); + setDescription("What biome am i In"); + } + + @Override + public boolean handle(MortarSender sender, String[] args) + { + if(sender.isPlayer()) + { + Player p = sender.player(); + World w = p.getWorld(); + + try + { + + IrisTerrainProvider g = IrisWorlds.getProvider(w); + IrisBiome b = g.sampleTrueBiome(p.getLocation().getBlockX(), p.getLocation().getBlockY(), p.getLocation().getBlockZ()); + sender.sendMessage("IBiome: " + b.getLoadKey() + " (" + b.getDerivative().name() + ")"); + } + + catch(Throwable e) + { + sender.sendMessage("Non-Iris Biome: " + p.getLocation().getBlock().getBiome().name()); + } + } + + else + { + sender.sendMessage("Players only."); + } + + return true; + } + + @Override + protected String getArgsUsage() + { + return ""; + } +} diff --git a/src/main/java/com/volmit/iris/command/CommandIrisWhatBlock.java b/src/main/java/com/volmit/iris/command/CommandIrisWhatBlock.java index 464040f93..3c34cec02 100644 --- a/src/main/java/com/volmit/iris/command/CommandIrisWhatBlock.java +++ b/src/main/java/com/volmit/iris/command/CommandIrisWhatBlock.java @@ -5,7 +5,9 @@ import org.bukkit.block.data.BlockData; import org.bukkit.entity.Player; import com.volmit.iris.Iris; +import com.volmit.iris.util.B; import com.volmit.iris.util.C; +import com.volmit.iris.util.FastBlockData; import com.volmit.iris.util.MortarCommand; import com.volmit.iris.util.MortarSender; @@ -27,9 +29,45 @@ public class CommandIrisWhatBlock extends MortarCommand { Player p = sender.player(); BlockData bd = p.getTargetBlockExact(128, FluidCollisionMode.NEVER).getBlockData(); - if(bd != null) { + if(bd != null) + { sender.sendMessage("Material: " + C.GREEN + bd.getMaterial().name()); sender.sendMessage("Full: " + C.WHITE + bd.getAsString(true)); + + if(B.isStorage(FastBlockData.of(bd))) + { + sender.sendMessage(C.YELLOW + "* Storage Block (Loot Capable)"); + } + + if(B.isLit(FastBlockData.of(bd))) + { + sender.sendMessage(C.YELLOW + "* Lit Block (Light Capable)"); + } + + if(B.isFoliage(FastBlockData.of(bd))) + { + sender.sendMessage(C.YELLOW + "* Foliage Block"); + } + + if(B.isDecorant(FastBlockData.of(bd))) + { + sender.sendMessage(C.YELLOW + "* Decorant Block"); + } + + if(B.isFluid(FastBlockData.of(bd))) + { + sender.sendMessage(C.YELLOW + "* Fluid Block"); + } + + if(B.isFoliagePlantable(FastBlockData.of(bd))) + { + sender.sendMessage(C.YELLOW + "* Plantable Foliage Block"); + } + + if(B.isSolid(FastBlockData.of(bd))) + { + sender.sendMessage(C.YELLOW + "* Solid Block"); + } } } diff --git a/src/main/java/com/volmit/iris/gen/ContextualTerrainProvider.java b/src/main/java/com/volmit/iris/gen/ContextualTerrainProvider.java index 6384df3fb..566f97e78 100644 --- a/src/main/java/com/volmit/iris/gen/ContextualTerrainProvider.java +++ b/src/main/java/com/volmit/iris/gen/ContextualTerrainProvider.java @@ -24,6 +24,7 @@ import org.bukkit.event.world.WorldUnloadEvent; import com.volmit.iris.Iris; import com.volmit.iris.gen.atomics.AtomicCache; import com.volmit.iris.gen.atomics.AtomicMulticache; +import com.volmit.iris.gen.scaffold.GeneratedChunk; import com.volmit.iris.gen.scaffold.IrisContext; import com.volmit.iris.gen.scaffold.IrisMetrics; import com.volmit.iris.gen.scaffold.Provisioned; @@ -88,7 +89,7 @@ public abstract class ContextualTerrainProvider implements TerrainProvider, List tickLatch = new ChronoLatch(650); perSecond = new ChronoLatch(1000); hlast = M.ms(); - cache = new AtomicMulticache((IrisTerrainProvider) this); + cache = new AtomicMulticache((SkyTerrainProvider) this); CNG.creates = 0; generated = 0; ticks = 0; @@ -112,7 +113,7 @@ public abstract class ContextualTerrainProvider implements TerrainProvider, List warnings.add(warning); } - protected abstract void onGenerate(RNG masterRandom, int x, int z, TerrainChunk chunk); + protected abstract GeneratedChunk onGenerate(RNG masterRandom, int x, int z, TerrainChunk chunk); protected abstract void onInit(RNG masterRandom); @@ -382,7 +383,7 @@ public abstract class ContextualTerrainProvider implements TerrainProvider, List } @Override - public void generate(Random no, int x, int z, TerrainChunk terrain) + public GeneratedChunk generate(Random no, int x, int z, TerrainChunk terrain) { setHotloadable(false); if(!isDev()) @@ -394,20 +395,20 @@ public abstract class ContextualTerrainProvider implements TerrainProvider, List if(failing) { generateFailure(terrain); - return; + return GeneratedChunk.builder().build(); } try { RNG random = new RNG(getTarget().getSeed()); init(random.nextParallelRNG(0)); - onGenerate(random, x, z, terrain); + GeneratedChunk c = onGenerate(random, x, z, terrain); generated++; long hits = CNG.hits; CNG.hits = 0; Iris.instance.hit(hits); setHotloadable(true); - return; + return c; } catch(Throwable e) @@ -417,6 +418,7 @@ public abstract class ContextualTerrainProvider implements TerrainProvider, List setHotloadable(true); generateFailure(terrain); + return GeneratedChunk.builder().build(); } private void doCheckHotload() @@ -468,7 +470,6 @@ public abstract class ContextualTerrainProvider implements TerrainProvider, List Iris.instance.imsg(i, C.DARK_RED + "Iris Generator has crashed!"); Iris.instance.imsg(i, C.RED + "- Check the console for the error."); Iris.instance.imsg(i, C.RED + "- To Regen, use /iris std open "); - Iris.instance.imsg(i, C.RED + "- To Retry the chunk, use /iris world retry"); } }); diff --git a/src/main/java/com/volmit/iris/gen/DimensionalTerrainProvider.java b/src/main/java/com/volmit/iris/gen/DimensionalTerrainProvider.java index 9baa4450b..629d6a2d7 100644 --- a/src/main/java/com/volmit/iris/gen/DimensionalTerrainProvider.java +++ b/src/main/java/com/volmit/iris/gen/DimensionalTerrainProvider.java @@ -26,6 +26,7 @@ import lombok.EqualsAndHashCode; public abstract class DimensionalTerrainProvider extends ContextualTerrainProvider { private String dimensionName; + private IrisDimension forceDimension; protected static final FastBlockData AIR = FastBlockData.of(Material.AIR); protected static final FastBlockData CAVE_AIR = B.get("CAVE_AIR"); protected static final FastBlockData BEDROCK = FastBlockData.of(Material.BEDROCK); @@ -35,6 +36,7 @@ public abstract class DimensionalTerrainProvider extends ContextualTerrainProvid { super(t); setDimensionName(dimensionName); + setForceDimension(null); if(getDimensionName().isEmpty()) { @@ -99,6 +101,11 @@ public abstract class DimensionalTerrainProvider extends ContextualTerrainProvid } } + protected void forceDimension(IrisDimension sky) + { + setForceDimension(sky); + } + protected void useDefaultDimensionSetupNOW() { @@ -124,6 +131,11 @@ public abstract class DimensionalTerrainProvider extends ContextualTerrainProvid public IrisDimension getDimension() { + if(forceDimension != null) + { + return forceDimension; + } + IrisDimension d = loadDimension(getDimensionName()); return d; diff --git a/src/main/java/com/volmit/iris/gen/IrisTerrainProvider.java b/src/main/java/com/volmit/iris/gen/IrisTerrainProvider.java index 09593e05e..3833a31ca 100644 --- a/src/main/java/com/volmit/iris/gen/IrisTerrainProvider.java +++ b/src/main/java/com/volmit/iris/gen/IrisTerrainProvider.java @@ -20,6 +20,7 @@ import org.bukkit.util.BlockVector; import com.volmit.iris.Iris; import com.volmit.iris.IrisSettings; import com.volmit.iris.gen.atomics.AtomicRegionData; +import com.volmit.iris.gen.scaffold.GeneratedChunk; import com.volmit.iris.gen.scaffold.IrisContext; import com.volmit.iris.gen.scaffold.IrisGenConfiguration; import com.volmit.iris.gen.scaffold.TerrainChunk; @@ -91,18 +92,19 @@ public class IrisTerrainProvider extends SkyTerrainProvider implements IrisConte } @Override - public void generate(Random no, int x, int z, TerrainChunk terrain) + public GeneratedChunk generate(Random no, int x, int z, TerrainChunk terrain) { PrecisionStopwatch s = PrecisionStopwatch.start(); - super.generate(no, x, z, terrain); + GeneratedChunk c = super.generate(no, x, z, terrain); s.end(); getMetrics().getTotal().put(s.getMilliseconds()); + return c; } @Override - protected void onGenerate(RNG random, int x, int z, TerrainChunk terrain) + protected GeneratedChunk onGenerate(RNG random, int x, int z, TerrainChunk terrain) { - super.onGenerate(random, x, z, terrain); + return super.onGenerate(random, x, z, terrain); } public void onInit(RNG rng) @@ -141,7 +143,15 @@ public class IrisTerrainProvider extends SkyTerrainProvider implements IrisConte { spawnable = true; super.onTick(ticks); - tickEffects(); + try + { + tickEffects(); + } + + catch(Throwable e) + { + + } } protected void tickEffects() @@ -489,66 +499,79 @@ public class IrisTerrainProvider extends SkyTerrainProvider implements IrisConte @Override protected void onSpawn(EntitySpawnEvent e) { - if(isSpawnable()) + if(getTarget().getRealWorld() == null || !getTarget().getRealWorld().equals(e.getEntity().getWorld())) { - if(!IrisSettings.get().isSystemEntitySpawnOverrides()) + return; + } + + try + { + if(isSpawnable()) { - return; - } + if(!IrisSettings.get().isSystemEntitySpawnOverrides()) + { + return; + } - int x = e.getEntity().getLocation().getBlockX(); - int y = e.getEntity().getLocation().getBlockY(); - int z = e.getEntity().getLocation().getBlockZ(); - IrisDimension dim = getDimension(); - IrisRegion region = sampleRegion(x, z); - IrisBiome above = sampleTrueBiome(x, z); - IrisBiome below = sampleTrueBiome(x, y, z); + int x = e.getEntity().getLocation().getBlockX(); + int y = e.getEntity().getLocation().getBlockY(); + int z = e.getEntity().getLocation().getBlockZ(); + IrisDimension dim = getDimension(); + IrisRegion region = sampleRegion(x, z); + IrisBiome above = sampleTrueBiome(x, z); + IrisBiome below = sampleTrueBiome(x, y, z); - if(above.getLoadKey().equals(below.getLoadKey())) - { - below = null; - } + if(above.getLoadKey().equals(below.getLoadKey())) + { + below = null; + } - IrisStructureResult res = getStructure(x, y, z); + IrisStructureResult res = getStructure(x, y, z); - if(res != null && res.getTile() != null) - { - if(trySpawn(res.getTile().getEntitySpawnOverrides(), e)) + if(res != null && res.getTile() != null) + { + if(trySpawn(res.getTile().getEntitySpawnOverrides(), e)) + { + return; + } + } + + if(res != null && res.getStructure() != null) + { + if(trySpawn(res.getStructure().getEntitySpawnOverrides(), e)) + { + return; + } + } + + if(below != null) + { + if(trySpawn(below.getEntitySpawnOverrides(), e)) + { + return; + } + } + + if(trySpawn(above.getEntitySpawnOverrides(), e)) + { + return; + } + + if(trySpawn(region.getEntitySpawnOverrides(), e)) + { + return; + } + + if(trySpawn(dim.getEntitySpawnOverrides(), e)) { return; } } + } - if(res != null && res.getStructure() != null) - { - if(trySpawn(res.getStructure().getEntitySpawnOverrides(), e)) - { - return; - } - } + catch(Throwable xe) + { - if(below != null) - { - if(trySpawn(below.getEntitySpawnOverrides(), e)) - { - return; - } - } - - if(trySpawn(above.getEntitySpawnOverrides(), e)) - { - return; - } - - if(trySpawn(region.getEntitySpawnOverrides(), e)) - { - return; - } - - if(trySpawn(dim.getEntitySpawnOverrides(), e)) - { - return; - } } } @@ -604,7 +627,7 @@ public class IrisTerrainProvider extends SkyTerrainProvider implements IrisConte { if(getDimension() == null) { - return false; + return true; } return getDimension().isVanillaStructures(); diff --git a/src/main/java/com/volmit/iris/gen/ParallaxTerrainProvider.java b/src/main/java/com/volmit/iris/gen/ParallaxTerrainProvider.java index 17a2fd27a..82d7f3457 100644 --- a/src/main/java/com/volmit/iris/gen/ParallaxTerrainProvider.java +++ b/src/main/java/com/volmit/iris/gen/ParallaxTerrainProvider.java @@ -184,16 +184,19 @@ public abstract class ParallaxTerrainProvider extends TopographicTerrainProvider return new AtomicSliverMap(); } - @Override - public List getPopulators() + public void initGLUpdate() { - List g = new KList<>(); - if(getGlUpdate() == null) { setGlUpdate(new GenLayerUpdate(this)); } + } + @Override + public List getPopulators() + { + List g = new KList<>(); + initGLUpdate(); g.add(getGlUpdate()); return g; } @@ -447,11 +450,21 @@ public abstract class ParallaxTerrainProvider extends TopographicTerrainProvider { for(IrisStructurePlacement k : r.getStructures()) { + if(k == null) + { + continue; + } + k.place(this, random.nextParallelRNG(2228 * 2 * g++), i, j); } for(IrisStructurePlacement k : b.getStructures()) { + if(k == null) + { + continue; + } + k.place(this, random.nextParallelRNG(-22228 * 4 * g++), i, j); } diff --git a/src/main/java/com/volmit/iris/gen/ParallelTerrainProvider.java b/src/main/java/com/volmit/iris/gen/ParallelTerrainProvider.java index 867bebad4..6059aa10b 100644 --- a/src/main/java/com/volmit/iris/gen/ParallelTerrainProvider.java +++ b/src/main/java/com/volmit/iris/gen/ParallelTerrainProvider.java @@ -3,6 +3,7 @@ package com.volmit.iris.gen; import com.volmit.iris.Iris; import com.volmit.iris.gen.atomics.AtomicSliver; import com.volmit.iris.gen.atomics.AtomicSliverMap; +import com.volmit.iris.gen.scaffold.GeneratedChunk; import com.volmit.iris.gen.scaffold.TerrainChunk; import com.volmit.iris.gen.scaffold.TerrainTarget; import com.volmit.iris.util.BiomeMap; @@ -44,7 +45,7 @@ public abstract class ParallelTerrainProvider extends DimensionalTerrainProvider Iris.info("Thread Count changed to " + getThreads()); } - protected abstract void onGenerateColumn(int cx, int cz, int wx, int wz, int x, int z, AtomicSliver sliver, BiomeMap biomeMap, boolean sampled); + protected abstract int onGenerateColumn(int cx, int cz, int wx, int wz, int x, int z, AtomicSliver sliver, BiomeMap biomeMap, boolean sampled); protected void onGenerateColumn(int cx, int cz, int wx, int wz, int x, int z, AtomicSliver sliver, BiomeMap biomeMap) { @@ -62,14 +63,14 @@ public abstract class ParallelTerrainProvider extends DimensionalTerrainProvider return onSampleColumnHeight(x >> 4, z >> 4, x, z, x & 15, z & 15); } - protected void onGenerate(RNG random, int x, int z, TerrainChunk terrain) + protected GeneratedChunk onGenerate(RNG random, int x, int z, TerrainChunk terrain) { PrecisionStopwatch p = PrecisionStopwatch.start(); AtomicSliverMap map = new AtomicSliverMap(); HeightMap height = new HeightMap(); String key = "c" + x + "," + z; BiomeMap biomeMap = new BiomeMap(); - int ii, jj; + int ii; onPreGenerate(random, x, z, terrain, height, biomeMap, map); for(ii = 0; ii < 16; ii++) @@ -77,14 +78,14 @@ public abstract class ParallelTerrainProvider extends DimensionalTerrainProvider int i = ii; int wx = (x * 16) + i; - for(jj = 0; jj < 16; jj++) + getAccelerant().queue(key, () -> { - int j = jj; - int wz = (z * 16) + j; - AtomicSliver sliver = map.getSliver(i, j); - - getAccelerant().queue(key, () -> + for(int jj = 0; jj < 16; jj++) { + int j = jj; + int wz = (z * 16) + j; + AtomicSliver sliver = map.getSliver(i, j); + try { onGenerateColumn(x, z, wx, wz, i, j, sliver, biomeMap); @@ -94,8 +95,8 @@ public abstract class ParallelTerrainProvider extends DimensionalTerrainProvider { fail(e); } - }); - } + } + }); } accelerant.waitFor(key); @@ -103,6 +104,14 @@ public abstract class ParallelTerrainProvider extends DimensionalTerrainProvider getMetrics().getTerrain().put(p.getMilliseconds()); p = PrecisionStopwatch.start(); onPostGenerate(random, x, z, terrain, height, biomeMap, map); + return GeneratedChunk.builder() + .biomeMap(biomeMap) + .sliverMap(map) + .height(height) + .terrain(terrain) + .x(x) + .z(z) + .build(); } protected void onClose() diff --git a/src/main/java/com/volmit/iris/gen/PostBlockTerrainProvider.java b/src/main/java/com/volmit/iris/gen/PostBlockTerrainProvider.java index 72cd02ea8..01eb44e3f 100644 --- a/src/main/java/com/volmit/iris/gen/PostBlockTerrainProvider.java +++ b/src/main/java/com/volmit/iris/gen/PostBlockTerrainProvider.java @@ -4,6 +4,7 @@ import org.bukkit.generator.ChunkGenerator.ChunkData; import com.volmit.iris.Iris; import com.volmit.iris.gen.post.PostMasterPatcher; +import com.volmit.iris.gen.scaffold.GeneratedChunk; import com.volmit.iris.gen.scaffold.TerrainChunk; import com.volmit.iris.gen.scaffold.TerrainTarget; import com.volmit.iris.util.CaveResult; @@ -39,13 +40,13 @@ public abstract class PostBlockTerrainProvider extends ParallaxTerrainProvider i } @Override - protected void onGenerate(RNG random, int x, int z, TerrainChunk terrain) + protected GeneratedChunk onGenerate(RNG random, int x, int z, TerrainChunk terrain) { - super.onGenerate(random, x, z, terrain); + GeneratedChunk map = super.onGenerate(random, x, z, terrain); if(!getDimension().isPostProcessing()) { - return; + return map; } int rx, i; @@ -74,6 +75,7 @@ public abstract class PostBlockTerrainProvider extends ParallaxTerrainProvider i p.end(); getMetrics().getPost().put(p.getMilliseconds()); + return map; } @Override diff --git a/src/main/java/com/volmit/iris/gen/SkyTerrainProvider.java b/src/main/java/com/volmit/iris/gen/SkyTerrainProvider.java index 37f25bc29..fb90ad54a 100644 --- a/src/main/java/com/volmit/iris/gen/SkyTerrainProvider.java +++ b/src/main/java/com/volmit/iris/gen/SkyTerrainProvider.java @@ -1,5 +1,6 @@ package com.volmit.iris.gen; +import com.volmit.iris.gen.scaffold.GeneratedChunk; import com.volmit.iris.gen.scaffold.TerrainChunk; import com.volmit.iris.gen.scaffold.TerrainTarget; import com.volmit.iris.util.RNG; @@ -12,8 +13,9 @@ public abstract class SkyTerrainProvider extends PostBlockTerrainProvider } @Override - protected void onGenerate(RNG random, int x, int z, TerrainChunk terrain) + protected GeneratedChunk onGenerate(RNG random, int x, int z, TerrainChunk terrain) { - super.onGenerate(random, x, z, terrain); + GeneratedChunk gc = super.onGenerate(random, x, z, terrain); + return gc; } } diff --git a/src/main/java/com/volmit/iris/gen/TopographicTerrainProvider.java b/src/main/java/com/volmit/iris/gen/TopographicTerrainProvider.java index c0050331d..842cea0c9 100644 --- a/src/main/java/com/volmit/iris/gen/TopographicTerrainProvider.java +++ b/src/main/java/com/volmit/iris/gen/TopographicTerrainProvider.java @@ -12,6 +12,7 @@ import com.volmit.iris.gen.layer.GenLayerBiome; import com.volmit.iris.gen.layer.GenLayerCarve; import com.volmit.iris.gen.layer.GenLayerCave; import com.volmit.iris.gen.layer.GenLayerRavine; +import com.volmit.iris.gen.scaffold.GeneratedChunk; import com.volmit.iris.gen.scaffold.TerrainChunk; import com.volmit.iris.gen.scaffold.TerrainTarget; import com.volmit.iris.noise.CNG; @@ -19,6 +20,7 @@ import com.volmit.iris.object.DecorationPart; import com.volmit.iris.object.InferredType; import com.volmit.iris.object.IrisBiome; import com.volmit.iris.object.IrisBiomeDecorator; +import com.volmit.iris.object.IrisCaveFluid; import com.volmit.iris.object.IrisDepositGenerator; import com.volmit.iris.object.IrisDimension; import com.volmit.iris.object.IrisGenerator; @@ -119,7 +121,7 @@ public abstract class TopographicTerrainProvider extends ParallelTerrainProvider } @Override - protected void onGenerateColumn(int cx, int cz, int rx, int rz, int x, int z, AtomicSliver sliver, BiomeMap biomeMap, boolean sampled) + protected int onGenerateColumn(int cx, int cz, int rx, int rz, int x, int z, AtomicSliver sliver, BiomeMap biomeMap, boolean sampled) { if(x > 15 || x < 0 || z > 15 || z < 0) { @@ -141,6 +143,7 @@ public abstract class TopographicTerrainProvider extends ParallelTerrainProvider IrisBiome biome = sampleTrueBiome(rx, rz); IrisBiome carveBiome = null; Biome onlyBiome = Iris.biome3d ? null : biome.getGroundBiome(getMasterRandom(), rz, getDimension().getFluidHeight(), rx); + IrisCaveFluid forceFluid = getDimension().getForceFluid().hasFluid(getData()) ? getDimension().getForceFluid() : null; if(biome == null) { @@ -281,6 +284,11 @@ public abstract class TopographicTerrainProvider extends ParallelTerrainProvider decorateLand(crand, carveBiome, sliver, k, rx, rz, block); } + + if(forceFluid != null && B.isAir(block) && (forceFluid.isInverseHeight() ? k >= forceFluid.getFluidHeight() : k <= forceFluid.getFluidHeight())) + { + sliver.set(k, forceFluid.getFluid(getData())); + } } // Carve out biomes @@ -339,17 +347,21 @@ public abstract class TopographicTerrainProvider extends ParallelTerrainProvider { decorateLand(crand, biome, sliver, Math.max(height, fluidHeight), rx, rz, block); } + + return height; } @Override - protected void onGenerate(RNG random, int x, int z, TerrainChunk terrain) + protected GeneratedChunk onGenerate(RNG random, int x, int z, TerrainChunk terrain) { - super.onGenerate(random, x, z, terrain); + GeneratedChunk map = super.onGenerate(random, x, z, terrain); if(!getDimension().isVanillaCaves()) { generateDeposits(random.nextParallelRNG(x * ((z * 39) + 10000)).nextParallelRNG(z + z - x), terrain, x, z); } + + return map; } private void decorateLand(RNG rng, IrisBiome biome, AtomicSliver sliver, int k, int rx, int rz, FastBlockData block) diff --git a/src/main/java/com/volmit/iris/gen/atomics/AtomicMulticache.java b/src/main/java/com/volmit/iris/gen/atomics/AtomicMulticache.java index 90bf27ffe..ef7b05af0 100644 --- a/src/main/java/com/volmit/iris/gen/atomics/AtomicMulticache.java +++ b/src/main/java/com/volmit/iris/gen/atomics/AtomicMulticache.java @@ -3,7 +3,7 @@ package com.volmit.iris.gen.atomics; import com.github.benmanes.caffeine.cache.Caffeine; import com.github.benmanes.caffeine.cache.LoadingCache; import com.volmit.iris.IrisSettings; -import com.volmit.iris.gen.IrisTerrainProvider; +import com.volmit.iris.gen.SkyTerrainProvider; import com.volmit.iris.object.IrisBiome; import com.volmit.iris.object.IrisRegion; import com.volmit.iris.util.ChunkPosition; @@ -18,7 +18,7 @@ public class AtomicMulticache private final LoadingCache rawBiome; private final LoadingCache region; - public AtomicMulticache(IrisTerrainProvider gen) + public AtomicMulticache(SkyTerrainProvider gen) { height = Caffeine.newBuilder().maximumSize(getLimit()).build((c) -> gen.getNoiseHeight(c.getX(), c.getZ()) + gen.getFluidHeight()); carvedHeight = Caffeine.newBuilder().maximumSize(getLimit()).build((c) -> diff --git a/src/main/java/com/volmit/iris/gen/layer/GenLayerUpdate.java b/src/main/java/com/volmit/iris/gen/layer/GenLayerUpdate.java index 9393d803b..27ca46172 100644 --- a/src/main/java/com/volmit/iris/gen/layer/GenLayerUpdate.java +++ b/src/main/java/com/volmit/iris/gen/layer/GenLayerUpdate.java @@ -1,5 +1,6 @@ package com.volmit.iris.gen.layer; +import java.util.Arrays; import java.util.Random; import org.bukkit.Chunk; @@ -196,24 +197,16 @@ public class GenLayerUpdate extends BlockPopulator { KList items = new KList<>(); - for(int t = 0; t < gen.getDimension().getLootTries(); t++) + int b = 4; + for(IrisLootTable i : tables) { - int b = 4; - for(IrisLootTable i : tables) - { - b++; - items.addAll(i.getLoot(debug, rng.nextParallelRNG(345911 * -t), slot, x, y, z, t + b + b, mgf + b)); - } + b++; + items.addAll(i.getLoot(debug, items.isEmpty(), rng.nextParallelRNG(345911), slot, x, y, z, b + b, mgf + b)); + } - for(ItemStack i : items) - { - inv.addItem(i); - } - - if(items.isNotEmpty()) - { - break; - } + for(ItemStack i : items) + { + inv.addItem(i); } scramble(inv, rng); @@ -231,11 +224,12 @@ public class GenLayerUpdate extends BlockPopulator if(slot != null) { KList tables = getLootTables(rng.nextParallelRNG(4568111), b); + InventorySlotType slott = slot; try { InventoryHolder m = (InventoryHolder) b.getState(); - addItems(false, m.getInventory(), rng, tables, slot, rx, b.getY(), rz, 15); + addItems(false, m.getInventory(), rng, tables, slott, rx, b.getY(), rz, 15); } catch(Throwable ignored) @@ -247,64 +241,49 @@ public class GenLayerUpdate extends BlockPopulator public void scramble(Inventory inventory, RNG rng) { - KList v = new KList<>(); + ItemStack[] items = inventory.getContents(); + ItemStack[] nitems = new ItemStack[inventory.getSize()]; + System.arraycopy(items, 0, nitems, 0, items.length); + boolean packedFull = false; - for(ItemStack i : inventory.getContents()) + splitting: for(int i = 0; i < nitems.length; i++) { - if(i == null) - { - continue; - } + ItemStack is = nitems[i]; - v.add(i); + if(is != null && is.getAmount() > 1 && !packedFull) + { + for(int j = 0; j < nitems.length; j++) + { + if(nitems[j] == null) + { + int take = rng.nextInt(is.getAmount()); + take = take == 0 ? 1 : take; + is.setAmount(is.getAmount() - take); + nitems[j] = is.clone(); + nitems[j].setAmount(take); + continue splitting; + } + } + + packedFull = true; + } } - inventory.clear(); - int sz = inventory.getSize(); - int tr = 5; - - while(v.isNotEmpty()) + for(int i = 0; i < 4; i++) { - int slot = rng.i(0, sz - 1); - - if(inventory.getItem(slot) == null) - { - tr = tr < 5 ? tr + 1 : tr; - int pick = rng.i(0, v.size() - 1); - ItemStack g = v.get(pick); - - if(g.getAmount() == 1) - { - v.remove(pick); - inventory.setItem(pick, g); - } - - else - { - int portion = rng.i(1, g.getAmount() - 1); - ItemStack port = g.clone(); - port.setAmount(portion); - g.setAmount(g.getAmount() - portion); - v.add(g); - inventory.setItem(slot, port); - } - } - - else - { - tr--; - } - - if(tr <= 0) + try { + Arrays.parallelSort(nitems, (a, b) -> rng.nextInt()); break; } + + catch(Throwable e) + { + + } } - for(ItemStack i : v) - { - inventory.addItem(i); - } + inventory.setContents(nitems); } public void updateLight(Block b, FastBlockData data) diff --git a/src/main/java/com/volmit/iris/gen/nms/INMS.java b/src/main/java/com/volmit/iris/gen/nms/INMS.java new file mode 100644 index 000000000..61943a745 --- /dev/null +++ b/src/main/java/com/volmit/iris/gen/nms/INMS.java @@ -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> bindings = new KMap>() + .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(); + } +} diff --git a/src/main/java/com/volmit/iris/gen/nms/INMSBinding.java b/src/main/java/com/volmit/iris/gen/nms/INMSBinding.java new file mode 100644 index 000000000..861b13431 --- /dev/null +++ b/src/main/java/com/volmit/iris/gen/nms/INMSBinding.java @@ -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); + } +} diff --git a/src/main/java/com/volmit/iris/gen/nms/INMSCreator.java b/src/main/java/com/volmit/iris/gen/nms/INMSCreator.java new file mode 100644 index 000000000..02abc85b9 --- /dev/null +++ b/src/main/java/com/volmit/iris/gen/nms/INMSCreator.java @@ -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); +} diff --git a/src/main/java/com/volmit/iris/gen/nms/NMSCreator.java b/src/main/java/com/volmit/iris/gen/nms/NMSCreator.java deleted file mode 100644 index 18d28835d..000000000 --- a/src/main/java/com/volmit/iris/gen/nms/NMSCreator.java +++ /dev/null @@ -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); - } -} diff --git a/src/main/java/com/volmit/iris/gen/nms/NMSCreator141.java b/src/main/java/com/volmit/iris/gen/nms/NMSCreator141.java deleted file mode 100644 index 9231c1f17..000000000 --- a/src/main/java/com/volmit/iris/gen/nms/NMSCreator141.java +++ /dev/null @@ -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 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(); - } -} diff --git a/src/main/java/com/volmit/iris/gen/nms/NMSCreator151.java b/src/main/java/com/volmit/iris/gen/nms/NMSCreator151.java deleted file mode 100644 index b84b6e4a9..000000000 --- a/src/main/java/com/volmit/iris/gen/nms/NMSCreator151.java +++ /dev/null @@ -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 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(); - } -} diff --git a/src/main/java/com/volmit/iris/gen/nms/NMSCreator161.java b/src/main/java/com/volmit/iris/gen/nms/NMSCreator161.java deleted file mode 100644 index f2df0b366..000000000 --- a/src/main/java/com/volmit/iris/gen/nms/NMSCreator161.java +++ /dev/null @@ -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 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 actualDimension = null; - switch(creator.environment()) - { - case NORMAL: - { - actualDimension = (ResourceKey) WorldDimension.OVERWORLD; - break; - } - case NETHER: - { - actualDimension = (ResourceKey) WorldDimension.THE_NETHER; - break; - } - case THE_END: - { - actualDimension = (ResourceKey) 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 registryreadops = (RegistryReadOps) 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 list = (List) 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(); - } -} diff --git a/src/main/java/com/volmit/iris/gen/nms/v16_2/NMSBinding16_2.java b/src/main/java/com/volmit/iris/gen/nms/v16_2/NMSBinding16_2.java new file mode 100644 index 000000000..7045e6101 --- /dev/null +++ b/src/main/java/com/volmit/iris/gen/nms/v16_2/NMSBinding16_2.java @@ -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 creator = new AtomicCache<>(); + + @Override + public INMSCreator getCreator() + { + return creator.aquire(() -> new NMSCreator16_2()); + } +} diff --git a/src/main/java/com/volmit/iris/gen/nms/v16_2/NMSChunkGenerator16_2_BACKUP.java b/src/main/java/com/volmit/iris/gen/nms/v16_2/NMSChunkGenerator16_2_BACKUP.java new file mode 100644 index 000000000..72de474dd --- /dev/null +++ b/src/main/java/com/volmit/iris/gen/nms/v16_2/NMSChunkGenerator16_2_BACKUP.java @@ -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 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 h; + private final int x; + + public NMSChunkGenerator16_2_BACKUP(WorldChunkManager worldchunkmanager, long i, Supplier supplier) + { + this(worldchunkmanager, worldchunkmanager, i, supplier); + } + + private NMSChunkGenerator16_2_BACKUP(WorldChunkManager worldchunkmanager, WorldChunkManager worldchunkmanager1, long i, Supplier 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 a() + { + return ChunkGeneratorAbstract.d; + } + + public boolean a(long i, ResourceKey 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) null); + return new BlockColumn(aiblockdata); + } + + private int a(int i, int j, @Nullable IBlockData[] aiblockdata, @Nullable Predicate 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 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 objectlist = new ObjectArrayList(10); + ObjectList objectlist1 = new ObjectArrayList(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 objectlistiterator = objectlist.iterator(); + ObjectListIterator 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 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); + } +} diff --git a/src/main/java/com/volmit/iris/gen/nms/v16_2/NMSChunkGenerator16_2_PAPER.java b/src/main/java/com/volmit/iris/gen/nms/v16_2/NMSChunkGenerator16_2_PAPER.java new file mode 100644 index 000000000..bc67f870a --- /dev/null +++ b/src/main/java/com/volmit/iris/gen/nms/v16_2/NMSChunkGenerator16_2_PAPER.java @@ -0,0 +1,730 @@ +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.Supplier; + +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.gen.scaffold.ProvisionedHolder; +import com.volmit.iris.gen.scaffold.TerrainProvider; +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 net.minecraft.server.v1_16_R2.BiomeBase; +import net.minecraft.server.v1_16_R2.BiomeManager; +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.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.WorldChunkManager; +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; + +@SuppressWarnings("deprecation") +public class NMSChunkGenerator16_2_PAPER extends ChunkGenerator implements ProvisionedHolder +{ + private static final IBlockData k = Blocks.AIR.getBlockData(); + private final Provisioned provisioned; + private final int maxHeight; + private final int xzSize; + protected final IBlockData f; + protected final IBlockData g; + private final long w; + protected final Supplier h; + private final O ws; + private BlockColumn BC; + + public NMSChunkGenerator16_2_PAPER(Provisioned p, O ws, WorldChunkManager worldchunkmanager, long i, Supplier supplier) + { + this(p, ws, worldchunkmanager, worldchunkmanager, i, supplier); + } + + private NMSChunkGenerator16_2_PAPER(Provisioned p, O ws, WorldChunkManager worldchunkmanager, WorldChunkManager worldchunkmanager1, long i, Supplier 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.f = generatorsettingbase.c(); + this.g = generatorsettingbase.d(); + this.xzSize = noisesettings.a() / this.maxHeight; + BC = new BlockColumn(new IBlockData[this.xzSize * this.maxHeight]); + } + + 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 a() + { + return ChunkGeneratorAbstract.d; + } + + public boolean a(long i, ResourceKey resourcekey) + { + return this.w == i && this.h.get().a(resourcekey); + } + + @Override + public int getBaseHeight(int i, int j, HeightMap.Type heightmap_type) + { + return 63; + } + + @Override + public IBlockAccess a(int x, int z) + { + return BC; + } + + 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_PAPER.k; + } + + return iblockdata; + } + + @Override + public void buildBase(RegionLimitedWorldAccess regionlimitedworldaccess, IChunkAccess ichunkaccess) + { + + } + + @Override + public void buildNoise(GeneratorAccess generatoraccess, StructureManager structuremanager, IChunkAccess ichunkaccess) + { + ObjectList objectlist = new ObjectArrayList(10); + ObjectList objectlist1 = new ObjectArrayList(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); + 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()); + } + + 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()); + } + + 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()); + } + + 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(); + // } + // 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++) + { + try + { + 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()); + } + + catch(Throwable e) + { + + } + } + } + } + + 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> structureGenerators = ((Map>>) new V(bbase).get("g")).getOrDefault(stage, Collections.emptyList()); + Iterator> iterator = structureGenerators.iterator(); + while(iterator.hasNext()) + { + var13 = (StructureGenerator) iterator.next(); + + if(var13.equals(StructureGenerator.VILLAGE)) + { + continue; + } + + if(var13.equals(StructureGenerator.JUNGLE_PYRAMID)) + { + continue; + } + + if(var13.equals(StructureGenerator.IGLOO)) + { + continue; + } + + if(var13.equals(StructureGenerator.NETHER_FOSSIL)) + { + continue; + } + + if(var13.equals(StructureGenerator.SHIPWRECK)) + { + continue; + } + + if(var13.equals(StructureGenerator.SHIPWRECK)) + { + continue; + } + + if(var13.equals(StructureGenerator.MONUMENT)) + { + continue; + } + + if(var13.equals(StructureGenerator.BASTION_REMNANT)) + { + continue; + } + + 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; + } + } + } + } + + @Override + public int getSeaLevel() + { + return ((IrisTerrainProvider) provisioned.getProvider()).getFluidHeight(); + } + + @Override + public List 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) + { + 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; + } + } + + @Override + public Provisioned getProvisioned() + { + return provisioned; + } + + @Override + public void clearRegeneratedLists() + { + getProvisioned().clearRegeneratedLists(); + } + + @Override + public TerrainProvider getProvider() + { + return getProvisioned().getProvider(); + } + + @Override + public void regenerate(int x, int z) + { + getProvisioned().regenerate(x, z); + } +} diff --git a/src/main/java/com/volmit/iris/gen/nms/v16_2/NMSChunkGenerator16_2_SPIGOT.java b/src/main/java/com/volmit/iris/gen/nms/v16_2/NMSChunkGenerator16_2_SPIGOT.java new file mode 100644 index 000000000..38c8942a6 --- /dev/null +++ b/src/main/java/com/volmit/iris/gen/nms/v16_2/NMSChunkGenerator16_2_SPIGOT.java @@ -0,0 +1,722 @@ +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.Supplier; + +import org.bukkit.Material; +import org.bukkit.block.Biome; +import org.bukkit.block.data.BlockData; +import org.bukkit.craftbukkit.libs.it.unimi.dsi.fastutil.objects.ObjectArrayList; +import org.bukkit.craftbukkit.libs.it.unimi.dsi.fastutil.objects.ObjectList; +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.gen.scaffold.ProvisionedHolder; +import com.volmit.iris.gen.scaffold.TerrainProvider; +import com.volmit.iris.util.O; +import com.volmit.iris.util.V; + +import net.minecraft.server.v1_16_R2.BiomeBase; +import net.minecraft.server.v1_16_R2.BiomeManager; +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.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.WorldChunkManager; +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; + +@SuppressWarnings("deprecation") +public class NMSChunkGenerator16_2_SPIGOT extends ChunkGenerator implements ProvisionedHolder +{ + private static final IBlockData k = Blocks.AIR.getBlockData(); + private final Provisioned provisioned; + private final int maxHeight; + private final int xzSize; + protected final IBlockData f; + protected final IBlockData g; + private final long w; + protected final Supplier h; + private final O ws; + private BlockColumn BC; + + public NMSChunkGenerator16_2_SPIGOT(Provisioned p, O ws, WorldChunkManager worldchunkmanager, long i, Supplier supplier) + { + this(p, ws, worldchunkmanager, worldchunkmanager, i, supplier); + } + + private NMSChunkGenerator16_2_SPIGOT(Provisioned p, O ws, WorldChunkManager worldchunkmanager, WorldChunkManager worldchunkmanager1, long i, Supplier 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.f = generatorsettingbase.c(); + this.g = generatorsettingbase.d(); + this.xzSize = noisesettings.a() / this.maxHeight; + BC = new BlockColumn(new IBlockData[this.xzSize * this.maxHeight]); + } + + 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 a() + { + return ChunkGeneratorAbstract.d; + } + + public boolean a(long i, ResourceKey resourcekey) + { + return this.w == i && this.h.get().a(resourcekey); + } + + @Override + public int getBaseHeight(int i, int j, HeightMap.Type heightmap_type) + { + return 63; + } + + @Override + public IBlockAccess a(int x, int z) + { + return BC; + } + + 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_SPIGOT.k; + } + + return iblockdata; + } + + @Override + public void buildBase(RegionLimitedWorldAccess regionlimitedworldaccess, IChunkAccess ichunkaccess) + { + + } + + @Override + public void buildNoise(GeneratorAccess generatoraccess, StructureManager structuremanager, IChunkAccess ichunkaccess) + { + ObjectList objectlist = new ObjectArrayList(10); + ObjectList objectlist1 = new ObjectArrayList(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); + 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()); + } + + 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()); + } + + 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()); + } + + 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(); + // } + // 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> structureGenerators = ((Map>>) new V(bbase).get("g")).getOrDefault(stage, Collections.emptyList()); + Iterator> iterator = structureGenerators.iterator(); + while(iterator.hasNext()) + { + var13 = (StructureGenerator) iterator.next(); + + if(var13.equals(StructureGenerator.VILLAGE)) + { + continue; + } + + if(var13.equals(StructureGenerator.JUNGLE_PYRAMID)) + { + continue; + } + + if(var13.equals(StructureGenerator.IGLOO)) + { + continue; + } + + if(var13.equals(StructureGenerator.NETHER_FOSSIL)) + { + continue; + } + + if(var13.equals(StructureGenerator.SHIPWRECK)) + { + continue; + } + + if(var13.equals(StructureGenerator.SHIPWRECK)) + { + continue; + } + + if(var13.equals(StructureGenerator.MONUMENT)) + { + continue; + } + + if(var13.equals(StructureGenerator.BASTION_REMNANT)) + { + continue; + } + + 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; + } + } + } + } + + @Override + public int getSeaLevel() + { + return ((IrisTerrainProvider) provisioned.getProvider()).getFluidHeight(); + } + + @Override + public List 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) + { + 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; + } + } + + @Override + public Provisioned getProvisioned() + { + return provisioned; + } + + @Override + public void clearRegeneratedLists() + { + getProvisioned().clearRegeneratedLists(); + } + + @Override + public TerrainProvider getProvider() + { + return getProvisioned().getProvider(); + } + + @Override + public void regenerate(int x, int z) + { + getProvisioned().regenerate(x, z); + } +} diff --git a/src/main/java/com/volmit/iris/gen/nms/NMSCreator162.java b/src/main/java/com/volmit/iris/gen/nms/v16_2/NMSCreator16_2.java similarity index 81% rename from src/main/java/com/volmit/iris/gen/nms/NMSCreator162.java rename to src/main/java/com/volmit/iris/gen/nms/v16_2/NMSCreator16_2.java index 0171a6bd8..8d4f13b93 100644 --- a/src/main/java/com/volmit/iris/gen/nms/NMSCreator162.java +++ b/src/main/java/com/volmit/iris/gen/nms/v16_2/NMSCreator16_2.java @@ -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; @@ -7,7 +7,6 @@ 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; @@ -23,8 +22,13 @@ 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.IrisWorlds; +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; @@ -47,21 +52,23 @@ import net.minecraft.server.v1_16_R2.MobSpawnerPatrol; import net.minecraft.server.v1_16_R2.MobSpawnerPhantom; import net.minecraft.server.v1_16_R2.MobSpawnerTrader; import net.minecraft.server.v1_16_R2.NBTBase; -import net.minecraft.server.v1_16_R2.RegistryMaterials; 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 worlds = new V(server).get("worlds"); DedicatedServer console = new V(server).get("console"); @@ -121,7 +128,7 @@ public class NMSCreator162 } MinecraftServer.convertWorld(worldSession); final boolean hardcore = creator.hardcore(); - final RegistryReadOps registryreadops = (RegistryReadOps) RegistryReadOps.a((DynamicOps) DynamicOpsNBT.a, console.dataPackResources.h(), console.f); + final RegistryReadOps registryreadops = (RegistryReadOps) RegistryReadOps.a((DynamicOps) DynamicOpsNBT.a, console.dataPackResources.h(), getConsoleDimension(console)); WorldDataServer worlddata = (WorldDataServer) worldSession.a((DynamicOps) registryreadops, console.datapackconfiguration); if(worlddata == null) { @@ -130,7 +137,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()); @@ -143,22 +150,12 @@ public class NMSCreator162 } final long j = BiomeManager.a(creator.seed()); final List list = (List) ImmutableList.of((MobSpawner) new MobSpawnerPhantom(), (MobSpawner) new MobSpawnerPatrol(), (MobSpawner) new MobSpawnerCat(), (MobSpawner) new VillageSiege(), (MobSpawner) new MobSpawnerTrader((IWorldDataServer) worlddata)); - final RegistryMaterials registrymaterials = (RegistryMaterials) worlddata.getGeneratorSettings().d(); - 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) console.f.b(IRegistry.ay), (IRegistry) console.f.b(IRegistry.ar), new Random().nextLong()); - } - else - { - dimensionmanager = worlddimension.b(); - chunkgenerator = worlddimension.c(); - } - + long ll = creator.seed(); + dimensionmanager = (DimensionManager) getConsoleDimension(console).a().d(DimensionManager.OVERWORLD); + O ws = new O(); + chunkgenerator = PaperLib.isPaper() ? new NMSChunkGenerator16_2_PAPER(pro, ws, (WorldChunkManager) new WorldChunkManagerOverworld(ll, false, false, (IRegistry) getConsoleDimension(console).b(IRegistry.ay)), ll, () -> (GeneratorSettingBase) getConsoleDimension(console).b(IRegistry.ar).d(GeneratorSettingBase.c)) : new NMSChunkGenerator16_2_SPIGOT(pro, ws, (WorldChunkManager) new WorldChunkManagerOverworld(ll, false, false, (IRegistry) getConsoleDimension(console).b(IRegistry.ay)), ll, () -> (GeneratorSettingBase) getConsoleDimension(console).b(IRegistry.ar).d(GeneratorSettingBase.c)); final ResourceKey worldKey = (ResourceKey) ResourceKey.a(IRegistry.L, new MinecraftKey(name.toLowerCase(Locale.ENGLISH))); //@builder final WorldServer internal = new WorldServer((MinecraftServer) console, @@ -173,8 +170,10 @@ public class NMSCreator162 (List) ((creator.environment() == World.Environment.NORMAL) ? list : ImmutableList.of()), true, creator.environment(), - generator); + server.getGenerator(name)); //@done + IrisWorlds.register(internal.getWorld(), pro); + ws.set(internal); if(!worlds.containsKey(name.toLowerCase(Locale.ENGLISH))) { try @@ -189,10 +188,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 +207,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; + } } diff --git a/src/main/java/com/volmit/iris/gen/nms/v1X/NMSBinding1X.java b/src/main/java/com/volmit/iris/gen/nms/v1X/NMSBinding1X.java new file mode 100644 index 000000000..57eae74a4 --- /dev/null +++ b/src/main/java/com/volmit/iris/gen/nms/v1X/NMSBinding1X.java @@ -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 creator = new AtomicCache<>(); + + @Override + public INMSCreator getCreator() + { + return creator.aquire(() -> new NMSCreator1X()); + } +} diff --git a/src/main/java/com/volmit/iris/gen/nms/v1X/NMSCreator1X.java b/src/main/java/com/volmit/iris/gen/nms/v1X/NMSCreator1X.java new file mode 100644 index 000000000..987b0dcd2 --- /dev/null +++ b/src/main/java/com/volmit/iris/gen/nms/v1X/NMSCreator1X.java @@ -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(); + } +} diff --git a/src/main/java/com/volmit/iris/gen/post/PostMasterPatcher.java b/src/main/java/com/volmit/iris/gen/post/PostMasterPatcher.java index 34dcea43e..213181941 100644 --- a/src/main/java/com/volmit/iris/gen/post/PostMasterPatcher.java +++ b/src/main/java/com/volmit/iris/gen/post/PostMasterPatcher.java @@ -388,7 +388,7 @@ public class PostMasterPatcher extends IrisPostBlockFilter if(!cancel && isAirOrWater(x, c, z, currentPostX, currentPostZ, currentData)) { - Slab slab = (Slab) d.getBlockData(); + Slab slab = (Slab) d.getBlockData().clone(); slab.setType(Type.TOP); setPostBlock(x, c, z, d, currentPostX, currentPostZ, currentData); } diff --git a/src/main/java/com/volmit/iris/gen/provisions/ProvisionBukkit.java b/src/main/java/com/volmit/iris/gen/provisions/ProvisionBukkit.java index 872bce6f8..46a8b094e 100644 --- a/src/main/java/com/volmit/iris/gen/provisions/ProvisionBukkit.java +++ b/src/main/java/com/volmit/iris/gen/provisions/ProvisionBukkit.java @@ -15,6 +15,7 @@ import org.bukkit.generator.ChunkGenerator; import com.volmit.iris.Iris; import com.volmit.iris.gen.IrisTerrainProvider; +import com.volmit.iris.gen.scaffold.GeneratedChunk; import com.volmit.iris.gen.scaffold.HeightedFakeWorld; import com.volmit.iris.gen.scaffold.Provisioned; import com.volmit.iris.gen.scaffold.TerrainChunk; @@ -198,17 +199,7 @@ public class ProvisionBukkit extends ChunkGenerator implements Provisioned @Override public ChunkData generateChunkData(World world, Random random, int x, int z, BiomeGrid biome) { - cachedWorld = world; - if(!worldSet) - { - worldSet = true; - provider.getTarget().setRealWorld(world); - - if(world.getSpawnLocation().getY() == 0 && world.getSpawnLocation().getZ() == 0 && world.getSpawnLocation().getX() == 0) - { - Bukkit.getScheduler().scheduleSyncDelayedTask(Iris.instance, () -> fixSpawn(world)); - } - } + cacheWorld(world); if(precache.size() > 0) { @@ -226,6 +217,28 @@ public class ProvisionBukkit extends ChunkGenerator implements Provisioned return terrain.getRaw(); } + public GeneratedChunk generateNMSChunkData(World world, Random random, int x, int z, ChunkData nmsData, BiomeGrid biome) + { + cacheWorld(world); + TerrainChunk terrain = TerrainChunk.create(nmsData, biome); + return getProvider().generate(getRNG(world, x, z), x, z, terrain); + } + + private void cacheWorld(World world) + { + cachedWorld = world; + if(!worldSet) + { + worldSet = true; + provider.getTarget().setRealWorld(world); + + if(world.getSpawnLocation().getY() == 0 && world.getSpawnLocation().getZ() == 0 && world.getSpawnLocation().getX() == 0) + { + Bukkit.getScheduler().scheduleSyncDelayedTask(Iris.instance, () -> fixSpawn(world)); + } + } + } + private Random getRNG(World world, int x, int z) { cachedWorld = world; diff --git a/src/main/java/com/volmit/iris/gen/scaffold/GeneratedChunk.java b/src/main/java/com/volmit/iris/gen/scaffold/GeneratedChunk.java new file mode 100644 index 000000000..70e03d35b --- /dev/null +++ b/src/main/java/com/volmit/iris/gen/scaffold/GeneratedChunk.java @@ -0,0 +1,20 @@ +package com.volmit.iris.gen.scaffold; + +import com.volmit.iris.gen.atomics.AtomicSliverMap; +import com.volmit.iris.util.BiomeMap; +import com.volmit.iris.util.HeightMap; + +import lombok.Builder; +import lombok.Data; + +@Builder +@Data +public class GeneratedChunk +{ + private int x; + private int z; + private TerrainChunk terrain; + private HeightMap height; + private AtomicSliverMap sliverMap; + private BiomeMap biomeMap; +} diff --git a/src/main/java/com/volmit/iris/gen/scaffold/IrisWorlds.java b/src/main/java/com/volmit/iris/gen/scaffold/IrisWorlds.java index 7b4c071be..160aaa8b9 100644 --- a/src/main/java/com/volmit/iris/gen/scaffold/IrisWorlds.java +++ b/src/main/java/com/volmit/iris/gen/scaffold/IrisWorlds.java @@ -3,19 +3,53 @@ package com.volmit.iris.gen.scaffold; import org.bukkit.World; import com.volmit.iris.gen.IrisTerrainProvider; +import com.volmit.iris.gen.provisions.ProvisionBukkit; +import com.volmit.iris.util.KMap; public class IrisWorlds { + private static final KMap provisioned = new KMap<>(); + + public static void register(World w, Provisioned p) + { + provisioned.put(w.getUID().toString(), p); + } + public static boolean isIrisWorld(World world) { - return world.getGenerator() instanceof Provisioned; + if(provisioned.containsKey(world.getUID().toString())) + { + return true; + } + + return world.getGenerator() instanceof Provisioned || world.getGenerator() instanceof ProvisionedHolder; } public static IrisTerrainProvider getProvider(World world) { if(isIrisWorld(world)) { - return (IrisTerrainProvider) ((Provisioned) world.getGenerator()).getProvider(); + return (IrisTerrainProvider) getProvisioned(world).getProvider(); + } + + return null; + } + + public static ProvisionBukkit getProvisioned(World world) + { + if(isIrisWorld(world)) + { + if(provisioned.containsKey(world.getUID().toString())) + { + return (ProvisionBukkit) provisioned.get(world.getUID().toString()); + } + + if(world.getGenerator() instanceof ProvisionedHolder) + { + return (ProvisionBukkit) ((ProvisionedHolder) world.getGenerator()).getProvisioned(); + } + + return ((ProvisionBukkit) world.getGenerator()); } return null; diff --git a/src/main/java/com/volmit/iris/gen/scaffold/LinkedTerrainChunk.java b/src/main/java/com/volmit/iris/gen/scaffold/LinkedTerrainChunk.java index 9a5d8f06e..50658e2ec 100644 --- a/src/main/java/com/volmit/iris/gen/scaffold/LinkedTerrainChunk.java +++ b/src/main/java/com/volmit/iris/gen/scaffold/LinkedTerrainChunk.java @@ -23,6 +23,14 @@ public class LinkedTerrainChunk implements TerrainChunk this(null, maxHeight); } + public LinkedTerrainChunk(BiomeGrid storage, ChunkData data) + { + this.storage = storage; + rawChunkData = data; + biome2D = storage != null ? null : Iris.biome3d ? null : new Biome[256]; + biome3D = storage != null ? null : Iris.biome3d ? new IrisBiomeStorage() : null; + } + public LinkedTerrainChunk(BiomeGrid storage, int maxHeight) { this.storage = storage; diff --git a/src/main/java/com/volmit/iris/gen/scaffold/ProvisionedHolder.java b/src/main/java/com/volmit/iris/gen/scaffold/ProvisionedHolder.java new file mode 100644 index 000000000..a1fb62c1c --- /dev/null +++ b/src/main/java/com/volmit/iris/gen/scaffold/ProvisionedHolder.java @@ -0,0 +1,6 @@ +package com.volmit.iris.gen.scaffold; + +public interface ProvisionedHolder extends Provisioned +{ + public Provisioned getProvisioned(); +} diff --git a/src/main/java/com/volmit/iris/gen/scaffold/TerrainChunk.java b/src/main/java/com/volmit/iris/gen/scaffold/TerrainChunk.java index 6d7dfa286..d8fe1b974 100644 --- a/src/main/java/com/volmit/iris/gen/scaffold/TerrainChunk.java +++ b/src/main/java/com/volmit/iris/gen/scaffold/TerrainChunk.java @@ -23,6 +23,11 @@ public interface TerrainChunk extends BiomeGrid, ChunkData return create(world.getMaxHeight(), grid); } + public static TerrainChunk create(ChunkData raw, BiomeGrid grid) + { + return new LinkedTerrainChunk(grid, raw); + } + public static TerrainChunk create(int maxHeight, BiomeGrid grid) { return new LinkedTerrainChunk(grid, maxHeight); diff --git a/src/main/java/com/volmit/iris/gen/scaffold/TerrainProvider.java b/src/main/java/com/volmit/iris/gen/scaffold/TerrainProvider.java index 7f2e60eb2..d53e48a30 100644 --- a/src/main/java/com/volmit/iris/gen/scaffold/TerrainProvider.java +++ b/src/main/java/com/volmit/iris/gen/scaffold/TerrainProvider.java @@ -17,7 +17,7 @@ public interface TerrainProvider public BlockVector computeSpawn(Function allowed); - public void generate(Random random, int x, int z, TerrainChunk chunk); + public GeneratedChunk generate(Random random, int x, int z, TerrainChunk chunk); public boolean canSpawn(int x, int z); diff --git a/src/main/java/com/volmit/iris/generator/IrisTerrainProvider.java b/src/main/java/com/volmit/iris/generator/IrisTerrainProvider.java new file mode 100644 index 000000000..5d15576d9 --- /dev/null +++ b/src/main/java/com/volmit/iris/generator/IrisTerrainProvider.java @@ -0,0 +1,6 @@ +package com.volmit.iris.generator; + +public class IrisTerrainProvider +{ + +} diff --git a/src/main/java/com/volmit/iris/generator/atomics/Hunk.java b/src/main/java/com/volmit/iris/generator/atomics/Hunk.java new file mode 100644 index 000000000..bf8a20006 --- /dev/null +++ b/src/main/java/com/volmit/iris/generator/atomics/Hunk.java @@ -0,0 +1,218 @@ +package com.volmit.iris.generator.atomics; + +import org.bouncycastle.util.Arrays; + +import lombok.Data; + +@Data +public class Hunk +{ + protected final int w; + protected final int h; + protected final int d; + protected final T[] data; + + @SuppressWarnings("unchecked") + public Hunk(int w, int h, int d) + { + this.w = w; + this.h = h; + this.d = d; + data = (T[]) new Object[w * h * d]; + } + + /** + * Create a new hunk from a section of this hunk. + * + * + * @param x1 + * The min x (inclusive) + * @param y1 + * The min y (inclusive) + * @param z1 + * The min z (inclusive) + * @param x2 + * The max x (exclusive) + * @param y2 + * The max y (exclusive) + * @param z2 + * The max z (exclusive) + * @return the new hunk (x2-x1, y2-y1, z2-z1) + */ + public Hunk crop(int x1, int y1, int z1, int x2, int y2, int z2) + { + Hunk h = new Hunk(x2 - x1, y2 - y1, z2 - z1); + + for(int i = x1; i < x2; i++) + { + for(int j = y1; j < y2; j++) + { + for(int k = z1; k < z2; k++) + { + h.set(i - x1, j - y1, k - z1, get(i, j, k)); + } + } + } + + return h; + } + + /** + * Insert a hunk into this one with an offset the inserted hunk + * + * @param offX + * the offset from zero for x + * @param offY + * the offset from zero for y + * @param offZ + * the offset from zero for z + * @param hunk + * the hunk to insert + */ + public void insert(int offX, int offY, int offZ, Hunk hunk) + { + insert(offX, offY, offZ, hunk, false); + } + + /** + * Insert a hunk into this one + * + * @param hunk + * the hunk to insert + */ + public void insert(Hunk hunk) + { + insert(0, 0, 0, hunk, false); + } + + /** + * Insert a hunk into this one + * + * @param hunk + * the hunk to insert + * @param inverted + * invert the inserted hunk or not + */ + public void insert(Hunk hunk, boolean inverted) + { + insert(0, 0, 0, hunk, inverted); + } + + /** + * Insert a hunk into this one with an offset and possibly inverting the y of + * the inserted hunk + * + * @param offX + * the offset from zero for x + * @param offY + * the offset from zero for y + * @param offZ + * the offset from zero for z + * @param hunk + * the hunk to insert + * @param invertY + * should the inserted hunk be inverted + */ + public void insert(int offX, int offY, int offZ, Hunk hunk, boolean invertY) + { + if(offX + (hunk.getW() - 1) >= w || offY + (hunk.getH() - 1) >= h || offZ + (hunk.getD() - 1) >= d || offX < 0 || offY < 0 || offZ < 0) + { + throw new RuntimeException("Cannot insert hunk " + hunk.getW() + "," + hunk.getH() + "," + hunk.getD() + " into Hunk " + w + "," + h + "," + d + " with offset " + offZ + "," + offY + "," + offZ); + } + + for(int i = offX; i < offX + hunk.getW(); i++) + { + for(int j = offY; j < offY + hunk.getH(); j++) + { + for(int k = offZ; k < offZ + hunk.getD(); k++) + { + set(i, j, k, hunk.get(i - offX, j - offY, k - offZ)); + } + } + } + } + + public void set(int x, int y, int z, T t) + { + data[index(x, y, z)] = t; + } + + public T get(int x, int y, int z) + { + return data[index(x, y, z)]; + } + + public void setInvertedY(int x, int y, int z, T t) + { + data[index(x, h - y, z)] = t; + } + + public T getInvertedY(int x, int y, int z) + { + return data[index(x, h - y, z)]; + } + + protected int index(int x, int y, int z) + { + if(x >= w || y >= h || z >= d) + { + throw new RuntimeException(x + " " + y + " " + z + " is out of the bounds 0,0,0 - " + (w - 1) + "," + (h - 1) + "," + (d - 1)); + } + + return (z * w * h) + (y * w) + x; + } + + public void fill(T t) + { + Arrays.fill(data, t); + } + + @SafeVarargs + public static Hunk combined(T defaultNode, Hunk... hunks) + { + int w = 0; + int h = 0; + int d = 0; + + for(Hunk i : hunks) + { + w = Math.max(w, i.getW()); + h = Math.max(h, i.getH()); + d = Math.max(d, i.getD()); + } + + Hunk b = new Hunk(w, h, d); + b.fill(defaultNode); + + for(Hunk i : hunks) + { + b.insert(i); + } + + return b; + } + + @SafeVarargs + public static Hunk combined(Hunk... hunks) + { + int w = 0; + int h = 0; + int d = 0; + + for(Hunk i : hunks) + { + w = Math.max(w, i.getW()); + h = Math.max(h, i.getH()); + d = Math.max(d, i.getD()); + } + + Hunk b = new Hunk(w, h, d); + + for(Hunk i : hunks) + { + b.insert(i); + } + + return b; + } +} diff --git a/src/main/java/com/volmit/iris/generator/atomics/TerrainHunk.java b/src/main/java/com/volmit/iris/generator/atomics/TerrainHunk.java new file mode 100644 index 000000000..fcc352d40 --- /dev/null +++ b/src/main/java/com/volmit/iris/generator/atomics/TerrainHunk.java @@ -0,0 +1,204 @@ +package com.volmit.iris.generator.atomics; + +import org.bukkit.Material; +import org.bukkit.block.Biome; +import org.bukkit.block.data.BlockData; +import org.bukkit.generator.ChunkGenerator.BiomeGrid; +import org.bukkit.generator.ChunkGenerator.ChunkData; +import org.bukkit.material.MaterialData; + +@SuppressWarnings("deprecation") +public class TerrainHunk extends Hunk implements BiomeGrid, ChunkData +{ + public TerrainHunk(int w, int h, int d) + { + super(w, h, d); + } + + @Override + public int getMaxHeight() + { + return getH(); + } + + private void set(int x, int y, int z, BlockData block) + { + TerrainNode n = get(x, y, z); + + if(n == null) + { + n = new TerrainNode(Biome.THE_VOID, block); + } + + else + { + n = n.setBlockData(block); + } + + set(x, y, z, n); + } + + private void set(int x, int y, int z, Biome biome) + { + TerrainNode n = get(x, y, z); + + if(n == null) + { + n = new TerrainNode(biome, Material.AIR.createBlockData()); + } + + else + { + n = n.setBiome(biome); + } + + set(x, y, z, n); + } + + @Override + public void setBlock(int x, int y, int z, Material material) + { + set(x, y, z, material.createBlockData()); + } + + @Override + public void setBlock(int x, int y, int z, MaterialData material) + { + set(x, y, z, material.getItemType().createBlockData()); + } + + @Override + public void setBlock(int x, int y, int z, BlockData blockData) + { + set(x, y, z, blockData); + } + + @Override + public void setRegion(int xMin, int yMin, int zMin, int xMax, int yMax, int zMax, Material material) + { + throw new RuntimeException("Not Supported"); + } + + @Override + public void setRegion(int xMin, int yMin, int zMin, int xMax, int yMax, int zMax, MaterialData material) + { + throw new RuntimeException("Not Supported"); + } + + @Override + public void setRegion(int xMin, int yMin, int zMin, int xMax, int yMax, int zMax, BlockData blockData) + { + throw new RuntimeException("Not Supported"); + } + + @Override + public Material getType(int x, int y, int z) + { + return getBlockData(x, y, z).getMaterial(); + } + + @Override + public MaterialData getTypeAndData(int x, int y, int z) + { + return new MaterialData(getBlockData(x, y, z).getMaterial()); + } + + @Override + public BlockData getBlockData(int x, int y, int z) + { + TerrainNode n = get(x, y, z); + + if(n == null) + { + return Material.STONE.createBlockData(); + } + + return n.getBlockData(); + } + + @Override + public byte getData(int x, int y, int z) + { + throw new RuntimeException("Not Supported"); + } + + @Override + public Biome getBiome(int x, int z) + { + throw new RuntimeException("Not Supported"); + } + + @Override + public Biome getBiome(int x, int y, int z) + { + TerrainNode n = get(x, y, z); + + if(n == null) + { + return Biome.THE_VOID; + } + + return n.getBiome(); + } + + @Override + public void setBiome(int x, int z, Biome bio) + { + throw new RuntimeException("Not Supported"); + } + + @Override + public void setBiome(int x, int y, int z, Biome bio) + { + set(x, y, z, bio); + } + + @SafeVarargs + public static TerrainHunk combined(TerrainNode defaultNode, TerrainHunk... hunks) + { + int w = 0; + int h = 0; + int d = 0; + + for(TerrainHunk i : hunks) + { + w = Math.max(w, i.getW()); + h = Math.max(h, i.getH()); + d = Math.max(d, i.getD()); + } + + TerrainHunk b = new TerrainHunk(w, h, d); + b.fill(defaultNode); + + for(TerrainHunk i : hunks) + { + b.insert(i); + } + + return b; + } + + @SafeVarargs + public static TerrainHunk combined(TerrainHunk... hunks) + { + int w = 0; + int h = 0; + int d = 0; + + for(TerrainHunk i : hunks) + { + w = Math.max(w, i.getW()); + h = Math.max(h, i.getH()); + d = Math.max(d, i.getD()); + } + + TerrainHunk b = new TerrainHunk(w, h, d); + + for(TerrainHunk i : hunks) + { + b.insert(i); + } + + return b; + } +} diff --git a/src/main/java/com/volmit/iris/generator/atomics/TerrainNode.java b/src/main/java/com/volmit/iris/generator/atomics/TerrainNode.java new file mode 100644 index 000000000..908811fcf --- /dev/null +++ b/src/main/java/com/volmit/iris/generator/atomics/TerrainNode.java @@ -0,0 +1,61 @@ +package com.volmit.iris.generator.atomics; + +import org.bukkit.block.Biome; +import org.bukkit.block.data.BlockData; + +import com.volmit.iris.util.KList; + +public class TerrainNode +{ + private static final KList blockDataPalette = new KList(); + + private final byte biome; + private final short block; + + private TerrainNode(byte biome, short block) + { + this.biome = biome; + this.block = block; + } + + public TerrainNode(Biome biome, BlockData block) + { + this((byte) (biome.ordinal() + Byte.MIN_VALUE), (short) (paletteOf(block) + Short.MIN_VALUE)); + } + + public TerrainNode setBlockData(BlockData block) + { + return new TerrainNode(biome, (short) (paletteOf(block) + Short.MIN_VALUE)); + } + + public TerrainNode setBiome(Biome biome) + { + return new TerrainNode((byte) (biome.ordinal() + Byte.MIN_VALUE), block); + } + + public BlockData getBlockData() + { + return blockDataPalette.get(block); + } + + public Biome getBiome() + { + return Biome.values()[biome]; + } + + private static int paletteOf(BlockData b) + { + synchronized(blockDataPalette) + { + int v = blockDataPalette.indexOf(b); + + if(v >= 0) + { + return v; + } + + blockDataPalette.add(b); + return blockDataPalette.size() - 1; + } + } +} diff --git a/src/main/java/com/volmit/iris/generator/scaffold/IrisTerrainStream.java b/src/main/java/com/volmit/iris/generator/scaffold/IrisTerrainStream.java new file mode 100644 index 000000000..b63b95590 --- /dev/null +++ b/src/main/java/com/volmit/iris/generator/scaffold/IrisTerrainStream.java @@ -0,0 +1,18 @@ +package com.volmit.iris.generator.scaffold; + +import com.volmit.iris.generator.atomics.TerrainHunk; + +public class IrisTerrainStream implements TerrainStream +{ + @Override + public TerrainHunk generate(int x1, int z1, int x2, int z2) + { + return null; + } + + @Override + public TerrainHunk generate(int x, int z) + { + return null; + } +} diff --git a/src/main/java/com/volmit/iris/generator/scaffold/TerrainStream.java b/src/main/java/com/volmit/iris/generator/scaffold/TerrainStream.java new file mode 100644 index 000000000..90794cbe4 --- /dev/null +++ b/src/main/java/com/volmit/iris/generator/scaffold/TerrainStream.java @@ -0,0 +1,10 @@ +package com.volmit.iris.generator.scaffold; + +import com.volmit.iris.generator.atomics.TerrainHunk; + +public interface TerrainStream +{ + public TerrainHunk generate(int x1, int z1, int x2, int z2); + + public TerrainHunk generate(int x, int z); +} diff --git a/src/main/java/com/volmit/iris/manager/EditManager.java b/src/main/java/com/volmit/iris/manager/EditManager.java index 938247234..45418b149 100644 --- a/src/main/java/com/volmit/iris/manager/EditManager.java +++ b/src/main/java/com/volmit/iris/manager/EditManager.java @@ -8,6 +8,7 @@ import org.bukkit.event.Listener; import org.bukkit.event.world.WorldUnloadEvent; import com.volmit.iris.Iris; +import com.volmit.iris.IrisSettings; import com.volmit.iris.edit.BlockEditor; import com.volmit.iris.edit.BukkitBlockEditor; import com.volmit.iris.edit.WEBlockEditor; @@ -15,6 +16,8 @@ import com.volmit.iris.util.FastBlockData; import com.volmit.iris.util.KMap; import com.volmit.iris.util.M; +import io.papermc.lib.PaperLib; + public class EditManager implements Listener { private KMap editors; @@ -85,7 +88,7 @@ public class EditManager implements Listener BlockEditor e = null; - if(Bukkit.getPluginManager().isPluginEnabled("WorldEdit")) + if(Bukkit.getPluginManager().isPluginEnabled("WorldEdit") && !PaperLib.isPaper() && !IrisSettings.get().isIgnoreWorldEdit()) { try { diff --git a/src/main/java/com/volmit/iris/manager/IrisBoardManager.java b/src/main/java/com/volmit/iris/manager/IrisBoardManager.java index 9d54d12c3..063233d35 100644 --- a/src/main/java/com/volmit/iris/manager/IrisBoardManager.java +++ b/src/main/java/com/volmit/iris/manager/IrisBoardManager.java @@ -10,7 +10,7 @@ import org.bukkit.event.player.PlayerChangedWorldEvent; import com.volmit.iris.Iris; import com.volmit.iris.gen.IrisTerrainProvider; -import com.volmit.iris.gen.provisions.ProvisionBukkit; +import com.volmit.iris.gen.scaffold.IrisWorlds; import com.volmit.iris.noise.CNG; import com.volmit.iris.object.IrisBiome; import com.volmit.iris.util.BoardManager; @@ -56,7 +56,7 @@ public class IrisBoardManager implements BoardProvider, Listener @DontObfuscate private boolean isIrisWorld(World w) { - return (w.getGenerator() instanceof ProvisionBukkit) && ((IrisTerrainProvider) ((ProvisionBukkit) w.getGenerator()).getProvider()).isDev(); + return IrisWorlds.isIrisWorld(w) && IrisWorlds.getProvider(w).isDev(); } public void updatePlayer(Player p) @@ -90,7 +90,7 @@ public class IrisBoardManager implements BoardProvider, Listener return v; } - IrisTerrainProvider g = (IrisTerrainProvider) ((ProvisionBukkit) player.getWorld().getGenerator()).getProvider(); + IrisTerrainProvider g = IrisWorlds.getProvider(player.getWorld()); if(cl.flip()) { diff --git a/src/main/java/com/volmit/iris/manager/IrisDataManager.java b/src/main/java/com/volmit/iris/manager/IrisDataManager.java index 4aac856f9..3d7829b3e 100644 --- a/src/main/java/com/volmit/iris/manager/IrisDataManager.java +++ b/src/main/java/com/volmit/iris/manager/IrisDataManager.java @@ -43,7 +43,7 @@ public class IrisDataManager public IrisDataManager(File dataFolder) { this.dataFolder = dataFolder; - this.packs = new File(dataFolder, ProjectManager.workspaceName); + this.packs = new File(dataFolder, ProjectManager.WORKSPACE_NAME); boolean pr = false; if(!packs.exists()) { @@ -65,7 +65,7 @@ public class IrisDataManager return; } - File packs = this.packs.getName().equals(ProjectManager.workspaceName) ? this.packs : dataFolder; + File packs = this.packs.getName().equals(ProjectManager.WORKSPACE_NAME) ? this.packs : dataFolder; packs.mkdirs(); this.lootLoader = new ResourceLoader<>(packs, "loot", "Loot", IrisLootTable.class); this.entityLoader = new ResourceLoader<>(packs, "entities", "Entity", IrisEntity.class); @@ -77,7 +77,7 @@ public class IrisDataManager this.blockLoader = new ResourceLoader<>(packs, "blocks", "Block", IrisBlockData.class); this.objectLoader = new ObjectResourceLoader(packs, "objects", "Object"); - if(packs.getName().equals(ProjectManager.workspaceName)) + if(packs.getName().equals(ProjectManager.WORKSPACE_NAME)) { writeExamples(); } diff --git a/src/main/java/com/volmit/iris/manager/IrisProject.java b/src/main/java/com/volmit/iris/manager/IrisProject.java index 4cc3a0fa0..d72a26fde 100644 --- a/src/main/java/com/volmit/iris/manager/IrisProject.java +++ b/src/main/java/com/volmit/iris/manager/IrisProject.java @@ -16,7 +16,7 @@ import com.google.gson.Gson; import com.volmit.iris.Iris; import com.volmit.iris.IrisSettings; import com.volmit.iris.gen.IrisTerrainProvider; -import com.volmit.iris.gen.nms.NMSCreator; +import com.volmit.iris.gen.nms.INMS; import com.volmit.iris.gen.provisions.ProvisionBukkit; import com.volmit.iris.gen.scaffold.IrisGenConfiguration; import com.volmit.iris.gen.scaffold.TerrainTarget; @@ -191,7 +191,7 @@ public class IrisProject }); //@builder - World world = NMSCreator.createWorld(new WorldCreator(wfp) + World world = INMS.get().createWorld(new WorldCreator(wfp) .seed(1337) .generator(gen) .generateStructures(d.isVanillaStructures()) @@ -238,7 +238,7 @@ public class IrisProject return new File(path, getName() + ".code-workspace"); } - public void updateWorkspace() + public boolean updateWorkspace() { getPath().mkdirs(); File ws = getCodeWorkspaceFile(); @@ -251,6 +251,7 @@ public class IrisProject IO.writeAll(ws, j.toString(4)); p.end(); Iris.info("Updated Workspace: " + ws.getPath() + " in " + Form.duration(p.getMilliseconds(), 2)); + return true; } catch(Throwable e) @@ -267,6 +268,8 @@ public class IrisProject e1.printStackTrace(); } } + + return false; } public JSONObject createCodeWorkspaceConfig() diff --git a/src/main/java/com/volmit/iris/manager/ProjectManager.java b/src/main/java/com/volmit/iris/manager/ProjectManager.java index ae94405f3..3cc9d36f3 100644 --- a/src/main/java/com/volmit/iris/manager/ProjectManager.java +++ b/src/main/java/com/volmit/iris/manager/ProjectManager.java @@ -27,7 +27,8 @@ import lombok.Data; @Data public class ProjectManager { - public static final String workspaceName = "packs"; + public static final String LISTING = "https://raw.githubusercontent.com/IrisDimensions/_listing/main/listing.json"; + public static final String WORKSPACE_NAME = "packs"; private KMap cacheListing = null; private IrisProject activeProject; @@ -71,7 +72,7 @@ public class ProjectManager { if(i.isFile() && i.getName().equals(type + ".iris")) { - sender.sendMessage("Found " + type + ".iris in " + ProjectManager.workspaceName + " folder"); + sender.sendMessage("Found " + type + ".iris in " + ProjectManager.WORKSPACE_NAME + " folder"); ZipUtil.unpack(i, iris); break; } @@ -80,7 +81,7 @@ public class ProjectManager else { - sender.sendMessage("Found " + type + " dimension in " + ProjectManager.workspaceName + " folder. Repackaging"); + sender.sendMessage("Found " + type + " dimension in " + ProjectManager.WORKSPACE_NAME + " folder. Repackaging"); File f = new IrisProject(new File(getWorkspaceFolder(), type)).getPath(); try @@ -90,7 +91,7 @@ public class ProjectManager catch(IOException e) { - e.printStackTrace(); + } } @@ -277,12 +278,12 @@ public class ProjectManager if(cached) { - a = new JSONArray(Iris.getCached("cachedlisting", "https://raw.githubusercontent.com/VolmitSoftware/Iris/master/listing.json")); + a = new JSONArray(Iris.getCached("cachedlisting", LISTING)); } else { - a = new JSONArray(Iris.getNonCached(!cached + "listing", "https://raw.githubusercontent.com/VolmitSoftware/Iris/master/listing.json")); + a = new JSONArray(Iris.getNonCached(!cached + "listing", LISTING)); } KMap l = new KMap<>(); @@ -331,12 +332,12 @@ public class ProjectManager public File getWorkspaceFolder(String... sub) { - return Iris.instance.getDataFolderList(workspaceName, sub); + return Iris.instance.getDataFolderList(WORKSPACE_NAME, sub); } public File getWorkspaceFile(String... sub) { - return Iris.instance.getDataFileList(workspaceName, sub); + return Iris.instance.getDataFileList(WORKSPACE_NAME, sub); } public void close() diff --git a/src/main/java/com/volmit/iris/manager/WandManager.java b/src/main/java/com/volmit/iris/manager/WandManager.java index b84f703ba..4fe43d67e 100644 --- a/src/main/java/com/volmit/iris/manager/WandManager.java +++ b/src/main/java/com/volmit/iris/manager/WandManager.java @@ -155,24 +155,32 @@ public class WandManager implements Listener @EventHandler public void on(PlayerInteractEvent e) { - if(e.getHand().equals(EquipmentSlot.HAND) && isWand(e.getPlayer().getInventory().getItemInMainHand())) + try { - if(e.getAction().equals(Action.LEFT_CLICK_BLOCK)) + if(e.getHand().equals(EquipmentSlot.HAND) && isWand(e.getPlayer().getInventory().getItemInMainHand())) { - e.setCancelled(true); - e.getPlayer().getInventory().setItemInMainHand(update(true, e.getClickedBlock().getLocation(), e.getPlayer().getInventory().getItemInMainHand())); - e.getPlayer().playSound(e.getClickedBlock().getLocation(), Sound.BLOCK_END_PORTAL_FRAME_FILL, 1f, 0.67f); - e.getPlayer().updateInventory(); - } + if(e.getAction().equals(Action.LEFT_CLICK_BLOCK)) + { + e.setCancelled(true); + e.getPlayer().getInventory().setItemInMainHand(update(true, e.getClickedBlock().getLocation(), e.getPlayer().getInventory().getItemInMainHand())); + e.getPlayer().playSound(e.getClickedBlock().getLocation(), Sound.BLOCK_END_PORTAL_FRAME_FILL, 1f, 0.67f); + e.getPlayer().updateInventory(); + } - else if(e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) - { - e.setCancelled(true); - e.getPlayer().getInventory().setItemInMainHand(update(false, e.getClickedBlock().getLocation(), e.getPlayer().getInventory().getItemInMainHand())); - e.getPlayer().playSound(e.getClickedBlock().getLocation(), Sound.BLOCK_END_PORTAL_FRAME_FILL, 1f, 1.17f); - e.getPlayer().updateInventory(); + else if(e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) + { + e.setCancelled(true); + e.getPlayer().getInventory().setItemInMainHand(update(false, e.getClickedBlock().getLocation(), e.getPlayer().getInventory().getItemInMainHand())); + e.getPlayer().playSound(e.getClickedBlock().getLocation(), Sound.BLOCK_END_PORTAL_FRAME_FILL, 1f, 1.17f); + e.getPlayer().updateInventory(); + } } } + + catch(Throwable ex) + { + + } } public static void pasteSchematic(IrisObject s, Location at) diff --git a/src/main/java/com/volmit/iris/noise/CNG.java b/src/main/java/com/volmit/iris/noise/CNG.java index 1f67866f0..512485649 100644 --- a/src/main/java/com/volmit/iris/noise/CNG.java +++ b/src/main/java/com/volmit/iris/noise/CNG.java @@ -285,6 +285,7 @@ public class CNG { Iris.error("Failed to sample noise into array " + v.size() + " nodes"); Iris.error("Noise Source: " + generator.getClass().getSimpleName()); + } return v.get(0); diff --git a/src/main/java/com/volmit/iris/noise/FastNoise.java b/src/main/java/com/volmit/iris/noise/FastNoise.java new file mode 100644 index 000000000..354b3cc98 --- /dev/null +++ b/src/main/java/com/volmit/iris/noise/FastNoise.java @@ -0,0 +1,2369 @@ +// FastNoise.java +// +// MIT License +// +// Copyright(c) 2017 Jordan Peck +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// +// The developer's email is jorzixdan.me2@gzixmail.com (for great email, take +// off every 'zix'.) +// + +package com.volmit.iris.noise; + +import com.volmit.iris.util.Vector2f; +import com.volmit.iris.util.Vector3f; + +public class FastNoise +{ + public enum NoiseType + { + Value, + ValueFractal, + Perlin, + PerlinFractal, + Simplex, + SimplexFractal, + Cellular, + WhiteNoise, + Cubic, + CubicFractal + } + + public enum Interp + { + Linear, + Hermite, + Quintic + } + + public enum FractalType + { + FBM, + Billow, + RigidMulti + } + + public enum CellularDistanceFunction + { + Euclidean, + Manhattan, + Natural + } + + public enum CellularReturnType + { + CellValue, + NoiseLookup, + Distance, + Distance2, + Distance2Add, + Distance2Sub, + Distance2Mul, + Distance2Div + } + + private int m_seed = 1337; + private float m_frequency = (float) 0.01; + private Interp m_interp = Interp.Quintic; + private NoiseType m_noiseType = NoiseType.Simplex; + + private int m_octaves = 3; + private float m_lacunarity = (float) 2.0; + private float m_gain = (float) 0.5; + private FractalType m_fractalType = FractalType.FBM; + + private float m_fractalBounding; + + private CellularDistanceFunction m_cellularDistanceFunction = CellularDistanceFunction.Euclidean; + private CellularReturnType m_cellularReturnType = CellularReturnType.CellValue; + private FastNoise m_cellularNoiseLookup = null; + + private float m_gradientPerturbAmp = (float) (1.0 / 0.45); + + public FastNoise() + { + this(1337); + } + + public FastNoise(int seed) + { + m_seed = seed; + CalculateFractalBounding(); + } + + // Returns a 0 float/double + public static float GetDecimalType() + { + return 0; + } + + // Returns the seed used by this object + public int GetSeed() + { + return m_seed; + } + + // Sets seed used for all noise types + // Default: 1337 + public void SetSeed(int seed) + { + m_seed = seed; + } + + // Sets frequency for all noise types + // Default: 0.01 + public void SetFrequency(float frequency) + { + m_frequency = frequency; + } + + // Changes the interpolation method used to smooth between noise values + // Possible interpolation methods (lowest to highest quality) : + // - Linear + // - Hermite + // - Quintic + // Used in Value, Gradient Noise and Position Perturbing + // Default: Quintic + public void SetInterp(Interp interp) + { + m_interp = interp; + } + + // Sets noise return type of GetNoise(...) + // Default: Simplex + public void SetNoiseType(NoiseType noiseType) + { + m_noiseType = noiseType; + } + + // Sets octave count for all fractal noise types + // Default: 3 + public void SetFractalOctaves(int octaves) + { + m_octaves = octaves; + CalculateFractalBounding(); + } + + // Sets octave lacunarity for all fractal noise types + // Default: 2.0 + public void SetFractalLacunarity(float lacunarity) + { + m_lacunarity = lacunarity; + } + + // Sets octave gain for all fractal noise types + // Default: 0.5 + public void SetFractalGain(float gain) + { + m_gain = gain; + CalculateFractalBounding(); + } + + // Sets method for combining octaves in all fractal noise types + // Default: FBM + public void SetFractalType(FractalType fractalType) + { + m_fractalType = fractalType; + } + + // Sets return type from cellular noise calculations + // Note: NoiseLookup requires another FastNoise object be set with + // SetCellularNoiseLookup() to function + // Default: CellValue + public void SetCellularDistanceFunction(CellularDistanceFunction cellularDistanceFunction) + { + m_cellularDistanceFunction = cellularDistanceFunction; + } + + // Sets distance function used in cellular noise calculations + // Default: Euclidean + public void SetCellularReturnType(CellularReturnType cellularReturnType) + { + m_cellularReturnType = cellularReturnType; + } + + // Noise used to calculate a cell value if cellular return type is NoiseLookup + // The lookup value is acquired through GetNoise() so ensure you SetNoiseType() + // on the noise lookup, value, gradient or simplex is recommended + public void SetCellularNoiseLookup(FastNoise noise) + { + m_cellularNoiseLookup = noise; + } + + // Sets the maximum perturb distance from original location when using + // GradientPerturb{Fractal}(...) + // Default: 1.0 + public void SetGradientPerturbAmp(float gradientPerturbAmp) + { + m_gradientPerturbAmp = gradientPerturbAmp / (float) 0.45; + } + + private static class Float2 + { + public final float x, y; + + public Float2(float x, float y) + { + this.x = x; + this.y = y; + } + } + + private static class Float3 + { + public final float x, y, z; + + public Float3(float x, float y, float z) + { + this.x = x; + this.y = y; + this.z = z; + } + } + + private static final Float2[] GRAD_2D = {new Float2(-1, -1), new Float2(1, -1), new Float2(-1, 1), new Float2(1, 1), new Float2(0, -1), new Float2(-1, 0), new Float2(0, 1), new Float2(1, 0), + }; + + private static final Float3[] GRAD_3D = {new Float3(1, 1, 0), new Float3(-1, 1, 0), new Float3(1, -1, 0), new Float3(-1, -1, 0), new Float3(1, 0, 1), new Float3(-1, 0, 1), new Float3(1, 0, -1), new Float3(-1, 0, -1), new Float3(0, 1, 1), new Float3(0, -1, 1), new Float3(0, 1, -1), new Float3(0, -1, -1), new Float3(1, 1, 0), new Float3(0, -1, 1), new Float3(-1, 1, 0), new Float3(0, -1, -1), + }; + + private static final Float2[] CELL_2D = {new Float2(-0.4313539279f, 0.1281943404f), new Float2(-0.1733316799f, 0.415278375f), new Float2(-0.2821957395f, -0.3505218461f), new Float2(-0.2806473808f, 0.3517627718f), new Float2(0.3125508975f, -0.3237467165f), new Float2(0.3383018443f, -0.2967353402f), new Float2(-0.4393982022f, -0.09710417025f), new Float2(-0.4460443703f, -0.05953502905f), new Float2(-0.302223039f, 0.3334085102f), new Float2(-0.212681052f, -0.3965687458f), new Float2(-0.2991156529f, 0.3361990872f), new Float2(0.2293323691f, 0.3871778202f), new Float2(0.4475439151f, -0.04695150755f), new Float2(0.1777518f, 0.41340573f), new Float2(0.1688522499f, -0.4171197882f), new Float2(-0.0976597166f, 0.4392750616f), new Float2(0.08450188373f, 0.4419948321f), new Float2(-0.4098760448f, -0.1857461384f), new Float2(0.3476585782f, -0.2857157906f), new Float2(-0.3350670039f, -0.30038326f), new Float2(0.2298190031f, -0.3868891648f), new Float2(-0.01069924099f, 0.449872789f), new Float2(-0.4460141246f, -0.05976119672f), new Float2(0.3650293864f, 0.2631606867f), new Float2(-0.349479423f, 0.2834856838f), new Float2(-0.4122720642f, 0.1803655873f), new Float2(-0.267327811f, 0.3619887311f), new Float2(0.322124041f, -0.3142230135f), new Float2(0.2880445931f, -0.3457315612f), new Float2(0.3892170926f, -0.2258540565f), new Float2(0.4492085018f, -0.02667811596f), new Float2(-0.4497724772f, 0.01430799601f), new Float2(0.1278175387f, -0.4314657307f), new Float2(-0.03572100503f, 0.4485799926f), new Float2(-0.4297407068f, -0.1335025276f), new Float2(-0.3217817723f, 0.3145735065f), new Float2(-0.3057158873f, 0.3302087162f), new Float2(-0.414503978f, 0.1751754899f), new Float2(-0.3738139881f, 0.2505256519f), new Float2(0.2236891408f, -0.3904653228f), new Float2(0.002967775577f, -0.4499902136f), new Float2(0.1747128327f, -0.4146991995f), new Float2(-0.4423772489f, -0.08247647938f), new Float2(-0.2763960987f, -0.355112935f), new Float2(-0.4019385906f, -0.2023496216f), new Float2(0.3871414161f, -0.2293938184f), new Float2(-0.430008727f, 0.1326367019f), new Float2(-0.03037574274f, -0.4489736231f), new Float2(-0.3486181573f, 0.2845441624f), new Float2(0.04553517144f, -0.4476902368f), new Float2(-0.0375802926f, 0.4484280562f), new Float2(0.3266408905f, 0.3095250049f), new Float2(0.06540017593f, -0.4452222108f), new Float2(0.03409025829f, 0.448706869f), new Float2(-0.4449193635f, 0.06742966669f), new Float2(-0.4255936157f, -0.1461850686f), new Float2(0.449917292f, 0.008627302568f), new Float2(0.05242606404f, 0.4469356864f), new Float2(-0.4495305179f, -0.02055026661f), new Float2(-0.1204775703f, 0.4335725488f), new Float2(-0.341986385f, -0.2924813028f), new Float2(0.3865320182f, 0.2304191809f), new Float2(0.04506097811f, -0.447738214f), new Float2(-0.06283465979f, 0.4455915232f), new Float2(0.3932600341f, -0.2187385324f), new Float2(0.4472261803f, -0.04988730975f), new Float2(0.3753571011f, -0.2482076684f), new Float2(-0.273662295f, 0.357223947f), new Float2(0.1700461538f, 0.4166344988f), new Float2(0.4102692229f, 0.1848760794f), new Float2(0.323227187f, -0.3130881435f), new Float2(-0.2882310238f, -0.3455761521f), new Float2(0.2050972664f, 0.4005435199f), new Float2(0.4414085979f, -0.08751256895f), new Float2(-0.1684700334f, 0.4172743077f), new Float2(-0.003978032396f, 0.4499824166f), new Float2(-0.2055133639f, 0.4003301853f), new Float2(-0.006095674897f, -0.4499587123f), new Float2(-0.1196228124f, -0.4338091548f), new Float2(0.3901528491f, -0.2242337048f), new Float2(0.01723531752f, 0.4496698165f), new Float2(-0.3015070339f, 0.3340561458f), new Float2(-0.01514262423f, -0.4497451511f), new Float2(-0.4142574071f, -0.1757577897f), new Float2(-0.1916377265f, -0.4071547394f), new Float2(0.3749248747f, 0.2488600778f), new Float2(-0.2237774255f, 0.3904147331f), new Float2(-0.4166343106f, -0.1700466149f), new Float2(0.3619171625f, 0.267424695f), new Float2(0.1891126846f, -0.4083336779f), new Float2(-0.3127425077f, 0.323561623f), new Float2(-0.3281807787f, 0.307891826f), new Float2(-0.2294806661f, 0.3870899429f), new Float2(-0.3445266136f, 0.2894847362f), new Float2(-0.4167095422f, -0.1698621719f), new Float2(-0.257890321f, -0.3687717212f), new Float2(-0.3612037825f, 0.2683874578f), new Float2(0.2267996491f, 0.3886668486f), new Float2(0.207157062f, 0.3994821043f), new Float2(0.08355176718f, -0.4421754202f), new Float2(-0.4312233307f, 0.1286329626f), new Float2(0.3257055497f, 0.3105090899f), new Float2(0.177701095f, -0.4134275279f), new Float2(-0.445182522f, 0.06566979625f), new Float2(0.3955143435f, 0.2146355146f), new Float2(-0.4264613988f, 0.1436338239f), new Float2(-0.3793799665f, -0.2420141339f), new Float2(0.04617599081f, -0.4476245948f), new Float2(-0.371405428f, -0.2540826796f), new Float2(0.2563570295f, -0.3698392535f), new Float2(0.03476646309f, 0.4486549822f), new Float2(-0.3065454405f, 0.3294387544f), new Float2(-0.2256979823f, 0.3893076172f), new Float2(0.4116448463f, -0.1817925206f), new Float2(-0.2907745828f, -0.3434387019f), new Float2(0.2842278468f, -0.348876097f), new Float2(0.3114589359f, -0.3247973695f), new Float2(0.4464155859f, -0.0566844308f), new Float2(-0.3037334033f, -0.3320331606f), new Float2(0.4079607166f, 0.1899159123f), new Float2(-0.3486948919f, -0.2844501228f), new Float2(0.3264821436f, 0.3096924441f), new Float2(0.3211142406f, 0.3152548881f), new Float2(0.01183382662f, 0.4498443737f), new Float2(0.4333844092f, 0.1211526057f), new Float2(0.3118668416f, 0.324405723f), new Float2(-0.272753471f, 0.3579183483f), new Float2(-0.422228622f, -0.1556373694f), new Float2(-0.1009700099f, -0.4385260051f), new Float2(-0.2741171231f, -0.3568750521f), new Float2(-0.1465125133f, 0.4254810025f), new Float2(0.2302279044f, -0.3866459777f), new Float2(-0.3699435608f, 0.2562064828f), new Float2(0.105700352f, -0.4374099171f), new Float2(-0.2646713633f, 0.3639355292f), new Float2(0.3521828122f, 0.2801200935f), new Float2(-0.1864187807f, -0.4095705534f), new Float2(0.1994492955f, -0.4033856449f), new Float2(0.3937065066f, 0.2179339044f), new Float2(-0.3226158377f, 0.3137180602f), new Float2(0.3796235338f, 0.2416318948f), new Float2(0.1482921929f, 0.4248640083f), new Float2(-0.407400394f, 0.1911149365f), new Float2(0.4212853031f, 0.1581729856f), new Float2(-0.2621297173f, 0.3657704353f), new Float2(-0.2536986953f, -0.3716678248f), new Float2(-0.2100236383f, 0.3979825013f), new Float2(0.3624152444f, 0.2667493029f), new Float2(-0.3645038479f, -0.2638881295f), new Float2(0.2318486784f, 0.3856762766f), new Float2(-0.3260457004f, 0.3101519002f), new Float2(-0.2130045332f, -0.3963950918f), new Float2(0.3814998766f, -0.2386584257f), new Float2(-0.342977305f, 0.2913186713f), new Float2(-0.4355865605f, 0.1129794154f), new Float2(-0.2104679605f, 0.3977477059f), new Float2(0.3348364681f, -0.3006402163f), new Float2(0.3430468811f, 0.2912367377f), new Float2(-0.2291836801f, -0.3872658529f), new Float2(0.2547707298f, -0.3709337882f), new Float2(0.4236174945f, -0.151816397f), new Float2(-0.15387742f, 0.4228731957f), new Float2(-0.4407449312f, 0.09079595574f), new Float2(-0.06805276192f, -0.444824484f), new Float2(0.4453517192f, -0.06451237284f), new Float2(0.2562464609f, -0.3699158705f), new Float2(0.3278198355f, -0.3082761026f), new Float2(-0.4122774207f, -0.1803533432f), new Float2(0.3354090914f, -0.3000012356f), new Float2(0.446632869f, -0.05494615882f), new Float2(-0.1608953296f, 0.4202531296f), new Float2(-0.09463954939f, 0.4399356268f), new Float2(-0.02637688324f, -0.4492262904f), new Float2(0.447102804f, -0.05098119915f), new Float2(-0.4365670908f, 0.1091291678f), new Float2(-0.3959858651f, 0.2137643437f), new Float2(-0.4240048207f, -0.1507312575f), new Float2(-0.3882794568f, 0.2274622243f), new Float2(-0.4283652566f, -0.1378521198f), new Float2(0.3303888091f, 0.305521251f), new Float2(0.3321434919f, -0.3036127481f), new Float2(-0.413021046f, -0.1786438231f), new Float2(0.08403060337f, -0.4420846725f), new Float2(-0.3822882919f, 0.2373934748f), new Float2(-0.3712395594f, -0.2543249683f), new Float2(0.4472363971f, -0.04979563372f), new Float2(-0.4466591209f, 0.05473234629f), new Float2(0.0486272539f, -0.4473649407f), new Float2(-0.4203101295f, -0.1607463688f), new Float2(0.2205360833f, 0.39225481f), new Float2(-0.3624900666f, 0.2666476169f), new Float2(-0.4036086833f, -0.1989975647f), new Float2(0.2152727807f, 0.3951678503f), new Float2(-0.4359392962f, -0.1116106179f), new Float2(0.4178354266f, 0.1670735057f), new Float2(0.2007630161f, 0.4027334247f), new Float2(-0.07278067175f, -0.4440754146f), new Float2(0.3644748615f, -0.2639281632f), new Float2(-0.4317451775f, 0.126870413f), new Float2(-0.297436456f, 0.3376855855f), new Float2(-0.2998672222f, 0.3355289094f), new Float2(-0.2673674124f, 0.3619594822f), new Float2(0.2808423357f, 0.3516071423f), new Float2(0.3498946567f, 0.2829730186f), new Float2(-0.2229685561f, 0.390877248f), new Float2(0.3305823267f, 0.3053118493f), new Float2(-0.2436681211f, -0.3783197679f), new Float2(-0.03402776529f, 0.4487116125f), new Float2(-0.319358823f, 0.3170330301f), new Float2(0.4454633477f, -0.06373700535f), new Float2(0.4483504221f, 0.03849544189f), new Float2(-0.4427358436f, -0.08052932871f), new Float2(0.05452298565f, 0.4466847255f), new Float2(-0.2812560807f, 0.3512762688f), new Float2(0.1266696921f, 0.4318041097f), new Float2(-0.3735981243f, 0.2508474468f), new Float2(0.2959708351f, -0.3389708908f), new Float2(-0.3714377181f, 0.254035473f), new Float2(-0.404467102f, -0.1972469604f), new Float2(0.1636165687f, -0.419201167f), new Float2(0.3289185495f, -0.3071035458f), new Float2(-0.2494824991f, -0.3745109914f), new Float2(0.03283133272f, 0.4488007393f), new Float2(-0.166306057f, -0.4181414777f), new Float2(-0.106833179f, 0.4371346153f), new Float2(0.06440260376f, -0.4453676062f), new Float2(-0.4483230967f, 0.03881238203f), new Float2(-0.421377757f, -0.1579265206f), new Float2(0.05097920662f, -0.4471030312f), new Float2(0.2050584153f, -0.4005634111f), new Float2(0.4178098529f, -0.167137449f), new Float2(-0.3565189504f, -0.2745801121f), new Float2(0.4478398129f, 0.04403977727f), new Float2(-0.3399999602f, -0.2947881053f), new Float2(0.3767121994f, 0.2461461331f), new Float2(-0.3138934434f, 0.3224451987f), new Float2(-0.1462001792f, -0.4255884251f), new Float2(0.3970290489f, -0.2118205239f), new Float2(0.4459149305f, -0.06049689889f), new Float2(-0.4104889426f, -0.1843877112f), new Float2(0.1475103971f, -0.4251360756f), new Float2(0.09258030352f, 0.4403735771f), new Float2(-0.1589664637f, -0.4209865359f), new Float2(0.2482445008f, 0.3753327428f), new Float2(0.4383624232f, -0.1016778537f), new Float2(0.06242802956f, 0.4456486745f), new Float2(0.2846591015f, -0.3485243118f), new Float2(-0.344202744f, -0.2898697484f), new Float2(0.1198188883f, -0.4337550392f), new Float2(-0.243590703f, 0.3783696201f), new Float2(0.2958191174f, -0.3391033025f), new Float2(-0.1164007991f, 0.4346847754f), new Float2(0.1274037151f, -0.4315881062f), new Float2(0.368047306f, 0.2589231171f), new Float2(0.2451436949f, 0.3773652989f), new Float2(-0.4314509715f, 0.12786735f), + }; + + private static final Float3[] CELL_3D = {new Float3(0.1453787434f, -0.4149781685f, -0.0956981749f), new Float3(-0.01242829687f, -0.1457918398f, -0.4255470325f), new Float3(0.2877979582f, -0.02606483451f, -0.3449535616f), new Float3(-0.07732986802f, 0.2377094325f, 0.3741848704f), new Float3(0.1107205875f, -0.3552302079f, -0.2530858567f), new Float3(0.2755209141f, 0.2640521179f, -0.238463215f), new Float3(0.294168941f, 0.1526064594f, 0.3044271714f), new Float3(0.4000921098f, -0.2034056362f, 0.03244149937f), new Float3(-0.1697304074f, 0.3970864695f, -0.1265461359f), new Float3(-0.1483224484f, -0.3859694688f, 0.1775613147f), new Float3(0.2623596946f, -0.2354852944f, 0.2796677792f), new Float3(-0.2709003183f, 0.3505271138f, -0.07901746678f), new Float3(-0.03516550699f, 0.3885234328f, 0.2243054374f), new Float3(-0.1267712655f, 0.1920044036f, 0.3867342179f), new Float3(0.02952021915f, 0.4409685861f, 0.08470692262f), new Float3(-0.2806854217f, -0.266996757f, 0.2289725438f), new Float3(-0.171159547f, 0.2141185563f, 0.3568720405f), new Float3(0.2113227183f, 0.3902405947f, -0.07453178509f), new Float3(-0.1024352839f, 0.2128044156f, -0.3830421561f), new Float3(-0.3304249877f, -0.1566986703f, 0.2622305365f), new Float3(0.2091111325f, 0.3133278055f, -0.2461670583f), new Float3(0.344678154f, -0.1944240454f, -0.2142341261f), new Float3(0.1984478035f, -0.3214342325f, -0.2445373252f), new Float3(-0.2929008603f, 0.2262915116f, 0.2559320961f), new Float3(-0.1617332831f, 0.006314769776f, -0.4198838754f), new Float3(-0.3582060271f, -0.148303178f, -0.2284613961f), new Float3(-0.1852067326f, -0.3454119342f, -0.2211087107f), new Float3(0.3046301062f, 0.1026310383f, 0.314908508f), new Float3(-0.03816768434f, -0.2551766358f, -0.3686842991f), new Float3(-0.4084952196f, 0.1805950793f, 0.05492788837f), new Float3(-0.02687443361f, -0.2749741471f, 0.3551999201f), new Float3(-0.03801098351f, 0.3277859044f, 0.3059600725f), new Float3(0.2371120802f, 0.2900386767f, -0.2493099024f), new Float3(0.4447660503f, 0.03946930643f, 0.05590469027f), new Float3(0.01985147278f, -0.01503183293f, -0.4493105419f), new Float3(0.4274339143f, 0.03345994256f, -0.1366772882f), new Float3(-0.2072988631f, 0.2871414597f, -0.2776273824f), new Float3(-0.3791240978f, 0.1281177671f, 0.2057929936f), new Float3(-0.2098721267f, -0.1007087278f, -0.3851122467f), new Float3(0.01582798878f, 0.4263894424f, 0.1429738373f), new Float3(-0.1888129464f, -0.3160996813f, -0.2587096108f), new Float3(0.1612988974f, -0.1974805082f, -0.3707885038f), new Float3(-0.08974491322f, 0.229148752f, -0.3767448739f), new Float3(0.07041229526f, 0.4150230285f, -0.1590534329f), new Float3(-0.1082925611f, -0.1586061639f, 0.4069604477f), new Float3(0.2474100658f, -0.3309414609f, 0.1782302128f), new Float3(-0.1068836661f, -0.2701644537f, -0.3436379634f), new Float3(0.2396452163f, 0.06803600538f, -0.3747549496f), new Float3(-0.3063886072f, 0.2597428179f, 0.2028785103f), new Float3(0.1593342891f, -0.3114350249f, -0.2830561951f), new Float3(0.2709690528f, 0.1412648683f, -0.3303331794f), new Float3(-0.1519780427f, 0.3623355133f, 0.2193527988f), new Float3(0.1699773681f, 0.3456012883f, 0.2327390037f), new Float3(-0.1986155616f, 0.3836276443f, -0.1260225743f), new Float3(-0.1887482106f, -0.2050154888f, -0.353330953f), new Float3(0.2659103394f, 0.3015631259f, -0.2021172246f), new Float3(-0.08838976154f, -0.4288819642f, -0.1036702021f), new Float3(-0.04201869311f, 0.3099592485f, 0.3235115047f), new Float3(-0.3230334656f, 0.201549922f, -0.2398478873f), new Float3(0.2612720941f, 0.2759854499f, -0.2409749453f), new Float3(0.385713046f, 0.2193460345f, 0.07491837764f), new Float3(0.07654967953f, 0.3721732183f, 0.241095919f), new Float3(0.4317038818f, -0.02577753072f, 0.1243675091f), new Float3(-0.2890436293f, -0.3418179959f, -0.04598084447f), new Float3(-0.2201947582f, 0.383023377f, -0.08548310451f), new Float3(0.4161322773f, -0.1669634289f, -0.03817251927f), new Float3(0.2204718095f, 0.02654238946f, -0.391391981f), new Float3(-0.1040307469f, 0.3890079625f, -0.2008741118f), new Float3(-0.1432122615f, 0.371614387f, -0.2095065525f), new Float3(0.3978380468f, -0.06206669342f, 0.2009293758f), new Float3(-0.2599274663f, 0.2616724959f, -0.2578084893f), new Float3(0.4032618332f, -0.1124593585f, 0.1650235939f), new Float3(-0.08953470255f, -0.3048244735f, 0.3186935478f), new Float3(0.118937202f, -0.2875221847f, 0.325092195f), new Float3(0.02167047076f, -0.03284630549f, -0.4482761547f), new Float3(-0.3411343612f, 0.2500031105f, 0.1537068389f), new Float3(0.3162964612f, 0.3082064153f, -0.08640228117f), new Float3(0.2355138889f, -0.3439334267f, -0.1695376245f), new Float3(-0.02874541518f, -0.3955933019f, 0.2125550295f), new Float3(-0.2461455173f, 0.02020282325f, -0.3761704803f), new Float3(0.04208029445f, -0.4470439576f, 0.02968078139f), new Float3(0.2727458746f, 0.2288471896f, -0.2752065618f), new Float3(-0.1347522818f, -0.02720848277f, -0.4284874806f), new Float3(0.3829624424f, 0.1231931484f, -0.2016512234f), new Float3(-0.3547613644f, 0.1271702173f, 0.2459107769f), new Float3(0.2305790207f, 0.3063895591f, 0.2354968222f), new Float3(-0.08323845599f, -0.1922245118f, 0.3982726409f), new Float3(0.2993663085f, -0.2619918095f, -0.2103333191f), new Float3(-0.2154865723f, 0.2706747713f, 0.287751117f), new Float3(0.01683355354f, -0.2680655787f, -0.3610505186f), new Float3(0.05240429123f, 0.4335128183f, -0.1087217856f), new Float3(0.00940104872f, -0.4472890582f, 0.04841609928f), new Float3(0.3465688735f, 0.01141914583f, -0.2868093776f), new Float3(-0.3706867948f, -0.2551104378f, 0.003156692623f), new Float3(0.2741169781f, 0.2139972417f, -0.2855959784f), new Float3(0.06413433865f, 0.1708718512f, 0.4113266307f), new Float3(-0.388187972f, -0.03973280434f, -0.2241236325f), new Float3(0.06419469312f, -0.2803682491f, 0.3460819069f), new Float3(-0.1986120739f, -0.3391173584f, 0.2192091725f), new Float3(-0.203203009f, -0.3871641506f, 0.1063600375f), new Float3(-0.1389736354f, -0.2775901578f, -0.3257760473f), new Float3(-0.06555641638f, 0.342253257f, -0.2847192729f), new Float3(-0.2529246486f, -0.2904227915f, 0.2327739768f), new Float3(0.1444476522f, 0.1069184044f, 0.4125570634f), new Float3(-0.3643780054f, -0.2447099973f, -0.09922543227f), new Float3(0.4286142488f, -0.1358496089f, -0.01829506817f), new Float3(0.165872923f, -0.3136808464f, -0.2767498872f), new Float3(0.2219610524f, -0.3658139958f, 0.1393320198f), new Float3(0.04322940318f, -0.3832730794f, 0.2318037215f), new Float3(-0.08481269795f, -0.4404869674f, -0.03574965489f), new Float3(0.1822082075f, -0.3953259299f, 0.1140946023f), new Float3(-0.3269323334f, 0.3036542563f, 0.05838957105f), new Float3(-0.4080485344f, 0.04227858267f, -0.184956522f), new Float3(0.2676025294f, -0.01299671652f, 0.36155217f), new Float3(0.3024892441f, -0.1009990293f, -0.3174892964f), new Float3(0.1448494052f, 0.425921681f, -0.0104580805f), new Float3(0.4198402157f, 0.08062320474f, 0.1404780841f), new Float3(-0.3008872161f, -0.333040905f, -0.03241355801f), new Float3(0.3639310428f, -0.1291284382f, -0.2310412139f), new Float3(0.3295806598f, 0.0184175994f, -0.3058388149f), new Float3(0.2776259487f, -0.2974929052f, -0.1921504723f), new Float3(0.4149000507f, -0.144793182f, -0.09691688386f), new Float3(0.145016715f, -0.0398992945f, 0.4241205002f), new Float3(0.09299023471f, -0.299732164f, -0.3225111565f), new Float3(0.1028907093f, -0.361266869f, 0.247789732f), new Float3(0.2683057049f, -0.07076041213f, -0.3542668666f), new Float3(-0.4227307273f, -0.07933161816f, -0.1323073187f), new Float3(-0.1781224702f, 0.1806857196f, -0.3716517945f), new Float3(0.4390788626f, -0.02841848598f, -0.09435116353f), new Float3(0.2972583585f, 0.2382799621f, -0.2394997452f), new Float3(-0.1707002821f, 0.2215845691f, 0.3525077196f), new Float3(0.3806686614f, 0.1471852559f, -0.1895464869f), new Float3(-0.1751445661f, -0.274887877f, 0.3102596268f), new Float3(-0.2227237566f, -0.2316778837f, 0.3149912482f), new Float3(0.1369633021f, 0.1341343041f, -0.4071228836f), new Float3(-0.3529503428f, -0.2472893463f, -0.129514612f), new Float3(-0.2590744185f, -0.2985577559f, -0.2150435121f), new Float3(-0.3784019401f, 0.2199816631f, -0.1044989934f), new Float3(-0.05635805671f, 0.1485737441f, 0.4210102279f), new Float3(0.3251428613f, 0.09666046873f, -0.2957006485f), new Float3(-0.4190995804f, 0.1406751354f, -0.08405978803f), new Float3(-0.3253150961f, -0.3080335042f, -0.04225456877f), new Float3(0.2857945863f, -0.05796152095f, 0.3427271751f), new Float3(-0.2733604046f, 0.1973770973f, -0.2980207554f), new Float3(0.219003657f, 0.2410037886f, -0.3105713639f), new Float3(0.3182767252f, -0.271342949f, 0.1660509868f), new Float3(-0.03222023115f, -0.3331161506f, -0.300824678f), new Float3(-0.3087780231f, 0.1992794134f, -0.2596995338f), new Float3(-0.06487611647f, -0.4311322747f, 0.1114273361f), new Float3(0.3921171432f, -0.06294284106f, -0.2116183942f), new Float3(-0.1606404506f, -0.358928121f, -0.2187812825f), new Float3(-0.03767771199f, -0.2290351443f, 0.3855169162f), new Float3(0.1394866832f, -0.3602213994f, 0.2308332918f), new Float3(-0.4345093872f, 0.005751117145f, 0.1169124335f), new Float3(-0.1044637494f, 0.4168128432f, -0.1336202785f), new Float3(0.2658727501f, 0.2551943237f, 0.2582393035f), new Float3(0.2051461999f, 0.1975390727f, 0.3484154868f), new Float3(-0.266085566f, 0.23483312f, 0.2766800993f), new Float3(0.07849405464f, -0.3300346342f, -0.2956616708f), new Float3(-0.2160686338f, 0.05376451292f, -0.3910546287f), new Float3(-0.185779186f, 0.2148499206f, 0.3490352499f), new Float3(0.02492421743f, -0.3229954284f, -0.3123343347f), new Float3(-0.120167831f, 0.4017266681f, 0.1633259825f), new Float3(-0.02160084693f, -0.06885389554f, 0.4441762538f), new Float3(0.2597670064f, 0.3096300784f, 0.1978643903f), new Float3(-0.1611553854f, -0.09823036005f, 0.4085091653f), new Float3(-0.3278896792f, 0.1461670309f, 0.2713366126f), new Float3(0.2822734956f, 0.03754421121f, -0.3484423997f), new Float3(0.03169341113f, 0.347405252f, -0.2842624114f), new Float3(0.2202613604f, -0.3460788041f, -0.1849713341f), new Float3(0.2933396046f, 0.3031973659f, 0.1565989581f), new Float3(-0.3194922995f, 0.2453752201f, -0.200538455f), new Float3(-0.3441586045f, -0.1698856132f, -0.2349334659f), new Float3(0.2703645948f, -0.3574277231f, 0.04060059933f), new Float3(0.2298568861f, 0.3744156221f, 0.0973588921f), new Float3(0.09326603877f, -0.3170108894f, 0.3054595587f), new Float3(-0.1116165319f, -0.2985018719f, 0.3177080142f), new Float3(0.2172907365f, -0.3460005203f, -0.1885958001f), new Float3(0.1991339479f, 0.3820341668f, -0.1299829458f), new Float3(-0.0541918155f, -0.2103145071f, 0.39412061f), new Float3(0.08871336998f, 0.2012117383f, 0.3926114802f), new Float3(0.2787673278f, 0.3505404674f, 0.04370535101f), new Float3(-0.322166438f, 0.3067213525f, 0.06804996813f), new Float3(-0.4277366384f, 0.132066775f, 0.04582286686f), new Float3(0.240131882f, -0.1612516055f, 0.344723946f), new Float3(0.1448607981f, -0.2387819045f, 0.3528435224f), new Float3(-0.3837065682f, -0.2206398454f, 0.08116235683f), new Float3(-0.4382627882f, -0.09082753406f, -0.04664855374f), new Float3(-0.37728353f, 0.05445141085f, 0.2391488697f), new Float3(0.1259579313f, 0.348394558f, 0.2554522098f), new Float3(-0.1406285511f, -0.270877371f, -0.3306796947f), new Float3(-0.1580694418f, 0.4162931958f, -0.06491553533f), new Float3(0.2477612106f, -0.2927867412f, -0.2353514536f), new Float3(0.2916132853f, 0.3312535401f, 0.08793624968f), new Float3(0.07365265219f, -0.1666159848f, 0.411478311f), new Float3(-0.26126526f, -0.2422237692f, 0.2748965434f), new Float3(-0.3721862032f, 0.252790166f, 0.008634938242f), new Float3(-0.3691191571f, -0.255281188f, 0.03290232422f), new Float3(0.2278441737f, -0.3358364886f, 0.1944244981f), new Float3(0.363398169f, -0.2310190248f, 0.1306597909f), new Float3(-0.304231482f, -0.2698452035f, 0.1926830856f), new Float3(-0.3199312232f, 0.316332536f, -0.008816977938f), new Float3(0.2874852279f, 0.1642275508f, -0.304764754f), new Float3(-0.1451096801f, 0.3277541114f, -0.2720669462f), new Float3(0.3220090754f, 0.0511344108f, 0.3101538769f), new Float3(-0.1247400865f, -0.04333605335f, -0.4301882115f), new Float3(-0.2829555867f, -0.3056190617f, -0.1703910946f), new Float3(0.1069384374f, 0.3491024667f, -0.2630430352f), new Float3(-0.1420661144f, -0.3055376754f, -0.2982682484f), new Float3(-0.250548338f, 0.3156466809f, -0.2002316239f), new Float3(0.3265787872f, 0.1871229129f, 0.2466400438f), new Float3(0.07646097258f, -0.3026690852f, 0.324106687f), new Float3(0.3451771584f, 0.2757120714f, -0.0856480183f), new Float3(0.298137964f, 0.2852657134f, 0.179547284f), new Float3(0.2812250376f, 0.3466716415f, 0.05684409612f), new Float3(0.4390345476f, -0.09790429955f, -0.01278335452f), new Float3(0.2148373234f, 0.1850172527f, 0.3494474791f), new Float3(0.2595421179f, -0.07946825393f, 0.3589187731f), new Float3(0.3182823114f, -0.307355516f, -0.08203022006f), new Float3(-0.4089859285f, -0.04647718411f, 0.1818526372f), new Float3(-0.2826749061f, 0.07417482322f, 0.3421885344f), new Float3(0.3483864637f, 0.225442246f, -0.1740766085f), new Float3(-0.3226415069f, -0.1420585388f, -0.2796816575f), new Float3(0.4330734858f, -0.118868561f, -0.02859407492f), new Float3(-0.08717822568f, -0.3909896417f, -0.2050050172f), new Float3(-0.2149678299f, 0.3939973956f, -0.03247898316f), new Float3(-0.2687330705f, 0.322686276f, -0.1617284888f), new Float3(0.2105665099f, -0.1961317136f, -0.3459683451f), new Float3(0.4361845915f, -0.1105517485f, 0.004616608544f), new Float3(0.05333333359f, -0.313639498f, -0.3182543336f), new Float3(-0.05986216652f, 0.1361029153f, -0.4247264031f), new Float3(0.3664988455f, 0.2550543014f, -0.05590974511f), new Float3(-0.2341015558f, -0.182405731f, 0.3382670703f), new Float3(-0.04730947785f, -0.4222150243f, -0.1483114513f), new Float3(-0.2391566239f, -0.2577696514f, -0.2808182972f), new Float3(-0.1242081035f, 0.4256953395f, -0.07652336246f), new Float3(0.2614832715f, -0.3650179274f, 0.02980623099f), new Float3(-0.2728794681f, -0.3499628774f, 0.07458404908f), new Float3(0.007892900508f, -0.1672771315f, 0.4176793787f), new Float3(-0.01730330376f, 0.2978486637f, -0.3368779738f), new Float3(0.2054835762f, -0.3252600376f, -0.2334146693f), new Float3(-0.3231994983f, 0.1564282844f, -0.2712420987f), new Float3(-0.2669545963f, 0.2599343665f, -0.2523278991f), new Float3(-0.05554372779f, 0.3170813944f, -0.3144428146f), new Float3(-0.2083935713f, -0.310922837f, -0.2497981362f), new Float3(0.06989323478f, -0.3156141536f, 0.3130537363f), new Float3(0.3847566193f, -0.1605309138f, -0.1693876312f), new Float3(-0.3026215288f, -0.3001537679f, -0.1443188342f), new Float3(0.3450735512f, 0.08611519592f, 0.2756962409f), new Float3(0.1814473292f, -0.2788782453f, -0.3029914042f), new Float3(-0.03855010448f, 0.09795110726f, 0.4375151083f), new Float3(0.3533670318f, 0.2665752752f, 0.08105160988f), new Float3(-0.007945601311f, 0.140359426f, -0.4274764309f), new Float3(0.4063099273f, -0.1491768253f, -0.1231199324f), new Float3(-0.2016773589f, 0.008816271194f, -0.4021797064f), new Float3(-0.07527055435f, -0.425643481f, -0.1251477955f), + }; + + private static int FastFloor(float f) + { + return (f >= 0 ? (int) f : (int) f - 1); + } + + private static int FastRound(float f) + { + return (f >= 0) ? (int) (f + (float) 0.5) : (int) (f - (float) 0.5); + } + + private static float Lerp(float a, float b, float t) + { + return a + t * (b - a); + } + + private static float InterpHermiteFunc(float t) + { + return t * t * (3 - 2 * t); + } + + private static float InterpQuinticFunc(float t) + { + return t * t * t * (t * (t * 6 - 15) + 10); + } + + private static float CubicLerp(float a, float b, float c, float d, float t) + { + float p = (d - c) - (a - b); + return t * t * t * p + t * t * ((a - b) - p) + t * (c - a) + b; + } + + private void CalculateFractalBounding() + { + float amp = m_gain; + float ampFractal = 1; + for(int i = 1; i < m_octaves; i++) + { + ampFractal += amp; + amp *= m_gain; + } + m_fractalBounding = 1 / ampFractal; + } + + // Hashing + private final static int X_PRIME = 1619; + private final static int Y_PRIME = 31337; + private final static int Z_PRIME = 6971; + private final static int W_PRIME = 1013; + + private static int Hash2D(int seed, int x, int y) + { + int hash = seed; + hash ^= X_PRIME * x; + hash ^= Y_PRIME * y; + + hash = hash * hash * hash * 60493; + hash = (hash >> 13) ^ hash; + + return hash; + } + + private static int Hash3D(int seed, int x, int y, int z) + { + int hash = seed; + hash ^= X_PRIME * x; + hash ^= Y_PRIME * y; + hash ^= Z_PRIME * z; + + hash = hash * hash * hash * 60493; + hash = (hash >> 13) ^ hash; + + return hash; + } + + public static int Hash4D(int seed, int x, int y, int z, int w) + { + int hash = seed; + hash ^= X_PRIME * x; + hash ^= Y_PRIME * y; + hash ^= Z_PRIME * z; + hash ^= W_PRIME * w; + + hash = hash * hash * hash * 60493; + hash = (hash >> 13) ^ hash; + + return hash; + } + + private static float ValCoord2D(int seed, int x, int y) + { + int n = seed; + n ^= X_PRIME * x; + n ^= Y_PRIME * y; + + return (n * n * n * 60493) / (float) 2147483648.0; + } + + private static float ValCoord3D(int seed, int x, int y, int z) + { + int n = seed; + n ^= X_PRIME * x; + n ^= Y_PRIME * y; + n ^= Z_PRIME * z; + + return (n * n * n * 60493) / (float) 2147483648.0; + } + + private static float ValCoord4D(int seed, int x, int y, int z, int w) + { + int n = seed; + n ^= X_PRIME * x; + n ^= Y_PRIME * y; + n ^= Z_PRIME * z; + n ^= W_PRIME * w; + + return (n * n * n * 60493) / (float) 2147483648.0; + } + + private static float GradCoord2D(int seed, int x, int y, float xd, float yd) + { + int hash = seed; + hash ^= X_PRIME * x; + hash ^= Y_PRIME * y; + + hash = hash * hash * hash * 60493; + hash = (hash >> 13) ^ hash; + + Float2 g = GRAD_2D[hash & 7]; + + return xd * g.x + yd * g.y; + } + + private static float GradCoord3D(int seed, int x, int y, int z, float xd, float yd, float zd) + { + int hash = seed; + hash ^= X_PRIME * x; + hash ^= Y_PRIME * y; + hash ^= Z_PRIME * z; + + hash = hash * hash * hash * 60493; + hash = (hash >> 13) ^ hash; + + Float3 g = GRAD_3D[hash & 15]; + + return xd * g.x + yd * g.y + zd * g.z; + } + + private static float GradCoord4D(int seed, int x, int y, int z, int w, float xd, float yd, float zd, float wd) + { + int hash = seed; + hash ^= X_PRIME * x; + hash ^= Y_PRIME * y; + hash ^= Z_PRIME * z; + hash ^= W_PRIME * w; + + hash = hash * hash * hash * 60493; + hash = (hash >> 13) ^ hash; + + hash &= 31; + float a = yd, b = zd, c = wd; // X,Y,Z + switch(hash >> 3) + { // OR, DEPENDING ON HIGH ORDER 2 BITS: + case 1: + a = wd; + b = xd; + c = yd; + break; // W,X,Y + case 2: + a = zd; + b = wd; + c = xd; + break; // Z,W,X + case 3: + a = yd; + b = zd; + c = wd; + break; // Y,Z,W + } + return ((hash & 4) == 0 ? -a : a) + ((hash & 2) == 0 ? -b : b) + ((hash & 1) == 0 ? -c : c); + } + + public float GetNoise(float x, float y, float z) + { + x *= m_frequency; + y *= m_frequency; + z *= m_frequency; + + switch(m_noiseType) + { + case Value: + return SingleValue(m_seed, x, y, z); + case ValueFractal: + switch(m_fractalType) + { + case FBM: + return SingleValueFractalFBM(x, y, z); + case Billow: + return SingleValueFractalBillow(x, y, z); + case RigidMulti: + return SingleValueFractalRigidMulti(x, y, z); + default: + return 0; + } + case Perlin: + return SinglePerlin(m_seed, x, y, z); + case PerlinFractal: + switch(m_fractalType) + { + case FBM: + return SinglePerlinFractalFBM(x, y, z); + case Billow: + return SinglePerlinFractalBillow(x, y, z); + case RigidMulti: + return SinglePerlinFractalRigidMulti(x, y, z); + default: + return 0; + } + case Simplex: + return SingleSimplex(m_seed, x, y, z); + case SimplexFractal: + switch(m_fractalType) + { + case FBM: + return SingleSimplexFractalFBM(x, y, z); + case Billow: + return SingleSimplexFractalBillow(x, y, z); + case RigidMulti: + return SingleSimplexFractalRigidMulti(x, y, z); + default: + return 0; + } + case Cellular: + switch(m_cellularReturnType) + { + case CellValue: + case NoiseLookup: + case Distance: + return SingleCellular(x, y, z); + default: + return SingleCellular2Edge(x, y, z); + } + case WhiteNoise: + return GetWhiteNoise(x, y, z); + case Cubic: + return SingleCubic(m_seed, x, y, z); + case CubicFractal: + switch(m_fractalType) + { + case FBM: + return SingleCubicFractalFBM(x, y, z); + case Billow: + return SingleCubicFractalBillow(x, y, z); + case RigidMulti: + return SingleCubicFractalRigidMulti(x, y, z); + default: + return 0; + } + default: + return 0; + } + } + + public float GetNoise(float x, float y) + { + x *= m_frequency; + y *= m_frequency; + + switch(m_noiseType) + { + case Value: + return SingleValue(m_seed, x, y); + case ValueFractal: + switch(m_fractalType) + { + case FBM: + return SingleValueFractalFBM(x, y); + case Billow: + return SingleValueFractalBillow(x, y); + case RigidMulti: + return SingleValueFractalRigidMulti(x, y); + default: + return 0; + } + case Perlin: + return SinglePerlin(m_seed, x, y); + case PerlinFractal: + switch(m_fractalType) + { + case FBM: + return SinglePerlinFractalFBM(x, y); + case Billow: + return SinglePerlinFractalBillow(x, y); + case RigidMulti: + return SinglePerlinFractalRigidMulti(x, y); + default: + return 0; + } + case Simplex: + return SingleSimplex(m_seed, x, y); + case SimplexFractal: + switch(m_fractalType) + { + case FBM: + return SingleSimplexFractalFBM(x, y); + case Billow: + return SingleSimplexFractalBillow(x, y); + case RigidMulti: + return SingleSimplexFractalRigidMulti(x, y); + default: + return 0; + } + case Cellular: + switch(m_cellularReturnType) + { + case CellValue: + case NoiseLookup: + case Distance: + return SingleCellular(x, y); + default: + return SingleCellular2Edge(x, y); + } + case WhiteNoise: + return GetWhiteNoise(x, y); + case Cubic: + return SingleCubic(m_seed, x, y); + case CubicFractal: + switch(m_fractalType) + { + case FBM: + return SingleCubicFractalFBM(x, y); + case Billow: + return SingleCubicFractalBillow(x, y); + case RigidMulti: + return SingleCubicFractalRigidMulti(x, y); + default: + return 0; + } + default: + return 0; + } + } + + // White Noise + + private int FloatCast2Int(float f) + { + int i = Float.floatToRawIntBits(f); + + return i ^ (i >> 16); + } + + public float GetWhiteNoise(float x, float y, float z, float w) + { + int xi = FloatCast2Int(x); + int yi = FloatCast2Int(y); + int zi = FloatCast2Int(z); + int wi = FloatCast2Int(w); + + return ValCoord4D(m_seed, xi, yi, zi, wi); + } + + public float GetWhiteNoise(double x, double y, double z) + { + int xi = FloatCast2Int((float) x); + int yi = FloatCast2Int((float) y); + int zi = FloatCast2Int((float) z); + + return ValCoord3D(m_seed, xi, yi, zi); + } + + public float GetWhiteNoise(double x, double y) + { + int xi = FloatCast2Int((float) x); + int yi = FloatCast2Int((float) y); + + return ValCoord2D(m_seed, xi, yi); + } + + public float GetWhiteNoiseInt(int x, int y, int z, int w) + { + return ValCoord4D(m_seed, x, y, z, w); + } + + public float GetWhiteNoiseInt(int x, int y, int z) + { + return ValCoord3D(m_seed, x, y, z); + } + + public float GetWhiteNoiseInt(int x, int y) + { + return ValCoord2D(m_seed, x, y); + } + + // Value Noise + public float GetValueFractal(float x, float y, float z) + { + x *= m_frequency; + y *= m_frequency; + z *= m_frequency; + + switch(m_fractalType) + { + case FBM: + return SingleValueFractalFBM(x, y, z); + case Billow: + return SingleValueFractalBillow(x, y, z); + case RigidMulti: + return SingleValueFractalRigidMulti(x, y, z); + default: + return 0; + } + } + + private float SingleValueFractalFBM(float x, float y, float z) + { + int seed = m_seed; + float sum = SingleValue(seed, x, y, z); + float amp = 1; + + for(int i = 1; i < m_octaves; i++) + { + x *= m_lacunarity; + y *= m_lacunarity; + z *= m_lacunarity; + + amp *= m_gain; + sum += SingleValue(++seed, x, y, z) * amp; + } + + return sum * m_fractalBounding; + } + + private float SingleValueFractalBillow(float x, float y, float z) + { + int seed = m_seed; + float sum = Math.abs(SingleValue(seed, x, y, z)) * 2 - 1; + float amp = 1; + + for(int i = 1; i < m_octaves; i++) + { + x *= m_lacunarity; + y *= m_lacunarity; + z *= m_lacunarity; + + amp *= m_gain; + sum += (Math.abs(SingleValue(++seed, x, y, z)) * 2 - 1) * amp; + } + + return sum * m_fractalBounding; + } + + private float SingleValueFractalRigidMulti(float x, float y, float z) + { + int seed = m_seed; + float sum = 1 - Math.abs(SingleValue(seed, x, y, z)); + float amp = 1; + + for(int i = 1; i < m_octaves; i++) + { + x *= m_lacunarity; + y *= m_lacunarity; + z *= m_lacunarity; + + amp *= m_gain; + sum -= (1 - Math.abs(SingleValue(++seed, x, y, z))) * amp; + } + + return sum; + } + + public float GetValue(float x, float y, float z) + { + return SingleValue(m_seed, x * m_frequency, y * m_frequency, z * m_frequency); + } + + private float SingleValue(int seed, float x, float y, float z) + { + int x0 = FastFloor(x); + int y0 = FastFloor(y); + int z0 = FastFloor(z); + int x1 = x0 + 1; + int y1 = y0 + 1; + int z1 = z0 + 1; + + float xs, ys, zs; + switch(m_interp) + { + default: + case Linear: + xs = x - x0; + ys = y - y0; + zs = z - z0; + break; + case Hermite: + xs = InterpHermiteFunc(x - x0); + ys = InterpHermiteFunc(y - y0); + zs = InterpHermiteFunc(z - z0); + break; + case Quintic: + xs = InterpQuinticFunc(x - x0); + ys = InterpQuinticFunc(y - y0); + zs = InterpQuinticFunc(z - z0); + break; + } + + float xf00 = Lerp(ValCoord3D(seed, x0, y0, z0), ValCoord3D(seed, x1, y0, z0), xs); + float xf10 = Lerp(ValCoord3D(seed, x0, y1, z0), ValCoord3D(seed, x1, y1, z0), xs); + float xf01 = Lerp(ValCoord3D(seed, x0, y0, z1), ValCoord3D(seed, x1, y0, z1), xs); + float xf11 = Lerp(ValCoord3D(seed, x0, y1, z1), ValCoord3D(seed, x1, y1, z1), xs); + + float yf0 = Lerp(xf00, xf10, ys); + float yf1 = Lerp(xf01, xf11, ys); + + return Lerp(yf0, yf1, zs); + } + + public float GetValueFractal(float x, float y) + { + x *= m_frequency; + y *= m_frequency; + + switch(m_fractalType) + { + case FBM: + return SingleValueFractalFBM(x, y); + case Billow: + return SingleValueFractalBillow(x, y); + case RigidMulti: + return SingleValueFractalRigidMulti(x, y); + default: + return 0; + } + } + + private float SingleValueFractalFBM(float x, float y) + { + int seed = m_seed; + float sum = SingleValue(seed, x, y); + float amp = 1; + + for(int i = 1; i < m_octaves; i++) + { + x *= m_lacunarity; + y *= m_lacunarity; + + amp *= m_gain; + sum += SingleValue(++seed, x, y) * amp; + } + + return sum * m_fractalBounding; + } + + private float SingleValueFractalBillow(float x, float y) + { + int seed = m_seed; + float sum = Math.abs(SingleValue(seed, x, y)) * 2 - 1; + float amp = 1; + + for(int i = 1; i < m_octaves; i++) + { + x *= m_lacunarity; + y *= m_lacunarity; + amp *= m_gain; + sum += (Math.abs(SingleValue(++seed, x, y)) * 2 - 1) * amp; + } + + return sum * m_fractalBounding; + } + + private float SingleValueFractalRigidMulti(float x, float y) + { + int seed = m_seed; + float sum = 1 - Math.abs(SingleValue(seed, x, y)); + float amp = 1; + + for(int i = 1; i < m_octaves; i++) + { + x *= m_lacunarity; + y *= m_lacunarity; + + amp *= m_gain; + sum -= (1 - Math.abs(SingleValue(++seed, x, y))) * amp; + } + + return sum; + } + + public float GetValue(float x, float y) + { + return SingleValue(m_seed, x * m_frequency, y * m_frequency); + } + + private float SingleValue(int seed, float x, float y) + { + int x0 = FastFloor(x); + int y0 = FastFloor(y); + int x1 = x0 + 1; + int y1 = y0 + 1; + + float xs, ys; + switch(m_interp) + { + default: + case Linear: + xs = x - x0; + ys = y - y0; + break; + case Hermite: + xs = InterpHermiteFunc(x - x0); + ys = InterpHermiteFunc(y - y0); + break; + case Quintic: + xs = InterpQuinticFunc(x - x0); + ys = InterpQuinticFunc(y - y0); + break; + } + + float xf0 = Lerp(ValCoord2D(seed, x0, y0), ValCoord2D(seed, x1, y0), xs); + float xf1 = Lerp(ValCoord2D(seed, x0, y1), ValCoord2D(seed, x1, y1), xs); + + return Lerp(xf0, xf1, ys); + } + + // Gradient Noise + public float GetPerlinFractal(float x, float y, float z) + { + x *= m_frequency; + y *= m_frequency; + z *= m_frequency; + + switch(m_fractalType) + { + case FBM: + return SinglePerlinFractalFBM(x, y, z); + case Billow: + return SinglePerlinFractalBillow(x, y, z); + case RigidMulti: + return SinglePerlinFractalRigidMulti(x, y, z); + default: + return 0; + } + } + + private float SinglePerlinFractalFBM(float x, float y, float z) + { + int seed = m_seed; + float sum = SinglePerlin(seed, x, y, z); + float amp = 1; + + for(int i = 1; i < m_octaves; i++) + { + x *= m_lacunarity; + y *= m_lacunarity; + z *= m_lacunarity; + + amp *= m_gain; + sum += SinglePerlin(++seed, x, y, z) * amp; + } + + return sum * m_fractalBounding; + } + + private float SinglePerlinFractalBillow(float x, float y, float z) + { + int seed = m_seed; + float sum = Math.abs(SinglePerlin(seed, x, y, z)) * 2 - 1; + float amp = 1; + + for(int i = 1; i < m_octaves; i++) + { + x *= m_lacunarity; + y *= m_lacunarity; + z *= m_lacunarity; + + amp *= m_gain; + sum += (Math.abs(SinglePerlin(++seed, x, y, z)) * 2 - 1) * amp; + } + + return sum * m_fractalBounding; + } + + private float SinglePerlinFractalRigidMulti(float x, float y, float z) + { + int seed = m_seed; + float sum = 1 - Math.abs(SinglePerlin(seed, x, y, z)); + float amp = 1; + + for(int i = 1; i < m_octaves; i++) + { + x *= m_lacunarity; + y *= m_lacunarity; + z *= m_lacunarity; + + amp *= m_gain; + sum -= (1 - Math.abs(SinglePerlin(++seed, x, y, z))) * amp; + } + + return sum; + } + + public float GetPerlin(float x, float y, float z) + { + return SinglePerlin(m_seed, x * m_frequency, y * m_frequency, z * m_frequency); + } + + private float SinglePerlin(int seed, float x, float y, float z) + { + int x0 = FastFloor(x); + int y0 = FastFloor(y); + int z0 = FastFloor(z); + int x1 = x0 + 1; + int y1 = y0 + 1; + int z1 = z0 + 1; + + float xs, ys, zs; + switch(m_interp) + { + default: + case Linear: + xs = x - x0; + ys = y - y0; + zs = z - z0; + break; + case Hermite: + xs = InterpHermiteFunc(x - x0); + ys = InterpHermiteFunc(y - y0); + zs = InterpHermiteFunc(z - z0); + break; + case Quintic: + xs = InterpQuinticFunc(x - x0); + ys = InterpQuinticFunc(y - y0); + zs = InterpQuinticFunc(z - z0); + break; + } + + float xd0 = x - x0; + float yd0 = y - y0; + float zd0 = z - z0; + float xd1 = xd0 - 1; + float yd1 = yd0 - 1; + float zd1 = zd0 - 1; + + float xf00 = Lerp(GradCoord3D(seed, x0, y0, z0, xd0, yd0, zd0), GradCoord3D(seed, x1, y0, z0, xd1, yd0, zd0), xs); + float xf10 = Lerp(GradCoord3D(seed, x0, y1, z0, xd0, yd1, zd0), GradCoord3D(seed, x1, y1, z0, xd1, yd1, zd0), xs); + float xf01 = Lerp(GradCoord3D(seed, x0, y0, z1, xd0, yd0, zd1), GradCoord3D(seed, x1, y0, z1, xd1, yd0, zd1), xs); + float xf11 = Lerp(GradCoord3D(seed, x0, y1, z1, xd0, yd1, zd1), GradCoord3D(seed, x1, y1, z1, xd1, yd1, zd1), xs); + + float yf0 = Lerp(xf00, xf10, ys); + float yf1 = Lerp(xf01, xf11, ys); + + return Lerp(yf0, yf1, zs); + } + + public float GetPerlinFractal(float x, float y) + { + x *= m_frequency; + y *= m_frequency; + + switch(m_fractalType) + { + case FBM: + return SinglePerlinFractalFBM(x, y); + case Billow: + return SinglePerlinFractalBillow(x, y); + case RigidMulti: + return SinglePerlinFractalRigidMulti(x, y); + default: + return 0; + } + } + + private float SinglePerlinFractalFBM(float x, float y) + { + int seed = m_seed; + float sum = SinglePerlin(seed, x, y); + float amp = 1; + + for(int i = 1; i < m_octaves; i++) + { + x *= m_lacunarity; + y *= m_lacunarity; + + amp *= m_gain; + sum += SinglePerlin(++seed, x, y) * amp; + } + + return sum * m_fractalBounding; + } + + private float SinglePerlinFractalBillow(float x, float y) + { + int seed = m_seed; + float sum = Math.abs(SinglePerlin(seed, x, y)) * 2 - 1; + float amp = 1; + + for(int i = 1; i < m_octaves; i++) + { + x *= m_lacunarity; + y *= m_lacunarity; + + amp *= m_gain; + sum += (Math.abs(SinglePerlin(++seed, x, y)) * 2 - 1) * amp; + } + + return sum * m_fractalBounding; + } + + private float SinglePerlinFractalRigidMulti(float x, float y) + { + int seed = m_seed; + float sum = 1 - Math.abs(SinglePerlin(seed, x, y)); + float amp = 1; + + for(int i = 1; i < m_octaves; i++) + { + x *= m_lacunarity; + y *= m_lacunarity; + + amp *= m_gain; + sum -= (1 - Math.abs(SinglePerlin(++seed, x, y))) * amp; + } + + return sum; + } + + public float GetPerlin(float x, float y) + { + return SinglePerlin(m_seed, x * m_frequency, y * m_frequency); + } + + private float SinglePerlin(int seed, float x, float y) + { + int x0 = FastFloor(x); + int y0 = FastFloor(y); + int x1 = x0 + 1; + int y1 = y0 + 1; + + float xs, ys; + switch(m_interp) + { + default: + case Linear: + xs = x - x0; + ys = y - y0; + break; + case Hermite: + xs = InterpHermiteFunc(x - x0); + ys = InterpHermiteFunc(y - y0); + break; + case Quintic: + xs = InterpQuinticFunc(x - x0); + ys = InterpQuinticFunc(y - y0); + break; + } + + float xd0 = x - x0; + float yd0 = y - y0; + float xd1 = xd0 - 1; + float yd1 = yd0 - 1; + + float xf0 = Lerp(GradCoord2D(seed, x0, y0, xd0, yd0), GradCoord2D(seed, x1, y0, xd1, yd0), xs); + float xf1 = Lerp(GradCoord2D(seed, x0, y1, xd0, yd1), GradCoord2D(seed, x1, y1, xd1, yd1), xs); + + return Lerp(xf0, xf1, ys); + } + + // Simplex Noise + public float GetSimplexFractal(float x, float y, float z) + { + x *= m_frequency; + y *= m_frequency; + z *= m_frequency; + + switch(m_fractalType) + { + case FBM: + return SingleSimplexFractalFBM(x, y, z); + case Billow: + return SingleSimplexFractalBillow(x, y, z); + case RigidMulti: + return SingleSimplexFractalRigidMulti(x, y, z); + default: + return 0; + } + } + + private float SingleSimplexFractalFBM(float x, float y, float z) + { + int seed = m_seed; + float sum = SingleSimplex(seed, x, y, z); + float amp = 1; + + for(int i = 1; i < m_octaves; i++) + { + x *= m_lacunarity; + y *= m_lacunarity; + z *= m_lacunarity; + + amp *= m_gain; + sum += SingleSimplex(++seed, x, y, z) * amp; + } + + return sum * m_fractalBounding; + } + + private float SingleSimplexFractalBillow(float x, float y, float z) + { + int seed = m_seed; + float sum = Math.abs(SingleSimplex(seed, x, y, z)) * 2 - 1; + float amp = 1; + + for(int i = 1; i < m_octaves; i++) + { + x *= m_lacunarity; + y *= m_lacunarity; + z *= m_lacunarity; + + amp *= m_gain; + sum += (Math.abs(SingleSimplex(++seed, x, y, z)) * 2 - 1) * amp; + } + + return sum * m_fractalBounding; + } + + private float SingleSimplexFractalRigidMulti(float x, float y, float z) + { + int seed = m_seed; + float sum = 1 - Math.abs(SingleSimplex(seed, x, y, z)); + float amp = 1; + + for(int i = 1; i < m_octaves; i++) + { + x *= m_lacunarity; + y *= m_lacunarity; + z *= m_lacunarity; + + amp *= m_gain; + sum -= (1 - Math.abs(SingleSimplex(++seed, x, y, z))) * amp; + } + + return sum; + } + + public float GetSimplex(float x, float y, float z) + { + return SingleSimplex(m_seed, x * m_frequency, y * m_frequency, z * m_frequency); + } + + private final static float F3 = (float) (1.0 / 3.0); + private final static float G3 = (float) (1.0 / 6.0); + private final static float G33 = G3 * 3 - 1; + + private float SingleSimplex(int seed, float x, float y, float z) + { + float t = (x + y + z) * F3; + int i = FastFloor(x + t); + int j = FastFloor(y + t); + int k = FastFloor(z + t); + + t = (i + j + k) * G3; + float x0 = x - (i - t); + float y0 = y - (j - t); + float z0 = z - (k - t); + + int i1, j1, k1; + int i2, j2, k2; + + if(x0 >= y0) + { + if(y0 >= z0) + { + i1 = 1; + j1 = 0; + k1 = 0; + i2 = 1; + j2 = 1; + k2 = 0; + } + else if(x0 >= z0) + { + i1 = 1; + j1 = 0; + k1 = 0; + i2 = 1; + j2 = 0; + k2 = 1; + } + else // x0 < z0 + { + i1 = 0; + j1 = 0; + k1 = 1; + i2 = 1; + j2 = 0; + k2 = 1; + } + } + else // x0 < y0 + { + if(y0 < z0) + { + i1 = 0; + j1 = 0; + k1 = 1; + i2 = 0; + j2 = 1; + k2 = 1; + } + else if(x0 < z0) + { + i1 = 0; + j1 = 1; + k1 = 0; + i2 = 0; + j2 = 1; + k2 = 1; + } + else // x0 >= z0 + { + i1 = 0; + j1 = 1; + k1 = 0; + i2 = 1; + j2 = 1; + k2 = 0; + } + } + + float x1 = x0 - i1 + G3; + float y1 = y0 - j1 + G3; + float z1 = z0 - k1 + G3; + float x2 = x0 - i2 + F3; + float y2 = y0 - j2 + F3; + float z2 = z0 - k2 + F3; + float x3 = x0 + G33; + float y3 = y0 + G33; + float z3 = z0 + G33; + + float n0, n1, n2, n3; + + t = (float) 0.6 - x0 * x0 - y0 * y0 - z0 * z0; + if(t < 0) + n0 = 0; + else + { + t *= t; + n0 = t * t * GradCoord3D(seed, i, j, k, x0, y0, z0); + } + + t = (float) 0.6 - x1 * x1 - y1 * y1 - z1 * z1; + if(t < 0) + n1 = 0; + else + { + t *= t; + n1 = t * t * GradCoord3D(seed, i + i1, j + j1, k + k1, x1, y1, z1); + } + + t = (float) 0.6 - x2 * x2 - y2 * y2 - z2 * z2; + if(t < 0) + n2 = 0; + else + { + t *= t; + n2 = t * t * GradCoord3D(seed, i + i2, j + j2, k + k2, x2, y2, z2); + } + + t = (float) 0.6 - x3 * x3 - y3 * y3 - z3 * z3; + if(t < 0) + n3 = 0; + else + { + t *= t; + n3 = t * t * GradCoord3D(seed, i + 1, j + 1, k + 1, x3, y3, z3); + } + + return 32 * (n0 + n1 + n2 + n3); + } + + public float GetSimplexFractal(float x, float y) + { + x *= m_frequency; + y *= m_frequency; + + switch(m_fractalType) + { + case FBM: + return SingleSimplexFractalFBM(x, y); + case Billow: + return SingleSimplexFractalBillow(x, y); + case RigidMulti: + return SingleSimplexFractalRigidMulti(x, y); + default: + return 0; + } + } + + private float SingleSimplexFractalFBM(float x, float y) + { + int seed = m_seed; + float sum = SingleSimplex(seed, x, y); + float amp = 1; + + for(int i = 1; i < m_octaves; i++) + { + x *= m_lacunarity; + y *= m_lacunarity; + + amp *= m_gain; + sum += SingleSimplex(++seed, x, y) * amp; + } + + return sum * m_fractalBounding; + } + + private float SingleSimplexFractalBillow(float x, float y) + { + int seed = m_seed; + float sum = Math.abs(SingleSimplex(seed, x, y)) * 2 - 1; + float amp = 1; + + for(int i = 1; i < m_octaves; i++) + { + x *= m_lacunarity; + y *= m_lacunarity; + + amp *= m_gain; + sum += (Math.abs(SingleSimplex(++seed, x, y)) * 2 - 1) * amp; + } + + return sum * m_fractalBounding; + } + + private float SingleSimplexFractalRigidMulti(float x, float y) + { + int seed = m_seed; + float sum = 1 - Math.abs(SingleSimplex(seed, x, y)); + float amp = 1; + + for(int i = 1; i < m_octaves; i++) + { + x *= m_lacunarity; + y *= m_lacunarity; + + amp *= m_gain; + sum -= (1 - Math.abs(SingleSimplex(++seed, x, y))) * amp; + } + + return sum; + } + + public float GetSimplex(float x, float y) + { + return SingleSimplex(m_seed, x * m_frequency, y * m_frequency); + } + + // private final static float F2 = (float) (1.0 / 2.0); + // private final static float G2 = (float) (1.0 / 4.0); + + private final static float SQRT3 = (float) 1.7320508075688772935274463415059; + private final static float F2 = 0.5f * (SQRT3 - 1.0f); + private final static float G2 = (3.0f - SQRT3) / 6.0f; + + private float SingleSimplex(int seed, float x, float y) + { + float t = (x + y) * F2; + int i = FastFloor(x + t); + int j = FastFloor(y + t); + + t = (i + j) * G2; + float X0 = i - t; + float Y0 = j - t; + + float x0 = x - X0; + float y0 = y - Y0; + + int i1, j1; + if(x0 > y0) + { + i1 = 1; + j1 = 0; + } + else + { + i1 = 0; + j1 = 1; + } + + float x1 = x0 - i1 + G2; + float y1 = y0 - j1 + G2; + float x2 = x0 - 1 + 2 * G2; + float y2 = y0 - 1 + 2 * G2; + + float n0, n1, n2; + + t = (float) 0.5 - x0 * x0 - y0 * y0; + if(t < 0) + n0 = 0; + else + { + t *= t; + n0 = t * t * GradCoord2D(seed, i, j, x0, y0); + } + + t = (float) 0.5 - x1 * x1 - y1 * y1; + if(t < 0) + n1 = 0; + else + { + t *= t; + n1 = t * t * GradCoord2D(seed, i + i1, j + j1, x1, y1); + } + + t = (float) 0.5 - x2 * x2 - y2 * y2; + if(t < 0) + n2 = 0; + else + { + t *= t; + n2 = t * t * GradCoord2D(seed, i + 1, j + 1, x2, y2); + } + + return 50 * (n0 + n1 + n2); + } + + public float GetSimplex(float x, float y, float z, float w) + { + return SingleSimplex(m_seed, x * m_frequency, y * m_frequency, z * m_frequency, w * m_frequency); + } + + private static final byte[] SIMPLEX_4D = {0, 1, 2, 3, 0, 1, 3, 2, 0, 0, 0, 0, 0, 2, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 0, 0, 2, 1, 3, 0, 0, 0, 0, 0, 3, 1, 2, 0, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 0, 3, 0, 0, 0, 0, 1, 3, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 0, 1, 2, 3, 1, 0, 1, 0, 2, 3, 1, 0, 3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 3, 1, 0, 0, 0, 0, 2, 1, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 1, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 1, 2, 3, 0, 2, 1, 0, 0, 0, 0, 3, 1, 2, 0, 2, 1, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 1, 0, 2, 0, 0, 0, 0, 3, 2, 0, 1, 3, 2, 1, 0 + }; + + private final static float F4 = (float) ((2.23606797 - 1.0) / 4.0); + private final static float G4 = (float) ((5.0 - 2.23606797) / 20.0); + + private float SingleSimplex(int seed, float x, float y, float z, float w) + { + float n0, n1, n2, n3, n4; + float t = (x + y + z + w) * F4; + int i = FastFloor(x + t); + int j = FastFloor(y + t); + int k = FastFloor(z + t); + int l = FastFloor(w + t); + t = (i + j + k + l) * G4; + float X0 = i - t; + float Y0 = j - t; + float Z0 = k - t; + float W0 = l - t; + float x0 = x - X0; + float y0 = y - Y0; + float z0 = z - Z0; + float w0 = w - W0; + + int c = (x0 > y0) ? 32 : 0; + c += (x0 > z0) ? 16 : 0; + c += (y0 > z0) ? 8 : 0; + c += (x0 > w0) ? 4 : 0; + c += (y0 > w0) ? 2 : 0; + c += (z0 > w0) ? 1 : 0; + c <<= 2; + + int i1 = SIMPLEX_4D[c] >= 3 ? 1 : 0; + int i2 = SIMPLEX_4D[c] >= 2 ? 1 : 0; + int i3 = SIMPLEX_4D[c++] >= 1 ? 1 : 0; + int j1 = SIMPLEX_4D[c] >= 3 ? 1 : 0; + int j2 = SIMPLEX_4D[c] >= 2 ? 1 : 0; + int j3 = SIMPLEX_4D[c++] >= 1 ? 1 : 0; + int k1 = SIMPLEX_4D[c] >= 3 ? 1 : 0; + int k2 = SIMPLEX_4D[c] >= 2 ? 1 : 0; + int k3 = SIMPLEX_4D[c++] >= 1 ? 1 : 0; + int l1 = SIMPLEX_4D[c] >= 3 ? 1 : 0; + int l2 = SIMPLEX_4D[c] >= 2 ? 1 : 0; + int l3 = SIMPLEX_4D[c] >= 1 ? 1 : 0; + + float x1 = x0 - i1 + G4; + float y1 = y0 - j1 + G4; + float z1 = z0 - k1 + G4; + float w1 = w0 - l1 + G4; + float x2 = x0 - i2 + 2 * G4; + float y2 = y0 - j2 + 2 * G4; + float z2 = z0 - k2 + 2 * G4; + float w2 = w0 - l2 + 2 * G4; + float x3 = x0 - i3 + 3 * G4; + float y3 = y0 - j3 + 3 * G4; + float z3 = z0 - k3 + 3 * G4; + float w3 = w0 - l3 + 3 * G4; + float x4 = x0 - 1 + 4 * G4; + float y4 = y0 - 1 + 4 * G4; + float z4 = z0 - 1 + 4 * G4; + float w4 = w0 - 1 + 4 * G4; + + t = (float) 0.6 - x0 * x0 - y0 * y0 - z0 * z0 - w0 * w0; + if(t < 0) + n0 = 0; + else + { + t *= t; + n0 = t * t * GradCoord4D(seed, i, j, k, l, x0, y0, z0, w0); + } + t = (float) 0.6 - x1 * x1 - y1 * y1 - z1 * z1 - w1 * w1; + if(t < 0) + n1 = 0; + else + { + t *= t; + n1 = t * t * GradCoord4D(seed, i + i1, j + j1, k + k1, l + l1, x1, y1, z1, w1); + } + t = (float) 0.6 - x2 * x2 - y2 * y2 - z2 * z2 - w2 * w2; + if(t < 0) + n2 = 0; + else + { + t *= t; + n2 = t * t * GradCoord4D(seed, i + i2, j + j2, k + k2, l + l2, x2, y2, z2, w2); + } + t = (float) 0.6 - x3 * x3 - y3 * y3 - z3 * z3 - w3 * w3; + if(t < 0) + n3 = 0; + else + { + t *= t; + n3 = t * t * GradCoord4D(seed, i + i3, j + j3, k + k3, l + l3, x3, y3, z3, w3); + } + t = (float) 0.6 - x4 * x4 - y4 * y4 - z4 * z4 - w4 * w4; + if(t < 0) + n4 = 0; + else + { + t *= t; + n4 = t * t * GradCoord4D(seed, i + 1, j + 1, k + 1, l + 1, x4, y4, z4, w4); + } + + return 27 * (n0 + n1 + n2 + n3 + n4); + } + + // Cubic Noise + public float GetCubicFractal(float x, float y, float z) + { + x *= m_frequency; + y *= m_frequency; + z *= m_frequency; + + switch(m_fractalType) + { + case FBM: + return SingleCubicFractalFBM(x, y, z); + case Billow: + return SingleCubicFractalBillow(x, y, z); + case RigidMulti: + return SingleCubicFractalRigidMulti(x, y, z); + default: + return 0; + } + } + + private float SingleCubicFractalFBM(float x, float y, float z) + { + int seed = m_seed; + float sum = SingleCubic(seed, x, y, z); + float amp = 1; + int i = 0; + + while(++i < m_octaves) + { + x *= m_lacunarity; + y *= m_lacunarity; + z *= m_lacunarity; + + amp *= m_gain; + sum += SingleCubic(++seed, x, y, z) * amp; + } + + return sum * m_fractalBounding; + } + + private float SingleCubicFractalBillow(float x, float y, float z) + { + int seed = m_seed; + float sum = Math.abs(SingleCubic(seed, x, y, z)) * 2 - 1; + float amp = 1; + int i = 0; + + while(++i < m_octaves) + { + x *= m_lacunarity; + y *= m_lacunarity; + z *= m_lacunarity; + + amp *= m_gain; + sum += (Math.abs(SingleCubic(++seed, x, y, z)) * 2 - 1) * amp; + } + + return sum * m_fractalBounding; + } + + private float SingleCubicFractalRigidMulti(float x, float y, float z) + { + int seed = m_seed; + float sum = 1 - Math.abs(SingleCubic(seed, x, y, z)); + float amp = 1; + int i = 0; + + while(++i < m_octaves) + { + x *= m_lacunarity; + y *= m_lacunarity; + z *= m_lacunarity; + + amp *= m_gain; + sum -= (1 - Math.abs(SingleCubic(++seed, x, y, z))) * amp; + } + + return sum; + } + + public float GetCubic(float x, float y, float z) + { + return SingleCubic(m_seed, x * m_frequency, y * m_frequency, z * m_frequency); + } + + private final static float CUBIC_3D_BOUNDING = 1 / (float) (1.5 * 1.5 * 1.5); + + private float SingleCubic(int seed, float x, float y, float z) + { + int x1 = FastFloor(x); + int y1 = FastFloor(y); + int z1 = FastFloor(z); + + int x0 = x1 - 1; + int y0 = y1 - 1; + int z0 = z1 - 1; + int x2 = x1 + 1; + int y2 = y1 + 1; + int z2 = z1 + 1; + int x3 = x1 + 2; + int y3 = y1 + 2; + int z3 = z1 + 2; + + float xs = x - (float) x1; + float ys = y - (float) y1; + float zs = z - (float) z1; + + return CubicLerp(CubicLerp(CubicLerp(ValCoord3D(seed, x0, y0, z0), ValCoord3D(seed, x1, y0, z0), ValCoord3D(seed, x2, y0, z0), ValCoord3D(seed, x3, y0, z0), xs), CubicLerp(ValCoord3D(seed, x0, y1, z0), ValCoord3D(seed, x1, y1, z0), ValCoord3D(seed, x2, y1, z0), ValCoord3D(seed, x3, y1, z0), xs), CubicLerp(ValCoord3D(seed, x0, y2, z0), ValCoord3D(seed, x1, y2, z0), ValCoord3D(seed, x2, y2, z0), ValCoord3D(seed, x3, y2, z0), xs), CubicLerp(ValCoord3D(seed, x0, y3, z0), ValCoord3D(seed, x1, y3, z0), ValCoord3D(seed, x2, y3, z0), ValCoord3D(seed, x3, y3, z0), xs), ys), CubicLerp(CubicLerp(ValCoord3D(seed, x0, y0, z1), ValCoord3D(seed, x1, y0, z1), ValCoord3D(seed, x2, y0, z1), ValCoord3D(seed, x3, y0, z1), xs), CubicLerp(ValCoord3D(seed, x0, y1, z1), ValCoord3D(seed, x1, y1, z1), ValCoord3D(seed, x2, y1, z1), ValCoord3D(seed, x3, y1, z1), xs), CubicLerp(ValCoord3D(seed, x0, y2, z1), ValCoord3D(seed, x1, y2, z1), ValCoord3D(seed, x2, y2, z1), ValCoord3D(seed, x3, y2, z1), xs), CubicLerp(ValCoord3D(seed, x0, y3, z1), ValCoord3D(seed, x1, y3, z1), ValCoord3D(seed, x2, y3, z1), ValCoord3D(seed, x3, y3, z1), xs), ys), CubicLerp(CubicLerp(ValCoord3D(seed, x0, y0, z2), ValCoord3D(seed, x1, y0, z2), ValCoord3D(seed, x2, y0, z2), ValCoord3D(seed, x3, y0, z2), xs), CubicLerp(ValCoord3D(seed, x0, y1, z2), ValCoord3D(seed, x1, y1, z2), ValCoord3D(seed, x2, y1, z2), ValCoord3D(seed, x3, y1, z2), xs), CubicLerp(ValCoord3D(seed, x0, y2, z2), ValCoord3D(seed, x1, y2, z2), ValCoord3D(seed, x2, y2, z2), ValCoord3D(seed, x3, y2, z2), xs), CubicLerp(ValCoord3D(seed, x0, y3, z2), ValCoord3D(seed, x1, y3, z2), ValCoord3D(seed, x2, y3, z2), ValCoord3D(seed, x3, y3, z2), xs), ys), CubicLerp(CubicLerp(ValCoord3D(seed, x0, y0, z3), ValCoord3D(seed, x1, y0, z3), ValCoord3D(seed, x2, y0, z3), ValCoord3D(seed, x3, y0, z3), xs), CubicLerp(ValCoord3D(seed, x0, y1, z3), ValCoord3D(seed, x1, y1, z3), ValCoord3D(seed, x2, y1, z3), ValCoord3D(seed, x3, y1, z3), xs), CubicLerp(ValCoord3D(seed, x0, y2, z3), ValCoord3D(seed, x1, y2, z3), ValCoord3D(seed, x2, y2, z3), ValCoord3D(seed, x3, y2, z3), xs), CubicLerp(ValCoord3D(seed, x0, y3, z3), ValCoord3D(seed, x1, y3, z3), ValCoord3D(seed, x2, y3, z3), ValCoord3D(seed, x3, y3, z3), xs), ys), zs) * CUBIC_3D_BOUNDING; + } + + public float GetCubicFractal(float x, float y) + { + x *= m_frequency; + y *= m_frequency; + + switch(m_fractalType) + { + case FBM: + return SingleCubicFractalFBM(x, y); + case Billow: + return SingleCubicFractalBillow(x, y); + case RigidMulti: + return SingleCubicFractalRigidMulti(x, y); + default: + return 0; + } + } + + private float SingleCubicFractalFBM(float x, float y) + { + int seed = m_seed; + float sum = SingleCubic(seed, x, y); + float amp = 1; + int i = 0; + + while(++i < m_octaves) + { + x *= m_lacunarity; + y *= m_lacunarity; + + amp *= m_gain; + sum += SingleCubic(++seed, x, y) * amp; + } + + return sum * m_fractalBounding; + } + + private float SingleCubicFractalBillow(float x, float y) + { + int seed = m_seed; + float sum = Math.abs(SingleCubic(seed, x, y)) * 2 - 1; + float amp = 1; + int i = 0; + + while(++i < m_octaves) + { + x *= m_lacunarity; + y *= m_lacunarity; + + amp *= m_gain; + sum += (Math.abs(SingleCubic(++seed, x, y)) * 2 - 1) * amp; + } + + return sum * m_fractalBounding; + } + + private float SingleCubicFractalRigidMulti(float x, float y) + { + int seed = m_seed; + float sum = 1 - Math.abs(SingleCubic(seed, x, y)); + float amp = 1; + int i = 0; + + while(++i < m_octaves) + { + x *= m_lacunarity; + y *= m_lacunarity; + + amp *= m_gain; + sum -= (1 - Math.abs(SingleCubic(++seed, x, y))) * amp; + } + + return sum; + } + + public float GetCubic(float x, float y) + { + x *= m_frequency; + y *= m_frequency; + + return SingleCubic(0, x, y); + } + + private final static float CUBIC_2D_BOUNDING = 1 / (float) (1.5 * 1.5); + + private float SingleCubic(int seed, float x, float y) + { + int x1 = FastFloor(x); + int y1 = FastFloor(y); + + int x0 = x1 - 1; + int y0 = y1 - 1; + int x2 = x1 + 1; + int y2 = y1 + 1; + int x3 = x1 + 2; + int y3 = y1 + 2; + + float xs = x - (float) x1; + float ys = y - (float) y1; + + return CubicLerp(CubicLerp(ValCoord2D(seed, x0, y0), ValCoord2D(seed, x1, y0), ValCoord2D(seed, x2, y0), ValCoord2D(seed, x3, y0), xs), CubicLerp(ValCoord2D(seed, x0, y1), ValCoord2D(seed, x1, y1), ValCoord2D(seed, x2, y1), ValCoord2D(seed, x3, y1), xs), CubicLerp(ValCoord2D(seed, x0, y2), ValCoord2D(seed, x1, y2), ValCoord2D(seed, x2, y2), ValCoord2D(seed, x3, y2), xs), CubicLerp(ValCoord2D(seed, x0, y3), ValCoord2D(seed, x1, y3), ValCoord2D(seed, x2, y3), ValCoord2D(seed, x3, y3), xs), ys) * CUBIC_2D_BOUNDING; + } + + // Cellular Noise + public float GetCellular(float x, float y, float z) + { + x *= m_frequency; + y *= m_frequency; + z *= m_frequency; + + switch(m_cellularReturnType) + { + case CellValue: + case NoiseLookup: + case Distance: + return SingleCellular(x, y, z); + default: + return SingleCellular2Edge(x, y, z); + } + } + + private float SingleCellular(float x, float y, float z) + { + int xr = FastRound(x); + int yr = FastRound(y); + int zr = FastRound(z); + + float distance = 999999; + int xc = 0, yc = 0, zc = 0; + + switch(m_cellularDistanceFunction) + { + case Euclidean: + for(int xi = xr - 1; xi <= xr + 1; xi++) + { + for(int yi = yr - 1; yi <= yr + 1; yi++) + { + for(int zi = zr - 1; zi <= zr + 1; zi++) + { + Float3 vec = CELL_3D[Hash3D(m_seed, xi, yi, zi) & 255]; + + float vecX = xi - x + vec.x; + float vecY = yi - y + vec.y; + float vecZ = zi - z + vec.z; + + float newDistance = vecX * vecX + vecY * vecY + vecZ * vecZ; + + if(newDistance < distance) + { + distance = newDistance; + xc = xi; + yc = yi; + zc = zi; + } + } + } + } + break; + case Manhattan: + for(int xi = xr - 1; xi <= xr + 1; xi++) + { + for(int yi = yr - 1; yi <= yr + 1; yi++) + { + for(int zi = zr - 1; zi <= zr + 1; zi++) + { + Float3 vec = CELL_3D[Hash3D(m_seed, xi, yi, zi) & 255]; + + float vecX = xi - x + vec.x; + float vecY = yi - y + vec.y; + float vecZ = zi - z + vec.z; + + float newDistance = Math.abs(vecX) + Math.abs(vecY) + Math.abs(vecZ); + + if(newDistance < distance) + { + distance = newDistance; + xc = xi; + yc = yi; + zc = zi; + } + } + } + } + break; + case Natural: + for(int xi = xr - 1; xi <= xr + 1; xi++) + { + for(int yi = yr - 1; yi <= yr + 1; yi++) + { + for(int zi = zr - 1; zi <= zr + 1; zi++) + { + Float3 vec = CELL_3D[Hash3D(m_seed, xi, yi, zi) & 255]; + + float vecX = xi - x + vec.x; + float vecY = yi - y + vec.y; + float vecZ = zi - z + vec.z; + + float newDistance = (Math.abs(vecX) + Math.abs(vecY) + Math.abs(vecZ)) + (vecX * vecX + vecY * vecY + vecZ * vecZ); + + if(newDistance < distance) + { + distance = newDistance; + xc = xi; + yc = yi; + zc = zi; + } + } + } + } + break; + } + + switch(m_cellularReturnType) + { + case CellValue: + return ValCoord3D(0, xc, yc, zc); + + case NoiseLookup: + Float3 vec = CELL_3D[Hash3D(m_seed, xc, yc, zc) & 255]; + return m_cellularNoiseLookup.GetNoise(xc + vec.x, yc + vec.y, zc + vec.z); + + case Distance: + return distance - 1; + default: + return 0; + } + } + + private float SingleCellular2Edge(float x, float y, float z) + { + int xr = FastRound(x); + int yr = FastRound(y); + int zr = FastRound(z); + + float distance = 999999; + float distance2 = 999999; + + switch(m_cellularDistanceFunction) + { + case Euclidean: + for(int xi = xr - 1; xi <= xr + 1; xi++) + { + for(int yi = yr - 1; yi <= yr + 1; yi++) + { + for(int zi = zr - 1; zi <= zr + 1; zi++) + { + Float3 vec = CELL_3D[Hash3D(m_seed, xi, yi, zi) & 255]; + + float vecX = xi - x + vec.x; + float vecY = yi - y + vec.y; + float vecZ = zi - z + vec.z; + + float newDistance = vecX * vecX + vecY * vecY + vecZ * vecZ; + + distance2 = Math.max(Math.min(distance2, newDistance), distance); + distance = Math.min(distance, newDistance); + } + } + } + break; + case Manhattan: + for(int xi = xr - 1; xi <= xr + 1; xi++) + { + for(int yi = yr - 1; yi <= yr + 1; yi++) + { + for(int zi = zr - 1; zi <= zr + 1; zi++) + { + Float3 vec = CELL_3D[Hash3D(m_seed, xi, yi, zi) & 255]; + + float vecX = xi - x + vec.x; + float vecY = yi - y + vec.y; + float vecZ = zi - z + vec.z; + + float newDistance = Math.abs(vecX) + Math.abs(vecY) + Math.abs(vecZ); + + distance2 = Math.max(Math.min(distance2, newDistance), distance); + distance = Math.min(distance, newDistance); + } + } + } + break; + case Natural: + for(int xi = xr - 1; xi <= xr + 1; xi++) + { + for(int yi = yr - 1; yi <= yr + 1; yi++) + { + for(int zi = zr - 1; zi <= zr + 1; zi++) + { + Float3 vec = CELL_3D[Hash3D(m_seed, xi, yi, zi) & 255]; + + float vecX = xi - x + vec.x; + float vecY = yi - y + vec.y; + float vecZ = zi - z + vec.z; + + float newDistance = (Math.abs(vecX) + Math.abs(vecY) + Math.abs(vecZ)) + (vecX * vecX + vecY * vecY + vecZ * vecZ); + + distance2 = Math.max(Math.min(distance2, newDistance), distance); + distance = Math.min(distance, newDistance); + } + } + } + break; + default: + break; + } + + switch(m_cellularReturnType) + { + case Distance2: + return distance2 - 1; + case Distance2Add: + return distance2 + distance - 1; + case Distance2Sub: + return distance2 - distance - 1; + case Distance2Mul: + return distance2 * distance - 1; + case Distance2Div: + return distance / distance2 - 1; + default: + return 0; + } + } + + public float GetCellular(float x, float y) + { + x *= m_frequency; + y *= m_frequency; + + switch(m_cellularReturnType) + { + case CellValue: + case NoiseLookup: + case Distance: + return SingleCellular(x, y); + default: + return SingleCellular2Edge(x, y); + } + } + + private float SingleCellular(float x, float y) + { + int xr = FastRound(x); + int yr = FastRound(y); + + float distance = 999999; + int xc = 0, yc = 0; + + switch(m_cellularDistanceFunction) + { + default: + case Euclidean: + for(int xi = xr - 1; xi <= xr + 1; xi++) + { + for(int yi = yr - 1; yi <= yr + 1; yi++) + { + Float2 vec = CELL_2D[Hash2D(m_seed, xi, yi) & 255]; + + float vecX = xi - x + vec.x; + float vecY = yi - y + vec.y; + + float newDistance = vecX * vecX + vecY * vecY; + + if(newDistance < distance) + { + distance = newDistance; + xc = xi; + yc = yi; + } + } + } + break; + case Manhattan: + for(int xi = xr - 1; xi <= xr + 1; xi++) + { + for(int yi = yr - 1; yi <= yr + 1; yi++) + { + Float2 vec = CELL_2D[Hash2D(m_seed, xi, yi) & 255]; + + float vecX = xi - x + vec.x; + float vecY = yi - y + vec.y; + + float newDistance = (Math.abs(vecX) + Math.abs(vecY)); + + if(newDistance < distance) + { + distance = newDistance; + xc = xi; + yc = yi; + } + } + } + break; + case Natural: + for(int xi = xr - 1; xi <= xr + 1; xi++) + { + for(int yi = yr - 1; yi <= yr + 1; yi++) + { + Float2 vec = CELL_2D[Hash2D(m_seed, xi, yi) & 255]; + + float vecX = xi - x + vec.x; + float vecY = yi - y + vec.y; + + float newDistance = (Math.abs(vecX) + Math.abs(vecY)) + (vecX * vecX + vecY * vecY); + + if(newDistance < distance) + { + distance = newDistance; + xc = xi; + yc = yi; + } + } + } + break; + } + + switch(m_cellularReturnType) + { + case CellValue: + return ValCoord2D(0, xc, yc); + + case NoiseLookup: + Float2 vec = CELL_2D[Hash2D(m_seed, xc, yc) & 255]; + return m_cellularNoiseLookup.GetNoise(xc + vec.x, yc + vec.y); + + case Distance: + return distance - 1; + default: + return 0; + } + } + + private float SingleCellular2Edge(float x, float y) + { + int xr = FastRound(x); + int yr = FastRound(y); + + float distance = 999999; + float distance2 = 999999; + + switch(m_cellularDistanceFunction) + { + default: + case Euclidean: + for(int xi = xr - 1; xi <= xr + 1; xi++) + { + for(int yi = yr - 1; yi <= yr + 1; yi++) + { + Float2 vec = CELL_2D[Hash2D(m_seed, xi, yi) & 255]; + + float vecX = xi - x + vec.x; + float vecY = yi - y + vec.y; + + float newDistance = vecX * vecX + vecY * vecY; + + distance2 = Math.max(Math.min(distance2, newDistance), distance); + distance = Math.min(distance, newDistance); + } + } + break; + case Manhattan: + for(int xi = xr - 1; xi <= xr + 1; xi++) + { + for(int yi = yr - 1; yi <= yr + 1; yi++) + { + Float2 vec = CELL_2D[Hash2D(m_seed, xi, yi) & 255]; + + float vecX = xi - x + vec.x; + float vecY = yi - y + vec.y; + + float newDistance = Math.abs(vecX) + Math.abs(vecY); + + distance2 = Math.max(Math.min(distance2, newDistance), distance); + distance = Math.min(distance, newDistance); + } + } + break; + case Natural: + for(int xi = xr - 1; xi <= xr + 1; xi++) + { + for(int yi = yr - 1; yi <= yr + 1; yi++) + { + Float2 vec = CELL_2D[Hash2D(m_seed, xi, yi) & 255]; + + float vecX = xi - x + vec.x; + float vecY = yi - y + vec.y; + + float newDistance = (Math.abs(vecX) + Math.abs(vecY)) + (vecX * vecX + vecY * vecY); + + distance2 = Math.max(Math.min(distance2, newDistance), distance); + distance = Math.min(distance, newDistance); + } + } + break; + } + + switch(m_cellularReturnType) + { + case Distance2: + return distance2 - 1; + case Distance2Add: + return distance2 + distance - 1; + case Distance2Sub: + return distance2 - distance - 1; + case Distance2Mul: + return distance2 * distance - 1; + case Distance2Div: + return distance / distance2 - 1; + default: + return 0; + } + } + + public void GradientPerturb(Vector3f v3) + { + SingleGradientPerturb(m_seed, m_gradientPerturbAmp, m_frequency, v3); + } + + public void GradientPerturbFractal(Vector3f v3) + { + int seed = m_seed; + float amp = m_gradientPerturbAmp * m_fractalBounding; + float freq = m_frequency; + + SingleGradientPerturb(seed, amp, m_frequency, v3); + + for(int i = 1; i < m_octaves; i++) + { + freq *= m_lacunarity; + amp *= m_gain; + SingleGradientPerturb(++seed, amp, freq, v3); + } + } + + private void SingleGradientPerturb(int seed, float perturbAmp, float frequency, Vector3f v3) + { + float xf = v3.x * frequency; + float yf = v3.y * frequency; + float zf = v3.z * frequency; + + int x0 = FastFloor(xf); + int y0 = FastFloor(yf); + int z0 = FastFloor(zf); + int x1 = x0 + 1; + int y1 = y0 + 1; + int z1 = z0 + 1; + + float xs, ys, zs; + switch(m_interp) + { + default: + case Linear: + xs = xf - x0; + ys = yf - y0; + zs = zf - z0; + break; + case Hermite: + xs = InterpHermiteFunc(xf - x0); + ys = InterpHermiteFunc(yf - y0); + zs = InterpHermiteFunc(zf - z0); + break; + case Quintic: + xs = InterpQuinticFunc(xf - x0); + ys = InterpQuinticFunc(yf - y0); + zs = InterpQuinticFunc(zf - z0); + break; + } + + Float3 vec0 = CELL_3D[Hash3D(seed, x0, y0, z0) & 255]; + Float3 vec1 = CELL_3D[Hash3D(seed, x1, y0, z0) & 255]; + + float lx0x = Lerp(vec0.x, vec1.x, xs); + float ly0x = Lerp(vec0.y, vec1.y, xs); + float lz0x = Lerp(vec0.z, vec1.z, xs); + + vec0 = CELL_3D[Hash3D(seed, x0, y1, z0) & 255]; + vec1 = CELL_3D[Hash3D(seed, x1, y1, z0) & 255]; + + float lx1x = Lerp(vec0.x, vec1.x, xs); + float ly1x = Lerp(vec0.y, vec1.y, xs); + float lz1x = Lerp(vec0.z, vec1.z, xs); + + float lx0y = Lerp(lx0x, lx1x, ys); + float ly0y = Lerp(ly0x, ly1x, ys); + float lz0y = Lerp(lz0x, lz1x, ys); + + vec0 = CELL_3D[Hash3D(seed, x0, y0, z1) & 255]; + vec1 = CELL_3D[Hash3D(seed, x1, y0, z1) & 255]; + + lx0x = Lerp(vec0.x, vec1.x, xs); + ly0x = Lerp(vec0.y, vec1.y, xs); + lz0x = Lerp(vec0.z, vec1.z, xs); + + vec0 = CELL_3D[Hash3D(seed, x0, y1, z1) & 255]; + vec1 = CELL_3D[Hash3D(seed, x1, y1, z1) & 255]; + + lx1x = Lerp(vec0.x, vec1.x, xs); + ly1x = Lerp(vec0.y, vec1.y, xs); + lz1x = Lerp(vec0.z, vec1.z, xs); + + v3.x += Lerp(lx0y, Lerp(lx0x, lx1x, ys), zs) * perturbAmp; + v3.y += Lerp(ly0y, Lerp(ly0x, ly1x, ys), zs) * perturbAmp; + v3.z += Lerp(lz0y, Lerp(lz0x, lz1x, ys), zs) * perturbAmp; + } + + public void GradientPerturb(Vector2f v2) + { + SingleGradientPerturb(m_seed, m_gradientPerturbAmp, m_frequency, v2); + } + + public void GradientPerturbFractal(Vector2f v2) + { + int seed = m_seed; + float amp = m_gradientPerturbAmp * m_fractalBounding; + float freq = m_frequency; + + SingleGradientPerturb(seed, amp, m_frequency, v2); + + for(int i = 1; i < m_octaves; i++) + { + freq *= m_lacunarity; + amp *= m_gain; + SingleGradientPerturb(++seed, amp, freq, v2); + } + } + + private void SingleGradientPerturb(int seed, float perturbAmp, float frequency, Vector2f v2) + { + float xf = v2.x * frequency; + float yf = v2.y * frequency; + + int x0 = FastFloor(xf); + int y0 = FastFloor(yf); + int x1 = x0 + 1; + int y1 = y0 + 1; + + float xs, ys; + switch(m_interp) + { + default: + case Linear: + xs = xf - x0; + ys = yf - y0; + break; + case Hermite: + xs = InterpHermiteFunc(xf - x0); + ys = InterpHermiteFunc(yf - y0); + break; + case Quintic: + xs = InterpQuinticFunc(xf - x0); + ys = InterpQuinticFunc(yf - y0); + break; + } + + Float2 vec0 = CELL_2D[Hash2D(seed, x0, y0) & 255]; + Float2 vec1 = CELL_2D[Hash2D(seed, x1, y0) & 255]; + + float lx0x = Lerp(vec0.x, vec1.x, xs); + float ly0x = Lerp(vec0.y, vec1.y, xs); + + vec0 = CELL_2D[Hash2D(seed, x0, y1) & 255]; + vec1 = CELL_2D[Hash2D(seed, x1, y1) & 255]; + + float lx1x = Lerp(vec0.x, vec1.x, xs); + float ly1x = Lerp(vec0.y, vec1.y, xs); + + v2.x += Lerp(lx0x, lx1x, ys) * perturbAmp; + v2.y += Lerp(ly0x, ly1x, ys) * perturbAmp; + } + +} \ No newline at end of file diff --git a/src/main/java/com/volmit/iris/noise/WhiteNoise.java b/src/main/java/com/volmit/iris/noise/WhiteNoise.java index 82afb7c9c..d49c3b558 100644 --- a/src/main/java/com/volmit/iris/noise/WhiteNoise.java +++ b/src/main/java/com/volmit/iris/noise/WhiteNoise.java @@ -4,16 +4,16 @@ import com.volmit.iris.util.RNG; public class WhiteNoise implements NoiseGenerator { - private final FastNoiseDouble n; + private final FastNoise n; public WhiteNoise(long seed) { - n = new FastNoiseDouble(new RNG(seed).lmax()); + n = new FastNoise(new RNG(seed).imax()); } private double f(double m) { - return m; + return (m % 8192) * 1024; } @Override diff --git a/src/main/java/com/volmit/iris/object/IrisCaveFluid.java b/src/main/java/com/volmit/iris/object/IrisCaveFluid.java index 19e8d05de..4bb31d28d 100644 --- a/src/main/java/com/volmit/iris/object/IrisCaveFluid.java +++ b/src/main/java/com/volmit/iris/object/IrisCaveFluid.java @@ -22,12 +22,11 @@ import lombok.experimental.Accessors; @Data public class IrisCaveFluid { - @Required @MaxNumber(255) @MinNumber(0) @DontObfuscate - @Desc("The cave zoom. Higher values makes caves spread out further and branch less often, but are thicker.") + @Desc("The fluid height of the cave") private int fluidHeight = 35; @DontObfuscate diff --git a/src/main/java/com/volmit/iris/object/IrisCompat.java b/src/main/java/com/volmit/iris/object/IrisCompat.java index 281134f9c..eaff4653e 100644 --- a/src/main/java/com/volmit/iris/object/IrisCompat.java +++ b/src/main/java/com/volmit/iris/object/IrisCompat.java @@ -94,8 +94,16 @@ public class IrisCompat return txf; } + int nomore = 64; + searching: while(true) { + if(nomore < 0) + { + return B.parseBlockDataOrNull("STONE").getType(); + } + + nomore--; if(err-- <= 0) { break; @@ -127,9 +135,17 @@ public class IrisCompat { return tx.getType(); } + nomore = 64; searching: while(true) { + if(nomore < 0) + { + return B.parseBlockDataOrNull("STONE").getType(); + } + + nomore--; + if(err-- <= 0) { return B.parseBlockDataOrNull("STONE").getType(); diff --git a/src/main/java/com/volmit/iris/object/IrisDimension.java b/src/main/java/com/volmit/iris/object/IrisDimension.java index 8f2fd8b05..efddb39ab 100644 --- a/src/main/java/com/volmit/iris/object/IrisDimension.java +++ b/src/main/java/com/volmit/iris/object/IrisDimension.java @@ -82,11 +82,6 @@ public class IrisDimension extends IrisRegistrant @Desc("Reference loot tables in this area") private IrisLootReference loot = new IrisLootReference(); - @DontObfuscate - @MinNumber(0) - @Desc("Try to fill a container with loot up to this many times to avoid too many empty chests.") - private int lootTries = 5; - @Required @MinNumber(0) @DontObfuscate @@ -168,6 +163,10 @@ public class IrisDimension extends IrisRegistrant @Desc("Generate vanilla structures") private boolean vanillaStructures = false; + @DontObfuscate + @Desc("If defined, If air is defined below the area, this fluid will always place") + private IrisCaveFluid forceFluid = new IrisCaveFluid(); + @DontObfuscate @Desc("Generate decorations or not") private boolean decorate = true; diff --git a/src/main/java/com/volmit/iris/object/IrisEntity.java b/src/main/java/com/volmit/iris/object/IrisEntity.java index eaa5b6b64..19ac11468 100644 --- a/src/main/java/com/volmit/iris/object/IrisEntity.java +++ b/src/main/java/com/volmit/iris/object/IrisEntity.java @@ -6,10 +6,13 @@ import java.util.Random; import org.bukkit.Location; import org.bukkit.NamespacedKey; import org.bukkit.attribute.Attributable; +import org.bukkit.entity.Ageable; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Mob; +import org.bukkit.entity.Panda; +import org.bukkit.entity.Panda.Gene; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.loot.LootContext; @@ -134,6 +137,18 @@ public class IrisEntity extends IrisRegistrant @Desc("If specified, this entity will be leashed by this entity. I.e. THIS ENTITY Leashed by SPECIFIED. This has no effect on EnderDragons, Withers, Players, or Bats.Non-living entities excluding leashes will not persist as leashholders.") private IrisEntity leashHolder = null; + @DontObfuscate + @Desc("The main gene for a panda if the entity type is a panda") + private Gene pandaMainGene = Gene.NORMAL; + + @DontObfuscate + @Desc("The hidden gene for a panda if the entity type is a panda") + private Gene pandaHiddenGene = Gene.NORMAL; + + @DontObfuscate + @Desc("The this entity is ageable, set it's baby status") + private boolean baby = false; + public Entity spawn(ParallaxTerrainProvider gen, Location at) { return spawn(gen, at, new RNG(at.hashCode())); @@ -184,15 +199,10 @@ public class IrisEntity extends IrisRegistrant { KList items = new KList<>(); - for(int t = 0; t < gen.getDimension().getLootTries(); t++) + for(String fi : getLoot().getTables()) { - int b = 4; - for(String fi : getLoot().getTables()) - { - IrisLootTable i = gen.getData().getLootLoader().load(fi); - b++; - items.addAll(i.getLoot(gen.isDev(), rng.nextParallelRNG(345911 * -t), InventorySlotType.STORAGE, at.getBlockX(), at.getBlockY(), at.getBlockZ(), t + b + b, b)); - } + IrisLootTable i = gen.getData().getLootLoader().load(fi); + items.addAll(i.getLoot(gen.isDev(), false, rng.nextParallelRNG(345911), InventorySlotType.STORAGE, at.getBlockX(), at.getBlockY(), at.getBlockZ(), 8, 4)); } return items; @@ -256,6 +266,17 @@ public class IrisEntity extends IrisRegistrant } } + if(e instanceof Ageable && isBaby()) + { + ((Ageable) e).setBaby(); + } + + if(e instanceof Panda) + { + ((Panda) e).setMainGene(getPandaMainGene()); + ((Panda) e).setMainGene(getPandaHiddenGene()); + } + if(Iris.awareEntities && e instanceof Mob) { Mob m = (Mob) e; diff --git a/src/main/java/com/volmit/iris/object/IrisLoot.java b/src/main/java/com/volmit/iris/object/IrisLoot.java index f11ab572b..6928152f7 100644 --- a/src/main/java/com/volmit/iris/object/IrisLoot.java +++ b/src/main/java/com/volmit/iris/object/IrisLoot.java @@ -217,14 +217,14 @@ public class IrisLoot return new ItemStack(Material.AIR); } - public ItemStack get(boolean debug, IrisLootTable table, RNG rng, int x, int y, int z) + public ItemStack get(boolean debug, boolean giveSomething, IrisLootTable table, RNG rng, int x, int y, int z) { if(debug) { chance.reset(); } - if(chance.aquire(() -> NoiseStyle.STATIC.create(rng)).fit(1, rarity * table.getRarity(), x, y, z) == 1) + if(giveSomething || chance.aquire(() -> NoiseStyle.STATIC.create(rng)).fit(1, rarity * table.getRarity(), x, y, z) == 1) { if(getType() == null) { diff --git a/src/main/java/com/volmit/iris/object/IrisLootTable.java b/src/main/java/com/volmit/iris/object/IrisLootTable.java index f5bc64c48..bbe485b2b 100644 --- a/src/main/java/com/volmit/iris/object/IrisLootTable.java +++ b/src/main/java/com/volmit/iris/object/IrisLootTable.java @@ -39,14 +39,19 @@ public class IrisLootTable extends IrisRegistrant @MinNumber(1) @DontObfuscate @Desc("The maximum amount of loot that can be picked in this table at a time.") - private int maxPicked = 3; + private int maxPicked = 5; + + @MinNumber(0) + @DontObfuscate + @Desc("The minimum amount of loot that can be picked in this table at a time.") + private int minPicked = 1; @DontObfuscate @Desc("The loot in this table") @ArrayType(min = 1, type = IrisLoot.class) private KList loot = new KList<>(); - public KList getLoot(boolean debug, RNG rng, InventorySlotType slot, int x, int y, int z, int gg, int ffs) + public KList getLoot(boolean debug, boolean doSomething, RNG rng, InventorySlotType slot, int x, int y, int z, int gg, int ffs) { KList lootf = new KList<>(); @@ -56,7 +61,7 @@ public class IrisLootTable extends IrisRegistrant { if(i.getSlotTypes().equals(slot)) { - ItemStack item = i.get(debug, this, rng, x, y, z); + ItemStack item = i.get(debug, false, this, rng, x, y, z); if(item != null) { @@ -72,6 +77,18 @@ public class IrisLootTable extends IrisRegistrant } } + if(lootf.size() < getMinPicked()) + { + for(int i = 0; i < getMinPicked() - lootf.size(); i++) + { + ItemStack item = loot.get(rng.nextParallelRNG(3945).nextInt(loot.size())).get(debug, doSomething, this, rng, x, y, z); + if(item != null) + { + lootf.add(item); + } + } + } + return lootf; } } diff --git a/src/main/java/com/volmit/iris/util/B.java b/src/main/java/com/volmit/iris/util/B.java index a9fb36599..9f2e0142d 100644 --- a/src/main/java/com/volmit/iris/util/B.java +++ b/src/main/java/com/volmit/iris/util/B.java @@ -138,20 +138,15 @@ public class B { String bd = bdx.trim().toUpperCase(); - return typesb.get(bd, (k) -> + try { - try - { - return FastBlockData.of(Material.valueOf(k)); - } - - catch(Throwable e) - { - - } + return Material.valueOf(bd); + } + catch(Throwable e) + { return null; - }).getType(); + } } public static boolean isSolid(FastBlockData mat) @@ -337,8 +332,33 @@ public class B return true; } - // @NoArgsConstructor - boolean str = mat.equals(B.mat("CHEST")) || mat.equals(B.mat("TRAPPED_CHEST")) || mat.equals(B.mat("SHULKER_BOX")) || mat.equals(B.mat("WHITE_SHULKER_BOX")) || mat.equals(B.mat("ORANGE_SHULKER_BOX")) || mat.equals(B.mat("MAGENTA_SHULKER_BOX")) || mat.equals(B.mat("LIGHT_BLUE_SHULKER_BOX")) || mat.equals(B.mat("YELLOW_SHULKER_BOX")) || mat.equals(B.mat("LIME_SHULKER_BOX")) || mat.equals(B.mat("PINK_SHULKER_BOX")) || mat.equals(B.mat("GRAY_SHULKER_BOX")) || mat.equals(B.mat("LIGHT_GRAY_SHULKER_BOX")) || mat.equals(B.mat("CYAN_SHULKER_BOX")) || mat.equals(B.mat("PURPLE_SHULKER_BOX")) || mat.equals(B.mat("BLUE_SHULKER_BOX")) || mat.equals(B.mat("BROWN_SHULKER_BOX")) || mat.equals(B.mat("GREEN_SHULKER_BOX")) || mat.equals(B.mat("RED_SHULKER_BOX")) || mat.equals(B.mat("BLACK_SHULKER_BOX")) || mat.equals(B.mat("BARREL")) || mat.equals(B.mat("DISPENSER")) || mat.equals(B.mat("DROPPER")) || mat.equals(B.mat("HOPPER")) || mat.equals(B.mat("FURNACE")) || mat.equals(B.mat("BLAST_FURNACE")) || mat.equals(B.mat("SMOKER")); + // @builder + boolean str = mat.matEquals(B.mat("CHEST")) + || mat.matEquals(B.mat("TRAPPED_CHEST")) + || mat.matEquals(B.mat("SHULKER_BOX")) + || mat.matEquals(B.mat("WHITE_SHULKER_BOX")) + || mat.matEquals(B.mat("ORANGE_SHULKER_BOX")) + || mat.matEquals(B.mat("MAGENTA_SHULKER_BOX")) + || mat.matEquals(B.mat("LIGHT_BLUE_SHULKER_BOX")) + || mat.matEquals(B.mat("YELLOW_SHULKER_BOX")) + || mat.matEquals(B.mat("LIME_SHULKER_BOX")) + || mat.matEquals(B.mat("PINK_SHULKER_BOX")) + || mat.matEquals(B.mat("GRAY_SHULKER_BOX")) + || mat.matEquals(B.mat("LIGHT_GRAY_SHULKER_BOX")) + || mat.matEquals(B.mat("CYAN_SHULKER_BOX")) + || mat.matEquals(B.mat("PURPLE_SHULKER_BOX")) + || mat.matEquals(B.mat("BLUE_SHULKER_BOX")) + || mat.matEquals(B.mat("BROWN_SHULKER_BOX")) + || mat.matEquals(B.mat("GREEN_SHULKER_BOX")) + || mat.matEquals(B.mat("RED_SHULKER_BOX")) + || mat.matEquals(B.mat("BLACK_SHULKER_BOX")) + || mat.matEquals(B.mat("BARREL")) + || mat.matEquals(B.mat("DISPENSER")) + || mat.matEquals(B.mat("DROPPER")) + || mat.matEquals(B.mat("HOPPER")) + || mat.matEquals(B.mat("FURNACE")) + || mat.matEquals(B.mat("BLAST_FURNACE")) + || mat.matEquals(B.mat("SMOKER")); //@done if(str) @@ -359,8 +379,30 @@ public class B return true; } - // @NoArgsConstructor - boolean str = mat.equals(B.mat("CHEST")) || mat.equals(B.mat("TRAPPED_CHEST")) || mat.equals(B.mat("SHULKER_BOX")) || mat.equals(B.mat("WHITE_SHULKER_BOX")) || mat.equals(B.mat("ORANGE_SHULKER_BOX")) || mat.equals(B.mat("MAGENTA_SHULKER_BOX")) || mat.equals(B.mat("LIGHT_BLUE_SHULKER_BOX")) || mat.equals(B.mat("YELLOW_SHULKER_BOX")) || mat.equals(B.mat("LIME_SHULKER_BOX")) || mat.equals(B.mat("PINK_SHULKER_BOX")) || mat.equals(B.mat("GRAY_SHULKER_BOX")) || mat.equals(B.mat("LIGHT_GRAY_SHULKER_BOX")) || mat.equals(B.mat("CYAN_SHULKER_BOX")) || mat.equals(B.mat("PURPLE_SHULKER_BOX")) || mat.equals(B.mat("BLUE_SHULKER_BOX")) || mat.equals(B.mat("BROWN_SHULKER_BOX")) || mat.equals(B.mat("GREEN_SHULKER_BOX")) || mat.equals(B.mat("RED_SHULKER_BOX")) || mat.equals(B.mat("BLACK_SHULKER_BOX")) || mat.equals(B.mat("BARREL")) || mat.equals(B.mat("DISPENSER")) || mat.equals(B.mat("DROPPER")) || mat.equals(B.mat("HOPPER")); + // @builder + boolean str = mat.matEquals(B.mat("CHEST")) + || mat.matEquals(B.mat("TRAPPED_CHEST")) + || mat.matEquals(B.mat("SHULKER_BOX")) + || mat.matEquals(B.mat("WHITE_SHULKER_BOX")) + || mat.matEquals(B.mat("ORANGE_SHULKER_BOX")) + || mat.matEquals(B.mat("MAGENTA_SHULKER_BOX")) + || mat.matEquals(B.mat("LIGHT_BLUE_SHULKER_BOX")) + || mat.matEquals(B.mat("YELLOW_SHULKER_BOX")) + || mat.matEquals(B.mat("LIME_SHULKER_BOX")) + || mat.matEquals(B.mat("PINK_SHULKER_BOX")) + || mat.matEquals(B.mat("GRAY_SHULKER_BOX")) + || mat.matEquals(B.mat("LIGHT_GRAY_SHULKER_BOX")) + || mat.matEquals(B.mat("CYAN_SHULKER_BOX")) + || mat.matEquals(B.mat("PURPLE_SHULKER_BOX")) + || mat.matEquals(B.mat("BLUE_SHULKER_BOX")) + || mat.matEquals(B.mat("BROWN_SHULKER_BOX")) + || mat.matEquals(B.mat("GREEN_SHULKER_BOX")) + || mat.matEquals(B.mat("RED_SHULKER_BOX")) + || mat.matEquals(B.mat("BLACK_SHULKER_BOX")) + || mat.matEquals(B.mat("BARREL")) + || mat.matEquals(B.mat("DISPENSER")) + || mat.matEquals(B.mat("DROPPER")) + || mat.matEquals(B.mat("HOPPER")); //@done if(str) @@ -381,8 +423,28 @@ public class B return true; } - // @NoArgsConstructor - boolean str = mat.equals(B.mat("GLOWSTONE")) || mat.equals(B.mat("END_ROD")) || mat.equals(B.mat("SOUL_SAND")) || mat.equals(B.mat("TORCH")) || mat.getType().equals(Material.REDSTONE_TORCH) || mat.equals(B.mat("SOUL_TORCH")) || mat.getType().equals(Material.REDSTONE_WALL_TORCH) || mat.getType().equals(Material.WALL_TORCH) || mat.equals(B.mat("SOUL_WALL_TORCH")) || mat.equals(B.mat("LANTERN")) || mat.getType().equals(Material.JACK_O_LANTERN) || mat.getType().equals(Material.REDSTONE_LAMP) || mat.getType().equals(Material.MAGMA_BLOCK) || mat.equals(B.mat("SHROOMLIGHT")) || mat.equals(B.mat("SEA_LANTERN")) || mat.equals(B.mat("SOUL_LANTERN")) || mat.getType().equals(Material.FIRE) || mat.equals(B.mat("SOUL_FIRE")) || mat.equals(B.mat("SEA_PICKLE")) || mat.getType().equals(Material.BREWING_STAND) || mat.getType().equals(Material.REDSTONE_ORE); + // @builder + boolean str = mat.matEquals(B.mat("GLOWSTONE")) + || mat.matEquals(B.mat("END_ROD")) + || mat.matEquals(B.mat("SOUL_SAND")) + || mat.matEquals(B.mat("TORCH")) + || mat.getType().equals(Material.REDSTONE_TORCH) + || mat.matEquals(B.mat("SOUL_TORCH")) + || mat.getType().equals(Material.REDSTONE_WALL_TORCH) + || mat.getType().equals(Material.WALL_TORCH) + || mat.matEquals(B.mat("SOUL_WALL_TORCH")) + || mat.matEquals(B.mat("LANTERN")) + || mat.getType().equals(Material.JACK_O_LANTERN) + || mat.getType().equals(Material.REDSTONE_LAMP) + || mat.getType().equals(Material.MAGMA_BLOCK) + || mat.matEquals(B.mat("SHROOMLIGHT")) + || mat.matEquals(B.mat("SEA_LANTERN")) + || mat.matEquals(B.mat("SOUL_LANTERN")) + || mat.getType().equals(Material.FIRE) + || mat.matEquals(B.mat("SOUL_FIRE")) + || mat.matEquals(B.mat("SEA_PICKLE")) + || mat.getType().equals(Material.BREWING_STAND) + || mat.getType().equals(Material.REDSTONE_ORE); //@done if(str) { @@ -431,8 +493,36 @@ public class B } FastBlockData mat = d; - // @NoArgsConstructor - return mat.getType().equals(Material.POPPY) || mat.getType().equals(Material.DANDELION) || mat.equals(B.mat("CORNFLOWER")) || mat.equals(B.mat("SWEET_BERRY_BUSH")) || mat.equals(B.mat("CRIMSON_ROOTS")) || mat.equals(B.mat("WARPED_ROOTS")) || mat.equals(B.mat("NETHER_SPROUTS")) || mat.equals(B.mat("ALLIUM")) || mat.equals(B.mat("AZURE_BLUET")) || mat.equals(B.mat("BLUE_ORCHID")) || mat.equals(B.mat("POPPY")) || mat.equals(B.mat("DANDELION")) || mat.equals(B.mat("OXEYE_DAISY")) || mat.equals(B.mat("LILY_OF_THE_VALLEY")) || mat.equals(B.mat("WITHER_ROSE")) || mat.getType().equals(Material.DARK_OAK_SAPLING) || mat.getType().equals(Material.ACACIA_SAPLING) || mat.getType().equals(Material.JUNGLE_SAPLING) || mat.getType().equals(Material.BIRCH_SAPLING) || mat.getType().equals(Material.SPRUCE_SAPLING) || mat.getType().equals(Material.OAK_SAPLING) || mat.getType().equals(Material.ORANGE_TULIP) || mat.getType().equals(Material.PINK_TULIP) || mat.getType().equals(Material.RED_TULIP) || mat.getType().equals(Material.WHITE_TULIP) || mat.getType().equals(Material.FERN) || mat.getType().equals(Material.LARGE_FERN) || mat.getType().equals(Material.GRASS) || mat.getType().equals(Material.TALL_GRASS); + // @builder + return mat.getType().equals(Material.POPPY) + || mat.getType().equals(Material.DANDELION) + || mat.matEquals(B.mat("CORNFLOWER")) + || mat.matEquals(B.mat("SWEET_BERRY_BUSH")) + || mat.matEquals(B.mat("CRIMSON_ROOTS")) + || mat.matEquals(B.mat("WARPED_ROOTS")) + || mat.matEquals(B.mat("NETHER_SPROUTS")) + || mat.matEquals(B.mat("ALLIUM")) + || mat.matEquals(B.mat("AZURE_BLUET")) + || mat.matEquals(B.mat("BLUE_ORCHID")) + || mat.matEquals(B.mat("POPPY")) + || mat.matEquals(B.mat("DANDELION")) + || mat.matEquals(B.mat("OXEYE_DAISY")) + || mat.matEquals(B.mat("LILY_OF_THE_VALLEY")) + || mat.matEquals(B.mat("WITHER_ROSE")) + || mat.getType().equals(Material.DARK_OAK_SAPLING) + || mat.getType().equals(Material.ACACIA_SAPLING) + || mat.getType().equals(Material.JUNGLE_SAPLING) + || mat.getType().equals(Material.BIRCH_SAPLING) + || mat.getType().equals(Material.SPRUCE_SAPLING) + || mat.getType().equals(Material.OAK_SAPLING) + || mat.getType().equals(Material.ORANGE_TULIP) + || mat.getType().equals(Material.PINK_TULIP) + || mat.getType().equals(Material.RED_TULIP) + || mat.getType().equals(Material.WHITE_TULIP) + || mat.getType().equals(Material.FERN) + || mat.getType().equals(Material.LARGE_FERN) + || mat.getType().equals(Material.GRASS) + || mat.getType().equals(Material.TALL_GRASS); //@done } diff --git a/src/main/java/com/volmit/iris/util/FastBlockData.java b/src/main/java/com/volmit/iris/util/FastBlockData.java index 6abf1c759..9059ab8f6 100644 --- a/src/main/java/com/volmit/iris/util/FastBlockData.java +++ b/src/main/java/com/volmit/iris/util/FastBlockData.java @@ -100,6 +100,11 @@ public class FastBlockData return getType().hashCode(); } + public boolean matEquals(FastBlockData obj) + { + return getMaterial().equals(obj.getMaterial()); + } + @Override public boolean equals(Object obj) { diff --git a/src/main/java/com/volmit/iris/util/MortarCommand.java b/src/main/java/com/volmit/iris/util/MortarCommand.java index 6abbf875b..7d96d4aa0 100644 --- a/src/main/java/com/volmit/iris/util/MortarCommand.java +++ b/src/main/java/com/volmit/iris/util/MortarCommand.java @@ -19,7 +19,7 @@ public abstract class MortarCommand implements ICommand private String description; /** - * Override this with a super constructor as most commands shouldnt change these + * Override this with a super constructor as most commands shouldn't change these * parameters * * @param node diff --git a/src/main/java/com/volmit/iris/util/PregenJob.java b/src/main/java/com/volmit/iris/util/PregenJob.java index 5a4cfc9bf..22019ac87 100644 --- a/src/main/java/com/volmit/iris/util/PregenJob.java +++ b/src/main/java/com/volmit/iris/util/PregenJob.java @@ -13,15 +13,14 @@ import org.bukkit.event.world.ChunkUnloadEvent; import com.volmit.iris.Iris; import com.volmit.iris.gen.IrisTerrainProvider; -import com.volmit.iris.gen.provisions.ProvisionBukkit; +import com.volmit.iris.gen.scaffold.IrisWorlds; import com.volmit.iris.gui.PregenGui; import io.papermc.lib.PaperLib; -import lombok.Getter; +import org.bukkit.scheduler.BukkitTask; public class PregenJob implements Listener { - @Getter private World world; private int size; private int total; @@ -53,6 +52,8 @@ public class PregenJob implements Listener private long nogen = M.ms(); private KList requeueMCA = new KList(); private RollingSequence acps = new RollingSequence(PaperLib.isPaper() ? 8 : 32); + private BukkitTask pausedTask; + private boolean isPaused = false; int xc = 0; public PregenJob(World world, int size, MortarSender sender, Runnable onDone) @@ -77,7 +78,7 @@ public class PregenJob implements Listener this.chunkZ = 0; completed = false; first = true; - tp = (world.getGenerator() instanceof ProvisionBukkit) ? (IrisTerrainProvider) ((ProvisionBukkit) world.getGenerator()).getProvider() : null; + tp = IrisWorlds.getProvider(world); chunkSpiraler = new Spiraler(cubeSize, cubeSize, (x, z) -> { @@ -126,6 +127,40 @@ public class PregenJob implements Listener task = -1; } + // TODO: Cannot get paused value from this. Have to check bukkit tasks, not sure how. + // TODO: Trying to add functionality here to allow for pausing an continuing. + public static boolean isPaused(){ + return false; + //return this.isPaused; + } + + public static void pause() + { + try + { + // Save the task, tell bukkit to cancel it + stop(); + } + catch(Throwable e) + { + + } + task = -1; + } + + public static void resume() + { + try + { + // Load task and tell bukkit to continue it + } + catch(Throwable e) + { + + } + task = -1; + } + public void onTick() { if(completed) @@ -375,9 +410,17 @@ public class PregenJob implements Listener @EventHandler public void on(ChunkUnloadEvent e) { - if(e.getWorld().equals(world) && isChunkWithin(e.getChunk().getX(), e.getChunk().getZ()) && consumer != null) + try { - consumer.accept(new ChunkPosition(e.getChunk().getX(), e.getChunk().getZ()), tp != null ? tp.render(e.getChunk().getX() * 16, e.getChunk().getZ() * 16) : Color.blue.darker()); + if(e.getWorld().equals(world) && isChunkWithin(e.getChunk().getX(), e.getChunk().getZ()) && consumer != null) + { + consumer.accept(new ChunkPosition(e.getChunk().getX(), e.getChunk().getZ()), tp != null ? tp.render(e.getChunk().getX() * 16, e.getChunk().getZ() * 16) : Color.blue.darker()); + } + } + + catch(Throwable ex) + { + } } @@ -419,10 +462,4 @@ public class PregenJob implements Listener return new String[] {"Progress: " + Form.pc(Math.min((double) genned / (double) total, 1.0), 0), "Generated: " + Form.f(genned) + " Chunks", "Remaining: " + Form.f(total - genned) + " Chunks", "Elapsed: " + Form.duration((long) s.getMilliseconds(), 2), "Estimate: " + ((genned >= total - 5 ? "Any second..." : s.getMilliseconds() < 25000 ? "Calculating..." : Form.duration(eta, 2))), "ChunksMS: " + Form.duration(1000D / cps, 2), "Chunks/s: " + Form.f(cps, 1), }; } - - public void progressMCA(Color color, int x, int z, double pct) - { - // TODO Auto-generated method stub - - } -} +} \ No newline at end of file