Skip to content

Commit

Permalink
missing texture system
Browse files Browse the repository at this point in the history
  • Loading branch information
UselessBullets committed Jan 8, 2024
1 parent 4ea5506 commit 0b2ce51
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 19 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ bta_version=7.1-pre1a
loader_version=0.14.19-babric.3-bta

# Mod
mod_version=3.1.0
mod_version=3.1.1
mod_group=turniplabs
mod_name=halplibe

1 change: 1 addition & 0 deletions src/main/java/turniplabs/halplibe/HalpLibe.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class HalpLibe implements ModInitializer, PreLaunchEntrypoint{
Toml toml = new Toml();
toml.addCategory("Experimental");
toml.addEntry("Experimental.AtlasWidth", "Dynamically resized the Terrain and Item atlases, value must be an integer greater than or equal to 32",32);
toml.addEntry("Experimental.RequireTextures", "Require texture to exist on startup", false);
toml.addCategory("Network");
toml.addEntry("Network.SendModlistPack", "This sends a modlist packet to clients that join the server when enabled, however it may cause issues if the clients do not have halplibe installed", true);

Expand Down
46 changes: 28 additions & 18 deletions src/main/java/turniplabs/halplibe/util/TextureHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
import turniplabs.halplibe.helper.TextureHelper;

import java.awt.image.BufferedImage;
import java.util.Arrays;
import java.util.logging.Logger;

import static turniplabs.halplibe.HalpLibe.CONFIG;
import static turniplabs.halplibe.HalpLibe.LOGGER;

public class TextureHandler extends DynamicTexture {
private final String textureName;
Expand Down Expand Up @@ -33,27 +38,32 @@ public TextureHandler(String textureName, String animationSource, int textureInd
if (mc == null){return;} // Don't process textures when mc is null
BufferedImage image = Textures.readImage(mc.texturePackList.selectedTexturePack.getResourceAsStream(animationSource));
if (image == null) {return;} // Don't process non existent images
this.resolution = image.getWidth();
// Scaling factor from source resolution to destination resolution
this.scale = getScale(textureName, resolution);



if (image == Textures.missingTexture) {
throw new RuntimeException("Animation " + animationSource + " couldn't be found!");
} else if (image.getHeight() % image.getWidth() != 0) {
if (CONFIG.getBoolean("Experimental.RequireTextures")){
throw new RuntimeException("Animation " + animationSource + " couldn't be found!");
}
LOGGER.warn("Animation " + animationSource + " couldn't be found!");
image = Textures.readImage(Textures.class.getResourceAsStream("/assets/halplibe/block/missing.png"));
}
if (image.getHeight() % image.getWidth() != 0) {
throw new RuntimeException("Invalid Height for animation! " + animationSource);
} else {
this.frameCount = image.getHeight() / image.getWidth();
System.out.println(animationSource + " frame Count: " + this.frameCount);
this.frames = new byte[(int) (resolution * resolution * 4 * this.frameCount * scale * scale)];
}
this.resolution = image.getWidth();
// Scaling factor from source resolution to destination resolution
this.scale = getScale(textureName, resolution);
this.frameCount = image.getHeight() / image.getWidth();
if (frameCount < 1){
frameCount = 1;
}
System.out.println(animationSource + " frame Count: " + this.frameCount);
this.frames = new byte[(int) (resolution * resolution * 4 * this.frameCount * scale * scale)];

for (int frame = 0; frame < this.frameCount; ++frame) {
for (int x = 0; x < resolution * scale; ++x) {
for (int y = 0; y < resolution * scale; ++y) {
int c = image.getRGB((int) (x/scale), (frame * resolution + (int)(y/scale)));
putPixel(this.frames, (int) (frame * resolution * scale * scale * resolution + y * resolution * scale + x), c);
}
for (int frame = 0; frame < this.frameCount; ++frame) {
for (int x = 0; x < resolution * scale; ++x) {
for (int y = 0; y < resolution * scale; ++y) {
int c = image.getRGB((int) (x/scale), (frame * resolution + (int)(y/scale)));
putPixel(this.frames, (int) (frame * resolution * scale * scale * resolution + y * resolution * scale + x), c);
}
}
}
Expand All @@ -65,14 +75,14 @@ public TextureHandler newHandler(Minecraft mc){
}
public void update() {
if (!hasInitialized) {return;}

this.elapsedTicks = (this.elapsedTicks + 1) % this.frameCount;

for (int i = 0; i < this.resolution * scale; ++i) {
for (int j = 0; j < this.resolution * scale; ++j) {
transferPixel(this.frames, (int) (this.elapsedTicks * this.resolution * this.resolution * scale * scale + j * this.resolution * scale + i), this.imageData, (int) (j * this.resolution * scale + i));
}
}

}
public String getTextureName() {
return this.textureName;
Expand Down
Binary file added src/main/resources/assets/halplibe/block/missing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0b2ce51

Please sign in to comment.