use of icbm.classic.lib.transform.vector.Pos in project ICBM-Classic by BuiltBrokenModding.
the class TileRadarStation method update.
@Override
public void update() {
super.update();
if (isServer()) {
// Update client every 1 seconds
if (this.ticks % 20 == 0) {
sendDescPacket();
}
// If we have energy
if (checkExtract()) {
// Do a radar scan
if (// TODO make config to control scan rate to reduce lag
ticks % 3 == 0) {
// TODO consider rewriting to not cache targets
this.doScan();
}
// Check for incoming and launch anti-missiles if
if (// TODO track if a anti-missile is already in air to hit target
this.ticks % 20 == 0 && this.incomingMissiles.size() > 0) {
RadioRegistry.popMessage(world, this, getFrequency(), "fireAntiMissile", this.incomingMissiles.get(0));
}
} else {
if (detectedEntities.size() > 0) {
world.setBlockState(getPos(), getBlockState().withProperty(BlockRadarStation.REDSTONE_PROPERTY, false));
}
incomingMissiles.clear();
detectedEntities.clear();
}
// Update redstone state
final boolean shouldBeOn = checkExtract() && detectedEntities.size() > 0;
if (world.getBlockState(getPos()).getValue(BlockRadarStation.REDSTONE_PROPERTY) != shouldBeOn) {
world.setBlockState(getPos(), getBlockState().withProperty(BlockRadarStation.REDSTONE_PROPERTY, shouldBeOn));
for (EnumFacing facing : EnumFacing.HORIZONTALS) {
BlockPos pos = getPos().add(facing.getXOffset(), facing.getYOffset(), facing.getZOffset());
for (EnumFacing enumfacing : EnumFacing.values()) {
world.notifyNeighborsOfStateChange(pos.offset(enumfacing), getBlockType(), false);
}
}
}
} else {
if (// TODO use a boolean on client for on/off state
checkExtract()) {
if (updateDrawList) {
guiDrawPoints.clear();
for (int i = 0; i < detectedEntities.size(); i++) {
Entity entity = detectedEntities.get(i);
if (entity != null) {
guiDrawPoints.add(new Pos(entity.posX, entity.posZ, types[i].ordinal()));
}
}
}
// Animation
this.rotation += 0.08f;
if (this.rotation > 360) {
this.rotation = 0;
}
} else {
guiDrawPoints.clear();
}
}
}
use of icbm.classic.lib.transform.vector.Pos in project ICBM-Classic by BuiltBrokenModding.
the class TileRadarStation method doScan.
private // TODO document and thread
void doScan() {
this.incomingMissiles.clear();
this.detectedEntities.clear();
List<Entity> entities = RadarRegistry.getAllLivingObjectsWithin(world, xi() + 1.5, yi() + 0.5, zi() + 0.5, Math.min(alarmRange, MAX_DETECTION_RANGE));
for (Entity entity : entities) {
if (// TODO && ((EntityMissile) entity).getExplosiveType() != Explosives.MISSILE_ANTI.handler)
ICBMClassicHelpers.isMissile(entity)) {
final IMissile newMissile = ICBMClassicHelpers.getMissile(entity);
if (newMissile != null && newMissile.getTicksInAir() > 1) {
if (!this.detectedEntities.contains(entity)) {
this.detectedEntities.add(entity);
}
if (this.isMissileGoingToHit((EntityMissile) entity)) {
if (this.incomingMissiles.size() > 0) {
/**
* Sort in order of distance
*/
double dist = new Pos((TileEntity) this).distance(newMissile);
for (int i = 0; i < this.incomingMissiles.size(); i++) {
IMissile missile = this.incomingMissiles.get(i);
if (dist < new Pos((TileEntity) this).distance(missile)) {
this.incomingMissiles.add(i, missile);
break;
} else if (i == this.incomingMissiles.size() - 1) {
this.incomingMissiles.add(missile);
break;
}
}
} else {
this.incomingMissiles.add(newMissile);
}
}
}
}
}
}
use of icbm.classic.lib.transform.vector.Pos in project ICBM-Classic by BuiltBrokenModding.
the class BlockLaunchScreen method onBlockActivated.
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
if (!world.isRemote) {
TileEntity tileEntity = world.getTileEntity(pos);
if (tileEntity instanceof TileLauncherScreen) {
TileLauncherScreen screen = (TileLauncherScreen) tileEntity;
ItemStack stack = player.getHeldItem(hand);
if (stack.getItem() == Items.REDSTONE) {
if ((screen._tier == EnumTier.ONE && !ConfigLauncher.LAUNCHER_REDSTONE_TIER1) || (screen._tier == EnumTier.TWO && !ConfigLauncher.LAUNCHER_REDSTONE_TIER2) || (screen._tier == EnumTier.THREE && !ConfigLauncher.LAUNCHER_REDSTONE_TIER3)) {
return false;
}
if (// canLaunch is called in launch and launch returns false if cannot launch
!screen.launch()) {
player.sendMessage(new TextComponentString(LanguageUtility.getLocal("chat.launcher.failedToFire")));
String translation = LanguageUtility.getLocal("chat.launcher.status");
translation = translation.replace("%s", screen.getStatus());
player.sendMessage(new TextComponentString(translation));
}
} else if (stack.getItem() instanceof ItemRemoteDetonator) {
((ItemRemoteDetonator) stack.getItem()).setBroadCastHz(stack, screen.getFrequency());
player.sendMessage(new TextComponentString(LanguageUtility.getLocal("chat.launcher.toolFrequencySet").replace("%s", "" + screen.getFrequency())));
} else if (stack.getItem() instanceof ItemLaserDetonator) {
((ItemLaserDetonator) stack.getItem()).setBroadCastHz(stack, screen.getFrequency());
player.sendMessage(new TextComponentString(LanguageUtility.getLocal("chat.launcher.toolFrequencySet").replace("%s", "" + screen.getFrequency())));
} else if (stack.getItem() instanceof IWorldPosItem) {
IWorldPosition location = ((IWorldPosItem) stack.getItem()).getLocation(stack);
if (location != null) {
if (location.world() == world) {
screen.setTarget(new Pos(location.x(), location.y(), location.z()));
player.sendMessage(new TextComponentString(LanguageUtility.getLocal("chat.launcher.toolTargetSet")));
} else {
player.sendMessage(new TextComponentString(LanguageUtility.getLocal("chat.launcher.toolWorldNotMatch")));
}
} else {
player.sendMessage(new TextComponentString(LanguageUtility.getLocal("chat.launcher.noTargetInTool")));
}
} else if (screen.launcherBase == null || !screen.launcherBase.tryInsertMissile(player, hand, player.getHeldItem(hand))) {
player.openGui(ICBMClassic.INSTANCE, 0, world, pos.getX(), pos.getY(), pos.getZ());
}
}
}
return true;
}
use of icbm.classic.lib.transform.vector.Pos in project ICBM-Classic by BuiltBrokenModding.
the class GuiLauncherScreen method keyTyped.
/**
* Call this method from you GuiScreen to process the keys into textbox.
*/
@Override
public void keyTyped(char par1, int par2) throws IOException {
super.keyTyped(par1, par2);
this.target_xCoord_field.textboxKeyTyped(par1, par2);
this.target_zCoord_field.textboxKeyTyped(par1, par2);
if (tileEntity.getTier().ordinal() >= 1) {
this.target_yCoord_field.textboxKeyTyped(par1, par2);
this.lock_height_field.textboxKeyTyped(par1, par2);
if (tileEntity.getTier().ordinal() > 1) {
this.target_freq_field.textboxKeyTyped(par1, par2);
}
}
try {
Pos newTarget = new Pos(parseInt(this.target_xCoord_field.getText()), max(parseInt(this.target_yCoord_field.getText()), 0), parseInt(this.target_zCoord_field.getText()));
this.tileEntity.setTarget(newTarget);
ICBMClassic.packetHandler.sendToServer(new PacketTile("target_C>S", TileLauncherScreen.SET_TARGET_PACKET_ID, this.tileEntity).addData(this.tileEntity.getTarget().xi(), this.tileEntity.getTarget().yi(), this.tileEntity.getTarget().zi()));
} catch (NumberFormatException e) {
}
try {
short newFrequency = (short) Math.max(Short.parseShort(this.target_freq_field.getText()), 0);
this.tileEntity.setFrequency(newFrequency);
ICBMClassic.packetHandler.sendToServer(new PacketTile("frequency_C>S", TileLauncherScreen.SET_FREQUENCY_PACKET_ID, this.tileEntity).addData(this.tileEntity.getFrequency()));
} catch (NumberFormatException e) {
}
try {
short newHeight = (short) Math.max(Math.min(Short.parseShort(this.lock_height_field.getText()), Short.MAX_VALUE), 3);
this.tileEntity.lockHeight = newHeight;
ICBMClassic.packetHandler.sendToServer(new PacketTile("lock_height_C>S", TileLauncherScreen.LOCK_HEIGHT_PACKET_ID, this.tileEntity).addData(this.tileEntity.lockHeight));
} catch (NumberFormatException e) {
}
}
use of icbm.classic.lib.transform.vector.Pos in project ICBM-Classic by BuiltBrokenModding.
the class BlockCruiseLauncher method onBlockActivated.
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
if (!world.isRemote) {
TileEntity tileEntity = world.getTileEntity(pos);
if (tileEntity instanceof TileCruiseLauncher) {
TileCruiseLauncher launcher = (TileCruiseLauncher) tileEntity;
ItemStack stack = player.getHeldItem(hand);
if (stack.getItem() == Items.REDSTONE) {
if (// canLaunch is called in launch and launch returns false if cannot launch
!launcher.launch()) {
player.sendMessage(new TextComponentString(LanguageUtility.getLocal("chat.launcher.failedToFire")));
String translation = LanguageUtility.getLocal("chat.launcher.status");
translation = translation.replace("%s", launcher.getStatus());
player.sendMessage(new TextComponentString(translation));
}
} else if (stack.getItem() instanceof ItemRemoteDetonator) {
((ItemRemoteDetonator) stack.getItem()).setBroadCastHz(stack, launcher.getFrequency());
player.sendMessage(new TextComponentString(LanguageUtility.getLocal("chat.launcher.toolFrequencySet").replace("%s", "" + launcher.getFrequency())));
} else if (stack.getItem() instanceof ItemLaserDetonator) {
((ItemLaserDetonator) stack.getItem()).setBroadCastHz(stack, launcher.getFrequency());
player.sendMessage(new TextComponentString(LanguageUtility.getLocal("chat.launcher.toolFrequencySet").replace("%s", "" + launcher.getFrequency())));
} else if (stack.getItem() instanceof IWorldPosItem) {
IWorldPosition location = ((IWorldPosItem) stack.getItem()).getLocation(stack);
if (location != null) {
if (location.world() == world) {
launcher.setTarget(new Pos(location.x(), location.y(), location.z()));
player.sendMessage(new TextComponentString(LanguageUtility.getLocal("chat.launcher.toolTargetSet")));
} else {
player.sendMessage(new TextComponentString(LanguageUtility.getLocal("chat.launcher.toolWorldNotMatch")));
}
} else {
player.sendMessage(new TextComponentString(LanguageUtility.getLocal("chat.launcher.noTargetInTool")));
}
} else {
player.openGui(ICBMClassic.INSTANCE, 0, world, pos.getX(), pos.getY(), pos.getZ());
}
}
}
return true;
}
Aggregations