Search in sources :

Example 81 with NbtCompound

use of net.minecraft.nbt.NbtCompound in project ProbablyChests by ReillyGregorio.

the class PCChestMimic method writeCustomDataToNbt.

public void writeCustomDataToNbt(NbtCompound nbt) {
    super.writeCustomDataToNbt(nbt);
    nbt.putBoolean("wasOnGround", this.onGroundLastTick);
    nbt.putBoolean("grounded", this.isOnGround());
    nbt.putBoolean("jumping", this.isJumping());
    nbt.putBoolean("idle", this.isIdle());
    nbt.putBoolean("flying", this.isFlying());
    nbt.putBoolean("sleeping", this.isSleeping());
    NbtList listnbt = new NbtList();
    for (int i = 0; i < this.inventory.size(); ++i) {
        ItemStack itemstack = this.inventory.getStack(i);
        NbtCompound compoundnbt = new NbtCompound();
        compoundnbt.putByte("Slot", (byte) i);
        itemstack.writeNbt(compoundnbt);
        listnbt.add(compoundnbt);
    }
    nbt.put("Inventory", listnbt);
}
Also used : NbtCompound(net.minecraft.nbt.NbtCompound) NbtList(net.minecraft.nbt.NbtList) ItemStack(net.minecraft.item.ItemStack)

Example 82 with NbtCompound

use of net.minecraft.nbt.NbtCompound in project ProbablyChests by ReillyGregorio.

the class PCChestMimicPet method readCustomDataFromNbt.

public void readCustomDataFromNbt(NbtCompound nbt) {
    super.readCustomDataFromNbt(nbt);
    this.onGroundLastTick = nbt.getBoolean("wasOnGround");
    this.setIsGrounded(nbt.getBoolean("grounded"));
    this.setIsJumping(nbt.getBoolean("jumping"));
    this.setIsIdle(nbt.getBoolean("idle"));
    this.setIsFlying(nbt.getBoolean("flying"));
    this.setIsSleeping(nbt.getBoolean("sleeping"));
    NbtList listnbt = nbt.getList("Inventory", 10);
    for (int i = 0; i < listnbt.size(); ++i) {
        NbtCompound compoundnbt = listnbt.getCompound(i);
        int j = compoundnbt.getByte("Slot") & 255;
        this.inventory.setStack(j, ItemStack.fromNbt(compoundnbt));
    }
}
Also used : NbtCompound(net.minecraft.nbt.NbtCompound) NbtList(net.minecraft.nbt.NbtList)

Example 83 with NbtCompound

use of net.minecraft.nbt.NbtCompound in project ProbablyChests by ReillyGregorio.

the class Config method toJson.

private JsonObject toJson(NbtCompound tag) {
    JsonObject json = new JsonObject();
    NbtCompound defaults = getDefaults();
    json.addProperty("pot_spawn_chance", getFloatOrDefault(tag, "pot_spawn_chance", defaults));
    json.addProperty("chest_spawn_chance", getFloatOrDefault(tag, "chest_spawn_chance", defaults));
    json.addProperty("surface_chest_spawn_chance", getFloatOrDefault(tag, "surface_chest_spawn_chance", defaults));
    json.addProperty("mimic_chance", getFloatOrDefault(tag, "mimic_chance", defaults));
    json.addProperty("easier_mimics", getBooleanOrDefault(tag, "easier_mimics", defaults));
    json.addProperty("spawn_natural_mimics", getBooleanOrDefault(tag, "spawn_natural_mimics", defaults));
    json.addProperty("natural_mimic_spawn_rate_modifier", getFloatOrDefault(tag, "natural_mimic_spawn_rate_modifier", defaults));
    json.addProperty("allow_pet_mimics", getBooleanOrDefault(tag, "allow_pet_mimics", defaults));
    // json.addProperty("max_pet_mimics", getIntOrDefault(tag, "max_pet_mimics", defaults));
    createFile(json, difference > 0);
    difference = 0;
    return json;
}
Also used : NbtCompound(net.minecraft.nbt.NbtCompound) JsonObject(com.google.gson.JsonObject)

Example 84 with NbtCompound

use of net.minecraft.nbt.NbtCompound in project Astromine by Mixinors.

the class WorldHoloBridgeComponent method writeToNbt.

/**
 * Serializes this {@link WorldHoloBridgeComponent} to a {@link NbtCompound}.
 */
@Override
public void writeToNbt(NbtCompound tag) {
    var dataTag = new NbtList();
    for (var entry : entries.long2ObjectEntrySet()) {
        var pointTag = new NbtCompound();
        var vecs = new long[entry.getValue().size()];
        var i = 0;
        for (var vec : entry.getValue()) {
            vecs[i++] = BlockPos.asLong(vec.getX(), vec.getY(), vec.getZ());
        }
        pointTag.putLong("Positions", entry.getLongKey());
        pointTag.put("Vectors", new NbtLongArray(vecs));
        dataTag.add(pointTag);
    }
    tag.put("Data", dataTag);
}
Also used : NbtCompound(net.minecraft.nbt.NbtCompound) NbtList(net.minecraft.nbt.NbtList) NbtLongArray(net.minecraft.nbt.NbtLongArray)

Example 85 with NbtCompound

use of net.minecraft.nbt.NbtCompound in project More-Weaponry by DakotaPride.

the class IronBoltEntity method writeCustomDataToNbt.

public void writeCustomDataToNbt(NbtCompound nbt) {
    super.writeCustomDataToNbt(nbt);
    if (this.potion != Potions.EMPTY) {
        nbt.putString("Potion", Registry.POTION.getId(this.potion).toString());
    }
    if (this.colorSet) {
        nbt.putInt("Color", this.getColor());
    }
    if (!this.effects.isEmpty()) {
        NbtList nbtList = new NbtList();
        Iterator var3 = this.effects.iterator();
        while (var3.hasNext()) {
            StatusEffectInstance statusEffectInstance = (StatusEffectInstance) var3.next();
            nbtList.add(statusEffectInstance.writeNbt(new NbtCompound()));
        }
        nbt.put("CustomPotionEffects", nbtList);
    }
}
Also used : NbtCompound(net.minecraft.nbt.NbtCompound) StatusEffectInstance(net.minecraft.entity.effect.StatusEffectInstance) Iterator(java.util.Iterator) NbtList(net.minecraft.nbt.NbtList)

Aggregations

NbtCompound (net.minecraft.nbt.NbtCompound)515 NbtList (net.minecraft.nbt.NbtList)149 ItemStack (net.minecraft.item.ItemStack)129 NbtElement (net.minecraft.nbt.NbtElement)40 Identifier (net.minecraft.util.Identifier)40 IOException (java.io.IOException)39 LiteralText (net.minecraft.text.LiteralText)33 BlockPos (net.minecraft.util.math.BlockPos)30 Inject (org.spongepowered.asm.mixin.injection.Inject)27 NbtString (net.minecraft.nbt.NbtString)20 TranslatableText (net.minecraft.text.TranslatableText)17 Item (net.minecraft.item.Item)15 PacketByteBuf (net.minecraft.network.PacketByteBuf)15 File (java.io.File)14 BlockState (net.minecraft.block.BlockState)14 UUID (java.util.UUID)13 MinecraftClient (net.minecraft.client.MinecraftClient)13 PlayerEntity (net.minecraft.entity.player.PlayerEntity)13 Text (net.minecraft.text.Text)13 HashMap (java.util.HashMap)12