Skip to content

Commit

Permalink
BG Compat
Browse files Browse the repository at this point in the history
Changelog:
Updated the compat for the changed api
Paladins with hammers and shields, ho!
  • Loading branch information
Zerokyuuni committed Dec 6, 2013
1 parent 2e99697 commit f1473dc
Show file tree
Hide file tree
Showing 23 changed files with 294 additions and 156 deletions.
11 changes: 11 additions & 0 deletions src/mods/battlegear2/api/IAllowItem.java
@@ -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);
}
6 changes: 3 additions & 3 deletions src/mods/battlegear2/api/IDyable.java
Expand Up @@ -8,20 +8,20 @@
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);

Expand Down
15 changes: 15 additions & 0 deletions src/mods/battlegear2/api/IEnchantable.java
@@ -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);
}
55 changes: 55 additions & 0 deletions src/mods/battlegear2/api/IOffhandDual.java
@@ -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 changes: 12 additions & 0 deletions src/mods/battlegear2/api/ISheathed.java
@@ -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);
}
10 changes: 9 additions & 1 deletion src/mods/battlegear2/api/IShield.java
@@ -1,6 +1,5 @@
package mods.battlegear2.api;


import net.minecraft.item.ItemStack;
import net.minecraft.util.DamageSource;

Expand All @@ -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
Expand Down
28 changes: 24 additions & 4 deletions src/mods/battlegear2/api/quiver/QuiverArrowRegistry.java
Expand Up @@ -2,6 +2,7 @@

import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;

import java.util.Comparator;
import java.util.Map;
Expand All @@ -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){
Expand All @@ -23,16 +30,29 @@ public static Class<? extends EntityArrow> getArrowClass(ItemStack stack){
static class StackComparator implements Comparator<ItemStack> {
@Override
public int compare(ItemStack stack, ItemStack stack2) {

if(stack == stack2){
return 0;
}else{

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;
}
}
}

}
Expand Down
66 changes: 4 additions & 62 deletions src/mods/battlegear2/api/weapons/IBattlegearWeapon.java
@@ -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{

}
98 changes: 98 additions & 0 deletions src/mods/battlegear2/api/weapons/WeaponRegistry.java
@@ -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;
}
}
}
2 changes: 1 addition & 1 deletion src/tconstruct/items/tools/Arrow.java
Expand Up @@ -231,7 +231,7 @@ else if (power > this.getMaxCharge(stack) * 2 / 3)
}

@Override
public boolean isOffhandHandDualWeapon ()
public boolean isOffhandHandDual(ItemStack off)
{
return false;
}
Expand Down

0 comments on commit f1473dc

Please sign in to comment.