-
Notifications
You must be signed in to change notification settings - Fork 11
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
c1b04ee
commit ba2a947
Showing
15 changed files
with
171 additions
and
25 deletions.
There are no files selected for viewing
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
15 changes: 15 additions & 0 deletions
15
src/main/java/net/zepalesque/redux/client/event/hook/KeyHooks.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,15 @@ | ||
package net.zepalesque.redux.client.event.hook; | ||
|
||
import net.minecraft.client.KeyMapping; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.ToggleKeyMapping; | ||
import net.minecraft.world.entity.LivingEntity; | ||
|
||
public class KeyHooks { | ||
|
||
public static void cancelKey(final LivingEntity entity, KeyMapping key) { | ||
if (entity == Minecraft.getInstance().player) { | ||
ToggleKeyMapping.set(key.getKey(), false); | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/net/zepalesque/redux/client/event/listener/ClientMobListener.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,20 @@ | ||
package net.zepalesque.redux.client.event.listener; | ||
|
||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.world.entity.LivingEntity; | ||
import net.neoforged.bus.api.SubscribeEvent; | ||
import net.neoforged.neoforge.event.entity.living.LivingEvent; | ||
import net.zepalesque.redux.client.event.hook.KeyHooks; | ||
import net.zepalesque.redux.config.ReduxConfig; | ||
import net.zepalesque.redux.event.hook.QuicksoilHooks; | ||
|
||
public class ClientMobListener { | ||
|
||
@SubscribeEvent | ||
public static void cancelSneak(LivingEvent.LivingTickEvent event) { | ||
final LivingEntity entity = event.getEntity(); | ||
if (ReduxConfig.SERVER.revamped_quicksoil_movement.get() && QuicksoilHooks.shouldAlterMovement(entity)) { | ||
KeyHooks.cancelKey(entity, Minecraft.getInstance().options.keyShift); | ||
} | ||
} | ||
} |
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
28 changes: 28 additions & 0 deletions
28
src/main/java/net/zepalesque/redux/event/hook/QuicksoilHooks.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,28 @@ | ||
package net.zepalesque.redux.event.hook; | ||
|
||
import net.minecraft.util.Mth; | ||
import net.minecraft.world.entity.LivingEntity; | ||
import net.zepalesque.redux.data.ReduxTags; | ||
import net.zepalesque.redux.mixin.mixins.common.accessor.EntityAccessor; | ||
|
||
public class QuicksoilHooks { | ||
|
||
public static boolean shouldAlterMovement(final LivingEntity entity) { | ||
return entity.onGround() && | ||
!entity.isInWater() && | ||
!(Math.abs(entity.getDeltaMovement().x + entity.getDeltaMovement().y + entity.getDeltaMovement().z) < 0.001D) && | ||
!entity.isSpectator() | ||
&& entity.level().getBlockState(((EntityAccessor) entity).callGetBlockPosBelowThatAffectsMyMovement()).is(ReduxTags.Blocks.QUICKSOIL_BEHAVIOR); | ||
} | ||
|
||
public static void alterMovement(final LivingEntity entity) { | ||
entity.setDeltaMovement(entity.getDeltaMovement().multiply(1.7D, 1D, 1.7D)); | ||
final double maxMotion = 1D; | ||
double x; | ||
double z; | ||
|
||
x = Mth.clamp(entity.getDeltaMovement().x, -maxMotion, maxMotion); | ||
z = Mth.clamp(entity.getDeltaMovement().z, -maxMotion, maxMotion); | ||
entity.setDeltaMovement(x, entity.getDeltaMovement().y, z); | ||
} | ||
} |
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
21 changes: 21 additions & 0 deletions
21
src/main/java/net/zepalesque/redux/event/listener/MobListener.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,21 @@ | ||
package net.zepalesque.redux.event.listener; | ||
|
||
import net.minecraft.world.entity.LivingEntity; | ||
import net.neoforged.bus.api.SubscribeEvent; | ||
import net.neoforged.fml.common.Mod; | ||
import net.neoforged.neoforge.event.entity.living.LivingEvent; | ||
import net.zepalesque.redux.Redux; | ||
import net.zepalesque.redux.config.ReduxConfig; | ||
import net.zepalesque.redux.event.hook.QuicksoilHooks; | ||
|
||
@Mod.EventBusSubscriber(modid = Redux.MODID) | ||
public class MobListener { | ||
|
||
@SubscribeEvent | ||
public static void handleQuicksoilMovement(LivingEvent.LivingTickEvent event) { | ||
final LivingEntity entity = event.getEntity(); | ||
if (ReduxConfig.SERVER.revamped_quicksoil_movement.get() && QuicksoilHooks.shouldAlterMovement(entity)) { | ||
QuicksoilHooks.alterMovement(entity); | ||
} | ||
} | ||
} |
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
40 changes: 40 additions & 0 deletions
40
src/main/java/net/zepalesque/redux/mixin/mixins/common/QuicksoilMixin.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,40 @@ | ||
package net.zepalesque.redux.mixin.mixins.common; | ||
|
||
import com.aetherteam.aether.block.natural.QuicksoilBlock; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.world.entity.Entity; | ||
import net.minecraft.world.entity.vehicle.Boat; | ||
import net.minecraft.world.level.BlockGetter; | ||
import net.minecraft.world.level.LevelReader; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraft.world.level.pathfinder.PathComputationType; | ||
import net.zepalesque.redux.config.ReduxConfig; | ||
import net.zepalesque.redux.mixin.mixins.common.base.BlockBehaviorMixin; | ||
import net.zepalesque.redux.mixin.mixins.common.base.BlockMixin; | ||
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(QuicksoilBlock.class) | ||
public class QuicksoilMixin extends BlockBehaviorMixin { | ||
|
||
@Override | ||
public void redux$pathFindable(BlockState state, BlockGetter level, BlockPos pos, PathComputationType type, CallbackInfoReturnable<Boolean> cir) { | ||
if (ReduxConfig.SERVER.revamped_quicksoil_movement.get() && type == PathComputationType.LAND) { | ||
cir.setReturnValue(false); | ||
} | ||
} | ||
|
||
|
||
@Inject(method = "getFriction", at = @At("HEAD"), cancellable = true) | ||
public void redux$getFriction(BlockState state, LevelReader level, BlockPos pos, Entity entity, CallbackInfoReturnable<Float> cir) { | ||
if (ReduxConfig.SERVER.revamped_quicksoil_movement.get()) { | ||
if (entity instanceof Boat) { | ||
cir.setReturnValue(0.8F); | ||
return; | ||
} | ||
cir.setReturnValue(0.6F); | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/net/zepalesque/redux/mixin/mixins/common/accessor/EntityAccessor.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,12 @@ | ||
package net.zepalesque.redux.mixin.mixins.common.accessor; | ||
|
||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.world.entity.Entity; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.gen.Invoker; | ||
|
||
@Mixin(Entity.class) | ||
public interface EntityAccessor { | ||
@Invoker | ||
BlockPos callGetBlockPosBelowThatAffectsMyMovement(); | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/net/zepalesque/redux/mixin/mixins/common/base/BlockBehaviorMixin.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,18 @@ | ||
package net.zepalesque.redux.mixin.mixins.common.base; | ||
|
||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.world.level.BlockGetter; | ||
import net.minecraft.world.level.block.state.BlockBehaviour; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraft.world.level.pathfinder.PathComputationType; | ||
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(BlockBehaviour.class) | ||
public class BlockBehaviorMixin { | ||
|
||
@Inject(method = "isPathfindable", at = @At("HEAD"), cancellable = true) | ||
public void redux$pathFindable(BlockState state, BlockGetter level, BlockPos pos, PathComputationType type, CallbackInfoReturnable<Boolean> cir) {} | ||
} |
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