Moved AnvilReceipts to BCLib
This commit is contained in:
parent
83b6c84f7d
commit
2e61a58e26
17 changed files with 553 additions and 1277 deletions
|
@ -1,20 +1,18 @@
|
||||||
package ru.betterend.blocks.basis;
|
package ru.betterend.blocks.basis;
|
||||||
|
|
||||||
import net.minecraft.world.level.material.MaterialColor;
|
import net.minecraft.world.level.material.MaterialColor;
|
||||||
import ru.bclib.blocks.BaseAnvilBlock;
|
import ru.bclib.blocks.LeveledAnvilBlock;
|
||||||
import ru.betterend.complexmaterials.MetalMaterial;
|
import ru.betterend.complexmaterials.MetalMaterial;
|
||||||
|
|
||||||
public class EndAnvilBlock extends BaseAnvilBlock {
|
public class EndAnvilBlock extends LeveledAnvilBlock {
|
||||||
protected MetalMaterial metalMaterial;
|
protected MetalMaterial metalMaterial;
|
||||||
protected final int level;
|
|
||||||
|
|
||||||
public EndAnvilBlock(MaterialColor color, int level) {
|
public EndAnvilBlock(MaterialColor color, int level) {
|
||||||
super(color);
|
super(color, level);
|
||||||
this.level = level;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public EndAnvilBlock(MetalMaterial metalMaterial, MaterialColor color, int level) {
|
public EndAnvilBlock(MetalMaterial metalMaterial, MaterialColor color, int level) {
|
||||||
this(color, level);
|
super(color, level);
|
||||||
this.metalMaterial = metalMaterial;
|
this.metalMaterial = metalMaterial;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@ import ru.bclib.items.tool.BaseAxeItem;
|
||||||
import ru.bclib.items.tool.BaseHoeItem;
|
import ru.bclib.items.tool.BaseHoeItem;
|
||||||
import ru.bclib.items.tool.BaseShovelItem;
|
import ru.bclib.items.tool.BaseShovelItem;
|
||||||
import ru.bclib.items.tool.BaseSwordItem;
|
import ru.bclib.items.tool.BaseSwordItem;
|
||||||
|
import ru.bclib.recipes.AnvilRecipe;
|
||||||
import ru.bclib.recipes.FurnaceRecipe;
|
import ru.bclib.recipes.FurnaceRecipe;
|
||||||
import ru.bclib.recipes.GridRecipe;
|
import ru.bclib.recipes.GridRecipe;
|
||||||
import ru.bclib.recipes.SmithingTableRecipe;
|
import ru.bclib.recipes.SmithingTableRecipe;
|
||||||
|
@ -43,7 +44,6 @@ import ru.betterend.item.EndArmorItem;
|
||||||
import ru.betterend.item.tool.EndHammerItem;
|
import ru.betterend.item.tool.EndHammerItem;
|
||||||
import ru.betterend.item.tool.EndPickaxe;
|
import ru.betterend.item.tool.EndPickaxe;
|
||||||
import ru.betterend.recipe.builders.AlloyingRecipe;
|
import ru.betterend.recipe.builders.AlloyingRecipe;
|
||||||
import ru.betterend.recipe.builders.AnvilRecipe;
|
|
||||||
import ru.betterend.registry.EndBlocks;
|
import ru.betterend.registry.EndBlocks;
|
||||||
import ru.betterend.registry.EndItems;
|
import ru.betterend.registry.EndItems;
|
||||||
|
|
||||||
|
@ -95,7 +95,8 @@ public class MetalMaterial {
|
||||||
return new MetalMaterial(
|
return new MetalMaterial(
|
||||||
name,
|
name,
|
||||||
true,
|
true,
|
||||||
FabricBlockSettings.copyOf(Blocks.IRON_BLOCK).materialColor(color),
|
FabricBlockSettings.copyOf(Blocks.IRON_BLOCK)
|
||||||
|
.materialColor(color),
|
||||||
EndItems.makeEndItemSettings(),
|
EndItems.makeEndItemSettings(),
|
||||||
material,
|
material,
|
||||||
armor
|
armor
|
||||||
|
@ -120,7 +121,8 @@ public class MetalMaterial {
|
||||||
return new MetalMaterial(
|
return new MetalMaterial(
|
||||||
name,
|
name,
|
||||||
false,
|
false,
|
||||||
FabricBlockSettings.copyOf(Blocks.IRON_BLOCK).materialColor(color),
|
FabricBlockSettings.copyOf(Blocks.IRON_BLOCK)
|
||||||
|
.materialColor(color),
|
||||||
EndItems.makeEndItemSettings(),
|
EndItems.makeEndItemSettings(),
|
||||||
material,
|
material,
|
||||||
armor
|
armor
|
||||||
|
@ -368,14 +370,16 @@ public class MetalMaterial {
|
||||||
.buildWithBlasting();
|
.buildWithBlasting();
|
||||||
|
|
||||||
// Tool parts from ingots
|
// Tool parts from ingots
|
||||||
AnvilRecipe.Builder.create(name + "_shovel_head")
|
AnvilRecipe.create(name + "_shovel_head")
|
||||||
|
.checkConfig(Configs.RECIPE_CONFIG)
|
||||||
.setInput(ingot)
|
.setInput(ingot)
|
||||||
.setOutput(shovelHead)
|
.setOutput(shovelHead)
|
||||||
.setAnvilLevel(level)
|
.setAnvilLevel(level)
|
||||||
.setToolLevel(level)
|
.setToolLevel(level)
|
||||||
.setDamage(level)
|
.setDamage(level)
|
||||||
.build();
|
.build();
|
||||||
AnvilRecipe.Builder.create(name + "_pickaxe_head")
|
AnvilRecipe.create(name + "_pickaxe_head")
|
||||||
|
.checkConfig(Configs.RECIPE_CONFIG)
|
||||||
.setInput(ingot)
|
.setInput(ingot)
|
||||||
.setInputCount(3)
|
.setInputCount(3)
|
||||||
.setOutput(pickaxeHead)
|
.setOutput(pickaxeHead)
|
||||||
|
@ -383,7 +387,8 @@ public class MetalMaterial {
|
||||||
.setToolLevel(level)
|
.setToolLevel(level)
|
||||||
.setDamage(level)
|
.setDamage(level)
|
||||||
.build();
|
.build();
|
||||||
AnvilRecipe.Builder.create(name + "_axe_head")
|
AnvilRecipe.create(name + "_axe_head")
|
||||||
|
.checkConfig(Configs.RECIPE_CONFIG)
|
||||||
.setInput(ingot)
|
.setInput(ingot)
|
||||||
.setInputCount(3)
|
.setInputCount(3)
|
||||||
.setOutput(axeHead)
|
.setOutput(axeHead)
|
||||||
|
@ -391,7 +396,8 @@ public class MetalMaterial {
|
||||||
.setToolLevel(level)
|
.setToolLevel(level)
|
||||||
.setDamage(level)
|
.setDamage(level)
|
||||||
.build();
|
.build();
|
||||||
AnvilRecipe.Builder.create(name + "_hoe_head")
|
AnvilRecipe.create(name + "_hoe_head")
|
||||||
|
.checkConfig(Configs.RECIPE_CONFIG)
|
||||||
.setInput(ingot)
|
.setInput(ingot)
|
||||||
.setInputCount(2)
|
.setInputCount(2)
|
||||||
.setOutput(hoeHead)
|
.setOutput(hoeHead)
|
||||||
|
@ -399,14 +405,16 @@ public class MetalMaterial {
|
||||||
.setToolLevel(level)
|
.setToolLevel(level)
|
||||||
.setDamage(level)
|
.setDamage(level)
|
||||||
.build();
|
.build();
|
||||||
AnvilRecipe.Builder.create(name + "_sword_blade")
|
AnvilRecipe.create(name + "_sword_blade")
|
||||||
|
.checkConfig(Configs.RECIPE_CONFIG)
|
||||||
.setInput(ingot)
|
.setInput(ingot)
|
||||||
.setOutput(swordBlade)
|
.setOutput(swordBlade)
|
||||||
.setAnvilLevel(level)
|
.setAnvilLevel(level)
|
||||||
.setToolLevel(level)
|
.setToolLevel(level)
|
||||||
.setDamage(level)
|
.setDamage(level)
|
||||||
.build();
|
.build();
|
||||||
AnvilRecipe.Builder.create(name + "_forged_plate")
|
AnvilRecipe.create(name + "_forged_plate")
|
||||||
|
.checkConfig(Configs.RECIPE_CONFIG)
|
||||||
.setInput(ingot)
|
.setInput(ingot)
|
||||||
.setOutput(forgedPlate)
|
.setOutput(forgedPlate)
|
||||||
.setAnvilLevel(level)
|
.setAnvilLevel(level)
|
||||||
|
|
|
@ -1,5 +1,10 @@
|
||||||
package ru.betterend.integration.rei;
|
package ru.betterend.integration.rei;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import me.shedaniel.rei.api.common.category.CategoryIdentifier;
|
import me.shedaniel.rei.api.common.category.CategoryIdentifier;
|
||||||
import me.shedaniel.rei.api.common.display.SimpleGridMenuDisplay;
|
import me.shedaniel.rei.api.common.display.SimpleGridMenuDisplay;
|
||||||
import me.shedaniel.rei.api.common.display.basic.BasicDisplay;
|
import me.shedaniel.rei.api.common.display.basic.BasicDisplay;
|
||||||
|
@ -7,11 +12,7 @@ import me.shedaniel.rei.api.common.util.EntryIngredients;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.item.crafting.Recipe;
|
import net.minecraft.world.item.crafting.Recipe;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import ru.bclib.recipes.AnvilRecipe;
|
||||||
import ru.betterend.recipe.builders.AnvilRecipe;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public class REIAnvilDisplay extends BasicDisplay implements SimpleGridMenuDisplay {
|
public class REIAnvilDisplay extends BasicDisplay implements SimpleGridMenuDisplay {
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
package ru.betterend.integration.rei;
|
package ru.betterend.integration.rei;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
import me.shedaniel.rei.api.client.plugins.REIClientPlugin;
|
import me.shedaniel.rei.api.client.plugins.REIClientPlugin;
|
||||||
import me.shedaniel.rei.api.client.registry.category.CategoryRegistry;
|
import me.shedaniel.rei.api.client.registry.category.CategoryRegistry;
|
||||||
import me.shedaniel.rei.api.client.registry.display.DisplayRegistry;
|
import me.shedaniel.rei.api.client.registry.display.DisplayRegistry;
|
||||||
|
@ -17,17 +22,13 @@ import net.minecraft.world.item.crafting.BlastingRecipe;
|
||||||
import net.minecraft.world.item.crafting.RecipeType;
|
import net.minecraft.world.item.crafting.RecipeType;
|
||||||
import net.minecraft.world.level.block.Blocks;
|
import net.minecraft.world.level.block.Blocks;
|
||||||
import ru.bclib.blocks.BaseFurnaceBlock;
|
import ru.bclib.blocks.BaseFurnaceBlock;
|
||||||
|
import ru.bclib.recipes.AnvilRecipe;
|
||||||
import ru.betterend.BetterEnd;
|
import ru.betterend.BetterEnd;
|
||||||
import ru.betterend.blocks.basis.EndAnvilBlock;
|
import ru.betterend.blocks.basis.EndAnvilBlock;
|
||||||
import ru.betterend.recipe.builders.AlloyingRecipe;
|
import ru.betterend.recipe.builders.AlloyingRecipe;
|
||||||
import ru.betterend.recipe.builders.AnvilRecipe;
|
|
||||||
import ru.betterend.recipe.builders.InfusionRecipe;
|
import ru.betterend.recipe.builders.InfusionRecipe;
|
||||||
import ru.betterend.registry.EndBlocks;
|
import ru.betterend.registry.EndBlocks;
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
//https://github.com/shedaniel/RoughlyEnoughItems/blob/6.x-1.17/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientPlugin.java
|
//https://github.com/shedaniel/RoughlyEnoughItems/blob/6.x-1.17/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientPlugin.java
|
||||||
public class REIPlugin implements REIClientPlugin {
|
public class REIPlugin implements REIClientPlugin {
|
||||||
public final static ResourceLocation PLUGIN_ID = BetterEnd.makeID("rei_plugin");
|
public final static ResourceLocation PLUGIN_ID = BetterEnd.makeID("rei_plugin");
|
||||||
|
|
|
@ -1,35 +0,0 @@
|
||||||
package ru.betterend.interfaces;
|
|
||||||
|
|
||||||
import ru.betterend.recipe.builders.AnvilRecipe;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public interface AnvilScreenHandlerExtended {
|
|
||||||
void be_updateCurrentRecipe(AnvilRecipe recipe);
|
|
||||||
|
|
||||||
AnvilRecipe be_getCurrentRecipe();
|
|
||||||
|
|
||||||
List<AnvilRecipe> be_getRecipes();
|
|
||||||
|
|
||||||
default void be_nextRecipe() {
|
|
||||||
List<AnvilRecipe> recipes = be_getRecipes();
|
|
||||||
if (recipes.size() < 2) return;
|
|
||||||
AnvilRecipe current = be_getCurrentRecipe();
|
|
||||||
int i = recipes.indexOf(current) + 1;
|
|
||||||
if (i >= recipes.size()) {
|
|
||||||
i = 0;
|
|
||||||
}
|
|
||||||
be_updateCurrentRecipe(recipes.get(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
default void be_previousRecipe() {
|
|
||||||
List<AnvilRecipe> recipes = be_getRecipes();
|
|
||||||
if (recipes.size() < 2) return;
|
|
||||||
AnvilRecipe current = be_getCurrentRecipe();
|
|
||||||
int i = recipes.indexOf(current) - 1;
|
|
||||||
if (i <= 0) {
|
|
||||||
i = recipes.size() - 1;
|
|
||||||
}
|
|
||||||
be_updateCurrentRecipe(recipes.get(i));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,3 +0,0 @@
|
||||||
package ru.betterend.interfaces;
|
|
||||||
|
|
||||||
public interface BetterEndRecipe {}
|
|
|
@ -1,95 +0,0 @@
|
||||||
package ru.betterend.mixin.client;
|
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
|
||||||
import net.minecraft.client.gui.components.AbstractWidget;
|
|
||||||
import net.minecraft.client.gui.components.Button;
|
|
||||||
import net.minecraft.client.gui.components.EditBox;
|
|
||||||
import net.minecraft.client.gui.screens.inventory.AnvilScreen;
|
|
||||||
import net.minecraft.client.gui.screens.inventory.ItemCombinerScreen;
|
|
||||||
import net.minecraft.network.chat.Component;
|
|
||||||
import net.minecraft.network.chat.TextComponent;
|
|
||||||
import net.minecraft.resources.ResourceLocation;
|
|
||||||
import net.minecraft.world.entity.player.Inventory;
|
|
||||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
|
||||||
import net.minecraft.world.inventory.AnvilMenu;
|
|
||||||
import net.minecraft.world.item.ItemStack;
|
|
||||||
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 ru.betterend.interfaces.AnvilScreenHandlerExtended;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Mixin(AnvilScreen.class)
|
|
||||||
public class AnvilScreenMixin extends ItemCombinerScreen<AnvilMenu> {
|
|
||||||
|
|
||||||
@Shadow
|
|
||||||
private EditBox name;
|
|
||||||
|
|
||||||
private final List<AbstractWidget> be_buttons = Lists.newArrayList();
|
|
||||||
|
|
||||||
public AnvilScreenMixin(AnvilMenu handler, Inventory playerInventory, Component title, ResourceLocation texture) {
|
|
||||||
super(handler, playerInventory, title, texture);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(method = "subInit", at = @At("TAIL"))
|
|
||||||
protected void be_subInit(CallbackInfo info) {
|
|
||||||
int x = (width - imageWidth) / 2;
|
|
||||||
int y = (height - imageHeight) / 2;
|
|
||||||
be_buttons.clear();
|
|
||||||
be_buttons.add(new Button(x + 8, y + 45, 15, 20, new TextComponent("<"), b -> be_previousRecipe()));
|
|
||||||
be_buttons.add(new Button(x + 154, y + 45, 15, 20, new TextComponent(">"), b -> be_nextRecipe()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(method = "renderFg", at = @At("TAIL"))
|
|
||||||
protected void be_renderForeground(PoseStack matrices, int mouseX, int mouseY, float delta, CallbackInfo info) {
|
|
||||||
be_buttons.forEach(button -> {
|
|
||||||
button.render(matrices, mouseX, mouseY, delta);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(method = "slotChanged", at = @At("HEAD"), cancellable = true)
|
|
||||||
public void be_onSlotUpdate(AbstractContainerMenu handler, int slotId, ItemStack stack, CallbackInfo info) {
|
|
||||||
AnvilScreenHandlerExtended anvilHandler = (AnvilScreenHandlerExtended) handler;
|
|
||||||
if (anvilHandler.be_getCurrentRecipe() != null) {
|
|
||||||
if (anvilHandler.be_getRecipes().size() > 1) {
|
|
||||||
be_buttons.forEach(button -> button.visible = true);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
be_buttons.forEach(button -> button.visible = false);
|
|
||||||
}
|
|
||||||
name.setValue("");
|
|
||||||
info.cancel();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
be_buttons.forEach(button -> button.visible = false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void be_nextRecipe() {
|
|
||||||
((AnvilScreenHandlerExtended) menu).be_nextRecipe();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void be_previousRecipe() {
|
|
||||||
((AnvilScreenHandlerExtended) menu).be_previousRecipe();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean mouseClicked(double mouseX, double mouseY, int button) {
|
|
||||||
if (minecraft != null) {
|
|
||||||
for (AbstractWidget elem : be_buttons) {
|
|
||||||
if (elem.visible && elem.mouseClicked(mouseX, mouseY, button)) {
|
|
||||||
if (minecraft.gameMode != null) {
|
|
||||||
int i = be_buttons.indexOf(elem);
|
|
||||||
minecraft.gameMode.handleInventoryButtonClick(menu.containerId, i);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return super.mouseClicked(mouseX, mouseY, button);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,20 +0,0 @@
|
||||||
package ru.betterend.mixin.client;
|
|
||||||
|
|
||||||
import net.minecraft.client.ClientRecipeBook;
|
|
||||||
import net.minecraft.client.RecipeBookCategories;
|
|
||||||
import net.minecraft.world.item.crafting.Recipe;
|
|
||||||
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 ru.betterend.interfaces.BetterEndRecipe;
|
|
||||||
|
|
||||||
@Mixin(ClientRecipeBook.class)
|
|
||||||
public abstract class ClientRecipeBookMixin {
|
|
||||||
@Inject(method = "getCategory", at = @At("HEAD"), cancellable = true)
|
|
||||||
private static void be_getGroupForRecipe(Recipe<?> recipe, CallbackInfoReturnable<RecipeBookCategories> info) {
|
|
||||||
if (recipe instanceof BetterEndRecipe) {
|
|
||||||
info.setReturnValue(RecipeBookCategories.UNKNOWN);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,159 +0,0 @@
|
||||||
package ru.betterend.mixin.common;
|
|
||||||
|
|
||||||
import net.minecraft.tags.BlockTags;
|
|
||||||
import net.minecraft.world.entity.player.Inventory;
|
|
||||||
import net.minecraft.world.entity.player.Player;
|
|
||||||
import net.minecraft.world.inventory.AnvilMenu;
|
|
||||||
import net.minecraft.world.inventory.ContainerLevelAccess;
|
|
||||||
import net.minecraft.world.inventory.DataSlot;
|
|
||||||
import net.minecraft.world.inventory.ItemCombinerMenu;
|
|
||||||
import net.minecraft.world.inventory.MenuType;
|
|
||||||
import net.minecraft.world.item.ItemStack;
|
|
||||||
import net.minecraft.world.item.crafting.RecipeManager;
|
|
||||||
import net.minecraft.world.level.block.Block;
|
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
|
||||||
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 org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
|
||||||
import ru.bclib.blocks.BaseAnvilBlock;
|
|
||||||
import ru.betterend.blocks.basis.EndAnvilBlock;
|
|
||||||
import ru.betterend.interfaces.AnvilScreenHandlerExtended;
|
|
||||||
import ru.betterend.recipe.builders.AnvilRecipe;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
@Mixin(AnvilMenu.class)
|
|
||||||
public abstract class AnvilMenuMixin extends ItemCombinerMenu implements AnvilScreenHandlerExtended {
|
|
||||||
private List<AnvilRecipe> be_recipes = Collections.emptyList();
|
|
||||||
private AnvilRecipe be_currentRecipe;
|
|
||||||
private DataSlot anvilLevel;
|
|
||||||
|
|
||||||
public AnvilMenuMixin(int syncId, Inventory playerInventory) {
|
|
||||||
super(MenuType.ANVIL, syncId, playerInventory, ContainerLevelAccess.NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(method = "<init>(ILnet/minecraft/world/entity/player/Inventory;Lnet/minecraft/world/inventory/ContainerLevelAccess;)V", at = @At("TAIL"))
|
|
||||||
public void be_initAnvilLevel(int syncId, Inventory inventory, ContainerLevelAccess context, CallbackInfo info) {
|
|
||||||
this.anvilLevel = addDataSlot(DataSlot.standalone());
|
|
||||||
if (context != ContainerLevelAccess.NULL) {
|
|
||||||
int level = context.evaluate((world, blockPos) -> {
|
|
||||||
Block anvilBlock = world.getBlockState(blockPos).getBlock();
|
|
||||||
if (anvilBlock instanceof EndAnvilBlock) {
|
|
||||||
return ((EndAnvilBlock) anvilBlock).getCraftingLevel();
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}, 1);
|
|
||||||
anvilLevel.set(level);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
anvilLevel.set(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Shadow
|
|
||||||
public abstract void createResult();
|
|
||||||
|
|
||||||
@Inject(method = "mayPickup", at = @At("HEAD"), cancellable = true)
|
|
||||||
protected void be_canTakeOutput(Player player, boolean present, CallbackInfoReturnable<Boolean> info) {
|
|
||||||
if (be_currentRecipe != null) {
|
|
||||||
info.setReturnValue(be_currentRecipe.checkHammerDurability(inputSlots, player));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(method = "onTake", at = @At("HEAD"), cancellable = true)
|
|
||||||
protected void be_onTakeOutput(Player player, ItemStack stack, CallbackInfo info) {
|
|
||||||
if (be_currentRecipe != null) {
|
|
||||||
inputSlots.getItem(0).shrink(be_currentRecipe.getInputCount());
|
|
||||||
stack = be_currentRecipe.craft(inputSlots, player);
|
|
||||||
slotsChanged(inputSlots);
|
|
||||||
access.execute((world, blockPos) -> {
|
|
||||||
BlockState anvilState = world.getBlockState(blockPos);
|
|
||||||
BaseAnvilBlock anvil = (BaseAnvilBlock) anvilState.getBlock();
|
|
||||||
if (!player.getAbilities().instabuild && anvilState.is(BlockTags.ANVIL) && player.getRandom().nextDouble() < 0.1) {
|
|
||||||
BlockState damagedState = anvil.damageAnvilUse(anvilState, player.getRandom());
|
|
||||||
if (damagedState == null) {
|
|
||||||
world.removeBlock(blockPos, false);
|
|
||||||
world.levelEvent(1029, blockPos, 0);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
world.setBlock(blockPos, damagedState, 2);
|
|
||||||
world.levelEvent(1030, blockPos, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
world.levelEvent(1030, blockPos, 0);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
info.cancel();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(method = "createResult", at = @At("HEAD"), cancellable = true)
|
|
||||||
public void be_updateOutput(CallbackInfo info) {
|
|
||||||
RecipeManager recipeManager = this.player.level.getRecipeManager();
|
|
||||||
be_recipes = recipeManager.getRecipesFor(AnvilRecipe.TYPE, inputSlots, player.level);
|
|
||||||
if (be_recipes.size() > 0) {
|
|
||||||
int anvilLevel = this.anvilLevel.get();
|
|
||||||
be_recipes = be_recipes.stream()
|
|
||||||
.filter(recipe -> anvilLevel >= recipe.getAnvilLevel())
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
if (be_recipes.size() > 0) {
|
|
||||||
if (be_currentRecipe == null || !be_recipes.contains(be_currentRecipe)) {
|
|
||||||
be_currentRecipe = be_recipes.get(0);
|
|
||||||
}
|
|
||||||
be_updateResult();
|
|
||||||
info.cancel();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
be_currentRecipe = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(method = "setItemName", at = @At("HEAD"), cancellable = true)
|
|
||||||
public void be_setNewItemName(String string, CallbackInfo info) {
|
|
||||||
if (be_currentRecipe != null) {
|
|
||||||
info.cancel();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean clickMenuButton(Player player, int id) {
|
|
||||||
if (id == 0) {
|
|
||||||
be_previousRecipe();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else if (id == 1) {
|
|
||||||
be_nextRecipe();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return super.clickMenuButton(player, id);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void be_updateResult() {
|
|
||||||
if (be_currentRecipe == null) return;
|
|
||||||
resultSlots.setItem(0, be_currentRecipe.assemble(inputSlots));
|
|
||||||
broadcastChanges();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void be_updateCurrentRecipe(AnvilRecipe recipe) {
|
|
||||||
this.be_currentRecipe = recipe;
|
|
||||||
be_updateResult();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AnvilRecipe be_getCurrentRecipe() {
|
|
||||||
return be_currentRecipe;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<AnvilRecipe> be_getRecipes() {
|
|
||||||
return be_recipes;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,19 +1,22 @@
|
||||||
package ru.betterend.recipe;
|
package ru.betterend.recipe;
|
||||||
|
|
||||||
import net.minecraft.world.item.Items;
|
import net.minecraft.world.item.Items;
|
||||||
|
import ru.bclib.recipes.AnvilRecipe;
|
||||||
|
import ru.betterend.config.Configs;
|
||||||
import ru.betterend.item.material.EndToolMaterial;
|
import ru.betterend.item.material.EndToolMaterial;
|
||||||
import ru.betterend.recipe.builders.AnvilRecipe;
|
|
||||||
import ru.betterend.registry.EndItems;
|
import ru.betterend.registry.EndItems;
|
||||||
|
|
||||||
public class AnvilRecipes {
|
public class AnvilRecipes {
|
||||||
public static void register() {
|
public static void register() {
|
||||||
AnvilRecipe.Builder.create("ender_pearl_to_dust")
|
AnvilRecipe.create("ender_pearl_to_dust")
|
||||||
|
.checkConfig(Configs.RECIPE_CONFIG)
|
||||||
.setInput(Items.ENDER_PEARL)
|
.setInput(Items.ENDER_PEARL)
|
||||||
.setOutput(EndItems.ENDER_DUST)
|
.setOutput(EndItems.ENDER_DUST)
|
||||||
.setToolLevel(4)
|
.setToolLevel(4)
|
||||||
.setDamage(5)
|
.setDamage(5)
|
||||||
.build();
|
.build();
|
||||||
AnvilRecipe.Builder.create("ender_shard_to_dust")
|
AnvilRecipe.create("ender_shard_to_dust")
|
||||||
|
.checkConfig(Configs.RECIPE_CONFIG)
|
||||||
.setInput(EndItems.ENDER_SHARD)
|
.setInput(EndItems.ENDER_SHARD)
|
||||||
.setOutput(EndItems.ENDER_DUST)
|
.setOutput(EndItems.ENDER_DUST)
|
||||||
.setToolLevel(0)
|
.setToolLevel(0)
|
||||||
|
@ -21,49 +24,56 @@ public class AnvilRecipes {
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
int anvilLevel = EndToolMaterial.AETERNIUM.getLevel();
|
int anvilLevel = EndToolMaterial.AETERNIUM.getLevel();
|
||||||
AnvilRecipe.Builder.create("aeternium_axe_head")
|
AnvilRecipe.create("aeternium_axe_head")
|
||||||
|
.checkConfig(Configs.RECIPE_CONFIG)
|
||||||
.setInput(EndItems.AETERNIUM_INGOT)
|
.setInput(EndItems.AETERNIUM_INGOT)
|
||||||
.setOutput(EndItems.AETERNIUM_AXE_HEAD)
|
.setOutput(EndItems.AETERNIUM_AXE_HEAD)
|
||||||
.setAnvilLevel(anvilLevel)
|
.setAnvilLevel(anvilLevel)
|
||||||
.setToolLevel(anvilLevel)
|
.setToolLevel(anvilLevel)
|
||||||
.setDamage(6)
|
.setDamage(6)
|
||||||
.build();
|
.build();
|
||||||
AnvilRecipe.Builder.create("aeternium_pickaxe_head")
|
AnvilRecipe.create("aeternium_pickaxe_head")
|
||||||
|
.checkConfig(Configs.RECIPE_CONFIG)
|
||||||
.setInput(EndItems.AETERNIUM_INGOT)
|
.setInput(EndItems.AETERNIUM_INGOT)
|
||||||
.setOutput(EndItems.AETERNIUM_PICKAXE_HEAD)
|
.setOutput(EndItems.AETERNIUM_PICKAXE_HEAD)
|
||||||
.setAnvilLevel(anvilLevel)
|
.setAnvilLevel(anvilLevel)
|
||||||
.setToolLevel(anvilLevel)
|
.setToolLevel(anvilLevel)
|
||||||
.setDamage(6)
|
.setDamage(6)
|
||||||
.build();
|
.build();
|
||||||
AnvilRecipe.Builder.create("aeternium_shovel_head")
|
AnvilRecipe.create("aeternium_shovel_head")
|
||||||
|
.checkConfig(Configs.RECIPE_CONFIG)
|
||||||
.setInput(EndItems.AETERNIUM_INGOT)
|
.setInput(EndItems.AETERNIUM_INGOT)
|
||||||
.setOutput(EndItems.AETERNIUM_SHOVEL_HEAD)
|
.setOutput(EndItems.AETERNIUM_SHOVEL_HEAD)
|
||||||
.setAnvilLevel(anvilLevel)
|
.setAnvilLevel(anvilLevel)
|
||||||
.setToolLevel(anvilLevel)
|
.setToolLevel(anvilLevel)
|
||||||
.setDamage(6)
|
.setDamage(6)
|
||||||
.build();
|
.build();
|
||||||
AnvilRecipe.Builder.create("aeternium_hoe_head")
|
AnvilRecipe.create("aeternium_hoe_head")
|
||||||
|
.checkConfig(Configs.RECIPE_CONFIG)
|
||||||
.setInput(EndItems.AETERNIUM_INGOT)
|
.setInput(EndItems.AETERNIUM_INGOT)
|
||||||
.setOutput(EndItems.AETERNIUM_HOE_HEAD)
|
.setOutput(EndItems.AETERNIUM_HOE_HEAD)
|
||||||
.setAnvilLevel(anvilLevel)
|
.setAnvilLevel(anvilLevel)
|
||||||
.setToolLevel(anvilLevel)
|
.setToolLevel(anvilLevel)
|
||||||
.setDamage(6)
|
.setDamage(6)
|
||||||
.build();
|
.build();
|
||||||
AnvilRecipe.Builder.create("aeternium_hammer_head")
|
AnvilRecipe.create("aeternium_hammer_head")
|
||||||
|
.checkConfig(Configs.RECIPE_CONFIG)
|
||||||
.setInput(EndItems.AETERNIUM_INGOT)
|
.setInput(EndItems.AETERNIUM_INGOT)
|
||||||
.setOutput(EndItems.AETERNIUM_HAMMER_HEAD)
|
.setOutput(EndItems.AETERNIUM_HAMMER_HEAD)
|
||||||
.setAnvilLevel(anvilLevel)
|
.setAnvilLevel(anvilLevel)
|
||||||
.setToolLevel(EndToolMaterial.THALLASIUM.getLevel())
|
.setToolLevel(EndToolMaterial.THALLASIUM.getLevel())
|
||||||
.setDamage(6)
|
.setDamage(6)
|
||||||
.build();
|
.build();
|
||||||
AnvilRecipe.Builder.create("aeternium_sword_blade")
|
AnvilRecipe.create("aeternium_sword_blade")
|
||||||
|
.checkConfig(Configs.RECIPE_CONFIG)
|
||||||
.setInput(EndItems.AETERNIUM_INGOT)
|
.setInput(EndItems.AETERNIUM_INGOT)
|
||||||
.setOutput(EndItems.AETERNIUM_SWORD_BLADE)
|
.setOutput(EndItems.AETERNIUM_SWORD_BLADE)
|
||||||
.setAnvilLevel(anvilLevel)
|
.setAnvilLevel(anvilLevel)
|
||||||
.setToolLevel(anvilLevel)
|
.setToolLevel(anvilLevel)
|
||||||
.setDamage(6)
|
.setDamage(6)
|
||||||
.build();
|
.build();
|
||||||
AnvilRecipe.Builder.create("aeternium_forged_plate")
|
AnvilRecipe.create("aeternium_forged_plate")
|
||||||
|
.checkConfig(Configs.RECIPE_CONFIG)
|
||||||
.setInput(EndItems.AETERNIUM_INGOT)
|
.setInput(EndItems.AETERNIUM_INGOT)
|
||||||
.setOutput(EndItems.AETERNIUM_FORGED_PLATE)
|
.setOutput(EndItems.AETERNIUM_FORGED_PLATE)
|
||||||
.setAnvilLevel(anvilLevel)
|
.setAnvilLevel(anvilLevel)
|
||||||
|
|
|
@ -18,15 +18,15 @@ import net.minecraft.world.item.crafting.RecipeSerializer;
|
||||||
import net.minecraft.world.item.crafting.RecipeType;
|
import net.minecraft.world.item.crafting.RecipeType;
|
||||||
import net.minecraft.world.level.ItemLike;
|
import net.minecraft.world.level.ItemLike;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
|
import ru.bclib.interfaces.UnknownReceipBookCategory;
|
||||||
import ru.bclib.recipes.BCLRecipeManager;
|
import ru.bclib.recipes.BCLRecipeManager;
|
||||||
import ru.betterend.BetterEnd;
|
import ru.betterend.BetterEnd;
|
||||||
import ru.betterend.config.Configs;
|
import ru.betterend.config.Configs;
|
||||||
import ru.betterend.interfaces.BetterEndRecipe;
|
|
||||||
import ru.betterend.registry.EndBlocks;
|
import ru.betterend.registry.EndBlocks;
|
||||||
import ru.betterend.util.ItemUtil;
|
import ru.bclib.util.ItemUtil;
|
||||||
import ru.betterend.util.RecipeHelper;
|
import ru.bclib.util.RecipeHelper;
|
||||||
|
|
||||||
public class AlloyingRecipe implements Recipe<Container>, BetterEndRecipe {
|
public class AlloyingRecipe implements Recipe<Container>, UnknownReceipBookCategory {
|
||||||
public final static String GROUP = "alloying";
|
public final static String GROUP = "alloying";
|
||||||
public final static RecipeType<AlloyingRecipe> TYPE = BCLRecipeManager.registerType(BetterEnd.MOD_ID, GROUP);
|
public final static RecipeType<AlloyingRecipe> TYPE = BCLRecipeManager.registerType(BetterEnd.MOD_ID, GROUP);
|
||||||
public final static Serializer SERIALIZER = BCLRecipeManager.registerSerializer(
|
public final static Serializer SERIALIZER = BCLRecipeManager.registerSerializer(
|
||||||
|
|
|
@ -1,329 +0,0 @@
|
||||||
package ru.betterend.recipe.builders;
|
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
|
||||||
import net.fabricmc.api.EnvType;
|
|
||||||
import net.fabricmc.api.Environment;
|
|
||||||
import net.minecraft.core.NonNullList;
|
|
||||||
import net.minecraft.nbt.CompoundTag;
|
|
||||||
import net.minecraft.nbt.TagParser;
|
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
|
||||||
import net.minecraft.resources.ResourceLocation;
|
|
||||||
import net.minecraft.tags.Tag;
|
|
||||||
import net.minecraft.util.GsonHelper;
|
|
||||||
import net.minecraft.world.Container;
|
|
||||||
import net.minecraft.world.InteractionHand;
|
|
||||||
import net.minecraft.world.entity.player.Player;
|
|
||||||
import net.minecraft.world.item.Item;
|
|
||||||
import net.minecraft.world.item.ItemStack;
|
|
||||||
import net.minecraft.world.item.TieredItem;
|
|
||||||
import net.minecraft.world.item.crafting.Ingredient;
|
|
||||||
import net.minecraft.world.item.crafting.Recipe;
|
|
||||||
import net.minecraft.world.item.crafting.RecipeSerializer;
|
|
||||||
import net.minecraft.world.item.crafting.RecipeType;
|
|
||||||
import net.minecraft.world.level.ItemLike;
|
|
||||||
import net.minecraft.world.level.Level;
|
|
||||||
import ru.bclib.api.TagAPI;
|
|
||||||
import ru.bclib.recipes.BCLRecipeManager;
|
|
||||||
import ru.betterend.BetterEnd;
|
|
||||||
import ru.betterend.config.Configs;
|
|
||||||
import ru.betterend.interfaces.BetterEndRecipe;
|
|
||||||
import ru.betterend.util.ItemUtil;
|
|
||||||
import ru.betterend.util.RecipeHelper;
|
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
public class AnvilRecipe implements Recipe<Container>, BetterEndRecipe {
|
|
||||||
public final static String GROUP = "smithing";
|
|
||||||
public final static RecipeType<AnvilRecipe> TYPE = BCLRecipeManager.registerType(BetterEnd.MOD_ID, GROUP);
|
|
||||||
public final static Serializer SERIALIZER = BCLRecipeManager.registerSerializer(
|
|
||||||
BetterEnd.MOD_ID,
|
|
||||||
GROUP,
|
|
||||||
new Serializer()
|
|
||||||
);
|
|
||||||
public final static ResourceLocation ID = BetterEnd.makeID(GROUP);
|
|
||||||
|
|
||||||
private final ResourceLocation id;
|
|
||||||
private final Ingredient input;
|
|
||||||
private final ItemStack output;
|
|
||||||
private final int damage;
|
|
||||||
private final int toolLevel;
|
|
||||||
private final int anvilLevel;
|
|
||||||
private final int inputCount;
|
|
||||||
|
|
||||||
public AnvilRecipe(ResourceLocation identifier, Ingredient input, ItemStack output, int inputCount, int toolLevel, int anvilLevel, int damage) {
|
|
||||||
this.id = identifier;
|
|
||||||
this.input = input;
|
|
||||||
this.output = output;
|
|
||||||
this.toolLevel = toolLevel;
|
|
||||||
this.anvilLevel = anvilLevel;
|
|
||||||
this.inputCount = inputCount;
|
|
||||||
this.damage = damage;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public RecipeSerializer<?> getSerializer() {
|
|
||||||
return SERIALIZER;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ItemStack getResultItem() {
|
|
||||||
return this.output;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean matches(Container craftingInventory, Level world) {
|
|
||||||
return this.matches(craftingInventory);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ItemStack assemble(Container craftingInventory) {
|
|
||||||
return this.output.copy();
|
|
||||||
}
|
|
||||||
|
|
||||||
public ItemStack craft(Container craftingInventory, Player player) {
|
|
||||||
if (!player.isCreative()) {
|
|
||||||
if (!checkHammerDurability(craftingInventory, player)) return ItemStack.EMPTY;
|
|
||||||
ItemStack hammer = craftingInventory.getItem(1);
|
|
||||||
hammer.hurtAndBreak(this.damage, player, entity -> entity.broadcastBreakEvent((InteractionHand) null));
|
|
||||||
}
|
|
||||||
return this.assemble(craftingInventory);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean checkHammerDurability(Container craftingInventory, Player player) {
|
|
||||||
if (player.isCreative()) return true;
|
|
||||||
ItemStack hammer = craftingInventory.getItem(1);
|
|
||||||
int damage = hammer.getDamageValue() + this.damage;
|
|
||||||
return damage < hammer.getMaxDamage();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean matches(Container craftingInventory) {
|
|
||||||
ItemStack hammer = craftingInventory.getItem(1);
|
|
||||||
if (hammer.isEmpty() || !TagAPI.ITEM_HAMMERS.contains(hammer.getItem())) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
ItemStack material = craftingInventory.getItem(0);
|
|
||||||
int materialCount = material.getCount();
|
|
||||||
int level = ((TieredItem) hammer.getItem()).getTier().getLevel();
|
|
||||||
return this.input.test(craftingInventory.getItem(0)) && materialCount >= this.inputCount && level >= this.toolLevel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getDamage() {
|
|
||||||
return this.damage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getInputCount() {
|
|
||||||
return this.inputCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getAnvilLevel() {
|
|
||||||
return this.anvilLevel;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public NonNullList<Ingredient> getIngredients() {
|
|
||||||
NonNullList<Ingredient> defaultedList = NonNullList.create();
|
|
||||||
defaultedList.add(Ingredient.of(TagAPI.ITEM_HAMMERS.getValues()
|
|
||||||
.stream()
|
|
||||||
.filter(hammer -> ((TieredItem) hammer).getTier()
|
|
||||||
.getLevel() >= toolLevel)
|
|
||||||
.map(ItemStack::new)));
|
|
||||||
defaultedList.add(input);
|
|
||||||
|
|
||||||
return defaultedList;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Environment(EnvType.CLIENT)
|
|
||||||
public boolean canCraftInDimensions(int width, int height) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ResourceLocation getId() {
|
|
||||||
return this.id;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public RecipeType<?> getType() {
|
|
||||||
return TYPE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isSpecial() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
|
||||||
AnvilRecipe that = (AnvilRecipe) o;
|
|
||||||
return damage == that.damage && toolLevel == that.toolLevel && id.equals(that.id) && input.equals(that.input) && output
|
|
||||||
.equals(that.output);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hash(id, input, output, damage, toolLevel);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "AnvilRecipe [" + id + "]";
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Builder {
|
|
||||||
private final static Builder INSTANCE = new Builder();
|
|
||||||
|
|
||||||
public static Builder create(String id) {
|
|
||||||
return create(BetterEnd.makeID(id));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Builder create(ResourceLocation id) {
|
|
||||||
INSTANCE.id = id;
|
|
||||||
INSTANCE.input = null;
|
|
||||||
INSTANCE.output = null;
|
|
||||||
INSTANCE.inputCount = 1;
|
|
||||||
INSTANCE.toolLevel = 1;
|
|
||||||
INSTANCE.anvilLevel = 1;
|
|
||||||
INSTANCE.damage = 1;
|
|
||||||
INSTANCE.alright = true;
|
|
||||||
|
|
||||||
return INSTANCE;
|
|
||||||
}
|
|
||||||
|
|
||||||
private ResourceLocation id;
|
|
||||||
private Ingredient input;
|
|
||||||
private ItemStack output;
|
|
||||||
private int inputCount = 1;
|
|
||||||
private int toolLevel = 1;
|
|
||||||
private int anvilLevel = 1;
|
|
||||||
private int damage = 1;
|
|
||||||
private boolean alright;
|
|
||||||
|
|
||||||
private Builder() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setInput(ItemLike... inputItems) {
|
|
||||||
this.alright &= RecipeHelper.exists(inputItems);
|
|
||||||
this.setInput(Ingredient.of(inputItems));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setInput(Tag<Item> inputTag) {
|
|
||||||
this.setInput(Ingredient.of(inputTag));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setInput(Ingredient ingredient) {
|
|
||||||
this.input = ingredient;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setInputCount(int count) {
|
|
||||||
this.inputCount = count;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setOutput(ItemLike output) {
|
|
||||||
return this.setOutput(output, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setOutput(ItemLike output, int amount) {
|
|
||||||
this.alright &= RecipeHelper.exists(output);
|
|
||||||
this.output = new ItemStack(output, amount);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setToolLevel(int level) {
|
|
||||||
this.toolLevel = level;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setAnvilLevel(int level) {
|
|
||||||
this.anvilLevel = level;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setDamage(int damage) {
|
|
||||||
this.damage = damage;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void build() {
|
|
||||||
if (Configs.RECIPE_CONFIG.getBoolean("anvil", id.getPath(), true)) {
|
|
||||||
if (input == null) {
|
|
||||||
BetterEnd.LOGGER.warning("Input for Anvil recipe can't be 'null', recipe {} will be ignored!", id);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (output == null) {
|
|
||||||
BetterEnd.LOGGER.warning("Output for Anvil recipe can't be 'null', recipe {} will be ignored!", id);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (BCLRecipeManager.getRecipe(TYPE, id) != null) {
|
|
||||||
BetterEnd.LOGGER.warning("Can't add Anvil recipe! Id {} already exists!", id);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!alright) {
|
|
||||||
BetterEnd.LOGGER.debug("Can't add Anvil recipe {}! Ingeredient or output not exists.", id);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
BCLRecipeManager.addRecipe(
|
|
||||||
TYPE,
|
|
||||||
new AnvilRecipe(id, input, output, inputCount, toolLevel, anvilLevel, damage)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Serializer implements RecipeSerializer<AnvilRecipe> {
|
|
||||||
@Override
|
|
||||||
public AnvilRecipe fromJson(ResourceLocation id, JsonObject json) {
|
|
||||||
Ingredient input = Ingredient.fromJson(json.get("input"));
|
|
||||||
JsonObject result = GsonHelper.getAsJsonObject(json, "result");
|
|
||||||
ItemStack output = ItemUtil.fromJsonRecipe(result);
|
|
||||||
if (output == null) {
|
|
||||||
throw new IllegalStateException("Output item does not exists!");
|
|
||||||
}
|
|
||||||
if (result.has("nbt")) {
|
|
||||||
try {
|
|
||||||
String nbtData = GsonHelper.getAsString(result, "nbt");
|
|
||||||
CompoundTag nbt = TagParser.parseTag(nbtData);
|
|
||||||
output.setTag(nbt);
|
|
||||||
}
|
|
||||||
catch (CommandSyntaxException ex) {
|
|
||||||
BetterEnd.LOGGER.warning("Error parse nbt data for output.", ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
int inputCount = GsonHelper.getAsInt(json, "inputCount", 1);
|
|
||||||
int toolLevel = GsonHelper.getAsInt(json, "toolLevel", 1);
|
|
||||||
int anvilLevel = GsonHelper.getAsInt(json, "anvilLevel", 1);
|
|
||||||
int damage = GsonHelper.getAsInt(json, "damage", 1);
|
|
||||||
|
|
||||||
return new AnvilRecipe(id, input, output, inputCount, toolLevel, anvilLevel, damage);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AnvilRecipe fromNetwork(ResourceLocation id, FriendlyByteBuf packetBuffer) {
|
|
||||||
Ingredient input = Ingredient.fromNetwork(packetBuffer);
|
|
||||||
ItemStack output = packetBuffer.readItem();
|
|
||||||
int inputCount = packetBuffer.readVarInt();
|
|
||||||
int toolLevel = packetBuffer.readVarInt();
|
|
||||||
int anvilLevel = packetBuffer.readVarInt();
|
|
||||||
int damage = packetBuffer.readVarInt();
|
|
||||||
|
|
||||||
return new AnvilRecipe(id, input, output, inputCount, toolLevel, anvilLevel, damage);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void toNetwork(FriendlyByteBuf packetBuffer, AnvilRecipe recipe) {
|
|
||||||
recipe.input.toNetwork(packetBuffer);
|
|
||||||
packetBuffer.writeItem(recipe.output);
|
|
||||||
packetBuffer.writeVarInt(recipe.inputCount);
|
|
||||||
packetBuffer.writeVarInt(recipe.toolLevel);
|
|
||||||
packetBuffer.writeVarInt(recipe.anvilLevel);
|
|
||||||
packetBuffer.writeVarInt(recipe.damage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,6 +1,9 @@
|
||||||
package ru.betterend.recipe.builders;
|
package ru.betterend.recipe.builders;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
|
|
||||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
import net.fabricmc.api.EnvType;
|
import net.fabricmc.api.EnvType;
|
||||||
import net.fabricmc.api.Environment;
|
import net.fabricmc.api.Environment;
|
||||||
|
@ -17,16 +20,14 @@ import net.minecraft.world.item.crafting.RecipeSerializer;
|
||||||
import net.minecraft.world.item.crafting.RecipeType;
|
import net.minecraft.world.item.crafting.RecipeType;
|
||||||
import net.minecraft.world.level.ItemLike;
|
import net.minecraft.world.level.ItemLike;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
|
import ru.bclib.interfaces.UnknownReceipBookCategory;
|
||||||
import ru.bclib.recipes.BCLRecipeManager;
|
import ru.bclib.recipes.BCLRecipeManager;
|
||||||
|
import ru.bclib.util.ItemUtil;
|
||||||
import ru.betterend.BetterEnd;
|
import ru.betterend.BetterEnd;
|
||||||
import ru.betterend.config.Configs;
|
import ru.betterend.config.Configs;
|
||||||
import ru.betterend.interfaces.BetterEndRecipe;
|
|
||||||
import ru.betterend.rituals.InfusionRitual;
|
import ru.betterend.rituals.InfusionRitual;
|
||||||
import ru.betterend.util.ItemUtil;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
public class InfusionRecipe implements Recipe<InfusionRitual>, UnknownReceipBookCategory {
|
||||||
|
|
||||||
public class InfusionRecipe implements Recipe<InfusionRitual>, BetterEndRecipe {
|
|
||||||
public final static String GROUP = "infusion";
|
public final static String GROUP = "infusion";
|
||||||
public final static RecipeType<InfusionRecipe> TYPE = BCLRecipeManager.registerType(BetterEnd.MOD_ID, GROUP);
|
public final static RecipeType<InfusionRecipe> TYPE = BCLRecipeManager.registerType(BetterEnd.MOD_ID, GROUP);
|
||||||
public final static Serializer SERIALIZER = BCLRecipeManager.registerSerializer(
|
public final static Serializer SERIALIZER = BCLRecipeManager.registerSerializer(
|
||||||
|
|
|
@ -1,74 +0,0 @@
|
||||||
package ru.betterend.util;
|
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import net.minecraft.core.Registry;
|
|
||||||
import net.minecraft.resources.ResourceLocation;
|
|
||||||
import net.minecraft.util.GsonHelper;
|
|
||||||
import net.minecraft.world.item.Item;
|
|
||||||
import net.minecraft.world.item.ItemStack;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
import ru.betterend.BetterEnd;
|
|
||||||
|
|
||||||
public class ItemUtil {
|
|
||||||
|
|
||||||
public static String toStackString(@NotNull ItemStack stack) {
|
|
||||||
try {
|
|
||||||
if (stack == null) {
|
|
||||||
throw new IllegalStateException("Stack can't be null!");
|
|
||||||
}
|
|
||||||
Item item = stack.getItem();
|
|
||||||
return Registry.ITEM.getKey(item) + ":" + stack.getCount();
|
|
||||||
}
|
|
||||||
catch (Exception ex) {
|
|
||||||
BetterEnd.LOGGER.error("ItemStack serialization error!", ex);
|
|
||||||
}
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public static ItemStack fromStackString(String stackString) {
|
|
||||||
if (stackString == null || stackString.equals("")) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
String[] parts = stackString.split(":");
|
|
||||||
if (parts.length < 2) return null;
|
|
||||||
if (parts.length == 2) {
|
|
||||||
ResourceLocation itemId = new ResourceLocation(stackString);
|
|
||||||
Item item = Registry.ITEM.getOptional(itemId).orElseThrow(() -> {
|
|
||||||
return new IllegalStateException("Output item " + itemId + " does not exists!");
|
|
||||||
});
|
|
||||||
return new ItemStack(item);
|
|
||||||
}
|
|
||||||
ResourceLocation itemId = new ResourceLocation(parts[0], parts[1]);
|
|
||||||
Item item = Registry.ITEM.getOptional(itemId).orElseThrow(() -> {
|
|
||||||
return new IllegalStateException("Output item " + itemId + " does not exists!");
|
|
||||||
});
|
|
||||||
return new ItemStack(item, Integer.valueOf(parts[2]));
|
|
||||||
}
|
|
||||||
catch (Exception ex) {
|
|
||||||
BetterEnd.LOGGER.error("ItemStack deserialization error!", ex);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public static ItemStack fromJsonRecipe(JsonObject recipe) {
|
|
||||||
try {
|
|
||||||
if (!recipe.has("item")) {
|
|
||||||
throw new IllegalStateException("Invalid JsonObject. Entry 'item' does not exists!");
|
|
||||||
}
|
|
||||||
ResourceLocation itemId = new ResourceLocation(GsonHelper.getAsString(recipe, "item"));
|
|
||||||
Item item = Registry.ITEM.getOptional(itemId).orElseThrow(() -> {
|
|
||||||
return new IllegalStateException("Output item " + itemId + " does not exists!");
|
|
||||||
});
|
|
||||||
int count = GsonHelper.getAsInt(recipe, "count", 1);
|
|
||||||
return new ItemStack(item, count);
|
|
||||||
}
|
|
||||||
catch (Exception ex) {
|
|
||||||
BetterEnd.LOGGER.error("ItemStack deserialization error!", ex);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,25 +0,0 @@
|
||||||
package ru.betterend.util;
|
|
||||||
|
|
||||||
import net.minecraft.core.Registry;
|
|
||||||
import net.minecraft.world.level.ItemLike;
|
|
||||||
import net.minecraft.world.level.block.Block;
|
|
||||||
|
|
||||||
public class RecipeHelper {
|
|
||||||
public static boolean exists(ItemLike item) {
|
|
||||||
if (item instanceof Block) {
|
|
||||||
return Registry.BLOCK.getKey((Block) item) != Registry.BLOCK.getDefaultKey();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return Registry.ITEM.getKey(item.asItem()) != Registry.ITEM.getDefaultKey();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean exists(ItemLike... items) {
|
|
||||||
for (ItemLike item : items) {
|
|
||||||
if (!exists(item)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -8,12 +8,10 @@
|
||||||
"ClientPlayNetworkHandlerMixin",
|
"ClientPlayNetworkHandlerMixin",
|
||||||
"HumanoidMobRendererMixin",
|
"HumanoidMobRendererMixin",
|
||||||
"ArmorStandRendererMixin",
|
"ArmorStandRendererMixin",
|
||||||
"ClientRecipeBookMixin",
|
|
||||||
"MinecraftClientMixin",
|
"MinecraftClientMixin",
|
||||||
"PlayerRendererMixin",
|
"PlayerRendererMixin",
|
||||||
"LevelRendererMixin",
|
"LevelRendererMixin",
|
||||||
"MusicTrackerMixin",
|
"MusicTrackerMixin",
|
||||||
"AnvilScreenMixin",
|
|
||||||
"BiomeColorsMixin",
|
"BiomeColorsMixin",
|
||||||
"ModelLoaderMixin",
|
"ModelLoaderMixin",
|
||||||
"LocalPlayerMixin",
|
"LocalPlayerMixin",
|
||||||
|
|
|
@ -26,7 +26,6 @@
|
||||||
"ServerPlayerMixin",
|
"ServerPlayerMixin",
|
||||||
"SpikeFeatureMixin",
|
"SpikeFeatureMixin",
|
||||||
"ServerLevelMixin",
|
"ServerLevelMixin",
|
||||||
"AnvilMenuMixin",
|
|
||||||
"EnderManMixin",
|
"EnderManMixin",
|
||||||
"EndSpikeMixin",
|
"EndSpikeMixin",
|
||||||
"MonsterMixin",
|
"MonsterMixin",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue