public void onPostBakeEvent(IRegistry<ModelResourceLocation, IBakedModel> modelRegistry) {
   IBakedModel missingModel = modelRegistry.getObject(MODEL_MISSING);
   for (ModelResourceLocation missing : missingVariants) {
     IBakedModel model = modelRegistry.getObject(missing);
     if (model == null || model == missingModel) {
       FMLLog.severe("Model definition for location %s not found", missing);
     }
   }
   isLoading = false;
 }
Esempio n. 2
0
 public void completeHandshake(Side target) {
   if (state == ConnectionState.CONNECTED) {
     FMLLog.severe("Attempt to double complete the network connection!");
     throw new FMLNetworkException("Attempt to double complete!");
   }
   if (side == Side.CLIENT) {
     completeClientSideConnection(ConnectionType.MODDED);
   } else {
     this.state = ConnectionState.FINALIZING; // Delay and finalize in the world tick loop.
   }
 }
Esempio n. 3
0
  @Override
  public ModelFluid process(ImmutableMap<String, String> customData) {
    if (!customData.containsKey("fluid")) return this;

    String fluidStr = customData.get("fluid");
    JsonElement e = new JsonParser().parse(fluidStr);
    String fluid = e.getAsString();
    if (!FluidRegistry.isFluidRegistered(fluid)) {
      FMLLog.severe("fluid '%s' not found", fluid);
      return WATER;
    }
    return new ModelFluid(FluidRegistry.getFluid(fluid));
  }
Esempio n. 4
0
 private void resize(int x, int y, int z) {
   if (x <= 0 || x > MAX_X_SIZE || y <= 0 || y > MAX_Y_SIZE || z <= 0 || z > MAX_Z_SIZE) {
     FMLLog.severe("Out-of-range [x,y,z] in VoxelSelection constructor: [%d, %d, %d]", x, y, z);
     x = 1;
     y = 1;
     z = 1;
   }
   xSize = x;
   ySize = y;
   zSize = z;
   if (voxels == null) {
     voxels = new BitSet(xSize * ySize * zSize); // default to all false
   } else {
     voxels.clear();
   }
 }
Esempio n. 5
0
 private FMLControlledNamespacedRegistry<?> findRegistry(Class<?> type) {
   BiMap<Class<?>, String> typeReg = registryTypes.inverse();
   String name = typeReg.get(type);
   if (name == null) {
     Set<Class<?>> parents = Sets.newHashSet();
     findSuperTypes(type, parents);
     SetView<Class<?>> foundType = Sets.intersection(parents, registryTypes.values());
     if (foundType.isEmpty()) {
       FMLLog.severe("Unable to find registry for type %s", type.getName());
       throw new IllegalArgumentException(
           "Attempt to register an object without an associated registry");
     }
     Class<?> regtype = Iterables.getOnlyElement(foundType);
     name = typeReg.get(regtype);
   }
   return genericRegistries.get(name);
 }
Esempio n. 6
0
 @SuppressWarnings("unchecked")
 private <T> FMLControlledNamespacedRegistry<T> createGenericRegistry(
     String registryName, Class<T> type, int minId, int maxId) {
   Set<Class<?>> parents = Sets.newHashSet();
   findSuperTypes(type, parents);
   SetView<Class<?>> overlappedTypes = Sets.intersection(parents, registryTypes.values());
   if (!overlappedTypes.isEmpty()) {
     Class<?> foundType = overlappedTypes.iterator().next();
     FMLLog.severe(
         "Found existing registry of type %1s named %2s, you cannot create a new registry (%3s) with type %4s, as %4s has a parent of that type",
         foundType, registryTypes.inverse().get(foundType), registryName, type);
     throw new IllegalArgumentException(
         "Duplicate registry parent type found - you can only have one registry for a particular super type");
   }
   FMLControlledNamespacedRegistry<?> fmlControlledNamespacedRegistry =
       new FMLControlledNamespacedRegistry<T>(null, maxId, minId, type);
   genericRegistries.put(registryName, fmlControlledNamespacedRegistry);
   registryTypes.put(registryName, type);
   return (FMLControlledNamespacedRegistry<T>) fmlControlledNamespacedRegistry;
 }
Esempio n. 7
0
  public static List<String> processIdRematches(
      Iterable<MissingMapping> missedMappings,
      boolean isLocalWorld,
      GameData gameData,
      Map<String, Integer[]> remapBlocks,
      Map<String, Integer[]> remapItems) {
    List<String> failed = Lists.newArrayList();
    List<String> ignored = Lists.newArrayList();
    List<String> warned = Lists.newArrayList();
    List<String> defaulted = Lists.newArrayList();

    for (MissingMapping remap : missedMappings) {
      FMLMissingMappingsEvent.Action action = remap.getAction();

      if (action == FMLMissingMappingsEvent.Action.REMAP) {
        // block/item re-mapped, finish the registration with the new name/object, but the old id
        int currId, newId;
        String newName;

        if (remap.type == Type.BLOCK) {
          currId = getMain().iBlockRegistry.getId((Block) remap.getTarget());
          newName = getMain().iBlockRegistry.getNameForObject(remap.getTarget()).toString();
          FMLLog.fine("The Block %s is being remapped to %s.", remap.name, newName);

          newId = gameData.registerBlock((Block) remap.getTarget(), newName, remap.id);
          gameData.iBlockRegistry.addAlias(remap.name, newName);
        } else {
          currId = getMain().iItemRegistry.getId((Item) remap.getTarget());
          newName = getMain().iItemRegistry.getNameForObject(remap.getTarget()).toString();
          FMLLog.fine("The Item %s is being remapped to %s.", remap.name, newName);

          newId = gameData.registerItem((Item) remap.getTarget(), newName, remap.id);
          gameData.iItemRegistry.addAlias(remap.name, newName);
        }

        if (newId != remap.id) throw new IllegalStateException();

        if (currId != newId) {
          FMLLog.info(
              "Fixed %s id mismatch %s: %d (init) -> %d (map).",
              remap.type == Type.BLOCK ? "block" : "item", newName, currId, newId);
          (remap.type == Type.BLOCK ? remapBlocks : remapItems)
              .put(newName, new Integer[] {currId, newId});
        }
      } else if (action == FMLMissingMappingsEvent.Action.BLOCKONLY) {
        // Pulled out specifically so the block doesn't get reassigned a new ID just because it's
        // Item block has gone away
        FMLLog.fine(
            "The ItemBlock %s is no longer present in the game. The residual block will remain",
            remap.name);
      } else {
        // block item missing, warn as requested and block the id
        if (action == FMLMissingMappingsEvent.Action.DEFAULT) {
          defaulted.add(remap.name);
        } else if (action == FMLMissingMappingsEvent.Action.IGNORE) {
          ignored.add(remap.name);
        } else if (action == FMLMissingMappingsEvent.Action.FAIL) {
          failed.add(remap.name);
        } else if (action == FMLMissingMappingsEvent.Action.WARN) {
          warned.add(remap.name);
        }

        gameData.block(remap.id); // prevent the id from being reused later
      }
    }

    if (!defaulted.isEmpty()) {
      String text =
          "Forge Mod Loader detected missing blocks/items.\n\n"
              + "There are "
              + defaulted.size()
              + " missing blocks and items in this save.\n"
              + "If you continue the missing blocks/items will get removed.\n"
              + "A world backup will be automatically created in your saves directory.\n\n"
              + "Missing Blocks/Items:\n";

      for (String s : defaulted) text += s + "\n";

      boolean confirmed = StartupQuery.confirm(text);
      if (!confirmed) StartupQuery.abort();

      try {
        String skip = System.getProperty("fml.doNotBackup");
        if (skip == null || !"true".equals(skip)) {
          ZipperUtil.backupWorld();
        } else {
          for (int x = 0; x < 10; x++)
            FMLLog.severe("!!!!!!!!!! UPDATING WORLD WITHOUT DOING BACKUP !!!!!!!!!!!!!!!!");
        }
      } catch (IOException e) {
        StartupQuery.notify("The world backup couldn't be created.\n\n" + e);
        StartupQuery.abort();
      }

      warned.addAll(defaulted);
    }
    if (!failed.isEmpty()) {
      FMLLog.severe(
          "This world contains blocks and items that refuse to be remapped. The world will not be loaded");
      return failed;
    }
    if (!warned.isEmpty()) {
      FMLLog.severe("This world contains block and item mappings that may cause world breakage");
      return failed;
    } else if (!ignored.isEmpty()) {
      FMLLog.fine("There were %d missing mappings that have been ignored", ignored.size());
    }
    return failed;
  }
Esempio n. 8
0
  /**
   * Fix IDs improperly allocated by early versions of the registry, best-effort.
   *
   * <p>Items sharing the same ID with a block, but not sharing the same registry name will be
   * mapped to an unused id. Losing items instead of blocks should minimize the damage.
   *
   * @param dataList List containing the IDs to fix
   */
  public static void fixBrokenIds(
      GameDataSnapshot.Entry blocks, GameDataSnapshot.Entry items, Set<Integer> blockedIds) {
    BitSet availabilityMap = new BitSet(MAX_ITEM_ID + 1);

    // reserve all ids occupied by blocks
    for (Entry<String, Integer> entry : blocks.ids.entrySet()) {
      availabilityMap.set(entry.getValue());
    }

    Set<Integer> newBlockedIds = new HashSet<Integer>();
    Set<String> itemsToRemove = new HashSet<String>();
    Map<String, Integer> itemsToRelocate = new HashMap<String, Integer>();

    // check all ids occupied by items
    for (Entry<String, Integer> entry : items.ids.entrySet()) {
      int oldId = entry.getValue();
      String name = entry.getKey();
      Item item = getMain().iItemRegistry.getRaw(name);
      boolean blockThisId = false; // block oldId unless it's used by a block

      if (item == null) // item no longer available
      {
        // can't fix items without reliably checking if they are ItemBlocks
        FMLLog.warning(
            "Item %s (old id %d) is no longer available and thus can't be fixed.", name, oldId);
        itemsToRemove.add(name);
        blockThisId = true;
      } else if (item instanceof ItemBlock) {
        if (blocks.ids.containsKey(name)) // the item was an ItemBlock before
        {
          int blockId = blocks.ids.get(name);

          if (blockId != oldId) // mis-located ItemBlock
          {
            // relocate to the matching block
            FMLLog.warning(
                "ItemBlock %s (old id %d) doesn't have the same id as its block (%d).",
                name, oldId, blockId);
            itemsToRelocate.put(name, blockId);
            blockThisId = true;
          } else // intact ItemBlock
          {
            availabilityMap.set(oldId); // occupy id
          }
        } else // the item hasn't been an ItemBlock before, but it's now
        {
          // can't fix these, drop them
          FMLLog.warning(
              "Item %s (old id %d) has been migrated to an ItemBlock and can't be fixed.",
              name, oldId);
          itemsToRemove.add(name);
          blockThisId = true;
        }
      } else if (availabilityMap.get(oldId)) // normal item, id is already occupied
      {
        // remove the item mapping
        FMLLog.warning(
            "Item %s (old id %d) is conflicting with another block/item and can't be fixed.",
            name, oldId);
        itemsToRemove.add(name);
      } else // intact Item
      {
        availabilityMap.set(oldId); // occupy id
      }

      // handle blocking the id from future use if possible (i.e. not used by a conflicting block)
      // blockThisId requests don't modify availabilityMap, it could only be set by a block (or
      // another item, which isn't being handled)
      if (blockThisId && !availabilityMap.get(oldId)) {
        // there's no block occupying this id, thus block the id from future use
        // as there may still be ItemStacks in the world referencing it
        newBlockedIds.add(oldId);
        availabilityMap.set(oldId);
      }
    }

    if (itemsToRemove.isEmpty() && itemsToRelocate.isEmpty()) return; // nothing to do

    // confirm
    String text =
        "Forge Mod Loader detected that this save is damaged.\n\n"
            + "It's likely that an automatic repair can successfully restore\n"
            + "most of it, except some items which may get swapped with others.\n\n"
            + "A world backup will be created as a zip file in your saves\n"
            + "directory automatically.\n\n"
            + itemsToRemove.size()
            + " items need to be removed.\n"
            + itemsToRelocate.size()
            + " items need to be relocated.";

    boolean confirmed = StartupQuery.confirm(text);
    if (!confirmed) StartupQuery.abort();

    // confirm missing mods causing item removal
    Set<String> modsMissing = new HashSet<String>();

    for (String name : itemsToRemove) {
      modsMissing.add(name.substring(0, name.indexOf(':')));
    }

    for (Iterator<String> it = modsMissing.iterator(); it.hasNext(); ) {
      String mod = it.next();

      if (mod.equals("minecraft") || Loader.isModLoaded(mod)) it.remove();
    }

    if (!modsMissing.isEmpty()) {
      text =
          "Forge Mod Loader detected that "
              + modsMissing.size()
              + " mods are missing.\n\n"
              + "If you continue items previously provided by those mods will be\n"
              + "removed while repairing this world save.\n\n"
              + "Missing mods:\n";

      for (String mod : modsMissing) text += mod + "\n";

      confirmed = StartupQuery.confirm(text);
      if (!confirmed) StartupQuery.abort();
    }

    // backup
    try {
      String skip = System.getProperty("fml.doNotBackup");
      if (skip == null || !"true".equals(skip)) {
        ZipperUtil.backupWorld();
      } else {
        for (int x = 0; x < 10; x++)
          FMLLog.severe("!!!!!!!!!! UPDATING WORLD WITHOUT DOING BACKUP !!!!!!!!!!!!!!!!");
      }
    } catch (IOException e) {
      StartupQuery.notify("The world backup couldn't be created.\n\n" + e);
      StartupQuery.abort();
    }

    // apply fix
    for (String name : itemsToRemove) {
      FMLLog.warning("Removed Item %s, old id %d.", name, items.ids.remove(name));
    }

    for (Map.Entry<String, Integer> entry : itemsToRelocate.entrySet()) {
      int newId = entry.getValue();
      int oldId = items.ids.put(entry.getKey(), newId);
      FMLLog.warning("Remapped Item %s to id %d, old id %d.", entry.getKey(), newId, oldId);
    }

    blockedIds.addAll(newBlockedIds);
  }