Skip to content

Commit

Permalink
Merge pull request #785 from VolmitSoftware/Development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
NextdoorPsycho authored Apr 16, 2022
2 parents 5b3918f + 935d11b commit 609104c
Show file tree
Hide file tree
Showing 10 changed files with 282 additions and 2 deletions.
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ plugins {
id "de.undercouch.download" version "5.0.1"
}

version '2.0.4-1.18.2' // Needs to be version specific
version '2.0.5-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'
Expand Down Expand Up @@ -124,6 +124,7 @@ dependencies {
annotationProcessor 'org.projectlombok:lombok:1.18.22'
implementation 'org.spigotmc:spigot-api:1.18.2-R0.1-SNAPSHOT'
implementation 'me.clip:placeholderapi:2.11.1'
implementation 'io.th0rgal:oraxen:1.94.0'
implementation 'org.bukkit:craftbukkit:1.18.2-R0.1-SNAPSHOT:remapped-mojang'

// Shaded
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/volmit/iris/Iris.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@
import com.volmit.iris.core.link.IrisPapiExpansion;
import com.volmit.iris.core.link.MultiverseCoreLink;
import com.volmit.iris.core.link.MythicMobsLink;
import com.volmit.iris.core.link.OraxenLink;
import com.volmit.iris.core.loader.IrisData;
import com.volmit.iris.core.nms.INMS;
import com.volmit.iris.core.service.StudioSVC;
import com.volmit.iris.core.tools.IrisToolbelt;
import com.volmit.iris.engine.EnginePanic;
import com.volmit.iris.engine.object.IrisBiome;
import com.volmit.iris.engine.object.IrisCompat;
Expand Down Expand Up @@ -64,6 +66,7 @@
import org.bukkit.WorldCreator;
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.Player;
Expand Down Expand Up @@ -93,6 +96,7 @@ public class Iris extends VolmitPlugin implements Listener {
public static Iris instance;
public static BukkitAudiences audiences;
public static MultiverseCoreLink linkMultiverseCore;
public static OraxenLink linkOraxen;
public static MythicMobsLink linkMythicMobs;
public static IrisCompat compat;
public static FileWatcher configWatcher;
Expand Down Expand Up @@ -398,6 +402,7 @@ private void enable() {
instance = this;
compat = IrisCompat.configured(getDataFile("compat.json"));
linkMultiverseCore = new MultiverseCoreLink();
linkOraxen = new OraxenLink();
linkMythicMobs = new MythicMobsLink();
configWatcher = new FileWatcher(getDataFile("settings.json"));
services.values().forEach(IrisService::onEnable);
Expand Down
113 changes: 113 additions & 0 deletions src/main/java/com/volmit/iris/core/link/OraxenLink.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*
* 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.link;

import com.volmit.iris.util.collection.KList;
import io.th0rgal.oraxen.items.OraxenItems;
import io.th0rgal.oraxen.mechanics.Mechanic;
import io.th0rgal.oraxen.mechanics.MechanicFactory;
import io.th0rgal.oraxen.mechanics.MechanicsManager;
import io.th0rgal.oraxen.mechanics.provided.gameplay.block.BlockMechanic;
import io.th0rgal.oraxen.mechanics.provided.gameplay.block.BlockMechanicFactory;
import io.th0rgal.oraxen.mechanics.provided.gameplay.noteblock.NoteBlockMechanicFactory;
import io.th0rgal.oraxen.utils.Utils;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.MultipleFacing;
import org.bukkit.plugin.Plugin;

import java.lang.reflect.Field;
import java.util.Map;

public class OraxenLink {
private static final String[] EMPTY = new String[0];

public boolean supported() {
return getOraxen() != null;
}

public BlockData getBlockDataFor(String id) {
if(!supported()) {
return null;
}

MechanicFactory f = getFactory(id);

if(f == null) {
return null;
}

Mechanic m = f.getMechanic(id);

// TODO: Why isnt there a simple getBlockData() function?
if(m.getFactory() instanceof NoteBlockMechanicFactory) {
return ((NoteBlockMechanicFactory) m.getFactory()).createNoteBlockData(id);
} else if(m.getFactory() instanceof BlockMechanicFactory) {
MultipleFacing newBlockData = (MultipleFacing) Bukkit.createBlockData(Material.MUSHROOM_STEM);
Utils.setBlockFacing(newBlockData, ((BlockMechanic) m).getCustomVariation());
return newBlockData;
}

return null;
}

public MechanicFactory getFactory(String id) {
if(!supported()) {
return null;
}

try {
Field f = MechanicsManager.class.getDeclaredField("FACTORIES_BY_MECHANIC_ID");
f.setAccessible(true);
Map<String, MechanicFactory> map = (Map<String, MechanicFactory>) f.get(null);

for(MechanicFactory i : map.values()) {
if(i.getItems().contains(id)) {
return i;
}
}
} catch(Throwable e) {
e.printStackTrace();
}

return null;
}

public String[] getItemTypes() {
if(!supported()) {
return EMPTY;
}

KList<String> v = new KList<>();

for(String i : OraxenItems.getItemNames()) {
if(getBlockDataFor(i) != null) {
v.add(i);
}
}

return v.toArray(new String[0]);
}

public Plugin getOraxen() {

return Bukkit.getPluginManager().getPlugin("Oraxen");
}
}
66 changes: 66 additions & 0 deletions src/main/java/com/volmit/iris/core/tools/IrisToolbelt.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,21 @@
import com.volmit.iris.util.plugin.VolmitSender;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.block.data.BlockData;
import org.bukkit.entity.Player;

import java.io.File;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

/**
* Something you really want to wear if working on Iris. Shit gets pretty hectic down there.
* Hope you packed snacks & road sodas.
*/
public class IrisToolbelt {
public static Map<String, Boolean> toolbeltConfiguration = new HashMap<>();

/**
* Will find / download / search for the dimension or return null
* <p>
Expand Down Expand Up @@ -210,4 +216,64 @@ public static boolean evacuate(World world, String m) {
public static boolean isStudio(World i) {
return isIrisWorld(i) && access(i).isStudio();
}

public static void retainMantleDataForSlice(String className)
{
toolbeltConfiguration.put("retain.mantle." + className, true);
}

public static <T> T getMantleData(World world, int x, int y, int z, Class<T> of)
{
PlatformChunkGenerator e = access(world);
if(e == null) {return null;}
return e.getEngine().getMantle().getMantle().get(x, y - world.getMinHeight(), z, of);
}

public static <T> void deleteMantleData(World world, int x, int y, int z, Class<T> of)
{
PlatformChunkGenerator e = access(world);
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;
}
}
70 changes: 70 additions & 0 deletions src/main/java/com/volmit/iris/engine/mantle/MantleWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@
import com.volmit.iris.engine.data.cache.Cache;
import com.volmit.iris.engine.framework.Engine;
import com.volmit.iris.engine.object.IObjectPlacer;
import com.volmit.iris.engine.object.IrisGeneratorStyle;
import com.volmit.iris.engine.object.IrisPosition;
import com.volmit.iris.engine.object.TileData;
import com.volmit.iris.util.collection.KMap;
import com.volmit.iris.util.collection.KSet;
import com.volmit.iris.util.function.Function3;
import com.volmit.iris.util.mantle.Mantle;
import com.volmit.iris.util.mantle.MantleChunk;
import com.volmit.iris.util.math.RNG;
import com.volmit.iris.util.matter.Matter;
import lombok.Data;
import org.bukkit.block.TileState;
Expand Down Expand Up @@ -121,6 +123,13 @@ private static double lengthSq(double x, double z) {
return (x * x) + (z * z);
}

public <T> void setDataWarped(int x, int y, int z, T t, RNG rng, IrisData data, IrisGeneratorStyle style)
{
setData((int)Math.round(style.warp(rng, data, x, x, y, -z)),
(int)Math.round(style.warp(rng, data, y, z, -x, y)),
(int)Math.round(style.warp(rng, data, z, -y, z, x)), t);
}

public <T> void setData(int x, int y, int z, T t) {
if(t == null) {
return;
Expand Down Expand Up @@ -233,6 +242,10 @@ public <T> void setElipsoid(int cx, int cy, int cz, double rx, double ry, double
setElipsoidFunction(cx, cy, cz, rx, ry, rz, fill, (a, b, c) -> data);
}

public <T> void setElipsoidWarped(int cx, int cy, int cz, double rx, double ry, double rz, boolean fill, T data, RNG rng, IrisData idata, IrisGeneratorStyle style) {
setElipsoidFunctionWarped(cx, cy, cz, rx, ry, rz, fill, (a, b, c) -> data, rng, idata, style);
}

/**
* Set an elipsoid into the mantle
*
Expand Down Expand Up @@ -312,6 +325,63 @@ public <T> void setElipsoidFunction(int cx, int cy, int cz, double rx, double ry
}
}

public <T> void setElipsoidFunctionWarped(int cx, int cy, int cz, double rx, double ry, double rz, boolean fill, Function3<Integer, Integer, Integer, T> data, RNG rng, IrisData idata, IrisGeneratorStyle style) {
rx += 0.5;
ry += 0.5;
rz += 0.5;
final double invRadiusX = 1 / rx;
final double invRadiusY = 1 / ry;
final double invRadiusZ = 1 / rz;
final int ceilRadiusX = (int) Math.ceil(rx);
final int ceilRadiusY = (int) Math.ceil(ry);
final int ceilRadiusZ = (int) Math.ceil(rz);
double nextXn = 0;

forX:
for(int x = 0; x <= ceilRadiusX; ++x) {
final double xn = nextXn;
nextXn = (x + 1) * invRadiusX;
double nextYn = 0;
forY:
for(int y = 0; y <= ceilRadiusY; ++y) {
final double yn = nextYn;
nextYn = (y + 1) * invRadiusY;
double nextZn = 0;
for(int z = 0; z <= ceilRadiusZ; ++z) {
final double zn = nextZn;
nextZn = (z + 1) * invRadiusZ;

double distanceSq = lengthSq(xn, yn, zn);
if(distanceSq > 1) {
if(z == 0) {
if(y == 0) {
break forX;
}
break forY;
}
break;
}

if(!fill) {
if(lengthSq(nextXn, yn, zn) <= 1 && lengthSq(xn, nextYn, zn) <= 1 && lengthSq(xn, yn, nextZn) <= 1) {
continue;
}
}

setDataWarped(x + cx, y + cy, z + cz, data.apply(x + cx, y + cy, z + cz), rng, idata, style);
setDataWarped(-x + cx, y + cy, z + cz, data.apply(-x + cx, y + cy, z + cz), rng, idata, style);
setDataWarped(x + cx, -y + cy, z + cz, data.apply(x + cx, -y + cy, z + cz), rng, idata, style);
setDataWarped(x + cx, y + cy, -z + cz, data.apply(x + cx, y + cy, -z + cz), rng, idata, style);
setDataWarped(-x + cx, y + cy, -z + cz, data.apply(-x + cx, y + cy, -z + cz), rng, idata, style);
setDataWarped(-x + cx, -y + cy, z + cz, data.apply(-x + cx, -y + cy, z + cz), rng, idata, style);
setDataWarped(x + cx, -y + cy, -z + cz, data.apply(x + cx, -y + cy, -z + cz), rng, idata, style);
setDataWarped(-x + cx, y + cy, -z + cz, data.apply(-x + cx, y + cy, -z + cz), rng, idata, style);
setDataWarped(-x + cx, -y + cy, -z + cz, data.apply(-x + cx, -y + cy, -z + cz), rng, idata, style);
}
}
}
}

/**
* Set a cuboid of data in the mantle
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ public CNG createNoCache(RNG rng, IrisData data) {
return cng;
}

public double warp(RNG rng, IrisData data, double value, double... coords)
{
return create(rng, data).noise(coords) + value;
}

public CNG create(RNG rng, IrisData data) {
return cng.aquire(() -> createNoCache(rng, data));
}
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/volmit/iris/util/data/B.java
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,10 @@ private static BlockData parseBlockData(String ix) {
BlockData bx = null;

if(!ix.startsWith("minecraft:")) {
if(ix.startsWith("oraxen:") && Iris.linkOraxen.supported()) {
bx = Iris.linkOraxen.getBlockDataFor(ix.split("\\Q:\\E")[1]);
}

if(bx == null) {
try {
if(ix.contains(":")) {
Expand Down Expand Up @@ -648,6 +652,14 @@ public synchronized static String[] getBlockTypes() {
}
}

try {
for(String i : Iris.linkOraxen.getItemTypes()) {
bt.add("oraxen:" + i);
}
} catch(Throwable e) {
e.printStackTrace();
}

try {
bt.addAll(Iris.service(RegistrySVC.class).getCustomBlockRegistry().compile());
} catch(Throwable e) {
Expand Down
Loading

0 comments on commit 609104c

Please sign in to comment.