From c013e22051cb5ae80736526663d98c747b6cbd56 Mon Sep 17 00:00:00 2001 From: repulica Date: Wed, 16 Sep 2020 02:16:57 -0700 Subject: [PATCH 01/11] implement meter and dynamic remainder --- .../api/item/settings/MeterComponent.java | 62 +++++++++++++ .../woven/api/item/settings/TemplateAPI.java | 25 ------ .../api/item/settings/WovenItemSettings.java | 87 +++++++++++++++++++ .../item/settings/WovenSettingsHolder.java | 16 ++++ .../item/settings/TemplateModInitializer.java | 28 ------ .../MixinAbstractFurnaceBlockEntity.java | 33 +++++++ .../settings/MixinBannerDuplicateRecipe.java | 36 ++++++++ .../item/settings/MixinBookCloningRecipe.java | 36 ++++++++ .../MixinBrewingStandBlockEntity.java | 33 +++++++ .../woven/mixin/item/settings/MixinItem.java | 40 +++++++++ .../mixin/item/settings/MixinRecipe.java | 38 ++++++++ .../settings/client/MixinItemRenderer.java | 74 ++++++++++++++++ .../resources/woven-item-settings.mixins.json | 9 ++ 13 files changed, 464 insertions(+), 53 deletions(-) create mode 100644 src/main/java/net/wovenmc/woven/api/item/settings/MeterComponent.java delete mode 100644 src/main/java/net/wovenmc/woven/api/item/settings/TemplateAPI.java create mode 100644 src/main/java/net/wovenmc/woven/api/item/settings/WovenItemSettings.java create mode 100644 src/main/java/net/wovenmc/woven/api/item/settings/WovenSettingsHolder.java delete mode 100644 src/main/java/net/wovenmc/woven/impl/item/settings/TemplateModInitializer.java create mode 100644 src/main/java/net/wovenmc/woven/mixin/item/settings/MixinAbstractFurnaceBlockEntity.java create mode 100644 src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBannerDuplicateRecipe.java create mode 100644 src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBookCloningRecipe.java create mode 100644 src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBrewingStandBlockEntity.java create mode 100644 src/main/java/net/wovenmc/woven/mixin/item/settings/MixinItem.java create mode 100644 src/main/java/net/wovenmc/woven/mixin/item/settings/MixinRecipe.java create mode 100644 src/main/java/net/wovenmc/woven/mixin/item/settings/client/MixinItemRenderer.java diff --git a/src/main/java/net/wovenmc/woven/api/item/settings/MeterComponent.java b/src/main/java/net/wovenmc/woven/api/item/settings/MeterComponent.java new file mode 100644 index 0000000..45b3668 --- /dev/null +++ b/src/main/java/net/wovenmc/woven/api/item/settings/MeterComponent.java @@ -0,0 +1,62 @@ +package net.wovenmc.woven.api.item.settings; + +import java.util.function.BiFunction; +import java.util.function.Function; + +import it.unimi.dsi.fastutil.objects.Object2FloatFunction; +import org.lwjgl.system.MathUtil; + +import net.minecraft.item.ItemStack; +import net.minecraft.util.math.MathHelper; + +public class MeterComponent { + private final Function levelFunc; + private final BiFunction colorFunc; + private final boolean displayAtFull; + + private MeterComponent(Function levelFunc, BiFunction colorFunc, + boolean displayAtFull) { + this.levelFunc = levelFunc; + this.colorFunc = colorFunc; + this.displayAtFull = displayAtFull; + } + + public float getLevel(ItemStack stack) { + return levelFunc.apply(stack); + } + + public int getColor(ItemStack stack) { + return colorFunc.apply(stack, levelFunc.apply(stack)); + } + + public boolean displayAtFull() { + return displayAtFull; + } + + public static class Builder { + private Function levelFunc = stack -> + (stack.getMaxDamage() - stack.getDamage()) / (float)stack.getMaxDamage(); + private BiFunction colorFunc = (stack, level) -> + MathHelper.hsvToRgb(levelFunc.apply(stack) / 3F, 1F, 1F); + private boolean displayAtFull = false; + + public Builder levelFunction(Function function) { + this.levelFunc = function; + return this; + } + + public Builder colorFunction(BiFunction function) { + this.colorFunc = function; + return this; + } + + public Builder displayAtFull() { + this.displayAtFull = true; + return this; + } + + public MeterComponent build() { + return new MeterComponent(levelFunc, colorFunc, displayAtFull); + } + } +} diff --git a/src/main/java/net/wovenmc/woven/api/item/settings/TemplateAPI.java b/src/main/java/net/wovenmc/woven/api/item/settings/TemplateAPI.java deleted file mode 100644 index 9606458..0000000 --- a/src/main/java/net/wovenmc/woven/api/item/settings/TemplateAPI.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2020 WovenMC - * - * 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.wovenmc.woven.api.item.settings; - -/** - * Represents a dummy class as template for API. - *

- * This should not be present in any module. - */ -public class TemplateAPI { -} diff --git a/src/main/java/net/wovenmc/woven/api/item/settings/WovenItemSettings.java b/src/main/java/net/wovenmc/woven/api/item/settings/WovenItemSettings.java new file mode 100644 index 0000000..296fc98 --- /dev/null +++ b/src/main/java/net/wovenmc/woven/api/item/settings/WovenItemSettings.java @@ -0,0 +1,87 @@ +package net.wovenmc.woven.api.item.settings; + +import java.util.IdentityHashMap; +import java.util.function.BiFunction; +import java.util.function.Function; + +import org.jetbrains.annotations.Nullable; + +import net.minecraft.item.FoodComponent; +import net.minecraft.item.Item; +import net.minecraft.item.ItemGroup; +import net.minecraft.item.ItemStack; +import net.minecraft.util.Identifier; +import net.minecraft.util.Rarity; + +public class WovenItemSettings extends Item.Settings { + private MeterComponent meterComponent; + private Function dynamicRecipeRemainder; + + public WovenItemSettings meter(MeterComponent meterComponent) { + this.meterComponent = meterComponent; + return this; + } + + public WovenItemSettings dynamicRecipeRemainder(Function remainder) { + this.dynamicRecipeRemainder = remainder; + return this; + } + + @Override + public WovenItemSettings group(ItemGroup group) { + super.group(group); + return this; + } + + @Override + public WovenItemSettings rarity(Rarity rarity) { + super.rarity(rarity); + return this; + } + + @Override + public WovenItemSettings recipeRemainder(Item recipeRemainder) { + super.recipeRemainder(recipeRemainder); + return this; + } + + @Override + public WovenItemSettings maxDamage(int maxDamage) { + super.maxDamage(maxDamage); + return this; + } + + @Override + public WovenItemSettings maxDamageIfAbsent(int maxDamage) { + super.maxDamageIfAbsent(maxDamage); + return this; + } + + @Override + public WovenItemSettings maxCount(int maxCount) { + super.maxCount(maxCount); + return this; + } + + @Override + public WovenItemSettings food(FoodComponent foodComponent) { + super.food(foodComponent); + return this; + } + + @Override + public WovenItemSettings fireproof() { + super.fireproof(); + return this; + } + + @Nullable + public MeterComponent getMeterComponent() { + return meterComponent; + } + + @Nullable + public Function getDynamicRecipeRemainder() { + return dynamicRecipeRemainder; + } +} diff --git a/src/main/java/net/wovenmc/woven/api/item/settings/WovenSettingsHolder.java b/src/main/java/net/wovenmc/woven/api/item/settings/WovenSettingsHolder.java new file mode 100644 index 0000000..d1a32b8 --- /dev/null +++ b/src/main/java/net/wovenmc/woven/api/item/settings/WovenSettingsHolder.java @@ -0,0 +1,16 @@ +package net.wovenmc.woven.api.item.settings; + +import java.util.function.Function; + +import org.jetbrains.annotations.Nullable; + +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; + +public interface WovenSettingsHolder { + @Nullable + MeterComponent getMeterComponent(); + + @Nullable + Function getDynamicRecipeRemainder(); +} diff --git a/src/main/java/net/wovenmc/woven/impl/item/settings/TemplateModInitializer.java b/src/main/java/net/wovenmc/woven/impl/item/settings/TemplateModInitializer.java deleted file mode 100644 index 98c0c32..0000000 --- a/src/main/java/net/wovenmc/woven/impl/item/settings/TemplateModInitializer.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2020 WovenMC - * - * 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.wovenmc.woven.impl.item.settings; - -import org.apache.logging.log4j.LogManager; - -import net.fabricmc.api.ModInitializer; - -public class TemplateModInitializer implements ModInitializer { - @Override - public void onInitialize() { - LogManager.getLogger("woven_module_template").info("Woven Module Template initialized."); - } -} diff --git a/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinAbstractFurnaceBlockEntity.java b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinAbstractFurnaceBlockEntity.java new file mode 100644 index 0000000..46cb2c2 --- /dev/null +++ b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinAbstractFurnaceBlockEntity.java @@ -0,0 +1,33 @@ +package net.wovenmc.woven.mixin.item.settings; + +import net.wovenmc.woven.api.item.settings.WovenSettingsHolder; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +import net.minecraft.block.entity.AbstractFurnaceBlockEntity; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; + +@Mixin(AbstractFurnaceBlockEntity.class) +public abstract class MixinAbstractFurnaceBlockEntity { + private final ThreadLocal stack = new ThreadLocal<>(); + + @Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;getRecipeRemainder()Lnet/minecraft/item/Item;"), + locals = LocalCapture.CAPTURE_FAILEXCEPTION) + private void grabLocalStack(CallbackInfo info, boolean isBurning, boolean isCooking, ItemStack cookingStack) { + stack.set(cookingStack); + } + + @Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;getRecipeRemainder()Lnet/minecraft/item/Item;")) + private Item getNewRemainder(Item origItem, Item origReturn) { + WovenSettingsHolder holder = (WovenSettingsHolder) origItem; + if (holder.getDynamicRecipeRemainder() != null) { + return holder.getDynamicRecipeRemainder().apply(stack.get()); + } + return origReturn; + } +} diff --git a/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBannerDuplicateRecipe.java b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBannerDuplicateRecipe.java new file mode 100644 index 0000000..299a3dc --- /dev/null +++ b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBannerDuplicateRecipe.java @@ -0,0 +1,36 @@ +package net.wovenmc.woven.mixin.item.settings; + +import net.wovenmc.woven.api.item.settings.WovenSettingsHolder; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +import net.minecraft.inventory.CraftingInventory; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.recipe.BannerDuplicateRecipe; +import net.minecraft.util.collection.DefaultedList; + +@Mixin(BannerDuplicateRecipe.class) +public abstract class MixinBannerDuplicateRecipe { + private final ThreadLocal slot = new ThreadLocal<>(); + + @Inject(method = "getRemainingStacks", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;getRecipeRemainder()Lnet/minecraft/item/Item;"), + locals = LocalCapture.CAPTURE_FAILEXCEPTION) + private void cacheSlot(CraftingInventory inv, CallbackInfoReturnable> info, DefaultedList ret, + int index) { + slot.set(index); + } + + @Redirect(method = "getRemainingStacks", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;getRecipeRemainder()Lnet/minecraft/item/Item;")) + private Item getNewRemainder(Item origItem, Item origReturn, CraftingInventory inv) { + WovenSettingsHolder holder = (WovenSettingsHolder) origItem; + if (holder.getDynamicRecipeRemainder() != null) { + return holder.getDynamicRecipeRemainder().apply(inv.getStack(slot.get())); + } + return origReturn; + } +} diff --git a/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBookCloningRecipe.java b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBookCloningRecipe.java new file mode 100644 index 0000000..a749bd7 --- /dev/null +++ b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBookCloningRecipe.java @@ -0,0 +1,36 @@ +package net.wovenmc.woven.mixin.item.settings; + +import net.wovenmc.woven.api.item.settings.WovenSettingsHolder; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +import net.minecraft.inventory.CraftingInventory; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.recipe.BookCloningRecipe; +import net.minecraft.util.collection.DefaultedList; + +@Mixin(BookCloningRecipe.class) +public abstract class MixinBookCloningRecipe { + private final ThreadLocal slot = new ThreadLocal<>(); + + @Inject(method = "getRemainingStacks", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;getRecipeRemainder()Lnet/minecraft/item/Item;"), + locals = LocalCapture.CAPTURE_FAILEXCEPTION) + private void cacheSlot(CraftingInventory inv, CallbackInfoReturnable> info, DefaultedList ret, + int index) { + slot.set(index); + } + + @Redirect(method = "getRemainingStacks", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;getRecipeRemainder()Lnet/minecraft/item/Item;")) + private Item getNewRemainder(Item origItem, Item origReturn, CraftingInventory inv) { + WovenSettingsHolder holder = (WovenSettingsHolder) origItem; + if (holder.getDynamicRecipeRemainder() != null) { + return holder.getDynamicRecipeRemainder().apply(inv.getStack(slot.get())); + } + return origReturn; + } +} diff --git a/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBrewingStandBlockEntity.java b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBrewingStandBlockEntity.java new file mode 100644 index 0000000..57b16df --- /dev/null +++ b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBrewingStandBlockEntity.java @@ -0,0 +1,33 @@ +package net.wovenmc.woven.mixin.item.settings; + +import net.wovenmc.woven.api.item.settings.WovenSettingsHolder; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +import net.minecraft.block.entity.BrewingStandBlockEntity; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; + +@Mixin(BrewingStandBlockEntity.class) +public abstract class MixinBrewingStandBlockEntity { + private final ThreadLocal stack = new ThreadLocal<>(); + + @Inject(method = "craft", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;getRecipeRemainder()Lnet/minecraft/item/Item;"), + locals = LocalCapture.CAPTURE_FAILEXCEPTION) + private void cacheStack(CallbackInfo info, ItemStack stack) { + this.stack.set(stack); + } + + @Redirect(method = "craft", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;getRecipeRemainder()Lnet/minecraft/item/Item;")) + private Item getNewRemainder(Item origItem, Item origReturn) { + WovenSettingsHolder holder = (WovenSettingsHolder) origItem; + if (holder.getDynamicRecipeRemainder() != null) { + return holder.getDynamicRecipeRemainder().apply(stack.get()); + } + return origReturn; + } +} diff --git a/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinItem.java b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinItem.java new file mode 100644 index 0000000..dba4860 --- /dev/null +++ b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinItem.java @@ -0,0 +1,40 @@ +package net.wovenmc.woven.mixin.item.settings; + +import java.util.function.BiFunction; +import java.util.function.Function; + +import net.wovenmc.woven.api.item.settings.WovenSettingsHolder; +import net.wovenmc.woven.api.item.settings.MeterComponent; +import net.wovenmc.woven.api.item.settings.WovenItemSettings; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; + +@Mixin(Item.class) +public abstract class MixinItem implements WovenSettingsHolder { + private MeterComponent meterComponent; + private Function dynamicRecipeRemainder; + + @Inject(method = "", at = @At("RETURN")) + private void captureInit(Item.Settings settings, CallbackInfo info) { + if (settings instanceof WovenItemSettings) { + WovenItemSettings woven = (WovenItemSettings) settings; + this.meterComponent = woven.getMeterComponent(); + this.dynamicRecipeRemainder = woven.getDynamicRecipeRemainder(); + } + } + + @Override + public MeterComponent getMeterComponent() { + return meterComponent; + } + + @Override + public Function getDynamicRecipeRemainder() { + return dynamicRecipeRemainder; + } +} diff --git a/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinRecipe.java b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinRecipe.java new file mode 100644 index 0000000..b97d486 --- /dev/null +++ b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinRecipe.java @@ -0,0 +1,38 @@ +package net.wovenmc.woven.mixin.item.settings; + +import net.wovenmc.woven.api.item.settings.WovenSettingsHolder; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +import net.minecraft.inventory.Inventory; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.recipe.Recipe; +import net.minecraft.util.collection.DefaultedList; + +@Mixin(Recipe.class) +public abstract class MixinRecipe { + private final ThreadLocal slot = new ThreadLocal<>(); + + @Inject(method = "getRemainingStacks", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;getRecipeRemainder()Lnet/minecraft/item/Item;"), + locals = LocalCapture.CAPTURE_FAILEXCEPTION) + private void cacheSlot(C inv, CallbackInfoReturnable> info, DefaultedList ret, + int index) { + slot.set(index); + } + + @Redirect(method = "getRemainingStacks", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;getRecipeRemainder()Lnet/minecraft/item/Item;")) + private Item getNewRemainder(Item origItem, Item origReturn, C inv) { + WovenSettingsHolder holder = (WovenSettingsHolder) origItem; + + if (holder.getDynamicRecipeRemainder() != null) { + return holder.getDynamicRecipeRemainder().apply(inv.getStack(slot.get())); + } + + return origReturn; + } +} diff --git a/src/main/java/net/wovenmc/woven/mixin/item/settings/client/MixinItemRenderer.java b/src/main/java/net/wovenmc/woven/mixin/item/settings/client/MixinItemRenderer.java new file mode 100644 index 0000000..e857d39 --- /dev/null +++ b/src/main/java/net/wovenmc/woven/mixin/item/settings/client/MixinItemRenderer.java @@ -0,0 +1,74 @@ +package net.wovenmc.woven.mixin.item.settings.client; + +import com.mojang.blaze3d.systems.RenderSystem; +import net.wovenmc.woven.api.item.settings.MeterComponent; +import net.wovenmc.woven.api.item.settings.WovenSettingsHolder; +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.CallbackInfo; + +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.font.TextRenderer; +import net.minecraft.client.network.ClientPlayerEntity; +import net.minecraft.client.render.BufferBuilder; +import net.minecraft.client.render.Tessellator; +import net.minecraft.client.render.item.ItemRenderer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.math.MathHelper; + +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; + +@Environment(EnvType.CLIENT) +@Mixin(ItemRenderer.class) +public abstract class MixinItemRenderer { + + @Shadow + protected abstract void renderGuiQuad(BufferBuilder buffer, int x, int y, int width, int height, int red, int green, int blue, int alpha); + + @Inject(method = "renderGuiItemOverlay(Lnet/minecraft/client/font/TextRenderer;Lnet/minecraft/item/ItemStack;IILjava/lang/String;)V", + at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;isDamaged()Z"), cancellable = true) + private void injectCustomMeter(TextRenderer textRenderer, ItemStack stack, int x, int y, String label, + CallbackInfo info) { + WovenSettingsHolder holder = (WovenSettingsHolder) stack.getItem(); + if (holder.getMeterComponent() != null) { + MeterComponent component = holder.getMeterComponent(); + float value = component.getLevel(stack); + if (value < 1 || (value == 1 && component.displayAtFull())) { + //draw the bar + RenderSystem.disableDepthTest(); + RenderSystem.disableTexture(); + RenderSystem.disableAlphaTest(); + RenderSystem.disableBlend(); + Tessellator tessellator = Tessellator.getInstance(); + BufferBuilder bufferBuilder = tessellator.getBuffer(); + int length = Math.round(13F - value * 13F); + int color = component.getColor(stack); + this.renderGuiQuad(bufferBuilder, x + 2, y + 13, 13, 2, 0, 0, 0, 255); + this.renderGuiQuad(bufferBuilder, x + 2, y + 13, length, 1, color >> 16 & 255, color >> 8 & 255, color & 255, 255); + RenderSystem.enableBlend(); + RenderSystem.enableAlphaTest(); + RenderSystem.enableTexture(); + RenderSystem.enableDepthTest(); + + //clean-up for skipped code in ItemRenderer + ClientPlayerEntity clientPlayerEntity = MinecraftClient.getInstance().player; + float cooldown = clientPlayerEntity == null ? 0.0F : clientPlayerEntity.getItemCooldownManager().getCooldownProgress(stack.getItem(), MinecraftClient.getInstance().getTickDelta()); + if (cooldown > 0.0F) { + RenderSystem.disableDepthTest(); + RenderSystem.disableTexture(); + RenderSystem.enableBlend(); + RenderSystem.defaultBlendFunc(); + Tessellator tesselator = Tessellator.getInstance(); + BufferBuilder buffer = tesselator.getBuffer(); + this.renderGuiQuad(buffer, x, y + MathHelper.floor(16.0F * (1.0F - cooldown)), 16, MathHelper.ceil(16.0F * cooldown), 255, 255, 255, 127); + RenderSystem.enableTexture(); + RenderSystem.enableDepthTest(); + } + info.cancel(); + } + } + } +} diff --git a/src/main/resources/woven-item-settings.mixins.json b/src/main/resources/woven-item-settings.mixins.json index 193b8e4..2ef16a6 100644 --- a/src/main/resources/woven-item-settings.mixins.json +++ b/src/main/resources/woven-item-settings.mixins.json @@ -3,5 +3,14 @@ "package": "net.wovenmc.woven.mixin.item.settings", "compatibilityLevel": "JAVA_8", "mixins": [ + "MixinAbstractFurnaceBlockEntity", + "MixinBannerDuplicateRecipe", + "MixinBookCloningRecipe", + "MixinBrewingStandBlockEntity", + "MixinItem", + "MixinRecipe" + ], + "client": [ + "client.MixinItemRenderer" ] } From 35554418553ac849998ef8adf82a27e77fb06257 Mon Sep 17 00:00:00 2001 From: repulica Date: Wed, 16 Sep 2020 02:22:41 -0700 Subject: [PATCH 02/11] license headers, import cleanup --- .../api/item/settings/MeterComponent.java | 19 ++++++++++++++++--- .../api/item/settings/WovenItemSettings.java | 19 ++++++++++++++++--- .../item/settings/WovenSettingsHolder.java | 16 ++++++++++++++++ .../MixinAbstractFurnaceBlockEntity.java | 16 ++++++++++++++++ .../settings/MixinBannerDuplicateRecipe.java | 16 ++++++++++++++++ .../item/settings/MixinBookCloningRecipe.java | 16 ++++++++++++++++ .../MixinBrewingStandBlockEntity.java | 16 ++++++++++++++++ .../woven/mixin/item/settings/MixinItem.java | 17 ++++++++++++++++- .../mixin/item/settings/MixinRecipe.java | 16 ++++++++++++++++ .../settings/client/MixinItemRenderer.java | 16 ++++++++++++++++ 10 files changed, 160 insertions(+), 7 deletions(-) diff --git a/src/main/java/net/wovenmc/woven/api/item/settings/MeterComponent.java b/src/main/java/net/wovenmc/woven/api/item/settings/MeterComponent.java index 45b3668..c309012 100644 --- a/src/main/java/net/wovenmc/woven/api/item/settings/MeterComponent.java +++ b/src/main/java/net/wovenmc/woven/api/item/settings/MeterComponent.java @@ -1,11 +1,24 @@ +/* + * Copyright (c) 2020 WovenMC + * + * 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.wovenmc.woven.api.item.settings; import java.util.function.BiFunction; import java.util.function.Function; -import it.unimi.dsi.fastutil.objects.Object2FloatFunction; -import org.lwjgl.system.MathUtil; - import net.minecraft.item.ItemStack; import net.minecraft.util.math.MathHelper; diff --git a/src/main/java/net/wovenmc/woven/api/item/settings/WovenItemSettings.java b/src/main/java/net/wovenmc/woven/api/item/settings/WovenItemSettings.java index 296fc98..a0119fd 100644 --- a/src/main/java/net/wovenmc/woven/api/item/settings/WovenItemSettings.java +++ b/src/main/java/net/wovenmc/woven/api/item/settings/WovenItemSettings.java @@ -1,7 +1,21 @@ +/* + * Copyright (c) 2020 WovenMC + * + * 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.wovenmc.woven.api.item.settings; -import java.util.IdentityHashMap; -import java.util.function.BiFunction; import java.util.function.Function; import org.jetbrains.annotations.Nullable; @@ -10,7 +24,6 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemStack; -import net.minecraft.util.Identifier; import net.minecraft.util.Rarity; public class WovenItemSettings extends Item.Settings { diff --git a/src/main/java/net/wovenmc/woven/api/item/settings/WovenSettingsHolder.java b/src/main/java/net/wovenmc/woven/api/item/settings/WovenSettingsHolder.java index d1a32b8..617d148 100644 --- a/src/main/java/net/wovenmc/woven/api/item/settings/WovenSettingsHolder.java +++ b/src/main/java/net/wovenmc/woven/api/item/settings/WovenSettingsHolder.java @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2020 WovenMC + * + * 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.wovenmc.woven.api.item.settings; import java.util.function.Function; diff --git a/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinAbstractFurnaceBlockEntity.java b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinAbstractFurnaceBlockEntity.java index 46cb2c2..4515abd 100644 --- a/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinAbstractFurnaceBlockEntity.java +++ b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinAbstractFurnaceBlockEntity.java @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2020 WovenMC + * + * 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.wovenmc.woven.mixin.item.settings; import net.wovenmc.woven.api.item.settings.WovenSettingsHolder; diff --git a/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBannerDuplicateRecipe.java b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBannerDuplicateRecipe.java index 299a3dc..4899385 100644 --- a/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBannerDuplicateRecipe.java +++ b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBannerDuplicateRecipe.java @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2020 WovenMC + * + * 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.wovenmc.woven.mixin.item.settings; import net.wovenmc.woven.api.item.settings.WovenSettingsHolder; diff --git a/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBookCloningRecipe.java b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBookCloningRecipe.java index a749bd7..ca23c8d 100644 --- a/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBookCloningRecipe.java +++ b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBookCloningRecipe.java @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2020 WovenMC + * + * 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.wovenmc.woven.mixin.item.settings; import net.wovenmc.woven.api.item.settings.WovenSettingsHolder; diff --git a/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBrewingStandBlockEntity.java b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBrewingStandBlockEntity.java index 57b16df..406e38b 100644 --- a/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBrewingStandBlockEntity.java +++ b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBrewingStandBlockEntity.java @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2020 WovenMC + * + * 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.wovenmc.woven.mixin.item.settings; import net.wovenmc.woven.api.item.settings.WovenSettingsHolder; diff --git a/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinItem.java b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinItem.java index dba4860..1a57f49 100644 --- a/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinItem.java +++ b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinItem.java @@ -1,6 +1,21 @@ +/* + * Copyright (c) 2020 WovenMC + * + * 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.wovenmc.woven.mixin.item.settings; -import java.util.function.BiFunction; import java.util.function.Function; import net.wovenmc.woven.api.item.settings.WovenSettingsHolder; diff --git a/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinRecipe.java b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinRecipe.java index b97d486..170e9a4 100644 --- a/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinRecipe.java +++ b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinRecipe.java @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2020 WovenMC + * + * 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.wovenmc.woven.mixin.item.settings; import net.wovenmc.woven.api.item.settings.WovenSettingsHolder; diff --git a/src/main/java/net/wovenmc/woven/mixin/item/settings/client/MixinItemRenderer.java b/src/main/java/net/wovenmc/woven/mixin/item/settings/client/MixinItemRenderer.java index e857d39..bef000f 100644 --- a/src/main/java/net/wovenmc/woven/mixin/item/settings/client/MixinItemRenderer.java +++ b/src/main/java/net/wovenmc/woven/mixin/item/settings/client/MixinItemRenderer.java @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2020 WovenMC + * + * 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.wovenmc.woven.mixin.item.settings.client; import com.mojang.blaze3d.systems.RenderSystem; From c3b1fd75b6b45eb1bbe7bafb98527b8533644889 Mon Sep 17 00:00:00 2001 From: repulica Date: Wed, 16 Sep 2020 04:53:57 -0700 Subject: [PATCH 03/11] equipment handler, javadocs, move/rename woven item settings holder --- .../api/item/settings/MeterComponent.java | 33 ++++++++++++++ .../api/item/settings/WovenItemSettings.java | 45 +++++++++++++++++-- .../settings/WovenItemSettingsHolder.java} | 13 ++++-- .../MixinAbstractFurnaceBlockEntity.java | 8 ++-- .../settings/MixinBannerDuplicateRecipe.java | 8 ++-- .../item/settings/MixinBookCloningRecipe.java | 8 ++-- .../MixinBrewingStandBlockEntity.java | 8 ++-- .../woven/mixin/item/settings/MixinItem.java | 36 ++++++++++----- .../mixin/item/settings/MixinMobEntity.java | 41 +++++++++++++++++ .../mixin/item/settings/MixinRecipe.java | 8 ++-- .../settings/client/MixinItemRenderer.java | 8 ++-- .../resources/woven-item-settings.mixins.json | 1 + 12 files changed, 176 insertions(+), 41 deletions(-) rename src/main/java/net/wovenmc/woven/{api/item/settings/WovenSettingsHolder.java => impl/item/settings/WovenItemSettingsHolder.java} (67%) create mode 100644 src/main/java/net/wovenmc/woven/mixin/item/settings/MixinMobEntity.java diff --git a/src/main/java/net/wovenmc/woven/api/item/settings/MeterComponent.java b/src/main/java/net/wovenmc/woven/api/item/settings/MeterComponent.java index c309012..7baf164 100644 --- a/src/main/java/net/wovenmc/woven/api/item/settings/MeterComponent.java +++ b/src/main/java/net/wovenmc/woven/api/item/settings/MeterComponent.java @@ -22,6 +22,9 @@ import net.minecraft.item.ItemStack; import net.minecraft.util.math.MathHelper; +/** + * A component that displays a colored meter on an item in a GUI, similar to the vanilla damage bar. + */ public class MeterComponent { private final Function levelFunc; private final BiFunction colorFunc; @@ -34,18 +37,34 @@ private MeterComponent(Function levelFunc, BiFunction levelFunc = stack -> (stack.getMaxDamage() - stack.getDamage()) / (float)stack.getMaxDamage(); @@ -53,21 +72,35 @@ public static class Builder { MathHelper.hsvToRgb(levelFunc.apply(stack) / 3F, 1F, 1F); private boolean displayAtFull = false; + /** + * @param function The function for getting the current level of a meter. + * @return The builder with the function set. + */ public Builder levelFunction(Function function) { this.levelFunc = function; return this; } + /** + * @param function The function for getting the current color of a meter. + * @return The builder with the function set. + */ public Builder colorFunction(BiFunction function) { this.colorFunc = function; return this; } + /** + * @return The builder with the flag for displaying at full set. + */ public Builder displayAtFull() { this.displayAtFull = true; return this; } + /** + * @return A built meter component. + */ public MeterComponent build() { return new MeterComponent(levelFunc, colorFunc, displayAtFull); } diff --git a/src/main/java/net/wovenmc/woven/api/item/settings/WovenItemSettings.java b/src/main/java/net/wovenmc/woven/api/item/settings/WovenItemSettings.java index a0119fd..3958bb6 100644 --- a/src/main/java/net/wovenmc/woven/api/item/settings/WovenItemSettings.java +++ b/src/main/java/net/wovenmc/woven/api/item/settings/WovenItemSettings.java @@ -20,26 +20,48 @@ import org.jetbrains.annotations.Nullable; +import net.minecraft.entity.EquipmentSlot; import net.minecraft.item.FoodComponent; import net.minecraft.item.Item; import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemStack; import net.minecraft.util.Rarity; +/** + * An extension to {@link Item.Settings} providing additional hooks for items. + */ public class WovenItemSettings extends Item.Settings { - private MeterComponent meterComponent; - private Function dynamicRecipeRemainder; - + private MeterComponent meterComponent = null; + private Function dynamicRecipeRemainder = null; + private Function equipmentHandler = null; + + /** + * @param meterComponent The {@link MeterComponent} for this item. + * @return The item settings with the component added. + */ public WovenItemSettings meter(MeterComponent meterComponent) { this.meterComponent = meterComponent; return this; } + /** + * @param remainder A function for determining the remainder of an item stack when crafting dynamically. + * @return The item settings with the function added. + */ public WovenItemSettings dynamicRecipeRemainder(Function remainder) { this.dynamicRecipeRemainder = remainder; return this; } + /** + * @param equipmentHandler A function for determining the equipment slot an item stack should go in. + * @return The item settings with the function added. + */ + public WovenItemSettings equipmentHandler(Function equipmentHandler) { + this.equipmentHandler = equipmentHandler; + return this; + } + @Override public WovenItemSettings group(ItemGroup group) { super.group(group); @@ -88,13 +110,30 @@ public WovenItemSettings fireproof() { return this; } + /** + * For internal use. + * @return The set meter component, or null if none was set. + */ @Nullable public MeterComponent getMeterComponent() { return meterComponent; } + /** + * For internal use. + * @return The set dynamic recipe remainder, or null if none was set. + */ @Nullable public Function getDynamicRecipeRemainder() { return dynamicRecipeRemainder; } + + /** + * For internal use. + * @return The set equipment handler, or null if none was set + */ + @Nullable + public Function getEquipmentHandler() { + return equipmentHandler; + } } diff --git a/src/main/java/net/wovenmc/woven/api/item/settings/WovenSettingsHolder.java b/src/main/java/net/wovenmc/woven/impl/item/settings/WovenItemSettingsHolder.java similarity index 67% rename from src/main/java/net/wovenmc/woven/api/item/settings/WovenSettingsHolder.java rename to src/main/java/net/wovenmc/woven/impl/item/settings/WovenItemSettingsHolder.java index 617d148..3f297f8 100644 --- a/src/main/java/net/wovenmc/woven/api/item/settings/WovenSettingsHolder.java +++ b/src/main/java/net/wovenmc/woven/impl/item/settings/WovenItemSettingsHolder.java @@ -14,19 +14,24 @@ * limitations under the License. */ -package net.wovenmc.woven.api.item.settings; +package net.wovenmc.woven.impl.item.settings; import java.util.function.Function; +import net.wovenmc.woven.api.item.settings.MeterComponent; import org.jetbrains.annotations.Nullable; +import net.minecraft.entity.EquipmentSlot; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -public interface WovenSettingsHolder { +public interface WovenItemSettingsHolder { @Nullable - MeterComponent getMeterComponent(); + MeterComponent woven$getMeterComponent(); @Nullable - Function getDynamicRecipeRemainder(); + Function woven$getDynamicRecipeRemainder(); + + @Nullable + Function woven$getEquipmentHandler(); } diff --git a/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinAbstractFurnaceBlockEntity.java b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinAbstractFurnaceBlockEntity.java index 4515abd..441d9d6 100644 --- a/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinAbstractFurnaceBlockEntity.java +++ b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinAbstractFurnaceBlockEntity.java @@ -16,7 +16,7 @@ package net.wovenmc.woven.mixin.item.settings; -import net.wovenmc.woven.api.item.settings.WovenSettingsHolder; +import net.wovenmc.woven.impl.item.settings.WovenItemSettingsHolder; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -40,9 +40,9 @@ private void grabLocalStack(CallbackInfo info, boolean isBurning, boolean isCook @Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;getRecipeRemainder()Lnet/minecraft/item/Item;")) private Item getNewRemainder(Item origItem, Item origReturn) { - WovenSettingsHolder holder = (WovenSettingsHolder) origItem; - if (holder.getDynamicRecipeRemainder() != null) { - return holder.getDynamicRecipeRemainder().apply(stack.get()); + WovenItemSettingsHolder holder = (WovenItemSettingsHolder) origItem; + if (holder.woven$getDynamicRecipeRemainder() != null) { + return holder.woven$getDynamicRecipeRemainder().apply(stack.get()); } return origReturn; } diff --git a/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBannerDuplicateRecipe.java b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBannerDuplicateRecipe.java index 4899385..da252b7 100644 --- a/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBannerDuplicateRecipe.java +++ b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBannerDuplicateRecipe.java @@ -16,7 +16,7 @@ package net.wovenmc.woven.mixin.item.settings; -import net.wovenmc.woven.api.item.settings.WovenSettingsHolder; +import net.wovenmc.woven.impl.item.settings.WovenItemSettingsHolder; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -43,9 +43,9 @@ private void cacheSlot(CraftingInventory inv, CallbackInfoReturnable dynamicRecipeRemainder; +public abstract class MixinItem implements WovenItemSettingsHolder { + @Unique + private MeterComponent woven$meterComponent; + @Unique + private Function woven$dynamicRecipeRemainder; + @Unique + private Function woven$equipmentHandler; @Inject(method = "", at = @At("RETURN")) private void captureInit(Item.Settings settings, CallbackInfo info) { if (settings instanceof WovenItemSettings) { WovenItemSettings woven = (WovenItemSettings) settings; - this.meterComponent = woven.getMeterComponent(); - this.dynamicRecipeRemainder = woven.getDynamicRecipeRemainder(); + this.woven$meterComponent = woven.getMeterComponent(); + this.woven$dynamicRecipeRemainder = woven.getDynamicRecipeRemainder(); + this.woven$equipmentHandler = woven.getEquipmentHandler(); } } + @Nullable @Override - public MeterComponent getMeterComponent() { - return meterComponent; + public MeterComponent woven$getMeterComponent() { + return woven$meterComponent; } + @Nullable @Override - public Function getDynamicRecipeRemainder() { - return dynamicRecipeRemainder; + public Function woven$getDynamicRecipeRemainder() { + return woven$dynamicRecipeRemainder; + } + + @Nullable + @Override + public Function woven$getEquipmentHandler() { + return woven$equipmentHandler; } } diff --git a/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinMobEntity.java b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinMobEntity.java new file mode 100644 index 0000000..8390495 --- /dev/null +++ b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinMobEntity.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2020 WovenMC + * + * 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.wovenmc.woven.mixin.item.settings; + +import net.wovenmc.woven.impl.item.settings.WovenItemSettingsHolder; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +import net.minecraft.entity.EquipmentSlot; +import net.minecraft.entity.mob.MobEntity; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; + +@Mixin(MobEntity.class) +public abstract class MixinMobEntity { + @Inject(method = "getPreferredEquipmentSlot", at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/item/ItemStack;getItem()Lnet/minecraft/item/Item;"), cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD) + private static void onGetPreferredEquipmentSlot(ItemStack stack, CallbackInfoReturnable info, Item item) { + WovenItemSettingsHolder holder = ((WovenItemSettingsHolder) item); + + if (holder.woven$getEquipmentHandler() != null) { + info.setReturnValue(holder.woven$getEquipmentHandler().apply(stack)); + } + } +} diff --git a/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinRecipe.java b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinRecipe.java index 170e9a4..0f495b0 100644 --- a/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinRecipe.java +++ b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinRecipe.java @@ -16,7 +16,7 @@ package net.wovenmc.woven.mixin.item.settings; -import net.wovenmc.woven.api.item.settings.WovenSettingsHolder; +import net.wovenmc.woven.impl.item.settings.WovenItemSettingsHolder; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -43,10 +43,10 @@ private void cacheSlot(C inv, CallbackInfoReturnable> i @Redirect(method = "getRemainingStacks", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;getRecipeRemainder()Lnet/minecraft/item/Item;")) private Item getNewRemainder(Item origItem, Item origReturn, C inv) { - WovenSettingsHolder holder = (WovenSettingsHolder) origItem; + WovenItemSettingsHolder holder = (WovenItemSettingsHolder) origItem; - if (holder.getDynamicRecipeRemainder() != null) { - return holder.getDynamicRecipeRemainder().apply(inv.getStack(slot.get())); + if (holder.woven$getDynamicRecipeRemainder() != null) { + return holder.woven$getDynamicRecipeRemainder().apply(inv.getStack(slot.get())); } return origReturn; diff --git a/src/main/java/net/wovenmc/woven/mixin/item/settings/client/MixinItemRenderer.java b/src/main/java/net/wovenmc/woven/mixin/item/settings/client/MixinItemRenderer.java index bef000f..c81dcf6 100644 --- a/src/main/java/net/wovenmc/woven/mixin/item/settings/client/MixinItemRenderer.java +++ b/src/main/java/net/wovenmc/woven/mixin/item/settings/client/MixinItemRenderer.java @@ -18,7 +18,7 @@ import com.mojang.blaze3d.systems.RenderSystem; import net.wovenmc.woven.api.item.settings.MeterComponent; -import net.wovenmc.woven.api.item.settings.WovenSettingsHolder; +import net.wovenmc.woven.impl.item.settings.WovenItemSettingsHolder; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -48,9 +48,9 @@ public abstract class MixinItemRenderer { at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;isDamaged()Z"), cancellable = true) private void injectCustomMeter(TextRenderer textRenderer, ItemStack stack, int x, int y, String label, CallbackInfo info) { - WovenSettingsHolder holder = (WovenSettingsHolder) stack.getItem(); - if (holder.getMeterComponent() != null) { - MeterComponent component = holder.getMeterComponent(); + WovenItemSettingsHolder holder = (WovenItemSettingsHolder) stack.getItem(); + if (holder.woven$getMeterComponent() != null) { + MeterComponent component = holder.woven$getMeterComponent(); float value = component.getLevel(stack); if (value < 1 || (value == 1 && component.displayAtFull())) { //draw the bar diff --git a/src/main/resources/woven-item-settings.mixins.json b/src/main/resources/woven-item-settings.mixins.json index 2ef16a6..b6c2692 100644 --- a/src/main/resources/woven-item-settings.mixins.json +++ b/src/main/resources/woven-item-settings.mixins.json @@ -8,6 +8,7 @@ "MixinBookCloningRecipe", "MixinBrewingStandBlockEntity", "MixinItem", + "MixinMobEntity", "MixinRecipe" ], "client": [ From 294e15831b129e5a068baf28e55338ba297f8ffb Mon Sep 17 00:00:00 2001 From: repulica Date: Wed, 16 Sep 2020 04:57:57 -0700 Subject: [PATCH 04/11] checkstyle fixes --- .../wovenmc/woven/api/item/settings/MeterComponent.java | 4 ++-- .../item/settings/MixinAbstractFurnaceBlockEntity.java | 2 ++ .../mixin/item/settings/MixinBannerDuplicateRecipe.java | 4 +++- .../woven/mixin/item/settings/MixinBookCloningRecipe.java | 4 +++- .../mixin/item/settings/MixinBrewingStandBlockEntity.java | 4 +++- .../mixin/item/settings/client/MixinItemRenderer.java | 7 +++++-- 6 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/main/java/net/wovenmc/woven/api/item/settings/MeterComponent.java b/src/main/java/net/wovenmc/woven/api/item/settings/MeterComponent.java index 7baf164..f303716 100644 --- a/src/main/java/net/wovenmc/woven/api/item/settings/MeterComponent.java +++ b/src/main/java/net/wovenmc/woven/api/item/settings/MeterComponent.java @@ -31,7 +31,7 @@ public class MeterComponent { private final boolean displayAtFull; private MeterComponent(Function levelFunc, BiFunction colorFunc, - boolean displayAtFull) { + boolean displayAtFull) { this.levelFunc = levelFunc; this.colorFunc = colorFunc; this.displayAtFull = displayAtFull; @@ -67,7 +67,7 @@ public boolean displayAtFull() { */ public static class Builder { private Function levelFunc = stack -> - (stack.getMaxDamage() - stack.getDamage()) / (float)stack.getMaxDamage(); + (stack.getMaxDamage() - stack.getDamage()) / (float) stack.getMaxDamage(); private BiFunction colorFunc = (stack, level) -> MathHelper.hsvToRgb(levelFunc.apply(stack) / 3F, 1F, 1F); private boolean displayAtFull = false; diff --git a/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinAbstractFurnaceBlockEntity.java b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinAbstractFurnaceBlockEntity.java index 441d9d6..c50e265 100644 --- a/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinAbstractFurnaceBlockEntity.java +++ b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinAbstractFurnaceBlockEntity.java @@ -41,9 +41,11 @@ private void grabLocalStack(CallbackInfo info, boolean isBurning, boolean isCook @Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;getRecipeRemainder()Lnet/minecraft/item/Item;")) private Item getNewRemainder(Item origItem, Item origReturn) { WovenItemSettingsHolder holder = (WovenItemSettingsHolder) origItem; + if (holder.woven$getDynamicRecipeRemainder() != null) { return holder.woven$getDynamicRecipeRemainder().apply(stack.get()); } + return origReturn; } } diff --git a/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBannerDuplicateRecipe.java b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBannerDuplicateRecipe.java index da252b7..b84aeeb 100644 --- a/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBannerDuplicateRecipe.java +++ b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBannerDuplicateRecipe.java @@ -37,16 +37,18 @@ public abstract class MixinBannerDuplicateRecipe { @Inject(method = "getRemainingStacks", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;getRecipeRemainder()Lnet/minecraft/item/Item;"), locals = LocalCapture.CAPTURE_FAILEXCEPTION) private void cacheSlot(CraftingInventory inv, CallbackInfoReturnable> info, DefaultedList ret, - int index) { + int index) { slot.set(index); } @Redirect(method = "getRemainingStacks", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;getRecipeRemainder()Lnet/minecraft/item/Item;")) private Item getNewRemainder(Item origItem, Item origReturn, CraftingInventory inv) { WovenItemSettingsHolder holder = (WovenItemSettingsHolder) origItem; + if (holder.woven$getDynamicRecipeRemainder() != null) { return holder.woven$getDynamicRecipeRemainder().apply(inv.getStack(slot.get())); } + return origReturn; } } diff --git a/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBookCloningRecipe.java b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBookCloningRecipe.java index ff2bf1d..0915a55 100644 --- a/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBookCloningRecipe.java +++ b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBookCloningRecipe.java @@ -37,16 +37,18 @@ public abstract class MixinBookCloningRecipe { @Inject(method = "getRemainingStacks", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;getRecipeRemainder()Lnet/minecraft/item/Item;"), locals = LocalCapture.CAPTURE_FAILEXCEPTION) private void cacheSlot(CraftingInventory inv, CallbackInfoReturnable> info, DefaultedList ret, - int index) { + int index) { slot.set(index); } @Redirect(method = "getRemainingStacks", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;getRecipeRemainder()Lnet/minecraft/item/Item;")) private Item getNewRemainder(Item origItem, Item origReturn, CraftingInventory inv) { WovenItemSettingsHolder holder = (WovenItemSettingsHolder) origItem; + if (holder.woven$getDynamicRecipeRemainder() != null) { return holder.woven$getDynamicRecipeRemainder().apply(inv.getStack(slot.get())); } + return origReturn; } } diff --git a/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBrewingStandBlockEntity.java b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBrewingStandBlockEntity.java index 4ff1ad2..8fa511a 100644 --- a/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBrewingStandBlockEntity.java +++ b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBrewingStandBlockEntity.java @@ -33,7 +33,7 @@ public abstract class MixinBrewingStandBlockEntity { private final ThreadLocal stack = new ThreadLocal<>(); @Inject(method = "craft", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;getRecipeRemainder()Lnet/minecraft/item/Item;"), - locals = LocalCapture.CAPTURE_FAILEXCEPTION) + locals = LocalCapture.CAPTURE_FAILEXCEPTION) private void cacheStack(CallbackInfo info, ItemStack stack) { this.stack.set(stack); } @@ -41,9 +41,11 @@ private void cacheStack(CallbackInfo info, ItemStack stack) { @Redirect(method = "craft", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;getRecipeRemainder()Lnet/minecraft/item/Item;")) private Item getNewRemainder(Item origItem, Item origReturn) { WovenItemSettingsHolder holder = (WovenItemSettingsHolder) origItem; + if (holder.woven$getDynamicRecipeRemainder() != null) { return holder.woven$getDynamicRecipeRemainder().apply(stack.get()); } + return origReturn; } } diff --git a/src/main/java/net/wovenmc/woven/mixin/item/settings/client/MixinItemRenderer.java b/src/main/java/net/wovenmc/woven/mixin/item/settings/client/MixinItemRenderer.java index c81dcf6..570d71b 100644 --- a/src/main/java/net/wovenmc/woven/mixin/item/settings/client/MixinItemRenderer.java +++ b/src/main/java/net/wovenmc/woven/mixin/item/settings/client/MixinItemRenderer.java @@ -40,18 +40,19 @@ @Environment(EnvType.CLIENT) @Mixin(ItemRenderer.class) public abstract class MixinItemRenderer { - @Shadow protected abstract void renderGuiQuad(BufferBuilder buffer, int x, int y, int width, int height, int red, int green, int blue, int alpha); @Inject(method = "renderGuiItemOverlay(Lnet/minecraft/client/font/TextRenderer;Lnet/minecraft/item/ItemStack;IILjava/lang/String;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;isDamaged()Z"), cancellable = true) private void injectCustomMeter(TextRenderer textRenderer, ItemStack stack, int x, int y, String label, - CallbackInfo info) { + CallbackInfo info) { WovenItemSettingsHolder holder = (WovenItemSettingsHolder) stack.getItem(); + if (holder.woven$getMeterComponent() != null) { MeterComponent component = holder.woven$getMeterComponent(); float value = component.getLevel(stack); + if (value < 1 || (value == 1 && component.displayAtFull())) { //draw the bar RenderSystem.disableDepthTest(); @@ -72,6 +73,7 @@ private void injectCustomMeter(TextRenderer textRenderer, ItemStack stack, int x //clean-up for skipped code in ItemRenderer ClientPlayerEntity clientPlayerEntity = MinecraftClient.getInstance().player; float cooldown = clientPlayerEntity == null ? 0.0F : clientPlayerEntity.getItemCooldownManager().getCooldownProgress(stack.getItem(), MinecraftClient.getInstance().getTickDelta()); + if (cooldown > 0.0F) { RenderSystem.disableDepthTest(); RenderSystem.disableTexture(); @@ -83,6 +85,7 @@ private void injectCustomMeter(TextRenderer textRenderer, ItemStack stack, int x RenderSystem.enableTexture(); RenderSystem.enableDepthTest(); } + info.cancel(); } } From bf7997d02c60b73115b9660af6b6623b9167a11a Mon Sep 17 00:00:00 2001 From: repulica Date: Wed, 16 Sep 2020 23:42:57 -0700 Subject: [PATCH 05/11] fix various bugs with settings --- .../api/item/settings/WovenItemSettings.java | 8 ++- .../settings/WovenItemSettingsHolder.java | 5 +- .../MixinAbstractFurnaceBlockEntity.java | 44 +++++++++++-- .../settings/MixinBannerDuplicateRecipe.java | 17 +++-- .../item/settings/MixinBookCloningRecipe.java | 17 +++-- .../MixinBrewingStandBlockEntity.java | 11 ++-- .../woven/mixin/item/settings/MixinItem.java | 6 +- .../mixin/item/settings/MixinRecipe.java | 63 +++++++++++++------ .../settings/client/MixinItemRenderer.java | 2 +- src/main/resources/fabric.mod.json | 6 +- 10 files changed, 131 insertions(+), 48 deletions(-) diff --git a/src/main/java/net/wovenmc/woven/api/item/settings/WovenItemSettings.java b/src/main/java/net/wovenmc/woven/api/item/settings/WovenItemSettings.java index 3958bb6..891c01b 100644 --- a/src/main/java/net/wovenmc/woven/api/item/settings/WovenItemSettings.java +++ b/src/main/java/net/wovenmc/woven/api/item/settings/WovenItemSettings.java @@ -16,6 +16,7 @@ package net.wovenmc.woven.api.item.settings; +import java.util.function.BiFunction; import java.util.function.Function; import org.jetbrains.annotations.Nullable; @@ -25,6 +26,7 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemStack; +import net.minecraft.util.Identifier; import net.minecraft.util.Rarity; /** @@ -32,7 +34,7 @@ */ public class WovenItemSettings extends Item.Settings { private MeterComponent meterComponent = null; - private Function dynamicRecipeRemainder = null; + private BiFunction dynamicRecipeRemainder = null; private Function equipmentHandler = null; /** @@ -48,7 +50,7 @@ public WovenItemSettings meter(MeterComponent meterComponent) { * @param remainder A function for determining the remainder of an item stack when crafting dynamically. * @return The item settings with the function added. */ - public WovenItemSettings dynamicRecipeRemainder(Function remainder) { + public WovenItemSettings dynamicRecipeRemainder(BiFunction remainder) { this.dynamicRecipeRemainder = remainder; return this; } @@ -124,7 +126,7 @@ public MeterComponent getMeterComponent() { * @return The set dynamic recipe remainder, or null if none was set. */ @Nullable - public Function getDynamicRecipeRemainder() { + public BiFunction getDynamicRecipeRemainder() { return dynamicRecipeRemainder; } diff --git a/src/main/java/net/wovenmc/woven/impl/item/settings/WovenItemSettingsHolder.java b/src/main/java/net/wovenmc/woven/impl/item/settings/WovenItemSettingsHolder.java index 3f297f8..a833158 100644 --- a/src/main/java/net/wovenmc/woven/impl/item/settings/WovenItemSettingsHolder.java +++ b/src/main/java/net/wovenmc/woven/impl/item/settings/WovenItemSettingsHolder.java @@ -16,21 +16,22 @@ package net.wovenmc.woven.impl.item.settings; +import java.util.function.BiFunction; import java.util.function.Function; import net.wovenmc.woven.api.item.settings.MeterComponent; import org.jetbrains.annotations.Nullable; import net.minecraft.entity.EquipmentSlot; -import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.util.Identifier; public interface WovenItemSettingsHolder { @Nullable MeterComponent woven$getMeterComponent(); @Nullable - Function woven$getDynamicRecipeRemainder(); + BiFunction woven$getDynamicRecipeRemainder(); @Nullable Function woven$getEquipmentHandler(); diff --git a/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinAbstractFurnaceBlockEntity.java b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinAbstractFurnaceBlockEntity.java index c50e265..f23c690 100644 --- a/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinAbstractFurnaceBlockEntity.java +++ b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinAbstractFurnaceBlockEntity.java @@ -16,8 +16,10 @@ package net.wovenmc.woven.mixin.item.settings; +import net.wovenmc.woven.api.item.settings.WovenItemSettings; import net.wovenmc.woven.impl.item.settings.WovenItemSettingsHolder; 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.Redirect; @@ -26,26 +28,60 @@ import net.minecraft.block.entity.AbstractFurnaceBlockEntity; import net.minecraft.item.Item; +import net.minecraft.item.ItemConvertible; import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; +import net.minecraft.recipe.Recipe; +import net.minecraft.util.Identifier; +import net.minecraft.util.collection.DefaultedList; +import net.minecraft.util.registry.Registry; @Mixin(AbstractFurnaceBlockEntity.class) public abstract class MixinAbstractFurnaceBlockEntity { + @Shadow + protected DefaultedList inventory; + private static final Identifier FUEL_ID = new Identifier("furnace_fuel"); private final ThreadLocal stack = new ThreadLocal<>(); @Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;getRecipeRemainder()Lnet/minecraft/item/Item;"), locals = LocalCapture.CAPTURE_FAILEXCEPTION) - private void grabLocalStack(CallbackInfo info, boolean isBurning, boolean isCooking, ItemStack cookingStack) { + private void grabLocalStack(CallbackInfo info, boolean isBurning, boolean isCooking, ItemStack cookingStack, Recipe recipe) { stack.set(cookingStack); } @Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;getRecipeRemainder()Lnet/minecraft/item/Item;")) - private Item getNewRemainder(Item origItem, Item origReturn) { + private Item hackCustomFuelRemainder(Item origItem) { WovenItemSettingsHolder holder = (WovenItemSettingsHolder) origItem; + System.out.println(Registry.ITEM.getId(origItem)); if (holder.woven$getDynamicRecipeRemainder() != null) { - return holder.woven$getDynamicRecipeRemainder().apply(stack.get()); + return Items.COAL; } - return origReturn; + return origItem.getRecipeRemainder(); + } + + @Redirect(method = "tick", at = @At(value = "NEW", target = "net/minecraft/item/ItemStack")) + private ItemStack getNewFuelRemainder(ItemConvertible origItem) { + WovenItemSettingsHolder holder = (WovenItemSettingsHolder) origItem; + + if (holder.woven$getDynamicRecipeRemainder() != null) { + return holder.woven$getDynamicRecipeRemainder().apply(stack.get(), FUEL_ID); + } + + return new ItemStack(origItem); + } + + @Inject(method = "craftRecipe", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;decrement(I)V"), + cancellable = true, locals = LocalCapture.CAPTURE_FAILEXCEPTION) + private void injectSmeltRemainder(Recipe recipe, CallbackInfo info, ItemStack inStack) { + WovenItemSettingsHolder woven = (WovenItemSettingsHolder) inStack.getItem(); + if (woven.woven$getDynamicRecipeRemainder() != null) { + ItemStack newStack = woven.woven$getDynamicRecipeRemainder().apply(inStack, recipe.getId()); + if (!newStack.isEmpty()) { + this.inventory.set(0, newStack); + info.cancel(); + } + } } } diff --git a/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBannerDuplicateRecipe.java b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBannerDuplicateRecipe.java index b84aeeb..f5dc577 100644 --- a/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBannerDuplicateRecipe.java +++ b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBannerDuplicateRecipe.java @@ -26,14 +26,21 @@ import net.minecraft.inventory.CraftingInventory; import net.minecraft.item.Item; +import net.minecraft.item.ItemConvertible; import net.minecraft.item.ItemStack; import net.minecraft.recipe.BannerDuplicateRecipe; +import net.minecraft.recipe.SpecialCraftingRecipe; +import net.minecraft.util.Identifier; import net.minecraft.util.collection.DefaultedList; @Mixin(BannerDuplicateRecipe.class) -public abstract class MixinBannerDuplicateRecipe { +public abstract class MixinBannerDuplicateRecipe extends SpecialCraftingRecipe { private final ThreadLocal slot = new ThreadLocal<>(); + public MixinBannerDuplicateRecipe(Identifier id) { + super(id); + } + @Inject(method = "getRemainingStacks", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;getRecipeRemainder()Lnet/minecraft/item/Item;"), locals = LocalCapture.CAPTURE_FAILEXCEPTION) private void cacheSlot(CraftingInventory inv, CallbackInfoReturnable> info, DefaultedList ret, @@ -41,14 +48,14 @@ private void cacheSlot(CraftingInventory inv, CallbackInfoReturnable slot = new ThreadLocal<>(); + public MixinBookCloningRecipe(Identifier id) { + super(id); + } + @Inject(method = "getRemainingStacks", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;getRecipeRemainder()Lnet/minecraft/item/Item;"), locals = LocalCapture.CAPTURE_FAILEXCEPTION) private void cacheSlot(CraftingInventory inv, CallbackInfoReturnable> info, DefaultedList ret, @@ -41,14 +48,14 @@ private void cacheSlot(CraftingInventory inv, CallbackInfoReturnable stack = new ThreadLocal<>(); @Inject(method = "craft", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;getRecipeRemainder()Lnet/minecraft/item/Item;"), @@ -38,14 +41,14 @@ private void cacheStack(CallbackInfo info, ItemStack stack) { this.stack.set(stack); } - @Redirect(method = "craft", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;getRecipeRemainder()Lnet/minecraft/item/Item;")) - private Item getNewRemainder(Item origItem, Item origReturn) { + @Redirect(method = "craft", at = @At(value = "NEW", target = "net/minecraft/item/ItemStack")) + private ItemStack getNewRemainder(ItemConvertible origItem) { WovenItemSettingsHolder holder = (WovenItemSettingsHolder) origItem; if (holder.woven$getDynamicRecipeRemainder() != null) { - return holder.woven$getDynamicRecipeRemainder().apply(stack.get()); + return holder.woven$getDynamicRecipeRemainder().apply(stack.get(), BREWING_ID); } - return origReturn; + return new ItemStack(origItem); } } diff --git a/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinItem.java b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinItem.java index d639227..a78d36f 100644 --- a/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinItem.java +++ b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinItem.java @@ -16,6 +16,7 @@ package net.wovenmc.woven.mixin.item.settings; +import java.util.function.BiFunction; import java.util.function.Function; import net.wovenmc.woven.impl.item.settings.WovenItemSettingsHolder; @@ -31,13 +32,14 @@ import net.minecraft.entity.EquipmentSlot; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.util.Identifier; @Mixin(Item.class) public abstract class MixinItem implements WovenItemSettingsHolder { @Unique private MeterComponent woven$meterComponent; @Unique - private Function woven$dynamicRecipeRemainder; + private BiFunction woven$dynamicRecipeRemainder; @Unique private Function woven$equipmentHandler; @@ -59,7 +61,7 @@ private void captureInit(Item.Settings settings, CallbackInfo info) { @Nullable @Override - public Function woven$getDynamicRecipeRemainder() { + public BiFunction woven$getDynamicRecipeRemainder() { return woven$dynamicRecipeRemainder; } diff --git a/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinRecipe.java b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinRecipe.java index 0f495b0..79426b6 100644 --- a/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinRecipe.java +++ b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinRecipe.java @@ -18,37 +18,60 @@ import net.wovenmc.woven.impl.item.settings.WovenItemSettingsHolder; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.Redirect; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; import net.minecraft.inventory.Inventory; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.recipe.Recipe; +import net.minecraft.util.Identifier; import net.minecraft.util.collection.DefaultedList; @Mixin(Recipe.class) -public abstract class MixinRecipe { - private final ThreadLocal slot = new ThreadLocal<>(); - - @Inject(method = "getRemainingStacks", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;getRecipeRemainder()Lnet/minecraft/item/Item;"), - locals = LocalCapture.CAPTURE_FAILEXCEPTION) - private void cacheSlot(C inv, CallbackInfoReturnable> info, DefaultedList ret, - int index) { - slot.set(index); - } +public interface MixinRecipe { + @Shadow + Identifier getId(); - @Redirect(method = "getRemainingStacks", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;getRecipeRemainder()Lnet/minecraft/item/Item;")) - private Item getNewRemainder(Item origItem, Item origReturn, C inv) { - WovenItemSettingsHolder holder = (WovenItemSettingsHolder) origItem; + /** + * @author repulica + * @reason injections into interfaces dont work rn + * TODO: remove once default interface method injection works + */ + @Overwrite + default DefaultedList getRemainingStacks(C inventory) { + DefaultedList defaultedList = DefaultedList.ofSize(inventory.size(), ItemStack.EMPTY); - if (holder.woven$getDynamicRecipeRemainder() != null) { - return holder.woven$getDynamicRecipeRemainder().apply(inv.getStack(slot.get())); + for(int i = 0; i < defaultedList.size(); ++i) { + Item item = inventory.getStack(i).getItem(); + WovenItemSettingsHolder woven = (WovenItemSettingsHolder) item; + if (woven.woven$getDynamicRecipeRemainder() != null) { + defaultedList.set(i, woven.woven$getDynamicRecipeRemainder().apply(inventory.getStack(i), getId())); + } else if (item.hasRecipeRemainder()) { + defaultedList.set(i, new ItemStack(item.getRecipeRemainder())); + } } - return origReturn; + return defaultedList; } + +// @Inject(method = "getRemainingStacks", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;getRecipeRemainder()Lnet/minecraft/item/Item;"), +// locals = LocalCapture.CAPTURE_FAILEXCEPTION) +// default void cacheSlot(C inv, CallbackInfoReturnable info, DefaultedList ret, +// int index) { +// GrossThreadLocalHack.THREADLOCALS.computeIfAbsent((Recipe)this, x -> new ThreadLocal<>()).set(index); +// } +// +// @Redirect(method = "getRemainingStacks", at = @At(value = "NEW", target = "net/minecraft/item/ItemStack")) +// default ItemStack getNewRemainder(ItemConvertible origItem, C inv) { +// WovenItemSettingsHolder holder = (WovenItemSettingsHolder) origItem; +// +// if (holder.woven$getDynamicRecipeRemainder() != null) { +// return holder.woven$getDynamicRecipeRemainder().apply(inv.getStack( +// GrossThreadLocalHack.THREADLOCALS.computeIfAbsent( +// (Recipe)this, x -> new ThreadLocal<>()).get()), this.getId()); +// } +// +// return new ItemStack(origItem); +// } } diff --git a/src/main/java/net/wovenmc/woven/mixin/item/settings/client/MixinItemRenderer.java b/src/main/java/net/wovenmc/woven/mixin/item/settings/client/MixinItemRenderer.java index 570d71b..ddf0b28 100644 --- a/src/main/java/net/wovenmc/woven/mixin/item/settings/client/MixinItemRenderer.java +++ b/src/main/java/net/wovenmc/woven/mixin/item/settings/client/MixinItemRenderer.java @@ -61,7 +61,7 @@ private void injectCustomMeter(TextRenderer textRenderer, ItemStack stack, int x RenderSystem.disableBlend(); Tessellator tessellator = Tessellator.getInstance(); BufferBuilder bufferBuilder = tessellator.getBuffer(); - int length = Math.round(13F - value * 13F); + int length = Math.round(value * 13F); int color = component.getColor(stack); this.renderGuiQuad(bufferBuilder, x + 2, y + 13, 13, 2, 0, 0, 0, 255); this.renderGuiQuad(bufferBuilder, x + 2, y + 13, length, 1, color >> 16 & 255, color >> 8 & 255, color & 255, 255); diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 8894ca8..1ff31a7 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -1,7 +1,7 @@ { "schemaVersion": 1, - "id": "${namespace}", - "name": "Woven Module Template", + "id": "woven_item_settings", + "name": "Woven Item Settings", "version": "${version}", "description": "${description}", "license": "Apache-2.0", @@ -16,6 +16,8 @@ "icon": "assets/woven/icon.png", "environment": "*", "entrypoints": { + "main": [ + ] }, "mixins": [ "woven-item-settings.mixins.json" From 18af3b63633f6691119c1b75e56d1ee397920bda Mon Sep 17 00:00:00 2001 From: repulica Date: Wed, 16 Sep 2020 23:45:19 -0700 Subject: [PATCH 06/11] checkstyle fixes --- .../MixinAbstractFurnaceBlockEntity.java | 3 +- .../settings/MixinBannerDuplicateRecipe.java | 1 - .../item/settings/MixinBookCloningRecipe.java | 1 - .../MixinBrewingStandBlockEntity.java | 1 - .../mixin/item/settings/MixinRecipe.java | 42 ++++++++++--------- 5 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinAbstractFurnaceBlockEntity.java b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinAbstractFurnaceBlockEntity.java index f23c690..e340b27 100644 --- a/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinAbstractFurnaceBlockEntity.java +++ b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinAbstractFurnaceBlockEntity.java @@ -16,7 +16,6 @@ package net.wovenmc.woven.mixin.item.settings; -import net.wovenmc.woven.api.item.settings.WovenItemSettings; import net.wovenmc.woven.impl.item.settings.WovenItemSettingsHolder; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -76,8 +75,10 @@ private ItemStack getNewFuelRemainder(ItemConvertible origItem) { cancellable = true, locals = LocalCapture.CAPTURE_FAILEXCEPTION) private void injectSmeltRemainder(Recipe recipe, CallbackInfo info, ItemStack inStack) { WovenItemSettingsHolder woven = (WovenItemSettingsHolder) inStack.getItem(); + if (woven.woven$getDynamicRecipeRemainder() != null) { ItemStack newStack = woven.woven$getDynamicRecipeRemainder().apply(inStack, recipe.getId()); + if (!newStack.isEmpty()) { this.inventory.set(0, newStack); info.cancel(); diff --git a/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBannerDuplicateRecipe.java b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBannerDuplicateRecipe.java index f5dc577..bfcd4cb 100644 --- a/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBannerDuplicateRecipe.java +++ b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBannerDuplicateRecipe.java @@ -25,7 +25,6 @@ import org.spongepowered.asm.mixin.injection.callback.LocalCapture; import net.minecraft.inventory.CraftingInventory; -import net.minecraft.item.Item; import net.minecraft.item.ItemConvertible; import net.minecraft.item.ItemStack; import net.minecraft.recipe.BannerDuplicateRecipe; diff --git a/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBookCloningRecipe.java b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBookCloningRecipe.java index d98edcb..c667ff0 100644 --- a/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBookCloningRecipe.java +++ b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBookCloningRecipe.java @@ -25,7 +25,6 @@ import org.spongepowered.asm.mixin.injection.callback.LocalCapture; import net.minecraft.inventory.CraftingInventory; -import net.minecraft.item.Item; import net.minecraft.item.ItemConvertible; import net.minecraft.item.ItemStack; import net.minecraft.recipe.BookCloningRecipe; diff --git a/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBrewingStandBlockEntity.java b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBrewingStandBlockEntity.java index a6e9179..a542429 100644 --- a/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBrewingStandBlockEntity.java +++ b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBrewingStandBlockEntity.java @@ -25,7 +25,6 @@ import org.spongepowered.asm.mixin.injection.callback.LocalCapture; import net.minecraft.block.entity.BrewingStandBlockEntity; -import net.minecraft.item.Item; import net.minecraft.item.ItemConvertible; import net.minecraft.item.ItemStack; import net.minecraft.util.Identifier; diff --git a/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinRecipe.java b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinRecipe.java index 79426b6..5d0653e 100644 --- a/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinRecipe.java +++ b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinRecipe.java @@ -42,9 +42,10 @@ public interface MixinRecipe { default DefaultedList getRemainingStacks(C inventory) { DefaultedList defaultedList = DefaultedList.ofSize(inventory.size(), ItemStack.EMPTY); - for(int i = 0; i < defaultedList.size(); ++i) { + for (int i = 0; i < defaultedList.size(); ++i) { Item item = inventory.getStack(i).getItem(); WovenItemSettingsHolder woven = (WovenItemSettingsHolder) item; + if (woven.woven$getDynamicRecipeRemainder() != null) { defaultedList.set(i, woven.woven$getDynamicRecipeRemainder().apply(inventory.getStack(i), getId())); } else if (item.hasRecipeRemainder()) { @@ -55,23 +56,24 @@ default DefaultedList getRemainingStacks(C inventory) { return defaultedList; } -// @Inject(method = "getRemainingStacks", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;getRecipeRemainder()Lnet/minecraft/item/Item;"), -// locals = LocalCapture.CAPTURE_FAILEXCEPTION) -// default void cacheSlot(C inv, CallbackInfoReturnable info, DefaultedList ret, -// int index) { -// GrossThreadLocalHack.THREADLOCALS.computeIfAbsent((Recipe)this, x -> new ThreadLocal<>()).set(index); -// } -// -// @Redirect(method = "getRemainingStacks", at = @At(value = "NEW", target = "net/minecraft/item/ItemStack")) -// default ItemStack getNewRemainder(ItemConvertible origItem, C inv) { -// WovenItemSettingsHolder holder = (WovenItemSettingsHolder) origItem; -// -// if (holder.woven$getDynamicRecipeRemainder() != null) { -// return holder.woven$getDynamicRecipeRemainder().apply(inv.getStack( -// GrossThreadLocalHack.THREADLOCALS.computeIfAbsent( -// (Recipe)this, x -> new ThreadLocal<>()).get()), this.getId()); -// } -// -// return new ItemStack(origItem); -// } + /* + @Inject(method = "getRemainingStacks", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;getRecipeRemainder()Lnet/minecraft/item/Item;"), + locals = LocalCapture.CAPTURE_FAILEXCEPTION) + default void cacheSlot(C inv, CallbackInfoReturnable info, DefaultedList ret, + int index) { + GrossThreadLocalHack.THREADLOCALS.computeIfAbsent((Recipe)this, x -> new ThreadLocal<>()).set(index); + } + + @Redirect(method = "getRemainingStacks", at = @At(value = "NEW", target = "net/minecraft/item/ItemStack")) + default ItemStack getNewRemainder(ItemConvertible origItem, C inv) { + WovenItemSettingsHolder holder = (WovenItemSettingsHolder) origItem; + + if (holder.woven$getDynamicRecipeRemainder() != null) { + return holder.woven$getDynamicRecipeRemainder().apply(inv.getStack( + GrossThreadLocalHack.THREADLOCALS.computeIfAbsent( + (Recipe)this, x -> new ThreadLocal<>()).get()), this.getId()); + } + + return new ItemStack(origItem); + }*/ } From 4750b3f327cc2a922cdffcadba012d44d2e3aeb9 Mon Sep 17 00:00:00 2001 From: repulica Date: Thu, 17 Sep 2020 01:07:46 -0700 Subject: [PATCH 07/11] functional interfaces, safety checks, more docs --- .../api/item/settings/EquipmentHandler.java | 16 ++++ .../api/item/settings/MeterComponent.java | 66 ++++++++++------ .../item/settings/RecipeRemainderHandler.java | 17 +++++ .../api/item/settings/WovenItemSettings.java | 76 ++++++++++++++----- .../settings/WovenItemSettingsHolder.java | 13 +--- .../MixinAbstractFurnaceBlockEntity.java | 10 +-- .../woven/mixin/item/settings/MixinItem.java | 34 ++++++--- .../resources/woven-item-settings.mixins.json | 1 + 8 files changed, 166 insertions(+), 67 deletions(-) create mode 100644 src/main/java/net/wovenmc/woven/api/item/settings/EquipmentHandler.java create mode 100644 src/main/java/net/wovenmc/woven/api/item/settings/RecipeRemainderHandler.java diff --git a/src/main/java/net/wovenmc/woven/api/item/settings/EquipmentHandler.java b/src/main/java/net/wovenmc/woven/api/item/settings/EquipmentHandler.java new file mode 100644 index 0000000..d46043f --- /dev/null +++ b/src/main/java/net/wovenmc/woven/api/item/settings/EquipmentHandler.java @@ -0,0 +1,16 @@ +package net.wovenmc.woven.api.item.settings; + +import net.minecraft.entity.EquipmentSlot; +import net.minecraft.item.ItemStack; + +/** + * An interface for handling the equipment slots of non-armor items. + */ +@FunctionalInterface +public interface EquipmentHandler { + /** + * @param stack The stack to equip. + * @return The slot the stack should be equipped to. + */ + EquipmentSlot getEquipmentSlot(ItemStack stack); +} diff --git a/src/main/java/net/wovenmc/woven/api/item/settings/MeterComponent.java b/src/main/java/net/wovenmc/woven/api/item/settings/MeterComponent.java index f303716..7857c01 100644 --- a/src/main/java/net/wovenmc/woven/api/item/settings/MeterComponent.java +++ b/src/main/java/net/wovenmc/woven/api/item/settings/MeterComponent.java @@ -16,9 +16,6 @@ package net.wovenmc.woven.api.item.settings; -import java.util.function.BiFunction; -import java.util.function.Function; - import net.minecraft.item.ItemStack; import net.minecraft.util.math.MathHelper; @@ -26,14 +23,14 @@ * A component that displays a colored meter on an item in a GUI, similar to the vanilla damage bar. */ public class MeterComponent { - private final Function levelFunc; - private final BiFunction colorFunc; + private final LevelHandler levelHandler; + private final ColorHandler colorHandler; private final boolean displayAtFull; - private MeterComponent(Function levelFunc, BiFunction colorFunc, + private MeterComponent(LevelHandler levelHandler, ColorHandler colorHandler, boolean displayAtFull) { - this.levelFunc = levelFunc; - this.colorFunc = colorFunc; + this.levelHandler = levelHandler; + this.colorHandler = colorHandler; this.displayAtFull = displayAtFull; } @@ -43,7 +40,7 @@ private MeterComponent(Function levelFunc, BiFunction levelFunc = stack -> + private LevelHandler levelHandler = stack -> (stack.getMaxDamage() - stack.getDamage()) / (float) stack.getMaxDamage(); - private BiFunction colorFunc = (stack, level) -> - MathHelper.hsvToRgb(levelFunc.apply(stack) / 3F, 1F, 1F); + private ColorHandler colorHandler = (stack, level) -> + MathHelper.hsvToRgb(levelHandler.getLevel(stack) / 3F, 1F, 1F); private boolean displayAtFull = false; /** - * @param function The function for getting the current level of a meter. - * @return The builder with the function set. + * @param handler The handler for getting the current level of a meter. + * @return The builder with the handler set. */ - public Builder levelFunction(Function function) { - this.levelFunc = function; + public Builder levelFunction(LevelHandler handler) { + this.levelHandler = handler; return this; } /** - * @param function The function for getting the current color of a meter. - * @return The builder with the function set. + * @param handler The handler for getting the current color of a meter. + * @return The builder with the handler set. */ - public Builder colorFunction(BiFunction function) { - this.colorFunc = function; + public Builder colorHandler(ColorHandler handler) { + this.colorHandler = handler; return this; } @@ -102,7 +99,32 @@ public Builder displayAtFull() { * @return A built meter component. */ public MeterComponent build() { - return new MeterComponent(levelFunc, colorFunc, displayAtFull); + return new MeterComponent(levelHandler, colorHandler, displayAtFull); } } + + /** + * An interface for determining the level of a meter. + */ + @FunctionalInterface + public interface LevelHandler { + /** + * @param stack The stack to get the meter level for. + * @return The level of the meter, as a float from 0 to 1 inclusive. + */ + float getLevel(ItemStack stack); + } + + /** + * An interface for determining the color of a meter. + */ + @FunctionalInterface + public interface ColorHandler { + /** + * @param stack The stack to get the meter color for. + * @param value The current level of the meter. + * @return The color to use as an RGB value. + */ + int getColor(ItemStack stack, float value); + } } diff --git a/src/main/java/net/wovenmc/woven/api/item/settings/RecipeRemainderHandler.java b/src/main/java/net/wovenmc/woven/api/item/settings/RecipeRemainderHandler.java new file mode 100644 index 0000000..1be91b8 --- /dev/null +++ b/src/main/java/net/wovenmc/woven/api/item/settings/RecipeRemainderHandler.java @@ -0,0 +1,17 @@ +package net.wovenmc.woven.api.item.settings; + +import net.minecraft.item.ItemStack; +import net.minecraft.util.Identifier; + +/** + * An interface for dynamically handling recipe remainders. + */ +@FunctionalInterface +public interface RecipeRemainderHandler { + /** + * @param original The original item stack used in the recipe. + * @param recipeId The ID of the original recipe. Hardcoded to minecraft:brewing for brewing and minecraft:furnace_fuel for furnace fuel. + * @return The item stack that should remain after crafting. + */ + ItemStack getRemainder(ItemStack original, Identifier recipeId); +} diff --git a/src/main/java/net/wovenmc/woven/api/item/settings/WovenItemSettings.java b/src/main/java/net/wovenmc/woven/api/item/settings/WovenItemSettings.java index 891c01b..42e4104 100644 --- a/src/main/java/net/wovenmc/woven/api/item/settings/WovenItemSettings.java +++ b/src/main/java/net/wovenmc/woven/api/item/settings/WovenItemSettings.java @@ -16,17 +16,12 @@ package net.wovenmc.woven.api.item.settings; -import java.util.function.BiFunction; -import java.util.function.Function; - +import net.wovenmc.woven.mixin.item.settings.MixinItem; import org.jetbrains.annotations.Nullable; -import net.minecraft.entity.EquipmentSlot; import net.minecraft.item.FoodComponent; import net.minecraft.item.Item; import net.minecraft.item.ItemGroup; -import net.minecraft.item.ItemStack; -import net.minecraft.util.Identifier; import net.minecraft.util.Rarity; /** @@ -34,8 +29,9 @@ */ public class WovenItemSettings extends Item.Settings { private MeterComponent meterComponent = null; - private BiFunction dynamicRecipeRemainder = null; - private Function equipmentHandler = null; + private RecipeRemainderHandler dynamicRecipeRemainder = null; + private EquipmentHandler equipmentHandler = null; + private boolean selfRemainder = false; /** * @param meterComponent The {@link MeterComponent} for this item. @@ -47,19 +43,42 @@ public WovenItemSettings meter(MeterComponent meterComponent) { } /** - * @param remainder A function for determining the remainder of an item stack when crafting dynamically. - * @return The item settings with the function added. + * Incompatible with {@link WovenItemSettings#selfRemainder} and {@link WovenItemSettings#recipeRemainder(Item)}. + * @param remainder A handler for determining the remainder of an item stack when crafting dynamically. + * @return The item settings with the handler added. */ - public WovenItemSettings dynamicRecipeRemainder(BiFunction remainder) { - this.dynamicRecipeRemainder = remainder; - return this; + public WovenItemSettings recipeRemainder(RecipeRemainderHandler remainder) { + if (selfRemainder) { + throw new RuntimeException("Unable to have dynamic recipe remainder AND self recipe remainder."); + } else if (((MixinItem.ItemSettingsAccessor) this).getRecipeRemainder() != null) { + throw new RuntimeException("Unable to have dynamic recipe remainder AND static recipe remainder."); + } else { + this.dynamicRecipeRemainder = remainder; + return this; + } } /** - * @param equipmentHandler A function for determining the equipment slot an item stack should go in. - * @return The item settings with the function added. + * Incompatible with {@link WovenItemSettings#recipeRemainder(RecipeRemainderHandler)} and {@link Item.Settings#recipeRemainder(Item)}. + * Flags an item to return itself as a recipe remainder without a dynamic remainder handler. + * @return The item settings with the flag set. */ - public WovenItemSettings equipmentHandler(Function equipmentHandler) { + public WovenItemSettings selfRemainder() { + if (dynamicRecipeRemainder != null) { + throw new RuntimeException("Unable to have self recipe remainder AND dynamic recipe remainder."); + } else if (((MixinItem.ItemSettingsAccessor) this).getRecipeRemainder() != null) { + throw new RuntimeException("Unable to have self recipe remainder AND static recipe remainder."); + } else { + this.selfRemainder = true; + return this; + } + } + + /** + * @param equipmentHandler A handler for determining the equipment slot an item stack should go in. + * @return The item settings with the handler added. + */ + public WovenItemSettings equipmentHandler(EquipmentHandler equipmentHandler) { this.equipmentHandler = equipmentHandler; return this; } @@ -76,10 +95,19 @@ public WovenItemSettings rarity(Rarity rarity) { return this; } + /** + * Incompatible with {@link WovenItemSettings#recipeRemainder(RecipeRemainderHandler)} and {@link WovenItemSettings#selfRemainder}. + */ @Override public WovenItemSettings recipeRemainder(Item recipeRemainder) { - super.recipeRemainder(recipeRemainder); - return this; + if (dynamicRecipeRemainder != null) { + throw new RuntimeException("Unable to have static recipe remainder AND dynamic recipe remainder."); + } else if (selfRemainder) { + throw new RuntimeException("Unable to have static recipe remainder AND self recipe remainder."); + } else { + super.recipeRemainder(recipeRemainder); + return this; + } } @Override @@ -126,16 +154,24 @@ public MeterComponent getMeterComponent() { * @return The set dynamic recipe remainder, or null if none was set. */ @Nullable - public BiFunction getDynamicRecipeRemainder() { + public RecipeRemainderHandler getRecipeRemainder() { return dynamicRecipeRemainder; } + /** + * For internal use. + * @return Whether the self-remainder flag was set. + */ + public boolean remainsSelf() { + return selfRemainder; + } + /** * For internal use. * @return The set equipment handler, or null if none was set */ @Nullable - public Function getEquipmentHandler() { + public EquipmentHandler getEquipmentHandler() { return equipmentHandler; } } diff --git a/src/main/java/net/wovenmc/woven/impl/item/settings/WovenItemSettingsHolder.java b/src/main/java/net/wovenmc/woven/impl/item/settings/WovenItemSettingsHolder.java index a833158..ee233f3 100644 --- a/src/main/java/net/wovenmc/woven/impl/item/settings/WovenItemSettingsHolder.java +++ b/src/main/java/net/wovenmc/woven/impl/item/settings/WovenItemSettingsHolder.java @@ -16,23 +16,18 @@ package net.wovenmc.woven.impl.item.settings; -import java.util.function.BiFunction; -import java.util.function.Function; - +import net.wovenmc.woven.api.item.settings.EquipmentHandler; import net.wovenmc.woven.api.item.settings.MeterComponent; +import net.wovenmc.woven.api.item.settings.RecipeRemainderHandler; import org.jetbrains.annotations.Nullable; -import net.minecraft.entity.EquipmentSlot; -import net.minecraft.item.ItemStack; -import net.minecraft.util.Identifier; - public interface WovenItemSettingsHolder { @Nullable MeterComponent woven$getMeterComponent(); @Nullable - BiFunction woven$getDynamicRecipeRemainder(); + RecipeRemainderHandler woven$getDynamicRecipeRemainder(); @Nullable - Function woven$getEquipmentHandler(); + EquipmentHandler woven$getEquipmentHandler(); } diff --git a/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinAbstractFurnaceBlockEntity.java b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinAbstractFurnaceBlockEntity.java index e340b27..7249eeb 100644 --- a/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinAbstractFurnaceBlockEntity.java +++ b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinAbstractFurnaceBlockEntity.java @@ -33,7 +33,6 @@ import net.minecraft.recipe.Recipe; import net.minecraft.util.Identifier; import net.minecraft.util.collection.DefaultedList; -import net.minecraft.util.registry.Registry; @Mixin(AbstractFurnaceBlockEntity.class) public abstract class MixinAbstractFurnaceBlockEntity { @@ -51,10 +50,11 @@ private void grabLocalStack(CallbackInfo info, boolean isBurning, boolean isCook @Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;getRecipeRemainder()Lnet/minecraft/item/Item;")) private Item hackCustomFuelRemainder(Item origItem) { WovenItemSettingsHolder holder = (WovenItemSettingsHolder) origItem; - System.out.println(Registry.ITEM.getId(origItem)); if (holder.woven$getDynamicRecipeRemainder() != null) { - return Items.COAL; + //hack to make the furnace realize it should do dynamic recipe remainder due to mixin not being able to change flow + //just needs to not be null + return Items.AIR; } return origItem.getRecipeRemainder(); @@ -65,7 +65,7 @@ private ItemStack getNewFuelRemainder(ItemConvertible origItem) { WovenItemSettingsHolder holder = (WovenItemSettingsHolder) origItem; if (holder.woven$getDynamicRecipeRemainder() != null) { - return holder.woven$getDynamicRecipeRemainder().apply(stack.get(), FUEL_ID); + return holder.woven$getDynamicRecipeRemainder().getRemainder(stack.get(), FUEL_ID); } return new ItemStack(origItem); @@ -77,7 +77,7 @@ private void injectSmeltRemainder(Recipe recipe, CallbackInfo info, ItemStack WovenItemSettingsHolder woven = (WovenItemSettingsHolder) inStack.getItem(); if (woven.woven$getDynamicRecipeRemainder() != null) { - ItemStack newStack = woven.woven$getDynamicRecipeRemainder().apply(inStack, recipe.getId()); + ItemStack newStack = woven.woven$getDynamicRecipeRemainder().getRemainder(inStack, recipe.getId()); if (!newStack.isEmpty()) { this.inventory.set(0, newStack); diff --git a/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinItem.java b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinItem.java index a78d36f..741af2d 100644 --- a/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinItem.java +++ b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinItem.java @@ -16,39 +16,40 @@ package net.wovenmc.woven.mixin.item.settings; -import java.util.function.BiFunction; -import java.util.function.Function; - +import net.wovenmc.woven.api.item.settings.EquipmentHandler; +import net.wovenmc.woven.api.item.settings.RecipeRemainderHandler; import net.wovenmc.woven.impl.item.settings.WovenItemSettingsHolder; import net.wovenmc.woven.api.item.settings.MeterComponent; import net.wovenmc.woven.api.item.settings.WovenItemSettings; import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.gen.Accessor; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import net.minecraft.entity.EquipmentSlot; import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.util.Identifier; @Mixin(Item.class) public abstract class MixinItem implements WovenItemSettingsHolder { @Unique private MeterComponent woven$meterComponent; @Unique - private BiFunction woven$dynamicRecipeRemainder; + private RecipeRemainderHandler woven$dynamicRecipeRemainder; + @Unique + private boolean woven$selfRemainder; @Unique - private Function woven$equipmentHandler; + private EquipmentHandler woven$equipmentHandler; @Inject(method = "", at = @At("RETURN")) private void captureInit(Item.Settings settings, CallbackInfo info) { if (settings instanceof WovenItemSettings) { WovenItemSettings woven = (WovenItemSettings) settings; this.woven$meterComponent = woven.getMeterComponent(); - this.woven$dynamicRecipeRemainder = woven.getDynamicRecipeRemainder(); + this.woven$dynamicRecipeRemainder = woven.getRecipeRemainder(); + this.woven$selfRemainder = woven.remainsSelf(); this.woven$equipmentHandler = woven.getEquipmentHandler(); } } @@ -61,13 +62,24 @@ private void captureInit(Item.Settings settings, CallbackInfo info) { @Nullable @Override - public BiFunction woven$getDynamicRecipeRemainder() { + public RecipeRemainderHandler woven$getDynamicRecipeRemainder() { return woven$dynamicRecipeRemainder; } @Nullable @Override - public Function woven$getEquipmentHandler() { + public EquipmentHandler woven$getEquipmentHandler() { return woven$equipmentHandler; } + + @Inject(method = "getRecipeRemainder", at = @At("HEAD")) + private void injectSelfRemainder(CallbackInfoReturnable info) { + if (woven$selfRemainder) info.setReturnValue((Item) (Object) this); + } + + @Mixin(Item.Settings.class) + public interface ItemSettingsAccessor { + @Accessor + Item getRecipeRemainder(); + } } diff --git a/src/main/resources/woven-item-settings.mixins.json b/src/main/resources/woven-item-settings.mixins.json index b6c2692..156de0a 100644 --- a/src/main/resources/woven-item-settings.mixins.json +++ b/src/main/resources/woven-item-settings.mixins.json @@ -8,6 +8,7 @@ "MixinBookCloningRecipe", "MixinBrewingStandBlockEntity", "MixinItem", + "MixinItem$ItemSettingsAccessor", "MixinMobEntity", "MixinRecipe" ], From ab41aaf235c02e0074ee23495fbda8e9261b75d0 Mon Sep 17 00:00:00 2001 From: repulica <68724985+repulica@users.noreply.github.com> Date: Thu, 17 Sep 2020 03:31:45 -0700 Subject: [PATCH 08/11] Update src/main/java/net/wovenmc/woven/api/item/settings/RecipeRemainderHandler.java Co-authored-by: LambdAurora --- .../wovenmc/woven/api/item/settings/RecipeRemainderHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/wovenmc/woven/api/item/settings/RecipeRemainderHandler.java b/src/main/java/net/wovenmc/woven/api/item/settings/RecipeRemainderHandler.java index 1be91b8..adb62ba 100644 --- a/src/main/java/net/wovenmc/woven/api/item/settings/RecipeRemainderHandler.java +++ b/src/main/java/net/wovenmc/woven/api/item/settings/RecipeRemainderHandler.java @@ -10,7 +10,7 @@ public interface RecipeRemainderHandler { /** * @param original The original item stack used in the recipe. - * @param recipeId The ID of the original recipe. Hardcoded to minecraft:brewing for brewing and minecraft:furnace_fuel for furnace fuel. + * @param recipeId The identifier of the original recipe. Hardcoded to {@code minecraft:brewing} for brewing and {@code minecraft:furnace_fuel} for furnace fuel. * @return The item stack that should remain after crafting. */ ItemStack getRemainder(ItemStack original, Identifier recipeId); From a580a0fe1a50e8d4427c73098c5c9fc1c4a41fc2 Mon Sep 17 00:00:00 2001 From: repulica Date: Thu, 17 Sep 2020 03:32:43 -0700 Subject: [PATCH 09/11] fix redundant call --- .../net/wovenmc/woven/api/item/settings/MeterComponent.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/wovenmc/woven/api/item/settings/MeterComponent.java b/src/main/java/net/wovenmc/woven/api/item/settings/MeterComponent.java index 7857c01..afe64c7 100644 --- a/src/main/java/net/wovenmc/woven/api/item/settings/MeterComponent.java +++ b/src/main/java/net/wovenmc/woven/api/item/settings/MeterComponent.java @@ -66,7 +66,7 @@ public static class Builder { private LevelHandler levelHandler = stack -> (stack.getMaxDamage() - stack.getDamage()) / (float) stack.getMaxDamage(); private ColorHandler colorHandler = (stack, level) -> - MathHelper.hsvToRgb(levelHandler.getLevel(stack) / 3F, 1F, 1F); + MathHelper.hsvToRgb(level / 3F, 1F, 1F); private boolean displayAtFull = false; /** From b08a513ad1a41ce2aba0989a5074e323cbd854a5 Mon Sep 17 00:00:00 2001 From: repulica Date: Thu, 17 Sep 2020 04:25:08 -0700 Subject: [PATCH 10/11] license headers, again --- .../api/item/settings/EquipmentHandler.java | 16 ++++++++++++++++ .../item/settings/RecipeRemainderHandler.java | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/main/java/net/wovenmc/woven/api/item/settings/EquipmentHandler.java b/src/main/java/net/wovenmc/woven/api/item/settings/EquipmentHandler.java index d46043f..3629489 100644 --- a/src/main/java/net/wovenmc/woven/api/item/settings/EquipmentHandler.java +++ b/src/main/java/net/wovenmc/woven/api/item/settings/EquipmentHandler.java @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2020 WovenMC + * + * 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.wovenmc.woven.api.item.settings; import net.minecraft.entity.EquipmentSlot; diff --git a/src/main/java/net/wovenmc/woven/api/item/settings/RecipeRemainderHandler.java b/src/main/java/net/wovenmc/woven/api/item/settings/RecipeRemainderHandler.java index adb62ba..b92cee6 100644 --- a/src/main/java/net/wovenmc/woven/api/item/settings/RecipeRemainderHandler.java +++ b/src/main/java/net/wovenmc/woven/api/item/settings/RecipeRemainderHandler.java @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2020 WovenMC + * + * 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.wovenmc.woven.api.item.settings; import net.minecraft.item.ItemStack; From a78468cfbdf777ee9d3f4edf958c1af411b388e8 Mon Sep 17 00:00:00 2001 From: repulica Date: Sun, 20 Sep 2020 14:21:25 -0700 Subject: [PATCH 11/11] fix compile errors idea didnt catch --- .../woven/mixin/item/settings/MixinBannerDuplicateRecipe.java | 2 +- .../woven/mixin/item/settings/MixinBookCloningRecipe.java | 2 +- .../woven/mixin/item/settings/MixinBrewingStandBlockEntity.java | 2 +- .../net/wovenmc/woven/mixin/item/settings/MixinMobEntity.java | 2 +- .../java/net/wovenmc/woven/mixin/item/settings/MixinRecipe.java | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBannerDuplicateRecipe.java b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBannerDuplicateRecipe.java index bfcd4cb..57cd025 100644 --- a/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBannerDuplicateRecipe.java +++ b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBannerDuplicateRecipe.java @@ -52,7 +52,7 @@ private ItemStack getNewRemainder(ItemConvertible origItem, CraftingInventory in WovenItemSettingsHolder holder = (WovenItemSettingsHolder) origItem; if (holder.woven$getDynamicRecipeRemainder() != null) { - return holder.woven$getDynamicRecipeRemainder().apply(inv.getStack(slot.get()), this.getId()); + return holder.woven$getDynamicRecipeRemainder().getRemainder(inv.getStack(slot.get()), this.getId()); } return new ItemStack(origItem); diff --git a/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBookCloningRecipe.java b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBookCloningRecipe.java index c667ff0..7e34842 100644 --- a/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBookCloningRecipe.java +++ b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBookCloningRecipe.java @@ -52,7 +52,7 @@ private ItemStack getNewRemainder(ItemConvertible origItem, CraftingInventory in WovenItemSettingsHolder holder = (WovenItemSettingsHolder) origItem; if (holder.woven$getDynamicRecipeRemainder() != null) { - return holder.woven$getDynamicRecipeRemainder().apply(inv.getStack(slot.get()), this.getId()); + return holder.woven$getDynamicRecipeRemainder().getRemainder(inv.getStack(slot.get()), this.getId()); } return new ItemStack(origItem); diff --git a/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBrewingStandBlockEntity.java b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBrewingStandBlockEntity.java index a542429..f5a6c09 100644 --- a/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBrewingStandBlockEntity.java +++ b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinBrewingStandBlockEntity.java @@ -45,7 +45,7 @@ private ItemStack getNewRemainder(ItemConvertible origItem) { WovenItemSettingsHolder holder = (WovenItemSettingsHolder) origItem; if (holder.woven$getDynamicRecipeRemainder() != null) { - return holder.woven$getDynamicRecipeRemainder().apply(stack.get(), BREWING_ID); + return holder.woven$getDynamicRecipeRemainder().getRemainder(stack.get(), BREWING_ID); } return new ItemStack(origItem); diff --git a/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinMobEntity.java b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinMobEntity.java index 8390495..2bb1c91 100644 --- a/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinMobEntity.java +++ b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinMobEntity.java @@ -35,7 +35,7 @@ private static void onGetPreferredEquipmentSlot(ItemStack stack, CallbackInfoRet WovenItemSettingsHolder holder = ((WovenItemSettingsHolder) item); if (holder.woven$getEquipmentHandler() != null) { - info.setReturnValue(holder.woven$getEquipmentHandler().apply(stack)); + info.setReturnValue(holder.woven$getEquipmentHandler().getEquipmentSlot(stack)); } } } diff --git a/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinRecipe.java b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinRecipe.java index 5d0653e..c097672 100644 --- a/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinRecipe.java +++ b/src/main/java/net/wovenmc/woven/mixin/item/settings/MixinRecipe.java @@ -47,7 +47,7 @@ default DefaultedList getRemainingStacks(C inventory) { WovenItemSettingsHolder woven = (WovenItemSettingsHolder) item; if (woven.woven$getDynamicRecipeRemainder() != null) { - defaultedList.set(i, woven.woven$getDynamicRecipeRemainder().apply(inventory.getStack(i), getId())); + defaultedList.set(i, woven.woven$getDynamicRecipeRemainder().getRemainder(inventory.getStack(i), getId())); } else if (item.hasRecipeRemainder()) { defaultedList.set(i, new ItemStack(item.getRecipeRemainder())); }