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());
}
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;
}
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();
}
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);
};
}
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_);
}
Aggregations