Skip to content

Commit

Permalink
Fix #333 and implement some of #509 (Dye Armor, Clone Banner, Clone B…
Browse files Browse the repository at this point in the history
…ook, Firework Rocket, Clone Map, Extend Map, Decorate Shield, Dye Shulker Box, Suspicious Stew)
  • Loading branch information
shedaniel committed Jun 1, 2023
1 parent 79f79b9 commit 3bab1b9
Show file tree
Hide file tree
Showing 15 changed files with 830 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
import me.shedaniel.rei.plugin.client.categories.beacon.DefaultBeaconPaymentCategory;
import me.shedaniel.rei.plugin.client.categories.cooking.DefaultCookingCategory;
import me.shedaniel.rei.plugin.client.categories.crafting.DefaultCraftingCategory;
import me.shedaniel.rei.plugin.client.categories.crafting.filler.TippedArrowRecipeFiller;
import me.shedaniel.rei.plugin.client.categories.crafting.filler.*;
import me.shedaniel.rei.plugin.client.categories.tag.DefaultTagCategory;
import me.shedaniel.rei.plugin.client.exclusionzones.DefaultPotionEffectExclusionZones;
import me.shedaniel.rei.plugin.client.exclusionzones.DefaultRecipeBookExclusionZones;
Expand Down Expand Up @@ -108,6 +108,19 @@
@Environment(EnvType.CLIENT)
@ApiStatus.Internal
public class DefaultClientPlugin implements REIClientPlugin, BuiltinClientPlugin {
private static final CraftingRecipeFiller<?>[] CRAFTING_RECIPE_FILLERS = new CraftingRecipeFiller[]{
new TippedArrowRecipeFiller(),
new ShulkerBoxColoringFiller(),
new BannerDuplicateRecipeFiller(),
new ShieldDecorationRecipeFiller(),
new SuspiciousStewRecipeFiller(),
new BookCloningRecipeFiller(),
new FireworkRocketRecipeFiller(),
new ArmorDyeRecipeFiller(),
new MapCloningRecipeFiller(),
new MapExtendingRecipeFiller()
};

public DefaultClientPlugin() {
ClientInternals.attachInstance((Supplier<Object>) () -> this, "builtinClientPlugin");
}
Expand Down Expand Up @@ -190,6 +203,10 @@ public void registerCategories(CategoryRegistry registry) {
return EventResult.pass();
});

for (CraftingRecipeFiller<?> filler : CRAFTING_RECIPE_FILLERS) {
filler.registerCategories(registry);
}

Set<Item> axes = Sets.newHashSet(), hoes = Sets.newHashSet(), shovels = Sets.newHashSet();
EntryRegistry.getInstance().getEntryStacks().filter(stack -> stack.getValueType() == ItemStack.class).map(stack -> ((ItemStack) stack.getValue()).getItem()).forEach(item -> {
if (item instanceof AxeItem && axes.add(item)) {
Expand Down Expand Up @@ -250,7 +267,9 @@ public void registerDisplays(DisplayRegistry registry) {
for (Map.Entry<Item, Integer> entry : AbstractFurnaceBlockEntity.getFuel().entrySet()) {
registry.add(new DefaultFuelDisplay(Collections.singletonList(EntryIngredients.of(entry.getKey())), Collections.emptyList(), entry.getValue()));
}
registry.registerRecipesFiller(TippedArrowRecipe.class, RecipeType.CRAFTING, new TippedArrowRecipeFiller()::apply);
for (CraftingRecipeFiller<?> filler : CRAFTING_RECIPE_FILLERS) {
filler.registerDisplays(registry);
}
if (ComposterBlock.COMPOSTABLES.isEmpty()) {
ComposterBlock.bootStrap();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* This file is licensed under the MIT License, part of Roughly Enough Items.
* Copyright (c) 2018, 2019, 2020, 2021, 2022 shedaniel
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package me.shedaniel.rei.plugin.client.categories.crafting.filler;

import me.shedaniel.rei.api.client.registry.entry.EntryRegistry;
import me.shedaniel.rei.api.common.display.Display;
import me.shedaniel.rei.api.common.entry.EntryIngredient;
import me.shedaniel.rei.api.common.entry.EntryStack;
import me.shedaniel.rei.api.common.util.EntryIngredients;
import me.shedaniel.rei.plugin.common.displays.crafting.DefaultCustomShapelessDisplay;
import net.minecraft.world.item.DyeColor;
import net.minecraft.world.item.DyeItem;
import net.minecraft.world.item.DyeableLeatherItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.ArmorDyeRecipe;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Random;

public class ArmorDyeRecipeFiller implements CraftingRecipeFiller<ArmorDyeRecipe> {
@Override
public Collection<Display> apply(ArmorDyeRecipe recipe) {
List<Display> displays = new ArrayList<>();
List<EntryStack<?>> toDye = EntryRegistry.getInstance().getEntryStacks().filter(entry -> entry.getValueType() == ItemStack.class && entry.<ItemStack>castValue().getItem() instanceof DyeableLeatherItem).toList();
DyeColor[] colors = DyeColor.values();

for (EntryStack<?> armor : toDye) {
ItemStack armorStack = armor.castValue();
for (DyeColor color : colors) {
ItemStack output = armorStack.copy();
DyeItem dyeItem = DyeItem.byColor(color);
output = DyeableLeatherItem.dyeArmor(output, List.of(dyeItem));
displays.add(new DefaultCustomShapelessDisplay(recipe,
List.of(EntryIngredient.of(armor.copy()),
EntryIngredients.of(dyeItem)),
List.of(EntryIngredients.of(output))));
}

for (int i = 0; i < 9; i++) {
int dyes = new Random().nextInt(2) + 2;
List<EntryIngredient> inputs = new ArrayList<>();
List<DyeItem> dyeItems = new ArrayList<>();
inputs.add(EntryIngredient.of(armor.copy()));
for (int j = 0; j < dyes; j++) {
DyeColor color = colors[new Random().nextInt(colors.length)];
DyeItem dyeItem = DyeItem.byColor(color);
dyeItems.add(dyeItem);
inputs.add(EntryIngredients.of(dyeItem));
}
ItemStack output = armorStack.copy();
output = DyeableLeatherItem.dyeArmor(output, dyeItems);
displays.add(new DefaultCustomShapelessDisplay(recipe,
inputs, List.of(EntryIngredients.of(output))));
}
}

return displays;
}

@Override
public Class<ArmorDyeRecipe> getRecipeClass() {
return ArmorDyeRecipe.class;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* This file is licensed under the MIT License, part of Roughly Enough Items.
* Copyright (c) 2018, 2019, 2020, 2021, 2022 shedaniel
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package me.shedaniel.rei.plugin.client.categories.crafting.filler;

import com.mojang.datafixers.util.Pair;
import me.shedaniel.rei.api.common.display.Display;
import me.shedaniel.rei.api.common.entry.EntryIngredient;
import me.shedaniel.rei.api.common.entry.EntryStack;
import me.shedaniel.rei.api.common.util.EntryStacks;
import me.shedaniel.rei.plugin.common.displays.crafting.DefaultCustomShapelessDisplay;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.DyeColor;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.BannerDuplicateRecipe;

import java.util.*;

public class BannerDuplicateRecipeFiller implements CraftingRecipeFiller<BannerDuplicateRecipe> {
@Override
public Collection<Display> apply(BannerDuplicateRecipe recipe) {
List<Display> displays = new ArrayList<>();
Map<DyeColor, Pair<EntryIngredient.Builder, EntryStack<?>>> displayMap = new HashMap<>();

for (Pair<DyeColor, ItemStack> pair : ShieldDecorationRecipeFiller.randomizeBanners()) {
Optional<Item> bannerOptional = Registry.ITEM.getOptional(new ResourceLocation(pair.getFirst().getName() + "_banner"));
if (bannerOptional.isEmpty()) continue;
Pair<EntryIngredient.Builder, EntryStack<?>> builderPair = displayMap.computeIfAbsent(pair.getFirst(), color -> Pair.of(EntryIngredient.builder(), EntryStacks.of(bannerOptional.get())));
builderPair.getFirst().add(EntryStacks.of(pair.getSecond()));
}

for (Pair<EntryIngredient.Builder, EntryStack<?>> pair : displayMap.values()) {
EntryIngredient inputsFirst = pair.getFirst().build();
EntryStack<?> inputsSecond = pair.getSecond();
EntryIngredient.unifyFocuses(inputsFirst);
displays.add(new DefaultCustomShapelessDisplay(recipe,
List.of(inputsFirst, EntryIngredient.of(inputsSecond)),
List.of(inputsFirst)));
}

return displays;
}

@Override
public Class<BannerDuplicateRecipe> getRecipeClass() {
return BannerDuplicateRecipe.class;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* This file is licensed under the MIT License, part of Roughly Enough Items.
* Copyright (c) 2018, 2019, 2020, 2021, 2022 shedaniel
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package me.shedaniel.rei.plugin.client.categories.crafting.filler;

import me.shedaniel.rei.api.common.display.Display;
import me.shedaniel.rei.api.common.entry.EntryIngredient;
import me.shedaniel.rei.api.common.util.CollectionUtils;
import me.shedaniel.rei.api.common.util.EntryStacks;
import me.shedaniel.rei.plugin.common.displays.crafting.DefaultCustomShapelessDisplay;
import net.minecraft.nbt.IntTag;
import net.minecraft.nbt.StringTag;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.WrittenBookItem;
import net.minecraft.world.item.crafting.BookCloningRecipe;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Random;

public class BookCloningRecipeFiller implements CraftingRecipeFiller<BookCloningRecipe> {
private static final String[] TITLES = new String[]{
"Adventurer's Dreams", "Adventurer's Diary", "The Lost Journal",
"The Lost Diary", "The Lost Book", "The Lost Tome", "The Lost Codex",
"The Last Journal", "The Last Diary", "The Last Book", "The Last Tome",
"Secrets of the World", "Secrets of the Universe", "Secrets of the Cosmos",
"Myths of the World", "Myths of the Universe", "Myths of the Cosmos",
"Old Tales of the World", "Old Tales of the Universe", "Old Tales of the Cosmos",
"The World of the Legends", "The Universe of the Heroes", "The Cosmos of the Gods",
"Diary of a Villager", "Diary of a Farmer", "Diary of a Fisherman",
"Dungeon Journal", "Dungeon Diary", "Dungeon Book", "Dungeon Tome",
"Dunk Memes", "Top 10 Memes of 2019", "Top 10 Memes of 2020",
"Plastic Memories", "Kizumonogatari"
};
private static final String[] AUTHORS = new String[]{
"shedaniel", "Steve", "Alex", "Notch", "Herobrine", "God",
"Santa Claus", "The Easter Bunny", "The Tooth Fairy"
};

@Override
public Collection<Display> apply(BookCloningRecipe recipe) {
List<Display> displays = new ArrayList<>();

for (int i = 1; i <= 8; i++) {
EntryIngredient.Builder[] inputs = new EntryIngredient.Builder[9];
for (int j = 0; j < 9; j++) {
inputs[j] = EntryIngredient.builder();
}
EntryIngredient.Builder output = EntryIngredient.builder();
for (int j = 0; j < 10; j++) {
ItemStack writtenBook = generateBook();
ItemStack bookAndQuill = new ItemStack(Items.WRITABLE_BOOK);
inputs[0].add(EntryStacks.of(writtenBook));
for (int k = 0; k < i; k++) {
inputs[k + 1].add(EntryStacks.of(bookAndQuill));
}
ItemStack cloned = writtenBook.copy();
cloned.addTagElement(WrittenBookItem.TAG_GENERATION, IntTag.valueOf(1));
cloned.setCount(i);
output.add(EntryStacks.of(cloned));
}
displays.add(new DefaultCustomShapelessDisplay(recipe,
CollectionUtils.map(inputs, EntryIngredient.Builder::build),
List.of(output.build())));
}

return displays;
}

private ItemStack generateBook() {
ItemStack stack = new ItemStack(Items.WRITTEN_BOOK);
stack.addTagElement(WrittenBookItem.TAG_AUTHOR, StringTag.valueOf(AUTHORS[new Random().nextInt(AUTHORS.length)]));
stack.addTagElement(WrittenBookItem.TAG_TITLE, StringTag.valueOf(TITLES[new Random().nextInt(TITLES.length)]));
stack.addTagElement(WrittenBookItem.TAG_GENERATION, IntTag.valueOf(0));
return stack;
}

@Override
public Class<BookCloningRecipe> getRecipeClass() {
return BookCloningRecipe.class;
}
}
Loading

0 comments on commit 3bab1b9

Please sign in to comment.