Skip to content

Commit

Permalink
Merge branch '1.20.5' into Common-Tag-Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
TelepathicGrunt committed Apr 14, 2024
2 parents 7b3c4df + cfb0a2d commit ef1f4ce
Show file tree
Hide file tree
Showing 66 changed files with 1,417 additions and 235 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
id "idea"
id "maven-publish"
id 'jacoco'
id "fabric-loom" version "1.6.3" apply false
id "fabric-loom" version "1.6.5" apply false
id "com.diffplug.spotless" version "6.20.0"
id "org.ajoberstar.grgit" version "3.1.0"
id "me.modmuss50.remotesign" version "0.4.0" apply false
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.fabricmc.fabric.api.registry;

import net.minecraft.item.Item;
import net.minecraft.potion.Potion;
import net.minecraft.recipe.BrewingRecipeRegistry;
import net.minecraft.recipe.Ingredient;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.resource.featuretoggle.FeatureSet;

import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;

/**
* An extension of {@link BrewingRecipeRegistry.Builder} to support ingredients.
*/
public interface FabricBrewingRecipeRegistryBuilder {
/**
* An event that is called when the brewing recipe registry is being built.
*/
Event<FabricBrewingRecipeRegistryBuilder.BuildCallback> BUILD = EventFactory.createArrayBacked(FabricBrewingRecipeRegistryBuilder.BuildCallback.class, listeners -> builder -> {
for (FabricBrewingRecipeRegistryBuilder.BuildCallback listener : listeners) {
listener.build(builder);
}
});

default void registerItemRecipe(Item input, Ingredient ingredient, Item output) {
throw new AssertionError("Must be implemented via interface injection");
}

default void registerPotionRecipe(RegistryEntry<Potion> input, Ingredient ingredient, RegistryEntry<Potion> output) {
throw new AssertionError("Must be implemented via interface injection");
}

default void registerRecipes(Ingredient ingredient, RegistryEntry<Potion> potion) {
throw new AssertionError("Must be implemented via interface injection");
}

default FeatureSet getEnabledFeatures() {
throw new AssertionError("Must be implemented via interface injection");
}

/**
* Use this event to register custom brewing recipes.
*/
@FunctionalInterface
interface BuildCallback {
/**
* Called when the brewing recipe registry is being built.
*
* @param builder the {@link BrewingRecipeRegistry} instance
*/
void build(BrewingRecipeRegistry.Builder builder);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,74 @@

package net.fabricmc.fabric.mixin.content.registry;

import java.util.List;

import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import net.minecraft.item.Item;
import net.minecraft.potion.Potion;
import net.minecraft.potion.Potions;
import net.minecraft.recipe.BrewingRecipeRegistry;
import net.minecraft.recipe.Ingredient;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.resource.featuretoggle.FeatureSet;

import net.fabricmc.fabric.api.registry.FabricBrewingRecipeRegistryBuilder;

import net.fabricmc.fabric.api.registry.BrewingRecipeRegistryBuilderCallback;
@Mixin(BrewingRecipeRegistry.Builder.class)
public abstract class BrewingRecipeRegistryBuilderMixin implements FabricBrewingRecipeRegistryBuilder {
@Shadow
@Final
private FeatureSet enabledFeatures;

@Shadow
private static void assertPotion(Item potionType) {
}

@Mixin(BrewingRecipeRegistry.class_9665.class)
public class BrewingRecipeRegistryBuilderMixin {
@Inject(method = "method_59701", at = @At("HEAD"))
@Shadow
@Final
private List<BrewingRecipeRegistry.Recipe<Item>> itemRecipes;

@Shadow
@Final
private List<BrewingRecipeRegistry.Recipe<Potion>> potionRecipes;

@Inject(method = "build", at = @At("HEAD"))
private void build(CallbackInfoReturnable<BrewingRecipeRegistry> cir) {
BrewingRecipeRegistryBuilderCallback.BUILD.invoker().build((BrewingRecipeRegistry.class_9665) (Object) this);
FabricBrewingRecipeRegistryBuilder.BUILD.invoker().build((BrewingRecipeRegistry.Builder) (Object) this);
}

@Override
public void registerItemRecipe(Item input, Ingredient ingredient, Item output) {
if (input.isEnabled(this.enabledFeatures) && output.isEnabled(this.enabledFeatures)) {
assertPotion(input);
assertPotion(output);
this.itemRecipes.add(new BrewingRecipeRegistry.Recipe<>(input.getRegistryEntry(), ingredient, output.getRegistryEntry()));
}
}

@Override
public void registerPotionRecipe(RegistryEntry<Potion> input, Ingredient ingredient, RegistryEntry<Potion> output) {
if (input.value().isEnabled(this.enabledFeatures) && output.value().isEnabled(this.enabledFeatures)) {
this.potionRecipes.add(new BrewingRecipeRegistry.Recipe<>(input, ingredient, output));
}
}

@Override
public void registerRecipes(Ingredient ingredient, RegistryEntry<Potion> potion) {
if (potion.value().isEnabled(this.enabledFeatures)) {
this.registerPotionRecipe(Potions.WATER, ingredient, Potions.MUNDANE);
this.registerPotionRecipe(Potions.AWKWARD, ingredient, potion);
}
}

@Override
public FeatureSet getEnabledFeatures() {
return this.enabledFeatures;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
],
"accessWidener" : "fabric-content-registries-v0.accesswidener",
"custom": {
"fabric-api:module-lifecycle": "stable"
"fabric-api:module-lifecycle": "stable",
"loom:injected_interfaces": {
"net/minecraft/class_1845\u0024class_9665": ["net/fabricmc/fabric/api/registry/FabricBrewingRecipeRegistryBuilder"]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,16 @@
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.item.PotionItem;
import net.minecraft.potion.Potions;
import net.minecraft.recipe.Ingredient;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.registry.tag.BlockTags;
import net.minecraft.registry.tag.ItemTags;
import net.minecraft.resource.featuretoggle.FeatureFlags;
import net.minecraft.text.Text;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Identifier;
Expand All @@ -47,8 +50,8 @@
import net.minecraft.world.event.GameEvent;

import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.registry.BrewingRecipeRegistryBuilderCallback;
import net.fabricmc.fabric.api.registry.CompostingChanceRegistry;
import net.fabricmc.fabric.api.registry.FabricBrewingRecipeRegistryBuilder;
import net.fabricmc.fabric.api.registry.FlammableBlockRegistry;
import net.fabricmc.fabric.api.registry.FlattenableBlockRegistry;
import net.fabricmc.fabric.api.registry.FuelRegistry;
Expand Down Expand Up @@ -84,6 +87,7 @@ public void onInitialize() {
// - assign a loot table to the nitwit villager type
// - right-clicking a 'test_event' block will emit a 'test_event' game event, which will have a sculk sensor frequency of 2
// - instant health potions can be brewed from awkward potions with any item in the 'minecraft:small_flowers' tag
// - if Bundle experiment is enabled, luck potions can be brewed from awkward potions with a bundle
// - dirty potions can be brewed by adding any item in the 'minecraft:dirt' tag to any standard potion

CompostingChanceRegistry.INSTANCE.add(Items.OBSIDIAN, 0.5F);
Expand Down Expand Up @@ -156,11 +160,14 @@ public void onInitialize() {
dirtyPotion);
/* Mods should use BrewingRecipeRegistry.registerPotionType(Item), which is access widened by fabric-transitive-access-wideners-v1
* This testmod uses an accessor due to Loom limitations that prevent TAWs from applying across Gradle subproject boundaries */
BrewingRecipeRegistryBuilderCallback.BUILD.register(builder -> {
builder.method_59702(dirtyPotion);
// TODO 1.20.5 Ingredient.fromTag(ItemTags.DIRT)
builder.method_59703(Items.POTION, Items.DIRT, dirtyPotion);
// registerPotionRecipe(Potions.AWKWARD, Ingredient.fromTag(ItemTags.SMALL_FLOWERS), Potions.HEALING);
FabricBrewingRecipeRegistryBuilder.BUILD.register(builder -> {
builder.registerPotionType(dirtyPotion);
builder.registerItemRecipe(Items.POTION, Ingredient.fromTag(ItemTags.DIRT), dirtyPotion);
builder.registerPotionRecipe(Potions.AWKWARD, Ingredient.fromTag(ItemTags.SMALL_FLOWERS), Potions.HEALING);

if (builder.getEnabledFeatures().contains(FeatureFlags.BUNDLE)) {
builder.registerPotionRecipe(Potions.AWKWARD, Ingredient.ofItems(Items.BUNDLE), Potions.LUCK);
}
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@
* <p>For preventing block breaking client side and other purposes, see {@link net.fabricmc.fabric.api.event.player.AttackBlockCallback}.
* For server side block break events, see {@link net.fabricmc.fabric.api.event.player.PlayerBlockBreakEvents}.
*/
public class ClientPlayerBlockBreakEvents {
public final class ClientPlayerBlockBreakEvents {
private ClientPlayerBlockBreakEvents() {
}

/**
* Callback after a block is broken client side.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
*
* <p>On the logical client, the return values have the following meaning:
* <ul>
* <li>SUCCESS cancels further processing, causes a hand swing, and sends a packet to the server.</li>
* <li>SUCCESS/SUCCESS_NO_ITEM_USED cancels further processing, causes a hand swing, and sends a packet to the server.</li>
* <li>CONSUME cancels further processing, and sends a packet to the server. It does NOT cause a hand swing.</li>
* <li>PASS falls back to further processing.</li>
* <li>FAIL cancels further processing and does not send a packet to the server.</li>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.fabricmc.fabric.api.item.v1;

import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.item.ItemStack;
import net.minecraft.resource.featuretoggle.FeatureSet;
import net.minecraft.util.math.random.Random;

/*
* There is one context for each vanilla call to Enchantment#isAcceptableItem. The reason why RANDOM_ENCHANTMENT
* feels like a kitchen sink is because it corresponds to the one in EnchantmentHelper, which is shared across multiple
* uses.
*
* This also gets in the way of adding further context (nullable Player and BlockPos have been suggested
* in the past). It's not impossible to do so, but a probably a bit more brittle.
*/
/**
* An enum that describes the various contexts in which the game checks whether an enchantment can be applied to an item.
*/
public enum EnchantingContext {
/**
* When generating a random enchantment for the item. This includes the enchanting table, random
* mob equipment, and the {@code enchant_with_levels} loot function.
*
* @see EnchantmentHelper#generateEnchantments(FeatureSet, Random, ItemStack, int, boolean)
*/
RANDOM_ENCHANTMENT,
/**
* When trying to apply an enchantment in an anvil.
*/
ANVIL,
/**
* When using the {@code /enchant} command.
*/
ENCHANT_COMMAND,
/**
* When randomly enchanting an item using the {@code enchant_randomly} loot function without a list of enchantments
* to choose from.
*/
LOOT_RANDOM_ENCHANTMENT
}
Loading

0 comments on commit ef1f4ce

Please sign in to comment.