Skip to content

Commit 5029538

Browse files
Merge pull request #12 from SLNE-Development/feat/9-improve-skin-handling
Feat/9 improve skin handling
2 parents bf8e7a9 + 7937bd7 commit 5029538

File tree

18 files changed

+121
-79
lines changed

18 files changed

+121
-79
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
kotlin.code.style=official
22
kotlin.stdlib.default.dependency=false
33
org.gradle.parallel=true
4-
version=1.21.7-1.2.1-SNAPSHOT
4+
version=1.21.7-1.3.0-SNAPSHOT

surf-npc-api/src/main/kotlin/dev/slne/surf/npc/api/SurfNpcApi.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ import dev.slne.surf.npc.api.npc.property.NpcPropertyType
88
import dev.slne.surf.npc.api.npc.rotation.NpcRotation
99
import dev.slne.surf.npc.api.npc.rotation.NpcRotationType
1010
import dev.slne.surf.npc.api.npc.skin.NpcSkin
11+
import dev.slne.surf.npc.api.npc.skin.NpcSkinPart
1112
import dev.slne.surf.npc.api.result.NpcCreationResult
1213
import dev.slne.surf.npc.api.result.NpcDeletionResult
14+
import dev.slne.surf.surfapi.core.api.util.objectSetOf
1315
import dev.slne.surf.surfapi.core.api.util.requiredService
1416
import it.unimi.dsi.fastutil.objects.ObjectList
1517
import it.unimi.dsi.fastutil.objects.ObjectSet
@@ -197,7 +199,8 @@ interface SurfNpcApi {
197199
fun createSkinData(
198200
owner: String,
199201
value: String,
200-
signature: String
202+
signature: String,
203+
parts: ObjectSet<NpcSkinPart> = objectSetOf(NpcSkinPart.entries)
201204
): NpcSkin
202205

203206
/**

surf-npc-api/src/main/kotlin/dev/slne/surf/npc/api/dsl/NpcDslSubBuilders.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ import dev.slne.surf.npc.api.npc.property.NpcProperty
55
import dev.slne.surf.npc.api.npc.property.NpcPropertyType
66
import dev.slne.surf.npc.api.npc.rotation.NpcRotation
77
import dev.slne.surf.npc.api.npc.skin.NpcSkin
8+
import dev.slne.surf.npc.api.npc.skin.NpcSkinPart
89
import dev.slne.surf.npc.api.surfNpcApi
10+
import dev.slne.surf.surfapi.core.api.util.objectSetOf
11+
import dev.slne.surf.surfapi.core.api.util.toObjectSet
12+
import it.unimi.dsi.fastutil.objects.ObjectSet
913

1014
/**
1115
* Builder class for creating NPC skins.
@@ -26,6 +30,11 @@ class SkinBuilder {
2630
*/
2731
lateinit var signature: String
2832

33+
/**
34+
* The parts of the skin, represented as a set of `NpcSkinPart`.
35+
*/
36+
var parts: ObjectSet<NpcSkinPart> = NpcSkinPart.entries.toObjectSet()
37+
2938
/**
3039
* Builds the NPC skin.
3140
*
@@ -35,6 +44,7 @@ class SkinBuilder {
3544
override val ownerName = this@SkinBuilder.ownerName
3645
override val value = this@SkinBuilder.value
3746
override val signature = this@SkinBuilder.signature
47+
override val parts = this@SkinBuilder.parts
3848
}
3949
}
4050

surf-npc-api/src/main/kotlin/dev/slne/surf/npc/api/npc/property/NpcProperty.kt

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,9 @@ interface NpcProperty {
1919
const val DISPLAYNAME = "displayname"
2020

2121
/**
22-
* The owner of the NPC's skin.
22+
* The skin data of the NPC.
2323
*/
24-
const val SKIN_OWNER = "skin_owner"
25-
26-
/**
27-
* The texture of the NPC's skin.
28-
*/
29-
const val SKIN_TEXTURE = "skin_texture"
30-
31-
/**
32-
* The signature of the NPC's skin.
33-
*/
34-
const val SKIN_SIGNATURE = "skin_signature"
24+
const val SKIN_DATA = "skin_data"
3525

3626
/**
3727
* The location of the NPC.

surf-npc-api/src/main/kotlin/dev/slne/surf/npc/api/npc/property/NpcPropertyType.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,10 @@ interface NpcPropertyType {
8383
* Represents a rotation property type for an NPC.
8484
*/
8585
const val NPC_ROTATION = "npc_rotation"
86+
87+
/**
88+
* Represents a skin data property type for an NPC.
89+
*/
90+
const val SKIN_DATA = "skin_data"
8691
}
8792
}

surf-npc-api/src/main/kotlin/dev/slne/surf/npc/api/npc/skin/NpcSkin.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package dev.slne.surf.npc.api.npc.skin
22

3+
import it.unimi.dsi.fastutil.objects.ObjectSet
4+
35
/**
46
* Data class representing the skin data of an NPC.
57
*
@@ -10,4 +12,17 @@ interface NpcSkin {
1012
val ownerName: String
1113
val value: String
1214
val signature: String
15+
val parts: ObjectSet<NpcSkinPart>
16+
17+
fun skinByte(): Byte {
18+
var skinByte = 0
19+
if (NpcSkinPart.CAPE in parts) skinByte = skinByte or 0x01
20+
if (NpcSkinPart.JACKET in parts) skinByte = skinByte or 0x02
21+
if (NpcSkinPart.LEFT_SLEEVES in parts) skinByte = skinByte or 0x04
22+
if (NpcSkinPart.RIGHT_SLEEVES in parts) skinByte = skinByte or 0x08
23+
if (NpcSkinPart.LEFT_PANTS_LEG in parts) skinByte = skinByte or 0x10
24+
if (NpcSkinPart.RIGHT_PANTS_LEG in parts) skinByte = skinByte or 0x20
25+
if (NpcSkinPart.HAT in parts) skinByte = skinByte or 0x40
26+
return skinByte.toByte()
27+
}
1328
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package dev.slne.surf.npc.api.npc.skin
2+
3+
enum class NpcSkinPart {
4+
HAT,
5+
JACKET,
6+
LEFT_SLEEVES,
7+
RIGHT_SLEEVES,
8+
LEFT_PANTS_LEG,
9+
RIGHT_PANTS_LEG,
10+
CAPE;
11+
}

surf-npc-bukkit/src/main/kotlin/dev/slne/surf/npc/bukkit/BukkitMain.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class BukkitMain : SuspendingJavaPlugin() {
3232
propertyTypeRegistry.register(UuidPropertyType(NpcPropertyType.Types.UUID))
3333
propertyTypeRegistry.register(NamedTextColorPropertyType(NpcPropertyType.Types.NAMED_TEXT_COLOR))
3434
propertyTypeRegistry.register(NpcRotationPropertyType(NpcPropertyType.Types.NPC_ROTATION))
35+
propertyTypeRegistry.register(SkinDataPropertyType(NpcPropertyType.Types.SKIN_DATA))
3536

3637
storageService.initialize()
3738
storageService.loadNpcs()

surf-npc-bukkit/src/main/kotlin/dev/slne/surf/npc/bukkit/BukkitPackets.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ fun createPlayerInfoPacket(profile: UserProfile, displayName: Component, listed:
2727
)
2828
)
2929

30-
fun createEntityMetadataPacket(npcEntityId: Int) = WrapperPlayServerEntityMetadata(
30+
fun createEntityMetadataPacket(npcEntityId: Int, skinParts: Byte = 0x7F.toByte()) = WrapperPlayServerEntityMetadata(
3131
npcEntityId,
3232
listOf(
33-
EntityData(17, EntityDataTypes.BYTE, 0x7F.toByte()),
33+
EntityData(17, EntityDataTypes.BYTE, skinParts),
3434
EntityData(0, EntityDataTypes.BYTE, 0x02.toByte()),
3535
)
3636
)

surf-npc-bukkit/src/main/kotlin/dev/slne/surf/npc/bukkit/api/BukkitSurfNpcApi.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ import dev.slne.surf.npc.api.npc.property.NpcPropertyType
1010
import dev.slne.surf.npc.api.npc.rotation.NpcRotation
1111
import dev.slne.surf.npc.api.npc.rotation.NpcRotationType
1212
import dev.slne.surf.npc.api.npc.skin.NpcSkin
13+
import dev.slne.surf.npc.api.npc.skin.NpcSkinPart
1314
import dev.slne.surf.npc.api.result.NpcCreationResult
1415
import dev.slne.surf.npc.api.result.NpcDeletionResult
1516
import dev.slne.surf.npc.bukkit.npc.location.BukkitNpcLocation
1617
import dev.slne.surf.npc.bukkit.npc.property.BukkitNpcProperty
1718
import dev.slne.surf.npc.bukkit.npc.rotation.BukkitNpcRotation
18-
import dev.slne.surf.npc.bukkit.npc.skin.BukkitSNpcSkinData
19+
import dev.slne.surf.npc.bukkit.npc.skin.BukkitNpcSkin
1920
import dev.slne.surf.npc.bukkit.util.skinDataFromName
2021
import dev.slne.surf.npc.core.controller.npcController
2122
import dev.slne.surf.npc.core.property.propertyTypeRegistry
@@ -137,9 +138,10 @@ class BukkitSurfNpcApi : SurfNpcApi, Services.Fallback {
137138
override fun createSkinData(
138139
owner: String,
139140
value: String,
140-
signature: String
141+
signature: String,
142+
parts: ObjectSet<NpcSkinPart>
141143
): NpcSkin {
142-
return BukkitSNpcSkinData(owner, value, signature)
144+
return BukkitNpcSkin(owner, value, signature, parts)
143145
}
144146

145147
override fun createLocation(

0 commit comments

Comments
 (0)