Skip to content

Commit

Permalink
1.19 + migrate to mojmap
Browse files Browse the repository at this point in the history
  • Loading branch information
samolego committed Jun 8, 2022
1 parent 336e192 commit 12d7224
Show file tree
Hide file tree
Showing 12 changed files with 209 additions and 201 deletions.
6 changes: 4 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import com.modrinth.minotaur.TaskModrinthUpload

plugins {
id 'fabric-loom' version '0.10-SNAPSHOT'
id 'fabric-loom' version '0.12-SNAPSHOT'
id 'maven-publish'
id "com.matthewprenger.cursegradle" version "1.4.0"
id "com.modrinth.minotaur" version "1.1.0"
Expand All @@ -27,7 +27,7 @@ repositories {
dependencies {
// To change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
mappings loom.officialMojangMappings()
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"

// Fabric API. This is technically optional, but you probably want it anyway.
Expand Down Expand Up @@ -108,6 +108,7 @@ curseforge {
releaseType = "release"
addGameVersion "${project.minecraft_version}"
addGameVersion "Fabric"
addGameVersion "Quilt"

mainArtifact(file("${project.buildDir}/libs/${archivesBaseName}-${version}.jar")) {
displayName = "[${project.minecraft_version}] Healthcare ${version}"
Expand Down Expand Up @@ -138,4 +139,5 @@ task modrinth(type: TaskModrinthUpload, dependsOn: remapJar) {

addGameVersion("${project.minecraft_version}")
addLoader('fabric')
addLoader('quilt')
}
20 changes: 8 additions & 12 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
# Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx1G

# Fabric Properties
minecraft_version=1.18.2
yarn_mappings=1.18.2+build.1
loader_version=0.13.3

minecraft_version=1.19
yarn_mappings=1.19+build.1
loader_version=0.14.6
#Fabric api
fabric_version=0.47.8+1.18.2

fabric_version=0.55.2+1.19
# Mod Properties
mod_version = 1.0.11
maven_group = org.samo_lego
archives_base_name = healthcare

mod_version=1.1.0
maven_group=org.samo_lego
archives_base_name=healthcare
# Config editing lib
c2b_version = 1.0.2
c2b_version=4c3b0be618
2 changes: 1 addition & 1 deletion src/main/java/org/samo_lego/healthcare/HealthCare.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.samo_lego.healthcare;

import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.fabricmc.fabric.api.entity.event.v1.ServerPlayerEvents;
import net.fabricmc.loader.api.FabricLoader;
import org.samo_lego.healthcare.command.HealthbarCommand;
Expand Down
157 changes: 80 additions & 77 deletions src/main/java/org/samo_lego/healthcare/command/HealthbarCommand.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,34 @@
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.tree.LiteralCommandNode;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.text.LiteralText;
import net.minecraft.util.Formatting;
import net.minecraft.ChatFormatting;
import net.minecraft.commands.CommandBuildContext;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.network.chat.Component;
import org.samo_lego.healthcare.config.HealthConfig;
import org.samo_lego.healthcare.permission.PermissionHelper;

import static net.minecraft.server.command.CommandManager.literal;
import static org.samo_lego.healthcare.HealthCare.*;
import static net.minecraft.commands.Commands.literal;
import static org.samo_lego.healthcare.HealthCare.CONFIG_FILE;
import static org.samo_lego.healthcare.HealthCare.LUCKPERMS_LOADED;
import static org.samo_lego.healthcare.HealthCare.config;

public class HealthcareCommand {

public static void register(CommandDispatcher<ServerCommandSource> dispatcher, boolean dedicated) {
LiteralCommandNode<ServerCommandSource> healthcareNode = dispatcher.register(literal("healthcare")
.requires(src -> LUCKPERMS_LOADED ? PermissionHelper.checkPermission(src, config.perms.healthcare_config, 4) : src.hasPermissionLevel(4)));
public static void register(CommandDispatcher<CommandSourceStack> dispatcher, CommandBuildContext context, Commands.CommandSelection selection) {
LiteralCommandNode<CommandSourceStack> healthcareNode = dispatcher.register(literal("healthcare")
.requires(src -> LUCKPERMS_LOADED ? PermissionHelper.checkPermission(src, config.perms.healthcare_config, 4) : src.hasPermission(4)));

LiteralCommandNode<ServerCommandSource> configNode = literal("config")
LiteralCommandNode<CommandSourceStack> configNode = literal("config")
.then(literal("reload")
.requires(src -> LUCKPERMS_LOADED ? PermissionHelper.checkPermission(src, config.perms.healthcare_config_reload, 4) : src.hasPermissionLevel(4))
.requires(src -> LUCKPERMS_LOADED ? PermissionHelper.checkPermission(src, config.perms.healthcare_config_reload, 4) : src.hasPermission(4))
.executes(HealthcareCommand::reloadConfig)
)
.build();

LiteralCommandNode<ServerCommandSource> editNode = literal("edit")
.requires(src -> LUCKPERMS_LOADED ? PermissionHelper.checkPermission(src, config.perms.healthcare_config_edit, 4) : src.hasPermissionLevel(4))
LiteralCommandNode<CommandSourceStack> editNode = literal("edit")
.requires(src -> LUCKPERMS_LOADED ? PermissionHelper.checkPermission(src, config.perms.healthcare_config_edit, 4) : src.hasPermission(4))
.build();

config.generateCommand(editNode);
Expand All @@ -35,12 +39,12 @@ public static void register(CommandDispatcher<ServerCommandSource> dispatcher, b
healthcareNode.addChild(configNode);
}

private static int reloadConfig(CommandContext<ServerCommandSource> ctx) {
private static int reloadConfig(CommandContext<CommandSourceStack> ctx) {
HealthConfig newConfig = HealthConfig.loadConfigFile(CONFIG_FILE);
config.reload(newConfig);

ctx.getSource().sendFeedback(
new LiteralText(config.lang.configReloaded).formatted(Formatting.GREEN),
ctx.getSource().sendSuccess(
Component.literal(config.lang.configReloaded).withStyle(ChatFormatting.GREEN),
false
);
return 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.samo_lego.healthcare.event;

import net.fabricmc.fabric.api.entity.event.v1.ServerPlayerEvents;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.level.ServerPlayer;
import org.samo_lego.healthcare.healthbar.HealthbarPreferences;

public class EventHandler implements ServerPlayerEvents.CopyFrom {
Expand All @@ -14,7 +14,7 @@ public class EventHandler implements ServerPlayerEvents.CopyFrom {
* @param alive whether the old player is still alive
*/
@Override
public void copyFromPlayer(ServerPlayerEntity oldPlayer, ServerPlayerEntity newPlayer, boolean alive) {
public void copyFromPlayer(ServerPlayer oldPlayer, ServerPlayer newPlayer, boolean alive) {
((HealthbarPreferences) newPlayer).setHealthbarStyle(((HealthbarPreferences) oldPlayer).getHealthbarStyle());
((HealthbarPreferences) newPlayer).setEnabled(((HealthbarPreferences) oldPlayer).isEnabled());
((HealthbarPreferences) newPlayer).setAlwaysVisible(((HealthbarPreferences) oldPlayer).isAlwaysVisible());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.samo_lego.healthcare.healthbar;

import net.minecraft.text.MutableText;
import net.minecraft.network.chat.MutableComponent;

public interface HealthbarPreferences {
/**
Expand All @@ -12,11 +12,12 @@ public interface HealthbarPreferences {

/**
* Gets the health text from current health and max health depending on HealthbarStyle.
* @param health current health
*
* @param health current health
* @param maxHealth max health
* @return formatted mutable text with health info
*/
MutableText getHealthbarText(float health, float maxHealth);
MutableComponent getHealthbarText(float health, float maxHealth);

void setEnabled(boolean enabled);
boolean isEnabled();
Expand Down
15 changes: 8 additions & 7 deletions src/main/java/org/samo_lego/healthcare/mixin/EntityAccessor.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
package org.samo_lego.healthcare.mixin;

import net.minecraft.entity.Entity;
import net.minecraft.entity.data.TrackedData;
import net.minecraft.text.Text;
import net.minecraft.network.chat.Component;
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.world.entity.Entity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

import java.util.Optional;

@Mixin(Entity.class)
public interface EntityAccessor {
@Accessor("NAME_VISIBLE")
static TrackedData<Boolean> getNAME_VISIBLE() {
@Accessor("DATA_CUSTOM_NAME_VISIBLE")
static EntityDataAccessor<Boolean> getNAME_VISIBLE() {
throw new AssertionError();
}
@Accessor("CUSTOM_NAME")
static TrackedData<Optional<Text>> getCUSTOM_NAME() {

@Accessor("DATA_CUSTOM_NAME")
static EntityDataAccessor<Optional<Component>> getCUSTOM_NAME() {
throw new AssertionError();
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
package org.samo_lego.healthcare.mixin;

import net.minecraft.entity.data.DataTracker;
import net.minecraft.network.packet.s2c.play.EntityTrackerUpdateS2CPacket;
import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket;
import net.minecraft.network.syncher.SynchedEntityData;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
import org.spongepowered.asm.mixin.gen.Accessor;

import java.util.List;

@Mixin(EntityTrackerUpdateS2CPacket.class)
@Mixin(ClientboundSetEntityDataPacket.class)
public interface EntityTrackerUpdateS2CPacketAccessor {

@Accessor("trackedValues")
List<DataTracker.Entry<?>> getTrackedValues();
@Accessor("packedItems")
List<SynchedEntityData.DataItem<?>> getPackedItems();

@Mutable
@Accessor("trackedValues")
void setTrackedValues(List<DataTracker.Entry<?>> trackedValues);
@Accessor("packedItems")
void setPackedItems(List<SynchedEntityData.DataItem<?>> packedItems);

@Accessor("id")
int getId();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package org.samo_lego.healthcare.mixin;

import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.text.LiteralText;
import net.minecraft.text.MutableText;
import net.minecraft.util.Formatting;
import net.minecraft.ChatFormatting;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.world.entity.player.Player;
import org.samo_lego.healthcare.healthbar.HealthbarPreferences;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -13,7 +13,7 @@

import static org.samo_lego.healthcare.HealthCare.config;

@Mixin(PlayerEntity.class)
@Mixin(Player.class)
public class PlayerEntityMixinCast_Preferences implements HealthbarPreferences {

private HealthbarStyle healthbarStyle = config.defaultStyle;
Expand All @@ -36,14 +36,14 @@ public void setHealthbarStyle(HealthbarStyle healthbarStyle) {
}

@Override
public MutableText getHealthbarText(float health, float maxHealth) {
if(health < 0.0F) {
public MutableComponent getHealthbarText(float health, float maxHealth) {
if (health < 0.0F) {
health = 0.0F;
}
if(maxHealth <= 0.0F) {
if (maxHealth <= 0.0F) {
maxHealth = 1.0F;
}
if(health > maxHealth) {
if (health > maxHealth) {
maxHealth = health;
}

Expand All @@ -55,14 +55,14 @@ public MutableText getHealthbarText(float health, float maxHealth) {
second = String.valueOf((int) Math.ceil(maxHealth));

// We return it here because of custom formatting
return new LiteralText(first)
.formatted(health > maxHealth / 2 ? Formatting.GREEN : Formatting.YELLOW)
.append(new LiteralText("/")
.formatted(Formatting.WHITE))
.append(new LiteralText(second)
.formatted(Formatting.GREEN))
.append(new LiteralText(String.valueOf((char) 10084)) // ❤
.formatted(Formatting.RED));
return Component.literal(first)
.withStyle(health > maxHealth / 2 ? ChatFormatting.GREEN : ChatFormatting.YELLOW)
.append(Component.literal("/")
.withStyle(ChatFormatting.WHITE))
.append(Component.literal(second)
.withStyle(ChatFormatting.GREEN))
.append(Component.literal(String.valueOf((char) 10084)) // ❤
.withStyle(ChatFormatting.RED));
}
case NUMBER -> {
// Number
Expand Down Expand Up @@ -98,9 +98,9 @@ public MutableText getHealthbarText(float health, float maxHealth) {
second = new String(new char[heartCount - fullHearts]).replace('\0', empty);
}
}
return new LiteralText(first)
.formatted(Formatting.RED) /*health > maxHealth / 3 ? (health > maxHealth * 1.5F ? Formatting.YELLOW : Formatting.GOLD) : */
.append(new LiteralText(second).formatted(Formatting.GRAY));
return Component.literal(first)
.withStyle(ChatFormatting.RED) /*health > maxHealth / 3 ? (health > maxHealth * 1.5F ? Formatting.YELLOW : Formatting.GOLD) : */
.append(Component.literal(second).withStyle(ChatFormatting.GRAY));
}

@Override
Expand Down Expand Up @@ -155,7 +155,7 @@ public int getCustomFullChar() {

@Override
public void setCustomLength(int length) {
if(length >= 0) // Don't allow negative length
if (length >= 0) // Don't allow negative length
this.customLength = length;
}

Expand All @@ -164,31 +164,31 @@ public int getCustomLength() {
return this.customLength;
}

@Inject(method = "writeCustomDataToNbt", at = @At("TAIL"))
private void writeCustomDataToTag(NbtCompound tag, CallbackInfo ci) {
NbtCompound healthbar = new NbtCompound();
@Inject(method = "addAdditionalSaveData", at = @At("TAIL"))
private void writeCustomDataToTag(CompoundTag tag, CallbackInfo ci) {
CompoundTag healthbar = new CompoundTag();
healthbar.putString("Style", this.healthbarStyle.toString());
healthbar.putBoolean("Enabled", this.enabled);
healthbar.putBoolean("ShowType", this.showType);
healthbar.putBoolean("AlwaysVisible", this.alwaysVisible);
if(this.healthbarStyle.equals(HealthbarStyle.CUSTOM)) {
if (this.healthbarStyle.equals(HealthbarStyle.CUSTOM)) {
healthbar.putInt("CustomFullChar", this.customFullChar);
healthbar.putInt("CustomEmptyChar", this.customEmptyChar);
healthbar.putInt("Length", this.customLength);
}
tag.put("Healthbar", healthbar);
}

@Inject(method = "readCustomDataFromNbt", at = @At("TAIL"))
private void readCustomDataFromTag(NbtCompound tag, CallbackInfo ci) {
if(tag.contains("Healthbar")) {
NbtCompound healthbar = tag.getCompound("Healthbar");
@Inject(method = "readAdditionalSaveData", at = @At("TAIL"))
private void readCustomDataFromTag(CompoundTag tag, CallbackInfo ci) {
if (tag.contains("Healthbar")) {
CompoundTag healthbar = tag.getCompound("Healthbar");
this.healthbarStyle = HealthbarStyle.valueOf(healthbar.getString("Style"));
this.enabled = healthbar.getBoolean("Enabled");
this.alwaysVisible = healthbar.getBoolean("AlwaysVisible");
this.showType = healthbar.getBoolean("ShowType");

if(this.healthbarStyle.equals(HealthbarStyle.CUSTOM)) {
if (this.healthbarStyle.equals(HealthbarStyle.CUSTOM)) {
this.customFullChar = healthbar.getInt("CustomFullChar");
this.customEmptyChar = healthbar.getInt("CustomEmptyChar");
this.customLength = healthbar.getInt("Length");
Expand Down
Loading

0 comments on commit 12d7224

Please sign in to comment.