mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
a tiny bit of arty stuff
This commit is contained in:
parent
0b511f604f
commit
e9f144bac9
@ -35,6 +35,7 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@ -1012,6 +1013,18 @@ public class MainRegistry {
|
||||
/*BiomeGenBase.plains.addFlower(ModBlocks.plant_flower, EnumFlowerType.FOXGLOVE.ordinal(), 10);
|
||||
BiomeGenBase.roofedForest.addFlower(ModBlocks.plant_flower, EnumFlowerType.NIGHTSHADE.ordinal(), 10);
|
||||
BiomeGenBase.jungle.addFlower(ModBlocks.plant_flower, EnumFlowerType.TOBACCO.ordinal(), 10);*/
|
||||
|
||||
/*Set<Thread> threads = Thread.getAllStackTraces().keySet();
|
||||
|
||||
for (Thread thread : threads) {
|
||||
|
||||
System.out.println("Printing thread " + thread.getName());
|
||||
StackTraceElement[] stackTraceElements = thread.getStackTrace();
|
||||
for (StackTraceElement stackTraceElement : stackTraceElements) {
|
||||
System.out.println("\t" + stackTraceElement);
|
||||
}
|
||||
System.out.println("");
|
||||
}*/
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
||||
@ -3,6 +3,7 @@ package com.hbm.tileentity.turret;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.hbm.entity.projectile.EntityBulletBase;
|
||||
import com.hbm.handler.BulletConfigSyncingUtil;
|
||||
import com.hbm.handler.BulletConfiguration;
|
||||
import com.hbm.inventory.container.ContainerTurretBase;
|
||||
@ -63,6 +64,40 @@ public class TileEntityTurretArty extends TileEntityTurretBaseNT implements IGUI
|
||||
return 3D;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void seekNewTarget() {
|
||||
|
||||
if(this.directMode) {
|
||||
super.seekNewTarget();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/* TODO: large field artillery target search */
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void alignTurret() {
|
||||
/* TODO: calculate angles */
|
||||
this.turnTowards(tPos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void spawnBullet(BulletConfiguration bullet) {
|
||||
|
||||
Vec3 pos = this.getTurretPos();
|
||||
Vec3 vec = Vec3.createVectorHelper(this.getBarrelLength(), 0, 0);
|
||||
vec.rotateAroundZ((float) -this.rotationPitch);
|
||||
vec.rotateAroundY((float) -(this.rotationYaw + Math.PI * 0.5));
|
||||
|
||||
/* TODO: replace bullet base entity with a chunkloading artillery shell */
|
||||
EntityBulletBase proj = new EntityBulletBase(worldObj, BulletConfigSyncingUtil.getKey(bullet));
|
||||
proj.setPositionAndRotation(pos.xCoord + vec.xCoord, pos.yCoord + vec.yCoord, pos.zCoord + vec.zCoord, 0.0F, 0.0F);
|
||||
|
||||
proj.setThrowableHeading(vec.xCoord, vec.yCoord, vec.zCoord, bullet.velocity, bullet.spread);
|
||||
worldObj.spawnEntityInWorld(proj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateFiringTick() {
|
||||
|
||||
|
||||
@ -455,9 +455,9 @@ public abstract class TileEntityTurretBaseNT extends TileEntityMachineBase imple
|
||||
*/
|
||||
public void turnTowards(Vec3 ent) {
|
||||
|
||||
double turnYaw = Math.toRadians(this.getTurretYawSpeed());
|
||||
/*double turnYaw = Math.toRadians(this.getTurretYawSpeed());
|
||||
double turnPitch = Math.toRadians(this.getTurretPitchSpeed());
|
||||
double pi2 = Math.PI * 2;
|
||||
double pi2 = Math.PI * 2;*/
|
||||
|
||||
Vec3 pos = this.getTurretPos();
|
||||
Vec3 delta = Vec3.createVectorHelper(ent.xCoord - pos.xCoord, ent.yCoord - pos.yCoord, ent.zCoord - pos.zCoord);
|
||||
@ -465,6 +465,60 @@ public abstract class TileEntityTurretBaseNT extends TileEntityMachineBase imple
|
||||
double targetPitch = Math.asin(delta.yCoord / delta.lengthVector());
|
||||
double targetYaw = -Math.atan2(delta.xCoord, delta.zCoord);
|
||||
|
||||
this.turnTowardsAngle(targetPitch, targetYaw);
|
||||
|
||||
/*//if we are about to overshoot the target by turning, just snap to the correct rotation
|
||||
if(Math.abs(this.rotationPitch - targetPitch) < turnPitch || Math.abs(this.rotationPitch - targetPitch) > pi2 - turnPitch) {
|
||||
this.rotationPitch = targetPitch;
|
||||
} else {
|
||||
|
||||
if(targetPitch > this.rotationPitch)
|
||||
this.rotationPitch += turnPitch;
|
||||
else
|
||||
this.rotationPitch -= turnPitch;
|
||||
}
|
||||
|
||||
double deltaYaw = (targetYaw - this.rotationYaw) % pi2;
|
||||
|
||||
//determines what direction the turret should turn
|
||||
//used to prevent situations where the turret would do almost a full turn when
|
||||
//the target is only a couple degrees off while being on the other side of the 360° line
|
||||
int dir = 0;
|
||||
|
||||
if(deltaYaw < -Math.PI)
|
||||
dir = 1;
|
||||
else if(deltaYaw < 0)
|
||||
dir = -1;
|
||||
else if(deltaYaw > Math.PI)
|
||||
dir = -1;
|
||||
else if(deltaYaw > 0)
|
||||
dir = 1;
|
||||
|
||||
if(Math.abs(this.rotationYaw - targetYaw) < turnYaw || Math.abs(this.rotationYaw - targetYaw) > pi2 - turnYaw) {
|
||||
this.rotationYaw = targetYaw;
|
||||
} else {
|
||||
this.rotationYaw += turnYaw * dir;
|
||||
}
|
||||
|
||||
double deltaPitch = targetPitch - this.rotationPitch;
|
||||
deltaYaw = targetYaw - this.rotationYaw;
|
||||
|
||||
double deltaAngle = Math.sqrt(deltaYaw * deltaYaw + deltaPitch * deltaPitch);
|
||||
|
||||
this.rotationYaw = this.rotationYaw % pi2;
|
||||
this.rotationPitch = this.rotationPitch % pi2;
|
||||
|
||||
if(deltaAngle <= Math.toRadians(this.getAcceptableInaccuracy())) {
|
||||
this.aligned = true;
|
||||
}*/
|
||||
}
|
||||
|
||||
public void turnTowardsAngle(double targetPitch, double targetYaw) {
|
||||
|
||||
double turnYaw = Math.toRadians(this.getTurretYawSpeed());
|
||||
double turnPitch = Math.toRadians(this.getTurretPitchSpeed());
|
||||
double pi2 = Math.PI * 2;
|
||||
|
||||
//if we are about to overshoot the target by turning, just snap to the correct rotation
|
||||
if(Math.abs(this.rotationPitch - targetPitch) < turnPitch || Math.abs(this.rotationPitch - targetPitch) > pi2 - turnPitch) {
|
||||
this.rotationPitch = targetPitch;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user