use of net.minecraft.util.Vec3 in project NyaSamaRailway by NSDN.
the class NSPCT8Renderer method doRender.
@Override
public void doRender(EntityMinecart minecart, double x, double y, double z, float Yaw, float p_doRender_9_) {
GL11.glPushMatrix();
this.bindEntityTexture(minecart);
long var10 = (long) minecart.getEntityId() * 493286711L;
var10 = var10 * var10 * 4392167121L + var10 * 98761L;
float var12 = (((float) (var10 >> 16 & 7L) + 0.5F) / 8.0F - 0.5F) * 0.004F;
float var13 = (((float) (var10 >> 20 & 7L) + 0.5F) / 8.0F - 0.5F) * 0.004F;
float var14 = (((float) (var10 >> 24 & 7L) + 0.5F) / 8.0F - 0.5F) * 0.004F;
GL11.glTranslatef(var12, var13, var14);
double var15 = minecart.lastTickPosX + (minecart.posX - minecart.lastTickPosX) * (double) p_doRender_9_;
double var17 = minecart.lastTickPosY + (minecart.posY - minecart.lastTickPosY) * (double) p_doRender_9_;
double var19 = minecart.lastTickPosZ + (minecart.posZ - minecart.lastTickPosZ) * (double) p_doRender_9_;
double var21 = 0.30000001192092896D;
Vec3 var23 = minecart.func_70489_a(var15, var17, var19);
float var24 = minecart.prevRotationPitch + (minecart.rotationPitch - minecart.prevRotationPitch) * p_doRender_9_;
if (var23 != null) {
Vec3 var25 = minecart.func_70495_a(var15, var17, var19, var21);
Vec3 var26 = minecart.func_70495_a(var15, var17, var19, -var21);
if (var25 == null) {
var25 = var23;
}
if (var26 == null) {
var26 = var23;
}
x += var23.xCoord - var15;
y += (var25.yCoord + var26.yCoord) / 2.0D - var17;
z += var23.zCoord - var19;
Vec3 var27 = var26.addVector(-var25.xCoord, -var25.yCoord, -var25.zCoord);
if (var27.lengthVector() != 0.0D) {
var27 = var27.normalize();
Yaw = (float) (Math.atan2(var27.zCoord, var27.xCoord) * 180.0D / 3.141592653589793D);
var24 = (float) (Math.atan(var27.yCoord) * 73.0D);
}
}
GL11.glTranslatef((float) x, (float) y, (float) z);
GL11.glRotatef(180.0F - Yaw, 0.0F, 1.0F, 0.0F);
GL11.glRotatef(-var24, 0.0F, 0.0F, 1.0F);
float var31 = (float) minecart.getRollingAmplitude() - p_doRender_9_;
float var32 = minecart.getDamage() - p_doRender_9_;
if (var32 < 0.0F) {
var32 = 0.0F;
}
if (var31 > 0.0F) {
GL11.glRotatef(MathHelper.sin(var31) * var31 * var32 / 10.0F * (float) minecart.getRollingDirection(), 1.0F, 0.0F, 0.0F);
}
int var33 = minecart.getDisplayTileOffset();
Block var28 = minecart.func_145820_n();
int var29 = minecart.getDisplayTileData();
if (var28.getRenderType() != -1) {
GL11.glPushMatrix();
this.bindTexture(TextureMap.locationBlocksTexture);
float var30 = 0.75F;
GL11.glScalef(var30, var30, var30);
GL11.glTranslatef(0.0F, (float) var33 / 16.0F, 0.0F);
this.func_147910_a(minecart, p_doRender_9_, var28, var29);
GL11.glPopMatrix();
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.bindEntityTexture(minecart);
}
RendererHelper.renderWithResource(modelBase, textureBase);
RendererHelper.renderWithResource(modelPrint, texturePrint);
if (minecart.riddenByEntity != null) {
if (minecart.riddenByEntity instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) minecart.riddenByEntity;
if (player.getCurrentEquippedItem() != null) {
if (player.getCurrentEquippedItem().getItem() instanceof ItemToolBase) {
RendererHelper.beginSpecialLightingNoDepth();
doRenderHUD(minecart);
GL11.glPushMatrix();
GL11.glRotatef(180.0F, 0.0F, 1.0F, 0.0F);
doRenderHUD(minecart);
GL11.glPopMatrix();
RendererHelper.endSpecialLightingNoDepth();
}
}
}
}
GL11.glPopMatrix();
}
use of net.minecraft.util.Vec3 in project NyaSamaRailway by NSDN.
the class MinecartBase method func_145821_a.
// applyPush()
@Override
protected void func_145821_a(int x, int y, int z, double maxVel, double slopeAdj, Block block, int meta) {
// applyPush
if (worldObj.getTileEntity(x, y, z) instanceof TileEntityTrackSideReception) {
TileEntityTrackSideReception reception = (TileEntityTrackSideReception) worldObj.getTileEntity(x, y, z);
if (riddenByEntity == null && !reception.cartType.isEmpty()) {
if (!reception.cartType.equals("loco"))
return;
}
}
if (block instanceof BlockRailReception) {
BlockRailReception.TileEntityRailReception tile = (BlockRailReception.TileEntityRailReception) worldObj.getTileEntity(x, y, z);
if (!((BlockRailReception) block).checkNearbySameRail(worldObj, x, y, z))
if (riddenByEntity == null && !tile.cartType.isEmpty()) {
if (!tile.cartType.equals("loco"))
return;
}
}
if (block instanceof BlockRailReceptionAnti) {
BlockRailReceptionAnti.TileEntityRailReceptionAnti tile = (BlockRailReceptionAnti.TileEntityRailReceptionAnti) worldObj.getTileEntity(x, y, z);
if (!((BlockRailReceptionAnti) block).checkNearbySameRail(worldObj, x, y, z))
if (riddenByEntity == null && !tile.cartType.isEmpty()) {
if (!tile.cartType.equals("loco"))
return;
}
}
if (block instanceof RailMonoMagnetReception) {
RailMonoMagnetReception.TileEntityRail tile = (RailMonoMagnetReception.TileEntityRail) worldObj.getTileEntity(x, y, z);
if (!((RailMonoMagnetReception) block).checkNearbySameRail(worldObj, x, y, z))
if (riddenByEntity == null && !tile.cartType.isEmpty())
return;
}
if (block instanceof RailMonoMagnetReceptionAnti) {
RailMonoMagnetReceptionAnti.TileEntityRail tile = (RailMonoMagnetReceptionAnti.TileEntityRail) worldObj.getTileEntity(x, y, z);
if (!((RailMonoMagnetReceptionAnti) block).checkNearbySameRail(worldObj, x, y, z))
if (riddenByEntity == null && !tile.cartType.isEmpty())
return;
}
/* ******************************** MAIN FUNC ******************************** */
this.fallDistance = 0.0F;
Vec3 vec3 = this.func_70489_a(this.posX, this.posY, this.posZ);
this.posY = (double) y;
boolean isRailPowered = false;
boolean slowDown = false;
if (block == Blocks.golden_rail) {
// Stock Powered Rail, Push-Brake
isRailPowered = (this.worldObj.getBlockMetadata(x, y, z) & 8) != 0;
slowDown = !isRailPowered;
}
if (((BlockRailBase) block).isPowered()) {
meta &= 7;
}
if (meta >= 2 && meta <= 5) {
this.posY = (double) (y + 1);
}
if (meta == 2) {
this.motionX -= slopeAdj;
}
if (meta == 3) {
this.motionX += slopeAdj;
}
if (meta == 4) {
this.motionZ += slopeAdj;
}
if (meta == 5) {
this.motionZ -= slopeAdj;
}
int[][] aint = matrix[meta];
double d2 = (double) (aint[1][0] - aint[0][0]);
double d3 = (double) (aint[1][2] - aint[0][2]);
double d4 = Math.sqrt(d2 * d2 + d3 * d3);
double d5 = this.motionX * d2 + this.motionZ * d3;
if (d5 < 0.0D) {
d2 = -d2;
d3 = -d3;
}
double vel = Math.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
if (vel > getMaxCartSpeedOnRail()) {
vel = getMaxCartSpeedOnRail();
}
this.motionX = vel * d2 / d4;
this.motionZ = vel * d3 / d4;
double d7;
double d8;
double d9;
double d10;
if (this.riddenByEntity != null && this.riddenByEntity instanceof EntityLivingBase) {
d7 = (double) ((EntityLivingBase) this.riddenByEntity).moveForward;
if (d7 > 0.0D) {
d8 = -Math.sin((double) (this.riddenByEntity.rotationYaw * 3.1415927F / 180.0F));
d9 = Math.cos((double) (this.riddenByEntity.rotationYaw * 3.1415927F / 180.0F));
d10 = this.motionX * this.motionX + this.motionZ * this.motionZ;
if (d10 < 0.01D) {
this.motionX += d8 * 0.1D;
this.motionZ += d9 * 0.1D;
slowDown = false;
}
}
}
if (slowDown && this.shouldDoRailFunctions()) {
d7 = Math.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
if (d7 < 0.03D) {
this.motionX *= 0.0D;
this.motionY *= 0.0D;
this.motionZ *= 0.0D;
} else {
this.motionX *= 0.5D;
this.motionY *= 0.0D;
this.motionZ *= 0.5D;
}
}
d7 = 0.0D;
d8 = (double) x + 0.5D + (double) aint[0][0] * 0.5D;
d9 = (double) z + 0.5D + (double) aint[0][2] * 0.5D;
d10 = (double) x + 0.5D + (double) aint[1][0] * 0.5D;
double d11 = (double) z + 0.5D + (double) aint[1][2] * 0.5D;
d2 = d10 - d8;
d3 = d11 - d9;
if (d2 == 0.0D) {
this.posX = (double) x + 0.5D;
d7 = this.posZ - (double) z;
} else if (d3 == 0.0D) {
this.posZ = (double) z + 0.5D;
d7 = this.posX - (double) x;
} else {
double d12 = this.posX - d8;
double d13 = this.posZ - d9;
d7 = (d12 * d2 + d13 * d3) * 2.0D;
}
this.posX = d8 + d2 * d7;
this.posZ = d9 + d3 * d7;
this.setPosition(this.posX, this.posY + (double) this.yOffset, this.posZ);
this.moveMinecartOnRail(x, y, z, maxVel);
if (aint[0][1] != 0 && MathHelper.floor_double(this.posX) - x == aint[0][0] && MathHelper.floor_double(this.posZ) - z == aint[0][2]) {
this.setPosition(this.posX, this.posY + (double) aint[0][1], this.posZ);
} else if (aint[1][1] != 0 && MathHelper.floor_double(this.posX) - x == aint[1][0] && MathHelper.floor_double(this.posZ) - z == aint[1][2]) {
this.setPosition(this.posX, this.posY + (double) aint[1][1], this.posZ);
}
this.applyDrag();
Vec3 vec31 = this.func_70489_a(this.posX, this.posY, this.posZ);
if (vec31 != null && vec3 != null) {
double d14 = (vec3.yCoord - vec31.yCoord) * 0.05D;
vel = Math.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
if (vel > 0.0D) {
this.motionX = this.motionX / vel * (vel + d14);
this.motionZ = this.motionZ / vel * (vel + d14);
}
this.setPosition(this.posX, vec31.yCoord, this.posZ);
}
/**
* HOLY SHIT! THE CODE CAUSES BUG!
* int pX = MathHelper.floor_double(this.posX);
* int pZ = MathHelper.floor_double(this.posZ);
* if (pX != x || pZ != z) {
* vel = Math.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
* this.motionX = vel * (double)(pX - x);
* this.motionZ = vel * (double)(pZ - z);
* }
*/
if (this.shouldDoRailFunctions()) {
((BlockRailBase) block).onMinecartPass(this.worldObj, this, x, y, z);
}
if (isRailPowered && this.shouldDoRailFunctions()) {
double d15 = Math.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
if (d15 > 0.01D) {
double d16 = 0.06D;
this.motionX += this.motionX / d15 * d16;
this.motionZ += this.motionZ / d15 * d16;
} else if (meta == 1) {
if (this.worldObj.getBlock(x - 1, y, z).isNormalCube()) {
this.motionX = 0.02D;
} else if (this.worldObj.getBlock(x + 1, y, z).isNormalCube()) {
this.motionX = -0.02D;
}
} else if (meta == 0) {
if (this.worldObj.getBlock(x, y, z - 1).isNormalCube()) {
this.motionZ = 0.02D;
} else if (this.worldObj.getBlock(x, y, z + 1).isNormalCube()) {
this.motionZ = -0.02D;
}
}
}
}
use of net.minecraft.util.Vec3 in project NyaSamaRailway by NSDN.
the class TrainBase method calcProjection.
Vec3 calcProjection(Vec3 vec, Vec3 dest) {
double length = vec.dotProduct(dest) / dest.lengthVector();
Vec3 nor = dest.normalize();
nor.xCoord *= length;
nor.yCoord *= length;
nor.zCoord *= length;
return nor;
}
use of net.minecraft.util.Vec3 in project NyaSamaRailway by NSDN.
the class NSPCT8W method updateRiderPosition.
@Override
public void updateRiderPosition() {
if (this.riddenByEntity != null) {
double x = this.posX, y = this.posY, z = this.posZ;
int bx = MathHelper.floor_double(x);
int by = MathHelper.floor_double(y);
int bz = MathHelper.floor_double(z);
Block block = worldObj.getBlock(bx, by, bz);
int meta = worldObj.getBlockMetadata(bx, by, bz);
double len = -1.0 + getShiftYCnt();
Vec3 mod = Vec3.createVectorHelper(0, len, 0);
mod.rotateAroundX(this.rotationPitch);
mod.rotateAroundY(this.rotationYaw);
x += mod.xCoord;
y += mod.yCoord;
z += mod.zCoord;
this.riddenByEntity.setPositionAndRotation(x, y + this.getMountedYOffset(), z, this.rotationYaw, 0.0F);
if (this.riddenByEntity instanceof Container && worldObj.isRemote) {
Container container = (Container) this.riddenByEntity;
container.setPositionAndRotation2(x, y + this.getMountedYOffset(), z, this.rotationYaw, 0.0F, -2);
boolean fix = true;
if (block instanceof BlockRailBase) {
fix = ((BlockRailBase) block).isPowered() || meta < 6 || meta > 9;
}
if ((((int) container.rotationYaw) % 90) != 0 && fix) {
container.prevRotationYaw = container.rotationYaw = (float) (MathHelper.floor_double((double) (this.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3) * 90.0F;
}
}
}
}
use of net.minecraft.util.Vec3 in project NyaSamaRailway by NSDN.
the class NSPCT8C method updateRiderPosition.
@Override
public void updateRiderPosition() {
if (this.riddenByEntity != null) {
double x = this.posX, y = this.posY, z = this.posZ;
int bx = MathHelper.floor_double(x);
int by = MathHelper.floor_double(y);
int bz = MathHelper.floor_double(z);
Block block = worldObj.getBlock(bx, by, bz);
int meta = worldObj.getBlockMetadata(bx, by, bz);
double len = -1.0 + getShiftYCnt();
Vec3 mod = Vec3.createVectorHelper(0, len, 0);
mod.rotateAroundX(this.rotationPitch);
mod.rotateAroundY(this.rotationYaw);
x += mod.xCoord;
y += mod.yCoord;
z += mod.zCoord;
this.riddenByEntity.setPositionAndRotation(x, y + this.getMountedYOffset(), z, this.rotationYaw, 0.0F);
if (this.riddenByEntity instanceof Container && worldObj.isRemote) {
Container container = (Container) this.riddenByEntity;
container.setPositionAndRotation2(x, y + this.getMountedYOffset(), z, this.rotationYaw, 0.0F, -2);
boolean fix = true;
if (block instanceof BlockRailBase) {
fix = ((BlockRailBase) block).isPowered() || meta < 6 || meta > 9;
}
if ((((int) container.rotationYaw) % 90) != 0 && fix) {
container.prevRotationYaw = container.rotationYaw = (float) (MathHelper.floor_double((double) (this.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3) * 90.0F;
}
}
}
}
Aggregations