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,243 @@
package net.optifine;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Properties;
import net.lax1dude.eaglercraft.v1_8.minecraft.EaglerTextureAtlasSprite;
import net.minecraft.block.Block;
import net.minecraft.block.BlockDirt;
import net.minecraft.block.BlockGrass;
import net.minecraft.block.BlockMycelium;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.resources.model.IBakedModel;
import net.minecraft.init.Blocks;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.IBlockAccess;
import net.optifine.model.BlockModelUtils;
import net.optifine.util.PropertiesOrdered;
public class BetterGrass {
private static boolean betterGrass = true;
private static boolean betterMycelium = true;
private static boolean betterPodzol = true;
private static boolean betterGrassSnow = true;
private static boolean betterMyceliumSnow = true;
private static boolean betterPodzolSnow = true;
private static boolean grassMultilayer = false;
private static EaglerTextureAtlasSprite spriteGrass = null;
private static EaglerTextureAtlasSprite spriteGrassSide = null;
private static EaglerTextureAtlasSprite spriteMycelium = null;
private static EaglerTextureAtlasSprite spritePodzol = null;
private static EaglerTextureAtlasSprite spriteSnow = null;
private static boolean spritesLoaded = false;
private static IBakedModel modelCubeGrass = null;
private static IBakedModel modelCubeMycelium = null;
private static IBakedModel modelCubePodzol = null;
private static IBakedModel modelCubeSnow = null;
private static boolean modelsLoaded = false;
private static final String TEXTURE_GRASS_DEFAULT = "blocks/grass_top";
private static final String TEXTURE_GRASS_SIDE_DEFAULT = "blocks/grass_side";
private static final String TEXTURE_MYCELIUM_DEFAULT = "blocks/mycelium_top";
private static final String TEXTURE_PODZOL_DEFAULT = "blocks/dirt_podzol_top";
private static final String TEXTURE_SNOW_DEFAULT = "blocks/snow";
public static void updateIcons(TextureMap textureMap) {
spritesLoaded = false;
modelsLoaded = false;
loadProperties(textureMap);
}
public static void update() {
if (spritesLoaded) {
modelCubeGrass = BlockModelUtils.makeModelCube(spriteGrass, 0);
if (grassMultilayer) {
IBakedModel ibakedmodel = BlockModelUtils.makeModelCube(spriteGrassSide, -1);
modelCubeGrass = BlockModelUtils.joinModelsCube(ibakedmodel, modelCubeGrass);
}
modelCubeMycelium = BlockModelUtils.makeModelCube(spriteMycelium, -1);
modelCubePodzol = BlockModelUtils.makeModelCube(spritePodzol, 0);
modelCubeSnow = BlockModelUtils.makeModelCube(spriteSnow, -1);
modelsLoaded = true;
}
}
private static void loadProperties(TextureMap textureMap) {
betterGrass = true;
betterMycelium = true;
betterPodzol = true;
betterGrassSnow = true;
betterMyceliumSnow = true;
betterPodzolSnow = true;
spriteGrass = textureMap.registerSprite(new ResourceLocation("blocks/grass_top"));
spriteGrassSide = textureMap.registerSprite(new ResourceLocation("blocks/grass_side"));
spriteMycelium = textureMap.registerSprite(new ResourceLocation("blocks/mycelium_top"));
spritePodzol = textureMap.registerSprite(new ResourceLocation("blocks/dirt_podzol_top"));
spriteSnow = textureMap.registerSprite(new ResourceLocation("blocks/snow"));
spritesLoaded = true;
String s = "optifine/bettergrass.properties";
try (InputStream inputstream = Minecraft.getMinecraft().getResourceManager()
.getResource(new ResourceLocation(s)).getInputStream()) {
Properties properties = new PropertiesOrdered();
properties.load(inputstream);
inputstream.close();
betterGrass = getBoolean(properties, "grass", true);
betterMycelium = getBoolean(properties, "mycelium", true);
betterPodzol = getBoolean(properties, "podzol", true);
betterGrassSnow = getBoolean(properties, "grass.snow", true);
betterMyceliumSnow = getBoolean(properties, "mycelium.snow", true);
betterPodzolSnow = getBoolean(properties, "podzol.snow", true);
grassMultilayer = getBoolean(properties, "grass.multilayer", false);
spriteGrass = registerSprite(properties, "texture.grass", "blocks/grass_top", textureMap);
spriteGrassSide = registerSprite(properties, "texture.grass_side", "blocks/grass_side", textureMap);
spriteMycelium = registerSprite(properties, "texture.mycelium", "blocks/mycelium_top", textureMap);
spritePodzol = registerSprite(properties, "texture.podzol", "blocks/dirt_podzol_top", textureMap);
spriteSnow = registerSprite(properties, "texture.snow", "blocks/snow", textureMap);
} catch (IOException ioexception) {
Config.warn(
"Error reading: " + s + ", " + ioexception.getClass().getName() + ": " + ioexception.getMessage());
}
}
private static EaglerTextureAtlasSprite registerSprite(Properties props, String key, String textureDefault,
TextureMap textureMap) {
String s = props.getProperty(key);
if (s == null) {
s = textureDefault;
}
// ResourceLocation resourcelocation = new ResourceLocation("textures/" + s + ".png");
//
// if (!Config.hasResource(resourcelocation)) {
// Config.warn("BetterGrass texture not found: " + resourcelocation);
// s = textureDefault;
// }
ResourceLocation resourcelocation1 = new ResourceLocation(s);
EaglerTextureAtlasSprite textureatlassprite = textureMap.registerSprite(resourcelocation1, key);
return textureatlassprite;
}
public static List getFaceQuads(IBlockAccess blockAccess, IBlockState blockState, BlockPos blockPos,
EnumFacing facing, List quads) {
if (facing != EnumFacing.UP && facing != EnumFacing.DOWN) {
if (!modelsLoaded) {
return quads;
} else {
Block block = blockState.getBlock();
return block instanceof BlockMycelium
? getFaceQuadsMycelium(blockAccess, blockState, blockPos, facing, quads)
: (block instanceof BlockDirt
? getFaceQuadsDirt(blockAccess, blockState, blockPos, facing, quads)
: (block instanceof BlockGrass
? getFaceQuadsGrass(blockAccess, blockState, blockPos, facing, quads)
: quads));
}
} else {
return quads;
}
}
private static List getFaceQuadsMycelium(IBlockAccess blockAccess, IBlockState blockState, BlockPos blockPos,
EnumFacing facing, List quads) {
Block block = blockAccess.getBlockState(blockPos.up()).getBlock();
boolean flag = block == Blocks.snow || block == Blocks.snow_layer;
if (Config.isBetterGrassFancy()) {
if (flag) {
if (betterMyceliumSnow && getBlockAt(blockPos, facing, blockAccess) == Blocks.snow_layer) {
return modelCubeSnow.getFaceQuads(facing);
}
} else if (betterMycelium && getBlockAt(blockPos.down(), facing, blockAccess) == Blocks.mycelium) {
return modelCubeMycelium.getFaceQuads(facing);
}
} else if (flag) {
if (betterMyceliumSnow) {
return modelCubeSnow.getFaceQuads(facing);
}
} else if (betterMycelium) {
return modelCubeMycelium.getFaceQuads(facing);
}
return quads;
}
private static List getFaceQuadsDirt(IBlockAccess blockAccess, IBlockState blockState, BlockPos blockPos,
EnumFacing facing, List quads) {
Block block = getBlockAt(blockPos, EnumFacing.UP, blockAccess);
if (blockState.getValue(BlockDirt.VARIANT) != BlockDirt.DirtType.PODZOL) {
return quads;
} else {
boolean flag = block == Blocks.snow || block == Blocks.snow_layer;
if (Config.isBetterGrassFancy()) {
if (flag) {
if (betterPodzolSnow && getBlockAt(blockPos, facing, blockAccess) == Blocks.snow_layer) {
return modelCubeSnow.getFaceQuads(facing);
}
} else if (betterPodzol) {
BlockPos blockpos = blockPos.down().offset(facing);
IBlockState iblockstate = blockAccess.getBlockState(blockpos);
if (iblockstate.getBlock() == Blocks.dirt
&& iblockstate.getValue(BlockDirt.VARIANT) == BlockDirt.DirtType.PODZOL) {
return modelCubePodzol.getFaceQuads(facing);
}
}
} else if (flag) {
if (betterPodzolSnow) {
return modelCubeSnow.getFaceQuads(facing);
}
} else if (betterPodzol) {
return modelCubePodzol.getFaceQuads(facing);
}
return quads;
}
}
private static List getFaceQuadsGrass(IBlockAccess blockAccess, IBlockState blockState, BlockPos blockPos,
EnumFacing facing, List quads) {
Block block = blockAccess.getBlockState(blockPos.up()).getBlock();
boolean flag = block == Blocks.snow || block == Blocks.snow_layer;
if (Config.isBetterGrassFancy()) {
if (flag) {
if (betterGrassSnow && getBlockAt(blockPos, facing, blockAccess) == Blocks.snow_layer) {
return modelCubeSnow.getFaceQuads(facing);
}
} else if (betterGrass && getBlockAt(blockPos.down(), facing, blockAccess) == Blocks.grass) {
return modelCubeGrass.getFaceQuads(facing);
}
} else if (flag) {
if (betterGrassSnow) {
return modelCubeSnow.getFaceQuads(facing);
}
} else if (betterGrass) {
return modelCubeGrass.getFaceQuads(facing);
}
return quads;
}
private static Block getBlockAt(BlockPos blockPos, EnumFacing facing, IBlockAccess blockAccess) {
BlockPos blockpos = blockPos.offset(facing);
Block block = blockAccess.getBlockState(blockpos).getBlock();
return block;
}
private static boolean getBoolean(Properties props, String key, boolean def) {
String s = props.getProperty(key);
return s == null ? def : Boolean.parseBoolean(s);
}
}

View File

@ -0,0 +1,91 @@
package net.optifine;
import net.minecraft.block.Block;
import net.minecraft.block.BlockBush;
import net.minecraft.block.BlockDoublePlant;
import net.minecraft.block.BlockFence;
import net.minecraft.block.BlockFenceGate;
import net.minecraft.block.BlockFlower;
import net.minecraft.block.BlockFlowerPot;
import net.minecraft.block.BlockLever;
import net.minecraft.block.BlockMushroom;
import net.minecraft.block.BlockPane;
import net.minecraft.block.BlockRedstoneTorch;
import net.minecraft.block.BlockReed;
import net.minecraft.block.BlockSapling;
import net.minecraft.block.BlockSnow;
import net.minecraft.block.BlockTallGrass;
import net.minecraft.block.BlockTorch;
import net.minecraft.block.BlockWall;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.model.IBakedModel;
import net.minecraft.init.Blocks;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.IBlockAccess;
public class BetterSnow {
private static IBakedModel modelSnowLayer = null;
public static void update() {
modelSnowLayer = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes()
.getModelForState(Blocks.snow_layer.getDefaultState());
}
public static IBakedModel getModelSnowLayer() {
return modelSnowLayer;
}
public static IBlockState getStateSnowLayer() {
return Blocks.snow_layer.getDefaultState();
}
public static boolean shouldRender(IBlockAccess blockAccess, IBlockState blockState, BlockPos blockPos) {
Block block = blockState.getBlock();
return !checkBlock(block, blockState) ? false : hasSnowNeighbours(blockAccess, blockPos);
}
private static boolean hasSnowNeighbours(IBlockAccess blockAccess, BlockPos pos) {
Block block = Blocks.snow_layer;
return blockAccess.getBlockState(pos.north()).getBlock() != block
&& blockAccess.getBlockState(pos.south()).getBlock() != block
&& blockAccess.getBlockState(pos.west()).getBlock() != block
&& blockAccess.getBlockState(pos.east()).getBlock() != block ? false
: blockAccess.getBlockState(pos.down()).getBlock().isOpaqueCube();
}
private static boolean checkBlock(Block block, IBlockState blockState) {
if (block.isFullCube()) {
return false;
} else if (block.isOpaqueCube()) {
return false;
} else if (block instanceof BlockSnow) {
return false;
} else if (!(block instanceof BlockBush) || !(block instanceof BlockDoublePlant)
&& !(block instanceof BlockFlower) && !(block instanceof BlockMushroom)
&& !(block instanceof BlockSapling) && !(block instanceof BlockTallGrass)) {
if (!(block instanceof BlockFence) && !(block instanceof BlockFenceGate)
&& !(block instanceof BlockFlowerPot) && !(block instanceof BlockPane)
&& !(block instanceof BlockReed) && !(block instanceof BlockWall)) {
if (block instanceof BlockRedstoneTorch && blockState.getValue(BlockTorch.FACING) == EnumFacing.UP) {
return true;
} else {
if (block instanceof BlockLever) {
Object object = blockState.getValue(BlockLever.FACING);
if (object == BlockLever.EnumOrientation.UP_X || object == BlockLever.EnumOrientation.UP_Z) {
return true;
}
}
return false;
}
} else {
return true;
}
} else {
return true;
}
}
}

View File

@ -0,0 +1,78 @@
package net.optifine;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
public enum BlockDir {
DOWN(EnumFacing.DOWN), UP(EnumFacing.UP), NORTH(EnumFacing.NORTH), SOUTH(EnumFacing.SOUTH), WEST(EnumFacing.WEST),
EAST(EnumFacing.EAST), NORTH_WEST(EnumFacing.NORTH, EnumFacing.WEST), NORTH_EAST(EnumFacing.NORTH, EnumFacing.EAST),
SOUTH_WEST(EnumFacing.SOUTH, EnumFacing.WEST), SOUTH_EAST(EnumFacing.SOUTH, EnumFacing.EAST),
DOWN_NORTH(EnumFacing.DOWN, EnumFacing.NORTH), DOWN_SOUTH(EnumFacing.DOWN, EnumFacing.SOUTH),
UP_NORTH(EnumFacing.UP, EnumFacing.NORTH), UP_SOUTH(EnumFacing.UP, EnumFacing.SOUTH),
DOWN_WEST(EnumFacing.DOWN, EnumFacing.WEST), DOWN_EAST(EnumFacing.DOWN, EnumFacing.EAST),
UP_WEST(EnumFacing.UP, EnumFacing.WEST), UP_EAST(EnumFacing.UP, EnumFacing.EAST);
private EnumFacing facing1;
private EnumFacing facing2;
private BlockDir(EnumFacing facing1) {
this.facing1 = facing1;
}
private BlockDir(EnumFacing facing1, EnumFacing facing2) {
this.facing1 = facing1;
this.facing2 = facing2;
}
public EnumFacing getFacing1() {
return this.facing1;
}
public EnumFacing getFacing2() {
return this.facing2;
}
BlockPos offset(BlockPos pos) {
pos = pos.offset(this.facing1, 1);
if (this.facing2 != null) {
pos = pos.offset(this.facing2, 1);
}
return pos;
}
public int getOffsetX() {
int i = this.facing1.getFrontOffsetX();
if (this.facing2 != null) {
i += this.facing2.getFrontOffsetX();
}
return i;
}
public int getOffsetY() {
int i = this.facing1.getFrontOffsetY();
if (this.facing2 != null) {
i += this.facing2.getFrontOffsetY();
}
return i;
}
public int getOffsetZ() {
int i = this.facing1.getFrontOffsetZ();
if (this.facing2 != null) {
i += this.facing2.getFrontOffsetZ();
}
return i;
}
public boolean isDouble() {
return this.facing2 != null;
}
}

View File

@ -0,0 +1,339 @@
package net.optifine;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import net.lax1dude.eaglercraft.v1_8.log4j.LogManager;
import net.lax1dude.eaglercraft.v1_8.log4j.Logger;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.DefaultResourcePack;
import net.minecraft.client.resources.IResourcePack;
import net.minecraft.client.resources.ResourcePackRepository;
import net.minecraft.client.settings.GameSettings;
import net.minecraft.util.BlockPos;
import net.minecraft.util.ResourceLocation;
import net.optifine.util.TextureUtils;
public class Config {
private static final Logger logger = LogManager.getLogger("OptiFine");
private static Minecraft mc;
private static GameSettings gameSettings;
public static void setGameObj(Minecraft mc) {
Config.mc = mc;
Config.gameSettings = mc.gameSettings;
}
public static String[] tokenize(String p_tokenize_0_, String p_tokenize_1_) {
StringTokenizer stringtokenizer = new StringTokenizer(p_tokenize_0_, p_tokenize_1_);
List list = new ArrayList();
while (stringtokenizer.hasMoreTokens()) {
String s = stringtokenizer.nextToken();
list.add(s);
}
String[] astring = (String[]) list.toArray(new String[list.size()]);
return astring;
}
public static boolean isCustomSky() {
return gameSettings.customSkyOF;
}
public static boolean isBetterGrass() {
return gameSettings.betterGrassOF != 0;
}
public static boolean isBetterGrassFancy() {
return gameSettings.betterGrassOF == 2;
}
public static boolean isBetterSnow() {
return gameSettings.betterGrassOF != 0;
}
public static boolean isConnectedTextures() {
return gameSettings.connectedTexturesOF != 0;
}
public static boolean isConnectedTexturesFancy() {
return gameSettings.connectedTexturesOF == 2;
}
public static boolean isTreesFancy() {
return gameSettings.fancyGraphics;
}
public static boolean isTreesSmart() {
return gameSettings.fancyGraphics && gameSettings.smartLeavesOF;
}
public static boolean isCullFacesLeaves() {
return !gameSettings.fancyGraphics;
}
public static boolean isCustomItems() {
return gameSettings.customItemsOF;
}
public static void dbg(String string) {
logger.debug(string);
}
public static void warn(String string) {
logger.warn(string);
}
public static void error(String string) {
logger.error(string);
}
public static int limit(int p_limit_0_, int p_limit_1_, int p_limit_2_) {
return p_limit_0_ < p_limit_1_ ? p_limit_1_ : (p_limit_0_ > p_limit_2_ ? p_limit_2_ : p_limit_0_);
}
public static float limit(float p_limit_0_, float p_limit_1_, float p_limit_2_) {
return p_limit_0_ < p_limit_1_ ? p_limit_1_ : (p_limit_0_ > p_limit_2_ ? p_limit_2_ : p_limit_0_);
}
public static double limit(double p_limit_0_, double p_limit_2_, double p_limit_4_) {
return p_limit_0_ < p_limit_2_ ? p_limit_2_ : (p_limit_0_ > p_limit_4_ ? p_limit_4_ : p_limit_0_);
}
public static int parseInt(String p_parseInt_0_, int p_parseInt_1_) {
try {
if (p_parseInt_0_ == null) {
return p_parseInt_1_;
} else {
p_parseInt_0_ = p_parseInt_0_.trim();
return Integer.parseInt(p_parseInt_0_);
}
} catch (NumberFormatException var3) {
return p_parseInt_1_;
}
}
public static float parseFloat(String p_parseFloat_0_, float p_parseFloat_1_) {
try {
if (p_parseFloat_0_ == null) {
return p_parseFloat_1_;
} else {
p_parseFloat_0_ = p_parseFloat_0_.trim();
return Float.parseFloat(p_parseFloat_0_);
}
} catch (NumberFormatException var3) {
return p_parseFloat_1_;
}
}
public static boolean parseBoolean(String p_parseBoolean_0_, boolean p_parseBoolean_1_) {
try {
if (p_parseBoolean_0_ == null) {
return p_parseBoolean_1_;
} else {
p_parseBoolean_0_ = p_parseBoolean_0_.trim();
return Boolean.parseBoolean(p_parseBoolean_0_);
}
} catch (NumberFormatException var3) {
return p_parseBoolean_1_;
}
}
public static int[] addIntToArray(int[] p_addIntToArray_0_, int p_addIntToArray_1_) {
if (p_addIntToArray_0_ != null) {
int[] ret = new int[p_addIntToArray_0_.length + 1];
System.arraycopy(p_addIntToArray_0_, 0, ret, 0, p_addIntToArray_0_.length);
ret[p_addIntToArray_0_.length] = p_addIntToArray_1_;
return ret;
} else {
throw new NullPointerException("The given array is NULL");
}
}
public static int[] addIntsToArray(int[] p_addIntsToArray_0_, int[] p_addIntsToArray_1_) {
if (p_addIntsToArray_0_ != null && p_addIntsToArray_1_ != null) {
int i = p_addIntsToArray_0_.length;
int j = i + p_addIntsToArray_1_.length;
int[] aint = new int[j];
System.arraycopy(p_addIntsToArray_0_, 0, aint, 0, i);
for (int k = 0; k < p_addIntsToArray_1_.length; ++k) {
aint[k + i] = p_addIntsToArray_1_[k];
}
return aint;
} else {
throw new NullPointerException("The given array is NULL");
}
}
public static String arrayToString(Object[] p_arrayToString_0_) {
return arrayToString(p_arrayToString_0_, ", ");
}
public static String arrayToString(Object[] p_arrayToString_0_, String p_arrayToString_1_) {
if (p_arrayToString_0_ == null) {
return "";
} else {
StringBuffer stringbuffer = new StringBuffer(p_arrayToString_0_.length * 5);
for (int i = 0; i < p_arrayToString_0_.length; ++i) {
Object object = p_arrayToString_0_[i];
if (i > 0) {
stringbuffer.append(p_arrayToString_1_);
}
stringbuffer.append(String.valueOf(object));
}
return stringbuffer.toString();
}
}
public static String arrayToString(int[] p_arrayToString_0_) {
return arrayToString(p_arrayToString_0_, ", ");
}
public static String arrayToString(int[] p_arrayToString_0_, String p_arrayToString_1_) {
if (p_arrayToString_0_ == null) {
return "";
} else {
StringBuffer stringbuffer = new StringBuffer(p_arrayToString_0_.length * 5);
for (int i = 0; i < p_arrayToString_0_.length; ++i) {
int j = p_arrayToString_0_[i];
if (i > 0) {
stringbuffer.append(p_arrayToString_1_);
}
stringbuffer.append(String.valueOf(j));
}
return stringbuffer.toString();
}
}
public static int[] toPrimitive(Integer[] p_toPrimitive_0_) {
if (p_toPrimitive_0_ == null) {
return null;
} else if (p_toPrimitive_0_.length == 0) {
return new int[0];
} else {
int[] aint = new int[p_toPrimitive_0_.length];
for (int i = 0; i < aint.length; ++i) {
aint[i] = p_toPrimitive_0_[i].intValue();
}
return aint;
}
}
public static boolean isSameOne(Object p_isSameOne_0_, Object[] p_isSameOne_1_) {
if (p_isSameOne_1_ == null) {
return false;
} else {
for (int i = 0; i < p_isSameOne_1_.length; ++i) {
Object object = p_isSameOne_1_[i];
if (p_isSameOne_0_ == object) {
return true;
}
}
return false;
}
}
public static boolean equals(Object p_equals_0_, Object p_equals_1_) {
return p_equals_0_ == p_equals_1_ ? true : (p_equals_0_ == null ? false : p_equals_0_.equals(p_equals_1_));
}
public static boolean isFromDefaultResourcePack(ResourceLocation p_isFromDefaultResourcePack_0_) {
IResourcePack iresourcepack = getDefiningResourcePack(p_isFromDefaultResourcePack_0_);
return iresourcepack == mc.getDefaultResourcePack();
}
public static IResourcePack getDefiningResourcePack(ResourceLocation p_getDefiningResourcePack_0_) {
ResourcePackRepository resourcepackrepository = mc.getResourcePackRepository();
IResourcePack iresourcepack = resourcepackrepository.getResourcePackInstance();
if (iresourcepack != null && iresourcepack.resourceExists(p_getDefiningResourcePack_0_)) {
return iresourcepack;
} else {
List<ResourcePackRepository.Entry> list = resourcepackrepository.getRepositoryEntries();
for (int i = list.size() - 1; i >= 0; --i) {
ResourcePackRepository.Entry resourcepackrepository$entry = (ResourcePackRepository.Entry) list.get(i);
IResourcePack iresourcepack1 = resourcepackrepository$entry.getResourcePack();
if (iresourcepack1.resourceExists(p_getDefiningResourcePack_0_)) {
return iresourcepack1;
}
}
DefaultResourcePack res = mc.getDefaultResourcePack();
if (res.resourceExists(p_getDefiningResourcePack_0_)) {
return res;
} else {
return null;
}
}
}
public static boolean hasResource(ResourceLocation p_hasResource_0_) {
if (p_hasResource_0_ == null) {
return false;
} else {
IResourcePack iresourcepack = getDefiningResourcePack(p_hasResource_0_);
return iresourcepack != null;
}
}
public static IResourcePack[] getResourcePacks() {
ResourcePackRepository resourcepackrepository = mc.getResourcePackRepository();
List list = resourcepackrepository.getRepositoryEntries();
List list1 = new ArrayList();
for (Object resourcepackrepository$entry0 : list) {
ResourcePackRepository.Entry resourcepackrepository$entry = (ResourcePackRepository.Entry) resourcepackrepository$entry0;
list1.add(resourcepackrepository$entry.getResourcePack());
}
if (resourcepackrepository.getResourcePackInstance() != null) {
list1.add(resourcepackrepository.getResourcePackInstance());
}
IResourcePack[] airesourcepack = (IResourcePack[]) ((IResourcePack[]) list1
.toArray(new IResourcePack[list1.size()]));
return airesourcepack;
}
public static int intHash(int p_intHash_0_) {
p_intHash_0_ = p_intHash_0_ ^ 61 ^ p_intHash_0_ >> 16;
p_intHash_0_ = p_intHash_0_ + (p_intHash_0_ << 3);
p_intHash_0_ = p_intHash_0_ ^ p_intHash_0_ >> 4;
p_intHash_0_ = p_intHash_0_ * 668265261;
p_intHash_0_ = p_intHash_0_ ^ p_intHash_0_ >> 15;
return p_intHash_0_;
}
public static int getRandom(BlockPos p_getRandom_0_, int p_getRandom_1_) {
int i = intHash(p_getRandom_1_ + 37);
i = intHash(i + p_getRandom_0_.getX());
i = intHash(i + p_getRandom_0_.getZ());
i = intHash(i + p_getRandom_0_.getY());
return i;
}
public static void frameInitHook() {
TextureUtils.registerResourceListener();
}
}

View File

@ -0,0 +1,993 @@
package net.optifine;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.function.Function;
import net.lax1dude.eaglercraft.v1_8.minecraft.EaglerTextureAtlasSprite;
import net.minecraft.block.Block;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.init.Blocks;
import net.minecraft.util.EnumWorldBlockLayer;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.biome.BiomeGenBase;
import net.optifine.config.ConnectedParser;
import net.optifine.config.MatchBlock;
import net.optifine.config.Matches;
import net.optifine.config.NbtTagValue;
import net.optifine.config.RangeInt;
import net.optifine.config.RangeListInt;
import net.optifine.util.MathUtils;
import net.optifine.util.TextureUtils;
public class ConnectedProperties {
public String name = null;
public String basePath = null;
public MatchBlock[] matchBlocks = null;
public int[] metadatas = null;
public String[] matchTiles = null;
public int method = 0;
public String[] tiles = null;
public int connect = 0;
public int faces = 63;
public BiomeGenBase[] biomes = null;
public RangeListInt heights = null;
public int renderPass = 0;
public boolean innerSeams = false;
public int[] ctmTileIndexes = null;
public int width = 0;
public int height = 0;
public int[] weights = null;
public int randomLoops = 0;
public int symmetry = 1;
public boolean linked = false;
public NbtTagValue nbtName = null;
public int[] sumWeights = null;
public int sumAllWeights = 1;
public EaglerTextureAtlasSprite[] matchTileIcons = null;
public EaglerTextureAtlasSprite[] tileIcons = null;
public MatchBlock[] connectBlocks = null;
public String[] connectTiles = null;
public EaglerTextureAtlasSprite[] connectTileIcons = null;
public int tintIndex = -1;
public IBlockState tintBlockState = Blocks.air.getDefaultState();
public EnumWorldBlockLayer layer = null;
public static final int METHOD_NONE = 0;
public static final int METHOD_CTM = 1;
public static final int METHOD_HORIZONTAL = 2;
public static final int METHOD_TOP = 3;
public static final int METHOD_RANDOM = 4;
public static final int METHOD_REPEAT = 5;
public static final int METHOD_VERTICAL = 6;
public static final int METHOD_FIXED = 7;
public static final int METHOD_HORIZONTAL_VERTICAL = 8;
public static final int METHOD_VERTICAL_HORIZONTAL = 9;
public static final int METHOD_CTM_COMPACT = 10;
public static final int METHOD_OVERLAY = 11;
public static final int METHOD_OVERLAY_FIXED = 12;
public static final int METHOD_OVERLAY_RANDOM = 13;
public static final int METHOD_OVERLAY_REPEAT = 14;
public static final int METHOD_OVERLAY_CTM = 15;
public static final int CONNECT_NONE = 0;
public static final int CONNECT_BLOCK = 1;
public static final int CONNECT_TILE = 2;
public static final int CONNECT_MATERIAL = 3;
public static final int CONNECT_UNKNOWN = 128;
public static final int FACE_BOTTOM = 1;
public static final int FACE_TOP = 2;
public static final int FACE_NORTH = 4;
public static final int FACE_SOUTH = 8;
public static final int FACE_WEST = 16;
public static final int FACE_EAST = 32;
public static final int FACE_SIDES = 60;
public static final int FACE_ALL = 63;
public static final int FACE_UNKNOWN = 128;
public static final int SYMMETRY_NONE = 1;
public static final int SYMMETRY_OPPOSITE = 2;
public static final int SYMMETRY_ALL = 6;
public static final int SYMMETRY_UNKNOWN = 128;
public static final String TILE_SKIP_PNG = "<skip>.png";
public static final String TILE_DEFAULT_PNG = "<default>.png";
public ConnectedProperties(Properties props, String path) {
ConnectedParser connectedparser = new ConnectedParser("ConnectedTextures");
this.name = connectedparser.parseName(path);
this.basePath = connectedparser.parseBasePath(path);
this.matchBlocks = connectedparser.parseMatchBlocks(props.getProperty("matchBlocks"));
this.metadatas = connectedparser.parseIntList(props.getProperty("metadata"));
this.matchTiles = this.parseMatchTiles(props.getProperty("matchTiles"));
this.method = parseMethod(props.getProperty("method"));
this.tiles = this.parseTileNames(props.getProperty("tiles"));
this.connect = parseConnect(props.getProperty("connect"));
this.faces = parseFaces(props.getProperty("faces"));
this.biomes = connectedparser.parseBiomes(props.getProperty("biomes"));
this.heights = connectedparser.parseRangeListInt(props.getProperty("heights"));
if (this.heights == null) {
int i = connectedparser.parseInt(props.getProperty("minHeight"), -1);
int j = connectedparser.parseInt(props.getProperty("maxHeight"), 1024);
if (i != -1 || j != 1024) {
this.heights = new RangeListInt(new RangeInt(i, j));
}
}
this.renderPass = connectedparser.parseInt(props.getProperty("renderPass"), -1);
this.innerSeams = connectedparser.parseBoolean(props.getProperty("innerSeams"), false);
this.ctmTileIndexes = this.parseCtmTileIndexes(props);
this.width = connectedparser.parseInt(props.getProperty("width"), -1);
this.height = connectedparser.parseInt(props.getProperty("height"), -1);
this.weights = connectedparser.parseIntList(props.getProperty("weights"));
this.randomLoops = connectedparser.parseInt(props.getProperty("randomLoops"), 0);
this.symmetry = parseSymmetry(props.getProperty("symmetry"));
this.linked = connectedparser.parseBoolean(props.getProperty("linked"), false);
this.nbtName = connectedparser.parseNbtTagValue("name", props.getProperty("name"));
this.connectBlocks = connectedparser.parseMatchBlocks(props.getProperty("connectBlocks"));
this.connectTiles = this.parseMatchTiles(props.getProperty("connectTiles"));
this.tintIndex = connectedparser.parseInt(props.getProperty("tintIndex"), -1);
this.tintBlockState = connectedparser.parseBlockState(props.getProperty("tintBlock"),
Blocks.air.getDefaultState());
this.layer = connectedparser.parseBlockRenderLayer(props.getProperty("layer"),
EnumWorldBlockLayer.CUTOUT_MIPPED);
}
private int[] parseCtmTileIndexes(Properties props) {
if (this.tiles == null) {
return null;
} else {
Map<Integer, Integer> map = new HashMap();
for (Object object : props.keySet()) {
if (object instanceof String) {
String s = (String) object;
String s1 = "ctm.";
if (s.startsWith(s1)) {
String s2 = s.substring(s1.length());
String s3 = props.getProperty(s);
if (s3 != null) {
s3 = s3.trim();
int i = Config.parseInt(s2, -1);
if (i >= 0 && i <= 46) {
int j = Config.parseInt(s3, -1);
if (j >= 0 && j < this.tiles.length) {
map.put(Integer.valueOf(i), Integer.valueOf(j));
} else {
Config.warn("Invalid CTM tile index: " + s3);
}
} else {
Config.warn("Invalid CTM index: " + s2);
}
}
}
}
}
if (map.isEmpty()) {
return null;
} else {
int[] aint = new int[47];
for (int k = 0; k < aint.length; ++k) {
aint[k] = -1;
if (map.containsKey(Integer.valueOf(k))) {
aint[k] = ((Integer) map.get(Integer.valueOf(k))).intValue();
}
}
return aint;
}
}
}
private String[] parseMatchTiles(String str) {
if (str == null) {
return null;
} else {
String[] astring = Config.tokenize(str, " ");
for (int i = 0; i < astring.length; ++i) {
String s = astring[i];
if (s.endsWith(".png")) {
s = s.substring(0, s.length() - 4);
}
s = TextureUtils.fixResourcePath(s, this.basePath);
astring[i] = s;
}
return astring;
}
}
private static 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;
}
private static String parseBasePath(String path) {
int i = path.lastIndexOf(47);
return i < 0 ? "" : path.substring(0, i);
}
private String[] parseTileNames(String str) {
if (str == null) {
return null;
} else {
List list = new ArrayList();
String[] astring = Config.tokenize(str, " ,");
label32:
for (int i = 0; i < astring.length; ++i) {
String s = astring[i];
if (s.contains("-")) {
String[] astring1 = Config.tokenize(s, "-");
if (astring1.length == 2) {
int j = Config.parseInt(astring1[0], -1);
int k = Config.parseInt(astring1[1], -1);
if (j >= 0 && k >= 0) {
if (j > k) {
Config.warn("Invalid interval: " + s + ", when parsing: " + str);
continue;
}
int l = j;
while (true) {
if (l > k) {
continue label32;
}
list.add(String.valueOf(l));
++l;
}
}
}
}
list.add(s);
}
String[] astring2 = (String[]) list.toArray(new String[list.size()]);
for (int i1 = 0; i1 < astring2.length; ++i1) {
String s1 = astring2[i1];
s1 = TextureUtils.fixResourcePath(s1, this.basePath);
if (!s1.startsWith(this.basePath) && !s1.startsWith("textures/") && !s1.startsWith("mcpatcher/")) {
s1 = this.basePath + "/" + s1;
}
if (s1.endsWith(".png")) {
s1 = s1.substring(0, s1.length() - 4);
}
if (s1.startsWith("/")) {
s1 = s1.substring(1);
}
astring2[i1] = s1;
}
return astring2;
}
}
private static int parseSymmetry(String str) {
if (str == null) {
return 1;
} else {
str = str.trim();
if (str.equals("opposite")) {
return 2;
} else if (str.equals("all")) {
return 6;
} else {
Config.warn("Unknown symmetry: " + str);
return 1;
}
}
}
private static int parseFaces(String str) {
if (str == null) {
return 63;
} else {
String[] astring = Config.tokenize(str, " ,");
int i = 0;
for (int j = 0; j < astring.length; ++j) {
String s = astring[j];
int k = parseFace(s);
i |= k;
}
return i;
}
}
private static int 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 4;
} else if (str.equals("south")) {
return 8;
} else if (str.equals("east")) {
return 32;
} else if (str.equals("west")) {
return 16;
} else if (str.equals("sides")) {
return 60;
} else if (str.equals("all")) {
return 63;
} else {
Config.warn("Unknown face: " + str);
return 128;
}
} else {
return 2;
}
} else {
return 1;
}
}
private static int parseConnect(String str) {
if (str == null) {
return 0;
} else {
str = str.trim();
if (str.equals("block")) {
return 1;
} else if (str.equals("tile")) {
return 2;
} else if (str.equals("material")) {
return 3;
} else {
Config.warn("Unknown connect: " + str);
return 128;
}
}
}
public static IProperty getProperty(String key, Collection properties) {
for (Object iproperty0 : properties) {
IProperty iproperty = (IProperty) iproperty0;
if (key.equals(iproperty.getName())) {
return iproperty;
}
}
return null;
}
private static int parseMethod(String str) {
if (str == null) {
return 1;
} else {
str = str.trim();
if (!str.equals("ctm") && !str.equals("glass")) {
if (str.equals("ctm_compact")) {
return 10;
} else if (!str.equals("horizontal") && !str.equals("bookshelf")) {
if (str.equals("vertical")) {
return 6;
} else if (str.equals("top")) {
return 3;
} else if (str.equals("random")) {
return 4;
} else if (str.equals("repeat")) {
return 5;
} else if (str.equals("fixed")) {
return 7;
} else if (!str.equals("horizontal+vertical") && !str.equals("h+v")) {
if (!str.equals("vertical+horizontal") && !str.equals("v+h")) {
if (str.equals("overlay")) {
return 11;
} else if (str.equals("overlay_fixed")) {
return 12;
} else if (str.equals("overlay_random")) {
return 13;
} else if (str.equals("overlay_repeat")) {
return 14;
} else if (str.equals("overlay_ctm")) {
return 15;
} else {
Config.warn("Unknown method: " + str);
return 0;
}
} else {
return 9;
}
} else {
return 8;
}
} else {
return 2;
}
} else {
return 1;
}
}
}
public boolean isValid(String path) {
if (this.name != null && this.name.length() > 0) {
if (this.basePath == null) {
Config.warn("No base path found: " + path);
return false;
} else {
if (this.matchBlocks == null) {
this.matchBlocks = this.detectMatchBlocks();
}
if (this.matchTiles == null && this.matchBlocks == null) {
this.matchTiles = this.detectMatchTiles();
}
if (this.matchBlocks == null && this.matchTiles == null) {
Config.warn("No matchBlocks or matchTiles specified: " + path);
return false;
} else if (this.method == 0) {
Config.warn("No method: " + path);
return false;
} else if (this.tiles != null && this.tiles.length > 0) {
if (this.connect == 0) {
this.connect = this.detectConnect();
}
if (this.connect == 128) {
Config.warn("Invalid connect in: " + path);
return false;
} else if (this.renderPass > 0) {
Config.warn("Render pass not supported: " + this.renderPass);
return false;
} else if ((this.faces & 128) != 0) {
Config.warn("Invalid faces in: " + path);
return false;
} else if ((this.symmetry & 128) != 0) {
Config.warn("Invalid symmetry in: " + path);
return false;
} else {
switch (this.method) {
case 1:
return this.isValidCtm(path);
case 2:
return this.isValidHorizontal(path);
case 3:
return this.isValidTop(path);
case 4:
return this.isValidRandom(path);
case 5:
return this.isValidRepeat(path);
case 6:
return this.isValidVertical(path);
case 7:
return this.isValidFixed(path);
case 8:
return this.isValidHorizontalVertical(path);
case 9:
return this.isValidVerticalHorizontal(path);
case 10:
return this.isValidCtmCompact(path);
case 11:
return this.isValidOverlay(path);
case 12:
return this.isValidOverlayFixed(path);
case 13:
return this.isValidOverlayRandom(path);
case 14:
return this.isValidOverlayRepeat(path);
case 15:
return this.isValidOverlayCtm(path);
default:
Config.warn("Unknown method: " + path);
return false;
}
}
} else {
Config.warn("No tiles specified: " + path);
return false;
}
}
} else {
Config.warn("No name found: " + path);
return false;
}
}
private int detectConnect() {
return this.matchBlocks != null ? 1 : (this.matchTiles != null ? 2 : 128);
}
private MatchBlock[] detectMatchBlocks() {
int[] aint = this.detectMatchBlockIds();
if (aint == null) {
return null;
} else {
MatchBlock[] amatchblock = new MatchBlock[aint.length];
for (int i = 0; i < amatchblock.length; ++i) {
amatchblock[i] = new MatchBlock(aint[i]);
}
return amatchblock;
}
}
private int[] detectMatchBlockIds() {
if (!this.name.startsWith("block")) {
return null;
} else {
int i = "block".length();
int j;
for (j = i; j < this.name.length(); ++j) {
char c0 = this.name.charAt(j);
if (c0 < 48 || c0 > 57) {
break;
}
}
if (j == i) {
return null;
} else {
String s = this.name.substring(i, j);
int k = Config.parseInt(s, -1);
return k < 0 ? null : new int[] { k };
}
}
}
private String[] detectMatchTiles() {
EaglerTextureAtlasSprite textureatlassprite = getIcon(this.name);
return textureatlassprite == null ? null : new String[] { this.name };
}
private static EaglerTextureAtlasSprite getIcon(String iconName) {
TextureMap texturemap = Minecraft.getMinecraft().getTextureMapBlocks();
EaglerTextureAtlasSprite textureatlassprite = texturemap.getSpriteSafe(iconName);
if (textureatlassprite != null) {
return textureatlassprite;
} else {
textureatlassprite = texturemap.getSpriteSafe("blocks/" + iconName);
return textureatlassprite;
}
}
private boolean isValidCtm(String path) {
if (this.tiles == null) {
this.tiles = this.parseTileNames("0-11 16-27 32-43 48-58");
}
if (this.tiles.length < 47) {
Config.warn("Invalid tiles, must be at least 47: " + path);
return false;
} else {
return true;
}
}
private boolean isValidCtmCompact(String path) {
if (this.tiles == null) {
this.tiles = this.parseTileNames("0-4");
}
if (this.tiles.length < 5) {
Config.warn("Invalid tiles, must be at least 5: " + path);
return false;
} else {
return true;
}
}
private boolean isValidOverlay(String path) {
if (this.tiles == null) {
this.tiles = this.parseTileNames("0-16");
}
if (this.tiles.length < 17) {
Config.warn("Invalid tiles, must be at least 17: " + path);
return false;
} else if (this.layer != null && this.layer != EnumWorldBlockLayer.SOLID) {
return true;
} else {
Config.warn("Invalid overlay layer: " + this.layer);
return false;
}
}
private boolean isValidOverlayFixed(String path) {
if (!this.isValidFixed(path)) {
return false;
} else if (this.layer != null && this.layer != EnumWorldBlockLayer.SOLID) {
return true;
} else {
Config.warn("Invalid overlay layer: " + this.layer);
return false;
}
}
private boolean isValidOverlayRandom(String path) {
if (!this.isValidRandom(path)) {
return false;
} else if (this.layer != null && this.layer != EnumWorldBlockLayer.SOLID) {
return true;
} else {
Config.warn("Invalid overlay layer: " + this.layer);
return false;
}
}
private boolean isValidOverlayRepeat(String path) {
if (!this.isValidRepeat(path)) {
return false;
} else if (this.layer != null && this.layer != EnumWorldBlockLayer.SOLID) {
return true;
} else {
Config.warn("Invalid overlay layer: " + this.layer);
return false;
}
}
private boolean isValidOverlayCtm(String path) {
if (!this.isValidCtm(path)) {
return false;
} else if (this.layer != null && this.layer != EnumWorldBlockLayer.SOLID) {
return true;
} else {
Config.warn("Invalid overlay layer: " + this.layer);
return false;
}
}
private boolean isValidHorizontal(String path) {
if (this.tiles == null) {
this.tiles = this.parseTileNames("12-15");
}
if (this.tiles.length != 4) {
Config.warn("Invalid tiles, must be exactly 4: " + path);
return false;
} else {
return true;
}
}
private boolean isValidVertical(String path) {
if (this.tiles == null) {
Config.warn("No tiles defined for vertical: " + path);
return false;
} else if (this.tiles.length != 4) {
Config.warn("Invalid tiles, must be exactly 4: " + path);
return false;
} else {
return true;
}
}
private boolean isValidHorizontalVertical(String path) {
if (this.tiles == null) {
Config.warn("No tiles defined for horizontal+vertical: " + path);
return false;
} else if (this.tiles.length != 7) {
Config.warn("Invalid tiles, must be exactly 7: " + path);
return false;
} else {
return true;
}
}
private boolean isValidVerticalHorizontal(String path) {
if (this.tiles == null) {
Config.warn("No tiles defined for vertical+horizontal: " + path);
return false;
} else if (this.tiles.length != 7) {
Config.warn("Invalid tiles, must be exactly 7: " + path);
return false;
} else {
return true;
}
}
private boolean isValidRandom(String path) {
if (this.tiles != null && this.tiles.length > 0) {
if (this.weights != null) {
if (this.weights.length > this.tiles.length) {
Config.warn("More weights defined than tiles, trimming weights: " + path);
int[] aint = new int[this.tiles.length];
System.arraycopy(this.weights, 0, aint, 0, aint.length);
this.weights = aint;
}
if (this.weights.length < this.tiles.length) {
Config.warn("Less weights defined than tiles, expanding weights: " + path);
int[] aint1 = new int[this.tiles.length];
System.arraycopy(this.weights, 0, aint1, 0, this.weights.length);
int i = MathUtils.getAverage(this.weights);
for (int j = this.weights.length; j < aint1.length; ++j) {
aint1[j] = i;
}
this.weights = aint1;
}
this.sumWeights = new int[this.weights.length];
int k = 0;
for (int l = 0; l < this.weights.length; ++l) {
k += this.weights[l];
this.sumWeights[l] = k;
}
this.sumAllWeights = k;
if (this.sumAllWeights <= 0) {
Config.warn("Invalid sum of all weights: " + k);
this.sumAllWeights = 1;
}
}
if (this.randomLoops >= 0 && this.randomLoops <= 9) {
return true;
} else {
Config.warn("Invalid randomLoops: " + this.randomLoops);
return false;
}
} else {
Config.warn("Tiles not defined: " + path);
return false;
}
}
private boolean isValidRepeat(String path) {
if (this.tiles == null) {
Config.warn("Tiles not defined: " + path);
return false;
} else if (this.width <= 0) {
Config.warn("Invalid width: " + path);
return false;
} else if (this.height <= 0) {
Config.warn("Invalid height: " + path);
return false;
} else if (this.tiles.length != this.width * this.height) {
Config.warn("Number of tiles does not equal width x height: " + path);
return false;
} else {
return true;
}
}
private boolean isValidFixed(String path) {
if (this.tiles == null) {
Config.warn("Tiles not defined: " + path);
return false;
} else if (this.tiles.length != 1) {
Config.warn("Number of tiles should be 1 for method: fixed.");
return false;
} else {
return true;
}
}
private boolean isValidTop(String path) {
if (this.tiles == null) {
this.tiles = this.parseTileNames("66");
}
if (this.tiles.length != 1) {
Config.warn("Invalid tiles, must be exactly 1: " + path);
return false;
} else {
return true;
}
}
public void updateIcons(TextureMap textureMap) {
String baseName = null;
if (this.matchTiles != null) {
this.matchTileIcons = registerIcons(this.matchTiles, null, textureMap, false, false);
if(this.matchTiles.length > 0) {
baseName = "blocks/" + this.matchTiles[0];
}
}
if(baseName == null) {
int blockBaseID = -1;
int metaBase = -1;
if(this.matchBlocks != null && this.matchBlocks.length > 0) {
MatchBlock b = this.matchBlocks[0];
blockBaseID = b.getBlockId();
int[] metas = b.getMetadatas();
if(metas != null && metas.length > 0) {
metaBase = metas[0];
}
}
if(blockBaseID != -1) {
if(metaBase == -1 && this.metadatas != null && this.metadatas.length > 0) {
metaBase = this.metadatas[0];
}
if(metaBase == -1) {
metaBase = 0;
}
baseName = Minecraft.getMinecraft().getModelManager().modelbakerytmp.getBaseTextureForBlockPre(blockBaseID, metaBase);
}
}
if (this.connectTiles != null) {
this.connectTileIcons = registerIcons(this.connectTiles, baseName, textureMap, false, false);
}
if (this.tiles != null) {
this.tileIcons = registerIcons(this.tiles, baseName, textureMap, true, !isMethodOverlay(this.method));
}
}
private static boolean isMethodOverlay(int method) {
switch (method) {
case 11:
case 12:
case 13:
case 14:
case 15:
return true;
default:
return false;
}
}
private static EaglerTextureAtlasSprite[] registerIcons(String[] tileNames, String baseName,
TextureMap textureMap, boolean skipTiles, boolean defaultTiles) {
if (tileNames == null) {
return null;
} else {
List list = new ArrayList();
for (int i = 0; i < tileNames.length; ++i) {
String s = tileNames[i];
ResourceLocation resourcelocation = new ResourceLocation(s);
String s1 = resourcelocation.getResourceDomain();
String s2 = resourcelocation.getResourcePath();
if (!s2.contains("/")) {
s2 = "textures/blocks/" + s2;
}
String s3 = s2 + ".png";
if (skipTiles && s3.endsWith("<skip>.png")) {
list.add(null);
} else if (defaultTiles && s3.endsWith("<default>.png")) {
list.add(ConnectedTextures.SPRITE_DEFAULT);
} else {
ResourceLocation resourcelocation1 = new ResourceLocation(s1, s3);
boolean flag = Config.hasResource(resourcelocation1);
if (!flag) {
Config.warn("File not found: " + s3);
}
String s4 = "textures/";
String s5 = s2;
if (s2.startsWith(s4)) {
s5 = s2.substring(s4.length());
}
ResourceLocation resourcelocation2 = new ResourceLocation(s1, s5);
EaglerTextureAtlasSprite textureatlassprite = textureMap.registerSprite(resourcelocation2, baseName);
list.add(textureatlassprite);
}
}
EaglerTextureAtlasSprite[] atextureatlassprite = (EaglerTextureAtlasSprite[]) list
.toArray(new EaglerTextureAtlasSprite[list.size()]);
return atextureatlassprite;
}
}
public boolean matchesBlockId(int blockId) {
return Matches.blockId(blockId, this.matchBlocks);
}
public boolean matchesBlock(int blockId, int metadata) {
return !Matches.block(blockId, metadata, this.matchBlocks) ? false : Matches.metadata(metadata, this.metadatas);
}
public boolean matchesIcon(EaglerTextureAtlasSprite icon) {
return Matches.sprite(icon, this.matchTileIcons);
}
public String toString() {
return "CTM name: " + this.name + ", basePath: " + this.basePath + ", matchBlocks: "
+ Config.arrayToString((Object[]) this.matchBlocks) + ", matchTiles: "
+ Config.arrayToString((Object[]) this.matchTiles);
}
public boolean matchesBiome(BiomeGenBase biome) {
return Matches.biome(biome, this.biomes);
}
public int getMetadataMax() {
int i = -1;
i = this.getMax(this.metadatas, i);
if (this.matchBlocks != null) {
for (int j = 0; j < this.matchBlocks.length; ++j) {
MatchBlock matchblock = this.matchBlocks[j];
i = this.getMax(matchblock.getMetadatas(), i);
}
}
return i;
}
private int getMax(int[] mds, int max) {
if (mds == null) {
return max;
} else {
for (int i = 0; i < mds.length; ++i) {
int j = mds[i];
if (j > max) {
max = j;
}
}
return max;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,450 @@
package net.optifine;
import java.util.IdentityHashMap;
import java.util.Map;
import net.lax1dude.eaglercraft.v1_8.minecraft.EaglerTextureAtlasSprite;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.optifine.render.RenderEnv;
public class ConnectedTexturesCompact {
private static final int COMPACT_NONE = 0;
private static final int COMPACT_ALL = 1;
private static final int COMPACT_V = 2;
private static final int COMPACT_H = 3;
private static final int COMPACT_HV = 4;
public static BakedQuad[] getConnectedTextureCtmCompact(int ctmIndex, ConnectedProperties cp, int side,
BakedQuad quad, RenderEnv renderEnv) {
if (cp.ctmTileIndexes != null && ctmIndex >= 0 && ctmIndex < cp.ctmTileIndexes.length) {
int i = cp.ctmTileIndexes[ctmIndex];
if (i >= 0 && i <= cp.tileIcons.length) {
return getQuadsCompact(i, cp.tileIcons, quad, renderEnv);
}
}
switch (ctmIndex) {
case 1:
return getQuadsCompactH(0, 3, cp.tileIcons, side, quad, renderEnv);
case 2:
return getQuadsCompact(3, cp.tileIcons, quad, renderEnv);
case 3:
return getQuadsCompactH(3, 0, cp.tileIcons, side, quad, renderEnv);
case 4:
return getQuadsCompact4(0, 3, 2, 4, cp.tileIcons, side, quad, renderEnv);
case 5:
return getQuadsCompact4(3, 0, 4, 2, cp.tileIcons, side, quad, renderEnv);
case 6:
return getQuadsCompact4(2, 4, 2, 4, cp.tileIcons, side, quad, renderEnv);
case 7:
return getQuadsCompact4(3, 3, 4, 4, cp.tileIcons, side, quad, renderEnv);
case 8:
return getQuadsCompact4(4, 1, 4, 4, cp.tileIcons, side, quad, renderEnv);
case 9:
return getQuadsCompact4(4, 4, 4, 1, cp.tileIcons, side, quad, renderEnv);
case 10:
return getQuadsCompact4(1, 4, 1, 4, cp.tileIcons, side, quad, renderEnv);
case 11:
return getQuadsCompact4(1, 1, 4, 4, cp.tileIcons, side, quad, renderEnv);
case 12:
return getQuadsCompactV(0, 2, cp.tileIcons, side, quad, renderEnv);
case 13:
return getQuadsCompact4(0, 3, 2, 1, cp.tileIcons, side, quad, renderEnv);
case 14:
return getQuadsCompactV(3, 1, cp.tileIcons, side, quad, renderEnv);
case 15:
return getQuadsCompact4(3, 0, 1, 2, cp.tileIcons, side, quad, renderEnv);
case 16:
return getQuadsCompact4(2, 4, 0, 3, cp.tileIcons, side, quad, renderEnv);
case 17:
return getQuadsCompact4(4, 2, 3, 0, cp.tileIcons, side, quad, renderEnv);
case 18:
return getQuadsCompact4(4, 4, 3, 3, cp.tileIcons, side, quad, renderEnv);
case 19:
return getQuadsCompact4(4, 2, 4, 2, cp.tileIcons, side, quad, renderEnv);
case 20:
return getQuadsCompact4(1, 4, 4, 4, cp.tileIcons, side, quad, renderEnv);
case 21:
return getQuadsCompact4(4, 4, 1, 4, cp.tileIcons, side, quad, renderEnv);
case 22:
return getQuadsCompact4(4, 4, 1, 1, cp.tileIcons, side, quad, renderEnv);
case 23:
return getQuadsCompact4(4, 1, 4, 1, cp.tileIcons, side, quad, renderEnv);
case 24:
return getQuadsCompact(2, cp.tileIcons, quad, renderEnv);
case 25:
return getQuadsCompactH(2, 1, cp.tileIcons, side, quad, renderEnv);
case 26:
return getQuadsCompact(1, cp.tileIcons, quad, renderEnv);
case 27:
return getQuadsCompactH(1, 2, cp.tileIcons, side, quad, renderEnv);
case 28:
return getQuadsCompact4(2, 4, 2, 1, cp.tileIcons, side, quad, renderEnv);
case 29:
return getQuadsCompact4(3, 3, 1, 4, cp.tileIcons, side, quad, renderEnv);
case 30:
return getQuadsCompact4(2, 1, 2, 4, cp.tileIcons, side, quad, renderEnv);
case 31:
return getQuadsCompact4(3, 3, 4, 1, cp.tileIcons, side, quad, renderEnv);
case 32:
return getQuadsCompact4(1, 1, 1, 4, cp.tileIcons, side, quad, renderEnv);
case 33:
return getQuadsCompact4(1, 1, 4, 1, cp.tileIcons, side, quad, renderEnv);
case 34:
return getQuadsCompact4(4, 1, 1, 4, cp.tileIcons, side, quad, renderEnv);
case 35:
return getQuadsCompact4(1, 4, 4, 1, cp.tileIcons, side, quad, renderEnv);
case 36:
return getQuadsCompactV(2, 0, cp.tileIcons, side, quad, renderEnv);
case 37:
return getQuadsCompact4(2, 1, 0, 3, cp.tileIcons, side, quad, renderEnv);
case 38:
return getQuadsCompactV(1, 3, cp.tileIcons, side, quad, renderEnv);
case 39:
return getQuadsCompact4(1, 2, 3, 0, cp.tileIcons, side, quad, renderEnv);
case 40:
return getQuadsCompact4(4, 1, 3, 3, cp.tileIcons, side, quad, renderEnv);
case 41:
return getQuadsCompact4(1, 2, 4, 2, cp.tileIcons, side, quad, renderEnv);
case 42:
return getQuadsCompact4(1, 4, 3, 3, cp.tileIcons, side, quad, renderEnv);
case 43:
return getQuadsCompact4(4, 2, 1, 2, cp.tileIcons, side, quad, renderEnv);
case 44:
return getQuadsCompact4(1, 4, 1, 1, cp.tileIcons, side, quad, renderEnv);
case 45:
return getQuadsCompact4(4, 1, 1, 1, cp.tileIcons, side, quad, renderEnv);
case 46:
return getQuadsCompact(4, cp.tileIcons, quad, renderEnv);
default:
return getQuadsCompact(0, cp.tileIcons, quad, renderEnv);
}
}
private static BakedQuad[] getQuadsCompactH(int indexLeft, int indexRight, EaglerTextureAtlasSprite[] sprites,
int side, BakedQuad quad, RenderEnv renderEnv) {
return getQuadsCompact(ConnectedTexturesCompact.Dir.LEFT, indexLeft, ConnectedTexturesCompact.Dir.RIGHT,
indexRight, sprites, side, quad, renderEnv);
}
private static BakedQuad[] getQuadsCompactV(int indexUp, int indexDown, EaglerTextureAtlasSprite[] sprites,
int side, BakedQuad quad, RenderEnv renderEnv) {
return getQuadsCompact(ConnectedTexturesCompact.Dir.UP, indexUp, ConnectedTexturesCompact.Dir.DOWN, indexDown,
sprites, side, quad, renderEnv);
}
private static BakedQuad[] getQuadsCompact4(int upLeft, int upRight, int downLeft, int downRight,
EaglerTextureAtlasSprite[] sprites, int side, BakedQuad quad, RenderEnv renderEnv) {
return upLeft == upRight ? (downLeft == downRight
? getQuadsCompact(ConnectedTexturesCompact.Dir.UP, upLeft, ConnectedTexturesCompact.Dir.DOWN, downLeft,
sprites, side, quad, renderEnv)
: getQuadsCompact(ConnectedTexturesCompact.Dir.UP, upLeft, ConnectedTexturesCompact.Dir.DOWN_LEFT,
downLeft, ConnectedTexturesCompact.Dir.DOWN_RIGHT, downRight, sprites, side, quad, renderEnv))
: (downLeft == downRight
? getQuadsCompact(ConnectedTexturesCompact.Dir.UP_LEFT, upLeft,
ConnectedTexturesCompact.Dir.UP_RIGHT, upRight, ConnectedTexturesCompact.Dir.DOWN,
downLeft, sprites, side, quad, renderEnv)
: (upLeft == downLeft
? (upRight == downRight ? getQuadsCompact(ConnectedTexturesCompact.Dir.LEFT, upLeft,
ConnectedTexturesCompact.Dir.RIGHT, upRight, sprites, side, quad, renderEnv)
: getQuadsCompact(ConnectedTexturesCompact.Dir.LEFT, upLeft,
ConnectedTexturesCompact.Dir.UP_RIGHT, upRight,
ConnectedTexturesCompact.Dir.DOWN_RIGHT, downRight, sprites, side, quad,
renderEnv))
: (upRight == downRight ? getQuadsCompact(ConnectedTexturesCompact.Dir.UP_LEFT, upLeft,
ConnectedTexturesCompact.Dir.DOWN_LEFT, downLeft,
ConnectedTexturesCompact.Dir.RIGHT, upRight, sprites, side, quad, renderEnv)
: getQuadsCompact(ConnectedTexturesCompact.Dir.UP_LEFT, upLeft,
ConnectedTexturesCompact.Dir.UP_RIGHT, upRight,
ConnectedTexturesCompact.Dir.DOWN_LEFT, downLeft,
ConnectedTexturesCompact.Dir.DOWN_RIGHT, downRight, sprites, side, quad,
renderEnv))));
}
private static BakedQuad[] getQuadsCompact(int index, EaglerTextureAtlasSprite[] sprites, BakedQuad quad,
RenderEnv renderEnv) {
EaglerTextureAtlasSprite textureatlassprite = sprites[index];
return ConnectedTextures.getQuads(textureatlassprite, quad, renderEnv);
}
private static BakedQuad[] getQuadsCompact(ConnectedTexturesCompact.Dir dir1, int index1,
ConnectedTexturesCompact.Dir dir2, int index2, EaglerTextureAtlasSprite[] sprites, int side, BakedQuad quad,
RenderEnv renderEnv) {
BakedQuad bakedquad = getQuadCompact(sprites[index1], dir1, side, quad, renderEnv);
BakedQuad bakedquad1 = getQuadCompact(sprites[index2], dir2, side, quad, renderEnv);
return renderEnv.getArrayQuadsCtm(bakedquad, bakedquad1);
}
private static BakedQuad[] getQuadsCompact(ConnectedTexturesCompact.Dir dir1, int index1,
ConnectedTexturesCompact.Dir dir2, int index2, ConnectedTexturesCompact.Dir dir3, int index3,
EaglerTextureAtlasSprite[] sprites, int side, BakedQuad quad, RenderEnv renderEnv) {
BakedQuad bakedquad = getQuadCompact(sprites[index1], dir1, side, quad, renderEnv);
BakedQuad bakedquad1 = getQuadCompact(sprites[index2], dir2, side, quad, renderEnv);
BakedQuad bakedquad2 = getQuadCompact(sprites[index3], dir3, side, quad, renderEnv);
return renderEnv.getArrayQuadsCtm(bakedquad, bakedquad1, bakedquad2);
}
private static BakedQuad[] getQuadsCompact(ConnectedTexturesCompact.Dir dir1, int index1,
ConnectedTexturesCompact.Dir dir2, int index2, ConnectedTexturesCompact.Dir dir3, int index3,
ConnectedTexturesCompact.Dir dir4, int index4, EaglerTextureAtlasSprite[] sprites, int side, BakedQuad quad,
RenderEnv renderEnv) {
BakedQuad bakedquad = getQuadCompact(sprites[index1], dir1, side, quad, renderEnv);
BakedQuad bakedquad1 = getQuadCompact(sprites[index2], dir2, side, quad, renderEnv);
BakedQuad bakedquad2 = getQuadCompact(sprites[index3], dir3, side, quad, renderEnv);
BakedQuad bakedquad3 = getQuadCompact(sprites[index4], dir4, side, quad, renderEnv);
return renderEnv.getArrayQuadsCtm(bakedquad, bakedquad1, bakedquad2, bakedquad3);
}
private static BakedQuad getQuadCompact(EaglerTextureAtlasSprite sprite, ConnectedTexturesCompact.Dir dir, int side,
BakedQuad quad, RenderEnv renderEnv) {
switch (dir) {
case UP:
return getQuadCompact(sprite, dir, 0, 0, 16, 8, side, quad, renderEnv);
case UP_RIGHT:
return getQuadCompact(sprite, dir, 8, 0, 16, 8, side, quad, renderEnv);
case RIGHT:
return getQuadCompact(sprite, dir, 8, 0, 16, 16, side, quad, renderEnv);
case DOWN_RIGHT:
return getQuadCompact(sprite, dir, 8, 8, 16, 16, side, quad, renderEnv);
case DOWN:
return getQuadCompact(sprite, dir, 0, 8, 16, 16, side, quad, renderEnv);
case DOWN_LEFT:
return getQuadCompact(sprite, dir, 0, 8, 8, 16, side, quad, renderEnv);
case LEFT:
return getQuadCompact(sprite, dir, 0, 0, 8, 16, side, quad, renderEnv);
case UP_LEFT:
return getQuadCompact(sprite, dir, 0, 0, 8, 8, side, quad, renderEnv);
default:
return quad;
}
}
private static BakedQuad getQuadCompact(EaglerTextureAtlasSprite sprite, ConnectedTexturesCompact.Dir dir, int x1,
int y1, int x2, int y2, int side, BakedQuad quadIn, RenderEnv renderEnv) {
Map[][] amap = ConnectedTextures.getSpriteQuadCompactMaps();
if (amap == null) {
return quadIn;
} else {
int i = sprite.getIndexInMap();
if (i >= 0 && i < amap.length) {
Map[] amap1 = amap[i];
if (amap1 == null) {
amap1 = new Map[ConnectedTexturesCompact.Dir.VALUES.length];
amap[i] = amap1;
}
Map<BakedQuad, BakedQuad> map = amap1[dir.ordinal()];
if (map == null) {
map = new IdentityHashMap(1);
amap1[dir.ordinal()] = map;
}
BakedQuad bakedquad = (BakedQuad) map.get(quadIn);
if (bakedquad == null) {
bakedquad = makeSpriteQuadCompact(quadIn, sprite, side, x1, y1, x2, y2);
map.put(quadIn, bakedquad);
}
return bakedquad;
} else {
return quadIn;
}
}
}
private static BakedQuad makeSpriteQuadCompact(BakedQuad quad, EaglerTextureAtlasSprite sprite, int side, int x1,
int y1, int x2, int y2) {
int[] aint = (int[]) quad.getVertexData().clone();
int[] aint2 = (int[]) quad.getVertexDataWithNormals().clone();
EaglerTextureAtlasSprite textureatlassprite = quad.getSprite();
for (int i = 0; i < 4; ++i) {
fixVertexCompact(aint, aint2, i, textureatlassprite, sprite, side, x1, y1, x2, y2);
}
BakedQuad bakedquad = new BakedQuad(aint, aint2, quad.getTintIndex(), quad.getFace(), sprite);
return bakedquad;
}
private static void fixVertexCompact(int[] data, int[] data2, int vertex, EaglerTextureAtlasSprite spriteFrom,
EaglerTextureAtlasSprite spriteTo, int side, int x1, int y1, int x2, int y2) {
int i = data.length / 4;
int j = i * vertex;
int i2 = data2.length / 4;
int j2 = i2 * vertex;
float f = Float.intBitsToFloat(data[j + 4]);
float f1 = Float.intBitsToFloat(data[j + 4 + 1]);
double d0 = spriteFrom.getSpriteU16(f);
double d1 = spriteFrom.getSpriteV16(f1);
float f2 = Float.intBitsToFloat(data[j + 0]);
float f3 = Float.intBitsToFloat(data[j + 1]);
float f4 = Float.intBitsToFloat(data[j + 2]);
float f5;
float f6;
switch (side) {
case 0:
f5 = f2;
f6 = 1.0F - f4;
break;
case 1:
f5 = f2;
f6 = f4;
break;
case 2:
f5 = 1.0F - f2;
f6 = 1.0F - f3;
break;
case 3:
f5 = f2;
f6 = 1.0F - f3;
break;
case 4:
f5 = f4;
f6 = 1.0F - f3;
break;
case 5:
f5 = 1.0F - f4;
f6 = 1.0F - f3;
break;
default:
return;
}
float f7 = 15.968F;
float f8 = 15.968F;
if (d0 < (double) x1) {
f5 = (float) ((double) f5 + ((double) x1 - d0) / (double) f7);
d0 = (double) x1;
}
if (d0 > (double) x2) {
f5 = (float) ((double) f5 - (d0 - (double) x2) / (double) f7);
d0 = (double) x2;
}
if (d1 < (double) y1) {
f6 = (float) ((double) f6 + ((double) y1 - d1) / (double) f8);
d1 = (double) y1;
}
if (d1 > (double) y2) {
f6 = (float) ((double) f6 - (d1 - (double) y2) / (double) f8);
d1 = (double) y2;
}
switch (side) {
case 0:
f2 = f5;
f4 = 1.0F - f6;
break;
case 1:
f2 = f5;
f4 = f6;
break;
case 2:
f2 = 1.0F - f5;
f3 = 1.0F - f6;
break;
case 3:
f2 = f5;
f3 = 1.0F - f6;
break;
case 4:
f4 = f5;
f3 = 1.0F - f6;
break;
case 5:
f4 = 1.0F - f5;
f3 = 1.0F - f6;
break;
default:
return;
}
data[j + 4] = data2[j2 + 4] = Float.floatToRawIntBits(spriteTo.getInterpolatedU(d0));
data[j + 4 + 1] = data2[j2 + 4 + 1] = Float.floatToRawIntBits(spriteTo.getInterpolatedV(d1));
data[j + 0] = data2[j2 + 0] = Float.floatToRawIntBits(f2);
data[j + 1] = data2[j2 + 1] = Float.floatToRawIntBits(f3);
data[j + 2] = data2[j2 + 2] = Float.floatToRawIntBits(f4);
}
private static enum Dir {
UP, UP_RIGHT, RIGHT, DOWN_RIGHT, DOWN, DOWN_LEFT, LEFT, UP_LEFT;
public static final ConnectedTexturesCompact.Dir[] VALUES = values();
}
}

View File

@ -0,0 +1,972 @@
package net.optifine;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.TreeSet;
import net.lax1dude.eaglercraft.v1_8.internal.ITextureGL;
import net.lax1dude.eaglercraft.v1_8.minecraft.EaglerTextureAtlasSprite;
import net.lax1dude.eaglercraft.v1_8.opengl.EaglercraftGPU;
import net.lax1dude.eaglercraft.v1_8.opengl.GlStateManager;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.block.model.BlockPart;
import net.minecraft.client.renderer.block.model.BlockPartFace;
import net.minecraft.client.renderer.block.model.FaceBakery;
import net.minecraft.client.renderer.block.model.ItemModelGenerator;
import net.minecraft.client.renderer.block.model.ModelBlock;
import net.minecraft.client.renderer.texture.ITextureObject;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.resources.model.IBakedModel;
import net.minecraft.client.resources.model.ModelBakery;
import net.minecraft.client.resources.model.ModelManager;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.client.resources.model.ModelRotation;
import net.minecraft.client.resources.model.SimpleBakedModel;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemArmor;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.optifine.config.IParserInt;
import net.optifine.config.NbtTagValue;
import net.optifine.config.ParserEnchantmentId;
import net.optifine.config.RangeInt;
import net.optifine.config.RangeListInt;
import net.optifine.render.Blender;
import net.optifine.util.StrUtils;
import net.optifine.util.TextureUtils;
public class CustomItemProperties {
public String name = null;
public String basePath = null;
public int type = 1;
public int[] items = null;
public String texture = null;
public Map<String, String> mapTextures = null;
public String model = null;
public Map<String, String> mapModels = null;
public RangeListInt damage = null;
public boolean damagePercent = false;
public int damageMask = 0;
public RangeListInt stackSize = null;
public RangeListInt enchantmentIds = null;
public RangeListInt enchantmentLevels = null;
public NbtTagValue[] nbtTagValues = null;
public int hand = 0;
public int blend = 1;
public float speed = 0.0F;
public float rotation = 0.0F;
public int layer = 0;
public float duration = 1.0F;
public int weight = 0;
public ResourceLocation textureLocation = null;
public Map mapTextureLocations = null;
public EaglerTextureAtlasSprite sprite = null;
public Map mapSprites = null;
public IBakedModel bakedModelTexture = null;
public Map<String, IBakedModel> mapBakedModelsTexture = null;
public IBakedModel bakedModelFull = null;
public Map<String, IBakedModel> mapBakedModelsFull = null;
private int textureWidth = 0;
private int textureHeight = 0;
public static final int TYPE_UNKNOWN = 0;
public static final int TYPE_ITEM = 1;
public static final int TYPE_ENCHANTMENT = 2;
public static final int TYPE_ARMOR = 3;
public static final int HAND_ANY = 0;
public static final int HAND_MAIN = 1;
public static final int HAND_OFF = 2;
public static final String INVENTORY = "inventory";
public CustomItemProperties(Properties props, String path) {
this.name = parseName(path);
this.basePath = parseBasePath(path);
this.type = this.parseType(props.getProperty("type"));
this.items = this.parseItems(props.getProperty("items"), props.getProperty("matchItems"));
this.mapModels = parseModels(props, this.basePath);
this.model = parseModel(props.getProperty("model"), path, this.basePath, this.type, this.mapModels);
this.mapTextures = parseTextures(props, this.basePath);
boolean flag = this.mapModels == null && this.model == null;
this.texture = parseTexture(props.getProperty("texture"), props.getProperty("tile"),
props.getProperty("source"), path, this.basePath, this.type, this.mapTextures, flag);
String s = props.getProperty("damage");
if (s != null) {
this.damagePercent = s.contains("%");
s = s.replace("%", "");
this.damage = this.parseRangeListInt(s);
this.damageMask = this.parseInt(props.getProperty("damageMask"), 0);
}
this.stackSize = this.parseRangeListInt(props.getProperty("stackSize"));
this.enchantmentIds = this.parseRangeListInt(props.getProperty("enchantmentIDs"), new ParserEnchantmentId());
this.enchantmentLevels = this.parseRangeListInt(props.getProperty("enchantmentLevels"));
this.nbtTagValues = this.parseNbtTagValues(props);
this.hand = this.parseHand(props.getProperty("hand"));
this.blend = Blender.parseBlend(props.getProperty("blend"));
this.speed = this.parseFloat(props.getProperty("speed"), 0.0F);
this.rotation = this.parseFloat(props.getProperty("rotation"), 0.0F);
this.layer = this.parseInt(props.getProperty("layer"), 0);
this.weight = this.parseInt(props.getProperty("weight"), 0);
this.duration = this.parseFloat(props.getProperty("duration"), 1.0F);
}
private static 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;
}
private static String parseBasePath(String path) {
int i = path.lastIndexOf(47);
return i < 0 ? "" : path.substring(0, i);
}
private int parseType(String str) {
if (str == null) {
return 1;
} else if (str.equals("item")) {
return 1;
} else if (str.equals("enchantment")) {
return 2;
} else if (str.equals("armor")) {
return 3;
} else {
Config.warn("Unknown method: " + str);
return 0;
}
}
private int[] parseItems(String str, String str2) {
if (str == null) {
str = str2;
}
if (str == null) {
return null;
} else {
str = str.trim();
Set set = new TreeSet();
String[] astring = Config.tokenize(str, " ");
label45:
for (int i = 0; i < astring.length; ++i) {
String s = astring[i];
int j = Config.parseInt(s, -1);
if (j >= 0) {
set.add(Integer.valueOf(j));
} else {
if (s.contains("-")) {
String[] astring1 = Config.tokenize(s, "-");
if (astring1.length == 2) {
int k = Config.parseInt(astring1[0], -1);
int l = Config.parseInt(astring1[1], -1);
if (k >= 0 && l >= 0) {
int i1 = Math.min(k, l);
int j1 = Math.max(k, l);
int k1 = i1;
while (true) {
if (k1 > j1) {
continue label45;
}
set.add(Integer.valueOf(k1));
++k1;
}
}
}
}
Item item = Item.getByNameOrId(s);
if (item == null) {
Config.warn("Item not found: " + s);
} else {
int i2 = Item.getIdFromItem(item);
if (i2 <= 0) {
Config.warn("Item not found: " + s);
} else {
set.add(Integer.valueOf(i2));
}
}
}
}
Integer[] ainteger = (Integer[]) ((Integer[]) set.toArray(new Integer[set.size()]));
int[] aint = new int[ainteger.length];
for (int l1 = 0; l1 < aint.length; ++l1) {
aint[l1] = ainteger[l1].intValue();
}
return aint;
}
}
private static String parseTexture(String texStr, String texStr2, String texStr3, String path, String basePath,
int type, Map<String, String> mapTexs, boolean textureFromPath) {
if (texStr == null) {
texStr = texStr2;
}
if (texStr == null) {
texStr = texStr3;
}
if (texStr != null) {
String s2 = ".png";
if (texStr.endsWith(s2)) {
texStr = texStr.substring(0, texStr.length() - s2.length());
}
texStr = fixTextureName(texStr, basePath);
return texStr;
} else if (type == 3) {
return null;
} else {
if (mapTexs != null) {
String s = (String) mapTexs.get("texture.bow_standby");
if (s != null) {
return s;
}
}
if (!textureFromPath) {
return null;
} else {
String s1 = path;
int i = path.lastIndexOf(47);
if (i >= 0) {
s1 = path.substring(i + 1);
}
int j = s1.lastIndexOf(46);
if (j >= 0) {
s1 = s1.substring(0, j);
}
s1 = fixTextureName(s1, basePath);
return s1;
}
}
}
private static Map parseTextures(Properties props, String basePath) {
String s = "texture.";
Map map = getMatchingProperties(props, s);
if (map.size() <= 0) {
return null;
} else {
Set set = map.keySet();
Map map1 = new LinkedHashMap();
for (Object e : set) {
String s1 = (String) e;
String s2 = (String) map.get(s1);
s2 = fixTextureName(s2, basePath);
map1.put(s1, s2);
}
return map1;
}
}
private static String fixTextureName(String iconName, String basePath) {
iconName = TextureUtils.fixResourcePath(iconName, basePath);
if (!iconName.startsWith(basePath) && !iconName.startsWith("textures/") && !iconName.startsWith("mcpatcher/")) {
iconName = basePath + "/" + iconName;
}
if (iconName.endsWith(".png")) {
iconName = iconName.substring(0, iconName.length() - 4);
}
if (iconName.startsWith("/")) {
iconName = iconName.substring(1);
}
return iconName;
}
private static String parseModel(String modelStr, String path, String basePath, int type,
Map<String, String> mapModelNames) {
if (modelStr != null) {
String s1 = ".json";
if (modelStr.endsWith(s1)) {
modelStr = modelStr.substring(0, modelStr.length() - s1.length());
}
modelStr = fixModelName(modelStr, basePath);
return modelStr;
} else if (type == 3) {
return null;
} else {
if (mapModelNames != null) {
String s = (String) mapModelNames.get("model.bow_standby");
if (s != null) {
return s;
}
}
return modelStr;
}
}
private static Map parseModels(Properties props, String basePath) {
String s = "model.";
Map map = getMatchingProperties(props, s);
if (map.size() <= 0) {
return null;
} else {
Set set = map.keySet();
Map map1 = new LinkedHashMap();
for (Object e : set) {
String s1 = (String) e;
String s2 = (String) map.get(s1);
s2 = fixModelName(s2, basePath);
map1.put(s1, s2);
}
return map1;
}
}
private static String fixModelName(String modelName, String basePath) {
modelName = TextureUtils.fixResourcePath(modelName, basePath);
boolean flag = modelName.startsWith("block/") || modelName.startsWith("item/");
if (!modelName.startsWith(basePath) && !flag && !modelName.startsWith("mcpatcher/")) {
modelName = basePath + "/" + modelName;
}
String s = ".json";
if (modelName.endsWith(s)) {
modelName = modelName.substring(0, modelName.length() - s.length());
}
if (modelName.startsWith("/")) {
modelName = modelName.substring(1);
}
return modelName;
}
private int parseInt(String str, int defVal) {
if (str == null) {
return defVal;
} else {
str = str.trim();
int i = Config.parseInt(str, Integer.MIN_VALUE);
if (i == Integer.MIN_VALUE) {
Config.warn("Invalid integer: " + str);
return defVal;
} else {
return i;
}
}
}
private float parseFloat(String str, float defVal) {
if (str == null) {
return defVal;
} else {
str = str.trim();
float f = Config.parseFloat(str, Float.MIN_VALUE);
if (f == Float.MIN_VALUE) {
Config.warn("Invalid float: " + str);
return defVal;
} else {
return f;
}
}
}
private RangeListInt parseRangeListInt(String str) {
return this.parseRangeListInt(str, (IParserInt) null);
}
private RangeListInt parseRangeListInt(String str, IParserInt parser) {
if (str == null) {
return null;
} else {
String[] astring = Config.tokenize(str, " ");
RangeListInt rangelistint = new RangeListInt();
for (int i = 0; i < astring.length; ++i) {
String s = astring[i];
if (parser != null) {
int j = parser.parse(s, Integer.MIN_VALUE);
if (j != Integer.MIN_VALUE) {
rangelistint.addRange(new RangeInt(j, j));
continue;
}
}
RangeInt rangeint = this.parseRangeInt(s);
if (rangeint == null) {
Config.warn("Invalid range list: " + str);
return null;
}
rangelistint.addRange(rangeint);
}
return rangelistint;
}
}
private RangeInt parseRangeInt(String str) {
if (str == null) {
return null;
} else {
str = str.trim();
int i = str.length() - str.replace("-", "").length();
if (i > 1) {
Config.warn("Invalid range: " + str);
return null;
} else {
String[] astring = Config.tokenize(str, "- ");
int[] aint = new int[astring.length];
for (int j = 0; j < astring.length; ++j) {
String s = astring[j];
int k = Config.parseInt(s, -1);
if (k < 0) {
Config.warn("Invalid range: " + str);
return null;
}
aint[j] = k;
}
if (aint.length == 1) {
int i1 = aint[0];
if (str.startsWith("-")) {
return new RangeInt(0, i1);
} else if (str.endsWith("-")) {
return new RangeInt(i1, 65535);
} else {
return new RangeInt(i1, i1);
}
} else if (aint.length == 2) {
int l = Math.min(aint[0], aint[1]);
int j1 = Math.max(aint[0], aint[1]);
return new RangeInt(l, j1);
} else {
Config.warn("Invalid range: " + str);
return null;
}
}
}
}
private NbtTagValue[] parseNbtTagValues(Properties props) {
String s = "nbt.";
Map map = getMatchingProperties(props, s);
if (map.size() <= 0) {
return null;
} else {
List list = new ArrayList();
for (Object e : map.keySet()) {
String s1 = (String) e;
String s2 = (String) map.get(s1);
String s3 = s1.substring(s.length());
NbtTagValue nbttagvalue = new NbtTagValue(s3, s2);
list.add(nbttagvalue);
}
NbtTagValue[] anbttagvalue = (NbtTagValue[]) ((NbtTagValue[]) list.toArray(new NbtTagValue[list.size()]));
return anbttagvalue;
}
}
private static Map getMatchingProperties(Properties props, String keyPrefix) {
Map map = new LinkedHashMap();
for (Object e : props.keySet()) {
String s = (String) e;
String s1 = props.getProperty(s);
if (s.startsWith(keyPrefix)) {
map.put(s, s1);
}
}
return map;
}
private int parseHand(String str) {
if (str == null) {
return 0;
} else {
str = str.toLowerCase();
if (str.equals("any")) {
return 0;
} else if (str.equals("main")) {
return 1;
} else if (str.equals("off")) {
return 2;
} else {
Config.warn("Invalid hand: " + str);
return 0;
}
}
}
public boolean isValid(String path) {
if (this.name != null && this.name.length() > 0) {
if (this.basePath == null) {
Config.warn("No base path found: " + path);
return false;
} else if (this.type == 0) {
Config.warn("No type defined: " + path);
return false;
} else {
if (this.type == 1 || this.type == 3) {
if (this.items == null) {
this.items = this.detectItems();
}
if (this.items == null) {
Config.warn("No items defined: " + path);
return false;
}
}
if (this.texture == null && this.mapTextures == null && this.model == null && this.mapModels == null) {
Config.warn("No texture or model specified: " + path);
return false;
} else if (this.type == 2 && this.enchantmentIds == null) {
Config.warn("No enchantmentIDs specified: " + path);
return false;
} else {
return true;
}
}
} else {
Config.warn("No name found: " + path);
return false;
}
}
private int[] detectItems() {
Item item = Item.getByNameOrId(this.name);
if (item == null) {
return null;
} else {
int i = Item.getIdFromItem(item);
return i <= 0 ? null : new int[] { i };
}
}
public void updateIcons(TextureMap textureMap) {
if (this.texture != null) {
this.textureLocation = this.getTextureLocation(this.texture);
if (this.type == 1) {
ResourceLocation resourcelocation = this.getSpriteLocation(this.textureLocation);
this.sprite = textureMap.registerSprite(resourcelocation);
}
}
if (this.mapTextures != null) {
this.mapTextureLocations = new HashMap();
this.mapSprites = new HashMap();
for (String s : this.mapTextures.keySet()) {
String s1 = (String) this.mapTextures.get(s);
ResourceLocation resourcelocation1 = this.getTextureLocation(s1);
this.mapTextureLocations.put(s, resourcelocation1);
if (this.type == 1) {
ResourceLocation resourcelocation2 = this.getSpriteLocation(resourcelocation1);
EaglerTextureAtlasSprite textureatlassprite = textureMap.registerSprite(resourcelocation2);
this.mapSprites.put(s, textureatlassprite);
}
}
}
}
private ResourceLocation getTextureLocation(String texName) {
if (texName == null) {
return null;
} else {
ResourceLocation resourcelocation = new ResourceLocation(texName);
String s = resourcelocation.getResourceDomain();
String s1 = resourcelocation.getResourcePath();
if (!s1.contains("/")) {
s1 = "textures/items/" + s1;
}
String s2 = s1 + ".png";
ResourceLocation resourcelocation1 = new ResourceLocation(s, s2);
boolean flag = Config.hasResource(resourcelocation1);
if (!flag) {
Config.warn("File not found: " + s2);
}
return resourcelocation1;
}
}
private ResourceLocation getSpriteLocation(ResourceLocation resLoc) {
String s = resLoc.getResourcePath();
s = StrUtils.removePrefix(s, "textures/");
s = StrUtils.removeSuffix(s, ".png");
ResourceLocation resourcelocation = new ResourceLocation(resLoc.getResourceDomain(), s);
return resourcelocation;
}
public void updateModelTexture(TextureMap textureMap, ItemModelGenerator itemModelGenerator) {
if (this.texture != null || this.mapTextures != null) {
String[] astring = this.getModelTextures();
boolean flag = this.isUseTint();
this.bakedModelTexture = makeBakedModel(textureMap, itemModelGenerator, astring, flag);
if (this.type == 1 && this.mapTextures != null) {
for (String s : this.mapTextures.keySet()) {
String s1 = (String) this.mapTextures.get(s);
String s2 = StrUtils.removePrefix(s, "texture.");
if (s2.startsWith("bow") || s2.startsWith("fishing_rod") || s2.startsWith("shield")) {
String[] astring1 = new String[] { s1 };
IBakedModel ibakedmodel = makeBakedModel(textureMap, itemModelGenerator, astring1, flag);
if (this.mapBakedModelsTexture == null) {
this.mapBakedModelsTexture = new HashMap();
}
this.mapBakedModelsTexture.put(s2, ibakedmodel);
}
}
}
}
}
private boolean isUseTint() {
return true;
}
private static IBakedModel makeBakedModel(TextureMap textureMap, ItemModelGenerator itemModelGenerator,
String[] textures, boolean useTint) {
String[] astring = new String[textures.length];
for (int i = 0; i < astring.length; ++i) {
String s = textures[i];
astring[i] = StrUtils.removePrefix(s, "textures/");
}
ModelBlock modelblock = makeModelBlock(astring);
ModelBlock modelblock1 = itemModelGenerator.makeItemModel(textureMap, modelblock);
IBakedModel ibakedmodel = bakeModel(textureMap, modelblock1, useTint);
return ibakedmodel;
}
private String[] getModelTextures() {
if (this.type == 1 && this.items.length == 1) {
Item item = Item.getItemById(this.items[0]);
if (item == Items.potionitem && this.damage != null && this.damage.getCountRanges() > 0) {
RangeInt rangeint = this.damage.getRange(0);
int i = rangeint.getMin();
boolean flag = (i & 16384) != 0;
String s5 = this.getMapTexture(this.mapTextures, "texture.potion_overlay", "items/potion_overlay");
String s6 = null;
if (flag) {
s6 = this.getMapTexture(this.mapTextures, "texture.potion_bottle_splash",
"items/potion_bottle_splash");
} else {
s6 = this.getMapTexture(this.mapTextures, "texture.potion_bottle_drinkable",
"items/potion_bottle_drinkable");
}
return new String[] { s5, s6 };
}
if (item instanceof ItemArmor) {
ItemArmor itemarmor = (ItemArmor) item;
if (itemarmor.getArmorMaterial() == ItemArmor.ArmorMaterial.LEATHER) {
String s = "leather";
String s1 = "helmet";
if (itemarmor.armorType == 0) {
s1 = "helmet";
}
if (itemarmor.armorType == 1) {
s1 = "chestplate";
}
if (itemarmor.armorType == 2) {
s1 = "leggings";
}
if (itemarmor.armorType == 3) {
s1 = "boots";
}
String s2 = s + "_" + s1;
String s3 = this.getMapTexture(this.mapTextures, "texture." + s2, "items/" + s2);
String s4 = this.getMapTexture(this.mapTextures, "texture." + s2 + "_overlay",
"items/" + s2 + "_overlay");
return new String[] { s3, s4 };
}
}
}
return new String[] { this.texture };
}
private String getMapTexture(Map<String, String> map, String key, String def) {
if (map == null) {
return def;
} else {
String s = (String) map.get(key);
return s == null ? def : s;
}
}
private static ModelBlock makeModelBlock(String[] modelTextures) {
StringBuffer stringbuffer = new StringBuffer();
stringbuffer.append("{\"parent\": \"builtin/generated\",\"textures\": {");
for (int i = 0; i < modelTextures.length; ++i) {
String s = modelTextures[i];
if (i > 0) {
stringbuffer.append(", ");
}
stringbuffer.append("\"layer" + i + "\": \"" + s + "\"");
}
stringbuffer.append("}}");
String s1 = stringbuffer.toString();
ModelBlock modelblock = ModelBlock.deserialize(s1);
return modelblock;
}
private static IBakedModel bakeModel(TextureMap textureMap, ModelBlock modelBlockIn, boolean useTint) {
ModelRotation modelrotation = ModelRotation.X0_Y0;
boolean flag = false;
String s = modelBlockIn.resolveTextureName("particle");
EaglerTextureAtlasSprite textureatlassprite = textureMap.getAtlasSprite((new ResourceLocation(s)).toString());
SimpleBakedModel.Builder simplebakedmodel$builder = (new SimpleBakedModel.Builder(modelBlockIn))
.setTexture(textureatlassprite);
for (BlockPart blockpart : modelBlockIn.getElements()) {
for (EnumFacing enumfacing : blockpart.mapFaces.keySet()) {
BlockPartFace blockpartface = (BlockPartFace) blockpart.mapFaces.get(enumfacing);
if (!useTint) {
blockpartface = new BlockPartFace(blockpartface.cullFace, -1, blockpartface.texture,
blockpartface.blockFaceUV);
}
String s1 = modelBlockIn.resolveTextureName(blockpartface.texture);
EaglerTextureAtlasSprite textureatlassprite1 = textureMap
.getAtlasSprite((new ResourceLocation(s1)).toString());
BakedQuad bakedquad = makeBakedQuad(blockpart, blockpartface, textureatlassprite1, enumfacing,
modelrotation, flag);
if (blockpartface.cullFace == null) {
simplebakedmodel$builder.addGeneralQuad(bakedquad);
} else {
simplebakedmodel$builder.addFaceQuad(modelrotation.rotateFace(blockpartface.cullFace), bakedquad);
}
}
}
return simplebakedmodel$builder.makeBakedModel();
}
private static BakedQuad makeBakedQuad(BlockPart blockPart, BlockPartFace blockPartFace,
EaglerTextureAtlasSprite textureAtlasSprite, EnumFacing enumFacing, ModelRotation modelRotation,
boolean uvLocked) {
FaceBakery facebakery = new FaceBakery();
return facebakery.makeBakedQuad(blockPart.positionFrom, blockPart.positionTo, blockPartFace, textureAtlasSprite,
enumFacing, modelRotation, blockPart.partRotation, uvLocked, blockPart.shade);
}
public String toString() {
return "" + this.basePath + "/" + this.name + ", type: " + this.type + ", items: ["
+ Config.arrayToString(this.items) + "], textture: " + this.texture;
}
public float getTextureWidth(TextureManager textureManager) {
if (this.textureWidth <= 0) {
if (this.textureLocation != null) {
ITextureObject itextureobject = textureManager.getTexture(this.textureLocation);
ITextureGL nativeTex = EaglercraftGPU.getNativeTexture(itextureobject.getGlTextureId());
this.textureWidth = nativeTex != null ? nativeTex.getWidth() : 0;
}
if (this.textureWidth <= 0) {
this.textureWidth = 16;
}
}
return (float) this.textureWidth;
}
public float getTextureHeight(TextureManager textureManager) {
if (this.textureHeight <= 0) {
if (this.textureLocation != null) {
ITextureObject itextureobject = textureManager.getTexture(this.textureLocation);
ITextureGL nativeTex = EaglercraftGPU.getNativeTexture(itextureobject.getGlTextureId());
this.textureHeight = nativeTex != null ? nativeTex.getWidth() : 0;
}
if (this.textureHeight <= 0) {
this.textureHeight = 16;
}
}
return (float) this.textureHeight;
}
public IBakedModel getBakedModel(ResourceLocation modelLocation, boolean fullModel) {
IBakedModel ibakedmodel;
Map<String, IBakedModel> map;
if (fullModel) {
ibakedmodel = this.bakedModelFull;
map = this.mapBakedModelsFull;
} else {
ibakedmodel = this.bakedModelTexture;
map = this.mapBakedModelsTexture;
}
if (modelLocation != null && map != null) {
String s = modelLocation.getResourcePath();
IBakedModel ibakedmodel1 = (IBakedModel) map.get(s);
if (ibakedmodel1 != null) {
return ibakedmodel1;
}
}
return ibakedmodel;
}
public void loadModels(ModelBakery modelBakery) {
if (this.model != null) {
loadItemModel(modelBakery, this.model);
}
if (this.type == 1 && this.mapModels != null) {
for (String s : this.mapModels.keySet()) {
String s1 = (String) this.mapModels.get(s);
String s2 = StrUtils.removePrefix(s, "model.");
if (s2.startsWith("bow") || s2.startsWith("fishing_rod") || s2.startsWith("shield")) {
loadItemModel(modelBakery, s1);
}
}
}
}
public void updateModelsFull() {
ModelManager modelmanager = Minecraft.getMinecraft().getModelManager();
IBakedModel ibakedmodel = modelmanager.getMissingModel();
if (this.model != null) {
ResourceLocation resourcelocation = getModelLocation(this.model);
ModelResourceLocation modelresourcelocation = new ModelResourceLocation(resourcelocation, "inventory");
this.bakedModelFull = modelmanager.getModel(modelresourcelocation);
if (this.bakedModelFull == ibakedmodel) {
Config.warn("Custom Items: Model not found " + modelresourcelocation.getResourcePath());
this.bakedModelFull = null;
}
}
if (this.type == 1 && this.mapModels != null) {
for (String s : this.mapModels.keySet()) {
String s1 = (String) this.mapModels.get(s);
String s2 = StrUtils.removePrefix(s, "model.");
if (s2.startsWith("bow") || s2.startsWith("fishing_rod") || s2.startsWith("shield")) {
ResourceLocation resourcelocation1 = getModelLocation(s1);
ModelResourceLocation modelresourcelocation1 = new ModelResourceLocation(resourcelocation1,
"inventory");
IBakedModel ibakedmodel1 = modelmanager.getModel(modelresourcelocation1);
if (ibakedmodel1 == ibakedmodel) {
Config.warn("Custom Items: Model not found " + modelresourcelocation1.getResourcePath());
} else {
if (this.mapBakedModelsFull == null) {
this.mapBakedModelsFull = new HashMap();
}
this.mapBakedModelsFull.put(s2, ibakedmodel1);
}
}
}
}
}
private static void loadItemModel(ModelBakery modelBakery, String model) {
ResourceLocation resourcelocation = getModelLocation(model);
ModelResourceLocation modelresourcelocation = new ModelResourceLocation(resourcelocation, "inventory");
modelBakery.loadItemModel(resourcelocation.toString(), modelresourcelocation, resourcelocation);
}
private static ResourceLocation getModelLocation(String modelName) {
// return Reflector.ModelLoader.exists() && !modelName.startsWith("mcpatcher/")
// && !modelName.startsWith("optifine/") ? new ResourceLocation("models/" + modelName)
// : new ResourceLocation(modelName);
return new ResourceLocation(modelName);
}
}

View File

@ -0,0 +1,840 @@
package net.optifine;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import net.lax1dude.eaglercraft.v1_8.opengl.GlStateManager;
import net.minecraft.client.Minecraft;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.renderer.block.model.ItemModelGenerator;
import net.minecraft.client.renderer.entity.RenderItem;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.resources.IResourcePack;
import net.minecraft.client.resources.model.IBakedModel;
import net.minecraft.client.resources.model.ModelBakery;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.potion.Potion;
import net.minecraft.util.ResourceLocation;
import net.optifine.config.NbtTagValue;
import net.optifine.render.Blender;
import net.optifine.util.PropertiesOrdered;
import net.optifine.util.ResUtils;
import net.optifine.util.StrUtils;
public class CustomItems {
private static CustomItemProperties[][] itemProperties = (CustomItemProperties[][]) null;
private static CustomItemProperties[][] enchantmentProperties = (CustomItemProperties[][]) null;
private static Map mapPotionIds = null;
private static ItemModelGenerator itemModelGenerator = new ItemModelGenerator();
private static boolean useGlint = true;
private static boolean renderOffHand = false;
public static final int MASK_POTION_SPLASH = 16384;
public static final int MASK_POTION_NAME = 63;
public static final int MASK_POTION_EXTENDED = 64;
public static final String KEY_TEXTURE_OVERLAY = "texture.potion_overlay";
public static final String KEY_TEXTURE_SPLASH = "texture.potion_bottle_splash";
public static final String KEY_TEXTURE_DRINKABLE = "texture.potion_bottle_drinkable";
public static final String DEFAULT_TEXTURE_OVERLAY = "items/potion_overlay";
public static final String DEFAULT_TEXTURE_SPLASH = "items/potion_bottle_splash";
public static final String DEFAULT_TEXTURE_DRINKABLE = "items/potion_bottle_drinkable";
private static final int[][] EMPTY_INT2_ARRAY = new int[0][];
private static final String TYPE_POTION_NORMAL = "normal";
private static final String TYPE_POTION_SPLASH = "splash";
private static final String TYPE_POTION_LINGER = "linger";
public static void update() {
itemProperties = (CustomItemProperties[][]) null;
enchantmentProperties = (CustomItemProperties[][]) null;
useGlint = true;
if (Config.isCustomItems()) {
readCitProperties("mcpatcher/cit.properties");
IResourcePack[] airesourcepack = Config.getResourcePacks();
for (int i = airesourcepack.length - 1; i >= 0; --i) {
IResourcePack iresourcepack = airesourcepack[i];
update(iresourcepack);
}
update(Minecraft.getMinecraft().getDefaultResourcePack());
if (itemProperties.length <= 0) {
itemProperties = (CustomItemProperties[][]) null;
}
if (enchantmentProperties.length <= 0) {
enchantmentProperties = (CustomItemProperties[][]) null;
}
}
}
private static void readCitProperties(String fileName) {
ResourceLocation resourcelocation = new ResourceLocation(fileName);
try (InputStream inputstream = Minecraft.getMinecraft().getResourceManager().getResource(resourcelocation)
.getInputStream()) {
Config.dbg("CustomItems: Loading " + fileName);
Properties properties = new PropertiesOrdered();
properties.load(inputstream);
inputstream.close();
useGlint = Config.parseBoolean(properties.getProperty("useGlint"), true);
} catch (FileNotFoundException var4) {
return;
} catch (IOException ioexception) {
ioexception.printStackTrace();
}
}
private static void update(IResourcePack rp) {
List<String> astring = ResUtils.collectPropertyFiles(rp, "mcpatcher/cit/", "optifine/cit/");
Map map = makeAutoImageProperties(rp);
if (map.size() > 0) {
astring.addAll(map.keySet());
}
Collections.sort(astring);
List list = makePropertyList(itemProperties);
List list1 = makePropertyList(enchantmentProperties);
for (int i = 0; i < astring.size(); ++i) {
String s = astring.get(i);
Config.dbg("CustomItems: " + s);
try {
CustomItemProperties customitemproperties = null;
if (map.containsKey(s)) {
customitemproperties = (CustomItemProperties) map.get(s);
}
if (customitemproperties == null) {
ResourceLocation resourcelocation = new ResourceLocation(s);
InputStream inputstream = rp.getInputStream(resourcelocation);
if (inputstream == null) {
Config.warn("CustomItems file not found: " + s);
continue;
}
Properties properties = new PropertiesOrdered();
properties.load(inputstream);
inputstream.close();
customitemproperties = new CustomItemProperties(properties, s);
}
if (customitemproperties.isValid(s)) {
addToItemList(customitemproperties, list);
addToEnchantmentList(customitemproperties, list1);
}
} catch (FileNotFoundException var11) {
Config.warn("CustomItems file not found: " + s);
} catch (Exception exception) {
exception.printStackTrace();
}
}
itemProperties = propertyListToArray(list);
enchantmentProperties = propertyListToArray(list1);
Comparator comparator = getPropertiesComparator();
for (int j = 0; j < itemProperties.length; ++j) {
CustomItemProperties[] acustomitemproperties = itemProperties[j];
if (acustomitemproperties != null) {
Arrays.sort(acustomitemproperties, comparator);
}
}
for (int k = 0; k < enchantmentProperties.length; ++k) {
CustomItemProperties[] acustomitemproperties1 = enchantmentProperties[k];
if (acustomitemproperties1 != null) {
Arrays.sort(acustomitemproperties1, comparator);
}
}
}
private static Comparator getPropertiesComparator() {
Comparator comparator = new Comparator() {
public int compare(Object o1, Object o2) {
CustomItemProperties customitemproperties = (CustomItemProperties) o1;
CustomItemProperties customitemproperties1 = (CustomItemProperties) o2;
return customitemproperties.layer != customitemproperties1.layer
? customitemproperties.layer - customitemproperties1.layer
: (customitemproperties.weight != customitemproperties1.weight
? customitemproperties1.weight - customitemproperties.weight
: (!customitemproperties.basePath.equals(customitemproperties1.basePath)
? customitemproperties.basePath.compareTo(customitemproperties1.basePath)
: customitemproperties.name.compareTo(customitemproperties1.name)));
}
};
return comparator;
}
public static void updateIcons(TextureMap textureMap) {
for (CustomItemProperties customitemproperties : getAllProperties()) {
customitemproperties.updateIcons(textureMap);
}
}
public static void loadModels(ModelBakery modelBakery) {
for (CustomItemProperties customitemproperties : getAllProperties()) {
customitemproperties.loadModels(modelBakery);
}
}
public static void updateModels() {
for (CustomItemProperties customitemproperties : getAllProperties()) {
if (customitemproperties.type == 1) {
TextureMap texturemap = Minecraft.getMinecraft().getTextureMapBlocks();
customitemproperties.updateModelTexture(texturemap, itemModelGenerator);
customitemproperties.updateModelsFull();
}
}
}
private static List<CustomItemProperties> getAllProperties() {
List<CustomItemProperties> list = new ArrayList();
addAll(itemProperties, list);
addAll(enchantmentProperties, list);
return list;
}
private static void addAll(CustomItemProperties[][] cipsArr, List<CustomItemProperties> list) {
if (cipsArr != null) {
for (int i = 0; i < cipsArr.length; ++i) {
CustomItemProperties[] acustomitemproperties = cipsArr[i];
if (acustomitemproperties != null) {
for (int j = 0; j < acustomitemproperties.length; ++j) {
CustomItemProperties customitemproperties = acustomitemproperties[j];
if (customitemproperties != null) {
list.add(customitemproperties);
}
}
}
}
}
}
private static Map makeAutoImageProperties(IResourcePack rp) {
Map map = new HashMap();
map.putAll(makePotionImageProperties(rp, "normal", Item.getIdFromItem(Items.potionitem)));
map.putAll(makePotionImageProperties(rp, "splash", Item.getIdFromItem(Items.potionitem)));
map.putAll(makePotionImageProperties(rp, "linger", Item.getIdFromItem(Items.potionitem)));
return map;
}
private static Map makePotionImageProperties(IResourcePack rp, String type, int itemId) {
Map map = new HashMap();
String s = type + "/";
String[] astring = new String[] { "mcpatcher/cit/potion/" + s, "mcpatcher/cit/Potion/" + s, "optifine/cit/potion/" + s };
String[] astring1 = new String[] { ".png" };
Collection<String> astring2 = ResUtils.collectPotionFiles(rp, astring);
for (String s1 : astring2) {
String name = StrUtils.removePrefixSuffix(s1, astring, astring1);
Properties properties = makePotionProperties(name, type, itemId, s1);
if (properties != null) {
String s3 = StrUtils.removeSuffix(s1, astring1) + ".properties";
CustomItemProperties customitemproperties = new CustomItemProperties(properties, s3);
map.put(s3, customitemproperties);
}
}
return map;
}
private static Properties makePotionProperties(String name, String type, int itemId, String path) {
if (StrUtils.endsWith(name, new String[] { "_n", "_s" })) {
return null;
} else if (name.equals("empty") && type.equals("normal")) {
itemId = Item.getIdFromItem(Items.glass_bottle);
Properties properties = new PropertiesOrdered();
properties.put("type", "item");
properties.put("items", "" + itemId);
return properties;
} else {
int[] aint = (int[]) ((int[]) getMapPotionIds().get(name));
if (aint == null) {
Config.warn("Potion not found for image: " + path);
return null;
} else {
StringBuffer stringbuffer = new StringBuffer();
for (int i = 0; i < aint.length; ++i) {
int j = aint[i];
if (type.equals("splash")) {
j |= 16384;
}
if (i > 0) {
stringbuffer.append(" ");
}
stringbuffer.append(j);
}
int k = 16447;
if (name.equals("water") || name.equals("mundane")) {
k |= 64;
}
Properties properties1 = new PropertiesOrdered();
properties1.put("type", "item");
properties1.put("items", "" + itemId);
properties1.put("damage", "" + stringbuffer.toString());
properties1.put("damageMask", "" + k);
if (type.equals("splash")) {
properties1.put("texture.potion_bottle_splash", name);
} else {
properties1.put("texture.potion_bottle_drinkable", name);
}
return properties1;
}
}
}
private static Map getMapPotionIds() {
if (mapPotionIds == null) {
mapPotionIds = new LinkedHashMap();
mapPotionIds.put("water", getPotionId(0, 0));
mapPotionIds.put("awkward", getPotionId(0, 1));
mapPotionIds.put("thick", getPotionId(0, 2));
mapPotionIds.put("potent", getPotionId(0, 3));
mapPotionIds.put("regeneration", getPotionIds(1));
mapPotionIds.put("movespeed", getPotionIds(2));
mapPotionIds.put("fireresistance", getPotionIds(3));
mapPotionIds.put("poison", getPotionIds(4));
mapPotionIds.put("heal", getPotionIds(5));
mapPotionIds.put("nightvision", getPotionIds(6));
mapPotionIds.put("clear", getPotionId(7, 0));
mapPotionIds.put("bungling", getPotionId(7, 1));
mapPotionIds.put("charming", getPotionId(7, 2));
mapPotionIds.put("rank", getPotionId(7, 3));
mapPotionIds.put("weakness", getPotionIds(8));
mapPotionIds.put("damageboost", getPotionIds(9));
mapPotionIds.put("moveslowdown", getPotionIds(10));
mapPotionIds.put("leaping", getPotionIds(11));
mapPotionIds.put("harm", getPotionIds(12));
mapPotionIds.put("waterbreathing", getPotionIds(13));
mapPotionIds.put("invisibility", getPotionIds(14));
mapPotionIds.put("thin", getPotionId(15, 0));
mapPotionIds.put("debonair", getPotionId(15, 1));
mapPotionIds.put("sparkling", getPotionId(15, 2));
mapPotionIds.put("stinky", getPotionId(15, 3));
mapPotionIds.put("mundane", getPotionId(0, 4));
mapPotionIds.put("speed", mapPotionIds.get("movespeed"));
mapPotionIds.put("fire_resistance", mapPotionIds.get("fireresistance"));
mapPotionIds.put("instant_health", mapPotionIds.get("heal"));
mapPotionIds.put("night_vision", mapPotionIds.get("nightvision"));
mapPotionIds.put("strength", mapPotionIds.get("damageboost"));
mapPotionIds.put("slowness", mapPotionIds.get("moveslowdown"));
mapPotionIds.put("instant_damage", mapPotionIds.get("harm"));
mapPotionIds.put("water_breathing", mapPotionIds.get("waterbreathing"));
}
return mapPotionIds;
}
private static int[] getPotionIds(int baseId) {
return new int[] { baseId, baseId + 16, baseId + 32, baseId + 48 };
}
private static int[] getPotionId(int baseId, int subId) {
return new int[] { baseId + subId * 16 };
}
private static int getPotionNameDamage(String name) {
String s = "potion." + name;
Potion[] apotion = Potion.potionTypes;
for (int i = 0; i < apotion.length; ++i) {
Potion potion = apotion[i];
if (potion != null) {
String s1 = potion.getName();
if (s.equals(s1)) {
return potion.getId();
}
}
}
return -1;
}
private static List makePropertyList(CustomItemProperties[][] propsArr) {
List list = new ArrayList();
if (propsArr != null) {
for (int i = 0; i < propsArr.length; ++i) {
CustomItemProperties[] acustomitemproperties = propsArr[i];
List list1 = null;
if (acustomitemproperties != null) {
list1 = new ArrayList(Arrays.asList(acustomitemproperties));
}
list.add(list1);
}
}
return list;
}
private static CustomItemProperties[][] propertyListToArray(List list) {
CustomItemProperties[][] acustomitemproperties = new CustomItemProperties[list.size()][];
for (int i = 0; i < list.size(); ++i) {
List list1 = (List) list.get(i);
if (list1 != null) {
CustomItemProperties[] acustomitemproperties1 = (CustomItemProperties[]) ((CustomItemProperties[]) list1
.toArray(new CustomItemProperties[list1.size()]));
Arrays.sort(acustomitemproperties1, new CustomItemsComparator());
acustomitemproperties[i] = acustomitemproperties1;
}
}
return acustomitemproperties;
}
private static void addToItemList(CustomItemProperties cp, List itemList) {
if (cp.items != null) {
for (int i = 0; i < cp.items.length; ++i) {
int j = cp.items[i];
if (j <= 0) {
Config.warn("Invalid item ID: " + j);
} else {
addToList(cp, itemList, j);
}
}
}
}
private static void addToEnchantmentList(CustomItemProperties cp, List enchantmentList) {
if (cp.type == 2) {
if (cp.enchantmentIds != null) {
for (int i = 0; i < 256; ++i) {
if (cp.enchantmentIds.isInRange(i)) {
addToList(cp, enchantmentList, i);
}
}
}
}
}
private static void addToList(CustomItemProperties cp, List list, int id) {
while (id >= list.size()) {
list.add(null);
}
List list1 = (List) list.get(id);
if (list1 == null) {
list1 = new ArrayList();
list.set(id, list1);
}
list1.add(cp);
}
public static IBakedModel getCustomItemModel(ItemStack itemStack, IBakedModel model, ResourceLocation modelLocation,
boolean fullModel) {
if (!fullModel && model.isGui3d()) {
return model;
} else if (itemProperties == null) {
return model;
} else {
CustomItemProperties customitemproperties = getCustomItemProperties(itemStack, 1);
if (customitemproperties == null) {
return model;
} else {
IBakedModel ibakedmodel = customitemproperties.getBakedModel(modelLocation, fullModel);
return ibakedmodel != null ? ibakedmodel : model;
}
}
}
public static boolean bindCustomArmorTexture(ItemStack itemStack, int layer, String overlay) {
if (itemProperties == null) {
return false;
} else {
ResourceLocation resourcelocation = getCustomArmorLocation(itemStack, layer, overlay);
if (resourcelocation == null) {
return false;
} else {
Minecraft.getMinecraft().getTextureManager().bindTexture(resourcelocation);
return true;
}
}
}
private static ResourceLocation getCustomArmorLocation(ItemStack itemStack, int layer, String overlay) {
CustomItemProperties customitemproperties = getCustomItemProperties(itemStack, 3);
if (customitemproperties == null) {
return null;
} else if (customitemproperties.mapTextureLocations == null) {
return customitemproperties.textureLocation;
} else {
Item item = itemStack.getItem();
if (!(item instanceof ItemArmor)) {
return null;
} else {
ItemArmor itemarmor = (ItemArmor) item;
String s = itemarmor.getArmorMaterial().getName();
StringBuffer stringbuffer = new StringBuffer();
stringbuffer.append("texture.");
stringbuffer.append(s);
stringbuffer.append("_layer_");
stringbuffer.append(layer);
if (overlay != null) {
stringbuffer.append("_");
stringbuffer.append(overlay);
}
String s1 = stringbuffer.toString();
ResourceLocation resourcelocation = (ResourceLocation) customitemproperties.mapTextureLocations.get(s1);
return resourcelocation == null ? customitemproperties.textureLocation : resourcelocation;
}
}
}
private static CustomItemProperties getCustomItemProperties(ItemStack itemStack, int type) {
if (itemProperties == null) {
return null;
} else if (itemStack == null) {
return null;
} else {
Item item = itemStack.getItem();
int i = Item.getIdFromItem(item);
if (i >= 0 && i < itemProperties.length) {
CustomItemProperties[] acustomitemproperties = itemProperties[i];
if (acustomitemproperties != null) {
for (int j = 0; j < acustomitemproperties.length; ++j) {
CustomItemProperties customitemproperties = acustomitemproperties[j];
if (customitemproperties.type == type
&& matchesProperties(customitemproperties, itemStack, (int[][]) null)) {
return customitemproperties;
}
}
}
}
return null;
}
}
private static boolean matchesProperties(CustomItemProperties cip, ItemStack itemStack,
int[][] enchantmentIdLevels) {
Item item = itemStack.getItem();
if (cip.damage != null) {
int i = itemStack.getItemDamage();
if (cip.damageMask != 0) {
i &= cip.damageMask;
}
if (cip.damagePercent) {
int j = item.getMaxDamage();
i = (int) ((double) (i * 100) / (double) j);
}
if (!cip.damage.isInRange(i)) {
return false;
}
}
if (cip.stackSize != null && !cip.stackSize.isInRange(itemStack.stackSize)) {
return false;
} else {
int[][] aint = enchantmentIdLevels;
if (cip.enchantmentIds != null) {
if (enchantmentIdLevels == null) {
aint = getEnchantmentIdLevels(itemStack);
}
boolean flag = false;
for (int k = 0; k < aint.length; ++k) {
int l = aint[k][0];
if (cip.enchantmentIds.isInRange(l)) {
flag = true;
break;
}
}
if (!flag) {
return false;
}
}
if (cip.enchantmentLevels != null) {
if (aint == null) {
aint = getEnchantmentIdLevels(itemStack);
}
boolean flag1 = false;
for (int i1 = 0; i1 < aint.length; ++i1) {
int k1 = aint[i1][1];
if (cip.enchantmentLevels.isInRange(k1)) {
flag1 = true;
break;
}
}
if (!flag1) {
return false;
}
}
if (cip.nbtTagValues != null) {
NBTTagCompound nbttagcompound = itemStack.getTagCompound();
for (int j1 = 0; j1 < cip.nbtTagValues.length; ++j1) {
NbtTagValue nbttagvalue = cip.nbtTagValues[j1];
if (!nbttagvalue.matches(nbttagcompound)) {
return false;
}
}
}
if (cip.hand != 0) {
if (cip.hand == 1 && renderOffHand) {
return false;
}
if (cip.hand == 2 && !renderOffHand) {
return false;
}
}
return true;
}
}
private static int[][] getEnchantmentIdLevels(ItemStack itemStack) {
Item item = itemStack.getItem();
NBTTagList nbttaglist = item == Items.enchanted_book ? Items.enchanted_book.getEnchantments(itemStack)
: itemStack.getEnchantmentTagList();
if (nbttaglist != null && nbttaglist.tagCount() > 0) {
int[][] aint = new int[nbttaglist.tagCount()][2];
for (int i = 0; i < nbttaglist.tagCount(); ++i) {
NBTTagCompound nbttagcompound = nbttaglist.getCompoundTagAt(i);
int j = nbttagcompound.getShort("id");
int k = nbttagcompound.getShort("lvl");
aint[i][0] = j;
aint[i][1] = k;
}
return aint;
} else {
return EMPTY_INT2_ARRAY;
}
}
public static boolean renderCustomEffect(RenderItem renderItem, ItemStack itemStack, IBakedModel model) {
if (enchantmentProperties == null) {
return false;
} else if (itemStack == null) {
return false;
} else {
int[][] aint = getEnchantmentIdLevels(itemStack);
if (aint.length <= 0) {
return false;
} else {
Set set = null;
boolean flag = false;
TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager();
for (int i = 0; i < aint.length; ++i) {
int j = aint[i][0];
if (j >= 0 && j < enchantmentProperties.length) {
CustomItemProperties[] acustomitemproperties = enchantmentProperties[j];
if (acustomitemproperties != null) {
for (int k = 0; k < acustomitemproperties.length; ++k) {
CustomItemProperties customitemproperties = acustomitemproperties[k];
if (set == null) {
set = new HashSet();
}
if (set.add(Integer.valueOf(j))
&& matchesProperties(customitemproperties, itemStack, aint)
&& customitemproperties.textureLocation != null) {
texturemanager.bindTexture(customitemproperties.textureLocation);
float f = customitemproperties.getTextureWidth(texturemanager);
if (!flag) {
flag = true;
GlStateManager.depthMask(false);
GlStateManager.depthFunc(514);
GlStateManager.disableLighting();
GlStateManager.matrixMode(5890);
}
Blender.setupBlend(customitemproperties.blend, 1.0F);
GlStateManager.pushMatrix();
GlStateManager.scale(f / 2.0F, f / 2.0F, f / 2.0F);
float f1 = customitemproperties.speed * (float) (Minecraft.getSystemTime() % 3000L)
/ 3000.0F / 8.0F;
GlStateManager.translate(f1, 0.0F, 0.0F);
GlStateManager.rotate(customitemproperties.rotation, 0.0F, 0.0F, 1.0F);
renderItem.renderModel(model, -1);
GlStateManager.popMatrix();
}
}
}
}
}
if (flag) {
GlStateManager.enableAlpha();
GlStateManager.enableBlend();
GlStateManager.blendFunc(770, 771);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
GlStateManager.matrixMode(5888);
GlStateManager.enableLighting();
GlStateManager.depthFunc(515);
GlStateManager.depthMask(true);
texturemanager.bindTexture(TextureMap.locationBlocksTexture);
}
return flag;
}
}
}
public static boolean renderCustomArmorEffect(EntityLivingBase entity, ItemStack itemStack, ModelBase model,
float limbSwing, float prevLimbSwing, float partialTicks, float timeLimbSwing, float yaw, float pitch,
float scale) {
if (enchantmentProperties == null) {
return false;
} else if (itemStack == null) {
return false;
} else {
int[][] aint = getEnchantmentIdLevels(itemStack);
if (aint.length <= 0) {
return false;
} else {
Set set = null;
boolean flag = false;
TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager();
for (int i = 0; i < aint.length; ++i) {
int j = aint[i][0];
if (j >= 0 && j < enchantmentProperties.length) {
CustomItemProperties[] acustomitemproperties = enchantmentProperties[j];
if (acustomitemproperties != null) {
for (int k = 0; k < acustomitemproperties.length; ++k) {
CustomItemProperties customitemproperties = acustomitemproperties[k];
if (set == null) {
set = new HashSet();
}
if (set.add(Integer.valueOf(j))
&& matchesProperties(customitemproperties, itemStack, aint)
&& customitemproperties.textureLocation != null) {
texturemanager.bindTexture(customitemproperties.textureLocation);
float f = customitemproperties.getTextureWidth(texturemanager);
if (!flag) {
flag = true;
GlStateManager.enableBlend();
GlStateManager.depthFunc(514);
GlStateManager.depthMask(false);
}
Blender.setupBlend(customitemproperties.blend, 1.0F);
GlStateManager.disableLighting();
GlStateManager.matrixMode(5890);
GlStateManager.loadIdentity();
GlStateManager.rotate(customitemproperties.rotation, 0.0F, 0.0F, 1.0F);
float f1 = f / 8.0F;
GlStateManager.scale(f1, f1 / 2.0F, f1);
float f2 = customitemproperties.speed * (float) (Minecraft.getSystemTime() % 3000L)
/ 3000.0F / 8.0F;
GlStateManager.translate(0.0F, f2, 0.0F);
GlStateManager.matrixMode(5888);
model.render(entity, limbSwing, prevLimbSwing, timeLimbSwing, yaw, pitch, scale);
}
}
}
}
}
if (flag) {
GlStateManager.enableAlpha();
GlStateManager.enableBlend();
GlStateManager.blendFunc(770, 771);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
GlStateManager.matrixMode(5890);
GlStateManager.loadIdentity();
GlStateManager.matrixMode(5888);
GlStateManager.enableLighting();
GlStateManager.depthMask(true);
GlStateManager.depthFunc(515);
GlStateManager.disableBlend();
}
return flag;
}
}
}
public static boolean isUseGlint() {
return useGlint;
}
}

View File

@ -0,0 +1,15 @@
package net.optifine;
import java.util.Comparator;
public class CustomItemsComparator implements Comparator {
public int compare(Object o1, Object o2) {
CustomItemProperties customitemproperties = (CustomItemProperties) o1;
CustomItemProperties customitemproperties1 = (CustomItemProperties) o2;
return customitemproperties.weight != customitemproperties1.weight
? customitemproperties1.weight - customitemproperties.weight
: (!Config.equals(customitemproperties.basePath, customitemproperties1.basePath)
? customitemproperties.basePath.compareTo(customitemproperties1.basePath)
: customitemproperties.name.compareTo(customitemproperties1.name));
}
}

View File

@ -0,0 +1,149 @@
package net.optifine;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.ITextureObject;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.optifine.render.Blender;
import net.optifine.util.PropertiesOrdered;
public class CustomSky {
private static CustomSkyLayer[][] worldSkyLayers = (CustomSkyLayer[][]) null;
public static void reset() {
worldSkyLayers = (CustomSkyLayer[][]) null;
}
public static void update() {
reset();
if (Config.isCustomSky()) {
worldSkyLayers = readCustomSkies();
}
}
private static CustomSkyLayer[][] readCustomSkies() {
CustomSkyLayer[][] acustomskylayer = new CustomSkyLayer[10][0];
String s = "mcpatcher/sky/world";
int i = -1;
for (int j = 0; j < acustomskylayer.length; ++j) {
String s1 = s + j + "/sky";
List list = new ArrayList();
for (int k = 1; k < 1000; ++k) {
String s2 = s1 + k + ".properties";
ResourceLocation resourcelocation = new ResourceLocation(s2);
try (InputStream inputstream = Minecraft.getMinecraft().getResourceManager()
.getResource(resourcelocation).getInputStream()) {
if (inputstream == null) {
break;
}
Properties properties = new PropertiesOrdered();
properties.load(inputstream);
inputstream.close();
Config.dbg("CustomSky properties: " + s2);
String s3 = s1 + k + ".png";
CustomSkyLayer customskylayer = new CustomSkyLayer(properties, s3);
if (customskylayer.isValid(s2)) {
ResourceLocation resourcelocation1 = new ResourceLocation(customskylayer.source);
TextureManager mgr = Minecraft.getMinecraft().getTextureManager();
mgr.bindTexture(resourcelocation1);
ITextureObject itextureobject = mgr.getTexture(resourcelocation1);
if (itextureobject == null) {
Config.warn("CustomSky: Texture not found: " + resourcelocation1);
} else {
customskylayer.textureId = itextureobject.getGlTextureId();
list.add(customskylayer);
inputstream.close();
}
}
} catch (FileNotFoundException var15) {
break;
} catch (IOException ioexception) {
ioexception.printStackTrace();
}
}
if (list.size() > 0) {
CustomSkyLayer[] acustomskylayer2 = (CustomSkyLayer[]) ((CustomSkyLayer[]) list
.toArray(new CustomSkyLayer[list.size()]));
acustomskylayer[j] = acustomskylayer2;
i = j;
}
}
if (i < 0) {
return (CustomSkyLayer[][]) null;
} else {
int l = i + 1;
CustomSkyLayer[][] acustomskylayer1 = new CustomSkyLayer[l][0];
for (int i1 = 0; i1 < acustomskylayer1.length; ++i1) {
acustomskylayer1[i1] = acustomskylayer[i1];
}
return acustomskylayer1;
}
}
public static void renderSky(World world, TextureManager re, float partialTicks) {
if (worldSkyLayers != null) {
int i = world.provider.getDimensionId();
if (i >= 0 && i < worldSkyLayers.length) {
CustomSkyLayer[] acustomskylayer = worldSkyLayers[i];
if (acustomskylayer != null) {
long j = world.getWorldTime();
int k = (int) (j % 24000L);
float f = world.getCelestialAngle(partialTicks);
float f1 = world.getRainStrength(partialTicks);
float f2 = world.getThunderStrength(partialTicks);
if (f1 > 0.0F) {
f2 /= f1;
}
for (int l = 0; l < acustomskylayer.length; ++l) {
CustomSkyLayer customskylayer = acustomskylayer[l];
if (customskylayer.isActive(world, k)) {
customskylayer.render(world, k, f, f1, f2);
}
}
float f3 = 1.0F - f1;
Blender.clearBlend(f3);
}
}
}
}
public static boolean hasSkyLayers(World world) {
if (worldSkyLayers == null) {
return false;
} else {
int i = world.provider.getDimensionId();
if (i >= 0 && i < worldSkyLayers.length) {
CustomSkyLayer[] acustomskylayer = worldSkyLayers[i];
return acustomskylayer == null ? false : acustomskylayer.length > 0;
} else {
return false;
}
}
}
}

View File

@ -0,0 +1,434 @@
package net.optifine;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;
import net.lax1dude.eaglercraft.v1_8.opengl.GlStateManager;
import net.lax1dude.eaglercraft.v1_8.opengl.WorldRenderer;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.entity.Entity;
import net.minecraft.util.BlockPos;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import net.minecraft.world.biome.BiomeGenBase;
import net.optifine.config.ConnectedParser;
import net.optifine.config.Matches;
import net.optifine.config.RangeListInt;
import net.optifine.render.Blender;
import net.optifine.util.NumUtils;
import net.optifine.util.SmoothFloat;
import net.optifine.util.TextureUtils;
public class CustomSkyLayer {
public String source = null;
private int startFadeIn = -1;
private int endFadeIn = -1;
private int startFadeOut = -1;
private int endFadeOut = -1;
private int blend = 1;
private boolean rotate = false;
private float speed = 1.0F;
private float[] axis;
private RangeListInt days;
private int daysLoop;
private boolean weatherClear;
private boolean weatherRain;
private boolean weatherThunder;
public BiomeGenBase[] biomes;
public RangeListInt heights;
private float transition;
private SmoothFloat smoothPositionBrightness;
public int textureId;
private World lastWorld;
public static final float[] DEFAULT_AXIS = new float[] { 1.0F, 0.0F, 0.0F };
private static final String WEATHER_CLEAR = "clear";
private static final String WEATHER_RAIN = "rain";
private static final String WEATHER_THUNDER = "thunder";
public CustomSkyLayer(Properties props, String defSource) {
this.axis = DEFAULT_AXIS;
this.days = null;
this.daysLoop = 8;
this.weatherClear = true;
this.weatherRain = false;
this.weatherThunder = false;
this.biomes = null;
this.heights = null;
this.transition = 1.0F;
this.smoothPositionBrightness = null;
this.textureId = -1;
this.lastWorld = null;
ConnectedParser connectedparser = new ConnectedParser("CustomSky");
this.source = props.getProperty("source", defSource);
this.startFadeIn = this.parseTime(props.getProperty("startFadeIn"));
this.endFadeIn = this.parseTime(props.getProperty("endFadeIn"));
this.startFadeOut = this.parseTime(props.getProperty("startFadeOut"));
this.endFadeOut = this.parseTime(props.getProperty("endFadeOut"));
this.blend = Blender.parseBlend(props.getProperty("blend"));
this.rotate = this.parseBoolean(props.getProperty("rotate"), true);
this.speed = this.parseFloat(props.getProperty("speed"), 1.0F);
this.axis = this.parseAxis(props.getProperty("axis"), DEFAULT_AXIS);
this.days = connectedparser.parseRangeListInt(props.getProperty("days"));
this.daysLoop = connectedparser.parseInt(props.getProperty("daysLoop"), 8);
List<String> list = this.parseWeatherList(props.getProperty("weather", "clear"));
this.weatherClear = list.contains("clear");
this.weatherRain = list.contains("rain");
this.weatherThunder = list.contains("thunder");
this.biomes = connectedparser.parseBiomes(props.getProperty("biomes"));
this.heights = connectedparser.parseRangeListInt(props.getProperty("heights"));
this.transition = this.parseFloat(props.getProperty("transition"), 1.0F);
}
private List<String> parseWeatherList(String str) {
List<String> list = Arrays.<String>asList(new String[] { "clear", "rain", "thunder" });
List<String> list1 = new ArrayList();
String[] astring = Config.tokenize(str, " ");
for (int i = 0; i < astring.length; ++i) {
String s = astring[i];
if (!list.contains(s)) {
Config.warn("Unknown weather: " + s);
} else {
list1.add(s);
}
}
return list1;
}
private int parseTime(String str) {
if (str == null) {
return -1;
} else {
String[] astring = Config.tokenize(str, ":");
if (astring.length != 2) {
Config.warn("Invalid time: " + str);
return -1;
} else {
String s = astring[0];
String s1 = astring[1];
int i = Config.parseInt(s, -1);
int j = Config.parseInt(s1, -1);
if (i >= 0 && i <= 23 && j >= 0 && j <= 59) {
i = i - 6;
if (i < 0) {
i += 24;
}
int k = i * 1000 + (int) ((double) j / 60.0D * 1000.0D);
return k;
} else {
Config.warn("Invalid time: " + str);
return -1;
}
}
}
}
private boolean parseBoolean(String str, boolean defVal) {
if (str == null) {
return defVal;
} else if (str.toLowerCase().equals("true")) {
return true;
} else if (str.toLowerCase().equals("false")) {
return false;
} else {
Config.warn("Unknown boolean: " + str);
return defVal;
}
}
private float parseFloat(String str, float defVal) {
if (str == null) {
return defVal;
} else {
float f = Config.parseFloat(str, Float.MIN_VALUE);
if (f == Float.MIN_VALUE) {
Config.warn("Invalid value: " + str);
return defVal;
} else {
return f;
}
}
}
private float[] parseAxis(String str, float[] defVal) {
if (str == null) {
return defVal;
} else {
String[] astring = Config.tokenize(str, " ");
if (astring.length != 3) {
Config.warn("Invalid axis: " + str);
return defVal;
} else {
float[] afloat = new float[3];
for (int i = 0; i < astring.length; ++i) {
afloat[i] = Config.parseFloat(astring[i], Float.MIN_VALUE);
if (afloat[i] == Float.MIN_VALUE) {
Config.warn("Invalid axis: " + str);
return defVal;
}
if (afloat[i] < -1.0F || afloat[i] > 1.0F) {
Config.warn("Invalid axis values: " + str);
return defVal;
}
}
float f2 = afloat[0];
float f = afloat[1];
float f1 = afloat[2];
float l = f2 * f2 + f * f + f1 * f1;
if (l < 1.0E-5F) {
Config.warn("Invalid axis values: " + str);
return defVal;
} else {
l = MathHelper.sqrt_float(l);
return new float[] { f1 / l, f / l, -f2 / l };
}
}
}
}
public boolean isValid(String path) {
if (this.source == null) {
Config.warn("No source texture: " + path);
return false;
} else {
this.source = TextureUtils.fixResourcePath(this.source, TextureUtils.getBasePath(path));
if (this.startFadeIn >= 0 && this.endFadeIn >= 0 && this.endFadeOut >= 0) {
int i = this.normalizeTime(this.endFadeIn - this.startFadeIn);
if (this.startFadeOut < 0) {
this.startFadeOut = this.normalizeTime(this.endFadeOut - i);
if (this.timeBetween(this.startFadeOut, this.startFadeIn, this.endFadeIn)) {
this.startFadeOut = this.endFadeIn;
}
}
int j = this.normalizeTime(this.startFadeOut - this.endFadeIn);
int k = this.normalizeTime(this.endFadeOut - this.startFadeOut);
int l = this.normalizeTime(this.startFadeIn - this.endFadeOut);
int i1 = i + j + k + l;
if (i1 != 24000) {
Config.warn("Invalid fadeIn/fadeOut times, sum is not 24h: " + i1);
return false;
} else if (this.speed < 0.0F) {
Config.warn("Invalid speed: " + this.speed);
return false;
} else if (this.daysLoop <= 0) {
Config.warn("Invalid daysLoop: " + this.daysLoop);
return false;
} else {
return true;
}
} else {
Config.warn("Invalid times, required are: startFadeIn, endFadeIn and endFadeOut.");
return false;
}
}
}
private int normalizeTime(int timeMc) {
while (timeMc >= 24000) {
timeMc -= 24000;
}
while (timeMc < 0) {
timeMc += 24000;
}
return timeMc;
}
public void render(World world, int timeOfDay, float celestialAngle, float rainStrength, float thunderStrength) {
float f = this.getPositionBrightness(world);
float f1 = this.getWeatherBrightness(rainStrength, thunderStrength);
float f2 = this.getFadeBrightness(timeOfDay);
float f3 = f * f1 * f2;
f3 = Config.limit(f3, 0.0F, 1.0F);
if (f3 >= 1.0E-4F) {
GlStateManager.bindTexture(this.textureId);
Blender.setupBlend(this.blend, f3);
GlStateManager.pushMatrix();
if (this.rotate) {
float f4 = 0.0F;
if (this.speed != (float) Math.round(this.speed)) {
long i = (world.getWorldTime() + 18000L) / 24000L;
double d0 = (double) (this.speed % 1.0F);
double d1 = (double) i * d0;
f4 = (float) (d1 % 1.0D);
}
GlStateManager.rotate(360.0F * (f4 + celestialAngle * this.speed), this.axis[0], this.axis[1],
this.axis[2]);
}
Tessellator tessellator = Tessellator.getInstance();
GlStateManager.rotate(90.0F, 1.0F, 0.0F, 0.0F);
GlStateManager.rotate(-90.0F, 0.0F, 0.0F, 1.0F);
this.renderSide(tessellator, 4);
GlStateManager.pushMatrix();
GlStateManager.rotate(90.0F, 1.0F, 0.0F, 0.0F);
this.renderSide(tessellator, 1);
GlStateManager.popMatrix();
GlStateManager.pushMatrix();
GlStateManager.rotate(-90.0F, 1.0F, 0.0F, 0.0F);
this.renderSide(tessellator, 0);
GlStateManager.popMatrix();
GlStateManager.rotate(90.0F, 0.0F, 0.0F, 1.0F);
this.renderSide(tessellator, 5);
GlStateManager.rotate(90.0F, 0.0F, 0.0F, 1.0F);
this.renderSide(tessellator, 2);
GlStateManager.rotate(90.0F, 0.0F, 0.0F, 1.0F);
this.renderSide(tessellator, 3);
GlStateManager.popMatrix();
}
}
private float getPositionBrightness(World world) {
if (this.biomes == null && this.heights == null) {
return 1.0F;
} else {
float f = this.getPositionBrightnessRaw(world);
if (this.smoothPositionBrightness == null) {
this.smoothPositionBrightness = new SmoothFloat(f, this.transition);
}
f = this.smoothPositionBrightness.getSmoothValue(f);
return f;
}
}
private float getPositionBrightnessRaw(World world) {
Entity entity = Minecraft.getMinecraft().getRenderViewEntity();
if (entity == null) {
return 0.0F;
} else {
BlockPos blockpos = entity.getPosition();
if (this.biomes != null) {
BiomeGenBase biomegenbase = world.getBiomeGenForCoords(blockpos);
if (biomegenbase == null) {
return 0.0F;
}
if (!Matches.biome(biomegenbase, this.biomes)) {
return 0.0F;
}
}
return this.heights != null && !this.heights.isInRange(blockpos.getY()) ? 0.0F : 1.0F;
}
}
private float getWeatherBrightness(float rainStrength, float thunderStrength) {
float f = 1.0F - rainStrength;
float f1 = rainStrength - thunderStrength;
float f2 = 0.0F;
if (this.weatherClear) {
f2 += f;
}
if (this.weatherRain) {
f2 += f1;
}
if (this.weatherThunder) {
f2 += thunderStrength;
}
f2 = NumUtils.limit(f2, 0.0F, 1.0F);
return f2;
}
private float getFadeBrightness(int timeOfDay) {
if (this.timeBetween(timeOfDay, this.startFadeIn, this.endFadeIn)) {
int k = this.normalizeTime(this.endFadeIn - this.startFadeIn);
int l = this.normalizeTime(timeOfDay - this.startFadeIn);
return (float) l / (float) k;
} else if (this.timeBetween(timeOfDay, this.endFadeIn, this.startFadeOut)) {
return 1.0F;
} else if (this.timeBetween(timeOfDay, this.startFadeOut, this.endFadeOut)) {
int i = this.normalizeTime(this.endFadeOut - this.startFadeOut);
int j = this.normalizeTime(timeOfDay - this.startFadeOut);
return 1.0F - (float) j / (float) i;
} else {
return 0.0F;
}
}
private void renderSide(Tessellator tess, int side) {
WorldRenderer worldrenderer = tess.getWorldRenderer();
double d0 = (double) (side % 3) / 3.0D;
double d1 = (double) (side / 3) / 2.0D;
worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX);
worldrenderer.pos(-100.0D, -100.0D, -100.0D).tex(d0, d1).endVertex();
worldrenderer.pos(-100.0D, -100.0D, 100.0D).tex(d0, d1 + 0.5D).endVertex();
worldrenderer.pos(100.0D, -100.0D, 100.0D).tex(d0 + 0.3333333333333333D, d1 + 0.5D).endVertex();
worldrenderer.pos(100.0D, -100.0D, -100.0D).tex(d0 + 0.3333333333333333D, d1).endVertex();
tess.draw();
}
public boolean isActive(World world, int timeOfDay) {
if (world != this.lastWorld) {
this.lastWorld = world;
this.smoothPositionBrightness = null;
}
if (this.timeBetween(timeOfDay, this.endFadeOut, this.startFadeIn)) {
return false;
} else {
if (this.days != null) {
long i = world.getWorldTime();
long j;
for (j = i - (long) this.startFadeIn; j < 0L; j += (long) (24000 * this.daysLoop)) {
;
}
int k = (int) (j / 24000L);
int l = k % this.daysLoop;
if (!this.days.isInRange(l)) {
return false;
}
}
return true;
}
}
private boolean timeBetween(int timeOfDay, int timeStart, int timeEnd) {
return timeStart <= timeEnd ? timeOfDay >= timeStart && timeOfDay <= timeEnd
: timeOfDay >= timeStart || timeOfDay <= timeEnd;
}
public String toString() {
return "" + this.source + ", " + this.startFadeIn + "-" + this.endFadeIn + " " + this.startFadeOut + "-"
+ this.endFadeOut;
}
}

View File

@ -0,0 +1,198 @@
package net.optifine;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.block.BlockNewLeaf;
import net.minecraft.block.BlockOldLeaf;
import net.minecraft.block.BlockPlanks;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.resources.DefaultResourcePack;
import net.minecraft.client.resources.model.IBakedModel;
import net.minecraft.client.resources.model.ModelManager;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.optifine.model.ModelUtils;
public class SmartLeaves {
private static IBakedModel modelLeavesCullAcacia = null;
private static IBakedModel modelLeavesCullBirch = null;
private static IBakedModel modelLeavesCullDarkOak = null;
private static IBakedModel modelLeavesCullJungle = null;
private static IBakedModel modelLeavesCullOak = null;
private static IBakedModel modelLeavesCullSpruce = null;
private static List generalQuadsCullAcacia = null;
private static List generalQuadsCullBirch = null;
private static List generalQuadsCullDarkOak = null;
private static List generalQuadsCullJungle = null;
private static List generalQuadsCullOak = null;
private static List generalQuadsCullSpruce = null;
private static IBakedModel modelLeavesDoubleAcacia = null;
private static IBakedModel modelLeavesDoubleBirch = null;
private static IBakedModel modelLeavesDoubleDarkOak = null;
private static IBakedModel modelLeavesDoubleJungle = null;
private static IBakedModel modelLeavesDoubleOak = null;
private static IBakedModel modelLeavesDoubleSpruce = null;
public static IBakedModel getLeavesModel(IBakedModel model, IBlockState stateIn) {
if (!Config.isTreesSmart()) {
return model;
} else {
List list = model.getGeneralQuads();
return list == generalQuadsCullAcacia ? modelLeavesDoubleAcacia
: (list == generalQuadsCullBirch ? modelLeavesDoubleBirch
: (list == generalQuadsCullDarkOak ? modelLeavesDoubleDarkOak
: (list == generalQuadsCullJungle ? modelLeavesDoubleJungle
: (list == generalQuadsCullOak ? modelLeavesDoubleOak
: (list == generalQuadsCullSpruce ? modelLeavesDoubleSpruce
: model)))));
}
}
public static boolean isSameLeaves(IBlockState state1, IBlockState state2) {
if (state1 == state2) {
return true;
} else {
Block block = state1.getBlock();
Block block1 = state2.getBlock();
return block != block1 ? false
: (block instanceof BlockOldLeaf
? ((BlockPlanks.EnumType) state1.getValue(BlockOldLeaf.VARIANT))
.equals(state2.getValue(BlockOldLeaf.VARIANT))
: (block instanceof BlockNewLeaf
? ((BlockPlanks.EnumType) state1.getValue(BlockNewLeaf.VARIANT)).equals(
state2.getValue(BlockNewLeaf.VARIANT))
: false));
}
}
public static void updateLeavesModels() {
List list = new ArrayList();
modelLeavesCullAcacia = getModelCull("acacia", list);
modelLeavesCullBirch = getModelCull("birch", list);
modelLeavesCullDarkOak = getModelCull("dark_oak", list);
modelLeavesCullJungle = getModelCull("jungle", list);
modelLeavesCullOak = getModelCull("oak", list);
modelLeavesCullSpruce = getModelCull("spruce", list);
generalQuadsCullAcacia = getGeneralQuadsSafe(modelLeavesCullAcacia);
generalQuadsCullBirch = getGeneralQuadsSafe(modelLeavesCullBirch);
generalQuadsCullDarkOak = getGeneralQuadsSafe(modelLeavesCullDarkOak);
generalQuadsCullJungle = getGeneralQuadsSafe(modelLeavesCullJungle);
generalQuadsCullOak = getGeneralQuadsSafe(modelLeavesCullOak);
generalQuadsCullSpruce = getGeneralQuadsSafe(modelLeavesCullSpruce);
modelLeavesDoubleAcacia = getModelDoubleFace(modelLeavesCullAcacia);
modelLeavesDoubleBirch = getModelDoubleFace(modelLeavesCullBirch);
modelLeavesDoubleDarkOak = getModelDoubleFace(modelLeavesCullDarkOak);
modelLeavesDoubleJungle = getModelDoubleFace(modelLeavesCullJungle);
modelLeavesDoubleOak = getModelDoubleFace(modelLeavesCullOak);
modelLeavesDoubleSpruce = getModelDoubleFace(modelLeavesCullSpruce);
if (list.size() > 0) {
Config.dbg("Enable face culling: " + Config.arrayToString(list.toArray()));
}
}
private static List getGeneralQuadsSafe(IBakedModel model) {
return model == null ? null : model.getGeneralQuads();
}
static IBakedModel getModelCull(String type, List updatedTypes) {
ModelManager modelmanager = Minecraft.getMinecraft().getModelManager();
if (modelmanager == null) {
return null;
} else {
ResourceLocation resourcelocation = new ResourceLocation("blockstates/" + type + "_leaves.json");
DefaultResourcePack res = Minecraft.getMinecraft().getDefaultResourcePack();
if (Config.getDefiningResourcePack(resourcelocation) != res) {
return null;
} else {
ResourceLocation resourcelocation1 = new ResourceLocation("models/block/" + type + "_leaves.json");
if (Config.getDefiningResourcePack(resourcelocation1) != res) {
return null;
} else {
ModelResourceLocation modelresourcelocation = new ModelResourceLocation(type + "_leaves", "normal");
IBakedModel ibakedmodel = modelmanager.getModel(modelresourcelocation);
if (ibakedmodel != null && ibakedmodel != modelmanager.getMissingModel()) {
List list = ibakedmodel.getGeneralQuads();
if (list.size() == 0) {
return ibakedmodel;
} else if (list.size() != 6) {
return null;
} else {
for (Object bakedquad0 : list) {
BakedQuad bakedquad = (BakedQuad) bakedquad0;
List list1 = ibakedmodel.getFaceQuads(bakedquad.getFace());
if (list1.size() > 0) {
return null;
}
list1.add(bakedquad);
}
list.clear();
updatedTypes.add(type + "_leaves");
return ibakedmodel;
}
} else {
return null;
}
}
}
}
}
private static IBakedModel getModelDoubleFace(IBakedModel model) {
if (model == null) {
return null;
} else if (model.getGeneralQuads().size() > 0) {
Config.warn("SmartLeaves: Model is not cube, general quads: " + model.getGeneralQuads().size() + ", model: "
+ model);
return model;
} else {
EnumFacing[] aenumfacing = EnumFacing._VALUES;
for (int i = 0; i < aenumfacing.length; ++i) {
EnumFacing enumfacing = aenumfacing[i];
List<BakedQuad> list = model.getFaceQuads(enumfacing);
if (list.size() != 1) {
Config.warn("SmartLeaves: Model is not cube, side: " + enumfacing + ", quads: " + list.size()
+ ", model: " + model);
return model;
}
}
IBakedModel ibakedmodel = ModelUtils.duplicateModel(model);
List[] alist = new List[aenumfacing.length];
for (int k = 0; k < aenumfacing.length; ++k) {
EnumFacing enumfacing1 = aenumfacing[k];
List<BakedQuad> list1 = ibakedmodel.getFaceQuads(enumfacing1);
BakedQuad bakedquad = (BakedQuad) list1.get(0);
BakedQuad bakedquad1 = new BakedQuad((int[]) bakedquad.getVertexData().clone(),
(int[]) bakedquad.getVertexDataWithNormals().clone(), bakedquad.getTintIndex(),
bakedquad.getFace(), bakedquad.getSprite());
int[] aint = bakedquad1.getVertexData();
int[] aint1 = (int[]) aint.clone();
int j = aint.length / 4;
System.arraycopy(aint, 0 * j, aint1, 3 * j, j);
System.arraycopy(aint, 1 * j, aint1, 2 * j, j);
System.arraycopy(aint, 2 * j, aint1, 1 * j, j);
System.arraycopy(aint, 3 * j, aint1, 0 * j, j);
System.arraycopy(aint1, 0, aint, 0, aint1.length);
list1.add(bakedquad1);
}
return ibakedmodel;
}
}
}

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;
}
}
}

View File

@ -0,0 +1,100 @@
package net.optifine.model;
import com.google.common.collect.ImmutableList;
import java.util.List;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.resources.model.IBakedModel;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumWorldBlockLayer;
import net.minecraft.world.IBlockAccess;
import net.optifine.BetterGrass;
import net.optifine.Config;
import net.optifine.ConnectedTextures;
import net.optifine.SmartLeaves;
import net.optifine.render.RenderEnv;
public class BlockModelCustomizer {
private static final List<BakedQuad> NO_QUADS = ImmutableList.<BakedQuad>of();
public static IBakedModel getRenderModel(IBakedModel modelIn, IBlockState stateIn, RenderEnv renderEnv) {
if (renderEnv.isSmartLeaves()) {
modelIn = SmartLeaves.getLeavesModel(modelIn, stateIn);
}
return modelIn;
}
public static List<BakedQuad> getRenderQuads(List<BakedQuad> quads, IBlockAccess worldIn, IBlockState stateIn,
BlockPos posIn, EnumFacing enumfacing, EnumWorldBlockLayer layer, long rand, RenderEnv renderEnv) {
if (enumfacing != null) {
if (renderEnv.isSmartLeaves()
&& SmartLeaves.isSameLeaves(worldIn.getBlockState(posIn.offset(enumfacing)), stateIn)) {
return NO_QUADS;
}
if (!renderEnv.isBreakingAnimation(quads) && Config.isBetterGrass()) {
quads = BetterGrass.getFaceQuads(worldIn, stateIn, posIn, enumfacing, quads);
}
}
List<BakedQuad> list = renderEnv.getListQuadsCustomizer();
list.clear();
for (int i = 0; i < quads.size(); ++i) {
BakedQuad bakedquad = (BakedQuad) quads.get(i);
BakedQuad[] abakedquad = getRenderQuads(bakedquad, worldIn, stateIn, posIn, enumfacing, rand, renderEnv);
if (i == 0 && quads.size() == 1 && abakedquad.length == 1 && abakedquad[0] == bakedquad
/* && bakedquad.getQuadEmissive() == null */) {
return quads;
}
for (int j = 0; j < abakedquad.length; ++j) {
BakedQuad bakedquad1 = abakedquad[j];
list.add(bakedquad1);
// if (bakedquad1.getQuadEmissive() != null) {
// renderEnv.getListQuadsOverlay(getEmissiveLayer(layer)).addQuad(bakedquad1.getQuadEmissive(),
// stateIn);
// renderEnv.setOverlaysRendered(true);
// }
}
}
return list;
}
private static EnumWorldBlockLayer getEmissiveLayer(EnumWorldBlockLayer layer) {
return layer != null && layer != EnumWorldBlockLayer.SOLID ? layer : EnumWorldBlockLayer.CUTOUT_MIPPED;
}
private static BakedQuad[] getRenderQuads(BakedQuad quad, IBlockAccess worldIn, IBlockState stateIn, BlockPos posIn,
EnumFacing enumfacing, long rand, RenderEnv renderEnv) {
if (renderEnv.isBreakingAnimation(quad)) {
return renderEnv.getArrayQuadsCtm(quad);
} else {
// BakedQuad bakedquad = quad;
if (Config.isConnectedTextures()) {
BakedQuad[] abakedquad = ConnectedTextures.getConnectedTexture(worldIn, stateIn, posIn, quad,
renderEnv);
if (abakedquad.length != 1 || abakedquad[0] != quad) {
return abakedquad;
}
}
// if (Config.isNaturalTextures()) {
// quad = NaturalTextures.getNaturalTexture(posIn, quad);
//
// if (quad != bakedquad) {
// return renderEnv.getArrayQuadsCtm(quad);
// }
// }
return renderEnv.getArrayQuadsCtm(quad);
}
}
}

View File

@ -0,0 +1,173 @@
package net.optifine.model;
import java.util.ArrayList;
import java.util.List;
import net.lax1dude.eaglercraft.v1_8.minecraft.EaglerTextureAtlasSprite;
import net.lax1dude.eaglercraft.v1_8.vector.Vector3f;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.block.model.BlockFaceUV;
import net.minecraft.client.renderer.block.model.BlockPartFace;
import net.minecraft.client.renderer.block.model.BlockPartRotation;
import net.minecraft.client.renderer.block.model.BreakingFour;
import net.minecraft.client.renderer.block.model.FaceBakery;
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.resources.model.IBakedModel;
import net.minecraft.client.resources.model.ModelManager;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.client.resources.model.ModelRotation;
import net.minecraft.client.resources.model.SimpleBakedModel;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
public class BlockModelUtils {
private static final float VERTEX_COORD_ACCURACY = 1.0E-6F;
public static IBakedModel makeModelCube(String spriteName, int tintIndex) {
EaglerTextureAtlasSprite textureatlassprite = Minecraft.getMinecraft().getTextureMapBlocks()
.getAtlasSprite(spriteName);
return makeModelCube(textureatlassprite, tintIndex);
}
public static IBakedModel makeModelCube(EaglerTextureAtlasSprite sprite, int tintIndex) {
List list = new ArrayList();
EnumFacing[] aenumfacing = EnumFacing._VALUES;
List<List<BakedQuad>> list1 = new ArrayList();
for (int i = 0; i < aenumfacing.length; ++i) {
EnumFacing enumfacing = aenumfacing[i];
List list2 = new ArrayList();
list2.add(makeBakedQuad(enumfacing, sprite, tintIndex));
list1.add(list2);
}
IBakedModel ibakedmodel = new SimpleBakedModel(list, list1, true, true, sprite, ItemCameraTransforms.DEFAULT);
return ibakedmodel;
}
public static IBakedModel joinModelsCube(IBakedModel modelBase, IBakedModel modelAdd) {
List<BakedQuad> list = new ArrayList();
list.addAll(modelBase.getGeneralQuads());
list.addAll(modelAdd.getGeneralQuads());
EnumFacing[] aenumfacing = EnumFacing._VALUES;
List list1 = new ArrayList();
for (int i = 0; i < aenumfacing.length; ++i) {
EnumFacing enumfacing = aenumfacing[i];
List list2 = new ArrayList();
list2.addAll(modelBase.getFaceQuads(enumfacing));
list2.addAll(modelAdd.getFaceQuads(enumfacing));
list1.add(list2);
}
boolean flag = modelBase.isAmbientOcclusion();
boolean flag1 = modelBase.isBuiltInRenderer();
EaglerTextureAtlasSprite textureatlassprite = modelBase.getParticleTexture();
ItemCameraTransforms itemcameratransforms = modelBase.getItemCameraTransforms();
IBakedModel ibakedmodel = new SimpleBakedModel(list, list1, flag, flag1, textureatlassprite,
itemcameratransforms);
return ibakedmodel;
}
public static BakedQuad makeBakedQuad(EnumFacing facing, EaglerTextureAtlasSprite sprite, int tintIndex) {
Vector3f vector3f = new Vector3f(0.0F, 0.0F, 0.0F);
Vector3f vector3f1 = new Vector3f(16.0F, 16.0F, 16.0F);
BlockFaceUV blockfaceuv = new BlockFaceUV(new float[] { 0.0F, 0.0F, 16.0F, 16.0F }, 0);
BlockPartFace blockpartface = new BlockPartFace(facing, tintIndex, "#" + facing.getName(), blockfaceuv);
ModelRotation modelrotation = ModelRotation.X0_Y0;
BlockPartRotation blockpartrotation = null;
boolean flag = false;
boolean flag1 = true;
FaceBakery facebakery = new FaceBakery();
BakedQuad bakedquad = facebakery.makeBakedQuad(vector3f, vector3f1, blockpartface, sprite, facing,
modelrotation, blockpartrotation, flag, flag1);
return bakedquad;
}
public static IBakedModel makeModel(String modelName, String spriteOldName, String spriteNewName) {
TextureMap texturemap = Minecraft.getMinecraft().getTextureMapBlocks();
EaglerTextureAtlasSprite textureatlassprite = texturemap.getAtlasSprite(spriteOldName); // getSpriteSafe
EaglerTextureAtlasSprite textureatlassprite1 = texturemap.getAtlasSprite(spriteNewName);
return makeModel(modelName, textureatlassprite, textureatlassprite1);
}
public static IBakedModel makeModel(String modelName, EaglerTextureAtlasSprite spriteOld,
EaglerTextureAtlasSprite spriteNew) {
if (spriteOld != null && spriteNew != null) {
ModelManager modelmanager = Minecraft.getMinecraft().getModelManager();
if (modelmanager == null) {
return null;
} else {
ModelResourceLocation modelresourcelocation = new ModelResourceLocation(modelName, "normal");
IBakedModel ibakedmodel = modelmanager.getModel(modelresourcelocation);
if (ibakedmodel != null && ibakedmodel != modelmanager.getMissingModel()) {
IBakedModel ibakedmodel1 = ModelUtils.duplicateModel(ibakedmodel);
EnumFacing[] aenumfacing = EnumFacing._VALUES;
for (int i = 0; i < aenumfacing.length; ++i) {
EnumFacing enumfacing = aenumfacing[i];
List<BakedQuad> list = ibakedmodel1.getFaceQuads(enumfacing);
replaceTexture(list, spriteOld, spriteNew);
}
List<BakedQuad> list1 = ibakedmodel1.getGeneralQuads();
replaceTexture(list1, spriteOld, spriteNew);
return ibakedmodel1;
} else {
return null;
}
}
} else {
return null;
}
}
private static void replaceTexture(List<BakedQuad> quads, EaglerTextureAtlasSprite spriteOld,
EaglerTextureAtlasSprite spriteNew) {
List<BakedQuad> list = new ArrayList();
for (BakedQuad bakedquad : quads) {
if (bakedquad.getSprite() == spriteOld) {
bakedquad = new BreakingFour(bakedquad, spriteNew);
}
list.add(bakedquad);
}
quads.clear();
quads.addAll(list);
}
public static void snapVertexPosition(Vector3f pos) {
pos.setX(snapVertexCoord(pos.getX()));
pos.setY(snapVertexCoord(pos.getY()));
pos.setZ(snapVertexCoord(pos.getZ()));
}
private static float snapVertexCoord(float x) {
return x > -1.0E-6F && x < 1.0E-6F ? 0.0F : (x > 0.999999F && x < 1.000001F ? 1.0F : x);
}
public static AxisAlignedBB getOffsetBoundingBox(AxisAlignedBB aabb, Block.EnumOffsetType offsetType,
BlockPos pos) {
int i = pos.getX();
int j = pos.getZ();
long k = (long) (i * 3129871) ^ (long) j * 116129781L;
k = k * k * 42317861L + k * 11L;
double d0 = ((double) ((float) (k >> 16 & 15L) / 15.0F) - 0.5D) * 0.5D;
double d1 = ((double) ((float) (k >> 24 & 15L) / 15.0F) - 0.5D) * 0.5D;
double d2 = 0.0D;
if (offsetType == Block.EnumOffsetType.XYZ) {
d2 = ((double) ((float) (k >> 20 & 15L) / 15.0F) - 1.0D) * 0.2D;
}
return aabb.offset(d0, d2, d1);
}
}

View File

@ -0,0 +1,44 @@
package net.optifine.model;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.init.Blocks;
public class ListQuadsOverlay {
private List<BakedQuad> listQuads = new ArrayList();
private List<IBlockState> listBlockStates = new ArrayList();
private List<BakedQuad> listQuadsSingle = Arrays.<BakedQuad>asList(new BakedQuad[1]);
public void addQuad(BakedQuad quad, IBlockState blockState) {
if (quad != null) {
this.listQuads.add(quad);
this.listBlockStates.add(blockState);
}
}
public int size() {
return this.listQuads.size();
}
public BakedQuad getQuad(int index) {
return (BakedQuad) this.listQuads.get(index);
}
public IBlockState getBlockState(int index) {
return index >= 0 && index < this.listBlockStates.size() ? (IBlockState) this.listBlockStates.get(index)
: Blocks.air.getDefaultState();
}
public List<BakedQuad> getListQuadsSingle(BakedQuad quad) {
this.listQuadsSingle.set(0, quad);
return this.listQuadsSingle;
}
public void clear() {
this.listQuads.clear();
this.listBlockStates.clear();
}
}

View File

@ -0,0 +1,94 @@
package net.optifine.model;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.resources.model.IBakedModel;
import net.minecraft.client.resources.model.SimpleBakedModel;
import net.minecraft.util.EnumFacing;
public class ModelUtils {
public static void dbgModel(IBakedModel model) {
if (model != null) {
// Config.dbg("Model: " + model + ", ao: " + model.isAmbientOcclusion() + ",
// gui3d: " + model.isGui3d() + ", builtIn: " + model.isBuiltInRenderer() + ",
// particle: " + model.getParticleTexture());
EnumFacing[] aenumfacing = EnumFacing._VALUES;
for (int i = 0; i < aenumfacing.length; ++i) {
EnumFacing enumfacing = aenumfacing[i];
List list = model.getFaceQuads(enumfacing);
dbgQuads(enumfacing.getName(), list, " ");
}
List list1 = model.getGeneralQuads();
dbgQuads("General", list1, " ");
}
}
private static void dbgQuads(String name, List quads, String prefix) {
for (Object bakedquad0 : quads) {
BakedQuad bakedQuad = (BakedQuad) bakedquad0;
dbgQuad(name, bakedQuad, prefix);
}
}
public static void dbgQuad(String name, BakedQuad quad, String prefix) {
// Config.dbg(prefix + "Quad: " + quad.getClass().getName() + ", type: " + name
// + ", face: " + quad.getFace() + ", tint: " + quad.getTintIndex() + ", sprite:
// " + quad.getSprite());
dbgVertexData(quad.getVertexData(), " " + prefix);
}
public static void dbgVertexData(int[] vd, String prefix) {
int i = vd.length / 4;
// Config.dbg(prefix + "Length: " + vd.length + ", step: " + i);
for (int j = 0; j < 4; ++j) {
int k = j * i;
float f = Float.intBitsToFloat(vd[k + 0]);
float f1 = Float.intBitsToFloat(vd[k + 1]);
float f2 = Float.intBitsToFloat(vd[k + 2]);
int l = vd[k + 3];
float f3 = Float.intBitsToFloat(vd[k + 4]);
float f4 = Float.intBitsToFloat(vd[k + 5]);
// Config.dbg(prefix + j + " xyz: " + f + "," + f1 + "," + f2 + " col: " + l + "
// u,v: " + f3 + "," + f4);
}
}
public static IBakedModel duplicateModel(IBakedModel model) {
List list = duplicateQuadList(model.getGeneralQuads());
EnumFacing[] aenumfacing = EnumFacing._VALUES;
List list1 = new ArrayList();
for (int i = 0; i < aenumfacing.length; ++i) {
EnumFacing enumfacing = aenumfacing[i];
List list2 = model.getFaceQuads(enumfacing);
List list3 = duplicateQuadList(list2);
list1.add(list3);
}
SimpleBakedModel simplebakedmodel = new SimpleBakedModel(list, list1, model.isAmbientOcclusion(),
model.isGui3d(), model.getParticleTexture(), model.getItemCameraTransforms());
return simplebakedmodel;
}
public static List duplicateQuadList(List lists) {
List list = new ArrayList();
for (Object e : lists) {
BakedQuad bakedquad = (BakedQuad) e;
BakedQuad bakedquad1 = duplicateQuad(bakedquad);
list.add(bakedquad1);
}
return list;
}
public static BakedQuad duplicateQuad(BakedQuad quad) {
BakedQuad bakedquad = new BakedQuad((int[]) quad.getVertexData().clone(),
(int[]) quad.getVertexDataWithNormals().clone(), quad.getTintIndex(), quad.getFace(), quad.getSprite());
return bakedquad;
}
}

View File

@ -0,0 +1,158 @@
package net.optifine.model;
import net.minecraft.util.EnumFacing;
public class QuadBounds {
private float minX = Float.MAX_VALUE;
private float minY = Float.MAX_VALUE;
private float minZ = Float.MAX_VALUE;
private float maxX = -3.4028235E38F;
private float maxY = -3.4028235E38F;
private float maxZ = -3.4028235E38F;
public QuadBounds(int[] vertexData) {
int i = vertexData.length / 4;
for (int j = 0; j < 4; ++j) {
int k = j * i;
float f = Float.intBitsToFloat(vertexData[k + 0]);
float f1 = Float.intBitsToFloat(vertexData[k + 1]);
float f2 = Float.intBitsToFloat(vertexData[k + 2]);
if (this.minX > f) {
this.minX = f;
}
if (this.minY > f1) {
this.minY = f1;
}
if (this.minZ > f2) {
this.minZ = f2;
}
if (this.maxX < f) {
this.maxX = f;
}
if (this.maxY < f1) {
this.maxY = f1;
}
if (this.maxZ < f2) {
this.maxZ = f2;
}
}
}
public float getMinX() {
return this.minX;
}
public float getMinY() {
return this.minY;
}
public float getMinZ() {
return this.minZ;
}
public float getMaxX() {
return this.maxX;
}
public float getMaxY() {
return this.maxY;
}
public float getMaxZ() {
return this.maxZ;
}
public boolean isFaceQuad(EnumFacing face) {
float f;
float f1;
float f2;
switch (face) {
case DOWN:
f = this.getMinY();
f1 = this.getMaxY();
f2 = 0.0F;
break;
case UP:
f = this.getMinY();
f1 = this.getMaxY();
f2 = 1.0F;
break;
case NORTH:
f = this.getMinZ();
f1 = this.getMaxZ();
f2 = 0.0F;
break;
case SOUTH:
f = this.getMinZ();
f1 = this.getMaxZ();
f2 = 1.0F;
break;
case WEST:
f = this.getMinX();
f1 = this.getMaxX();
f2 = 0.0F;
break;
case EAST:
f = this.getMinX();
f1 = this.getMaxX();
f2 = 1.0F;
break;
default:
return false;
}
return f == f2 && f1 == f2;
}
public boolean isFullQuad(EnumFacing face) {
float f;
float f1;
float f2;
float f3;
switch (face) {
case DOWN:
case UP:
f = this.getMinX();
f1 = this.getMaxX();
f2 = this.getMinZ();
f3 = this.getMaxZ();
break;
case NORTH:
case SOUTH:
f = this.getMinX();
f1 = this.getMaxX();
f2 = this.getMinY();
f3 = this.getMaxY();
break;
case WEST:
case EAST:
f = this.getMinY();
f1 = this.getMaxY();
f2 = this.getMinZ();
f3 = this.getMaxZ();
break;
default:
return false;
}
return f == 0.0F && f1 == 1.0F && f2 == 0.0F && f3 == 1.0F;
}
}

View File

@ -0,0 +1,122 @@
package net.optifine.render;
import net.lax1dude.eaglercraft.v1_8.opengl.GlStateManager;
import net.optifine.Config;
public class Blender {
public static final int BLEND_ALPHA = 0;
public static final int BLEND_ADD = 1;
public static final int BLEND_SUBSTRACT = 2;
public static final int BLEND_MULTIPLY = 3;
public static final int BLEND_DODGE = 4;
public static final int BLEND_BURN = 5;
public static final int BLEND_SCREEN = 6;
public static final int BLEND_OVERLAY = 7;
public static final int BLEND_REPLACE = 8;
public static final int BLEND_DEFAULT = 1;
public static int parseBlend(String str) {
if (str == null) {
return 1;
} else {
str = str.toLowerCase().trim();
if (str.equals("alpha")) {
return 0;
} else if (str.equals("add")) {
return 1;
} else if (str.equals("subtract")) {
return 2;
} else if (str.equals("multiply")) {
return 3;
} else if (str.equals("dodge")) {
return 4;
} else if (str.equals("burn")) {
return 5;
} else if (str.equals("screen")) {
return 6;
} else if (str.equals("overlay")) {
return 7;
} else if (str.equals("replace")) {
return 8;
} else {
Config.warn("Unknown blend: " + str);
return 1;
}
}
}
public static void setupBlend(int blend, float brightness) {
switch (blend) {
case 0:
GlStateManager.disableAlpha();
GlStateManager.enableBlend();
GlStateManager.blendFunc(770, 771);
GlStateManager.color(1.0F, 1.0F, 1.0F, brightness);
break;
case 1:
GlStateManager.disableAlpha();
GlStateManager.enableBlend();
GlStateManager.blendFunc(770, 1);
GlStateManager.color(1.0F, 1.0F, 1.0F, brightness);
break;
case 2:
GlStateManager.disableAlpha();
GlStateManager.enableBlend();
GlStateManager.blendFunc(775, 0);
GlStateManager.color(brightness, brightness, brightness, 1.0F);
break;
case 3:
GlStateManager.disableAlpha();
GlStateManager.enableBlend();
GlStateManager.blendFunc(774, 771);
GlStateManager.color(brightness, brightness, brightness, brightness);
break;
case 4:
GlStateManager.disableAlpha();
GlStateManager.enableBlend();
GlStateManager.blendFunc(1, 1);
GlStateManager.color(brightness, brightness, brightness, 1.0F);
break;
case 5:
GlStateManager.disableAlpha();
GlStateManager.enableBlend();
GlStateManager.blendFunc(0, 769);
GlStateManager.color(brightness, brightness, brightness, 1.0F);
break;
case 6:
GlStateManager.disableAlpha();
GlStateManager.enableBlend();
GlStateManager.blendFunc(1, 769);
GlStateManager.color(brightness, brightness, brightness, 1.0F);
break;
case 7:
GlStateManager.disableAlpha();
GlStateManager.enableBlend();
GlStateManager.blendFunc(774, 768);
GlStateManager.color(brightness, brightness, brightness, 1.0F);
break;
case 8:
GlStateManager.enableAlpha();
GlStateManager.disableBlend();
GlStateManager.color(1.0F, 1.0F, 1.0F, brightness);
}
GlStateManager.enableTexture2D();
}
public static void clearBlend(float rainBrightness) {
GlStateManager.disableAlpha();
GlStateManager.enableBlend();
GlStateManager.blendFunc(770, 1);
GlStateManager.color(1.0F, 1.0F, 1.0F, rainBrightness);
}
}

View File

@ -0,0 +1,265 @@
package net.optifine.render;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.block.BlockLeaves;
import net.minecraft.block.state.BlockStateBase;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.BlockModelRenderer;
import net.minecraft.client.renderer.RegionRenderCacheBuilder;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.block.model.BreakingFour;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumWorldBlockLayer;
import net.optifine.Config;
import net.optifine.model.ListQuadsOverlay;
public class RenderEnv {
private IBlockState blockState;
private BlockPos blockPos;
private int blockId = -1;
private int metadata = -1;
private int breakingAnimation = -1;
private int smartLeaves = -1;
private float[] quadBounds = new float[EnumFacing._VALUES.length * 2];
private BitSet boundsFlags = new BitSet(3);
private BlockModelRenderer.AmbientOcclusionFace aoFace = new BlockModelRenderer.AmbientOcclusionFace();
private BlockPos colorizerBlockPosM = null;
private boolean[] borderFlags = null;
private boolean[] borderFlags2 = null;
private boolean[] borderFlags3 = null;
private EnumFacing[] borderDirections = null;
private List<BakedQuad> listQuadsCustomizer = new ArrayList();
private List<BakedQuad> listQuadsCtmMultipass = new ArrayList();
private BakedQuad[] arrayQuadsCtm1 = new BakedQuad[1];
private BakedQuad[] arrayQuadsCtm2 = new BakedQuad[2];
private BakedQuad[] arrayQuadsCtm3 = new BakedQuad[3];
private BakedQuad[] arrayQuadsCtm4 = new BakedQuad[4];
private RegionRenderCacheBuilder regionRenderCacheBuilder = null;
private ListQuadsOverlay[] listsQuadsOverlay = new ListQuadsOverlay[EnumWorldBlockLayer.values().length];
private boolean overlaysRendered = false;
private static final int UNKNOWN = -1;
private static final int FALSE = 0;
private static final int TRUE = 1;
public RenderEnv(IBlockState blockState, BlockPos blockPos) {
this.blockState = blockState;
this.blockPos = blockPos;
}
public void reset(IBlockState blockStateIn, BlockPos blockPosIn) {
if (this.blockState != blockStateIn || this.blockPos != blockPosIn) {
this.blockState = blockStateIn;
this.blockPos = blockPosIn;
this.blockId = -1;
this.metadata = -1;
this.breakingAnimation = -1;
this.smartLeaves = -1;
this.boundsFlags.clear();
}
}
public int getBlockId() {
if (this.blockId < 0) {
if (this.blockState instanceof BlockStateBase) {
BlockStateBase blockstatebase = (BlockStateBase) this.blockState;
this.blockId = blockstatebase.getBlockId();
} else {
this.blockId = Block.getIdFromBlock(this.blockState.getBlock());
}
}
return this.blockId;
}
public int getMetadata() {
if (this.metadata < 0) {
if (this.blockState instanceof BlockStateBase) {
BlockStateBase blockstatebase = (BlockStateBase) this.blockState;
this.metadata = blockstatebase.getMetadata();
} else {
this.metadata = this.blockState.getBlock().getMetaFromState(this.blockState);
}
}
return this.metadata;
}
public float[] getQuadBounds() {
return this.quadBounds;
}
public BitSet getBoundsFlags() {
return this.boundsFlags;
}
public BlockModelRenderer.AmbientOcclusionFace getAoFace() {
return this.aoFace;
}
public boolean isBreakingAnimation(List listQuads) {
if (this.breakingAnimation == -1 && listQuads.size() > 0) {
if (listQuads.get(0) instanceof BreakingFour) {
this.breakingAnimation = 1;
} else {
this.breakingAnimation = 0;
}
}
return this.breakingAnimation == 1;
}
public boolean isBreakingAnimation(BakedQuad quad) {
if (this.breakingAnimation < 0) {
if (quad instanceof BreakingFour) {
this.breakingAnimation = 1;
} else {
this.breakingAnimation = 0;
}
}
return this.breakingAnimation == 1;
}
public boolean isBreakingAnimation() {
return this.breakingAnimation == 1;
}
public IBlockState getBlockState() {
return this.blockState;
}
public BlockPos getColorizerBlockPosM() {
if (this.colorizerBlockPosM == null) {
this.colorizerBlockPosM = new BlockPos(0, 0, 0);
}
return this.colorizerBlockPosM;
}
public boolean[] getBorderFlags() {
if (this.borderFlags == null) {
this.borderFlags = new boolean[4];
}
return this.borderFlags;
}
public boolean[] getBorderFlags2() {
if (this.borderFlags2 == null) {
this.borderFlags2 = new boolean[4];
}
return this.borderFlags2;
}
public boolean[] getBorderFlags3() {
if (this.borderFlags3 == null) {
this.borderFlags3 = new boolean[4];
}
return this.borderFlags3;
}
public EnumFacing[] getBorderDirections() {
if (this.borderDirections == null) {
this.borderDirections = new EnumFacing[4];
}
return this.borderDirections;
}
public EnumFacing[] getBorderDirections(EnumFacing dir0, EnumFacing dir1, EnumFacing dir2, EnumFacing dir3) {
EnumFacing[] aenumfacing = this.getBorderDirections();
aenumfacing[0] = dir0;
aenumfacing[1] = dir1;
aenumfacing[2] = dir2;
aenumfacing[3] = dir3;
return aenumfacing;
}
public boolean isSmartLeaves() {
if (this.smartLeaves == -1) {
if (Config.isTreesSmart() && this.blockState.getBlock() instanceof BlockLeaves) {
this.smartLeaves = 1;
} else {
this.smartLeaves = 0;
}
}
return this.smartLeaves == 1;
}
public List<BakedQuad> getListQuadsCustomizer() {
return this.listQuadsCustomizer;
}
public BakedQuad[] getArrayQuadsCtm(BakedQuad quad) {
this.arrayQuadsCtm1[0] = quad;
return this.arrayQuadsCtm1;
}
public BakedQuad[] getArrayQuadsCtm(BakedQuad quad0, BakedQuad quad1) {
this.arrayQuadsCtm2[0] = quad0;
this.arrayQuadsCtm2[1] = quad1;
return this.arrayQuadsCtm2;
}
public BakedQuad[] getArrayQuadsCtm(BakedQuad quad0, BakedQuad quad1, BakedQuad quad2) {
this.arrayQuadsCtm3[0] = quad0;
this.arrayQuadsCtm3[1] = quad1;
this.arrayQuadsCtm3[2] = quad2;
return this.arrayQuadsCtm3;
}
public BakedQuad[] getArrayQuadsCtm(BakedQuad quad0, BakedQuad quad1, BakedQuad quad2, BakedQuad quad3) {
this.arrayQuadsCtm4[0] = quad0;
this.arrayQuadsCtm4[1] = quad1;
this.arrayQuadsCtm4[2] = quad2;
this.arrayQuadsCtm4[3] = quad3;
return this.arrayQuadsCtm4;
}
public List<BakedQuad> getListQuadsCtmMultipass(BakedQuad[] quads) {
this.listQuadsCtmMultipass.clear();
if (quads != null) {
for (int i = 0; i < quads.length; ++i) {
BakedQuad bakedquad = quads[i];
this.listQuadsCtmMultipass.add(bakedquad);
}
}
return this.listQuadsCtmMultipass;
}
public RegionRenderCacheBuilder getRegionRenderCacheBuilder() {
return this.regionRenderCacheBuilder;
}
public void setRegionRenderCacheBuilder(RegionRenderCacheBuilder regionRenderCacheBuilder) {
this.regionRenderCacheBuilder = regionRenderCacheBuilder;
}
public ListQuadsOverlay getListQuadsOverlay(EnumWorldBlockLayer layer) {
ListQuadsOverlay listquadsoverlay = this.listsQuadsOverlay[layer.ordinal()];
if (listquadsoverlay == null) {
listquadsoverlay = new ListQuadsOverlay();
this.listsQuadsOverlay[layer.ordinal()] = listquadsoverlay;
}
return listquadsoverlay;
}
public boolean isOverlaysRendered() {
return this.overlaysRendered;
}
public void setOverlaysRendered(boolean overlaysRendered) {
this.overlaysRendered = overlaysRendered;
}
}

View 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;
}
}

View 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);
// }
// }
}

View 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;
}
}

View 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());
}
}

View 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;
}
}

View 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;
}
}
}

View 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;
}
}
}

View 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();
}
}
}

View 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();
}
}
}