feat: 迁移到多加载器版本,还有点小BUG,待修
This commit is contained in:
parent
0c62d360d9
commit
099f29e76f
|
|
@ -48,10 +48,6 @@ repositories {
|
|||
name = 'BlameJared'
|
||||
url = 'https://maven.blamejared.com'
|
||||
}
|
||||
|
||||
maven {
|
||||
url "https://maven.blamejared.com/"
|
||||
}
|
||||
}
|
||||
|
||||
// Declare capabilities on the outgoing configurations.
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import org.jetbrains.annotations.Contract;
|
|||
import org.jetbrains.annotations.NotNull;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import top.r3944realms.lib39.example.Lib39Example;
|
||||
import top.r3944realms.lib39.platform.Services;
|
||||
|
||||
public class Lib39 {
|
||||
|
|
@ -67,7 +68,7 @@ public class Lib39 {
|
|||
* @return the boolean
|
||||
*/
|
||||
public static boolean shouldRegisterExamples() {
|
||||
return !Services.PLATFORM.isDevelopmentEnvironment() || Boolean.getBoolean(ENABLE_EXAMPLES_PROPERTY_KEY);
|
||||
return Services.PLATFORM.isDevelopmentEnvironment() || Boolean.getBoolean(ENABLE_EXAMPLES_PROPERTY_KEY);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -75,18 +76,17 @@ public class Lib39 {
|
|||
* Register examples.
|
||||
*/
|
||||
static void registerExamples() {
|
||||
LOGGER.info("[Lib39] Starting example demonstrations");
|
||||
LOGGER.info("[Lib39-Common] Starting example demonstrations");
|
||||
try {
|
||||
// 创建示例实例并演示功能
|
||||
Lib39Example example = new Lib39Example();
|
||||
example.demonstrateFeature();
|
||||
|
||||
LOGGER.info("[Lib39] Example demonstrations completed successfully");
|
||||
LOGGER.info("[Lib39-Common] Example demonstrations completed successfully");
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("[Lib39] Failed to demonstrate examples", e);
|
||||
LOGGER.error("[Lib39-Common] Failed to demonstrate examples", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* The type Mod info.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ public class Lib39HelpCommand extends SimpleHelpCommand {
|
|||
/**
|
||||
* Instantiates a new Lib 39 help command.
|
||||
*
|
||||
* @param event the event
|
||||
*/
|
||||
public Lib39HelpCommand(CommandDispatcher<CommandSourceStack> dispatcher, CommandBuildContext context) {
|
||||
super(dispatcher, context);
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ public class Lib39RecipeProvider extends RecipeProvider {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void buildRecipes(@NotNull Consumer<FinishedRecipe> consumer) {
|
||||
public void buildRecipes(@NotNull Consumer<FinishedRecipe> consumer) {
|
||||
ShapelessRecipeBuilder.shapeless(RecipeCategory.MISC, Lib39Items.DOLL.get())
|
||||
.requires(ItemTags.WOOL)
|
||||
.requires(Items.ARMOR_STAND)
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import net.minecraft.resources.ResourceLocation;
|
|||
import net.minecraft.world.item.ItemDisplayContext;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import top.r3944realms.lib39.Lib39;
|
||||
import top.r3944realms.lib39.client.model.DollModel;
|
||||
import top.r3944realms.lib39.content.item.DollItem;
|
||||
import top.r3944realms.lib39.util.GameProfileHelper;
|
||||
|
|
@ -24,15 +25,29 @@ import top.r3944realms.lib39.util.lang.Pair;
|
|||
*/
|
||||
public class DollItemRenderer extends BlockEntityWithoutLevelRenderer {
|
||||
private static DollItemRenderer instance;
|
||||
private final DollModel dollModel;
|
||||
private DollModel dollModel;
|
||||
private boolean initialized = false;
|
||||
private DollItemRenderer() {
|
||||
super(
|
||||
Minecraft.getInstance().getBlockEntityRenderDispatcher(),
|
||||
Minecraft.getInstance().getEntityModels()
|
||||
);
|
||||
this.dollModel = new DollModel(
|
||||
Minecraft.getInstance().getEntityModels().bakeLayer(DollModel.LAYER_LOCATION)
|
||||
);
|
||||
}
|
||||
private void lazyInit() {
|
||||
if (!initialized) {
|
||||
try {
|
||||
// 确保 Minecraft 实例已初始化
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
mc.getEntityModels();
|
||||
this.dollModel = new DollModel(
|
||||
mc.getEntityModels().bakeLayer(DollModel.LAYER_LOCATION)
|
||||
);
|
||||
initialized = true;
|
||||
Lib39.LOGGER.info("Doll model initialized successfully");
|
||||
} catch (Exception e) {
|
||||
Lib39.LOGGER.error("Failed to initialize doll model", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -52,6 +67,7 @@ public class DollItemRenderer extends BlockEntityWithoutLevelRenderer {
|
|||
if (!(stack.getItem() instanceof DollItem)) {
|
||||
return;
|
||||
}
|
||||
lazyInit();
|
||||
GameProfile profile = GameProfileHelper.getProfileFromItemStack(stack);
|
||||
Pair<ResourceLocation, Boolean> resourceLocationBooleanPair = loadSkin(profile);
|
||||
ResourceLocation playerSkin = resourceLocationBooleanPair.first;
|
||||
|
|
|
|||
|
|
@ -36,33 +36,17 @@ public class Lib39Shaders {
|
|||
return selectionShader;
|
||||
}
|
||||
|
||||
public static void setRingShader(ShaderInstance ringShader) {
|
||||
Lib39Shaders.ringShader = ringShader;
|
||||
}
|
||||
|
||||
public static void setSelectionShader(ShaderInstance selectionShader) {
|
||||
Lib39Shaders.selectionShader = selectionShader;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Selection shader.
|
||||
*/
|
||||
static ShaderInstance selectionShader;
|
||||
|
||||
/**
|
||||
* 在资源重载时注册/重新加载着色器
|
||||
*/
|
||||
public static void registerShaders(ResourceProvider resourceProvider) {
|
||||
try {
|
||||
// 注册ring着色器
|
||||
ringShader = new ShaderInstance(
|
||||
resourceProvider,
|
||||
"ring",
|
||||
DefaultVertexFormat.POSITION_COLOR
|
||||
);
|
||||
|
||||
// 注册selection着色器
|
||||
selectionShader = new ShaderInstance(
|
||||
resourceProvider,
|
||||
"selection",
|
||||
DefaultVertexFormat.POSITION_COLOR
|
||||
);
|
||||
|
||||
} catch (IOException e) {
|
||||
// 着色器加载失败时的处理
|
||||
Lib39.LOGGER.error("Failed to load lib39 shaders", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,9 @@ dependencies {
|
|||
officialMojangMappings()
|
||||
parchment("org.parchmentmc.data:parchment-${parchment_minecraft}:${parchment_version}@zip")
|
||||
}
|
||||
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}"
|
||||
implementation group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.1'
|
||||
|
|
@ -17,6 +20,12 @@ dependencies {
|
|||
}
|
||||
|
||||
loom {
|
||||
def commonResources = project(':common').file('src/main/resources/').getAbsolutePath().toString()
|
||||
def fabricResources = file('src/main/resources/').getAbsolutePath().toString()
|
||||
def fabricBuildResources = file('build/resources/main/').getAbsolutePath().toString()
|
||||
def commonBuildResources = project(':common').file('build/resources/main/').getAbsolutePath().toString()
|
||||
def generatedOutput = project(':common').file('src/generated/resources/').getAbsolutePath().toString()
|
||||
|
||||
if (project(":common").file("src/main/resources/${mod_id}.accesswidener").exists()) {
|
||||
accessWidenerPath.set(project(":common").file("src/main/resources/${mod_id}.accesswidener"))
|
||||
}
|
||||
|
|
@ -29,12 +38,39 @@ loom {
|
|||
setConfigName("Fabric Client")
|
||||
ideConfigGenerated(true)
|
||||
runDir("run")
|
||||
|
||||
def args = [
|
||||
"-Dlib39.modid=${mod_id}".toString(),
|
||||
"-Dlib39.output=${generatedOutput}".toString(),
|
||||
"-Dlib39.existing.fabric=${fabricResources}".toString(),
|
||||
"-Dlib39.existing.common=${commonResources}".toString(),
|
||||
"-Dlib39.existing.fabricBuild=${fabricBuildResources}".toString(),
|
||||
"-Dlib39.existing.commonBuild=${commonBuildResources}".toString()
|
||||
]
|
||||
vmArgs.addAll(args)
|
||||
|
||||
// 也可以添加JVM参数
|
||||
vmArgs.addAll(
|
||||
"-Dfabric.log.level=info",
|
||||
"-Dmixin.debug.export=true"
|
||||
)
|
||||
}
|
||||
|
||||
server {
|
||||
server()
|
||||
setConfigName("Fabric Server")
|
||||
ideConfigGenerated(true)
|
||||
runDir("run")
|
||||
|
||||
def args = [
|
||||
"-Dlib39.modid=${mod_id}".toString(),
|
||||
"-Dlib39.output=${generatedOutput}".toString(),
|
||||
"-Dlib39.existing.fabric=${fabricResources}".toString(),
|
||||
"-Dlib39.existing.common=${commonResources}".toString(),
|
||||
"-Dlib39.existing.fabricBuild=${fabricBuildResources}".toString(),
|
||||
"-Dlib39.existing.commonBuild=${commonBuildResources}".toString()
|
||||
]
|
||||
vmArgs.addAll(args)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package top.r3944realms.lib39;
|
|||
import net.fabricmc.api.ModInitializer;
|
||||
import top.r3944realms.lib39.core.event.CommonEventHandler;
|
||||
import top.r3944realms.lib39.core.register.*;
|
||||
import top.r3944realms.lib39.example.FabricLib39Example;
|
||||
|
||||
public class Lib39Fabric implements ModInitializer {
|
||||
|
||||
|
|
@ -15,6 +16,26 @@ public class Lib39Fabric implements ModInitializer {
|
|||
FabricLib39BlockEntities.init();
|
||||
FabricLib39SoundEvents.init();
|
||||
CommonEventHandler.initCommon();
|
||||
if (Lib39.shouldRegisterExamples()) {
|
||||
Lib39.LOGGER.info("[Lib39-Fabric] Registering Examples");
|
||||
registerExamples();
|
||||
}
|
||||
Lib39.LOGGER.info("[Lib39-Fabric] Finished Initializing.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Register examples.
|
||||
*/
|
||||
static void registerExamples() {
|
||||
Lib39.LOGGER.info("[Lib39-Fabric] Starting example demonstrations");
|
||||
try {
|
||||
// 创建示例实例并演示功能
|
||||
FabricLib39Example example = new FabricLib39Example();
|
||||
example.demonstrateFeature();
|
||||
|
||||
Lib39.LOGGER.info("[Lib39-Fabric] Example demonstrations completed successfully");
|
||||
} catch (Exception e) {
|
||||
Lib39.LOGGER.error("[Lib39-Fabric] Failed to demonstrate examples", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,24 @@
|
|||
package top.r3944realms.lib39;
|
||||
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import top.r3944realms.lib39.client.ItemRenderRegister;
|
||||
import top.r3944realms.lib39.client.ShaderRegister;
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents;
|
||||
import top.r3944realms.lib39.client.BlockEntityRendererRegistry;
|
||||
import top.r3944realms.lib39.client.ItemRendererRegistry;
|
||||
import top.r3944realms.lib39.client.LayerDefinitionRegistry;
|
||||
import top.r3944realms.lib39.client.ShaderRegistry;
|
||||
import top.r3944realms.lib39.core.event.CommonEventHandler;
|
||||
import top.r3944realms.lib39.core.network.NetworkHandler;
|
||||
|
||||
public class Lib39FabricClient implements ClientModInitializer {
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
ShaderRegister.register();
|
||||
ItemRenderRegister.register();
|
||||
NetworkHandler.registerClientReceivers();
|
||||
CommonEventHandler.initClient();
|
||||
ClientLifecycleEvents.CLIENT_STARTED.register( r -> {
|
||||
ShaderRegistry.register();
|
||||
LayerDefinitionRegistry.register();
|
||||
BlockEntityRendererRegistry.register();
|
||||
ItemRendererRegistry.register();
|
||||
NetworkHandler.registerClientReceivers();
|
||||
CommonEventHandler.initClient();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,72 @@
|
|||
package top.r3944realms.lib39.api.callback;
|
||||
|
||||
import net.fabricmc.fabric.api.event.Event;
|
||||
import net.fabricmc.fabric.api.event.EventFactory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
/**
|
||||
* Fabric版的铁砧更新事件,对应Forge的AnvilUpdateEvent
|
||||
*/
|
||||
public class AnvilUpdateCallback {
|
||||
|
||||
/**
|
||||
* 铁砧更新事件接口
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface AnvilUpdate {
|
||||
/**
|
||||
* 当铁砧内容改变时调用
|
||||
* @param left 左侧输入槽的物品
|
||||
* @param right 右侧输入槽的物品
|
||||
* @param outputSlot 输出槽的物品
|
||||
* @param name 输入的名字
|
||||
* @param baseCost 基础花费
|
||||
* @param player 玩家
|
||||
* @return AnvilUpdateResult 包含处理结果,如果返回null则继续默认处理
|
||||
*/
|
||||
AnvilUpdateResult onAnvilUpdate(ItemStack left, ItemStack right, ItemStack outputSlot,
|
||||
String name, int baseCost, Player player);
|
||||
}
|
||||
|
||||
/**
|
||||
* 铁砧更新结果
|
||||
*/
|
||||
public record AnvilUpdateResult(ItemStack output, int cost, int materialCost, boolean cancel) {
|
||||
|
||||
public static AnvilUpdateResult cancelled() {
|
||||
return new AnvilUpdateResult(ItemStack.EMPTY, 0, 0, true);
|
||||
}
|
||||
|
||||
public static AnvilUpdateResult passed() {
|
||||
return new AnvilUpdateResult(ItemStack.EMPTY, 0, 0, false);
|
||||
}
|
||||
|
||||
public static AnvilUpdateResult withOutput(ItemStack output, int cost, int materialCost) {
|
||||
return new AnvilUpdateResult(output, cost, materialCost, false);
|
||||
}
|
||||
|
||||
public boolean shouldOverride() {
|
||||
return !output.isEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
// 创建事件实例
|
||||
public static final Event<AnvilUpdate> EVENT = EventFactory.createArrayBacked(
|
||||
AnvilUpdate.class,
|
||||
(listeners) -> (left, right, outputSlot, name, baseCost, player) -> {
|
||||
for (AnvilUpdate listener : listeners) {
|
||||
AnvilUpdateResult result = listener.onAnvilUpdate(left, right, outputSlot, name, baseCost, player);
|
||||
if (result != null) {
|
||||
if (result.cancel()) {
|
||||
return result; // 取消事件
|
||||
}
|
||||
if (result.shouldOverride()) {
|
||||
return result; // 返回自定义结果
|
||||
}
|
||||
}
|
||||
}
|
||||
return AnvilUpdateResult.passed(); // 继续默认处理
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
package top.r3944realms.lib39.client;
|
||||
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderers;
|
||||
import top.r3944realms.lib39.client.renderer.block.DollBlockEntityRenderer;
|
||||
import top.r3944realms.lib39.core.register.Lib39BlockEntities;
|
||||
|
||||
public class BlockEntityRendererRegistry {
|
||||
public static void register() {
|
||||
BlockEntityRenderers.register(
|
||||
Lib39BlockEntities.DOLL_BLOCK_ENTITY.get(),
|
||||
DollBlockEntityRenderer::new
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -4,7 +4,7 @@ import net.fabricmc.fabric.api.client.rendering.v1.BuiltinItemRendererRegistry;
|
|||
import top.r3944realms.lib39.client.renderer.item.DollItemRenderer;
|
||||
import top.r3944realms.lib39.core.register.Lib39Items;
|
||||
|
||||
public class ItemRenderRegister {
|
||||
public class ItemRendererRegistry {
|
||||
public static void register() {
|
||||
BuiltinItemRendererRegistry.INSTANCE.register(
|
||||
Lib39Items.DOLL.get(),
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
package top.r3944realms.lib39.client;
|
||||
|
||||
import net.fabricmc.fabric.api.client.rendering.v1.EntityModelLayerRegistry;
|
||||
import top.r3944realms.lib39.client.model.DollModel;
|
||||
|
||||
public class LayerDefinitionRegistry {
|
||||
public static void register() {
|
||||
EntityModelLayerRegistry.registerModelLayer(
|
||||
DollModel.LAYER_LOCATION, DollModel::createBodyLayer
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
package top.r3944realms.lib39.client;
|
||||
|
||||
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
|
||||
import net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.packs.PackType;
|
||||
import net.minecraft.server.packs.resources.ResourceManager;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import top.r3944realms.lib39.Lib39;
|
||||
import top.r3944realms.lib39.client.shader.Lib39Shaders;
|
||||
|
||||
public class ShaderRegister {
|
||||
public static void register() {
|
||||
ResourceManagerHelper.get(PackType.CLIENT_RESOURCES).registerReloadListener(new SimpleSynchronousResourceReloadListener() {
|
||||
@Override
|
||||
public void onResourceManagerReload(@NotNull ResourceManager resourceManager) {
|
||||
Lib39Shaders.registerShaders(resourceManager);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getFabricId() {
|
||||
return Lib39.rl("shaders");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
package top.r3944realms.lib39.client;
|
||||
|
||||
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
|
||||
import net.fabricmc.fabric.api.client.rendering.v1.CoreShaderRegistrationCallback;
|
||||
import top.r3944realms.lib39.Lib39;
|
||||
import top.r3944realms.lib39.client.shader.Lib39Shaders;
|
||||
|
||||
public class ShaderRegistry {
|
||||
public static void register() {
|
||||
CoreShaderRegistrationCallback.EVENT.register( context -> {
|
||||
context.register(
|
||||
Lib39.rl("ring"), DefaultVertexFormat.POSITION_COLOR, Lib39Shaders::setRingShader
|
||||
);
|
||||
context.register(
|
||||
Lib39.rl("selection"), DefaultVertexFormat.POSITION_COLOR, Lib39Shaders::setSelectionShader
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -1,29 +1,38 @@
|
|||
package top.r3944realms.lib39.core.event;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerEntityEvents;
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerWorldEvents;
|
||||
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
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.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.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.SyncManagerRegisterCallback;
|
||||
import top.r3944realms.lib39.api.callback.client.ClientWorldCallback;
|
||||
import top.r3944realms.lib39.core.sync.CachedSyncManager;
|
||||
import top.r3944realms.lib39.base.command.Lib39HelpCommand;
|
||||
import top.r3944realms.lib39.content.item.DollItem;
|
||||
import top.r3944realms.lib39.core.register.Lib39Items;
|
||||
import top.r3944realms.lib39.core.sync.ISyncData;
|
||||
import top.r3944realms.lib39.core.sync.SyncData2LookupManager;
|
||||
import top.r3944realms.lib39.example.content.data.AbstractedTestSyncData;
|
||||
import top.r3944realms.lib39.example.content.data.TestSyncData;
|
||||
import top.r3944realms.lib39.util.GameProfileHelper;
|
||||
import top.r3944realms.lib39.util.IClientOnly;
|
||||
import top.r3944realms.lib39.util.ILevelHelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
|
@ -59,6 +68,7 @@ public class CommonEventHandler {
|
|||
syncData2Manager = new SyncData2LookupManager();
|
||||
isSync2MInitialized = true;
|
||||
sl = serverLevel;
|
||||
ILevelHelper.LevelHelper.SERVER.setLevel(serverLevel);
|
||||
SyncManagerRegisterCallback.EVENT.invoker().registerSyncManagers(new SyncManagerRegisterCallback.SyncManagerRegistrar((syncData2Manager)));
|
||||
Lib39.LOGGER.info("SyncData2Manager initialized on Sever load");
|
||||
}
|
||||
|
|
@ -68,8 +78,8 @@ public class CommonEventHandler {
|
|||
|
||||
public static void onServerWorldUnLoad(MinecraftServer server, @NotNull ServerLevel serverLevel) {
|
||||
if (!serverLevel.dimension().equals(Level.OVERWORLD)) return;
|
||||
|
||||
sl = null;
|
||||
ILevelHelper.LevelHelper.SERVER.setLevel(null);
|
||||
isSync2MInitialized = false;
|
||||
}
|
||||
|
||||
|
|
@ -118,47 +128,62 @@ public class CommonEventHandler {
|
|||
}
|
||||
|
||||
public static void initCommon() {
|
||||
try {
|
||||
Class.forName("top.r3944realms.lib39.base.command.Lib39CommandHelpManager");
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
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())));
|
||||
}
|
||||
SyncManagerRegisterCallback.EVENT.register(registrar -> {
|
||||
registrar.register(
|
||||
TestSyncData.ID,
|
||||
new CachedSyncManager<>() {
|
||||
private final Map<Entity, AbstractedTestSyncData> syncDataMap = new ConcurrentHashMap<>();
|
||||
|
||||
@Override
|
||||
public Map<Entity, AbstractedTestSyncData> getSyncMap() {
|
||||
return syncDataMap;
|
||||
}
|
||||
},
|
||||
AbstractedTestSyncData.class
|
||||
);
|
||||
return ActionResult.PASS;
|
||||
AnvilUpdateCallback.EVENT.register((left, right, outputSlot, name, baseCost, player) -> {
|
||||
if (left.getItem() instanceof DollItem && 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(left.getCount());
|
||||
return AnvilUpdateCallback.AnvilUpdateResult.withOutput(copied, 1, 1);
|
||||
} else {
|
||||
ItemStack defaultInstance = Items.BARRIER.getDefaultInstance();
|
||||
defaultInstance.setHoverName(Component.translatable("invalid.player_name.too_long"));
|
||||
return AnvilUpdateCallback.AnvilUpdateResult.withOutput(defaultInstance, 0, 0);
|
||||
}
|
||||
});
|
||||
ServerTickEvents.END_SERVER_TICK.register(CommonEventHandler::onServerTick);
|
||||
ServerWorldEvents.LOAD.register(CommonEventHandler::onServerWorldLoad);
|
||||
ServerWorldEvents.UNLOAD.register(CommonEventHandler::onServerWorldUnLoad);
|
||||
ServerEntityEvents.ENTITY_LOAD.register(CommonEventHandler::onEntityJoinWorld);
|
||||
ServerEntityEvents.ENTITY_UNLOAD.register(CommonEventHandler::onEntityLeaveWorld);
|
||||
CommandRegistrationCallback.EVENT.register((commandDispatcher, commandBuildContext, commandSelection) -> {
|
||||
new Lib39HelpCommand(commandDispatcher, commandBuildContext);
|
||||
});
|
||||
}
|
||||
public static class ClientOpt implements IClientOnly {
|
||||
public static void onClientWorldLoad(@NotNull ClientLevel clientLevel) {
|
||||
synchronized (CommonEventHandler.class) {
|
||||
synchronized (CommonEventHandler.ClientOpt.class) {
|
||||
IClientOnly.check(() -> {
|
||||
if (!clientLevel.dimension().equals(Level.OVERWORLD)) return;
|
||||
if (!isSync2MInitialized) {
|
||||
syncData2Manager = new SyncData2LookupManager();
|
||||
SyncManagerRegisterCallback.EVENT.invoker().registerSyncManagers(new SyncManagerRegisterCallback.SyncManagerRegistrar(syncData2Manager));
|
||||
Lib39.LOGGER.info("SyncData2Manager initialized on Client load");
|
||||
ILevelHelper.LevelHelper.CLIENT.setLevel(clientLevel);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
public static void onClientWorldUnLoad(@NotNull ClientLevel clientLevel) {
|
||||
synchronized (CommonEventHandler.ClientOpt.class) {
|
||||
IClientOnly.check(() -> ILevelHelper.LevelHelper.CLIENT.setLevel(null));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void initClient() {
|
||||
ClientWorldCallback.LOAD.register(ClientOpt::onClientWorldLoad);
|
||||
ClientWorldCallback.LOAD.register(ClientOpt::onClientWorldUnLoad);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ public class FabricLib39BlockEntities {
|
|||
}
|
||||
@Contract(pure = true)
|
||||
public static <T extends BlockEntityType<?>> @NotNull Supplier<T> register(String path, T blockEntityType) {
|
||||
return () -> Registry.register(BuiltInRegistries.BLOCK_ENTITY_TYPE, Lib39.rl(path), blockEntityType);
|
||||
T item = Registry.register(BuiltInRegistries.BLOCK_ENTITY_TYPE, Lib39.rl(path), blockEntityType);
|
||||
return () -> item;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,8 @@ public class FabricLib39Blocks {
|
|||
}
|
||||
@Contract(pure = true)
|
||||
public static <T extends Block> @NotNull Supplier<T> register(String path, T block) {
|
||||
return () -> Registry.register(BuiltInRegistries.BLOCK, Lib39.rl(path), block);
|
||||
T item = Registry.register(BuiltInRegistries.BLOCK, Lib39.rl(path), block);
|
||||
return () -> item;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ public class FabricLib39Items {
|
|||
}
|
||||
@Contract(pure = true)
|
||||
public static <T extends Item> @NotNull Supplier<T> register(String path, T item) {
|
||||
return () -> Registry.register(BuiltInRegistries.ITEM, Lib39.rl(path), item);
|
||||
T register = Registry.register(BuiltInRegistries.ITEM, Lib39.rl(path), item);
|
||||
return () -> register;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ public class FabricLib39SoundEvents {
|
|||
}
|
||||
@Contract(pure = true)
|
||||
public static <T extends SoundEvent> @NotNull Supplier<T> register(String path, T soundEvent) {
|
||||
return () -> Registry.register(BuiltInRegistries.SOUND_EVENT, Lib39.rl(path), soundEvent);
|
||||
T register = Registry.register(BuiltInRegistries.SOUND_EVENT, Lib39.rl(path), soundEvent);
|
||||
return () -> register;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,35 @@
|
|||
package top.r3944realms.lib39.example;
|
||||
|
||||
import top.r3944realms.lib39.core.compat.CompatManager;
|
||||
import top.r3944realms.lib39.example.core.compat.Lib39Compat;
|
||||
import top.r3944realms.lib39.example.core.event.ExCommonEventHandler;
|
||||
import top.r3944realms.lib39.example.core.network.ExNetworkHandler;
|
||||
import top.r3944realms.lib39.example.core.register.FabricExLib39Items;
|
||||
|
||||
public class FabricLib39Example {
|
||||
private static boolean registered = false;
|
||||
/**
|
||||
* Instantiates a new Lib 39 example.
|
||||
*/
|
||||
public FabricLib39Example() {
|
||||
if (!registered) {
|
||||
init();
|
||||
registered = true;
|
||||
}
|
||||
}
|
||||
public void init() {
|
||||
ExCommonEventHandler.init();
|
||||
FabricExLib39Items.init();
|
||||
ExNetworkHandler.registerServerReceivers();
|
||||
CompatManager orCreateCompatManager = ExCommonEventHandler.getOrCreateCompatManager();
|
||||
orCreateCompatManager.registerCompat(Lib39Compat.ID, Lib39Compat.INSTANCE);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Demonstrate feature.
|
||||
*/
|
||||
public void demonstrateFeature() {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
package top.r3944realms.lib39.example;
|
||||
|
||||
public class FabricLib39Examples {
|
||||
//todo:注册网络
|
||||
}
|
||||
|
|
@ -47,7 +47,7 @@ public class FabricItem extends AbstractFabricItem {
|
|||
|
||||
public static @Nullable AbstractedTestSyncData getStaticData(Entity target) {
|
||||
try {
|
||||
AbstractedTestSyncData abstractData = EntityApiLookup.get(TestSyncData.ID, AbstractedTestSyncData.class,null).find(target, null);
|
||||
AbstractedTestSyncData abstractData = EntityApiLookup.get(TestSyncData.ID, AbstractedTestSyncData.class, Void.class).find(target, null);
|
||||
if (abstractData instanceof TestSyncData) {
|
||||
return abstractData;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
package top.r3944realms.lib39.example.content.item;
|
||||
|
||||
import net.fabricmc.fabric.api.lookup.v1.entity.EntityApiLookup;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import top.r3944realms.lib39.example.content.data.AbstractedTestSyncData;
|
||||
import top.r3944realms.lib39.example.content.data.TestSyncData;
|
||||
import top.r3944realms.lib39.example.content.item.AbstractNeoForgeItem;
|
||||
|
||||
public class NeoForgeItem extends AbstractNeoForgeItem {
|
||||
|
|
@ -12,6 +14,6 @@ public class NeoForgeItem extends AbstractNeoForgeItem {
|
|||
|
||||
@Override
|
||||
protected AbstractedTestSyncData getData(Entity entity) {
|
||||
return null;
|
||||
return EntityApiLookup.get(TestSyncData.ID, AbstractedTestSyncData.class, null).find(entity, null);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,51 @@
|
|||
package top.r3944realms.lib39.example.core.compat;
|
||||
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import top.r3944realms.lib39.Lib39;
|
||||
import top.r3944realms.lib39.core.compat.ICompat;
|
||||
|
||||
/**
|
||||
* The type Lib 39 compat.
|
||||
*/
|
||||
public class Lib39Compat implements ICompat {
|
||||
boolean initialized = false;
|
||||
/**
|
||||
* The constant INSTANCE.
|
||||
*/
|
||||
public static Lib39Compat INSTANCE = new Lib39Compat();
|
||||
/**
|
||||
* The constant ID.
|
||||
*/
|
||||
public static ResourceLocation ID = Lib39.rl("lib39");
|
||||
|
||||
@Override
|
||||
public void setInitialize(boolean initialize) {
|
||||
this.initialized = initialize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInitialized() {
|
||||
return initialized;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation id() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isModLoaded() {
|
||||
return FabricLoader.getInstance().isModLoaded("lib39");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
Lib39.LOGGER.info("[Lib39 Compat] Init!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadComplete() {
|
||||
Lib39.LOGGER.info("[Lib39 Compat] Complete!");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package top.r3944realms.lib39.example.core.compat;
|
||||
|
||||
import top.r3944realms.lib39.Lib39;
|
||||
import top.r3944realms.lib39.core.compat.CompatManager;
|
||||
|
||||
public class Lib39CompatManager extends CompatManager {
|
||||
/**
|
||||
* Instantiates a new Compat manager.
|
||||
*
|
||||
* @param path the path
|
||||
*/
|
||||
public Lib39CompatManager(String path) {
|
||||
super(Lib39.rl(path));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
package top.r3944realms.lib39.example.core.event;
|
||||
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import top.r3944realms.lib39.api.callback.ActionResult;
|
||||
import top.r3944realms.lib39.api.callback.SyncManagerRegisterCallback;
|
||||
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.content.data.AbstractedTestSyncData;
|
||||
import top.r3944realms.lib39.example.content.data.TestSyncData;
|
||||
import top.r3944realms.lib39.example.core.compat.Lib39CompatManager;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class ExCommonEventHandler {
|
||||
/**
|
||||
* Gets compat manager.
|
||||
*
|
||||
* @return the compat manager
|
||||
*/
|
||||
public static CompatManager getOrCreateCompatManager() {
|
||||
if (compatManager == null) {
|
||||
synchronized (CommonEventHandler.class) {
|
||||
if (compatManager == null) {
|
||||
compatManager = new Lib39CompatManager("compat");
|
||||
}
|
||||
}
|
||||
}
|
||||
return compatManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Compat manager.
|
||||
*/
|
||||
static volatile CompatManager compatManager;
|
||||
public static void init() {
|
||||
SyncManagerRegisterCallback.EVENT.register(registrar -> {
|
||||
registrar.register(
|
||||
TestSyncData.ID,
|
||||
new CachedSyncManager<>() {
|
||||
private final Map<Entity, AbstractedTestSyncData> syncDataMap = new ConcurrentHashMap<>();
|
||||
|
||||
@Override
|
||||
public Map<Entity, AbstractedTestSyncData> getSyncMap() {
|
||||
return syncDataMap;
|
||||
}
|
||||
},
|
||||
AbstractedTestSyncData.class
|
||||
);
|
||||
return ActionResult.PASS;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
package top.r3944realms.lib39.example.core.register;
|
||||
|
||||
import net.minecraft.world.item.Item;
|
||||
import top.r3944realms.lib39.core.register.FabricLib39Items;
|
||||
import top.r3944realms.lib39.core.register.Lib39Items;
|
||||
import top.r3944realms.lib39.example.content.item.FabricItem;
|
||||
import top.r3944realms.lib39.example.content.item.ForgeItem;
|
||||
import top.r3944realms.lib39.example.content.item.NeoForgeItem;
|
||||
import top.r3944realms.lib39.example.core.register.ExLib39Items;
|
||||
|
||||
/**
|
||||
* The type Ex lib 39 items.
|
||||
*/
|
||||
public class FabricExLib39Items {
|
||||
public static void init() {
|
||||
ExLib39Items.FABRIC = FabricLib39Items.register("fabric", new FabricItem(
|
||||
new Item.Properties()
|
||||
.stacksTo(1)
|
||||
.fireResistant()
|
||||
));
|
||||
ExLib39Items.NEOFORGE = FabricLib39Items.register("neoforge", new NeoForgeItem(
|
||||
new Item.Properties()
|
||||
.stacksTo(1)
|
||||
.fireResistant()
|
||||
));
|
||||
ExLib39Items.FORGE = FabricLib39Items.register("forge", new ForgeItem(
|
||||
new Item.Properties()
|
||||
.stacksTo(1)
|
||||
.fireResistant()
|
||||
));
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,86 @@
|
|||
package top.r3944realms.lib39.mixin.callback;
|
||||
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.*;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import top.r3944realms.lib39.api.callback.AnvilUpdateCallback;
|
||||
|
||||
@Mixin(AnvilMenu.class)
|
||||
public abstract class MixinAnvilMenu extends AbstractContainerMenu {
|
||||
@Shadow
|
||||
private String itemName;
|
||||
@Final
|
||||
@Shadow private DataSlot cost;
|
||||
@Shadow
|
||||
private int repairItemCountCost;
|
||||
|
||||
@Unique
|
||||
private Player cachedPlayer;
|
||||
|
||||
protected MixinAnvilMenu(@Nullable MenuType<?> menuType, int containerId) {
|
||||
super(menuType, containerId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 捕获玩家引用
|
||||
*/
|
||||
@Inject(method = "<init>(ILnet/minecraft/world/entity/player/Inventory;Lnet/minecraft/world/inventory/ContainerLevelAccess;)V",
|
||||
at = @At("RETURN"))
|
||||
private void onInit(int containerId, net.minecraft.world.entity.player.Inventory playerInventory,
|
||||
ContainerLevelAccess access, CallbackInfo ci) {
|
||||
this.cachedPlayer = playerInventory.player;
|
||||
}
|
||||
|
||||
/**
|
||||
* 在createResult方法开始时注入事件
|
||||
*/
|
||||
@Inject(
|
||||
method = "createResult",
|
||||
at = @At(value = "HEAD"),
|
||||
cancellable = true
|
||||
)
|
||||
private void onAnvilUpdate(CallbackInfo ci) {
|
||||
AnvilMenu menu = AnvilMenu.class.cast(this);
|
||||
ItemStack left = menu.getSlot(0).getItem();
|
||||
ItemStack right = menu.getSlot(1).getItem();
|
||||
ItemStack outputSlot = menu.getSlot(2).getItem();
|
||||
|
||||
// 如果左侧为空,不处理
|
||||
if (left.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 调用事件
|
||||
AnvilUpdateCallback.AnvilUpdateResult result = AnvilUpdateCallback.EVENT.invoker()
|
||||
.onAnvilUpdate(left, right, outputSlot, itemName, cost.get(), cachedPlayer);
|
||||
|
||||
if (result != null) {
|
||||
if (result.cancel()) {
|
||||
// 取消事件,清空输出
|
||||
menu.getSlot(2).set(ItemStack.EMPTY);
|
||||
cost.set(0);
|
||||
repairItemCountCost = 0;
|
||||
broadcastChanges();
|
||||
ci.cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
if (result.shouldOverride()) {
|
||||
// 设置自定义结果
|
||||
menu.getSlot(2).set(result.output());
|
||||
cost.set(result.cost());
|
||||
repairItemCountCost = result.materialCost();
|
||||
broadcastChanges();
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,5 @@
|
|||
package top.r3944realms.lib39.mixin.callback.client;
|
||||
|
||||
import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod;
|
||||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import net.minecraft.client.multiplayer.ClientPacketListener;
|
||||
import net.minecraft.client.renderer.LevelRenderer;
|
||||
|
|
@ -13,6 +11,9 @@ import net.minecraft.world.level.Level;
|
|||
import net.minecraft.world.level.dimension.DimensionType;
|
||||
import net.minecraft.world.level.storage.WritableLevelData;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import top.r3944realms.lib39.api.callback.client.ClientWorldCallback;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
|
@ -22,9 +23,8 @@ public abstract class MixinClientLevel extends Level {
|
|||
protected MixinClientLevel(WritableLevelData levelData, ResourceKey<Level> dimension, RegistryAccess registryAccess, Holder<DimensionType> dimensionTypeRegistration, Supplier<ProfilerFiller> profiler, boolean isClientSide, boolean isDebug, long biomeZoomSeed, int maxChainedNeighborUpdates) {
|
||||
super(levelData, dimension, registryAccess, dimensionTypeRegistration, profiler, isClientSide, isDebug, biomeZoomSeed, maxChainedNeighborUpdates);
|
||||
}
|
||||
@WrapMethod(method = "<init>")
|
||||
private void init(ClientPacketListener connection, ClientLevel.ClientLevelData clientLevelData, ResourceKey<Level> dimension, Holder<DimensionType> dimensionType, int viewDistance, int serverSimulationDistance, Supplier<ProfilerFiller> profiler, LevelRenderer levelRenderer, boolean isDebug, long biomeZoomSeed, Operation<Void> original) {
|
||||
original.call(connection, clientLevelData, dimension, dimensionType, viewDistance, serverSimulationDistance, profiler, levelRenderer, isDebug, biomeZoomSeed);
|
||||
@Inject(method = "<init>", at = @At("RETURN"))
|
||||
private void $init(ClientPacketListener connection, ClientLevel.ClientLevelData clientLevelData, ResourceKey<Level> dimension, Holder<DimensionType> dimensionType, int viewDistance, int serverSimulationDistance, Supplier<ProfilerFiller> profiler, LevelRenderer levelRenderer, boolean isDebug, long biomeZoomSeed, CallbackInfo ci) {
|
||||
ClientWorldCallback.LOAD.invoker().onWorldLoad(ClientLevel.class.cast(this));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"schemaVersion": 1,
|
||||
"id": "mod_id",
|
||||
"id": "${mod_id}",
|
||||
"version": "${version}",
|
||||
"name": "${mod_name}",
|
||||
"description": "${description}",
|
||||
|
|
@ -8,8 +8,8 @@
|
|||
"${mod_author}"
|
||||
],
|
||||
"contact": {
|
||||
"homepage": "https://fabricmc.net/",
|
||||
"sources": "https://github.com/FabricMC/fabric-example-mod"
|
||||
"homepage": "https://github.com/3944Realms",
|
||||
"sources": "https://github.com/3944Realms/Lib39"
|
||||
},
|
||||
"license": "${license}",
|
||||
"icon": "lib39_logo.png",
|
||||
|
|
|
|||
|
|
@ -2,19 +2,20 @@
|
|||
"required": true,
|
||||
"minVersion": "0.8",
|
||||
"package": "top.r3944realms.lib39.mixin",
|
||||
"refmap": "${mod_id}.refmap.json",
|
||||
"refmap": "${mod_id}.fabric.refmap.json",
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"mixins": [
|
||||
"callback.MixinAnvilMenu",
|
||||
"callback.MixinDedicateServer"
|
||||
],
|
||||
"client": [
|
||||
"callback.client.MixinClientLevel",
|
||||
"callback.MixinMinecraft"
|
||||
"callback.MixinMinecraft",
|
||||
"callback.client.MixinClientLevel"
|
||||
],
|
||||
"server": [
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,13 +10,18 @@ mixin {
|
|||
config("${mod_id}.forge.mixins.json")
|
||||
}
|
||||
|
||||
def commonResources = project(':common').file('src/main/resources/').getAbsolutePath()
|
||||
def forgeResources = file('src/main/resources/').getAbsolutePath()
|
||||
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()
|
||||
|
||||
legacyForge {
|
||||
version = "${minecraft_version}-${forge_version}"
|
||||
|
||||
validateAccessTransformers = true
|
||||
|
||||
def at = project(':common').file('src/main/resources/META-INF/accesstransformer.cfg')
|
||||
def generated = project(':common').file('src/generated/resources/')
|
||||
if (at.exists()) {
|
||||
accessTransformers = ["src/main/resources/META-INF/accesstransformer.cfg"]
|
||||
}
|
||||
|
|
@ -27,13 +32,40 @@ legacyForge {
|
|||
runs {
|
||||
client {
|
||||
client()
|
||||
devLogin = true
|
||||
programArguments.addAll(
|
||||
'--mod', project.mod_id,
|
||||
'--all',
|
||||
'--existing', forgeResources,
|
||||
'--existing', commonResources,
|
||||
'--existing', forgeBuildResources,
|
||||
'--existing', commonBuildResources
|
||||
)
|
||||
}
|
||||
data {
|
||||
data()
|
||||
programArguments.addAll '--mod', project.mod_id, '--all', '--output', generated.getAbsolutePath(), '--existing', file('src/main/resources/').getAbsolutePath()
|
||||
|
||||
// 使用之前定义的变量
|
||||
programArguments.addAll(
|
||||
'--mod', project.mod_id,
|
||||
'--all',
|
||||
'--output', generatedOutput,
|
||||
'--existing', forgeResources,
|
||||
'--existing', commonResources,
|
||||
'--existing', forgeBuildResources,
|
||||
'--existing', commonBuildResources
|
||||
)
|
||||
}
|
||||
server {
|
||||
server()
|
||||
programArguments.addAll(
|
||||
'--mod', project.mod_id,
|
||||
'--all',
|
||||
'--existing', forgeResources,
|
||||
'--existing', commonResources,
|
||||
'--existing', forgeBuildResources,
|
||||
'--existing', commonBuildResources
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -50,6 +82,9 @@ dependencies {
|
|||
compileOnly project(":common")
|
||||
annotationProcessor("org.spongepowered:mixin:0.8.5-SNAPSHOT:processor")
|
||||
implementation(annotationProcessor("io.github.llamalad7:mixinextras-common:0.2.0"))
|
||||
modImplementation(group: 'tschipp.carryon', name: 'carryon-forge-1.20.1', version: '2.1.2.7') {
|
||||
transitive = false
|
||||
}
|
||||
implementation(jarJar("io.github.llamalad7:mixinextras-forge:0.2.0"))
|
||||
}
|
||||
|
||||
|
|
@ -171,6 +206,7 @@ publishing {
|
|||
// 处理资源
|
||||
processResources {
|
||||
from project(':common').sourceSets.main.resources
|
||||
|
||||
inputs.property "version", project.version
|
||||
inputs.property "minecraft_version", minecraft_version
|
||||
inputs.property "forge_version", forge_version
|
||||
|
|
@ -179,7 +215,7 @@ processResources {
|
|||
inputs.property "description", description
|
||||
inputs.property "mod_author", mod_author
|
||||
|
||||
filesMatching(['META-INF/mods.toml', 'pack.mcmeta']) {
|
||||
filesMatching(['META-INF/mods.toml', 'pack.mcmeta', "*.mixins.json"]) {
|
||||
expand([
|
||||
version: project.version,
|
||||
minecraft_version: minecraft_version,
|
||||
|
|
|
|||
|
|
@ -7,11 +7,12 @@ 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(top.r3944realms.lib39.Lib39.MOD_ID)
|
||||
@Mod(Lib39.MOD_ID)
|
||||
public class Lib39Forge {
|
||||
/**
|
||||
* Instantiates a new Lib 39.
|
||||
|
|
@ -31,7 +32,27 @@ public class Lib39Forge {
|
|||
ForgeLib39Items.register(modEventBus);
|
||||
ForgeLib39BlockEntities.register(modEventBus);
|
||||
ForgeLib39SoundEvents.register(modEventBus);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ public class Lib39BlockStatesProvider extends BlockStateProvider {
|
|||
|
||||
// 创建GeckoLib模型引用
|
||||
ModelFile modelFile = new ModelFile.ExistingModelFile(
|
||||
Lib39.rl( "block/base_doll"),
|
||||
Lib39.rl("block/base_doll"),
|
||||
models().existingFileHelper
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
package top.r3944realms.lib39.core.event;
|
||||
|
||||
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import net.minecraft.client.renderer.ShaderInstance;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.client.event.EntityRenderersEvent;
|
||||
import net.minecraftforge.client.event.RegisterShadersEvent;
|
||||
|
|
@ -13,6 +15,8 @@ import top.r3944realms.lib39.client.shader.Lib39Shaders;
|
|||
import top.r3944realms.lib39.core.register.Lib39BlockEntities;
|
||||
import top.r3944realms.lib39.util.ILevelHelper;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* The type Client handler.
|
||||
*/
|
||||
|
|
@ -28,8 +32,9 @@ public class ClientEventHandler {
|
|||
* @param event the event
|
||||
*/
|
||||
@SubscribeEvent
|
||||
public static void onRegisterShaders(RegisterShadersEvent event) {
|
||||
Lib39Shaders.registerShaders(event.getResourceProvider());
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -65,7 +70,7 @@ public class ClientEventHandler {
|
|||
* @param event the event
|
||||
*/
|
||||
@SubscribeEvent
|
||||
public static void registerLayerDefinitions(LevelEvent.Load event) {
|
||||
public static void obClientUnload(LevelEvent.Load event) {
|
||||
if (event.getLevel() != null && event.getLevel() instanceof ClientLevel level) {
|
||||
ILevelHelper.LevelHelper.CLIENT.setLevel(level);
|
||||
}
|
||||
|
|
@ -77,7 +82,7 @@ public class ClientEventHandler {
|
|||
* @param event the event
|
||||
*/
|
||||
@SubscribeEvent
|
||||
public static void registerLayerDefinitions(LevelEvent.Unload event) {
|
||||
public static void obClientUnload(LevelEvent.Unload event) {
|
||||
if (event.getLevel() != null && event.getLevel() instanceof ClientLevel level) {
|
||||
ILevelHelper.LevelHelper.CLIENT.setLevel(null);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,12 +31,9 @@ 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.item.DollItem;
|
||||
import top.r3944realms.lib39.content.register.Lib39Items;
|
||||
import top.r3944realms.lib39.core.register.Lib39Items;
|
||||
import top.r3944realms.lib39.core.sync.ISyncData;
|
||||
import top.r3944realms.lib39.core.sync.SyncData2CapManager;
|
||||
import top.r3944realms.lib39.core.sync.SyncData2Manager;
|
||||
import top.r3944realms.lib39.example.compat.Lib39CompatManager;
|
||||
import top.r3944realms.lib39.util.GameProfileHelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,53 @@
|
|||
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;
|
||||
|
||||
public class ForgeLib39Example {
|
||||
//todo:订阅事件
|
||||
private static boolean registered = false;
|
||||
/**
|
||||
* Instantiates a new Lib 39 example.
|
||||
*/
|
||||
public ForgeLib39Example() {
|
||||
if (!registered) {
|
||||
init();
|
||||
registerToEventBus();
|
||||
registered = true;
|
||||
}
|
||||
}
|
||||
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,61 +0,0 @@
|
|||
package top.r3944realms.lib39.example.core.register;
|
||||
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
import top.r3944realms.lib39.Lib39;
|
||||
import top.r3944realms.lib39.example.content.item.FabricItem;
|
||||
import top.r3944realms.lib39.example.content.item.NeoForgeItem;
|
||||
|
||||
/**
|
||||
* The type Ex lib 39 items.
|
||||
*/
|
||||
public class ExLib39Items {
|
||||
/**
|
||||
* The constant ITEMS.
|
||||
*/
|
||||
public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, Lib39.MOD_ID);
|
||||
/**
|
||||
* The constant SUPER_LEAD_ROPE.
|
||||
*/
|
||||
public static final RegistryObject<Item> FABRIC = ITEMS.register(
|
||||
"fabric",
|
||||
() -> new FabricItem(
|
||||
new Item.Properties()
|
||||
.stacksTo(1)
|
||||
.fireResistant()
|
||||
)
|
||||
);
|
||||
/**
|
||||
* The constant ETERNAL_POTATO.
|
||||
*/
|
||||
public static final RegistryObject<Item> NEOFORGE =
|
||||
ITEMS.register("neoforge",
|
||||
() -> new NeoForgeItem(
|
||||
new Item.Properties()
|
||||
.stacksTo(1)
|
||||
.fireResistant()
|
||||
));
|
||||
/**
|
||||
* The constant FORGE.
|
||||
*/
|
||||
public static final RegistryObject<Item> FORGE =
|
||||
ITEMS.register("forge",
|
||||
() -> new NeoForgeItem(
|
||||
new Item.Properties()
|
||||
.stacksTo(1)
|
||||
.fireResistant()
|
||||
));
|
||||
|
||||
/**
|
||||
* Register.
|
||||
*
|
||||
* @param bus the bus
|
||||
*/
|
||||
public static void register(IEventBus bus) {
|
||||
ITEMS.register(bus);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
package top.r3944realms.lib39.example.core.register;
|
||||
|
||||
import net.minecraft.world.item.Item;
|
||||
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.example.content.item.FabricItem;
|
||||
import top.r3944realms.lib39.example.content.item.NeoForgeItem;
|
||||
|
||||
/**
|
||||
* The type Ex lib 39 items.
|
||||
*/
|
||||
public class ForgeExLib39Items {
|
||||
/**
|
||||
* The constant ITEMS.
|
||||
*/
|
||||
public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, Lib39.MOD_ID);
|
||||
|
||||
static {
|
||||
ExLib39Items.FABRIC = ITEMS.register(
|
||||
"fabric",
|
||||
() -> new FabricItem(
|
||||
new Item.Properties()
|
||||
.stacksTo(1)
|
||||
.fireResistant()
|
||||
)
|
||||
);
|
||||
ExLib39Items.NEOFORGE =
|
||||
ITEMS.register("neoforge",
|
||||
() -> new NeoForgeItem(
|
||||
new Item.Properties()
|
||||
.stacksTo(1)
|
||||
.fireResistant()
|
||||
));
|
||||
ExLib39Items.FORGE =
|
||||
ITEMS.register("forge",
|
||||
() -> new NeoForgeItem(
|
||||
new Item.Properties()
|
||||
.stacksTo(1)
|
||||
.fireResistant()
|
||||
));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Register.
|
||||
*
|
||||
* @param bus the bus
|
||||
*/
|
||||
public static void register(IEventBus bus) {
|
||||
ITEMS.register(bus);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
modLoader = "javafml" #mandatory
|
||||
loaderVersion = "${forge_loader_version_range}" #mandatory This is typically bumped every Minecraft version by Forge. See https://files.minecraftforge.net/ for a list of versions.
|
||||
license = "${license}" # Review your options at https://choosealicense.com/.
|
||||
#issueTrackerURL="https://change.me.to.your.issue.tracker.example.invalid/" #optional
|
||||
issueTrackerURL="https://github.com/3944Realms/Lib39/issues" #optional
|
||||
[[mods]] #mandatory
|
||||
modId = "${mod_id}" #mandatory
|
||||
version = "${version}" #mandatory
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
"required": true,
|
||||
"minVersion": "0.8",
|
||||
"package": "top.r3944realms.lib39.mixin",
|
||||
"refmap": "${mod_id}.refmap.json",
|
||||
"refmap": "${mod_id}.forge.refmap.json",
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"mixins": [
|
||||
"init.MixinDedicateServer"
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ fabric_loader_version=0.16.9
|
|||
|
||||
# Forge
|
||||
forge_version=47.2.30
|
||||
forge_loader_version_range=[47.1.3,)
|
||||
forge_loader_version_range=[47,)
|
||||
|
||||
# Gradle
|
||||
org.gradle.jvmargs=-Xmx3G
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user