Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
megadoxs committed Jun 14, 2024
1 parent e2c8da6 commit 13f8cf1
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 22 deletions.

This file was deleted.

8 changes: 7 additions & 1 deletion src/main/java/com/megadoxs/megalib/Megalib.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package com.megadoxs.megalib;

import com.megadoxs.megalib.registry.factory.*;
import com.megadoxs.megalib.registry.factory.MegalibPowers;
import net.fabricmc.api.ModInitializer;

import net.minecraft.util.Identifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Megalib implements ModInitializer {
// 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 String MOD_ID = "megalib";
public static final Logger LOGGER = LoggerFactory.getLogger("megalib");

@Override
Expand All @@ -21,4 +24,7 @@ public void onInitialize() {
LOGGER.info("Hello Fabric world!");
MegalibPowers.register();
}
public static Identifier identifier(String path) {
return new Identifier(MOD_ID, path);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package com.megadoxs.megalib;

import com.megadoxs.megalib.registry.factory.MegalibClientPowers;
import net.fabricmc.api.ClientModInitializer;

public class MegalibClient implements ClientModInitializer {
@Override
public void onInitializeClient() {
MegalibClientPowers.register();
}
}
35 changes: 35 additions & 0 deletions src/main/java/com/megadoxs/megalib/data/UserInterfaceData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.megadoxs.megalib.data;

import io.github.apace100.calio.data.SerializableData;
import io.github.apace100.calio.data.SerializableDataType;
import io.github.apace100.calio.data.SerializableDataTypes;

public record UserInterfaceData(String title) {

public static final SerializableData DATA = new SerializableData()
.add("title", SerializableDataTypes.STRING);

public static final SerializableDataType<UserInterfaceData> DATA_TYPE = SerializableDataType.compound(
UserInterfaceData.class,
DATA,
UserInterfaceData::fromData,
(serializableData, interfaceData) -> interfaceData.toData()
);

public static UserInterfaceData fromData(SerializableData.Instance data) {
return new UserInterfaceData(
data.get("title")
);
}

public SerializableData.Instance toData() {

SerializableData.Instance data = DATA.new Instance();

data.set("title", this.title());

return data;

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.megadoxs.megalib.networking.packet.s2c;

import com.megadoxs.megalib.Megalib;
import com.megadoxs.megalib.data.UserInterfaceData;
import net.fabricmc.fabric.api.networking.v1.FabricPacket;
import net.fabricmc.fabric.api.networking.v1.PacketType;
import net.minecraft.network.PacketByteBuf;

public record UserInterfaceS2CPacket(UserInterfaceData InterfaceData) implements FabricPacket {

public static final PacketType<UserInterfaceS2CPacket> TYPE = PacketType.create(
Megalib.identifier("s2c/user_interface"), UserInterfaceS2CPacket::read
);

public static UserInterfaceS2CPacket read(PacketByteBuf buf) {
return new UserInterfaceS2CPacket(UserInterfaceData.DATA_TYPE.receive(buf));
}

@Override
public void write(PacketByteBuf buf) {
UserInterfaceData.DATA_TYPE.send(buf, InterfaceData);
}

@Override
public PacketType<?> getType() {
return TYPE;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void setKey(Key key) {
}

public static PowerFactory<?> getFactory() {
return new PowerFactory<>(Apoli.identifier("UserInterface"),
return new PowerFactory<>(Megalib.identifier("user_interface"),
new SerializableData()
.add("key", ApoliDataTypes.BACKWARDS_COMPATIBLE_KEY, new Active.Key())
.add("title", SerializableDataTypes.STRING, "User Interface"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.megadoxs.megalib.registry.factory;

import com.megadoxs.megalib.power.*;
import io.github.apace100.apoli.power.factory.PowerFactory;
import io.github.apace100.apoli.registry.ApoliRegistries;
import net.minecraft.registry.Registry;

public class MegalibPowers {

public static void register() {

register(UserInterfacePower.getFactory());
}

public static PowerFactory<?> register(PowerFactory<?> powerFactory) {
Expand Down

0 comments on commit 13f8cf1

Please sign in to comment.