mirror of
https://github.com/GTNewHorizons/TinkersConstruct.git
synced 2026-11-25 06:24:37 +00:00
Allow arrows and bolts to be used from bauble slots.
Register a Quiver slot if Baubles Expanded is present. Can be put in a ring slot (had to pick one) if just Baubles is present. Clean up some unused and outdated logic in all the bow and ammo classes.
This commit is contained in:
1 parent
fdfe5df30f
commit
7fe01beebc
12 files changed
+255
-219
No files matched your search
@@ -1,22 +1,36 @@
|
||||
package tconstruct.library.weaponry;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
||||
|
||||
import baubles.api.BaubleType;
|
||||
import baubles.api.IBauble;
|
||||
import baubles.api.expanded.IBaubleExpanded;
|
||||
import baubles.common.lib.PlayerHandler;
|
||||
import cpw.mods.fml.common.Optional;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import mods.battlegear2.api.PlayerEventChild;
|
||||
import mods.battlegear2.api.weapons.IBattlegearWeapon;
|
||||
import tconstruct.TConstruct;
|
||||
import tconstruct.compat.LoadedMods;
|
||||
import tconstruct.library.TConstructRegistry;
|
||||
import tconstruct.library.tools.ToolCore;
|
||||
import tconstruct.tools.TinkerTools;
|
||||
|
||||
@Optional.InterfaceList({
|
||||
@Optional.Interface(modid = "battlegear2", iface = "mods.battlegear2.api.weapons.IBattlegearWeapon") })
|
||||
public abstract class AmmoItem extends ToolCore implements IBattlegearWeapon, IAmmo {
|
||||
@Optional.Interface(modid = "battlegear2", iface = "mods.battlegear2.api.weapons.IBattlegearWeapon"),
|
||||
@Optional.Interface(modid = "Baubles|Expanded", iface = "baubles.api.expanded.IBaubleExpanded"),
|
||||
@Optional.Interface(modid = "Baubles", iface = "baubles.api.IBauble") })
|
||||
public abstract class AmmoItem extends ToolCore implements IBattlegearWeapon, IAmmo, IBauble, IBaubleExpanded {
|
||||
|
||||
public AmmoItem(int baseDamage, String name) {
|
||||
super(baseDamage);
|
||||
@@ -76,28 +90,23 @@ public abstract class AmmoItem extends ToolCore implements IBattlegearWeapon, IA
|
||||
}
|
||||
|
||||
public boolean pickupAmmo(ItemStack stack, ItemStack candidate, EntityPlayer player) {
|
||||
if (stack.getItem() == null || !stack.hasTagCompound() || !(stack.getItem() instanceof IAmmo)) return false;
|
||||
if (stack.getItem() == null || !stack.hasTagCompound() || !(stack.getItem() instanceof IAmmo pickedup))
|
||||
return false;
|
||||
|
||||
// check if our candidate fits
|
||||
if (candidate != null) {
|
||||
// same item
|
||||
if (testIfAmmoMatches(stack, candidate)) {
|
||||
IAmmo pickedup = ((IAmmo) stack.getItem());
|
||||
IAmmo ininventory = ((IAmmo) candidate.getItem());
|
||||
// we can be sure that it's ammo, since stack is ammo and they're equal
|
||||
int count = pickedup.getAmmoCount(stack);
|
||||
if (count != ininventory.addAmmo(count, candidate)) return true;
|
||||
}
|
||||
if (ammoCanStack(stack, pickedup, candidate)) return true;
|
||||
}
|
||||
|
||||
// search the players inventory
|
||||
// search the player's inventory
|
||||
for (ItemStack invItem : player.inventory.mainInventory) {
|
||||
if (testIfAmmoMatches(stack, invItem)) {
|
||||
IAmmo pickedup = ((IAmmo) stack.getItem());
|
||||
IAmmo ininventory = ((IAmmo) invItem.getItem());
|
||||
// we can be sure that it's ammo, since stack is ammo and they're equal
|
||||
int count = pickedup.getAmmoCount(stack);
|
||||
if (count != ininventory.addAmmo(count, invItem)) return true;
|
||||
if (ammoCanStack(stack, pickedup, invItem)) return true;
|
||||
}
|
||||
|
||||
// search bauble slots
|
||||
if (LoadedMods.baubles) {
|
||||
for (ItemStack bauble : PlayerHandler.getPlayerBaubles(player).stackList) {
|
||||
if (ammoCanStack(stack, pickedup, bauble)) return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,6 +114,17 @@ public abstract class AmmoItem extends ToolCore implements IBattlegearWeapon, IA
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean ammoCanStack(ItemStack stack, IAmmo pickedup, ItemStack bauble) {
|
||||
if (!testIfAmmoMatches(stack, bauble)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
IAmmo ininventory = ((IAmmo) bauble.getItem());
|
||||
// we can be sure that it's ammo, since stack is ammo and they're equal
|
||||
int count = pickedup.getAmmoCount(stack);
|
||||
return count != ininventory.addAmmo(count, bauble);
|
||||
}
|
||||
|
||||
private boolean testIfAmmoMatches(ItemStack reference, ItemStack candidate) {
|
||||
if (candidate == null) return false;
|
||||
if (!candidate.hasTagCompound() || !candidate.getTagCompound().hasKey("InfiTool")) return false;
|
||||
@@ -198,4 +218,62 @@ public abstract class AmmoItem extends ToolCore implements IBattlegearWeapon, IA
|
||||
&& mainhand.getItem() != TinkerTools.battleaxe)
|
||||
&& (offhand.getItem() != TinkerTools.cleaver && offhand.getItem() != TinkerTools.battleaxe);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Optional.Method(modid = "Baubles|Expanded")
|
||||
public String[] getBaubleTypes(ItemStack itemstack) {
|
||||
return new String[] { TConstruct.AMMOBAUBLESLOT };
|
||||
}
|
||||
|
||||
// Fallback for base Baubles
|
||||
@Override
|
||||
@Optional.Method(modid = "Baubles")
|
||||
public BaubleType getBaubleType(ItemStack itemStack) {
|
||||
return BaubleType.RING;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Optional.Method(modid = "Baubles")
|
||||
public void onWornTick(ItemStack itemstack, EntityLivingBase player) {
|
||||
onUpdate(itemstack, player.worldObj, player, 0, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Optional.Method(modid = "Baubles")
|
||||
public void onEquipped(ItemStack itemstack, EntityLivingBase player) {}
|
||||
|
||||
@Override
|
||||
@Optional.Method(modid = "Baubles")
|
||||
public void onUnequipped(ItemStack itemstack, EntityLivingBase player) {}
|
||||
|
||||
@Override
|
||||
@Optional.Method(modid = "Baubles")
|
||||
public boolean canEquip(ItemStack itemstack, EntityLivingBase player) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Optional.Method(modid = "Baubles")
|
||||
public boolean canUnequip(ItemStack itemstack, EntityLivingBase player) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void addInformation(ItemStack stack, EntityPlayer player, List<String> lines, boolean advanced) {
|
||||
super.addInformation(stack, player, lines, advanced);
|
||||
addBaubleInformation(lines);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Optional.Method(modid = "Baubles")
|
||||
private void addBaubleInformation(List<String> lines) {
|
||||
if (LoadedMods.baublesExpanded) {
|
||||
if (GuiScreen.isShiftKeyDown()) {
|
||||
lines.add(StatCollector.translateToLocal("tooltip.compatibleslots"));
|
||||
lines.add(StatCollector.translateToLocal("slot.quiver"));
|
||||
if (LoadedMods.tiCTooltips) lines.add(""); // Required for spacing
|
||||
} else if (!LoadedMods.tiCTooltips) lines.add(StatCollector.translateToLocal("tooltip.shiftprompt"));
|
||||
} else lines.add(StatCollector.translateToLocal("baubletype.any"));
|
||||
}
|
||||
}
|
||||
@@ -12,9 +12,10 @@ import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import baubles.common.lib.PlayerHandler;
|
||||
import mods.battlegear2.api.core.IBattlePlayer;
|
||||
import tconstruct.compat.Battlegear2Compat;
|
||||
import tconstruct.compat.LoadedMods;
|
||||
import tconstruct.library.TConstructRegistry;
|
||||
import tconstruct.library.crafting.ToolBuilder;
|
||||
import tconstruct.library.tools.BowstringMaterial;
|
||||
@@ -24,8 +25,6 @@ import tconstruct.weaponry.entity.ArrowEntity;
|
||||
|
||||
public abstract class BowBaseAmmo extends ProjectileWeapon {
|
||||
|
||||
private static final boolean isBattlegear2Loaded = Loader.isModLoaded("battlegear2");
|
||||
|
||||
public BowBaseAmmo(int baseDamage, String name) {
|
||||
super(baseDamage, name);
|
||||
}
|
||||
@@ -62,8 +61,8 @@ public abstract class BowBaseAmmo extends ProjectileWeapon {
|
||||
|
||||
@Override
|
||||
public ItemStack searchForAmmo(EntityPlayer player, ItemStack weapon) {
|
||||
// arrow priority: hotbar > inventory, tinker arrows > regular arrows
|
||||
if (isBattlegear2Loaded && player instanceof IBattlePlayer battlePlayer
|
||||
// arrow priority: offhand > bauble slots > hotbar > inventory, tinker arrows > regular arrows
|
||||
if (LoadedMods.battlegear2 && player instanceof IBattlePlayer battlePlayer
|
||||
&& battlePlayer.battlegear2$isBattlemode()) {
|
||||
ItemStack offhand = Battlegear2Compat.getBattlegear2Offhand(player);
|
||||
if (checkTinkerArrow(offhand) || checkVanillaArrow(offhand)) {
|
||||
@@ -71,6 +70,14 @@ public abstract class BowBaseAmmo extends ProjectileWeapon {
|
||||
}
|
||||
}
|
||||
|
||||
if (LoadedMods.baubles) {
|
||||
for (ItemStack bauble : PlayerHandler.getPlayerBaubles(player).stackList) {
|
||||
if (checkTinkerArrow(bauble) || checkVanillaArrow(bauble)) {
|
||||
return bauble;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ItemStack[] inventory = player.inventory.mainInventory;
|
||||
|
||||
// check hotbar for tinker arrows
|
||||
@@ -142,7 +149,7 @@ public abstract class BowBaseAmmo extends ProjectileWeapon {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildTool(int id, String name, List list) {
|
||||
public void buildTool(int id, String name, List<ItemStack> list) {
|
||||
// does the material have a bow material?
|
||||
if (TConstructRegistry.getBowMaterial(id) == null) return;
|
||||
|
||||
|
||||
@@ -198,7 +198,7 @@ public abstract class ProjectileWeapon extends ToolCore implements IBattlegearWe
|
||||
playFiringSound(world, player, weapon, ammo, projectileSpeed, accuracy);
|
||||
|
||||
// use up ammo
|
||||
if (!player.capabilities.isCreativeMode) {
|
||||
if (!player.capabilities.isCreativeMode && !world.isRemote) {
|
||||
if (ammo.getItem() instanceof IAmmo) {
|
||||
if (ammo.hasTagCompound()) {
|
||||
int ammoReinforced = ammo.getTagCompound().getCompoundTag("InfiTool").getInteger("Unbreaking");
|
||||
|
||||
Reference in new issue
Block a user