From 1f2ac66463c40c659b7f542f7bc4292b89f0f25f Mon Sep 17 00:00:00 2001 From: minemobs Date: Sat, 8 Jun 2024 21:43:44 +0200 Subject: [PATCH] Updated to 1.20.6 --- build.gradle.kts | 2 +- .../java/fr/sunderia/bomberman/Powerup.java | 10 ++- .../sunderia/bomberman/PrimedTntEntity.java | 9 +-- .../kotlin/fr/sunderia/bomberman/Bomberman.kt | 20 ++++-- .../fr/sunderia/bomberman/InstanceCreator.kt | 66 ++++++++++--------- .../fr/sunderia/bomberman/party/Game.kt | 9 ++- 6 files changed, 63 insertions(+), 53 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index a2d71e0..bc9af6e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -14,7 +14,7 @@ repositories { } dependencies { - implementation("net.minestom:minestom-snapshots:19bb74e942") + implementation("net.minestom:minestom-snapshots:e17689902f") implementation("commons-codec:commons-codec:1.16.1") } diff --git a/src/main/java/fr/sunderia/bomberman/Powerup.java b/src/main/java/fr/sunderia/bomberman/Powerup.java index 8e2b812..1d9514f 100644 --- a/src/main/java/fr/sunderia/bomberman/Powerup.java +++ b/src/main/java/fr/sunderia/bomberman/Powerup.java @@ -1,11 +1,10 @@ package fr.sunderia.bomberman; import fr.sunderia.bomberman.utils.PowerupTags; -import net.minestom.server.attribute.Attribute; -import net.minestom.server.attribute.AttributeInstance; -import net.minestom.server.attribute.AttributeModifier; -import net.minestom.server.attribute.AttributeOperation; import net.minestom.server.entity.Player; +import net.minestom.server.entity.attribute.Attribute; +import net.minestom.server.entity.attribute.AttributeModifier; +import net.minestom.server.entity.attribute.AttributeOperation; import java.util.function.Consumer; @@ -36,8 +35,7 @@ public Consumer getEffect() { } private static void incrementSpeed(Player player, float amount) { - AttributeInstance currentAttribute = player.getAttribute(Attribute.MOVEMENT_SPEED); - currentAttribute.addModifier(new AttributeModifier("speed", amount, AttributeOperation.ADDITION)); + player.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED).addModifier(new AttributeModifier("speed", amount, AttributeOperation.ADD_VALUE)); } @SuppressWarnings("DataFlowIssue") diff --git a/src/main/java/fr/sunderia/bomberman/PrimedTntEntity.java b/src/main/java/fr/sunderia/bomberman/PrimedTntEntity.java index a4334fe..7450070 100644 --- a/src/main/java/fr/sunderia/bomberman/PrimedTntEntity.java +++ b/src/main/java/fr/sunderia/bomberman/PrimedTntEntity.java @@ -10,6 +10,7 @@ import net.minestom.server.entity.*; import net.minestom.server.instance.Instance; import net.minestom.server.instance.block.Block; +import net.minestom.server.item.ItemComponent; import net.minestom.server.item.ItemStack; import net.minestom.server.item.Material; import net.minestom.server.network.packet.server.play.ParticlePacket; @@ -86,8 +87,8 @@ private void dropPowerup(Pos pos) { return; int index = Random.Default.nextInt(Powerup.values().length); Powerup powerup = Powerup.values()[index]; - ItemStack is = ItemStack.of(Material.NAUTILUS_SHELL).withMeta(meta -> meta.customModelData(index + 1) - .displayName(Component.text(powerup.name().replace("_", " ").toLowerCase()))); + ItemStack is = ItemStack.of(Material.NAUTILUS_SHELL).with(meta -> meta.set(ItemComponent.CUSTOM_MODEL_DATA, index + 1) + .set(ItemComponent.ITEM_NAME, Component.text(powerup.name().replace("_", " ").toLowerCase()))); ItemEntity item = new ItemEntity(is); item.setInstance(getInstance(), pos); } @@ -118,7 +119,7 @@ public void update(long time) { explode(); getInstance().setBlock(this.position, Block.AIR); remove(); - if(pierceTeam.getMembers().contains(this.uuid.toString())) pierceTeam.removeMember(this.uuid.toString()); + if(pierceTeam.getMembers().contains(this.getUuid().toString())) pierceTeam.removeMember(this.getUuid().toString()); } public boolean isAPierceBomb() { @@ -127,7 +128,7 @@ public boolean isAPierceBomb() { public void setPierce(boolean pierce) { this.setGlowing(true); - pierceTeam.addMember(this.uuid.toString()); + pierceTeam.addMember(this.getUuid().toString()); this.pierce = pierce; } } diff --git a/src/main/kotlin/fr/sunderia/bomberman/Bomberman.kt b/src/main/kotlin/fr/sunderia/bomberman/Bomberman.kt index dc5a7c7..622ccf1 100644 --- a/src/main/kotlin/fr/sunderia/bomberman/Bomberman.kt +++ b/src/main/kotlin/fr/sunderia/bomberman/Bomberman.kt @@ -1,7 +1,5 @@ package fr.sunderia.bomberman -import com.google.gson.Gson -import com.google.gson.GsonBuilder import fr.sunderia.bomberman.InstanceCreator.Companion.createInstanceContainer import fr.sunderia.bomberman.party.Game import fr.sunderia.bomberman.party.GameCommand @@ -35,13 +33,17 @@ import net.minestom.server.instance.Instance import net.minestom.server.instance.InstanceContainer import net.minestom.server.instance.block.Block import net.minestom.server.instance.block.BlockFace +import net.minestom.server.instance.block.predicate.BlockPredicate +import net.minestom.server.item.ItemComponent import net.minestom.server.item.ItemStack import net.minestom.server.item.Material +import net.minestom.server.item.component.BlockPredicates import net.minestom.server.listener.PlayerDiggingListener import net.minestom.server.network.NetworkBuffer import net.minestom.server.network.packet.client.play.ClientPlayerDiggingPacket import net.minestom.server.network.packet.server.play.ChangeGameStatePacket import net.minestom.server.network.packet.server.play.SetCooldownPacket +import net.minestom.server.registry.DynamicRegistry import net.minestom.server.scoreboard.TeamBuilder import net.minestom.server.tag.Tag import net.minestom.server.timer.TaskSchedule @@ -71,13 +73,13 @@ class Bomberman { companion object { val powerMap = mutableMapOf() - val gson: Gson = GsonBuilder().create() val logger: Logger = Logger.getLogger("Bomberman") private lateinit var lobbyInstance: Instance fun getLobbyInstance(): Instance { return lobbyInstance } - val fullBright: DimensionType = DimensionType.builder(NamespaceID.from("sunderia:full_bright")).ambientLight(2.0f).build() + val fullBrightType = DimensionType.builder(NamespaceID.from("sunderia:full_bright")).ambientLight(2.0f).build() + lateinit var fullbright: DynamicRegistry.Key } private fun createNPC(lobby: Instance) { @@ -88,7 +90,7 @@ class Bomberman { fun initialize() { val manager = MinecraftServer.getInstanceManager() - MinecraftServer.getDimensionTypeManager().addDimension(fullBright) + fullbright = MinecraftServer.getDimensionTypeRegistry().register(fullBrightType) val lobbyContainer: InstanceContainer = createInstanceContainer(manager) lobbyInstance = lobbyContainer createNPC(lobbyContainer) @@ -186,7 +188,7 @@ class Bomberman { it.isCancelled = true return@addListener } - Powerup.entries[it.itemStack.meta().customModelData - 1].effect.accept(player) + Powerup.entries[it.itemStack.get(ItemComponent.CUSTOM_MODEL_DATA)!! - 1].effect.accept(player) } gameNode.addListener(PlayerSpawnEvent::class.java) { @@ -209,7 +211,11 @@ class Bomberman { ) } if(!it.spawnInstance.hasTag(Tag.Boolean("game"))) return@addListener - player.inventory.addItemStack(ItemStack.of(Material.TNT).withMeta { it.canPlaceOn(Block.STONE, Block.BRICKS).canDestroy(Block.BARRIER).build() } ) + player.inventory.addItemStack(ItemStack.of(Material.TNT).with { + it + .set(ItemComponent.CAN_PLACE_ON, BlockPredicates(listOf(BlockPredicate(Block.STONE, Block.BRICKS)))) + .set(ItemComponent.CAN_BREAK, BlockPredicates(listOf(BlockPredicate(Block.BARRIER)))).build() + } ) powerMap[player.uuid] = 2 player.scheduler().scheduleTask({ diff --git a/src/main/kotlin/fr/sunderia/bomberman/InstanceCreator.kt b/src/main/kotlin/fr/sunderia/bomberman/InstanceCreator.kt index 5f8f526..9fc72de 100644 --- a/src/main/kotlin/fr/sunderia/bomberman/InstanceCreator.kt +++ b/src/main/kotlin/fr/sunderia/bomberman/InstanceCreator.kt @@ -1,9 +1,10 @@ package fr.sunderia.bomberman -import com.google.gson.JsonObject import fr.sunderia.bomberman.utils.BlockPos import fr.sunderia.bomberman.utils.Structure import it.unimi.dsi.fastutil.longs.Long2ObjectMap +import net.kyori.adventure.nbt.BinaryTagIO +import net.kyori.adventure.nbt.CompoundBinaryTag import net.minestom.server.coordinate.Pos import net.minestom.server.coordinate.Vec import net.minestom.server.instance.Instance @@ -12,18 +13,15 @@ import net.minestom.server.instance.InstanceManager import net.minestom.server.instance.batch.AbsoluteBlockBatch import net.minestom.server.instance.block.Block import net.minestom.server.utils.chunk.ChunkUtils -import org.jglrxavpok.hephaistos.nbt.NBTException -import org.jglrxavpok.hephaistos.nbt.NBTReader import java.io.IOException -import java.util.* import java.util.stream.IntStream import kotlin.random.Random class InstanceCreator { companion object { fun createInstanceContainer(manager: InstanceManager): InstanceContainer { - val container = manager.createInstanceContainer(Bomberman.fullBright) - container.setGenerator { unit -> unit.modifier().fillHeight(0, 40, Block.STONE) } + val container = manager.createInstanceContainer(Bomberman.fullbright) + container.setGenerator { it.modifier().fillHeight(0, 40, Block.STONE) } return container } @@ -42,41 +40,49 @@ class InstanceCreator { } getAffectedChunks(batch).let { ChunkUtils.optionalLoadAll(container, it, null) - .thenRun { batch.apply(container) { batch.clear() } } + .thenRun { batch.apply(container) { batch.clear() } } } } private fun parseNBT(): Structure? { try { Bomberman::class.java.getResourceAsStream("/bomberman.nbt").use { stream -> - NBTReader(stream!!).use { reader -> - val structure: MutableList = LinkedList() - val nbt = Bomberman.gson.fromJson(reader.read().toSNBT(), JsonObject::class.java) - val palettes = nbt.getAsJsonArray("palette") - val palette = - IntStream.range(0, palettes.size()) - .mapToObj { palettes[it] } - .map { it.asJsonObject } - .map { it.getAsJsonPrimitive("Name").asString } - .map { Block.fromNamespaceId(it) }.toList().toTypedArray() - val blockArray = nbt.getAsJsonArray("blocks") - blockArray.forEach { - val blockObj = it.asJsonObject - val jsonPos = blockObj.getAsJsonArray("pos") - structure.add( - BlockPos(Vec(jsonPos[0].asInt.toDouble(), jsonPos[1].asInt.toDouble(), jsonPos[2].asInt.toDouble()), palette[blockObj["state"].asInt]) + val reader = BinaryTagIO.unlimitedReader().read(stream!!, BinaryTagIO.Compression.GZIP) + val structure = mutableListOf() + //val nbt = Bomberman.gson.fromJson(reader.getList(), JsonObject::class.java) + val palettes = reader.getList("palette") + val palette = + IntStream.range(0, palettes.size()) + .mapToObj { palettes.getCompound(it) } + .map { it.getString("Name") } + .map { Block.fromNamespaceId(it) }.toList().toTypedArray() + val blockArray = reader.getList("blocks") + blockArray.forEach { + val blockObj = it.asBinaryTag() as CompoundBinaryTag + val jsonPos = blockObj.getList("pos") + structure.add( + BlockPos( + Vec( + jsonPos.getInt(0).toDouble(), + jsonPos.getInt(1).toDouble(), + jsonPos.getInt(2).toDouble() + ), palette[blockObj.getInt("state")] ) - } - val size = IntArray(3) - val jsonSize = nbt.getAsJsonArray("size") - for (i in 0..2) size[i] = jsonSize[i].asInt - return Structure(Vec(jsonSize[0].asInt.toDouble(), jsonSize[1].asInt.toDouble(), jsonSize[2].asInt.toDouble()), structure) + ) } + val size = IntArray(3) + val jsonSize = reader.getList("size") + for (i in 0..2) size[i] = jsonSize.getInt(i) + return Structure( + Vec( + jsonSize.getInt(0).toDouble(), + jsonSize.getInt(1).toDouble(), + jsonSize.getInt(2).toDouble() + ), structure + ) } } catch (e: IOException) { e.printStackTrace() - } catch (e: NBTException) { - e.printStackTrace() } return null } diff --git a/src/main/kotlin/fr/sunderia/bomberman/party/Game.kt b/src/main/kotlin/fr/sunderia/bomberman/party/Game.kt index a0c7821..12bdcef 100644 --- a/src/main/kotlin/fr/sunderia/bomberman/party/Game.kt +++ b/src/main/kotlin/fr/sunderia/bomberman/party/Game.kt @@ -8,11 +8,10 @@ import fr.sunderia.bomberman.utils.PowerupTags import net.kyori.adventure.text.Component.text import net.kyori.adventure.text.format.NamedTextColor import net.minestom.server.MinecraftServer -import net.minestom.server.attribute.Attribute -import net.minestom.server.attribute.AttributeModifier import net.minestom.server.entity.Entity import net.minestom.server.entity.EntityType import net.minestom.server.entity.Player +import net.minestom.server.entity.attribute.Attribute import net.minestom.server.instance.Instance import net.minestom.server.instance.InstanceContainer import net.minestom.server.instance.InstanceManager @@ -70,11 +69,11 @@ 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.MOVEMENT_SPEED).modifiers.stream() - .map { obj: AttributeModifier -> obj.id } + val uuids = p.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED).modifiers.stream() + .map { obj-> obj.id } .toList().toTypedArray() for (uuid in uuids) { - p.getAttribute(Attribute.MOVEMENT_SPEED).removeModifier(uuid!!) + p.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED).removeModifier(uuid!!) } PowerupTags.entries.forEach { p.removeTag(it.getBool())