diff --git a/src/main/java/net/pivipi/LoginHandler.java b/src/main/java/net/pivipi/LoginHandler.java index a3105cf..4a717e0 100644 --- a/src/main/java/net/pivipi/LoginHandler.java +++ b/src/main/java/net/pivipi/LoginHandler.java @@ -44,6 +44,6 @@ public class LoginHandler { Ball ball = new Ball(); ball.setInstance(event.getInstance()); - ball.teleport(new Pos(0.5, 10, 0.5)); + ball.teleport(new Pos(0.5, 15, 0.5)); } } diff --git a/src/main/java/net/pivipi/Main.java b/src/main/java/net/pivipi/Main.java index b77516e..4f2d705 100644 --- a/src/main/java/net/pivipi/Main.java +++ b/src/main/java/net/pivipi/Main.java @@ -1,10 +1,14 @@ 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.minestom.server.registry.DynamicRegistry.Key; +import net.minestom.server.world.DimensionType; +import net.pivipi.world.FancyDimension; import net.pivipi.world.SoccerGenerator; import net.pivipi.world.WorldConstraints; @@ -17,7 +21,8 @@ public class Main { InstanceManager instanceManager = MinecraftServer.getInstanceManager(); GlobalEventHandler globalEventHandler = MinecraftServer.getGlobalEventHandler(); - InstanceContainer instanceContainer = instanceManager.createInstanceContainer(); + Key dimension = FancyDimension.create(); + InstanceContainer instanceContainer = instanceManager.createInstanceContainer(dimension); SoccerGenerator generator = new SoccerGenerator(); instanceContainer.setGenerator(generator); diff --git a/src/main/java/net/pivipi/ball/Ball.java b/src/main/java/net/pivipi/ball/Ball.java index 52b3b81..71fd87f 100644 --- a/src/main/java/net/pivipi/ball/Ball.java +++ b/src/main/java/net/pivipi/ball/Ball.java @@ -13,7 +13,6 @@ public class Ball extends Entity { 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); @@ -34,7 +33,7 @@ public class Ball extends Entity { long delay = time - this.lastTick; - physics.applyPhysics(); + physics.applyPhysics(delay / 1000.0); this.lastTick = time; } diff --git a/src/main/java/net/pivipi/physics/Collision.java b/src/main/java/net/pivipi/physics/Collision.java index fd61da3..7523ef0 100644 --- a/src/main/java/net/pivipi/physics/Collision.java +++ b/src/main/java/net/pivipi/physics/Collision.java @@ -1,9 +1,10 @@ package net.pivipi.physics; -import javax.swing.text.html.parser.Entity; - -import net.kyori.adventure.text.BlockNBTComponent.Pos; +import net.minestom.server.collision.BoundingBox; +import net.minestom.server.collision.SweepResult; import net.minestom.server.collision.VisibleSweepResult; +import net.minestom.server.coordinate.Vec; +import net.minestom.server.entity.Entity; import net.minestom.server.entity.Player; public class Collision { @@ -14,7 +15,7 @@ public class Collision { * @param velocity the applied velocity * @return null if no collision */ - public static VisibleSweepResult willCollideWithPlayer(Player player, Entity moving, Pos velocity) { + public static VisibleSweepResult willCollideWithPlayer(Player player, Entity moving, Vec velocity) { return null; // TODO } @@ -22,10 +23,11 @@ public class Collision { * * @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 + public static VisibleSweepResult willCollideWithGround(double groundY, Entity moving, Vec movement) { + SweepResult sweepResult = new SweepResult(1, 0, 0, 0, null, 0, 0, 0); + boolean collided = new BoundingBox(10, 10, 1).intersectBoxSwept(moving.getPosition(), movement, moving.getPosition().withY(groundY).sub(5, 0, 5), moving.getBoundingBox(), sweepResult); + return collided ? new VisibleSweepResult(sweepResult) : null; } } diff --git a/src/main/java/net/pivipi/physics/Physics.java b/src/main/java/net/pivipi/physics/Physics.java index 9698539..651e748 100644 --- a/src/main/java/net/pivipi/physics/Physics.java +++ b/src/main/java/net/pivipi/physics/Physics.java @@ -1,9 +1,14 @@ package net.pivipi.physics; +import net.minestom.server.collision.VisibleSweepResult; +import net.minestom.server.coordinate.Vec; import net.minestom.server.entity.Entity; public class Physics { private final double gravity = 9.8; + private final double bounciness = 1; + + private Vec velocity = new Vec(5, 0, 5); private final Entity entity; @@ -11,7 +16,16 @@ public class Physics { this.entity = entity; } - public void applyPhysics() { + public void applyPhysics(double delta) { + velocity = velocity.sub(0, gravity * delta, 0); + VisibleSweepResult result = Collision.willCollideWithGround(5, entity, velocity.mul(delta)); + System.out.println(entity.hasCollision()); + if (result != null) { + System.out.println(result.res); + velocity = velocity.mul(0, -bounciness, 0); + } + + entity.setVelocity(velocity); } } diff --git a/src/main/java/net/pivipi/world/FancyDimension.java b/src/main/java/net/pivipi/world/FancyDimension.java new file mode 100644 index 0000000..0fd54d9 --- /dev/null +++ b/src/main/java/net/pivipi/world/FancyDimension.java @@ -0,0 +1,18 @@ +package net.pivipi.world; + +import net.minestom.server.MinecraftServer; +import net.minestom.server.registry.DynamicRegistry.Key; +import net.minestom.server.utils.NamespaceID; +import net.minestom.server.world.DimensionType; + +public class FancyDimension { + public static Key create() { + DimensionType dimension = DimensionType.builder() + .ambientLight(1.0f) + .fixedTime(18000l) + .effects("minecraft:the_end") + .build(); + + return MinecraftServer.getDimensionTypeRegistry().register(NamespaceID.from("fancy_dimension"), dimension); + } +} diff --git a/src/main/java/net/pivipi/world/SoccerGenerator.java b/src/main/java/net/pivipi/world/SoccerGenerator.java index 63f21f7..1103c03 100644 --- a/src/main/java/net/pivipi/world/SoccerGenerator.java +++ b/src/main/java/net/pivipi/world/SoccerGenerator.java @@ -6,6 +6,7 @@ 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; +import net.minestom.server.world.biome.Biome; public class SoccerGenerator implements Generator { @@ -13,7 +14,10 @@ public class SoccerGenerator implements Generator { public void generate(@NotNull GenerationUnit unit) { UnitModifier modifier = unit.modifier(); - modifier.fillHeight(1, 2, Block.GRASS_BLOCK); + modifier.fillBiome(Biome.SNOWY_PLAINS); + + modifier.fillHeight(1, 2, Block.COARSE_DIRT); + modifier.fill(unit.absoluteStart().withY(1).add(1, 0, 1), unit.absoluteEnd().withY(2), Block.GRASS_BLOCK); } }