Skip to content

Commit

Permalink
Update to 1.21.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Kenny-Hui committed Dec 21, 2024
1 parent f573385 commit 7746b7e
Show file tree
Hide file tree
Showing 13 changed files with 96 additions and 94 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on: [pull_request, push, workflow_dispatch]

jobs:
build:
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
steps:
- name: Checkout Repository
uses: actions/checkout@v4
Expand Down
12 changes: 6 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ org.gradle.parallel=true

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.21.3
yarn_mappings=1.21.3+build.2
loader_version=0.16.7
minecraft_version=1.21.4
yarn_mappings=1.21.4+build.2
loader_version=0.16.9

# Dependencies
mod_menu_version = 12.0.0-beta.1
mod_menu_version = 13.0.0-beta.1

# Mod Properties
mod_version = 1.2.0
mod_version = 1.2.1
maven_group = com.lx862
archives_base_name = splashfox

# Fabric API
fabric_version=0.107.0+1.21.3
fabric_version=0.112.2+1.21.4
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/lx862/splashfox/SplashFox.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import org.slf4j.LoggerFactory;

public class SplashFox implements ClientModInitializer {
public static final Logger LOGGER = LoggerFactory.getLogger("SplashFox");
public static Config config;
public static final Logger LOGGER = LoggerFactory.getLogger("splashfox");

@Override
public void onInitializeClient() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.minecraft.client.resource.metadata.TextureResourceMetadata;
import net.minecraft.client.texture.NativeImage;
import net.minecraft.client.texture.ResourceTexture;
import net.minecraft.client.texture.TextureContents;
import net.minecraft.resource.ResourceManager;
import net.minecraft.util.Identifier;

Expand All @@ -14,22 +15,25 @@ public BuiltinResourceTexture(Identifier location) {
super(location);
}

protected TextureData loadTextureData(ResourceManager resourceManager) {
@Override
public TextureContents loadContents(ResourceManager resourceManager) {
final Identifier textureId = getId();

try {
InputStream input = Thread.currentThread().getContextClassLoader().getResourceAsStream("assets/" + location.getNamespace() + "/" + location.getPath());
TextureData texture = null;
InputStream input = Thread.currentThread().getContextClassLoader().getResourceAsStream("assets/" + textureId.getNamespace() + "/" + textureId.getPath());
TextureContents texture = null;

if(input != null) {
try {
texture = new TextureData(new TextureResourceMetadata(true, true), NativeImage.read(input));
texture = new TextureContents(NativeImage.read(input), new TextureResourceMetadata(true, true));
} finally {
input.close();
}
}

return texture;
} catch (IOException exception) {
return new TextureData(exception);
return TextureContents.createMissing();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.minecraft.client.resource.metadata.TextureResourceMetadata;
import net.minecraft.client.texture.NativeImage;
import net.minecraft.client.texture.ResourceTexture;
import net.minecraft.client.texture.TextureContents;
import net.minecraft.resource.ResourceManager;
import net.minecraft.util.Identifier;

Expand All @@ -19,11 +20,12 @@ public CustomResourceTexture(String relativePath, Identifier location) {
this.relativePath = relativePath;
}

protected TextureData loadTextureData(ResourceManager resourceManager) {
@Override
public TextureContents loadContents(ResourceManager resourceManager) {
try(InputStream input = Files.newInputStream(Config.CUSTOM_IMG_PATH.resolve(relativePath))) {
return new TextureData(new TextureResourceMetadata(true, true), NativeImage.read(input));
return new TextureContents(NativeImage.read(input), new TextureResourceMetadata(true, true));
} catch (IOException exception) {
return new TextureData(exception);
return TextureContents.createMissing();
}
}
}
15 changes: 9 additions & 6 deletions src/main/java/com/lx862/splashfox/data/ImagePosition.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package com.lx862.splashfox.data;

public enum ImagePosition {
LEFT_TO_MOJANG(false),
RIGHT_TO_MOJANG(false),
ABOVE_MOJANG(false),
REPLACE_MOJANG(true),
FOLLOW_MOUSE(false);
LEFT_TO_MOJANG(false, true),
RIGHT_TO_MOJANG(false, true),
ABOVE_MOJANG(false, true),
REPLACE_MOJANG(true, true),
FOLLOW_MOUSE(false, true),
GUI_PREVIEW(false, false);

public final boolean mojangLogoHidden;
public final boolean selectable;

ImagePosition(boolean hideMojangLogo) {
ImagePosition(boolean hideMojangLogo, boolean selectable) {
this.mojangLogoHidden = hideMojangLogo;
this.selectable = selectable;
}
}

17 changes: 10 additions & 7 deletions src/main/java/com/lx862/splashfox/mixin/SplashOverlayMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.SplashOverlay;
import net.minecraft.client.texture.TextureManager;
import net.minecraft.util.Identifier;
import net.minecraft.util.Util;
import net.minecraft.util.math.MathHelper;
Expand All @@ -22,25 +23,25 @@
@Mixin(SplashOverlay.class)
public class SplashOverlayMixin {
@Unique private static final Identifier EMPTY_LOGO = Identifier.of("splashfox", "textures/empty.png");
@Shadow private long reloadCompleteTime;
@Shadow private long reloadStartTime;
@Shadow @Final private boolean reloading;
@Shadow @Final private MinecraftClient client;
@Shadow @Final public static Identifier LOGO;
@Shadow private long reloadCompleteTime;
@Shadow private long reloadStartTime;
@Unique private double elapsed;
@Unique private FoxRenderer renderer;

@Inject(at = @At("HEAD"), method = "init", cancellable = true)
private static void init(MinecraftClient client, CallbackInfo ci) {
private static void init(TextureManager textureManager, CallbackInfo ci) {
Identifier imageId = SplashFox.config.getImageIdentifier();
if(SplashFox.config.usesCustomImage()) {
client.getTextureManager().registerTexture(imageId, new CustomResourceTexture(SplashFox.config.customPath, imageId));
textureManager.registerTexture(imageId, new CustomResourceTexture(SplashFox.config.customPath, imageId));
} else {
client.getTextureManager().registerTexture(imageId, new BuiltinResourceTexture(imageId));
textureManager.registerTexture(imageId, new BuiltinResourceTexture(imageId));
}

if(SplashFox.config.position.mojangLogoHidden) {
client.getTextureManager().registerTexture(LOGO, new BuiltinResourceTexture(EMPTY_LOGO));
textureManager.registerTexture(LOGO, new BuiltinResourceTexture(EMPTY_LOGO));
ci.cancel();
}
}
Expand All @@ -55,13 +56,15 @@ private void render(DrawContext context, int mouseX, int mouseY, float delta, Ca
}

// The init method is only called once on startup, call init again if any settings is mismatched
@Unique
private void ensureTextureRegistered() {
if(Config.needUpdateTexture) {
SplashOverlay.init(client);
SplashOverlay.init(this.client.getTextureManager());
Config.needUpdateTexture = false;
}
}

@Unique
private float getOverlayAlpha() {
long l = Util.getMeasuringTimeMs();
float f = this.reloadCompleteTime > -1L ? (float)(l - this.reloadCompleteTime) / 1000.0F : -1.0F;
Expand Down
79 changes: 37 additions & 42 deletions src/main/java/com/lx862/splashfox/render/FoxRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

import com.lx862.splashfox.config.Config;
import com.lx862.splashfox.data.ImagePosition;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.RenderPhase;
import net.minecraft.client.render.VertexFormat;
import net.minecraft.client.render.VertexFormats;
import net.minecraft.client.util.math.MatrixStack;
Expand All @@ -22,10 +20,11 @@ public class FoxRenderer {
public static final Function<Identifier, RenderLayer> SplashFoxRenderLayer = Util.memoize((texture) -> RenderLayer.of("splashfox_gui_textured", VertexFormats.POSITION_TEXTURE_COLOR, VertexFormat.DrawMode.QUADS, 786432, RenderLayer.MultiPhaseParameters.builder().texture(new Texture(texture, TriState.FALSE, false)).program(POSITION_TEXTURE_COLOR_PROGRAM).transparency(TRANSLUCENT_TRANSPARENCY).depthTest(LEQUAL_DEPTH_TEST).cull(DISABLE_CULLING).build(false)));
private double shiftY = 0;
private double animationProgress = 0;

public void render(MinecraftClient client, DrawContext drawContext, ImagePosition imagePosition, Config config, int mouseX, int mouseY, double elapsed, float alpha) {
MatrixStack matrices = drawContext.getMatrices();
double d = Math.min((double)client.getWindow().getScaledWidth() * 0.75, client.getWindow().getScaledHeight()) * 0.25;
int splashScreenScale = (int)(d * 0.5);
double scaleBasis = Math.min((double)client.getWindow().getScaledWidth() * 0.75, client.getWindow().getScaledHeight()) * 0.25;
int splashScreenScale = (int)(scaleBasis * 0.5);

double size = config.foxSize * splashScreenScale;
double dropHeight = config.dropHeight * splashScreenScale;
Expand All @@ -34,40 +33,40 @@ public void render(MinecraftClient client, DrawContext drawContext, ImagePositio
boolean flipped = config.flipped;
Identifier foxImage = config.getImageIdentifier();

double centeredScreenWidth = (client.getWindow().getScaledWidth() / 2.0) - (size / 2);
double centeredScreenHeight = (client.getWindow().getScaledHeight() / 2.0) - dropHeight;
double x = centeredScreenWidth;
double y = shiftY;

if(imagePosition == ImagePosition.LEFT_TO_MOJANG) {
x = centeredScreenWidth - (6 * splashScreenScale);
y = centeredScreenHeight + shiftY;
}

if(imagePosition == ImagePosition.RIGHT_TO_MOJANG) {
x = centeredScreenWidth + (6 * splashScreenScale);
y = centeredScreenHeight + shiftY;
}

if(imagePosition == ImagePosition.ABOVE_MOJANG) {
x = centeredScreenWidth;
y = centeredScreenHeight - (splashScreenScale) - size + shiftY;
}

if(imagePosition == ImagePosition.REPLACE_MOJANG) {
x = centeredScreenWidth;
y = centeredScreenHeight + shiftY;
}

if(imagePosition == ImagePosition.FOLLOW_MOUSE) {
x = mouseX;
y = mouseY + shiftY;
}

// Preview mode
if(imagePosition == null) {
x = client.getWindow().getScaledHeight() > 450 ? centeredScreenWidth : (flipped ? 0 : client.getWindow().getScaledWidth() - size);
y = centeredScreenHeight + shiftY;
final double centeredScreenWidth = (client.getWindow().getScaledWidth() / 2.0) - (size / 2);
final double centeredScreenHeight = (client.getWindow().getScaledHeight() / 2.0) - dropHeight;
final double x;
final double y;

switch(imagePosition) {
case LEFT_TO_MOJANG -> {
x = centeredScreenWidth - (6 * splashScreenScale);
y = centeredScreenHeight + shiftY;
}
case RIGHT_TO_MOJANG -> {
x = centeredScreenWidth + (6 * splashScreenScale);
y = centeredScreenHeight + shiftY;
}
case ABOVE_MOJANG -> {
x = centeredScreenWidth;
y = centeredScreenHeight - (splashScreenScale) - size + shiftY;
}
case REPLACE_MOJANG -> {
x = centeredScreenWidth;
y = centeredScreenHeight + shiftY;
}
case FOLLOW_MOUSE -> {
x = mouseX;
y = mouseY + shiftY;
}
case GUI_PREVIEW -> {
x = client.getWindow().getScaledHeight() > 450 ? centeredScreenWidth : (flipped ? 0 : client.getWindow().getScaledWidth() - size);
y = centeredScreenHeight + shiftY;
}
default -> {
x = centeredScreenWidth;
y = shiftY;
}
}

matrices.push();
Expand All @@ -86,11 +85,7 @@ public void render(MinecraftClient client, DrawContext drawContext, ImagePositio
matrices.translate(-(size / 2.0), -size, 0);
}

RenderSystem.enableBlend();
RenderSystem.disableCull();
drawContext.drawTexture(SplashFoxRenderLayer, foxImage, 0, 0, 0, 0, (int)size, (int)size, (int)size, (int)size, 0xFFFFFF | ((int)(alpha * 255)) << 24);
RenderSystem.disableBlend();
RenderSystem.enableCull();
matrices.pop();

animationProgress = getBounceProgress(speedFactor, elapsed / 10, wobbly);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ protected void init() {
doneButton.setX((client.getWindow().getScaledWidth() / 2) - (doneButton.getWidth() / 2));
doneButton.setY(client.getWindow().getScaledHeight() - 30);

int fw = (int)(client.getWindow().getScaledWidth() * CHOOSER_WIDTH_FACTOR);
int startX = (client.getWindow().getScaledWidth() - fw) / 2;
int availWidth = (int)(client.getWindow().getScaledWidth() * CHOOSER_WIDTH_FACTOR);
int startX = (client.getWindow().getScaledWidth() - availWidth) / 2;
chooseImageWidget.setX(startX);
chooseImageWidget.setY(30);
chooseImageWidget.setWidth(fw);
chooseImageWidget.setWidth(availWidth);
chooseImageWidget.setHeight(client.getWindow().getScaledHeight() - 70);
chooseImageWidget.init();
addDrawableChild(doneButton);
Expand Down
12 changes: 4 additions & 8 deletions src/main/java/com/lx862/splashfox/screen/ChooseImageWidget.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public ChooseImageWidget(Consumer<ButtonWidget> addSelectableChild, String initi
}

public void init() {
List<ChooseButton> builtInImages = new ArrayList<>();
List<ChooseButton> customImages = new ArrayList<>();
final List<ChooseButton> builtInImages = new ArrayList<>();
final List<ChooseButton> customImages = new ArrayList<>();

try {
Path builtInPath = Path.of(SplashFox.class.getResource("/assets/splashfox/textures/gui/").toURI());
Expand Down Expand Up @@ -139,13 +139,9 @@ protected void renderWidget(DrawContext context, int mouseX, int mouseY, float d
context.enableScissor(getX(), getY(), getX() + getWidth(), getY() + getHeight());

for(ButtonWidget button : subWidgets) {
final boolean buttonInVisibleArea = mouseY >= 30 && mouseY <= MinecraftClient.getInstance().getWindow().getScaledHeight() - 40;
button.render(context, mouseX, mouseY, delta);

if(mouseY >= 30 && mouseY <= MinecraftClient.getInstance().getWindow().getScaledHeight() - 40) {
button.active = true;
} else {
button.active = false;
}
button.active = buttonInVisibleArea;
}

context.getMatrices().push();
Expand Down
Loading

0 comments on commit 7746b7e

Please sign in to comment.