Search in sources :

Example 91 with ResourceLocation

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());
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) ListTag(net.minecraft.nbt.ListTag) CompoundTag(net.minecraft.nbt.CompoundTag)

Example 92 with ResourceLocation

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()));
    });
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) IOException(java.io.IOException) WorldGenSettings(net.minecraft.world.level.levelgen.WorldGenSettings) LevelStem(net.minecraft.world.level.dimension.LevelStem) ResourceLocation(net.minecraft.resources.ResourceLocation) Level(net.minecraft.world.level.Level) ServerLevel(net.minecraft.server.level.ServerLevel) WorldTemplate(org.spongepowered.api.world.server.WorldTemplate) ResourceKeyBridge(org.spongepowered.common.bridge.ResourceKeyBridge)

Example 93 with ResourceLocation

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;
}
Also used : LevelStem(net.minecraft.world.level.dimension.LevelStem) LevelStemBridge(org.spongepowered.common.bridge.world.level.dimension.LevelStemBridge) ResourceLocation(net.minecraft.resources.ResourceLocation)

Example 94 with ResourceLocation

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);
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) Inject(org.spongepowered.asm.mixin.injection.Inject) Criterion(net.minecraft.advancements.Criterion) HashMap(java.util.HashMap) Overwrite(org.spongepowered.asm.mixin.Overwrite) SpongeAdventure(org.spongepowered.common.adventure.SpongeAdventure) DisplayInfoBridge(org.spongepowered.common.bridge.advancements.DisplayInfoBridge) ArrayList(java.util.ArrayList) FrameType(net.minecraft.advancements.FrameType) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) CallbackInfo(org.spongepowered.asm.mixin.injection.callback.CallbackInfo) DefaultedAdvancementCriterion(org.spongepowered.common.advancement.criterion.DefaultedAdvancementCriterion) ImmutableList(com.google.common.collect.ImmutableList) DisplayInfo(net.minecraft.advancements.DisplayInfo) Mixin(org.spongepowered.asm.mixin.Mixin) Component(net.kyori.adventure.text.Component) Map(java.util.Map) AdvancementBridge(org.spongepowered.common.bridge.advancements.AdvancementBridge) Nullable(javax.annotation.Nullable) At(org.spongepowered.asm.mixin.injection.At) AdvancementRewards(net.minecraft.advancements.AdvancementRewards) Mutable(org.spongepowered.asm.mixin.Mutable) Advancement(net.minecraft.advancements.Advancement) AndCriterion(org.spongepowered.api.advancement.criteria.AndCriterion) OrCriterion(org.spongepowered.api.advancement.criteria.OrCriterion) Set(java.util.Set) AdvancementCriterion(org.spongepowered.api.advancement.criteria.AdvancementCriterion) CriterionBridge(org.spongepowered.common.bridge.advancements.CriterionBridge) Final(org.spongepowered.asm.mixin.Final) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) PlatformHooks(org.spongepowered.common.hooks.PlatformHooks) SpongeScoreCriterion(org.spongepowered.common.advancement.criterion.SpongeScoreCriterion) Shadow(org.spongepowered.asm.mixin.Shadow) Optional(java.util.Optional) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) DefaultedAdvancementCriterion(org.spongepowered.common.advancement.criterion.DefaultedAdvancementCriterion) AdvancementCriterion(org.spongepowered.api.advancement.criteria.AdvancementCriterion) SpongeScoreCriterion(org.spongepowered.common.advancement.criterion.SpongeScoreCriterion) DisplayInfoBridge(org.spongepowered.common.bridge.advancements.DisplayInfoBridge) LinkedHashMap(java.util.LinkedHashMap) Criterion(net.minecraft.advancements.Criterion) DefaultedAdvancementCriterion(org.spongepowered.common.advancement.criterion.DefaultedAdvancementCriterion) AndCriterion(org.spongepowered.api.advancement.criteria.AndCriterion) OrCriterion(org.spongepowered.api.advancement.criteria.OrCriterion) AdvancementCriterion(org.spongepowered.api.advancement.criteria.AdvancementCriterion) SpongeScoreCriterion(org.spongepowered.common.advancement.criterion.SpongeScoreCriterion) DefaultedAdvancementCriterion(org.spongepowered.common.advancement.criterion.DefaultedAdvancementCriterion) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) CriterionBridge(org.spongepowered.common.bridge.advancements.CriterionBridge) HashSet(java.util.HashSet) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 95 with ResourceLocation

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);
            }
        }
    }
}
Also used : PrimedTnt(net.minecraft.world.entity.item.PrimedTnt) FallingBlockEntity(net.minecraft.world.entity.item.FallingBlockEntity) Player(net.minecraft.world.entity.player.Player) ServerPlayer(net.minecraft.server.level.ServerPlayer) WorldConfig(org.spongepowered.common.config.inheritable.WorldConfig) EntityTypeBridge(org.spongepowered.common.bridge.world.entity.EntityTypeBridge) EndCrystal(net.minecraft.world.entity.boss.enderdragon.EndCrystal) FireworkRocketEntity(net.minecraft.world.entity.projectile.FireworkRocketEntity) Painting(net.minecraft.world.entity.decoration.Painting) LightningBolt(net.minecraft.world.entity.LightningBolt) EnderDragon(net.minecraft.world.entity.boss.enderdragon.EnderDragon) ActivationCapabilityBridge(org.spongepowered.common.bridge.activation.ActivationCapabilityBridge) WitherBoss(net.minecraft.world.entity.boss.wither.WitherBoss) EnderDragonPart(net.minecraft.world.entity.boss.EnderDragonPart) AbstractHurtingProjectile(net.minecraft.world.entity.projectile.AbstractHurtingProjectile) ResourceLocation(net.minecraft.resources.ResourceLocation) ThrowableProjectile(net.minecraft.world.entity.projectile.ThrowableProjectile) EntityActivationRangeCategory(org.spongepowered.common.config.inheritable.EntityActivationRangeCategory)

Aggregations

ResourceLocation (net.minecraft.resources.ResourceLocation)130 Map (java.util.Map)12 IOException (java.io.IOException)11 ArrayList (java.util.ArrayList)11 CompoundTag (net.minecraft.nbt.CompoundTag)11 List (java.util.List)10 BlockPos (net.minecraft.core.BlockPos)9 Collectors (java.util.stream.Collectors)7 Block (net.minecraft.world.level.block.Block)7 LogManager (org.apache.logging.log4j.LogManager)7 Logger (org.apache.logging.log4j.Logger)7 JsonObject (com.google.gson.JsonObject)6 HashMap (java.util.HashMap)6 FriendlyByteBuf (net.minecraft.network.FriendlyByteBuf)6 LivingEntity (net.minecraft.world.entity.LivingEntity)6 JsonElement (com.google.gson.JsonElement)5 CommandSyntaxException (com.mojang.brigadier.exceptions.CommandSyntaxException)5 Registry (net.minecraft.core.Registry)5 ServerLevel (net.minecraft.server.level.ServerLevel)5 InputStream (java.io.InputStream)4