Skip to content

Commit

Permalink
Cloth-Gamerules screen integration (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
Estecka authored Feb 27, 2024
1 parent 287c9d3 commit 8333e4a
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 12 deletions.
17 changes: 15 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '1.4-SNAPSHOT'
id 'fabric-loom' version '1.5-SNAPSHOT'
id 'maven-publish'
}

Expand All @@ -16,6 +16,13 @@ repositories {
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
// for more information about repositories.

maven { url "https://maven.shedaniel.me/" }

maven {
name = "Modrinth"
url = "https://api.modrinth.com/maven"
}
}

dependencies {
Expand All @@ -31,6 +38,12 @@ dependencies {
// These are included in the Fabric API production distribution and allow you to update your mod to the latest modules at a later more convenient time.

// modImplementation "net.fabricmc.fabric-api:fabric-api-deprecated:${project.fabric_version}"

modApi("me.shedaniel.cloth:cloth-config-fabric:${project.cloth_version}") {
exclude(group: "net.fabricmc.fabric-api")
}

modCompileOnly "maven.modrinth:cloth-gamerules:${project.clothGamerules_version}"
}

processResources {
Expand Down Expand Up @@ -59,7 +72,7 @@ java {

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

Expand Down
8 changes: 6 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ org.gradle.parallel=true
# check these on https://fabricmc.net/develop
minecraft_version=1.19.4
yarn_mappings=1.19.4+build.2
loader_version=0.15.3
loader_version=0.15.7

#Fabric api
fabric_version=0.87.2+1.19.4

# Mod Properties
mod_version=1.1.0
mod_version=1.2.0
maven_group=tk.estecka.packrulemenus
archives_base_name=packrule-menus

# Optional Dependencies
clothGamerules_version=1.0.0+1.19.4
cloth_version=10.1.117
6 changes: 6 additions & 0 deletions port.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Minecraft Code Breaking Changes
### 1.19.4
Current master

### 1.20.0
- `MatrixStack` parameters are replaced with `DrawContext` in most GUI.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package tk.estecka.packrulemenus.mixin;

import java.util.Collection;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.Supplier;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand All @@ -11,6 +13,7 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import com.llamalad7.mixinextras.sugar.Local;
import it.unimi.dsi.fastutil.booleans.BooleanConsumer;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.gui.screen.MessageScreen;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.TitleScreen;
Expand All @@ -29,18 +32,19 @@
import net.minecraft.util.Identifier;
import net.minecraft.util.WorldSavePath;
import net.minecraft.world.GameRules;
import tk.estecka.clothgamerules.api.ClothGamerulesScreenFactory;
import tk.estecka.packrulemenus.GenericWarningScreen;
import tk.estecka.packrulemenus.PackRuleMenus;

@Unique
@Mixin(OptionsScreen.class)
abstract public class OptionScreenMixin
extends Screen
{
private OptionScreenMixin(){ super(null); throw new AssertionError(); }
private OptionScreenMixin(){ super(null); }

@Shadow abstract ButtonWidget createButton(Text message, Supplier<Screen> screenSupplier);

@Unique
private IntegratedServer server;

@Inject( method="init", at=@At(value="INVOKE", ordinal=1, shift=Shift.AFTER, target="net/minecraft/client/gui/widget/GridWidget$Adder.add (Lnet/minecraft/client/gui/widget/Widget;)Lnet/minecraft/client/gui/widget/Widget;") )
Expand All @@ -54,9 +58,9 @@ abstract public class OptionScreenMixin
final GameRules worldRules = server.getOverworld().getGameRules();
adder.add(createButton(
Text.translatable("selectWorld.gameRules"),
() -> new EditGameRulesScreen(
() -> CreateGameruleScreen(
worldRules.copy(),
optRules -> { RevertScreen(); optRules.ifPresent(r -> worldRules.setAllValues(r, server)); }
optRules -> optRules.ifPresent(r -> worldRules.setAllValues(r, server))
)
));

Expand All @@ -72,13 +76,18 @@ abstract public class OptionScreenMixin
));
}
}

private Screen CreateGameruleScreen(GameRules rules, Consumer<Optional<GameRules>> saveConsumer){
if (FabricLoader.getInstance().isModLoaded("cloth-gamerules"))
return ClothGamerulesScreenFactory.CreateScreen(this, rules, saveConsumer);
else
return new EditGameRulesScreen(rules, saveConsumer.andThen( __->RevertScreen() ));
}

@Unique
private void RevertScreen(){
client.setScreen((OptionsScreen)(Object)this);
};

@Unique
private void HandleDatapackRefresh(final ResourcePackManager manager, Collection<String> rollback){
FeatureSet neoFeatures = manager.getRequestedFeatures();
FeatureSet oldFeatures = server.getSaveProperties().getEnabledFeatures();
Expand Down Expand Up @@ -113,7 +122,6 @@ private void HandleDatapackRefresh(final ResourcePackManager manager, Collection
}
}

@Unique
private void ApplyFlags(final ResourcePackManager manager){
FeatureSet features = manager.getRequestedFeatures();

Expand All @@ -126,7 +134,6 @@ private void ApplyFlags(final ResourcePackManager manager){
}


@Unique
private void ReloadPacks(final ResourcePackManager manager){
client.inGameHud.getChatHud().addMessage(Text.translatable("commands.reload.success"));

Expand Down

0 comments on commit 8333e4a

Please sign in to comment.