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

117 lines
5.4 KiB
Java

package net.minecraft.world.level.block;
import net.minecraft.world.level.block.state.AbstractStateHolder;
import com.google.common.collect.Maps;
import com.google.common.collect.ImmutableMap;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.core.particles.ParticleTypes;
import java.util.Random;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import javax.annotation.Nullable;
import net.minecraft.world.item.BlockPlaceContext;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraft.core.Direction;
import java.util.Map;
import net.minecraft.world.level.block.state.properties.DirectionProperty;
public class WallTorchBlock extends TorchBlock {
public static final DirectionProperty FACING;
private static final Map<Direction, VoxelShape> AABBS;
protected WallTorchBlock(final Properties c) {
super(c);
this.registerDefaultState(((AbstractStateHolder<O, BlockState>)this.stateDefinition.any()).<Comparable, Direction>setValue((Property<Comparable>)WallTorchBlock.FACING, Direction.NORTH));
}
@Override
public String getDescriptionId() {
return this.asItem().getDescriptionId();
}
@Override
public VoxelShape getShape(final BlockState byg, final BlockGetter bjd, final BlockPos fk, final CollisionContext cvn) {
return getShape(byg);
}
public static VoxelShape getShape(final BlockState byg) {
return WallTorchBlock.AABBS.get(byg.getValue((Property<Object>)WallTorchBlock.FACING));
}
@Override
public boolean canSurvive(final BlockState byg, final LevelReader bjw, final BlockPos fk) {
final Direction fp5 = byg.<Direction>getValue((Property<Direction>)WallTorchBlock.FACING);
final BlockPos fk2 = fk.relative(fp5.getOpposite());
final BlockState byg2 = bjw.getBlockState(fk2);
return byg2.isFaceSturdy(bjw, fk2, fp5);
}
@Nullable
@Override
public BlockState getStateForPlacement(final BlockPlaceContext bcn) {
BlockState byg3 = this.defaultBlockState();
final LevelReader bjw4 = bcn.getLevel();
final BlockPos fk5 = bcn.getClickedPos();
final Direction[] nearestLookingDirections;
final Direction[] arr6 = nearestLookingDirections = bcn.getNearestLookingDirections();
for (final Direction fp10 : nearestLookingDirections) {
if (fp10.getAxis().isHorizontal()) {
final Direction fp11 = fp10.getOpposite();
byg3 = ((AbstractStateHolder<O, BlockState>)byg3).<Comparable, Direction>setValue((Property<Comparable>)WallTorchBlock.FACING, fp11);
if (byg3.canSurvive(bjw4, fk5)) {
return byg3;
}
}
}
return null;
}
@Override
public BlockState updateShape(final BlockState byg1, final Direction fp, final BlockState byg3, final LevelAccessor bju, final BlockPos fk5, final BlockPos fk6) {
if (fp.getOpposite() == byg1.<Direction>getValue((Property<Direction>)WallTorchBlock.FACING) && !byg1.canSurvive(bju, fk5)) {
return Blocks.AIR.defaultBlockState();
}
return byg1;
}
@Override
public void animateTick(final BlockState byg, final Level bjt, final BlockPos fk, final Random random) {
final Direction fp6 = byg.<Direction>getValue((Property<Direction>)WallTorchBlock.FACING);
final double double7 = fk.getX() + 0.5;
final double double8 = fk.getY() + 0.7;
final double double9 = fk.getZ() + 0.5;
final double double10 = 0.22;
final double double11 = 0.27;
final Direction fp7 = fp6.getOpposite();
bjt.addParticle(ParticleTypes.SMOKE, double7 + 0.27 * fp7.getStepX(), double8 + 0.22, double9 + 0.27 * fp7.getStepZ(), 0.0, 0.0, 0.0);
bjt.addParticle(ParticleTypes.FLAME, double7 + 0.27 * fp7.getStepX(), double8 + 0.22, double9 + 0.27 * fp7.getStepZ(), 0.0, 0.0, 0.0);
}
@Override
public BlockState rotate(final BlockState byg, final Rotation btr) {
return ((AbstractStateHolder<O, BlockState>)byg).<Comparable, Direction>setValue((Property<Comparable>)WallTorchBlock.FACING, btr.rotate(byg.<Direction>getValue((Property<Direction>)WallTorchBlock.FACING)));
}
@Override
public BlockState mirror(final BlockState byg, final Mirror bsr) {
return byg.rotate(bsr.getRotation(byg.<Direction>getValue((Property<Direction>)WallTorchBlock.FACING)));
}
@Override
protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> a) {
a.add(WallTorchBlock.FACING);
}
static {
FACING = HorizontalDirectionalBlock.FACING;
AABBS = Maps.<Direction, Object>newEnumMap(ImmutableMap.<Direction, VoxelShape>of(Direction.NORTH, Block.box(5.5, 3.0, 11.0, 10.5, 13.0, 16.0), Direction.SOUTH, Block.box(5.5, 3.0, 0.0, 10.5, 13.0, 5.0), Direction.WEST, Block.box(11.0, 3.0, 5.5, 16.0, 13.0, 10.5), Direction.EAST, Block.box(0.0, 3.0, 5.5, 5.0, 13.0, 10.5)));
}
}