Esempio n. 1
0
 public void setBlockMaterial(int xx, int yy, int zz, BlockMaterial material, short data) {
   final Vector3 transformed = transform(xx, yy, zz);
   position
       .getWorld()
       .setBlockMaterial(
           transformed.getFloorX(),
           transformed.getFloorY(),
           transformed.getFloorZ(),
           material,
           data,
           null);
   if (material instanceof Directional) {
     final Directional directional = (Directional) material;
     final Block block = position.getWorld().getBlock(transformed);
     final BlockFace face = directional.getFacing(block);
     if (face != BlockFace.BOTTOM && face != BlockFace.TOP) {
       directional.setFacing(
           block, BlockFace.fromYaw(face.getDirection().getYaw() + rotation.getYaw()));
     }
   } else if (material instanceof Attachable) {
     final Attachable attachable = (Attachable) material;
     final Block block = position.getWorld().getBlock(transformed);
     final BlockFace face = attachable.getAttachedFace(block);
     if (face != BlockFace.BOTTOM && face != BlockFace.TOP) {
       attachable.setAttachedFace(
           block, BlockFace.fromYaw(face.getDirection().getYaw() + rotation.getYaw()), null);
     }
   }
 }
Esempio n. 2
0
 public void placeObject(int xx, int yy, int zz, WorldGeneratorObject object) {
   final Vector3 transformed = transform(xx, yy, zz);
   if (object.canPlaceObject(
       position.getWorld(),
       transformed.getFloorX(),
       transformed.getFloorY(),
       transformed.getFloorZ())) {
     object.placeObject(
         position.getWorld(),
         transformed.getFloorX(),
         transformed.getFloorY(),
         transformed.getFloorZ());
   }
 }
Esempio n. 3
0
 public BlockMaterial getBlockMaterial(int xx, int yy, int zz) {
   final Vector3 transformed = transform(xx, yy, zz);
   return position
       .getWorld()
       .getBlockMaterial(
           transformed.getFloorX(), transformed.getFloorY(), transformed.getFloorZ());
 }
  @Override
  protected void freeChunk(Point p) {
    int x = (int) p.getX() >> Chunk.BLOCKS.BITS;
    int y = (int) p.getY() >> Chunk.BLOCKS.BITS; // + SEALEVEL_CHUNK;
    int z = (int) p.getZ() >> Chunk.BLOCKS.BITS;

    if (y < 0 || y >= p.getWorld().getHeight() >> Chunk.BLOCKS.BITS) {
      return;
    }

    TIntSet column = initializedChunks.get(x, z);
    CompressedChunkMessage CCMsg;
    if (column != null) {
      column.remove(y);
      if (column.isEmpty()) {
        if (initializedChunks.remove(x, z) != null) {
          activeChunks.remove(x, z);
        }
        CCMsg = new CompressedChunkMessage(x, z, true, null, null, null, true);
      } else {
        CCMsg = new CompressedChunkMessage(x, z, false, null, null, null, true);
      }

      session.send(false, CCMsg);
    }
  }
 @Command(
     aliases = {"biome"},
     usage = "",
     desc = "Print out the name of the biome at the current location",
     min = 0,
     max = 0)
 @CommandPermissions("vanilla.command.biome")
 public void getBiomeName(CommandContext args, CommandSource source) throws CommandException {
   if (!(source instanceof Player)) {
     throw new CommandException("Only a player may call this command.");
   }
   Player player = (Player) source;
   if (!(player.getTransform().getPosition().getWorld().getGenerator()
       instanceof BiomeGenerator)) {
     throw new CommandException("This map does not appear to have any biome data.");
   }
   Point pos = player.getTransform().getPosition();
   Biome biome = pos.getWorld().getBiome(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ());
   source.sendMessage(
       plugin.getPrefix(),
       ChatStyle.BRIGHT_GREEN,
       "Current biome: ",
       ChatStyle.WHITE,
       (biome != null ? biome.getName() : "none"));
 }
Esempio n. 6
0
  @Override
  public void onInteract(Entity entity, Block block, Action type, BlockFace clickedface) {
    super.onInteract(entity, block, type, clickedface);
    if (type == Action.RIGHT_CLICK) {
      BlockMaterial clickedmat = block.getMaterial();
      Cause<Entity> cause;
      if (entity instanceof Player) {
        cause = new PlayerCause((Player) entity);
      } else {
        cause = new EntityCause(entity);
      }
      if (clickedmat.equals(VanillaMaterials.TNT)) {
        // Detonate TntBlock
        VanillaMaterials.TNT.onIgnite(block, cause);
      } else {
        // Default fire creation
        Block target = block.translate(clickedface);
        // Default fire placement
        if (VanillaMaterials.FIRE.canCreate(target, (short) 0, cause)) {
          VanillaMaterials.FIRE.onCreate(target, (short) 0, cause);
          Slot held = PlayerUtil.getHeldSlot(entity);
          if (held != null && !PlayerUtil.isCostSuppressed(entity)) {
            held.addData(1);
          }
        }

        // Handle the creation of portals
        Point pos = target.translate(BlockFace.BOTTOM).getPosition();
        VanillaObjects.NETHER_PORTAL.setActive(
            pos.getWorld(), pos.getBlockX(), pos.getBlockY(), pos.getBlockZ(), true);
      }
    }
  }
  private void initChunkRaw(Point p) {
    int x = p.getChunkX();
    int y = p.getChunkY(); // + SEALEVEL_CHUNK;
    int z = p.getChunkZ();

    RepositionManager rm = getRepositionManager();

    int cY = rm.convertChunkY(y);

    if (cY < 0 || cY >= p.getWorld().getHeight() >> Chunk.BLOCKS.BITS) {
      return;
    }

    TSyncIntHashSet column = initializedChunks.get(x, z);
    if (column == null) {
      column = new TSyncIntHashSet();
      synchronized (initChunkLock) {
        TSyncIntHashSet oldColumn = initializedChunks.putIfAbsent(x, z, column);
        if (oldColumn != null) {
          column = oldColumn;
        }
      }
    }
    column.add(y);
  }
Esempio n. 8
0
 public SpoutBlock(Point position, Source source) {
   this(
       position.getWorld(),
       position.getBlockX(),
       position.getBlockY(),
       position.getBlockZ(),
       source);
 }
Esempio n. 9
0
 /**
  * Gets all the Players nearby a certain Point that can receive this Effect
  *
  * @param position of this Effect
  * @param ignore Entity to ignore
  * @return a Set of nearby Players
  */
 public List<Player> getNearbyPlayers(Point position, Player ignore, float volume) {
   int range = this.getRange();
   if (volume > 1.0f) {
     // Multiply range for different volumes
     range *= volume;
   }
   return position.getWorld().getNearbyPlayers(position, ignore, range);
 }
Esempio n. 10
0
 @EventHandler
 public void onSpoutEvent(PlayerInteractEvent event) {
   final Point point = event.getInteractedPoint();
   Block block =
       point
           .getWorld()
           .getBlock(point, (org.spout.api.plugin.Plugin) plugin.getFrameworkPlugin());
   event.getPlayer().sendMessage("Stop messing with that " + block.getMaterial() + "!");
 }
Esempio n. 11
0
 @Override
 public void play(Player player, Point position, int note) {
   Block block = position.getWorld().getBlock(position);
   player
       .getSession()
       .getNetworkSynchronizer()
       .callProtocolEvent(
           new BlockActionEvent(block, VanillaMaterials.NOTEBLOCK, (byte) 0, (byte) note));
 }
Esempio n. 12
0
 @Override
 @SuppressWarnings("unchecked")
 public Minecart spawnEntity(Point position) {
   Class<? extends Minecart> component = this.getSpawnedComponent();
   Entity spawned =
       position
           .getWorld()
           .createAndSpawnEntity(position, LoadOption.NO_LOAD, component, getMinecartType());
   return spawned.add(component);
 }
Esempio n. 13
0
 @Override
 public void onTick(float dt) {
   Point pos = this.getOwner().getTransform().getPosition();
   BlockMaterial material =
       pos.getWorld().getBlockMaterial(pos.getBlockX(), pos.getBlockY() - 1, pos.getBlockZ());
   if (isObstacle(material)) {
     pos.getWorld()
         .setBlockMaterial(
             pos.getBlockX(),
             pos.getBlockY(),
             pos.getBlockZ(),
             getMaterial(),
             getMaterial().getData(),
             getMaterial().toCause(pos));
     this.getOwner().remove();
   } else {
     this.getOwner().getTransform().setPosition(pos.add(0, fallSpeed, 0F));
     fallSpeed = Math.max(-1F, fallSpeed - dt);
   }
 }
Esempio n. 14
0
 /** Ejects the currently playing music disc */
 public void eject() {
   ItemStack current = this.inventory.getMusicSlot();
   this.inventory.setMusicSlot(null);
   if (current != null) {
     Point position = this.getParent().getPosition();
     position
         .getWorld()
         .createAndSpawnEntity(position, new Item(current, Vector3.UP.multiply(0.5)));
     this.update();
   }
 }
  private static int[][] getColumnHeights(Point p) {
    int[][] heights = new int[Chunk.BLOCKS.SIZE][Chunk.BLOCKS.SIZE];

    World w = p.getWorld();

    for (int xx = 0; xx < Chunk.BLOCKS.SIZE; xx++) {
      for (int zz = 0; zz < Chunk.BLOCKS.SIZE; zz++) {
        heights[xx][zz] = w.getSurfaceHeight(p.getBlockX() + xx, p.getBlockZ() + zz, true);
      }
    }
    return heights;
  }
  private static BlockMaterial[][] getColumnTopmostMaterials(Point p) {
    BlockMaterial[][] materials = new BlockMaterial[Chunk.BLOCKS.SIZE][Chunk.BLOCKS.SIZE];

    World w = p.getWorld();

    for (int xx = 0; xx < Chunk.BLOCKS.SIZE; xx++) {
      for (int zz = 0; zz < Chunk.BLOCKS.SIZE; zz++) {
        materials[xx][zz] = w.getTopmostBlock(p.getBlockX() + xx, p.getBlockZ() + zz, true);
      }
    }
    return materials;
  }
Esempio n. 17
0
  /** Called when the tick is finished and collisions need to be resolved and move events fired */
  public void resolve() {
    if (Spout.debugMode()) {
      //	System.out.println("COLLISION DEBUGGING");
      //	System.out.println("Current Collision: " + this.collision.toString());
    }

    List<CollisionVolume> colliding =
        ((SpoutWorld) collisionPoint.getWorld()).getCollidingObject(this.collision);

    Vector3 offset = this.lastTransform.getPosition().subtract(collisionPoint);
    for (CollisionVolume box : colliding) {
      if (Spout.debugMode()) {
        //	System.out.println("Colliding box: " + box.toString());
      }
      Vector3 collision = this.collision.resolve(box);
      if (Spout.debugMode()) {
        //	System.out.println("Collision vector: " + collision.toString());
      }
      if (collision != null) {
        collision = collision.subtract(collisionPoint);
        if (Spout.debugMode()) {
          //	System.out.println("Collision point: " + collision.toString() + " Collision vector: " +
          // collision);
        }

        if (collision.getX() != 0F) {
          offset = new Vector3(collision.getX(), offset.getY(), offset.getZ());
        }
        if (collision.getY() != 0F) {
          offset = new Vector3(offset.getX(), collision.getY(), offset.getZ());
        }
        if (collision.getZ() != 0F) {
          offset = new Vector3(offset.getX(), offset.getY(), collision.getZ());
        }

        if (Spout.debugMode()) {
          //	System.out.println("Collision offset: " + offset.toString());
        }
        if (this.getCollision().getStrategy() == CollisionStrategy.SOLID
            && box.getStrategy() == CollisionStrategy.SOLID) {
          this.setPosition(collisionPoint.add(offset));
          if (Spout.debugMode()) {
            //	System.out.println("New Position: " + this.getPosition());
          }
        }

        controllerLive.get().onCollide(getWorld().getBlock(box.getPosition()));
      }
    }

    // Check to see if we should fire off a Move event
  }
 @Command(
     aliases = {"list", "ls"},
     desc = "Lists the existing waypoints",
     min = 0,
     max = 0)
 @Permissible("plugintest.waypoint.list")
 public void list(CommandSource source, CommandArguments args) throws CommandException {
   for (Map.Entry<String, Point> entry : this.waypoints.entrySet()) {
     Point p = entry.getValue();
     source.sendMessage(
         entry.getKey()
             + " -> ("
             + p.getWorld().getName()
             + ":"
             + p.getX()
             + ","
             + p.getY()
             + ","
             + p.getZ()
             + ")");
   }
 }
  @Override
  protected void freeChunk(Point p) {
    int x = (int) p.getX() >> Chunk.BLOCKS.BITS;
    int y = (int) p.getY() >> Chunk.BLOCKS.BITS; // + SEALEVEL_CHUNK;
    int z = (int) p.getZ() >> Chunk.BLOCKS.BITS;

    if (y < 0 || y >= p.getWorld().getHeight() >> Chunk.BLOCKS.BITS) {
      return;
    }

    TIntSet column = initializedChunks.get(x, z);
    if (column != null) {
      column.remove(y);
      if (column.isEmpty()) {
        emptyColumns.add(IntPairHashed.key(x, z));
      } // TODO - is this required?
      /*
      else {
      	CCMsg = new ChunkDataMessage(x, z, false, null, null, null, true);
      }*/
    }
  }
  @Override
  protected void freeChunk(Point p) {
    int x = (int) p.getX() >> Chunk.BLOCKS.BITS;
    int y = (int) p.getY() >> Chunk.BLOCKS.BITS; // + SEALEVEL_CHUNK;
    int z = (int) p.getZ() >> Chunk.BLOCKS.BITS;

    RepositionManager rm = getRepositionManager();

    int cY = rm.convertChunkY(y);

    if (cY < 0 || cY >= p.getWorld().getHeight() >> Chunk.BLOCKS.BITS) {
      return;
    }

    TIntSet column = initializedChunks.get(x, z);
    if (column != null) {
      column.remove(y);
      if (column.isEmpty()) {
        emptyColumns.add(IntPairHashed.key(x, z));
      }
    }
  }
  @Override
  protected void initChunk(Point p) {

    int x = p.getChunkX();
    int y = p.getChunkY(); // + SEALEVEL_CHUNK;
    int z = p.getChunkZ();

    if (y < 0 || y >= p.getWorld().getHeight() >> Chunk.BLOCKS.BITS) {
      return;
    }

    TSyncIntHashSet column = initializedChunks.get(x, z);
    if (column == null) {
      column = new TSyncIntHashSet();
      synchronized (initChunkLock) {
        TSyncIntHashSet oldColumn = initializedChunks.putIfAbsent(x, z, column);
        if (oldColumn != null) {
          column = oldColumn;
        }
      }
    }
    column.add(y);
  }
Esempio n. 22
0
 public Point(Point point) {
   super(point);
   world = point.getWorld();
 }
Esempio n. 23
0
 @Override
 public Point convert(Point p) {
   Point newP = new Point(convert((Vector3) p), p.getWorld());
   return newP;
 }
  @Override
  protected Collection<Chunk> sendChunk(Chunk c, boolean force) {

    if (!force) {
      return sendChunk(c);
    }

    int x = c.getX();
    int y = c.getY(); // + SEALEVEL_CHUNK;
    int z = c.getZ();

    RepositionManager rm = getRepositionManager();

    int cY = rm.convertChunkY(y);

    if (cY < 0 || cY >= c.getWorld().getHeight() >> Chunk.BLOCKS.BITS) {
      return null;
    }

    initChunkRaw(c.getBase());

    Collection<Chunk> chunks = null;

    List<ProtocolEvent> events = new ArrayList<ProtocolEvent>();

    if (activeChunks.add(x, z)) {
      Point p = c.getBase();
      int[][] heights = getColumnHeights(p);
      BlockMaterial[][] materials = getColumnTopmostMaterials(p);

      byte[][] packetChunkData = new byte[16][];

      for (int cube = 0; cube < 16; cube++) {
        int serverCube = rm.getInverse().convertChunkY(cube);
        Point pp =
            new Point(
                c.getWorld(),
                x << Chunk.BLOCKS.BITS,
                serverCube << Chunk.BLOCKS.BITS,
                z << Chunk.BLOCKS.BITS);
        packetChunkData[cube] = chunkInit.getChunkData(heights, materials, pp, events);
      }

      Chunk chunk = p.getWorld().getChunkFromBlock(p);
      byte[] biomeData = new byte[Chunk.BLOCKS.AREA];
      for (int dx = x; dx < x + Chunk.BLOCKS.SIZE; ++dx) {
        for (int dz = z; dz < z + Chunk.BLOCKS.SIZE; ++dz) {
          Biome biome = chunk.getBiome(dx & Chunk.BLOCKS.MASK, 0, dz & Chunk.BLOCKS.MASK);
          if (biome instanceof VanillaBiome) {
            biomeData[(dz & Chunk.BLOCKS.MASK) << 4 | (dx & Chunk.BLOCKS.MASK)] =
                (byte) ((VanillaBiome) biome).getBiomeId();
          }
        }
      }

      ChunkDataMessage CCMsg =
          new ChunkDataMessage(
              x,
              z,
              true,
              new boolean[16],
              packetChunkData,
              biomeData,
              player.getSession(),
              getRepositionManager());
      player.getSession().send(false, CCMsg);

      chunks = chunkInit.getChunks(c);
    }

    if (chunks == null || !chunks.contains(c)) {

      byte[] fullChunkData = ChunkInit.getChunkFullData(c, events);

      byte[][] packetChunkData = new byte[16][];
      packetChunkData[cY] = fullChunkData;
      ChunkDataMessage CCMsg =
          new ChunkDataMessage(
              x,
              z,
              false,
              new boolean[16],
              packetChunkData,
              null,
              player.getSession(),
              getRepositionManager());
      player.getSession().send(false, CCMsg);

      if (chunks == null) {
        chunks = new ArrayList<Chunk>(1);
      }
      chunks.add(c);
    }

    for (ProtocolEvent e : events) {
      this.callProtocolEvent(e);
    }

    return chunks;
  }
 private static byte[] getChunkFullColumn(
     int[][] heights, BlockMaterial[][] materials, Point p, List<ProtocolEvent> updateEvents) {
   Chunk c = p.getWorld().getChunkFromBlock(p);
   return getChunkFullData(c, updateEvents);
 }
  @Override
  public void sendChunk(Chunk c) {

    int x = c.getX();
    int y = c.getY(); // + SEALEVEL_CHUNK;
    int z = c.getZ();

    if (y < 0 || y >= c.getWorld().getHeight() >> Chunk.BLOCKS.BITS) {
      return;
    }

    initChunk(c.getBase());

    if (activeChunks.add(x, z)) {
      Point p = c.getBase();
      int[][] heights = getColumnHeights(p);
      BlockMaterial[][] materials = getColumnTopmostMaterials(p);

      byte[][] packetChunkData = new byte[16][];

      for (int cube = 0; cube < 16; cube++) {
        packetChunkData[cube] = getChunkHeightMap(heights, materials, cube);
      }

      Chunk chunk = p.getWorld().getChunkFromBlock(p);
      byte[] biomeData = new byte[Chunk.BLOCKS.AREA];
      for (int dx = x; dx < x + Chunk.BLOCKS.SIZE; ++dx) {
        for (int dz = z; dz < z + Chunk.BLOCKS.SIZE; ++dz) {
          Biome biome = chunk.getBiomeType(dx & Chunk.BLOCKS.MASK, 0, dz & Chunk.BLOCKS.MASK);
          if (biome instanceof VanillaBiome) {
            biomeData[(dz & Chunk.BLOCKS.MASK) << 4 | (dx & Chunk.BLOCKS.MASK)] =
                (byte) ((VanillaBiome) biome).getBiomeId();
          }
        }
      }

      CompressedChunkMessage CCMsg =
          new CompressedChunkMessage(x, z, true, new boolean[16], packetChunkData, biomeData);
      owner.getSession().send(false, CCMsg);
    }

    ChunkSnapshot snapshot =
        c.getSnapshot(SnapshotType.BOTH, EntityType.NO_ENTITIES, ExtraData.NO_EXTRA_DATA);
    short[] rawBlockIdArray = snapshot.getBlockIds();
    short[] rawBlockData = snapshot.getBlockData();
    byte[] rawBlockLight = snapshot.getBlockLight();
    byte[] rawSkyLight = snapshot.getSkyLight();
    byte[] fullChunkData = new byte[Chunk.BLOCKS.HALF_VOLUME * 5];

    int arrIndex = 0;
    for (int i = 0; i < rawBlockIdArray.length; i++) {
      short convert = getMinecraftId(rawBlockIdArray[i]);
      fullChunkData[arrIndex++] = (byte) (convert & 0xFF);
    }

    for (int i = 0; i < rawBlockData.length; i += 2) {
      fullChunkData[arrIndex++] = (byte) ((rawBlockData[i + 1] << 4) | (rawBlockData[i] & 0xF));
    }

    System.arraycopy(rawBlockLight, 0, fullChunkData, arrIndex, rawBlockLight.length);
    arrIndex += rawBlockLight.length;

    System.arraycopy(rawSkyLight, 0, fullChunkData, arrIndex, rawSkyLight.length);

    arrIndex += rawSkyLight.length;

    byte[][] packetChunkData = new byte[16][];
    packetChunkData[y] = fullChunkData;
    CompressedChunkMessage CCMsg =
        new CompressedChunkMessage(x, z, false, new boolean[16], packetChunkData, null);
    owner.getSession().send(false, CCMsg);
  }
 private static byte[] getChunkFullColumn(
     int[][] heights, BlockMaterial[][] materials, Point p) {
   Chunk c = p.getWorld().getChunkFromBlock(p);
   return getChunkFullData(c);
 }
Esempio n. 28
0
 public static Point center(Point loc) {
   return new Point(loc.getWorld(), loc.getX() + 0.5F, loc.getY() + 0.5F, loc.getZ() + 0.5F);
 }
Esempio n. 29
0
 public Block getBlock(int xx, int yy, int zz) {
   return position.getWorld().getBlock(transform(xx, yy, zz));
 }
  @Override
  public Collection<Chunk> sendChunk(Chunk c) {

    int x = c.getX();
    int y = c.getY(); // + SEALEVEL_CHUNK;
    int z = c.getZ();

    if (y < 0 || y >= c.getWorld().getHeight() >> Chunk.BLOCKS.BITS) {
      return null;
    }

    initChunk(c.getBase());

    Collection<Chunk> chunks = null;

    if (activeChunks.add(x, z)) {
      Point p = c.getBase();
      int[][] heights = getColumnHeights(p);
      BlockMaterial[][] materials = getColumnTopmostMaterials(p);

      byte[][] packetChunkData = new byte[16][];

      for (int cube = 0; cube < 16; cube++) {
        Point pp =
            new Point(
                c.getWorld(),
                x << Chunk.BLOCKS.BITS,
                cube << Chunk.BLOCKS.BITS,
                z << Chunk.BLOCKS.BITS);
        packetChunkData[cube] = chunkInit.getChunkData(heights, materials, pp);
      }

      Chunk chunk = p.getWorld().getChunkFromBlock(p);
      byte[] biomeData = new byte[Chunk.BLOCKS.AREA];
      for (int dx = x; dx < x + Chunk.BLOCKS.SIZE; ++dx) {
        for (int dz = z; dz < z + Chunk.BLOCKS.SIZE; ++dz) {
          Biome biome = chunk.getBiome(dx & Chunk.BLOCKS.MASK, 0, dz & Chunk.BLOCKS.MASK);
          if (biome instanceof VanillaBiome) {
            biomeData[(dz & Chunk.BLOCKS.MASK) << 4 | (dx & Chunk.BLOCKS.MASK)] =
                (byte) ((VanillaBiome) biome).getBiomeId();
          }
        }
      }

      ChunkDataMessage CCMsg =
          new ChunkDataMessage(
              x, z, true, new boolean[16], packetChunkData, biomeData, player.getSession());
      player.getSession().send(false, CCMsg);

      chunks = chunkInit.getChunks(c);
    }

    byte[] fullChunkData = ChunkInit.getChunkFullData(c);

    byte[][] packetChunkData = new byte[16][];
    packetChunkData[y] = fullChunkData;
    ChunkDataMessage CCMsg =
        new ChunkDataMessage(
            x, z, false, new boolean[16], packetChunkData, null, player.getSession());
    player.getSession().send(false, CCMsg);

    return chunks;
  }