Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AntiCactus -> Collisions, CollisionShapeEvent enhancements #2862

Merged
merged 1 commit into from
Dec 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@

package meteordevelopment.meteorclient.events.world;

import meteordevelopment.meteorclient.events.Cancellable;
import net.minecraft.block.BlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.shape.VoxelShape;

public class CollisionShapeEvent {
public class CollisionShapeEvent extends Cancellable {
public enum CollisionType {
BLOCK,
FLUID
Expand All @@ -22,10 +23,10 @@ public enum CollisionType {
public VoxelShape shape;
public CollisionType type;

public static CollisionShapeEvent get(BlockState state, BlockPos pos, CollisionType type) {
public static CollisionShapeEvent get(BlockState state, BlockPos pos, VoxelShape shape, CollisionType type) {
INSTANCE.state = state;
INSTANCE.pos = pos;
INSTANCE.shape = null;
INSTANCE.shape = shape;
INSTANCE.type = type;
return INSTANCE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@

import meteordevelopment.meteorclient.MeteorClient;
import meteordevelopment.meteorclient.events.world.AmbientOcclusionEvent;
import meteordevelopment.meteorclient.events.world.CollisionShapeEvent;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.BlockState;
import net.minecraft.block.ShapeContext;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.BlockView;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -27,17 +24,4 @@ private void onGetAmbientOcclusionLightLevel(BlockState state, BlockView world,

if (event.lightLevel != -1) info.setReturnValue(event.lightLevel);
}

@Inject(method = "getCollisionShape", at = @At("HEAD"), cancellable = true)
private void onGetCollisionShape(BlockState state, BlockView view, BlockPos pos, ShapeContext context, CallbackInfoReturnable<VoxelShape> info) {
if (!(state.getFluidState().isEmpty())) {
CollisionShapeEvent event = MeteorClient.EVENT_BUS.post(CollisionShapeEvent.get(state.getFluidState().getBlockState(), pos, CollisionShapeEvent.CollisionType.FLUID));

if (event.shape != null) info.setReturnValue(event.shape);
} else {
CollisionShapeEvent event = MeteorClient.EVENT_BUS.post(CollisionShapeEvent.get(state, pos, CollisionShapeEvent.CollisionType.BLOCK));

if (event.shape != null) info.setReturnValue(event.shape);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client).
* Copyright (c) Meteor Development.
*/

package meteordevelopment.meteorclient.mixin;

import meteordevelopment.meteorclient.MeteorClient;
import meteordevelopment.meteorclient.events.world.CollisionShapeEvent;
import net.minecraft.block.BlockState;
import net.minecraft.block.ShapeContext;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockCollisionSpliterator;
import net.minecraft.world.BlockView;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(BlockCollisionSpliterator.class)
public class BlockCollisionSpliteratorMixin {
@Redirect(method = "computeNext", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/BlockState;getCollisionShape(Lnet/minecraft/world/BlockView;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/ShapeContext;)Lnet/minecraft/util/shape/VoxelShape;"))
private VoxelShape onComputeNextCollisionBox(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
VoxelShape shape = state.getCollisionShape(world, pos, context);
CollisionShapeEvent event = state.getFluidState().isEmpty()
? MeteorClient.EVENT_BUS.post(CollisionShapeEvent.get(state, pos, shape, CollisionShapeEvent.CollisionType.BLOCK))
: MeteorClient.EVENT_BUS.post(CollisionShapeEvent.get(state.getFluidState().getBlockState(), pos, shape, CollisionShapeEvent.CollisionType.FLUID));

if (event.isCancelled())
return VoxelShapes.empty();
else
return event.shape;
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client).
* Copyright (c) Meteor Development.
*/

package meteordevelopment.meteorclient.mixin;

import meteordevelopment.meteorclient.systems.modules.Modules;
import meteordevelopment.meteorclient.systems.modules.world.Collisions;
import net.minecraft.world.border.WorldBorder;
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(WorldBorder.class)
public abstract class WorldBorderMixin {
@Inject(method = "canCollide", at = @At("HEAD"), cancellable = true)
private void canCollide(CallbackInfoReturnable<Boolean> info) {
if (Modules.get().get(Collisions.class).ignoreBorder()) info.setReturnValue(false);
}

@Inject(method = "contains(Lnet/minecraft/util/math/BlockPos;)Z", at = @At("HEAD"), cancellable = true)
private void contains(CallbackInfoReturnable<Boolean> info) {
if (Modules.get().get(Collisions.class).ignoreBorder()) info.setReturnValue(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ private void initRender() {
private void initWorld() {
add(new AirPlace());
add(new Ambience());
add(new AntiCactus());
add(new Collisions());
add(new AutoBreed());
add(new AutoBrewer());
add(new AutoMount());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,80 +6,17 @@
package meteordevelopment.meteorclient.systems.modules.movement;

import meteordevelopment.meteorclient.events.entity.player.ClipAtLedgeEvent;
import meteordevelopment.meteorclient.events.world.CollisionShapeEvent;
import meteordevelopment.meteorclient.settings.BlockListSetting;
import meteordevelopment.meteorclient.settings.BoolSetting;
import meteordevelopment.meteorclient.settings.Setting;
import meteordevelopment.meteorclient.settings.SettingGroup;
import meteordevelopment.meteorclient.systems.modules.Categories;
import meteordevelopment.meteorclient.systems.modules.Module;
import meteordevelopment.orbit.EventHandler;
import net.minecraft.block.*;
import net.minecraft.util.shape.VoxelShapes;

import java.util.List;

public class SafeWalk extends Module {
private final SettingGroup sgGeneral = settings.getDefaultGroup();

private final Setting<Boolean> ledge = sgGeneral.add(new BoolSetting.Builder()
.name("ledge")
.description("Prevents you from walking of blocks, like pressing shift.")
.defaultValue(true)
.build()
);

private final Setting<List<Block>> blocks = sgGeneral.add(new BlockListSetting.Builder()
.name("blocks")
.description("Which blocks to prevent on walking")
.filter(this::blockFilter)
.build()
);

private final Setting<Boolean> magma = sgGeneral.add(new BoolSetting.Builder()
.name("magma")
.description("Prevents you from walking over magma blocks.")
.defaultValue(false)
.build()
);

public SafeWalk() {
super(Categories.Movement, "safe-walk", "Prevents you from walking off blocks or on blocks that you dont want.");
super(Categories.Movement, "safe-walk", "Prevents you from walking off blocks.");
}

@EventHandler
private void onClipAtLedge(ClipAtLedgeEvent event) {
if (!mc.player.isSneaking()) event.setClip(ledge.get());
}

@EventHandler
private void onCollisionShape(CollisionShapeEvent event) {
if (mc.world == null || mc.player == null) return;
if (event.type != CollisionShapeEvent.CollisionType.BLOCK) return;
if (blocks.get().contains(event.state.getBlock())) {
event.shape = VoxelShapes.fullCube();
}
else if (magma.get() && !mc.player.isSneaking()
&& event.state.isAir()
&& mc.world.getBlockState(event.pos.down()).getBlock() == Blocks.MAGMA_BLOCK) {
event.shape = VoxelShapes.fullCube();
}
}

private boolean blockFilter(Block block) {
return (block instanceof AbstractFireBlock
|| block instanceof AbstractPressurePlateBlock
|| block instanceof TripwireBlock
|| block instanceof TripwireHookBlock
|| block instanceof CobwebBlock
|| block instanceof CampfireBlock
|| block instanceof SweetBerryBushBlock
|| block instanceof CactusBlock
|| block instanceof AbstractRailBlock
|| block instanceof TrapdoorBlock
|| block instanceof PowderSnowBlock
|| block instanceof AbstractCauldronBlock
|| block instanceof HoneyBlock
);
if (!mc.player.isSneaking()) event.setClip(true);
}
}

This file was deleted.

Loading