use of net.minecraft.nbt.CompoundTag in project SpongeCommon by SpongePowered.
the class MobSpawnerData method getNextEntity.
// @formatter:on
private static WeightedSerializableObject<EntityArchetype> getNextEntity(final BaseSpawnerAccessor logic) {
final int weight = ((WeighedRandom_WeighedRandomItemAccessor) logic.accessor$nextSpawnData()).accessor$weight();
final String resourceLocation = logic.accessor$nextSpawnData().getTag().getString(Constants.Entity.ENTITY_TYPE_ID);
final EntityType<?> type = Registry.ENTITY_TYPE.getOptional(new ResourceLocation(resourceLocation)).map(EntityType.class::cast).orElse(EntityTypes.PIG.get());
final CompoundTag data = logic.accessor$nextSpawnData().getTag();
final EntityArchetype archetype = SpongeEntityArchetypeBuilder.pooled().type(type).entityData(NBTTranslator.INSTANCE.translateFrom(data)).build();
return new WeightedSerializableObject<>(archetype, weight);
}
use of net.minecraft.nbt.CompoundTag in project SpongeCommon by SpongePowered.
the class MobSpawnerData method setNextEntity.
private static void setNextEntity(final BaseSpawner logic, final WeightedSerializableObject<EntityArchetype> value) {
final CompoundTag compound = NBTTranslator.INSTANCE.translate(value.get().entityData());
if (!compound.contains(Constants.Entity.ENTITY_TYPE_ID)) {
final ResourceKey key = (ResourceKey) (Object) net.minecraft.world.entity.EntityType.getKey((net.minecraft.world.entity.EntityType<?>) value.get().type());
compound.putString(Constants.Entity.ENTITY_TYPE_ID, key.toString());
}
logic.setNextSpawnData(new SpawnData((int) value.weight(), compound));
}
use of net.minecraft.nbt.CompoundTag in project SpongeCommon by SpongePowered.
the class MobSpawnerData method getEntities.
private static WeightedTable<EntityArchetype> getEntities(final BaseSpawner logic) {
final WeightedTable<EntityArchetype> possibleEntities = new WeightedTable<>();
for (final SpawnData weightedEntity : ((BaseSpawnerAccessor) logic).accessor$spawnPotentials()) {
final CompoundTag nbt = weightedEntity.getTag();
final String resourceLocation = nbt.getString(Constants.Entity.ENTITY_TYPE_ID);
final EntityType<?> type = Registry.ENTITY_TYPE.getOptional(new ResourceLocation(resourceLocation)).map(EntityType.class::cast).orElse(EntityTypes.PIG.get());
final EntityArchetype archetype = SpongeEntityArchetypeBuilder.pooled().type(type).entityData(NBTTranslator.INSTANCE.translateFrom(nbt)).build();
possibleEntities.add(new WeightedSerializableObject<>(archetype, ((WeighedRandom_WeighedRandomItemAccessor) weightedEntity).accessor$weight()));
}
return possibleEntities;
}
use of net.minecraft.nbt.CompoundTag in project SpongeCommon by SpongePowered.
the class NBTTranslator method containerToCompound.
private static void containerToCompound(final DataView container, final CompoundTag compound) {
// We don't need to get deep values since all nested DataViews will be found
// from the instance of checks.
checkNotNull(container);
checkNotNull(compound);
for (Map.Entry<DataQuery, Object> entry : container.values(false).entrySet()) {
Object value = entry.getValue();
String key = entry.getKey().asString('.');
if (value instanceof DataView) {
CompoundTag inner = new CompoundTag();
NBTTranslator.containerToCompound(container.getView(entry.getKey()).get(), inner);
compound.put(key, inner);
} else if (value instanceof Boolean) {
compound.put(key + NBTTranslator.BOOLEAN_IDENTIFIER, ByteTag.valueOf((Boolean) value));
} else {
compound.put(key, NBTTranslator.getBaseFromObject(value));
}
}
}
use of net.minecraft.nbt.CompoundTag in project SpongeCommon by SpongePowered.
the class NBTTranslator method addTo.
@Override
public DataView addTo(CompoundTag compound, DataView container) {
for (String key : compound.getAllKeys()) {
Tag base = compound.get(key);
byte type = base.getId();
// gotta love recursion
NBTTranslator.setInternal(base, type, container, key);
}
return container;
}
Aggregations