Skip to content

Commit

Permalink
Merge pull request #13 from GTNewHorizons/add_gt_weapon_compat
Browse files Browse the repository at this point in the history
Add GT weapon compatibility ...
  • Loading branch information
Dream-Master authored Sep 22, 2022
2 parents 1a66899 + 663febf commit 1319aae
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions src/main/java/mods/battlegear2/api/core/BattlegearUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import net.minecraftforge.event.entity.player.AttackEntityEvent;
import net.minecraftforge.event.entity.player.EntityInteractEvent;
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.oredict.OreDictionary;

import java.io.Closeable;
import java.io.IOException;
Expand Down Expand Up @@ -134,6 +135,8 @@ else if(main == prevNotWieldable)//Prevent lag from check spam
return false;
else if(WeaponRegistry.isWeapon(main))//Registered as such
return true;
else if(checkWeaponOreDictEntries(main))
return true;
else if(!checkForRightClickFunction(main)){//Make sure there are no special functions for offhand/mainhand weapons
WeaponRegistry.addDualWeapon(main);//register so as not to make that costly check again
return true;
Expand All @@ -142,6 +145,29 @@ else if(!checkForRightClickFunction(main)){//Make sure there are no special func
return false;
}

/**
* Checks if an item is a GT weapon based on OreDict entries
* @param main the item to check
* @return true if the item is a GT weapon
*/
public static boolean checkWeaponOreDictEntries(ItemStack main)
{
int[] oreDictEntries = OreDictionary.getOreIDs(main);

for(int i = 0; i < oreDictEntries.length; i++)
{
int ore = oreDictEntries[i];
String name = OreDictionary.getOreName(ore);

if(name.equals("craftingToolBlade") || name.equals("craftingToolAxe")) // craftingToolPickaxe?
{
return true;
}
}

return false;
}

/**
* @deprecated see below
*/
Expand All @@ -155,7 +181,7 @@ else if(main.getItem() instanceof IArrowContainer2)//A quiver
else if(usagePriorAttack(main))//"Usable" item
return off == null || !usagePriorAttack(off);//With empty hand or non "usable item"
else if(isWeapon(main))//A generic weapon
return main.getAttributeModifiers().containsKey(genericAttack) || WeaponRegistry.isMainHand(main);//With either generic attack, or registered
return checkWeaponOreDictEntries(main) || main.getAttributeModifiers().containsKey(genericAttack) || WeaponRegistry.isMainHand(main);//With either generic attack, or registered
return false;
}

Expand All @@ -177,7 +203,7 @@ else if(main.getItem() instanceof IArrowContainer2)//A quiver
else if(usagePriorAttack(main, wielder, false))//"Usable" item
return off == null || !usagePriorAttack(off, wielder, true);//With empty hand or non "usable item"
else if(isWeapon(main))//A generic weapon
return main.getAttributeModifiers().containsKey(genericAttack) || WeaponRegistry.isMainHand(main);//With either generic attack, or registered
return checkWeaponOreDictEntries(main) || main.getAttributeModifiers().containsKey(genericAttack) || WeaponRegistry.isMainHand(main);//With either generic attack, or registered
return false;
}

Expand All @@ -192,7 +218,7 @@ else if(off.getItem() instanceof IOffhandDual)//An item using the API
else if(off.getItem() instanceof IShield || off.getItem() instanceof IArrowContainer2 || usagePriorAttack(off))//Shield, Quiver, or "usable"
return true;//always
else if(isWeapon(off))//A generic weapon
return off.getAttributeModifiers().containsKey(genericAttack) || WeaponRegistry.isOffHand(off);//with a generic attack or registered
return checkWeaponOreDictEntries(off) || off.getAttributeModifiers().containsKey(genericAttack) || WeaponRegistry.isOffHand(off);//with a generic attack or registered
return false;
}

Expand All @@ -212,7 +238,7 @@ else if(off.getItem() instanceof IOffhandWield)//An item using the API
else if(off.getItem() instanceof IShield || off.getItem() instanceof IArrowContainer2 || usagePriorAttack(off, wielder, true))//Shield, Quiver, or "usable"
return true;//always
else if(isWeapon(off))//A generic weapon
return off.getAttributeModifiers().containsKey(genericAttack) || WeaponRegistry.isOffHand(off);//with a generic attack or registered
return checkWeaponOreDictEntries(off) || off.getAttributeModifiers().containsKey(genericAttack) || WeaponRegistry.isOffHand(off);//with a generic attack or registered
return false;
}

Expand Down

0 comments on commit 1319aae

Please sign in to comment.