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

@ -3,6 +3,7 @@ package net.lax1dude.eaglercraft.v1_8.minecraft;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
@ -19,6 +20,7 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import net.lax1dude.eaglercraft.v1_8.ArrayUtils;
import net.lax1dude.eaglercraft.v1_8.EagRuntime;
import net.lax1dude.eaglercraft.v1_8.EaglerInputStream;
import net.lax1dude.eaglercraft.v1_8.crypto.SHA1Digest;
import net.lax1dude.eaglercraft.v1_8.internal.PlatformRuntime;
@ -28,7 +30,7 @@ import net.lax1dude.eaglercraft.v1_8.log4j.Logger;
import net.minecraft.client.resources.AbstractResourcePack;
/**
* Copyright (c) 2024 lax1dude. All Rights Reserved.
* Copyright (c) 2024-2025 lax1dude. All Rights Reserved.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
@ -70,6 +72,80 @@ public class EaglerFolderResourcePack extends AbstractResourcePack {
this.prefix = prefix;
this.domains = domains;
this.timestamp = timestamp;
this.resourceIndex = new ResourceIndex() {
@Override
protected Collection<String> getPropertiesFiles0() {
VFile2 file = new VFile2(prefix, resourcePackFile, "assets/minecraft/optifine/_property_files_index.json");
String str = file.getAllChars();
Collection<String> propertyFiles = null;
if(str != null) {
propertyFiles = loadPropertyFileList(str);
if(propertyFiles != null) {
return propertyFiles;
}
}
VFile2 mcDir = new VFile2(prefix, resourcePackFile, "assets/minecraft");
int pfxLen = mcDir.getPath().length() + 1;
List<String> philes = mcDir.listFilenames(true);
propertyFiles = new ArrayList<>();
JSONArray arr = new JSONArray();
for(int i = 0, l = philes.size(); i < l; ++i) {
String name = philes.get(i);
if(name.length() > pfxLen && name.endsWith(".properties")) {
name = name.substring(pfxLen);
propertyFiles.add(name);
arr.put(name);
}
}
JSONObject json = new JSONObject();
json.put("propertyFiles", arr);
file.setAllChars(json.toString());
return propertyFiles;
}
@Override
protected Collection<String> getCITPotionsFiles0() {
VFile2 file = new VFile2(prefix, resourcePackFile, "assets/minecraft/mcpatcher/cit/potion/_potions_files_index.json");
String str = file.getAllChars();
Collection<String> propertyFiles = null;
if(str != null) {
propertyFiles = loadPotionsFileList(str);
if(propertyFiles != null) {
return propertyFiles;
}
}
VFile2 mcDir = new VFile2(prefix, resourcePackFile, "assets/minecraft/mcpatcher/cit/potion");
int pfxLen = mcDir.getPath().length() - 20;
List<String> philes = mcDir.listFilenames(true);
propertyFiles = new ArrayList<>();
JSONArray arr = new JSONArray();
for(int i = 0, l = philes.size(); i < l; ++i) {
String name = philes.get(i);
if(name.length() > pfxLen && name.endsWith(".png")) {
name = name.substring(pfxLen);
propertyFiles.add(name);
arr.put(name);
}
}
mcDir = new VFile2(prefix, resourcePackFile, "assets/minecraft/optifine/cit/potion");
pfxLen = mcDir.getPath().length() - 19;
philes = mcDir.listFilenames(true);
for(int i = 0, l = philes.size(); i < l; ++i) {
String name = philes.get(i);
if(name.length() > pfxLen && name.endsWith(".png")) {
name = name.substring(pfxLen);
propertyFiles.add(name);
arr.put(name);
}
}
JSONObject json = new JSONObject();
json.put("potionsFiles", arr);
file.setAllChars(json.toString());
return propertyFiles;
}
};
}
@Override
@ -177,6 +253,8 @@ public class EaglerFolderResourcePack extends AbstractResourcePack {
}
Set<String> domainsList = Sets.newHashSet();
JSONArray propertyFiles = new JSONArray();
JSONArray potionsFiles = new JSONArray();
String fn;
for(int i = 0, l = fileNames.size(); i < l; ++i) {
fn = fileNames.get(i);
@ -184,7 +262,18 @@ public class EaglerFolderResourcePack extends AbstractResourcePack {
fn = fn.substring(prefixLen + 7);
int j = fn.indexOf('/');
if(j != -1) {
domainsList.add(fn.substring(0, j));
String dm = fn.substring(0, j);
domainsList.add(dm);
if("minecraft".equals(dm)) {
if(fn.endsWith(".properties")) {
propertyFiles.put(fn.substring(10));
}else if((fn.startsWith("minecraft/mcpatcher/cit/potion/")
|| fn.startsWith("minecraft/mcpatcher/cit/Potion/")) && fn.endsWith(".png")) {
potionsFiles.put(fn.substring(10));
}else if(fn.startsWith("minecraft/optifine/cit/potion/") && fn.endsWith(".png")) {
potionsFiles.put(fn.substring(10));
}
}
}
}
}
@ -234,9 +323,19 @@ public class EaglerFolderResourcePack extends AbstractResourcePack {
}
throw ex;
}
logger.info("Updating manifest...");
JSONObject json = new JSONObject();
json.put("propertyFiles", propertyFiles);
(new VFile2(prefix, folderName, "assets/minecraft/optifine/_property_files_index.json"))
.setAllChars(json.toString());
json = new JSONObject();
json.put("potionsFiles", propertyFiles);
(new VFile2(prefix, folderName, "assets/minecraft/mcpatcher/cit/potion/_potions_files_index.json"))
.setAllChars(json.toString());
VFile2 manifestFile = new VFile2(prefix, "manifest.json");
String str = manifestFile.getAllChars();
JSONArray arr = null;
@ -363,4 +462,37 @@ public class EaglerFolderResourcePack extends AbstractResourcePack {
}
}
}
public static Collection<String> loadPropertyFileList(String str) {
try {
JSONObject json = new JSONObject(str);
JSONArray arr = json.getJSONArray("propertyFiles");
int l = arr.length();
Collection<String> ret = new ArrayList<>(l);
for(int i = 0; i < l; ++i) {
ret.add(arr.getString(i));
}
return ret;
}catch(JSONException ex) {
EagRuntime.debugPrintStackTrace(ex);
return null;
}
}
public static Collection<String> loadPotionsFileList(String str) {
try {
JSONObject json = new JSONObject(str);
JSONArray arr = json.getJSONArray("potionsFiles");
int l = arr.length();
Collection<String> ret = new ArrayList<>(l);
for(int i = 0; i < l; ++i) {
ret.add(arr.getString(i));
}
return ret;
}catch(JSONException ex) {
EagRuntime.debugPrintStackTrace(ex);
return null;
}
}
}

View File

@ -8,10 +8,10 @@ import com.carrotsearch.hppc.cursors.IntCursor;
import com.google.common.collect.Lists;
import net.lax1dude.eaglercraft.v1_8.HString;
import net.lax1dude.eaglercraft.v1_8.internal.IFramebufferGL;
import net.lax1dude.eaglercraft.v1_8.log4j.LogManager;
import net.lax1dude.eaglercraft.v1_8.log4j.Logger;
import net.lax1dude.eaglercraft.v1_8.opengl.ImageData;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.TextureClock;
import net.minecraft.client.renderer.texture.TextureCompass;
import net.minecraft.client.renderer.texture.TextureUtil;
@ -21,9 +21,10 @@ import net.minecraft.crash.CrashReport;
import net.minecraft.crash.CrashReportCategory;
import net.minecraft.util.ReportedException;
import net.minecraft.util.ResourceLocation;
import net.optifine.util.CounterInt;
/**
* Copyright (c) 2022 lax1dude. All Rights Reserved.
* Copyright (c) 2022-2025 lax1dude. All Rights Reserved.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
@ -56,11 +57,14 @@ public class EaglerTextureAtlasSprite {
protected float maxV;
protected int frameCounter;
protected int tickCounter;
private int indexInMap = -1;
protected static String locationNameClock = "builtin/clock";
protected static String locationNameCompass = "builtin/compass";
protected TextureAnimationCache animationCache = null;
public String optifineBaseTextureName = null;
public EaglerTextureAtlasSprite(String spriteName) {
this.iconName = spriteName;
}
@ -101,6 +105,9 @@ public class EaglerTextureAtlasSprite {
this.maxU = atlasSpirit.maxU;
this.minV = atlasSpirit.minV;
this.maxV = atlasSpirit.maxV;
if (atlasSpirit != Minecraft.getMinecraft().getTextureMapBlocks().getMissingSprite()) {
this.indexInMap = atlasSpirit.indexInMap;
}
}
public int getOriginX() {
@ -149,7 +156,13 @@ public class EaglerTextureAtlasSprite {
return this.iconName;
}
public void updateAnimation(IFramebufferGL[] copyColorFramebuffer) {
protected static interface IAnimCopyFunction {
void updateAnimation(int mapWidth, int mapHeight, int mapLevel);
}
protected IAnimCopyFunction currentAnimUpdater = null;
public void updateAnimation() {
if(animationCache == null) {
throw new IllegalStateException("Animation cache for '" + this.iconName + "' was never baked!");
}
@ -162,7 +175,12 @@ public class EaglerTextureAtlasSprite {
this.tickCounter = 0;
int k = this.animationMetadata.getFrameIndex(this.frameCounter);
if (i != k && k >= 0 && k < this.framesTextureData.size()) {
animationCache.copyFrameLevelsToTex2D(k, this.originX, this.originY, this.width, this.height, copyColorFramebuffer);
currentAnimUpdater = (mapWidth, mapHeight, mapLevel) -> {
animationCache.copyFrameToTex2D(k, mapLevel, this.originX >> mapLevel, this.originY >> mapLevel,
this.width >> mapLevel, this.height >> mapLevel, mapWidth, mapHeight);
};
}else {
currentAnimUpdater = null;
}
} else if (this.animationMetadata.isInterpolate()) {
float f = 1.0f - (float) this.tickCounter / (float) this.animationMetadata.getFrameTimeSingle(this.frameCounter);
@ -171,8 +189,22 @@ public class EaglerTextureAtlasSprite {
: this.animationMetadata.getFrameCount();
int k = this.animationMetadata.getFrameIndex((this.frameCounter + 1) % j);
if (i != k && k >= 0 && k < this.framesTextureData.size()) {
animationCache.copyInterpolatedFrameLevelsToTex2D(i, k, f, this.originX, this.originY, this.width, this.height, copyColorFramebuffer);
currentAnimUpdater = (mapWidth, mapHeight, mapLevel) -> {
animationCache.copyInterpolatedFrameToTex2D(i, k, f, mapLevel, this.originX >> mapLevel,
this.originY >> mapLevel, this.width >> mapLevel, this.height >> mapLevel, mapWidth,
mapHeight);
};
}else {
currentAnimUpdater = null;
}
} else {
currentAnimUpdater = null;
}
}
public void copyAnimationFrame(int mapWidth, int mapHeight, int mapLevel) {
if(currentAnimUpdater != null) {
currentAnimUpdater.updateAnimation(mapWidth, mapHeight, mapLevel);
}
}
@ -367,7 +399,7 @@ public class EaglerTextureAtlasSprite {
}
}
public void updateAnimationPBR(IFramebufferGL[] copyColorFramebuffer, IFramebufferGL[] copyMaterialFramebuffer, int materialTexOffset) {
public void updateAnimationPBR() {
Throwable t = new UnsupportedOperationException("PBR is not enabled");
try {
throw t;
@ -375,4 +407,37 @@ public class EaglerTextureAtlasSprite {
logger.error(t);
}
}
public void copyAnimationFramePBR(int pass, int width, int height, int level) {
Throwable t = new UnsupportedOperationException("PBR is not enabled");
try {
throw t;
}catch(Throwable tt) {
logger.error(t);
}
}
public int getIndexInMap() {
return this.indexInMap;
}
public void setIndexInMap(int p_setIndexInMap_1_) {
this.indexInMap = p_setIndexInMap_1_;
}
public void updateIndexInMap(CounterInt p_updateIndexInMap_1_) {
if (this.indexInMap < 0) {
this.indexInMap = p_updateIndexInMap_1_.nextValue();
}
}
public double getSpriteU16(float p_getSpriteU16_1_) {
float f = this.maxU - this.minU;
return (double) ((p_getSpriteU16_1_ - this.minU) / f * 16.0F);
}
public double getSpriteV16(float p_getSpriteV16_1_) {
float f = this.maxV - this.minV;
return (double) ((p_getSpriteV16_1_ - this.minV) / f * 16.0F);
}
}

View File

@ -0,0 +1,43 @@
package net.lax1dude.eaglercraft.v1_8.minecraft;
import java.util.Collection;
/**
* Copyright (c) 2025 lax1dude. All Rights Reserved.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
public abstract class ResourceIndex {
protected Collection<String> propertiesCache = null;
protected Collection<String> citPotionsCache = null;
public Collection<String> getPropertiesFiles() {
if(propertiesCache == null) {
propertiesCache = getPropertiesFiles0();
}
return propertiesCache;
}
protected abstract Collection<String> getPropertiesFiles0();
public Collection<String> getCITPotionsFiles() {
if(citPotionsCache == null) {
citPotionsCache = getCITPotionsFiles0();
}
return citPotionsCache;
}
protected abstract Collection<String> getCITPotionsFiles0();
}

View File

@ -1,22 +1,19 @@
package net.lax1dude.eaglercraft.v1_8.minecraft;
import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*;
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
import java.util.List;
import net.lax1dude.eaglercraft.v1_8.EagRuntime;
import net.lax1dude.eaglercraft.v1_8.internal.IFramebufferGL;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.IntBuffer;
import net.lax1dude.eaglercraft.v1_8.opengl.EaglercraftGPU;
import net.lax1dude.eaglercraft.v1_8.opengl.GlStateManager;
import net.lax1dude.eaglercraft.v1_8.opengl.SpriteLevelMixer;
import net.lax1dude.eaglercraft.v1_8.opengl.TextureCopyUtil;
import net.lax1dude.eaglercraft.v1_8.vector.Matrix3f;
import net.minecraft.client.renderer.GLAllocation;
/**
* Copyright (c) 2022 lax1dude. All Rights Reserved.
* Copyright (c) 2022-2025 lax1dude. All Rights Reserved.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
@ -40,8 +37,6 @@ public class TextureAnimationCache {
private int[] cacheTextures = null;
public static final int _GL_FRAMEBUFFER = 0x8D40;
public TextureAnimationCache(int width, int height, int mipLevels) {
this.width = width;
this.height = height;
@ -105,76 +100,40 @@ public class TextureAnimationCache {
}
}
public void copyFrameLevelsToTex2D(int animationFrame, int dx, int dy, int w, int h, IFramebufferGL[] dstFramebuffers) {
copyFrameLevelsToTex2D(animationFrame, mipLevels, dx, dy, w, h, dstFramebuffers);
}
/**
* WARNING: call <code>_wglBindFramebuffer(_GL_FRAMEBUFFER, null);</code> when complete
*/
public void copyFrameLevelsToTex2D(int animationFrame, int levels, int dx, int dy, int w, int h, IFramebufferGL[] dstFramebuffers) {
for(int i = 0; i < levels; ++i) {
_wglBindFramebuffer(_GL_FRAMEBUFFER, dstFramebuffers[i]);
copyFrameToTex2D(animationFrame, i, dx >> i, dy >> i, w >> i, h >> i);
}
}
public void copyFrameToTex2D(int animationFrame, int level, int dx, int dy, int w, int h) {
public void copyFrameToTex2D(int animationFrame, int level, int dx, int dy, int w, int h, int mapWidth, int mapHeight) {
if(cacheTextures == null) {
throw new IllegalStateException("Cannot copy from uninitialized TextureAnimationCache");
}
GlStateManager.disableBlend();
GlStateManager.disableAlpha();
GlStateManager.bindTexture(cacheTextures[level]);
TextureCopyUtil.srcSize(width >> level, (height >> level) * frameCount);
TextureCopyUtil.blitTextureUsingViewports(0, h * animationFrame, dx, dy, w, h);
}
public void copyInterpolatedFrameLevelsToTex2D(int animationFrameFrom, int animationFrameTo, float factor, int dx,
int dy, int w, int h, IFramebufferGL[] dstFramebuffers) {
copyInterpolatedFrameLevelsToTex2D(animationFrameFrom, animationFrameTo, factor, mipLevels, dx, dy, w, h, dstFramebuffers);
}
/**
* WARNING: call <code>_wglBindFramebuffer(_GL_FRAMEBUFFER, null);</code> when complete
*/
public void copyInterpolatedFrameLevelsToTex2D(int animationFrameFrom, int animationFrameTo, float factor,
int levels, int dx, int dy, int w, int h, IFramebufferGL[] dstFramebuffers) {
for(int i = 0; i < levels; ++i) {
_wglBindFramebuffer(_GL_FRAMEBUFFER, dstFramebuffers[i]);
copyInterpolatedFrameToTex2D(animationFrameFrom, animationFrameTo, factor, i, dx >> i, dy >> i, w >> i, h >> i);
}
TextureCopyUtil.dstSize(mapWidth, mapHeight);
TextureCopyUtil.blitTexture(0, h * animationFrame, dx, dy, w, h);
}
public void copyInterpolatedFrameToTex2D(int animationFrameFrom, int animationFrameTo, float factor, int level,
int dx, int dy, int w, int h) {
int dx, int dy, int w, int h, int mapWidth, int mapHeight) {
if(cacheTextures == null) {
throw new IllegalStateException("Cannot copy from uninitialized TextureAnimationCache");
}
GlStateManager.viewport(dx, dy, w, h);
GlStateManager.bindTexture(cacheTextures[level]);
GlStateManager.disableBlend();
Matrix3f matrix = new Matrix3f();
matrix.m11 = 1.0f / frameCount;
matrix.m21 = matrix.m11 * animationFrameFrom;
SpriteLevelMixer.setMatrix3f(matrix);
SpriteLevelMixer.srcSize(width >> level, (height >> level) * frameCount);
SpriteLevelMixer.dstSize(mapWidth, mapHeight);
SpriteLevelMixer.setBlendColor(factor, factor, factor, factor);
SpriteLevelMixer.setBiasColor(0.0f, 0.0f, 0.0f, 0.0f);
SpriteLevelMixer.drawSprite(0);
SpriteLevelMixer.drawSprite(0, 0, h * animationFrameFrom, w, h, dx, dy, w, h);
matrix.m21 = matrix.m11 * animationFrameTo;
SpriteLevelMixer.setMatrix3f(matrix);
float fac1 = 1.0f - factor;
SpriteLevelMixer.setBlendColor(fac1, fac1, fac1, fac1);
GlStateManager.enableBlend();
GlStateManager.blendFunc(GL_ONE, GL_ONE);
SpriteLevelMixer.drawSprite(0);
SpriteLevelMixer.drawSprite(0, 0, h * animationFrameTo, w, h, dx, dy, w, h);
GlStateManager.disableBlend();
GlStateManager.blendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);