Skip to content

Commit

Permalink
Merge pull request #10 from legoraft/dev
Browse files Browse the repository at this point in the history
Quick and dirty update to 1.21
  • Loading branch information
legoraft authored Aug 4, 2024
2 parents a34dd70 + af07b2b commit 051e8a5
Show file tree
Hide file tree
Showing 16 changed files with 201 additions and 143 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
matrix:
# Use these Java versions
java: [
17, # Current Java LTS & minimum supported by Minecraft
21, # Current Java LTS & minimum supported by Minecraft
]
# and run on both Linux and Windows
os: [ubuntu-22.04, windows-2022]
Expand All @@ -33,7 +33,7 @@ jobs:
- name: build
run: ./gradlew build
- name: capture build artifacts
if: ${{ runner.os == 'Linux' && matrix.java == '17' }} # Only upload artifacts built from latest java on one OS
if: ${{ runner.os == 'Linux' && matrix.java == '21' }} # Only upload artifacts built from latest java on one OS
uses: actions/upload-artifact@v3
with:
name: survivaltweaks-mod
Expand Down
15 changes: 8 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '1.2-SNAPSHOT'
id 'fabric-loom' version '1.6-SNAPSHOT'
id 'maven-publish'
}

Expand All @@ -11,8 +11,6 @@ base {
}

repositories {
maven { url = "https://jitpack.io" }
maven { url = "https://maven.gegy.dev" }
maven { url = "https://maven.terraformersmc.com/" }
}

Expand All @@ -28,6 +26,12 @@ loom {

}

configurations.configureEach {
resolutionStrategy {
force("net.fabricmc:fabric-loader:$loader_version")
}
}

dependencies {
// To change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
Expand All @@ -37,9 +41,6 @@ dependencies {
// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

include(implementation(annotationProcessor "com.github.llamalad7.mixinextras:mixinextras-fabric:${project.mixin_extras_version}"))
include modImplementation("dev.lambdaurora:spruceui:${project.spruceui_version}")

modApi "com.terraformersmc:modmenu:${project.modmenu_version}"

// Uncomment the following line to enable the deprecated Fabric API modules.
Expand Down Expand Up @@ -70,7 +71,7 @@ java {

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

Expand Down
14 changes: 6 additions & 8 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@ org.gradle.parallel=true

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.20.2
yarn_mappings=1.20.2+build.4
loader_version=0.14.23
minecraft_version=1.21
yarn_mappings=1.21+build.2
loader_version=0.15.11

# Mod Properties
mod_version=1.1.0
mod_version=1.1.1
maven_group=com.survivaltweaks
archives_base_name=simple-survival-tweaks

# Dependencies
fabric_version=0.90.0+1.20.2
mixin_extras_version=0.2.0
spruceui_version=5.0.3+1.20.2
modmenu_version=8.0.0
fabric_version=0.100.3+1.21
modmenu_version=11.0.1
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.1.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Empty file modified gradlew
100644 → 100755
Empty file.
91 changes: 55 additions & 36 deletions src/client/java/com/survivaltweaks/configScreen.java
Original file line number Diff line number Diff line change
@@ -1,74 +1,93 @@
package com.survivaltweaks;

import dev.lambdaurora.spruceui.Position;
import dev.lambdaurora.spruceui.option.SpruceBooleanOption;
import dev.lambdaurora.spruceui.option.SpruceOption;
import dev.lambdaurora.spruceui.screen.SpruceScreen;
import dev.lambdaurora.spruceui.widget.SpruceButtonWidget;
import dev.lambdaurora.spruceui.widget.container.SpruceOptionListWidget;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.option.GameOptionsScreen;
import net.minecraft.client.gui.screen.option.OptionsScreen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.gui.widget.CyclingButtonWidget;
import net.minecraft.client.gui.widget.OptionListWidget;
import net.minecraft.text.Text;
import org.jetbrains.annotations.Nullable;

import java.util.Properties;

public class configScreen extends SpruceScreen {
public class configScreen extends GameOptionsScreen {

private final Screen parent;
public Screen parent;

private final SpruceOption survivalDebugStickToggle;
private final SpruceOption endermanGriefToggle;
private final SpruceOption noExpensiveToggle;
private final SpruceOption cheapRenameToggle;
private final SpruceOption noXpPenaltyToggle;
public configScreen(Screen parent) {
super(parent, null, Text.translatable("config.title"));

public configScreen(@Nullable Screen parent) {
super(Text.translatable("title.config"));
this.parent = parent;
}

this.survivalDebugStickToggle = new SpruceBooleanOption("config.survivaldebugstick", () -> config.SURVIVAL_DEBUG_STICK, newValue -> config.SURVIVAL_DEBUG_STICK = newValue, Text.translatable("config.description.survivaldebugstick"));
this.endermanGriefToggle = new SpruceBooleanOption("config.noendermangrief", () -> config.NO_ENDERMAN_GRIEF, newValue -> config.NO_ENDERMAN_GRIEF = newValue, Text.translatable("config.description.noendermagrief"));
this.noExpensiveToggle = new SpruceBooleanOption("config.notooexpensive", () -> config.NO_EXPENSIVE, newValue -> config.NO_EXPENSIVE = newValue, Text.translatable("config.description.notooexpensive"));
this.cheapRenameToggle = new SpruceBooleanOption("config.cheaprename", () -> config.CHEAP_RENAME, newValue -> config.CHEAP_RENAME = newValue, Text.translatable("config.description.cheaprename"));
this.noXpPenaltyToggle = new SpruceBooleanOption("config.noxppenalty", () -> config.NO_XP_PENALTY, newValue -> config.NO_XP_PENALTY = newValue, Text.translatable("config.description.noxppenalty"));
public CyclingButtonWidget survivalDebugStickToggle;
public CyclingButtonWidget endermanGriefToggle;
public CyclingButtonWidget noExpensiveToggle;
public CyclingButtonWidget cheapRenameToggle;
public CyclingButtonWidget noXpPenaltyToggle;
public CyclingButtonWidget phantomMobCap;

}
public ButtonWidget doneButton;

@Override
protected void init() {
super.init();
survivalDebugStickToggle = CyclingButtonWidget.onOffBuilder(config.SURVIVAL_DEBUG_STICK)
.build(Text.translatable("config.survivaldebugstick"), ((button, value) -> config.SURVIVAL_DEBUG_STICK = !config.SURVIVAL_DEBUG_STICK));

endermanGriefToggle = CyclingButtonWidget.onOffBuilder(config.NO_ENDERMAN_GRIEF)
.build(Text.translatable("config.noendermangrief"), (button, value) -> config.NO_ENDERMAN_GRIEF = !config.NO_ENDERMAN_GRIEF);

noExpensiveToggle = CyclingButtonWidget.onOffBuilder(config.NO_EXPENSIVE)
.build(Text.translatable("config.notooexpensive"), (button, value) -> config.NO_EXPENSIVE = !config.NO_EXPENSIVE);

cheapRenameToggle = CyclingButtonWidget.onOffBuilder(config.CHEAP_RENAME)
.build(Text.translatable("config.cheaprename"), (button, value) -> config.CHEAP_RENAME = !config.CHEAP_RENAME);

SpruceOptionListWidget list = new SpruceOptionListWidget(Position.of(0, 34), this.width, this.height - 69);
list.addOptionEntry(this.survivalDebugStickToggle, this.endermanGriefToggle);
list.addOptionEntry(this.noExpensiveToggle, this.cheapRenameToggle);
list.addOptionEntry(this.noXpPenaltyToggle, null);
noXpPenaltyToggle = CyclingButtonWidget.onOffBuilder(config.NO_XP_PENALTY)
.build(Text.translatable("config.noxppenalty"), ((button, value) -> config.NO_XP_PENALTY = !config.NO_XP_PENALTY));

this.addDrawableChild(list);
phantomMobCap = CyclingButtonWidget.onOffBuilder(config.PHANTOM_MOBCAP)
.build(Text.translatable("config.noxppenalty"), ((button, value) -> config.PHANTOM_MOBCAP = !config.PHANTOM_MOBCAP));

this.addDrawableChild(new SpruceButtonWidget(Position.of(this.width / 2 - 100, this.height - 30), 200, 20, Text.translatable("config.done"), button -> this.applyChanges()));
OptionListWidget optionListWidget = this.addDrawableChild(new OptionListWidget(this.client, this.width, this));

optionListWidget.addWidgetEntry(survivalDebugStickToggle, endermanGriefToggle);
optionListWidget.addWidgetEntry(noExpensiveToggle, cheapRenameToggle);
optionListWidget.addWidgetEntry(noXpPenaltyToggle, phantomMobCap);

doneButton = ButtonWidget
.builder(Text.translatable("config.done"), button -> close())
.dimensions(width / 2 - 100, height - 25, 200, 20)
.build();

addDrawableChild(doneButton);
}

@Override
public void renderTitle(DrawContext context, int MouseX, int MouseY, float delta) {
context.drawCenteredTextWithShadow(this.textRenderer, this.title, this.width / 2, 8, 16777215);
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
super.render(context, mouseX, mouseY, delta);
context.drawCenteredTextWithShadow(textRenderer, super.title, width / 2, 12, 0xffffff);
}

@Override
public void renderBackground(DrawContext context, int mouseX, int mouseY, float delta) {
this.renderBackgroundTexture(context);
protected void addOptions() {
super.init();
}

@Override
public void close() {
this.client.setScreen(parent);
assert this.client != null;

applyChanges();
this.client.setScreen(this.parent);
}

public void applyChanges() {
config config = survivalTweaks.CONFIG;
Properties properties = new Properties();
config.write(properties);
config.save();
this.client.setScreen(parent);
config.save(survivalTweaks.CONFIG_PATH);
}

}
12 changes: 11 additions & 1 deletion src/main/java/com/survivaltweaks/commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,24 @@ public static void register(CommandDispatcher<ServerCommandSource> dispatcher, C
})
)
)
.then(CommandManager.literal("phantomMobcap").executes(c -> { c.getSource().sendMessage(Text.translatable("commands.tweak.query", "phantomMobcap", config.PHANTOM_MOBCAP)); return 1;})
.then(CommandManager.argument("boolean", bool())
.executes(c -> {
config.PHANTOM_MOBCAP = getBool(c, "boolean");
applyChanges();
c.getSource().sendMessage(Text.translatable("commands.tweak.set", "phantomMobcap", config.PHANTOM_MOBCAP));
return 1;
})
)
)
);
}

public static void applyChanges() {
config config = survivalTweaks.CONFIG;
java.util.Properties properties = new java.util.Properties();
config.write(properties);
config.save();
config.save(survivalTweaks.CONFIG_PATH);
}

}
23 changes: 12 additions & 11 deletions src/main/java/com/survivaltweaks/config.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ public class config {
public static boolean CHEAP_RENAME = false;
public static boolean NO_ENDERMAN_GRIEF = false;
public static boolean NO_XP_PENALTY = false;

private static final Path CONFIG_PATH = FabricLoader.getInstance().getConfigDir().resolve("survivaltweaks.properties");
public static boolean PHANTOM_MOBCAP = false;

public void write(Properties properties) {
properties.setProperty("survival_debug_stick", Boolean.toString(SURVIVAL_DEBUG_STICK));
properties.setProperty("no_too_expensive", Boolean.toString(NO_EXPENSIVE));
properties.setProperty("cheap_rename", Boolean.toString(CHEAP_RENAME));
properties.setProperty("no_enderman_grief", Boolean.toString(NO_ENDERMAN_GRIEF));
properties.setProperty("no_xp_penalty", Boolean.toString(NO_XP_PENALTY));
properties.setProperty("phantom_mobcap", Boolean.toString(PHANTOM_MOBCAP));
}

public void read(Properties properties) {
Expand All @@ -32,40 +32,41 @@ public void read(Properties properties) {
CHEAP_RENAME = Boolean.parseBoolean(properties.getProperty("cheap_rename"));
NO_ENDERMAN_GRIEF = Boolean.parseBoolean(properties.getProperty("no_enderman_grief"));
NO_XP_PENALTY = Boolean.parseBoolean(properties.getProperty("no_xp_penalty"));
PHANTOM_MOBCAP = Boolean.parseBoolean(properties.getProperty("phantom_mobcap"));
}

public void save() {
public void save(Path configPath) {
Properties properties = new Properties();
write(properties);
if (!Files.exists(CONFIG_PATH)) {
if (!Files.exists(configPath)) {
try {
Files.createFile(CONFIG_PATH);
Files.createFile(configPath);
} catch (IOException e) {
LogManager.getLogger("Simple Survival Tweaks").error("Failed to create config file");
e.printStackTrace();
}
}
try {
properties.store(Files.newOutputStream(CONFIG_PATH), "Simple Survival Tweaks config file");
properties.store(Files.newOutputStream(configPath), "Simple Survival Tweaks config file");
} catch (IOException e) {
LogManager.getLogger("Simple Survival Tweaks").error("Failed to write config");
e.printStackTrace();
}
}

public void load() {
public void load(Path configPath) {
Properties properties = new Properties();
if (!Files.exists(CONFIG_PATH)) {
if (!Files.exists(configPath)) {
try {
Files.createFile(CONFIG_PATH);
save();
Files.createFile(configPath);
save(configPath);
} catch (IOException e) {
LogManager.getLogger("Simple Survival Tweaks").error("Failed to create config file");
e.printStackTrace();
}
}
try {
properties.load(Files.newInputStream(CONFIG_PATH));
properties.load(Files.newInputStream(configPath));
} catch (IOException e) {
LogManager.getLogger("Simple Survival Tweaks").error("Failed to read config");
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.survivaltweaks.mixin;

import com.survivaltweaks.config;
import net.minecraft.screen.AnvilScreenHandler;
import net.minecraft.screen.Property;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.*;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(AnvilScreenHandler.class)
public class anvilScreenHandlerMixin {

@Shadow @Final private Property levelCost;

@Inject(method = "updateResult", at = @At("TAIL"))
private void setLevelCost(CallbackInfo ci) {
int cost = levelCost.get();

if (cost > 5 && config.NO_EXPENSIVE) {
levelCost.set(5);
}
}
}
27 changes: 0 additions & 27 deletions src/main/java/com/survivaltweaks/mixin/anvilScreenMixin.java

This file was deleted.

Loading

0 comments on commit 051e8a5

Please sign in to comment.