mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-17 11:05:40 +00:00
Add DeferredRegistryData to help with generating data driven registry entries.
Revive GameTest system and make all but one Forge Test mod pass.
This commit is contained in:
102 files changed
+1229
-469
No files matched your search
@@ -231,7 +231,6 @@ patcher {
|
||||
args '--launchTarget', 'forge_dev_client_data',
|
||||
'--mod', 'forge',
|
||||
'--all',
|
||||
'--validate',
|
||||
'--output', rootProject.file('src/main/generated/'),
|
||||
'--existing', sourceSets.main.resources.srcDirs[0],
|
||||
'--assetsDir', downloadAssets.output,
|
||||
|
||||
@@ -33,25 +33,17 @@
|
||||
.tooltip(tooltip)
|
||||
.build()
|
||||
)
|
||||
@@ -289,6 +_,7 @@
|
||||
if ((i & -67108864) != 0) {
|
||||
super.render(p_282860_, p_281753_, p_283539_, p_282628_);
|
||||
this.logoRenderer.renderLogo(p_282860_, this.width, f);
|
||||
+ net.minecraftforge.client.ForgeHooksClient.renderMainMenu(this, p_282860_, this.font, this.width, this.height, i);
|
||||
if (this.splash != null && !this.minecraft.options.hideSplashTexts().get()) {
|
||||
this.splash.render(p_282860_, this.width, this.font, i);
|
||||
}
|
||||
@@ -304,10 +_,18 @@
|
||||
s = s + I18n.get("menu.modded");
|
||||
}
|
||||
|
||||
- p_282860_.drawString(this.font, s, 2, this.height - 10, 16777215 | i);
|
||||
+ net.minecraftforge.internal.BrandingControl.forEachLine(true, true, (brd, brdline) ->
|
||||
+ p_282860_.drawString(this.font, brd, 2, this.height - ( 10 + brdline * (this.font.lineHeight + 1)), 16777215 | i)
|
||||
+ p_282860_.drawString(this.font, brd, 2, this.height - ( 10 + brdline * (this.font.lineHeight + 1)), 16777215 | i)
|
||||
+ );
|
||||
+
|
||||
+ net.minecraftforge.internal.BrandingControl.forEachAboveCopyrightLine((brd, brdline) ->
|
||||
+ p_282860_.drawString(this.font, brd, this.width - font.width(brd), this.height - (10 + (brdline + 1) * ( this.font.lineHeight + 1)), 16777215 | i)
|
||||
+ p_282860_.drawString(this.font, brd, this.width - font.width(brd), this.height - (10 + (brdline + 1) * ( this.font.lineHeight + 1)), 16777215 | i)
|
||||
+ );
|
||||
+
|
||||
if (this.realmsNotificationsEnabled() && f >= 1.0F) {
|
||||
|
||||
@@ -1,6 +1,50 @@
|
||||
--- a/net/minecraft/core/RegistrySetBuilder.java
|
||||
+++ b/net/minecraft/core/RegistrySetBuilder.java
|
||||
@@ -74,6 +_,10 @@
|
||||
@@ -22,7 +_,8 @@
|
||||
import net.minecraft.tags.TagKey;
|
||||
import org.apache.commons.lang3.mutable.MutableObject;
|
||||
|
||||
-public class RegistrySetBuilder {
|
||||
+public class RegistrySetBuilder implements net.minecraftforge.common.extensions.IForgeRegistrySetBuilder {
|
||||
+ private final it.unimi.dsi.fastutil.objects.Object2IntMap<ResourceKey<? extends Registry<?>>> indexes = new it.unimi.dsi.fastutil.objects.Object2IntLinkedOpenHashMap<>();
|
||||
private final List<RegistrySetBuilder.RegistryStub<?>> entries = new ArrayList<>();
|
||||
|
||||
static <T> HolderGetter<T> wrapContextLookup(final HolderLookup.RegistryLookup<T> p_255625_) {
|
||||
@@ -66,14 +_,43 @@
|
||||
public <T> RegistrySetBuilder add(
|
||||
ResourceKey<? extends Registry<T>> p_256446_, Lifecycle p_256394_, RegistrySetBuilder.RegistryBootstrap<T> p_256638_
|
||||
) {
|
||||
- this.entries.add(new RegistrySetBuilder.RegistryStub<>(p_256446_, p_256394_, p_256638_));
|
||||
+ add(new RegistrySetBuilder.RegistryStub<>(p_256446_, p_256394_, p_256638_));
|
||||
return this;
|
||||
}
|
||||
|
||||
+ // Forge: This merges two entries in this builder together, so that we can reuse vanilla boostrap methods, or potentially other modder's methods.
|
||||
+ private <T> RegistrySetBuilder.RegistryStub<T> add(RegistrySetBuilder.RegistryStub<T> entry) {
|
||||
+ int idx = indexes.getOrDefault(entry.key(), -1);
|
||||
+ if (idx != -1) {
|
||||
+ var _oldB = ((RegistrySetBuilder.RegistryStub<T>)this.entries.get(idx)).bootstrap();
|
||||
+ var _newB = entry.bootstrap();
|
||||
+ var _new = new RegistrySetBuilder.RegistryStub<>(entry.key(), entry.lifecycle(), ctx -> {
|
||||
+ _oldB.run(ctx);
|
||||
+ _newB.run(ctx);
|
||||
+ });
|
||||
+ this.entries.set(idx, _new);
|
||||
+ return _new;
|
||||
+ } else {
|
||||
+ this.indexes.put(entry.key(), this.entries.size());
|
||||
+ this.entries.add(entry);
|
||||
+ return entry;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ public RegistrySetBuilder copy() {
|
||||
+ var ret = new RegistrySetBuilder();
|
||||
+ this.entries.forEach(ret::add);
|
||||
+ return ret;
|
||||
+ }
|
||||
+
|
||||
public <T> RegistrySetBuilder add(ResourceKey<? extends Registry<T>> p_256261_, RegistrySetBuilder.RegistryBootstrap<T> p_256010_) {
|
||||
return this.add(p_256261_, Lifecycle.stable(), p_256010_);
|
||||
}
|
||||
|
||||
|
||||
+12
-1
@@ -36,7 +36,18 @@
|
||||
PackOutput.PathProvider packoutput$pathprovider = this.output.createRegistryElementsPathProvider(resourcekey);
|
||||
return CompletableFuture.allOf(
|
||||
p_358460_.listElements()
|
||||
+ .filter(holder -> this.namespacePredicate.test(holder.key().location().getNamespace()))
|
||||
+ .filter(holder -> shouldDump(holder.key()))
|
||||
.map(
|
||||
p_256105_ -> dumpValue(
|
||||
packoutput$pathprovider.json(p_256105_.key().location()),
|
||||
@@ -65,6 +_,10 @@
|
||||
);
|
||||
}
|
||||
);
|
||||
+ }
|
||||
+
|
||||
+ protected boolean shouldDump(ResourceKey<?> key) {
|
||||
+ return this.namespacePredicate.test(key.location().getNamespace());
|
||||
}
|
||||
|
||||
private static <E> CompletableFuture<?> dumpValue(
|
||||
@@ -8,3 +8,13 @@
|
||||
|
||||
private static void validateThatAllBiomeFeaturesHaveBiomeFilter(HolderLookup.Provider p_256242_) {
|
||||
validateThatAllBiomeFeaturesHaveBiomeFilter(p_256242_.lookupOrThrow(Registries.PLACED_FEATURE), p_256242_.lookupOrThrow(Registries.BIOME));
|
||||
@@ -119,5 +_,9 @@
|
||||
HolderLookup.Provider holderlookup$provider = BUILDER.build(registryaccess$frozen);
|
||||
validateThatAllBiomeFeaturesHaveBiomeFilter(holderlookup$provider);
|
||||
return holderlookup$provider;
|
||||
+ }
|
||||
+
|
||||
+ public static RegistrySetBuilder builder() {
|
||||
+ return BUILDER.copy();
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -124,7 +124,7 @@ include ':forge'
|
||||
project(":forge").projectDir = file("projects/forge")
|
||||
project(':forge').buildFileName = '../../build_forge.gradle'
|
||||
|
||||
if (!System.env.TEAMCITY_VERSION) {
|
||||
if (false && !System.env.TEAMCITY_VERSION) {
|
||||
include ':clean'
|
||||
project(':clean').projectDir = file('projects/clean')
|
||||
project(':clean').buildFileName = '../../build_clean.gradle'
|
||||
|
||||
@@ -27,7 +27,6 @@ import net.minecraft.client.gui.components.ChatComponent;
|
||||
import net.minecraft.client.gui.components.LerpingBossEvent;
|
||||
import net.minecraft.client.gui.screens.ConfirmScreen;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.client.gui.screens.TitleScreen;
|
||||
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent;
|
||||
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipPositioner;
|
||||
import net.minecraft.client.gui.screens.multiplayer.JoinMultiplayerScreen;
|
||||
@@ -50,7 +49,6 @@ import net.minecraft.client.renderer.entity.state.HumanoidRenderState;
|
||||
import net.minecraft.client.renderer.texture.SpriteContents;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlas;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.resources.language.I18n;
|
||||
import net.minecraft.client.resources.metadata.animation.FrameSize;
|
||||
import net.minecraft.client.resources.model.ModelBaker;
|
||||
import net.minecraft.client.resources.model.ModelBakery;
|
||||
@@ -132,7 +130,6 @@ import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.IExtensionPoint;
|
||||
import net.minecraftforge.fml.ModList;
|
||||
import net.minecraftforge.fml.ModLoader;
|
||||
import net.minecraftforge.fml.VersionChecker;
|
||||
import net.minecraftforge.network.NetworkContext;
|
||||
import net.minecraftforge.network.NetworkInitialization;
|
||||
import net.minecraftforge.network.NetworkRegistry;
|
||||
@@ -293,50 +290,6 @@ public class ForgeHooksClient {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialization of Forge Renderers.
|
||||
*/
|
||||
static {
|
||||
//FluidRegistry.renderIdFluid = RenderingRegistry.getNextAvailableRenderId();
|
||||
//RenderingRegistry.registerBlockHandler(RenderBlockFluid.instance);
|
||||
}
|
||||
|
||||
private static VersionChecker.Status getForgeVersionStatus() {
|
||||
final class LazyInit {
|
||||
private static final VersionChecker.Status INSTANCE = ForgeVersion.getStatus();
|
||||
|
||||
static {
|
||||
forgeStatusLine = switch (INSTANCE) {
|
||||
// case FAILED -> " Version check failed";
|
||||
// case UP_TO_DATE -> "Forge up to date";
|
||||
// case AHEAD -> "Using non-recommended Forge build, issues may arise.";
|
||||
case OUTDATED, BETA_OUTDATED -> I18n.get("forge.update.newversion", ForgeVersion.getTarget());
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
|
||||
private LazyInit() {}
|
||||
}
|
||||
|
||||
return LazyInit.INSTANCE;
|
||||
}
|
||||
|
||||
// NO-OP method, kept for bin-compat. Used in TitleScreen.java
|
||||
@Deprecated(forRemoval = true, since = "1.21.4")
|
||||
public static void renderMainMenu(TitleScreen gui, GuiGraphics graphics, Font font, int width, int height, int alpha) {
|
||||
/*
|
||||
VersionChecker.Status status = getForgeVersionStatus();
|
||||
|
||||
if (status == VersionChecker.Status.BETA || status == VersionChecker.Status.BETA_OUTDATED) {
|
||||
// Render a warning at the top of the screen
|
||||
Component line = Component.translatable("forge.update.beta.1", ChatFormatting.RED, ChatFormatting.RESET).withStyle(ChatFormatting.RED);
|
||||
graphics.drawCenteredString(font, line, width / 2, 4, 0xFFFFFF | alpha);
|
||||
line = Component.translatable("forge.update.beta.2");
|
||||
graphics.drawCenteredString(font, line, width / 2, 4 + (font.lineHeight + 1), 0xFFFFFF | alpha);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
public static String forgeStatusLine;
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -412,7 +412,8 @@ public enum ForgeRenderTypes {
|
||||
/**
|
||||
* Use {@link #TEXT_INTENSITY_SEE_THROUGH} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
@SuppressWarnings("unused")
|
||||
@Deprecated(forRemoval = true, since = "1.21.5")
|
||||
public static Function<ResourceLocation, RenderType> TEXT_INTENSITY_SEETHROUGH = TEXT_INTENSITY_SEE_THROUGH;
|
||||
private static RenderType getTextIntensitySeeThrough(ResourceLocation locationIn) {
|
||||
return create(
|
||||
|
||||
@@ -18,8 +18,6 @@ import java.util.stream.Collectors;
|
||||
import net.minecraftforge.client.gui.widget.ScrollPanel;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import com.mojang.blaze3d.vertex.Tesselator;
|
||||
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
@@ -22,6 +22,18 @@ public class DatapackBuiltinEntriesProvider extends RegistriesDatapackGenerator
|
||||
|
||||
private final CompletableFuture<HolderLookup.Provider> fullRegistries;
|
||||
|
||||
/**
|
||||
* Constructs a new datapack provider which generates all registry objects
|
||||
* from the provided mods using the holder.
|
||||
*
|
||||
* @param output the target directory of the data generator
|
||||
* @param registries a future of patched registries
|
||||
* @param modId The mod id to generate the dynamic registry objects of
|
||||
*/
|
||||
public DatapackBuiltinEntriesProvider(PackOutput output, CompletableFuture<RegistrySetBuilder.PatchedRegistries> registries, String modId) {
|
||||
this(output, registries, Set.of(modId));
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new datapack provider which generates all registry objects
|
||||
* from the provided mods using the holder.
|
||||
@@ -35,6 +47,20 @@ public class DatapackBuiltinEntriesProvider extends RegistriesDatapackGenerator
|
||||
this.fullRegistries = registries.thenApply(RegistrySetBuilder.PatchedRegistries::full);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new datapack provider which generates all registry objects
|
||||
* from the provided mods using the holder. All entries that need to be
|
||||
* bootstrapped are provided within the {@link RegistrySetBuilder}.
|
||||
*
|
||||
* @param output the target directory of the data generator
|
||||
* @param registries a future of a lookup for registries and their objects
|
||||
* @param registryBuilder a builder containing the dynamic registry objects added by this provider
|
||||
* @param modId The mod id to generate the dynamic registry objects of
|
||||
*/
|
||||
public DatapackBuiltinEntriesProvider(PackOutput output, CompletableFuture<HolderLookup.Provider> registries, RegistrySetBuilder registryBuilder, String modId) {
|
||||
this(output, registries, registryBuilder, Set.of(modId));
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new datapack provider which generates all registry objects
|
||||
* from the provided mods using the holder. All entries that need to be
|
||||
|
||||
@@ -87,7 +87,7 @@ public interface IForgeBlockEntity extends ICapabilityProvider {
|
||||
bb = AABB.encapsulatingFullBlocks(pos.offset(-1, 0, -1), pos.offset(1, 0, 1));
|
||||
} else if (block == Blocks.STRUCTURE_BLOCK) {
|
||||
bb = INFINITE_EXTENT_AABB;
|
||||
} else if (block != null && block != Blocks.BEACON) {
|
||||
} else if (block != null && block != Blocks.BEACON && block != Blocks.TEST_INSTANCE_BLOCK) {
|
||||
AABB cbb = null;
|
||||
try {
|
||||
VoxelShape collisionShape = state.getCollisionShape(self().getLevel(), pos);
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.common.extensions;
|
||||
|
||||
import com.mojang.serialization.Lifecycle;
|
||||
|
||||
import net.minecraft.core.RegistrySetBuilder;
|
||||
import net.minecraftforge.registries.DeferredRegisterData;
|
||||
|
||||
public interface IForgeRegistrySetBuilder {
|
||||
private RegistrySetBuilder self() {
|
||||
return (RegistrySetBuilder)this;
|
||||
}
|
||||
|
||||
default <T> RegistrySetBuilder add(DeferredRegisterData<T> dr) {
|
||||
return self().add(dr.getRegistryKey(), dr);
|
||||
}
|
||||
|
||||
default <T> RegistrySetBuilder add(DeferredRegisterData<T> dr, Lifecycle lifecycle) {
|
||||
return self().add(dr.getRegistryKey(), lifecycle, dr);
|
||||
}
|
||||
}
|
||||
@@ -6,46 +6,31 @@
|
||||
package net.minecraftforge.gametest;
|
||||
|
||||
import net.minecraft.SharedConstants;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.gametest.framework.GameTestEnvironments;
|
||||
import net.minecraft.gametest.framework.GameTestHelper;
|
||||
import net.minecraft.gametest.framework.GameTestInstance;
|
||||
import net.minecraft.gametest.framework.TestData;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraftforge.fml.ModList;
|
||||
import net.minecraftforge.fml.ModLoader;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.loading.FMLLoader;
|
||||
import net.minecraftforge.fml.util.ObfuscationReflectionHelper;
|
||||
import net.minecraftforge.forgespi.language.ModFileScanData;
|
||||
import net.minecraftforge.forgespi.language.ModFileScanData.AnnotationData;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.objectweb.asm.Type;
|
||||
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* Internal class used to glue mods into the game test framework.
|
||||
* Modders should use the supplied annotations and DeferredRegister
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
@ApiStatus.Internal
|
||||
public class ForgeGameTestHooks {
|
||||
private static boolean registeredGametests = false;
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
private static final Type GAME_TEST_HOLDER = Type.getType(GameTestHolder.class);
|
||||
private static MethodHandles.Lookup LOOKUP = MethodHandles.lookup();
|
||||
|
||||
public static boolean isGametestEnabled() {
|
||||
return !FMLLoader.isProduction() && (SharedConstants.IS_RUNNING_IN_IDE || isGametestServer() || Boolean.getBoolean("forge.enableGameTest"));
|
||||
@@ -55,78 +40,45 @@ public class ForgeGameTestHooks {
|
||||
return !FMLLoader.isProduction() && Boolean.getBoolean("forge.gameTestServer");
|
||||
}
|
||||
|
||||
/*
|
||||
@SuppressWarnings("deprecation")
|
||||
public static void registerGametests() {
|
||||
if (!registeredGametests && isGametestEnabled() && ModLoader.isLoadingStateValid()) {
|
||||
Set<String> enabledNamespaces = getEnabledNamespaces();
|
||||
LOGGER.info("Enabled Gametest Namespaces: {}", enabledNamespaces);
|
||||
|
||||
Set<Method> gameTestMethods = new HashSet<>();
|
||||
RegisterGameTestsEvent event = new RegisterGameTestsEvent(gameTestMethods);
|
||||
|
||||
ModLoader.get().postEvent(event);
|
||||
|
||||
ModList.get().getAllScanData().stream()
|
||||
.map(ModFileScanData::getAnnotations)
|
||||
.flatMap(Collection::stream)
|
||||
.filter(a -> GAME_TEST_HOLDER.equals(a.annotationType()))
|
||||
.forEach(a -> addGameTestMethods(a, gameTestMethods));
|
||||
|
||||
for (Method gameTestMethod : gameTestMethods) {
|
||||
GameTestRegistry.register(gameTestMethod, enabledNamespaces);
|
||||
}
|
||||
|
||||
registeredGametests = true;
|
||||
}
|
||||
}
|
||||
|
||||
private static Set<String> getEnabledNamespaces() {
|
||||
String enabledNamespacesStr = System.getProperty("forge.enabledGameTestNamespaces");
|
||||
if (enabledNamespacesStr == null)
|
||||
return Set.of();
|
||||
|
||||
return Arrays.stream(enabledNamespacesStr.split(",")).filter(s -> !s.isBlank()).collect(Collectors.toUnmodifiableSet());
|
||||
}
|
||||
|
||||
private static void addGameTestMethods(AnnotationData annotationData, Set<Method> gameTestMethods) {
|
||||
try {
|
||||
Class<?> clazz = Class.forName(annotationData.clazz().getClassName(), true, ForgeGameTestHooks.class.getClassLoader());
|
||||
|
||||
gameTestMethods.addAll(Arrays.asList(clazz.getDeclaredMethods()));
|
||||
} catch (ClassNotFoundException e) {
|
||||
// Should not be possible
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static String getTestName(Method method, GameTest meta) {
|
||||
var name = method.getName().toLowerCase(Locale.ENGLISH);
|
||||
return getPrefixed(method, name);
|
||||
}
|
||||
|
||||
private static String getPrefixed(Method method, String name) {
|
||||
var prefix = getPrefix(method);
|
||||
return prefix == null ? name : prefix + '.' + name;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static String getPrefix(Method method) {
|
||||
private static boolean shouldPrefix(Method method) {
|
||||
var cls = method.getDeclaringClass();
|
||||
var shouldPrefix = !method.isAnnotationPresent(GameTestDontPrefix.class) &&
|
||||
!cls.isAnnotationPresent(GameTestDontPrefix.class);
|
||||
if (!shouldPrefix)
|
||||
return null;
|
||||
return !method.isAnnotationPresent(GameTestDontPrefix.class) &&
|
||||
!cls.isAnnotationPresent(GameTestDontPrefix.class);
|
||||
}
|
||||
|
||||
return getPrefix(cls);
|
||||
private static String snake(String input) {
|
||||
var result = new StringBuilder();
|
||||
for (char c : input.toCharArray()) {
|
||||
if (Character.isUpperCase(c)) {
|
||||
if (!result.isEmpty())
|
||||
result.append('_');
|
||||
result.append(Character.toLowerCase(c));
|
||||
} else
|
||||
result.append(c);
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
private static String getPrefix(Class<?> cls) {
|
||||
var prefix = cls.getAnnotation(GameTestPrefix.class);
|
||||
if (prefix != null)
|
||||
return prefix.value();
|
||||
return prefix.value() + '/';
|
||||
|
||||
var holder = cls.getAnnotation(GameTestHolder.class);
|
||||
var mod = cls.getAnnotation(Mod.class);
|
||||
if (mod != null) {
|
||||
var holder = cls.getAnnotation(GameTestNamespace.class);
|
||||
if (holder != null && !holder.value().isEmpty())
|
||||
return mod.value() + '/';
|
||||
}
|
||||
|
||||
|
||||
return cls.getSimpleName().toLowerCase(Locale.ENGLISH);
|
||||
}
|
||||
|
||||
private static String getNamespace(Class<?> cls) {
|
||||
var holder = cls.getAnnotation(GameTestNamespace.class);
|
||||
if (holder != null && !holder.value().isEmpty())
|
||||
return holder.value();
|
||||
|
||||
@@ -134,21 +86,32 @@ public class ForgeGameTestHooks {
|
||||
if (mod != null)
|
||||
return mod.value();
|
||||
|
||||
return cls.getSimpleName().toLowerCase(Locale.ENGLISH);
|
||||
throw new IllegalArgumentException("Could not find modid for " + cls.getName());
|
||||
}
|
||||
|
||||
private static ResourceLocation key(String namespace, String path) {
|
||||
return path.indexOf(':') == -1 ? ResourceLocation.parse(path) : ResourceLocation.fromNamespaceAndPath(namespace, path);
|
||||
private static ResourceLocation key(String namespace, String prefix, String path) {
|
||||
if (path.indexOf(':') != -1) {
|
||||
var rl = ResourceLocation.parse(path);
|
||||
if (!prefix.isEmpty())
|
||||
return rl.withPrefix(prefix);
|
||||
return rl;
|
||||
}
|
||||
|
||||
return ResourceLocation.fromNamespaceAndPath(namespace, prefix + path);
|
||||
}
|
||||
|
||||
public static Map<ResourceLocation, GameTestInstance> gatherTests(Class<?> root) {
|
||||
String prefix = getPrefix(root);
|
||||
var seen = new HashSet<ResourceLocation>();
|
||||
public record TestReference(Consumer<GameTestHelper> consumer, TestData<ResourceLocation> data) {}
|
||||
|
||||
public static Map<ResourceLocation, TestReference> gatherTests(Class<?> root, Object instance) {
|
||||
var ret = new HashMap<ResourceLocation, TestReference>();
|
||||
var seen = new HashSet<String>();
|
||||
String class_prefix = getPrefix(root);
|
||||
String namespace = getNamespace(root);
|
||||
Class<?> cls = root;
|
||||
|
||||
while (cls != Object.class) {
|
||||
for (var method : cls.getDeclaredMethods()) {
|
||||
if (cls != root && Modifier.isStatic(method.getModifiers()))
|
||||
if (!Modifier.isPublic(method.getModifiers()) || (cls != root && Modifier.isStatic(method.getModifiers())))
|
||||
continue;
|
||||
|
||||
var gametest = method.getAnnotation(GameTest.class);
|
||||
@@ -160,40 +123,73 @@ public class ForgeGameTestHooks {
|
||||
if (method.getParameterCount() != 1 || method.getParameterTypes()[0] != GameTestHelper.class)
|
||||
throw new IllegalStateException("Invalid @GameTest function " + owner + " incorrect arguments");
|
||||
|
||||
var testName = key(prefix, gametest.name().isEmpty() ? method.getName() : gametest.name());
|
||||
if (!seen.add(testName)) {
|
||||
if (!Modifier.isStatic(method.getModifiers()))
|
||||
continue;
|
||||
throw new IllegalStateException("Failed to register test, already seen " + testName + ", for " + owner);
|
||||
}
|
||||
// We don't want parent methods
|
||||
if (!seen.add(method.getName()))
|
||||
continue;
|
||||
|
||||
if (gametest.type() == GameTest.Type.FUNCTION) {
|
||||
var funcName = key(prefix, gametest.function());
|
||||
var func = BuiltInRegistries.TEST_FUNCTION.get(funcName).orElse(null);
|
||||
var prefix = shouldPrefix(method) ? class_prefix : "";
|
||||
var name = key(namespace, prefix, gametest.name().isEmpty() ? snake(method.getName()) : gametest.name());
|
||||
|
||||
if (func == null)
|
||||
throw new IllegalStateException("Could not find referenced function `" + funcName + "` for " + owner);
|
||||
var structure = GameTest.DEFAULT_STRUCTURE.equals(gametest.structure())
|
||||
? ResourceLocation.parse(gametest.structure())
|
||||
: key(namespace, "", gametest.structure());
|
||||
|
||||
var data = getTestData(prefix, owner, gametest.data());
|
||||
var env = GameTestEnvironments.DEFAULT.equals(gametest.environment())
|
||||
? ResourceLocation.withDefaultNamespace(gametest.environment())
|
||||
: key(namespace, "", gametest.environment());
|
||||
|
||||
var data = new TestData<ResourceLocation>(
|
||||
env,
|
||||
structure,
|
||||
gametest.maxTicks(),
|
||||
gametest.setupTicks(),
|
||||
gametest.required(),
|
||||
gametest.rotation(),
|
||||
gametest.manualOnly(),
|
||||
gametest.maxAttempts(),
|
||||
gametest.requiredSuccesses(),
|
||||
gametest.skyAccess()
|
||||
);
|
||||
|
||||
} else if (gametest.type() == GameTest.Type.BLOCK) {
|
||||
MethodHandle handle = unreflect(method, owner);
|
||||
|
||||
Consumer<GameTestHelper> func;
|
||||
if (Modifier.isStatic(method.getModifiers())) {
|
||||
func = ctx -> {
|
||||
try {
|
||||
handle.invoke(ctx);
|
||||
} catch (Throwable e) {
|
||||
sneakyThrow(e);
|
||||
}
|
||||
};
|
||||
} else {
|
||||
throw new IllegalStateException("Could not determine GameTest type for " + root.getName() + " -> " + gametest.type());
|
||||
func = ctx -> {
|
||||
try {
|
||||
handle.invoke(instance, ctx);
|
||||
} catch (Throwable e) {
|
||||
sneakyThrow(e);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
ret.put(name, new TestReference(func, data));
|
||||
}
|
||||
|
||||
cls = cls.getSuperclass();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
private static MethodHandle unreflect(Method method, String owner) {
|
||||
try {
|
||||
return LOOKUP.unreflect(method);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new IllegalArgumentException("Failed to unreflect " + owner, e);
|
||||
}
|
||||
}
|
||||
|
||||
private static TestData<?> getTestData(String prefix, String owner, GameTest.Data data) {
|
||||
var envName = key(prefix, data.environment());
|
||||
var env = BuiltInRegistries.TEST_ENVIRONMENT
|
||||
@SuppressWarnings("unchecked")
|
||||
private static <E extends Throwable> void sneakyThrow(Throwable e) throws E {
|
||||
throw (E)e;
|
||||
}
|
||||
*/
|
||||
}
|
||||
@@ -6,39 +6,23 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import net.minecraft.gametest.framework.GameTestEnvironments;
|
||||
import net.minecraft.world.level.block.Rotation;
|
||||
|
||||
@Retention(RUNTIME)
|
||||
@Target(METHOD)
|
||||
public @interface GameTest {
|
||||
String name() default "";
|
||||
String function() default "";
|
||||
Type type() default Type.BLOCK;
|
||||
Data data() default @Data;
|
||||
|
||||
|
||||
|
||||
int rotationSteps() default 0;
|
||||
|
||||
|
||||
public enum Type {
|
||||
BLOCK,
|
||||
FUNCTION;
|
||||
}
|
||||
|
||||
/**
|
||||
* Annotation definitions for {@link net.minecraft.gametest.framework.TestData}
|
||||
*/
|
||||
public @interface Data {
|
||||
String environment() default "";
|
||||
String structure() default "forge:empty3x3";
|
||||
int maxTicks() default Integer.MAX_VALUE;
|
||||
int setupTicks() default 0;
|
||||
boolean required() default false;
|
||||
Rotation rotation() default Rotation.NONE;
|
||||
boolean manualOnly() default false;
|
||||
int maxAttempts() default 1;
|
||||
int requiredSuccesses() default 1;
|
||||
boolean skyAccess() default false;
|
||||
}
|
||||
static final String DEFAULT_STRUCTURE = "forge:empty3x3x3";
|
||||
String environment() default GameTestEnvironments.DEFAULT;
|
||||
String structure() default DEFAULT_STRUCTURE;
|
||||
int maxTicks() default 100;
|
||||
int setupTicks() default 0;
|
||||
boolean required() default true;
|
||||
Rotation rotation() default Rotation.NONE;
|
||||
boolean manualOnly() default false;
|
||||
int maxAttempts() default 1;
|
||||
int requiredSuccesses() default 1;
|
||||
boolean skyAccess() default false;
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.gametest;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Marks a class as containing game tests that should be registered automatically.
|
||||
* All methods annotated with {@link GameTest} or {@link GameTestGenerator} will be registered.
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.TYPE)
|
||||
public @interface GameTestHolder {
|
||||
/**
|
||||
* The default batch for all tests in this class that do not manually specify one.
|
||||
* It it recommended that this includes your mod id.
|
||||
* <br/>
|
||||
* This is also used when filtering out which batches to run during automation.
|
||||
* the filters will be tested against the prefix of the batch name. So it is
|
||||
* recommended to be structured in a logical fashion.
|
||||
* <pre>
|
||||
* Examples:
|
||||
* forge.tags.items
|
||||
* forge.tags.blocks
|
||||
* forge.global_loot_modifiers.block_drops
|
||||
* forge.global_loot_modifiers.tool_filter
|
||||
* </pre>
|
||||
*
|
||||
* The filter 'forge.global_loot_modifiers' would execute both the block_drops and tool_filter batches.
|
||||
* <p>
|
||||
* This will default to your modid if it is on the same class that is annotated with {@link net.minecraftforge.fml.common.Mod @Mod}
|
||||
*/
|
||||
String value() default "";
|
||||
|
||||
/**
|
||||
* Used as the default namespace to use for {@link GameTest#template() templates} for any game tests in the class.
|
||||
* Defaults to the modid if in a class with @Mod or else defaults to "minecraft"
|
||||
*/
|
||||
String namespace() default "";
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.gametest;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Marks a class as containing game tests that should be registered automatically.
|
||||
* All methods annotated with {@link GameTest} or {@link GameTestGenerator} will be registered.
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.TYPE)
|
||||
public @interface GameTestNamespace {
|
||||
/**
|
||||
* The default namespace for all tests in this class that do not manually specify one.
|
||||
* It it recommended that this is your modid, but if you have multiple test mods that
|
||||
* you want to group together you can use this to do so.
|
||||
* <p>
|
||||
* This will default to your modid if it is on the same class that is annotated with {@link net.minecraftforge.fml.common.Mod @Mod}
|
||||
*/
|
||||
String value() default "";
|
||||
}
|
||||
@@ -0,0 +1,309 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.registries;
|
||||
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.RegistrySetBuilder.RegistryBootstrap;
|
||||
import net.minecraft.data.worldgen.BootstrapContext;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraftforge.common.extensions.IForgeRegistrySetBuilder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import com.mojang.serialization.Lifecycle;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* Utility class to help with managing registry entries.
|
||||
* Maintains a list of all suppliers for entries and registers them during the proper Register event.
|
||||
* Suppliers should return NEW instances every time.
|
||||
*
|
||||
*Example Usage:
|
||||
*<pre>{@code
|
||||
* public static final DeferredRegisterData<ConfiguredFeature<?, ?>> CONFIGURED_FEATURES = DeferredRegisterData.create(Registries.CONFIGURED_FEATURE, MOD_ID);
|
||||
* private static final RegistryObject<ConfiguredFeature<?, ?>> CONFIGURED = CONFIGURED_FEATURES.register("configured", () ->
|
||||
* new ConfiguredFeature<>(Feature.NO_OP, NoneFeatureConfiguration.INSTANCE)
|
||||
* );
|
||||
*
|
||||
* public static final DeferredRegisterData<PlacedFeature> PLACED_FEATURES = DeferredRegisterData.create(Registries.PLACED_FEATURE, MOD_ID);
|
||||
* private static final RegistryObject<PlacedFeature> PLACED = PLACED_FEATURES.register("placed", () ->
|
||||
* new PlacedFeature(CONFIGURED.getHolder().orElseThrow(), List.of())
|
||||
* );
|
||||
*
|
||||
* public static final DeferredRegisterData<BiomeModifier> BIOME_MODIFIERS = DeferredRegisterData.create(ForgeRegistries.Keys.BIOME_MODIFIERS, MOD_ID);
|
||||
* @SuppressWarnings("unused")
|
||||
* private static final RegistryObject<BiomeModifier> MODIFIER = BIOME_MODIFIERS.register("modifier", ctx -> {
|
||||
* return new ForgeBiomeModifiers.AddFeaturesBiomeModifier(
|
||||
* ctx.lookup(Registries.BIOME).getOrThrow(BiomeTags.IS_OVERWORLD),
|
||||
* HolderSet.direct(PLACED.getHolder().orElseThrow()),
|
||||
* GenerationStep.Decoration.UNDERGROUND_ORES
|
||||
* );
|
||||
* });
|
||||
*
|
||||
* protected void generateDataRegistries(GatherDataEvent event) {
|
||||
* var registrySet = VanillaRegistries.builder()
|
||||
* .add(CONFIGURED_FEATURES)
|
||||
* .add(PLACED_FEATURES)
|
||||
* .add(BIOME_MODIFIERS);
|
||||
*
|
||||
* event.getGenerator().addProvider(event.includeServer(), new DatapackBuiltinEntriesProvider(
|
||||
* gen.getPackOutput(), event.getLookupProvider(), registrySet, modid)
|
||||
* );
|
||||
* }
|
||||
*
|
||||
*}</pre>
|
||||
*
|
||||
* @param <T> The base registry type
|
||||
*/
|
||||
public class DeferredRegisterData<T> implements RegistryBootstrap<T> {
|
||||
|
||||
/**
|
||||
* DeferredRegister factory for data driven registries. This will not create objects during the normal registry events.
|
||||
* This is meant to be used as helper for creating a {@link RegistrySetBuilder}, and thus should <string>NOT</strong>
|
||||
* be registered to and {@link EventBus}. But instead used with {@link IForgeRegistrySetBuilder#add(DeferredRegister)}.
|
||||
*
|
||||
* @param registryKey the key of the registry to reference.
|
||||
* @param modid the namespace for all objects registered to this DeferredRegister
|
||||
*/
|
||||
public static <B> DeferredRegisterData.Builder<B> builder(ResourceKey<? extends Registry<B>> registryKey, String modid) {
|
||||
requireNonNull("registryKey", registryKey);
|
||||
requireNonNull("modid", modid);
|
||||
return new Builder<>(registryKey, modid);
|
||||
}
|
||||
|
||||
/**
|
||||
* DeferredRegister factory for data driven registries. This will not create objects during the normal registry events.
|
||||
* This is meant to be used as helper for creating a {@link RegistrySetBuilder}, and thus should <string>NOT</strong>
|
||||
* be registered to and {@link EventBus}. But instead used with {@link IForgeRegistrySetBuilder#add(DeferredRegister)}.
|
||||
*
|
||||
* @param registryKey the key of the registry to reference.
|
||||
* @param modid the namespace for all objects registered to this DeferredRegister
|
||||
*
|
||||
* @return A built instance using the default values for the builder. Equivalent to {@code builder(registryKey, modid).build()}
|
||||
*/
|
||||
public static <B> DeferredRegisterData<B> create(ResourceKey<? extends Registry<B>> registryKey, String modid) {
|
||||
return new Builder<>(registryKey, modid).build();
|
||||
}
|
||||
|
||||
public static class Builder<T> {
|
||||
private final ResourceKey<? extends Registry<T>> registryKey;
|
||||
private final String modid;
|
||||
|
||||
private Lifecycle lifecycle = Lifecycle.stable();
|
||||
|
||||
private Builder(ResourceKey<? extends Registry<T>> registryKey, String modid) {
|
||||
this.registryKey = registryKey;
|
||||
this.modid = modid;
|
||||
}
|
||||
|
||||
/**
|
||||
* By default will register objects as {@link Lifecycle#stable()}
|
||||
*/
|
||||
public Builder<T> lifecycle(Lifecycle value) {
|
||||
this.lifecycle = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DeferredRegisterData<T> build() {
|
||||
return new DeferredRegisterData<>(this);
|
||||
}
|
||||
}
|
||||
|
||||
private final ResourceKey<? extends Registry<T>> registryKey;
|
||||
private final String modid;
|
||||
private final Lifecycle lifecycle;
|
||||
private final Map<RegistryObject<T>, Function<BootstrapContext<T>, ? extends T>> entries = new LinkedHashMap<>();
|
||||
private final Set<RegistryObject<T>> entriesView = Collections.unmodifiableSet(entries.keySet());
|
||||
|
||||
private boolean beenBuilt = false;
|
||||
|
||||
private DeferredRegisterData(Builder<T> builder) {
|
||||
this.registryKey = builder.registryKey;
|
||||
this.modid = builder.modid;
|
||||
this.lifecycle = builder.lifecycle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a RegistryObject for the specified name, which will be filled when the {@link RegistrySetBuilder} is built.
|
||||
* This is useful is you need references to entries added not using the {@link DeferredRegisterData} system.
|
||||
*
|
||||
* @param name The entry's name, it will automatically have the modid prefixed.
|
||||
*/
|
||||
public <I extends T> RegistryObject<I> register(final String name) {
|
||||
return registerInternal(name, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new supplier to the list of entries to be registered, and returns a RegistryObject that will be populated with the created entry automatically.
|
||||
* If you need context from other data registries, use {@link DeferredRegisterData#register(String, Function)}
|
||||
*
|
||||
* @param name The new entry's name, it will automatically have the modid prefixed.
|
||||
* @param factory A factory for the new entry, it should return a new instance every time it is called.
|
||||
* @return A RegistryObject that will be updated with when the entries in the registry change.
|
||||
* @see #register(String, Supplier)
|
||||
*/
|
||||
public <I extends T> RegistryObject<I> register(final String name, final Supplier<? extends I> factory) {
|
||||
return register(name, ctx -> factory.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new entry to be registered, the Function will be invoked with the {@link BootstrapContext} which allows lookup of other registry entries.
|
||||
* Returns a RegistryObject that will be populated with the created entry automatically.
|
||||
*
|
||||
* @param name The new entry's name, it will automatically have the modid prefixed.
|
||||
* @param factory A factory for the new entry, it should return a new instance every time it is called.
|
||||
* @return A RegistryObject that will be updated with when the entries in the registry change.
|
||||
*/
|
||||
public <I extends T> RegistryObject<I> register(final String name, final Function<BootstrapContext<T>, ? extends I> factory) {
|
||||
requireNonNull("factory", factory);
|
||||
return registerInternal(name, factory);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <I extends T> RegistryObject<I> registerInternal(final String name, final Function<BootstrapContext<T>, ? extends I> factory) {
|
||||
if (beenBuilt)
|
||||
throw new IllegalStateException("Cannot register new entries to DeferredRegister after it has been used. You should use this in a static context");
|
||||
|
||||
requireNonNull("name", name);
|
||||
var key = ResourceLocation.fromNamespaceAndPath(modid, name);
|
||||
|
||||
RegistryObject<I> ret = new RegistryObject<>(key, this.registryKey, this.modid);
|
||||
|
||||
if (entries.containsKey((RegistryObject<T>)ret))
|
||||
throw new IllegalArgumentException("Duplicate registration " + name);
|
||||
|
||||
entries.put((RegistryObject<T>)ret, factory);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a ResourceKey based on the current modid and provided path as the location and the registry name linked to this DeferredRegister.
|
||||
* To control the namespace, use {@link #key(ResourceLocation)}.
|
||||
*
|
||||
* @see #key(ResourceLocation)
|
||||
*/
|
||||
@NotNull
|
||||
public ResourceKey<T> key(@NotNull String path) {
|
||||
requireNonNull("path", path);
|
||||
return key(ResourceLocation.fromNamespaceAndPath(this.modid, path));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a tag key based on the provided resource location and the registry name linked to this DeferredRegister.
|
||||
* To use the current modid as the namespace, use {@link #createTagKey(String)}.
|
||||
*
|
||||
* @see #key(String)
|
||||
*/
|
||||
@NotNull
|
||||
public ResourceKey<T> key(@NotNull ResourceLocation location) {
|
||||
requireNonNull("location", location);
|
||||
return ResourceKey.create(getRegistryKey(), location);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a tag key based on the current modid and provided path as the location and the registry name linked to this DeferredRegister.
|
||||
* To control the namespace, use {@link #createTagKey(ResourceLocation)}.
|
||||
*
|
||||
* @see #createTagKey(ResourceLocation)
|
||||
* @see #createOptionalTagKey(String, Set)
|
||||
*/
|
||||
@NotNull
|
||||
public TagKey<T> createTagKey(@NotNull String path) {
|
||||
requireNonNull("path", path);
|
||||
return createTagKey(ResourceLocation.fromNamespaceAndPath(this.modid, path));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a tag key based on the provided resource location and the registry name linked to this DeferredRegister.
|
||||
* To use the current modid as the namespace, use {@link #createTagKey(String)}.
|
||||
*
|
||||
* @see #createTagKey(String)
|
||||
* @see #createOptionalTagKey(ResourceLocation, Set)
|
||||
*/
|
||||
@NotNull
|
||||
public TagKey<T> createTagKey(@NotNull ResourceLocation location) {
|
||||
requireNonNull("location", location);
|
||||
return TagKey.create(this.registryKey, location);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The {@link Lifecycle} that objects are registered as.
|
||||
*/
|
||||
public Lifecycle getLifecycle() {
|
||||
return this.lifecycle;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The unmodifiable view of registered entries. Useful for bulk operations on all values.
|
||||
*/
|
||||
public Collection<RegistryObject<T>> getEntries() {
|
||||
return this.entriesView;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The registry key stored in this deferred register. Useful for creating new deferred registers based on an existing one.
|
||||
*/
|
||||
public ResourceKey<? extends Registry<T>> getRegistryKey() {
|
||||
return this.registryKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The registry name stored in this deferred register. Useful for creating new deferred registers based on an existing one.
|
||||
*/
|
||||
@NotNull
|
||||
public ResourceLocation getRegistryName() {
|
||||
return this.registryKey.location();
|
||||
}
|
||||
|
||||
private static <T> T requireNonNull(String name, T value) {
|
||||
if (value == null)
|
||||
throw new IllegalArgumentException(name + " can not be null");
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the key is registered to a valid object factory, useful for data generation knowing if this actually declares data.
|
||||
*/
|
||||
public boolean isDeclared(ResourceKey<T> key) {
|
||||
for (var entry : this.entries.entrySet()) {
|
||||
if (entry.getKey().getKey() == key)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build this DeferredRegister using the supplied {@link BoostrapContext}. This is meant to be called by {@link RegistrySetBuilder} by adding this
|
||||
* function to the builder using {@link RegistrySetBuilder#add(ResourceKey, RegistryBootstrap)} or {@link IForgeRegistrySetBuilder#add(DeferredRegisterData)}
|
||||
*/
|
||||
@Override
|
||||
public void run(BootstrapContext<T> context) {
|
||||
beenBuilt = true;
|
||||
|
||||
var lookup = context.lookup(this.registryKey);
|
||||
|
||||
for (var e : entries.entrySet()) {
|
||||
var ro = e.getKey();
|
||||
T value;
|
||||
if (e.getValue() != null) {
|
||||
value = e.getValue().apply(context);
|
||||
context.register(ro.getKey(), value, this.lifecycle);
|
||||
} else
|
||||
value = lookup.get(ro.getKey()).map(Holder::get).orElse(null);
|
||||
|
||||
ro.updateReference(value, () -> lookup.getOrThrow(ro.getKey()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -175,6 +175,15 @@ public final class RegistryObject<T> implements Supplier<T> {
|
||||
this.updateReference(registryName);
|
||||
}
|
||||
|
||||
/** Internal constructor used for {@link DeferredRegisterData} */
|
||||
RegistryObject(final ResourceLocation name, final ResourceKey<? extends Registry<? super T>> registry, final String modid) {
|
||||
this.name = name;
|
||||
@SuppressWarnings("unchecked")
|
||||
var typed = (ResourceKey<Registry<T>>)registry;
|
||||
this.key = ResourceKey.create(typed, name);
|
||||
this.optionalRegistry = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the wrapped object in the registry.
|
||||
* This value will automatically be updated when the backing registry is updated.
|
||||
@@ -265,6 +274,11 @@ public final class RegistryObject<T> implements Supplier<T> {
|
||||
this.value = null;
|
||||
}
|
||||
|
||||
void updateReference(T value, Supplier<Holder<T>> holder) {
|
||||
this.value = value;
|
||||
this.holder = holder;
|
||||
}
|
||||
|
||||
private static boolean registryExists(ResourceLocation registryName) {
|
||||
return RegistryManager.ACTIVE.getRegistry(registryName) != null
|
||||
|| BuiltInRegistries.REGISTRY.containsKey(registryName);
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"type": "minecraft:function",
|
||||
"environment": "minecraft:default",
|
||||
"function": "forge:automatic_module/correct_name",
|
||||
"max_ticks": 100,
|
||||
"structure": "forge:empty3x3x3"
|
||||
}
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"type": "forge:add_features",
|
||||
"biomes": "#minecraft:is_overworld",
|
||||
"features": "biome_test_mod:overworld_netherite_block_ore_placed",
|
||||
"features": "biome_test:placed",
|
||||
"step": "underground_ores"
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"type": "minecraft:no_op",
|
||||
"config": {}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"feature": "biome_test:configured",
|
||||
"placement": []
|
||||
}
|
||||
-18
@@ -1,18 +0,0 @@
|
||||
{
|
||||
"type": "minecraft:replace_single_block",
|
||||
"config": {
|
||||
"targets": [
|
||||
{
|
||||
"state": {
|
||||
"Name": "minecraft:netherite_block"
|
||||
},
|
||||
"target": {
|
||||
"block_state": {
|
||||
"Name": "minecraft:air"
|
||||
},
|
||||
"predicate_type": "minecraft:blockstate_match"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
-15
@@ -1,15 +0,0 @@
|
||||
{
|
||||
"feature": "biome_test_mod:overworld_netherite_block_ore",
|
||||
"placement": [
|
||||
{
|
||||
"type": "minecraft:count",
|
||||
"count": 1
|
||||
},
|
||||
{
|
||||
"type": "minecraft:height_range",
|
||||
"height": {
|
||||
"absolute": 100
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"type": "minecraft:function",
|
||||
"environment": "minecraft:default",
|
||||
"function": "forge:chorus_block_placement/custom_placeable_block",
|
||||
"max_ticks": 100,
|
||||
"structure": "forge:empty3x3x3"
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"type": "minecraft:function",
|
||||
"environment": "minecraft:default",
|
||||
"function": "forge:closed_module_test/can_reflect_exported",
|
||||
"max_ticks": 100,
|
||||
"structure": "forge:empty3x3x3"
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"type": "minecraft:function",
|
||||
"environment": "minecraft:default",
|
||||
"function": "forge:closed_module_test/can_reflect_opened_internal",
|
||||
"max_ticks": 100,
|
||||
"structure": "forge:empty3x3x3"
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"type": "minecraft:function",
|
||||
"environment": "minecraft:default",
|
||||
"function": "forge:closed_module_test/cant_reflect_internal",
|
||||
"max_ticks": 100,
|
||||
"structure": "forge:empty3x3x3"
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"type": "minecraft:function",
|
||||
"environment": "minecraft:default",
|
||||
"function": "forge:conditional_loot_test/test_true_false",
|
||||
"max_ticks": 100,
|
||||
"structure": "forge:empty3x3x3"
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"type": "minecraft:function",
|
||||
"environment": "minecraft:default",
|
||||
"function": "forge:conditional_recipe/conditional_recipe_choice",
|
||||
"max_ticks": 100,
|
||||
"structure": "forge:empty3x3x3"
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"type": "minecraft:function",
|
||||
"environment": "minecraft:default",
|
||||
"function": "forge:conditional_recipe/cooking_false_conditions",
|
||||
"max_ticks": 100,
|
||||
"structure": "forge:empty3x3x3"
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"type": "minecraft:function",
|
||||
"environment": "minecraft:default",
|
||||
"function": "forge:conditional_recipe/cooking_true_conditions",
|
||||
"max_ticks": 100,
|
||||
"structure": "forge:empty3x3x3"
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"type": "minecraft:function",
|
||||
"environment": "minecraft:default",
|
||||
"function": "forge:conditional_recipe/shaped_false_conditions",
|
||||
"max_ticks": 100,
|
||||
"structure": "forge:empty3x3x3"
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"type": "minecraft:function",
|
||||
"environment": "minecraft:default",
|
||||
"function": "forge:conditional_recipe/shaped_true_conditions",
|
||||
"max_ticks": 100,
|
||||
"structure": "forge:empty3x3x3"
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"type": "minecraft:function",
|
||||
"environment": "minecraft:default",
|
||||
"function": "forge:conditional_recipe/shapeless_false_conditions",
|
||||
"max_ticks": 100,
|
||||
"structure": "forge:empty3x3x3"
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"type": "minecraft:function",
|
||||
"environment": "minecraft:default",
|
||||
"function": "forge:conditional_recipe/shapeless_true_conditions",
|
||||
"max_ticks": 100,
|
||||
"structure": "forge:empty3x3x3"
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"type": "minecraft:function",
|
||||
"environment": "minecraft:default",
|
||||
"function": "forge:conditional_recipe/single_item_false_conditions",
|
||||
"max_ticks": 100,
|
||||
"structure": "forge:empty3x3x3"
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"type": "minecraft:function",
|
||||
"environment": "minecraft:default",
|
||||
"function": "forge:conditional_recipe/single_item_true_conditions",
|
||||
"max_ticks": 100,
|
||||
"structure": "forge:empty3x3x3"
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"type": "minecraft:function",
|
||||
"environment": "minecraft:default",
|
||||
"function": "forge:conditional_recipe/tag_empty_condition_with_empty_tag",
|
||||
"max_ticks": 100,
|
||||
"structure": "forge:empty3x3x3"
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"type": "minecraft:function",
|
||||
"environment": "minecraft:default",
|
||||
"function": "forge:conditional_recipe/tag_empty_condition_with_populated_tag",
|
||||
"max_ticks": 100,
|
||||
"structure": "forge:empty3x3x3"
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"type": "minecraft:function",
|
||||
"environment": "minecraft:default",
|
||||
"function": "forge:criterion_test/test_custom_criterion",
|
||||
"max_ticks": 100,
|
||||
"structure": "forge:empty3x3x3"
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"type": "minecraft:function",
|
||||
"environment": "minecraft:default",
|
||||
"function": "forge:custom_ingredients/compound",
|
||||
"max_ticks": 100,
|
||||
"structure": "forge:empty3x3x3"
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"type": "minecraft:function",
|
||||
"environment": "minecraft:default",
|
||||
"function": "forge:custom_ingredients/difference",
|
||||
"max_ticks": 100,
|
||||
"structure": "forge:empty3x3x3"
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"type": "minecraft:function",
|
||||
"environment": "minecraft:default",
|
||||
"function": "forge:custom_ingredients/intersection",
|
||||
"max_ticks": 100,
|
||||
"structure": "forge:empty3x3x3"
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"type": "minecraft:function",
|
||||
"environment": "minecraft:default",
|
||||
"function": "forge:custom_ingredients/partial_nbt",
|
||||
"max_ticks": 100,
|
||||
"structure": "forge:empty3x3x3"
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"type": "minecraft:function",
|
||||
"environment": "minecraft:default",
|
||||
"function": "forge:custom_ingredients/strict",
|
||||
"max_ticks": 100,
|
||||
"structure": "forge:empty3x3x3"
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"type": "minecraft:function",
|
||||
"environment": "minecraft:default",
|
||||
"function": "forge:forced_chunk_loading/force_far_away_chunk",
|
||||
"max_ticks": 100,
|
||||
"structure": "forge:empty3x3x3"
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"type": "minecraft:function",
|
||||
"environment": "minecraft:default",
|
||||
"function": "forge:gather_components_test_event/is_food",
|
||||
"max_ticks": 100,
|
||||
"structure": "forge:empty3x3x3"
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"type": "minecraft:function",
|
||||
"environment": "minecraft:default",
|
||||
"function": "forge:global_loot_test/condition_table_name",
|
||||
"max_ticks": 100,
|
||||
"structure": "forge:empty3x3x3"
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"type": "minecraft:function",
|
||||
"environment": "minecraft:default",
|
||||
"function": "forge:global_loot_test/silk_reentrant",
|
||||
"max_ticks": 100,
|
||||
"structure": "forge:empty3x3x3"
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"type": "minecraft:function",
|
||||
"environment": "minecraft:default",
|
||||
"function": "forge:global_loot_test/smellting",
|
||||
"max_ticks": 100,
|
||||
"structure": "forge:empty3x3x3"
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"type": "minecraft:function",
|
||||
"environment": "minecraft:default",
|
||||
"function": "forge:item_caps/item_capability",
|
||||
"max_ticks": 100,
|
||||
"structure": "forge:empty3x3x3"
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"type": "minecraft:function",
|
||||
"environment": "minecraft:default",
|
||||
"function": "forge:late_bound_id_mapper/compound",
|
||||
"max_ticks": 100,
|
||||
"structure": "forge:empty3x3x3"
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"type": "minecraft:function",
|
||||
"environment": "minecraft:default",
|
||||
"function": "forge:load_sort_test/ran_after_parent",
|
||||
"max_ticks": 100,
|
||||
"structure": "forge:empty3x3x3"
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"type": "minecraft:function",
|
||||
"environment": "minecraft:default",
|
||||
"function": "forge:load_sort_test/ran_before_child",
|
||||
"max_ticks": 100,
|
||||
"structure": "forge:empty3x3x3"
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"type": "minecraft:function",
|
||||
"environment": "minecraft:default",
|
||||
"function": "forge:loot_events/test_load_table",
|
||||
"max_ticks": 100,
|
||||
"structure": "forge:empty3x3x3"
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"type": "minecraft:function",
|
||||
"environment": "minecraft:default",
|
||||
"function": "forge:model_render_type/old_leaves_render_type",
|
||||
"max_ticks": 100,
|
||||
"structure": "forge:empty3x3x3"
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"type": "minecraft:function",
|
||||
"environment": "minecraft:default",
|
||||
"function": "forge:model_render_type/type_from_model",
|
||||
"max_ticks": 100,
|
||||
"structure": "forge:empty3x3x3"
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"type": "minecraft:function",
|
||||
"environment": "minecraft:default",
|
||||
"function": "forge:network_data_registry/client_has_registry",
|
||||
"max_ticks": 100,
|
||||
"structure": "forge:empty3x3x3"
|
||||
}
|
||||
+1
-1
@@ -1,3 +1,3 @@
|
||||
{
|
||||
"value": "network_data_registry:test_value"
|
||||
"value": "network_data_registry:test_value_new"
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"type": "minecraft:function",
|
||||
"environment": "minecraft:default",
|
||||
"function": "forge:packet/send_to_all",
|
||||
"max_ticks": 100,
|
||||
"structure": "forge:empty3x3x3"
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"type": "minecraft:function",
|
||||
"environment": "minecraft:default",
|
||||
"function": "forge:packet/send_to_nearby",
|
||||
"max_ticks": 100,
|
||||
"structure": "forge:empty3x3x3"
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"type": "minecraft:function",
|
||||
"environment": "minecraft:default",
|
||||
"function": "forge:packet/send_to_player",
|
||||
"max_ticks": 100,
|
||||
"structure": "forge:empty3x3x3"
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"type": "minecraft:function",
|
||||
"environment": "minecraft:default",
|
||||
"function": "forge:prevent_item_damage/fake_shield_damage_item_impl",
|
||||
"max_ticks": 100,
|
||||
"structure": "forge:empty3x3x3"
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"type": "minecraft:function",
|
||||
"environment": "minecraft:default",
|
||||
"function": "forge:prevent_item_damage/player_fake_shield_took_modified_damage",
|
||||
"max_ticks": 100,
|
||||
"structure": "forge:empty3x3x3"
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"type": "minecraft:function",
|
||||
"environment": "minecraft:default",
|
||||
"function": "forge:shears_loot/test_shears_drop_blocks",
|
||||
"max_ticks": 100,
|
||||
"structure": "forge:empty3x3x3"
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"type": "minecraft:function",
|
||||
"environment": "minecraft:default",
|
||||
"function": "forge:shield_disabling/player_shield_disabled_by_axe",
|
||||
"max_ticks": 100,
|
||||
"structure": "forge:empty3x3x3"
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"type": "minecraft:function",
|
||||
"environment": "minecraft:default",
|
||||
"function": "forge:shield_disabling/player_shield_disabled_by_warden",
|
||||
"max_ticks": 100,
|
||||
"structure": "forge:empty3x3x3"
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"type": "minecraft:function",
|
||||
"environment": "minecraft:default",
|
||||
"function": "forge:tags_test/cobble_in_legacy",
|
||||
"max_ticks": 100,
|
||||
"structure": "forge:empty3x3x3"
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"type": "minecraft:function",
|
||||
"environment": "minecraft:default",
|
||||
"function": "forge:update_order/east",
|
||||
"max_ticks": 100,
|
||||
"rotation": "counterclockwise_90",
|
||||
"structure": "update_order:update_order"
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"type": "minecraft:function",
|
||||
"environment": "minecraft:default",
|
||||
"function": "forge:update_order/north",
|
||||
"max_ticks": 100,
|
||||
"rotation": "180",
|
||||
"structure": "update_order:update_order"
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"type": "minecraft:function",
|
||||
"environment": "minecraft:default",
|
||||
"function": "forge:update_order/south",
|
||||
"max_ticks": 100,
|
||||
"structure": "update_order:update_order"
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"type": "minecraft:function",
|
||||
"environment": "minecraft:default",
|
||||
"function": "forge:update_order/up",
|
||||
"max_ticks": 100,
|
||||
"structure": "update_order:upward_update"
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"type": "minecraft:function",
|
||||
"environment": "minecraft:default",
|
||||
"function": "forge:update_order/west",
|
||||
"max_ticks": 100,
|
||||
"rotation": "clockwise_90",
|
||||
"structure": "update_order:update_order"
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"type": "minecraft:function",
|
||||
"environment": "minecraft:default",
|
||||
"function": "forge:villager_type_test/biome_type",
|
||||
"max_ticks": 100,
|
||||
"structure": "forge:empty3x3x3"
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"type": "minecraft:function",
|
||||
"environment": "minecraft:default",
|
||||
"function": "forge:villager_type_test/emeralds_for_villager_type",
|
||||
"max_ticks": 100,
|
||||
"structure": "forge:empty3x3x3"
|
||||
}
|
||||
@@ -29,7 +29,6 @@ import net.minecraft.data.CachedOutput;
|
||||
import net.minecraft.data.DataProvider;
|
||||
import net.minecraft.data.PackOutput;
|
||||
import net.minecraft.gametest.framework.GameTestHelper;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.animal.Cow;
|
||||
import net.minecraft.world.entity.animal.Pig;
|
||||
@@ -51,7 +50,7 @@ import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.fml.loading.FMLLoader;
|
||||
import net.minecraftforge.gametest.GameTest;
|
||||
import net.minecraftforge.gametest.GameTestHolder;
|
||||
import net.minecraftforge.gametest.GameTestNamespace;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
import net.minecraftforge.test.BaseTestMod;
|
||||
@@ -66,8 +65,8 @@ import java.util.stream.Stream;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
|
||||
@GameTestNamespace("forge")
|
||||
@Mod(AdditionalModelTest.MODID)
|
||||
@GameTestHolder("forge." + AdditionalModelTest.MODID)
|
||||
public class AdditionalModelTest extends BaseTestMod {
|
||||
public static final String MODID = "additional_model";
|
||||
|
||||
@@ -79,10 +78,6 @@ public class AdditionalModelTest extends BaseTestMod {
|
||||
private static final DeferredRegister<Item> ITEMS = DeferredRegister.create(Registries.ITEM, MODID);
|
||||
private static final RegistryObject<Item> PIG_HEAD_ITEM = ITEMS.register("pig_head", () -> new Item(new Item.Properties().setId(ITEMS.key("pig_head"))));
|
||||
|
||||
private static ResourceLocation rl(String path) {
|
||||
return ResourceLocation.fromNamespaceAndPath(MODID, path);
|
||||
}
|
||||
|
||||
public AdditionalModelTest(FMLJavaModLoadingContext context) {
|
||||
super(context, false);
|
||||
|
||||
|
||||
@@ -9,13 +9,12 @@ import net.minecraft.client.color.item.ItemTintSource;
|
||||
import net.minecraft.client.color.item.ItemTintSources;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import net.minecraft.gametest.framework.GameTestHelper;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.gametest.GameTest;
|
||||
import net.minecraftforge.gametest.GameTestHolder;
|
||||
import net.minecraftforge.gametest.GameTestNamespace;
|
||||
import net.minecraftforge.test.BaseTestMod;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@@ -26,16 +25,13 @@ import com.mojang.serialization.MapCodec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
|
||||
@Mod(LateBoundIdMapperTest.MODID)
|
||||
@GameTestHolder("forge." + LateBoundIdMapperTest.MODID)
|
||||
@GameTestNamespace("forge")
|
||||
public class LateBoundIdMapperTest extends BaseTestMod {
|
||||
public LateBoundIdMapperTest(FMLJavaModLoadingContext context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public static final String MODID = "late_bound_id_mapper";
|
||||
private static ResourceLocation rl(String path) {
|
||||
return ResourceLocation.fromNamespaceAndPath(MODID, path);
|
||||
}
|
||||
|
||||
@GameTest
|
||||
public static void compound(GameTestHelper helper) {
|
||||
|
||||
@@ -37,7 +37,7 @@ import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.gametest.GameTest;
|
||||
import net.minecraftforge.gametest.GameTestHolder;
|
||||
import net.minecraftforge.gametest.GameTestNamespace;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
import net.minecraftforge.test.BaseTestMod;
|
||||
@@ -52,7 +52,7 @@ import java.util.stream.Stream;
|
||||
import com.google.gson.JsonElement;
|
||||
|
||||
@Mod(ModelRenderLayerTest.MODID)
|
||||
@GameTestHolder("forge." + ModelRenderLayerTest.MODID)
|
||||
@GameTestNamespace("forge")
|
||||
public class ModelRenderLayerTest extends BaseTestMod {
|
||||
public static final String MODID = "model_render_type";
|
||||
private static final String BLOCK_NAME = "cutout_block";
|
||||
|
||||
@@ -5,77 +5,49 @@
|
||||
|
||||
package net.minecraftforge.debug.gameplay.biome;
|
||||
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.core.HolderSet;
|
||||
import net.minecraft.core.RegistrySetBuilder;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.data.PackOutput;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.BiomeTags;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.levelgen.GenerationStep;
|
||||
import net.minecraft.world.level.levelgen.VerticalAnchor;
|
||||
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
|
||||
import net.minecraft.world.level.levelgen.feature.Feature;
|
||||
import net.minecraft.world.level.levelgen.feature.configurations.ReplaceBlockConfiguration;
|
||||
import net.minecraft.world.level.levelgen.heightproviders.ConstantHeight;
|
||||
import net.minecraft.world.level.levelgen.placement.CountPlacement;
|
||||
import net.minecraft.world.level.levelgen.placement.HeightRangePlacement;
|
||||
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
|
||||
import net.minecraft.world.level.levelgen.placement.PlacedFeature;
|
||||
import net.minecraftforge.common.data.DatapackBuiltinEntriesProvider;
|
||||
import net.minecraftforge.common.world.BiomeModifier;
|
||||
import net.minecraftforge.common.world.ForgeBiomeModifiers;
|
||||
import net.minecraftforge.data.event.GatherDataEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.registries.DeferredRegisterData;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
import net.minecraftforge.test.BaseTestMod;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Mod(BiomeTestMod.MOD_ID)
|
||||
public class BiomeTestMod extends BaseTestMod {
|
||||
public static final String MOD_ID = "biome_test_mod";
|
||||
public static final String MOD_ID = "biome_test";
|
||||
|
||||
private static final ResourceKey<PlacedFeature> OVERWORLD_NETHERITE_BLOCK_ORE_PLACED_KEY = ResourceKey.create(Registries.PLACED_FEATURE, ResourceLocation.fromNamespaceAndPath(BiomeTestMod.MOD_ID, "overworld_netherite_block_ore_placed"));
|
||||
private static final ResourceKey<BiomeModifier> ADD_OVERWORLD_NETHERITE_BLOCK_ORE = ResourceKey.create(ForgeRegistries.Keys.BIOME_MODIFIERS, ResourceLocation.fromNamespaceAndPath(BiomeTestMod.MOD_ID, "add_overworld_netherite_block_ore"));
|
||||
private static final ResourceKey<ConfiguredFeature<?, ?>> OVERWORLD_NETHERITE_BLOCK_ORE = ResourceKey.create(Registries.CONFIGURED_FEATURE, ResourceLocation.fromNamespaceAndPath(BiomeTestMod.MOD_ID, "overworld_netherite_block_ore"));
|
||||
public static final DeferredRegisterData<ConfiguredFeature<?, ?>> CONFIGURED_FEATURES = DeferredRegisterData.create(Registries.CONFIGURED_FEATURE, MOD_ID);
|
||||
private static final RegistryObject<ConfiguredFeature<?, ?>> CONFIGURED = CONFIGURED_FEATURES.register("configured", () ->
|
||||
new ConfiguredFeature<>(Feature.NO_OP, NoneFeatureConfiguration.INSTANCE)
|
||||
);
|
||||
|
||||
public static final DeferredRegisterData<PlacedFeature> PLACED_FEATURES = DeferredRegisterData.create(Registries.PLACED_FEATURE, MOD_ID);
|
||||
private static final RegistryObject<PlacedFeature> PLACED = PLACED_FEATURES.register("placed", () ->
|
||||
new PlacedFeature(CONFIGURED.getHolder().orElseThrow(), List.of())
|
||||
);
|
||||
|
||||
public static final DeferredRegisterData<BiomeModifier> BIOME_MODIFIERS = DeferredRegisterData.create(ForgeRegistries.Keys.BIOME_MODIFIERS, MOD_ID);
|
||||
@SuppressWarnings("unused")
|
||||
private static final RegistryObject<BiomeModifier> MODIFIER = BIOME_MODIFIERS.register("modifier", ctx -> {
|
||||
return new ForgeBiomeModifiers.AddFeaturesBiomeModifier(
|
||||
ctx.lookup(Registries.BIOME).getOrThrow(BiomeTags.IS_OVERWORLD),
|
||||
HolderSet.direct(PLACED.getHolder().orElseThrow()),
|
||||
GenerationStep.Decoration.UNDERGROUND_ORES
|
||||
);
|
||||
});
|
||||
|
||||
public BiomeTestMod(FMLJavaModLoadingContext context) {
|
||||
super(context);
|
||||
modBus.addListener(BiomeTestMod::onDataGen);
|
||||
}
|
||||
|
||||
private static void onDataGen(GatherDataEvent event) {
|
||||
event.getGenerator().addProvider(event.includeServer(), new ModWorldGenProvider(event.getGenerator().getPackOutput(), event.getLookupProvider()));
|
||||
}
|
||||
|
||||
private static class ModWorldGenProvider extends DatapackBuiltinEntriesProvider {
|
||||
public static final RegistrySetBuilder BUILDER = new RegistrySetBuilder()
|
||||
.add(Registries.CONFIGURED_FEATURE, context -> {
|
||||
context.register(OVERWORLD_NETHERITE_BLOCK_ORE, new ConfiguredFeature<>(
|
||||
Feature.REPLACE_SINGLE_BLOCK,
|
||||
new ReplaceBlockConfiguration(Blocks.AIR.defaultBlockState(), Blocks.NETHERITE_BLOCK.defaultBlockState())
|
||||
));
|
||||
})
|
||||
.add(Registries.PLACED_FEATURE, context -> {
|
||||
context.register(OVERWORLD_NETHERITE_BLOCK_ORE_PLACED_KEY, new PlacedFeature(
|
||||
context.lookup(Registries.CONFIGURED_FEATURE).getOrThrow(OVERWORLD_NETHERITE_BLOCK_ORE),
|
||||
List.of(CountPlacement.of(1), HeightRangePlacement.of(ConstantHeight.of(VerticalAnchor.absolute(100))))
|
||||
));
|
||||
})
|
||||
.add(ForgeRegistries.Keys.BIOME_MODIFIERS, context -> {
|
||||
context.register(ADD_OVERWORLD_NETHERITE_BLOCK_ORE, new ForgeBiomeModifiers.AddFeaturesBiomeModifier(
|
||||
context.lookup(Registries.BIOME).getOrThrow(BiomeTags.IS_OVERWORLD),
|
||||
HolderSet.direct(context.lookup(Registries.PLACED_FEATURE).getOrThrow(OVERWORLD_NETHERITE_BLOCK_ORE_PLACED_KEY)),
|
||||
GenerationStep.Decoration.UNDERGROUND_ORES
|
||||
));
|
||||
});
|
||||
|
||||
public ModWorldGenProvider(PackOutput output, CompletableFuture<HolderLookup.Provider> registries) {
|
||||
super(output, registries, BUILDER, Set.of(BiomeTestMod.MOD_ID));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,13 +17,13 @@ import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.gametest.GameTest;
|
||||
import net.minecraftforge.gametest.GameTestHolder;
|
||||
import net.minecraftforge.gametest.GameTestNamespace;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
import net.minecraftforge.test.BaseTestMod;
|
||||
|
||||
@GameTestHolder("forge." + ChorusBlockPlacementTest.MOD_ID)
|
||||
@GameTestNamespace("forge")
|
||||
@Mod(ChorusBlockPlacementTest.MOD_ID)
|
||||
public class ChorusBlockPlacementTest extends BaseTestMod {
|
||||
static final String MOD_ID = "chorus_block_placement";
|
||||
|
||||
@@ -18,7 +18,6 @@ import net.minecraft.data.recipes.SimpleCookingRecipeBuilder;
|
||||
import net.minecraft.data.recipes.SingleItemRecipeBuilder;
|
||||
import net.minecraft.data.tags.ItemTagsProvider;
|
||||
import net.minecraft.gametest.framework.GameTestHelper;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.ItemTags;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
@@ -41,10 +40,10 @@ import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.gametest.GameTest;
|
||||
import net.minecraftforge.gametest.GameTestHolder;
|
||||
import net.minecraftforge.gametest.GameTestNamespace;
|
||||
import net.minecraftforge.test.BaseTestMod;
|
||||
|
||||
@GameTestHolder("forge." + ConditionalRecipeTest.MODID)
|
||||
@GameTestNamespace("forge")
|
||||
@Mod(ConditionalRecipeTest.MODID)
|
||||
public class ConditionalRecipeTest extends BaseTestMod {
|
||||
static final String MODID = "conditional_recipe";
|
||||
@@ -62,10 +61,6 @@ public class ConditionalRecipeTest extends BaseTestMod {
|
||||
gen.addProvider(event.includeServer(), new TestItemTags(gen.getPackOutput(), event.getLookupProvider(), testBlockTags.contentsGetter(), event.getExistingFileHelper()));
|
||||
}
|
||||
|
||||
private static ResourceLocation rl(String path) {
|
||||
return ResourceLocation.fromNamespaceAndPath(MODID, path);
|
||||
}
|
||||
|
||||
private static <C extends RecipeInput, T extends Recipe<C>> void assertFalse(GameTestHelper helper, RecipeType<T> type, C container) {
|
||||
var recipe = helper.getLevel().recipeAccess().getRecipeFor(type, container, helper.getLevel());
|
||||
helper.assertTrue(recipe.isEmpty(), () -> "Found crafting recipe when unexpected: " + recipe.get().id());
|
||||
|
||||
@@ -24,7 +24,6 @@ import net.minecraft.data.tags.ItemTagsProvider;
|
||||
import net.minecraft.gametest.framework.GameTestHelper;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.ItemTags;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.world.item.Item;
|
||||
@@ -46,10 +45,10 @@ import net.minecraftforge.data.event.GatherDataEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.gametest.GameTest;
|
||||
import net.minecraftforge.gametest.GameTestHolder;
|
||||
import net.minecraftforge.gametest.GameTestNamespace;
|
||||
import net.minecraftforge.test.BaseTestMod;
|
||||
|
||||
@GameTestHolder("forge." + CustomIngredientsTest.MODID)
|
||||
@GameTestNamespace("forge")
|
||||
@Mod(CustomIngredientsTest.MODID)
|
||||
public class CustomIngredientsTest extends BaseTestMod implements INBTBuilder {
|
||||
static final String MODID = "custom_ingredients";
|
||||
@@ -77,10 +76,6 @@ public class CustomIngredientsTest extends BaseTestMod implements INBTBuilder {
|
||||
gen.addProvider(event.includeServer(), new Recipes.Runner(out, event.getLookupProvider()));
|
||||
}
|
||||
|
||||
private static ResourceLocation rl(String path) {
|
||||
return ResourceLocation.fromNamespaceAndPath(MODID, path);
|
||||
}
|
||||
|
||||
private static TagKey<Item> tag(String name) {
|
||||
return ItemTags.create(rl(name));
|
||||
}
|
||||
|
||||
@@ -13,11 +13,11 @@ import net.minecraft.world.item.Items;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.gametest.GameTest;
|
||||
import net.minecraftforge.gametest.GameTestHolder;
|
||||
import net.minecraftforge.gametest.GameTestNamespace;
|
||||
import net.minecraftforge.test.BaseTestMod;
|
||||
|
||||
@Mod(TagsTest.MODID)
|
||||
@GameTestHolder("forge.crafting.tags")
|
||||
@GameTestNamespace("forge")
|
||||
public class TagsTest extends BaseTestMod {
|
||||
public static final String MODID = "tags_test";
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.gametest.GameTest;
|
||||
import net.minecraftforge.gametest.GameTestHolder;
|
||||
import net.minecraftforge.gametest.GameTestNamespace;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
@@ -47,7 +47,7 @@ import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@Mod(CriterionTest.MOD_ID)
|
||||
@GameTestHolder("forge.custom_criterions")
|
||||
@GameTestNamespace("forge")
|
||||
public final class CriterionTest extends BaseTestMod {
|
||||
public static final String MOD_ID = "criterion_test";
|
||||
private static final DeferredRegister<CriterionTrigger<?>> TRIGGERS = DeferredRegister.create(BuiltInRegistries.TRIGGER_TYPES.key(), MOD_ID);
|
||||
|
||||
@@ -15,10 +15,10 @@ import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.gametest.GameTest;
|
||||
import net.minecraftforge.gametest.GameTestHolder;
|
||||
import net.minecraftforge.gametest.GameTestNamespace;
|
||||
import net.minecraftforge.test.BaseTestMod;
|
||||
|
||||
@GameTestHolder("forge." + GatherComponentsEventTest.MOD_ID)
|
||||
@GameTestNamespace("forge")
|
||||
@Mod(GatherComponentsEventTest.MOD_ID)
|
||||
public class GatherComponentsEventTest extends BaseTestMod {
|
||||
public static final String MOD_ID = "gather_components_test_event";
|
||||
@@ -36,7 +36,7 @@ public class GatherComponentsEventTest extends BaseTestMod {
|
||||
}
|
||||
|
||||
@GameTest
|
||||
public static void onTestForFood(GameTestHelper helper) {
|
||||
public static void is_food(GameTestHelper helper) {
|
||||
helper.assertTrue(Items.IRON_NUGGET.components().has(DataComponents.FOOD), "Iron Nugget is not edible, failed to apply DataComponents.FOOD to it.");
|
||||
helper.assertFalse(Items.IRON_INGOT.components().has(DataComponents.FOOD), "Iron Ingot is edible, should not have DataComponents.FOOD");
|
||||
helper.succeed();
|
||||
|
||||
@@ -29,7 +29,7 @@ import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.gametest.GameTest;
|
||||
import net.minecraftforge.gametest.GameTestHolder;
|
||||
import net.minecraftforge.gametest.GameTestNamespace;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
import net.minecraftforge.test.BaseTestMod;
|
||||
@@ -38,7 +38,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@GameTestHolder("forge." + ItemCapabilityTest.MOD_ID)
|
||||
@GameTestNamespace("forge")
|
||||
@Mod(ItemCapabilityTest.MOD_ID)
|
||||
public class ItemCapabilityTest extends BaseTestMod {
|
||||
public static final String MOD_ID = "item_caps";
|
||||
@@ -66,7 +66,7 @@ public class ItemCapabilityTest extends BaseTestMod {
|
||||
}
|
||||
|
||||
@GameTest
|
||||
public static void testItemCap(GameTestHelper helper) {
|
||||
public static void item_capability(GameTestHelper helper) {
|
||||
|
||||
helper.registerEventListener(ItemCapabilityTest.class);
|
||||
|
||||
|
||||
@@ -7,34 +7,41 @@ package net.minecraftforge.debug.gameplay.item;
|
||||
|
||||
import net.minecraft.commands.arguments.EntityAnchorArgument;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.component.DataComponents;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.gametest.framework.GameTestHelper;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.tags.DamageTypeTags;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.damagesource.DamageTypes;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.ShieldItem;
|
||||
import net.minecraft.world.item.component.BlocksAttacks;
|
||||
import net.minecraft.world.level.GameType;
|
||||
import net.minecraftforge.event.entity.living.LivingEntityUseItemEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.gametest.GameTest;
|
||||
import net.minecraftforge.gametest.GameTestHolder;
|
||||
import net.minecraftforge.gametest.GameTestNamespace;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
import net.minecraftforge.test.BaseTestMod;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@GameTestNamespace("forge")
|
||||
@Mod(PreventItemDamageTest.MOD_ID)
|
||||
@GameTestHolder("forge." + PreventItemDamageTest.MOD_ID)
|
||||
public class PreventItemDamageTest extends BaseTestMod {
|
||||
static final String MOD_ID = "prevent_item_damage";
|
||||
|
||||
@@ -133,7 +140,23 @@ public class PreventItemDamageTest extends BaseTestMod {
|
||||
|
||||
private static final class FakeShieldItem extends ShieldItem {
|
||||
public FakeShieldItem() {
|
||||
super(new Item.Properties().setId(ITEMS.key("fake_shield")).durability(10));
|
||||
super(new Item.Properties()
|
||||
.setId(ITEMS.key("fake_shield"))
|
||||
.durability(10)
|
||||
.equippableUnswappable(EquipmentSlot.OFFHAND)
|
||||
.component(
|
||||
DataComponents.BLOCKS_ATTACKS,
|
||||
new BlocksAttacks(
|
||||
0F,
|
||||
0F,
|
||||
List.of(new BlocksAttacks.DamageReduction(360.0F, Optional.empty(), 0.0F, 1.0F)),
|
||||
new BlocksAttacks.ItemDamageFunction(3.0F, 1.0F, 1.0F),
|
||||
Optional.of(DamageTypeTags.BYPASSES_SHIELD),
|
||||
Optional.of(SoundEvents.SHIELD_BLOCK),
|
||||
Optional.of(SoundEvents.SHIELD_BREAK)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -22,13 +22,13 @@ import net.minecraftforge.event.entity.living.LivingEntityUseItemEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.gametest.GameTest;
|
||||
import net.minecraftforge.gametest.GameTestHolder;
|
||||
import net.minecraftforge.gametest.GameTestNamespace;
|
||||
import net.minecraftforge.test.BaseTestMod;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
@GameTestNamespace("forge")
|
||||
@Mod(ShieldDisablingTest.MOD_ID)
|
||||
@GameTestHolder("forge." + ShieldDisablingTest.MOD_ID)
|
||||
public final class ShieldDisablingTest extends BaseTestMod {
|
||||
public static final String MOD_ID = "shield_disabling";
|
||||
|
||||
|
||||
@@ -14,10 +14,10 @@ import net.minecraft.world.level.chunk.ChunkAccess;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.gametest.GameTest;
|
||||
import net.minecraftforge.gametest.GameTestHolder;
|
||||
import net.minecraftforge.gametest.GameTestNamespace;
|
||||
import net.minecraftforge.test.BaseTestMod;
|
||||
|
||||
@GameTestHolder("forge." + ForcedChunkLoadingTest.MOD_ID)
|
||||
@GameTestNamespace("forge")
|
||||
@Mod(ForcedChunkLoadingTest.MOD_ID)
|
||||
public class ForcedChunkLoadingTest extends BaseTestMod {
|
||||
static final String MOD_ID = "forced_chunk_loading";
|
||||
|
||||
@@ -28,7 +28,7 @@ import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.common.crafting.conditions.IConditionBuilder;
|
||||
import net.minecraftforge.data.event.GatherDataEvent;
|
||||
import net.minecraftforge.gametest.GameTest;
|
||||
import net.minecraftforge.gametest.GameTestHolder;
|
||||
import net.minecraftforge.gametest.GameTestNamespace;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
@@ -37,8 +37,8 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@GameTestNamespace("forge")
|
||||
@Mod(ConditionalLootPools.MODID)
|
||||
@GameTestHolder("forge." + ConditionalLootPools.MODID)
|
||||
public class ConditionalLootPools extends BaseTestMod {
|
||||
public static final String MODID = "conditional_loot_test";
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ import net.minecraftforge.test.BaseTestMod;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.data.event.GatherDataEvent;
|
||||
import net.minecraftforge.gametest.GameTest;
|
||||
import net.minecraftforge.gametest.GameTestHolder;
|
||||
import net.minecraftforge.gametest.GameTestNamespace;
|
||||
import net.minecraftforge.items.ItemHandlerHelper;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
@@ -79,7 +79,7 @@ import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@GameTestHolder("forge.global_loot_modifiers")
|
||||
@GameTestNamespace("forge")
|
||||
@Mod(GlobalLootModifiersTest.MODID)
|
||||
public class GlobalLootModifiersTest extends BaseTestMod {
|
||||
public static final String MODID = "global_loot_test";
|
||||
|
||||
@@ -36,14 +36,14 @@ import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.gametest.GameTest;
|
||||
import net.minecraftforge.gametest.GameTestHolder;
|
||||
import net.minecraftforge.gametest.GameTestNamespace;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
import net.minecraftforge.test.BaseTestMod;
|
||||
|
||||
@Mod(LootEventsTest.MODID)
|
||||
@GameTestHolder("forge." + LootEventsTest.MODID)
|
||||
@GameTestNamespace("forge")
|
||||
public class LootEventsTest extends BaseTestMod {
|
||||
public static final String MODID = "loot_events";
|
||||
@SuppressWarnings("unused")
|
||||
|
||||
@@ -24,14 +24,14 @@ import net.minecraft.world.level.block.state.properties.DoubleBlockHalf;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.gametest.GameTest;
|
||||
import net.minecraftforge.gametest.GameTestHolder;
|
||||
import net.minecraftforge.gametest.GameTestNamespace;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
import net.minecraftforge.test.BaseTestMod;
|
||||
|
||||
@Mod(ShearsLootTests.MODID)
|
||||
@GameTestHolder("forge." + ShearsLootTests.MODID)
|
||||
@GameTestNamespace("forge")
|
||||
public class ShearsLootTests extends BaseTestMod {
|
||||
public static final String MODID = "shears_loot";
|
||||
|
||||
|
||||
@@ -10,12 +10,14 @@ import net.minecraft.gametest.framework.GameTestHelper;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.Rotation;
|
||||
import net.minecraft.world.level.block.entity.BarrelBlockEntity;
|
||||
import net.minecraft.world.level.block.entity.ChestBlockEntity;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.test.BaseTestMod;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.gametest.GameTest;
|
||||
import net.minecraftforge.gametest.GameTestHolder;
|
||||
import net.minecraftforge.gametest.GameTestNamespace;
|
||||
|
||||
/**
|
||||
* Redstone update orders are important in many contraptions as there are pistons and other things that could conflict with each other.
|
||||
@@ -24,7 +26,7 @@ import net.minecraftforge.gametest.GameTestHolder;
|
||||
* Partial verification/fix for https://github.com/MinecraftForge/MinecraftForge/issues/9973
|
||||
*/
|
||||
@Mod(UpdateOrder.MODID)
|
||||
@GameTestHolder("forge." + UpdateOrder.MODID)
|
||||
@GameTestNamespace("forge")
|
||||
public class UpdateOrder extends BaseTestMod {
|
||||
public static final String MODID = "update_order";
|
||||
private static final int PISTON_DELAY = 4;
|
||||
@@ -33,7 +35,7 @@ public class UpdateOrder extends BaseTestMod {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@GameTest(data = @GameTest.Data( structure = "update_order:update_order" ), rotationSteps = 0)
|
||||
@GameTest(structure = "update_order:update_order")
|
||||
public static void south(GameTestHelper helper) {
|
||||
var chestPos = new BlockPos(0, 1, 0);
|
||||
helper.assertBlockPresent(Blocks.CHEST, chestPos);
|
||||
@@ -47,7 +49,7 @@ public class UpdateOrder extends BaseTestMod {
|
||||
});
|
||||
}
|
||||
|
||||
@GameTest(data = @GameTest.Data( structure = "update_order:update_order" ), rotationSteps = 1)
|
||||
@GameTest(structure = "update_order:update_order", rotation = Rotation.CLOCKWISE_90)
|
||||
public static void west(GameTestHelper helper) {
|
||||
var chestPos = new BlockPos(0, 1, 0);
|
||||
helper.assertBlockPresent(Blocks.CHEST, chestPos);
|
||||
@@ -61,7 +63,7 @@ public class UpdateOrder extends BaseTestMod {
|
||||
});
|
||||
}
|
||||
|
||||
@GameTest(data = @GameTest.Data( structure = "update_order:update_order" ), rotationSteps = 2)
|
||||
@GameTest(structure = "update_order:update_order", rotation = Rotation.CLOCKWISE_180)
|
||||
public static void north(GameTestHelper helper) {
|
||||
var chestPos = new BlockPos(0, 1, 0);
|
||||
helper.assertBlockPresent(Blocks.CHEST, chestPos);
|
||||
@@ -75,7 +77,7 @@ public class UpdateOrder extends BaseTestMod {
|
||||
});
|
||||
}
|
||||
|
||||
@GameTest(data = @GameTest.Data( structure = "update_order:update_order" ), rotationSteps = 3)
|
||||
@GameTest(structure = "update_order:update_order", rotation = Rotation.COUNTERCLOCKWISE_90)
|
||||
public static void east(GameTestHelper helper) {
|
||||
var chestPos = new BlockPos(0, 1, 0);
|
||||
helper.assertBlockPresent(Blocks.CHEST, chestPos);
|
||||
@@ -89,16 +91,16 @@ public class UpdateOrder extends BaseTestMod {
|
||||
});
|
||||
}
|
||||
|
||||
@GameTest(data = @GameTest.Data( structure = "update_order:upward_update"))
|
||||
@GameTest(structure = "update_order:upward_update")
|
||||
public static void up(GameTestHelper helper) {
|
||||
var chestPos = new BlockPos(0, 1, 2);
|
||||
var barrelPos = new BlockPos(0, 1, 2);
|
||||
var expectedPos = new BlockPos(2, 1, 0);
|
||||
var unexpectedPos = new BlockPos(0, 4, 0);
|
||||
helper.assertBlockPresent(Blocks.BARREL, chestPos);
|
||||
helper.assertBlockPresent(Blocks.BARREL, barrelPos);
|
||||
helper.assertBlockPresent(Blocks.AIR, expectedPos);
|
||||
helper.assertBlockPresent(Blocks.AIR, unexpectedPos);
|
||||
var chest = helper.getBlockEntity(chestPos, ChestBlockEntity.class);
|
||||
chest.setItem(0, new ItemStack(Items.DIRT));
|
||||
var barrel = helper.getBlockEntity(barrelPos, BarrelBlockEntity.class);
|
||||
barrel.setItem(0, new ItemStack(Items.DIRT));
|
||||
|
||||
helper.runAfterDelay(10, () -> { // There are a lot of things happening, give it a few ticks
|
||||
helper.assertBlockNotPresent(Blocks.WHITE_WOOL, unexpectedPos);
|
||||
|
||||
@@ -21,14 +21,14 @@ import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.gametest.GameTest;
|
||||
import net.minecraftforge.gametest.GameTestHolder;
|
||||
import net.minecraftforge.gametest.GameTestNamespace;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
import net.minecraftforge.test.BaseTestMod;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@GameTestHolder("forge." + VillagerTypeTestMod.MOD_ID)
|
||||
@GameTestNamespace("forge")
|
||||
@Mod(VillagerTypeTestMod.MOD_ID)
|
||||
public class VillagerTypeTestMod extends BaseTestMod {
|
||||
public static final String MOD_ID = "villager_type_test";
|
||||
@@ -55,7 +55,7 @@ public class VillagerTypeTestMod extends BaseTestMod {
|
||||
helper.assertValueEqual(type, TEST_VILLAGER_TYPE.get(), Component.literal("Loaded entry does not contain expected value"));
|
||||
|
||||
Holder<Biome> biome = access.lookupOrThrow(Registries.BIOME).getOrThrow(Biomes.PLAINS);
|
||||
helper.assertValueEqual(VillagerType.byBiome(biome), TEST_VILLAGER_TYPE.get(), Component.literal("VillagerType.byBiome did not return the expected value"));
|
||||
helper.assertValueEqual(VillagerType.byBiome(biome), TEST_VILLAGER_TYPE.getKey(), Component.literal("VillagerType.byBiome did not return the expected value"));
|
||||
|
||||
helper.succeed();
|
||||
}
|
||||
|
||||
@@ -13,10 +13,10 @@ import net.minecraft.gametest.framework.GameTestHelper;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.gametest.GameTest;
|
||||
import net.minecraftforge.gametest.GameTestHolder;
|
||||
import net.minecraftforge.gametest.GameTestNamespace;
|
||||
import net.minecraftforge.test.BaseTestMod;
|
||||
|
||||
@GameTestHolder("forge." + ModLoadSortingTest.MODID)
|
||||
@GameTestNamespace("forge")
|
||||
@Mod(ModLoadSortingTest.MODID)
|
||||
public class ModLoadSortingTest extends BaseTestMod {
|
||||
static final String MODID = "load_sort_test";
|
||||
|
||||
@@ -9,11 +9,11 @@ import net.minecraft.gametest.framework.GameTestHelper;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.gametest.GameTest;
|
||||
import net.minecraftforge.gametest.GameTestHolder;
|
||||
import net.minecraftforge.gametest.GameTestNamespace;
|
||||
import net.minecraftforge.test.BaseTestMod;
|
||||
|
||||
@GameTestNamespace("forge")
|
||||
@Mod(AutomaticModuleMod.MODID)
|
||||
@GameTestHolder("forge.module.automatic")
|
||||
public class AutomaticModuleMod extends BaseTestMod {
|
||||
public static final String MODID = "automatic_module";
|
||||
|
||||
|
||||
@@ -14,14 +14,14 @@ import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.gametest.GameTest;
|
||||
import net.minecraftforge.gametest.GameTestHolder;
|
||||
import net.minecraftforge.gametest.GameTestNamespace;
|
||||
import net.minecraftforge.test.BaseTestMod;
|
||||
import net.minecraftforge.test.ManifestProvider;
|
||||
import net.minecraftforge.test.ModuleProvider;
|
||||
import net.minecraft.gametest.framework.GameTestHelper;
|
||||
|
||||
@Mod(ClosedTestsMod.MODID)
|
||||
@GameTestHolder("forge.module.closed")
|
||||
@GameTestNamespace("forge")
|
||||
public class ClosedTestsMod extends BaseTestMod {
|
||||
public static final String MODID = "closed_module_test";
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.gametest.GameTest;
|
||||
import net.minecraftforge.gametest.GameTestHolder;
|
||||
import net.minecraftforge.gametest.GameTestNamespace;
|
||||
import net.minecraftforge.network.Channel.VersionTest;
|
||||
import net.minecraftforge.network.ChannelBuilder;
|
||||
import net.minecraftforge.network.ForgePayload;
|
||||
@@ -33,8 +33,8 @@ import net.minecraftforge.network.PacketDistributor;
|
||||
import net.minecraftforge.network.SimpleChannel;
|
||||
import net.minecraftforge.test.BaseTestMod;
|
||||
|
||||
@GameTestHolder("forge." + PacketTest.MODID)
|
||||
@Mod(PacketTest.MODID)
|
||||
@GameTestNamespace("forge")
|
||||
public class PacketTest extends BaseTestMod {
|
||||
static final String MODID = "packet";
|
||||
|
||||
|
||||
Loaded 100 of 102 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user