From aa8dc5d16cb7e570ca8691912fc7a979d763c0f3 Mon Sep 17 00:00:00 2001 From: Vincent Lee Date: Sun, 17 Jul 2016 20:33:56 -0500 Subject: [PATCH] Fix something in bows not being cross proxied. Closes #398 --- .../core/proxy/CrossVersionProxy_110.java | 29 +++++++++++++++++-- .../core/proxy/CrossVersionProxy_19.java | 29 +++++++++++++++++-- .../common/core/proxy/ICrossVersionProxy.java | 3 ++ .../equipment/tool/bow/ItemLivingwoodBow.java | 3 +- 4 files changed, 57 insertions(+), 7 deletions(-) diff --git a/src/main/java/vazkii/botania/common/core/proxy/CrossVersionProxy_110.java b/src/main/java/vazkii/botania/common/core/proxy/CrossVersionProxy_110.java index 17ebd45ac..bf0c8ccde 100644 --- a/src/main/java/vazkii/botania/common/core/proxy/CrossVersionProxy_110.java +++ b/src/main/java/vazkii/botania/common/core/proxy/CrossVersionProxy_110.java @@ -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; + } } } diff --git a/src/main/java/vazkii/botania/common/core/proxy/CrossVersionProxy_19.java b/src/main/java/vazkii/botania/common/core/proxy/CrossVersionProxy_19.java index cccf9d8b5..2b6005a26 100644 --- a/src/main/java/vazkii/botania/common/core/proxy/CrossVersionProxy_19.java +++ b/src/main/java/vazkii/botania/common/core/proxy/CrossVersionProxy_19.java @@ -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; + } } } diff --git a/src/main/java/vazkii/botania/common/core/proxy/ICrossVersionProxy.java b/src/main/java/vazkii/botania/common/core/proxy/ICrossVersionProxy.java index d2f160d4c..ccd24d540 100644 --- a/src/main/java/vazkii/botania/common/core/proxy/ICrossVersionProxy.java +++ b/src/main/java/vazkii/botania/common/core/proxy/ICrossVersionProxy.java @@ -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); + } diff --git a/src/main/java/vazkii/botania/common/item/equipment/tool/bow/ItemLivingwoodBow.java b/src/main/java/vazkii/botania/common/item/equipment/tool/bow/ItemLivingwoodBow.java index 6cc8ad030..dac5b2c5b 100644 --- a/src/main/java/vazkii/botania/common/item/equipment/tool/bow/ItemLivingwoodBow.java +++ b/src/main/java/vazkii/botania/common/item/equipment/tool/bow/ItemLivingwoodBow.java @@ -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); } }