Battlegear 2 for Backhand compat (#178)

This commit is contained in:
Yannick Marcotte-Gourde authored and GitHub committed 2025-05-30 20:38:29 -04:00
1 parent 985e5fa714
commit cddcb7a959
3 files changed
+27 -6

No files matched your search

@@ -0,0 +1,17 @@
package tconstruct.compat;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import mods.battlegear2.api.core.IInventoryPlayerBattle;
/**
* This class exists to isolate classes that exist in Battlegear 2 but not in Battlegear 2 for Backhand in order to
* avoid class loading exceptions.
*/
public class Battlegear2Compat {
public static ItemStack getBattlegear2Offhand(EntityPlayer player) {
return ((IInventoryPlayerBattle) player.inventory).battlegear2$getCurrentOffhandWeapon();
}
}
@@ -13,7 +13,8 @@ import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import cpw.mods.fml.common.Loader;
import mods.battlegear2.api.core.IInventoryPlayerBattle;
import mods.battlegear2.api.core.IBattlePlayer;
import tconstruct.compat.Battlegear2Compat;
import tconstruct.library.TConstructRegistry;
import tconstruct.library.crafting.ToolBuilder;
import tconstruct.library.tools.BowstringMaterial;
@@ -62,8 +63,9 @@ public abstract class BowBaseAmmo extends ProjectileWeapon {
@Override
public ItemStack searchForAmmo(EntityPlayer player, ItemStack weapon) {
// arrow priority: hotbar > inventory, tinker arrows > regular arrows
if (isBattlegear2Loaded) {
ItemStack offhand = ((IInventoryPlayerBattle) player.inventory).battlegear2$getCurrentOffhandWeapon();
if (isBattlegear2Loaded && player instanceof IBattlePlayer battlePlayer
&& battlePlayer.battlegear2$isBattlemode()) {
ItemStack offhand = Battlegear2Compat.getBattlegear2Offhand(player);
if (checkTinkerArrow(offhand) || checkVanillaArrow(offhand)) {
return offhand;
}
@@ -12,7 +12,8 @@ import net.minecraft.util.IIcon;
import net.minecraft.world.World;
import cpw.mods.fml.common.Loader;
import mods.battlegear2.api.core.IInventoryPlayerBattle;
import mods.battlegear2.api.core.IBattlePlayer;
import tconstruct.compat.Battlegear2Compat;
import tconstruct.library.TConstructRegistry;
import tconstruct.library.crafting.ToolBuilder;
import tconstruct.library.tools.AbilityHelper;
@@ -224,8 +225,9 @@ public class Crossbow extends ProjectileWeapon {
@Override
public ItemStack searchForAmmo(EntityPlayer player, ItemStack weapon) {
// arrow priority: hotbar > inventory, tinker arrows > regular arrows
if (isBattlegear2Loaded) {
ItemStack offhand = ((IInventoryPlayerBattle) player.inventory).battlegear2$getCurrentOffhandWeapon();
if (isBattlegear2Loaded && player instanceof IBattlePlayer battlePlayer
&& battlePlayer.battlegear2$isBattlemode()) {
ItemStack offhand = Battlegear2Compat.getBattlegear2Offhand(player);
if (offhand != null && (offhand.getItem() instanceof BoltAmmo)
&& ((IAmmo) offhand.getItem()).getAmmoCount(offhand) > 0) {
return offhand;