Ejemplo n.º 1
0
  private static boolean trySpawnEntity(ItemStack stack, WorldServer world, EntityPlayerMP player) {
    int damage = stack.getItemDamage();
    if (damage >= stack.getMaxDamage()) return false;

    NBTTagCompound tag = ItemUtils.getItemTag(stack);
    String structureName = tag.getString(TAG_STRUCTURE);

    if (Strings.isNullOrEmpty(structureName)) return false;

    Map<String, ChunkPosition> nearbyStructures =
        StructureRegistry.instance.getNearestStructures(
            world, (int) player.posX, (int) player.posY, (int) player.posZ);

    ChunkPosition structurePos = nearbyStructures.get(structureName);
    if (structurePos != null) {
      if (Config.eyeDebug)
        player.addChatComponentMessage(
            new ChatComponentTranslation(
                "openblocks.misc.structure_pos",
                structureName,
                structurePos.chunkPosX,
                structurePos.chunkPosY,
                structurePos.chunkPosZ));

      stack.setItemDamage(damage + 1);
      EntityGoldenEye eye = new EntityGoldenEye(world, stack, player, structurePos);
      world.spawnEntityInWorld(eye);
      world.playSoundAtEntity(
          player, "random.bow", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
      return true;
    }
    return false;
  }
Ejemplo n.º 2
0
 @Override
 @SideOnly(Side.CLIENT)
 @SuppressWarnings({"rawtypes", "unchecked"})
 public void addInformation(ItemStack stack, EntityPlayer player, List result, boolean expanded) {
   NBTTagCompound tag = ItemUtils.getItemTag(stack);
   if (tag.hasKey(TAG_STRUCTURE))
     result.add(StatCollector.translateToLocal("openblocks.misc.locked"));
 }
Ejemplo n.º 3
0
  private static void saveTank(ItemStack container, FluidTank tank) {
    if (tank.getFluidAmount() > 0) {
      NBTTagCompound itemTag = ItemUtils.getItemTag(container);

      NBTTagCompound tankTag = new NBTTagCompound();
      tank.writeToNBT(tankTag);
      itemTag.setTag(TANK_TAG, tankTag);
    } else {
      container.stackTagCompound = null;
    }
  }
Ejemplo n.º 4
0
  private static void tryLearnStructure(ItemStack stack, WorldServer world, EntityPlayerMP player) {
    Map<String, ChunkPosition> nearbyStructures =
        StructureRegistry.instance.getNearestStructures(
            world, (int) player.posX, (int) player.posY, (int) player.posZ);

    String structureName = "";
    double max = Double.MAX_VALUE;

    for (Map.Entry<String, ChunkPosition> e : nearbyStructures.entrySet()) {
      ChunkPosition pos = e.getValue();
      if (Config.eyeDebug)
        player.addChatMessage(
            new ChatComponentTranslation(
                "openblocks.misc.structure_pos",
                e.getKey(),
                pos.chunkPosX,
                pos.chunkPosY,
                pos.chunkPosZ));

      double dx = pos.chunkPosX - player.posX;
      double dy = pos.chunkPosY - player.posY;
      double dz = pos.chunkPosZ - player.posZ;

      double dist = (dx * dx) + (dy * dy) + (dz * dz);

      if (dist < max) {
        max = dist;
        structureName = e.getKey();
      }
    }

    if (!Strings.isNullOrEmpty(structureName)) {
      Log.info("Learned structure %s, d = %f", structureName, max);
      NBTTagCompound tag = ItemUtils.getItemTag(stack);
      tag.setString(TAG_STRUCTURE, structureName);
    }
  }
Ejemplo n.º 5
0
 public static ItemStack putMetadata(ItemStack stack, Trophy trophy) {
   NBTTagCompound tag = ItemUtils.getItemTag(stack);
   tag.setString(TAG_ENTITY, trophy.name());
   return stack;
 }