Merge 1.18 into 1.19.2
This commit is contained in:
commit
12345a67e8
|
|
@ -0,0 +1,15 @@
|
||||||
|
package org.embeddedt.modernfix.common.mixin.perf.dynamic_dfu;
|
||||||
|
|
||||||
|
import net.minecraft.SharedConstants;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
|
@Mixin(SharedConstants.class)
|
||||||
|
public class SharedConstantsMixin {
|
||||||
|
@Inject(method = "<clinit>", at = @At("RETURN"))
|
||||||
|
private static void skipSchemaCheck(CallbackInfo ci) {
|
||||||
|
SharedConstants.CHECK_DATA_FIXER_SCHEMA = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,37 +1,26 @@
|
||||||
package org.embeddedt.modernfix.dfu;
|
package org.embeddedt.modernfix.dfu;
|
||||||
|
|
||||||
import com.mojang.datafixers.DSL;
|
import com.mojang.datafixers.DSL;
|
||||||
import com.mojang.datafixers.DataFixUtils;
|
|
||||||
import com.mojang.datafixers.DataFixer;
|
import com.mojang.datafixers.DataFixer;
|
||||||
import com.mojang.datafixers.schemas.Schema;
|
import com.mojang.datafixers.schemas.Schema;
|
||||||
import com.mojang.datafixers.types.Type;
|
|
||||||
import com.mojang.datafixers.types.constant.EmptyPart;
|
|
||||||
import com.mojang.datafixers.types.templates.TypeTemplate;
|
|
||||||
import com.mojang.serialization.Dynamic;
|
import com.mojang.serialization.Dynamic;
|
||||||
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
|
||||||
import net.minecraft.SharedConstants;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
public class LazyDataFixer implements DataFixer {
|
public class LazyDataFixer implements DataFixer {
|
||||||
private static final Logger LOGGER = LogManager.getLogger("ModernFix");
|
private static final Logger LOGGER = LogManager.getLogger("ModernFix");
|
||||||
private DataFixer backingDataFixer;
|
private DataFixer backingDataFixer;
|
||||||
private final Supplier<DataFixer> dfuSupplier;
|
private final Supplier<DataFixer> dfuSupplier;
|
||||||
private static final Schema FAKE_SCHEMA = new EmptySchema();
|
|
||||||
|
|
||||||
public LazyDataFixer(Supplier<DataFixer> dfuSupplier) {
|
public LazyDataFixer(Supplier<DataFixer> dfuSupplier) {
|
||||||
LOGGER.info("Bypassed Mojang DFU");
|
LOGGER.info("Bypassed Mojang DFU");
|
||||||
this.backingDataFixer = null;
|
this.backingDataFixer = null;
|
||||||
this.dfuSupplier = dfuSupplier;
|
this.dfuSupplier = dfuSupplier;
|
||||||
}
|
}
|
||||||
@Override
|
|
||||||
public <T> Dynamic<T> update(DSL.TypeReference type, Dynamic<T> input, int version, int newVersion) {
|
private DataFixer getDataFixer() {
|
||||||
if(version >= newVersion)
|
|
||||||
return input;
|
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
if(backingDataFixer == null) {
|
if(backingDataFixer == null) {
|
||||||
LOGGER.info("Instantiating Mojang DFU");
|
LOGGER.info("Instantiating Mojang DFU");
|
||||||
|
|
@ -39,58 +28,18 @@ public class LazyDataFixer implements DataFixer {
|
||||||
backingDataFixer = dfuSupplier.get();
|
backingDataFixer = dfuSupplier.get();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return backingDataFixer.update(type, input, version, newVersion);
|
return backingDataFixer;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> Dynamic<T> update(DSL.TypeReference type, Dynamic<T> input, int version, int newVersion) {
|
||||||
|
if(version >= newVersion)
|
||||||
|
return input;
|
||||||
|
return getDataFixer().update(type, input, version, newVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* "getSchema is only there for checks that are not important" - fry, 2021
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public Schema getSchema(int key) {
|
public Schema getSchema(int key) {
|
||||||
return FAKE_SCHEMA;
|
return getDataFixer().getSchema(key);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Empty schema that also returns empty Type<?> instances to prevent crashes.
|
|
||||||
*/
|
|
||||||
static class EmptySchema extends Schema {
|
|
||||||
public EmptySchema() {
|
|
||||||
super(DataFixUtils.makeKey(SharedConstants.getCurrentVersion().getWorldVersion()), null);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final Type<?> EMPTY_TYPE = new EmptyPart();
|
|
||||||
private static final TypeTemplate FAKE_TEMPLATE = EMPTY_TYPE.template();
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Map<String, Type<?>> buildTypes() {
|
|
||||||
Object2ObjectOpenHashMap<String, Type<?>> map = new Object2ObjectOpenHashMap<>();
|
|
||||||
map.defaultReturnValue(new EmptyPart());
|
|
||||||
return map;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TypeTemplate resolveTemplate(String name) {
|
|
||||||
return FAKE_TEMPLATE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Type<?> getChoiceType(DSL.TypeReference type, String choiceName) {
|
|
||||||
return EMPTY_TYPE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void registerTypes(Schema schema, Map<String, Supplier<TypeTemplate>> entityTypes, Map<String, Supplier<TypeTemplate>> blockEntityTypes) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Map<String, Supplier<TypeTemplate>> registerEntities(Schema schema) {
|
|
||||||
return Collections.emptyMap();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Map<String, Supplier<TypeTemplate>> registerBlockEntities(Schema schema) {
|
|
||||||
return Collections.emptyMap();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user