mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-19 03:39:17 +00:00
Fix something in bows not being cross proxied. Closes #398
This commit is contained in:
4 files changed
+57
-7
No files matched your search
@@ -2,13 +2,16 @@ package vazkii.botania.common.core.proxy;
|
||||
|
||||
import net.minecraft.client.multiplayer.PlayerControllerMP;
|
||||
import net.minecraft.entity.monster.EntitySkeleton;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.server.management.PlayerInteractionManager;
|
||||
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 vazkii.botania.common.Botania;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
@@ -16,10 +19,11 @@ 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);
|
||||
Method m = ReflectionHelper.findMethod(TileEntity.class, null, new String[] { "create", "func_190200_a", "a" }, World.class, NBTTagCompound.class);
|
||||
try {
|
||||
return (TileEntity) m.invoke(null, world, compound);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
Botania.LOGGER.error("Couldn't create TE in 1.10 crossversion proxy");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -33,7 +37,9 @@ public class CrossVersionProxy_110 implements ICrossVersionProxy {
|
||||
Object gameType = m.invoke(from);
|
||||
m = ReflectionHelper.findMethod(PlayerControllerMP.class, null, new String[]{ "setGameType", "func_78746_a", "a" }, gameTypeClazz);
|
||||
m.invoke(to, gameType);
|
||||
} catch (IllegalAccessException | InvocationTargetException | ClassNotFoundException ignored) {}
|
||||
} catch (IllegalAccessException | InvocationTargetException | ClassNotFoundException ignored) {
|
||||
Botania.LOGGER.error("Couldn't copy gametype in 1.10 crossversion proxy");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -43,6 +49,7 @@ public class CrossVersionProxy_110 implements ICrossVersionProxy {
|
||||
Enum e = (Enum) m.invoke(skeleton);
|
||||
return e.ordinal();
|
||||
} catch (IllegalAccessException | InvocationTargetException e1) {
|
||||
Botania.LOGGER.error("Couldn't get skeleton type in 1.10 crossversion proxy");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -54,6 +61,22 @@ public class CrossVersionProxy_110 implements ICrossVersionProxy {
|
||||
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) {}
|
||||
} catch (IllegalAccessException | InvocationTargetException | ClassNotFoundException e) {
|
||||
Botania.LOGGER.error("Couldn't set skeleton type in 1.10 crossversion proxy");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSurvivalOrAdventure(EntityPlayerMP playerMP) {
|
||||
try {
|
||||
Class gameTypeClazz = Class.forName("net.minecraft.world.GameType");
|
||||
Method m = ReflectionHelper.findMethod(PlayerInteractionManager.class, null, new String[] { "getGameType", "func_73081_b", "b" });
|
||||
Object gameType = m.invoke(playerMP.interactionManager);
|
||||
m = ReflectionHelper.findMethod(gameTypeClazz, null, new String[] { "isSurvivalOrAdventure", "func_77144_e", "e" });
|
||||
return (Boolean) m.invoke(gameType);
|
||||
} catch (IllegalAccessException | InvocationTargetException | ClassNotFoundException ignored) {
|
||||
Botania.LOGGER.error("Couldn't determine survival or adventure in 1.10 crossversion proxy");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,13 +2,16 @@ package vazkii.botania.common.core.proxy;
|
||||
|
||||
import net.minecraft.client.multiplayer.PlayerControllerMP;
|
||||
import net.minecraft.entity.monster.EntitySkeleton;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.server.management.PlayerInteractionManager;
|
||||
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 vazkii.botania.common.Botania;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
@@ -20,6 +23,7 @@ public class CrossVersionProxy_19 implements ICrossVersionProxy {
|
||||
try {
|
||||
return (TileEntity) m.invoke(null, compound);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
Botania.LOGGER.error("Couldn't create TE in 1.9 crossversion proxy");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -28,12 +32,14 @@ public class CrossVersionProxy_19 implements ICrossVersionProxy {
|
||||
@Override
|
||||
public void copyGameType(PlayerControllerMP from, BotaniaPlayerController to) {
|
||||
try {
|
||||
Class<?> gameTypeClazz = Class.forName("net.minecraft.world.WorldSettings.GameType");
|
||||
Class<?> gameTypeClazz = Class.forName("net.minecraft.world.WorldSettings$GameType");
|
||||
Method m = ReflectionHelper.findMethod(PlayerControllerMP.class, null, new String[]{ "getCurrentGameType", "func_178889_l", "l" });
|
||||
Object gameType = m.invoke(from);
|
||||
m = ReflectionHelper.findMethod(PlayerControllerMP.class, null, new String[]{ "setGameType", "func_78746_a", "a" }, gameTypeClazz);
|
||||
m.invoke(to, gameType);
|
||||
} catch (IllegalAccessException | InvocationTargetException | ClassNotFoundException ignored) {}
|
||||
} catch (IllegalAccessException | InvocationTargetException | ClassNotFoundException ignored) {
|
||||
Botania.LOGGER.error("Couldn't copy game type in 1.9 crossversion proxy");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -42,6 +48,7 @@ public class CrossVersionProxy_19 implements ICrossVersionProxy {
|
||||
Method m = ReflectionHelper.findMethod(EntitySkeleton.class, null, new String[]{ "getSkeletonType", "func_82202_m", "db" });
|
||||
return (int) m.invoke(skeleton);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
Botania.LOGGER.error("Couldn't get skeleton type in 1.9 crossversion proxy");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -51,6 +58,22 @@ public class CrossVersionProxy_19 implements ICrossVersionProxy {
|
||||
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) {}
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
Botania.LOGGER.error("Couldn't set skeleton type in 1.9 crossversion proxy");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSurvivalOrAdventure(EntityPlayerMP playerMP) {
|
||||
try {
|
||||
Class gameTypeClazz = Class.forName("net.minecraft.world.WorldSettings$GameType");
|
||||
Method m = ReflectionHelper.findMethod(PlayerInteractionManager.class, null, new String[] { "getGameType", "func_73081_b", "b" });
|
||||
Object gameType = m.invoke(playerMP.interactionManager);
|
||||
m = ReflectionHelper.findMethod(gameTypeClazz, null, new String[] { "isSurvivalOrAdventure", "func_77144_e", "e" });
|
||||
return (Boolean) m.invoke(gameType);
|
||||
} catch (IllegalAccessException | InvocationTargetException | ClassNotFoundException ignored) {
|
||||
Botania.LOGGER.error("Couldn't determine survival or adventure in 1.9 crossversion proxy");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package vazkii.botania.common.core.proxy;
|
||||
|
||||
import net.minecraft.client.multiplayer.PlayerControllerMP;
|
||||
import net.minecraft.entity.monster.EntitySkeleton;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
@@ -22,4 +23,6 @@ public interface ICrossVersionProxy {
|
||||
|
||||
void setSkeletonTypeInt(EntitySkeleton skeleton, int type);
|
||||
|
||||
boolean isSurvivalOrAdventure(EntityPlayerMP playerMP);
|
||||
|
||||
}
|
||||
@@ -37,6 +37,7 @@ import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
import vazkii.botania.api.mana.IManaUsingItem;
|
||||
import vazkii.botania.api.mana.ManaItemHandler;
|
||||
import vazkii.botania.client.lib.LibResources;
|
||||
import vazkii.botania.common.Botania;
|
||||
import vazkii.botania.common.core.BotaniaCreativeTab;
|
||||
import vazkii.botania.common.core.helper.PlayerHelper;
|
||||
import vazkii.botania.common.item.ModItems;
|
||||
@@ -194,7 +195,7 @@ public class ItemLivingwoodBow extends ItemBow implements IManaUsingItem {
|
||||
void onFire(ItemStack bow, EntityLivingBase living, boolean infinity, EntityArrow arrow) {
|
||||
if(living instanceof EntityPlayerMP) {
|
||||
ToolCommons.damageItem(bow, 1, living, MANA_PER_DAMAGE);
|
||||
if(((EntityPlayerMP) living).interactionManager.getGameType().isSurvivalOrAdventure())
|
||||
if(Botania.crossVersionProxy.isSurvivalOrAdventure((EntityPlayerMP) living))
|
||||
PlayerHelper.consumeAmmo(((EntityPlayerMP) living), AMMO_FUNC);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user