Skip to content

Commit

Permalink
Merge pull request #32 from UselessBullets/TextureHandler-Crash-Fix
Browse files Browse the repository at this point in the history
Texture handler crash fix
  • Loading branch information
MartinSVK12 authored Nov 6, 2023
2 parents d9196b9 + 1356a3e commit d773894
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/main/java/turniplabs/halplibe/util/TextureHandler.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package turniplabs.halplibe.util;

import net.minecraft.client.Minecraft;
import net.minecraft.client.option.GameSettings;
import net.minecraft.client.render.dynamictexture.DynamicTexture;
import net.minecraft.client.render.texturepack.TexturePackList;
import net.minecraft.core.util.helper.Textures;
import turniplabs.halplibe.helper.TextureHelper;

import java.awt.image.BufferedImage;
import java.io.File;

public class TextureHandler extends DynamicTexture {
private final String textureName;
Expand All @@ -21,6 +18,7 @@ public class TextureHandler extends DynamicTexture {
private byte[] frames;
private int elapsedTicks = 0;
private float scale;
private boolean hasInitialized = false;

public TextureHandler(String textureName, String animationSource, int textureIndex, int resolution, int width) {
this(textureName, animationSource, textureIndex, resolution, width, null);
Expand All @@ -47,7 +45,7 @@ public TextureHandler(String textureName, String animationSource, int textureInd
throw new RuntimeException("Invalid Height for animation! " + animationSource);
} else {
this.frameCount = image.getHeight() / image.getWidth();
System.out.println("Frame Count: " + this.frameCount);
System.out.println(textureName + " frame Count: " + this.frameCount);
this.frames = new byte[(int) (resolution * resolution * 4 * this.frameCount * scale * scale)];

for (int frame = 0; frame < this.frameCount; ++frame) {
Expand All @@ -59,12 +57,14 @@ public TextureHandler(String textureName, String animationSource, int textureInd
}
}
}
hasInitialized = true;
}
public TextureHandler newHandler(Minecraft mc){
// Returns a new TextureHandler using the current state of Minecraft, If the texturepack has changed it will then use the new texturepack's textures
return new TextureHandler(textureName, animationSource, textureIndex, defaultResolution, width, mc);
}
public void update() {
if (!hasInitialized) {return;}
this.elapsedTicks = (this.elapsedTicks + 1) % this.frameCount;

for (int i = 0; i < this.resolution * scale; ++i) {
Expand Down

0 comments on commit d773894

Please sign in to comment.