mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
all that turret targeting code
This commit is contained in:
parent
61c5d932b0
commit
21943e186c
@ -1,6 +1,6 @@
|
||||
# Blender v2.79 (sub 0) OBJ File: 'turret_jeremy.blend'
|
||||
# www.blender.org
|
||||
o Cube
|
||||
o Gun
|
||||
v -1.500000 1.250000 0.250000
|
||||
v -1.500000 1.750000 0.250000
|
||||
v -1.500000 1.250000 -0.250000
|
||||
|
||||
4942
src/main/java/assets/hbm/models/turrets/turret_tauon.obj
Normal file
4942
src/main/java/assets/hbm/models/turrets/turret_tauon.obj
Normal file
File diff suppressed because it is too large
Load Diff
BIN
src/main/java/assets/hbm/textures/items/digamma_kauai_moho.png
Normal file
BIN
src/main/java/assets/hbm/textures/items/digamma_kauai_moho.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 203 B |
BIN
src/main/java/assets/hbm/textures/models/turrets/base/tauon.png
Normal file
BIN
src/main/java/assets/hbm/textures/models/turrets/base/tauon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.4 KiB |
BIN
src/main/java/assets/hbm/textures/models/turrets/tauon.png
Normal file
BIN
src/main/java/assets/hbm/textures/models/turrets/tauon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.2 KiB |
@ -794,6 +794,8 @@ public class ModBlocks {
|
||||
public static Block turret_cheapo;
|
||||
|
||||
public static Block turret_chekhov;
|
||||
public static Block turret_jeremy;
|
||||
public static Block turret_tauon;
|
||||
|
||||
public static Block book_guide;
|
||||
|
||||
@ -1468,6 +1470,8 @@ public class ModBlocks {
|
||||
turret_cheapo = new TurretCheapo(Material.iron).setBlockName("turret_cheapo").setHardness(5.0F).setResistance(10.0F).setCreativeTab(MainRegistry.weaponTab).setBlockTextureName(RefStrings.MODID + ":turret_cheapo");
|
||||
|
||||
turret_chekhov = new TurretChekhov(Material.iron).setBlockName("turret_chekhov").setHardness(5.0F).setResistance(10.0F).setCreativeTab(MainRegistry.weaponTab).setBlockTextureName(RefStrings.MODID + ":turret_chekhov");
|
||||
turret_jeremy = new TurretJeremy(Material.iron).setBlockName("turret_jeremy").setHardness(5.0F).setResistance(10.0F).setCreativeTab(MainRegistry.weaponTab).setBlockTextureName(RefStrings.MODID + ":turret_jeremy");
|
||||
turret_tauon = new TurretTauon(Material.iron).setBlockName("turret_tauon").setHardness(5.0F).setResistance(10.0F).setCreativeTab(MainRegistry.weaponTab).setBlockTextureName(RefStrings.MODID + ":turret_tauon");
|
||||
|
||||
book_guide = new Guide(Material.iron).setBlockName("book_guide").setHardness(5.0F).setResistance(10.0F).setCreativeTab(MainRegistry.nukeTab);
|
||||
|
||||
@ -1963,6 +1967,8 @@ public class ModBlocks {
|
||||
GameRegistry.registerBlock(turret_cwis, ItemBlockLore.class, turret_cwis.getUnlocalizedName());
|
||||
GameRegistry.registerBlock(turret_cheapo, turret_cheapo.getUnlocalizedName());
|
||||
GameRegistry.registerBlock(turret_chekhov, turret_chekhov.getUnlocalizedName());
|
||||
GameRegistry.registerBlock(turret_jeremy, turret_jeremy.getUnlocalizedName());
|
||||
GameRegistry.registerBlock(turret_tauon, turret_tauon.getUnlocalizedName());
|
||||
|
||||
//Mines
|
||||
GameRegistry.registerBlock(mine_ap, mine_ap.getUnlocalizedName());
|
||||
|
||||
@ -5,6 +5,8 @@ import com.hbm.tileentity.turret.TileEntityTurretChekhov;
|
||||
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class TurretChekhov extends BlockDummyable {
|
||||
@ -15,7 +17,7 @@ public class TurretChekhov extends BlockDummyable {
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World world, int meta) {
|
||||
|
||||
|
||||
if(meta >= 12)
|
||||
return new TileEntityTurretChekhov();
|
||||
return null;
|
||||
@ -23,7 +25,7 @@ public class TurretChekhov extends BlockDummyable {
|
||||
|
||||
@Override
|
||||
public int[] getDimensions() {
|
||||
return new int[] {0, 0, 1, 0, 1, 0};
|
||||
return new int[] { 0, 0, 1, 0, 1, 0 };
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -31,4 +33,14 @@ public class TurretChekhov extends BlockDummyable {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlockBoundsBasedOnState(IBlockAccess p_149719_1_, int p_149719_2_, int p_149719_3_, int p_149719_4_) {
|
||||
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.5F, 1.0F);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z) {
|
||||
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.5F, 1.0F);
|
||||
return AxisAlignedBB.getBoundingBox(x + this.minX, y + this.minY, z + this.minZ, x + this.maxX, y + this.maxY, z + this.maxZ);
|
||||
}
|
||||
}
|
||||
|
||||
46
src/main/java/com/hbm/blocks/bomb/TurretJeremy.java
Normal file
46
src/main/java/com/hbm/blocks/bomb/TurretJeremy.java
Normal file
@ -0,0 +1,46 @@
|
||||
package com.hbm.blocks.bomb;
|
||||
|
||||
import com.hbm.blocks.BlockDummyable;
|
||||
import com.hbm.tileentity.turret.TileEntityTurretJeremy;
|
||||
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class TurretJeremy extends BlockDummyable {
|
||||
|
||||
public TurretJeremy(Material mat) {
|
||||
super(mat);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World world, int meta) {
|
||||
|
||||
if(meta >= 12)
|
||||
return new TileEntityTurretJeremy();
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getDimensions() {
|
||||
return new int[] { 0, 0, 1, 0, 1, 0 };
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOffset() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlockBoundsBasedOnState(IBlockAccess p_149719_1_, int p_149719_2_, int p_149719_3_, int p_149719_4_) {
|
||||
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.5F, 1.0F);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z) {
|
||||
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.5F, 1.0F);
|
||||
return AxisAlignedBB.getBoundingBox(x + this.minX, y + this.minY, z + this.minZ, x + this.maxX, y + this.maxY, z + this.maxZ);
|
||||
}
|
||||
}
|
||||
47
src/main/java/com/hbm/blocks/bomb/TurretTauon.java
Normal file
47
src/main/java/com/hbm/blocks/bomb/TurretTauon.java
Normal file
@ -0,0 +1,47 @@
|
||||
package com.hbm.blocks.bomb;
|
||||
|
||||
import com.hbm.blocks.BlockDummyable;
|
||||
import com.hbm.tileentity.turret.TileEntityTurretChekhov;
|
||||
import com.hbm.tileentity.turret.TileEntityTurretTauon;
|
||||
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class TurretTauon extends BlockDummyable {
|
||||
|
||||
public TurretTauon(Material mat) {
|
||||
super(mat);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World world, int meta) {
|
||||
|
||||
if(meta >= 12)
|
||||
return new TileEntityTurretTauon();
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getDimensions() {
|
||||
return new int[] { 0, 0, 1, 0, 1, 0 };
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOffset() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlockBoundsBasedOnState(IBlockAccess p_149719_1_, int p_149719_2_, int p_149719_3_, int p_149719_4_) {
|
||||
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.5F, 1.0F);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z) {
|
||||
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.5F, 1.0F);
|
||||
return AxisAlignedBB.getBoundingBox(x + this.minX, y + this.minY, z + this.minZ, x + this.maxX, y + this.maxY, z + this.maxZ);
|
||||
}
|
||||
}
|
||||
@ -124,6 +124,8 @@ public class ClientProxy extends ServerProxy {
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityTurretCIWS.class, new RenderCIWSTurret());
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityTurretCheapo.class, new RenderCheapoTurret());
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityTurretChekhov.class, new RenderTurretChekhov());
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityTurretJeremy.class, new RenderTurretJeremy());
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityTurretTauon.class, new RenderTurretTauon());
|
||||
//mines
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityLandmine.class, new RenderLandmine());
|
||||
//cel prime
|
||||
|
||||
@ -451,6 +451,8 @@ public class MainRegistry {
|
||||
GameRegistry.registerTileEntity(TileEntityFireworks.class, "tileentity_firework_box");
|
||||
GameRegistry.registerTileEntity(TileEntityCrateTungsten.class, "tileentity_crate_hot");
|
||||
GameRegistry.registerTileEntity(TileEntityTurretChekhov.class, "tileentity_turret_chekhov");
|
||||
GameRegistry.registerTileEntity(TileEntityTurretJeremy.class, "tileentity_turret_jeremy");
|
||||
GameRegistry.registerTileEntity(TileEntityTurretTauon.class, "tileentity_turret_tauon");
|
||||
|
||||
EntityRegistry.registerModEntity(EntityRocket.class, "entity_rocket", 0, this, 250, 1, true);
|
||||
EntityRegistry.registerModEntity(EntityNukeExplosion.class, "entity_nuke_explosion", 1, this, 250, 1, true);
|
||||
|
||||
@ -40,6 +40,7 @@ public class ResourceManager {
|
||||
|
||||
public static final IModelCustom turret_chekhov = new HFRWavefrontObject(new ResourceLocation(RefStrings.MODID, "models/turrets/turret_chekhov.obj"));
|
||||
public static final IModelCustom turret_jeremy = new HFRWavefrontObject(new ResourceLocation(RefStrings.MODID, "models/turrets/turret_jeremy.obj"));
|
||||
public static final IModelCustom turret_tauon = new HFRWavefrontObject(new ResourceLocation(RefStrings.MODID, "models/turrets/turret_tauon.obj"));
|
||||
|
||||
//Landmines
|
||||
public static final IModelCustom mine_ap = AdvancedModelLoader.loadModel(new ResourceLocation(RefStrings.MODID, "models/mine_ap.obj"));
|
||||
@ -268,6 +269,7 @@ public class ResourceManager {
|
||||
public static final ResourceLocation turret_chekhov_tex = new ResourceLocation(RefStrings.MODID, "textures/models/turrets/chekhov.png");
|
||||
public static final ResourceLocation turret_chekhov_barrels_tex = new ResourceLocation(RefStrings.MODID, "textures/models/turrets/chekhov_barrels.png");
|
||||
public static final ResourceLocation turret_jeremy_tex = new ResourceLocation(RefStrings.MODID, "textures/models/turrets/jeremy.png");
|
||||
public static final ResourceLocation turret_tauon_tex = new ResourceLocation(RefStrings.MODID, "textures/models/turrets/tauon.png");
|
||||
|
||||
//Landmines
|
||||
public static final ResourceLocation mine_ap_tex = new ResourceLocation(RefStrings.MODID, "textures/models/mine_ap.png");
|
||||
|
||||
@ -3,6 +3,7 @@ package com.hbm.render.tileentity;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.hbm.main.ResourceManager;
|
||||
import com.hbm.tileentity.turret.TileEntityTurretChekhov;
|
||||
|
||||
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
@ -21,12 +22,16 @@ public class RenderTurretChekhov extends TileEntitySpecialRenderer {
|
||||
bindTexture(ResourceManager.turret_base_tex);
|
||||
ResourceManager.turret_chekhov.renderPart("Base");
|
||||
|
||||
GL11.glRotated(System.currentTimeMillis() / 100D % 360, 0, 1, 0);
|
||||
TileEntityTurretChekhov turret = (TileEntityTurretChekhov)te;
|
||||
double yaw = -Math.toDegrees(turret.lastRotationYaw + (turret.rotationYaw - turret.lastRotationYaw) * interp) - 90D;
|
||||
double pitch = Math.toDegrees(turret.lastRotationPitch + (turret.rotationPitch - turret.lastRotationPitch) * interp);
|
||||
|
||||
GL11.glRotated(yaw, 0, 1, 0);
|
||||
bindTexture(ResourceManager.turret_carriage_tex);
|
||||
ResourceManager.turret_chekhov.renderPart("Carriage");
|
||||
|
||||
GL11.glTranslated(0, 1.5, 0);
|
||||
GL11.glRotated(Math.sin(System.currentTimeMillis() / 1000D) * 30, 0, 0, 1);
|
||||
GL11.glRotated(pitch, 0, 0, 1);
|
||||
GL11.glTranslated(0, -1.5, 0);
|
||||
bindTexture(ResourceManager.turret_chekhov_tex);
|
||||
ResourceManager.turret_chekhov.renderPart("Body");
|
||||
@ -40,5 +45,4 @@ public class RenderTurretChekhov extends TileEntitySpecialRenderer {
|
||||
GL11.glShadeModel(GL11.GL_FLAT);
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,42 @@
|
||||
package com.hbm.render.tileentity;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.hbm.main.ResourceManager;
|
||||
import com.hbm.tileentity.turret.TileEntityTurretJeremy;
|
||||
|
||||
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
public class RenderTurretJeremy extends TileEntitySpecialRenderer {
|
||||
|
||||
@Override
|
||||
public void renderTileEntityAt(TileEntity te, double x, double y, double z, float interp) {
|
||||
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslated(x + 1D, y, z + 1D);
|
||||
GL11.glEnable(GL11.GL_LIGHTING);
|
||||
GL11.glEnable(GL11.GL_CULL_FACE);
|
||||
GL11.glShadeModel(GL11.GL_SMOOTH);
|
||||
|
||||
bindTexture(ResourceManager.turret_base_tex);
|
||||
ResourceManager.turret_chekhov.renderPart("Base");
|
||||
|
||||
TileEntityTurretJeremy turret = (TileEntityTurretJeremy)te;
|
||||
double yaw = -Math.toDegrees(turret.lastRotationYaw + (turret.rotationYaw - turret.lastRotationYaw) * interp) - 90D;
|
||||
double pitch = Math.toDegrees(turret.lastRotationPitch + (turret.rotationPitch - turret.lastRotationPitch) * interp);
|
||||
|
||||
GL11.glRotated(yaw, 0, 1, 0);
|
||||
bindTexture(ResourceManager.turret_carriage_tex);
|
||||
ResourceManager.turret_chekhov.renderPart("Carriage");
|
||||
|
||||
GL11.glTranslated(0, 1.5, 0);
|
||||
GL11.glRotated(pitch, 0, 0, 1);
|
||||
GL11.glTranslated(0, -1.5, 0);
|
||||
bindTexture(ResourceManager.turret_jeremy_tex);
|
||||
ResourceManager.turret_jeremy.renderPart("Gun");
|
||||
|
||||
GL11.glShadeModel(GL11.GL_FLAT);
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,61 @@
|
||||
package com.hbm.render.tileentity;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.hbm.main.ResourceManager;
|
||||
import com.hbm.render.util.BeamPronter;
|
||||
import com.hbm.render.util.BeamPronter.EnumBeamType;
|
||||
import com.hbm.render.util.BeamPronter.EnumWaveType;
|
||||
import com.hbm.tileentity.turret.TileEntityTurretTauon;
|
||||
|
||||
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.Vec3;
|
||||
|
||||
public class RenderTurretTauon extends TileEntitySpecialRenderer {
|
||||
|
||||
@Override
|
||||
public void renderTileEntityAt(TileEntity te, double x, double y, double z, float interp) {
|
||||
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslated(x + 1D, y, z + 1D);
|
||||
GL11.glEnable(GL11.GL_LIGHTING);
|
||||
GL11.glEnable(GL11.GL_CULL_FACE);
|
||||
GL11.glShadeModel(GL11.GL_SMOOTH);
|
||||
|
||||
bindTexture(ResourceManager.turret_base_tex);
|
||||
ResourceManager.turret_chekhov.renderPart("Base");
|
||||
|
||||
TileEntityTurretTauon turret = (TileEntityTurretTauon)te;
|
||||
double yaw = -Math.toDegrees(turret.lastRotationYaw + (turret.rotationYaw - turret.lastRotationYaw) * interp) - 90D;
|
||||
double pitch = Math.toDegrees(turret.lastRotationPitch + (turret.rotationPitch - turret.lastRotationPitch) * interp);
|
||||
|
||||
GL11.glRotated(yaw, 0, 1, 0);
|
||||
bindTexture(ResourceManager.turret_carriage_tex);
|
||||
ResourceManager.turret_chekhov.renderPart("Carriage");
|
||||
|
||||
GL11.glTranslated(0, 1.5, 0);
|
||||
GL11.glRotated(pitch, 0, 0, 1);
|
||||
GL11.glTranslated(0, -1.5, 0);
|
||||
bindTexture(ResourceManager.turret_tauon_tex);
|
||||
ResourceManager.turret_tauon.renderPart("Cannon");
|
||||
|
||||
if(turret.target != null && turret.aligned && System.currentTimeMillis() % 500 < 200) {
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslated(0, 1.5D, 0);
|
||||
Vec3 pos = turret.getTurretPos();
|
||||
Vec3 ent = turret.getEntityPos(turret.target);
|
||||
double length = Vec3.createVectorHelper(ent.xCoord - pos.xCoord, ent.yCoord - pos.yCoord, ent.zCoord - pos.zCoord).lengthVector();
|
||||
BeamPronter.prontBeam(Vec3.createVectorHelper(length, 0, 0), EnumWaveType.RANDOM, EnumBeamType.LINE, 0xffa200, 0xffd000, (int)te.getWorldObj().getTotalWorldTime() / 5 % 360, (int)length + 1, 0.1F, 0, 0);
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
GL11.glTranslated(0, 1.375, 0);
|
||||
GL11.glRotated((te.getWorldObj().getTotalWorldTime() + interp) * 15, -1, 0, 0);
|
||||
GL11.glTranslated(0, -1.375, 0);
|
||||
ResourceManager.turret_tauon.renderPart("Rotor");
|
||||
|
||||
GL11.glShadeModel(GL11.GL_FLAT);
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
}
|
||||
@ -2,15 +2,25 @@ package com.hbm.tileentity.turret;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.hbm.entity.logic.EntityBomber;
|
||||
import com.hbm.entity.missile.EntityMissileBase;
|
||||
import com.hbm.entity.missile.EntityMissileBaseAdvanced;
|
||||
import com.hbm.handler.BulletConfiguration;
|
||||
import com.hbm.lib.Library;
|
||||
import com.hbm.tileentity.TileEntityMachineBase;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.item.EntityMinecart;
|
||||
import net.minecraft.entity.monster.IMob;
|
||||
import net.minecraft.entity.passive.EntityAnimal;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraftforge.common.util.FakePlayer;
|
||||
|
||||
/**
|
||||
* More over-engineered than ever, but chopping this thing into the smallest possible pieces makes it easier for my demented brain to comprehend
|
||||
@ -19,6 +29,7 @@ import net.minecraft.util.Vec3;
|
||||
*/
|
||||
public abstract class TileEntityTurretBaseNT extends TileEntityMachineBase {
|
||||
|
||||
//this time we do all rotations in radians
|
||||
//what way are we facing?
|
||||
public double rotationYaw;
|
||||
public double rotationPitch;
|
||||
@ -29,6 +40,8 @@ public abstract class TileEntityTurretBaseNT extends TileEntityMachineBase {
|
||||
public boolean isOn = false;
|
||||
//is the turret aimed at the target?
|
||||
public boolean aligned = false;
|
||||
//how many ticks until the next check
|
||||
public int searchTimer;
|
||||
|
||||
public boolean targetPlayers = false;
|
||||
public boolean targetAnimals = false;
|
||||
@ -56,6 +69,74 @@ public abstract class TileEntityTurretBaseNT extends TileEntityMachineBase {
|
||||
super(11);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
|
||||
if(target != null) {
|
||||
if(!this.entityInLOS(this.target)) {
|
||||
this.target = null;
|
||||
}
|
||||
}
|
||||
|
||||
if(worldObj.isRemote) {
|
||||
this.lastRotationPitch = this.rotationPitch;
|
||||
this.lastRotationYaw = this.rotationYaw;
|
||||
}
|
||||
|
||||
if(target != null) {
|
||||
this.aligned = false;
|
||||
this.alignTurret();
|
||||
} else {
|
||||
this.aligned = false;
|
||||
}
|
||||
|
||||
if(!worldObj.isRemote) {
|
||||
|
||||
searchTimer--;
|
||||
|
||||
if(searchTimer <= 0) {
|
||||
searchTimer = this.getDecetorInterval();
|
||||
this.seekNewTarget();
|
||||
}
|
||||
|
||||
NBTTagCompound data = new NBTTagCompound();
|
||||
data.setInteger("target", this.target == null ? -1 : this.target.getEntityId());
|
||||
this.networkPack(data, 250);
|
||||
|
||||
} else {
|
||||
|
||||
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));
|
||||
|
||||
//this will fix the interpolation error when the turret crosses the 360° point
|
||||
if(Math.abs(this.lastRotationYaw - this.rotationYaw) > Math.PI) {
|
||||
|
||||
if(this.lastRotationYaw < this.rotationYaw)
|
||||
this.lastRotationYaw += Math.PI * 2;
|
||||
else
|
||||
this.lastRotationYaw -= Math.PI * 2;
|
||||
}
|
||||
|
||||
worldObj.spawnParticle("cloud", pos.xCoord, pos.yCoord, pos.zCoord, 0.0, 0.1, 0.0);
|
||||
|
||||
if(this.aligned)
|
||||
worldObj.spawnParticle("flame", pos.xCoord + vec.xCoord, pos.yCoord + vec.yCoord, pos.zCoord + vec.zCoord, vec.xCoord, vec.yCoord, vec.zCoord);
|
||||
if(this.target != null)
|
||||
worldObj.spawnParticle("smoke", pos.xCoord + vec.xCoord, pos.yCoord + vec.yCoord, pos.zCoord + vec.zCoord, vec.xCoord, vec.yCoord, vec.zCoord);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void networkUnpack(NBTTagCompound nbt) {
|
||||
|
||||
int t = nbt.getInteger("target");
|
||||
|
||||
if(t != -1)
|
||||
this.target = worldObj.getEntityByID(t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the namelist from the AI chip in slot 0
|
||||
* @return null if there is either no chip to be found or if the name list is empty, otherwise it just reads the strings from the chip's NBT
|
||||
@ -65,21 +146,107 @@ public abstract class TileEntityTurretBaseNT extends TileEntityMachineBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the nearest acceptable target within range aand in line of sight
|
||||
* Finds the nearest acceptable target within range and in line of sight
|
||||
*/
|
||||
protected void seekNewTarget() {
|
||||
|
||||
Vec3 pos = this.getTurretPos();
|
||||
double range = this.getDecetorRange();
|
||||
List<Entity> entities = worldObj.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(pos.xCoord, pos.yCoord, pos.zCoord, pos.xCoord, pos.yCoord, pos.zCoord).expand(range, range, range));
|
||||
|
||||
Entity target = null;
|
||||
double closest = range;
|
||||
|
||||
for(Entity entity : entities) {
|
||||
|
||||
Vec3 ent = this.getEntityPos(entity);
|
||||
Vec3 delta = Vec3.createVectorHelper(ent.xCoord - pos.xCoord, ent.yCoord - pos.yCoord, ent.zCoord - pos.zCoord);
|
||||
|
||||
double dist = delta.lengthVector();
|
||||
|
||||
//check if it's in range
|
||||
if(dist > range)
|
||||
continue;
|
||||
|
||||
//check if we should even fire at this entity
|
||||
if(!entityAcceptableTarget(entity))
|
||||
continue;
|
||||
|
||||
//check for visibility
|
||||
if(!entityInLOS(entity))
|
||||
continue;
|
||||
|
||||
//replace current target if this one is closer
|
||||
if(dist < closest) {
|
||||
closest = dist;
|
||||
target = entity;
|
||||
}
|
||||
}
|
||||
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns the turret by a specific amount of degrees towards the target
|
||||
* Assumes that the target is not null
|
||||
*/
|
||||
protected void alignTurret() {
|
||||
|
||||
/* TODO */
|
||||
double turnYaw = Math.toRadians(this.getTurretYawSpeed());
|
||||
double turnPitch = Math.toRadians(this.getTurretPitchSpeed());
|
||||
double pi2 = Math.PI * 2;
|
||||
|
||||
Vec3 pos = this.getTurretPos();
|
||||
Vec3 ent = this.getEntityPos(target);
|
||||
Vec3 delta = Vec3.createVectorHelper(ent.xCoord - pos.xCoord, ent.yCoord - pos.yCoord, ent.zCoord - pos.zCoord);
|
||||
|
||||
//if the delta is smaller than the angular velocity, just snap directly to the optimal position
|
||||
//check if the delta exceeds 180 and choose an appropriate shortest turning direction based on that
|
||||
double targetPitch = Math.asin(delta.yCoord / delta.lengthVector());
|
||||
double targetYaw = -Math.atan2(delta.xCoord, delta.zCoord);
|
||||
|
||||
//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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -87,7 +254,64 @@ public abstract class TileEntityTurretBaseNT extends TileEntityMachineBase {
|
||||
* @return
|
||||
*/
|
||||
public boolean entityInLOS(Entity e) {
|
||||
return false; //TODO: for the love of god don't forget to check the swivel range
|
||||
|
||||
Vec3 pos = this.getTurretPos();
|
||||
Vec3 ent = this.getEntityPos(e);
|
||||
Vec3 delta = Vec3.createVectorHelper(ent.xCoord - pos.xCoord, ent.yCoord - pos.yCoord, ent.zCoord - pos.zCoord);
|
||||
|
||||
if(delta.lengthVector() < this.getDecetorGrace())
|
||||
return false;
|
||||
|
||||
delta = delta.normalize();
|
||||
double pitch = Math.asin(delta.yCoord / delta.lengthVector());
|
||||
double pitchDeg = Math.toDegrees(pitch);
|
||||
|
||||
//check if the entity is within swivel range
|
||||
if(pitchDeg < -this.getTurretDepression() || pitchDeg > this.getTurretElevation())
|
||||
return false;
|
||||
|
||||
return !Library.isObstructed(worldObj, pos.xCoord, pos.yCoord, pos.zCoord, ent.xCoord, ent.yCoord, ent.zCoord);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the entity is considered for targeting
|
||||
* @return
|
||||
*/
|
||||
public boolean entityAcceptableTarget(Entity e) {
|
||||
|
||||
if(e.isDead || !e.isEntityAlive())
|
||||
return false;
|
||||
|
||||
if(targetAnimals && e instanceof EntityAnimal)
|
||||
return true;
|
||||
|
||||
if(targetMobs && e instanceof IMob)
|
||||
return true;
|
||||
|
||||
if(targetMachines) {
|
||||
|
||||
if(e instanceof EntityMissileBaseAdvanced)
|
||||
return true;
|
||||
if(e instanceof EntityMinecart)
|
||||
return true;
|
||||
if(e instanceof EntityBomber)
|
||||
return true;
|
||||
}
|
||||
|
||||
if(targetPlayers && e instanceof EntityPlayer) {
|
||||
|
||||
if(e instanceof FakePlayer)
|
||||
return false;
|
||||
|
||||
List<String> wl = getWhitelist();
|
||||
|
||||
if(wl == null || wl.isEmpty())
|
||||
return true;
|
||||
|
||||
return !wl.contains(((EntityPlayer)e).getDisplayName());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -138,6 +362,22 @@ public abstract class TileEntityTurretBaseNT extends TileEntityMachineBase {
|
||||
return 20;
|
||||
}
|
||||
|
||||
/**
|
||||
* How far away an entity can be to be picked up
|
||||
* @return
|
||||
*/
|
||||
public double getDecetorRange() {
|
||||
return 32D;
|
||||
}
|
||||
|
||||
/**
|
||||
* How far away an entity needs to be to be picked up
|
||||
* @return
|
||||
*/
|
||||
public double getDecetorGrace() {
|
||||
return 3D;
|
||||
}
|
||||
|
||||
/**
|
||||
* The pivot point of the turret, larger models have a default of 1.5
|
||||
* @return
|
||||
@ -160,7 +400,15 @@ public abstract class TileEntityTurretBaseNT extends TileEntityMachineBase {
|
||||
*/
|
||||
public Vec3 getTurretPos() {
|
||||
//TODO: account for multiblock rotation
|
||||
return Vec3.createVectorHelper(xCoord, yCoord + getHeightOffset(), zCoord);
|
||||
return Vec3.createVectorHelper(xCoord + 1, yCoord + getHeightOffset(), zCoord + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* The pivot point of the turret, this position is used for LOS calculation and more
|
||||
* @return
|
||||
*/
|
||||
public Vec3 getEntityPos(Entity e) {
|
||||
return Vec3.createVectorHelper(e.posX, e.posY + e.height * 0.5 - e.getYOffset(), e.posZ);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -178,26 +426,6 @@ public abstract class TileEntityTurretBaseNT extends TileEntityMachineBase {
|
||||
* mayhaps some dangly bits that tie together the GUI with the AI chip's whitelist
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
|
||||
//hinga dinga durgen
|
||||
|
||||
//let's see
|
||||
|
||||
//check power, if it's turned on, all that jazz
|
||||
|
||||
//is there an active enemy? good, aim at it (alignTurret does all that)
|
||||
|
||||
//is the gun aimed? now shøøt
|
||||
|
||||
//check ammo, spawn boolets if present, make empty clicking if not
|
||||
|
||||
//decrement the timer, if the timer runs out, set the timer to the detector interval and choose a new target
|
||||
|
||||
//target choosing time? seekNewTarget does all the work
|
||||
}
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getRenderBoundingBox() {
|
||||
return TileEntity.INFINITE_EXTENT_AABB;
|
||||
|
||||
@ -27,4 +27,8 @@ public class TileEntityTurretChekhov extends TileEntityTurretBaseNT {
|
||||
return "container.turretChekhov";
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getTurretElevation() {
|
||||
return 45D;
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,28 @@
|
||||
package com.hbm.tileentity.turret;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.hbm.handler.BulletConfiguration;
|
||||
|
||||
public class TileEntityTurretJeremy extends TileEntityTurretBaseNT {
|
||||
|
||||
@Override
|
||||
protected List<BulletConfiguration> getAmmoList() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDecetorGrace() {
|
||||
return 10D;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getTurretDepression() {
|
||||
return 35D;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,43 @@
|
||||
package com.hbm.tileentity.turret;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.hbm.handler.BulletConfiguration;
|
||||
|
||||
public class TileEntityTurretTauon extends TileEntityTurretBaseNT {
|
||||
|
||||
@Override
|
||||
protected List<BulletConfiguration> getAmmoList() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDecetorGrace() {
|
||||
return 7D;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getTurretYawSpeed() {
|
||||
return 9D;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getTurretPitchSpeed() {
|
||||
return 6D;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getTurretElevation() {
|
||||
return 35D;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getTurretDepression() {
|
||||
return 35D;
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user