1
1
package dev.sterner.common.entity
2
2
3
3
import com.sammy.malum.common.entity.FloatingEntity
4
+ import com.sammy.malum.common.entity.spirit.SpiritItemEntity
4
5
import com.sammy.malum.registry.common.SpiritTypeRegistry
5
6
import com.sammy.malum.registry.common.item.ItemRegistry
6
7
import com.sammy.malum.visual_effects.SpiritLightSpecs
8
+ import dev.sterner.common.entity.ParticleEntity.Companion.DATA_SPIRIT
7
9
import dev.sterner.registry.VoidBoundEntityTypeRegistry
8
10
import net.minecraft.nbt.CompoundTag
11
+ import net.minecraft.network.protocol.Packet
12
+ import net.minecraft.network.protocol.game.ClientGamePacketListener
9
13
import net.minecraft.network.syncher.EntityDataAccessor
10
14
import net.minecraft.network.syncher.EntityDataSerializers
11
15
import net.minecraft.network.syncher.SynchedEntityData
@@ -39,37 +43,44 @@ class ItemCarrierItemEntity(level: Level?) : FloatingEntity(VoidBoundEntityTypeR
39
43
this .itemStack = stack
40
44
this .setPos(posX, posY, posZ)
41
45
this .setDeltaMovement(velX, velY, velZ)
42
- this .maxAge = 800
46
+ this .maxAge = 8000
47
+ this .age = 0
48
+ }
49
+
50
+ init {
51
+ this .maxAge = 8000
43
52
}
44
53
45
54
override fun addAdditionalSaveData (pCompound : CompoundTag ) {
46
- super .addAdditionalSaveData(pCompound)
55
+ pCompound.putInt(" age" , this .age)
56
+ pCompound.putFloat(" windUp" , this .windUp)
57
+ if (this .ownerUUID != null ) {
58
+ pCompound.putUUID(" ownerUUID" , this .ownerUUID)
59
+ }
47
60
val itemstack = this .getItemRaw()
48
61
if (! itemstack.isEmpty) {
49
62
pCompound.put(" Item" , itemstack.save(CompoundTag ()))
50
63
}
51
64
}
52
65
53
66
override fun readAdditionalSaveData (pCompound : CompoundTag ) {
54
- super .readAdditionalSaveData(pCompound)
55
- val itemstack = ItemStack .of(pCompound.getCompound(" Item" ))
56
- this .setItem(itemstack)
67
+ this .age = pCompound.getInt(" age" )
68
+ this .windUp = pCompound.getFloat(" windUp" )
69
+ if (pCompound.contains(" ownerUUID" )) {
70
+ this .setOwner(pCompound.getUUID(" ownerUUID" ))
71
+ }
72
+ if (pCompound.contains(" Item" )) {
73
+ val itemstack = ItemStack .of(pCompound.getCompound(" Item" ))
74
+ this .setItem(itemstack)
75
+ }
57
76
}
58
77
59
78
fun setItem (pStack : ItemStack ) {
60
- getEntityData() .set(DATA_ITEM_STACK , pStack)
79
+ entityData .set(DATA_ITEM_STACK , pStack)
61
80
}
62
81
63
82
override fun defineSynchedData () {
64
- getEntityData().define(DATA_ITEM_STACK , ItemStack .EMPTY )
65
- }
66
-
67
- override fun onSyncedDataUpdated (pKey : EntityDataAccessor <* >) {
68
- if (DATA_ITEM_STACK == pKey) {
69
- this .itemStack = getEntityData().get(DATA_ITEM_STACK ) as ItemStack
70
- }
71
-
72
- super .onSyncedDataUpdated(pKey)
83
+ entityData.define(DATA_ITEM_STACK , ItemStack .EMPTY )
73
84
}
74
85
75
86
override fun collect () {
@@ -81,7 +92,7 @@ class ItemCarrierItemEntity(level: Level?) : FloatingEntity(VoidBoundEntityTypeR
81
92
}
82
93
83
94
protected fun getItemRaw (): ItemStack {
84
- return getEntityData() .get(DATA_ITEM_STACK ) as ItemStack
95
+ return entityData .get(DATA_ITEM_STACK ) as ItemStack
85
96
}
86
97
87
98
protected fun getDefaultItem (): Item {
@@ -93,11 +104,24 @@ class ItemCarrierItemEntity(level: Level?) : FloatingEntity(VoidBoundEntityTypeR
93
104
return if (itemstack.isEmpty) ItemStack (this .getDefaultItem()) else itemstack
94
105
}
95
106
107
+ override fun tick () {
108
+ super .tick()
109
+ println (" $age : $maxAge : $isAlive : ${level().isClientSide} " )
110
+ }
111
+
112
+ override fun onSyncedDataUpdated (pKey : EntityDataAccessor <* >) {
113
+ if (DATA_ITEM_STACK .equals(pKey)) {
114
+ itemStack = getEntityData().get(DATA_ITEM_STACK )
115
+ }
116
+
117
+ super .onSyncedDataUpdated(pKey)
118
+ }
119
+
120
+
96
121
override fun spawnParticles (x : Double , y : Double , z : Double ) {
97
122
val motion = this .deltaMovement
98
123
val norm = motion.normalize().scale(0.05000000074505806 )
99
- val lightSpecs: ParticleEffectSpawner =
100
- SpiritLightSpecs .spiritLightSpecs(this .level(), Vec3 (x, y, z), SpiritTypeRegistry .AQUEOUS_SPIRIT )
124
+ val lightSpecs: ParticleEffectSpawner = SpiritLightSpecs .spiritLightSpecs(this .level(), Vec3 (x, y, z), SpiritTypeRegistry .AQUEOUS_SPIRIT )
101
125
lightSpecs.builder.setMotion(norm)
102
126
lightSpecs.bloomBuilder.setMotion(norm)
103
127
lightSpecs.spawnParticles()
0 commit comments