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

125 lines
5.4 KiB
Java

package net.minecraft.world.level.block;
import net.minecraft.world.level.block.state.AbstractStateHolder;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.pathfinder.PathComputationType;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.Container;
import net.minecraft.world.Containers;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.core.particles.ParticleTypes;
import java.util.Random;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.stats.Stats;
import net.minecraft.world.MenuProvider;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.entity.BrewingStandBlockEntity;
import net.minecraft.world.level.block.entity.BlockEntity;
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.world.level.block.state.properties.BooleanProperty;
public class BrewingStandBlock extends BaseEntityBlock {
public static final BooleanProperty[] HAS_BOTTLE;
protected static final VoxelShape SHAPE;
public BrewingStandBlock(final Properties c) {
super(c);
this.registerDefaultState(((((AbstractStateHolder<O, BlockState>)this.stateDefinition.any()).setValue((Property<Comparable>)BrewingStandBlock.HAS_BOTTLE[0], false)).setValue((Property<Comparable>)BrewingStandBlock.HAS_BOTTLE[1], false)).<Comparable, Boolean>setValue((Property<Comparable>)BrewingStandBlock.HAS_BOTTLE[2], false));
}
@Override
public RenderShape getRenderShape(final BlockState byg) {
return RenderShape.MODEL;
}
@Override
public BlockEntity newBlockEntity(final BlockGetter bjd) {
return new BrewingStandBlockEntity();
}
@Override
public VoxelShape getShape(final BlockState byg, final BlockGetter bjd, final BlockPos fk, final CollisionContext cvn) {
return BrewingStandBlock.SHAPE;
}
@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) {
return InteractionResult.SUCCESS;
}
final BlockEntity bwi8 = bjt.getBlockEntity(fk);
if (bwi8 instanceof BrewingStandBlockEntity) {
ayg.openMenu((MenuProvider)bwi8);
ayg.awardStat(Stats.INTERACT_WITH_BREWINGSTAND);
}
return InteractionResult.SUCCESS;
}
@Override
public void setPlacedBy(final Level bjt, final BlockPos fk, final BlockState byg, final LivingEntity akw, final ItemStack bek) {
if (bek.hasCustomHoverName()) {
final BlockEntity bwi7 = bjt.getBlockEntity(fk);
if (bwi7 instanceof BrewingStandBlockEntity) {
((BrewingStandBlockEntity)bwi7).setCustomName(bek.getHoverName());
}
}
}
@Override
public void animateTick(final BlockState byg, final Level bjt, final BlockPos fk, final Random random) {
final double double6 = fk.getX() + 0.4 + random.nextFloat() * 0.2;
final double double7 = fk.getY() + 0.7 + random.nextFloat() * 0.3;
final double double8 = fk.getZ() + 0.4 + random.nextFloat() * 0.2;
bjt.addParticle(ParticleTypes.SMOKE, double6, double7, double8, 0.0, 0.0, 0.0);
}
@Override
public void onRemove(final BlockState byg1, final Level bjt, final BlockPos fk, final BlockState byg4, final boolean boolean5) {
if (byg1.getBlock() == byg4.getBlock()) {
return;
}
final BlockEntity bwi7 = bjt.getBlockEntity(fk);
if (bwi7 instanceof BrewingStandBlockEntity) {
Containers.dropContents(bjt, fk, (Container)bwi7);
}
super.onRemove(byg1, bjt, fk, byg4, boolean5);
}
@Override
public boolean hasAnalogOutputSignal(final BlockState byg) {
return true;
}
@Override
public int getAnalogOutputSignal(final BlockState byg, final Level bjt, final BlockPos fk) {
return AbstractContainerMenu.getRedstoneSignalFromBlockEntity(bjt.getBlockEntity(fk));
}
@Override
protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> a) {
a.add(BrewingStandBlock.HAS_BOTTLE[0], BrewingStandBlock.HAS_BOTTLE[1], BrewingStandBlock.HAS_BOTTLE[2]);
}
@Override
public boolean isPathfindable(final BlockState byg, final BlockGetter bjd, final BlockPos fk, final PathComputationType cqo) {
return false;
}
static {
HAS_BOTTLE = new BooleanProperty[] { BlockStateProperties.HAS_BOTTLE_0, BlockStateProperties.HAS_BOTTLE_1, BlockStateProperties.HAS_BOTTLE_2 };
SHAPE = Shapes.or(Block.box(1.0, 0.0, 1.0, 15.0, 2.0, 15.0), Block.box(7.0, 0.0, 7.0, 9.0, 14.0, 9.0));
}
}