Пример #1
0
 public static MinecartMember spawn(Location at, int type) {
   MinecartMember mm =
       new MinecartMember(
           WorldUtil.getNative(at.getWorld()), at.getX(), at.getY(), at.getZ(), type);
   mm.yaw = at.getYaw();
   mm.pitch = at.getPitch();
   mm.world.addEntity(mm);
   return mm;
 }
Пример #2
0
 private static boolean isHeadingTo(MinecartMember mm, ChunkCoordinates to) {
   if (mm == null) {
     return false;
   } else {
     BlockFace dir = mm.getDirection();
     if (dir.getModX() + mm.getBlockX() != to.x) return false;
     if (dir.getModZ() + mm.getBlockZ() != to.z) return false;
     return true;
   }
 }
Пример #3
0
 public static void cleanUpDeadCarts() {
   Iterator<MinecartMember> iter = replacedCarts.iterator();
   MinecartMember mm;
   while (iter.hasNext()) {
     mm = iter.next();
     if (mm.dead) {
       iter.remove();
       mm.die();
     }
   }
 }
Пример #4
0
 public static MinecartMember getAt(Location at, MinecartGroup in, double searchRadius) {
   if (at == null) return null;
   searchRadius *= searchRadius;
   MinecartMember result = null;
   for (Entity e : at.getBlock().getChunk().getEntities()) {
     if (e instanceof Minecart) {
       MinecartMember mm = get(e);
       if (mm == null) continue;
       if (in != null && mm.getGroup() != in) continue;
       if (mm.distanceSquared(at) > searchRadius) continue;
       result = mm;
       if (mm.isHeadingTo(at)) return result;
     }
   }
   return result;
 }
Пример #5
0
 public static EntityMinecart undoReplacement(MinecartMember mm) {
   replacedCarts.remove(mm);
   if (!mm.dead) {
     denyConversion = true;
     mm.died = true;
     EntityMinecart em = new EntityMinecart(mm.world, mm.lastX, mm.lastY, mm.lastZ, mm.type);
     replaceMinecarts(mm, em);
     denyConversion = false;
     return em;
   }
   return null;
 }
Пример #6
0
  @SuppressWarnings("rawtypes")
  public static MinecartMember getAt(World world, ChunkCoordinates coord, boolean checkmoving) {
    net.minecraft.server.Chunk chunk = WorldUtil.getChunk(world, coord.x >> 4, coord.z >> 4);
    if (chunk != null) {
      MinecartMember mm;
      MinecartMember result = null;
      for (List list : chunk.entitySlices) {
        for (Object e : list) {
          if (e instanceof MinecartMember) {
            mm = (MinecartMember) e;
            if (mm.getBlockX() != coord.x) continue;
            if (mm.getBlockY() != coord.y) continue;
            if (mm.getBlockZ() != coord.z) continue;
            result = mm;
            if (result.isHeadingTo(coord)) return result;
          }
        }
      }
      if (result == null && checkmoving) {
        Block b = world.getWorld().getBlockAt(coord.x, coord.y, coord.z);
        int id = b.getTypeId();

        // get the two connected rails to check
        if (BlockUtil.isRails(id)) {
          BlockFace[] possible = FaceUtil.getFaces(BlockUtil.getRails(b).getDirection());
          MinecartMember mm1 = getAt(Util.getRailsBlock(b.getRelative(possible[0])), false);
          MinecartMember mm2 = getAt(Util.getRailsBlock(b.getRelative(possible[1])), false);
          if (mm1 != null && mm2 != null && mm1.group == mm2.group) {
            Location loc = b.getLocation();
            return mm1.distance(loc) < mm2.distance(loc) ? mm1 : mm2;
          } else if (isHeadingTo(mm1, coord)) {
            return mm1;
          } else if (isHeadingTo(mm2, coord)) {
            return mm2;
          } else {
            return null;
          }
        } else if (Util.isPressurePlate(id)) {
          // check all directions
          MinecartMember mm1 = getAt(Util.getRailsBlock(b.getRelative(BlockFace.NORTH)), false);
          MinecartMember mm2 = getAt(Util.getRailsBlock(b.getRelative(BlockFace.SOUTH)), false);
          MinecartMember mm3 = getAt(Util.getRailsBlock(b.getRelative(BlockFace.EAST)), false);
          MinecartMember mm4 = getAt(Util.getRailsBlock(b.getRelative(BlockFace.WEST)), false);
          if (mm1 != null && mm2 != null && mm1.group == mm2.group) {
            Location loc = b.getLocation();
            return mm1.distance(loc) < mm2.distance(loc) ? mm1 : mm2;
          } else if (mm3 != null && mm4 != null && mm3.group == mm4.group) {
            Location loc = b.getLocation();
            return mm3.distance(loc) < mm4.distance(loc) ? mm3 : mm4;
          } else if (isHeadingTo(mm1, coord)) {
            return mm1;
          } else if (isHeadingTo(mm2, coord)) {
            return mm2;
          } else if (isHeadingTo(mm3, coord)) {
            return mm3;
          } else if (isHeadingTo(mm4, coord)) {
            return mm4;
          } else {
            return null;
          }
        }
      }
      return result;
    }
    return null;
  }