Skip to content

Commit

Permalink
Added a couple options on NoSlow module. (CCBlueX#641)
Browse files Browse the repository at this point in the history
* Added a couple options on NoSlow module.

* Improved description.
  • Loading branch information
mems01 authored Oct 17, 2021
1 parent 5121990 commit 1e1dd6c
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package net.ccbluex.liquidbounce.injection.mixins.minecraft.block;

import net.ccbluex.liquidbounce.event.BlockSlipperinessMultiplierEvent;
import net.ccbluex.liquidbounce.event.BlockVelocityMultiplierEvent;
import net.ccbluex.liquidbounce.event.EventManager;
import net.minecraft.block.Block;
Expand All @@ -39,4 +40,14 @@ private void hookVelocityMultiplier(CallbackInfoReturnable<Float> callback) {
callback.setReturnValue(multiplierEvent.getMultiplier());
}

/**
* Hook slipperiness multiplier event
*/
@Inject(method = "getSlipperiness", at = @At("RETURN"), cancellable = true)
private void hookSlipperinessMultiplier(CallbackInfoReturnable<Float> cir) {
final BlockSlipperinessMultiplierEvent slipperinessEvent = new BlockSlipperinessMultiplierEvent((Block) (Object) this, cir.getReturnValue());
EventManager.INSTANCE.callEvent(slipperinessEvent);
cir.setReturnValue(slipperinessEvent.getSlipperiness());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package net.ccbluex.liquidbounce.injection.mixins.minecraft.block;

import net.ccbluex.liquidbounce.features.module.modules.movement.ModuleNoSlow;
import net.minecraft.block.BlockState;
import net.minecraft.block.PowderSnowBlock;
import net.minecraft.entity.Entity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
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.CallbackInfo;

@Mixin(PowderSnowBlock.class)
public class MixinPowderSnowBlock {

@Inject(method = "onEntityCollision", at = @At("HEAD"), cancellable = true)
private void hookEntityCollision(BlockState state, World world, BlockPos pos, Entity entity, CallbackInfo ci) {
if (ModuleNoSlow.INSTANCE.getEnabled() && ModuleNoSlow.PowderSnow.INSTANCE.getEnabled()) {
ci.cancel();
entity.setVelocity(entity.getVelocity().x * ModuleNoSlow.PowderSnow.INSTANCE.getMultiplier(), entity.getVelocity().y, entity.getVelocity().z * ModuleNoSlow.PowderSnow.INSTANCE.getMultiplier());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package net.ccbluex.liquidbounce.injection.mixins.minecraft.block;

import net.ccbluex.liquidbounce.features.module.modules.movement.ModuleNoSlow;
import net.minecraft.block.BlockState;
import net.minecraft.block.SlimeBlock;
import net.minecraft.entity.Entity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
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.CallbackInfo;

@Mixin(SlimeBlock.class)
public class MixinSlimeBlock {

@Inject(method = "bounce", at = @At("HEAD"), cancellable = true)
private void hookBounce(Entity entity, CallbackInfo ci) {
if (ModuleNoSlow.INSTANCE.getEnabled() && ModuleNoSlow.Slime.INSTANCE.getEnabled()) {
if (entity.getVelocity().y == -0.0784000015258789 || entity.getVelocity().y == -0.001567998535156222) {
ci.cancel();
}
}
}

@Inject(method = "onSteppedOn", at = @At("HEAD"), cancellable = true)
private void hookStep(World world, BlockPos pos, BlockState state, Entity entity, CallbackInfo ci) {
if (ModuleNoSlow.INSTANCE.getEnabled() && ModuleNoSlow.Slime.INSTANCE.getEnabled()) {
ci.cancel();
}
}
}
3 changes: 3 additions & 0 deletions src/main/kotlin/net/ccbluex/liquidbounce/event/Events.kt
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ class BlockAttackEvent(val pos: BlockPos) : Event()
@Nameable("blockMultiplier")
class BlockVelocityMultiplierEvent(val block: Block, var multiplier: Float) : Event()

@Nameable("blockSlipperinessMultiplier")
class BlockSlipperinessMultiplierEvent(val block: Block, var slipperiness: Float) : Event()

// Entity events

@Nameable("entityMargin")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import net.ccbluex.liquidbounce.config.ToggleableConfigurable
import net.ccbluex.liquidbounce.event.*
import net.ccbluex.liquidbounce.features.module.Category
import net.ccbluex.liquidbounce.features.module.Module
import net.minecraft.block.HoneyBlock
import net.minecraft.block.SlimeBlock
import net.minecraft.block.SoulSandBlock
import net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket
import net.minecraft.network.packet.c2s.play.PlayerInteractItemC2SPacket
Expand All @@ -33,7 +35,7 @@ import net.minecraft.util.math.Direction
/**
* NoSlow module
*
* Cancels slowness effects caused by soulsand and using items.
* Cancels slowness effects caused by blocks and using items.
*/

object ModuleNoSlow : Module("NoSlow", Category.MOVEMENT) {
Expand Down Expand Up @@ -75,19 +77,53 @@ object ModuleNoSlow : Module("NoSlow", Category.MOVEMENT) {

val multiplier by float("Multiplier", 1f, 0.4f..2f)

val blockVecocityHandler = handler<BlockVelocityMultiplierEvent> { event ->
val blockVelocityHandler = handler<BlockVelocityMultiplierEvent> { event ->
if (event.block is SoulSandBlock) {
event.multiplier = multiplier
}
}

}

object Slime : ToggleableConfigurable(this, "SlimeBlock", true) {
val multiplier by float("Multiplier", 1f, 0.4f..2f)

val blockSlipperinessMultiplierHandler = handler<BlockSlipperinessMultiplierEvent> { event ->
if (event.block is SlimeBlock) {
event.slipperiness = 0.6f
}
}

val blockVelocityHandler = handler<BlockVelocityMultiplierEvent> { event ->
if (event.block is SlimeBlock) {
event.multiplier = multiplier
}
}
}

private object Honey : ToggleableConfigurable(this, "HoneyBlock", true) {
val multiplier by float("Multiplier", 1f, 0.4f..2f)

val blockVelocityHandler = handler<BlockVelocityMultiplierEvent> { event ->
if (event.block is HoneyBlock) {
event.multiplier = multiplier
}
}
}

object PowderSnow : ToggleableConfigurable(this, "PowderSnow", true) {
val multiplier by float("Multiplier", 1f, 0.4f..2f)
}


init {
tree(Block)
tree(Consume)
tree(Bow)
tree(Soulsand)
tree(Slime)
tree(Honey)
tree(PowderSnow)
}

val multiplierHandler = handler<PlayerUseMultiplier> { event ->
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/assets/liquidbounce/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@

"liquidbounce.module.fastUse.description": "Allows you to use items faster.",

"liquidbounce.module.noSlow.description": "Cancels slowness effects caused by soulsand and using items.",
"liquidbounce.module.noSlow.description": "Cancels slowness effects caused by blocks and using items.",

"liquidbounce.module.highJump.description": "Allows you to jump higher.",

Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/liquidbounce.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
"minecraft.block.MixinCobwebBlock",
"minecraft.block.MixinFluidBlock",
"minecraft.block.MixinSnowBlock",
"minecraft.block.MixinSlimeBlock",
"minecraft.block.MixinPowderSnowBlock",
"minecraft.client.MixinClientWorld",
"minecraft.client.MixinInput",
"minecraft.client.MixinKeyboard",
Expand Down

0 comments on commit 1e1dd6c

Please sign in to comment.