mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-19 10:43:14 +00:00
Add strongholds (POG)
This commit is contained in:
parent
044c7f997d
commit
e6113b4aa1
@ -16,6 +16,7 @@ import com.volmit.iris.scaffold.parallel.MultiBurst;
|
|||||||
import com.volmit.iris.util.*;
|
import com.volmit.iris.util.*;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.Biome;
|
import org.bukkit.block.Biome;
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
@ -25,6 +26,10 @@ import org.bukkit.event.world.WorldSaveEvent;
|
|||||||
import org.bukkit.generator.BlockPopulator;
|
import org.bukkit.generator.BlockPopulator;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
public class IrisEngineCompound implements EngineCompound {
|
public class IrisEngineCompound implements EngineCompound {
|
||||||
@Getter
|
@Getter
|
||||||
@ -66,36 +71,47 @@ public class IrisEngineCompound implements EngineCompound {
|
|||||||
engineMetadata.setLastVersion(Iris.instance.getDescription().getVersion());
|
engineMetadata.setLastVersion(Iris.instance.getDescription().getVersion());
|
||||||
|
|
||||||
|
|
||||||
if(engineMetadata.getStrongholdPosition() == null)
|
if(engineMetadata.getStrongholdPositions() == null || engineMetadata.getStrongholdPositions().size() == 0)
|
||||||
{
|
{
|
||||||
if(!(world instanceof FakeWorld && world instanceof HeightedFakeWorld))
|
if(!(world instanceof FakeWorld || world instanceof HeightedFakeWorld))
|
||||||
{
|
{
|
||||||
|
Iris.info("Got this far (0)");
|
||||||
|
List<IrisPosition> strongholds = new ArrayList<>();
|
||||||
Object nmsWorld = new V(world).invoke("getHandle");
|
Object nmsWorld = new V(world).invoke("getHandle");
|
||||||
Object chunkProvider = new V(nmsWorld).invoke("getChunkProvider");
|
Object chunkProvider = new V(nmsWorld).invoke("getChunkProvider");
|
||||||
Object chunkGenerator = new V(chunkProvider).invoke("getChunkGenerator");
|
Object chunkGenerator = new V(chunkProvider).invoke("getChunkGenerator");
|
||||||
try {
|
try {
|
||||||
|
Iris.info("Got this far (1)");
|
||||||
Class<?> clazz = Class.forName("net.minecraft.server." + INMS.getNMSTag() + ".ChunkGenerator");
|
Class<?> clazz = Class.forName("net.minecraft.server." + INMS.getNMSTag() + ".ChunkGenerator");
|
||||||
Class<?> clazzSG = Class.forName("net.minecraft.server." + INMS.getNMSTag() + ".StructureGenerator");
|
Class<?> clazzSG = Class.forName("net.minecraft.server." + INMS.getNMSTag() + ".StructureGenerator");
|
||||||
Class<?> clazzBP = Class.forName("net.minecraft.server." + INMS.getNMSTag() + ".BlockPosition");
|
Class<?> clazzBP = Class.forName("net.minecraft.server." + INMS.getNMSTag() + ".BlockPosition");
|
||||||
Object bp = clazz.getDeclaredMethod("findNearestMapFeature",
|
CompletableFuture<Object> cf = new CompletableFuture<>();
|
||||||
nmsWorld.getClass(),
|
Object BP = null;
|
||||||
clazzSG,
|
getBPSafe(clazz, clazzSG, clazzBP, nmsWorld, chunkGenerator).thenAccept(bp -> {
|
||||||
clazzBP,
|
Iris.info("Got this far (2)");
|
||||||
int.class,
|
strongholds.add(new IrisPosition((int) new V(bp, false).invoke("getX"), (int) new V(bp, false).invoke("getY"), (int) new V(bp, false).invoke("getZ")));
|
||||||
boolean.class
|
Iris.info("Got this far (3)");
|
||||||
).invoke(chunkGenerator,
|
String positions = "";
|
||||||
nmsWorld,
|
for (IrisPosition pos : strongholds){
|
||||||
clazzSG.getDeclaredField("STRONGHOLD").get(null),
|
positions += "(" + pos.getX() + "," + pos.getY() + "," + pos.getZ() + ") ";
|
||||||
clazzBP.getDeclaredField("ZERO").get(null),
|
}
|
||||||
100,
|
Iris.info("Strongholds (" + engineMetadata.getStrongholdPositions().size() + ") found at [" + positions + "]");
|
||||||
false
|
});
|
||||||
);
|
|
||||||
engineMetadata.setStrongholdPosition(new IrisPosition((int)new V(bp, false).invoke("getX"), (int)new V(bp, false).invoke("getY"), (int)new V(bp, false).invoke("getZ")));
|
engineMetadata.setStrongholdPositions(strongholds);
|
||||||
} catch (Throwable ignored) {
|
} catch (Throwable ignored) {
|
||||||
engineMetadata.setStrongholdPosition(new IrisPosition(1337, 32, -1337));
|
strongholds.add( new IrisPosition(10337, 32, -1337) );
|
||||||
Iris.warn("Couldn't properly find the stronghold positon for this world. Is this headless mode?");
|
engineMetadata.setStrongholdPositions(strongholds);
|
||||||
|
Iris.warn("Couldn't properly find the stronghold position for this world. Is this headless mode?");
|
||||||
|
Iris.warn(" -> Setting default stronghold position");
|
||||||
|
ignored.printStackTrace();
|
||||||
|
Iris.info("Got this far (3)");
|
||||||
|
String positions = "";
|
||||||
|
for (IrisPosition pos : strongholds){
|
||||||
|
positions += "(" + pos.getX() + "," + pos.getY() + "," + pos.getZ() + ") ";
|
||||||
|
}
|
||||||
|
Iris.info("Strongholds (" + engineMetadata.getStrongholdPositions().size() + ") found at [" + positions + "]");
|
||||||
}
|
}
|
||||||
Iris.info("Stronghold: " + engineMetadata.getStrongholdPosition().toString());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,9 +175,38 @@ public class IrisEngineCompound implements EngineCompound {
|
|||||||
Iris.instance.registerListener(this);
|
Iris.instance.registerListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IrisPosition getStrongholdPosition()
|
private Object getBP(Class clazz, Class clazzSG, Class clazzBP, Object nmsWorld, Object chunkGenerator) throws NoSuchFieldException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
|
||||||
|
return clazz.getDeclaredMethod("findNearestMapFeature",
|
||||||
|
nmsWorld.getClass(),
|
||||||
|
clazzSG,
|
||||||
|
clazzBP,
|
||||||
|
int.class,
|
||||||
|
boolean.class
|
||||||
|
).invoke(chunkGenerator,
|
||||||
|
nmsWorld,
|
||||||
|
clazzSG.getDeclaredField("STRONGHOLD").get(null),
|
||||||
|
clazzBP.getDeclaredField("ZERO").get(null),
|
||||||
|
100,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompletableFuture<Object> getBPSafe(Class clazz, Class clazzSG, Class clazzBP, Object nmsWorld, Object chunkGenerator) {
|
||||||
|
CompletableFuture<Object> cf = new CompletableFuture<>();
|
||||||
|
Bukkit.getScheduler().runTask(Iris.instance, () -> {
|
||||||
|
try {
|
||||||
|
cf.complete(getBP(clazz, clazzSG, clazzBP, nmsWorld, chunkGenerator));
|
||||||
|
} catch (Throwable e){
|
||||||
|
cf.complete(null);
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return cf;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<IrisPosition> getStrongholdPositions()
|
||||||
{
|
{
|
||||||
return engineMetadata.getStrongholdPosition();
|
return engineMetadata.getStrongholdPositions();
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
@ -16,9 +16,9 @@ public class CommandLocate extends MortarCommand implements Listener
|
|||||||
{
|
{
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event) {
|
public void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event) {
|
||||||
if (event.getMessage().contains("locate") && IrisWorlds.isIrisWorld(event.getPlayer().getWorld())){
|
if (!event.getMessage().contains("stronghold") && event.getMessage().contains("locate") && IrisWorlds.isIrisWorld(event.getPlayer().getWorld())) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
event.getPlayer().sendMessage("/locate command blocked in Iris worlds. Please use '/ir goto' instead.");
|
event.getPlayer().sendMessage("/locate command blocked in Iris worlds. Please use '/ir goto' instead. You can /locate stronghold!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,6 +16,8 @@ import org.bukkit.command.CommandSender;
|
|||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.generator.BlockPopulator;
|
import org.bukkit.generator.BlockPopulator;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public interface EngineCompound extends Listener, Hotloadable, DataProvider
|
public interface EngineCompound extends Listener, Hotloadable, DataProvider
|
||||||
{
|
{
|
||||||
public IrisDimension getRootDimension();
|
public IrisDimension getRootDimension();
|
||||||
@ -24,7 +26,7 @@ public interface EngineCompound extends Listener, Hotloadable, DataProvider
|
|||||||
|
|
||||||
public World getWorld();
|
public World getWorld();
|
||||||
|
|
||||||
public IrisPosition getStrongholdPosition();
|
public List<IrisPosition> getStrongholdPositions();
|
||||||
|
|
||||||
public void printMetrics(CommandSender sender);
|
public void printMetrics(CommandSender sender);
|
||||||
|
|
||||||
|
@ -7,12 +7,13 @@ import lombok.Data;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class EngineData {
|
public class EngineData {
|
||||||
private String dimension;
|
private String dimension;
|
||||||
private String lastVersion;
|
private String lastVersion;
|
||||||
private IrisPosition strongholdPosition;
|
private List<IrisPosition> strongholdPositions;
|
||||||
|
|
||||||
public void save(File f)
|
public void save(File f)
|
||||||
{
|
{
|
||||||
|
@ -21,6 +21,7 @@ import org.bukkit.block.data.BlockData;
|
|||||||
import org.bukkit.util.BlockVector;
|
import org.bukkit.util.BlockVector;
|
||||||
import org.bukkit.util.Consumer;
|
import org.bukkit.util.Consumer;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
@ -345,6 +346,10 @@ public interface EngineParallaxManager extends DataProvider, IObjectPlacer {
|
|||||||
{
|
{
|
||||||
KList<Runnable> placeAfter = new KList<>();
|
KList<Runnable> placeAfter = new KList<>();
|
||||||
|
|
||||||
|
if (structure == null){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
if(structure.getFeature() != null)
|
if(structure.getFeature() != null)
|
||||||
{
|
{
|
||||||
if(structure.getFeature().getBlockRadius() == 32)
|
if(structure.getFeature().getBlockRadius() == 32)
|
||||||
@ -366,13 +371,13 @@ public interface EngineParallaxManager extends DataProvider, IObjectPlacer {
|
|||||||
|
|
||||||
if(getEngine().getDimension().getStronghold() != null)
|
if(getEngine().getDimension().getStronghold() != null)
|
||||||
{
|
{
|
||||||
IrisPosition pos = getEngine().getCompound().getStrongholdPosition();
|
List<IrisPosition> poss = getEngine().getCompound().getStrongholdPositions();
|
||||||
|
for (IrisPosition pos : poss) {
|
||||||
if(x == pos.getX() >> 4 && z == pos.getZ() >> 4)
|
if (x == pos.getX() >> 4 && z == pos.getZ() >> 4) {
|
||||||
{
|
IrisJigsawStructure structure = getData().getJigsawStructureLoader().load(getEngine().getDimension().getStronghold());
|
||||||
IrisJigsawStructure structure = getData().getJigsawStructureLoader().load(getEngine().getDimension().getStronghold());
|
placeAfter.addAll(placeStructure(pos, structure, rng));
|
||||||
placeAfter.addAll(placeStructure(pos, structure, rng));
|
placed = true;
|
||||||
placed = true;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user