Skip to content

Commit

Permalink
Added IsVisible to NMS Entity
Browse files Browse the repository at this point in the history
  • Loading branch information
TheRedMagic committed Jun 13, 2024
1 parent 5e9149d commit 05a653b
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ interface NMSEntity {

var customName: String?

var glowing: Boolean
var isVisible: Boolean

fun addViewer(player: Player)

fun removeViewer(player: Player)
Expand Down
10 changes: 8 additions & 2 deletions server/src/main/java/com/redmagic/undefinedapi/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,18 @@ class Main: JavaPlugin() {
event<PlayerJoinEvent> {


val e = api.createFakeEntity(EntityType.ENDERMAN)!!
val e = api.createFakeEntity(EntityType.SHEEP)!!
e.addViewer(player)

e.spawn(player.location)

e.customName = "Testing"
e.glowing = true

delay(100) {
e.glowing = false
println("Not")
}




Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package com.redmagic.undefinedapi.nms.v1_20_4.entity

import com.redmagic.undefinedapi.nms.EntityInteract
import com.redmagic.undefinedapi.nms.extensions.getPrivateField
import com.redmagic.undefinedapi.nms.interfaces.NMSEntity
import com.redmagic.undefinedapi.nms.v1_20_4.NMSManager
import com.redmagic.undefinedapi.nms.v1_20_4.entity.entityClasses.UndefinedEntity
import com.redmagic.undefinedapi.nms.v1_20_4.extensions.sendPacket
import net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket
import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket
import net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket
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.level.Level
import org.bukkit.Location
Expand All @@ -22,6 +26,34 @@ open class NMSEntity(open val entityType: EntityType): NMSEntity {
override var location: Location? = null
var entity: Entity? = null

override var glowing: Boolean = false
set(value) {

if (entity == null) return

field = value

val data = entity!!.entityData

data.set(EntityDataAccessor(0, EntityDataSerializers.BYTE), 0x40)

viewers.sendPacket(ClientboundSetEntityDataPacket(
entity!!.id,
data.packDirty()
))

}
override var isVisible: Boolean = true
set(value) {

if (entity == null) return

entity!!.isInvisible = !value

sendMetaPackets()

field = value
}

override var customName: String? = null
get() = if (field == null) "" else field
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import com.redmagic.undefinedapi.nms.v1_20_5.extensions.sendPacket
import net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket
import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket
import net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket
import net.minecraft.world.entity.AgeableMob
import net.minecraft.world.entity.Entity
import net.minecraft.world.level.Level
import org.bukkit.Location
Expand All @@ -23,6 +22,29 @@ open class NMSEntity(open val entityType: EntityType): NMSEntity {
override var location: Location? = null
var entity: Entity? = null

override var glowing: Boolean = false
set(value) {

if (entity == null) return

entity!!.setSharedFlag(5, value)

sendMetaPackets()

field = value
}
override var isVisible: Boolean = true
set(value) {

if (entity == null) return

entity!!.setSharedFlag(6, value)

sendMetaPackets()

field = value
}

override var customName: String? = null
get() = if (field == null) "" else field
set(value) {
Expand All @@ -34,7 +56,7 @@ open class NMSEntity(open val entityType: EntityType): NMSEntity {

entity!!.isCustomNameVisible = false

sendMetaDataPackets()
sendMetaPackets()

}else{
//Show / Set name
Expand All @@ -49,7 +71,7 @@ open class NMSEntity(open val entityType: EntityType): NMSEntity {

entity!!.isCustomNameVisible = true

sendMetaDataPackets()
sendMetaPackets()

}

Expand Down Expand Up @@ -114,7 +136,7 @@ open class NMSEntity(open val entityType: EntityType): NMSEntity {

open fun getUndefinedEntityClass(entityType: net.minecraft.world.entity.EntityType<*>, level: Level): Entity = UndefinedEntity(entityType, level)

private fun sendMetaDataPackets() {
private fun sendMetaPackets() {
entity!!.entityData.packDirty()?.let {
ClientboundSetEntityDataPacket(
entity!!.id,
Expand Down

0 comments on commit 05a653b

Please sign in to comment.