Tabnine Logo
Position
Code IndexAdd Tabnine to your IDE (free)

How to use
Position
in
us.myles.ViaVersion.api.minecraft

Best Java code snippets using us.myles.ViaVersion.api.minecraft.Position (Showing top 20 results out of 315)

origin: MylesIsCool/ViaVersion

@Override
public Position read(ByteBuf buffer) {
  long val = buffer.readLong();
  long x = (val >> 38); // signed
  long y = (val >> 26) & 0xfff; // unsigned
  // this shifting madness is used to preserve sign
  long z = (val << 38) >> 38; // signed
  return new Position(x, y, z);
}
origin: MylesIsCool/ViaVersion

  @Override
  public void write(ByteBuf buffer, Position object) {
    buffer.writeLong(((object.getX() & 0x3ffffff) << 38) | ((object.getY() & 0xfff) << 26) | (object.getZ() & 0x3ffffff));
  }
}
origin: MylesIsCool/ViaVersion

  @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;
  }
}
origin: MylesIsCool/ViaVersion

private Pair<Integer, Integer> getPair(Position position) {
  int chunkX = (int) (position.getX() >> 4);
  int chunkZ = (int) (position.getZ() >> 4);
  return new Pair<>(chunkX, chunkZ);
}
origin: MylesIsCool/ViaVersion

public static void update(UserConnection user, Position position) {
  for (int x = -1; x <= 1; x++) {
    for (int z = -1; z <= 1; z++) {
      for (int y = -1; y <= 1; y++) {
        if (Math.abs(x) + Math.abs(y) + Math.abs(z) != 1) continue;
        Position pos = new Position(position.getX() + x, position.getY() + y, position.getZ() + z);
        int blockState = Via.getManager().getProviders().get(BlockConnectionProvider.class).getBlockdata(user, pos);
        if (!connects(blockState)) continue;
        int newBlockState = connect(user, pos, blockState);
        if (newBlockState == blockState) continue;
        PacketWrapper blockUpdatePacket = new PacketWrapper(0x0B, null, user);
        blockUpdatePacket.write(Type.POSITION, pos);
        blockUpdatePacket.write(Type.VAR_INT, newBlockState);
        try {
          blockUpdatePacket.send(Protocol1_13To1_12_2.class, true, false);
        } catch (Exception ex) {
          ex.printStackTrace();
        }
      }
    }
  }
}
origin: MylesIsCool/ViaVersion

private Pair<Integer, Integer> getChunkCoords(Position position) {
  int chunkX = (int) Math.floor(position.getX() / 16);
  int chunkZ = (int) Math.floor(position.getZ() / 16);
  return new Pair<>(chunkX, chunkZ);
}
origin: MylesIsCool/ViaVersion

  public BlockPositon(Position position) {
    x = position.getX().intValue();
    y = position.getY().intValue();
    z = position.getZ().intValue();
  }
}
origin: MylesIsCool/ViaVersion

public void storeBlock(UserConnection connection, long x, long y, long z, int blockState) {
  storeBlock(connection, new Position(x, y, z), blockState);
}
origin: MylesIsCool/ViaVersion

  @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;
  }
}
origin: MylesIsCool/ViaVersion

public boolean interactedBlockRecently(int x, int y, int z) {
  if (blockInteractions.size() == 0)
    return false;
  for (Position p : blockInteractions.asMap().keySet()) {
    if (p.getX() == x)
      if (p.getY() == y)
        if (p.getZ() == z)
          return true;
  }
  return false;
}
origin: MylesIsCool/ViaVersion

public Position getRelative(BlockFace face) {
  return new Position(this.x + face.getModX(), this.y + face.getModY(), this.z + face.getModZ());
}
origin: MylesIsCool/ViaVersion

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
}
origin: MylesIsCool/ViaVersion

  @Override
  public int getWorldBlockData(UserConnection user, Position position) {
    if (blockStateIds != null) {
      UUID uuid = user.get(ProtocolInfo.class).getUuid();
      Optional<Player> player = Sponge.getServer().getPlayer(uuid);
      if (player.isPresent()) {
        World world = player.get().getWorld();
        Optional<Chunk> chunk = world.getChunkAtBlock(position.getX().intValue(), position.getY().intValue(), position.getZ().intValue());
        if (chunk.isPresent()) {
          BlockState b = chunk.get().getBlock(position.getX().intValue(), position.getY().intValue(), position.getZ().intValue());
          Integer id = blockStateIds.get(b);
          if (id == null) {
            System.out.println("id not found");
          } else {
            return id;
          }
        }
      }
    }
    return 0;
  }
}
origin: MylesIsCool/ViaVersion

  block = ConnectionData.connect(user, new Position(xOff + x, yOff + y, zOff + z), block);
  section.setFlatBlock(x, y, z, block);
  update(user, new Position(xOff - 1, yOff + y, zOff + z));
} else if (x == 15) {
  update(user, new Position(xOff + 16, yOff + y, zOff + z));
  update(user, new Position(xOff + x, yOff + y, zOff - 1));
} else if (z == 15) {
  update(user, new Position(xOff + x, yOff + y, zOff + 16));
origin: MylesIsCool/ViaVersion

  @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;
  }
}
origin: MylesIsCool/ViaVersion

@Override
public int getWorldBlockData(UserConnection user, Position position) {
  UUID uuid = user.get(ProtocolInfo.class).getUuid();
  Player player = Bukkit.getPlayer(uuid);
  if (player != null) {
    World world = player.getWorld();
    int x = (int) (position.getX() >> 4);
    int z = (int) (position.getZ() >> 4);
    if (world.isChunkLoaded(x, z)) {
      Chunk c = getChunk(world, x, z);
      Block b = c.getBlock(position.getX().intValue(), position.getY().intValue(), position.getZ().intValue());
      return b.getTypeId() << 4 | b.getData();
    }
  }
  return 0;
}
origin: MylesIsCool/ViaVersion

public static void handle(List<CompoundTag> tags, UserConnection connection) {
  for (CompoundTag tag : tags) {
    try {
      if (!tag.contains("id"))
        throw new Exception("NBT tag not handled because the id key is missing");
      String id = (String) tag.get("id").getValue();
      if (!types.containsKey(id))
        throw new Exception("Not handled id: " + id);
      int newId = types.get(id);
      if (newId == -1)
        continue;
      int x = (int) tag.get("x").getValue();
      int y = (int) tag.get("y").getValue();
      int z = (int) tag.get("z").getValue();
      Position pos = new Position((long) x, (long) y, (long) z);
      updateBlockEntity(pos, (short) newId, tag, connection);
    } catch (Exception e) {
      if (Via.getManager().isDebug()) {
        Via.getPlatform().getLogger().warning("Block Entity: " + e.getMessage() + ": " + tag);
      }
    }
  }
}
origin: MylesIsCool/ViaVersion

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;
}
origin: MylesIsCool/ViaVersion

  @Listener
  public void placeBlock(ChangeBlockEvent.Place e, @Root Player player) {
    if (isOnPipe(player.getUniqueId())) {
      Location loc = e.getTransactions().get(0).getFinal().getLocation().get();
      getUserConnection(player.getUniqueId())
          .get(EntityTracker.class)
          .addBlockInteraction(new Position((long) loc.getX(), (long) loc.getY(), (long) loc.getZ()));
    }
  }
}
origin: MylesIsCool/ViaVersion

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;
}
us.myles.ViaVersion.api.minecraftPosition

Most used methods

    Popular in Java

    • Reactive rest calls using spring rest template
    • getSharedPreferences (Context)
    • addToBackStack (FragmentTransaction)
    • notifyDataSetChanged (ArrayAdapter)
    • BufferedInputStream (java.io)
      A BufferedInputStream adds functionality to another input stream-namely, the ability to buffer the i
    • UUID (java.util)
      UUID is an immutable representation of a 128-bit universally unique identifier (UUID). There are mul
    • Pattern (java.util.regex)
      Patterns are compiled regular expressions. In many cases, convenience methods such as String#matches
    • Reference (javax.naming)
    • IsNull (org.hamcrest.core)
      Is the value null?
    • Loader (org.hibernate.loader)
      Abstract superclass of object loading (and querying) strategies. This class implements useful common
    • Top Vim plugins
    Tabnine Logo
    • Products

      Search for Java codeSearch for JavaScript code
    • IDE Plugins

      IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
    • Company

      About UsContact UsCareers
    • Resources

      FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
    Get Tabnine for your IDE now