2015-12-29 19:32:35 +00:00
|
|
|
package WayofTime.bloodmagic.item;
|
|
|
|
|
2016-03-18 20:08:06 +00:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
2016-06-17 14:15:46 +00:00
|
|
|
import javax.annotation.Nullable;
|
|
|
|
|
2017-02-05 20:42:28 +00:00
|
|
|
import WayofTime.bloodmagic.api.util.helper.NetworkHelper;
|
2016-06-24 01:40:28 +00:00
|
|
|
import WayofTime.bloodmagic.util.Utils;
|
2016-03-18 20:31:55 +00:00
|
|
|
import net.minecraft.block.state.IBlockState;
|
2016-03-18 20:08:06 +00:00
|
|
|
import net.minecraft.client.renderer.ItemMeshDefinition;
|
2017-08-16 03:21:54 +00:00
|
|
|
import net.minecraft.client.util.ITooltipFlag;
|
2016-06-24 01:40:28 +00:00
|
|
|
import net.minecraft.creativetab.CreativeTabs;
|
2017-02-05 20:42:28 +00:00
|
|
|
import net.minecraft.entity.Entity;
|
2016-03-18 20:08:06 +00:00
|
|
|
import net.minecraft.entity.EntityLivingBase;
|
|
|
|
import net.minecraft.entity.SharedMonsterAttributes;
|
|
|
|
import net.minecraft.entity.ai.attributes.AttributeModifier;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2016-03-18 20:31:55 +00:00
|
|
|
import net.minecraft.inventory.EntityEquipmentSlot;
|
2016-06-24 01:40:28 +00:00
|
|
|
import net.minecraft.item.Item;
|
2016-03-18 20:08:06 +00:00
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.item.ItemSword;
|
2016-03-18 20:31:55 +00:00
|
|
|
import net.minecraft.util.ActionResult;
|
|
|
|
import net.minecraft.util.EnumHand;
|
2017-01-02 06:26:42 +00:00
|
|
|
import net.minecraft.util.NonNullList;
|
2016-03-21 06:21:07 +00:00
|
|
|
import net.minecraft.util.ResourceLocation;
|
2016-03-18 20:08:06 +00:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
2016-03-17 20:00:44 +00:00
|
|
|
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.NBTHelper;
|
|
|
|
import WayofTime.bloodmagic.api.util.helper.PlayerHelper;
|
2016-03-16 05:48:01 +00:00
|
|
|
import WayofTime.bloodmagic.client.IMeshProvider;
|
|
|
|
import WayofTime.bloodmagic.client.mesh.CustomMeshDefinitionActivatable;
|
2017-08-16 01:14:28 +00:00
|
|
|
import WayofTime.bloodmagic.core.RegistrarBloodMagicItems;
|
2016-03-17 20:00:44 +00:00
|
|
|
import WayofTime.bloodmagic.util.helper.TextHelper;
|
2016-03-18 20:08:06 +00:00
|
|
|
|
2016-03-17 20:00:44 +00:00
|
|
|
import com.google.common.base.Strings;
|
2016-03-19 12:47:59 +00:00
|
|
|
import com.google.common.collect.HashMultimap;
|
2016-03-17 20:00:44 +00:00
|
|
|
import com.google.common.collect.Multimap;
|
2015-12-29 19:32:35 +00:00
|
|
|
|
2016-03-16 05:48:01 +00:00
|
|
|
public class ItemBoundSword extends ItemSword implements IBindable, IActivatable, IMeshProvider
|
2015-12-30 20:34:40 +00:00
|
|
|
{
|
|
|
|
public ItemBoundSword()
|
|
|
|
{
|
2017-08-15 03:53:42 +00:00
|
|
|
super(RegistrarBloodMagicItems.BOUND_TOOL_MATERIAL);
|
2015-12-29 19:32:35 +00:00
|
|
|
|
2017-08-15 03:53:42 +00:00
|
|
|
setUnlocalizedName(BloodMagic.MODID + ".bound.sword");
|
|
|
|
setCreativeTab(BloodMagic.TAB_BM);
|
2015-12-29 19:32:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-01-02 06:26:42 +00:00
|
|
|
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand)
|
2015-12-30 20:34:40 +00:00
|
|
|
{
|
2017-01-02 06:26:42 +00:00
|
|
|
ItemStack stack = player.getHeldItem(hand);
|
2016-01-14 00:48:34 +00:00
|
|
|
if (player.isSneaking())
|
2016-02-04 10:45:19 +00:00
|
|
|
setActivatedState(stack, !getActivated(stack));
|
2015-12-29 19:32:35 +00:00
|
|
|
|
2016-05-14 19:33:05 +00:00
|
|
|
// if (!player.isSneaking() && getActivated(stack))
|
|
|
|
// {
|
|
|
|
// BoundToolEvent.Charge event = new BoundToolEvent.Charge(player, stack);
|
|
|
|
// if (MinecraftForge.EVENT_BUS.post(event))
|
|
|
|
// return new ActionResult<ItemStack>(EnumActionResult.FAIL, event.result);
|
|
|
|
//
|
|
|
|
// player.setActiveHand(hand);
|
|
|
|
// return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
|
|
|
|
// }
|
2016-03-18 20:31:55 +00:00
|
|
|
|
2017-01-02 06:26:42 +00:00
|
|
|
return super.onItemRightClick(world, player, hand);
|
2015-12-29 19:32:35 +00:00
|
|
|
}
|
|
|
|
|
2017-02-05 20:42:28 +00:00
|
|
|
@Override
|
|
|
|
public void onUpdate(ItemStack stack, World world, Entity entity, int itemSlot, boolean isSelected)
|
|
|
|
{
|
2017-03-29 01:40:24 +00:00
|
|
|
if (Strings.isNullOrEmpty(getOwnerUUID(stack))) {
|
|
|
|
setActivatedState(stack, false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-02-05 20:42:28 +00:00
|
|
|
if (entity instanceof EntityPlayer && getActivated(stack) && world.getTotalWorldTime() % 80 == 0)
|
|
|
|
NetworkHelper.getSoulNetwork(getOwnerUUID(stack)).syphonAndDamage((EntityPlayer) entity, 20);
|
|
|
|
}
|
|
|
|
|
2016-02-04 10:45:19 +00:00
|
|
|
@Override
|
|
|
|
public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-03-18 20:31:55 +00:00
|
|
|
public boolean onBlockDestroyed(ItemStack stack, World world, IBlockState block, BlockPos pos, EntityLivingBase entityLiving)
|
2016-02-04 10:45:19 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean shouldCauseReequipAnimation(ItemStack oldStack, ItemStack newStack, boolean slotChanged)
|
|
|
|
{
|
|
|
|
return oldStack.getItem() != newStack.getItem();
|
|
|
|
}
|
|
|
|
|
2016-06-24 01:40:28 +00:00
|
|
|
@Override
|
|
|
|
@SideOnly(Side.CLIENT)
|
2017-08-16 03:21:54 +00:00
|
|
|
public void getSubItems(CreativeTabs tab, NonNullList<ItemStack> subItems)
|
2016-06-24 01:44:01 +00:00
|
|
|
{
|
2017-08-16 03:21:54 +00:00
|
|
|
if (!isInCreativeTab(tab))
|
|
|
|
return;
|
|
|
|
|
|
|
|
subItems.add(Utils.setUnbreakable(new ItemStack(this)));
|
2016-06-24 01:40:28 +00:00
|
|
|
}
|
|
|
|
|
2015-12-29 19:32:35 +00:00
|
|
|
@Override
|
|
|
|
@SideOnly(Side.CLIENT)
|
2017-08-16 03:21:54 +00:00
|
|
|
public void addInformation(ItemStack stack, World world, List<String> tooltip, ITooltipFlag flag)
|
2015-12-30 20:34:40 +00:00
|
|
|
{
|
2016-09-07 01:55:32 +00:00
|
|
|
if (!stack.hasTagCompound())
|
|
|
|
return;
|
2015-12-29 19:32:35 +00:00
|
|
|
|
2017-01-02 09:18:29 +00:00
|
|
|
if (TextHelper.canTranslate("tooltip.bloodmagic.bound.sword.desc"))
|
|
|
|
tooltip.add(TextHelper.localizeEffect("tooltip.bloodmagic.bound.sword.desc"));
|
2016-01-07 23:52:02 +00:00
|
|
|
|
2017-01-02 09:18:29 +00:00
|
|
|
tooltip.add(TextHelper.localize("tooltip.bloodmagic." + (getActivated(stack) ? "activated" : "deactivated")));
|
2015-12-29 19:32:35 +00:00
|
|
|
|
2016-04-11 23:57:23 +00:00
|
|
|
if (!Strings.isNullOrEmpty(getOwnerUUID(stack)))
|
2017-01-02 09:18:29 +00:00
|
|
|
tooltip.add(TextHelper.localizeEffect("tooltip.bloodmagic.currentOwner", PlayerHelper.getUsernameFromStack(stack)));
|
2015-12-29 19:32:35 +00:00
|
|
|
}
|
|
|
|
|
2016-02-04 10:51:54 +00:00
|
|
|
@Override
|
2016-03-18 20:31:55 +00:00
|
|
|
public Multimap<String, AttributeModifier> getAttributeModifiers(EntityEquipmentSlot equipmentSlot, ItemStack stack)
|
2016-02-20 00:47:58 +00:00
|
|
|
{
|
2016-03-19 12:47:59 +00:00
|
|
|
Multimap<String, AttributeModifier> multimap = HashMultimap.<String, AttributeModifier>create();
|
2016-03-18 22:01:52 +00:00
|
|
|
if (equipmentSlot == EntityEquipmentSlot.MAINHAND)
|
|
|
|
{
|
2017-01-02 06:26:42 +00:00
|
|
|
multimap.put(SharedMonsterAttributes.ATTACK_DAMAGE.getName(), new AttributeModifier(ATTACK_DAMAGE_MODIFIER, "Weapon modifier", getActivated(stack) ? 8 : 2, 0));
|
|
|
|
multimap.put(SharedMonsterAttributes.ATTACK_SPEED.getName(), new AttributeModifier(ATTACK_SPEED_MODIFIER, "Weapon modifier", -2.4, 0));
|
2016-03-18 22:01:52 +00:00
|
|
|
}
|
2016-02-04 10:51:54 +00:00
|
|
|
return multimap;
|
|
|
|
}
|
|
|
|
|
2016-03-16 05:48:01 +00:00
|
|
|
@Override
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public ItemMeshDefinition getMeshDefinition()
|
|
|
|
{
|
|
|
|
return new CustomMeshDefinitionActivatable("ItemBoundSword");
|
|
|
|
}
|
|
|
|
|
2016-03-21 06:21:07 +00:00
|
|
|
@Nullable
|
|
|
|
@Override
|
|
|
|
public ResourceLocation getCustomLocation()
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2016-03-16 05:48:01 +00:00
|
|
|
@Override
|
|
|
|
public List<String> getVariants()
|
|
|
|
{
|
|
|
|
List<String> ret = new ArrayList<String>();
|
|
|
|
ret.add("active=true");
|
|
|
|
ret.add("active=false");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-01-14 00:48:34 +00:00
|
|
|
// IBindable
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onBind(EntityPlayer player, ItemStack stack)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2016-02-04 08:25:37 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getOwnerName(ItemStack stack)
|
|
|
|
{
|
|
|
|
return stack != null ? NBTHelper.checkNBT(stack).getTagCompound().getString(Constants.NBT.OWNER_NAME) : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getOwnerUUID(ItemStack stack)
|
|
|
|
{
|
|
|
|
return stack != null ? NBTHelper.checkNBT(stack).getTagCompound().getString(Constants.NBT.OWNER_UUID) : null;
|
|
|
|
}
|
2016-04-11 23:57:23 +00:00
|
|
|
|
|
|
|
// IActivatable
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean getActivated(ItemStack stack)
|
|
|
|
{
|
|
|
|
return stack != null && NBTHelper.checkNBT(stack).getTagCompound().getBoolean(Constants.NBT.ACTIVATED);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ItemStack setActivatedState(ItemStack stack, boolean activated)
|
|
|
|
{
|
|
|
|
if (stack != null)
|
|
|
|
{
|
|
|
|
NBTHelper.checkNBT(stack).getTagCompound().setBoolean(Constants.NBT.ACTIVATED, activated);
|
|
|
|
return stack;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
2015-12-29 19:32:35 +00:00
|
|
|
}
|