use of net.minecraft.resources.IResource in project Mekanism by mekanism.
the class GuiElementHolder method updateBackgroundColor.
public static void updateBackgroundColor() {
// get it from the texture
try {
IResource resource = Minecraft.getInstance().getResourceManager().getResource(HOLDER);
BufferedImage img = ImageIO.read(resource.getInputStream());
int rgb = img.getRGB(HOLDER_SIZE + 1, HOLDER_SIZE + 1);
if (rgb >> 24 == 0) {
// Don't allow fully transparent colors, fallback to default color.
// Mark as null for now so that it can default to the proper color
rgb = 0xFF787878;
Mekanism.logger.warn("Unable to retrieve background color for element holder.");
}
BACKGROUND_COLOR = rgb;
} catch (Exception e) {
Mekanism.logger.error("Failed to retrieve background color for element holder", e);
}
}
use of net.minecraft.resources.IResource in project Mekanism by mekanism.
the class ColorAtlas method loadColorAtlas.
private static void loadColorAtlas(ResourceLocation rl, int count, List<Color> ret) throws IOException {
IResource resource = Minecraft.getInstance().getResourceManager().getResource(rl);
BufferedImage img = ImageIO.read(resource.getInputStream());
for (int i = 0; i < count; i++) {
int rgb = img.getRGB(i % ATLAS_SIZE, i / ATLAS_SIZE);
if (rgb >> 24 == 0) {
// Don't allow fully transparent colors, fallback to default color.
// Mark as null for now so that it can default to the proper color
ret.add(null);
Mekanism.logger.warn("Unable to retrieve color marker: '{}' for atlas: '{}'. This is likely due to an out of date resource pack.", count, rl);
} else {
ret.add(Color.argb(rgb));
}
}
}
use of net.minecraft.resources.IResource in project MCMOD-Industria by M-Marvin.
the class JigsawFileManager method loadListNBT.
@SuppressWarnings("deprecation")
private static ListNBT loadListNBT(ServerWorld world, ResourceLocation location) {
IResourceManager resourceManager = getResourceManager(world);
ResourceLocation resourcePath = new ResourceLocation(location.getNamespace(), "structures/" + location.getPath() + ".mcmeta");
try (IResource resource = resourceManager.getResource(resourcePath)) {
InputStream inputStream = resource.getInputStream();
String jsonString = IOUtils.toString(inputStream);
CompoundNBT fileNBT = new JsonToNBT(new StringReader(jsonString)).readStruct();
ListNBT list = fileNBT.getList("structures", 10);
return list;
} catch (FileNotFoundException e) {
return null;
} catch (Throwable throwable) {
Industria.LOGGER.error("Couldn't load Jigsaw-Structure-List {}: {}", location, throwable.toString());
throwable.printStackTrace();
return null;
}
}
use of net.minecraft.resources.IResource in project ChocolateQuestRepoured by TeamChocoQuest.
the class AutoGlowingTexture method load.
@Override
public void load(IResourceManager resourceManager) throws IOException {
this.releaseId();
try (IResource iresource = resourceManager.getResource(this.originalTexture)) {
// Needed to get the GL-texture id
Texture ito = Minecraft.getInstance().textureManager.getTexture(iresource.getLocation());
NativeImage bufferedimage = NativeImage.read(TextureUtil.readResource(iresource.getInputStream()));
NativeImage glowingBI = new NativeImage(bufferedimage.getWidth(), bufferedimage.getHeight(), false);
boolean flag = false;
boolean flag1 = false;
// if (iresource.hasMetadata()) {
try {
// DONE: Fix this for the CTS!! Cts for whatever reason tries to load png as mcmeta file...
TextureMetadataSection texturemetadatasection = iresource.getMetadata(new TextureMetadataSectionSerializer());
if (texturemetadatasection != null) {
flag = texturemetadatasection.isBlur();
flag1 = texturemetadatasection.isClamp();
}
GlowingMetadataSection glowInformation = iresource.getMetadata(new GlowingMetadataSectionSerializer());
if (glowInformation != null) {
for (Tuple<Tuple<Integer, Integer>, Tuple<Integer, Integer>> area : glowInformation.getGlowingSections()) {
for (int ix = area.getA().getA(); ix < area.getB().getA(); ix++) {
for (int iy = area.getA().getB(); iy < area.getB().getB(); iy++) {
glowingBI.setPixelRGBA(ix, iy, bufferedimage.getPixelRGBA(ix, iy));
// Remove it from the original
bufferedimage.setPixelRGBA(ix, iy, 0);
}
}
}
}
/*
* String name = this.texture.getPath().replace("/", "-");
* File outputFile = new File(CQRMain.CQ_CONFIG_FOLDER, name);
* ImageIO.write(glowingBI, "png", outputFile);
*/
} catch (RuntimeException runtimeexception) {
LOGGER.warn("Failed reading metadata of: {}", this.originalTexture, runtimeexception);
}
// }
TextureUtil.uploadTextureImageAllocate(this.getId(), glowingBI, flag, flag1);
// Also upload the changes to the original texture...
TextureUtil.uploadTextureImage(ito.getId(), bufferedimage);
}
}
use of net.minecraft.resources.IResource in project minecolonies by ldtteam.
the class DatagenLootTableManager method get.
@NotNull
@Override
public LootTable get(@NotNull final ResourceLocation location) {
final LootTable table = this.tables.get(location);
if (table != null)
return table;
try {
final IResource resource = existingFileHelper.getResource(getPreparedPath(location), ResourcePackType.SERVER_DATA);
try (final InputStream inputstream = resource.getInputStream();
final Reader reader = new BufferedReader(new InputStreamReader(inputstream, StandardCharsets.UTF_8))) {
final JsonObject jsonobject = JSONUtils.fromJson(GSON, reader, JsonObject.class);
final LootTable loottable = ForgeHooks.loadLootTable(GSON, location, jsonobject, false, this);
if (loottable != null) {
this.tables.put(location, loottable);
return loottable;
}
}
} catch (final Throwable e) {
e.printStackTrace();
}
return LootTable.EMPTY;
}
Aggregations