feat: initial worldgen noise

This commit is contained in:
Ninjdai 2024-09-30 12:33:03 +02:00
parent 623e458013
commit 028f816598
8 changed files with 131 additions and 53 deletions

2
.gitignore vendored
View File

@ -1,3 +1,5 @@
/mojang-data
.gradle .gradle
build/ build/
!gradle/wrapper/gradle-wrapper.jar !gradle/wrapper/gradle-wrapper.jar

View File

@ -9,11 +9,15 @@ version = '0.1.0'
repositories { repositories {
mavenCentral() mavenCentral()
maven { url 'https://jitpack.io' } maven { url 'https://jitpack.io' }
maven { url "https://s01.oss.sonatype.org/content/repositories/snapshots/" }
} }
dependencies { dependencies {
implementation "net.minestom:minestom-snapshots:${minestom_version}" implementation "net.minestom:minestom-snapshots:${minestom_version}"
implementation "com.github.TogAr2:MinestomPvP:${minestompvp_version}" implementation "com.github.TogAr2:MinestomPvP:${minestompvp_version}"
implementation "com.github.Minestom:VanillaReimplementation:${vri_version}"
implementation("de.articdive:jnoise-pipeline:${jnoise_version}")
compileOnly 'org.projectlombok:lombok:1.18.34' compileOnly 'org.projectlombok:lombok:1.18.34'
annotationProcessor 'org.projectlombok:lombok:1.18.34' annotationProcessor 'org.projectlombok:lombok:1.18.34'

View File

@ -1,3 +1,5 @@
minestom_version = d0754f2a15 minestom_version = d0754f2a15
minestompvp_version = 547b6e95af minestompvp_version = 547b6e95af
vri_version = a79a2d9422
jnoise_version = 5.0.0-SNAPSHOT

View File

@ -0,0 +1,54 @@
package dev.ninjdai.werewolf;
import dev.ninjdai.werewolf.uhc.UHCPlayer;
import dev.ninjdai.werewolf.uhc.events.TimedPlayerDeath;
import io.github.togar2.pvp.events.EntityPreDeathEvent;
import net.minestom.server.coordinate.Pos;
import net.minestom.server.entity.ItemEntity;
import net.minestom.server.entity.Player;
import net.minestom.server.event.Event;
import net.minestom.server.event.EventNode;
import net.minestom.server.event.GlobalEventHandler;
import net.minestom.server.event.player.AsyncPlayerConfigurationEvent;
import net.minestom.server.event.player.PlayerBlockBreakEvent;
import net.minestom.server.instance.block.Block;
import net.minestom.server.item.ItemStack;
import net.minestom.server.item.Material;
import java.time.Duration;
public class EventHandler {
public static void onBlockBreak(PlayerBlockBreakEvent event) {
Material m = Material.fromNamespaceId(event.getBlock().namespace());
if (m == null) return;
ItemEntity item = new ItemEntity(ItemStack.of(m));
item.setPickupDelay(Duration.ofMillis(500));
item.setMergeable(true);
item.setInstance(event.getInstance(), event.getBlockPosition().add(0.5, 0.5, 0.5));
}
public static void onPlayerConfiguration(AsyncPlayerConfigurationEvent event) {
final Player player = event.getPlayer();
event.setSpawningInstance(Main.overworld);
player.setRespawnPoint(new Pos(0, 42, 0));
};
public static void onPlayerDeath(EntityPreDeathEvent event) {
UHCPlayer player = (UHCPlayer) event.getEntity();
event.setCancelDeath(true);
player.toggleSpectating();
var timedPlayerDeath = new TimedPlayerDeath(player, event.getDamage(), 15);
player.getUHCRole().onPlayerDeath(player, timedPlayerDeath);
}
public static void register(EventNode<Event> node) {
node.addListener(PlayerBlockBreakEvent.class, EventHandler::onBlockBreak);
node.addListener(AsyncPlayerConfigurationEvent.class, EventHandler::onPlayerConfiguration);
node.addListener(EntityPreDeathEvent.class, event -> {
if (event.getEntity() instanceof UHCPlayer) onPlayerDeath(event);
});
}
}

View File

@ -3,45 +3,38 @@ package dev.ninjdai.werewolf;
import dev.ninjdai.werewolf.commands.LGCommand; import dev.ninjdai.werewolf.commands.LGCommand;
import dev.ninjdai.werewolf.commands.PlayerKillCommand; import dev.ninjdai.werewolf.commands.PlayerKillCommand;
import dev.ninjdai.werewolf.uhc.UHCPlayer; import dev.ninjdai.werewolf.uhc.UHCPlayer;
import dev.ninjdai.werewolf.uhc.events.UHCPlayerDeathEvent; import dev.ninjdai.werewolf.worldgen.LGGenerator;
import io.github.togar2.pvp.MinestomPvP; import io.github.togar2.pvp.MinestomPvP;
import io.github.togar2.pvp.feature.CombatFeatureSet; import io.github.togar2.pvp.feature.CombatFeatureSet;
import io.github.togar2.pvp.feature.CombatFeatures; import io.github.togar2.pvp.feature.CombatFeatures;
import net.minestom.server.MinecraftServer; import net.minestom.server.MinecraftServer;
import net.minestom.server.coordinate.Pos;
import net.minestom.server.entity.Player;
import net.minestom.server.event.GlobalEventHandler; import net.minestom.server.event.GlobalEventHandler;
import net.minestom.server.event.player.AsyncPlayerConfigurationEvent;
import net.minestom.server.extras.lan.OpenToLAN; import net.minestom.server.extras.lan.OpenToLAN;
import net.minestom.server.extras.velocity.VelocityProxy;
import net.minestom.server.instance.InstanceContainer; import net.minestom.server.instance.InstanceContainer;
import net.minestom.server.instance.InstanceManager; import net.minestom.server.instance.InstanceManager;
import net.minestom.server.instance.LightingChunk; import net.minestom.server.instance.LightingChunk;
import net.minestom.server.instance.block.Block;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.UUID;
public class Main { public class Main {
public static final Logger LOGGER = LoggerFactory.getLogger("Playground"); public static final Logger LOGGER = LoggerFactory.getLogger("Playground");
public static final InstanceManager instanceManager = MinecraftServer.getInstanceManager();
public static final InstanceContainer overworld = instanceManager.createInstanceContainer();
public static void main(String[] args) { public static void main(String[] args) {
MinecraftServer minecraftServer = MinecraftServer.init(); MinecraftServer minecraftServer = MinecraftServer.init();
InstanceManager instanceManager = MinecraftServer.getInstanceManager(); //VanillaReimplementation vri = VanillaReimplementation.hook(MinecraftServer.process());
InstanceContainer instanceContainer = instanceManager.createInstanceContainer();
instanceContainer.setGenerator(unit -> unit.modifier().fillHeight(0, 40, Block.GRASS_BLOCK)); overworld.setGenerator(LGGenerator::generate);
instanceContainer.setChunkSupplier(LightingChunk::new); overworld.setChunkSupplier(LightingChunk::new);
GlobalEventHandler globalEventHandler = MinecraftServer.getGlobalEventHandler(); GlobalEventHandler globalEventHandler = MinecraftServer.getGlobalEventHandler();
globalEventHandler.addListener(AsyncPlayerConfigurationEvent.class, event -> { EventHandler.register(globalEventHandler);
final Player player = event.getPlayer();
event.setSpawningInstance(instanceContainer);
player.setRespawnPoint(new Pos(0, 42, 0));
});
MinecraftServer.getCommandManager().register(new LGCommand(), new PlayerKillCommand()); MinecraftServer.getCommandManager().register(new LGCommand());
MinecraftServer.getCommandManager().register(new PlayerKillCommand());
MinestomPvP.init(); MinestomPvP.init();
CombatFeatureSet legacyVanilla = CombatFeatures.legacyVanilla(); CombatFeatureSet legacyVanilla = CombatFeatures.legacyVanilla();
@ -49,8 +42,6 @@ public class Main {
MinecraftServer.getConnectionManager().setPlayerProvider(UHCPlayer::new); MinecraftServer.getConnectionManager().setPlayerProvider(UHCPlayer::new);
UHCPlayerDeathEvent.register();
OpenToLAN.open(); OpenToLAN.open();
MinecraftServer.setBrandName("Playground"); MinecraftServer.setBrandName("Playground");
//VelocityProxy.enable("cMkrrJ8tdUS6"); //VelocityProxy.enable("cMkrrJ8tdUS6");

View File

@ -7,7 +7,9 @@ import dev.ninjdai.werewolf.uhc.teams.Teams;
import io.github.togar2.pvp.player.CombatPlayerImpl; import io.github.togar2.pvp.player.CombatPlayerImpl;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import net.minestom.server.MinecraftServer;
import net.minestom.server.entity.GameMode; import net.minestom.server.entity.GameMode;
import net.minestom.server.network.packet.server.play.WorldBorderSizePacket;
import net.minestom.server.network.player.PlayerConnection; import net.minestom.server.network.player.PlayerConnection;
import net.minestom.server.potion.Potion; import net.minestom.server.potion.Potion;
import net.minestom.server.potion.PotionEffect; import net.minestom.server.potion.PotionEffect;
@ -19,6 +21,8 @@ public class UHCPlayer extends CombatPlayerImpl {
@Getter private boolean spectating; @Getter private boolean spectating;
@Getter @Setter private Team UHCTeam = Teams.VILLAGERS.get(); @Getter @Setter private Team UHCTeam = Teams.VILLAGERS.get();
@Getter @Setter private Role UHCRole = Roles.VILLAGER.get(); @Getter @Setter private Role UHCRole = Roles.VILLAGER.get();
public int minedDiamonds = 0;
public UHCPlayer(@NotNull UUID uuid, @NotNull String username, @NotNull PlayerConnection playerConnection) { public UHCPlayer(@NotNull UUID uuid, @NotNull String username, @NotNull PlayerConnection playerConnection) {
super(uuid, username, playerConnection); super(uuid, username, playerConnection);
} }
@ -27,14 +31,26 @@ public class UHCPlayer extends CombatPlayerImpl {
if (isSpectating()) { if (isSpectating()) {
spectating = false; spectating = false;
sendPacket(new WorldBorderSizePacket(getInstance().getWorldBorder().diameter()));
setGameMode(GameMode.SURVIVAL); setGameMode(GameMode.SURVIVAL);
setCanPickupItem(true);
setInvulnerable(false);
setSilent(false);
this.collidesWithEntities = true;
setInvisible(false); setInvisible(false);
setFlying(false);
} else { } else {
spectating = true; spectating = true;
addEffect(new Potion(PotionEffect.BLINDNESS, (byte) 3, 100, (byte) 0)); sendPacket(new WorldBorderSizePacket(0));
setGameMode(GameMode.SPECTATOR); setGameMode(GameMode.ADVENTURE);
setCanPickupItem(false);
setInvulnerable(true);
setSilent(true);
this.collidesWithEntities = false;
setInvisible(true); setInvisible(true);
setFlying(true);
heal();
} }
} }
} }

View File

@ -1,30 +0,0 @@
package dev.ninjdai.werewolf.uhc.events;
import dev.ninjdai.werewolf.uhc.UHCPlayer;
import io.github.togar2.pvp.events.EntityPreDeathEvent;
import net.minestom.server.MinecraftServer;
import net.minestom.server.event.EventFilter;
import net.minestom.server.event.EventNode;
import net.minestom.server.event.trait.EntityEvent;
public class UHCPlayerDeathEvent {
public static void onPlayerDeath(EntityPreDeathEvent event) {
UHCPlayer player = (UHCPlayer) event.getEntity();
event.setCancelDeath(true);
player.toggleSpectating();
var timedPlayerDeath = new TimedPlayerDeath(player, event.getDamage(), 15);
player.getUHCRole().onPlayerDeath(player, timedPlayerDeath);
}
public static void register() {
EventNode<EntityEvent> playerNode = EventNode.type("player-listener", EventFilter.ENTITY);
MinecraftServer.getGlobalEventHandler().addChild(playerNode);
playerNode.addListener(EntityPreDeathEvent.class, event -> {
if (event.getEntity() instanceof UHCPlayer) onPlayerDeath(event);
});
}
}

View File

@ -0,0 +1,39 @@
package dev.ninjdai.werewolf.worldgen;
import de.articdive.jnoise.core.api.functions.Interpolation;
import de.articdive.jnoise.core.api.modifiers.NoiseModifier;
import de.articdive.jnoise.generators.noise_parameters.fade_functions.FadeFunction;
import de.articdive.jnoise.modifiers.clamp.ClampModifier;
import de.articdive.jnoise.modules.octavation.fractal_functions.FractalFunction;
import de.articdive.jnoise.pipeline.JNoise;
import net.minestom.server.coordinate.Point;
import net.minestom.server.instance.block.Block;
import net.minestom.server.instance.generator.GenerationUnit;
import org.jetbrains.annotations.NotNull;
public class LGGenerator {
static final JNoise noise1 = JNoise.newBuilder()
.perlin(3301, Interpolation.LINEAR, FadeFunction.QUINTIC_POLY)
.scale(1/48.0)
.addModifier(v -> (v + 1) / 2.0)
.clamp(0.0, 1.0)
.octavate(3, 0.5, .75, FractalFunction.TURBULENCE, true)
.build();
public static void generate(@NotNull GenerationUnit unit) {
Point start = unit.absoluteStart();
for (int x = 0; x < unit.size().x(); x++) {
for (int z = 0; z < unit.size().z(); z++) {
Point bottom = start.add(x, 0, z);
synchronized (noise1) {
double height = noise1.evaluateNoise(bottom.x(), bottom.z()) * 16 + 20;
// * 16 means the height will be between -16 and +16
unit.modifier().fill(bottom, bottom.add(1, 0, 1).withY(height), Block.STONE);
unit.modifier().fill(bottom.withY(height), bottom.add(1, 0, 1).withY(height+3), Block.DIRT);
unit.modifier().fill(bottom.withY(height+3), bottom.add(1, 0, 1).withY(height+4), Block.GRASS_BLOCK);
}
}
}
}
}