1.21 Update

Co-authored-by: RealMangoRage <[email protected]>
Co-authored-by: Daniel Norris <[email protected]>
Co-authored-by: Ven <[email protected]>
This commit is contained in:
committed 2024-06-13 10:42:32 -07:00
1 parent 3d9e12a71d
commit 4a2db246e0
941 files changed
+3119 -4266

No files matched your search

@@ -0,0 +1,20 @@
{
"anvil_cost": 5,
"description": {
"translate": "enchantment.global_loot_test.smelt"
},
"max_cost": {
"base": 15,
"per_level_above_first": 0
},
"max_level": 1,
"min_cost": {
"base": 15,
"per_level_above_first": 0
},
"slots": [
"mainhand"
],
"supported_items": "#minecraft:enchantable/mining_loot",
"weight": 1
}
@@ -7,7 +7,7 @@
"predicates": {
"minecraft:enchantments": [
{
"enchantment": "global_loot_test:smelt",
"enchantments": "global_loot_test:smelt",
"levels": {
"min": 1
}
+1 -1
View File
@@ -1,6 +1,6 @@
{
"pack": {
"description": "${mod_id} resources",
"pack_format": 32
"pack_format": 34
}
}
@@ -1,6 +1,6 @@
{
"pack": {
"description": "Forge tests resource pack",
"pack_format": 32
"pack_format": 34
}
}
@@ -30,8 +30,8 @@ public class CreativeModeTabTest {
public static final String MOD_ID = "creative_mode_tab_test";
private static final boolean ENABLED = true;
private static final ResourceKey<CreativeModeTab> LOGS = ResourceKey.create(Registries.CREATIVE_MODE_TAB, new ResourceLocation(MOD_ID, "logs"));
private static final ResourceKey<CreativeModeTab> STONE = ResourceKey.create(Registries.CREATIVE_MODE_TAB, new ResourceLocation(MOD_ID, "stone"));
private static final ResourceKey<CreativeModeTab> LOGS = ResourceKey.create(Registries.CREATIVE_MODE_TAB, ResourceLocation.fromNamespaceAndPath(MOD_ID, "logs"));
private static final ResourceKey<CreativeModeTab> STONE = ResourceKey.create(Registries.CREATIVE_MODE_TAB, ResourceLocation.fromNamespaceAndPath(MOD_ID, "stone"));
public CreativeModeTabTest() {
if (!ENABLED)
@@ -70,7 +70,7 @@ public class CreativeModeTabTest {
.withTabsAfter(CreativeModeTabs.BUILDING_BLOCKS)
.build());
helper.register(new ResourceLocation(MOD_ID, "colors"), CreativeModeTab.builder().title(Component.literal("Colors"))
helper.register(ResourceLocation.fromNamespaceAndPath(MOD_ID, "colors"), CreativeModeTab.builder().title(Component.literal("Colors"))
.displayItems((params, output) -> {
for (DyeColor color : DyeColor.values())
output.accept(DyeItem.byColor(color));
@@ -83,7 +83,7 @@ public class CreativeModeTabTest {
List<Block> blocks = List.of(Blocks.GRANITE, Blocks.DIORITE, Blocks.ANDESITE, Blocks.COBBLESTONE);
for (int i = 0; i < blocks.size(); i++) {
Block block = blocks.get(i);
helper.register(new ResourceLocation(MOD_ID, "dummy" + i), CreativeModeTab.builder()
helper.register(ResourceLocation.fromNamespaceAndPath(MOD_ID, "dummy" + i), CreativeModeTab.builder()
.title(Component.literal("Dummy " + i))
.icon(() -> new ItemStack(block))
.displayItems((params, output) -> output.accept(block))
@@ -92,7 +92,7 @@ public class CreativeModeTabTest {
}
//final ResourceLocation custom_tabs_image = new ResourceLocation(MOD_ID, "textures/gui/container/creative_inventory/custom_tabs.png");
helper.register(new ResourceLocation(MOD_ID, "with_tabs_image"), CreativeModeTab.builder()
helper.register(ResourceLocation.fromNamespaceAndPath(MOD_ID, "with_tabs_image"), CreativeModeTab.builder()
.title(Component.translatable("itemGroup.with_tabs_image"))
.icon(() -> new ItemStack(Blocks.BRICKS))
.displayItems((params, output) -> output.accept(Blocks.BRICKS))
@@ -35,9 +35,9 @@ import java.util.concurrent.CompletableFuture;
public class BiomeTestMod extends BaseTestMod {
public static final String MOD_ID = "biome_test_mod";
private static final ResourceKey<PlacedFeature> OVERWORLD_NETHERITE_BLOCK_ORE_PLACED_KEY = ResourceKey.create(Registries.PLACED_FEATURE, new ResourceLocation(BiomeTestMod.MOD_ID, "overworld_netherite_block_ore_placed"));
private static final ResourceKey<BiomeModifier> ADD_OVERWORLD_NETHERITE_BLOCK_ORE = ResourceKey.create(ForgeRegistries.Keys.BIOME_MODIFIERS, new ResourceLocation(BiomeTestMod.MOD_ID, "add_overworld_netherite_block_ore"));
private static final ResourceKey<ConfiguredFeature<?, ?>> OVERWORLD_NETHERITE_BLOCK_ORE = ResourceKey.create(Registries.CONFIGURED_FEATURE, new ResourceLocation(BiomeTestMod.MOD_ID, "overworld_netherite_block_ore"));
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 BiomeTestMod() {
var modBus = FMLJavaModLoadingContext.get().getModEventBus();
@@ -20,10 +20,12 @@ import net.minecraft.gametest.framework.GameTest;
import net.minecraft.gametest.framework.GameTestHelper;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.ItemTags;
import net.minecraft.world.Container;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.item.crafting.Recipe;
import net.minecraft.world.item.crafting.RecipeInput;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.item.crafting.SingleRecipeInput;
import net.minecraft.world.level.block.Blocks;
import net.minecraftforge.common.crafting.ConditionalRecipe;
import net.minecraftforge.common.crafting.SimpleCraftingContainer;
@@ -46,16 +48,16 @@ public class ConditionalRecipeTest extends BaseTestMod {
}
private static ResourceLocation rl(String path) {
return new ResourceLocation(MODID, path);
return ResourceLocation.fromNamespaceAndPath(MODID, path);
}
private static <C extends Container, T extends Recipe<C>> void assertFalse(GameTestHelper helper, RecipeType<T> type, C container) {
private static <C extends RecipeInput, T extends Recipe<C>> void assertFalse(GameTestHelper helper, RecipeType<T> type, C container) {
var recipe = helper.getLevel().getRecipeManager().getRecipeFor(type, container, helper.getLevel());
helper.assertTrue(recipe.isEmpty(), () -> "Found crafting recipe when unexpected: " + recipe.get().id());
helper.succeed();
}
private static <C extends Container, T extends Recipe<C>> void assertTrue(GameTestHelper helper, RecipeType<T> type, C container) {
private static <C extends RecipeInput, T extends Recipe<C>> void assertTrue(GameTestHelper helper, RecipeType<T> type, C container) {
var recipe = helper.getLevel().getRecipeManager().getRecipeFor(type, container, helper.getLevel());
helper.assertTrue(recipe.isPresent(), "Did not find crafting recipe when expected!");
helper.assertTrue(recipe.get().id().getNamespace().equals(MODID), "It wasn't our recipe: " + recipe.get().id());
@@ -108,38 +110,22 @@ public class ConditionalRecipeTest extends BaseTestMod {
@GameTest(template = "forge:empty3x3x3")
public static void cooking_false_conditions(GameTestHelper helper) {
assertFalse(helper, RecipeType.SMELTING, SimpleCraftingContainer.builder()
.pattern("X")
.define('X', Blocks.DIRT)
.build()
);
assertFalse(helper, RecipeType.SMELTING, new SingleRecipeInput(new ItemStack(Blocks.DIRT)));
}
@GameTest(template = "forge:empty3x3x3")
public static void cooking_true_conditions(GameTestHelper helper) {
assertTrue(helper, RecipeType.SMELTING, SimpleCraftingContainer.builder()
.pattern("X")
.define('X', Blocks.BEE_NEST)
.build()
);
assertTrue(helper, RecipeType.SMELTING, new SingleRecipeInput(new ItemStack(Blocks.BEE_NEST)));
}
@GameTest(template = "forge:empty3x3x3")
public static void single_item_false_conditions(GameTestHelper helper) {
assertFalse(helper, RecipeType.STONECUTTING, SimpleCraftingContainer.builder()
.pattern("X")
.define('X', Blocks.DIRT)
.build()
);
assertFalse(helper, RecipeType.STONECUTTING, new SingleRecipeInput(new ItemStack(Blocks.DIRT)));
}
@GameTest(template = "forge:empty3x3x3")
public static void single_item_true_conditions(GameTestHelper helper) {
assertTrue(helper, RecipeType.STONECUTTING, SimpleCraftingContainer.builder()
.pattern("X")
.define('X', Blocks.REDSTONE_ORE)
.build()
);
assertTrue(helper, RecipeType.STONECUTTING, new SingleRecipeInput(new ItemStack(Blocks.REDSTONE_ORE)));
}
@GameTest(template = "forge:empty3x3x3")
@@ -24,13 +24,13 @@ import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.ItemTags;
import net.minecraft.tags.TagKey;
import net.minecraft.world.Container;
import net.minecraft.world.inventory.CraftingContainer;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.component.CustomData;
import net.minecraft.world.item.crafting.CraftingInput;
import net.minecraft.world.item.crafting.Recipe;
import net.minecraft.world.item.crafting.RecipeInput;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.level.ItemLike;
import net.minecraftforge.common.crafting.SimpleCraftingContainer;
@@ -70,20 +70,20 @@ public class CustomIngredientsTest extends BaseTestMod implements INBTBuilder {
}
private static ResourceLocation rl(String path) {
return new ResourceLocation(MODID, path);
return ResourceLocation.fromNamespaceAndPath(MODID, path);
}
private static TagKey<Item> tag(String name) {
return ItemTags.create(rl(name));
}
private static <C extends Container, T extends Recipe<C>> void assertRecipeMiss(GameTestHelper helper, RecipeType<T> type, C container) {
private static <C extends RecipeInput, T extends Recipe<C>> void assertRecipeMiss(GameTestHelper helper, RecipeType<T> type, C container) {
var recipe = helper.getLevel().getRecipeManager().getRecipeFor(type, container, helper.getLevel());
helper.assertTrue(recipe.isEmpty(), () -> "Found crafting recipe when unexpected: " + recipe.get().id());
helper.succeed();
}
private static <C extends Container, T extends Recipe<C>> void assertRecipeMatch(GameTestHelper helper, RecipeType<T> type, C container, String name) {
private static <C extends RecipeInput, T extends Recipe<C>> void assertRecipeMatch(GameTestHelper helper, RecipeType<T> type, C container, String name) {
var recipe = helper.getLevel().getRecipeManager().getRecipeFor(type, container, helper.getLevel());
helper.assertTrue(recipe.isPresent(), "Did not find crafting recipe when expected!");
helper.assertTrue(recipe.get().id().getNamespace().equals(MODID), "It wasn't our recipe: " + recipe.get().id());
@@ -133,7 +133,7 @@ public class CustomIngredientsTest extends BaseTestMod implements INBTBuilder {
var iron_tag = tagged(Items.IRON_PICKAXE, both);
var diamond = stack(Items.DIAMOND_PICKAXE);
var diamond_tag = tagged(Items.DIAMOND_PICKAXE, both);
Function<ItemStack, CraftingContainer> container = (stack) ->
Function<ItemStack, CraftingInput> container = (stack) ->
SimpleCraftingContainer.builder()
.pattern("XXX")
.pattern("XXX")
@@ -167,7 +167,7 @@ public class CustomIngredientsTest extends BaseTestMod implements INBTBuilder {
@GameTest(template = "forge:empty3x3x3")
public static void compound(GameTestHelper helper) {
Function<ItemStack, CraftingContainer> container = (stack) ->
Function<ItemStack, CraftingInput> container = (stack) ->
SimpleCraftingContainer.builder()
.pattern("XXX")
.pattern(" X ")
@@ -183,7 +183,7 @@ public class CustomIngredientsTest extends BaseTestMod implements INBTBuilder {
@GameTest(template = "forge:empty3x3x3")
public static void strict(GameTestHelper helper) {
Function<ItemStack, CraftingContainer> container = (stack) ->
Function<ItemStack, CraftingInput> container = (stack) ->
SimpleCraftingContainer.builder()
.pattern("XXX")
.define('X', stack)
@@ -196,7 +196,7 @@ public class CustomIngredientsTest extends BaseTestMod implements INBTBuilder {
@GameTest(template = "forge:empty3x3x3")
public static void intersection(GameTestHelper helper) {
Function<ItemStack, CraftingContainer> container = (stack) ->
Function<ItemStack, CraftingInput> container = (stack) ->
SimpleCraftingContainer.builder()
.pattern("XXX")
.pattern("XXX")
@@ -212,7 +212,7 @@ public class CustomIngredientsTest extends BaseTestMod implements INBTBuilder {
@GameTest(template = "forge:empty3x3x3")
public static void difference(GameTestHelper helper) {
Function<ItemStack, CraftingContainer> container = (stack) ->
Function<ItemStack, CraftingInput> container = (stack) ->
SimpleCraftingContainer.builder()
.pattern(" X ")
.pattern("XXX")
@@ -53,7 +53,7 @@ public final class CriterionTest extends BaseTestMod {
private static final DeferredRegister<CriterionTrigger<?>> TRIGGERS = DeferredRegister.create(BuiltInRegistries.TRIGGER_TYPES.key(), MOD_ID);
public static final RegistryObject<BreakWithItemCriterion> CRITERION = TRIGGERS.register("criterion", BreakWithItemCriterion::new);
public static final String TEST_CRITERION_ID = "break_glass_with_fish";
public static final ResourceLocation TEST_ADVANCEMENT_ID = new ResourceLocation(MOD_ID, TEST_CRITERION_ID);
public static final ResourceLocation TEST_ADVANCEMENT_ID = ResourceLocation.fromNamespaceAndPath(MOD_ID, TEST_CRITERION_ID);
public CriterionTest() {
MinecraftForge.EVENT_BUS.addListener(this::onBlockBreak);
@@ -107,7 +107,7 @@ public final class CriterionTest extends BaseTestMod {
@SubscribeEvent
public void onGatherData(GatherDataEvent event) {
var tag = TagKey.create(Registries.ITEM, new ResourceLocation(MOD_ID, "fish"));
var tag = TagKey.create(Registries.ITEM, ResourceLocation.fromNamespaceAndPath(MOD_ID, "fish"));
event.getGenerator().addProvider(true, new TagsProvider<Item>(event.getGenerator().getPackOutput(), Registries.ITEM, event.getLookupProvider(), MOD_ID, event.getExistingFileHelper()) {
@Override
@@ -123,7 +123,7 @@ public final class CriterionTest extends BaseTestMod {
}
});
var STORY_ROOT = new AdvancementHolder(new ResourceLocation("minecraft", "story/root"), null);
var STORY_ROOT = new AdvancementHolder(ResourceLocation.fromNamespaceAndPath("minecraft", "story/root"), null);
event.getGenerator().addProvider(true,
new ForgeAdvancementProvider(
@@ -38,10 +38,10 @@ public class DatapackBuiltinEntriesProviderTest extends BaseTestMod {
public static final String MOD_ID = "datapack_builtin_entries_provider_test";
// Vanilla registry entries
public static final ResourceKey<ConfiguredFeature<?, ?>> MOSSY_STONE_FEATURE = ResourceKey.create(Registries.CONFIGURED_FEATURE, new ResourceLocation(MOD_ID, "mossy_stone"));
public static final ResourceKey<PlacedFeature> MOSSY_STONE_PLACEMENT = ResourceKey.create(Registries.PLACED_FEATURE, new ResourceLocation(MOD_ID, "mossy_stone"));
public static final ResourceKey<ConfiguredFeature<?, ?>> MOSSY_STONE_FEATURE = ResourceKey.create(Registries.CONFIGURED_FEATURE, ResourceLocation.fromNamespaceAndPath(MOD_ID, "mossy_stone"));
public static final ResourceKey<PlacedFeature> MOSSY_STONE_PLACEMENT = ResourceKey.create(Registries.PLACED_FEATURE, ResourceLocation.fromNamespaceAndPath(MOD_ID, "mossy_stone"));
// Forge registry entries
public static final ResourceKey<BiomeModifier> MOSSY_STONE_MODIFIER = ResourceKey.create(ForgeRegistries.Keys.BIOME_MODIFIERS, new ResourceLocation(MOD_ID, "mossy_stone_modifier"));
public static final ResourceKey<BiomeModifier> MOSSY_STONE_MODIFIER = ResourceKey.create(ForgeRegistries.Keys.BIOME_MODIFIERS, ResourceLocation.fromNamespaceAndPath(MOD_ID, "mossy_stone_modifier"));
// The ore targets
public static final Supplier<List<OreConfiguration.TargetBlockState>> MOSSY_STONE_TARGETS = () -> {
return List.of(
@@ -13,6 +13,7 @@ import net.minecraftforge.gametest.GameTestHolder;
import net.minecraftforge.test.BaseTestMod;
import java.util.List;
import java.util.Optional;
@GameTestHolder("forge." + GatherComponentsEventTest.MOD_ID)
@Mod(GatherComponentsEventTest.MOD_ID)
@@ -31,6 +32,7 @@ public class GatherComponentsEventTest extends BaseTestMod {
7,
true,
3,
Optional.empty(),
List.of()
));
}
@@ -71,8 +71,8 @@ public class ConditionalLootPools extends BaseTestMod {
}
private static class BlockLoot extends BlockLootSubProvider implements IConditionBuilder {
public BlockLoot() {
super(Set.of(), FeatureFlags.REGISTRY.allFlags());
public BlockLoot(HolderLookup.Provider lookup) {
super(Set.of(), FeatureFlags.REGISTRY.allFlags(), lookup);
}
@Override
@@ -17,7 +17,9 @@ import net.minecraft.advancements.critereon.ItemSubPredicates;
import net.minecraft.advancements.critereon.MinMaxBounds;
import net.minecraft.core.BlockPos;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.RegistrySetBuilder;
import net.minecraft.core.component.DataComponents;
import net.minecraft.core.registries.Registries;
import net.minecraft.util.ExtraCodecs;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
@@ -25,21 +27,25 @@ import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.data.PackOutput;
import net.minecraft.data.loot.BlockLootSubProvider;
import net.minecraft.data.loot.LootTableProvider;
import net.minecraft.data.registries.RegistryPatchGenerator;
import net.minecraft.gametest.framework.GameTest;
import net.minecraft.gametest.framework.GameTestHelper;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.ItemTags;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.world.item.enchantment.ItemEnchantments;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.EquipmentSlotGroup;
import net.minecraft.world.flag.FeatureFlags;
import net.minecraft.world.SimpleContainer;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.item.crafting.SingleRecipeInput;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.LootParams;
import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets;
@@ -48,6 +54,7 @@ import net.minecraft.world.level.storage.loot.predicates.LootItemBlockStatePrope
import net.minecraft.world.level.storage.loot.predicates.LootItemCondition;
import net.minecraft.world.level.storage.loot.predicates.MatchTool;
import net.minecraftforge.common.crafting.conditions.IConditionBuilder;
import net.minecraftforge.common.data.DatapackBuiltinEntriesProvider;
import net.minecraftforge.common.data.GlobalLootModifierProvider;
import net.minecraftforge.common.loot.IGlobalLootModifier;
import net.minecraftforge.common.loot.LootModifier;
@@ -82,8 +89,16 @@ public class GlobalLootModifiersTest extends BaseTestMod {
GLM.register("silk_touch_bamboo", SilkTouchTestModifier.CODEC);
}
private static final DeferredRegister<Enchantment> ENCHANTS = DeferredRegister.create(ForgeRegistries.ENCHANTMENTS, MODID);
private static final RegistryObject<Enchantment> SMELT = ENCHANTS.register("smelt", () -> new Enchantment(Enchantment.definition(ItemTags.MINING_LOOT_ENCHANTABLE, 1, 1, Enchantment.constantCost(15), Enchantment.constantCost(15), 5, EquipmentSlot.MAINHAND)));
private static final ResourceKey<Enchantment> SMELT = ResourceKey.create(Registries.ENCHANTMENT, ResourceLocation.fromNamespaceAndPath(MODID, "smelt"));
private static final Supplier<RegistrySetBuilder> ENCHANTMENTS = () -> new RegistrySetBuilder()
.add(Registries.ENCHANTMENT, ctx -> {
ctx.register(SMELT, Enchantment.enchantment(
Enchantment.definition(
ctx.lookup(Registries.ITEM).getOrThrow(ItemTags.MINING_LOOT_ENCHANTABLE), 1, 1,
Enchantment.constantCost(15), Enchantment.constantCost(15), 5, EquipmentSlotGroup.MAINHAND
)
).build(SMELT.location()));
});
private static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, MODID);
private static final RegistryObject<Block> TEST_BLOCK = BLOCKS.register("test", () -> new Block(BlockBehaviour.Properties.of()));
@@ -91,21 +106,26 @@ public class GlobalLootModifiersTest extends BaseTestMod {
private static final RegistryObject<Item> TEST_ITEM = ITEMS.register("test", () -> new BlockItem(TEST_BLOCK.get(), new Item.Properties()));
public GlobalLootModifiersTest() {
testItem(() -> getTestItem());
testItem(lookup -> getTestItem(lookup.lookup(Registries.ENCHANTMENT).get()));
}
private static ItemStack getTestItem() {
private static ItemStack getTestItem(HolderLookup<Enchantment> lookup) {
var smelt = new ItemStack(Items.IRON_AXE);
var enchants = new ItemEnchantments.Mutable(EnchantmentHelper.getEnchantmentsForCrafting(smelt));
enchants.set(SMELT.get(), 1);
enchants.set(lookup.getOrThrow(SMELT), 1);
smelt.set(DataComponents.ENCHANTMENTS, enchants.toImmutable());
return smelt;
}
@SubscribeEvent
public void runData(GatherDataEvent event) {
event.getGenerator().addProvider(event.includeServer(), new DataProvider(event.getGenerator().getPackOutput(), MODID, event.getLookupProvider()));
event.getGenerator().addProvider(event.includeServer(), new LootProvider(event.getGenerator().getPackOutput(), event.getLookupProvider()));
var out = event.getGenerator().getPackOutput();
var lookup = event.getLookupProvider();
var patched = RegistryPatchGenerator.createLookup(lookup, ENCHANTMENTS.get())
.thenApply(RegistrySetBuilder.PatchedRegistries::patches);
event.getGenerator().addProvider(event.includeServer(), new DatapackBuiltinEntriesProvider(out, lookup, ENCHANTMENTS.get(), Set.of(MODID)));
event.getGenerator().addProvider(event.includeServer(), new ModifierProvider(out, MODID, patched));
event.getGenerator().addProvider(event.includeServer(), new LootProvider(out, lookup));
}
@GameTest(template = "forge:empty3x3x3")
@@ -113,7 +133,7 @@ public class GlobalLootModifiersTest extends BaseTestMod {
var center = new BlockPos(1, 1, 1);
helper.setBlock(center, Blocks.OAK_LOG);
var smelt = getTestItem();
var smelt = getTestItem(helper.getLevel().holderLookup(Registries.ENCHANTMENT));
var player = helper.makeMockServerPlayer();
player.setItemSlot(EquipmentSlot.MAINHAND, smelt);
@@ -142,13 +162,15 @@ public class GlobalLootModifiersTest extends BaseTestMod {
helper.succeed();
}
private static class DataProvider extends GlobalLootModifierProvider {
public DataProvider(PackOutput output, String modid, CompletableFuture<HolderLookup.Provider> registries) {
private static class ModifierProvider extends GlobalLootModifierProvider {
public ModifierProvider(PackOutput output, String modid, CompletableFuture<HolderLookup.Provider> registries) {
super(output, modid, registries);
}
@Override
protected void start() {
protected void start(HolderLookup.Provider registries) {
var smelt = registries.lookupOrThrow(Registries.ENCHANTMENT).getOrThrow(SMELT);
add("smelting", new SmeltingEnchantmentModifier(
new LootItemCondition[]{
MatchTool.toolMatches(
@@ -156,7 +178,7 @@ public class GlobalLootModifiersTest extends BaseTestMod {
.withSubPredicate(
ItemSubPredicates.ENCHANTMENTS,
ItemEnchantmentsPredicate.enchantments(List.of(
new EnchantmentPredicate(SMELT.getHolder(), MinMaxBounds.Ints.atLeast(1))
new EnchantmentPredicate(smelt, MinMaxBounds.Ints.atLeast(1))
))
)
).build()
@@ -194,8 +216,8 @@ public class GlobalLootModifiersTest extends BaseTestMod {
}
private static class BlockLoot extends BlockLootSubProvider implements IConditionBuilder {
public BlockLoot() {
super(Set.of(), FeatureFlags.REGISTRY.allFlags());
public BlockLoot(HolderLookup.Provider lookup) {
super(Set.of(), FeatureFlags.REGISTRY.allFlags(), lookup);
}
@Override
@@ -237,7 +259,7 @@ public class GlobalLootModifiersTest extends BaseTestMod {
var mgr = context.getLevel().getRecipeManager();
var reg = context.getLevel().registryAccess();
return mgr
.getRecipeFor(RecipeType.SMELTING, new SimpleContainer(stack), context.getLevel())
.getRecipeFor(RecipeType.SMELTING, new SingleRecipeInput(stack), context.getLevel())
.map(holder -> holder.value())
.map(recipe -> recipe.getResultItem(reg))
.filter(itemStack -> !itemStack.isEmpty())
@@ -272,9 +294,11 @@ public class GlobalLootModifiersTest extends BaseTestMod {
public ObjectArrayList<ItemStack> doApply(ObjectArrayList<ItemStack> generatedLoot, LootContext context) {
var ctxTool = context.getParamOrNull(LootContextParams.TOOL);
//return early if silk-touch is already applied (otherwise we'll get stuck in an infinite loop).
if (ctxTool == null || ctxTool.isEmpty() || ctxTool.getEnchantmentLevel(Enchantments.SILK_TOUCH) > 0) return generatedLoot;
var silk = context.getLevel().holderLookup(Registries.ENCHANTMENT).getOrThrow(Enchantments.SILK_TOUCH);
var silkLevel = EnchantmentHelper.getItemEnchantmentLevel(silk, ctxTool);
if (ctxTool == null || ctxTool.isEmpty() || silkLevel > 0) return generatedLoot;
var fakeTool = ctxTool.copy();
fakeTool.enchant(Enchantments.SILK_TOUCH, 1);
fakeTool.enchant(silk, 1);
var params = new LootParams.Builder(context.getLevel())
.withParameter(LootContextParams.TOOL, fakeTool)
.create(LootContextParamSets.EMPTY);
@@ -9,9 +9,9 @@ import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Supplier;
import java.util.function.Function;
import net.minecraft.world.item.ItemStack;
import net.minecraft.core.HolderLookup;
import net.minecraft.world.item.CreativeModeTab.TabVisibility;
import net.minecraftforge.event.BuildCreativeModeTabContentsEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
@@ -19,7 +19,7 @@ import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.DeferredRegister;
public abstract class BaseTestMod {
private List<Supplier<ItemStack>> testItems = new ArrayList<>();
private List<Function<HolderLookup.Provider, ItemStack>> testItems = new ArrayList<>();
protected BaseTestMod() {
// TODO: Some form of enable flag?
@@ -41,18 +41,17 @@ public abstract class BaseTestMod {
}
}
protected Supplier<ItemStack> testItem(Supplier<ItemStack> supplier) {
protected void testItem(Function<HolderLookup.Provider, ItemStack> supplier) {
this.testItems.add(supplier);
return supplier;
}
@SubscribeEvent
protected void onCreativeModeTabBuildContents(BuildCreativeModeTabContentsEvent event) {
var entries = event.getEntries();
var lookup = event.getParameters().holders();
if (event.getTabKey() == TestHelperMod.TAB) {
for (var s : testItems)
entries.put(s.get(), TabVisibility.PARENT_AND_SEARCH_TABS);
entries.put(s.apply(lookup), TabVisibility.PARENT_AND_SEARCH_TABS);
}
}
@@ -27,7 +27,7 @@ import net.minecraftforge.registries.RegisterEvent;
@Mod(TestHelperMod.MOD_ID)
public class TestHelperMod extends BaseTestMod {
public static final String MOD_ID = "test_helper_mod";
public static final ResourceKey<CreativeModeTab> TAB = ResourceKey.create(Registries.CREATIVE_MODE_TAB, new ResourceLocation(MOD_ID, "test_items"));
public static final ResourceKey<CreativeModeTab> TAB = ResourceKey.create(Registries.CREATIVE_MODE_TAB, ResourceLocation.fromNamespaceAndPath(MOD_ID, "test_items"));
@SubscribeEvent
public void onRegister(RegisterEvent event) {