Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Startup Crash On Servers #15

Merged
merged 1 commit into from
Sep 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions src/main/java/turniplabs/halplibe/helper/TextureHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
import net.minecraft.core.block.Block;
import turniplabs.halplibe.util.TextureHandler;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;

public class TextureHelper {
public static List<TextureHandler> textureHandlers = new ArrayList<>();
Expand Down
24 changes: 8 additions & 16 deletions src/main/java/turniplabs/halplibe/util/TextureHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,32 @@

public class TextureHandler extends DynamicTexture {
private final String textureName;
private final int frameCount;
private int frameCount;
private final String animationSource;
private final int textureIndex;
private final int resolution;
private int resolution;
private final int defaultResolution;
private final int width;
private final byte[] frames;
private byte[] frames;
private int elapsedTicks = 0;
private static final Minecraft fakeMc;
private final float scale;
private float scale;

public TextureHandler(String textureName, String animationSource, int textureIndex, int resolution, int width) {
this(textureName, animationSource, textureIndex, resolution, width, fakeMc);
this(textureName, animationSource, textureIndex, resolution, width, null);
}
public TextureHandler(String textureName, String animationSource, int textureIndex, int defaultResolution, int width, Minecraft mc) {
super(textureIndex, getAtlasResolution(textureName, defaultResolution), width);
this.textureName = textureName;
this.animationSource = animationSource;
this.textureIndex = textureIndex;
this.defaultResolution = defaultResolution;
this.width = width;
if (mc == null){return;} // Don't process textures when mc is null
BufferedImage image = Textures.readImage(mc.texturePackList.selectedTexturePack.getResourceAsStream(animationSource));
this.resolution = image.getWidth();
// Scaling factor from source resolution to destination resolution
this.scale = getScale(textureName, resolution);
this.width = width;



if (image == Textures.missingTexture) {
Expand Down Expand Up @@ -87,13 +88,4 @@ public static int getAtlasResolution(String textureName, int defaultResolution){
}
return defaultResolution;
}

static {
// Create a Minecraft Container with the needed information to load the texture-pack
Minecraft mc = Minecraft.getMinecraft(Minecraft.class);
File mcdir = mc.getMinecraftDir();
mc.gameSettings = new GameSettings(mc, mcdir);
mc.texturePackList = new TexturePackList(mc, mcdir);
fakeMc = mc;
}
}
Loading