Skip to content

Commit

Permalink
add new methods to the interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Brokkonaut committed Aug 14, 2023
1 parent f7e48b2 commit 27993ba
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
37 changes: 37 additions & 0 deletions nmsutils-core/src/main/java/de/cubeside/nmsutils/EntityUtils.java
@@ -1,5 +1,6 @@
package de.cubeside.nmsutils;

import de.cubeside.nmsutils.nbt.CompoundTag;
import java.util.function.Function;
import java.util.logging.Level;
import org.bukkit.Chunk;
Expand Down Expand Up @@ -214,4 +215,40 @@ default public boolean isCamelSitting(Camel camel) {
getNMSUtils().getPlugin().getLogger().log(Level.SEVERE, "Call to unimplemented method", new RuntimeException());
return false;
}

/**
* Gets a copy of the current nbt data of an entity
*
* @param entity
* the entity
* @return the entities nbt data
*/
default public CompoundTag getNbt(Entity entity) {
getNMSUtils().getPlugin().getLogger().log(Level.SEVERE, "Call to unimplemented method", new RuntimeException());
return new CompoundTag();
}

/**
* Overwrites the nbt data of an entity, deleting all values that are not in the new nbt
*
* @param entity
* the entity
* @param nbt
* the new nbt data for the entity
*/
default public void setNbt(Entity entity, CompoundTag nbt) {
getNMSUtils().getPlugin().getLogger().log(Level.SEVERE, "Call to unimplemented method", new RuntimeException());
}

/**
* Merges the new nbt data to the entities nbt. All values that are not specified are kept unchanged
*
* @param entity
* the entity
* @param nbt
* the nbt data to merge in
*/
default public void mergeNbt(Entity entity, CompoundTag nbt) {
getNMSUtils().getPlugin().getLogger().log(Level.SEVERE, "Call to unimplemented method", new RuntimeException());
}
}
Expand Up @@ -351,12 +351,14 @@ public boolean isCamelSitting(org.bukkit.entity.Camel entity) {
return nmsEntity.isCamelSitting();
}

@Override
public CompoundTag getNbt(org.bukkit.entity.Entity entity) {
Entity nmsEntity = ((CraftEntity) entity).getHandle();
net.minecraft.nbt.CompoundTag compoundTag = nmsEntity.saveWithoutId(new net.minecraft.nbt.CompoundTag());
return nmsUtils.getNbtUtils().fromNativeCompound(compoundTag);
}

@Override
public void setNbt(org.bukkit.entity.Entity entity, CompoundTag nbt) {
net.minecraft.nbt.CompoundTag nativeNbt = nmsUtils.getNbtUtils().toNativeCompound(nbt);
Entity nmsEntity = ((CraftEntity) entity).getHandle();
Expand All @@ -366,6 +368,7 @@ public void setNbt(org.bukkit.entity.Entity entity, CompoundTag nbt) {
nmsEntity.setUUID(uuid);
}

@Override
public void mergeNbt(org.bukkit.entity.Entity entity, CompoundTag nbt) {
net.minecraft.nbt.CompoundTag nativeNbt = nmsUtils.getNbtUtils().toNativeCompound(nbt);
Entity nmsEntity = ((CraftEntity) entity).getHandle();
Expand Down

0 comments on commit 27993ba

Please sign in to comment.