GeezerVison is showing github.com — Fix #25 (add BlockAnvilSmashingRecipe) · MaxNeedsSnacks/Interactio@f2e030a
This repository was archived by the owner on Aug 9, 2022. It is now read-only.
File treeExpand file treeCollapse file tree Open diff view settings java/dev/maxneedssnacks/interactio resources/assets/interactio/lang
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: src/main/java/dev/maxneedssnacks/interactio/core/mixin/AnvilBlockMixin.java +6-1Lines changed: 6 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -29,11 +29,16 @@ public AnvilBlockMixin(Properties p_i48401_1_) { | 29 | 29 | method = "onEndFalling(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;Lnet/minecraft/block/BlockState;Lnet/minecraft/entity/item/FallingBlockEntity;)V", | 30 | 30 | at = @At(value = "RETURN") | 31 | 31 | ) | 32 | | - public void handleAnvilRecipes(World world, BlockPos pos, BlockState fallState, BlockState hitState, FallingBlockEntity entity, CallbackInfo ci) { | | 32 | + public void handleAnvilRecipes(World world, BlockPos pos, BlockState fallState, BlockState landState, FallingBlockEntity entity, CallbackInfo ci) { | 33 | 33 | List<ItemEntity> items = world.getEntitiesWithinAABB(ItemEntity.class, new AxisAlignedBB(pos, pos.add(1, 1, 1))); | | 34 | + BlockPos hitPos = pos.down(); | | 35 | + BlockState hitState = world.getBlockState(hitPos); | 34 | 36 |
| 35 | 37 | InWorldRecipeType.ITEM_ANVIL_SMASHING.applyAll(recipe -> recipe.canCraft(items, hitState), | 36 | 38 | recipe -> recipe.craft(items, new InWorldRecipe.DefaultInfo(world, pos))); | | 39 | + | | 40 | + InWorldRecipeType.BLOCK_ANVIL_SMASHING.apply(recipe -> recipe.canCraft(pos, hitState), | | 41 | + recipe -> recipe.craft(pos, new InWorldRecipe.DefaultInfo(world, hitPos))); | 37 | 42 | } | 38 | 43 |
| 39 | 44 | } |
Collapse file Copy file name to clipboardExpand all lines: src/main/java/dev/maxneedssnacks/interactio/integration/jei/InteractioJEIPlugin.java +3-1Lines changed: 3 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -36,7 +36,8 @@ public void registerCategories(IRecipeCategoryRegistration registration) { | 36 | 36 | new ItemExplosionCategory(guiHelper), | 37 | 37 | new BlockExplosionCategory(guiHelper), | 38 | 38 | new ItemLightningCategory(guiHelper), | 39 | | - new ItemAnvilSmashingCategory(guiHelper) | | 39 | + new ItemAnvilSmashingCategory(guiHelper), | | 40 | + new BlockAnvilSmashingCategory(guiHelper) | 40 | 41 | ); | 41 | 42 | } | 42 | 43 |
| @@ -48,5 +49,6 @@ public void registerRecipes(IRecipeRegistration registration) { | 48 | 49 | registration.addRecipes(InWorldRecipeType.BLOCK_EXPLODE.getRecipes(), BlockExplosionCategory.UID); | 49 | 50 | registration.addRecipes(InWorldRecipeType.ITEM_LIGHTNING.getRecipes(), ItemLightningCategory.UID); | 50 | 51 | registration.addRecipes(InWorldRecipeType.ITEM_ANVIL_SMASHING.getRecipes(), ItemAnvilSmashingCategory.UID); | | 52 | + registration.addRecipes(InWorldRecipeType.BLOCK_ANVIL_SMASHING.getRecipes(), BlockAnvilSmashingCategory.UID); | 51 | 53 | } | 52 | 54 | } |
Collapse file Copy file name to clipboard +161Lines changed: 161 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +package dev.maxneedssnacks.interactio.integration.jei.categories; | | 2 | + | | 3 | +import com.mojang.blaze3d.matrix.MatrixStack; | | 4 | +import com.mojang.blaze3d.systems.RenderSystem; | | 5 | +import dev.maxneedssnacks.interactio.Interactio; | | 6 | +import dev.maxneedssnacks.interactio.Utils; | | 7 | +import dev.maxneedssnacks.interactio.integration.jei.util.TooltipCallbacks; | | 8 | +import dev.maxneedssnacks.interactio.recipe.BlockAnvilSmashingRecipe; | | 9 | +import dev.maxneedssnacks.interactio.recipe.ingredient.WeightedOutput; | | 10 | +import dev.maxneedssnacks.interactio.recipe.util.InWorldRecipeType; | | 11 | +import mezz.jei.api.constants.VanillaTypes; | | 12 | +import mezz.jei.api.gui.IRecipeLayout; | | 13 | +import mezz.jei.api.gui.drawable.IDrawable; | | 14 | +import mezz.jei.api.gui.drawable.IDrawableStatic; | | 15 | +import mezz.jei.api.gui.ingredient.IGuiItemStackGroup; | | 16 | +import mezz.jei.api.helpers.IGuiHelper; | | 17 | +import mezz.jei.api.ingredients.IIngredients; | | 18 | +import mezz.jei.api.recipe.category.IRecipeCategory; | | 19 | +import net.minecraft.block.Block; | | 20 | +import net.minecraft.item.Item; | | 21 | +import net.minecraft.item.ItemStack; | | 22 | +import net.minecraft.item.Items; | | 23 | +import net.minecraft.util.ResourceLocation; | | 24 | + | | 25 | +import java.awt.*; | | 26 | +import java.util.Collections; | | 27 | +import java.util.List; | | 28 | +import java.util.stream.Collectors; | | 29 | + | | 30 | +public class BlockAnvilSmashingCategory implements IRecipeCategory<BlockAnvilSmashingRecipe> { | | 31 | + | | 32 | + public static final ResourceLocation UID = InWorldRecipeType.BLOCK_ANVIL_SMASHING.registryName; | | 33 | + | | 34 | + private final IGuiHelper guiHelper; | | 35 | + | | 36 | + private final IDrawableStatic background; | | 37 | + private final IDrawableStatic overlay; | | 38 | + | | 39 | + private final IDrawable icon; | | 40 | + | | 41 | + private final IDrawable anvil; | | 42 | + | | 43 | + private final String localizedName; | | 44 | + | | 45 | + private final int width = 160; | | 46 | + private final int height = 120; | | 47 | + | | 48 | + public BlockAnvilSmashingCategory(IGuiHelper guiHelper) { | | 49 | + this.guiHelper = guiHelper; | | 50 | + | | 51 | + background = guiHelper.createBlankDrawable(width, height); | | 52 | + overlay = guiHelper.createDrawable(Interactio.id("textures/gui/anvil_smashing.png"), 0, 0, width, height); | | 53 | + | | 54 | + icon = guiHelper.createDrawableIngredient(new ItemStack(Items.ANVIL)); | | 55 | + | | 56 | + anvil = guiHelper.createDrawableIngredient(new ItemStack(Items.ANVIL)); | | 57 | + | | 58 | + localizedName = Utils.translate("interactio.jei.block_anvil_smashing", null).getString(); | | 59 | + } | | 60 | + | | 61 | + @Override | | 62 | + public ResourceLocation getUid() { | | 63 | + return UID; | | 64 | + } | | 65 | + | | 66 | + @Override | | 67 | + public Class<BlockAnvilSmashingRecipe> getRecipeClass() { | | 68 | + return BlockAnvilSmashingRecipe.class; | | 69 | + } | | 70 | + | | 71 | + @Override | | 72 | + public String getTitle() { | | 73 | + return localizedName; | | 74 | + } | | 75 | + | | 76 | + @Override | | 77 | + public IDrawable getBackground() { | | 78 | + return background; | | 79 | + } | | 80 | + | | 81 | + @Override | | 82 | + public IDrawable getIcon() { | | 83 | + return icon; | | 84 | + } | | 85 | + | | 86 | + @Override | | 87 | + public void setIngredients(BlockAnvilSmashingRecipe recipe, IIngredients ingredients) { | | 88 | + // display input block as item | | 89 | + ingredients.setInputs(VanillaTypes.ITEM, recipe.getInput().getMatchingBlocks() | | 90 | + .stream() | | 91 | + .map(Block::asItem) | | 92 | + .map(Item::getDefaultInstance) | | 93 | + .collect(Collectors.toList())); | | 94 | + | | 95 | + // display resulting block as item, as well | | 96 | + if (recipe.getOutput().isBlock()) { | | 97 | + ingredients.setOutputLists(VanillaTypes.ITEM, Collections.singletonList(recipe.getOutput() | | 98 | + .blockOutput | | 99 | + .stream() | | 100 | + .map(WeightedOutput.WeightedEntry::getResult) | | 101 | + .map(Block::asItem) | | 102 | + .map(Item::getDefaultInstance) | | 103 | + .collect(Collectors.toList()))); | | 104 | + } else if (recipe.getOutput().isItem()) { | | 105 | + ingredients.setOutputLists(VanillaTypes.ITEM, Collections.singletonList(recipe.getOutput() | | 106 | + .itemOutput | | 107 | + .stream() | | 108 | + .map(WeightedOutput.WeightedEntry::getResult) | | 109 | + .collect(Collectors.toList()))); | | 110 | + } | | 111 | + } | | 112 | + | | 113 | + private final Point center = new Point(45, 52); | | 114 | + | | 115 | + @Override | | 116 | + public void setRecipe(IRecipeLayout layout, BlockAnvilSmashingRecipe recipe, IIngredients ingredients) { | | 117 | + | | 118 | + List<List<ItemStack>> outputs = ingredients.getOutputs(VanillaTypes.ITEM); | | 119 | + | | 120 | + IGuiItemStackGroup itemStackGroup = layout.getItemStacks(); | | 121 | + | | 122 | + WeightedOutput<ItemStack> output; | | 123 | + | | 124 | + if (recipe.getOutput().isItem()) { | | 125 | + output = recipe.getOutput().itemOutput; | | 126 | + } else if (recipe.getOutput().isBlock()) { | | 127 | + WeightedOutput<Block> blocks = recipe.getOutput().blockOutput; | | 128 | + output = new WeightedOutput<>(blocks.emptyWeight); | | 129 | + blocks.forEach(entry -> output.add(entry.getResult().asItem().getDefaultInstance(), entry.getWeight())); | | 130 | + } else { | | 131 | + output = new WeightedOutput<>(0.0D); | | 132 | + } | | 133 | + | | 134 | + WeightedOutput.WeightedEntry<ItemStack> empty = new WeightedOutput.WeightedEntry<>(Items.BARRIER.getDefaultInstance(), output.emptyWeight); | | 135 | + | | 136 | + itemStackGroup.init(0, true, center.x, center.y); | | 137 | + itemStackGroup.init(1, false, width - 20, center.y); | | 138 | + | | 139 | + if (output.emptyWeight > 0) outputs.get(0).add(empty.getResult()); | | 140 | + itemStackGroup.set(ingredients); | | 141 | + | | 142 | + itemStackGroup.addTooltipCallback((idx, input, stack, tooltip) -> { | | 143 | + TooltipCallbacks.weightedOutput(input, stack, tooltip, output, empty, recipe.getOutput().isItem(), entry -> entry.getResult().equals(stack, false)); | | 144 | + }); | | 145 | + | | 146 | + } | | 147 | + | | 148 | + @Override | | 149 | + public void draw(BlockAnvilSmashingRecipe recipe, MatrixStack ms, double mouseX, double mouseY) { | | 150 | + | | 151 | + RenderSystem.enableBlend(); | | 152 | + | | 153 | + overlay.draw(ms); | | 154 | + | | 155 | + RenderSystem.disableBlend(); | | 156 | + | | 157 | + anvil.draw(ms, center.x + 1, center.y - 32); | | 158 | + | | 159 | + } | | 160 | + | | 161 | +} |
Collapse file Copy file name to clipboardExpand all lines: src/main/java/dev/maxneedssnacks/interactio/integration/jei/categories/BlockExplosionCategory.java -1Lines changed: 0 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -133,7 +133,6 @@ public void setRecipe(IRecipeLayout layout, BlockExplosionRecipe recipe, IIngred | 133 | 133 |
| 134 | 134 | itemStackGroup.addTooltipCallback((idx, input, stack, tooltip) -> { | 135 | 135 | TooltipCallbacks.weightedOutput(input, stack, tooltip, output, empty, recipe.getOutput().isItem(), entry -> entry.getResult().equals(stack, false)); | 136 | | - TooltipCallbacks.recipeID(input, tooltip, recipe); | 137 | 136 | }); | 138 | 137 |
| 139 | 138 | } | |
Collapse file Copy file name to clipboardExpand all lines: src/main/java/dev/maxneedssnacks/interactio/integration/jei/categories/FluidFluidTransformCategory.java -1Lines changed: 0 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -155,7 +155,6 @@ public void setRecipe(IRecipeLayout layout, FluidFluidTransformRecipe recipe, II | 155 | 155 |
| 156 | 156 | fluidStackGroup.addTooltipCallback((idx, input, stack, tooltip) -> { | 157 | 157 | TooltipCallbacks.weightedOutput(input, stack.getFluid(), tooltip, output, empty, false); | 158 | | - TooltipCallbacks.recipeID(input, tooltip, recipe); | 159 | 158 | }); | 160 | 159 |
| 161 | 160 | } | |
Collapse file Copy file name to clipboardExpand all lines: src/main/java/dev/maxneedssnacks/interactio/integration/jei/categories/ItemAnvilSmashingCategory.java -1Lines changed: 0 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -144,7 +144,6 @@ public void setRecipe(IRecipeLayout layout, ItemAnvilSmashingRecipe recipe, IIng | 144 | 144 | itemStackGroup.addTooltipCallback((idx, input, stack, tooltip) -> { | 145 | 145 | TooltipCallbacks.returnChance(idx, input, tooltip, returnChances); | 146 | 146 | TooltipCallbacks.weightedOutput(input, stack, tooltip, output, empty, true); | 147 | | - TooltipCallbacks.recipeID(input, tooltip, recipe); | 148 | 147 | }); | 149 | 148 |
| 150 | 149 | } | |
Collapse file Copy file name to clipboardExpand all lines: src/main/java/dev/maxneedssnacks/interactio/integration/jei/categories/ItemExplosionCategory.java -1Lines changed: 0 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -142,7 +142,6 @@ public void setRecipe(IRecipeLayout layout, ItemExplosionRecipe recipe, IIngredi | 142 | 142 | itemStackGroup.addTooltipCallback((idx, input, stack, tooltip) -> { | 143 | 143 | TooltipCallbacks.returnChance(idx, input, tooltip, returnChances); | 144 | 144 | TooltipCallbacks.weightedOutput(input, stack, tooltip, output, empty, true); | 145 | | - TooltipCallbacks.recipeID(input, tooltip, recipe); | 146 | 145 | }); | 147 | 146 |
| 148 | 147 | } | |
Collapse file Copy file name to clipboardExpand all lines: src/main/java/dev/maxneedssnacks/interactio/integration/jei/categories/ItemFluidTransformCategory.java -1Lines changed: 0 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -149,7 +149,6 @@ public void setRecipe(IRecipeLayout layout, ItemFluidTransformRecipe recipe, IIn | 149 | 149 | itemStackGroup.addTooltipCallback((idx, input, stack, tooltip) -> { | 150 | 150 | TooltipCallbacks.returnChance(idx, input, tooltip, returnChances); | 151 | 151 | TooltipCallbacks.weightedOutput(input, stack, tooltip, output, empty, true); | 152 | | - TooltipCallbacks.recipeID(input, tooltip, recipe); | 153 | 152 | }); | 154 | 153 |
| 155 | 154 | fluidStackGroup.addTooltipCallback((idx, input, stack, tooltip) -> { | |
Collapse file Copy file name to clipboardExpand all lines: src/main/java/dev/maxneedssnacks/interactio/integration/jei/categories/ItemLightningCategory.java -1Lines changed: 0 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -138,7 +138,6 @@ public void setRecipe(IRecipeLayout layout, ItemLightningRecipe recipe, IIngredi | 138 | 138 | itemStackGroup.addTooltipCallback((idx, input, stack, tooltip) -> { | 139 | 139 | TooltipCallbacks.returnChance(idx, input, tooltip, returnChances); | 140 | 140 | TooltipCallbacks.weightedOutput(input, stack, tooltip, output, empty, true); | 141 | | - TooltipCallbacks.recipeID(input, tooltip, recipe); | 142 | 141 | }); | 143 | 142 |
| 144 | 143 | } | |
Collapse file Copy file name to clipboardExpand all lines: src/main/java/dev/maxneedssnacks/interactio/integration/jei/util/TooltipCallbacks.java -8Lines changed: 0 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -53,12 +53,4 @@ public static <T> void weightedOutput(boolean input, T stack, List<ITextComponen | 53 | 53 | } | 54 | 54 | } | 55 | 55 |
| 56 | | - public static void recipeID(boolean input, List<ITextComponent> tooltip, IRecipe<?> recipe) { | 57 | | - if (!input) { | 58 | | - boolean showAdvanced = Minecraft.getInstance().gameSettings.advancedItemTooltips || Screen.hasShiftDown(); | 59 | | - if (showAdvanced) { | 60 | | - tooltip.add(Utils.translate("jei.tooltip.recipe.id", Style.EMPTY.setFormatting(TextFormatting.DARK_GRAY), recipe.getId())); | 61 | | - } | 62 | | - } | 63 | | - } | 64 | 56 | } |
|