2020-04-15 22:19:40 +00:00
|
|
|
package com.thebrokenrail.reliccraft.item;
|
|
|
|
|
|
|
|
import com.squareup.moshi.JsonAdapter;
|
|
|
|
import com.squareup.moshi.Moshi;
|
|
|
|
import com.thebrokenrail.reliccraft.RelicCraft;
|
|
|
|
import com.thebrokenrail.reliccraft.data.RelicData;
|
|
|
|
import net.minecraft.client.item.TooltipContext;
|
|
|
|
import net.minecraft.entity.player.PlayerEntity;
|
|
|
|
import net.minecraft.item.Item;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.nbt.CompoundTag;
|
2020-04-15 22:53:31 +00:00
|
|
|
import net.minecraft.stat.Stats;
|
2020-04-15 22:19:40 +00:00
|
|
|
import net.minecraft.text.Text;
|
|
|
|
import net.minecraft.text.TranslatableText;
|
|
|
|
import net.minecraft.util.ActionResult;
|
|
|
|
import net.minecraft.util.Formatting;
|
|
|
|
import net.minecraft.util.Hand;
|
|
|
|
import net.minecraft.util.Rarity;
|
|
|
|
import net.minecraft.util.TypedActionResult;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
public class GenerateRelicItem extends Item {
|
|
|
|
public GenerateRelicItem() {
|
2020-04-16 02:42:41 +00:00
|
|
|
super(new Settings().group(RelicCraft.ITEM_GROUP).rarity(Rarity.UNCOMMON));
|
2020-04-15 22:19:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) {
|
|
|
|
ItemStack stack = user.getStackInHand(hand);
|
|
|
|
|
|
|
|
if (!world.isClient()) {
|
2020-04-15 22:53:31 +00:00
|
|
|
user.incrementStat(Stats.USED.getOrCreateStat(this));
|
|
|
|
|
2020-04-15 22:19:40 +00:00
|
|
|
RelicCraft.playRelicSound(user);
|
|
|
|
|
|
|
|
ItemStack newStack;
|
|
|
|
if (RANDOM.nextBoolean()) {
|
|
|
|
newStack = new ItemStack(RelicCraft.ORB_ITEM);
|
|
|
|
} else {
|
|
|
|
newStack = new ItemStack(RelicCraft.STAFF_ITEM);
|
|
|
|
}
|
|
|
|
|
|
|
|
CompoundTag tag = new CompoundTag();
|
|
|
|
Moshi moshi = new Moshi.Builder().build();
|
|
|
|
JsonAdapter<RelicData> jsonAdapter = moshi.adapter(RelicData.class);
|
|
|
|
tag.putString("RelicData", jsonAdapter.toJson(RelicData.generate(RANDOM)));
|
|
|
|
newStack.setTag(tag);
|
|
|
|
|
|
|
|
if (!user.isCreative()) {
|
|
|
|
stack.decrement(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!user.inventory.insertStack(newStack.copy())) {
|
|
|
|
user.dropItem(newStack, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return new TypedActionResult<>(ActionResult.SUCCESS, stack);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void appendTooltip(ItemStack stack, World world, List<Text> tooltip, TooltipContext context) {
|
|
|
|
tooltip.add(new TranslatableText("item." + RelicCraft.NAMESPACE + ".generate_relic.tooltip").formatted(Formatting.GRAY));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-06-28 16:38:49 +00:00
|
|
|
public boolean hasGlint(ItemStack stack) {
|
2020-04-15 22:19:40 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|