Skip to content

Commit 12345a6

Browse files
committed
Merge 1.18 into 1.19.2
2 parents eea53ee + 440cc21 commit 12345a6

File tree

2 files changed

+25
-61
lines changed

2 files changed

+25
-61
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package org.embeddedt.modernfix.common.mixin.perf.dynamic_dfu;
2+
3+
import net.minecraft.SharedConstants;
4+
import org.spongepowered.asm.mixin.Mixin;
5+
import org.spongepowered.asm.mixin.injection.At;
6+
import org.spongepowered.asm.mixin.injection.Inject;
7+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
8+
9+
@Mixin(SharedConstants.class)
10+
public class SharedConstantsMixin {
11+
@Inject(method = "<clinit>", at = @At("RETURN"))
12+
private static void skipSchemaCheck(CallbackInfo ci) {
13+
SharedConstants.CHECK_DATA_FIXER_SCHEMA = false;
14+
}
15+
}
Lines changed: 10 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,45 @@
11
package org.embeddedt.modernfix.dfu;
22

33
import com.mojang.datafixers.DSL;
4-
import com.mojang.datafixers.DataFixUtils;
54
import com.mojang.datafixers.DataFixer;
65
import com.mojang.datafixers.schemas.Schema;
7-
import com.mojang.datafixers.types.Type;
8-
import com.mojang.datafixers.types.constant.EmptyPart;
9-
import com.mojang.datafixers.types.templates.TypeTemplate;
106
import com.mojang.serialization.Dynamic;
11-
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
12-
import net.minecraft.SharedConstants;
137
import org.apache.logging.log4j.LogManager;
148
import org.apache.logging.log4j.Logger;
159

16-
import java.util.Collections;
17-
import java.util.Map;
1810
import java.util.function.Supplier;
1911

2012
public class LazyDataFixer implements DataFixer {
2113
private static final Logger LOGGER = LogManager.getLogger("ModernFix");
2214
private DataFixer backingDataFixer;
2315
private final Supplier<DataFixer> dfuSupplier;
24-
private static final Schema FAKE_SCHEMA = new EmptySchema();
2516

2617
public LazyDataFixer(Supplier<DataFixer> dfuSupplier) {
2718
LOGGER.info("Bypassed Mojang DFU");
2819
this.backingDataFixer = null;
2920
this.dfuSupplier = dfuSupplier;
3021
}
31-
@Override
32-
public <T> Dynamic<T> update(DSL.TypeReference type, Dynamic<T> input, int version, int newVersion) {
33-
if(version >= newVersion)
34-
return input;
22+
23+
private DataFixer getDataFixer() {
3524
synchronized (this) {
3625
if(backingDataFixer == null) {
3726
LOGGER.info("Instantiating Mojang DFU");
3827
DFUBlaster.blastMaps();
3928
backingDataFixer = dfuSupplier.get();
4029
}
4130
}
42-
return backingDataFixer.update(type, input, version, newVersion);
31+
return backingDataFixer;
4332
}
4433

45-
/**
46-
* "getSchema is only there for checks that are not important" - fry, 2021
47-
*/
4834
@Override
49-
public Schema getSchema(int key) {
50-
return FAKE_SCHEMA;
35+
public <T> Dynamic<T> update(DSL.TypeReference type, Dynamic<T> input, int version, int newVersion) {
36+
if(version >= newVersion)
37+
return input;
38+
return getDataFixer().update(type, input, version, newVersion);
5139
}
5240

53-
/**
54-
* Empty schema that also returns empty Type<?> instances to prevent crashes.
55-
*/
56-
static class EmptySchema extends Schema {
57-
public EmptySchema() {
58-
super(DataFixUtils.makeKey(SharedConstants.getCurrentVersion().getWorldVersion()), null);
59-
}
60-
61-
private static final Type<?> EMPTY_TYPE = new EmptyPart();
62-
private static final TypeTemplate FAKE_TEMPLATE = EMPTY_TYPE.template();
63-
64-
65-
@Override
66-
protected Map<String, Type<?>> buildTypes() {
67-
Object2ObjectOpenHashMap<String, Type<?>> map = new Object2ObjectOpenHashMap<>();
68-
map.defaultReturnValue(new EmptyPart());
69-
return map;
70-
}
71-
72-
@Override
73-
public TypeTemplate resolveTemplate(String name) {
74-
return FAKE_TEMPLATE;
75-
}
76-
77-
@Override
78-
public Type<?> getChoiceType(DSL.TypeReference type, String choiceName) {
79-
return EMPTY_TYPE;
80-
}
81-
82-
@Override
83-
public void registerTypes(Schema schema, Map<String, Supplier<TypeTemplate>> entityTypes, Map<String, Supplier<TypeTemplate>> blockEntityTypes) {
84-
}
85-
86-
@Override
87-
public Map<String, Supplier<TypeTemplate>> registerEntities(Schema schema) {
88-
return Collections.emptyMap();
89-
}
90-
91-
@Override
92-
public Map<String, Supplier<TypeTemplate>> registerBlockEntities(Schema schema) {
93-
return Collections.emptyMap();
94-
}
41+
@Override
42+
public Schema getSchema(int key) {
43+
return getDataFixer().getSchema(key);
9544
}
9645
}

0 commit comments

Comments
 (0)