Merge pull request #567 from Arcaratus/1.8-Rewrite

Fixed up Bound Sword
This commit is contained in:
Nick Ignoffo 2016-01-25 13:23:30 -08:00
commit 895413f0f0
2 changed files with 21 additions and 92 deletions

View file

@ -2,36 +2,27 @@ package WayofTime.bloodmagic.item;
import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.api.event.BoundToolEvent;
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;
import WayofTime.bloodmagic.util.helper.TextHelper;
import com.google.common.base.Strings;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumAction;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemSword;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.StatCollector;
import net.minecraft.world.Explosion;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.ForgeEventFactory;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import java.util.List;
public class ItemBoundSword extends ItemSword
public class ItemBoundSword extends ItemSword implements IBindable
{
private int lpUsed;
public ItemBoundSword()
{
super(ModItems.boundToolMaterial);
@ -41,91 +32,22 @@ public class ItemBoundSword extends ItemSword
setHasSubtypes(true);
setNoRepair();
setCreativeTab(BloodMagic.tabBloodMagic);
this.lpUsed = 50;
}
@Override
public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityPlayer playerIn, int timeLeft)
{
if (!playerIn.isSneaking() && getActivated(stack))
{
int i = this.getMaxItemUseDuration(stack) - timeLeft;
BoundToolEvent.Release event = new BoundToolEvent.Release(playerIn, stack, i);
if (MinecraftForge.EVENT_BUS.post(event))
return;
i = event.charge;
// TODO Make conical charge blast
Explosion explosion = new Explosion(worldIn, playerIn, playerIn.posX, playerIn.posY, playerIn.posZ, (float) (i * 0.5), true, true);
ItemBindable.syphonNetwork(stack, playerIn, (int) (i * i * i / 2.7));
if (ForgeEventFactory.onExplosionStart(worldIn, explosion))
return;
explosion.doExplosionA();
explosion.doExplosionB(true);
}
}
@Override
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player)
{
BindableHelper.checkAndSetItemOwner(stack, player);
// if (!world.isRemote)
{
if (player.isSneaking())
setActivated(stack, !getActivated(stack));
if (getActivated(stack) && ItemBindable.syphonNetwork(stack, player, lpUsed))
return stack;
if (!player.isSneaking() && getActivated(stack))
player.setItemInUse(stack, this.getMaxItemUseDuration(stack));
if (!player.isSneaking() && getActivated(stack))
{
BoundToolEvent.Charge event = new BoundToolEvent.Charge(player, stack);
if (MinecraftForge.EVENT_BUS.post(event))
return event.result;
player.setItemInUse(stack, this.getMaxItemUseDuration(stack));
}
}
if (player.isSneaking())
setActivated(stack, !getActivated(stack));
return stack;
}
@Override
public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker)
{
if (getActivated(stack))
{
if (target != null || attacker != null)
{
if (target instanceof EntityLiving)
{
if (!target.isPotionActive(Potion.weakness))
target.addPotionEffect(new PotionEffect(Potion.weakness.id, 60, 2));
}
}
return true;
}
return false;
}
@Override
public ItemStack onItemUseFinish(ItemStack stack, World worldIn, EntityPlayer playerIn)
{
return stack;
}
@Override
public EnumAction getItemUseAction(ItemStack stack)
{
return EnumAction.BLOCK;
}
@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, EntityPlayer player, List<String> tooltip, boolean advanced)
@ -138,10 +60,10 @@ public class ItemBoundSword extends ItemSword
tooltip.add(TextHelper.localize("tooltip.BloodMagic." + (getActivated(stack) ? "activated" : "deactivated")));
if (!Strings.isNullOrEmpty(stack.getTagCompound().getString(Constants.NBT.OWNER_UUID)))
tooltip.add(TextHelper.localizeEffect("tooltip.BloodMagic.currentOwner", stack.getTagCompound().getString(Constants.NBT.OWNER_UUID)));
tooltip.add(TextHelper.localizeEffect("tooltip.BloodMagic.currentOwner", PlayerHelper.getUsernameFromStack(stack)));
}
private boolean getActivated(ItemStack stack)
public boolean getActivated(ItemStack stack)
{
return stack.getItemDamage() > 0;
}
@ -152,4 +74,12 @@ public class ItemBoundSword extends ItemSword
return stack;
}
// IBindable
@Override
public boolean onBind(EntityPlayer player, ItemStack stack)
{
return true;
}
}

View file

@ -71,10 +71,10 @@ public class ItemBoundTool extends ItemBindable
EntityPlayer player = (EntityPlayer) entityIn;
setHeldDownCount(stack, Math.min(player.getItemInUseDuration(), chargeTime));
}
// else if (!isSelected)
// {
// //TODO Make it so that if you scroll of while charging, does not show the charge bar
// }
else if (!isSelected)
{
setBeingHeldDown(stack, false);
}
}
protected int getHeldDownCount(ItemStack stack)
@ -110,7 +110,6 @@ public class ItemBoundTool extends ItemBindable
@Override
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player)
{
BindableHelper.checkAndSetItemOwner(stack, player);
// if (!world.isRemote)