mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-22 05:02:18 +00:00
Add validation via resources for tag providers (#7271)
BREAKING CHANGE: Moved ExistingFileHelper to common package Remove various workarounds from forge tag providers
This commit is contained in:
1 parent
5dac065994
commit
be5885155c
25 files changed
+191
-121
No files matched your search
@@ -20,6 +20,7 @@
|
||||
package net.minecraftforge.client.model.generators;
|
||||
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.common.data.ExistingFileHelper;
|
||||
|
||||
/**
|
||||
* Builder for block models, does not currently provide any additional
|
||||
|
||||
@@ -22,6 +22,7 @@ package net.minecraftforge.client.model.generators;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraftforge.common.data.ExistingFileHelper;
|
||||
|
||||
/**
|
||||
* Stub class to extend for block model data providers, eliminates some
|
||||
|
||||
@@ -69,6 +69,7 @@ import net.minecraft.state.properties.SlabType;
|
||||
import net.minecraft.state.properties.StairsShape;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.Direction.Axis;
|
||||
import net.minecraftforge.common.data.ExistingFileHelper;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,103 +0,0 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2020.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.client.model.generators;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collection;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
|
||||
import net.minecraft.resources.FilePack;
|
||||
import net.minecraft.resources.FolderPack;
|
||||
import net.minecraft.resources.IResource;
|
||||
import net.minecraft.resources.IResourceManager;
|
||||
import net.minecraft.resources.IResourcePack;
|
||||
import net.minecraft.resources.ResourcePackType;
|
||||
import net.minecraft.resources.SimpleReloadableResourceManager;
|
||||
import net.minecraft.resources.VanillaPack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.event.lifecycle.GatherDataEvent;
|
||||
|
||||
/**
|
||||
* Enables data providers to check if other data files currently exist. The
|
||||
* instance provided in the {@link GatherDataEvent} utilizes the standard
|
||||
* resources (via {@link VanillaPack}), as well as any extra resource packs
|
||||
* passed in via the {@code --existing} argument.
|
||||
*/
|
||||
public class ExistingFileHelper {
|
||||
|
||||
private final SimpleReloadableResourceManager clientResources, serverData;
|
||||
private final boolean enable;
|
||||
|
||||
public ExistingFileHelper(Collection<Path> existingPacks, boolean enable) {
|
||||
this.clientResources = new SimpleReloadableResourceManager(ResourcePackType.CLIENT_RESOURCES);
|
||||
this.serverData = new SimpleReloadableResourceManager(ResourcePackType.SERVER_DATA);
|
||||
this.clientResources.addResourcePack(new VanillaPack("minecraft", "realms"));
|
||||
this.serverData.addResourcePack(new VanillaPack("minecraft"));
|
||||
for (Path existing : existingPacks) {
|
||||
File file = existing.toFile();
|
||||
IResourcePack pack = file.isDirectory() ? new FolderPack(file) : new FilePack(file);
|
||||
this.clientResources.addResourcePack(pack);
|
||||
this.serverData.addResourcePack(pack);
|
||||
};
|
||||
this.enable = enable;
|
||||
}
|
||||
|
||||
private IResourceManager getManager(ResourcePackType type) {
|
||||
return type == ResourcePackType.CLIENT_RESOURCES ? clientResources : serverData;
|
||||
}
|
||||
|
||||
private ResourceLocation getLocation(ResourceLocation base, String suffix, String prefix) {
|
||||
return new ResourceLocation(base.getNamespace(), prefix + "/" + base.getPath() + suffix);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a given resource exists in the known resource packs.
|
||||
*
|
||||
* @param loc the base location of the resource, e.g.
|
||||
* {@code "minecraft:block/stone"}
|
||||
* @param type the type of resources to check
|
||||
* @param pathSuffix a string to append after the path, e.g. {@code ".json"}
|
||||
* @param pathPrefix a string to append before the path, before a slash, e.g.
|
||||
* {@code "models"}
|
||||
* @return {@code true} if the resource exists in any pack, {@code false}
|
||||
* otherwise
|
||||
*/
|
||||
public boolean exists(ResourceLocation loc, ResourcePackType type, String pathSuffix, String pathPrefix) {
|
||||
if (!enable) {
|
||||
return true;
|
||||
}
|
||||
return getManager(type).hasResource(getLocation(loc, pathSuffix, pathPrefix));
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public IResource getResource(ResourceLocation loc, ResourcePackType type, String pathSuffix, String pathPrefix) throws IOException {
|
||||
return getManager(type).getResource(getLocation(loc, pathSuffix, pathPrefix));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {@code true} if validation is enabled, {@code false} otherwise
|
||||
*/
|
||||
public boolean isEnabled() {
|
||||
return enable;
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,7 @@ import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.common.data.ExistingFileHelper;
|
||||
|
||||
/**
|
||||
* Builder for item models, adds the ability to build overrides via
|
||||
|
||||
@@ -22,6 +22,7 @@ package net.minecraftforge.client.model.generators;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraftforge.common.data.ExistingFileHelper;
|
||||
|
||||
/**
|
||||
* Stub class to extend for item model data providers, eliminates some
|
||||
|
||||
@@ -37,6 +37,7 @@ import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import net.minecraft.util.math.vector.Vector3f;
|
||||
import net.minecraftforge.common.data.ExistingFileHelper;
|
||||
import net.minecraft.client.renderer.model.BlockFaceUV;
|
||||
import net.minecraft.client.renderer.model.BlockPart;
|
||||
import net.minecraft.client.renderer.model.BlockPartFace;
|
||||
|
||||
@@ -23,6 +23,7 @@ import com.google.common.base.Preconditions;
|
||||
|
||||
import net.minecraft.resources.ResourcePackType;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.common.data.ExistingFileHelper;
|
||||
|
||||
public abstract class ModelFile {
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ import net.minecraft.data.DirectoryCache;
|
||||
import net.minecraft.data.IDataProvider;
|
||||
import net.minecraft.resources.ResourcePackType;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.common.data.ExistingFileHelper;
|
||||
|
||||
public abstract class ModelProvider<T extends ModelBuilder<T>> implements IDataProvider {
|
||||
|
||||
|
||||
Reference in new issue
Block a user