Skip to content

Commit

Permalink
Merge branch '1.20.1/dev' into 1.20.1/fabric
Browse files Browse the repository at this point in the history
  • Loading branch information
bibi-reden committed Oct 26, 2024
2 parents 0555f40 + a7785c4 commit a1a33fe
Show file tree
Hide file tree
Showing 15 changed files with 171 additions and 111 deletions.
11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
**Ensure you back up your playerex config before updating to this version and using it!**

## Additions 💖
- Added a `LifecycleConfig` enum on the playerex config: `ON_TICK` | `ON_EVERY_SECOND`.
- This has been applied to Health Regeneration, and you can adjust it in the config. Default is `ON_EVERY_SECOND`.

## Changes 🌽
- Resolved an issue with `ON_TICK` and renamed it to `ON_EVERY_SECOND`.
- The counter to reset was not present, but this has been fixed now.
- Rearranged the config in its entirety.
- Everything is nested and opened by default.
- Everything labeled in `AdvancedSettings` has been adjusted to reflect better in their respective components internally.
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ loader=fabric

# Fabric Properties
minecraft_version=1.20.1
loader_version=0.15.11
fabric_kotlin_version=1.12.0+kotlin.2.0.10
loader_version=0.16.7
fabric_kotlin_version=1.12.3+kotlin.2.0.21
loom_version=1.8-SNAPSHOT

# Mappings
parchment_version=1.20.1:2023.09.03
quilt_mappings_version=23

# Mod Properties
mod_version=4.0.0+1.20.1-beta.10
mod_version=4.0.0+1.20.1-beta.11
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 @@ -18,7 +18,7 @@
@Mixin(EntityRenderer.class)
abstract class EntityRendererMixin<T extends Entity> {
@Unique
private boolean playerex$shouldRenderLevel() { return PlayerEX.CONFIG.getShowLevelOnNameplates(); }
private boolean playerex$shouldRenderLevel() { return PlayerEX.CONFIG.getVisualSettings().getShowLevelOnNameplates(); }

@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) {
Expand Down
2 changes: 1 addition & 1 deletion src/client/kotlin/com/bibireden/playerex/PlayerEXClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ object PlayerEXClient : ClientModInitializer {
PlayerEXMenuRegistry.register(PlayerEX.id("attributes"), PlayerEXAttributesMenu::class.java)

ClientTickEvents.END_CLIENT_TICK.register { client ->
if (PlayerEX.CONFIG.disableUI) return@register
if (PlayerEX.CONFIG.featureSettings.disableUI) return@register

while (KEYBINDING_MAIN_SCREEN.consumeClick()) {
if (client.screen == null) client.setScreen(PlayerEXScreen())
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/com/bibireden/playerex/mixin/ItemStackMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ abstract class ItemStackMixin {

@Inject(method = "use(Lnet/minecraft/world/level/Level;Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/world/InteractionHand;)Lnet/minecraft/world/InteractionResultHolder;", at = @At(value = "HEAD"), cancellable = true)
public void preventUse(Level level, Player player, InteractionHand usedHand, CallbackInfoReturnable<InteractionResultHolder<ItemStack>> cir) {
if (!PlayerEX.CONFIG.getItemBreakingEnabled()) return;
if (!PlayerEX.CONFIG.getFeatureSettings().getItemBreakingEnabled()) return;

ItemStack stack = (ItemStack)(Object)this;
if (PlayerEXUtil.isBroken(stack)) {
Expand All @@ -62,7 +62,7 @@ public void preventUse(Level level, Player player, InteractionHand usedHand, Cal

@Inject(method = "useOn(Lnet/minecraft/world/item/context/UseOnContext;)Lnet/minecraft/world/InteractionResult;", at = @At(value = "HEAD"), cancellable = true)
public void preventUseOnBlock(UseOnContext context, CallbackInfoReturnable<InteractionResult> cir) {
if (!PlayerEX.CONFIG.getItemBreakingEnabled()) return;
if (!PlayerEX.CONFIG.getFeatureSettings().getItemBreakingEnabled()) return;

ItemStack stack = (ItemStack)(Object)this;
if (PlayerEXUtil.isBroken(stack)) {
Expand All @@ -72,7 +72,7 @@ public void preventUseOnBlock(UseOnContext context, CallbackInfoReturnable<Inter

@Inject(method = "hurt(ILnet/minecraft/util/RandomSource;Lnet/minecraft/server/level/ServerPlayer;)Z", at = @At(value = "HEAD"), cancellable = true)
public void preventDamage(int amount, RandomSource random, ServerPlayer user, CallbackInfoReturnable<Boolean> cir) {
if (!PlayerEX.CONFIG.getItemBreakingEnabled()) return;
if (!PlayerEX.CONFIG.getFeatureSettings().getItemBreakingEnabled()) return;

ItemStack stack = (ItemStack)(Object)this;
if (PlayerEXUtil.isBroken(stack)) {
Expand All @@ -82,7 +82,7 @@ public void preventDamage(int amount, RandomSource random, ServerPlayer user, Ca

@Inject(method = "hurtAndBreak(ILnet/minecraft/world/entity/LivingEntity;Ljava/util/function/Consumer;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/ItemStack;getItem()Lnet/minecraft/world/item/Item;"), cancellable = true)
public <T extends LivingEntity> void preventBreak(int amount, T entity, Consumer<T> onBroken, CallbackInfo ci) {
if (!PlayerEX.CONFIG.getItemBreakingEnabled()) return;
if (!PlayerEX.CONFIG.getFeatureSettings().getItemBreakingEnabled()) return;

ItemStack stack = (ItemStack)(Object)this;
if (stack.getItem().builtInRegistryHolder().is(PlayerEXTags.UNBREAKABLE_ITEMS)) {
Expand All @@ -97,7 +97,7 @@ public <T extends LivingEntity> void preventBreak(int amount, T entity, Consumer

@Inject(method = "setDamageValue(I)V", at = @At(value = "HEAD"))
public void removeBrokenOnRepair(int damage, CallbackInfo ci) {
if (!PlayerEX.CONFIG.getItemBreakingEnabled()) return;
if (!PlayerEX.CONFIG.getFeatureSettings().getItemBreakingEnabled()) return;

ItemStack stack = (ItemStack)(Object)this;
if (PlayerEXUtil.isBroken(stack) && damage < stack.getDamageValue()) {
Expand All @@ -109,7 +109,7 @@ public void removeBrokenOnRepair(int damage, CallbackInfo ci) {

@Inject(method = "getAttributeModifiers(Lnet/minecraft/world/entity/EquipmentSlot;)Lcom/google/common/collect/Multimap;", at = @At(value = "RETURN"), cancellable = true)
public void preventArmour(EquipmentSlot slot, CallbackInfoReturnable<Multimap<Attribute, AttributeModifier>> cir) {
if (!PlayerEX.CONFIG.getItemBreakingEnabled()) return;
if (!PlayerEX.CONFIG.getFeatureSettings().getItemBreakingEnabled()) return;

ItemStack stack = (ItemStack)(Object)this;
HashMultimap<Attribute, AttributeModifier> hashmap = HashMultimap.create(cir.getReturnValue());
Expand All @@ -125,7 +125,7 @@ public void preventArmour(EquipmentSlot slot, CallbackInfoReturnable<Multimap<At

@Unique
private double playerex$modifyValue(double val, @Nullable Player player, Attribute attribute, UUID uuid) {
if (player == null || PlayerEX.CONFIG.getTooltip() == PlayerEXConfigModel.Tooltip.Default) return val;
if (player == null || PlayerEX.CONFIG.getVisualSettings().getTooltip() == PlayerEXConfigModel.Tooltip.Default) return val;

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

Expand All @@ -137,7 +137,7 @@ public void preventArmour(EquipmentSlot slot, CallbackInfoReturnable<Multimap<At

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

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

@Unique
Expand All @@ -158,12 +158,12 @@ public void preventArmour(EquipmentSlot slot, CallbackInfoReturnable<Multimap<At

@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;
return PlayerEX.CONFIG.getVisualSettings().getTooltip() != PlayerEXConfigModel.Tooltip.Vanilla && original;
}

@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;
return PlayerEX.CONFIG.getVisualSettings().getTooltip() != PlayerEXConfigModel.Tooltip.Vanilla && original;
}

@ModifyVariable(method = "getTooltipLines", at = @At(value = "STORE", ordinal = 1), ordinal = 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@ public abstract class LivingEntityMixin {
@Unique
private int playerex_ticks;

@Unique
final int ON_EVERY_SECOND_TICKS = 20;

@Inject(method = "startUsingItem(Lnet/minecraft/world/InteractionHand;)V", at = @At(value = "HEAD"), locals = LocalCapture.CAPTURE_FAILEXCEPTION, cancellable = true)
public void preventAttack(InteractionHand hand, CallbackInfo ci) {
if (!PlayerEX.CONFIG.getItemBreakingEnabled()) return;
if (!PlayerEX.CONFIG.getFeatureSettings().getItemBreakingEnabled()) return;

LivingEntity entity = (LivingEntity)(Object)this;
if (PlayerEXUtil.isBroken(entity.getItemInHand(hand))) {
Expand All @@ -44,14 +47,14 @@ public void preventAttack(InteractionHand hand, CallbackInfo ci) {

@Inject(method = "tick", at = @At("TAIL"))
private void playerex$tick(CallbackInfo ci) {
final int TICKS_UNTIL_RESET = 20;
if (this.playerex_ticks < TICKS_UNTIL_RESET) {
if (this.playerex_ticks < ON_EVERY_SECOND_TICKS) {
this.playerex_ticks++;
}
else {
LivingEntityEvents.ON_EVERY_SECOND.invoker().onEverySecond((LivingEntity) (Object) this);
this.playerex_ticks = 0;
}
LivingEntityEvents.ON_TICK.invoker().onTick((LivingEntity) (Object) this);
}

@ModifyVariable(method = "hurt", at = @At("HEAD"), ordinal = 0, argsOnly = true)
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/bibireden/playerex/mixin/PlayerMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
public abstract class PlayerMixin {
@Inject(method = "attack(Lnet/minecraft/world/entity/Entity;)V", at = @At(value = "HEAD"), locals = LocalCapture.CAPTURE_FAILEXCEPTION, cancellable = true)
public void preventAttack(Entity target, CallbackInfo ci) {
if (!PlayerEX.CONFIG.getItemBreakingEnabled()) return;
if (!PlayerEX.CONFIG.getFeatureSettings().getItemBreakingEnabled()) return;

Player player = (Player)(Object)this;
// TODO: BetterCombat compat
Expand All @@ -33,7 +33,7 @@ public void preventAttack(Entity target, CallbackInfo ci) {

@Inject(method = "interactOn(Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/InteractionHand;)Lnet/minecraft/world/InteractionResult;", at = @At(value = "HEAD"), locals = LocalCapture.CAPTURE_FAILEXCEPTION, cancellable = true)
public void preventInteract(Entity entityToInteractOn, InteractionHand hand, CallbackInfoReturnable<InteractionResult> cir) {
if (!PlayerEX.CONFIG.getItemBreakingEnabled()) return;
if (!PlayerEX.CONFIG.getFeatureSettings().getItemBreakingEnabled()) return;

Player player = (Player)(Object)this;
if (PlayerEXUtil.isBroken(player.getItemInHand(hand))) {
Expand All @@ -43,7 +43,7 @@ public void preventInteract(Entity entityToInteractOn, InteractionHand hand, Cal

@Inject(method = "blockActionRestricted(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/GameType;)Z", at = @At(value = "HEAD"), locals = LocalCapture.CAPTURE_FAILEXCEPTION, cancellable = true)
public void preventBreakBlock(Level level, BlockPos pos, GameType gameMode, CallbackInfoReturnable<Boolean> cir) {
if (!PlayerEX.CONFIG.getItemBreakingEnabled()) return;
if (!PlayerEX.CONFIG.getFeatureSettings().getItemBreakingEnabled()) return;

Player player = (Player)(Object)this;
if (PlayerEXUtil.isBroken(player.getMainHandItem())) {
Expand Down
11 changes: 10 additions & 1 deletion src/main/kotlin/com/bibireden/playerex/PlayerEX.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import com.bibireden.playerex.api.event.LivingEntityEvents
import com.bibireden.playerex.api.event.PlayerEXSoundEvents
import com.bibireden.playerex.api.event.PlayerEntityEvents
import com.bibireden.playerex.config.PlayerEXConfig
import com.bibireden.playerex.config.PlayerEXConfigModel
import com.bibireden.playerex.config.PlayerEXConfigModel.Lifecycle
import com.bibireden.playerex.ext.component
import com.bibireden.playerex.factory.*
import com.bibireden.playerex.networking.NetworkingChannels
Expand Down Expand Up @@ -69,7 +71,14 @@ object PlayerEX : ModInitializer {
ServerPlayerEvents.COPY_FROM.register(EventFactory::reset)

LivingEntityEvents.ON_HEAL.register(EventFactory::healed)
LivingEntityEvents.ON_EVERY_SECOND.register(EventFactory::healthRegeneration)

if (CONFIG.lifecycleSettings.healthRegeneration == Lifecycle.ON_EVERY_SECOND) {
LivingEntityEvents.ON_EVERY_SECOND.register(EventFactory::healthRegeneration)
}
else {
LivingEntityEvents.ON_TICK.register(EventFactory::healthRegeneration)
}

LivingEntityEvents.ON_DAMAGE.register(EventFactory::onDamage)
LivingEntityEvents.SHOULD_DAMAGE.register(EventFactory::shouldDamage)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,28 @@ object LivingEntityEvents {
}}

/**
* Fired once at the end of {@link LivingEntity#tick()}, every 20 ticks (1 second).
* Fired once at the end of [LivingEntity.tick].
*/
@JvmField
val ON_TICK: Event<OnTick> = EventFactory.createArrayBacked(OnTick::class.java) { callbacks -> OnTick { entity -> callbacks.forEach { it.onTick(entity) } }}

/**
* Fired once at the end of [LivingEntity.tick], every `20` ticks (~1 second).
*/
@JvmField
val ON_EVERY_SECOND: Event<OnEverySecond> = EventFactory.createArrayBacked(OnEverySecond::class.java) { callbacks -> OnEverySecond { entity -> callbacks.forEach { it.onEverySecond(entity) } }}

/**
* Fired before {@link LivingEntity#damage(DamageSource, float)}; allows the amount of damage to be modified before it is used in any way.
* Can be used to perform logic prior to the damage method, and can return the original damage to avoid modifying the value.
* Fired before [LivingEntity.hurt].
*
* This allows the amount of damage to be modified before it is used in any way.
* It can be used to perform logic prior to the damage method,
* and can return the original damage to avoid modifying the value.
*
* The original value is the incoming damage, followed by the result of this event by any previous registries.
* Setting the output to 0 is an unreliable way to negate incoming damage depending on other mods installed. Instead, use {@link LivingEntityEvents#SHOUL_DAMAGE}.
*
* Setting the output to 0 is an unreliable way to negate incoming damage depending on other mods installed.
* Instead, use [LivingEntityEvents.SHOULD_DAMAGE].
*/
@JvmField
val ON_DAMAGE: Event<Damaged> = EventFactory.createArrayBacked(Damaged::class.java) { callbacks -> Damaged { entity, source, original ->
Expand All @@ -48,8 +60,12 @@ object LivingEntityEvents {
}}

/**
* Fired after: [LivingEntity.isInvulnerableTo], [net.minecraft.world.World.isClient], [LivingEntity.isDead],
* ([DamageSource.isFire] && [LivingEntity.hasStatusEffect] for Fire Resistance), and [LivingEntity.isSleeping]
* Fired after:
* - [LivingEntity.isInvulnerableTo],
* - [net.minecraft.world.World.isClient],
* - [LivingEntity.isDeadOrDying],
* - ([DamageSource] && [LivingEntity.hasEffect] for Fire Resistance), and [LivingEntity.isSleeping]
*
* is checked, but before all other logic is performed. Can be used to cancel the method and prevent damage from being taken by returning false.
* Returning true allows the logic to continue.
*/
Expand All @@ -67,6 +83,10 @@ object LivingEntityEvents {
fun shouldHeal(livingEntity: LivingEntity, original: Float): Boolean
}

fun interface OnTick {
fun onTick(livingEntity: LivingEntity)
}

fun interface OnEverySecond {
fun onEverySecond(livingEntity: LivingEntity)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,18 @@ import kotlin.math.max
import kotlin.math.min
import kotlin.random.Random

class ExperienceDataComponent(
val chunk: ChunkAccess,
private var _ticks: Int = 0,
private var _restorativeForceTicks: Int = PlayerEX.CONFIG.restorativeForceTicks,
private var _restorativeForceMultiplier: Int = PlayerEX.CONFIG.restorativeForceMultiplier,
private var _expNegationFactor: Float = 1.0F,
private var _expNegationMultiplier: Int = PlayerEX.CONFIG.expNegationFactor
) : IExperienceDataComponent {
class ExperienceDataComponent(val chunk: ChunkAccess, private var _ticks: Int = 0, private var _expNegationFactor: Float = 1.0F) : IExperienceDataComponent {
override fun updateExperienceNegationFactor(amount: Int): Boolean {
if (Random.nextFloat() > this._expNegationFactor) return true;
if (Random.nextFloat() > this._expNegationFactor) return true

val dynamicMultiplier = this._expNegationMultiplier + ((1.0F - this._expNegationMultiplier) * (1.0F - (0.1F * amount)))
val negFactor = PlayerEX.CONFIG.advancedSettings.expNegationFactor
val dynamicMultiplier = negFactor + ((1.0F - negFactor) * (1.0F - (0.1F * amount)))
this._expNegationFactor = max(this._expNegationFactor * dynamicMultiplier, 0.0F)
this.chunk.isUnsaved = true
return false
}

override fun resetExperienceNegationFactor() { this._expNegationMultiplier = 1 }
override fun resetExperienceNegationFactor() { PlayerEX.CONFIG.advancedSettings.expNegationFactor = 1 }

override fun readFromNbt(tag: CompoundTag) {
this._expNegationFactor = tag.getFloat("exp_factor")
Expand All @@ -36,10 +30,10 @@ class ExperienceDataComponent(

override fun serverTick() {
if (this._expNegationFactor == 1.0F) return
if (this._ticks < this._restorativeForceTicks) this._ticks++
if (this._ticks < PlayerEX.CONFIG.advancedSettings.restorativeForceTicks) this._ticks++
else {
this._ticks = 0
this._expNegationFactor = min(this._expNegationFactor * this._restorativeForceMultiplier, 1.0F)
this._expNegationFactor = min(this._expNegationFactor * PlayerEX.CONFIG.advancedSettings.restorativeForceMultiplier, 1.0F)
this.chunk.isUnsaved = true
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class PlayerDataComponent(

val isEnoughExperience = player.experienceLevel >= required || override
if (isEnoughExperience) {
val skillPoints = CONFIG.skillPointsPerLevelUp * amount
val skillPoints = CONFIG.levelingSettings.skillPointsPerLevelUp * amount

if (!override) player.giveExperienceLevels(-required)
this.addSkillPoints(skillPoints)
Expand Down
Loading

0 comments on commit a1a33fe

Please sign in to comment.