equivalent-exchange-3/src/main/java/com/pahimar/ee3/item/ItemDarkMatterShovel.java

128 lines
3.9 KiB
Java
Raw Normal View History

2014-07-15 03:23:48 +02:00
package com.pahimar.ee3.item;
2014-07-17 03:40:12 +02:00
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
2014-07-15 19:24:04 +02:00
import com.pahimar.ee3.reference.*;
2014-10-14 22:08:12 +02:00
import com.pahimar.ee3.util.CommonSoundHelper;
import com.pahimar.ee3.util.IChargeable;
import com.pahimar.ee3.util.IKeyBound;
2014-07-15 03:23:48 +02:00
import com.pahimar.ee3.util.NBTHelper;
2014-07-17 03:40:12 +02:00
import net.minecraft.block.Block;
2014-07-15 03:23:48 +02:00
import net.minecraft.entity.player.EntityPlayer;
2014-07-17 03:40:12 +02:00
import net.minecraft.init.Blocks;
2014-07-15 03:23:48 +02:00
import net.minecraft.item.ItemStack;
import java.util.Arrays;
2014-07-15 19:24:04 +02:00
import java.util.List;
2014-07-17 03:40:12 +02:00
import java.util.Set;
2014-07-15 19:24:04 +02:00
public class ItemDarkMatterShovel extends ItemToolModalEE implements IKeyBound, IChargeable
2014-07-15 03:23:48 +02:00
{
2014-07-17 03:40:12 +02:00
private static final Set blocksEffectiveAgainst = Sets.newHashSet(new Block[]{Blocks.grass, Blocks.dirt, Blocks.sand, Blocks.gravel, Blocks.snow_layer, Blocks.snow, Blocks.clay, Blocks.farmland, Blocks.soul_sand, Blocks.mycelium});
2014-07-16 22:10:18 +02:00
public ItemDarkMatterShovel()
2014-07-15 03:23:48 +02:00
{
2014-07-17 03:40:12 +02:00
super(1.0f, Material.Tools.DARK_MATTER, blocksEffectiveAgainst);
2014-07-16 22:10:18 +02:00
this.setUnlocalizedName(Names.Tools.DARK_MATTER_SHOVEL);
2014-07-15 03:23:48 +02:00
}
@Override
2014-07-17 03:40:12 +02:00
public boolean func_150897_b(Block block)
2014-07-15 03:23:48 +02:00
{
2014-09-15 22:06:20 +02:00
return block == Blocks.snow_layer || block == Blocks.snow;
2014-07-15 03:23:48 +02:00
}
@Override
2014-07-17 03:40:12 +02:00
public Set<String> getToolClasses(ItemStack itemStack)
2014-07-15 03:23:48 +02:00
{
2014-07-17 03:40:12 +02:00
return ImmutableSet.of("shovel");
2014-07-15 03:23:48 +02:00
}
@Override
2014-07-16 22:10:18 +02:00
public short getMaxChargeLevel()
2014-07-15 03:23:48 +02:00
{
2014-07-16 22:10:18 +02:00
return 3;
2014-07-15 19:24:04 +02:00
}
2014-07-15 03:23:48 +02:00
@Override
public short getChargeLevel(ItemStack itemStack) {
if (NBTHelper.getShort(itemStack, Names.NBT.CHARGE_LEVEL) != null) {
return NBTHelper.getShort(itemStack, Names.NBT.CHARGE_LEVEL);
}
return 0;
2014-07-15 03:23:48 +02:00
}
@Override
public void setChargeLevel(ItemStack itemStack, short chargeLevel)
{
2014-07-16 22:10:18 +02:00
if (chargeLevel <= this.getMaxChargeLevel())
2014-07-15 03:23:48 +02:00
{
NBTHelper.setShort(itemStack, Names.NBT.CHARGE_LEVEL, chargeLevel);
}
}
@Override
public void increaseChargeLevel(ItemStack itemStack)
{
if (getChargeLevel(itemStack) < this.getMaxChargeLevel())
2014-07-15 03:23:48 +02:00
{
NBTHelper.setShort(itemStack, Names.NBT.CHARGE_LEVEL, (short) (getChargeLevel(itemStack) + 1));
2014-07-15 03:23:48 +02:00
}
}
@Override
public void decreaseChargeLevel(ItemStack itemStack)
{
if (getChargeLevel(itemStack) > 0)
2014-07-15 03:23:48 +02:00
{
NBTHelper.setShort(itemStack, Names.NBT.CHARGE_LEVEL, (short) (getChargeLevel(itemStack) - 1));
2014-07-15 03:23:48 +02:00
}
}
@Override
public void doKeyBindingAction(EntityPlayer entityPlayer, ItemStack itemStack, Key key)
{
if (key == Key.CHARGE)
{
if (!entityPlayer.isSneaking())
{
2014-07-16 22:10:18 +02:00
if (getChargeLevel(itemStack) == this.getMaxChargeLevel())
2014-07-15 03:23:48 +02:00
{
CommonSoundHelper.playSoundAtPlayer(entityPlayer, Sounds.FAIL, 1.5f, 1.5f);
2014-07-15 03:23:48 +02:00
}
else
{
increaseChargeLevel(itemStack);
CommonSoundHelper.playSoundAtPlayer(entityPlayer, Sounds.CHARGE_UP, 0.5F, 0.5F + 0.5F * (getChargeLevel(itemStack) * 1.0F / this.getMaxChargeLevel()));
2014-07-15 03:23:48 +02:00
}
}
else
{
if (getChargeLevel(itemStack) == 0)
{
CommonSoundHelper.playSoundAtPlayer(entityPlayer, Sounds.FAIL, 1.5f, 1.5f);
2014-07-15 03:23:48 +02:00
}
else
{
decreaseChargeLevel(itemStack);
CommonSoundHelper.playSoundAtPlayer(entityPlayer, Sounds.CHARGE_DOWN, 0.5F, 1.0F - (0.5F - 0.5F * (getChargeLevel(itemStack) * 1.0F / this.getMaxChargeLevel())));
2014-07-15 03:23:48 +02:00
}
}
}
2014-07-15 19:24:04 +02:00
else if (key == Key.EXTRA)
{
CommonSoundHelper.playSoundAtPlayer(entityPlayer, Sounds.TOCK, 0.5f, 1.5F);
2014-07-15 19:24:04 +02:00
changeToolMode(itemStack);
}
}
@Override
public List<ToolMode> getAvailableToolModes()
{
2014-07-16 22:10:18 +02:00
// TODO
return Arrays.asList(ToolMode.STANDARD);
2014-07-15 03:23:48 +02:00
}
}