mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-19 03:49:14 +00:00
1 parent
6e1de81ff5
commit
9f895a79f2
162 files changed
+578
-224
No files matched your search
@@ -12,6 +12,7 @@ import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -22,23 +23,27 @@ import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import com.google.gson.JsonNull;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import net.minecraft.DetectedVersion;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.advancements.critereon.InventoryChangeTrigger;
|
||||
import net.minecraft.core.*;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.data.CachedOutput;
|
||||
import net.minecraft.data.PackOutput;
|
||||
import net.minecraft.data.metadata.PackMetadataGenerator;
|
||||
import net.minecraft.data.recipes.*;
|
||||
import net.minecraft.data.worldgen.BootstapContext;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.server.packs.metadata.pack.PackMetadataSection;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.tags.ItemTags;
|
||||
import net.minecraft.world.item.ItemDisplayContext;
|
||||
@@ -151,6 +156,13 @@ public class DataGeneratorTest
|
||||
PackOutput packOutput = gen.getPackOutput();
|
||||
CompletableFuture<HolderLookup.Provider> lookupProvider = event.getLookupProvider();
|
||||
|
||||
gen.addProvider(true, new PackMetadataGenerator(packOutput)
|
||||
.add(PackMetadataSection.TYPE, new PackMetadataSection(
|
||||
Component.literal("Forge tests resource pack"),
|
||||
DetectedVersion.BUILT_IN.getPackVersion(PackType.CLIENT_RESOURCES),
|
||||
Arrays.stream(PackType.values()).collect(Collectors.toMap(Function.identity(), DetectedVersion.BUILT_IN::getPackVersion))
|
||||
))
|
||||
);
|
||||
gen.addProvider(event.includeClient(), new Lang(packOutput));
|
||||
// Let blockstate provider see generated item models by passing its existing file helper
|
||||
ItemModelProvider itemModels = new ItemModels(packOutput, event.getExistingFileHelper());
|
||||
@@ -432,8 +444,7 @@ public class DataGeneratorTest
|
||||
@Override
|
||||
public CompletableFuture<?> run(CachedOutput cache)
|
||||
{
|
||||
super.run(cache);
|
||||
return CompletableFuture.runAsync(this::test);
|
||||
return super.run(cache).thenRun(this::test);
|
||||
}
|
||||
|
||||
private void test()
|
||||
@@ -683,7 +694,7 @@ public class DataGeneratorTest
|
||||
@Override
|
||||
public CompletableFuture<?> run(CachedOutput cache)
|
||||
{
|
||||
super.run(cache);
|
||||
var output = super.run(cache);
|
||||
List<String> errors = testModelResults(this.generatedModels, existingFileHelper, IGNORED_MODELS.stream().map(s -> new ResourceLocation(MODID, folder + "/" + s)).collect(Collectors.toSet()));
|
||||
if (!errors.isEmpty()) {
|
||||
LOGGER.error("Found {} discrepancies between generated and vanilla item models: ", errors.size());
|
||||
@@ -693,7 +704,7 @@ public class DataGeneratorTest
|
||||
throw new AssertionError("Generated item models differed from vanilla equivalents, check above errors.");
|
||||
}
|
||||
|
||||
return CompletableFuture.allOf();
|
||||
return output;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -865,35 +876,35 @@ public class DataGeneratorTest
|
||||
@Override
|
||||
public CompletableFuture<?> run(CachedOutput cache)
|
||||
{
|
||||
super.run(cache);
|
||||
this.errors.addAll(testModelResults(models().generatedModels, models().existingFileHelper, Sets.union(IGNORED_MODELS, CUSTOM_MODELS)));
|
||||
this.registeredBlocks.forEach((block, state) -> {
|
||||
if (IGNORED_BLOCKS.contains(block)) return;
|
||||
JsonObject generated = state.toJson();
|
||||
try {
|
||||
Resource vanillaResource = models().existingFileHelper.getResource(ForgeRegistries.BLOCKS.getKey(block), PackType.CLIENT_RESOURCES, ".json", "blockstates");
|
||||
JsonObject existing = GSON.fromJson(vanillaResource.openAsReader(), JsonObject.class);
|
||||
if (state instanceof VariantBlockStateBuilder) {
|
||||
compareVariantBlockstates(block, generated, existing);
|
||||
} else if (state instanceof MultiPartBlockStateBuilder) {
|
||||
compareMultipartBlockstates(block, generated, existing);
|
||||
} else {
|
||||
throw new IllegalStateException("Unknown blockstate type: " + state.getClass());
|
||||
return super.run(cache).thenRun(() -> {
|
||||
this.errors.addAll(testModelResults(models().generatedModels, models().existingFileHelper, Sets.union(IGNORED_MODELS, CUSTOM_MODELS)));
|
||||
this.registeredBlocks.forEach((block, state) -> {
|
||||
if (IGNORED_BLOCKS.contains(block)) return;
|
||||
JsonObject generated = state.toJson();
|
||||
try {
|
||||
Resource vanillaResource = models().existingFileHelper.getResource(ForgeRegistries.BLOCKS.getKey(block), PackType.CLIENT_RESOURCES, ".json", "blockstates");
|
||||
JsonObject existing = GSON.fromJson(vanillaResource.openAsReader(), JsonObject.class);
|
||||
if (state instanceof VariantBlockStateBuilder) {
|
||||
compareVariantBlockstates(block, generated, existing);
|
||||
} else if (state instanceof MultiPartBlockStateBuilder) {
|
||||
compareMultipartBlockstates(block, generated, existing);
|
||||
} else {
|
||||
throw new IllegalStateException("Unknown blockstate type: " + state.getClass());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
});
|
||||
|
||||
if (!errors.isEmpty()) {
|
||||
LOGGER.error("Found {} discrepancies between generated and vanilla models/blockstates: ", errors.size());
|
||||
for (String s : errors) {
|
||||
LOGGER.error(" {}", s);
|
||||
}
|
||||
throw new AssertionError("Generated blockstates/models differed from vanilla equivalents, check above errors.");
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
if (!errors.isEmpty()) {
|
||||
LOGGER.error("Found {} discrepancies between generated and vanilla models/blockstates: ", errors.size());
|
||||
for (String s : errors) {
|
||||
LOGGER.error(" {}", s);
|
||||
}
|
||||
throw new AssertionError("Generated blockstates/models differed from vanilla equivalents, check above errors.");
|
||||
}
|
||||
|
||||
return CompletableFuture.allOf();
|
||||
}
|
||||
|
||||
private void compareVariantBlockstates(Block block, JsonObject generated, JsonObject vanilla) {
|
||||
|
||||
Reference in new issue
Block a user