Skip to content

Commit

Permalink
Added relatively good tnt throw (fix #9)
Browse files Browse the repository at this point in the history
  • Loading branch information
Minemobs committed Jul 17, 2024
1 parent 1f2ac66 commit f0c5333
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 8 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions src/main/java/fr/sunderia/bomberman/PrimedTntEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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);
}

Expand Down
32 changes: 27 additions & 5 deletions src/main/kotlin/fr/sunderia/bomberman/Bomberman.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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<DimensionType>
}

Expand All @@ -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)
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand All @@ -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) {
Expand Down Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion src/main/kotlin/fr/sunderia/bomberman/party/Game.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit f0c5333

Please sign in to comment.