use of micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider in project Galacticraft by micdoodle8.
the class TileEntitySolar method update.
@Override
public void update() {
if (!this.initialised) {
int metadata = this.getBlockMetadata();
if (metadata >= BlockSolar.ADVANCED_METADATA) {
this.storage.setCapacity(30000);
this.setTierGC(2);
}
this.initialised = true;
}
if (!this.initialisedMulti) {
this.initialisedMulti = this.initialiseMultiTiles(this.getPos(), this.world);
}
if (!this.world.isRemote) {
this.receiveEnergyGC(null, this.generateWatts, false);
}
super.update();
if (!this.world.isRemote) {
this.recharge(this.getInventory().get(0));
if (this.disableCooldown > 0) {
this.disableCooldown--;
}
if (!this.getDisabled(0) && this.ticks % 20 == 0) {
this.solarStrength = 0;
if (this.world.isDaytime() && (this.world.provider instanceof IGalacticraftWorldProvider || !this.world.isRaining() && !this.world.isThundering())) {
double distance = 100.0D;
double sinA = -Math.sin((this.currentAngle - 77.5D) / Constants.RADIANS_TO_DEGREES_D);
double cosA = Math.abs(Math.cos((this.currentAngle - 77.5D) / Constants.RADIANS_TO_DEGREES_D));
for (int x = -1; x <= 1; x++) {
for (int z = -1; z <= 1; z++) {
if (this.tierGC == 1) {
if (this.world.canBlockSeeSky(this.getPos().add(x, 2, z))) {
boolean valid = true;
for (int y = this.getPos().getY() + 3; y < 256; y++) {
IBlockState state = this.world.getBlockState(new BlockPos(this.getPos().getX() + x, y, this.getPos().getZ() + z));
if (state.getBlock().isOpaqueCube(state)) {
valid = false;
break;
}
}
if (valid) {
this.solarStrength++;
}
}
} else {
boolean valid = true;
BlockVec3 blockVec = new BlockVec3(this).translate(x, 3, z);
for (double d = 0.0D; d < distance; d++) {
BlockVec3 blockAt = blockVec.clone().translate((int) (d * sinA), (int) (d * cosA), 0);
IBlockState state = blockAt.getBlockState(this.world);
if (state == null) {
break;
}
if (state.getBlock().isOpaqueCube(state)) {
valid = false;
break;
}
}
if (valid) {
this.solarStrength++;
}
}
}
}
}
}
}
float angle = this.world.getCelestialAngle(1.0F) - 0.7845194F < 0 ? 1.0F - 0.7845194F : -0.7845194F;
float celestialAngle = (this.world.getCelestialAngle(1.0F) + angle) * 360.0F;
if (!(this.world.provider instanceof WorldProviderSpaceStation))
celestialAngle += 12.5F;
if (GalacticraftCore.isPlanetsLoaded && this.world.provider instanceof WorldProviderVenus)
celestialAngle = 180F - celestialAngle;
celestialAngle %= 360;
boolean isDaytime = this.world.isDaytime() && (celestialAngle < 180.5F || celestialAngle > 359.5F) || this.world.provider instanceof WorldProviderSpaceStation;
if (this.tierGC == 1) {
if (!isDaytime || this.world.isRaining() || this.world.isThundering()) {
this.targetAngle = 77.5F + 180.0F;
} else {
this.targetAngle = 77.5F;
}
} else {
if (!isDaytime || this.world.isRaining() || this.world.isThundering()) {
this.targetAngle = 77.5F + 180F;
} else if (celestialAngle > 27.5F && celestialAngle < 152.5F) {
float difference = this.targetAngle - celestialAngle + 12.5F;
this.targetAngle -= difference / 20.0F;
} else if (celestialAngle <= 27.5F || celestialAngle > 270F) {
this.targetAngle = 15F;
} else if (celestialAngle >= 152.5F) {
this.targetAngle = 140F;
}
}
float difference = this.targetAngle - this.currentAngle;
this.currentAngle += difference / 20.0F;
if (!this.world.isRemote) {
int generated = this.getGenerate();
if (generated > 0) {
this.generateWatts = Math.min(Math.max(generated, 0), TileEntitySolar.MAX_GENERATE_WATTS);
} else {
this.generateWatts = 0;
}
}
this.produce();
}
use of micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider in project Galacticraft by micdoodle8.
the class TileEntityOxygenCollector method update.
@Override
public void update() {
super.update();
if (!this.world.isRemote) {
producedLastTick = this.getOxygenStored() < this.getMaxOxygenStored();
this.produceOxygen();
// Approximately once every 40 ticks, search out oxygen producing blocks
if (this.world.rand.nextInt(10) == 0) {
if (this.hasEnoughEnergyToRun) {
// The later calculations are more efficient if power is a float, so
// there are fewer casts
float nearbyLeaves = 0;
if (!this.isInitialised) {
this.noAtmosphericOxygen = (this.world.provider instanceof IGalacticraftWorldProvider && !((IGalacticraftWorldProvider) this.world.provider).isGasPresent(EnumAtmosphericGas.OXYGEN));
this.isInitialised = true;
}
if (this.noAtmosphericOxygen) {
// loop
if (this.getPos().getX() > -29999995 && this.getPos().getY() < 2999995 && this.getPos().getZ() > -29999995 && this.getPos().getZ() < 29999995) {
// Test the y coordinates, so code doesn't have to keep
// testing that either
int miny = this.getPos().getY() - 5;
int maxy = this.getPos().getY() + 5;
if (miny < 0) {
miny = 0;
}
if (maxy >= this.world.getHeight()) {
maxy = this.world.getHeight() - 1;
}
// coordinates
for (int x = this.getPos().getX() - 5; x <= this.getPos().getX() + 5; x++) {
int chunkx = x >> 4;
int intrachunkx = x & 15;
// Preload the first chunk for the z loop - there
// can be a maximum of 2 chunks in the z loop
int chunkz = this.getPos().getZ() - 5 >> 4;
Chunk chunk = this.world.getChunkFromChunkCoords(chunkx, chunkz);
for (int z = this.getPos().getZ() - 5; z <= this.getPos().getZ() + 5; z++) {
if (z >> 4 != chunkz) {
// moved across z chunk boundary into a new
// chunk, so load the new chunk
chunkz = z >> 4;
chunk = this.world.getChunkFromChunkCoords(chunkx, chunkz);
}
for (int y = miny; y <= maxy; y++) {
// chunk.getBlockID is like world.getBlock
// but faster - needs to be given
// intra-chunk coordinates though
final IBlockState state = chunk.getBlockState(intrachunkx, y, z & 15);
// in the blocksList
if (!(state.getBlock() instanceof BlockAir)) {
BlockPos pos = new BlockPos(x, y, z);
if (state.getBlock().isLeaves(state, this.world, pos) || state.getBlock() instanceof IPlantable && ((IPlantable) state.getBlock()).getPlantType(this.world, pos) == EnumPlantType.Crop) {
nearbyLeaves += OXYGEN_PER_PLANT;
}
}
}
}
}
}
} else {
nearbyLeaves = 9.3F * 10F;
}
nearbyLeaves = (float) Math.floor(nearbyLeaves);
this.lastOxygenCollected = nearbyLeaves / 10F;
this.tank.setFluid(new FluidStack(GCFluids.fluidOxygenGas, (int) Math.max(Math.min(this.getOxygenStored() + nearbyLeaves, this.getMaxOxygenStored()), 0)));
} else {
this.lastOxygenCollected = 0;
}
}
}
}
use of micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider in project Galacticraft by micdoodle8.
the class GCPlayerHandler method throwMeteors.
protected void throwMeteors(EntityPlayerMP player) {
World world = player.world;
if (world.provider instanceof IGalacticraftWorldProvider && !world.isRemote) {
if (((IGalacticraftWorldProvider) world.provider).getMeteorFrequency() > 0 && ConfigManagerCore.meteorSpawnMod > 0.0) {
final int f = (int) (((IGalacticraftWorldProvider) world.provider).getMeteorFrequency() * 750D * (1.0 / ConfigManagerCore.meteorSpawnMod));
if (world.rand.nextInt(f) == 0) {
final EntityPlayer closestPlayer = world.getClosestPlayerToEntity(player, 100);
if (closestPlayer == null || closestPlayer.getEntityId() <= player.getEntityId()) {
int r = world.getMinecraftServer().getPlayerList().getViewDistance();
int x, z;
double motX, motZ;
x = world.rand.nextInt(20) + 160;
z = world.rand.nextInt(20) - 10;
motX = world.rand.nextDouble() * 2 - 2.5D;
motZ = world.rand.nextDouble() * 5 - 2.5D;
int px = MathHelper.floor(player.posX);
if ((x + px >> 4) - (px >> 4) >= r) {
x = ((px >> 4) + r << 4) - 1 - px;
}
final EntityMeteor meteor = new EntityMeteor(world, player.posX + x, 355D, player.posZ + z, motX, 0, motZ, 1);
if (!world.isRemote) {
world.spawnEntity(meteor);
}
}
}
if (world.rand.nextInt(f * 3) == 0) {
final EntityPlayer closestPlayer = world.getClosestPlayerToEntity(player, 100);
if (closestPlayer == null || closestPlayer.getEntityId() <= player.getEntityId()) {
int r = world.getMinecraftServer().getPlayerList().getViewDistance();
int x, z;
double motX, motZ;
x = world.rand.nextInt(20) + 160;
z = world.rand.nextInt(20) - 10;
motX = world.rand.nextDouble() * 2 - 2.5D;
motZ = world.rand.nextDouble() * 5 - 2.5D;
int px = MathHelper.floor(player.posX);
if ((x + px >> 4) - (px >> 4) >= r) {
x = ((px >> 4) + r << 4) - 1 - px;
}
final EntityMeteor meteor = new EntityMeteor(world, player.posX + x, 355D, player.posZ + z, motX, 0, motZ, 6);
if (!world.isRemote) {
world.spawnEntity(meteor);
}
}
}
}
}
}
use of micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider in project Galacticraft by micdoodle8.
the class GCPlayerHandler method onPlayerUpdate.
public void onPlayerUpdate(EntityPlayerMP player) {
int tick = player.ticksExisted - 1;
// This will speed things up a little
GCPlayerStats stats = GCPlayerStats.get(player);
if ((ConfigManagerCore.challengeSpawnHandling) && stats.getUnlockedSchematics().size() == 0) {
if (stats.getStartDimension().length() > 0) {
stats.setStartDimension("");
} else {
// PlayerAPI is installed
WorldServer worldOld = (WorldServer) player.world;
try {
worldOld.getPlayerChunkMap().removePlayer(player);
} catch (Exception e) {
}
worldOld.playerEntities.remove(player);
worldOld.updateAllPlayersSleepingFlag();
worldOld.loadedEntityList.remove(player);
worldOld.onEntityRemoved(player);
worldOld.getEntityTracker().untrack(player);
if (player.addedToChunk && worldOld.getChunkProvider().chunkExists(player.chunkCoordX, player.chunkCoordZ)) {
Chunk chunkOld = worldOld.getChunkFromChunkCoords(player.chunkCoordX, player.chunkCoordZ);
chunkOld.removeEntity(player);
chunkOld.setModified(true);
}
WorldServer worldNew = WorldUtil.getStartWorld(worldOld);
int dimID = GCCoreUtil.getDimensionID(worldNew);
player.dimension = dimID;
GCLog.debug("DEBUG: Sending respawn packet to player for dim " + dimID);
player.connection.sendPacket(new SPacketRespawn(dimID, player.world.getDifficulty(), player.world.getWorldInfo().getTerrainType(), player.interactionManager.getGameType()));
if (worldNew.provider instanceof WorldProviderSpaceStation) {
GalacticraftCore.packetPipeline.sendTo(new PacketSimple(EnumSimplePacket.C_RESET_THIRD_PERSON, GCCoreUtil.getDimensionID(player.world), new Object[] {}), player);
}
worldNew.spawnEntity(player);
player.setWorld(worldNew);
player.mcServer.getPlayerList().preparePlayer(player, (WorldServer) worldOld);
}
// This is a mini version of the code at WorldUtil.teleportEntity
player.interactionManager.setWorld((WorldServer) player.world);
final ITeleportType type = GalacticraftRegistry.getTeleportTypeForDimension(player.world.provider.getClass());
Vector3 spawnPos = type.getPlayerSpawnLocation((WorldServer) player.world, player);
ChunkPos pair = player.world.getChunkFromChunkCoords(spawnPos.intX() >> 4, spawnPos.intZ() >> 4).getPos();
GCLog.debug("Loading first chunk in new dimension.");
((WorldServer) player.world).getChunkProvider().loadChunk(pair.x, pair.z);
player.setLocationAndAngles(spawnPos.x, spawnPos.y, spawnPos.z, player.rotationYaw, player.rotationPitch);
type.setupAdventureSpawn(player);
type.onSpaceDimensionChanged(player.world, player, false);
player.setSpawnChunk(new BlockPos(spawnPos.intX(), spawnPos.intY(), spawnPos.intZ()), true, GCCoreUtil.getDimensionID(player.world));
stats.setNewAdventureSpawn(true);
}
final boolean isInGCDimension = player.world.provider instanceof IGalacticraftWorldProvider;
if (tick >= 25) {
if (ConfigManagerCore.enableSpaceRaceManagerPopup && !stats.hasOpenedSpaceRaceManager()) {
SpaceRace race = SpaceRaceManager.getSpaceRaceFromPlayer(PlayerUtil.getName(player));
if (race == null || race.teamName.equals(SpaceRace.DEFAULT_NAME)) {
GalacticraftCore.packetPipeline.sendTo(new PacketSimple(EnumSimplePacket.C_OPEN_SPACE_RACE_GUI, GCCoreUtil.getDimensionID(player.world), new Object[] {}), player);
}
stats.setOpenedSpaceRaceManager(true);
}
if (!stats.hasSentFlags()) {
GalacticraftCore.packetPipeline.sendTo(new PacketSimple(EnumSimplePacket.C_UPDATE_STATS, GCCoreUtil.getDimensionID(player.world), stats.getMiscNetworkedStats()), player);
stats.setSentFlags(true);
}
}
if (stats.getCryogenicChamberCooldown() > 0) {
stats.setCryogenicChamberCooldown(stats.getCryogenicChamberCooldown() - 1);
}
if (!player.onGround && stats.isLastOnGround()) {
stats.setTouchedGround(true);
}
if (stats.getTeleportCooldown() > 0) {
stats.setTeleportCooldown(stats.getTeleportCooldown() - 1);
}
if (stats.getChatCooldown() > 0) {
stats.setChatCooldown(stats.getChatCooldown() - 1);
}
if (stats.getOpenPlanetSelectionGuiCooldown() > 0) {
stats.setOpenPlanetSelectionGuiCooldown(stats.getOpenPlanetSelectionGuiCooldown() - 1);
if (stats.getOpenPlanetSelectionGuiCooldown() == 1 && !stats.hasOpenedPlanetSelectionGui()) {
WorldUtil.toCelestialSelection(player, stats, stats.getSpaceshipTier());
stats.setHasOpenedPlanetSelectionGui(true);
}
}
if (stats.isUsingParachute()) {
if (!stats.getLastParachuteInSlot().isEmpty()) {
player.fallDistance = 0.0F;
}
if (player.onGround) {
GCPlayerHandler.setUsingParachute(player, stats, false);
}
}
this.checkCurrentItem(player);
if (stats.isUsingPlanetSelectionGui()) {
// This sends the planets list again periodically (forcing the Celestial Selection screen to open) in case of server/client lag
// #PACKETSPAM
this.sendPlanetList(player, stats);
}
/* if (isInGCDimension || player.usingPlanetSelectionGui)
{
player.connection.ticksForFloatKick = 0;
}
*/
if (stats.getDamageCounter() > 0) {
stats.setDamageCounter(stats.getDamageCounter() - 1);
}
if (isInGCDimension) {
if (tick % 10 == 0) {
boolean doneDungeon = false;
ItemStack current = player.inventory.getCurrentItem();
if (current != null && current.getItem() == GCItems.dungeonFinder) {
this.sendDungeonDirectionPacket(player, stats);
doneDungeon = true;
}
if (tick % 30 == 0) {
GCPlayerHandler.sendAirRemainingPacket(player, stats);
this.sendThermalLevelPacket(player, stats);
if (!doneDungeon) {
for (ItemStack stack : player.inventory.mainInventory) {
if (stack != null && stack.getItem() == GCItems.dungeonFinder) {
this.sendDungeonDirectionPacket(player, stats);
break;
}
}
}
}
}
if (player.getRidingEntity() instanceof EntityLanderBase) {
stats.setInLander(true);
stats.setJustLanded(false);
} else {
if (stats.isInLander()) {
stats.setJustLanded(true);
}
stats.setInLander(false);
}
if (player.onGround && stats.hasJustLanded()) {
stats.setJustLanded(false);
// Set spawn point here if just descended from a lander for the first time
if (player.getBedLocation(GCCoreUtil.getDimensionID(player.world)) == null || stats.isNewAdventureSpawn()) {
int i = 30000000;
int j = Math.min(i, Math.max(-i, MathHelper.floor(player.posX + 0.5D)));
int k = Math.min(256, Math.max(0, MathHelper.floor(player.posY + 1.5D)));
int l = Math.min(i, Math.max(-i, MathHelper.floor(player.posZ + 0.5D)));
BlockPos coords = new BlockPos(j, k, l);
player.setSpawnChunk(coords, true, GCCoreUtil.getDimensionID(player.world));
stats.setNewAdventureSpawn(false);
}
GalacticraftCore.packetPipeline.sendTo(new PacketSimple(EnumSimplePacket.C_RESET_THIRD_PERSON, GCCoreUtil.getDimensionID(player.world), new Object[] {}), player);
}
if (player.world.provider instanceof WorldProviderSpaceStation || player.world.provider instanceof IZeroGDimension || GalacticraftCore.isPlanetsLoaded && player.world.provider instanceof WorldProviderAsteroids) {
this.preventFlyingKicks(player);
if (player.world.provider instanceof WorldProviderSpaceStation && stats.isNewInOrbit()) {
((WorldProviderSpaceStation) player.world.provider).getSpinManager().sendPackets(player);
stats.setNewInOrbit(false);
}
} else {
stats.setNewInOrbit(true);
}
} else {
stats.setNewInOrbit(true);
}
checkGear(player, stats, false);
if (stats.getChestSpawnCooldown() > 0) {
stats.setChestSpawnCooldown(stats.getChestSpawnCooldown() - 1);
if (stats.getChestSpawnCooldown() == 180) {
if (stats.getChestSpawnVector() != null) {
EntityParachest chest = new EntityParachest(player.world, stats.getRocketStacks(), stats.getFuelLevel());
chest.setPosition(stats.getChestSpawnVector().x, stats.getChestSpawnVector().y, stats.getChestSpawnVector().z);
chest.color = stats.getParachuteInSlot().isEmpty() ? EnumDyeColor.WHITE : ItemParaChute.getDyeEnumFromParachuteDamage(stats.getParachuteInSlot().getItemDamage());
if (!player.world.isRemote) {
player.world.spawnEntity(chest);
}
}
}
}
if (stats.getLaunchAttempts() > 0 && player.getRidingEntity() == null) {
stats.setLaunchAttempts(0);
}
this.checkThermalStatus(player, stats);
this.checkOxygen(player, stats);
this.checkShield(player, stats);
if (isInGCDimension && (stats.isOxygenSetupValid() != stats.isLastOxygenSetupValid() || tick % 100 == 0)) {
GalacticraftCore.packetPipeline.sendTo(new PacketSimple(EnumSimplePacket.C_UPDATE_OXYGEN_VALIDITY, player.world.provider.getDimension(), new Object[] { stats.isOxygenSetupValid() }), player);
}
this.throwMeteors(player);
this.updateSchematics(player, stats);
if (tick % 250 == 0 && stats.getFrequencyModuleInSlot().isEmpty() && !stats.hasReceivedSoundWarning() && isInGCDimension && player.onGround && tick > 0 && ((IGalacticraftWorldProvider) player.world.provider).getSoundVolReductionAmount() > 1.0F) {
String[] string2 = GCCoreUtil.translate("gui.frequencymodule.warning1").split(" ");
StringBuilder sb = new StringBuilder();
for (String aString2 : string2) {
sb.append(" ").append(EnumColor.YELLOW).append(aString2);
}
player.sendMessage(new TextComponentString(EnumColor.YELLOW + GCCoreUtil.translate("gui.frequencymodule.warning0") + " " + EnumColor.AQUA + GCItems.basicItem.getItemStackDisplayName(new ItemStack(GCItems.basicItem, 1, 19)) + sb.toString()));
stats.setReceivedSoundWarning(true);
}
// Player moves and sprints 18% faster with full set of Titanium Armor
if (GalacticraftCore.isPlanetsLoaded && tick % 40 == 1 && player.inventory != null) {
int titaniumCount = 0;
for (ItemStack armorPiece : player.getArmorInventoryList()) {
if (armorPiece != null && armorPiece.getItem() instanceof ItemArmorAsteroids) {
titaniumCount++;
}
}
if (stats.getSavedSpeed() == 0F) {
if (titaniumCount == 4) {
float speed = player.capabilities.getWalkSpeed();
if (speed < 0.118F) {
try {
Field f = player.capabilities.getClass().getDeclaredField(GCCoreUtil.isDeobfuscated() ? "walkSpeed" : "field_75097_g");
f.setAccessible(true);
f.set(player.capabilities, 0.118F);
stats.setSavedSpeed(speed);
} catch (Exception e) {
e.printStackTrace();
}
}
}
} else if (titaniumCount < 4) {
try {
Field f = player.capabilities.getClass().getDeclaredField(GCCoreUtil.isDeobfuscated() ? "walkSpeed" : "field_75097_g");
f.setAccessible(true);
f.set(player.capabilities, stats.getSavedSpeed());
stats.setSavedSpeed(0F);
} catch (Exception e) {
e.printStackTrace();
}
}
}
stats.setLastOxygenSetupValid(stats.isOxygenSetupValid());
stats.setLastUnlockedSchematics(stats.getUnlockedSchematics());
stats.setLastOnGround(player.onGround);
}
use of micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider in project Galacticraft by micdoodle8.
the class GCPlayerHandler method checkThermalStatus.
protected void checkThermalStatus(EntityPlayerMP player, GCPlayerStats playerStats) {
if (player.world.provider instanceof IGalacticraftWorldProvider && !player.capabilities.isCreativeMode && !CompatibilityManager.isAndroid(player)) {
final ItemStack thermalPaddingHelm = playerStats.getExtendedInventory().getStackInSlot(6);
final ItemStack thermalPaddingChestplate = playerStats.getExtendedInventory().getStackInSlot(7);
final ItemStack thermalPaddingLeggings = playerStats.getExtendedInventory().getStackInSlot(8);
final ItemStack thermalPaddingBoots = playerStats.getExtendedInventory().getStackInSlot(9);
float lowestThermalStrength = 0.0F;
if (!thermalPaddingHelm.isEmpty() && !thermalPaddingChestplate.isEmpty() && !thermalPaddingLeggings.isEmpty() && !thermalPaddingBoots.isEmpty()) {
if (thermalPaddingHelm.getItem() instanceof IItemThermal) {
lowestThermalStrength += ((IItemThermal) thermalPaddingHelm.getItem()).getThermalStrength();
}
if (thermalPaddingChestplate.getItem() instanceof IItemThermal) {
lowestThermalStrength += ((IItemThermal) thermalPaddingChestplate.getItem()).getThermalStrength();
}
if (thermalPaddingLeggings.getItem() instanceof IItemThermal) {
lowestThermalStrength += ((IItemThermal) thermalPaddingLeggings.getItem()).getThermalStrength();
}
if (thermalPaddingBoots.getItem() instanceof IItemThermal) {
lowestThermalStrength += ((IItemThermal) thermalPaddingBoots.getItem()).getThermalStrength();
}
lowestThermalStrength /= 4.0F;
// It shouldn't be negative, but just in case!
lowestThermalStrength = Math.abs(lowestThermalStrength);
}
IGalacticraftWorldProvider provider = (IGalacticraftWorldProvider) player.world.provider;
float thermalLevelMod = provider.getThermalLevelModifier();
float absThermalLevelMod = Math.abs(thermalLevelMod);
if (absThermalLevelMod > 0D) {
int thermalLevelCooldownBase = Math.abs(MathHelper.floor(200 / thermalLevelMod));
int normaliseCooldown = MathHelper.floor(150 / lowestThermalStrength);
int thermalLevelTickCooldown = thermalLevelCooldownBase;
if (thermalLevelTickCooldown < 1) {
// Prevent divide by zero errors
thermalLevelTickCooldown = 1;
}
if (!thermalPaddingHelm.isEmpty() && !thermalPaddingChestplate.isEmpty() && !thermalPaddingLeggings.isEmpty() && !thermalPaddingBoots.isEmpty()) {
// If the thermal strength exceeds the dimension's thermal level mod, it can't improve the normalise
// This factor of 1.5F is chosen so that a combination of Tier 1 and Tier 2 thermal isn't enough to normalise on Venus (three Tier 2, one Tier 1 stays roughly constant)
float relativeFactor = Math.max(1.0F, absThermalLevelMod / lowestThermalStrength) / 1.5F;
normaliseCooldown = MathHelper.floor(normaliseCooldown / absThermalLevelMod * relativeFactor);
if (normaliseCooldown < 1) {
// Prevent divide by zero errors
normaliseCooldown = 1;
}
// Player is wearing all required thermal padding items
if ((player.ticksExisted - 1) % normaliseCooldown == 0) {
this.normaliseThermalLevel(player, playerStats, 1);
}
thermalLevelMod /= Math.max(1.0F, lowestThermalStrength / 2.0F);
absThermalLevelMod = Math.abs(thermalLevelMod);
}
if (OxygenUtil.isAABBInBreathableAirBlock(player, true)) {
playerStats.setThermalLevelNormalising(true);
this.normaliseThermalLevel(player, playerStats, 1);
// If player is in ambient thermal area, slowly reset to normal
return;
}
// For each piece of thermal equipment being used, slow down the the harmful thermal change slightly
if (!thermalPaddingHelm.isEmpty()) {
thermalLevelTickCooldown += thermalLevelCooldownBase;
}
if (!thermalPaddingChestplate.isEmpty()) {
thermalLevelTickCooldown += thermalLevelCooldownBase;
}
if (!thermalPaddingLeggings.isEmpty()) {
thermalLevelTickCooldown += thermalLevelCooldownBase;
}
if (!thermalPaddingBoots.isEmpty()) {
thermalLevelTickCooldown += thermalLevelCooldownBase;
}
// Instead of increasing/decreasing the thermal level by a large amount every ~200 ticks, increase/decrease
// by a small amount each time (still the same average increase/decrease)
int thermalLevelTickCooldownSingle = MathHelper.floor(thermalLevelTickCooldown / absThermalLevelMod);
if (thermalLevelTickCooldownSingle < 1) {
// Prevent divide by zero errors
thermalLevelTickCooldownSingle = 1;
}
if ((player.ticksExisted - 1) % thermalLevelTickCooldownSingle == 0) {
int last = playerStats.getThermalLevel();
playerStats.setThermalLevel((int) Math.min(Math.max(last + (thermalLevelMod < 0 ? -1 : 1), -22), 22));
if (playerStats.getThermalLevel() != last) {
this.sendThermalLevelPacket(player, playerStats);
}
}
// If the normalisation is outpacing the freeze/overheat
playerStats.setThermalLevelNormalising(thermalLevelTickCooldownSingle > normaliseCooldown && !thermalPaddingHelm.isEmpty() && !thermalPaddingChestplate.isEmpty() && !thermalPaddingLeggings.isEmpty() && !thermalPaddingBoots.isEmpty());
if (!playerStats.isThermalLevelNormalising()) {
if ((player.ticksExisted - 1) % thermalLevelTickCooldown == 0) {
if (Math.abs(playerStats.getThermalLevel()) >= 22) {
player.attackEntityFrom(DamageSourceGC.thermal, 1.5F);
}
}
if (playerStats.getThermalLevel() < -15) {
player.addPotionEffect(new PotionEffect(MobEffects.SLOWNESS, 5, 2, true, true));
}
if (playerStats.getThermalLevel() > 15) {
player.addPotionEffect(new PotionEffect(MobEffects.NAUSEA, 5, 2, true, true));
}
}
} else // Normalise thermal level if on Space Station or non-modifier planet
{
playerStats.setThermalLevelNormalising(true);
this.normaliseThermalLevel(player, playerStats, 2);
}
} else // Normalise thermal level if on Overworld or any non-GC dimension
{
playerStats.setThermalLevelNormalising(true);
this.normaliseThermalLevel(player, playerStats, 3);
}
}
Aggregations