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