| 1 | package com.jellypudding.offlineclient.mixin;
|
| 2 |
|
| 3 | import com.jellypudding.offlineclient.modules.player.GhostHand;
|
| 4 | import com.jellypudding.offlineclient.modules.render.NoRender;
|
| 5 | import com.jellypudding.offlineclient.modules.render.XRay;
|
| 6 | import com.jellypudding.offlineclient.util.Modules;
|
| 7 | import net.minecraft.core.BlockPos;
|
| 8 | import net.minecraft.world.level.BlockGetter;
|
| 9 | import net.minecraft.world.level.block.state.BlockBehaviour;
|
| 10 | import net.minecraft.world.phys.Vec3;
|
| 11 | import net.minecraft.world.phys.shapes.CollisionContext;
|
| 12 | import net.minecraft.world.phys.shapes.Shapes;
|
| 13 | import net.minecraft.world.phys.shapes.VoxelShape;
|
| 14 | import org.spongepowered.asm.mixin.Mixin;
|
| 15 | import org.spongepowered.asm.mixin.Unique;
|
| 16 | import org.spongepowered.asm.mixin.injection.At;
|
| 17 | import org.spongepowered.asm.mixin.injection.Inject;
|
| 18 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
| 19 |
|
| 20 | @Mixin(BlockBehaviour.BlockStateBase.class)
|
| 21 | public abstract class BlockStateBaseMixin {
|
| 22 |
|
| 23 | // No ambient occlusion shading whilst XRay is on.
|
| 24 | @Inject(
|
| 25 | method = "getShadeBrightness(Lnet/minecraft/world/level/BlockGetter;Lnet/minecraft/core/BlockPos;)F",
|
| 26 | at = @At("RETURN"),
|
| 27 | cancellable = true)
|
| 28 | private void onGetShadeBrightness(BlockGetter level, BlockPos pos, CallbackInfoReturnable<Float> cir) {
|
| 29 | XRay xray = XRay.get();
|
| 30 | if (xray != null && xray.isEnabled()) {
|
| 31 | cir.setReturnValue(1f);
|
| 32 | }
|
| 33 | }
|
| 34 |
|
| 35 | // GhostHand empties the outline of every block it cannot open. The
|
| 36 | // crosshair then reaches the container behind the wall.
|
| 37 | @Inject(
|
| 38 | method = "getShape(Lnet/minecraft/world/level/BlockGetter;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/phys/shapes/CollisionContext;)Lnet/minecraft/world/phys/shapes/VoxelShape;",
|
| 39 | at = @At("HEAD"), cancellable = true)
|
| 40 | private void onGetShape(BlockGetter level, BlockPos pos, CollisionContext context,
|
| 41 | CallbackInfoReturnable<VoxelShape> cir) {
|
| 42 | if (context == CollisionContext.empty()) {
|
| 43 | return;
|
| 44 | }
|
| 45 | GhostHand ghostHand = Modules.get(GhostHand.class);
|
| 46 | if (ghostHand != null && ghostHand.passesThrough(pos)) {
|
| 47 | cir.setReturnValue(Shapes.empty());
|
| 48 | }
|
| 49 | }
|
| 50 |
|
| 51 | // The offset and the seed are what make grass and flowers sit differently in each spot.
|
| 52 | @Inject(method = "getOffset(Lnet/minecraft/core/BlockPos;)Lnet/minecraft/world/phys/Vec3;",
|
| 53 | at = @At("HEAD"), cancellable = true)
|
| 54 | private void onGetOffset(BlockPos pos, CallbackInfoReturnable<Vec3> cir) {
|
| 55 | if (offlineclient$fixedRotations()) {
|
| 56 | cir.setReturnValue(Vec3.ZERO);
|
| 57 | }
|
| 58 | }
|
| 59 |
|
| 60 | @Inject(method = "getSeed(Lnet/minecraft/core/BlockPos;)J", at = @At("HEAD"), cancellable = true)
|
| 61 | private void onGetSeed(BlockPos pos, CallbackInfoReturnable<Long> cir) {
|
| 62 | if (offlineclient$fixedRotations()) {
|
| 63 | cir.setReturnValue(0L);
|
| 64 | }
|
| 65 | }
|
| 66 |
|
| 67 | @Unique
|
| 68 | private static boolean offlineclient$fixedRotations() {
|
| 69 | NoRender noRender = Modules.get(NoRender.class);
|
| 70 | return noRender != null && noRender.fixesTextureRotations();
|
| 71 | }
|
| 72 | }
|
| 73 |
|