More REI compat

This commit is contained in:
Aleksey 2020-10-02 17:29:43 +03:00
parent e0cf41db63
commit fbe25dbd85
8 changed files with 107 additions and 76 deletions

View file

@ -23,7 +23,7 @@ import net.minecraft.client.gui.DrawableHelper;
import net.minecraft.client.util.math.MatrixStack; import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.TranslatableText; import net.minecraft.text.TranslatableText;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import ru.betterend.recipe.AlloyingRecipe;
import ru.betterend.registry.BlockRegistry; import ru.betterend.registry.BlockRegistry;
import ru.betterend.util.LangUtil; import ru.betterend.util.LangUtil;
@ -31,7 +31,7 @@ public class REIAlloyingCategory implements TransferRecipeCategory<REIAlloyingDi
@Override @Override
public @NotNull Identifier getIdentifier() { public @NotNull Identifier getIdentifier() {
return REICompat.ALLOYING; return AlloyingRecipe.ID;
} }
@Override @Override
@ -41,7 +41,7 @@ public class REIAlloyingCategory implements TransferRecipeCategory<REIAlloyingDi
@Override @Override
public @NotNull EntryStack getLogo() { public @NotNull EntryStack getLogo() {
return REICompat.END_STONE_SMELTER; return REIPlugin.END_STONE_SMELTER;
} }
@Override @Override
@ -56,8 +56,13 @@ public class REIAlloyingCategory implements TransferRecipeCategory<REIAlloyingDi
widgets.add(Widgets.createLabel(new Point(bounds.x + bounds.width - 5, bounds.y + 5), widgets.add(Widgets.createLabel(new Point(bounds.x + bounds.width - 5, bounds.y + 5),
new TranslatableText("category.rei.cooking.time&xp", df.format(display.getXp()), df.format(smeltTime / 20D))).noShadow().rightAligned().color(0xFF404040, 0xFFBBBBBB)); new TranslatableText("category.rei.cooking.time&xp", df.format(display.getXp()), df.format(smeltTime / 20D))).noShadow().rightAligned().color(0xFF404040, 0xFFBBBBBB));
widgets.add(Widgets.createArrow(new Point(startPoint.x + 24, startPoint.y + 8)).animationDurationTicks(smeltTime)); widgets.add(Widgets.createArrow(new Point(startPoint.x + 24, startPoint.y + 8)).animationDurationTicks(smeltTime));
widgets.add(Widgets.createSlot(new Point(startPoint.x - 20, startPoint.y + 1)).entries(display.getInputEntries().get(0)).markInput()); List<List<EntryStack>> inputEntries = display.getInputEntries();
widgets.add(Widgets.createSlot(new Point(startPoint.x + 1, startPoint.y + 1)).entries(display.getInputEntries().get(1)).markInput()); widgets.add(Widgets.createSlot(new Point(startPoint.x - 20, startPoint.y + 1)).entries(inputEntries.get(0)).markInput());
if (inputEntries.size() > 1) {
widgets.add(Widgets.createSlot(new Point(startPoint.x + 1, startPoint.y + 1)).entries(inputEntries.get(1)).markInput());
} else {
widgets.add(Widgets.createSlot(new Point(startPoint.x + 1, startPoint.y + 1)).entries(Lists.newArrayList()).markInput());
}
widgets.add(Widgets.createSlot(new Point(startPoint.x + 61, startPoint.y + 9)).entries(display.getResultingEntries().get(0)).disableBackground().markOutput()); widgets.add(Widgets.createSlot(new Point(startPoint.x + 61, startPoint.y + 9)).entries(display.getResultingEntries().get(0)).disableBackground().markOutput());
return widgets; return widgets;
} }

View file

@ -12,6 +12,8 @@ import me.shedaniel.rei.api.TransferRecipeDisplay;
import me.shedaniel.rei.server.ContainerInfo; import me.shedaniel.rei.server.ContainerInfo;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.recipe.BlastingRecipe;
import net.minecraft.recipe.Recipe;
import net.minecraft.screen.ScreenHandler; import net.minecraft.screen.ScreenHandler;
import net.minecraft.text.TranslatableText; import net.minecraft.text.TranslatableText;
import net.minecraft.util.Formatting; import net.minecraft.util.Formatting;
@ -24,7 +26,7 @@ public class REIAlloyingDisplay implements TransferRecipeDisplay {
private static List<EntryStack> fuel; private static List<EntryStack> fuel;
private AlloyingRecipe recipe; private Recipe<?> recipe;
private List<List<EntryStack>> input; private List<List<EntryStack>> input;
private List<EntryStack> output; private List<EntryStack> output;
private float xp; private float xp;
@ -38,13 +40,21 @@ public class REIAlloyingDisplay implements TransferRecipeDisplay {
this.smeltTime = recipe.getSmeltTime(); this.smeltTime = recipe.getSmeltTime();
} }
public REIAlloyingDisplay(BlastingRecipe recipe) {
this.recipe = recipe;
this.input = EntryStack.ofIngredients(recipe.getPreviewInputs());
this.output = Collections.singletonList(EntryStack.create(recipe.getOutput()));
this.xp = recipe.getExperience();
this.smeltTime = recipe.getCookTime();
}
public static List<EntryStack> getFuel() { public static List<EntryStack> getFuel() {
return fuel; return fuel;
} }
@Override @Override
public @NotNull Optional<Identifier> getRecipeLocation() { public @NotNull Optional<Identifier> getRecipeLocation() {
return Optional.ofNullable(recipe).map(AlloyingRecipe::getId); return Optional.ofNullable(recipe).map(Recipe::getId);
} }
@Override @Override
@ -59,7 +69,7 @@ public class REIAlloyingDisplay implements TransferRecipeDisplay {
@Override @Override
public @NotNull Identifier getRecipeCategory() { public @NotNull Identifier getRecipeCategory() {
return REICompat.ALLOYING; return AlloyingRecipe.ID;
} }
@Override @Override
@ -75,7 +85,7 @@ public class REIAlloyingDisplay implements TransferRecipeDisplay {
return this.smeltTime; return this.smeltTime;
} }
public Optional<AlloyingRecipe> getOptionalRecipe() { public Optional<Recipe<?>> getOptionalRecipe() {
return Optional.ofNullable(recipe); return Optional.ofNullable(recipe);
} }
@ -90,8 +100,7 @@ public class REIAlloyingDisplay implements TransferRecipeDisplay {
} }
@Override @Override
public List<List<EntryStack>> getOrganisedInputEntries(ContainerInfo<ScreenHandler> containerInfo, public List<List<EntryStack>> getOrganisedInputEntries(ContainerInfo<ScreenHandler> containerInfo, ScreenHandler container) {
ScreenHandler container) {
return input; return input;
} }

View file

@ -0,0 +1,15 @@
package ru.betterend.compat;
import me.shedaniel.rei.plugin.containers.CraftingContainerInfoWrapper;
import me.shedaniel.rei.server.ContainerInfoHandler;
import ru.betterend.client.gui.EndStoneSmelterScreenHandler;
import ru.betterend.recipe.AlloyingRecipe;
public class REIContainer implements Runnable {
@Override
public void run() {
ContainerInfoHandler.registerContainerInfo(AlloyingRecipe.ID, CraftingContainerInfoWrapper.create(EndStoneSmelterScreenHandler.class));
}
}

View file

@ -7,6 +7,7 @@ import me.shedaniel.rei.api.plugins.REIPluginV0;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.minecraft.recipe.BlastingRecipe;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import ru.betterend.BetterEnd; import ru.betterend.BetterEnd;
@ -14,10 +15,9 @@ import ru.betterend.recipe.AlloyingRecipe;
import ru.betterend.registry.BlockRegistry; import ru.betterend.registry.BlockRegistry;
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public class REICompat implements REIPluginV0 { public class REIPlugin implements REIPluginV0 {
public final static Identifier PLUGIN_ID = BetterEnd.getIdentifier("rei_plugin"); public final static Identifier PLUGIN_ID = BetterEnd.getIdentifier("rei_plugin");
public final static Identifier ALLOYING = BetterEnd.getIdentifier("alloying");
public final static EntryStack END_STONE_SMELTER = EntryStack.create(BlockRegistry.END_STONE_SMELTER); public final static EntryStack END_STONE_SMELTER = EntryStack.create(BlockRegistry.END_STONE_SMELTER);
@Override @Override
@ -27,12 +27,13 @@ public class REICompat implements REIPluginV0 {
@Override @Override
public void registerRecipeDisplays(RecipeHelper recipeHelper) { public void registerRecipeDisplays(RecipeHelper recipeHelper) {
recipeHelper.registerRecipes(ALLOYING, AlloyingRecipe.class, REIAlloyingDisplay::new); recipeHelper.registerRecipes(AlloyingRecipe.ID, AlloyingRecipe.class, REIAlloyingDisplay::new);
recipeHelper.registerRecipes(AlloyingRecipe.ID, BlastingRecipe.class, REIAlloyingDisplay::new);
} }
@Override @Override
public void registerOthers(RecipeHelper recipeHelper) { public void registerOthers(RecipeHelper recipeHelper) {
recipeHelper.registerWorkingStations(ALLOYING, END_STONE_SMELTER); recipeHelper.registerWorkingStations(AlloyingRecipe.ID, END_STONE_SMELTER);
} }
@Override @Override

View file

@ -28,6 +28,7 @@ public class AlloyingRecipe implements Recipe<Inventory> {
public final static String GROUP = "alloying"; public final static String GROUP = "alloying";
public final static RecipeType<AlloyingRecipe> TYPE = EndRecipeManager.registerType(GROUP); public final static RecipeType<AlloyingRecipe> TYPE = EndRecipeManager.registerType(GROUP);
public final static Serializer SERIALIZER = EndRecipeManager.registerSerializer(GROUP, new Serializer()); public final static Serializer SERIALIZER = EndRecipeManager.registerSerializer(GROUP, new Serializer());
public final static Identifier ID = BetterEnd.getIdentifier("alloying");
protected final RecipeType<?> type; protected final RecipeType<?> type;
protected final Identifier id; protected final Identifier id;

View file

@ -10,33 +10,6 @@ import ru.betterend.registry.BlockRegistry;
import ru.betterend.registry.ItemRegistry; import ru.betterend.registry.ItemRegistry;
public class CraftingRecipes { public class CraftingRecipes {
private static String[] helmet_recipe = new String[] {
"III", "I I"
};
private static String[] chestplate_recipe = new String[] {
"I I", "III", "III"
};
private static String[] leggings_recipe = new String[] {
"III", "I I", "I I"
};
private static String[] boots_recipe = new String[] {
"I I", "I I"
};
private static String[] shovel_recipe = new String[] {
"I", "#", "#"
};
private static String[] sword_recipe = new String[] {
"I", "I", "#"
};
private static String[] pickaxe_recipe = new String[] {
"III", " # ", " # "
};
private static String[] axe_recipe = new String[] {
"II", "#I", "# "
};
private static String[] hoe_recipe = new String[] {
"II", "# ", "# "
};
public static void register() { public static void register() {
if (blockExists(BlockRegistry.ENDER_BLOCK)) { if (blockExists(BlockRegistry.ENDER_BLOCK)) {
@ -52,67 +25,79 @@ public class CraftingRecipes {
} }
if (blockExists(BlockRegistry.END_STONE_SMELTER)) { if (blockExists(BlockRegistry.END_STONE_SMELTER)) {
RecipeBuilder.make("end_stone_smelter", BlockRegistry.END_STONE_SMELTER) RecipeBuilder.make("end_stone_smelter", BlockRegistry.END_STONE_SMELTER)
.setShape(new String[] { "###", "V#V", "###" }) .setShape(new String[] { "###", "V V", "###" })
.addMaterial('#', Blocks.END_STONE_BRICKS) .addMaterial('#', Blocks.END_STONE_BRICKS)
.addMaterial('V', Items.BUCKET) .addMaterial('V', Items.BUCKET)
.build(); .build();
} }
if (itemExists(ItemRegistry.TERMINITE_INGOT)) { if (itemExists(ItemRegistry.TERMINITE_INGOT)) {
registerHelmet("terminite", ItemRegistry.TERMINITE_INGOT, ItemRegistry.TERMINITE_HELMET); String material = "terminite";
registerChestplate("terminite", ItemRegistry.TERMINITE_INGOT, ItemRegistry.TERMINITE_CHESTPLATE); RecipeBuilder.make(material + "_block", BlockRegistry.TERMINITE_BLOCK)
registerLeggings("terminite", ItemRegistry.TERMINITE_INGOT, ItemRegistry.TERMINITE_LEGGINGS); .setShape(new String[] { "III", "III", "III" })
registerBoots("terminite", ItemRegistry.TERMINITE_INGOT, ItemRegistry.TERMINITE_BOOTS); .addMaterial('I', ItemRegistry.TERMINITE_INGOT)
registerShovel("terminite", ItemRegistry.TERMINITE_INGOT, ItemRegistry.TERMINITE_SHOVEL); .build();
registerSword("terminite", ItemRegistry.TERMINITE_INGOT, ItemRegistry.TERMINITE_SWORD);
registerPickaxe("terminite", ItemRegistry.TERMINITE_INGOT, ItemRegistry.TERMINITE_PICKAXE); registerHelmet(material, ItemRegistry.TERMINITE_INGOT, ItemRegistry.TERMINITE_HELMET);
registerAxe("terminite", ItemRegistry.TERMINITE_INGOT, ItemRegistry.TERMINITE_AXE); registerChestplate(material, ItemRegistry.TERMINITE_INGOT, ItemRegistry.TERMINITE_CHESTPLATE);
registerHoe("terminite", ItemRegistry.TERMINITE_INGOT, ItemRegistry.TERMINITE_HOE); registerLeggings(material, ItemRegistry.TERMINITE_INGOT, ItemRegistry.TERMINITE_LEGGINGS);
registerBoots(material, ItemRegistry.TERMINITE_INGOT, ItemRegistry.TERMINITE_BOOTS);
registerShovel(material, ItemRegistry.TERMINITE_INGOT, ItemRegistry.TERMINITE_SHOVEL);
registerSword(material, ItemRegistry.TERMINITE_INGOT, ItemRegistry.TERMINITE_SWORD);
registerPickaxe(material, ItemRegistry.TERMINITE_INGOT, ItemRegistry.TERMINITE_PICKAXE);
registerAxe(material, ItemRegistry.TERMINITE_INGOT, ItemRegistry.TERMINITE_AXE);
registerHoe(material, ItemRegistry.TERMINITE_INGOT, ItemRegistry.TERMINITE_HOE);
} }
if (itemExists(ItemRegistry.AETERNIUM_INGOT)) { if (itemExists(ItemRegistry.AETERNIUM_INGOT)) {
registerHelmet("aeternium", ItemRegistry.AETERNIUM_INGOT, ItemRegistry.AETERNIUM_HELMET); String material = "aeternium";
registerChestplate("aeternium", ItemRegistry.AETERNIUM_INGOT, ItemRegistry.AETERNIUM_CHESTPLATE); RecipeBuilder.make(material + "_block", BlockRegistry.AETERNIUM_BLOCK)
registerLeggings("aeternium", ItemRegistry.AETERNIUM_INGOT, ItemRegistry.AETERNIUM_LEGGINGS); .setShape(new String[] { "III", "III", "III" })
registerBoots("aeternium", ItemRegistry.AETERNIUM_INGOT, ItemRegistry.AETERNIUM_BOOTS); .addMaterial('I', ItemRegistry.AETERNIUM_INGOT)
registerShovel("aeternium", ItemRegistry.AETERNIUM_INGOT, ItemRegistry.AETERNIUM_SHOVEL); .build();
registerSword("aeternium", ItemRegistry.AETERNIUM_INGOT, ItemRegistry.AETERNIUM_SWORD);
registerPickaxe("aeternium", ItemRegistry.AETERNIUM_INGOT, ItemRegistry.AETERNIUM_PICKAXE); registerHelmet(material, ItemRegistry.AETERNIUM_INGOT, ItemRegistry.AETERNIUM_HELMET);
registerAxe("aeternium", ItemRegistry.AETERNIUM_INGOT, ItemRegistry.AETERNIUM_AXE); registerChestplate(material, ItemRegistry.AETERNIUM_INGOT, ItemRegistry.AETERNIUM_CHESTPLATE);
registerHoe("aeternium", ItemRegistry.AETERNIUM_INGOT, ItemRegistry.AETERNIUM_HOE); registerLeggings(material, ItemRegistry.AETERNIUM_INGOT, ItemRegistry.AETERNIUM_LEGGINGS);
registerBoots(material, ItemRegistry.AETERNIUM_INGOT, ItemRegistry.AETERNIUM_BOOTS);
registerShovel(material, ItemRegistry.AETERNIUM_INGOT, ItemRegistry.AETERNIUM_SHOVEL);
registerSword(material, ItemRegistry.AETERNIUM_INGOT, ItemRegistry.AETERNIUM_SWORD);
registerPickaxe(material, ItemRegistry.AETERNIUM_INGOT, ItemRegistry.AETERNIUM_PICKAXE);
registerAxe(material, ItemRegistry.AETERNIUM_INGOT, ItemRegistry.AETERNIUM_AXE);
registerHoe(material, ItemRegistry.AETERNIUM_INGOT, ItemRegistry.AETERNIUM_HOE);
} }
} }
private static void registerHelmet(String name, Item material, Item result) { private static void registerHelmet(String name, Item material, Item result) {
RecipeBuilder.make(name + "_helmet", result) RecipeBuilder.make(name + "_helmet", result)
.setShape(helmet_recipe) .setShape(new String[] { "III", "I I" })
.addMaterial('I', material) .addMaterial('I', material)
.build(); .build();
} }
private static void registerChestplate(String name, Item material, Item result) { private static void registerChestplate(String name, Item material, Item result) {
RecipeBuilder.make(name + "_chestplate", result) RecipeBuilder.make(name + "_chestplate", result)
.setShape(chestplate_recipe) .setShape(new String[] { "I I", "III", "III" })
.addMaterial('I', material) .addMaterial('I', material)
.build(); .build();
} }
private static void registerLeggings(String name, Item material, Item result) { private static void registerLeggings(String name, Item material, Item result) {
RecipeBuilder.make(name + "_leggings", result) RecipeBuilder.make(name + "_leggings", result)
.setShape(leggings_recipe) .setShape(new String[] { "III", "I I", "I I" })
.addMaterial('I', material) .addMaterial('I', material)
.build(); .build();
} }
private static void registerBoots(String name, Item material, Item result) { private static void registerBoots(String name, Item material, Item result) {
RecipeBuilder.make(name + "_boots", result) RecipeBuilder.make(name + "_boots", result)
.setShape(boots_recipe) .setShape(new String[] { "I I", "I I" })
.addMaterial('I', material) .addMaterial('I', material)
.build(); .build();
} }
private static void registerShovel(String name, Item material, Item result) { private static void registerShovel(String name, Item material, Item result) {
RecipeBuilder.make(name + "_shovel", result) RecipeBuilder.make(name + "_shovel", result)
.setShape(shovel_recipe) .setShape(new String[] { "I", "#", "#" })
.addMaterial('I', material) .addMaterial('I', material)
.addMaterial('#', Items.STICK) .addMaterial('#', Items.STICK)
.build(); .build();
@ -120,7 +105,7 @@ public class CraftingRecipes {
private static void registerSword(String name, Item material, Item result) { private static void registerSword(String name, Item material, Item result) {
RecipeBuilder.make(name + "_sword", result) RecipeBuilder.make(name + "_sword", result)
.setShape(sword_recipe) .setShape(new String[] { "I", "I", "#" })
.addMaterial('I', material) .addMaterial('I', material)
.addMaterial('#', Items.STICK) .addMaterial('#', Items.STICK)
.build(); .build();
@ -128,7 +113,7 @@ public class CraftingRecipes {
private static void registerPickaxe(String name, Item material, Item result) { private static void registerPickaxe(String name, Item material, Item result) {
RecipeBuilder.make(name + "_pickaxe", result) RecipeBuilder.make(name + "_pickaxe", result)
.setShape(pickaxe_recipe) .setShape(new String[] { "III", " # ", " # " })
.addMaterial('I', material) .addMaterial('I', material)
.addMaterial('#', Items.STICK) .addMaterial('#', Items.STICK)
.build(); .build();
@ -136,7 +121,7 @@ public class CraftingRecipes {
private static void registerAxe(String name, Item material, Item result) { private static void registerAxe(String name, Item material, Item result) {
RecipeBuilder.make(name + "_axe", result) RecipeBuilder.make(name + "_axe", result)
.setShape(axe_recipe) .setShape(new String[] { "II", "#I", "# " })
.addMaterial('I', material) .addMaterial('I', material)
.addMaterial('#', Items.STICK) .addMaterial('#', Items.STICK)
.build(); .build();
@ -144,7 +129,7 @@ public class CraftingRecipes {
private static void registerHoe(String name, Item material, Item result) { private static void registerHoe(String name, Item material, Item result) {
RecipeBuilder.make(name + "_hoe", result) RecipeBuilder.make(name + "_hoe", result)
.setShape(hoe_recipe) .setShape(new String[] { "II", "# ", "# " })
.addMaterial('I', material) .addMaterial('I', material)
.addMaterial('#', Items.STICK) .addMaterial('#', Items.STICK)
.build(); .build();

View file

@ -4,6 +4,7 @@ import java.util.List;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
import net.minecraft.entity.EquipmentSlot; import net.minecraft.entity.EquipmentSlot;
import net.minecraft.item.ArmorItem; import net.minecraft.item.ArmorItem;
import net.minecraft.item.BlockItem; import net.minecraft.item.BlockItem;
@ -65,10 +66,21 @@ public class ItemRegistry {
} }
protected static ToolItem registerTool(String name, ToolItem item) { protected static ToolItem registerTool(String name, ToolItem item) {
if (item != Items.AIR) { Registry.register(Registry.ITEM, BetterEnd.getIdentifier(name), item);
Registry.register(Registry.ITEM, BetterEnd.getIdentifier(name), item); MOD_ITEMS.add(item);
MOD_ITEMS.add(item);
} // if (item instanceof ShovelItem) {
// FabricToolTags.SHOVELS.values().add(item);
// } else if (item instanceof SwordItem) {
// FabricToolTags.SWORDS.values().add(item);
// } else if (item instanceof EndPickaxe) {
// FabricToolTags.PICKAXES.values().add(item);
// } else if (item instanceof EndAxe) {
// FabricToolTags.AXES.values().add(item);
// } else if (item instanceof EndHoe) {
// FabricToolTags.HOES.values().add(item);
// }
return item; return item;
} }

View file

@ -26,8 +26,11 @@
"ru.betterend.client.BetterEndClient" "ru.betterend.client.BetterEndClient"
], ],
"rei_plugins": [ "rei_plugins": [
"ru.betterend.compat.REICompat" "ru.betterend.compat.REIPlugin"
] ],
"rei_containers": [
"ru.betterend.compat.REIContainer"
]
}, },
"mixins": [ "mixins": [
"betterend.mixins.common.json", "betterend.mixins.common.json",