-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed packicon.png. Also made it auto-scale, so source image size sho…
…uld no longer matter. Does not work on mac tho
- Loading branch information
1 parent
21ab56e
commit 6f2d3de
Showing
5 changed files
with
80 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
common/src/main/java/dev/latvian/mods/kubejs/core/WindowKJS.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package dev.latvian.mods.kubejs.core; | ||
|
||
import dev.latvian.mods.kubejs.KubeJS; | ||
import dev.latvian.mods.kubejs.KubeJSPaths; | ||
import dev.latvian.mods.kubejs.script.data.GeneratedData; | ||
import dev.latvian.mods.kubejs.util.Lazy; | ||
import net.minecraft.server.packs.resources.IoSupplier; | ||
|
||
import javax.imageio.ImageIO; | ||
import java.awt.RenderingHints; | ||
import java.awt.image.BufferedImage; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.nio.file.Files; | ||
import java.util.List; | ||
import java.util.function.Supplier; | ||
|
||
public interface WindowKJS { | ||
record KJSScaledIconProvider(BufferedImage original, int target) implements Supplier<byte[]> { | ||
@Override | ||
public byte[] get() { | ||
try { | ||
var out = new ByteArrayOutputStream(); | ||
|
||
if (original.getWidth() == target && original.getHeight() == target) { | ||
ImageIO.write(original, "png", out); | ||
} else { | ||
var img = new BufferedImage(target, target, BufferedImage.TYPE_INT_ARGB); | ||
var g = img.createGraphics(); | ||
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); | ||
g.drawImage(original, 0, 0, target, target, null); | ||
g.dispose(); | ||
ImageIO.write(img, "png", out); | ||
} | ||
|
||
return out.toByteArray(); | ||
} catch (Exception ex) { | ||
throw new IllegalStateException(original.toString(), ex); | ||
} | ||
} | ||
} | ||
|
||
default List<IoSupplier<InputStream>> kjs$loadIcons(List<IoSupplier<InputStream>> original) throws IOException { | ||
if (Files.exists(KubeJSPaths.PACKICON)) { | ||
System.out.println("Hello"); | ||
|
||
try (var in = Files.newInputStream(KubeJSPaths.PACKICON)) { | ||
var img = ImageIO.read(in); | ||
|
||
return List.of( | ||
new GeneratedData(KubeJS.id("icon_16x.png"), Lazy.of(new KJSScaledIconProvider(img, 16)), true), | ||
new GeneratedData(KubeJS.id("icon_32x.png"), Lazy.of(new KJSScaledIconProvider(img, 32)), true), | ||
new GeneratedData(KubeJS.id("icon_48x.png"), Lazy.of(new KJSScaledIconProvider(img, 48)), true), | ||
new GeneratedData(KubeJS.id("icon_128.png"), Lazy.of(new KJSScaledIconProvider(img, 128)), true), | ||
new GeneratedData(KubeJS.id("icon_256x.png"), Lazy.of(new KJSScaledIconProvider(img, 256)), true) | ||
); | ||
} | ||
} | ||
|
||
return original; | ||
} | ||
} |
22 changes: 14 additions & 8 deletions
22
common/src/main/java/dev/latvian/mods/kubejs/core/mixin/common/WindowMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,22 @@ | ||
package dev.latvian.mods.kubejs.core.mixin.common; | ||
|
||
import com.llamalad7.mixinextras.injector.ModifyExpressionValue; | ||
import com.mojang.blaze3d.platform.IconSet; | ||
import com.mojang.blaze3d.platform.Window; | ||
import dev.latvian.mods.kubejs.core.WindowKJS; | ||
import net.minecraft.server.packs.PackResources; | ||
import net.minecraft.server.packs.resources.IoSupplier; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.List; | ||
|
||
@Mixin(Window.class) | ||
public class WindowMixin { | ||
/* | ||
@Inject(method = "setIcon", at = @At("HEAD"), cancellable = true) | ||
private void setWindowIcon(InputStream icon16, InputStream icon32, CallbackInfo ci) { | ||
if (ClientProperties.get().cancelIconUpdate()) { | ||
ci.cancel(); | ||
} | ||
public class WindowMixin implements WindowKJS { | ||
@ModifyExpressionValue(method = "setIcon", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/platform/IconSet;getStandardIcons(Lnet/minecraft/server/packs/PackResources;)Ljava/util/List;")) | ||
private List<IoSupplier<InputStream>> kjs$icons(List<IoSupplier<InputStream>> original, PackResources packResources, IconSet set) throws IOException { | ||
return kjs$loadIcons(original); | ||
} | ||
*/ | ||
} |