package jp.ngt.rtm.entity.train;
import java.util.ArrayList;
import java.util.Random;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import jp.ngt.ngtlib.io.NGTLog;
import jp.ngt.ngtlib.math.NGTMath;
import jp.ngt.ngtlib.util.NGTUtil;
import jp.ngt.rtm.RTMItem;
import jp.ngt.rtm.entity.vehicle.EntityVehicleBase;
import jp.ngt.rtm.rail.TileEntityLargeRailBase;
import jp.ngt.rtm.rail.TileEntityLargeRailCore;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.DamageSource;
import net.minecraft.util.MathHelper;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
import ru.madadev.GR.MultiMessage;
import ru.madadev.GR.ModelPack.Configs.ModelConfigTrain;
import ru.madadev.GR.entity.EntityAttacher;
import ru.madadev.GR.entity.EntitySeat;
import ru.madadev.GR.entity.EntityTrainPart;
public abstract class EntityTrainBase extends EntityVehicleBase {
private static final byte DW_Bogie0 = 21;
private static final byte DW_Bogie1 = 22;
private static final byte DW_Data = 23;
private static final byte DW_ActiveCab = 24;
private static final byte DW_Attacher0 = 25;
private static final byte DW_Attacher1 = 26;
private static final byte DW_Dist = 27;
private static final byte DW_Reverce = 28;
private static final byte DW_Seats = 29;
private static final byte DW_Position = 30;
private static final byte DW_Speed = 31;
public static final float TRAIN_WIDTH = 2.75F;
public static final float TRAIN_HEIGHT = 1.25F - 0.0625F;
@SideOnly(Side.CLIENT)
private int carPosRotationIncrements;
@SideOnly(Side.CLIENT)
private double carX, carY, carZ;
@SideOnly(Side.CLIENT)
private float carYaw, carPitch;
@SideOnly(Side.CLIENT)
private float carSpeed;
private float speedInc = 0;
private float trainSpeed;
public EntityTrainBase(World world) {
super(world);
this.setSize(TRAIN_WIDTH, TRAIN_HEIGHT);
this.yOffset = TRAIN_HEIGHT;
this.noClip = true;
}
public void setBogies(EntityBogie[] bogies) {
if (!worldObj.isRemote) {
this.dataWatcher.updateObject(DW_Bogie0, bogies[0].getEntityId());
this.dataWatcher.updateObject(DW_Bogie1, bogies[1].getEntityId());
getBogie(0).setTrain(this);
getBogie(1).setTrain(this);
}
}
public void spawnTrain(World world) {
if (!world.isRemote) {
world.spawnEntityInWorld(this);
setupBogies();
}
}
private void setupBogies() {
float ro0 = MathHelper.wrapAngleTo180_float(rotationYaw);
float[][] bPosArray = new float[2][];
String[] bogie = ((ModelConfigTrain) getModel().config).bogies.get(0);
bPosArray[0] = new float[] {Float.parseFloat(bogie[0]), Float.parseFloat(bogie[1]), Float.parseFloat(bogie[2])};
bogie = ((ModelConfigTrain) getModel().config).bogies.get(1);
bPosArray[1] = new float[] {Float.parseFloat(bogie[0]), Float.parseFloat(bogie[1]), Float.parseFloat(bogie[2])};
float bPos = bPosArray[0][2];
getBogie(0).setPositionAndRotation(posX + NGTMath.sin(ro0) * bPos, posY, posZ + NGTMath.cos(ro0) * bPos, ro0, 0.0F);
bPos = bPosArray[1][2];
getBogie(1).setPositionAndRotation(posX + NGTMath.sin(ro0) * bPos, posY, posZ + NGTMath.cos(ro0) * bPos, MathHelper.wrapAngleTo180_float(ro0 + 180.0F), 0.0F);
}
@Override
protected void entityInit()
{
super.entityInit();
this.dataWatcher.addObject(DW_Bogie0, Integer.valueOf(0));
this.dataWatcher.addObject(DW_Bogie1, Integer.valueOf(0));
this.dataWatcher.addObject(DW_Attacher0, Integer.valueOf(0));
this.dataWatcher.addObject(DW_Attacher1, Integer.valueOf(0));
this.dataWatcher.addObject(DW_Dist, Float.valueOf(0));
this.dataWatcher.addObject(DW_Reverce, Integer.valueOf(0));
this.dataWatcher.addObject(DW_Seats, "|");
this.dataWatcher.addObject(DW_Position, Integer.valueOf(0));
this.dataWatcher.addObject(DW_Data, "|");
this.dataWatcher.addObject(DW_ActiveCab, Integer.valueOf(0));
this.dataWatcher.addObject(DW_Speed, Float.valueOf(0));
}
public void addSeat(EntitySeat seat) {
MultiMessage msg = new MultiMessage(this.dataWatcher.getWatchableObjectString(DW_Seats));
int count = msg.getInteger("count");
MultiMessage newMsg = new MultiMessage();
newMsg.addInteger("count", count + 1);
for (int i = 0; i < count; i++) {
newMsg.addInteger("seat" + i, msg.getInteger("seat" + i));
}
newMsg.addInteger("seat" + count, seat.getEntityId());
this.dataWatcher.updateObject(DW_Seats, newMsg.getMessage());
}
public EntitySeat[] getSeats() {
try {
MultiMessage msg = new MultiMessage(this.dataWatcher.getWatchableObjectString(DW_Seats));
EntitySeat[] result = new EntitySeat[msg.getInteger("count")];
for (int i = 0; i < result.length; i++) {
result[i] = (EntitySeat) worldObj.getEntityByID(msg.getInteger("seat" + i));
}
return result;
} catch (NullPointerException e) {return new EntitySeat[0];}
}
public void setSeats(EntitySeat[] seats) {
MultiMessage msg = new MultiMessage();
msg.addInteger("count", seats.length);
for (int i = 0; i < seats.length; i++) {
msg.addInteger("seat" + i, seats[i].getEntityId());
}
this.dataWatcher.updateObject(DW_Seats, msg.getMessage());
}
public void setAttacher(EntityAttacher entity, int id) {
this.dataWatcher.updateObject(id == 0 ? DW_Attacher0 : DW_Attacher1, entity.getEntityId());
entity.setTrain(this);
}
public EntityAttacher getAttacher(int id) {
Entity entity = this.worldObj.getEntityByID(this.dataWatcher.getWatchableObjectInt(id == 0 ? DW_Attacher0 : DW_Attacher1));
if (entity instanceof EntityAttacher) {
return (EntityAttacher) entity;
}
return null;
}
@Override
protected void setSize(float par1, float par2) {
super.setSize(par1, par2);
this.myEntitySize = Entity.EnumEntitySize.SIZE_1;
}
@Override
public AxisAlignedBB getCollisionBox(Entity par1) {
return par1.boundingBox;
}
@Override
protected void writeEntityToNBT(NBTTagCompound nbt) {
super.writeEntityToNBT(nbt);
System.out.println("save train " + getModelName());
nbt.setFloat("speedInc", this.speedInc);
nbt.setInteger("bogie0", this.dataWatcher.getWatchableObjectInt(DW_Bogie0));
nbt.setInteger("bogie1", this.dataWatcher.getWatchableObjectInt(DW_Bogie1));
if (getAttacher(0) != null) nbt.setInteger("attacher0", getAttacher(0).getEntityId());
if (getAttacher(1) != null) nbt.setInteger("attacher1", getAttacher(1).getEntityId());
nbt.setString("seats", this.dataWatcher.getWatchableObjectString(DW_Seats));
nbt.setFloat("dist", getDist());
nbt.setInteger("reverce", getReverce());
nbt.setInteger("position", getPosition());
nbt.setInteger("activeCab", getActiveCab());
nbt.setString("data", this.dataWatcher.getWatchableObjectString(DW_Data));
}
@Override
protected void readEntityFromNBT(NBTTagCompound nbt) {
super.readEntityFromNBT(nbt);
this.speedInc = nbt.getFloat("speedInc");
this.dataWatcher.updateObject(DW_Bogie0, nbt.getInteger("bogie0"));
this.dataWatcher.updateObject(DW_Bogie1, nbt.getInteger("bogie1"));
if (nbt.hasKey("attacher0")) this.dataWatcher.updateObject(DW_Attacher0, nbt.getInteger("attacher0"));
if (nbt.hasKey("attacher1")) this.dataWatcher.updateObject(DW_Attacher1, nbt.getInteger("attacher1"));
this.dataWatcher.updateObject(DW_Seats, nbt.getString("seats"));
this.dataWatcher.updateObject(DW_Dist, nbt.getFloat("dist"));
this.dataWatcher.updateObject(DW_Reverce, nbt.getInteger("reverce"));
this.dataWatcher.updateObject(DW_Position, nbt.getInteger("position"));
this.dataWatcher.updateObject(DW_Data, nbt.getString("data"));
setActiveCab(nbt.getInteger("activeCab"));
System.out.println("load train" + getModelName());
}
public int getPartById(int id) {
for (Object obj : worldObj.loadedEntityList) {
if (obj instanceof EntityTrainPart) {
EntityTrainPart entity = (EntityTrainPart) obj;
int entityId = entity.getId();
if (entityId == id) return entity.getEntityId();
}
}
return -1;
}
public void setActiveCab(int cab) {
this.dataWatcher.updateObject(DW_ActiveCab, cab);
}
public int getActiveCab() {
return this.dataWatcher.getWatchableObjectInt(DW_ActiveCab);
}
public void setDist(float dist2) {
this.dataWatcher.updateObject(DW_Dist, dist2);
}
public void addDist(double d) {
float dist = this.dataWatcher.getWatchableObjectFloat(DW_Dist);
dist += d;
this.dataWatcher.updateObject(DW_Dist, dist);
}
public float getDist() {
return this.dataWatcher.getWatchableObjectFloat(DW_Dist);
}
@Override
public void onUpdate() {
super.onUpdate();
if (!worldObj.isRemote) {
if (getModel() == null) setDead();
int newId;
if (getBogie(0) == null || getBogie(1) == null) {
newId = getPartById(this.dataWatcher.getWatchableObjectInt(DW_Bogie0));
if (newId != -1) {
setBogie(0, (EntityBogie) worldObj.getEntityByID(newId));
getBogie(0).setId(newId);
}
newId = getPartById(this.dataWatcher.getWatchableObjectInt(DW_Bogie1));
if (newId != -1) {
setBogie(1, (EntityBogie) worldObj.getEntityByID(newId));
getBogie(1).setId(newId);
}
MultiMessage msg = new MultiMessage(this.dataWatcher.getWatchableObjectString(DW_Seats));
EntitySeat[] result = new EntitySeat[msg.getInteger("count")];
for (int i = 0; i < result.length; i++) {
Entity entity = worldObj.getEntityByID(msg.getInteger("seat" + i));
if (entity != null && entity instanceof EntitySeat) {
result[i] = (EntitySeat) entity;
} else {
newId = getPartById(msg.getInteger("seat" + i));
if (newId != -1) {
result[i] = (EntitySeat) worldObj.getEntityByID(newId);
result[i].setId(newId);
}
}
}
this.setSeats(result);
}
}
this.updateSpeed();
this.moveTrain();
if(this.worldObj.isRemote) {
if(this.carPosRotationIncrements > 0) {
float f0 = 1.0F / (float)this.carPosRotationIncrements;
double x = this.posX + (this.carX - this.posX) * (double)f0;
double y = this.posY + (this.carY - this.posY) * (double)f0;
double z = this.posZ + (this.carZ - this.posZ) * (double)f0;
float yaw = this.rotationYaw + MathHelper.wrapAngleTo180_float(this.carYaw - this.rotationYaw) * f0;
float pitch = this.rotationPitch + (this.carPitch - this.rotationPitch) * f0;
this.setPosition(x, y, z);
this.setRotation(yaw, pitch);
float f2 = this.getSpeed() + (this.carSpeed - this.getSpeed()) * f0;
//this.setSpeed(f2);
--this.carPosRotationIncrements;
Vec3 trainPos = Vec3.createVectorHelper(x, y, z);
try {
for (EntitySeat seat : getSeats()) {
setEntityPos(seat, trainPos, seat.getMove(), yaw, pitch);
}
setEntityPos(getAttacher(0), trainPos, getAttacher(0).getMove(), yaw, pitch);
setEntityPos(getAttacher(1), trainPos, getAttacher(1).getMove(), yaw, pitch);
} catch (NullPointerException e) {}
}
else
{
this.setPosition(this.posX, this.posY, this.posZ);
this.setRotation(this.rotationYaw, this.rotationPitch);
Vec3 trainPos = Vec3.createVectorHelper(posX, posY, posZ);
try {
for (EntitySeat seat : getSeats()) {
setEntityPos(seat, trainPos, seat.getMove(), rotationYaw, rotationPitch);
}
setEntityPos(this.getAttacher(0), trainPos, getAttacher(0).getMove(), rotationYaw, rotationPitch);
setEntityPos(this.getAttacher(1), trainPos, getAttacher(1).getMove(), rotationYaw, rotationPitch);
} catch (NullPointerException e) {}
}
try {
getBogie(0).updateBogie();
getBogie(1).updateBogie();
} catch (NullPointerException e) {}
if(getConfig().smoke.size() > 0 && getTrainStateData(3) == 1) {
float speed = this.getSpeed();
int notch = this.getPosition();
Random random = this.worldObj.rand;
for(String[] smoke : getConfig().smoke) {
Vec3 vec3 = Vec3.createVectorHelper(Double.parseDouble(smoke[0]), Double.parseDouble(smoke[1]), Double.parseDouble(smoke[2]));
vec3.rotateAroundX(NGTMath.toRadians(this.rotationPitch));
vec3.rotateAroundY(NGTMath.toRadians(this.rotationYaw));
double min = Double.parseDouble(smoke[4]);
double max = Double.parseDouble(smoke[5]);
int amount = speed > 0.05F ? (int)max : (notch > 0 ? (int)min + 3 : (int)min);
for(int j = 0; j < amount; ++j) {
double d0 = this.posX + vec3.xCoord + (double)random.nextFloat() * 0.5D - 0.25D;
double d1 = this.posY + vec3.yCoord;
double d2 = this.posZ + vec3.zCoord + (double)random.nextFloat() * 0.5D - 0.25D;
double smokeSpeed = 0.0625D;
/*if(set.getConfig().smoke.length == 7) {
smokeSpeed = (Double)set.getConfig().smoke[i][6];
}*/
double vx = (random.nextDouble() * 2.0D - 1.0D) * smokeSpeed;
double vz = (random.nextDouble() * 2.0D - 1.0D) * smokeSpeed;
this.worldObj.spawnParticle(smoke[3], d0, d1, d2, vx, 0.25D, vz);
}
}
}
} else {
TileEntityLargeRailBase rail = TileEntityLargeRailBase.getRailFromCoordinates(this.worldObj, this.posX, this.posY, this.posZ);
if(rail != null)
{
TileEntityLargeRailCore railCore = rail.getRailCore();
if(railCore != null)
{
int signal = railCore.getSignal();
//this.setSignal(signal);
}
}
this.func_145775_I();//call Block.onEntityCollidedWithBlock()
}
Vec3 prev = Vec3.createVectorHelper(this.prevPosX, this.prevPosY, this.prevPosZ);
Vec3 current = Vec3.createVectorHelper(this.posX, this.posY, this.posZ);
this.addDist(Math.abs(prev.distanceTo(current)) / 1000f);
float f0 = -Float.parseFloat(((ModelConfigTrain) this.getModel().config).rolling);
float roll = MathHelper.wrapAngleTo180_float((this.rotationYaw - this.prevRotationYaw) * f0);
if(getReverce() == 1)
{
roll *= -1.0F;
}
this.rotationRoll = roll;
}
private void setEntityPos(Entity entity, Vec3 trainPos, Vec3 move, float rotationYaw, float rotationPitch) {
move.rotateAroundX((float) Math.toRadians(rotationPitch));
move.rotateAroundY((float) Math.toRadians(rotationYaw));
entity.setPositionAndRotation(trainPos.xCoord + move.xCoord, trainPos.yCoord + move.yCoord, trainPos.zCoord + move.zCoord, rotationYaw, rotationPitch);
}
public ModelConfigTrain getConfig() {
return (ModelConfigTrain) this.getModel().config;
}
@SideOnly(Side.CLIENT)
@Override
protected void updateAnimation()
{
super.updateAnimation();
/*this.setRollsignAnimation(this.getTrainStateData(8));
if(this.rollsignAnimation > this.rollsignV) {
--this.rollsignAnimation;
}
else if(this.rollsignAnimation < this.rollsignV)
{
++this.rollsignAnimation;
}*/
if(getTrainStateData(2) == 1) {
if(this.doorMoveR < MAX_DOOR_MOVE) {
if(this.doorMoveR == 0) {
// TODO RTMCore.proxy.playSound(this, this.getModelSet().sound_doorOpen, 1.0F, 1.0F);
}
++this.doorMoveR;
}
} else {
if(this.doorMoveR > 0) {
if(this.doorMoveR == MAX_DOOR_MOVE) {
// TODO RTMCore.proxy.playSound(this, this.getModelSet().sound_doorClose, 1.0F, 1.0F);
}
--this.doorMoveR;
}
}
if(getTrainStateData(1) == 1) {
if(this.doorMoveL < MAX_DOOR_MOVE) {
if(this.doorMoveL == 0) {
// TODO RTMCore.proxy.playSound(this, this.getModelSet().sound_doorOpen, 1.0F, 1.0F);
}
++this.doorMoveL;
}
} else {
if(this.doorMoveL > 0) {
if(this.doorMoveL == MAX_DOOR_MOVE) {
// TODO RTMCore.proxy.playSound(this, this.getModelSet().sound_doorClose, 1.0F, 1.0F);
}
--this.doorMoveL;
}
}
if(getTrainStateData(3) == 1) {
if(this.pantograph_F < MAX_PANTOGRAPH_MOVE) {
if(this.pantograph_F == 0) {
// TODO RTMCore.proxy.playSound(this, this.getModelSet().sound_pantUp, 1.0F, 1.0F);
}
++this.pantograph_F;
}
} else {
if(this.pantograph_F > 0) {
if(this.pantograph_F == MAX_PANTOGRAPH_MOVE) {
// TODO RTMCore.proxy.playSound(this, this.getModelSet().sound_pantDown, 1.0F, 1.0F);
}
--this.pantograph_F;
}
}
if(getTrainStateData(4) == 1) {
if(this.pantograph_B < MAX_PANTOGRAPH_MOVE) {
if(this.pantograph_B == 0) {
// TODO RTMCore.proxy.playSound(this, this.getModelSet().sound_pantUp, 1.0F, 1.0F);
}
++this.pantograph_B;
}
} else {
if(this.pantograph_B > 0) {
if(this.pantograph_B == MAX_PANTOGRAPH_MOVE) {
// TODO RTMCore.proxy.playSound(this, this.getModelSet().sound_pantDown, 1.0F, 1.0F);
}
--this.pantograph_B;
}
}
}
protected void playBrakeReleaseSound(boolean isStrong)
{
/*String sound;
if(this.getModelSet() instanceof ModelSetTrain)
{
ModelSetTrain modelSet = (ModelSetTrain)this.getModelSet();
sound = isStrong ? modelSet.sound_brakeRelease_s : modelSet.sound_brakeRelease_w;
}
else
{
ModelSetTrainClient modelSet = (ModelSetTrainClient)this.getModelSet();
sound = isStrong ? modelSet.sound_brakeRelease_s : modelSet.sound_brakeRelease_w;
}
if(sound != null)
{
String[] sa = sound.split(":");
RTMCore.proxy.playSound(this, new ResourceLocation(sa[0], sa[1]), 1.0F, 1.0F);
}*/
}
protected void updateSpeed() {
int notch = this.getPosition();
boolean isBrakeDisabled = true;
float speed = this.getSpeed();
if(this.isControlCar()) {
if(isBrakeDisabled) {
float acceleration = getAcceleration() * getReverce() * (getActiveCab() == 1 ? -1 : 1);
if(notch >= 0) {
float deceleration = 0;
if(this.rotationPitch == 0.0F) {
float f1 = 0.0002F;
deceleration = speed > 0.0F ? f1 : (speed < 0.0F ? -f1 : 0.0F);
} else {
float dec = 0.0125F;
float f2 = (getReverce() * (getActiveCab() == 1 ? -1 : 1) == 1) ? dec : -dec;
deceleration = (float) (Math.sin(Math.toRadians(this.rotationPitch)) * f2);
}
speed += acceleration - deceleration;
} else {
if (Math.abs(speed) < Math.abs(acceleration)) speed = 0;
else speed += speed > 0 ? -Math.abs(acceleration) : (speed < 0 ? Math.abs(acceleration) : 0);
}
this.setSpeed(speed);
}
}
}
public float getAcceleration() {
if (getPosition() > 0) {
String[] currPos = ((ModelConfigTrain) getModel().config).positions.get(getPosition() - 1);
if (Float.parseFloat(currPos[1]) > (getSpeed() * 72.0F) + 0.5F) return Float.parseFloat(currPos[0]);
} else {
return getPosition() * 0.001f;
}
return 0;
}
protected void moveTrain() {
float speed = getSpeed();
moveTrainWithBogie(this, speed);
}
public void moveTrainWithBogie(EntityTrainBase train, float speed)
{
if(speed == 0.0F)
{
this.updateBogiePos(train, 0, false);
this.updateBogiePos(train, 0, false);
return;
}
try {
EntityBogie frontBogie = this.getBogie(0).isFront() ? this.getBogie(0) : this.getBogie(1);
EntityBogie backBogie = !this.getBogie(0).isFront() ? this.getBogie(0) : this.getBogie(1);
ArrayList<String[]> pos = ((ModelConfigTrain) train.getModel().config).bogies;
float lengthF = Float.parseFloat(pos.get(0)[2]);
float lengthB = Float.parseFloat(pos.get(1)[2]);
float trainLength = MathHelper.abs(lengthF - lengthB);
if(frontBogie.updateBogiePos(speed, 0.0F, null))
{
if(backBogie.updateBogiePos(speed, trainLength, frontBogie))
{
this.updateTrainPos(train, lengthF, lengthB);
}
}
} catch (NullPointerException e) {}
}
private void updateTrainPos(EntityTrainBase train, float lf, float lb) {
double d0 = Math.abs(lf) / (Math.abs(lf - lb));
double[] fp = this.getBogie(0).getPosBuf();
double[] bp = this.getBogie(1).getPosBuf();
double x = fp[0] + (bp[0] - fp[0]) * d0;
double y = (fp[1] + bp[1]) * 0.5D;
double z = fp[2] + (bp[2] - fp[2]) * d0;
double x0 = fp[0] - bp[0];
double y0 = fp[1] - bp[1];
double z0 = fp[2] - bp[2];
float yaw = (float)MathHelper.wrapAngleTo180_double(NGTMath.toDegrees(Math.atan2(x0, z0)));
float pitch = (float)MathHelper.wrapAngleTo180_double(NGTMath.toDegrees(Math.atan2(y0, Math.sqrt(x0 * x0 + z0 * z0))));
train.setPositionAndRotation(x, y, z, yaw, pitch);
this.updateBogiePos(train, 0, true);
this.updateBogiePos(train, 1, true);
try {
Vec3 trainPos = Vec3.createVectorHelper(posX, posY, posZ);
try {
for (EntitySeat seat : getSeats()) {
setEntityPos(seat, trainPos, seat.getMove(), yaw, pitch);
}
setEntityPos(getAttacher(0), trainPos, getAttacher(0).getMove(), yaw, pitch);
setEntityPos(getAttacher(1), trainPos, getAttacher(1).getMove(), yaw, pitch);
} catch (NullPointerException e) {}
} catch (NullPointerException e) {}
}
public void updateBogiePos(EntityTrainBase train, int bogieIndex, boolean updateRotation) {
ArrayList<String[]> pos = ((ModelConfigTrain) train.getModel().config).bogies;
Vec3 v31 = Vec3.createVectorHelper(Float.parseFloat(pos.get(bogieIndex)[0]), Float.parseFloat(pos.get(bogieIndex)[1]), Float.parseFloat(pos.get(bogieIndex)[2]));
v31.rotateAroundX(NGTMath.toRadians(train.rotationPitch));
v31.rotateAroundY(NGTMath.toRadians(train.rotationYaw));
this.getBogie(bogieIndex).moveBogie(train.posX + v31.xCoord, train.posY + v31.yCoord, train.posZ + v31.zCoord, updateRotation);
}
@Override
public void setPositionAndRotation(double x, double y, double z, float yaw, float pitch)
{
this.setPosition(x, y, z);
this.setRotation(yaw, pitch);
}
@Override
protected void setRotation(float yaw, float pitch)
{
this.rotationYaw = MathHelper.wrapAngleTo180_float(yaw);
this.rotationPitch = MathHelper.wrapAngleTo180_float(pitch);
}
@Override
@SideOnly(Side.CLIENT)
public void setPositionAndRotation2(double par1, double par3, double par5, float par7, float par8, int par9)
{
this.carPosRotationIncrements = par9;
this.carX = par1;
this.carY = par3;
this.carZ = par5;
this.carYaw = par7;
this.carPitch = par8;
}
@Override
@SideOnly(Side.CLIENT)
public void setVelocity(double par1, double par3, double par5)
{
this.carSpeed = (float)par1;
}
@Override
public double getMountedYOffset()
{
return (double)(this.height - 0.93F);
}
@Override
public boolean attackEntityFrom(DamageSource par1, float par2) {
if(this.isEntityInvulnerable() || this.isDead) return false;
else {
if(!par1.isExplosion() && par1.getEntity() instanceof EntityPlayer) {
if(!this.worldObj.isRemote) {
this.setDead();
for (EntitySeat seat : this.getSeats()) {
if (seat != null) seat.setDead();
}
try {
this.getBogie(0).setDead();
this.getBogie(1).setDead();
worldObj.getEntityByID(this.dataWatcher.getWatchableObjectInt(DW_Attacher0)).setDead();
worldObj.getEntityByID(this.dataWatcher.getWatchableObjectInt(DW_Attacher1)).setDead();
} catch (NullPointerException e) {}
}
return true;
}
}
return false;
}
@Override
public boolean interactFirst(EntityPlayer player) {
if(NGTUtil.isEquippedItem(player, RTMItem.paddle)) {
//Debug
if(!this.worldObj.isRemote) {
NGTLog.sendChatMessage(player, "UUID:" + this.getUniqueID().toString() + "(train)");
}
return true;
}
return false;
}
public void connectTrain(EntityBogie par1, EntityBogie par2)
{
if(!this.worldObj.isRemote && par2.getTrain() != null)
{
//int id1 = par1.getBogieId();
//int id2 = par2.getBogieId();
// TODO сцепка
/*if(id1 >= 0 && id2 >= 0 && this.getConnectedTrain(id1) == null && par2.getTrain().formation != null)
{
this.formation.connectTrain(this, par2.getTrain(), id1, id2, par2.getTrain().formation);
this.worldObj.playAuxSFX(1022, (int)par1.posX, (int)par1.posY, (int)par1.posZ, 0);
EntityPlayer player = null;
if(this.riddenByEntity instanceof EntityPlayer)
{
player = (EntityPlayer)this.riddenByEntity;
}
else if(par2.getTrain().riddenByEntity instanceof EntityPlayer)
{
player = (EntityPlayer)par2.getTrain().riddenByEntity;
}
if(player != null)
{
NGTLog.sendChatMessage(player, "message.train.concatenated");
}
}*/
}
}
@Override
public String getDefaultName() {
// TODO дефолт модель
return "GR_VL80c";
}
@Override
public float getSpeed() {
return (worldObj.isRemote) ? this.dataWatcher.getWatchableObjectFloat(DW_Speed) : trainSpeed;
}
protected void setSpeed(float par1) {
trainSpeed = par1;
this.dataWatcher.updateObject(DW_Speed, par1);
}
public void stopTrain(boolean changeSpeed) {
this.setSpeed(0.0F);
}
public boolean isControlCar() {
// TODO
return true;
}
public boolean existBogies() {
return this.getBogie(0) != null && this.getBogie(1) != null;
}
public EntityBogie getBogie(int bogieId) {
int id = bogieId == 0 ? DW_Bogie0 : DW_Bogie1;
Entity entity = this.worldObj.getEntityByID(this.dataWatcher.getWatchableObjectInt(id));
if (entity instanceof EntityBogie) return (EntityBogie) entity;
else return null;
}
public void setBogie(int id, EntityBogie bogie) {
int dwid = id == 0 ? DW_Bogie0 : DW_Bogie1;
this.dataWatcher.updateObject(dwid, Integer.valueOf(bogie.getEntityId()));
}
public void setReverce(int reverce) {
this.dataWatcher.updateObject(DW_Reverce, reverce);
}
public int getReverce() {
return this.dataWatcher.getWatchableObjectInt(DW_Reverce);
}
public int getPosition() {
return this.dataWatcher.getWatchableObjectInt(DW_Position);
}
public boolean addPosition(Entity driver, int par2) {
if(par2 != 0) {
int i = this.getPosition();
if(this.setPosition(i + par2)) {
driver.worldObj.playSoundAtEntity(driver, "rtm:train.lever", 1.0F, 1.0F);
if(i < 0 && par2 > 0 && !this.worldObj.isRemote) {
this.playBrakeReleaseSound(i == -1);
}
return true;
}
}
return false;
}
public boolean setPosition(int par1) {
if(this.isControlCar() && (this.getTrainStateData(3) != 0 || this.getTrainStateData(4) != 0)) {
if(par1 <= ((ModelConfigTrain) getModel().config).positions.size() && par1 >= -8) {
int prevNotch = this.getPosition();
if(prevNotch != par1) {
this.dataWatcher.updateObject(DW_Position, par1);
return true;
}
}
}
return false;
}
/**
* 1:doorLeft <br>
* 2:doorRight <br>
* 3:pantFront <br>
* 4:pantBack <br>
* 5:intLight <br>
* 6:lights <br>
*/
public int getTrainStateData(int id) {
MultiMessage msg = new MultiMessage(this.dataWatcher.getWatchableObjectString(DW_Data));
return msg.getInteger("data" + id);
}
public void setTrainStateData(int id, int data) {
MultiMessage msg = new MultiMessage(this.dataWatcher.getWatchableObjectString(DW_Data));
msg.addInteger("data" + id, data);
this.dataWatcher.updateObject(DW_Data, msg.getMessage());
}
/**DataWatcher.updateWatchedObjectsFromList()から�び出される*/
@Override
public void func_145781_i(int par1) {
/*if(par1 == DW_FormationData && this.worldObj.isRemote)
{
this.createFormation();
}*/
}
@SideOnly(Side.CLIENT)
public float getRollsignAnimation() {
return (float)this.rollsignAnimation / 16.0F;
}
@SideOnly(Side.CLIENT)
public void setRollsignAnimation(int par1) {
this.rollsignV = par1 * 16;
}
@SideOnly(Side.CLIENT)
@Override
protected boolean useInteriorLight() {
return this.getTrainStateData(5) > 0;
}
@Override
protected float getMoveDir() {
return getReverce();
}
}