2024-09-17
1.取消了对LivingEntity的Mixin 2.更新另一个进度条(仍在调试阶段) 3.修复指令上的纰漏
This commit is contained in:
parent
7663bf5e9e
commit
14b082dd1f
|
|
@ -1,6 +1,7 @@
|
|||
// 1.21.1 2024-09-07T10:24:45.3887825 Item Models: leashedplayer
|
||||
// 1.21.1 2024-09-11T16:30:11.5982305 Item Models: leashedplayer
|
||||
5846df9d85726428905701120ef34c9324c20faf assets/leashedplayer/models/item/bow_lra_pulling_0.json
|
||||
845a7316b86e26f88c6932d4ef2656126503727a assets/leashedplayer/models/item/bow_lra_pulling_1.json
|
||||
5bd1f9f28b91005c587f1c38fb77cd19b59495e3 assets/leashedplayer/models/item/bow_lra_pulling_2.json
|
||||
83946f4d60d0fb1758d6553c36330506c8e48ada assets/leashedplayer/models/item/crossbow_leash_rope_arrow.json
|
||||
bb0d76077719c83c8a8bd4346a24ea1766175125 assets/leashedplayer/models/item/fabric.json
|
||||
114d3cc5832ef047403114504483c6f3ea07e77c assets/leashedplayer/models/item/leash_rope_arrow.json
|
||||
|
|
|
|||
|
|
@ -1,2 +1,2 @@
|
|||
// 1.21.1 2024-09-09T15:57:30.9531898 Languages: en_us for mod: leashedplayer
|
||||
c51f1722b91e85159f4c60282bf43a1c934b151a assets/leashedplayer/lang/en_us.json
|
||||
// 1.21.1 2024-09-11T16:30:11.6002137 Languages: en_us for mod: leashedplayer
|
||||
c3d8ea4a7d24b56bd6b701c531aab3132cdc6da9 assets/leashedplayer/lang/en_us.json
|
||||
|
|
|
|||
|
|
@ -1,2 +1,2 @@
|
|||
// 1.21.1 2024-09-09T16:00:58.2714402 Languages: zh_cn for mod: leashedplayer
|
||||
bd4d6fe17ea35390bf61a642df42cb2e7bc60beb assets/leashedplayer/lang/zh_cn.json
|
||||
// 1.21.1 2024-09-11T16:30:11.5982305 Languages: zh_cn for mod: leashedplayer
|
||||
7e38a6c0cc14d7f6f362f97b2a00ca1ab2626c68 assets/leashedplayer/lang/zh_cn.json
|
||||
|
|
|
|||
|
|
@ -1,2 +1,2 @@
|
|||
// 1.21.1 2024-09-09T16:00:58.2694396 Languages: zh_tw for mod: leashedplayer
|
||||
ecf1d6cec85b001be6584c37134a76d5d75e65c0 assets/leashedplayer/lang/zh_tw.json
|
||||
// 1.21.1 2024-09-11T16:30:11.5962153 Languages: zh_tw for mod: leashedplayer
|
||||
1b05b79582ac4bce69560b88179dd216490ec0fe assets/leashedplayer/lang/zh_tw.json
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
"gamerule.LP.TeleportWithLeashedPlayers": "Teleport leashed player with player holder",
|
||||
"gamerule.LP.TeleportWithLeashedPlayers.description": "Holder will teleport with their leashed players ",
|
||||
"item.leash_rope_arrow.description": "Arrows with ropes attached?",
|
||||
"item.leashedplayer.fabric": "Fabric",
|
||||
"item.leashedplayer.leash_rope_arrow": "Leash Rope Arrow",
|
||||
"leashedplayer.command.leash.message.leash.data.clear": "%1$s's LeashData(LeashHolderEntity: %2$s) now is clear",
|
||||
"leashedplayer.command.leash.message.leash.data.clear.leash.clear.failed.no_data": "%1$s has no LeashData can be clear",
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
"gamerule.LP.TeleportWithLeashedPlayers": "被拴玩家随玩家持有者传送",
|
||||
"gamerule.LP.TeleportWithLeashedPlayers.description": "传送时将被拴玩家与持有者一起传送",
|
||||
"item.leash_rope_arrow.description": "带有拴绳的箭矢?",
|
||||
"item.leashedplayer.fabric": "Fabric",
|
||||
"item.leashedplayer.leash_rope_arrow": "拴绳箭",
|
||||
"leashedplayer.command.leash.message.leash.data.clear": "%1$s的拴绳数据(拴绳持有者实体:%2$s)现在已清除",
|
||||
"leashedplayer.command.leash.message.leash.data.clear.leash.clear.failed.no_data": "%1$s沒有拴绳数据可清除",
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
"gamerule.LP.TeleportWithLeashedPlayers": "被拴玩家随玩家持有者傳送",
|
||||
"gamerule.LP.TeleportWithLeashedPlayers.description": "將被拴玩家將隨持有者一起傳送",
|
||||
"item.leash_rope_arrow.description": "帶有拴繩的箭矢?",
|
||||
"item.leashedplayer.fabric": "Fabric",
|
||||
"item.leashedplayer.leash_rope_arrow": "拴繩箭",
|
||||
"leashedplayer.command.leash.message.leash.data.clear": "%1$s的拴繩數據(拴繩持有者實體:%2$s)現在已清除",
|
||||
"leashedplayer.command.leash.message.leash.data.clear.leash.clear.failed.no_data": "%1$s沒有拴繩數據實體可被清除",
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"parent": "minecraft:item/generated",
|
||||
"textures": {
|
||||
"layer0": "leashedplayer:item/fabric"
|
||||
}
|
||||
}
|
||||
|
|
@ -36,4 +36,5 @@ public class ClientEventHandler {
|
|||
public static void RegisterRenderer(EntityRenderersEvent.RegisterRenderers event) {
|
||||
event.registerEntityRenderer(ModEntityRegister.LEASH_ROPE_ARROW.get(), LeashRopeArrowRenderer::new);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,55 @@
|
|||
package com.r3944realms.leashedplayer.client.processBar;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
/**
|
||||
* 进度条
|
||||
|
||||
*/
|
||||
public interface IProcessBar {
|
||||
/**
|
||||
*
|
||||
* @return 存活计数 (<=0 则会被清除)
|
||||
*/
|
||||
int aliveCount();
|
||||
/**
|
||||
* 维持计数
|
||||
*/
|
||||
void retain();
|
||||
void decreaseAliveCount();
|
||||
void setRenderStatus(boolean status);
|
||||
boolean shouldRender();
|
||||
int getCurrentProcess();
|
||||
int getMaxProcess();
|
||||
void setMaxProcess(int maxProcess);
|
||||
void setProcess(int process);
|
||||
void resetProcess();
|
||||
|
||||
/**
|
||||
* 完成进度条执行的任务,由实现者实现
|
||||
*/
|
||||
void completeTask();
|
||||
default void decrease() {
|
||||
int updateValue = getCurrentProcess() - 1;
|
||||
if(updateValue < 0) {
|
||||
setRenderStatus(false);
|
||||
setProcess(0);
|
||||
}
|
||||
else {
|
||||
setRenderStatus(true);
|
||||
setProcess(updateValue);
|
||||
}
|
||||
}
|
||||
default void increase() {
|
||||
int updateValue = getCurrentProcess() + 1;
|
||||
if(updateValue > getMaxProcess()) {
|
||||
setRenderStatus(false);
|
||||
setProcess(getMaxProcess());
|
||||
completeTask();//执行任务
|
||||
}
|
||||
else {
|
||||
setRenderStatus(true);
|
||||
setProcess(updateValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,92 @@
|
|||
package com.r3944realms.leashedplayer.client.processBar;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.network.chat.ChatType;
|
||||
import net.minecraft.network.chat.Component;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class TestProcessBar implements IProcessBar {
|
||||
private int aliveCount = 0;
|
||||
private boolean isRendering;
|
||||
private int maxProgress;
|
||||
private int progress;
|
||||
public TestProcessBar() {
|
||||
aliveCount++;
|
||||
isRendering = false;
|
||||
maxProgress = 100;
|
||||
progress = 0;
|
||||
}
|
||||
public TestProcessBar(int maxProgress) {
|
||||
aliveCount++;
|
||||
isRendering = false;
|
||||
this.maxProgress = maxProgress;
|
||||
progress = 0;
|
||||
}
|
||||
public TestProcessBar(int maxProgress, int progress) {
|
||||
aliveCount++;
|
||||
isRendering = false;
|
||||
this.maxProgress = maxProgress;
|
||||
this.progress = progress;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int aliveCount() {
|
||||
return aliveCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void retain() {
|
||||
aliveCount++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decreaseAliveCount() {
|
||||
aliveCount = aliveCount > 0 ? aliveCount - 1 : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRenderStatus(boolean status) {
|
||||
isRendering = status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldRender() {
|
||||
return isRendering;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCurrentProcess() {
|
||||
return progress;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxProcess() {
|
||||
return maxProgress;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxProcess(int maxProcess) {
|
||||
this.maxProgress = maxProcess;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProcess(int process) {
|
||||
this.progress = process < 0 ? 0 : (Math.min(process, maxProgress));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetProcess() {
|
||||
this.progress = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void completeTask() {
|
||||
Runnable runnable = () -> {
|
||||
if (Minecraft.getInstance().player != null) {
|
||||
Minecraft.getInstance().getChatListener().handleDisguisedChatMessage(Component.literal("Completed"), ChatType.bind(ChatType.MSG_COMMAND_OUTGOING, Minecraft.getInstance().player));
|
||||
}
|
||||
};
|
||||
CompletableFuture.runAsync(runnable);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
package com.r3944realms.leashedplayer.client.renders;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.r3944realms.leashedplayer.LeashedPlayer;
|
||||
import com.r3944realms.leashedplayer.client.processBar.IProcessBar;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
import net.neoforged.fml.common.EventBusSubscriber;
|
||||
import net.neoforged.neoforge.client.event.RenderGuiEvent;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@EventBusSubscriber(modid = LeashedPlayer.MOD_ID, value = Dist.CLIENT)
|
||||
public class AdaptiveGuiRendererHandler {
|
||||
private static final Map<IProcessBar, IProcessBarRenderer<? extends IProcessBar>> processBars = Maps.newConcurrentMap();
|
||||
public static void addProcessBar(IProcessBar processBar, IProcessBarRenderer<? extends IProcessBar> renderer) {
|
||||
processBars.put(processBar, renderer);
|
||||
}
|
||||
public static IProcessBarRenderer<? extends IProcessBar> getProcessBarRenderer(IProcessBar processBar) {
|
||||
return processBars.get(processBar);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onRendererLevel(RenderGuiEvent.Pre event) {
|
||||
PoseStack matrixStack = event.getGuiGraphics().pose();
|
||||
GuiGraphics guiGraphics = event.getGuiGraphics();
|
||||
processBars.keySet().forEach(
|
||||
processBar -> {
|
||||
IProcessBarRenderer<? extends IProcessBar> renderer = processBars.get(processBar);
|
||||
if(processBar.shouldRender()) {
|
||||
renderer.renderProcessBar(matrixStack, guiGraphics);
|
||||
} else {
|
||||
if (processBar.aliveCount() <= 0) {//计数为非正时移除
|
||||
processBars.remove(processBar);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,83 @@
|
|||
package com.r3944realms.leashedplayer.client.renders;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.r3944realms.leashedplayer.client.processBar.IProcessBar;
|
||||
import com.r3944realms.leashedplayer.client.processBar.TestProcessBar;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
|
||||
public interface IFadingProcessBarRenderer<T extends IProcessBar> extends IProcessBarRenderer<T> {
|
||||
/**
|
||||
* @return 当前透明度,0.0(完全透明)到 1.0(完全不透明)
|
||||
*/
|
||||
float getFadeAlpha();
|
||||
void setFadeAlpha(float alpha);
|
||||
/**
|
||||
* @return 是否淡入
|
||||
*/
|
||||
boolean isFadingIn();
|
||||
void setFadingIn(boolean fadingIn);
|
||||
/**
|
||||
* @return 是否淡出
|
||||
*/
|
||||
boolean isFadingOut();
|
||||
void setFadingOut(boolean fadingOut);
|
||||
/**
|
||||
* @return 淡化速度
|
||||
*/
|
||||
float getFadeRate();
|
||||
void setFadeRate(float fadeRate);
|
||||
/**
|
||||
* @return 完全淡入/淡出所需时间(秒)
|
||||
*/
|
||||
float getFadeDuration();
|
||||
void setFadeDuration(float fadeDuration);
|
||||
/**
|
||||
* 更新淡化效果
|
||||
*/
|
||||
default void updateFadeEffect() {
|
||||
float fadeSpeed = getFadeRate() / getFadeDuration();
|
||||
if (isFadingIn()) {
|
||||
fadeInTick(fadeSpeed);
|
||||
|
||||
} else if (isFadingOut()) {
|
||||
fadeOutTick(fadeSpeed);
|
||||
if(getFadeAlpha() <= 0.0F){
|
||||
if (getProcessBar().getCurrentProcess() != 0 || getProcessBar().getCurrentProcess() != getProcessBar().getMaxProcess()) {
|
||||
getProcessBar().retain();
|
||||
}
|
||||
stopRender();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Do Not Override, instead of using <code>renderProcessBar0()</code><br/>
|
||||
* 请勿重载,请重载renderProcessBar0()替代
|
||||
* @deprecated
|
||||
*/
|
||||
@Deprecated
|
||||
@Override
|
||||
default void renderProcessBar(PoseStack poseStack, GuiGraphics guiGraphics) {
|
||||
updateFadeEffect();
|
||||
renderProcessBar0(poseStack, guiGraphics);
|
||||
}
|
||||
void renderProcessBar0(PoseStack poseStack, GuiGraphics guiGraphics);
|
||||
|
||||
default void fadeInTick(float fadeSpeed) {
|
||||
if (getFadeAlpha() >= 1.0f) {
|
||||
setFadingIn(false);
|
||||
return;
|
||||
}
|
||||
setFadeAlpha(Math.min(getFadeAlpha() + fadeSpeed, 1.0f));
|
||||
|
||||
}
|
||||
default void fadeOutTick(float fadeSpeed) {
|
||||
if (getFadeAlpha() >= 1.0f) {
|
||||
setFadingOut(false);
|
||||
return;
|
||||
}
|
||||
setFadeAlpha(Math.max(getFadeAlpha() - fadeSpeed, 0.0f));
|
||||
}
|
||||
|
||||
void setProcessBar(TestProcessBar processBar);
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package com.r3944realms.leashedplayer.client.renders;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.r3944realms.leashedplayer.client.processBar.IProcessBar;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
|
||||
public interface IProcessBarRenderer<T extends IProcessBar> {
|
||||
T getProcessBar();
|
||||
void setProcessBar(T processBar);
|
||||
void renderProcessBar(PoseStack poseStack, GuiGraphics guiGraphics);
|
||||
default void stopRender() {
|
||||
T processBar = getProcessBar();
|
||||
processBar.decreaseAliveCount();
|
||||
processBar.setRenderStatus(false);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,90 @@
|
|||
package com.r3944realms.leashedplayer.client.renders;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.r3944realms.leashedplayer.LeashedPlayer;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
import net.neoforged.fml.common.EventBusSubscriber;
|
||||
import net.neoforged.neoforge.client.event.ClientTickEvent;
|
||||
import net.neoforged.neoforge.client.event.RenderGuiEvent;
|
||||
|
||||
@EventBusSubscriber(modid = LeashedPlayer.MOD_ID, value = Dist.CLIENT)
|
||||
public class ProcessBarRenderer {
|
||||
|
||||
private static boolean isRendering = false;
|
||||
private static final int progressDuration = 100;
|
||||
private static int currentProgress = 0;
|
||||
public static void startRenderingProgressBar(Player player) {
|
||||
isRendering = true;
|
||||
currentProgress = 0;
|
||||
}
|
||||
public static void stopRenderingProgressBar() {
|
||||
isRendering = false;
|
||||
}
|
||||
@SubscribeEvent
|
||||
public static void onClientTick(ClientTickEvent.Pre event) {
|
||||
if (isRendering) {
|
||||
currentProgress++;
|
||||
if (currentProgress >= progressDuration) {
|
||||
stopRenderingProgressBar();
|
||||
}
|
||||
}
|
||||
}
|
||||
@SubscribeEvent
|
||||
public static void onRendererLevel(RenderGuiEvent.Pre event) {
|
||||
PoseStack matrixStack = event.getGuiGraphics().pose();
|
||||
GuiGraphics guiGraphics = event.getGuiGraphics();
|
||||
if(isRendering) {
|
||||
renderProgressBar(matrixStack, guiGraphics);
|
||||
}
|
||||
}
|
||||
public static float getProgress() {
|
||||
return (float) currentProgress / progressDuration;
|
||||
}
|
||||
private static void renderProgressBar(PoseStack matrixStack, GuiGraphics guiGraphics) {
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
int screenWidth = mc.getWindow().getGuiScaledWidth();
|
||||
int screenHeight = mc.getWindow().getGuiScaledHeight();
|
||||
|
||||
// 设置进度条的位置和尺寸
|
||||
int barWidth = screenWidth / 4;
|
||||
int barHeight = 12;
|
||||
int x = (screenWidth - barWidth) / 2;
|
||||
int y = screenHeight - 47;
|
||||
|
||||
// 绘制背景(灰色)
|
||||
guiGraphics.fill(x, y, x + barWidth, y + barHeight, 0xFF555555);
|
||||
|
||||
// 计算当前进度并绘制前景(渐变颜色)
|
||||
float progress = getProgress();
|
||||
int progressWidth = (int) (progress * barWidth);
|
||||
|
||||
// 渐变颜色效果:从红色到绿色
|
||||
int color = lerpColor(progress);
|
||||
guiGraphics.fill(x, y, x + progressWidth, y + barHeight, color);
|
||||
|
||||
// 绘制边框:分别绘制四条边
|
||||
int borderColor = 0xFFFFFFFF; // 白色
|
||||
guiGraphics.fill(x - 1, y - 1, x + barWidth + 1, y, borderColor); // 顶边
|
||||
guiGraphics.fill(x - 1, y + barHeight, x + barWidth + 1, y + barHeight + 1, borderColor); // 底边
|
||||
guiGraphics.fill(x - 1, y, x, y + barHeight, borderColor); // 左边
|
||||
guiGraphics.fill(x + barWidth, y, x + barWidth + 1, y + barHeight, borderColor); // 右边
|
||||
}
|
||||
|
||||
// 渐变颜色计算
|
||||
private static int lerpColor(float progress) {
|
||||
int a = (int) (getAlpha(-65536) * (1 - progress) + getAlpha(-16711936) * progress);
|
||||
int r = (int) (getRed(-65536) * (1 - progress) + getRed(-16711936) * progress);
|
||||
int g = (int) (getGreen(-65536) * (1 - progress) + getGreen(-16711936) * progress);
|
||||
int b = (int) (getBlue(-65536) * (1 - progress) + getBlue(-16711936) * progress);
|
||||
return (a << 24) | (r << 16) | (g << 8) | b;
|
||||
}
|
||||
|
||||
private static int getAlpha(int color) { return (color >> 24) & 0xFF; }
|
||||
private static int getRed(int color) { return (color >> 16) & 0xFF; }
|
||||
private static int getGreen(int color) { return (color >> 8) & 0xFF; }
|
||||
private static int getBlue(int color) { return color & 0xFF; }
|
||||
}
|
||||
|
|
@ -0,0 +1,161 @@
|
|||
package com.r3944realms.leashedplayer.client.renders;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.r3944realms.leashedplayer.client.processBar.IProcessBar;
|
||||
import com.r3944realms.leashedplayer.client.processBar.TestProcessBar;
|
||||
import com.r3944realms.leashedplayer.utils.ColorUtil;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class TestProcessBarRenderer implements IFadingProcessBarRenderer<IProcessBar>{
|
||||
@Nullable
|
||||
private TestProcessBar processBar;
|
||||
private float FadeAlpha;
|
||||
private boolean fadingIn, fadingOut;
|
||||
private float FadeRate;
|
||||
private float FadeDuration;
|
||||
|
||||
public TestProcessBarRenderer(boolean fadingIn, boolean fadingOut, float FadeRate, float FadeDuration){
|
||||
this.fadingIn = fadingIn;
|
||||
this.fadingOut = fadingOut;
|
||||
this.FadeRate = FadeRate;
|
||||
this.FadeDuration = FadeDuration;
|
||||
this.FadeAlpha = 0.0F;
|
||||
}
|
||||
|
||||
public TestProcessBarRenderer(boolean fadingIn, boolean fadingOut, float FadeRate, float FadeDuration, float FadeAlpha){
|
||||
this.fadingIn = fadingIn;
|
||||
this.fadingOut = fadingOut;
|
||||
this.FadeRate = FadeRate;
|
||||
this.FadeDuration = FadeDuration;
|
||||
this.FadeAlpha = FadeAlpha;
|
||||
}
|
||||
|
||||
public TestProcessBarRenderer(TestProcessBar bar, boolean fadingIn, boolean fadingOut, float FadeRate, float FadeDuration) {
|
||||
this(fadingIn, fadingOut, FadeRate, FadeDuration);
|
||||
setProcessBar(bar);
|
||||
}
|
||||
|
||||
public TestProcessBarRenderer(TestProcessBar bar, boolean fadingIn, boolean fadingOut, float FadeRate, float FadeDuration, float FadeAlpha) {
|
||||
this(fadingIn, fadingOut, FadeRate, FadeDuration, FadeAlpha);
|
||||
setProcessBar(bar);
|
||||
}
|
||||
|
||||
public TestProcessBarRenderer() {
|
||||
this(true, false, 0.02f, 10.0f, 0.0f);
|
||||
}
|
||||
|
||||
public TestProcessBarRenderer(TestProcessBar bar) {
|
||||
this(true, false, 0.02f, 10.0f);
|
||||
setProcessBar(bar);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public float getFadeAlpha() {
|
||||
return this.FadeAlpha;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFadeAlpha(float alpha) {
|
||||
this.FadeAlpha = alpha;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFadingIn() {
|
||||
return this.fadingIn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFadingIn(boolean fadingIn) {
|
||||
this.fadingIn = fadingIn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFadingOut() {
|
||||
return this.fadingOut;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFadingOut(boolean fadingOut) {
|
||||
this.fadingOut = fadingOut;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getFadeRate() {
|
||||
return this.FadeRate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFadeRate(float fadeRate) {
|
||||
this.FadeRate = fadeRate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getFadeDuration() {
|
||||
return this.FadeDuration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFadeDuration(float fadeDuration) {
|
||||
this.FadeDuration = fadeDuration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable TestProcessBar getProcessBar() {
|
||||
return this.processBar;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProcessBar(IProcessBar processBar) {
|
||||
if(processBar instanceof TestProcessBar pB){
|
||||
setProcessBar(pB);
|
||||
} else throw new UnsupportedOperationException("Not supported Non-TestProcessBar");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProcessBar(TestProcessBar processBar) {
|
||||
this.processBar = processBar;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void renderProcessBar0(PoseStack poseStack, GuiGraphics guiGraphics) {
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
int screenWidth = mc.getWindow().getGuiScaledWidth();
|
||||
int screenHeight = mc.getWindow().getGuiScaledHeight();
|
||||
|
||||
int elementWidth = 200;
|
||||
int elementHeight = 12;
|
||||
int x = (screenWidth - elementWidth) / 2;
|
||||
int y = screenHeight - elementHeight - 47; // 控制 GUI 元素的位置
|
||||
|
||||
// 计算透明度
|
||||
float progress = 0;
|
||||
if (getProcessBar() != null) {
|
||||
progress = (float) getProcessBar().getCurrentProcess() / getProcessBar().getMaxProcess();
|
||||
}
|
||||
int alpha = (int) (FadeAlpha * 255);
|
||||
int backgroundColor = (alpha << 24) | 0xFF555555; // 背景颜色
|
||||
int foregroundColor = (alpha << 24) | ColorUtil.lerpColor(progress);; // 前景颜色
|
||||
|
||||
// 绘制背景
|
||||
guiGraphics.fill(x, y, x + elementWidth, y + elementHeight, backgroundColor);
|
||||
|
||||
// 绘制前景(例如进度条)
|
||||
|
||||
int progressWidth = (int) (progress * elementWidth);
|
||||
guiGraphics.fill(x, y, x + progressWidth, y + elementHeight, foregroundColor);
|
||||
|
||||
// 绘制边框
|
||||
int borderColor = 0xFFFFFFFF; // 白色边框
|
||||
guiGraphics.fill(x - 1, y - 1, x + elementWidth + 1, y, borderColor); // 顶边
|
||||
guiGraphics.fill(x - 1, y + elementHeight, x + elementWidth + 1, y + elementHeight + 1, borderColor); // 底边
|
||||
guiGraphics.fill(x - 1, y, x, y + elementHeight, borderColor); // 左边
|
||||
guiGraphics.fill(x + elementWidth, y, x + elementWidth + 1, y + elementHeight, borderColor); // 右边
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -132,10 +132,11 @@ public class LeashCommand {
|
|||
CommandSourceStack source = context.getSource();
|
||||
float leashLength = context.getArgument("leashLength", Float.class);
|
||||
try {
|
||||
Collection<ServerPlayer> playerCol = EntityArgument.getPlayers(context, "targetPlayer");
|
||||
Collection<ServerPlayer> playerCol = EntityArgument.getPlayers(context, "targetPlayers");
|
||||
playerCol.forEach(player -> {
|
||||
try {
|
||||
((ILivingEntityExtension)player).setLeashLength(leashLength);
|
||||
source.sendSuccess(() -> Component.translatable(LEASH_LENGTH_SET, player.getDisplayName(), leashLength), true);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,11 @@ public class ModItemRegister {
|
|||
public static final Supplier<Item> LEASH_ROPE_ARROW = ModItemRegister.register("leash_rope_arrow",
|
||||
() -> new LeashRopeArrowItem(new Item.Properties().stacksTo(16))
|
||||
);
|
||||
|
||||
public static final Supplier<Item> FABRIC = ModItemRegister.register("fabric",
|
||||
() -> new TestItem(new Item.Properties().stacksTo(1))
|
||||
);
|
||||
|
||||
public static Supplier<Item> register(String name, Supplier<Item> supplier) {
|
||||
return register(name, supplier, true);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,48 @@
|
|||
package com.r3944realms.leashedplayer.content.items;
|
||||
|
||||
import com.r3944realms.leashedplayer.client.processBar.IProcessBar;
|
||||
import com.r3944realms.leashedplayer.client.processBar.TestProcessBar;
|
||||
import com.r3944realms.leashedplayer.client.renders.AdaptiveGuiRendererHandler;
|
||||
import com.r3944realms.leashedplayer.client.renders.IFadingProcessBarRenderer;
|
||||
import com.r3944realms.leashedplayer.client.renders.IProcessBarRenderer;
|
||||
import com.r3944realms.leashedplayer.client.renders.TestProcessBarRenderer;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResultHolder;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class TestItem extends Item {
|
||||
public TestProcessBar testProcessBar = null;
|
||||
public TestItem(Properties pProperties) {
|
||||
super(pProperties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull InteractionResultHolder<ItemStack> use(@NotNull Level pLevel, @NotNull Player pPlayer, @NotNull InteractionHand pUsedHand) {
|
||||
if(!pLevel.isClientSide()){
|
||||
//some lo
|
||||
}
|
||||
else {
|
||||
if (testProcessBar == null) {
|
||||
testProcessBar = new TestProcessBar();
|
||||
testProcessBar.setRenderStatus(true);
|
||||
TestProcessBarRenderer testProcessBarRenderer = new TestProcessBarRenderer(testProcessBar);
|
||||
AdaptiveGuiRendererHandler.addProcessBar(testProcessBar, testProcessBarRenderer);
|
||||
} else {
|
||||
if(testProcessBar.getCurrentProcess() >= testProcessBar.getMaxProcess()) {
|
||||
testProcessBar.increase();
|
||||
IProcessBarRenderer<? extends IProcessBar> processBarRenderer = AdaptiveGuiRendererHandler.getProcessBarRenderer(testProcessBar);
|
||||
((IFadingProcessBarRenderer<?>)processBarRenderer).setFadingOut(true);
|
||||
testProcessBar = null;
|
||||
} else {
|
||||
testProcessBar.increase();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return super.use(pLevel, pPlayer, pUsedHand);
|
||||
}
|
||||
}
|
||||
|
|
@ -22,6 +22,7 @@ import static com.r3944realms.leashedplayer.content.items.ModCreativeTab.LEASHED
|
|||
public enum ModLangKeyValue {
|
||||
//ITEM
|
||||
ITEM_LEASH_ROPE_ARROW(ModItemRegister.LEASH_ROPE_ARROW, ModPartEnum.ITEM, "Leash Rope Arrow", "拴绳箭", "拴繩箭", true),
|
||||
TEST_FABRIC_ITEM(ModItemRegister.FABRIC, ModPartEnum.ITEM, "Fabric", "Fabric", "Fabric", true),
|
||||
//ITEM_DESC
|
||||
DESC_ITEM_LEASH_ROPE_ARROW(LeashRopeArrowItem.descKey, ModPartEnum.DESCRIPTION, "Arrows with ropes attached?","带有拴绳的箭矢?", "帶有拴繩的箭矢?", false),
|
||||
//ENTITY
|
||||
|
|
|
|||
|
|
@ -1,67 +0,0 @@
|
|||
package com.r3944realms.leashedplayer.mixin.both;
|
||||
|
||||
import com.r3944realms.leashedplayer.modInterface.ILivingEntityExtension;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.syncher.EntityDataAccessor;
|
||||
import net.minecraft.network.syncher.EntityDataSerializers;
|
||||
import net.minecraft.network.syncher.SynchedEntityData;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.level.Level;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(LivingEntity.class)
|
||||
public abstract class MixinLivingEntity extends Entity implements ILivingEntityExtension {
|
||||
@Unique
|
||||
protected int Pl$LeashKeepTick;//保存状态,当超过断裂绳长时若LeashKeepTick大于0,则不断裂
|
||||
|
||||
public MixinLivingEntity(EntityType<?> pEntityType, Level pLevel) {
|
||||
super(pEntityType, pLevel);
|
||||
}
|
||||
@Unique
|
||||
@SuppressWarnings("WrongEntityDataParameterClass")
|
||||
private static final EntityDataAccessor<Float> DATA_ENTITY_LEASH_LENGTH = SynchedEntityData.defineId(LivingEntity.class, EntityDataSerializers.FLOAT);
|
||||
|
||||
@SuppressWarnings("AddedMixinMembersNamePattern")
|
||||
@Override
|
||||
public float getLeashLength() {
|
||||
return this.entityData.get(DATA_ENTITY_LEASH_LENGTH);
|
||||
}
|
||||
@SuppressWarnings("AddedMixinMembersNamePattern")
|
||||
@Override
|
||||
public void setLeashLength(float length) {
|
||||
this.entityData.set(DATA_ENTITY_LEASH_LENGTH, length);
|
||||
}
|
||||
|
||||
@SuppressWarnings("AddedMixinMembersNamePattern")
|
||||
@Override
|
||||
public void setKeepLeashTick(int keepTick) {
|
||||
this.Pl$LeashKeepTick = Math.max(keepTick, 0);
|
||||
}
|
||||
@SuppressWarnings("AddedMixinMembersNamePattern")
|
||||
@Override
|
||||
public int getKeepLeashTick() {
|
||||
return this.Pl$LeashKeepTick;
|
||||
}
|
||||
|
||||
@Inject(method = {"defineSynchedData"}, at = {@At("TAIL")})
|
||||
//定义Client/Server实体同步数据
|
||||
private void defineSyncData(SynchedEntityData.Builder pBuilder, CallbackInfo ci) {
|
||||
pBuilder.define(DATA_ENTITY_LEASH_LENGTH, 5.0F);
|
||||
}
|
||||
@Inject(method = {"readAdditionalSaveData"}, at = {@At("RETURN")})
|
||||
private void readSaveData(CompoundTag compoundTag, CallbackInfo callbackInfo) {
|
||||
if(compoundTag.contains("LeashLength")) {
|
||||
this.setLeashLength(compoundTag.getFloat("LeashLength"));
|
||||
}
|
||||
}
|
||||
@Inject(method = {"addAdditionalSaveData"}, at = {@At("RETURN")})
|
||||
private void addSaveData(CompoundTag compoundTag, CallbackInfo callbackInfo) {
|
||||
compoundTag.putFloat("LeashLength", getLeashLength());
|
||||
}
|
||||
}
|
||||
|
|
@ -28,16 +28,46 @@ import javax.annotation.Nullable;
|
|||
import java.util.function.Consumer;
|
||||
|
||||
@Mixin(Player.class)
|
||||
public abstract class MixinPlayer extends LivingEntity implements PlayerLeashable {
|
||||
public abstract class MixinPlayer extends LivingEntity implements PlayerLeashable, ILivingEntityExtension {
|
||||
|
||||
@Unique
|
||||
protected int Pl$LeashKeepTick;//保存状态,当超过断裂绳长时若LeashKeepTick大于0,则不断裂
|
||||
|
||||
@Unique
|
||||
@Nullable
|
||||
private LeashData Pl$LeashData;//Data
|
||||
|
||||
|
||||
@SuppressWarnings("WrongEntityDataParameterClass")
|
||||
@Unique//客户端与服务器端的实体同步数据
|
||||
private static final EntityDataAccessor<CompoundTag> Pl$LEASH_DATA = SynchedEntityData.defineId(Player.class, EntityDataSerializers.COMPOUND_TAG);
|
||||
|
||||
@Unique
|
||||
@SuppressWarnings("WrongEntityDataParameterClass")
|
||||
private static final EntityDataAccessor<Float> DATA_ENTITY_LEASH_LENGTH = SynchedEntityData.defineId(Player.class, EntityDataSerializers.FLOAT);
|
||||
|
||||
@SuppressWarnings("AddedMixinMembersNamePattern")
|
||||
@Override
|
||||
public float getLeashLength() {
|
||||
return this.entityData.get(DATA_ENTITY_LEASH_LENGTH);
|
||||
}
|
||||
@SuppressWarnings("AddedMixinMembersNamePattern")
|
||||
@Override
|
||||
public void setLeashLength(float length) {
|
||||
this.entityData.set(DATA_ENTITY_LEASH_LENGTH, length);
|
||||
}
|
||||
|
||||
@SuppressWarnings("AddedMixinMembersNamePattern")
|
||||
@Override
|
||||
public void setKeepLeashTick(int keepTick) {
|
||||
this.Pl$LeashKeepTick = Math.max(keepTick, 0);
|
||||
}
|
||||
@SuppressWarnings("AddedMixinMembersNamePattern")
|
||||
@Override
|
||||
public int getKeepLeashTick() {
|
||||
return this.Pl$LeashKeepTick;
|
||||
}
|
||||
|
||||
|
||||
protected MixinPlayer(EntityType<? extends LivingEntity> pEntityType, Level pLevel) {
|
||||
super(pEntityType, pLevel);
|
||||
}
|
||||
|
|
@ -256,6 +286,7 @@ public abstract class MixinPlayer extends LivingEntity implements PlayerLeashabl
|
|||
CompoundTag leashCompoundTag = new CompoundTag();
|
||||
this.writeLeashData(leashCompoundTag, null);
|
||||
pBuilder.define(Pl$LEASH_DATA, leashCompoundTag);
|
||||
pBuilder.define(DATA_ENTITY_LEASH_LENGTH, 5.0F);
|
||||
}
|
||||
@Inject(
|
||||
method = {"addAdditionalSaveData"}, at = {@At("RETURN")}
|
||||
|
|
@ -265,6 +296,7 @@ public abstract class MixinPlayer extends LivingEntity implements PlayerLeashabl
|
|||
writeLeashData(pLeashTag, Pl$LeashData);
|
||||
pCompound.put("Pl$LeashData", pLeashTag);
|
||||
this.entityData.set(Pl$LEASH_DATA, pLeashTag);
|
||||
pCompound.putFloat("LeashLength", getLeashLength());
|
||||
}
|
||||
@Inject(
|
||||
method = {"readAdditionalSaveData"}, at = {@At("RETURN")}
|
||||
|
|
@ -275,6 +307,9 @@ public abstract class MixinPlayer extends LivingEntity implements PlayerLeashabl
|
|||
this.entityData.set(Pl$LEASH_DATA, pl$LeashData);
|
||||
Pl$LeashData = readLeashData(pl$LeashData);
|
||||
}
|
||||
if(pCompound.contains("LeashLength")) {
|
||||
this.setLeashLength(pCompound.getFloat("LeashLength"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,18 @@
|
|||
package com.r3944realms.leashedplayer.utils;
|
||||
|
||||
public class ColorUtil {
|
||||
// 渐变颜色计算
|
||||
public static int lerpColor(float progress) {
|
||||
int a = (int) (getAlpha(-65536) * (1 - progress) + getAlpha(-16711936) * progress);
|
||||
int r = (int) (getRed(-65536) * (1 - progress) + getRed(-16711936) * progress);
|
||||
int g = (int) (getGreen(-65536) * (1 - progress) + getGreen(-16711936) * progress);
|
||||
int b = (int) (getBlue(-65536) * (1 - progress) + getBlue(-16711936) * progress);
|
||||
return (a << 24) | (r << 16) | (g << 8) | b;
|
||||
}
|
||||
|
||||
private static int getAlpha(int color) { return (color >> 24) & 0xFF; }
|
||||
private static int getRed(int color) { return (color >> 16) & 0xFF; }
|
||||
private static int getGreen(int color) { return (color >> 8) & 0xFF; }
|
||||
private static int getBlue(int color) { return color & 0xFF; }
|
||||
}
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
BIN
src/main/resources/assets/leashedplayer/textures/item/fabric.png
Normal file
BIN
src/main/resources/assets/leashedplayer/textures/item/fabric.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.7 KiB |
|
|
@ -2,7 +2,6 @@
|
|||
"package": "com.r3944realms.leashedplayer.mixin",
|
||||
"mixins": [
|
||||
"both.MixinEntity",
|
||||
"both.MixinLivingEntity",
|
||||
"both.MixinPlayer",
|
||||
"item.MixinLeadItem",
|
||||
"server.MixinServerGamePacketListenerImpl"
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user