/* * Decompiled with CFR 0.152. * * Could not load the following classes: * com.google.common.collect.Maps * com.mojang.datafixers.kinds.App * com.mojang.datafixers.kinds.Applicative * com.mojang.serialization.MapCodec * com.mojang.serialization.codecs.RecordCodecBuilder */ package net.minecraft.world.level.block; import com.google.common.collect.Maps; import com.mojang.datafixers.kinds.App; import com.mojang.datafixers.kinds.Applicative; import com.mojang.serialization.MapCodec; import com.mojang.serialization.codecs.RecordCodecBuilder; import java.util.List; import java.util.Map; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.tags.BlockTags; import net.minecraft.util.RandomSource; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; import net.minecraft.world.level.LevelReader; import net.minecraft.world.level.ScheduledTickAccess; import net.minecraft.world.level.block.AbstractCandleBlock; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.CakeBlock; import net.minecraft.world.level.block.CandleBlock; import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.properties.BooleanProperty; import net.minecraft.world.level.pathfinder.PathComputationType; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.Shapes; import net.minecraft.world.phys.shapes.VoxelShape; public class CandleCakeBlock extends AbstractCandleBlock { public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(i -> i.group((App)BuiltInRegistries.BLOCK.byNameCodec().fieldOf("candle").forGetter(b -> b.candleBlock), CandleCakeBlock.propertiesCodec()).apply((Applicative)i, CandleCakeBlock::new)); public static final BooleanProperty LIT = AbstractCandleBlock.LIT; private static final VoxelShape SHAPE = Shapes.or(Block.column(2.0, 8.0, 14.0), Block.column(14.0, 0.0, 8.0)); private static final Map BY_CANDLE = Maps.newHashMap(); private static final Iterable PARTICLE_OFFSETS = List.of(new Vec3(8.0, 16.0, 8.0).scale(0.0625)); private final CandleBlock candleBlock; public MapCodec codec() { return CODEC; } protected CandleCakeBlock(Block block, BlockBehaviour.Properties properties) { super(properties); this.registerDefaultState((BlockState)((BlockState)this.stateDefinition.any()).setValue(LIT, false)); if (!(block instanceof CandleBlock)) { throw new IllegalArgumentException("Expected block to be of " + String.valueOf(CandleBlock.class) + " was " + String.valueOf(block.getClass())); } CandleBlock matchingCandleBlock = (CandleBlock)block; BY_CANDLE.put(matchingCandleBlock, this); this.candleBlock = matchingCandleBlock; } @Override protected Iterable getParticleOffsets(BlockState state) { return PARTICLE_OFFSETS; } @Override protected VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) { return SHAPE; } @Override protected InteractionResult useItemOn(ItemStack itemStack, BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hitResult) { if (itemStack.is(Items.FLINT_AND_STEEL) || itemStack.is(Items.FIRE_CHARGE)) { return InteractionResult.PASS; } if (CandleCakeBlock.candleHit(hitResult) && itemStack.isEmpty() && state.getValue(LIT).booleanValue()) { CandleCakeBlock.extinguish(player, state, level, pos); return InteractionResult.SUCCESS; } return super.useItemOn(itemStack, state, level, pos, player, hand, hitResult); } @Override protected InteractionResult useWithoutItem(BlockState state, Level level, BlockPos pos, Player player, BlockHitResult hitResult) { InteractionResult eatResult = CakeBlock.eat(level, pos, Blocks.CAKE.defaultBlockState(), player); if (eatResult.consumesAction()) { CandleCakeBlock.dropResources(state, level, pos); } return eatResult; } private static boolean candleHit(BlockHitResult hitResult) { return hitResult.getLocation().y - (double)hitResult.getBlockPos().getY() > 0.5; } @Override protected void createBlockStateDefinition(StateDefinition.Builder builder) { builder.add(LIT); } @Override protected ItemStack getCloneItemStack(LevelReader level, BlockPos pos, BlockState state, boolean includeData) { return new ItemStack(Blocks.CAKE); } @Override protected BlockState updateShape(BlockState state, LevelReader level, ScheduledTickAccess ticks, BlockPos pos, Direction directionToNeighbour, BlockPos neighbourPos, BlockState neighbourState, RandomSource random) { if (directionToNeighbour == Direction.DOWN && !state.canSurvive(level, pos)) { return Blocks.AIR.defaultBlockState(); } return super.updateShape(state, level, ticks, pos, directionToNeighbour, neighbourPos, neighbourState, random); } @Override protected boolean canSurvive(BlockState state, LevelReader level, BlockPos pos) { return level.getBlockState(pos.below()).isSolid(); } @Override protected int getAnalogOutputSignal(BlockState state, Level level, BlockPos pos, Direction direction) { return CakeBlock.FULL_CAKE_SIGNAL; } @Override protected boolean hasAnalogOutputSignal(BlockState state) { return true; } @Override protected boolean isPathfindable(BlockState state, PathComputationType type) { return false; } public static BlockState byCandle(CandleBlock block) { return BY_CANDLE.get(block).defaultBlockState(); } public static boolean canLight(BlockState state) { return state.is(BlockTags.CANDLE_CAKES, s -> s.hasProperty(LIT) && state.getValue(LIT) == false); } }