diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d69f42..192660b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,15 @@ [Added] - - command /leaverace to leave GC SpaceRace team - (Team owners cannot use command) + - Ability to unlock Rocket Schematics via Configs - - Feature to fix planet/star Icon sizes when using AsmodeusCore celestial map \ No newline at end of file + - Dimensional-Comets Spawn Rate can be modified per dimension via Configs + + - Custom Spawn Dimension can be set via Configs + + - New Version checking system + + +[Changed] + + - Overworld-Comets merged into Dimensional-Comets \ No newline at end of file diff --git a/build.gradle b/build.gradle index e601073..103f942 100644 --- a/build.gradle +++ b/build.gradle @@ -67,7 +67,11 @@ jacocoTestReport { } repositories { - jcenter() + maven { + // Location of CurseAPI Files + url "https://jitpack.io" + } + mavenCentral() maven { name 'MJRLegends' url = "https://maven.mjrlegends.com/" @@ -87,19 +91,17 @@ repositories { maven { url = "https://www.cursemaven.com" } - maven { - // Location of CurseAPI Files - url "https://jitpack.io" - } + } dependencies { - - compile "com.vdurmont:semver4j:3.1.0" - - compile("com.github.TheRandomLabs:CurseAPI:master-SNAPSHOT"){ - exclude group: 'com.google.guava', module: 'guava' + + compile("com.github.TheRandomLabs:CurseAPI:master-SNAPSHOT"){ + exclude group: 'com.google.guava', module: 'guava' } + + compile "org.apache.logging.log4j:log4j-core:2.13.3" + compile "org.apache.logging.log4j:log4j-slf4j18-impl:2.13.3" compile "org.projectlombok:lombok:1.18.12" apt "org.projectlombok:lombok:1.18.12" @@ -108,7 +110,7 @@ dependencies { // LOAD GC ADDONS compile "com.mjr.planetprogression:PlanetProgression:1.12.2-0.4.5:api" - compile "curse.maven:AsmodeusCore-Dev:3039768" + compile "curse.maven:AsmodeusCore-Dev:3063158" compile "curse.maven:GSMod-0.0.14:3015062" compile "curse.maven:ExtraPlanets-1.7.0:3031689" runtime "curse.maven:MJRLib-1.2.0:3029769" @@ -128,6 +130,25 @@ minecraft { replaceIn "Ref.java" } +processResources { + inputs.property "version", project.version + inputs.property "mcversion", project.minecraft.version + from(sourceSets.main.resources.srcDirs) { + include 'mcmod.info' + expand 'version':project.version, 'mcversion':project.minecraft.version + } + from(sourceSets.main.resources.srcDirs) { + exclude 'mcmod.info' + } + rename '(.+_at.cfg)', 'META-INF/$1' +} + +jar { + manifest { + attributes 'FMLAT': 'galactictweaks_at.cfg' + } + } + jar { manifest { mainAttributes( diff --git a/gradle.properties b/gradle.properties index ffe2fd6..7f61594 100644 --- a/gradle.properties +++ b/gradle.properties @@ -15,7 +15,7 @@ mcp=snapshot_20171003 ## Mod Versioning versionMajor=1 -versionMinor=2 +versionMinor=3 versionRev=0 ## Cureforge Upload Configs diff --git a/src/main/java/net/rom/gctweaks/base/version/DownloadUpdate.java b/src/main/java/net/rom/gctweaks/base/version/DownloadUpdate.java deleted file mode 100644 index afa8503..0000000 --- a/src/main/java/net/rom/gctweaks/base/version/DownloadUpdate.java +++ /dev/null @@ -1,77 +0,0 @@ -package net.rom.gctweaks.base.version; - -import java.awt.Desktop; -import java.io.File; -import java.io.IOException; -import java.nio.file.Path; -import java.util.Optional; - -import com.therandomlabs.curseapi.CurseAPI; -import com.therandomlabs.curseapi.CurseException; -import com.therandomlabs.curseapi.project.CurseProject; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.resources.I18n; -import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.Style; -import net.minecraft.util.text.TextComponentTranslation; -import net.minecraft.util.text.TextFormatting; - -public class DownloadUpdate { - - private final String fileId; - private final int PROJECT = 359766; - private final CurseProject proj; - - public DownloadUpdate(String fileId) throws CurseException { - - final Optional project = CurseAPI.project(PROJECT); - proj = project.get(); - this.fileId = fileId; - - run(); - } - - public void run () { - String fileName = null; - try { - fileName = proj.files().fileWithID(Integer.parseInt(fileId)).displayName(); - } - catch (NumberFormatException | CurseException e) { - e.printStackTrace(); - } - - ITextComponent component = ITextComponent.Serializer - .jsonToComponent(I18n.format("gctweaks.versions.startingDownload", fileName)); - ITextComponent component2 = ITextComponent.Serializer - .jsonToComponent(I18n.format("gctweaks.versions.startingDownload2")); - if (Minecraft.getMinecraft().player != null) { - - Minecraft.getMinecraft().player.sendMessage(component); - Minecraft.getMinecraft().player.sendMessage(component2); - } - - VersionChecker.startedDownload = true; - - Path dir = new File(Minecraft.getMinecraft().mcDataDir, "mods").toPath(); - try { - proj.files().fileWithID(Integer.parseInt(fileId)).downloadToDirectory(dir); - } - catch (NumberFormatException | CurseException e) { - e.printStackTrace(); - } - - if (Minecraft.getMinecraft().player != null) - Minecraft.getMinecraft().player - .sendMessage(new TextComponentTranslation("gctweaks.versions.doneDownloading", fileName) - .setStyle(new Style().setColor(TextFormatting.GREEN))); - - try { - Desktop.getDesktop().open(dir.toFile()); - } - catch (IOException e) { - e.printStackTrace(); - } - VersionChecker.downloadedFile = true; - } -} diff --git a/src/main/java/net/rom/gctweaks/base/version/ThreadVersionChecker.java b/src/main/java/net/rom/gctweaks/base/version/ThreadVersionChecker.java deleted file mode 100644 index e7d6892..0000000 --- a/src/main/java/net/rom/gctweaks/base/version/ThreadVersionChecker.java +++ /dev/null @@ -1,37 +0,0 @@ -package net.rom.gctweaks.base.version; - -import java.io.BufferedReader; -import java.io.InputStreamReader; -import java.net.URL; - -import net.minecraftforge.common.MinecraftForge; -import net.rom.gctweaks.Ref; - -public class ThreadVersionChecker extends Thread { - - public ThreadVersionChecker() { - setName("Version Checker Thread"); - setDaemon(true); - start(); - } - - @Override - public void run () { - try { - URL url = new URL("https://raw.githubusercontent.com/ReadOnly-Mods/ReadOnly-Versions/master/" - + MinecraftForge.MC_VERSION + ".txt"); - BufferedReader r = new BufferedReader(new InputStreamReader(url.openStream())); - String line; - while ((line = r.readLine()) != null) { - if(line.contains(Ref.MOD_ID)) { - VersionChecker.onlineVersion = line; - } - } - r.close(); - } - catch (Exception e) { - e.printStackTrace(); - } - VersionChecker.doneChecking = true; - } -} diff --git a/src/main/java/net/rom/gctweaks/gc/GalacticraftModule.java b/src/main/java/net/rom/gctweaks/gc/GalacticraftModule.java deleted file mode 100644 index 713630e..0000000 --- a/src/main/java/net/rom/gctweaks/gc/GalacticraftModule.java +++ /dev/null @@ -1,30 +0,0 @@ -package net.rom.gctweaks.gc; - -import net.rom.gctweaks.base.Module; -import net.rom.gctweaks.gc.features.CompressorFixes; -import net.rom.gctweaks.gc.features.FixAsmodeusMapIcons; -import net.rom.gctweaks.gc.features.MobsBreatheInSpace; -import net.rom.gctweaks.gc.features.NoSpaceMusic; -import net.rom.gctweaks.gc.features.OverworldComets; -import net.rom.gctweaks.gc.features.galaxyfeature.SeperateAddonPlanets; -import net.rom.gctweaks.gc.features.oxygenfeature.SpawnWithOxygenEquip; -import net.rom.gctweaks.gc.features.sprfeature.SpaceRaceFeature; - -public class GalacticraftModule extends Module { - - public GalacticraftModule(String name) { - super(name); - } - - @Override - public void addFeatures() { - registerFeature(new MobsBreatheInSpace()); - registerFeature(new SpawnWithOxygenEquip()); - registerFeature(new NoSpaceMusic()); - registerFeature(new CompressorFixes()); - registerFeature(new OverworldComets()); - registerFeature(new SeperateAddonPlanets()); - registerFeature(new SpaceRaceFeature()); - registerFeature(new FixAsmodeusMapIcons()); - } -} diff --git a/src/main/java/net/rom/gctweaks/gc/features/OverworldComets.java b/src/main/java/net/rom/gctweaks/gc/features/OverworldComets.java deleted file mode 100644 index 66bf3f8..0000000 --- a/src/main/java/net/rom/gctweaks/gc/features/OverworldComets.java +++ /dev/null @@ -1,90 +0,0 @@ -package net.rom.gctweaks.gc.features; - -import micdoodle8.mods.galacticraft.core.entities.EntityMeteor; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.util.math.MathHelper; -import net.minecraft.world.World; -import net.minecraftforge.common.config.Configuration; -import net.minecraftforge.event.entity.living.LivingEvent; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import net.rom.gctweaks.base.Feature; - -public class OverworldComets extends Feature { - - private static boolean overworldComets; - private static double overworldCometSpawnRate; - - @Override - public String[] category() { - return new String[] {"overworld-comets"}; - } - - @Override - public String comment() { - return "have comets also drop in the overworld - extending realism even further"; - } - - @Override - public void syncConfig(Configuration config, String[] category) { - overworldComets = config - .get(category[0], "overworldComets", false, "Set to true to enable comets in the Overworld").getBoolean(); - overworldCometSpawnRate = config.get(category[0], "overworldCometSpawnRate", 1.0D, - "Set to a value between 0.0 and 0.9 to decrease meteor spawn").getDouble(); - } - - @Override - public boolean usesEvents() { - return true; - } - - @SubscribeEvent - public void entityLivingEvent(LivingEvent.LivingUpdateEvent event) { - if (overworldComets) { - final EntityLivingBase entityLiving = event.getEntityLiving(); - if (entityLiving instanceof EntityPlayerMP) { - this.onPlayerUpdate((EntityPlayerMP) entityLiving); - } - } - } - - private void onPlayerUpdate(EntityPlayerMP player) { - this.meteors(player); - } - - protected void meteors(EntityPlayerMP player) { - World world = player.world; - if (world.provider.getDimensionType().getId() == 0) { - final int f = (int) ((int) 5D * 750D * (1.0 / overworldCometSpawnRate)); - int e = world.rand.nextInt(f); - if (e < 3) { - 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); -// String pos = meteor.getPosition().toString().replace("[BlockPos{", "[").replace("}]", "]"); -// String[] msg = { "[DEBUG] ", "Meteor has spawned at ", pos}; -// Utilz.sendColorizedMulti(closestPlayer, msg); - } - } - } - } - } -} diff --git a/src/main/java/net/romvoid95/api/versioning/Version.java b/src/main/java/net/romvoid95/api/versioning/Version.java new file mode 100644 index 0000000..802994b --- /dev/null +++ b/src/main/java/net/romvoid95/api/versioning/Version.java @@ -0,0 +1,647 @@ +package net.romvoid95.api.versioning; + +import java.util.Objects; + +public class Version implements Comparable { + + private final String originalValue; + private final String value; + private final Integer major; + private final Integer minor; + private final Integer patch; + private final String[] suffixTokens; + private final String build; + // private final String mcVersion; + // private final String majorMod; + // private final String majorApi; + // private final String mcMinor; + // private final String mcPatch; + private final VersionType type; + + public Version(String value) { + this(value, VersionType.STRICT); + } + + public Version(String value, VersionType type) { + this.originalValue = value; + this.type = type; + value = value.trim(); + + this.value = value; + String[] tokens; + + if (hasPreRelease(value)) { + tokens = value.split("-", 2); + } + else { + tokens = new String[] { value }; + } + + String build = null; + Integer minor = null; + Integer patch = null; + try { + String[] mainTokens; + if (tokens.length == 1) { + // The build version may be in the main tokens + if (tokens[0].endsWith("+")) { + throw new VersionException("The build cannot be empty."); + } + String[] tmp = tokens[0].split("\\+"); + mainTokens = tmp[0].split("\\."); + if (tmp.length == 2) { + build = tmp[1]; + } + } + else { + mainTokens = tokens[0].split("\\."); + } + + try { + this.major = Integer.valueOf(mainTokens[0]); + } + catch (NumberFormatException e) { + throw new VersionException("Invalid version (no major version): " + value); + } + catch (IndexOutOfBoundsException e) { + throw new VersionException("Invalid version (no major version): " + value); + } + + try { + minor = Integer.valueOf(mainTokens[1]); + } + catch (IndexOutOfBoundsException e) { + if (type == VersionType.STRICT) { + throw new VersionException("Invalid version (no minor version): " + value); + } + } + try { + patch = Integer.valueOf(mainTokens[2]); + } + catch (IndexOutOfBoundsException e) { + if (type == VersionType.STRICT) { + throw new VersionException("Invalid version (no patch version): " + value); + } + } + } + catch (NumberFormatException e) { + throw new VersionException("The version is invalid: " + value); + } + catch (IndexOutOfBoundsException e) { + throw new VersionException("The version is invalid: " + value); + } + this.minor = minor; + this.patch = patch; + + String[] suffix = new String[0]; + try { + // The build version may be in the suffix tokens + if (tokens[1].endsWith("+")) { + throw new VersionException("The build cannot be empty."); + } + String[] tmp = tokens[1].split("\\+"); + if (tmp.length == 2) { + suffix = tmp[0].split("\\."); + build = tmp[1]; + } + else { + suffix = tokens[1].split("\\."); + } + } + catch (IndexOutOfBoundsException ignored) {} + this.suffixTokens = suffix; + + this.build = build; + + this.validate(type); + } + + private void validate (VersionType type) { + if (this.minor == null && type == VersionType.STRICT) { + throw new VersionException("Invalid version (no minor version): " + value); + } + if (this.patch == null && type == VersionType.STRICT) { + throw new VersionException("Invalid version (no patch version): " + value); + } + } + + private boolean hasPreRelease (String version) { + + int firstIndexOfPlus = value.indexOf("+"); + int firstIndexOfHyphen = value.indexOf("-"); + + if (firstIndexOfHyphen == -1) { + return false; + } + + return firstIndexOfPlus == -1 || firstIndexOfHyphen < firstIndexOfPlus; + } + + /** + * @see #isGreaterThan(Version) + * + * @param version the version to compare + * + * @return true if the current version is greater than the provided version + */ + public boolean isGreaterThan (String version) { + return this.isGreaterThan(new Version(version, this.getType())); + } + + /** + * Checks if the version is greater than another version + * + * @param version the version to compare + * + * @return true if the current version is greater than the provided version + */ + public boolean isGreaterThan (Version version) { + // Compare the main part + if (this.getMajor() > version.getMajor()) + return true; + else if (this.getMajor() < version.getMajor()) + return false; + + int otherMinor = version.getMinor() != null ? version.getMinor() : 0; + if (this.getMinor() != null && this.getMinor() > otherMinor) + return true; + else if (this.getMinor() != null && this.getMinor() < otherMinor) + return false; + + int otherPatch = version.getPatch() != null ? version.getPatch() : 0; + if (this.getPatch() != null && this.getPatch() > otherPatch) + return true; + else if (this.getPatch() != null && this.getPatch() < otherPatch) + return false; + + // Let's take a look at the suffix + String[] tokens1 = this.getSuffixTokens(); + String[] tokens2 = version.getSuffixTokens(); + + // If one of the versions has no suffix, it's greater! + if (tokens1.length == 0 && tokens2.length > 0) + return true; + if (tokens2.length == 0 && tokens1.length > 0) + return false; + + // Let's see if one of suffixes is greater than the other + int i = 0; + while (i < tokens1.length && i < tokens2.length) { + int cmp; + try { + // Trying to resolve the suffix part with an integer + int t1 = Integer.valueOf(tokens1[i]); + int t2 = Integer.valueOf(tokens2[i]); + cmp = t1 - t2; + } + catch (NumberFormatException e) { + // Else, do a string comparison + cmp = tokens1[i].compareToIgnoreCase(tokens2[i]); + } + if (cmp < 0) + return false; + else if (cmp > 0) + return true; + i++; + } + + // If one of the versions has some remaining suffixes, it's greater + return tokens1.length > tokens2.length; + } + + /** + * @see #isGreaterThanOrEqualTo(Version) + * + * @param version the version to compare + * + * @return true if the current version is greater than or equal to the provided version + */ + public boolean isGreaterThanOrEqualTo (String version) { + return this.isGreaterThanOrEqualTo(new Version(version, this.type)); + } + + /** + * Checks if the version is greater than or equal to another version + * + * @param version the version to compare + * + * @return true if the current version is greater than or equal to the provided version + */ + public boolean isGreaterThanOrEqualTo (Version version) { + return this.isGreaterThan(version) || this.isEquivalentTo(version); + } + + /** + * @see #isLowerThan(Version) + * + * @param version the version to compare + * + * @return true if the current version is lower than the provided version + */ + public boolean isLowerThan (String version) { + return this.isLowerThan(new Version(version, this.type)); + } + + /** + * Checks if the version is lower than another version + * + * @param version the version to compare + * + * @return true if the current version is lower than the provided version + */ + public boolean isLowerThan (Version version) { + return !this.isGreaterThan(version) && !this.isEquivalentTo(version); + } + + /** + * @see #isLowerThanOrEqualTo(Version) + * + * @param version the version to compare + * + * @return true if the current version is lower than or equal to the provided version + */ + public boolean isLowerThanOrEqualTo (String version) { + return this.isLowerThanOrEqualTo(new Version(version, this.type)); + } + + /** + * Checks if the version is lower than or equal to another version + * + * @param version the version to compare + * + * @return true if the current version is lower than or equal to the provided version + */ + public boolean isLowerThanOrEqualTo (Version version) { + return !this.isGreaterThan(version); + } + + /** + * @see #isEquivalentTo(Version) + * + * @param version the version to compare + * + * @return true if the current version equals the provided version (build excluded) + */ + public boolean isEquivalentTo (String version) { + return this.isEquivalentTo(new Version(version, this.type)); + } + + /** + * Checks if the version equals another version, without taking the build into account. + * + * @param version the version to compare + * + * @return true if the current version equals the provided version (build excluded) + */ + public boolean isEquivalentTo (Version version) { + // Get versions without build + Version sem1 = this.getBuild() == null ? this : new Version(this.getValue().replace("+" + this.getBuild(), "")); + Version sem2 = version.getBuild() == null ? version + : new Version(version.getValue().replace("+" + version.getBuild(), "")); + // Compare those new versions + return sem1.isEqualTo(sem2); + } + + /** + * @see #isEqualTo(Version) + * + * @param version the version to compare + * + * @return true if the current version equals the provided version + */ + public boolean isEqualTo (String version) { + return this.isEqualTo(new Version(version, this.type)); + } + + /** + * Checks if the version equals another version + * + * @param version the version to compare + * + * @return true if the current version equals the provided version + */ + public boolean isEqualTo (Version version) { + return this.equals(version); + } + + /** + * Determines if the current version is stable or not. + * Stable version have a major version number strictly positive and no suffix tokens. + * + * @return true if the current version is stable + */ + public boolean isStable () { + return (this.getMajor() != null && this.getMajor() > 0) + && (this.getSuffixTokens() == null || this.getSuffixTokens().length == 0); + } + + /** + * @see #diff(Version) + * + * @param version the version to compare + * + * @return the greatest difference + */ + public GenericVersionDiff diff (String version) { + return this.diff(new Version(version, this.type)); + } + + /** + * Returns the greatest difference between 2 versions. + * For example, if the current version is "1.2.3" and compared version is "1.3.0", the biggest difference + * is the 'MINOR' number. + * + * @param version the version to compare + * + * @return the greatest difference + */ + public GenericVersionDiff diff (Version version) { + if (!Objects.equals(this.major, version.getMajor())) + return GenericVersionDiff.MAJOR; + if (!Objects.equals(this.minor, version.getMinor())) + return GenericVersionDiff.MINOR; + if (!Objects.equals(this.patch, version.getPatch())) + return GenericVersionDiff.PATCH; + if (!areSameSuffixes(version.getSuffixTokens())) + return GenericVersionDiff.SUFFIX; + if (!Objects.equals(this.build, version.getBuild())) + return GenericVersionDiff.BUILD; + return GenericVersionDiff.NONE; + } + + private boolean areSameSuffixes (String[] suffixTokens) { + if (this.suffixTokens == null && suffixTokens == null) + return true; + else if (this.suffixTokens == null || suffixTokens == null) + return false; + else if (this.suffixTokens.length != suffixTokens.length) + return false; + for (int i = 0; i < this.suffixTokens.length; i++) { + if (!this.suffixTokens[i].equals(suffixTokens[i])) + return false; + } + return true; + } + + public Version toStrict () { + Integer minor = this.minor != null ? this.minor : 0; + Integer patch = this.patch != null ? this.patch : 0; + return Version.create(VersionType.STRICT, this.major, minor, patch, this.suffixTokens, this.build); + } + + public Version withIncMajor () { + return this.withIncMajor(1); + } + + public Version withIncMajor (int increment) { + return this.withInc(increment, 0, 0); + } + + public Version withIncMinor () { + return this.withIncMinor(1); + } + + public Version withIncMinor (int increment) { + return this.withInc(0, increment, 0); + } + + public Version withIncPatch () { + return this.withIncPatch(1); + } + + public Version withIncPatch (int increment) { + return this.withInc(0, 0, increment); + } + + private Version withInc (int majorInc, int minorInc, int patchInc) { + Integer minor = this.minor; + Integer patch = this.patch; + if (this.minor != null) { + minor += minorInc; + } + if (this.patch != null) { + patch += patchInc; + } + return with(this.major + majorInc, minor, patch, true, true); + } + + public Version withClearedSuffix () { + return with(this.major, this.minor, this.patch, false, true); + } + + public Version withClearedBuild () { + return with(this.major, this.minor, this.patch, true, false); + } + + public Version withClearedSuffixAndBuild () { + return with(this.major, this.minor, this.patch, false, false); + } + + public Version withSuffix (String suffix) { + return with(this.major, this.minor, this.patch, suffix.split("\\."), this.build); + } + + public Version withBuild (String build) { + return with(this.major, this.minor, this.patch, this.suffixTokens, build); + } + + public Version nextMajor () { + return with(this.major + 1, 0, 0, false, false); + } + + public Version nextMinor () { + return with(this.major, this.minor + 1, 0, false, false); + } + + public Version nextPatch () { + return with(this.major, this.minor, this.patch + 1, false, false); + } + + private Version with (int major, Integer minor, Integer patch, boolean suffix, boolean build) { + minor = this.minor != null ? minor : null; + patch = this.patch != null ? patch : null; + String buildStr = build ? this.build : null; + String[] suffixTokens = suffix ? this.suffixTokens : null; + return Version.create(this.type, major, minor, patch, suffixTokens, buildStr); + } + + private Version with (int major, Integer minor, Integer patch, String[] suffixTokens, String build) { + minor = this.minor != null ? minor : null; + patch = this.patch != null ? patch : null; + return Version.create(this.type, major, minor, patch, suffixTokens, build); + } + + private static Version create (VersionType type, int major, Integer minor, Integer patch, String[] suffix, String build) { + StringBuilder sb = new StringBuilder().append(major); + if (minor != null) { + sb.append(".").append(minor); + } + if (patch != null) { + sb.append(".").append(patch); + } + if (suffix != null) { + boolean first = true; + for (String suffixToken : suffix) { + if (first) { + sb.append("-"); + first = false; + } + else { + sb.append("."); + } + sb.append(suffixToken); + } + } + if (build != null) { + sb.append("+").append(build); + } + + return new Version(sb.toString(), type); + } + + @Override + public boolean equals (Object o) { + if (this == o) + return true; + if (!(o instanceof Version)) + return false; + Version version = (Version) o; + return value.equals(version.value); + } + + @Override + public int hashCode () { + return value.hashCode(); + } + + @Override + public int compareTo (Version version) { + if (this.isGreaterThan(version)) + return 1; + else if (this.isLowerThan(version)) + return -1; + return 0; + } + + @Override + public String toString () { + return this.getValue(); + } + + /** + * Get the original value as a string + * + * @return the original string passed in the constructor + */ + public String getOriginalValue () { + return originalValue; + } + + /** + * Returns the version as a String + * + * @return the version as a String + */ + public String getValue () { + return value; + } + + /** + * Returns the major part of the version. + * Example: for "1.2.3" = 1 + * + * @return the major part of the version + */ + public Integer getMajor () { + return this.major; + } + + /** + * Returns the minor part of the version. + * Example: for "1.2.3" = 2 + * + * @return the minor part of the version + */ + public Integer getMinor () { + return this.minor; + } + + /** + * Returns the patch part of the version. + * Example: for "1.2.3" = 3 + * + * @return the patch part of the version + */ + public Integer getPatch () { + return this.patch; + } + + /** + * Returns the suffix of the version. + * Example: for "1.2.3-beta.4+sha98450956" = {"beta", "4"} + * + * @return the suffix of the version + */ + public String[] getSuffixTokens () { + return suffixTokens; + } + + /** + * Returns the build of the version. + * Example: for "1.2.3-beta.4+sha98450956" = "sha98450956" + * + * @return the build of the version + */ + public String getBuild () { + return build; + } + + public VersionType getType () { + return type; + } + + /** + * The types of diffs between two versions. + */ + public enum GenericVersionDiff { + NONE, + MAJOR, + MINOR, + PATCH, + SUFFIX, + BUILD + } + + public enum McVersionDiff { + MCVERSION, + MAJORMOD, + MAJORAPI, + MINOR, + PATCH + } + + /** + * The different types of supported version systems. + */ + public enum VersionType { + /** + * The default type of version. + * Major, minor and patch parts are required. + * Suffixes and build are optional. + */ + STRICT, + + /** + * Major part is required. + * Minor, patch, suffixes and build are optional. + */ + LOOSE, + + /** + * Follows the (simi-strict) Minecraft Versioning. + * See https://mcforge.readthedocs.io/en/latest/conventions/versioning/ + */ + MC + } + +} diff --git a/src/main/java/net/romvoid95/api/versioning/VersionException.java b/src/main/java/net/romvoid95/api/versioning/VersionException.java new file mode 100644 index 0000000..daeefc6 --- /dev/null +++ b/src/main/java/net/romvoid95/api/versioning/VersionException.java @@ -0,0 +1,14 @@ +package net.romvoid95.api.versioning; + +public class VersionException extends RuntimeException { + + private static final long serialVersionUID = 3380584011358917827L; + + public VersionException(String msg) { + super(msg); + } + + public VersionException(String msg, Throwable t) { + super(msg, t); + } +} diff --git a/src/main/java/net/rom/gctweaks/GalacticTweaks.java b/src/main/java/net/romvoid95/gctweaks/GalacticTweaks.java similarity index 63% rename from src/main/java/net/rom/gctweaks/GalacticTweaks.java rename to src/main/java/net/romvoid95/gctweaks/GalacticTweaks.java index e8954dc..2633029 100644 --- a/src/main/java/net/rom/gctweaks/GalacticTweaks.java +++ b/src/main/java/net/romvoid95/gctweaks/GalacticTweaks.java @@ -1,5 +1,6 @@ -package net.rom.gctweaks; +package net.romvoid95.gctweaks; +import java.io.File; import java.util.Map; import net.minecraftforge.common.MinecraftForge; @@ -7,77 +8,78 @@ import net.minecraftforge.fml.common.Mod.EventHandler; import net.minecraftforge.fml.common.Mod.Instance; import net.minecraftforge.fml.common.SidedProxy; -import net.minecraftforge.fml.common.event.FMLFingerprintViolationEvent; -import net.minecraftforge.fml.common.event.FMLInitializationEvent; -import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; -import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; -import net.minecraftforge.fml.common.event.FMLServerStartingEvent; +import net.minecraftforge.fml.common.event.*; import net.minecraftforge.fml.common.network.NetworkCheckHandler; import net.minecraftforge.fml.common.network.NetworkRegistry; import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper; import net.minecraftforge.fml.relauncher.Side; -import net.rom.gctweaks.base.InternalModule; -import net.rom.gctweaks.base.Module; -import net.rom.gctweaks.base.core.proxy.CommonProxy; -import net.rom.gctweaks.base.core.utils.GameUtil; -import net.rom.gctweaks.base.core.utils.I18nHelper; -import net.rom.gctweaks.base.core.utils.LogHelper; -import net.rom.gctweaks.base.version.CommandDownloadUpdate; + +import net.romvoid95.gctweaks.base.InternalModule; +import net.romvoid95.gctweaks.base.Module; +import net.romvoid95.gctweaks.base.core.proxy.CommonProxy; +import net.romvoid95.gctweaks.base.core.utils.*; +//import net.romvoid95.gctweaks.base.version.CommandDownloadUpdate; +import net.romvoid95.gctweaks.internal.command.DownloadCommand; +import net.romvoid95.gctweaks.internal.config.ConfigCore; @Mod(modid = Ref.MOD_ID, name = Ref.MOD_NAME, version = Ref.MOD_VERSION, dependencies = Ref.DEPS, certificateFingerprint = Ref.MOD_FINGERPRINT, useMetadata = true) public class GalacticTweaks { @Instance(Ref.MOD_ID) - public static GalacticTweaks instance; - public static SimpleNetworkWrapper network = NetworkRegistry.INSTANCE.newSimpleChannel(Ref.MOD_ID); - public static LogHelper logger = new LogHelper(); - public static I18nHelper stringz = new I18nHelper(Ref.MOD_ID, logger, false); + public static GalacticTweaks instance; + public static SimpleNetworkWrapper network = NetworkRegistry.INSTANCE.newSimpleChannel(Ref.MOD_ID); + public static LogHelper logger = new LogHelper(); + public static I18nHelper stringz = new I18nHelper(Ref.MOD_ID, logger, false); + public static File modFolder = null; @NetworkCheckHandler public boolean networkCheck(Map map, Side side) { return true; } - @SidedProxy(clientSide = "net.rom.gctweaks.base.core.proxy.ClientProxy", serverSide = "net.rom.gctweaks.base.core.proxy.CommonProxy") + @SidedProxy(clientSide = "net.romvoid95.gctweaks.base.core.proxy.ClientProxy", serverSide = "net.romvoid95.gctweaks.base.core.proxy.CommonProxy") public static CommonProxy proxy; - + @EventHandler - public void onFingerprintViolation (FMLFingerprintViolationEvent event) { - if(!GameUtil.isDeobfuscated()) { + public void onFingerprintViolation(FMLFingerprintViolationEvent event) { + if (!GameUtil.isDeobfuscated()) { logger.warn("Invalid fingerprint detected! The file " + event.getSource().getName() + " may have been tampered with. This version will NOT be supported by the author!"); } else { - logger.info("Ignoring fingerprint signing since we are in a Development Enviroment"); + logger.info("Ignoring fingerprint signing since we are in a Development Environment"); } } @EventHandler public void preInit(FMLPreInitializationEvent event) { + GalacticTweaks.modFolder = event.getModConfigurationDirectory(); + MinecraftForge.EVENT_BUS.register(this); - + MinecraftForge.EVENT_BUS.register(new ConfigCore(new File(modFolder, "GalacticTweaks/core.cfg"))); + // ========================================== - // Internal Modules + // Internal Modules // ========================================== // ~ Register ~ // ModuleController.registerInternalModules(); - + // ~ Network ~ // ModuleController.internals.forEach(module -> module.registerPacket(network)); - + // ~ Phase ~ // ModuleController.internals.forEach(InternalModule::preInit); - + // ========================================== - // Feature Modules + // Feature Modules // ========================================== // ~ Register ~ // ModuleController.registerModules(); - + // ~ Configurations ~ // ModuleController.modules.forEach(module -> module.setupConfig(event)); ModuleController.modules.forEach(Module::syncConfig); - + // ~ Network ~ // ModuleController.modules.forEach(module -> module.registerPacket(network)); @@ -88,15 +90,15 @@ public void preInit(FMLPreInitializationEvent event) { @EventHandler public void init(FMLInitializationEvent event) { - + // ========================================== - // Internal Modules + // Internal Modules // ========================================== // ~ Phase ~ // ModuleController.internals.forEach(InternalModule::init); - + // ========================================== - // Feature Modules + // Feature Modules // ========================================== // ~ Phase ~ // ModuleController.modules.forEach(Module::init); @@ -105,36 +107,37 @@ public void init(FMLInitializationEvent event) { @EventHandler public void postInit(FMLPostInitializationEvent event) { - + // ========================================== - // Internal Modules + // Internal Modules // ========================================== // ~ Phase ~ // ModuleController.internals.forEach(InternalModule::postInit); - + // ========================================== - // Feature Modules + // Feature Modules // ========================================== // ~ Phase ~ // ModuleController.modules.forEach(Module::postInit); proxy.postInit(event); } - - @EventHandler - public void onServerStarting(FMLServerStartingEvent event) { - + + @EventHandler + public void onServerStarting(FMLServerStartingEvent event) { + // ========================================== - // Internal Modules + // Internal Modules // ========================================== // ~ Phase ~ // - ModuleController.internals.forEach(internal -> internal.serverStartingEvent(event)); - + ModuleController.internals.forEach(internal -> internal.serverStartingEvent(event)); + // ========================================== - // Feature Modules + // Feature Modules // ========================================== // ~ Phase ~ // - ModuleController.modules.forEach(module -> module.serverStartingEvent(event)); - - event.registerServerCommand(new CommandDownloadUpdate()); - } + ModuleController.modules.forEach(module -> module.serverStartingEvent(event)); + + if (ConfigCore.enableCheckVersion) + event.registerServerCommand(new DownloadCommand()); + } } diff --git a/src/main/java/net/rom/gctweaks/ModuleController.java b/src/main/java/net/romvoid95/gctweaks/ModuleController.java similarity index 65% rename from src/main/java/net/rom/gctweaks/ModuleController.java rename to src/main/java/net/romvoid95/gctweaks/ModuleController.java index 44f357d..34af507 100644 --- a/src/main/java/net/rom/gctweaks/ModuleController.java +++ b/src/main/java/net/romvoid95/gctweaks/ModuleController.java @@ -1,18 +1,18 @@ -package net.rom.gctweaks; +package net.romvoid95.gctweaks; import java.util.ArrayList; import java.util.List; -import net.rom.gctweaks.base.InternalModule; -import net.rom.gctweaks.base.Module; -import net.rom.gctweaks.gc.GalacticraftModule; -import net.rom.gctweaks.internal.BuiltInModule; +import net.romvoid95.gctweaks.base.InternalModule; +import net.romvoid95.gctweaks.base.Module; +import net.romvoid95.gctweaks.gc.GalacticraftModule; +import net.romvoid95.gctweaks.internal.BuiltInModule; public class ModuleController { public static List modules = new ArrayList<>(); - public static List internals = new ArrayList<>(); + public static void registerModules() { modules.add(new GalacticraftModule("Galacticraft Module")); diff --git a/src/main/java/net/rom/gctweaks/Ref.java b/src/main/java/net/romvoid95/gctweaks/Ref.java similarity index 84% rename from src/main/java/net/rom/gctweaks/Ref.java rename to src/main/java/net/romvoid95/gctweaks/Ref.java index a891430..44b4540 100644 --- a/src/main/java/net/rom/gctweaks/Ref.java +++ b/src/main/java/net/romvoid95/gctweaks/Ref.java @@ -1,4 +1,4 @@ -package net.rom.gctweaks; +package net.romvoid95.gctweaks; public class Ref { @@ -24,5 +24,9 @@ public class Ref { // Dependencies public static final String DEPS = "required:forge@[" + MOD_FORGE_VERSION_MIN + ",);" + MOD_GC + ";" + OPTS; + + // CORE CONFIG + public static final String CATEGORY_CORE = "Core Mod Settings"; + public static final String CATEGORY_CORE_LANGKEY = "galactictweaks.configgui.category.core"; } diff --git a/src/main/java/net/rom/gctweaks/base/Feature.java b/src/main/java/net/romvoid95/gctweaks/base/Feature.java similarity index 95% rename from src/main/java/net/rom/gctweaks/base/Feature.java rename to src/main/java/net/romvoid95/gctweaks/base/Feature.java index a0059eb..e4f0194 100644 --- a/src/main/java/net/rom/gctweaks/base/Feature.java +++ b/src/main/java/net/romvoid95/gctweaks/base/Feature.java @@ -1,4 +1,4 @@ -package net.rom.gctweaks.base; +package net.romvoid95.gctweaks.base; import net.minecraftforge.common.config.Configuration; import net.minecraftforge.fml.common.event.FMLServerStartingEvent; diff --git a/src/main/java/net/rom/gctweaks/base/InternalFeature.java b/src/main/java/net/romvoid95/gctweaks/base/InternalFeature.java similarity index 94% rename from src/main/java/net/rom/gctweaks/base/InternalFeature.java rename to src/main/java/net/romvoid95/gctweaks/base/InternalFeature.java index 894824a..4c26b83 100644 --- a/src/main/java/net/rom/gctweaks/base/InternalFeature.java +++ b/src/main/java/net/romvoid95/gctweaks/base/InternalFeature.java @@ -1,4 +1,4 @@ -package net.rom.gctweaks.base; +package net.romvoid95.gctweaks.base; import net.minecraftforge.fml.common.event.FMLServerStartingEvent; import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper; diff --git a/src/main/java/net/rom/gctweaks/base/InternalModule.java b/src/main/java/net/romvoid95/gctweaks/base/InternalModule.java similarity index 97% rename from src/main/java/net/rom/gctweaks/base/InternalModule.java rename to src/main/java/net/romvoid95/gctweaks/base/InternalModule.java index 3161aa2..2da699d 100644 --- a/src/main/java/net/rom/gctweaks/base/InternalModule.java +++ b/src/main/java/net/romvoid95/gctweaks/base/InternalModule.java @@ -1,4 +1,4 @@ -package net.rom.gctweaks.base; +package net.romvoid95.gctweaks.base; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/net/rom/gctweaks/base/Module.java b/src/main/java/net/romvoid95/gctweaks/base/Module.java similarity index 93% rename from src/main/java/net/rom/gctweaks/base/Module.java rename to src/main/java/net/romvoid95/gctweaks/base/Module.java index f725bc2..f3214ce 100644 --- a/src/main/java/net/rom/gctweaks/base/Module.java +++ b/src/main/java/net/romvoid95/gctweaks/base/Module.java @@ -1,4 +1,4 @@ -package net.rom.gctweaks.base; +package net.romvoid95.gctweaks.base; import java.io.File; import java.util.ArrayList; @@ -71,6 +71,9 @@ public Configuration getConfig () { return config; } + /** + * Method in every feature class. You can just specify this in a class and auto adds to GalacticTweaks.cfg + */ public void syncConfig () { features.forEach(feature -> { feature.syncConfig(config, feature.category()); diff --git a/src/main/java/net/rom/gctweaks/base/core/compat/CompatMods.java b/src/main/java/net/romvoid95/gctweaks/base/core/compat/CompatMods.java similarity index 94% rename from src/main/java/net/rom/gctweaks/base/core/compat/CompatMods.java rename to src/main/java/net/romvoid95/gctweaks/base/core/compat/CompatMods.java index 070ad72..5f4b30f 100644 --- a/src/main/java/net/rom/gctweaks/base/core/compat/CompatMods.java +++ b/src/main/java/net/romvoid95/gctweaks/base/core/compat/CompatMods.java @@ -1,4 +1,4 @@ -package net.rom.gctweaks.base.core.compat; +package net.romvoid95.gctweaks.base.core.compat; import javax.annotation.ParametersAreNonnullByDefault; diff --git a/src/main/java/net/rom/gctweaks/base/core/compat/PlanetProgressionCompat.java b/src/main/java/net/romvoid95/gctweaks/base/core/compat/PlanetProgressionCompat.java similarity index 92% rename from src/main/java/net/rom/gctweaks/base/core/compat/PlanetProgressionCompat.java rename to src/main/java/net/romvoid95/gctweaks/base/core/compat/PlanetProgressionCompat.java index 568774b..1a169bf 100644 --- a/src/main/java/net/rom/gctweaks/base/core/compat/PlanetProgressionCompat.java +++ b/src/main/java/net/romvoid95/gctweaks/base/core/compat/PlanetProgressionCompat.java @@ -1,4 +1,4 @@ -package net.rom.gctweaks.base.core.compat; +package net.romvoid95.gctweaks.base.core.compat; import com.mjr.planetprogression.api.research.ResearchHooksSP; diff --git a/src/main/java/net/rom/gctweaks/base/core/proxy/ClientProxy.java b/src/main/java/net/romvoid95/gctweaks/base/core/proxy/ClientProxy.java similarity index 53% rename from src/main/java/net/rom/gctweaks/base/core/proxy/ClientProxy.java rename to src/main/java/net/romvoid95/gctweaks/base/core/proxy/ClientProxy.java index 8fc5a03..cd62cd6 100644 --- a/src/main/java/net/rom/gctweaks/base/core/proxy/ClientProxy.java +++ b/src/main/java/net/romvoid95/gctweaks/base/core/proxy/ClientProxy.java @@ -1,11 +1,12 @@ -package net.rom.gctweaks.base.core.proxy; +package net.romvoid95.gctweaks.base.core.proxy; -import net.minecraftforge.fml.common.event.FMLInitializationEvent; -import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; -import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; -import net.rom.gctweaks.ModuleController; -import net.rom.gctweaks.base.Module; -import net.rom.gctweaks.base.version.VersionChecker; +import net.minecraftforge.fml.common.event.*; + +import net.romvoid95.gctweaks.ModuleController; +import net.romvoid95.gctweaks.base.Module; +import net.romvoid95.gctweaks.internal.config.ConfigCore; +//import net.romvoid95.gctweaks.base.version.VersionChecker; +import net.romvoid95.gctweaks.internal.versioning.VersionChecker; public class ClientProxy extends CommonProxy { @@ -18,7 +19,9 @@ public void preInit(FMLPreInitializationEvent event) { @Override public void init(FMLInitializationEvent event) { ModuleController.modules.forEach(Module::proxyInit); - VersionChecker.init(); + if (ConfigCore.enableCheckVersion) { + VersionChecker.init(); + } super.init(event); } diff --git a/src/main/java/net/rom/gctweaks/base/core/proxy/CommonProxy.java b/src/main/java/net/romvoid95/gctweaks/base/core/proxy/CommonProxy.java similarity index 92% rename from src/main/java/net/rom/gctweaks/base/core/proxy/CommonProxy.java rename to src/main/java/net/romvoid95/gctweaks/base/core/proxy/CommonProxy.java index 5abf32f..b1cc8c0 100644 --- a/src/main/java/net/rom/gctweaks/base/core/proxy/CommonProxy.java +++ b/src/main/java/net/romvoid95/gctweaks/base/core/proxy/CommonProxy.java @@ -1,4 +1,4 @@ -package net.rom.gctweaks.base.core.proxy; +package net.romvoid95.gctweaks.base.core.proxy; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.event.FMLInitializationEvent; diff --git a/src/main/java/net/rom/gctweaks/base/core/utils/GameUtil.java b/src/main/java/net/romvoid95/gctweaks/base/core/utils/GameUtil.java similarity index 78% rename from src/main/java/net/rom/gctweaks/base/core/utils/GameUtil.java rename to src/main/java/net/romvoid95/gctweaks/base/core/utils/GameUtil.java index 64c2e2c..56847c8 100644 --- a/src/main/java/net/rom/gctweaks/base/core/utils/GameUtil.java +++ b/src/main/java/net/romvoid95/gctweaks/base/core/utils/GameUtil.java @@ -1,11 +1,12 @@ -package net.rom.gctweaks.base.core.utils; +package net.romvoid95.gctweaks.base.core.utils; + +import java.io.IOException; import net.minecraft.client.Minecraft; import net.minecraft.launchwrapper.Launch; + import net.minecraftforge.fml.client.FMLClientHandler; -import net.minecraftforge.fml.common.FMLCommonHandler; -import net.minecraftforge.fml.common.Loader; -import net.minecraftforge.fml.common.LoaderState; +import net.minecraftforge.fml.common.*; public final class GameUtil { private GameUtil() { @@ -36,7 +37,12 @@ public static boolean isServer() { * @return True if and only if we are running in a deobfuscated environment */ public static boolean isDeobfuscated() { - return (Boolean) Launch.blackboard.get("fml.deobfuscatedEnvironment"); + try { + return Launch.classLoader.getClassBytes("net.minecraft.world.World") != null; + } catch (IOException e) { + e.printStackTrace(); + } + return false; } public static Minecraft getMinecraft() { @@ -56,7 +62,7 @@ public static boolean shouldCalculateTooltip() { LoaderState state = Loader.instance().getLoaderState(); // These states have no reason to go through tooltips that I can tell, but they // do. - return state != LoaderState.INITIALIZATION && state != LoaderState.SERVER_ABOUT_TO_START - && state != LoaderState.SERVER_STOPPING; + return (state != LoaderState.INITIALIZATION) && (state != LoaderState.SERVER_ABOUT_TO_START) + && (state != LoaderState.SERVER_STOPPING); } } diff --git a/src/main/java/net/rom/gctweaks/base/core/utils/I18nHelper.java b/src/main/java/net/romvoid95/gctweaks/base/core/utils/I18nHelper.java similarity index 99% rename from src/main/java/net/rom/gctweaks/base/core/utils/I18nHelper.java rename to src/main/java/net/romvoid95/gctweaks/base/core/utils/I18nHelper.java index 1ed944a..a83e837 100644 --- a/src/main/java/net/rom/gctweaks/base/core/utils/I18nHelper.java +++ b/src/main/java/net/romvoid95/gctweaks/base/core/utils/I18nHelper.java @@ -1,4 +1,4 @@ -package net.rom.gctweaks.base.core.utils; +package net.romvoid95.gctweaks.base.core.utils; import java.util.HashSet; import java.util.Locale; diff --git a/src/main/java/net/romvoid95/gctweaks/base/core/utils/ItemStackUtil.java b/src/main/java/net/romvoid95/gctweaks/base/core/utils/ItemStackUtil.java new file mode 100644 index 0000000..4bd9f93 --- /dev/null +++ b/src/main/java/net/romvoid95/gctweaks/base/core/utils/ItemStackUtil.java @@ -0,0 +1,111 @@ +package net.romvoid95.gctweaks.base.core.utils; + +import net.minecraft.block.Block; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; + +public class ItemStackUtil { + + /** + * Get ItemStack (1 item) from a block + * + * @param block + * @return + */ + public static ItemStack blockStack(Block block) { + return new ItemStack(block); + } + /** + * Get ItemStack (1 item) from a blocks meta + * + * Example: galacticraftcore:basic_block_core:4 + * + * + * ItemStack gcBlockTin = ItemStackUtil.blockStack(GCBlocks.basicblock, 4); + * + * + * @param block + * @return + */ + public static ItemStack blockStack(Block block, int meta) { + return new ItemStack(block); + } + /** + * Get ItemStack quantity from a block + * + * + * ItemStack diamondBlock = ItemStackUtil.blockStack(32, Blocks.DIAMOND_BLOCK); + * + * + * @param block + * @return + */ + public static ItemStack blockStack( int amount, Block block) { + return new ItemStack(block); + } + /** + * Get ItemStack quantity from a blocks meta + * + * + * ItemStack gcBlockTin = ItemStackUtil.blockStack(32, GCBlocks.basicblock, 4); + * + * + * @param block + * @return + */ + public static ItemStack blockStack(int amount, Block block, int meta) { + return new ItemStack(block); + } + + /** + * Get ItemStack (1 item) from an Item + * + * @param block + * @return + */ + public static ItemStack itemStack(Item item) { + return new ItemStack(item); + } + /** + * Get ItemStack (1 item) from a Items meta + * + * Example: galacticraftcore:basic_item:4 + * + * + * ItemStack gcCopperIngot = ItemStackUtil.blockStack(GCBlocks.basicItem, 4); + * + * + * @param block + * @return + */ + public static ItemStack itemStack(Item item, int meta) { + return new ItemStack(item); + } + /** + * Get ItemStack quantity from a Item + * + * + * ItemStack diamondBlock = ItemStackUtil.blockStack(32, Blocks.DIAMOND_BLOCK); + * + * + * @param block + * @return + */ + public static ItemStack itemStack( int amount, Item item) { + return new ItemStack(item); + } + /** + * Get ItemStack quantity from a Items meta + * + * + * ItemStack gcCopperIngot = ItemStackUtil.blockStack(32, GCItems.basicItem, 4); + * + * + * @param block + * @return + */ + public static ItemStack itemStack(int amount, Item item, int meta) { + return new ItemStack(item); + } + +} diff --git a/src/main/java/net/rom/gctweaks/base/core/utils/LogHelper.java b/src/main/java/net/romvoid95/gctweaks/base/core/utils/LogHelper.java similarity index 99% rename from src/main/java/net/rom/gctweaks/base/core/utils/LogHelper.java rename to src/main/java/net/romvoid95/gctweaks/base/core/utils/LogHelper.java index d25381e..897fa6e 100644 --- a/src/main/java/net/rom/gctweaks/base/core/utils/LogHelper.java +++ b/src/main/java/net/romvoid95/gctweaks/base/core/utils/LogHelper.java @@ -22,7 +22,7 @@ * THE SOFTWARE. */ -package net.rom.gctweaks.base.core.utils; +package net.romvoid95.gctweaks.base.core.utils; import java.io.IOException; @@ -31,7 +31,7 @@ import org.apache.logging.log4j.Logger; import net.minecraft.launchwrapper.Launch; -import net.rom.gctweaks.Ref; +import net.romvoid95.gctweaks.Ref; // TODO: Auto-generated Javadoc /** diff --git a/src/main/java/net/rom/gctweaks/base/core/utils/Utilz.java b/src/main/java/net/romvoid95/gctweaks/base/core/utils/Utilz.java similarity index 97% rename from src/main/java/net/rom/gctweaks/base/core/utils/Utilz.java rename to src/main/java/net/romvoid95/gctweaks/base/core/utils/Utilz.java index ffdbb1b..3909fce 100644 --- a/src/main/java/net/rom/gctweaks/base/core/utils/Utilz.java +++ b/src/main/java/net/romvoid95/gctweaks/base/core/utils/Utilz.java @@ -1,4 +1,4 @@ -package net.rom.gctweaks.base.core.utils; +package net.romvoid95.gctweaks.base.core.utils; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.text.TextComponentString; diff --git a/src/main/java/net/romvoid95/gctweaks/gc/GalacticraftModule.java b/src/main/java/net/romvoid95/gctweaks/gc/GalacticraftModule.java new file mode 100644 index 0000000..ef6cf9d --- /dev/null +++ b/src/main/java/net/romvoid95/gctweaks/gc/GalacticraftModule.java @@ -0,0 +1,31 @@ +package net.romvoid95.gctweaks.gc; + +import net.romvoid95.gctweaks.base.Module; +import net.romvoid95.gctweaks.gc.features.*; +import net.romvoid95.gctweaks.gc.features.galaxy.SeperateAddonPlanets; +import net.romvoid95.gctweaks.gc.features.oxygen.SpawnWithOxygenEquip; +import net.romvoid95.gctweaks.gc.features.schematic.UnlockSchematics; +import net.romvoid95.gctweaks.gc.features.spawndim.SpawnDimension; +import net.romvoid95.gctweaks.gc.features.spawnitems.SpaceRaceFeature; + +public class GalacticraftModule extends Module { + + public GalacticraftModule(String name) { + super(name); + } + + @Override + public void addFeatures() { + registerFeature(new MobsBreatheInSpace()); + registerFeature(new SpawnWithOxygenEquip()); + registerFeature(new NoSpaceMusic()); + registerFeature(new CompressorFixes()); + registerFeature(new SeperateAddonPlanets()); + registerFeature(new SpaceRaceFeature()); + registerFeature(new FixAsmodeusMapIcons()); + registerFeature(new DimensionalComets()); + registerFeature(new UnlockSchematics()); + registerFeature(new SpawnDimension()); + + } +} diff --git a/src/main/java/net/rom/gctweaks/gc/features/CompressorFixes.java b/src/main/java/net/romvoid95/gctweaks/gc/features/CompressorFixes.java similarity index 96% rename from src/main/java/net/rom/gctweaks/gc/features/CompressorFixes.java rename to src/main/java/net/romvoid95/gctweaks/gc/features/CompressorFixes.java index 1887d05..98f27cc 100644 --- a/src/main/java/net/rom/gctweaks/gc/features/CompressorFixes.java +++ b/src/main/java/net/romvoid95/gctweaks/gc/features/CompressorFixes.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package net.rom.gctweaks.gc.features; +package net.romvoid95.gctweaks.gc.features; import micdoodle8.mods.galacticraft.api.recipe.CompressorRecipes; import micdoodle8.mods.galacticraft.core.GCItems; @@ -23,7 +23,7 @@ import net.minecraft.item.ItemStack; import net.minecraftforge.common.config.Configuration; import net.minecraftforge.oredict.OreDictionary; -import net.rom.gctweaks.base.Feature; +import net.romvoid95.gctweaks.base.Feature; public class CompressorFixes extends Feature { diff --git a/src/main/java/net/romvoid95/gctweaks/gc/features/DimensionalComets.java b/src/main/java/net/romvoid95/gctweaks/gc/features/DimensionalComets.java new file mode 100644 index 0000000..8a0ba12 --- /dev/null +++ b/src/main/java/net/romvoid95/gctweaks/gc/features/DimensionalComets.java @@ -0,0 +1,124 @@ +package net.romvoid95.gctweaks.gc.features; + +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.util.math.MathHelper; +import net.minecraft.world.World; + +import net.minecraftforge.common.config.Configuration; +import net.minecraftforge.event.entity.living.LivingEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; + +import micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider; +import micdoodle8.mods.galacticraft.core.entities.EntityMeteor; + +import net.romvoid95.gctweaks.base.Feature; + +public class DimensionalComets extends Feature { + + private static boolean cometModification; + private static String[] dimensionID_spawnrate; + + @Override + public String[] category() { + return new String[] { "dimensional-comets" }; + } + + @Override + public String comment() { + return "You can specify where asteroids will drop via dimension IDs\nCheck GC dimension ID's here https://wiki.micdoodle8.com/wiki/Dimensions"; + } + + @Override + public void syncConfig(Configuration config, String[] category) { + cometModification = config.get(category[0], "comet-modification", false, + "Set to true to specify what new dimensions asteroids drop").getBoolean(); + dimensionID_spawnrate = config.get(category[0], "dimension-id", new String[] { "0:1.0", "1:2.0" }, + "Data consisting of which Dimensions meteors will spawn in and the spawn-rate modification value.\nSpec: (Ex: -1:3.5)").getStringList(); + } + + @Override + public boolean usesEvents() { + return true; + } + + @SubscribeEvent + public void entityLivingEvent(LivingEvent.LivingUpdateEvent event) { + if (cometModification) { + final EntityLivingBase entityLiving = event.getEntityLiving(); + if (entityLiving instanceof EntityPlayerMP) { + this.onPlayerUpdate((EntityPlayerMP) entityLiving); + } + } + } + + private void onPlayerUpdate(EntityPlayerMP player) { + for (String data : dimensionID_spawnrate) { + int dimId = Integer.parseInt(data.split(":")[0]); + double spawnRate = Double.parseDouble(data.split(":")[1]); + this.meteors(player, dimId, spawnRate); + } + } + + protected void meteors(EntityPlayerMP player, int dimensionid, double spawnRate) { + World world = player.world; + int f; + if (world.provider.getDimensionType().getId() == dimensionid && !world.isRemote) { + if (world.provider instanceof IGalacticraftWorldProvider) { + f = (int) (((IGalacticraftWorldProvider) world.provider).getMeteorFrequency() * 750D * (1.0 / spawnRate)); + } else { + f = (int) (750D * (1.0 / spawnRate)); + } + 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); + } + } + } + } + } +} diff --git a/src/main/java/net/rom/gctweaks/gc/features/FixAsmodeusMapIcons.java b/src/main/java/net/romvoid95/gctweaks/gc/features/FixAsmodeusMapIcons.java similarity index 91% rename from src/main/java/net/rom/gctweaks/gc/features/FixAsmodeusMapIcons.java rename to src/main/java/net/romvoid95/gctweaks/gc/features/FixAsmodeusMapIcons.java index 7f58010..2124d29 100644 --- a/src/main/java/net/rom/gctweaks/gc/features/FixAsmodeusMapIcons.java +++ b/src/main/java/net/romvoid95/gctweaks/gc/features/FixAsmodeusMapIcons.java @@ -1,4 +1,4 @@ -package net.rom.gctweaks.gc.features; +package net.romvoid95.gctweaks.gc.features; import java.util.Map; import java.util.Map.Entry; @@ -8,8 +8,8 @@ import micdoodle8.mods.galacticraft.api.galaxies.Planet; import micdoodle8.mods.galacticraft.api.galaxies.SolarSystem; import net.minecraftforge.common.config.Configuration; -import net.rom.gctweaks.base.Feature; -import net.rom.gctweaks.base.core.compat.CompatMods; +import net.romvoid95.gctweaks.base.Feature; +import net.romvoid95.gctweaks.base.core.compat.CompatMods; public class FixAsmodeusMapIcons extends Feature { diff --git a/src/main/java/net/rom/gctweaks/gc/features/MobsBreatheInSpace.java b/src/main/java/net/romvoid95/gctweaks/gc/features/MobsBreatheInSpace.java similarity index 79% rename from src/main/java/net/rom/gctweaks/gc/features/MobsBreatheInSpace.java rename to src/main/java/net/romvoid95/gctweaks/gc/features/MobsBreatheInSpace.java index 2d727ca..3bfebbb 100644 --- a/src/main/java/net/rom/gctweaks/gc/features/MobsBreatheInSpace.java +++ b/src/main/java/net/romvoid95/gctweaks/gc/features/MobsBreatheInSpace.java @@ -1,13 +1,13 @@ -package net.rom.gctweaks.gc.features; +package net.romvoid95.gctweaks.gc.features; import micdoodle8.mods.galacticraft.api.event.oxygen.GCCoreOxygenSuffocationEvent; import micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider; -import net.minecraft.entity.EntityLiving; -import net.minecraft.entity.EntityLivingBase; + +import net.minecraft.entity.*; import net.minecraft.entity.passive.EntityAnimal; import net.minecraftforge.common.config.Configuration; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import net.rom.gctweaks.base.Feature; +import net.romvoid95.gctweaks.base.Feature; public class MobsBreatheInSpace extends Feature { @@ -15,7 +15,7 @@ public class MobsBreatheInSpace extends Feature { @Override public String comment() { - return "Adds ability for passive mobs to beathe on other planets"; + return "Adds ability for passive mobs to breathe on other planets"; } @Override @@ -39,7 +39,7 @@ public void GCCoreOxygenSuffocationEvent(GCCoreOxygenSuffocationEvent.Pre event) if (mobsBreatheInSpace) { EntityLivingBase e = event.getEntityLiving(); if (e.world.provider instanceof IGalacticraftWorldProvider) { - if (e instanceof EntityLiving || e instanceof EntityAnimal) { + if (e instanceof EntityLiving || e instanceof EntityAnimal || e instanceof EntityCreature) { event.setCanceled(true); } } diff --git a/src/main/java/net/rom/gctweaks/gc/features/NoSpaceMusic.java b/src/main/java/net/romvoid95/gctweaks/gc/features/NoSpaceMusic.java similarity index 95% rename from src/main/java/net/rom/gctweaks/gc/features/NoSpaceMusic.java rename to src/main/java/net/romvoid95/gctweaks/gc/features/NoSpaceMusic.java index 4f440f1..abe6c77 100644 --- a/src/main/java/net/rom/gctweaks/gc/features/NoSpaceMusic.java +++ b/src/main/java/net/romvoid95/gctweaks/gc/features/NoSpaceMusic.java @@ -1,4 +1,4 @@ -package net.rom.gctweaks.gc.features; +package net.romvoid95.gctweaks.gc.features; import java.lang.reflect.Field; @@ -8,7 +8,7 @@ import net.minecraft.client.audio.MusicTicker; import net.minecraftforge.common.config.Configuration; import net.minecraftforge.fml.client.FMLClientHandler; -import net.rom.gctweaks.base.Feature; +import net.romvoid95.gctweaks.base.Feature; public class NoSpaceMusic extends Feature { diff --git a/src/main/java/net/rom/gctweaks/gc/features/galaxyfeature/GCPlanets.java b/src/main/java/net/romvoid95/gctweaks/gc/features/galaxy/GCPlanets.java similarity index 89% rename from src/main/java/net/rom/gctweaks/gc/features/galaxyfeature/GCPlanets.java rename to src/main/java/net/romvoid95/gctweaks/gc/features/galaxy/GCPlanets.java index 00e61fd..d2e9c45 100644 --- a/src/main/java/net/rom/gctweaks/gc/features/galaxyfeature/GCPlanets.java +++ b/src/main/java/net/romvoid95/gctweaks/gc/features/galaxy/GCPlanets.java @@ -1,17 +1,16 @@ -package net.rom.gctweaks.gc.features.galaxyfeature; +package net.romvoid95.gctweaks.gc.features.galaxy; import com.mjr.extraplanets.planets.ExtraPlanets_Planets; -import galaxyspace.systems.SolarSystem.SolarSystemBodies; -import micdoodle8.mods.galacticraft.api.galaxies.CelestialBody; +import net.minecraft.util.ResourceLocation; + +import micdoodle8.mods.galacticraft.api.galaxies.*; import micdoodle8.mods.galacticraft.api.galaxies.CelestialBody.ScalableDistance; -import micdoodle8.mods.galacticraft.api.galaxies.GalaxyRegistry; -import micdoodle8.mods.galacticraft.api.galaxies.Planet; -import micdoodle8.mods.galacticraft.api.galaxies.SolarSystem; import micdoodle8.mods.galacticraft.api.world.EnumAtmosphericGas; import micdoodle8.mods.galacticraft.core.GalacticraftCore; import micdoodle8.mods.galacticraft.planets.asteroids.AsteroidsModule; -import net.minecraft.util.ResourceLocation; + +import galaxyspace.systems.SolarSystem.SolarSystemBodies; public class GCPlanets { public static Planet FAKE_OVERWORLD; @@ -74,7 +73,7 @@ public static void buildFakeEarth (Planet planet, String planetName, SolarSystem planet.setRelativeSize(1.0F); planet.setBodyIcon(new ResourceLocation("galacticraftcore:textures/gui/celestialbodies/earth.png")); planet.atmosphereComponent(EnumAtmosphericGas.NITROGEN).atmosphereComponent(EnumAtmosphericGas.OXYGEN) - .atmosphereComponent(EnumAtmosphericGas.ARGON).atmosphereComponent(EnumAtmosphericGas.WATER); + .atmosphereComponent(EnumAtmosphericGas.ARGON).atmosphereComponent(EnumAtmosphericGas.WATER); planet.setUnreachable(); GalaxyRegistry.registerPlanet(planet); } diff --git a/src/main/java/net/rom/gctweaks/gc/features/galaxyfeature/GCSystems.java b/src/main/java/net/romvoid95/gctweaks/gc/features/galaxy/GCSystems.java similarity index 93% rename from src/main/java/net/rom/gctweaks/gc/features/galaxyfeature/GCSystems.java rename to src/main/java/net/romvoid95/gctweaks/gc/features/galaxy/GCSystems.java index f8c9e22..866ef9e 100644 --- a/src/main/java/net/rom/gctweaks/gc/features/galaxyfeature/GCSystems.java +++ b/src/main/java/net/romvoid95/gctweaks/gc/features/galaxy/GCSystems.java @@ -1,4 +1,4 @@ -package net.rom.gctweaks.gc.features.galaxyfeature; +package net.romvoid95.gctweaks.gc.features.galaxy; import asmodeuscore.core.astronomy.BodiesRegistry; @@ -8,7 +8,7 @@ import micdoodle8.mods.galacticraft.api.galaxies.Star; import micdoodle8.mods.galacticraft.api.vector.Vector3; import net.minecraft.util.ResourceLocation; -import net.rom.gctweaks.Ref; +import net.romvoid95.gctweaks.Ref; public class GCSystems { public static Galaxies EXTRAPLANETS; diff --git a/src/main/java/net/rom/gctweaks/gc/features/galaxyfeature/SeperateAddonPlanets.java b/src/main/java/net/romvoid95/gctweaks/gc/features/galaxy/SeperateAddonPlanets.java similarity index 91% rename from src/main/java/net/rom/gctweaks/gc/features/galaxyfeature/SeperateAddonPlanets.java rename to src/main/java/net/romvoid95/gctweaks/gc/features/galaxy/SeperateAddonPlanets.java index 0f88a62..94b2ee6 100644 --- a/src/main/java/net/rom/gctweaks/gc/features/galaxyfeature/SeperateAddonPlanets.java +++ b/src/main/java/net/romvoid95/gctweaks/gc/features/galaxy/SeperateAddonPlanets.java @@ -1,9 +1,9 @@ -package net.rom.gctweaks.gc.features.galaxyfeature; +package net.romvoid95.gctweaks.gc.features.galaxy; import asmodeuscore.core.astronomy.BodiesRegistry; import net.minecraftforge.common.config.Configuration; -import net.rom.gctweaks.base.Feature; -import net.rom.gctweaks.base.core.compat.CompatMods; +import net.romvoid95.gctweaks.base.Feature; +import net.romvoid95.gctweaks.base.core.compat.CompatMods; public class SeperateAddonPlanets extends Feature { diff --git a/src/main/java/net/rom/gctweaks/gc/features/oxygenfeature/SpawnWithOxygenEquip.java b/src/main/java/net/romvoid95/gctweaks/gc/features/oxygen/SpawnWithOxygenEquip.java similarity index 96% rename from src/main/java/net/rom/gctweaks/gc/features/oxygenfeature/SpawnWithOxygenEquip.java rename to src/main/java/net/romvoid95/gctweaks/gc/features/oxygen/SpawnWithOxygenEquip.java index c2858d6..4ab38e7 100644 --- a/src/main/java/net/rom/gctweaks/gc/features/oxygenfeature/SpawnWithOxygenEquip.java +++ b/src/main/java/net/romvoid95/gctweaks/gc/features/oxygen/SpawnWithOxygenEquip.java @@ -1,22 +1,25 @@ -package net.rom.gctweaks.gc.features.oxygenfeature; +package net.romvoid95.gctweaks.gc.features.oxygen; -import micdoodle8.mods.galacticraft.core.GCItems; -import micdoodle8.mods.galacticraft.core.entities.player.GCCapabilities; -import micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats; -import micdoodle8.mods.galacticraft.core.inventory.InventoryExtended; -import micdoodle8.mods.galacticraft.planets.asteroids.items.AsteroidsItems; -import micdoodle8.mods.galacticraft.planets.venus.VenusItems; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; + import net.minecraftforge.common.config.Configuration; import net.minecraftforge.fml.common.event.FMLServerStartingEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.PlayerEvent.PlayerLoggedInEvent; -import net.rom.gctweaks.Ref; -import net.rom.gctweaks.base.Feature; -import net.rom.gctweaks.gc.features.oxygenfeature.command.CommandOxygenReset; + +import micdoodle8.mods.galacticraft.core.GCItems; +import micdoodle8.mods.galacticraft.core.entities.player.GCCapabilities; +import micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats; +import micdoodle8.mods.galacticraft.core.inventory.InventoryExtended; +import micdoodle8.mods.galacticraft.planets.asteroids.items.AsteroidsItems; +import micdoodle8.mods.galacticraft.planets.venus.VenusItems; + +import net.romvoid95.gctweaks.Ref; +import net.romvoid95.gctweaks.base.Feature; +import net.romvoid95.gctweaks.gc.features.oxygen.command.CommandOxygenReset; public class SpawnWithOxygenEquip extends Feature { @@ -75,7 +78,6 @@ public boolean usesEvents () { @SubscribeEvent public void playerLogin (PlayerLoggedInEvent event) { final EntityPlayer player = event.player; - final NBTTagCompound entityData = player.getEntityData(); final NBTTagCompound persistedData = entityData.getCompoundTag(EntityPlayer.PERSISTED_NBT_TAG); entityData.setTag(EntityPlayer.PERSISTED_NBT_TAG, persistedData); diff --git a/src/main/java/net/rom/gctweaks/gc/features/oxygenfeature/command/CommandOxygenReset.java b/src/main/java/net/romvoid95/gctweaks/gc/features/oxygen/command/CommandOxygenReset.java similarity index 96% rename from src/main/java/net/rom/gctweaks/gc/features/oxygenfeature/command/CommandOxygenReset.java rename to src/main/java/net/romvoid95/gctweaks/gc/features/oxygen/command/CommandOxygenReset.java index 71b3cbb..5e3cd0f 100644 --- a/src/main/java/net/rom/gctweaks/gc/features/oxygenfeature/command/CommandOxygenReset.java +++ b/src/main/java/net/romvoid95/gctweaks/gc/features/oxygen/command/CommandOxygenReset.java @@ -1,4 +1,4 @@ -package net.rom.gctweaks.gc.features.oxygenfeature.command; +package net.romvoid95.gctweaks.gc.features.oxygen.command; import java.util.List; @@ -13,7 +13,7 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.text.TextComponentString; import net.minecraft.util.text.TextFormatting; -import net.rom.gctweaks.Ref; +import net.romvoid95.gctweaks.Ref; public class CommandOxygenReset extends CommandBase { diff --git a/src/main/java/net/romvoid95/gctweaks/gc/features/schematic/UnlockSchematics.java b/src/main/java/net/romvoid95/gctweaks/gc/features/schematic/UnlockSchematics.java new file mode 100644 index 0000000..749c4a1 --- /dev/null +++ b/src/main/java/net/romvoid95/gctweaks/gc/features/schematic/UnlockSchematics.java @@ -0,0 +1,62 @@ +package net.romvoid95.gctweaks.gc.features.schematic; + +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.item.ItemStack; + +import net.minecraftforge.common.config.Configuration; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.gameevent.PlayerEvent; + +import micdoodle8.mods.galacticraft.api.recipe.SchematicRegistry; + +import net.romvoid95.gctweaks.GalacticTweaks; +import net.romvoid95.gctweaks.base.Feature; + +public class UnlockSchematics extends Feature { + + private static boolean unlockSchematicsOnJoin; + private static int[] schematicID; + + @Override + public String[] category() { + return new String[] { "unlock-schematics" }; + } + + @Override + public String comment() { + return "Unlock all schematics specified when the player joins the world."; + } + + @Override + public void syncConfig(Configuration config, String[] category) { + unlockSchematicsOnJoin = config.get(category[0], "unlock-schematics", false, + "Set to true unlock schematics specified in config on player join.\nYou can see what schematic IDs are in GC by default in configs.").getBoolean(); + schematicID = config.get(category[0], "schematic-ids", new int[] { 0, 1, 2, 3, 4 }, + "Check galacticraft/addon config for schematic IDs").getIntList(); + } + + @Override + public boolean usesEvents() { + return true; + } + + @SubscribeEvent + public void PlayerWorldJoin(PlayerEvent.PlayerLoggedInEvent e) { + final EntityPlayerMP player = (EntityPlayerMP) e.player; + if (unlockSchematicsOnJoin) { + perPlayerSchems(player); + } + } + + private void perPlayerSchems(EntityPlayerMP player) { + for (int schem : schematicID) { + ItemStack schemItem = SchematicRegistry.getSchematicItem(schem); + try { + SchematicRegistry.unlockNewPage(player, schemItem); + } catch (Exception e) { + GalacticTweaks.logger.error( + "Please remove " + schem + " from the schematics config. This is a invalid value..."); + } + } + } +} diff --git a/src/main/java/net/romvoid95/gctweaks/gc/features/spawndim/SpawnDimension.java b/src/main/java/net/romvoid95/gctweaks/gc/features/spawndim/SpawnDimension.java new file mode 100644 index 0000000..f991fc0 --- /dev/null +++ b/src/main/java/net/romvoid95/gctweaks/gc/features/spawndim/SpawnDimension.java @@ -0,0 +1,151 @@ +package net.romvoid95.gctweaks.gc.features.spawndim; + +import java.io.*; +import java.util.*; +import java.util.Map.Entry; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.server.MinecraftServer; +import net.minecraft.world.WorldServer; + +import net.minecraftforge.common.config.Configuration; +import net.minecraftforge.fml.common.eventhandler.EventPriority; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.gameevent.PlayerEvent.PlayerLoggedInEvent; +import net.minecraftforge.fml.common.gameevent.PlayerEvent.PlayerRespawnEvent; + +import micdoodle8.mods.galacticraft.api.galaxies.*; +import micdoodle8.mods.galacticraft.api.vector.Vector3; +import micdoodle8.mods.galacticraft.core.util.WorldUtil; + +import net.romvoid95.gctweaks.GalacticTweaks; +import net.romvoid95.gctweaks.Ref; +import net.romvoid95.gctweaks.base.Feature; +import net.romvoid95.gctweaks.base.core.compat.CompatMods; + +public class SpawnDimension extends Feature { + + private static boolean enableSpawnDimension, firstJoinOnly, everyDeath; + private static int spawnDimId; + + @Override + public String[] category() { + return new String[] { "spawn-dimension" }; + } + + @Override + public String comment() { + return "Set a certain Planet or Moon as a Spawn Point\n\nYou should have SPAWN-ITEMS Configured and set prior to enabling this setting\n" + + "At the moment any moon or planet set to spawn in uses that bodies teleport system (spawns in the lander)"; + } + + @Override + public void syncConfig(Configuration config, String[] category) { + enableSpawnDimension = config.get(category[0], "spawnfeature", false, + "Enable & Disable the Spawn Dimension Feature\n[default: false]").getBoolean(); + firstJoinOnly = config.get(category[0], "firstJoinOnly", true, + "If \"true\" players are only sent to the spawn dimension" + + " on their first time joining.\nIf \"false\" players are sent every join\n [default: false]").getBoolean(); + everyDeath = config.get(category[0], "everyDeath", false, "If \"true\" players are sent to the spawn dimension" + + "every death respawn.\n [default: false]").getBoolean(); + spawnDimId = config.get(category[0], "spawnDimId", 0, + "Set the Dimension ID of the planet/moon you want players join on\n" + + "There is a file under this one called ValidSpawnDimsneions.txt\n" + + "that will contain every valid dimension ID you can set").getInt(); + + } + + @Override + public boolean usesEvents() { + return true; + } + + @Override + public void postInit() { + creatFile(); + } + + @SubscribeEvent(priority = EventPriority.LOWEST) + public void onPlayerJoin(PlayerLoggedInEvent event) { + if (event.player instanceof EntityPlayer) { + if (enableSpawnDimension) { + final EntityPlayer player = event.player; + final NBTTagCompound entityData = player.getEntityData(); + final NBTTagCompound persistedData = entityData.getCompoundTag(EntityPlayer.PERSISTED_NBT_TAG); + entityData.setTag(EntityPlayer.PERSISTED_NBT_TAG, persistedData); + final String key = Ref.MOD_ID + ":" + "FirstSpawn"; + if (!persistedData.getBoolean(key)) { + teleport((EntityPlayerMP) event.player, spawnDimId); + persistedData.setBoolean(key, true); + } + } else if (firstJoinOnly) { + teleport((EntityPlayerMP) event.player, spawnDimId); + } + } + } + + @SubscribeEvent(priority = EventPriority.LOWEST) + public void onPlayerRespawn(PlayerRespawnEvent event) { + if (event.player instanceof EntityPlayer) { + if (everyDeath) { + teleport((EntityPlayerMP) event.player, spawnDimId); + } + } + } + + private void teleport(EntityPlayerMP player, int dimId) { + MinecraftServer mcServer = player.getServer(); + final WorldServer world = mcServer.getWorld(dimId); + int yy = world.getChunkFromBlockCoords(world.getSpawnPoint()).getHeight(world.getSpawnPoint()); + Vector3 v = new Vector3(world.getSpawnPoint().getX(), yy, world.getSpawnPoint().getZ()); + WorldUtil.teleportEntitySimple(world, dimId, player, v); + } + + private static boolean creatFile() { + File dims = new File(GalacticTweaks.modFolder, "GalacticTweaks/ValidSpawnDimsneions.txt"); + if (dims.exists()) { + dims.delete(); + } + Map planets = new HashMap<>(); + for (Entry body : GalaxyRegistry.getRegisteredPlanets().entrySet()) { + if (body.getValue().getReachable()) { + planets.put(body.getValue().getLocalizedName(), body.getValue().getDimensionID()); + } + } + Map moons = new HashMap<>(); + for (Entry body : GalaxyRegistry.getRegisteredMoons().entrySet()) { + if (body.getValue().getReachable()) { + moons.put(body.getValue().getLocalizedName(), body.getValue().getDimensionID()); + } + } + try { + dims.createNewFile(); + PrintWriter print_line = new PrintWriter(new FileWriter(dims)); + if(CompatMods.EXTRAPLANETS.isLoaded()) { + print_line.println("### NOTICE ###"); + print_line.println("Planets & Moons that end with \"ep\" are added by ExtraPlanets."); + print_line.println("Please keep this in mind if choosing a planet that is added by both ExtraPlanets & GalaxySpace"); + } + print_line.println(""); + print_line.println("If adding or removing Galacticraft Addons, This file is regenerated every time minecraft is ran"); + print_line.println(""); + print_line.println("| ### PLANETS ###"); + print_line.println("|------------------"); + planets.entrySet().stream().sorted(Map.Entry.comparingByValue(Comparator.reverseOrder())).forEach( + s -> print_line.println(String.format("| %-15s %15s", s.getKey(), s.getValue()))); + print_line.println(""); + print_line.println(""); + print_line.println("| ### MOONS ###"); + print_line.println("|------------------"); + moons.entrySet().stream().sorted(Map.Entry.comparingByValue(Comparator.reverseOrder())).forEach( + s -> print_line.println(String.format("| %-15s %15s", s.getKey(), s.getValue()))); + print_line.flush(); + print_line.close(); + return true; + } catch (IOException localIOException) { + return false; + } + } +} diff --git a/src/main/java/net/rom/gctweaks/gc/features/sprfeature/SpaceRaceFeature.java b/src/main/java/net/romvoid95/gctweaks/gc/features/spawnitems/SpaceRaceFeature.java similarity index 81% rename from src/main/java/net/rom/gctweaks/gc/features/sprfeature/SpaceRaceFeature.java rename to src/main/java/net/romvoid95/gctweaks/gc/features/spawnitems/SpaceRaceFeature.java index b060a5f..41a5802 100644 --- a/src/main/java/net/rom/gctweaks/gc/features/sprfeature/SpaceRaceFeature.java +++ b/src/main/java/net/romvoid95/gctweaks/gc/features/spawnitems/SpaceRaceFeature.java @@ -1,9 +1,9 @@ -package net.rom.gctweaks.gc.features.sprfeature; +package net.romvoid95.gctweaks.gc.features.spawnitems; import net.minecraftforge.common.config.Configuration; import net.minecraftforge.fml.common.event.FMLServerStartingEvent; -import net.rom.gctweaks.base.Feature; -import net.rom.gctweaks.gc.features.sprfeature.command.CommandLeaveSpaceRace; +import net.romvoid95.gctweaks.base.Feature; +import net.romvoid95.gctweaks.gc.features.spawnitems.command.CommandLeaveSpaceRace; public class SpaceRaceFeature extends Feature { diff --git a/src/main/java/net/rom/gctweaks/gc/features/sprfeature/command/CommandLeaveSpaceRace.java b/src/main/java/net/romvoid95/gctweaks/gc/features/spawnitems/command/CommandLeaveSpaceRace.java similarity index 82% rename from src/main/java/net/rom/gctweaks/gc/features/sprfeature/command/CommandLeaveSpaceRace.java rename to src/main/java/net/romvoid95/gctweaks/gc/features/spawnitems/command/CommandLeaveSpaceRace.java index 6918b71..d67090b 100644 --- a/src/main/java/net/rom/gctweaks/gc/features/sprfeature/command/CommandLeaveSpaceRace.java +++ b/src/main/java/net/romvoid95/gctweaks/gc/features/spawnitems/command/CommandLeaveSpaceRace.java @@ -1,4 +1,4 @@ -package net.rom.gctweaks.gc.features.sprfeature.command; +package net.romvoid95.gctweaks.gc.features.spawnitems.command; import java.util.ArrayList; import java.util.List; @@ -70,21 +70,21 @@ public void execute (MinecraftServer server, ICommandSender sender, String[] arg SpaceRaceManager.sendSpaceRaceData(server, player, race); if (!race.getPlayerNames().contains(player.getName())) { - sender.sendMessage(new TextComponentTranslation("gctweaks.leaverace.playerleave", race + sender.sendMessage(new TextComponentTranslation("galactictweaks.leaverace.playerleave", race .getTeamName())); } else { } } else { - sender.sendMessage(new TextComponentTranslation("gctweaks.leaverace.leader")); + sender.sendMessage(new TextComponentTranslation("galactictweaks.leaverace.leader")); } } else { - sender.sendMessage(new TextComponentTranslation("gctweaks.leaverace.noteam")); + sender.sendMessage(new TextComponentTranslation("galactictweaks.leaverace.noteam")); } } else { - sender.sendMessage(new TextComponentTranslation("gctweaks.leaverace.noarg")); - sender.sendMessage(new TextComponentTranslation("gctweaks.leaverace.useage", this.getUsage(sender))); + sender.sendMessage(new TextComponentTranslation("galactictweaks.leaverace.noarg")); + sender.sendMessage(new TextComponentTranslation("galactictweaks.leaverace.useage", this.getUsage(sender))); } } diff --git a/src/main/java/net/rom/gctweaks/internal/BuiltInModule.java b/src/main/java/net/romvoid95/gctweaks/internal/BuiltInModule.java similarity index 68% rename from src/main/java/net/rom/gctweaks/internal/BuiltInModule.java rename to src/main/java/net/romvoid95/gctweaks/internal/BuiltInModule.java index fa38e48..828fb20 100644 --- a/src/main/java/net/rom/gctweaks/internal/BuiltInModule.java +++ b/src/main/java/net/romvoid95/gctweaks/internal/BuiltInModule.java @@ -1,6 +1,6 @@ -package net.rom.gctweaks.internal; +package net.romvoid95.gctweaks.internal; -import net.rom.gctweaks.base.InternalModule; +import net.romvoid95.gctweaks.base.InternalModule; public class BuiltInModule extends InternalModule { diff --git a/src/main/java/net/rom/gctweaks/internal/CrashLogWarning.java b/src/main/java/net/romvoid95/gctweaks/internal/CrashLogWarning.java similarity index 84% rename from src/main/java/net/rom/gctweaks/internal/CrashLogWarning.java rename to src/main/java/net/romvoid95/gctweaks/internal/CrashLogWarning.java index 6aed632..c22b2c3 100644 --- a/src/main/java/net/rom/gctweaks/internal/CrashLogWarning.java +++ b/src/main/java/net/romvoid95/gctweaks/internal/CrashLogWarning.java @@ -1,28 +1,21 @@ -package net.rom.gctweaks.internal; +package net.romvoid95.gctweaks.internal; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.Map.Entry; -import java.util.Set; -import net.minecraftforge.fml.common.FMLCommonHandler; -import net.minecraftforge.fml.common.ICrashCallable; -import net.minecraftforge.fml.common.Loader; -import net.minecraftforge.fml.common.ModContainer; +import net.minecraftforge.fml.common.*; import net.minecraftforge.fml.common.versioning.ArtifactVersion; -import net.rom.gctweaks.base.InternalFeature; -import net.rom.gctweaks.gc.features.galaxyfeature.SeperateAddonPlanets; + +import net.romvoid95.gctweaks.base.InternalFeature; +import net.romvoid95.gctweaks.gc.features.galaxy.SeperateAddonPlanets; public class CrashLogWarning extends InternalFeature { private static List loaded = Loader.instance().getActiveModList(); - private static Map sets = new HashMap(); - private static Map cores = new HashMap(); - private static Set> setRemove = new HashSet>(); - private static Set> coreRemove = new HashSet>(); + private static Map sets = new HashMap<>(); + private static Map cores = new HashMap<>(); + private static Set> setRemove = new HashSet<>(); + private static Set> coreRemove = new HashSet<>(); private static String setter = "\n\t|\t"; private static String setter2 = "\t|\t"; diff --git a/src/main/java/net/rom/gctweaks/base/version/CommandDownloadUpdate.java b/src/main/java/net/romvoid95/gctweaks/internal/command/DownloadCommand.java similarity index 57% rename from src/main/java/net/rom/gctweaks/base/version/CommandDownloadUpdate.java rename to src/main/java/net/romvoid95/gctweaks/internal/command/DownloadCommand.java index 6bd28f7..5f22cfe 100644 --- a/src/main/java/net/rom/gctweaks/base/version/CommandDownloadUpdate.java +++ b/src/main/java/net/romvoid95/gctweaks/internal/command/DownloadCommand.java @@ -1,6 +1,4 @@ -package net.rom.gctweaks.base.version; - -import com.therandomlabs.curseapi.CurseException; +package net.romvoid95.gctweaks.internal.command; import net.minecraft.command.CommandBase; import net.minecraft.command.CommandException; @@ -9,8 +7,11 @@ import net.minecraft.util.text.Style; import net.minecraft.util.text.TextComponentTranslation; import net.minecraft.util.text.TextFormatting; +import net.romvoid95.gctweaks.internal.versioning.DownloadUpdate; +import net.romvoid95.gctweaks.internal.versioning.VersionChecker; + -public class CommandDownloadUpdate extends CommandBase { +public class DownloadCommand extends CommandBase { @Override public String getName () { @@ -19,7 +20,7 @@ public String getName () { @Override public String getUsage (ICommandSender sender) { - return "/download-latest-gctweaks "; + return "/download-latest-gctweaks"; } @Override @@ -29,21 +30,21 @@ public boolean checkPermission (MinecraftServer server, ICommandSender sender) { @Override public void execute (MinecraftServer server, ICommandSender sender, String[] args) throws CommandException { - if (args.length == 1) - if (VersionChecker.downloadedFile) - sender.sendMessage(new TextComponentTranslation("gctweaks.versions.downloadedAlready") + if (args.length == 0) { + if (VersionChecker.downloadedFile) { + sender.sendMessage(new TextComponentTranslation("galactictweaks.versions.downloadedAlready") .setStyle(new Style().setColor(TextFormatting.RED))); - else if (VersionChecker.startedDownload) - sender.sendMessage(new TextComponentTranslation("gctweaks.versions.downloadingAlready") + } + else if (VersionChecker.startedDownload) { + sender.sendMessage(new TextComponentTranslation("galactictweaks.versions.downloadingAlready") .setStyle(new Style().setColor(TextFormatting.RED))); - else - try { - new DownloadUpdate(args[0]); - } - catch (CurseException e) { - e.printStackTrace(); - } - + } + else { + new DownloadUpdate(); + } + } + else { + + } } - } diff --git a/src/main/java/net/romvoid95/gctweaks/internal/config/ConfigCore.java b/src/main/java/net/romvoid95/gctweaks/internal/config/ConfigCore.java new file mode 100644 index 0000000..98372ca --- /dev/null +++ b/src/main/java/net/romvoid95/gctweaks/internal/config/ConfigCore.java @@ -0,0 +1,128 @@ +/** + * Copyright (C) 2020 Interstellar: Exoplanets + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.romvoid95.gctweaks.internal.config; + +import static net.romvoid95.gctweaks.Ref.*; + +import java.io.File; +import java.util.*; + +import net.minecraftforge.common.config.*; +import net.minecraftforge.fml.client.config.IConfigElement; +import net.minecraftforge.fml.client.event.ConfigChangedEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; + +import net.romvoid95.gctweaks.GalacticTweaks; +import net.romvoid95.gctweaks.Ref; + +public class ConfigCore { + + static Configuration config; + + public ConfigCore(File file) { + ConfigCore.config = new Configuration((file), "1.0"); + ConfigCore.syncConfig(true); + } + + public static boolean enableCheckVersion; + + private static Map> propOrder = new TreeMap<>(); + private static String currentCat; + + public static void syncConfig(boolean load) { + try { + propOrder.clear(); + Property prop; + if (!config.isChild) { + if (load) { + config.load(); + } + } + + config.addCustomCategoryComment(CATEGORY_CORE, CATEGORY_CORE); + config.setCategoryLanguageKey(CATEGORY_CORE, CATEGORY_CORE_LANGKEY); + config.setCategoryRequiresMcRestart(CATEGORY_CORE, true); + + prop = getConfig(CATEGORY_CORE, "enableCheckVersion", true); + prop.setComment("Enable/Disable Check Version"); + prop.setLanguageKey("galactictweaks.configgui.enableCheckVersion"); + enableCheckVersion = prop.getBoolean(true); + finishProp(prop); + + if (config.hasChanged()) { + config.save(); + } + } catch (final Exception e) { + GalacticTweaks.logger.warn("GalacticTweaks Core Config had an issue loading the config file!"); + } + } + + public static void cleanConfig(Configuration config, Map> propOrder) { + List categoriesToRemove = new LinkedList<>(); + for (String catName : config.getCategoryNames()) { + List newProps = propOrder.get(catName); + if (newProps == null) { + categoriesToRemove.add(catName); + } else { + ConfigCategory cat = config.getCategory(catName); + List toRemove = new LinkedList<>(); + for (String oldprop : cat.keySet()) { + if (!newProps.contains(oldprop)) { + toRemove.add(oldprop); + } + } + for (String removeMe : toRemove) { + cat.remove(removeMe); + } + config.setCategoryPropertyOrder(catName, propOrder.get(catName)); + } + } + for (String catName : categoriesToRemove) { + config.removeCategory(config.getCategory(catName)); + } + } + + private static Property getConfig(String cat, String key, boolean defaultValue) { + config.moveProperty(CATEGORY_CORE, key, cat); + currentCat = cat; + return config.get(cat, key, defaultValue); + } + + private static void finishProp(Property prop) { + if (propOrder.get(currentCat) == null) { + propOrder.put(currentCat, new ArrayList()); + } + propOrder.get(currentCat).add(prop.getName()); + } + + public static List getConfigElements() { + List list = new ArrayList<>(); + ConfigCategory configGeneral = config.getCategory(CATEGORY_CORE); + configGeneral.setComment("Core Settings"); + list.add(new ConfigElement(configGeneral)); + return list; + } + + @SubscribeEvent + public void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent eventArgs) { + if (eventArgs.getModID().equals(Ref.MOD_ID)) { + config.save(); + } + } + +} diff --git a/src/main/java/net/romvoid95/gctweaks/internal/versioning/DownloadUpdate.java b/src/main/java/net/romvoid95/gctweaks/internal/versioning/DownloadUpdate.java new file mode 100644 index 0000000..cdc3705 --- /dev/null +++ b/src/main/java/net/romvoid95/gctweaks/internal/versioning/DownloadUpdate.java @@ -0,0 +1,74 @@ +package net.romvoid95.gctweaks.internal.versioning; + +import java.awt.Desktop; +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.net.URLConnection; +import java.nio.file.Path; + +import org.apache.commons.io.FileUtils; +import org.apache.commons.io.FilenameUtils; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.resources.I18n; +import net.minecraft.util.text.*; + +public class DownloadUpdate { + + public DownloadUpdate() { + run(); + } + + public void run () { + + URL downloadUrl = null; + try { + downloadUrl = new URL(Request.getLatestVersionDownload()); + } + catch (Exception e) { + e.printStackTrace(); + } + + Path dir = new File(Minecraft.getMinecraft().mcDataDir, "mods").toPath(); + + String fileName = FilenameUtils.getName(downloadUrl.getPath()); + File newFile = new File(dir.toString() + "/" + fileName); + + ITextComponent component = ITextComponent.Serializer + .jsonToComponent(I18n.format("galactictweaks.versions.startingDownload", fileName)); + ITextComponent component2 = ITextComponent.Serializer + .jsonToComponent(I18n.format("galactictweaks.versions.startingDownload2")); + if (Minecraft.getMinecraft().player != null) { + + Minecraft.getMinecraft().player.sendMessage(component); + Minecraft.getMinecraft().player.sendMessage(component2); + } + + VersionChecker.startedDownload = true; + + try { + URLConnection conn = downloadUrl.openConnection(); + conn.connect(); + FileUtils.copyInputStreamToFile(conn.getInputStream(), newFile); + } + catch (NumberFormatException | IOException e) { + e.printStackTrace(); + } + + if (newFile.exists()) { + if (Minecraft.getMinecraft().player != null) + Minecraft.getMinecraft().player + .sendMessage(new TextComponentTranslation("galactictweaks.versions.doneDownloading", fileName) + .setStyle(new Style().setColor(TextFormatting.GREEN))); + + try { + Desktop.getDesktop().open(dir.toFile()); + } + catch (IOException e) { + e.printStackTrace(); + } + } + VersionChecker.downloadedFile = true; + } +} diff --git a/src/main/java/net/romvoid95/gctweaks/internal/versioning/Request.java b/src/main/java/net/romvoid95/gctweaks/internal/versioning/Request.java new file mode 100644 index 0000000..117cde7 --- /dev/null +++ b/src/main/java/net/romvoid95/gctweaks/internal/versioning/Request.java @@ -0,0 +1,65 @@ +package net.romvoid95.gctweaks.internal.versioning; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + +import com.google.gson.*; + +import net.romvoid95.gctweaks.GalacticTweaks; + +public class Request { + + public static String domain1 = "https://addons-ecs.forgesvc.net/api/v2/addon/359766"; + + public static String getLatestVersion() { + try { + URL getRequestURL = new URL(domain1); + HttpURLConnection con = (HttpURLConnection) getRequestURL.openConnection(); + con.setRequestMethod("GET"); + BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); + String inputLine; + String response = ""; + while ((inputLine = in.readLine()) != null) { + + response += inputLine; + in.close(); + JsonParser parser = new JsonParser(); + JsonObject array = parser.parse(response).getAsJsonObject(); + JsonArray json = array.getAsJsonArray("latestFiles"); + JsonObject ob = json.get(0).getAsJsonObject(); + String version = ob.get("displayName").getAsString().split("-")[1].replace(".jar", ""); + return version; + } + } catch (Exception e) { + GalacticTweaks.logger.error("There was an issue communicating with the CurseAPI"); + } + return null; + } + + public static String getLatestVersionDownload() { + try { + URL getRequestURL = new URL(domain1); + HttpURLConnection con = (HttpURLConnection) getRequestURL.openConnection(); + con.setRequestMethod("GET"); + BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); + String inputLine; + String response = ""; + while ((inputLine = in.readLine()) != null) { + //GalacticTweaks.logger.info(inputLine); + response += inputLine; + in.close(); + JsonParser parser = new JsonParser(); + JsonObject array = parser.parse(response).getAsJsonObject(); + JsonArray json = array.getAsJsonArray("latestFiles"); + JsonObject ob = json.get(0).getAsJsonObject(); + String version = ob.get("downloadUrl").getAsString(); + return version; + } + } catch (Exception e) { + GalacticTweaks.logger.error("There was an issue communicating with the CurseAPI"); + } + return null; + } +} diff --git a/src/main/java/net/romvoid95/gctweaks/internal/versioning/ThreadVersionChecker.java b/src/main/java/net/romvoid95/gctweaks/internal/versioning/ThreadVersionChecker.java new file mode 100644 index 0000000..01501fe --- /dev/null +++ b/src/main/java/net/romvoid95/gctweaks/internal/versioning/ThreadVersionChecker.java @@ -0,0 +1,21 @@ +package net.romvoid95.gctweaks.internal.versioning; + +public class ThreadVersionChecker extends Thread { + + public ThreadVersionChecker () { + setName("Version Checker Thread"); + setDaemon(true); + start(); + } + + @Override + public void run() { + try { + VersionChecker.onlineVersion = Request.getLatestVersion(); + + } catch (Exception e) { + e.printStackTrace(); + } + VersionChecker.doneChecking = true; + } +} diff --git a/src/main/java/net/rom/gctweaks/base/version/VersionChecker.java b/src/main/java/net/romvoid95/gctweaks/internal/versioning/VersionChecker.java similarity index 55% rename from src/main/java/net/rom/gctweaks/base/version/VersionChecker.java rename to src/main/java/net/romvoid95/gctweaks/internal/versioning/VersionChecker.java index c2b5d2e..0022942 100644 --- a/src/main/java/net/rom/gctweaks/base/version/VersionChecker.java +++ b/src/main/java/net/romvoid95/gctweaks/internal/versioning/VersionChecker.java @@ -1,31 +1,26 @@ -package net.rom.gctweaks.base.version; - -import com.vdurmont.semver4j.Semver; +package net.romvoid95.gctweaks.internal.versioning; import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.Style; -import net.minecraft.util.text.TextComponentTranslation; -import net.minecraft.util.text.TextFormatting; +import net.minecraft.util.text.*; import net.minecraft.util.text.translation.I18n; + import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent; import net.minecraftforge.fml.common.gameevent.TickEvent.Phase; import net.minecraftforge.fml.relauncher.Side; -import net.rom.gctweaks.Ref; +import net.romvoid95.api.versioning.Version; +import net.romvoid95.gctweaks.Ref; @Mod.EventBusSubscriber(value = Side.CLIENT, modid = Ref.MOD_ID) -@SuppressWarnings("deprecation") public final class VersionChecker { private VersionChecker() {} public static volatile boolean doneChecking = false; public static volatile String onlineVersion = ""; - public static volatile String fileId = ""; private static boolean triedToWarnPlayer = false; public static volatile boolean startedDownload = false; public static volatile boolean downloadedFile = false; @@ -39,21 +34,19 @@ public static void onTick (ClientTickEvent event) { if (event.phase == Phase.END && Minecraft.getMinecraft().player != null && !triedToWarnPlayer && doneChecking) { if (!onlineVersion.isEmpty()) { EntityPlayer player = Minecraft.getMinecraft().player; - Semver online = new Semver(onlineVersion.split(":")[0]); - Semver client = new Semver(Ref.MOD_VERSION); - fileId = onlineVersion.split(":")[1]; + Version online = new Version(Request.getLatestVersion()); + Version client = new Version(Ref.MOD_VERSION); if (online.isGreaterThan(client)) { - player.sendMessage(new TextComponentTranslation("gctweaks.versions.notify") + player.sendMessage(new TextComponentTranslation("galactictweaks.versions.notify") .setStyle(new Style().setColor(TextFormatting.LIGHT_PURPLE))); - player.sendMessage(new TextComponentTranslation("gctweaks.versions.outdated0")); - player.sendMessage(new TextComponentTranslation("gctweaks.versions.outdated1", client + player.sendMessage(new TextComponentTranslation("galactictweaks.versions.outdated0")); + player.sendMessage(new TextComponentTranslation("galactictweaks.versions.outdated1", client .toString())); - player.sendMessage(new TextComponentTranslation("gctweaks.versions.outdated2", online + player.sendMessage(new TextComponentTranslation("galactictweaks.versions.outdated2", online .toString())); - player.sendMessage(new TextComponentTranslation("gctweaks.versions.outdated0")); - - ITextComponent component = ITextComponent.Serializer.fromJsonLenient(I18n - .translateToLocal("gctweaks.versions.updateMessage").replaceAll("%version%", fileId)); + player.sendMessage(new TextComponentTranslation("galactictweaks.versions.outdated0")); + ITextComponent component = ITextComponent.Serializer + .fromJsonLenient(I18n.translateToLocal("galactictweaks.versions.updateMessage")); player.sendMessage(component); } } diff --git a/src/main/resources/assets/gctweaks/lang/en_US.lang b/src/main/resources/assets/gctweaks/lang/en_US.lang new file mode 100644 index 0000000..871d733 --- /dev/null +++ b/src/main/resources/assets/gctweaks/lang/en_US.lang @@ -0,0 +1,22 @@ +galaxy.wormhole= Alt Sol +solarsystem.secondSystem=Alternate Sol +star.epsystem=Sun +planet.fakeOverworld=Earth +planet.fakeRocks=Asteroids + +galactictweaks.leaverace.playerleave=You have sucsessfully left %s +galactictweaks.leaverace.leader=Team Leaders cannot use this command! +galactictweaks.leaverace.noarg=Command has no arguments! +galactictweaks.leaverace.useage=%s +galactictweaks.leaverace.noteam=You must be in a team to use this command! + +galactictweaks.versions.notify=Hey player! Hey player hey! GalacticTweaks update! +galactictweaks.versions.outdated0=§6**************************************** +galactictweaks.versions.outdated1=§6* §aRunning......v§c%s +galactictweaks.versions.outdated2=§6* §aLatest.........v§9%s +galactictweaks.versions.updateMessage=["Click To... [",{"text":"Download","color":"green","hoverEvent":{"action":"show_text","value":{"text":"Click this to automatically download the latest version","color":"green"}},"clickEvent":{"action":"run_command","value":"/download-latest-gctweaks"}},"]"] +galactictweaks.versions.startingDownload=[{"text":"Starting download . . . . . Please do not remove your hard disk. Enjoying ","color":"aqua"},{"text":"GalacticTweaks?","color":"green"}] +galactictweaks.versions.startingDownload2=[{"text":" Consider supporting ","color":"aqua"},{"text":"ROMVoid95","color":"light_purple"},{"text":" on [","color":"aqua"},{"text":"Patreon","color":"gold","hoverEvent":{"action":"show_text","value":{"text":"Click this to go to ROMVoid95's Patreon","color":"light_purple"}},"clickEvent":{"action":"open_url","value":"http://www.patreon.com/romvoid95"}},{"text":"]!","color":"aqua"}] +galactictweaks.versions.doneDownloading=Finished downloading . . . . . Delete your old GalacticTweaks jar and reload your game to update. +galactictweaks.versions.downloadedAlready=You already downloaded the latest version. Close your game, delete the old version from your mods folder and load it again to update! +galactictweaks.versions.downloadingAlready=The update is already downloading, give it some time, will you? \ No newline at end of file diff --git a/src/main/resources/assets/gctweaks/lang/es_ES.lang b/src/main/resources/assets/gctweaks/lang/es_ES.lang new file mode 100644 index 0000000..e510519 --- /dev/null +++ b/src/main/resources/assets/gctweaks/lang/es_ES.lang @@ -0,0 +1,22 @@ +galaxy.wormhole= Alt Sol +solarsystem.secondSystem=Sol Alternativo +star.epsystem=El sol +planet.fakeOverworld=La Tierra +planet.fakeRocks=El Asteroides + +galactictweaks.leaverace.playerleave=Has abandonado %s con éxito +galactictweaks.leaverace.leader=¡Los líderes de equipo no pueden usar este comando! +galactictweaks.leaverace.noarg=¡Esta comando no tiene argumentos! +galactictweaks.leaverace.useage=%s +galactictweaks.leaverace.noteam=¡Debes estar en un equipo para usar este comando! + +galactictweaks.versions.notify=Oye jugador! Oye jugador Oye! Actualizaciones de GalacticTweaks! +galactictweaks.versions.outdated0=§6**************************************** +galactictweaks.versions.outdated1=§6* §Funcionamiento......v§c%s +galactictweaks.versions.outdated2=§6* §aAúltimo.........v§9%s +galactictweaks.versions.updateMessage=["Haga clic para... [",{"text":"Descargar","color":"green","hoverEvent":{"action":"show_text","value":{"text":"Haga clic en esto para descargar automáticamente la última versión","color":"green"}},"clickEvent":{"action":"run_command","value":"/download-latest-gctweaks"}},"]"] +galactictweaks.versions.startingDownload=[{"text":"Iniciando descarga . . . . . Por favor no quite su disco duro. ¿Te gusta ","color":"aqua"},{"text":"GalacticTweaks?","color":"green"}] +galactictweaks.versions.startingDownload2=[{"text":" Considere la posibilidad de admitir ","color":"aqua"},{"text":"ROMVoid95","color":"light_purple"},{"text":" en [","color":"aqua"},{"text":"Patreon","color":"gold","hoverEvent":{"action":"show_text","value":{"text":"Haga clic aquí para ir a Patreon de ROMVoid95","color":"light_purple"}},"clickEvent":{"action":"open_url","value":"http://www.patreon.com/romvoid95"}},{"text":"]!","color":"aqua"}] +galactictweaks.versions.doneDownloading=Finalizada la descarga . . . . . Elimina tu antiguo GalacticTweaks.jar y vuelve a cargar el juego para actualizarlo. +galactictweaks.versions.downloadedAlready=Ya descargó la última versión. ¡Cierre su juego, suprima la vieja versión de su carpeta de mods y cárguelo otra vez para actualizar! +galactictweaks.versions.downloadingAlready=La actualización ya se está descargando, dale algo de tiempo, ¿quieres? diff --git a/src/main/resources/assets/gctweaks/lang/ru_RU.lang b/src/main/resources/assets/gctweaks/lang/ru_RU.lang new file mode 100644 index 0000000..8c84626 --- /dev/null +++ b/src/main/resources/assets/gctweaks/lang/ru_RU.lang @@ -0,0 +1,22 @@ +galaxy.wormhole= Алт Солнце +solarsystem.secondSystem=Альтернативное Солнце +star.epsystem=Солнце +planet.fakeOverworld=Земля +planet.fakeRocks=Астероиды + +galactictweaks.leaverace.playerleave=Вы успешно покинули %s +galactictweaks.leaverace.leader=Командиры команды не могут использовать эту команду! +galactictweaks.leaverace.noarg=Команда не имеет аргументов! +galactictweaks.leaverace.useage=%s +galactictweaks.leaverace.noteam=вы должны состоять в команде чтобы использовать эту команду! + +galactictweaks.versions.notify=Ей игрок! Зацени ! GalacticTweaks Обновился +galactictweaks.versions.outdated0=§6**************************************** +galactictweaks.versions.outdated1=§6* §aТекущая версия......v§c%s +galactictweaks.versions.outdated2=§6* §aПоследняя.........v§9%s +galactictweaks.versions.updateMessage=["Нажмите... [",{"text":"Скачать","color":"green","hoverEvent":{"action":"show_text","value":{"text":"Нажмите сюда чтобы автоматически скачать последнюю версию","color":"green"}},"clickEvent":{"action":"run_command","value":"/download-latest-gctweaks"}},"]"] +galactictweaks.versions.startingDownload=[{"text":"Начинаем Скачивание . . . . . Пожалуйста не удаляйте ваш жесткий диск. Наслаждайтесь ","color":"aqua"},{"text":"GalacticTweaks?","color":"green"}] +galactictweaks.versions.startingDownload2=[{"text":" Поддержите ","color":"aqua"},{"text":"ROMVoid95","color":"light_purple"},{"text":" on [","color":"aqua"},{"text":"Patreon","color":"gold","hoverEvent":{"action":"show_text","value":{"text":"Это патреон ROMVoid95's ","color":"light_purple"}},"clickEvent":{"action":"open_url","value":"http://www.patreon.com/romvoid95"}},{"text":"]!","color":"aqua"}] +galactictweaks.versions.doneDownloading=Скачивание закончено . . . . . Удалите ваше старое версию GalacticTweaks jar и перезагрузите игру чтобы обновится. +galactictweaks.versions.downloadedAlready=Вы уже скачали последнию версию. Закройте игру. удалите старую версию. и зайдите в игру заново! +galactictweaks.versions.downloadingAlready=Обновление уже скачивается. дайте ему время. Дашь?? diff --git a/src/main/resources/assets/gtweaks/textures/gui/galaxy/wormhole.png b/src/main/resources/assets/gctweaks/textures/gui/galaxy/wormhole.png similarity index 100% rename from src/main/resources/assets/gtweaks/textures/gui/galaxy/wormhole.png rename to src/main/resources/assets/gctweaks/textures/gui/galaxy/wormhole.png diff --git a/src/main/resources/assets/gtweaks/lang/en_us.lang b/src/main/resources/assets/gtweaks/lang/en_us.lang deleted file mode 100644 index 942e52d..0000000 --- a/src/main/resources/assets/gtweaks/lang/en_us.lang +++ /dev/null @@ -1,22 +0,0 @@ -galaxy.wormhole= Alt Sol -solarsystem.secondSystem=Alternate Sol -star.epsystem=Sun -planet.fakeOverworld=Earth -planet.fakeRocks=Asteroids - -gctweaks.leaverace.playerleave=You have sucsessfully left %s -gctweaks.leaverace.leader=Team Leaders cannot use this command! -gctweaks.leaverace.noarg=Command has no arguments! -gctweaks.leaverace.useage=%s -gctweaks.leaverace.noteam=You must be in a team to use this command! - -gctweaks.versions.notify=Hey player! Hey player hey! GalacticTweaks update! -gctweaks.versions.outdated0=§6**************************************** -gctweaks.versions.outdated1=§6* §aRunning......v§c%s -gctweaks.versions.outdated2=§6* §aLatest.........v§9%s -gctweaks.versions.updateMessage=["Click To... [",{"text":"Download","color":"green","hoverEvent":{"action":"show_text","value":{"text":"Click this to automatically download the latest version","color":"green"}},"clickEvent":{"action":"run_command","value":"/download-latest-gctweaks %version%"}},"]"] -gctweaks.versions.startingDownload=[{"text":"Starting download . . . . . Please do not remove your hard disk. Enjoying ","color":"aqua"},{"text":"GalacticTweaks?","color":"green"}] -gctweaks.versions.startingDownload2=[{"text":" Consider supporting ","color":"aqua"},{"text":"ROMVoid95","color":"light_purple"},{"text":" on [","color":"aqua"},{"text":"Patreon","color":"gold","hoverEvent":{"action":"show_text","value":{"text":"Click this to go to ROMVoid95's Patreon","color":"light_purple"}},"clickEvent":{"action":"open_url","value":"http://www.patreon.com/romvoid95"}},{"text":"]!","color":"aqua"}] -gctweaks.versions.doneDownloading=Finished downloading . . . . . Delete your old GalacticTweaks jar and reload your game to update. -gctweaks.versions.downloadedAlready=You already downloaded the latest version. Close your game, delete the old version from your mods folder and load it again to update! -gctweaks.versions.downloadingAlready=The update is already downloading, give it some time, will you? \ No newline at end of file diff --git a/src/main/resources/assets/gtweaks/lang/ru_ru.lang b/src/main/resources/assets/gtweaks/lang/ru_ru.lang deleted file mode 100644 index e2aa6c3..0000000 --- a/src/main/resources/assets/gtweaks/lang/ru_ru.lang +++ /dev/null @@ -1,5 +0,0 @@ -galaxy.wormhole= Алт Солнце -solarsystem.secondSystem=Альтернативное Солнце -star.epsystem=Солнце -planet.fakeOverworld=Земля -planet.fakeRocks=Астероиды \ No newline at end of file diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info index 31145f9..4573d92 100644 --- a/src/main/resources/mcmod.info +++ b/src/main/resources/mcmod.info @@ -1,12 +1,12 @@ [ { - "modid": "gtweaks", + "modid": "gctweaks", "name": "GalacticTweaks", "description": "Tweaking Mod to Galacticraft", "version": "${version}", "mcversion": "${mcversion}", "url": "https://www.curseforge.com/minecraft/mc-mods/galactictweaks", - "updateUrl": "https://github.com/ROMVoid95/GalacticTweaks/blob/dev/update.json", + "updateUrl": "", "authorList": ["ROMVoid95"], "credits": "", "logoFile": "", diff --git a/src/main/resources/mixins.galactictweaks.json b/src/main/resources/mixins.galactictweaks.json deleted file mode 100644 index 4818d74..0000000 --- a/src/main/resources/mixins.galactictweaks.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "required": true, - "minVersion": "0.7.11", - "compatibilityLevel": "JAVA_8", - "package": "net.rom.gctweaks.core.mixins", - "plugin": "net.rom.gctweaks.core.mixins.GalacticTweaksMixinPlugin", - "refmap": "mixins.galactictweaks.refmap.json", - "target": "@env(DEFAULT)", - "mixins": [ - "CommandLocateMixin" - ], - "injectors": { - "defaultRequire": 1 - } -} \ No newline at end of file diff --git a/src/main/resources/pack.mcmeta b/src/main/resources/pack.mcmeta deleted file mode 100644 index 0295b71..0000000 --- a/src/main/resources/pack.mcmeta +++ /dev/null @@ -1,6 +0,0 @@ -{ - "pack":{ - "pack_format": 3, - "description": "" - } -} \ No newline at end of file