133 lines
5.8 KiB
Java
133 lines
5.8 KiB
Java
/*
|
|
* Decompiled with CFR 0.152.
|
|
*
|
|
* Could not load the following classes:
|
|
* com.mojang.datafixers.kinds.App
|
|
* com.mojang.datafixers.kinds.Applicative
|
|
* com.mojang.serialization.MapCodec
|
|
* com.mojang.serialization.codecs.RecordCodecBuilder
|
|
* org.jspecify.annotations.Nullable
|
|
*/
|
|
package net.minecraft.world.level.block;
|
|
|
|
import com.mojang.datafixers.kinds.App;
|
|
import com.mojang.datafixers.kinds.Applicative;
|
|
import com.mojang.serialization.MapCodec;
|
|
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.core.Direction;
|
|
import net.minecraft.core.particles.BlockParticleOption;
|
|
import net.minecraft.core.particles.ParticleTypes;
|
|
import net.minecraft.core.registries.BuiltInRegistries;
|
|
import net.minecraft.server.level.ServerLevel;
|
|
import net.minecraft.sounds.SoundEvent;
|
|
import net.minecraft.util.RandomSource;
|
|
import net.minecraft.world.entity.Entity;
|
|
import net.minecraft.world.entity.item.FallingBlockEntity;
|
|
import net.minecraft.world.level.Level;
|
|
import net.minecraft.world.level.LevelReader;
|
|
import net.minecraft.world.level.ScheduledTickAccess;
|
|
import net.minecraft.world.level.block.BaseEntityBlock;
|
|
import net.minecraft.world.level.block.Block;
|
|
import net.minecraft.world.level.block.Fallable;
|
|
import net.minecraft.world.level.block.FallingBlock;
|
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
|
import net.minecraft.world.level.block.entity.BrushableBlockEntity;
|
|
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.BlockStateProperties;
|
|
import net.minecraft.world.level.block.state.properties.IntegerProperty;
|
|
import net.minecraft.world.level.gameevent.GameEvent;
|
|
import net.minecraft.world.phys.Vec3;
|
|
import org.jspecify.annotations.Nullable;
|
|
|
|
public class BrushableBlock
|
|
extends BaseEntityBlock
|
|
implements Fallable {
|
|
public static final MapCodec<BrushableBlock> CODEC = RecordCodecBuilder.mapCodec(i -> i.group((App)BuiltInRegistries.BLOCK.byNameCodec().fieldOf("turns_into").forGetter(BrushableBlock::getTurnsInto), (App)BuiltInRegistries.SOUND_EVENT.byNameCodec().fieldOf("brush_sound").forGetter(BrushableBlock::getBrushSound), (App)BuiltInRegistries.SOUND_EVENT.byNameCodec().fieldOf("brush_completed_sound").forGetter(BrushableBlock::getBrushCompletedSound), BrushableBlock.propertiesCodec()).apply((Applicative)i, BrushableBlock::new));
|
|
private static final IntegerProperty DUSTED = BlockStateProperties.DUSTED;
|
|
public static final int TICK_DELAY = 2;
|
|
private final Block turnsInto;
|
|
private final SoundEvent brushSound;
|
|
private final SoundEvent brushCompletedSound;
|
|
|
|
public MapCodec<BrushableBlock> codec() {
|
|
return CODEC;
|
|
}
|
|
|
|
public BrushableBlock(Block turnsInto, SoundEvent brushSound, SoundEvent brushCompletedSound, BlockBehaviour.Properties properties) {
|
|
super(properties);
|
|
this.turnsInto = turnsInto;
|
|
this.brushSound = brushSound;
|
|
this.brushCompletedSound = brushCompletedSound;
|
|
this.registerDefaultState((BlockState)((BlockState)this.stateDefinition.any()).setValue(DUSTED, 0));
|
|
}
|
|
|
|
@Override
|
|
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
|
|
builder.add(DUSTED);
|
|
}
|
|
|
|
@Override
|
|
public void onPlace(BlockState state, Level level, BlockPos pos, BlockState oldState, boolean movedByPiston) {
|
|
level.scheduleTick(pos, this, 2);
|
|
}
|
|
|
|
@Override
|
|
public BlockState updateShape(BlockState state, LevelReader level, ScheduledTickAccess ticks, BlockPos pos, Direction directionToNeighbour, BlockPos neighbourPos, BlockState neighbourState, RandomSource random) {
|
|
ticks.scheduleTick(pos, this, 2);
|
|
return super.updateShape(state, level, ticks, pos, directionToNeighbour, neighbourPos, neighbourState, random);
|
|
}
|
|
|
|
@Override
|
|
public void tick(BlockState state, ServerLevel level, BlockPos pos, RandomSource random) {
|
|
BlockEntity blockEntity = level.getBlockEntity(pos);
|
|
if (blockEntity instanceof BrushableBlockEntity) {
|
|
BrushableBlockEntity brushableBlockEntity = (BrushableBlockEntity)blockEntity;
|
|
brushableBlockEntity.checkReset(level);
|
|
}
|
|
if (!FallingBlock.isFree(level.getBlockState(pos.below())) || pos.getY() < level.getMinY()) {
|
|
return;
|
|
}
|
|
FallingBlockEntity entity = FallingBlockEntity.fall(level, pos, state);
|
|
entity.disableDrop();
|
|
}
|
|
|
|
@Override
|
|
public void onBrokenAfterFall(Level level, BlockPos pos, FallingBlockEntity entity) {
|
|
Vec3 centerOfEntity = entity.getBoundingBox().getCenter();
|
|
level.levelEvent(2001, BlockPos.containing(centerOfEntity), Block.getId(entity.getBlockState()));
|
|
level.gameEvent((Entity)entity, GameEvent.BLOCK_DESTROY, centerOfEntity);
|
|
}
|
|
|
|
@Override
|
|
public void animateTick(BlockState state, Level level, BlockPos pos, RandomSource random) {
|
|
BlockPos below;
|
|
if (random.nextInt(16) == 0 && FallingBlock.isFree(level.getBlockState(below = pos.below()))) {
|
|
double xx = (double)pos.getX() + random.nextDouble();
|
|
double yy = (double)pos.getY() - 0.05;
|
|
double zz = (double)pos.getZ() + random.nextDouble();
|
|
level.addParticle(new BlockParticleOption(ParticleTypes.FALLING_DUST, state), xx, yy, zz, 0.0, 0.0, 0.0);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public @Nullable BlockEntity newBlockEntity(BlockPos worldPosition, BlockState blockState) {
|
|
return new BrushableBlockEntity(worldPosition, blockState);
|
|
}
|
|
|
|
public Block getTurnsInto() {
|
|
return this.turnsInto;
|
|
}
|
|
|
|
public SoundEvent getBrushSound() {
|
|
return this.brushSound;
|
|
}
|
|
|
|
public SoundEvent getBrushCompletedSound() {
|
|
return this.brushCompletedSound;
|
|
}
|
|
}
|
|
|