/
PatchEntity.java
346 lines (283 loc) · 10.3 KB
/
PatchEntity.java
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
package nallar.patched.entity;
import java.util.List;
import nallar.tickthreading.patcher.Declare;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
public abstract class PatchEntity extends Entity {
@Declare
public Boolean isForced_;
@Declare
public Boolean canUpdate_;
@Declare
public nallar.tickthreading.minecraft.tickregion.EntityTickRegion tickRegion_;
@Declare
public int collisionSkipCounter_;
@Declare
public net.minecraft.world.chunk.Chunk chunk_;
private int lavaCheckTicks;
private boolean inLava;
public PatchEntity(World par1World) {
super(par1World);
}
@Override
@Declare
public float getDistanceToEntitySq(Entity entity) {
float xD = (float) (this.posX - entity.posX);
float yD = (float) (this.posY - entity.posY);
float zD = (float) (this.posZ - entity.posZ);
return xD * xD + yD * yD + zD * zD;
}
@Override
public boolean handleLavaMovement() {
return (lavaCheckTicks++ % 15 == 0) ? inLava = this.worldObj.isMaterialInBB(this.boundingBox.expand(-0.10000000149011612D, -0.4000000059604645D, -0.10000000149011612D), Material.lava) : inLava;
}
@Override
public void moveEntity(double vX, double vY, double vZ) {
if (this.noClip) {
this.boundingBox.offset(vX, vY, vZ);
this.posX = (this.boundingBox.minX + this.boundingBox.maxX) / 2.0D;
this.posY = this.boundingBox.minY + (double) this.yOffset - (double) this.ySize;
this.posZ = (this.boundingBox.minZ + this.boundingBox.maxZ) / 2.0D;
} else {
this.worldObj.theProfiler.startSection("move");
this.ySize *= 0.4F;
double var7 = this.posX;
double var9 = this.posY;
double var11 = this.posZ;
if (this.isInWeb) {
this.isInWeb = false;
vX *= 0.25D;
vY *= 0.05000000074505806D;
vZ *= 0.25D;
this.motionX = 0.0D;
this.motionY = 0.0D;
this.motionZ = 0.0D;
}
double vX1 = vX;
double vY1 = vY;
double vZ1 = vZ;
AxisAlignedBB var19 = this.boundingBox.copy();
@SuppressWarnings ("RedundantCast")
boolean sneakingPlayer = this.onGround && this.isSneaking() && (Object) this instanceof EntityPlayer;
if (sneakingPlayer) {
double var21;
for (var21 = 0.05D; vX != 0.0D && !this.worldObj.hasCollidingBoundingBoxes(this, this.boundingBox.getOffsetBoundingBox(vX, -1.0D, 0.0D)); vX1 = vX) {
if (vX < var21 && vX >= -var21) {
vX = 0.0D;
} else if (vX > 0.0D) {
vX -= var21;
} else {
vX += var21;
}
}
for (; vZ != 0.0D && !this.worldObj.hasCollidingBoundingBoxes(this, this.boundingBox.getOffsetBoundingBox(0.0D, -1.0D, vZ)); vZ1 = vZ) {
if (vZ < var21 && vZ >= -var21) {
vZ = 0.0D;
} else if (vZ > 0.0D) {
vZ -= var21;
} else {
vZ += var21;
}
}
while (vX != 0.0D && vZ != 0.0D && !this.worldObj.hasCollidingBoundingBoxes(this, this.boundingBox.getOffsetBoundingBox(vX, -1.0D, vZ))) {
if (vX < var21 && vX >= -var21) {
vX = 0.0D;
} else if (vX > 0.0D) {
vX -= var21;
} else {
vX += var21;
}
if (vZ < var21 && vZ >= -var21) {
vZ = 0.0D;
} else if (vZ > 0.0D) {
vZ -= var21;
} else {
vZ += var21;
}
vX1 = vX;
vZ1 = vZ;
}
}
List<AxisAlignedBB> collidingBoundingBoxes = this.worldObj.getCollidingBoundingBoxes(this, this.boundingBox.addCoord(vX, vY, vZ), 12);
int collidingBoundingBoxesSize = collidingBoundingBoxes.size();
collisionSkipCounter = collidingBoundingBoxesSize / 11;
if (collisionSkipCounter != 0 && tickRegion != null) {
collisionSkipCounter = tickRegion.size() / 50;
}
for (int i = 0; i < collidingBoundingBoxesSize; ++i) {
vY = collidingBoundingBoxes.get(i).calculateYOffset(this.boundingBox, vY);
}
this.boundingBox.offset(0.0D, vY, 0.0D);
if (!this.field_70135_K && vY1 != vY) {
vZ = 0.0D;
vY = 0.0D;
vX = 0.0D;
}
boolean var34 = this.onGround || vY1 != vY && vY1 < 0.0D;
int i;
for (i = 0; i < collidingBoundingBoxesSize; ++i) {
vX = collidingBoundingBoxes.get(i).calculateXOffset(this.boundingBox, vX);
}
this.boundingBox.offset(vX, 0.0D, 0.0D);
if (!this.field_70135_K && vX1 != vX) {
vZ = 0.0D;
vY = 0.0D;
vX = 0.0D;
}
for (i = 0; i < collidingBoundingBoxesSize; ++i) {
vZ = collidingBoundingBoxes.get(i).calculateZOffset(this.boundingBox, vZ);
}
this.boundingBox.offset(0.0D, 0.0D, vZ);
if (!this.field_70135_K && vZ1 != vZ) {
vZ = 0.0D;
vY = 0.0D;
vX = 0.0D;
}
double var25;
double var27;
int var30;
double var36;
if (this.stepHeight > 0.0F && var34 && (sneakingPlayer || this.ySize < 0.05F) && (vX1 != vX || vZ1 != vZ)) {
var36 = vX;
var25 = vY;
var27 = vZ;
vX = vX1;
vY = (double) this.stepHeight;
vZ = vZ1;
AxisAlignedBB var29 = this.boundingBox.copy();
this.boundingBox.setBB(var19);
collidingBoundingBoxes = this.worldObj.getCollidingBoundingBoxes(this, this.boundingBox.addCoord(vX1, vY, vZ1), 10);
collidingBoundingBoxesSize = collidingBoundingBoxes.size();
for (var30 = 0; var30 < collidingBoundingBoxesSize; ++var30) {
vY = collidingBoundingBoxes.get(var30).calculateYOffset(this.boundingBox, vY);
}
this.boundingBox.offset(0.0D, vY, 0.0D);
if (!this.field_70135_K && vY1 != vY) {
vZ = 0.0D;
vY = 0.0D;
vX = 0.0D;
}
for (var30 = 0; var30 < collidingBoundingBoxesSize; ++var30) {
vX = collidingBoundingBoxes.get(var30).calculateXOffset(this.boundingBox, vX);
}
this.boundingBox.offset(vX, 0.0D, 0.0D);
if (!this.field_70135_K && vX1 != vX) {
vZ = 0.0D;
vY = 0.0D;
vX = 0.0D;
}
for (var30 = 0; var30 < collidingBoundingBoxesSize; ++var30) {
vZ = collidingBoundingBoxes.get(var30).calculateZOffset(this.boundingBox, vZ);
}
this.boundingBox.offset(0.0D, 0.0D, vZ);
if (!this.field_70135_K && vZ1 != vZ) {
vZ = 0.0D;
vY = 0.0D;
vX = 0.0D;
}
if (!this.field_70135_K && vY1 != vY) {
vZ = 0.0D;
vY = 0.0D;
vX = 0.0D;
} else {
vY = (double) (-this.stepHeight);
for (var30 = 0; var30 < collidingBoundingBoxesSize; ++var30) {
vY = collidingBoundingBoxes.get(var30).calculateYOffset(this.boundingBox, vY);
}
this.boundingBox.offset(0.0D, vY, 0.0D);
}
if (var36 * var36 + var27 * var27 >= vX * vX + vZ * vZ) {
vX = var36;
vY = var25;
vZ = var27;
this.boundingBox.setBB(var29);
}
/* Fixes a vanilla bug where the player view would dip when stepping between certain blocks
* https://mojang.atlassian.net/browse/MC-1594
else
{
double var40 = this.boundingBox.minY - (double)((int)this.boundingBox.minY);
if (var40 > 0.0D)
{
this.ySize = (float)((double)this.ySize + var40 + 0.01D);
}
}
*/
}
this.worldObj.theProfiler.endSection();
this.worldObj.theProfiler.startSection("rest");
this.posX = (this.boundingBox.minX + this.boundingBox.maxX) / 2.0D;
this.posY = this.boundingBox.minY + (double) this.yOffset - (double) this.ySize;
this.posZ = (this.boundingBox.minZ + this.boundingBox.maxZ) / 2.0D;
this.isCollidedHorizontally = vX1 != vX || vZ1 != vZ;
this.isCollidedVertically = vY1 != vY;
this.onGround = vY1 != vY && vY1 < 0.0D;
this.isCollided = this.isCollidedHorizontally || this.isCollidedVertically;
this.updateFallState(vY, this.onGround);
if (vX1 != vX) {
this.motionX = 0.0D;
}
if (vY1 != vY) {
this.motionY = 0.0D;
}
if (vZ1 != vZ) {
this.motionZ = 0.0D;
}
var36 = this.posX - var7;
var25 = this.posY - var9;
var27 = this.posZ - var11;
if (this.canTriggerWalking() && !sneakingPlayer && this.ridingEntity == null) {
int var37 = MathHelper.floor_double(this.posX);
var30 = MathHelper.floor_double(this.posY - 0.20000000298023224D - (double) this.yOffset);
int var31 = MathHelper.floor_double(this.posZ);
int var32 = this.worldObj.getBlockId(var37, var30, var31);
if (var32 == 0) {
int var33 = this.worldObj.blockGetRenderType(var37, var30 - 1, var31);
if (var33 == 11 || var33 == 32 || var33 == 21) {
var32 = this.worldObj.getBlockId(var37, var30 - 1, var31);
}
}
if (var32 != Block.ladder.blockID) {
var25 = 0.0D;
}
this.distanceWalkedModified = (float) ((double) this.distanceWalkedModified + (double) MathHelper.sqrt_double(var36 * var36 + var27 * var27) * 0.6D);
this.field_82151_R = (float) ((double) this.field_82151_R + (double) MathHelper.sqrt_double(var36 * var36 + var25 * var25 + var27 * var27) * 0.6D);
if (this.field_82151_R > (float) this.nextStepDistance && var32 > 0) {
this.nextStepDistance = (int) this.field_82151_R + 1;
if (this.isInWater()) {
float var39 = MathHelper.sqrt_double(this.motionX * this.motionX * 0.20000000298023224D + this.motionY * this.motionY + this.motionZ * this.motionZ * 0.20000000298023224D) * 0.35F;
if (var39 > 1.0F) {
var39 = 1.0F;
}
this.playSound("liquid.swim", var39, 1.0F + (this.rand.nextFloat() - this.rand.nextFloat()) * 0.4F);
}
this.playStepSound(var37, var30, var31, var32);
Block.blocksList[var32].onEntityWalking(this.worldObj, var37, var30, var31, this);
}
}
this.doBlockCollisions();
boolean var38 = this.isWet();
if (this.worldObj.isBoundingBoxBurning(this.boundingBox.contract(0.001D, 0.001D, 0.001D))) {
this.dealFireDamage(1);
if (!var38) {
++this.fire;
if (this.fire == 0) {
this.setFire(8);
}
}
} else if (this.fire <= 0) {
this.fire = -this.fireResistance;
}
if (var38 && this.fire > 0) {
this.playSound("random.fizz", 0.7F, 1.6F + (this.rand.nextFloat() - this.rand.nextFloat()) * 0.4F);
this.fire = -this.fireResistance;
}
this.worldObj.theProfiler.endSection();
}
}
}