Update #48 - Added some features from OptiFine

This commit is contained in:
lax1dude
2025-01-24 18:39:36 -08:00
parent 1f0d593a8c
commit e83a912e38
1056 changed files with 17706 additions and 898 deletions

View File

@ -0,0 +1,914 @@
package net.optifine.config;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import net.minecraft.block.Block;
import net.minecraft.block.BlockDoublePlant;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.item.Item;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumWorldBlockLayer;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.biome.BiomeGenBase;
import net.optifine.Config;
import net.optifine.ConnectedProperties;
public class ConnectedParser {
private String context = null;
public static final EnumDyeColor[] DYE_COLORS_INVALID = new EnumDyeColor[0];
private static final INameGetter<Enum> NAME_GETTER_ENUM = new INameGetter<Enum>() {
public String getName(Enum en) {
return en.name();
}
};
private static final INameGetter<EnumDyeColor> NAME_GETTER_DYE_COLOR = new INameGetter<EnumDyeColor>() {
public String getName(EnumDyeColor col) {
return col.getName();
}
};
public ConnectedParser(String context) {
this.context = context;
}
public String parseName(String path) {
String s = path;
int i = path.lastIndexOf(47);
if (i >= 0) {
s = path.substring(i + 1);
}
int j = s.lastIndexOf(46);
if (j >= 0) {
s = s.substring(0, j);
}
return s;
}
public String parseBasePath(String path) {
int i = path.lastIndexOf(47);
return i < 0 ? "" : path.substring(0, i);
}
public MatchBlock[] parseMatchBlocks(String propMatchBlocks) {
if (propMatchBlocks == null) {
return null;
} else {
List list = new ArrayList();
String[] astring = Config.tokenize(propMatchBlocks, " ");
for (int i = 0; i < astring.length; ++i) {
String s = astring[i];
MatchBlock[] amatchblock = this.parseMatchBlock(s);
if (amatchblock != null) {
list.addAll(Arrays.asList(amatchblock));
}
}
MatchBlock[] amatchblock1 = (MatchBlock[]) ((MatchBlock[]) list.toArray(new MatchBlock[list.size()]));
return amatchblock1;
}
}
public IBlockState parseBlockState(String str, IBlockState def) {
MatchBlock[] amatchblock = this.parseMatchBlock(str);
if (amatchblock == null) {
return def;
} else if (amatchblock.length != 1) {
return def;
} else {
MatchBlock matchblock = amatchblock[0];
int i = matchblock.getBlockId();
Block block = Block.getBlockById(i);
return block.getDefaultState();
}
}
public MatchBlock[] parseMatchBlock(String blockStr) {
if (blockStr == null) {
return null;
} else {
blockStr = blockStr.trim();
if (blockStr.length() <= 0) {
return null;
} else {
String[] astring = Config.tokenize(blockStr, ":");
String s = "minecraft";
int i = 0;
if (astring.length > 1 && this.isFullBlockName(astring)) {
s = astring[0];
i = 1;
} else {
s = "minecraft";
i = 0;
}
String s1 = astring[i];
String[] astring1 = (String[]) Arrays.copyOfRange(astring, i + 1, astring.length);
Block[] ablock = this.parseBlockPart(s, s1);
if (ablock == null) {
return null;
} else {
MatchBlock[] amatchblock = new MatchBlock[ablock.length];
for (int j = 0; j < ablock.length; ++j) {
Block block = ablock[j];
int k = Block.getIdFromBlock(block);
int[] aint = null;
if (astring1.length > 0) {
aint = this.parseBlockMetadatas(block, astring1);
if (aint == null) {
return null;
}
}
MatchBlock matchblock = new MatchBlock(k, aint);
amatchblock[j] = matchblock;
}
return amatchblock;
}
}
}
}
public boolean isFullBlockName(String[] parts) {
if (parts.length < 2) {
return false;
} else {
String s = parts[1];
return s.length() < 1 ? false : (this.startsWithDigit(s) ? false : !s.contains("="));
}
}
public boolean startsWithDigit(String str) {
if (str == null) {
return false;
} else if (str.length() < 1) {
return false;
} else {
char c0 = str.charAt(0);
return Character.isDigit(c0);
}
}
public Block[] parseBlockPart(String domain, String blockPart) {
if (this.startsWithDigit(blockPart)) {
int[] aint = this.parseIntList(blockPart);
if (aint == null) {
return null;
} else {
Block[] ablock1 = new Block[aint.length];
for (int j = 0; j < aint.length; ++j) {
int i = aint[j];
Block block1 = Block.getBlockById(i);
if (block1 == null) {
this.warn("Block not found for id: " + i);
return null;
}
ablock1[j] = block1;
}
return ablock1;
}
} else {
String s = domain + ":" + blockPart;
Block block = Block.getBlockFromName(s);
if (block == null) {
this.warn("Block not found for name: " + s);
return null;
} else {
Block[] ablock = new Block[] { block };
return ablock;
}
}
}
public int[] parseBlockMetadatas(Block block, String[] params) {
if (params.length <= 0) {
return null;
} else {
String s = params[0];
if (this.startsWithDigit(s)) {
int[] aint = this.parseIntList(s);
return aint;
} else {
IBlockState iblockstate = block.getDefaultState();
Collection collection = iblockstate.getPropertyNames();
Map<IProperty, List<Comparable>> map = new HashMap();
for (int i = 0; i < params.length; ++i) {
String s1 = params[i];
if (s1.length() > 0) {
String[] astring = Config.tokenize(s1, "=");
if (astring.length != 2) {
this.warn("Invalid block property: " + s1);
return null;
}
String s2 = astring[0];
String s3 = astring[1];
IProperty iproperty = ConnectedProperties.getProperty(s2, collection);
if (iproperty == null) {
this.warn("Property not found: " + s2 + ", block: " + block);
return null;
}
List<Comparable> list = (List) map.get(s2);
if (list == null) {
list = new ArrayList();
map.put(iproperty, list);
}
String[] astring1 = Config.tokenize(s3, ",");
for (int j = 0; j < astring1.length; ++j) {
String s4 = astring1[j];
Comparable comparable = parsePropertyValue(iproperty, s4);
if (comparable == null) {
this.warn(
"Property value not found: " + s4 + ", property: " + s2 + ", block: " + block);
return null;
}
list.add(comparable);
}
}
}
if (map.isEmpty()) {
return null;
} else {
List<Integer> list1 = new ArrayList();
for (int k = 0; k < 16; ++k) {
int l = k;
try {
IBlockState iblockstate1 = this.getStateFromMeta(block, l);
if (this.matchState(iblockstate1, map)) {
list1.add(Integer.valueOf(l));
}
} catch (IllegalArgumentException var18) {
;
}
}
if (list1.size() == 16) {
return null;
} else {
int[] aint1 = new int[list1.size()];
for (int i1 = 0; i1 < aint1.length; ++i1) {
aint1[i1] = ((Integer) list1.get(i1)).intValue();
}
return aint1;
}
}
}
}
}
private IBlockState getStateFromMeta(Block block, int md) {
try {
IBlockState iblockstate = block.getStateFromMeta(md);
if (block == Blocks.double_plant && md > 7) {
IBlockState iblockstate1 = block.getStateFromMeta(md & 7);
iblockstate = iblockstate.withProperty(BlockDoublePlant.VARIANT,
iblockstate1.getValue(BlockDoublePlant.VARIANT));
}
return iblockstate;
} catch (IllegalArgumentException var5) {
return block.getDefaultState();
}
}
public static Comparable parsePropertyValue(IProperty prop, String valStr) {
Class oclass = prop.getValueClass();
Comparable comparable = parseValue(valStr, oclass);
if (comparable == null) {
Collection collection = prop.getAllowedValues();
comparable = getPropertyValue(valStr, collection);
}
return comparable;
}
public static Comparable getPropertyValue(String value, Collection propertyValues) {
for (Object comparable0 : propertyValues) {
Comparable comparable = (Comparable) comparable0;
if (getValueName(comparable).equals(value)) {
return comparable;
}
}
return null;
}
private static Object getValueName(Comparable obj) {
if (obj instanceof IStringSerializable) {
IStringSerializable istringserializable = (IStringSerializable) obj;
return istringserializable.getName();
} else {
return obj.toString();
}
}
public static Comparable parseValue(String str, Class cls) {
if (cls == String.class) {
return str;
} else if (cls == Boolean.class) {
return Boolean.valueOf(str);
} else if (cls == Float.class) {
return Float.valueOf(str);
} else if (cls == Double.class) {
return Double.valueOf(str);
} else if (cls == Integer.class) {
return Integer.valueOf(str);
} else {
return cls == Long.class ? Long.valueOf(str) : null;
}
}
public boolean matchState(IBlockState bs, Map<IProperty, List<Comparable>> mapPropValues) {
for (IProperty iproperty : mapPropValues.keySet()) {
List<Comparable> list = (List) mapPropValues.get(iproperty);
Comparable comparable = bs.getValue(iproperty);
if (comparable == null) {
return false;
}
if (!list.contains(comparable)) {
return false;
}
}
return true;
}
public BiomeGenBase[] parseBiomes(String str) {
if (str == null) {
return null;
} else {
str = str.trim();
boolean flag = false;
if (str.startsWith("!")) {
flag = true;
str = str.substring(1);
}
String[] astring = Config.tokenize(str, " ");
List list = new ArrayList();
for (int i = 0; i < astring.length; ++i) {
String s = astring[i];
BiomeGenBase biomegenbase = this.findBiome(s);
if (biomegenbase == null) {
this.warn("Biome not found: " + s);
} else {
list.add(biomegenbase);
}
}
if (flag) {
List<BiomeGenBase> list1 = new ArrayList(Arrays.asList(BiomeGenBase.getBiomeGenArray()));
list1.removeAll(list);
list = list1;
}
BiomeGenBase[] abiomegenbase = (BiomeGenBase[]) ((BiomeGenBase[]) list
.toArray(new BiomeGenBase[list.size()]));
return abiomegenbase;
}
}
public BiomeGenBase findBiome(String biomeName) {
biomeName = biomeName.toLowerCase();
if (biomeName.equals("nether")) {
return BiomeGenBase.hell;
} else {
BiomeGenBase[] abiomegenbase = BiomeGenBase.getBiomeGenArray();
for (int i = 0; i < abiomegenbase.length; ++i) {
BiomeGenBase biomegenbase = abiomegenbase[i];
if (biomegenbase != null) {
String s = biomegenbase.biomeName.replace(" ", "").toLowerCase();
if (s.equals(biomeName)) {
return biomegenbase;
}
}
}
return null;
}
}
public int parseInt(String str, int defVal) {
if (str == null) {
return defVal;
} else {
str = str.trim();
int i = Config.parseInt(str, -1);
if (i < 0) {
this.warn("Invalid number: " + str);
return defVal;
} else {
return i;
}
}
}
public int[] parseIntList(String str) {
if (str == null) {
return null;
} else {
List<Integer> list = new ArrayList();
String[] astring = Config.tokenize(str, " ,");
for (int i = 0; i < astring.length; ++i) {
String s = astring[i];
if (s.contains("-")) {
String[] astring1 = Config.tokenize(s, "-");
if (astring1.length != 2) {
this.warn("Invalid interval: " + s + ", when parsing: " + str);
} else {
int k = Config.parseInt(astring1[0], -1);
int l = Config.parseInt(astring1[1], -1);
if (k >= 0 && l >= 0 && k <= l) {
for (int i1 = k; i1 <= l; ++i1) {
list.add(Integer.valueOf(i1));
}
} else {
this.warn("Invalid interval: " + s + ", when parsing: " + str);
}
}
} else {
int j = Config.parseInt(s, -1);
if (j < 0) {
this.warn("Invalid number: " + s + ", when parsing: " + str);
} else {
list.add(Integer.valueOf(j));
}
}
}
int[] aint = new int[list.size()];
for (int j1 = 0; j1 < aint.length; ++j1) {
aint[j1] = ((Integer) list.get(j1)).intValue();
}
return aint;
}
}
public boolean[] parseFaces(String str, boolean[] defVal) {
if (str == null) {
return defVal;
} else {
EnumSet enumset = EnumSet.allOf(EnumFacing.class);
String[] astring = Config.tokenize(str, " ,");
for (int i = 0; i < astring.length; ++i) {
String s = astring[i];
if (s.equals("sides")) {
enumset.add(EnumFacing.NORTH);
enumset.add(EnumFacing.SOUTH);
enumset.add(EnumFacing.WEST);
enumset.add(EnumFacing.EAST);
} else if (s.equals("all")) {
enumset.addAll(Arrays.asList(EnumFacing._VALUES));
} else {
EnumFacing enumfacing = this.parseFace(s);
if (enumfacing != null) {
enumset.add(enumfacing);
}
}
}
boolean[] aboolean = new boolean[EnumFacing._VALUES.length];
for (int j = 0; j < aboolean.length; ++j) {
aboolean[j] = enumset.contains(EnumFacing._VALUES[j]);
}
return aboolean;
}
}
public EnumFacing parseFace(String str) {
str = str.toLowerCase();
if (!str.equals("bottom") && !str.equals("down")) {
if (!str.equals("top") && !str.equals("up")) {
if (str.equals("north")) {
return EnumFacing.NORTH;
} else if (str.equals("south")) {
return EnumFacing.SOUTH;
} else if (str.equals("east")) {
return EnumFacing.EAST;
} else if (str.equals("west")) {
return EnumFacing.WEST;
} else {
Config.warn("Unknown face: " + str);
return null;
}
} else {
return EnumFacing.UP;
}
} else {
return EnumFacing.DOWN;
}
}
public void dbg(String str) {
Config.dbg("" + this.context + ": " + str);
}
public void warn(String str) {
Config.warn("" + this.context + ": " + str);
}
public RangeListInt parseRangeListInt(String str) {
if (str == null) {
return null;
} else {
RangeListInt rangelistint = new RangeListInt();
String[] astring = Config.tokenize(str, " ,");
for (int i = 0; i < astring.length; ++i) {
String s = astring[i];
RangeInt rangeint = this.parseRangeInt(s);
if (rangeint == null) {
return null;
}
rangelistint.addRange(rangeint);
}
return rangelistint;
}
}
private RangeInt parseRangeInt(String str) {
if (str == null) {
return null;
} else if (str.indexOf(45) >= 0) {
String[] astring = Config.tokenize(str, "-");
if (astring.length != 2) {
this.warn("Invalid range: " + str);
return null;
} else {
int j = Config.parseInt(astring[0], -1);
int k = Config.parseInt(astring[1], -1);
if (j >= 0 && k >= 0) {
return new RangeInt(j, k);
} else {
this.warn("Invalid range: " + str);
return null;
}
}
} else {
int i = Config.parseInt(str, -1);
if (i < 0) {
this.warn("Invalid integer: " + str);
return null;
} else {
return new RangeInt(i, i);
}
}
}
public boolean parseBoolean(String str, boolean defVal) {
if (str == null) {
return defVal;
} else {
String s = str.toLowerCase().trim();
if (s.equals("true")) {
return true;
} else if (s.equals("false")) {
return false;
} else {
this.warn("Invalid boolean: " + str);
return defVal;
}
}
}
public Boolean parseBooleanObject(String str) {
if (str == null) {
return null;
} else {
String s = str.toLowerCase().trim();
if (s.equals("true")) {
return Boolean.TRUE;
} else if (s.equals("false")) {
return Boolean.FALSE;
} else {
this.warn("Invalid boolean: " + str);
return null;
}
}
}
public static int parseColor(String str, int defVal) {
if (str == null) {
return defVal;
} else {
str = str.trim();
try {
int i = Integer.parseInt(str, 16) & 16777215;
return i;
} catch (NumberFormatException var3) {
return defVal;
}
}
}
public static int parseColor4(String str, int defVal) {
if (str == null) {
return defVal;
} else {
str = str.trim();
try {
int i = (int) (Long.parseLong(str, 16) & -1L);
return i;
} catch (NumberFormatException var3) {
return defVal;
}
}
}
public EnumWorldBlockLayer parseBlockRenderLayer(String str, EnumWorldBlockLayer def) {
if (str == null) {
return def;
} else {
str = str.toLowerCase().trim();
EnumWorldBlockLayer[] aenumworldblocklayer = EnumWorldBlockLayer.values();
for (int i = 0; i < aenumworldblocklayer.length; ++i) {
EnumWorldBlockLayer enumworldblocklayer = aenumworldblocklayer[i];
if (str.equals(enumworldblocklayer.name().toLowerCase())) {
return enumworldblocklayer;
}
}
return def;
}
}
public <T> T parseObject(String str, T[] objs, INameGetter nameGetter, String property) {
if (str == null) {
return (T) null;
} else {
String s = str.toLowerCase().trim();
for (int i = 0; i < objs.length; ++i) {
T t = objs[i];
String s1 = nameGetter.getName(t);
if (s1 != null && s1.toLowerCase().equals(s)) {
return t;
}
}
this.warn("Invalid " + property + ": " + str);
return (T) null;
}
}
public <T> T[] parseObjects(String str, T[] objs, INameGetter nameGetter, String property, T[] errValue) {
if (str == null) {
return null;
} else {
str = str.toLowerCase().trim();
String[] astring = Config.tokenize(str, " ");
T[] at = (T[]) Array.newInstance(objs.getClass().getComponentType(), astring.length);
for (int i = 0; i < astring.length; ++i) {
String s = astring[i];
T t = this.parseObject(s, objs, nameGetter, property);
if (t == null) {
return (T[]) errValue;
}
at[i] = t;
}
return at;
}
}
public Enum parseEnum(String str, Enum[] enums, String property) {
return (Enum) this.parseObject(str, enums, NAME_GETTER_ENUM, property);
}
public Enum[] parseEnums(String str, Enum[] enums, String property, Enum[] errValue) {
return (Enum[]) this.parseObjects(str, enums, NAME_GETTER_ENUM, property, errValue);
}
public EnumDyeColor[] parseDyeColors(String str, String property, EnumDyeColor[] errValue) {
return (EnumDyeColor[]) this.parseObjects(str, EnumDyeColor.values(), NAME_GETTER_DYE_COLOR, property,
errValue);
}
public Weather[] parseWeather(String str, String property, Weather[] errValue) {
return (Weather[]) this.parseObjects(str, Weather.values(), NAME_GETTER_ENUM, property, errValue);
}
public NbtTagValue parseNbtTagValue(String path, String value) {
return path != null && value != null ? new NbtTagValue(path, value) : null;
}
private static int parseProfessionId(String str) {
int i = Config.parseInt(str, -1);
return i >= 0 ? i
: (str.equals("farmer") ? 0
: (str.equals("librarian") ? 1
: (str.equals("priest") ? 2
: (str.equals("blacksmith") ? 3
: (str.equals("butcher") ? 4 : (str.equals("nitwit") ? 5 : -1))))));
}
private static int[] parseCareerIds(int prof, String str) {
Set<Integer> set = new HashSet();
String[] astring = Config.tokenize(str, ",");
for (int i = 0; i < astring.length; ++i) {
String s = astring[i];
int j = parseCareerId(prof, s);
if (j < 0) {
return null;
}
set.add(Integer.valueOf(j));
}
Integer[] ainteger = (Integer[]) ((Integer[]) set.toArray(new Integer[set.size()]));
int[] aint = new int[ainteger.length];
for (int k = 0; k < aint.length; ++k) {
aint[k] = ainteger[k].intValue();
}
return aint;
}
private static int parseCareerId(int prof, String str) {
int i = Config.parseInt(str, -1);
if (i >= 0) {
return i;
} else {
if (prof == 0) {
if (str.equals("farmer")) {
return 1;
}
if (str.equals("fisherman")) {
return 2;
}
if (str.equals("shepherd")) {
return 3;
}
if (str.equals("fletcher")) {
return 4;
}
}
if (prof == 1) {
if (str.equals("librarian")) {
return 1;
}
if (str.equals("cartographer")) {
return 2;
}
}
if (prof == 2 && str.equals("cleric")) {
return 1;
} else {
if (prof == 3) {
if (str.equals("armor")) {
return 1;
}
if (str.equals("weapon")) {
return 2;
}
if (str.equals("tool")) {
return 3;
}
}
if (prof == 4) {
if (str.equals("butcher")) {
return 1;
}
if (str.equals("leather")) {
return 2;
}
}
return prof == 5 && str.equals("nitwit") ? 1 : -1;
}
}
}
public int[] parseItems(String str) {
str = str.trim();
Set<Integer> set = new TreeSet();
String[] astring = Config.tokenize(str, " ");
for (int i = 0; i < astring.length; ++i) {
String s = astring[i];
ResourceLocation resourcelocation = new ResourceLocation(s);
Item item = (Item) Item.itemRegistry.getObject(resourcelocation);
if (item == null) {
this.warn("Item not found: " + s);
} else {
int j = Item.getIdFromItem(item);
if (j < 0) {
this.warn("Item has no ID: " + item + ", name: " + s);
} else {
set.add(Integer.valueOf(j));
}
}
}
Integer[] ainteger = (Integer[]) ((Integer[]) set.toArray(new Integer[set.size()]));
int[] aint = Config.toPrimitive(ainteger);
return aint;
}
}

View File

@ -0,0 +1,46 @@
package net.optifine.config;
public class GlVersion {
private int major;
private int minor;
private int release;
private String suffix;
public GlVersion(int major, int minor) {
this(major, minor, 0);
}
public GlVersion(int major, int minor, int release) {
this(major, minor, release, (String) null);
}
public GlVersion(int major, int minor, int release, String suffix) {
this.major = major;
this.minor = minor;
this.release = release;
this.suffix = suffix;
}
public int getMajor() {
return this.major;
}
public int getMinor() {
return this.minor;
}
public int getRelease() {
return this.release;
}
public int toInt() {
return this.minor > 9 ? this.major * 100 + this.minor
: (this.release > 9 ? this.major * 100 + this.minor * 10 + 9
: this.major * 100 + this.minor * 10 + this.release);
}
public String toString() {
return this.suffix == null ? "" + this.major + "." + this.minor + "." + this.release
: "" + this.major + "." + this.minor + "." + this.release + this.suffix;
}
}

View File

@ -0,0 +1,5 @@
package net.optifine.config;
public interface INameGetter<T> {
String getName(T var1);
}

View File

@ -0,0 +1,7 @@
package net.optifine.config;
import net.minecraft.util.ResourceLocation;
public interface IObjectLocator {
Object getObject(ResourceLocation var1);
}

View File

@ -0,0 +1,5 @@
package net.optifine.config;
public interface IParserInt {
int parse(String var1, int var2);
}

View File

@ -0,0 +1,11 @@
package net.optifine.config;
import net.minecraft.item.Item;
import net.minecraft.util.ResourceLocation;
public class ItemLocator implements IObjectLocator {
public Object getObject(ResourceLocation loc) {
Item item = Item.getByNameOrId(loc.toString());
return item;
}
}

View File

@ -0,0 +1,61 @@
package net.optifine.config;
import net.minecraft.block.state.BlockStateBase;
import net.optifine.Config;
public class MatchBlock {
private int blockId = -1;
private int[] metadatas = null;
public MatchBlock(int blockId) {
this.blockId = blockId;
}
public MatchBlock(int blockId, int metadata) {
this.blockId = blockId;
if (metadata >= 0 && metadata <= 15) {
this.metadatas = new int[] { metadata };
}
}
public MatchBlock(int blockId, int[] metadatas) {
this.blockId = blockId;
this.metadatas = metadatas;
}
public int getBlockId() {
return this.blockId;
}
public int[] getMetadatas() {
return this.metadatas;
}
public boolean matches(BlockStateBase blockState) {
return blockState.getBlockId() != this.blockId ? false
: Matches.metadata(blockState.getMetadata(), this.metadatas);
}
public boolean matches(int id, int metadata) {
return id != this.blockId ? false : Matches.metadata(metadata, this.metadatas);
}
public void addMetadata(int metadata) {
if (this.metadatas != null) {
if (metadata >= 0 && metadata <= 15) {
for (int i = 0; i < this.metadatas.length; ++i) {
if (this.metadatas[i] == metadata) {
return;
}
}
this.metadatas = Config.addIntToArray(this.metadatas, metadata);
}
}
}
public String toString() {
return "" + this.blockId + ":" + Config.arrayToString(this.metadatas);
}
}

View File

@ -0,0 +1,97 @@
package net.optifine.config;
import net.lax1dude.eaglercraft.v1_8.minecraft.EaglerTextureAtlasSprite;
import net.minecraft.block.state.BlockStateBase;
import net.minecraft.world.biome.BiomeGenBase;
public class Matches {
public static boolean block(BlockStateBase blockStateBase, MatchBlock[] matchBlocks) {
if (matchBlocks == null) {
return true;
} else {
for (int i = 0; i < matchBlocks.length; ++i) {
MatchBlock matchblock = matchBlocks[i];
if (matchblock.matches(blockStateBase)) {
return true;
}
}
return false;
}
}
public static boolean block(int blockId, int metadata, MatchBlock[] matchBlocks) {
if (matchBlocks == null) {
return true;
} else {
for (int i = 0; i < matchBlocks.length; ++i) {
MatchBlock matchblock = matchBlocks[i];
if (matchblock.matches(blockId, metadata)) {
return true;
}
}
return false;
}
}
public static boolean blockId(int blockId, MatchBlock[] matchBlocks) {
if (matchBlocks == null) {
return true;
} else {
for (int i = 0; i < matchBlocks.length; ++i) {
MatchBlock matchblock = matchBlocks[i];
if (matchblock.getBlockId() == blockId) {
return true;
}
}
return false;
}
}
public static boolean metadata(int metadata, int[] metadatas) {
if (metadatas == null) {
return true;
} else {
for (int i = 0; i < metadatas.length; ++i) {
if (metadatas[i] == metadata) {
return true;
}
}
return false;
}
}
public static boolean sprite(EaglerTextureAtlasSprite sprite, EaglerTextureAtlasSprite[] sprites) {
if (sprites == null) {
return true;
} else {
for (int i = 0; i < sprites.length; ++i) {
if (sprites[i] == sprite) {
return true;
}
}
return false;
}
}
public static boolean biome(BiomeGenBase biome, BiomeGenBase[] biomes) {
if (biomes == null) {
return true;
} else {
for (int i = 0; i < biomes.length; ++i) {
if (biomes[i] == biome) {
return true;
}
}
return false;
}
}
}

View File

@ -0,0 +1,254 @@
package net.optifine.config;
import java.util.Arrays;
import java.util.regex.Pattern;
import org.apache.commons.lang3.StringEscapeUtils;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagByte;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagDouble;
import net.minecraft.nbt.NBTTagFloat;
import net.minecraft.nbt.NBTTagInt;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.nbt.NBTTagLong;
import net.minecraft.nbt.NBTTagShort;
import net.minecraft.nbt.NBTTagString;
import net.optifine.Config;
import net.optifine.util.StrUtils;
public class NbtTagValue {
private String[] parents = null;
private String name = null;
private boolean negative = false;
private int type = 0;
private String value = null;
private int valueFormat = 0;
private static final int TYPE_TEXT = 0;
private static final int TYPE_PATTERN = 1;
private static final int TYPE_IPATTERN = 2;
private static final int TYPE_REGEX = 3;
private static final int TYPE_IREGEX = 4;
private static final String PREFIX_PATTERN = "pattern:";
private static final String PREFIX_IPATTERN = "ipattern:";
private static final String PREFIX_REGEX = "regex:";
private static final String PREFIX_IREGEX = "iregex:";
private static final int FORMAT_DEFAULT = 0;
private static final int FORMAT_HEX_COLOR = 1;
private static final String PREFIX_HEX_COLOR = "#";
private static final Pattern PATTERN_HEX_COLOR = Pattern.compile("^#[0-9a-f]{6}+$");
public NbtTagValue(String tag, String value) {
String[] astring = Config.tokenize(tag, ".");
this.parents = (String[]) Arrays.copyOfRange(astring, 0, astring.length - 1);
this.name = astring[astring.length - 1];
if (value.startsWith("!")) {
this.negative = true;
value = value.substring(1);
}
if (value.startsWith("pattern:")) {
this.type = 1;
value = value.substring("pattern:".length());
} else if (value.startsWith("ipattern:")) {
this.type = 2;
value = value.substring("ipattern:".length()).toLowerCase();
} else if (value.startsWith("regex:")) {
this.type = 3;
value = value.substring("regex:".length());
} else if (value.startsWith("iregex:")) {
this.type = 4;
value = value.substring("iregex:".length()).toLowerCase();
} else {
this.type = 0;
}
value = StringEscapeUtils.unescapeJava(value);
if (this.type == 0 && PATTERN_HEX_COLOR.matcher(value).matches()) {
this.valueFormat = 1;
}
this.value = value;
}
public boolean matches(NBTTagCompound nbt) {
return this.negative ? !this.matchesCompound(nbt) : this.matchesCompound(nbt);
}
public boolean matchesCompound(NBTTagCompound nbt) {
if (nbt == null) {
return false;
} else {
NBTBase nbtbase = nbt;
for (int i = 0; i < this.parents.length; ++i) {
String s = this.parents[i];
nbtbase = getChildTag(nbtbase, s);
if (nbtbase == null) {
return false;
}
}
if (this.name.equals("*")) {
return this.matchesAnyChild(nbtbase);
} else {
nbtbase = getChildTag(nbtbase, this.name);
if (nbtbase == null) {
return false;
} else if (this.matchesBase(nbtbase)) {
return true;
} else {
return false;
}
}
}
}
private boolean matchesAnyChild(NBTBase tagBase) {
if (tagBase instanceof NBTTagCompound) {
NBTTagCompound nbttagcompound = (NBTTagCompound) tagBase;
for (String s : nbttagcompound.getKeySet()) {
NBTBase nbtbase = nbttagcompound.getTag(s);
if (this.matchesBase(nbtbase)) {
return true;
}
}
}
if (tagBase instanceof NBTTagList) {
NBTTagList nbttaglist = (NBTTagList) tagBase;
int i = nbttaglist.tagCount();
for (int j = 0; j < i; ++j) {
NBTBase nbtbase1 = nbttaglist.get(j);
if (this.matchesBase(nbtbase1)) {
return true;
}
}
}
return false;
}
private static NBTBase getChildTag(NBTBase tagBase, String tag) {
if (tagBase instanceof NBTTagCompound) {
NBTTagCompound nbttagcompound = (NBTTagCompound) tagBase;
return nbttagcompound.getTag(tag);
} else if (tagBase instanceof NBTTagList) {
NBTTagList nbttaglist = (NBTTagList) tagBase;
if (tag.equals("count")) {
return new NBTTagInt(nbttaglist.tagCount());
} else {
int i = Config.parseInt(tag, -1);
return i >= 0 && i < nbttaglist.tagCount() ? nbttaglist.get(i) : null;
}
} else {
return null;
}
}
public boolean matchesBase(NBTBase nbtBase) {
if (nbtBase == null) {
return false;
} else {
String s = getNbtString(nbtBase, this.valueFormat);
return this.matchesValue(s);
}
}
public boolean matchesValue(String nbtValue) {
if (nbtValue == null) {
return false;
} else {
switch (this.type) {
case 0:
return nbtValue.equals(this.value);
case 1:
return this.matchesPattern(nbtValue, this.value);
case 2:
return this.matchesPattern(nbtValue.toLowerCase(), this.value);
case 3:
return this.matchesRegex(nbtValue, this.value);
case 4:
return this.matchesRegex(nbtValue.toLowerCase(), this.value);
default:
throw new IllegalArgumentException("Unknown NbtTagValue type: " + this.type);
}
}
}
private boolean matchesPattern(String str, String pattern) {
return StrUtils.equalsMask(str, pattern, '*', '?');
}
private boolean matchesRegex(String str, String regex) {
return str.matches(regex);
}
private static String getNbtString(NBTBase nbtBase, int format) {
if (nbtBase == null) {
return null;
} else if (nbtBase instanceof NBTTagString) {
NBTTagString nbttagstring = (NBTTagString) nbtBase;
return nbttagstring.getString();
} else if (nbtBase instanceof NBTTagInt) {
NBTTagInt nbttagint = (NBTTagInt) nbtBase;
return format == 1 ? "#" + StrUtils.fillLeft(Integer.toHexString(nbttagint.getInt()), 6, '0')
: Integer.toString(nbttagint.getInt());
} else if (nbtBase instanceof NBTTagByte) {
NBTTagByte nbttagbyte = (NBTTagByte) nbtBase;
return Byte.toString(nbttagbyte.getByte());
} else if (nbtBase instanceof NBTTagShort) {
NBTTagShort nbttagshort = (NBTTagShort) nbtBase;
return Short.toString(nbttagshort.getShort());
} else if (nbtBase instanceof NBTTagLong) {
NBTTagLong nbttaglong = (NBTTagLong) nbtBase;
return Long.toString(nbttaglong.getLong());
} else if (nbtBase instanceof NBTTagFloat) {
NBTTagFloat nbttagfloat = (NBTTagFloat) nbtBase;
return Float.toString(nbttagfloat.getFloat());
} else if (nbtBase instanceof NBTTagDouble) {
NBTTagDouble nbttagdouble = (NBTTagDouble) nbtBase;
return Double.toString(nbttagdouble.getDouble());
} else {
return nbtBase.toString();
}
}
public String toString() {
StringBuffer stringbuffer = new StringBuffer();
for (int i = 0; i < this.parents.length; ++i) {
String s = this.parents[i];
if (i > 0) {
stringbuffer.append(".");
}
stringbuffer.append(s);
}
if (stringbuffer.length() > 0) {
stringbuffer.append(".");
}
stringbuffer.append(this.name);
stringbuffer.append(" = ");
stringbuffer.append(this.value);
return stringbuffer.toString();
}
}

View File

@ -0,0 +1,10 @@
package net.optifine.config;
import net.minecraft.enchantment.Enchantment;
public class ParserEnchantmentId implements IParserInt {
public int parse(String str, int defVal) {
Enchantment enchantment = Enchantment.getEnchantmentByLocation(str);
return enchantment == null ? defVal : enchantment.effectId;
}
}

View File

@ -0,0 +1,27 @@
package net.optifine.config;
public class RangeInt {
private int min;
private int max;
public RangeInt(int min, int max) {
this.min = Math.min(min, max);
this.max = Math.max(min, max);
}
public boolean isInRange(int val) {
return val < this.min ? false : val <= this.max;
}
public int getMin() {
return this.min;
}
public int getMax() {
return this.max;
}
public String toString() {
return "min: " + this.min + ", max: " + this.max;
}
}

View File

@ -0,0 +1,57 @@
package net.optifine.config;
public class RangeListInt {
private RangeInt[] ranges = new RangeInt[0];
public RangeListInt() {
}
public RangeListInt(RangeInt ri) {
this.addRange(ri);
}
public void addRange(RangeInt ri) {
RangeInt[] newRanges = new RangeInt[ranges.length + 1];
System.arraycopy(ranges, 0, newRanges, 0, ranges.length);
newRanges[ranges.length] = ri;
this.ranges = newRanges;
}
public boolean isInRange(int val) {
for (int i = 0; i < this.ranges.length; ++i) {
RangeInt rangeint = this.ranges[i];
if (rangeint.isInRange(val)) {
return true;
}
}
return false;
}
public int getCountRanges() {
return this.ranges.length;
}
public RangeInt getRange(int i) {
return this.ranges[i];
}
public String toString() {
StringBuffer stringbuffer = new StringBuffer();
stringbuffer.append("[");
for (int i = 0; i < this.ranges.length; ++i) {
RangeInt rangeint = this.ranges[i];
if (i > 0) {
stringbuffer.append(", ");
}
stringbuffer.append(rangeint.toString());
}
stringbuffer.append("]");
return stringbuffer.toString();
}
}

View File

@ -0,0 +1,18 @@
package net.optifine.config;
import net.minecraft.world.World;
public enum Weather {
CLEAR, RAIN, THUNDER;
public static Weather getWeather(World world, float partialTicks) {
float f = world.getThunderStrength(partialTicks);
if (f > 0.5F) {
return THUNDER;
} else {
float f1 = world.getRainStrength(partialTicks);
return f1 > 0.5F ? RAIN : CLEAR;
}
}
}