Skip to content

Commit

Permalink
Sorta works?
Browse files Browse the repository at this point in the history
  • Loading branch information
Seggan committed Aug 19, 2024
1 parent 532e098 commit d1370a5
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 47 deletions.
1 change: 1 addition & 0 deletions plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ tasks.shadowJar {
relocate(from, "io.github.addoncommunity.galactifun.shadowlibs.$last")
}

mergeServiceFiles()
// Relocate if true or not set, always relocate bstats
doRelocate("org.bstats")
if (System.getenv("RELOCATE") != "false") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ open class Galactifun2 : AbstractAddon() {
Material.RED_SAND top 2

fillInRestWith(random {
Material.RED_SANDSTONE withWeight 0.8f
Material.IRON_ORE withWeight 0.2f
Material.RED_SANDSTONE withWeight 80f
Material.IRON_ORE withWeight 20f
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import io.github.addoncommunity.galactifun.impl.items.abstract.Seat
import io.github.addoncommunity.galactifun.impl.managers.PlanetManager
import io.github.addoncommunity.galactifun.impl.managers.RocketManager
import io.github.addoncommunity.galactifun.pluginInstance
import io.github.addoncommunity.galactifun.units.Acceleration.Companion.metersPerSecondSquared
import io.github.addoncommunity.galactifun.units.Velocity.Companion.metersPerSecond
import io.github.addoncommunity.galactifun.units.abs
import io.github.addoncommunity.galactifun.units.div
import io.github.addoncommunity.galactifun.units.times
import io.github.addoncommunity.galactifun.units.unitSumOf
import io.github.addoncommunity.galactifun.util.*
Expand All @@ -30,9 +30,7 @@ import io.github.thebusybiscuit.slimefun4.core.handlers.BlockPlaceHandler
import io.github.thebusybiscuit.slimefun4.core.handlers.BlockUseHandler
import io.github.thebusybiscuit.slimefun4.libraries.dough.blocks.BlockPosition
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap
import kotlinx.coroutines.Job
import kotlinx.coroutines.future.await
import kotlinx.coroutines.joinAll
import me.mrCookieSlime.Slimefun.api.BlockStorage
import net.kyori.adventure.text.format.NamedTextColor
import org.bukkit.Location
Expand Down Expand Up @@ -215,38 +213,30 @@ class CommandComputer(
}
launched.set(true)

val movingEntities = entities.filter { it.vehicle == null }
val offsets = movingEntities.associateWith { it.location.subtract(pos.toLocation()) }
val offsets = entities.associateWith { it.location.subtract(pos.toLocation()) }
val maxHeight = world.maxHeight
var position = pos.y.toDouble()

val weight = rocket.wetMass * currentPlanet.gravity
val netForce = firstStage.engines.unitSumOf { it.first.thrust } - weight
val acceleration = netForce / rocket.wetMass
val acceleration = 0.5.metersPerSecondSquared
val marginalAcceleration = acceleration * 0.05.seconds
var speed = 0.0.metersPerSecond
while (position < maxHeight) {
for (entity in movingEntities) {
entity.galactifunTeleport(entity.location.add(0.0, (speed / 20).metersPerSecond, 0.0))
speed += marginalAcceleration
position = max(position, entity.location.y)
}
delayTicks(1)
}

val jobs = mutableListOf<Job>()
for (entity in movingEntities) {
jobs += pluginInstance.launch {
for (entity in entities) {
entity.galactifunTeleport(
dest.copy(world = PlanetManager.spaceWorld) + offsets[entity]!!
entity.location.add(0.0, (speed / 20).metersPerSecond, 0.0)
).await()
unfreezeEntity(entity)
position = max(position, entity.location.y)
}
speed += marginalAcceleration
delayTicks(1)
}
jobs.joinAll()

for (entity in entities) {
if (!entity.isValid || entity in movingEntities) continue
entity.galactifunTeleport(
dest + offsets[entity]!!.copy(world = PlanetManager.spaceWorld)
).await()
unfreezeEntity(entity)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.addoncommunity.galactifun.util.bukkit

import io.github.addoncommunity.galactifun.pluginInstance
import io.papermc.paper.entity.TeleportFlag.EntityState
import net.kyori.adventure.text.Component
import net.kyori.adventure.text.TextComponent
import net.kyori.adventure.text.format.TextColor
Expand Down Expand Up @@ -51,32 +52,17 @@ operator fun RegionAccessor.set(location: Location, material: Material) = setTyp
*/
fun Entity.galactifunTeleport(
dest: Location,
preservePassengers: Boolean = true,
reason: PlayerTeleportEvent.TeleportCause = PlayerTeleportEvent.TeleportCause.PLUGIN
): CompletableFuture<Boolean> {
if (preservePassengers && passengers.isNotEmpty()) {
val futures = mutableListOf<CompletableFuture<Boolean>>()
val passengers = this.passengers
for (passenger in passengers) {
removePassenger(passenger)
futures += passenger.galactifunTeleport(dest, true, reason)
}
var future = galactifunTeleport(dest, false, reason)
for (passengerFuture in futures) {
future = future.thenCombine(passengerFuture) { a, b -> a && b }
}
return future.thenApply {
if (it) {
passengers.forEach(::addPassenger)
}
it
}
} else {
setMetadata("galactifun.teleporting", DummyMetadataValue)
return teleportAsync(dest, reason).thenApply {
removeMetadata("galactifun.teleporting", pluginInstance)
it
}
setMetadata("galactifun.teleporting", DummyMetadataValue)
return teleportAsync(
dest,
reason,
EntityState.RETAIN_VEHICLE,
EntityState.RETAIN_PASSENGERS
).thenApply {
removeMetadata("galactifun.teleporting", pluginInstance)
it
}
}

Expand Down

0 comments on commit d1370a5

Please sign in to comment.