use of net.minecraft.util.EnumHand in project 3arthh4ck by 3arthqu4ke.
the class PreCrystalFunction method accept.
@Override
public void accept(BlockPos pos, BlockPos down, BlockPos on, EnumFacing onFacing, int obbySlot, MineSlots slots, int crystalSlot, Entity blocking, EntityPlayer found, boolean execute) {
if (blocking != null) {
return;
}
// TODO: support Obby???
IBlockState state = mc.world.getBlockState(down);
if (state.getBlock() != Blocks.OBSIDIAN && state.getBlock() != Blocks.BEDROCK) {
return;
}
synchronized (module) {
// check again, this time synchronized
if (module.isActive() || AntiSurround.LEG_SWITCH.returnIfPresent(LegSwitch::isActive, false)) {
return;
}
if (module.normal.getValue() || module.async.getValue()) {
module.semiActiveTime = System.nanoTime();
module.semiActive.set(true);
module.semiPos = down;
}
RayTraceResult ray = null;
if (module.rotations != null) {
ray = RotationUtil.rayTraceWithYP(down, mc.world, module.rotations[0], module.rotations[1], (b, p) -> p.equals(down));
}
if (ray == null) {
module.rotations = RotationUtil.getRotations(down.getX() + 0.5f, down.getY() + 1, down.getZ() + 0.5f, RotationUtil.getRotationPlayer().posX, RotationUtil.getRotationPlayer().posY, RotationUtil.getRotationPlayer().posZ, mc.player.getEyeHeight());
ray = RotationUtil.rayTraceWithYP(down, mc.world, module.rotations[0], module.rotations[1], (b, p) -> p.equals(down));
if (ray == null) {
ray = new RayTraceResult(new Vec3d(0.5, 1.0, 0.5), EnumFacing.UP, down);
}
}
RayTraceResult finalResult = ray;
float[] f = RayTraceUtil.hitVecToPlaceVec(down, ray.hitVec);
EnumHand h = InventoryUtil.getHand(crystalSlot);
Locks.acquire(Locks.PLACE_SWITCH_LOCK, () -> {
int lastSlot = mc.player.inventory.currentItem;
InventoryUtil.switchTo(crystalSlot);
mc.player.connection.sendPacket(new CPacketPlayerTryUseItemOnBlock(down, finalResult.sideHit, h, f[0], f[1], f[2]));
InventoryUtil.switchTo(lastSlot);
});
}
}
use of net.minecraft.util.EnumHand in project 3arthh4ck by 3arthqu4ke.
the class ListenerMotion method executeLocked.
private void executeLocked() {
final int lastSlot = mc.player.inventory.currentItem;
if (!InventoryUtil.isHolding(Items.END_CRYSTAL)) {
if (module.offhand.getValue() || module.slot == -1) {
return;
} else {
InventoryUtil.switchTo(module.slot);
}
}
EnumHand hand = mc.player.getHeldItemOffhand().getItem() == Items.END_CRYSTAL ? EnumHand.OFF_HAND : EnumHand.MAIN_HAND;
CPacketPlayerTryUseItemOnBlock place = new CPacketPlayerTryUseItemOnBlock(module.pos, module.result.sideHit, hand, (float) module.result.hitVec.x, (float) module.result.hitVec.y, (float) module.result.hitVec.z);
CPacketAnimation swing = new CPacketAnimation(hand);
if (module.rotate.getValue() == Rotate.Packet && module.rotations != null) {
mc.player.connection.sendPacket(new CPacketPlayer.Rotation(module.rotations[0], module.rotations[1], mc.player.onGround));
}
mc.player.connection.sendPacket(place);
mc.player.connection.sendPacket(swing);
InventoryUtil.switchTo(lastSlot);
if (module.swing.getValue()) {
Swing.Client.swing(hand);
}
module.disable();
}
use of net.minecraft.util.EnumHand in project 3arthh4ck by 3arthqu4ke.
the class BlockPlacingModule method placeBlock.
public void placeBlock(BlockPos on, EnumFacing facing, float[] helpingRotations, Vec3d hitVec) {
if (rotations == null && (rotate.getValue() == Rotate.Normal || (blocksPlaced == 0 && rotate.getValue() == Rotate.Packet))) {
rotations = helpingRotations;
} else if (rotate.getValue() == Rotate.Packet) {
packets.add(new CPacketPlayer.Rotation(helpingRotations[0], helpingRotations[1], getPlayer().onGround));
}
float[] f = RayTraceUtil.hitVecToPlaceVec(on, hitVec);
EnumHand hand = InventoryUtil.getHand(slot);
packets.add(new CPacketPlayerTryUseItemOnBlock(on, facing, hand, f[0], f[1], f[2]));
if (placeSwing.getValue() == PlaceSwing.Always) {
packets.add(new CPacketAnimation(InventoryUtil.getHand(slot)));
}
// Simulate PlayerControllerMP behaviour.
if (!packet.getValue() && !(NO_GLITCH_BLOCKS.isPresent() && NO_GLITCH_BLOCKS.get().noPlace())) {
ItemStack stack = slot == -2 ? mc.player.getHeldItemOffhand() : mc.player.inventory.getStackInSlot(slot);
mc.addScheduledTask(() -> placeClient(stack, on, hand, facing, f[0], f[1], f[2]));
}
blocksPlaced++;
}
use of net.minecraft.util.EnumHand in project 3arthh4ck by 3arthqu4ke.
the class ListenerMotion method runPre.
private boolean runPre() {
module.stage = module.current.getOrder()[module.index];
BlockPos pos = module.stage.getPos(module.current);
if (module.stage == PistonStage.BREAK) {
if (!module.explode.getValue()) {
return false;
}
for (EntityEnderCrystal crystal : mc.world.getEntitiesWithinAABB(EntityEnderCrystal.class, new AxisAlignedBB(pos))) {
if (crystal.getPosition().equals(pos.up()) || crystal.getPosition().equals(module.current.getStartPos().up())) {
float[] crystalRots = RotationUtil.getRotations(crystal);
CPacketPlayer rotation = null;
if (module.rotate.getValue() == Rotate.Packet && module.rotations != null) {
rotation = new CPacketPlayer.Rotation(crystalRots[0], crystalRots[1], mc.player.onGround);
} else if (module.rotate.getValue() != Rotate.None) {
module.rotations = crystalRots;
}
CPacketPlayer finalRotation = rotation;
module.actions.add(() -> {
if (module.breakTimer.passed(module.breakDelay.getValue()) && Managers.SWITCH.getLastSwitch() >= module.coolDown.getValue()) {
if (finalRotation != null) {
mc.player.connection.sendPacket(finalRotation);
}
mc.player.connection.sendPacket(new CPacketUseEntity(crystal));
mc.player.connection.sendPacket(new CPacketAnimation(EnumHand.MAIN_HAND));
module.breakTimer.reset();
module.nextTimer.reset();
module.reset = true;
}
});
return false;
}
}
return false;
}
if (!module.timer.passed(module.delay.getValue())) {
return false;
}
if (module.stage == PistonStage.CRYSTAL) {
for (Entity entity : mc.world.getEntitiesWithinAABB(Entity.class, new AxisAlignedBB(pos.up(), module.current.getStartPos()))) {
if (entity == null || EntityUtil.isDead(entity)) {
continue;
}
if (entity instanceof EntityEnderCrystal && entity.getPosition().equals(pos.up())) {
module.index++;
module.stage = module.current.getOrder()[module.index];
pos = module.stage.getPos(module.current);
break;
}
module.current.setValid(false);
return false;
}
}
// TODO: Use BlockPlacingModule#placeBlock here, its almost the same!
if (pos != null) {
EnumFacing facing = BlockUtil.getFacing(pos);
if (facing == null && module.stage != PistonStage.CRYSTAL && (!module.packet.getValue() || module.packetTimer.passed(module.confirmation.getValue())) || module.stage != PistonStage.CRYSTAL && module.checkEntities(pos)) {
module.current.setValid(false);
return false;
}
if (facing == null && module.stage != PistonStage.CRYSTAL) {
return false;
}
int slot = module.getSlot();
if (slot == -1) {
module.disableWithMessage("<" + module.getDisplayName() + "> " + TextColor.RED + "Items missing!");
return false;
}
module.actions.add(() -> InventoryUtil.switchTo(slot));
float[] rotations;
if (module.stage == PistonStage.CRYSTAL) {
RayTraceResult result;
if (module.rotate.getValue() != Rotate.None) {
rotations = RotationUtil.getRotationsToTopMiddle(pos.up());
result = RayTraceUtil.getRayTraceResult(rotations[0], rotations[1], module.placeRange.getValue());
} else {
result = new RayTraceResult(new Vec3d(0.5, 1.0, 0.5), EnumFacing.UP);
}
// Opposite because tge PlacePacket gets the Opposite
facing = result.sideHit.getOpposite();
rotations = RotationUtil.getRotationsToTopMiddle(pos.up());
} else {
assert facing != null;
rotations = RotationUtil.getRotations(pos.offset(facing), facing.getOpposite());
}
EnumHand hand = slot == -2 ? EnumHand.OFF_HAND : EnumHand.MAIN_HAND;
if (module.stage == PistonStage.PISTON && module.multiDirectional.getValue()) {
EnumFacing toFace = module.current.getFacing().getOpposite();
EnumFacing piston = module.getFacing(pos, rotations);
if (piston == EnumFacing.UP || piston == EnumFacing.DOWN) {
module.current.setValid(false);
return false;
}
int index = 0;
while (piston != toFace && index < 36) {
rotations[0] = (rotations[0] + 10) % 360.0f;
piston = module.getFacing(pos, rotations);
index++;
}
if (piston != toFace) {
return false;
}
}
switch(module.rotate.getValue()) {
case None:
if (module.stage != PistonStage.PISTON) {
break;
}
case Normal:
if (module.rotations == null) {
module.rotations = rotations;
} else {
return false;
}
break;
case Packet:
CPacketPlayer rotation = new CPacketPlayer.Rotation(rotations[0], rotations[1], mc.player.onGround);
module.actions.add(() -> mc.player.connection.sendPacket(rotation));
break;
default:
}
RayTraceResult result = RayTraceUtil.getRayTraceResult(rotations[0], rotations[1]);
float[] f = RayTraceUtil.hitVecToPlaceVec(pos.offset(facing), result.hitVec);
BlockPos on = module.stage == PistonStage.CRYSTAL ? pos : pos.offset(facing);
module.clicked.add(mc.world.getBlockState(on).getBlock());
CPacketPlayerTryUseItemOnBlock place = new CPacketPlayerTryUseItemOnBlock(on, facing.getOpposite(), hand, f[0], f[1], f[2]);
if (module.stage != PistonStage.CRYSTAL && !module.packet.getValue() && (!NO_GLITCH_BLOCKS.isPresent() || !NO_GLITCH_BLOCKS.get().noPlace())) {
ItemStack stack = slot == -2 ? mc.player.getHeldItemOffhand() : mc.player.inventory.getStackInSlot(slot);
module.placeClient(stack, on, InventoryUtil.getHand(slot), facing, f[0], f[1], f[2]);
}
module.actions.add(() -> {
mc.player.connection.sendPacket(place);
mc.player.connection.sendPacket(new CPacketAnimation(hand));
if (module.swing.getValue()) {
Swing.Client.swing(hand);
}
module.packetTimer.reset();
});
module.blocksPlaced++;
module.index = module.index == 4 ? 4 : module.index + 1;
return module.rotate.getValue() != Rotate.Normal;
}
return false;
}
use of net.minecraft.util.EnumHand in project 3arthh4ck by 3arthqu4ke.
the class ListenerUpdate method placeCrystal.
private void placeCrystal(BlockPos pos, int slot, RayTraceResult ray) {
EnumHand hand = InventoryUtil.getHand(slot);
float[] f = RayTraceUtil.hitVecToPlaceVec(pos, ray.hitVec);
Locks.acquire(Locks.PLACE_SWITCH_LOCK, () -> {
if (slot != -2) {
InventoryUtil.switchTo(slot);
}
if (AUTOCRYSTAL.get().placeSwing.getValue() == SwingTime.Pre) {
AUTOCRYSTAL.get().rotationHelper.swing(hand, false);
}
mc.player.connection.sendPacket(new CPacketPlayerTryUseItemOnBlock(pos, ray.sideHit, hand, f[0], f[1], f[2]));
});
if (AUTOCRYSTAL.get().placeSwing.getValue() == SwingTime.Post) {
AUTOCRYSTAL.get().rotationHelper.swing(hand, false);
}
AUTOCRYSTAL.get().placed.put(pos, new CrystalTimeStamp(Float.MAX_VALUE, false));
}
Aggregations