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:
Nick 2016-02-04 02:45:19 -08:00
parent fd16a58b6b
commit cc66af7eb1
15 changed files with 122 additions and 134 deletions

View file

@ -15,6 +15,7 @@ public class Constants
public static final String OWNER_UUID = "ownerUUID";
public static final String OWNER_NAME = "ownerNAME";
public static final String USES = "uses";
public static final String ACTIVATED = "activated";
public static final String UNUSABLE = "unusable";
public static final String SACRIFICE = "sacrifice";
public static final String DIMENSION_ID = "dimensionId";

View file

@ -0,0 +1,10 @@
package WayofTime.bloodmagic.api.iface;
import net.minecraft.item.ItemStack;
public interface IActivatable
{
boolean getActivated(ItemStack stack);
ItemStack setActivatedState(ItemStack stack, boolean activated);
}

View file

@ -0,0 +1,29 @@
package WayofTime.bloodmagic.client.mesh;
import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.api.iface.IActivatable;
import net.minecraft.client.renderer.ItemMeshDefinition;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.item.ItemStack;
public class CustomMeshDefinitionActivatable implements ItemMeshDefinition
{
private final String name;
public CustomMeshDefinitionActivatable(String name) {
this.name = name;
}
@Override
public ModelResourceLocation getModelLocation(ItemStack stack)
{
if (stack != null && stack.getItem() instanceof IActivatable)
{
if (!((IActivatable) stack.getItem()).getActivated(stack))
return new ModelResourceLocation(Constants.Mod.DOMAIN + name + "0", "inventory");
return new ModelResourceLocation(Constants.Mod.DOMAIN + name + "1", "inventory");
}
return null;
}
}

View file

@ -1,25 +0,0 @@
package WayofTime.bloodmagic.client.mesh;
import net.minecraft.client.renderer.ItemMeshDefinition;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.item.ItemStack;
import WayofTime.bloodmagic.item.soul.ItemSentientSword;
public class ItemSentientSwordMeshDefinition implements ItemMeshDefinition
{
@Override
public ModelResourceLocation getModelLocation(ItemStack stack)
{
if (stack != null && stack.getItem() instanceof ItemSentientSword)
{
if (((ItemSentientSword) stack.getItem()).getActivated(stack))
{
return new ModelResourceLocation("bloodmagic:ItemSentientSword1", "inventory");
} else
{
return new ModelResourceLocation("bloodmagic:ItemSentientSword0", "inventory");
}
}
return null;
}
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -1,13 +1,11 @@
package WayofTime.bloodmagic.proxy;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.client.model.obj.OBJLoader;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.client.registry.ClientRegistry;
import net.minecraftforge.fml.client.registry.RenderingRegistry;
import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.client.helper.ShaderHelper;
import WayofTime.bloodmagic.client.mesh.ItemSentientSwordMeshDefinition;
import WayofTime.bloodmagic.client.render.RenderAlchemyArray;
import WayofTime.bloodmagic.client.render.RenderAltar;
import WayofTime.bloodmagic.client.render.RenderItemRoutingNode;
@ -51,8 +49,6 @@ public class ClientProxy extends CommonProxy
ClientRegistry.bindTileEntitySpecialRenderer(TileAlchemyArray.class, new RenderAlchemyArray());
ClientRegistry.bindTileEntitySpecialRenderer(TileAltar.class, new RenderAltar());
ClientRegistry.bindTileEntitySpecialRenderer(TileRoutingNode.class, new RenderItemRoutingNode());
ModelLoader.setCustomMeshDefinition(ModItems.sentientSword, new ItemSentientSwordMeshDefinition());
}
@Override

View file

@ -1,7 +1,9 @@
package WayofTime.bloodmagic.registry;
import WayofTime.bloodmagic.client.mesh.CustomMeshDefinitionActivatable;
import net.minecraft.item.Item;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.common.util.EnumHelper;
import net.minecraftforge.fml.common.registry.GameRegistry;
import WayofTime.bloodmagic.BloodMagic;
@ -136,7 +138,7 @@ public class ModItems
public static Item nodeRouter;
public static Item baseItemFilter;
public static Item.ToolMaterial boundToolMaterial = EnumHelper.addToolMaterial("BoundToolMaterial", 4, 0, 10, 8, 50);
public static Item.ToolMaterial boundToolMaterial = EnumHelper.addToolMaterial("BoundToolMaterial", 4, 1, 10, 8, 50);
public static Item.ToolMaterial soulToolMaterial = EnumHelper.addToolMaterial("SoulToolMaterial", 4, 520, 7, 8, 50);
public static void init()
@ -268,14 +270,18 @@ public class ModItems
renderHelper.itemRender(lavaCrystal);
renderHelper.itemRender(boundSword, 0);
renderHelper.itemRender(boundSword, 1);
renderHelper.itemRender(boundPickaxe, 0);
renderHelper.itemRender(boundPickaxe, 1);
renderHelper.itemRender(boundAxe, 0);
renderHelper.itemRender(boundAxe, 1);
renderHelper.itemRender(boundShovel, 0);
renderHelper.itemRender(boundShovel, 1);
renderHelper.customItemRender(boundSword, 0);
renderHelper.customItemRender(boundSword, 1);
ModelLoader.setCustomMeshDefinition(ModItems.boundSword, new CustomMeshDefinitionActivatable("ItemBoundSword"));
renderHelper.customItemRender(boundPickaxe, 0);
renderHelper.customItemRender(boundPickaxe, 1);
ModelLoader.setCustomMeshDefinition(ModItems.boundPickaxe, new CustomMeshDefinitionActivatable("ItemBoundPickaxe"));
renderHelper.customItemRender(boundAxe, 0);
renderHelper.customItemRender(boundAxe, 1);
ModelLoader.setCustomMeshDefinition(ModItems.boundAxe, new CustomMeshDefinitionActivatable("ItemBoundAxe"));
renderHelper.customItemRender(boundShovel, 0);
renderHelper.customItemRender(boundShovel, 1);
ModelLoader.setCustomMeshDefinition(ModItems.boundShovel, new CustomMeshDefinitionActivatable("ItemBoundShovel"));
renderHelper.itemRender(sigilDivination);
renderHelper.itemRender(sigilAir);
@ -339,6 +345,7 @@ public class ModItems
renderHelper.customItemRender(sentientSword, 0);
renderHelper.customItemRender(sentientSword, 1);
ModelLoader.setCustomMeshDefinition(ModItems.sentientSword, new CustomMeshDefinitionActivatable("ItemSentientSword"));
renderHelper.itemRender(sentientBow, 0, "ItemSentientBow");
renderHelper.itemRender(sentientBow, 1, "ItemSentientBow_pulling_0");
renderHelper.itemRender(sentientBow, 2, "ItemSentientBow_pulling_1");

View file

@ -2,17 +2,5 @@
"parent":"bloodmagic:item/ItemModelBase",
"textures": {
"layer0":"bloodmagic:items/BoundAxe_activated"
},
"display": {
"thirdperson": {
"rotation": [ 0, 90, -35 ],
"translation": [ 0, 1.25, -3.5 ],
"scale": [ 0.85, 0.85, 0.85 ]
},
"firstperson": {
"rotation": [ 0, -135, 25 ],
"translation": [ 0, 4, 2 ],
"scale": [ 1.7, 1.7, 1.7 ]
}
}
}

View file

@ -2,17 +2,5 @@
"parent":"bloodmagic:item/ItemModelBase",
"textures": {
"layer0":"bloodmagic:items/BoundPickaxe_activated"
},
"display": {
"thirdperson": {
"rotation": [ 0, 90, -35 ],
"translation": [ 0, 1.25, -3.5 ],
"scale": [ 0.85, 0.85, 0.85 ]
},
"firstperson": {
"rotation": [ 0, -135, 25 ],
"translation": [ 0, 4, 2 ],
"scale": [ 1.7, 1.7, 1.7 ]
}
}
}

View file

@ -2,17 +2,5 @@
"parent":"bloodmagic:item/ItemModelBase",
"textures": {
"layer0":"bloodmagic:items/BoundShovel_activated"
},
"display": {
"thirdperson": {
"rotation": [ 0, 90, -35 ],
"translation": [ 0, 1.25, -3.5 ],
"scale": [ 0.85, 0.85, 0.85 ]
},
"firstperson": {
"rotation": [ 0, -135, 25 ],
"translation": [ 0, 4, 2 ],
"scale": [ 1.7, 1.7, 1.7 ]
}
}
}

View file

@ -2,17 +2,5 @@
"parent":"bloodmagic:item/ItemModelBase",
"textures": {
"layer0":"bloodmagic:items/BoundSword_activated"
},
"display": {
"thirdperson": {
"rotation": [ 0, 90, -35 ],
"translation": [ 0, 1.25, -3.5 ],
"scale": [ 0.85, 0.85, 0.85 ]
},
"firstperson": {
"rotation": [ 0, -135, 25 ],
"translation": [ 0, 4, 2 ],
"scale": [ 1.7, 1.7, 1.7 ]
}
}
}

View file

@ -2,18 +2,6 @@
"parent":"bloodmagic:item/ItemModelBase",
"textures": {
"layer0":"bloodmagic:items/SoulSword_deactivated"
},
"display": {
"thirdperson": {
"rotation": [ 0, 90, -35 ],
"translation": [ 0, 1.25, -3.5 ],
"scale": [ 0.85, 0.85, 0.85 ]
},
"firstperson": {
"rotation": [ 0, -135, 25 ],
"translation": [ 0, 4, 2 ],
"scale": [ 1.7, 1.7, 1.7 ]
}
}
}

View file

@ -2,18 +2,6 @@
"parent":"bloodmagic:item/ItemModelBase",
"textures": {
"layer0":"bloodmagic:items/SoulSword_activated"
},
"display": {
"thirdperson": {
"rotation": [ 0, 90, -35 ],
"translation": [ 0, 1.25, -3.5 ],
"scale": [ 0.85, 0.85, 0.85 ]
},
"firstperson": {
"rotation": [ 0, -135, 25 ],
"translation": [ 0, 4, 2 ],
"scale": [ 1.7, 1.7, 1.7 ]
}
}
}