@Override public int connect(UserConnection user, Position position, int blockState) { if (blockState != baseStateId) { return blockState; } for (BlockFace blockFace : BLOCK_FACES) { if (blockId.contains(getBlockData(user, position.getRelative(blockFace)))) { return stemps.get(blockFace); } } return baseStateId; } }
private int connects(UserConnection user, Position position, BlockFace side) { final Position relative = position.getRelative(side); int blockState = getBlockData(user, relative); if (connects(side, blockState)) { return 1; //side } int up = getBlockData(user, relative.getRelative(BlockFace.TOP)); if (redstone.contains(up) && !ConnectionData.occludingStates.contains(getBlockData(user, position.getRelative(BlockFace.TOP)))) { return 2; //"up" } int down = getBlockData(user, relative.getRelative(BlockFace.BOTTOM)); if (redstone.contains(down) && !ConnectionData.occludingStates.contains(getBlockData(user, relative))) { return 1; //side } return 0; //none }
@Override public int connect(UserConnection user, Position position, int blockState) { BlockFace facing = chestFacings.get(blockState); byte states = 0; states |= (facing.ordinal() << 2); boolean trapped = trappedChests.contains(blockState); if (trapped) states |= 16; int relative; if (chestFacings.containsKey(relative = getBlockData(user, position.getRelative(BlockFace.NORTH))) && trapped == trappedChests.contains(relative)) { states |= facing == BlockFace.WEST ? 1 : 2; } else if (chestFacings.containsKey(relative = getBlockData(user, position.getRelative(BlockFace.SOUTH))) && trapped == trappedChests.contains(relative)) { states |= facing == BlockFace.EAST ? 1 : 2; } else if (chestFacings.containsKey(relative = getBlockData(user, position.getRelative(BlockFace.WEST))) && trapped == trappedChests.contains(relative)) { states |= facing == BlockFace.NORTH ? 2 : 1; } else if (chestFacings.containsKey(relative = getBlockData(user, position.getRelative(BlockFace.EAST))) && trapped == trappedChests.contains(relative)) { states |= facing == BlockFace.SOUTH ? 2 : 1; } Integer newBlockState = connectedStates.get(states); return newBlockState == null ? blockState : newBlockState; } }
@Override public int connect(UserConnection user, Position position, int blockState) { int blockBelowId = getBlockData(user, position.getRelative(BlockFace.BOTTOM)); if (flowers.containsKey(blockBelowId)) { int blockAboveId = getBlockData(user, position.getRelative(BlockFace.TOP)); if (Via.getConfig().isStemWhenBlockAbove()) { if (blockAboveId == 0) { return flowers.get(blockBelowId); } } else if (!flowers.containsKey(blockAboveId)) { return flowers.get(blockBelowId); } } return blockState; } }
protected byte getStates(UserConnection user, Position position, int blockState) { byte states = 0; if (connects(BlockFace.EAST, getBlockData(user, position.getRelative(BlockFace.EAST)))) states |= 1; if (connects(BlockFace.NORTH, getBlockData(user, position.getRelative(BlockFace.NORTH)))) states |= 2; if (connects(BlockFace.SOUTH, getBlockData(user, position.getRelative(BlockFace.SOUTH)))) states |= 4; if (connects(BlockFace.WEST, getBlockData(user, position.getRelative(BlockFace.WEST)))) states |= 8; return states; }
private int getBlockFaces(UserConnection user, Position position) { int blockFaces = 0; for (int i = 0; i < BLOCK_FACES.length; i++) { if (isWall(getBlockData(user, position.getRelative(BLOCK_FACES[i])))) { blockFaces |= 1 << i; } } return blockFaces; }
@Override public int connect(UserConnection user, Position position, int blockState) { TripwireData tripwireData = tripwireDataMap.get(blockState); if (tripwireData == null) return blockState; byte b = 0; if (tripwireData.isAttached()) b |= 1; if (tripwireData.isDisarmed()) b |= 2; if (tripwireData.isPowered()) b |= 4; int east = getBlockData(user, position.getRelative(BlockFace.EAST)); int north = getBlockData(user, position.getRelative(BlockFace.NORTH)); int south = getBlockData(user, position.getRelative(BlockFace.SOUTH)); int west = getBlockData(user, position.getRelative(BlockFace.WEST)); if (tripwireDataMap.containsKey(east) || tripwireHooks.get(east) == BlockFace.WEST) { b |= 8; } if (tripwireDataMap.containsKey(north) || tripwireHooks.get(north) == BlockFace.SOUTH) { b |= 16; } if (tripwireDataMap.containsKey(south) || tripwireHooks.get(south) == BlockFace.NORTH) { b |= 32; } if (tripwireDataMap.containsKey(west) || tripwireHooks.get(west) == BlockFace.EAST) { b |= 64; } Integer newBlockState = connectedBlocks.get(b); return newBlockState == null ? blockState : newBlockState; }
@Override protected byte getStates(UserConnection user, Position position, int blockState) { byte states = super.getStates(user, position, blockState); if (connects(BlockFace.TOP, getBlockData(user, position.getRelative(BlockFace.TOP)))) states |= 16; if (connects(BlockFace.BOTTOM, getBlockData(user, position.getRelative(BlockFace.BOTTOM)))) states |= 32; return states; }
public boolean up(UserConnection user, Position position) { if (isWall(getBlockData(user, position.getRelative(BlockFace.BOTTOM))) || isWall(getBlockData(user, position.getRelative(BlockFace.TOP)))) return true; int blockFaces = getBlockFaces(user, position); if (blockFaces == 0 || blockFaces == 0xF) return true; for (int i = 0; i < BLOCK_FACES.length; i++) { if ((blockFaces & (1 << i)) != 0 && (blockFaces & (1 << OPPOSITES[i])) == 0) return true; } return false; }
private boolean checkOpposite(UserConnection user, StairData stair, Position position, BlockFace face) { StairData relativeStair = stairDataMap.get(getBlockData(user, position.getRelative(face))); return relativeStair == null || relativeStair.getFacing() != stair.getFacing() || relativeStair.isBottom() != stair.isBottom(); }
@Override public int connect(UserConnection user, Position position, int blockState) { DoorData doorData = doorDataMap.get(blockState); if (doorData == null) return blockState; short s = 0; s |= (doorData.getType() & 0x7) << 6; if (doorData.isLower()) { DoorData upperHalf = doorDataMap.get(getBlockData(user, position.getRelative(BlockFace.TOP))); if (upperHalf == null) return blockState; s |= 1; if (doorData.isOpen()) s |= 2; if (upperHalf.isPowered()) s |= 4; if (upperHalf.isRightHinge()) s |= 8; s |= doorData.getFacing().ordinal() << 4; } else { DoorData lowerHalf = doorDataMap.get(getBlockData(user, position.getRelative(BlockFace.BOTTOM))); if (lowerHalf == null) return blockState; if (lowerHalf.isOpen()) s |= 2; if (doorData.isPowered()) s |= 4; if (doorData.isRightHinge()) s |= 8; s |= lowerHalf.getFacing().ordinal() << 4; } Integer newBlockState = connectedStates.get(s); return newBlockState == null ? blockState : newBlockState; }
private int getShape(UserConnection user, Position position, StairData stair) { BlockFace facing = stair.getFacing(); StairData relativeStair = stairDataMap.get(getBlockData(user, position.getRelative(facing))); if (relativeStair != null && relativeStair.isBottom() == stair.isBottom()) { BlockFace facing2 = relativeStair.getFacing(); if (facing.getAxis() != facing2.getAxis() && checkOpposite(user, stair, position, facing2.opposite())){ return facing2 == rotateAntiClockwise(facing) ? 3 : 4; // outer_left : outer_right } } relativeStair = stairDataMap.get(getBlockData(user, position.getRelative(facing.opposite()))); if(relativeStair != null && relativeStair.isBottom() == stair.isBottom()) { BlockFace facing2 = relativeStair.getFacing(); if (facing.getAxis() != facing2.getAxis() && checkOpposite(user, stair, position, facing2)){ return facing2 == rotateAntiClockwise(facing) ? 1 : 2; // inner_left : inner_right } } return 0; // straight }