45 lines
1.6 KiB
Java
45 lines
1.6 KiB
Java
package net.minecraft.world.item;
|
|
|
|
import java.util.Map;
|
|
import javax.annotation.Nullable;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.world.level.LevelReader;
|
|
import net.minecraft.world.phys.shapes.CollisionContext;
|
|
import net.minecraft.core.Direction;
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
import net.minecraft.world.level.block.Block;
|
|
|
|
public class StandingAndWallBlockItem extends BlockItem {
|
|
protected final Block wallBlock;
|
|
|
|
public StandingAndWallBlockItem(final Block bpe1, final Block bpe2, final Properties a) {
|
|
super(bpe1, a);
|
|
this.wallBlock = bpe2;
|
|
}
|
|
|
|
@Nullable
|
|
@Override
|
|
protected BlockState getPlacementState(final BlockPlaceContext bcn) {
|
|
final BlockState byg3 = this.wallBlock.getStateForPlacement(bcn);
|
|
BlockState byg4 = null;
|
|
final LevelReader bjw5 = bcn.getLevel();
|
|
final BlockPos fk6 = bcn.getClickedPos();
|
|
for (final Direction fp10 : bcn.getNearestLookingDirections()) {
|
|
if (fp10 != Direction.UP) {
|
|
final BlockState byg5 = (fp10 == Direction.DOWN) ? this.getBlock().getStateForPlacement(bcn) : byg3;
|
|
if (byg5 != null && byg5.canSurvive(bjw5, fk6)) {
|
|
byg4 = byg5;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
return (byg4 != null && bjw5.isUnobstructed(byg4, fk6, CollisionContext.empty())) ? byg4 : null;
|
|
}
|
|
|
|
@Override
|
|
public void registerBlocks(final Map<Block, Item> map, final Item bef) {
|
|
super.registerBlocks(map, bef);
|
|
map.put(this.wallBlock, bef);
|
|
}
|
|
}
|