From f0c53339461471b87d60881a05587580b1cc41d8 Mon Sep 17 00:00:00 2001 From: minemobs Date: Wed, 17 Jul 2024 23:22:19 +0200 Subject: [PATCH] Added relatively good tnt throw (fix #9) --- build.gradle.kts | 2 +- gradle/wrapper/gradle-wrapper.properties | 2 +- .../sunderia/bomberman/PrimedTntEntity.java | 7 ++++ .../kotlin/fr/sunderia/bomberman/Bomberman.kt | 32 ++++++++++++++++--- .../fr/sunderia/bomberman/party/Game.kt | 2 +- 5 files changed, 37 insertions(+), 8 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index bc9af6e..e9141fe 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -14,7 +14,7 @@ repositories { } dependencies { - implementation("net.minestom:minestom-snapshots:e17689902f") + implementation("net.minestom:minestom-snapshots:8736fc43d8") implementation("commons-codec:commons-codec:1.16.1") } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 17655d0..0d18421 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/java/fr/sunderia/bomberman/PrimedTntEntity.java b/src/main/java/fr/sunderia/bomberman/PrimedTntEntity.java index 7450070..06314c6 100644 --- a/src/main/java/fr/sunderia/bomberman/PrimedTntEntity.java +++ b/src/main/java/fr/sunderia/bomberman/PrimedTntEntity.java @@ -32,6 +32,12 @@ public class PrimedTntEntity extends Entity { private boolean pierce; public static Team pierceTeam; + public double calculateNextY(double x, double maxPosX) { + double maxBlockX = maxPosX; + // -3.75 / (minBlock - maxBlock)² * (x - minBlock)(x - maxBlock) + return (-3.75f/Math.pow(0.0-maxBlockX, 2)) * (x - 0.0) * (x - maxBlockX); + } + public Player getPlayer() { return player; } @@ -40,6 +46,7 @@ public PrimedTntEntity(Player player, Instance instance, Point pos) { super(EntityType.TNT); this.player = player; this.setInstance(instance, pos); + this.setNoGravity(true); setBoundingBox(1, 1, 1); } diff --git a/src/main/kotlin/fr/sunderia/bomberman/Bomberman.kt b/src/main/kotlin/fr/sunderia/bomberman/Bomberman.kt index 622ccf1..0a61fe7 100644 --- a/src/main/kotlin/fr/sunderia/bomberman/Bomberman.kt +++ b/src/main/kotlin/fr/sunderia/bomberman/Bomberman.kt @@ -57,6 +57,8 @@ import java.net.URI import java.util.* import java.util.logging.Level import java.util.logging.Logger +import kotlin.math.abs +import kotlin.math.sign fun main() { @@ -78,7 +80,7 @@ class Bomberman { fun getLobbyInstance(): Instance { return lobbyInstance } - val fullBrightType = DimensionType.builder(NamespaceID.from("sunderia:full_bright")).ambientLight(2.0f).build() + val fullBrightType = DimensionType.builder().ambientLight(2.0f).build() lateinit var fullbright: DynamicRegistry.Key } @@ -90,7 +92,7 @@ class Bomberman { fun initialize() { val manager = MinecraftServer.getInstanceManager() - fullbright = MinecraftServer.getDimensionTypeRegistry().register(fullBrightType) + fullbright = MinecraftServer.getDimensionTypeRegistry().register(NamespaceID.from("sunderia:full_bright"), fullBrightType) val lobbyContainer: InstanceContainer = createInstanceContainer(manager) lobbyInstance = lobbyContainer createNPC(lobbyContainer) @@ -118,6 +120,7 @@ class Bomberman { @Suppress("UnstableApiUsage", "NestedLambdaShadowedImplicitParameter") private fun registerListeners(container: InstanceContainer) { + val scheduleManager = MinecraftServer.getSchedulerManager() val spawn = Pos(.0, 45.0, .0) val extensionNode = MinecraftServer.getGlobalEventHandler() val lobbyNode = EventNode.all("lobby") @@ -150,7 +153,7 @@ class Bomberman { (it.target as NPC).onInteract(it) } - MinecraftServer.getPacketListenerManager().setPlayListener(ClientPlayerDiggingPacket::class.java) { packet: ClientPlayerDiggingPacket, player: Player -> + MinecraftServer.getPacketListenerManager().setPlayListener(ClientPlayerDiggingPacket::class.java) { packet, player -> val instance = player.instance if(player.gameMode != GameMode.ADVENTURE || packet.status != ClientPlayerDiggingPacket.Status.STARTED_DIGGING) return@setPlayListener PlayerDiggingListener.playerDiggingListener(packet, player) //logger.info("Digging") @@ -176,8 +179,26 @@ class Bomberman { } } removeBlockAt(tnt.position, tnt.instance) - tnt.teleport(lastPos) - setBlockAt(tnt.position, Block.BARRIER, tnt.instance) + //tnt.teleport(lastPos) + val lastAirBlock = tnt.position.sub(lastPos).addAll() + val oldY = tnt.position.y + val tickUpdate = 3 + val blockPerTicks = 1.0 / tickUpdate + var relativeX = 0.0 + scheduleManager.scheduleTask({ + if(tnt.instance == null) { + return@scheduleTask TaskSchedule.stop() + } + relativeX += blockPerTicks + if(abs(relativeX) >= abs(lastAirBlock)) { + setBlockAt(tnt.position, Block.BARRIER, tnt.instance) + return@scheduleTask TaskSchedule.stop() + } + val addX = if(packet.blockFace == BlockFace.EAST) -1.0 else if(packet.blockFace == BlockFace.WEST) 1.0 else 0.0 + val addZ = if(packet.blockFace == BlockFace.SOUTH) -1.0 else if(packet.blockFace == BlockFace.NORTH) 1.0 else 0.0 + tnt.teleport(tnt.position.add(addX * blockPerTicks, .0, addZ * blockPerTicks).withY(tnt.calculateNextY(relativeX, abs(lastAirBlock)) + oldY)) + return@scheduleTask TaskSchedule.nextTick() + }, TaskSchedule.immediate()) } gameNode.addListener(PickupItemEvent::class.java) { @@ -302,4 +323,5 @@ class Bomberman { } private fun Block.isAirOrBarrier() = this.isAir || this.compare(Block.BARRIER) + private fun Pos.addAll() = this.x + this.y + this.z } \ No newline at end of file diff --git a/src/main/kotlin/fr/sunderia/bomberman/party/Game.kt b/src/main/kotlin/fr/sunderia/bomberman/party/Game.kt index 12bdcef..adaafb1 100644 --- a/src/main/kotlin/fr/sunderia/bomberman/party/Game.kt +++ b/src/main/kotlin/fr/sunderia/bomberman/party/Game.kt @@ -69,7 +69,7 @@ data class Game(val instance: InstanceContainer, val scheduler: SchedulerManager powerMap.replaceAll { _: UUID, _: Int -> 2 } instance.players.forEach { p: Player -> p.clearEffects() - val uuids = p.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED).modifiers.stream() + val uuids = p.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED).modifiers().stream() .map { obj-> obj.id } .toList().toTypedArray() for (uuid in uuids) {