BG Compat

Changelog:
Updated the compat for the changed api
Paladins with hammers and shields, ho!
This commit is contained in:
Zerokyuuni committed 2013-12-06 18:26:57 -05:00
1 parent 2e9969729b
commit f1473dc42f
23 files changed
+302 -164

No files matched your search

+11
View File
@@ -0,0 +1,11 @@
package mods.battlegear2.api;
import net.minecraft.item.ItemStack;
public interface IAllowItem {
/**
* Returns true if the mainhand {@link #ItemStack} allows the offhand {@link #ItemStack} to be placed in the partner offhand slot
*/
public boolean allowOffhand(ItemStack mainhand, ItemStack offhand);
}
+3 -3
View File
@@ -8,20 +8,20 @@ import net.minecraft.nbt.NBTTagCompound;
public interface IDyable {
/**
* Return whether the specified armor ItemStack has a color.
* Return whether the specified ItemStack has a color.
*/
public boolean hasColor(ItemStack par1ItemStack);
/**
* Return the color for the specified armor ItemStack.
* Return the color for the specified ItemStack.
*/
public int getColor(ItemStack par1ItemStack);
public void setColor(ItemStack dyable, int rgb);
/**
* Remove the color from the specified armor ItemStack.
* Remove the color from the specified ItemStack.
*/
public void removeColor(ItemStack par1ItemStack);
@@ -0,0 +1,15 @@
package mods.battlegear2.api;
import mods.battlegear2.enchantments.BaseEnchantment;
import net.minecraft.item.ItemStack;
public interface IEnchantable {
/**
* If a Battlegear {@link #BaseEnchantment} can be applied to this item, given the {@link #ItemStack}
* @param baseEnchantment
* @param stack
* @return
*/
public boolean isEnchantable(BaseEnchantment baseEnchantment, ItemStack stack);
}
@@ -0,0 +1,55 @@
package mods.battlegear2.api;
import cpw.mods.fml.relauncher.Side;
import mods.battlegear2.api.weapons.OffhandAttackEvent;
import net.minecraft.item.ItemStack;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
public interface IOffhandDual {
/**
* Returns true if the item can be dual wielded in the offhand slot
*/
public boolean isOffhandHandDual(ItemStack off);
/**
* Perform any function when the item is held in the offhand and the user right clicks an entity.
* This is generally used to attack an entity with the offhand item. If this is the case the event should
* be canceled to prevent any default right clicking events (Eg Villager Trading)
*
* @param event the OffhandAttackEvent that was generated
* @param mainhandItem the ItemStack currently being held in the right hand
* @param offhandItem the ItemStack currently being held in the left hand
* @return true if the off hand swing animation should be performed
*/
public boolean offhandAttackEntity(OffhandAttackEvent event, ItemStack mainhandItem, ItemStack offhandItem);
/**
* Perform any function when the item is held in the offhand and the user right clicks "Air".
*
* @param event the PlayerInteractEvent that was generated
* @param mainhandItem the ItemStack currently being held in the right hand
* @param offhandItem the ItemStack currently being held in the left hand
* @return true if the off hand swing animation should be performed
*/
public boolean offhandClickAir(PlayerInteractEvent event, ItemStack mainhandItem, ItemStack offhandItem);
/**
* Perform any function when the item is held in the offhand and the user right clicks a block.
* Note that this will happen prior to the activation of any activation functions of blocks
*
* @param event the PlayerInteractEvent that was generated
* @param mainhandItem the ItemStack currently being held in the right hand
* @param offhandItem the ItemStack currently being held in the left hand
* @return true if the off hand swing animation should be performed
*/
public boolean offhandClickBlock(PlayerInteractEvent event, ItemStack mainhandItem, ItemStack offhandItem);
/**
* Perform any passive effects on each game tick when the item is held in the offhand
*
* @param effectiveSide the effective side the method was called from
* @param mainhandItem the ItemStack currently being held in the right hand
* @param offhandItem the ItemStack currently being held in the left hand
*/
public void performPassiveEffects(Side effectiveSide, ItemStack mainhandItem, ItemStack offhandItem);
}
+12
View File
@@ -0,0 +1,12 @@
package mods.battlegear2.api;
import net.minecraft.item.ItemStack;
public interface ISheathed {
/**
* Returns true if the item should always be sheathed on the back, false if it should be sheathed on the hip
* @param item the {@link #ItemStack} to be sheathed
*/
public boolean sheatheOnBack(ItemStack item);
}
+9 -1
View File
@@ -1,6 +1,5 @@
package mods.battlegear2.api;
import net.minecraft.item.ItemStack;
import net.minecraft.util.DamageSource;
@@ -15,6 +14,15 @@ public interface IShield {
* @return a value between 0 & 1 representing the decay rate per tick
*/
public float getDecayRate(ItemStack shield);
/**
* Gets the recovery rate for the stamina bar when the shield is not in use.
* The value should be between 0 and 1.
*
* @param shield The {@link #ItemStack} representing the shield
* @return a value between 0 & 1 representing the recovery rate per tick
*/
public float getRecoveryRate(ItemStack shield);
/**
* Returns true if the current shield can and should block the given damage source
@@ -2,6 +2,7 @@ package mods.battlegear2.api.quiver;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import java.util.Comparator;
import java.util.Map;
@@ -13,7 +14,13 @@ public class QuiverArrowRegistry {
public static void addArrowToRegistry(int itemId, int itemMetadata, Class<? extends EntityArrow> entityArrow){
ItemStack stack = new ItemStack(itemId, 1, itemMetadata);
map.put(stack, entityArrow);
addArrowToRegistry(stack, entityArrow);
}
public static void addArrowToRegistry(ItemStack stack, Class<? extends EntityArrow> entityArrow){
ItemStack st = stack.copy();
st.stackSize = 1;
map.put(st, entityArrow);
}
public static Class<? extends EntityArrow> getArrowClass(ItemStack stack){
@@ -23,7 +30,6 @@ public class QuiverArrowRegistry {
static class StackComparator implements Comparator<ItemStack> {
@Override
public int compare(ItemStack stack, ItemStack stack2) {
if(stack == stack2){
return 0;
}else{
@@ -31,8 +37,22 @@ public class QuiverArrowRegistry {
int idDiff = stack.itemID - stack2.itemID;
if(idDiff != 0){
return idDiff;
}else
return stack.getItemDamage() - stack2.getItemDamage();
}else{
idDiff = stack.getItemDamage() - stack2.getItemDamage();
if(idDiff != 0){
return idDiff;
}else{
int tag = 0;
if(stack.hasTagCompound()){
tag = stack.getTagCompound().hashCode();
}
int tag2 = 0;
if(stack2.hasTagCompound()){
tag2 = stack2.getTagCompound().hashCode();
}
return tag-tag2;
}
}
}
}
@@ -1,70 +1,12 @@
package mods.battlegear2.api.weapons;
import cpw.mods.fml.relauncher.Side;
import mods.battlegear2.api.IAllowItem;
import mods.battlegear2.api.IOffhandDual;
import mods.battlegear2.api.ISheathed;
import net.minecraft.item.ItemStack;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
public interface IBattlegearWeapon {
/**
* Returns true if the weapon will allow other weapons to be placed in the partner offhand slot
*/
public boolean willAllowOffhandWeapon();
/**
* Will allow shield
*/
public boolean willAllowShield();
/**
* Returns true if the weapon be dual wielded in the offhand slot
*/
public boolean isOffhandHandDualWeapon();
/**
* Returns true if the weapon should always be sheathed on the back, false if it should be sheathed on the hip
*/
public boolean sheatheOnBack();
/**
* Perform any function when the item is held in the offhand and the user right clicks an entity.
* This is generally used to attack an entity with the offhand item. If this is the case the event should
* be canceled to prevent any default right clicking events (Eg Villager Trading)
*
* @param event the OffhandAttackEvent that was generated
* @param mainhandItem the ItemStack currently being held in the right hand
* @param offhandItem the ItemStack currently being held in the left hand
* @return true if the off hand swing animation should be performed
*/
public boolean offhandAttackEntity(OffhandAttackEvent event, ItemStack mainhandItem, ItemStack offhandItem);
/**
* Perform any function when the item is held in the offhand and the user right clicks "Air".
*
* @param event the PlayerInteractEvent that was generated
* @param mainhandItem the ItemStack currently being held in the right hand
* @param offhandItem the ItemStack currently being held in the left hand
* @return true if the off hand swing animation should be performed
*/
public boolean offhandClickAir(PlayerInteractEvent event, ItemStack mainhandItem, ItemStack offhandItem);
/**
* Perform any function when the item is held in the offhand and the user right clicks a block.
* Note that this will happen prior to the activation of any activation functions of blocks
*
* @param event the PlayerInteractEvent that was generated
* @param mainhandItem the ItemStack currently being held in the right hand
* @param offhandItem the ItemStack currently being held in the left hand
*/
public boolean offhandClickBlock(PlayerInteractEvent event, ItemStack mainhandItem, ItemStack offhandItem);
/**
* Perform any passive effects on each game tick when the item is held in the offhand
*
* @param effectiveSide the effective side the method was called from
* @param mainhandItem the ItemStack currently being held in the right hand
* @param offhandItem the ItemStack currently being held in the left hand
*/
public void performPassiveEffects(Side effectiveSide, ItemStack mainhandItem, ItemStack offhandItem);
public interface IBattlegearWeapon extends ISheathed,IOffhandDual,IAllowItem{
}
@@ -0,0 +1,98 @@
package mods.battlegear2.api.weapons;
import java.util.HashSet;
import java.util.Set;
import mods.battlegear2.utils.BattlegearUtils;
import net.minecraft.item.ItemStack;
/**
* Registry for stacks which will be allowed in battle inventory,
* accessible through {@link #FMLInterModComms} messages.
* Use only if your item is not recognized by default.
* Use of {@link #IBattlegearWeapon} is preferred over this method.
* {@link #NBTTagCompound} are supported.
* @author GotoLink
*
*/
public class WeaponRegistry {
private static Set<StackHolder> weapons = new HashSet<StackHolder>();
private static Set<StackHolder> mainHand = new HashSet<StackHolder>();
private static Set<StackHolder> offHand = new HashSet<StackHolder>();
/**
* Called by a {@link #IMCMessage} with "Dual" as key, and the {@link #ItemStack} as value
* @param stack registered as dual wieldable
*/
public static void addDualWeapon(ItemStack stack) {
if(!BattlegearUtils.checkForRightClickFunction(stack.getItem())){
weapons.add(new StackHolder(stack));
mainHand.add(new StackHolder(stack));
offHand.add(new StackHolder(stack));
}
}
/**
* Called by a {@link #IMCMessage} with "MainHand" as key, and the {@link #ItemStack} as value
* @param stack registered as wieldable only in main hand
*/
public static void addTwoHanded(ItemStack stack) {
if(!BattlegearUtils.checkForRightClickFunction(stack.getItem())){
weapons.add(new StackHolder(stack));
mainHand.add(new StackHolder(stack));
}
}
/**
* Called by a {@link #IMCMessage} with "OffHand" as key, and the {@link #ItemStack} as value
* @param stack registered as wieldable only in main hand
*/
public static void addOffhandWeapon(ItemStack stack) {
if(!BattlegearUtils.checkForRightClickFunction(stack.getItem())){
weapons.add(new StackHolder(stack));
offHand.add(new StackHolder(stack));
}
}
public static boolean isWeapon(ItemStack stack) {
return weapons.contains(new StackHolder(stack));
}
public static boolean isMainHand(ItemStack stack) {
return mainHand.contains(new StackHolder(stack));
}
public static boolean isOffHand(ItemStack stack) {
return offHand.contains(new StackHolder(stack));
}
static class StackHolder{
private ItemStack stack;
public StackHolder(ItemStack stack){
this.stack = stack;
}
@Override
public int hashCode() {
final int prime = 31;
int result = prime + (stack == null ? 0 : stack.itemID ^ stack.stackSize + (stack.hasTagCompound() ? prime*prime ^ stack.getTagCompound().hashCode():0));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof StackHolder)) {
return false;
}
if (!ItemStack.areItemStacksEqual(stack, ((StackHolder) obj).stack)) {
return false;
}
return true;
}
}
}
+1 -1
View File
@@ -231,7 +231,7 @@ public class Arrow extends ToolCore
}
@Override
public boolean isOffhandHandDualWeapon ()
public boolean isOffhandHandDual(ItemStack off)
{
return false;
}
+5 -5
View File
@@ -302,20 +302,20 @@ public class Battleaxe extends HarvestTool
}
@Override
public boolean willAllowOffhandWeapon ()
public boolean allowOffhand(ItemStack mainhand, ItemStack offhand)
{
return false;
}
@Override
public boolean willAllowShield ()
public boolean isOffhandHandDual(ItemStack off)
{
return false;
}
@Override
public boolean isOffhandHandDualWeapon ()
public boolean sheatheOnBack(ItemStack item)
{
return false;
return true;
}
}
+2 -8
View File
@@ -227,19 +227,13 @@ public class Chisel extends ToolCore
}
@Override
public boolean willAllowOffhandWeapon ()
public boolean allowOffhand(ItemStack mainhand, ItemStack offhand)
{
return false;
}
@Override
public boolean willAllowShield ()
{
return false;
}
@Override
public boolean isOffhandHandDualWeapon ()
public boolean isOffhandHandDual(ItemStack off)
{
return false;
}
+20 -14
View File
@@ -4,6 +4,7 @@ import tconstruct.common.TContent;
import tconstruct.library.tools.AbilityHelper;
import tconstruct.library.tools.Weapon;
import tconstruct.util.config.PHConstruct;
import mods.battlegear2.items.ItemShield;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
@@ -164,25 +165,30 @@ public class Cleaver extends Weapon
}*/
@Override
public boolean willAllowOffhandWeapon ()
public boolean allowOffhand(ItemStack mainhand, ItemStack offhand)
{
try
{
if ((PHConstruct.isCleaverTwoHanded) && (offhand.getItem() instanceof ItemShield))
{
return true;
}
else return false;
}
catch (Exception e)
{
return false;
}
}
@Override
public boolean isOffhandHandDual(ItemStack off)
{
return false;
}
@Override
public boolean willAllowShield ()
{
return PHConstruct.isCleaverTwoHanded;
}
@Override
public boolean isOffhandHandDualWeapon ()
{
return false;
}
@Override
public boolean sheatheOnBack ()
public boolean sheatheOnBack(ItemStack item)
{
return true;
}
+3 -9
View File
@@ -295,25 +295,19 @@ public class Excavator extends HarvestTool
}
@Override
public boolean willAllowOffhandWeapon ()
public boolean allowOffhand(ItemStack mainhand, ItemStack offhand)
{
return false;
}
@Override
public boolean willAllowShield ()
public boolean isOffhandHandDual(ItemStack off)
{
return false;
}
@Override
public boolean isOffhandHandDualWeapon ()
{
return false;
}
@Override
public boolean sheatheOnBack ()
public boolean sheatheOnBack(ItemStack item)
{
return true;
}
+20 -8
View File
@@ -10,6 +10,7 @@ import tconstruct.library.crafting.ToolBuilder;
import tconstruct.library.tools.AbilityHelper;
import tconstruct.library.tools.HarvestTool;
import mods.battlegear2.items.ItemShield;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
@@ -422,19 +423,30 @@ public class Hammer extends HarvestTool
}
@Override
public boolean willAllowOffhandWeapon ()
public boolean allowOffhand(ItemStack mainhand, ItemStack offhand)
{
try
{
if (offhand.getItem() instanceof ItemShield)
{
return true;
}
else return false;
}
catch (Exception e)
{
return false;
}
}
@Override
public boolean isOffhandHandDual(ItemStack off)
{
return false;
}
@Override
public boolean isOffhandHandDualWeapon ()
{
return false;
}
@Override
public boolean sheatheOnBack ()
public boolean sheatheOnBack(ItemStack item)
{
return true;
}
+1 -1
View File
@@ -107,7 +107,7 @@ public class Hatchet extends HarvestTool
}
@Override
public boolean isOffhandHandDualWeapon ()
public boolean isOffhandHandDual(ItemStack off)
{
return PHConstruct.isHatchetWeapon;
}
+3 -9
View File
@@ -402,25 +402,19 @@ public class LumberAxe extends HarvestTool
}
@Override
public boolean willAllowOffhandWeapon ()
public boolean allowOffhand(ItemStack mainhand, ItemStack offhand)
{
return false;
}
@Override
public boolean willAllowShield ()
public boolean isOffhandHandDual(ItemStack off)
{
return false;
}
@Override
public boolean isOffhandHandDualWeapon ()
{
return false;
}
@Override
public boolean sheatheOnBack ()
public boolean sheatheOnBack(ItemStack item)
{
return true;
}
+3 -9
View File
@@ -146,25 +146,19 @@ public class Mattock extends DualHarvestTool
}
@Override
public boolean willAllowOffhandWeapon ()
public boolean allowOffhand(ItemStack mainhand, ItemStack offhand)
{
return false;
}
@Override
public boolean willAllowShield ()
public boolean isOffhandHandDual(ItemStack off)
{
return false;
}
@Override
public boolean isOffhandHandDualWeapon ()
{
return false;
}
@Override
public boolean sheatheOnBack ()
public boolean sheatheOnBack(ItemStack item)
{
return true;
}
+2 -1
View File
@@ -4,6 +4,7 @@ import tconstruct.common.TContent;
import tconstruct.library.tools.HarvestTool;
import net.minecraft.block.material.Material;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
public class Pickaxe extends HarvestTool
{
@@ -70,7 +71,7 @@ public class Pickaxe extends HarvestTool
}
@Override
public boolean isOffhandHandDualWeapon ()
public boolean isOffhandHandDual(ItemStack off)
{
return false;
}
+3 -9
View File
@@ -219,25 +219,19 @@ public class Scythe extends Weapon
}
@Override
public boolean willAllowOffhandWeapon ()
public boolean allowOffhand(ItemStack mainhand, ItemStack offhand)
{
return false;
}
@Override
public boolean willAllowShield ()
public boolean isOffhandHandDual(ItemStack off)
{
return false;
}
@Override
public boolean isOffhandHandDualWeapon ()
{
return false;
}
@Override
public boolean sheatheOnBack ()
public boolean sheatheOnBack(ItemStack item)
{
return true;
}
+3 -9
View File
@@ -192,25 +192,19 @@ public class Shortbow extends BowBase
}
@Override
public boolean willAllowOffhandWeapon ()
public boolean allowOffhand(ItemStack mainhand, ItemStack offhand)
{
return false;
}
@Override
public boolean willAllowShield ()
public boolean isOffhandHandDual(ItemStack off)
{
return false;
}
@Override
public boolean isOffhandHandDualWeapon ()
{
return false;
}
@Override
public boolean sheatheOnBack ()
public boolean sheatheOnBack(ItemStack item)
{
return true;
}
+2 -1
View File
@@ -4,6 +4,7 @@ import tconstruct.common.TContent;
import tconstruct.library.tools.HarvestTool;
import net.minecraft.block.material.Material;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@@ -91,7 +92,7 @@ public class Shovel extends HarvestTool
}
@Override
public boolean isOffhandHandDualWeapon ()
public boolean isOffhandHandDual(ItemStack off)
{
return false;
}
+3 -10
View File
@@ -1022,25 +1022,19 @@ public abstract class ToolCore extends Item implements IEnergyContainerItem, ICu
/* Battlegear support, IBattlegearWeapon */
@Override
public boolean willAllowOffhandWeapon ()
public boolean allowOffhand(ItemStack mainhand, ItemStack offhand)
{
return true;
}
@Override
public boolean willAllowShield ()
public boolean isOffhandHandDual(ItemStack off)
{
return true;
}
@Override
public boolean isOffhandHandDualWeapon ()
{
return true;
}
@Override
public boolean sheatheOnBack ()
public boolean sheatheOnBack(ItemStack item)
{
return false;
}
@@ -1057,7 +1051,6 @@ public abstract class ToolCore extends Item implements IEnergyContainerItem, ICu
return true;
}
@Override
public boolean offhandClickBlock (PlayerInteractEvent event, ItemStack mainhandItem, ItemStack offhandItem)
{
return true;