Skip to content

Commit

Permalink
Merge pull request #12 from Kortako/1.7.10
Browse files Browse the repository at this point in the history
Tinkers bows in Battlegear slots
  • Loading branch information
Dream-Master authored Feb 22, 2018
2 parents 3792e46 + a15044c commit ca0e6c5
Show file tree
Hide file tree
Showing 8 changed files with 697 additions and 6 deletions.
451 changes: 451 additions & 0 deletions src/api/java/mods/battlegear2/api/core/InventoryPlayerBattle.java

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions src/api/java/mods/battlegear2/api/core/InventorySlotType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package mods.battlegear2.api.core;

/**
* Created by GotoLink on 24/04/2014.
*/
public enum InventorySlotType {
/**
* The main inventory space (slots 0 to 99)
*/
MAIN,
/**
* The armor inventory space (slots 100 to 149)
*/
ARMOR,
/**
* The inventory space added by battlegear (slots 150 and above)
*/
BATTLE
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package mods.battlegear2.api.core;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraftforge.event.entity.player.PlayerEvent;

/**
* Created by GotoLink on 01/05/2014.
* Event posted on {@link MinecraftForge.EVENT_BUS} from the player inventory {@link InventoryPlayerBattle#readFromNBT(NBTTagList)}
* if the slot number is outside the expected boundaries
*/
public class UnhandledInventoryItemEvent extends PlayerEvent {
/**
* The slot number read from NBT, that is outside the arrays limits
*/
public final int inventorySlot;
/**
* The item read from the NBT, not null
*/
public final ItemStack item;
public UnhandledInventoryItemEvent(EntityPlayer player, int slot, ItemStack itemStack) {
super(player);
inventorySlot = slot;
item = itemStack;
}
}
57 changes: 56 additions & 1 deletion src/main/java/tconstruct/library/weaponry/AmmoItem.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package tconstruct.library.weaponry;

import cpw.mods.fml.common.Optional;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.util.StatCollector;
Expand All @@ -11,10 +12,17 @@
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import tconstruct.library.tools.ToolCore;
import tconstruct.tools.TinkerTools;
import mods.battlegear2.api.PlayerEventChild;
import mods.battlegear2.api.weapons.IBattlegearWeapon;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;

import java.util.List;

public abstract class AmmoItem extends ToolCore implements IAmmo {
@Optional.InterfaceList({
@Optional.Interface(modid = "battlegear2", iface = "mods.battlegear2.api.weapons.IBattlegearWeapon")
})
public abstract class AmmoItem extends ToolCore implements IBattlegearWeapon, IAmmo {
public AmmoItem(int baseDamage, String name) {
super(baseDamage);
this.setCreativeTab(TConstructRegistry.weaponryTab);
Expand Down Expand Up @@ -154,4 +162,51 @@ public boolean onLeftClickEntity (ItemStack stack, EntityPlayer player, Entity e
// ammo doesn't hurt on smacking stuff with it
return false;
}

@Override
@Optional.Method(modid = "battlegear2")
public boolean sheatheOnBack(ItemStack item)
{
return true;
}

@Override
@Optional.Method(modid = "battlegear2")
public boolean isOffhandHandDual(ItemStack off) {
return true;
}

@Override
@Optional.Method(modid = "battlegear2")
public boolean offhandAttackEntity(PlayerEventChild.OffhandAttackEvent event, ItemStack mainhandItem, ItemStack offhandItem) {
return false;
}

@Override
@Optional.Method(modid = "battlegear2")
public boolean offhandClickAir(PlayerInteractEvent event, ItemStack mainhandItem, ItemStack offhandItem) {
event.setCanceled(false);
return false;
}

@Override
@Optional.Method(modid = "battlegear2")
public boolean offhandClickBlock(PlayerInteractEvent event, ItemStack mainhandItem, ItemStack offhandItem) {
return false;
}

@Override
@Optional.Method(modid = "battlegear2")
public void performPassiveEffects(Side effectiveSide, ItemStack mainhandItem, ItemStack offhandItem) {
// unused
}

@Override
@Optional.Method(modid = "battlegear2")
public boolean allowOffhand(ItemStack mainhand, ItemStack offhand) {
if(offhand == null)
return true;
return (mainhand != null && mainhand.getItem() != TinkerTools.cleaver && mainhand.getItem() != TinkerTools.battleaxe)
&& (offhand.getItem() != TinkerTools.cleaver && offhand.getItem() != TinkerTools.battleaxe);
}
}
60 changes: 58 additions & 2 deletions src/main/java/tconstruct/library/weaponry/AmmoWeapon.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package tconstruct.library.weaponry;

import cpw.mods.fml.common.Optional;
import tconstruct.weaponry.client.CrosshairType;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
Expand All @@ -8,12 +9,18 @@
import net.minecraft.item.EnumAction;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;

import tconstruct.tools.TinkerTools;
import mods.battlegear2.api.PlayerEventChild;
import mods.battlegear2.api.weapons.IBattlegearWeapon;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
@Optional.InterfaceList({
@Optional.Interface(modid = "battlegear2", iface = "mods.battlegear2.api.weapons.IBattlegearWeapon")
})
/**
* Throwing weapons that utilize the ammo system on themselves.
* Throwing knifes etc.
*/
public abstract class AmmoWeapon extends AmmoItem implements IAccuracy, IWindup {
public abstract class AmmoWeapon extends AmmoItem implements IBattlegearWeapon, IAccuracy, IWindup {
public AmmoWeapon(int baseDamage, String name) {
super(baseDamage, name);
}
Expand Down Expand Up @@ -134,4 +141,53 @@ public boolean zoomOnWindup(ItemStack itemStack) {
public float getZoom(ItemStack itemStack) {
return 1.0f;
}

/*---- Battlegear Support START ----*/

@Override
@Optional.Method(modid = "battlegear2")
public boolean sheatheOnBack(ItemStack item)
{
return true;
}

@Override
@Optional.Method(modid = "battlegear2")
public boolean isOffhandHandDual(ItemStack off) {
return true;
}

@Override
@Optional.Method(modid = "battlegear2")
public boolean offhandAttackEntity(PlayerEventChild.OffhandAttackEvent event, ItemStack mainhandItem, ItemStack offhandItem) {
return true;
}

@Override
@Optional.Method(modid = "battlegear2")
public boolean offhandClickAir(PlayerInteractEvent event, ItemStack mainhandItem, ItemStack offhandItem) {
onItemRightClick(offhandItem, event.entity.worldObj, event.entityPlayer);
return true;
}

@Override
@Optional.Method(modid = "battlegear2")
public boolean offhandClickBlock(PlayerInteractEvent event, ItemStack mainhandItem, ItemStack offhandItem) {
return true;
}

@Override
@Optional.Method(modid = "battlegear2")
public void performPassiveEffects(Side effectiveSide, ItemStack mainhandItem, ItemStack offhandItem) {
// unused
}

@Override
@Optional.Method(modid = "battlegear2")
public boolean allowOffhand(ItemStack mainhand, ItemStack offhand) {
if(offhand == null)
return true;
return (mainhand != null && mainhand.getItem() != TinkerTools.cleaver && mainhand.getItem() != TinkerTools.battleaxe)
&& (offhand.getItem() != TinkerTools.cleaver && offhand.getItem() != TinkerTools.battleaxe);
}
}
10 changes: 10 additions & 0 deletions src/main/java/tconstruct/library/weaponry/BowBaseAmmo.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import tconstruct.library.crafting.ToolBuilder;
import cpw.mods.fml.common.Loader;
import mods.battlegear2.api.core.InventoryPlayerBattle;

import java.util.List;

Expand Down Expand Up @@ -57,6 +59,14 @@ public float getProjectileSpeed(ItemStack itemStack) {
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)))
{
return offhand;
}
}

ItemStack[] inventory = player.inventory.mainInventory;

// check hotbar for tinker arrows
Expand Down
60 changes: 59 additions & 1 deletion src/main/java/tconstruct/library/weaponry/ProjectileWeapon.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package tconstruct.library.weaponry;

import cpw.mods.fml.common.Optional;
import net.minecraft.init.Items;
import net.minecraft.util.StatCollector;
import tconstruct.client.TProxyClient;
Expand All @@ -23,17 +24,24 @@
import tconstruct.library.tools.AbilityHelper;
import tconstruct.library.tools.ToolCore;
import tconstruct.library.util.TextureHelper;
import tconstruct.tools.TinkerTools;
import tconstruct.weaponry.entity.ArrowEntity;
import mods.battlegear2.api.PlayerEventChild;
import mods.battlegear2.api.weapons.IBattlegearWeapon;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@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,...
*/
public abstract class ProjectileWeapon extends ToolCore implements IAccuracy, IWindup {
public abstract class ProjectileWeapon extends ToolCore implements IBattlegearWeapon, IAccuracy, IWindup {
public ProjectileWeapon(int baseDamage, String name) {
super(baseDamage);

Expand Down Expand Up @@ -474,4 +482,54 @@ else if(currentAmmo.getItem() instanceof AmmoItem && currentAmmo.hasTagCompound(
list.add(currentAmmo.getDisplayName());
list.add(StatCollector.translateToLocal("attribute.name.ammo.maxAttackDamage") + ": " + TProxyClient.df.format(damage));
}

/*---- Battlegear Support START ----*/

@Override
@Optional.Method(modid = "battlegear2")
public boolean sheatheOnBack(ItemStack item)
{
return true;
}

@Override
@Optional.Method(modid = "battlegear2")
public boolean isOffhandHandDual(ItemStack off) {
return true;
}

@Override
@Optional.Method(modid = "battlegear2")
public boolean offhandAttackEntity(PlayerEventChild.OffhandAttackEvent event, ItemStack mainhandItem, ItemStack offhandItem) {
return false;
}

@Override
@Optional.Method(modid = "battlegear2")
public boolean offhandClickAir(PlayerInteractEvent event, ItemStack mainhandItem, ItemStack offhandItem) {
return false;
}

@Override
@Optional.Method(modid = "battlegear2")
public boolean offhandClickBlock(PlayerInteractEvent event, ItemStack mainhandItem, ItemStack offhandItem) {
return false;
}

@Override
@Optional.Method(modid = "battlegear2")
public void performPassiveEffects(Side effectiveSide, ItemStack mainhandItem, ItemStack offhandItem) {
// unused
}

@Override
@Optional.Method(modid = "battlegear2")
public boolean allowOffhand(ItemStack mainhand, ItemStack offhand) {
if(offhand == null)
return true;
return (mainhand != null && mainhand.getItem() != TinkerTools.cleaver && mainhand.getItem() != TinkerTools.battleaxe)
&& (offhand.getItem() != TinkerTools.cleaver && offhand.getItem() != TinkerTools.battleaxe);
}

/*---- Battlegear Support END ----*/
}
20 changes: 18 additions & 2 deletions src/main/java/tconstruct/weaponry/weapons/Crossbow.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import tconstruct.library.crafting.ToolBuilder;
import tconstruct.library.tools.AbilityHelper;
import tconstruct.tools.TinkerTools;
import cpw.mods.fml.common.Loader;
import mods.battlegear2.api.core.InventoryPlayerBattle;

import java.util.List;

Expand Down Expand Up @@ -166,8 +168,14 @@ public boolean reload(ItemStack weapon, EntityPlayer player, World world, NBTTag
// remove loaded item
if(ammo.getItem() instanceof IAmmo)
((IAmmo) ammo.getItem()).consumeAmmo(1, ammo);
else
player.inventory.consumeInventoryItem(ammo.getItem());
else {
if(Loader.isModLoaded("battlegear2")) {
((InventoryPlayerBattle)player.inventory).consumeInventoryItem(ammo.getItem());
}
else {
player.inventory.consumeInventoryItem(ammo.getItem());
}
}

playReloadSound(world, player, weapon, ammo);

Expand Down Expand Up @@ -248,6 +256,14 @@ public void fire(ItemStack weapon, World world, EntityPlayer player)
@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 && (offhand.getItem() instanceof BoltAmmo) && ((IAmmo) offhand.getItem()).getAmmoCount(offhand) > 0)
{
return offhand;
}
}

ItemStack[] inventory = player.inventory.mainInventory;

// check hotbar for tinker arrows
Expand Down

0 comments on commit ca0e6c5

Please sign in to comment.