mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 10:30:42 +00:00
add inject lock
This commit is contained in:
@@ -94,45 +94,17 @@ public class BukkitChunkGeneratorWrapper extends org.bukkit.generator.ChunkGener
|
||||
@Override
|
||||
public boolean shouldGenerateDecorations() {
|
||||
return false;
|
||||
//return pack.vanillaFlora();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Location getFixedSpawnLocation(@NotNull World world, @NotNull Random random) {
|
||||
LOGGER.info("Getting spawn location...");
|
||||
int x = random.nextInt(-500, 500);
|
||||
int z = random.nextInt(-500, 500);
|
||||
int y = world.getMaxHeight() - 1;
|
||||
|
||||
int max = 500;
|
||||
for(int i = 0; i < max; i++) {
|
||||
BukkitWorldProperties properties = new BukkitWorldProperties(world);
|
||||
while(y > world.getMinHeight() && delegate.getBlock(properties, x, y, z, pack.getBiomeProvider()).isAir()) y--;
|
||||
|
||||
if(((BlockData) delegate.getBlock(properties, x, y, z, pack.getBiomeProvider()).getHandle()).getMaterial().isSolid()) {
|
||||
LOGGER.info("Found spawn on attempt {}", i + 1);
|
||||
break;
|
||||
} else {
|
||||
x = random.nextInt(-500, 500);
|
||||
z = random.nextInt(-500, 500);
|
||||
y = world.getMaxHeight() - 1;
|
||||
if(i % 25 == 0) LOGGER.info("Spawn finding attempt {}/{} failed. Retrying...", i, max);
|
||||
}
|
||||
}
|
||||
|
||||
return new Location(world, x, y, z);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean shouldGenerateMobs() {
|
||||
return true;
|
||||
//return pack.vanillaMobs();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldGenerateStructures() {
|
||||
return true;
|
||||
//return pack.vanillaStructures();
|
||||
}
|
||||
|
||||
public ConfigPack getPack() {
|
||||
|
||||
@@ -1,25 +1,39 @@
|
||||
package com.dfsek.terra.bukkit.nms;
|
||||
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.world.chunk.generation.ProtoChunk;
|
||||
import com.dfsek.terra.bukkit.generator.BukkitChunkGeneratorWrapper;
|
||||
|
||||
import com.dfsek.terra.bukkit.world.BukkitWorldProperties;
|
||||
|
||||
import net.minecraft.server.level.WorldServer;
|
||||
import net.minecraft.world.level.chunk.ChunkGenerator;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_18_R2.CraftWorld;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.world.WorldInitEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
|
||||
public class NMSInjectListener implements Listener {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(NMSInjectListener.class);
|
||||
private static final Set<World> INJECTED = new HashSet<>();
|
||||
private static final ReentrantLock INJECT_LOCK = new ReentrantLock();
|
||||
|
||||
@EventHandler
|
||||
public void onWorldInit(WorldInitEvent event) {
|
||||
if (event.getWorld().getGenerator() instanceof BukkitChunkGeneratorWrapper bukkitChunkGeneratorWrapper) {
|
||||
LOGGER.info("A great evil has fallen upon this land: {}", event.getWorld().getName());
|
||||
if (!INJECTED.contains(event.getWorld()) && event.getWorld().getGenerator() instanceof BukkitChunkGeneratorWrapper bukkitChunkGeneratorWrapper) {
|
||||
INJECT_LOCK.lock();
|
||||
INJECTED.add(event.getWorld());
|
||||
LOGGER.info("Preparing to take over the world: {}", event.getWorld().getName());
|
||||
CraftWorld craftWorld = (CraftWorld) event.getWorld();
|
||||
WorldServer serverWorld = craftWorld.getHandle();
|
||||
|
||||
@@ -34,6 +48,7 @@ public class NMSInjectListener implements Listener {
|
||||
serverWorld.k().a.u = custom;
|
||||
|
||||
LOGGER.info("Successfully injected into world.");
|
||||
INJECT_LOCK.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user