minecraft-source/src/net/minecraft/world/level/block/RedStoneOreBlock.java

114 lines
4.9 KiB
Java

package net.minecraft.world.level.block;
import net.minecraft.world.level.block.state.AbstractStateHolder;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.core.particles.DustParticleOptions;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.core.Direction;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.world.item.ItemStack;
import java.util.Random;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
public class RedStoneOreBlock extends Block {
public static final BooleanProperty LIT;
public RedStoneOreBlock(final Properties c) {
super(c);
this.registerDefaultState(((AbstractStateHolder<O, BlockState>)this.defaultBlockState()).<Comparable, Boolean>setValue((Property<Comparable>)RedStoneOreBlock.LIT, false));
}
@Override
public int getLightEmission(final BlockState byg) {
return byg.<Boolean>getValue((Property<Boolean>)RedStoneOreBlock.LIT) ? super.getLightEmission(byg) : 0;
}
@Override
public void attack(final BlockState byg, final Level bjt, final BlockPos fk, final Player ayg) {
interact(byg, bjt, fk);
super.attack(byg, bjt, fk, ayg);
}
@Override
public void stepOn(final Level bjt, final BlockPos fk, final Entity akn) {
interact(bjt.getBlockState(fk), bjt, fk);
super.stepOn(bjt, fk, akn);
}
@Override
public InteractionResult use(final BlockState byg, final Level bjt, final BlockPos fk, final Player ayg, final InteractionHand ajh, final BlockHitResult cvd) {
if (bjt.isClientSide) {
spawnParticles(bjt, fk);
return InteractionResult.SUCCESS;
}
interact(byg, bjt, fk);
return InteractionResult.PASS;
}
private static void interact(final BlockState byg, final Level bjt, final BlockPos fk) {
spawnParticles(bjt, fk);
if (!byg.<Boolean>getValue((Property<Boolean>)RedStoneOreBlock.LIT)) {
bjt.setBlock(fk, ((AbstractStateHolder<O, BlockState>)byg).<Comparable, Boolean>setValue((Property<Comparable>)RedStoneOreBlock.LIT, true), 3);
}
}
@Override
public void tick(final BlockState byg, final ServerLevel xd, final BlockPos fk, final Random random) {
if (byg.<Boolean>getValue((Property<Boolean>)RedStoneOreBlock.LIT)) {
xd.setBlock(fk, ((AbstractStateHolder<O, BlockState>)byg).<Comparable, Boolean>setValue((Property<Comparable>)RedStoneOreBlock.LIT, false), 3);
}
}
@Override
public void spawnAfterBreak(final BlockState byg, final Level bjt, final BlockPos fk, final ItemStack bek) {
super.spawnAfterBreak(byg, bjt, fk, bek);
if (EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, bek) == 0) {
final int integer6 = 1 + bjt.random.nextInt(5);
this.popExperience(bjt, fk, integer6);
}
}
@Override
public void animateTick(final BlockState byg, final Level bjt, final BlockPos fk, final Random random) {
if (byg.<Boolean>getValue((Property<Boolean>)RedStoneOreBlock.LIT)) {
spawnParticles(bjt, fk);
}
}
private static void spawnParticles(final Level bjt, final BlockPos fk) {
final double double3 = 0.5625;
final Random random5 = bjt.random;
for (final Direction fp9 : Direction.values()) {
final BlockPos fk2 = fk.relative(fp9);
if (!bjt.getBlockState(fk2).isSolidRender(bjt, fk2)) {
final Direction.Axis a11 = fp9.getAxis();
final double double4 = (a11 == Direction.Axis.X) ? (0.5 + 0.5625 * fp9.getStepX()) : random5.nextFloat();
final double double5 = (a11 == Direction.Axis.Y) ? (0.5 + 0.5625 * fp9.getStepY()) : random5.nextFloat();
final double double6 = (a11 == Direction.Axis.Z) ? (0.5 + 0.5625 * fp9.getStepZ()) : random5.nextFloat();
bjt.addParticle(DustParticleOptions.REDSTONE, fk.getX() + double4, fk.getY() + double5, fk.getZ() + double6, 0.0, 0.0, 0.0);
}
}
}
@Override
protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> a) {
a.add(RedStoneOreBlock.LIT);
}
static {
LIT = RedstoneTorchBlock.LIT;
}
}