Please enter the commit message for your changes. Lines starting

with '#' will be ignored, and an empty message aborts the commit.
This commit is contained in:
Minecon724 2024-07-04 20:46:26 +02:00
parent c803feef96
commit d17b004e7e
Signed by: Minecon724
GPG key ID: 3CCC4D267742C8E8
7 changed files with 55 additions and 13 deletions

View file

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

View file

@ -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<DimensionType> dimension = FancyDimension.create();
InstanceContainer instanceContainer = instanceManager.createInstanceContainer(dimension);
SoccerGenerator generator = new SoccerGenerator();
instanceContainer.setGenerator(generator);

View file

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

View file

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

View file

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

View file

@ -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<DimensionType> create() {
DimensionType dimension = DimensionType.builder()
.ambientLight(1.0f)
.fixedTime(18000l)
.effects("minecraft:the_end")
.build();
return MinecraftServer.getDimensionTypeRegistry().register(NamespaceID.from("fancy_dimension"), dimension);
}
}

View file

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