Skip to content

Commit

Permalink
feat: 1.20.5 support
Browse files Browse the repository at this point in the history
  • Loading branch information
RubixDev committed May 23, 2024
1 parent 67df5d9 commit de4222f
Show file tree
Hide file tree
Showing 533 changed files with 11,916 additions and 2,391 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
- uses: actions/checkout@v4
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 17
java-version: 21

- name: Cache gradle files
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
Expand Down Expand Up @@ -67,7 +67,7 @@ jobs:
# ./gradlew runServerMixinAudit

- name: Upload artifacts
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: build-artifacts
path: versions/*/build/libs/
Expand All @@ -94,10 +94,10 @@ jobs:
- build

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Download build artifacts
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: build-artifacts
path: build-artifacts
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/matrix_prep.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
matrix_prep:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- id: setmatrix
run: python3 .github/workflows/scripts/matrix.py # ubuntu-22.04 uses Python 3.10.6
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
matrix: ${{ fromJson(needs.matrix_prep.outputs.matrix) }}

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Display context
run: |
Expand All @@ -67,7 +67,7 @@ jobs:
echo target_release_tag = ${{ github.event.inputs.target_release_tag }}
- name: Download build artifacts
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: build-artifacts
path: build-artifacts
Expand Down Expand Up @@ -138,7 +138,7 @@ jobs:
cat "$GITHUB_OUTPUT"
- name: Prepare changelog
uses: actions/github-script@v6
uses: actions/github-script@v7
id: changelog
with:
script: return process.env.CHANGELOG
Expand Down
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ preprocess {
def mc120 = createNode('1.20.1' , 1_20_01, 'yarn')
def mc1202 = createNode('1.20.2' , 1_20_02, 'yarn')
def mc1204 = createNode('1.20.4' , 1_20_04, 'yarn')
def mc1206 = createNode('1.20.6' , 1_20_06, 'yarn')

mc1206.link(mc1204, file('versions/mapping-1.20.6-1.20.4.txt'))
mc1204.link(mc1202, file('versions/mapping-1.20.4-1.20.2.txt'))
mc1202.link(mc120, file('versions/mapping-1.20.2-1.20.1.txt'))
}
Expand Down
4 changes: 3 additions & 1 deletion common.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ dependencies {
String MIXIN_CONFIG_PATH = 'rug.mixins.json'
String LANG_DIR = 'assets/rug/lang'
JavaVersion JAVA_COMPATIBILITY
if (mcVersion >= 11800) {
if (mcVersion >= 12005) {
JAVA_COMPATIBILITY = JavaVersion.VERSION_21
} else if (mcVersion >= 11800) {
JAVA_COMPATIBILITY = JavaVersion.VERSION_17
} else if (mcVersion >= 11700) {
JAVA_COMPATIBILITY = JavaVersion.VERSION_16
Expand Down
3 changes: 2 additions & 1 deletion settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"versions": [
"1.20.1",
"1.20.2",
"1.20.4"
"1.20.4",
"1.20.6"
]
}
22 changes: 17 additions & 5 deletions src/main/java/de/rubixdev/rug/RugServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.Nullable;

//#if MC >= 12006
import net.minecraft.entity.LivingEntity;
//#endif

public class RugServer implements CarpetExtension, ModInitializer {
public static final Logger LOGGER = LogManager.getLogger("Rug");
public static final String MOD_ID = "rug";
Expand Down Expand Up @@ -91,7 +95,7 @@ public SettingsManager extensionSettingsManager() {

@Override
public void onGameStarted() {
LOGGER.info("Rug Mod v" + MOD_VERSION + " loaded!");
LOGGER.info("Rug Mod v{} loaded!", MOD_VERSION);

// load rules into both settings managers
settingsManager.parseSettingsClass(RugSettings.class);
Expand Down Expand Up @@ -210,7 +214,15 @@ public void onServerLoaded(MinecraftServer server) {
}

if (RugSettings.easyHarvesting.equals("require_hoe") && player != null) {
tool.damage(1, player, p -> p.sendToolBreakStatus(hand));
tool.damage(
1,
player,
//#if MC >= 12006
LivingEntity.getSlotForHand(hand)
//#else
//$$ p -> p.sendToolBreakStatus(hand)
//#endif
);
}
return ActionResult.SUCCESS;
}));
Expand Down Expand Up @@ -464,7 +476,7 @@ private static void writeJson(JsonObject jsonObject, File file) {
private static void reload() {
ResourcePackManager resourcePackManager = minecraftServer.getDataPackManager();
resourcePackManager.scanPacks();
Collection<String> collection = Lists.newArrayList(resourcePackManager.getEnabledNames());
Collection<String> collection = Lists.newArrayList(resourcePackManager.getEnabledIds());
collection.add("RugData");

ReloadCommand.tryReloadDataPacks(collection, minecraftServer.getCommandSource());
Expand Down Expand Up @@ -507,7 +519,7 @@ private static void copyFile(String resourcePath, Path targetPath) {
} catch (IOException e) {
Logging.logStackTrace(e);
} catch (NullPointerException e) {
LOGGER.error("Resource '" + resourcePath + "' is null:");
LOGGER.error("Resource '{}' is null:", resourcePath);
Logging.logStackTrace(e);
}
}
Expand All @@ -531,7 +543,7 @@ public static void savePlayerData(ServerPlayerEntity player) {
//$$ Util.backupAndReplace(file2, file, file3);
//#endif
} catch (Exception ignored) {
LOGGER.warn("Failed to save player data for " + player.getName().getString());
LOGGER.warn("Failed to save player data for {}", player.getName().getString());
}
}
}
68 changes: 35 additions & 33 deletions src/main/java/de/rubixdev/rug/RugSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,39 +154,41 @@ public String description() {
categories = {FEATURE, SURVIVAL, RUG})
public static int enderPearlDamage = 5;

public static class validatorReachDistance extends Validator<Double> {
@Override
public Double validate(
ServerCommandSource source, CarpetRule<Double> currentRule, Double newValue, String string) {
return newValue >= 0 && newValue <= 100 ? newValue : null;
}

@Override
public String description() {
return "You must choose a value from 0 to 100";
}
}

public static boolean shouldApplyReachDistance() {
return !FabricLoader.getInstance().isModLoaded("reach-entity-attributes")
&& !FabricLoader.getInstance().isModLoaded("pehkui")
&& !FabricLoader.getInstance().isModLoaded("carpet-org-addition");
}

public static class conditionReachDistance implements Condition {
@Override
public boolean shouldRegister() {
return shouldApplyReachDistance();
}
}

@Rule(
strict = false,
validators = validatorReachDistance.class,
conditions = conditionReachDistance.class,
options = {"0.0", "4.5", "5.0", "10.0"},
categories = {EXPERIMENTAL, CREATIVE, CLIENT, RUG})
public static double reachDistance = 4.5;
//#if MC < 12006
//$$ public static class validatorReachDistance extends Validator<Double> {
//$$ @Override
//$$ public Double validate(
//$$ ServerCommandSource source, CarpetRule<Double> currentRule, Double newValue, String string) {
//$$ return newValue >= 0 && newValue <= 100 ? newValue : null;
//$$ }
//$$
//$$ @Override
//$$ public String description() {
//$$ return "You must choose a value from 0 to 100";
//$$ }
//$$ }
//$$
//$$ public static boolean shouldApplyReachDistance() {
//$$ return !FabricLoader.getInstance().isModLoaded("reach-entity-attributes")
//$$ && !FabricLoader.getInstance().isModLoaded("pehkui")
//$$ && !FabricLoader.getInstance().isModLoaded("carpet-org-addition");
//$$ }
//$$
//$$ public static class conditionReachDistance implements Condition {
//$$ @Override
//$$ public boolean shouldRegister() {
//$$ return shouldApplyReachDistance();
//$$ }
//$$ }
//$$
//$$ @Rule(
//$$ strict = false,
//$$ validators = validatorReachDistance.class,
//$$ conditions = conditionReachDistance.class,
//$$ options = {"0.0", "4.5", "5.0", "10.0"},
//$$ categories = {EXPERIMENTAL, CREATIVE, CLIENT, RUG})
//$$ public static double reachDistance = 4.5;
//#endif

public static class validatorCactusFurnaceXp extends Validator<Double> {
@Override
Expand Down
29 changes: 23 additions & 6 deletions src/main/java/de/rubixdev/rug/commands/MaxEffectCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,51 @@
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
import de.rubixdev.rug.RugSettings;
import net.minecraft.command.CommandRegistryAccess;
import net.minecraft.command.argument.RegistryEntryArgumentType;
import net.minecraft.entity.effect.StatusEffect;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;

//#if MC >= 12006
import net.minecraft.command.argument.RegistryEntryReferenceArgumentType;
//#else
//$$ import net.minecraft.command.argument.RegistryEntryArgumentType;
//#endif

public class MaxEffectCommand {
public static void register(
CommandDispatcher<ServerCommandSource> dispatcher, CommandRegistryAccess registryAccess) {
LiteralArgumentBuilder<ServerCommandSource> command = literal("maxeffect")
.requires((player) -> CommandHelper.canUseCommand(player, RugSettings.commandMaxEffect))
.then(argument(
"effect",
RegistryEntryArgumentType.registryEntry(registryAccess, RegistryKeys.STATUS_EFFECT))
//#if MC >= 12006
RegistryEntryReferenceArgumentType.registryEntry(registryAccess, RegistryKeys.STATUS_EFFECT))
//#else
//$$ RegistryEntryArgumentType.registryEntry(registryAccess, RegistryKeys.STATUS_EFFECT))
//#endif
.executes(context -> {
ServerCommandSource source = context.getSource();

ServerPlayerEntity player = source.getPlayer();
StatusEffect effect = RegistryEntryArgumentType.getStatusEffect(context, "effect")
.value();
//#if MC >= 12006
RegistryEntry.Reference<StatusEffect> effect = RegistryEntryReferenceArgumentType.getStatusEffect(context, "effect");
int seconds = -1;
Text effectName = effect.value().getName();
//#else
//$$ StatusEffect effect = RegistryEntryArgumentType.getStatusEffect(context, "effect").value();
//$$ int seconds = effect.isInstant() ? 999999 : (999999 * 20);
//$$ Text effectName = effect.getName();
//#endif

boolean success = false;

if (player != null) {
StatusEffectInstance statusEffectInstance = new StatusEffectInstance(
effect, effect.isInstant() ? 999999 : (999999 * 20), 255, false, false);
effect, seconds, 255, false, false);
success = (player).addStatusEffect(statusEffectInstance, source.getEntity());
}

Expand All @@ -48,7 +65,7 @@ public static void register(
source.sendFeedback(
() -> Text.translatable(
"commands.effect.give.success.single",
effect.getName(),
effectName,
player.getDisplayName()
),
true);
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/de/rubixdev/rug/commands/ModsCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ private static int execute(CommandContext<ServerCommandSource> context, boolean
chatMessageJson += String.join(",\"\\n \",", modJsons) + "]";

String finalChatMessageJson = chatMessageJson;
context.getSource().sendFeedback(() -> Text.Serialization.fromJson(finalChatMessageJson), false);
context.getSource().sendFeedback(() -> Text.Serialization.fromJson(
finalChatMessageJson
//#if MC > 12006
, context.getSource().getRegistryManager()
//#endif
), false);
return 1;
}

Expand Down
6 changes: 5 additions & 1 deletion src/main/java/de/rubixdev/rug/commands/PeekCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ private static int execute(CommandContext<ServerCommandSource> context, boolean
//#else
//$$ targetPlayer = playerManager.createPlayer(targetPlayerProfile);
//#endif
NbtCompound targetPlayerData = playerManager.loadPlayerData(targetPlayer);
NbtCompound targetPlayerData = playerManager.loadPlayerData(targetPlayer)
//#if MC >= 12006
.orElse(null)
//#endif
;

if (targetPlayerData == null) {
source.sendError(Text.of("Targeted player's data could not be found. Was he ever in this world?"));
Expand Down
Loading

0 comments on commit de4222f

Please sign in to comment.