103 lines
3.8 KiB
Java
103 lines
3.8 KiB
Java
package net.minecraft.world.level.block;
|
|
|
|
import com.mojang.serialization.MapCodec;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.core.cauldron.CauldronInteraction;
|
|
import net.minecraft.server.level.ServerLevel;
|
|
import net.minecraft.util.RandomSource;
|
|
import net.minecraft.world.InteractionHand;
|
|
import net.minecraft.world.ItemInteractionResult;
|
|
import net.minecraft.world.entity.Entity;
|
|
import net.minecraft.world.entity.player.Player;
|
|
import net.minecraft.world.item.ItemStack;
|
|
import net.minecraft.world.level.BlockGetter;
|
|
import net.minecraft.world.level.Level;
|
|
import net.minecraft.world.level.block.state.BlockBehaviour;
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
import net.minecraft.world.level.material.Fluid;
|
|
import net.minecraft.world.level.material.Fluids;
|
|
import net.minecraft.world.level.pathfinder.PathComputationType;
|
|
import net.minecraft.world.phys.BlockHitResult;
|
|
import net.minecraft.world.phys.shapes.BooleanOp;
|
|
import net.minecraft.world.phys.shapes.CollisionContext;
|
|
import net.minecraft.world.phys.shapes.Shapes;
|
|
import net.minecraft.world.phys.shapes.VoxelShape;
|
|
|
|
public abstract class AbstractCauldronBlock extends Block {
|
|
private static final int SIDE_THICKNESS = 2;
|
|
private static final int LEG_WIDTH = 4;
|
|
private static final int LEG_HEIGHT = 3;
|
|
private static final int LEG_DEPTH = 2;
|
|
protected static final int FLOOR_LEVEL = 4;
|
|
private static final VoxelShape INSIDE = box(2.0, 4.0, 2.0, 14.0, 16.0, 14.0);
|
|
protected static final VoxelShape SHAPE = Shapes.join(
|
|
Shapes.block(),
|
|
Shapes.or(box(0.0, 0.0, 4.0, 16.0, 3.0, 12.0), box(4.0, 0.0, 0.0, 12.0, 3.0, 16.0), box(2.0, 0.0, 2.0, 14.0, 3.0, 14.0), INSIDE),
|
|
BooleanOp.ONLY_FIRST
|
|
);
|
|
protected final CauldronInteraction.InteractionMap interactions;
|
|
|
|
@Override
|
|
protected abstract MapCodec<? extends AbstractCauldronBlock> codec();
|
|
|
|
public AbstractCauldronBlock(BlockBehaviour.Properties properties, CauldronInteraction.InteractionMap interactions) {
|
|
super(properties);
|
|
this.interactions = interactions;
|
|
}
|
|
|
|
protected double getContentHeight(BlockState state) {
|
|
return 0.0;
|
|
}
|
|
|
|
protected boolean isEntityInsideContent(BlockState state, BlockPos pos, Entity entity) {
|
|
return entity.getY() < pos.getY() + this.getContentHeight(state) && entity.getBoundingBox().maxY > pos.getY() + 0.25;
|
|
}
|
|
|
|
@Override
|
|
protected ItemInteractionResult useItemOn(
|
|
ItemStack stack, BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hitResult
|
|
) {
|
|
CauldronInteraction cauldronInteraction = (CauldronInteraction)this.interactions.map().get(stack.getItem());
|
|
return cauldronInteraction.interact(state, level, pos, player, hand, stack);
|
|
}
|
|
|
|
@Override
|
|
protected VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
|
|
return SHAPE;
|
|
}
|
|
|
|
@Override
|
|
protected VoxelShape getInteractionShape(BlockState state, BlockGetter level, BlockPos pos) {
|
|
return INSIDE;
|
|
}
|
|
|
|
@Override
|
|
protected boolean hasAnalogOutputSignal(BlockState state) {
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
protected boolean isPathfindable(BlockState state, PathComputationType pathComputationType) {
|
|
return false;
|
|
}
|
|
|
|
public abstract boolean isFull(BlockState state);
|
|
|
|
@Override
|
|
protected void tick(BlockState state, ServerLevel level, BlockPos pos, RandomSource random) {
|
|
BlockPos blockPos = PointedDripstoneBlock.findStalactiteTipAboveCauldron(level, pos);
|
|
if (blockPos != null) {
|
|
Fluid fluid = PointedDripstoneBlock.getCauldronFillFluidType(level, blockPos);
|
|
if (fluid != Fluids.EMPTY && this.canReceiveStalactiteDrip(fluid)) {
|
|
this.receiveStalactiteDrip(state, level, pos, fluid);
|
|
}
|
|
}
|
|
}
|
|
|
|
protected boolean canReceiveStalactiteDrip(Fluid fluid) {
|
|
return false;
|
|
}
|
|
|
|
protected void receiveStalactiteDrip(BlockState state, Level level, BlockPos pos, Fluid fluid) {
|
|
}
|
|
}
|