mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-17 10:55:17 +00:00
Add workaround crafting recipe for Botania banner patterns, rerun data
Closes #3114 I was planning to do this for a while, and accidentally added the empty class for the recipe with the recipe generator...
This commit is contained in:
1 parent
99df65bb45
commit
337f9fe322
9 files changed
+364
-333
No files matched your search
@@ -10,38 +10,46 @@
|
||||
*/
|
||||
package vazkii.botania.common.block;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.tileentity.BannerPattern;
|
||||
import net.minecraft.util.IItemProvider;
|
||||
import net.minecraftforge.registries.IRegistryDelegate;
|
||||
import vazkii.botania.common.item.ModItems;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
public final class ModBanners {
|
||||
|
||||
public static final Map<IRegistryDelegate<Item>, BannerPattern> PATTERNS = new LinkedHashMap<>();
|
||||
|
||||
public static void init() {
|
||||
addPattern("flower", "flr", new ItemStack(ModItems.livingwoodTwig));
|
||||
addPattern("lexicon", "lex", new ItemStack(ModItems.lexicon));
|
||||
addPattern("logo", "lgo", new ItemStack(ModItems.terrasteel));
|
||||
addPattern("sapling", "spl", new ItemStack(ModItems.dreamwoodTwig));
|
||||
addPattern("tiny_potato", "tpt", new ItemStack(ModBlocks.tinyPotato));
|
||||
addPattern("flower", "flr", ModItems.livingwoodTwig);
|
||||
addPattern("lexicon", "lex", ModItems.lexicon);
|
||||
addPattern("logo", "lgo", ModItems.terrasteel);
|
||||
addPattern("sapling", "spl", ModItems.dreamwoodTwig);
|
||||
addPattern("tiny_potato", "tpt", ModBlocks.tinyPotato);
|
||||
|
||||
addPattern("spark_dispersive", "sds", new ItemStack(ModItems.sparkUpgradeDispersive));
|
||||
addPattern("spark_dominant", "sdm", new ItemStack(ModItems.sparkUpgradeDominant));
|
||||
addPattern("spark_recessive", "src", new ItemStack(ModItems.sparkUpgradeRecessive));
|
||||
addPattern("spark_isolated", "sis", new ItemStack(ModItems.sparkUpgradeIsolated));
|
||||
addPattern("spark_dispersive", "sds", ModItems.sparkUpgradeDispersive);
|
||||
addPattern("spark_dominant", "sdm", ModItems.sparkUpgradeDominant);
|
||||
addPattern("spark_recessive", "src", ModItems.sparkUpgradeRecessive);
|
||||
addPattern("spark_isolated", "sis", ModItems.sparkUpgradeIsolated);
|
||||
|
||||
addPattern("fish", "fis", new ItemStack(Items.COD));
|
||||
addPattern("axe", "axe", new ItemStack(Items.IRON_AXE));
|
||||
addPattern("hoe", "hoe", new ItemStack(Items.IRON_HOE));
|
||||
addPattern("pickaxe", "pik", new ItemStack(Items.IRON_PICKAXE));
|
||||
addPattern("shovel", "shv", new ItemStack(Items.IRON_SHOVEL));
|
||||
addPattern("sword", "srd", new ItemStack(Items.IRON_SWORD));
|
||||
addPattern("fish", "fis", Items.COD);
|
||||
addPattern("axe", "axe", Items.IRON_AXE);
|
||||
addPattern("hoe", "hoe", Items.IRON_HOE);
|
||||
addPattern("pickaxe", "pik", Items.IRON_PICKAXE);
|
||||
addPattern("shovel", "shv", Items.IRON_SHOVEL);
|
||||
addPattern("sword", "srd", Items.IRON_SWORD);
|
||||
}
|
||||
|
||||
private static void addPattern(String name, String id, ItemStack craftingItem) {
|
||||
private static void addPattern(String name, String id, IItemProvider craftingItem) {
|
||||
name = "botania_" + name;
|
||||
id = "bt_" + id;
|
||||
BannerPattern.create(name.toUpperCase(Locale.ROOT), name, id, craftingItem);
|
||||
BannerPattern pattern = BannerPattern.create(name.toUpperCase(Locale.ROOT), name, id, new ItemStack(craftingItem));
|
||||
PATTERNS.put(craftingItem.asItem().delegate, pattern);
|
||||
}
|
||||
}
|
||||
@@ -11,37 +11,112 @@
|
||||
package vazkii.botania.common.crafting.recipe;
|
||||
|
||||
import net.minecraft.inventory.CraftingInventory;
|
||||
import net.minecraft.item.DyeColor;
|
||||
import net.minecraft.item.DyeItem;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.IRecipeSerializer;
|
||||
import net.minecraft.item.crafting.SpecialRecipe;
|
||||
import net.minecraft.item.crafting.SpecialRecipeSerializer;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.nbt.ListNBT;
|
||||
import net.minecraft.tags.ItemTags;
|
||||
import net.minecraft.tileentity.BannerPattern;
|
||||
import net.minecraft.tileentity.BannerTileEntity;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.World;
|
||||
import vazkii.botania.common.block.ModBanners;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
// Workaround recipe for the loom hardcoding problem.
|
||||
public class BannerRecipe extends SpecialRecipe {
|
||||
public static IRecipeSerializer<BannerRecipe> SERIALIZER = new SpecialRecipeSerializer<>(BannerRecipe::new);
|
||||
public static SpecialRecipeSerializer<BannerRecipe> SERIALIZER = new SpecialRecipeSerializer<>(BannerRecipe::new);
|
||||
|
||||
public BannerRecipe(ResourceLocation id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(CraftingInventory inv, World worldIn) {
|
||||
return false;
|
||||
public boolean matches(CraftingInventory inv, @Nonnull World world) {
|
||||
boolean foundBanner = false;
|
||||
boolean foundItem = false;
|
||||
boolean foundDye = false;
|
||||
for (int i = 0; i < inv.getSizeInventory(); i++) {
|
||||
ItemStack stack = inv.getStackInSlot(i);
|
||||
Item item = stack.getItem();
|
||||
if (stack.isEmpty())
|
||||
continue;
|
||||
|
||||
if (ModBanners.PATTERNS.containsKey(item.delegate) && !foundItem) {
|
||||
foundItem = true;
|
||||
} else if (ItemTags.BANNERS.contains(item) && !foundBanner && BannerTileEntity.getPatterns(stack) < 6) {
|
||||
foundBanner = true;
|
||||
} else if (item instanceof DyeItem && !foundDye) {
|
||||
foundDye = true;
|
||||
} else return false;
|
||||
}
|
||||
return foundBanner && foundItem && foundDye;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack getCraftingResult(CraftingInventory inv) {
|
||||
return null;
|
||||
public ItemStack getCraftingResult(@Nonnull CraftingInventory inv) {
|
||||
ItemStack banner = ItemStack.EMPTY;
|
||||
ItemStack dye = ItemStack.EMPTY;
|
||||
BannerPattern pattern = null;
|
||||
|
||||
for (int i = 0; i < inv.getSizeInventory(); i++) {
|
||||
ItemStack stack = inv.getStackInSlot(i);
|
||||
Item item = stack.getItem();
|
||||
if (ModBanners.PATTERNS.containsKey(item.delegate)) {
|
||||
pattern = ModBanners.PATTERNS.get(item.delegate);
|
||||
} else if (ItemTags.BANNERS.contains(item)) {
|
||||
banner = stack;
|
||||
} else if (item instanceof DyeItem) {
|
||||
dye = stack;
|
||||
}
|
||||
}
|
||||
return applyPattern(banner, pattern, dye);
|
||||
}
|
||||
|
||||
// [VanillaCopy] From LoomContainer.func_217031_j, edits noted
|
||||
@SuppressWarnings("UnnecessaryLocalVariable")
|
||||
private static ItemStack applyPattern(ItemStack banner, BannerPattern pattern, ItemStack dye) {
|
||||
ItemStack itemstack = banner; // Apply our context here
|
||||
ItemStack itemstack1 = dye;
|
||||
ItemStack itemstack2 = ItemStack.EMPTY;
|
||||
|
||||
if (!itemstack.isEmpty() && !itemstack1.isEmpty()) {
|
||||
itemstack2 = itemstack.copy();
|
||||
itemstack2.setCount(1);
|
||||
BannerPattern bannerpattern = pattern; // Replace the pattern with provided one
|
||||
DyeColor dyecolor = ((DyeItem) itemstack1.getItem()).getDyeColor();
|
||||
CompoundNBT compoundnbt = itemstack2.getOrCreateChildTag("BlockEntityTag");
|
||||
ListNBT listnbt;
|
||||
if (compoundnbt.contains("Patterns", 9)) {
|
||||
listnbt = compoundnbt.getList("Patterns", 10);
|
||||
} else {
|
||||
listnbt = new ListNBT();
|
||||
compoundnbt.put("Patterns", listnbt);
|
||||
}
|
||||
|
||||
CompoundNBT compoundnbt1 = new CompoundNBT();
|
||||
compoundnbt1.putString("Pattern", bannerpattern.getHashname());
|
||||
compoundnbt1.putInt("Color", dyecolor.getId());
|
||||
listnbt.add(compoundnbt1);
|
||||
}
|
||||
return itemstack2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canFit(int width, int height) {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public IRecipeSerializer<?> getSerializer() {
|
||||
return null;
|
||||
return SERIALIZER;
|
||||
}
|
||||
}
|
||||
@@ -713,6 +713,7 @@ public final class ModItems {
|
||||
IForgeRegistry<IRecipeSerializer<?>> r = evt.getRegistry();
|
||||
register(r, AncientWillRecipe.SERIALIZER, "ancient_will_attach");
|
||||
register(r, ArmorUpgradeRecipe.SERIALIZER, "armor_upgrade");
|
||||
register(r, BannerRecipe.SERIALIZER, "banner_pattern_apply");
|
||||
register(r, BlackHoleTalismanExtractRecipe.SERIALIZER, "black_hole_talisman_extract");
|
||||
register(r, CompositeLensRecipe.SERIALIZER, "composite_lens");
|
||||
register(r, CosmeticAttachRecipe.SERIALIZER, "cosmetic_attach");
|
||||
|
||||
@@ -74,6 +74,7 @@ public class RecipeProvider extends net.minecraft.data.RecipeProvider {
|
||||
@Override
|
||||
protected void registerRecipes(Consumer<IFinishedRecipe> consumer) {
|
||||
specialRecipe(consumer, AncientWillRecipe.SERIALIZER);
|
||||
specialRecipe(consumer, BannerRecipe.SERIALIZER);
|
||||
specialRecipe(consumer, BlackHoleTalismanExtractRecipe.SERIALIZER);
|
||||
specialRecipe(consumer, CompositeLensRecipe.SERIALIZER);
|
||||
specialRecipe(consumer, CosmeticAttachRecipe.SERIALIZER);
|
||||
|
||||
Reference in new issue
Block a user