-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
button action is still w.i.p. (only works client side), currently working on alignment for widgets
- Loading branch information
Showing
24 changed files
with
578 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,22 @@ | ||
package com.megadoxs.megalib; | ||
|
||
import com.megadoxs.megalib.networking.packet.c2s.PerformButtonActionsC2SPacket; | ||
import net.fabricmc.api.ClientModInitializer; | ||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; | ||
import net.minecraft.util.Identifier; | ||
|
||
import java.util.LinkedList; | ||
import java.util.List; | ||
|
||
@Environment(EnvType.CLIENT) | ||
public class MegalibClient implements ClientModInitializer { | ||
@Override | ||
public void onInitializeClient() { | ||
} | ||
|
||
public static void performButtonActions(Identifier identifier) { | ||
ClientPlayNetworking.send(new PerformButtonActionsC2SPacket(identifier)); | ||
} | ||
} |
3 changes: 2 additions & 1 deletion
3
src/main/java/com/megadoxs/megalib/access/UserInterfaceViewer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
package com.megadoxs.megalib.access; | ||
|
||
import com.megadoxs.megalib.data.UserInterfaceData; | ||
import io.github.apace100.apoli.power.PowerType; | ||
|
||
public interface UserInterfaceViewer { | ||
void megalib$showInterface(UserInterfaceData toastData); | ||
void megalib$showInterface(UserInterfaceData interfaceData, PowerType<?> powerType); | ||
} |
78 changes: 78 additions & 0 deletions
78
src/main/java/com/megadoxs/megalib/data/MegalibDataTypes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,83 @@ | ||
package com.megadoxs.megalib.data; | ||
|
||
import com.google.gson.JsonObject; | ||
import com.google.gson.JsonSyntaxException; | ||
import com.megadoxs.megalib.registry.MegalibRegistries; | ||
import com.megadoxs.megalib.screen_element.ScreenElementFactory; | ||
import com.megadoxs.megalib.screen_element.ScreenElements; | ||
import com.megadoxs.megalib.util.Screen.Size; | ||
import io.github.apace100.calio.util.IdentifierAlias; | ||
import io.github.apace100.calio.ClassUtil; | ||
import io.github.apace100.calio.data.SerializableData; | ||
import io.github.apace100.calio.data.SerializableDataType; | ||
import io.github.apace100.calio.data.SerializableDataTypes; | ||
import io.github.apace100.calio.util.DynamicIdentifier; | ||
import net.minecraft.registry.Registry; | ||
import net.minecraft.util.Identifier; | ||
import net.minecraft.util.JsonHelper; | ||
|
||
import java.util.List; | ||
import java.util.function.BiFunction; | ||
|
||
public class MegalibDataTypes { | ||
public static final SerializableDataType<Size> SIZE = SerializableDataType.compound( | ||
Size.class, | ||
new SerializableData() | ||
.add("unit", SerializableDataTypes.STRING, "percents") | ||
.add("width", SerializableDataTypes.INT, 0) | ||
.add("height", SerializableDataTypes.INT, 0), | ||
(data) -> new Size( | ||
data.get("unit"), | ||
data.get("width"), | ||
data.get("height") | ||
), | ||
(serializableData, Size) -> { | ||
SerializableData.Instance data = serializableData.new Instance(); | ||
|
||
data.set("unit", Size.unit()); | ||
data.set("width", Size.width()); | ||
data.set("height", Size.height()); | ||
|
||
return data; | ||
} | ||
); | ||
|
||
public static final SerializableDataType<ScreenElementFactory.Instance> SCREEN_ELEMENT = element(MegalibRegistries.SCREEN_ELEMENT_FACTORY, ScreenElements.ALIASES, "Screen Element"); | ||
public static final SerializableDataType<List<ScreenElementFactory.Instance>> SCREEN_ELEMENTS = SerializableDataType.list(SCREEN_ELEMENT); | ||
|
||
public static <T> SerializableDataType<ScreenElementFactory.Instance> element(Registry<ScreenElementFactory> registry, String name) { | ||
return element(registry, IdentifierAlias.GLOBAL, name); | ||
} | ||
|
||
public static <T> SerializableDataType<ScreenElementFactory.Instance> element(Registry<ScreenElementFactory> registry, IdentifierAlias aliases, String name) { | ||
return element(registry, aliases, (conditionFactories, id) -> new IllegalArgumentException(name + " \"" + id + "\" is not registered")); | ||
} | ||
|
||
public static <T> SerializableDataType<ScreenElementFactory.Instance> element(Registry<ScreenElementFactory> registry, IdentifierAlias aliases, BiFunction<Registry<ScreenElementFactory>, Identifier, RuntimeException> errorHandler) { | ||
return new SerializableDataType<>( | ||
ClassUtil.castClass(ScreenElementFactory.Instance.class), | ||
(buf, instance) -> instance.write(buf), | ||
buf -> { | ||
Identifier factoryId = buf.readIdentifier(); | ||
return registry | ||
.getOrEmpty(aliases.resolveAlias(factoryId, registry::containsId)) | ||
.orElseThrow(() -> errorHandler.apply(registry, factoryId)) | ||
.read(buf); | ||
}, | ||
jsonElement -> { | ||
|
||
if (!(jsonElement instanceof JsonObject jsonObject)) { | ||
throw new JsonSyntaxException("Expected a JSON object."); | ||
} | ||
|
||
Identifier factoryId = DynamicIdentifier.of(JsonHelper.getString(jsonObject, "type")); | ||
return registry | ||
.getOrEmpty(aliases.resolveAlias(factoryId, registry::containsId)) | ||
.orElseThrow(() -> errorHandler.apply(registry, factoryId)) | ||
.read(jsonObject); | ||
|
||
}, | ||
ScreenElementFactory.Instance::toJson | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 0 additions & 39 deletions
39
src/main/java/com/megadoxs/megalib/networking/ModPacketsS2C.java
This file was deleted.
Oops, something went wrong.
27 changes: 27 additions & 0 deletions
27
src/main/java/com/megadoxs/megalib/networking/packet/c2s/PerformButtonActionsC2SPacket.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.megadoxs.megalib.networking.packet.c2s; | ||
|
||
import com.megadoxs.megalib.Megalib; | ||
import net.fabricmc.fabric.api.networking.v1.FabricPacket; | ||
import net.fabricmc.fabric.api.networking.v1.PacketType; | ||
import net.minecraft.network.PacketByteBuf; | ||
import net.minecraft.util.Identifier; | ||
|
||
public record PerformButtonActionsC2SPacket(Identifier identifier) implements FabricPacket { | ||
|
||
public static final PacketType<PerformButtonActionsC2SPacket> TYPE = PacketType.create( | ||
Megalib.identifier("c2s/perform_button_action"), PerformButtonActionsC2SPacket::read | ||
); | ||
|
||
private static PerformButtonActionsC2SPacket read(PacketByteBuf buffer) { | ||
return new PerformButtonActionsC2SPacket(buffer.readIdentifier()); | ||
} | ||
@Override | ||
public void write(PacketByteBuf buffer) { | ||
buffer.writeIdentifier(identifier); | ||
} | ||
|
||
@Override | ||
public PacketType<?> getType() { | ||
return TYPE; | ||
} | ||
} |
29 changes: 0 additions & 29 deletions
29
src/main/java/com/megadoxs/megalib/networking/packet/s2c/UserInterfaceS2CPacket.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.