Skip to content

Commit

Permalink
Updated to 1.20.6
Browse files Browse the repository at this point in the history
  • Loading branch information
Minemobs committed Jun 8, 2024
1 parent fd486c3 commit 1f2ac66
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 53 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:19bb74e942")
implementation("net.minestom:minestom-snapshots:e17689902f")
implementation("commons-codec:commons-codec:1.16.1")
}

Expand Down
10 changes: 4 additions & 6 deletions src/main/java/fr/sunderia/bomberman/Powerup.java
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -36,8 +35,7 @@ public Consumer<Player> 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")
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/fr/sunderia/bomberman/PrimedTntEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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() {
Expand All @@ -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;
}
}
20 changes: 13 additions & 7 deletions src/main/kotlin/fr/sunderia/bomberman/Bomberman.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -71,13 +73,13 @@ class Bomberman {

companion object {
val powerMap = mutableMapOf<UUID, Int>()
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<DimensionType>
}

private fun createNPC(lobby: Instance) {
Expand All @@ -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)
Expand Down Expand Up @@ -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) {
Expand All @@ -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({
Expand Down
66 changes: 36 additions & 30 deletions src/main/kotlin/fr/sunderia/bomberman/InstanceCreator.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
}

Expand All @@ -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<BlockPos> = 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?> { 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<BlockPos>()
//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?> { 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
}
Expand Down
9 changes: 4 additions & 5 deletions src/main/kotlin/fr/sunderia/bomberman/party/Game.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit 1f2ac66

Please sign in to comment.