mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-27 23:45:57 +00:00
Added cross version proxies
This commit is contained in:
4 files changed
+153
No files matched your search
@@ -39,6 +39,7 @@ import org.apache.logging.log4j.Logger;
|
||||
import vazkii.botania.common.core.handler.IMCHandler;
|
||||
import vazkii.botania.common.core.handler.ManaNetworkHandler;
|
||||
import vazkii.botania.common.core.proxy.CommonProxy;
|
||||
import vazkii.botania.common.core.proxy.ICrossVersionProxy;
|
||||
import vazkii.botania.common.lib.LibMisc;
|
||||
|
||||
@Mod(modid = LibMisc.MOD_ID, name = LibMisc.MOD_NAME, version = LibMisc.VERSION, dependencies = LibMisc.DEPENDENCIES,
|
||||
@@ -62,10 +63,24 @@ public class Botania {
|
||||
@SidedProxy(serverSide = LibMisc.PROXY_COMMON, clientSide = LibMisc.PROXY_CLIENT)
|
||||
public static CommonProxy proxy;
|
||||
|
||||
public static ICrossVersionProxy crossVersionProxy;
|
||||
|
||||
public static final Logger LOGGER = LogManager.getLogger(LibMisc.MOD_ID);
|
||||
|
||||
@EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event) {
|
||||
try {
|
||||
if ("1.10".equals(Loader.MC_VERSION)) {
|
||||
crossVersionProxy = (ICrossVersionProxy) Class.forName("vazkii.botania.common.core.proxy.CrossVersionProxy_110").newInstance();
|
||||
} else if ("1.9.4".equals(Loader.MC_VERSION)) {
|
||||
crossVersionProxy = (ICrossVersionProxy) Class.forName("vazkii.botania.common.core.proxy.CrossVersionProxy_19").newInstance();
|
||||
} else {
|
||||
throw new IllegalStateException("Botania couldn't find a cross version proxy!");
|
||||
}
|
||||
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException ex) {
|
||||
throw new IllegalStateException("Botania couldn't find a cross version proxy!", ex);
|
||||
}
|
||||
|
||||
gardenOfGlassLoaded = Loader.isModLoaded("GardenOfGlass");
|
||||
|
||||
thaumcraftLoaded = Loader.isModLoaded("Thaumcraft");
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
package vazkii.botania.common.core.proxy;
|
||||
|
||||
import net.minecraft.client.multiplayer.PlayerControllerMP;
|
||||
import net.minecraft.entity.monster.EntitySkeleton;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.ReflectionHelper;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import vazkii.botania.client.core.handler.BotaniaPlayerController;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class CrossVersionProxy_110 implements ICrossVersionProxy {
|
||||
@Override
|
||||
public TileEntity createTeFromCompound(World world, NBTTagCompound compound) {
|
||||
Method m = ReflectionHelper.findMethod(TileEntity.class, null, new String[] { "func_190200_a", "a" }, World.class, NBTTagCompound.class);
|
||||
try {
|
||||
return (TileEntity) m.invoke(null, world, compound);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void copyGameType(PlayerControllerMP from, BotaniaPlayerController to) {
|
||||
try {
|
||||
Class<?> gameTypeClazz = Class.forName("net.minecraft.world.GameType");
|
||||
Object gameType = from.getCurrentGameType();
|
||||
Method m = ReflectionHelper.findMethod(PlayerControllerMP.class, null, new String[]{ "setGameType", "func_78746_a", "a" }, gameTypeClazz);
|
||||
m.invoke(to, gameType);
|
||||
} catch (IllegalAccessException | InvocationTargetException | ClassNotFoundException ignored) {}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSkeletonTypeInt(EntitySkeleton skeleton) {
|
||||
try {
|
||||
Method m = ReflectionHelper.findMethod(EntitySkeleton.class, null, new String[] { "func_189771_df", "df" });
|
||||
Enum e = (Enum) m.invoke(skeleton);
|
||||
return e.ordinal();
|
||||
} catch (IllegalAccessException | InvocationTargetException e1) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSkeletonTypeInt(EntitySkeleton skeleton, int type) {
|
||||
try {
|
||||
Class skeletonTypeClazz = Class.forName("net.minecraft.entity.monster.SkeletonType");
|
||||
Object typeToSet = skeletonTypeClazz.getEnumConstants()[type];
|
||||
Method m = ReflectionHelper.findMethod(EntitySkeleton.class, null, new String[] { "func_189768_a", "a" }, skeletonTypeClazz);
|
||||
m.invoke(skeleton, typeToSet);
|
||||
} catch (IllegalAccessException | InvocationTargetException | ClassNotFoundException e) {}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package vazkii.botania.common.core.proxy;
|
||||
|
||||
import net.minecraft.client.multiplayer.PlayerControllerMP;
|
||||
import net.minecraft.entity.monster.EntitySkeleton;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.ReflectionHelper;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import vazkii.botania.client.core.handler.BotaniaPlayerController;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class CrossVersionProxy_19 implements ICrossVersionProxy {
|
||||
@Override
|
||||
public TileEntity createTeFromCompound(World world, NBTTagCompound compound) {
|
||||
Method m = ReflectionHelper.findMethod(TileEntity.class, null, new String[] { "create", "func_189514_c", "c" }, NBTTagCompound.class);
|
||||
try {
|
||||
return (TileEntity) m.invoke(null, compound);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void copyGameType(PlayerControllerMP from, BotaniaPlayerController to) {
|
||||
try {
|
||||
Class<?> gameTypeClazz = Class.forName("net.minecraft.world.WorldSettings.GameType");
|
||||
Object gameType = from.getCurrentGameType();
|
||||
Method m = ReflectionHelper.findMethod(PlayerControllerMP.class, null, new String[]{ "setGameType", "func_78746_a", "a" }, gameTypeClazz);
|
||||
m.invoke(to, gameType);
|
||||
} catch (IllegalAccessException | InvocationTargetException | ClassNotFoundException ignored) {}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSkeletonTypeInt(EntitySkeleton skeleton) {
|
||||
try {
|
||||
Method m = ReflectionHelper.findMethod(EntitySkeleton.class, null, new String[]{ "getSkeletonType", "func_82202_m", "db" });
|
||||
return (int) m.invoke(skeleton);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSkeletonTypeInt(EntitySkeleton skeleton, int type) {
|
||||
try {
|
||||
Method m = ReflectionHelper.findMethod(EntitySkeleton.class, null, new String[]{ "setSkeletonType", "func_82201_a", "a" }, int.class);
|
||||
m.invoke(skeleton, type);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package vazkii.botania.common.core.proxy;
|
||||
|
||||
import net.minecraft.client.multiplayer.PlayerControllerMP;
|
||||
import net.minecraft.entity.monster.EntitySkeleton;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import vazkii.botania.client.core.handler.BotaniaPlayerController;
|
||||
|
||||
// horrible hax to try to run 1.9/10 from the same jar :D
|
||||
// Taking this as an example is heavily discouraged
|
||||
public interface ICrossVersionProxy {
|
||||
|
||||
TileEntity createTeFromCompound(World world, NBTTagCompound compound);
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
void copyGameType(PlayerControllerMP from, BotaniaPlayerController to);
|
||||
|
||||
int getSkeletonTypeInt(EntitySkeleton skeleton);
|
||||
|
||||
void setSkeletonTypeInt(EntitySkeleton skeleton, int type);
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user