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;
|
public boolean isOnRail = true;
|
||||||
private int turnProgress;
|
private int turnProgress;
|
||||||
|
/* Clientside position that should be approached with smooth interpolation */
|
||||||
private double trainX;
|
private double trainX;
|
||||||
private double trainY;
|
private double trainY;
|
||||||
private double trainZ;
|
private double trainZ;
|
||||||
@ -29,6 +30,16 @@ public abstract class EntityRailCarBase extends Entity {
|
|||||||
@SideOnly(Side.CLIENT) private double velocityX;
|
@SideOnly(Side.CLIENT) private double velocityX;
|
||||||
@SideOnly(Side.CLIENT) private double velocityY;
|
@SideOnly(Side.CLIENT) private double velocityY;
|
||||||
@SideOnly(Side.CLIENT) private double velocityZ;
|
@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 boolean initDummies = false;
|
||||||
public BoundingBoxDummyEntity[] dummies = new BoundingBoxDummyEntity[0];
|
public BoundingBoxDummyEntity[] dummies = new BoundingBoxDummyEntity[0];
|
||||||
@ -41,21 +52,15 @@ public abstract class EntityRailCarBase extends Entity {
|
|||||||
@Override protected void readEntityFromNBT(NBTTagCompound nbt) { }
|
@Override protected void readEntityFromNBT(NBTTagCompound nbt) { }
|
||||||
@Override protected void writeEntityToNBT(NBTTagCompound nbt) { }
|
@Override protected void writeEntityToNBT(NBTTagCompound nbt) { }
|
||||||
|
|
||||||
/*@Override
|
|
||||||
public boolean canBePushed() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canBeCollidedWith() {
|
|
||||||
return !this.isDead;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUpdate() {
|
public void onUpdate() {
|
||||||
|
|
||||||
if(this.worldObj.isRemote) {
|
if(this.worldObj.isRemote) {
|
||||||
|
|
||||||
|
this.prevPosX = this.posX;
|
||||||
|
this.prevPosY = this.posY;
|
||||||
|
this.prevPosZ = this.posZ;
|
||||||
|
|
||||||
if(this.turnProgress > 0) {
|
if(this.turnProgress > 0) {
|
||||||
this.prevRotationYaw = this.rotationYaw;
|
this.prevRotationYaw = this.rotationYaw;
|
||||||
double x = this.posX + (this.trainX - this.posX) / (double) this.turnProgress;
|
double x = this.posX + (this.trainX - this.posX) / (double) this.turnProgress;
|
||||||
@ -71,6 +76,21 @@ public abstract class EntityRailCarBase extends Entity {
|
|||||||
this.setPosition(this.posX, this.posY, this.posZ);
|
this.setPosition(this.posX, this.posY, this.posZ);
|
||||||
this.setRotation(this.rotationYaw, this.rotationPitch);
|
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 {
|
} else {
|
||||||
|
|
||||||
DummyConfig[] definitions = this.getDummies();
|
DummyConfig[] definitions = this.getDummies();
|
||||||
@ -109,6 +129,9 @@ public abstract class EntityRailCarBase extends Entity {
|
|||||||
this.derail();
|
this.derail();
|
||||||
return;
|
return;
|
||||||
} else {
|
} 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.prevRotationYaw = this.rotationYaw;
|
||||||
this.rotationYaw = this.movementYaw = generateYaw(frontPos, backPos);
|
this.rotationYaw = this.movementYaw = generateYaw(frontPos, backPos);
|
||||||
this.motionX = this.rotationYaw / 360D; // hijacking this crap for easy syncing
|
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];
|
BoundingBoxDummyEntity dummy = dummies[i];
|
||||||
Vec3 rot = Vec3.createVectorHelper(def.offset.xCoord, def.offset.yCoord, def.offset.zCoord);
|
Vec3 rot = Vec3.createVectorHelper(def.offset.xCoord, def.offset.yCoord, def.offset.zCoord);
|
||||||
rot.rotateAroundY((float) (-this.rotationYaw * Math.PI / 180));
|
rot.rotateAroundY((float) (-this.rotationYaw * Math.PI / 180));
|
||||||
double x = posX + rot.xCoord;
|
double x = renderX + rot.xCoord;
|
||||||
double y = posY + rot.yCoord;
|
double y = renderY + rot.yCoord;
|
||||||
double z = posZ + rot.zCoord;
|
double z = renderZ + rot.zCoord;
|
||||||
dummy.setSize(def.width, def.height); // TEMP
|
dummy.setSize(def.width, def.height); // TEMP
|
||||||
dummy.setPosition(x, y, z);
|
dummy.setPosition(x, y, z);
|
||||||
}
|
}
|
||||||
@ -319,4 +342,17 @@ public abstract class EntityRailCarBase extends Entity {
|
|||||||
this.offset = offset;
|
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;
|
if(passengerSeats[i] != null) continue;
|
||||||
|
|
||||||
seat.rotateAroundY((float) (-this.rotationYaw * Math.PI / 180));
|
seat.rotateAroundY((float) (-this.rotationYaw * Math.PI / 180));
|
||||||
double x = posX + seat.xCoord;
|
double x = renderX + seat.xCoord;
|
||||||
double z = posZ + seat.zCoord;
|
double z = renderZ + seat.zCoord;
|
||||||
|
|
||||||
double deltaX = player.posX - x;
|
double deltaX = player.posX - x;
|
||||||
double deltaZ = player.posZ - z;
|
double deltaZ = player.posZ - z;
|
||||||
@ -108,8 +108,8 @@ public abstract class EntityRailCarRidable extends EntityRailCarCargo {
|
|||||||
if(this.riddenByEntity == null) {
|
if(this.riddenByEntity == null) {
|
||||||
Vec3 seat = getRiderSeatPosition();
|
Vec3 seat = getRiderSeatPosition();
|
||||||
seat.rotateAroundY((float) (-this.rotationYaw * Math.PI / 180));
|
seat.rotateAroundY((float) (-this.rotationYaw * Math.PI / 180));
|
||||||
double x = posX + seat.xCoord;
|
double x = renderX + seat.xCoord;
|
||||||
double z = posZ + seat.zCoord;
|
double z = renderZ + seat.zCoord;
|
||||||
|
|
||||||
double deltaX = player.posX - x;
|
double deltaX = player.posX - x;
|
||||||
double deltaZ = player.posZ - z;
|
double deltaZ = player.posZ - z;
|
||||||
@ -131,9 +131,9 @@ public abstract class EntityRailCarRidable extends EntityRailCarCargo {
|
|||||||
SeatDummyEntity dummySeat = new SeatDummyEntity(worldObj, this);
|
SeatDummyEntity dummySeat = new SeatDummyEntity(worldObj, this);
|
||||||
Vec3 passengerSeat = this.getPassengerSeats()[nearestSeat];
|
Vec3 passengerSeat = this.getPassengerSeats()[nearestSeat];
|
||||||
passengerSeat.rotateAroundY((float) (-this.rotationYaw * Math.PI / 180));
|
passengerSeat.rotateAroundY((float) (-this.rotationYaw * Math.PI / 180));
|
||||||
double x = posX + passengerSeat.xCoord;
|
double x = renderX + passengerSeat.xCoord;
|
||||||
double y = posY + passengerSeat.yCoord;
|
double y = renderY + passengerSeat.yCoord;
|
||||||
double z = posZ + passengerSeat.zCoord;
|
double z = renderZ + passengerSeat.zCoord;
|
||||||
dummySeat.setPosition(x, y - 1, z);
|
dummySeat.setPosition(x, y - 1, z);
|
||||||
passengerSeats[nearestSeat] = dummySeat;
|
passengerSeats[nearestSeat] = dummySeat;
|
||||||
worldObj.spawnEntityInWorld(dummySeat);
|
worldObj.spawnEntityInWorld(dummySeat);
|
||||||
@ -160,9 +160,9 @@ public abstract class EntityRailCarRidable extends EntityRailCarCargo {
|
|||||||
} else {
|
} else {
|
||||||
Vec3 rot = seats[i];
|
Vec3 rot = seats[i];
|
||||||
rot.rotateAroundY((float) (-this.rotationYaw * Math.PI / 180));
|
rot.rotateAroundY((float) (-this.rotationYaw * Math.PI / 180));
|
||||||
double x = posX + rot.xCoord;
|
double x = renderX + rot.xCoord;
|
||||||
double y = posY + rot.yCoord;
|
double y = renderY + rot.yCoord;
|
||||||
double z = posZ + rot.zCoord;
|
double z = renderZ + rot.zCoord;
|
||||||
seat.setPosition(x, y - 1, z);
|
seat.setPosition(x, y - 1, z);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -177,7 +177,7 @@ public abstract class EntityRailCarRidable extends EntityRailCarCargo {
|
|||||||
offset.rotateAroundY((float) (-this.rotationYaw * Math.PI / 180));
|
offset.rotateAroundY((float) (-this.rotationYaw * Math.PI / 180));
|
||||||
|
|
||||||
if(this.riddenByEntity != null) {
|
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 org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
|
import com.hbm.entity.train.EntityRailCarBase;
|
||||||
import com.hbm.main.ResourceManager;
|
import com.hbm.main.ResourceManager;
|
||||||
|
|
||||||
import net.minecraft.client.renderer.entity.Render;
|
import net.minecraft.client.renderer.entity.Render;
|
||||||
@ -13,6 +14,18 @@ public class RenderTrainCargoTram extends Render {
|
|||||||
@Override
|
@Override
|
||||||
public void doRender(Entity entity, double x, double y, double z, float swing, float interp) {
|
public void doRender(Entity entity, double x, double y, double z, float swing, float interp) {
|
||||||
GL11.glPushMatrix();
|
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);
|
GL11.glTranslated(x, y, z);
|
||||||
|
|
||||||
float yaw = entity.rotationYaw;
|
float yaw = entity.rotationYaw;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user