Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package growthcraft.cellar.block;

import growthcraft.cellar.block.entity.FermentationBarrelBlockEntity;
import growthcraft.milk.init.GrowthcraftMilkFluids;
import growthcraft.milk.item.GrowthcraftMilkBucketItem;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.Containers;
Expand All @@ -10,6 +12,7 @@
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.BottleItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
Expand All @@ -31,6 +34,8 @@
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.neoforged.neoforge.fluids.FluidUtil;
import net.neoforged.neoforge.fluids.FluidStack;
import net.neoforged.neoforge.fluids.capability.IFluidHandler;
import org.jetbrains.annotations.Nullable;

public class FermentationBarrelBlock extends Block implements EntityBlock {
Expand Down Expand Up @@ -85,6 +90,10 @@ protected InteractionResult useWithoutItem(BlockState state, Level level, BlockP

@Override
protected ItemInteractionResult useItemOn(ItemStack heldStack, BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hitResult) {
if (tryMilkBucketInteraction(heldStack, level, pos, player, hand)) {
return ItemInteractionResult.sidedSuccess(level.isClientSide);
}

if (heldStack.getItem() instanceof BottleItem) {
BlockEntity blockEntity = level.getBlockEntity(pos);
if (blockEntity instanceof FermentationBarrelBlockEntity barrel && !barrel.getResultingPotionItemStack().isEmpty()) {
Expand All @@ -101,6 +110,26 @@ protected ItemInteractionResult useItemOn(ItemStack heldStack, BlockState state,
return ItemInteractionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION;
}

private static boolean tryMilkBucketInteraction(ItemStack heldStack, Level level, BlockPos pos, Player player, InteractionHand hand) {
boolean vanillaMilk = heldStack.is(Items.MILK_BUCKET);
boolean growthcraftMilk = heldStack.getItem() instanceof GrowthcraftMilkBucketItem;
if (!vanillaMilk && !growthcraftMilk) {
return false;
}

if (!level.isClientSide && level.getBlockEntity(pos) instanceof FermentationBarrelBlockEntity barrel) {
int filled = barrel.getTank().fill(new FluidStack(GrowthcraftMilkFluids.MILK.source.get(), 1000),
IFluidHandler.FluidAction.EXECUTE);
if (filled == 1000 && !player.getAbilities().instabuild) {
ItemStack remainder = vanillaMilk
? new ItemStack(Items.BUCKET)
: heldStack.getCraftingRemainingItem();
player.setItemInHand(hand, remainder);
}
}
return true;
}

private void fillBottleFromBarrel(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, ItemStack heldStack, FermentationBarrelBlockEntity barrel) {
ItemStack result = barrel.getResultingPotionItemStack();
if (result.isEmpty()) return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
{
"type": "growthcraft_cellar:fermentation_barrel_recipe",
"neoforge:conditions": [
{
"type": "neoforge:false"
}
],
"processing_time": 1200,
"ingredient_item": {
"item": "growthcraft_cellar:yeast_brewers",
Expand All @@ -21,8 +16,8 @@
"effects": [
{
"effect": "minecraft:resistance",
"duration": 3600,
"amplifier": 1
"duration": 6000,
"amplifier": 0
}
],
"bottle": {
Expand Down
Loading