Implement tracking range
This commit is contained in:
parent
efc4df3c36
commit
402346073d
@ -11,13 +11,15 @@ import java.util.Collections;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class GlobalClassRepo implements ClassRepo {
|
public class GlobalClassRepo implements ClassRepo {
|
||||||
|
|
||||||
public static final GlobalClassRepo INSTANCE = new GlobalClassRepo();
|
public static final GlobalClassRepo INSTANCE = new GlobalClassRepo();
|
||||||
private static final PluginInheritanceProvider PROVIDER = new PluginInheritanceProvider(INSTANCE);
|
private static final PluginInheritanceProvider PROVIDER = new PluginInheritanceProvider(INSTANCE);
|
||||||
|
|
||||||
private final LoadingCache<String, ClassNode> cache = CacheBuilder.newBuilder().maximumSize(65536).build(CacheLoader.from(this::findParallel));
|
private final LoadingCache<String, ClassNode> cache = CacheBuilder.newBuilder().maximumSize(256)
|
||||||
|
.expireAfterAccess(1, TimeUnit.MINUTES).build(CacheLoader.from(this::findParallel));
|
||||||
private final Set<ClassRepo> repos = Collections.newSetFromMap(new ConcurrentHashMap<>());
|
private final Set<ClassRepo> repos = Collections.newSetFromMap(new ConcurrentHashMap<>());
|
||||||
|
|
||||||
private GlobalClassRepo() {
|
private GlobalClassRepo() {
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import io.izzel.arclight.api.ArclightVersion;
|
|||||||
import io.izzel.arclight.api.Unsafe;
|
import io.izzel.arclight.api.Unsafe;
|
||||||
import io.izzel.arclight.common.mod.util.remapper.ClassLoaderAdapter;
|
import io.izzel.arclight.common.mod.util.remapper.ClassLoaderAdapter;
|
||||||
import io.izzel.arclight.common.mod.util.remapper.ClassLoaderRemapper;
|
import io.izzel.arclight.common.mod.util.remapper.ClassLoaderRemapper;
|
||||||
|
import org.objectweb.asm.ClassReader;
|
||||||
import org.objectweb.asm.Type;
|
import org.objectweb.asm.Type;
|
||||||
|
|
||||||
import java.lang.invoke.MethodHandle;
|
import java.lang.invoke.MethodHandle;
|
||||||
@ -53,12 +54,6 @@ public class ArclightReflectionHandler extends ClassLoader {
|
|||||||
|
|
||||||
// bukkit -> srg
|
// bukkit -> srg
|
||||||
public static Method redirectGetMethod(Class<?> cl, String bukkitName, Class<?>... pTypes) throws NoSuchMethodException {
|
public static Method redirectGetMethod(Class<?> cl, String bukkitName, Class<?>... pTypes) throws NoSuchMethodException {
|
||||||
if (ClassLoaderAdapter.isDefineClassMethod(cl, bukkitName, pTypes)) {
|
|
||||||
Class<?>[] classes = new Class<?>[pTypes.length + 1];
|
|
||||||
classes[0] = ClassLoader.class;
|
|
||||||
System.arraycopy(pTypes, 0, classes, 1, pTypes.length);
|
|
||||||
return ArclightReflectionHandler.class.getMethod(bukkitName, classes);
|
|
||||||
}
|
|
||||||
Method method = remapper.tryMapMethodToSrg(cl, bukkitName, pTypes);
|
Method method = remapper.tryMapMethodToSrg(cl, bukkitName, pTypes);
|
||||||
if (method != null) {
|
if (method != null) {
|
||||||
return method;
|
return method;
|
||||||
@ -69,12 +64,6 @@ public class ArclightReflectionHandler extends ClassLoader {
|
|||||||
|
|
||||||
// bukkit -> srg
|
// bukkit -> srg
|
||||||
public static Method redirectGetDeclaredMethod(Class<?> cl, String bukkitName, Class<?>... pTypes) throws NoSuchMethodException {
|
public static Method redirectGetDeclaredMethod(Class<?> cl, String bukkitName, Class<?>... pTypes) throws NoSuchMethodException {
|
||||||
if (ClassLoaderAdapter.isDefineClassMethod(cl, bukkitName, pTypes)) {
|
|
||||||
Class<?>[] classes = new Class<?>[pTypes.length + 1];
|
|
||||||
classes[0] = ClassLoader.class;
|
|
||||||
System.arraycopy(pTypes, 0, classes, 1, pTypes.length);
|
|
||||||
return ArclightReflectionHandler.class.getDeclaredMethod(bukkitName, classes);
|
|
||||||
}
|
|
||||||
Method method = remapper.tryMapMethodToSrg(cl, bukkitName, pTypes);
|
Method method = remapper.tryMapMethodToSrg(cl, bukkitName, pTypes);
|
||||||
if (method != null) {
|
if (method != null) {
|
||||||
return method;
|
return method;
|
||||||
@ -253,7 +242,7 @@ public class ArclightReflectionHandler extends ClassLoader {
|
|||||||
|
|
||||||
public static Class<?> defineClass(ClassLoader loader, String name, byte[] b, int off, int len, ProtectionDomain pd) {
|
public static Class<?> defineClass(ClassLoader loader, String name, byte[] b, int off, int len, ProtectionDomain pd) {
|
||||||
byte[] bytes = remapper.remapClass(b);
|
byte[] bytes = remapper.remapClass(b);
|
||||||
return Unsafe.defineClass(name, bytes, 0, bytes.length, loader, pd);
|
return Unsafe.defineClass(new ClassReader(bytes).getClassName().replace('/', '.'), bytes, 0, bytes.length, loader, pd);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Class<?> defineClass(ClassLoader loader, String name, ByteBuffer b, ProtectionDomain pd) {
|
public static Class<?> defineClass(ClassLoader loader, String name, ByteBuffer b, ProtectionDomain pd) {
|
||||||
|
|||||||
@ -0,0 +1,17 @@
|
|||||||
|
package io.izzel.arclight.impl.mixin.optimization.general.trackingrange;
|
||||||
|
|
||||||
|
import net.minecraft.entity.Entity;
|
||||||
|
import net.minecraft.world.server.ChunkManager;
|
||||||
|
import org.spigotmc.TrackingRange;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.ModifyVariable;
|
||||||
|
|
||||||
|
@Mixin(ChunkManager.class)
|
||||||
|
public class ChunkManagerMixin_TrackingRange {
|
||||||
|
|
||||||
|
@ModifyVariable(method = "track", index = 3, at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/EntityType;getUpdateFrequency()I"))
|
||||||
|
private int trackingRange$updateRange(int defaultRange, Entity entity) {
|
||||||
|
return TrackingRange.getEntityTrackingRange(entity, defaultRange);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -15,6 +15,7 @@
|
|||||||
"activationrange.entity.FireworkRocketEntityMixin_ActivationRange",
|
"activationrange.entity.FireworkRocketEntityMixin_ActivationRange",
|
||||||
"activationrange.entity.ItemEntityMixin_ActivationRange",
|
"activationrange.entity.ItemEntityMixin_ActivationRange",
|
||||||
"activationrange.entity.LivingEntityMixin_ActivationRange",
|
"activationrange.entity.LivingEntityMixin_ActivationRange",
|
||||||
"activationrange.entity.VillagerEntityMixin_ActivationRange"
|
"activationrange.entity.VillagerEntityMixin_ActivationRange",
|
||||||
|
"trackingrange.ChunkManagerMixin_TrackingRange"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user