[Change] More consistent Names for Anvil Mixins

This commit is contained in:
Frank 2023-04-22 16:45:50 +02:00
parent 842501af48
commit 6a0749f8ce
3 changed files with 36 additions and 37 deletions

View file

@ -6,31 +6,31 @@ import org.betterx.bclib.recipes.AnvilRecipe;
import java.util.List; import java.util.List;
public interface AnvilScreenHandlerExtended { public interface AnvilScreenHandlerExtended {
void be_updateCurrentRecipe(AnvilRecipe recipe); void bcl_updateCurrentRecipe(AnvilRecipe recipe);
AnvilRecipe be_getCurrentRecipe(); AnvilRecipe bcl_getCurrentRecipe();
List<AnvilRecipe> be_getRecipes(); List<AnvilRecipe> bcl_getRecipes();
default void be_nextRecipe() { default void be_nextRecipe() {
List<AnvilRecipe> recipes = be_getRecipes(); List<AnvilRecipe> recipes = bcl_getRecipes();
if (recipes.size() < 2) return; if (recipes.size() < 2) return;
AnvilRecipe current = be_getCurrentRecipe(); AnvilRecipe current = bcl_getCurrentRecipe();
int i = recipes.indexOf(current) + 1; int i = recipes.indexOf(current) + 1;
if (i >= recipes.size()) { if (i >= recipes.size()) {
i = 0; i = 0;
} }
be_updateCurrentRecipe(recipes.get(i)); bcl_updateCurrentRecipe(recipes.get(i));
} }
default void be_previousRecipe() { default void be_previousRecipe() {
List<AnvilRecipe> recipes = be_getRecipes(); List<AnvilRecipe> recipes = bcl_getRecipes();
if (recipes.size() < 2) return; if (recipes.size() < 2) return;
AnvilRecipe current = be_getCurrentRecipe(); AnvilRecipe current = bcl_getCurrentRecipe();
int i = recipes.indexOf(current) - 1; int i = recipes.indexOf(current) - 1;
if (i <= 0) { if (i <= 0) {
i = recipes.size() - 1; i = recipes.size() - 1;
} }
be_updateCurrentRecipe(recipes.get(i)); bcl_updateCurrentRecipe(recipes.get(i));
} }
} }

View file

@ -74,8 +74,8 @@ public class AnvilScreenMixin extends ItemCombinerScreen<AnvilMenu> {
@Inject(method = "slotChanged", at = @At("HEAD"), cancellable = true) @Inject(method = "slotChanged", at = @At("HEAD"), cancellable = true)
public void be_onSlotUpdate(AbstractContainerMenu handler, int slotId, ItemStack stack, CallbackInfo info) { public void be_onSlotUpdate(AbstractContainerMenu handler, int slotId, ItemStack stack, CallbackInfo info) {
AnvilScreenHandlerExtended anvilHandler = (AnvilScreenHandlerExtended) handler; AnvilScreenHandlerExtended anvilHandler = (AnvilScreenHandlerExtended) handler;
if (anvilHandler.be_getCurrentRecipe() != null) { if (anvilHandler.bcl_getCurrentRecipe() != null) {
if (anvilHandler.be_getRecipes().size() > 1) { if (anvilHandler.bcl_getRecipes().size() > 1) {
be_buttons.forEach(button -> button.visible = true); be_buttons.forEach(button -> button.visible = true);
} else { } else {
be_buttons.forEach(button -> button.visible = false); be_buttons.forEach(button -> button.visible = false);

View file

@ -5,7 +5,6 @@ import org.betterx.bclib.blocks.LeveledAnvilBlock;
import org.betterx.bclib.interfaces.AnvilScreenHandlerExtended; import org.betterx.bclib.interfaces.AnvilScreenHandlerExtended;
import org.betterx.bclib.recipes.AnvilRecipe; import org.betterx.bclib.recipes.AnvilRecipe;
import net.minecraft.client.Minecraft;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.tags.BlockTags; import net.minecraft.tags.BlockTags;
import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Inventory;
@ -34,7 +33,7 @@ import org.jetbrains.annotations.Nullable;
@Mixin(AnvilMenu.class) @Mixin(AnvilMenu.class)
public abstract class AnvilMenuMixin extends ItemCombinerMenu implements AnvilScreenHandlerExtended { public abstract class AnvilMenuMixin extends ItemCombinerMenu implements AnvilScreenHandlerExtended {
private List<AnvilRecipe> be_recipes = Collections.emptyList(); private List<AnvilRecipe> be_recipes = Collections.emptyList();
private AnvilRecipe be_currentRecipe; private AnvilRecipe bcl_currentRecipe;
private DataSlot anvilLevel; private DataSlot anvilLevel;
@Shadow @Shadow
@ -71,14 +70,14 @@ public abstract class AnvilMenuMixin extends ItemCombinerMenu implements AnvilSc
public abstract void createResult(); public abstract void createResult();
@Inject(method = "mayPickup", at = @At("HEAD"), cancellable = true) @Inject(method = "mayPickup", at = @At("HEAD"), cancellable = true)
protected void be_canTakeOutput(Player player, boolean present, CallbackInfoReturnable<Boolean> info) { protected void bcl_canTakeOutput(Player player, boolean present, CallbackInfoReturnable<Boolean> info) {
if (be_currentRecipe != null) { if (bcl_currentRecipe != null) {
info.setReturnValue(be_currentRecipe.checkHammerDurability(inputSlots, player)); info.setReturnValue(bcl_currentRecipe.checkHammerDurability(inputSlots, player));
} }
} }
@Inject(method = "method_24922", at = @At(value = "HEAD"), cancellable = true) @Inject(method = "method_24922", at = @At(value = "HEAD"), cancellable = true)
private static void bclib_onDamageAnvil(Player player, Level level, BlockPos blockPos, CallbackInfo ci) { private static void bcl_onDamageAnvil(Player player, Level level, BlockPos blockPos, CallbackInfo ci) {
BlockState blockState = level.getBlockState(blockPos); BlockState blockState = level.getBlockState(blockPos);
if (blockState.getBlock() instanceof BaseAnvilBlock anvil) { if (blockState.getBlock() instanceof BaseAnvilBlock anvil) {
BlockState damaged = anvil.damageAnvilUse(blockState, player.getRandom()); BlockState damaged = anvil.damageAnvilUse(blockState, player.getRandom());
@ -98,12 +97,12 @@ public abstract class AnvilMenuMixin extends ItemCombinerMenu implements AnvilSc
} }
@Inject(method = "onTake", at = @At("HEAD"), cancellable = true) @Inject(method = "onTake", at = @At("HEAD"), cancellable = true)
protected void bclib_onTakeAnvilOutput(Player player, ItemStack stack, CallbackInfo info) { protected void bcl_onTakeAnvilOutput(Player player, ItemStack stack, CallbackInfo info) {
if (be_currentRecipe != null) { if (bcl_currentRecipe != null) {
final int ingredientSlot = AnvilRecipe.getIngredientSlot(inputSlots); final int ingredientSlot = AnvilRecipe.getIngredientSlot(inputSlots);
inputSlots.getItem(ingredientSlot).shrink(be_currentRecipe.getInputCount()); inputSlots.getItem(ingredientSlot).shrink(bcl_currentRecipe.getInputCount());
stack = be_currentRecipe.craft(inputSlots, player); stack = bcl_currentRecipe.craft(inputSlots, player);
slotsChanged(inputSlots); slotsChanged(inputSlots);
access.execute((level, blockPos) -> { access.execute((level, blockPos) -> {
final BlockState anvilState = level.getBlockState(blockPos); final BlockState anvilState = level.getBlockState(blockPos);
@ -124,7 +123,7 @@ public abstract class AnvilMenuMixin extends ItemCombinerMenu implements AnvilSc
} }
@Inject(method = "createResult", at = @At("HEAD"), cancellable = true) @Inject(method = "createResult", at = @At("HEAD"), cancellable = true)
public void be_updateOutput(CallbackInfo info) { public void bcl_updateOutput(CallbackInfo info) {
RecipeManager recipeManager = this.player.level.getRecipeManager(); RecipeManager recipeManager = this.player.level.getRecipeManager();
be_recipes = recipeManager.getRecipesFor(AnvilRecipe.TYPE, inputSlots, player.level); be_recipes = recipeManager.getRecipesFor(AnvilRecipe.TYPE, inputSlots, player.level);
if (be_recipes.size() > 0) { if (be_recipes.size() > 0) {
@ -133,20 +132,20 @@ public abstract class AnvilMenuMixin extends ItemCombinerMenu implements AnvilSc
.filter(recipe -> anvilLevel >= recipe.getAnvilLevel()) .filter(recipe -> anvilLevel >= recipe.getAnvilLevel())
.collect(Collectors.toList()); .collect(Collectors.toList());
if (be_recipes.size() > 0) { if (be_recipes.size() > 0) {
if (be_currentRecipe == null || !be_recipes.contains(be_currentRecipe)) { if (bcl_currentRecipe == null || !be_recipes.contains(bcl_currentRecipe)) {
be_currentRecipe = be_recipes.get(0); bcl_currentRecipe = be_recipes.get(0);
} }
be_updateResult(); bcl_updateResult();
info.cancel(); info.cancel();
} else { } else {
be_currentRecipe = null; bcl_currentRecipe = null;
} }
} }
} }
@Inject(method = "setItemName", at = @At("HEAD"), cancellable = true) @Inject(method = "setItemName", at = @At("HEAD"), cancellable = true)
public void be_setNewItemName(String string, CallbackInfo info) { public void bcl_setNewItemName(String string, CallbackInfo info) {
if (be_currentRecipe != null) { if (bcl_currentRecipe != null) {
info.cancel(); info.cancel();
} }
} }
@ -163,25 +162,25 @@ public abstract class AnvilMenuMixin extends ItemCombinerMenu implements AnvilSc
return super.clickMenuButton(player, id); return super.clickMenuButton(player, id);
} }
private void be_updateResult() { private void bcl_updateResult() {
if (be_currentRecipe == null) return; if (bcl_currentRecipe == null) return;
resultSlots.setItem(0, be_currentRecipe.assemble(inputSlots, Minecraft.getInstance().level.registryAccess())); resultSlots.setItem(0, bcl_currentRecipe.assemble(inputSlots, this.player.level.registryAccess()));
broadcastChanges(); broadcastChanges();
} }
@Override @Override
public void be_updateCurrentRecipe(AnvilRecipe recipe) { public void bcl_updateCurrentRecipe(AnvilRecipe recipe) {
this.be_currentRecipe = recipe; this.bcl_currentRecipe = recipe;
be_updateResult(); bcl_updateResult();
} }
@Override @Override
public AnvilRecipe be_getCurrentRecipe() { public AnvilRecipe bcl_getCurrentRecipe() {
return be_currentRecipe; return bcl_currentRecipe;
} }
@Override @Override
public List<AnvilRecipe> be_getRecipes() { public List<AnvilRecipe> bcl_getRecipes() {
return be_recipes; return be_recipes;
} }
} }