Skip to content

Commit 69b2686

Browse files
authored
Merge pull request #680 from fixrtm/fix-ride-opposite-bogie
Fix riding to bogie of moving train
2 parents 8c5aca9 + 425b2bb commit 69b2686

5 files changed

Lines changed: 101 additions & 20 deletions

File tree

CHANGELOG-SNAPSHOTS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ The changelog for 2.0.23 and earlier is generated by [anatawa12's fork of `auto-
2424
- Unnecessary ABI breaking changes `#676`
2525
- we don't need to remove original signature of `RenderElectricalWiring.renderAllWire`
2626
- Directory based ModelPacks not working `#677`
27+
- Getting onto bogie of moving train may drive train opposite direction `#680`
28+
- This also reverts `#633` because it's broken for long train
2729

2830
### Security
2931

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ Thanks to prepare-changelog.sh, we have some macros.
3232
### Removed
3333

3434
### Fixed
35-
- Sitting in the driver's seat on the opposite side drives train in reverse `#633`
3635
- Vec3 DataMap will cause crash `#652`
3736
- World is accessed from Netty IO Thread `#654`
3837
- syncVehicleState(Door, data) does not work as the setter of getVehicleState(Door) `#660`
@@ -49,6 +48,7 @@ Thanks to prepare-changelog.sh, we have some macros.
4948
- Unnecessary ABI breaking changes `#676`
5049
- we don't need to remove original signature of `RenderElectricalWiring.renderAllWire`
5150
- Directory based ModelPacks not working `#677`
51+
- Getting onto bogie of moving train may drive train opposite direction `#680`
5252

5353
### Security
5454

src/main/rtm-patches/jp/ngt/rtm/entity/train/EntityTrainBase.java.patch

Lines changed: 81 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
--- a/jp/ngt/rtm/entity/train/EntityTrainBase.java
22
+++ b/jp/ngt/rtm/entity/train/EntityTrainBase.java
3-
@@ -54,28 +54,29 @@
3+
@@ -54,28 +54,30 @@
44
import net.minecraftforge.fml.relauncher.SideOnly;
55

66
public abstract class EntityTrainBase extends EntityVehicleBase<ModelSetTrain> implements IChunkLoader {
77
private static final DataParameter<Integer> BOGIE_ID0 = EntityDataManager.createKey(EntityTrainBase.class, DataSerializers.VARINT);
88
private static final DataParameter<Integer> BOGIE_ID1 = EntityDataManager.createKey(EntityTrainBase.class, DataSerializers.VARINT);
99
+ private static final DataParameter<Float> TRAIN_SPEED = EntityDataManager.createKey(EntityTrainBase.class, DataSerializers.FLOAT);
10+
+ private static final DataParameter<Boolean> CAB_DIRECTION = EntityDataManager.createKey(EntityTrainBase.class, DataSerializers.BOOLEAN);
1011
public static final short MAX_AIR_COUNT = 2880;
1112
public static final short MIN_AIR_COUNT = 2480;
1213
public static final float TRAIN_WIDTH = 2.75F;
@@ -32,19 +33,37 @@
3233
super(world);
3334
this.setSize(2.75F, 1.1875F);
3435
this.noClip = true;
35-
@@ -92,10 +93,11 @@
36+
@@ -92,18 +94,21 @@
3637

3738
protected void entityInit() {
3839
super.entityInit();
3940
this.getDataManager().register(BOGIE_ID0, 0);
4041
this.getDataManager().register(BOGIE_ID1, 0);
4142
+ this.getDataManager().register(TRAIN_SPEED, 0.0f);
43+
+ this.getDataManager().register(CAB_DIRECTION, false);
4244
}
4345

4446
protected void writeEntityToNBT(NBTTagCompound nbt) {
4547
super.writeEntityToNBT(nbt);
4648
NBTTagCompound nbttagcompound = new NBTTagCompound();
47-
@@ -126,12 +128,15 @@
49+
this.writeFormationData(nbttagcompound);
50+
nbt.setTag("FormationEntry", nbttagcompound);
51+
nbt.setInteger("trainDir", this.getTrainDirection());
52+
+ nbt.setBoolean("cabDir", this.getDataManager().get(CAB_DIRECTION));
53+
}
54+
55+
private void writeFormationData(NBTTagCompound nbt) {
56+
if (this.formation != null) {
57+
FormationEntry formationentry = this.formation.getEntry(this);
58+
@@ -119,19 +124,23 @@
59+
protected void readEntityFromNBT(NBTTagCompound nbt) {
60+
super.readEntityFromNBT(nbt);
61+
NBTTagCompound nbttagcompound = nbt.getCompoundTag("FormationEntry");
62+
this.readFormationData(nbttagcompound);
63+
this.setTrainDirection(nbt.getInteger("trainDir"));
64+
+ this.getDataManager().set(CAB_DIRECTION, nbt.getBoolean("cabDir"));
65+
}
66+
4867
private void readFormationData(NBTTagCompound nbt) {
4968
long i = nbt.getLong("FormationId");
5069
byte b0 = nbt.getByte("EntryPos");
@@ -61,7 +80,7 @@
6180
formation.setTrain(this, b0, b1);
6281
}
6382

64-
@@ -293,25 +298,25 @@
83+
@@ -293,25 +302,25 @@
6584
float f = this.getSpeed();
6685
int i = this.getNotch();
6786
Random random = this.world.rand;
@@ -91,7 +110,7 @@
91110
double d6 = (random.nextDouble() * 2.0D - 1.0D) * d5;
92111
double d7 = (random.nextDouble() * 2.0D - 1.0D) * d5;
93112
this.world.spawnParticle(enumparticletypes, d2, d3, d4, d6, 0.25D, d7, new int[0]);
94-
@@ -441,25 +446,34 @@
113+
@@ -441,25 +450,34 @@
95114
}
96115
}
97116

@@ -129,7 +148,44 @@
129148
this.setSpeed(f);
130149
}
131150

132-
@@ -655,11 +669,11 @@
151+
@@ -506,11 +524,11 @@
152+
public Vec3 getRiderPos(Entity passenger) {
153+
return super.getRiderPos(passenger).add(0.0D, this.getMountedYOffset(), 0.0D);
154+
}
155+
156+
protected int getRiderPosIndex() {
157+
- return this.getTrainDirection();
158+
+ return this.getCabDirection();
159+
}
160+
161+
public double getMountedYOffset() {
162+
return (double)(this.height + 1.1875F - 0.93F);
163+
}
164+
@@ -593,15 +611,20 @@
165+
}
166+
167+
}
168+
169+
private void mountEntityToTrain(Entity entity, int direction) {
170+
- if (this.getTrainDirection() != direction) {
171+
- this.setSpeed(-this.getSpeed());
172+
+ if (this.isControlCar()) {
173+
+ this.setTrainDirection(direction);
174+
+ if (this.formation != null && this.formation.size() > 1) {
175+
+ byte data = this.getVehicleState(TrainState.TrainStateType.Role);
176+
+ byte newData = this.getCabDirection() == this.getTrainDirection() ? data : (byte) (data ^ 2);
177+
+ this.setTrainStateData_NoSync(TrainState.TrainStateType.Role, newData);
178+
+ }
179+
}
180+
181+
- this.setTrainDirection(direction);
182+
+ setCabDirection(direction);
183+
entity.startRiding(this);
184+
}
185+
186+
protected void removePassengerFromVehicle(Entity passenger) {
187+
Entity entity = this.getBogie(this.getTrainDirection());
188+
@@ -655,11 +678,11 @@
133189
if (!this.world.isRemote && par2.getTrain() != null) {
134190
int i = par1.getBogieId();
135191
int j = par2.getBogieId();
@@ -142,7 +198,7 @@
142198
entityplayer = (EntityPlayer)this.getFirstPassenger();
143199
} else if (par2.getTrain().getFirstPassenger() instanceof EntityPlayer) {
144200
entityplayer = (EntityPlayer)par2.getTrain().getFirstPassenger();
145-
@@ -672,38 +686,38 @@
201+
@@ -672,38 +695,38 @@
146202
}
147203

148204
}
@@ -186,7 +242,20 @@
186242
public boolean existBogies() {
187243
return this.getBogie(0) != null && this.getBogie(1) != null;
188244
}
189-
@@ -760,10 +774,11 @@
245+
@@ -755,15 +778,24 @@
246+
247+
public void setFormation(Formation par1) {
248+
this.formation = par1;
249+
}
250+
251+
+ public int getCabDirection() {
252+
+ return this.getDataManager().get(CAB_DIRECTION) ? 1 : 0;
253+
+ }
254+
+
255+
+ private void setCabDirection(int direction) {
256+
+ this.getDataManager().set(CAB_DIRECTION, direction != 0);
257+
+ }
258+
+
190259
public int getTrainDirection() {
191260
return this.getVehicleState(TrainState.TrainStateType.Direction);
192261
}
@@ -198,7 +267,7 @@
198267
} else {
199268
this.formation.setTrainDirection((byte)par1, this);
200269
}
201-
@@ -793,33 +808,46 @@
270+
@@ -793,33 +825,46 @@
202271
public boolean addNotch(Entity driver, int par2) {
203272
if (par2 != 0) {
204273
int i = this.getNotch();
@@ -250,7 +319,7 @@
250319
}
251320

252321
public void setSignal(int par1) {
253-
@@ -883,10 +911,11 @@
322+
@@ -883,10 +928,11 @@
254323
this.releaseTicket();
255324
}
256325

@@ -262,7 +331,7 @@
262331
public boolean isChunkLoaderEnable() {
263332
return this.getVehicleState(TrainState.TrainStateType.ChunkLoader) > 0;
264333
}
265-
@@ -903,11 +932,10 @@
334+
@@ -903,11 +949,10 @@
266335
private boolean requestTicket() {
267336
Ticket ticket = RTMChunkManager.INSTANCE.getNewTicket(this.world, Type.ENTITY);
268337
if (ticket != null) {
@@ -274,7 +343,7 @@
274343
return true;
275344
} else {
276345
NGTLog.debug("[RTM] Failed to get ticket (Chunk Loader)");
277-
@@ -931,20 +959,26 @@
346+
@@ -931,20 +976,26 @@
278347
if (!this.world.isRemote) {
279348
if (this.ticket == null && !this.requestTicket()) {
280349
return;

src/main/rtm-patches/jp/ngt/rtm/entity/train/util/Formation.java.patch

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
break;
9191
}
9292
}
93-
@@ -241,10 +247,11 @@
93+
@@ -241,18 +247,23 @@
9494
}
9595

9696
public void setSpeed(float par1) {
@@ -102,7 +102,19 @@
102102

103103
this.speed = par1;
104104
}
105-
@@ -265,35 +272,44 @@
105+
}
106+
107+
public void setTrainDirection(byte par1, EntityTrainBase par2) {
108+
+ if (par2.getTrainDirection() != par1) {
109+
+ this.setSpeed(-par2.getSpeed());
110+
+ }
111+
+
112+
FormationEntry formationentry = this.getEntry(par2);
113+
if (formationentry != null) {
114+
this.direction = (byte)(par1 ^ formationentry.dir);
115+
byte b0 = 0;
116+
117+
@@ -265,35 +276,45 @@
106118

107119
}
108120
}
@@ -116,7 +128,8 @@
116128
+ if (formationentry == null) continue;
117129
+ if (data == TrainState.Role_Front.data || data == TrainState.Role_Back.data) {
118130
this.controlCar = par2;
119-
+ par2.setTrainDirection(par2.getTrainDirection());
131+
+ par2.setTrainStateData_NoSync(type, (par2.getCabDirection() == par2.getTrainDirection()) ? data : (byte) (data ^ 2));
132+
+ par2.setTrainDirection(par2.getCabDirection());
120133
}
121134

122135
if (par2.equals(formationentry.train)) {

src/main/rtm-patches/jp/ngt/rtm/entity/vehicle/EntityVehicleBase.java.patch

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
if (axisalignedbb == null) {
1313
axisalignedbb = new AxisAlignedBB(-1.5D, 0.0D, -2.0D, 1.5D, 3.0D, 2.0D);
1414
}
15-
@@ -532,21 +531,36 @@
15+
@@ -532,21 +531,33 @@
1616
public void setTrainStateData(int id, byte data) {
1717
this.setVehicleState(TrainState.getStateType(id), data);
1818
}
@@ -25,9 +25,6 @@
2525
public void setVehicleState(TrainState.TrainStateType type, byte data) {
2626
- this.getResourceState().getDataMap().setInt(type.toString(), data, 3);
2727
+ this.getResourceState().getDataMap().setInt(type.toString(), type.clap(data, this), 3);
28-
+ if (type == TrainState.TrainStateType.Direction && data != getVehicleState(TrainState.TrainStateType.Direction)) {
29-
+ setSpeed(-getSpeed());
30-
+ }
3128
}
3229

3330
@SideOnly(Side.CLIENT)

0 commit comments

Comments
 (0)