This repository has been archived by the owner on Jun 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use protocollib's built in converters where possible
- Loading branch information
Showing
11 changed files
with
190 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
version=0.9 | ||
version=0.10 | ||
group=com.mineinabyss | ||
idofrontVersion=0.22.3 | ||
publishComponentName=java |
2 changes: 2 additions & 0 deletions
2
protocolburrito-api/src/main/kotlin/com/mineinabyss/protocolburrito/FieldHelpers.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 5 additions & 1 deletion
6
protocolburrito-api/src/main/kotlin/com/mineinabyss/protocolburrito/WrappedPacket.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
package com.mineinabyss.protocolburrito | ||
|
||
interface WrappedPacket | ||
import com.comphenix.protocol.events.PacketContainer | ||
|
||
interface WrappedPacket { | ||
val container: PacketContainer | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
165 changes: 129 additions & 36 deletions
165
...olburrito-generator/src/main/kotlin/com/mineinabyss/protocolburrito/generation/TypeMap.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,140 @@ | ||
package com.mineinabyss.protocolburrito.generation | ||
|
||
import com.comphenix.protocol.events.PacketContainer | ||
import com.comphenix.protocol.reflect.StructureModifier | ||
import org.bukkit.entity.Entity | ||
import kotlin.reflect.KClass | ||
import kotlin.reflect.KFunction1 | ||
import com.squareup.kotlinpoet.* | ||
import com.squareup.kotlinpoet.MemberName.Companion.member | ||
import it.unimi.dsi.fastutil.objects.Object2IntMap | ||
import net.minecraft.stats.Stat | ||
import java.util.* | ||
import kotlin.reflect.* | ||
import kotlin.reflect.full.withNullability | ||
|
||
object TypeMap { | ||
class TypeInfo<T : Any>( | ||
val kClass: KClass<T>, | ||
val structureModified: KFunction1<PacketContainer, StructureModifier<T>> | ||
class TypeInfo( | ||
val type: TypeName, | ||
val structureModifierMember: MemberName | ||
// val structureModifier: KFunction1<PacketContainer, StructureModifier<T>> | ||
) | ||
|
||
inline fun <reified T : Any> get(function: KFunction1<PacketContainer, StructureModifier<T>>): TypeInfo<T> { | ||
return TypeInfo(T::class, function) | ||
// inline fun <reified T : Any> get(function: KFunction1<PacketContainer, StructureModifier<T>>): TypeInfo<T> { | ||
// return TypeInfo(T::class, function) | ||
// } | ||
// | ||
// val types = mapOf<String, TypeInfo>( | ||
// // Arrays | ||
// //TODO doesnt work because Array<String> gets type erased | ||
//// "java.lang.String[]" to get<Array<String>>(PacketContainer::getStringArrays), | ||
// "byte[]" to get<ByteArray>(PacketContainer::getByteArrays), | ||
// "int[]" to get<IntArray>(PacketContainer::getIntegerArrays), | ||
// "short[]" to get<ShortArray>(PacketContainer::getShortArrays), | ||
// "net.minecraft.world.entity.EntityType<?>" to get(PacketContainer::getEntityTypeModifier), | ||
// "net.minecraft.core.BlockPos" to get(PacketContainer::getBlockPositionModifier), | ||
// //TODO UNSURE | ||
// "net.minecraft.network.chat.Component" to get(PacketContainer::getChatComponents), | ||
// //TODO figure something out with this modifier, requires world parameter pass | ||
//// "net.minecraft.world.entity.Entity" to get(PacketContainer::getEntityModifier), | ||
// ) | ||
|
||
@OptIn(ExperimentalStdlibApi::class) | ||
fun getStructureModifier(type: KType): TypeInfo? { | ||
// val type = type.withNullability(false) | ||
// val singleArgument = type.arguments.singleOrNull()?.type?.withNullability(false) | ||
// if(singleArgument != null) { | ||
// val outerType = outerModifier[type.jvmErasure] | ||
// println("Working on $type with args ${type.arguments}, and erased ${type.jvmErasure}") | ||
// if (outerType != null) { | ||
// println(FunSpec.builder("test").addStatement("val test = %N", outerType).build()) | ||
// } | ||
// | ||
// leafModifier[singleArgument] | ||
// | ||
// println("Got type $outerType") | ||
// } | ||
val modifier = mappedLeafModifiers[type.javaType] ?: return null | ||
val structureModifierName = modifier.name | ||
val fieldType = modifier.returnType.arguments.single().type!!.asTypeName() | ||
|
||
return TypeInfo(fieldType, packetContainer.member(structureModifierName)) | ||
} | ||
|
||
val types = mapOf<String, TypeInfo<*>>( | ||
"byte" to get(PacketContainer::getBytes), | ||
"boolean" to get(PacketContainer::getBooleans), | ||
"short" to get(PacketContainer::getShorts), | ||
"int" to get(PacketContainer::getIntegers), | ||
"long" to get(PacketContainer::getLongs), | ||
"float" to get(PacketContainer::getFloat), | ||
"double" to get(PacketContainer::getDoubles), | ||
"java.lang.String" to get(PacketContainer::getStrings), | ||
"java.util.UUID" to get(PacketContainer::getUUIDs), | ||
//TODO doesnt work because Array<String> gets type erased | ||
// "java.lang.String[]" to get<Array<String>>(PacketContainer::getStringArrays), | ||
"byte[]" to get<ByteArray>(PacketContainer::getByteArrays), | ||
"int[]" to get<IntArray>(PacketContainer::getIntegerArrays), | ||
"short[]" to get<ShortArray>(PacketContainer::getShortArrays), | ||
// "" to get(PacketContainer::getItemModifier), | ||
// "" to get(PacketContainer::getItemArrayModifier), | ||
// "" to get(PacketContainer::getItemListModifier), | ||
// "" to get(PacketContainer::getStatisticMaps), | ||
// "" to get(PacketContainer::getWorldTypeModifier), | ||
// "" to get(PacketContainer::getDataWatcherModifier), | ||
"net.minecraft.world.entity.EntityType" to get(PacketContainer::getEntityTypeModifier), | ||
"net.minecraft.core.BlockPos" to get(PacketContainer::getBlockPositionModifier), | ||
//TODO UNSURE | ||
"net.minecraft.network.chat.Component" to get(PacketContainer::getChatComponents), | ||
//TODO figure something out with this modifier, requires world parameter pass | ||
// "net.minecraft.world.entity.Entity" to get(PacketContainer::getEntityModifier), | ||
val packetContainer = PacketContainer::class.asClassName() | ||
|
||
val outerModifier = mapOf<KClass<*>, MemberName>( | ||
List::class to packetContainer.member("lists"), | ||
// Optional::class to PacketContainer::getOptionals, | ||
) | ||
|
||
private val leafModifier = mapOf<KType, KFunction<*>>( | ||
// Primitives | ||
typeOf<Byte>() to PacketContainer::getIntegers, | ||
typeOf<Boolean>() to PacketContainer::getBooleans, | ||
typeOf<Short>() to PacketContainer::getShorts, | ||
typeOf<Int>() to PacketContainer::getIntegers, | ||
typeOf<Long>() to PacketContainer::getLongs, | ||
typeOf<Float>() to PacketContainer::getFloat, | ||
typeOf<Double>() to PacketContainer::getDoubles, | ||
typeOf<String>() to PacketContainer::getStrings, | ||
typeOf<UUID>() to PacketContainer::getUUIDs, | ||
typeOf<Array<String>>() to PacketContainer::getStringArrays, | ||
typeOf<ByteArray>() to PacketContainer::getByteArrays, | ||
typeOf<IntArray>() to PacketContainer::getIntegerArrays, | ||
typeOf<ShortArray>() to PacketContainer::getShortArrays, | ||
typeOf<net.minecraft.world.item.ItemStack>() to PacketContainer::getItemModifier, | ||
typeOf<Array<net.minecraft.world.item.ItemStack>>() to PacketContainer::getItemArrayModifier, | ||
typeOf<List<net.minecraft.world.item.ItemStack>>() to PacketContainer::getItemListModifier, | ||
typeOf<Object2IntMap<Stat<*>>>() to PacketContainer::getStatisticMaps, | ||
// typeOf<net.minecraft.world.level.GameType>() to PacketContainer::getWorldTypeModifier, | ||
typeOf<net.minecraft.network.syncher.SynchedEntityData>() to PacketContainer::getDataWatcherModifier, | ||
typeOf<net.minecraft.world.entity.EntityType<*>>() to PacketContainer::getEntityTypeModifier, | ||
typeOf<net.minecraft.core.BlockPos>() to PacketContainer::getBlockPositionModifier, | ||
typeOf<net.minecraft.world.level.block.entity.BlockEntityType<*>>() to PacketContainer::getBlockEntityTypeModifier, | ||
// TODO getChunkCoordIntPairs | ||
typeOf<net.minecraft.nbt.CompoundTag>() to PacketContainer::getNbtModifier, | ||
typeOf<List<net.minecraft.nbt.CompoundTag>>() to PacketContainer::getListNbtModifier, | ||
typeOf<net.minecraft.world.phys.Vec3>() to PacketContainer::getVectors, | ||
typeOf<List<net.minecraft.network.protocol.game.ClientboundUpdateAttributesPacket.AttributeSnapshot>>() to PacketContainer::getAttributeCollectionModifier, | ||
typeOf<List<net.minecraft.core.BlockPos>>() to PacketContainer::getBlockPositionCollectionModifier, | ||
typeOf<List<net.minecraft.network.syncher.SynchedEntityData.DataItem<*>>>() to PacketContainer::getWatchableCollectionModifier, | ||
typeOf<List<net.minecraft.network.syncher.SynchedEntityData.DataValue<*>>>() to PacketContainer::getDataValueCollectionModifier, | ||
// blocks | ||
typeOf<net.minecraft.world.level.block.Block>() to PacketContainer::getBlocks, | ||
typeOf<net.minecraft.world.level.block.state.BlockState>() to PacketContainer::getBlockData, | ||
typeOf<Array<net.minecraft.world.level.block.state.BlockState>>() to PacketContainer::getBlockDataArrays, | ||
//getMultiBlockChangeInfoArrays | ||
typeOf<net.minecraft.network.chat.Component>() to PacketContainer::getChatComponents, | ||
typeOf<Array<net.minecraft.network.chat.Component>>() to PacketContainer::getChatComponentArrays, | ||
// getServerPings | ||
// getPlayerInfoDataLists | ||
// getProtocols | ||
// getClientCommands | ||
// getChatVisibilities | ||
typeOf<net.minecraft.world.Difficulty>() to PacketContainer::getDifficulties, | ||
// getEntityUseActions | ||
// getEnumEntityUseActions | ||
// getGameModes | ||
// getResourcePackStatus | ||
// getPlayerInfoAction | ||
// getPlayerInfoActions | ||
// getTitleActions | ||
// getWorldBorderActions | ||
// getCombatEvents | ||
// getPlayerDigTypes | ||
// getPlayerActions | ||
// getScoreboardActions | ||
// getParticles | ||
// getNewParticles | ||
// getEffectTypes | ||
// getSoundCategories | ||
// ... | ||
typeOf<net.minecraft.world.InteractionHand>() to PacketContainer::getHands, | ||
typeOf<net.minecraft.core.Direction>() to PacketContainer::getDirections, | ||
typeOf<net.minecraft.network.chat.ChatType.BoundNetwork>() to PacketContainer::getChatTypes, | ||
typeOf<net.minecraft.resources.ResourceLocation>() to PacketContainer::getMinecraftKeys, | ||
// getDimensions | ||
typeOf<net.minecraft.world.level.dimension.DimensionType>() to PacketContainer::getDimensionTypes, | ||
// getMerchantRecipeLists | ||
// ... | ||
) | ||
@OptIn(ExperimentalStdlibApi::class) | ||
private val mappedLeafModifiers = leafModifier.mapKeys { it.key.javaType } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,4 @@ dependencies: | |
ProtocolLib: | ||
required: true | ||
load: BEFORE | ||
join-classpath: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters