mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
preparation for train coupling
This commit is contained in:
parent
9a1d7c76e8
commit
6898cdb09e
@ -20,6 +20,7 @@ public abstract class EntityRailCarBase extends Entity {
|
||||
|
||||
public boolean isOnRail = true;
|
||||
private int turnProgress;
|
||||
/* Clientside position that should be approached with smooth interpolation */
|
||||
private double trainX;
|
||||
private double trainY;
|
||||
private double trainZ;
|
||||
@ -29,6 +30,16 @@ public abstract class EntityRailCarBase extends Entity {
|
||||
@SideOnly(Side.CLIENT) private double velocityX;
|
||||
@SideOnly(Side.CLIENT) private double velocityY;
|
||||
@SideOnly(Side.CLIENT) private double velocityZ;
|
||||
/* "Actual" position with offset directly between the front and back pos, won't match the standard position on curves */
|
||||
public double lastRenderX;
|
||||
public double lastRenderY;
|
||||
public double lastRenderZ;
|
||||
public double renderX;
|
||||
public double renderY;
|
||||
public double renderZ;
|
||||
|
||||
public EntityRailCarBase coupledFront;
|
||||
public EntityRailCarBase coupledBack;
|
||||
|
||||
public boolean initDummies = false;
|
||||
public BoundingBoxDummyEntity[] dummies = new BoundingBoxDummyEntity[0];
|
||||
@ -40,21 +51,15 @@ public abstract class EntityRailCarBase extends Entity {
|
||||
@Override protected void entityInit() { }
|
||||
@Override protected void readEntityFromNBT(NBTTagCompound nbt) { }
|
||||
@Override protected void writeEntityToNBT(NBTTagCompound nbt) { }
|
||||
|
||||
/*@Override
|
||||
public boolean canBePushed() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeCollidedWith() {
|
||||
return !this.isDead;
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public void onUpdate() {
|
||||
|
||||
if(this.worldObj.isRemote) {
|
||||
|
||||
this.prevPosX = this.posX;
|
||||
this.prevPosY = this.posY;
|
||||
this.prevPosZ = this.posZ;
|
||||
|
||||
if(this.turnProgress > 0) {
|
||||
this.prevRotationYaw = this.rotationYaw;
|
||||
@ -71,6 +76,21 @@ public abstract class EntityRailCarBase extends Entity {
|
||||
this.setPosition(this.posX, this.posY, this.posZ);
|
||||
this.setRotation(this.rotationYaw, this.rotationPitch);
|
||||
}
|
||||
|
||||
BlockPos anchor = this.getCurentAnchorPos();
|
||||
Vec3 frontPos = getRelPosAlongRail(anchor, this.getLengthSpan());
|
||||
Vec3 backPos = getRelPosAlongRail(anchor, -this.getLengthSpan());
|
||||
|
||||
this.lastRenderX = this.renderX;
|
||||
this.lastRenderY = this.renderY;
|
||||
this.lastRenderZ = this.renderZ;
|
||||
|
||||
if(frontPos != null && backPos != null) {
|
||||
this.renderX = (frontPos.xCoord + backPos.xCoord) / 2D;
|
||||
this.renderY = (frontPos.yCoord + backPos.yCoord) / 2D;
|
||||
this.renderZ = (frontPos.zCoord + backPos.zCoord) / 2D;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
DummyConfig[] definitions = this.getDummies();
|
||||
@ -109,6 +129,9 @@ public abstract class EntityRailCarBase extends Entity {
|
||||
this.derail();
|
||||
return;
|
||||
} else {
|
||||
this.renderX = (frontPos.xCoord + backPos.xCoord) / 2D;
|
||||
this.renderY = (frontPos.yCoord + backPos.yCoord) / 2D;
|
||||
this.renderZ = (frontPos.zCoord + backPos.zCoord) / 2D;
|
||||
this.prevRotationYaw = this.rotationYaw;
|
||||
this.rotationYaw = this.movementYaw = generateYaw(frontPos, backPos);
|
||||
this.motionX = this.rotationYaw / 360D; // hijacking this crap for easy syncing
|
||||
@ -121,9 +144,9 @@ public abstract class EntityRailCarBase extends Entity {
|
||||
BoundingBoxDummyEntity dummy = dummies[i];
|
||||
Vec3 rot = Vec3.createVectorHelper(def.offset.xCoord, def.offset.yCoord, def.offset.zCoord);
|
||||
rot.rotateAroundY((float) (-this.rotationYaw * Math.PI / 180));
|
||||
double x = posX + rot.xCoord;
|
||||
double y = posY + rot.yCoord;
|
||||
double z = posZ + rot.zCoord;
|
||||
double x = renderX + rot.xCoord;
|
||||
double y = renderY + rot.yCoord;
|
||||
double z = renderZ + rot.zCoord;
|
||||
dummy.setSize(def.width, def.height); // TEMP
|
||||
dummy.setPosition(x, y, z);
|
||||
}
|
||||
@ -319,4 +342,17 @@ public abstract class EntityRailCarBase extends Entity {
|
||||
this.offset = offset;
|
||||
}
|
||||
}
|
||||
|
||||
public static enum TrainCoupling {
|
||||
FRONT,
|
||||
BACK
|
||||
}
|
||||
|
||||
public Vec3 getCouplingPos(TrainCoupling coupling) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public EntityRailCarBase getCoupledTo(TrainCoupling coupling) {
|
||||
return coupling == TrainCoupling.FRONT ? this.coupledFront : coupling == TrainCoupling.BACK ? this.coupledBack : null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -90,8 +90,8 @@ public abstract class EntityRailCarRidable extends EntityRailCarCargo {
|
||||
if(passengerSeats[i] != null) continue;
|
||||
|
||||
seat.rotateAroundY((float) (-this.rotationYaw * Math.PI / 180));
|
||||
double x = posX + seat.xCoord;
|
||||
double z = posZ + seat.zCoord;
|
||||
double x = renderX + seat.xCoord;
|
||||
double z = renderZ + seat.zCoord;
|
||||
|
||||
double deltaX = player.posX - x;
|
||||
double deltaZ = player.posZ - z;
|
||||
@ -108,8 +108,8 @@ public abstract class EntityRailCarRidable extends EntityRailCarCargo {
|
||||
if(this.riddenByEntity == null) {
|
||||
Vec3 seat = getRiderSeatPosition();
|
||||
seat.rotateAroundY((float) (-this.rotationYaw * Math.PI / 180));
|
||||
double x = posX + seat.xCoord;
|
||||
double z = posZ + seat.zCoord;
|
||||
double x = renderX + seat.xCoord;
|
||||
double z = renderZ + seat.zCoord;
|
||||
|
||||
double deltaX = player.posX - x;
|
||||
double deltaZ = player.posZ - z;
|
||||
@ -131,9 +131,9 @@ public abstract class EntityRailCarRidable extends EntityRailCarCargo {
|
||||
SeatDummyEntity dummySeat = new SeatDummyEntity(worldObj, this);
|
||||
Vec3 passengerSeat = this.getPassengerSeats()[nearestSeat];
|
||||
passengerSeat.rotateAroundY((float) (-this.rotationYaw * Math.PI / 180));
|
||||
double x = posX + passengerSeat.xCoord;
|
||||
double y = posY + passengerSeat.yCoord;
|
||||
double z = posZ + passengerSeat.zCoord;
|
||||
double x = renderX + passengerSeat.xCoord;
|
||||
double y = renderY + passengerSeat.yCoord;
|
||||
double z = renderZ + passengerSeat.zCoord;
|
||||
dummySeat.setPosition(x, y - 1, z);
|
||||
passengerSeats[nearestSeat] = dummySeat;
|
||||
worldObj.spawnEntityInWorld(dummySeat);
|
||||
@ -160,9 +160,9 @@ public abstract class EntityRailCarRidable extends EntityRailCarCargo {
|
||||
} else {
|
||||
Vec3 rot = seats[i];
|
||||
rot.rotateAroundY((float) (-this.rotationYaw * Math.PI / 180));
|
||||
double x = posX + rot.xCoord;
|
||||
double y = posY + rot.yCoord;
|
||||
double z = posZ + rot.zCoord;
|
||||
double x = renderX + rot.xCoord;
|
||||
double y = renderY + rot.yCoord;
|
||||
double z = renderZ + rot.zCoord;
|
||||
seat.setPosition(x, y - 1, z);
|
||||
}
|
||||
}
|
||||
@ -177,7 +177,7 @@ public abstract class EntityRailCarRidable extends EntityRailCarCargo {
|
||||
offset.rotateAroundY((float) (-this.rotationYaw * Math.PI / 180));
|
||||
|
||||
if(this.riddenByEntity != null) {
|
||||
this.riddenByEntity.setPosition(this.posX + offset.xCoord, this.posY + offset.yCoord, this.posZ + offset.zCoord);
|
||||
this.riddenByEntity.setPosition(this.renderX + offset.xCoord, this.renderY + offset.yCoord, this.renderZ + offset.zCoord);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -2,6 +2,7 @@ package com.hbm.render.entity.item;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.hbm.entity.train.EntityRailCarBase;
|
||||
import com.hbm.main.ResourceManager;
|
||||
|
||||
import net.minecraft.client.renderer.entity.Render;
|
||||
@ -13,6 +14,18 @@ public class RenderTrainCargoTram extends Render {
|
||||
@Override
|
||||
public void doRender(Entity entity, double x, double y, double z, float swing, float interp) {
|
||||
GL11.glPushMatrix();
|
||||
|
||||
EntityRailCarBase train = (EntityRailCarBase) entity;
|
||||
double iX = train.prevPosX + (train.posX - train.prevPosX) * interp;
|
||||
double iY = train.prevPosY + (train.posY - train.prevPosY) * interp;
|
||||
double iZ = train.prevPosZ + (train.posZ - train.prevPosZ) * interp;
|
||||
double rX = train.lastRenderX + (train.renderX - train.lastRenderX) * interp;
|
||||
double rY = train.lastRenderY + (train.renderY - train.lastRenderY) * interp;
|
||||
double rZ = train.lastRenderZ + (train.renderZ - train.lastRenderZ) * interp;
|
||||
x -= iX - rX;
|
||||
y -= iY - rY;
|
||||
z -= iZ - rZ;
|
||||
|
||||
GL11.glTranslated(x, y, z);
|
||||
|
||||
float yaw = entity.rotationYaw;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user