Search in sources :

Example 41 with NbtCompound

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);
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) NbtCompound(net.minecraft.nbt.NbtCompound) TaglockItem(moriyashiine.bewitchment.common.item.TaglockItem) ItemStack(net.minecraft.item.ItemStack) BWUniversalWorldState(moriyashiine.bewitchment.common.world.BWUniversalWorldState) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Example 42 with NbtCompound

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);
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) NbtCompound(net.minecraft.nbt.NbtCompound) TaglockItem(moriyashiine.bewitchment.common.item.TaglockItem) ItemStack(net.minecraft.item.ItemStack) BWUniversalWorldState(moriyashiine.bewitchment.common.world.BWUniversalWorldState) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Example 43 with NbtCompound

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");
}
Also used : NbtCompound(net.minecraft.nbt.NbtCompound) NbtList(net.minecraft.nbt.NbtList) NbtElement(net.minecraft.nbt.NbtElement)

Example 44 with NbtCompound

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;
}
Also used : NbtCompound(net.minecraft.nbt.NbtCompound)

Example 45 with NbtCompound

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;
}
Also used : NbtCompound(net.minecraft.nbt.NbtCompound)

Aggregations

NbtCompound (net.minecraft.nbt.NbtCompound)318 NbtList (net.minecraft.nbt.NbtList)93 ItemStack (net.minecraft.item.ItemStack)69 NbtElement (net.minecraft.nbt.NbtElement)28 IOException (java.io.IOException)25 LiteralText (net.minecraft.text.LiteralText)24 Identifier (net.minecraft.util.Identifier)24 Inject (org.spongepowered.asm.mixin.injection.Inject)21 BlockPos (net.minecraft.util.math.BlockPos)20 NbtString (net.minecraft.nbt.NbtString)16 File (java.io.File)13 HashMap (java.util.HashMap)10 List (java.util.List)9 Text (net.minecraft.text.Text)9 Vec3d (net.minecraft.util.math.Vec3d)9 Map (java.util.Map)8 Items (net.minecraft.item.Items)8 TranslatableText (net.minecraft.text.TranslatableText)8 HashSet (java.util.HashSet)7 BlockEntity (net.minecraft.block.entity.BlockEntity)7