Skip to content

Commit

Permalink
Implement Forge's gametest system
Browse files Browse the repository at this point in the history
  • Loading branch information
BluSpring committed Jan 18, 2025
1 parent 052cbf7 commit dc6f72e
Show file tree
Hide file tree
Showing 33 changed files with 455 additions and 60 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ gradle-app.setting

# Common working directory
run/
run_test/
!run_test/.gitkeep

# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
!gradle-wrapper.jar
Expand Down
53 changes: 43 additions & 10 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ sourceSets {
resources.srcDir("forge/src/generated/resources")
resources.srcDir("forge/src/main/resources")
}

getByName("test") {
java.srcDirs("forge/src/test/java")
resources.srcDir("forge/src/generated_test/resources")
resources.srcDir("forge/src/test/resources")
}
}

loom {
Expand Down Expand Up @@ -212,6 +218,14 @@ dependencies {
implementation("com.google.code.findbugs:jsr305:3.0.2")

implementation(include("commons-codec:commons-codec:1.15")!!)


// Test libraries
testImplementation("net.fabricmc:fabric-loader-junit:${property("loader_version")}")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.7.0")
testImplementation("org.junit.vintage:junit-vintage-engine:5.+")
testImplementation("org.opentest4j:opentest4j:1.2.0") // needed for junit 5
testImplementation("org.hamcrest:hamcrest-all:1.3") // needs advanced matching for list order
}

configurations.all {
Expand All @@ -236,6 +250,10 @@ java {
}

tasks {
test {
useJUnitPlatform()
}

register("countPatchProgress") {
group = "kilt"
description = "Counts the total of patches in Forge, and checks how many Kilt ForgeInjects there are, to check how much is remaining."
Expand Down Expand Up @@ -315,6 +333,17 @@ tasks {
}

processResources {
val properties = mutableMapOf(
"version" to project.version,
"loader_version" to project.property("loader_version"),
"fabric_version" to project.property("fabric_version"),
"minecraft_version" to project.property("minecraft_version"),
"fabric_kotlin_version" to project.property("fabric_kotlin_version"),
"fabric_asm_version" to project.property("fabric_asm_version"),
"forge_config_version" to project.property("forgeconfigapiport_version"),
"architectury_version" to project.property("architectury_version"),
)

inputs.property("version", project.version)
inputs.property("loader_version", project.property("loader_version"))
inputs.property("fabric_version", project.property("fabric_version"))
Expand All @@ -326,16 +355,20 @@ tasks {
filteringCharset = "UTF-8"

filesMatching("fabric.mod.json") {
expand(mutableMapOf(
"version" to project.version,
"loader_version" to project.property("loader_version"),
"fabric_version" to project.property("fabric_version"),
"minecraft_version" to project.property("minecraft_version"),
"fabric_kotlin_version" to project.property("fabric_kotlin_version"),
"fabric_asm_version" to project.property("fabric_asm_version"),
"forge_config_version" to project.property("forgeconfigapiport_version"),
"architectury_version" to project.property("architectury_version"),
))
// Use this instead of expand, as otherwise Gradle hard-errors when finding unknown $ names, and treats them as properties.
this.filter {
if (it.contains("\${")) {
var newString = it

for ((name, property) in properties) {
newString = newString.replace("\${$name}", property.toString())
}

return@filter newString
}

it
}
}

// Rename Forge's mods.toml, so launchers like Prism don't end up detecting it over Kilt.
Expand Down
2 changes: 1 addition & 1 deletion forge
Submodule forge updated 43 files
+6 −2 src/main/java/net/minecraftforge/common/extensions/IForgeBaseRailBlock.java
+3 −1 src/main/java/net/minecraftforge/common/extensions/IForgeBlock.java
+44 −15 src/main/java/net/minecraftforge/common/extensions/IForgeEntity.java
+2 −1 src/main/java/net/minecraftforge/common/extensions/IForgeHolderSet.java
+3 −1 src/main/java/net/minecraftforge/common/extensions/IForgeItem.java
+5 −3 src/main/java/net/minecraftforge/registries/holdersets/ICustomHolderSet.java
+14 −13 src/test/java/net/minecraftforge/debug/CreativeModeTabTest.java
+47 −94 src/test/java/net/minecraftforge/debug/DataGeneratorTest.java
+2 −2 src/test/java/net/minecraftforge/debug/ManyMobEffectsTest.java
+5 −4 src/test/java/net/minecraftforge/debug/RemoveTagDatagenTest.java
+6 −2 src/test/java/net/minecraftforge/debug/block/CustomHeadTest.java
+10 −10 src/test/java/net/minecraftforge/debug/block/CustomPlantTypeTest.java
+12 −18 src/test/java/net/minecraftforge/debug/block/CustomSignsTest.java
+8 −7 src/test/java/net/minecraftforge/debug/block/FlowerPotTest.java
+24 −10 src/test/java/net/minecraftforge/debug/block/FullPotsAccessorDemo.java
+2 −2 src/test/java/net/minecraftforge/debug/block/HideNeighborFaceTest.java
+12 −13 src/test/java/net/minecraftforge/debug/block/ScaffoldingTest.java
+3 −2 src/test/java/net/minecraftforge/debug/client/AudioStreamTest.java
+3 −2 src/test/java/net/minecraftforge/debug/client/CustomArmorModelTest.java
+9 −6 src/test/java/net/minecraftforge/debug/client/CustomTASTest.java
+12 −7 src/test/java/net/minecraftforge/debug/client/CustomTooltipTest.java
+8 −7 src/test/java/net/minecraftforge/debug/client/GuiLayeringTest.java
+2 −2 src/test/java/net/minecraftforge/debug/client/model/CalculateNormalsTest.java
+5 −3 src/test/java/net/minecraftforge/debug/client/model/CustomItemDisplayContextTest.java
+5 −5 src/test/java/net/minecraftforge/debug/client/model/MultiLayerModelTest.java
+16 −17 src/test/java/net/minecraftforge/debug/client/model/NewModelLoaderTest.java
+18 −12 src/test/java/net/minecraftforge/debug/client/model/TRSRTransformerTest.java
+5 −9 src/test/java/net/minecraftforge/debug/client/rendering/ShaderResourcesTest.java
+2 −1 src/test/java/net/minecraftforge/debug/entity/CreateEntityClassificationTest.java
+10 −4 src/test/java/net/minecraftforge/debug/entity/player/ItemUseAnimationTest.java
+10 −6 src/test/java/net/minecraftforge/debug/fluid/FluidTypeTest.java
+16 −25 src/test/java/net/minecraftforge/debug/fluid/NewFluidTest.java
+16 −13 src/test/java/net/minecraftforge/debug/item/CustomElytraTest.java
+2 −2 src/test/java/net/minecraftforge/debug/item/CustomMobBucketTest.java
+5 −5 src/test/java/net/minecraftforge/debug/item/MusicDiscTest.java
+8 −6 src/test/java/net/minecraftforge/debug/item/TagBasedToolTypesTest.java
+2 −1 src/test/java/net/minecraftforge/debug/misc/CustomRarityTest.java
+8 −5 src/test/java/net/minecraftforge/debug/misc/GameTestTest.java
+4 −3 src/test/java/net/minecraftforge/debug/recipe/recipebook/RecipeBookExtensionClientHelper.java
+4 −2 src/test/java/net/minecraftforge/debug/recipe/recipebook/RecipeBookExtensionTest.java
+2 −2 src/test/java/net/minecraftforge/debug/world/RaidEnumTest.java
+1 −1 src/test/java/net/minecraftforge/debug/world/item/IngredientInvalidationTest.java
+2 −1 src/test/java/net/minecraftforge/mdk/MdkDatagen.java
Empty file added run_test/.gitkeep
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
import net.minecraft.client.sounds.AudioStream;
import net.minecraft.client.sounds.SoundBufferLibrary;
import org.spongepowered.asm.mixin.Mixin;
import xyz.bluspring.kilt.injections.client.resources.sounds.SoundInstanceInjection;

import java.util.concurrent.CompletableFuture;

@Mixin(SoundInstance.class)
public interface SoundInstanceInject {
public interface SoundInstanceInject extends SoundInstanceInjection {
@Override
default CompletableFuture<AudioStream> getStream(SoundBufferLibrary soundBuffers, Sound sound, boolean looping) {
return soundBuffers.getStream(sound.getPath(), looping);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package xyz.bluspring.kilt.forgeinjects.data.loot;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import net.minecraft.core.DefaultedRegistry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.data.loot.BlockLootSubProvider;
import net.minecraft.world.level.block.Block;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import xyz.bluspring.kilt.injections.data.loot.BlockLootSubProviderInjection;

import java.util.Iterator;

@Mixin(BlockLootSubProvider.class)
public abstract class BlockLootSubProviderInject implements BlockLootSubProviderInjection {
@Override
public Iterable<Block> getKnownBlocks() {
return BuiltInRegistries.BLOCK;
}

@WrapOperation(method = "generate(Ljava/util/function/BiConsumer;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/core/DefaultedRegistry;iterator()Ljava/util/Iterator;"))
private Iterator<Block> kilt$useGetKnownBlocks(DefaultedRegistry<Block> instance, Operation<Iterator<Block>> original) {
var knownBlocks = this.getKnownBlocks();

// fallback to a modded one if needed.
if (knownBlocks == BuiltInRegistries.BLOCK)
return original.call(instance);

return knownBlocks.iterator();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import java.util.function.Supplier;

@Mixin(MobBucketItem.class)
public class MobBucketItemInject {
public abstract class MobBucketItemInject {
@Shadow @Final private SoundEvent emptySound;
@Shadow @Final private EntityType<?> type;
private Supplier<? extends EntityType<?>> entityTypeSupplier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import xyz.bluspring.kilt.helpers.mixin.CreateInitializer;
import xyz.bluspring.kilt.injections.world.item.RecordItemInjection;

import java.util.function.Supplier;

@Mixin(RecordItem.class)
public abstract class RecordItemInject extends Item {
public abstract class RecordItemInject extends Item implements RecordItemInjection {
@Mutable @Shadow @Final private int analogOutput;
@Mutable @Shadow @Final private SoundEvent sound;
@Mutable @Shadow @Final private int lengthInTicks;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package xyz.bluspring.kilt.forgeinjects.world.item;

import net.minecraft.world.item.UseAnim;
import org.spongepowered.asm.mixin.Mixin;
import xyz.bluspring.kilt.helpers.mixin.CreateStatic;
import xyz.bluspring.kilt.injections.world.item.UseAnimInjection;

@Mixin(UseAnim.class)
public abstract class UseAnimInject implements UseAnimInjection {
@CreateStatic
private static UseAnim CUSTOM = UseAnimInjection.CUSTOM;
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public FlowerPotBlock getEmptyPot() {
return emptyPot == null ? (FlowerPotBlock) (Object) this : emptyPot.get();
}

@Override
public void addPlant(ResourceLocation flower, Supplier<? extends Block> fullPot) {
if (getEmptyPot() != (Object) this) {
throw new IllegalArgumentException("Cannot add plant to non-empty pot: " + this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public Supplier<ResourceLocation> getLootTableSupplier() {
return lootTableSupplier;
}

@Override
public BlockBehaviour.Properties lootFrom(Supplier<? extends Block> blockIn) {
this.lootTableSupplier = () -> blockIn.get().getLootTable();
return (BlockBehaviour.Properties) (Object) this;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package xyz.bluspring.kilt.injections.client.resources.sounds;

import net.minecraft.client.resources.sounds.Sound;
import net.minecraft.client.sounds.AudioStream;
import net.minecraft.client.sounds.SoundBufferLibrary;

import java.util.concurrent.CompletableFuture;

public interface SoundInstanceInjection {
default CompletableFuture<AudioStream> getStream(SoundBufferLibrary soundBuffers, Sound sound, boolean looping) {
throw new IllegalStateException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,19 @@
import java.util.Map;

public interface DataGeneratorInjection {
Map<String, DataProvider> getProvidersView();
PackOutput getPackOutput();
PackOutput getPackOutput(String path);
<T extends DataProvider> T addProvider(boolean run, DataProvider.Factory<T> factory);
<T extends DataProvider> T addProvider(boolean run, T provider);
default Map<String, DataProvider> getProvidersView() {
throw new IllegalStateException();
}
default PackOutput getPackOutput() {
throw new IllegalStateException();
}
default PackOutput getPackOutput(String path) {
throw new IllegalStateException();
}
default <T extends DataProvider> T addProvider(boolean run, DataProvider.Factory<T> factory) {
throw new IllegalStateException();
}
default <T extends DataProvider> T addProvider(boolean run, T provider) {
throw new IllegalStateException();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package xyz.bluspring.kilt.injections.data.loot;

import net.minecraft.world.level.block.Block;

public interface BlockLootSubProviderInjection {
default Iterable<Block> getKnownBlocks() {
throw new IllegalStateException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,46 +12,106 @@
public interface CreativeModeTabInjection {
static CreativeModeTab create(CreativeModeTab.Builder builder) {
var tab = CreativeModeTabAccessor.createCreativeModeTab(((CreativeModeTabBuilderAccessor) builder).getRow(), ((CreativeModeTabBuilderAccessor) builder).getColumn(), ((CreativeModeTabBuilderAccessor) builder).getType(), ((CreativeModeTabBuilderAccessor) builder).getDisplayName(), ((CreativeModeTabBuilderAccessor) builder).getIconGenerator(), ((CreativeModeTabBuilderAccessor) builder).getDisplayItemsGenerator());
((CreativeModeTabInjection) tab).kilt$assignValues(builder);
tab.kilt$assignValues(builder);

return tab;
}

static CreativeModeTab.Builder builder() {
return new CreativeModeTab.Builder(CreativeModeTab.Row.TOP, 0);
}

// Helper method for both create() here and <init> in the mixin
void kilt$assignValues(CreativeModeTab.Builder builder);
void kilt$setBackgroundLocation(ResourceLocation location);
default void kilt$assignValues(CreativeModeTab.Builder builder) {}
default void kilt$setBackgroundLocation(ResourceLocation location) {}

ResourceLocation getBackgroundLocation();
boolean hasSearchBar();
int getSearchBarWidth();
ResourceLocation getTabsImage();
int getLabelColor();
int getSlotColor();
default ResourceLocation getBackgroundLocation() {
throw new IllegalStateException();
}
default boolean hasSearchBar() {
throw new IllegalStateException();
}
default int getSearchBarWidth() {
throw new IllegalStateException();
}
default ResourceLocation getTabsImage() {
throw new IllegalStateException();
}
default int getLabelColor() {
throw new IllegalStateException();
}
default int getSlotColor() {
throw new IllegalStateException();
}

List<ResourceLocation> kilt$getTabsBefore();
List<ResourceLocation> kilt$getTabsAfter();
default List<ResourceLocation> kilt$getTabsBefore() {
throw new IllegalStateException();
}
default List<ResourceLocation> kilt$getTabsAfter() {
throw new IllegalStateException();
}

interface BuilderInjection {
CreativeModeTab.Builder withBackgroundLocation(ResourceLocation background);
CreativeModeTab.Builder withSearchBar();
CreativeModeTab.Builder withSearchBar(int searchBarWidth);
CreativeModeTab.Builder withTabsImage(ResourceLocation tabsImage);
CreativeModeTab.Builder withLabelColor(int labelColor);
CreativeModeTab.Builder withSlotColor(int slotColor);
CreativeModeTab.Builder withTabFactory(Function<CreativeModeTab.Builder, CreativeModeTab> factory);
CreativeModeTab.Builder withTabsBefore(ResourceKey<CreativeModeTab>... tabs);
CreativeModeTab.Builder withTabsAfter(ResourceKey<CreativeModeTab>... tabs);
CreativeModeTab.Builder withTabsBefore(ResourceLocation... tabs);
CreativeModeTab.Builder withTabsAfter(ResourceLocation... tabs);

ResourceLocation kilt$getBackgroundLocation();
boolean kilt$hasSearchBar();
int kilt$searchBarWidth();
ResourceLocation kilt$getTabsImage();
int kilt$labelColor();
int kilt$slotColor();
Function<CreativeModeTab.Builder, CreativeModeTab> kilt$getTabFactory();
List<ResourceLocation> kilt$getTabsBefore();
List<ResourceLocation> kilt$getTabsAfter();
default CreativeModeTab.Builder withBackgroundLocation(ResourceLocation background) {
throw new IllegalStateException();
}
default CreativeModeTab.Builder withSearchBar() {
throw new IllegalStateException();
}
default CreativeModeTab.Builder withSearchBar(int searchBarWidth) {
throw new IllegalStateException();
}
default CreativeModeTab.Builder withTabsImage(ResourceLocation tabsImage) {
throw new IllegalStateException();
}
default CreativeModeTab.Builder withLabelColor(int labelColor) {
throw new IllegalStateException();
}
default CreativeModeTab.Builder withSlotColor(int slotColor) {
throw new IllegalStateException();
}
default CreativeModeTab.Builder withTabFactory(Function<CreativeModeTab.Builder, CreativeModeTab> factory) {
throw new IllegalStateException();
}
default CreativeModeTab.Builder withTabsBefore(ResourceKey<CreativeModeTab>... tabs) {
throw new IllegalStateException();
}
default CreativeModeTab.Builder withTabsAfter(ResourceKey<CreativeModeTab>... tabs) {
throw new IllegalStateException();
}
default CreativeModeTab.Builder withTabsBefore(ResourceLocation... tabs) {
throw new IllegalStateException();
}
default CreativeModeTab.Builder withTabsAfter(ResourceLocation... tabs) {
throw new IllegalStateException();
}

default ResourceLocation kilt$getBackgroundLocation() {
throw new IllegalStateException();
}
default boolean kilt$hasSearchBar() {
throw new IllegalStateException();
}
default int kilt$searchBarWidth() {
throw new IllegalStateException();
}
default ResourceLocation kilt$getTabsImage() {
throw new IllegalStateException();
}
default int kilt$labelColor() {
throw new IllegalStateException();
}
default int kilt$slotColor() {
throw new IllegalStateException();
}
default Function<CreativeModeTab.Builder, CreativeModeTab> kilt$getTabFactory() {
throw new IllegalStateException();
}
default List<ResourceLocation> kilt$getTabsBefore() {
throw new IllegalStateException();
}
default List<ResourceLocation> kilt$getTabsAfter() {
throw new IllegalStateException();
}
}
}
Loading

0 comments on commit dc6f72e

Please sign in to comment.