Skip to content

Commit

Permalink
Commented And Cleaned Up Code
Browse files Browse the repository at this point in the history
  • Loading branch information
UselessBullets committed Sep 27, 2023
1 parent 2559132 commit 43bbb7d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
7 changes: 5 additions & 2 deletions src/main/java/turniplabs/halplibe/helper/TextureHelper.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package turniplabs.halplibe.helper;

import net.minecraft.core.Global;
import net.minecraft.core.block.Block;
import turniplabs.halplibe.util.TextureHandler;

Expand All @@ -16,10 +17,12 @@ public class TextureHelper {
public static Map<String, Integer> textureAtlasWidths = new HashMap<>();

static {
// Assign Default Resolutions
textureDestinationResolutions.put("/terrain.png", 16);
textureDestinationResolutions.put("/gui/items.png", 16);
textureAtlasWidths.put("/terrain.png", 32);
textureAtlasWidths.put("/gui/items.png", 32);
// Assign Default Atlas Widths
textureAtlasWidths.put("/terrain.png", Global.TEXTURE_ATLAS_WIDTH_TILES);
textureAtlasWidths.put("/gui/items.png", Global.TEXTURE_ATLAS_WIDTH_TILES);
}

@Deprecated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public abstract class RenderEngineMixin {
private void initDynamicTextures(CallbackInfo ci) {
Minecraft mc = Minecraft.getMinecraft(Minecraft.class);
for (String key: TextureHelper.textureDestinationResolutions.keySet()) {
// Updates atlas resolution references
GL11.glBindTexture(3553, thisAsRenderEngine.getTexture(key));
int destinationResolution = GL11.glGetTexLevelParameteri(3553, 0, 4096) / TextureHelper.textureAtlasWidths.get(key);
TextureHelper.textureDestinationResolutions.put(key, destinationResolution);
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/turniplabs/halplibe/util/TextureHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public class TextureHandler extends DynamicTexture {
private final byte[] frames;
private int elapsedTicks = 0;
private static final Minecraft fakeMc;
// End Resolution/source Resolutions
private final float scale;

public TextureHandler(String textureName, String animationSource, int textureIndex, int resolution, int width) {
Expand All @@ -35,7 +34,8 @@ public TextureHandler(String textureName, String animationSource, int textureInd
this.defaultResolution = defaultResolution;
BufferedImage image = Textures.readImage(mc.texturePackList.selectedTexturePack.getResourceAsStream(animationSource));
this.resolution = image.getWidth();
this.scale = getScale(mc, textureName, resolution);
// Scaling factor from source resolution to destination resolution
this.scale = getScale(textureName, resolution);
this.width = width;


Expand Down Expand Up @@ -75,17 +75,17 @@ public void update() {
public String getTextureName() {
return this.textureName;
}
public static float getScale(Minecraft mc, String textureName, int resolution){
public static float getScale(String textureName, int resolution){
if (TextureHelper.textureDestinationResolutions.get(textureName) != null){
return (float)TextureHelper.textureDestinationResolutions.get(textureName)/resolution;
}
return 1f;
}
public static int getAtlasResolution(String textureName, int resolution){
public static int getAtlasResolution(String textureName, int defaultResolution){
if (TextureHelper.textureDestinationResolutions.get(textureName) != null){
return TextureHelper.textureDestinationResolutions.get(textureName);
}
return resolution;
return defaultResolution;
}

static {
Expand Down

0 comments on commit 43bbb7d

Please sign in to comment.