mirror of
https://github.com/Eaglercraft-Archive/Eaglercraftx-1.8.8-src.git
synced 2025-06-28 02:48:14 -05:00
Update #48 - Added some features from OptiFine
This commit is contained in:
24
sources/main/java/net/optifine/util/CounterInt.java
Normal file
24
sources/main/java/net/optifine/util/CounterInt.java
Normal file
@ -0,0 +1,24 @@
|
||||
package net.optifine.util;
|
||||
|
||||
public class CounterInt {
|
||||
private int startValue;
|
||||
private int value;
|
||||
|
||||
public CounterInt(int startValue) {
|
||||
this.startValue = startValue;
|
||||
this.value = startValue;
|
||||
}
|
||||
|
||||
public int nextValue() {
|
||||
int i = this.value++;
|
||||
return i;
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
this.value = this.startValue;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return this.value;
|
||||
}
|
||||
}
|
74
sources/main/java/net/optifine/util/MathUtils.java
Normal file
74
sources/main/java/net/optifine/util/MathUtils.java
Normal file
@ -0,0 +1,74 @@
|
||||
package net.optifine.util;
|
||||
|
||||
import net.minecraft.util.MathHelper;
|
||||
|
||||
public class MathUtils {
|
||||
public static final float PI = (float) Math.PI;
|
||||
public static final float PI2 = ((float) Math.PI * 2F);
|
||||
public static final float PId2 = ((float) Math.PI / 2F);
|
||||
// private static final float[] ASIN_TABLE = new float[65536];
|
||||
//
|
||||
// public static float asin(float value) {
|
||||
// return ASIN_TABLE[(int) ((double) (value + 1.0F) * 32767.5D) & 65535];
|
||||
// }
|
||||
//
|
||||
// public static float acos(float value) {
|
||||
// return ((float) Math.PI / 2F) - ASIN_TABLE[(int) ((double) (value + 1.0F) * 32767.5D) & 65535];
|
||||
// }
|
||||
|
||||
public static int getAverage(int[] vals) {
|
||||
if (vals.length <= 0) {
|
||||
return 0;
|
||||
} else {
|
||||
int i = getSum(vals);
|
||||
int j = i / vals.length;
|
||||
return j;
|
||||
}
|
||||
}
|
||||
|
||||
public static int getSum(int[] vals) {
|
||||
if (vals.length <= 0) {
|
||||
return 0;
|
||||
} else {
|
||||
int i = 0;
|
||||
|
||||
for (int j = 0; j < vals.length; ++j) {
|
||||
int k = vals[j];
|
||||
i += k;
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
public static int roundDownToPowerOfTwo(int val) {
|
||||
int i = MathHelper.roundUpToPowerOfTwo(val);
|
||||
return val == i ? i : i / 2;
|
||||
}
|
||||
|
||||
public static boolean equalsDelta(float f1, float f2, float delta) {
|
||||
return Math.abs(f1 - f2) <= delta;
|
||||
}
|
||||
|
||||
public static float toDeg(float angle) {
|
||||
return angle * 180.0F / PI;
|
||||
}
|
||||
|
||||
public static float toRad(float angle) {
|
||||
return angle / 180.0F * PI;
|
||||
}
|
||||
|
||||
public static float roundToFloat(double d) {
|
||||
return (float) ((double) Math.round(d * 1.0E8D) / 1.0E8D);
|
||||
}
|
||||
|
||||
// static {
|
||||
// for (int i = 0; i < 65536; ++i) {
|
||||
// ASIN_TABLE[i] = (float) Math.asin((double) i / 32767.5D - 1.0D);
|
||||
// }
|
||||
//
|
||||
// for (int j = -1; j < 2; ++j) {
|
||||
// ASIN_TABLE[(int) (((double) j + 1.0D) * 32767.5D) & 65535] = (float) Math.asin((double) j);
|
||||
// }
|
||||
// }
|
||||
}
|
17
sources/main/java/net/optifine/util/NumUtils.java
Normal file
17
sources/main/java/net/optifine/util/NumUtils.java
Normal file
@ -0,0 +1,17 @@
|
||||
package net.optifine.util;
|
||||
|
||||
public class NumUtils {
|
||||
public static float limit(float val, float min, float max) {
|
||||
return val < min ? min : (val > max ? max : val);
|
||||
}
|
||||
|
||||
public static int mod(int x, int y) {
|
||||
int i = x % y;
|
||||
|
||||
if (i < 0) {
|
||||
i += y;
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
}
|
27
sources/main/java/net/optifine/util/PropertiesOrdered.java
Normal file
27
sources/main/java/net/optifine/util/PropertiesOrdered.java
Normal file
@ -0,0 +1,27 @@
|
||||
package net.optifine.util;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.EaglerProperties;
|
||||
|
||||
public class PropertiesOrdered extends EaglerProperties {
|
||||
private Set<Object> keysOrdered = new LinkedHashSet();
|
||||
|
||||
public Object put(Object key, Object value) {
|
||||
this.keysOrdered.add(key);
|
||||
return super.put(key, value);
|
||||
}
|
||||
|
||||
public Set<Object> keySet() {
|
||||
Set<Object> set = super.keySet();
|
||||
this.keysOrdered.retainAll(set);
|
||||
return Collections.<Object>unmodifiableSet(this.keysOrdered);
|
||||
}
|
||||
|
||||
public Enumeration<Object> keys() {
|
||||
return Collections.<Object>enumeration(this.keySet());
|
||||
}
|
||||
}
|
54
sources/main/java/net/optifine/util/ResUtils.java
Normal file
54
sources/main/java/net/optifine/util/ResUtils.java
Normal file
@ -0,0 +1,54 @@
|
||||
package net.optifine.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.resources.IResourcePack;
|
||||
|
||||
public class ResUtils {
|
||||
|
||||
public static List<String> collectPropertyFiles(IResourcePack rp, String prefix) {
|
||||
List<String> ret = new ArrayList<>();
|
||||
for (String str : rp.getEaglerFileIndex().getPropertiesFiles()) {
|
||||
if (str.startsWith(prefix)) {
|
||||
ret.add(str);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static List<String> collectPropertyFiles(IResourcePack rp, String... prefixes) {
|
||||
List<String> ret = new ArrayList<>();
|
||||
for (String str : rp.getEaglerFileIndex().getPropertiesFiles()) {
|
||||
for (int i = 0; i < prefixes.length; ++i) {
|
||||
if (str.startsWith(prefixes[i])) {
|
||||
ret.add(str);
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static List<String> collectPotionFiles(IResourcePack rp, String prefix) {
|
||||
List<String> ret = new ArrayList<>();
|
||||
for (String str : rp.getEaglerFileIndex().getCITPotionsFiles()) {
|
||||
if (str.startsWith(prefix)) {
|
||||
ret.add(str);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static List<String> collectPotionFiles(IResourcePack rp, String... prefixes) {
|
||||
List<String> ret = new ArrayList<>();
|
||||
for (String str : rp.getEaglerFileIndex().getCITPotionsFiles()) {
|
||||
for (int i = 0; i < prefixes.length; ++i) {
|
||||
if (str.startsWith(prefixes[i])) {
|
||||
ret.add(str);
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
77
sources/main/java/net/optifine/util/SmoothFloat.java
Normal file
77
sources/main/java/net/optifine/util/SmoothFloat.java
Normal file
@ -0,0 +1,77 @@
|
||||
package net.optifine.util;
|
||||
|
||||
public class SmoothFloat {
|
||||
private float valueLast;
|
||||
private float timeFadeUpSec;
|
||||
private float timeFadeDownSec;
|
||||
private long timeLastMs;
|
||||
|
||||
public SmoothFloat(float valueLast, float timeFadeSec) {
|
||||
this(valueLast, timeFadeSec, timeFadeSec);
|
||||
}
|
||||
|
||||
public SmoothFloat(float valueLast, float timeFadeUpSec, float timeFadeDownSec) {
|
||||
this.valueLast = valueLast;
|
||||
this.timeFadeUpSec = timeFadeUpSec;
|
||||
this.timeFadeDownSec = timeFadeDownSec;
|
||||
this.timeLastMs = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public float getValueLast() {
|
||||
return this.valueLast;
|
||||
}
|
||||
|
||||
public float getTimeFadeUpSec() {
|
||||
return this.timeFadeUpSec;
|
||||
}
|
||||
|
||||
public float getTimeFadeDownSec() {
|
||||
return this.timeFadeDownSec;
|
||||
}
|
||||
|
||||
public long getTimeLastMs() {
|
||||
return this.timeLastMs;
|
||||
}
|
||||
|
||||
public float getSmoothValue(float value, float timeFadeUpSec, float timeFadeDownSec) {
|
||||
this.timeFadeUpSec = timeFadeUpSec;
|
||||
this.timeFadeDownSec = timeFadeDownSec;
|
||||
return this.getSmoothValue(value);
|
||||
}
|
||||
|
||||
public float getSmoothValue(float value) {
|
||||
long i = System.currentTimeMillis();
|
||||
float f = this.valueLast;
|
||||
long j = this.timeLastMs;
|
||||
float f1 = (float) (i - j) / 1000.0F;
|
||||
float f2 = value >= f ? this.timeFadeUpSec : this.timeFadeDownSec;
|
||||
float f3 = getSmoothValue(f, value, f1, f2);
|
||||
this.valueLast = f3;
|
||||
this.timeLastMs = i;
|
||||
return f3;
|
||||
}
|
||||
|
||||
public static float getSmoothValue(float valPrev, float value, float timeDeltaSec, float timeFadeSec) {
|
||||
if (timeDeltaSec <= 0.0F) {
|
||||
return valPrev;
|
||||
} else {
|
||||
float f = value - valPrev;
|
||||
float f1;
|
||||
|
||||
if (timeFadeSec > 0.0F && timeDeltaSec < timeFadeSec && Math.abs(f) > 1.0E-6F) {
|
||||
float f2 = timeFadeSec / timeDeltaSec;
|
||||
float f3 = 4.61F;
|
||||
float f4 = 0.13F;
|
||||
float f5 = 10.0F;
|
||||
float f6 = f3 - 1.0F / (f4 + f2 / f5);
|
||||
float f7 = timeDeltaSec / timeFadeSec * f6;
|
||||
f7 = NumUtils.limit(f7, 0.0F, 1.0F);
|
||||
f1 = valPrev + f * f7;
|
||||
} else {
|
||||
f1 = value;
|
||||
}
|
||||
|
||||
return f1;
|
||||
}
|
||||
}
|
||||
}
|
603
sources/main/java/net/optifine/util/StrUtils.java
Normal file
603
sources/main/java/net/optifine/util/StrUtils.java
Normal file
@ -0,0 +1,603 @@
|
||||
package net.optifine.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
public class StrUtils {
|
||||
public static boolean equalsMask(String str, String mask, char wildChar, char wildCharSingle) {
|
||||
if (mask != null && str != null) {
|
||||
if (mask.indexOf(wildChar) < 0) {
|
||||
return mask.indexOf(wildCharSingle) < 0 ? mask.equals(str)
|
||||
: equalsMaskSingle(str, mask, wildCharSingle);
|
||||
} else {
|
||||
List list = new ArrayList();
|
||||
String s = "" + wildChar;
|
||||
|
||||
if (mask.startsWith(s)) {
|
||||
list.add("");
|
||||
}
|
||||
|
||||
StringTokenizer stringtokenizer = new StringTokenizer(mask, s);
|
||||
|
||||
while (stringtokenizer.hasMoreElements()) {
|
||||
list.add(stringtokenizer.nextToken());
|
||||
}
|
||||
|
||||
if (mask.endsWith(s)) {
|
||||
list.add("");
|
||||
}
|
||||
|
||||
String s1 = (String) list.get(0);
|
||||
|
||||
if (!startsWithMaskSingle(str, s1, wildCharSingle)) {
|
||||
return false;
|
||||
} else {
|
||||
String s2 = (String) list.get(list.size() - 1);
|
||||
|
||||
if (!endsWithMaskSingle(str, s2, wildCharSingle)) {
|
||||
return false;
|
||||
} else {
|
||||
int i = 0;
|
||||
|
||||
for (int j = 0; j < ((List) list).size(); ++j) {
|
||||
String s3 = (String) list.get(j);
|
||||
|
||||
if (s3.length() > 0) {
|
||||
int k = indexOfMaskSingle(str, s3, i, wildCharSingle);
|
||||
|
||||
if (k < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
i = k + s3.length();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return mask == str;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean equalsMaskSingle(String str, String mask, char wildCharSingle) {
|
||||
if (str != null && mask != null) {
|
||||
if (str.length() != mask.length()) {
|
||||
return false;
|
||||
} else {
|
||||
for (int i = 0; i < mask.length(); ++i) {
|
||||
char c0 = mask.charAt(i);
|
||||
|
||||
if (c0 != wildCharSingle && str.charAt(i) != c0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
return str == mask;
|
||||
}
|
||||
}
|
||||
|
||||
private static int indexOfMaskSingle(String str, String mask, int startPos, char wildCharSingle) {
|
||||
if (str != null && mask != null) {
|
||||
if (startPos >= 0 && startPos <= str.length()) {
|
||||
if (str.length() < startPos + mask.length()) {
|
||||
return -1;
|
||||
} else {
|
||||
for (int i = startPos; i + mask.length() <= str.length(); ++i) {
|
||||
String s = str.substring(i, i + mask.length());
|
||||
|
||||
if (equalsMaskSingle(s, mask, wildCharSingle)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean endsWithMaskSingle(String str, String mask, char wildCharSingle) {
|
||||
if (str != null && mask != null) {
|
||||
if (str.length() < mask.length()) {
|
||||
return false;
|
||||
} else {
|
||||
String s = str.substring(str.length() - mask.length(), str.length());
|
||||
return equalsMaskSingle(s, mask, wildCharSingle);
|
||||
}
|
||||
} else {
|
||||
return str == mask;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean startsWithMaskSingle(String str, String mask, char wildCharSingle) {
|
||||
if (str != null && mask != null) {
|
||||
if (str.length() < mask.length()) {
|
||||
return false;
|
||||
} else {
|
||||
String s = str.substring(0, mask.length());
|
||||
return equalsMaskSingle(s, mask, wildCharSingle);
|
||||
}
|
||||
} else {
|
||||
return str == mask;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean equalsMask(String str, String[] masks, char wildChar) {
|
||||
for (int i = 0; i < masks.length; ++i) {
|
||||
String s = masks[i];
|
||||
|
||||
if (equalsMask(str, s, wildChar)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean equalsMask(String str, String mask, char wildChar) {
|
||||
if (mask != null && str != null) {
|
||||
if (mask.indexOf(wildChar) < 0) {
|
||||
return mask.equals(str);
|
||||
} else {
|
||||
List list = new ArrayList();
|
||||
String s = "" + wildChar;
|
||||
|
||||
if (mask.startsWith(s)) {
|
||||
list.add("");
|
||||
}
|
||||
|
||||
StringTokenizer stringtokenizer = new StringTokenizer(mask, s);
|
||||
|
||||
while (stringtokenizer.hasMoreElements()) {
|
||||
list.add(stringtokenizer.nextToken());
|
||||
}
|
||||
|
||||
if (mask.endsWith(s)) {
|
||||
list.add("");
|
||||
}
|
||||
|
||||
String s1 = (String) list.get(0);
|
||||
|
||||
if (!str.startsWith(s1)) {
|
||||
return false;
|
||||
} else {
|
||||
String s2 = (String) list.get(list.size() - 1);
|
||||
|
||||
if (!str.endsWith(s2)) {
|
||||
return false;
|
||||
} else {
|
||||
int i = 0;
|
||||
|
||||
for (int j = 0; j < ((List) list).size(); ++j) {
|
||||
String s3 = (String) list.get(j);
|
||||
|
||||
if (s3.length() > 0) {
|
||||
int k = str.indexOf(s3, i);
|
||||
|
||||
if (k < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
i = k + s3.length();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return mask == str;
|
||||
}
|
||||
}
|
||||
|
||||
public static String[] split(String str, String separators) {
|
||||
if (str != null && str.length() > 0) {
|
||||
if (separators == null) {
|
||||
return new String[] { str };
|
||||
} else {
|
||||
List list = new ArrayList();
|
||||
int i = 0;
|
||||
|
||||
for (int j = 0; j < str.length(); ++j) {
|
||||
char c0 = str.charAt(j);
|
||||
|
||||
if (equals(c0, separators)) {
|
||||
list.add(str.substring(i, j));
|
||||
i = j + 1;
|
||||
}
|
||||
}
|
||||
|
||||
list.add(str.substring(i, str.length()));
|
||||
return (String[]) ((String[]) list.toArray(new String[list.size()]));
|
||||
}
|
||||
} else {
|
||||
return new String[0];
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean equals(char ch, String matches) {
|
||||
for (int i = 0; i < matches.length(); ++i) {
|
||||
if (matches.charAt(i) == ch) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean equalsTrim(String a, String b) {
|
||||
if (a != null) {
|
||||
a = a.trim();
|
||||
}
|
||||
|
||||
if (b != null) {
|
||||
b = b.trim();
|
||||
}
|
||||
|
||||
return equals(a, b);
|
||||
}
|
||||
|
||||
public static boolean isEmpty(String string) {
|
||||
return string == null ? true : string.trim().length() <= 0;
|
||||
}
|
||||
|
||||
public static String stringInc(String str) {
|
||||
int i = parseInt(str, -1);
|
||||
|
||||
if (i == -1) {
|
||||
return "";
|
||||
} else {
|
||||
++i;
|
||||
String s = "" + i;
|
||||
return s.length() > str.length() ? "" : fillLeft("" + i, str.length(), '0');
|
||||
}
|
||||
}
|
||||
|
||||
public static int parseInt(String s, int defVal) {
|
||||
if (s == null) {
|
||||
return defVal;
|
||||
} else {
|
||||
try {
|
||||
return Integer.parseInt(s);
|
||||
} catch (NumberFormatException var3) {
|
||||
return defVal;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isFilled(String string) {
|
||||
return !isEmpty(string);
|
||||
}
|
||||
|
||||
public static String addIfNotContains(String target, String source) {
|
||||
for (int i = 0; i < source.length(); ++i) {
|
||||
if (target.indexOf(source.charAt(i)) < 0) {
|
||||
target = target + source.charAt(i);
|
||||
}
|
||||
}
|
||||
|
||||
return target;
|
||||
}
|
||||
|
||||
public static String fillLeft(String s, int len, char fillChar) {
|
||||
if (s == null) {
|
||||
s = "";
|
||||
}
|
||||
|
||||
if (s.length() >= len) {
|
||||
return s;
|
||||
} else {
|
||||
StringBuffer stringbuffer = new StringBuffer();
|
||||
int i = len - s.length();
|
||||
|
||||
while (stringbuffer.length() < i) {
|
||||
stringbuffer.append(fillChar);
|
||||
}
|
||||
|
||||
return stringbuffer.toString() + s;
|
||||
}
|
||||
}
|
||||
|
||||
public static String fillRight(String s, int len, char fillChar) {
|
||||
if (s == null) {
|
||||
s = "";
|
||||
}
|
||||
|
||||
if (s.length() >= len) {
|
||||
return s;
|
||||
} else {
|
||||
StringBuffer stringbuffer = new StringBuffer(s);
|
||||
|
||||
while (stringbuffer.length() < len) {
|
||||
stringbuffer.append(fillChar);
|
||||
}
|
||||
|
||||
return stringbuffer.toString();
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean equals(Object a, Object b) {
|
||||
return a == b ? true : (a != null && a.equals(b) ? true : b != null && b.equals(a));
|
||||
}
|
||||
|
||||
public static boolean startsWith(String str, String[] prefixes) {
|
||||
if (str == null) {
|
||||
return false;
|
||||
} else if (prefixes == null) {
|
||||
return false;
|
||||
} else {
|
||||
for (int i = 0; i < prefixes.length; ++i) {
|
||||
String s = prefixes[i];
|
||||
|
||||
if (str.startsWith(s)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean endsWith(String str, String[] suffixes) {
|
||||
if (str == null) {
|
||||
return false;
|
||||
} else if (suffixes == null) {
|
||||
return false;
|
||||
} else {
|
||||
for (int i = 0; i < suffixes.length; ++i) {
|
||||
String s = suffixes[i];
|
||||
|
||||
if (str.endsWith(s)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static String removePrefix(String str, String prefix) {
|
||||
if (str != null && prefix != null) {
|
||||
if (str.startsWith(prefix)) {
|
||||
str = str.substring(prefix.length());
|
||||
}
|
||||
|
||||
return str;
|
||||
} else {
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
public static String removeSuffix(String str, String suffix) {
|
||||
if (str != null && suffix != null) {
|
||||
if (str.endsWith(suffix)) {
|
||||
str = str.substring(0, str.length() - suffix.length());
|
||||
}
|
||||
|
||||
return str;
|
||||
} else {
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
public static String replaceSuffix(String str, String suffix, String suffixNew) {
|
||||
if (str != null && suffix != null) {
|
||||
if (!str.endsWith(suffix)) {
|
||||
return str;
|
||||
} else {
|
||||
if (suffixNew == null) {
|
||||
suffixNew = "";
|
||||
}
|
||||
|
||||
str = str.substring(0, str.length() - suffix.length());
|
||||
return str + suffixNew;
|
||||
}
|
||||
} else {
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
public static String replacePrefix(String str, String prefix, String prefixNew) {
|
||||
if (str != null && prefix != null) {
|
||||
if (!str.startsWith(prefix)) {
|
||||
return str;
|
||||
} else {
|
||||
if (prefixNew == null) {
|
||||
prefixNew = "";
|
||||
}
|
||||
|
||||
str = str.substring(prefix.length());
|
||||
return prefixNew + str;
|
||||
}
|
||||
} else {
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
public static int findPrefix(String[] strs, String prefix) {
|
||||
if (strs != null && prefix != null) {
|
||||
for (int i = 0; i < strs.length; ++i) {
|
||||
String s = strs[i];
|
||||
|
||||
if (s.startsWith(prefix)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
public static int findSuffix(String[] strs, String suffix) {
|
||||
if (strs != null && suffix != null) {
|
||||
for (int i = 0; i < strs.length; ++i) {
|
||||
String s = strs[i];
|
||||
|
||||
if (s.endsWith(suffix)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
public static String[] remove(String[] strs, int start, int end) {
|
||||
if (strs == null) {
|
||||
return strs;
|
||||
} else if (end > 0 && start < strs.length) {
|
||||
if (start >= end) {
|
||||
return strs;
|
||||
} else {
|
||||
List<String> list = new ArrayList(strs.length);
|
||||
|
||||
for (int i = 0; i < strs.length; ++i) {
|
||||
String s = strs[i];
|
||||
|
||||
if (i < start || i >= end) {
|
||||
list.add(s);
|
||||
}
|
||||
}
|
||||
|
||||
String[] astring = (String[]) list.toArray(new String[list.size()]);
|
||||
return astring;
|
||||
}
|
||||
} else {
|
||||
return strs;
|
||||
}
|
||||
}
|
||||
|
||||
public static String removeSuffix(String str, String[] suffixes) {
|
||||
if (str != null && suffixes != null) {
|
||||
int i = str.length();
|
||||
|
||||
for (int j = 0; j < suffixes.length; ++j) {
|
||||
String s = suffixes[j];
|
||||
str = removeSuffix(str, s);
|
||||
|
||||
if (str.length() != i) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return str;
|
||||
} else {
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
public static String removePrefix(String str, String[] prefixes) {
|
||||
if (str != null && prefixes != null) {
|
||||
int i = str.length();
|
||||
|
||||
for (int j = 0; j < prefixes.length; ++j) {
|
||||
String s = prefixes[j];
|
||||
str = removePrefix(str, s);
|
||||
|
||||
if (str.length() != i) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return str;
|
||||
} else {
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
public static String removePrefixSuffix(String str, String[] prefixes, String[] suffixes) {
|
||||
str = removePrefix(str, prefixes);
|
||||
str = removeSuffix(str, suffixes);
|
||||
return str;
|
||||
}
|
||||
|
||||
public static String removePrefixSuffix(String str, String prefix, String suffix) {
|
||||
return removePrefixSuffix(str, new String[] { prefix }, new String[] { suffix });
|
||||
}
|
||||
|
||||
public static String getSegment(String str, String start, String end) {
|
||||
if (str != null && start != null && end != null) {
|
||||
int i = str.indexOf(start);
|
||||
|
||||
if (i < 0) {
|
||||
return null;
|
||||
} else {
|
||||
int j = str.indexOf(end, i);
|
||||
return j < 0 ? null : str.substring(i, j + end.length());
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static String addSuffixCheck(String str, String suffix) {
|
||||
return str != null && suffix != null ? (str.endsWith(suffix) ? str : str + suffix) : str;
|
||||
}
|
||||
|
||||
public static String addPrefixCheck(String str, String prefix) {
|
||||
return str != null && prefix != null ? (str.endsWith(prefix) ? str : prefix + str) : str;
|
||||
}
|
||||
|
||||
public static String trim(String str, String chars) {
|
||||
if (str != null && chars != null) {
|
||||
str = trimLeading(str, chars);
|
||||
str = trimTrailing(str, chars);
|
||||
return str;
|
||||
} else {
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
public static String trimLeading(String str, String chars) {
|
||||
if (str != null && chars != null) {
|
||||
int i = str.length();
|
||||
|
||||
for (int j = 0; j < i; ++j) {
|
||||
char c0 = str.charAt(j);
|
||||
|
||||
if (chars.indexOf(c0) < 0) {
|
||||
return str.substring(j);
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
} else {
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
public static String trimTrailing(String str, String chars) {
|
||||
if (str != null && chars != null) {
|
||||
int i = str.length();
|
||||
int j;
|
||||
|
||||
for (j = i; j > 0; --j) {
|
||||
char c0 = str.charAt(j - 1);
|
||||
|
||||
if (chars.indexOf(c0) < 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return j == i ? str : str.substring(0, j);
|
||||
} else {
|
||||
return str;
|
||||
}
|
||||
}
|
||||
}
|
96
sources/main/java/net/optifine/util/TextureUtils.java
Normal file
96
sources/main/java/net/optifine/util/TextureUtils.java
Normal file
@ -0,0 +1,96 @@
|
||||
package net.optifine.util;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.resources.IReloadableResourceManager;
|
||||
import net.minecraft.client.resources.IResourceManager;
|
||||
import net.minecraft.client.resources.IResourceManagerReloadListener;
|
||||
import net.optifine.BetterGrass;
|
||||
import net.optifine.BetterSnow;
|
||||
import net.optifine.Config;
|
||||
import net.optifine.CustomItems;
|
||||
import net.optifine.CustomSky;
|
||||
import net.optifine.SmartLeaves;
|
||||
|
||||
public class TextureUtils {
|
||||
|
||||
public static String fixResourcePath(String path, String basePath) {
|
||||
String s = "assets/minecraft/";
|
||||
|
||||
if (path.startsWith(s)) {
|
||||
path = path.substring(s.length());
|
||||
return path;
|
||||
} else if (path.startsWith("./")) {
|
||||
path = path.substring(2);
|
||||
|
||||
if (!basePath.endsWith("/")) {
|
||||
basePath = basePath + "/";
|
||||
}
|
||||
|
||||
path = basePath + path;
|
||||
return path;
|
||||
} else {
|
||||
if (path.startsWith("/~")) {
|
||||
path = path.substring(1);
|
||||
}
|
||||
|
||||
String s1 = "mcpatcher/";
|
||||
|
||||
if (path.startsWith("~/")) {
|
||||
path = path.substring(2);
|
||||
path = s1 + path;
|
||||
return path;
|
||||
} else if (path.startsWith("/")) {
|
||||
path = s1 + path.substring(1);
|
||||
return path;
|
||||
} else {
|
||||
return path;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String getBasePath(String path) {
|
||||
int i = path.lastIndexOf(47);
|
||||
return i < 0 ? "" : path.substring(0, i);
|
||||
}
|
||||
|
||||
public static void registerResourceListener() {
|
||||
IResourceManager iresourcemanager = Minecraft.getMinecraft().getResourceManager();
|
||||
if (iresourcemanager instanceof IReloadableResourceManager) {
|
||||
IReloadableResourceManager ireloadableresourcemanager = (IReloadableResourceManager) iresourcemanager;
|
||||
IResourceManagerReloadListener iresourcemanagerreloadlistener = new IResourceManagerReloadListener() {
|
||||
public void onResourceManagerReload(IResourceManager var1) {
|
||||
TextureUtils.resourcesReloaded(var1);
|
||||
}
|
||||
};
|
||||
ireloadableresourcemanager.registerReloadListener(iresourcemanagerreloadlistener);
|
||||
}
|
||||
}
|
||||
|
||||
public static void resourcesReloaded(IResourceManager rm) {
|
||||
if (Minecraft.getMinecraft().getTextureMapBlocks() != null) {
|
||||
Config.dbg("*** Reloading custom textures ***");
|
||||
CustomSky.reset();
|
||||
// TextureAnimations.reset();
|
||||
// update();
|
||||
// NaturalTextures.update();
|
||||
BetterGrass.update();
|
||||
BetterSnow.update();
|
||||
// TextureAnimations.update();
|
||||
// CustomColors.update();
|
||||
CustomSky.update();
|
||||
// RandomEntities.update();
|
||||
CustomItems.updateModels();
|
||||
// CustomEntityModels.update();
|
||||
// Shaders.resourcesReloaded();
|
||||
// Lang.resourcesReloaded();
|
||||
// Config.updateTexturePackClouds();
|
||||
SmartLeaves.updateLeavesModels();
|
||||
// CustomPanorama.update();
|
||||
// CustomGuis.update();
|
||||
// LayerMooshroomMushroom.update();
|
||||
// CustomLoadingScreens.update();
|
||||
// CustomBlockLayers.update();
|
||||
Minecraft.getMinecraft().getTextureManager().tick();
|
||||
}
|
||||
}
|
||||
}
|
22
sources/main/java/net/optifine/util/TileEntityUtils.java
Normal file
22
sources/main/java/net/optifine/util/TileEntityUtils.java
Normal file
@ -0,0 +1,22 @@
|
||||
package net.optifine.util;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.IWorldNameable;
|
||||
|
||||
public class TileEntityUtils {
|
||||
public static String getTileEntityName(IBlockAccess blockAccess, BlockPos blockPos) {
|
||||
TileEntity tileentity = blockAccess.getTileEntity(blockPos);
|
||||
return getTileEntityName(tileentity);
|
||||
}
|
||||
|
||||
public static String getTileEntityName(TileEntity te) {
|
||||
if (!(te instanceof IWorldNameable)) {
|
||||
return null;
|
||||
} else {
|
||||
IWorldNameable iworldnameable = (IWorldNameable) te;
|
||||
return !iworldnameable.hasCustomName() ? null : iworldnameable.getName();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user