2025-11-24 22:52:51 +03:00

76 lines
2.8 KiB
Java

/*
* Decompiled with CFR 0.152.
*
* Could not load the following classes:
* com.mojang.serialization.MapCodec
* org.jspecify.annotations.Nullable
*/
package net.minecraft.world.level.block;
import com.mojang.serialization.MapCodec;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.tags.EnchantmentTags;
import net.minecraft.util.RandomSource;
import net.minecraft.world.attribute.EnvironmentAttributes;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LightLayer;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.HalfTransparentBlock;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import org.jspecify.annotations.Nullable;
public class IceBlock
extends HalfTransparentBlock {
public static final MapCodec<IceBlock> CODEC = IceBlock.simpleCodec(IceBlock::new);
public MapCodec<? extends IceBlock> codec() {
return CODEC;
}
public IceBlock(BlockBehaviour.Properties properties) {
super(properties);
}
public static BlockState meltsInto() {
return Blocks.WATER.defaultBlockState();
}
@Override
public void playerDestroy(Level level, Player player, BlockPos pos, BlockState state, @Nullable BlockEntity blockEntity, ItemStack destroyedWith) {
super.playerDestroy(level, player, pos, state, blockEntity, destroyedWith);
if (!EnchantmentHelper.hasTag(destroyedWith, EnchantmentTags.PREVENTS_ICE_MELTING)) {
if (level.environmentAttributes().getValue(EnvironmentAttributes.WATER_EVAPORATES, pos).booleanValue()) {
level.removeBlock(pos, false);
return;
}
BlockState belowState = level.getBlockState(pos.below());
if (belowState.blocksMotion() || belowState.liquid()) {
level.setBlockAndUpdate(pos, IceBlock.meltsInto());
}
}
}
@Override
protected void randomTick(BlockState state, ServerLevel level, BlockPos pos, RandomSource random) {
if (level.getBrightness(LightLayer.BLOCK, pos) > 11 - state.getLightBlock()) {
this.melt(state, level, pos);
}
}
protected void melt(BlockState state, Level level, BlockPos pos) {
if (level.environmentAttributes().getValue(EnvironmentAttributes.WATER_EVAPORATES, pos).booleanValue()) {
level.removeBlock(pos, false);
return;
}
level.setBlockAndUpdate(pos, IceBlock.meltsInto());
level.neighborChanged(pos, IceBlock.meltsInto().getBlock(), null);
}
}