47 lines
2.9 KiB
Java
47 lines
2.9 KiB
Java
package com.thebrokenrail.twine.item;
|
|
|
|
import com.thebrokenrail.twine.Twine;
|
|
import com.thebrokenrail.twine.component.StageDataComponent;
|
|
import net.minecraft.entity.player.PlayerEntity;
|
|
import net.minecraft.item.Item;
|
|
import net.minecraft.item.ItemStack;
|
|
import net.minecraft.item.SwordItem;
|
|
import net.minecraft.server.world.ServerWorld;
|
|
import net.minecraft.text.LiteralText;
|
|
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.ChunkPos;
|
|
import net.minecraft.world.World;
|
|
|
|
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);
|
|
ChunkPos chunkPos = new ChunkPos(user.getBlockPos());
|
|
|
|
int stage = component.findEffectiveStageOfChunk((ServerWorld) world, chunkPos);
|
|
|
|
StageDataComponent.StageData[] personalData = component.getData(user.getUuid());
|
|
int effectiveStage = StageDataComponent.findStageOfChunk(chunkPos, 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, chunkPos)))).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 << 4)).formatted(Formatting.WHITE), new LiteralText(String.valueOf(personalData[effectiveStage].z << 4)).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);
|
|
}
|
|
}
|