Created visual niceties when an item uses/contains a different will type.

This commit is contained in:
WayofTime 2016-03-28 20:14:05 -04:00
parent 09e90f93c3
commit 4ea3e0ca92
9 changed files with 349 additions and 117 deletions

View file

@ -0,0 +1,9 @@
package WayofTime.bloodmagic.api.iface;
import net.minecraft.item.ItemStack;
import WayofTime.bloodmagic.api.soul.EnumDemonWillType;
public interface IMultiWillTool
{
public EnumDemonWillType getCurrentType(ItemStack stack);
}

View file

@ -43,6 +43,23 @@ public class PlayerDemonWillHandler
return souls;
}
public static EnumDemonWillType getLargestWillType(EntityPlayer player)
{
EnumDemonWillType type = EnumDemonWillType.DEFAULT;
double max = 0;
for (EnumDemonWillType testType : EnumDemonWillType.values())
{
double value = getTotalDemonWill(testType, player);
if (value > max)
{
type = testType;
}
}
return type;
}
/**
* Checks if the player's Tartaric gems are completely full.
*

View file

@ -0,0 +1,31 @@
package WayofTime.bloodmagic.client.mesh;
import net.minecraft.client.renderer.ItemMeshDefinition;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.api.iface.IMultiWillTool;
import WayofTime.bloodmagic.api.soul.EnumDemonWillType;
public class CustomMeshDefinitionMultiWill implements ItemMeshDefinition
{
private final String name;
public CustomMeshDefinitionMultiWill(String name)
{
this.name = name;
}
@Override
public ModelResourceLocation getModelLocation(ItemStack stack)
{
if (stack != null && stack.getItem() instanceof IMultiWillTool)
{
EnumDemonWillType type = ((IMultiWillTool) stack.getItem()).getCurrentType(stack);
return new ModelResourceLocation(new ResourceLocation(Constants.Mod.MODID, "item/" + name), "type=" + type.getName().toLowerCase());
}
return new ModelResourceLocation(new ResourceLocation(Constants.Mod.MODID, "item/" + name), "type=default");
}
}

View file

@ -0,0 +1,32 @@
package WayofTime.bloodmagic.client.mesh;
import net.minecraft.client.renderer.ItemMeshDefinition;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.api.soul.EnumDemonWillType;
import WayofTime.bloodmagic.item.soul.ItemSoulGem;
import WayofTime.bloodmagic.registry.ModItems;
public class CustomMeshDefinitionWillGem implements ItemMeshDefinition
{
private final String name;
public CustomMeshDefinitionWillGem(String name)
{
this.name = name;
}
@Override
public ModelResourceLocation getModelLocation(ItemStack stack)
{
if (stack != null && stack.getItem() == ModItems.soulGem)
{
EnumDemonWillType type = ((ItemSoulGem) stack.getItem()).getCurrentType(stack);
return new ModelResourceLocation(new ResourceLocation(Constants.Mod.MODID, "item/" + name), "type=" + ItemSoulGem.names[stack.getItemDamage()] + "_" + type.getName().toLowerCase());
}
return new ModelResourceLocation(new ResourceLocation(Constants.Mod.MODID, "item/" + name), "type=petty_default");
}
}

View file

@ -13,12 +13,10 @@ import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.attributes.AttributeModifier;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.EnumAction;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemSword;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
@ -26,7 +24,7 @@ import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.api.iface.IActivatable;
import WayofTime.bloodmagic.api.iface.IMultiWillTool;
import WayofTime.bloodmagic.api.iface.ISentientSwordEffectProvider;
import WayofTime.bloodmagic.api.soul.EnumDemonWillType;
import WayofTime.bloodmagic.api.soul.IDemonWill;
@ -34,14 +32,14 @@ import WayofTime.bloodmagic.api.soul.IDemonWillWeapon;
import WayofTime.bloodmagic.api.soul.PlayerDemonWillHandler;
import WayofTime.bloodmagic.api.util.helper.NBTHelper;
import WayofTime.bloodmagic.client.IMeshProvider;
import WayofTime.bloodmagic.client.mesh.CustomMeshDefinitionActivatable;
import WayofTime.bloodmagic.client.mesh.CustomMeshDefinitionMultiWill;
import WayofTime.bloodmagic.registry.ModItems;
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, IActivatable, IMeshProvider
public class ItemSentientSword extends ItemSword implements IDemonWillWeapon, IMeshProvider, IMultiWillTool
{
public int[] soulBracket = new int[] { 16, 60, 200, 400 };
public double[] damageAdded = new double[] { 1, 1.5, 2, 2.5 };
@ -83,33 +81,52 @@ public class ItemSentientSword extends ItemSword implements IDemonWillWeapon, IA
return false;
}
@Override
public EnumDemonWillType getCurrentType(ItemStack stack)
{
return EnumDemonWillType.DEFAULT;
NBTHelper.checkNBT(stack);
NBTTagCompound tag = stack.getTagCompound();
if (!tag.hasKey(Constants.NBT.WILL_TYPE))
{
return EnumDemonWillType.DEFAULT;
}
return EnumDemonWillType.valueOf(tag.getString(Constants.NBT.WILL_TYPE));
}
public void setCurrentType(ItemStack stack, EnumDemonWillType type)
{
NBTHelper.checkNBT(stack);
NBTTagCompound tag = stack.getTagCompound();
tag.setString(Constants.NBT.WILL_TYPE, type.toString());
}
@Override
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand)
{
if (player.isSneaking())
setActivatedState(stack, !getActivated(stack));
recalculatePowers(stack, world, player);
if (getActivated(stack))
{
double soulsRemaining = PlayerDemonWillHandler.getTotalDemonWill(getCurrentType(stack), player);
int level = getLevel(stack, soulsRemaining);
return super.onItemRightClick(stack, world, player, hand);
}
double drain = level >= 0 ? soulDrainPerSwing[level] : 0;
double extraDamage = level >= 0 ? damageAdded[level] : 0;
public void recalculatePowers(ItemStack stack, World world, EntityPlayer player)
{
EnumDemonWillType type = PlayerDemonWillHandler.getLargestWillType(player);
double soulsRemaining = PlayerDemonWillHandler.getTotalDemonWill(type, player);
this.setCurrentType(stack, type);
int level = getLevel(stack, soulsRemaining);
setDrainOfActivatedSword(stack, drain);
setDamageOfActivatedSword(stack, 7 + extraDamage);
setStaticDropOfActivatedSword(stack, level >= 0 ? staticDrop[level] : 1);
setDropOfActivatedSword(stack, level >= 0 ? soulDrop[level] : 0);
}
double drain = level >= 0 ? soulDrainPerSwing[level] : 0;
double extraDamage = level >= 0 ? damageAdded[level] : 0;
player.setActiveHand(hand);
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
setDrainOfActivatedSword(stack, drain);
setDamageOfActivatedSword(stack, 7 + extraDamage);
setStaticDropOfActivatedSword(stack, level >= 0 ? staticDrop[level] : 1);
setDropOfActivatedSword(stack, level >= 0 ? soulDrop[level] : 0);
}
@Override
@ -132,12 +149,6 @@ public class ItemSentientSword extends ItemSword implements IDemonWillWeapon, IA
return lvl;
}
@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)
@ -146,32 +157,26 @@ public class ItemSentientSword extends ItemSword implements IDemonWillWeapon, IA
tooltip.addAll(Arrays.asList(TextHelper.cutLongString(TextHelper.localizeEffect("tooltip.BloodMagic.sentientSword.desc"))));
if (getActivated(stack))
tooltip.add(TextHelper.localize("tooltip.BloodMagic.activated"));
else
tooltip.add(TextHelper.localize("tooltip.BloodMagic.deactivated"));
tooltip.add(TextHelper.localizeEffect("tooltip.BloodMagic.currentType." + getCurrentType(stack).getName().toLowerCase()));
}
@Override
public boolean onLeftClickEntity(ItemStack stack, EntityPlayer player, Entity entity)
{
if (getActivated(stack))
{
double drain = this.getDrainOfActivatedSword(stack);
if (drain > 0)
{
EnumDemonWillType type = getCurrentType(stack);
double soulsRemaining = PlayerDemonWillHandler.getTotalDemonWill(type, player);
recalculatePowers(stack, player.worldObj, player);
if (drain > soulsRemaining)
{
setActivatedState(stack, false);
return false;
} else
{
PlayerDemonWillHandler.consumeDemonWill(type, player, drain);
}
double drain = this.getDrainOfActivatedSword(stack);
if (drain > 0)
{
EnumDemonWillType type = getCurrentType(stack);
double soulsRemaining = PlayerDemonWillHandler.getTotalDemonWill(type, player);
if (drain > soulsRemaining)
{
return false;
} else
{
PlayerDemonWillHandler.consumeDemonWill(type, player, drain);
}
}
@ -182,7 +187,7 @@ public class ItemSentientSword extends ItemSword implements IDemonWillWeapon, IA
@SideOnly(Side.CLIENT)
public ItemMeshDefinition getMeshDefinition()
{
return new CustomMeshDefinitionActivatable("ItemSentientSword");
return new CustomMeshDefinitionMultiWill("ItemSentientSword");
}
@Nullable
@ -196,43 +201,27 @@ public class ItemSentientSword extends ItemSword implements IDemonWillWeapon, IA
public List<String> getVariants()
{
List<String> ret = new ArrayList<String>();
ret.add("active=true");
ret.add("active=false");
for (EnumDemonWillType type : EnumDemonWillType.values())
{
ret.add("type=" + type.getName().toLowerCase());
}
return ret;
}
@Override
public boolean getActivated(ItemStack stack)
{
NBTHelper.checkNBT(stack);
return stack.getTagCompound().getBoolean(Constants.NBT.ACTIVATED);
}
@Override
public ItemStack setActivatedState(ItemStack stack, boolean activated)
{
NBTHelper.checkNBT(stack);
stack.getTagCompound().setBoolean(Constants.NBT.ACTIVATED, activated);
return stack;
}
@Override
public List<ItemStack> getRandomDemonWillDrop(EntityLivingBase killedEntity, EntityLivingBase attackingEntity, ItemStack stack, int looting)
{
List<ItemStack> soulList = new ArrayList<ItemStack>();
if (getActivated(stack))
{
IDemonWill soul = ((IDemonWill) ModItems.monsterSoul);
IDemonWill soul = ((IDemonWill) ModItems.monsterSoul);
for (int i = 0; i <= looting; i++)
for (int i = 0; i <= looting; i++)
{
if (i == 0 || attackingEntity.worldObj.rand.nextDouble() < 0.4)
{
if (i == 0 || attackingEntity.worldObj.rand.nextDouble() < 0.4)
{
ItemStack soulStack = soul.createWill(0, this.getDropOfActivatedSword(stack) * attackingEntity.worldObj.rand.nextDouble() + this.getStaticDropOfActivatedSword(stack));
soulList.add(soulStack);
}
ItemStack soulStack = soul.createWill(0, this.getDropOfActivatedSword(stack) * attackingEntity.worldObj.rand.nextDouble() + this.getStaticDropOfActivatedSword(stack));
soulList.add(soulStack);
}
}
@ -246,7 +235,7 @@ public class ItemSentientSword extends ItemSword implements IDemonWillWeapon, IA
Multimap<String, AttributeModifier> multimap = HashMultimap.<String, AttributeModifier>create();
if (slot == EntityEquipmentSlot.MAINHAND)
{
multimap.put(SharedMonsterAttributes.ATTACK_DAMAGE.getAttributeUnlocalizedName(), new AttributeModifier(ATTACK_DAMAGE_MODIFIER, "Weapon modifier", getActivated(stack) ? getDamageOfActivatedSword(stack) : 2, 0));
multimap.put(SharedMonsterAttributes.ATTACK_DAMAGE.getAttributeUnlocalizedName(), new AttributeModifier(ATTACK_DAMAGE_MODIFIER, "Weapon modifier", getDamageOfActivatedSword(stack), 0));
multimap.put(SharedMonsterAttributes.ATTACK_SPEED.getAttributeUnlocalizedName(), new AttributeModifier(ATTACK_SPEED_MODIFIER, "Weapon modifier", -2.4, 0));
}
return multimap;

View file

@ -1,14 +1,11 @@
package WayofTime.bloodmagic.item.soul;
import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.api.soul.EnumDemonWillType;
import WayofTime.bloodmagic.api.soul.IDemonWill;
import WayofTime.bloodmagic.api.soul.IDemonWillGem;
import WayofTime.bloodmagic.api.soul.PlayerDemonWillHandler;
import WayofTime.bloodmagic.api.util.helper.NBTHelper;
import WayofTime.bloodmagic.client.IVariantProvider;
import WayofTime.bloodmagic.util.helper.TextHelper;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nullable;
import net.minecraft.client.renderer.ItemMeshDefinition;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
@ -17,17 +14,23 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.api.iface.IMultiWillTool;
import WayofTime.bloodmagic.api.soul.EnumDemonWillType;
import WayofTime.bloodmagic.api.soul.IDemonWill;
import WayofTime.bloodmagic.api.soul.IDemonWillGem;
import WayofTime.bloodmagic.api.soul.PlayerDemonWillHandler;
import WayofTime.bloodmagic.api.util.helper.NBTHelper;
import WayofTime.bloodmagic.client.IMeshProvider;
import WayofTime.bloodmagic.client.mesh.CustomMeshDefinitionWillGem;
import WayofTime.bloodmagic.util.helper.TextHelper;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import java.util.ArrayList;
import java.util.List;
public class ItemSoulGem extends Item implements IDemonWillGem, IVariantProvider
public class ItemSoulGem extends Item implements IDemonWillGem, IMeshProvider, IMultiWillTool
{
public static String[] names = { "petty", "lesser", "common", "greater", "grand" };
@ -60,6 +63,36 @@ public class ItemSoulGem extends Item implements IDemonWillGem, IVariantProvider
return new ActionResult<ItemStack>(EnumActionResult.PASS, stack);
}
@Override
@SideOnly(Side.CLIENT)
public ItemMeshDefinition getMeshDefinition()
{
return new CustomMeshDefinitionWillGem("ItemSoulGem");
}
@Nullable
@Override
public ResourceLocation getCustomLocation()
{
return null;
}
@Override
public List<String> getVariants()
{
List<String> ret = new ArrayList<String>();
for (EnumDemonWillType type : EnumDemonWillType.values())
{
ret.add("type=petty_" + type.getName().toLowerCase());
ret.add("type=lesser_" + type.getName().toLowerCase());
ret.add("type=common_" + type.getName().toLowerCase());
ret.add("type=greater_" + type.getName().toLowerCase());
ret.add("type=grand_" + type.getName().toLowerCase());
}
return ret;
}
@Override
@SideOnly(Side.CLIENT)
public void getSubItems(Item id, CreativeTabs creativeTab, List<ItemStack> list)
@ -67,10 +100,17 @@ public class ItemSoulGem extends Item implements IDemonWillGem, IVariantProvider
for (int i = 0; i < names.length; i++)
{
ItemStack emptyStack = new ItemStack(this, 1, i);
ItemStack fullStack = new ItemStack(this, 1, i);
setWill(EnumDemonWillType.DEFAULT, fullStack, getMaxWill(EnumDemonWillType.DEFAULT, fullStack));
list.add(emptyStack);
list.add(fullStack);
}
for (EnumDemonWillType type : EnumDemonWillType.values())
{
for (int i = 0; i < names.length; i++)
{
ItemStack fullStack = new ItemStack(this, 1, i);
setWill(type, fullStack, getMaxWill(EnumDemonWillType.DEFAULT, fullStack));
list.add(fullStack);
}
}
}
@ -81,6 +121,7 @@ public class ItemSoulGem extends Item implements IDemonWillGem, IVariantProvider
EnumDemonWillType type = this.getCurrentType(stack);
tooltip.add(TextHelper.localize("tooltip.BloodMagic.soulGem." + names[stack.getItemDamage()]));
tooltip.add(TextHelper.localize("tooltip.BloodMagic.will", getWill(type, stack)));
tooltip.add(TextHelper.localizeEffect("tooltip.BloodMagic.currentType." + getCurrentType(stack).getName().toLowerCase()));
super.addInformation(stack, player, tooltip, advanced);
}
@ -192,24 +233,13 @@ public class ItemSoulGem extends Item implements IDemonWillGem, IVariantProvider
}
@Override
public List<Pair<Integer, String>> getVariants()
{
List<Pair<Integer, String>> ret = new ArrayList<Pair<Integer, String>>();
ret.add(new ImmutablePair<Integer, String>(0, "type=petty"));
ret.add(new ImmutablePair<Integer, String>(1, "type=lesser"));
ret.add(new ImmutablePair<Integer, String>(2, "type=common"));
ret.add(new ImmutablePair<Integer, String>(3, "type=greater"));
ret.add(new ImmutablePair<Integer, String>(4, "type=grand"));
return ret;
}
public EnumDemonWillType getCurrentType(ItemStack soulGemStack)
{
NBTHelper.checkNBT(soulGemStack);
NBTTagCompound tag = soulGemStack.getTagCompound();
if (!tag.hasKey(tag.getString(Constants.NBT.WILL_TYPE)))
if (!tag.hasKey(Constants.NBT.WILL_TYPE))
{
return EnumDemonWillType.DEFAULT;
}