Skip to content

Commit

Permalink
Fabric: Make FastMap state holders "compatible" with Hydrogen
Browse files Browse the repository at this point in the history
Implicitely fixes #7
  • Loading branch information
malte0811 committed Mar 28, 2021
1 parent 955d2f2 commit 99fb471
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
import org.spongepowered.asm.service.MixinService;

import javax.annotation.Nullable;
import java.io.IOException;
import java.util.List;
import java.util.Set;

public abstract class FerriteMixinConfig implements IMixinConfigPlugin {
private static final Logger LOGGER = LogManager.getLogger("ferritecore-mixin");
private static final boolean HAS_HYDROGEN;
protected static final Logger LOGGER = LogManager.getLogger("ferritecore-mixin");
protected static final boolean HAS_HYDROGEN;
private String prefix = null;
@Nullable
private final FerriteConfig.Option enableOption;
private final boolean disableWithHydrogen;

Expand All @@ -32,16 +34,15 @@ public abstract class FerriteMixinConfig implements IMixinConfigPlugin {
HAS_HYDROGEN = hasHydrogen;
}

protected FerriteMixinConfig(FerriteConfig.Option enableOption, boolean disableWithHydrogen) {
protected FerriteMixinConfig(@Nullable FerriteConfig.Option enableOption, boolean disableWithHydrogen) {
this.enableOption = enableOption;
this.disableWithHydrogen = disableWithHydrogen;
}

@Override
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
Preconditions.checkState(mixinClassName.startsWith(prefix), "Unexpected prefix on " + mixinClassName);
final String name = mixinClassName.substring(prefix.length());
if (!enableOption.isEnabled()) {
if (enableOption != null && !enableOption.isEnabled()) {
LOGGER.warn("Mixin " + mixinClassName + " is disabled by config");
return false;
} else if (HAS_HYDROGEN && disableWithHydrogen) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

public class Config extends FerriteMixinConfig {
public Config() {
// TODO make compatible
super(FerriteConfig.NEIGHBOR_LOOKUP, true);
super(FerriteConfig.NEIGHBOR_LOOKUP, false);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package malte0811.ferritecore.mixin.fabric;

import malte0811.ferritecore.mixin.config.FerriteConfig;
import malte0811.ferritecore.mixin.config.FerriteMixinConfig;

import java.util.Collections;
import java.util.List;

public class Config extends FerriteMixinConfig {
public Config() {
super(null, false);
}

@Override
public List<String> getMixins() {
if (HAS_HYDROGEN && FerriteConfig.NEIGHBOR_LOOKUP.isEnabled()) {
LOGGER.warn("Adding Mixin to disable Hydrogen's MixinState#postCreateWithTable");
return Collections.singletonList("HydrogenStateholderMixin");
} else {
return super.getMixins();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package malte0811.ferritecore.mixin.fabric;

import net.minecraft.state.Property;
import net.minecraft.state.StateHolder;
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;

import java.util.Map;

// This mixin is conditionally added by the Mixin config
@SuppressWarnings("UnusedMixin")
@Mixin(value = StateHolder.class, priority = 900)
public class HydrogenStateholderMixin<S> {
/**
* Disable the callback injected by Hydrogen, since it relies on the neighbor table being present, which is not the
* case after this method is called with FASTMAP enabled.<br>
* This is a massive hack, but is currently probably the cleanest approach. If H gets the system for
* disabling Mixins already implemented in Na/Li that system should be used instead!
*/
@Inject(method = "func_235899_a_", at = @At("RETURN"), cancellable = true)
public void postPopulateNeighbors(Map<Map<Property<?>, Comparable<?>>, S> map, CallbackInfo ci) {
ci.cancel();
}
}
1 change: 1 addition & 0 deletions fabric/src/main/resources/ferritecore.fabric.mixin.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
"injectors": {
"defaultRequire": 1
},
"plugin": "malte0811.ferritecore.mixin.fabric.Config",
"minVersion": "0.8"
}

0 comments on commit 99fb471

Please sign in to comment.