diff --git a/build.gradle b/build.gradle index 3ee58f6..ad6c0eb 100644 --- a/build.gradle +++ b/build.gradle @@ -112,6 +112,16 @@ tasks.withType(JavaCompile) { options.release = isJava21 ? 21 : 17 } +def buildJar = tasks.create("buildJar", Copy.class) { + into("${rootProject.layout.getBuildDirectory().get()}/libs/$mod_version") +} + +afterEvaluate { + buildJar.dependsOn(remapJar) + buildJar.from(remapJar.archiveFile) + build.finalizedBy(buildJar) +} + java { withSourcesJar() sourceCompatibility = isJava21 ? JavaVersion.VERSION_21 : JavaVersion.VERSION_17 @@ -150,6 +160,7 @@ ext { } } + processResources { def version_range = mc_version_range diff --git a/gradle.properties b/gradle.properties index d92375e..10c3ec7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ org.gradle.jvmargs=-Xmx3072M enabled_platforms=fabric,forge,neoforge archives_base_name=Legacy4J -mod_version=1.7.10.2501.2 +mod_version=1.7.10.2501.3 mod_id=legacy mod_license=MIT mod_name=Legacy4J diff --git a/src/main/java/wily/legacy/Legacy4J.java b/src/main/java/wily/legacy/Legacy4J.java index 6cfd0fd..cebaa8b 100644 --- a/src/main/java/wily/legacy/Legacy4J.java +++ b/src/main/java/wily/legacy/Legacy4J.java @@ -351,7 +351,7 @@ public static int getDyeColor(DyeColor dyeColor){ } public static float getItemDamageModifier(ItemStack stack){ - if (LegacyConfig.legacyCombat.get()){ + if (LegacyConfig.hasCommonConfigEnabled(LegacyConfig.legacyCombat)){ if (stack.getItem() instanceof SwordItem) return 1; else if (stack.getItem() instanceof ShovelItem) return -0.5f; else if (stack.getItem() instanceof PickaxeItem) return 1; diff --git a/src/main/java/wily/legacy/config/LegacyConfig.java b/src/main/java/wily/legacy/config/LegacyConfig.java index 113aebb..d3a58bf 100644 --- a/src/main/java/wily/legacy/config/LegacyConfig.java +++ b/src/main/java/wily/legacy/config/LegacyConfig.java @@ -10,6 +10,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import wily.factoryapi.FactoryAPI; +import wily.factoryapi.FactoryAPIClient; import wily.factoryapi.base.ArbitrarySupplier; import wily.factoryapi.base.Bearer; import wily.factoryapi.base.network.CommonNetwork; @@ -222,6 +223,10 @@ static LegacyConfig create(String key, ArbitrarySupplier legacySwordBlocking = COMMON_STORAGE.register(createCommonBoolean("legacySwordBlocking", ()-> new LegacyConfigDisplay<>(LegacyConfig.legacySwordBlocking.getKey()), false, b-> {})); + static boolean hasCommonConfigEnabled(LegacyConfig config) { + return config.get() && (!FactoryAPI.isClient() || FactoryAPIClient.hasModOnServer); + } + static void decodeConfigs(Map> configs, Dynamic dynamic, Consumer> afterDecode){ dynamic.asMapOpt().result().ifPresent(m->m.forEach(p-> p.getFirst().asString().result().ifPresent(s-> { LegacyConfig config = configs.get(s); diff --git a/src/main/java/wily/legacy/mixin/base/ItemInHandRendererMixin.java b/src/main/java/wily/legacy/mixin/base/ItemInHandRendererMixin.java index 2515cca..81167e3 100644 --- a/src/main/java/wily/legacy/mixin/base/ItemInHandRendererMixin.java +++ b/src/main/java/wily/legacy/mixin/base/ItemInHandRendererMixin.java @@ -122,7 +122,7 @@ private void applyItemTransforms(PoseStack poseStack, float h, HumanoidArm human @Inject(method = "renderArmWithItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/ItemInHandRenderer;applyItemArmTransform(Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/world/entity/HumanoidArm;F)V", shift = At.Shift.AFTER, ordinal = 4)) private void renderArmWithItemBlockAnim(AbstractClientPlayer abstractClientPlayer, float f, float g, InteractionHand interactionHand, float h, ItemStack itemStack, float i, PoseStack poseStack, MultiBufferSource multiBufferSource, int j, CallbackInfo ci) { - if (LegacyConfig.legacySwordBlocking.get()) { + if (LegacyConfig.hasCommonConfigEnabled(LegacyConfig.legacySwordBlocking)) { boolean bl = interactionHand == InteractionHand.MAIN_HAND; HumanoidArm humanoidArm = bl ? abstractClientPlayer.getMainArm() : abstractClientPlayer.getMainArm().getOpposite(); this.applyItemArmAttackTransform(poseStack, humanoidArm, h); diff --git a/src/main/java/wily/legacy/mixin/base/ItemStackMixin.java b/src/main/java/wily/legacy/mixin/base/ItemStackMixin.java index 189e870..419b471 100644 --- a/src/main/java/wily/legacy/mixin/base/ItemStackMixin.java +++ b/src/main/java/wily/legacy/mixin/base/ItemStackMixin.java @@ -71,12 +71,12 @@ private void replaceNeoForgeAttributesEvent(ItemStack stack, Consumer @Redirect(method = "addModifierTooltip", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/ai/attributes/AttributeModifier;is(Lnet/minecraft/resources/ResourceLocation;)Z")) private boolean addModifierTooltip(AttributeModifier instance, ResourceLocation location) { - return !LegacyConfig.legacyCombat.get() && instance.is(location); + return !LegacyConfig.hasCommonConfigEnabled(LegacyConfig.legacyCombat) && instance.is(location); } @Inject(method = "addModifierTooltip", at = @At("HEAD"), cancellable = true) private void addModifierTooltip(Consumer consumer, Player player, Holder holder, AttributeModifier attributeModifier, CallbackInfo ci) { - if (LegacyConfig.legacyCombat.get() && attributeModifier.is(Item.BASE_ATTACK_SPEED_ID)) ci.cancel(); + if (LegacyConfig.hasCommonConfigEnabled(LegacyConfig.legacyCombat) && attributeModifier.is(Item.BASE_ATTACK_SPEED_ID)) ci.cancel(); } @Redirect(method = "addModifierTooltip", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/ai/attributes/AttributeModifier;amount()D")) @@ -96,7 +96,7 @@ private void addAttributeTooltips(ItemStack instance, EquipmentSlotGroup equipme forEachModifier(equipmentSlotGroup, (holder, attributeModifier)->{ if (noSpace.get()){ consumer.accept(CommonComponents.EMPTY); - if (!LegacyConfig.legacyCombat.get()) consumer.accept(Component.translatable("item.modifiers." + equipmentSlotGroup.getSerializedName()).withStyle(ChatFormatting.GRAY)); + if (!LegacyConfig.hasCommonConfigEnabled(LegacyConfig.legacyCombat)) consumer.accept(Component.translatable("item.modifiers." + equipmentSlotGroup.getSerializedName()).withStyle(ChatFormatting.GRAY)); noSpace.set(false); } this.addModifierTooltip(consumer, player, holder, attributeModifier); diff --git a/src/main/java/wily/legacy/mixin/base/LivingEntityMixin.java b/src/main/java/wily/legacy/mixin/base/LivingEntityMixin.java index b2cbaad..1b98f07 100644 --- a/src/main/java/wily/legacy/mixin/base/LivingEntityMixin.java +++ b/src/main/java/wily/legacy/mixin/base/LivingEntityMixin.java @@ -61,6 +61,6 @@ public void isBlocking(CallbackInfoReturnable cir) { //?} @Inject(method = "getDamageAfterArmorAbsorb", at = @At("RETURN"), cancellable = true) protected void getDamageAfterArmorAbsorb(DamageSource damageSource, float f, CallbackInfoReturnable cir) { - if (!damageSource.is(DamageTypeTags.BYPASSES_ARMOR) && LegacyConfig.legacySwordBlocking.get() && useItem.getItem() instanceof SwordItem) cir.setReturnValue(cir.getReturnValue()/2); + if (!damageSource.is(DamageTypeTags.BYPASSES_ARMOR) && LegacyConfig.hasCommonConfigEnabled(LegacyConfig.legacySwordBlocking) && useItem.getItem() instanceof SwordItem) cir.setReturnValue(cir.getReturnValue()/2); } } diff --git a/src/main/java/wily/legacy/mixin/base/PlayerMixin.java b/src/main/java/wily/legacy/mixin/base/PlayerMixin.java index 1be9aaa..308d701 100644 --- a/src/main/java/wily/legacy/mixin/base/PlayerMixin.java +++ b/src/main/java/wily/legacy/mixin/base/PlayerMixin.java @@ -66,7 +66,7 @@ public void aiStep(CallbackInfo ci) { @Inject(method = "resetAttackStrengthTicker", at = @At(value = "HEAD"), cancellable = true) protected void resetAttackStrengthTicker(CallbackInfo ci) { - if (LegacyConfig.legacyCombat.get()) ci.cancel(); + if (LegacyConfig.hasCommonConfigEnabled(LegacyConfig.legacyCombat)) ci.cancel(); } @Redirect(method = "attack", at = @At(value = "INVOKE", target = /*? if <1.20.5 {*//*"Lnet/minecraft/world/entity/player/Player;getAttributeValue(Lnet/minecraft/world/entity/ai/attributes/Attribute;)D"*//*?} else {*/"Lnet/minecraft/world/entity/player/Player;getAttributeValue(Lnet/minecraft/core/Holder;)D"/*?}*/)) @@ -76,7 +76,7 @@ protected double modifyAttackDamage(Player instance,/*? if <1.20.5 {*//*Attribut @ModifyVariable(method = "attack", at = @At(value = "STORE"), ordinal = 3) protected boolean modifyAttackDamage(boolean original) { - return !LegacyConfig.legacyCombat.get() && original; + return !LegacyConfig.hasCommonConfigEnabled(LegacyConfig.legacyCombat) && original; } } diff --git a/src/main/java/wily/legacy/mixin/base/SwordItemMixin.java b/src/main/java/wily/legacy/mixin/base/SwordItemMixin.java index 24462c6..1519be0 100644 --- a/src/main/java/wily/legacy/mixin/base/SwordItemMixin.java +++ b/src/main/java/wily/legacy/mixin/base/SwordItemMixin.java @@ -23,13 +23,13 @@ public SwordItemMixin(Properties properties) { @Override public int getUseDuration(ItemStack itemStack/*? if >=1.20.5 {*/, LivingEntity livingEntity/*?}*/) { - if (LegacyConfig.legacySwordBlocking.get()) return 7200; + if (LegacyConfig.hasCommonConfigEnabled(LegacyConfig.legacySwordBlocking)) return 7200; return super.getUseDuration(itemStack/*? if >=1.20.5 {*/, livingEntity/*?}*/); } //? <=1.21.1 { public InteractionResultHolder use(Level level, Player player, InteractionHand interactionHand) { - if (LegacyConfig.legacySwordBlocking.get()) { + if (LegacyConfig.hasCommonConfigEnabled(LegacyConfig.legacySwordBlocking)) { player.startUsingItem(interactionHand); return InteractionResultHolder.consume( player.getItemInHand(interactionHand)); } @@ -47,7 +47,7 @@ public InteractionResultHolder use(Level level, Player player, Intera @Override public /*? if <1.21.2 {*/UseAnim/*?} else {*//*ItemUseAnimation*//*?}*/ getUseAnimation(ItemStack itemStack) { - if (LegacyConfig.legacySwordBlocking.get()) return /*? if <1.21.2 {*/UseAnim/*?} else {*//*ItemUseAnimation*//*?}*/.BLOCK; + if (LegacyConfig.hasCommonConfigEnabled(LegacyConfig.legacySwordBlocking)) return /*? if <1.21.2 {*/UseAnim/*?} else {*//*ItemUseAnimation*//*?}*/.BLOCK; return super.getUseAnimation(itemStack); } } diff --git a/src/main/java/wily/legacy/mixin/base/client/gui/GuiMixin.java b/src/main/java/wily/legacy/mixin/base/client/gui/GuiMixin.java index cbaf584..c09cca9 100644 --- a/src/main/java/wily/legacy/mixin/base/client/gui/GuiMixin.java +++ b/src/main/java/wily/legacy/mixin/base/client/gui/GuiMixin.java @@ -76,7 +76,6 @@ @Mixin(Gui.class) - public abstract class GuiMixin implements ControlTooltip.Event { @Shadow @Final private Minecraft minecraft; @@ -108,14 +107,14 @@ public void renderVignette(GuiGraphics guiGraphics, Entity entity, CallbackInfo ci.cancel(); } - @Redirect(method = "renderCrosshair", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/OptionInstance;get()Ljava/lang/Object;")) + @Redirect(method = "renderCrosshair", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/OptionInstance;get()Ljava/lang/Object;", ordinal = 1)) public Object renderCrosshair(OptionInstance instance) { - return LegacyConfig.legacyCombat.get() ? AttackIndicatorStatus.OFF : instance.get(); + return LegacyConfig.hasCommonConfigEnabled(LegacyConfig.legacyCombat) ? AttackIndicatorStatus.OFF : instance.get(); } @Redirect(method = /*? if >=1.20.5 {*/"renderItemHotbar"/*?} else {*//*"renderHotbar"*//*?}*/, at = @At(value = "INVOKE", target = "Lnet/minecraft/client/OptionInstance;get()Ljava/lang/Object;")) public Object renderItemHotbar(OptionInstance instance) { - return LegacyConfig.legacyCombat.get() ? AttackIndicatorStatus.OFF : instance.get(); + return LegacyConfig.hasCommonConfigEnabled(LegacyConfig.legacyCombat) ? AttackIndicatorStatus.OFF : instance.get(); } @Inject(method = "renderCrosshair", at = @At("HEAD"), cancellable = true)