Facade Recipe integration and cleanups
This commit is contained in:
@@ -19,9 +19,11 @@
|
||||
package appeng.core;
|
||||
|
||||
import appeng.items.parts.FacadeItem;
|
||||
import com.google.common.base.Preconditions;
|
||||
import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemGroup;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.util.collection.DefaultedList;
|
||||
@@ -34,8 +36,11 @@ public final class FacadeCreativeTab {
|
||||
|
||||
private static List<ItemStack> subTypes = null;
|
||||
|
||||
private static ItemGroup group;
|
||||
|
||||
public static void init() {
|
||||
FabricItemGroupBuilder.create(AppEng.makeId("facades"))
|
||||
Preconditions.checkState(group == null);
|
||||
group = FabricItemGroupBuilder.create(AppEng.makeId("facades"))
|
||||
.icon(() -> {
|
||||
calculateSubTypes();
|
||||
if (subTypes.isEmpty()) {
|
||||
@@ -47,6 +52,13 @@ public final class FacadeCreativeTab {
|
||||
.build();
|
||||
}
|
||||
|
||||
public static ItemGroup getGroup() {
|
||||
if (group == null) {
|
||||
init();
|
||||
}
|
||||
return group;
|
||||
}
|
||||
|
||||
private static void fill(List<ItemStack> items) {
|
||||
calculateSubTypes();
|
||||
items.addAll(subTypes);
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package appeng.integration.modules.jei;
|
||||
|
||||
import appeng.core.AppEng;
|
||||
import appeng.core.FacadeCreativeTab;
|
||||
import me.shedaniel.rei.api.EntryStack;
|
||||
import me.shedaniel.rei.plugin.crafting.DefaultCraftingCategory;
|
||||
import net.minecraft.client.resource.language.I18n;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
/**
|
||||
* A simple copy of the crafting category to separate out the facade recipes.
|
||||
*/
|
||||
public class FacadeRecipeCategory extends DefaultCraftingCategory {
|
||||
|
||||
public static final Identifier ID = AppEng.makeId("facades");
|
||||
|
||||
@Override
|
||||
public Identifier getIdentifier() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntryStack getLogo() {
|
||||
return EntryStack.create(FacadeCreativeTab.getGroup().getIcon());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCategoryName() {
|
||||
return I18n.translate(FacadeCreativeTab.getGroup().getTranslationKey());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.integration.modules.jei;
|
||||
|
||||
import appeng.core.AppEng;
|
||||
import appeng.core.FacadeCreativeTab;
|
||||
import appeng.items.parts.FacadeItem;
|
||||
import me.shedaniel.rei.api.ClientHelper;
|
||||
import me.shedaniel.rei.api.EntryStack;
|
||||
import me.shedaniel.rei.api.LiveRecipeGenerator;
|
||||
import me.shedaniel.rei.plugin.crafting.DefaultShapedDisplay;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.recipe.Ingredient;
|
||||
import net.minecraft.recipe.ShapedRecipe;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.collection.DefaultedList;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* This plugin will dynamically add facade recipes for any item that can be
|
||||
* turned into a facade.
|
||||
*/
|
||||
class FacadeRegistryGenerator implements LiveRecipeGenerator<DefaultShapedDisplay> {
|
||||
|
||||
private final FacadeItem itemFacade;
|
||||
|
||||
private final ItemStack cableAnchor;
|
||||
|
||||
FacadeRegistryGenerator(FacadeItem itemFacade, ItemStack cableAnchor) {
|
||||
this.itemFacade = itemFacade;
|
||||
this.cableAnchor = cableAnchor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Identifier getCategoryIdentifier() {
|
||||
return FacadeRecipeCategory.ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<List<DefaultShapedDisplay>> getRecipeFor(EntryStack entry) {
|
||||
// Looking up how a certain facade is crafted
|
||||
ItemStack itemStack = entry.getItemStack();
|
||||
if (itemStack.getItem() instanceof FacadeItem) {
|
||||
FacadeItem facadeItem = (FacadeItem) itemStack.getItem();
|
||||
ItemStack textureItem = facadeItem.getTextureItem(itemStack);
|
||||
return Optional.of(Collections.singletonList(make(textureItem, this.cableAnchor, itemStack)));
|
||||
}
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<List<DefaultShapedDisplay>> getUsageFor(EntryStack entry) {
|
||||
// Looking up if a certain block can be used to make a facade
|
||||
ItemStack itemStack = entry.getItemStack();
|
||||
ItemStack facade = this.itemFacade.createFacadeForItem(itemStack, false);
|
||||
|
||||
if (!facade.isEmpty()) {
|
||||
return Optional.of(Collections.singletonList(make(itemStack, this.cableAnchor, facade)));
|
||||
}
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<List<DefaultShapedDisplay>> getDisplaysGenerated(ClientHelper.ViewSearchBuilder builder) {
|
||||
// FABRIC FIXME Return a list of all facade recipes here
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
private DefaultShapedDisplay make(ItemStack textureItem, ItemStack cableAnchor, ItemStack result) {
|
||||
// This id should only be used within JEI and not really matter
|
||||
Identifier id = AppEng.makeId("facade/" + Item.getRawId(textureItem.getItem()));
|
||||
|
||||
DefaultedList<Ingredient> ingredients = DefaultedList.ofSize(9, Ingredient.EMPTY);
|
||||
ingredients.set(1, Ingredient.ofStacks(cableAnchor));
|
||||
ingredients.set(3, Ingredient.ofStacks(cableAnchor));
|
||||
ingredients.set(5, Ingredient.ofStacks(cableAnchor));
|
||||
ingredients.set(7, Ingredient.ofStacks(cableAnchor));
|
||||
ingredients.set(4, Ingredient.ofStacks(textureItem));
|
||||
|
||||
return new DefaultShapedDisplay(new ShapedRecipe(id, "", 3, 3, ingredients, result));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -30,16 +30,14 @@ import appeng.core.AEConfig;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.integration.abstraction.ReiFacade;
|
||||
import appeng.items.parts.FacadeItem;
|
||||
import appeng.recipes.handlers.GrinderRecipe;
|
||||
import appeng.recipes.handlers.InscriberRecipe;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import me.shedaniel.rei.api.EntryStack;
|
||||
import me.shedaniel.rei.api.RecipeHelper;
|
||||
import me.shedaniel.rei.api.plugins.REIPluginV0;
|
||||
import me.shedaniel.rei.plugin.information.DefaultInformationDisplay;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.recipe.RecipeManager;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
@@ -66,6 +64,7 @@ public class ReiPlugin implements REIPluginV0 {
|
||||
recipeHelper.registerCategory(new GrinderRecipeCategory());
|
||||
recipeHelper.registerCategory(new CondenserCategory());
|
||||
recipeHelper.registerCategory(new InscriberRecipeCategory());
|
||||
recipeHelper.registerCategory(new FacadeRecipeCategory());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -88,6 +87,12 @@ public class ReiPlugin implements REIPluginV0 {
|
||||
recipeHelper.removeAutoCraftButton(CondenserCategory.UID);
|
||||
|
||||
registerWorkingStations(recipeHelper);
|
||||
|
||||
IDefinitions definitions = Api.instance().definitions();
|
||||
recipeHelper.registerLiveRecipeGenerator(new FacadeRegistryGenerator(
|
||||
(FacadeItem) definitions.items().facade().item(),
|
||||
definitions.parts().cableAnchor().stack(1)
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user