mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-21 04:32:15 +00:00
Forge 1.19
* Bump pack.mcmeta formats * 1.19 biome modifiers * Mark ClientPlayerNetworkEvent.LoggedOutEvent's getters as nullable * Add docs and package-info to client extension interfaces package * Move RenderBlockOverlayEvent hooks to ForgeHooksClient * Add package-infos to client events package * Rename SoundLoadEvent to SoundEngineLoadEvent This reduces confusion from consumers which may think the name SoundLoadEvent refers to an individual sound being loaded rather than the sound engine. * Document and change SoundLoadEvent to fire on mod bus Previously, it fired on both the mod bus and the Forge bus, which is confusing for consumers. * Delete SoundSetupEvent Looking at its original implementation shows that there isn't an appropriate place in the new sound code to reinsert the event, and the place of 'sound engine/manager initialization event' is taken already by SoundLoadEvent. * Perform some cleanup on client events - Removed nullable annotations from ClientPlayerNetworkEvent - Renamed #getPartialTicks methods to #getPartialTick, to be consistent with vanilla's naming of the partial tick - Cleanup documentation to remove line breaks, use the spelling 'cancelled' over 'canceled', and improve docs on existing and new methods. * Remove EntityEvent.CanUpdate Closes MinecraftForge/MinecraftForge#6394 * Switch to Jetbrains nullability annotations * New PlayLevelSoundEvent; replaces old PlaySoundAtEntityEvent * Remove ForgeWorldPresetScreens * Remove IForgeRegistryEntry * Remove use of List<Throwable> in FML's CompletableFutures * Add docs to mod loading stages, stages, and phases * Gradle 7.4.2 * Use SLF4J in FMLLoader and other subprojects * Switch dynamic versions in subprojects to pinned ones * Switch ForgeRoot and MDK to FG plugin markers * Configure Forge javadoc task The task now uses a custom stylesheet with MCForge elements, and configured to combine the generation from the four FML subprojects (fmlloader, fmlcore, javafmllanguage, mclanguage) and the Forge project into the javadoc output. * Update docs/md files, for 1.19 update and the move away from IRC to Discord. * Make "Potentially dangerous alternative prefix" a debug warning, not info. Co-authored-by: Curle <[email protected]> Co-authored-by: sciwhiz12 <[email protected]> Signed-off-by: SizableShrimp <[email protected]>
This commit is contained in:
1 parent
270e778ac5
commit
4ed9117799
1485 files changed
+14960
-15446
No files matched your search
@@ -37,8 +37,7 @@ import net.minecraftforge.fml.ModList;
|
||||
import net.minecraftforge.forge.event.lifecycle.GatherDataEvent;
|
||||
import net.minecraftforge.forgespi.language.IModFileInfo;
|
||||
import net.minecraftforge.resource.ResourcePackLoader;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Enables data providers to check if other data files currently exist. The
|
||||
@@ -147,7 +146,7 @@ public class ExistingFileHelper {
|
||||
if (!enable) {
|
||||
return true;
|
||||
}
|
||||
return generated.get(packType).contains(loc) || getManager(packType).hasResource(loc);
|
||||
return generated.get(packType).contains(loc) || getManager(packType).getResource(loc).isPresent();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -155,7 +154,7 @@ public class ExistingFileHelper {
|
||||
* convenience method to avoid repeating type/prefix/suffix and instead use the
|
||||
* common definitions in {@link ResourceType}, or a custom {@link IResourceType}
|
||||
* definition.
|
||||
*
|
||||
*
|
||||
* @param loc the base location of the resource, e.g.
|
||||
* {@code "minecraft:block/stone"}
|
||||
* @param type a {@link IResourceType} describing how to form the path to the
|
||||
@@ -169,7 +168,7 @@ public class ExistingFileHelper {
|
||||
|
||||
/**
|
||||
* 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 packType the type of resources to check
|
||||
@@ -190,13 +189,13 @@ public class ExistingFileHelper {
|
||||
* <p>
|
||||
* This should be called by data providers immediately when a new data object is
|
||||
* created, i.e. not during
|
||||
* {@link DataProvider#run(net.minecraft.data.HashCache) run} but instead
|
||||
* {@link DataProvider#run(net.minecraft.data.CachedOutput) run} but instead
|
||||
* when the "builder" (or whatever intermediate object) is created, such as a
|
||||
* {@link ModelBuilder}.
|
||||
* <p>
|
||||
* This represents a <em>promise</em> to generate the file later, since other
|
||||
* datagen may rely on this file existing.
|
||||
*
|
||||
*
|
||||
* @param loc the base location of the resource, e.g.
|
||||
* {@code "minecraft:block/stone"}
|
||||
* @param type a {@link IResourceType} describing how to form the path to the
|
||||
@@ -211,13 +210,13 @@ public class ExistingFileHelper {
|
||||
* <p>
|
||||
* This should be called by data providers immediately when a new data object is
|
||||
* created, i.e. not during
|
||||
* {@link DataProvider#run(HashCache) run} but instead
|
||||
* {@link DataProvider#run(net.minecraft.data.CachedOutput) run} but instead
|
||||
* when the "builder" (or whatever intermediate object) is created, such as a
|
||||
* {@link ModelBuilder}.
|
||||
* <p>
|
||||
* This represents a <em>promise</em> to generate the file later, since other
|
||||
* datagen may rely on this file existing.
|
||||
*
|
||||
*
|
||||
* @param loc the base location of the resource, e.g.
|
||||
* {@code "minecraft:block/stone"}
|
||||
* @param packType the type of resources to check
|
||||
@@ -236,7 +235,7 @@ public class ExistingFileHelper {
|
||||
|
||||
@VisibleForTesting
|
||||
public Resource getResource(ResourceLocation loc, PackType packType) throws IOException {
|
||||
return getManager(packType).getResource(loc);
|
||||
return getManager(packType).getResource(loc).orElseThrow();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,7 +9,6 @@ import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.data.tags.BlockTagsProvider;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.BlockTags;
|
||||
import net.minecraft.tags.Tag;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.world.item.DyeColor;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
|
||||
@@ -9,7 +9,6 @@ import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.data.tags.BlockTagsProvider;
|
||||
import net.minecraft.data.tags.ItemTagsProvider;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.Tag;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.world.item.DyeColor;
|
||||
import net.minecraft.world.item.Item;
|
||||
|
||||
@@ -6,14 +6,13 @@
|
||||
package net.minecraftforge.common.data;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.data.CachedOutput;
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.data.HashCache;
|
||||
import net.minecraft.data.recipes.FinishedRecipe;
|
||||
import net.minecraft.data.recipes.RecipeProvider;
|
||||
import net.minecraft.data.recipes.ShapedRecipeBuilder;
|
||||
import net.minecraft.data.recipes.ShapelessRecipeBuilder;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.Tag;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
@@ -25,6 +24,8 @@ import net.minecraft.world.item.crafting.Ingredient.Value;
|
||||
import net.minecraft.world.level.ItemLike;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraftforge.common.Tags;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.nio.file.Path;
|
||||
@@ -33,8 +34,8 @@ import java.util.function.Consumer;
|
||||
|
||||
public final class ForgeRecipeProvider extends RecipeProvider
|
||||
{
|
||||
private Map<Item, TagKey<Item>> replacements = new HashMap<>();
|
||||
private Set<ResourceLocation> excludes = new HashSet<>();
|
||||
private final Map<Item, TagKey<Item>> replacements = new HashMap<>();
|
||||
private final Set<ResourceLocation> excludes = new HashSet<>();
|
||||
|
||||
public ForgeRecipeProvider(DataGenerator generatorIn)
|
||||
{
|
||||
@@ -43,7 +44,7 @@ public final class ForgeRecipeProvider extends RecipeProvider
|
||||
|
||||
private void exclude(ItemLike item)
|
||||
{
|
||||
excludes.add(item.asItem().getRegistryName());
|
||||
excludes.add(ForgeRegistries.ITEMS.getKey(item.asItem()));
|
||||
}
|
||||
|
||||
private void replace(ItemLike item, TagKey<Item> tag)
|
||||
@@ -54,15 +55,15 @@ public final class ForgeRecipeProvider extends RecipeProvider
|
||||
@Override
|
||||
protected void buildCraftingRecipes(Consumer<FinishedRecipe> consumer)
|
||||
{
|
||||
replace(Items.STICK, Tags.Items.RODS_WOODEN);
|
||||
replace(Items.GOLD_INGOT, Tags.Items.INGOTS_GOLD);
|
||||
replace(Items.IRON_INGOT, Tags.Items.INGOTS_IRON);
|
||||
replace(Items.STICK, Tags.Items.RODS_WOODEN);
|
||||
replace(Items.GOLD_INGOT, Tags.Items.INGOTS_GOLD);
|
||||
replace(Items.IRON_INGOT, Tags.Items.INGOTS_IRON);
|
||||
replace(Items.NETHERITE_INGOT, Tags.Items.INGOTS_NETHERITE);
|
||||
replace(Items.COPPER_INGOT, Tags.Items.INGOTS_COPPER);
|
||||
replace(Items.AMETHYST_SHARD, Tags.Items.GEMS_AMETHYST);
|
||||
replace(Items.DIAMOND, Tags.Items.GEMS_DIAMOND);
|
||||
replace(Items.EMERALD, Tags.Items.GEMS_EMERALD);
|
||||
replace(Items.CHEST, Tags.Items.CHESTS_WOODEN);
|
||||
replace(Items.DIAMOND, Tags.Items.GEMS_DIAMOND);
|
||||
replace(Items.EMERALD, Tags.Items.GEMS_EMERALD);
|
||||
replace(Items.CHEST, Tags.Items.CHESTS_WOODEN);
|
||||
replace(Blocks.COBBLESTONE, Tags.Items.COBBLESTONE_NORMAL);
|
||||
replace(Blocks.COBBLED_DEEPSLATE, Tags.Items.COBBLESTONE_DEEPSLATE);
|
||||
|
||||
@@ -90,20 +91,17 @@ public final class ForgeRecipeProvider extends RecipeProvider
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void saveAdvancement(HashCache cache, JsonObject advancementJson, Path pathIn) {
|
||||
//NOOP - We dont replace any of the advancement things yet...
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private FinishedRecipe enhance(FinishedRecipe vanilla)
|
||||
{
|
||||
if (vanilla instanceof ShapelessRecipeBuilder.Result)
|
||||
return enhance((ShapelessRecipeBuilder.Result)vanilla);
|
||||
if (vanilla instanceof ShapedRecipeBuilder.Result)
|
||||
return enhance((ShapedRecipeBuilder.Result)vanilla);
|
||||
if (vanilla instanceof ShapelessRecipeBuilder.Result shapeless)
|
||||
return enhance(shapeless);
|
||||
if (vanilla instanceof ShapedRecipeBuilder.Result shaped)
|
||||
return enhance(shaped);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private FinishedRecipe enhance(ShapelessRecipeBuilder.Result vanilla)
|
||||
{
|
||||
List<Ingredient> ingredients = getField(ShapelessRecipeBuilder.Result.class, vanilla, 4);
|
||||
@@ -120,6 +118,13 @@ public final class ForgeRecipeProvider extends RecipeProvider
|
||||
return modified ? vanilla : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void saveAdvancement(CachedOutput output, JsonObject advancementJson, Path pathIn)
|
||||
{
|
||||
//NOOP - We dont replace any of the advancement things yet...
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private FinishedRecipe enhance(ShapedRecipeBuilder.Result vanilla)
|
||||
{
|
||||
Map<Character, Ingredient> ingredients = getField(ShapedRecipeBuilder.Result.class, vanilla, 5);
|
||||
@@ -136,6 +141,7 @@ public final class ForgeRecipeProvider extends RecipeProvider
|
||||
return modified ? vanilla : null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Ingredient enhance(ResourceLocation name, Ingredient vanilla)
|
||||
{
|
||||
if (excludes.contains(name))
|
||||
@@ -154,11 +160,9 @@ public final class ForgeRecipeProvider extends RecipeProvider
|
||||
{
|
||||
items.add(new TagValue(replacement));
|
||||
modified = true;
|
||||
}
|
||||
else
|
||||
} else
|
||||
items.add(entry);
|
||||
}
|
||||
else
|
||||
} else
|
||||
items.add(entry);
|
||||
}
|
||||
return modified ? Ingredient.fromValues(items.stream()) : null;
|
||||
@@ -171,9 +175,8 @@ public final class ForgeRecipeProvider extends RecipeProvider
|
||||
fld.setAccessible(true);
|
||||
try
|
||||
{
|
||||
return (R)fld.get(inst);
|
||||
}
|
||||
catch (IllegalArgumentException | IllegalAccessException e)
|
||||
return (R) fld.get(inst);
|
||||
} catch (IllegalArgumentException | IllegalAccessException e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
@@ -11,12 +11,11 @@ import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.data.tags.TagsProvider;
|
||||
import net.minecraftforge.registries.GameData;
|
||||
import net.minecraftforge.registries.IForgeRegistry;
|
||||
import net.minecraftforge.registries.IForgeRegistryEntry;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public abstract class ForgeRegistryTagsProvider<T extends IForgeRegistryEntry<T>> extends TagsProvider<T>
|
||||
public abstract class ForgeRegistryTagsProvider<T> extends TagsProvider<T>
|
||||
{
|
||||
private static <T extends IForgeRegistryEntry<T>> Registry<T> wrapRegistry(IForgeRegistry<T> forgeRegistry)
|
||||
private static <T> Registry<T> wrapRegistry(IForgeRegistry<T> forgeRegistry)
|
||||
{
|
||||
if (forgeRegistry.tags() == null)
|
||||
throw new IllegalArgumentException("Forge registry " + forgeRegistry.getRegistryName() + " does not have support for tags");
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonObject;
|
||||
import cpw.mods.modlauncher.api.LamdbaExceptionUtils;
|
||||
import net.minecraft.data.CachedOutput;
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.data.HashCache;
|
||||
import net.minecraft.data.DataProvider;
|
||||
@@ -17,6 +18,7 @@ import net.minecraft.util.Tuple;
|
||||
import net.minecraftforge.common.loot.GlobalLootModifierSerializer;
|
||||
import net.minecraftforge.common.loot.IGlobalLootModifier;
|
||||
import net.minecraftforge.common.loot.LootModifier;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
@@ -59,7 +61,7 @@ public abstract class GlobalLootModifierProvider implements DataProvider
|
||||
protected abstract void start();
|
||||
|
||||
@Override
|
||||
public void run(HashCache cache) throws IOException
|
||||
public void run(CachedOutput cache) throws IOException
|
||||
{
|
||||
start();
|
||||
|
||||
@@ -73,16 +75,16 @@ public abstract class GlobalLootModifierProvider implements DataProvider
|
||||
Path modifierPath = gen.getOutputFolder().resolve(modPath + name + ".json");
|
||||
|
||||
JsonObject json = pair.getB();
|
||||
json.addProperty("type", pair.getA().getRegistryName().toString());
|
||||
json.addProperty("type", ForgeRegistries.LOOT_MODIFIER_SERIALIZERS.get().getKey(pair.getA()).toString());
|
||||
|
||||
DataProvider.save(GSON, cache, json, modifierPath);
|
||||
DataProvider.saveStable(cache, json, modifierPath);
|
||||
}));
|
||||
|
||||
JsonObject forgeJson = new JsonObject();
|
||||
forgeJson.addProperty("replace", this.replace);
|
||||
forgeJson.add("entries", GSON.toJsonTree(entries.stream().map(ResourceLocation::toString).collect(Collectors.toList())));
|
||||
|
||||
DataProvider.save(GSON, cache, forgeJson, forgePath);
|
||||
DataProvider.saveStable(cache, forgeJson, forgePath);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -14,6 +14,9 @@ import java.util.Objects;
|
||||
import java.util.TreeMap;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.google.common.hash.Hashing;
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.data.CachedOutput;
|
||||
import org.apache.commons.lang3.text.translate.JavaUnicodeEscaper;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
@@ -31,7 +34,7 @@ import net.minecraft.world.effect.MobEffect;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public abstract class LanguageProvider implements DataProvider {
|
||||
private static final Gson GSON = (new GsonBuilder()).setPrettyPrinting().disableHtmlEscaping().create();
|
||||
private static final Gson GSON = (new GsonBuilder()).setPrettyPrinting().disableHtmlEscaping().setLenient().create();
|
||||
private final Map<String, String> data = new TreeMap<>();
|
||||
private final DataGenerator gen;
|
||||
private final String modid;
|
||||
@@ -46,7 +49,7 @@ public abstract class LanguageProvider implements DataProvider {
|
||||
protected abstract void addTranslations();
|
||||
|
||||
@Override
|
||||
public void run(HashCache cache) throws IOException {
|
||||
public void run(CachedOutput cache) throws IOException {
|
||||
addTranslations();
|
||||
if (!data.isEmpty())
|
||||
save(cache, data, this.gen.getOutputFolder().resolve("assets/" + modid + "/lang/" + locale + ".json"));
|
||||
@@ -57,19 +60,14 @@ public abstract class LanguageProvider implements DataProvider {
|
||||
return "Languages: " + locale;
|
||||
}
|
||||
|
||||
private void save(HashCache cache, Object object, Path target) throws IOException {
|
||||
String data = GSON.toJson(object);
|
||||
data = JavaUnicodeEscaper.outsideOf(0, 0x7f).translate(data); // Escape unicode after the fact so that it's not double escaped by GSON
|
||||
String hash = DataProvider.SHA1.hashUnencodedChars(data).toString();
|
||||
if (!Objects.equals(cache.getHash(target), hash) || !Files.exists(target)) {
|
||||
Files.createDirectories(target.getParent());
|
||||
|
||||
try (BufferedWriter bufferedwriter = Files.newBufferedWriter(target)) {
|
||||
bufferedwriter.write(data);
|
||||
}
|
||||
private void save(CachedOutput cache, Object object, Path target) throws IOException {
|
||||
// TODO: DataProvider.saveStable handles the caching and hashing already, but creating the JSON Object this way seems unreliable. -C
|
||||
JsonObject json = new JsonObject();
|
||||
for (Map.Entry<String, String> pair : data.entrySet()) {
|
||||
json.addProperty(pair.getKey(), pair.getValue());
|
||||
}
|
||||
|
||||
cache.putNew(target, hash);
|
||||
DataProvider.saveStable(cache, json, target);
|
||||
}
|
||||
|
||||
public void addBlock(Supplier<? extends Block> key, String name) {
|
||||
|
||||
@@ -10,8 +10,8 @@ import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@@ -8,6 +8,7 @@ package net.minecraftforge.common.data;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.data.CachedOutput;
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.data.HashCache;
|
||||
import net.minecraft.data.DataProvider;
|
||||
@@ -60,7 +61,7 @@ public abstract class SoundDefinitionsProvider implements DataProvider
|
||||
public abstract void registerSounds();
|
||||
|
||||
@Override
|
||||
public void run(HashCache cache) throws IOException
|
||||
public void run(CachedOutput cache) throws IOException
|
||||
{
|
||||
this.sounds.clear();
|
||||
this.registerSounds();
|
||||
@@ -229,7 +230,7 @@ public abstract class SoundDefinitionsProvider implements DataProvider
|
||||
// Differently from all the other errors, this is not a 'missing sound' but rather something completely different
|
||||
// that has broken the invariants of this sound definitions provider. In fact, a sound may only be either of
|
||||
// SOUND or EVENT type. Any other values is somebody messing with the internals, reflectively adding something
|
||||
// to an enum or passing `null` to a parameter annotated with `@Nonnull`.
|
||||
// to an enum or passing `null` to a parameter annotated with `@NotNull`.
|
||||
throw new IllegalArgumentException("The given sound '" + sound.name() + "' does not have a valid type: expected either SOUND or EVENT, but found " + sound.type());
|
||||
}
|
||||
|
||||
@@ -254,9 +255,9 @@ public abstract class SoundDefinitionsProvider implements DataProvider
|
||||
return valid;
|
||||
}
|
||||
|
||||
private void save(final HashCache cache, final Path targetFile) throws IOException
|
||||
private void save(final CachedOutput cache, final Path targetFile) throws IOException
|
||||
{
|
||||
DataProvider.save(GSON, cache, this.mapToJson(this.sounds), targetFile);
|
||||
DataProvider.saveStable(cache, this.mapToJson(this.sounds), targetFile);
|
||||
}
|
||||
|
||||
private JsonObject mapToJson(final Map<String, SoundDefinition> map)
|
||||
|
||||
Reference in new issue
Block a user