Fixed it so that if the Sentient Specters hit each other and they have the same owner they will not attack each other

This commit is contained in:
WayofTime 2016-08-16 21:41:02 -04:00
parent 939e1c3946
commit 5592e8661b
9 changed files with 298 additions and 27 deletions

View file

@ -0,0 +1,9 @@
package WayofTime.bloodmagic.api.iface;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
public interface ISentientTool
{
boolean spawnSentientEntityOnDrop(ItemStack droppedStack, EntityPlayer player);
}

View file

@ -0,0 +1,32 @@
package WayofTime.bloodmagic.entity.ai;
import java.util.UUID;
import net.minecraft.entity.EntityCreature;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.IEntityOwnable;
import net.minecraft.entity.ai.EntityAIHurtByTarget;
public class EntityAIHurtByTargetIgnoreTamed extends EntityAIHurtByTarget
{
public EntityAIHurtByTargetIgnoreTamed(EntityCreature creatureIn, boolean entityCallsForHelpIn, Class<?>... targetClassesIn)
{
super(creatureIn, true, targetClassesIn);
}
@Override
public boolean isSuitableTarget(EntityLivingBase target, boolean includeInvincibles)
{
if (this.taskOwner instanceof IEntityOwnable && target instanceof IEntityOwnable)
{
UUID thisId = ((IEntityOwnable) this.taskOwner).getOwnerId();
UUID targetId = ((IEntityOwnable) target).getOwnerId();
if (thisId != null && targetId != null && thisId.equals(targetId))
{
return false;
}
}
return super.isSuitableTarget(target, includeInvincibles);
}
}

View file

@ -4,6 +4,8 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import javax.annotation.Nullable;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import net.minecraft.block.Block; import net.minecraft.block.Block;
@ -13,7 +15,6 @@ import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.IEntityOwnable; import net.minecraft.entity.IEntityOwnable;
import net.minecraft.entity.SharedMonsterAttributes; import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.EntityAIAttackMelee; import net.minecraft.entity.ai.EntityAIAttackMelee;
import net.minecraft.entity.ai.EntityAIHurtByTarget;
import net.minecraft.entity.ai.EntityAILookIdle; import net.minecraft.entity.ai.EntityAILookIdle;
import net.minecraft.entity.ai.EntityAINearestAttackableTarget; import net.minecraft.entity.ai.EntityAINearestAttackableTarget;
import net.minecraft.entity.ai.EntityAISwimming; import net.minecraft.entity.ai.EntityAISwimming;
@ -39,6 +40,7 @@ import net.minecraft.network.datasync.EntityDataManager;
import net.minecraft.potion.PotionEffect; import net.minecraft.potion.PotionEffect;
import net.minecraft.server.management.PreYggdrasilConverter; import net.minecraft.server.management.PreYggdrasilConverter;
import net.minecraft.util.DamageSource; import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumHand;
import net.minecraft.util.SoundEvent; import net.minecraft.util.SoundEvent;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
@ -50,6 +52,7 @@ import WayofTime.bloodmagic.api.soul.EnumDemonWillType;
import WayofTime.bloodmagic.entity.ai.EntityAIAttackRangedBow; import WayofTime.bloodmagic.entity.ai.EntityAIAttackRangedBow;
import WayofTime.bloodmagic.entity.ai.EntityAIFollowOwner; import WayofTime.bloodmagic.entity.ai.EntityAIFollowOwner;
import WayofTime.bloodmagic.entity.ai.EntityAIGrabEffectsFromOwner; import WayofTime.bloodmagic.entity.ai.EntityAIGrabEffectsFromOwner;
import WayofTime.bloodmagic.entity.ai.EntityAIHurtByTargetIgnoreTamed;
import WayofTime.bloodmagic.entity.ai.EntityAIOwnerHurtByTarget; import WayofTime.bloodmagic.entity.ai.EntityAIOwnerHurtByTarget;
import WayofTime.bloodmagic.entity.ai.EntityAIOwnerHurtTarget; import WayofTime.bloodmagic.entity.ai.EntityAIOwnerHurtTarget;
import WayofTime.bloodmagic.item.soul.ItemSentientBow; import WayofTime.bloodmagic.item.soul.ItemSentientBow;
@ -66,6 +69,10 @@ public class EntitySentientSpecter extends EntityMob implements IEntityOwnable
@Setter @Setter
protected EnumDemonWillType type = EnumDemonWillType.DESTRUCTIVE; protected EnumDemonWillType type = EnumDemonWillType.DESTRUCTIVE;
@Getter
@Setter
protected boolean wasGivenSentientArmour = false;
private final EntityAIAttackRangedBow aiArrowAttack = new EntityAIAttackRangedBow(this, 1.0D, 20, 15.0F); private final EntityAIAttackRangedBow aiArrowAttack = new EntityAIAttackRangedBow(this, 1.0D, 20, 15.0F);
private final EntityAIAttackMelee aiAttackOnCollide = new EntityAIAttackMelee(this, 1.0D, false); private final EntityAIAttackMelee aiAttackOnCollide = new EntityAIAttackMelee(this, 1.0D, false);
@ -88,7 +95,7 @@ public class EntitySentientSpecter extends EntityMob implements IEntityOwnable
this.targetTasks.addTask(2, new EntityAIOwnerHurtTarget(this)); this.targetTasks.addTask(2, new EntityAIOwnerHurtTarget(this));
this.targetTasks.addTask(3, new EntityAINearestAttackableTarget<EntityPlayer>(this, EntityPlayer.class, true)); this.targetTasks.addTask(3, new EntityAINearestAttackableTarget<EntityPlayer>(this, EntityPlayer.class, true));
this.targetTasks.addTask(3, new EntityAIHurtByTarget(this, true, new Class[0])); this.targetTasks.addTask(4, new EntityAIHurtByTargetIgnoreTamed(this, false, new Class[0]));
this.setCombatTask(); this.setCombatTask();
// this.targetTasks.addTask(8, new EntityAINearestAttackableTarget<EntityCreature>(this, EntityCreature.class, true)); // this.targetTasks.addTask(8, new EntityAINearestAttackableTarget<EntityCreature>(this, EntityCreature.class, true));
@ -299,6 +306,17 @@ public class EntitySentientSpecter extends EntityMob implements IEntityOwnable
} }
} }
@Override
public void onDeath(DamageSource cause)
{
super.onDeath(cause);
if (!worldObj.isRemote)
{
this.entityDropItem(getHeldItemMainhand(), 0);
}
}
public boolean isStationary() public boolean isStationary()
{ {
return false; return false;
@ -318,6 +336,38 @@ public class EntitySentientSpecter extends EntityMob implements IEntityOwnable
return false; return false;
} }
@Override
public boolean processInteract(EntityPlayer player, EnumHand hand, @Nullable ItemStack stack)
{
if (this.isTamed() && player.equals(this.getOwner()) && hand == EnumHand.MAIN_HAND)
{
if (stack == null && player.isSneaking()) //Should return to the entity
{
if (!worldObj.isRemote)
{
if (getHeldItemMainhand() != null)
{
this.entityDropItem(getHeldItemMainhand(), 0);
}
if (getHeldItemOffhand() != null)
{
this.entityDropItem(getHeldItemOffhand(), 0);
}
if (wasGivenSentientArmour)
{
this.entityDropItem(new ItemStack(ModItems.sentientArmourGem), 0);
}
this.setDead();
}
}
}
return super.processInteract(player, hand, stack);
}
public boolean isEntityInvulnerable(DamageSource source) public boolean isEntityInvulnerable(DamageSource source)
{ {
return super.isEntityInvulnerable(source) && (this.type == EnumDemonWillType.DESTRUCTIVE && source.isExplosion()); return super.isEntityInvulnerable(source) && (this.type == EnumDemonWillType.DESTRUCTIVE && source.isExplosion());
@ -343,6 +393,8 @@ public class EntitySentientSpecter extends EntityMob implements IEntityOwnable
} }
tag.setString(Constants.NBT.WILL_TYPE, type.toString()); tag.setString(Constants.NBT.WILL_TYPE, type.toString());
tag.setBoolean("sentientArmour", wasGivenSentientArmour);
} }
@Override @Override
@ -381,6 +433,8 @@ public class EntitySentientSpecter extends EntityMob implements IEntityOwnable
type = EnumDemonWillType.valueOf(tag.getString(Constants.NBT.WILL_TYPE)); type = EnumDemonWillType.valueOf(tag.getString(Constants.NBT.WILL_TYPE));
} }
wasGivenSentientArmour = tag.getBoolean("sentientArmour");
this.setCombatTask(); this.setCombatTask();
} }

View file

@ -34,6 +34,7 @@ import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.api.Constants; import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.api.iface.IMultiWillTool; import WayofTime.bloodmagic.api.iface.IMultiWillTool;
import WayofTime.bloodmagic.api.iface.ISentientSwordEffectProvider; import WayofTime.bloodmagic.api.iface.ISentientSwordEffectProvider;
import WayofTime.bloodmagic.api.iface.ISentientTool;
import WayofTime.bloodmagic.api.soul.EnumDemonWillType; import WayofTime.bloodmagic.api.soul.EnumDemonWillType;
import WayofTime.bloodmagic.api.soul.IDemonWill; import WayofTime.bloodmagic.api.soul.IDemonWill;
import WayofTime.bloodmagic.api.soul.IDemonWillWeapon; import WayofTime.bloodmagic.api.soul.IDemonWillWeapon;
@ -41,13 +42,14 @@ import WayofTime.bloodmagic.api.soul.PlayerDemonWillHandler;
import WayofTime.bloodmagic.api.util.helper.NBTHelper; import WayofTime.bloodmagic.api.util.helper.NBTHelper;
import WayofTime.bloodmagic.client.IMeshProvider; import WayofTime.bloodmagic.client.IMeshProvider;
import WayofTime.bloodmagic.client.mesh.CustomMeshDefinitionMultiWill; import WayofTime.bloodmagic.client.mesh.CustomMeshDefinitionMultiWill;
import WayofTime.bloodmagic.entity.mob.EntitySentientSpecter;
import WayofTime.bloodmagic.registry.ModItems; import WayofTime.bloodmagic.registry.ModItems;
import WayofTime.bloodmagic.util.helper.TextHelper; import WayofTime.bloodmagic.util.helper.TextHelper;
import com.google.common.collect.HashMultimap; import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
public class ItemSentientAxe extends ItemAxe implements IDemonWillWeapon, IMeshProvider, IMultiWillTool public class ItemSentientAxe extends ItemAxe implements IDemonWillWeapon, IMeshProvider, IMultiWillTool, ISentientTool
{ {
public static int[] soulBracket = new int[] { 16, 60, 200, 400, 1000 }; public static int[] soulBracket = new int[] { 16, 60, 200, 400, 1000 };
public static double[] defaultDamageAdded = new double[] { 1, 2, 3, 3.5, 4 }; public static double[] defaultDamageAdded = new double[] { 1, 2, 3, 3.5, 4 };
@ -538,4 +540,37 @@ public class ItemSentientAxe extends ItemAxe implements IDemonWillWeapon, IMeshP
tag.setDouble(Constants.NBT.SOUL_SWORD_DIG_SPEED, speed); tag.setDouble(Constants.NBT.SOUL_SWORD_DIG_SPEED, speed);
} }
@Override
public boolean spawnSentientEntityOnDrop(ItemStack droppedStack, EntityPlayer player)
{
World world = player.worldObj;
if (!world.isRemote)
{
this.recalculatePowers(droppedStack, world, player);
EnumDemonWillType type = this.getCurrentType(droppedStack);
double soulsRemaining = PlayerDemonWillHandler.getTotalDemonWill(type, player);
if (soulsRemaining < 1024)
{
return false;
}
PlayerDemonWillHandler.consumeDemonWill(type, player, 100);
EntitySentientSpecter specterEntity = new EntitySentientSpecter(world);
specterEntity.setPosition(player.posX, player.posY, player.posZ);
world.spawnEntityInWorld(specterEntity);
specterEntity.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, droppedStack.copy());
specterEntity.setType(this.getCurrentType(droppedStack));
specterEntity.setOwner(player);
specterEntity.setTamed(true);
return true;
}
return false;
}
} }

View file

@ -8,6 +8,7 @@ import net.minecraft.entity.projectile.EntityTippedArrow;
import net.minecraft.init.Enchantments; import net.minecraft.init.Enchantments;
import net.minecraft.init.Items; import net.minecraft.init.Items;
import net.minecraft.init.SoundEvents; import net.minecraft.init.SoundEvents;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.IItemPropertyGetter; import net.minecraft.item.IItemPropertyGetter;
import net.minecraft.item.ItemBow; import net.minecraft.item.ItemBow;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
@ -24,13 +25,15 @@ import net.minecraftforge.fml.relauncher.SideOnly;
import WayofTime.bloodmagic.BloodMagic; import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.api.Constants; import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.api.iface.IMultiWillTool; import WayofTime.bloodmagic.api.iface.IMultiWillTool;
import WayofTime.bloodmagic.api.iface.ISentientTool;
import WayofTime.bloodmagic.api.soul.EnumDemonWillType; import WayofTime.bloodmagic.api.soul.EnumDemonWillType;
import WayofTime.bloodmagic.api.soul.PlayerDemonWillHandler; import WayofTime.bloodmagic.api.soul.PlayerDemonWillHandler;
import WayofTime.bloodmagic.api.util.helper.NBTHelper; import WayofTime.bloodmagic.api.util.helper.NBTHelper;
import WayofTime.bloodmagic.entity.mob.EntitySentientSpecter;
import WayofTime.bloodmagic.entity.projectile.EntitySentientArrow; import WayofTime.bloodmagic.entity.projectile.EntitySentientArrow;
import WayofTime.bloodmagic.registry.ModItems; import WayofTime.bloodmagic.registry.ModItems;
public class ItemSentientBow extends ItemBow implements IMultiWillTool//, IMeshProvider public class ItemSentientBow extends ItemBow implements IMultiWillTool, ISentientTool//, IMeshProvider
{ {
public static int[] soulBracket = new int[] { 16, 60, 200, 400, 1000 }; public static int[] soulBracket = new int[] { 16, 60, 200, 400, 1000 };
public static double[] defaultDamageAdded = new double[] { 0.25, 0.5, 0.75, 1, 1.25 }; public static double[] defaultDamageAdded = new double[] { 0.25, 0.5, 0.75, 1, 1.25 };
@ -444,4 +447,37 @@ public class ItemSentientBow extends ItemBow implements IMultiWillTool//, IMeshP
return null; return null;
} }
} }
@Override
public boolean spawnSentientEntityOnDrop(ItemStack droppedStack, EntityPlayer player)
{
World world = player.worldObj;
if (!world.isRemote)
{
this.recalculatePowers(droppedStack, world, player);
EnumDemonWillType type = this.getCurrentType(droppedStack);
double soulsRemaining = PlayerDemonWillHandler.getTotalDemonWill(type, player);
if (soulsRemaining < 1024)
{
return false;
}
PlayerDemonWillHandler.consumeDemonWill(type, player, 100);
EntitySentientSpecter specterEntity = new EntitySentientSpecter(world);
specterEntity.setPosition(player.posX, player.posY, player.posZ);
world.spawnEntityInWorld(specterEntity);
specterEntity.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, droppedStack.copy());
specterEntity.setType(this.getCurrentType(droppedStack));
specterEntity.setOwner(player);
specterEntity.setTamed(true);
return true;
}
return false;
}
} }

View file

@ -34,6 +34,7 @@ import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.api.Constants; import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.api.iface.IMultiWillTool; import WayofTime.bloodmagic.api.iface.IMultiWillTool;
import WayofTime.bloodmagic.api.iface.ISentientSwordEffectProvider; import WayofTime.bloodmagic.api.iface.ISentientSwordEffectProvider;
import WayofTime.bloodmagic.api.iface.ISentientTool;
import WayofTime.bloodmagic.api.soul.EnumDemonWillType; import WayofTime.bloodmagic.api.soul.EnumDemonWillType;
import WayofTime.bloodmagic.api.soul.IDemonWill; import WayofTime.bloodmagic.api.soul.IDemonWill;
import WayofTime.bloodmagic.api.soul.IDemonWillWeapon; import WayofTime.bloodmagic.api.soul.IDemonWillWeapon;
@ -41,13 +42,14 @@ import WayofTime.bloodmagic.api.soul.PlayerDemonWillHandler;
import WayofTime.bloodmagic.api.util.helper.NBTHelper; import WayofTime.bloodmagic.api.util.helper.NBTHelper;
import WayofTime.bloodmagic.client.IMeshProvider; import WayofTime.bloodmagic.client.IMeshProvider;
import WayofTime.bloodmagic.client.mesh.CustomMeshDefinitionMultiWill; import WayofTime.bloodmagic.client.mesh.CustomMeshDefinitionMultiWill;
import WayofTime.bloodmagic.entity.mob.EntitySentientSpecter;
import WayofTime.bloodmagic.registry.ModItems; import WayofTime.bloodmagic.registry.ModItems;
import WayofTime.bloodmagic.util.helper.TextHelper; import WayofTime.bloodmagic.util.helper.TextHelper;
import com.google.common.collect.HashMultimap; import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
public class ItemSentientPickaxe extends ItemPickaxe implements IDemonWillWeapon, IMeshProvider, IMultiWillTool public class ItemSentientPickaxe extends ItemPickaxe implements IDemonWillWeapon, IMeshProvider, IMultiWillTool, ISentientTool
{ {
public static int[] soulBracket = new int[] { 16, 60, 200, 400, 1000 }; public static int[] soulBracket = new int[] { 16, 60, 200, 400, 1000 };
public static double[] defaultDamageAdded = new double[] { 1, 2, 3, 3.5, 4 }; public static double[] defaultDamageAdded = new double[] { 1, 2, 3, 3.5, 4 };
@ -538,4 +540,37 @@ public class ItemSentientPickaxe extends ItemPickaxe implements IDemonWillWeapon
tag.setDouble(Constants.NBT.SOUL_SWORD_DIG_SPEED, speed); tag.setDouble(Constants.NBT.SOUL_SWORD_DIG_SPEED, speed);
} }
@Override
public boolean spawnSentientEntityOnDrop(ItemStack droppedStack, EntityPlayer player)
{
World world = player.worldObj;
if (!world.isRemote)
{
this.recalculatePowers(droppedStack, world, player);
EnumDemonWillType type = this.getCurrentType(droppedStack);
double soulsRemaining = PlayerDemonWillHandler.getTotalDemonWill(type, player);
if (soulsRemaining < 1024)
{
return false;
}
PlayerDemonWillHandler.consumeDemonWill(type, player, 100);
EntitySentientSpecter specterEntity = new EntitySentientSpecter(world);
specterEntity.setPosition(player.posX, player.posY, player.posZ);
world.spawnEntityInWorld(specterEntity);
specterEntity.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, droppedStack.copy());
specterEntity.setType(this.getCurrentType(droppedStack));
specterEntity.setOwner(player);
specterEntity.setTamed(true);
return true;
}
return false;
}
} }

View file

@ -34,6 +34,7 @@ import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.api.Constants; import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.api.iface.IMultiWillTool; import WayofTime.bloodmagic.api.iface.IMultiWillTool;
import WayofTime.bloodmagic.api.iface.ISentientSwordEffectProvider; import WayofTime.bloodmagic.api.iface.ISentientSwordEffectProvider;
import WayofTime.bloodmagic.api.iface.ISentientTool;
import WayofTime.bloodmagic.api.soul.EnumDemonWillType; import WayofTime.bloodmagic.api.soul.EnumDemonWillType;
import WayofTime.bloodmagic.api.soul.IDemonWill; import WayofTime.bloodmagic.api.soul.IDemonWill;
import WayofTime.bloodmagic.api.soul.IDemonWillWeapon; import WayofTime.bloodmagic.api.soul.IDemonWillWeapon;
@ -41,13 +42,14 @@ import WayofTime.bloodmagic.api.soul.PlayerDemonWillHandler;
import WayofTime.bloodmagic.api.util.helper.NBTHelper; import WayofTime.bloodmagic.api.util.helper.NBTHelper;
import WayofTime.bloodmagic.client.IMeshProvider; import WayofTime.bloodmagic.client.IMeshProvider;
import WayofTime.bloodmagic.client.mesh.CustomMeshDefinitionMultiWill; import WayofTime.bloodmagic.client.mesh.CustomMeshDefinitionMultiWill;
import WayofTime.bloodmagic.entity.mob.EntitySentientSpecter;
import WayofTime.bloodmagic.registry.ModItems; import WayofTime.bloodmagic.registry.ModItems;
import WayofTime.bloodmagic.util.helper.TextHelper; import WayofTime.bloodmagic.util.helper.TextHelper;
import com.google.common.collect.HashMultimap; import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
public class ItemSentientShovel extends ItemSpade implements IDemonWillWeapon, IMeshProvider, IMultiWillTool public class ItemSentientShovel extends ItemSpade implements IDemonWillWeapon, IMeshProvider, IMultiWillTool, ISentientTool
{ {
public static int[] soulBracket = new int[] { 16, 60, 200, 400, 1000 }; public static int[] soulBracket = new int[] { 16, 60, 200, 400, 1000 };
public static double[] defaultDamageAdded = new double[] { 1, 2, 3, 3.5, 4 }; public static double[] defaultDamageAdded = new double[] { 1, 2, 3, 3.5, 4 };
@ -538,4 +540,37 @@ public class ItemSentientShovel extends ItemSpade implements IDemonWillWeapon, I
tag.setDouble(Constants.NBT.SOUL_SWORD_DIG_SPEED, speed); tag.setDouble(Constants.NBT.SOUL_SWORD_DIG_SPEED, speed);
} }
@Override
public boolean spawnSentientEntityOnDrop(ItemStack droppedStack, EntityPlayer player)
{
World world = player.worldObj;
if (!world.isRemote)
{
this.recalculatePowers(droppedStack, world, player);
EnumDemonWillType type = this.getCurrentType(droppedStack);
double soulsRemaining = PlayerDemonWillHandler.getTotalDemonWill(type, player);
if (soulsRemaining < 1024)
{
return false;
}
PlayerDemonWillHandler.consumeDemonWill(type, player, 100);
EntitySentientSpecter specterEntity = new EntitySentientSpecter(world);
specterEntity.setPosition(player.posX, player.posY, player.posZ);
world.spawnEntityInWorld(specterEntity);
specterEntity.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, droppedStack.copy());
specterEntity.setType(this.getCurrentType(droppedStack));
specterEntity.setOwner(player);
specterEntity.setTamed(true);
return true;
}
return false;
}
} }

View file

@ -32,6 +32,7 @@ import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.api.Constants; import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.api.iface.IMultiWillTool; import WayofTime.bloodmagic.api.iface.IMultiWillTool;
import WayofTime.bloodmagic.api.iface.ISentientSwordEffectProvider; import WayofTime.bloodmagic.api.iface.ISentientSwordEffectProvider;
import WayofTime.bloodmagic.api.iface.ISentientTool;
import WayofTime.bloodmagic.api.soul.EnumDemonWillType; import WayofTime.bloodmagic.api.soul.EnumDemonWillType;
import WayofTime.bloodmagic.api.soul.IDemonWill; import WayofTime.bloodmagic.api.soul.IDemonWill;
import WayofTime.bloodmagic.api.soul.IDemonWillWeapon; import WayofTime.bloodmagic.api.soul.IDemonWillWeapon;
@ -46,7 +47,7 @@ import WayofTime.bloodmagic.util.helper.TextHelper;
import com.google.common.collect.HashMultimap; import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
public class ItemSentientSword extends ItemSword implements IDemonWillWeapon, IMeshProvider, IMultiWillTool public class ItemSentientSword extends ItemSword implements IDemonWillWeapon, IMeshProvider, IMultiWillTool, ISentientTool
{ {
public static int[] soulBracket = new int[] { 16, 60, 200, 400, 1000, 2000, 4000 }; public static int[] soulBracket = new int[] { 16, 60, 200, 400, 1000, 2000, 4000 };
public static double[] defaultDamageAdded = new double[] { 1, 1.5, 2, 2.5, 3, 3.5, 4 }; public static double[] defaultDamageAdded = new double[] { 1, 1.5, 2, 2.5, 3, 3.5, 4 };
@ -252,26 +253,6 @@ public class ItemSentientSword extends ItemSword implements IDemonWillWeapon, IM
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand) public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand)
{ {
recalculatePowers(stack, world, player); recalculatePowers(stack, world, player);
if (!world.isRemote && spawnSpecterOnClick)
{
EntitySentientSpecter specterEntity = new EntitySentientSpecter(world);
specterEntity.setPosition(player.posX, player.posY, player.posZ);
world.spawnEntityInWorld(specterEntity);
System.out.println("Spawning Specter...");
ItemStack bowStack = new ItemStack(ModItems.sentientBow);
((ItemSentientBow) ModItems.sentientBow).recalculatePowers(bowStack, EnumDemonWillType.CORROSIVE, 1025);
specterEntity.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, bowStack);
// specterEntity.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, stack.copy());
// specterEntity.setItemStackToSlot(EntityEquipmentSlot.HEAD, new ItemStack(ModItems.sentientArmourHelmet));
// specterEntity.setItemStackToSlot(EntityEquipmentSlot.CHEST, new ItemStack(ModItems.sentientArmourChest));
// specterEntity.setItemStackToSlot(EntityEquipmentSlot.LEGS, new ItemStack(ModItems.sentientArmourLegs));
// specterEntity.setItemStackToSlot(EntityEquipmentSlot.FEET, new ItemStack(ModItems.sentientArmourBoots));
specterEntity.setType(this.getCurrentType(stack));
specterEntity.setOwner(player);
specterEntity.setTamed(true);
}
return super.onItemRightClick(stack, world, player, hand); return super.onItemRightClick(stack, world, player, hand);
} }
@ -516,4 +497,37 @@ public class ItemSentientSword extends ItemSword implements IDemonWillWeapon, IM
tag.setDouble(Constants.NBT.SOUL_SWORD_SPEED, speed); tag.setDouble(Constants.NBT.SOUL_SWORD_SPEED, speed);
} }
@Override
public boolean spawnSentientEntityOnDrop(ItemStack droppedStack, EntityPlayer player)
{
World world = player.worldObj;
if (!world.isRemote)
{
this.recalculatePowers(droppedStack, world, player);
EnumDemonWillType type = this.getCurrentType(droppedStack);
double soulsRemaining = PlayerDemonWillHandler.getTotalDemonWill(type, player);
if (soulsRemaining < 1024)
{
return false;
}
PlayerDemonWillHandler.consumeDemonWill(type, player, 100);
EntitySentientSpecter specterEntity = new EntitySentientSpecter(world);
specterEntity.setPosition(player.posX, player.posY, player.posZ);
world.spawnEntityInWorld(specterEntity);
specterEntity.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, droppedStack.copy());
specterEntity.setType(this.getCurrentType(droppedStack));
specterEntity.setOwner(player);
specterEntity.setTamed(true);
return true;
}
return false;
}
} }

View file

@ -13,6 +13,7 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Enchantments; import net.minecraft.init.Enchantments;
import net.minecraft.inventory.EntityEquipmentSlot; import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.DamageSource; import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumHand; import net.minecraft.util.EnumHand;
@ -23,6 +24,7 @@ import net.minecraft.util.math.Vec3d;
import net.minecraft.world.Explosion; import net.minecraft.world.Explosion;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.item.ItemTossEvent;
import net.minecraftforge.event.entity.living.LivingDropsEvent; import net.minecraftforge.event.entity.living.LivingDropsEvent;
import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent; import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent;
import net.minecraftforge.event.entity.living.LivingHurtEvent; import net.minecraftforge.event.entity.living.LivingHurtEvent;
@ -41,6 +43,7 @@ import WayofTime.bloodmagic.api.event.ItemBindEvent;
import WayofTime.bloodmagic.api.event.SacrificeKnifeUsedEvent; import WayofTime.bloodmagic.api.event.SacrificeKnifeUsedEvent;
import WayofTime.bloodmagic.api.event.TeleposeEvent; import WayofTime.bloodmagic.api.event.TeleposeEvent;
import WayofTime.bloodmagic.api.iface.IBindable; import WayofTime.bloodmagic.api.iface.IBindable;
import WayofTime.bloodmagic.api.iface.ISentientTool;
import WayofTime.bloodmagic.api.livingArmour.LivingArmourUpgrade; import WayofTime.bloodmagic.api.livingArmour.LivingArmourUpgrade;
import WayofTime.bloodmagic.api.orb.IBloodOrb; import WayofTime.bloodmagic.api.orb.IBloodOrb;
import WayofTime.bloodmagic.api.saving.SoulNetwork; import WayofTime.bloodmagic.api.saving.SoulNetwork;
@ -87,6 +90,24 @@ public class GenericHandler
} }
} }
@SubscribeEvent
public void onPlayerDropItem(ItemTossEvent event)
{
EntityItem itemEntity = event.getEntityItem();
if (itemEntity != null)
{
ItemStack stack = itemEntity.getEntityItem();
Item item = stack.getItem();
if (item instanceof ISentientTool)
{
if (((ISentientTool) item).spawnSentientEntityOnDrop(stack, event.getPlayer()))
{
event.setCanceled(true);
}
}
}
}
@SubscribeEvent @SubscribeEvent
public void onExplosion(ExplosionEvent.Start event) public void onExplosion(ExplosionEvent.Start event)
{ {