Search in sources :

Example 96 with ResourceLocation

use of net.minecraft.resources.ResourceLocation in project MinecraftForge by MinecraftForge.

the class VanillaConnectionNetworkFilter method filterEntityProperties.

/**
 * Filter for SEntityPropertiesPacket. Filters out any entity attributes that are not in the "minecraft" namespace.
 * A vanilla client would ignore these with an error log.
 */
@Nonnull
private static ClientboundUpdateAttributesPacket filterEntityProperties(ClientboundUpdateAttributesPacket msg) {
    ClientboundUpdateAttributesPacket newPacket = new ClientboundUpdateAttributesPacket(msg.getEntityId(), Collections.emptyList());
    msg.getValues().stream().filter(snapshot -> {
        ResourceLocation key = ForgeRegistries.ATTRIBUTES.getKey(snapshot.getAttribute());
        return key != null && key.getNamespace().equals("minecraft");
    }).forEach(snapshot -> newPacket.getValues().add(snapshot));
    return newPacket;
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) SharedSuggestionProvider(net.minecraft.commands.SharedSuggestionProvider) Connection(net.minecraft.network.Connection) Registry(net.minecraft.core.Registry) Map(java.util.Map) BiConsumer(java.util.function.BiConsumer) Nonnull(javax.annotation.Nonnull) RootCommandNode(com.mojang.brigadier.tree.RootCommandNode) ClientboundCommandsPacket(net.minecraft.network.protocol.game.ClientboundCommandsPacket) ArgumentTypes(net.minecraft.commands.synchronization.ArgumentTypes) ClientboundUpdateTagsPacket(net.minecraft.network.protocol.game.ClientboundUpdateTagsPacket) ImmutableMap(com.google.common.collect.ImmutableMap) ClientboundUpdateAttributesPacket(net.minecraft.network.protocol.game.ClientboundUpdateAttributesPacket) Collectors(java.util.stream.Collectors) ResourceKey(net.minecraft.resources.ResourceKey) List(java.util.List) Logger(org.apache.logging.log4j.Logger) ForgeTagHandler(net.minecraftforge.common.ForgeTagHandler) ChannelHandler(io.netty.channel.ChannelHandler) Packet(net.minecraft.network.protocol.Packet) Collections(java.util.Collections) TagCollection(net.minecraft.tags.TagCollection) LogManager(org.apache.logging.log4j.LogManager) ForgeRegistries(net.minecraftforge.registries.ForgeRegistries) NetworkHooks(net.minecraftforge.network.NetworkHooks) ResourceLocation(net.minecraft.resources.ResourceLocation) ClientboundUpdateAttributesPacket(net.minecraft.network.protocol.game.ClientboundUpdateAttributesPacket) Nonnull(javax.annotation.Nonnull)

Example 97 with ResourceLocation

use of net.minecraft.resources.ResourceLocation in project MinecraftForge by MinecraftForge.

the class VanillaConnectionNetworkFilter method filterCommandList.

/**
 * Filter for SCommandListPacket. Uses {@link CommandTreeCleaner} to filter out any ArgumentTypes that are not in the "minecraft" or "brigadier" namespace.
 * A vanilla client would fail to deserialize the packet and disconnect with an error message if these were sent.
 */
@Nonnull
private static ClientboundCommandsPacket filterCommandList(ClientboundCommandsPacket packet) {
    RootCommandNode<SharedSuggestionProvider> root = packet.getRoot();
    RootCommandNode<SharedSuggestionProvider> newRoot = CommandTreeCleaner.cleanArgumentTypes(root, argType -> {
        ResourceLocation id = ArgumentTypes.getId(argType);
        return id != null && (id.getNamespace().equals("minecraft") || id.getNamespace().equals("brigadier"));
    });
    return new ClientboundCommandsPacket(newRoot);
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) ClientboundCommandsPacket(net.minecraft.network.protocol.game.ClientboundCommandsPacket) SharedSuggestionProvider(net.minecraft.commands.SharedSuggestionProvider) Nonnull(javax.annotation.Nonnull)

Example 98 with ResourceLocation

use of net.minecraft.resources.ResourceLocation in project MinecraftForge by MinecraftForge.

the class DataGeneratorTest method testModelResults.

private static <T extends ModelBuilder<T>> List<String> testModelResults(Map<ResourceLocation, T> models, ExistingFileHelper existingFileHelper, Set<ResourceLocation> toIgnore) {
    List<String> ret = new ArrayList<>();
    models.forEach((loc, model) -> {
        if (toIgnore.contains(loc))
            return;
        JsonObject generated = model.toJson();
        if (generated.has("parent")) {
            generated.addProperty("parent", toVanillaModel(generated.get("parent").getAsString()));
        }
        try {
            Resource vanillaResource = existingFileHelper.getResource(new ResourceLocation(loc.getPath()), PackType.CLIENT_RESOURCES, ".json", "models");
            JsonObject existing = GSON.fromJson(new InputStreamReader(vanillaResource.getInputStream()), JsonObject.class);
            JsonElement generatedDisplay = generated.remove("display");
            JsonElement vanillaDisplay = existing.remove("display");
            if (generatedDisplay == null && vanillaDisplay != null) {
                ret.add("Model " + loc + " is missing transforms");
                return;
            } else if (generatedDisplay != null && vanillaDisplay == null) {
                ret.add("Model " + loc + " has transforms when vanilla equivalent does not");
                return;
            } else if (generatedDisplay != null) {
                // Both must be non-null
                ItemTransforms generatedTransforms = GSON.fromJson(generatedDisplay, ItemTransforms.class);
                ItemTransforms vanillaTransforms = GSON.fromJson(vanillaDisplay, ItemTransforms.class);
                for (Perspective type : Perspective.values()) {
                    if (!generatedTransforms.getTransform(type.vanillaType).equals(vanillaTransforms.getTransform(type.vanillaType))) {
                        ret.add("Model " + loc + " has transforms that differ from vanilla equivalent for perspective " + type.name());
                        return;
                    }
                }
            }
            JsonElement generatedTextures = generated.remove("textures");
            JsonElement vanillaTextures = existing.remove("textures");
            if (generatedTextures == null && vanillaTextures != null) {
                ret.add("Model " + loc + " is missing textures");
            } else if (generatedTextures != null && vanillaTextures == null) {
                ret.add("Model " + loc + " has textures when vanilla equivalent does not");
            } else if (generatedTextures != null) {
                // Both must be non-null
                for (Map.Entry<String, JsonElement> e : generatedTextures.getAsJsonObject().entrySet()) {
                    String vanillaTexture = vanillaTextures.getAsJsonObject().get(e.getKey()).getAsString();
                    if (!e.getValue().getAsString().equals(vanillaTexture)) {
                        ret.add("Texture for variable '" + e.getKey() + "' for model " + loc + " does not match vanilla equivalent");
                    }
                }
                if (generatedTextures.getAsJsonObject().size() != vanillaTextures.getAsJsonObject().size()) {
                    ret.add("Model " + loc + " is missing textures from vanilla equivalent");
                }
            }
            if (!existing.equals(generated)) {
                ret.add("Model " + loc + " does not match vanilla equivalent");
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    });
    return ret;
}
Also used : InputStreamReader(org.jline.utils.InputStreamReader) ArrayList(java.util.ArrayList) Resource(net.minecraft.server.packs.resources.Resource) JsonObject(com.google.gson.JsonObject) IOException(java.io.IOException) ItemTransforms(net.minecraft.client.renderer.block.model.ItemTransforms) Perspective(net.minecraftforge.client.model.generators.ModelBuilder.Perspective) JsonElement(com.google.gson.JsonElement) ResourceLocation(net.minecraft.resources.ResourceLocation) Map(java.util.Map)

Example 99 with ResourceLocation

use of net.minecraft.resources.ResourceLocation in project MinecraftForge by MinecraftForge.

the class PermissionAPI method initializePermissionAPI.

/**
 * <p>Helper method for internal use only!</p>
 * <p>Initializes the active permission handler based on the users config.</p>
 */
public static void initializePermissionAPI() {
    Class callerClass = StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE).getCallerClass();
    if (callerClass != ServerLifecycleHooks.class) {
        LOGGER.warn("{} tried to initialize the PermissionAPI, this call will be ignored.", callerClass.getName());
        return;
    }
    PermissionAPI.activeHandler = null;
    PermissionGatherEvent.Handler handlerEvent = new PermissionGatherEvent.Handler();
    MinecraftForge.EVENT_BUS.post(handlerEvent);
    Map<ResourceLocation, IPermissionHandlerFactory> availableHandlers = handlerEvent.getAvailablePermissionHandlerFactories();
    try {
        ResourceLocation selectedPermissionHandler = new ResourceLocation(ForgeConfig.SERVER.permissionHandler.get());
        if (!availableHandlers.containsKey(selectedPermissionHandler)) {
            LOGGER.error("Unable to find configured permission handler {}, will use {}", selectedPermissionHandler, DefaultPermissionHandler.IDENTIFIER);
            selectedPermissionHandler = DefaultPermissionHandler.IDENTIFIER;
        }
        IPermissionHandlerFactory factory = availableHandlers.get(selectedPermissionHandler);
        PermissionGatherEvent.Nodes nodesEvent = new PermissionGatherEvent.Nodes();
        MinecraftForge.EVENT_BUS.post(nodesEvent);
        PermissionAPI.activeHandler = factory.create(nodesEvent.getNodes());
        if (!selectedPermissionHandler.equals(activeHandler.getIdentifier()))
            LOGGER.warn("Identifier for permission handler {} does not match registered one {}", activeHandler.getIdentifier(), selectedPermissionHandler);
        LOGGER.info("Successfully initialized permission handler {}", PermissionAPI.activeHandler.getIdentifier());
    } catch (ResourceLocationException e) {
        LOGGER.error("Error parsing config value 'permissionHandler'", e);
    }
}
Also used : PermissionGatherEvent(net.minecraftforge.server.permission.events.PermissionGatherEvent) IPermissionHandlerFactory(net.minecraftforge.server.permission.handler.IPermissionHandlerFactory) ResourceLocation(net.minecraft.resources.ResourceLocation) ResourceLocationException(net.minecraft.ResourceLocationException) IPermissionHandler(net.minecraftforge.server.permission.handler.IPermissionHandler) DefaultPermissionHandler(net.minecraftforge.server.permission.handler.DefaultPermissionHandler)

Example 100 with ResourceLocation

use of net.minecraft.resources.ResourceLocation in project MinecraftForge by MinecraftForge.

the class RegistryManager method createRegistry.

<V extends IForgeRegistryEntry<V>> ForgeRegistry<V> createRegistry(ResourceLocation name, RegistryBuilder<V> builder) {
    Set<Class<?>> parents = Sets.newHashSet();
    findSuperTypes(builder.getType(), parents);
    SetView<Class<?>> overlappedTypes = Sets.intersection(parents, superTypes.keySet());
    if (!overlappedTypes.isEmpty()) {
        Class<?> foundType = overlappedTypes.iterator().next();
        LOGGER.error("Found existing registry of type {} named {}, you cannot create a new registry ({}) with type {}, as {} has a parent of that type", foundType, superTypes.get(foundType), name, builder.getType(), builder.getType());
        throw new IllegalArgumentException("Duplicate registry parent type found - you can only have one registry for a particular super type");
    }
    ForgeRegistry<V> reg = new ForgeRegistry<V>(this, name, builder);
    registries.put(name, reg);
    superTypes.put(builder.getType(), name);
    if (builder.getSaveToDisc())
        this.persisted.add(name);
    if (builder.getSync())
        this.synced.add(name);
    for (ResourceLocation legacyName : builder.getLegacyNames()) addLegacyName(legacyName, name);
    return getRegistry(name);
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation)

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