Java Code Examples for cn.nukkit.math.BlockFace#getOpposite()

The following examples show how to use cn.nukkit.math.BlockFace#getOpposite() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BlockRail.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
private Orientation connect(BlockRail rail1, BlockFace face1, BlockRail rail2, BlockFace face2) {
    this.connect(rail1, face1);
    this.connect(rail2, face2);

    if (face1.getOpposite() == face2) {
        int delta1 = (int) (this.y - rail1.y);
        int delta2 = (int) (this.y - rail2.y);

        if (delta1 == -1) {
            return Orientation.ascending(face1);
        } else if (delta2 == -1) {
            return Orientation.ascending(face2);
        }
    }
    return straightOrCurved(face1, face2);
}
 
Example 2
Source File: BlockTripWire.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public void updateHook(boolean scheduleUpdate) {
    for (BlockFace side : new BlockFace[]{BlockFace.SOUTH, BlockFace.WEST}) {
        for (int i = 1; i < 42; ++i) {
            Block block = this.getSide(side, i);

            if (block instanceof BlockTripWireHook) {
                BlockTripWireHook hook = (BlockTripWireHook) block;

                if (hook.getFacing() == side.getOpposite()) {
                    hook.calculateState(false, true, i, this);
                }

                /*if(scheduleUpdate) {
                    this.level.scheduleUpdate(hook, 10);
                }*/
                break;
            }

            if (block.getId() != Block.TRIPWIRE) {
                break;
            }
        }
    }
}
 
Example 3
Source File: BlockRail.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
private Orientation connect(BlockRail rail1, BlockFace face1, BlockRail rail2, BlockFace face2) {
    this.connect(rail1, face1);
    this.connect(rail2, face2);

    if (face1.getOpposite() == face2) {
        int delta1 = (int) (this.y - rail1.y);
        int delta2 = (int) (this.y - rail2.y);

        if (delta1 == -1) {
            return Orientation.ascending(face1);
        } else if (delta2 == -1) {
            return Orientation.ascending(face2);
        }
    }
    return straightOrCurved(face1, face2);
}
 
Example 4
Source File: BlockTripWire.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public void updateHook(boolean scheduleUpdate) {
    for (BlockFace side : new BlockFace[]{BlockFace.SOUTH, BlockFace.WEST}) {
        for (int i = 1; i < 42; ++i) {
            Block block = this.getSide(side, i);

            if (block instanceof BlockTripWireHook) {
                BlockTripWireHook hook = (BlockTripWireHook) block;

                if (hook.getFacing() == side.getOpposite()) {
                    hook.calculateState(false, true, i, this);
                }

                /*if(scheduleUpdate) {
                    this.level.scheduleUpdate(hook, 10);
                }*/
                break;
            }

            if (block.getId() != Block.TRIPWIRE) {
                break;
            }
        }
    }
}
 
Example 5
Source File: BlockRail.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
private Orientation connect(BlockRail rail1, BlockFace face1, BlockRail rail2, BlockFace face2) {
    this.connect(rail1, face1);
    this.connect(rail2, face2);

    if (face1.getOpposite() == face2) {
        int delta1 = (int) (this.y - rail1.y);
        int delta2 = (int) (this.y - rail2.y);

        if (delta1 == -1) {
            return Orientation.ascending(face1);
        } else if (delta2 == -1) {
            return Orientation.ascending(face2);
        }
    }
    return straightOrCurved(face1, face2);
}
 
Example 6
Source File: BlockTripWire.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
public void updateHook(boolean scheduleUpdate) {
    for (BlockFace side : new BlockFace[]{BlockFace.SOUTH, BlockFace.WEST}) {
        for (int i = 1; i < 42; ++i) {
            Block block = this.getSide(side, i);

            if (block instanceof BlockTripWireHook) {
                BlockTripWireHook hook = (BlockTripWireHook) block;

                if (hook.getFacing() == side.getOpposite()) {
                    hook.calculateState(false, true, i, this);
                }

                /*if(scheduleUpdate) {
                    this.level.scheduleUpdate(hook, 10);
                }*/
                break;
            }

            if (block.getId() != Block.TRIPWIRE) {
                break;
            }
        }
    }
}
 
Example 7
Source File: BlockPistonBase.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public BlocksCalculator(Level level, Block pos, BlockFace facing, boolean extending) {
    this.level = level;
    this.pistonPos = pos.getLocation();

    if (extending) {
        this.moveDirection = facing;
        this.blockToMove = pos.getSide(facing);
    } else {
        this.moveDirection = facing.getOpposite();
        this.blockToMove = pos.getSide(facing, 2);
    }
}
 
Example 8
Source File: BlockHopper.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
    BlockFace facing = face.getOpposite();

    if (facing == BlockFace.UP) {
        facing = BlockFace.DOWN;
    }

    this.meta = facing.getIndex();

    boolean powered = this.level.isBlockPowered(this);

    if (powered == this.isEnabled()) {
        this.setEnabled(!powered);
    }

    this.level.setBlock(this, this);

    CompoundTag nbt = new CompoundTag()
            .putList(new ListTag<>("Items"))
            .putString("id", BlockEntity.HOPPER)
            .putInt("x", (int) this.x)
            .putInt("y", (int) this.y)
            .putInt("z", (int) this.z);

    new BlockEntityHopper(this.level.getChunk(this.getFloorX() >> 4, this.getFloorZ() >> 4), nbt);
    return true;
}
 
Example 9
Source File: BlockRedstoneWire.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
protected static boolean canConnectTo(Block block, BlockFace side) {
    if (block.getId() == Block.REDSTONE_WIRE) {
        return true;
    } else if (BlockRedstoneDiode.isDiode(block)) {
        BlockFace face = ((BlockRedstoneDiode) block).getFacing();
        return face == side || face.getOpposite() == side;
    } else {
        return block.isPowerSource() && side != null;
    }
}
 
Example 10
Source File: BlockPistonBase.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public BlocksCalculator(Level level, Block pos, BlockFace facing, boolean extending) {
    this.level = level;
    this.pistonPos = pos.getLocation();

    if (extending) {
        this.moveDirection = facing;
        this.blockToMove = pos.getSide(facing);
    } else {
        this.moveDirection = facing.getOpposite();
        this.blockToMove = pos.getSide(facing, 2);
    }
}
 
Example 11
Source File: BlockHopper.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
    BlockFace facing = face.getOpposite();

    if (facing == BlockFace.UP) {
        facing = BlockFace.DOWN;
    }

    this.setDamage(facing.getIndex());

    boolean powered = this.level.isBlockPowered(this.getLocation());

    if (powered == this.isEnabled()) {
        this.setEnabled(!powered);
    }

    this.level.setBlock(this, this);

    CompoundTag nbt = new CompoundTag()
            .putList(new ListTag<>("Items"))
            .putString("id", BlockEntity.HOPPER)
            .putInt("x", (int) this.x)
            .putInt("y", (int) this.y)
            .putInt("z", (int) this.z);

    BlockEntityHopper hopper = (BlockEntityHopper) BlockEntity.createBlockEntity(BlockEntity.HOPPER, this.level.getChunk(this.getFloorX() >> 4, this.getFloorZ() >> 4), nbt);
    return hopper != null;
}
 
Example 12
Source File: BlockHopper.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
    BlockFace facing = face.getOpposite();

    if (facing == BlockFace.UP) {
        facing = BlockFace.DOWN;
    }

    this.setDamage(facing.getIndex());

    boolean powered = this.level.isBlockPowered(this);

    if (powered == this.isEnabled()) {
        this.setEnabled(!powered);
    }

    this.level.setBlock(this, this);

    CompoundTag nbt = new CompoundTag()
            .putList(new ListTag<>("Items"))
            .putString("id", BlockEntity.HOPPER)
            .putInt("x", (int) this.x)
            .putInt("y", (int) this.y)
            .putInt("z", (int) this.z);

    new BlockEntityHopper(this.level.getChunk(this.getFloorX() >> 4, this.getFloorZ() >> 4), nbt);
    return true;
}
 
Example 13
Source File: BlockRedstoneWire.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
protected static boolean canConnectTo(Block block, BlockFace side) {
    if (block.getId() == Block.REDSTONE_WIRE) {
        return true;
    } else if (BlockRedstoneDiode.isDiode(block)) {
        BlockFace face = ((BlockRedstoneDiode) block).getFacing();
        return face == side || face.getOpposite() == side;
    } else {
        return block.isPowerSource() && side != null;
    }
}
 
Example 14
Source File: BlockPistonBase.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public BlocksCalculator(Level level, Block pos, BlockFace facing, boolean extending) {
    this.level = level;
    this.pistonPos = pos.getLocation();

    if (extending) {
        this.moveDirection = facing;
        this.blockToMove = pos.getSide(facing);
    } else {
        this.moveDirection = facing.getOpposite();
        this.blockToMove = pos.getSide(facing, 2);
    }
}
 
Example 15
Source File: BlockRail.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@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 -> faces.containsAll(o.connectingDirections()))
                        .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().min((f1, f2) -> (f1.getIndex() < f2.getIndex()) ? 1 : ((x == y) ? 0 : -1)).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;
}
 
Example 16
Source File: BlockTripWireHook.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
public void calculateState(boolean onBreak, boolean updateAround, int pos, Block block) {
    BlockFace facing = getFacing();
    Vector3 v = this.getLocation();
    boolean attached = isAttached();
    boolean powered = isPowered();
    boolean canConnect = !onBreak;
    boolean nextPowered = false;
    int distance = 0;
    Block[] blocks = new Block[42];

    for (int i = 1; i < 42; ++i) {
        Vector3 vector = v.getSide(facing, i);
        Block b = this.level.getBlock(vector);

        if (b instanceof BlockTripWireHook) {
            if (((BlockTripWireHook) b).getFacing() == facing.getOpposite()) {
                distance = i;
            }
            break;
        }

        if (b.getId() != Block.TRIPWIRE && i != pos) {
            blocks[i] = null;
            canConnect = false;
        } else {
            if (i == pos) {
                b = block != null ? block : b;
            }

            if (b instanceof BlockTripWire) {
                boolean disarmed = !((BlockTripWire) b).isDisarmed();
                boolean wirePowered = ((BlockTripWire) b).isPowered();
                nextPowered |= disarmed && wirePowered;

                if (i == pos) {
                    this.level.scheduleUpdate(this, 10);
                    canConnect &= disarmed;
                }
            }
            blocks[i] = b;
        }
    }

    canConnect = canConnect & distance > 1;
    nextPowered = nextPowered & canConnect;
    BlockTripWireHook hook = new BlockTripWireHook();
    hook.setAttached(canConnect);
    hook.setPowered(nextPowered);


    if (distance > 0) {
        Vector3 vec = v.getSide(facing, distance);
        BlockFace face = facing.getOpposite();
        hook.setFace(face);
        this.level.setBlock(vec, hook, true, false);
        this.level.updateAroundRedstone(vec, null);
        this.level.updateAroundRedstone(vec.getSide(face.getOpposite()), null);
        this.addSound(vec, canConnect, nextPowered, attached, powered);
    }

    this.addSound(v, canConnect, nextPowered, attached, powered);

    if (!onBreak) {
        hook.setFace(facing);
        this.level.setBlock(v, hook, true, false);

        if (updateAround) {
            this.level.updateAroundRedstone(v, null);
            this.level.updateAroundRedstone(v.getSide(facing.getOpposite()), null);
        }
    }

    if (attached != canConnect) {
        for (int i = 1; i < distance; i++) {
            Vector3 vc = v.getSide(facing, i);
            block = blocks[i];

            if (block != null && this.level.getBlockIdAt(vc.getFloorX(), vc.getFloorY(), vc.getFloorZ()) != Block.AIR) {
                if (canConnect ^ ((block.meta & 0x04) > 0)) {
                    block.meta ^= 0x04;
                }

                this.level.setBlock(vc, block, true, false);
            }
        }
    }
}
 
Example 17
Source File: BlockTripWireHook.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public void calculateState(boolean onBreak, boolean updateAround, int pos, Block block) {
    BlockFace facing = getFacing();
    Vector3 v = this.getLocation();
    boolean attached = isAttached();
    boolean powered = isPowered();
    boolean canConnect = !onBreak;
    boolean nextPowered = false;
    int distance = 0;
    Block[] blocks = new Block[42];

    for (int i = 1; i < 42; ++i) {
        Vector3 vector = v.getSide(facing, i);
        Block b = this.level.getBlock(vector);

        if (b instanceof BlockTripWireHook) {
            if (((BlockTripWireHook) b).getFacing() == facing.getOpposite()) {
                distance = i;
            }
            break;
        }

        if (b.getId() != Block.TRIPWIRE && i != pos) {
            blocks[i] = null;
            canConnect = false;
        } else {
            if (i == pos) {
                b = block != null ? block : b;
            }

            if (b instanceof BlockTripWire) {
                boolean disarmed = !((BlockTripWire) b).isDisarmed();
                boolean wirePowered = ((BlockTripWire) b).isPowered();
                nextPowered |= disarmed && wirePowered;

                if (i == pos) {
                    this.level.scheduleUpdate(this, 10);
                    canConnect &= disarmed;
                }
            }
            blocks[i] = b;
        }
    }

    canConnect = canConnect & distance > 1;
    nextPowered = nextPowered & canConnect;
    BlockTripWireHook hook = (BlockTripWireHook) Block.get(BlockID.TRIPWIRE_HOOK);
    hook.setAttached(canConnect);
    hook.setPowered(nextPowered);


    if (distance > 0) {
        Vector3 vec = v.getSide(facing, distance);
        BlockFace face = facing.getOpposite();
        hook.setFace(face);
        this.level.setBlock(vec, hook, true, false);
        this.level.updateAroundRedstone(vec, null);
        this.level.updateAroundRedstone(vec.getSide(face.getOpposite()), null);
        this.addSound(vec, canConnect, nextPowered, attached, powered);
    }

    this.addSound(v, canConnect, nextPowered, attached, powered);

    if (!onBreak) {
        hook.setFace(facing);
        this.level.setBlock(v, hook, true, false);

        if (updateAround) {
            this.level.updateAroundRedstone(v, null);
            this.level.updateAroundRedstone(v.getSide(facing.getOpposite()), null);
        }
    }

    if (attached != canConnect) {
        for (int i = 1; i < distance; i++) {
            Vector3 vc = v.getSide(facing, i);
            block = blocks[i];

            if (block != null && this.level.getBlockIdAt(vc.getFloorX(), vc.getFloorY(), vc.getFloorZ()) != Block.AIR) {
                if (canConnect ^ ((block.getDamage() & 0x04) > 0)) {
                    block.setDamage(block.getDamage() ^ 0x04);
                }

                this.level.setBlock(vc, block, true, false);
            }
        }
    }
}
 
Example 18
Source File: BlockRail.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@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;
}
 
Example 19
Source File: BlockRail.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
@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.meta = this.connect(other, railsAround.get(other)).metadata();
    } else if (railsAround.size() == 4) {
        if (this.isAbstract()) {
            this.meta = this.connect(rails.get(faces.indexOf(SOUTH)), SOUTH, rails.get(faces.indexOf(EAST)), EAST).metadata();
        } else {
            this.meta = 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.meta = 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.meta = 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.meta = this.connect(rails.get(faces.indexOf(f)), f, rails.get(faces.indexOf(fo)), fo).metadata();
            } else {
                this.meta = 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;
}
 
Example 20
Source File: BlockTripWireHook.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public void calculateState(boolean onBreak, boolean updateAround, int pos, Block block) {
    BlockFace facing = getFacing();
    Vector3 v = this.getLocation();
    boolean attached = isAttached();
    boolean powered = isPowered();
    boolean canConnect = !onBreak;
    boolean nextPowered = false;
    int distance = 0;
    Block[] blocks = new Block[42];

    for (int i = 1; i < 42; ++i) {
        Vector3 vector = v.getSide(facing, i);
        Block b = this.level.getBlock(vector);

        if (b instanceof BlockTripWireHook) {
            if (((BlockTripWireHook) b).getFacing() == facing.getOpposite()) {
                distance = i;
            }
            break;
        }

        if (b.getId() != Block.TRIPWIRE && i != pos) {
            blocks[i] = null;
            canConnect = false;
        } else {
            if (i == pos) {
                b = block != null ? block : b;
            }

            if (b instanceof BlockTripWire) {
                boolean disarmed = !((BlockTripWire) b).isDisarmed();
                boolean wirePowered = ((BlockTripWire) b).isPowered();
                nextPowered |= disarmed && wirePowered;

                if (i == pos) {
                    this.level.scheduleUpdate(this, 10);
                    canConnect &= disarmed;
                }
            }
            blocks[i] = b;
        }
    }

    canConnect = canConnect & distance > 1;
    nextPowered = nextPowered & canConnect;
    BlockTripWireHook hook = new BlockTripWireHook();
    hook.setAttached(canConnect);
    hook.setPowered(nextPowered);


    if (distance > 0) {
        Vector3 vec = v.getSide(facing, distance);
        BlockFace face = facing.getOpposite();
        hook.setFace(face);
        this.level.setBlock(vec, hook, true, false);
        this.level.updateAroundRedstone(vec, null);
        this.level.updateAroundRedstone(vec.getSide(face.getOpposite()), null);
        this.addSound(vec, canConnect, nextPowered, attached, powered);
    }

    this.addSound(v, canConnect, nextPowered, attached, powered);

    if (!onBreak) {
        hook.setFace(facing);
        this.level.setBlock(v, hook, true, false);

        if (updateAround) {
            this.level.updateAroundRedstone(v, null);
            this.level.updateAroundRedstone(v.getSide(facing.getOpposite()), null);
        }
    }

    if (attached != canConnect) {
        for (int i = 1; i < distance; i++) {
            Vector3 vc = v.getSide(facing, i);
            block = blocks[i];

            if (block != null && this.level.getBlockIdAt(vc.getFloorX(), vc.getFloorY(), vc.getFloorZ()) != Block.AIR) {
                if (canConnect ^ ((block.getDamage() & 0x04) > 0)) {
                    block.setDamage(block.getDamage() ^ 0x04);
                }

                this.level.setBlock(vc, block, true, false);
            }
        }
    }
}