Skip to content

Commit 708ec7e

Browse files
committed
Fix incompatibilities with Optifine and Galacticraft
1 parent ed18645 commit 708ec7e

10 files changed

Lines changed: 147 additions & 31 deletions

File tree

build.gradle

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,17 @@ dependencies {
5252
def travisBuildNumber = System.getenv("TRAVIS_BUILD_NUMBER")
5353
def versionSuffix = travisBuildNumber != null ? travisBuildNumber : "SNAPSHOT"
5454

55-
version "1.0.10-$versionSuffix"
55+
version "1.1-$versionSuffix"
5656
group "org.dimdev.vanillafix"
5757
archivesBaseName = "VanillaFix"
5858

5959
sourceCompatibility = 1.8
6060
targetCompatibility = 1.8
6161

62+
sourceSets {
63+
main
64+
}
65+
6266
minecraft {
6367
version "1.12.2-14.23.4.2703"
6468
runDir "run"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package net.optifine.render;
2+
3+
public class RenderEnv {}

src/main/java/org/dimdev/vanillafix/ModCompatibilityMixinPlugin.java

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,9 @@
1010
import java.util.Set;
1111

1212
public class ModCompatibilityMixinPlugin implements IMixinConfigPlugin {
13-
private boolean spongeInstalled;
14-
1513
@Override
1614
public void onLoad(String mixinPackage) {
17-
try {
18-
spongeInstalled = Launch.classLoader.getClassBytes("org.spongepowered.mod.SpongeCoremod") != null;
19-
} catch (IOException e) {
20-
throw new RuntimeException(e); // Should never happen
21-
}
15+
2216
}
2317

2418
@Override
@@ -27,16 +21,30 @@ public String getRefMapperConfig() {
2721
}
2822

2923
@Override
30-
@SuppressWarnings("RedundantIfStatement")
3124
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
32-
// Sponge
33-
if (spongeInstalled) {
34-
if (mixinClassName.equals("org.dimdev.vanillafix.profiler.mixins.MixinWorld")) return false;
25+
if (mixinClassName.equals("org.dimdev.vanillafix.profiler.mixins.MixinWorld")) {
26+
return !classExists("org.spongepowered.mod.SpongeCoremod");
27+
}
28+
29+
if (mixinClassName.equals("org.dimdev.vanillafix.textures.mixins.client.MixinBlockModelRenderer")) {
30+
return !classExists("optifine.OptiFineForgeTweaker");
31+
}
32+
33+
if (mixinClassName.equals("org.dimdev.vanillafix.textures.mixins.client.MixinBlockModelRendererOptifine")) {
34+
return classExists("optifine.OptiFineForgeTweaker");
3535
}
3636

3737
return true;
3838
}
3939

40+
public boolean classExists(String name) {
41+
try {
42+
return Launch.classLoader.getClassBytes(name) != null;
43+
} catch (IOException e) {
44+
throw new RuntimeException(e);
45+
}
46+
}
47+
4048
@Override
4149
public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {}
4250

src/main/java/org/dimdev/vanillafix/VanillaFixLoadingPlugin.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
import net.minecraft.launchwrapper.Launch;
44
import net.minecraftforge.common.ForgeVersion;
55
import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin;
6-
import net.minecraftforge.fml.relauncher.libraries.LibraryManager;
7-
import org.apache.commons.io.FileUtils;
8-
import org.apache.commons.io.IOUtils;
9-
import org.apache.commons.lang3.StringUtils;
106
import org.apache.logging.log4j.LogManager;
117
import org.apache.logging.log4j.Logger;
128
import org.dimdev.utils.SSLUtils;
@@ -17,13 +13,12 @@
1713
import sun.misc.URLClassPath;
1814

1915
import javax.annotation.Nullable;
20-
import java.io.*;
21-
import java.lang.management.ManagementFactory;
16+
import java.io.File;
17+
import java.io.IOException;
18+
import java.io.InputStream;
2219
import java.lang.reflect.Field;
23-
import java.lang.reflect.Method;
2420
import java.net.URL;
2521
import java.net.URLClassLoader;
26-
import java.nio.file.Files;
2722
import java.security.KeyStore;
2823
import java.security.KeyStoreException;
2924
import java.security.NoSuchAlgorithmException;
@@ -38,20 +33,21 @@
3833
public class VanillaFixLoadingPlugin implements IFMLLoadingPlugin {
3934
private static final Logger log = LogManager.getLogger("VanillaFix");
4035
public static LoadingConfig config;
41-
private static final boolean deobfuscatedEnvironment = VanillaFixLoadingPlugin.class.getResource("/net/minecraft/world/World.class") != null;
36+
// private static final boolean deobfuscatedEnvironment = VanillaFixLoadingPlugin.class.getResource("/net/minecraft/world/World.class") != null;
4237

4338
static {
4439
log.info("Initializing VanillaFix");
4540
config = new LoadingConfig(new File(Launch.minecraftHome, "config/vanillafix.cfg"));
4641
config.improvedLaunchWrapper = false; // TODO: fix this
4742

48-
replaceLaunchWrapper();
43+
// replaceLaunchWrapper();
4944
trustIdenTrust();
5045
initStacktraceDeobfuscator();
5146
fixMixinClasspathOrder();
5247
initMixin();
5348
}
5449

50+
/*
5551
private static void replaceLaunchWrapper() {
5652
if (!config.improvedLaunchWrapper) {
5753
log.info("LaunchWrapper replacement disabled by config");
@@ -136,6 +132,7 @@ private static String makeNewCommandLine(String newLibraryPath) {
136132
137133
return command.toString();
138134
}
135+
*/
139136

140137
private static void trustIdenTrust() {
141138
// Trust the "IdenTrust DST Root CA X3" certificate (used by Let's Encrypt, which is used by paste.dimdev.org)

src/main/java/org/dimdev/vanillafix/blockstates/mixins/MixinBlockStateContainer.java

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
package org.dimdev.vanillafix.blockstates.mixins;
22

3-
import com.google.common.collect.ImmutableList;
4-
import com.google.common.collect.ImmutableMap;
5-
import com.google.common.collect.ImmutableSortedMap;
3+
import com.google.common.collect.*;
64
import net.minecraft.block.Block;
75
import net.minecraft.block.properties.IProperty;
86
import net.minecraft.block.state.BlockStateContainer;
97
import net.minecraft.block.state.IBlockState;
108
import net.minecraft.util.MapPopulator;
119
import net.minecraft.util.math.Cartesian;
1210
import net.minecraft.util.math.MathHelper;
11+
import net.minecraftforge.common.property.ExtendedBlockState;
1312
import net.minecraftforge.common.property.IUnlistedProperty;
1413
import org.dimdev.vanillafix.blockstates.IPatchedBlockStateContainer;
1514
import org.dimdev.vanillafix.blockstates.NumericalBlockState;
@@ -18,40 +17,74 @@
1817
import javax.annotation.Nullable;
1918
import java.util.*;
2019

20+
@SuppressWarnings({"ResultOfMethodCallIgnored", "ConstructorNotProtectedInAbstractClass"})
2121
@Mixin(BlockStateContainer.class)
2222
public abstract class MixinBlockStateContainer implements IPatchedBlockStateContainer {
23+
// @formatter:off
2324
@Shadow @Final @Mutable private Block block;
2425
@Shadow @Final @Mutable private ImmutableSortedMap<String, IProperty<?>> properties;
2526
@Shadow public static <T extends Comparable<T>> String validateProperty(Block block, IProperty<T> property) { return null; }
2627
@Shadow protected abstract List<Iterable<Comparable<?>>> getAllowedValues();
28+
@Shadow public abstract Block getBlock();
29+
@Shadow @Final private ImmutableList<IBlockState> validStates;
30+
// @formatter:on
2731

32+
@SuppressWarnings("EqualsBetweenInconvertibleTypes") // mixin
33+
private boolean isNumerical = getClass().equals(BlockStateContainer.class) || getClass().equals(ExtendedBlockState.class);
2834
private final ImmutableMap<IUnlistedProperty<?>, Optional<?>> unlistedProperties;
2935
private final Map<IProperty<?>, Integer> propertyOffsets = new HashMap<>();
30-
protected ImmutableList<IBlockState> validStatesCache;
36+
protected ImmutableList<IBlockState> validStatesCache = null;
37+
@SuppressWarnings({"FieldCanBeLocal", "unused"}) private final Object x; // workaround for mixin bug
3138

3239
@Overwrite
3340
public MixinBlockStateContainer(Block block, IProperty<?>[] properties, ImmutableMap<IUnlistedProperty<?>, Optional<?>> unlistedProperties) {
3441
this.block = block;
3542
this.unlistedProperties = unlistedProperties;
3643

3744
// Immutable map builder won't work, some mods have duplicate properties
38-
LinkedHashMap<String, IProperty<?>> propertyMap = new LinkedHashMap<>();
45+
Map<String, IProperty<?>> propertyMap = new LinkedHashMap<>();
3946
int offset = 0;
4047

4148
for (IProperty<?> property : properties) {
4249
validateProperty(block, property);
4350
propertyMap.put(property.getName(), property);
4451

45-
NumericalBlockState.makePropertyInfo(property);
46-
propertyOffsets.put(property, offset);
47-
offset += MathHelper.log2(property.getAllowedValues().size()) + 1;
52+
if (isNumerical) {
53+
NumericalBlockState.makePropertyInfo(property);
54+
propertyOffsets.put(property, offset);
55+
offset += MathHelper.log2(property.getAllowedValues().size()) + 1;
56+
}
4857
}
4958

5059
this.properties = ImmutableSortedMap.copyOf(propertyMap);
60+
61+
if (!isNumerical) {
62+
Map<Map<IProperty<?>, Comparable<?>>, BlockStateContainer.StateImplementation> map2 = Maps.newLinkedHashMap();
63+
List<BlockStateContainer.StateImplementation> validStates = Lists.newArrayList();
64+
65+
for (List<Comparable<?>> list : Cartesian.cartesianProduct(getAllowedValues())) {
66+
Map<IProperty<?>, Comparable<?>> map1 = MapPopulator.createMap(this.properties.values(), list);
67+
BlockStateContainer.StateImplementation blockstatecontainer$stateimplementation = createState(block, ImmutableMap.copyOf(map1), unlistedProperties);
68+
map2.put(map1, blockstatecontainer$stateimplementation);
69+
validStates.add(blockstatecontainer$stateimplementation);
70+
}
71+
72+
for (BlockStateContainer.StateImplementation blockstatecontainer$stateimplementation1 : validStates) {
73+
blockstatecontainer$stateimplementation1.buildPropertyValueTable(map2);
74+
}
75+
76+
this.validStates = ImmutableList.copyOf(validStates);
77+
}
78+
79+
x = new Object();
5180
}
5281

5382
@Overwrite
5483
public ImmutableList<IBlockState> getValidStates() {
84+
if (!isNumerical) {
85+
return validStates;
86+
}
87+
5588
if (validStatesCache == null) {
5689
ImmutableList.Builder<IBlockState> states = ImmutableList.builder();
5790

@@ -69,6 +102,10 @@ public ImmutableList<IBlockState> getValidStates() {
69102

70103
@Overwrite(remap = false)
71104
protected BlockStateContainer.StateImplementation createState(Block block, ImmutableMap<IProperty<?>, Comparable<?>> properties, @Nullable ImmutableMap<IUnlistedProperty<?>, Optional<?>> unlistedProperties) {
105+
if (!isNumerical) {
106+
return new BlockStateContainer.StateImplementation(block, properties);
107+
}
108+
72109
return null;
73110
}
74111

@@ -83,6 +120,10 @@ protected IBlockState createState(ImmutableMap<IProperty<?>, Comparable<?>> prop
83120

84121
@Overwrite
85122
public IBlockState getBaseState() {
123+
if (!isNumerical) {
124+
return validStates.get(0);
125+
}
126+
86127
if (validStatesCache != null) {
87128
return validStatesCache.get(0);
88129
}

src/main/java/org/dimdev/vanillafix/blockstates/mixins/MixinExtendedBlockState.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ protected BlockStateContainer.StateImplementation createState(Block block, Immut
2929

3030
@Override
3131
protected IBlockState createState(ImmutableMap<IProperty<?>, Comparable<?>> properties, @Nullable ImmutableMap<IUnlistedProperty<?>, Optional<?>> unlistedProperties) {
32+
if (getClass() != MixinExtendedBlockState.class) {
33+
return createState(getBlock(), properties, unlistedProperties);
34+
}
35+
3236
IBlockState normalState = super.createState(properties, unlistedProperties);
3337
if (unlistedProperties == null || unlistedProperties.isEmpty()) {
3438
return normalState;
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package org.dimdev.vanillafix.textures.mixins.client;
2+
3+
import net.minecraft.block.state.IBlockState;
4+
import net.minecraft.client.renderer.BlockModelRenderer;
5+
import net.minecraft.client.renderer.BufferBuilder;
6+
import net.minecraft.client.renderer.block.model.BakedQuad;
7+
import net.minecraft.client.renderer.chunk.CompiledChunk;
8+
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
9+
import net.minecraft.util.math.BlockPos;
10+
import net.minecraft.world.IBlockAccess;
11+
import net.optifine.render.RenderEnv;
12+
import org.dimdev.vanillafix.textures.IPatchedCompiledChunk;
13+
import org.dimdev.vanillafix.textures.IPatchedTextureAtlasSprite;
14+
import org.dimdev.vanillafix.textures.TemporaryStorage;
15+
import org.spongepowered.asm.mixin.Mixin;
16+
import org.spongepowered.asm.mixin.injection.At;
17+
import org.spongepowered.asm.mixin.injection.Inject;
18+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
19+
20+
import java.util.List;
21+
import java.util.Set;
22+
23+
@Mixin(BlockModelRenderer.class)
24+
public class MixinBlockModelRendererOptifine {
25+
@Inject(method = "renderQuadsSmooth", remap = false, at = @At("HEAD"))
26+
private void onRenderQuadsSmooth(IBlockAccess blockAccess, IBlockState state, BlockPos pos, BufferBuilder buffer, List<BakedQuad> quads, RenderEnv renderEnv, CallbackInfo ci) {
27+
markQuads(quads);
28+
}
29+
30+
@Inject(method = "renderQuadsFlat", remap = false, at = @At("HEAD"))
31+
private void onRenderQuadsFlat(IBlockAccess blockAccess, IBlockState state, BlockPos pos, int brightness, boolean ownBrightness, BufferBuilder buffer, List<BakedQuad> quads, RenderEnv renderEnv, CallbackInfo ci) {
32+
markQuads(quads);
33+
}
34+
35+
private static void markQuads(List<BakedQuad> quads) {
36+
CompiledChunk compiledChunk = TemporaryStorage.currentCompiledChunk.get();
37+
if (compiledChunk != null) {
38+
Set<TextureAtlasSprite> visibleTextures = ((IPatchedCompiledChunk) compiledChunk).getVisibleTextures();
39+
40+
for (BakedQuad quad : quads) {
41+
if (quad.getSprite() != null) {
42+
visibleTextures.add(quad.getSprite());
43+
}
44+
}
45+
} else {
46+
// Called from non-chunk render thread. Unfortunately, the best we can do
47+
// is assume it's only going to be used once:
48+
for (BakedQuad quad : quads) {
49+
if (quad.getSprite() != null) {
50+
((IPatchedTextureAtlasSprite) quad.getSprite()).markNeedsAnimationUpdate();
51+
}
52+
}
53+
}
54+
}
55+
}

src/main/resources/META-INF/vanillafix_at.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,6 @@ public net.minecraft.client.renderer.texture.TextureAtlasSprite <init>(Ljava/lan
4141

4242
# dynamicresources.MixinGlStateManager
4343
public net.minecraft.client.renderer.GlStateManager$TextureState
44+
45+
# blockstates.MixinBlockStateContainer
46+
public net.minecraft.block.state.BlockStateContainer$StateImplementation <init>(Lnet/minecraft/block/Block;Lcom/google/common/collect/ImmutableMap;)V
-18.7 KB
Binary file not shown.

src/main/resources/mixins.vanillafix.textures.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
"client.MixinTextureMap",
1818
"client.MixinRender",
1919
"client.MixinTextureAtlasSprite",
20-
"client.MixinForgeBlockModelRenderer"
20+
"client.MixinForgeBlockModelRenderer",
21+
"client.MixinBlockModelRendererOptifine"
2122
],
2223
"injectors": {
2324
"maxShiftBy": 10

0 commit comments

Comments
 (0)