Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
nthxny committed Aug 1, 2024
1 parent 9271b58 commit 3958df5
Show file tree
Hide file tree
Showing 15 changed files with 108 additions and 39 deletions.
Binary file added banner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 23 additions & 13 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import org.jetbrains.kotlin.incremental.createDirectory

plugins {
`maven-publish`
kotlin("jvm")
Expand Down Expand Up @@ -61,7 +63,10 @@ dependencies {
modImplementation("net.fabricmc.fabric-api:fabric-api:${property("deps.fapi")}")
modImplementation("net.fabricmc:fabric-loader:${property("deps.fabric_loader")}")

modApi("fuzs.forgeconfigapiport:forgeconfigapiport-fabric:${property("deps.forgeconfigapi")}")
if (mcVersion == "1.19.2")
modApi("net.minecraftforge:forgeconfigapiport-fabric:${property("deps.forgeconfigapi")}")
else
modApi("fuzs.forgeconfigapiport:forgeconfigapiport-fabric:${property("deps.forgeconfigapi")}")
} else {
if (loader == "forge") {
"forge"("net.minecraftforge:forge:${mcVersion}-${property("deps.fml")}")
Expand Down Expand Up @@ -106,10 +111,20 @@ tasks.withType<JavaCompile>() {
options.compilerArgs.add("-Xplugin:Manifold")
// modify the JavaCompile task and inject our auto-generated Manifold symbols
if(!this.name.startsWith("_")) { // check the name, so we don't inject into Forge internal compilation
setupManifoldPreprocessors(options.compilerArgs, isFabric, projectDir, mcVersion)
setupManifoldPreprocessors(options.compilerArgs, isFabric, projectDir, mcVersion, false)
}
}

project.tasks.register("setupManifoldPreprocessors") {
setupManifoldPreprocessors(ArrayList(), isFabric, projectDir, mcVersion, true)
}

tasks.setupChiseledBuild {
finalizedBy("setupManifoldPreprocessors")
}



val buildAndCollect = tasks.register<Copy>("buildAndCollect") {
group = "build"
from(tasks.remapJar.get().archiveFile)
Expand Down Expand Up @@ -205,16 +220,6 @@ publishMods {
}

publishing {
repositories {
maven("https://maven.kikugie.dev/releases") {
name = "kikugieMaven"
credentials(PasswordCredentials::class.java)
authentication {
create<BasicAuthentication>("basic")
}
}
}

publications {
create<MavenPublication>("mavenJava") {
groupId = "${property("mod.group")}.${mod.id}"
Expand All @@ -226,7 +231,7 @@ publishing {
}
}

fun setupManifoldPreprocessors(compilerArgs: MutableList<String>?, isFabric: Boolean, parent: File, mcString : String) {
fun setupManifoldPreprocessors(compilerArgs: MutableList<String>?, isFabric: Boolean, parent: File, mcString : String, clearMainProject : Boolean) {
val mcVers = listOf("1.18.2", "1.19.2", "1.20.1", "1.21")
val mcIndex = mcVers.indexOf(mcString);

Expand All @@ -250,6 +255,8 @@ fun setupManifoldPreprocessors(compilerArgs: MutableList<String>?, isFabric: Boo
}

File(parent, "build.properties").writeText(sb.toString())
File(parent, "build/chiseledSrc").createDirectory()
File(parent, "build/chiseledSrc/build.properties").writeText(sb.toString())

// if the project we're currently processing annotations for happens to be the
// main project, we need to also copy the build.properties to the root folder
Expand All @@ -258,4 +265,7 @@ fun setupManifoldPreprocessors(compilerArgs: MutableList<String>?, isFabric: Boo

if (stonecutter.active.project == stonecutter.current.project)
File(parent, "../../src/main/build.properties").writeText(sb.toString())

if (clearMainProject)
File(parent, "../../src/main/build.properties").delete()
}
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ org.gradle.caching.debug=false
org.gradle.configureondemand=true

# Mod Properties
mod.version=3.4.3
mod.group=dev.kikugie
mod.id=elytratrims
mod.name=Elytra Trims
mod.version=1.0.0
mod.group=com.github.alexmodguy
mod.id=mediumcore
mod.name=Mediumcore

# Global Dependencies
deps.mixin_squared=0.1.2-beta.4
Expand Down
Binary file added logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added logo.psd
Binary file not shown.
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ extensions.configure<StonecutterSettings> {
for (it in loaders) vers("$version-$it", version)
}
//mc("1.19.4", "fabric", "forge")
//mc("1.19.2", "fabric")
mc("1.20.1", "fabric")
mc("1.21", "fabric")
}
Expand Down
21 changes: 13 additions & 8 deletions src/main/java/com/github/alexmodguy/mediumcore/Mediumcore.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.util.Mth;
import net.minecraftforge.common.ForgeConfigSpec;

import org.apache.commons.lang3.tuple.Pair;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand All @@ -30,9 +29,10 @@
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
import fuzs.forgeconfigapiport.fabric.api.forge.v4.ForgeConfigRegistry;
#endif

#if BEFORE_21
#elif BEFORE_20_1
import net.minecraftforge.fml.config.ModConfig;
import net.minecraftforge.api.ModLoadingContext;
#elif BEFORE_21
import net.minecraftforge.fml.config.ModConfig;
import fuzs.forgeconfigapiport.api.config.v2.ForgeConfigRegistry;
#endif
Expand All @@ -42,6 +42,7 @@
public class Mediumcore implements ModInitializer, ClientModInitializer
{
public static final Logger LOGGER = LogManager.getLogger("mediumcore");
public static final ResourceLocation MEDIUMCORE_HEARTS_TEXTURE = VersionUtils.resource("mediumcore", "textures/gui/icons.png");

public static final String MOD_ID = "mediumcore";

Expand All @@ -66,14 +67,18 @@ public void onInitializeClient()
ItemTooltipCallback.EVENT.register((stack, tooltipContext, #if AFTER_21 tooltipType, #endif lines) ->
{
if (stack.is(MediumcoreTags.RESTORES_MAX_HEALTH) && clientActive) {
lines.add(Component.literal("❤ Restores Max Hea/lth").withStyle(ChatFormatting.RED));
lines.add(Component.literal("❤ Restores Max Health").withStyle(ChatFormatting.RED));
}
});
}

public void onInitialize()
{
#if BEFORE_20_1
ModLoadingContext.registerConfig(MOD_ID, ModConfig.Type.COMMON, CONFIG_SPEC);
#else
ForgeConfigRegistry.INSTANCE.register(Mediumcore.MOD_ID, ModConfig.Type.COMMON, CONFIG_SPEC);
#endif
GameRuleRegistry.setup();

SyncMediumcoreGameRuleMessage.register();
Expand All @@ -87,7 +92,7 @@ public void onInitialize()
.executes(context -> {
var player = EntityArgument.getPlayer(context, "player");
var value = IntegerArgumentType.getInteger(context, "value");
context.getSource().sendSuccess(() -> Component.literal("Removed " + value + " Hearts"), false);
context.getSource().sendSuccess(#if AFTER_20_1 () -> #endif Component.literal("Removed " + value + " Hearts"), false);
return addHearts(player, -value);
})
)
Expand All @@ -99,7 +104,7 @@ public void onInitialize()
.executes(context -> {
var player = EntityArgument.getPlayer(context, "player");
var value = IntegerArgumentType.getInteger(context, "value");
context.getSource().sendSuccess(() -> Component.literal("Added " + value + " Hearts"), false);
context.getSource().sendSuccess(#if AFTER_20_1 () -> #endif Component.literal("Added " + value + " Hearts"), false);
return addHearts(player, value);
})
)
Expand All @@ -109,7 +114,7 @@ public void onInitialize()
}

public static int addHearts(ServerPlayer player, int amount) {
if (player == null || !GameRuleRegistry.isMediumCoreMode(player.level().getGameRules()))
if (player == null || !GameRuleRegistry.isMediumCoreMode(VersionUtils.level(player).getGameRules()))
return 0;

MediumCoreData.PlayerData data = MediumCoreData.getPlayerData(player);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public static void onInitialize() {
});

ServerPlayerEvents.AFTER_RESPAWN.register((ServerPlayer oldPlayer, ServerPlayer newPlayer, boolean alive) -> {
if (!alive && !newPlayer.level().isClientSide) {
if (GameRuleRegistry.isMediumCoreMode(newPlayer.level().getGameRules())) {
if (!alive && !VersionUtils.level(newPlayer).isClientSide) {
if (GameRuleRegistry.isMediumCoreMode(VersionUtils.level(newPlayer).getGameRules())) {
double healthModifiedBy = MediumCoreData.getPlayerData(newPlayer).healthModifiedBy;
updateHealth(newPlayer, healthModifiedBy);
}
Expand All @@ -66,7 +66,7 @@ public static void onInitialize() {
if (!(entity instanceof Player player))
return;

if (!GameRuleRegistry.isMediumCoreMode(player.level().getGameRules()))
if (!GameRuleRegistry.isMediumCoreMode(VersionUtils.level(player).getGameRules()))
return;

MediumCoreData.PlayerData data = MediumCoreData.getPlayerData(player);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
package com.github.alexmodguy.mediumcore.mixins;

import com.github.alexmodguy.mediumcore.Mediumcore;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.resources.ResourceLocation;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

#if AFTER_20_1
import net.minecraft.client.gui.GuiGraphics;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
#else
import net.minecraft.client.gui.GuiComponent;
#endif

#if AFTER_21
@Mixin(Gui.HeartType.class)
#else
Expand All @@ -35,18 +43,27 @@ public void getSpriteMediumcore(boolean hardcore, boolean halfHeart, boolean bli
cir.setReturnValue(blinking ? this.mediumcore$FullBlinking : mediumcore$Full);
}
}
#else
#elif AFTER_20_1
@Inject(at = @At("HEAD"), method = "renderHeart", cancellable = true)
public void getSpriteMediumcore(GuiGraphics guiGraphics, Gui.HeartType heartType, int i, int j, int k, boolean bl, boolean bl2, CallbackInfo ci)
{
if (!Mediumcore.clientActive || heartType != Gui.HeartType.NORMAL)
return;

@Unique
private static final ResourceLocation MEDIUMCORE_HEARTS_TEXTURE = new ResourceLocation("mediumcore:textures/gui/icons.png");
guiGraphics.blit(Mediumcore.MEDIUMCORE_HEARTS_TEXTURE, i, j, heartType.getX(bl2, bl), k, 9, 9);
ci.cancel();
}

#else
@Inject(at = @At("HEAD"), method = "renderHeart", cancellable = true)
public void getSpriteMediumcore(GuiGraphics guiGraphics, Gui.HeartType heartType, int i, int j, int k, boolean bl, boolean bl2, CallbackInfo ci)
public void getSpriteMediumcore(PoseStack poseStack, Gui.HeartType heartType, int i, int j, int k, boolean bl, boolean bl2, CallbackInfo ci)
{
if (!Mediumcore.clientActive || heartType != Gui.HeartType.NORMAL)
return;
RenderSystem.setShaderTexture(0, Mediumcore.MEDIUMCORE_HEARTS_TEXTURE);
((Gui)(Object) this).blit(poseStack, i, j, heartType.getX(bl2, bl), k, 9, 9);
RenderSystem.setShaderTexture(0, GuiComponent.GUI_ICONS_LOCATION);

guiGraphics.blit(MEDIUMCORE_HEARTS_TEXTURE, i, j, heartType.getX(bl2, bl), k, 9, 9);
ci.cancel();
}
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import toni.lib.VersionUtils;


@Mixin(Item.class)
Expand All @@ -26,7 +27,7 @@ public void onUseItem(ItemStack stack, Level level, LivingEntity livingEntity, C
if (!(livingEntity instanceof Player player) || level.isClientSide())
return;

if (stack.is(MediumcoreTags.RESTORES_MAX_HEALTH) && GameRuleRegistry.isMediumCoreMode(player.level().getGameRules())) {
if (stack.is(MediumcoreTags.RESTORES_MAX_HEALTH) && GameRuleRegistry.isMediumCoreMode(VersionUtils.level(player).getGameRules())) {
MediumCoreData.PlayerData data = MediumCoreData.getPlayerData(player);
double clampedHealth = Mth.clamp(player.getMaxHealth() + Mediumcore.CONFIG.healthIncreasePerHeal.get(), Mediumcore.CONFIG.minimumPlayerHealth.get(), Mediumcore.CONFIG.maxPlayerHealth.get());
data.healthModifiedBy += (clampedHealth - player.getMaxHealth());
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/toni/lib/VersionUtils.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package toni.lib;

import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;

public class VersionUtils
{
Expand All @@ -11,4 +15,22 @@ public static ResourceLocation resource(String modid, String path) {
return new ResourceLocation(modid, path);
#endif
}

public static Component text(String str) {
#if AFTER_21
return Component.literal(str);
#else
return Component.literal(str);
#endif
}

public static Level level(Entity entity)
{
#if AFTER_20_1
return entity.level();
#else
return entity.level;
#endif

}
}
Binary file modified src/main/resources/assets/mediumcore/textures/mod_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/main/resources/mediumcore.mixins.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"required": true,
"package": "com.github.alexmodguy.mediumcore.mixins",
"compatibilityLevel": "JAVA_21",
"compatibilityLevel": "JAVA_17",
"mixins": [
"DedicatedServerPropertiesMixin",
"ItemMixin"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# DO NOT EDIT - GENERATED BY THE BUILD SCRIPT
NEWER_THAN_18_2=
AFTER_18_2=
NEWER_THAN_19_2=
UPTO_19_2=
CURRENT_19_2=
AFTER_19_2=
BEFORE_20_1=
UPTO_20_1=
CURRENT_20_1=
AFTER_20_1=
BEFORE_21=
UPTO_21=
FABRIC=
13 changes: 13 additions & 0 deletions versions/1.19.2-fabric/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
loom.platform=fabric

# Global
deps.yarn_build=10

# Fabric
deps.fapi=0.77.0+1.19.2

# Mod
mod.mc_dep=>=1.19.2 <=1.19.2
mod.mc_title=1.19.2
mod.mc_targets=1.19.2
deps.forgeconfigapi=4.2.11

0 comments on commit 3958df5

Please sign in to comment.