100 lines
3.7 KiB
Java
100 lines
3.7 KiB
Java
package net.minecraft.world.level.block;
|
|
|
|
import com.google.common.collect.Maps;
|
|
import net.minecraft.world.level.LevelReader;
|
|
import net.minecraft.world.level.LevelAccessor;
|
|
import net.minecraft.core.Direction;
|
|
import net.minecraft.world.item.Item;
|
|
import net.minecraft.world.level.ItemLike;
|
|
import net.minecraft.world.item.ItemStack;
|
|
import net.minecraft.stats.Stats;
|
|
import net.minecraft.world.item.BlockItem;
|
|
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.BlockGetter;
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
import net.minecraft.world.phys.shapes.VoxelShape;
|
|
import java.util.Map;
|
|
|
|
public class FlowerPotBlock extends Block {
|
|
private static final Map<Block, Block> POTTED_BY_CONTENT;
|
|
protected static final VoxelShape SHAPE;
|
|
private final Block content;
|
|
|
|
public FlowerPotBlock(final Block bpe, final Properties c) {
|
|
super(c);
|
|
this.content = bpe;
|
|
FlowerPotBlock.POTTED_BY_CONTENT.put(bpe, this);
|
|
}
|
|
|
|
@Override
|
|
public VoxelShape getShape(final BlockState byg, final BlockGetter bjd, final BlockPos fk, final CollisionContext cvn) {
|
|
return FlowerPotBlock.SHAPE;
|
|
}
|
|
|
|
@Override
|
|
public RenderShape getRenderShape(final BlockState byg) {
|
|
return RenderShape.MODEL;
|
|
}
|
|
|
|
@Override
|
|
public InteractionResult use(final BlockState byg, final Level bjt, final BlockPos fk, final Player ayg, final InteractionHand ajh, final BlockHitResult cvd) {
|
|
final ItemStack bek8 = ayg.getItemInHand(ajh);
|
|
final Item bef9 = bek8.getItem();
|
|
final Block bpe10 = (bef9 instanceof BlockItem) ? FlowerPotBlock.POTTED_BY_CONTENT.getOrDefault(((BlockItem)bef9).getBlock(), Blocks.AIR) : Blocks.AIR;
|
|
final boolean boolean11 = bpe10 == Blocks.AIR;
|
|
final boolean boolean12 = this.content == Blocks.AIR;
|
|
if (boolean11 != boolean12) {
|
|
if (boolean12) {
|
|
bjt.setBlock(fk, bpe10.defaultBlockState(), 3);
|
|
ayg.awardStat(Stats.POT_FLOWER);
|
|
if (!ayg.abilities.instabuild) {
|
|
bek8.shrink(1);
|
|
}
|
|
}
|
|
else {
|
|
final ItemStack bek9 = new ItemStack(this.content);
|
|
if (bek8.isEmpty()) {
|
|
ayg.setItemInHand(ajh, bek9);
|
|
}
|
|
else if (!ayg.addItem(bek9)) {
|
|
ayg.drop(bek9, false);
|
|
}
|
|
bjt.setBlock(fk, Blocks.FLOWER_POT.defaultBlockState(), 3);
|
|
}
|
|
return InteractionResult.SUCCESS;
|
|
}
|
|
return InteractionResult.CONSUME;
|
|
}
|
|
|
|
@Override
|
|
public ItemStack getCloneItemStack(final BlockGetter bjd, final BlockPos fk, final BlockState byg) {
|
|
if (this.content == Blocks.AIR) {
|
|
return super.getCloneItemStack(bjd, fk, byg);
|
|
}
|
|
return new ItemStack(this.content);
|
|
}
|
|
|
|
@Override
|
|
public BlockState updateShape(final BlockState byg1, final Direction fp, final BlockState byg3, final LevelAccessor bju, final BlockPos fk5, final BlockPos fk6) {
|
|
if (fp == Direction.DOWN && !byg1.canSurvive(bju, fk5)) {
|
|
return Blocks.AIR.defaultBlockState();
|
|
}
|
|
return super.updateShape(byg1, fp, byg3, bju, fk5, fk6);
|
|
}
|
|
|
|
public Block getContent() {
|
|
return this.content;
|
|
}
|
|
|
|
static {
|
|
POTTED_BY_CONTENT = Maps.newHashMap();
|
|
SHAPE = Block.box(5.0, 0.0, 5.0, 11.0, 6.0, 11.0);
|
|
}
|
|
}
|