From c803feef96ec640d4162de6c509a4ae76d7762c6 Mon Sep 17 00:00:00 2001 From: Minecon724 Date: Thu, 4 Jul 2024 18:04:46 +0200 Subject: [PATCH] initial commit I accidentally did git rm -fr . and it removed all the code with no backups --- .classpath | 40 +++++++++++++++ .gitignore | 3 ++ .project | 23 +++++++++ pom.xml | 24 +++++++++ .../server/collision/VisibleSweepResult.java | 19 +++++++ src/main/java/net/pivipi/LoginHandler.java | 49 +++++++++++++++++++ src/main/java/net/pivipi/Main.java | 42 ++++++++++++++++ src/main/java/net/pivipi/ball/Ball.java | 42 ++++++++++++++++ .../java/net/pivipi/physics/Collision.java | 31 ++++++++++++ src/main/java/net/pivipi/physics/Physics.java | 17 +++++++ .../net/pivipi/world/SoccerGenerator.java | 19 +++++++ .../net/pivipi/world/WorldConstraints.java | 32 ++++++++++++ 12 files changed, 341 insertions(+) create mode 100644 .classpath create mode 100644 .gitignore create mode 100644 .project create mode 100644 pom.xml create mode 100644 src/main/java/net/minestom/server/collision/VisibleSweepResult.java create mode 100644 src/main/java/net/pivipi/LoginHandler.java create mode 100644 src/main/java/net/pivipi/Main.java create mode 100644 src/main/java/net/pivipi/ball/Ball.java create mode 100644 src/main/java/net/pivipi/physics/Collision.java create mode 100644 src/main/java/net/pivipi/physics/Physics.java create mode 100644 src/main/java/net/pivipi/world/SoccerGenerator.java create mode 100644 src/main/java/net/pivipi/world/WorldConstraints.java diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..7a9a105 --- /dev/null +++ b/.classpath @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2992ae8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/target/ +/bin/ +/.settings/ diff --git a/.project b/.project new file mode 100644 index 0000000..dac10b6 --- /dev/null +++ b/.project @@ -0,0 +1,23 @@ + + + soccer + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..5e2a28b --- /dev/null +++ b/pom.xml @@ -0,0 +1,24 @@ + + + 4.0.0 + + net.pivipi + soccer + 0.0.1-SNAPSHOT + + + 17 + 17 + + + + + net.minestom + minestom-snapshots + 90fb708739 + + + + \ No newline at end of file diff --git a/src/main/java/net/minestom/server/collision/VisibleSweepResult.java b/src/main/java/net/minestom/server/collision/VisibleSweepResult.java new file mode 100644 index 0000000..5ec1a28 --- /dev/null +++ b/src/main/java/net/minestom/server/collision/VisibleSweepResult.java @@ -0,0 +1,19 @@ +package net.minestom.server.collision; + +public class VisibleSweepResult { + public final double res; + public final double normalX, normalY, normalZ; + public final double collidedPositionX, collidedPositionY, collidedPositionZ; + public final Shape collidedShape; + + public VisibleSweepResult(SweepResult sweepResult) { + this.res = sweepResult.res; + this.normalX = sweepResult.normalX; + this.normalY = sweepResult.normalY; + this.normalZ = sweepResult.normalZ; + this.collidedPositionX = sweepResult.collidedPositionX; + this.collidedPositionY = sweepResult.collidedPositionY; + this.collidedPositionZ = sweepResult.collidedPositionZ; + this.collidedShape = sweepResult.collidedShape; + } +} diff --git a/src/main/java/net/pivipi/LoginHandler.java b/src/main/java/net/pivipi/LoginHandler.java new file mode 100644 index 0000000..a3105cf --- /dev/null +++ b/src/main/java/net/pivipi/LoginHandler.java @@ -0,0 +1,49 @@ +package net.pivipi; + +import net.minestom.server.coordinate.Pos; +import net.minestom.server.entity.GameMode; +import net.minestom.server.entity.Player; +import net.minestom.server.event.GlobalEventHandler; +import net.minestom.server.event.player.AsyncPlayerConfigurationEvent; +import net.minestom.server.event.player.PlayerSpawnEvent; +import net.minestom.server.instance.Instance; +import net.pivipi.ball.Ball; + +public class LoginHandler { + private final Instance spawningInstance; + + public LoginHandler(Instance spawningInstance) { + this.spawningInstance = spawningInstance; + } + + public void setup(GlobalEventHandler globalEventHandler) { + globalEventHandler.addListener( + AsyncPlayerConfigurationEvent.class, + event -> onLogin(event) + ); + + globalEventHandler.addListener( + PlayerSpawnEvent.class, + event -> onSpawn(event) + ); + } + + private void onLogin(AsyncPlayerConfigurationEvent event) { + Player player = event.getPlayer(); + + event.setSpawningInstance(spawningInstance); + event.setHardcore(true); + + player.setRespawnPoint(new Pos(0, 5, 0)); + } + + private void onSpawn(PlayerSpawnEvent event) { + Player player = event.getPlayer(); + + player.setGameMode(GameMode.CREATIVE); + + Ball ball = new Ball(); + ball.setInstance(event.getInstance()); + ball.teleport(new Pos(0.5, 10, 0.5)); + } +} diff --git a/src/main/java/net/pivipi/Main.java b/src/main/java/net/pivipi/Main.java new file mode 100644 index 0000000..b77516e --- /dev/null +++ b/src/main/java/net/pivipi/Main.java @@ -0,0 +1,42 @@ +package net.pivipi; + +import net.minestom.server.MinecraftServer; +import net.minestom.server.event.GlobalEventHandler; +import net.minestom.server.instance.InstanceContainer; +import net.minestom.server.instance.InstanceManager; +import net.minestom.server.instance.LightingChunk; +import net.pivipi.world.SoccerGenerator; +import net.pivipi.world.WorldConstraints; + +public class Main { + public static void main(String[] args) { + System.setProperty("minestom.tps", "60"); + + MinecraftServer minecraftServer = MinecraftServer.init(); + + InstanceManager instanceManager = MinecraftServer.getInstanceManager(); + GlobalEventHandler globalEventHandler = MinecraftServer.getGlobalEventHandler(); + + InstanceContainer instanceContainer = instanceManager.createInstanceContainer(); + + SoccerGenerator generator = new SoccerGenerator(); + instanceContainer.setGenerator(generator); + instanceContainer.setChunkSupplier(LightingChunk::new); + + LoginHandler loginHandler = new LoginHandler(instanceContainer); + loginHandler.setup(globalEventHandler); + + WorldConstraints worldConstraints = new WorldConstraints(); + worldConstraints.setup(globalEventHandler); + + + /* done */ + + MinecraftServer.setCompressionThreshold(0); + MinecraftServer.setBrandName("PiViPi"); + + minecraftServer.start("0.0.0.0", 25565); + System.out.println("started"); + + } +} \ No newline at end of file diff --git a/src/main/java/net/pivipi/ball/Ball.java b/src/main/java/net/pivipi/ball/Ball.java new file mode 100644 index 0000000..52b3b81 --- /dev/null +++ b/src/main/java/net/pivipi/ball/Ball.java @@ -0,0 +1,42 @@ +package net.pivipi.ball; + +import net.minestom.server.entity.Entity; +import net.minestom.server.entity.EntityType; +import net.minestom.server.entity.metadata.other.FallingBlockMeta; +import net.minestom.server.instance.block.Block; +import net.pivipi.physics.Physics; + +public class Ball extends Entity { + private long lastTick; + private final Physics physics = new Physics(this); + + public Ball(Block block) { + super(EntityType.FALLING_BLOCK); // not block display because its movement lags for some reason + + this.setBoundingBox(0.625, 0.625, 0.625); + this.setNoGravity(true); + this.setGlowing(true); + + this.editEntityMeta(FallingBlockMeta.class, meta -> { + meta.setBlock(block); + }); + } + + public Ball() { + this(Block.WHITE_WOOL); + } + + + public void tick(long time) { // I don't know if change that to update + if (this.lastTick == 0) { + this.lastTick = time; + } + + long delay = time - this.lastTick; + + physics.applyPhysics(); + + this.lastTick = time; + } + +} diff --git a/src/main/java/net/pivipi/physics/Collision.java b/src/main/java/net/pivipi/physics/Collision.java new file mode 100644 index 0000000..fd61da3 --- /dev/null +++ b/src/main/java/net/pivipi/physics/Collision.java @@ -0,0 +1,31 @@ +package net.pivipi.physics; + +import javax.swing.text.html.parser.Entity; + +import net.kyori.adventure.text.BlockNBTComponent.Pos; +import net.minestom.server.collision.VisibleSweepResult; +import net.minestom.server.entity.Player; + +public class Collision { + /** + * + * @param player + * @param moving the moving entity + * @param velocity the applied velocity + * @return null if no collision + */ + public static VisibleSweepResult willCollideWithPlayer(Player player, Entity moving, Pos velocity) { + return null; // TODO + } + + /** + * + * @param groundY ground Y + * @param moving the moving entity + * @param velocity the applied velocity + * @return null if no collision + */ + public static VisibleSweepResult willCollideWithGround(double groundY, Entity moving, Pos velocity) { + return null; // TODO + } +} diff --git a/src/main/java/net/pivipi/physics/Physics.java b/src/main/java/net/pivipi/physics/Physics.java new file mode 100644 index 0000000..9698539 --- /dev/null +++ b/src/main/java/net/pivipi/physics/Physics.java @@ -0,0 +1,17 @@ +package net.pivipi.physics; + +import net.minestom.server.entity.Entity; + +public class Physics { + private final double gravity = 9.8; + + private final Entity entity; + + public Physics(Entity entity) { + this.entity = entity; + } + + public void applyPhysics() { + + } +} diff --git a/src/main/java/net/pivipi/world/SoccerGenerator.java b/src/main/java/net/pivipi/world/SoccerGenerator.java new file mode 100644 index 0000000..63f21f7 --- /dev/null +++ b/src/main/java/net/pivipi/world/SoccerGenerator.java @@ -0,0 +1,19 @@ +package net.pivipi.world; + +import org.jetbrains.annotations.NotNull; + +import net.minestom.server.instance.block.Block; +import net.minestom.server.instance.generator.GenerationUnit; +import net.minestom.server.instance.generator.Generator; +import net.minestom.server.instance.generator.UnitModifier; + +public class SoccerGenerator implements Generator { + + @Override + public void generate(@NotNull GenerationUnit unit) { + UnitModifier modifier = unit.modifier(); + + modifier.fillHeight(1, 2, Block.GRASS_BLOCK); + } + +} diff --git a/src/main/java/net/pivipi/world/WorldConstraints.java b/src/main/java/net/pivipi/world/WorldConstraints.java new file mode 100644 index 0000000..02c86c1 --- /dev/null +++ b/src/main/java/net/pivipi/world/WorldConstraints.java @@ -0,0 +1,32 @@ +package net.pivipi.world; + +import net.minestom.server.event.GlobalEventHandler; +import net.minestom.server.event.player.PlayerBlockBreakEvent; +import net.minestom.server.event.player.PlayerBlockPlaceEvent; + +public class WorldConstraints { + public WorldConstraints() { + + } + + private void onBreak(PlayerBlockBreakEvent event) { + //if (event.getBlock() == Block.GRASS_BLOCK) + // event.setCancelled(true); + } + + private void onPlace(PlayerBlockPlaceEvent event) { + + } + + public void setup(GlobalEventHandler globalEventHandler) { + globalEventHandler.addListener( + PlayerBlockBreakEvent.class, + event -> onBreak(event) + ); + + globalEventHandler.addListener( + PlayerBlockPlaceEvent.class, + event -> onPlace(event) + ); + } +}