diff --git a/blockentity/common/build.gradle b/blockentity/common/build.gradle index c7681462..18d9e99a 100644 --- a/blockentity/common/build.gradle +++ b/blockentity/common/build.gradle @@ -4,9 +4,5 @@ base.archivesName = rootProject.name + "-blockentity" kessoku { module("base", "common") - module("platform", "common") -} - -dependencies { - implementation libs.aj4j -} + module("data", "common") +} \ No newline at end of file diff --git a/blockentity/common/src/main/java/band/kessoku/lib/api/blockentity/BlockEntityAccess.java b/blockentity/common/src/main/java/band/kessoku/lib/api/blockentity/BlockEntityAccess.java new file mode 100644 index 00000000..7ad66d35 --- /dev/null +++ b/blockentity/common/src/main/java/band/kessoku/lib/api/blockentity/BlockEntityAccess.java @@ -0,0 +1,5 @@ +package band.kessoku.lib.api.blockentity; + +public class BlockEntityAccess { + +} diff --git a/blockentity/common/src/main/java/band/kessoku/lib/api/blockentity/KessokuBlockEntity.java b/blockentity/common/src/main/java/band/kessoku/lib/api/blockentity/KessokuBlockEntity.java new file mode 100644 index 00000000..76b553bc --- /dev/null +++ b/blockentity/common/src/main/java/band/kessoku/lib/api/blockentity/KessokuBlockEntity.java @@ -0,0 +1,10 @@ +package band.kessoku.lib.api.blockentity; + +import org.slf4j.Marker; +import org.slf4j.MarkerFactory; + +public class KessokuBlockEntity { + public static final String MOD_ID = "kessoku_blockentity"; + public static final String NAME = "Kessoku Block Entity API"; + public static final Marker MARKER = MarkerFactory.getMarker("[" + NAME +"]"); +} diff --git a/blockentity/common/src/main/resources/kessoku_blockentity.mixins.json b/blockentity/common/src/main/resources/kessoku_blockentity.mixins.json new file mode 100644 index 00000000..57c93d2d --- /dev/null +++ b/blockentity/common/src/main/resources/kessoku_blockentity.mixins.json @@ -0,0 +1,8 @@ +{ + "required": true, + "package": "band.kessoku.lib.mixin.blockentity", + "compatibilityLevel": "JAVA_21", + "injectors": { + "defaultRequire": 1 + } +} \ No newline at end of file diff --git a/blockentity/fabric/src/main/java/band/kessoku/lib/impl/blockentity/fabric/KessokuBlockEntityFabric.java b/blockentity/fabric/src/main/java/band/kessoku/lib/impl/blockentity/fabric/KessokuBlockEntityFabric.java index 825ca559..4edb47dc 100644 --- a/blockentity/fabric/src/main/java/band/kessoku/lib/impl/blockentity/fabric/KessokuBlockEntityFabric.java +++ b/blockentity/fabric/src/main/java/band/kessoku/lib/impl/blockentity/fabric/KessokuBlockEntityFabric.java @@ -15,11 +15,13 @@ */ package band.kessoku.lib.impl.blockentity.fabric; +import band.kessoku.lib.api.KessokuLib; +import band.kessoku.lib.api.blockentity.KessokuBlockEntity; import net.fabricmc.api.ModInitializer; public class KessokuBlockEntityFabric implements ModInitializer { @Override public void onInitialize() { - + KessokuLib.loadModule(KessokuBlockEntity.class); } } diff --git a/blockentity/fabric/src/main/resources/fabric.mod.json b/blockentity/fabric/src/main/resources/fabric.mod.json index 5926a109..0f200982 100644 --- a/blockentity/fabric/src/main/resources/fabric.mod.json +++ b/blockentity/fabric/src/main/resources/fabric.mod.json @@ -3,7 +3,7 @@ "id": "kessoku_blockentity", "version": "${version}", "name": "Kessoku Block Entity", - "description": "Common blockentity API.", + "description": "A API of Block Entity Building.", "authors": [ "Kessoku Tea Time" ], diff --git a/data/common/src/main/java/band/kessoku/lib/api/data/NBTSerializable.java b/blockentity/neo/src/main/java/band/kessoku/lib/impl/blockentity/forge/KessokuBlockEntityNeoforge.java similarity index 61% rename from data/common/src/main/java/band/kessoku/lib/api/data/NBTSerializable.java rename to blockentity/neo/src/main/java/band/kessoku/lib/impl/blockentity/forge/KessokuBlockEntityNeoforge.java index 70f188ca..efca213b 100644 --- a/data/common/src/main/java/band/kessoku/lib/api/data/NBTSerializable.java +++ b/blockentity/neo/src/main/java/band/kessoku/lib/impl/blockentity/forge/KessokuBlockEntityNeoforge.java @@ -13,15 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.api.data; +package band.kessoku.lib.impl.blockentity.forge; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.registry.RegistryWrapper; +import band.kessoku.lib.api.KessokuLib; +import band.kessoku.lib.api.blockentity.KessokuBlockEntity; +import net.neoforged.fml.common.Mod; -/** - * An interface used to normalize serialization of {@link NbtCompound NBT}. - */ -public interface NBTSerializable { - void write(NbtCompound nbt, RegistryWrapper.WrapperLookup registries); - void read(NbtCompound nbt, RegistryWrapper.WrapperLookup registries); +@Mod(KessokuBlockEntity.MOD_ID) +public final class KessokuBlockEntityNeoforge { + public KessokuBlockEntityNeoforge() { + KessokuLib.loadModule(KessokuBlockEntity.class); + } } diff --git a/blockentity/neo/src/main/resources/META-INF/neoforge.mods.toml b/blockentity/neo/src/main/resources/META-INF/neoforge.mods.toml index ef002246..f1339132 100644 --- a/blockentity/neo/src/main/resources/META-INF/neoforge.mods.toml +++ b/blockentity/neo/src/main/resources/META-INF/neoforge.mods.toml @@ -8,7 +8,7 @@ modId = "kessoku_blockentity" version = "${version}" displayName = "Kessoku Block Entity" description = ''' -Common blockentity API. +A API of Block Entity Building. ''' logoFile = "icon.png" authors = "Kessoku Tea Time" diff --git a/component/common/build.gradle b/component/common/build.gradle new file mode 100644 index 00000000..bee056e4 --- /dev/null +++ b/component/common/build.gradle @@ -0,0 +1,10 @@ +apply from: rootProject.file("gradle/scripts/klib-common.gradle") + +base.archivesName = rootProject.name + "-component" + +kessoku { + module("base", "common") + module("registry", "common") + module("data", "common") +} + diff --git a/component/common/src/main/java/band/kessoku/lib/api/component/KessokuComponent.java b/component/common/src/main/java/band/kessoku/lib/api/component/KessokuComponent.java new file mode 100644 index 00000000..e0b940db --- /dev/null +++ b/component/common/src/main/java/band/kessoku/lib/api/component/KessokuComponent.java @@ -0,0 +1,27 @@ +package band.kessoku.lib.api.component; + +import band.kessoku.lib.api.registry.KessokuRegistry; +import band.kessoku.lib.impl.Progress; +import net.minecraft.component.ComponentType; +import net.minecraft.util.Identifier; +import org.slf4j.Marker; +import org.slf4j.MarkerFactory; + +public class KessokuComponent { + public static final String MOD_ID = "kessoku_component"; + public static final String NAME = "Kessoku Component API"; + public static final Marker MARKER = MarkerFactory.getMarker("[" + NAME +"]"); + + public static final ComponentType PROGRESS_COMPONENT_TYPE; + + public static void init() { + + } + + static { + PROGRESS_COMPONENT_TYPE = KessokuRegistry.registerComponentType( + Identifier.of("kessoku", "progress"), + builder -> builder.codec(Progress.CODEC).packetCodec(Progress.PACKET_CODEC) + ); + } +} diff --git a/component/common/src/main/resources/icon.png b/component/common/src/main/resources/icon.png new file mode 100644 index 00000000..87099d09 Binary files /dev/null and b/component/common/src/main/resources/icon.png differ diff --git a/component/fabric/build.gradle b/component/fabric/build.gradle new file mode 100644 index 00000000..ded69767 --- /dev/null +++ b/component/fabric/build.gradle @@ -0,0 +1,12 @@ +import net.fabricmc.loom.util.ModPlatform + +apply from: rootProject.file("gradle/scripts/klib-fabric.gradle") + +base.archivesName = rootProject.name + "-component" + +kessoku { + module("base", "common") + + common("component", ModPlatform.FABRIC) + shadowBundle("component", ModPlatform.FABRIC) +} diff --git a/component/fabric/src/main/java/band/kessoku/lib/impl/component/fabric/KessokuComponentFabric.java b/component/fabric/src/main/java/band/kessoku/lib/impl/component/fabric/KessokuComponentFabric.java new file mode 100644 index 00000000..0e7e292b --- /dev/null +++ b/component/fabric/src/main/java/band/kessoku/lib/impl/component/fabric/KessokuComponentFabric.java @@ -0,0 +1,13 @@ +package band.kessoku.lib.impl.component.fabric; + +import band.kessoku.lib.api.KessokuLib; +import band.kessoku.lib.api.component.KessokuComponent; +import net.fabricmc.api.ModInitializer; + +public class KessokuComponentFabric implements ModInitializer { + @Override + public void onInitialize() { + KessokuLib.loadModule(KessokuComponent.class); + KessokuComponent.init(); + } +} diff --git a/component/fabric/src/main/resources/fabric.mod.json b/component/fabric/src/main/resources/fabric.mod.json new file mode 100644 index 00000000..ed1bb81f --- /dev/null +++ b/component/fabric/src/main/resources/fabric.mod.json @@ -0,0 +1,36 @@ +{ + "schemaVersion": 1, + "id": "kessoku_data", + "version": "${version}", + "name": "Kessoku Component", + "description": "A API about component in Minecraft.", + "authors": [ + "Kessoku Tea Time" + ], + "contact": { + "homepage": "https://modrinth.com/mod/kessoku-lib", + "sources": "https://github.com/KessokuTeaTime/KessokuLib", + "issues": "https://github.com/KessokuTeaTime/KessokuLib/issues" + }, + "license": "LGPL-3.0-only", + "icon": "icon.png", + "entrypoints": { + "main": [ + "band.kessoku.lib.impl.component.fabric.KessokuComponentFabric" + ] + }, + "environment": "*", + "depends": { + "fabricloader": ">=0.16.0", + "minecraft": "1.21", + "java": ">=21", + "fabric-api": "*" + }, + "custom": { + "modmenu": { + "badges": [ + "library" + ] + } + } +} \ No newline at end of file diff --git a/component/neo/build.gradle b/component/neo/build.gradle new file mode 100644 index 00000000..7b9ef94f --- /dev/null +++ b/component/neo/build.gradle @@ -0,0 +1,12 @@ +import net.fabricmc.loom.util.ModPlatform + +apply from: rootProject.file("gradle/scripts/klib-neo.gradle") + +base.archivesName = rootProject.name + "-component" + +kessoku { + module("base", "common") + + common("component", ModPlatform.NEOFORGE) + shadowBundle("component", ModPlatform.NEOFORGE) +} diff --git a/component/neo/gradle.properties b/component/neo/gradle.properties new file mode 100644 index 00000000..2914393d --- /dev/null +++ b/component/neo/gradle.properties @@ -0,0 +1 @@ +loom.platform=neoforge \ No newline at end of file diff --git a/component/neo/src/main/java/band/kessoku/lib/impl/component/forge/KessokuComponentForge.java b/component/neo/src/main/java/band/kessoku/lib/impl/component/forge/KessokuComponentForge.java new file mode 100644 index 00000000..072f2b83 --- /dev/null +++ b/component/neo/src/main/java/band/kessoku/lib/impl/component/forge/KessokuComponentForge.java @@ -0,0 +1,13 @@ +package band.kessoku.lib.impl.component.forge; + +import band.kessoku.lib.api.KessokuLib; +import band.kessoku.lib.api.component.KessokuComponent; +import net.neoforged.fml.common.Mod; + +@Mod(KessokuComponent.MOD_ID) +public class KessokuComponentForge { + public KessokuComponentForge() { + KessokuLib.loadModule(KessokuComponent.class); + KessokuComponent.init(); + } +} diff --git a/component/neo/src/main/resources/META-INF/neoforge.mods.toml b/component/neo/src/main/resources/META-INF/neoforge.mods.toml new file mode 100644 index 00000000..2d0286af --- /dev/null +++ b/component/neo/src/main/resources/META-INF/neoforge.mods.toml @@ -0,0 +1,29 @@ +modLoader = "javafml" +loaderVersion = "[4,)" +license = "LGPL-3.0-only" +issueTrackerURL = "https://github.com/KessokuTeaTime/KessokuLib/issues" + +[[mods]] +modId = "kessoku_data" +version = "${version}" +displayName = "Kessoku Data" +description = ''' +A API about component in Minecraft. +''' +logoFile = "icon.png" +authors = "Kessoku Tea Time" +displayURL = "https://modrinth.com/mod/kessoku-lib" + +[[dependencies.kessoku_data]] +modId = "neoforge" +type = "required" +versionRange = "[21.0,)" +ordering = "NONE" +side = "BOTH" + +[[dependencies.kessoku_data]] +modId = "minecraft" +type = "required" +versionRange = "[1.21,)" +ordering = "NONE" +side = "BOTH" \ No newline at end of file diff --git a/data/common/src/main/java/band/kessoku/lib/api/data/DataAccess.java b/data/common/src/main/java/band/kessoku/lib/api/data/DataAccess.java new file mode 100644 index 00000000..8ad38234 --- /dev/null +++ b/data/common/src/main/java/band/kessoku/lib/api/data/DataAccess.java @@ -0,0 +1,6 @@ +package band.kessoku.lib.api.data; + +@FunctionalInterface +public interface DataAccess { + S get(T target); +} diff --git a/data/common/src/main/java/band/kessoku/lib/api/data/DataStructure.java b/data/common/src/main/java/band/kessoku/lib/api/data/DataStructure.java index 24922dad..6c628445 100644 --- a/data/common/src/main/java/band/kessoku/lib/api/data/DataStructure.java +++ b/data/common/src/main/java/band/kessoku/lib/api/data/DataStructure.java @@ -1,28 +1,5 @@ -/* - * Copyright (c) 2024 KessokuTeaTime - * - * Licensed under the GNU Lesser General Pubic License, Version 3 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.gnu.org/licenses/lgpl-3.0.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ package band.kessoku.lib.api.data; -/** - * This is an interface used to abstract a structure holding some data and implement processing logic. - *

- * When building structure, data must be member variable and {@link DataStructure#integrate(Data) "integrate()"} - * can be used to hold data for other usages. - *

- */ public interface DataStructure { - > K integrate(K data); - K integrate(K dataStructure); + } diff --git a/data/common/src/main/java/band/kessoku/lib/api/data/KessokuData.java b/data/common/src/main/java/band/kessoku/lib/api/data/KessokuData.java index 23357e84..a74234ef 100644 --- a/data/common/src/main/java/band/kessoku/lib/api/data/KessokuData.java +++ b/data/common/src/main/java/band/kessoku/lib/api/data/KessokuData.java @@ -22,4 +22,8 @@ public final class KessokuData { public static final String MOD_ID = "kessoku_data"; public static final String NAME = "Kessoku Data API"; public static final Marker MARKER = MarkerFactory.getMarker("[" + NAME +"]"); + + public static void init() { + + } } diff --git a/data/common/src/main/java/band/kessoku/lib/impl/Progress.java b/data/common/src/main/java/band/kessoku/lib/impl/Progress.java new file mode 100644 index 00000000..feb32e57 --- /dev/null +++ b/data/common/src/main/java/band/kessoku/lib/impl/Progress.java @@ -0,0 +1,66 @@ +package band.kessoku.lib.impl; + +import band.kessoku.lib.api.data.DataStructure; +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import net.minecraft.network.RegistryByteBuf; +import net.minecraft.network.codec.PacketCodec; + +public class Progress implements DataStructure { + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( + Codec.INT.fieldOf("time").forGetter(Progress::time), + Codec.INT.fieldOf("totalTime").forGetter(Progress::totalTime) + ).apply(instance, Progress::new)); + public static final PacketCodec PACKET_CODEC = new PacketCodec<>() { + @Override + public Progress decode(RegistryByteBuf buf) { + return new Progress(buf.readInt(), buf.readInt()); + } + + @Override + public void encode(RegistryByteBuf buf, Progress value) { + buf.writeInt(value.time()); + buf.writeInt(value.totalTime()); + } + }; + + private int time = 0; + private int totalTime; + + private Progress(int time, int totalTime) { + this.time = time; + this.totalTime = totalTime; + + } + + public Progress(int totalTime) { + this.totalTime = totalTime; + } + + public void process() { + process(1); + } + + public void process(int time) { + this.time += time; + } + + public void reset(int totalTime) { + this.time = 0; + this.totalTime = totalTime; + } + + public int time() { + return this.time; + } + + public int totalTime() { + return this.totalTime; + } + + public float decimal() { + if (totalTime == 0) + return 0.0f; + return ((float) time) / totalTime; + } +} diff --git a/data/common/src/main/java/band/kessoku/lib/impl/data/BaseData.java b/data/common/src/main/java/band/kessoku/lib/impl/data/BaseData.java deleted file mode 100644 index 9db0f77a..00000000 --- a/data/common/src/main/java/band/kessoku/lib/impl/data/BaseData.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2024 KessokuTeaTime - * - * Licensed under the GNU Lesser General Pubic License, Version 3 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.gnu.org/licenses/lgpl-3.0.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package band.kessoku.lib.impl.data; - -import java.util.Objects; - -import band.kessoku.lib.api.data.MutableData; -import org.jetbrains.annotations.NotNull; - -public class BaseData implements MutableData { - private final String id; - private T value; - - public BaseData(String id, T defaultValue) { - this.id = id; - this.value = defaultValue; - } - - @Override - public void set(T newValue) { - this.value = newValue; - } - - @Override - public T get() { - return this.value; - } - - @Override - public @NotNull String id() { - return this.id; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof BaseData baseData)) return false; - return Objects.equals(value, baseData.value) && Objects.equals(id, baseData.id); - } - - @Override - public int hashCode() { - return Objects.hash(value, id); - } -} diff --git a/data/common/src/main/java/band/kessoku/lib/impl/data/base/ByteData.java b/data/common/src/main/java/band/kessoku/lib/impl/data/base/ByteData.java deleted file mode 100644 index 830390d9..00000000 --- a/data/common/src/main/java/band/kessoku/lib/impl/data/base/ByteData.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2024 KessokuTeaTime - * - * Licensed under the GNU Lesser General Pubic License, Version 3 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.gnu.org/licenses/lgpl-3.0.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package band.kessoku.lib.impl.data.base; - -import band.kessoku.lib.api.data.NBTSerializable; -import band.kessoku.lib.impl.data.BaseData; - -import net.minecraft.nbt.NbtCompound; -import net.minecraft.registry.RegistryWrapper; - -public final class ByteData extends BaseData implements NBTSerializable { - private ByteData(String id, byte defaultValue) { - super(id, defaultValue); - } - - public static ByteData create(String id, byte defaultValue) { - return new ByteData(id, defaultValue); - } - - @Override - public void write(NbtCompound nbt, RegistryWrapper.WrapperLookup registries) { - nbt.putByte(id(), get()); - } - - @Override - public void read(NbtCompound nbt, RegistryWrapper.WrapperLookup registries) { - set(nbt.getByte(id())); - } -} diff --git a/data/common/src/main/java/band/kessoku/lib/impl/data/base/DoubleData.java b/data/common/src/main/java/band/kessoku/lib/impl/data/base/DoubleData.java deleted file mode 100644 index d8091a44..00000000 --- a/data/common/src/main/java/band/kessoku/lib/impl/data/base/DoubleData.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2024 KessokuTeaTime - * - * Licensed under the GNU Lesser General Pubic License, Version 3 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.gnu.org/licenses/lgpl-3.0.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package band.kessoku.lib.impl.data.base; - -import band.kessoku.lib.api.data.NBTSerializable; -import band.kessoku.lib.impl.data.BaseData; - -import net.minecraft.nbt.NbtCompound; -import net.minecraft.registry.RegistryWrapper; - -public final class DoubleData extends BaseData implements NBTSerializable { - private DoubleData(String id, double defaultValue) { - super(id, defaultValue); - } - - public static DoubleData create(String id, double defaultValue) { - return new DoubleData(id, defaultValue); - } - - @Override - public void write(NbtCompound nbt, RegistryWrapper.WrapperLookup registries) { - nbt.putDouble(id(), get()); - } - - @Override - public void read(NbtCompound nbt, RegistryWrapper.WrapperLookup registries) { - set(nbt.getDouble(id())); - } -} diff --git a/data/common/src/main/java/band/kessoku/lib/impl/data/base/FloatData.java b/data/common/src/main/java/band/kessoku/lib/impl/data/base/FloatData.java deleted file mode 100644 index ca2d4afb..00000000 --- a/data/common/src/main/java/band/kessoku/lib/impl/data/base/FloatData.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2024 KessokuTeaTime - * - * Licensed under the GNU Lesser General Pubic License, Version 3 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.gnu.org/licenses/lgpl-3.0.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package band.kessoku.lib.impl.data.base; - -import band.kessoku.lib.api.data.NBTSerializable; -import band.kessoku.lib.impl.data.BaseData; - -import net.minecraft.nbt.NbtCompound; -import net.minecraft.registry.RegistryWrapper; - -public final class FloatData extends BaseData implements NBTSerializable { - private FloatData(String id, float defaultValue) { - super(id, defaultValue); - } - - public static FloatData create(String id, float defaultValue) { - return new FloatData(id, defaultValue); - } - - @Override - public void write(NbtCompound nbt, RegistryWrapper.WrapperLookup registries) { - nbt.putFloat(id(), get()); - } - - @Override - public void read(NbtCompound nbt, RegistryWrapper.WrapperLookup registries) { - set(nbt.getFloat(id())); - } -} diff --git a/data/common/src/main/java/band/kessoku/lib/impl/data/base/IdentifierData.java b/data/common/src/main/java/band/kessoku/lib/impl/data/base/IdentifierData.java deleted file mode 100644 index 25b3fe22..00000000 --- a/data/common/src/main/java/band/kessoku/lib/impl/data/base/IdentifierData.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2024 KessokuTeaTime - * - * Licensed under the GNU Lesser General Pubic License, Version 3 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.gnu.org/licenses/lgpl-3.0.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package band.kessoku.lib.impl.data.base; - -import band.kessoku.lib.api.data.NBTSerializable; -import band.kessoku.lib.impl.data.BaseData; - -import net.minecraft.nbt.NbtCompound; -import net.minecraft.registry.RegistryWrapper; -import net.minecraft.util.Identifier; - -public final class IdentifierData extends BaseData implements NBTSerializable { - private IdentifierData(String id, Identifier defaultValue) { - super(id, defaultValue); - } - - public static IdentifierData create(String id, Identifier defaultValue) { - return new IdentifierData(id, defaultValue); - } - - @Override - public void write(NbtCompound nbt, RegistryWrapper.WrapperLookup registries) { - nbt.putString(id(), get().toString()); - } - - @Override - public void read(NbtCompound nbt, RegistryWrapper.WrapperLookup registries) { - set(Identifier.of(nbt.getString(id()))); - } -} diff --git a/data/common/src/main/java/band/kessoku/lib/impl/data/base/IntData.java b/data/common/src/main/java/band/kessoku/lib/impl/data/base/IntData.java deleted file mode 100644 index 1866e19f..00000000 --- a/data/common/src/main/java/band/kessoku/lib/impl/data/base/IntData.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2024 KessokuTeaTime - * - * Licensed under the GNU Lesser General Pubic License, Version 3 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.gnu.org/licenses/lgpl-3.0.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package band.kessoku.lib.impl.data.base; - -import band.kessoku.lib.api.data.NBTSerializable; -import band.kessoku.lib.impl.data.BaseData; - -import net.minecraft.nbt.NbtCompound; -import net.minecraft.registry.RegistryWrapper; - -public final class IntData extends BaseData implements NBTSerializable { - private IntData(String id, int defaultValue) { - super(id, defaultValue); - } - - public static IntData create(String id, int defaultValue) { - return new IntData(id, defaultValue); - } - - @Override - public void write(NbtCompound nbt, RegistryWrapper.WrapperLookup registries) { - nbt.putInt(id(), get()); - } - - @Override - public void read(NbtCompound nbt, RegistryWrapper.WrapperLookup registries) { - set(nbt.getInt(id())); - } -} diff --git a/data/common/src/main/java/band/kessoku/lib/impl/data/base/ItemStackData.java b/data/common/src/main/java/band/kessoku/lib/impl/data/base/ItemStackData.java deleted file mode 100644 index b0063f13..00000000 --- a/data/common/src/main/java/band/kessoku/lib/impl/data/base/ItemStackData.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2024 KessokuTeaTime - * - * Licensed under the GNU Lesser General Pubic License, Version 3 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.gnu.org/licenses/lgpl-3.0.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package band.kessoku.lib.impl.data.base; - -import band.kessoku.lib.api.data.NBTSerializable; -import band.kessoku.lib.impl.data.BaseData; - -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.registry.RegistryWrapper; - -public final class ItemStackData extends BaseData implements NBTSerializable { - private ItemStackData(String id, ItemStack defaultValue) { - super(id, defaultValue); - } - - public static ItemStackData create(String id, ItemStack defaultValue) { - return new ItemStackData(id, defaultValue); - } - - @Override - public void write(NbtCompound nbt, RegistryWrapper.WrapperLookup registries) { - if (!get().isEmpty()) { - NbtCompound itemNBT = new NbtCompound(); - get().encode(registries, itemNBT); - nbt.put(id(), itemNBT); - } - } - - @Override - public void read(NbtCompound nbt, RegistryWrapper.WrapperLookup registries) { - set(ItemStack.fromNbt(registries, nbt.getCompound(id())).orElse(ItemStack.EMPTY)); - } -} diff --git a/data/common/src/main/java/band/kessoku/lib/impl/data/base/LongData.java b/data/common/src/main/java/band/kessoku/lib/impl/data/base/LongData.java deleted file mode 100644 index b812f75e..00000000 --- a/data/common/src/main/java/band/kessoku/lib/impl/data/base/LongData.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2024 KessokuTeaTime - * - * Licensed under the GNU Lesser General Pubic License, Version 3 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.gnu.org/licenses/lgpl-3.0.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package band.kessoku.lib.impl.data.base; - -import band.kessoku.lib.api.data.NBTSerializable; -import band.kessoku.lib.impl.data.BaseData; - -import net.minecraft.nbt.NbtCompound; -import net.minecraft.registry.RegistryWrapper; - -public final class LongData extends BaseData implements NBTSerializable { - private LongData(String id, long defaultValue) { - super(id, defaultValue); - } - - public static LongData create(String id, long defaultValue) { - return new LongData(id, defaultValue); - } - - @Override - public void write(NbtCompound nbt, RegistryWrapper.WrapperLookup registries) { - nbt.putLong(id(), get()); - } - - @Override - public void read(NbtCompound nbt, RegistryWrapper.WrapperLookup registries) { - set(nbt.getLong(id())); - } -} diff --git a/data/common/src/main/java/band/kessoku/lib/impl/data/base/ShortData.java b/data/common/src/main/java/band/kessoku/lib/impl/data/base/ShortData.java deleted file mode 100644 index f294eb87..00000000 --- a/data/common/src/main/java/band/kessoku/lib/impl/data/base/ShortData.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2024 KessokuTeaTime - * - * Licensed under the GNU Lesser General Pubic License, Version 3 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.gnu.org/licenses/lgpl-3.0.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package band.kessoku.lib.impl.data.base; - -import band.kessoku.lib.api.data.NBTSerializable; -import band.kessoku.lib.impl.data.BaseData; - -import net.minecraft.nbt.NbtCompound; -import net.minecraft.registry.RegistryWrapper; - -public final class ShortData extends BaseData implements NBTSerializable { - private ShortData(String id, short defaultValue) { - super(id, defaultValue); - } - - public static ShortData create(String id, short defaultValue) { - return new ShortData(id, defaultValue); - } - - @Override - public void write(NbtCompound nbt, RegistryWrapper.WrapperLookup registries) { - nbt.putShort(id(), get()); - } - - @Override - public void read(NbtCompound nbt, RegistryWrapper.WrapperLookup registries) { - set(nbt.getShort(id())); - } -} diff --git a/data/common/src/main/java/band/kessoku/lib/impl/data/base/StringData.java b/data/common/src/main/java/band/kessoku/lib/impl/data/base/StringData.java deleted file mode 100644 index 31ea8d75..00000000 --- a/data/common/src/main/java/band/kessoku/lib/impl/data/base/StringData.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2024 KessokuTeaTime - * - * Licensed under the GNU Lesser General Pubic License, Version 3 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.gnu.org/licenses/lgpl-3.0.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package band.kessoku.lib.impl.data.base; - -import band.kessoku.lib.api.data.NBTSerializable; -import band.kessoku.lib.impl.data.BaseData; - -import net.minecraft.nbt.NbtCompound; -import net.minecraft.registry.RegistryWrapper; - -public final class StringData extends BaseData implements NBTSerializable { - private StringData(String id, String defaultValue) { - super(id, defaultValue); - } - - public static StringData create(String id, String defaultValue) { - return new StringData(id, defaultValue); - } - - @Override - public void write(NbtCompound nbt, RegistryWrapper.WrapperLookup registries) { - nbt.putString(id(), get()); - } - - @Override - public void read(NbtCompound nbt, RegistryWrapper.WrapperLookup registries) { - set(nbt.getString(id())); - } -} diff --git a/data/common/src/main/java/band/kessoku/lib/impl/data/base/TextData.java b/data/common/src/main/java/band/kessoku/lib/impl/data/base/TextData.java deleted file mode 100644 index 39bcd0b4..00000000 --- a/data/common/src/main/java/band/kessoku/lib/impl/data/base/TextData.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2024 KessokuTeaTime - * - * Licensed under the GNU Lesser General Pubic License, Version 3 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.gnu.org/licenses/lgpl-3.0.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package band.kessoku.lib.impl.data.base; - -import static net.minecraft.block.entity.BlockEntity.tryParseCustomName; - -import band.kessoku.lib.api.data.NBTSerializable; -import band.kessoku.lib.impl.data.BaseData; - -import net.minecraft.nbt.NbtCompound; -import net.minecraft.registry.RegistryWrapper; -import net.minecraft.text.Text; - -public final class TextData extends BaseData implements NBTSerializable { - private TextData(String id, Text defaultValue) { - super(id, defaultValue); - } - - public static TextData create(String id, Text defaultValue) { - return new TextData(id, defaultValue); - } - - @Override - public void write(NbtCompound nbt, RegistryWrapper.WrapperLookup registries) { - if (get() != null) - nbt.putString(id(), Text.Serialization.toJsonString(get(), registries)); - } - - @Override - public void read(NbtCompound nbt, RegistryWrapper.WrapperLookup registries) { - Text text = tryParseCustomName(nbt.getString(id()), registries); - if (text != null) - set(text); - } -} diff --git a/data/common/src/main/java/band/kessoku/lib/impl/data/collection/DefaultedListData.java b/data/common/src/main/java/band/kessoku/lib/impl/data/collection/DefaultedListData.java deleted file mode 100644 index 8bdd3086..00000000 --- a/data/common/src/main/java/band/kessoku/lib/impl/data/collection/DefaultedListData.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2024 KessokuTeaTime - * - * Licensed under the GNU Lesser General Pubic License, Version 3 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.gnu.org/licenses/lgpl-3.0.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package band.kessoku.lib.impl.data.collection; - -import java.util.Collections; -import java.util.ListIterator; - -import org.jetbrains.annotations.NotNull; - -public final class DefaultedListData extends ListData { - private final @NotNull T defaultValue; - - private DefaultedListData(String id, int size, @NotNull T defaultValue) { - super(id); - this.defaultValue = defaultValue; - addAll(Collections.nCopies(size, defaultValue)); - } - - public static DefaultedListData create(String id, int size, @NotNull T defaultValue) { - return new DefaultedListData<>(id, size, defaultValue); - } - - @Override - protected void removeRange(int fromIndex, int toIndex) { - ListIterator it = this.listIterator(fromIndex); - int i = 0; - - for(int n = toIndex - fromIndex; i < n; i++) { - it.next(); - it.set(defaultValue); - } - } - - @Override - public void clear() { - for(int i = 0; i < this.size(); i++) { - this.set(i, defaultValue); - } - } - - @Override - public T remove(int index) { - return set(index, defaultValue); - } - - @Override - public void add(int index, T element) { - throw new UnsupportedOperationException(); - } - - @Override - public boolean isEmpty() { - for (T t : this) { - if (t != defaultValue) - return false; - } - return true; - } -} diff --git a/data/common/src/main/java/band/kessoku/lib/impl/data/collection/ListData.java b/data/common/src/main/java/band/kessoku/lib/impl/data/collection/ListData.java deleted file mode 100644 index 5481cf9b..00000000 --- a/data/common/src/main/java/band/kessoku/lib/impl/data/collection/ListData.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 2024 KessokuTeaTime - * - * Licensed under the GNU Lesser General Pubic License, Version 3 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.gnu.org/licenses/lgpl-3.0.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package band.kessoku.lib.impl.data.collection; - -import java.util.AbstractList; -import java.util.ArrayList; -import java.util.List; - -import band.kessoku.lib.api.data.Data; -import org.jetbrains.annotations.NotNull; - -public class ListData extends AbstractList implements Data> { - private final List list = new ArrayList<>(); - private final String id; - - public ListData(String id) { - this.id = id; - } - - @Override - public T set(int index, T element) { - return list.set(index, element); - } - - @Override - public void add(int index, T element) { - list.add(index, element); - } - - @Override - public T remove(int index) { - return list.remove(index); - } - - @Deprecated - @Override - public List get() { - return this.list; - } - - @Override - public @NotNull String id() { - return this.id; - } - - @Override - public T get(int i) { - return this.list.get(i); - } - - @Override - public int size() { - return this.list.size(); - } -} diff --git a/data/fabric/src/main/java/band/kessoku/lib/impl/data/fabric/KessokuDataFabric.java b/data/fabric/src/main/java/band/kessoku/lib/impl/data/fabric/KessokuDataFabric.java index 443bd49a..3b790e11 100644 --- a/data/fabric/src/main/java/band/kessoku/lib/impl/data/fabric/KessokuDataFabric.java +++ b/data/fabric/src/main/java/band/kessoku/lib/impl/data/fabric/KessokuDataFabric.java @@ -24,5 +24,6 @@ public final class KessokuDataFabric implements ModInitializer { @Override public void onInitialize() { KessokuLib.loadModule(KessokuData.class); + KessokuData.init(); } } diff --git a/data/fabric/src/main/resources/fabric.mod.json b/data/fabric/src/main/resources/fabric.mod.json index cfd842bd..edaa77bf 100644 --- a/data/fabric/src/main/resources/fabric.mod.json +++ b/data/fabric/src/main/resources/fabric.mod.json @@ -3,7 +3,7 @@ "id": "kessoku_data", "version": "${version}", "name": "Kessoku Data", - "description": "About data in Minecraft.", + "description": "A API about data in Minecraft.", "authors": [ "Kessoku Tea Time" ], diff --git a/data/neo/src/main/java/band/kessoku/lib/impl/data/neoforge/KessokuDataNeoforge.java b/data/neo/src/main/java/band/kessoku/lib/impl/data/neoforge/KessokuDataNeoforge.java index c37265be..3e4074f0 100644 --- a/data/neo/src/main/java/band/kessoku/lib/impl/data/neoforge/KessokuDataNeoforge.java +++ b/data/neo/src/main/java/band/kessoku/lib/impl/data/neoforge/KessokuDataNeoforge.java @@ -24,5 +24,6 @@ public final class KessokuDataNeoforge { public KessokuDataNeoforge() { KessokuLib.loadModule(KessokuData.class); + KessokuData.init(); } } diff --git a/data/neo/src/main/resources/META-INF/neoforge.mods.toml b/data/neo/src/main/resources/META-INF/neoforge.mods.toml index e8ae709b..301da7c0 100644 --- a/data/neo/src/main/resources/META-INF/neoforge.mods.toml +++ b/data/neo/src/main/resources/META-INF/neoforge.mods.toml @@ -8,7 +8,7 @@ modId = "kessoku_data" version = "${version}" displayName = "Kessoku Data" description = ''' -About data in Minecraft. +A API about data in Minecraft. ''' logoFile = "icon.png" authors = "Kessoku Tea Time" diff --git a/gradle/example/common/build.gradle b/gradle/example/common/build.gradle index df81fc1b..c6871d21 100644 --- a/gradle/example/common/build.gradle +++ b/gradle/example/common/build.gradle @@ -1,9 +1,7 @@ apply from: rootProject.file("gradle/scripts/klib-common.gradle") -group = "band.kessoku.lib.package" base.archivesName = rootProject.name + "-package" -// You can delete this section if you need to -dependencies { - +kessoku { + module("base", "common") } diff --git a/gradle/example/fabric/build.gradle b/gradle/example/fabric/build.gradle index 80af3fc1..f7cf9e29 100644 --- a/gradle/example/fabric/build.gradle +++ b/gradle/example/fabric/build.gradle @@ -5,8 +5,8 @@ apply from: rootProject.file("gradle/scripts/klib-fabric.gradle") base.archivesName = rootProject.name + "-package" kessoku { - modules("base", "common") + module("base", "common") - common("package-common", ModPlatform.FABRIC) - shadowBundle("package-common", ModPlatform.FABRIC) + common("package", ModPlatform.FABRIC) + shadowBundle("package", ModPlatform.FABRIC) } diff --git a/gradle/example/neo/build.gradle b/gradle/example/neo/build.gradle index 726226fa..3b51cc2b 100644 --- a/gradle/example/neo/build.gradle +++ b/gradle/example/neo/build.gradle @@ -5,8 +5,8 @@ apply from: rootProject.file("gradle/scripts/klib-neo.gradle") base.archivesName = rootProject.name + "-package" kessoku { - modules("base", "common") + module("base", "common") - common("package-common", ModPlatform.FABRIC) - shadowBundle("package-common", ModPlatform.FABRIC) + common("package", ModPlatform.NEOFORGE) + shadowBundle("package", ModPlatform.NEOFORGE) } diff --git a/registry/common/src/main/java/band/kessoku/lib/api/registry/KessokuRegistry.java b/registry/common/src/main/java/band/kessoku/lib/api/registry/KessokuRegistry.java index 1c7e7024..5d591d92 100644 --- a/registry/common/src/main/java/band/kessoku/lib/api/registry/KessokuRegistry.java +++ b/registry/common/src/main/java/band/kessoku/lib/api/registry/KessokuRegistry.java @@ -15,9 +15,20 @@ */ package band.kessoku.lib.api.registry; +import band.kessoku.lib.service.registry.RegistryService; +import net.minecraft.block.AbstractBlock; +import net.minecraft.block.Block; +import net.minecraft.component.ComponentType; +import net.minecraft.item.BlockItem; +import net.minecraft.item.Item; +import net.minecraft.registry.Registries; +import net.minecraft.registry.entry.RegistryEntry; +import net.minecraft.util.Identifier; import org.slf4j.Marker; import org.slf4j.MarkerFactory; +import java.util.function.UnaryOperator; + public final class KessokuRegistry { private KessokuRegistry() { } @@ -25,4 +36,40 @@ private KessokuRegistry() { public static final String MOD_ID = "kessoku_registry"; public static final String NAME = "Kessoku Registry API"; public static final Marker MARKER = MarkerFactory.getMarker("[" + NAME + "]"); + + public static T register(net.minecraft.registry.Registry registry, String id, T entry) { + return register(registry, Identifier.of(id), entry); + } + + public static T register(net.minecraft.registry.Registry registry, Identifier id, T entry) { + return RegistryService.getInstance().register(registry, id, entry); + } + + public static Item registerItem(Identifier id, Item.Settings settings) { + return register(Registries.ITEM, id, new Item(settings)); + } + + public static Item registerSimpleItem(Identifier id) { + return register(Registries.ITEM, id, new Item(new Item.Settings())); + } + + public static Block registerBlock(Identifier id, AbstractBlock.Settings settings) { + return register(Registries.BLOCK, id, new Block(settings)); + } + + public static Item registerSimpleBlockItem(Identifier id, Block block, Item.Settings settings) { + return register(Registries.ITEM, id, new BlockItem(block, settings)); + } + + public static Item registerSimpleBlockItem(RegistryEntry block) { + return registerSimpleBlockItem(block.getKey().orElseThrow().getValue(), block.value(), new Item.Settings()); + } + + public static Item registerSimpleBlockItem(Identifier id, Block block) { + return registerSimpleBlockItem(id, block, new Item.Settings()); + } + + public static ComponentType registerComponentType(Identifier id, UnaryOperator> builderOperator) { + return register(Registries.DATA_COMPONENT_TYPE, id, builderOperator.apply(ComponentType.builder()).build()); + } } diff --git a/registry/common/src/main/java/band/kessoku/lib/api/registry/Registry.java b/registry/common/src/main/java/band/kessoku/lib/api/registry/Registry.java deleted file mode 100644 index 52545a47..00000000 --- a/registry/common/src/main/java/band/kessoku/lib/api/registry/Registry.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2024 KessokuTeaTime - * - * Licensed under the GNU Lesser General Pubic License, Version 3 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.gnu.org/licenses/lgpl-3.0.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package band.kessoku.lib.api.registry; - -import band.kessoku.lib.service.registry.RegistryService; - -import net.minecraft.block.AbstractBlock; -import net.minecraft.block.Block; -import net.minecraft.item.BlockItem; -import net.minecraft.item.Item; -import net.minecraft.registry.Registries; -import net.minecraft.registry.entry.RegistryEntry; -import net.minecraft.util.Identifier; - -public final class Registry { - private Registry() { - } - - public static T register(net.minecraft.registry.Registry registry, String id, T entry) { - return register(registry, Identifier.of(id), entry); - } - - static T register(net.minecraft.registry.Registry registry, Identifier id, T entry) { - return RegistryService.getInstance().register(registry, id, entry); - } - - static Item registerItem(Identifier id, Item.Settings settings) { - return register(Registries.ITEM, id, new Item(settings)); - } - - static Item registerSimpleItem(Identifier id) { - return register(Registries.ITEM, id, new Item(new Item.Settings())); - } - - static Block registerBlock(Identifier id, AbstractBlock.Settings settings) { - return register(Registries.BLOCK, id, new Block(settings)); - } - - static Block registerSimpleBlock(Identifier id) { - return registerBlock(id, AbstractBlock.Settings.create()); - } - - static Item registerSimpleBlockItem(Identifier id, Block block) { - return registerSimpleBlockItem(id, block, new Item.Settings()); - } - - static Item registerSimpleBlockItem(Identifier id, Block block, Item.Settings settings) { - return register(Registries.ITEM, id, new BlockItem(block, settings)); - } - - static Item registerSimpleBlockItem(RegistryEntry block, Item.Settings settings) { - return registerSimpleBlockItem(block.getKey().orElseThrow().getValue(), block.value(), settings); - } - - static Item registerSimpleBlockItem(RegistryEntry block) { - return registerSimpleBlockItem(block.getKey().orElseThrow().getValue(), block.value(), new Item.Settings()); - } -} diff --git a/settings.gradle b/settings.gradle index c664a0d2..f96ce437 100644 --- a/settings.gradle +++ b/settings.gradle @@ -24,6 +24,8 @@ includeModule("config") // Config API includeModule("entrypoint") // Entrypoint API includeModule("entity-events") // Entity Events includeModule("blockentity") // Block Entity +includeModule("transfer") // Transfer +includeModule("component") // Component void includeWrapper(String platform) { include("wrapper/$platform") diff --git a/transfer/common/build.gradle b/transfer/common/build.gradle new file mode 100644 index 00000000..16eb0289 --- /dev/null +++ b/transfer/common/build.gradle @@ -0,0 +1,8 @@ +apply from: rootProject.file("gradle/scripts/klib-common.gradle") + +base.archivesName = rootProject.name + "-transfer" + +kessoku { + module("base", "common") + module("data", "common") +} \ No newline at end of file diff --git a/transfer/common/src/main/java/band/kessoku/lib/api/transfer/KessokuTransfer.java b/transfer/common/src/main/java/band/kessoku/lib/api/transfer/KessokuTransfer.java new file mode 100644 index 00000000..9da27e77 --- /dev/null +++ b/transfer/common/src/main/java/band/kessoku/lib/api/transfer/KessokuTransfer.java @@ -0,0 +1,10 @@ +package band.kessoku.lib.api.transfer; + +import org.slf4j.Marker; +import org.slf4j.MarkerFactory; + +public class KessokuTransfer { + public static final String MOD_ID = "kessoku_transfer"; + public static final String NAME = "Kessoku Transfer API"; + public static final Marker MARKER = MarkerFactory.getMarker("[" + NAME +"]"); +} diff --git a/transfer/common/src/main/resources/icon.png b/transfer/common/src/main/resources/icon.png new file mode 100644 index 00000000..87099d09 Binary files /dev/null and b/transfer/common/src/main/resources/icon.png differ diff --git a/transfer/common/src/main/resources/kessoku_transfer.mixins.json b/transfer/common/src/main/resources/kessoku_transfer.mixins.json new file mode 100644 index 00000000..3d39f34b --- /dev/null +++ b/transfer/common/src/main/resources/kessoku_transfer.mixins.json @@ -0,0 +1,8 @@ +{ + "required": true, + "package": "band.kessoku.lib.mixin.transfer", + "compatibilityLevel": "JAVA_21", + "injectors": { + "defaultRequire": 1 + } +} \ No newline at end of file diff --git a/transfer/fabric/build.gradle b/transfer/fabric/build.gradle new file mode 100644 index 00000000..457ce673 --- /dev/null +++ b/transfer/fabric/build.gradle @@ -0,0 +1,12 @@ +import net.fabricmc.loom.util.ModPlatform + +apply from: rootProject.file("gradle/scripts/klib-fabric.gradle") + +base.archivesName = rootProject.name + "-transfer" + +kessoku { + module("base", "common") + + common("transfer", ModPlatform.FABRIC) + shadowBundle("transfer", ModPlatform.FABRIC) +} diff --git a/data/common/src/main/java/band/kessoku/lib/api/data/Data.java b/transfer/fabric/src/main/java/band/kessoku/lib/api/transfer/fabric/KessokuTransferFabric.java similarity index 58% rename from data/common/src/main/java/band/kessoku/lib/api/data/Data.java rename to transfer/fabric/src/main/java/band/kessoku/lib/api/transfer/fabric/KessokuTransferFabric.java index adbd1ab2..80200acd 100644 --- a/data/common/src/main/java/band/kessoku/lib/api/data/Data.java +++ b/transfer/fabric/src/main/java/band/kessoku/lib/api/transfer/fabric/KessokuTransferFabric.java @@ -13,26 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.api.data; +package band.kessoku.lib.api.transfer.fabric; -import org.jetbrains.annotations.NotNull; +import band.kessoku.lib.api.KessokuLib; +import band.kessoku.lib.api.transfer.KessokuTransfer; +import net.fabricmc.api.ModInitializer; -/** - * A fundamental part for Kessoku Lib to hold data. - *

- * This data is only readable in most cases, and it can be considered immutable. - *

- * @param The type of data. - */ -public interface Data { - /** - * @return The value. - */ - T get(); - - /** - * @return The id using to distinguish data. - */ - @NotNull - String id(); +public final class KessokuTransferFabric implements ModInitializer { + @Override + public void onInitialize() { + KessokuLib.loadModule(KessokuTransfer.class); + } } diff --git a/transfer/fabric/src/main/resources/fabric.mod.json b/transfer/fabric/src/main/resources/fabric.mod.json new file mode 100644 index 00000000..55932d1d --- /dev/null +++ b/transfer/fabric/src/main/resources/fabric.mod.json @@ -0,0 +1,39 @@ +{ + "schemaVersion": 1, + "id": "kessoku_data", + "version": "${version}", + "name": "Kessoku Transfer", + "description": "A Item/Fluid/Energy Transfer API.", + "authors": [ + "Kessoku Tea Time" + ], + "contact": { + "homepage": "https://modrinth.com/mod/kessoku-lib", + "sources": "https://github.com/KessokuTeaTime/KessokuLib", + "issues": "https://github.com/KessokuTeaTime/KessokuLib/issues" + }, + "license": "LGPL-3.0-only", + "icon": "icon.png", + "entrypoints": { + "main": [ + "band.kessoku.lib.api.transfer.fabric.KessokuTransferFabric" + ] + }, + "environment": "*", + "depends": { + "fabricloader": ">=0.16.0", + "minecraft": "1.21", + "java": ">=21", + "fabric-api": "*" + }, + "mixins": [ + "kessoku_transfer.mixins.json" + ], + "custom": { + "modmenu": { + "badges": [ + "library" + ] + } + } +} \ No newline at end of file diff --git a/transfer/neo/build.gradle b/transfer/neo/build.gradle new file mode 100644 index 00000000..48c295ee --- /dev/null +++ b/transfer/neo/build.gradle @@ -0,0 +1,12 @@ +import net.fabricmc.loom.util.ModPlatform + +apply from: rootProject.file("gradle/scripts/klib-neo.gradle") + +base.archivesName = rootProject.name + "-transfer" + +kessoku { + module("base", "common") + + common("transfer", ModPlatform.NEOFORGE) + shadowBundle("transfer", ModPlatform.NEOFORGE) +} diff --git a/transfer/neo/gradle.properties b/transfer/neo/gradle.properties new file mode 100644 index 00000000..2914393d --- /dev/null +++ b/transfer/neo/gradle.properties @@ -0,0 +1 @@ +loom.platform=neoforge \ No newline at end of file diff --git a/data/common/src/main/java/band/kessoku/lib/api/data/MutableData.java b/transfer/neo/src/main/java/band/kessoku/lib/api/transfer/neoforge/KessokuTransferNeoforge.java similarity index 63% rename from data/common/src/main/java/band/kessoku/lib/api/data/MutableData.java rename to transfer/neo/src/main/java/band/kessoku/lib/api/transfer/neoforge/KessokuTransferNeoforge.java index 81972ec8..10695e75 100644 --- a/data/common/src/main/java/band/kessoku/lib/api/data/MutableData.java +++ b/transfer/neo/src/main/java/band/kessoku/lib/api/transfer/neoforge/KessokuTransferNeoforge.java @@ -13,15 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.api.data; +package band.kessoku.lib.api.transfer.neoforge; -/** - * A fundamental part for Kessoku Lib to hold data. - *

- * This data is mutable. - *

- * @param The type of data. - */ -public interface MutableData extends Data { - void set(T newValue); +import band.kessoku.lib.api.KessokuLib; +import band.kessoku.lib.api.transfer.KessokuTransfer; +import net.neoforged.fml.common.Mod; + +@Mod(KessokuTransfer.MOD_ID) +public final class KessokuTransferNeoforge { + public KessokuTransferNeoforge() { + KessokuLib.loadModule(KessokuTransfer.class); + } } diff --git a/transfer/neo/src/main/resources/META-INF/neoforge.mods.toml b/transfer/neo/src/main/resources/META-INF/neoforge.mods.toml new file mode 100644 index 00000000..401d4eb7 --- /dev/null +++ b/transfer/neo/src/main/resources/META-INF/neoforge.mods.toml @@ -0,0 +1,29 @@ +modLoader = "javafml" +loaderVersion = "[4,)" +license = "LGPL-3.0-only" +issueTrackerURL = "https://github.com/KessokuTeaTime/KessokuLib/issues" + +[[mods]] +modId = "kessoku_transfer" +version = "${version}" +displayName = "Kessoku Block Entity" +description = ''' +A Item/Fluid/Energy Transfer API. +''' +logoFile = "icon.png" +authors = "Kessoku Tea Time" +displayURL = "https://modrinth.com/mod/kessoku-lib" + +[[dependencies.kessoku_transfer]] +modId = "neoforge" +type = "required" +versionRange = "[21.0,)" +ordering = "NONE" +side = "BOTH" + +[[dependencies.kessoku_transfer]] +modId = "minecraft" +type = "required" +versionRange = "[1.21,)" +ordering = "NONE" +side = "BOTH" \ No newline at end of file