mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-12-29 12:09:07 +00:00
THE SUPER DUPER COOL BUT TOTALLY NOT STABLE THING THATS NOT READY YET...
This commit is contained in:
@@ -4,6 +4,7 @@ import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.WorldCreator;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
|
||||
public interface INMSBinding {
|
||||
Object getBiomeBaseFromId(int id);
|
||||
@@ -29,4 +30,8 @@ public interface INMSBinding {
|
||||
default World createWorld(WorldCreator c) {
|
||||
return c.createWorld();
|
||||
}
|
||||
|
||||
int countCustomBiomes();
|
||||
|
||||
void forceBiomeInto(int x, int y, int z, Object somethingVeryDirty, ChunkGenerator.BiomeGrid chunk);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.volmit.iris.nms.v17_1;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.nms.INMSBinding;
|
||||
import com.volmit.iris.util.KMap;
|
||||
import net.minecraft.core.IRegistry;
|
||||
@@ -7,18 +8,54 @@ import net.minecraft.core.IRegistryWritable;
|
||||
import net.minecraft.resources.MinecraftKey;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.world.level.biome.BiomeBase;
|
||||
import net.minecraft.world.level.chunk.BiomeStorage;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.craftbukkit.v1_17_R1.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_17_R1.CraftWorld;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class NMSBinding17_1 implements INMSBinding {
|
||||
private final KMap<Biome, Object> baseBiomeCache = new KMap<>();
|
||||
private Field biomeStorageCache = null;
|
||||
|
||||
private Object getBiomeStorage(ChunkGenerator.BiomeGrid g)
|
||||
{
|
||||
try {
|
||||
return getFieldForBiomeStorage(g).get(g);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private Field getFieldForBiomeStorage(Object storage) {
|
||||
Field f = biomeStorageCache;
|
||||
|
||||
if (f != null)
|
||||
{
|
||||
return f;
|
||||
}
|
||||
try {
|
||||
|
||||
f = storage.getClass().getDeclaredField("biome");
|
||||
f.setAccessible(true);
|
||||
return f;
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
Iris.error(storage.getClass().getCanonicalName());
|
||||
}
|
||||
|
||||
biomeStorageCache = f;
|
||||
return null;
|
||||
}
|
||||
|
||||
private IRegistryWritable<BiomeBase> getCustomBiomeRegistry() {
|
||||
return ((CraftServer) Bukkit.getServer()).getHandle().getServer().getCustomRegistry().b(IRegistry.aO);
|
||||
@@ -148,6 +185,34 @@ public class NMSBinding17_1 implements INMSBinding {
|
||||
return biome.ordinal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int countCustomBiomes() {
|
||||
AtomicInteger a = new AtomicInteger(0);
|
||||
getCustomBiomeRegistry().d().stream().forEach((i) -> {
|
||||
MinecraftKey k = i.getKey().a();
|
||||
|
||||
if(k.getNamespace().equals("minecraft"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
a.incrementAndGet();
|
||||
Iris.verbose("Custom Biome: " + k.toString());
|
||||
});
|
||||
|
||||
return a.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forceBiomeInto(int x, int y, int z, Object somethingVeryDirty, ChunkGenerator.BiomeGrid chunk) {
|
||||
try {
|
||||
BiomeStorage s = (BiomeStorage) getFieldForBiomeStorage(chunk).get(chunk);
|
||||
s.setBiome(x,y,z, (BiomeBase) somethingVeryDirty);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBukkit() {
|
||||
return false;
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.volmit.iris.nms.INMSBinding;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
|
||||
public class NMSBinding1X implements INMSBinding {
|
||||
@Override
|
||||
@@ -54,4 +55,14 @@ public class NMSBinding1X implements INMSBinding {
|
||||
public int getBiomeId(Biome biome) {
|
||||
return biome.ordinal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int countCustomBiomes() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forceBiomeInto(int x, int y, int z, Object somethingVeryDirty, ChunkGenerator.BiomeGrid chunk) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user