-
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6641f45
commit 153ae7a
Showing
10 changed files
with
325 additions
and
126 deletions.
There are no files selected for viewing
94 changes: 94 additions & 0 deletions
94
...on/viafabricplus/injection/mixin/features/block/mining_calculation/MixinPlayerEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* This file is part of ViaFabricPlus - https://github.com/ViaVersion/ViaFabricPlus | ||
* Copyright (C) 2021-2025 the original authors | ||
* - FlorianMichael/EnZaXD <[email protected]> | ||
* - RK_01/RaphiMC | ||
* Copyright (C) 2023-2025 ViaVersion and contributors | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.viaversion.viafabricplus.injection.mixin.features.block.mining_calculation; | ||
|
||
import com.llamalad7.mixinextras.sugar.Local; | ||
import com.llamalad7.mixinextras.sugar.ref.LocalFloatRef; | ||
import com.viaversion.viafabricplus.protocoltranslator.ProtocolTranslator; | ||
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.entity.EntityType; | ||
import net.minecraft.entity.LivingEntity; | ||
import net.minecraft.entity.attribute.EntityAttributes; | ||
import net.minecraft.entity.effect.StatusEffect; | ||
import net.minecraft.entity.effect.StatusEffects; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.entity.player.PlayerInventory; | ||
import net.minecraft.registry.entry.RegistryEntry; | ||
import net.minecraft.world.World; | ||
import net.raphimc.vialegacy.api.LegacyProtocolVersion; | ||
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.Redirect; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
@Mixin(PlayerEntity.class) | ||
public abstract class MixinPlayerEntity extends LivingEntity { | ||
|
||
@Shadow @Final private PlayerInventory inventory; | ||
|
||
@Shadow public abstract boolean canHarvest(BlockState state); | ||
|
||
protected MixinPlayerEntity(EntityType<? extends LivingEntity> entityType, World world) { | ||
super(entityType, world); | ||
} | ||
|
||
@Redirect(method = "getBlockBreakingSpeed", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;hasStatusEffect(Lnet/minecraft/registry/entry/RegistryEntry;)Z")) | ||
private boolean changeSpeedCalculation(PlayerEntity instance, RegistryEntry<StatusEffect> statusEffect, @Local LocalFloatRef f) { | ||
final boolean hasMiningFatigue = instance.hasStatusEffect(statusEffect); | ||
if (hasMiningFatigue && ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_7_6)) { | ||
f.set(f.get() * (1.0F - (this.getStatusEffect(StatusEffects.MINING_FATIGUE).getAmplifier() + 1) * 0.2F)); | ||
if (f.get() < 0) { | ||
f.set(0); | ||
} | ||
return false; // disable original code | ||
} | ||
return hasMiningFatigue; | ||
} | ||
|
||
@Inject(method = "getBlockBreakingSpeed", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/effect/StatusEffectUtil;hasHaste(Lnet/minecraft/entity/LivingEntity;)Z", shift = At.Shift.BEFORE)) | ||
private void changeSpeedCalculation(BlockState block, CallbackInfoReturnable<Float> cir, @Local LocalFloatRef f) { | ||
final float efficiency = (float) this.getAttributeValue(EntityAttributes.MINING_EFFICIENCY); | ||
if (efficiency <= 0) { | ||
return; | ||
} | ||
|
||
final float speed = this.inventory.getBlockBreakingSpeed(block); | ||
if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(LegacyProtocolVersion.r1_4_4tor1_4_5) && this.canHarvest(block)) { | ||
f.set(speed + efficiency); | ||
} else if (speed > 1F || ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(LegacyProtocolVersion.r1_4_6tor1_4_7)) { | ||
if (!this.getMainHandStack().isEmpty()) { | ||
if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_7_6)) { | ||
if (speed <= 1.0 && !this.canHarvest(block)) { | ||
f.set(speed + efficiency * 0.08F); | ||
} else { | ||
f.set(speed + efficiency); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
...viafabricplus/injection/mixin/features/interaction/attack_cooldown/MixinPlayerEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* This file is part of ViaFabricPlus - https://github.com/ViaVersion/ViaFabricPlus | ||
* Copyright (C) 2021-2025 the original authors | ||
* - FlorianMichael/EnZaXD <[email protected]> | ||
* - RK_01/RaphiMC | ||
* Copyright (C) 2023-2025 ViaVersion and contributors | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.viaversion.viafabricplus.injection.mixin.features.interaction.attack_cooldown; | ||
|
||
import com.viaversion.viafabricplus.protocoltranslator.ProtocolTranslator; | ||
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
@Mixin(PlayerEntity.class) | ||
public abstract class MixinPlayerEntity { | ||
|
||
@Inject(method = "getAttackCooldownProgress", at = @At("HEAD"), cancellable = true) | ||
private void removeAttackCooldown(CallbackInfoReturnable<Float> ci) { | ||
if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_8)) { | ||
ci.setReturnValue(1F); | ||
} | ||
} | ||
|
||
} |
63 changes: 63 additions & 0 deletions
63
...aversion/viafabricplus/injection/mixin/features/movement/constants/MixinLivingEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* This file is part of ViaFabricPlus - https://github.com/ViaVersion/ViaFabricPlus | ||
* Copyright (C) 2021-2025 the original authors | ||
* - FlorianMichael/EnZaXD <[email protected]> | ||
* - RK_01/RaphiMC | ||
* Copyright (C) 2023-2025 ViaVersion and contributors | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.viaversion.viafabricplus.injection.mixin.features.movement.constants; | ||
|
||
import com.llamalad7.mixinextras.injector.ModifyExpressionValue; | ||
import com.viaversion.viafabricplus.protocoltranslator.ProtocolTranslator; | ||
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; | ||
import net.minecraft.entity.LivingEntity; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Constant; | ||
import org.spongepowered.asm.mixin.injection.ModifyConstant; | ||
|
||
@Mixin(LivingEntity.class) | ||
public abstract class MixinLivingEntity { | ||
|
||
@ModifyExpressionValue(method = "tickStatusEffects", at = @At(value = "CONSTANT", args = "intValue=4")) | ||
private int changeParticleDensity(int original) { | ||
if (ProtocolTranslator.getTargetVersion().olderThan(ProtocolVersion.v1_20_5)) { | ||
return 2; | ||
} else { | ||
return original; | ||
} | ||
} | ||
|
||
@ModifyConstant(method = "getBlockingItem", constant = @Constant(intValue = 5)) | ||
private int removeBlockActionUseDelay(int constant) { | ||
if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_8)) { | ||
return 0; | ||
} else { | ||
return constant; | ||
} | ||
} | ||
|
||
@ModifyConstant(method = "tickMovement", constant = @Constant(doubleValue = 0.003D)) | ||
private double modifyVelocityZero(double constant) { | ||
if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_8)) { | ||
return 0.005D; | ||
} else { | ||
return constant; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.