-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0b2e477
commit c7996be
Showing
11 changed files
with
121 additions
and
26 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
api/src/main/java/com/redmagic/undefinedapi/nms/interfaces/NMSItemEntity.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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.redmagic.undefinedapi.nms.interfaces | ||
|
||
import org.bukkit.inventory.ItemStack | ||
|
||
interface NMSItemEntity: NMSEntity { | ||
|
||
var itemStack: ItemStack | ||
|
||
fun update() | ||
|
||
} |
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
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
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
2 changes: 1 addition & 1 deletion
2
...4/entity/entityClasses/UndefinedEntity.kt → ...api/nms/v1_20_4/entity/UndefinedEntity.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
44 changes: 44 additions & 0 deletions
44
...src/main/java/com/redmagic/undefinedapi/nms/v1_20_4/entity/entityClasses/NMSItemEntity.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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.redmagic.undefinedapi.nms.v1_20_4.entity.entityClasses | ||
|
||
import com.redmagic.undefinedapi.nms.interfaces.NMSItemEntity | ||
import com.redmagic.undefinedapi.nms.v1_20_4.entity.NMSEntity | ||
import net.minecraft.network.syncher.EntityDataAccessor | ||
import net.minecraft.network.syncher.EntityDataSerializers | ||
import net.minecraft.network.syncher.SynchedEntityData | ||
import net.minecraft.world.entity.Entity | ||
import net.minecraft.world.entity.item.ItemEntity | ||
import net.minecraft.world.level.Level | ||
import org.bukkit.Location | ||
import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftItemStack | ||
import org.bukkit.entity.EntityType | ||
import org.bukkit.inventory.ItemStack | ||
|
||
class NMSItemEntity(item: ItemStack): NMSEntity(EntityType.DROPPED_ITEM), NMSItemEntity { | ||
|
||
private val DATA_ITEM: EntityDataAccessor<net.minecraft.world.item.ItemStack> = SynchedEntityData.defineId( | ||
ItemEntity::class.java, EntityDataSerializers.ITEM_STACK | ||
) | ||
|
||
override var itemStack: ItemStack = item | ||
set(value) { | ||
|
||
entity?.let { | ||
it.entityData.set(DATA_ITEM, CraftItemStack.asNMSCopy(value)) | ||
|
||
sendMetaPackets() | ||
field = value | ||
} | ||
|
||
} | ||
|
||
override fun spawn(newLocation: Location) { | ||
super.spawn(newLocation) | ||
update() | ||
} | ||
|
||
override fun update() { | ||
itemStack = itemStack | ||
} | ||
|
||
override fun getUndefinedEntityClass(entityType: net.minecraft.world.entity.EntityType<*>, level: Level): Entity = ItemEntity(net.minecraft.world.entity.EntityType.ITEM, level) | ||
} |
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
2 changes: 1 addition & 1 deletion
2
...0_5/entity/entityClass/UndefinedEntity.kt → ...api/nms/v1_20_5/entity/UndefinedEntity.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
44 changes: 44 additions & 0 deletions
44
...5/src/main/java/com/redmagic/undefinedapi/nms/v1_20_5/entity/entityClass/NMSItemEntity.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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.redmagic.undefinedapi.nms.v1_20_5.entity.entityClass | ||
|
||
import com.redmagic.undefinedapi.nms.interfaces.NMSItemEntity | ||
import com.redmagic.undefinedapi.nms.v1_20_5.entity.NMSEntity | ||
import net.minecraft.network.syncher.EntityDataSerializers | ||
import net.minecraft.network.syncher.SynchedEntityData | ||
import net.minecraft.world.entity.Entity | ||
import net.minecraft.world.entity.item.ItemEntity | ||
import net.minecraft.world.level.Level | ||
import org.bukkit.Location | ||
import org.bukkit.craftbukkit.inventory.CraftItemStack | ||
import org.bukkit.entity.EntityType | ||
import org.bukkit.inventory.ItemStack | ||
|
||
class NMSItemEntity(item: ItemStack): NMSEntity(EntityType.ITEM), NMSItemEntity { | ||
override var itemStack: ItemStack = item | ||
set(value) { | ||
|
||
entity?.let { | ||
|
||
val itemEntity = entity as ItemEntity | ||
|
||
itemEntity.entityData.set( | ||
SynchedEntityData.defineId( | ||
ItemEntity::class.java, EntityDataSerializers.ITEM_STACK | ||
), CraftItemStack.asNMSCopy(value)) | ||
|
||
sendMetaPackets() | ||
field = value | ||
} | ||
|
||
} | ||
|
||
override fun spawn(newLocation: Location) { | ||
super.spawn(newLocation) | ||
update() | ||
} | ||
|
||
override fun update() { | ||
itemStack = itemStack | ||
} | ||
|
||
override fun getUndefinedEntityClass(entityType: net.minecraft.world.entity.EntityType<*>, level: Level): Entity = ItemEntity(net.minecraft.world.entity.EntityType.ITEM, level) | ||
} |