use of net.minecraft.resources.ResourceLocation in project SpongeCommon by SpongePowered.
the class BlockTypeItemStackData method get.
// @formatter:on
private static Set<BlockType> get(final ItemStack stack, final String nbtKey) {
final CompoundTag tag = stack.getTag();
if (tag == null) {
return null;
}
final ListTag list = tag.getList(nbtKey, Constants.NBT.TAG_STRING);
if (list.isEmpty()) {
return null;
}
return NBTStreams.toStrings(list).map(ResourceLocation::tryParse).filter(Objects::nonNull).map(key -> (BlockType) Registry.BLOCK.getOptional(key).orElse(null)).filter(Objects::nonNull).collect(Collectors.toSet());
}
use of net.minecraft.resources.ResourceLocation in project SpongeCommon by SpongePowered.
the class SpongeWorldManager method loadWorld.
@Override
public CompletableFuture<org.spongepowered.api.world.server.ServerWorld> loadWorld(final ResourceKey key) {
final net.minecraft.resources.ResourceKey<Level> registryKey = SpongeWorldManager.createRegistryKey(Objects.requireNonNull(key, "key"));
if (Level.OVERWORLD.equals(registryKey)) {
FutureUtil.completedWithException(new IllegalArgumentException("The default world cannot be told to load!"));
}
final ServerLevel world = this.worlds.get(registryKey);
if (world != null) {
return CompletableFuture.completedFuture((org.spongepowered.api.world.server.ServerWorld) world);
}
return this.loadTemplate(key).thenCompose(r -> {
WorldTemplate loadedTemplate = r.orElse(null);
if (loadedTemplate == null) {
final LevelStem scratch = BootstrapProperties.worldGenSettings.dimensions().get(net.minecraft.resources.ResourceKey.create(net.minecraft.core.Registry.LEVEL_STEM_REGISTRY, (ResourceLocation) (Object) key));
if (scratch != null) {
((ResourceKeyBridge) (Object) scratch).bridge$setKey(key);
loadedTemplate = new SpongeWorldTemplate(scratch);
}
if (loadedTemplate == null) {
return FutureUtil.completedWithException(new IOException(String.format("Failed to load a template for '%s'!", key)));
}
this.saveTemplate(loadedTemplate);
}
return this.loadWorld0(registryKey, ((SpongeWorldTemplate) loadedTemplate).asDimension(), ((WorldGenSettings) loadedTemplate.generationConfig()));
});
}
use of net.minecraft.resources.ResourceLocation in project SpongeCommon by SpongePowered.
the class SpongeWorldTemplate method asDimension.
public LevelStem asDimension() {
final LevelStem scratch = new LevelStem(() -> BootstrapProperties.registries.dimensionTypes().get((ResourceLocation) (Object) this.worldType.location()), (net.minecraft.world.level.chunk.ChunkGenerator) this.generator);
((LevelStemBridge) (Object) scratch).bridge$setFromSettings(false);
((LevelStemBridge) (Object) scratch).bridge$populateFromTemplate(this);
return scratch;
}
use of net.minecraft.resources.ResourceLocation in project SpongeCommon by SpongePowered.
the class AdvancementMixin method impl$setUpSpongeFields.
@SuppressWarnings({ "ConstantConditions" })
@Inject(method = "<init>", at = @At("RETURN"))
private void impl$setUpSpongeFields(ResourceLocation location, @Nullable Advancement parent, @Nullable DisplayInfo displayInfo, AdvancementRewards rewards, Map<String, Criterion> criteria, String[][] requirements, CallbackInfo ci) {
// Don't do anything on the client, unless we're performing registry initialization
if (!PlatformHooks.INSTANCE.getGeneralHooks().onServerThread()) {
return;
}
if (displayInfo != null) {
((DisplayInfoBridge) displayInfo).bridge$setAdvancement((org.spongepowered.api.advancement.Advancement) this);
}
this.impl$toastText = this.impl$generateToastText();
final Map<String, DefaultedAdvancementCriterion> criteriaMap = new LinkedHashMap<>();
final Map<String, List<DefaultedAdvancementCriterion>> scoreCriteria = new HashMap<>();
for (Map.Entry<String, Criterion> entry : criteria.entrySet()) {
final CriterionBridge mixinCriterion = (CriterionBridge) entry.getValue();
final String groupName = mixinCriterion.bridge$getScoreCriterionName();
if (groupName != null) {
scoreCriteria.computeIfAbsent(groupName, k -> new ArrayList<>()).add((DefaultedAdvancementCriterion) entry.getValue());
}
criteriaMap.put(entry.getKey(), (DefaultedAdvancementCriterion) mixinCriterion);
mixinCriterion.bridge$setName(entry.getKey());
}
for (Map.Entry<String, List<DefaultedAdvancementCriterion>> groupEntry : scoreCriteria.entrySet()) {
criteriaMap.put(groupEntry.getKey(), new SpongeScoreCriterion(groupEntry.getKey(), groupEntry.getValue()));
groupEntry.getValue().forEach(c -> criteriaMap.remove(c.name()));
}
final Set<AdvancementCriterion> andCriteria = new HashSet<>();
for (final String[] array : requirements) {
final Set<AdvancementCriterion> orCriteria = new HashSet<>();
for (final String name : array) {
DefaultedAdvancementCriterion criterion = criteriaMap.get(name);
if (criterion == null && criteria.get(name) != null) {
// internal removed by scoreCriterion
criterion = criteriaMap.get(((CriterionBridge) criteria.get(name)).bridge$getScoreCriterionName());
}
orCriteria.add(criterion);
}
andCriteria.add(OrCriterion.of(orCriteria));
}
this.impl$criterion = AndCriterion.of(andCriteria);
}
use of net.minecraft.resources.ResourceLocation in project SpongeCommon by SpongePowered.
the class EntityActivationRange method initializeEntityActivationState.
/**
* Initialize entity activation state.
*
* @param entity Entity to check
*/
public static void initializeEntityActivationState(final Entity entity) {
final ActivationCapabilityBridge spongeEntity = (ActivationCapabilityBridge) entity;
if (entity.level.isClientSide()) {
return;
}
// types that should always be active
if (entity instanceof Player && !((PlatformEntityBridge) entity).bridge$isFakePlayer() || entity instanceof ThrowableProjectile || entity instanceof EnderDragon || entity instanceof EnderDragonPart || entity instanceof WitherBoss || entity instanceof AbstractHurtingProjectile || entity instanceof LightningBolt || entity instanceof PrimedTnt || entity instanceof Painting || entity instanceof EndCrystal || entity instanceof FireworkRocketEntity || // Always tick falling blocks
entity instanceof FallingBlockEntity) {
return;
}
final InheritableConfigHandle<WorldConfig> configAdapter = SpongeGameConfigs.getForWorld(entity.level);
final EntityActivationRangeCategory config = configAdapter.get().entityActivationRange;
final EntityTypeBridge type = (EntityTypeBridge) entity.getType();
final ResourceLocation key = EntityType.getKey(entity.getType());
final byte activationType = spongeEntity.activation$getActivationType();
final String activationTypeName = EntityActivationRange.activationTypeMappings.getOrDefault(activationType, "misc");
if (!type.bridge$isActivationRangeInitialized()) {
EntityActivationRange.addEntityToConfig(config.autoPopulate, key, activationType, activationTypeName);
type.bridge$setActivationRangeInitialized(true);
}
final EntityActivationRangeCategory.ModSubCategory entityMod = config.mods.get(key.getNamespace());
final int defaultActivationRange = config.globalRanges.get(activationTypeName);
if (entityMod == null) {
// use default activation range
spongeEntity.activation$setActivationRange(defaultActivationRange);
if (defaultActivationRange > 0) {
spongeEntity.activation$setDefaultActivationState(false);
}
} else {
if (!entityMod.enabled) {
spongeEntity.activation$setDefaultActivationState(true);
return;
}
final Integer defaultModActivationRange = entityMod.defaultRanges.get(activationTypeName);
final Integer entityActivationRange = entityMod.entities.get(key.getPath());
if (defaultModActivationRange != null && entityActivationRange == null) {
spongeEntity.activation$setActivationRange(defaultModActivationRange);
if (defaultModActivationRange > 0) {
spongeEntity.activation$setDefaultActivationState(false);
}
} else if (entityActivationRange != null) {
spongeEntity.activation$setActivationRange(entityActivationRange);
if (entityActivationRange > 0) {
spongeEntity.activation$setDefaultActivationState(false);
}
}
}
}
Aggregations