|
1 | 1 | --- a/jp/ngt/rtm/entity/train/EntityTrainBase.java |
2 | 2 | +++ b/jp/ngt/rtm/entity/train/EntityTrainBase.java |
3 | | -@@ -54,28 +54,29 @@ |
| 3 | +@@ -54,28 +54,30 @@ |
4 | 4 | import net.minecraftforge.fml.relauncher.SideOnly; |
5 | 5 |
|
6 | 6 | public abstract class EntityTrainBase extends EntityVehicleBase<ModelSetTrain> implements IChunkLoader { |
7 | 7 | private static final DataParameter<Integer> BOGIE_ID0 = EntityDataManager.createKey(EntityTrainBase.class, DataSerializers.VARINT); |
8 | 8 | private static final DataParameter<Integer> BOGIE_ID1 = EntityDataManager.createKey(EntityTrainBase.class, DataSerializers.VARINT); |
9 | 9 | + 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); |
10 | 11 | public static final short MAX_AIR_COUNT = 2880; |
11 | 12 | public static final short MIN_AIR_COUNT = 2480; |
12 | 13 | public static final float TRAIN_WIDTH = 2.75F; |
|
32 | 33 | super(world); |
33 | 34 | this.setSize(2.75F, 1.1875F); |
34 | 35 | this.noClip = true; |
35 | | -@@ -92,10 +93,11 @@ |
| 36 | +@@ -92,18 +94,21 @@ |
36 | 37 |
|
37 | 38 | protected void entityInit() { |
38 | 39 | super.entityInit(); |
39 | 40 | this.getDataManager().register(BOGIE_ID0, 0); |
40 | 41 | this.getDataManager().register(BOGIE_ID1, 0); |
41 | 42 | + this.getDataManager().register(TRAIN_SPEED, 0.0f); |
| 43 | ++ this.getDataManager().register(CAB_DIRECTION, false); |
42 | 44 | } |
43 | 45 |
|
44 | 46 | protected void writeEntityToNBT(NBTTagCompound nbt) { |
45 | 47 | super.writeEntityToNBT(nbt); |
46 | 48 | 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 | + |
48 | 67 | private void readFormationData(NBTTagCompound nbt) { |
49 | 68 | long i = nbt.getLong("FormationId"); |
50 | 69 | byte b0 = nbt.getByte("EntryPos"); |
|
61 | 80 | formation.setTrain(this, b0, b1); |
62 | 81 | } |
63 | 82 |
|
64 | | -@@ -293,25 +298,25 @@ |
| 83 | +@@ -293,25 +302,25 @@ |
65 | 84 | float f = this.getSpeed(); |
66 | 85 | int i = this.getNotch(); |
67 | 86 | Random random = this.world.rand; |
|
91 | 110 | double d6 = (random.nextDouble() * 2.0D - 1.0D) * d5; |
92 | 111 | double d7 = (random.nextDouble() * 2.0D - 1.0D) * d5; |
93 | 112 | this.world.spawnParticle(enumparticletypes, d2, d3, d4, d6, 0.25D, d7, new int[0]); |
94 | | -@@ -441,25 +446,34 @@ |
| 113 | +@@ -441,25 +450,34 @@ |
95 | 114 | } |
96 | 115 | } |
97 | 116 |
|
|
129 | 148 | this.setSpeed(f); |
130 | 149 | } |
131 | 150 |
|
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 @@ |
133 | 189 | if (!this.world.isRemote && par2.getTrain() != null) { |
134 | 190 | int i = par1.getBogieId(); |
135 | 191 | int j = par2.getBogieId(); |
|
142 | 198 | entityplayer = (EntityPlayer)this.getFirstPassenger(); |
143 | 199 | } else if (par2.getTrain().getFirstPassenger() instanceof EntityPlayer) { |
144 | 200 | entityplayer = (EntityPlayer)par2.getTrain().getFirstPassenger(); |
145 | | -@@ -672,38 +686,38 @@ |
| 201 | +@@ -672,38 +695,38 @@ |
146 | 202 | } |
147 | 203 |
|
148 | 204 | } |
|
186 | 242 | public boolean existBogies() { |
187 | 243 | return this.getBogie(0) != null && this.getBogie(1) != null; |
188 | 244 | } |
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 | ++ |
190 | 259 | public int getTrainDirection() { |
191 | 260 | return this.getVehicleState(TrainState.TrainStateType.Direction); |
192 | 261 | } |
|
198 | 267 | } else { |
199 | 268 | this.formation.setTrainDirection((byte)par1, this); |
200 | 269 | } |
201 | | -@@ -793,33 +808,46 @@ |
| 270 | +@@ -793,33 +825,46 @@ |
202 | 271 | public boolean addNotch(Entity driver, int par2) { |
203 | 272 | if (par2 != 0) { |
204 | 273 | int i = this.getNotch(); |
|
250 | 319 | } |
251 | 320 |
|
252 | 321 | public void setSignal(int par1) { |
253 | | -@@ -883,10 +911,11 @@ |
| 322 | +@@ -883,10 +928,11 @@ |
254 | 323 | this.releaseTicket(); |
255 | 324 | } |
256 | 325 |
|
|
262 | 331 | public boolean isChunkLoaderEnable() { |
263 | 332 | return this.getVehicleState(TrainState.TrainStateType.ChunkLoader) > 0; |
264 | 333 | } |
265 | | -@@ -903,11 +932,10 @@ |
| 334 | +@@ -903,11 +949,10 @@ |
266 | 335 | private boolean requestTicket() { |
267 | 336 | Ticket ticket = RTMChunkManager.INSTANCE.getNewTicket(this.world, Type.ENTITY); |
268 | 337 | if (ticket != null) { |
|
274 | 343 | return true; |
275 | 344 | } else { |
276 | 345 | NGTLog.debug("[RTM] Failed to get ticket (Chunk Loader)"); |
277 | | -@@ -931,20 +959,26 @@ |
| 346 | +@@ -931,20 +976,26 @@ |
278 | 347 | if (!this.world.isRemote) { |
279 | 348 | if (this.ticket == null && !this.requestTicket()) { |
280 | 349 | return; |
|
0 commit comments