NaturesAura/src/main/java/de/ellpeck/naturesaura/items/EnderAccess.java

46 lines
1.8 KiB
Java
Raw Normal View History

2019-02-18 12:15:18 +01:00
package de.ellpeck.naturesaura.items;
2019-02-18 19:30:35 +01:00
import com.google.common.base.Strings;
2019-02-18 12:15:18 +01:00
import de.ellpeck.naturesaura.NaturesAura;
2019-02-18 13:00:54 +01:00
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
2019-02-18 19:30:35 +01:00
import de.ellpeck.naturesaura.blocks.BlockEnderCrate;
import net.minecraft.client.util.ITooltipFlag;
2019-10-20 22:30:49 +02:00
import net.minecraft.entity.player.PlayerEntity;
2019-02-18 12:15:18 +01:00
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
2019-10-20 22:30:49 +02:00
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Hand;
2019-11-04 19:08:49 +01:00
import net.minecraft.util.text.ITextComponent;
2019-02-18 12:15:18 +01:00
import net.minecraft.world.World;
2019-10-20 22:30:49 +02:00
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
2019-02-18 19:30:35 +01:00
import javax.annotation.Nullable;
import java.util.List;
2019-02-18 12:15:18 +01:00
2019-11-04 19:08:49 +01:00
public class EnderAccess extends ItemImpl {
public EnderAccess() {
super("ender_access", new Properties().group(NaturesAura.CREATIVE_TAB));
2019-02-18 12:15:18 +01:00
}
@Override
2019-10-20 22:30:49 +02:00
public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) {
if (handIn != Hand.MAIN_HAND)
return new ActionResult<>(ActionResultType.PASS, playerIn.getHeldItem(handIn));
2019-02-18 12:15:18 +01:00
ItemStack stack = playerIn.getHeldItemMainhand();
2019-02-18 19:30:35 +01:00
if (!Strings.isNullOrEmpty(BlockEnderCrate.getEnderName(stack))) {
if (!worldIn.isRemote && NaturesAuraAPI.instance().extractAuraFromPlayer(playerIn, 10000, false))
2019-11-04 19:08:49 +01:00
// TODO playerIn.openGui(NaturesAura.MOD_ID, 1, worldIn, (int) playerIn.posX, (int) playerIn.posY, (int) playerIn.posZ);
2019-10-20 22:30:49 +02:00
return new ActionResult<>(ActionResultType.SUCCESS, stack);
2019-02-18 12:15:18 +01:00
}
2019-10-20 22:30:49 +02:00
return new ActionResult<>(ActionResultType.FAIL, stack);
2019-02-18 12:15:18 +01:00
}
2019-02-18 19:30:35 +01:00
2019-11-04 19:08:49 +01:00
2019-02-18 19:30:35 +01:00
@Override
2019-10-20 22:30:49 +02:00
@OnlyIn(Dist.CLIENT)
2019-11-04 19:08:49 +01:00
public void addInformation(ItemStack stack, @Nullable World worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) {
2019-02-18 19:30:35 +01:00
BlockEnderCrate.addEnderNameInfo(stack, tooltip);
}
2019-02-18 12:15:18 +01:00
}