60 lines
3.3 KiB
Java
60 lines
3.3 KiB
Java
package com.thebrokenrail.twine.item;
|
|
|
|
import com.thebrokenrail.twine.Twine;
|
|
import com.thebrokenrail.twine.component.StageDataComponent;
|
|
import com.thebrokenrail.twine.util.ItemUtil;
|
|
import net.fabricmc.api.EnvType;
|
|
import net.fabricmc.api.Environment;
|
|
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.server.world.ServerWorld;
|
|
import net.minecraft.text.LiteralText;
|
|
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.TypedActionResult;
|
|
import net.minecraft.util.math.BlockPos;
|
|
import net.minecraft.world.World;
|
|
|
|
import java.util.List;
|
|
|
|
public class DivinerItem extends Item {
|
|
public DivinerItem() {
|
|
super(new Settings().group(Twine.ITEM_GROUP).maxDamage(6));
|
|
}
|
|
|
|
@Override
|
|
public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) {
|
|
ItemStack stack = user.getStackInHand(hand);
|
|
if (!world.isClient()) {
|
|
StageDataComponent component = StageDataComponent.getFromWorld((ServerWorld) world);
|
|
BlockPos pos = user.getBlockPos();
|
|
|
|
int stage = component.findEffectiveStageOfChunk((ServerWorld) world, pos);
|
|
|
|
StageDataComponent.StageData[] personalData = component.getData(user.getUuid());
|
|
int effectiveStage = StageDataComponent.findStageOfChunk(pos, personalData);
|
|
|
|
user.sendMessage(new TranslatableText("chat.twine.diviner_info_1", new LiteralText(String.valueOf(stage + 1)).formatted(Formatting.WHITE)).formatted(Formatting.YELLOW), false);
|
|
user.sendMessage(new TranslatableText("chat.twine.diviner_info_2", (stage + 1 >= Twine.STAGE_COUNT ? new TranslatableText("chat.twine.diviner_info_never") : new LiteralText(String.valueOf(Twine.STAGE_TIME - component.findEffectiveTimeOfChunk((ServerWorld) world, pos)))).formatted(Formatting.WHITE)).formatted(Formatting.YELLOW), false);
|
|
user.sendMessage(new TranslatableText("chat.twine.diviner_info_3", new LiteralText(String.valueOf(effectiveStage + 1)).formatted(Formatting.WHITE)).formatted(Formatting.YELLOW), false);
|
|
user.sendMessage(new TranslatableText("chat.twine.diviner_info_4", new LiteralText(String.valueOf(personalData[effectiveStage].x)).formatted(Formatting.WHITE), new LiteralText(String.valueOf(personalData[effectiveStage].z)).formatted(Formatting.WHITE)).formatted(Formatting.YELLOW), false);
|
|
user.sendMessage(new TranslatableText("chat.twine.diviner_info_5", (effectiveStage + 1 >= Twine.STAGE_COUNT ? new TranslatableText("chat.twine.diviner_info_never") : new LiteralText(String.valueOf(Twine.STAGE_TIME - personalData[effectiveStage].time))).formatted(Formatting.WHITE)).formatted(Formatting.YELLOW), false);
|
|
|
|
stack.damage(1, user, e -> e.sendToolBreakStatus(hand));
|
|
}
|
|
return new TypedActionResult<>(ActionResult.SUCCESS, stack);
|
|
}
|
|
|
|
@Override
|
|
@Environment(EnvType.CLIENT)
|
|
public void appendTooltip(ItemStack stack, World world, List<Text> tooltip, TooltipContext context) {
|
|
super.appendTooltip(stack, world, tooltip, context);
|
|
ItemUtil.addTooltip("item", "diviner", 2, tooltip);
|
|
}
|
|
}
|