Merge remote-tracking branch 'origin/main' into 1.18
This commit is contained in:
commit
8303d85b6c
|
|
@ -1,7 +1,6 @@
|
||||||
package org.embeddedt.modernfix;
|
package org.embeddedt.modernfix;
|
||||||
|
|
||||||
import com.mojang.datafixers.util.Pair;
|
import com.mojang.datafixers.util.Pair;
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.gui.screens.ConnectScreen;
|
import net.minecraft.client.gui.screens.ConnectScreen;
|
||||||
|
|
@ -107,7 +106,19 @@ public class ModernFixClient {
|
||||||
*
|
*
|
||||||
* This is to ensure we can perform ID fixup on already constructed managers.
|
* This is to ensure we can perform ID fixup on already constructed managers.
|
||||||
*/
|
*/
|
||||||
public static Set<SynchedEntityData> allEntityDatas = Collections.newSetFromMap(new WeakHashMap<>());
|
public static final Set<SynchedEntityData> allEntityDatas = Collections.newSetFromMap(new WeakHashMap<>());
|
||||||
|
|
||||||
|
private static final Field entriesArrayField;
|
||||||
|
static {
|
||||||
|
Field field;
|
||||||
|
try {
|
||||||
|
field = SynchedEntityData.class.getDeclaredField("entriesArray");
|
||||||
|
field.setAccessible(true);
|
||||||
|
} catch(ReflectiveOperationException e) {
|
||||||
|
field = null;
|
||||||
|
}
|
||||||
|
entriesArrayField = field;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extremely hacky method to detect and correct mismatched entity data parameter IDs on the client and server.
|
* Extremely hacky method to detect and correct mismatched entity data parameter IDs on the client and server.
|
||||||
|
|
@ -142,12 +153,28 @@ public class ModernFixClient {
|
||||||
if(fixNeeded) {
|
if(fixNeeded) {
|
||||||
dataEntries = new ArrayList<>(allEntityDatas);
|
dataEntries = new ArrayList<>(allEntityDatas);
|
||||||
for(SynchedEntityData manager : dataEntries) {
|
for(SynchedEntityData manager : dataEntries) {
|
||||||
Int2ObjectMap<SynchedEntityData.DataItem<?>> fixedMap = new Int2ObjectOpenHashMap<>();
|
Int2ObjectOpenHashMap<SynchedEntityData.DataItem<?>> fixedMap = new Int2ObjectOpenHashMap<>();
|
||||||
List<SynchedEntityData.DataItem<?>> items = new ArrayList<>(manager.itemsById.values());
|
List<SynchedEntityData.DataItem<?>> items = new ArrayList<>(manager.itemsById.values());
|
||||||
for(SynchedEntityData.DataItem<?> item : items) {
|
for(SynchedEntityData.DataItem<?> item : items) {
|
||||||
fixedMap.put(item.getAccessor().id, item);
|
fixedMap.put(item.getAccessor().id, item);
|
||||||
}
|
}
|
||||||
manager.itemsById = fixedMap;
|
manager.lock.writeLock().lock();
|
||||||
|
try {
|
||||||
|
manager.itemsById.replaceAll((id, parameter) -> fixedMap.get((int)id));
|
||||||
|
if(entriesArrayField != null) {
|
||||||
|
try {
|
||||||
|
SynchedEntityData.DataItem<?>[] dataArray = new SynchedEntityData.DataItem[items.size()];
|
||||||
|
for(int i = 0; i < dataArray.length; i++) {
|
||||||
|
dataArray[i] = fixedMap.get(i);
|
||||||
|
}
|
||||||
|
entriesArrayField.set(manager, dataArray);
|
||||||
|
} catch(ReflectiveOperationException e) {
|
||||||
|
ModernFix.LOGGER.error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
manager.lock.writeLock().unlock();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
allEntityDatas.clear();
|
allEntityDatas.clear();
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,7 @@ public class ModernFixEarlyConfig {
|
||||||
disableIfModPresent("mixin.perf.thread_priorities", "smoothboot");
|
disableIfModPresent("mixin.perf.thread_priorities", "smoothboot");
|
||||||
disableIfModPresent("mixin.perf.async_jei", "modernui");
|
disableIfModPresent("mixin.perf.async_jei", "modernui");
|
||||||
disableIfModPresent("mixin.perf.compress_biome_container", "chocolate");
|
disableIfModPresent("mixin.perf.compress_biome_container", "chocolate");
|
||||||
|
disableIfModPresent("mixin.bugfix.mc218112", "performant");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void disableIfModPresent(String configName, String... ids) {
|
private void disableIfModPresent(String configName, String... ids) {
|
||||||
|
|
|
||||||
|
|
@ -11,12 +11,119 @@ import org.lwjgl.stb.STBRPNode;
|
||||||
import org.lwjgl.stb.STBRPRect;
|
import org.lwjgl.stb.STBRPRect;
|
||||||
import org.lwjgl.stb.STBRectPack;
|
import org.lwjgl.stb.STBRectPack;
|
||||||
|
|
||||||
|
import static java.lang.invoke.MethodHandles.*;
|
||||||
|
import static java.lang.invoke.MethodType.*;
|
||||||
|
|
||||||
|
import java.lang.invoke.MethodHandle;
|
||||||
|
import java.sql.Ref;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
/* Source: https://github.com/GTNewHorizons/lwjgl3ify/blob/f21364cd3d178aef863458a2faa1f5718a4e350d/src/main/java/me/eigenraven/lwjgl3ify/textures/StbStitcher.java */
|
/* Source: https://github.com/GTNewHorizons/lwjgl3ify/blob/f21364cd3d178aef863458a2faa1f5718a4e350d/src/main/java/me/eigenraven/lwjgl3ify/textures/StbStitcher.java */
|
||||||
public class StbStitcher {
|
public class StbStitcher {
|
||||||
|
/* Most of this logic is to allow use of LWJGL versions where coordinates are short and versions where they are int */
|
||||||
|
private static final MethodHandle MH_rect_shortSet, MH_rect_intSet, MH_rect_intX, MH_rect_intY, MH_rect_shortX,
|
||||||
|
MH_rect_shortY;
|
||||||
|
|
||||||
|
static {
|
||||||
|
MethodHandle shortM = null, intM = null;
|
||||||
|
List<ReflectiveOperationException> exceptions = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
intM = publicLookup().findVirtual(STBRPRect.class, "set", methodType(STBRPRect.class,
|
||||||
|
int.class, /* id */
|
||||||
|
int.class,
|
||||||
|
int.class,
|
||||||
|
int.class,
|
||||||
|
int.class,
|
||||||
|
boolean.class));
|
||||||
|
} catch(ReflectiveOperationException e) {
|
||||||
|
exceptions.add(e);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
shortM = publicLookup().findVirtual(STBRPRect.class, "set", methodType(STBRPRect.class,
|
||||||
|
int.class, /* id */
|
||||||
|
short.class,
|
||||||
|
short.class,
|
||||||
|
short.class,
|
||||||
|
short.class,
|
||||||
|
boolean.class));
|
||||||
|
} catch(ReflectiveOperationException e) {
|
||||||
|
exceptions.add(e);
|
||||||
|
}
|
||||||
|
if(shortM == null && intM == null) {
|
||||||
|
IllegalStateException e = new IllegalStateException("An STBRPRect set method could not be located");
|
||||||
|
exceptions.forEach(e::addSuppressed);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
MH_rect_shortSet = shortM;
|
||||||
|
MH_rect_intSet = intM;
|
||||||
|
/* Now look for X methods */
|
||||||
|
exceptions.clear();
|
||||||
|
try {
|
||||||
|
intM = publicLookup().findVirtual(STBRPRect.class, "x", methodType(int.class));
|
||||||
|
} catch(ReflectiveOperationException e) {
|
||||||
|
exceptions.add(e);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
shortM = publicLookup().findVirtual(STBRPRect.class, "x", methodType(short.class));
|
||||||
|
} catch(ReflectiveOperationException e) {
|
||||||
|
exceptions.add(e);
|
||||||
|
}
|
||||||
|
if(shortM == null && intM == null) {
|
||||||
|
IllegalStateException e = new IllegalStateException("An STBRPRect x() method could not be located");
|
||||||
|
exceptions.forEach(e::addSuppressed);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
MH_rect_shortX = shortM;
|
||||||
|
MH_rect_intX = intM;
|
||||||
|
/* Assume that Y is the same */
|
||||||
|
try {
|
||||||
|
if(MH_rect_shortX != null) {
|
||||||
|
MH_rect_shortY = publicLookup().findVirtual(STBRPRect.class, "y", methodType(short.class));
|
||||||
|
MH_rect_intY = null;
|
||||||
|
} else { /* it must be int */
|
||||||
|
MH_rect_intY = publicLookup().findVirtual(STBRPRect.class, "y", methodType(int.class));
|
||||||
|
MH_rect_shortY = null;
|
||||||
|
}
|
||||||
|
} catch(ReflectiveOperationException e) {
|
||||||
|
throw new IllegalStateException("An STBRPRect y() method could not be located", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static STBRPRect setWrapper(STBRPRect rect, int id, int width, int height, int x, int y, boolean was_packed) {
|
||||||
|
try {
|
||||||
|
if(MH_rect_shortSet != null)
|
||||||
|
return (STBRPRect)MH_rect_shortSet.invokeExact(rect, id, (short)width, (short)height, (short)0, (short)0, false);
|
||||||
|
else
|
||||||
|
return (STBRPRect)MH_rect_intSet.invokeExact(rect, id, width, height, 0, 0, false);
|
||||||
|
} catch(Throwable e) {
|
||||||
|
throw new AssertionError(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int getX(STBRPRect rect) {
|
||||||
|
try {
|
||||||
|
if(MH_rect_shortX != null)
|
||||||
|
return (short)MH_rect_shortX.invokeExact(rect);
|
||||||
|
else
|
||||||
|
return (int)MH_rect_intX.invokeExact(rect);
|
||||||
|
} catch(Throwable e) {
|
||||||
|
throw new AssertionError(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int getY(STBRPRect rect) {
|
||||||
|
try {
|
||||||
|
if(MH_rect_shortX != null)
|
||||||
|
return (short)MH_rect_shortY.invokeExact(rect);
|
||||||
|
else
|
||||||
|
return (int)MH_rect_intY.invokeExact(rect);
|
||||||
|
} catch(Throwable e) {
|
||||||
|
throw new AssertionError(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static Pair<Pair<Integer, Integer>, List<LoadableSpriteInfo>> packRects(Stitcher.Holder[] holders) {
|
public static Pair<Pair<Integer, Integer>, List<LoadableSpriteInfo>> packRects(Stitcher.Holder[] holders) {
|
||||||
int holderSize = holders.length;
|
int holderSize = holders.length;
|
||||||
|
|
||||||
|
|
@ -36,7 +143,9 @@ public class StbStitcher {
|
||||||
int height = holder.height;
|
int height = holder.height;
|
||||||
|
|
||||||
// The ID here is just the array index, for easy lookup later
|
// The ID here is just the array index, for easy lookup later
|
||||||
rectBuf.get(j).set(j, (short)width, (short)height, (short)0, (short)0, false);
|
STBRPRect rect = rectBuf.get(j);
|
||||||
|
|
||||||
|
setWrapper(rect, j, width, height, 0, 0, false);
|
||||||
|
|
||||||
sqSize += (width * height);
|
sqSize += (width * height);
|
||||||
}
|
}
|
||||||
|
|
@ -63,7 +172,7 @@ public class StbStitcher {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize the sprite now with the position and size that we've calculated so far
|
// Initialize the sprite now with the position and size that we've calculated so far
|
||||||
infoList.add(new LoadableSpriteInfo(holder.spriteInfo, width, height, rect.x(), rect.y()));
|
infoList.add(new LoadableSpriteInfo(holder.spriteInfo, width, height, getX(rect), getY(rect)));
|
||||||
//holder.spriteInfo.initSprite(size, size, rect.x(), rect.y(), false);
|
//holder.spriteInfo.initSprite(size, size, rect.x(), rect.y(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,3 +11,4 @@ public net.minecraft.server.MinecraftServer f_129726_ # nextTickTime
|
||||||
public net.minecraft.client.Minecraft f_90999_ # progressListener
|
public net.minecraft.client.Minecraft f_90999_ # progressListener
|
||||||
public-f net.minecraft.network.syncher.EntityDataAccessor f_135010_ # id
|
public-f net.minecraft.network.syncher.EntityDataAccessor f_135010_ # id
|
||||||
public-f net.minecraft.network.syncher.SynchedEntityData f_135345_ # itemsById
|
public-f net.minecraft.network.syncher.SynchedEntityData f_135345_ # itemsById
|
||||||
|
public-f net.minecraft.network.syncher.SynchedEntityData f_135346_ # lock
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user