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