diff --git a/src/main/java/com/flansmod/client/model/AnimTankTrack.java b/src/main/java/com/flansmod/client/model/AnimTankTrack.java index e3860c231..1ba80641c 100644 --- a/src/main/java/com/flansmod/client/model/AnimTankTrack.java +++ b/src/main/java/com/flansmod/client/model/AnimTankTrack.java @@ -2,17 +2,16 @@ import java.util.ArrayList; -import net.minecraft.item.ItemStack; - import com.flansmod.common.vector.Vector3f; -public class AnimTankTrack { +public class AnimTankTrack +{ - public ArrayList points = new ArrayList(); - public float trackLinkLength = 0; + public ArrayList points; + public float trackLinkLength; - public AnimTankTrack (ArrayList trackPoints, float linkLength) + public AnimTankTrack(ArrayList trackPoints, float linkLength) { points = trackPoints; trackLinkLength = linkLength; @@ -29,7 +28,7 @@ public float distBetweenPoints(Vector3f p1, Vector3f p2) float x = p1.x - p2.x; float y = p1.y - p2.y; - distance = (float)Math.sqrt((x*x) + (y*y)); + distance = (float)Math.sqrt((x * x) + (y * y)); return distance; } @@ -37,63 +36,62 @@ public float distBetweenPoints(Vector3f p1, Vector3f p2) public float getTrackLength() { float length = 0; - for(int i = 0; i < points.size(); i++) - { - length += distBetweenPoints(points.get(i), points.get((i == 0)? points.size()-1:i-1)); - } + for(int i = 0; i < points.size(); i++) + { + length += distBetweenPoints(points.get(i), points.get((i == 0) ? points.size() - 1 : i - 1)); + } return length; } public int getTrackPart(float distance) { float length = 0; - for(int i = 0; i < points.size(); i++) - { - if(length >= distance) - { - return i; - } else { - length += distBetweenPoints(points.get(i), points.get((i == (points.size()-1))? 0:i+1)); - } - } + for(int i = 0; i < points.size(); i++) + { + if(length >= distance) + { + return i; + } + else + { + length += distBetweenPoints(points.get(i), points.get((i == (points.size() - 1)) ? 0 : i + 1)); + } + } return 0; } - + public float getProgressAlongTrackPart(float distance, int trackPart) { float length = 0; - float lastLength = 0; - for(int i = 0; i < trackPart + 1; i++) - { - if(i != 0) - { - length += distBetweenPoints(points.get(i-1), points.get(i)); - } - } + for(int i = 0; i < trackPart + 1; i++) + { + if(i != 0) + { + length += distBetweenPoints(points.get(i - 1), points.get(i)); + } + } return length; } - + public Vector3f getPositionOnTrack(float distance) { - + int trackPart = getTrackPart(distance); - Vector3f p2 = points.get((trackPart == 0)? points.size()-1:trackPart-1); + Vector3f p2 = points.get((trackPart == 0) ? points.size() - 1 : trackPart - 1); Vector3f p1 = points.get(trackPart); float partLength = distBetweenPoints(p2, p1); - float prog = distance - (getProgressAlongTrackPart(distance,(trackPart == 0)? points.size()-1:trackPart-1)); - float progress = prog/partLength; - Vector3f finalPos = new Vector3f(lerp(p2.x, p1.x, progress),lerp(p2.y, p1.y, progress), lerp(p2.z, p1.z, progress)); + float prog = + distance - (getProgressAlongTrackPart(distance, (trackPart == 0) ? points.size() - 1 : trackPart - 1)); + float progress = prog / partLength; - return finalPos; + return new Vector3f(lerp(p2.x, p1.x, progress), lerp(p2.y, p1.y, progress), lerp(p2.z, p1.z, progress)); } - public float lerp(float a, float b, float f) + public float lerp(float a, float b, float f) { - float result = (a+ f*(b - a)); - - return result; + return (a + f * (b - a)); } -} \ No newline at end of file +} diff --git a/src/main/java/com/flansmod/client/model/AnimTrackLink.java b/src/main/java/com/flansmod/client/model/AnimTrackLink.java index 75ac514bf..80526f0f1 100644 --- a/src/main/java/com/flansmod/client/model/AnimTrackLink.java +++ b/src/main/java/com/flansmod/client/model/AnimTrackLink.java @@ -3,13 +3,14 @@ import com.flansmod.common.RotatedAxes; import com.flansmod.common.vector.Vector3f; -public class AnimTrackLink { +public class AnimTrackLink +{ public Vector3f position; public Vector3f prevPosition; public float zRot = 0; public float prevZRot; - public float progress = 0; + public float progress; public RotatedAxes rot; public AnimTrackLink(float prog) diff --git a/src/main/java/com/flansmod/client/model/ModelVehicle.java b/src/main/java/com/flansmod/client/model/ModelVehicle.java index fcf03ff1f..034c5d683 100644 --- a/src/main/java/com/flansmod/client/model/ModelVehicle.java +++ b/src/main/java/com/flansmod/client/model/ModelVehicle.java @@ -12,37 +12,37 @@ //Extensible ModelVehicle class for rendering vehicle models public class ModelVehicle extends ModelDriveable { - public ModelRendererTurbo turretModel[] = new ModelRendererTurbo[0]; //The turret (for tanks) - public ModelRendererTurbo barrelModel[] = new ModelRendererTurbo[0]; //The barrel of the main turret - public ModelRendererTurbo ammoModel[][] = new ModelRendererTurbo[0][0]; //Ammo models for the main turret. ammoModel[i] will render if the vehicle has less than 3 ammo slots or if slot i is full. Checks shell / missile inventory - public ModelRendererTurbo frontWheelModel[] = new ModelRendererTurbo[0]; //Front and back wheels are for bicycles and motorbikes and whatnot - public ModelRendererTurbo backWheelModel[] = new ModelRendererTurbo[0]; - public ModelRendererTurbo leftFrontWheelModel[] = new ModelRendererTurbo[0]; //This set of 4 wheels are for 4 or more wheeled things - public ModelRendererTurbo rightFrontWheelModel[] = new ModelRendererTurbo[0]; //The front wheels will turn as the player steers, and the back ones will not - public ModelRendererTurbo leftBackWheelModel[] = new ModelRendererTurbo[0]; //They will all turn as the car drives if the option to do so is set on - public ModelRendererTurbo rightBackWheelModel[] = new ModelRendererTurbo[0]; //In the vehicle type file - public ModelRendererTurbo rightTrackModel[] = new ModelRendererTurbo[0]; - public ModelRendererTurbo leftTrackModel[] = new ModelRendererTurbo[0]; - public ModelRendererTurbo rightTrackWheelModels[] = new ModelRendererTurbo[0]; //These go with the tracks but rotate - public ModelRendererTurbo leftTrackWheelModels[] = new ModelRendererTurbo[0]; + public ModelRendererTurbo[] turretModel = new ModelRendererTurbo[0]; //The turret (for tanks) + public ModelRendererTurbo[] barrelModel = new ModelRendererTurbo[0]; //The barrel of the main turret + public ModelRendererTurbo[][] ammoModel = new ModelRendererTurbo[0][0]; //Ammo models for the main turret. ammoModel[i] will render if the vehicle has less than 3 ammo slots or if slot i is full. Checks shell / missile inventory + public ModelRendererTurbo[] frontWheelModel = new ModelRendererTurbo[0]; //Front and back wheels are for bicycles and motorbikes and whatnot + public ModelRendererTurbo[] backWheelModel = new ModelRendererTurbo[0]; + public ModelRendererTurbo[] leftFrontWheelModel = new ModelRendererTurbo[0]; //This set of 4 wheels are for 4 or more wheeled things + public ModelRendererTurbo[] rightFrontWheelModel = new ModelRendererTurbo[0]; //The front wheels will turn as the player steers, and the back ones will not + public ModelRendererTurbo[] leftBackWheelModel = new ModelRendererTurbo[0]; //They will all turn as the car drives if the option to do so is set on + public ModelRendererTurbo[] rightBackWheelModel = new ModelRendererTurbo[0]; //In the vehicle type file + public ModelRendererTurbo[] rightTrackModel = new ModelRendererTurbo[0]; + public ModelRendererTurbo[] leftTrackModel = new ModelRendererTurbo[0]; + public ModelRendererTurbo[] rightTrackWheelModels = new ModelRendererTurbo[0]; //These go with the tracks but rotate + public ModelRendererTurbo[] leftTrackWheelModels = new ModelRendererTurbo[0]; - public ModelRendererTurbo fancyTrackModel[] = new ModelRendererTurbo[0]; + public ModelRendererTurbo[] fancyTrackModel = new ModelRendererTurbo[0]; - public ModelRendererTurbo leftAnimTrackModel[][] = new ModelRendererTurbo[0][0]; //Unlimited frame track animations - public ModelRendererTurbo rightAnimTrackModel[][] = new ModelRendererTurbo[0][0]; + public ModelRendererTurbo[][] leftAnimTrackModel = new ModelRendererTurbo[0][0]; //Unlimited frame track animations + public ModelRendererTurbo[][] rightAnimTrackModel = new ModelRendererTurbo[0][0]; - public ModelRendererTurbo bodyDoorOpenModel[] = new ModelRendererTurbo[0]; - public ModelRendererTurbo bodyDoorCloseModel[] = new ModelRendererTurbo[0]; - public ModelRendererTurbo trailerModel[] = new ModelRendererTurbo[0]; - public ModelRendererTurbo steeringWheelModel[] = new ModelRendererTurbo[0]; + public ModelRendererTurbo[] bodyDoorOpenModel = new ModelRendererTurbo[0]; + public ModelRendererTurbo[] bodyDoorCloseModel = new ModelRendererTurbo[0]; + public ModelRendererTurbo[] trailerModel = new ModelRendererTurbo[0]; + public ModelRendererTurbo[] steeringWheelModel = new ModelRendererTurbo[0]; - public ModelRendererTurbo drillHeadModel[] = new ModelRendererTurbo[0]; //Drill head. Rotates around + public ModelRendererTurbo[] drillHeadModel = new ModelRendererTurbo[0]; //Drill head. Rotates around public Vector3f drillHeadOrigin = new Vector3f(); //this point //recoiling barrel part - public ModelRendererTurbo animBarrelModel[] = new ModelRendererTurbo[0]; + public ModelRendererTurbo[] animBarrelModel = new ModelRendererTurbo[0]; public Vector3f barrelAttach = new Vector3f(); public int animFrame = 0; @@ -225,7 +225,9 @@ public void render(float f5, EntityVehicle vehicle, float f) for(EntitySeat seat : vehicle.getSeats()) { //If the seat has a gun model attached - if(seat != null && seat.seatInfo != null && seat.seatInfo.gunName != null && gunModels.get(seat.seatInfo.gunName) != null && vehicle.isPartIntact(seat.seatInfo.part) && !vehicle.rotateWithTurret(seat.seatInfo)) + if(seat != null && seat.seatInfo != null && seat.seatInfo.gunName != null && + gunModels.get(seat.seatInfo.gunName) != null && vehicle.isPartIntact(seat.seatInfo.part) && + !vehicle.rotateWithTurret(seat.seatInfo)) { float yaw = seat.prevLooking.getYaw() + (seat.looking.getYaw() - seat.prevLooking.getYaw()) * f; float pitch = seat.prevLooking.getPitch() + (seat.looking.getPitch() - seat.prevLooking.getPitch()) * f; @@ -299,13 +301,17 @@ public void renderTurret(float f, float f1, float f2, float f3, float f4, float for(EntitySeat seat : vehicle.getSeats()) { //If the seat has a gun model attached - if(seat != null && seat.seatInfo != null && seat.seatInfo.gunName != null && gunModels.get(seat.seatInfo.gunName) != null && vehicle.isPartIntact(seat.seatInfo.part) && vehicle.rotateWithTurret(seat.seatInfo)) + if(seat != null && seat.seatInfo != null && seat.seatInfo.gunName != null && + gunModels.get(seat.seatInfo.gunName) != null && vehicle.isPartIntact(seat.seatInfo.part) && + vehicle.rotateWithTurret(seat.seatInfo)) { EntitySeat driverSeat = vehicle.getSeat(0); - float driverYaw = driverSeat.prevLooking.getYaw() + (driverSeat.looking.getYaw() - driverSeat.prevLooking.getYaw()) * dt; + float driverYaw = driverSeat.prevLooking.getYaw() + + (driverSeat.looking.getYaw() - driverSeat.prevLooking.getYaw()) * dt; float yaw = seat.prevLooking.getYaw() + (seat.looking.getYaw() - seat.prevLooking.getYaw()) * dt; - float pitch = seat.prevLooking.getPitch() + (seat.looking.getPitch() - seat.prevLooking.getPitch()) * dt; + float pitch = + seat.prevLooking.getPitch() + (seat.looking.getPitch() - seat.prevLooking.getPitch()) * dt; float effectiveYaw = yaw - driverYaw; @@ -338,14 +344,16 @@ public void renderTurret(float f, float f1, float f2, float f3, float f4, float } } - public void renderAnimBarrel(float f, float f1, float f2, float f3, float f4, float f5, EntityVehicle vehicle, float dt) + public void renderAnimBarrel(float f, float f1, float f2, float f3, float f4, float f5, EntityVehicle vehicle, + float dt) { - if(vehicle.isPartIntact(EnumDriveablePart.turret)) - { - for (ModelRendererTurbo aAnimBarrelModel : animBarrelModel) { + if(vehicle.isPartIntact(EnumDriveablePart.turret)) + { + for(ModelRendererTurbo aAnimBarrelModel : animBarrelModel) + { aAnimBarrelModel.render(f5, oldRotateOrder); } - } + } } public void renderDrillBit(EntityVehicle vehicle, float f) @@ -361,7 +369,8 @@ public void renderDrillBit(EntityVehicle vehicle, float f) public void renderFancyTracks(EntityVehicle vehicle, float f) { - for (ModelRendererTurbo adrillHeadModel : fancyTrackModel) { + for(ModelRendererTurbo adrillHeadModel : fancyTrackModel) + { adrillHeadModel.render(0.0625F, oldRotateOrder); } } diff --git a/src/main/java/com/flansmod/client/model/RenderVehicle.java b/src/main/java/com/flansmod/client/model/RenderVehicle.java index a67846ce1..788f585df 100644 --- a/src/main/java/com/flansmod/client/model/RenderVehicle.java +++ b/src/main/java/com/flansmod/client/model/RenderVehicle.java @@ -84,42 +84,52 @@ public void render(EntityVehicle vehicle, double d, double d1, double d2, float float modelScale = type.modelScale; GlStateManager.pushMatrix(); { - float recoilDPos = (float)Math.sin(Math.toRadians(vehicle.recoilPos)) - (float)Math.sin(Math.toRadians(vehicle.lastRecoilPos)); - float recoilPos = (float)Math.sin(Math.toRadians(vehicle.lastRecoilPos)) + recoilDPos*f1; + float recoilDPos = (float)Math.sin(Math.toRadians(vehicle.recoilPos)) - + (float)Math.sin(Math.toRadians(vehicle.lastRecoilPos)); + float recoilPos = (float)Math.sin(Math.toRadians(vehicle.lastRecoilPos)) + recoilDPos * f1; GlStateManager.scale(modelScale, modelScale, modelScale); ModelVehicle modVehicle = (ModelVehicle)type.model; if(modVehicle != null) modVehicle.render(vehicle, f1); - for(int i = 0; i < vehicle.trackLinksLeft.length; i++) - { - AnimTrackLink link = vehicle.trackLinksLeft[i]; - float rotZ = link.zRot; - GL11.glPushMatrix(); - GL11.glTranslatef(link.position.x/16F, link.position.y/16F, link.position.z/16F); - for(; rotZ > 180F; rotZ -= 360F) {} - for(; rotZ <= -180F; rotZ += 360F) {} - GL11.glRotatef(rotZ * (float)(180/Math.PI), 0, 0, 1); - modVehicle.renderFancyTracks(vehicle, f1); - GL11.glPopMatrix(); - } - - for(int i = 0; i < vehicle.trackLinksRight.length; i++) - { - AnimTrackLink link = vehicle.trackLinksRight[i]; - float rotZ = link.zRot; - for(; rotZ > 180F; rotZ -= 360F) {} - for(; rotZ <= -180F; rotZ += 360F) {} - GL11.glPushMatrix(); - GL11.glTranslatef(link.position.x/16F, link.position.y/16F, link.position.z/16F); - GL11.glRotatef(rotZ * (float)(180/Math.PI), 0, 0, 1); - modVehicle.renderFancyTracks(vehicle, f1); - GL11.glPopMatrix(); - } + for(int i = 0; i < vehicle.trackLinksLeft.length; i++) + { + AnimTrackLink link = vehicle.trackLinksLeft[i]; + float rotZ = link.zRot; + GL11.glPushMatrix(); + GL11.glTranslatef(link.position.x / 16F, link.position.y / 16F, link.position.z / 16F); + for(; rotZ > 180F; rotZ -= 360F) + { + } + for(; rotZ <= -180F; rotZ += 360F) + { + } + GL11.glRotatef(rotZ * (float)(180 / Math.PI), 0, 0, 1); + modVehicle.renderFancyTracks(vehicle, f1); + GL11.glPopMatrix(); + } + + for(int i = 0; i < vehicle.trackLinksRight.length; i++) + { + AnimTrackLink link = vehicle.trackLinksRight[i]; + float rotZ = link.zRot; + for(; rotZ > 180F; rotZ -= 360F) + { + } + for(; rotZ <= -180F; rotZ += 360F) + { + } + GL11.glPushMatrix(); + GL11.glTranslatef(link.position.x / 16F, link.position.y / 16F, link.position.z / 16F); + GL11.glRotatef(rotZ * (float)(180 / Math.PI), 0, 0, 1); + modVehicle.renderFancyTracks(vehicle, f1); + GL11.glPopMatrix(); + } GlStateManager.pushMatrix(); - if(type.turretOrigin != null && vehicle.isPartIntact(EnumDriveablePart.turret) && vehicle.getSeat(0) != null) + if(type.turretOrigin != null && vehicle.isPartIntact(EnumDriveablePart.turret) && + vehicle.getSeat(0) != null) { dYaw = (vehicle.getSeat(0).looking.getYaw() - vehicle.getSeat(0).prevLooking.getYaw()); while(dYaw > 180F) @@ -140,14 +150,17 @@ public void render(EntityVehicle vehicle, double d, double d1, double d2, float modVehicle.renderTurret(0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F, vehicle, f1); //rotate and render barrel - if(modVehicle != null) { + if(modVehicle != null) + { EntitySeat[] seats = vehicle.getSeats(); - GL11.glTranslatef(modVehicle.barrelAttach.x,modVehicle.barrelAttach.y, -modVehicle.barrelAttach.z); + GL11.glTranslatef(modVehicle.barrelAttach.x, + modVehicle.barrelAttach.y, + -modVehicle.barrelAttach.z); float bPitch = (seats[0].looking.getPitch() - seats[0].prevLooking.getPitch()); - float aPitch = seats[0].prevLooking.getPitch() + bPitch * f1; - + float aPitch = seats[0].prevLooking.getPitch() + bPitch * f1; + GL11.glRotatef(-aPitch, 0F, 0F, 1F); - GL11.glTranslatef(recoilPos*-(5F/16F),0F, 0F); + GL11.glTranslatef(recoilPos * -(5F / 16F), 0F, 0F); modVehicle.renderAnimBarrel(0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F, vehicle, f1); } @@ -197,10 +210,10 @@ public void render(EntityVehicle vehicle, double d, double d1, double d2, float GlStateManager.pushMatrix(); GlStateManager.translate(modVehicle.drillHeadOrigin.x, modVehicle.drillHeadOrigin.y, - modVehicle.drillHeadOrigin.z); + modVehicle.drillHeadOrigin.z); GlStateManager.rotate(vehicle.harvesterAngle * 50F, 1.0F, 0.0F, 0.0F); GlStateManager.translate(-modVehicle.drillHeadOrigin.x, -modVehicle.drillHeadOrigin.y, - -modVehicle.drillHeadOrigin.z); + -modVehicle.drillHeadOrigin.z); modVehicle.renderDrillBit(vehicle, f1); GlStateManager.popMatrix(); @@ -221,7 +234,7 @@ public void render(EntityVehicle vehicle, double d, double d1, double d2, float continue; renderOffsetAABB(new AxisAlignedBB(part.box.x, part.box.y, part.box.z, (part.box.x + part.box.w), - (part.box.y + part.box.h), (part.box.z + part.box.d)), 0, 0, 0); + (part.box.y + part.box.h), (part.box.z + part.box.d)), 0, 0, 0); } // Render shoot points @@ -333,7 +346,7 @@ public void renderItem(CustomItemRenderType type, EnumHand hand, ItemStack item, } GlStateManager.scale(scale / vehicleType.cameraDistance, scale / vehicleType.cameraDistance, - scale / vehicleType.cameraDistance); + scale / vehicleType.cameraDistance); Minecraft.getMinecraft().renderEngine.bindTexture(FlansModResourceHandler.getTexture(vehicleType)); ModelDriveable model = vehicleType.model; model.render(vehicleType); @@ -387,11 +400,11 @@ public void renderWorld(RenderWorldLastEvent event) OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, (float)j / 1.0F, (float)k / 1.0F); GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); render(vehicle, - vehicle.prevPosX + (vehicle.posX - vehicle.prevPosX) * event.getPartialTicks(), - vehicle.prevPosY + (vehicle.posY - vehicle.prevPosY) * event.getPartialTicks(), - vehicle.prevPosZ + (vehicle.posZ - vehicle.prevPosZ) * event.getPartialTicks(), - 0F, - event.getPartialTicks()); + vehicle.prevPosX + (vehicle.posX - vehicle.prevPosX) * event.getPartialTicks(), + vehicle.prevPosY + (vehicle.posY - vehicle.prevPosY) * event.getPartialTicks(), + vehicle.prevPosZ + (vehicle.posZ - vehicle.prevPosZ) * event.getPartialTicks(), + 0F, + event.getPartialTicks()); } } @@ -411,4 +424,4 @@ public Render createRenderFor(RenderManager manager) return new RenderVehicle(manager); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/flansmod/common/driveables/EntityDriveable.java b/src/main/java/com/flansmod/common/driveables/EntityDriveable.java index ff048fbf3..ad9c3e14a 100644 --- a/src/main/java/com/flansmod/common/driveables/EntityDriveable.java +++ b/src/main/java/com/flansmod/common/driveables/EntityDriveable.java @@ -1,6 +1,7 @@ package com.flansmod.common.driveables; import java.util.ArrayList; + import io.netty.buffer.ByteBuf; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; @@ -590,12 +591,14 @@ public EntityPlayer getDriver() { return ((EntityPlayer)seats[0].getControllingPassenger()); } - else { + else + { return null; } } - private void shootEach(DriveableType type, ShootPoint shootPoint, int currentGun, boolean secondary, EnumWeaponType weaponType) + private void shootEach(DriveableType type, ShootPoint shootPoint, int currentGun, boolean secondary, + EnumWeaponType weaponType) { // Rotate the gun vector to global axes Vector3f gunVec = getOrigin(shootPoint); @@ -616,44 +619,62 @@ private void shootEach(DriveableType type, ShootPoint shootPoint, int currentGun } // For each - + ItemShootable shootableItem = (ItemShootable)shootableStack.getItem(); ShootableType shootableType = shootableItem.type; - if (!gunType.isAmmo(shootableType)) + if(!gunType.isAmmo(shootableType)) return; - FireableGun fireableGun = new FireableGun(gunType, gunType.damage, gunType.bulletSpread, gunType.bulletSpeed); + FireableGun fireableGun = new FireableGun(gunType, + gunType.damage, + gunType.bulletSpread, + gunType.bulletSpeed); //TODO grenades wont work (currently no vehicle with this feature exists) - if (shootableType instanceof BulletType) - { - FiredShot shot = new FiredShot(fireableGun, (BulletType) shootableType, this, (EntityPlayerMP) getDriver()); - - ShootBulletHandler handler = (Boolean isExtraBullet) -> + if(shootableType instanceof BulletType) { - if (driverIsCreative()) - return; - if (shootableStack.getItem() instanceof ItemShootable) + FiredShot shot = new FiredShot(fireableGun, + (BulletType)shootableType, + this, + (EntityPlayerMP)getDriver()); + + ShootBulletHandler handler = (Boolean isExtraBullet) -> { - shootableStack.setItemDamage(shootableStack.getItemDamage() + 1); - if(shootableStack.getItemDamage() >= shootableStack.getMaxDamage()) + if(driverIsCreative()) + return; + if(shootableStack.getItem() instanceof ItemShootable) { - shootableStack.setItemDamage(0); - shootableStack.setCount(shootableStack.getCount() - 1); - if(shootableStack.getCount() <= 0) - driveableData.ammo[getDriveableType().numPassengerGunners + currentGun] = ItemStack.EMPTY.copy(); + shootableStack.setItemDamage(shootableStack.getItemDamage() + 1); + if(shootableStack.getItemDamage() >= shootableStack.getMaxDamage()) + { + shootableStack.setItemDamage(0); + shootableStack.setCount(shootableStack.getCount() - 1); + if(shootableStack.getCount() <= 0) + driveableData.ammo[getDriveableType().numPassengerGunners + + currentGun] = ItemStack.EMPTY.copy(); + } } + }; + + Vector3f gunVector = Vector3f.add(gunVec, new Vector3f(posX, posY, posZ), null); + + ShotHandler.fireGun(world, + shot, + gunType.numBullets * shootableType.numBullets, + gunVector, + lookVector, + handler); + + if(type.shootSound(secondary) != null) + { + PacketPlaySound.sendSoundPacket(gunVector.x, + gunVector.y, + gunVector.z, + FlansMod.soundRange, + world.provider.getDimension(), + type.shootSound(secondary), + false); } - }; - - Vector3f gunVector = Vector3f.add(gunVec, new Vector3f(posX,posY,posZ), null); - - ShotHandler.fireGun(world, shot, gunType.numBullets * shootableType.numBullets, gunVector, lookVector, handler); - - if (type.shootSound(secondary) != null) - { - PacketPlaySound.sendSoundPacket(gunVector.x, gunVector.y, gunVector.z, FlansMod.soundRange, world.provider.getDimension(), type.shootSound(secondary), false); - } } // Reset the shoot delay @@ -711,7 +732,7 @@ private void shootEach(DriveableType type, ShootPoint shootPoint, int currentGun { shootProjectile(slot, gunVec, lookVector, - type, secondary, (float)getSpeed()+3f); + type, secondary, (float)getSpeed() + 3f); } else { @@ -732,7 +753,7 @@ private void shootEach(DriveableType type, ShootPoint shootPoint, int currentGun public double getSpeed() { - return Math.sqrt(motionX*motionX + motionY*motionY + motionZ*motionZ); + return Math.sqrt(motionX * motionX + motionY * motionY + motionZ * motionZ); } public Vector3f getOrigin(ShootPoint shootPoint) @@ -759,14 +780,19 @@ public Vector3f getLookVector(ShootPoint shootPoint) return axes.getXAxis(); } - private void shootProjectile(final Integer slot, Vector3f gunVec, Vector3f lookVector, DriveableType type, Boolean secondary, float speed) + private void shootProjectile(final Integer slot, Vector3f gunVec, Vector3f lookVector, DriveableType type, + Boolean secondary, float speed) { ItemStack bullet = driveableData.getStackInSlot(slot); ItemBullet bulletItem = (ItemBullet)bullet.getItem(); int damageMultiplier = secondary ? type.damageModifierSecondary : type.damageModifierPrimary; - - FireableGun fireableGun = new FireableGun(bulletItem.type, bulletItem.type.damageVsLiving*damageMultiplier, bulletItem.type.damageVsDriveable*damageMultiplier, bulletItem.type.bulletSpread, speed); - FiredShot shot = new FiredShot(fireableGun, bulletItem.type, this, (EntityPlayerMP) getDriver()); + + FireableGun fireableGun = new FireableGun(bulletItem.type, + bulletItem.type.damageVsLiving * damageMultiplier, + bulletItem.type.damageVsDriveable * damageMultiplier, + bulletItem.type.bulletSpread, + speed); + FiredShot shot = new FiredShot(fireableGun, bulletItem.type, this, (EntityPlayerMP)getDriver()); ShootBulletHandler handler = (Boolean isExtraBullet) -> { @@ -785,14 +811,20 @@ private void shootProjectile(final Integer slot, Vector3f gunVec, Vector3f lookV } }; - Vector3f gunVector = Vector3f.add(gunVec, new Vector3f(posX,posY,posZ), null); + Vector3f gunVector = Vector3f.add(gunVec, new Vector3f(posX, posY, posZ), null); ShotHandler.fireGun(world, shot, bulletItem.type.numBullets, gunVector, lookVector, handler); - if (type.shootSound(secondary) != null) + if(type.shootSound(secondary) != null) { //TODO proper general sound implementation - PacketPlaySound.sendSoundPacket(gunVector.x, gunVector.y, gunVector.z, FlansMod.soundRange, world.provider.getDimension(), type.shootSound(secondary), false); + PacketPlaySound.sendSoundPacket(gunVector.x, + gunVector.y, + gunVector.z, + FlansMod.soundRange, + world.provider.getDimension(), + type.shootSound(secondary), + false); } // Reset the shoot delay setShootDelay(type.shootDelay(secondary), secondary); @@ -961,23 +993,24 @@ else if(passenger instanceof EntityWheel) } //Gun recoil - if(leftMouseHeld){ - tryRecoil(); - setRecoilTimer(); - } - lastRecoilPos = recoilPos; - - if(recoilPos > 180-(180/type.recoilTime)) + if(leftMouseHeld) + { + tryRecoil(); + setRecoilTimer(); + } + lastRecoilPos = recoilPos; + + if(recoilPos > 180 - (180 / type.recoilTime)) { recoilPos = 0; isRecoil = false; } if(isRecoil) - recoilPos = recoilPos + (180/type.recoilTime); + recoilPos = recoilPos + (180 / type.recoilTime); if(recoilTimer >= 0) - recoilTimer--; + recoilTimer--; for(DriveablePart part : getDriveableData().parts.values()) { @@ -1105,7 +1138,7 @@ else if(EnumDriveablePart.getPart( { throttle *= 0.98F; primaryShootHeld = secondaryShootHeld = false; - } + } else if(getDriver() != null && getDriver() == getControllingPassenger()) { reportVehicleError(); @@ -1211,34 +1244,38 @@ public void tryRecoil() { int slot = -1; DriveableType type = getDriveableType(); - for(int i = driveableData.getMissileInventoryStart(); i < driveableData.getMissileInventoryStart() + type.numMissileSlots; i++) + for(int i = driveableData.getMissileInventoryStart(); + i < driveableData.getMissileInventoryStart() + type.numMissileSlots; i++) { ItemStack shell = driveableData.getStackInSlot(i); - if(shell != null && shell.getItem() instanceof ItemBullet && type.isValidAmmo(((ItemBullet)shell.getItem()).type, EnumWeaponType.SHELL)) + if(shell != null && shell.getItem() instanceof ItemBullet && + type.isValidAmmo(((ItemBullet)shell.getItem()).type, EnumWeaponType.SHELL)) { slot = i; } } - + if(recoilTimer <= 0 && slot != -1) - isRecoil = true; + isRecoil = true; } public void setRecoilTimer() { int slot = -1; DriveableType type = getDriveableType(); - for(int i = driveableData.getMissileInventoryStart(); i < driveableData.getMissileInventoryStart() + type.numMissileSlots; i++) + for(int i = driveableData.getMissileInventoryStart(); + i < driveableData.getMissileInventoryStart() + type.numMissileSlots; i++) { ItemStack shell = driveableData.getStackInSlot(i); - if(shell != null && shell.getItem() instanceof ItemBullet && type.isValidAmmo(((ItemBullet)shell.getItem()).type, EnumWeaponType.SHELL)) + if(shell != null && shell.getItem() instanceof ItemBullet && + type.isValidAmmo(((ItemBullet)shell.getItem()).type, EnumWeaponType.SHELL)) { slot = i; } } - + if(recoilTimer <= 0 && slot != -1) - recoilTimer = getDriveableType().shootDelayPrimary; + recoilTimer = getDriveableType().shootDelayPrimary; } private Vector3f getRandPosInBoundingBox(DriveablePart part) diff --git a/src/main/java/com/flansmod/common/driveables/EntityVehicle.java b/src/main/java/com/flansmod/common/driveables/EntityVehicle.java index ebed3da59..dd1563357 100644 --- a/src/main/java/com/flansmod/common/driveables/EntityVehicle.java +++ b/src/main/java/com/flansmod/common/driveables/EntityVehicle.java @@ -1,16 +1,5 @@ package com.flansmod.common.driveables; -import com.flansmod.api.IExplodeable; -import com.flansmod.client.model.AnimTankTrack; -import com.flansmod.client.model.AnimTrackLink; -import com.flansmod.common.FlansMod; -import com.flansmod.common.RotatedAxes; -import com.flansmod.common.network.PacketPlaySound; -import com.flansmod.common.network.PacketVehicleControl; -import com.flansmod.common.teams.TeamsManager; -import com.flansmod.common.tools.ItemTool; -import com.flansmod.common.vector.Vector3f; - import io.netty.buffer.ByteBuf; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.MoverType; @@ -25,6 +14,17 @@ import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; +import com.flansmod.api.IExplodeable; +import com.flansmod.client.model.AnimTankTrack; +import com.flansmod.client.model.AnimTrackLink; +import com.flansmod.common.FlansMod; +import com.flansmod.common.RotatedAxes; +import com.flansmod.common.network.PacketPlaySound; +import com.flansmod.common.network.PacketVehicleControl; +import com.flansmod.common.teams.TeamsManager; +import com.flansmod.common.tools.ItemTool; +import com.flansmod.common.vector.Vector3f; + public class EntityVehicle extends EntityDriveable implements IExplodeable { @@ -60,8 +60,8 @@ public class EntityVehicle extends EntityDriveable implements IExplodeable public AnimTankTrack rightTrack; public AnimTankTrack leftTrack; - public AnimTrackLink trackLinksLeft[] = new AnimTrackLink[0]; - public AnimTrackLink trackLinksRight[] = new AnimTrackLink[0]; + public AnimTrackLink[] trackLinksLeft = new AnimTrackLink[0]; + public AnimTrackLink[] trackLinksRight = new AnimTrackLink[0]; public EntityVehicle(World world) { @@ -93,22 +93,30 @@ public void setupTracks(DriveableType type) { rightTrack = new AnimTankTrack(type.rightTrackPoints, type.trackLinkLength); leftTrack = new AnimTankTrack(type.leftTrackPoints, type.trackLinkLength); - int numLinks = Math.round(rightTrack.getTrackLength()/ type.trackLinkLength); + int numLinks = Math.round(rightTrack.getTrackLength() / type.trackLinkLength); trackLinksLeft = new AnimTrackLink[numLinks]; trackLinksRight = new AnimTrackLink[numLinks]; - for(int i = 0; i < numLinks; i++) - { - float progress = 0.01F + (type.trackLinkLength * i); - int trackPart = leftTrack.getTrackPart(progress); - trackLinksLeft[i] = new AnimTrackLink(progress); - trackLinksRight[i] = new AnimTrackLink(progress); - trackLinksLeft[i].position = leftTrack.getPositionOnTrack(progress); - trackLinksRight[i].position = rightTrack.getPositionOnTrack(progress); - trackLinksLeft[i].rot = new RotatedAxes(0,0,rotateTowards(leftTrack.points.get((trackPart == 0)? leftTrack.points.size()-1:trackPart-1), trackLinksLeft[i].position)); - trackLinksRight[i].rot = new RotatedAxes(0,0,rotateTowards(rightTrack.points.get((trackPart == 0)? rightTrack.points.size()-1:trackPart-1), trackLinksRight[i].position)); - trackLinksLeft[i].zRot = rotateTowards(leftTrack.points.get((trackPart == 0)? leftTrack.points.size()-1:trackPart-1), trackLinksLeft[i].position); - trackLinksRight[i].zRot = rotateTowards(rightTrack.points.get((trackPart == 0)? rightTrack.points.size()-1:trackPart-1), trackLinksRight[i].position); - } + for(int i = 0; i < numLinks; i++) + { + float progress = 0.01F + (type.trackLinkLength * i); + int trackPart = leftTrack.getTrackPart(progress); + trackLinksLeft[i] = new AnimTrackLink(progress); + trackLinksRight[i] = new AnimTrackLink(progress); + trackLinksLeft[i].position = leftTrack.getPositionOnTrack(progress); + trackLinksRight[i].position = rightTrack.getPositionOnTrack(progress); + trackLinksLeft[i].rot = new RotatedAxes(0, + 0, + rotateTowards(leftTrack.points.get((trackPart == 0) ? leftTrack.points.size() - 1 : trackPart - 1), + trackLinksLeft[i].position)); + trackLinksRight[i].rot = new RotatedAxes(0, + 0, + rotateTowards(rightTrack.points.get((trackPart == 0) ? rightTrack.points.size() - 1 : trackPart - 1), + trackLinksRight[i].position)); + trackLinksLeft[i].zRot = rotateTowards(leftTrack.points + .get((trackPart == 0) ? leftTrack.points.size() - 1 : trackPart - 1), trackLinksLeft[i].position); + trackLinksRight[i].zRot = rotateTowards(rightTrack.points + .get((trackPart == 0) ? rightTrack.points.size() - 1 : trackPart - 1), trackLinksRight[i].position); + } } @Override @@ -155,7 +163,7 @@ public void setPositionRotationAndMotion(double x, double y, double z, float yaw float velRoll, float throttle, float steeringYaw) { super.setPositionRotationAndMotion(x, y, z, yaw, pitch, roll, motX, motY, motZ, velYaw, velPitch, velRoll, - throttle, steeringYaw); + throttle, steeringYaw); wheelsYaw = steeringYaw; } @@ -288,8 +296,8 @@ public void onUpdate() //Work out if this is the client side and the player is driving boolean thePlayerIsDrivingThis = - world.isRemote && getSeat(0) != null && getSeat(0).getControllingPassenger() instanceof EntityPlayer - && FlansMod.proxy.isThePlayer((EntityPlayer)getSeat(0).getControllingPassenger()); + world.isRemote && getSeat(0) != null && getSeat(0).getControllingPassenger() instanceof EntityPlayer + && FlansMod.proxy.isThePlayer((EntityPlayer)getSeat(0).getControllingPassenger()); //Despawning ticksSinceUsed++; @@ -379,8 +387,8 @@ world.isRemote && getSeat(0) != null && getSeat(0).getControllingPassenger() ins //Apply velocity //If the player driving this is in creative, then we can thrust, no matter what boolean canThrustCreatively = !TeamsManager.vehiclesNeedFuel || (getSeat(0) != null - && getSeat(0).getControllingPassenger() instanceof EntityPlayer - && ((EntityPlayer)getSeat(0).getControllingPassenger()).capabilities.isCreativeMode); + && getSeat(0).getControllingPassenger() instanceof EntityPlayer + && ((EntityPlayer)getSeat(0).getControllingPassenger()).capabilities.isCreativeMode); //Otherwise, check the fuel tanks! if(canThrustCreatively || data.fuelInTank > data.engine.fuelConsumption * throttle) { @@ -393,10 +401,10 @@ && getSeat(0).getControllingPassenger() instanceof EntityPlayer wheel.motionZ *= 1F - (Math.abs(wheelsYaw) * turningDrag); float velocityScale = 0.04F * (throttle > 0 ? type.maxThrottle : type.maxNegativeThrottle) * - data.engine.engineSpeed; + data.engine.engineSpeed; float steeringScale = 0.1F * (wheelsYaw > 0 ? type.turnLeftModifier : type.turnRightModifier); float effectiveWheelSpeed = - (throttle + (wheelsYaw * (left ? 1 : -1) * steeringScale)) * velocityScale; + (throttle + (wheelsYaw * (left ? 1 : -1) * steeringScale)) * velocityScale; wheel.motionX += effectiveWheelSpeed * Math.cos(wheel.rotationYaw * 3.14159265F / 180F); wheel.motionZ += effectiveWheelSpeed * Math.sin(wheel.rotationYaw * 3.14159265F / 180F); @@ -407,8 +415,8 @@ && getSeat(0).getControllingPassenger() instanceof EntityPlayer //if(getVehicleType().fourWheelDrive || wheel.ID == 0 || wheel.ID == 1) { float velocityScale = - 0.1F * throttle * (throttle > 0 ? type.maxThrottle : type.maxNegativeThrottle) * - data.engine.engineSpeed; + 0.1F * throttle * (throttle > 0 ? type.maxThrottle : type.maxNegativeThrottle) * + data.engine.engineSpeed; wheel.motionX += Math.cos(wheel.rotationYaw * 3.14159265F / 180F) * velocityScale; wheel.motionZ += Math.sin(wheel.rotationYaw * 3.14159265F / 180F) * velocityScale; } @@ -417,14 +425,14 @@ && getSeat(0).getControllingPassenger() instanceof EntityPlayer if(wheel.getExpectedWheelID() == 2 || wheel.getExpectedWheelID() == 3) { float velocityScale = 0.01F * (wheelsYaw > 0 ? type.turnLeftModifier : type.turnRightModifier) * - (throttle > 0 ? 1 : -1); + (throttle > 0 ? 1 : -1); wheel.motionX -= - wheel.getSpeedXZ() * Math.sin(wheel.rotationYaw * 3.14159265F / 180F) * velocityScale * - wheelsYaw; + wheel.getSpeedXZ() * Math.sin(wheel.rotationYaw * 3.14159265F / 180F) * velocityScale * + wheelsYaw; wheel.motionZ += - wheel.getSpeedXZ() * Math.cos(wheel.rotationYaw * 3.14159265F / 180F) * velocityScale * - wheelsYaw; + wheel.getSpeedXZ() * Math.cos(wheel.rotationYaw * 3.14159265F / 180F) * velocityScale * + wheelsYaw; } else { @@ -443,11 +451,11 @@ && getSeat(0).getControllingPassenger() instanceof EntityPlayer //Pull wheels towards car Vector3f targetWheelPos = axes - .findLocalVectorGlobally(getVehicleType().wheelPositions[wheel.getExpectedWheelID()].position); + .findLocalVectorGlobally(getVehicleType().wheelPositions[wheel.getExpectedWheelID()].position); Vector3f currentWheelPos = new Vector3f(wheel.posX - posX, wheel.posY - posY, wheel.posZ - posZ); Vector3f dPos = ((Vector3f)Vector3f.sub(targetWheelPos, currentWheelPos, null) - .scale(getVehicleType().wheelSpringStrength)); + .scale(getVehicleType().wheelSpringStrength)); if(dPos.length() > 0.001F) { @@ -462,17 +470,17 @@ && getSeat(0).getControllingPassenger() instanceof EntityPlayer if(wheels[0] != null && wheels[1] != null && wheels[2] != null && wheels[3] != null) { Vector3f frontAxleCentre = new Vector3f((wheels[2].posX + wheels[3].posX) / 2F, - (wheels[2].posY + wheels[3].posY) / 2F, - (wheels[2].posZ + wheels[3].posZ) / 2F); + (wheels[2].posY + wheels[3].posY) / 2F, + (wheels[2].posZ + wheels[3].posZ) / 2F); Vector3f backAxleCentre = new Vector3f((wheels[0].posX + wheels[1].posX) / 2F, - (wheels[0].posY + wheels[1].posY) / 2F, - (wheels[0].posZ + wheels[1].posZ) / 2F); + (wheels[0].posY + wheels[1].posY) / 2F, + (wheels[0].posZ + wheels[1].posZ) / 2F); Vector3f leftSideCentre = new Vector3f((wheels[0].posX + wheels[3].posX) / 2F, - (wheels[0].posY + wheels[3].posY) / 2F, - (wheels[0].posZ + wheels[3].posZ) / 2F); + (wheels[0].posY + wheels[3].posY) / 2F, + (wheels[0].posZ + wheels[3].posZ) / 2F); Vector3f rightSideCentre = new Vector3f((wheels[1].posX + wheels[2].posX) / 2F, - (wheels[1].posY + wheels[2].posY) / 2F, - (wheels[1].posZ + wheels[2].posZ) / 2F); + (wheels[1].posY + wheels[2].posY) / 2F, + (wheels[1].posZ + wheels[2].posZ) / 2F); float dx = frontAxleCentre.x - backAxleCentre.x; float dy = frontAxleCentre.y - backAxleCentre.y; @@ -496,7 +504,7 @@ && getSeat(0).getControllingPassenger() instanceof EntityPlayer if(type.tank) { yaw = (float)Math.atan2(wheels[3].posZ - wheels[2].posZ, wheels[3].posX - wheels[2].posX) + - (float)Math.PI / 2F; + (float)Math.PI / 2F; } axes.setAngles(yaw * 180F / 3.14159F, pitch * 180F / 3.14159F, roll * 180F / 3.14159F); @@ -538,11 +546,11 @@ && getSeat(0).getControllingPassenger() instanceof EntityPlayer if(!world.isRemote && ticksExisted % 5 == 0) { FlansMod.getPacketHandler().sendToAllAround(new PacketVehicleControl(this), - posX, - posY, - posZ, - FlansMod.driveableUpdateRange, - dimension); + posX, + posY, + posZ, + FlansMod.driveableUpdateRange, + dimension); } int animSpeed = 4; @@ -601,64 +609,73 @@ else if(throttle < -0.05) } } - public void animateFancyTracks() - { - float funkypart = getVehicleType().trackLinkFix; - boolean funk = getVehicleType().flipLinkFix; - float funk2 = 0; - for(int i = 0; i < trackLinksLeft.length; i++) - { - trackLinksLeft[i].prevPosition = trackLinksLeft[i].position; - trackLinksLeft[i].prevZRot = trackLinksLeft[i].zRot; - float speed = throttle*1.5F - (wheelsYaw/12); - trackLinksLeft[i].progress += speed; - if(trackLinksLeft[i].progress > leftTrack.getTrackLength()) trackLinksLeft[i].progress -= leftTrack.getTrackLength(); - if(trackLinksLeft[i].progress < 0) trackLinksLeft[i].progress += leftTrack.getTrackLength(); - trackLinksLeft[i].position = leftTrack.getPositionOnTrack(trackLinksLeft[i].progress); - for(; trackLinksLeft[i].zRot > 180F; trackLinksLeft[i].zRot -= 360F) {} - for(; trackLinksLeft[i].zRot <= -180F; trackLinksLeft[i].zRot += 360F) {} - float newAngle = rotateTowards(leftTrack.points.get(leftTrack.getTrackPart(trackLinksLeft[i].progress)), trackLinksLeft[i].position); + public void animateFancyTracks() + { + float funkypart = getVehicleType().trackLinkFix; + boolean funk = getVehicleType().flipLinkFix; + float funk2 = 0; + for(int i = 0; i < trackLinksLeft.length; i++) + { + trackLinksLeft[i].prevPosition = trackLinksLeft[i].position; + trackLinksLeft[i].prevZRot = trackLinksLeft[i].zRot; + float speed = throttle * 1.5F - (wheelsYaw / 12); + trackLinksLeft[i].progress += speed; + if(trackLinksLeft[i].progress > leftTrack.getTrackLength()) + trackLinksLeft[i].progress -= leftTrack.getTrackLength(); + if(trackLinksLeft[i].progress < 0) trackLinksLeft[i].progress += leftTrack.getTrackLength(); + trackLinksLeft[i].position = leftTrack.getPositionOnTrack(trackLinksLeft[i].progress); + for(; trackLinksLeft[i].zRot > 180F; trackLinksLeft[i].zRot -= 360F) + { + } + for(; trackLinksLeft[i].zRot <= -180F; trackLinksLeft[i].zRot += 360F) + { + } + float newAngle = rotateTowards(leftTrack.points.get(leftTrack.getTrackPart(trackLinksLeft[i].progress)), + trackLinksLeft[i].position); int part = leftTrack.getTrackPart(trackLinksLeft[i].progress); - if(funk) funk2 = (speed < 0)?0:1; - else funk2 = (speed < 0)?-1:0; - trackLinksLeft[i].zRot = Lerp(trackLinksLeft[i].zRot, newAngle, (part != (funkypart + funk2))?0.5F:1); - - } - - for(int i = 0; i < trackLinksRight.length; i++) - { - trackLinksRight[i].prevPosition = trackLinksRight[i].position; - trackLinksRight[i].prevZRot = trackLinksRight[i].zRot; - float speed = throttle*1.5F + (wheelsYaw/12); - trackLinksRight[i].progress += speed; - if(trackLinksRight[i].progress > rightTrack.getTrackLength()) trackLinksRight[i].progress -= leftTrack.getTrackLength(); - if(trackLinksRight[i].progress < 0) trackLinksRight[i].progress += rightTrack.getTrackLength(); - trackLinksRight[i].position = rightTrack.getPositionOnTrack(trackLinksRight[i].progress); - float newAngle = rotateTowards(rightTrack.points.get(rightTrack.getTrackPart(trackLinksRight[i].progress)), trackLinksRight[i].position); + if(funk) funk2 = (speed < 0) ? 0 : 1; + else funk2 = (speed < 0) ? -1 : 0; + trackLinksLeft[i].zRot = Lerp(trackLinksLeft[i].zRot, newAngle, (part != (funkypart + funk2)) ? 0.5F : 1); + + } + + for(int i = 0; i < trackLinksRight.length; i++) + { + trackLinksRight[i].prevPosition = trackLinksRight[i].position; + trackLinksRight[i].prevZRot = trackLinksRight[i].zRot; + float speed = throttle * 1.5F + (wheelsYaw / 12); + trackLinksRight[i].progress += speed; + if(trackLinksRight[i].progress > rightTrack.getTrackLength()) + trackLinksRight[i].progress -= leftTrack.getTrackLength(); + if(trackLinksRight[i].progress < 0) trackLinksRight[i].progress += rightTrack.getTrackLength(); + trackLinksRight[i].position = rightTrack.getPositionOnTrack(trackLinksRight[i].progress); + float newAngle = rotateTowards(rightTrack.points.get(rightTrack.getTrackPart(trackLinksRight[i].progress)), + trackLinksRight[i].position); int part = rightTrack.getTrackPart(trackLinksRight[i].progress); - if(funk) funk2 = (speed < 0)?0:1; - else funk2 = (speed < 0)?-1:0; - trackLinksRight[i].zRot = Lerp(trackLinksRight[i].zRot, newAngle, (part != (funkypart + funk2))?0.5F:1); - } - } - - public float rotateTowards(Vector3f point, Vector3f original) - { - - float angle = (float)Math.atan2(point.y - original.y, point.x - original.x); - return angle; - } - - public float Lerp(float start, float end, float percent) - { - float result = (start + percent*(end - start)); - - return result; - } - - public static float Clamp(float val, float min, float max) { - return Math.max(min, Math.min(max, val)); - } + if(funk) funk2 = (speed < 0) ? 0 : 1; + else funk2 = (speed < 0) ? -1 : 0; + trackLinksRight[i].zRot = Lerp(trackLinksRight[i].zRot, newAngle, (part != (funkypart + funk2)) ? 0.5F : 1); + } + } + + public float rotateTowards(Vector3f point, Vector3f original) + { + + float angle = (float)Math.atan2(point.y - original.y, point.x - original.x); + return angle; + } + + public float Lerp(float start, float end, float percent) + { + float result = (start + percent * (end - start)); + + return result; + } + + public static float Clamp(float val, float min, float max) + { + return Math.max(min, Math.min(max, val)); + } private float averageAngles(float a, float b) { @@ -703,7 +720,7 @@ public boolean attackEntityFrom(DamageSource damagesource, float i) VehicleType type = getVehicleType(); if(damagesource.damageType.equals("player") && damagesource.getTrueSource().onGround - && (getSeat(0) == null || getSeat(0).getControllingPassenger() == null)) + && (getSeat(0) == null || getSeat(0).getControllingPassenger() == null)) { ItemStack vehicleStack = new ItemStack(type.item, 1, driveableData.paintjobID); NBTTagCompound tags = new NBTTagCompound(); diff --git a/src/main/java/com/flansmod/common/driveables/VehicleType.java b/src/main/java/com/flansmod/common/driveables/VehicleType.java index ce8786842..e16002c04 100644 --- a/src/main/java/com/flansmod/common/driveables/VehicleType.java +++ b/src/main/java/com/flansmod/common/driveables/VehicleType.java @@ -108,7 +108,8 @@ protected void read(String[] split, TypeFile file) } /** - * Find the items needed to rebuild a part. The returned array is disconnected from the template items it has looked up + * Find the items needed to rebuild a part. The returned array is disconnected from the template items it has looked + * up */ @Override public ArrayList getItemsRequired(DriveablePart part, PartType engine)