From d696ad50c3ca36ec096c1ee8fd9a39679c63e0bd Mon Sep 17 00:00:00 2001 From: Alexdoru <57050655+Alexdoru@users.noreply.github.com> Date: Sat, 14 Oct 2023 20:38:39 +0200 Subject: [PATCH] use updated battlegear2 api (#99) * use updated battlegear2 api * Update dependencies.gradle --------- Co-authored-by: Martin Robertz --- dependencies.gradle | 3 +-- .../java/tconstruct/library/weaponry/AmmoWeapon.java | 4 ++-- .../java/tconstruct/library/weaponry/BowBaseAmmo.java | 10 ++++++---- .../tconstruct/library/weaponry/ProjectileWeapon.java | 4 ++-- .../java/tconstruct/weaponry/weapons/Crossbow.java | 8 +++++--- 5 files changed, 16 insertions(+), 13 deletions(-) diff --git a/dependencies.gradle b/dependencies.gradle index 94eae2d1..5bbf4eeb 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -7,8 +7,7 @@ dependencies { compileOnlyApi("curse.maven:cofh-core-69162:2388751") compileOnly("com.github.GTNewHorizons:inventory-tweaks:1.5.16:api") compileOnly("com.github.GTNewHorizons:waila:1.6.0:api") - compileOnly("com.github.GTNewHorizons:Battlegear2:1.2.1:api") { - transitive = false + compileOnly("com.github.GTNewHorizons:Battlegear2:1.2.4:api") { } compileOnly("curse.maven:minefactory-reloaded-66672:2366150") compileOnly("curse.maven:zelda-sword-skills-220540:2384889") diff --git a/src/main/java/tconstruct/library/weaponry/AmmoWeapon.java b/src/main/java/tconstruct/library/weaponry/AmmoWeapon.java index 7267616c..06fb60ca 100644 --- a/src/main/java/tconstruct/library/weaponry/AmmoWeapon.java +++ b/src/main/java/tconstruct/library/weaponry/AmmoWeapon.java @@ -15,11 +15,11 @@ import mods.battlegear2.api.weapons.IBattlegearWeapon; import tconstruct.tools.TinkerTools; import tconstruct.weaponry.client.CrosshairType; -@Optional.InterfaceList({ - @Optional.Interface(modid = "battlegear2", iface = "mods.battlegear2.api.weapons.IBattlegearWeapon") }) /** * Throwing weapons that utilize the ammo system on themselves. Throwing knifes etc. */ +@Optional.InterfaceList({ + @Optional.Interface(modid = "battlegear2", iface = "mods.battlegear2.api.weapons.IBattlegearWeapon") }) public abstract class AmmoWeapon extends AmmoItem implements IBattlegearWeapon, IAccuracy, IWindup { public AmmoWeapon(int baseDamage, String name) { diff --git a/src/main/java/tconstruct/library/weaponry/BowBaseAmmo.java b/src/main/java/tconstruct/library/weaponry/BowBaseAmmo.java index 20ea7d45..d234389b 100644 --- a/src/main/java/tconstruct/library/weaponry/BowBaseAmmo.java +++ b/src/main/java/tconstruct/library/weaponry/BowBaseAmmo.java @@ -13,7 +13,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.world.World; import cpw.mods.fml.common.Loader; -import mods.battlegear2.api.core.InventoryPlayerBattle; +import mods.battlegear2.api.core.IInventoryPlayerBattle; import tconstruct.library.TConstructRegistry; import tconstruct.library.crafting.ToolBuilder; import tconstruct.library.tools.BowstringMaterial; @@ -23,6 +23,8 @@ import tconstruct.weaponry.entity.ArrowEntity; public abstract class BowBaseAmmo extends ProjectileWeapon { + private static final boolean isBattlegear2Loaded = Loader.isModLoaded("battlegear2"); + public BowBaseAmmo(int baseDamage, String name) { super(baseDamage, name); } @@ -60,9 +62,9 @@ public abstract class BowBaseAmmo extends ProjectileWeapon { @Override public ItemStack searchForAmmo(EntityPlayer player, ItemStack weapon) { // arrow priority: hotbar > inventory, tinker arrows > regular arrows - if (Loader.isModLoaded("battlegear2")) { - ItemStack offhand = ((InventoryPlayerBattle) player.inventory).getCurrentOffhandWeapon(); - if (offhand != null && (checkTinkerArrow(offhand) || checkVanillaArrow(offhand))) { + if (isBattlegear2Loaded) { + ItemStack offhand = ((IInventoryPlayerBattle) player.inventory).battlegear2$getCurrentOffhandWeapon(); + if (checkTinkerArrow(offhand) || checkVanillaArrow(offhand)) { return offhand; } } diff --git a/src/main/java/tconstruct/library/weaponry/ProjectileWeapon.java b/src/main/java/tconstruct/library/weaponry/ProjectileWeapon.java index c27aa4ee..38b6eb8a 100644 --- a/src/main/java/tconstruct/library/weaponry/ProjectileWeapon.java +++ b/src/main/java/tconstruct/library/weaponry/ProjectileWeapon.java @@ -32,11 +32,11 @@ import tconstruct.tools.TinkerTools; import tconstruct.weaponry.TinkerWeaponry; import tconstruct.weaponry.client.CrosshairType; -@Optional.InterfaceList({ - @Optional.Interface(modid = "battlegear2", iface = "mods.battlegear2.api.weapons.IBattlegearWeapon") }) /** * Weapons that utilize ammo that uses the ammo system to shoot projectiles. Bows,... */ +@Optional.InterfaceList({ + @Optional.Interface(modid = "battlegear2", iface = "mods.battlegear2.api.weapons.IBattlegearWeapon") }) public abstract class ProjectileWeapon extends ToolCore implements IBattlegearWeapon, IAccuracy, IWindup { public ProjectileWeapon(int baseDamage, String name) { diff --git a/src/main/java/tconstruct/weaponry/weapons/Crossbow.java b/src/main/java/tconstruct/weaponry/weapons/Crossbow.java index e4322fc1..2f41184c 100644 --- a/src/main/java/tconstruct/weaponry/weapons/Crossbow.java +++ b/src/main/java/tconstruct/weaponry/weapons/Crossbow.java @@ -12,7 +12,7 @@ import net.minecraft.util.IIcon; import net.minecraft.world.World; import cpw.mods.fml.common.Loader; -import mods.battlegear2.api.core.InventoryPlayerBattle; +import mods.battlegear2.api.core.IInventoryPlayerBattle; import tconstruct.library.TConstructRegistry; import tconstruct.library.crafting.ToolBuilder; import tconstruct.library.tools.AbilityHelper; @@ -27,6 +27,8 @@ import tconstruct.weaponry.entity.BoltEntity; public class Crossbow extends ProjectileWeapon { + private static final boolean isBattlegear2Loaded = Loader.isModLoaded("battlegear2"); + public Crossbow() { super(0, "Crossbow"); this.setMaxDamage(100); @@ -218,8 +220,8 @@ public class Crossbow extends ProjectileWeapon { @Override public ItemStack searchForAmmo(EntityPlayer player, ItemStack weapon) { // arrow priority: hotbar > inventory, tinker arrows > regular arrows - if (Loader.isModLoaded("battlegear2")) { - ItemStack offhand = ((InventoryPlayerBattle) player.inventory).getCurrentOffhandWeapon(); + if (isBattlegear2Loaded) { + ItemStack offhand = ((IInventoryPlayerBattle) player.inventory).battlegear2$getCurrentOffhandWeapon(); if (offhand != null && (offhand.getItem() instanceof BoltAmmo) && ((IAmmo) offhand.getItem()).getAmmoCount(offhand) > 0) { return offhand;