ABMs with SmЯt™ predictive targeting technology

This commit is contained in:
Boblet 2023-11-23 15:40:35 +01:00 committed by Bob
parent b6f9953b3e
commit 23a55a23a2
14 changed files with 480 additions and 1180 deletions

View File

@ -26,6 +26,12 @@
* Trenchmaster armor is now unbreakable
* The arc welder recipe for advanced circuits now uses simple insulator instead of gold dust
* The arc welder recipes for enhanced and advanced circuits now use only 100mB of fluid instead of 250mB
* Completely rewrote the missile base code, missiles now accelerate smoothly instead of in increments and use interpolated movement, making them less jittery
* Missiles now have a slightly higher top-speed
* Remodeled the anti-ballistic missile
* Anti-ballistic missiles now use predictive targeting as well as a heightened sensor range of 1,000 blocks (instead of 500) which should make them a lot more effective
* Anti-ballistic missiles accelerate 4x faster than normal missiles and have a 50% higher top-speed
* PWRs that have recently been close to unloaded chunks now have a 40 tick timeframe where they are "frozen", only trying to connect to a fluid network but not doing any fission, this should reduce the amount of meltdowns caused by chunkloading
## Fixed
* Fixed thorium bedrock ore using the wrong ore dict key, making it unable to be processed via centrifuge or acidizer

View File

@ -1,168 +1,229 @@
package com.hbm.entity.missile;
import java.util.ArrayList;
import java.util.List;
import com.hbm.entity.particle.EntitySmokeFX;
import com.hbm.entity.logic.IChunkLoader;
import com.hbm.entity.projectile.EntityThrowableInterp;
import com.hbm.explosion.ExplosionLarge;
import com.hbm.main.MainRegistry;
import com.hbm.tileentity.machine.TileEntityMachineRadarNT;
import api.hbm.entity.IRadarDetectable;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.entity.Entity;
import net.minecraft.init.Blocks;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3;
import net.minecraft.world.ChunkCoordIntPair;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeChunkManager;
import net.minecraftforge.common.ForgeChunkManager.Ticket;
import net.minecraftforge.common.ForgeChunkManager.Type;
/*
* COME ON
* STEP 1: GET 24 EGGS
* STEP 2: FUCK EVERY EGG
* STEP 3: BLOW UP ALL THE FUCKING EGGS
* AND FROM THE ASHES THE MOTHER OF ALL OMELETTES WILL BE BORN!
*/
public class EntityMissileAntiBallistic extends Entity implements IRadarDetectable {
public class EntityMissileAntiBallistic extends EntityThrowableInterp implements IChunkLoader, IRadarDetectable {
int activationTimer;
private Ticket loaderTicket;
public Entity tracking;
public double velocity;
protected int activationTimer;
public static double baseSpeed = 1.5D;
public EntityMissileAntiBallistic(World p_i1582_1_) {
super(p_i1582_1_);
}
@Override
public void onUpdate() {
if(activationTimer < 40) {
activationTimer++;
motionY = 1.5D;
this.setLocationAndAngles(posX + this.motionX, posY + this.motionY, posZ + this.motionZ, 0, 0);
this.rotation();
if(!this.worldObj.isRemote && this.posY < 400)
this.worldObj.spawnEntityInWorld(new EntitySmokeFX(this.worldObj, this.posX, this.posY, this.posZ, 0.0, 0.0, 0.0));
} else {
if(activationTimer == 40) {
ExplosionLarge.spawnParticlesRadial(worldObj, posX, posY, posZ, 15);
activationTimer = 100;
}
for(int i = 0; i < 5; i++) {
targetMissile();
this.setLocationAndAngles(posX + this.motionX, posY + this.motionY, posZ + this.motionZ, 0, 0);
this.rotation();
if(!this.worldObj.isRemote && this.posY < 400)
this.worldObj.spawnEntityInWorld(new EntitySmokeFX(this.worldObj, this.posX, this.posY, this.posZ, 0.0, 0.0, 0.0));
List<Entity> list = worldObj.getEntitiesWithinAABBExcludingEntity(null, AxisAlignedBB.getBoundingBox(posX - 5, posY - 5, posZ - 5, posX + 5, posY + 5, posZ + 5));
for(Entity e : list) {
if(e instanceof EntityMissileBaseNT || e instanceof EntityMissileCustom) {
ExplosionLarge.explode(worldObj, posX, posY, posZ, 15F, true, false, true);
this.setDead();
return;
}
}
}
}
if(this.posY > 2000)
this.setDead();
if(this.worldObj.getBlock((int) this.posX, (int) this.posY, (int) this.posZ) != Blocks.air && this.worldObj.getBlock((int) this.posX, (int) this.posY, (int) this.posZ) != Blocks.water && this.worldObj.getBlock((int) this.posX, (int) this.posY, (int) this.posZ) != Blocks.flowing_water) {
if(!this.worldObj.isRemote) {
ExplosionLarge.explode(worldObj, posX, posY, posZ, 10F, true, true, true);
}
this.setDead();
return;
}
}
protected void rotation() {
float f2 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ);
this.rotationYaw = (float) (Math.atan2(this.motionX, this.motionZ) * 180.0D / Math.PI);
for(this.rotationPitch = (float) (Math.atan2(this.motionY, f2) * 180.0D / Math.PI) - 90; this.rotationPitch - this.prevRotationPitch < -180.0F; this.prevRotationPitch -= 360.0F) {
;
}
while(this.rotationPitch - this.prevRotationPitch >= 180.0F) {
this.prevRotationPitch += 360.0F;
}
while(this.rotationYaw - this.prevRotationYaw < -180.0F) {
this.prevRotationYaw -= 360.0F;
}
while(this.rotationYaw - this.prevRotationYaw >= 180.0F) {
this.prevRotationYaw += 360.0F;
}
}
private void targetMissile() {
List<Entity> list = worldObj.getEntitiesWithinAABBExcludingEntity(null, AxisAlignedBB.getBoundingBox(posX - 500, 0, posZ - 500, posX + 500, 5000, posZ + 500));
Entity target = null;
double closest = 1000D;
for(Entity e : list) {
if(e instanceof EntityMissileBaseNT || e instanceof EntityMissileCustom) {
double dis = Math.sqrt(Math.pow(e.posX - posX, 2) + Math.pow(e.posY - posY, 2) + Math.pow(e.posZ - posZ, 2));
if(dis < closest) {
closest = dis;
target = e;
}
}
}
if(target != null) {
Vec3 vec = Vec3.createVectorHelper(target.posX - posX, target.posY - posY, target.posZ - posZ);
vec.normalize();
this.motionX = vec.xCoord * 0.065D;
this.motionY = vec.yCoord * 0.065D;
this.motionZ = vec.zCoord * 0.065D;
}
public EntityMissileAntiBallistic(World world) {
super(world);
this.setSize(1.5F, 1.5F);
this.motionY = baseSpeed;
}
@Override
protected void entityInit() {
super.entityInit();
init(ForgeChunkManager.requestTicket(MainRegistry.instance, worldObj, Type.ENTITY));
}
@Override
protected void readEntityFromNBT(NBTTagCompound p_70037_1_) {
protected double motionMult() {
return velocity;
}
@Override
protected void writeEntityToNBT(NBTTagCompound p_70014_1_) {
public boolean doesImpactEntities() {
return false;
}
@Override
public void onUpdate() {
super.onUpdate();
if(!worldObj.isRemote) {
if(velocity < 6) velocity += 0.1;
if(activationTimer < 40) {
activationTimer++;
motionY = baseSpeed;
} else {
Entity prevTracking = this.tracking;
if(this.tracking == null || this.tracking.isDead) this.targetMissile();
if(prevTracking == null && this.tracking != null) {
ExplosionLarge.spawnShock(worldObj, posX, posY, posZ, 24, 3F);
}
if(this.tracking != null) {
this.aimAtTarget();
}
}
if(this.posY > 2000 && (this.tracking == null || this.tracking.isDead)) this.setDead();
} else {
Vec3 vec = Vec3.createVectorHelper(motionX, motionY, motionZ).normalize();
MainRegistry.proxy.particleControl(posX - vec.xCoord, posY - vec.yCoord, posZ - vec.zCoord, 2);
}
float f2 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ);
this.rotationYaw = (float) (Math.atan2(this.motionX, this.motionZ) * 180.0D / Math.PI);
for(this.rotationPitch = (float) (Math.atan2(this.motionY, f2) * 180.0D / Math.PI) - 90; this.rotationPitch - this.prevRotationPitch < -180.0F; this.prevRotationPitch -= 360.0F);
while(this.rotationPitch - this.prevRotationPitch >= 180.0F) this.prevRotationPitch += 360.0F;
while(this.rotationYaw - this.prevRotationYaw < -180.0F) this.prevRotationYaw -= 360.0F;
while(this.rotationYaw - this.prevRotationYaw >= 180.0F) this.prevRotationYaw += 360.0F;
}
/** Detects and caches nearby EntityMissileBaseNT */
protected void targetMissile() {
Entity closest = null;
double dist = 1_000;
for(Entity e : TileEntityMachineRadarNT.matchingEntities) {
if(e.dimension != this.dimension) continue;
if(!(e instanceof EntityMissileBaseNT)) continue;
Vec3 vec = Vec3.createVectorHelper(e.posX - posX, e.posY - posY, e.posZ - posZ);
if(vec.lengthVector() < dist) {
closest = e;
}
}
this.tracking = closest;
}
/** Predictive targeting system */
protected void aimAtTarget() {
Vec3 delta = Vec3.createVectorHelper(tracking.posX - posX, tracking.posY - posY, tracking.posZ - posZ);
double intercept = delta.lengthVector() / (this.baseSpeed * this.velocity);
Vec3 predicted = Vec3.createVectorHelper(tracking.posX + (tracking.posX - tracking.lastTickPosX) * intercept, tracking.posY + (tracking.posY - tracking.lastTickPosY) * intercept, tracking.posZ + (tracking.posZ - tracking.lastTickPosZ) * intercept);
Vec3 motion = Vec3.createVectorHelper(predicted.xCoord - posX, predicted.yCoord - posY, predicted.zCoord - posZ).normalize();
if(delta.lengthVector() < 10 && activationTimer >= 40) {
ExplosionLarge.explode(worldObj, posX, posY, posZ, 15F, true, false, false);
this.killAndClear();
}
this.motionX = motion.xCoord * baseSpeed;
this.motionY = motion.yCoord * baseSpeed;
this.motionZ = motion.zCoord * baseSpeed;
}
@Override
protected void onImpact(MovingObjectPosition mop) {
if(this.activationTimer >= 40) {
ExplosionLarge.explode(worldObj, posX, posY, posZ, 20F, true, false, false);
this.killAndClear();
}
}
@Override
public double getGravityVelocity() {
return 0.0D;
}
@Override
protected float getAirDrag() {
return 1F;
}
@Override
protected float getWaterDrag() {
return 1F;
}
@Override
public void readEntityFromNBT(NBTTagCompound nbt) {
super.readEntityFromNBT(nbt);
this.velocity = nbt.getDouble("veloc");
}
@Override
public void writeEntityToNBT(NBTTagCompound nbt) {
super.writeEntityToNBT(nbt);
nbt.setDouble("veloc", this.velocity);
}
@Override
public void init(Ticket ticket) {
if(!worldObj.isRemote) {
if(ticket != null) {
if(loaderTicket == null) {
loaderTicket = ticket;
loaderTicket.bindEntity(this);
loaderTicket.getModData();
}
ForgeChunkManager.forceChunk(loaderTicket, new ChunkCoordIntPair(chunkCoordX, chunkCoordZ));
}
}
}
List<ChunkCoordIntPair> loadedChunks = new ArrayList<ChunkCoordIntPair>();
public void loadNeighboringChunks(int newChunkX, int newChunkZ) {
if(!worldObj.isRemote && loaderTicket != null) {
clearChunkLoader();
loadedChunks.clear();
loadedChunks.add(new ChunkCoordIntPair(newChunkX, newChunkZ));
//loadedChunks.add(new ChunkCoordIntPair(newChunkX + (int) Math.floor((this.posX + this.motionX * this.motionMult()) / 16D), newChunkZ + (int) Math.floor((this.posZ + this.motionZ * this.motionMult()) / 16D)));
for(ChunkCoordIntPair chunk : loadedChunks) {
ForgeChunkManager.forceChunk(loaderTicket, chunk);
}
}
}
public void killAndClear() {
this.setDead();
this.clearChunkLoader();
}
public void clearChunkLoader() {
if(!worldObj.isRemote && loaderTicket != null) {
for(ChunkCoordIntPair chunk : loadedChunks) {
ForgeChunkManager.unforceChunk(loaderTicket, chunk);
}
}
}
@Override
@SideOnly(Side.CLIENT)
public boolean isInRangeToRenderDist(double distance) {
return distance < 500000;
return true;
}
@Override
public RadarTargetType getTargetType() {
return RadarTargetType.MISSILE_AB;
}
}

View File

@ -237,6 +237,7 @@ public abstract class EntityMissileBaseNT extends EntityThrowableInterp implemen
return 1F;
}
@Override
public void init(Ticket ticket) {
if(!worldObj.isRemote) {

View File

@ -229,7 +229,7 @@ public class EntityMissileCustom extends EntityMissileBaseNT implements IChunkLo
if(top == PartSize.SIZE_15 && bottom == PartSize.SIZE_20) return RadarTargetType.MISSILE_15_20;
if(top == PartSize.SIZE_20 && bottom == PartSize.SIZE_20) return RadarTargetType.MISSILE_20;
return RadarTargetType.PLAYER;
return RadarTargetType.MISSILE_TIER1;
}
@Override public List<ItemStack> getDebris() { return new ArrayList(); }

View File

@ -1,24 +0,0 @@
package com.hbm.inventory.container;
import com.hbm.tileentity.machine.TileEntityMachineRadar;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ICrafting;
public class ContainerMachineRadar extends Container {
public ContainerMachineRadar(InventoryPlayer invPlayer, TileEntityMachineRadar tedf) {
}
@Override
public void addCraftingToCrafters(ICrafting crafting) {
super.addCraftingToCrafters(crafting);
}
@Override
public boolean canInteractWith(EntityPlayer player) {
return true;
}
}

View File

@ -1,143 +0,0 @@
package com.hbm.inventory.gui;
import java.util.Arrays;
import org.lwjgl.opengl.GL11;
import com.hbm.config.WeaponConfig;
import com.hbm.inventory.container.ContainerMachineRadar;
import com.hbm.lib.RefStrings;
import com.hbm.packet.AuxButtonPacket;
import com.hbm.packet.PacketDispatcher;
import com.hbm.tileentity.machine.TileEntityMachineRadar;
import com.hbm.util.I18nUtil;
import api.hbm.entity.IRadarDetectable.RadarTargetType;
import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.PositionedSoundRecord;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.ResourceLocation;
public class GUIMachineRadar extends GuiInfoContainer {
private static ResourceLocation texture = new ResourceLocation(RefStrings.MODID + ":textures/gui/machine/gui_radar.png");
private TileEntityMachineRadar diFurnace;
public GUIMachineRadar(InventoryPlayer invPlayer, TileEntityMachineRadar tedf) {
super(new ContainerMachineRadar(invPlayer, tedf));
diFurnace = tedf;
texture = new ResourceLocation(RefStrings.MODID + ":textures/gui/machine/gui_radar.png");
this.xSize = 216;
this.ySize = 234;
}
@Override
public void drawScreen(int mouseX, int mouseY, float f) {
super.drawScreen(mouseX, mouseY, f);
this.drawElectricityInfo(this, mouseX, mouseY, guiLeft + 8, guiTop + 221, 200, 7, diFurnace.power, diFurnace.maxPower);
this.drawCustomInfoStat(mouseX, mouseY, guiLeft - 10, guiTop + 98, 8, 8, mouseX, mouseY, I18nUtil.resolveKeyArray("radar.detectMissiles") );
this.drawCustomInfoStat(mouseX, mouseY, guiLeft - 10, guiTop + 108, 8, 8, mouseX, mouseY, I18nUtil.resolveKeyArray("radar.detectPlayers"));
this.drawCustomInfoStat(mouseX, mouseY, guiLeft - 10, guiTop + 118, 8, 8, mouseX, mouseY, I18nUtil.resolveKeyArray("radar.smartMode"));
this.drawCustomInfoStat(mouseX, mouseY, guiLeft - 10, guiTop + 128, 8, 8, mouseX, mouseY, I18nUtil.resolveKeyArray("radar.redMode"));
if(!diFurnace.nearbyMissiles.isEmpty()) {
for(int[] m : diFurnace.nearbyMissiles) {
int x = guiLeft + (int)((m[0] - diFurnace.xCoord) / ((double)WeaponConfig.radarRange * 2 + 1) * (200D - 8D)) + 108;
int z = guiTop + (int)((m[1] - diFurnace.zCoord) / ((double)WeaponConfig.radarRange * 2 + 1) * (200D - 8D)) + 117;
if(mouseX + 4 > x && mouseX - 4 < x &&
mouseY + 4 > z && mouseY - 4 < z) {
String[] text = new String[] { RadarTargetType.values()[m[2]].name, m[0] + " / " + m[1], "Alt.: " + m[3] };
this.func_146283_a(Arrays.asList(text), x, z);
return;
}
}
}
}
@Override
protected void mouseClicked(int x, int y, int i) {
super.mouseClicked(x, y, i);
if(guiLeft -10 <= x && guiLeft + -10 + 8 > x && guiTop + 98 < y && guiTop + 98 + 8 >= y) {
mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F));
PacketDispatcher.wrapper.sendToServer(new AuxButtonPacket(diFurnace.xCoord, diFurnace.yCoord, diFurnace.zCoord, 0, 0));
}
if(guiLeft -10 <= x && guiLeft + -10 + 8 > x && guiTop + 108 < y && guiTop + 108 + 8 >= y) {
mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F));
PacketDispatcher.wrapper.sendToServer(new AuxButtonPacket(diFurnace.xCoord, diFurnace.yCoord, diFurnace.zCoord, 0, 1));
}
if(guiLeft -10 <= x && guiLeft + -10 + 8 > x && guiTop + 118 < y && guiTop + 118 + 8 >= y) {
mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F));
PacketDispatcher.wrapper.sendToServer(new AuxButtonPacket(diFurnace.xCoord, diFurnace.yCoord, diFurnace.zCoord, 0, 2));
}
if(guiLeft -10 <= x && guiLeft + -10 + 8 > x && guiTop + 128 < y && guiTop + 128 + 8 >= y) {
mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F));
PacketDispatcher.wrapper.sendToServer(new AuxButtonPacket(diFurnace.xCoord, diFurnace.yCoord, diFurnace.zCoord, 0, 3));
}
}
@Override
protected void drawGuiContainerForegroundLayer(int i, int j) {
String name = I18n.format("container.radar");
this.fontRendererObj.drawString(name, this.xSize / 2 - this.fontRendererObj.getStringWidth(name) / 2, 6, 4210752);
}
@Override
protected void drawGuiContainerBackgroundLayer(float p_146976_1_, int p_146976_2_, int p_146976_3_) {
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
Minecraft.getMinecraft().getTextureManager().bindTexture(texture);
drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
drawTexturedModalRect(guiLeft - 14, guiTop + 94, 216, 198, 14, 46);
if(diFurnace.scanMissiles || (diFurnace.jammed && diFurnace.getWorldObj().rand.nextBoolean()))
drawTexturedModalRect(guiLeft - 10, guiTop + 98, 230, 202, 8, 8);
if(diFurnace.scanPlayers || (diFurnace.jammed && diFurnace.getWorldObj().rand.nextBoolean()))
drawTexturedModalRect(guiLeft - 10, guiTop + 108, 230, 212, 8, 8);
if(diFurnace.smartMode || (diFurnace.jammed && diFurnace.getWorldObj().rand.nextBoolean()))
drawTexturedModalRect(guiLeft - 10, guiTop + 118, 230, 222, 8, 8);
if(diFurnace.redMode || (diFurnace.jammed && diFurnace.getWorldObj().rand.nextBoolean()))
drawTexturedModalRect(guiLeft - 10, guiTop + 128, 230, 232, 8, 8);
if(diFurnace.power > 0) {
int i = (int)diFurnace.getPowerScaled(200);
drawTexturedModalRect(guiLeft + 8, guiTop + 221, 0, 234, i, 16);
}
if(diFurnace.jammed) {
for(int i = 0; i < 5; i++) {
for(int j = 0; j < 5; j++) {
drawTexturedModalRect(guiLeft + 8 + i * 40, guiTop + 17 + j * 40, 216, 118 + diFurnace.getWorldObj().rand.nextInt(41), 40, 40);
}
}
return;
}
if(!diFurnace.nearbyMissiles.isEmpty()) {
for(int[] m : diFurnace.nearbyMissiles) {
int x = (int)((m[0] - diFurnace.xCoord) / ((double)WeaponConfig.radarRange * 2 + 1) * (200D - 8D)) - 4;
int z = (int)((m[1] - diFurnace.zCoord) / ((double)WeaponConfig.radarRange * 2 + 1) * (200D - 8D)) - 4;
int t = m[2];
drawTexturedModalRect(guiLeft + 108 + x, guiTop + 117 + z, 216, 8 * t, 8, 8);
}
}
}
}

View File

@ -19,10 +19,6 @@ public class PacketDispatcher {
wrapper.registerMessage(TEStructurePacket.Handler.class, TEStructurePacket.class, i++, Side.CLIENT);
//Mining drill rotation for rendering
wrapper.registerMessage(TEDrillPacket.Handler.class, TEDrillPacket.class, i++, Side.CLIENT);
//Mining drill torque for sounds
wrapper.registerMessage(TEDrillSoundPacket.Handler.class, TEDrillSoundPacket.class, i++, Side.CLIENT);
//Missile type for rendering
wrapper.registerMessage(TEMissilePacket.Handler.class, TEMissilePacket.class, i++, Side.CLIENT);
//Fluid packet for GUI
wrapper.registerMessage(TEFluidPacket.Handler.class, TEFluidPacket.class, i++, Side.CLIENT);
//Sound packet that keeps client and server separated
@ -35,8 +31,6 @@ public class PacketDispatcher {
wrapper.registerMessage(TESirenPacket.Handler.class, TESirenPacket.class, i++, Side.CLIENT);
//Signals server to change ItemStacks
wrapper.registerMessage(ItemDesignatorPacket.Handler.class, ItemDesignatorPacket.class, i++, Side.SERVER);
//Siren packet for looped sounds
wrapper.registerMessage(TERadarPacket.Handler.class, TERadarPacket.class, i++, Side.CLIENT);
//Signals server to perform orbital strike, among other things
wrapper.registerMessage(SatLaserPacket.Handler.class, SatLaserPacket.class, i++, Side.SERVER);
//Universal package for sending small info packs back to server

View File

@ -1,62 +0,0 @@
package com.hbm.packet;
import com.hbm.tileentity.machine.TileEntityMachineMiningDrill;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import io.netty.buffer.ByteBuf;
import net.minecraft.client.Minecraft;
import net.minecraft.tileentity.TileEntity;
public class TEDrillSoundPacket implements IMessage {
int x;
int y;
int z;
float spin;
public TEDrillSoundPacket()
{
}
public TEDrillSoundPacket(int x, int y, int z, float spin)
{
this.x = x;
this.y = y;
this.z = z;
this.spin = spin;
}
@Override
public void fromBytes(ByteBuf buf) {
x = buf.readInt();
y = buf.readInt();
z = buf.readInt();
spin = buf.readFloat();
}
@Override
public void toBytes(ByteBuf buf) {
buf.writeInt(x);
buf.writeInt(y);
buf.writeInt(z);
buf.writeFloat(spin);
}
public static class Handler implements IMessageHandler<TEDrillSoundPacket, IMessage> {
@Override
public IMessage onMessage(TEDrillSoundPacket m, MessageContext ctx) {
TileEntity te = Minecraft.getMinecraft().theWorld.getTileEntity(m.x, m.y, m.z);
if (te != null && te instanceof TileEntityMachineMiningDrill) {
TileEntityMachineMiningDrill gen = (TileEntityMachineMiningDrill) te;
gen.torque = m.spin;
}
return null;
}
}
}

View File

@ -1,124 +0,0 @@
package com.hbm.packet;
import com.hbm.interfaces.Spaghetti;
import com.hbm.items.ModItems;
import com.hbm.tileentity.bomb.TileEntityLaunchPad;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import io.netty.buffer.ByteBuf;
import net.minecraft.client.Minecraft;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
public class TEMissilePacket implements IMessage {
int x;
int y;
int z;
int type;
public TEMissilePacket() { }
@Spaghetti("die")
public TEMissilePacket(int x, int y, int z, ItemStack stack) {
this.x = x;
this.y = y;
this.z = z;
this.type = 0;
if(stack != null) {
if(stack.getItem() == ModItems.missile_generic)
type = 1;
if(stack.getItem() == ModItems.missile_strong)
type = 2;
if(stack.getItem() == ModItems.missile_cluster)
type = 3;
if(stack.getItem() == ModItems.missile_nuclear)
type = 4;
if(stack.getItem() == ModItems.missile_incendiary)
type = 5;
if(stack.getItem() == ModItems.missile_buster)
type = 6;
if(stack.getItem() == ModItems.missile_incendiary_strong)
type = 7;
if(stack.getItem() == ModItems.missile_cluster_strong)
type = 8;
if(stack.getItem() == ModItems.missile_buster_strong)
type = 9;
if(stack.getItem() == ModItems.missile_burst)
type = 10;
if(stack.getItem() == ModItems.missile_inferno)
type = 11;
if(stack.getItem() == ModItems.missile_rain)
type = 12;
if(stack.getItem() == ModItems.missile_drill)
type = 13;
if(stack.getItem() == ModItems.missile_endo)
type = 14;
if(stack.getItem() == ModItems.missile_exo)
type = 15;
if(stack.getItem() == ModItems.missile_nuclear_cluster)
type = 16;
if(stack.getItem() == ModItems.missile_doomsday)
type = 17;
if(stack.getItem() == ModItems.missile_taint)
type = 18;
if(stack.getItem() == ModItems.missile_micro)
type = 19;
if(stack.getItem() == ModItems.missile_carrier)
type = 20;
if(stack.getItem() == ModItems.missile_anti_ballistic)
type = 21;
if(stack.getItem() == ModItems.missile_bhole)
type = 22;
if(stack.getItem() == ModItems.missile_schrabidium)
type = 23;
if(stack.getItem() == ModItems.missile_emp)
type = 24;
if(stack.getItem() == ModItems.missile_emp_strong)
type = 25;
if(stack.getItem() == ModItems.missile_volcano)
type = 26;
if(stack.getItem() == ModItems.missile_shuttle)
type = 27;
}
}
@Override
public void fromBytes(ByteBuf buf) {
x = buf.readInt();
y = buf.readInt();
z = buf.readInt();
type = buf.readInt();
}
@Override
public void toBytes(ByteBuf buf) {
buf.writeInt(x);
buf.writeInt(y);
buf.writeInt(z);
buf.writeInt(type);
}
public static class Handler implements IMessageHandler<TEMissilePacket, IMessage> {
@Override
public IMessage onMessage(TEMissilePacket m, MessageContext ctx) {
try {
TileEntity te = Minecraft.getMinecraft().theWorld.getTileEntity(m.x, m.y, m.z);
if (te != null && te instanceof TileEntityLaunchPad) {
TileEntityLaunchPad gen = (TileEntityLaunchPad)te;
gen.state = m.type;
}
} catch(Exception e) { }
return null;
}
}
}

View File

@ -1,78 +0,0 @@
package com.hbm.packet;
import com.hbm.tileentity.machine.TileEntityMachineRadar;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import io.netty.buffer.ByteBuf;
import net.minecraft.client.Minecraft;
import net.minecraft.tileentity.TileEntity;
public class TERadarPacket implements IMessage {
int x;
int y;
int z;
int conX;
int conY;
int conZ;
int alt;
public TERadarPacket() {
}
public TERadarPacket(int x, int y, int z, int conX, int conY, int conZ, int alt) {
this.x = x;
this.y = y;
this.z = z;
this.conX = conX;
this.conY = conY;
this.conZ = conZ;
this.alt = alt;
}
@Override
public void fromBytes(ByteBuf buf) {
x = buf.readInt();
y = buf.readInt();
z = buf.readInt();
conX = buf.readInt();
conY = buf.readInt();
conZ = buf.readInt();
alt = buf.readInt();
}
@Override
public void toBytes(ByteBuf buf) {
buf.writeInt(x);
buf.writeInt(y);
buf.writeInt(z);
buf.writeInt(conX);
buf.writeInt(conY);
buf.writeInt(conZ);
buf.writeInt(alt);
}
public static class Handler implements IMessageHandler<TERadarPacket, IMessage> {
@Override
@SideOnly(Side.CLIENT)
public IMessage onMessage(TERadarPacket m, MessageContext ctx) {
TileEntity te = Minecraft.getMinecraft().theWorld.getTileEntity(m.x, m.y, m.z);
try {
if (te != null && te instanceof TileEntityMachineRadar) {
TileEntityMachineRadar radar = (TileEntityMachineRadar) te;
radar.nearbyMissiles.add(new int[]{m.conX, m.conY, m.conZ, m.alt});
}
} catch (Exception x) {
}
return null;
}
}
}

View File

@ -2,213 +2,190 @@ package com.hbm.render.tileentity;
import org.lwjgl.opengl.GL11;
import com.hbm.items.ModItems;
import com.hbm.main.ResourceManager;
import com.hbm.tileentity.bomb.TileEntityLaunchPad;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
public class RenderLaunchPadTier1 extends TileEntitySpecialRenderer {
@Override
public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float f)
{
GL11.glPushMatrix();
GL11.glTranslated(x + 0.5D, y, z + 0.5D);
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_CULL_FACE);
bindTexture(ResourceManager.missile_pad_tex);
ResourceManager.missile_pad.renderAll();
@Override
public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float f) {
GL11.glPushMatrix();
GL11.glTranslated(x + 0.5D, y, z + 0.5D);
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_CULL_FACE);
GL11.glDisable(GL11.GL_CULL_FACE);
int state = 0;
if(tileEntity instanceof TileEntityLaunchPad)
state = ((TileEntityLaunchPad)tileEntity).state;
GL11.glTranslated(0, 1, 0);
if(state == 1)
{
GL11.glScalef(1.0F, 1.0F, 1.0F);
bindTexture(ResourceManager.missileV2_HE_tex);
ResourceManager.missileV2.renderAll();
}
if(state == 2)
{
GL11.glScalef(1.5F, 1.5F, 1.5F);
bindTexture(ResourceManager.missileStrong_HE_tex);
ResourceManager.missileStrong.renderAll();
}
if(state == 3)
{
GL11.glScalef(1.0F, 1.0F, 1.0F);
bindTexture(ResourceManager.missileV2_CL_tex);
ResourceManager.missileV2.renderAll();
}
if(state == 4)
{
GL11.glScalef(1.5F, 1.5F, 1.5F);
bindTexture(ResourceManager.missileNuclear_tex);
ResourceManager.missileNuclear.renderAll();
}
if(state == 5)
{
GL11.glScalef(1.0F, 1.0F, 1.0F);
bindTexture(ResourceManager.missileV2_IN_tex);
ResourceManager.missileV2.renderAll();
}
if(state == 6)
{
GL11.glScalef(1.0F, 1.0F, 1.0F);
bindTexture(ResourceManager.missileV2_BU_tex);
ResourceManager.missileV2.renderAll();
}
if(state == 7)
{
GL11.glScalef(1.5F, 1.5F, 1.5F);
bindTexture(ResourceManager.missileStrong_IN_tex);
ResourceManager.missileStrong.renderAll();
}
if(state == 8)
{
GL11.glScalef(1.5F, 1.5F, 1.5F);
bindTexture(ResourceManager.missileStrong_CL_tex);
ResourceManager.missileStrong.renderAll();
}
if(state == 9)
{
GL11.glScalef(1.5F, 1.5F, 1.5F);
bindTexture(ResourceManager.missileStrong_BU_tex);
ResourceManager.missileStrong.renderAll();
}
if(state == 10)
{
GL11.glScalef(2.0F, 2.0F, 2.0F);
bindTexture(ResourceManager.missileHuge_HE_tex);
ResourceManager.missileHuge.renderAll();
}
if(state == 11)
{
GL11.glScalef(2.0F, 2.0F, 2.0F);
bindTexture(ResourceManager.missileHuge_IN_tex);
ResourceManager.missileHuge.renderAll();
}
if(state == 12)
{
GL11.glScalef(2.0F, 2.0F, 2.0F);
bindTexture(ResourceManager.missileHuge_CL_tex);
ResourceManager.missileHuge.renderAll();
}
if(state == 13)
{
GL11.glScalef(2.0F, 2.0F, 2.0F);
bindTexture(ResourceManager.missileHuge_BU_tex);
ResourceManager.missileHuge.renderAll();
}
if(state == 14)
{
GL11.glScalef(1.5F, 1.5F, 1.5F);
bindTexture(ResourceManager.missileEndo_tex);
ResourceManager.missileThermo.renderAll();
}
if(state == 15)
{
GL11.glScalef(1.5F, 1.5F, 1.5F);
bindTexture(ResourceManager.missileExo_tex);
ResourceManager.missileThermo.renderAll();
}
if(state == 16)
{
GL11.glScalef(1.5F, 1.5F, 1.5F);
bindTexture(ResourceManager.missileMIRV_tex);
ResourceManager.missileNuclear.renderAll();
}
if(state == 17)
{
GL11.glScalef(2F, 2F, 2F);
bindTexture(ResourceManager.missileDoomsday_tex);
ResourceManager.missileDoomsday.renderAll();
}
if(state == 18)
{
GL11.glScalef(2F, 2F, 2F);
bindTexture(ResourceManager.missileTaint_tex);
ResourceManager.missileTaint.renderAll();
}
if(state == 19)
{
GL11.glScalef(2F, 2F, 2F);
bindTexture(ResourceManager.missileMicro_tex);
ResourceManager.missileTaint.renderAll();
}
if(state == 20)
{
GL11.glScalef(2F, 2F, 2F);
bindTexture(ResourceManager.missileCarrier_tex);
ResourceManager.missileCarrier.renderAll();
GL11.glTranslated(0.0D, 0.5D, 0.0D);
GL11.glTranslated(1.25D, 0.0D, 0.0D);
bindTexture(ResourceManager.missileBooster_tex);
ResourceManager.missileBooster.renderAll();
GL11.glTranslated(-2.5D, 0.0D, 0.0D);
ResourceManager.missileBooster.renderAll();
GL11.glTranslated(1.25D, 0.0D, 0.0D);
GL11.glTranslated(0.0D, 0.0D, 1.25D);
ResourceManager.missileBooster.renderAll();
GL11.glTranslated(0.0D, 0.0D, -2.5D);
ResourceManager.missileBooster.renderAll();
GL11.glTranslated(0.0D, 0.0D, 1.25D);
}
if(state == 21)
{
GL11.glScalef(1.0F, 1.0F, 1.0F);
bindTexture(ResourceManager.missileAA_tex);
GL11.glShadeModel(GL11.GL_SMOOTH);
ResourceManager.missileABM.renderAll();
GL11.glShadeModel(GL11.GL_FLAT);
}
if(state == 22)
{
GL11.glScalef(2F, 2F, 2F);
bindTexture(ResourceManager.missileMicroBHole_tex);
ResourceManager.missileTaint.renderAll();
}
if(state == 23)
{
GL11.glScalef(2F, 2F, 2F);
bindTexture(ResourceManager.missileMicroSchrab_tex);
ResourceManager.missileTaint.renderAll();
}
if(state == 24)
{
GL11.glScalef(2F, 2F, 2F);
bindTexture(ResourceManager.missileMicroEMP_tex);
ResourceManager.missileTaint.renderAll();
}
if(state == 25)
{
GL11.glScalef(1.5F, 1.5F, 1.5F);
bindTexture(ResourceManager.missileStrong_EMP_tex);
ResourceManager.missileStrong.renderAll();
}
if(state == 26)
{
GL11.glScalef(1.5F, 1.5F, 1.5F);
bindTexture(ResourceManager.missileVolcano_tex);
ResourceManager.missileNuclear.renderAll();
}
if(state == 27)
{
GL11.glScalef(1.0F, 1.0F, 1.0F);
bindTexture(ResourceManager.missileShuttle_tex);
ResourceManager.missileShuttle.renderAll();
}
bindTexture(ResourceManager.missile_pad_tex);
ResourceManager.missile_pad.renderAll();
GL11.glDisable(GL11.GL_CULL_FACE);
if(tileEntity instanceof TileEntityLaunchPad) {
ItemStack toRender = ((TileEntityLaunchPad) tileEntity).toRender;
GL11.glEnable(GL11.GL_CULL_FACE);
if(toRender != null) {
GL11.glTranslated(0, 1, 0);
//TODO: add a registry for missile rendering to be reused here and for the entity renderer
if(toRender.getItem() == ModItems.missile_generic) {
GL11.glScalef(1.0F, 1.0F, 1.0F);
bindTexture(ResourceManager.missileV2_HE_tex);
ResourceManager.missileV2.renderAll();
}
if(toRender.getItem() == ModItems.missile_strong) {
GL11.glScalef(1.5F, 1.5F, 1.5F);
bindTexture(ResourceManager.missileStrong_HE_tex);
ResourceManager.missileStrong.renderAll();
}
if(toRender.getItem() == ModItems.missile_cluster) {
GL11.glScalef(1.0F, 1.0F, 1.0F);
bindTexture(ResourceManager.missileV2_CL_tex);
ResourceManager.missileV2.renderAll();
}
if(toRender.getItem() == ModItems.missile_nuclear) {
GL11.glScalef(1.5F, 1.5F, 1.5F);
bindTexture(ResourceManager.missileNuclear_tex);
ResourceManager.missileNuclear.renderAll();
}
if(toRender.getItem() == ModItems.missile_incendiary) {
GL11.glScalef(1.0F, 1.0F, 1.0F);
bindTexture(ResourceManager.missileV2_IN_tex);
ResourceManager.missileV2.renderAll();
}
if(toRender.getItem() == ModItems.missile_buster) {
GL11.glScalef(1.0F, 1.0F, 1.0F);
bindTexture(ResourceManager.missileV2_BU_tex);
ResourceManager.missileV2.renderAll();
}
if(toRender.getItem() == ModItems.missile_incendiary_strong) {
GL11.glScalef(1.5F, 1.5F, 1.5F);
bindTexture(ResourceManager.missileStrong_IN_tex);
ResourceManager.missileStrong.renderAll();
}
if(toRender.getItem() == ModItems.missile_cluster_strong) {
GL11.glScalef(1.5F, 1.5F, 1.5F);
bindTexture(ResourceManager.missileStrong_CL_tex);
ResourceManager.missileStrong.renderAll();
}
if(toRender.getItem() == ModItems.missile_buster_strong) {
GL11.glScalef(1.5F, 1.5F, 1.5F);
bindTexture(ResourceManager.missileStrong_BU_tex);
ResourceManager.missileStrong.renderAll();
}
if(toRender.getItem() == ModItems.missile_burst) {
GL11.glScalef(2.0F, 2.0F, 2.0F);
bindTexture(ResourceManager.missileHuge_HE_tex);
ResourceManager.missileHuge.renderAll();
}
if(toRender.getItem() == ModItems.missile_inferno) {
GL11.glScalef(2.0F, 2.0F, 2.0F);
bindTexture(ResourceManager.missileHuge_IN_tex);
ResourceManager.missileHuge.renderAll();
}
if(toRender.getItem() == ModItems.missile_rain) {
GL11.glScalef(2.0F, 2.0F, 2.0F);
bindTexture(ResourceManager.missileHuge_CL_tex);
ResourceManager.missileHuge.renderAll();
}
if(toRender.getItem() == ModItems.missile_drill) {
GL11.glScalef(2.0F, 2.0F, 2.0F);
bindTexture(ResourceManager.missileHuge_BU_tex);
ResourceManager.missileHuge.renderAll();
}
if(toRender.getItem() == ModItems.missile_endo) {
GL11.glScalef(1.5F, 1.5F, 1.5F);
bindTexture(ResourceManager.missileEndo_tex);
ResourceManager.missileThermo.renderAll();
}
if(toRender.getItem() == ModItems.missile_exo) {
GL11.glScalef(1.5F, 1.5F, 1.5F);
bindTexture(ResourceManager.missileExo_tex);
ResourceManager.missileThermo.renderAll();
}
if(toRender.getItem() == ModItems.missile_nuclear_cluster) {
GL11.glScalef(1.5F, 1.5F, 1.5F);
bindTexture(ResourceManager.missileMIRV_tex);
ResourceManager.missileNuclear.renderAll();
}
if(toRender.getItem() == ModItems.missile_doomsday) {
GL11.glScalef(2F, 2F, 2F);
bindTexture(ResourceManager.missileDoomsday_tex);
ResourceManager.missileDoomsday.renderAll();
}
if(toRender.getItem() == ModItems.missile_taint) {
GL11.glScalef(2F, 2F, 2F);
bindTexture(ResourceManager.missileTaint_tex);
ResourceManager.missileTaint.renderAll();
}
if(toRender.getItem() == ModItems.missile_micro) {
GL11.glScalef(2F, 2F, 2F);
bindTexture(ResourceManager.missileMicro_tex);
ResourceManager.missileTaint.renderAll();
}
if(toRender.getItem() == ModItems.missile_carrier) {
GL11.glScalef(2F, 2F, 2F);
bindTexture(ResourceManager.missileCarrier_tex);
ResourceManager.missileCarrier.renderAll();
GL11.glTranslated(0.0D, 0.5D, 0.0D);
GL11.glTranslated(1.25D, 0.0D, 0.0D);
bindTexture(ResourceManager.missileBooster_tex);
ResourceManager.missileBooster.renderAll();
GL11.glTranslated(-2.5D, 0.0D, 0.0D);
ResourceManager.missileBooster.renderAll();
GL11.glTranslated(1.25D, 0.0D, 0.0D);
GL11.glTranslated(0.0D, 0.0D, 1.25D);
ResourceManager.missileBooster.renderAll();
GL11.glTranslated(0.0D, 0.0D, -2.5D);
ResourceManager.missileBooster.renderAll();
GL11.glTranslated(0.0D, 0.0D, 1.25D);
}
if(toRender.getItem() == ModItems.missile_anti_ballistic) {
GL11.glScalef(1.0F, 1.0F, 1.0F);
bindTexture(ResourceManager.missileAA_tex);
GL11.glShadeModel(GL11.GL_SMOOTH);
ResourceManager.missileABM.renderAll();
GL11.glShadeModel(GL11.GL_FLAT);
}
if(toRender.getItem() == ModItems.missile_bhole) {
GL11.glScalef(2F, 2F, 2F);
bindTexture(ResourceManager.missileMicroBHole_tex);
ResourceManager.missileTaint.renderAll();
}
if(toRender.getItem() == ModItems.missile_schrabidium) {
GL11.glScalef(2F, 2F, 2F);
bindTexture(ResourceManager.missileMicroSchrab_tex);
ResourceManager.missileTaint.renderAll();
}
if(toRender.getItem() == ModItems.missile_emp) {
GL11.glScalef(2F, 2F, 2F);
bindTexture(ResourceManager.missileMicroEMP_tex);
ResourceManager.missileTaint.renderAll();
}
if(toRender.getItem() == ModItems.missile_emp_strong) {
GL11.glScalef(1.5F, 1.5F, 1.5F);
bindTexture(ResourceManager.missileStrong_EMP_tex);
ResourceManager.missileStrong.renderAll();
}
if(toRender.getItem() == ModItems.missile_volcano) {
GL11.glScalef(1.5F, 1.5F, 1.5F);
bindTexture(ResourceManager.missileVolcano_tex);
ResourceManager.missileNuclear.renderAll();
}
if(toRender.getItem() == ModItems.missile_shuttle) {
GL11.glScalef(1.0F, 1.0F, 1.0F);
bindTexture(ResourceManager.missileShuttle_tex);
ResourceManager.missileShuttle.renderAll();
}
}
}
GL11.glPopMatrix();
}
GL11.glEnable(GL11.GL_CULL_FACE);
GL11.glPopMatrix();
}
}

View File

@ -5,16 +5,13 @@ import com.hbm.blocks.bomb.LaunchPad;
import com.hbm.inventory.container.ContainerLaunchPadTier1;
import com.hbm.inventory.gui.GUILaunchPadTier1;
import com.hbm.lib.Library;
import com.hbm.packet.AuxElectricityPacket;
import com.hbm.packet.PacketDispatcher;
import com.hbm.packet.TEMissilePacket;
import com.hbm.tileentity.IGUIProvider;
import com.hbm.tileentity.INBTPacketReceiver;
import com.hbm.tileentity.TileEntityLoadedBase;
import api.hbm.energy.IEnergyUser;
import api.hbm.item.IDesignatorItem;
import cpw.mods.fml.common.Optional;
import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import li.cil.oc.api.machine.Arguments;
@ -25,6 +22,7 @@ import net.minecraft.client.gui.GuiScreen;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
@ -34,9 +32,10 @@ import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
@Optional.InterfaceList({@Optional.Interface(iface = "li.cil.oc.api.network.SimpleComponent", modid = "OpenComputers")})
public class TileEntityLaunchPad extends TileEntityLoadedBase implements ISidedInventory, IEnergyUser, SimpleComponent, IGUIProvider {
public class TileEntityLaunchPad extends TileEntityLoadedBase implements ISidedInventory, INBTPacketReceiver, IEnergyUser, SimpleComponent, IGUIProvider {
public ItemStack slots[];
public ItemStack toRender;
public long power;
public final long maxPower = 100000;
@ -44,7 +43,6 @@ public class TileEntityLaunchPad extends TileEntityLoadedBase implements ISidedI
private static final int[] slots_top = new int[] {0};
private static final int[] slots_bottom = new int[] { 0, 1, 2};
private static final int[] slots_side = new int[] {0};
public int state = 0;
private String customName;
public TileEntityLaunchPad() {
@ -209,8 +207,25 @@ public class TileEntityLaunchPad extends TileEntityLoadedBase implements ISidedI
power = Library.chargeTEFromItems(slots, 2, power, maxPower);
this.updateConnections();
PacketDispatcher.wrapper.sendToAllAround(new TEMissilePacket(xCoord, yCoord, zCoord, slots[0]), new TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 250));
PacketDispatcher.wrapper.sendToAllAround(new AuxElectricityPacket(xCoord, yCoord, zCoord, power), new TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 50));
NBTTagCompound data = new NBTTagCompound();
data.setLong("power", power);
if(slots[0] != null) {
data.setInteger("id", Item.getIdFromItem(slots[0].getItem()));
data.setShort("meta", (short) slots[0].getItemDamage());
}
INBTPacketReceiver.networkPack(this, data, 250);
}
}
@Override
public void networkUnpack(NBTTagCompound nbt) {
this.power = nbt.getLong("power");
if(nbt.hasKey("id")) {
this.toRender = new ItemStack(Item.getItemById(nbt.getInteger("id")), 1, nbt.getShort("meta"));
} else {
this.toRender = null;
}
}

View File

@ -1,342 +0,0 @@
package com.hbm.tileentity.machine;
import java.util.ArrayList;
import java.util.List;
import com.hbm.blocks.ModBlocks;
import com.hbm.config.WeaponConfig;
import com.hbm.extprop.HbmLivingProps;
import com.hbm.inventory.container.ContainerMachineRadar;
import com.hbm.inventory.gui.GUIMachineRadar;
import com.hbm.tileentity.IGUIProvider;
import com.hbm.tileentity.TileEntityTickingBase;
import api.hbm.energy.IEnergyUser;
import api.hbm.entity.IRadarDetectable;
import api.hbm.entity.IRadarDetectable.RadarTargetType;
import cpw.mods.fml.common.Optional;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
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.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;
import li.cil.oc.api.machine.Arguments;
import li.cil.oc.api.machine.Callback;
import li.cil.oc.api.machine.Context;
import li.cil.oc.api.network.SimpleComponent;
@Optional.InterfaceList({@Optional.Interface(iface = "li.cil.oc.api.network.SimpleComponent", modid = "OpenComputers")})
public class TileEntityMachineRadar extends TileEntityTickingBase implements IEnergyUser, IGUIProvider, SimpleComponent {
public List<Entity> detectedEntities = new ArrayList();
public List<int[]> nearbyMissiles = new ArrayList();
int pingTimer = 0;
int lastPower;
final static int maxTimer = 80;
public boolean scanMissiles = true;
public boolean scanPlayers = true;
public boolean smartMode = true;
public boolean redMode = true;
public boolean jammed = false;
public float prevRotation;
public float rotation;
public long power = 0;
public static final int maxPower = 100000;
@Override
public String getInventoryName() {
return "";
}
@Override
public void updateEntity() {
if(this.yCoord < WeaponConfig.radarAltitude) return;
if(!worldObj.isRemote) {
this.updateStandardConnections(worldObj, xCoord, yCoord, zCoord);
nearbyMissiles.clear();
if(power > 0) {
allocateMissiles();
power -= 500;
if(power < 0) power = 0;
}
if(this.lastPower != getRedPower()) worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, getBlockType());
sendMissileData();
lastPower = getRedPower();
if(worldObj.getBlock(xCoord, yCoord - 1, zCoord) != ModBlocks.muffler) {
pingTimer++;
if(power > 0 && pingTimer >= maxTimer) {
this.worldObj.playSoundEffect(this.xCoord, this.yCoord, this.zCoord, "hbm:block.sonarPing", 5.0F, 1.0F);
pingTimer = 0;
}
}
} else {
prevRotation = rotation;
if(power > 0) rotation += 5F;
if(rotation >= 360) {
rotation -= 360F;
prevRotation -= 360F;
}
}
}
public void handleButtonPacket(int value, int meta) {
switch(meta) {
case 0: this.scanMissiles = !this.scanMissiles; break;
case 1: this.scanPlayers = !this.scanPlayers; break;
case 2: this.smartMode = !this.smartMode; break;
case 3: this.redMode = !this.redMode; break;
}
}
private void allocateMissiles() {
nearbyMissiles.clear();
detectedEntities.clear();
jammed = false;
List<Entity> list = worldObj.getEntitiesWithinAABBExcludingEntity(null, AxisAlignedBB.getBoundingBox(xCoord + 0.5 - WeaponConfig.radarRange, 0, zCoord + 0.5 - WeaponConfig.radarRange, xCoord + 0.5 + WeaponConfig.radarRange, 5000, zCoord + 0.5 + WeaponConfig.radarRange));
for(Entity e : list) {
if(e.posY < yCoord + WeaponConfig.radarBuffer)
continue;
if(e instanceof EntityLivingBase && HbmLivingProps.getDigamma((EntityLivingBase) e) > 0.001) {
this.jammed = true;
nearbyMissiles.clear();
detectedEntities.clear();
return;
}
if(e instanceof EntityPlayer && this.scanPlayers) {
nearbyMissiles.add(new int[] { (int)e.posX, (int)e.posZ, RadarTargetType.PLAYER.ordinal(), (int)e.posY });
detectedEntities.add(e);
}
if(e instanceof IRadarDetectable && this.scanMissiles) {
nearbyMissiles.add(new int[] { (int)e.posX, (int)e.posZ, ((IRadarDetectable)e).getTargetType().ordinal(), (int)e.posY });
if(!this.smartMode || e.motionY <= 0)
detectedEntities.add(e);
}
}
}
public int getRedPower() {
if(!detectedEntities.isEmpty()) {
/// PROXIMITY ///
if(redMode) {
double maxRange = WeaponConfig.radarRange * Math.sqrt(2D);
int power = 0;
for(int i = 0; i < detectedEntities.size(); i++) {
Entity e = detectedEntities.get(i);
double dist = Math.sqrt(Math.pow(e.posX - xCoord, 2) + Math.pow(e.posZ - zCoord, 2));
int p = 15 - (int)Math.floor(dist / maxRange * 15);
if(p > power)
power = p;
}
return power;
/// TIER ///
} else {
int power = 0;
for(int i = 0; i < nearbyMissiles.size(); i++) {
if(nearbyMissiles.get(i)[2] + 1 > power) {
power = nearbyMissiles.get(i)[2] + 1;
}
}
return power;
}
}
return 0;
}
private void sendMissileData() {
NBTTagCompound data = new NBTTagCompound();
data.setLong("power", power);
data.setBoolean("scanMissiles", scanMissiles);
data.setBoolean("scanPlayers", scanPlayers);
data.setBoolean("smartMode", smartMode);
data.setBoolean("redMode", redMode);
data.setBoolean("jammed", jammed);
data.setInteger("count", this.nearbyMissiles.size());
for(int i = 0; i < this.nearbyMissiles.size(); i++) {
data.setInteger("x" + i, this.nearbyMissiles.get(i)[0]);
data.setInteger("z" + i, this.nearbyMissiles.get(i)[1]);
data.setInteger("type" + i, this.nearbyMissiles.get(i)[2]);
data.setInteger("y" + i, this.nearbyMissiles.get(i)[3]);
}
this.networkPack(data, 15);
}
public void networkUnpack(NBTTagCompound data) {
this.nearbyMissiles.clear();
this.power = data.getLong("power");
this.scanMissiles = data.getBoolean("scanMissiles");
this.scanPlayers = data.getBoolean("scanPlayers");
this.smartMode = data.getBoolean("smartMode");
this.redMode = data.getBoolean("redMode");
this.jammed = data.getBoolean("jammed");
int count = data.getInteger("count");
for(int i = 0; i < count; i++) {
int x = data.getInteger("x" + i);
int z = data.getInteger("z" + i);
int type = data.getInteger("type" + i);
int y = data.getInteger("y" + i);
this.nearbyMissiles.add(new int[] {x, z, type, y});
}
}
public long getPowerScaled(long i) {
return (power * i) / maxPower;
}
@Override
public void setPower(long i) {
power = i;
}
@Override
public long getPower() {
return power;
}
@Override
public long getMaxPower() {
return maxPower;
}
@Override
public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt);
this.power = nbt.getLong("power");
this.scanMissiles = nbt.getBoolean("scanMissiles");
this.scanPlayers = nbt.getBoolean("scanPlayers");
this.smartMode = nbt.getBoolean("smartMode");
this.redMode = nbt.getBoolean("redMode");
}
@Override
public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt);
nbt.setLong("power", power);
nbt.setBoolean("scanMissiles", scanMissiles);
nbt.setBoolean("scanPlayers", scanPlayers);
nbt.setBoolean("smartMode", smartMode);
nbt.setBoolean("redMode", redMode);
}
@Override
public AxisAlignedBB getRenderBoundingBox() {
return TileEntity.INFINITE_EXTENT_AABB;
}
@Override
@SideOnly(Side.CLIENT)
public double getMaxRenderDistanceSquared()
{
return 65536.0D;
}
// do some opencomputer stuff
@Override
public String getComponentName() {
return "ntm_radar";
}
@Callback(direct = true, limit = 8)
@Optional.Method(modid = "OpenComputers")
public Object[] getEnergyInfo(Context context, Arguments args) {
return new Object[] {getPower(), getMaxPower()};
}
@Callback(direct = true, limit = 8)
@Optional.Method(modid = "OpenComputers")
public Object[] isJammed(Context context, Arguments args) {
return new Object[] {jammed};
}
@Callback(direct = true, limit = 8)
@Optional.Method(modid = "OpenComputers")
public Object[] getEntities(Context context, Arguments args) { //fuck fuck fuck
if(!jammed) {
List<Object> list = new ArrayList();
list.add(detectedEntities.size()); // small header of how many entities in the list
for (Entity e : detectedEntities) {
list.add(e.posX); // positions
list.add(e.posY);
list.add(e.posZ);
list.add(e.motionX);
list.add(e.motionY);
list.add(e.motionZ);
list.add(e.rotationYaw); // just do rotation so you can calculate DOT
list.add(Math.sqrt(Math.pow(e.posX - xCoord, 2) + Math.pow(e.posZ - zCoord, 2))); // distance
boolean player = e instanceof EntityPlayer;
list.add(player); // isPlayer boolean
if(!player) // missile tier
list.add(((IRadarDetectable) e).getTargetType().ordinal());
else // player name (hopefully)
list.add(((EntityPlayer) e).getDisplayName());
}
return new Object[] {list}; // long-ass list (like 9 entries per entity)
} else {
return new Object[] {"Radar jammed!"};
}
}
@Override
public Container provideContainer(int ID, EntityPlayer player, World world, int x, int y, int z) {
return new ContainerMachineRadar(player.inventory, this);
}
@Override
@SideOnly(Side.CLIENT)
public GuiScreen provideGUI(int ID, EntityPlayer player, World world, int x, int y, int z) {
return new GUIMachineRadar(player.inventory, this);
}
}

View File

@ -61,6 +61,7 @@ public class TileEntityPWRController extends TileEntityMachineBase implements IG
public int channelCount;
public int sourceCount;
public int unloadDelay = 0;
public boolean assembled;
private AudioWrapper audio;
@ -160,6 +161,20 @@ public class TileEntityPWRController extends TileEntityMachineBase implements IG
this.tanks[0].setType(2, slots);
setupTanks();
if(unloadDelay > 0) unloadDelay--;
int chunkX = xCoord >> 4;
int chunkZ = zCoord >> 4;
//since fluid sources are often not within 1 chunk, we just do 2 chunks distance and call it a day
if(!worldObj.getChunkProvider().chunkExists(chunkX, chunkZ) ||
!worldObj.getChunkProvider().chunkExists(chunkX + 2, chunkZ + 2) ||
!worldObj.getChunkProvider().chunkExists(chunkX + 2, chunkZ - 2) ||
!worldObj.getChunkProvider().chunkExists(chunkX - 2, chunkZ + 2) ||
!worldObj.getChunkProvider().chunkExists(chunkX - 2, chunkZ - 2)) {
this.unloadDelay = 40;
}
if(this.assembled) {
for(BlockPos pos : ports) {
for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
@ -170,76 +185,80 @@ public class TileEntityPWRController extends TileEntityMachineBase implements IG
}
}
if((typeLoaded == -1 || amountLoaded <= 0) && slots[0] != null && slots[0].getItem() == ModItems.pwr_fuel) {
typeLoaded = slots[0].getItemDamage();
amountLoaded++;
this.decrStackSize(0, 1);
this.markChanged();
} else if(slots[0] != null && slots[0].getItem() == ModItems.pwr_fuel && slots[0].getItemDamage() == typeLoaded && amountLoaded < rodCount){
amountLoaded++;
this.decrStackSize(0, 1);
this.markChanged();
}
if(this.rodTarget > this.rodLevel) this.rodLevel++;
if(this.rodTarget < this.rodLevel) this.rodLevel--;
int newFlux = this.sourceCount * 20;
if(typeLoaded != -1 && amountLoaded > 0) {
//only perform fission if the area has been loaded for 40 ticks or more
if(this.unloadDelay <= 0) {
EnumPWRFuel fuel = EnumUtil.grabEnumSafely(EnumPWRFuel.class, typeLoaded);
double usedRods = getTotalProcessMultiplier();
double fluxPerRod = this.flux / this.rodCount;
double outputPerRod = fuel.function.effonix(fluxPerRod);
double totalOutput = outputPerRod * amountLoaded * usedRods;
double totalHeatOutput = totalOutput * fuel.heatEmission;
this.coreHeat += totalHeatOutput;
newFlux += totalOutput;
this.processTime = (int) fuel.yield;
this.progress += totalOutput;
if(this.progress >= this.processTime) {
this.progress -= this.processTime;
if(slots[1] == null) {
slots[1] = new ItemStack(ModItems.pwr_fuel_hot, 1, typeLoaded);
} else if(slots[1].getItem() == ModItems.pwr_fuel_hot && slots[1].getItemDamage() == typeLoaded && slots[1].stackSize < slots[1].getMaxStackSize()) {
slots[1].stackSize++;
}
this.amountLoaded--;
if((typeLoaded == -1 || amountLoaded <= 0) && slots[0] != null && slots[0].getItem() == ModItems.pwr_fuel) {
typeLoaded = slots[0].getItemDamage();
amountLoaded++;
this.decrStackSize(0, 1);
this.markChanged();
} else if(slots[0] != null && slots[0].getItem() == ModItems.pwr_fuel && slots[0].getItemDamage() == typeLoaded && amountLoaded < rodCount){
amountLoaded++;
this.decrStackSize(0, 1);
this.markChanged();
}
}
if(this.amountLoaded <= 0) {
this.typeLoaded = -1;
}
if(amountLoaded > rodCount) amountLoaded = rodCount;
/* CORE COOLING */
double coreCoolingApproachNum = getXOverE((double) this.heatexCount * 5 / (double) this.rodCount, 2) / 2D;
int averageCoreHeat = (this.coreHeat + this.hullHeat) / 2;
this.coreHeat -= (coreHeat - averageCoreHeat) * coreCoolingApproachNum;
this.hullHeat -= (hullHeat - averageCoreHeat) * coreCoolingApproachNum;
updateCoolant();
this.coreHeat *= 0.999D;
this.hullHeat *= 0.999D;
this.flux = newFlux;
if(tanks[0].getTankType().hasTrait(FT_PWRModerator.class) && tanks[0].getFill() > 0) {
this.flux *= tanks[0].getTankType().getTrait(FT_PWRModerator.class).getMultiplier();
}
if(this.coreHeat > this.coreHeatCapacity) {
meltDown();
if(this.rodTarget > this.rodLevel) this.rodLevel++;
if(this.rodTarget < this.rodLevel) this.rodLevel--;
int newFlux = this.sourceCount * 20;
if(typeLoaded != -1 && amountLoaded > 0) {
EnumPWRFuel fuel = EnumUtil.grabEnumSafely(EnumPWRFuel.class, typeLoaded);
double usedRods = getTotalProcessMultiplier();
double fluxPerRod = this.flux / this.rodCount;
double outputPerRod = fuel.function.effonix(fluxPerRod);
double totalOutput = outputPerRod * amountLoaded * usedRods;
double totalHeatOutput = totalOutput * fuel.heatEmission;
this.coreHeat += totalHeatOutput;
newFlux += totalOutput;
this.processTime = (int) fuel.yield;
this.progress += totalOutput;
if(this.progress >= this.processTime) {
this.progress -= this.processTime;
if(slots[1] == null) {
slots[1] = new ItemStack(ModItems.pwr_fuel_hot, 1, typeLoaded);
} else if(slots[1].getItem() == ModItems.pwr_fuel_hot && slots[1].getItemDamage() == typeLoaded && slots[1].stackSize < slots[1].getMaxStackSize()) {
slots[1].stackSize++;
}
this.amountLoaded--;
this.markChanged();
}
}
if(this.amountLoaded <= 0) {
this.typeLoaded = -1;
}
if(amountLoaded > rodCount) amountLoaded = rodCount;
/* CORE COOLING */
double coreCoolingApproachNum = getXOverE((double) this.heatexCount * 5 / (double) this.rodCount, 2) / 2D;
int averageCoreHeat = (this.coreHeat + this.hullHeat) / 2;
this.coreHeat -= (coreHeat - averageCoreHeat) * coreCoolingApproachNum;
this.hullHeat -= (hullHeat - averageCoreHeat) * coreCoolingApproachNum;
updateCoolant();
this.coreHeat *= 0.999D;
this.hullHeat *= 0.999D;
this.flux = newFlux;
if(tanks[0].getTankType().hasTrait(FT_PWRModerator.class) && tanks[0].getFill() > 0) {
this.flux *= tanks[0].getTankType().getTrait(FT_PWRModerator.class).getMultiplier();
}
if(this.coreHeat > this.coreHeatCapacity) {
meltDown();
}
}
}