use of net.minecraft.nbt.NbtCompound in project bewitchment by MoriyaShiine.
the class BindFamiliarRitualFunction method start.
@Override
public void start(ServerWorld world, BlockPos glyphPos, BlockPos effectivePos, Inventory inventory, boolean catFamiliar) {
boolean succeeded = false;
ItemStack taglock = null;
for (int i = 0; i < inventory.size(); i++) {
ItemStack stack = inventory.getStack(i);
if (inventory.getStack(i).getItem() instanceof TaglockItem) {
taglock = stack;
break;
}
}
if (taglock != null) {
LivingEntity livingEntity = BewitchmentAPI.getTaglockOwner(world, taglock);
if (livingEntity != null) {
PlayerEntity closestPlayer = world.getClosestPlayer(effectivePos.getX() + 0.5, effectivePos.getY() + 0.5, effectivePos.getZ() + 0.5, 8, false);
if (closestPlayer != null && BewitchmentAPI.getFamiliar(closestPlayer) == null) {
NbtCompound entityCompound = new NbtCompound();
livingEntity.saveSelfNbt(entityCompound);
if (entityCompound.contains("Owner") && closestPlayer.getUuid().equals(entityCompound.getUuid("Owner"))) {
BWComponents.FAMILIAR_COMPONENT.get(livingEntity).setFamiliar(true);
BWUniversalWorldState universalWorldState = BWUniversalWorldState.get(world);
NbtCompound familiarCompound = new NbtCompound();
familiarCompound.putUuid("UUID", entityCompound.getUuid("UUID"));
familiarCompound.putString("id", Registry.ENTITY_TYPE.getId(livingEntity.getType()).toString());
universalWorldState.familiars.add(new Pair<>(closestPlayer.getUuid(), familiarCompound));
universalWorldState.markDirty();
succeeded = true;
}
}
}
}
if (!succeeded) {
ItemScatterer.spawn(world, glyphPos, inventory);
}
super.start(world, glyphPos, effectivePos, inventory, catFamiliar);
}
use of net.minecraft.nbt.NbtCompound in project bewitchment by MoriyaShiine.
the class UnbindFamiliarRitualFunction method start.
@Override
public void start(ServerWorld world, BlockPos glyphPos, BlockPos effectivePos, Inventory inventory, boolean catFamiliar) {
boolean succeeded = false;
ItemStack taglock = null;
for (int i = 0; i < inventory.size(); i++) {
ItemStack stack = inventory.getStack(i);
if (inventory.getStack(i).getItem() instanceof TaglockItem) {
taglock = stack;
break;
}
}
if (taglock != null) {
LivingEntity livingEntity = BewitchmentAPI.getTaglockOwner(world, taglock);
if (livingEntity != null) {
PlayerEntity closestPlayer = world.getClosestPlayer(effectivePos.getX() + 0.5, effectivePos.getY() + 0.5, effectivePos.getZ() + 0.5, 8, false);
if (closestPlayer != null && BewitchmentAPI.getFamiliar(closestPlayer) != null) {
NbtCompound entityCompound = new NbtCompound();
livingEntity.saveSelfNbt(entityCompound);
if (entityCompound.contains("Owner") && closestPlayer.getUuid().equals(entityCompound.getUuid("Owner"))) {
BWComponents.FAMILIAR_COMPONENT.get(livingEntity).setFamiliar(false);
BWUniversalWorldState universalWorldState = BWUniversalWorldState.get(world);
for (int i = universalWorldState.familiars.size() - 1; i >= 0; i--) {
if (livingEntity.getUuid().equals(universalWorldState.familiars.get(i).getRight().getUuid("UUID"))) {
universalWorldState.familiars.remove(i);
universalWorldState.markDirty();
succeeded = true;
}
}
}
}
}
}
if (!succeeded) {
ItemScatterer.spawn(world, glyphPos, inventory);
}
super.start(world, glyphPos, effectivePos, inventory, catFamiliar);
}
use of net.minecraft.nbt.NbtCompound in project bewitchment by MoriyaShiine.
the class DemonEntity method readCustomDataFromNbt.
@Override
public void readCustomDataFromNbt(NbtCompound nbt) {
super.readCustomDataFromNbt(nbt);
dataTracker.set(MALE, nbt.getBoolean("Male"));
if (nbt.contains("Offers")) {
offers.clear();
NbtList offersList = nbt.getList("Offers", NbtType.COMPOUND);
for (NbtElement offerTag : offersList) {
offers.add(new DemonTradeOffer((NbtCompound) offerTag));
}
}
tradeResetTimer = nbt.getInt("TradeResetTimer");
}
use of net.minecraft.nbt.NbtCompound in project bewitchment by MoriyaShiine.
the class JuniperChestBlockEntity method toInitialChunkDataNbt.
@Override
public NbtCompound toInitialChunkDataNbt() {
NbtCompound nbt = super.toInitialChunkDataNbt();
writeNbt(nbt);
return nbt;
}
use of net.minecraft.nbt.NbtCompound in project bewitchment by MoriyaShiine.
the class SigilBlockEntity method toInitialChunkDataNbt.
@Override
public NbtCompound toInitialChunkDataNbt() {
NbtCompound nbt = super.toInitialChunkDataNbt();
writeNbt(nbt);
return nbt;
}
Aggregations