Skip to content

Commit

Permalink
Require fire to make soup or potions
Browse files Browse the repository at this point in the history
  • Loading branch information
KnightMiner committed Nov 1, 2022
1 parent 9faee85 commit 3fe26de
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 43 deletions.
Expand Up @@ -348,16 +348,16 @@ void commonSetup(FMLCommonSetupEvent event) {

// making the soup
// mushroom: slight discount (6 mushrooms for 4 bowls) and can use either mushroom (but not both)
CauldronInteraction mushroomTransform = new TransformCauldronInteraction(2, LayeredCauldronBlock.LEVEL, mushroomStewCauldron);
CauldronInteraction mushroomTransform = new TransformCauldronInteraction(true, 2, LayeredCauldronBlock.LEVEL, mushroomStewCauldron);
CauldronInteraction.WATER.put(Items.BROWN_MUSHROOM, mushroomTransform);
CauldronInteraction.WATER.put(Items.RED_MUSHROOM, mushroomTransform);
CauldronRegistry.register(exactBlock(Blocks.WATER_CAULDRON), itemTag(Tags.Items.MUSHROOMS), mushroomTransform);
// potato: slight discount, 4 bowls only costs 6 potatoes instead of 8. Uses 2 more mushrooms
MUSHROOM_STEW_CAULDRON_INTERACTIONS.put(Items.BAKED_POTATO, new TransformCauldronInteraction(2, FourLayerCauldronBlock.LEVEL, potatoSoupCauldron));
MUSHROOM_STEW_CAULDRON_INTERACTIONS.put(Items.BAKED_POTATO, new TransformCauldronInteraction(true, 2, FourLayerCauldronBlock.LEVEL, potatoSoupCauldron));
// rabbit: slight discount, 4 bowls only costs 3 rabbit instead of 4 and does not need carrot. Uses 2 more mushroom
POTATO_SOUP_CAULDRON_INTERACTIONS.put(Items.COOKED_RABBIT, new TransformCauldronInteraction(1, FourLayerCauldronBlock.LEVEL, rabbitStewCauldron));
POTATO_SOUP_CAULDRON_INTERACTIONS.put(Items.COOKED_RABBIT, new TransformCauldronInteraction(true, 1, FourLayerCauldronBlock.LEVEL, rabbitStewCauldron));
// rabbit: slight discount, 4 bowls only costs 18 beetroot instead of 24
CauldronInteraction.WATER.put(Items.BEETROOT, new TransformCauldronInteraction(6, LayeredCauldronBlock.LEVEL, beetrootSoupCauldron));
CauldronInteraction.WATER.put(Items.BEETROOT, new TransformCauldronInteraction(true, 6, LayeredCauldronBlock.LEVEL, beetrootSoupCauldron));

// honey bottles
CauldronInteraction.EMPTY.put(Items.HONEY_BOTTLE, new FillCauldronInteraction(honeyCauldron, 1, Items.GLASS_BOTTLE));
Expand Down
@@ -1,5 +1,6 @@
package knightminer.inspirations.recipes.cauldron;

import knightminer.inspirations.library.InspirationsTags;
import knightminer.inspirations.library.MiscUtil;
import knightminer.inspirations.recipes.block.FourLayerCauldronBlock;
import net.minecraft.core.BlockPos;
Expand All @@ -18,13 +19,16 @@
import net.minecraft.world.level.block.state.properties.IntegerProperty;

/** Transforms a cauldron into another cauldron */
public record TransformCauldronInteraction(int needed, IntegerProperty oldProp, FourLayerCauldronBlock block, SoundEvent sound) implements CauldronInteraction {
public TransformCauldronInteraction(int needed, IntegerProperty oldProp, FourLayerCauldronBlock block) {
this(needed, oldProp, block, SoundEvents.BREWING_STAND_BREW);
public record TransformCauldronInteraction(boolean requireFire, int needed, IntegerProperty oldProp, FourLayerCauldronBlock block, SoundEvent sound) implements CauldronInteraction {
public TransformCauldronInteraction(boolean requireFire, int needed, IntegerProperty oldProp, FourLayerCauldronBlock block) {
this(requireFire, needed, oldProp, block, SoundEvents.BREWING_STAND_BREW);
}

@Override
public InteractionResult interact(BlockState state, Level level, BlockPos pos, Player player, InteractionHand pHand, ItemStack stack) {
if (requireFire && !level.getBlockState(pos.below()).is(InspirationsTags.Blocks.CAULDRON_FIRE)) {
return InteractionResult.PASS;
}
if (!level.isClientSide) {
int contentLevel = state.getValue(oldProp);
int needed = this.needed * contentLevel;
Expand Down
@@ -1,5 +1,6 @@
package knightminer.inspirations.recipes.cauldron.potion;

import knightminer.inspirations.library.InspirationsTags;
import knightminer.inspirations.library.MiscUtil;
import knightminer.inspirations.recipes.InspirationsRecipes;
import knightminer.inspirations.recipes.block.entity.PotionCauldronBlockEntity;
Expand Down Expand Up @@ -42,49 +43,52 @@ public BrewingCauldronInteraction(@Nullable Potion fixedInput) {

@Override
public InteractionResult interact(BlockState oldState, Level level, BlockPos pos, Player player, InteractionHand hand, ItemStack stack) {
// if given a fixed input, use that
PotionCauldronBlockEntity cauldron = null;
Potion oldPotion = this.fixedInput;
if (oldPotion == null) {
cauldron = InspirationsRecipes.potionCauldronEntity.getBlockEntity(level, pos);
if (cauldron == null) {
return InteractionResult.PASS;
// cauldron needs to be above fire
if (level.getBlockState(pos.below()).is(InspirationsTags.Blocks.CAULDRON_FIRE)) {
// if given a fixed input, use that
PotionCauldronBlockEntity cauldron = null;
Potion oldPotion = this.fixedInput;
if (oldPotion == null) {
cauldron = InspirationsRecipes.potionCauldronEntity.getBlockEntity(level, pos);
if (cauldron == null) {
return InteractionResult.PASS;
}
oldPotion = cauldron.getPotion();
}
oldPotion = cauldron.getPotion();
}

// try both forge and vanilla for result
Potion newPotion = getVanillaResult(oldPotion, stack);
if (newPotion == Potions.EMPTY) {
newPotion = getForgeResult(oldPotion, stack);
}
// found either?
if (newPotion != Potions.EMPTY) {
if (!level.isClientSide) {
// if we have a fixed input, update the cauldron then fetch the BE
if (fixedInput != null) {
// update the block, if already a potion cauldron it will remain one, but it may be water before
level.setBlockAndUpdate(pos, InspirationsRecipes.potionCauldron.defaultBlockState().setValue(LEVEL, oldState.getValue(LEVEL)));
cauldron = InspirationsRecipes.potionCauldronEntity.getBlockEntity(level, pos);
if (cauldron == null) {
return InteractionResult.CONSUME;
// try both forge and vanilla for result
Potion newPotion = getVanillaResult(oldPotion, stack);
if (newPotion == Potions.EMPTY) {
newPotion = getForgeResult(oldPotion, stack);
}
// found either?
if (newPotion != Potions.EMPTY) {
if (!level.isClientSide) {
// if we have a fixed input, update the cauldron then fetch the BE
if (fixedInput != null) {
// update the block, if already a potion cauldron it will remain one, but it may be water before
level.setBlockAndUpdate(pos, InspirationsRecipes.potionCauldron.defaultBlockState().setValue(LEVEL, oldState.getValue(LEVEL)));
cauldron = InspirationsRecipes.potionCauldronEntity.getBlockEntity(level, pos);
if (cauldron == null) {
return InteractionResult.CONSUME;
}
}
}

// update potion
cauldron.setPotion(newPotion);
// update potion
cauldron.setPotion(newPotion);

// consume items
ItemStack container = stack.getContainerItem();
MiscUtil.shrinkHeldItem(player, hand, stack, 1);
if (!container.isEmpty()) {
MiscUtil.givePlayerItem(player, container.copy());
}
// consume items
ItemStack container = stack.getContainerItem();
MiscUtil.shrinkHeldItem(player, hand, stack, 1);
if (!container.isEmpty()) {
MiscUtil.givePlayerItem(player, container.copy());
}

player.awardStat(Stats.USE_CAULDRON);
level.playSound(null, pos, SoundEvents.BREWING_STAND_BREW, SoundSource.BLOCKS, 1.0F, 1.0F);
player.awardStat(Stats.USE_CAULDRON);
level.playSound(null, pos, SoundEvents.BREWING_STAND_BREW, SoundSource.BLOCKS, 1.0F, 1.0F);
}
return InteractionResult.sidedSuccess(level.isClientSide);
}
return InteractionResult.sidedSuccess(level.isClientSide);
}
return InteractionResult.PASS;
}
Expand Down

0 comments on commit 3fe26de

Please sign in to comment.