2016-03-07 08:01:02 +01:00
|
|
|
package techreborn.items.tools;
|
|
|
|
|
2016-06-05 12:57:38 +02:00
|
|
|
import com.google.common.collect.HashMultimap;
|
|
|
|
import com.google.common.collect.Multimap;
|
2016-05-13 09:35:02 +02:00
|
|
|
import me.modmuss50.jsonDestroyer.api.IHandHeld;
|
2016-03-07 08:01:02 +01:00
|
|
|
import net.minecraft.creativetab.CreativeTabs;
|
|
|
|
import net.minecraft.entity.EntityLivingBase;
|
2016-06-05 12:57:38 +02:00
|
|
|
import net.minecraft.entity.SharedMonsterAttributes;
|
|
|
|
import net.minecraft.entity.ai.attributes.AttributeModifier;
|
2016-03-07 08:01:02 +01:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2016-06-05 12:57:38 +02:00
|
|
|
import net.minecraft.inventory.EntityEquipmentSlot;
|
|
|
|
import net.minecraft.item.IItemPropertyGetter;
|
2016-03-07 08:01:02 +01:00
|
|
|
import net.minecraft.item.Item;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.item.ItemSword;
|
2016-06-05 12:57:38 +02:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2016-03-13 18:38:12 +01:00
|
|
|
import net.minecraft.util.ActionResult;
|
|
|
|
import net.minecraft.util.EnumActionResult;
|
|
|
|
import net.minecraft.util.EnumHand;
|
2016-06-05 12:57:38 +02:00
|
|
|
import net.minecraft.util.ResourceLocation;
|
|
|
|
import net.minecraft.util.text.TextComponentString;
|
2016-03-28 22:33:36 +02:00
|
|
|
import net.minecraft.util.text.TextFormatting;
|
2016-06-05 12:57:38 +02:00
|
|
|
import net.minecraft.util.text.translation.I18n;
|
2016-03-07 08:01:02 +01:00
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
|
|
|
import reborncore.api.power.IEnergyItemInfo;
|
|
|
|
import reborncore.common.powerSystem.PoweredItem;
|
2016-06-05 12:57:38 +02:00
|
|
|
import reborncore.common.util.ChatUtils;
|
2016-03-07 08:01:02 +01:00
|
|
|
import techreborn.client.TechRebornCreativeTab;
|
2016-06-05 12:57:38 +02:00
|
|
|
import techreborn.config.ConfigTechReborn;
|
|
|
|
import techreborn.init.ModItems;
|
|
|
|
import techreborn.lib.MessageIDs;
|
2016-03-07 08:01:02 +01:00
|
|
|
|
2016-06-05 12:57:38 +02:00
|
|
|
import javax.annotation.Nullable;
|
|
|
|
import java.util.List;
|
2016-03-07 08:01:02 +01:00
|
|
|
|
2016-06-05 12:57:38 +02:00
|
|
|
public class ItemNanosaber extends ItemSword implements IEnergyItemInfo, IHandHeld
|
|
|
|
{
|
2016-03-07 08:01:02 +01:00
|
|
|
public int cost = 250;
|
|
|
|
|
2016-03-25 10:47:34 +01:00
|
|
|
public ItemNanosaber()
|
|
|
|
{
|
2016-03-13 18:38:12 +01:00
|
|
|
super(ToolMaterial.DIAMOND);
|
2016-03-07 08:01:02 +01:00
|
|
|
setCreativeTab(TechRebornCreativeTab.instance);
|
|
|
|
setMaxStackSize(1);
|
2016-06-05 12:57:38 +02:00
|
|
|
setMaxDamage(1);
|
2016-03-07 08:01:02 +01:00
|
|
|
setUnlocalizedName("techreborn.nanosaber");
|
2016-06-05 12:57:38 +02:00
|
|
|
this.addPropertyOverride(new ResourceLocation("techreborn:active"), new IItemPropertyGetter()
|
2016-03-09 16:03:26 +01:00
|
|
|
{
|
2016-06-05 12:57:38 +02:00
|
|
|
@SideOnly(Side.CLIENT) public float apply(ItemStack stack, @Nullable World worldIn,
|
|
|
|
@Nullable EntityLivingBase entityIn)
|
|
|
|
{
|
|
|
|
if (stack != null && stack.getTagCompound().getBoolean("isActive"))
|
|
|
|
{
|
|
|
|
return 1.0F;
|
|
|
|
}
|
|
|
|
return 0.0F;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override public Multimap<String, AttributeModifier> getAttributeModifiers(EntityEquipmentSlot slot,
|
|
|
|
ItemStack stack)
|
|
|
|
{
|
|
|
|
Multimap<String, AttributeModifier> multimap = HashMultimap.<String, AttributeModifier>create();
|
|
|
|
int modifier = 0;
|
|
|
|
if (stack.getTagCompound().getBoolean("isActive"))
|
|
|
|
modifier = 9;
|
|
|
|
|
|
|
|
if (slot == EntityEquipmentSlot.MAINHAND)
|
|
|
|
{
|
|
|
|
multimap.put(SharedMonsterAttributes.ATTACK_DAMAGE.getAttributeUnlocalizedName(),
|
|
|
|
new AttributeModifier(ATTACK_DAMAGE_MODIFIER, "Weapon modifier", (double) modifier, 0));
|
|
|
|
multimap.put(SharedMonsterAttributes.ATTACK_SPEED.getAttributeUnlocalizedName(),
|
|
|
|
new AttributeModifier(ATTACK_SPEED_MODIFIER, "Weapon modifier", -2.4000000953674316D, 0));
|
2016-03-07 08:01:02 +01:00
|
|
|
}
|
2016-06-05 12:57:38 +02:00
|
|
|
return multimap;
|
2016-03-09 16:03:26 +01:00
|
|
|
}
|
2016-03-13 18:38:12 +01:00
|
|
|
|
2016-06-05 12:57:38 +02:00
|
|
|
@Override public boolean hitEntity(ItemStack itemstack, EntityLivingBase entityliving,
|
|
|
|
EntityLivingBase entityliving1)
|
2016-03-09 16:03:26 +01:00
|
|
|
{
|
2016-06-05 12:57:38 +02:00
|
|
|
if (PoweredItem.canUseEnergy(cost, itemstack))
|
2016-03-09 16:03:26 +01:00
|
|
|
{
|
2016-06-05 12:57:38 +02:00
|
|
|
PoweredItem.useEnergy(cost, itemstack);
|
|
|
|
return true;
|
|
|
|
} else
|
2016-03-09 16:03:26 +01:00
|
|
|
{
|
2016-06-05 12:57:38 +02:00
|
|
|
return false;
|
2016-03-09 16:03:26 +01:00
|
|
|
}
|
|
|
|
}
|
2016-03-25 10:47:34 +01:00
|
|
|
|
2016-06-05 12:57:38 +02:00
|
|
|
@Override public boolean isRepairable()
|
2016-03-25 10:47:34 +01:00
|
|
|
{
|
2016-03-07 08:01:02 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-06-05 12:57:38 +02:00
|
|
|
@Override public double getMaxPower(ItemStack stack)
|
2016-03-25 10:47:34 +01:00
|
|
|
{
|
2016-06-05 12:57:38 +02:00
|
|
|
return 100000;
|
2016-03-07 08:01:02 +01:00
|
|
|
}
|
|
|
|
|
2016-06-05 12:57:38 +02:00
|
|
|
@Override public boolean canAcceptEnergy(ItemStack stack)
|
2016-03-25 10:47:34 +01:00
|
|
|
{
|
2016-03-07 08:01:02 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-06-05 12:57:38 +02:00
|
|
|
@Override public boolean canProvideEnergy(ItemStack stack)
|
2016-03-25 10:47:34 +01:00
|
|
|
{
|
2016-03-07 08:01:02 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-06-05 12:57:38 +02:00
|
|
|
@Override public double getMaxTransfer(ItemStack stack)
|
2016-03-25 10:47:34 +01:00
|
|
|
{
|
2016-06-05 12:57:38 +02:00
|
|
|
return 512;
|
2016-03-07 08:01:02 +01:00
|
|
|
}
|
|
|
|
|
2016-06-05 12:57:38 +02:00
|
|
|
@Override public int getStackTier(ItemStack stack)
|
2016-03-25 10:47:34 +01:00
|
|
|
{
|
2016-06-05 12:57:38 +02:00
|
|
|
return 2;
|
2016-03-07 08:01:02 +01:00
|
|
|
}
|
|
|
|
|
2016-06-05 12:57:38 +02:00
|
|
|
@SuppressWarnings({ "rawtypes", "unchecked" }) @SideOnly(Side.CLIENT) public void getSubItems(Item item,
|
|
|
|
CreativeTabs par2CreativeTabs, List itemList)
|
2016-03-25 10:47:34 +01:00
|
|
|
{
|
2016-06-05 12:57:38 +02:00
|
|
|
ItemStack inactiveUncharged = new ItemStack(ModItems.nanosaber);
|
|
|
|
inactiveUncharged.setTagCompound(new NBTTagCompound());
|
|
|
|
inactiveUncharged.getTagCompound().setBoolean("isActive", false);
|
|
|
|
PoweredItem.setEnergy(0, inactiveUncharged);
|
2016-03-07 08:01:02 +01:00
|
|
|
|
2016-06-05 12:57:38 +02:00
|
|
|
ItemStack inactiveCharged = new ItemStack(ModItems.nanosaber);
|
|
|
|
inactiveCharged.setTagCompound(new NBTTagCompound());
|
|
|
|
inactiveCharged.getTagCompound().setBoolean("isActive", false);
|
|
|
|
PoweredItem.setEnergy(getMaxPower(inactiveCharged), inactiveCharged);
|
2016-03-07 08:01:02 +01:00
|
|
|
|
2016-06-05 12:57:38 +02:00
|
|
|
ItemStack activeUncharged = new ItemStack(ModItems.nanosaber);
|
|
|
|
activeUncharged.setTagCompound(new NBTTagCompound());
|
|
|
|
activeUncharged.getTagCompound().setBoolean("isActive", true);
|
|
|
|
PoweredItem.setEnergy(0, activeUncharged);
|
2016-03-07 08:01:02 +01:00
|
|
|
|
2016-06-05 12:57:38 +02:00
|
|
|
ItemStack activeCharged = new ItemStack(ModItems.nanosaber);
|
|
|
|
activeCharged.setTagCompound(new NBTTagCompound());
|
|
|
|
activeCharged.getTagCompound().setBoolean("isActive", true);
|
|
|
|
PoweredItem.setEnergy(getMaxPower(activeCharged), activeCharged);
|
2016-03-07 08:01:02 +01:00
|
|
|
|
2016-06-05 12:57:38 +02:00
|
|
|
itemList.add(inactiveUncharged);
|
|
|
|
itemList.add(inactiveCharged);
|
|
|
|
itemList.add(activeUncharged);
|
|
|
|
itemList.add(activeCharged);
|
2016-03-07 08:01:02 +01:00
|
|
|
}
|
|
|
|
|
2016-06-05 12:57:38 +02:00
|
|
|
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean par4)
|
2016-03-25 10:47:34 +01:00
|
|
|
{
|
2016-06-05 12:57:38 +02:00
|
|
|
if (stack.getTagCompound() == null || !stack.getTagCompound().getBoolean("isActive"))
|
|
|
|
{
|
|
|
|
list.add(TextFormatting.GRAY + I18n.translateToLocal("techreborn.message.nanosaberInactive"));
|
|
|
|
} else
|
2016-03-25 10:47:34 +01:00
|
|
|
{
|
2016-06-05 12:57:38 +02:00
|
|
|
list.add(TextFormatting.GRAY + I18n.translateToLocal("techreborn.message.nanosaberActive"));
|
2016-03-07 08:01:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-05 12:57:38 +02:00
|
|
|
@Override public double getDurabilityForDisplay(ItemStack stack)
|
2016-03-25 10:47:34 +01:00
|
|
|
{
|
2016-06-05 12:57:38 +02:00
|
|
|
double charge = (PoweredItem.getEnergy(stack) / getMaxPower(stack));
|
|
|
|
return 1 - charge;
|
|
|
|
|
2016-03-07 08:01:02 +01:00
|
|
|
}
|
2016-03-14 14:28:33 +01:00
|
|
|
|
2016-06-05 12:57:38 +02:00
|
|
|
@Override public boolean showDurabilityBar(ItemStack stack)
|
2016-03-25 10:47:34 +01:00
|
|
|
{
|
2016-06-05 12:57:38 +02:00
|
|
|
return true;
|
2016-03-14 14:28:33 +01:00
|
|
|
}
|
2016-03-28 22:33:36 +02:00
|
|
|
|
2016-06-05 12:57:38 +02:00
|
|
|
@Override public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player,
|
|
|
|
EnumHand hand)
|
2016-03-28 22:33:36 +02:00
|
|
|
{
|
2016-06-05 12:57:38 +02:00
|
|
|
if (player.isSneaking())
|
|
|
|
{
|
|
|
|
if (stack.getTagCompound() == null || !stack.getTagCompound().getBoolean("isActive"))
|
|
|
|
{
|
|
|
|
stack.setTagCompound(new NBTTagCompound());
|
|
|
|
stack.getTagCompound().setBoolean("isActive", true);
|
|
|
|
if (!world.isRemote && ConfigTechReborn.NanosaberChat)
|
|
|
|
{
|
|
|
|
ChatUtils.sendNoSpamMessages(MessageIDs.nanosaberID, new TextComponentString(
|
|
|
|
TextFormatting.GRAY + I18n.translateToLocal("techreborn.message.setTo") + " "
|
|
|
|
+ TextFormatting.GOLD + I18n
|
|
|
|
.translateToLocal("techreborn.message.nanosaberActive")));
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
stack.getTagCompound().setBoolean("isActive", false);
|
|
|
|
if (!world.isRemote && ConfigTechReborn.NanosaberChat)
|
|
|
|
{
|
|
|
|
ChatUtils.sendNoSpamMessages(MessageIDs.nanosaberID, new TextComponentString(
|
|
|
|
TextFormatting.GRAY + I18n.translateToLocal("techreborn.message.setTo") + " "
|
|
|
|
+ TextFormatting.GOLD + I18n
|
|
|
|
.translateToLocal("techreborn.message.nanosaberInactive")));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return new ActionResult<>(EnumActionResult.SUCCESS, stack);
|
2016-03-28 22:33:36 +02:00
|
|
|
}
|
2016-03-07 08:01:02 +01:00
|
|
|
}
|