Bound Tools are now enchantable (#664)
This commit is contained in:
parent
14267656cb
commit
6a6cb53d8f
|
@ -3,10 +3,12 @@ package WayofTime.bloodmagic.item;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import WayofTime.bloodmagic.api.util.helper.NetworkHelper;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockLeavesBase;
|
import net.minecraft.block.BlockLeavesBase;
|
||||||
import net.minecraft.block.material.Material;
|
import net.minecraft.block.material.Material;
|
||||||
import net.minecraft.enchantment.EnchantmentHelper;
|
import net.minecraft.enchantment.EnchantmentHelper;
|
||||||
|
import net.minecraft.entity.EntityLivingBase;
|
||||||
import net.minecraft.entity.SharedMonsterAttributes;
|
import net.minecraft.entity.SharedMonsterAttributes;
|
||||||
import net.minecraft.entity.ai.attributes.AttributeModifier;
|
import net.minecraft.entity.ai.attributes.AttributeModifier;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
@ -31,14 +33,20 @@ public class ItemBoundAxe extends ItemBoundTool
|
||||||
|
|
||||||
public ItemBoundAxe()
|
public ItemBoundAxe()
|
||||||
{
|
{
|
||||||
super("axe", 7, 5, EFFECTIVE_ON);
|
super("axe", 7, EFFECTIVE_ON);
|
||||||
setRegistryName(Constants.BloodMagicItem.BOUND_AXE.getRegName());
|
setRegistryName(Constants.BloodMagicItem.BOUND_AXE.getRegName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getStrVsBlock(ItemStack stack, Block block)
|
public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker)
|
||||||
{
|
{
|
||||||
return block.getMaterial() != Material.wood && block.getMaterial() != Material.plants && block.getMaterial() != Material.vine ? super.getStrVsBlock(stack, block) : 12F;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onBlockDestroyed(ItemStack stack, World world, Block block, BlockPos pos, EntityLivingBase player)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -95,8 +103,7 @@ public class ItemBoundAxe extends ItemBoundTool
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemBindable.syphonNetwork(stack, player, (int) (charge * charge * charge / 2.7));
|
NetworkHelper.getSoulNetwork(player).syphonAndDamage(player, (int) (charge * charge * charge / 2.7));
|
||||||
|
|
||||||
world.createExplosion(player, playerPos.getX(), playerPos.getY(), playerPos.getZ(), 0.1F, false);
|
world.createExplosion(player, playerPos.getX(), playerPos.getY(), playerPos.getZ(), 0.1F, false);
|
||||||
dropStacks(drops, world, playerPos.add(0, 1, 0));
|
dropStacks(drops, world, playerPos.add(0, 1, 0));
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,9 +3,11 @@ package WayofTime.bloodmagic.item;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import WayofTime.bloodmagic.api.util.helper.NetworkHelper;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.material.Material;
|
import net.minecraft.block.material.Material;
|
||||||
import net.minecraft.enchantment.EnchantmentHelper;
|
import net.minecraft.enchantment.EnchantmentHelper;
|
||||||
|
import net.minecraft.entity.EntityLivingBase;
|
||||||
import net.minecraft.entity.SharedMonsterAttributes;
|
import net.minecraft.entity.SharedMonsterAttributes;
|
||||||
import net.minecraft.entity.ai.attributes.AttributeModifier;
|
import net.minecraft.entity.ai.attributes.AttributeModifier;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
@ -30,20 +32,35 @@ public class ItemBoundPickaxe extends ItemBoundTool
|
||||||
|
|
||||||
public ItemBoundPickaxe()
|
public ItemBoundPickaxe()
|
||||||
{
|
{
|
||||||
super("pickaxe", 5, 5, EFFECTIVE_ON);
|
super("pickaxe", 5, EFFECTIVE_ON);
|
||||||
setRegistryName(Constants.BloodMagicItem.BOUND_PICKAXE.getRegName());
|
setRegistryName(Constants.BloodMagicItem.BOUND_PICKAXE.getRegName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canHarvestBlock(Block blockIn)
|
public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onBlockDestroyed(ItemStack stack, World world, Block block, BlockPos pos, EntityLivingBase player)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canHarvestBlock(Block blockIn)
|
||||||
|
{
|
||||||
|
return blockIn == Blocks.obsidian ? this.toolMaterial.getHarvestLevel() == 3 : (blockIn != Blocks.diamond_block && blockIn != Blocks.diamond_ore ? (blockIn != Blocks.emerald_ore && blockIn != Blocks.emerald_block ? (blockIn != Blocks.gold_block && blockIn != Blocks.gold_ore ? (blockIn != Blocks.iron_block && blockIn != Blocks.iron_ore ? (blockIn != Blocks.lapis_block && blockIn != Blocks.lapis_ore ? (blockIn != Blocks.redstone_ore && blockIn != Blocks.lit_redstone_ore ? (blockIn.getMaterial() == Material.rock || (blockIn.getMaterial() == Material.iron || blockIn.getMaterial() == Material.anvil)) : this.toolMaterial.getHarvestLevel() >= 2) : this.toolMaterial.getHarvestLevel() >= 1) : this.toolMaterial.getHarvestLevel() >= 1) : this.toolMaterial.getHarvestLevel() >= 2) : this.toolMaterial.getHarvestLevel() >= 2) : this.toolMaterial.getHarvestLevel() >= 2);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getStrVsBlock(ItemStack stack, Block block)
|
public float getStrVsBlock(ItemStack stack, Block block)
|
||||||
{
|
{
|
||||||
return block.getMaterial() != Material.iron && block.getMaterial() != Material.anvil && block.getMaterial() != Material.rock ? super.getStrVsBlock(stack, block) : 12F;
|
if (!getActivated(stack))
|
||||||
|
return 1.0F;
|
||||||
|
|
||||||
|
return block.getMaterial() != Material.iron && block.getMaterial() != Material.anvil && block.getMaterial() != Material.rock ? super.getStrVsBlock(stack, block) : this.efficiencyOnProperMaterial;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -100,8 +117,7 @@ public class ItemBoundPickaxe extends ItemBoundTool
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemBindable.syphonNetwork(stack, player, (int) (charge * charge * charge / 2.7));
|
NetworkHelper.getSoulNetwork(player).syphonAndDamage(player, (int) (charge * charge * charge / 2.7));
|
||||||
|
|
||||||
world.createExplosion(player, playerPos.getX(), playerPos.getY(), playerPos.getZ(), 0.5F, false);
|
world.createExplosion(player, playerPos.getX(), playerPos.getY(), playerPos.getZ(), 0.5F, false);
|
||||||
dropStacks(drops, world, playerPos.add(0, 1, 0));
|
dropStacks(drops, world, playerPos.add(0, 1, 0));
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,10 @@ package WayofTime.bloodmagic.item;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import WayofTime.bloodmagic.api.util.helper.NetworkHelper;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.enchantment.EnchantmentHelper;
|
import net.minecraft.enchantment.EnchantmentHelper;
|
||||||
|
import net.minecraft.entity.EntityLivingBase;
|
||||||
import net.minecraft.entity.SharedMonsterAttributes;
|
import net.minecraft.entity.SharedMonsterAttributes;
|
||||||
import net.minecraft.entity.ai.attributes.AttributeModifier;
|
import net.minecraft.entity.ai.attributes.AttributeModifier;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
@ -29,14 +31,20 @@ public class ItemBoundShovel extends ItemBoundTool
|
||||||
|
|
||||||
public ItemBoundShovel()
|
public ItemBoundShovel()
|
||||||
{
|
{
|
||||||
super("shovel", 1, 5, EFFECTIVE_ON);
|
super("shovel", 1, EFFECTIVE_ON);
|
||||||
setRegistryName(Constants.BloodMagicItem.BOUND_SHOVEL.getRegName());
|
setRegistryName(Constants.BloodMagicItem.BOUND_SHOVEL.getRegName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canHarvestBlock(Block blockIn)
|
public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker)
|
||||||
{
|
{
|
||||||
return blockIn == Blocks.snow_layer || blockIn == Blocks.snow;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onBlockDestroyed(ItemStack stack, World world, Block block, BlockPos pos, EntityLivingBase player)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -93,8 +101,7 @@ public class ItemBoundShovel extends ItemBoundTool
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemBindable.syphonNetwork(stack, player, (int) (charge * charge * charge / 2.7));
|
NetworkHelper.getSoulNetwork(player).syphonAndDamage(player, (int) (charge * charge * charge / 2.7));
|
||||||
|
|
||||||
world.createExplosion(player, playerPos.getX(), playerPos.getY(), playerPos.getZ(), 0.5F, false);
|
world.createExplosion(player, playerPos.getX(), playerPos.getY(), playerPos.getZ(), 0.5F, false);
|
||||||
dropStacks(drops, world, playerPos.add(0, 1, 0));
|
dropStacks(drops, world, playerPos.add(0, 1, 0));
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,12 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import WayofTime.bloodmagic.api.iface.IBindable;
|
||||||
|
import WayofTime.bloodmagic.registry.ModItems;
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.SharedMonsterAttributes;
|
import net.minecraft.entity.SharedMonsterAttributes;
|
||||||
import net.minecraft.entity.ai.attributes.AttributeModifier;
|
import net.minecraft.entity.ai.attributes.AttributeModifier;
|
||||||
|
@ -14,6 +18,7 @@ import net.minecraft.entity.item.EntityItem;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.EnumAction;
|
import net.minecraft.item.EnumAction;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.item.ItemTool;
|
||||||
import net.minecraft.util.BlockPos;
|
import net.minecraft.util.BlockPos;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.StatCollector;
|
import net.minecraft.util.StatCollector;
|
||||||
|
@ -32,39 +37,37 @@ import com.google.common.collect.Multimap;
|
||||||
import com.google.common.collect.Multiset;
|
import com.google.common.collect.Multiset;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public class ItemBoundTool extends ItemBindable implements IActivatable
|
public class ItemBoundTool extends ItemTool implements IBindable, IActivatable
|
||||||
{
|
{
|
||||||
private Set<Block> effectiveBlocks;
|
|
||||||
protected final String tooltipBase;
|
protected final String tooltipBase;
|
||||||
private final String name;
|
private final String name;
|
||||||
private final int damage;
|
private final float damage;
|
||||||
|
|
||||||
public Map<ItemStack, Boolean> heldDownMap = new HashMap<ItemStack, Boolean>();
|
public Map<ItemStack, Boolean> heldDownMap = new HashMap<ItemStack, Boolean>();
|
||||||
public Map<ItemStack, Integer> heldDownCountMap = new HashMap<ItemStack, Integer>();
|
public Map<ItemStack, Integer> heldDownCountMap = new HashMap<ItemStack, Integer>();
|
||||||
|
|
||||||
public final int chargeTime = 30;
|
public final int chargeTime = 30;
|
||||||
|
|
||||||
public ItemBoundTool(String name, int damage, int lpUsed, Set<Block> effectiveBlocks)
|
public ItemBoundTool(String name, float damage, Set<Block> effectiveBlocks)
|
||||||
{
|
{
|
||||||
super();
|
super(damage, ModItems.boundToolMaterial, effectiveBlocks);
|
||||||
setUnlocalizedName(Constants.Mod.MODID + ".bound." + name);
|
setUnlocalizedName(Constants.Mod.MODID + ".bound." + name);
|
||||||
setLPUsed(lpUsed);
|
|
||||||
|
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.tooltipBase = "tooltip.BloodMagic.bound." + name + ".";
|
this.tooltipBase = "tooltip.BloodMagic.bound." + name + ".";
|
||||||
this.effectiveBlocks = effectiveBlocks;
|
|
||||||
this.damage = damage;
|
this.damage = damage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemBoundTool(String name, int damage, int lpUsed)
|
|
||||||
{
|
|
||||||
this(name, damage, lpUsed, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getStrVsBlock(ItemStack stack, Block block)
|
public float getStrVsBlock(ItemStack stack, Block block)
|
||||||
{
|
{
|
||||||
return this.effectiveBlocks.contains(block) ? 8.0F : 1.0F;
|
return getActivated(stack) ? getToolMaterial().getEfficiencyOnProperMaterial() : 1.0F;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getDigSpeed(ItemStack stack, IBlockState state)
|
||||||
|
{
|
||||||
|
return getActivated(stack) ? getToolMaterial().getEfficiencyOnProperMaterial() : 1.0F;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -90,9 +93,7 @@ public class ItemBoundTool extends ItemBindable implements IActivatable
|
||||||
protected int getHeldDownCount(ItemStack stack)
|
protected int getHeldDownCount(ItemStack stack)
|
||||||
{
|
{
|
||||||
if (!heldDownCountMap.containsKey(stack))
|
if (!heldDownCountMap.containsKey(stack))
|
||||||
{
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
return heldDownCountMap.get(stack);
|
return heldDownCountMap.get(stack);
|
||||||
}
|
}
|
||||||
|
@ -105,9 +106,7 @@ public class ItemBoundTool extends ItemBindable implements IActivatable
|
||||||
protected boolean getBeingHeldDown(ItemStack stack)
|
protected boolean getBeingHeldDown(ItemStack stack)
|
||||||
{
|
{
|
||||||
if (!heldDownMap.containsKey(stack))
|
if (!heldDownMap.containsKey(stack))
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
return heldDownMap.get(stack);
|
return heldDownMap.get(stack);
|
||||||
}
|
}
|
||||||
|
@ -120,38 +119,22 @@ public class ItemBoundTool extends ItemBindable implements IActivatable
|
||||||
@Override
|
@Override
|
||||||
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player)
|
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player)
|
||||||
{
|
{
|
||||||
// if (!world.isRemote)
|
if (player.isSneaking())
|
||||||
|
setActivatedState(stack, !getActivated(stack));
|
||||||
|
|
||||||
|
if (!player.isSneaking() && getActivated(stack))
|
||||||
{
|
{
|
||||||
if (player.isSneaking())
|
BoundToolEvent.Charge event = new BoundToolEvent.Charge(player, stack);
|
||||||
setActivatedState(stack, !getActivated(stack));
|
if (MinecraftForge.EVENT_BUS.post(event))
|
||||||
// if (getActivated(stack) && ItemBindable.syphonBatteries(stack,
|
return event.result;
|
||||||
// player, getLPUsed()))
|
|
||||||
// return stack;
|
|
||||||
// if (getActivated(stack) && ItemBindable.syphonNetwork(stack, player, getLPUsed()))
|
|
||||||
// return stack;
|
|
||||||
|
|
||||||
if (!player.isSneaking() && getActivated(stack))
|
player.setItemInUse(stack, this.getMaxItemUseDuration(stack));
|
||||||
{
|
setBeingHeldDown(stack, true);
|
||||||
BoundToolEvent.Charge event = new BoundToolEvent.Charge(player, stack);
|
|
||||||
if (MinecraftForge.EVENT_BUS.post(event))
|
|
||||||
return event.result;
|
|
||||||
|
|
||||||
player.setItemInUse(stack, this.getMaxItemUseDuration(stack));
|
|
||||||
setBeingHeldDown(stack, true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return stack;
|
return stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ)
|
|
||||||
{
|
|
||||||
this.onItemRightClick(stack, world, player);
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityPlayer playerIn, int timeLeft)
|
public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityPlayer playerIn, int timeLeft)
|
||||||
{
|
{
|
||||||
|
@ -218,6 +201,11 @@ public class ItemBoundTool extends ItemBindable implements IActivatable
|
||||||
super.addInformation(stack, player, tooltip, advanced);
|
super.addInformation(stack, player, tooltip, advanced);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<String> getToolClasses(ItemStack stack) {
|
||||||
|
return ImmutableSet.of(name);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean showDurabilityBar(ItemStack stack)
|
public boolean showDurabilityBar(ItemStack stack)
|
||||||
{
|
{
|
||||||
|
@ -249,17 +237,35 @@ public class ItemBoundTool extends ItemBindable implements IActivatable
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getActivated(ItemStack stack)
|
// IBindable
|
||||||
{
|
|
||||||
NBTHelper.checkNBT(stack);
|
@Override
|
||||||
return stack.getTagCompound().getBoolean(Constants.NBT.ACTIVATED);
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onBind(EntityPlayer player, ItemStack stack) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// IActivatable
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean getActivated(ItemStack stack)
|
||||||
|
{
|
||||||
|
return NBTHelper.checkNBT(stack).getTagCompound().getBoolean(Constants.NBT.ACTIVATED);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public ItemStack setActivatedState(ItemStack stack, boolean activated)
|
public ItemStack setActivatedState(ItemStack stack, boolean activated)
|
||||||
{
|
{
|
||||||
NBTHelper.checkNBT(stack);
|
NBTHelper.checkNBT(stack).getTagCompound().setBoolean(Constants.NBT.ACTIVATED, activated);
|
||||||
stack.getTagCompound().setBoolean(Constants.NBT.ACTIVATED, activated);
|
|
||||||
|
|
||||||
return stack;
|
return stack;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue