Compare commits

...

2 Commits

Author SHA1 Message Date
028f816598 feat: initial worldgen noise 2024-09-30 12:33:03 +02:00
623e458013 refactor: remove unused imports 2024-09-29 17:22:36 +02:00
16 changed files with 130 additions and 96 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'
@ -41,4 +45,4 @@ tasks {
mergeServiceFiles() mergeServiceFiles()
archiveClassifier.set("") // Prevent the -all suffix on the shadowjar file. archiveClassifier.set("") // Prevent the -all suffix on the shadowjar file.
} }
} }

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,48 +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 net.minestom.server.network.PlayerProvider;
import net.minestom.server.network.player.PlayerConnection;
import org.jetbrains.annotations.NotNull;
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();
@ -52,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

@ -1,10 +1,6 @@
package dev.ninjdai.werewolf.commands; package dev.ninjdai.werewolf.commands;
import net.minestom.server.command.builder.Command; import net.minestom.server.command.builder.Command;
import net.minestom.server.command.builder.arguments.ArgumentType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class LGCommand extends Command { public class LGCommand extends Command {
public LGCommand() { public LGCommand() {
super("lg", "loupgarou", "werewolf"); super("lg", "loupgarou", "werewolf");

View File

@ -1,11 +1,8 @@
package dev.ninjdai.werewolf.commands; package dev.ninjdai.werewolf.commands;
import dev.ninjdai.werewolf.Main;
import dev.ninjdai.werewolf.uhc.UHCPlayer; import dev.ninjdai.werewolf.uhc.UHCPlayer;
import dev.ninjdai.werewolf.uhc.roles.Role; import dev.ninjdai.werewolf.uhc.roles.Role;
import dev.ninjdai.werewolf.uhc.roles.Roles; import dev.ninjdai.werewolf.uhc.roles.Roles;
import dev.ninjdai.werewolf.uhc.teams.Team;
import dev.ninjdai.werewolf.uhc.teams.Teams;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.Style; import net.kyori.adventure.text.format.Style;
import net.kyori.adventure.text.format.TextColor; import net.kyori.adventure.text.format.TextColor;
@ -14,7 +11,6 @@ import net.minestom.server.command.builder.Command;
import net.minestom.server.command.builder.arguments.ArgumentEnum; import net.minestom.server.command.builder.arguments.ArgumentEnum;
import net.minestom.server.command.builder.arguments.ArgumentType; import net.minestom.server.command.builder.arguments.ArgumentType;
import net.minestom.server.command.builder.arguments.minecraft.ArgumentEntity; import net.minestom.server.command.builder.arguments.minecraft.ArgumentEntity;
import net.minestom.server.entity.Player;
import net.minestom.server.utils.entity.EntityFinder; import net.minestom.server.utils.entity.EntityFinder;
public class LGRoleCommand extends Command { public class LGRoleCommand extends Command {

View File

@ -1,6 +1,5 @@
package dev.ninjdai.werewolf.commands; package dev.ninjdai.werewolf.commands;
import dev.ninjdai.werewolf.Main;
import dev.ninjdai.werewolf.uhc.UHCPlayer; import dev.ninjdai.werewolf.uhc.UHCPlayer;
import dev.ninjdai.werewolf.uhc.teams.Team; import dev.ninjdai.werewolf.uhc.teams.Team;
import dev.ninjdai.werewolf.uhc.teams.Teams; import dev.ninjdai.werewolf.uhc.teams.Teams;
@ -12,7 +11,6 @@ import net.minestom.server.command.builder.Command;
import net.minestom.server.command.builder.arguments.ArgumentEnum; import net.minestom.server.command.builder.arguments.ArgumentEnum;
import net.minestom.server.command.builder.arguments.ArgumentType; import net.minestom.server.command.builder.arguments.ArgumentType;
import net.minestom.server.command.builder.arguments.minecraft.ArgumentEntity; import net.minestom.server.command.builder.arguments.minecraft.ArgumentEntity;
import net.minestom.server.entity.Player;
import net.minestom.server.utils.entity.EntityFinder; import net.minestom.server.utils.entity.EntityFinder;
public class LGTeamCommand extends Command { public class LGTeamCommand extends Command {

View File

@ -4,25 +4,25 @@ import dev.ninjdai.werewolf.uhc.roles.Role;
import dev.ninjdai.werewolf.uhc.roles.Roles; import dev.ninjdai.werewolf.uhc.roles.Roles;
import dev.ninjdai.werewolf.uhc.teams.Team; import dev.ninjdai.werewolf.uhc.teams.Team;
import dev.ninjdai.werewolf.uhc.teams.Teams; import dev.ninjdai.werewolf.uhc.teams.Teams;
import io.github.togar2.pvp.MinestomPvP;
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.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;
import net.minestom.server.timer.TaskSchedule;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.Optional;
import java.util.UUID; import java.util.UUID;
public class UHCPlayer extends CombatPlayerImpl { 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);
} }
@ -31,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,7 +1,6 @@
package dev.ninjdai.werewolf.uhc.effects; package dev.ninjdai.werewolf.uhc.effects;
import net.minestom.server.potion.Potion; import net.minestom.server.potion.Potion;
import org.jetbrains.annotations.Nullable;
import java.util.Optional; import java.util.Optional;

View File

@ -1,47 +0,0 @@
package dev.ninjdai.werewolf.uhc.events;
import dev.ninjdai.werewolf.uhc.UHCPlayer;
import dev.ninjdai.werewolf.uhc.roles.Role;
import dev.ninjdai.werewolf.uhc.roles.Roles;
import dev.ninjdai.werewolf.uhc.teams.Team;
import dev.ninjdai.werewolf.uhc.teams.Teams;
import dev.ninjdai.werewolf.uhc.teams.WinCondition;
import io.github.togar2.pvp.events.EntityPreDeathEvent;
import net.kyori.adventure.sound.Sound;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.Style;
import net.kyori.adventure.text.format.TextColor;
import net.minestom.server.MinecraftServer;
import net.minestom.server.entity.GameMode;
import net.minestom.server.entity.Player;
import net.minestom.server.event.EventFilter;
import net.minestom.server.event.EventNode;
import net.minestom.server.event.trait.EntityEvent;
import net.minestom.server.sound.SoundEvent;
import org.jetbrains.annotations.NotNull;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
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

@ -9,7 +9,6 @@ import net.kyori.adventure.text.format.Style;
import net.kyori.adventure.text.format.TextColor; import net.kyori.adventure.text.format.TextColor;
import net.kyori.adventure.text.format.TextDecoration; import net.kyori.adventure.text.format.TextDecoration;
import net.minestom.server.item.ItemStack; import net.minestom.server.item.ItemStack;
import net.minestom.server.tag.Tag;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.*; import java.util.*;

View File

@ -2,9 +2,6 @@ package dev.ninjdai.werewolf.uhc.roles;
import dev.ninjdai.werewolf.uhc.effects.werewolves.WerewolfStrength; import dev.ninjdai.werewolf.uhc.effects.werewolves.WerewolfStrength;
import java.util.HashMap;
import java.util.Map;
public enum Roles { public enum Roles {
WEREWOLF(new Role.Builder().setId("werewolf").setName("Werewolf").addRoleEffect(new WerewolfStrength()).build()), WEREWOLF(new Role.Builder().setId("werewolf").setName("Werewolf").addRoleEffect(new WerewolfStrength()).build()),
VILLAGER(new Role.Builder().setId("villager").setName("Villager").build()); VILLAGER(new Role.Builder().setId("villager").setName("Villager").build());

View File

@ -2,7 +2,6 @@ package dev.ninjdai.werewolf.uhc.teams;
import lombok.Getter; import lombok.Getter;
import net.minestom.server.color.Color; import net.minestom.server.color.Color;
import net.minestom.server.tag.Tag;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;

View File

@ -1,11 +1,7 @@
package dev.ninjdai.werewolf.uhc.teams; package dev.ninjdai.werewolf.uhc.teams;
import dev.ninjdai.werewolf.uhc.roles.Role;
import net.minestom.server.color.Color; import net.minestom.server.color.Color;
import java.util.HashMap;
import java.util.Map;
public enum Teams { public enum Teams {
WEREWOLVES(new Team.Builder().setId("werewolves").setName("Werewolves").setColor(new Color(150,10,10)).build()), WEREWOLVES(new Team.Builder().setId("werewolves").setName("Werewolves").setColor(new Color(150,10,10)).build()),
VILLAGERS(new Team.Builder().setId("villagers").setName("Villagers").setColor(new Color(48,216,90)).build()), VILLAGERS(new Team.Builder().setId("villagers").setName("Villagers").setColor(new Color(48,216,90)).build()),

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);
}
}
}
}
}