-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathBurrowUtil.java
More file actions
154 lines (128 loc) · 5.33 KB
/
BurrowUtil.java
File metadata and controls
154 lines (128 loc) · 5.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package fuck.you.bitch.stop.skidding;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.network.play.client.CPacketEntityAction;
import net.minecraft.network.play.client.CPacketPlayer;
import net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import java.util.ArrayList;
import java.util.List;
public class BurrowUtil implements FuckYouStopSkiddingBitch {
public static final Minecraft mc = Minecraft.getMinecraft();
/*
Start block Util.
*/
public static boolean placeBlock(BlockPos pos, EnumHand hand, boolean rotate, boolean packet, boolean isSneaking) {
boolean sneaking = false;
EnumFacing side = getFirstFacing(pos);
if (side == null) {
return isSneaking;
}
BlockPos neighbour = pos.offset(side);
EnumFacing opposite = side.getOpposite();
Vec3d hitVec = new Vec3d(neighbour).add(0.5, 0.5, 0.5).add(new Vec3d(opposite.getDirectionVec()).scale(0.5));
Block neighbourBlock = mc.world.getBlockState(neighbour).getBlock();
if (!mc.player.isSneaking()) {
mc.player.connection.sendPacket(new CPacketEntityAction(mc.player, CPacketEntityAction.Action.START_SNEAKING));
mc.player.setSneaking(true);
sneaking = true;
}
if (rotate) {
faceVector(hitVec, true);
}
rightClickBlock(neighbour, hitVec, hand, opposite, packet);
mc.player.swingArm(EnumHand.MAIN_HAND);
mc.rightClickDelayTimer = 4; //?
return sneaking || isSneaking;
}
public static List<EnumFacing> getPossibleSides(BlockPos pos) {
List<EnumFacing> facings = new ArrayList<>();
for (EnumFacing side : EnumFacing.values()) {
BlockPos neighbour = pos.offset(side);
if (mc.world.getBlockState(neighbour).getBlock().canCollideCheck(mc.world.getBlockState(neighbour), false)) {
IBlockState blockState = mc.world.getBlockState(neighbour);
if (!blockState.getMaterial().isReplaceable()) {
facings.add(side);
}
}
}
return facings;
}
public static EnumFacing getFirstFacing(BlockPos pos) {
for (EnumFacing facing : getPossibleSides(pos)) {
return facing;
}
return null;
}
public static Vec3d getEyesPos() {
return new Vec3d(mc.player.posX, mc.player.posY + mc.player.getEyeHeight(), mc.player.posZ);
}
public static float[] getLegitRotations(Vec3d vec) {
Vec3d eyesPos = getEyesPos();
double diffX = vec.x - eyesPos.x;
double diffY = vec.y - eyesPos.y;
double diffZ = vec.z - eyesPos.z;
double diffXZ = Math.sqrt(diffX * diffX + diffZ * diffZ);
float yaw = (float) Math.toDegrees(Math.atan2(diffZ, diffX)) - 90F;
float pitch = (float) -Math.toDegrees(Math.atan2(diffY, diffXZ));
return new float[]{
mc.player.rotationYaw + MathHelper.wrapDegrees(yaw - mc.player.rotationYaw),
mc.player.rotationPitch + MathHelper.wrapDegrees(pitch - mc.player.rotationPitch)
};
}
public static void faceVector(Vec3d vec, boolean normalizeAngle) {
float[] rotations = getLegitRotations(vec);
mc.player.connection.sendPacket(new CPacketPlayer.Rotation(rotations[0], normalizeAngle ? MathHelper.normalizeAngle((int) rotations[1], 360) : rotations[1], mc.player.onGround));
}
public static void rightClickBlock(BlockPos pos, Vec3d vec, EnumHand hand, EnumFacing direction, boolean packet) {
if (packet) {
float f = (float) (vec.x - (double) pos.getX());
float f1 = (float) (vec.y - (double) pos.getY());
float f2 = (float) (vec.z - (double) pos.getZ());
mc.player.connection.sendPacket(new CPacketPlayerTryUseItemOnBlock(pos, direction, hand, f, f1, f2));
} else {
mc.playerController.processRightClickBlock(mc.player, mc.world, pos, direction, vec, hand);
}
mc.player.swingArm(EnumHand.MAIN_HAND);
mc.rightClickDelayTimer = 4; //?
}
/*
End block Util.
*/
/*
Start Inventory Util.
*/
public static int findHotbarBlock(Class clazz) {
for (int i = 0; i < 9; i++) {
ItemStack stack = mc.player.inventory.getStackInSlot(i);
if (stack == ItemStack.EMPTY) {
continue;
}
if (clazz.isInstance(stack.getItem())) {
return i;
}
if (stack.getItem() instanceof ItemBlock) {
Block block = ((ItemBlock) stack.getItem()).getBlock();
if (clazz.isInstance(block)) {
return i;
}
}
}
return -1;
}
public static void switchToSlot(final int slot) {
mc.player.connection.sendPacket(new CPacketHeldItemChange(slot));
mc.player.inventory.currentItem = slot;
mc.playerController.updateController();
}
/*
End Inventory Util
*/
}