2017-02-23 13:29:43 +01:00
|
|
|
/*
|
|
|
|
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
|
|
|
*
|
|
|
|
* Copyright (c) 2017 TechReborn
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
|
|
* copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
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-03-07 08:01:02 +01:00
|
|
|
import net.minecraft.creativetab.CreativeTabs;
|
2016-11-05 17:29:37 +01:00
|
|
|
import net.minecraft.entity.Entity;
|
2016-03-07 08:01:02 +01:00
|
|
|
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.ItemStack;
|
|
|
|
import net.minecraft.item.ItemSword;
|
2016-06-05 12:57:38 +02:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2016-11-25 14:23:42 +01:00
|
|
|
import net.minecraft.util.*;
|
2016-06-05 12:57:38 +02:00
|
|
|
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;
|
2016-08-10 01:29:47 +02:00
|
|
|
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-10-08 21:46:16 +02:00
|
|
|
public class ItemNanosaber extends ItemSword implements IEnergyItemInfo {
|
2016-08-10 01:29:47 +02:00
|
|
|
public int cost = 250;
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
public ItemNanosaber() {
|
2016-08-10 01:29:47 +02:00
|
|
|
super(ToolMaterial.DIAMOND);
|
|
|
|
setNoRepair();
|
|
|
|
setCreativeTab(TechRebornCreativeTab.instance);
|
|
|
|
setMaxStackSize(1);
|
|
|
|
setUnlocalizedName("techreborn.nanosaber");
|
2016-10-08 21:46:16 +02:00
|
|
|
this.addPropertyOverride(new ResourceLocation("techreborn:active"), new IItemPropertyGetter() {
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public float apply(ItemStack stack,
|
|
|
|
@Nullable
|
|
|
|
World worldIn,
|
|
|
|
@Nullable
|
|
|
|
EntityLivingBase entityIn) {
|
2016-11-25 14:23:42 +01:00
|
|
|
if (stack != ItemStack.EMPTY && stack.hasTagCompound() && stack.getTagCompound().hasKey("isActive") && stack.getTagCompound().getBoolean("isActive")) {
|
2016-12-10 07:50:26 +01:00
|
|
|
if (PoweredItem.getMaxPower(stack) - PoweredItem.getEnergy(stack) >= 0.9 * PoweredItem.getMaxPower(stack))
|
|
|
|
return 0.5F;
|
2016-08-10 01:29:47 +02:00
|
|
|
return 1.0F;
|
|
|
|
}
|
|
|
|
return 0.0F;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
@Override
|
|
|
|
public Multimap<String, AttributeModifier> getAttributeModifiers(EntityEquipmentSlot slot,
|
|
|
|
ItemStack stack) {
|
2016-08-10 01:29:47 +02:00
|
|
|
Multimap<String, AttributeModifier> multimap = HashMultimap.<String, AttributeModifier>create();
|
|
|
|
int modifier = 0;
|
2017-06-11 22:22:07 +02:00
|
|
|
if (!stack.isEmpty() && stack.getTagCompound() != null && stack.getTagCompound().getBoolean("isActive"))
|
2016-08-10 01:29:47 +02:00
|
|
|
modifier = 9;
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
if (slot == EntityEquipmentSlot.MAINHAND) {
|
2016-11-19 13:50:08 +01:00
|
|
|
multimap.put(SharedMonsterAttributes.ATTACK_DAMAGE.getName(),
|
2016-10-08 21:46:16 +02:00
|
|
|
new AttributeModifier(ATTACK_DAMAGE_MODIFIER, "Weapon modifier", (double) modifier, 0));
|
2016-11-19 13:50:08 +01:00
|
|
|
multimap.put(SharedMonsterAttributes.ATTACK_SPEED.getName(),
|
2016-10-08 21:46:16 +02:00
|
|
|
new AttributeModifier(ATTACK_SPEED_MODIFIER, "Weapon modifier", -2.4000000953674316D, 0));
|
2016-08-10 01:29:47 +02:00
|
|
|
}
|
|
|
|
return multimap;
|
|
|
|
}
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
@Override
|
|
|
|
public boolean hitEntity(ItemStack itemstack, EntityLivingBase entityliving,
|
|
|
|
EntityLivingBase entityliving1) {
|
|
|
|
if (PoweredItem.canUseEnergy(cost, itemstack)) {
|
2016-08-10 01:29:47 +02:00
|
|
|
PoweredItem.useEnergy(cost, itemstack);
|
|
|
|
return true;
|
2016-10-08 21:46:16 +02:00
|
|
|
} else {
|
2016-08-10 01:29:47 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
@SuppressWarnings({ "rawtypes", "unchecked" })
|
|
|
|
@SideOnly(Side.CLIENT)
|
2017-06-11 22:22:07 +02:00
|
|
|
@Override
|
|
|
|
public void getSubItems(
|
2017-06-12 15:23:32 +02:00
|
|
|
CreativeTabs par2CreativeTabs, NonNullList itemList) {
|
2017-06-12 18:30:21 +02:00
|
|
|
if(!func_194125_a(par2CreativeTabs)){
|
|
|
|
return;
|
|
|
|
}
|
2017-01-01 08:29:32 +01:00
|
|
|
ItemStack inactiveUncharged = new ItemStack(ModItems.NANOSABER);
|
2016-08-10 01:29:47 +02:00
|
|
|
inactiveUncharged.setTagCompound(new NBTTagCompound());
|
|
|
|
inactiveUncharged.getTagCompound().setBoolean("isActive", false);
|
|
|
|
|
2017-01-01 08:29:32 +01:00
|
|
|
ItemStack inactiveCharged = new ItemStack(ModItems.NANOSABER);
|
2016-08-10 01:29:47 +02:00
|
|
|
inactiveCharged.setTagCompound(new NBTTagCompound());
|
|
|
|
inactiveCharged.getTagCompound().setBoolean("isActive", false);
|
|
|
|
PoweredItem.setEnergy(getMaxPower(inactiveCharged), inactiveCharged);
|
|
|
|
|
2017-01-01 08:29:32 +01:00
|
|
|
ItemStack activeCharged = new ItemStack(ModItems.NANOSABER);
|
2016-08-10 01:29:47 +02:00
|
|
|
activeCharged.setTagCompound(new NBTTagCompound());
|
|
|
|
activeCharged.getTagCompound().setBoolean("isActive", true);
|
|
|
|
PoweredItem.setEnergy(getMaxPower(activeCharged), activeCharged);
|
|
|
|
|
|
|
|
itemList.add(inactiveUncharged);
|
|
|
|
itemList.add(inactiveCharged);
|
|
|
|
itemList.add(activeCharged);
|
|
|
|
}
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean par4) {
|
|
|
|
if (stack.getTagCompound() == null || !stack.getTagCompound().getBoolean("isActive")) {
|
2016-08-10 01:29:47 +02:00
|
|
|
list.add(TextFormatting.GRAY + I18n.translateToLocal("techreborn.message.nanosaberInactive"));
|
2016-10-08 21:46:16 +02:00
|
|
|
} else {
|
2016-08-10 01:29:47 +02:00
|
|
|
list.add(TextFormatting.GRAY + I18n.translateToLocal("techreborn.message.nanosaberActive"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
@Override
|
2017-02-03 14:18:15 +01:00
|
|
|
public ActionResult<ItemStack> onItemRightClick(final World world, final EntityPlayer player,
|
2017-06-12 15:23:32 +02:00
|
|
|
final EnumHand hand) {
|
2017-02-03 14:18:15 +01:00
|
|
|
final ItemStack stack = player.getHeldItem(hand);
|
2016-10-08 21:46:16 +02:00
|
|
|
if (player.isSneaking()) {
|
2017-02-03 14:18:15 +01:00
|
|
|
if (!PoweredItem.canUseEnergy(this.cost, stack)) {
|
2016-11-05 17:29:37 +01:00
|
|
|
ChatUtils.sendNoSpamMessages(MessageIDs.nanosaberID, new TextComponentString(
|
2017-06-12 15:23:32 +02:00
|
|
|
TextFormatting.GRAY + I18n.translateToLocal("techreborn.message.nanosaberEnergyErrorTo") + " "
|
|
|
|
+ TextFormatting.GOLD + I18n
|
|
|
|
.translateToLocal("techreborn.message.nanosaberActivate")));
|
2016-10-08 21:46:16 +02:00
|
|
|
} else {
|
2016-11-05 17:29:37 +01:00
|
|
|
if (stack.getTagCompound() == null || !stack.getTagCompound().getBoolean("isActive")) {
|
|
|
|
if (stack.getTagCompound() == null) {
|
|
|
|
stack.setTagCompound(new NBTTagCompound());
|
|
|
|
}
|
|
|
|
stack.getTagCompound().setBoolean("isActive", true);
|
2017-02-03 14:18:15 +01:00
|
|
|
if (world.isRemote && ConfigTechReborn.NanosaberChat) {
|
2016-11-05 17:29:37 +01:00
|
|
|
ChatUtils.sendNoSpamMessages(MessageIDs.nanosaberID, new TextComponentString(
|
2017-06-12 15:23:32 +02:00
|
|
|
TextFormatting.GRAY + I18n.translateToLocal("techreborn.message.setTo") + " "
|
|
|
|
+ TextFormatting.GOLD + I18n
|
|
|
|
.translateToLocal("techreborn.message.nanosaberActive")));
|
2016-11-05 17:29:37 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
stack.getTagCompound().setBoolean("isActive", false);
|
2017-02-03 14:18:15 +01:00
|
|
|
if (world.isRemote && ConfigTechReborn.NanosaberChat) {
|
2016-11-05 17:29:37 +01:00
|
|
|
ChatUtils.sendNoSpamMessages(MessageIDs.nanosaberID, new TextComponentString(
|
2017-06-12 15:23:32 +02:00
|
|
|
TextFormatting.GRAY + I18n.translateToLocal("techreborn.message.setTo") + " "
|
|
|
|
+ TextFormatting.GOLD + I18n
|
|
|
|
.translateToLocal("techreborn.message.nanosaberInactive")));
|
2016-11-05 17:29:37 +01:00
|
|
|
}
|
2016-08-10 01:29:47 +02:00
|
|
|
}
|
|
|
|
}
|
2016-11-05 17:29:37 +01:00
|
|
|
return new ActionResult<>(EnumActionResult.SUCCESS, stack);
|
|
|
|
}
|
|
|
|
return new ActionResult<>(EnumActionResult.PASS, stack);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) {
|
|
|
|
if (stack.getTagCompound() != null && stack.getTagCompound().getBoolean("isActive") && !PoweredItem.canUseEnergy(cost, stack)) {
|
|
|
|
ChatUtils.sendNoSpamMessages(MessageIDs.nanosaberID, new TextComponentString(
|
|
|
|
TextFormatting.GRAY + I18n.translateToLocal("techreborn.message.nanosaberEnergyError") + " "
|
|
|
|
+ TextFormatting.GOLD + I18n
|
|
|
|
.translateToLocal("techreborn.message.nanosaberDeactivating")));
|
|
|
|
stack.getTagCompound().setBoolean("isActive", false);
|
2016-08-10 01:29:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
@Override
|
|
|
|
public boolean isRepairable() {
|
2016-08-10 01:29:47 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
@Override
|
|
|
|
public double getMaxPower(ItemStack stack) {
|
2016-08-10 01:29:47 +02:00
|
|
|
return 100000;
|
|
|
|
}
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
@Override
|
|
|
|
public boolean canAcceptEnergy(ItemStack stack) {
|
2016-08-10 01:29:47 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
@Override
|
|
|
|
public boolean canProvideEnergy(ItemStack stack) {
|
2016-08-10 01:29:47 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
@Override
|
|
|
|
public double getMaxTransfer(ItemStack stack) {
|
2016-08-10 01:29:47 +02:00
|
|
|
return 512;
|
|
|
|
}
|
|
|
|
|
2016-03-07 08:01:02 +01:00
|
|
|
}
|