Ejemplo n.º 1
0
 private File getRealPathBecauseMojangLiterallyCantEvenCodeOutsideTheirUsageScenario(
     ResourceLocation l) {
   String altPath = l.getResourcePath();
   altPath = altPath.substring(7); // omit the leading "sounds/"
   // System.out.println("Final path: "+new
   // File(mc_dir.getAbsolutePath(),altPath).getAbsolutePath());
   return new File(mc_dir.getAbsolutePath(), altPath);
 }
Ejemplo n.º 2
0
 public static InputStream getResourceStream(ResourceLocation res) {
   try {
     String domain = res.getResourceDomain(), path = res.getResourcePath();
     return RegistryUtils.class.getResourceAsStream("/assets/" + domain + "/" + path);
   } catch (Exception e) {
     e.printStackTrace();
     return null;
   }
 }
Ejemplo n.º 3
0
 private InputStream getResourceStream(ResourceLocation resourceLocation) {
   // TODO Check this
   return addon
       .getClass()
       .getResourceAsStream(
           String.format(
               "/assets/%s/%s",
               addon.getDescription().getIdentifier(), resourceLocation.getResourcePath()));
 }
Ejemplo n.º 4
0
 public static void registerTransparentBlock(Block block, float transparency, int meta) {
   if (block != null) {
     NBTTagCompound tag = new NBTTagCompound();
     ResourceLocation b1 = block.delegate.name();
     tag.setString("blockName", b1.getResourcePath());
     tag.setString("modid", b1.getResourceDomain());
     tag.setFloat("t", transparency);
     tag.setInteger("m", meta);
     TomsModRecipeHelper.sendMessage(tag, "glass", 2);
   }
 }
Ejemplo n.º 5
0
  public InputStream getInputStream(ResourceLocation p_110590_1_) throws IOException {
    InputStream inputstream = this.getResourceStream(p_110590_1_);

    if (inputstream != null) {
      return inputstream;
    } else {
      InputStream inputstream1 = this.func_152780_c(p_110590_1_);

      if (inputstream1 != null) {
        return inputstream1;
      } else {
        throw new FileNotFoundException(p_110590_1_.getResourcePath());
      }
    }
  }
Ejemplo n.º 6
0
 public boolean resourceExists(ResourceLocation l) {
   return isResourceFromThisPack(l)
       && (l.getResourcePath().equals("sounds.json")
           || getRealPathBecauseMojangLiterallyCantEvenCodeOutsideTheirUsageScenario(l).exists());
 }
Ejemplo n.º 7
0
 public InputStream getInputStream(ResourceLocation l) throws IOException {
   if (l.getResourcePath().equals("sounds.json")) return generateSoundsJSON();
   return new FileInputStream(
       getRealPathBecauseMojangLiterallyCantEvenCodeOutsideTheirUsageScenario(l));
 }
Ejemplo n.º 8
0
 private static ResourceLocation completeResourceLocation(
     ResourceLocation location, String basePath) {
   return new ResourceLocation(
       location.getResourceDomain(),
       String.format("%s/%s%s", basePath, location.getResourcePath(), ".png"));
 }
Ejemplo n.º 9
0
 @Override
 protected ResourceLocation getModelLocation(ResourceLocation model) {
   return new ResourceLocation(model.getResourceDomain(), model.getResourcePath() + ".json");
 }
Ejemplo n.º 10
0
 private InputStream getResourceStream(ResourceLocation p_110605_1_) {
   return DefaultResourcePack.class.getResourceAsStream(
       "/assets/" + p_110605_1_.getResourceDomain() + "/" + p_110605_1_.getResourcePath());
 }
Ejemplo n.º 11
0
 public boolean accepts(ResourceLocation modelLocation) {
   return modelLocation.getResourceDomain().equals("forge")
       && (modelLocation.getResourcePath().equals("fluid")
           || modelLocation.getResourcePath().equals("models/block/fluid")
           || modelLocation.getResourcePath().equals("models/item/fluid"));
 }
Ejemplo n.º 12
0
  /**
   * Imports resources using the metadata from a resource pack.
   *
   * @param manager - the resource manager to use
   * @param data - the metadata that contains the resource names
   */
  private void importResources(IResourceManager manager, ModbuilderResource data) {
    ResourceDeserializer deserializer = new ResourceDeserializer();
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(BaseItemResource.class, deserializer);
    builder.registerTypeAdapter(BaseBlockResource.class, deserializer);
    builder.registerTypeAdapter(BaseStructureResource.class, deserializer);
    builder.registerTypeAdapter(BaseRecipe.class, deserializer);
    Gson gson = builder.create();

    Map<String, BaseBlockResource> blockResources = new HashMap<String, BaseBlockResource>();
    Map<String, BaseItemResource> itemResources = new HashMap<String, BaseItemResource>();
    for (String path : data.blocks) {
      try {
        ResourceLocation location =
            new ResourceLocation(BuilderMod.MODID + ":blocks/" + path + ".json");
        IResource resource = manager.getResource(location);
        BaseBlockResource blockResource =
            gson.fromJson(
                new InputStreamReader(resource.getInputStream()), BaseBlockResource.class);
        Block block = ResourceConverter.toEmptyBlock(blockResource);
        block.setUnlocalizedName(BuilderMod.MODID + "_" + path);
        if (!registeredBlocks.contains(path)) {
          registeredBlocks.add(path);
          blockModels.put(block, blockResource.model);
          customBlocks.put(path, block);
          blockResources.put(path, blockResource);
        }
      } catch (IOException e) {
        // ignore
      }
    }

    for (String path : data.items) {
      try {
        ResourceLocation location =
            new ResourceLocation(BuilderMod.MODID + ":items/" + path + ".json");
        IResource resource = manager.getResource(location);
        BaseItemResource itemResource =
            gson.fromJson(new InputStreamReader(resource.getInputStream()), BaseItemResource.class);
        Item item = ResourceConverter.toEmptyItem(itemResource);
        item.setUnlocalizedName(BuilderMod.MODID + "_" + path);
        if (!registeredItems.contains(path)) {
          registeredItems.add(path);
          itemModels.put(item, itemResource.model);
          customItems.put(path, item);
          itemResources.put(path, itemResource);
        }
      } catch (IOException e) {
        // ignore
      }
    }

    for (String path : blockResources.keySet()) {
      BaseBlockResource resource = blockResources.get(path);
      Block block = ResourceConverter.toBlock(customBlocks.get(path), resource);
      GameRegistry.registerBlock(block, path);
      if (resource.burntime != null) fuels.put(Item.getItemFromBlock(block), resource.burntime);
    }

    for (String path : itemResources.keySet()) {
      BaseItemResource resource = itemResources.get(path);
      Item item = ResourceConverter.toItem(customItems.get(path), resource);
      GameRegistry.registerItem(item, path);
      if (resource.burntime != null) fuels.put(item, resource.burntime);
    }

    for (String path : data.structures) {
      try {
        ResourceLocation location =
            new ResourceLocation(BuilderMod.MODID + ":structures/" + path + ".json");
        IResource resource = manager.getResource(location);
        BaseStructureResource structureResource =
            gson.fromJson(
                new InputStreamReader(resource.getInputStream()), BaseStructureResource.class);
        BuilderStruct structure = ResourceConverter.toStructure(structureResource);
        if (!registeredStructures.contains(path)) {
          registeredStructures.add(path);
          registry.structs.add(structure);
        }
      } catch (IOException e) {
        // ignore
      }
    }

    for (String path : data.recipes) {
      try {
        ResourceLocation location =
            new ResourceLocation(BuilderMod.MODID + ":recipes/" + path + ".json");
        String s = location.getResourcePath();
        IResource resource = manager.getResource(location);
        BaseRecipe recipe =
            gson.fromJson(new InputStreamReader(resource.getInputStream()), BaseRecipe.class);
        RecipeRegistry.register(recipe);
      } catch (IOException e) {
        // ignore
      }
    }
  }
Ejemplo n.º 13
0
 @Override
 public String getId() {
   ResourceLocation res = Block.blockRegistry.getNameForObject(block);
   return res.getResourceDomain() + ":" + res.getResourcePath();
 }