First commit
Some checks failed
build / build (push) Failing after 4m1s

This commit is contained in:
2026-07-12 17:00:44 +02:00
commit aa8fa05506
34 changed files with 2192 additions and 0 deletions

View 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);
}
}

View 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;
}
}

View 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
}
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}