use of net.minecraft.resources.IResource in project ChocolateQuestRepoured by TeamChocoQuest.
the class InvisibilityTexture method load.
@Override
public void load(IResourceManager resourceManager) throws IOException {
this.releaseId();
try (IResource iresource = resourceManager.getResource(this.originalTextureLocation)) {
NativeImage bufferedimage = NativeImage.read(TextureUtil.readResource(iresource.getInputStream()));
// CQR Start
PERLIN.setup(RANDOM.nextLong(), 4.0F);
for (int x = 0; x < bufferedimage.getWidth(); x++) {
for (int y = 0; y < bufferedimage.getHeight(); y++) {
int argb = bufferedimage.getPixelRGBA(x, y);
if ((argb >>> 24) <= 2) {
continue;
}
float f = PERLIN.getNoiseAt(x, y);
bufferedimage.setPixelRGBA(x, y, ((int) (f * 255.0F) << 24) | (argb & 0x00FFFFFF));
}
}
// CQR End
boolean flag = false;
boolean flag1 = false;
// if (iresource.hasMetadata()) {
try {
TextureMetadataSection texturemetadatasection = iresource.getMetadata(TextureMetadataSection.SERIALIZER);
if (texturemetadatasection != null) {
flag = texturemetadatasection.isBlur();
flag1 = texturemetadatasection.isClamp();
}
} catch (RuntimeException runtimeexception) {
LOGGER.warn("Failed reading metadata of: {}", this.originalTextureLocation, runtimeexception);
}
// }
TextureUtil.uploadTextureImageAllocate(this.getId(), bufferedimage, flag, flag1);
}
}
use of net.minecraft.resources.IResource in project ChocolateQuestRepoured by TeamChocoQuest.
the class ResourceSupplier method get.
@Override
public String get() {
StringBuilder sb = new StringBuilder();
try (IResource resource = Minecraft.getInstance().getResourceManager().getResource(this.file)) {
try (Stream<String> stream = new BufferedReader(new InputStreamReader(resource.getInputStream())).lines()) {
stream.forEach(s -> {
sb.append(s);
sb.append('\n');
});
}
} catch (IOException e) {
e.printStackTrace();
}
return sb.toString();
}
use of net.minecraft.resources.IResource in project ChocolateQuestRepoured by TeamChocoQuest.
the class CubemapTexture method load.
private void load(IResourceManager resourceManager, ResourceLocation location, int target) throws IOException {
try (IResource iresource = resourceManager.getResource(location)) {
NativeImage bufferedimage = NativeImage.read(TextureUtil.readResource(iresource.getInputStream()));
int w = bufferedimage.getWidth();
int h = bufferedimage.getHeight();
IntBuffer data = ByteBuffer.allocateDirect(w * h * 4).order(ByteOrder.nativeOrder()).asIntBuffer();
data.put(bufferedimage.getRGB(0, 0, w, h, new int[w * h], 0, w));
data.flip();
GL11.glTexImage2D(target, 0, GL11.GL_RGBA8, w, h, 0, GL12.GL_BGRA, GL11.GL_UNSIGNED_BYTE, data);
}
}
use of net.minecraft.resources.IResource in project MCMOD-Industria by M-Marvin.
the class JigsawFileManager method loadTemplate.
private static Template loadTemplate(ServerWorld world, ResourceLocation location) {
IResourceManager resourceManager = getResourceManager(world);
ResourceLocation resourcePath = new ResourceLocation(location.getNamespace(), "structures/" + location.getPath() + ".nbt");
try (IResource resource = resourceManager.getResource(resourcePath)) {
InputStream inputStream = resource.getInputStream();
CompoundNBT fileNBT = CompressedStreamTools.readCompressed(inputStream);
Template template = new Template();
template.load(fileNBT);
return template;
} catch (FileNotFoundException e) {
return null;
} catch (Throwable throwable) {
Industria.LOGGER.error("Couldn't load Structure {}: {}", location, throwable);
return null;
}
}
use of net.minecraft.resources.IResource in project MCMOD-Industria by M-Marvin.
the class AnimatedTexture method load.
public void load(IResourceManager manager) throws IOException {
SimpleTexture.TextureData simpletexture$texturedata = this.getTextureImage(manager);
simpletexture$texturedata.throwIfError();
TextureMetadataSection texturemetadatasection = simpletexture$texturedata.getTextureMetadata();
boolean flag;
boolean flag1;
if (texturemetadatasection != null) {
flag = texturemetadatasection.isBlur();
flag1 = texturemetadatasection.isClamp();
} else {
flag = false;
flag1 = false;
}
NativeImage nativeimage = simpletexture$texturedata.getImage();
if (!RenderSystem.isOnRenderThreadOrInit()) {
RenderSystem.recordRenderCall(() -> {
this.loadImage(nativeimage, flag, flag1);
});
} else {
this.loadImage(nativeimage, flag, flag1);
}
this.size = simpletexture$texturedata.getImage().getWidth();
this.textureHeight = simpletexture$texturedata.getImage().getHeight();
ResourceLocation metadataFile = new ResourceLocation(this.location.getNamespace(), this.location.getPath() + ".mcmeta");
try {
IResource metadataResource = manager.getResource(metadataFile);
InputStreamReader inputStreamReader = new InputStreamReader(metadataResource.getInputStream());
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
StringBuffer stringBuffer = new StringBuffer();
String string;
while ((string = bufferedReader.readLine()) != null) {
stringBuffer.append(string);
}
CompoundNBT metadataNBT = JsonToNBT.parseTag(stringBuffer.toString());
CompoundNBT animation = metadataNBT.getCompound("animation");
this.frameTime = animation.getInt("frametime");
if (animation.contains("frames")) {
ListNBT arr = animation.getList("frames", 3);
frames = new int[arr.size()];
for (int i = 0; i < arr.size(); i++) {
this.frames[i] = arr.getInt(i);
}
} else {
int height = simpletexture$texturedata.getImage().getHeight();
int frameCount = height / size;
frames = new int[frameCount];
for (int i = 0; i < frameCount; i++) {
this.frames[i] = i;
}
}
} catch (CommandSyntaxException | FileNotFoundException e) {
this.frames = new int[] { 0 };
this.frameTime = 1;
}
}
Aggregations