Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transfer tea flavors to datapack resources #39

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
2 changes: 2 additions & 0 deletions src/main/java/com/hugman/culinaire/Culinaire.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.common.reflect.Reflection;
import com.hugman.culinaire.config.CulinaireConfig;
import com.hugman.culinaire.init.CulinaireCauldronBehaviors;
import com.hugman.culinaire.init.CulinaireRegistries;
import com.hugman.culinaire.init.FoodBundle;
import com.hugman.culinaire.init.TeaBundle;
import com.hugman.culinaire.init.data.CulinaireLootTables;
Expand All @@ -21,6 +22,7 @@ public class Culinaire implements ModInitializer {

@Override
public void onInitialize() {
CulinaireRegistries.register();
MOD_DATA.addOldName("ce_foodstuffs");
Reflection.initialize(FoodBundle.class);
Reflection.initialize(TeaBundle.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

import com.hugman.culinaire.Culinaire;
import com.hugman.culinaire.init.TeaBundle;
import com.hugman.culinaire.objects.item.tea.TeaHelper;
import com.hugman.culinaire.objects.item.tea.TeaType;
import com.hugman.culinaire.objects.recipe.TeaBagMakingRecipe;
import com.hugman.culinaire.objects.recipe.TeaRecipe;
import com.hugman.culinaire.objects.screen.KettleScreen;
import com.hugman.culinaire.objects.tea.TeaType;
import me.shedaniel.math.Rectangle;
import me.shedaniel.rei.api.client.REIRuntime;
import me.shedaniel.rei.api.client.plugins.REIClientPlugin;
Expand All @@ -14,11 +13,18 @@
import me.shedaniel.rei.api.client.registry.screen.ScreenRegistry;
import me.shedaniel.rei.api.common.category.CategoryIdentifier;
import me.shedaniel.rei.api.common.util.EntryStacks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.recipe.Ingredient;
import net.minecraft.recipe.ShapelessRecipe;
import net.minecraft.util.Identifier;
import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryEntry;
import net.minecraft.util.registry.RegistryEntryList;

import java.util.List;
import java.util.Optional;

public class CulinaireREIPlugin implements REIClientPlugin {
public static final CategoryIdentifier<TeaBrewingDisplay> TEA_BREWING = CategoryIdentifier.of(Culinaire.MOD_DATA.id("plugins/tea_brewing"));
Expand All @@ -45,25 +51,34 @@ public void registerDisplays(DisplayRegistry registry) {
}

private void registerTeaBagDisplays(DisplayRegistry registry) {
for(TeaType teaType : TeaHelper.getAllTypes()) {
for(TeaType teaType : TeaType.getAll()) {
DefaultedList<Ingredient> inputs = DefaultedList.of();
inputs.add(TeaBagMakingRecipe.PAPER);
inputs.add(TeaBagMakingRecipe.STRING);
Ingredient ingredient = Ingredient.fromTag(teaType.getTag());
if(!ingredient.isEmpty()) {
inputs.add(ingredient);
ItemStack output = TeaHelper.appendTeaType(new ItemStack(TeaBundle.TEA_BAG), teaType);
Identifier id = new Identifier("culinaire", teaType.getStrength().getName() + "_" + teaType.getFlavor().getName() + "_tea_bag");
registry.add(new ShapelessRecipe(id, "tea_bags", output, inputs));
// TODO
//inputs.add(TeaRecipe.paper);
//inputs.add(TeaRecipe.string);

Optional<RegistryEntryList.Named<Item>> optional = Registry.ITEM.getEntryList(teaType.potency().ingredients());

if(optional.isPresent()) {
List<Item> list = optional.get().stream().map(RegistryEntry::value).toList();
if(!list.isEmpty()) {
list.forEach(item -> inputs.add(Ingredient.ofItems(item)));
ItemStack output = new ItemStack(TeaBundle.TEA_BAG);
teaType.addToStack(output);
Identifier id = Culinaire.MOD_DATA.id("tea_bag/" + teaType.flavor().getId().getPath() + "/" + teaType.potency().value());
registry.add(new ShapelessRecipe(id, "tea_bags", output, inputs));
}
}
}
}

private void registerTeaBottleDisplays(DisplayRegistry registry) {
for(TeaType teaType : TeaHelper.getAllTypes()) {
ItemStack input = TeaHelper.appendTeaType(new ItemStack(TeaBundle.TEA_BAG), teaType);
ItemStack output = TeaHelper.appendTeaType(new ItemStack(TeaBundle.TEA_BOTTLE), teaType);
registry.add(new TeaBrewingDisplay(input, output, teaType.getFlavor().getColor()));
for(TeaType teaType : TeaType.getAll()) {
ItemStack input = new ItemStack(TeaBundle.TEA_BAG);
ItemStack output = new ItemStack(TeaBundle.TEA_BOTTLE);
teaType.addToStack(input);
teaType.addToStack(output);
registry.add(new TeaBrewingDisplay(input, output, teaType.flavor().color()));
}
}

Expand Down
19 changes: 19 additions & 0 deletions src/main/java/com/hugman/culinaire/init/CulinaireRegistries.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.hugman.culinaire.init;

import com.google.common.reflect.Reflection;
import com.hugman.culinaire.Culinaire;
import com.hugman.culinaire.objects.tea.TeaFlavor;
import com.hugman.culinaire.objects.tea.effect.TeaEffectType;
import net.fabricmc.fabric.api.event.registry.FabricRegistryBuilder;
import net.fabricmc.fabric.api.event.registry.RegistryAttribute;
import net.minecraft.util.registry.SimpleRegistry;

public class CulinaireRegistries {
public static final SimpleRegistry<TeaEffectType> TEA_EFFECT_TYPE = FabricRegistryBuilder.createSimple(TeaEffectType.class, Culinaire.MOD_DATA.id("tea_effect_type")).attribute(RegistryAttribute.SYNCED).buildAndRegister();
public static final SimpleRegistry<TeaFlavor> TEA_FLAVOR = FabricRegistryBuilder.createSimple(TeaFlavor.class, Culinaire.MOD_DATA.id("tea_flavor")).attribute(RegistryAttribute.SYNCED).buildAndRegister();

public static void register() {
Reflection.initialize(TeaEffectType.class);
Reflection.initialize(TeaFlavor.class);
}
}
11 changes: 5 additions & 6 deletions src/main/java/com/hugman/culinaire/init/TeaBundle.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.hugman.culinaire.objects.block.entity.KettleBlockEntity;
import com.hugman.culinaire.objects.item.TeaBagItem;
import com.hugman.culinaire.objects.item.TeaBottleItem;
import com.hugman.culinaire.objects.recipe.TeaBagMakingRecipe;
import com.hugman.culinaire.objects.recipe.serializer.TeaRecipeSerializer;
import com.hugman.culinaire.objects.screen.handler.KettleScreenHandler;
import com.hugman.dawn.api.creator.*;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
Expand All @@ -16,19 +16,18 @@
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.Items;
import net.minecraft.recipe.SpecialRecipeSerializer;
import net.minecraft.sound.BlockSoundGroup;

public class TeaBundle extends CulinaireBundle {
public static final Item TEA_BAG = add(new ItemCreator.Builder("tea_bag", TeaBagItem::new, new Item.Settings().group(ItemGroup.FOOD).maxCount(16)).build());
public static final SpecialRecipeSerializer<TeaBagMakingRecipe> TEA_BAG_MAKING = add(new RecipeSerializerCreator<>("tea_bag_making", new SpecialRecipeSerializer<>(TeaBagMakingRecipe::new)));
public static final TeaRecipeSerializer TEA_CRAFTING = add(new RecipeSerializerCreator<>("crafting/tea", new TeaRecipeSerializer()));

public static final Item TEA_BOTTLE = add(new ItemCreator.Builder("tea_bottle", TeaBottleItem::new, new Item.Settings().group(ItemGroup.FOOD).maxCount(1).recipeRemainder(Items.GLASS_BOTTLE)).build());
public static final SoundCreator TEA_BOTTLE_FILL_SOUND = creator(new SoundCreator("item.tea_bottle.fill"));
public static final SoundCreator TEA_BOTTLE_FILL_SOUND = creator(new SoundCreator("ingredients.tea_bottle.fill"));

public static final Block KETTLE = add(new BlockCreator.Builder("kettle", KettleBlock::new, FabricBlockSettings.of(Material.METAL, MapColor.IRON_GRAY).requiresTool().strength(5.0F, 1200.0F).sounds(BlockSoundGroup.STONE)).itemGroup(ItemGroup.DECORATIONS).build());
public static final ScreenHandlerCreator<KettleScreenHandler> KETTLE_SCREEN_HANDLER = creator(new ScreenHandlerCreator<>("kettle", KettleScreenHandler::new));
public static final BlockEntityType<KettleBlockEntity> KETTLE_ENTITY = add(new BlockEntityCreator<>("kettle", FabricBlockEntityTypeBuilder.create(KettleBlockEntity::new, KETTLE)));
public static final StatCreator KETTLE_INTERACTION_STAT = creator(new StatCreator("interact_with_kettle"));
public static final SoundCreator KETTLE_BREW_SOUND = creator(new SoundCreator("block.kettle.brew"));
public static final ScreenHandlerCreator<KettleScreenHandler> KETTLE_SCREEN_HANDLER = creator(new ScreenHandlerCreator<>("kettle", KettleScreenHandler::new));
public static final BlockEntityType<KettleBlockEntity> KETTLE_ENTITY = add(new BlockEntityCreator<>("kettle", FabricBlockEntityTypeBuilder.create(KettleBlockEntity::new, KETTLE)));
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.hugman.culinaire.init.client;

import com.hugman.culinaire.init.TeaBundle;
import com.hugman.culinaire.objects.item.tea.TeaHelper;
import com.hugman.culinaire.objects.tea.TeaType;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.rendering.v1.ColorProviderRegistry;
Expand All @@ -13,6 +13,6 @@ public static void registerColors() {
}

private static void registerItemColors() {
ColorProviderRegistry.ITEM.register((stack, tintIndex) -> tintIndex > 0 ? -1 : TeaHelper.getColor(stack), TeaBundle.TEA_BOTTLE);
ColorProviderRegistry.ITEM.register((stack, tintIndex) -> tintIndex > 0 ? -1 : TeaType.getColor(stack), TeaBundle.TEA_BOTTLE);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.hugman.culinaire.mixin;

import com.google.common.collect.ImmutableMap;
import com.hugman.culinaire.init.CulinaireRegistries;
import com.hugman.culinaire.objects.tea.TeaFlavor;
import com.mojang.serialization.Codec;
import net.minecraft.util.registry.DynamicRegistryManager;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryKey;
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.ModifyVariable;

@Mixin(DynamicRegistryManager.class)
public interface DynamicRegistryManagerMixin {
@Shadow
private static <E> void register(ImmutableMap.Builder<RegistryKey<? extends Registry<?>>, DynamicRegistryManager.Info<?>> infosBuilder, RegistryKey<? extends Registry<E>> registryRef, Codec<E> entryCodec) {}

@SuppressWarnings("InvalidInjectorMethodSignature")
@ModifyVariable(method = "method_30531", at = @At("STORE"))
private static ImmutableMap.Builder<RegistryKey<? extends Registry<?>>, DynamicRegistryManager.Info<?>> addInfos(ImmutableMap.Builder<RegistryKey<? extends Registry<?>>, DynamicRegistryManager.Info<?>> builder) {
register(builder, CulinaireRegistries.TEA_FLAVOR.getKey(), TeaFlavor.CODEC);
return builder;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

import com.hugman.culinaire.init.TeaBundle;
import com.hugman.culinaire.objects.block.entity.KettleBlockEntity;
import com.hugman.culinaire.objects.item.tea.TeaHelper;
import com.hugman.culinaire.objects.item.tea.TeaType;
import com.hugman.culinaire.objects.tea.TeaType;
import net.minecraft.block.Block;
import net.minecraft.block.BlockRenderType;
import net.minecraft.block.BlockState;
Expand Down Expand Up @@ -179,7 +178,9 @@ else if(stack.getItem() == Items.GLASS_BOTTLE && kettle.getFluid() == KettleBloc
List<TeaType> teaTypes = kettle.getTeaTypes();
if(kettle.removeFluid(1)) {
openScreen = false;
player.setStackInHand(hand, ItemUsage.exchangeStack(stack, player, TeaHelper.appendTeaTypes(new ItemStack(TeaBundle.TEA_BOTTLE), teaTypes)));
ItemStack newStack = new ItemStack(TeaBundle.TEA_BOTTLE);
TeaType.addToStack(newStack, teaTypes);
player.setStackInHand(hand, ItemUsage.exchangeStack(stack, player, newStack));
player.incrementStat(Stats.USED.getOrCreateStat(stack.getItem()));
world.playSound(null, pos, TeaBundle.TEA_BOTTLE_FILL_SOUND.getSound(), SoundCategory.BLOCKS, 1.0F, 1.0F);
world.emitGameEvent(null, GameEvent.FLUID_PICKUP, pos);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
import com.hugman.culinaire.init.data.CulinaireTags;
import com.hugman.culinaire.objects.block.KettleBlock;
import com.hugman.culinaire.objects.item.TeaBagItem;
import com.hugman.culinaire.objects.item.tea.TeaHelper;
import com.hugman.culinaire.objects.item.tea.TeaType;
import com.hugman.culinaire.objects.screen.handler.KettleScreenHandler;
import com.hugman.culinaire.objects.tea.TeaType;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.LockableContainerBlockEntity;
import net.minecraft.entity.player.PlayerEntity;
Expand Down Expand Up @@ -61,7 +60,7 @@ public int get(int index) {
case 2 -> KettleBlockEntity.this.fluidLevel;
case 3 -> KettleBlockEntity.this.fluid.ordinal();
case 4 -> KettleBlockEntity.this.isHot ? 1 : 0;
case 5 -> TeaHelper.getColor(KettleBlockEntity.this.teaTypes);
case 5 -> TeaType.getColor(KettleBlockEntity.this.teaTypes);
default -> 0;
};
}
Expand Down Expand Up @@ -159,7 +158,7 @@ protected Text getContainerName() {

private void brew(World world, ItemStack stack) {
this.fluid = Fluid.TEA;
this.teaTypes = TeaHelper.getTeaTypesByCompound(stack.getNbt());
this.teaTypes = TeaType.fromStack(stack);
stack.decrement(1);
if(stack.getItem().hasRecipeRemainder()) {
ItemStack remainderStack = new ItemStack(stack.getItem().getRecipeRemainder());
Expand Down Expand Up @@ -285,7 +284,7 @@ public boolean canPlayerUse(PlayerEntity player) {
@Override
public boolean isValid(int slot, ItemStack stack) {
if(stack.getItem() instanceof TeaBagItem) {
return !TeaHelper.getTeaTypesByCompound(stack.getNbt()).isEmpty();
return !TeaType.fromStack(stack).isEmpty();
}
else {
return false;
Expand All @@ -297,17 +296,17 @@ public boolean canBrew(ItemStack stack) {
return false;
}
else if(stack.getItem() instanceof TeaBagItem) {
return !TeaHelper.getTeaTypesByCompound(stack.getNbt()).isEmpty() && this.fluid == Fluid.WATER && this.fluidLevel >= 1 && this.isHot;
return !TeaType.fromStack(stack).isEmpty() && this.fluid == Fluid.WATER && this.fluidLevel >= 1 && this.isHot;
}
else {
return false;
}
}

public int getBrewTime(ItemStack stack) {
List<TeaType> teaTypeList = TeaHelper.getTeaTypesByCompound(stack.getNbt());
List<TeaType> teaTypeList = TeaType.fromStack(stack);
if(!teaTypeList.isEmpty()) {
return teaTypeList.stream().mapToInt(TeaType::getBrewTime).sum();
return teaTypeList.stream().mapToInt(value -> value.potency().brewTime()).sum();
}
return 0;
}
Expand All @@ -324,8 +323,8 @@ public void readNbt(NbtCompound tag) {
if(!teaTypeList.isEmpty()) {
for(int i = 0; i < teaTypeList.size(); ++i) {
NbtCompound typeTag = teaTypeList.getCompound(i);
TeaType teaType = new TeaType(typeTag.getString("Strength"), typeTag.getString("Flavor"));
if(teaType.isCorrect()) {
TeaType teaType = TeaType.fromNbt(typeTag);
if(teaType != null) {
teaTypes.add(teaType);
}
}
Expand All @@ -341,10 +340,7 @@ public void writeNbt(NbtCompound tag) {
tag.putByte("FluidLevel", (byte) this.fluidLevel);
NbtList listTag = new NbtList();
for(TeaType teaType : teaTypes) {
NbtCompound typeTag = new NbtCompound();
typeTag.putString("Flavor", teaType.getFlavor().getName());
typeTag.putString("Strength", teaType.getStrength().getName());
listTag.add(typeTag);
listTag.add(teaType.toNbt());
}
tag.put("TeaTypes", listTag);
}
Expand Down
20 changes: 12 additions & 8 deletions src/main/java/com/hugman/culinaire/objects/item/TeaBagItem.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.hugman.culinaire.objects.item;

import com.hugman.culinaire.objects.item.tea.TeaHelper;
import com.hugman.culinaire.objects.item.tea.TeaType;
import com.hugman.culinaire.objects.tea.TeaFlavorManager;
import com.hugman.culinaire.objects.tea.TeaType;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.item.TooltipContext;
Expand All @@ -23,20 +23,24 @@ public TeaBagItem(Settings settings) {
@Override
@Environment(EnvType.CLIENT)
public void appendTooltip(ItemStack stack, @Nullable World world, List<Text> tooltip, TooltipContext context) {
TeaHelper.appendTeaTooltip(tooltip, TeaHelper.getTeaTypesByCompound(stack.getNbt()));
TeaType.appendTooltip(tooltip, TeaType.fromStack(stack));
}

@Override
public void appendStacks(ItemGroup group, DefaultedList<ItemStack> stacks) {
if(group == ItemGroup.SEARCH) {
for(TeaType teaType : TeaHelper.getAllTypes()) {
stacks.add(TeaHelper.appendTeaType(new ItemStack(this), teaType));
for(TeaType teaType : TeaType.getAll()) {
ItemStack stack = new ItemStack(this);
teaType.addToStack(stack);
stacks.add(stack);
}
}
else if(this.isIn(group)) {
for(TeaType.Flavor flavor : TeaType.Flavor.values()) {
stacks.add(TeaHelper.appendTeaType(new ItemStack(this), new TeaType(TeaType.Strength.NORMAL, flavor)));
}
TeaFlavorManager.getAll().forEach(flavor -> {
ItemStack stack = new ItemStack(this);
TeaType.withMiddlePotency(flavor).addToStack(stack);
stacks.add(stack);
});
}
}
}
Loading