use of club.nsdn.nyasamarailway.network.TrainPacket in project NyaSamaRailway by NSDN.
the class ItemNTP8Bit method onCreated.
@Override
public void onCreated(ItemStack itemStack, World world, EntityPlayer player) {
power.set(itemStack, 0);
brake.set(itemStack, 5);
dir.set(itemStack, 0);
cart.set(itemStack, -1);
if (player instanceof EntityPlayerMP) {
TrainPacket packet = new TrainPacket();
packet.fromStack(itemStack);
NetworkWrapper.instance.sendTo(packet, (EntityPlayerMP) player);
}
}
use of club.nsdn.nyasamarailway.network.TrainPacket in project NyaSamaRailway by NSDN.
the class ItemNTP8Bit method onUpdate.
@Override
public void onUpdate(ItemStack itemStack, World world, Entity entity, int index, boolean inHand) {
if (!world.isRemote && inHand) {
if (entity instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) entity;
TrainPacket packet = new TrainPacket();
packet.P = this.power.get(itemStack);
packet.R = this.brake.get(itemStack);
packet.Dir = this.dir.get(itemStack);
packet.dimensionID = player.dimension;
EntityMinecart cart = packet.getCartInServer(this.cart.get(itemStack));
if (cart != null) {
if (cart instanceof LocoBase) {
((LocoBase) cart).setTrainPacket(packet);
return;
}
if (Traincraft.getInstance() != null) {
if (Traincraft.instance.isLocomotive(cart)) {
Traincraft.instance.Locomotive_setIsLocoTurnedOn(cart, true);
}
}
packet.Velocity = Dynamics.vel(cart.motionX, cart.motionZ);
TrainController.doMotion(packet, cart);
}
}
}
}
use of club.nsdn.nyasamarailway.network.TrainPacket in project NyaSamaRailway by NSDN.
the class NSPCT4 method applyDrag.
@Override
protected void applyDrag() {
if (this.motorState) {
TrainPacket tmpPacket = new TrainPacket(getMotorPower(), getMotorBrake(), getMotorDir());
// High speed
tmpPacket.highSpeed = true;
tmpPacket.Velocity = this.Velocity;
if (this.maxVelocity > 0) {
if (this.Velocity > this.maxVelocity && tmpMotorBrake == -1) {
tmpMotorBrake = getMotorBrake();
setMotorBrake(1);
} else if (this.Velocity > this.maxVelocity && tmpMotorBrake != -1) {
setMotorBrake(1);
} else if (this.Velocity <= this.maxVelocity && tmpMotorBrake != -1) {
setMotorBrake(tmpMotorBrake);
tmpMotorBrake = -1;
}
}
TrainController.doMotionWithAir(tmpPacket, this);
setMotorVel((float) tmpPacket.Velocity);
} else {
if (this.motionX != 0)
setMotorDir((int) Math.signum(this.motionX / Math.cos(TrainController.calcYaw(this) * Math.PI / 180.0)));
else if (this.motionZ != 0)
setMotorDir((int) Math.signum(this.motionZ / -Math.sin(TrainController.calcYaw(this) * Math.PI / 180.0)));
else
setMotorDir(0);
setMotorVel((float) Math.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ));
}
super.applyDrag();
}
use of club.nsdn.nyasamarailway.network.TrainPacket in project NyaSamaRailway by NSDN.
the class NSPCT8 method applyDrag.
@Override
protected void applyDrag() {
if (this.motorState) {
TrainPacket tmpPacket = new TrainPacket(getMotorPower(), getMotorBrake(), getMotorDir());
// High speed
tmpPacket.highSpeed = true;
tmpPacket.Velocity = this.Velocity;
if (this.maxVelocity > 0) {
if (this.Velocity > this.maxVelocity && tmpMotorBrake == -1) {
tmpMotorBrake = getMotorBrake();
setMotorBrake(1);
} else if (this.Velocity > this.maxVelocity && tmpMotorBrake != -1) {
setMotorBrake(1);
} else if (this.Velocity <= this.maxVelocity && tmpMotorBrake != -1) {
setMotorBrake(tmpMotorBrake);
tmpMotorBrake = -1;
}
}
TrainController.doMotionWithAir(tmpPacket, this);
setMotorVel((float) tmpPacket.Velocity);
} else {
if (this.motionX != 0)
setMotorDir((int) Math.signum(this.motionX / Math.cos(TrainController.calcYaw(this) * Math.PI / 180.0)));
else if (this.motionZ != 0)
setMotorDir((int) Math.signum(this.motionZ / -Math.sin(TrainController.calcYaw(this) * Math.PI / 180.0)));
else
setMotorDir(0);
setMotorVel((float) Math.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ));
}
super.applyDrag();
}
use of club.nsdn.nyasamarailway.network.TrainPacket in project NyaSamaRailway by NSDN.
the class NSPCT8W method applyDrag.
@Override
protected void applyDrag() {
if (this.motorState) {
TrainPacket tmpPacket = new TrainPacket(getMotorPower(), getMotorBrake(), getMotorDir());
// High speed
tmpPacket.highSpeed = true;
tmpPacket.Velocity = this.Velocity;
if (this.maxVelocity > 0) {
if (this.Velocity > this.maxVelocity && tmpMotorBrake == -1) {
tmpMotorBrake = getMotorBrake();
setMotorBrake(1);
} else if (this.Velocity > this.maxVelocity && tmpMotorBrake != -1) {
setMotorBrake(1);
} else if (this.Velocity <= this.maxVelocity && tmpMotorBrake != -1) {
setMotorBrake(tmpMotorBrake);
tmpMotorBrake = -1;
}
}
TrainController.doMotionWithAir(tmpPacket, this);
setMotorVel((float) tmpPacket.Velocity);
} else {
if (this.motionX != 0)
setMotorDir((int) Math.signum(this.motionX / Math.cos(TrainController.calcYaw(this) * Math.PI / 180.0)));
else if (this.motionZ != 0)
setMotorDir((int) Math.signum(this.motionZ / -Math.sin(TrainController.calcYaw(this) * Math.PI / 180.0)));
else
setMotorDir(0);
setMotorVel((float) Math.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ));
}
super.applyDrag();
}
Aggregations