diff --git a/.gitignore b/.gitignore index b63da45..53a2169 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +/mojang-data + .gradle build/ !gradle/wrapper/gradle-wrapper.jar diff --git a/build.gradle b/build.gradle index 11afeb9..060d187 100644 --- a/build.gradle +++ b/build.gradle @@ -9,11 +9,15 @@ version = '0.1.0' repositories { mavenCentral() maven { url 'https://jitpack.io' } + maven { url "https://s01.oss.sonatype.org/content/repositories/snapshots/" } } dependencies { implementation "net.minestom:minestom-snapshots:${minestom_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' annotationProcessor 'org.projectlombok:lombok:1.18.34' @@ -41,4 +45,4 @@ tasks { mergeServiceFiles() archiveClassifier.set("") // Prevent the -all suffix on the shadowjar file. } -} \ No newline at end of file +} diff --git a/gradle.properties b/gradle.properties index 4f12409..24a7cce 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,5 @@ minestom_version = d0754f2a15 minestompvp_version = 547b6e95af +vri_version = a79a2d9422 +jnoise_version = 5.0.0-SNAPSHOT diff --git a/src/main/java/dev/ninjdai/werewolf/EventHandler.java b/src/main/java/dev/ninjdai/werewolf/EventHandler.java new file mode 100644 index 0000000..984db16 --- /dev/null +++ b/src/main/java/dev/ninjdai/werewolf/EventHandler.java @@ -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 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); + }); + } +} diff --git a/src/main/java/dev/ninjdai/werewolf/Main.java b/src/main/java/dev/ninjdai/werewolf/Main.java index b894be2..0ebfaec 100644 --- a/src/main/java/dev/ninjdai/werewolf/Main.java +++ b/src/main/java/dev/ninjdai/werewolf/Main.java @@ -3,45 +3,38 @@ package dev.ninjdai.werewolf; import dev.ninjdai.werewolf.commands.LGCommand; import dev.ninjdai.werewolf.commands.PlayerKillCommand; 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.feature.CombatFeatureSet; import io.github.togar2.pvp.feature.CombatFeatures; 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.player.AsyncPlayerConfigurationEvent; 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.InstanceManager; import net.minestom.server.instance.LightingChunk; -import net.minestom.server.instance.block.Block; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.UUID; - public class Main { 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) { MinecraftServer minecraftServer = MinecraftServer.init(); - InstanceManager instanceManager = MinecraftServer.getInstanceManager(); - InstanceContainer instanceContainer = instanceManager.createInstanceContainer(); - instanceContainer.setGenerator(unit -> unit.modifier().fillHeight(0, 40, Block.GRASS_BLOCK)); - instanceContainer.setChunkSupplier(LightingChunk::new); + //VanillaReimplementation vri = VanillaReimplementation.hook(MinecraftServer.process()); + + overworld.setGenerator(LGGenerator::generate); + overworld.setChunkSupplier(LightingChunk::new); GlobalEventHandler globalEventHandler = MinecraftServer.getGlobalEventHandler(); - globalEventHandler.addListener(AsyncPlayerConfigurationEvent.class, event -> { - final Player player = event.getPlayer(); - event.setSpawningInstance(instanceContainer); - player.setRespawnPoint(new Pos(0, 42, 0)); - }); + EventHandler.register(globalEventHandler); - MinecraftServer.getCommandManager().register(new LGCommand(), new PlayerKillCommand()); + MinecraftServer.getCommandManager().register(new LGCommand()); + MinecraftServer.getCommandManager().register(new PlayerKillCommand()); MinestomPvP.init(); CombatFeatureSet legacyVanilla = CombatFeatures.legacyVanilla(); @@ -49,8 +42,6 @@ public class Main { MinecraftServer.getConnectionManager().setPlayerProvider(UHCPlayer::new); - UHCPlayerDeathEvent.register(); - OpenToLAN.open(); MinecraftServer.setBrandName("Playground"); //VelocityProxy.enable("cMkrrJ8tdUS6"); diff --git a/src/main/java/dev/ninjdai/werewolf/uhc/UHCPlayer.java b/src/main/java/dev/ninjdai/werewolf/uhc/UHCPlayer.java index 0420532..4712f80 100644 --- a/src/main/java/dev/ninjdai/werewolf/uhc/UHCPlayer.java +++ b/src/main/java/dev/ninjdai/werewolf/uhc/UHCPlayer.java @@ -7,7 +7,9 @@ import dev.ninjdai.werewolf.uhc.teams.Teams; import io.github.togar2.pvp.player.CombatPlayerImpl; import lombok.Getter; import lombok.Setter; +import net.minestom.server.MinecraftServer; 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.potion.Potion; import net.minestom.server.potion.PotionEffect; @@ -19,6 +21,8 @@ public class UHCPlayer extends CombatPlayerImpl { @Getter private boolean spectating; @Getter @Setter private Team UHCTeam = Teams.VILLAGERS.get(); @Getter @Setter private Role UHCRole = Roles.VILLAGER.get(); + public int minedDiamonds = 0; + public UHCPlayer(@NotNull UUID uuid, @NotNull String username, @NotNull PlayerConnection playerConnection) { super(uuid, username, playerConnection); } @@ -27,14 +31,26 @@ public class UHCPlayer extends CombatPlayerImpl { if (isSpectating()) { spectating = false; + sendPacket(new WorldBorderSizePacket(getInstance().getWorldBorder().diameter())); setGameMode(GameMode.SURVIVAL); + setCanPickupItem(true); + setInvulnerable(false); + setSilent(false); + this.collidesWithEntities = true; setInvisible(false); + setFlying(false); } else { spectating = true; - addEffect(new Potion(PotionEffect.BLINDNESS, (byte) 3, 100, (byte) 0)); - setGameMode(GameMode.SPECTATOR); + sendPacket(new WorldBorderSizePacket(0)); + setGameMode(GameMode.ADVENTURE); + setCanPickupItem(false); + setInvulnerable(true); + setSilent(true); + this.collidesWithEntities = false; setInvisible(true); + setFlying(true); + heal(); } } } diff --git a/src/main/java/dev/ninjdai/werewolf/uhc/events/UHCPlayerDeathEvent.java b/src/main/java/dev/ninjdai/werewolf/uhc/events/UHCPlayerDeathEvent.java deleted file mode 100644 index e6d20c4..0000000 --- a/src/main/java/dev/ninjdai/werewolf/uhc/events/UHCPlayerDeathEvent.java +++ /dev/null @@ -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 playerNode = EventNode.type("player-listener", EventFilter.ENTITY); - MinecraftServer.getGlobalEventHandler().addChild(playerNode); - - playerNode.addListener(EntityPreDeathEvent.class, event -> { - if (event.getEntity() instanceof UHCPlayer) onPlayerDeath(event); - }); - } -} diff --git a/src/main/java/dev/ninjdai/werewolf/worldgen/LGGenerator.java b/src/main/java/dev/ninjdai/werewolf/worldgen/LGGenerator.java new file mode 100644 index 0000000..49e48d9 --- /dev/null +++ b/src/main/java/dev/ninjdai/werewolf/worldgen/LGGenerator.java @@ -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); + } + } + } + } +}