Search in sources :

Example 96 with CompoundTag

use of net.minecraft.nbt.CompoundTag in project SpongeCommon by SpongePowered.

the class HumanEntity method defineSynchedData.

@Override
protected void defineSynchedData() {
    // LivingEntity
    this.entityData.define(LivingEntityAccessor.accessor$DATA_LIVING_ENTITY_FLAGS(), (byte) 0);
    this.entityData.define(LivingEntityAccessor.accessor$DATA_HEALTH_ID(), 1.0F);
    this.entityData.define(LivingEntityAccessor.accessor$DATA_EFFECT_COLOR_ID(), 0);
    this.entityData.define(LivingEntityAccessor.accessor$DATA_EFFECT_AMBIENCE_ID(), Boolean.FALSE);
    this.entityData.define(LivingEntityAccessor.accessor$DATA_ARROW_COUNT_ID(), 0);
    this.entityData.define(LivingEntityAccessor.accessor$DATA_STINGER_COUNT_ID(), 0);
    this.entityData.define(LivingEntityAccessor.accessor$SLEEPING_POS_ID(), Optional.empty());
    // PlayerEntity
    this.entityData.define(PlayerAccessor.accessor$DATA_PLAYER_ABSORPTION_ID(), 0.0F);
    this.entityData.define(PlayerAccessor.accessor$DATA_SCORE_ID(), 0);
    this.entityData.define(PlayerAccessor.accessor$DATA_PLAYER_MODE_CUSTOMISATION(), Constants.Sponge.Entity.Human.PLAYER_MODEL_FLAG_ALL);
    this.entityData.define(PlayerAccessor.accessor$DATA_PLAYER_MAIN_HAND(), (byte) 1);
    this.entityData.define(PlayerAccessor.accessor$DATA_SHOULDER_LEFT(), new CompoundTag());
    this.entityData.define(PlayerAccessor.accessor$DATA_SHOULDER_RIGHT(), new CompoundTag());
}
Also used : CompoundTag(net.minecraft.nbt.CompoundTag)

Example 97 with CompoundTag

use of net.minecraft.nbt.CompoundTag in project SpongeCommon by SpongePowered.

the class SpongeUserInventory method writeList.

/**
 * Writes the inventory out as a list of compound tags. This is where the slot indices are used (+100 for armor, +80
 * for crafting).
 */
public ListTag writeList(final ListTag nbtTagListIn) {
    for (int i = 0; i < this.mainInventory.size(); ++i) {
        if (!this.mainInventory.get(i).isEmpty()) {
            final CompoundTag nbttagcompound = new CompoundTag();
            nbttagcompound.putByte("Slot", (byte) i);
            this.mainInventory.get(i).save(nbttagcompound);
            nbtTagListIn.add(nbttagcompound);
        }
    }
    for (int j = 0; j < this.armorInventory.size(); ++j) {
        if (!this.armorInventory.get(j).isEmpty()) {
            final CompoundTag nbttagcompound1 = new CompoundTag();
            nbttagcompound1.putByte("Slot", (byte) (j + 100));
            this.armorInventory.get(j).save(nbttagcompound1);
            nbtTagListIn.add(nbttagcompound1);
        }
    }
    for (int k = 0; k < this.offHandInventory.size(); ++k) {
        if (!this.offHandInventory.get(k).isEmpty()) {
            final CompoundTag nbttagcompound2 = new CompoundTag();
            nbttagcompound2.putByte("Slot", (byte) (k + 150));
            this.offHandInventory.get(k).save(nbttagcompound2);
            nbtTagListIn.add(nbttagcompound2);
        }
    }
    this.dirty = false;
    return nbtTagListIn;
}
Also used : CompoundTag(net.minecraft.nbt.CompoundTag)

Example 98 with CompoundTag

use of net.minecraft.nbt.CompoundTag in project SpongeCommon by SpongePowered.

the class SpongeEntityArchetype method toSnapshot.

@Override
public EntitySnapshot toSnapshot(final ServerLocation location) {
    final SpongeEntitySnapshotBuilder builder = new SpongeEntitySnapshotBuilder();
    builder.entityType = this.type;
    final CompoundTag newCompound = this.compound.copy();
    final Vector3d pos = location.position();
    newCompound.put(Constants.Entity.ENTITY_POSITION, Constants.NBT.newDoubleNBTList(pos.x(), pos.y(), pos.z()));
    newCompound.putString(Constants.Sponge.World.WORLD_KEY, location.worldKey().formatted());
    builder.compound = newCompound;
    builder.worldKey = location.world().properties().key();
    builder.position = pos;
    builder.rotation = this.getRotation();
    builder.scale = Vector3d.ONE;
    return builder.build();
}
Also used : Vector3d(org.spongepowered.math.vector.Vector3d) CompoundTag(net.minecraft.nbt.CompoundTag)

Example 99 with CompoundTag

use of net.minecraft.nbt.CompoundTag in project SpongeCommon by SpongePowered.

the class EntityPerformingDropsTransaction method captureState.

@Override
protected void captureState() {
    super.captureState();
    final Entity entity = this.destroyingEntity;
    this.worldSupplier = VolumeStreamUtils.createWeaklyReferencedSupplier((ServerLevel) entity.level, "ServerLevel");
    final CompoundTag tag = new CompoundTag();
    entity.saveWithoutId(tag);
    this.entityTag = tag;
    @Nullable final DamageSource lastAttacker;
    if (entity instanceof LivingEntity) {
        final CombatEntry entry = ((CombatTrackerAccessor) ((LivingEntity) entity).getCombatTracker()).invoker$getMostSignificantFall();
        if (entry != null) {
            lastAttacker = ((CombatEntryAccessor) entry).accessor$source();
        } else {
            lastAttacker = null;
        }
    } else {
        lastAttacker = null;
    }
    final WeakReference<@Nullable DamageSource> ref = new WeakReference<>(lastAttacker);
    this.lastAttacker = () -> {
        @Nullable final DamageSource damageSource = ref.get();
        // Yes, I know, we're effectively
        if (damageSource == null) {
            return Optional.empty();
        }
        return Optional.of(damageSource);
    };
}
Also used : LivingEntity(net.minecraft.world.entity.LivingEntity) LivingEntity(net.minecraft.world.entity.LivingEntity) Entity(net.minecraft.world.entity.Entity) ServerLevel(net.minecraft.server.level.ServerLevel) DamageSource(net.minecraft.world.damagesource.DamageSource) CombatTrackerAccessor(org.spongepowered.common.accessor.world.damagesource.CombatTrackerAccessor) WeakReference(java.lang.ref.WeakReference) CombatEntry(net.minecraft.world.damagesource.CombatEntry) CompoundTag(net.minecraft.nbt.CompoundTag) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Example 100 with CompoundTag

use of net.minecraft.nbt.CompoundTag in project SpongeCommon by SpongePowered.

the class SpongeSmithingRecipe method assemble.

@Override
public ItemStack assemble(Container p_77572_1_) {
    if (this.resultFunction != null) {
        return this.resultFunction.apply(p_77572_1_);
    }
    if (this.getResultItem().hasTag()) {
        final ItemStack itemStack = this.getResultItem().copy();
        CompoundTag compoundnbt = p_77572_1_.getItem(0).getTag();
        if (compoundnbt != null) {
            final CompoundTag merged = itemStack.getTag().merge(compoundnbt.copy());
            itemStack.setTag(merged);
            return itemStack;
        }
    }
    return super.assemble(p_77572_1_);
}
Also used : ItemStack(net.minecraft.world.item.ItemStack) CompoundTag(net.minecraft.nbt.CompoundTag)

Aggregations

CompoundTag (net.minecraft.nbt.CompoundTag)146 ListTag (net.minecraft.nbt.ListTag)41 ItemStack (net.minecraft.world.item.ItemStack)22 TagCompound (de.keyle.knbt.TagCompound)12 ResourceLocation (net.minecraft.resources.ResourceLocation)12 Nullable (org.checkerframework.checker.nullness.qual.Nullable)10 Keys (org.spongepowered.api.data.Keys)9 DataProviderRegistrator (org.spongepowered.common.data.provider.DataProviderRegistrator)9 Constants (org.spongepowered.common.util.Constants)9 TagList (de.keyle.knbt.TagList)8 ArrayList (java.util.ArrayList)8 List (java.util.List)8 IntArrayTag (net.minecraft.nbt.IntArrayTag)8 Tag (net.minecraft.nbt.Tag)8 ResourceKey (org.spongepowered.api.ResourceKey)8 DataContainer (org.spongepowered.api.data.persistence.DataContainer)8 DataView (org.spongepowered.api.data.persistence.DataView)8 ByteArrayTag (net.minecraft.nbt.ByteArrayTag)7 TagString (de.keyle.knbt.TagString)6 Block (net.minecraft.world.level.block.Block)6