manual artillery contoller

This commit is contained in:
Bob 2022-06-21 22:56:20 +02:00
parent 2952e175b5
commit c98a011141
6 changed files with 206 additions and 4 deletions

View File

@ -1,5 +1,6 @@
package com.hbm.entity.projectile;
import com.hbm.entity.effect.EntityNukeTorex;
import com.hbm.entity.logic.IChunkLoader;
import cpw.mods.fml.relauncher.Side;

View File

@ -1212,6 +1212,7 @@ public class ModItems {
public static Item designator;
public static Item designator_range;
public static Item designator_manual;
public static Item designator_arty_range;
public static Item linker;
public static Item reactor_sensor;
public static Item oil_detector;
@ -3976,6 +3977,7 @@ public class ModItems {
designator = new ItemDesingator().setUnlocalizedName("designator").setMaxStackSize(1).setCreativeTab(MainRegistry.missileTab).setTextureName(RefStrings.MODID + ":designator");
designator_range = new ItemDesingatorRange().setUnlocalizedName("designator_range").setFull3D().setMaxStackSize(1).setCreativeTab(MainRegistry.missileTab).setTextureName(RefStrings.MODID + ":designator_range_alt");
designator_manual = new ItemDesingatorManual().setUnlocalizedName("designator_manual").setMaxStackSize(1).setCreativeTab(MainRegistry.missileTab).setTextureName(RefStrings.MODID + ":designator_manual");
designator_arty_range = new ItemDesignatorArtyRange().setUnlocalizedName("designator_arty_range").setCreativeTab(MainRegistry.missileTab).setTextureName(RefStrings.MODID + ":designator_arty_range");
missile_assembly = new Item().setUnlocalizedName("missile_assembly").setMaxStackSize(1).setCreativeTab(MainRegistry.partsTab).setTextureName(RefStrings.MODID + ":missile_assembly");
missile_generic = new Item().setUnlocalizedName("missile_generic").setMaxStackSize(1).setCreativeTab(MainRegistry.missileTab).setTextureName(RefStrings.MODID + ":missile_generic");
missile_anti_ballistic = new Item().setUnlocalizedName("missile_anti_ballistic").setMaxStackSize(1).setCreativeTab(MainRegistry.missileTab).setTextureName(RefStrings.MODID + ":missile_anti_ballistic");
@ -6926,6 +6928,7 @@ public class ModItems {
GameRegistry.registerItem(designator, designator.getUnlocalizedName());
GameRegistry.registerItem(designator_range, designator_range.getUnlocalizedName());
GameRegistry.registerItem(designator_manual, designator_manual.getUnlocalizedName());
GameRegistry.registerItem(designator_arty_range, designator_arty_range.getUnlocalizedName());
GameRegistry.registerItem(turret_control, turret_control.getUnlocalizedName());
GameRegistry.registerItem(turret_chip, turret_chip.getUnlocalizedName());
//GameRegistry.registerItem(turret_biometry, turret_biometry.getUnlocalizedName());

View File

@ -0,0 +1,93 @@
package com.hbm.items.tool;
import java.util.List;
import com.hbm.blocks.ModBlocks;
import com.hbm.blocks.turret.TurretArty;
import com.hbm.lib.Library;
import com.hbm.tileentity.turret.TileEntityTurretArty;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
public class ItemDesignatorArtyRange extends Item {
public ItemDesignatorArtyRange() {
this.setFull3D();
this.setMaxStackSize(1);
}
@Override
public void addInformation(ItemStack itemstack, EntityPlayer player, List list, boolean bool) {
if(itemstack.getTagCompound() == null) {
list.add(EnumChatFormatting.RED + "No turret linked!");
} else {
list.add(EnumChatFormatting.YELLOW + "Linked to " + itemstack.stackTagCompound.getInteger("x") + ", " + itemstack.stackTagCompound.getInteger("y") + ", " + itemstack.stackTagCompound.getInteger("z"));
}
}
@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
Block b = world.getBlock(x, y, z);
if(b == ModBlocks.turret_arty) {
int pos[] = ((TurretArty) b).findCore(world, x, y, z);
if(pos == null)
return false;
TileEntity te = world.getTileEntity(pos[0], pos[1], pos[2]);
if(te instanceof TileEntityTurretArty) {
if(world.isRemote)
return true;
if(!stack.hasTagCompound())
stack.stackTagCompound = new NBTTagCompound();
stack.stackTagCompound.setInteger("x", pos[0]);
stack.stackTagCompound.setInteger("y", pos[1]);
stack.stackTagCompound.setInteger("z", pos[2]);
world.playSoundAtEntity(player, "hbm:item.techBleep", 1.0F, 1.0F);
return true;
}
}
return false;
}
@Override
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
if(!stack.hasTagCompound())
return stack;
MovingObjectPosition pos = Library.rayTrace(player, 500, 1);
int x = pos.blockX;
int y = pos.blockY;
int z = pos.blockZ;
if(!world.isRemote) {
TileEntity te = world.getTileEntity(stack.stackTagCompound.getInteger("x"), stack.stackTagCompound.getInteger("y"), stack.stackTagCompound.getInteger("z"));
if(te instanceof TileEntityTurretArty) {
TileEntityTurretArty arty = (TileEntityTurretArty) te;
if(arty.mode == arty.MODE_MANUAL) {
arty.enqueueTarget(x + 0.5, y + 0.5, z + 0.5);
world.playSoundAtEntity(player, "hbm:item.techBoop", 1.0F, 1.0F);
}
}
}
return stack;
}
}

View File

@ -16,12 +16,9 @@ import com.hbm.tileentity.IGUIProvider;
import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.potion.Potion;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
@ -35,6 +32,8 @@ public class TileEntityTurretArty extends TileEntityTurretBaseNT implements IGUI
private boolean retracting = false;
public double barrelPos = 0;
public double lastBarrelPos = 0;
private List<Vec3> targetQueue = new ArrayList();
static List<Integer> configs = new ArrayList();
@ -46,6 +45,10 @@ public class TileEntityTurretArty extends TileEntityTurretBaseNT implements IGUI
configs.add(BulletConfigSyncingUtil.SHELL_W9);
}
public void enqueueTarget(double x, double y, double z) {
this.targetQueue.add(Vec3.createVectorHelper(x, y, z));
}
@Override
protected List<Integer> getAmmoList() {
return configs;
@ -195,7 +198,104 @@ public class TileEntityTurretArty extends TileEntityTurretBaseNT implements IGUI
}
}
super.updateEntity();
if(this.mode == this.MODE_MANUAL) {
if(!this.targetQueue.isEmpty()) {
this.tPos = this.targetQueue.get(0);
}
} else {
this.targetQueue.clear();
}
if(worldObj.isRemote) {
this.lastRotationPitch = this.rotationPitch;
this.lastRotationYaw = this.rotationYaw;
}
this.aligned = false;
if(!worldObj.isRemote) {
if(this.target != null && !target.isEntityAlive()) {
this.target = null;
this.stattrak++;
}
}
if(target != null && this.mode != this.MODE_MANUAL) {
if(!this.entityInLOS(this.target)) {
this.target = null;
}
}
if(!worldObj.isRemote) {
if(target != null) {
this.tPos = this.getEntityPos(target);
} else {
if(this.mode != this.MODE_MANUAL) {
this.tPos = null;
}
}
}
if(isOn() && hasPower()) {
if(tPos != null)
this.alignTurret();
} else {
this.target = null;
this.tPos = null;
}
if(!worldObj.isRemote) {
if(this.target != null && !target.isEntityAlive()) {
this.target = null;
this.tPos = null;
this.stattrak++;
}
if(isOn() && hasPower()) {
searchTimer--;
this.setPower(this.getPower() - this.getConsumption());
if(searchTimer <= 0) {
searchTimer = this.getDecetorInterval();
if(this.target == null)
this.seekNewTarget();
}
} else {
searchTimer = 0;
}
if(this.aligned) {
this.updateFiringTick();
}
this.power = Library.chargeTEFromItems(slots, 10, this.power, this.getMaxPower());
NBTTagCompound data = this.writePacket();
this.networkPack(data, 250);
} else {
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;
}
}
this.didJustShoot = false;
}
@ -220,6 +320,11 @@ public class TileEntityTurretArty extends TileEntityTurretBaseNT implements IGUI
vec.rotateAroundY((float) -(this.rotationYaw + Math.PI * 0.5));
this.didJustShoot = true;
if(this.mode == this.MODE_MANUAL && !this.targetQueue.isEmpty()) {
this.targetQueue.remove(0);
this.tPos = null;
}
NBTTagCompound data = new NBTTagCompound();
data.setString("type", "vanillaExt");
data.setString("mode", "largeexplode");

Binary file not shown.

After

Width:  |  Height:  |  Size: 299 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 259 B