Skip to content

Commit

Permalink
完成罗盘设计
Browse files Browse the repository at this point in the history
  • Loading branch information
TartaricAcid committed Dec 27, 2023
1 parent 066d2da commit 2455fbd
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.mojang.blaze3d.vertex.VertexConsumer;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.resources.language.I18n;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.schedule.Activity;
import net.minecraft.world.item.ItemStack;
Expand All @@ -31,53 +32,65 @@ public static void onRender(RenderLevelStageEvent event) {
}
ItemStack stack = mc.player.getMainHandItem();
if (stack.getItem() != InitItems.KAPPA_COMPASS.get()) {
return;
stack = mc.player.getOffhandItem();
if (stack.getItem() != InitItems.KAPPA_COMPASS.get()) {
return;
}
}
if (!ItemKappaCompass.hasKappaCompassData(stack)) {
return;
}
BlockPos workPos = ItemKappaCompass.getPoint(Activity.WORK, stack);
Vec3 camera = event.getCamera().getPosition().reverse();
event.getPoseStack().pushPose();
event.getPoseStack().translate(0, 1, 0);
if (workPos != null) {
Vec3 camera = event.getCamera().getPosition().reverse();
Vec3 centerPos = camera.add(workPos.getX(), workPos.getY(), workPos.getZ());
int radius = MaidConfig.MAID_WORK_RANGE.get();

Vec3 centerPos = camera.add(workPos.getX() + 0.5, workPos.getY() + 0.5, workPos.getZ() + 0.5);
double radius = MaidConfig.MAID_WORK_RANGE.get() + 0.1;
VertexConsumer buffer = mc.renderBuffers().bufferSource().getBuffer(RenderType.LINES);
RenderHelper.renderCylinder(event.getPoseStack(), buffer, centerPos.add(0, 2, 0), radius, 32, 1.0F, 0, 0);
RenderHelper.renderCylinder(event.getPoseStack(), buffer, centerPos.add(0, 1, 0), radius, 32, 1.0F, 0, 0);
RenderHelper.renderCylinder(event.getPoseStack(), buffer, centerPos, radius, 32, 1.0F, 0, 0);

RenderHelper.renderFloatingText(event.getPoseStack(), "工作区域", new Vec3(workPos.getX(), workPos.getY(), workPos.getZ()), 0xff1111, 0.2f, -10);
RenderHelper.renderFloatingText(event.getPoseStack(), "▼", new Vec3(workPos.getX(), workPos.getY(), workPos.getZ()), 0xff1111, 0.2f, 0);
RenderHelper.renderCylinder(event.getPoseStack(), buffer, centerPos, radius, 16, 1.0F, 0, 0);
Vec3 textPos = new Vec3(workPos.getX() + 0.5, workPos.getY() + 0.5, workPos.getZ() + 0.5);
String text = I18n.get("message.touhou_little_maid.kappa_compass.work_area");
RenderHelper.renderFloatingText(event.getPoseStack(), text, textPos, 0xff1111, 0.15f, -5);
RenderHelper.renderFloatingText(event.getPoseStack(), "▼", textPos, 0xff1111, 0.15f, 5);
}

BlockPos idlePos = ItemKappaCompass.getPoint(Activity.IDLE, stack);
if (idlePos != null) {
Vec3 position = event.getCamera().getPosition().reverse();
Vec3 pos = position.add(idlePos.getX(), idlePos.getY(), idlePos.getZ());
int radius = MaidConfig.MAID_IDLE_RANGE.get();
Vec3 centerPos = camera.add(idlePos.getX() + 0.5, idlePos.getY() + 0.5, idlePos.getZ() + 0.5);
double radius = MaidConfig.MAID_IDLE_RANGE.get();
VertexConsumer buffer = mc.renderBuffers().bufferSource().getBuffer(RenderType.LINES);
RenderHelper.renderCylinder(event.getPoseStack(), buffer, pos.add(0, 2, 0), radius, 32, 0, 1.0F, 0);
RenderHelper.renderCylinder(event.getPoseStack(), buffer, pos.add(0, 1, 0), radius, 32, 0, 1.0F, 0);
RenderHelper.renderCylinder(event.getPoseStack(), buffer, pos, radius, 32, 0, 1.0F, 0);

RenderHelper.renderFloatingText(event.getPoseStack(), "休息区域", new Vec3(idlePos.getX(), idlePos.getY(), idlePos.getZ()), 0x11ff11, 0.15f, -10);
RenderHelper.renderFloatingText(event.getPoseStack(), "▼", new Vec3(idlePos.getX(), idlePos.getY(), idlePos.getZ()), 0x11ff11, 0.15f, 0);
RenderHelper.renderCylinder(event.getPoseStack(), buffer, centerPos, radius, 16, 0, 1.0F, 0);
Vec3 textPos = new Vec3(idlePos.getX() + 0.5, idlePos.getY() + 0.5, idlePos.getZ() + 0.5);
if (idlePos.equals(workPos)) {
textPos = textPos.add(0, 1, 0);
} else if (workPos != null) {
Vec3 prePos = camera.add(workPos.getX() + 0.5, workPos.getY() + 0.5, workPos.getZ() + 0.5);
RenderHelper.renderLine(event.getPoseStack(), buffer, centerPos, prePos, 1.0f, 1.0f, 1.0f);
}
String text = I18n.get("message.touhou_little_maid.kappa_compass.idle_area");
RenderHelper.renderFloatingText(event.getPoseStack(), text, textPos, 0x11ff11, 0.15f, -5);
RenderHelper.renderFloatingText(event.getPoseStack(), "▼", textPos, 0x11ff11, 0.15f, 5);
}

BlockPos resetPos = ItemKappaCompass.getPoint(Activity.REST, stack);
if (resetPos != null) {
Vec3 position = event.getCamera().getPosition().reverse();
Vec3 pos = position.add(resetPos.getX(), resetPos.getY(), resetPos.getZ());
double radius = MaidConfig.MAID_SLEEP_RANGE.get() - 0.2;
Vec3 centerPos = camera.add(resetPos.getX() + 0.5, resetPos.getY() + 0.5, resetPos.getZ() + 0.5);
double radius = MaidConfig.MAID_SLEEP_RANGE.get() - 0.1;
VertexConsumer buffer = mc.renderBuffers().bufferSource().getBuffer(RenderType.LINES);
RenderHelper.renderCylinder(event.getPoseStack(), buffer, pos.add(0, 2, 0), radius, 32, 0, 0, 1.0F);
RenderHelper.renderCylinder(event.getPoseStack(), buffer, pos.add(0, 1, 0), radius, 32, 0, 0, 1.0F);
RenderHelper.renderCylinder(event.getPoseStack(), buffer, pos, radius, 32, 0, 0, 1.0F);

RenderHelper.renderFloatingText(event.getPoseStack(), "睡觉区域", new Vec3(resetPos.getX(), resetPos.getY(), resetPos.getZ()), 0x1111ff, 0.1f, -10);
RenderHelper.renderFloatingText(event.getPoseStack(), "▼", new Vec3(resetPos.getX(), resetPos.getY(), resetPos.getZ()), 0x1111ff, 0.1f, 0);
RenderHelper.renderCylinder(event.getPoseStack(), buffer, centerPos, radius, 16, 0, 0, 1.0F);
Vec3 textPos = new Vec3(resetPos.getX() + 0.5, resetPos.getY() + 0.5, resetPos.getZ() + 0.5);
if (resetPos.equals(idlePos)) {
textPos = textPos.add(0, 2, 0);
} else if (idlePos != null) {
Vec3 prePos = camera.add(idlePos.getX() + 0.5, idlePos.getY() + 0.5, idlePos.getZ() + 0.5);
RenderHelper.renderLine(event.getPoseStack(), buffer, centerPos, prePos, 1.0f, 1.0f, 1.0f);
}
String text = I18n.get("message.touhou_little_maid.kappa_compass.sleep_area");
RenderHelper.renderFloatingText(event.getPoseStack(), text, textPos, 0x1111ff, 0.15f, -5);
RenderHelper.renderFloatingText(event.getPoseStack(), "▼", textPos, 0x1111ff, 0.15f, 5);
}
event.getPoseStack().popPose();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ public MaidUpdateActivityFromSchedule() {
super(ImmutableMap.of());
}

protected void start(ServerLevel level, EntityMaid maid, long gameTIme) {
protected void start(ServerLevel level, EntityMaid maid, long gameTime) {
Brain<EntityMaid> brain = maid.getBrain();
long dayTime = level.getDayTime();
if (maid.tickCount % 20 == 0) {
if (gameTime - brain.lastScheduleUpdate > 20L) {
Activity activity = brain.getSchedule().getActivityAt((int) (dayTime % 24000L));
if (!brain.isActive(activity)) {
maid.getSchedulePos().restrictTo(maid);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
package com.github.tartaricacid.touhoulittlemaid.item;

import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
import com.github.tartaricacid.touhoulittlemaid.init.InitSounds;
import net.minecraft.ChatFormatting;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtUtils;
import net.minecraft.nbt.Tag;
import net.minecraft.network.chat.Component;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.schedule.Activity;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.Level;

import javax.annotation.Nullable;
import java.util.List;

public class ItemKappaCompass extends Item {
public ItemKappaCompass() {
Expand Down Expand Up @@ -74,6 +80,7 @@ public InteractionResult interactLivingEntity(ItemStack compass, Player player,
if (player.isDiscrete()) {
maid.getSchedulePos().clear(maid);
player.sendSystemMessage(Component.translatable("message.touhou_little_maid.kappa_compass.maid_clear"));
player.level.playSound(null, player.blockPosition(), InitSounds.COMPASS_POINT.get(), SoundSource.PLAYERS, 0.8f, 1.5f);
return InteractionResult.SUCCESS;
}
CompoundTag tag = compass.getTagElement("KappaCompassData");
Expand All @@ -93,6 +100,7 @@ public InteractionResult interactLivingEntity(ItemStack compass, Player player,
maid.getSchedulePos().setConfigured(true);
maid.getSchedulePos().restrictTo(maid);
player.sendSystemMessage(Component.translatable("message.touhou_little_maid.kappa_compass.maid_write"));
player.level.playSound(null, player.blockPosition(), InitSounds.COMPASS_POINT.get(), SoundSource.PLAYERS, 0.8f, 1.5f);
return InteractionResult.SUCCESS;
}
player.sendSystemMessage(Component.translatable("message.touhou_little_maid.kappa_compass.no_data"));
Expand Down Expand Up @@ -137,6 +145,25 @@ public InteractionResult useOn(UseOnContext context) {
player.sendSystemMessage(Component.translatable("message.touhou_little_maid.kappa_compass.work", clickedPos.getX(), clickedPos.getY(), clickedPos.getZ()));
}
}
player.level.playSound(null, player.blockPosition(), InitSounds.COMPASS_POINT.get(), SoundSource.PLAYERS, 0.8f, 1.5f);
return InteractionResult.SUCCESS;
}

@Override
public void appendHoverText(ItemStack stack, @Nullable Level pLevel, List<Component> components, TooltipFlag pIsAdvanced) {
if (hasKappaCompassData(stack)) {
BlockPos workPos = getPoint(Activity.WORK, stack);
BlockPos idlePos = getPoint(Activity.IDLE, stack);
BlockPos sleepPos = getPoint(Activity.REST, stack);
if (workPos != null) {
components.add(Component.translatable("message.touhou_little_maid.kappa_compass.work", workPos.getX(), workPos.getY(), workPos.getZ()).withStyle(ChatFormatting.GRAY));
}
if (idlePos != null) {
components.add(Component.translatable("message.touhou_little_maid.kappa_compass.idle", idlePos.getX(), idlePos.getY(), idlePos.getZ()).withStyle(ChatFormatting.GRAY));
}
if (sleepPos != null) {
components.add(Component.translatable("message.touhou_little_maid.kappa_compass.sleep", sleepPos.getX(), sleepPos.getY(), sleepPos.getZ()).withStyle(ChatFormatting.GRAY));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,19 @@ public static void renderFloatingText(PoseStack poseStack, String text, double x
}
}

public static void renderLine(PoseStack poseStack, VertexConsumer consumer, Vec3 start, Vec3 end, float red, float green, float blue) {
Matrix4f matrix4f = poseStack.last().pose();
Matrix3f matrix3f = poseStack.last().normal();
consumer.vertex(matrix4f, (float) start.x, (float) start.y, (float) start.z).color(red, green, blue, 1.0F).normal(matrix3f, 1.0F, 0.0F, 0.0F).endVertex();
consumer.vertex(matrix4f, (float) end.x, (float) end.y, (float) end.z).color(red, green, blue, 1.0F).normal(matrix3f, 1.0F, 0.0F, 0.0F).endVertex();

consumer.vertex(matrix4f, (float) start.x, (float) start.y, (float) start.z).color(red, green, blue, 1.0F).normal(matrix3f, 0.0F, 1.0F, 0.0F).endVertex();
consumer.vertex(matrix4f, (float) end.x, (float) end.y, (float) end.z).color(red, green, blue, 1.0F).normal(matrix3f, 0.0F, 1.0F, 0.0F).endVertex();

consumer.vertex(matrix4f, (float) start.x, (float) start.y, (float) start.z).color(red, green, blue, 1.0F).normal(matrix3f, 0.0F, 0.0F, 1.0F).endVertex();
consumer.vertex(matrix4f, (float) end.x, (float) end.y, (float) end.z).color(red, green, blue, 1.0F).normal(matrix3f, 0.0F, 0.0F, 1.0F).endVertex();
}

public static void renderCylinder(PoseStack poseStack, VertexConsumer consumer, Vec3 centerPos, double radius, int precision, float red, float green, float blue) {
Matrix4f matrix4f = poseStack.last().pose();
Matrix3f matrix3f = poseStack.last().normal();
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/META-INF/accesstransformer.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ public net.minecraft.world.entity.ai.goal.TemptGoal f_25924_ # mob
public net.minecraft.world.entity.ai.goal.TemptGoal f_25927_ # speedModifier
public net.minecraft.world.entity.ai.goal.TemptGoal f_25935_ # items
public net.minecraft.world.entity.ai.goal.TemptGoal f_25936_ # canScare

public net.minecraft.world.entity.ai.Brain f_21852_ # lastScheduleUpdate
3 changes: 3 additions & 0 deletions src/main/resources/assets/touhou_little_maid/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@
"message.touhou_little_maid.kappa_compass.work": "Work Pos: [%d, %d, %d]",
"message.touhou_little_maid.kappa_compass.idle": "Idle Pos: [%d, %d, %d]",
"message.touhou_little_maid.kappa_compass.sleep": "Sleep Pos: [%d, %d, %d]",
"message.touhou_little_maid.kappa_compass.work_area": "Work Area",
"message.touhou_little_maid.kappa_compass.idle_area": "Idle Area",
"message.touhou_little_maid.kappa_compass.sleep_area": "Sleep Area",
"commands.touhou_little_maid.pack.reload.info": "All model pack have been reloaded!",
"commands.touhou_little_maid.power.handle.info": "%d players's power point is changed",
"commands.touhou_little_maid.maid_num.handle.info": "%d players's maid num is changed",
Expand Down

0 comments on commit 2455fbd

Please sign in to comment.