use of cn.nukkit.math.BlockFace.SOUTH in project Nukkit by Nukkit.
the class BlockRail method place.
// Information from http://minecraft.gamepedia.com/Rail
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
Block down = this.down();
if (down == null || down.isTransparent()) {
return false;
}
Map<BlockRail, BlockFace> railsAround = this.checkRailsAroundAffected();
List<BlockRail> rails = new ArrayList<>(railsAround.keySet());
List<BlockFace> faces = new ArrayList<>(railsAround.values());
if (railsAround.size() == 1) {
BlockRail other = rails.get(0);
this.setDamage(this.connect(other, railsAround.get(other)).metadata());
} else if (railsAround.size() == 4) {
if (this.isAbstract()) {
this.setDamage(this.connect(rails.get(faces.indexOf(SOUTH)), SOUTH, rails.get(faces.indexOf(EAST)), EAST).metadata());
} else {
this.setDamage(this.connect(rails.get(faces.indexOf(EAST)), EAST, rails.get(faces.indexOf(WEST)), WEST).metadata());
}
} else if (!railsAround.isEmpty()) {
if (this.isAbstract()) {
if (railsAround.size() == 2) {
BlockRail rail1 = rails.get(0);
BlockRail rail2 = rails.get(1);
this.setDamage(this.connect(rail1, railsAround.get(rail1), rail2, railsAround.get(rail2)).metadata());
} else {
List<BlockFace> cd = Stream.of(CURVED_SOUTH_EAST, CURVED_NORTH_EAST, CURVED_SOUTH_WEST).filter(o -> o.connectingDirections().stream().allMatch(faces::contains)).findFirst().get().connectingDirections();
BlockFace f1 = cd.get(0);
BlockFace f2 = cd.get(1);
this.setDamage(this.connect(rails.get(faces.indexOf(f1)), f1, rails.get(faces.indexOf(f2)), f2).metadata());
}
} else {
BlockFace f = faces.stream().sorted((f1, f2) -> (f1.getIndex() < f2.getIndex()) ? 1 : ((x == y) ? 0 : -1)).findFirst().get();
BlockFace fo = f.getOpposite();
if (faces.contains(fo)) {
// Opposite connectable
this.setDamage(this.connect(rails.get(faces.indexOf(f)), f, rails.get(faces.indexOf(fo)), fo).metadata());
} else {
this.setDamage(this.connect(rails.get(faces.indexOf(f)), f).metadata());
}
}
}
this.level.setBlock(this, this, true, true);
if (!isAbstract()) {
level.scheduleUpdate(this, this, 0);
}
return true;
}
Aggregations