Skip to content

Commit

Permalink
TwilightForest fixes and uses proper fixes depending on version
Browse files Browse the repository at this point in the history
- Also added a few logging points for aesthetics
- Will log which TwilightForest mixins the mod is using, should there be an issue
  • Loading branch information
ZombieHDGaming committed Apr 24, 2019
1 parent 58ec790 commit 0d3bb68
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 18 deletions.
4 changes: 4 additions & 0 deletions src/main/java/org/dimdev/jeid/JEID.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.registries.IForgeRegistry;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.dimdev.jeid.network.MessageManager;

import java.util.Random;
Expand All @@ -35,6 +37,8 @@ public class JEID {
public static final Biome errorBiome = new BiomeVoid(new Biome.BiomeProperties("A mod doesn't support extended biome IDs -- report to JEID"))
.setRegistryName("jeid:error_biome");

public static Logger LOGGER = LogManager.getLogger("JustEnoughIDs");

@Mod.EventHandler
public void onPreInit(FMLPreInitializationEvent event) {
// Register messages
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/dimdev/jeid/JEIDLoadingPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ public class JEIDLoadingPlugin implements IFMLLoadingPlugin {

public JEIDLoadingPlugin() {
MixinBootstrap.init();
JEID.LOGGER.info("Initializing JustEnoughIDs core mixins");
Mixins.addConfiguration("mixins.jeid.core.json");
JEID.LOGGER.info("Initializing JustEnoughIDs initialization mixins");
Mixins.addConfiguration("mixins.jeid.init.json");
}

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/dimdev/jeid/mixin/init/MixinLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.ModClassLoader;
import net.minecraftforge.fml.common.ModContainer;
import org.dimdev.jeid.JEID;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.MixinEnvironment;
import org.spongepowered.asm.mixin.Mixins;
Expand Down Expand Up @@ -40,7 +41,9 @@ private void beforeConstructingMods(List<String> injectedModContainers, Callback
}

// Add and reload mixin configs
JEID.LOGGER.info("Initializing JustEnoughIDs modsupport mixins");
Mixins.addConfiguration("mixins.jeid.modsupport.json");
Mixins.addConfiguration("mixins.jeid.twilightforest.json");

Proxy mixinProxy = (Proxy) Launch.classLoader.getTransformers().stream().filter(transformer -> transformer instanceof Proxy).findFirst().get();
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,13 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import twilightforest.biomes.TFBiomes;
import twilightforest.block.BlockTFMagicLogSpecial;

import java.util.Random;

@Pseudo
@Mixin(BlockTFMagicLogSpecial.class)
public class MixinBlockTFMagicLogSpecial {

/**
* For versions upto and including 3.8
*/
@Overwrite(remap = false)
private void sendChangedBiome(World world, BlockPos pos) {
IMessage message = new BiomeChangeMessage(pos.getX(), pos.getZ(), Biome.getIdForBiome(TFBiomes.enchantedForest));
MessageManager.CHANNEL.sendToAllAround(message, new NetworkRegistry.TargetPoint(world.provider.getDimension(), pos.getX(), 128.0D, pos.getZ(), 128.0D));
}

@Inject(method = "doTreeOfTransformationEffect", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/chunk/Chunk;getBiomeArray()[B"), locals = LocalCapture.CAPTURE_FAILSOFT)
private void onChangeBiome(World world, BlockPos pos, Random rand, CallbackInfo ci, int i, BlockPos dPos, Biome biomeAt, Chunk chunkAt) {
((INewChunk) chunkAt).getIntBiomeArray()[(dPos.getZ() & 15) << 4 | (dPos.getX() & 15)] = Biome.getIdForBiome(TFBiomes.enchantedForest);
}

/**
* For versions 3.9 and later
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.dimdev.jeid.mixin.modsupport.twilightforest;

import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.chunk.Chunk;
import net.minecraftforge.fml.common.network.NetworkRegistry;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import org.dimdev.jeid.INewChunk;
import org.dimdev.jeid.network.BiomeChangeMessage;
import org.dimdev.jeid.network.MessageManager;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Pseudo;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import twilightforest.biomes.TFBiomes;
import twilightforest.block.BlockTFMagicLogSpecial;

import java.util.Random;

@Pseudo
@Mixin(BlockTFMagicLogSpecial.class)
public class MixinBlockTFMagicLogSpecial_Old {
/**
* For versions upto and including 3.8
*/
@Overwrite(remap = false)
private void sendChangedBiome(World world, BlockPos pos) {
IMessage message = new BiomeChangeMessage(pos.getX(), pos.getZ(), Biome.getIdForBiome(TFBiomes.enchantedForest));
MessageManager.CHANNEL.sendToAllAround(message, new NetworkRegistry.TargetPoint(world.provider.getDimension(), pos.getX(), 128.0D, pos.getZ(), 128.0D));
}

@Inject(method = "doTreeOfTransformationEffect", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/chunk/Chunk;getBiomeArray()[B"), locals = LocalCapture.CAPTURE_FAILSOFT)
private void onChangeBiome(World world, BlockPos pos, Random rand, CallbackInfo ci, int i, BlockPos dPos, Biome biomeAt, Chunk chunkAt) {
((INewChunk) chunkAt).getIntBiomeArray()[(dPos.getZ() & 15) << 4 | (dPos.getX() & 15)] = Biome.getIdForBiome(TFBiomes.enchantedForest);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package org.dimdev.jeid.mixin.modsupport.twilightforest;

import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.ModContainer;
import org.dimdev.jeid.JEID;
import org.spongepowered.asm.lib.tree.ClassNode;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;

import java.util.List;
import java.util.Set;

public class TwilightMixinPlugin implements IMixinConfigPlugin {
@Override
public void onLoad(String s) {}

@Override
public String getRefMapperConfig() { return null; }

@Override
public boolean shouldApplyMixin(String s, String s1) {
for (ModContainer mod : Loader.instance().getModList()) {
if (mod.getModId().equals("twilightforest")) {
if (s1.equals("org.dimdev.jeid.mixin.modsupport.twilightforest.MixinBlockTFMagicLogSpecial_Old")) {
if (Integer.parseInt(mod.getVersion().split("[.]")[2]) < 689) {
JEID.LOGGER.info("Older TwilightForest version (<689). Using mixin: " + s1);
return true;
} else {
return false;
}
} else if (s1.equals("org.dimdev.jeid.mixin.modsupport.twilightforest.MixinBlockTFMagicLogSpecial")) {
if (Integer.parseInt(mod.getVersion().split("[.]")[2]) > 689) {
JEID.LOGGER.info("Newer TwilightForest version (>689). Using mixin: " + s1);
return true;
} else {
return false;
}
} else {
return true;
}
}
}
return false;
}

@Override
public void acceptTargets(Set<String> set, Set<String> set1) {

}

@Override
public List<String> getMixins() {
return null;
}

@Override
public void preApply(String s, ClassNode classNode, String s1, IMixinInfo iMixinInfo) {

}

@Override
public void postApply(String s, ClassNode classNode, String s1, IMixinInfo iMixinInfo) {

}
}
2 changes: 0 additions & 2 deletions src/main/resources/mixins.jeid.modsupport.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
"tofucraft.MixinGenLayerRiverMix",
"tofucraft.MixinGenLayerTofuVoronoiZoom",
"tropicraft.MixinGenLayerTropiVoronoiZoom",
"twilightforest.MixinBlockTFMagicLogSpecial",
"twilightforest.MixinGenLayerTFRiverMix",
"worldedit.MixinBaseBlock"
],
"client": [],
Expand Down
18 changes: 18 additions & 0 deletions src/main/resources/mixins.jeid.twilightforest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"package": "org.dimdev.jeid.mixin.modsupport.twilightforest",
"plugin": "org.dimdev.jeid.mixin.modsupport.twilightforest.TwilightMixinPlugin",
"required": true,
"refmap": "mixins.jeid.refmap.json",
"target": "@env(DEFAULT)",
"minVersion": "0.6",
"compatibilityLevel": "JAVA_8",
"mixins": [
"MixinBlockTFMagicLogSpecial",
"MixinBlockTFMagicLogSpecial_Old",
"MixinGenLayerTFRiverMix"
],
"client": [],
"injectors": {
"maxShiftBy": 10
}
}

0 comments on commit 0d3bb68

Please sign in to comment.