-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathEntityBogie.java.patch
192 lines (172 loc) · 7.36 KB
/
EntityBogie.java.patch
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
--- a/jp/ngt/rtm/entity/train/EntityBogie.java
+++ b/jp/ngt/rtm/entity/train/EntityBogie.java
@@ -44,10 +44,11 @@
private TileEntityLargeRailCore currentRailObj;
private RailMap currentRailMap;
private final double[] posBuf = new double[3];
private final float[] rotationBuf = new float[4];
private int split = -1;
+ private static final int SPLITS_PER_METER = 360; //(Minimum Speed[km/h] / 3.6 / 20[tick])^-1 e.g. (0.2/3.6/20)^-1 = 360
private int prevPosIndex;
private float jointDelay;
private boolean reverbSound;
private int jointIndex;
private int existCount;
@@ -126,11 +127,11 @@
return BogieController.MotionState.FLY;
} else {
RailMap railmap = this.currentRailMap;
int i = 0;
if (frontBogie != null && this.prevPosIndex != -1) {
- int j = (int)((speed + 0.25F) * 32.0F);
+ int j = (int)((Math.abs(speed) + 0.25F) * SPLITS_PER_METER);
int k = this.prevPosIndex - j;
int l = this.prevPosIndex + j;
int i1 = k < 0 ? 0 : k;
int j1 = l > this.split ? this.split : l;
double[] adouble = frontBogie.getPosBuf();
@@ -171,11 +172,11 @@
this.rotationBuf[0] = f2;
this.rotationBuf[1] = f3;
this.rotationBuf[2] = f1;
this.rotationBuf[3] = f4;
if (this.jointDelay > 0.0F) {
- this.jointDelay -= speed;
+ this.jointDelay -= Math.abs(speed);
if (this.jointDelay <= 0.0F) {
this.playJointSound();
}
}
@@ -196,19 +197,21 @@
TileEntityLargeRailCore tileentitylargerailcore = this.getRail(px, py, pz);
if (tileentitylargerailcore == null) {
return false;
} else {
if (this.currentRailObj != tileentitylargerailcore) {
- this.currentRailObj = tileentitylargerailcore;
+ RailMap railMap;
if (tileentitylargerailcore instanceof TileEntityLargeRailSwitchCore) {
TileEntityLargeRailSwitchCore tileentitylargerailswitchcore = (TileEntityLargeRailSwitchCore)tileentitylargerailcore;
- this.currentRailMap = tileentitylargerailswitchcore.getSwitch().getNearestPoint(this).getActiveRailMap(this.world);
+ railMap = tileentitylargerailswitchcore.getSwitch().getNearestPoint(this).getActiveRailMap(this.world);
} else {
- this.currentRailMap = tileentitylargerailcore.getRailMap(this);
+ railMap = tileentitylargerailcore.getRailMap(this);
}
- this.split = (int)(this.currentRailMap.getLength() * 32.0D);
+ this.currentRailObj = tileentitylargerailcore;
+ this.currentRailMap = railMap;
+ this.split = (int)(this.currentRailMap.getLength() * SPLITS_PER_METER);
this.prevPosIndex = -1;
this.onChangeRail(tileentitylargerailcore);
}
return true;
@@ -227,14 +230,17 @@
return null;
}
protected void onChangeRail(TileEntityLargeRailCore newRail) {
this.reverbSound = newRail.isReberbSound();
- TrainConfig trainconfig = this.getTrain().getResourceState().getResourceSet().getConfig();
- if (!trainconfig.muteJointSound) {
- this.jointIndex = 0;
- this.playJointSound();
+ EntityTrainBase train = this.getTrain();
+ if (train != null) {
+ TrainConfig trainconfig = train.getResourceState().getResourceSet().getConfig();
+ if (!trainconfig.muteJointSound) {
+ this.jointIndex = 0;
+ this.playJointSound();
+ }
}
}
protected boolean reverseJointArray() {
@@ -245,13 +251,13 @@
protected void playJointSound() {
EntityTrainBase entitytrainbase = this.getTrain();
TrainConfig trainconfig = entitytrainbase.getResourceState().getResourceSet().getConfig();
if (!trainconfig.muteJointSound) {
- float f = entitytrainbase.getSpeed() / trainconfig.maxSpeed[4] * 0.5F + 1.0F;
+ float f = Math.abs(entitytrainbase.getSpeed()) / trainconfig.maxSpeed[4] * 0.5F + 1.0F;
String s = this.reverbSound ? "rtm:sounds/train/joint_reverb.ogg" : "rtm:sounds/train/joint.ogg";
- RTMCore.proxy.playSound(this, s, 1.0F, f);
+ RTMCore.proxy.playSound(this, s, 4.0F, f);
int i = trainconfig.jointDelay[this.getBogieId()].length;
if (this.jointIndex < i - 1) {
int j = this.reverseJointArray() ? i - this.jointIndex - 1 : this.jointIndex;
++this.jointIndex;
int k = this.reverseJointArray() ? i - this.jointIndex - 1 : this.jointIndex;
@@ -287,14 +293,23 @@
public final void onUpdate() {
if (!this.world.isRemote && !this.tracked) {
this.tracked = VehicleTrackerEntry.trackingVehicle(this);
}
+ if (!this.world.isRemote) {
+ if (this.currentRailObj != null) {
+ this.currentRailObj.colliding = true;
+ } else {
+ this.resetRailObj(this.posX, this.posY, this.posZ);
+ }
+ }
++this.existCount;
if (this.existCount > 100 && this.getTrain() == null) {
+ if (!this.world.isRemote) {
this.setDead();
+ }
}
}
public void onBogieUpdate() {
@@ -309,11 +324,11 @@
}
public void setDead() {
boolean flag = this.getEntityWorld().isRemote && this.getTrain() != null && this.getTrain().getVehicleState(TrainState.TrainStateType.ChunkLoader) > 0;
- if (this.existCount > 100 && !flag) {
+ if (this.existCount > 100 && !flag || (this.getEntityWorld().isRemote && this.getTrain() == null)) {
super.setDead();
}
}
@@ -349,13 +364,14 @@
public boolean attackEntityFrom(DamageSource par1, float par2) {
if (this.getTrain() != null && !this.getTrain().isDead) {
return this.getTrain().attackEntityFrom(par1, par2);
} else {
- if (!this.world.isRemote) {
+ /*if (!this.world.isRemote) {
this.setDead();
- }
+ }*/
+ this.setDead();
return true;
}
}
@@ -491,10 +507,14 @@
public void addVelocity(double par1, double par3, double par5) {
}
public boolean processInitialInteract(EntityPlayer player, EnumHand hand) {
if (this.getTrain() != null) {
+ if (player.world.isRemote)
+ return true;
+ if (player.isSneaking())
+ return this.getTrain().processInitialInteract(player, hand);
if (PermissionManager.INSTANCE.hasPermission(player, "driveTrain")) {
return this.getTrain().interactTrain(this, player);
}
} else if (player.inventory.getCurrentItem() != null && player.inventory.getCurrentItem().getItem() == RTMItem.paddle) {
return true;
@@ -578,6 +598,18 @@
}
public int getProhibitedAction() {
return 1;
}
+
+ @Override
+ public void onRemovedFromWorld() {
+ super.onRemovedFromWorld();
+ com.anatawa12.fixRtm.rtm.entity.train.EntityBogieKt.onRemovedFromWorld(this);
+ }
+
+ @Override
+ public void addEntityCrashInfo(net.minecraft.crash.CrashReportCategory category) {
+ super.addEntityCrashInfo(category);
+ com.anatawa12.fixRtm.rtm.entity.train.EntityBogieKt.addEntityCrashInfo(this, category);
+ }
}