mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-02 16:07:06 +00:00
commit
1c5774fca5
@ -24,7 +24,7 @@ plugins {
|
||||
id "de.undercouch.download" version "5.0.1"
|
||||
}
|
||||
|
||||
version '2.0.6-1.18.2' // Needs to be version specific
|
||||
version '2.0.7-1.18.2' // Needs to be version specific
|
||||
def nmsVersion = "1.18.2"
|
||||
def apiVersion = '1.18'
|
||||
def spigotJarVersion = '1.18.2-R0.1-SNAPSHOT'
|
||||
@ -40,7 +40,7 @@ registerCustomOutputTask('Coco', 'D://Documents/MC/plugins')
|
||||
registerCustomOutputTask('Strange', 'D://Servers/1.17 Test Server/plugins')
|
||||
registerCustomOutputTask('Vatuu', 'D://Minecraft/Servers/1.18.2/plugins')
|
||||
// ========================== UNIX ==============================
|
||||
registerCustomOutputTaskUnix('CyberpwnLT', '/Users/danielmills/Documents/development/server/plugins')
|
||||
registerCustomOutputTaskUnix('CyberpwnLT', '/Users/danielmills/development/server/plugins')
|
||||
registerCustomOutputTaskUnix('PsychoLT', '/Users/brianfopiano/Desktop/REMOTES/RemoteMinecraft/plugins')
|
||||
// ==============================================================
|
||||
|
||||
|
@ -32,21 +32,22 @@ import com.volmit.iris.engine.EnginePanic;
|
||||
import com.volmit.iris.engine.object.IrisBiome;
|
||||
import com.volmit.iris.engine.object.IrisCompat;
|
||||
import com.volmit.iris.engine.object.IrisDimension;
|
||||
import com.volmit.iris.engine.object.IrisObject;
|
||||
import com.volmit.iris.engine.object.IrisWorld;
|
||||
import com.volmit.iris.engine.platform.BukkitChunkGenerator;
|
||||
import com.volmit.iris.engine.platform.DummyChunkGenerator;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
import com.volmit.iris.util.data.B;
|
||||
import com.volmit.iris.util.exceptions.IrisException;
|
||||
import com.volmit.iris.util.format.C;
|
||||
import com.volmit.iris.util.format.Form;
|
||||
import com.volmit.iris.util.function.NastyRunnable;
|
||||
import com.volmit.iris.util.io.FileWatcher;
|
||||
import com.volmit.iris.util.io.IO;
|
||||
import com.volmit.iris.util.io.InstanceState;
|
||||
import com.volmit.iris.util.io.JarScanner;
|
||||
import com.volmit.iris.util.io.*;
|
||||
import com.volmit.iris.util.math.M;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import com.volmit.iris.util.matter.IrisMatter;
|
||||
import com.volmit.iris.util.matter.Matter;
|
||||
import com.volmit.iris.util.parallel.MultiBurst;
|
||||
import com.volmit.iris.util.plugin.IrisService;
|
||||
import com.volmit.iris.util.plugin.Metrics;
|
||||
@ -62,13 +63,16 @@ import net.kyori.adventure.text.serializer.ComponentSerializer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.WorldCreator;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
@ -190,7 +194,6 @@ public class Iris extends VolmitPlugin implements Listener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static File getCached(String name, String url) {
|
||||
String h = IO.hash(name + "@" + url);
|
||||
File f = Iris.instance.getDataFile("cache", h.substring(0, 2), h.substring(3, 5), h);
|
||||
|
@ -32,7 +32,7 @@ import java.io.IOException;
|
||||
@SuppressWarnings("SynchronizeOnNonFinalField")
|
||||
@Data
|
||||
public class IrisSettings {
|
||||
public static transient IrisSettings settings;
|
||||
public static IrisSettings settings;
|
||||
private IrisSettingsGeneral general = new IrisSettingsGeneral();
|
||||
private IrisSettingsWorld world = new IrisSettingsWorld();
|
||||
private IrisSettingsGUI gui = new IrisSettingsGUI();
|
||||
|
@ -68,6 +68,10 @@ public class JigsawEditor implements Listener {
|
||||
}
|
||||
|
||||
editors.put(player, this);
|
||||
if(object == null)
|
||||
{
|
||||
throw new RuntimeException("Object is null! " + piece.getObject());
|
||||
}
|
||||
this.object = object;
|
||||
this.player = player;
|
||||
origin = player.getLocation().clone().add(0, 7, 0);
|
||||
@ -77,7 +81,7 @@ public class JigsawEditor implements Listener {
|
||||
this.piece.setObject(object.getLoadKey());
|
||||
cuboid = new Cuboid(origin.clone(), origin.clone().add(object.getW() - 1, object.getH() - 1, object.getD() - 1));
|
||||
ticker = J.sr(this::onTick, 0);
|
||||
object.placeCenterY(origin);
|
||||
J.s(() -> object.placeCenterY(origin));
|
||||
Iris.instance.registerListener(this);
|
||||
}
|
||||
|
||||
|
@ -31,26 +31,9 @@ import com.google.gson.stream.JsonWriter;
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.engine.data.cache.AtomicCache;
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
import com.volmit.iris.engine.object.IrisBiome;
|
||||
import com.volmit.iris.engine.object.IrisBlockData;
|
||||
import com.volmit.iris.engine.object.IrisCave;
|
||||
import com.volmit.iris.engine.object.IrisDimension;
|
||||
import com.volmit.iris.engine.object.IrisEntity;
|
||||
import com.volmit.iris.engine.object.IrisExpression;
|
||||
import com.volmit.iris.engine.object.IrisGenerator;
|
||||
import com.volmit.iris.engine.object.IrisImage;
|
||||
import com.volmit.iris.engine.object.IrisJigsawPiece;
|
||||
import com.volmit.iris.engine.object.IrisJigsawPool;
|
||||
import com.volmit.iris.engine.object.IrisJigsawStructure;
|
||||
import com.volmit.iris.engine.object.IrisLootTable;
|
||||
import com.volmit.iris.engine.object.IrisMarker;
|
||||
import com.volmit.iris.engine.object.IrisMod;
|
||||
import com.volmit.iris.engine.object.IrisObject;
|
||||
import com.volmit.iris.engine.object.IrisRavine;
|
||||
import com.volmit.iris.engine.object.IrisRegion;
|
||||
import com.volmit.iris.engine.object.IrisScript;
|
||||
import com.volmit.iris.engine.object.IrisSpawner;
|
||||
import com.volmit.iris.engine.object.*;
|
||||
import com.volmit.iris.engine.object.annotations.Snippet;
|
||||
import com.volmit.iris.engine.object.matter.IrisMatterObject;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
import com.volmit.iris.util.context.IrisContext;
|
||||
@ -87,6 +70,7 @@ public class IrisData implements ExclusionStrategy, TypeAdapterFactory {
|
||||
private ResourceLoader<IrisBlockData> blockLoader;
|
||||
private ResourceLoader<IrisExpression> expressionLoader;
|
||||
private ResourceLoader<IrisObject> objectLoader;
|
||||
private ResourceLoader<IrisMatterObject> matterLoader;
|
||||
private ResourceLoader<IrisImage> imageLoader;
|
||||
private ResourceLoader<IrisScript> scriptLoader;
|
||||
private ResourceLoader<IrisCave> caveLoader;
|
||||
@ -131,6 +115,9 @@ public class IrisData implements ExclusionStrategy, TypeAdapterFactory {
|
||||
public static IrisObject loadAnyObject(String key) {
|
||||
return loadAny(key, (dm) -> dm.getObjectLoader().load(key, false));
|
||||
}
|
||||
public static IrisMatterObject loadAnyMatter(String key) {
|
||||
return loadAny(key, (dm) -> dm.getMatterLoader().load(key, false));
|
||||
}
|
||||
|
||||
public static IrisBiome loadAnyBiome(String key) {
|
||||
return loadAny(key, (dm) -> dm.getBiomeLoader().load(key, false));
|
||||
@ -295,9 +282,12 @@ public class IrisData implements ExclusionStrategy, TypeAdapterFactory {
|
||||
if(registrant.equals(IrisObject.class)) {
|
||||
r = (ResourceLoader<T>) new ObjectResourceLoader(dataFolder, this, rr.getFolderName(),
|
||||
rr.getTypeName());
|
||||
} else if(registrant.equals(IrisMatterObject.class)) {
|
||||
r = (ResourceLoader<T>) new MatterObjectResourceLoader(dataFolder, this, rr.getFolderName(),
|
||||
rr.getTypeName());
|
||||
} else if(registrant.equals(IrisScript.class)) {
|
||||
r = (ResourceLoader<T>) new ScriptResourceLoader(dataFolder, this, rr.getFolderName(),
|
||||
rr.getTypeName());
|
||||
rr.getTypeName());
|
||||
} else if(registrant.equals(IrisImage.class)) {
|
||||
r = (ResourceLoader<T>) new ImageResourceLoader(dataFolder, this, rr.getFolderName(),
|
||||
rr.getTypeName());
|
||||
|
@ -0,0 +1,146 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.volmit.iris.core.loader;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.IrisSettings;
|
||||
import com.volmit.iris.engine.object.matter.IrisMatterObject;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.collection.KSet;
|
||||
import com.volmit.iris.util.data.KCache;
|
||||
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class MatterObjectResourceLoader extends ResourceLoader<IrisMatterObject> {
|
||||
public MatterObjectResourceLoader(File root, IrisData idm, String folderName, String resourceTypeName) {
|
||||
super(root, idm, folderName, resourceTypeName, IrisMatterObject.class);
|
||||
loadCache = new KCache<>(this::loadRaw, IrisSettings.get().getPerformance().getObjectLoaderCacheSize());
|
||||
}
|
||||
|
||||
public boolean supportsSchemas() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public long getSize() {
|
||||
return loadCache.getSize();
|
||||
}
|
||||
|
||||
public long getTotalStorage() {
|
||||
return getSize();
|
||||
}
|
||||
|
||||
protected IrisMatterObject loadFile(File j, String name) {
|
||||
try {
|
||||
PrecisionStopwatch p = PrecisionStopwatch.start();
|
||||
IrisMatterObject t = IrisMatterObject.from(j);
|
||||
t.setLoadKey(name);
|
||||
t.setLoader(manager);
|
||||
t.setLoadFile(j);
|
||||
logLoad(j, t);
|
||||
tlt.addAndGet(p.getMilliseconds());
|
||||
return t;
|
||||
} catch(Throwable e) {
|
||||
Iris.reportError(e);
|
||||
Iris.warn("Couldn't read " + resourceTypeName + " file: " + j.getPath() + ": " + e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public String[] getPossibleKeys() {
|
||||
if(possibleKeys != null) {
|
||||
return possibleKeys;
|
||||
}
|
||||
|
||||
Iris.debug("Building " + resourceTypeName + " Possibility Lists");
|
||||
KSet<String> m = new KSet<>();
|
||||
|
||||
for(File i : getFolders()) {
|
||||
for(File j : i.listFiles()) {
|
||||
if(j.isFile() && j.getName().endsWith(".mat")) {
|
||||
m.add(j.getName().replaceAll("\\Q.mat\\E", ""));
|
||||
} else if(j.isDirectory()) {
|
||||
for(File k : j.listFiles()) {
|
||||
if(k.isFile() && k.getName().endsWith(".mat")) {
|
||||
m.add(j.getName() + "/" + k.getName().replaceAll("\\Q.mat\\E", ""));
|
||||
} else if(k.isDirectory()) {
|
||||
for(File l : k.listFiles()) {
|
||||
if(l.isFile() && l.getName().endsWith(".mat")) {
|
||||
m.add(j.getName() + "/" + k.getName() + "/" + l.getName().replaceAll("\\Q.mat\\E", ""));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
KList<String> v = new KList<>(m);
|
||||
possibleKeys = v.toArray(new String[0]);
|
||||
return possibleKeys;
|
||||
}
|
||||
|
||||
public File findFile(String name) {
|
||||
for(File i : getFolders(name)) {
|
||||
for(File j : i.listFiles()) {
|
||||
if(j.isFile() && j.getName().endsWith(".mat") && j.getName().split("\\Q.\\E")[0].equals(name)) {
|
||||
return j;
|
||||
}
|
||||
}
|
||||
|
||||
File file = new File(i, name + ".mat");
|
||||
|
||||
if(file.exists()) {
|
||||
return file;
|
||||
}
|
||||
}
|
||||
|
||||
Iris.warn("Couldn't find " + resourceTypeName + ": " + name);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public IrisMatterObject load(String name) {
|
||||
return load(name, true);
|
||||
}
|
||||
|
||||
private IrisMatterObject loadRaw(String name) {
|
||||
for(File i : getFolders(name)) {
|
||||
for(File j : i.listFiles()) {
|
||||
if(j.isFile() && j.getName().endsWith(".mat") && j.getName().split("\\Q.\\E")[0].equals(name)) {
|
||||
return loadFile(j, name);
|
||||
}
|
||||
}
|
||||
|
||||
File file = new File(i, name + ".mat");
|
||||
|
||||
if(file.exists()) {
|
||||
return loadFile(file, name);
|
||||
}
|
||||
}
|
||||
|
||||
Iris.warn("Couldn't find " + resourceTypeName + ": " + name);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public IrisMatterObject load(String name, boolean warn) {
|
||||
return loadCache.get(name);
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package com.volmit.iris.core.tools;
|
||||
|
||||
import com.volmit.iris.util.data.B;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
|
||||
/**
|
||||
* This class is used by an external IrisLib for other plugins to interact with Iris. Do not change
|
||||
* existing methods or their parameters as it will break the library that uses these methods
|
||||
* feel free to add more methods so long as you also add the reflective methods to the library
|
||||
*/
|
||||
public class IrisReflectiveAPI {
|
||||
public static boolean isIrisWorld(World world) {
|
||||
return IrisToolbelt.isIrisWorld(world);
|
||||
}
|
||||
|
||||
public static boolean isIrisStudioWorld(World world) {
|
||||
return IrisToolbelt.isIrisStudioWorld(world);
|
||||
}
|
||||
|
||||
public static void registerCustomBlockData(String namespace, String key, BlockData blockData) {
|
||||
B.registerCustomBlockData(namespace, key, blockData);
|
||||
}
|
||||
|
||||
public static void retainMantleData(String classname) {
|
||||
IrisToolbelt.retainMantleDataForSlice(classname);
|
||||
}
|
||||
|
||||
public static void setMantleData(World world, int x, int y, int z, Object data) {
|
||||
IrisToolbelt.access(world).getEngine().getMantle().getMantle().set(x, y, z, data);
|
||||
}
|
||||
|
||||
public static void deleteMantleData(World world, int x, int y, int z, Class c) {
|
||||
IrisToolbelt.access(world).getEngine().getMantle().getMantle().remove(x, y, z, c);
|
||||
}
|
||||
|
||||
public static Object getMantleData(World world, int x, int y, int z, Class c) {
|
||||
return IrisToolbelt.access(world).getEngine().getMantle().getMantle().get(x, y, z, c);
|
||||
}
|
||||
}
|
@ -235,45 +235,4 @@ public class IrisToolbelt {
|
||||
if(e == null) {return;}
|
||||
e.getEngine().getMantle().getMantle().remove(x, y - world.getMinHeight(), z, of);
|
||||
}
|
||||
|
||||
/////////////////// REFLECTIVE METHODS //////////////////////////
|
||||
// Copy this stuff to your project, it's safe to use with a
|
||||
// bukkit api only.
|
||||
/////////////////////////////////////////////////////////////////
|
||||
|
||||
public static void setup() throws Throwable {
|
||||
Method m = Class.forName("com.volmit.iris.core.tools.IrisToolbelt").getDeclaredMethod("retainMantleDataForSlice", String.class);
|
||||
m.invoke(null, String.class.getCanonicalName());
|
||||
m.invoke(null, BlockData.class.getCanonicalName());
|
||||
}
|
||||
|
||||
public static boolean hasMantleObject(World world, int x, int y, int z) {
|
||||
return getMantleIdentity(world, x, y, z) != -1;
|
||||
}
|
||||
|
||||
public static void deleteMantleBlock(World world, int x, int y, int z) {
|
||||
try {
|
||||
Method m = Class.forName("com.volmit.iris.core.tools.IrisToolbelt").getDeclaredMethod("deleteMantleData", World.class, int.class, int.class, int.class, Class.class);
|
||||
m.invoke(null, world, x, y, z, BlockData.class);
|
||||
m.invoke(null, world, x, y, z, String.class);
|
||||
} catch(Throwable ignored) {}
|
||||
}
|
||||
|
||||
public static BlockData getMantleBlock(World world, int x, int y, int z) {
|
||||
try {
|
||||
Method m = Class.forName("com.volmit.iris.core.tools.IrisToolbelt").getDeclaredMethod("getMantleData", World.class, int.class, int.class, int.class, Class.class);
|
||||
BlockData s = (BlockData) m.invoke(null, world, x, y, z, BlockData.class);
|
||||
if(s != null) {return s;}
|
||||
} catch(Throwable ignored) {}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static int getMantleIdentity(World world, int x, int y, int z) {
|
||||
try {
|
||||
Method m = Class.forName("com.volmit.iris.core.tools.IrisToolbelt").getDeclaredMethod("getMantleData", World.class, int.class, int.class, int.class, Class.class);
|
||||
String s = (String) m.invoke(null, world, x, y, z, String.class);
|
||||
if(s != null) {return Integer.parseInt(s.split("\\Q@\\E")[1]);}
|
||||
} catch(Throwable ignored) {}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ import com.volmit.iris.engine.object.annotations.MaxNumber;
|
||||
import com.volmit.iris.engine.object.annotations.MinNumber;
|
||||
import com.volmit.iris.engine.object.annotations.RegistryListResource;
|
||||
import com.volmit.iris.engine.object.annotations.Snippet;
|
||||
import com.volmit.iris.util.interpolation.IrisInterpolation;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import com.volmit.iris.util.noise.CNG;
|
||||
import com.volmit.iris.util.noise.ExpressionNoise;
|
||||
@ -50,7 +51,6 @@ public class IrisGeneratorStyle {
|
||||
|
||||
@Desc("Cell zooms")
|
||||
private double cellularZoom = 1;
|
||||
|
||||
@MinNumber(0.00001)
|
||||
@Desc("The zoom of this style")
|
||||
private double zoom = 1;
|
||||
|
@ -34,6 +34,8 @@ import com.volmit.iris.util.math.AxisAlignedBB;
|
||||
import com.volmit.iris.util.math.BlockPosition;
|
||||
import com.volmit.iris.util.math.Position2;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import com.volmit.iris.util.matter.IrisMatter;
|
||||
import com.volmit.iris.util.matter.Matter;
|
||||
import com.volmit.iris.util.matter.MatterMarker;
|
||||
import com.volmit.iris.util.parallel.BurstExecutor;
|
||||
import com.volmit.iris.util.parallel.MultiBurst;
|
||||
|
@ -0,0 +1,56 @@
|
||||
package com.volmit.iris.engine.object.matter;
|
||||
|
||||
import com.volmit.iris.core.loader.IrisRegistrant;
|
||||
import com.volmit.iris.engine.object.IrisObject;
|
||||
import com.volmit.iris.util.json.JSONObject;
|
||||
import com.volmit.iris.util.matter.IrisMatter;
|
||||
import com.volmit.iris.util.matter.Matter;
|
||||
import com.volmit.iris.util.plugin.VolmitSender;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
@Data
|
||||
public class IrisMatterObject extends IrisRegistrant {
|
||||
private final Matter matter;
|
||||
|
||||
public IrisMatterObject()
|
||||
{
|
||||
this(1,1,1);
|
||||
}
|
||||
|
||||
public IrisMatterObject(int w, int h, int d)
|
||||
{
|
||||
this(new IrisMatter(w,h,d));
|
||||
}
|
||||
|
||||
public IrisMatterObject(Matter matter)
|
||||
{
|
||||
this.matter = matter;
|
||||
}
|
||||
|
||||
public static IrisMatterObject from(IrisObject object)
|
||||
{
|
||||
return new IrisMatterObject(Matter.from(object));
|
||||
}
|
||||
|
||||
public static IrisMatterObject from(File j) throws IOException, ClassNotFoundException {
|
||||
return new IrisMatterObject(Matter.read(j));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFolderName() {
|
||||
return "matter";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeName() {
|
||||
return "Matter";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void scanForErrors(JSONObject p, VolmitSender sender) {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.volmit.iris.engine.object.matter;
|
||||
|
||||
import com.volmit.iris.core.loader.IrisData;
|
||||
import com.volmit.iris.engine.IrisEngine;
|
||||
import com.volmit.iris.engine.object.IRare;
|
||||
import com.volmit.iris.engine.object.IrisStyledRange;
|
||||
import com.volmit.iris.engine.object.annotations.*;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.mantle.Mantle;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import com.volmit.iris.util.matter.MatterSlice;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Snippet("matter-placer")
|
||||
@EqualsAndHashCode()
|
||||
@Accessors(chain = true)
|
||||
@NoArgsConstructor
|
||||
@Desc("Represents an iris object placer. It places matter objects.")
|
||||
@Data
|
||||
public class IrisMatterPlacement implements IRare {
|
||||
@RegistryListResource(IrisMatterObject.class)
|
||||
@Required
|
||||
@ArrayType(min = 1, type = String.class)
|
||||
@Desc("List of objects to place")
|
||||
private KList<String> place = new KList<>();
|
||||
|
||||
@MinNumber(0)
|
||||
@Desc("The rarity of this object placing")
|
||||
private int rarity = 0;
|
||||
|
||||
@MinNumber(0)
|
||||
@Desc("The styled density of this object")
|
||||
private IrisStyledRange densityRange;
|
||||
|
||||
@Desc("The absolute density for this object")
|
||||
private double density = 1;
|
||||
|
||||
@Desc("Translate this matter object before placement")
|
||||
private IrisMatterTranslate translate;
|
||||
|
||||
@Desc("Place this object on the surface height, bedrock or the sky, then use translate if need be.")
|
||||
private IrisMatterPlacementLocation location = IrisMatterPlacementLocation.SURFACE;
|
||||
|
||||
public void place(IrisEngine engine, IrisData data, RNG rng, int ax, int az)
|
||||
{
|
||||
IrisMatterObject object = data.getMatterLoader().load(place.getRandom(rng));
|
||||
int x = ax;
|
||||
int z = az;
|
||||
int yoff = 0;
|
||||
|
||||
if(translate != null)
|
||||
{
|
||||
x += translate.xOffset(data, rng, x, z);
|
||||
yoff += translate.yOffset(data, rng, x, z);
|
||||
z += translate.zOffset(data, rng, x, z);
|
||||
}
|
||||
|
||||
int y = yoff + location.at(engine, x, z);
|
||||
Mantle mantle = engine.getMantle().getMantle();
|
||||
|
||||
int xx = x;
|
||||
int yy = y;
|
||||
int zz = z;
|
||||
|
||||
for(MatterSlice<?> slice : object.getMatter().getSliceMap().values())
|
||||
{
|
||||
slice.iterate((mx, my, mz, v) -> {
|
||||
mantle.set(xx + mx, yy + my, zz + mz, v);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package com.volmit.iris.engine.object.matter;
|
||||
|
||||
import com.volmit.iris.engine.IrisEngine;
|
||||
import com.volmit.iris.util.function.Function3;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
public enum IrisMatterPlacementLocation {
|
||||
SURFACE((e, x, z) -> e.getHeight(x, z, true)),
|
||||
SURFACE_ON_FLUID((e, x, z) -> e.getHeight(x, z, false)),
|
||||
BEDROCK((e, x, z) -> 0),
|
||||
SKY((e, x, z) -> e.getHeight());
|
||||
|
||||
private final Function3<IrisEngine, Integer, Integer, Integer> computer;
|
||||
|
||||
private IrisMatterPlacementLocation(Function3<IrisEngine, Integer, Integer, Integer> computer)
|
||||
{
|
||||
this.computer = computer;
|
||||
}
|
||||
|
||||
public int at(IrisEngine engine, int x, int z) {
|
||||
return computer.apply(engine, x, z);
|
||||
}
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
package com.volmit.iris.engine.object.matter;
|
||||
|
||||
import com.volmit.iris.core.loader.IrisData;
|
||||
import com.volmit.iris.engine.IrisEngine;
|
||||
import com.volmit.iris.engine.object.IrisStyledRange;
|
||||
import com.volmit.iris.engine.object.annotations.Desc;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode()
|
||||
@Accessors(chain = true)
|
||||
@Desc("Represents a matter translator")
|
||||
public class IrisMatterTranslate {
|
||||
@Desc("For varied coordinate shifts use ranges not the literal coordinate")
|
||||
private IrisStyledRange rangeX = null;
|
||||
@Desc("For varied coordinate shifts use ranges not the literal coordinate")
|
||||
private IrisStyledRange rangeY = null;
|
||||
@Desc("For varied coordinate shifts use ranges not the literal coordinate")
|
||||
private IrisStyledRange rangeZ = null;
|
||||
@Desc("Define an absolute shift instead of varied.")
|
||||
private int x = 0;
|
||||
@Desc("Define an absolute shift instead of varied.")
|
||||
private int y = 0;
|
||||
@Desc("Define an absolute shift instead of varied.")
|
||||
private int z = 0;
|
||||
|
||||
public int xOffset(IrisData data, RNG rng, int rx, int rz)
|
||||
{
|
||||
if(rangeX != null)
|
||||
{
|
||||
return (int) Math.round(rangeX.get(rng, rx, rz, data));
|
||||
}
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
public int yOffset(IrisData data, RNG rng, int rx, int rz)
|
||||
{
|
||||
if(rangeY != null)
|
||||
{
|
||||
return (int) Math.round(rangeY.get(rng, rx, rz, data));
|
||||
}
|
||||
|
||||
return y;
|
||||
}
|
||||
|
||||
public int zOffset(IrisData data, RNG rng, int rx, int rz)
|
||||
{
|
||||
if(rangeZ != null)
|
||||
{
|
||||
return (int) Math.round(rangeZ.get(rng, rx, rz, data));
|
||||
}
|
||||
|
||||
return z;
|
||||
}
|
||||
}
|
@ -22,6 +22,7 @@ import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.IrisSettings;
|
||||
import com.volmit.iris.core.service.RegistrySVC;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
import com.volmit.iris.util.scheduling.ChronoLatch;
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
|
||||
@ -34,6 +35,7 @@ import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.Waterlogged;
|
||||
import org.bukkit.block.data.type.Leaves;
|
||||
import org.bukkit.block.data.type.PointedDripstone;
|
||||
import org.checkerframework.checker.units.qual.K;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
@ -44,6 +46,8 @@ import java.util.stream.Collectors;
|
||||
import static org.bukkit.Material.*;
|
||||
|
||||
public class B {
|
||||
private static final KMap<String, BlockData> custom = new KMap<>();
|
||||
|
||||
private static final Material AIR_MATERIAL = Material.AIR;
|
||||
private static final BlockData AIR = AIR_MATERIAL.createBlockData();
|
||||
private static final IntSet foliageCache = buildFoliageCache();
|
||||
@ -405,6 +409,11 @@ public class B {
|
||||
try {
|
||||
String bd = bdxf.trim();
|
||||
|
||||
if(!custom.isEmpty() && custom.containsKey(bd))
|
||||
{
|
||||
return custom.get(bd);
|
||||
}
|
||||
|
||||
if(bd.startsWith("minecraft:cauldron[level=")) {
|
||||
bd = bd.replaceAll("\\Q:cauldron[\\E", ":water_cauldron[");
|
||||
}
|
||||
@ -660,6 +669,8 @@ public class B {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
bt.addAll(custom.k());
|
||||
|
||||
try {
|
||||
bt.addAll(Iris.service(RegistrySVC.class).getCustomBlockRegistry().compile());
|
||||
} catch(Throwable e) {
|
||||
@ -683,4 +694,8 @@ public class B {
|
||||
public static boolean isWaterLogged(BlockData b) {
|
||||
return (b instanceof Waterlogged) && ((Waterlogged) b).isWaterlogged();
|
||||
}
|
||||
|
||||
public static void registerCustomBlockData(String namespace, String key, BlockData blockData) {
|
||||
custom.put(namespace + ":" + key, blockData);
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
package com.volmit.iris.util.hunk;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.engine.object.IrisPosition;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.function.Consumer2;
|
||||
@ -1254,6 +1255,12 @@ public interface Hunk<T> {
|
||||
* the value
|
||||
*/
|
||||
default void set(int x, int y, int z, T t) {
|
||||
if(!contains(x, y, z))
|
||||
{
|
||||
Iris.warn("OUT OF BOUNDS " + x + " " + y + " "+ z + " in bounds " + getWidth() + " " + getHeight() + " " + getDepth() );
|
||||
return;
|
||||
}
|
||||
|
||||
setRaw(x, y, z, t);
|
||||
}
|
||||
|
||||
@ -1561,4 +1568,9 @@ public interface Hunk<T> {
|
||||
default boolean contains(int x, int y, int z) {
|
||||
return x < getWidth() && x >= 0 && y < getHeight() && y >= 0 && z < getDepth() && z >= 0;
|
||||
}
|
||||
|
||||
default int volume()
|
||||
{
|
||||
return getWidth() * getDepth() * getHeight();
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
package com.volmit.iris.util.interpolation;
|
||||
|
||||
import com.google.common.util.concurrent.AtomicDouble;
|
||||
import com.volmit.iris.engine.data.chunk.LinkedTerrainChunk;
|
||||
import com.volmit.iris.engine.object.NoiseStyle;
|
||||
import com.volmit.iris.util.format.Form;
|
||||
import com.volmit.iris.util.function.Consumer2;
|
||||
@ -284,9 +285,24 @@ public class IrisInterpolation {
|
||||
//@done
|
||||
}
|
||||
|
||||
public static int getRadiusFactor(int coord, double radius)
|
||||
{
|
||||
if(radius == 2) {return coord >> 1;}
|
||||
if(radius == 4) {return coord >> 2;}
|
||||
if(radius == 8) {return coord >> 3;}
|
||||
if(radius == 16) {return coord >> 4;}
|
||||
if(radius == 32) {return coord >> 5;}
|
||||
if(radius == 64) {return coord >> 6;}
|
||||
if(radius == 128) {return coord >> 7;}
|
||||
if(radius == 256) {return coord >> 8;}
|
||||
if(radius == 512) {return coord >> 9;}
|
||||
if(radius == 1024) {return coord >> 10;}
|
||||
return (int) Math.floor(coord / radius);
|
||||
}
|
||||
|
||||
public static double getBilinearNoise(int x, int z, double rad, NoiseProvider n) {
|
||||
int fx = (int) Math.floor(x / rad);
|
||||
int fz = (int) Math.floor(z / rad);
|
||||
int fx = getRadiusFactor(x, rad);
|
||||
int fz = getRadiusFactor(z, rad);
|
||||
int x1 = (int) Math.round(fx * rad);
|
||||
int z1 = (int) Math.round(fz * rad);
|
||||
int x2 = (int) Math.round((fx + 1) * rad);
|
||||
@ -375,8 +391,8 @@ public class IrisInterpolation {
|
||||
}
|
||||
|
||||
public static double getBilinearBezierNoise(int x, int z, double rad, NoiseProvider n) {
|
||||
int fx = (int) Math.floor(x / rad);
|
||||
int fz = (int) Math.floor(z / rad);
|
||||
int fx = getRadiusFactor(x, rad);
|
||||
int fz = getRadiusFactor(z, rad);
|
||||
int x1 = (int) Math.round(fx * rad);
|
||||
int z1 = (int) Math.round(fz * rad);
|
||||
int x2 = (int) Math.round((fx + 1) * rad);
|
||||
@ -394,8 +410,8 @@ public class IrisInterpolation {
|
||||
}
|
||||
|
||||
public static double getBilinearParametricNoise(int x, int z, double rad, NoiseProvider n, double a) {
|
||||
int fx = (int) Math.floor(x / rad);
|
||||
int fz = (int) Math.floor(z / rad);
|
||||
int fx = getRadiusFactor(x, rad);
|
||||
int fz = getRadiusFactor(z, rad);
|
||||
int x1 = (int) Math.round(fx * rad);
|
||||
int z1 = (int) Math.round(fz * rad);
|
||||
int x2 = (int) Math.round((fx + 1) * rad);
|
||||
@ -417,9 +433,9 @@ public class IrisInterpolation {
|
||||
}
|
||||
|
||||
public static double getTrilinear(int x, int y, int z, double radx, double rady, double radz, NoiseProvider3 n) {
|
||||
int fx = (int) Math.floor(x / radx);
|
||||
int fy = (int) Math.floor(y / rady);
|
||||
int fz = (int) Math.floor(z / radz);
|
||||
int fx = getRadiusFactor(x, radx);
|
||||
int fy = getRadiusFactor(y, rady);
|
||||
int fz = getRadiusFactor(z, radz);
|
||||
int x1 = (int) Math.round(fx * radx);
|
||||
int y1 = (int) Math.round(fy * rady);
|
||||
int z1 = (int) Math.round(fz * radz);
|
||||
@ -448,9 +464,9 @@ public class IrisInterpolation {
|
||||
}
|
||||
|
||||
public static double getTricubic(int x, int y, int z, double radx, double rady, double radz, NoiseProvider3 n) {
|
||||
int fx = (int) Math.floor(x / radx);
|
||||
int fy = (int) Math.floor(y / rady);
|
||||
int fz = (int) Math.floor(z / radz);
|
||||
int fx = getRadiusFactor(x, radx);
|
||||
int fy = getRadiusFactor(y, rady);
|
||||
int fz = getRadiusFactor(z, radz);
|
||||
int x0 = (int) Math.round((fx - 1) * radx);
|
||||
int y0 = (int) Math.round((fy - 1) * rady);
|
||||
int z0 = (int) Math.round((fz - 1) * radz);
|
||||
@ -551,9 +567,9 @@ public class IrisInterpolation {
|
||||
}
|
||||
|
||||
public static double getTrihermite(int x, int y, int z, double radx, double rady, double radz, NoiseProvider3 n, double tension, double bias) {
|
||||
int fx = (int) Math.floor(x / radx);
|
||||
int fy = (int) Math.floor(y / rady);
|
||||
int fz = (int) Math.floor(z / radz);
|
||||
int fx = getRadiusFactor(x, radx);
|
||||
int fy = getRadiusFactor(y, rady);
|
||||
int fz = getRadiusFactor(z, radz);
|
||||
int x0 = (int) Math.round((fx - 1) * radx);
|
||||
int y0 = (int) Math.round((fy - 1) * rady);
|
||||
int z0 = (int) Math.round((fz - 1) * radz);
|
||||
@ -642,8 +658,8 @@ public class IrisInterpolation {
|
||||
}
|
||||
|
||||
public static double getBilinearCenterSineNoise(int x, int z, double rad, NoiseProvider n) {
|
||||
int fx = (int) Math.floor(x / rad);
|
||||
int fz = (int) Math.floor(z / rad);
|
||||
int fx = getRadiusFactor(x, rad);
|
||||
int fz = getRadiusFactor(z, rad);
|
||||
int x1 = (int) Math.round(fx * rad);
|
||||
int z1 = (int) Math.round(fz * rad);
|
||||
int x2 = (int) Math.round((fx + 1) * rad);
|
||||
@ -661,8 +677,8 @@ public class IrisInterpolation {
|
||||
}
|
||||
|
||||
public static double getBicubicNoise(int x, int z, double rad, NoiseProvider n) {
|
||||
int fx = (int) Math.floor(x / rad);
|
||||
int fz = (int) Math.floor(z / rad);
|
||||
int fx = getRadiusFactor(x, rad);
|
||||
int fz = getRadiusFactor(z, rad);
|
||||
int x0 = (int) Math.round((fx - 1) * rad);
|
||||
int z0 = (int) Math.round((fz - 1) * rad);
|
||||
int x1 = (int) Math.round(fx * rad);
|
||||
@ -696,8 +712,8 @@ public class IrisInterpolation {
|
||||
}
|
||||
|
||||
public static double getBicubicBezierNoise(int x, int z, double rad, NoiseProvider n) {
|
||||
int fx = (int) Math.floor(x / rad);
|
||||
int fz = (int) Math.floor(z / rad);
|
||||
int fx = getRadiusFactor(x, rad);
|
||||
int fz = getRadiusFactor(z, rad);
|
||||
int x0 = (int) Math.round((fx - 1) * rad);
|
||||
int z0 = (int) Math.round((fz - 1) * rad);
|
||||
int x1 = (int) Math.round(fx * rad);
|
||||
@ -731,8 +747,8 @@ public class IrisInterpolation {
|
||||
}
|
||||
|
||||
public static double getBicubicParametricNoise(int x, int z, double rad, NoiseProvider n, double a) {
|
||||
int fx = (int) Math.floor(x / rad);
|
||||
int fz = (int) Math.floor(z / rad);
|
||||
int fx = getRadiusFactor(x, rad);
|
||||
int fz = getRadiusFactor(z, rad);
|
||||
int x0 = (int) Math.round((fx - 1) * rad);
|
||||
int z0 = (int) Math.round((fz - 1) * rad);
|
||||
int x1 = (int) Math.round(fx * rad);
|
||||
@ -778,8 +794,8 @@ public class IrisInterpolation {
|
||||
}
|
||||
|
||||
public static double getHermiteNoise(int x, int z, double rad, NoiseProvider n, double t, double b) {
|
||||
int fx = (int) Math.floor(x / rad);
|
||||
int fz = (int) Math.floor(z / rad);
|
||||
int fx = getRadiusFactor(x, rad);
|
||||
int fz = getRadiusFactor(z, rad);
|
||||
int x0 = (int) Math.round((fx - 1) * rad);
|
||||
int z0 = (int) Math.round((fz - 1) * rad);
|
||||
int x1 = (int) Math.round(fx * rad);
|
||||
@ -813,8 +829,8 @@ public class IrisInterpolation {
|
||||
}
|
||||
|
||||
public static double getHermiteBezierNoise(int x, int z, double rad, NoiseProvider n, double t, double b) {
|
||||
int fx = (int) Math.floor(x / rad);
|
||||
int fz = (int) Math.floor(z / rad);
|
||||
int fx = getRadiusFactor(x, rad);
|
||||
int fz = getRadiusFactor(z, rad);
|
||||
int x0 = (int) Math.round((fx - 1) * rad);
|
||||
int z0 = (int) Math.round((fz - 1) * rad);
|
||||
int x1 = (int) Math.round(fx * rad);
|
||||
@ -848,8 +864,8 @@ public class IrisInterpolation {
|
||||
}
|
||||
|
||||
public static double getHermiteParametricNoise(int x, int z, double rad, NoiseProvider n, double t, double b, double a) {
|
||||
int fx = (int) Math.floor(x / rad);
|
||||
int fz = (int) Math.floor(z / rad);
|
||||
int fx = getRadiusFactor(x, rad);
|
||||
int fz = getRadiusFactor(z, rad);
|
||||
int x0 = (int) Math.round((fx - 1) * rad);
|
||||
int z0 = (int) Math.round((fz - 1) * rad);
|
||||
int x1 = (int) Math.round(fx * rad);
|
||||
@ -1027,7 +1043,6 @@ public class IrisInterpolation {
|
||||
|
||||
return n.noise(x, z);
|
||||
}
|
||||
|
||||
public static double rangeScale(double amin, double amax, double bmin, double bmax, double b) {
|
||||
return amin + ((amax - amin) * ((b - bmin) / (bmax - bmin)));
|
||||
}
|
||||
|
@ -379,6 +379,14 @@ public class Mantle {
|
||||
return closed.get();
|
||||
}
|
||||
|
||||
public void set(int x, int y, int z, Matter matter)
|
||||
{
|
||||
for(MatterSlice<?> i : matter.getSliceMap().values())
|
||||
{
|
||||
i.iterate((mx, my, mz, v) -> set(mx + x, my + y, mz + z, v));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the Mantle. By closing the mantle, you can no longer read or writeNodeData
|
||||
* any data to the mantle or it's Tectonic Plates. Closing will also flush any
|
||||
|
@ -24,6 +24,7 @@ import com.volmit.iris.engine.object.IrisPosition;
|
||||
import com.volmit.iris.util.collection.KSet;
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
import com.volmit.iris.util.math.BlockPosition;
|
||||
import com.volmit.iris.util.scheduling.J;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.entity.Entity;
|
||||
@ -59,11 +60,42 @@ import java.util.function.Function;
|
||||
public interface Matter {
|
||||
int VERSION = 1;
|
||||
|
||||
static long convert(File folder)
|
||||
{
|
||||
if(folder.isDirectory())
|
||||
{
|
||||
long v = 0;
|
||||
|
||||
for(File i : folder.listFiles())
|
||||
{
|
||||
v += convert(i);
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
IrisObject object = new IrisObject(1,1,1);
|
||||
try {
|
||||
long fs = folder.length();
|
||||
object.read(folder);
|
||||
Matter.from(object).write(folder);
|
||||
Iris.info("Converted " + folder.getPath() + " Saved " + (fs - folder.length()));
|
||||
} catch(Throwable e) {
|
||||
Iris.error("Failed to convert " + folder.getPath());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static Matter from(IrisObject object) {
|
||||
object.clean();
|
||||
object.shrinkwrap();
|
||||
BlockVector min = new BlockVector();
|
||||
Matter m = new IrisMatter(object.getW(), object.getH(), object.getD());
|
||||
Matter m = new IrisMatter(Math.max(object.getW(), 1)+1, Math.max( object.getH(), 1)+1, Math.max( object.getD(), 1)+1);
|
||||
|
||||
for(BlockVector i : object.getBlocks().keySet()) {
|
||||
min.setX(Math.min(min.getX(), i.getX()));
|
||||
|
@ -19,6 +19,7 @@
|
||||
package com.volmit.iris.util.noise;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.engine.data.cache.AtomicCache;
|
||||
import com.volmit.iris.engine.object.IRare;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.function.NoiseInjector;
|
||||
@ -129,6 +130,17 @@ public class CNG {
|
||||
}, 1D, 1);
|
||||
}
|
||||
|
||||
public CNG cached(int size)
|
||||
{
|
||||
if(size <= 0)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
generator = new CachedNoise(generator, size);
|
||||
return this;
|
||||
}
|
||||
|
||||
public static CNG signature(RNG rng) {
|
||||
return signature(rng, NoiseType.SIMPLEX);
|
||||
}
|
||||
|
@ -16,21 +16,29 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.volmit.iris.engine.object;
|
||||
package com.volmit.iris.util.noise;
|
||||
|
||||
import com.volmit.iris.engine.object.annotations.Desc;
|
||||
import com.volmit.iris.engine.object.annotations.Snippet;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
|
||||
@Snippet("matter-placer")
|
||||
@EqualsAndHashCode()
|
||||
@Accessors(chain = true)
|
||||
@NoArgsConstructor
|
||||
@Desc("Represents an iris object placer. It places objects.")
|
||||
@Data
|
||||
public class IrisMatterPlacement {
|
||||
public class CachedNoise implements NoiseGenerator {
|
||||
private final CachedNoiseMap n;
|
||||
|
||||
public CachedNoise(NoiseGenerator generator, int size) {
|
||||
n = new CachedNoiseMap(size, generator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x) {
|
||||
return n.get((int)Math.round(x), 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double z) {
|
||||
return n.get((int)Math.round(x),(int)Math.round(z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double y, double z) {
|
||||
return n.get((int)Math.round(x),(int)Math.round(z));
|
||||
}
|
||||
}
|
85
src/main/java/com/volmit/iris/util/noise/CachedNoiseMap.java
Normal file
85
src/main/java/com/volmit/iris/util/noise/CachedNoiseMap.java
Normal file
@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.volmit.iris.util.noise;
|
||||
|
||||
import com.volmit.iris.util.hunk.bits.Writable;
|
||||
import com.volmit.iris.util.interpolation.InterpolationMethod;
|
||||
import com.volmit.iris.util.matter.IrisMatter;
|
||||
import com.volmit.iris.util.matter.Matter;
|
||||
import com.volmit.iris.util.matter.MatterSlice;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class CachedNoiseMap implements Writable<Integer> {
|
||||
private final Matter noise;
|
||||
private final MatterSlice<Integer> slice;
|
||||
|
||||
public CachedNoiseMap(int size, NoiseGenerator cng)
|
||||
{
|
||||
noise = new IrisMatter(size, size, 1);
|
||||
slice = noise.slice(Integer.class);
|
||||
|
||||
for(int i = 0; i < slice.getWidth(); i++)
|
||||
{
|
||||
for(int j = 0; j < slice.getHeight(); j++)
|
||||
{
|
||||
set(i, j, cng.noise(i, j));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public CachedNoiseMap(File file) throws IOException, ClassNotFoundException {
|
||||
noise = Matter.read(file);
|
||||
slice = noise.slice(Integer.class);
|
||||
}
|
||||
|
||||
void write(File file) throws IOException {
|
||||
noise.write(file);
|
||||
}
|
||||
|
||||
void set(int x, int y, double value)
|
||||
{
|
||||
slice.set(x%slice.getWidth(), y%slice.getHeight(), 0, Float.floatToIntBits((float)value));
|
||||
}
|
||||
|
||||
double get(int x, int y)
|
||||
{
|
||||
Integer i = slice.get(x%slice.getWidth(), y%slice.getHeight(), 0);
|
||||
|
||||
if(i == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return Float.intBitsToFloat(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer readNodeData(DataInputStream din) throws IOException {
|
||||
return din.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeNodeData(DataOutputStream dos, Integer integer) throws IOException {
|
||||
dos.writeInt(integer);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user