Allow Bound Sword to be enchanted
Also changes how the models are handled and changing activation states does not cause the "item change" animation.
This commit is contained in:
parent
fd16a58b6b
commit
cc66af7eb1
15 changed files with 122 additions and 134 deletions
|
@ -2,8 +2,8 @@ package WayofTime.bloodmagic.item;
|
|||
|
||||
import WayofTime.bloodmagic.BloodMagic;
|
||||
import WayofTime.bloodmagic.api.Constants;
|
||||
import WayofTime.bloodmagic.api.iface.IActivatable;
|
||||
import WayofTime.bloodmagic.api.iface.IBindable;
|
||||
import WayofTime.bloodmagic.api.util.helper.BindableHelper;
|
||||
import WayofTime.bloodmagic.api.util.helper.NBTHelper;
|
||||
import WayofTime.bloodmagic.api.util.helper.PlayerHelper;
|
||||
import WayofTime.bloodmagic.registry.ModItems;
|
||||
|
@ -11,9 +11,16 @@ import WayofTime.bloodmagic.util.helper.TextHelper;
|
|||
|
||||
import com.google.common.base.Strings;
|
||||
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.SharedMonsterAttributes;
|
||||
import net.minecraft.entity.ai.attributes.AttributeModifier;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemSword;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
|
@ -21,17 +28,19 @@ import net.minecraftforge.fml.relauncher.SideOnly;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
public class ItemBoundSword extends ItemSword implements IBindable
|
||||
public class ItemBoundSword extends ItemSword implements IBindable, IActivatable
|
||||
{
|
||||
private float attackDamage;
|
||||
|
||||
public ItemBoundSword()
|
||||
{
|
||||
super(ModItems.boundToolMaterial);
|
||||
|
||||
setUnlocalizedName(Constants.Mod.MODID + ".bound.sword");
|
||||
setRegistryName(Constants.BloodMagicItem.BOUND_SWORD.getRegName());
|
||||
setHasSubtypes(true);
|
||||
setNoRepair();
|
||||
setCreativeTab(BloodMagic.tabBloodMagic);
|
||||
|
||||
this.attackDamage = 4.0F + ModItems.boundToolMaterial.getDamageVsEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -41,11 +50,29 @@ public class ItemBoundSword extends ItemSword implements IBindable
|
|||
player.setItemInUse(stack, this.getMaxItemUseDuration(stack));
|
||||
|
||||
if (player.isSneaking())
|
||||
setActivated(stack, !getActivated(stack));
|
||||
setActivatedState(stack, !getActivated(stack));
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBlockDestroyed(ItemStack stack, World worldIn, Block blockIn, BlockPos pos, EntityLivingBase playerIn)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldCauseReequipAnimation(ItemStack oldStack, ItemStack newStack, boolean slotChanged)
|
||||
{
|
||||
return oldStack.getItem() != newStack.getItem();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void addInformation(ItemStack stack, EntityPlayer player, List<String> tooltip, boolean advanced)
|
||||
|
@ -63,12 +90,14 @@ public class ItemBoundSword extends ItemSword implements IBindable
|
|||
|
||||
public boolean getActivated(ItemStack stack)
|
||||
{
|
||||
return stack.getItemDamage() > 0;
|
||||
NBTHelper.checkNBT(stack);
|
||||
return stack.getTagCompound().getBoolean(Constants.NBT.ACTIVATED);
|
||||
}
|
||||
|
||||
private ItemStack setActivated(ItemStack stack, boolean activated)
|
||||
public ItemStack setActivatedState(ItemStack stack, boolean activated)
|
||||
{
|
||||
stack.setItemDamage(activated ? 1 : 0);
|
||||
NBTHelper.checkNBT(stack);
|
||||
stack.getTagCompound().setBoolean(Constants.NBT.ACTIVATED, activated);
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
|
|
@ -5,6 +5,8 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import WayofTime.bloodmagic.api.iface.IActivatable;
|
||||
import WayofTime.bloodmagic.api.util.helper.NBTHelper;
|
||||
import lombok.Getter;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.Entity;
|
||||
|
@ -12,6 +14,7 @@ import net.minecraft.entity.item.EntityItem;
|
|||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.EnumAction;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.StatCollector;
|
||||
|
@ -28,7 +31,7 @@ import WayofTime.bloodmagic.util.helper.TextHelper;
|
|||
import com.google.common.collect.Multiset;
|
||||
|
||||
@Getter
|
||||
public class ItemBoundTool extends ItemBindable
|
||||
public class ItemBoundTool extends ItemBindable implements IActivatable
|
||||
{
|
||||
private Set<Block> effectiveBlocks;
|
||||
protected final String tooltipBase;
|
||||
|
@ -43,9 +46,7 @@ public class ItemBoundTool extends ItemBindable
|
|||
{
|
||||
super();
|
||||
setUnlocalizedName(Constants.Mod.MODID + ".bound." + name);
|
||||
setHasSubtypes(true);
|
||||
setLPUsed(lpUsed);
|
||||
setFull3D();
|
||||
|
||||
this.name = name;
|
||||
this.tooltipBase = "tooltip.BloodMagic.bound." + name + ".";
|
||||
|
@ -63,6 +64,12 @@ public class ItemBoundTool extends ItemBindable
|
|||
return this.effectiveBlocks.contains(block) ? 8.0F : 1.0F;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldCauseReequipAnimation(ItemStack oldStack, ItemStack newStack, boolean slotChanged)
|
||||
{
|
||||
return oldStack.getItem() != newStack.getItem();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected)
|
||||
{
|
||||
|
@ -113,7 +120,7 @@ public class ItemBoundTool extends ItemBindable
|
|||
// if (!world.isRemote)
|
||||
{
|
||||
if (player.isSneaking())
|
||||
setActivated(stack, !getActivated(stack));
|
||||
setActivatedState(stack, !getActivated(stack));
|
||||
// if (getActivated(stack) && ItemBindable.syphonBatteries(stack,
|
||||
// player, getLPUsed()))
|
||||
// return stack;
|
||||
|
@ -233,12 +240,14 @@ public class ItemBoundTool extends ItemBindable
|
|||
|
||||
public boolean getActivated(ItemStack stack)
|
||||
{
|
||||
return stack.getItemDamage() > 0;
|
||||
NBTHelper.checkNBT(stack);
|
||||
return stack.getTagCompound().getBoolean(Constants.NBT.ACTIVATED);
|
||||
}
|
||||
|
||||
public ItemStack setActivated(ItemStack stack, boolean activated)
|
||||
public ItemStack setActivatedState(ItemStack stack, boolean activated)
|
||||
{
|
||||
stack.setItemDamage(activated ? 1 : 0);
|
||||
NBTHelper.checkNBT(stack);
|
||||
stack.getTagCompound().setBoolean(Constants.NBT.ACTIVATED, activated);
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
|||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import WayofTime.bloodmagic.api.iface.IActivatable;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.SharedMonsterAttributes;
|
||||
|
@ -28,7 +29,7 @@ import WayofTime.bloodmagic.util.helper.TextHelper;
|
|||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
|
||||
public class ItemSentientSword extends ItemSword implements IDemonWillWeapon
|
||||
public class ItemSentientSword extends ItemSword implements IDemonWillWeapon, IActivatable
|
||||
{
|
||||
public int[] soulBracket = new int[] { 16, 60, 200, 400 };
|
||||
public double[] damageAdded = new double[] { 1, 1.5, 2, 2.5 };
|
||||
|
@ -49,7 +50,7 @@ public class ItemSentientSword extends ItemSword implements IDemonWillWeapon
|
|||
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player)
|
||||
{
|
||||
if (player.isSneaking())
|
||||
setActivated(stack, !getActivated(stack));
|
||||
setActivatedState(stack, !getActivated(stack));
|
||||
|
||||
if (getActivated(stack))
|
||||
{
|
||||
|
@ -69,6 +70,12 @@ public class ItemSentientSword extends ItemSword implements IDemonWillWeapon
|
|||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldCauseReequipAnimation(ItemStack oldStack, ItemStack newStack, boolean slotChanged)
|
||||
{
|
||||
return oldStack.getItem() != newStack.getItem();
|
||||
}
|
||||
|
||||
private int getLevel(ItemStack stack, double soulsRemaining)
|
||||
{
|
||||
int lvl = -1;
|
||||
|
@ -116,7 +123,7 @@ public class ItemSentientSword extends ItemSword implements IDemonWillWeapon
|
|||
|
||||
if (drain > soulsRemaining)
|
||||
{
|
||||
setActivated(stack, false);
|
||||
setActivatedState(stack, false);
|
||||
return false;
|
||||
} else
|
||||
{
|
||||
|
@ -131,16 +138,13 @@ public class ItemSentientSword extends ItemSword implements IDemonWillWeapon
|
|||
public boolean getActivated(ItemStack stack)
|
||||
{
|
||||
NBTHelper.checkNBT(stack);
|
||||
NBTTagCompound tag = stack.getTagCompound();
|
||||
|
||||
return tag.getBoolean("activated");
|
||||
return stack.getTagCompound().getBoolean(Constants.NBT.ACTIVATED);
|
||||
}
|
||||
|
||||
public ItemStack setActivated(ItemStack stack, boolean activated)
|
||||
public ItemStack setActivatedState(ItemStack stack, boolean activated)
|
||||
{
|
||||
NBTHelper.checkNBT(stack);
|
||||
NBTTagCompound tag = stack.getTagCompound();
|
||||
tag.setBoolean("activated", activated);
|
||||
stack.getTagCompound().setBoolean(Constants.NBT.ACTIVATED, activated);
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue