use of net.minecraft.server.v1_16_R2.NBTTagCompound in project RoseStacker by Rosewood-Development.
the class NMSHandlerImpl method setItemStackNBT.
@Override
public ItemStack setItemStackNBT(ItemStack itemStack, String key, int value) {
net.minecraft.server.v1_16_R3.ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound tagCompound = nmsItem.getOrCreateTag();
tagCompound.setInt(key, value);
return CraftItemStack.asBukkitCopy(nmsItem);
}
use of net.minecraft.server.v1_16_R2.NBTTagCompound in project RoseStacker by Rosewood-Development.
the class NMSHandlerImpl method createEntityFromNBT.
@Override
public LivingEntity createEntityFromNBT(StackedEntityDataEntry<?> serialized, Location location, boolean addToWorld, EntityType entityType) {
try {
NBTTagCompound nbt = (NBTTagCompound) serialized.get();
NBTTagList positionTagList = nbt.getList("Pos", 6);
if (positionTagList == null)
positionTagList = new NBTTagList();
this.setTag(positionTagList, 0, NBTTagDouble.a(location.getX()));
this.setTag(positionTagList, 1, NBTTagDouble.a(location.getY()));
this.setTag(positionTagList, 2, NBTTagDouble.a(location.getZ()));
nbt.set("Pos", positionTagList);
NBTTagList rotationTagList = nbt.getList("Rotation", 5);
if (rotationTagList == null)
rotationTagList = new NBTTagList();
this.setTag(rotationTagList, 0, NBTTagFloat.a(location.getYaw()));
this.setTag(rotationTagList, 1, NBTTagFloat.a(location.getPitch()));
nbt.set("Rotation", rotationTagList);
// Reset the UUID to resolve possible duplicates
nbt.a("UUID", UUID.randomUUID());
Optional<EntityTypes<?>> optionalEntity = EntityTypes.a(entityType.getKey().getKey());
if (optionalEntity.isPresent()) {
WorldServer world = ((CraftWorld) location.getWorld()).getHandle();
Entity entity = this.createCreature(optionalEntity.get(), world, nbt, null, null, new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ()), EnumMobSpawn.COMMAND);
if (entity == null)
throw new NullPointerException("Unable to create entity from NBT");
// Load NBT
entity.load(nbt);
if (addToWorld) {
IChunkAccess ichunkaccess = world.getChunkAt(MathHelper.floor(entity.locX() / 16.0D), MathHelper.floor(entity.locZ() / 16.0D), ChunkStatus.FULL, true);
if (!(ichunkaccess instanceof Chunk))
throw new NullPointerException("Unable to spawn entity from NBT, couldn't get chunk");
ichunkaccess.a(entity);
method_WorldServer_registerEntity.invoke(world, entity);
entity.noDamageTicks = 0;
}
return (LivingEntity) entity.getBukkitEntity();
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
use of net.minecraft.server.v1_16_R2.NBTTagCompound in project RoseStacker by Rosewood-Development.
the class NMSHandlerImpl method setItemStackNBT.
@Override
public ItemStack setItemStackNBT(ItemStack itemStack, String key, String value) {
net.minecraft.server.v1_16_R3.ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound tagCompound = nmsItem.getOrCreateTag();
tagCompound.setString(key, value);
return CraftItemStack.asBukkitCopy(nmsItem);
}
use of net.minecraft.server.v1_16_R2.NBTTagCompound in project RoseStacker by Rosewood-Development.
the class NMSHandlerImpl method getItemStackNBTInt.
@Override
public int getItemStackNBTInt(ItemStack itemStack, String key) {
net.minecraft.server.v1_16_R3.ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound tagCompound = nmsItem.getOrCreateTag();
return tagCompound.getInt(key);
}
use of net.minecraft.server.v1_16_R2.NBTTagCompound in project RoseStacker by Rosewood-Development.
the class NMSHandlerImpl method getEntityAsNBT.
@Override
public StackedEntityDataEntry<?> getEntityAsNBT(LivingEntity livingEntity) {
NBTTagCompound nbt = new NBTTagCompound();
EntityLiving nmsEntity = ((CraftLivingEntity) livingEntity).getHandle();
nmsEntity.save(nbt);
return new NBTStackedEntityDataEntry(nbt);
}
Aggregations