use of micdoodle8.mods.galacticraft.core.tile.TileEntityTelemetry in project Galacticraft by micdoodle8.
the class EntitySpaceshipBase method onUpdate.
@Override
public void onUpdate() {
this.ticks++;
super.onUpdate();
if (this.addToTelemetry) {
this.addToTelemetry = false;
for (BlockVec3Dim vec : new ArrayList<BlockVec3Dim>(this.telemetryList)) {
TileEntity t1 = vec.getTileEntityNoLoad();
if (t1 instanceof TileEntityTelemetry && !t1.isInvalid()) {
if (((TileEntityTelemetry) t1).linkedEntity == this)
((TileEntityTelemetry) t1).addTrackedEntity(this);
}
}
}
if (this.riddenByEntity != null) {
this.riddenByEntity.fallDistance = 0.0F;
}
if (this.posY > (this.worldObj.provider instanceof IExitHeight ? ((IExitHeight) this.worldObj.provider).getYCoordinateToTeleport() : 1200) && this.launchPhase != EnumLaunchPhase.LANDING.ordinal()) {
this.onReachAtmosphere();
// if (this.worldObj.isRemote)
// this.posY = 1 + (this.worldObj.provider instanceof IExitHeight ? ((IExitHeight) this.worldObj.provider).getYCoordinateToTeleport() : 1200);
}
if (this.rollAmplitude > 0) {
this.rollAmplitude--;
}
if (this.shipDamage > 0) {
this.shipDamage--;
}
if (!this.worldObj.isRemote) {
if (this.posY < 0.0D) {
this.setDead();
} else if (this.posY > (this.worldObj.provider instanceof IExitHeight ? ((IExitHeight) this.worldObj.provider).getYCoordinateToTeleport() : 1200) + (this.launchPhase == EnumLaunchPhase.LANDING.ordinal() ? 355 : 100)) {
if (this.riddenByEntity instanceof EntityPlayerMP) {
GCPlayerStats stats = GCPlayerStats.get(this.riddenByEntity);
if (stats.isUsingPlanetSelectionGui()) {
this.setDead();
}
} else
this.setDead();
}
if (this.timeSinceLaunch > 50 && this.onGround) {
this.failRocket();
}
}
if (this.launchPhase == EnumLaunchPhase.UNIGNITED.ordinal()) {
this.timeUntilLaunch = this.getPreLaunchWait();
}
if (this.launchPhase >= EnumLaunchPhase.LAUNCHED.ordinal()) {
this.timeSinceLaunch++;
} else {
this.timeSinceLaunch = 0;
}
if (this.timeUntilLaunch > 0 && this.launchPhase == EnumLaunchPhase.IGNITED.ordinal()) {
this.timeUntilLaunch--;
}
AxisAlignedBB box = null;
box = this.getEntityBoundingBox().expand(0.2D, 0.2D, 0.2D);
final List<?> var15 = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, box);
if (var15 != null && !var15.isEmpty()) {
for (int var52 = 0; var52 < var15.size(); ++var52) {
final Entity var17 = (Entity) var15.get(var52);
if (var17 != this.riddenByEntity) {
var17.applyEntityCollision(this);
}
}
}
if (this.timeUntilLaunch == 0 && this.launchPhase == EnumLaunchPhase.IGNITED.ordinal()) {
this.setLaunchPhase(EnumLaunchPhase.LAUNCHED);
this.onLaunch();
}
if (this.rotationPitch > 90) {
this.rotationPitch = 90;
}
if (this.rotationPitch < -90) {
this.rotationPitch = -90;
}
this.motionX = -(50 * Math.cos(this.rotationYaw / Constants.RADIANS_TO_DEGREES_D) * Math.sin(this.rotationPitch * 0.01 / Constants.RADIANS_TO_DEGREES_D));
this.motionZ = -(50 * Math.sin(this.rotationYaw / Constants.RADIANS_TO_DEGREES_D) * Math.sin(this.rotationPitch * 0.01 / Constants.RADIANS_TO_DEGREES_D));
if (this.launchPhase < EnumLaunchPhase.LAUNCHED.ordinal()) {
this.motionX = this.motionY = this.motionZ = 0.0F;
}
if (this.worldObj.isRemote) {
this.setPosition(this.posX, this.posY, this.posZ);
if (this.shouldMoveClientSide()) {
this.moveEntity(this.motionX, this.motionY, this.motionZ);
}
} else {
this.moveEntity(this.motionX, this.motionY, this.motionZ);
}
this.setRotation(this.rotationYaw, this.rotationPitch);
if (this.worldObj.isRemote) {
this.setPosition(this.posX, this.posY, this.posZ);
}
this.prevPosX = this.posX;
this.prevPosY = this.posY;
this.prevPosZ = this.posZ;
if (!this.worldObj.isRemote && this.ticks % 3 == 0) {
GalacticraftCore.packetPipeline.sendToDimension(new PacketDynamic(this), this.worldObj.provider.getDimensionId());
// PacketDispatcher.sendPacketToAllInDimension(GCCorePacketManager.getPacket(GalacticraftCore.CHANNELENTITIES,
// this, this.getNetworkedData(new ArrayList())),
// this.worldObj.provider.getDimensionId());
}
}
use of micdoodle8.mods.galacticraft.core.tile.TileEntityTelemetry in project Galacticraft by micdoodle8.
the class BlockTelemetry method onMachineActivated.
@Override
public boolean onMachineActivated(World world, BlockPos pos, IBlockState state, EntityPlayer entityPlayer, EnumFacing side, float hitX, float hitY, float hitZ) {
if (!world.isRemote) {
TileEntity tile = world.getTileEntity(pos);
if (tile instanceof TileEntityTelemetry) {
ItemStack held = entityPlayer.inventory.getCurrentItem();
// Look for Frequency Module
if (held != null && held.getItem() == GCItems.basicItem && held.getItemDamage() == 19) {
NBTTagCompound fmData = held.getTagCompound();
if (fmData != null && fmData.hasKey("linkedUUIDMost") && fmData.hasKey("linkedUUIDLeast")) {
UUID uuid = new UUID(fmData.getLong("linkedUUIDMost"), fmData.getLong("linkedUUIDLeast"));
((TileEntityTelemetry) tile).addTrackedEntity(uuid);
entityPlayer.addChatMessage(new ChatComponentText(GCCoreUtil.translate("gui.telemetry_succeed.message")));
} else {
entityPlayer.addChatMessage(new ChatComponentText(GCCoreUtil.translate("gui.telemetry_fail.message")));
if (fmData == null) {
fmData = new NBTTagCompound();
held.setTagCompound(fmData);
}
}
fmData.setInteger("teCoordX", pos.getX());
fmData.setInteger("teCoordY", pos.getY());
fmData.setInteger("teCoordZ", pos.getZ());
fmData.setInteger("teDim", GCCoreUtil.getDimensionID(world));
return true;
}
ItemStack wearing = GCPlayerStats.get(entityPlayer).getFrequencyModuleInSlot();
if (wearing != null) {
if (wearing.hasTagCompound() && wearing.getTagCompound().hasKey("teDim")) {
return false;
}
entityPlayer.addChatMessage(new ChatComponentText(GCCoreUtil.translate("gui.telemetry_fail_wearing_it.message")));
} else {
entityPlayer.addChatMessage(new ChatComponentText(GCCoreUtil.translate("gui.telemetry_fail_no_frequency_module.message")));
}
}
}
return false;
}
use of micdoodle8.mods.galacticraft.core.tile.TileEntityTelemetry in project Galacticraft by micdoodle8.
the class GameScreenText method render.
@Override
@SideOnly(Side.CLIENT)
public void render(int type, float ticks, float sizeX, float sizeY, IScreenManager scr) {
DrawGameScreen screen = (DrawGameScreen) scr;
frameBx = sizeX - frameA;
frameBy = sizeY - frameA;
drawBlackBackground(0.0F);
planeEquation(frameA, frameA, 0, frameA, frameBy, 0, frameA, frameBy, 1);
GL11.glClipPlane(GL11.GL_CLIP_PLANE0, planes);
GL11.glEnable(GL11.GL_CLIP_PLANE0);
planeEquation(frameBx, frameBy, 0, frameBx, frameA, 0, frameBx, frameA, 1);
GL11.glClipPlane(GL11.GL_CLIP_PLANE1, planes);
GL11.glEnable(GL11.GL_CLIP_PLANE1);
planeEquation(frameA, frameBy, 0, frameBx, frameBy, 0, frameBx, frameBy, 1);
GL11.glClipPlane(GL11.GL_CLIP_PLANE2, planes);
GL11.glEnable(GL11.GL_CLIP_PLANE2);
planeEquation(frameBx, frameA, 0, frameA, frameA, 0, frameA, frameA, 1);
GL11.glClipPlane(GL11.GL_CLIP_PLANE3, planes);
GL11.glEnable(GL11.GL_CLIP_PLANE3);
yPos = 0;
TileEntityTelemetry telemeter = TileEntityTelemetry.getNearest(screen.driver);
// Make the text to draw. To look good it's important the width and height
// of the whole text box are correctly set here.
String strName = "";
String[] str = { GCCoreUtil.translate("gui.display.nolink"), "", "", "", "" };
Render renderEntity = null;
Entity entity = null;
float Xmargin = 0;
if (telemeter != null && telemeter.clientData.length >= 3) {
if (telemeter.clientClass != null) {
if (telemeter.clientClass == screen.telemetryLastClass && (telemeter.clientClass != EntityPlayerMP.class || telemeter.clientName.equals(screen.telemetryLastName))) {
// Used cached data from last time if possible
entity = screen.telemetryLastEntity;
renderEntity = screen.telemetryLastRender;
strName = screen.telemetryLastName;
} else {
// Create an entity to render, based on class, and get its name
entity = null;
if (telemeter.clientClass == EntityPlayerMP.class) {
strName = telemeter.clientName;
entity = new EntityOtherPlayerMP(screen.driver.getWorld(), telemeter.clientGameProfile);
renderEntity = (Render) FMLClientHandler.instance().getClient().getRenderManager().getEntityRenderObject(entity);
} else {
try {
entity = (Entity) telemeter.clientClass.getConstructor(World.class).newInstance(screen.driver.getWorld());
} catch (Exception ex) {
}
if (entity != null) {
strName = entity.getName();
}
renderEntity = (Render) FMLClientHandler.instance().getClient().getRenderManager().entityRenderMap.get(telemeter.clientClass);
}
}
// Setup special visual types from data sent by Telemetry
if (entity instanceof EntityHorse) {
((EntityHorse) entity).setHorseType(telemeter.clientData[3]);
((EntityHorse) entity).setHorseVariant(telemeter.clientData[4]);
}
if (entity instanceof EntityVillager) {
((EntityVillager) entity).setProfession(telemeter.clientData[3]);
((EntityVillager) entity).setGrowingAge(telemeter.clientData[4]);
} else if (entity instanceof EntityWolf) {
((EntityWolf) entity).setCollarColor(EnumDyeColor.byDyeDamage(telemeter.clientData[3]));
((EntityWolf) entity).setBegging(telemeter.clientData[4] == 1);
} else if (entity instanceof EntitySheep) {
((EntitySheep) entity).setFleeceColor(EnumDyeColor.byDyeDamage(telemeter.clientData[3]));
((EntitySheep) entity).setSheared(telemeter.clientData[4] == 1);
} else if (entity instanceof EntityOcelot) {
((EntityOcelot) entity).setTameSkin(telemeter.clientData[3]);
} else if (entity instanceof EntitySkeleton) {
((EntitySkeleton) entity).setSkeletonType(telemeter.clientData[3]);
} else if (entity instanceof EntityZombie) {
((EntityZombie) entity).setVillager(telemeter.clientData[3] == 1);
((EntityZombie) entity).setChild(telemeter.clientData[4] == 1);
}
}
if (entity instanceof ITelemetry) {
((ITelemetry) entity).receiveData(telemeter.clientData, str);
} else if (entity instanceof EntityLivingBase) {
// Living entity:
// data0 = time to show red damage
// data1 = health in half-hearts
// data2 = pulse
// data3 = hunger (for player); horsetype (for horse)
// data4 = oxygen (for player); horsevariant (for horse)
str[0] = telemeter.clientData[0] > 0 ? GCCoreUtil.translate("gui.player.ouch") : "";
if (telemeter.clientData[1] >= 0) {
str[1] = GCCoreUtil.translate("gui.player.health") + ": " + telemeter.clientData[1] + "%";
} else {
str[1] = "";
}
str[2] = "" + telemeter.clientData[2] + " " + GCCoreUtil.translate("gui.player.bpm");
if (telemeter.clientData[3] > -1) {
str[3] = GCCoreUtil.translate("gui.player.food") + ": " + telemeter.clientData[3] + "%";
}
if (telemeter.clientData[4] > -1) {
int oxygen = telemeter.clientData[4];
oxygen = (oxygen % 4096) + (oxygen / 4096);
if (oxygen == 180 || oxygen == 90) {
str[4] = GCCoreUtil.translate("gui.oxygen_storage.desc.1") + ": OK";
} else {
str[4] = GCCoreUtil.translate("gui.oxygen_storage.desc.1") + ": " + this.makeOxygenString(oxygen) + GCCoreUtil.translate("gui.seconds");
}
}
} else // TODO can add more here, e.g. position data?
if (telemeter.clientData[2] >= 0) {
str[2] = makeSpeedString(telemeter.clientData[2]);
}
} else {
// Default - draw a simple time display just to show the Display Screen is working
World w1 = screen.driver.getWorld();
int time1 = w1 != null ? (int) ((w1.getWorldTime() + 6000L) % 24000L) : 0;
str[2] = makeTimeString(time1 * 360);
}
int textWidthPixels = 155;
// 1 lines
int textHeightPixels = 60;
if (str[3].isEmpty()) {
textHeightPixels -= 10;
}
if (str[4].isEmpty()) {
textHeightPixels -= 10;
}
// First pass - approximate border size
float borders = frameA * 2 + 0.05F * Math.min(sizeX, sizeY);
float scaleXTest = (sizeX - borders) / textWidthPixels;
float scaleYTest = (sizeY - borders) / textHeightPixels;
float scale = sizeX;
if (scaleYTest < scaleXTest) {
scale = sizeY;
}
// Second pass - the border size may be more accurate now
borders = frameA * 2 + 0.05F * scale;
scaleXTest = (sizeX - borders) / textWidthPixels;
scaleYTest = (sizeY - borders) / textHeightPixels;
scale = sizeX;
float scaleText = scaleXTest;
if (scaleYTest < scaleXTest) {
scale = sizeY;
scaleText = scaleYTest;
}
// Centre the text in the display
float border = frameA + 0.025F * scale;
if (entity != null && renderEntity != null) {
Xmargin = (sizeX - borders) / 2;
}
float Xoffset = (sizeX - borders - textWidthPixels * scaleText) / 2 + Xmargin;
float Yoffset = (sizeY - borders - textHeightPixels * scaleText) / 2 + scaleText;
GL11.glTranslatef(border + Xoffset, border + Yoffset, 0.0F);
GL11.glScalef(scaleText, scaleText, 1.0F);
// Actually draw the text
int whiteColour = ColorUtil.to32BitColor(255, 240, 216, 255);
drawText(strName, whiteColour);
drawText(str[0], whiteColour);
drawText(str[1], whiteColour);
drawText(str[2], whiteColour);
drawText(str[3], whiteColour);
drawText(str[4], whiteColour);
// If there is an entity to render, draw it on the left of the text
if (renderEntity != null && entity != null) {
GL11.glTranslatef(-Xmargin / 2 / scaleText, textHeightPixels / 2 + (-Yoffset + (sizeY - borders) / 2) / scaleText, -0.0005F);
float scalefactor = 38F / (float) Math.pow(Math.max(entity.height, entity.width), 0.65);
GL11.glScalef(scalefactor, scalefactor, 0.0015F);
GL11.glRotatef(180F, 0, 0, 1);
GL11.glRotatef(180F, 0, 1, 0);
if (entity instanceof ITelemetry) {
((ITelemetry) entity).adjustDisplay(telemeter.clientData);
}
RenderPlayerGC.flagThermalOverride = true;
if (entity instanceof EntityLivingBase && renderEntity instanceof RendererLivingEntity && renderModelMethod != null) {
this.renderLiving((EntityLivingBase) entity, (RendererLivingEntity) renderEntity, ticks % 1F);
} else {
renderEntity.doRender(entity, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F);
}
RenderPlayerGC.flagThermalOverride = false;
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
OpenGlHelper.setActiveTexture(OpenGlHelper.lightmapTexUnit);
GL11.glDisable(GL11.GL_TEXTURE_2D);
OpenGlHelper.setActiveTexture(OpenGlHelper.defaultTexUnit);
}
// TODO Cross-dimensional tracking (i.e. old entity setDead, new entity created)
// TODO Deal with text off screen (including where localizations longer than English)
screen.telemetryLastClass = (telemeter == null) ? null : telemeter.clientClass;
screen.telemetryLastEntity = entity;
screen.telemetryLastRender = renderEntity;
screen.telemetryLastName = strName;
GL11.glDisable(GL11.GL_CLIP_PLANE3);
GL11.glDisable(GL11.GL_CLIP_PLANE2);
GL11.glDisable(GL11.GL_CLIP_PLANE1);
GL11.glDisable(GL11.GL_CLIP_PLANE0);
}
use of micdoodle8.mods.galacticraft.core.tile.TileEntityTelemetry in project Galacticraft by micdoodle8.
the class WorldUtil method teleportEntity.
private static Entity teleportEntity(World worldNew, Entity entity, int dimID, ITeleportType type, boolean transferInv, EntityAutoRocket ridingRocket) {
Entity otherRiddenEntity = null;
if (entity.ridingEntity != null) {
if (entity.ridingEntity instanceof EntitySpaceshipBase) {
entity.mountEntity(entity.ridingEntity);
} else if (entity.ridingEntity instanceof EntityCelestialFake) {
entity.ridingEntity.setDead();
entity.mountEntity(null);
} else {
otherRiddenEntity = entity.ridingEntity;
entity.mountEntity(null);
}
}
boolean dimChange = entity.worldObj != worldNew;
// Make sure the entity is added to the correct chunk in the OLD world so that it will be properly removed later if it needs to be unloaded from that world
entity.worldObj.updateEntityWithOptionalForce(entity, false);
EntityPlayerMP player = null;
Vector3 spawnPos = null;
int oldDimID = GCCoreUtil.getDimensionID(entity.worldObj);
if (ridingRocket != null) {
ArrayList<TileEntityTelemetry> tList = ridingRocket.getTelemetry();
NBTTagCompound nbt = new NBTTagCompound();
ridingRocket.isDead = false;
ridingRocket.riddenByEntity = null;
ridingRocket.writeToNBTOptional(nbt);
((WorldServer) ridingRocket.worldObj).getEntityTracker().untrackEntity(ridingRocket);
removeEntityFromWorld(ridingRocket.worldObj, ridingRocket, true);
ridingRocket = (EntityAutoRocket) EntityList.createEntityFromNBT(nbt, worldNew);
if (ridingRocket != null) {
ridingRocket.setWaitForPlayer(true);
if (ridingRocket instanceof IWorldTransferCallback) {
((IWorldTransferCallback) ridingRocket).onWorldTransferred(worldNew);
}
}
}
if (dimChange) {
if (entity instanceof EntityPlayerMP) {
player = (EntityPlayerMP) entity;
World worldOld = player.worldObj;
GCPlayerStats stats = GCPlayerStats.get(player);
stats.setUsingPlanetSelectionGui(false);
player.dimension = dimID;
if (ConfigManagerCore.enableDebug) {
GCLog.info("DEBUG: Sending respawn packet to player for dim " + dimID);
}
player.playerNetServerHandler.sendPacket(new S07PacketRespawn(dimID, player.worldObj.getDifficulty(), player.worldObj.getWorldInfo().getTerrainType(), player.theItemInWorldManager.getGameType()));
if (worldNew.provider instanceof WorldProviderSpaceStation) {
if (WorldUtil.registeredSpaceStations.containsKey(dimID)) // TODO This has never been effective before due to the earlier bug - what does it actually do?
{
NBTTagCompound var2 = new NBTTagCompound();
SpaceStationWorldData.getStationData(worldNew, dimID, player).writeToNBT(var2);
GalacticraftCore.packetPipeline.sendTo(new PacketSimple(EnumSimplePacket.C_UPDATE_SPACESTATION_DATA, GCCoreUtil.getDimensionID(player.worldObj), new Object[] { dimID, var2 }), player);
}
}
removeEntityFromWorld(worldOld, player, true);
if (ridingRocket != null) {
spawnPos = new Vector3(ridingRocket);
} else {
spawnPos = type.getPlayerSpawnLocation((WorldServer) worldNew, player);
}
forceMoveEntityToPos(entity, (WorldServer) worldNew, spawnPos, true);
GCLog.info("Server attempting to transfer player " + PlayerUtil.getName(player) + " to dimension " + GCCoreUtil.getDimensionID(worldNew));
if (worldNew.provider instanceof WorldProviderSpaceStation) {
GalacticraftCore.packetPipeline.sendTo(new PacketSimple(EnumSimplePacket.C_RESET_THIRD_PERSON, GCCoreUtil.getDimensionID(worldNew), new Object[] {}), player);
}
player.capabilities.isFlying = false;
player.mcServer.getConfigurationManager().preparePlayer(player, (WorldServer) worldOld);
player.theItemInWorldManager.setWorld((WorldServer) worldNew);
player.mcServer.getConfigurationManager().updateTimeAndWeatherForPlayer(player, (WorldServer) worldNew);
player.mcServer.getConfigurationManager().syncPlayerInventory(player);
for (Object o : player.getActivePotionEffects()) {
PotionEffect var10 = (PotionEffect) o;
player.playerNetServerHandler.sendPacket(new S1DPacketEntityEffect(player.getEntityId(), var10));
}
player.playerNetServerHandler.sendPacket(new S1FPacketSetExperience(player.experience, player.experienceTotal, player.experienceLevel));
} else // Non-player entity transfer i.e. it's an EntityCargoRocket or an empty rocket
{
ArrayList<TileEntityTelemetry> tList = null;
if (entity instanceof EntitySpaceshipBase) {
tList = ((EntitySpaceshipBase) entity).getTelemetry();
}
WorldUtil.removeEntityFromWorld(entity.worldObj, entity, true);
NBTTagCompound nbt = new NBTTagCompound();
entity.isDead = false;
entity.writeToNBTOptional(nbt);
entity = EntityList.createEntityFromNBT(nbt, worldNew);
if (entity == null) {
return null;
}
if (entity instanceof IWorldTransferCallback) {
((IWorldTransferCallback) entity).onWorldTransferred(worldNew);
}
forceMoveEntityToPos(entity, (WorldServer) worldNew, new Vector3(entity), true);
if (tList != null && tList.size() > 0) {
for (TileEntityTelemetry t : tList) {
t.addTrackedEntity(entity);
}
}
}
} else {
// Same dimension player transfer
if (entity instanceof EntityPlayerMP) {
player = (EntityPlayerMP) entity;
player.closeScreen();
GCPlayerStats stats = GCPlayerStats.get(player);
stats.setUsingPlanetSelectionGui(false);
if (ridingRocket != null) {
spawnPos = new Vector3(ridingRocket);
} else {
spawnPos = type.getPlayerSpawnLocation((WorldServer) entity.worldObj, (EntityPlayerMP) entity);
}
forceMoveEntityToPos(entity, (WorldServer) worldNew, spawnPos, false);
GCLog.info("Server attempting to transfer player " + PlayerUtil.getName(player) + " within same dimension " + GCCoreUtil.getDimensionID(worldNew));
if (worldNew.provider instanceof WorldProviderSpaceStation) {
GalacticraftCore.packetPipeline.sendTo(new PacketSimple(EnumSimplePacket.C_RESET_THIRD_PERSON, GCCoreUtil.getDimensionID(worldNew), new Object[] {}), player);
}
player.capabilities.isFlying = false;
}
// Cargo rocket does not needs its location setting here, it will do that itself
}
// Update PlayerStatsGC
if (player != null) {
GCPlayerStats stats = GCPlayerStats.get(player);
if (ridingRocket == null && type.useParachute() && stats.getExtendedInventory().getStackInSlot(4) != null && stats.getExtendedInventory().getStackInSlot(4).getItem() instanceof ItemParaChute) {
GCPlayerHandler.setUsingParachute(player, stats, true);
} else {
GCPlayerHandler.setUsingParachute(player, stats, false);
}
if (stats.getRocketStacks() != null && stats.getRocketStacks().length > 0) {
for (int stack = 0; stack < stats.getRocketStacks().length; stack++) {
if (transferInv) {
if (stats.getRocketStacks()[stack] == null) {
if (stack == stats.getRocketStacks().length - 1) {
if (stats.getRocketItem() != null) {
stats.getRocketStacks()[stack] = new ItemStack(stats.getRocketItem(), 1, stats.getRocketType());
}
} else if (stack == stats.getRocketStacks().length - 2) {
stats.getRocketStacks()[stack] = stats.getLaunchpadStack();
stats.setLaunchpadStack(null);
}
}
} else {
stats.getRocketStacks()[stack] = null;
}
}
}
if (transferInv && stats.getChestSpawnCooldown() == 0) {
stats.setChestSpawnVector(type.getParaChestSpawnLocation((WorldServer) entity.worldObj, player, new Random()));
stats.setChestSpawnCooldown(200);
}
}
if (ridingRocket != null) {
ridingRocket.forceSpawn = true;
worldNew.spawnEntityInWorld(ridingRocket);
ridingRocket.setWorld(worldNew);
worldNew.updateEntityWithOptionalForce(ridingRocket, true);
entity.mountEntity(ridingRocket);
GCLog.debug("Entering rocket at : " + entity.posX + "," + entity.posZ + " rocket at: " + ridingRocket.posX + "," + ridingRocket.posZ);
} else if (otherRiddenEntity != null) {
if (dimChange) {
World worldOld = otherRiddenEntity.worldObj;
NBTTagCompound nbt = new NBTTagCompound();
otherRiddenEntity.writeToNBTOptional(nbt);
removeEntityFromWorld(worldOld, otherRiddenEntity, true);
otherRiddenEntity = EntityList.createEntityFromNBT(nbt, worldNew);
worldNew.spawnEntityInWorld(otherRiddenEntity);
otherRiddenEntity.setWorld(worldNew);
}
otherRiddenEntity.setPositionAndRotation(entity.posX, entity.posY - 10, entity.posZ, otherRiddenEntity.rotationYaw, otherRiddenEntity.rotationPitch);
worldNew.updateEntityWithOptionalForce(otherRiddenEntity, true);
}
if (entity instanceof EntityPlayerMP) {
if (dimChange)
FMLCommonHandler.instance().firePlayerChangedDimensionEvent((EntityPlayerMP) entity, oldDimID, dimID);
// Spawn in a lander if appropriate
type.onSpaceDimensionChanged(worldNew, (EntityPlayerMP) entity, ridingRocket != null);
}
return entity;
}
use of micdoodle8.mods.galacticraft.core.tile.TileEntityTelemetry in project Galacticraft by micdoodle8.
the class PacketSimple method handleClientSide.
@SideOnly(Side.CLIENT)
@Override
public void handleClientSide(EntityPlayer player) {
EntityPlayerSP playerBaseClient = null;
GCPlayerStatsClient stats = null;
if (player instanceof EntityPlayerSP) {
playerBaseClient = (EntityPlayerSP) player;
stats = GCPlayerStatsClient.get(playerBaseClient);
} else {
if (type != EnumSimplePacket.C_UPDATE_SPACESTATION_LIST && type != EnumSimplePacket.C_UPDATE_PLANETS_LIST && type != EnumSimplePacket.C_UPDATE_CONFIGS) {
return;
}
}
switch(this.type) {
case C_AIR_REMAINING:
if (String.valueOf(this.data.get(2)).equals(String.valueOf(PlayerUtil.getName(player)))) {
TickHandlerClient.airRemaining = (Integer) this.data.get(0);
TickHandlerClient.airRemaining2 = (Integer) this.data.get(1);
}
break;
case C_UPDATE_DIMENSION_LIST:
if (String.valueOf(this.data.get(0)).equals(PlayerUtil.getName(player))) {
String dimensionList = (String) this.data.get(1);
if (ConfigManagerCore.enableDebug) {
if (!dimensionList.equals(PacketSimple.spamCheckString)) {
GCLog.info("DEBUG info: " + dimensionList);
PacketSimple.spamCheckString = dimensionList;
}
}
final String[] destinations = dimensionList.split("\\?");
List<CelestialBody> possibleCelestialBodies = Lists.newArrayList();
Map<Integer, Map<String, GuiCelestialSelection.StationDataGUI>> spaceStationData = Maps.newHashMap();
for (String str : destinations) {
CelestialBody celestialBody = WorldUtil.getReachableCelestialBodiesForName(str);
if (celestialBody == null && str.contains("$")) {
String[] values = str.split("\\$");
int homePlanetID = Integer.parseInt(values[4]);
for (Satellite satellite : GalaxyRegistry.getRegisteredSatellites().values()) {
if (satellite.getParentPlanet().getDimensionID() == homePlanetID) {
celestialBody = satellite;
break;
}
}
if (!spaceStationData.containsKey(homePlanetID)) {
spaceStationData.put(homePlanetID, new HashMap<String, GuiCelestialSelection.StationDataGUI>());
}
spaceStationData.get(homePlanetID).put(values[1], new GuiCelestialSelection.StationDataGUI(values[2], Integer.parseInt(values[3])));
// spaceStationNames.put(values[1], values[2]);
// spaceStationIDs.put(values[1], Integer.parseInt(values[3]));
// spaceStationHomes.put(values[1], Integer.parseInt(values[4]));
}
if (celestialBody != null) {
possibleCelestialBodies.add(celestialBody);
}
}
if (FMLClientHandler.instance().getClient().theWorld != null) {
if (!(FMLClientHandler.instance().getClient().currentScreen instanceof GuiCelestialSelection)) {
GuiCelestialSelection gui = new GuiCelestialSelection(false, possibleCelestialBodies);
gui.spaceStationMap = spaceStationData;
// gui.spaceStationNames = spaceStationNames;
// gui.spaceStationIDs = spaceStationIDs;
FMLClientHandler.instance().getClient().displayGuiScreen(gui);
} else {
((GuiCelestialSelection) FMLClientHandler.instance().getClient().currentScreen).possibleBodies = possibleCelestialBodies;
((GuiCelestialSelection) FMLClientHandler.instance().getClient().currentScreen).spaceStationMap = spaceStationData;
// ((GuiCelestialSelection) FMLClientHandler.instance().getClient().currentScreen).spaceStationNames = spaceStationNames;
// ((GuiCelestialSelection) FMLClientHandler.instance().getClient().currentScreen).spaceStationIDs = spaceStationIDs;
}
}
}
break;
case C_SPAWN_SPARK_PARTICLES:
BlockPos pos = (BlockPos) this.data.get(0);
Minecraft mc = Minecraft.getMinecraft();
for (int i = 0; i < 4; i++) {
if (mc != null && mc.getRenderViewEntity() != null && mc.effectRenderer != null && mc.theWorld != null) {
final EntityFX fx = new EntityFXSparks(mc.theWorld, pos.getX() - 0.15 + 0.5, pos.getY() + 1.2, pos.getZ() + 0.15 + 0.5, mc.theWorld.rand.nextDouble() / 20 - mc.theWorld.rand.nextDouble() / 20, mc.theWorld.rand.nextDouble() / 20 - mc.theWorld.rand.nextDouble() / 20);
if (fx != null) {
mc.effectRenderer.addEffect(fx);
}
}
}
break;
case C_UPDATE_GEAR_SLOT:
int subtype = (Integer) this.data.get(3);
String gearName = (String) this.data.get(0);
EntityPlayer gearDataPlayer = player.worldObj.getPlayerEntityByName(gearName);
if (gearDataPlayer != null) {
PlayerGearData gearData = ClientProxyCore.playerItemData.get(PlayerUtil.getName(gearDataPlayer));
if (gearData == null) {
gearData = new PlayerGearData(player);
if (!ClientProxyCore.gearDataRequests.contains(gearName)) {
GalacticraftCore.packetPipeline.sendToServer(new PacketSimple(PacketSimple.EnumSimplePacket.S_REQUEST_GEAR_DATA, getDimensionID(), new Object[] { gearName }));
ClientProxyCore.gearDataRequests.add(gearName);
}
} else {
ClientProxyCore.gearDataRequests.remove(gearName);
}
EnumExtendedInventorySlot type = EnumExtendedInventorySlot.values()[(Integer) this.data.get(2)];
EnumModelPacketType typeChange = EnumModelPacketType.values()[(Integer) this.data.get(1)];
switch(type) {
case MASK:
gearData.setMask(subtype);
break;
case GEAR:
gearData.setGear(subtype);
break;
case LEFT_TANK:
gearData.setLeftTank(subtype);
break;
case RIGHT_TANK:
gearData.setRightTank(subtype);
break;
case PARACHUTE:
if (typeChange == EnumModelPacketType.ADD) {
String name;
if (subtype != -1) {
name = ItemParaChute.names[subtype];
gearData.setParachute(new ResourceLocation(Constants.ASSET_PREFIX, "textures/model/parachute/" + name + ".png"));
}
} else {
gearData.setParachute(null);
}
break;
case FREQUENCY_MODULE:
gearData.setFrequencyModule(subtype);
break;
case THERMAL_HELMET:
gearData.setThermalPadding(0, subtype);
break;
case THERMAL_CHESTPLATE:
gearData.setThermalPadding(1, subtype);
break;
case THERMAL_LEGGINGS:
gearData.setThermalPadding(2, subtype);
break;
case THERMAL_BOOTS:
gearData.setThermalPadding(3, subtype);
break;
case SHIELD_CONTROLLER:
gearData.setShieldController(subtype);
break;
default:
break;
}
ClientProxyCore.playerItemData.put(gearName, gearData);
}
break;
case C_CLOSE_GUI:
FMLClientHandler.instance().getClient().displayGuiScreen(null);
break;
case C_RESET_THIRD_PERSON:
FMLClientHandler.instance().getClient().gameSettings.thirdPersonView = stats.getThirdPersonView();
break;
case C_UPDATE_SPACESTATION_LIST:
WorldUtil.decodeSpaceStationListClient(data);
break;
case C_UPDATE_SPACESTATION_DATA:
SpaceStationWorldData var4 = SpaceStationWorldData.getMPSpaceStationData(player.worldObj, (Integer) this.data.get(0), player);
var4.readFromNBT((NBTTagCompound) this.data.get(1));
break;
case C_UPDATE_SPACESTATION_CLIENT_ID:
ClientProxyCore.clientSpaceStationID = WorldUtil.stringToSpaceStationData((String) this.data.get(0));
break;
case C_UPDATE_PLANETS_LIST:
WorldUtil.decodePlanetsListClient(data);
break;
case C_UPDATE_CONFIGS:
ConfigManagerCore.saveClientConfigOverrideable();
ConfigManagerCore.setConfigOverride(data);
break;
case C_ADD_NEW_SCHEMATIC:
final ISchematicPage page = SchematicRegistry.getMatchingRecipeForID((Integer) this.data.get(0));
if (!stats.getUnlockedSchematics().contains(page)) {
stats.getUnlockedSchematics().add(page);
}
break;
case C_UPDATE_SCHEMATIC_LIST:
for (Object o : this.data) {
Integer schematicID = (Integer) o;
if (schematicID != -2) {
Collections.sort(stats.getUnlockedSchematics());
if (!stats.getUnlockedSchematics().contains(SchematicRegistry.getMatchingRecipeForID(schematicID))) {
stats.getUnlockedSchematics().add(SchematicRegistry.getMatchingRecipeForID(schematicID));
}
}
}
break;
case C_PLAY_SOUND_BOSS_DEATH:
player.playSound(Constants.TEXTURE_PREFIX + "entity.bossdeath", 10.0F, (Float) this.data.get(0));
break;
case C_PLAY_SOUND_EXPLODE:
player.playSound("random.explode", 10.0F, 0.7F);
break;
case C_PLAY_SOUND_BOSS_LAUGH:
player.playSound(Constants.TEXTURE_PREFIX + "entity.bosslaugh", 10.0F, 1.1F);
break;
case C_PLAY_SOUND_BOW:
player.playSound("random.bow", 10.0F, 0.2F);
break;
case C_UPDATE_OXYGEN_VALIDITY:
stats.setOxygenSetupValid((Boolean) this.data.get(0));
break;
case C_OPEN_PARACHEST_GUI:
switch((Integer) this.data.get(1)) {
case 0:
if (player.ridingEntity instanceof EntityBuggy) {
FMLClientHandler.instance().getClient().displayGuiScreen(new GuiBuggy(player.inventory, (EntityBuggy) player.ridingEntity, ((EntityBuggy) player.ridingEntity).getType()));
player.openContainer.windowId = (Integer) this.data.get(0);
}
break;
case 1:
int entityID = (Integer) this.data.get(2);
Entity entity = player.worldObj.getEntityByID(entityID);
if (entity != null && entity instanceof IInventorySettable) {
FMLClientHandler.instance().getClient().displayGuiScreen(new GuiParaChest(player.inventory, (IInventorySettable) entity));
}
player.openContainer.windowId = (Integer) this.data.get(0);
break;
}
break;
case C_UPDATE_WIRE_BOUNDS:
TileEntity tile = player.worldObj.getTileEntity((BlockPos) this.data.get(0));
if (tile instanceof TileBaseConductor) {
((TileBaseConductor) tile).adjacentConnections = null;
player.worldObj.getBlockState(tile.getPos()).getBlock().setBlockBoundsBasedOnState(player.worldObj, tile.getPos());
}
break;
case C_OPEN_SPACE_RACE_GUI:
if (Minecraft.getMinecraft().currentScreen == null) {
TickHandlerClient.spaceRaceGuiScheduled = false;
player.openGui(GalacticraftCore.instance, GuiIdsCore.SPACE_RACE_START, player.worldObj, (int) player.posX, (int) player.posY, (int) player.posZ);
} else {
TickHandlerClient.spaceRaceGuiScheduled = true;
}
break;
case C_UPDATE_SPACE_RACE_DATA:
Integer teamID = (Integer) this.data.get(0);
String teamName = (String) this.data.get(1);
FlagData flagData = (FlagData) this.data.get(2);
Vector3 teamColor = (Vector3) this.data.get(3);
List<String> playerList = new ArrayList<String>();
for (int i = 4; i < this.data.size(); i++) {
String playerName = (String) this.data.get(i);
ClientProxyCore.flagRequestsSent.remove(playerName);
playerList.add(playerName);
}
SpaceRace race = new SpaceRace(playerList, teamName, flagData, teamColor);
race.setSpaceRaceID(teamID);
SpaceRaceManager.addSpaceRace(race);
break;
case C_OPEN_JOIN_RACE_GUI:
stats.setSpaceRaceInviteTeamID((Integer) this.data.get(0));
player.openGui(GalacticraftCore.instance, GuiIdsCore.SPACE_RACE_JOIN, player.worldObj, (int) player.posX, (int) player.posY, (int) player.posZ);
break;
case C_UPDATE_DUNGEON_DIRECTION:
stats.setDungeonDirection((Float) this.data.get(0));
break;
case C_UPDATE_FOOTPRINT_LIST:
List<Footprint> printList = new ArrayList<Footprint>();
long chunkKey = (Long) this.data.get(0);
for (int i = 1; i < this.data.size(); i++) {
Footprint print = (Footprint) this.data.get(i);
if (!print.owner.equals(player.getName())) {
printList.add(print);
}
}
FootprintRenderer.setFootprints(chunkKey, printList);
break;
case C_FOOTPRINTS_REMOVED:
long chunkKey0 = (Long) this.data.get(0);
BlockVec3 position = (BlockVec3) this.data.get(1);
List<Footprint> footprintList = FootprintRenderer.footprints.get(chunkKey0);
List<Footprint> toRemove = new ArrayList<Footprint>();
if (footprintList != null) {
for (Footprint footprint : footprintList) {
if (footprint.position.x > position.x && footprint.position.x < position.x + 1 && footprint.position.z > position.z && footprint.position.z < position.z + 1) {
toRemove.add(footprint);
}
}
}
if (!toRemove.isEmpty()) {
footprintList.removeAll(toRemove);
FootprintRenderer.footprints.put(chunkKey0, footprintList);
}
break;
case C_UPDATE_STATION_SPIN:
if (playerBaseClient.worldObj.provider instanceof WorldProviderSpaceStation) {
((WorldProviderSpaceStation) playerBaseClient.worldObj.provider).getSpinManager().setSpinRate((Float) this.data.get(0), (Boolean) this.data.get(1));
}
break;
case C_UPDATE_STATION_DATA:
if (playerBaseClient.worldObj.provider instanceof WorldProviderSpaceStation) {
((WorldProviderSpaceStation) playerBaseClient.worldObj.provider).getSpinManager().setSpinCentre((Double) this.data.get(0), (Double) this.data.get(1));
}
break;
case C_UPDATE_STATION_BOX:
if (playerBaseClient.worldObj.provider instanceof WorldProviderSpaceStation) {
((WorldProviderSpaceStation) playerBaseClient.worldObj.provider).getSpinManager().setSpinBox((Integer) this.data.get(0), (Integer) this.data.get(1), (Integer) this.data.get(2), (Integer) this.data.get(3), (Integer) this.data.get(4), (Integer) this.data.get(5));
}
break;
case C_UPDATE_THERMAL_LEVEL:
stats.setThermalLevel((Integer) this.data.get(0));
stats.setThermalLevelNormalising((Boolean) this.data.get(1));
break;
case C_DISPLAY_ROCKET_CONTROLS:
player.addChatMessage(new ChatComponentText(GameSettings.getKeyDisplayString(KeyHandlerClient.spaceKey.getKeyCode()) + " - " + GCCoreUtil.translate("gui.rocket.launch.name")));
player.addChatMessage(new ChatComponentText(GameSettings.getKeyDisplayString(KeyHandlerClient.leftKey.getKeyCode()) + " / " + GameSettings.getKeyDisplayString(KeyHandlerClient.rightKey.getKeyCode()) + " - " + GCCoreUtil.translate("gui.rocket.turn.name")));
player.addChatMessage(new ChatComponentText(GameSettings.getKeyDisplayString(KeyHandlerClient.accelerateKey.getKeyCode()) + " / " + GameSettings.getKeyDisplayString(KeyHandlerClient.decelerateKey.getKeyCode()) + " - " + GCCoreUtil.translate("gui.rocket.updown.name")));
player.addChatMessage(new ChatComponentText(GameSettings.getKeyDisplayString(KeyHandlerClient.openFuelGui.getKeyCode()) + " - " + GCCoreUtil.translate("gui.rocket.inv.name")));
break;
case C_GET_CELESTIAL_BODY_LIST:
String str = "";
for (CelestialBody cBody : GalaxyRegistry.getRegisteredPlanets().values()) {
str = str.concat(cBody.getUnlocalizedName() + ";");
}
for (CelestialBody cBody : GalaxyRegistry.getRegisteredMoons().values()) {
str = str.concat(cBody.getUnlocalizedName() + ";");
}
for (CelestialBody cBody : GalaxyRegistry.getRegisteredSatellites().values()) {
str = str.concat(cBody.getUnlocalizedName() + ";");
}
for (SolarSystem solarSystem : GalaxyRegistry.getRegisteredSolarSystems().values()) {
str = str.concat(solarSystem.getUnlocalizedName() + ";");
}
GalacticraftCore.packetPipeline.sendToServer(new PacketSimple(EnumSimplePacket.S_COMPLETE_CBODY_HANDSHAKE, getDimensionID(), new Object[] { str }));
break;
case C_UPDATE_ENERGYUNITS:
CommandGCEnergyUnits.handleParamClientside((Integer) this.data.get(0));
break;
case C_RESPAWN_PLAYER:
final WorldProvider provider = WorldUtil.getProviderForNameClient((String) this.data.get(0));
final int dimID = GCCoreUtil.getDimensionID(provider);
if (ConfigManagerCore.enableDebug) {
GCLog.info("DEBUG: Client receiving respawn packet for dim " + dimID);
}
int par2 = (Integer) this.data.get(1);
String par3 = (String) this.data.get(2);
int par4 = (Integer) this.data.get(3);
WorldUtil.forceRespawnClient(dimID, par2, par3, par4);
break;
case C_UPDATE_STATS:
stats.setBuildFlags((Integer) this.data.get(0));
BlockPanelLighting.updateClient(this.data);
break;
case C_UPDATE_TELEMETRY:
tile = player.worldObj.getTileEntity((BlockPos) this.data.get(0));
if (tile instanceof TileEntityTelemetry) {
((TileEntityTelemetry) tile).receiveUpdate(data, this.getDimensionID());
}
break;
case C_SEND_PLAYERSKIN:
String strName = (String) this.data.get(0);
String s1 = (String) this.data.get(1);
String s2 = (String) this.data.get(2);
String strUUID = (String) this.data.get(3);
GameProfile gp = PlayerUtil.getOtherPlayerProfile(strName);
if (gp == null) {
gp = PlayerUtil.makeOtherPlayerProfile(strName, strUUID);
}
gp.getProperties().put("textures", new Property("textures", s1, s2));
break;
case C_SEND_OVERWORLD_IMAGE:
try {
int cx = (Integer) this.data.get(0);
int cz = (Integer) this.data.get(1);
byte[] bytes = (byte[]) this.data.get(2);
MapUtil.receiveOverworldImageCompressed(cx, cz, bytes);
} catch (Exception e) {
e.printStackTrace();
}
break;
case C_RECOLOR_PIPE:
TileEntity tileEntity = player.worldObj.getTileEntity((BlockPos) this.data.get(0));
if (tileEntity instanceof TileEntityFluidPipe) {
TileEntityFluidPipe pipe = (TileEntityFluidPipe) tileEntity;
pipe.getNetwork().split(pipe);
pipe.setNetwork(null);
}
break;
case C_RECOLOR_ALL_GLASS:
BlockSpaceGlass.updateGlassColors((Integer) this.data.get(0), (Integer) this.data.get(1), (Integer) this.data.get(2));
break;
case C_UPDATE_MACHINE_DATA:
TileEntity tile3 = player.worldObj.getTileEntity((BlockPos) this.data.get(0));
if (tile3 instanceof ITileClientUpdates) {
((ITileClientUpdates) tile3).updateClient(this.data);
}
break;
case C_LEAK_DATA:
TileEntity tile4 = player.worldObj.getTileEntity((BlockPos) this.data.get(0));
if (tile4 instanceof TileEntityOxygenSealer) {
((ITileClientUpdates) tile4).updateClient(this.data);
}
break;
case C_SPAWN_HANGING_SCHEMATIC:
EntityHangingSchematic entity = new EntityHangingSchematic(player.worldObj, (BlockPos) this.data.get(0), EnumFacing.getFront((Integer) this.data.get(2)), (Integer) this.data.get(3));
((WorldClient) player.worldObj).addEntityToWorld((Integer) this.data.get(1), entity);
break;
default:
break;
}
}
Aggregations