Skip to content

Commit

Permalink
Migrate to Mojmap + Parchment
Browse files Browse the repository at this point in the history
  • Loading branch information
naomieow committed Jul 30, 2024
1 parent f648a7b commit e7f9721
Show file tree
Hide file tree
Showing 52 changed files with 557 additions and 556 deletions.
14 changes: 13 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ repositories {
maven {
url = "https://maven.kosmx.dev/"
}
maven {
name = 'ParchmentMC'
url = 'https://maven.parchmentmc.org'
}
maven {
name = 'Quilt'
url = "https://maven.quiltmc.org/repository/release/"
}
}

loom {
Expand All @@ -51,7 +59,11 @@ loom {
dependencies {
minecraft "com.mojang:minecraft:${project.minecraft_version}"

mappings("net.fabricmc:yarn:${project.yarn_mappings}:v2")
mappings loom.layered() {
mappings("org.quiltmc:quilt-mappings:${project.minecraft_version}+build.${project.quilt_mappings_version}:intermediary-v2")
officialMojangMappings()
parchment("org.parchmentmc.data:parchment-${project.parchment_version}@zip")
}

modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"

Expand Down
6 changes: 4 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ loader=fabric

# Fabric Properties
minecraft_version=1.20.1
yarn_mappings=1.20.1+build.10
loader_version=0.15.11
fabric_kotlin_version=1.11.0+kotlin.2.0.0
loom_version=1.7-SNAPSHOT

# Mappings
parchment_version=1.20.1:2023.09.03
quilt_mappings_version=23

# Mod Properties
mod_version=4.0.0-alpha.1+1.20.1
mod_version=4.0.0-alpha.5+1.20.1
maven_group=com.bibireden.playerex
archives_base_name=playerex-directors-cut

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import com.bibireden.playerex.PlayerEX;
import com.bibireden.playerex.api.attribute.PlayerEXAttributes;
import com.llamalad7.mixinextras.sugar.Local;
import net.minecraft.client.render.entity.EntityRenderer;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.text.Text;
import net.minecraft.client.renderer.entity.EntityRenderer;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -20,12 +20,12 @@ abstract class EntityRendererMixin<T extends Entity> {
@Unique
private boolean playerex$shouldRenderLevel() { return PlayerEX.CONFIG.getShowLevelOnNameplates(); }

@ModifyArg(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/entity/EntityRenderer;renderLabelIfPresent(Lnet/minecraft/entity/Entity;Lnet/minecraft/text/Text;Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V"), index = 1)
private Text playerex$renderLabelIfPresent(Text text, @Local(argsOnly = true) Entity entity) {
if (playerex$shouldRenderLevel() && entity instanceof PlayerEntity livingEntity) {
@ModifyArg(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/entity/EntityRenderer;renderNameTag(Lnet/minecraft/world/entity/Entity;Lnet/minecraft/network/chat/Component;Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;I)V"), index = 1)
private Component playerex$renderLabelIfPresent(Component text, @Local(argsOnly = true) Entity entity) {
if (playerex$shouldRenderLevel() && entity instanceof Player livingEntity) {
Optional<Double> maybeLevel = DataAttributesAPI.getValue(PlayerEXAttributes.LEVEL, livingEntity);
if (maybeLevel.isPresent()) {
text = text.copy().append(" ").append(Text.translatable("playerex.ui.nameplate.level", maybeLevel.get().intValue()).styled((style) -> style.withColor(0xFFAA00)));
text = text.copy().append(" ").append(Component.translatable("playerex.ui.nameplate.level", maybeLevel.get().intValue()).withStyle((style) -> style.withColor(0xFFAA00)));
}
}
return text;
Expand Down
113 changes: 57 additions & 56 deletions src/client/java/com/bibireden/playerex/mixin/ItemStackMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
import com.bibireden.playerex.PlayerEX;
import com.bibireden.playerex.config.PlayerEXConfigModel;
import com.google.common.collect.Multimap;
import net.minecraft.client.item.TooltipContext;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.attribute.EntityAttribute;
import net.minecraft.entity.attribute.EntityAttributeInstance;
import net.minecraft.entity.attribute.EntityAttributeModifier;
import net.minecraft.entity.attribute.EntityAttributes;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.ai.attributes.Attribute;
import net.minecraft.world.entity.ai.attributes.AttributeInstance;
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
Expand All @@ -32,117 +32,118 @@
@Mixin(ItemStack.class)
abstract class ItemStackMixin {
@Unique
private double playerex$modifyValue(double val, @Nullable PlayerEntity player, EntityAttribute attribute, UUID uuid) {
private double playerex$modifyValue(double val, @Nullable Player player, Attribute attribute, UUID uuid) {
if (player == null || PlayerEX.CONFIG.getTooltip() == PlayerEXConfigModel.Tooltip.Default) return val;

double valSubBase = val - player.getAttributeBaseValue(attribute);

EntityAttributeInstance instance = player.getAttributeInstance(attribute);
AttributeInstance instance = player.getAttribute(attribute);
if (instance == null) return val;

EntityAttributeModifier modifier = instance.getModifier(uuid);
AttributeModifier modifier = instance.getModifier(uuid);
double value = player.getAttributeValue(attribute) + valSubBase;

if (modifier != null) value -= modifier.getValue();
if (modifier != null) value -= modifier.getAmount();

return PlayerEX.CONFIG.getTooltip() == PlayerEXConfigModel.Tooltip.Vanilla ? valSubBase : value;
}

@Unique
private String playerex$value(double e, Map.Entry<EntityAttribute, EntityAttributeModifier> entry, EntityAttributeModifier modifier) {
if (modifier.getOperation() != EntityAttributeModifier.Operation.ADDITION) return ItemStack.MODIFIER_FORMAT.format(e);
return ItemStack.MODIFIER_FORMAT.format(e);
private String playerex$value(double e, Map.Entry<Attribute, AttributeModifier> entry, AttributeModifier modifier) {
if (modifier.getOperation() != AttributeModifier.Operation.ADDITION) return ItemStack.ATTRIBUTE_MODIFIER_FORMAT.format(e);
return ItemStack.ATTRIBUTE_MODIFIER_FORMAT.format(e);
}

@ModifyVariable(method = "getTooltip", at = @At(value = "STORE", ordinal = 1), ordinal = 0)
private double playerex$modifyAttackDamage(double original, PlayerEntity player) {
return playerex$modifyValue(original, player, EntityAttributes.GENERIC_ATTACK_DAMAGE, ItemFields.attackDamageModifierID());
@ModifyVariable(method = "getTooltipLines", at = @At(value = "STORE", ordinal = 1), ordinal = 0)
private double playerex$modifyAttackDamage(double original, Player player) {
return playerex$modifyValue(original, player, Attributes.ATTACK_DAMAGE, ItemFields.attackDamageModifierID());
}

@ModifyVariable(method = "getTooltip", at = @At(value = "STORE", ordinal = 3), ordinal = 0)
private double playerex$modifyAttackSpeed(double original, PlayerEntity player) {
return playerex$modifyValue(original, player, EntityAttributes.GENERIC_ATTACK_SPEED, ItemFields.attackDamageModifierID());
@ModifyVariable(method = "getTooltipLines", at = @At(value = "STORE", ordinal = 3), ordinal = 0)
private double playerex$modifyAttackSpeed(double original, Player player) {
return playerex$modifyValue(original, player, Attributes.ATTACK_SPEED, ItemFields.attackDamageModifierID());
}

@ModifyVariable(method = "getTooltip", at = @At(value = "STORE", ordinal = 1), ordinal = 0)
@ModifyVariable(method = "getTooltipLines", at = @At(value = "STORE", ordinal = 1), ordinal = 0)
private boolean playerex$flagAttackDamage(boolean original) {
return PlayerEX.CONFIG.getTooltip() != PlayerEXConfigModel.Tooltip.Vanilla && original;
}

@ModifyVariable(method = "getTooltip", at = @At(value = "STORE", ordinal = 2), ordinal = 0)
@ModifyVariable(method = "getTooltipLines", at = @At(value = "STORE", ordinal = 2), ordinal = 0)
private boolean playerex$flagAttackSpeed(boolean original) {
return PlayerEX.CONFIG.getTooltip() != PlayerEXConfigModel.Tooltip.Vanilla && original;
}

@ModifyVariable(method = "getTooltip", at = @At(value = "STORE", ordinal = 1), ordinal = 1)
@ModifyVariable(method = "getTooltipLines", at = @At(value = "STORE", ordinal = 1), ordinal = 1)
private double playerex$modifyAdditionAttributeKnockback(double original) { return original / 10.0; }

// todo: not sure about the implementation(s) here...
@Inject(method = "getTooltip", at = @At(value = "INVOKE", target = "Ljava/util/List;add(Ljava/lang/Object;)Z", ordinal = 7, shift = At.Shift.AFTER), locals = LocalCapture.CAPTURE_FAILHARD)
@Inject(method = "getTooltipLines", at = @At(value = "INVOKE", target = "Ljava/util/List;add(Ljava/lang/Object;)Z", ordinal = 7, shift = At.Shift.AFTER), locals = LocalCapture.CAPTURE_FAILHARD)
private void playerex$insertModifierEqualsTooltip(
PlayerEntity player, TooltipContext context,
CallbackInfoReturnable<List<Text>> info,
List<Text> list,
MutableText arg3,
Player player, TooltipFlag context,
CallbackInfoReturnable<List<Component>> info,
List<Component> list,
MutableComponent arg3,
int arg4,
EquipmentSlot[] arg5,
int arg6,
int arg7,
EquipmentSlot arg8,
Multimap<?, ?> arg9,
Iterator<?> arg10,
Map.Entry<EntityAttribute, EntityAttributeModifier> entry,
EntityAttributeModifier entityAttributeModifier,
Map.Entry<Attribute, AttributeModifier> entry,
AttributeModifier entityAttributeModifier,
double arg13, double e
) {
list.set(list.size() - 1, Text.literal(" ")
.append(Text.translatable("attribute.modifier.equals." + entityAttributeModifier.getOperation().getId(), playerex$value(e, entry, entityAttributeModifier), Text.translatable(entry.getKey().getTranslationKey())))
.formatted(Formatting.DARK_GREEN)
list.set(list.size() - 1, Component.literal(" ")
.append(Component.translatable("attribute.modifier.equals." + entityAttributeModifier.getOperation().toValue(), playerex$value(e, entry, entityAttributeModifier), Component.translatable(entry.getKey().getDescriptionId())))
.withStyle(ChatFormatting.DARK_GREEN)
);
}

@Inject(method = "getTooltip", at = @At(value = "INVOKE", target = "Ljava/util/List;add(Ljava/lang/Object;)Z", ordinal = 8, shift = At.Shift.AFTER), locals = LocalCapture.CAPTURE_FAILHARD)
@Inject(method = "getTooltipLines", at = @At(value = "INVOKE", target = "Ljava/util/List;add(Ljava/lang/Object;)Z", ordinal = 8, shift = At.Shift.AFTER), locals = LocalCapture.CAPTURE_FAILHARD)
private void playerex$insertModifierPlusTooltip(
PlayerEntity player,
TooltipContext context,
CallbackInfoReturnable<List<Text>> info,
List<Text> list,
MutableText arg3,
Player player,
TooltipFlag context,
CallbackInfoReturnable<List<Component>> info,
List<Component> list,
MutableComponent arg3,
int arg4,
EquipmentSlot[] arg5,
int arg6, int arg7, EquipmentSlot arg8, Multimap<?, ?> arg9, Iterator<?> arg10,
Map.Entry<EntityAttribute, EntityAttributeModifier> entry, EntityAttributeModifier entityAttributeModifier,
Map.Entry<Attribute, AttributeModifier> entry, AttributeModifier entityAttributeModifier,
double arg13, double e
) {
list.set(
list.size() - 1,
Text.translatable("attribute.modifier.plus." + entityAttributeModifier.getOperation().getId(),
Component.translatable("attribute.modifier.plus." + entityAttributeModifier.getOperation().toValue(),
playerex$value(e, entry, entityAttributeModifier),
Text.translatable(entry.getKey().getTranslationKey())).formatted(Formatting.BLUE)
Component.translatable(entry.getKey().getDescriptionId())).withStyle(ChatFormatting.BLUE)
);
}

@Inject(method = "getTooltip", at = @At(value = "INVOKE", target = "Ljava/util/List;add(Ljava/lang/Object;)Z", ordinal = 9, shift = At.Shift.AFTER), locals = LocalCapture.CAPTURE_FAILHARD)
@Inject(method = "getTooltipLines", at = @At(value = "INVOKE", target = "Ljava/util/List;add(Ljava/lang/Object;)Z", ordinal = 9, shift = At.Shift.AFTER), locals = LocalCapture.CAPTURE_FAILHARD)
private void playerex$insertModifierTakeTooltip(
PlayerEntity player, TooltipContext context,
CallbackInfoReturnable<List<Text>> info,
List<Text> list,
MutableText arg3,
Player player, TooltipFlag context,
CallbackInfoReturnable<List<Component>> info,
List<Component> list,
MutableComponent arg3,
int arg4,
EquipmentSlot[] arg5,
int arg6, int arg7,
int arg6,
int arg7,
EquipmentSlot arg8,
Multimap<?, ?> arg9,
Iterator<?> arg10,
Map.Entry<EntityAttribute, EntityAttributeModifier> entry,
EntityAttributeModifier entityAttributeModifier,
Map.Entry<Attribute, AttributeModifier> entry,
AttributeModifier entityAttributeModifier,
double arg13, double e
) {
list.set(
list.size() - 1,
Text.translatable("attribute.modifier.take." + entityAttributeModifier.getOperation().getId(),
Component.translatable("attribute.modifier.take." + entityAttributeModifier.getOperation().toValue(),
playerex$value(e, entry, entityAttributeModifier),
Text.translatable(entry.getKey().getTranslationKey())).formatted(Formatting.RED)
Component.translatable(entry.getKey().getDescriptionId())).withStyle(ChatFormatting.RED)
);
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package com.bibireden.playerex.mixin;

import com.bibireden.playerex.ui.PlayerEXScreen;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.Minecraft;
import net.minecraft.client.player.LocalPlayer;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(ClientPlayerEntity.class)
abstract class ClientPlayerEntityMixin {
@Shadow @Final protected MinecraftClient client;
@Mixin(LocalPlayer.class)
abstract class LocalPlayerMixin {
@Shadow @Final protected Minecraft minecraft;

@Inject(method = "setExperience", at = @At("TAIL"))
@Inject(method = "setExperienceValues", at = @At("TAIL"))
private void setExperience(CallbackInfo ci) {
if (client.currentScreen instanceof PlayerEXScreen screen) screen.onExperienceUpdated();
if (minecraft.screen instanceof PlayerEXScreen screen) screen.onExperienceUpdated();
}
}
26 changes: 13 additions & 13 deletions src/client/kotlin/com/bibireden/playerex/PlayerEXClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,34 @@ import com.bibireden.playerex.networking.types.NotificationType
import com.bibireden.playerex.registry.PlayerEXMenuRegistry
import com.bibireden.playerex.ui.PlayerEXScreen
import com.bibireden.playerex.ui.menus.PlayerEXAttributesMenu
import com.mojang.blaze3d.platform.InputConstants
import net.fabricmc.api.ClientModInitializer
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper
import net.minecraft.client.MinecraftClient
import net.minecraft.client.network.ClientPlayerEntity
import net.minecraft.client.option.KeyBinding
import net.minecraft.client.util.InputUtil
import net.minecraft.sound.SoundCategory
import net.minecraft.client.KeyMapping
import net.minecraft.client.Minecraft
import net.minecraft.client.player.LocalPlayer
import net.minecraft.sounds.SoundSource
import org.lwjgl.glfw.GLFW

object PlayerEXClient : ClientModInitializer {
val MAIN_UI_SCREEN_ID = PlayerEX.id("main_ui_model")

val KEYBINDING_MAIN_SCREEN: KeyBinding = KeyBindingHelper.registerKeyBinding(KeyBinding("${PlayerEX.MOD_ID}.key.main_screen", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_MINUS, "key.categories.${PlayerEX.MOD_ID}"))
val KEYBINDING_MAIN_SCREEN: KeyMapping = KeyBindingHelper.registerKeyBinding(KeyMapping("${PlayerEX.MOD_ID}.key.main_screen", InputConstants.Type.KEYSYM, GLFW.GLFW_KEY_MINUS, "key.categories.${PlayerEX.MOD_ID}"))

override fun onInitializeClient() {
NetworkingChannels.NOTIFICATIONS.registerClientbound(NetworkingPackets.Notify::class) { (type), ctx ->
val soundSettings = PlayerEX.CONFIG.soundSettings
when (type) {
NotificationType.LevelUpAvailable -> ctx.player().playSound(PlayerEXSoundEvents.LEVEL_UP_SOUND, SoundCategory.NEUTRAL, soundSettings.levelUpVolume.toFloat(), 1F)
NotificationType.Spent -> ctx.player().playSound(PlayerEXSoundEvents.SPEND_SOUND, SoundCategory.NEUTRAL, soundSettings.skillUpVolume.toFloat(), 1F)
NotificationType.Refunded -> ctx.player().playSound(PlayerEXSoundEvents.REFUND_SOUND, SoundCategory.NEUTRAL, soundSettings.refundVolume.toFloat(), 0.7F)
NotificationType.LevelUpAvailable -> ctx.player().playNotifySound(PlayerEXSoundEvents.LEVEL_UP_SOUND, SoundSource.NEUTRAL, soundSettings.levelUpVolume.toFloat(), 1F)
NotificationType.Spent -> ctx.player().playNotifySound(PlayerEXSoundEvents.SPEND_SOUND, SoundSource.NEUTRAL, soundSettings.skillUpVolume.toFloat(), 1F)
NotificationType.Refunded -> ctx.player().playNotifySound(PlayerEXSoundEvents.REFUND_SOUND, SoundSource.NEUTRAL, soundSettings.refundVolume.toFloat(), 0.7F)
}
}

EntityAttributeModifiedEvents.MODIFIED.register { attribute, entity, _, _, _ ->
if (entity is ClientPlayerEntity) {
val screen = MinecraftClient.getInstance().currentScreen
if (entity is LocalPlayer) {
val screen = Minecraft.getInstance().screen
if (screen is PlayerEXScreen) {
if (attribute == PlayerEXAttributes.LEVEL) {
DataAttributesAPI.getValue(attribute, entity).map(Double::toInt).ifPresent(screen::onLevelUpdated)
Expand All @@ -56,8 +56,8 @@ object PlayerEXClient : ClientModInitializer {

ClientTickEvents.END_CLIENT_TICK.register { client ->
if (PlayerEX.CONFIG.disableUI) return@register
while (KEYBINDING_MAIN_SCREEN.wasPressed()) {
if (client.currentScreen == null) {
while (KEYBINDING_MAIN_SCREEN.consumeClick()) {
if (client.screen == null) {
client.setScreen(PlayerEXScreen())
}
}
Expand Down
Loading

0 comments on commit e7f9721

Please sign in to comment.