From 5a0dc68bbfcce936eccec33ba28a8dfb666faee7 Mon Sep 17 00:00:00 2001 From: chemiofitor <98449295+chemiofitor@users.noreply.github.com> Date: Sat, 11 Nov 2023 18:37:57 +0800 Subject: [PATCH] 2.0.0 Formal Push --- build.gradle | 63 ++++----- gradle.properties | 15 +-- .../java/ho/artisan/holib/HOLibClient.java | 11 -- .../java/ho/artisan/holib/HOLibDataGen.java | 11 -- .../java/ho/artisan/holib/HOLibExample.java | 43 ------ src/main/java/ho/artisan/holib/HOLibMod.java | 20 --- .../holib/common/block/HBlockWithEntity.java | 56 -------- .../common/blockentity/HBlockEntity.java | 49 ------- .../common/blockentity/data/DataList.java | 104 --------------- .../common/blockentity/data/StoreList.java | 113 ---------------- .../common/blockentity/data/StoreStack.java | 122 ------------------ .../blockentity/extra/ISaveToBlock.java | 9 -- .../holib/common/screen/HScreenHandler.java | 78 ----------- .../java/ho/artisan/holib/impl/HOBlock.java | 43 ------ .../java/ho/artisan/holib/impl/HOScreen.java | 35 ----- .../artisan/holib/impl/HOScreenHandler.java | 32 ----- .../java/ho/artisan/holib/impl/HOTile.java | 65 ---------- .../ho/artisan/holib/registry/Registrar.java | 26 ---- .../holib/registry/RegistryCasket.java | 55 -------- .../registrar/BlockEntityTypeRegistrar.java | 23 ---- .../registry/registrar/BlockRegistrar.java | 19 --- .../registrar/ItemGroupRegistrar.java | 33 ----- .../registry/registrar/ItemRegistrar.java | 48 ------- .../artisan/holib/tool/i18n/Translator.java | 42 ------ .../artisan/holib/tool/old/ExtraInGroup.java | 14 -- .../artisan/holib/tool/old/OldRegistrar.java | 101 --------------- .../artisan/holib/tool/tag/TagGenerator.java | 17 --- src/main/java/ho/artisan/lib/HOLibrary.java | 21 +++ .../ho/artisan/lib/common/item/FuelItem.java | 19 +++ .../lib/example/HORegistryHandler.java | 60 +++++++++ .../artisan/lib/gen/IdentifierGenerator.java | 23 ++++ .../java/ho/artisan/lib/gen/TagGenerator.java | 24 ++++ .../java/ho/artisan/lib/registry/Casket.java | 52 ++++++++ .../registrar/BlockEntityTypeRegistrar.java | 21 +++ .../registry/registrar/BlockRegistrar.java | 56 ++++++++ .../lib/registry/registrar/IRegistrar.java | 47 +++++++ .../lib/registry/registrar/ItemRegistrar.java | 82 ++++++++++++ .../registry/registrar/VanillaRegistrar.java | 48 +++++++ src/main/resources/fabric.mod.json | 14 +- .../{holib.mixins.json => holib.mixin.json} | 6 +- 40 files changed, 490 insertions(+), 1230 deletions(-) delete mode 100644 src/main/java/ho/artisan/holib/HOLibClient.java delete mode 100644 src/main/java/ho/artisan/holib/HOLibDataGen.java delete mode 100644 src/main/java/ho/artisan/holib/HOLibExample.java delete mode 100644 src/main/java/ho/artisan/holib/HOLibMod.java delete mode 100644 src/main/java/ho/artisan/holib/common/block/HBlockWithEntity.java delete mode 100644 src/main/java/ho/artisan/holib/common/blockentity/HBlockEntity.java delete mode 100644 src/main/java/ho/artisan/holib/common/blockentity/data/DataList.java delete mode 100644 src/main/java/ho/artisan/holib/common/blockentity/data/StoreList.java delete mode 100644 src/main/java/ho/artisan/holib/common/blockentity/data/StoreStack.java delete mode 100644 src/main/java/ho/artisan/holib/common/blockentity/extra/ISaveToBlock.java delete mode 100644 src/main/java/ho/artisan/holib/common/screen/HScreenHandler.java delete mode 100644 src/main/java/ho/artisan/holib/impl/HOBlock.java delete mode 100644 src/main/java/ho/artisan/holib/impl/HOScreen.java delete mode 100644 src/main/java/ho/artisan/holib/impl/HOScreenHandler.java delete mode 100644 src/main/java/ho/artisan/holib/impl/HOTile.java delete mode 100644 src/main/java/ho/artisan/holib/registry/Registrar.java delete mode 100644 src/main/java/ho/artisan/holib/registry/RegistryCasket.java delete mode 100644 src/main/java/ho/artisan/holib/registry/registrar/BlockEntityTypeRegistrar.java delete mode 100644 src/main/java/ho/artisan/holib/registry/registrar/BlockRegistrar.java delete mode 100644 src/main/java/ho/artisan/holib/registry/registrar/ItemGroupRegistrar.java delete mode 100644 src/main/java/ho/artisan/holib/registry/registrar/ItemRegistrar.java delete mode 100644 src/main/java/ho/artisan/holib/tool/i18n/Translator.java delete mode 100644 src/main/java/ho/artisan/holib/tool/old/ExtraInGroup.java delete mode 100644 src/main/java/ho/artisan/holib/tool/old/OldRegistrar.java delete mode 100644 src/main/java/ho/artisan/holib/tool/tag/TagGenerator.java create mode 100644 src/main/java/ho/artisan/lib/HOLibrary.java create mode 100644 src/main/java/ho/artisan/lib/common/item/FuelItem.java create mode 100644 src/main/java/ho/artisan/lib/example/HORegistryHandler.java create mode 100644 src/main/java/ho/artisan/lib/gen/IdentifierGenerator.java create mode 100644 src/main/java/ho/artisan/lib/gen/TagGenerator.java create mode 100644 src/main/java/ho/artisan/lib/registry/Casket.java create mode 100644 src/main/java/ho/artisan/lib/registry/registrar/BlockEntityTypeRegistrar.java create mode 100644 src/main/java/ho/artisan/lib/registry/registrar/BlockRegistrar.java create mode 100644 src/main/java/ho/artisan/lib/registry/registrar/IRegistrar.java create mode 100644 src/main/java/ho/artisan/lib/registry/registrar/ItemRegistrar.java create mode 100644 src/main/java/ho/artisan/lib/registry/registrar/VanillaRegistrar.java rename src/main/resources/{holib.mixins.json => holib.mixin.json} (66%) diff --git a/build.gradle b/build.gradle index a240b57..1a862de 100644 --- a/build.gradle +++ b/build.gradle @@ -2,65 +2,48 @@ plugins { id 'fabric-loom' version '1.2-SNAPSHOT' } -version = project.mod_version -group = project.maven_group - -loom { - runs { - datagenClient { - inherit client - name "Minecraft Data" - vmArg "-Dfabric-api.datagen" - vmArg "-Dfabric-api.datagen.output-dir=${file("src/main/generated")}" - vmArg "-Dfabric-api.datagen.strict-validation" - - runDir "build/datagen" - } - } -} +version = minecraft_version + '-' + mod_version +group = maven_group +archivesBaseName = mod_name loom { accessWidenerPath = file("src/main/resources/holib.accesswidener") } -sourceSets { - main { - resources { - srcDirs += ['src/main/generated'] - } - } -} - repositories { - maven { - url = "https://maven.terraformersmc.com/releases/" - } - maven { - url = "https://maven.resourcefulbees.com/repository/maven-public/" - } - maven { - url = "https://api.modrinth.com/maven" - } + maven { url "https://maven.terraformersmc.com/releases/" } + maven { url "https://api.modrinth.com/maven" } } dependencies { minecraft "com.mojang:minecraft:${project.minecraft_version}" mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" - modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" + modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" - modImplementation "com.terraformersmc:modmenu:${project.modmenu_version}" - - include modApi('teamreborn:energy:3.0.0') { - exclude(group: "net.fabricmc.fabric-api") - } } processResources { inputs.property "version", project.version - filteringCharset "UTF-8" filesMatching("fabric.mod.json") { expand "version": project.version } +} + +tasks.withType(JavaCompile).configureEach { + it.options.release = 17 +} + +java { + withSourcesJar() + + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 +} + +jar { + from("LICENSE") { + rename { "${it}_" + archivesBaseName} + } } \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 50f4e34..280183e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,16 +1,15 @@ -# Done to increase the memory available to gradle. org.gradle.jvmargs=-Xmx2G # Fabric Properties -minecraft_version=1.20.1 -yarn_mappings=1.20.1+build.10 +minecraft_version=1.18.2 +yarn_mappings=1.18.2+build.4 loader_version=0.14.22 # Mod Properties -mod_version=1.0.3 -maven_group=ho.artisan -archives_base_name=HO-Library +mod_version=2.1.0 +maven_group=ho.artisan.lib +mod_name=HOLibrary +mod_id=holib # Dependencies -fabric_version=0.87.0+1.20.1 -modmenu_version=7.1.0 \ No newline at end of file +fabric_version=0.76.0+1.18.2 \ No newline at end of file diff --git a/src/main/java/ho/artisan/holib/HOLibClient.java b/src/main/java/ho/artisan/holib/HOLibClient.java deleted file mode 100644 index cca6a21..0000000 --- a/src/main/java/ho/artisan/holib/HOLibClient.java +++ /dev/null @@ -1,11 +0,0 @@ -package ho.artisan.holib; - -import net.fabricmc.api.ClientModInitializer; - -public class HOLibClient implements ClientModInitializer { - - @Override - public void onInitializeClient() { - - } -} diff --git a/src/main/java/ho/artisan/holib/HOLibDataGen.java b/src/main/java/ho/artisan/holib/HOLibDataGen.java deleted file mode 100644 index 805e86f..0000000 --- a/src/main/java/ho/artisan/holib/HOLibDataGen.java +++ /dev/null @@ -1,11 +0,0 @@ -package ho.artisan.holib; - -import net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint; -import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator; - -public class HOLibDataGen implements DataGeneratorEntrypoint { - @Override - public void onInitializeDataGenerator(FabricDataGenerator generator) { - - } -} diff --git a/src/main/java/ho/artisan/holib/HOLibExample.java b/src/main/java/ho/artisan/holib/HOLibExample.java deleted file mode 100644 index d59618b..0000000 --- a/src/main/java/ho/artisan/holib/HOLibExample.java +++ /dev/null @@ -1,43 +0,0 @@ -package ho.artisan.holib; - - -import ho.artisan.holib.registry.RegistryCasket; -import ho.artisan.holib.registry.registrar.BlockEntityTypeRegistrar; -import ho.artisan.holib.registry.registrar.BlockRegistrar; -import ho.artisan.holib.registry.registrar.ItemGroupRegistrar; -import ho.artisan.holib.registry.registrar.ItemRegistrar; -import net.minecraft.block.Block; -import net.minecraft.block.Blocks; -import net.minecraft.item.BlockItem; -import net.minecraft.item.Item; -import net.minecraft.item.ItemGroup; -import net.minecraft.item.ItemStack; - -import static ho.artisan.holib.HOLibMod.MOD_ID; - -public class HOLibExample { - public static final RegistryCasket IRON_COAL_BLOCK; - - public static final RegistryCasket IRON_COAL_BLOCK_ITEM; - public static final RegistryCasket IRON_COAL; - - public static final ItemGroup MAIN; - - static { - BlockRegistrar blockRegistrar = new BlockRegistrar(MOD_ID); - IRON_COAL_BLOCK = blockRegistrar.function("iron_coal_block", Block::new, Blocks.IRON_BLOCK); - - BlockEntityTypeRegistrar blockEntityTypeRegistrar = new BlockEntityTypeRegistrar(MOD_ID); - //blockEntityTypeRegistrar.register("iron_coal_block", IronCoalBlockEntity::new, IRON_COAL_BLOCK.get()) - - ItemRegistrar itemRegistrar = new ItemRegistrar(MOD_ID); - IRON_COAL_BLOCK_ITEM = itemRegistrar.blockItem("iron_coal_block", IRON_COAL_BLOCK); - IRON_COAL = itemRegistrar.simple("iron_coal"); - - ItemGroupRegistrar itemGroupRegistrar = new ItemGroupRegistrar(MOD_ID); - - MAIN = itemGroupRegistrar.register("main", itemRegistrar.list(), itemGroup -> { - itemGroup.icon(IRON_COAL.supplier(ItemStack::new)); - }).get(); - } -} diff --git a/src/main/java/ho/artisan/holib/HOLibMod.java b/src/main/java/ho/artisan/holib/HOLibMod.java deleted file mode 100644 index 06e15d4..0000000 --- a/src/main/java/ho/artisan/holib/HOLibMod.java +++ /dev/null @@ -1,20 +0,0 @@ -package ho.artisan.holib; - -import ho.artisan.holib.registry.registrar.ItemRegistrar; -import net.fabricmc.api.ModInitializer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class HOLibMod implements ModInitializer { - public static final String MOD_ID = "holib"; - public static final String MOD_NAME = "HO-Library"; - public static final Logger LOGGER = LoggerFactory.getLogger(MOD_NAME); - private static final ItemRegistrar ITEM_REGISTRAR = new ItemRegistrar(MOD_ID); - - - @Override - public void onInitialize() { - //RegistrationResolver.process(RegistrationExample.class); - LOGGER.info(MOD_NAME + " has set up!"); - } -} diff --git a/src/main/java/ho/artisan/holib/common/block/HBlockWithEntity.java b/src/main/java/ho/artisan/holib/common/block/HBlockWithEntity.java deleted file mode 100644 index 5e46af0..0000000 --- a/src/main/java/ho/artisan/holib/common/block/HBlockWithEntity.java +++ /dev/null @@ -1,56 +0,0 @@ -package ho.artisan.holib.common.block; - -import ho.artisan.holib.common.blockentity.extra.ISaveToBlock; -import net.minecraft.block.BlockRenderType; -import net.minecraft.block.BlockState; -import net.minecraft.block.BlockWithEntity; -import net.minecraft.block.entity.BlockEntity; -import net.minecraft.block.entity.BlockEntityType; -import net.minecraft.entity.ItemEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.BlockItem; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.BlockView; -import net.minecraft.world.World; - -import java.util.Optional; - -public abstract class HBlockWithEntity extends BlockWithEntity { - public HBlockWithEntity(Settings settings) { - super(settings); - } - - @Override - public void onBreak(World world, BlockPos pos, BlockState state, PlayerEntity player) { - BlockEntity blockEntity = world.getBlockEntity(pos); - if (blockEntity instanceof ISaveToBlock iSave) { - if (!world.isClient && iSave.hasToSave()) { - ItemStack drop = new ItemStack(state.getBlock()); - BlockItem.setBlockEntityNbt(drop, blockEntity.getType(), iSave.saveToBlock(new NbtCompound())); - - ItemEntity itemEntity = new ItemEntity(world, (double)pos.getX() + 0.5, (double)pos.getY() + 0.5, (double)pos.getZ() + 0.5, drop); - itemEntity.setToDefaultPickupDelay(); - world.spawnEntity(itemEntity); - } - } - super.onBreak(world, pos, state, player); - } - - @Override - public ItemStack getPickStack(BlockView world, BlockPos pos, BlockState state) { - ItemStack drop = super.getPickStack(world, pos, state); - Optional optional = world.getBlockEntity(pos, getBlockEntityType()); - if (optional.isPresent() && optional.get() instanceof ISaveToBlock iSave) - BlockItem.setBlockEntityNbt(drop, optional.get().getType(), iSave.saveToBlock(new NbtCompound())); - return drop; - } - - public abstract BlockEntityType getBlockEntityType(); - - @Override - public BlockRenderType getRenderType(BlockState state) { - return BlockRenderType.MODEL; - } -} diff --git a/src/main/java/ho/artisan/holib/common/blockentity/HBlockEntity.java b/src/main/java/ho/artisan/holib/common/blockentity/HBlockEntity.java deleted file mode 100644 index 27dd728..0000000 --- a/src/main/java/ho/artisan/holib/common/blockentity/HBlockEntity.java +++ /dev/null @@ -1,49 +0,0 @@ -package ho.artisan.holib.common.blockentity; - -import net.minecraft.block.BlockState; -import net.minecraft.block.entity.BlockEntity; -import net.minecraft.block.entity.BlockEntityType; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.network.listener.ClientPlayPacketListener; -import net.minecraft.network.packet.Packet; -import net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket; -import net.minecraft.util.math.BlockPos; -import org.jetbrains.annotations.NotNull; - -public abstract class HBlockEntity extends BlockEntity { - - public HBlockEntity(BlockEntityType type, BlockPos pos, BlockState state) { - super(type, pos, state); - } - - public abstract void read(NbtCompound nbt, boolean isClient); - - public abstract void write(NbtCompound nbt, boolean isClient); - - @Override - public void readNbt(NbtCompound nbt) { - this.read(nbt, false); - super.readNbt(nbt); - } - - @Override - public void writeNbt(NbtCompound nbt) { - this.write(nbt, false); - super.writeNbt(nbt); - } - - @Override - public NbtCompound toInitialChunkDataNbt() { - NbtCompound nbt = super.createNbt(); - this.write(nbt, true); - return nbt; - } - - @NotNull - @Override - public Packet toUpdatePacket() { - NbtCompound nbt = new NbtCompound(); - this.write(nbt, true); - return BlockEntityUpdateS2CPacket.create(this); - } -} diff --git a/src/main/java/ho/artisan/holib/common/blockentity/data/DataList.java b/src/main/java/ho/artisan/holib/common/blockentity/data/DataList.java deleted file mode 100644 index f66232a..0000000 --- a/src/main/java/ho/artisan/holib/common/blockentity/data/DataList.java +++ /dev/null @@ -1,104 +0,0 @@ -package ho.artisan.holib.common.blockentity.data; - -import net.minecraft.nbt.NbtCompound; -import net.minecraft.screen.PropertyDelegate; - -import java.util.ArrayList; -import java.util.List; - -public class DataList { - private final List valueList; - private final List idList; - - private final PropertyDelegate delegate = new PropertyDelegate() { - @Override - public int get(int index) { - return valueList.get(index); - } - - @Override - public void set(int index, int value) { - valueList.set(index, value); - } - - @Override - public int size() { - return valueList.size(); - } - }; - - public DataList(int size) { - this.valueList = new ArrayList<>(size); - for (int i = 0; i < size; i++) { - this.valueList.add(0); - } - this.idList = new ArrayList<>(size); - for (int i = 0; i < size; i++) { - this.idList.add("None"); - } - } - - public Value create(int index, int defaultValue, String id) { - valueList.set(index, defaultValue); - idList.set(index, id); - return new Value(index); - } - - public Value create(int index, String id) { - valueList.set(index, 0); - idList.set(index, id); - return new Value(index); - } - - public void write(NbtCompound nbt) { - for (int i = 0; i < valueList.size(); i++) { - nbt.putInt(idList.get(i), valueList.get(i)); - } - } - - public void read(NbtCompound nbt) { - for (int i = 0; i < idList.size(); i++) { - valueList.set(i, nbt.getInt(idList.get(i))); - } - } - - public class Value { - private final int index; - - public Value(int index) { - this.index = index; - } - - public int get() { - return valueList.get(index); - } - - public void set(int value) { - valueList.set(index, value); - } - - public void plus(int value) { - set(get() + value); - } - - public void minus(int value) { - set(get() - value); - } - - public void times(int value) { - set(get() * value); - } - - public void inc() { - plus(1); - } - - public void dec() { - minus(1); - } - } - - public PropertyDelegate delegate() { - return delegate; - } -} diff --git a/src/main/java/ho/artisan/holib/common/blockentity/data/StoreList.java b/src/main/java/ho/artisan/holib/common/blockentity/data/StoreList.java deleted file mode 100644 index 2658a90..0000000 --- a/src/main/java/ho/artisan/holib/common/blockentity/data/StoreList.java +++ /dev/null @@ -1,113 +0,0 @@ -package ho.artisan.holib.common.blockentity.data; - -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.inventory.Inventories; -import net.minecraft.inventory.SidedInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.nbt.NbtList; -import net.minecraft.util.collection.DefaultedList; -import net.minecraft.util.math.Direction; -import org.jetbrains.annotations.Nullable; - -import java.util.stream.IntStream; - -public class StoreList implements SidedInventory { - private final DefaultedList list; - - public StoreList(int size) { - this.list = DefaultedList.ofSize(size, ItemStack.EMPTY); - } - - @Override - public int[] getAvailableSlots(Direction side) { - return IntStream.range(0, list.size() - 1).toArray(); - } - - @Override - public boolean canInsert(int slot, ItemStack stack, @Nullable Direction dir) { - return true; - } - - @Override - public boolean canExtract(int slot, ItemStack stack, Direction dir) { - return true; - } - - @Override - public int size() { - return list.size(); - } - - @Override - public boolean isEmpty() { - for (ItemStack stack : list) { - if (!stack.isEmpty()) - return false; - } - return true; - } - - @Override - public ItemStack getStack(int slot) { - return list.get(slot); - } - - @Override - public ItemStack removeStack(int slot, int amount) { - return Inventories.splitStack(list, slot, amount); - } - - @Override - public ItemStack removeStack(int slot) { - return Inventories.removeStack(list, slot); - } - - @Override - public void setStack(int slot, ItemStack stack) { - list.set(slot, stack); - } - - @Override - public void markDirty() { - - } - - @Override - public boolean canPlayerUse(PlayerEntity player) { - return true; - } - - @Override - public void clear() { - list.clear(); - } - - public void write(NbtCompound nbt) { - NbtList nbtList = new NbtList(); - - for(int i = 0; i < list.size(); ++i) { - ItemStack itemStack = list.get(i); - if (!itemStack.isEmpty()) { - NbtCompound nbtCompound = new NbtCompound(); - nbtCompound.putByte("Slot", (byte)i); - itemStack.writeNbt(nbtCompound); - nbtList.add(nbtCompound); - } - } - - nbt.put("Items", nbtList); - } - - public void read(NbtCompound nbt) { - NbtList nbtList = nbt.getList("Items", 10); - - for(int i = 0; i < nbtList.size(); ++i) { - NbtCompound nbtCompound = nbtList.getCompound(i); - int j = nbtCompound.getByte("Slot") & 255; - if (j < list.size()) { - list.set(j, ItemStack.fromNbt(nbtCompound)); - } - } - } -} diff --git a/src/main/java/ho/artisan/holib/common/blockentity/data/StoreStack.java b/src/main/java/ho/artisan/holib/common/blockentity/data/StoreStack.java deleted file mode 100644 index b3e153c..0000000 --- a/src/main/java/ho/artisan/holib/common/blockentity/data/StoreStack.java +++ /dev/null @@ -1,122 +0,0 @@ -package ho.artisan.holib.common.blockentity.data; - -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.inventory.Inventories; -import net.minecraft.inventory.SidedInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.nbt.NbtList; -import net.minecraft.util.math.Direction; -import org.jetbrains.annotations.Nullable; - -import java.util.Stack; -import java.util.stream.IntStream; - -public class StoreStack implements SidedInventory { - private final Stack collection; - - public StoreStack() { - this.collection = new Stack<>(); - } - - @Override - public int[] getAvailableSlots(Direction side) { - return IntStream.range(0, collection.size() - 1).toArray(); - } - - @Override - public boolean canInsert(int slot, ItemStack stack, @Nullable Direction dir) { - return true; - } - - @Override - public boolean canExtract(int slot, ItemStack stack, Direction dir) { - return true; - } - - @Override - public int size() { - return collection.size(); - } - - @Override - public boolean isEmpty() { - return collection.isEmpty(); - } - - @Override - public ItemStack getStack(int slot) { - return collection.get(slot); - } - - @Override - public ItemStack removeStack(int slot, int amount) { - return Inventories.splitStack(collection, slot, amount); - } - - @Override - public ItemStack removeStack(int slot) { - return Inventories.removeStack(collection, slot); - } - - @Override - public void setStack(int slot, ItemStack stack) { - if (!stack.isEmpty() && slot < collection.size()) - collection.set(slot, stack); - } - - public ItemStack popStack() { - return collection.pop(); - } - - public void pushStack(ItemStack stack) { - collection.push(stack); - } - - public ItemStack peekStack() { - return collection.peek(); - } - - @Override - public void markDirty() { - - } - - @Override - public boolean canPlayerUse(PlayerEntity player) { - return true; - } - - @Override - public void clear() { - collection.clear(); - } - - public void write(NbtCompound nbt) { - NbtList nbtList = new NbtList(); - - for(int i = 0; i < collection.size(); ++i) { - ItemStack itemStack = collection.get(i); - if (!itemStack.isEmpty()) { - NbtCompound nbtCompound = new NbtCompound(); - nbtCompound.putByte("Slot", (byte)i); - itemStack.writeNbt(nbtCompound); - nbtList.add(nbtCompound); - } - } - - nbt.put("Items", nbtList); - } - - public void read(NbtCompound nbt) { - NbtList nbtList = nbt.getList("Items", 10); - - for(int i = 0; i < nbtList.size(); ++i) { - NbtCompound nbtCompound = nbtList.getCompound(i); - int j = nbtCompound.getByte("Slot") & 255; - if (j < collection.size()) { - collection.set(j, ItemStack.fromNbt(nbtCompound)); - } - } - } -} diff --git a/src/main/java/ho/artisan/holib/common/blockentity/extra/ISaveToBlock.java b/src/main/java/ho/artisan/holib/common/blockentity/extra/ISaveToBlock.java deleted file mode 100644 index 491148a..0000000 --- a/src/main/java/ho/artisan/holib/common/blockentity/extra/ISaveToBlock.java +++ /dev/null @@ -1,9 +0,0 @@ -package ho.artisan.holib.common.blockentity.extra; - -import net.minecraft.nbt.NbtCompound; - -public interface ISaveToBlock { - NbtCompound saveToBlock(NbtCompound nbt); - - boolean hasToSave(); -} diff --git a/src/main/java/ho/artisan/holib/common/screen/HScreenHandler.java b/src/main/java/ho/artisan/holib/common/screen/HScreenHandler.java deleted file mode 100644 index 33d3933..0000000 --- a/src/main/java/ho/artisan/holib/common/screen/HScreenHandler.java +++ /dev/null @@ -1,78 +0,0 @@ -package ho.artisan.holib.common.screen; - -import ho.artisan.holib.common.blockentity.data.DataList; -import ho.artisan.holib.common.blockentity.data.StoreList; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.screen.ScreenHandler; -import net.minecraft.screen.ScreenHandlerType; -import net.minecraft.screen.slot.Slot; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -public abstract class HScreenHandler extends ScreenHandler { - private final StoreList storeList; - public final DataList dataList; - - public HScreenHandler(@NotNull ScreenHandlerType type, int syncId, PlayerInventory playerInventory, @Nullable StoreList storeList, DataList dataList) { - super(type, syncId); - this.storeList = storeList; - this.dataList = dataList; - - if (storeList != null) { - storeList.onOpen(playerInventory.player); - this.addSlots(storeList); - } - - this.addPlayerSlots(playerInventory); - - this.addProperties(dataList.delegate()); - } - - @Override - public ItemStack quickMove(PlayerEntity player, int slot) { - ItemStack itemStack = ItemStack.EMPTY; - Slot slot2 = this.slots.get(slot); - if (slot2.hasStack()) { - ItemStack itemStack2 = slot2.getStack(); - itemStack = itemStack2.copy(); - if (slot < this.storeList.size()) { - if (!this.insertItem(itemStack2, this.storeList.size(), this.slots.size(), true)) { - return ItemStack.EMPTY; - } - } else if (!this.insertItem(itemStack2, 0, this.storeList.size(), false)) { - return ItemStack.EMPTY; - } - if (itemStack2.isEmpty()) { - slot2.setStack(ItemStack.EMPTY); - } else { - slot2.markDirty(); - } - } - - return itemStack; - } - - @Override - public boolean canUse(PlayerEntity player) { - return this.storeList.canPlayerUse(player); - } - - public void addPlayerSlots(PlayerInventory playerInventory) { - int m; - int l; - - for (m = 0; m < 3; ++m) { - for (l = 0; l < 9; ++l) { - this.addSlot(new Slot(playerInventory, l + m * 9 + 9, 8 + l * 18, 84 + m * 18)); - } - } - - for (m = 0; m < 9; ++m) { - this.addSlot(new Slot(playerInventory, m, 8 + m * 18, 142)); - } - } - - public abstract void addSlots(StoreList storeList); -} diff --git a/src/main/java/ho/artisan/holib/impl/HOBlock.java b/src/main/java/ho/artisan/holib/impl/HOBlock.java deleted file mode 100644 index f10890e..0000000 --- a/src/main/java/ho/artisan/holib/impl/HOBlock.java +++ /dev/null @@ -1,43 +0,0 @@ -package ho.artisan.holib.impl; - -import ho.artisan.holib.common.block.HBlockWithEntity; -import net.minecraft.block.BlockState; -import net.minecraft.block.entity.BlockEntity; -import net.minecraft.block.entity.BlockEntityType; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.screen.NamedScreenHandlerFactory; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.jetbrains.annotations.Nullable; - -public class HOBlock extends HBlockWithEntity { - public HOBlock(Settings settings) { - super(settings); - } - - @Override - public BlockEntityType getBlockEntityType() { - throw new AssertionError(); - } - - @Override - public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { - if (!world.isClient) { - NamedScreenHandlerFactory screenHandlerFactory = state.createScreenHandlerFactory(world, pos); - - if (screenHandlerFactory != null) { - player.openHandledScreen(screenHandlerFactory); - } - } - return ActionResult.SUCCESS; - } - - @Nullable - @Override - public BlockEntity createBlockEntity(BlockPos pos, BlockState state) { - throw new AssertionError(); - } -} diff --git a/src/main/java/ho/artisan/holib/impl/HOScreen.java b/src/main/java/ho/artisan/holib/impl/HOScreen.java deleted file mode 100644 index 7759d68..0000000 --- a/src/main/java/ho/artisan/holib/impl/HOScreen.java +++ /dev/null @@ -1,35 +0,0 @@ -package ho.artisan.holib.impl; - -import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.gui.screen.ingame.HandledScreen; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.text.Text; -import net.minecraft.util.Identifier; - -public class HOScreen extends HandledScreen { - private static final Identifier TEXTURE = new Identifier("minecraft", "textures/gui/container/dispenser.png"); - - public HOScreen(HOScreenHandler handler, PlayerInventory inventory, Text title) { - super(handler, inventory, title); - } - - @Override - protected void drawBackground(DrawContext context, float delta, int mouseX, int mouseY) { - int i = this.x; - int j = this.y; - context.drawTexture(TEXTURE, i, j, 0, 0, this.backgroundWidth, this.backgroundHeight); - } - - @Override - public void render(DrawContext context, int mouseX, int mouseY, float delta) { - renderBackground(context); - super.render(context, mouseX, mouseY, delta); - drawMouseoverTooltip(context, mouseX, mouseY); - } - - @Override - protected void init() { - super.init(); - titleX = (backgroundWidth - textRenderer.getWidth(title)) / 2; - } -} diff --git a/src/main/java/ho/artisan/holib/impl/HOScreenHandler.java b/src/main/java/ho/artisan/holib/impl/HOScreenHandler.java deleted file mode 100644 index 8207e11..0000000 --- a/src/main/java/ho/artisan/holib/impl/HOScreenHandler.java +++ /dev/null @@ -1,32 +0,0 @@ -package ho.artisan.holib.impl; - -import ho.artisan.holib.common.blockentity.data.DataList; -import ho.artisan.holib.common.blockentity.data.StoreList; -import ho.artisan.holib.common.screen.HScreenHandler; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.screen.ScreenHandlerType; -import net.minecraft.screen.slot.Slot; -import org.jetbrains.annotations.Nullable; - -public class HOScreenHandler extends HScreenHandler { - - public HOScreenHandler(ScreenHandlerType type, int syncId, PlayerInventory playerInventory) { - super(type, syncId, playerInventory, new StoreList(9), new DataList(2)); - } - - public HOScreenHandler(ScreenHandlerType type, int syncId, PlayerInventory playerInventory, @Nullable StoreList storeList, DataList dataList) { - super(type, syncId, playerInventory, storeList, dataList); - } - - @Override - public void addSlots(StoreList storeList) { - int m; - int l; - - for (m = 0; m < 3; ++m) { - for (l = 0; l < 3; ++l) { - this.addSlot(new Slot(storeList, l + m * 3, 62 + l * 18, 17 + m * 18)); - } - } - } -} diff --git a/src/main/java/ho/artisan/holib/impl/HOTile.java b/src/main/java/ho/artisan/holib/impl/HOTile.java deleted file mode 100644 index ced6937..0000000 --- a/src/main/java/ho/artisan/holib/impl/HOTile.java +++ /dev/null @@ -1,65 +0,0 @@ -package ho.artisan.holib.impl; - -import ho.artisan.holib.common.blockentity.HBlockEntity; -import ho.artisan.holib.common.blockentity.data.DataList; -import ho.artisan.holib.common.blockentity.data.StoreList; -import ho.artisan.holib.common.blockentity.extra.ISaveToBlock; -import net.fabricmc.fabric.api.transfer.v1.item.InventoryStorage; -import net.minecraft.block.BlockState; -import net.minecraft.block.entity.BlockEntityType; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.screen.NamedScreenHandlerFactory; -import net.minecraft.screen.ScreenHandler; -import net.minecraft.text.Text; -import net.minecraft.util.math.BlockPos; -import org.jetbrains.annotations.Nullable; - -public class HOTile extends HBlockEntity implements NamedScreenHandlerFactory, ISaveToBlock { - public final DataList data = new DataList(2); - public final StoreList store = new StoreList(9); - public final DataList.Value processTime = data.create(0, "ProcessTime"); - public final DataList.Value processTimeTotal = data.create(1, "ProcessTimeTotal"); - - public final InventoryStorage inventoryWrapper = InventoryStorage.of(store, null); - - - public HOTile(BlockEntityType type, BlockPos pos, BlockState state) { - super(type, pos, state); - } - - @Override - public void read(NbtCompound nbt, boolean isClient) { - data.read(nbt); - store.read(nbt); - } - - @Override - public void write(NbtCompound nbt, boolean isClient) { - data.write(nbt); - store.write(nbt); - } - - @Override - public Text getDisplayName() { - return Text.translatable(getCachedState().getBlock().getTranslationKey()); - } - - @Nullable - @Override - public ScreenHandler createMenu(int syncId, PlayerInventory playerInventory, PlayerEntity player) { - throw new AssertionError(); - } - - @Override - public NbtCompound saveToBlock(NbtCompound nbt) { - store.write(nbt); - return nbt; - } - - @Override - public boolean hasToSave() { - return !store.isEmpty(); - } -} diff --git a/src/main/java/ho/artisan/holib/registry/Registrar.java b/src/main/java/ho/artisan/holib/registry/Registrar.java deleted file mode 100644 index 9ebdb76..0000000 --- a/src/main/java/ho/artisan/holib/registry/Registrar.java +++ /dev/null @@ -1,26 +0,0 @@ -package ho.artisan.holib.registry; - -import net.minecraft.registry.Registry; -import net.minecraft.util.Identifier; - -public class Registrar { - private final Registry registry; - public final String modid; - - public Registrar(String modid, Registry registry) { - this.registry = registry; - this.modid = modid; - } - - public Registry getRegistry() { - return this.registry; - } - - public RegistryCasket register(String id, K object) { - return new RegistryCasket<>(Registry.register(registry, new Identifier(modid, id), object), genID(id)); - } - - public Identifier genID(String path) { - return new Identifier(modid, path); - } -} diff --git a/src/main/java/ho/artisan/holib/registry/RegistryCasket.java b/src/main/java/ho/artisan/holib/registry/RegistryCasket.java deleted file mode 100644 index a287192..0000000 --- a/src/main/java/ho/artisan/holib/registry/RegistryCasket.java +++ /dev/null @@ -1,55 +0,0 @@ -package ho.artisan.holib.registry; - -import net.minecraft.util.Identifier; - -import java.util.Objects; -import java.util.function.Function; -import java.util.function.Supplier; - -public class RegistryCasket implements Supplier { - private final T object; - private final Identifier id; - - public RegistryCasket(T object, Identifier id) { - this.object = object; - this.id = id; - } - - public boolean is(T object) { - return this.object == object; - } - - @Override - public T get() { - return object; - } - - public K act(Function function) { - return function.apply(object); - } - - public Supplier supplier(Function function) { - return () -> function.apply(object); - } - - public Identifier id() { - return id; - } - - @Override - public String toString() { - return object.toString(); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof RegistryCasket that)) return false; - return Objects.equals(object, that.object) && Objects.equals(id, that.id); - } - - @Override - public int hashCode() { - return Objects.hash(object, id); - } -} diff --git a/src/main/java/ho/artisan/holib/registry/registrar/BlockEntityTypeRegistrar.java b/src/main/java/ho/artisan/holib/registry/registrar/BlockEntityTypeRegistrar.java deleted file mode 100644 index d092e44..0000000 --- a/src/main/java/ho/artisan/holib/registry/registrar/BlockEntityTypeRegistrar.java +++ /dev/null @@ -1,23 +0,0 @@ -package ho.artisan.holib.registry.registrar; - -import ho.artisan.holib.registry.Registrar; -import ho.artisan.holib.registry.RegistryCasket; -import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder; -import net.minecraft.block.Block; -import net.minecraft.block.entity.BlockEntity; -import net.minecraft.block.entity.BlockEntityType; -import net.minecraft.registry.Registries; - -public class BlockEntityTypeRegistrar extends Registrar> { - public BlockEntityTypeRegistrar(String modid) { - super(modid, Registries.BLOCK_ENTITY_TYPE); - } - - - public RegistryCasket> register( - String id, - FabricBlockEntityTypeBuilder.Factory factory, - Block... blocks) { - return register(id, FabricBlockEntityTypeBuilder.create(factory, blocks).build()); - } -} diff --git a/src/main/java/ho/artisan/holib/registry/registrar/BlockRegistrar.java b/src/main/java/ho/artisan/holib/registry/registrar/BlockRegistrar.java deleted file mode 100644 index b5adb0d..0000000 --- a/src/main/java/ho/artisan/holib/registry/registrar/BlockRegistrar.java +++ /dev/null @@ -1,19 +0,0 @@ -package ho.artisan.holib.registry.registrar; - -import ho.artisan.holib.registry.Registrar; -import ho.artisan.holib.registry.RegistryCasket; -import net.minecraft.block.AbstractBlock; -import net.minecraft.block.Block; -import net.minecraft.registry.Registries; - -import java.util.function.Function; - -public class BlockRegistrar extends Registrar { - public BlockRegistrar(String modid) { - super(modid, Registries.BLOCK); - } - - public RegistryCasket function(String id, Function blockFunction, Block copy) { - return super.register(id, blockFunction.apply(AbstractBlock.Settings.copy(copy))); - } -} diff --git a/src/main/java/ho/artisan/holib/registry/registrar/ItemGroupRegistrar.java b/src/main/java/ho/artisan/holib/registry/registrar/ItemGroupRegistrar.java deleted file mode 100644 index 154f545..0000000 --- a/src/main/java/ho/artisan/holib/registry/registrar/ItemGroupRegistrar.java +++ /dev/null @@ -1,33 +0,0 @@ -package ho.artisan.holib.registry.registrar; - -import ho.artisan.holib.registry.Registrar; -import ho.artisan.holib.registry.RegistryCasket; -import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup; -import net.minecraft.item.Item; -import net.minecraft.item.ItemGroup; -import net.minecraft.registry.Registries; -import net.minecraft.text.Text; - -import java.util.List; -import java.util.function.Consumer; - -public class ItemGroupRegistrar extends Registrar { - public ItemGroupRegistrar(String modid) { - super(modid, Registries.ITEM_GROUP); - } - - public RegistryCasket register(String id, List> list) { - var builder = FabricItemGroup.builder() - .displayName(Text.translatable("itemGroup." + this.modid + "." + id)) - .entries((displayContext, entries) -> list.forEach(item -> entries.add(item::get))); - return super.register(id, builder.build()); - } - - public RegistryCasket register(String id, List> list, Consumer consumer) { - var builder = FabricItemGroup.builder() - .displayName(Text.translatable("itemGroup." + this.modid + "." + id)) - .entries((displayContext, entries) -> list.forEach(item -> entries.add(item::get))); - consumer.accept(builder); - return super.register(id, builder.build()); - } -} diff --git a/src/main/java/ho/artisan/holib/registry/registrar/ItemRegistrar.java b/src/main/java/ho/artisan/holib/registry/registrar/ItemRegistrar.java deleted file mode 100644 index 82d65d5..0000000 --- a/src/main/java/ho/artisan/holib/registry/registrar/ItemRegistrar.java +++ /dev/null @@ -1,48 +0,0 @@ -package ho.artisan.holib.registry.registrar; - -import ho.artisan.holib.registry.Registrar; -import ho.artisan.holib.registry.RegistryCasket; -import net.minecraft.block.Block; -import net.minecraft.item.BlockItem; -import net.minecraft.item.Item; -import net.minecraft.registry.Registries; - -import java.util.ArrayList; -import java.util.List; -import java.util.function.Function; -import java.util.function.Supplier; - -public class ItemRegistrar extends Registrar { - private final List> list = new ArrayList<>(); - - public ItemRegistrar(String modid) { - super(modid, Registries.ITEM); - } - - @Override - public RegistryCasket register(String id, K object) { - var item = super.register(id, object); - list.add(item); - return item; - } - - public RegistryCasket function(String id, Function itemFunction) { - return register(id, itemFunction.apply(new Item.Settings())); - } - - public RegistryCasket simple(String id) { - return function(id, Item::new); - } - - public RegistryCasket blockItem(String id, Supplier block, Item.Settings settings) { - return register(id, new BlockItem(block.get(), settings)); - } - - public RegistryCasket blockItem(String id, Supplier block) { - return function(id, (settings -> new BlockItem(block.get(), settings))); - } - - public List> list() { - return list; - } -} diff --git a/src/main/java/ho/artisan/holib/tool/i18n/Translator.java b/src/main/java/ho/artisan/holib/tool/i18n/Translator.java deleted file mode 100644 index a45f62e..0000000 --- a/src/main/java/ho/artisan/holib/tool/i18n/Translator.java +++ /dev/null @@ -1,42 +0,0 @@ -package ho.artisan.holib.tool.i18n; - -import net.fabricmc.fabric.api.datagen.v1.provider.FabricLanguageProvider; -import net.minecraft.item.Item; -import net.minecraft.item.ItemGroup; -import net.minecraft.text.TranslatableTextContent; - -public class Translator { - private final FabricLanguageProvider.TranslationBuilder builder; - - public Translator(FabricLanguageProvider.TranslationBuilder builder) { - this.builder = builder; - } - - public void gen(Item item) { - builder.add(item, beautify(item.toString())); - } - - public void gen(Item... items) { - for (Item item : items) { - gen(item); - } - } - - public void gen(ItemGroup itemGroup, String name) { - if (itemGroup.getDisplayName().getContent() instanceof TranslatableTextContent content) - builder.add(content.getKey(), name); - } - - public String beautify(String name) { - String[] str1 = name.split("_"); - StringBuilder str2 = new StringBuilder(); - for (int i = 0; i < str1.length; i++) { - str1[i] = str1[i].substring(0, 1).toUpperCase() + str1[i].substring(1); - if (i == str1.length - 1) - str2.append(str1[i]); - else - str2.append(str1[i]).append(" "); - } - return str2.toString(); - } -} diff --git a/src/main/java/ho/artisan/holib/tool/old/ExtraInGroup.java b/src/main/java/ho/artisan/holib/tool/old/ExtraInGroup.java deleted file mode 100644 index e9bfe14..0000000 --- a/src/main/java/ho/artisan/holib/tool/old/ExtraInGroup.java +++ /dev/null @@ -1,14 +0,0 @@ -package ho.artisan.holib.tool.old; - -import net.minecraft.item.ItemStack; - -import java.util.List; - -@Deprecated -public interface ExtraInGroup { - void expand(List itemGroup); - - default boolean isSelfUsed() { - return true; - } -} diff --git a/src/main/java/ho/artisan/holib/tool/old/OldRegistrar.java b/src/main/java/ho/artisan/holib/tool/old/OldRegistrar.java deleted file mode 100644 index 9fbe1f2..0000000 --- a/src/main/java/ho/artisan/holib/tool/old/OldRegistrar.java +++ /dev/null @@ -1,101 +0,0 @@ -package ho.artisan.holib.tool.old; - -import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup; -import net.minecraft.block.Block; -import net.minecraft.block.entity.BlockEntity; -import net.minecraft.block.entity.BlockEntityType; -import net.minecraft.fluid.Fluid; -import net.minecraft.item.Item; -import net.minecraft.item.ItemGroup; -import net.minecraft.item.ItemStack; -import net.minecraft.recipe.Recipe; -import net.minecraft.recipe.RecipeSerializer; -import net.minecraft.recipe.RecipeType; -import net.minecraft.registry.Registries; -import net.minecraft.registry.Registry; -import net.minecraft.screen.ScreenHandler; -import net.minecraft.screen.ScreenHandlerType; -import net.minecraft.text.Text; -import net.minecraft.util.Identifier; - -import java.util.ArrayList; -import java.util.List; - -@Deprecated -public class OldRegistrar { - private final String modid; - private final List itemGroup; - - public OldRegistrar(String modid) { - this.modid = modid.toLowerCase(); - this.itemGroup = new ArrayList<>(); - } - - public void register(String id, T item) { - boolean flag = true; - if (item instanceof ExtraInGroup extra) { - extra.expand(itemGroup); - flag = extra.isSelfUsed(); - } - if (flag) - itemGroup.add(new ItemStack(item)); - register(Registries.ITEM, id, item); - } - - public void register(String id, T itemGroup) { - register(Registries.ITEM_GROUP, id, itemGroup); - } - - public void register(String id, T block) { - register(Registries.BLOCK, id, block); - } - - public void register(String id, T fluid) { - register(Registries.FLUID, id, fluid); - } - - public , T extends RecipeSerializer> void register(String id, T serializer) { - register(Registries.RECIPE_SERIALIZER, id, serializer); - } - - public , T extends RecipeType> void register(String id, T rType) { - register(Registries.RECIPE_TYPE, id, rType); - } - - public > void register(String id, T bType) { - register(Registries.BLOCK_ENTITY_TYPE, id, bType); - } - - public > void register(String id, T sType) { - register(Registries.SCREEN_HANDLER, id, sType); - } - - public ItemGroup.Builder createTab(String id, Item item) { - return FabricItemGroup.builder() - .displayName(Text.translatable("itemGroup." + modid + "." + id)) - .entries((displayContext, entries) -> entries.addAll(itemGroup)) - .icon(() -> new ItemStack(item)); - } - - public T register(Registry registry, String id, T object) { - return Registry.register(registry, createID(id), object); - } - - public Identifier createID(String path) { - return new Identifier(modid, path); - } - - public String getModid() { - return modid; - } - - public List getModItemStacks() { - return itemGroup; - } - - public List getModItems() { - List list = new ArrayList<>(); - itemGroup.forEach((itemStack) -> list.add(itemStack.getItem())); - return list; - } -} diff --git a/src/main/java/ho/artisan/holib/tool/tag/TagGenerator.java b/src/main/java/ho/artisan/holib/tool/tag/TagGenerator.java deleted file mode 100644 index ff1a56c..0000000 --- a/src/main/java/ho/artisan/holib/tool/tag/TagGenerator.java +++ /dev/null @@ -1,17 +0,0 @@ -package ho.artisan.holib.tool.tag; - -import net.minecraft.registry.Registry; -import net.minecraft.registry.tag.TagKey; -import net.minecraft.util.Identifier; - -public class TagGenerator { - private final Registry registry; - - public TagGenerator(Registry registry) { - this.registry = registry; - } - - public TagKey build(Identifier id) { - return TagKey.of(registry.getKey(), id); - } -} diff --git a/src/main/java/ho/artisan/lib/HOLibrary.java b/src/main/java/ho/artisan/lib/HOLibrary.java new file mode 100644 index 0000000..e2109c5 --- /dev/null +++ b/src/main/java/ho/artisan/lib/HOLibrary.java @@ -0,0 +1,21 @@ +package ho.artisan.lib; + +import ho.artisan.lib.example.HORegistryHandler; +import net.fabricmc.api.ModInitializer; +import net.fabricmc.loader.api.FabricLoader; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class HOLibrary implements ModInitializer { + public static final String MOD_ID = "holib"; + public static final String MOD_NAME = "HOLibrary"; + public static final Logger LOGGER = LoggerFactory.getLogger(MOD_NAME); + + @Override + public void onInitialize() { + if (FabricLoader.getInstance().isDevelopmentEnvironment()) { + HORegistryHandler.load(); + } + LOGGER.info(MOD_NAME + " has set up!"); + } +} diff --git a/src/main/java/ho/artisan/lib/common/item/FuelItem.java b/src/main/java/ho/artisan/lib/common/item/FuelItem.java new file mode 100644 index 0000000..d6352c3 --- /dev/null +++ b/src/main/java/ho/artisan/lib/common/item/FuelItem.java @@ -0,0 +1,19 @@ +package ho.artisan.lib.common.item; + +import net.fabricmc.fabric.api.registry.FuelRegistry; +import net.minecraft.item.Item; + + +/** + * 使用FabricAPI注册燃烧时间的燃料类物品 + */ +public class FuelItem extends Item { + public FuelItem(Settings settings, int burnTime) { + super(settings); + FuelRegistry.INSTANCE.add(this, burnTime); + } + + public int getBurnTime() { + return FuelRegistry.INSTANCE.get(this); + } +} diff --git a/src/main/java/ho/artisan/lib/example/HORegistryHandler.java b/src/main/java/ho/artisan/lib/example/HORegistryHandler.java new file mode 100644 index 0000000..c17213f --- /dev/null +++ b/src/main/java/ho/artisan/lib/example/HORegistryHandler.java @@ -0,0 +1,60 @@ +package ho.artisan.lib.example; + +import ho.artisan.lib.common.item.FuelItem; +import ho.artisan.lib.registry.registrar.BlockRegistrar; +import ho.artisan.lib.registry.registrar.ItemRegistrar; +import net.minecraft.block.AbstractBlock; +import net.minecraft.block.Block; +import net.minecraft.block.Blocks; +import net.minecraft.item.BlockItem; +import net.minecraft.item.Item; +import net.minecraft.item.SwordItem; +import net.minecraft.item.ToolMaterials; +import net.minecraft.util.Rarity; + +public class HORegistryHandler { + public static final Block IRON_COAL_BLOCK; + + public static final BlockItem IRON_COAL_BLOCK_ITEM; + + public static final FuelItem IRON_COAL; + public static final FuelItem GOLD_COAL; + public static final FuelItem DIAMOND_COAL; + + public static final Item COPPER_SWORD; + public static final Item TIN_SWORD; + public static final Item LEAD_SWORD; + + public static void load() {} + + static { + BlockRegistrar registrar = new BlockRegistrar("ho"); + + registrar.templateSettings(AbstractBlock.Settings.copy(Blocks.IRON_BLOCK)); + IRON_COAL_BLOCK = registrar.factory("iron_coal_block"); + } + + static { + ItemRegistrar registrar = new ItemRegistrar("ho"); + + IRON_COAL = registrar.register("iron_coal", new FuelItem(new Item.Settings().maxCount(16), 400)); + + IRON_COAL_BLOCK_ITEM = registrar.blockItem("iron_coal_block", () -> IRON_COAL_BLOCK); + + registrar.templateSettings(new Item.Settings().maxCount(16)); + GOLD_COAL = registrar.func("gold_coal", + settings -> new FuelItem(settings, 800)); + DIAMOND_COAL = registrar.func("diamond_coal", + settings -> new FuelItem(settings.rarity(Rarity.EPIC), 1600)); + registrar.clearTemplate(); + + registrar.templateSettings(new Item.Settings().rarity(Rarity.UNCOMMON)); + registrar.templateItem(settings -> new SwordItem(ToolMaterials.WOOD, 0, 0, settings)); + COPPER_SWORD = registrar.factory("copper_sword", settings -> settings.maxDamageIfAbsent(200)); + TIN_SWORD = registrar.factory("tin_sword", settings -> settings.maxDamageIfAbsent(150)); + LEAD_SWORD = registrar.factory("lead_sword", settings -> settings.maxDamageIfAbsent(100)); + registrar.clearTemplate(); + + registrar.factory("copper_dust", "tin_dust", "lead_dust"); + } +} diff --git a/src/main/java/ho/artisan/lib/gen/IdentifierGenerator.java b/src/main/java/ho/artisan/lib/gen/IdentifierGenerator.java new file mode 100644 index 0000000..76c5d94 --- /dev/null +++ b/src/main/java/ho/artisan/lib/gen/IdentifierGenerator.java @@ -0,0 +1,23 @@ +package ho.artisan.lib.gen; + + +import net.minecraft.util.Identifier; + +import java.util.Arrays; +import java.util.List; + +public class IdentifierGenerator { + private final String namespace; + + public IdentifierGenerator(String namespace) { + this.namespace = namespace; + } + + public Identifier gen(String path) { + return new Identifier(namespace, path); + } + + public List gen(String... paths) { + return Arrays.stream(paths).map(this::gen).toList(); + } +} diff --git a/src/main/java/ho/artisan/lib/gen/TagGenerator.java b/src/main/java/ho/artisan/lib/gen/TagGenerator.java new file mode 100644 index 0000000..05d03a2 --- /dev/null +++ b/src/main/java/ho/artisan/lib/gen/TagGenerator.java @@ -0,0 +1,24 @@ +package ho.artisan.lib.gen; + +import net.minecraft.tag.TagKey; +import net.minecraft.util.Identifier; +import net.minecraft.util.registry.Registry; + +import java.util.Arrays; +import java.util.List; + +public class TagGenerator { + private final Registry registry; + + public TagGenerator(Registry registry) { + this.registry = registry; + } + + public TagKey gen(Identifier id) { + return TagKey.of(registry.getKey(), id); + } + + public List> gen(Identifier... id) { + return Arrays.stream(id).map(this::gen).toList(); + } +} diff --git a/src/main/java/ho/artisan/lib/registry/Casket.java b/src/main/java/ho/artisan/lib/registry/Casket.java new file mode 100644 index 0000000..90f66ef --- /dev/null +++ b/src/main/java/ho/artisan/lib/registry/Casket.java @@ -0,0 +1,52 @@ +package ho.artisan.lib.registry; + +import net.minecraft.util.Identifier; +import org.jetbrains.annotations.NotNull; + +import java.util.Objects; +import java.util.function.Function; +import java.util.function.Supplier; + +public final class Casket implements Supplier { + private final T object; + private final Identifier identifier; + + public Casket(@NotNull T object, @NotNull Identifier id) { + this.object = object; + this.identifier = id; + } + + @Override + public T get() { + return object; + } + + public F func(Function function) { + return function.apply(object); + } + + public Identifier id() { + return identifier; + } + + public String sid() { + return identifier.getPath(); + } + + public String namespace() { + return identifier.getNamespace(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Casket casket = (Casket) o; + return Objects.equals(object, casket.object) && Objects.equals(identifier, casket.identifier); + } + + @Override + public int hashCode() { + return Objects.hash(object, identifier); + } +} diff --git a/src/main/java/ho/artisan/lib/registry/registrar/BlockEntityTypeRegistrar.java b/src/main/java/ho/artisan/lib/registry/registrar/BlockEntityTypeRegistrar.java new file mode 100644 index 0000000..46b27cf --- /dev/null +++ b/src/main/java/ho/artisan/lib/registry/registrar/BlockEntityTypeRegistrar.java @@ -0,0 +1,21 @@ +package ho.artisan.lib.registry.registrar; + +import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder; +import net.minecraft.block.Block; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.block.entity.BlockEntityType; +import net.minecraft.util.registry.Registry; + +public class BlockEntityTypeRegistrar extends VanillaRegistrar> { + public BlockEntityTypeRegistrar(String modid) { + super(modid, Registry.BLOCK_ENTITY_TYPE); + } + + public + BlockEntityType + register(String id, + FabricBlockEntityTypeBuilder.Factory factory, + Block... blocks) { + return register(id, FabricBlockEntityTypeBuilder.create(factory, blocks).build()); + } +} diff --git a/src/main/java/ho/artisan/lib/registry/registrar/BlockRegistrar.java b/src/main/java/ho/artisan/lib/registry/registrar/BlockRegistrar.java new file mode 100644 index 0000000..02a10e4 --- /dev/null +++ b/src/main/java/ho/artisan/lib/registry/registrar/BlockRegistrar.java @@ -0,0 +1,56 @@ +package ho.artisan.lib.registry.registrar; + +import net.minecraft.block.AbstractBlock; +import net.minecraft.block.Block; +import net.minecraft.block.Material; +import net.minecraft.util.registry.Registry; +import org.jetbrains.annotations.NotNull; + +import java.util.Arrays; +import java.util.List; +import java.util.function.Consumer; +import java.util.function.Function; + +public class BlockRegistrar extends VanillaRegistrar { + private AbstractBlock.Settings templateSettings = AbstractBlock.Settings.of(Material.AIR); + private Function templateBlock = Block::new; + + public BlockRegistrar(String modid) { + super(modid, Registry.BLOCK); + } + + public K func(String id, @NotNull Function function) { + return register(id, function.apply(templateSettings)); + } + + public Block factory(String id) { + return func(id, templateBlock); + } + + public Block factory(String id, Consumer consumer) { + return func(id, settings -> { + consumer.accept(settings); + return templateBlock.apply(settings); + }); + } + + public List factory(String... id) { + return Arrays.stream(id).map(this::factory).toList(); + } + + public List factory(Consumer consumer, String... id) { + return Arrays.stream(id).map(this::factory).toList(); + } + + @SuppressWarnings("UnusedReturnValue") + public AbstractBlock.Settings templateSettings(AbstractBlock.Settings settings) { + this.templateSettings = settings; + return this.templateSettings; + } + + @SuppressWarnings("UnusedReturnValue") + public Function templateBlock(Function template) { + this.templateBlock = template; + return this.templateBlock; + } +} diff --git a/src/main/java/ho/artisan/lib/registry/registrar/IRegistrar.java b/src/main/java/ho/artisan/lib/registry/registrar/IRegistrar.java new file mode 100644 index 0000000..54d6bf7 --- /dev/null +++ b/src/main/java/ho/artisan/lib/registry/registrar/IRegistrar.java @@ -0,0 +1,47 @@ +package ho.artisan.lib.registry.registrar; + +import ho.artisan.lib.registry.Casket; +import net.minecraft.util.Identifier; + + +/** + * 实现注册器的规范接口 + * + * @param 实现注册的类型 + */ +public interface IRegistrar { + + /** + * 注册条目的共同命名空间 + */ + String namespace(); + + /** + * 简化生成ID + */ + Identifier id(String id); + + /** + * 注册条目 + * + * @param id 注册条目的ID + * @param object 注册条目的实例 + */ + @SuppressWarnings("UnusedReturnValue") + K register(String id, K object); + + + /** + * 注册条目并返回封装 + * + * @param id 注册条目的ID + * @param object 注册条目的实例 + */ + @SuppressWarnings("UnusedReturnValue") + default Casket casket(String id, K object) { + return new Casket<>(register(id, object), id(id)); + } + + + +} \ No newline at end of file diff --git a/src/main/java/ho/artisan/lib/registry/registrar/ItemRegistrar.java b/src/main/java/ho/artisan/lib/registry/registrar/ItemRegistrar.java new file mode 100644 index 0000000..1c8b360 --- /dev/null +++ b/src/main/java/ho/artisan/lib/registry/registrar/ItemRegistrar.java @@ -0,0 +1,82 @@ +package ho.artisan.lib.registry.registrar; + +import net.minecraft.block.Block; +import net.minecraft.item.BlockItem; +import net.minecraft.item.Item; +import net.minecraft.util.registry.Registry; +import org.jetbrains.annotations.NotNull; + +import java.util.Arrays; +import java.util.List; +import java.util.function.Consumer; +import java.util.function.Function; +import java.util.function.Supplier; + +/** + * 实现物品注册的注册器 + */ +public class ItemRegistrar extends VanillaRegistrar { + private Item.Settings templateSettings = new Item.Settings(); + private Function templateItem = Item::new; + + public ItemRegistrar(String modid) { + super(modid, Registry.ITEM); + } + + /** + * 简化注册简单物品 + */ + public Item factory(String id) { + return func(id, templateItem); + } + + public Item factory(String id, Consumer consumer) { + return func(id, settings -> { + consumer.accept(settings); + return new Item(settings); + }); + } + + public List factory(String... id) { + return Arrays.stream(id).map(this::factory).toList(); + } + + public List factory(Consumer consumer, String... id) { + return Arrays.stream(id).map(this::factory).toList(); + } + + /** + * 简化注册方块物品 + */ + public BlockItem blockItem(String id, Supplier block) { + return func(id, settings -> new BlockItem(block.get(), settings)); + } + + /** + * 通过函数式接口来实现简化注册 + */ + public K func(String id, @NotNull Function function) { + return register(id, function.apply(templateSettings)); + } + + /** + * 切换 {@code func()} 所使用的 {@code Item.Setting} + * @see ho.artisan.lib.registry.registrar.ItemRegistrar#func(String, Function) + */ + @SuppressWarnings("UnusedReturnValue") + public Item.Settings templateSettings(Item.Settings settings) { + this.templateSettings = settings; + return this.templateSettings; + } + + @SuppressWarnings("UnusedReturnValue") + public Function templateItem(Function template) { + this.templateItem = template; + return this.templateItem; + } + + public void clearTemplate() { + templateSettings = new Item.Settings(); + templateItem = Item::new; + } +} diff --git a/src/main/java/ho/artisan/lib/registry/registrar/VanillaRegistrar.java b/src/main/java/ho/artisan/lib/registry/registrar/VanillaRegistrar.java new file mode 100644 index 0000000..63b0445 --- /dev/null +++ b/src/main/java/ho/artisan/lib/registry/registrar/VanillaRegistrar.java @@ -0,0 +1,48 @@ +package ho.artisan.lib.registry.registrar; + +import ho.artisan.lib.gen.IdentifierGenerator; +import net.minecraft.util.Identifier; +import net.minecraft.util.registry.Registry; +import org.jetbrains.annotations.NotNull; + +/** + * 实现原版注册的简易注册器 + * + * @param 实现注册的类型 + */ +public class VanillaRegistrar implements IRegistrar { + private final String modid; + private final Registry registry; + public final IdentifierGenerator idGenerator; + + /** + * @param modid 模组ID + * @param registry 原版注册表实例 + */ + public VanillaRegistrar(String modid, @NotNull Registry registry) { + this.modid = modid; + this.registry = registry; + this.idGenerator = new IdentifierGenerator(modid); + } + + @Override + public String namespace() { + return modid; + } + + /** + * 简单地使用原版注册方法来注册条目 + * + * @param id 注册条目的ID + * @param object 注册条目的实例 + */ + @Override + public K register(String id, K object) { + return Registry.register(registry, id(id), object); + } + + @Override + public Identifier id(String path) { + return idGenerator.gen(path); + } +} diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index de550f8..997202f 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -10,26 +10,18 @@ "contact": { "repo": "https://github.com/HO-Artisan/HO-Library", "issues": "https://github.com/HO-Artisan/HO-Library/issues", - "homepage": "https://modrinth.com/mod/ho-library", - "email": "783626185@qq.com" + "homepage": "https://modrinth.com/mod/ho-library" }, "license": "MIT", "icon": "assets/holib/icon.png", "environment": "*", "entrypoints": { - "client": [ - "ho.artisan.holib.HOLibClient" - ], "main": [ - "ho.artisan.holib.HOLibMod" - ], - "fabric-datagen": [ - "ho.artisan.holib.HOLibDataGen" + "ho.artisan.lib.HOLibrary" ] }, "depends": { - "fabric": "*", - "minecraft": ">=1.19.3" + "fabric": "*" }, "custom": { "modmenu": { diff --git a/src/main/resources/holib.mixins.json b/src/main/resources/holib.mixin.json similarity index 66% rename from src/main/resources/holib.mixins.json rename to src/main/resources/holib.mixin.json index 4066e4f..fcb1079 100644 --- a/src/main/resources/holib.mixins.json +++ b/src/main/resources/holib.mixin.json @@ -1,9 +1,11 @@ { "required": true, "minVersion": "0.8", - "package": "ho.artisan.holib.mixin", + "package": "ho.artisan.lib.mixin", "compatibilityLevel": "JAVA_17", - "mixins": [], + "mixins": [ + "ItemSettingMixin" + ], "client": [], "server": [], "injectors": {