This commit is contained in:
4
src/main/generated/assets/codecraft/lang/en_us.json
Normal file
4
src/main/generated/assets/codecraft/lang/en_us.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"key.category.codecraft.codecraft": "Codecraft",
|
||||
"key.codecraft.open_editor": "Open Editor"
|
||||
}
|
||||
39
src/main/java/com/aranroig/Codecraft.java
Normal file
39
src/main/java/com/aranroig/Codecraft.java
Normal file
@@ -0,0 +1,39 @@
|
||||
package com.aranroig;
|
||||
|
||||
import com.aranroig.payloads.ServerboundSaveCodePayload;
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
|
||||
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
|
||||
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
|
||||
import net.minecraft.resources.Identifier;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class Codecraft implements ModInitializer {
|
||||
public static final String MOD_ID = "codecraft";
|
||||
|
||||
// This logger is used to write text to the console and the log file.
|
||||
// It is considered best practice to use your mod id as the logger's name.
|
||||
// That way, it's clear which mod wrote info, warnings, and errors.
|
||||
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
|
||||
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
// This code runs as soon as Minecraft is in a mod-load-ready state.
|
||||
// However, some things (like resources) may still be uninitialized.
|
||||
// Proceed with mild caution.
|
||||
LOGGER.info("Hello Fabric world!");
|
||||
|
||||
PayloadTypeRegistry.serverboundPlay().register(ServerboundSaveCodePayload.TYPE, ServerboundSaveCodePayload.CODEC);
|
||||
|
||||
ServerPlayNetworking.registerGlobalReceiver(ServerboundSaveCodePayload.TYPE, (payload, context) -> {
|
||||
System.out.println(payload.data().getName());
|
||||
System.out.println(payload.data().getText());
|
||||
});
|
||||
}
|
||||
|
||||
public static Identifier id(String path) {
|
||||
return Identifier.fromNamespaceAndPath(MOD_ID, path);
|
||||
}
|
||||
}
|
||||
40
src/main/java/com/aranroig/editor/EditorFile.java
Normal file
40
src/main/java/com/aranroig/editor/EditorFile.java
Normal file
@@ -0,0 +1,40 @@
|
||||
package com.aranroig.editor;
|
||||
|
||||
import net.minecraft.network.RegistryFriendlyByteBuf;
|
||||
import net.minecraft.network.codec.ByteBufCodecs;
|
||||
import net.minecraft.network.codec.StreamCodec;
|
||||
|
||||
public class EditorFile {
|
||||
public static final StreamCodec<RegistryFriendlyByteBuf, EditorFile> CODEC =
|
||||
StreamCodec.composite(
|
||||
ByteBufCodecs.STRING_UTF8,
|
||||
EditorFile::getName,
|
||||
|
||||
ByteBufCodecs.STRING_UTF8,
|
||||
EditorFile::getText,
|
||||
|
||||
EditorFile::new
|
||||
);
|
||||
|
||||
// Class with file info
|
||||
private String name;
|
||||
private String text;
|
||||
|
||||
public EditorFile(String name, String text) {
|
||||
this.name = name;
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public void setText(String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
}
|
||||
15
src/main/java/com/aranroig/mixin/ExampleMixin.java
Normal file
15
src/main/java/com/aranroig/mixin/ExampleMixin.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package com.aranroig.mixin;
|
||||
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
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;
|
||||
|
||||
@Mixin(MinecraftServer.class)
|
||||
public class ExampleMixin {
|
||||
@Inject(at = @At("HEAD"), method = "loadLevel")
|
||||
private void init(CallbackInfo info) {
|
||||
// This code is injected into the start of MinecraftServer.loadLevel()V
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.aranroig.payloads;
|
||||
|
||||
import com.aranroig.Codecraft;
|
||||
import com.aranroig.editor.EditorFile;
|
||||
import net.minecraft.network.RegistryFriendlyByteBuf;
|
||||
import net.minecraft.network.codec.StreamCodec;
|
||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||
import net.minecraft.resources.Identifier;
|
||||
|
||||
public record ClientboundSaveCodePayload(EditorFile data) implements CustomPacketPayload {
|
||||
|
||||
public static final Identifier SAVE_CODE_PAYLOAD_ID = Identifier.fromNamespaceAndPath(Codecraft.MOD_ID, "save_code");
|
||||
|
||||
public static final CustomPacketPayload.Type<ClientboundSaveCodePayload> TYPE = new CustomPacketPayload.Type<>(SAVE_CODE_PAYLOAD_ID);
|
||||
|
||||
public static final StreamCodec<RegistryFriendlyByteBuf, ClientboundSaveCodePayload> CODEC =
|
||||
StreamCodec.composite(EditorFile.CODEC, ClientboundSaveCodePayload::data, ClientboundSaveCodePayload::new);
|
||||
|
||||
@Override
|
||||
public Type<? extends CustomPacketPayload> type() {
|
||||
return TYPE;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.aranroig.payloads;
|
||||
|
||||
import com.aranroig.Codecraft;
|
||||
import com.aranroig.editor.EditorFile;
|
||||
import net.minecraft.network.RegistryFriendlyByteBuf;
|
||||
import net.minecraft.network.codec.StreamCodec;
|
||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||
import net.minecraft.resources.Identifier;
|
||||
|
||||
public record ServerboundSaveCodePayload(EditorFile data) implements CustomPacketPayload {
|
||||
public static final Identifier SAVE_CODE_PAYLOAD_ID = Identifier.fromNamespaceAndPath(Codecraft.MOD_ID, "save_code");
|
||||
|
||||
public static final CustomPacketPayload.Type<ServerboundSaveCodePayload> TYPE = new CustomPacketPayload.Type<>(SAVE_CODE_PAYLOAD_ID);
|
||||
|
||||
public static final StreamCodec<RegistryFriendlyByteBuf, ServerboundSaveCodePayload> CODEC =
|
||||
StreamCodec.composite(EditorFile.CODEC, ServerboundSaveCodePayload::data, ServerboundSaveCodePayload::new);
|
||||
|
||||
@Override
|
||||
public CustomPacketPayload.Type<? extends CustomPacketPayload> type() {
|
||||
return TYPE;
|
||||
}
|
||||
}
|
||||
BIN
src/main/resources/assets/codecraft/icon.png
Normal file
BIN
src/main/resources/assets/codecraft/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.9 KiB |
14
src/main/resources/codecraft.mixins.json
Normal file
14
src/main/resources/codecraft.mixins.json
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"required": true,
|
||||
"package": "com.aranroig.mixin",
|
||||
"compatibilityLevel": "JAVA_25",
|
||||
"mixins": [
|
||||
"ExampleMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
},
|
||||
"overwrites": {
|
||||
"requireAnnotations": true
|
||||
}
|
||||
}
|
||||
41
src/main/resources/fabric.mod.json
Normal file
41
src/main/resources/fabric.mod.json
Normal file
@@ -0,0 +1,41 @@
|
||||
{
|
||||
"schemaVersion": 1,
|
||||
"id": "codecraft",
|
||||
"version": "${version}",
|
||||
"name": "codecraft",
|
||||
"description": "Codecraft Mod",
|
||||
"authors": [
|
||||
"Aran Roig"
|
||||
],
|
||||
"contact": {
|
||||
"homepage": "https://aranroig.com/",
|
||||
"sources": "https://github.com/FabricMC/fabric-example-mod"
|
||||
},
|
||||
"license": "CC0-1.0",
|
||||
"icon": "assets/codecraft/icon.png",
|
||||
"environment": "*",
|
||||
"entrypoints": {
|
||||
"main": [
|
||||
"com.aranroig.Codecraft"
|
||||
],
|
||||
"client": [
|
||||
"com.aranroig.client.CodecraftClient"
|
||||
],
|
||||
"fabric-datagen": [
|
||||
"com.aranroig.client.CodecraftDataGenerator"
|
||||
]
|
||||
},
|
||||
"mixins": [
|
||||
"codecraft.mixins.json",
|
||||
{
|
||||
"config": "codecraft.client.mixins.json",
|
||||
"environment": "client"
|
||||
}
|
||||
],
|
||||
"depends": {
|
||||
"fabricloader": ">=0.19.3",
|
||||
"minecraft": "~26.2",
|
||||
"java": ">=25",
|
||||
"fabric-api": "*"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user