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

Add Minecraft 1.17.0 support #4

Merged
merged 1 commit into from
Jul 18, 2024
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
19 changes: 19 additions & 0 deletions build-logic/src/main/kotlin/kit_tunes.java.16.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
plugins {
id("java")
}

java {
withSourcesJar()

toolchain {
languageVersion = JavaLanguageVersion.of(16)
}
}

tasks.withType<JavaCompile> {
options.encoding = "UTF-8"

javaCompiler = javaToolchains.compilerFor {
languageVersion = JavaLanguageVersion.of(16)
}
}
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ quilt_loader = "0.26.0"

qsl = "8.0.0-alpha.11+1.20.4"

annotations = "24.1.0"
gson = "2.11.0"
annotations = "13.0"
gson = "2.8.0"
slf4j = "2.0.13"

[libraries]
Expand Down
6 changes: 4 additions & 2 deletions kit-tunes/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ dependencies {
include(project(":kit-tunes-api"))
include(project(":kitten-heart"))

include(project(":kitten-star:r1.20.4"))
include(project(":kitten-star:r1.17.0"))
include(project(":kitten-star:r1.20.4"))

include(project(":kitten-square:r1.20.4"))
include(project(":kitten-square:r1.17.0"))
include(project(":kitten-square:r1.20.4"))
include(project(":kitten-square:r1.21.0"))
}

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"gui": {
"scaling": {
"type": "nine_slice",
"width": 200,
"height": 20,
"border": 3
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"gui": {
"scaling": {
"type": "nine_slice",
"width": 200,
"height": 20,
"border": 1
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"gui": {
"scaling": {
"type": "nine_slice",
"width": 200,
"height": 20,
"border": 3
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ public class RectangularButton implements Button {
public static final Size DEFAULT_SIZE = Size.of(200, 20);

private static final GuiTexture DEFAULT_DISABLED_TEXTURE = GuiTexture
.of(new ResourcePathImpl("minecraft", "textures/gui/sprites/widget/button_disabled.png"), DEFAULT_SIZE);
.of(new ResourcePathImpl("kit_tunes", "textures/gui/sprites/widget/button_disabled.png"), DEFAULT_SIZE);
private static final GuiTexture DEFAULT_UNHIGLIGHTED_TEXTURE = GuiTexture
.of(new ResourcePathImpl("minecraft", "textures/gui/sprites/widget/button.png"), DEFAULT_SIZE);
.of(new ResourcePathImpl("kit_tunes", "textures/gui/sprites/widget/button.png"), DEFAULT_SIZE);
private static final GuiTexture DEFAULT_HIGHLIGHTED_TEXTURE = GuiTexture
.of(new ResourcePathImpl("minecraft", "textures/gui/sprites/widget/button_highlighted.png"), DEFAULT_SIZE);
.of(new ResourcePathImpl("kit_tunes", "textures/gui/sprites/widget/button_highlighted.png"), DEFAULT_SIZE);

private final ButtonBackground background;
private final RectangularSurface surface;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public ScrobblerCache deserialize(JsonElement json, Type _type, JsonDeserializat
throws JsonParseException {
ArrayList<Scrobbler> scrobblers = new ArrayList<>();

for (JsonElement scrobblerData : json.getAsJsonArray().asList()) {
for (JsonElement scrobblerData : json.getAsJsonArray()) {
Pixaurora marked this conversation as resolved.
Show resolved Hide resolved
Scrobbler scrobbler = context.deserialize(scrobblerData, Scrobbler.class);
scrobblers.add(scrobbler);
}
Expand Down
21 changes: 21 additions & 0 deletions kitten-square/r1.17.0/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
plugins {
id("kit_tunes.java.16")
id("kit_tunes.module")
}

repositories {
maven {
name = "Terraformers"
url = uri("https://maven.terraformersmc.com/")
}
}

dependencies {
implementation(project(":kit-tunes-api"))
implementation(project(":kitten-heart"))

modImplementation(libs.qsl.resource.loader)

modImplementation("com.terraformersmc:modmenu:${project.property("modmenu_version")}")
modImplementation(fabricApi.module("fabric-resource-loader-v0", project.property("fabric_api_version").toString()))
}
8 changes: 8 additions & 0 deletions kitten-square/r1.17.0/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Mod properties
sub_mod_name = ui
minecraft_version_min = 1.17.0

minecraft_version = 1.17

modmenu_version=2.0.17
fabric_api_version=0.36.0+1.17
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package net.pixaurora.kitten_square.impl;

import net.minecraft.network.chat.MutableComponent;
import net.pixaurora.kitten_cube.impl.text.Component;
import net.pixaurora.kitten_square.impl.service.UICompatImpl;

public class FakeComponent implements Component {
private final MutableComponent parent;

public FakeComponent(MutableComponent component) {
this.parent = component;
}

public MutableComponent gameVer() {
return this.parent;
}

@Override
public Component concat(Component component) {
return new FakeComponent(this.parent.copy().append(UICompatImpl.internalToMinecraftType(component)));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package net.pixaurora.kitten_square.impl;

import net.minecraft.client.resources.sounds.SimpleSoundInstance;
import net.minecraft.client.resources.sounds.SoundInstance;
import net.minecraft.sounds.SoundEvents;
import net.pixaurora.kitten_cube.impl.ui.sound.Sound;

public class SoundUtil {
public static SoundInstance soundFromInternalID(Sound sound) {
switch (sound) {
case BUTTON_CLICK:
return SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1.0F);
default:
throw new RuntimeException("Sound " + sound.name() + " was not mapped!");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package net.pixaurora.kitten_square.impl.compat;

import java.util.Map;

import com.terraformersmc.modmenu.api.ConfigScreenFactory;
import com.terraformersmc.modmenu.api.ModMenuApi;

import net.minecraft.client.gui.screens.Screen;
import net.pixaurora.kitten_heart.impl.Constants;
import net.pixaurora.kitten_heart.impl.ui.screen.KitTunesHomeScreen;
import net.pixaurora.kitten_square.impl.ui.screen.MinecraftScreen;
import net.pixaurora.kitten_square.impl.ui.screen.ScreenImpl;

public class ModMenuIntegration implements ModMenuApi {
public ScreenImpl modHomeScreen(Screen parent) {
return new ScreenImpl(new KitTunesHomeScreen(new MinecraftScreen(parent)));
}

@Override
public Map<String, ConfigScreenFactory<?>> getProvidedConfigScreenFactories() {
return Map.of(Constants.MOD_ID, this::modHomeScreen);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package net.pixaurora.kitten_square.impl.mixin;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import net.minecraft.client.gui.Gui;
import net.minecraft.network.chat.Component;

@Mixin(Gui.class)
public class GuiMixin {
// Because we want to show our own notification, we cancel this one so it
// doesn't show twice.
@Inject(method = "setNowPlaying", at = @At("HEAD"), cancellable = true)
private void cancelNowPlayingNotification(Component description, CallbackInfo cInfo) {
cInfo.cancel();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
package net.pixaurora.kitten_square.impl.service;

import java.util.List;

import net.minecraft.Util;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screens.ConfirmLinkScreen;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.FormattedCharSequence;
import net.pixaurora.kit_tunes.api.resource.ResourcePath;
import net.pixaurora.kitten_cube.impl.math.Point;
import net.pixaurora.kitten_cube.impl.text.Color;
import net.pixaurora.kitten_cube.impl.text.Component;
import net.pixaurora.kitten_cube.impl.ui.screen.Screen;
import net.pixaurora.kitten_cube.impl.ui.sound.Sound;
import net.pixaurora.kitten_cube.impl.ui.widget.text.TextBox;
import net.pixaurora.kitten_heart.impl.resource.ResourcePathImpl;
import net.pixaurora.kitten_heart.impl.resource.ResourcePathUtils;
import net.pixaurora.kitten_heart.impl.service.MinecraftUICompat;
import net.pixaurora.kitten_square.impl.FakeComponent;
import net.pixaurora.kitten_square.impl.SoundUtil;
import net.pixaurora.kitten_square.impl.ui.screen.MinecraftScreen;
import net.pixaurora.kitten_square.impl.ui.screen.ScreenImpl;
import net.pixaurora.kitten_square.impl.ui.toast.ToastImpl;
import net.pixaurora.kitten_square.impl.ui.widget.TextBoxImpl;

public class UICompatImpl implements MinecraftUICompat {
private final Minecraft client = Minecraft.getInstance();

public static ResourceLocation internalToMinecraftType(ResourcePath path) {
return new ResourceLocation(path.namespace(), path.path());
}

public static MutableComponent internalToMinecraftType(Component component) {
if (component instanceof FakeComponent) {
return ((FakeComponent) component).gameVer();
} else {
throw new RuntimeException(
"Internal component is of an unconvertable type `" + component.getClass().getName() + "`!");
}
}

@Override
public void sendToast(net.pixaurora.kitten_cube.impl.ui.toast.Toast toast) {
this.client.getToasts().addToast(new ToastImpl(toast));
}

@Override
public ResourcePath convertToRegularAsset(ResourcePath path) {
return path;
}

@Override
public ResourcePath convertToGuiAsset(ResourcePath path) {
return path;
}

@Override
public Component translatable(String key) {
return new FakeComponent(new TranslatableComponent(key));
}

@Override
public Component translatableWithFallback(String key, String defaultText) {
return new FakeComponent(new TranslatableComponent(key));
}

@Override
public Component literal(String text) {
return new FakeComponent(new TextComponent(text));
}

@Override
public int textHeight() {
return this.client.font.lineHeight;
}

@Override
public int textWidth(Component text) {
return this.client.font.width(internalToMinecraftType(text));
}

@Override
public void playSound(Sound sound) {
this.client.getSoundManager().play(SoundUtil.soundFromInternalID(sound));
}

@Override
public void setScreen(Screen screen) {
net.minecraft.client.gui.screens.Screen mcScreen;
if (screen instanceof MinecraftScreen) {
mcScreen = ((MinecraftScreen) screen).parent();
} else {
mcScreen = new ScreenImpl(screen);
}
this.client.setScreen(mcScreen);
}

@Override
public void confirmURL(String url) {
confirmLinkNow(this.client.screen, url);
}

private void confirmLinkNow(net.minecraft.client.gui.screens.Screen screen, String url) {
this.client.setScreen(new ConfirmLinkScreen((result) -> {
if (result) {
Util.getPlatform().openUri(url);
}

this.client.setScreen(screen);
}, url, true));
}

@Override
public TextBox createTextbox(List<Component> lines, Color color, int maxLineLength, Point pos) {
List<FormattedCharSequence> text = lines.stream().map(UICompatImpl::internalToMinecraftType)
.flatMap(line -> this.client.font.split(line, maxLineLength).stream()).toList();

return new TextBoxImpl(text, color, pos);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package net.pixaurora.kitten_square.impl.ui;

import net.minecraft.resources.ResourceLocation;
import net.pixaurora.kit_tunes.api.resource.ResourcePath;
import net.pixaurora.kitten_cube.impl.ConversionCache;
import net.pixaurora.kitten_square.impl.service.UICompatImpl;

public class ConversionCacheImpl extends ConversionCache<ResourceLocation, net.minecraft.network.chat.Component> {
@Override
protected ResourceLocation resourceToMinecraftType(ResourcePath path) {
return UICompatImpl.internalToMinecraftType(path);
}

@Override
protected net.minecraft.network.chat.Component componentToMinecraftType(
net.pixaurora.kitten_cube.impl.text.Component component) {
return UICompatImpl.internalToMinecraftType(component);
}

}
Loading