Compare commits
No commits in common. "MultiLoader_1_21_1" and "MultiLoader_1_20_1" have entirely different histories.
MultiLoade
...
MultiLoade
|
|
@ -1,4 +1,4 @@
|
|||
plugins {
|
||||
id 'fabric-loom' version '1.9-SNAPSHOT' apply false
|
||||
id 'net.neoforged.moddev' version '2.0.141' apply false
|
||||
id 'fabric-loom' version '1.9-SNAPSHOT' apply(false)
|
||||
id 'net.neoforged.moddev.legacyforge' version '2.0.103' apply(false)
|
||||
}
|
||||
|
|
@ -48,9 +48,6 @@ repositories {
|
|||
name = 'BlameJared'
|
||||
url = 'https://maven.blamejared.com'
|
||||
}
|
||||
repositories {
|
||||
maven { url 'https://maven.covers1624.net/' }
|
||||
}
|
||||
}
|
||||
|
||||
// Declare capabilities on the outgoing configurations.
|
||||
|
|
@ -104,17 +101,24 @@ processResources {
|
|||
'mod_id' : mod_id,
|
||||
'license' : license,
|
||||
'description' : project.description,
|
||||
'neoforge_version' : neoforge_version,
|
||||
'neoforge_loader_version_range': neoforge_loader_version_range,
|
||||
"neoforge_version": neoforge_version,
|
||||
"neoforge_loader_version_range": neoforge_loader_version_range,
|
||||
"forge_version" : forge_version,
|
||||
"forge_loader_version_range" : forge_loader_version_range,
|
||||
'credits' : credits,
|
||||
'java_version' : java_version
|
||||
]
|
||||
|
||||
filesMatching(['pack.mcmeta', 'fabric.mod.json', 'META-INF/mods.toml', 'META-INF/neoforge.mods.toml', '*.mixins.json']) {
|
||||
var jsonExpandProps = expandProps.collectEntries {
|
||||
key, value -> [(key): value instanceof String ? value.replace("\n", "\\\\n") : value]
|
||||
}
|
||||
|
||||
filesMatching(['META-INF/mods.toml']) {
|
||||
expand expandProps
|
||||
}
|
||||
|
||||
filesMatching(['pack.mcmeta', 'fabric.mod.json', '*.mixins.json']) {
|
||||
expand jsonExpandProps
|
||||
}
|
||||
|
||||
inputs.properties(expandProps)
|
||||
}
|
||||
|
||||
|
|
@ -126,18 +130,19 @@ publishing {
|
|||
pom {
|
||||
name = 'Lib39'
|
||||
description = 'Lib39 is a general-purpose dependency library for Minecraft mods.'
|
||||
url = 'https://gitea.bot.leisuretimedock.top/R3944Realms/Lib39'
|
||||
url = 'https://github.com/3944Realms/lib39'
|
||||
|
||||
properties = [
|
||||
'minecraft.version': project.minecraft_version,
|
||||
'mod.version': project.version,
|
||||
'java.version': project.java_version
|
||||
'forge.version': project.forge_version,
|
||||
'java.version': '17'
|
||||
]
|
||||
|
||||
licenses {
|
||||
license {
|
||||
name = 'MIT'
|
||||
url = 'https://gitea.bot.leisuretimedock.top/R3944Realms/Lib39/raw/branch/MultiLoader_1_21_1/LICENSE'
|
||||
url = 'https://raw.githubusercontent.com/3944Realms/lib39/refs/heads/main/LICENSE'
|
||||
distribution = 'repo'
|
||||
}
|
||||
}
|
||||
|
|
@ -151,15 +156,15 @@ publishing {
|
|||
}
|
||||
|
||||
scm {
|
||||
connection = 'scm:git:git@bot.leisuretimedock.top:R3944Realms/Lib39.git'
|
||||
developerConnection = 'scm:git:ssh://git@bot.leisuretimedock.top:R3944Realms/Lib39.git'
|
||||
url = 'https://gitea.bot.leisuretimedock.top/R3944Realms/Lib39'
|
||||
connection = 'scm:git:https://github.com/3944Realms/lib39.git'
|
||||
developerConnection = 'scm:git:ssh://git@github.com:3944Realms/lib39.git'
|
||||
url = 'https://github.com/3944Realms/lib39'
|
||||
tag = 'main'
|
||||
}
|
||||
|
||||
issueManagement {
|
||||
system = 'Gitea'
|
||||
url = 'https://gitea.bot.leisuretimedock.top/R3944Realms/Lib39/issues'
|
||||
system = 'GitHub'
|
||||
url = 'https://github.com/3944Realms/lib39/issues'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,11 +36,10 @@ tasks.named('javadoc', Javadoc).configure {
|
|||
source(configurations.commonJava)
|
||||
options.encoding = 'UTF-8'
|
||||
options.charSet = 'UTF-8'
|
||||
options.links("https://docs.oracle.com/en/java/javase/21/docs/api/")
|
||||
options.links("https://docs.oracle.com/en/java/javase/17/docs/api/")
|
||||
options.memberLevel = JavadocMemberLevel.PUBLIC
|
||||
options.addBooleanOption('Xdoclint:none', true)
|
||||
options.addStringOption('doctitle', "${mod_id} ${minecraft_version} ${version} Javadoc")
|
||||
|
||||
}
|
||||
|
||||
tasks.named('sourcesJar', Jar) {
|
||||
|
|
|
|||
|
|
@ -1,14 +1,12 @@
|
|||
plugins {
|
||||
id 'multiloader-common'
|
||||
id 'net.neoforged.moddev'
|
||||
id 'net.neoforged.moddev.legacyforge'
|
||||
}
|
||||
|
||||
neoForge {
|
||||
neoFormVersion = neo_form_version
|
||||
// Automatically enable AccessTransformers if the file exists
|
||||
def at = file('src/main/resources/META-INF/accesstransformer.cfg')
|
||||
if (at.exists()) {
|
||||
accessTransformers.from(at.absolutePath)
|
||||
legacyForge {
|
||||
mcpVersion = minecraft_version
|
||||
if (file("src/main/resources/META-INF/accesstransformer.cfg").exists()) {
|
||||
accessTransformers = ["src/main/resources/META-INF/accesstransformer.cfg"]
|
||||
}
|
||||
parchment {
|
||||
minecraftVersion = parchment_minecraft
|
||||
|
|
@ -16,16 +14,13 @@ neoForge {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
dependencies {
|
||||
compileOnly group: 'org.spongepowered', name: 'mixin', version: '0.8.5'
|
||||
|
||||
implementation(group: 'tschipp.carryon', name: 'carryon-common-1.21.1', version: '2.2.4') {
|
||||
compileOnly(group: 'org.spongepowered', name: 'mixin', version: '0.8.5')
|
||||
implementation(group: 'tschipp.carryon', name: 'carryon-common-1.20.1', version: '2.1.2') {
|
||||
transitive = false
|
||||
}
|
||||
// fabric and neoforge both bundle mixinextras, so it is safe to use it in common
|
||||
implementation group: 'io.github.llamalad7', name: 'mixinextras-common', version: '0.4.1'
|
||||
annotationProcessor group: 'io.github.llamalad7', name: 'mixinextras-common', version: '0.4.1'
|
||||
implementation(annotationProcessor("io.github.llamalad7:mixinextras-common:0.2.0"))
|
||||
implementation(group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.1')
|
||||
}
|
||||
configurations {
|
||||
commonJava {
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ public class Lib39 {
|
|||
*/
|
||||
@Contract("_ -> new")
|
||||
public static @NotNull ResourceLocation rl(String path) {
|
||||
return ResourceLocation.fromNamespaceAndPath(Lib39.MOD_ID, path);
|
||||
return new ResourceLocation(Lib39.MOD_ID, path);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -61,7 +61,7 @@ public class Lib39 {
|
|||
*/
|
||||
@Contract("_, _ -> new")
|
||||
public static @NotNull ResourceLocation rl(String modId, String path) {
|
||||
return ResourceLocation.fromNamespaceAndPath(modId, path);
|
||||
return new ResourceLocation(modId, path);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -72,7 +72,7 @@ public class Lib39 {
|
|||
*/
|
||||
@Contract("_ -> new")
|
||||
public static @NotNull ResourceLocation mrl(String path) {
|
||||
return ResourceLocation.withDefaultNamespace(path);
|
||||
return new ResourceLocation(path);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,13 +1,16 @@
|
|||
package top.r3944realms.lib39.base.datagen.provider;
|
||||
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.data.PackOutput;
|
||||
import net.minecraft.data.recipes.*;
|
||||
import net.minecraft.data.recipes.FinishedRecipe;
|
||||
import net.minecraft.data.recipes.RecipeCategory;
|
||||
import net.minecraft.data.recipes.RecipeProvider;
|
||||
import net.minecraft.data.recipes.ShapelessRecipeBuilder;
|
||||
import net.minecraft.tags.ItemTags;
|
||||
import net.minecraft.world.item.Items;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import top.r3944realms.lib39.core.register.Lib39Items;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* The type Lib 39 recipe provider.
|
||||
|
|
@ -16,19 +19,18 @@ public class Lib39RecipeProvider extends RecipeProvider {
|
|||
/**
|
||||
* Instantiates a new Lib 39 recipe provider.
|
||||
*
|
||||
* @param output the output
|
||||
* @param registries the registries
|
||||
* @param output the output
|
||||
*/
|
||||
public Lib39RecipeProvider(PackOutput output, CompletableFuture<HolderLookup.Provider> registries) {
|
||||
super(output, registries);
|
||||
public Lib39RecipeProvider(PackOutput output) {
|
||||
super(output);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildRecipes(RecipeOutput recipeOutput) {
|
||||
public void buildRecipes(@NotNull Consumer<FinishedRecipe> consumer) {
|
||||
ShapelessRecipeBuilder.shapeless(RecipeCategory.MISC, Lib39Items.DOLL.get())
|
||||
.requires(ItemTags.WOOL)
|
||||
.requires(Items.ARMOR_STAND)
|
||||
.unlockedBy("has_armor_stand",has(Items.ARMOR_STAND))
|
||||
.save(recipeOutput);
|
||||
.save(consumer);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,14 +17,18 @@ import top.r3944realms.lib39.util.MathUtil;
|
|||
import top.r3944realms.lib39.util.lang.FourConsumer;
|
||||
import top.r3944realms.lib39.util.lang.Pair;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
|
||||
/**
|
||||
* The type Wheel widget.
|
||||
*
|
||||
* @author QiuShui1012
|
||||
*/
|
||||
@MethodsReturnNonnullByDefault
|
||||
@ParametersAreNonnullByDefault
|
||||
public class WheelWidget extends AbstractWidget {
|
||||
/**
|
||||
* The constant IGNORE_CURSOR_MOVE_LENGTH.
|
||||
|
|
@ -74,7 +78,6 @@ public class WheelWidget extends AbstractWidget {
|
|||
private Vector2f selectionEffectPos;
|
||||
private boolean animationStarted = false;
|
||||
|
||||
|
||||
/**
|
||||
* Sets closing animation started.
|
||||
*
|
||||
|
|
@ -381,15 +384,16 @@ public class WheelWidget extends AbstractWidget {
|
|||
return this.sections.size();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean mouseScrolled(double mouseX, double mouseY, double scrollX, double scrollY) {
|
||||
if (scrollY > 0) {
|
||||
public boolean mouseScrolled(double mouseX, double mouseY, double delta) {
|
||||
if (delta > 0) {
|
||||
if (this.currentSectionIndex == this.getSectionSize() - 1) {
|
||||
this.currentSectionIndex = 0;
|
||||
} else {
|
||||
this.currentSectionIndex++;
|
||||
}
|
||||
} else if (scrollY < 0) {
|
||||
} else if (delta < 0) {
|
||||
if (this.currentSectionIndex == 0) {
|
||||
this.currentSectionIndex = this.getSectionSize() - 1;
|
||||
} else {
|
||||
|
|
@ -447,8 +451,13 @@ public class WheelWidget extends AbstractWidget {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void renderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) {
|
||||
checkMousePos(mouseX, mouseY);
|
||||
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) {
|
||||
this.checkMousePos(mouseX, mouseY);
|
||||
this.renderWidget(guiGraphics, mouseX, mouseY, partialTick);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderWidget(GuiGraphics guiGraphics, int i, int i1, float v) {
|
||||
RenderSystem.enableDepthTest();
|
||||
RenderSystem.enableBlend();
|
||||
this.renderClosingAnimation(guiGraphics);
|
||||
|
|
@ -587,8 +596,8 @@ public class WheelWidget extends AbstractWidget {
|
|||
PoseStack poseStack = guiGraphics.pose();
|
||||
poseStack.pushPose();
|
||||
|
||||
setupRingShader(centerX, centerY, innerRadius, outerRadius);
|
||||
Tesselator tesselator = Tesselator.getInstance();
|
||||
BufferBuilder buffer = tesselator.getBuilder();
|
||||
|
||||
// 计算足够大的绘制区域来覆盖整个环形(基于外半径)
|
||||
float margin = outerRadius + 100f; // 使用半径计算边距
|
||||
|
|
@ -597,16 +606,17 @@ public class WheelWidget extends AbstractWidget {
|
|||
float x2 = centerX + margin;
|
||||
float y2 = centerY + margin;
|
||||
|
||||
BufferBuilder buffer = tesselator.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);
|
||||
buffer.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);
|
||||
|
||||
Matrix4f matrix = poseStack.last().pose();
|
||||
buffer.addVertex(matrix, x1, y1, -300).setColor(color);
|
||||
buffer.addVertex(matrix, x1, y2, -300).setColor(color);
|
||||
buffer.addVertex(matrix, x2, y2, -300).setColor(color);
|
||||
buffer.addVertex(matrix, x2, y1, -300).setColor(color);
|
||||
buffer.vertex(matrix, x1, y1, -300).color(color).endVertex();
|
||||
buffer.vertex(matrix, x1, y2, -300).color(color).endVertex();
|
||||
buffer.vertex(matrix, x2, y2, -300).color(color).endVertex();
|
||||
buffer.vertex(matrix, x2, y1, -300).color(color).endVertex();
|
||||
|
||||
BufferUploader.drawWithShader(buffer.build());
|
||||
RenderSystem.setShader(() -> null);
|
||||
setupRingShader(centerX, centerY, innerRadius, outerRadius);
|
||||
|
||||
BufferUploader.drawWithShader(buffer.end());
|
||||
poseStack.popPose();
|
||||
}
|
||||
|
||||
|
|
@ -693,16 +703,17 @@ public class WheelWidget extends AbstractWidget {
|
|||
PoseStack poseStack = guiGraphics.pose();
|
||||
Matrix4f matrix4f = poseStack.last().pose();
|
||||
Tesselator tesselator = Tesselator.getInstance();
|
||||
BufferBuilder buffer = tesselator.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);
|
||||
BufferBuilder buffer = tesselator.getBuilder();
|
||||
buffer.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);
|
||||
|
||||
float x1 = centerX - radius - 5;
|
||||
float y1 = centerY - radius - 5;
|
||||
float x2 = centerX + radius + 5;
|
||||
float y2 = centerY + radius + 5;
|
||||
buffer.addVertex(matrix4f, x1, y1, -200).setColor(color);
|
||||
buffer.addVertex(matrix4f, x1, y2, -200).setColor(color);
|
||||
buffer.addVertex(matrix4f, x2, y2, -200).setColor(color);
|
||||
buffer.addVertex(matrix4f, x2, y1, -200).setColor(color);
|
||||
buffer.vertex(matrix4f, x1, y1, -200).color(color).endVertex();
|
||||
buffer.vertex(matrix4f, x1, y2, -200).color(color).endVertex();
|
||||
buffer.vertex(matrix4f, x2, y2, -200).color(color).endVertex();
|
||||
buffer.vertex(matrix4f, x2, y1, -200).color(color).endVertex();
|
||||
|
||||
Window window = Minecraft.getInstance().getWindow();
|
||||
float guiScale = (float) window.getGuiScale();
|
||||
|
|
@ -721,8 +732,11 @@ public class WheelWidget extends AbstractWidget {
|
|||
Lib39Shaders.getSelectionShader()
|
||||
.safeGetUniform("Radius")
|
||||
.set(radius * guiScale);
|
||||
Lib39Shaders.getSelectionShader()
|
||||
.safeGetUniform("AntiAliasingRadius")
|
||||
.set(guiScale); // 根据需要调整
|
||||
RenderSystem.setShaderColor(1, 1, 1, 1);
|
||||
BufferUploader.drawWithShader(Objects.requireNonNull(buffer.build()));
|
||||
BufferUploader.drawWithShader(Objects.requireNonNull(buffer.end()));
|
||||
RenderSystem.enableDepthTest();
|
||||
}
|
||||
|
||||
|
|
@ -742,15 +756,8 @@ public class WheelWidget extends AbstractWidget {
|
|||
protected void updateWidgetNarration(NarrationElementOutput narrationElementOutput) {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The type Wheel section.
|
||||
* @param center 中心
|
||||
* @param angle 角度
|
||||
* @param angleStart 开始角度
|
||||
* @param angleEnd 结束角度
|
||||
* @param subTitle 副标题
|
||||
* @param renderer 渲染操作
|
||||
*/
|
||||
public record WheelSection(
|
||||
Vector2f center,
|
||||
|
|
|
|||
|
|
@ -5,10 +5,10 @@ import com.mojang.blaze3d.vertex.VertexConsumer;
|
|||
import net.minecraft.client.model.Model;
|
||||
import net.minecraft.client.model.geom.ModelLayerLocation;
|
||||
import net.minecraft.client.model.geom.ModelPart;
|
||||
import net.minecraft.client.model.geom.PartPose;
|
||||
import net.minecraft.client.model.geom.builders.*;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import top.r3944realms.lib39.Lib39;
|
||||
|
||||
/**
|
||||
|
|
@ -31,57 +31,13 @@ public class DollModel extends Model {
|
|||
private final ModelPart rightArmSlim;
|
||||
private final ModelPart leftArmSlim;
|
||||
private final ModelPart leftLeg;
|
||||
@Nullable
|
||||
private IDollPose currentPose;
|
||||
|
||||
/**
|
||||
* Gets current pose.
|
||||
*
|
||||
* @return the current pose
|
||||
*/
|
||||
@Nullable
|
||||
public IDollPose getCurrentPose() {
|
||||
return currentPose;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets doll pose.
|
||||
*
|
||||
* @param dollPose the doll pose
|
||||
*/
|
||||
public void setDollPose(@NotNull IDollPose dollPose) {
|
||||
this.currentPose = dollPose;
|
||||
this.head.loadPose(dollPose.getHeadPose());
|
||||
this.body.loadPose(dollPose.getBodyPose());
|
||||
this.rightArm.loadPose(dollPose.getRightArmPose());
|
||||
this.leftArm.loadPose(dollPose.getLeftArmPose());
|
||||
this.rightArmSlim.loadPose(dollPose.getRightArmPose());
|
||||
this.leftArmSlim.loadPose(dollPose.getLeftArmPose());
|
||||
this.rightLeg.loadPose(dollPose.getRightLegPose());
|
||||
this.leftLeg.loadPose(dollPose.getLeftLegPose());
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset pose.
|
||||
*/
|
||||
public void resetPose() {
|
||||
this.currentPose = DollPoses.DEFAULT;
|
||||
this.head.resetPose();
|
||||
this.body.resetPose();
|
||||
this.rightArm.resetPose();
|
||||
this.leftArm.resetPose();
|
||||
this.rightArmSlim.resetPose();
|
||||
this.leftArmSlim.resetPose();
|
||||
this.rightLeg.resetPose();
|
||||
this.leftLeg.resetPose();
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new Doll model.
|
||||
*
|
||||
* @param root the root
|
||||
*/
|
||||
public DollModel(@NotNull ModelPart root) {
|
||||
public DollModel(ModelPart root) {
|
||||
super(RenderType::entityTranslucent);
|
||||
this.head = root.getChild("head");
|
||||
this.body = root.getChild("body");
|
||||
|
|
@ -98,118 +54,38 @@ public class DollModel extends Model {
|
|||
*
|
||||
* @return the layer definition
|
||||
*/
|
||||
public static @NotNull LayerDefinition createBodyLayer() {
|
||||
return createBodyLayer(DollPoses.DEFAULT);
|
||||
}
|
||||
|
||||
private static @NotNull LayerDefinition createBodyLayer(@NotNull IDollPose dollPoses) {
|
||||
public static LayerDefinition createBodyLayer() {
|
||||
MeshDefinition meshdefinition = new MeshDefinition();
|
||||
PartDefinition partdefinition = meshdefinition.getRoot();
|
||||
partdefinition.addOrReplaceChild(
|
||||
"head",
|
||||
CubeListBuilder.create()
|
||||
.texOffs(0, 0)
|
||||
.addBox(-4.0F, -8.0F, -4.0F, 8.0F, 8.0F, 8.0F, new CubeDeformation(0.0F))
|
||||
.texOffs(32, 0)
|
||||
.addBox(
|
||||
-4.0F, -8.0F, -4.0F, 8.0F, 8.0F, 8.0F,
|
||||
new CubeDeformation(0.5F)
|
||||
), dollPoses.getHeadPose()
|
||||
);
|
||||
partdefinition.addOrReplaceChild(
|
||||
"body",
|
||||
CubeListBuilder.create()
|
||||
.texOffs(16, 16)
|
||||
.addBox(-4.0F, 0.0F, -2.0F, 8.0F, 12.0F, 4.0F, new CubeDeformation(0.0F))
|
||||
.texOffs(16, 32)
|
||||
.addBox(
|
||||
-4.0F, 0.0F, -2.0F, 8.0F, 12.0F, 4.0F,
|
||||
new CubeDeformation(0.25F)
|
||||
), dollPoses.getBodyPose()
|
||||
);
|
||||
partdefinition.addOrReplaceChild(
|
||||
"right_arm",
|
||||
CubeListBuilder.create()
|
||||
.texOffs(40, 16)
|
||||
.addBox(-3.0F, -2.0F, -2.0F, 4.0F, 12.0F, 4.0F, new CubeDeformation(0.0F))
|
||||
.texOffs(40, 32)
|
||||
.addBox(
|
||||
-3.0F, -2.0F, -2.0F, 4.0F, 12.0F, 4.0F,
|
||||
new CubeDeformation(0.25F)
|
||||
), dollPoses.getRightArmPose()
|
||||
);
|
||||
partdefinition.addOrReplaceChild(
|
||||
"right_arm_slim",
|
||||
CubeListBuilder.create()
|
||||
.texOffs(40, 16)
|
||||
.addBox(-2.0F, -2.0F, -2.0F, 3.0F, 12.0F, 4.0F, new CubeDeformation(0.0F))
|
||||
.texOffs(40, 32)
|
||||
.addBox(-2.0F, -2.0F, -2.0F, 3.0F, 12.0F, 4.0F,
|
||||
new CubeDeformation(0.25F)
|
||||
), dollPoses.getRightArmPose()
|
||||
);
|
||||
partdefinition.addOrReplaceChild(
|
||||
"left_arm_slim",
|
||||
CubeListBuilder.create()
|
||||
.texOffs(32, 48)
|
||||
.addBox(-1.0F, -2.0F, -2.0F, 3.0F, 12.0F, 4.0F, new CubeDeformation(0.0F))
|
||||
.texOffs(48, 48)
|
||||
.addBox(
|
||||
-1.0F, -2.0F, -2.0F, 3.0F, 12.0F, 4.0F,
|
||||
new CubeDeformation(0.25F)
|
||||
), dollPoses.getLeftArmPose()
|
||||
);
|
||||
partdefinition.addOrReplaceChild(
|
||||
"left_arm",
|
||||
CubeListBuilder.create()
|
||||
.texOffs(32, 48)
|
||||
.addBox(-1.0F, -2.0F, -2.0F, 4.0F, 12.0F, 4.0F, new CubeDeformation(0.0F))
|
||||
.texOffs(48, 48)
|
||||
.addBox(
|
||||
-1.0F, -2.0F, -2.0F, 4.0F, 12.0F, 4.0F,
|
||||
new CubeDeformation(0.25F)
|
||||
), dollPoses.getLeftArmPose()
|
||||
);
|
||||
partdefinition.addOrReplaceChild(
|
||||
"right_leg",
|
||||
CubeListBuilder.create()
|
||||
.texOffs(0, 16)
|
||||
.addBox(-2.0F, 0.0F, -2.0F, 4.0F, 12.0F, 4.0F, new CubeDeformation(0.0F))
|
||||
.texOffs(0, 32)
|
||||
.addBox(
|
||||
-2.0F, 0.0F, -2.0F, 4.0F, 12.0F, 4.0F, new CubeDeformation(0.25F)
|
||||
), dollPoses.getRightLegPose()
|
||||
);
|
||||
partdefinition.addOrReplaceChild(
|
||||
"left_leg",
|
||||
CubeListBuilder.create()
|
||||
.texOffs(16, 48)
|
||||
.addBox(-2.0F, 0.0F, -2.0F, 4.0F, 12.0F, 4.0F, new CubeDeformation(0.0F))
|
||||
.texOffs(0, 48)
|
||||
.addBox(
|
||||
-2.0F, 0.0F, -2.0F, 4.0F, 12.0F, 4.0F,
|
||||
new CubeDeformation(0.25F)
|
||||
), dollPoses.getLeftLegPose()
|
||||
);
|
||||
partdefinition.addOrReplaceChild("head", CubeListBuilder.create().texOffs(0, 0).addBox(-4.0F, -8.0F, -4.0F, 8.0F, 8.0F, 8.0F, new CubeDeformation(0.0F)).texOffs(32, 0).addBox(-4.0F, -8.0F, -4.0F, 8.0F, 8.0F, 8.0F, new CubeDeformation(0.5F)), PartPose.offset(0.0F, 9.0F, 0.0F));
|
||||
partdefinition.addOrReplaceChild("body", CubeListBuilder.create().texOffs(16, 16).addBox(-4.0F, 0.0F, -2.0F, 8.0F, 12.0F, 4.0F, new CubeDeformation(0.0F)).texOffs(16, 32).addBox(-4.0F, 0.0F, -2.0F, 8.0F, 12.0F, 4.0F, new CubeDeformation(0.25F)), PartPose.offset(0.0F, 9.0F, 0.0F));
|
||||
partdefinition.addOrReplaceChild("right_arm", CubeListBuilder.create().texOffs(40, 16).addBox(-3.0F, -2.0F, -2.0F, 4.0F, 12.0F, 4.0F, new CubeDeformation(0.0F)).texOffs(40, 32).addBox(-3.0F, -2.0F, -2.0F, 4.0F, 12.0F, 4.0F, new CubeDeformation(0.25F)), PartPose.offsetAndRotation(-5.0F, 11.0F, 0.0F, 0.0F, 0.0F, 0.3927F));
|
||||
partdefinition.addOrReplaceChild("right_arm_slim", CubeListBuilder.create().texOffs(40, 16).addBox(-2.0F, -2.0F, -2.0F, 3.0F, 12.0F, 4.0F, new CubeDeformation(0.0F)).texOffs(40, 32).addBox(-2.0F, -2.0F, -2.0F, 3.0F, 12.0F, 4.0F, new CubeDeformation(0.25F)), PartPose.offsetAndRotation(-5.0F, 11.0F, 0.0F, 0.0F, 0.0F, 0.3927F));
|
||||
partdefinition.addOrReplaceChild("left_arm_slim", CubeListBuilder.create().texOffs(32, 48).addBox(-1.0F, -2.0F, -2.0F, 3.0F, 12.0F, 4.0F, new CubeDeformation(0.0F)).texOffs(48, 48).addBox(-1.0F, -2.0F, -2.0F, 3.0F, 12.0F, 4.0F, new CubeDeformation(0.25F)), PartPose.offsetAndRotation(5.0F, 11.0F, 0.0F, 0.0F, 0.0F, -0.3927F));
|
||||
partdefinition.addOrReplaceChild("left_arm", CubeListBuilder.create().texOffs(32, 48).addBox(-1.0F, -2.0F, -2.0F, 4.0F, 12.0F, 4.0F, new CubeDeformation(0.0F)).texOffs(48, 48).addBox(-1.0F, -2.0F, -2.0F, 4.0F, 12.0F, 4.0F, new CubeDeformation(0.25F)), PartPose.offsetAndRotation(5.0F, 11.0F, 0.0F, 0.0F, 0.0F, -0.3927F));
|
||||
partdefinition.addOrReplaceChild("right_leg", CubeListBuilder.create().texOffs(0, 16).addBox(-2.0F, 0.0F, -2.0F, 4.0F, 12.0F, 4.0F, new CubeDeformation(0.0F)).texOffs(0, 32).addBox(-2.0F, 0.0F, -2.0F, 4.0F, 12.0F, 4.0F, new CubeDeformation(0.25F)), PartPose.offsetAndRotation(-2.0F, 19.0F, -2.0F, -1.5708F, 0.3927F, 0.0F));
|
||||
partdefinition.addOrReplaceChild("left_leg", CubeListBuilder.create().texOffs(16, 48).addBox(-2.0F, 0.0F, -2.0F, 4.0F, 12.0F, 4.0F, new CubeDeformation(0.0F)).texOffs(0, 48).addBox(-2.0F, 0.0F, -2.0F, 4.0F, 12.0F, 4.0F, new CubeDeformation(0.25F)), PartPose.offsetAndRotation(2.0F, 19.0F, -2.0F, -1.5708F, -0.3927F, 0.0F));
|
||||
return LayerDefinition.create(meshdefinition, 64, 64);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void renderToBuffer(@NotNull PoseStack poseStack, VertexConsumer vertexConsumer, int packedLight, int packedOverlay, int color) {
|
||||
public void renderToBuffer(PoseStack poseStack, @NotNull VertexConsumer vertexConsumer, int packedLight, int packedOverlay, float red, float green, float blue, float alpha) {
|
||||
poseStack.pushPose();
|
||||
poseStack.scale(0.5F, 0.5F, 0.5F);
|
||||
poseStack.translate(0.0, 1.5010000467300415, 0.0);
|
||||
this.head.render(poseStack, vertexConsumer, packedLight, packedOverlay, color);
|
||||
this.body.render(poseStack, vertexConsumer, packedLight, packedOverlay, color);
|
||||
this.head.render(poseStack, vertexConsumer, packedLight, packedOverlay, red, green, blue, alpha);
|
||||
this.body.render(poseStack, vertexConsumer, packedLight, packedOverlay, red, green, blue, alpha);
|
||||
if (this.slim) {
|
||||
this.rightArmSlim.render(poseStack, vertexConsumer, packedLight, packedOverlay, color);
|
||||
this.leftArmSlim.render(poseStack, vertexConsumer, packedLight, packedOverlay, color);
|
||||
this.rightArmSlim.render(poseStack, vertexConsumer, packedLight, packedOverlay, red, green, blue, alpha);
|
||||
this.leftArmSlim.render(poseStack, vertexConsumer, packedLight, packedOverlay, red, green, blue, alpha);
|
||||
} else {
|
||||
this.rightArm.render(poseStack, vertexConsumer, packedLight, packedOverlay, color);
|
||||
this.leftArm.render(poseStack, vertexConsumer, packedLight, packedOverlay, color);
|
||||
this.rightArm.render(poseStack, vertexConsumer, packedLight, packedOverlay, red, green, blue, alpha);
|
||||
this.leftArm.render(poseStack, vertexConsumer, packedLight, packedOverlay, red, green, blue, alpha);
|
||||
}
|
||||
this.rightLeg.render(poseStack, vertexConsumer, packedLight, packedOverlay, color);
|
||||
this.leftLeg.render(poseStack, vertexConsumer, packedLight, packedOverlay, color);
|
||||
|
||||
this.rightLeg.render(poseStack, vertexConsumer, packedLight, packedOverlay, red, green, blue, alpha);
|
||||
this.leftLeg.render(poseStack, vertexConsumer, packedLight, packedOverlay, red, green, blue, alpha);
|
||||
poseStack.popPose();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,93 +0,0 @@
|
|||
package top.r3944realms.lib39.client.model;
|
||||
|
||||
import net.minecraft.client.model.geom.PartPose;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import top.r3944realms.lib39.Lib39;
|
||||
|
||||
/**
|
||||
* The enum Doll poses.
|
||||
*/
|
||||
public enum DollPoses implements IDollPose{
|
||||
/**
|
||||
* Default doll poses.
|
||||
*/
|
||||
DEFAULT(
|
||||
"default",
|
||||
PartPose.offset(0.0F, 9.0F, 0.0F),
|
||||
PartPose.offset(0.0F, 9.0F, 0.0F),
|
||||
PartPose.offsetAndRotation(-5.0F, 11.0F, 0.0F, 0.0F, 0.0F, 0.3927F),
|
||||
PartPose.offsetAndRotation(5.0F, 11.0F, 0.0F, 0.0F, 0.0F, -0.3927F),
|
||||
PartPose.offsetAndRotation(-2.0F, 19.0F, -2.0F, -1.5708F, 0.3927F, 0.0F),
|
||||
PartPose.offsetAndRotation(2.0F, 19.0F, -2.0F, -1.5708F, -0.3927F, 0.0F)
|
||||
);
|
||||
// 注册全局?
|
||||
private final ResourceLocation id;
|
||||
private final Vec3 offset;
|
||||
private final PartPose headPose;
|
||||
private final PartPose bodyPose;
|
||||
private final PartPose rightArmPose;
|
||||
private final PartPose leftArmPose;
|
||||
private final PartPose rightLegPose;
|
||||
private final PartPose leftLegPose;
|
||||
|
||||
DollPoses(String name, PartPose headPose, PartPose bodyPose,
|
||||
PartPose rightArmPose, PartPose leftArmPose,
|
||||
PartPose rightLegPose, PartPose leftLegPose) {
|
||||
this(name, Vec3.ZERO, headPose, bodyPose, rightArmPose, leftArmPose, rightLegPose, leftLegPose);
|
||||
}
|
||||
|
||||
DollPoses(String name, Vec3 offset, PartPose headPose, PartPose bodyPose,
|
||||
PartPose rightArmPose, PartPose leftArmPose,
|
||||
PartPose rightLegPose, PartPose leftLegPose) {
|
||||
this.id = Lib39.rl(name);
|
||||
this.offset = offset;
|
||||
this.headPose = headPose;
|
||||
this.bodyPose = bodyPose;
|
||||
this.rightArmPose = rightArmPose;
|
||||
this.leftArmPose = leftArmPose;
|
||||
this.rightLegPose = rightLegPose;
|
||||
this.leftLegPose = leftLegPose;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ResourceLocation getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PartPose getHeadPose() {
|
||||
return headPose;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PartPose getBodyPose() {
|
||||
return bodyPose;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PartPose getRightArmPose() {
|
||||
return rightArmPose;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PartPose getLeftArmPose() {
|
||||
return leftArmPose;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PartPose getRightLegPose() {
|
||||
return rightLegPose;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PartPose getLeftLegPose() {
|
||||
return leftLegPose;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Vec3 getTotalOffset() {
|
||||
return offset;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,69 +0,0 @@
|
|||
package top.r3944realms.lib39.client.model;
|
||||
|
||||
import net.minecraft.client.model.geom.PartPose;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* The interface Doll pose.
|
||||
*/
|
||||
public interface IDollPose {
|
||||
/**
|
||||
* Gets id.
|
||||
*
|
||||
* @return the id
|
||||
*/
|
||||
@NotNull ResourceLocation getId();
|
||||
|
||||
/**
|
||||
* Gets total offset.
|
||||
*
|
||||
* @return the total offset
|
||||
*/
|
||||
@NotNull default Vec3 getTotalOffset() {
|
||||
return Vec3.ZERO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets head pose.
|
||||
*
|
||||
* @return the head pose
|
||||
*/
|
||||
@NotNull PartPose getHeadPose();
|
||||
|
||||
/**
|
||||
* Gets body pose.
|
||||
*
|
||||
* @return the body pose
|
||||
*/
|
||||
@NotNull PartPose getBodyPose();
|
||||
|
||||
/**
|
||||
* Gets right arm pose.
|
||||
*
|
||||
* @return the right arm pose
|
||||
*/
|
||||
@NotNull PartPose getRightArmPose();
|
||||
|
||||
/**
|
||||
* Gets left arm pose.
|
||||
*
|
||||
* @return the left arm pose
|
||||
*/
|
||||
@NotNull PartPose getLeftArmPose();
|
||||
|
||||
/**
|
||||
* Gets right leg pose.
|
||||
*
|
||||
* @return the right leg pose
|
||||
*/
|
||||
@NotNull PartPose getRightLegPose();
|
||||
|
||||
/**
|
||||
* Gets left leg pose.
|
||||
*
|
||||
* @return the left leg pose
|
||||
*/
|
||||
@NotNull PartPose getLeftLegPose();
|
||||
}
|
||||
|
|
@ -254,8 +254,8 @@ public class RadialMenuRenderer<T> {
|
|||
*/
|
||||
private void drawSector(GuiGraphics guiGraphics, float startAngle, float angleSize,
|
||||
float innerRadius, float outerRadius, float[] color) {
|
||||
Tesselator instance = Tesselator.getInstance();
|
||||
BufferBuilder buffer = instance.begin(VertexFormat.Mode.TRIANGLE_STRIP, DefaultVertexFormat.POSITION_COLOR);
|
||||
BufferBuilder buffer = Tesselator.getInstance().getBuilder();
|
||||
buffer.begin(VertexFormat.Mode.TRIANGLE_STRIP, DefaultVertexFormat.POSITION_COLOR);
|
||||
|
||||
Matrix4f matrix = guiGraphics.pose().last().pose();
|
||||
float segments = Math.max(8, this.segments * (angleSize / 360f));
|
||||
|
|
@ -269,14 +269,14 @@ public class RadialMenuRenderer<T> {
|
|||
float sin = Mth.sin(rad);
|
||||
|
||||
// 外圈顶点
|
||||
buffer.addVertex(matrix, outerRadius * cos, outerRadius * sin, 0)
|
||||
.setColor(color[0], color[1], color[2], color[3]);
|
||||
buffer.vertex(matrix, outerRadius * cos, outerRadius * sin, 0)
|
||||
.color(color[0], color[1], color[2], color[3]).endVertex();
|
||||
// 内圈顶点
|
||||
buffer.addVertex(matrix, innerRadius * cos, innerRadius * sin, 0)
|
||||
.setColor(color[0], color[1], color[2], color[3] * 0.6f);
|
||||
buffer.vertex(matrix, innerRadius * cos, innerRadius * sin, 0)
|
||||
.color(color[0], color[1], color[2], color[3] * 0.6f).endVertex();
|
||||
}
|
||||
|
||||
BufferUploader.drawWithShader(buffer.build());
|
||||
BufferUploader.drawWithShader(buffer.end());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -4,32 +4,25 @@ import com.mojang.authlib.GameProfile;
|
|||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
import com.mojang.math.Axis;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
|
||||
import net.minecraft.client.renderer.texture.OverlayTexture;
|
||||
import net.minecraft.client.resources.DefaultPlayerSkin;
|
||||
import net.minecraft.client.resources.PlayerSkin;
|
||||
import net.minecraft.client.resources.SkinManager;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.component.ResolvableProfile;
|
||||
import net.minecraft.world.level.block.SkullBlock;
|
||||
import net.minecraft.world.level.block.WallSkullBlock;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.properties.RotationSegment;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import top.r3944realms.lib39.client.model.DollModel;
|
||||
import top.r3944realms.lib39.client.renderer.item.DollItemRenderer;
|
||||
import top.r3944realms.lib39.content.block.AbstractDollBlock;
|
||||
import top.r3944realms.lib39.content.block.WallDollBlock;
|
||||
import top.r3944realms.lib39.content.block.blockentity.DollBlockEntity;
|
||||
import top.r3944realms.lib39.util.lang.Pair;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* The type Doll block entity renderer.
|
||||
*/
|
||||
|
|
@ -52,43 +45,16 @@ public class DollBlockEntityRenderer implements BlockEntityRenderer<DollBlockEnt
|
|||
boolean isWall = dollBlock instanceof WallDollBlock;
|
||||
Direction direction = isWall ? blockState.getValue(WallSkullBlock.FACING) : null;
|
||||
float rotation = isWall ? direction.toYRot() : RotationSegment.convertToDegrees(blockState.getValue(SkullBlock.ROTATION));
|
||||
Pair<PlayerSkin.Model, RenderType> modelAndRenderTypePair = getModelAndRenderTypePair(dollBlockEntity.getOwnerProfile());
|
||||
GameProfile profile = dollBlockEntity.getOwnerProfile();
|
||||
Pair<ResourceLocation, Boolean> resourceLocationBooleanPair = DollItemRenderer.loadSkin(profile);
|
||||
poseStack.pushPose();
|
||||
poseStack.translate(0.5, 1.5, 0.5);
|
||||
poseStack.scale(1.0F, -1.0F, -1.0F);
|
||||
poseStack.mulPose(Axis.YP.rotationDegrees(rotation));
|
||||
VertexConsumer vertexConsumer = buffer.getBuffer(modelAndRenderTypePair.second);
|
||||
this.dollModel.slim = modelAndRenderTypePair.first == PlayerSkin.Model.SLIM;
|
||||
this.dollModel.renderToBuffer(poseStack, vertexConsumer, packedLight, OverlayTexture.NO_OVERLAY,-1);
|
||||
VertexConsumer vertexConsumer = buffer.getBuffer(RenderType.entityTranslucent(resourceLocationBooleanPair.first));
|
||||
this.dollModel.slim = resourceLocationBooleanPair.second;
|
||||
this.dollModel.renderToBuffer(poseStack, vertexConsumer, packedLight, OverlayTexture.NO_OVERLAY, 1.0F, 1.0F, 1.0F, 1.0F);
|
||||
poseStack.popPose();
|
||||
}
|
||||
}
|
||||
public static @NotNull Pair<PlayerSkin.Model, RenderType> getModelAndRenderTypePair(@Nullable ResolvableProfile profile) {
|
||||
SkinManager skinmanager = Minecraft.getInstance().getSkinManager();
|
||||
|
||||
if (profile == null) {
|
||||
return Pair.of(PlayerSkin.Model.SLIM,
|
||||
RenderType.entityTranslucent(DefaultPlayerSkin.getDefaultTexture()));
|
||||
}
|
||||
|
||||
GameProfile gameProfile = profile.gameProfile();
|
||||
|
||||
// 如果当前 Profile 没有纹理数据,尝试从 DollBlockEntity 缓存获取
|
||||
if (gameProfile != null && gameProfile.getProperties().isEmpty()
|
||||
&& gameProfile.getName() != null && !gameProfile.getName().isEmpty()) {
|
||||
Optional<GameProfile> cached = DollBlockEntity.fetchGameProfile(gameProfile.getName())
|
||||
.getNow(Optional.empty());
|
||||
if (cached.isPresent() && !cached.get().getProperties().isEmpty()) {
|
||||
gameProfile = cached.get();
|
||||
}
|
||||
}
|
||||
|
||||
if (gameProfile != null && !gameProfile.getProperties().isEmpty()) {
|
||||
PlayerSkin skin = skinmanager.getInsecureSkin(gameProfile);
|
||||
return Pair.of(skin.model(), RenderType.entityTranslucent(skin.texture()));
|
||||
}
|
||||
|
||||
return Pair.of(PlayerSkin.Model.SLIM,
|
||||
RenderType.entityTranslucent(DefaultPlayerSkin.getDefaultTexture()));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,13 +9,10 @@ import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer;
|
|||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.resources.DefaultPlayerSkin;
|
||||
import net.minecraft.client.resources.PlayerSkin;
|
||||
import net.minecraft.client.resources.SkinManager;
|
||||
import net.minecraft.core.component.DataComponents;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.ItemDisplayContext;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.component.ResolvableProfile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import top.r3944realms.lib39.Lib39;
|
||||
import top.r3944realms.lib39.client.model.DollModel;
|
||||
|
|
@ -64,44 +61,54 @@ public class DollItemRenderer extends BlockEntityWithoutLevelRenderer {
|
|||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderByItem(@NotNull ItemStack stack, @NotNull ItemDisplayContext displayContext,
|
||||
@NotNull PoseStack poseStack, @NotNull MultiBufferSource buffer,
|
||||
int packedLight, int packedOverlay) {
|
||||
public void renderByItem(@NotNull ItemStack stack, @NotNull ItemDisplayContext displayContext, @NotNull PoseStack poseStack, @NotNull MultiBufferSource buffer, int packedLight, int packedOverlay) {
|
||||
if (!(stack.getItem() instanceof DollItem)) {
|
||||
return;
|
||||
}
|
||||
lazyInit();
|
||||
|
||||
// 直接从 DataComponents.PROFILE 获取 ResolvableProfile
|
||||
ResolvableProfile profile = stack.get(DataComponents.PROFILE);
|
||||
Pair<ResourceLocation, PlayerSkin.Model> skinInfo = getSkinInfo(profile);
|
||||
|
||||
GameProfile profile = GameProfileHelper.getProfileFromItemStack(stack);
|
||||
Pair<ResourceLocation, Boolean> resourceLocationBooleanPair = loadSkin(profile);
|
||||
ResourceLocation playerSkin = resourceLocationBooleanPair.first;
|
||||
boolean isSlim = resourceLocationBooleanPair.second;
|
||||
poseStack.pushPose();
|
||||
VertexConsumer vertexConsumer = buffer.getBuffer(RenderType.entityTranslucent(skinInfo.first));
|
||||
VertexConsumer vertexConsumer = buffer.getBuffer(
|
||||
RenderType.entityTranslucent(playerSkin)
|
||||
);
|
||||
|
||||
poseStack.translate(0.5, 2.6, 0.8);
|
||||
poseStack.scale(1.8F, -1.8F, -1.8F);
|
||||
poseStack.mulPose(Axis.YP.rotationDegrees(180));
|
||||
|
||||
this.dollModel.slim = skinInfo.second == PlayerSkin.Model.SLIM;
|
||||
this.dollModel.renderToBuffer(poseStack, vertexConsumer, packedLight, packedOverlay, -1);
|
||||
this.dollModel.slim = isSlim;
|
||||
this.dollModel.renderToBuffer(
|
||||
poseStack,
|
||||
vertexConsumer,
|
||||
packedLight,
|
||||
packedOverlay,
|
||||
1.0F, 1.0F, 1.0F, 1.0F
|
||||
);
|
||||
|
||||
poseStack.popPose();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取皮肤纹理和模型类型(1.21+ 版本)
|
||||
* Load skin pair.
|
||||
*
|
||||
* @param profile the profile
|
||||
* @return the pair
|
||||
*/
|
||||
public static @NotNull Pair<ResourceLocation, PlayerSkin.Model> getSkinInfo(@NotNull ResolvableProfile profile) {
|
||||
public static @NotNull Pair<ResourceLocation,Boolean> loadSkin(GameProfile profile) {
|
||||
SkinManager skinManager = Minecraft.getInstance().getSkinManager();
|
||||
|
||||
if (profile != null && profile.gameProfile() != null) {
|
||||
PlayerSkin skin = skinManager.getInsecureSkin(profile.gameProfile());
|
||||
return Pair.of(skin.texture(), skin.model());
|
||||
ResourceLocation playerSkin;
|
||||
boolean isSlim;
|
||||
if (profile != null) {
|
||||
playerSkin = skinManager.getInsecureSkinLocation(profile);
|
||||
isSlim = GameProfileHelper.isSlimArms(profile);
|
||||
} else {
|
||||
playerSkin = DefaultPlayerSkin.getDefaultSkin(); //6 new SkinType("textures/entity/player/slim/steve.png", DefaultPlayerSkin.ModelType.SLIM),
|
||||
isSlim = true;
|
||||
}
|
||||
|
||||
// 默认返回 Steve 皮肤
|
||||
return Pair.of(DefaultPlayerSkin.getDefaultTexture(), PlayerSkin.Model.SLIM);
|
||||
return Pair.of(playerSkin, isSlim);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,24 +1,19 @@
|
|||
package top.r3944realms.lib39.content.block;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.serialization.MapCodec;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.component.DataComponents;
|
||||
import net.minecraft.core.particles.ParticleTypes;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
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.item.ItemStack;
|
||||
import net.minecraft.world.item.component.ResolvableProfile;
|
||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.LevelAccessor;
|
||||
import net.minecraft.world.level.LevelReader;
|
||||
import net.minecraft.world.level.block.*;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
|
@ -39,7 +34,6 @@ import net.minecraft.world.phys.shapes.Shapes;
|
|||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import top.r3944realms.lib39.client.model.IDollPose;
|
||||
import top.r3944realms.lib39.content.block.blockentity.DollBlockEntity;
|
||||
import top.r3944realms.lib39.content.block.property.DollPose;
|
||||
import top.r3944realms.lib39.core.register.Lib39BlockEntities;
|
||||
|
|
@ -106,16 +100,16 @@ public abstract class AbstractDollBlock extends BaseEntityBlock implements Simpl
|
|||
}
|
||||
|
||||
@Override
|
||||
protected InteractionResult useWithoutItem(BlockState state, Level level, BlockPos pos, Player player, BlockHitResult hitResult) {
|
||||
public @NotNull InteractionResult use(@NotNull BlockState blockState, @NotNull Level level, @NotNull BlockPos blockPos, @NotNull Player player,
|
||||
@NotNull InteractionHand hand, @NotNull BlockHitResult hitResult) {
|
||||
if (level instanceof ServerLevel serverLevel) {
|
||||
// 播放粒子效果
|
||||
spawnNoteParticles(serverLevel, pos);
|
||||
spawnNoteParticles(serverLevel, blockPos);
|
||||
// 播放音效
|
||||
playDollSound(serverLevel, pos);
|
||||
playDollSound(serverLevel, blockPos);
|
||||
}
|
||||
return InteractionResult.SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* 在玩偶位置生成音符粒子效果
|
||||
*/
|
||||
|
|
@ -177,16 +171,13 @@ public abstract class AbstractDollBlock extends BaseEntityBlock implements Simpl
|
|||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getCloneItemStack(LevelReader level, BlockPos pos, BlockState state) {
|
||||
public @NotNull ItemStack getCloneItemStack(@NotNull BlockGetter level, @NotNull BlockPos pos, @NotNull BlockState state) {
|
||||
ItemStack stack = super.getCloneItemStack(level, pos, state);
|
||||
BlockEntity blockEntity = level.getBlockEntity(pos);
|
||||
if (blockEntity instanceof DollBlockEntity doll) {
|
||||
ResolvableProfile profile;
|
||||
if (doll.getOwnerProfile() != null) {
|
||||
profile = doll.getOwnerProfile();
|
||||
if (profile != null) {
|
||||
GameProfileHelper.saveProfileToItemStack(stack, profile);
|
||||
}
|
||||
GameProfile profile = doll.getOwnerProfile();
|
||||
if (profile != null) {
|
||||
GameProfileHelper.saveProfileToItemStack(stack, profile);
|
||||
}
|
||||
}
|
||||
return stack;
|
||||
|
|
@ -213,38 +204,22 @@ public abstract class AbstractDollBlock extends BaseEntityBlock implements Simpl
|
|||
super.createBlockStateDefinition(builder);
|
||||
builder.add(WATERLOGGED, POSE);
|
||||
}
|
||||
@Override
|
||||
public void setPlacedBy(@NotNull Level level, @NotNull BlockPos pos, @NotNull BlockState state,
|
||||
@Nullable LivingEntity placer, @NotNull ItemStack stack) {
|
||||
super.setPlacedBy(level, pos, state, placer, stack);
|
||||
|
||||
BlockEntity blockEntity = level.getBlockEntity(pos);
|
||||
if (blockEntity instanceof DollBlockEntity dollEntity) {
|
||||
ResolvableProfile profile = GameProfileHelper.getProfileFromItemStack(stack);
|
||||
if (profile != null) {
|
||||
dollEntity.setOwner(profile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成自定义掉落物
|
||||
*/
|
||||
@Nullable
|
||||
private List<ItemStack> getCustomDrops(DollBlockEntity dollEntity, LootParams.@NotNull Builder params) {
|
||||
private List<ItemStack> getCustomDrops(DollBlockEntity dollEntity, LootParams.Builder params) {
|
||||
if (params.getOptionalParameter(LootContextParams.THIS_ENTITY) instanceof Player player) {
|
||||
if (player.isCreative()) {
|
||||
return List.of();
|
||||
}
|
||||
}
|
||||
ResolvableProfile profile;
|
||||
if (dollEntity.getOwnerProfile() != null) {
|
||||
profile = dollEntity.getOwnerProfile();
|
||||
if (profile != null) {
|
||||
ItemStack instance = Lib39Items.DOLL.get().getDefaultInstance();
|
||||
GameProfileHelper.saveProfileToItemStack(instance, profile);
|
||||
return List.of(instance);
|
||||
}
|
||||
GameProfile profile = dollEntity.getOwnerProfile();
|
||||
if (profile != null) {
|
||||
ItemStack instance = Lib39Items.DOLL.get().getDefaultInstance();
|
||||
GameProfileHelper.saveProfileToItemStack(instance, profile);
|
||||
return List.of(instance);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
package top.r3944realms.lib39.content.block;
|
||||
|
||||
import com.mojang.serialization.MapCodec;
|
||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||
import net.minecraft.world.level.block.BaseEntityBlock;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Mirror;
|
||||
import net.minecraft.world.level.block.Rotation;
|
||||
|
|
@ -19,7 +17,7 @@ import top.r3944realms.lib39.content.block.property.DollPose;
|
|||
* The type Doll block.
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class DollBlock extends AbstractDollBlock {
|
||||
public class DollBlock extends AbstractDollBlock{
|
||||
/**
|
||||
* The constant MAX.
|
||||
*/
|
||||
|
|
@ -44,10 +42,6 @@ public class DollBlock extends AbstractDollBlock {
|
|||
);
|
||||
}
|
||||
@Override
|
||||
protected MapCodec<? extends BaseEntityBlock> codec() {
|
||||
return simpleCodec(p -> new DollBlock());
|
||||
}
|
||||
@Override
|
||||
public @Nullable BlockState getStateForPlacement(@NotNull BlockPlaceContext context) {
|
||||
BlockState stateForPlacement = super.getStateForPlacement(context);
|
||||
return stateForPlacement != null ? stateForPlacement.setValue(ROTATION, RotationSegment.convertToSegment((context.getRotation()+180) % 360)) : null;
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
package top.r3944realms.lib39.content.block;
|
||||
|
||||
import com.mojang.serialization.MapCodec;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||
import net.minecraft.world.level.block.*;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.HorizontalDirectionalBlock;
|
||||
import net.minecraft.world.level.block.Mirror;
|
||||
import net.minecraft.world.level.block.Rotation;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.StateDefinition;
|
||||
import net.minecraft.world.level.block.state.properties.DirectionProperty;
|
||||
|
|
@ -33,12 +35,6 @@ public class WallDollBlock extends AbstractDollBlock {
|
|||
.setValue(FACING, Direction.NORTH)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected MapCodec<? extends BaseEntityBlock> codec() {
|
||||
return simpleCodec(p -> new WallDollBlock());
|
||||
}
|
||||
|
||||
public @NotNull BlockState rotate(@NotNull BlockState state, @NotNull Rotation rotation) {
|
||||
return state.setValue(FACING, rotation.rotate(state.getValue(FACING)));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,196 +1,98 @@
|
|||
package top.r3944realms.lib39.content.block.blockentity;
|
||||
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.NbtOps;
|
||||
import net.minecraft.nbt.NbtUtils;
|
||||
import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket;
|
||||
import net.minecraft.server.Services;
|
||||
import net.minecraft.world.item.component.ResolvableProfile;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.SkullBlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import top.r3944realms.lib39.core.register.Lib39BlockEntities;
|
||||
import top.r3944realms.lib39.util.GameProfileHelper;
|
||||
import top.r3944realms.lib39.util.nbt.NBTReader;
|
||||
import top.r3944realms.lib39.util.nbt.NBTWriter;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.function.BooleanSupplier;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* The type Doll block entity.
|
||||
* 参考 SkullBlockEntity 实现,添加缓存机制
|
||||
*/
|
||||
public class DollBlockEntity extends BlockEntity {
|
||||
|
||||
private static final String TAG_PROFILE = "profile";
|
||||
|
||||
// 静态缓存(与 SkullBlockEntity 共享或独立)
|
||||
@Nullable
|
||||
private static Executor mainThreadExecutor;
|
||||
@Nullable
|
||||
private static LoadingCache<String, CompletableFuture<Optional<GameProfile>>> profileCacheByName;
|
||||
@Nullable
|
||||
private static LoadingCache<UUID, CompletableFuture<Optional<GameProfile>>> profileCacheById;
|
||||
|
||||
public static final Executor CHECKED_MAIN_THREAD_EXECUTOR = (runnable) -> {
|
||||
Executor executor = mainThreadExecutor;
|
||||
if (executor != null) {
|
||||
executor.execute(runnable);
|
||||
}
|
||||
};
|
||||
|
||||
@Nullable
|
||||
private ResolvableProfile owner;
|
||||
private GameProfile owner;
|
||||
|
||||
/**
|
||||
* Instantiates a new Doll block entity.
|
||||
*
|
||||
* @param pos the pos
|
||||
* @param blockState the block state
|
||||
*/
|
||||
public DollBlockEntity(BlockPos pos, BlockState blockState) {
|
||||
super(Lib39BlockEntities.DOLL_BLOCK_ENTITY.get(), pos, blockState);
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化缓存(在 Mod 初始化或服务器启动时调用)
|
||||
*/
|
||||
public static void setup(final Services services, Executor executor) {
|
||||
mainThreadExecutor = executor;
|
||||
final BooleanSupplier cacheUninitialized = () -> profileCacheById == null;
|
||||
|
||||
profileCacheByName = CacheBuilder.newBuilder()
|
||||
.expireAfterAccess(Duration.ofMinutes(10L))
|
||||
.maximumSize(256L)
|
||||
.build(new CacheLoader<>() {
|
||||
@Override
|
||||
public CompletableFuture<Optional<GameProfile>> load(String username) {
|
||||
return fetchProfileByName(username, services);
|
||||
}
|
||||
});
|
||||
|
||||
profileCacheById = CacheBuilder.newBuilder()
|
||||
.expireAfterAccess(Duration.ofMinutes(10L))
|
||||
.maximumSize(256L)
|
||||
.build(new CacheLoader<>() {
|
||||
@Override
|
||||
public CompletableFuture<Optional<GameProfile>> load(UUID uuid) {
|
||||
return fetchProfileById(uuid, services, cacheUninitialized);
|
||||
}
|
||||
});
|
||||
protected void saveAdditional(@NotNull CompoundTag tag) {
|
||||
super.saveAdditional(tag);
|
||||
NBTWriter.of(tag)
|
||||
.compoundIf(GameProfileHelper.TAG_OWN_PROFILE, owner != null, () -> NbtUtils.writeGameProfile(new CompoundTag(), this.owner));
|
||||
}
|
||||
|
||||
private static CompletableFuture<Optional<GameProfile>> fetchProfileByName(String name, Services services) {
|
||||
return services.profileCache().getAsync(name).thenCompose(optional -> {
|
||||
LoadingCache<UUID, CompletableFuture<Optional<GameProfile>>> cache = profileCacheById;
|
||||
if (cache != null && optional.isPresent()) {
|
||||
return cache.getUnchecked(optional.get().getId())
|
||||
.thenApply(fullProfile -> fullProfile.or(() -> optional));
|
||||
}
|
||||
return CompletableFuture.completedFuture(Optional.empty());
|
||||
});
|
||||
}
|
||||
|
||||
private static CompletableFuture<Optional<GameProfile>> fetchProfileById(UUID uuid, Services services, BooleanSupplier cacheUninitialized) {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
if (cacheUninitialized.getAsBoolean()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
var result = services.sessionService().fetchProfile(uuid, true);
|
||||
return Optional.ofNullable(result).map(com.mojang.authlib.yggdrasil.ProfileResult::profile);
|
||||
}, Util.backgroundExecutor());
|
||||
public void load(@NotNull CompoundTag tag) {
|
||||
super.load(tag);
|
||||
NBTReader.of(tag)
|
||||
.compound(GameProfileHelper.TAG_OWN_PROFILE, compoundTag -> setOwner(NbtUtils.readGameProfile(compoundTag)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 公开的静态方法:异步获取 GameProfile(复用 SkullBlockEntity 的缓存或使用自己的)
|
||||
* Gets owner profile.
|
||||
*
|
||||
* @return the owner profile
|
||||
*/
|
||||
public static CompletableFuture<Optional<GameProfile>> fetchGameProfile(String name) {
|
||||
if (profileCacheByName != null && name != null && !name.isEmpty()) {
|
||||
return profileCacheByName.getUnchecked(name);
|
||||
}
|
||||
// 回退到 SkullBlockEntity 的缓存
|
||||
return SkullBlockEntity.fetchGameProfile(name);
|
||||
}
|
||||
|
||||
public static CompletableFuture<Optional<GameProfile>> fetchGameProfile(UUID uuid) {
|
||||
if (profileCacheById != null && uuid != null) {
|
||||
return profileCacheById.getUnchecked(uuid);
|
||||
}
|
||||
return SkullBlockEntity.fetchGameProfile(uuid);
|
||||
}
|
||||
|
||||
public static void clearCache() {
|
||||
mainThreadExecutor = null;
|
||||
profileCacheByName = null;
|
||||
profileCacheById = null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ResolvableProfile getOwnerProfile() {
|
||||
public GameProfile getOwnerProfile() {
|
||||
return this.owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
public ClientboundBlockEntityDataPacket getUpdatePacket() {
|
||||
return ClientboundBlockEntityDataPacket.create(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag getUpdateTag(HolderLookup.Provider registries) {
|
||||
CompoundTag tag = super.getUpdateTag(registries);
|
||||
saveAdditional(tag, registries);
|
||||
return tag;
|
||||
public @NotNull CompoundTag getUpdateTag() {
|
||||
return this.saveWithoutMetadata();
|
||||
}
|
||||
|
||||
public void setOwner(@Nullable ResolvableProfile owner) {
|
||||
/**
|
||||
* Sets owner.
|
||||
*
|
||||
* @param owner the owner
|
||||
*/
|
||||
public void setOwner(@Nullable GameProfile owner) {
|
||||
synchronized (this) {
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
this.updateOwnerProfile();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets owner.
|
||||
*
|
||||
* @param ownerName the owner name
|
||||
*/
|
||||
public void setOwner(@Nullable String ownerName) {
|
||||
if (ownerName != null && !ownerName.isEmpty()) {
|
||||
setOwner(new ResolvableProfile(new GameProfile(Util.NIL_UUID, ownerName)));
|
||||
}
|
||||
setOwner(new GameProfile(Util.NIL_UUID, ownerName));
|
||||
}
|
||||
|
||||
private void updateOwnerProfile() {
|
||||
if (this.owner != null && !this.owner.isResolved()) {
|
||||
this.owner.resolve().thenAcceptAsync(resolved -> {
|
||||
this.owner = resolved;
|
||||
this.setChanged();
|
||||
// 通知客户端更新
|
||||
if (level != null && !level.isClientSide) {
|
||||
level.sendBlockUpdated(worldPosition, getBlockState(), getBlockState(), 3);
|
||||
}
|
||||
}, CHECKED_MAIN_THREAD_EXECUTOR);
|
||||
} else {
|
||||
SkullBlockEntity.updateGameprofile(this.owner, gameProfile -> {
|
||||
this.owner = gameProfile;
|
||||
this.setChanged();
|
||||
if (level != null && !level.isClientSide && this.owner != null) {
|
||||
level.sendBlockUpdated(worldPosition, getBlockState(), getBlockState(), 3);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void saveAdditional(CompoundTag tag, HolderLookup.Provider registries) {
|
||||
super.saveAdditional(tag, registries);
|
||||
if (this.owner != null) {
|
||||
tag.put(TAG_PROFILE, ResolvableProfile.CODEC.encodeStart(NbtOps.INSTANCE, this.owner).getOrThrow());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadAdditional(CompoundTag tag, HolderLookup.Provider registries) {
|
||||
super.loadAdditional(tag, registries);
|
||||
if (tag.contains(TAG_PROFILE)) {
|
||||
ResolvableProfile.CODEC.parse(NbtOps.INSTANCE, tag.get(TAG_PROFILE))
|
||||
.resultOrPartial(error -> {})
|
||||
.ifPresent(this::setOwner);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ import net.minecraft.world.item.Equipable;
|
|||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.StandingAndWallBlockItem;
|
||||
import net.minecraft.world.item.TooltipFlag;
|
||||
import net.minecraft.world.item.component.ResolvableProfile;
|
||||
import net.minecraft.world.level.Level;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
|
@ -30,19 +29,15 @@ public class DollItem extends StandingAndWallBlockItem implements Equipable {
|
|||
super(Lib39Blocks.DOLL.get(), Lib39Blocks.WALL_DOLL.get(), properties, Direction.DOWN);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendHoverText(ItemStack stack, TooltipContext context, List<Component> tooltipComponents, TooltipFlag tooltipFlag) {
|
||||
super.appendHoverText(stack, context, tooltipComponents, tooltipFlag);
|
||||
ResolvableProfile profileFromItemStack = GameProfileHelper.getProfileFromItemStack(stack);
|
||||
if (profileFromItemStack != null) {
|
||||
GameProfile gameProfile = profileFromItemStack.gameProfile();
|
||||
if (gameProfile != null && gameProfile.getName() != null) {
|
||||
tooltipComponents.add(Component.translatable("tooltip.lib39.content.doll.hover.1", gameProfile.getName()));
|
||||
}
|
||||
}
|
||||
tooltipComponents.add(Component.translatable("tooltip.lib39.content.doll.hover.2"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendHoverText(@NotNull ItemStack stack, @Nullable Level level, @NotNull List<Component> tooltip, @NotNull TooltipFlag flag) {
|
||||
GameProfile profileFromItemStack = GameProfileHelper.getProfileFromItemStack(stack);
|
||||
if (profileFromItemStack != null && profileFromItemStack.getName() != null) {
|
||||
tooltip.add(Component.translatable("tooltip.lib39.content.doll.hover.1", profileFromItemStack.getName()));
|
||||
}
|
||||
tooltip.add(Component.translatable("tooltip.lib39.content.doll.hover.2"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull EquipmentSlot getEquipmentSlot() {
|
||||
|
|
|
|||
|
|
@ -10,10 +10,11 @@ import net.minecraft.commands.Commands;
|
|||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.MutableComponent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import top.r3944realms.lib39.base.datagen.value.Lib39LangKey;
|
||||
import top.r3944realms.lib39.platform.Services;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* The interface Help command.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1109,8 +1109,6 @@ public class CommandNode {
|
|||
|
||||
/**
|
||||
* 葉子節點配置記錄
|
||||
* @param description 介绍
|
||||
* @param parameters 参数列表
|
||||
*/
|
||||
public record LeafConfig(@NotNull MutableComponent description,
|
||||
@Nullable List<Parameter> parameters) {
|
||||
|
|
|
|||
|
|
@ -8,8 +8,6 @@ import java.util.List;
|
|||
|
||||
/**
|
||||
* The type Parameter.
|
||||
* @param name 参数名
|
||||
* @param required 是否必须
|
||||
*/
|
||||
public record Parameter(String name, boolean required) {
|
||||
|
||||
|
|
|
|||
|
|
@ -11,17 +11,14 @@ import java.util.stream.Collectors;
|
|||
|
||||
/**
|
||||
* The type Compat manager.
|
||||
*
|
||||
* @param <C> the type parameter
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public abstract class CompatManager<C extends ICompat> implements ICompatManager<C> {
|
||||
public abstract class CompatManager {
|
||||
/**
|
||||
* Gets id.
|
||||
*
|
||||
* @return the id
|
||||
*/
|
||||
@Override
|
||||
public ResourceLocation getId() {
|
||||
return id;
|
||||
}
|
||||
|
|
@ -34,7 +31,10 @@ public abstract class CompatManager<C extends ICompat> implements ICompatManager
|
|||
* The Id.
|
||||
*/
|
||||
protected final ResourceLocation id;
|
||||
|
||||
/**
|
||||
* The Compats.
|
||||
*/
|
||||
protected final Map<ResourceLocation, ICompat> compats = new HashMap<>();
|
||||
/**
|
||||
* The Initialized.
|
||||
*/
|
||||
|
|
@ -47,7 +47,6 @@ public abstract class CompatManager<C extends ICompat> implements ICompatManager
|
|||
/**
|
||||
* Initialize.
|
||||
*/
|
||||
@Override
|
||||
public void initialize() {
|
||||
initializeAllCompat();
|
||||
onLoadComplete();
|
||||
|
|
@ -69,8 +68,7 @@ public abstract class CompatManager<C extends ICompat> implements ICompatManager
|
|||
* @param id the id
|
||||
* @param compat the compat
|
||||
*/
|
||||
@Override
|
||||
public void registerCompat(ResourceLocation id, C compat) {
|
||||
public void registerCompat(ResourceLocation id, ICompat compat) {
|
||||
if (initialized) {
|
||||
// 已初始化,直接注册
|
||||
doRegisterCompat(id, compat);
|
||||
|
|
@ -87,12 +85,12 @@ public abstract class CompatManager<C extends ICompat> implements ICompatManager
|
|||
* @param id the id
|
||||
* @param compat the compat
|
||||
*/
|
||||
protected void doRegisterCompat(ResourceLocation id, C compat) {
|
||||
if (getCompatMap().containsKey(id)) {
|
||||
protected void doRegisterCompat(ResourceLocation id, ICompat compat) {
|
||||
if (compats.containsKey(id)) {
|
||||
logger.warn("Compat with id {} is already registered!", id);
|
||||
return;
|
||||
}
|
||||
getCompatMap().put(id, compat);
|
||||
compats.put(id, compat);
|
||||
logger.debug("Registered compat: {}", id);
|
||||
}
|
||||
|
||||
|
|
@ -103,8 +101,7 @@ public abstract class CompatManager<C extends ICompat> implements ICompatManager
|
|||
* @param path the path
|
||||
* @param compat the compat
|
||||
*/
|
||||
@Override
|
||||
public void registerCompat(String namespace, String path, C compat) {
|
||||
public void registerCompat(String namespace, String path, ICompat compat) {
|
||||
registerCompat(Lib39.rl(namespace, path), compat);
|
||||
}
|
||||
|
||||
|
|
@ -115,14 +112,14 @@ public abstract class CompatManager<C extends ICompat> implements ICompatManager
|
|||
* 初始化所有兼容模块并应用事件监听器
|
||||
*/
|
||||
protected synchronized void initializeAllCompat() {
|
||||
logger.info("Initializing {} compatibility modules", getCompatMap().size());
|
||||
logger.info("Initializing {} compatibility modules", compats.size());
|
||||
|
||||
// 先处理所有缓存的注册
|
||||
pendingTasks.forEach(Runnable::run);
|
||||
pendingTasks.clear();
|
||||
|
||||
// 初始化所有兼容模块
|
||||
for (Map.Entry<ResourceLocation, C> entry : getCompatMap().entrySet()) {
|
||||
for (Map.Entry<ResourceLocation, ICompat> entry : compats.entrySet()) {
|
||||
if (!entry.getValue().isInitialized() && entry.getValue().isModLoaded()) {
|
||||
try {
|
||||
entry.getValue().initialize();
|
||||
|
|
@ -142,9 +139,8 @@ public abstract class CompatManager<C extends ICompat> implements ICompatManager
|
|||
* @param id the id
|
||||
* @return the compat
|
||||
*/
|
||||
@Override
|
||||
public Optional<C> getCompat(ResourceLocation id) {
|
||||
return Optional.ofNullable(getCompatMap().get(id));
|
||||
public Optional<ICompat> getCompat(ResourceLocation id) {
|
||||
return Optional.ofNullable(compats.get(id));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -153,9 +149,8 @@ public abstract class CompatManager<C extends ICompat> implements ICompatManager
|
|||
* @param id the id
|
||||
* @return the boolean
|
||||
*/
|
||||
@Override
|
||||
public boolean hasCompat(ResourceLocation id) {
|
||||
return getCompatMap().containsKey(id);
|
||||
return compats.containsKey(id);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -163,9 +158,8 @@ public abstract class CompatManager<C extends ICompat> implements ICompatManager
|
|||
*
|
||||
* @param id the id
|
||||
*/
|
||||
@Override
|
||||
public void unregisterCompat(ResourceLocation id) {
|
||||
C removed = getCompatMap().remove(id);
|
||||
ICompat removed = compats.remove(id);
|
||||
if (removed != null) {
|
||||
logger.debug("Unregistered compat: {}", id);
|
||||
}
|
||||
|
|
@ -176,9 +170,9 @@ public abstract class CompatManager<C extends ICompat> implements ICompatManager
|
|||
*
|
||||
* @return the loaded compats
|
||||
*/
|
||||
public List<C> getLoadedCompats() {
|
||||
return getCompatMap().values().stream()
|
||||
.filter(C::isModLoaded)
|
||||
public List<ICompat> getLoadedCompats() {
|
||||
return compats.values().stream()
|
||||
.filter(ICompat::isModLoaded)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
|
@ -186,8 +180,8 @@ public abstract class CompatManager<C extends ICompat> implements ICompatManager
|
|||
* On load complete.
|
||||
*/
|
||||
public void onLoadComplete() {
|
||||
logger.info("Calling onLoadComplete for {} compatibility modules", getCompatMap().size());
|
||||
for (Map.Entry<ResourceLocation, C> entry : getCompatMap().entrySet()) {
|
||||
logger.info("Calling onLoadComplete for {} compatibility modules", compats.size());
|
||||
for (Map.Entry<ResourceLocation, ICompat> entry : compats.entrySet()) {
|
||||
try {
|
||||
entry.getValue().onLoadComplete();
|
||||
} catch (Exception e) {
|
||||
|
|
|
|||
|
|
@ -1,72 +0,0 @@
|
|||
package top.r3944realms.lib39.core.compat;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* The interface Compat manager.
|
||||
*
|
||||
* @param <C> the type parameter
|
||||
*/
|
||||
public interface ICompatManager<C extends ICompat> {
|
||||
/**
|
||||
* Gets id.
|
||||
*
|
||||
* @return the id
|
||||
*/
|
||||
ResourceLocation getId();
|
||||
|
||||
/**
|
||||
* Gets compat map.
|
||||
*
|
||||
* @return the compat map
|
||||
*/
|
||||
Map<ResourceLocation, C> getCompatMap();
|
||||
|
||||
/**
|
||||
* Initialize.
|
||||
*/
|
||||
void initialize();
|
||||
|
||||
/**
|
||||
* Register compat.
|
||||
*
|
||||
* @param id the id
|
||||
* @param compat the compat
|
||||
*/
|
||||
void registerCompat(ResourceLocation id, C compat);
|
||||
|
||||
/**
|
||||
* Register compat.
|
||||
*
|
||||
* @param namespace the namespace
|
||||
* @param path the path
|
||||
* @param compat the compat
|
||||
*/
|
||||
void registerCompat(String namespace, String path, C compat);
|
||||
|
||||
/**
|
||||
* Gets compat.
|
||||
*
|
||||
* @param id the id
|
||||
* @return the compat
|
||||
*/
|
||||
Optional<C> getCompat(ResourceLocation id);
|
||||
|
||||
/**
|
||||
* Has compat boolean.
|
||||
*
|
||||
* @param id the id
|
||||
* @return the boolean
|
||||
*/
|
||||
boolean hasCompat(ResourceLocation id);
|
||||
|
||||
/**
|
||||
* Unregister compat.
|
||||
*
|
||||
* @param id the id
|
||||
*/
|
||||
void unregisterCompat(ResourceLocation id);
|
||||
}
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
package top.r3944realms.lib39.core.compat;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* The type Simple compat manager.
|
||||
*/
|
||||
public class SimpleCompatManager extends CompatManager<ICompat> {
|
||||
/**
|
||||
* The Compats.
|
||||
*/
|
||||
Map<ResourceLocation, ICompat> compats = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Instantiates a new Compat manager.
|
||||
*
|
||||
* @param id the id
|
||||
*/
|
||||
public SimpleCompatManager(@NotNull ResourceLocation id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<ResourceLocation, ICompat> getCompatMap() {
|
||||
return compats;
|
||||
}
|
||||
}
|
||||
|
|
@ -7,7 +7,7 @@ import net.minecraft.nbt.Tag;
|
|||
*
|
||||
* @param <T> the type parameter
|
||||
*/
|
||||
public interface INBTSerializable <T extends Tag> {
|
||||
public interface INBTSerializable <T extends Tag>{
|
||||
/**
|
||||
* Serialize nbt t.
|
||||
*
|
||||
|
|
@ -18,7 +18,7 @@ public interface INBTSerializable <T extends Tag> {
|
|||
/**
|
||||
* Deserialize nbt.
|
||||
*
|
||||
* @param t the var
|
||||
* @param var1 the var 1
|
||||
*/
|
||||
void deserializeNBT(T t);
|
||||
void deserializeNBT(T var1);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -123,6 +123,26 @@ public abstract class LanguageProvider implements DataProvider {
|
|||
this.add(key.getDescriptionId(), name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add enchantment.
|
||||
*
|
||||
* @param key the key
|
||||
* @param name the name
|
||||
*/
|
||||
public void addEnchantment(@NotNull Supplier<? extends Enchantment> key, String name) {
|
||||
this.add(key.get(), name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add.
|
||||
*
|
||||
* @param key the key
|
||||
* @param name the name
|
||||
*/
|
||||
public void add(@NotNull Enchantment key, String name) {
|
||||
this.add(key.getDescriptionId(), name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add effect.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -530,29 +530,29 @@ public abstract class AbstractFabricItem extends Item {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void appendHoverText(ItemStack stack, TooltipContext context, List<Component> tooltipComponents, TooltipFlag tooltipFlag) {
|
||||
super.appendHoverText(stack, context, tooltipComponents, tooltipFlag);
|
||||
public void appendHoverText(@NotNull ItemStack stack, @Nullable Level level,
|
||||
@NotNull List<Component> tooltip, @NotNull TooltipFlag flag) {
|
||||
super.appendHoverText(stack, level, tooltip, flag);
|
||||
|
||||
tooltipComponents.add(Component.literal("§7右键点击在 3 秒后执行"));
|
||||
tooltipComponents.add(Component.literal("§7§e准星瞄准生物§7的数据查询"));
|
||||
tooltipComponents.add(Component.literal("§7§oShift + 右键§7进行§e客户端-服务器双端同步检查§7"));
|
||||
tooltipComponents.add(Component.literal(""));
|
||||
tooltipComponents.add(Component.literal("§6查询延迟: §e3秒"));
|
||||
tooltipComponents.add(Component.literal("§6瞄准距离: §e20格"));
|
||||
tooltipComponents.add(Component.literal("§6冷却时间: §e1秒"));
|
||||
tooltipComponents.add(Component.literal(""));
|
||||
tooltipComponents.add(Component.literal("§a单端查询内容:"));
|
||||
tooltipComponents.add(Component.literal("§7- 基础数据字段"));
|
||||
tooltipComponents.add(Component.literal("§7- 自定义数据结构"));
|
||||
tooltipComponents.add(Component.literal("§7- 数据验证状态"));
|
||||
tooltipComponents.add(Component.literal("§7- 同步状态信息"));
|
||||
tooltipComponents.add(Component.literal(""));
|
||||
tooltipComponents.add(Component.literal("§e双端同步检查:"));
|
||||
tooltipComponents.add(Component.literal("§7- 客户端和服务器同时查询"));
|
||||
tooltipComponents.add(Component.literal("§7- 字段级同步状态对比"));
|
||||
tooltipComponents.add(Component.literal("§7- 总体同步率计算"));
|
||||
tooltipComponents.add(Component.literal("§7- 双端数据状态差异"));
|
||||
tooltipComponents.add(Component.literal("§7- 同步建议"));
|
||||
tooltip.add(Component.literal("§7右键点击在 3 秒后执行"));
|
||||
tooltip.add(Component.literal("§7§e准星瞄准生物§7的数据查询"));
|
||||
tooltip.add(Component.literal("§7§oShift + 右键§7进行§e客户端-服务器双端同步检查§7"));
|
||||
tooltip.add(Component.literal(""));
|
||||
tooltip.add(Component.literal("§6查询延迟: §e3秒"));
|
||||
tooltip.add(Component.literal("§6瞄准距离: §e20格"));
|
||||
tooltip.add(Component.literal("§6冷却时间: §e1秒"));
|
||||
tooltip.add(Component.literal(""));
|
||||
tooltip.add(Component.literal("§a单端查询内容:"));
|
||||
tooltip.add(Component.literal("§7- 基础数据字段"));
|
||||
tooltip.add(Component.literal("§7- 自定义数据结构"));
|
||||
tooltip.add(Component.literal("§7- 数据验证状态"));
|
||||
tooltip.add(Component.literal("§7- 同步状态信息"));
|
||||
tooltip.add(Component.literal(""));
|
||||
tooltip.add(Component.literal("§e双端同步检查:"));
|
||||
tooltip.add(Component.literal("§7- 客户端和服务器同时查询"));
|
||||
tooltip.add(Component.literal("§7- 字段级同步状态对比"));
|
||||
tooltip.add(Component.literal("§7- 总体同步率计算"));
|
||||
tooltip.add(Component.literal("§7- 双端数据状态差异"));
|
||||
tooltip.add(Component.literal("§7- 同步建议"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -268,27 +268,27 @@ public abstract class AbstractNeoForgeItem extends Item {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void appendHoverText(ItemStack stack, TooltipContext context, List<Component> tooltipComponents, TooltipFlag tooltipFlag) {
|
||||
super.appendHoverText(stack, context, tooltipComponents, tooltipFlag);
|
||||
public void appendHoverText(@NotNull ItemStack stack, @Nullable Level level,
|
||||
@NotNull List<Component> tooltip, @NotNull TooltipFlag flag) {
|
||||
super.appendHoverText(stack, level, tooltip, flag);
|
||||
|
||||
|
||||
tooltipComponents.add(Component.literal("§7右键点击触发§e准星瞄准生物§7的"));
|
||||
tooltipComponents.add(Component.literal("§7测试数据随机变换"));
|
||||
tooltipComponents.add(Component.literal("§7§oShift + 右键§7操作§e自身§7数据"));
|
||||
tooltipComponents.add(Component.literal(""));
|
||||
tooltipComponents.add(Component.literal("§6冷却时间: §e1秒"));
|
||||
tooltipComponents.add(Component.literal("§6瞄准距离: §e20格"));
|
||||
tooltipComponents.add(Component.literal(""));
|
||||
tooltipComponents.add(Component.literal("§a变换类型:"));
|
||||
tooltipComponents.add(Component.literal("§7- 完全随机数据"));
|
||||
tooltipComponents.add(Component.literal("§7- 字符串+计数器"));
|
||||
tooltipComponents.add(Component.literal("§7- 数值数据"));
|
||||
tooltipComponents.add(Component.literal("§7- 自定义数据"));
|
||||
tooltipComponents.add(Component.literal("§7- 重置默认值"));
|
||||
tooltipComponents.add(Component.literal("§7- 玩家专属数据"));
|
||||
tooltipComponents.add(Component.literal(""));
|
||||
tooltipComponents.add(Component.literal("§e自身操作特性:"));
|
||||
tooltipComponents.add(Component.literal("§7- 显示数据预览"));
|
||||
tooltipComponents.add(Component.literal("§7- 玩家专属数据变换"));
|
||||
tooltip.add(Component.literal("§7右键点击触发§e准星瞄准生物§7的"));
|
||||
tooltip.add(Component.literal("§7测试数据随机变换"));
|
||||
tooltip.add(Component.literal("§7§oShift + 右键§7操作§e自身§7数据"));
|
||||
tooltip.add(Component.literal(""));
|
||||
tooltip.add(Component.literal("§6冷却时间: §e1秒"));
|
||||
tooltip.add(Component.literal("§6瞄准距离: §e20格"));
|
||||
tooltip.add(Component.literal(""));
|
||||
tooltip.add(Component.literal("§a变换类型:"));
|
||||
tooltip.add(Component.literal("§7- 完全随机数据"));
|
||||
tooltip.add(Component.literal("§7- 字符串+计数器"));
|
||||
tooltip.add(Component.literal("§7- 数值数据"));
|
||||
tooltip.add(Component.literal("§7- 自定义数据"));
|
||||
tooltip.add(Component.literal("§7- 重置默认值"));
|
||||
tooltip.add(Component.literal("§7- 玩家专属数据"));
|
||||
tooltip.add(Component.literal(""));
|
||||
tooltip.add(Component.literal("§e自身操作特性:"));
|
||||
tooltip.add(Component.literal("§7- 显示数据预览"));
|
||||
tooltip.add(Component.literal("§7- 玩家专属数据变换"));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,27 +1,21 @@
|
|||
package top.r3944realms.lib39.mixin.carryon;
|
||||
|
||||
import com.llamalad7.mixinextras.sugar.Local;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.component.ResolvableProfile;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Pseudo;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyVariable;
|
||||
import top.r3944realms.lib39.content.item.DollItem;
|
||||
import top.r3944realms.lib39.util.GameProfileHelper;
|
||||
import top.r3944realms.lib39.util.nbt.NBTReader;
|
||||
import tschipp.carryon.client.render.CarriedObjectRender;
|
||||
import tschipp.carryon.common.carry.CarryOnDataManager;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
/**
|
||||
* The type Mixin carried object render.
|
||||
*/
|
||||
@SuppressWarnings("DuplicatedCode")
|
||||
@Pseudo
|
||||
@Mixin(value = CarriedObjectRender.class, remap = false)
|
||||
public class MixinCarriedObjectRender {
|
||||
|
|
@ -34,12 +28,8 @@ public class MixinCarriedObjectRender {
|
|||
)
|
||||
private static ItemStack warpDollItem$1(ItemStack stack, @Local(ordinal = 0, argsOnly = true) Player player) {
|
||||
if (stack.getItem() instanceof DollItem) {
|
||||
CompoundTag compound = CarryOnDataManager.getCarryData(player).getNbt().getCompound("tile");
|
||||
AtomicReference<GameProfile> gameProfileAtomicReference = new AtomicReference<>();
|
||||
NBTReader.of(compound).gameProfile("profile", gameProfileAtomicReference::set);
|
||||
if (gameProfileAtomicReference.get() != null) {
|
||||
GameProfileHelper.saveProfileToItemStack(stack, new ResolvableProfile(gameProfileAtomicReference.get()));
|
||||
}
|
||||
CompoundTag compound = CarryOnDataManager.getCarryData(player).getNbt().getCompound("tile").getCompound(GameProfileHelper.TAG_OWN_PROFILE);
|
||||
stack.getOrCreateTag().put(GameProfileHelper.TAG_OWN_PROFILE, compound);
|
||||
}
|
||||
return stack;
|
||||
}
|
||||
|
|
@ -50,16 +40,12 @@ public class MixinCarriedObjectRender {
|
|||
target = "Ltschipp/carryon/client/render/CarryRenderHelper;renderBakedModel(Lnet/minecraft/world/item/ItemStack;Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;ILnet/minecraft/client/resources/model/BakedModel;)V"
|
||||
)
|
||||
)
|
||||
private static ItemStack warpDollItem$2(ItemStack tileItem, @Local(ordinal = 0) Player player) {
|
||||
if (tileItem.getItem() instanceof DollItem) {
|
||||
CompoundTag compound = CarryOnDataManager.getCarryData(player).getNbt().getCompound("tile");
|
||||
AtomicReference<GameProfile> gameProfileAtomicReference = new AtomicReference<>();
|
||||
NBTReader.of(compound).gameProfile("profile", gameProfileAtomicReference::set);
|
||||
if (gameProfileAtomicReference.get() != null) {
|
||||
GameProfileHelper.saveProfileToItemStack(tileItem, new ResolvableProfile(gameProfileAtomicReference.get()));
|
||||
}
|
||||
private static ItemStack warpDollItem$2(ItemStack stack, @Local(ordinal = 0) Player player) {
|
||||
if (stack.getItem() instanceof DollItem) {
|
||||
CompoundTag compound = CarryOnDataManager.getCarryData(player).getNbt().getCompound("tile").getCompound(GameProfileHelper.TAG_OWN_PROFILE);
|
||||
stack.getOrCreateTag().put(GameProfileHelper.TAG_OWN_PROFILE, compound);
|
||||
}
|
||||
return tileItem;
|
||||
return stack;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
package top.r3944realms.lib39.platform.services;
|
||||
|
||||
import top.r3944realms.lib39.core.sync.SyncData2Manager;
|
||||
import top.r3944realms.lib39.util.block.BlockRegistryBuilder;
|
||||
|
||||
/**
|
||||
|
|
@ -13,6 +12,4 @@ public interface IUtilHelper {
|
|||
* @return the block registry builder
|
||||
*/
|
||||
BlockRegistryBuilder getBlockRegistryBuilder();
|
||||
|
||||
SyncData2Manager<?> getSyncData2Manager();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,81 +8,26 @@ import net.minecraft.client.Minecraft;
|
|||
import net.minecraft.client.multiplayer.PlayerInfo;
|
||||
import net.minecraft.client.player.AbstractClientPlayer;
|
||||
import net.minecraft.client.resources.DefaultPlayerSkin;
|
||||
import net.minecraft.core.component.DataComponents;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.NbtUtils;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.Services;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.component.ResolvableProfile;
|
||||
import net.minecraft.world.level.block.entity.SkullBlockEntity;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import top.r3944realms.lib39.Lib39;
|
||||
import top.r3944realms.lib39.util.nbt.NBTReader;
|
||||
import top.r3944realms.lib39.util.nbt.NBTWriter;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.Base64;
|
||||
import java.util.Collection;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
/**
|
||||
* The type GameProfile helper.
|
||||
*/
|
||||
public class GameProfileHelper {
|
||||
/**
|
||||
* 异步获取 GameProfile(通过玩家名)
|
||||
* 直接复用 SkullBlockEntity 的实现
|
||||
*/
|
||||
public static CompletableFuture<Optional<GameProfile>> fetchGameProfileByName(String name) {
|
||||
return SkullBlockEntity.fetchGameProfile(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* 异步获取 GameProfile(通过 UUID)
|
||||
* 直接复用 SkullBlockEntity 的实现
|
||||
*/
|
||||
public static CompletableFuture<Optional<GameProfile>> fetchGameProfileByUUID(UUID uuid) {
|
||||
return SkullBlockEntity.fetchGameProfile(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* 异步获取 GameProfile(自动识别类型)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> CompletableFuture<Optional<GameProfile>> fetchGameProfile(T identifier) {
|
||||
if (identifier instanceof UUID uuid) {
|
||||
return fetchGameProfileByUUID(uuid);
|
||||
} else if (identifier instanceof String name) {
|
||||
return fetchGameProfileByName(name);
|
||||
}
|
||||
return CompletableFuture.completedFuture(Optional.empty());
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 ItemStack 异步获取完整的 GameProfile
|
||||
* 需要配合 ResolvableProfile 使用
|
||||
*/
|
||||
public static CompletableFuture<Optional<GameProfile>> fetchProfileFromItemStack(@NotNull ItemStack stack) {
|
||||
ResolvableProfile resolvable = stack.get(DataComponents.PROFILE);
|
||||
if (resolvable == null) {
|
||||
return CompletableFuture.completedFuture(Optional.empty());
|
||||
}
|
||||
|
||||
// 如果已经有 UUID,直接用 SkullBlockEntity 的方法
|
||||
GameProfile profile = resolvable.gameProfile();
|
||||
if (profile != null && profile.getId() != null) {
|
||||
return fetchGameProfileByUUID(profile.getId());
|
||||
}
|
||||
|
||||
// 否则异步解析
|
||||
return resolvable.resolve().thenApply(resolved ->
|
||||
Optional.ofNullable(resolved.gameProfile())
|
||||
);
|
||||
}
|
||||
/**
|
||||
* Client Only Class
|
||||
*/
|
||||
|
|
@ -96,7 +41,7 @@ public class GameProfileHelper {
|
|||
public static @NotNull ResourceLocation resolveSkinTexture(@NotNull GameProfile gameProfile) {
|
||||
return IClientOnly.check(() ->
|
||||
Minecraft.getInstance().getSkinManager()
|
||||
.getInsecureSkin(gameProfile)).texture();
|
||||
.getInsecureSkinLocation(gameProfile));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -108,7 +53,7 @@ public class GameProfileHelper {
|
|||
public static ResourceLocation getSkinTexture(@Nullable GameProfile gameProfile) {
|
||||
return IClientOnly.check(() -> {
|
||||
if (gameProfile == null) {
|
||||
return Lib39.mrl("textures/entity/player/wide/steve.png");
|
||||
return DefaultPlayerSkin.getDefaultSkin();
|
||||
}
|
||||
return resolveSkinTexture(gameProfile);
|
||||
});
|
||||
|
|
@ -126,7 +71,7 @@ public class GameProfileHelper {
|
|||
PlayerInfo playerInfo = Objects.requireNonNull(Minecraft.getInstance()
|
||||
.getConnection())
|
||||
.getPlayerInfo(clientPlayer.getUUID());
|
||||
return playerInfo != null && "slim".equals(playerInfo.getSkin().model().id());
|
||||
return playerInfo != null && "slim".equals(playerInfo.getModelName());
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
|
@ -143,7 +88,7 @@ public class GameProfileHelper {
|
|||
if (player.level().isClientSide && player instanceof AbstractClientPlayer) {
|
||||
PlayerInfo info = Objects.requireNonNull(Minecraft.getInstance().getConnection())
|
||||
.getPlayerInfo(player.getUUID());
|
||||
return info != null ? info.getSkin().model().id() : "default";
|
||||
return info != null ? info.getModelName() : "default";
|
||||
}
|
||||
return "default";
|
||||
});
|
||||
|
|
@ -151,6 +96,10 @@ public class GameProfileHelper {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* The constant TAG_BE.
|
||||
*/
|
||||
public static final String TAG_BE = "BlockEntityTag";
|
||||
/**
|
||||
* The constant TAG_OWN_PROFILE.
|
||||
*/
|
||||
|
|
@ -201,7 +150,7 @@ public class GameProfileHelper {
|
|||
GameProfile profile = player.getGameProfile();
|
||||
for (Property property : profile.getProperties().get("textures")) {
|
||||
try {
|
||||
String json = new String(Base64.getDecoder().decode(property.value()));
|
||||
String json = new String(Base64.getDecoder().decode(property.getValue()));
|
||||
JsonObject obj = JsonParser.parseString(json).getAsJsonObject();
|
||||
JsonObject textures = obj.getAsJsonObject("textures");
|
||||
JsonObject skin = textures.getAsJsonObject("SKIN");
|
||||
|
|
@ -248,7 +197,7 @@ public class GameProfileHelper {
|
|||
|
||||
// 获取第一个texture属性(通常是皮肤)
|
||||
Property textureProperty = textures.iterator().next();
|
||||
String value = textureProperty.value();
|
||||
String value = textureProperty.getValue();
|
||||
|
||||
try {
|
||||
return isSlimFromTextureData(value);
|
||||
|
|
@ -319,7 +268,7 @@ public class GameProfileHelper {
|
|||
}
|
||||
|
||||
Property textureProperty = textures.iterator().next();
|
||||
String value = textureProperty.value();
|
||||
String value = textureProperty.getValue();
|
||||
|
||||
try {
|
||||
byte[] decodedBytes = Base64.getDecoder().decode(value);
|
||||
|
|
@ -342,37 +291,64 @@ public class GameProfileHelper {
|
|||
}
|
||||
|
||||
/**
|
||||
* 从ItemStack的组件中读取GameProfile
|
||||
* 从ItemStack的NBT中读取GameProfile
|
||||
*
|
||||
* @param stack the stack
|
||||
* @return the profile from item stack
|
||||
*/
|
||||
@Nullable
|
||||
public static ResolvableProfile getProfileFromItemStack(@NotNull ItemStack stack) {
|
||||
public static GameProfile getProfileFromItemStack(ItemStack stack) {
|
||||
if (stack.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (stack.isEmpty()) return null;
|
||||
|
||||
ResolvableProfile profile = stack.get(DataComponents.PROFILE);
|
||||
return profile != null ? profile : null;
|
||||
CompoundTag tag = stack.getTag();
|
||||
if (tag == null) {
|
||||
return null;
|
||||
}
|
||||
AtomicReference<GameProfile> profileRef = new AtomicReference<>();
|
||||
// 检查方块实体数据
|
||||
NBTReader.of(tag)
|
||||
.compound(TAG_BE, compoundTag ->
|
||||
NBTReader.of(compoundTag)
|
||||
.compound("OwnerProfile", ct -> profileRef.set(NbtUtils.readGameProfile(ct)))
|
||||
)
|
||||
.compound("OwnerProfile", ct -> {
|
||||
if (profileRef.get() == null) { //兼容写法
|
||||
profileRef.set(NbtUtils.readGameProfile(ct));
|
||||
}
|
||||
});
|
||||
return profileRef.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* 将GameProfile保存到ItemStack的组件
|
||||
* 将GameProfile保存到ItemStack的NBT
|
||||
*
|
||||
* @param stack the stack
|
||||
* @param profile the profile
|
||||
*/
|
||||
public static void saveProfileToItemStack(@NotNull ItemStack stack, @Nullable ResolvableProfile profile) {
|
||||
if (stack.isEmpty()) return;
|
||||
public static void saveProfileToItemStack(@NotNull ItemStack stack, @Nullable GameProfile profile) {
|
||||
if (stack.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
CompoundTag tag = stack.getOrCreateTag();
|
||||
|
||||
if (profile == null) {
|
||||
stack.remove(DataComponents.PROFILE);
|
||||
} else {
|
||||
stack.set(DataComponents.PROFILE, profile);
|
||||
// 移除现有数据
|
||||
NBTReader.of(tag)
|
||||
.compound(TAG_BE, ct -> tag.remove(TAG_OWN_PROFILE));
|
||||
tag.remove(TAG_BE);
|
||||
tag.remove(TAG_OWN_PROFILE);
|
||||
return;
|
||||
}
|
||||
|
||||
// 创建方块实体数据
|
||||
NBTWriter.of(tag)
|
||||
.compound(TAG_BE, writer ->
|
||||
writer
|
||||
.compound(TAG_OWN_PROFILE, NbtUtils.writeGameProfile(new CompoundTag(), profile))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -386,7 +362,17 @@ public class GameProfileHelper {
|
|||
return false;
|
||||
}
|
||||
|
||||
return !stack.isEmpty() && stack.has(DataComponents.PROFILE);
|
||||
CompoundTag tag = stack.getTag();
|
||||
if (tag == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (tag.contains(TAG_BE)) {
|
||||
CompoundTag blockEntityTag = tag.getCompound(TAG_BE);
|
||||
return blockEntityTag.contains(TAG_OWN_PROFILE);
|
||||
}
|
||||
|
||||
return tag.contains(TAG_OWN_PROFILE);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,8 +15,6 @@
|
|||
|
||||
package top.r3944realms.lib39.util.nbt;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
|
@ -380,123 +378,6 @@ public class NBTReader {
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Game profile nbt reader.
|
||||
*
|
||||
* @param key the key
|
||||
* @param setter the setter
|
||||
* @return the nbt reader
|
||||
*/
|
||||
public NBTReader gameProfile(String key, Consumer<GameProfile> setter) {
|
||||
if (nbt.contains(key, CompoundTag.TAG_COMPOUND)) {
|
||||
CompoundTag tag = nbt.getCompound(key);
|
||||
GameProfile profile = readGameProfileFromTag(tag);
|
||||
if (profile != null) {
|
||||
setter.accept(profile);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Game profile nbt reader with default value.
|
||||
*
|
||||
* @param key the key
|
||||
* @param setter the setter
|
||||
* @param defaultValue the default value
|
||||
* @return the nbt reader
|
||||
*/
|
||||
public NBTReader gameProfile(String key, Consumer<GameProfile> setter, GameProfile defaultValue) {
|
||||
if (nbt.contains(key, CompoundTag.TAG_COMPOUND)) {
|
||||
CompoundTag tag = nbt.getCompound(key);
|
||||
GameProfile profile = readGameProfileFromTag(tag);
|
||||
if (profile != null) {
|
||||
setter.accept(profile);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
setter.accept(defaultValue);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read GameProfile from CompoundTag.
|
||||
*
|
||||
* @param tag the tag
|
||||
* @return the game profile, or null if invalid
|
||||
*/
|
||||
@Nullable
|
||||
private static GameProfile readGameProfileFromTag(@NotNull CompoundTag tag) {
|
||||
String name = null;
|
||||
UUID uuid = null;
|
||||
|
||||
// 支持 "Name" 或 "name"
|
||||
if (tag.contains("Name", CompoundTag.TAG_STRING)) {
|
||||
name = tag.getString("Name");
|
||||
} else if (tag.contains("name", CompoundTag.TAG_STRING)) {
|
||||
name = tag.getString("name");
|
||||
}
|
||||
|
||||
// 支持 "Id" 或 "id"
|
||||
if (tag.hasUUID("Id")) {
|
||||
uuid = tag.getUUID("Id");
|
||||
} else if (tag.hasUUID("id")) {
|
||||
uuid = tag.getUUID("id");
|
||||
}
|
||||
|
||||
try {
|
||||
GameProfile profile = new GameProfile(uuid, name);
|
||||
|
||||
// 支持 "Properties" 或 "properties",支持 COMPOUND 或 LIST 格式
|
||||
String propertiesKey = tag.contains("Properties", CompoundTag.TAG_COMPOUND) ? "Properties"
|
||||
: (tag.contains("properties", CompoundTag.TAG_COMPOUND) ? "properties" : null);
|
||||
|
||||
// 如果没有 COMPOUND,尝试 LIST 格式
|
||||
if (propertiesKey == null) {
|
||||
String listKey = tag.contains("Properties", CompoundTag.TAG_LIST) ? "Properties"
|
||||
: (tag.contains("properties", CompoundTag.TAG_LIST) ? "properties" : null);
|
||||
if (listKey != null) {
|
||||
ListTag propertiesList = tag.getList(listKey, CompoundTag.TAG_COMPOUND);
|
||||
for (int i = 0; i < propertiesList.size(); i++) {
|
||||
CompoundTag propTag = propertiesList.getCompound(i);
|
||||
String propName = propTag.getString("name");
|
||||
String value = propTag.getString("value");
|
||||
String signature = propTag.contains("signature") ? propTag.getString("signature") : null;
|
||||
|
||||
if (signature != null) {
|
||||
profile.getProperties().put(propName, new Property(propName, value, signature));
|
||||
} else {
|
||||
profile.getProperties().put(propName, new Property(propName, value));
|
||||
}
|
||||
}
|
||||
return profile;
|
||||
}
|
||||
}
|
||||
|
||||
// COMPOUND 格式处理
|
||||
if (propertiesKey != null && tag.contains(propertiesKey, CompoundTag.TAG_COMPOUND)) {
|
||||
CompoundTag propertiesTag = tag.getCompound(propertiesKey);
|
||||
for (String key : propertiesTag.getAllKeys()) {
|
||||
ListTag listTag = propertiesTag.getList(key, CompoundTag.TAG_COMPOUND);
|
||||
for (int i = 0; i < listTag.size(); i++) {
|
||||
CompoundTag propTag = listTag.getCompound(i);
|
||||
String value = propTag.getString("Value");
|
||||
String signature = propTag.contains("Signature") ? propTag.getString("Signature") : null;
|
||||
if (signature != null) {
|
||||
profile.getProperties().put(key, new Property(key, value, signature));
|
||||
} else {
|
||||
profile.getProperties().put(key, new Property(key, value));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return profile;
|
||||
} catch (Throwable e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Vec 3 nbt reader.
|
||||
*
|
||||
|
|
@ -588,7 +469,6 @@ public class NBTReader {
|
|||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Nested nbt reader.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1,8 +1,5 @@
|
|||
package top.r3944realms.lib39.util.nbt;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import io.netty.util.internal.StringUtil;
|
||||
import net.minecraft.nbt.*;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
|
|
@ -565,6 +562,7 @@ public class NBTWriter {
|
|||
* @param tag the tag
|
||||
* @return the nbt writer
|
||||
*/
|
||||
// 直接操作Tag
|
||||
public NBTWriter tag(String key, Tag tag) {
|
||||
if (tag != null) {
|
||||
root.put(key, tag);
|
||||
|
|
@ -572,60 +570,6 @@ public class NBTWriter {
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Game profile nbt writer.
|
||||
*
|
||||
* @param key the key
|
||||
* @param profile the profile
|
||||
* @return the nbt writer
|
||||
*/
|
||||
public NBTWriter gameProfile(String key, @NotNull GameProfile profile) {
|
||||
root.put(key, writeGameProfile(profile));
|
||||
return this;
|
||||
}
|
||||
|
||||
private CompoundTag writeGameProfile(@NotNull GameProfile profile) {
|
||||
CompoundTag tag = new CompoundTag();
|
||||
if (!StringUtil.isNullOrEmpty(profile.getName())) {
|
||||
tag.putString("Name", profile.getName());
|
||||
}
|
||||
if (profile.getId() != null) {
|
||||
tag.putUUID("Id", profile.getId());
|
||||
}
|
||||
if (!profile.getProperties().isEmpty()) {
|
||||
CompoundTag compoundTag = new CompoundTag();
|
||||
for(String keySet : profile.getProperties().keySet()) {
|
||||
ListTag propListTag = new ListTag();
|
||||
for(Property property : profile.getProperties().get(keySet)) {
|
||||
CompoundTag propTag = new CompoundTag();
|
||||
propTag.putString("Value", property.value());
|
||||
if (property.hasSignature()) {
|
||||
propTag.putString("Signature", property.signature());
|
||||
}
|
||||
propListTag.add(propTag);
|
||||
}
|
||||
compoundTag.put(keySet, propListTag);
|
||||
}
|
||||
tag.put("Properties", compoundTag);
|
||||
}
|
||||
return tag;
|
||||
}
|
||||
|
||||
/**
|
||||
* GameProfile if nbt writer.
|
||||
*
|
||||
* @param key the key
|
||||
* @param condition the condition
|
||||
* @param value the value
|
||||
* @return the nbt writer
|
||||
*/
|
||||
public NBTWriter gameProfileIf(String key, boolean condition, Supplier<GameProfile> value) {
|
||||
if (condition && value != null) {
|
||||
root.put(key, writeGameProfile(value.get()));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* String if nbt writer.
|
||||
*
|
||||
|
|
@ -634,6 +578,7 @@ public class NBTWriter {
|
|||
* @param value the value
|
||||
* @return the nbt writer
|
||||
*/
|
||||
// 条件添加方法
|
||||
public NBTWriter stringIf(String key, boolean condition, Supplier<String> value) {
|
||||
if (condition && value != null) {
|
||||
root.putString(key, value.get());
|
||||
|
|
|
|||
|
|
@ -2,15 +2,9 @@ package top.r3944realms.lib39.util.villager;
|
|||
|
||||
import com.google.common.collect.Lists;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.component.DataComponents;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.tags.EnchantmentTags;
|
||||
import net.minecraft.tags.ItemTags;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.util.RandomSource;
|
||||
|
|
@ -22,18 +16,15 @@ import net.minecraft.world.entity.npc.VillagerType;
|
|||
import net.minecraft.world.item.*;
|
||||
import net.minecraft.world.item.alchemy.Potion;
|
||||
import net.minecraft.world.item.alchemy.PotionBrewing;
|
||||
import net.minecraft.world.item.alchemy.PotionContents;
|
||||
import net.minecraft.world.item.component.DyedItemColor;
|
||||
import net.minecraft.world.item.component.SuspiciousStewEffects;
|
||||
import net.minecraft.world.item.alchemy.PotionUtils;
|
||||
import net.minecraft.world.item.enchantment.Enchantment;
|
||||
import net.minecraft.world.item.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.world.item.enchantment.EnchantmentInstance;
|
||||
import net.minecraft.world.item.trading.ItemCost;
|
||||
import net.minecraft.world.item.trading.MerchantOffer;
|
||||
import net.minecraft.world.level.ItemLike;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.levelgen.structure.Structure;
|
||||
import net.minecraft.world.level.saveddata.maps.MapDecorationType;
|
||||
import net.minecraft.world.level.saveddata.maps.MapDecoration;
|
||||
import net.minecraft.world.level.saveddata.maps.MapItemSavedData;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
|
@ -41,8 +32,6 @@ import org.jetbrains.annotations.Nullable;
|
|||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 村民交易构建器
|
||||
|
|
@ -127,21 +116,20 @@ public class TradeBuilder {
|
|||
/**
|
||||
* 创建宝藏地图交易
|
||||
*
|
||||
* @param emeraldCost 绿宝石价格
|
||||
* @param destination the destination
|
||||
* @param displayName 显示名称
|
||||
* @param destinationType the destination type
|
||||
* @param maxUses 最大使用次数
|
||||
* @param villagerXp 村民获得的经验
|
||||
* @param emeraldCost 绿宝石价格
|
||||
* @param destination the destination
|
||||
* @param displayName 显示名称
|
||||
* @param destinationTyp the destination typ
|
||||
* @param maxUses 最大使用次数
|
||||
* @param villagerXp 村民获得的经验
|
||||
* @return 交易实例 treasure map for emeralds
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
public static @NotNull TreasureMapForEmeralds createTreasureMapTrade(
|
||||
int emeraldCost, TagKey<Structure> destination, String displayName,
|
||||
Holder<MapDecorationType> destinationType, int maxUses, int villagerXp) {
|
||||
return new TreasureMapForEmeralds(emeraldCost, destination, displayName, destinationType, maxUses, villagerXp);
|
||||
}
|
||||
int emeraldCost, TagKey<Structure> destination, String displayName, MapDecoration.Type destinationTyp, int maxUses, int villagerXp) {
|
||||
|
||||
return new TreasureMapForEmeralds(emeraldCost, destination, displayName, destinationTyp, maxUses, villagerXp);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建染色盔甲交易
|
||||
|
|
@ -185,8 +173,8 @@ public class TradeBuilder {
|
|||
}
|
||||
|
||||
public MerchantOffer getOffer(@NotNull Entity trader, @NotNull RandomSource random) {
|
||||
ItemCost itemCost = new ItemCost(this.item, this.cost);
|
||||
return new MerchantOffer(itemCost, new ItemStack(Items.EMERALD), this.maxUses, this.villagerXp, this.priceMultiplier);
|
||||
ItemStack itemstack = new ItemStack(this.item, this.cost);
|
||||
return new MerchantOffer(itemstack, new ItemStack(Items.EMERALD), this.maxUses, this.villagerXp, this.priceMultiplier);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -272,7 +260,7 @@ public class TradeBuilder {
|
|||
}
|
||||
|
||||
public MerchantOffer getOffer(@NotNull Entity trader, @NotNull RandomSource random) {
|
||||
return new MerchantOffer(new ItemCost(Items.EMERALD, this.emeraldCost), new ItemStack(this.itemStack.getItem(), this.numberOfItems), this.maxUses, this.villagerXp, this.priceMultiplier);
|
||||
return new MerchantOffer(new ItemStack(Items.EMERALD, this.emeraldCost), new ItemStack(this.itemStack.getItem(), this.numberOfItems), this.maxUses, this.villagerXp, this.priceMultiplier);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -283,7 +271,7 @@ public class TradeBuilder {
|
|||
/**
|
||||
* The Effect.
|
||||
*/
|
||||
private final Holder<MobEffect> effect;
|
||||
final MobEffect effect;
|
||||
/**
|
||||
* The Duration.
|
||||
*/
|
||||
|
|
@ -301,7 +289,7 @@ public class TradeBuilder {
|
|||
* @param duration the duration
|
||||
* @param xp the xp
|
||||
*/
|
||||
public SuspiciousStewForEmerald(Holder<MobEffect> effect, int duration, int xp) {
|
||||
public SuspiciousStewForEmerald(MobEffect effect, int duration, int xp) {
|
||||
this.effect = effect;
|
||||
this.duration = duration;
|
||||
this.xp = xp;
|
||||
|
|
@ -311,9 +299,8 @@ public class TradeBuilder {
|
|||
@Nullable
|
||||
public MerchantOffer getOffer(@NotNull Entity trader, @NotNull RandomSource random) {
|
||||
ItemStack itemstack = new ItemStack(Items.SUSPICIOUS_STEW, 1);
|
||||
itemstack.set(DataComponents.SUSPICIOUS_STEW_EFFECTS,
|
||||
new SuspiciousStewEffects(List.of(new SuspiciousStewEffects.Entry(effect, this.duration))));
|
||||
return new MerchantOffer(new ItemCost(Items.EMERALD, 1), itemstack, 12, this.xp, this.priceMultiplier);
|
||||
SuspiciousStewItem.saveMobEffect(itemstack, this.effect, this.duration);
|
||||
return new MerchantOffer(new ItemStack(Items.EMERALD, 1), itemstack, 12, this.xp, this.priceMultiplier);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -368,7 +355,7 @@ public class TradeBuilder {
|
|||
|
||||
@Nullable
|
||||
public MerchantOffer getOffer(@NotNull Entity trader, @NotNull RandomSource random) {
|
||||
return new MerchantOffer(new ItemCost(Items.EMERALD, this.emeraldCost), Optional.of(new ItemCost(this.fromItem.getItem(), this.fromCount)), new ItemStack(this.toItem.getItem(), this.toCount), this.maxUses, this.villagerXp, this.priceMultiplier);
|
||||
return new MerchantOffer(new ItemStack(Items.EMERALD, this.emeraldCost), new ItemStack(this.fromItem.getItem(), this.fromCount), new ItemStack(this.toItem.getItem(), this.toCount), this.maxUses, this.villagerXp, this.priceMultiplier);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -413,10 +400,9 @@ public class TradeBuilder {
|
|||
|
||||
public MerchantOffer getOffer(@NotNull Entity trader, @NotNull RandomSource random) {
|
||||
int i = 5 + random.nextInt(15);
|
||||
ItemStack itemstack = EnchantmentHelper.enchantItem(random, new ItemStack(this.itemStack.getItem()), i ,
|
||||
trader.level().registryAccess(), Optional.empty());
|
||||
ItemStack itemstack = EnchantmentHelper.enchantItem(random, new ItemStack(this.itemStack.getItem()), i, false);
|
||||
int j = Math.min(this.baseEmeraldCost + i, 64);
|
||||
ItemCost itemstack1 = new ItemCost(Items.EMERALD, j);
|
||||
ItemStack itemstack1 = new ItemStack(Items.EMERALD, j);
|
||||
return new MerchantOffer(itemstack1, itemstack, this.maxUses, this.villagerXp, this.priceMultiplier);
|
||||
}
|
||||
}
|
||||
|
|
@ -453,8 +439,8 @@ public class TradeBuilder {
|
|||
@Nullable
|
||||
public MerchantOffer getOffer(@NotNull Entity trader, @NotNull RandomSource random) {
|
||||
if (trader instanceof VillagerDataHolder) {
|
||||
ItemCost itemCost = new ItemCost(this.trades.get(((VillagerDataHolder)trader).getVillagerData().getType()), this.cost);
|
||||
return new MerchantOffer(itemCost, new ItemStack(Items.EMERALD), this.maxUses, this.villagerXp, 0.05F);
|
||||
ItemStack itemstack = new ItemStack(this.trades.get(((VillagerDataHolder)trader).getVillagerData().getType()), this.cost);
|
||||
return new MerchantOffer(itemstack, new ItemStack(Items.EMERALD), this.maxUses, this.villagerXp, 0.05F);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
|
@ -498,15 +484,11 @@ public class TradeBuilder {
|
|||
}
|
||||
|
||||
public MerchantOffer getOffer(@NotNull Entity trader, @NotNull RandomSource random) {
|
||||
ItemCost itemcost = new ItemCost(Items.EMERALD, this.emeraldCost);
|
||||
List<? extends Holder<Potion>> brewablePotions = BuiltInRegistries.POTION.holders()
|
||||
.filter(potion -> !potion.value().getEffects().isEmpty())
|
||||
.filter(trader.level().potionBrewing()::isBrewablePotion)
|
||||
.toList();
|
||||
Holder<Potion> potion = brewablePotions.get(random.nextInt(brewablePotions.size()));
|
||||
ItemStack itemstack = new ItemStack(this.toItem.getItem(), this.toCount);
|
||||
itemstack.set(DataComponents.POTION_CONTENTS, new PotionContents(potion));
|
||||
return new MerchantOffer(itemcost, Optional.of(new ItemCost(this.fromItem, this.fromCount)), itemstack, this.maxUses, this.villagerXp, this.priceMultiplier);
|
||||
ItemStack itemstack = new ItemStack(Items.EMERALD, this.emeraldCost);
|
||||
List<Potion> list = BuiltInRegistries.POTION.stream().filter((effects) -> !effects.getEffects().isEmpty() && PotionBrewing.isBrewablePotion(effects)).toList();
|
||||
Potion potion = list.get(random.nextInt(list.size()));
|
||||
ItemStack itemstack1 = PotionUtils.setPotion(new ItemStack(this.toItem.getItem(), this.toCount), potion);
|
||||
return new MerchantOffer(itemstack, new ItemStack(this.fromItem, this.fromCount), itemstack1, this.maxUses, this.villagerXp, this.priceMultiplier);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -527,17 +509,12 @@ public class TradeBuilder {
|
|||
}
|
||||
|
||||
public MerchantOffer getOffer(@NotNull Entity trader, @NotNull RandomSource random) {
|
||||
Registry<Enchantment> registry = trader.level().registryAccess().registryOrThrow(Registries.ENCHANTMENT);
|
||||
List<? extends Holder<Enchantment>> list = registry.holders()
|
||||
.filter(holder -> holder.is(EnchantmentTags.TRADEABLE))
|
||||
.toList();
|
||||
Holder<Enchantment> holder = list.get(random.nextInt(list.size()));
|
||||
Enchantment enchantment = holder.value();
|
||||
List<Enchantment> list = BuiltInRegistries.ENCHANTMENT.stream().filter(Enchantment::isTradeable).toList();
|
||||
Enchantment enchantment = list.get(random.nextInt(list.size()));
|
||||
int i = Mth.nextInt(random, enchantment.getMinLevel(), enchantment.getMaxLevel());
|
||||
ItemStack itemstack = EnchantedBookItem.createForEnchantment(new EnchantmentInstance(holder, i));
|
||||
ItemStack itemstack = EnchantedBookItem.createForEnchantment(new EnchantmentInstance(enchantment, i));
|
||||
int j = 2 + random.nextInt(5 + i * 10) + 3 * i;
|
||||
|
||||
if (holder.is(EnchantmentTags.DOUBLE_TRADE_PRICE)) {
|
||||
if (enchantment.isTreasureOnly()) {
|
||||
j *= 2;
|
||||
}
|
||||
|
||||
|
|
@ -545,7 +522,7 @@ public class TradeBuilder {
|
|||
j = 64;
|
||||
}
|
||||
|
||||
return new MerchantOffer(new ItemCost(Items.EMERALD, j), Optional.of(new ItemCost(Items.BOOK)), itemstack, 12, this.villagerXp, 0.2F);
|
||||
return new MerchantOffer(new ItemStack(Items.EMERALD, j), new ItemStack(Items.BOOK), itemstack, 12, this.villagerXp, 0.2F);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -556,7 +533,7 @@ public class TradeBuilder {
|
|||
private final int emeraldCost;
|
||||
private final TagKey<Structure> destination;
|
||||
private final String displayName;
|
||||
private final Holder<MapDecorationType> destinationType;
|
||||
private final MapDecoration.Type destinationType;
|
||||
private final int maxUses;
|
||||
private final int villagerXp;
|
||||
|
||||
|
|
@ -570,7 +547,7 @@ public class TradeBuilder {
|
|||
* @param maxUses the max uses
|
||||
* @param villagerXp the villager xp
|
||||
*/
|
||||
public TreasureMapForEmeralds(int emeraldCost, TagKey<Structure> destination, String displayName, Holder<MapDecorationType> destinationType, int maxUses, int villagerXp) {
|
||||
public TreasureMapForEmeralds(int emeraldCost, TagKey<Structure> destination, String displayName, MapDecoration.Type destinationType, int maxUses, int villagerXp) {
|
||||
this.emeraldCost = emeraldCost;
|
||||
this.destination = destination;
|
||||
this.displayName = displayName;
|
||||
|
|
@ -589,10 +566,8 @@ public class TradeBuilder {
|
|||
ItemStack itemstack = MapItem.create(serverlevel, blockpos.getX(), blockpos.getZ(), (byte)2, true, true);
|
||||
MapItem.renderBiomePreviewMap(serverlevel, itemstack);
|
||||
MapItemSavedData.addTargetDecoration(itemstack, blockpos, "+", this.destinationType);
|
||||
MapItemSavedData.addTargetDecoration(itemstack, blockpos, "+", this.destinationType);
|
||||
itemstack.set(DataComponents.ITEM_NAME, Component.translatable(this.displayName));
|
||||
return new MerchantOffer(new ItemCost(Items.EMERALD, this.emeraldCost),
|
||||
Optional.of(new ItemCost(Items.COMPASS)), itemstack, this.maxUses, this.villagerXp, 0.2F);
|
||||
itemstack.setHoverName(Component.translatable(this.displayName));
|
||||
return new MerchantOffer(new ItemStack(Items.EMERALD, this.emeraldCost), new ItemStack(Items.COMPASS), itemstack, this.maxUses, this.villagerXp, 0.2F);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
|
@ -635,23 +610,23 @@ public class TradeBuilder {
|
|||
}
|
||||
|
||||
public MerchantOffer getOffer(@NotNull Entity trader, @NotNull RandomSource random) {
|
||||
ItemCost itemCost = new ItemCost(Items.EMERALD, this.value);
|
||||
ItemStack armorStack = new ItemStack(this.item);
|
||||
|
||||
if (armorStack.is(ItemTags.DYEABLE)) {
|
||||
List<DyeItem> dyes = Lists.newArrayList();
|
||||
dyes.add(getRandomDye(random));
|
||||
ItemStack itemstack = new ItemStack(Items.EMERALD, this.value);
|
||||
ItemStack itemstack1 = new ItemStack(this.item);
|
||||
if (this.item instanceof DyeableArmorItem) {
|
||||
List<DyeItem> list = Lists.newArrayList();
|
||||
list.add(getRandomDye(random));
|
||||
if (random.nextFloat() > 0.7F) {
|
||||
dyes.add(getRandomDye(random));
|
||||
list.add(getRandomDye(random));
|
||||
}
|
||||
|
||||
if (random.nextFloat() > 0.8F) {
|
||||
dyes.add(getRandomDye(random));
|
||||
list.add(getRandomDye(random));
|
||||
}
|
||||
// 1.21.1: 使用 DYED_COLOR 组件设置颜色
|
||||
armorStack = DyedItemColor.applyDyes(armorStack, dyes);
|
||||
|
||||
itemstack1 = DyeableLeatherItem.dyeArmor(itemstack1, list);
|
||||
}
|
||||
|
||||
return new MerchantOffer(itemCost, armorStack, this.maxUses, this.villagerXp, 0.2F);
|
||||
return new MerchantOffer(itemstack, itemstack1, this.maxUses, this.villagerXp, 0.2F);
|
||||
}
|
||||
|
||||
private static @NotNull DyeItem getRandomDye(@NotNull RandomSource random) {
|
||||
|
|
|
|||
|
|
@ -16,7 +16,9 @@ void main() {
|
|||
|
||||
// 确保内外半径合理
|
||||
if (OuterRadius <= InnerRadius) {
|
||||
discard; // ✅ 直接丢弃片段,不需要设置颜色
|
||||
vec4 color = vertexColor;
|
||||
color.a = 0;
|
||||
fragColor = color;
|
||||
}
|
||||
|
||||
// 计算环形 alpha
|
||||
|
|
@ -26,20 +28,20 @@ void main() {
|
|||
// 内边缘抗锯齿
|
||||
if (dist < InnerRadius + AntiAliasing) {
|
||||
float fade = (dist - InnerRadius) / AntiAliasing;
|
||||
alpha *= clamp(fade, 0.0, 1.0); // ✅ 确保值在 [0,1] 范围内
|
||||
alpha *= fade;
|
||||
}
|
||||
|
||||
// 外边缘抗锯齿
|
||||
if (dist > OuterRadius - AntiAliasing) {
|
||||
float fade = 1.0 - (dist - (OuterRadius - AntiAliasing)) / AntiAliasing;
|
||||
alpha *= clamp(fade, 0.0, 1.0); // ✅ 确保值在 [0,1] 范围内
|
||||
alpha *= fade;
|
||||
}
|
||||
}
|
||||
|
||||
vec4 color = vertexColor;
|
||||
color.a = color.a * alpha; // ✅ 修正语法
|
||||
color.a *= alpha;
|
||||
|
||||
if (color.a > 0.0) {
|
||||
if (alpha > 0.0) {
|
||||
fragColor = color * ColorModulator;
|
||||
} else {
|
||||
discard;
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ uniform vec4 ColorModulator;
|
|||
uniform vec2 FramebufferSize;
|
||||
uniform vec2 Center;
|
||||
uniform float Radius;
|
||||
uniform float AntiAliasingRadius;
|
||||
|
||||
out vec4 fragColor;
|
||||
|
||||
|
|
|
|||
|
|
@ -32,6 +32,14 @@
|
|||
"values": [
|
||||
0.0
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "AntiAliasingRadius",
|
||||
"type": "float",
|
||||
"count": 1,
|
||||
"values": [
|
||||
1.5
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -3,10 +3,9 @@
|
|||
"minVersion": "0.8",
|
||||
"package": "top.r3944realms.lib39.mixin",
|
||||
"refmap": "${mod_id}.refmap.json",
|
||||
"compatibilityLevel": "JAVA_21",
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"mixins": [
|
||||
"carryon.MixinCarriedObjectRender",
|
||||
"minecraft.MixinEntity",
|
||||
"minecraft.CreativeModeTabsAccessor"
|
||||
],
|
||||
"client": [
|
||||
|
|
|
|||
|
|
@ -1,20 +1,26 @@
|
|||
import net.fabricmc.loom.task.RemapJarTask
|
||||
|
||||
plugins {
|
||||
id 'multiloader-loader'
|
||||
id 'fabric-loom'
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven { url 'https://maven.covers1624.net/' }
|
||||
}
|
||||
dependencies {
|
||||
minecraft "com.mojang:minecraft:${minecraft_version}"
|
||||
mappings loom.layered {
|
||||
officialMojangMappings()
|
||||
parchment("org.parchmentmc.data:parchment-${parchment_minecraft}:${parchment_version}@zip")
|
||||
}
|
||||
modImplementation(group: 'tschipp.carryon', name: 'carryon-fabric-1.21.1', version: '2.2.4.4') {
|
||||
modImplementation(group: 'tschipp.carryon', name: 'carryon-fabric-1.20.1', version: '2.1.2.7') {
|
||||
transitive = false
|
||||
}
|
||||
modImplementation "net.fabricmc:fabric-loader:${fabric_loader_version}"
|
||||
modImplementation "net.fabricmc.fabric-api:fabric-api:${fabric_version}"
|
||||
modImplementation "curse.maven:jade-324717:7545228"
|
||||
implementation group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.1'
|
||||
implementation project(":common")
|
||||
modImplementation "curse.maven:jade-324717:6291330"
|
||||
testImplementation "net.fabricmc:fabric-loader-junit:${fabric_loader_version}"
|
||||
localRuntime 'net.covers1624:DevLogin:0.1.0.5'
|
||||
}
|
||||
|
|
@ -30,7 +36,7 @@ loom {
|
|||
accessWidenerPath.set(project(":common").file("src/main/resources/${mod_id}.accesswidener"))
|
||||
}
|
||||
mixin {
|
||||
defaultRefmapName.set("${mod_id}.fabric.refmap.json")
|
||||
defaultRefmapName.set("${mod_id}.refmap.json")
|
||||
}
|
||||
runs {
|
||||
client {
|
||||
|
|
@ -96,7 +102,7 @@ tasks.named('javadoc', Javadoc) {
|
|||
classpath += project(':common').sourceSets.main.compileClasspath
|
||||
options.encoding = 'UTF-8'
|
||||
options.charSet = 'UTF-8'
|
||||
options.links("https://docs.oracle.com/en/java/javase/21/docs/api/")
|
||||
options.links("https://docs.oracle.com/en/java/javase/17/docs/api/")
|
||||
options.memberLevel = JavadocMemberLevel.PUBLIC
|
||||
options.addBooleanOption('Xdoclint:none', true)
|
||||
options.addStringOption('doctitle', "${mod_id} ${minecraft_version} ${version} Javadoc")
|
||||
|
|
@ -130,6 +136,13 @@ remapSourcesJar {
|
|||
inputFile.set(tasks.named('sourcesJar').get().archiveFile)
|
||||
}
|
||||
|
||||
// 为javadocJar创建remap任务
|
||||
tasks.register('remapJavadocJar', RemapJarTask) {
|
||||
dependsOn tasks.named('javadocJar')
|
||||
inputFile.set(tasks.named('javadocJar').get().archiveFile)
|
||||
archiveClassifier.set('javadoc')
|
||||
addNestedDependencies = false
|
||||
}
|
||||
|
||||
// 将remapped artifacts添加到发布配置
|
||||
publishing {
|
||||
|
|
@ -146,20 +159,61 @@ publishing {
|
|||
builtBy remapSourcesJar
|
||||
classifier = 'sources'
|
||||
}
|
||||
artifact(javadocJar) {
|
||||
builtBy javadocJar
|
||||
artifact(remapJavadocJar) {
|
||||
builtBy remapJavadocJar
|
||||
classifier = 'javadoc'
|
||||
}
|
||||
pom {
|
||||
name = 'Lib39'
|
||||
description = 'Lib39 is a general-purpose dependency library for Minecraft mods.'
|
||||
url = 'https://github.com/3944Realms/lib39'
|
||||
|
||||
properties = [
|
||||
'minecraft.version': project.minecraft_version,
|
||||
'mod.version': project.version,
|
||||
'fabric.version': project.fabric_version,
|
||||
'java.version': '17'
|
||||
]
|
||||
|
||||
licenses {
|
||||
license {
|
||||
name = 'MIT'
|
||||
url = 'https://raw.githubusercontent.com/3944Realms/lib39/refs/heads/main/LICENSE'
|
||||
distribution = 'repo'
|
||||
}
|
||||
}
|
||||
|
||||
developers {
|
||||
developer {
|
||||
id = 'R3944Realms'
|
||||
name = "${mod_author}"
|
||||
email = 'f256198830@hotmail.com'
|
||||
}
|
||||
}
|
||||
|
||||
scm {
|
||||
connection = 'scm:git:https://github.com/3944Realms/lib39.git'
|
||||
developerConnection = 'scm:git:ssh://git@github.com:3944Realms/lib39.git'
|
||||
url = 'https://github.com/3944Realms/lib39'
|
||||
tag = 'main'
|
||||
}
|
||||
|
||||
issueManagement {
|
||||
system = 'GitHub'
|
||||
url = 'https://github.com/3944Realms/lib39/issues'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
test {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
||||
tasks.named('generateMetadataFileForMavenJavaPublication') {
|
||||
dependsOn tasks.named('remapJar')
|
||||
dependsOn tasks.named('remapSourcesJar')
|
||||
dependsOn tasks.named('javadocJar')
|
||||
}
|
||||
}
|
||||
test {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
||||
tasks.named('generateMetadataFileForMavenJavaPublication') {
|
||||
dependsOn tasks.named('remapJavadocJar')
|
||||
dependsOn tasks.named('remapJar')
|
||||
dependsOn tasks.named('remapSourcesJar')
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,13 +1,11 @@
|
|||
package top.r3944realms.lib39.base.compat.jade;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import snownee.jade.api.IWailaClientRegistration;
|
||||
import snownee.jade.api.IWailaPlugin;
|
||||
import snownee.jade.api.WailaPlugin;
|
||||
import top.r3944realms.lib39.Lib39;
|
||||
import top.r3944realms.lib39.base.compat.jade.provider.FabricDollComponentProvider;
|
||||
import top.r3944realms.lib39.content.block.AbstractDollBlock;
|
||||
import top.r3944realms.lib39.content.block.DollBlock;
|
||||
|
||||
/**
|
||||
|
|
@ -21,7 +19,7 @@ public class FabricJadePlugin implements IWailaPlugin {
|
|||
public static final ResourceLocation UID = Lib39.rl("lib39");
|
||||
|
||||
@Override
|
||||
public void registerClient(@NotNull IWailaClientRegistration registration) {
|
||||
registration.registerBlockComponent(new FabricDollComponentProvider(), AbstractDollBlock.class);
|
||||
public void registerClient(IWailaClientRegistration registration) {
|
||||
registration.registerBlockComponent(new FabricDollComponentProvider(), DollBlock.class);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ package top.r3944realms.lib39.base.compat.jade.provider;
|
|||
import com.mojang.authlib.GameProfile;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import snownee.jade.api.BlockAccessor;
|
||||
import snownee.jade.api.IBlockComponentProvider;
|
||||
import snownee.jade.api.ITooltip;
|
||||
|
|
@ -21,16 +20,12 @@ public class FabricDollComponentProvider implements IBlockComponentProvider {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void appendTooltip(ITooltip iTooltip, @NotNull BlockAccessor blockAccessor, IPluginConfig iPluginConfig) {
|
||||
public void appendTooltip(ITooltip iTooltip, BlockAccessor blockAccessor, IPluginConfig iPluginConfig) {
|
||||
if (blockAccessor.getBlockEntity() instanceof DollBlockEntity doll) {
|
||||
GameProfile ownerProfile;
|
||||
if (doll.getOwnerProfile() != null) {
|
||||
ownerProfile = doll.getOwnerProfile().gameProfile();
|
||||
if (ownerProfile != null) {
|
||||
iTooltip.add(Component.translatable("tooltip.lib39.content.doll.hover.1", ownerProfile.getName()));
|
||||
}
|
||||
GameProfile ownerProfile = doll.getOwnerProfile();
|
||||
if (ownerProfile != null) {
|
||||
iTooltip.add(Component.translatable("tooltip.lib39.content.doll.hover.1", ownerProfile.getName()));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,30 +9,24 @@ import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
|
|||
import net.fabricmc.fabric.api.lookup.v1.entity.EntityApiLookup;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import net.minecraft.core.component.DataComponents;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.Services;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.item.CreativeModeTab;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.item.component.ResolvableProfile;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.SkullBlockEntity;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import top.r3944realms.lib39.Lib39;
|
||||
import top.r3944realms.lib39.api.callback.ActionResult;
|
||||
import top.r3944realms.lib39.api.callback.AnvilUpdateCallback;
|
||||
import top.r3944realms.lib39.api.callback.MinecraftSetUpServiceCallback;
|
||||
import top.r3944realms.lib39.api.callback.SyncManagerRegisterCallback;
|
||||
import top.r3944realms.lib39.api.callback.client.ClientWorldCallback;
|
||||
import top.r3944realms.lib39.base.command.Lib39HelpCommand;
|
||||
import top.r3944realms.lib39.content.block.blockentity.DollBlockEntity;
|
||||
import top.r3944realms.lib39.content.item.DollItem;
|
||||
import top.r3944realms.lib39.core.register.Lib39Items;
|
||||
import top.r3944realms.lib39.core.sync.ISyncData;
|
||||
|
|
@ -48,7 +42,6 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
|
|
@ -188,35 +181,19 @@ public class FabricCommonEventHandler {
|
|||
for (Map.Entry<ResourceKey<CreativeModeTab>, List<Supplier<Block>>> resourceKeyListEntry : tabToItemsMap.entrySet()) {
|
||||
ItemGroupEvents.modifyEntriesEvent(resourceKeyListEntry.getKey()).register(content -> resourceKeyListEntry.getValue().forEach(i -> content.accept(i.get())));
|
||||
}
|
||||
MinecraftSetUpServiceCallback.EVENT.register((services, mainThreadExecutor) -> {
|
||||
DollBlockEntity.setup(services, mainThreadExecutor);
|
||||
return ActionResult.SUCCESS;
|
||||
});
|
||||
AnvilUpdateCallback.EVENT.register((left, right, outputSlot, name, baseCost, player) -> {
|
||||
if (left.getItem() instanceof DollItem && name != null && !name.isEmpty() && name.length() <= 16) {
|
||||
ItemStack output = Lib39Items.DOLL.get().getDefaultInstance();
|
||||
output.setCount(left.getCount());
|
||||
|
||||
// 创建 ResolvableProfile
|
||||
if (left.getItem() instanceof DollItem && name != null && name.length() < 15) {
|
||||
GameProfile profile = new GameProfile(Util.NIL_UUID, name);
|
||||
ResolvableProfile resolvableProfile = new ResolvableProfile(profile);
|
||||
output.set(DataComponents.PROFILE, resolvableProfile);
|
||||
|
||||
// 使用 DollBlockEntity 的缓存异步获取完整档案
|
||||
DollBlockEntity.fetchGameProfile(name).thenAcceptAsync(optional -> {
|
||||
optional.ifPresent(fullProfile -> {
|
||||
output.set(DataComponents.PROFILE, new ResolvableProfile(fullProfile));
|
||||
});
|
||||
}, SkullBlockEntity.CHECKED_MAIN_THREAD_EXECUTOR);
|
||||
|
||||
return AnvilUpdateCallback.AnvilUpdateResult.withOutput(output, 1, 1);
|
||||
} else if (name == null || name.isEmpty()) {
|
||||
return AnvilUpdateCallback.AnvilUpdateResult.withOutput(ItemStack.EMPTY, 0, 0);
|
||||
ItemStack copied = Lib39Items.DOLL.get().getDefaultInstance();
|
||||
SkullBlockEntity.updateGameprofile(profile,
|
||||
profile1 -> GameProfileHelper.saveProfileToItemStack(copied, profile1)
|
||||
);
|
||||
copied.setCount(left.getCount());
|
||||
return AnvilUpdateCallback.AnvilUpdateResult.withOutput(copied, 1, 1);
|
||||
} else {
|
||||
ItemStack errorOutput = Items.BARRIER.getDefaultInstance();
|
||||
errorOutput.set(DataComponents.CUSTOM_NAME,
|
||||
Component.translatable("invalid.player_name.too_long"));
|
||||
return AnvilUpdateCallback.AnvilUpdateResult.withOutput(errorOutput, 0, 0);
|
||||
ItemStack defaultInstance = Items.BARRIER.getDefaultInstance();
|
||||
defaultInstance.setHoverName(Component.translatable("invalid.player_name.too_long"));
|
||||
return AnvilUpdateCallback.AnvilUpdateResult.withOutput(defaultInstance, 0, 0);
|
||||
}
|
||||
});
|
||||
EntityApiLookup.get(FabricTestSyncData.ID, AbstractedTestSyncData.class, Void.class)
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
package top.r3944realms.lib39.core.network;
|
||||
|
||||
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
|
||||
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
|
||||
import top.r3944realms.lib39.core.network.toClient.SyncNBTLookupDataEntityS2CPayload;
|
||||
import top.r3944realms.lib39.core.network.toClient.SyncNBTLookupDataEntityS2CPacket;
|
||||
|
||||
/**
|
||||
* The type Fabric network handler.
|
||||
|
|
@ -13,13 +12,10 @@ public class FabricNetworkHandler {
|
|||
* 注册客户端接收的数据包
|
||||
*/
|
||||
public static void registerClientReceivers() {
|
||||
PayloadTypeRegistry.playS2C().register(
|
||||
SyncNBTLookupDataEntityS2CPayload.TYPE,
|
||||
SyncNBTLookupDataEntityS2CPayload.STREAM_CODEC
|
||||
);
|
||||
ClientPlayNetworking.registerGlobalReceiver(
|
||||
SyncNBTLookupDataEntityS2CPayload.TYPE,
|
||||
SyncNBTLookupDataEntityS2CPayload::handle
|
||||
SyncNBTLookupDataEntityS2CPacket.TYPE,
|
||||
SyncNBTLookupDataEntityS2CPacket::receive
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,91 @@
|
|||
package top.r3944realms.lib39.core.network.toClient;
|
||||
|
||||
import net.fabricmc.fabric.api.networking.v1.FabricPacket;
|
||||
import net.fabricmc.fabric.api.networking.v1.PacketSender;
|
||||
import net.fabricmc.fabric.api.networking.v1.PacketType;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.level.Level;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import top.r3944realms.lib39.Lib39;
|
||||
import top.r3944realms.lib39.core.event.FabricCommonEventHandler;
|
||||
import top.r3944realms.lib39.core.sync.ISyncData;
|
||||
import top.r3944realms.lib39.core.sync.NBTEntitySyncData;
|
||||
import top.r3944realms.lib39.core.sync.SyncData2Manager;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* The type Sync nbt lookup data entity s 2 c packet.
|
||||
*/
|
||||
public record SyncNBTLookupDataEntityS2CPacket(int entityId, ResourceLocation id, CompoundTag data) implements FabricPacket {
|
||||
/**
|
||||
* The constant SYNC_NBT_LOOKUP_PACKET_ID.
|
||||
*/
|
||||
public static final ResourceLocation SYNC_NBT_LOOKUP_PACKET_ID =
|
||||
Lib39.rl("sync_nbt_lookup_data_entity");
|
||||
/**
|
||||
* The constant TYPE.
|
||||
*/
|
||||
public static final PacketType<SyncNBTLookupDataEntityS2CPacket> TYPE = PacketType.create(
|
||||
SYNC_NBT_LOOKUP_PACKET_ID,
|
||||
buf -> new SyncNBTLookupDataEntityS2CPacket(buf.readInt(), buf.readResourceLocation(), buf.readNbt())
|
||||
);
|
||||
|
||||
/**
|
||||
* Instantiates a new Sync nbt data s 2 c pack.
|
||||
*
|
||||
* @param entityId the entity id
|
||||
* @param data the data
|
||||
*/
|
||||
public SyncNBTLookupDataEntityS2CPacket(int entityId, @NotNull NBTEntitySyncData data) {
|
||||
this(entityId, data.id(), data.serializeNBT());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull FriendlyByteBuf friendlyByteBuf) {
|
||||
friendlyByteBuf.writeInt(entityId);
|
||||
friendlyByteBuf.writeResourceLocation(id);
|
||||
friendlyByteBuf.writeNbt(data);
|
||||
}
|
||||
|
||||
@Contract(value = " -> new", pure = true)
|
||||
@Override
|
||||
public @NotNull PacketType<?> getType() {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Receive.
|
||||
*
|
||||
* @param packet the packet
|
||||
* @param localPlayer the local player
|
||||
* @param packetSender the packet sender
|
||||
*/
|
||||
public static void receive(@NotNull SyncNBTLookupDataEntityS2CPacket packet, @NotNull LocalPlayer localPlayer, PacketSender packetSender) {
|
||||
Level level = localPlayer.level();
|
||||
Entity entity = level.getEntity(packet.entityId);
|
||||
if (entity != null) {
|
||||
Optional<SyncData2Manager.DataProvider<Entity, ISyncData<?>>> lookupOpt =
|
||||
FabricCommonEventHandler
|
||||
.getSyncData2Manager()
|
||||
.getDataProvider(packet.id);
|
||||
lookupOpt.flatMap(dataProvider -> dataProvider.getData(entity))
|
||||
.ifPresent(lookup -> {
|
||||
if (lookup instanceof NBTEntitySyncData nbtLookup) {
|
||||
CompoundTag current = nbtLookup.serializeNBT();
|
||||
if (!current.equals(packet.data)) {
|
||||
nbtLookup.deserializeNBT(packet.data);
|
||||
}
|
||||
} else Lib39.LOGGER.debug("Unhandled sync data: {}", packet.data);
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,109 +0,0 @@
|
|||
package top.r3944realms.lib39.core.network.toClient;
|
||||
|
||||
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.network.RegistryFriendlyByteBuf;
|
||||
import net.minecraft.network.codec.StreamCodec;
|
||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.level.Level;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import top.r3944realms.lib39.Lib39;
|
||||
import top.r3944realms.lib39.core.event.FabricCommonEventHandler;
|
||||
import top.r3944realms.lib39.core.sync.ISyncData;
|
||||
import top.r3944realms.lib39.core.sync.NBTEntitySyncData;
|
||||
import top.r3944realms.lib39.core.sync.SyncData2Manager;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* The type Sync nbt lookup data entity s 2 c payload.
|
||||
*/
|
||||
public record SyncNBTLookupDataEntityS2CPayload(int entityId, ResourceLocation id, CompoundTag data) implements CustomPacketPayload {
|
||||
/**
|
||||
* The constant SYNC_NBT_LOOKUP_PACKET_ID.
|
||||
*/
|
||||
public static final ResourceLocation SYNC_NBT_LOOKUP_PACKET_ID =
|
||||
Lib39.rl("sync_nbt_lookup_data_entity");
|
||||
/**
|
||||
* The constant TYPE.
|
||||
*/
|
||||
public static final Type<SyncNBTLookupDataEntityS2CPayload> TYPE = new Type<>(SYNC_NBT_LOOKUP_PACKET_ID);
|
||||
|
||||
/**
|
||||
* Stream codec for serializing/deserializing the packet.
|
||||
*/
|
||||
public static final StreamCodec<RegistryFriendlyByteBuf, SyncNBTLookupDataEntityS2CPayload> STREAM_CODEC =
|
||||
StreamCodec.ofMember(SyncNBTLookupDataEntityS2CPayload::write, SyncNBTLookupDataEntityS2CPayload::new);
|
||||
|
||||
|
||||
/**
|
||||
* Instantiates a new Sync nbt data s 2 c pack.
|
||||
*
|
||||
* @param entityId the entity id
|
||||
* @param data the data
|
||||
*/
|
||||
public SyncNBTLookupDataEntityS2CPayload(int entityId, @NotNull NBTEntitySyncData data) {
|
||||
this(entityId, data.id(), data.serializeNBT());
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates from buffer.
|
||||
*
|
||||
* @param buf the buffer
|
||||
*/
|
||||
public SyncNBTLookupDataEntityS2CPayload(RegistryFriendlyByteBuf buf) {
|
||||
this(buf.readInt(), buf.readResourceLocation(), buf.readNbt());
|
||||
}
|
||||
|
||||
/**
|
||||
* Write.
|
||||
*
|
||||
* @param friendlyByteBuf the friendly byte buf
|
||||
*/
|
||||
public void write(@NotNull FriendlyByteBuf friendlyByteBuf) {
|
||||
friendlyByteBuf.writeInt(entityId);
|
||||
friendlyByteBuf.writeResourceLocation(id);
|
||||
friendlyByteBuf.writeNbt(data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Receive.
|
||||
*
|
||||
* @param payload the packet
|
||||
* @param context the context
|
||||
*/
|
||||
public static void handle(@NotNull SyncNBTLookupDataEntityS2CPayload payload, ClientPlayNetworking.Context context) {
|
||||
LocalPlayer localPlayer = context.player();
|
||||
Level level = localPlayer.level();
|
||||
Entity entity = level.getEntity(payload.entityId);
|
||||
|
||||
if (entity != null) {
|
||||
Optional<SyncData2Manager.DataProvider<Entity, ISyncData<?>>> lookupOpt =
|
||||
FabricCommonEventHandler
|
||||
.getSyncData2Manager()
|
||||
.getDataProvider(payload.id);
|
||||
|
||||
lookupOpt.flatMap(dataProvider -> dataProvider.getData(entity))
|
||||
.ifPresent(lookup -> {
|
||||
if (lookup instanceof NBTEntitySyncData nbtLookup) {
|
||||
CompoundTag current = nbtLookup.serializeNBT();
|
||||
if (!current.equals(payload.data)) {
|
||||
nbtLookup.deserializeNBT(payload.data);
|
||||
}
|
||||
} else {
|
||||
Lib39.LOGGER.debug("Unhandled sync data: {}", payload.data);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type<? extends CustomPacketPayload> type() {
|
||||
return TYPE;
|
||||
}
|
||||
}
|
||||
|
|
@ -5,7 +5,7 @@ import net.minecraft.server.level.ServerLevel;
|
|||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.players.PlayerList;
|
||||
import top.r3944realms.lib39.core.event.FabricCommonEventHandler;
|
||||
import top.r3944realms.lib39.core.network.toClient.SyncNBTLookupDataEntityS2CPayload;
|
||||
import top.r3944realms.lib39.core.network.toClient.SyncNBTLookupDataEntityS2CPacket;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -19,8 +19,8 @@ public interface IFabricUpdate extends IUpdate {
|
|||
PlayerList playerList = serverLevel.getServer().getPlayerList();
|
||||
List<ServerPlayer> players = playerList.getPlayers();
|
||||
for (ServerPlayer player : players) {
|
||||
if (ServerPlayNetworking.canSend(player, SyncNBTLookupDataEntityS2CPayload.TYPE)) {
|
||||
ServerPlayNetworking.send(player, new SyncNBTLookupDataEntityS2CPayload(getSyncData().entityId(), getSyncData()));
|
||||
if (ServerPlayNetworking.canSend(player, SyncNBTLookupDataEntityS2CPacket.TYPE)) {
|
||||
ServerPlayNetworking.send(player, new SyncNBTLookupDataEntityS2CPacket(getSyncData().entityId(), getSyncData()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package top.r3944realms.lib39.example;
|
||||
|
||||
import top.r3944realms.lib39.core.compat.ICompatManager;
|
||||
import top.r3944realms.lib39.core.compat.CompatManager;
|
||||
import top.r3944realms.lib39.example.core.compat.FabricLib39Compat;
|
||||
import top.r3944realms.lib39.example.core.event.FabricExCommonEventHandler;
|
||||
import top.r3944realms.lib39.example.core.network.FabricExNetworkHandler;
|
||||
|
|
@ -29,7 +29,7 @@ public class FabricLib39Example {
|
|||
FabricExCommonEventHandler.init();
|
||||
FabricExLib39Items.init();
|
||||
FabricExNetworkHandler.registerServerReceivers();
|
||||
ICompatManager orCreateCompatManager = FabricExCommonEventHandler.getOrCreateCompatManager();
|
||||
CompatManager orCreateCompatManager = FabricExCommonEventHandler.getOrCreateCompatManager();
|
||||
orCreateCompatManager.registerCompat(FabricLib39Compat.ID, FabricLib39Compat.INSTANCE);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -290,8 +290,8 @@ public class FabricTestSyncData extends AbstractedTestSyncData implements IFabri
|
|||
}
|
||||
|
||||
@Override
|
||||
public void deserializeNBT(CompoundTag t) {
|
||||
NBTReader.of(t)
|
||||
public void deserializeNBT(CompoundTag nbt) {
|
||||
NBTReader.of(nbt)
|
||||
.intValue(NBT_KEY_INT, integer -> testInt = integer)
|
||||
.string(NBT_KEY_STRING, string -> testString = string)
|
||||
.booleanValue(NBT_KEY_BOOLEAN, bool -> testBoolean = bool)
|
||||
|
|
|
|||
|
|
@ -1,19 +1,12 @@
|
|||
package top.r3944realms.lib39.example.core.compat;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import top.r3944realms.lib39.Lib39;
|
||||
import top.r3944realms.lib39.core.compat.CompatManager;
|
||||
import top.r3944realms.lib39.core.compat.ICompat;
|
||||
import top.r3944realms.lib39.core.compat.SimpleCompatManager;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* The type Fabric lib 39 compat manager.
|
||||
*/
|
||||
public class FabricLib39CompatManager extends SimpleCompatManager {
|
||||
|
||||
public class FabricLib39CompatManager extends CompatManager {
|
||||
/**
|
||||
* Instantiates a new Compat manager.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import net.minecraft.world.entity.Entity;
|
|||
import net.minecraft.world.entity.LivingEntity;
|
||||
import top.r3944realms.lib39.api.callback.ActionResult;
|
||||
import top.r3944realms.lib39.api.callback.SyncManagerRegisterCallback;
|
||||
import top.r3944realms.lib39.core.compat.ICompatManager;
|
||||
import top.r3944realms.lib39.core.compat.CompatManager;
|
||||
import top.r3944realms.lib39.core.event.FabricCommonEventHandler;
|
||||
import top.r3944realms.lib39.core.sync.CachedSyncManager;
|
||||
import top.r3944realms.lib39.example.content.data.AbstractedTestSyncData;
|
||||
|
|
@ -23,7 +23,7 @@ public class FabricExCommonEventHandler {
|
|||
*
|
||||
* @return the compat manager
|
||||
*/
|
||||
public static ICompatManager getOrCreateCompatManager() {
|
||||
public static CompatManager getOrCreateCompatManager() {
|
||||
if (compatManager == null) {
|
||||
synchronized (FabricCommonEventHandler.class) {
|
||||
if (compatManager == null) {
|
||||
|
|
@ -37,7 +37,7 @@ public class FabricExCommonEventHandler {
|
|||
/**
|
||||
* The Compat manager.
|
||||
*/
|
||||
static volatile ICompatManager compatManager;
|
||||
static volatile CompatManager compatManager;
|
||||
|
||||
/**
|
||||
* Init.
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
package top.r3944realms.lib39.example.core.network;
|
||||
|
||||
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
|
||||
import net.minecraft.network.RegistryFriendlyByteBuf;
|
||||
import net.minecraft.network.codec.StreamCodec;
|
||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||
import net.fabricmc.fabric.api.networking.v1.FabricPacket;
|
||||
import net.fabricmc.fabric.api.networking.v1.PacketSender;
|
||||
import net.fabricmc.fabric.api.networking.v1.PacketType;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
|
@ -15,59 +15,63 @@ import top.r3944realms.lib39.example.content.item.FabricFabricItem;
|
|||
/**
|
||||
* The type Client data packet.
|
||||
*/
|
||||
public record FabricClientDataPacket(AbstractedTestSyncData clientData, int targetEntityId) implements CustomPacketPayload {
|
||||
public class FabricClientDataPacket implements FabricPacket {
|
||||
/**
|
||||
* The constant CLIENT_TEST_DATA.
|
||||
*/
|
||||
public static final ResourceLocation CLIENT_TEST_DATA =
|
||||
Lib39.rl("client_test_data");
|
||||
|
||||
/**
|
||||
* The constant TYPE.
|
||||
*/
|
||||
public static final CustomPacketPayload.Type<FabricClientDataPacket> TYPE =
|
||||
new CustomPacketPayload.Type<>(CLIENT_TEST_DATA);
|
||||
public static final PacketType<FabricClientDataPacket> TYPE = PacketType.create(
|
||||
CLIENT_TEST_DATA,
|
||||
FabricClientDataPacket::new
|
||||
);
|
||||
private final AbstractedTestSyncData clientData;
|
||||
private final int targetEntityId;
|
||||
|
||||
/**
|
||||
* Stream codec for serializing/deserializing the packet.
|
||||
*/
|
||||
public static final StreamCodec<RegistryFriendlyByteBuf, FabricClientDataPacket> STREAM_CODEC =
|
||||
StreamCodec.ofMember(FabricClientDataPacket::write, FabricClientDataPacket::new);
|
||||
|
||||
/**
|
||||
* Instantiates a new Client data packet from buffer.
|
||||
* Instantiates a new Client data packet.
|
||||
*
|
||||
* @param buf the buffer
|
||||
* @param clientData the client data
|
||||
* @param targetEntityId the target entity id
|
||||
*/
|
||||
public FabricClientDataPacket(RegistryFriendlyByteBuf buf) {
|
||||
this(FabricTestSyncData.staticFromBytes(buf), buf.readInt());
|
||||
public FabricClientDataPacket(AbstractedTestSyncData clientData, int targetEntityId) {
|
||||
this.clientData = clientData;
|
||||
this.targetEntityId = targetEntityId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write packet data to buffer.
|
||||
* Instantiates a new Client data packet.
|
||||
*
|
||||
* @param buf the buffer
|
||||
* @param buf the buf
|
||||
*/
|
||||
public void write(RegistryFriendlyByteBuf buf) {
|
||||
public FabricClientDataPacket(FriendlyByteBuf buf) {
|
||||
this.clientData = FabricTestSyncData.staticFromBytes(buf);
|
||||
this.targetEntityId = buf.readInt();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void write(FriendlyByteBuf buf) {
|
||||
clientData.toBytes(buf);
|
||||
buf.writeInt(targetEntityId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Type<? extends CustomPacketPayload> type() {
|
||||
public PacketType<?> getType() {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle packet on server side.
|
||||
* Register this with ServerPlayNetworking.registerGlobalReceiver
|
||||
* Receive.
|
||||
*
|
||||
* @param packet the packet
|
||||
* @param context the context
|
||||
* @param packet the packet
|
||||
* @param serverPlayer the server player
|
||||
* @param packetSender the packet sender
|
||||
*/
|
||||
public static void handle(FabricClientDataPacket packet, ServerPlayNetworking.Context context) {
|
||||
ServerPlayer serverPlayer = context.player();
|
||||
// PacketSender is no longer needed, use context.responseSender() if needed
|
||||
public static void receive(@NotNull FabricClientDataPacket packet, @NotNull ServerPlayer serverPlayer, PacketSender packetSender) {
|
||||
FabricFabricItem.handleClientDataFromPacket(serverPlayer, packet.clientData, packet.targetEntityId);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,5 @@
|
|||
package top.r3944realms.lib39.example.core.network;
|
||||
|
||||
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
|
||||
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
|
||||
|
||||
/**
|
||||
|
|
@ -11,13 +10,9 @@ public class FabricExNetworkHandler {
|
|||
* 注册服务器接收的数据包
|
||||
*/
|
||||
public static void registerServerReceivers() {
|
||||
PayloadTypeRegistry.playC2S().register(
|
||||
FabricClientDataPacket.TYPE,
|
||||
FabricClientDataPacket.STREAM_CODEC
|
||||
);
|
||||
ServerPlayNetworking.registerGlobalReceiver(
|
||||
FabricClientDataPacket.TYPE,
|
||||
FabricClientDataPacket::handle
|
||||
FabricClientDataPacket::receive
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package top.r3944realms.lib39.mixin.minecraft;
|
||||
package top.r3944realms.lib39.mixin;
|
||||
|
||||
import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod;
|
||||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
||||
|
|
@ -8,9 +8,10 @@ import org.jetbrains.annotations.NotNull;
|
|||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import top.r3944realms.lib39.core.event.FabricCommonEventHandler;
|
||||
import top.r3944realms.lib39.core.sync.ILib39SyncDataHolder;
|
||||
import top.r3944realms.lib39.core.sync.ISyncData;
|
||||
import top.r3944realms.lib39.core.sync.NBTEntitySyncData;import top.r3944realms.lib39.platform.Services;
|
||||
import top.r3944realms.lib39.core.sync.NBTEntitySyncData;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
|
|
@ -44,7 +45,7 @@ public abstract class MixinEntity implements ILib39SyncDataHolder {
|
|||
|
||||
@WrapMethod(method = "saveWithoutId")
|
||||
private CompoundTag wrapSave(CompoundTag compound, @NotNull Operation<CompoundTag> original) {
|
||||
Services.PLATFORM.getUtilHelper().getSyncData2Manager().forEach((id, manager) -> {
|
||||
FabricCommonEventHandler.getSyncData2Manager().forEach((id, manager) -> {
|
||||
ISyncData<?> o = manager.getSyncMap().get(getUUID());
|
||||
if (o instanceof NBTEntitySyncData syncData) {
|
||||
saveSyncData(syncData);
|
||||
|
|
@ -5,15 +5,12 @@ import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
|||
import com.llamalad7.mixinextras.sugar.Local;
|
||||
import com.mojang.blaze3d.platform.WindowEventHandler;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.screens.ReceivingLevelScreen;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import net.minecraft.server.Services;
|
||||
import net.minecraft.server.WorldStem;
|
||||
import net.minecraft.server.packs.repository.PackRepository;
|
||||
import net.minecraft.util.thread.ReentrantBlockableEventLoop;
|
||||
import net.minecraft.world.level.storage.LevelStorageSource;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
|
|
@ -22,6 +19,8 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|||
import top.r3944realms.lib39.api.callback.MinecraftSetUpServiceCallback;
|
||||
import top.r3944realms.lib39.api.callback.client.ClientWorldCallback;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* The type Mixin minecraft.
|
||||
*/
|
||||
|
|
@ -30,8 +29,7 @@ public abstract class MixinMinecraft extends ReentrantBlockableEventLoop<Runnabl
|
|||
/**
|
||||
* The Level.
|
||||
*/
|
||||
@Shadow @Nullable
|
||||
public ClientLevel level;
|
||||
@Shadow @Nullable public ClientLevel level;
|
||||
|
||||
/**
|
||||
* Instantiates a new Mixin minecraft.
|
||||
|
|
@ -43,37 +41,34 @@ public abstract class MixinMinecraft extends ReentrantBlockableEventLoop<Runnabl
|
|||
}
|
||||
|
||||
/**
|
||||
* Set clientLevel callback.
|
||||
* Set level callback.
|
||||
*
|
||||
* @param clientLevel the clientLevel client
|
||||
* @param reason the reason
|
||||
* @param levelClient the level client
|
||||
* @param original the original
|
||||
*/
|
||||
@WrapMethod(method = "setLevel")
|
||||
public void setLevel$callback(ClientLevel clientLevel, ReceivingLevelScreen.Reason reason, Operation<Void> original) {
|
||||
if (clientLevel != null) ClientWorldCallback.UNLOAD.invoker().onWorldUnload(clientLevel);
|
||||
original.call(clientLevel, reason);
|
||||
public void setLevel$callback(ClientLevel levelClient, Operation<Void> original) {
|
||||
if (levelClient != null) ClientWorldCallback.UNLOAD.invoker().onWorldUnload(levelClient);
|
||||
original.call(levelClient);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear level callback.
|
||||
*
|
||||
* @param nextScreen the next screen
|
||||
* @param original the original
|
||||
* @param original the original
|
||||
*/
|
||||
@WrapMethod(method = "clearClientLevel")
|
||||
public void clearLevel$callback(Screen nextScreen, Operation<Void> original) {
|
||||
@WrapMethod(method = "clearLevel()V")
|
||||
public void clearLevel$callback(Operation<Void> original) {
|
||||
if (level != null) ClientWorldCallback.UNLOAD.invoker().onWorldUnload(level);
|
||||
original.call(nextScreen);
|
||||
original.call();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set level setup.
|
||||
*
|
||||
* @param level the level client
|
||||
* @param reason the reason
|
||||
* @param ci the ci
|
||||
* @param services the services
|
||||
* @param levelClient the level client
|
||||
* @param ci the ci
|
||||
* @param services the services
|
||||
*/
|
||||
@Inject(
|
||||
method = "setLevel",
|
||||
|
|
@ -83,14 +78,16 @@ public abstract class MixinMinecraft extends ReentrantBlockableEventLoop<Runnabl
|
|||
shift = At.Shift.AFTER
|
||||
)
|
||||
)
|
||||
public void setLevel$setup(ClientLevel level, ReceivingLevelScreen.Reason reason, CallbackInfo ci, @Local(ordinal = 0) Services services) {
|
||||
public void setLevel$setup(ClientLevel levelClient, CallbackInfo ci,
|
||||
@Local(ordinal = 0) Services services) {
|
||||
MinecraftSetUpServiceCallback.EVENT.invoker().load(services,this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Do world load setup.
|
||||
*
|
||||
* @param levelStorage the level id
|
||||
* @param levelId the level id
|
||||
* @param level the level
|
||||
* @param packRepository the pack repository
|
||||
* @param worldStem the world stem
|
||||
* @param newWorld the new world
|
||||
|
|
@ -105,7 +102,8 @@ public abstract class MixinMinecraft extends ReentrantBlockableEventLoop<Runnabl
|
|||
shift = At.Shift.AFTER
|
||||
)
|
||||
)
|
||||
public void doWorldLoad$setup(LevelStorageSource.LevelStorageAccess levelStorage, PackRepository packRepository, WorldStem worldStem, boolean newWorld, CallbackInfo ci, @Local(ordinal = 0) Services services) {
|
||||
public void doWorldLoad$setup(String levelId, LevelStorageSource.LevelStorageAccess level, PackRepository packRepository, WorldStem worldStem, boolean newWorld, CallbackInfo ci,
|
||||
@Local(ordinal = 0) Services services) {
|
||||
MinecraftSetUpServiceCallback.EVENT.invoker().load(services,this);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
package top.r3944realms.lib39.platform;
|
||||
|
||||
import top.r3944realms.lib39.core.event.FabricCommonEventHandler;
|
||||
import top.r3944realms.lib39.core.sync.SyncData2Manager;
|
||||
import top.r3944realms.lib39.platform.services.IUtilHelper;
|
||||
import top.r3944realms.lib39.util.FabricBlockRegistryBuilder;
|
||||
import top.r3944realms.lib39.util.block.BlockRegistryBuilder;
|
||||
|
|
@ -18,9 +16,4 @@ public enum FabricUtilHelper implements IUtilHelper {
|
|||
public BlockRegistryBuilder getBlockRegistryBuilder() {
|
||||
return new FabricBlockRegistryBuilder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SyncData2Manager<?> getSyncData2Manager() {
|
||||
return FabricCommonEventHandler.getSyncData2Manager();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@
|
|||
"${mod_author}"
|
||||
],
|
||||
"contact": {
|
||||
"homepage": "https://gitea.bot.leisuretimedock.top/3944Realms",
|
||||
"sources": "https://gitea.bot.leisuretimedock.top/3944Realms/Lib39"
|
||||
"homepage": "https://github.com/3944Realms",
|
||||
"sources": "https://github.com/3944Realms/Lib39"
|
||||
},
|
||||
"license": "${license}",
|
||||
"icon": "lib39_logo.png",
|
||||
|
|
|
|||
|
|
@ -3,17 +3,18 @@
|
|||
"minVersion": "0.8",
|
||||
"package": "top.r3944realms.lib39.mixin",
|
||||
"refmap": "${mod_id}.fabric.refmap.json",
|
||||
"compatibilityLevel": "JAVA_18",
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"mixins": [
|
||||
"MixinApiLookUpImpl",
|
||||
"callback.MixinAnvilMenu"
|
||||
"MixinEntity",
|
||||
"callback.MixinAnvilMenu",
|
||||
"callback.MixinDedicateServer"
|
||||
],
|
||||
"client": [
|
||||
"callback.MixinMinecraft",
|
||||
"callback.client.MixinClientLevel"
|
||||
],
|
||||
"server": [
|
||||
"callback.MixinDedicateServer"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
|
|
|
|||
|
|
@ -1,6 +1,13 @@
|
|||
plugins {
|
||||
id 'multiloader-loader'
|
||||
id 'net.neoforged.moddev'
|
||||
id 'net.neoforged.moddev.legacyforge'
|
||||
}
|
||||
|
||||
mixin {
|
||||
add(sourceSets.main, "${mod_id}.refmap.json")
|
||||
|
||||
config("${mod_id}.mixins.json")
|
||||
config("${mod_id}.forge.mixins.json")
|
||||
}
|
||||
|
||||
def commonResources = project(':common').file('src/main/resources/').getAbsolutePath()
|
||||
|
|
@ -9,8 +16,8 @@ def forgeBuildResources = file('build/resources/main/').getAbsolutePath()
|
|||
def commonBuildResources = project(':common').file('build/resources/main/').getAbsolutePath()
|
||||
def generatedOutput = project(':common').file('src/generated/resources/').getAbsolutePath()
|
||||
|
||||
neoForge {
|
||||
version = neoforge_version
|
||||
legacyForge {
|
||||
version = "${minecraft_version}-${forge_version}"
|
||||
|
||||
validateAccessTransformers = true
|
||||
|
||||
|
|
@ -65,12 +72,20 @@ sourceSets.main.resources.srcDir project(':common').file('src/generated/resource
|
|||
|
||||
dependencies {
|
||||
compileOnly project(":common")
|
||||
annotationProcessor("org.spongepowered:mixin:0.8.5-SNAPSHOT:processor")
|
||||
implementation(annotationProcessor("io.github.llamalad7:mixinextras-common:0.2.0"))
|
||||
implementation(group: 'tschipp.carryon', name: 'carryon-neoforge-1.21.1', version: '2.2.4.4') {
|
||||
modImplementation(group: 'tschipp.carryon', name: 'carryon-forge-1.20.1', version: '2.1.2.7') {
|
||||
transitive = false
|
||||
}
|
||||
implementation "curse.maven:jade-324717:7545219"
|
||||
modImplementation ("curse.maven:jade-324717:6855440")
|
||||
implementation(jarJar("io.github.llamalad7:mixinextras-forge:0.2.0"))
|
||||
}
|
||||
|
||||
jar {
|
||||
finalizedBy('reobfJar')
|
||||
manifest.attributes([
|
||||
"MixinConfigs": "${mod_id}.mixins.json,${mod_id}.forge.mixins.json"
|
||||
])
|
||||
}
|
||||
|
||||
// 配置sourceJar任务
|
||||
|
|
@ -91,7 +106,7 @@ tasks.named('javadoc', Javadoc) {
|
|||
classpath += project(':common').sourceSets.main.compileClasspath
|
||||
options.encoding = 'UTF-8'
|
||||
options.charSet = 'UTF-8'
|
||||
options.links("https://docs.oracle.com/en/java/javase/21/docs/api/")
|
||||
options.links("https://docs.oracle.com/en/java/javase/17/docs/api/")
|
||||
options.memberLevel = JavadocMemberLevel.PUBLIC
|
||||
options.addBooleanOption('Xdoclint:none', true)
|
||||
options.addStringOption('doctitle', "${mod_id} ${minecraft_version} ${version} Javadoc")
|
||||
|
|
@ -114,6 +129,72 @@ tasks.named('build') {
|
|||
dependsOn tasks.named('javadocJar')
|
||||
}
|
||||
|
||||
// 处理reobf
|
||||
tasks.named('reobfJar') {
|
||||
dependsOn tasks.named('sourcesJar')
|
||||
dependsOn tasks.named('javadocJar')
|
||||
}
|
||||
|
||||
// 发布配置
|
||||
publishing {
|
||||
publications {
|
||||
mavenJava(MavenPublication) {
|
||||
artifactId = "${mod_id}-forge-${minecraft_version}"
|
||||
artifacts.clear()
|
||||
artifact(tasks.named('reobfJar').get()) {
|
||||
builtBy tasks.named('reobfJar')
|
||||
}
|
||||
artifact(tasks.named('sourcesJar').get()) {
|
||||
builtBy tasks.named('sourcesJar')
|
||||
classifier = 'sources'
|
||||
}
|
||||
artifact(tasks.named('javadocJar').get()) {
|
||||
builtBy tasks.named('javadocJar')
|
||||
classifier = 'javadoc'
|
||||
}
|
||||
pom {
|
||||
name = 'Lib39'
|
||||
description = 'Lib39 is a general-purpose dependency library for Minecraft mods.'
|
||||
url = 'https://github.com/3944Realms/lib39'
|
||||
|
||||
properties = [
|
||||
'minecraft.version': project.minecraft_version,
|
||||
'mod.version': project.version,
|
||||
'forge.version': project.forge_version,
|
||||
'java.version': '17'
|
||||
]
|
||||
|
||||
licenses {
|
||||
license {
|
||||
name = 'MIT'
|
||||
url = 'https://raw.githubusercontent.com/3944Realms/lib39/refs/heads/main/LICENSE'
|
||||
distribution = 'repo'
|
||||
}
|
||||
}
|
||||
|
||||
developers {
|
||||
developer {
|
||||
id = 'R3944Realms'
|
||||
name = "${mod_author}"
|
||||
email = 'f256198830@hotmail.com'
|
||||
}
|
||||
}
|
||||
|
||||
scm {
|
||||
connection = 'scm:git:https://github.com/3944Realms/lib39.git'
|
||||
developerConnection = 'scm:git:ssh://git@github.com:3944Realms/lib39.git'
|
||||
url = 'https://github.com/3944Realms/lib39'
|
||||
tag = 'main'
|
||||
}
|
||||
|
||||
issueManagement {
|
||||
system = 'GitHub'
|
||||
url = 'https://github.com/3944Realms/lib39/issues'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
test {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
|
@ -124,23 +205,21 @@ processResources {
|
|||
|
||||
inputs.property "version", project.version
|
||||
inputs.property "minecraft_version", minecraft_version
|
||||
inputs.property "neoforge_version", neoforge_version
|
||||
inputs.property "forge_version", forge_version
|
||||
inputs.property "mod_id", mod_id
|
||||
inputs.property "mod_name", mod_name
|
||||
inputs.property "description", description
|
||||
inputs.property "mod_author", mod_author
|
||||
inputs.property "credits", credits
|
||||
|
||||
filesMatching(['META-INF/mods.toml', 'pack.mcmeta', "*.mixins.json"]) {
|
||||
expand([
|
||||
version: project.version,
|
||||
minecraft_version: minecraft_version,
|
||||
neoforge_version: neoforge_version,
|
||||
forge_version: forge_version,
|
||||
mod_id: mod_id,
|
||||
mod_name: mod_name,
|
||||
description: description,
|
||||
mod_author: mod_author,
|
||||
"credits": credits
|
||||
mod_author: mod_author
|
||||
])
|
||||
}
|
||||
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
||||
60
forge/src/main/java/top/r3944realms/lib39/Lib39Forge.java
Normal file
60
forge/src/main/java/top/r3944realms/lib39/Lib39Forge.java
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
package top.r3944realms.lib39;
|
||||
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import top.r3944realms.lib39.core.network.NetworkHandler;
|
||||
import top.r3944realms.lib39.core.register.ForgeLib39BlockEntities;
|
||||
import top.r3944realms.lib39.core.register.ForgeLib39Blocks;
|
||||
import top.r3944realms.lib39.core.register.ForgeLib39Items;
|
||||
import top.r3944realms.lib39.core.register.ForgeLib39SoundEvents;
|
||||
import top.r3944realms.lib39.example.ForgeLib39Example;
|
||||
|
||||
/**
|
||||
* The type Lib 39.
|
||||
*/
|
||||
@Mod(Lib39.MOD_ID)
|
||||
public class Lib39Forge {
|
||||
/**
|
||||
* Instantiates a new Lib 39.
|
||||
*/
|
||||
public Lib39Forge() {
|
||||
Lib39.initialize();
|
||||
initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize.
|
||||
*/
|
||||
public static void initialize() {
|
||||
Lib39.LOGGER.info("[Lib39-Forge] Hello Forge");
|
||||
IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
|
||||
ForgeLib39Blocks.register(modEventBus);
|
||||
ForgeLib39Items.register(modEventBus);
|
||||
ForgeLib39BlockEntities.register(modEventBus);
|
||||
ForgeLib39SoundEvents.register(modEventBus);
|
||||
NetworkHandler.register();
|
||||
if (Lib39.shouldRegisterExamples()) {
|
||||
Lib39.LOGGER.info("[Lib39-Forge] Registering Examples");
|
||||
registerExamples();
|
||||
}
|
||||
Lib39.LOGGER.info("[Lib39-Forge] Finished Initializing.");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Register examples.
|
||||
*/
|
||||
static void registerExamples() {
|
||||
Lib39.LOGGER.info("[Lib39-Forge] Starting example demonstrations");
|
||||
try {
|
||||
// 创建示例实例并演示功能
|
||||
ForgeLib39Example example = new ForgeLib39Example();
|
||||
example.demonstrateFeature();
|
||||
|
||||
Lib39.LOGGER.info("[Lib39-Forge] Example demonstrations completed successfully");
|
||||
} catch (Exception e) {
|
||||
Lib39.LOGGER.error("[Lib39-Forge] Failed to demonstrate examples", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
package top.r3944realms.lib39.api.event;
|
||||
|
||||
import net.minecraft.server.Services;
|
||||
import net.neoforged.bus.api.Event;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
|
|
@ -5,7 +5,7 @@ import net.minecraft.commands.CommandBuildContext;
|
|||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.network.chat.MutableComponent;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.neoforged.bus.api.Event;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import top.r3944realms.lib39.core.command.ICommandHelpManager;
|
||||
import top.r3944realms.lib39.core.command.model.CommandNode;
|
||||
import top.r3944realms.lib39.core.command.model.CommandPath;
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
package top.r3944realms.lib39.api.event;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.neoforged.bus.api.Event;
|
||||
import net.neoforged.neoforge.capabilities.EntityCapability;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import top.r3944realms.lib39.core.sync.ISyncData;
|
||||
import top.r3944realms.lib39.core.sync.ISyncManager;
|
||||
import top.r3944realms.lib39.core.sync.SyncData2CapManager;
|
||||
|
|
@ -46,8 +46,8 @@ public class SyncManagerRegisterEvent extends Event {
|
|||
*/
|
||||
public <K, T extends ISyncData<?>> void registerSyncManager(
|
||||
ResourceLocation id,
|
||||
ISyncManager<EntityCapability<T, Void>, T> syncManager,
|
||||
EntityCapability<T, Void> capability
|
||||
ISyncManager<Capability<T>, T> syncManager,
|
||||
Capability<T> capability
|
||||
) {
|
||||
syncs2Manager.registerManager(id, syncManager, capability);
|
||||
}
|
||||
|
|
@ -88,7 +88,7 @@ public class SyncManagerRegisterEvent extends Event {
|
|||
* @param id 必须先注册安全同步管理器,再绑定Cap,否则会抛出{@link IllegalStateException 未找到对应安全同步管理器}
|
||||
* @param capability the capability
|
||||
*/
|
||||
public <T extends ISyncData<?>> void bindCapability(ResourceLocation id, EntityCapability<T, Void> capability) {
|
||||
public <T extends ISyncData<?>> void bindCapability(ResourceLocation id, Capability<T> capability) {
|
||||
syncs2Manager.bindCapability(id, capability);
|
||||
}
|
||||
|
||||
|
|
@ -113,8 +113,8 @@ public class SyncManagerRegisterEvent extends Event {
|
|||
*/
|
||||
public <K, T extends ISyncData<?>> void registerComplete(
|
||||
ResourceLocation id,
|
||||
ISyncManager<EntityCapability<T, Void>, T> syncManager,
|
||||
EntityCapability<T, Void> capability,
|
||||
ISyncManager<Capability<T>, T> syncManager,
|
||||
Capability<T> capability,
|
||||
Class<?>... allowedEntityClasses
|
||||
) {
|
||||
registerSyncManager(id, syncManager, capability);
|
||||
|
|
@ -1,26 +1,25 @@
|
|||
package top.r3944realms.lib39.base.compat.jade;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import snownee.jade.api.IWailaClientRegistration;
|
||||
import snownee.jade.api.IWailaPlugin;
|
||||
import snownee.jade.api.WailaPlugin;
|
||||
import top.r3944realms.lib39.Lib39;
|
||||
import top.r3944realms.lib39.base.compat.jade.provider.NeoForgeDollComponentProvider;
|
||||
import top.r3944realms.lib39.content.block.AbstractDollBlock;
|
||||
import top.r3944realms.lib39.base.compat.jade.provider.ForgeDollComponentProvider;
|
||||
import top.r3944realms.lib39.content.block.DollBlock;
|
||||
|
||||
/**
|
||||
* The type Forge jade plugin.
|
||||
*/
|
||||
@WailaPlugin
|
||||
public class NeoForgeJadePlugin implements IWailaPlugin {
|
||||
public class ForgeJadePlugin implements IWailaPlugin {
|
||||
/**
|
||||
* The constant UID.
|
||||
*/
|
||||
public static final ResourceLocation UID = Lib39.rl("lib39");
|
||||
|
||||
@Override
|
||||
public void registerClient(@NotNull IWailaClientRegistration registration) {
|
||||
registration.registerBlockComponent(new NeoForgeDollComponentProvider(), AbstractDollBlock.class);
|
||||
public void registerClient(IWailaClientRegistration registration) {
|
||||
registration.registerBlockComponent(new ForgeDollComponentProvider(), DollBlock.class);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
package top.r3944realms.lib39.base.compat.jade.provider;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import snownee.jade.api.BlockAccessor;
|
||||
import snownee.jade.api.IBlockComponentProvider;
|
||||
import snownee.jade.api.ITooltip;
|
||||
import snownee.jade.api.config.IPluginConfig;
|
||||
|
||||
import top.r3944realms.lib39.base.compat.jade.ForgeJadePlugin;
|
||||
import top.r3944realms.lib39.content.block.blockentity.DollBlockEntity;
|
||||
|
||||
/**
|
||||
* The type Forge doll component provider.
|
||||
*/
|
||||
public class ForgeDollComponentProvider implements IBlockComponentProvider {
|
||||
@Override
|
||||
public ResourceLocation getUid() {
|
||||
return ForgeJadePlugin.UID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendTooltip(ITooltip iTooltip, BlockAccessor blockAccessor, IPluginConfig iPluginConfig) {
|
||||
if (blockAccessor.getBlockEntity() instanceof DollBlockEntity doll) {
|
||||
GameProfile ownerProfile = doll.getOwnerProfile();
|
||||
if (ownerProfile != null) {
|
||||
iTooltip.add(Component.translatable("tooltip.lib39.content.doll.hover.1", ownerProfile.getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
package top.r3944realms.lib39.base.datagen;
|
||||
|
||||
import net.minecraft.data.DataProvider;
|
||||
import net.neoforged.neoforge.data.event.GatherDataEvent;
|
||||
import net.minecraftforge.data.event.GatherDataEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
|
@ -13,8 +13,6 @@ import top.r3944realms.lib39.datagen.provider.SimpleLootTableProvider;
|
|||
import top.r3944realms.lib39.datagen.provider.SubProvidersWrapper;
|
||||
import top.r3944realms.lib39.datagen.value.McLocale;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
/**
|
||||
* The type Lib 39 base data gen event.
|
||||
*/
|
||||
|
|
@ -75,20 +73,13 @@ public class Lib39BaseDataGenEvent {
|
|||
private static void LootTableDataGenerate(@NotNull GatherDataEvent event) {
|
||||
event.getGenerator().addProvider(
|
||||
event.includeServer(),
|
||||
(DataProvider.Factory<SimpleLootTableProvider>) pOutput -> {
|
||||
try {
|
||||
return new SimpleLootTableProvider(pOutput, new SubProvidersWrapper().addBlockEntry(new Lib39BlockLootTable(event.getLookupProvider())), event.getLookupProvider());
|
||||
} catch (Exception e) {
|
||||
logger.error("Failed to generate loot_table",e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
(DataProvider.Factory<SimpleLootTableProvider>) pOutput -> new SimpleLootTableProvider(pOutput, new SubProvidersWrapper().addBlockEntry(new Lib39BlockLootTable()))
|
||||
);
|
||||
}
|
||||
private static void RecipeGenerator(@NotNull GatherDataEvent event) {
|
||||
event.getGenerator().addProvider(
|
||||
event.includeServer(),
|
||||
(DataProvider.Factory<Lib39RecipeProvider>)pOutput -> new Lib39RecipeProvider(pOutput, event.getLookupProvider())
|
||||
(DataProvider.Factory<Lib39RecipeProvider>) Lib39RecipeProvider::new
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,13 +1,9 @@
|
|||
package top.r3944realms.lib39.base.datagen.provider;
|
||||
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import top.r3944realms.lib39.core.register.NeoForgeLib39Blocks;
|
||||
import top.r3944realms.lib39.core.register.ForgeLib39Blocks;
|
||||
import top.r3944realms.lib39.core.register.Lib39Blocks;
|
||||
import top.r3944realms.lib39.datagen.provider.subprovider.BlockLootTables;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
/**
|
||||
* The type Lib 39 block loot table.
|
||||
*/
|
||||
|
|
@ -15,8 +11,8 @@ public class Lib39BlockLootTable extends BlockLootTables {
|
|||
/**
|
||||
* Instantiates a new Lib 39 block loot table.
|
||||
*/
|
||||
public Lib39BlockLootTable(CompletableFuture<HolderLookup.Provider> registries) throws ExecutionException, InterruptedException {
|
||||
super(NeoForgeLib39Blocks.BLOCKS, registries.get());
|
||||
public Lib39BlockLootTable() {
|
||||
super(ForgeLib39Blocks.BLOCKS);
|
||||
dropSelf(Lib39Blocks.DOLL, Lib39Blocks.WALL_DOLL);
|
||||
}
|
||||
}
|
||||
|
|
@ -2,8 +2,8 @@ package top.r3944realms.lib39.base.datagen.provider;
|
|||
|
||||
import net.minecraft.data.PackOutput;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.neoforged.neoforge.client.model.generators.BlockModelProvider;
|
||||
import net.neoforged.neoforge.common.data.ExistingFileHelper;
|
||||
import net.minecraftforge.client.model.generators.BlockModelProvider;
|
||||
import net.minecraftforge.common.data.ExistingFileHelper;
|
||||
import top.r3944realms.lib39.Lib39;
|
||||
import top.r3944realms.lib39.util.PlantHelper;
|
||||
|
||||
|
|
@ -3,10 +3,10 @@ package top.r3944realms.lib39.base.datagen.provider;
|
|||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.data.PackOutput;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.neoforged.neoforge.client.model.generators.BlockStateProvider;
|
||||
import net.neoforged.neoforge.client.model.generators.ConfiguredModel;
|
||||
import net.neoforged.neoforge.client.model.generators.ModelFile;
|
||||
import net.neoforged.neoforge.common.data.ExistingFileHelper;
|
||||
import net.minecraftforge.client.model.generators.BlockStateProvider;
|
||||
import net.minecraftforge.client.model.generators.ConfiguredModel;
|
||||
import net.minecraftforge.client.model.generators.ModelFile;
|
||||
import net.minecraftforge.common.data.ExistingFileHelper;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import top.r3944realms.lib39.Lib39;
|
||||
|
|
@ -15,12 +15,11 @@
|
|||
|
||||
package top.r3944realms.lib39.base.datagen.provider;
|
||||
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.data.PackOutput;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.neoforged.neoforge.client.model.generators.ItemModelProvider;
|
||||
import net.neoforged.neoforge.common.data.ExistingFileHelper;
|
||||
import net.minecraftforge.common.data.ExistingFileHelper;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import top.r3944realms.lib39.Lib39;
|
||||
import top.r3944realms.lib39.base.datagen.value.Lib39LangKey;
|
||||
import top.r3944realms.lib39.datagen.value.LangKeyValue;
|
||||
|
|
@ -33,7 +32,7 @@ import java.util.Objects;
|
|||
/**
|
||||
* The type item model provider.
|
||||
*/
|
||||
public class Lib39ItemModelProvider extends ItemModelProvider {
|
||||
public class Lib39ItemModelProvider extends net.minecraftforge.client.model.generators.ItemModelProvider {
|
||||
private static List<Item> objectList;
|
||||
/**
|
||||
* The constant GENERATED.
|
||||
|
|
@ -109,7 +108,7 @@ public class Lib39ItemModelProvider extends ItemModelProvider {
|
|||
* @return the string
|
||||
*/
|
||||
public String itemName(Item item){
|
||||
return Objects.requireNonNull(BuiltInRegistries.ITEM.getKey(item)).getPath();
|
||||
return Objects.requireNonNull(ForgeRegistries.ITEMS.getKey(item)).getPath();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
package top.r3944realms.lib39.base.datagen.provider;
|
||||
|
||||
import net.minecraft.data.PackOutput;
|
||||
import net.neoforged.neoforge.common.data.ExistingFileHelper;
|
||||
import net.neoforged.neoforge.common.data.SoundDefinition;
|
||||
import net.neoforged.neoforge.common.data.SoundDefinitionsProvider;
|
||||
import net.minecraftforge.common.data.ExistingFileHelper;
|
||||
import net.minecraftforge.common.data.SoundDefinition;
|
||||
import net.minecraftforge.common.data.SoundDefinitionsProvider;
|
||||
import top.r3944realms.lib39.Lib39;
|
||||
import top.r3944realms.lib39.core.register.Lib39SoundEvents;
|
||||
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
package top.r3944realms.lib39.content.item;
|
||||
|
||||
import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer;
|
||||
import net.minecraftforge.client.extensions.common.IClientItemExtensions;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import top.r3944realms.lib39.client.renderer.item.DollItemRenderer;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* The type Forge doll item.
|
||||
*/
|
||||
public class ForgeDollItem extends DollItem {
|
||||
/**
|
||||
* Instantiates a new Forge doll item.
|
||||
*
|
||||
* @param properties the properties
|
||||
*/
|
||||
public ForgeDollItem(Properties properties) {
|
||||
super(properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializeClient(@NotNull Consumer<IClientItemExtensions> consumer) {
|
||||
consumer.accept(new IClientItemExtensions() {
|
||||
@Override
|
||||
public BlockEntityWithoutLevelRenderer getCustomRenderer() {
|
||||
return DollItemRenderer.getInstance();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -1,10 +1,10 @@
|
|||
package top.r3944realms.lib39.core.compat;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.bus.api.IEventBus;
|
||||
import net.neoforged.fml.common.EventBusSubscriber;
|
||||
import net.neoforged.fml.loading.FMLEnvironment;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.fml.DistExecutor;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
|
|
@ -18,32 +18,24 @@ import java.util.function.Consumer;
|
|||
* The type Compat manager.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public abstract class NeoForgeCompatManager extends CompatManager<INeoForgeCompat> {
|
||||
public abstract class ForgeCompatManager extends CompatManager {
|
||||
/**
|
||||
* The Mod event bus.
|
||||
*/
|
||||
protected final IEventBus modEventBus,
|
||||
/**
|
||||
protected final IEventBus modEventBus, /**
|
||||
* The Game event bus.
|
||||
*/
|
||||
gameEventBus;
|
||||
/**
|
||||
* The Compats.
|
||||
*/
|
||||
protected final Map<ResourceLocation, INeoForgeCompat> compats = new HashMap<>();
|
||||
protected final Map<ResourceLocation, IForgeCompat> compats = new HashMap<>();
|
||||
/**
|
||||
* <pre>
|
||||
* 存储事件监听器配置
|
||||
* The Listener configs.
|
||||
* </pre>
|
||||
*/
|
||||
// 存储事件监听器配置
|
||||
protected final List<ListenerConfig> listenerConfigs = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public Map<ResourceLocation, INeoForgeCompat> getCompatMap() {
|
||||
return compats;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new Forge compat manager.
|
||||
*
|
||||
|
|
@ -51,16 +43,18 @@ public abstract class NeoForgeCompatManager extends CompatManager<INeoForgeCompa
|
|||
* @param modEventBus the mod event bus
|
||||
* @param gameEventBus the game event bus
|
||||
*/
|
||||
public NeoForgeCompatManager(ResourceLocation id, IEventBus modEventBus, IEventBus gameEventBus) {
|
||||
public ForgeCompatManager(ResourceLocation id, IEventBus modEventBus, IEventBus gameEventBus) {
|
||||
super(id);
|
||||
this.modEventBus = modEventBus;
|
||||
this.gameEventBus = gameEventBus;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doRegisterCompat(ResourceLocation id, INeoForgeCompat compat) {
|
||||
super.doRegisterCompat(id, compat);
|
||||
addListenerForCompat(id);
|
||||
protected void doRegisterCompat(ResourceLocation id, ICompat compat) {
|
||||
if (compat instanceof IForgeCompat) {
|
||||
super.doRegisterCompat(id, compat);
|
||||
addListenerForCompat(id);
|
||||
} else throw new IllegalArgumentException("Can't register compat " + id + " of type " + compat.getClass());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -69,7 +63,7 @@ public abstract class NeoForgeCompatManager extends CompatManager<INeoForgeCompa
|
|||
* @param dists the dists
|
||||
* @param bus the bus
|
||||
*/
|
||||
public void addListenerForAll(@Nullable Dist dists, EventBusSubscriber.Bus bus) {
|
||||
public void addListenerForAll(@Nullable Dist dists, Mod.EventBusSubscriber.Bus bus) {
|
||||
listenerConfigs.add(new ListenerConfig(null, dists, bus));
|
||||
}
|
||||
|
||||
|
|
@ -80,7 +74,7 @@ public abstract class NeoForgeCompatManager extends CompatManager<INeoForgeCompa
|
|||
* @param dists the dists
|
||||
* @param bus the bus
|
||||
*/
|
||||
public void addListenerForCompat(ResourceLocation compatId, @Nullable Dist dists, EventBusSubscriber.Bus bus) {
|
||||
public void addListenerForCompat(ResourceLocation compatId, @Nullable Dist dists, Mod.EventBusSubscriber.Bus bus) {
|
||||
listenerConfigs.add(new ListenerConfig(compatId, dists, bus));
|
||||
}
|
||||
|
||||
|
|
@ -90,14 +84,14 @@ public abstract class NeoForgeCompatManager extends CompatManager<INeoForgeCompa
|
|||
* @param compatId the compat id
|
||||
*/
|
||||
public void addListenerForCompat(ResourceLocation compatId) {
|
||||
addListenerForCompat(compatId, null, EventBusSubscriber.Bus.GAME);
|
||||
addListenerForCompat(compatId, null, EventBusSubscriber.Bus.MOD);
|
||||
addListenerForCompat(compatId, null, Mod.EventBusSubscriber.Bus.FORGE);
|
||||
addListenerForCompat(compatId, null, Mod.EventBusSubscriber.Bus.MOD);
|
||||
|
||||
addListenerForCompat(compatId, Dist.CLIENT, EventBusSubscriber.Bus.GAME);
|
||||
addListenerForCompat(compatId, Dist.CLIENT, EventBusSubscriber.Bus.MOD);
|
||||
addListenerForCompat(compatId, Dist.CLIENT, Mod.EventBusSubscriber.Bus.FORGE);
|
||||
addListenerForCompat(compatId, Dist.CLIENT, Mod.EventBusSubscriber.Bus.MOD);
|
||||
|
||||
addListenerForCompat(compatId, Dist.DEDICATED_SERVER, EventBusSubscriber.Bus.GAME);
|
||||
addListenerForCompat(compatId, Dist.DEDICATED_SERVER, EventBusSubscriber.Bus.MOD);
|
||||
addListenerForCompat(compatId, Dist.DEDICATED_SERVER, Mod.EventBusSubscriber.Bus.FORGE);
|
||||
addListenerForCompat(compatId, Dist.DEDICATED_SERVER, Mod.EventBusSubscriber.Bus.MOD);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -107,10 +101,10 @@ public abstract class NeoForgeCompatManager extends CompatManager<INeoForgeCompa
|
|||
* @param bus the bus
|
||||
* @param consumer the consumer
|
||||
*/
|
||||
public void addListenerForLoaded(@Nullable Dist dists, EventBusSubscriber.Bus bus, Consumer<IEventBus> consumer) {
|
||||
public void addListenerForLoaded(@Nullable Dist dists, Mod.EventBusSubscriber.Bus bus, Consumer<IEventBus> consumer) {
|
||||
listenerConfigs.add(new ListenerConfig(null, dists, bus) {
|
||||
@Override
|
||||
boolean shouldApply(@NotNull INeoForgeCompat compat) {
|
||||
boolean shouldApply(@NotNull IForgeCompat compat) {
|
||||
return super.shouldApply(compat);
|
||||
}
|
||||
});
|
||||
|
|
@ -129,7 +123,7 @@ public abstract class NeoForgeCompatManager extends CompatManager<INeoForgeCompa
|
|||
pendingTasks.clear();
|
||||
|
||||
// 初始化所有兼容模块
|
||||
for (Map.Entry<ResourceLocation, INeoForgeCompat> entry : compats.entrySet()) {
|
||||
for (Map.Entry<ResourceLocation, IForgeCompat> entry : compats.entrySet()) {
|
||||
if (!entry.getValue().isInitialized() && entry.getValue().isModLoaded()) {
|
||||
try {
|
||||
entry.getValue().initialize();
|
||||
|
|
@ -166,7 +160,7 @@ public abstract class NeoForgeCompatManager extends CompatManager<INeoForgeCompa
|
|||
* 将监听器应用到所有兼容模块
|
||||
*/
|
||||
private void applyListenerToAllCompats(ListenerConfig config) {
|
||||
for (INeoForgeCompat compat : compats.values()) {
|
||||
for (IForgeCompat compat : compats.values()) {
|
||||
if(!compat.isInitialized()) {
|
||||
if (config.shouldApply(compat)) {
|
||||
applyListenerToCompat(compat, config);
|
||||
|
|
@ -179,7 +173,7 @@ public abstract class NeoForgeCompatManager extends CompatManager<INeoForgeCompa
|
|||
* 将监听器应用到特定兼容模块
|
||||
*/
|
||||
private void applyListenerToCompat(ResourceLocation compatId, ListenerConfig config) {
|
||||
INeoForgeCompat compat = compats.get(compatId);
|
||||
IForgeCompat compat = compats.get(compatId);
|
||||
if (compat != null && config.shouldApply(compat)) {
|
||||
applyListenerToCompat(compat, config);
|
||||
}
|
||||
|
|
@ -188,22 +182,33 @@ public abstract class NeoForgeCompatManager extends CompatManager<INeoForgeCompa
|
|||
/**
|
||||
* 将监听器应用到具体的 ICompat 实例
|
||||
*/
|
||||
private void applyListenerToCompat(INeoForgeCompat compat, ListenerConfig config) {
|
||||
private void applyListenerToCompat(IForgeCompat compat, ListenerConfig config) {
|
||||
try {
|
||||
// 根据配置调用对应的 ICompat 方法
|
||||
if (config.dists != null) {
|
||||
// 不再使用 DistExecutor,改为在运行时判断环境
|
||||
Dist currentDist = FMLEnvironment.dist;
|
||||
|
||||
if (config.dists == Dist.CLIENT && currentDist == Dist.CLIENT) {
|
||||
applyClientListener(compat, config);
|
||||
} else if (config.dists == Dist.DEDICATED_SERVER && currentDist == Dist.DEDICATED_SERVER) {
|
||||
applyServerListener(compat, config);
|
||||
switch (config.dists) {
|
||||
case CLIENT -> DistExecutor.unsafeRunWhenOn(Dist.CLIENT,() -> () -> {
|
||||
if (config.bus == Mod.EventBusSubscriber.Bus.FORGE) {
|
||||
compat.addClientGameListener(gameEventBus);
|
||||
} else {
|
||||
compat.addClientModListener(modEventBus);
|
||||
}
|
||||
});
|
||||
case DEDICATED_SERVER -> DistExecutor.unsafeRunWhenOn(Dist.DEDICATED_SERVER,() -> () -> {
|
||||
if (config.bus == Mod.EventBusSubscriber.Bus.FORGE) {
|
||||
compat.addServerGameListener(gameEventBus);
|
||||
} else {
|
||||
compat.addServerModListener(modEventBus);
|
||||
}
|
||||
});
|
||||
}
|
||||
// 如果环境不匹配,什么都不做
|
||||
} else {
|
||||
// 通用监听器(两边都执行)
|
||||
applyCommonListener(compat, config);
|
||||
// 通用监听器
|
||||
if (config.bus == Mod.EventBusSubscriber.Bus.FORGE) {
|
||||
compat.addCommonGameListener(gameEventBus);
|
||||
} else {
|
||||
compat.addCommonModListener(modEventBus);
|
||||
}
|
||||
}
|
||||
|
||||
logger.debug("Applied {} listener to compat: {}",
|
||||
|
|
@ -214,39 +219,15 @@ public abstract class NeoForgeCompatManager extends CompatManager<INeoForgeCompa
|
|||
}
|
||||
}
|
||||
|
||||
private void applyClientListener(INeoForgeCompat compat, @NotNull ListenerConfig config) {
|
||||
if (config.bus == EventBusSubscriber.Bus.GAME) {
|
||||
compat.addClientGameListener(gameEventBus);
|
||||
} else {
|
||||
compat.addClientModListener(modEventBus);
|
||||
}
|
||||
}
|
||||
|
||||
private void applyServerListener(INeoForgeCompat compat, @NotNull ListenerConfig config) {
|
||||
if (config.bus == EventBusSubscriber.Bus.GAME) {
|
||||
compat.addServerGameListener(gameEventBus);
|
||||
} else {
|
||||
compat.addServerModListener(modEventBus);
|
||||
}
|
||||
}
|
||||
|
||||
private void applyCommonListener(INeoForgeCompat compat, @NotNull ListenerConfig config) {
|
||||
if (config.bus == EventBusSubscriber.Bus.GAME) {
|
||||
compat.addCommonGameListener(gameEventBus);
|
||||
} else {
|
||||
compat.addCommonModListener(modEventBus);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取监听器类型名称(用于日志)
|
||||
*/
|
||||
private @NotNull String getListenerTypeName(@NotNull ListenerConfig config) {
|
||||
if (config.dists != null) {
|
||||
return config.dists.name().toLowerCase() + " " +
|
||||
(config.bus == EventBusSubscriber.Bus.GAME ? "game" : "mod");
|
||||
(config.bus == Mod.EventBusSubscriber.Bus.FORGE ? "game" : "mod");
|
||||
} else {
|
||||
return "common " + (config.bus == EventBusSubscriber.Bus.GAME ? "game" : "mod");
|
||||
return "common " + (config.bus == Mod.EventBusSubscriber.Bus.FORGE ? "game" : "mod");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -257,7 +238,7 @@ public abstract class NeoForgeCompatManager extends CompatManager<INeoForgeCompa
|
|||
* @param compatId the compat id
|
||||
* @param bus the bus
|
||||
*/
|
||||
public void addListenerForCompat(ResourceLocation compatId, EventBusSubscriber.Bus bus) {
|
||||
public void addListenerForCompat(ResourceLocation compatId, Mod.EventBusSubscriber.Bus bus) {
|
||||
addListenerForCompat(compatId, null, bus);
|
||||
}
|
||||
|
||||
|
|
@ -276,7 +257,7 @@ public abstract class NeoForgeCompatManager extends CompatManager<INeoForgeCompa
|
|||
/**
|
||||
* The Bus.
|
||||
*/
|
||||
final EventBusSubscriber.Bus bus;
|
||||
final Mod.EventBusSubscriber.Bus bus;
|
||||
|
||||
/**
|
||||
* Instantiates a new Listener config.
|
||||
|
|
@ -285,7 +266,7 @@ public abstract class NeoForgeCompatManager extends CompatManager<INeoForgeCompa
|
|||
* @param dists the dists
|
||||
* @param bus the bus
|
||||
*/
|
||||
ListenerConfig(ResourceLocation compatId, Dist dists, EventBusSubscriber.Bus bus) {
|
||||
ListenerConfig(ResourceLocation compatId, Dist dists, Mod.EventBusSubscriber.Bus bus) {
|
||||
this.compatId = compatId;
|
||||
this.dists = dists;
|
||||
this.bus = bus;
|
||||
|
|
@ -297,7 +278,7 @@ public abstract class NeoForgeCompatManager extends CompatManager<INeoForgeCompa
|
|||
* @param compat the compat
|
||||
* @return the boolean
|
||||
*/
|
||||
boolean shouldApply(@NotNull INeoForgeCompat compat) {
|
||||
boolean shouldApply(@NotNull IForgeCompat compat) {
|
||||
return compat.isModLoaded();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,12 +1,11 @@
|
|||
package top.r3944realms.lib39.core.compat;
|
||||
|
||||
|
||||
import net.neoforged.bus.api.IEventBus;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
|
||||
/**
|
||||
* The interface Compat.
|
||||
*/
|
||||
public interface INeoForgeCompat extends ICompat {
|
||||
public interface IForgeCompat extends ICompat {
|
||||
/**
|
||||
* Add common game listener.
|
||||
*
|
||||
|
|
@ -1,28 +1,18 @@
|
|||
package top.r3944realms.lib39.core.event;
|
||||
|
||||
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import net.minecraft.client.renderer.ShaderInstance;
|
||||
import net.minecraft.client.renderer.entity.ItemRenderer;
|
||||
import net.minecraft.client.renderer.item.ItemProperties;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
import net.neoforged.fml.common.EventBusSubscriber;
|
||||
import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent;
|
||||
import net.neoforged.neoforge.client.event.EntityRenderersEvent;
|
||||
import net.neoforged.neoforge.client.event.RegisterShadersEvent;
|
||||
import net.neoforged.neoforge.client.extensions.common.IClientItemExtensions;
|
||||
import net.neoforged.neoforge.client.extensions.common.RegisterClientExtensionsEvent;
|
||||
import net.neoforged.neoforge.event.level.LevelEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.client.event.EntityRenderersEvent;
|
||||
import net.minecraftforge.client.event.RegisterShadersEvent;
|
||||
import net.minecraftforge.event.level.LevelEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import top.r3944realms.lib39.Lib39;
|
||||
import top.r3944realms.lib39.client.model.DollModel;
|
||||
import top.r3944realms.lib39.client.renderer.block.DollBlockEntityRenderer;
|
||||
import top.r3944realms.lib39.client.shader.Lib39Shaders;
|
||||
import top.r3944realms.lib39.content.item.NeoForgeDollItem;
|
||||
import top.r3944realms.lib39.core.register.Lib39BlockEntities;
|
||||
import top.r3944realms.lib39.core.register.Lib39Items;
|
||||
import top.r3944realms.lib39.util.ILevelHelper;
|
||||
|
||||
import java.io.IOException;
|
||||
|
|
@ -34,7 +24,7 @@ public class ClientEventHandler {
|
|||
/**
|
||||
* The type Mod.
|
||||
*/
|
||||
@EventBusSubscriber(value = Dist.CLIENT, bus = EventBusSubscriber.Bus.MOD, modid = Lib39.MOD_ID)
|
||||
@net.minecraftforge.fml.common.Mod.EventBusSubscriber(value = Dist.CLIENT, bus = net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus.MOD, modid = Lib39.MOD_ID)
|
||||
public static class Mod extends ClientEventHandler {
|
||||
/**
|
||||
* On register shaders.
|
||||
|
|
@ -43,7 +33,7 @@ public class ClientEventHandler {
|
|||
* @throws IOException the io exception
|
||||
*/
|
||||
@SubscribeEvent
|
||||
public static void onRegisterShaders(@NotNull RegisterShadersEvent event) throws IOException {
|
||||
public static void onRegisterShaders(RegisterShadersEvent event) throws IOException {
|
||||
event.registerShader(new ShaderInstance(event.getResourceProvider(), Lib39.rl("ring"), DefaultVertexFormat.POSITION_COLOR), Lib39Shaders::setRingShader);
|
||||
event.registerShader(new ShaderInstance(event.getResourceProvider(), Lib39.rl("selection"), DefaultVertexFormat.POSITION_COLOR), Lib39Shaders::setSelectionShader);
|
||||
}
|
||||
|
|
@ -54,7 +44,7 @@ public class ClientEventHandler {
|
|||
* @param event the event
|
||||
*/
|
||||
@SubscribeEvent
|
||||
public static void onRegisterRenderer (EntityRenderersEvent.@NotNull RegisterRenderers event) {
|
||||
public static void onRegisterRenderer (EntityRenderersEvent.RegisterRenderers event) {
|
||||
event.registerBlockEntityRenderer(Lib39BlockEntities.DOLL_BLOCK_ENTITY.get(),DollBlockEntityRenderer::new);
|
||||
}
|
||||
|
||||
|
|
@ -64,26 +54,16 @@ public class ClientEventHandler {
|
|||
* @param event the event
|
||||
*/
|
||||
@SubscribeEvent
|
||||
public static void registerLayerDefinitions(EntityRenderersEvent.@NotNull RegisterLayerDefinitions event) {
|
||||
public static void registerLayerDefinitions(EntityRenderersEvent.RegisterLayerDefinitions event) {
|
||||
event.registerLayerDefinition(DollModel.LAYER_LOCATION, DollModel::createBodyLayer);
|
||||
}
|
||||
|
||||
/**
|
||||
* On register client ex.
|
||||
*
|
||||
* @param event the event
|
||||
*/
|
||||
@SubscribeEvent
|
||||
public static void onRegisterClientEx (@NotNull RegisterClientExtensionsEvent event) {
|
||||
event.registerItem(NeoForgeDollItem.ClientOpt.getExtensions(), Lib39Items.DOLL.get());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The type Game.
|
||||
*/
|
||||
@EventBusSubscriber(value = Dist.CLIENT, bus = EventBusSubscriber.Bus.GAME, modid = Lib39.MOD_ID)
|
||||
@net.minecraftforge.fml.common.Mod.EventBusSubscriber(value = Dist.CLIENT, bus = net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus.FORGE, modid = Lib39.MOD_ID)
|
||||
public static class Game extends ClientEventHandler {
|
||||
/**
|
||||
* Register layer definitions.
|
||||
|
|
@ -91,7 +71,7 @@ public class ClientEventHandler {
|
|||
* @param event the event
|
||||
*/
|
||||
@SubscribeEvent
|
||||
public static void obClientUnload(LevelEvent.@NotNull Load event) {
|
||||
public static void obClientUnload(LevelEvent.Load event) {
|
||||
if (event.getLevel() != null && event.getLevel() instanceof ClientLevel level) {
|
||||
ILevelHelper.LevelHelper.CLIENT.setLevel(level);
|
||||
}
|
||||
|
|
@ -103,7 +83,7 @@ public class ClientEventHandler {
|
|||
* @param event the event
|
||||
*/
|
||||
@SubscribeEvent
|
||||
public static void obClientUnload(LevelEvent.@NotNull Unload event) {
|
||||
public static void obClientUnload(LevelEvent.Unload event) {
|
||||
if (event.getLevel() != null && event.getLevel() instanceof ClientLevel level) {
|
||||
ILevelHelper.LevelHelper.CLIENT.setLevel(null);
|
||||
}
|
||||
|
|
@ -3,7 +3,6 @@ package top.r3944realms.lib39.core.event;
|
|||
import com.mojang.authlib.GameProfile;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import net.minecraft.core.component.DataComponents;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
|
@ -12,33 +11,26 @@ import net.minecraft.world.entity.Entity;
|
|||
import net.minecraft.world.item.CreativeModeTab;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.item.component.ResolvableProfile;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.LevelAccessor;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.SkullBlockEntity;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
import net.neoforged.fml.common.EventBusSubscriber;
|
||||
import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||
import net.neoforged.neoforge.common.NeoForge;
|
||||
import net.neoforged.neoforge.data.event.GatherDataEvent;
|
||||
import net.neoforged.neoforge.event.AnvilUpdateEvent;
|
||||
import net.neoforged.neoforge.event.BuildCreativeModeTabContentsEvent;
|
||||
import net.neoforged.neoforge.event.RegisterCommandsEvent;
|
||||
import net.neoforged.neoforge.event.entity.EntityJoinLevelEvent;
|
||||
import net.neoforged.neoforge.event.entity.EntityLeaveLevelEvent;
|
||||
import net.neoforged.neoforge.event.level.LevelEvent;
|
||||
import net.neoforged.neoforge.event.tick.ServerTickEvent;
|
||||
import net.neoforged.neoforge.network.event.RegisterPayloadHandlersEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.data.event.GatherDataEvent;
|
||||
import net.minecraftforge.event.AnvilUpdateEvent;
|
||||
import net.minecraftforge.event.BuildCreativeModeTabContentsEvent;
|
||||
import net.minecraftforge.event.RegisterCommandsEvent;
|
||||
import net.minecraftforge.event.TickEvent;
|
||||
import net.minecraftforge.event.entity.EntityJoinLevelEvent;
|
||||
import net.minecraftforge.event.entity.EntityLeaveLevelEvent;
|
||||
import net.minecraftforge.event.level.LevelEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||
import top.r3944realms.lib39.Lib39;
|
||||
import top.r3944realms.lib39.api.event.MinecraftSetUpServiceEvent;
|
||||
import top.r3944realms.lib39.api.event.SyncManagerRegisterEvent;
|
||||
import top.r3944realms.lib39.base.command.Lib39HelpCommand;
|
||||
import top.r3944realms.lib39.base.datagen.Lib39BaseDataGenEvent;
|
||||
import top.r3944realms.lib39.content.block.blockentity.DollBlockEntity;
|
||||
import top.r3944realms.lib39.content.item.DollItem;
|
||||
import top.r3944realms.lib39.core.network.NetworkHandler;
|
||||
import top.r3944realms.lib39.core.register.Lib39Items;
|
||||
import top.r3944realms.lib39.core.sync.ISyncData;
|
||||
import top.r3944realms.lib39.core.sync.SyncData2CapManager;
|
||||
|
|
@ -58,7 +50,7 @@ public class CommonEventHandler {
|
|||
* The type Game.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
@EventBusSubscriber(modid = Lib39.MOD_ID, bus = EventBusSubscriber.Bus.GAME)
|
||||
@net.minecraftforge.fml.common.Mod.EventBusSubscriber(modid = Lib39.MOD_ID, bus = net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus.FORGE)
|
||||
public static class Game extends CommonEventHandler {
|
||||
private static ServerLevel sl;
|
||||
|
||||
|
|
@ -100,7 +92,7 @@ public class CommonEventHandler {
|
|||
synchronized (Game.class) {
|
||||
if (!isSync2MInitialized) {
|
||||
syncData2Manager = new SyncData2CapManager();
|
||||
NeoForge.EVENT_BUS.post(new SyncManagerRegisterEvent(syncData2Manager));
|
||||
MinecraftForge.EVENT_BUS.post(new SyncManagerRegisterEvent(syncData2Manager));
|
||||
isSync2MInitialized = true;
|
||||
sl = serverLevel;
|
||||
Lib39.LOGGER.info("SyncData2Manager initialized on Sever load");
|
||||
|
|
@ -112,7 +104,7 @@ public class CommonEventHandler {
|
|||
if (!clientLevel.dimension().equals(Level.OVERWORLD)) return;
|
||||
if (!isSync2MInitialized) {
|
||||
syncData2Manager = new SyncData2CapManager();
|
||||
NeoForge.EVENT_BUS.post(new SyncManagerRegisterEvent(syncData2Manager));
|
||||
MinecraftForge.EVENT_BUS.post(new SyncManagerRegisterEvent(syncData2Manager));
|
||||
Lib39.LOGGER.info("SyncData2Manager initialized on Client load");
|
||||
}
|
||||
}
|
||||
|
|
@ -140,11 +132,13 @@ public class CommonEventHandler {
|
|||
* @param event the event
|
||||
*/
|
||||
@SubscribeEvent
|
||||
public static void onServerTick(ServerTickEvent.Post event) {
|
||||
if (syncData2Manager == null) return;
|
||||
if (event.getServer().getTickCount() % 10 == 0)
|
||||
syncData2Manager.forEach(((resourceLocation, iSyncManager) -> iSyncManager.foreach(ISyncData::markDirty)));
|
||||
syncData2Manager.forEach(((resourceLocation, iSyncManager) -> iSyncManager.foreach(ISyncData::checkIfDirtyThenUpdate)));
|
||||
public static void onServerTick(TickEvent.ServerTickEvent event) {
|
||||
if (event.phase == TickEvent.Phase.END) {
|
||||
if (syncData2Manager == null) return;
|
||||
if (event.getServer().getTickCount() % 10 == 0)
|
||||
syncData2Manager.forEach(((resourceLocation, iSyncManager) -> iSyncManager.foreach(ISyncData::markDirty)));
|
||||
syncData2Manager.forEach(((resourceLocation, iSyncManager) -> iSyncManager.foreach(ISyncData::checkIfDirtyThenUpdate)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -156,45 +150,22 @@ public class CommonEventHandler {
|
|||
public static void onAnvilRename(AnvilUpdateEvent event) {
|
||||
if (event.getLeft().getItem() instanceof DollItem) {
|
||||
String name = event.getName();
|
||||
|
||||
if (name != null && !name.isEmpty()) {
|
||||
if (name.length() <= 16) {
|
||||
ItemStack output = Lib39Items.DOLL.get().getDefaultInstance();
|
||||
output.setCount(event.getLeft().getCount());
|
||||
|
||||
// 创建 ResolvableProfile
|
||||
GameProfile profile = new GameProfile(Util.NIL_UUID, name);
|
||||
ResolvableProfile resolvableProfile = new ResolvableProfile(profile);
|
||||
output.set(DataComponents.PROFILE, resolvableProfile);
|
||||
|
||||
// 使用 DollBlockEntity 的缓存异步获取完整档案
|
||||
DollBlockEntity.fetchGameProfile(name).thenAcceptAsync(optional -> {
|
||||
optional.ifPresent(fullProfile -> {
|
||||
// 更新为完整的 ResolvableProfile
|
||||
output.set(DataComponents.PROFILE, new ResolvableProfile(fullProfile));
|
||||
});
|
||||
}, SkullBlockEntity.CHECKED_MAIN_THREAD_EXECUTOR);
|
||||
|
||||
event.setOutput(output);
|
||||
event.setCost(1);
|
||||
event.setMaterialCost(1);
|
||||
} else {
|
||||
ItemStack errorOutput = Items.BARRIER.getDefaultInstance();
|
||||
errorOutput.set(DataComponents.CUSTOM_NAME,
|
||||
Component.translatable("invalid.player_name.too_long"));
|
||||
event.setOutput(errorOutput);
|
||||
event.setCost(0);
|
||||
}
|
||||
if (name != null && name.length() < 15) {
|
||||
GameProfile profile = new GameProfile(Util.NIL_UUID, name);
|
||||
ItemStack copied = Lib39Items.DOLL.get().getDefaultInstance();
|
||||
SkullBlockEntity.updateGameprofile(profile,
|
||||
profile1 -> GameProfileHelper.saveProfileToItemStack(copied, profile1)
|
||||
);
|
||||
copied.setCount(event.getLeft().getCount());
|
||||
event.setOutput(copied);
|
||||
event.setCost(1);
|
||||
} else {
|
||||
event.setOutput(ItemStack.EMPTY);
|
||||
event.setCost(0);
|
||||
ItemStack defaultInstance = Items.BARRIER.getDefaultInstance();
|
||||
defaultInstance.setHoverName(Component.translatable("invalid.player_name.too_long"));
|
||||
event.setOutput(defaultInstance);
|
||||
}
|
||||
}
|
||||
}
|
||||
@SubscribeEvent
|
||||
public static void onMinecraftSetUpService (@NotNull MinecraftSetUpServiceEvent event) {
|
||||
DollBlockEntity.setup(event.services, event.mainThreadExecutor);
|
||||
}
|
||||
|
||||
/**
|
||||
* On entity join world.
|
||||
|
|
@ -245,7 +216,7 @@ public class CommonEventHandler {
|
|||
* The type Mod.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
@EventBusSubscriber(modid = Lib39.MOD_ID, bus = EventBusSubscriber.Bus.MOD)
|
||||
@net.minecraftforge.fml.common.Mod.EventBusSubscriber(modid = Lib39.MOD_ID, bus = net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus.MOD)
|
||||
public static class Mod extends CommonEventHandler {
|
||||
private static final Map<Supplier<Block>, ResourceKey<CreativeModeTab>[]> itemAddMap = new ConcurrentHashMap<>();
|
||||
private static final Map<ResourceKey<CreativeModeTab>, List<Supplier<Block>>> tabToItemsMap = new ConcurrentHashMap<>();
|
||||
|
|
@ -291,20 +262,10 @@ public class CommonEventHandler {
|
|||
public static void onBuildCreativeTabContents(BuildCreativeModeTabContentsEvent event) {
|
||||
List<Supplier<Block>> itemsForTab = tabToItemsMap.get(event.getTabKey());
|
||||
if (itemsForTab != null) {
|
||||
itemsForTab.forEach(i -> event.accept(i.get()));
|
||||
itemsForTab.forEach(event::accept);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* On register payload.
|
||||
*
|
||||
* @param event the event
|
||||
*/
|
||||
@SubscribeEvent
|
||||
public static void onRegisterPayload (RegisterPayloadHandlersEvent event) {
|
||||
NetworkHandler.register(event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gather data.
|
||||
*
|
||||
|
|
@ -1,10 +1,9 @@
|
|||
package top.r3944realms.lib39.core.event;
|
||||
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
import net.neoforged.fml.common.EventBusSubscriber;
|
||||
import net.neoforged.neoforge.event.level.LevelEvent;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.event.level.LevelEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import top.r3944realms.lib39.Lib39;
|
||||
import top.r3944realms.lib39.util.ILevelHelper;
|
||||
|
||||
|
|
@ -20,7 +19,7 @@ public class ServerEventHandler {
|
|||
/**
|
||||
* The type Game.
|
||||
*/
|
||||
@EventBusSubscriber(value = Dist.DEDICATED_SERVER, bus = EventBusSubscriber.Bus.GAME, modid = Lib39.MOD_ID)
|
||||
@net.minecraftforge.fml.common.Mod.EventBusSubscriber(value = Dist.DEDICATED_SERVER, bus = net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus.FORGE, modid = Lib39.MOD_ID)
|
||||
public static class Game extends ServerEventHandler {
|
||||
/**
|
||||
* Register layer definitions.
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
package top.r3944realms.lib39.core.network;
|
||||
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraftforge.network.NetworkDirection;
|
||||
import net.minecraftforge.network.NetworkRegistry;
|
||||
import net.minecraftforge.network.PacketDistributor;
|
||||
import net.minecraftforge.network.simple.SimpleChannel;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import top.r3944realms.lib39.Lib39;
|
||||
import top.r3944realms.lib39.core.network.toClient.SyncNBTCapDataEntityS2CPacket;
|
||||
|
||||
/**
|
||||
* The type Network handler.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class NetworkHandler {
|
||||
private static int cid = 0;
|
||||
/**
|
||||
* The constant INSTANCE.
|
||||
*/
|
||||
public static final SimpleChannel INSTANCE = NetworkRegistry.newSimpleChannel(
|
||||
Lib39.rl(Lib39.MOD_ID, "main"),
|
||||
() -> Lib39.ModInfo.VERSION,
|
||||
Lib39.ModInfo.VERSION::equals,
|
||||
Lib39.ModInfo.VERSION::equals
|
||||
);
|
||||
|
||||
/**
|
||||
* Register.
|
||||
*/
|
||||
public static void register() {
|
||||
INSTANCE.messageBuilder(SyncNBTCapDataEntityS2CPacket.class, cid++, NetworkDirection.PLAY_TO_CLIENT)
|
||||
.encoder(SyncNBTCapDataEntityS2CPacket::encode)
|
||||
.decoder(SyncNBTCapDataEntityS2CPacket::decode)
|
||||
.consumerNetworkThread(SyncNBTCapDataEntityS2CPacket::handle)
|
||||
.add();
|
||||
}
|
||||
|
||||
/**
|
||||
* Send to player.
|
||||
*
|
||||
* @param <MSG> the type parameter
|
||||
* @param message the message
|
||||
* @param player the player
|
||||
*/
|
||||
public static <MSG> void sendToPlayer(MSG message, ServerPlayer player){
|
||||
INSTANCE.send(PacketDistributor.PLAYER.with(() -> player), message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send to player.
|
||||
*
|
||||
* @param <MSG> the type parameter
|
||||
* @param <T> the type parameter
|
||||
* @param message the message
|
||||
* @param entity the entity
|
||||
* @param packetDistributor the packet distributor
|
||||
*/
|
||||
public static <MSG, T> void sendToPlayer(MSG message, T entity, @NotNull PacketDistributor<T> packetDistributor){
|
||||
INSTANCE.send(packetDistributor.with(() -> entity), message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send to player.
|
||||
*
|
||||
* @param <MSG> the type parameter
|
||||
* @param message the message
|
||||
*/
|
||||
public static <MSG> void sendToAllPlayer(MSG message){
|
||||
INSTANCE.send(PacketDistributor.ALL.noArg(), message);
|
||||
}
|
||||
}
|
||||
|
|
@ -4,12 +4,9 @@ import net.minecraft.client.Minecraft;
|
|||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.network.RegistryFriendlyByteBuf;
|
||||
import net.minecraft.network.codec.StreamCodec;
|
||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.neoforged.neoforge.network.handling.IPayloadContext;
|
||||
import net.minecraftforge.network.NetworkEvent;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import top.r3944realms.lib39.Lib39;
|
||||
|
|
@ -22,25 +19,10 @@ import java.util.Optional;
|
|||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* The type Sync nbt data s 2 c payload.
|
||||
* The type Sync nbt data s 2 c pack.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public record SyncNBTCapDataEntityS2CPayload(int entityId, ResourceLocation id, CompoundTag data) implements CustomPacketPayload {
|
||||
/**
|
||||
* The constant SYNC_NBT_CAP_PACKET_ID.
|
||||
*/
|
||||
public static final ResourceLocation SYNC_NBT_CAP_PACKET_ID =
|
||||
Lib39.rl("sync_nbt_cap_data_entity");
|
||||
/**
|
||||
* The constant TYPE.
|
||||
*/
|
||||
public static final Type<SyncNBTCapDataEntityS2CPayload> TYPE = new Type<>(SYNC_NBT_CAP_PACKET_ID);
|
||||
|
||||
/**
|
||||
* The constant STREAM_CODEC.
|
||||
*/
|
||||
public static final StreamCodec<RegistryFriendlyByteBuf, SyncNBTCapDataEntityS2CPayload> STREAM_CODEC =
|
||||
StreamCodec.ofMember(SyncNBTCapDataEntityS2CPayload::encode, SyncNBTCapDataEntityS2CPayload::decode);
|
||||
public record SyncNBTCapDataEntityS2CPacket(int entityId, ResourceLocation id, CompoundTag data) {
|
||||
|
||||
/**
|
||||
* Instantiates a new Sync nbt data s 2 c pack.
|
||||
|
|
@ -48,7 +30,7 @@ public record SyncNBTCapDataEntityS2CPayload(int entityId, ResourceLocation id,
|
|||
* @param entityId the entity id
|
||||
* @param data the data
|
||||
*/
|
||||
public SyncNBTCapDataEntityS2CPayload(int entityId, @NotNull NBTEntitySyncData data) {
|
||||
public SyncNBTCapDataEntityS2CPacket(int entityId, @NotNull NBTEntitySyncData data) {
|
||||
this(entityId, data.id(), data.serializeNBT());
|
||||
}
|
||||
|
||||
|
|
@ -58,7 +40,7 @@ public record SyncNBTCapDataEntityS2CPayload(int entityId, ResourceLocation id,
|
|||
* @param msg the msg
|
||||
* @param buffer the buffer
|
||||
*/
|
||||
public static void encode(@NotNull SyncNBTCapDataEntityS2CPayload msg, @NotNull FriendlyByteBuf buffer) {
|
||||
public static void encode(@NotNull SyncNBTCapDataEntityS2CPacket msg, @NotNull FriendlyByteBuf buffer) {
|
||||
buffer.writeInt(msg.entityId);
|
||||
buffer.writeResourceLocation(msg.id);
|
||||
buffer.writeNbt(msg.data);
|
||||
|
|
@ -71,43 +53,41 @@ public record SyncNBTCapDataEntityS2CPayload(int entityId, ResourceLocation id,
|
|||
* @return the sync nbt data s 2 c pack
|
||||
*/
|
||||
@Contract("_ -> new")
|
||||
public static @NotNull SyncNBTCapDataEntityS2CPayload decode(@NotNull FriendlyByteBuf buffer) {
|
||||
return new SyncNBTCapDataEntityS2CPayload(buffer.readInt(), buffer.readResourceLocation(), buffer.readNbt());
|
||||
public static @NotNull SyncNBTCapDataEntityS2CPacket decode(@NotNull FriendlyByteBuf buffer) {
|
||||
return new SyncNBTCapDataEntityS2CPacket(buffer.readInt(), buffer.readResourceLocation(), buffer.readNbt());
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle.
|
||||
*
|
||||
* @param payload the msg
|
||||
* @param context the context
|
||||
* @param msg the msg
|
||||
* @param ctx the ctx
|
||||
*/
|
||||
public static void handle(SyncNBTCapDataEntityS2CPayload payload, @NotNull IPayloadContext context) {
|
||||
public static void handle(SyncNBTCapDataEntityS2CPacket msg, @NotNull Supplier<NetworkEvent.Context> ctx) {
|
||||
NetworkEvent.Context context = ctx.get();
|
||||
context.enqueueWork(() -> {
|
||||
ClientLevel level = Minecraft.getInstance().level;
|
||||
if (level != null) {
|
||||
Entity entity = level.getEntity(payload.entityId);
|
||||
Entity entity = level.getEntity(msg.entityId);
|
||||
if (entity != null) {
|
||||
Optional<SyncData2Manager.DataProvider<Entity, ISyncData<?>>> capOpt =
|
||||
CommonEventHandler.Game
|
||||
.getSyncData2Manager()
|
||||
.getDataProvider(payload.id);
|
||||
.getDataProvider(msg.id);
|
||||
capOpt.flatMap(dataProvider -> dataProvider.getData(entity))
|
||||
.ifPresent(cap -> {
|
||||
if (cap instanceof NBTEntitySyncData nbtCap) {
|
||||
CompoundTag current = nbtCap.serializeNBT();
|
||||
if (!current.equals(payload.data)) {
|
||||
nbtCap.deserializeNBT(payload.data);
|
||||
if (!current.equals(msg.data)) {
|
||||
nbtCap.deserializeNBT(msg.data);
|
||||
}
|
||||
} else Lib39.LOGGER.debug("Unhandled sync data: {}", payload.data);
|
||||
} else Lib39.LOGGER.debug("Unhandled sync data: {}", msg.data);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
context.setPacketHandled(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type<? extends CustomPacketPayload> type() {
|
||||
return TYPE;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,20 +1,20 @@
|
|||
package top.r3944realms.lib39.core.register;
|
||||
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.neoforged.bus.api.IEventBus;
|
||||
import net.neoforged.neoforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import top.r3944realms.lib39.Lib39;
|
||||
import top.r3944realms.lib39.content.block.blockentity.DollBlockEntity;
|
||||
|
||||
/**
|
||||
* The type Lib 39 block entities.
|
||||
*/
|
||||
public class NeoForgeLib39BlockEntities {
|
||||
public class ForgeLib39BlockEntities {
|
||||
/**
|
||||
* The constant BLOCK_ENTITY_TYPES.
|
||||
*/
|
||||
public static final DeferredRegister<BlockEntityType<?>> BLOCK_ENTITY_TYPES = DeferredRegister.create(BuiltInRegistries.BLOCK_ENTITY_TYPE, Lib39.MOD_ID);
|
||||
public static final DeferredRegister<BlockEntityType<?>> BLOCK_ENTITY_TYPES = DeferredRegister.create(ForgeRegistries.BLOCK_ENTITY_TYPES, Lib39.MOD_ID);
|
||||
|
||||
static {
|
||||
//noinspection DataFlowIssue
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
package top.r3944realms.lib39.core.register;
|
||||
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.neoforged.bus.api.IEventBus;
|
||||
import net.neoforged.neoforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import top.r3944realms.lib39.Lib39;
|
||||
import top.r3944realms.lib39.content.block.DollBlock;
|
||||
import top.r3944realms.lib39.content.block.WallDollBlock;
|
||||
|
|
@ -12,11 +12,11 @@ import top.r3944realms.lib39.util.block.BlockRegistryBuilder;
|
|||
/**
|
||||
* The type Lib 39 blocks.
|
||||
*/
|
||||
public class NeoForgeLib39Blocks {
|
||||
public class ForgeLib39Blocks {
|
||||
/**
|
||||
* The constant BLOCKS.
|
||||
*/
|
||||
public static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(BuiltInRegistries.BLOCK, Lib39.MOD_ID);
|
||||
public static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, Lib39.MOD_ID);
|
||||
|
||||
static {
|
||||
Lib39Blocks.DOLL = BlockRegistryBuilder
|
||||
|
|
@ -1,23 +1,23 @@
|
|||
package top.r3944realms.lib39.core.register;
|
||||
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.neoforged.bus.api.IEventBus;
|
||||
import net.neoforged.neoforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import top.r3944realms.lib39.Lib39;
|
||||
import top.r3944realms.lib39.content.item.NeoForgeDollItem;
|
||||
import top.r3944realms.lib39.content.item.ForgeDollItem;
|
||||
|
||||
/**
|
||||
* The type Ex lib 39 items.
|
||||
*/
|
||||
public class NeoForgeLib39Items {
|
||||
public class ForgeLib39Items {
|
||||
/**
|
||||
* The constant ITEMS.
|
||||
*/
|
||||
public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(BuiltInRegistries.ITEM, Lib39.MOD_ID);
|
||||
public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, Lib39.MOD_ID);
|
||||
|
||||
static {
|
||||
Lib39Items.DOLL = ITEMS.register("doll", () -> new NeoForgeDollItem(new Item.Properties()));
|
||||
Lib39Items.DOLL = ITEMS.register("doll", () -> new ForgeDollItem(new Item.Properties()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1,19 +1,19 @@
|
|||
package top.r3944realms.lib39.core.register;
|
||||
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.neoforged.bus.api.IEventBus;
|
||||
import net.neoforged.neoforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import top.r3944realms.lib39.Lib39;
|
||||
|
||||
/**
|
||||
* The type Lib 39 sound events.
|
||||
*/
|
||||
public class NeoForgeLib39SoundEvents {
|
||||
public class ForgeLib39SoundEvents {
|
||||
/**
|
||||
* The constant SOUND_EVENTS.
|
||||
*/
|
||||
public static final DeferredRegister<SoundEvent> SOUND_EVENTS = DeferredRegister.create(BuiltInRegistries.SOUND_EVENT, Lib39.MOD_ID);
|
||||
public static final DeferredRegister<SoundEvent> SOUND_EVENTS = DeferredRegister.create(ForgeRegistries.SOUND_EVENTS, Lib39.MOD_ID);
|
||||
|
||||
static {
|
||||
Lib39SoundEvents.DUCK_TOY = SOUND_EVENTS.register("duck_toy",
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package top.r3944realms.lib39.core.sync;
|
||||
|
||||
import top.r3944realms.lib39.core.network.NetworkHandler;
|
||||
import top.r3944realms.lib39.core.network.toClient.SyncNBTCapDataEntityS2CPacket;
|
||||
|
||||
/**
|
||||
* The interface Forge update.
|
||||
*/
|
||||
public interface IForgeUpdate extends IUpdate {
|
||||
default void update() {
|
||||
NetworkHandler.sendToAllPlayer(new SyncNBTCapDataEntityS2CPacket(getSyncData().entityId(), getSyncData().id, getSyncData().serializeNBT()));
|
||||
}
|
||||
}
|
||||
|
|
@ -2,7 +2,7 @@ package top.r3944realms.lib39.core.sync;
|
|||
|
||||
import com.google.common.collect.Maps;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.neoforged.neoforge.capabilities.EntityCapability;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Map;
|
||||
|
|
@ -29,15 +29,15 @@ public class SyncData2CapManager extends SyncData2Manager<SyncData2CapManager.Ty
|
|||
*
|
||||
* @param <T> the type parameter
|
||||
*/
|
||||
protected static class TypedSyncEntry<T extends ISyncData<?>> extends SyncData2Manager.TypedSyncEntry<EntityCapability<T, Void>, T> {
|
||||
protected static class TypedSyncEntry<T extends ISyncData<?>> extends SyncData2Manager.TypedSyncEntry<Capability<T>, T> {
|
||||
/**
|
||||
* Instantiates a new Typed sync entry.
|
||||
*
|
||||
* @param manager the manager
|
||||
* @param capability the capability
|
||||
*/
|
||||
public TypedSyncEntry(ISyncManager<EntityCapability<T, Void>, T> manager,@Nullable EntityCapability<T, Void> capability) {
|
||||
super(manager, key -> capability != null ? Optional.ofNullable(key.getCapability(capability)) : Optional.empty());
|
||||
public TypedSyncEntry(ISyncManager<Capability<T>, T> manager,@Nullable Capability<T> capability) {
|
||||
super(manager, key -> capability != null ? key.getCapability(capability).resolve() : Optional.empty());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -51,8 +51,8 @@ public class SyncData2CapManager extends SyncData2Manager<SyncData2CapManager.Ty
|
|||
*/
|
||||
public <T extends ISyncData<?>> void registerManager(
|
||||
ResourceLocation key,
|
||||
ISyncManager<EntityCapability<T, Void>, T> manager,
|
||||
EntityCapability<T, Void> capability
|
||||
ISyncManager<Capability<T>, T> manager,
|
||||
Capability<T> capability
|
||||
) {
|
||||
Objects.requireNonNull(key, "ResourceLocation key cannot be null");
|
||||
Objects.requireNonNull(manager, "Sync manager cannot be null");
|
||||
|
|
@ -69,7 +69,7 @@ public class SyncData2CapManager extends SyncData2Manager<SyncData2CapManager.Ty
|
|||
* @param key the key
|
||||
* @param capability the capability
|
||||
*/
|
||||
public <T extends ISyncData<?>> void bindCapability(ResourceLocation key, EntityCapability<T, Void> capability) {
|
||||
public <T extends ISyncData<?>> void bindCapability(ResourceLocation key, Capability<T> capability) {
|
||||
Objects.requireNonNull(key, "ResourceLocation key cannot be null");
|
||||
Objects.requireNonNull(capability, "Capability cannot be null");
|
||||
|
||||
|
|
@ -103,7 +103,7 @@ public class SyncData2CapManager extends SyncData2Manager<SyncData2CapManager.Ty
|
|||
* @param entry the entry
|
||||
* @param newCapability the new capability
|
||||
*/
|
||||
protected <T extends ISyncData<?>> void updateCapabilityInEntry(ResourceLocation id, TypedSyncEntry<?> entry, EntityCapability<T, Void> newCapability) {
|
||||
updateDataProviderInEntry(id, entry, key -> newCapability != null ? Optional.ofNullable(key.getCapability(newCapability)) : Optional.empty());
|
||||
protected <T extends ISyncData<?>> void updateCapabilityInEntry(ResourceLocation id, TypedSyncEntry<?> entry, Capability<T> newCapability) {
|
||||
updateDataProviderInEntry(id, entry, key -> newCapability != null ? key.getCapability(newCapability).resolve() : Optional.empty());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,19 +1,14 @@
|
|||
package top.r3944realms.lib39.datagen.provider;
|
||||
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.core.WritableRegistry;
|
||||
import net.minecraft.data.PackOutput;
|
||||
import net.minecraft.data.loot.LootTableProvider;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.ProblemReporter;
|
||||
import net.minecraft.world.level.storage.loot.LootTable;
|
||||
import net.minecraft.world.level.storage.loot.ValidationContext;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
/**
|
||||
* The type Simple loot table provider.
|
||||
|
|
@ -24,10 +19,9 @@ public class SimpleLootTableProvider extends LootTableProvider {
|
|||
*
|
||||
* @param output the output
|
||||
* @param subProvidersWrapper the sub providers wrapper
|
||||
* @param registries the registries
|
||||
*/
|
||||
public SimpleLootTableProvider(PackOutput output, @NotNull SubProvidersWrapper subProvidersWrapper, CompletableFuture<HolderLookup.Provider> registries) {
|
||||
super(output, Set.of(), subProvidersWrapper.entries, registries);
|
||||
public SimpleLootTableProvider(PackOutput output, @NotNull SubProvidersWrapper subProvidersWrapper) {
|
||||
super(output, Set.of(), subProvidersWrapper.entries);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -36,14 +30,13 @@ public class SimpleLootTableProvider extends LootTableProvider {
|
|||
* @param output the output
|
||||
* @param requiredTables the required tables
|
||||
* @param subProvidersWrapper the sub providers wrapper
|
||||
* @param registries the registries
|
||||
*/
|
||||
public SimpleLootTableProvider(PackOutput output, Set<ResourceKey<LootTable>> requiredTables, @NotNull SubProvidersWrapper subProvidersWrapper, CompletableFuture<HolderLookup.Provider> registries) {
|
||||
super(output, requiredTables, subProvidersWrapper.entries, registries);
|
||||
public SimpleLootTableProvider(PackOutput output, Set<ResourceLocation> requiredTables, @NotNull SubProvidersWrapper subProvidersWrapper) {
|
||||
super(output, requiredTables, subProvidersWrapper.entries);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validate(WritableRegistry<LootTable> writableregistry, ValidationContext validationcontext, ProblemReporter.Collector problemreporter$collector) {
|
||||
writableregistry.forEach(lootTable -> lootTable.validate(validationcontext));
|
||||
protected void validate(@NotNull Map<ResourceLocation, LootTable> map, @NotNull ValidationContext validationcontext) {
|
||||
map.forEach((id, table) -> table.validate(validationcontext));
|
||||
}
|
||||
}
|
||||
|
|
@ -42,7 +42,7 @@ public class SubProvidersWrapper {
|
|||
* @return the sub providers wrapper
|
||||
*/
|
||||
public SubProvidersWrapper addEntry(LootTableSubProvider subProvider, LootContextParamSet subParamSet) {
|
||||
entries.add(new LootTableProvider.SubProviderEntry(provider -> subProvider, subParamSet));
|
||||
entries.add(new LootTableProvider.SubProviderEntry(() -> subProvider, subParamSet));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
@ -53,7 +53,7 @@ public class SubProvidersWrapper {
|
|||
* @return the sub providers wrapper
|
||||
*/
|
||||
public SubProvidersWrapper addBlockEntry(BlockLootTables blockLootTables) {
|
||||
entries.add(new LootTableProvider.SubProviderEntry(provider -> blockLootTables, LootContextParamSets.BLOCK));
|
||||
entries.add(new LootTableProvider.SubProviderEntry(() -> blockLootTables, LootContextParamSets.BLOCK));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
@ -1,25 +1,24 @@
|
|||
package top.r3944realms.lib39.datagen.provider.subprovider;
|
||||
|
||||
import net.minecraft.advancements.critereon.*;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.advancements.critereon.ItemPredicate;
|
||||
import net.minecraft.data.loot.BlockLootSubProvider;
|
||||
import net.minecraft.world.flag.FeatureFlags;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.enchantment.Enchantment;
|
||||
import net.minecraft.world.item.enchantment.Enchantments;
|
||||
import net.minecraft.world.level.ItemLike;
|
||||
import net.minecraft.world.level.block.*;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.FlowerPotBlock;
|
||||
import net.minecraft.world.level.block.state.properties.Property;
|
||||
import net.minecraft.world.level.storage.loot.LootPool;
|
||||
import net.minecraft.world.level.storage.loot.LootTable;
|
||||
import net.minecraft.world.level.storage.loot.entries.LootItem;
|
||||
import net.minecraft.world.level.storage.loot.functions.*;
|
||||
import net.minecraft.world.level.storage.loot.predicates.*;
|
||||
import net.minecraft.world.level.storage.loot.functions.ApplyBonusCount;
|
||||
import net.minecraft.world.level.storage.loot.functions.SetItemCountFunction;
|
||||
import net.minecraft.world.level.storage.loot.predicates.LootItemBlockStatePropertyCondition;
|
||||
import net.minecraft.world.level.storage.loot.predicates.MatchTool;
|
||||
import net.minecraft.world.level.storage.loot.providers.number.ConstantValue;
|
||||
import net.minecraft.world.level.storage.loot.providers.number.UniformGenerator;
|
||||
import net.neoforged.neoforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
|
@ -43,10 +42,9 @@ public class BlockLootTables extends BlockLootSubProvider {
|
|||
* Instantiates a new Block loot tables.
|
||||
*
|
||||
* @param deferredRegister the deferred register
|
||||
* @param registries the registries
|
||||
*/
|
||||
public BlockLootTables(DeferredRegister<Block> deferredRegister, HolderLookup.Provider registries) {
|
||||
super(Set.of(), FeatureFlags.REGISTRY.allFlags(), registries);
|
||||
public BlockLootTables(DeferredRegister<Block> deferredRegister) {
|
||||
super(Set.of(), FeatureFlags.REGISTRY.allFlags());
|
||||
knowBlocks = deferredRegister;
|
||||
}
|
||||
|
||||
|
|
@ -88,7 +86,7 @@ public class BlockLootTables extends BlockLootSubProvider {
|
|||
* @return the block loot tables
|
||||
*/
|
||||
public BlockLootTables dropWhenSilkTouch(Supplier<Block> block) {
|
||||
return addEntry(block, this::createSilkTouchOnlyTable);
|
||||
return addEntry(block, BlockLootSubProvider::createSilkTouchOnlyTable);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -194,7 +192,7 @@ public class BlockLootTables extends BlockLootSubProvider {
|
|||
* @return the block loot tables
|
||||
*/
|
||||
public BlockLootTables dropFlowerPot(Supplier<Block> block) {
|
||||
return addEntry(block, this::createPotFlowerItemTable);
|
||||
return addEntry(block, (pBlock) -> this.createPotFlowerItemTable(((FlowerPotBlock)pBlock).getContent()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -338,44 +336,32 @@ public class BlockLootTables extends BlockLootSubProvider {
|
|||
* 创建新的战利品表生成器
|
||||
*
|
||||
* @param deferredRegister the deferred register
|
||||
* @param registries the registries
|
||||
* @return the block loot tables
|
||||
*/
|
||||
@Contract("_ -> new")
|
||||
public static @NotNull BlockLootTables create(DeferredRegister<Block> deferredRegister, HolderLookup.Provider registries) {
|
||||
return new BlockLootTables(deferredRegister, registries);
|
||||
public static @NotNull BlockLootTables create(DeferredRegister<Block> deferredRegister) {
|
||||
return new BlockLootTables(deferredRegister);
|
||||
}
|
||||
|
||||
/**
|
||||
* 快速创建基本矿物的掉落表
|
||||
*
|
||||
* @param oreBlock the ore block
|
||||
* @param oreItem the ore item
|
||||
* @param registries the registries
|
||||
* @param oreBlock the ore block
|
||||
* @param oreItem the ore item
|
||||
* @return the loot table .@ not null builder
|
||||
*/
|
||||
public static LootTable.@NotNull Builder simpleOreDrop(Block oreBlock, Item oreItem,
|
||||
HolderLookup.Provider registries) {
|
||||
HolderLookup.RegistryLookup<Enchantment> enchantments = registries.lookupOrThrow(Registries.ENCHANTMENT);
|
||||
Holder<Enchantment> silkTouch = enchantments.getOrThrow(Enchantments.SILK_TOUCH);
|
||||
Holder<Enchantment> fortune = enchantments.getOrThrow(Enchantments.FORTUNE);
|
||||
|
||||
// 创建 Silk Touch 谓词
|
||||
ItemPredicate.Builder silkTouchPredicates = ItemPredicate.Builder.item()
|
||||
.withSubPredicate(
|
||||
ItemSubPredicates.ENCHANTMENTS,
|
||||
ItemEnchantmentsPredicate.enchantments(List.of(
|
||||
new EnchantmentPredicate(silkTouch, MinMaxBounds.Ints.atLeast(1))
|
||||
))
|
||||
);
|
||||
|
||||
public static LootTable.@NotNull Builder simpleOreDrop(Block oreBlock, Item oreItem) {
|
||||
return LootTable.lootTable()
|
||||
.withPool(LootPool.lootPool()
|
||||
.setRolls(ConstantValue.exactly(1))
|
||||
.add(LootItem.lootTableItem(oreItem)
|
||||
.when(MatchTool.toolMatches(silkTouchPredicates).invert())
|
||||
.when(MatchTool.toolMatches(ItemPredicate.Builder.item()
|
||||
.hasEnchantment(new net.minecraft.advancements.critereon.EnchantmentPredicate(
|
||||
Enchantments.SILK_TOUCH,
|
||||
net.minecraft.advancements.critereon.MinMaxBounds.Ints.atLeast(1)
|
||||
))).invert())
|
||||
.apply(SetItemCountFunction.setCount(UniformGenerator.between(1, 1)))
|
||||
.apply(ApplyBonusCount.addOreBonusCount(fortune))));
|
||||
.apply(ApplyBonusCount.addOreBonusCount(Enchantments.BLOCK_FORTUNE))));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -383,59 +369,17 @@ public class BlockLootTables extends BlockLootSubProvider {
|
|||
*
|
||||
* @param stoneBlock the stone block
|
||||
* @param dropItem the drop item
|
||||
* @param registries the registries
|
||||
* @return the loot table .@ not null builder
|
||||
*/
|
||||
public static LootTable.@NotNull Builder stoneDrop(Block stoneBlock, Item dropItem,
|
||||
HolderLookup.Provider registries) {
|
||||
HolderLookup.RegistryLookup<Enchantment> enchantments = registries.lookupOrThrow(Registries.ENCHANTMENT);
|
||||
Holder<Enchantment> silkTouch = enchantments.getOrThrow(Enchantments.SILK_TOUCH);
|
||||
|
||||
// 创建 Silk Touch 谓词
|
||||
ItemPredicate.Builder silkTouchPredicate = ItemPredicate.Builder.item()
|
||||
.withSubPredicate(
|
||||
ItemSubPredicates.ENCHANTMENTS,
|
||||
ItemEnchantmentsPredicate.enchantments(List.of(
|
||||
new EnchantmentPredicate(silkTouch, MinMaxBounds.Ints.atLeast(1))
|
||||
))
|
||||
);
|
||||
|
||||
public static LootTable.@NotNull Builder stoneDrop(Block stoneBlock, Item dropItem) {
|
||||
return LootTable.lootTable()
|
||||
.withPool(LootPool.lootPool()
|
||||
.setRolls(ConstantValue.exactly(1))
|
||||
.add(LootItem.lootTableItem(dropItem)
|
||||
.when(MatchTool.toolMatches(silkTouchPredicate))));
|
||||
}
|
||||
|
||||
/**
|
||||
* 快速创建基本矿物的掉落表(需要获取附魔的 Holder)
|
||||
* 适用于需要动态获取附魔引用的场景
|
||||
*
|
||||
* @param oreBlock the ore block
|
||||
* @param oreItem the ore item
|
||||
* @param silkTouch the silk touch enchantment holder
|
||||
* @param blockFortune the block fortune enchantment holder
|
||||
* @return the loot table builder
|
||||
*/
|
||||
public static LootTable.@NotNull Builder simpleOreDrop(Block oreBlock, Item oreItem,
|
||||
Holder<Enchantment> silkTouch,
|
||||
Holder<Enchantment> blockFortune) {
|
||||
// 创建 Silk Touch 谓词
|
||||
ItemPredicate.Builder silkTouchPredicate = ItemPredicate.Builder.item()
|
||||
.withSubPredicate(
|
||||
ItemSubPredicates.ENCHANTMENTS,
|
||||
ItemEnchantmentsPredicate.enchantments(List.of(
|
||||
new EnchantmentPredicate(silkTouch, MinMaxBounds.Ints.atLeast(1))
|
||||
))
|
||||
);
|
||||
|
||||
|
||||
return LootTable.lootTable()
|
||||
.withPool(LootPool.lootPool()
|
||||
.setRolls(ConstantValue.exactly(1))
|
||||
.add(LootItem.lootTableItem(oreItem)
|
||||
.when(MatchTool.toolMatches(silkTouchPredicate).invert())
|
||||
.apply(SetItemCountFunction.setCount(UniformGenerator.between(1, 1)))
|
||||
.apply(ApplyBonusCount.addOreBonusCount(blockFortune))));
|
||||
.when(MatchTool.toolMatches(ItemPredicate.Builder.item()
|
||||
.hasEnchantment(new net.minecraft.advancements.critereon.EnchantmentPredicate(
|
||||
Enchantments.SILK_TOUCH,
|
||||
net.minecraft.advancements.critereon.MinMaxBounds.Ints.atLeast(1)
|
||||
))))));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
package top.r3944realms.lib39.example;
|
||||
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import top.r3944realms.lib39.example.core.event.ExCommonEventHandler;
|
||||
import top.r3944realms.lib39.example.core.network.ExNetworkHandler;
|
||||
import top.r3944realms.lib39.example.core.register.ForgeExLib39Items;
|
||||
|
||||
/**
|
||||
* The type Forge lib 39 example.
|
||||
*/
|
||||
public class ForgeLib39Example {
|
||||
private static boolean registered = false;
|
||||
|
||||
/**
|
||||
* Instantiates a new Lib 39 example.
|
||||
*/
|
||||
public ForgeLib39Example() {
|
||||
if (!registered) {
|
||||
init();
|
||||
registerToEventBus();
|
||||
registered = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Init.
|
||||
*/
|
||||
public void init() {
|
||||
IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
|
||||
ForgeExLib39Items.register(modEventBus);
|
||||
ExNetworkHandler.register();
|
||||
}
|
||||
|
||||
private void registerToEventBus() {
|
||||
IEventBus modBus = FMLJavaModLoadingContext.get().getModEventBus();
|
||||
IEventBus gameBus = MinecraftForge.EVENT_BUS;
|
||||
// DistExecutor.unsafeCallWhenOn(Dist.CLIENT, () -> {
|
||||
// modBus.register(ExClientEventHandler.Mod.class);
|
||||
// gameBus.register(ExClientEventHandler.Game.class);
|
||||
// return null;
|
||||
// });
|
||||
// DistExecutor.unsafeCallWhenOn(Dist.DEDICATED_SERVER, () -> {
|
||||
// modBus.register(ExServerEventHandler.Mod.class);
|
||||
// gameBus.register(ExServerEventHandler.Game.class);
|
||||
// return null;
|
||||
// });
|
||||
modBus.register(ExCommonEventHandler.Mod.class);
|
||||
gameBus.register(ExCommonEventHandler.Game.class);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Demonstrate feature.
|
||||
*/
|
||||
public void demonstrateFeature() {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,17 +1,17 @@
|
|||
package top.r3944realms.lib39.example.compat;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.neoforged.bus.api.IEventBus;
|
||||
import net.neoforged.fml.ModList;
|
||||
import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.fml.ModList;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import top.r3944realms.lib39.Lib39;
|
||||
import top.r3944realms.lib39.core.compat.INeoForgeCompat;
|
||||
import top.r3944realms.lib39.core.compat.IForgeCompat;
|
||||
|
||||
/**
|
||||
* The type Lib 39 compat.
|
||||
*/
|
||||
public class Lib39Compat implements INeoForgeCompat {
|
||||
public class Lib39Compat implements IForgeCompat {
|
||||
/**
|
||||
* The Initialized.
|
||||
*/
|
||||
|
|
@ -1,13 +1,13 @@
|
|||
package top.r3944realms.lib39.example.compat;
|
||||
|
||||
import net.neoforged.bus.api.IEventBus;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import top.r3944realms.lib39.Lib39;
|
||||
import top.r3944realms.lib39.core.compat.NeoForgeCompatManager;
|
||||
import top.r3944realms.lib39.core.compat.ForgeCompatManager;
|
||||
|
||||
/**
|
||||
* The type Lib 39 compat manager.
|
||||
*/
|
||||
public class Lib39CompatManager extends NeoForgeCompatManager {
|
||||
public class Lib39CompatManager extends ForgeCompatManager {
|
||||
/**
|
||||
* Instantiates a new Compat manager.
|
||||
*
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
package top.r3944realms.lib39.example.content.data;
|
||||
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.capabilities.CapabilityManager;
|
||||
import net.minecraftforge.common.capabilities.CapabilityToken;
|
||||
import net.minecraftforge.common.capabilities.RegisterCapabilitiesEvent;
|
||||
import net.minecraftforge.event.AttachCapabilitiesEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* The type Ex capability handler.
|
||||
*/
|
||||
public class ExCapabilityHandler {
|
||||
/**
|
||||
* The constant TEST_CAP.
|
||||
*/
|
||||
public static final Capability<AbstractedTestSyncData> TEST_CAP = CapabilityManager.get(new CapabilityToken<>() {});
|
||||
|
||||
/**
|
||||
* Register capability.
|
||||
*
|
||||
* @param event the event
|
||||
*/
|
||||
public static void registerCapability(@NotNull RegisterCapabilitiesEvent event) {
|
||||
event.register(AbstractedTestSyncData.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Attach capability.
|
||||
*
|
||||
* @param event the event
|
||||
*/
|
||||
public static void attachCapability(@NotNull AttachCapabilitiesEvent<?> event) {
|
||||
Object object = event.getObject();
|
||||
if(object instanceof Entity entity) {
|
||||
event.addCapability(TestSyncCapProvider.TEST_SYNC_REL, new TestSyncCapProvider(entity));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
package top.r3944realms.lib39.example.content.data;
|
||||
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.capabilities.ICapabilitySerializable;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import top.r3944realms.lib39.Lib39;
|
||||
|
||||
/**
|
||||
* The type Test sync cap provider.
|
||||
*/
|
||||
public class TestSyncCapProvider implements ICapabilitySerializable<CompoundTag> {
|
||||
|
||||
/**
|
||||
* The constant TEST_SYNC_REL.
|
||||
*/
|
||||
public static final ResourceLocation TEST_SYNC_REL = Lib39.rl(Lib39.MOD_ID, "test_sync_data");
|
||||
private final AbstractedTestSyncData instance;
|
||||
private final LazyOptional<AbstractedTestSyncData> optional;
|
||||
|
||||
/**
|
||||
* Instantiates a new Test sync cap provider.
|
||||
*
|
||||
* @param entity the entity
|
||||
*/
|
||||
public TestSyncCapProvider(Entity entity) {
|
||||
this.instance = new TestSyncData(entity);
|
||||
this.optional = LazyOptional.of(() -> instance);
|
||||
}
|
||||
@Override
|
||||
public @NotNull <T> LazyOptional<T> getCapability(@NotNull Capability<T> cap, @Nullable Direction side) {
|
||||
return ExCapabilityHandler.TEST_CAP.orEmpty(cap, optional);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag serializeNBT() {
|
||||
return instance.serializeNBT();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deserializeNBT(CompoundTag nbt) {
|
||||
instance.deserializeNBT(nbt);
|
||||
}
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@ import net.minecraft.resources.ResourceLocation;
|
|||
import net.minecraft.world.entity.Entity;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import top.r3944realms.lib39.Lib39;
|
||||
import top.r3944realms.lib39.core.sync.INeoForgeUpdate;
|
||||
import top.r3944realms.lib39.core.sync.IForgeUpdate;
|
||||
import top.r3944realms.lib39.util.nbt.NBTReader;
|
||||
import top.r3944realms.lib39.util.nbt.NBTWriter;
|
||||
|
||||
|
|
@ -18,7 +18,7 @@ import java.util.concurrent.atomic.AtomicReference;
|
|||
* 测试同步数据实现
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class TestSyncData extends AbstractedTestSyncData implements INeoForgeUpdate {
|
||||
public class TestSyncData extends AbstractedTestSyncData implements IForgeUpdate {
|
||||
/**
|
||||
* The constant ID.
|
||||
*/
|
||||
|
|
@ -287,8 +287,8 @@ public class TestSyncData extends AbstractedTestSyncData implements INeoForgeUpd
|
|||
}
|
||||
|
||||
@Override
|
||||
public void deserializeNBT(CompoundTag t) {
|
||||
NBTReader.of(t)
|
||||
public void deserializeNBT(CompoundTag nbt) {
|
||||
NBTReader.of(nbt)
|
||||
.intValue(NBT_KEY_INT, integer -> testInt = integer)
|
||||
.string(NBT_KEY_STRING, string -> testString = string)
|
||||
.booleanValue(NBT_KEY_BOOLEAN, bool -> testBoolean = bool)
|
||||
|
|
@ -4,26 +4,26 @@ import net.minecraft.network.chat.Component;
|
|||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.neoforged.neoforge.network.PacketDistributor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import top.r3944realms.lib39.Lib39;
|
||||
import top.r3944realms.lib39.example.content.data.AbstractedTestSyncData;
|
||||
import top.r3944realms.lib39.example.content.data.ExCapabilityHandler;
|
||||
import top.r3944realms.lib39.example.content.data.TestSyncData;
|
||||
import top.r3944realms.lib39.example.core.network.toServer.ClientDataPayload;
|
||||
import top.r3944realms.lib39.example.core.network.ClientDataPacket;
|
||||
import top.r3944realms.lib39.example.core.network.ExNetworkHandler;
|
||||
|
||||
/**
|
||||
* The type Forge fabric item.
|
||||
*/
|
||||
public class NeoForgeFabricItem extends AbstractFabricItem {
|
||||
public class ForgeFabricItem extends AbstractFabricItem {
|
||||
|
||||
/**
|
||||
* Instantiates a new Forge fabric item.
|
||||
*
|
||||
* @param properties the properties
|
||||
*/
|
||||
public NeoForgeFabricItem(Properties properties) {
|
||||
public ForgeFabricItem(Properties properties) {
|
||||
super(properties);
|
||||
}
|
||||
|
||||
|
|
@ -34,7 +34,7 @@ public class NeoForgeFabricItem extends AbstractFabricItem {
|
|||
|
||||
@Override
|
||||
protected void sendClientDataToServer(AbstractedTestSyncData clientData, int targetEntityId) {
|
||||
PacketDistributor.sendToServer(new ClientDataPayload(clientData, targetEntityId));
|
||||
ExNetworkHandler.INSTANCE.sendToServer(new ClientDataPacket(clientData, targetEntityId));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -45,7 +45,7 @@ public class NeoForgeFabricItem extends AbstractFabricItem {
|
|||
*/
|
||||
public static @Nullable AbstractedTestSyncData getStaticData(Entity target) {
|
||||
try {
|
||||
AbstractedTestSyncData abstractData = target.getCapability(ExCapabilityHandler.TEST_CAP);
|
||||
AbstractedTestSyncData abstractData = target.getCapability(ExCapabilityHandler.TEST_CAP).resolve().orElse(null);
|
||||
if (abstractData instanceof TestSyncData) {
|
||||
return abstractData;
|
||||
}
|
||||
|
|
@ -10,14 +10,14 @@ import top.r3944realms.lib39.example.content.data.TestSyncData;
|
|||
/**
|
||||
* The type Forge neo forge item.
|
||||
*/
|
||||
public class NeoForgeNeoForgeItem extends AbstractNeoForgeItem{
|
||||
public class ForgeNeoForgeItem extends AbstractNeoForgeItem{
|
||||
|
||||
/**
|
||||
* Instantiates a new Forge neo forge item.
|
||||
*
|
||||
* @param properties the properties
|
||||
*/
|
||||
public NeoForgeNeoForgeItem(Properties properties) {
|
||||
public ForgeNeoForgeItem(Properties properties) {
|
||||
super(properties);
|
||||
}
|
||||
|
||||
|
|
@ -35,7 +35,7 @@ public class NeoForgeNeoForgeItem extends AbstractNeoForgeItem{
|
|||
@SuppressWarnings("JavaExistingMethodCanBeUsed")
|
||||
public static @Nullable AbstractedTestSyncData getStaticData(Entity target) {
|
||||
try {
|
||||
AbstractedTestSyncData abstractData = target.getCapability(ExCapabilityHandler.TEST_CAP);
|
||||
AbstractedTestSyncData abstractData = target.getCapability(ExCapabilityHandler.TEST_CAP).resolve().orElse(null);
|
||||
if (abstractData instanceof TestSyncData) {
|
||||
return abstractData;
|
||||
}
|
||||
|
|
@ -1,19 +1,16 @@
|
|||
package top.r3944realms.lib39.example.core.event;
|
||||
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.vehicle.Boat;
|
||||
import net.minecraft.world.entity.vehicle.Minecart;
|
||||
import net.neoforged.bus.api.IEventBus;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
import net.neoforged.fml.ModLoadingContext;
|
||||
import net.neoforged.fml.event.lifecycle.FMLConstructModEvent;
|
||||
import net.neoforged.neoforge.capabilities.EntityCapability;
|
||||
import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent;
|
||||
import net.neoforged.neoforge.common.NeoForge;
|
||||
import net.neoforged.neoforge.network.event.RegisterPayloadHandlersEvent;
|
||||
import top.r3944realms.lib39.Lib39NeoForge;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.capabilities.RegisterCapabilitiesEvent;
|
||||
import net.minecraftforge.event.AttachCapabilitiesEvent;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLConstructModEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import top.r3944realms.lib39.api.event.SyncManagerRegisterEvent;
|
||||
import top.r3944realms.lib39.core.compat.ICompatManager;
|
||||
import top.r3944realms.lib39.core.compat.CompatManager;
|
||||
import top.r3944realms.lib39.core.event.CommonEventHandler;
|
||||
import top.r3944realms.lib39.core.sync.CachedSyncManager;
|
||||
import top.r3944realms.lib39.example.compat.Lib39Compat;
|
||||
|
|
@ -21,7 +18,6 @@ import top.r3944realms.lib39.example.compat.Lib39CompatManager;
|
|||
import top.r3944realms.lib39.example.content.data.AbstractedTestSyncData;
|
||||
import top.r3944realms.lib39.example.content.data.ExCapabilityHandler;
|
||||
import top.r3944realms.lib39.example.content.data.TestSyncData;
|
||||
import top.r3944realms.lib39.example.core.network.ExNetworkHandler;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
|
@ -36,6 +32,15 @@ public class ExCommonEventHandler {
|
|||
@SuppressWarnings("unused")
|
||||
|
||||
public static class Game extends ExCommonEventHandler {
|
||||
/**
|
||||
* Attach capability.
|
||||
*
|
||||
* @param event the event
|
||||
*/
|
||||
@SubscribeEvent
|
||||
public static void attachCapability(AttachCapabilitiesEvent<?> event) {
|
||||
ExCapabilityHandler.attachCapability(event);
|
||||
}
|
||||
|
||||
/**
|
||||
* On register sync.
|
||||
|
|
@ -47,16 +52,16 @@ public class ExCommonEventHandler {
|
|||
event.registerSyncManager(
|
||||
TestSyncData.ID,
|
||||
new CachedSyncManager<>() {
|
||||
private final Map<EntityCapability<AbstractedTestSyncData, Void>, AbstractedTestSyncData> syncDataMap = new ConcurrentHashMap<>();
|
||||
private final Map<Capability<AbstractedTestSyncData>, AbstractedTestSyncData> syncDataMap = new ConcurrentHashMap<>();
|
||||
@Override
|
||||
public Map<EntityCapability<AbstractedTestSyncData, Void>, AbstractedTestSyncData> getSyncMap() {
|
||||
public Map<Capability<AbstractedTestSyncData>, AbstractedTestSyncData> getSyncMap() {
|
||||
return syncDataMap;
|
||||
}
|
||||
},
|
||||
ExCapabilityHandler.TEST_CAP
|
||||
|
||||
);
|
||||
event.addAllowEntityClass(TestSyncData.ID, LivingEntity.class, Boat.class, Minecart.class);
|
||||
event.addAllowEntityClass(TestSyncData.ID, LivingEntity.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -66,17 +71,21 @@ public class ExCommonEventHandler {
|
|||
* The type Mod.
|
||||
*/
|
||||
public static class Mod extends ExCommonEventHandler {
|
||||
/**
|
||||
* The constant EVENT_BUS.
|
||||
*/
|
||||
public static final IEventBus EVENT_BUS = FMLJavaModLoadingContext.get().getModEventBus();
|
||||
|
||||
/**
|
||||
* Gets compat manager.
|
||||
*
|
||||
* @return the compat manager
|
||||
*/
|
||||
public static ICompatManager getOrCreateCompatManager() {
|
||||
public static CompatManager getOrCreateCompatManager() {
|
||||
if (compatManager == null) {
|
||||
synchronized (CommonEventHandler.Mod.class) {
|
||||
if (compatManager == null) {
|
||||
compatManager = new Lib39CompatManager("compat", Lib39NeoForge.modEventBus, NeoForge.EVENT_BUS);
|
||||
compatManager = new Lib39CompatManager("compat", EVENT_BUS, MinecraftForge.EVENT_BUS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -86,7 +95,7 @@ public class ExCommonEventHandler {
|
|||
/**
|
||||
* The Compat manager.
|
||||
*/
|
||||
static volatile ICompatManager compatManager;
|
||||
static volatile CompatManager compatManager;
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -97,7 +106,7 @@ public class ExCommonEventHandler {
|
|||
@SubscribeEvent
|
||||
public static void onConstructMod(FMLConstructModEvent event) {
|
||||
event.enqueueWork(() -> {
|
||||
ICompatManager orCreateCompatManager = Mod.getOrCreateCompatManager();
|
||||
CompatManager orCreateCompatManager = Mod.getOrCreateCompatManager();
|
||||
orCreateCompatManager
|
||||
.registerCompat(Lib39Compat.ID, Lib39Compat.INSTANCE);
|
||||
orCreateCompatManager.initialize();
|
||||
|
|
@ -114,15 +123,5 @@ public class ExCommonEventHandler {
|
|||
ExCapabilityHandler.registerCapability(event);
|
||||
}
|
||||
|
||||
/**
|
||||
* On register payload.
|
||||
*
|
||||
* @param event the event
|
||||
*/
|
||||
@SubscribeEvent
|
||||
public static void onRegisterPayload (RegisterPayloadHandlersEvent event) {
|
||||
ExNetworkHandler.register(event);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
package top.r3944realms.lib39.example.core.network;
|
||||
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraftforge.network.NetworkEvent;
|
||||
import top.r3944realms.lib39.example.content.data.AbstractedTestSyncData;
|
||||
import top.r3944realms.lib39.example.content.data.TestSyncData;
|
||||
import top.r3944realms.lib39.example.content.item.ForgeFabricItem;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* The type Client data packet.
|
||||
*/
|
||||
public class ClientDataPacket {
|
||||
private final AbstractedTestSyncData clientData;
|
||||
private final int targetEntityId;
|
||||
|
||||
/**
|
||||
* Instantiates a new Client data packet.
|
||||
*
|
||||
* @param clientData the client data
|
||||
* @param targetEntityId the target entity id
|
||||
*/
|
||||
public ClientDataPacket(AbstractedTestSyncData clientData, int targetEntityId) {
|
||||
this.clientData = clientData;
|
||||
this.targetEntityId = targetEntityId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new Client data packet.
|
||||
*
|
||||
* @param buf the buf
|
||||
*/
|
||||
public ClientDataPacket(FriendlyByteBuf buf) {
|
||||
this.clientData = TestSyncData.staticFromBytes(buf);
|
||||
this.targetEntityId = buf.readInt();
|
||||
}
|
||||
|
||||
/**
|
||||
* To bytes.
|
||||
*
|
||||
* @param buf the buf
|
||||
*/
|
||||
public void toBytes(FriendlyByteBuf buf) {
|
||||
clientData.toBytes(buf);
|
||||
buf.writeInt(targetEntityId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle.
|
||||
*
|
||||
* @param supplier the supplier
|
||||
*/
|
||||
public void handle(Supplier<NetworkEvent.Context> supplier) {
|
||||
NetworkEvent.Context context = supplier.get();
|
||||
context.enqueueWork(() -> {
|
||||
ServerPlayer player = context.getSender();
|
||||
if (player != null) {
|
||||
// 处理客户端发送的数据
|
||||
handleClientData(player, clientData, targetEntityId);
|
||||
}
|
||||
});
|
||||
context.setPacketHandled(true);
|
||||
}
|
||||
|
||||
private void handleClientData(ServerPlayer player, AbstractedTestSyncData clientData, int targetEntityId) {
|
||||
ForgeFabricItem.handleClientDataFromPacket(player, clientData, targetEntityId);
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user