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

[WIP] feat(deps): Support 1.19.3 #27

Closed
wants to merge 5 commits into from
Closed
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
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

*A Fabric mod for choosing between sets of Fabric mods.*

This branch (`master`) is the active development branch for latest Minecraft (currently 1.17.1).
This branch (`master`) is the active development branch for latest Minecraft (currently 1.19.3).

## What is this

Expand Down Expand Up @@ -69,5 +69,4 @@ NOTE: ThatOrThis is only **intended for small, client-side mods**. It may cause
[moddirector]: https://www.curseforge.com/minecraft/mc-mods/moddirector
[fabric-language-kotlin]: https://www.curseforge.com/minecraft/mc-mods/fabric-language-kotlin
[fabric-language-scala]: https://www.curseforge.com/minecraft/mc-mods/fabric-language-scala
[fabric-language-groovy]: https://www.curseforge.com/minecraft/mc-mods/fabric-language-groovy

[fabric-language-groovy]: https://www.curseforge.com/minecraft/mc-mods/fabric-language-groovy
33 changes: 14 additions & 19 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
plugins {
id 'fabric-loom' version '0.9-SNAPSHOT'
id 'fabric-loom' version '0.12-SNAPSHOT'
id 'maven-publish'
}

sourceCompatibility = JavaVersion.VERSION_16
targetCompatibility = JavaVersion.VERSION_16
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17

archivesBaseName = project.archives_base_name
version = project.mod_version
group = project.maven_group

loom {
mods {
thatorthis {
sourceSet sourceSets.main
}
}
}

repositories {
// Add repositories to retrieve artifacts from in here.
// You should only use this when depending on other mods because
Expand All @@ -33,7 +41,6 @@ dependencies {
// You may need to force-disable transitiveness on them.

modImplementation "com.terraformersmc:modmenu:${project.modmenu_version}"
implementation "com.google.code.gson:gson:${project.gson_version}"
}

processResources {
Expand All @@ -51,8 +58,8 @@ tasks.withType(JavaCompile).configureEach {
// If Javadoc is generated, this must be specified in that task too.
it.options.encoding = "UTF-8"

// Minecraft 1.17 (21w19a) upwards uses Java 16.
it.options.release = 16
// Minecraft 1.18 upwards uses Java 17.
it.options.release = 17
}

java {
Expand All @@ -62,23 +69,11 @@ java {
withSourcesJar()
}

jar {
from("LICENSE") {
rename { "${it}_${project.archivesBaseName}"}
}
}

// configure the maven publication
publishing {
publications {
mavenJava(MavenPublication) {
// add all the jars that should be included when publishing to maven
artifact(remapJar) {
builtBy remapJar
}
artifact(sourcesJar) {
builtBy remapSourcesJar
}
from components.java
}
}

Expand Down
13 changes: 6 additions & 7 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://fabricmc.net/versions.html
minecraft_version=1.17.1
yarn_mappings=1.17.1+build.63
loader_version=0.12.3
minecraft_version=1.19.3
yarn_mappings=1.19.3+build.5
loader_version=0.14.19

# Mod Properties
mod_version = 0.2.6+1.17
mod_version = 0.2.6+1.19
maven_group = io.github.ezforever
archives_base_name = thatorthis

# Dependencies
#fabric_version=0.41.0+1.17
modmenu_version=2.0.14
gson_version=2.8.0
#fabric_version=0.87.1+1.19.3
modmenu_version=5.0.2
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package io.github.ezforever.thatorthis.config;

import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import io.github.ezforever.thatorthis.internal.BidirectionalMap;

import java.lang.reflect.Type;

Expand All @@ -20,10 +19,10 @@ public class EnumClassTypeAdapter<T>

// ---

private final BiMap<String, Class<? extends T>> nameClassMap;
private final BidirectionalMap<String, Class<? extends T>> nameClassMap;

public <U extends Enum<U> & EnumClassType<T>> EnumClassTypeAdapter(Class<U> classOfU) {
this.nameClassMap = HashBiMap.create();
this.nameClassMap = new BidirectionalMap<>();
for(U value : classOfU.getEnumConstants())
this.nameClassMap.put(value.name(), value.getClazz());
}
Expand Down
24 changes: 12 additions & 12 deletions src/main/java/io/github/ezforever/thatorthis/gui/ChoiceScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.gui.widget.LockButtonWidget;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.LiteralText;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.text.TranslatableTextContent;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand Down Expand Up @@ -79,7 +78,6 @@ public static Screen create(Screen parent) {
private RuleButtonListWidget ruleButtons;
private ButtonWidget discardOrDefaultButton;
private LockButtonWidget disableButton;
private ButtonWidget doneButton;
private boolean dirty = false;

public ChoiceScreen(Screen parent,
Expand Down Expand Up @@ -117,16 +115,15 @@ protected void init() {
ruleButtons.setChoices(shownChoices);
addDrawableChild(ruleButtons);

discardOrDefaultButton = new ButtonWidget(
width / 2 - 155, height - 27, 150 - 20, 20,
LiteralText.EMPTY,
(ButtonWidget button) -> {
discardOrDefaultButton = ButtonWidget.builder(Text.empty(), (ButtonWidget button) -> {
shownChoices = (dirty ? initialChoices.choices : ruleHolder.getDefaultChoices()).copy();
ruleButtons.setChoices(shownChoices);
disableButton.setLocked(dirty && ruleHolder.canDisable() && initialChoices.disabled != null && initialChoices.disabled);
setDirty(!dirty);
}
);
})
.position(width / 2 - 155, height - 27)
.size(150 - 20, 20)
.build();
setDirty(dirty); // Reset button caption
addDrawableChild(discardOrDefaultButton);

Expand All @@ -141,7 +138,7 @@ protected void init() {
) {
@Override // Erase difficulty info in narration message
protected MutableText getNarrationMessage() {
return new TranslatableText("gui.narrate.button", getMessage());
return MutableText.of(new TranslatableTextContent("gui.narrate.button", getMessage()));
}

@Override // Sync "locked"/"disabled" status to the buttons list
Expand All @@ -155,12 +152,15 @@ public void setLocked(boolean locked) {
disableButton.active = ruleHolder.canDisable();
addDrawableChild(disableButton);

doneButton = new ButtonWidget(width / 2 - 155 + 160, height - 27, 150, 20, Texts.DONE.get(), (ButtonWidget button) -> onClose());
ButtonWidget doneButton = ButtonWidget.builder(Texts.DONE.get(), (ButtonWidget button) -> close())
.position(width / 2 - 155 + 160, height - 27)
.size(150, 20)
.build();
addDrawableChild(doneButton);
}

@Override
public void onClose() {
public void close() {
Screen nextScreen;
if(dirty) {
setDirty(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public List<? extends Selectable> selectableChildren() {
@Override
public void render(MatrixStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) {
this.buttons.forEach((button) -> {
button.y = y;
button.setY(y);
button.render(matrices, mouseX, mouseY, tickDelta);
if(hovered && button.isHovered() && !button.isFocused())
RuleButtonListWidget.this.hoveredButton = button;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;

@Environment(EnvType.CLIENT)
Expand All @@ -14,12 +13,12 @@ public class RuleButtonWidget extends ButtonWidget {
private Choice choice;

public RuleButtonWidget(int x, int y, int width, int height, VisibleRule rule, RuleButtonListWidget.UpdateAction updateAction) {
super(x, y, width, height, LiteralText.EMPTY, (ButtonWidget button) -> {
super(x, y, width, height, Text.empty(), (ButtonWidget button) -> {
RuleButtonWidget self = (RuleButtonWidget)button;
SingleThreadFuture<Choice> newChoice = rule.updateChoice(self.choice)
.then(self::setChoice);
updateAction.onUpdate(rule, newChoice);
});
}, null);

this.rule = rule;
rule.initButton(this);
Expand Down
13 changes: 6 additions & 7 deletions src/main/java/io/github/ezforever/thatorthis/gui/Texts.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package io.github.ezforever.thatorthis.gui;

import net.minecraft.text.LiteralText;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;

public enum Texts {
TITLE("thatorthis.choice.title"),
Expand Down Expand Up @@ -41,23 +40,23 @@ public static Text getText(String keyOrLiteral, Object... params) {
isKey = false;
}
return isKey
? new TranslatableText(keyOrLiteral, params)
: new LiteralText(String.format(keyOrLiteral, params));
? Text.translatable(keyOrLiteral, params)
: Text.of(String.format(keyOrLiteral, params));
}

// ---

private final String key;
private TranslatableText text;
private MutableText text;

public Text get() {
if(text == null)
text = new TranslatableText(key);
text = Text.translatable(key);
return text;
}

public Text get(Object... args) {
return new TranslatableText(key, args);
return Text.translatable(key, args);
}

Texts(String key) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package io.github.ezforever.thatorthis.internal;

import java.io.Serial;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;

/**
* <a href="https://stackoverflow.com/a/54871433">https://stackoverflow.com/a/54871433</a> <br>
* Fabric not allow use other packages when loading {@link net.fabricmc.loader.impl.launch.knot.KnotClassDelegate#isValidParentUrl(URL, String)}
*/
@SuppressWarnings("JavadocReference")
public class BidirectionalMap<K, V> extends HashMap<K, V> {
@Serial
private static final long serialVersionUID = 1L;
public HashMap<V, K> inversedMap = new HashMap<>();

public Map<V, K> inverse() {
return Map.copyOf(inversedMap);
}

@Override
public V remove(Object key) {
V val = super.remove(key);
inversedMap.remove(val);
return val;
}

@Override
public V get(Object key) {
return super.get(key);
}

@Override
public V put(K key, V value) {
inversedMap.put(value, key);
return super.put(key, value);
}
}
Loading