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:
parent
c803feef96
commit
d17b004e7e
7 changed files with 55 additions and 13 deletions
|
@ -44,6 +44,6 @@ public class LoginHandler {
|
||||||
|
|
||||||
Ball ball = new Ball();
|
Ball ball = new Ball();
|
||||||
ball.setInstance(event.getInstance());
|
ball.setInstance(event.getInstance());
|
||||||
ball.teleport(new Pos(0.5, 10, 0.5));
|
ball.teleport(new Pos(0.5, 15, 0.5));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,14 @@
|
||||||
package net.pivipi;
|
package net.pivipi;
|
||||||
|
|
||||||
|
|
||||||
import net.minestom.server.MinecraftServer;
|
import net.minestom.server.MinecraftServer;
|
||||||
import net.minestom.server.event.GlobalEventHandler;
|
import net.minestom.server.event.GlobalEventHandler;
|
||||||
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.registry.DynamicRegistry.Key;
|
||||||
|
import net.minestom.server.world.DimensionType;
|
||||||
|
import net.pivipi.world.FancyDimension;
|
||||||
import net.pivipi.world.SoccerGenerator;
|
import net.pivipi.world.SoccerGenerator;
|
||||||
import net.pivipi.world.WorldConstraints;
|
import net.pivipi.world.WorldConstraints;
|
||||||
|
|
||||||
|
@ -17,7 +21,8 @@ public class Main {
|
||||||
InstanceManager instanceManager = MinecraftServer.getInstanceManager();
|
InstanceManager instanceManager = MinecraftServer.getInstanceManager();
|
||||||
GlobalEventHandler globalEventHandler = MinecraftServer.getGlobalEventHandler();
|
GlobalEventHandler globalEventHandler = MinecraftServer.getGlobalEventHandler();
|
||||||
|
|
||||||
InstanceContainer instanceContainer = instanceManager.createInstanceContainer();
|
Key<DimensionType> dimension = FancyDimension.create();
|
||||||
|
InstanceContainer instanceContainer = instanceManager.createInstanceContainer(dimension);
|
||||||
|
|
||||||
SoccerGenerator generator = new SoccerGenerator();
|
SoccerGenerator generator = new SoccerGenerator();
|
||||||
instanceContainer.setGenerator(generator);
|
instanceContainer.setGenerator(generator);
|
||||||
|
|
|
@ -13,7 +13,6 @@ public class Ball extends Entity {
|
||||||
public Ball(Block block) {
|
public Ball(Block block) {
|
||||||
super(EntityType.FALLING_BLOCK); // not block display because its movement lags for some reason
|
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.setNoGravity(true);
|
||||||
this.setGlowing(true);
|
this.setGlowing(true);
|
||||||
|
|
||||||
|
@ -34,7 +33,7 @@ public class Ball extends Entity {
|
||||||
|
|
||||||
long delay = time - this.lastTick;
|
long delay = time - this.lastTick;
|
||||||
|
|
||||||
physics.applyPhysics();
|
physics.applyPhysics(delay / 1000.0);
|
||||||
|
|
||||||
this.lastTick = time;
|
this.lastTick = time;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
package net.pivipi.physics;
|
package net.pivipi.physics;
|
||||||
|
|
||||||
import javax.swing.text.html.parser.Entity;
|
import net.minestom.server.collision.BoundingBox;
|
||||||
|
import net.minestom.server.collision.SweepResult;
|
||||||
import net.kyori.adventure.text.BlockNBTComponent.Pos;
|
|
||||||
import net.minestom.server.collision.VisibleSweepResult;
|
import net.minestom.server.collision.VisibleSweepResult;
|
||||||
|
import net.minestom.server.coordinate.Vec;
|
||||||
|
import net.minestom.server.entity.Entity;
|
||||||
import net.minestom.server.entity.Player;
|
import net.minestom.server.entity.Player;
|
||||||
|
|
||||||
public class Collision {
|
public class Collision {
|
||||||
|
@ -14,7 +15,7 @@ public class Collision {
|
||||||
* @param velocity the applied velocity
|
* @param velocity the applied velocity
|
||||||
* @return null if no collision
|
* @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
|
return null; // TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,10 +23,11 @@ public class Collision {
|
||||||
*
|
*
|
||||||
* @param groundY ground Y
|
* @param groundY ground Y
|
||||||
* @param moving the moving entity
|
* @param moving the moving entity
|
||||||
* @param velocity the applied velocity
|
|
||||||
* @return null if no collision
|
* @return null if no collision
|
||||||
*/
|
*/
|
||||||
public static VisibleSweepResult willCollideWithGround(double groundY, Entity moving, Pos velocity) {
|
public static VisibleSweepResult willCollideWithGround(double groundY, Entity moving, Vec movement) {
|
||||||
return null; // TODO
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,14 @@
|
||||||
package net.pivipi.physics;
|
package net.pivipi.physics;
|
||||||
|
|
||||||
|
import net.minestom.server.collision.VisibleSweepResult;
|
||||||
|
import net.minestom.server.coordinate.Vec;
|
||||||
import net.minestom.server.entity.Entity;
|
import net.minestom.server.entity.Entity;
|
||||||
|
|
||||||
public class Physics {
|
public class Physics {
|
||||||
private final double gravity = 9.8;
|
private final double gravity = 9.8;
|
||||||
|
private final double bounciness = 1;
|
||||||
|
|
||||||
|
private Vec velocity = new Vec(5, 0, 5);
|
||||||
|
|
||||||
private final Entity entity;
|
private final Entity entity;
|
||||||
|
|
||||||
|
@ -11,7 +16,16 @@ public class Physics {
|
||||||
this.entity = entity;
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
18
src/main/java/net/pivipi/world/FancyDimension.java
Normal file
18
src/main/java/net/pivipi/world/FancyDimension.java
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,6 +6,7 @@ import net.minestom.server.instance.block.Block;
|
||||||
import net.minestom.server.instance.generator.GenerationUnit;
|
import net.minestom.server.instance.generator.GenerationUnit;
|
||||||
import net.minestom.server.instance.generator.Generator;
|
import net.minestom.server.instance.generator.Generator;
|
||||||
import net.minestom.server.instance.generator.UnitModifier;
|
import net.minestom.server.instance.generator.UnitModifier;
|
||||||
|
import net.minestom.server.world.biome.Biome;
|
||||||
|
|
||||||
public class SoccerGenerator implements Generator {
|
public class SoccerGenerator implements Generator {
|
||||||
|
|
||||||
|
@ -13,7 +14,10 @@ public class SoccerGenerator implements Generator {
|
||||||
public void generate(@NotNull GenerationUnit unit) {
|
public void generate(@NotNull GenerationUnit unit) {
|
||||||
UnitModifier modifier = unit.modifier();
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue