Skip to content

Commit 3cfa262

Browse files
committed
Adjustments
- adjusted EntitySeat from trying to kill itself every tick. Now it do every 10. - collisionhandler now checks if the stock is in a consist containing a locomotive before trying to push.
1 parent 9dadcf5 commit 3cfa262

2 files changed

Lines changed: 25 additions & 20 deletions

File tree

src/main/java/ebf/tim/entities/EntitySeat.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79,22 +79,24 @@ public void entityInit(){}
7979

8080
@Override
8181
public void onUpdate() {
82-
if (parent==null) {
83-
if (getWorld().getEntityByID(parentId) instanceof EntityRollingStock) {
84-
if (getWorld().isRemote) {
85-
if (parent == null) {
86-
parent = (EntityRollingStock) getWorld().getEntityByID(parentId);
82+
if (ticksExisted % 10 == 0) { //no reason to do all this every tick. Every half a second should still feel responsive enough without causing issues.
83+
if (parent == null) {
84+
if (getWorld().getEntityByID(parentId) instanceof EntityRollingStock) {
85+
if (getWorld().isRemote) {
86+
if (parent == null) {
87+
parent = (EntityRollingStock) getWorld().getEntityByID(parentId);
88+
}
89+
parent.setSeats(this, seatNumber);
8790
}
88-
parent.setSeats(this, seatNumber);
91+
} else {
92+
getWorld().removeEntity(this);
93+
this.setDead();
8994
}
90-
} else {
91-
getWorld().removeEntity(this);
92-
this.setDead();
9395
}
94-
}
95-
if (worldObj.isRemote) {
96-
if (this.parent.seats.size() >= seatNumber+1 && (this.pos != this.parent.seats.get(seatNumber).pos || this.getPassenger() != this.parent.seats.get(seatNumber).getPassenger())) {
97-
this.setDead();
96+
if (worldObj.isRemote) {
97+
if (this.parent.seats.size() >= seatNumber + 1 && (this.pos != this.parent.seats.get(seatNumber).pos || this.getPassenger() != this.parent.seats.get(seatNumber).getPassenger())) {
98+
this.setDead();
99+
}
98100
}
99101
}
100102
}

src/main/java/train/common/entity/EntityHitbox.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import ebf.tim.entities.EntitySeat;
44
import ebf.tim.utility.CommonUtil;
5-
import ebf.tim.utility.DebugUtil;
65
import fexcraft.tmt.slim.Vec3d;
76
import fexcraft.tmt.slim.Vec3f;
87
import net.minecraft.entity.Entity;
@@ -77,7 +76,8 @@ public void manageCollision(){
7776
CommonUtil.atan2degreesf(host.posZ - e.posZ, host.posX - e.posX));
7877
e.addVelocity(motion[0], 0.05, motion[2]);
7978
}
80-
} else {
79+
}
80+
else {
8181
if (e instanceof CollisionBox) {
8282
if(((CollisionBox) e).host==null){
8383
continue;
@@ -142,13 +142,15 @@ public void manageCollision(){
142142
}
143143
}
144144

145-
} else if (e instanceof EntityPlayer || e instanceof EntityLiving) {
145+
}
146+
else if (e instanceof EntityPlayer || e instanceof EntityLiving) {
146147
//hurt entity if going fast
147148
if (Math.abs(host.motionX) + Math.abs(host.motionZ) > 0.25f) {
148149
e.attackEntityFrom(new EntityDamageSource(
149150
host instanceof Locomotive ? "Locomotive" : "rollingstock", host),
150151
(float) (Math.abs(host.motionX) + Math.abs(host.motionZ)) * 0.5f);
151-
} else if (Math.abs(host.motionX) + Math.abs(host.motionZ) <0.05) {
152+
}
153+
else if (Math.abs(host.motionX) + Math.abs(host.motionZ) <0.05) {
152154
double distanceFront = Math.sqrt((e.posX - front.posX) * (e.posX - front.posX)
153155
+ (e.posZ - front.posZ) * (e.posZ - front.posZ));
154156
double distanceBack = Math.sqrt((e.posX - back.posX) * (e.posX - back.posX)
@@ -195,8 +197,9 @@ public void updateCollidingEntities(EntityRollingStock host){
195197
}
196198

197199
//No matter what, we don't want to push a locomotive.
198-
//If the config is disabled, we don't want to push ANYTHING
199-
if (!ConfigHandler.PUSHABLE_ROLLINGSTOCK || host instanceof Locomotive) {
200+
//If the config is disabled, we don't want to push ANYTHING.
201+
//If the cart is in a consist containing a locomotive, we do not want to push it.
202+
if (!ConfigHandler.PUSHABLE_ROLLINGSTOCK || host instanceof Locomotive || (host.consistLeadID != null && host.worldObj.getEntityByID(host.consistLeadID) instanceof Locomotive)) {
200203
//still need to push the player back though
201204
if (containsEntity((Entity)obj)) {
202205
((Entity)obj).applyEntityCollision(host);
@@ -216,7 +219,7 @@ public void updateCollidingEntities(EntityRollingStock host){
216219
}
217220

218221
//we don't want to collide with our own CollisionBoxes, or the CollisionBoxes of our own consist either
219-
if(obj instanceof CollisionBox && (((CollisionBox) obj).host==host || host.consist.contains(((CollisionBox) obj).host))){
222+
if(obj instanceof CollisionBox && (((CollisionBox) obj).host == host || host.consist.contains(((CollisionBox) obj).host))){
220223
continue;
221224
}
222225

0 commit comments

Comments
 (0)