aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/kubatech/api/utils
diff options
context:
space:
mode:
authorJason Mitchell <mitchej@gmail.com>2023-01-28 19:03:53 -0800
committerJason Mitchell <mitchej@gmail.com>2023-01-28 19:03:53 -0800
commitf51616bda220887fdd45c4bc951ff59e3398213a (patch)
tree35fdbb15b4c7ea0282773a388eff517a1d09d941 /src/main/java/kubatech/api/utils
parent11216d666cbc30fc1e1dfc84e1e0c2f4252b1fc2 (diff)
downloadGT5-Unofficial-f51616bda220887fdd45c4bc951ff59e3398213a.tar.gz
GT5-Unofficial-f51616bda220887fdd45c4bc951ff59e3398213a.tar.bz2
GT5-Unofficial-f51616bda220887fdd45c4bc951ff59e3398213a.zip
[ci skip] spotlessApply with the new settings
Diffstat (limited to 'src/main/java/kubatech/api/utils')
-rw-r--r--src/main/java/kubatech/api/utils/FastRandom.java23
-rw-r--r--src/main/java/kubatech/api/utils/GSONUtils.java45
-rw-r--r--src/main/java/kubatech/api/utils/ItemID.java25
-rw-r--r--src/main/java/kubatech/api/utils/MobUtils.java33
-rw-r--r--src/main/java/kubatech/api/utils/ModUtils.java67
-rw-r--r--src/main/java/kubatech/api/utils/StringUtils.java54
6 files changed, 89 insertions, 158 deletions
diff --git a/src/main/java/kubatech/api/utils/FastRandom.java b/src/main/java/kubatech/api/utils/FastRandom.java
index 03699d2b62..33d157a1aa 100644
--- a/src/main/java/kubatech/api/utils/FastRandom.java
+++ b/src/main/java/kubatech/api/utils/FastRandom.java
@@ -1,20 +1,11 @@
/*
- * KubaTech - Gregtech Addon
- * Copyright (C) 2022 - 2023 kuba6000
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This library 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this library. If not, see <https://www.gnu.org/licenses/>.
- *
+ * KubaTech - Gregtech Addon Copyright (C) 2022 - 2023 kuba6000 This library is free software; you can redistribute it
+ * and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation; either version 3 of the License, or (at your option) any later version. This library 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 Lesser General Public License for more details. You should have
+ * received a copy of the GNU Lesser General Public License along with this library. If not, see
+ * <https://www.gnu.org/licenses/>.
*/
package kubatech.api.utils;
diff --git a/src/main/java/kubatech/api/utils/GSONUtils.java b/src/main/java/kubatech/api/utils/GSONUtils.java
index 1882a1e346..99580ad803 100644
--- a/src/main/java/kubatech/api/utils/GSONUtils.java
+++ b/src/main/java/kubatech/api/utils/GSONUtils.java
@@ -1,40 +1,35 @@
/*
- * KubaTech - Gregtech Addon
- * Copyright (C) 2022 - 2023 kuba6000
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This library 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this library. If not, see <https://www.gnu.org/licenses/>.
- *
+ * KubaTech - Gregtech Addon Copyright (C) 2022 - 2023 kuba6000 This library is free software; you can redistribute it
+ * and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation; either version 3 of the License, or (at your option) any later version. This library 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 Lesser General Public License for more details. You should have
+ * received a copy of the GNU Lesser General Public License along with this library. If not, see
+ * <https://www.gnu.org/licenses/>.
*/
package kubatech.api.utils;
-import com.google.gson.*;
import java.io.IOException;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
+
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTSizeTracker;
import net.minecraft.nbt.NBTTagCompound;
+import com.google.gson.*;
+
public class GSONUtils {
+
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface SkipGSON {}
private static final ExclusionStrategy GSONStrategy = new ExclusionStrategy() {
+
@Override
public boolean shouldSkipField(FieldAttributes f) {
return f.getAnnotation(SkipGSON.class) != null;
@@ -62,25 +57,19 @@ public class GSONUtils {
try {
if (!(json instanceof JsonArray)) return null;
byte[] bytes = new byte[((JsonArray) json).size()];
- for (int i = 0; i < bytes.length; i++)
- bytes[i] = ((JsonArray) json).get(i).getAsByte();
+ for (int i = 0; i < bytes.length; i++) bytes[i] = ((JsonArray) json).get(i).getAsByte();
return CompressedStreamTools.func_152457_a(bytes, new NBTSizeTracker(2097152L));
} catch (IOException e) {
throw new RuntimeException(e);
}
};
- public static final GsonBuilder GSON_BUILDER = new GsonBuilder()
- .addSerializationExclusionStrategy(GSONStrategy)
+ public static final GsonBuilder GSON_BUILDER = new GsonBuilder().addSerializationExclusionStrategy(GSONStrategy)
.addDeserializationExclusionStrategy(GSONStrategy)
.registerTypeAdapter(NBTTagCompound.class, NBTTagCompoundDeserializer)
- .registerTypeAdapter(NBTTagCompound.class, NBTTagCompoundSerializer)
- .serializeNulls();
+ .registerTypeAdapter(NBTTagCompound.class, NBTTagCompoundSerializer).serializeNulls();
public static final GsonBuilder GSON_BUILDER_PRETTY = new GsonBuilder()
- .addSerializationExclusionStrategy(GSONStrategy)
- .addDeserializationExclusionStrategy(GSONStrategy)
+ .addSerializationExclusionStrategy(GSONStrategy).addDeserializationExclusionStrategy(GSONStrategy)
.registerTypeAdapter(NBTTagCompound.class, NBTTagCompoundDeserializer)
- .registerTypeAdapter(NBTTagCompound.class, NBTTagCompoundSerializer)
- .serializeNulls()
- .setPrettyPrinting();
+ .registerTypeAdapter(NBTTagCompound.class, NBTTagCompoundSerializer).serializeNulls().setPrettyPrinting();
}
diff --git a/src/main/java/kubatech/api/utils/ItemID.java b/src/main/java/kubatech/api/utils/ItemID.java
index d296c7d80d..c2060e59bc 100644
--- a/src/main/java/kubatech/api/utils/ItemID.java
+++ b/src/main/java/kubatech/api/utils/ItemID.java
@@ -1,30 +1,23 @@
/*
- * KubaTech - Gregtech Addon
- * Copyright (C) 2022 - 2023 kuba6000
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This library 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this library. If not, see <https://www.gnu.org/licenses/>.
- *
+ * KubaTech - Gregtech Addon Copyright (C) 2022 - 2023 kuba6000 This library is free software; you can redistribute it
+ * and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation; either version 3 of the License, or (at your option) any later version. This library 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 Lesser General Public License for more details. You should have
+ * received a copy of the GNU Lesser General Public License along with this library. If not, see
+ * <https://www.gnu.org/licenses/>.
*/
package kubatech.api.utils;
import java.util.Objects;
+
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
public class ItemID {
+
private final Item item;
private final int count;
private final int meta;
diff --git a/src/main/java/kubatech/api/utils/MobUtils.java b/src/main/java/kubatech/api/utils/MobUtils.java
index 76bec7b988..0a6881edeb 100644
--- a/src/main/java/kubatech/api/utils/MobUtils.java
+++ b/src/main/java/kubatech/api/utils/MobUtils.java
@@ -1,27 +1,17 @@
/*
- * KubaTech - Gregtech Addon
- * Copyright (C) 2022 - 2023 kuba6000
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This library 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this library. If not, see <https://www.gnu.org/licenses/>.
- *
+ * KubaTech - Gregtech Addon Copyright (C) 2022 - 2023 kuba6000 This library is free software; you can redistribute it
+ * and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation; either version 3 of the License, or (at your option) any later version. This library 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 Lesser General Public License for more details. You should have
+ * received a copy of the GNU Lesser General Public License along with this library. If not, see
+ * <https://www.gnu.org/licenses/>.
*/
package kubatech.api.utils;
-import cpw.mods.fml.relauncher.Side;
-import cpw.mods.fml.relauncher.SideOnly;
import java.lang.reflect.Field;
+
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelBox;
import net.minecraft.client.model.ModelRenderer;
@@ -30,6 +20,9 @@ import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.entity.RendererLivingEntity;
import net.minecraft.entity.EntityLiving;
+import cpw.mods.fml.relauncher.Side;
+import cpw.mods.fml.relauncher.SideOnly;
+
public class MobUtils {
private static Field mainmodelfield = null;
@@ -48,8 +41,8 @@ public class MobUtils {
public static float getMobHeight(EntityLiving e) {
try {
if (mainmodelfield == null) {
- mainmodelfield = RendererLivingEntity.class.getDeclaredField(
- ModUtils.isDeobfuscatedEnvironment ? "mainModel" : "field_77045_g");
+ mainmodelfield = RendererLivingEntity.class
+ .getDeclaredField(ModUtils.isDeobfuscatedEnvironment ? "mainModel" : "field_77045_g");
mainmodelfield.setAccessible(true);
}
float eheight = e.height;
diff --git a/src/main/java/kubatech/api/utils/ModUtils.java b/src/main/java/kubatech/api/utils/ModUtils.java
index 6870a8801d..a09b3b68ee 100644
--- a/src/main/java/kubatech/api/utils/ModUtils.java
+++ b/src/main/java/kubatech/api/utils/ModUtils.java
@@ -1,35 +1,30 @@
/*
- * KubaTech - Gregtech Addon
- * Copyright (C) 2022 - 2023 kuba6000
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This library 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this library. If not, see <https://www.gnu.org/licenses/>.
- *
+ * KubaTech - Gregtech Addon Copyright (C) 2022 - 2023 kuba6000 This library is free software; you can redistribute it
+ * and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation; either version 3 of the License, or (at your option) any later version. This library 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 Lesser General Public License for more details. You should have
+ * received a copy of the GNU Lesser General Public License along with this library. If not, see
+ * <https://www.gnu.org/licenses/>.
*/
package kubatech.api.utils;
-import cpw.mods.fml.common.Loader;
-import cpw.mods.fml.common.ModContainer;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.util.*;
+
import javax.xml.bind.DatatypeConverter;
+
import net.minecraft.launchwrapper.Launch;
+import cpw.mods.fml.common.Loader;
+import cpw.mods.fml.common.ModContainer;
+
public class ModUtils {
- public static final boolean isDeobfuscatedEnvironment =
- (boolean) Launch.blackboard.get("fml.deobfuscatedEnvironment");
+
+ public static final boolean isDeobfuscatedEnvironment = (boolean) Launch.blackboard
+ .get("fml.deobfuscatedEnvironment");
public static boolean isClientSided = false;
private static final HashMap<String, String> classNamesToModIDs = new HashMap<>();
private static final Map.Entry<String, String> emptyEntry = new AbstractMap.SimpleEntry<>("", "");
@@ -39,15 +34,11 @@ public class ModUtils {
classNamesToModIDs.put("net.minecraft", "Minecraft");
Loader.instance().getActiveModList().forEach(m -> {
Object Mod = m.getMod();
- if (Mod != null)
- classNamesToModIDs.put(Mod.getClass().getPackage().getName(), m.getName());
+ if (Mod != null) classNamesToModIDs.put(Mod.getClass().getPackage().getName(), m.getName());
});
}
- return classNamesToModIDs.entrySet().stream()
- .filter(e -> classname.startsWith(e.getKey()))
- .findAny()
- .orElse(emptyEntry)
- .getValue();
+ return classNamesToModIDs.entrySet().stream().filter(e -> classname.startsWith(e.getKey())).findAny()
+ .orElse(emptyEntry).getValue();
}
private static String modListVersion = null;
@@ -55,10 +46,9 @@ public class ModUtils {
public static String getModListVersion() {
if (modListVersion != null) return modListVersion;
@SuppressWarnings("unchecked")
- ArrayList<ModContainer> modlist = (ArrayList<ModContainer>)
- ((ArrayList<ModContainer>) Loader.instance().getActiveModList()).clone();
- String sortedList = modlist.stream()
- .filter(m -> m.getMod() != null)
+ ArrayList<ModContainer> modlist = (ArrayList<ModContainer>) ((ArrayList<ModContainer>) Loader.instance()
+ .getActiveModList()).clone();
+ String sortedList = modlist.stream().filter(m -> m.getMod() != null)
.sorted(Comparator.comparing(ModContainer::getModId))
.collect(
StringBuilder::new,
@@ -81,19 +71,16 @@ public class ModUtils {
public static String getModListVersionIgnoringModVersions() {
if (modListVersionIgnoringModVersions != null) return modListVersionIgnoringModVersions;
@SuppressWarnings("unchecked")
- ArrayList<ModContainer> modlist = (ArrayList<ModContainer>)
- ((ArrayList<ModContainer>) Loader.instance().getActiveModList()).clone();
- String sortedList = modlist.stream()
- .filter(m -> m.getMod() != null)
+ ArrayList<ModContainer> modlist = (ArrayList<ModContainer>) ((ArrayList<ModContainer>) Loader.instance()
+ .getActiveModList()).clone();
+ String sortedList = modlist.stream().filter(m -> m.getMod() != null)
.sorted(Comparator.comparing(ModContainer::getModId))
- .collect(StringBuilder::new, (a, b) -> a.append(b.getModId()), (a, b) -> a.append(", ")
- .append(b))
+ .collect(StringBuilder::new, (a, b) -> a.append(b.getModId()), (a, b) -> a.append(", ").append(b))
.toString();
try {
MessageDigest md = MessageDigest.getInstance("MD5");
- modListVersionIgnoringModVersions = DatatypeConverter.printHexBinary(
- md.digest(sortedList.getBytes(StandardCharsets.UTF_8)))
- .toUpperCase();
+ modListVersionIgnoringModVersions = DatatypeConverter
+ .printHexBinary(md.digest(sortedList.getBytes(StandardCharsets.UTF_8))).toUpperCase();
return modListVersionIgnoringModVersions;
} catch (Exception e) {
modListVersionIgnoringModVersions = sortedList;
diff --git a/src/main/java/kubatech/api/utils/StringUtils.java b/src/main/java/kubatech/api/utils/StringUtils.java
index f7bbdcf9b7..066fa69d4f 100644
--- a/src/main/java/kubatech/api/utils/StringUtils.java
+++ b/src/main/java/kubatech/api/utils/StringUtils.java
@@ -1,20 +1,11 @@
/*
- * KubaTech - Gregtech Addon
- * Copyright (C) 2022 - 2023 kuba6000
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This library 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this library. If not, see <https://www.gnu.org/licenses/>.
- *
+ * KubaTech - Gregtech Addon Copyright (C) 2022 - 2023 kuba6000 This library is free software; you can redistribute it
+ * and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation; either version 3 of the License, or (at your option) any later version. This library 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 Lesser General Public License for more details. You should have
+ * received a copy of the GNU Lesser General Public License along with this library. If not, see
+ * <https://www.gnu.org/licenses/>.
*/
package kubatech.api.utils;
@@ -23,33 +14,20 @@ import net.minecraft.util.EnumChatFormatting;
public class StringUtils {
- private static final String[] rainbow = new String[] {
- EnumChatFormatting.DARK_RED.toString(),
- EnumChatFormatting.RED.toString(),
- EnumChatFormatting.GOLD.toString(),
- EnumChatFormatting.YELLOW.toString(),
- EnumChatFormatting.DARK_GREEN.toString(),
- EnumChatFormatting.GREEN.toString(),
- EnumChatFormatting.AQUA.toString(),
- EnumChatFormatting.DARK_AQUA.toString(),
- EnumChatFormatting.DARK_BLUE.toString(),
- EnumChatFormatting.BLUE.toString(),
- EnumChatFormatting.LIGHT_PURPLE.toString(),
- EnumChatFormatting.DARK_PURPLE.toString(),
- EnumChatFormatting.WHITE.toString(),
- EnumChatFormatting.GRAY.toString(),
- EnumChatFormatting.DARK_GRAY.toString(),
- EnumChatFormatting.BLACK.toString(),
- };
+ private static final String[] rainbow = new String[] { EnumChatFormatting.DARK_RED.toString(),
+ EnumChatFormatting.RED.toString(), EnumChatFormatting.GOLD.toString(), EnumChatFormatting.YELLOW.toString(),
+ EnumChatFormatting.DARK_GREEN.toString(), EnumChatFormatting.GREEN.toString(),
+ EnumChatFormatting.AQUA.toString(), EnumChatFormatting.DARK_AQUA.toString(),
+ EnumChatFormatting.DARK_BLUE.toString(), EnumChatFormatting.BLUE.toString(),
+ EnumChatFormatting.LIGHT_PURPLE.toString(), EnumChatFormatting.DARK_PURPLE.toString(),
+ EnumChatFormatting.WHITE.toString(), EnumChatFormatting.GRAY.toString(),
+ EnumChatFormatting.DARK_GRAY.toString(), EnumChatFormatting.BLACK.toString(), };
public static String applyRainbow(String str, int offset, String additional) {
StringBuilder final_string = new StringBuilder();
int i = offset;
for (char c : str.toCharArray())
- final_string
- .append(rainbow[i++ % rainbow.length])
- .append(additional)
- .append(c);
+ final_string.append(rainbow[i++ % rainbow.length]).append(additional).append(c);
return final_string.toString();
}