diff --git a/.github/workflows/auto-cherry-pick.yml b/.github/workflows/auto-cherry-pick.yml new file mode 100644 index 000000000..894017d61 --- /dev/null +++ b/.github/workflows/auto-cherry-pick.yml @@ -0,0 +1,44 @@ +name: Auto Cherry-Pick +on: + push: + branches: + - "1.*" # 1.21.5, 1.21.4...のブランチでpushされたとき + pull_request: + types: + - closed # PRがmergeされたとき +jobs: + cherry-pick: + if: | + (github.event_name == 'push' || + (github.event_name == 'pull_request' && github.event.pull_request.merged == true)) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Check + id: check + run: | + COMMIT_MSG=$(git log -1 --pretty=%B) + if echo "$COMMIT_MSG" | grep -q '^\[cp\]'; then + echo "pickable=true" >> $GITHUB_ENV + fi + - name: Setup Git + if: env.pickable == 'true' + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + - name: Chmod cherry-pick.sh + if: env.pickable == 'true' + run: | + if [ ! -f .github/workflows/cherry-pick.sh ]; then + echo "cherry-pick.sh not found" + exit 1 + fi + git update-index --assume-unchanged .github/workflows/cherry-pick.sh + chmod +x .github/workflows/cherry-pick.sh + - name: Run cherry-pick.sh + if: env.pickable == 'true' + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: .github/workflows/cherry-pick.sh \ No newline at end of file diff --git a/.github/workflows/cherry-pick.sh b/.github/workflows/cherry-pick.sh new file mode 100644 index 000000000..064ae6243 --- /dev/null +++ b/.github/workflows/cherry-pick.sh @@ -0,0 +1,52 @@ +#!/bin/bash +set -e + +git fetch --all +CURRENT_BRANCH="${GITHUB_REF##*/}" +SHA=$(git log -1 --pretty=format:"%H") +MSG=$(git log -1 --pretty=%B) + +echo "Current: $CURRENT_BRANCH" +echo "SHA: $SHA" + +BRANCHES=$(git for-each-ref --format='%(refname:short)' refs/remotes/origin | grep -E '^origin/1\.' | sed 's|origin/||' | sort -Vr) + +TARGETS=() +FOUND=0 +while read -r b; do + if [ "$FOUND" = "1" ]; then + TARGETS+=("$b") + fi + if [ "$b" = "$CURRENT_BRANCH" ]; then + FOUND=1 + fi +done <<< "$BRANCHES" + +for TARGET_BRANCH in "${TARGETS[@]}"; do + if [ -z "$TARGET_BRANCH" ]; then + continue + fi + + echo "Trying to cherry-pick to $TARGET_BRANCH..." + + git reset --hard + git switch -c "$TARGET_BRANCH" "origin/$TARGET_BRANCH" + + echo "Cherry-picking $SHA from $CURRENT_BRANCH to $TARGET_BRANCH..." + if git cherry-pick "$SHA"; then + git push origin "$TARGET_BRANCH" + echo "Cherry-pick successful. Pushed to $TARGET_BRANCH." + continue + fi + + echo "Cherry-pick failed. Attempting to resolve conflicts..." + + git cherry-pick --abort + gh auth setup-git + gh pr create \ + --base "$TARGET_BRANCH" \ + --head "$CURRENT_BRANCH" \ + --title "Manual Cherry-pick needed: $SHA" \ + --body "Cherry-pick of $SHA from $CURRENT_BRANCH to $TARGET_BRANCH failed due to conflicts." + exit 0 +done \ No newline at end of file diff --git a/.gitignore b/.gitignore index 3c37caf38..a6596c591 100644 --- a/.gitignore +++ b/.gitignore @@ -30,6 +30,7 @@ atlassian-ide-plugin.xml *.zip *.tar.gz *.rar +*.php # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* @@ -114,5 +115,7 @@ gradle-app.setting # Common working directory run/ +php/ + # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) -!gradle-wrapper.jar +!gradle-wrapper.jar \ No newline at end of file diff --git a/LICENSE b/LICENSE index 1263235d6..21068a6f0 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2022 Pitan +Copyright (c) 2022-2025 Pitan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md new file mode 100644 index 000000000..98a622d0e --- /dev/null +++ b/README.md @@ -0,0 +1,128 @@ +# MCPitanLib +## License +- MIT License + +## 日本語 +MCPitanLibはライブラリです。 1つのjarで複数のMCバージョンを対応させるためのものです。
+開発中であるため、予告なく仕様が変更されることがあったり、不具合があるかもしれません。
+私専用につくっているため、他の方が使うことをあまり想定していません。
+ +クロスバージョンかつクロスプラットフォームを目指しています。 + +### 対応状況 +- アイテムの追加 +- ブロックの追加 +- エンティティの追加 +- ブロックエンティティの追加 +- クリエイティブタブの追加 +- GUIの追加 +- サウンドの追加 + +となります。 + +### 前提MOD +- MODローダー + - [FabricMC](https://fabricmc.net/) + - [Minecraft Forge](https://files.minecraftforge.net/) + - [NeoForge](https://neoforged.net/) +- Architectury API ([CurseForge](https://www.curseforge.com/minecraft/mc-mods/architectury-api) | [Modrinth](https://modrinth.com/mod/architectury-api)) + +### ダウンロード +- [CurseForge](https://www.curseforge.com/minecraft/mc-mods/mcpitanlibarch) +- [Modrinth](https://modrinth.com/mod/mcpitanlibarch) + +### 使い方 +`build.gradle`に以下のように記述してください。 +```groovy +repositories { + maven { + url = "https://maven.pitan76.net/" + } +} + +dependencies { + // FabricMC + modImplementation "net.pitan76:mcpitanlib-fabric:${rootProject.mcpitanlib_version}" + + // Minecraft Forge + //modImplementation "net.pitan76:mcpitanlib-forge:${rootProject.mcpitanlib_version}" + + // NeoForge + //modImplementation "net.pitan76:mcpitanlib-neoforge:${rootProject.mcpitanlib_version}" +} +``` + +`gradle.properties`に以下のように記述してください。 +```properties +# Example: mcpitanlib_version=+1.18.2:3.3.3 +mcpitanlib_version=+x.x.x:x.x.x +``` + +バージョンは[GitHub Packages](https://github.com/PTOM76/maven/packages/?q=net.pitan76.mcpitanlib) (3.3.3以降) or [maven.pitan76.net](https://maven.pitan76.net/net/pitan76/) (3.3.3以前)で確認してください。 + +MCPitanLibを用いたMOD開発は「common/src/main/java/net/pitan76/mcpitanlib/test/ExampleMod.java」を参考にしてください。 + +## English +MCPitanLib is a library. It is for supporting multiple MC versions with one jar.
+It is under development, so the specification may change without notice, and there may be bugs.
+I am creating it for my own use, so I don't expect others to use it much.
+ +It aims to be cross-version and cross-platform. + +### Supported features +- Adding items +- Adding blocks +- Adding entities +- Adding block entities +- Adding creative tabs +- Adding GUIs +- Adding sounds + +### Required MOD +- MOD Loader + - [FabricMC](https://fabricmc.net/) + - [Minecraft Forge](https://files.minecraftforge.net/) + - [NeoForge](https://neoforged.net/) +- [Architectury API](https://www.curseforge.com/minecraft/mc-mods/architectury-api) ([CurseForge](https://www.curseforge.com/minecraft/mc-mods/architectury-api) | [Modrinth](https://modrinth.com/mod/architectury-api)) + +### Download +- [CurseForge](https://www.curseforge.com/minecraft/mc-mods/mcpitanlibarch) +- [Modrinth](https://modrinth.com/mod/mcpitanlibarch) + +### How to use +Write as follows in `build.gradle`. +```groovy +repositories { + maven { + url = "https://maven.pitan76.net/" + } +} + +dependencies { + // FabricMC + modImplementation "net.pitan76:mcpitanlib-fabric${rootProject.mcpitanlib_version}" + + // Minecraft Forge + //modImplementation "net.pitan76:mcpitanlib-forge${rootProject.mcpitanlib_version}" + + // NeoForge + //modImplementation "net.pitan76:mcpitanlib-neoforge${rootProject.mcpitanlib_version}" +} +``` + +Write as follows in `gradle.properties`. +```properties +# Example: mcpitanlib_version=+1.18.2:3.2.4 +mcpitanlib_version=+x.x.x:x.x.x +``` + +Please check the version at [GitHub Packages](https://github.com/PTOM76/maven/packages/?q=net.pitan76.mcpitanlib) (for versions 3.3.3 and later) or [maven.pitan76.net](https://maven.pitan76.net/net/pitan76/) (for versions before 3.3.3). + +For MOD development using MCPitanLib, refer to "common/src/main/java/net/pitan76/mcpitanlib/test/ExampleMod.java". + +## Note +### Auto Cherry-Pick (GitHub Actions) +コミットメッセージに [cp] を含むと、Actionsで自動的にCherry-Pickを行います。
+そのコミットしたブランチからそれより下位のバージョンのブランチにCherry-Pickし、コンフリを起こした場合はそこで停止し、PRを作成します。
+今のところ、そのPRは使えないので閉じる必要があります。(今後はissueにする予定です。) + diff --git a/build.gradle b/build.gradle index fabeb0562..a6fbbb486 100644 --- a/build.gradle +++ b/build.gradle @@ -1,25 +1,115 @@ plugins { id "architectury-plugin" version "3.4-SNAPSHOT" - id "dev.architectury.loom" version "0.11.0-SNAPSHOT" apply false + id "dev.architectury.loom" version "1.7-SNAPSHOT" apply false + id 'com.matthewprenger.cursegradle' version '1.+' + id "com.modrinth.minotaur" version "2.+" } architectury { minecraft = rootProject.minecraft_version } +def loadProperties(filename) { + def props = new Properties() + file(filename).withInputStream { + props.load(it) + } + return props +} + +ext.info = loadProperties("$rootDir/info.properties") + subprojects { apply plugin: "dev.architectury.loom" + apply plugin: "com.modrinth.minotaur" + apply plugin: "com.matthewprenger.cursegradle" loom { silentMojangMappingsLicense() } + repositories { + maven { url "https://maven.pitan76.net/" } + maven { url "https://maven.neoforged.net/releases/" } + maven { url "https://maven.shedaniel.me/" } + } + dependencies { minecraft "com.mojang:minecraft:${rootProject.minecraft_version}" // The following line declares the mojmap mappings, you may use other mappings as well // mappings loom.officialMojangMappings() // The following line declares the yarn mappings you may select this one as well. - mappings "net.fabricmc:yarn:${rootProject.yarn_mappings}:v2" + //mappings "net.fabricmc:yarn:${rootProject.yarn_mappings}:v2" + mappings loom.layered() { + it.mappings("net.fabricmc:yarn:${rootProject.yarn_mappings}:v2") + it.mappings file("../mappings/121-1fix.tiny") + } + + // https://mvnrepository.com/artifact/org.yaml/snakeyaml + implementation 'org.yaml:snakeyaml:2.0' + } + + if (name in "fabric,neoforge".split(",")) { + var modLoader = name + + if (System.getenv("CURSEFORGE_TOKEN") != null) { + curseforge { + apiKey = System.getenv("CURSEFORGE_TOKEN") + project { + id = '682213' + changelog = info.changelog + releaseType = modLoader == "fabric" ? 'release' : 'beta' + if (modLoader == "fabric") { + addGameVersion "Fabric" + } + if (modLoader == "forge") { + addGameVersion "Forge" + } + if (modLoader == "neoforge") { + addGameVersion "NeoForge" + } + addGameVersion '1.21' + addGameVersion '1.21.1' + + relations { + if (modLoader == "fabric") { + requiredDependency "fabric-api" + } + + requiredDependency 'architectury-api' + embeddedLibrary 'cloth-config' + embeddedLibrary 'compatdatapacks' + } + + mainArtifact(tasks.remapJar) + } + options { + forgeGradleIntegration = false + } + } + + } + + if (System.getenv("MODRINTH_TOKEN") != null) { + modrinth { + token = System.getenv("MODRINTH_TOKEN") + projectId = 'mcpitanlibarch' + versionNumber = info.mod_version + "-" + modLoader + gameVersions = ['1.21', '1.21.1'] + versionType = 'release' + uploadFile = tasks.remapJar + changelog = info.changelog + loaders = [modLoader] + dependencies { + if (modLoader == "fabric") { + required.project "fabric-api" // Fabric API + } + required.project "architectury-api" + embedded.project "cloth-config" + embedded.project "compatdatapacks" + } + } + } } } @@ -28,9 +118,9 @@ allprojects { apply plugin: "architectury-plugin" apply plugin: "maven-publish" - archivesBaseName = rootProject.archives_base_name - version = rootProject.mod_version - group = rootProject.maven_group + archivesBaseName = info.archives_base_name + version = info.mod_version + "-" + rootProject.minecraft_version + group = info.maven_group repositories { // Add repositories to retrieve artifacts from in here. @@ -40,9 +130,11 @@ allprojects { // for more information about repositories. } - tasks.withType(JavaCompile) { + tasks.withType(JavaCompile).configureEach { options.encoding = "UTF-8" - options.release = 17 + options.release = 21 + sourceCompatibility = JavaVersion.VERSION_21 + targetCompatibility = JavaVersion.VERSION_21 } java { diff --git a/common/build.gradle b/common/build.gradle index 22df1ed86..b6e594192 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -7,19 +7,31 @@ dependencies { } architectury { - common() + common("fabric", "neoforge") +} + +loom { + accessWidenerPath = file("src/main/resources/mcpitanlib.accesswidener") } publishing { publications { mavenCommon(MavenPublication) { - artifactId = rootProject.archives_base_name + artifactId = info.archives_base_name + "-" + project.name + "-" + rootProject.minecraft_version + version = info.mod_version from components.java } } // See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing. repositories { - // Add repositories to publish to here. + maven { + name = "GitHubPackages" + url = uri("https://maven.pkg.github.com/PTOM76/maven") + credentials { + username = project.findProperty("gpr.user") ?: System.getenv("GITHUB_ACTOR") + password = project.findProperty("gpr.key") ?: System.getenv("GITHUB_TOKEN") + } + } } } \ No newline at end of file diff --git a/common/src/main/java/ml/pkom/mcpitanlibarch/MCPitanLibarch.java b/common/src/main/java/ml/pkom/mcpitanlibarch/MCPitanLibarch.java deleted file mode 100644 index 4ba33fd9f..000000000 --- a/common/src/main/java/ml/pkom/mcpitanlibarch/MCPitanLibarch.java +++ /dev/null @@ -1,9 +0,0 @@ -package ml.pkom.mcpitanlibarch; - -public class MCPitanLibarch { - public static final String MOD_ID = "mcpitanlibarch"; - - public static void init() { - - } -} \ No newline at end of file diff --git a/common/src/main/java/ml/pkom/mcpitanlibarch/api/entity/Player.java b/common/src/main/java/ml/pkom/mcpitanlibarch/api/entity/Player.java deleted file mode 100644 index 6f1a375f3..000000000 --- a/common/src/main/java/ml/pkom/mcpitanlibarch/api/entity/Player.java +++ /dev/null @@ -1,128 +0,0 @@ -package ml.pkom.mcpitanlibarch.api.entity; - -import net.minecraft.block.BlockState; -import net.minecraft.entity.player.PlayerAbilities; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.screen.NamedScreenHandlerFactory; -import net.minecraft.util.collection.DefaultedList; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; - -import java.util.OptionalInt; -import java.util.UUID; - -/* -PlayerEntity helper - */ -public class Player { - private final PlayerEntity entity; - - public PlayerEntity getEntity() { - return entity; - } - - public PlayerEntity getPlayerEntity() { - return getEntity(); - } - - public Player(PlayerEntity playerEntity) { - this.entity = playerEntity; - } - - /** - * Get player inventory - * @return PlayerInventory - */ - public PlayerInventory getInv() { - return getEntity().getInventory(); - } - - /** - * Alias of getInv() - * @return PlayerInventory - */ - public PlayerInventory getInventory() { - return getInv(); - } - - /** - * Get armor's item stack list - * @return DefaultedList - */ - public DefaultedList getArmor() { - return getInv().armor; - } - - /** - * Get main's item stack list - * @return DefaultedList - */ - public DefaultedList getMain() { - return getInv().main; - } - - /** - * Get off hand's item stack list - * @return DefaultedList - */ - public DefaultedList getOffHand() { - return getInv().offHand; - } - - /** - * Get select slot integer - * @return int - */ - public int getSelectSlot() { - return getInv().selectedSlot; - } - - /** - * Get player inventory size - * @return player inventory size - */ - public int getInvSize() { - return getInv().size(); - } - - public OptionalInt openGuiScreen(NamedScreenHandlerFactory factory) { - return getEntity().openHandledScreen(factory); - } - - public OptionalInt openGuiScreen(World world, BlockState state, BlockPos pos) { - return openGuiScreen(state.createScreenHandlerFactory(world, pos)); - } - - public void insertStack(ItemStack stack) { - getInv().insertStack(stack); - } - - public void insertStack(int slot, ItemStack stack) { - getInv().insertStack(slot, stack); - } - - public void giveStack(ItemStack stack) { - getEntity().giveItemStack(stack); - } - - public String getName() { - return getEntity().getName().getString(); - } - - public UUID getUUID() { - return getEntity().getUuid(); - } - - public PlayerAbilities getAbilities() { - return getEntity().getAbilities(); - } - - /** - * Returns whether this player is in creative mode. - */ - public boolean isCreative() { - return getAbilities().creativeMode; - } -} \ No newline at end of file diff --git a/common/src/main/java/ml/pkom/mcpitanlibarch/api/event/BaseEvent.java b/common/src/main/java/ml/pkom/mcpitanlibarch/api/event/BaseEvent.java deleted file mode 100644 index 7dc5d4429..000000000 --- a/common/src/main/java/ml/pkom/mcpitanlibarch/api/event/BaseEvent.java +++ /dev/null @@ -1,4 +0,0 @@ -package ml.pkom.mcpitanlibarch.api.event; - -public class BaseEvent { -} \ No newline at end of file diff --git a/common/src/main/java/ml/pkom/mcpitanlibarch/api/registry/ArchRegistry.java b/common/src/main/java/ml/pkom/mcpitanlibarch/api/registry/ArchRegistry.java deleted file mode 100644 index 04fbbc423..000000000 --- a/common/src/main/java/ml/pkom/mcpitanlibarch/api/registry/ArchRegistry.java +++ /dev/null @@ -1,40 +0,0 @@ -package ml.pkom.mcpitanlibarch.api.registry; - -import com.google.common.base.Suppliers; -import dev.architectury.registry.registries.Registrar; -import dev.architectury.registry.registries.Registries; -import dev.architectury.registry.registries.RegistrySupplier; -import net.minecraft.block.Block; -import net.minecraft.item.Item; -import net.minecraft.util.Identifier; -import net.minecraft.util.registry.Registry; - -import java.util.function.Supplier; - -public class ArchRegistry { - - public Supplier REGISTRIES; - - public Registrar ITEMS; - public Registrar BLOCKS; - - public ArchRegistry(String MOD_ID) { - REGISTRIES = Suppliers.memoize(() -> Registries.get(MOD_ID)); - - ITEMS = REGISTRIES.get().get(Registry.ITEM_KEY); - BLOCKS = REGISTRIES.get().get(Registry.BLOCK_KEY); - - } - - public static ArchRegistry createRegistry(String MOD_ID) { - return new ArchRegistry(MOD_ID); - } - - public RegistrySupplier registerItem(Identifier id, Supplier supplier) { - return ITEMS.register(id, supplier); - } - - public RegistrySupplier registerBlock(Identifier id, Supplier supplier) { - return BLOCKS.register(id, supplier); - } -} diff --git a/common/src/main/java/ml/pkom/mcpitanlibarch/api/util/BlockUtil.java b/common/src/main/java/ml/pkom/mcpitanlibarch/api/util/BlockUtil.java deleted file mode 100644 index 85b43c07c..000000000 --- a/common/src/main/java/ml/pkom/mcpitanlibarch/api/util/BlockUtil.java +++ /dev/null @@ -1,25 +0,0 @@ -package ml.pkom.mcpitanlibarch.api.util; - -import ml.pkom.mcpitanlibarch.api.tag.MineableToolTags; -import net.minecraft.block.AbstractBlock; -import net.minecraft.block.Block; -import net.minecraft.util.Identifier; -import net.minecraft.util.registry.Registry; - -public class BlockUtil { - public static Block block(Identifier id) { - return Registry.BLOCK.get(id); - } - - /** - * ~1.16? - * @param settings - * @param toolTags - * @param level - * @return - */ - public static AbstractBlock.Settings breakByTool(AbstractBlock.Settings settings, MineableToolTags toolTags, int level) { - - return settings; - } -} diff --git a/common/src/main/java/ml/pkom/mcpitanlibarch/api/util/ItemUtil.java b/common/src/main/java/ml/pkom/mcpitanlibarch/api/util/ItemUtil.java deleted file mode 100644 index 44bea4a44..000000000 --- a/common/src/main/java/ml/pkom/mcpitanlibarch/api/util/ItemUtil.java +++ /dev/null @@ -1,11 +0,0 @@ -package ml.pkom.mcpitanlibarch.api.util; - -import net.minecraft.item.Item; -import net.minecraft.util.Identifier; -import net.minecraft.util.registry.Registry; - -public class ItemUtil { - public static Item item(Identifier id) { - return Registry.ITEM.get(id); - } -} diff --git a/common/src/main/java/ml/pkom/mcpitanlibarch/api/util/TextUtil.java b/common/src/main/java/ml/pkom/mcpitanlibarch/api/util/TextUtil.java deleted file mode 100644 index 4abbc5d7f..000000000 --- a/common/src/main/java/ml/pkom/mcpitanlibarch/api/util/TextUtil.java +++ /dev/null @@ -1,34 +0,0 @@ -package ml.pkom.mcpitanlibarch.api.util; - -import net.minecraft.text.*; - -public class TextUtil { - public static MutableText literal(String string) { - //return Text.literal(string); - return new LiteralText(string); - } - - public static MutableText translatable(String key) { - //return Text.translatable(key); - return new TranslatableText(key); - } - - public static MutableText translatable(String key, Object... args) { - //return Text.translatable(key, args); - return new TranslatableText(key, args); - } - - public static MutableText empty() { - //return Text.empty(); - return literal(""); - } - - public static MutableText keybind(String string) { - //return Text.keybind(string); - return new KeybindText(string); - } - - public static String txt2str(Text text) { - return text.getString(); - } -} \ No newline at end of file diff --git a/common/src/main/java/net/pitan76/easyapi/FileControl.java b/common/src/main/java/net/pitan76/easyapi/FileControl.java new file mode 100644 index 000000000..673c29ab2 --- /dev/null +++ b/common/src/main/java/net/pitan76/easyapi/FileControl.java @@ -0,0 +1,173 @@ +package net.pitan76.easyapi; + +import java.io.*; +import java.nio.channels.FileChannel; + +public class FileControl { + + public static boolean fileWriteContents(String pathName, String contents){ return fileWriteContents(new File(pathName), contents); } + + public static String fileReadContents(String pathName) { return fileReadContents(new File(pathName)); } + + public static boolean fileCopy(String inPathName, String outPathName) { return fileCopy(new File(inPathName), new File(outPathName)); } + + public static boolean fileExists(String pathName) { return fileExists(new File(pathName)); } + + public static long getFileTime(String pathName) { return getFileTime(new File(pathName)); } + + public static boolean setFileTime(String pathName, long time) { return setFileTime(new File(pathName), time); } + + public static boolean fileRename(String pathName, String renamedPathName) { return fileRename(new File(pathName), new File(renamedPathName)); } + + public static String basename(String pathName) { return basename(new File(pathName)); } + + public static String dirname(String pathName) { return dirname(new File(pathName)); } + + public static String dirname(String pathName, int levels) { return dirname(new File(pathName), levels); } + + /** + * ファイルにデータを書き込みます。 + * 失敗した場合falseを返します。 + * + * @param file ファイル + * @param contents データ + */ + public static boolean fileWriteContents(File file, String contents) { + try { + PrintWriter writer = new PrintWriter( + new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8"))); + writer.println(contents); + writer.close(); + return true; + } catch (IOException e) { + e.printStackTrace(); + return false; + } + } + + /** + * ファイルからデータを読み込みます。 + * 失敗した場合nullを返します。 + * + * @param file ファイル + * @return ファイルのデータ or null + */ + public static String fileReadContents(File file) { + try { + BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8")); + String line = ""; + String contents = ""; + while ((line = reader.readLine()) != null) { + contents += line + "\n"; + } + reader.close(); + return contents; + } catch (IOException e) { + e.printStackTrace(); + return null; + } + } + + /** + * ファイルからデータを読み込みます。 + * 失敗した場合falseを返します。 + * + * @param inFile コピー元ファイル + * @param outFile コピー先ファイル + */ + public static boolean fileCopy(File inFile, File outFile) { + try { + FileChannel inCh, outCh = null; + FileInputStream inStream = new FileInputStream(inFile); + FileOutputStream outStream = new FileOutputStream(outFile); + inCh = inStream.getChannel(); + outCh = outStream.getChannel(); + outCh.transferFrom(inCh, 0, inCh.size()); + inCh.close(); + outCh.close(); + inStream.close(); + outStream.close(); + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + /** + * File.exists()のエイリアス関数です。 + * + * @param file 確認するファイル + */ + public static boolean fileExists(File file) { + return file.exists(); + } + + /** + * File.lastModified()のエイリアス関数です。 + * + * @param file 更新日時を取得するファイル + * @return ファイルの更新日時 + */ + public static long getFileTime(File file) { + return file.lastModified(); + } + + + /** + * File.setLastModified()のエイリアス関数です。 + * + * @param file 日時変更されるファイル + * @param time 変更後の更新日時 + */ + public static boolean setFileTime(File file, long time) { + return file.setLastModified(time); + } + + /** + * File.renameTo()のエイリアス関数です。 + * + * @param file 名前変更されるファイル + * @param renamedFile 名前変更後のファイル + */ + public static boolean fileRename(File file, File renamedFile) { + return file.renameTo(renamedFile); + } + + /** + * StringからFileへ変換します。 + * + * @param pathName ファイルのパス + * @return File + */ + public static File stringToFile(String pathName) { + return new File(pathName); + } + + public static String basename(File file) { + return file.getName(); + } + + public static String dirname(File file) { + return file.getParent(); + } + + public static String dirname(File file, int levels) { + for (int i = 0; i < levels; i++) { + file = dirfile(file); + } + return file.toString(); + } + + public static File dirfile(File file) { + return file.getParentFile(); + } + + public static File dirfile(File file, int count) { + for (int i = 0; i > count; i++) { + file = dirfile(file); + } + return file; + } + +} diff --git a/common/src/main/java/net/pitan76/easyapi/config/Config.java b/common/src/main/java/net/pitan76/easyapi/config/Config.java new file mode 100644 index 000000000..cdbabbcc1 --- /dev/null +++ b/common/src/main/java/net/pitan76/easyapi/config/Config.java @@ -0,0 +1,456 @@ +package net.pitan76.easyapi.config; + +import java.io.File; +import java.util.LinkedHashMap; +import java.util.Map; + +public class Config implements IConfig { + public Map configMap = new LinkedHashMap<>(); + + /** + * 任意ファイルを読み込み、Mapへ変換 + * + * @param file ファイル + */ + public Config(File file) { + load(file); + } + + /** + * 任意ファイルを読み込み、Mapへ変換 + * + * @param file ファイル名 + */ + public Config(String file) { + this(new File(file)); + } + + public Config() {}; + + /** + * Configの変換 + * + * @param config Config + */ + public Config(Config config) { + configMap = config.configMap; + }; + + public boolean has(String key) { + if (configMap == null) + return false; + + return configMap.containsKey(key); + } + + /** + * マップのキーから値を取得 + * "."でパスを区切る + * + * @param key キー + * @return 取得した値 + */ + @SuppressWarnings("unchecked") + public Object get(String key) { + try { + key = key.replace("\\.", "$\$"); + String[] keyList = key.split("\\."); + if (keyList.length == 1) { + key = key.replace("$\$", "."); + return configMap.get(key); + } + int i = 0; + Map inMap = new LinkedHashMap<>(); + for (String k : keyList) { + i++; + k = k.replace("$\$", "."); + if (keyList.length == i) { + return inMap.get(k); + } + if (i == 1) { + inMap = (Map) configMap.get(k); + continue; + } + inMap = (Map) inMap.get(k); + } + return null; + } catch (Exception e) { + return null; + } + + } + + /** + * マップのキーから値(文字列)を取得 + * "."でパスを区切る + * + * @param key キー + * @return 取得した値 + */ + public String getString(String key) { + return (String) get(key); + } + + /** + * マップのキーから値(整数)を取得 + * "."でパスを区切る + * + * @param key キー + * @return 取得した値 + */ + public int getInt(String key) { + Object obj = get(key); + if (obj instanceof Double) { + return ((Double)obj).intValue(); + } + if (obj instanceof Short) { + return ((Short)obj).intValue(); + } + if (obj instanceof Long) { + return ((Long)obj).intValue(); + } + return (Integer) obj; + } + + /** + * マップのキーから値(数値)を取得 + * "."でパスを区切る + * + * @param key キー + * @return 取得した値 + */ + public double getDouble(String key) { + return (Double) get(key); + } + + /** + * マップのキーから値(真偽値)を取得 + * "."でパスを区切る + * + * @param key キー + * @return 取得した値 + */ + public boolean getBoolean(String key) { + try { + return (Boolean) get(key); + } catch (Exception e) { + return false; + } + } + + /** + * マップのキーから値を取得、存在しない場合はデフォルト値を返す + * "."でパスを区切る + * + * @param key キー + * @param defaultValue デフォルト値 + * @return 取得した値 + */ + public Object getOrDefault(String key, Object defaultValue) { + if (has(key)) { + return get(key); + } + return defaultValue; + } + + /** + * マップのキーから値(文字列)を取得、存在しない場合はデフォルト値を返す + * "."でパスを区切る + * + * @param key キー + * @param defaultValue デフォルト値 + * @return 取得した値 + */ + public String getStringOrDefault(String key, String defaultValue) { + if (has(key)) { + return getString(key); + } + return defaultValue; + } + + /** + * マップのキーから値(整数)を取得、存在しない場合はデフォルト値を返す + * "."でパスを区切る + * + * @param key キー + * @param defaultValue デフォルト値 + * @return 取得した値 + */ + public int getIntOrDefault(String key, int defaultValue) { + if (has(key)) { + return getInt(key); + } + return defaultValue; + } + + /** + * マップのキーから値(数値)を取得、存在しない場合はデフォルト値を返す + * "."でパスを区切る + * + * @param key キー + * @param defaultValue デフォルト値 + * @return 取得した値 + */ + public double getDoubleOrDefault(String key, double defaultValue) { + if (has(key)) { + return getDouble(key); + } + return defaultValue; + } + /** + * マップのキーから値(真偽値)を取得、存在しない場合はデフォルト値を返す + * "."でパスを区切る + * + * @param key キー + * @param defaultValue デフォルト値 + * @return 取得した値 + */ + public boolean getBooleanOrDefault(String key, boolean defaultValue) { + if (has(key)) { + return getBoolean(key); + } + return defaultValue; + } + + /** + * マップのキーから値を取得、存在しない場合はデフォルト値を保存して返す + * "."でパスを区切る + * + * @param key キー + * @param defaultValue デフォルト値 + * @return 取得した値 + */ + public Object getOrCreate(String key, Object defaultValue) { + if (has(key)) return get(key); + + set(key, defaultValue); + return defaultValue; + } + + /** + * マップのキーから値(文字列)を取得、存在しない場合はデフォルト値を保存して返す + * "."でパスを区切る + * + * @param key キー + * @param defaultValue デフォルト値 + * @return 取得した値 + */ + public String getStringOrCreate(String key, String defaultValue) { + if (has(key)) return getString(key); + + setString(key, defaultValue); + return defaultValue; + } + + /** + * マップのキーから値(整数)を取得、存在しない場合はデフォルト値を保存して返す + * "."でパスを区切る + * + * @param key キー + * @param defaultValue デフォルト値 + * @return 取得した値 + */ + public int getIntOrCreate(String key, int defaultValue) { + if (has(key)) return getInt(key); + + setInt(key, defaultValue); + return defaultValue; + } + + /** + * マップのキーから値(数値)を取得、存在しない場合はデフォルト値を保存して返す + * "."でパスを区切る + * + * @param key キー + * @param defaultValue デフォルト値 + * @return 取得した値 + */ + public double getDoubleOrCreate(String key, double defaultValue) { + if (has(key)) return getDouble(key); + + setDouble(key, defaultValue); + return defaultValue; + } + + /** + * マップのキーから値(真偽値)を取得、存在しない場合はデフォルト値を保存して返す + * "."でパスを区切る + * + * @param key キー + * @param defaultValue デフォルト値 + * @return 取得した値 + */ + public boolean getBooleanOrCreate(String key, boolean defaultValue) { + if (has(key)) return getBoolean(key); + + setBoolean(key, defaultValue); + return defaultValue; + } + + /** + * マップのキーに値をセット + * "."でパスを区切る + * 失敗するとfalseを返す + * + * @param key キー + * @param value 値 + * @return 真偽値 + */ + @SuppressWarnings("unchecked") + public boolean set(String key, Object value) { + try { + key = key.replace("\\.", "$\$"); + String[] keyList = key.split("\\."); + if (keyList.length == 1) { + key = key.replace("$\$", "."); + configMap.put(key, value); + return true; + } + int i = 0; + Map inMap = new LinkedHashMap<>(); + for (String k : keyList) { + i++; + k = k.replace("$\$", "."); + if (keyList.length == i) { + inMap.put(k, value); + continue; + } + Map beforeInMap = inMap; + if (configMap.containsKey(k) && i == 1) { + inMap = (LinkedHashMap) configMap.get(k); + }else if (beforeInMap.containsKey(k)){ + inMap = (LinkedHashMap) beforeInMap.get(k); + }else { + inMap = new LinkedHashMap(); + } + if (i == 1) { + configMap.put(k, inMap); + continue; + } + beforeInMap.put(k, inMap); + } + return true; + } catch (Exception e) { + return false; + } + } + + /** + * マップのキーに値(文字列)をセット + * "."でパスを区切る + * 失敗するとfalseを返す + * + * @param key キー + * @param value 値 + * @return 真偽値 + */ + public boolean setString(String key, String value) { + return set(key, value); + } + + /** + * マップのキーに値(整数)をセット + * "."でパスを区切る + * 失敗するとfalseを返す + * + * @param key キー + * @param value 値 + * @return 真偽値 + */ + public boolean setInt(String key, int value) { + return set(key, value); + } + + /** + * マップのキーに値(数値)をセット + * "."でパスを区切る + * 失敗するとfalseを返す + * + * @param key キー + * @param value 値 + * @return 真偽値 + */ + public boolean setDouble(String key, double value) { + return set(key, value); + } + + /** + * マップのキーに値(真偽値)をセット + * "."でパスを区切る + * 失敗するとfalseを返す + * + * @param key キー + * @param value 値 + * @return 真偽値 + */ + public boolean setBoolean(String key, boolean value) { + return set(key, value); + } + + /** + * マップのキーから値を削除 + * "."でパスを区切る + * + * @param key キー + * @return 真偽値 + */ + public boolean remove(String key) { + return configMap.remove(key) != null; + } + + /** + * StringをFileにして読み込み、継承先で処理 + * + * @param file ファイル名 + */ + public boolean load(String file) { + return load(new File(file)); + } + + /** + * この関数は継承先で定義 + * + * @param file ファイル + */ + public boolean load(File file) { + return false; + } + + /** + * StringをFileにし、継承先で処理して保存 + * + * @param file ファイル名 + */ + public boolean save(String file) { + return save(new File(file)); + } + + /** + * ファイルを継承先で処理して保存 + * + * @param file ファイル + */ + public boolean save(File file) { + return save(file, true); + } + + /** + * ファイルを継承先で処理して保存 + * + * @param file ファイル名 + * @param pretty 整形 + */ + public boolean save(String file, boolean pretty) { + return save(new File(file), pretty); + } + + /** + * この関数は継承先で定義 + * + * @param file ファイル + * @param pretty 整形 + */ + public boolean save(File file, boolean pretty) { + return false; + } +} diff --git a/common/src/main/java/net/pitan76/easyapi/config/IConfig.java b/common/src/main/java/net/pitan76/easyapi/config/IConfig.java new file mode 100644 index 000000000..09d0b68e8 --- /dev/null +++ b/common/src/main/java/net/pitan76/easyapi/config/IConfig.java @@ -0,0 +1,37 @@ +package net.pitan76.easyapi.config; + +import java.io.File; +import java.util.LinkedHashMap; +import java.util.Map; + +public interface IConfig { + Map configMap = new LinkedHashMap<>(); + + Object get(String key); + + String getString(String key); + + int getInt(String key); + + boolean getBoolean(String key); + + boolean set(String key, Object value); + + boolean setString(String key, String value); + + boolean setInt(String key, int value); + + boolean setBoolean(String key, boolean value); + + boolean load(String file); + + boolean load(File file); + + boolean save(String file); + + boolean save(File file); + + boolean save(String file, boolean pretty); + + boolean save(File file, boolean pretty); +} diff --git a/common/src/main/java/net/pitan76/easyapi/config/JsonConfig.java b/common/src/main/java/net/pitan76/easyapi/config/JsonConfig.java new file mode 100644 index 000000000..c549f09da --- /dev/null +++ b/common/src/main/java/net/pitan76/easyapi/config/JsonConfig.java @@ -0,0 +1,102 @@ +package net.pitan76.easyapi.config; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.reflect.TypeToken; +import net.pitan76.easyapi.FileControl; + +import java.io.File; +import java.lang.reflect.Type; +import java.util.LinkedHashMap; + +public class JsonConfig extends Config { + /** + * + * @param file ファイル + */ + public JsonConfig(File file) { + super(file); + } + + /** + * + * @param file ファイル名 + */ + public JsonConfig(String file) { + super(file); + } + + public JsonConfig() { + super(); + } + + /** + * Config→JsonConfigへ変換 + * + * @param config Config + */ + public JsonConfig(Config config) { + super(config); + } + + /** + * Jsonファイルを読み込んでMapへ変換 + * + * @param file ファイル + * @return 成功→true / 失敗→false + */ + public boolean load(File file) { + if (!file.exists()) { + configMap = new LinkedHashMap<>(); + return false; + } + + try { + String configData = FileControl.fileReadContents(file); + Gson gson = new Gson(); + Type jsonMap = new TypeToken>() { + }.getType(); + configMap = gson.fromJson(configData, jsonMap); + return true; + } catch (Exception e) { + configMap = new LinkedHashMap<>(); + return false; + } + } + + /** + * MapをJsonへ変換し、Jsonファイルとして保存 + * + * @param file ファイル + * @param pretty 整形 + * @return 成功→true / 失敗→false + */ + public boolean save(File file, boolean pretty) { + try { + String configData = this.toJson(pretty); + FileControl.fileWriteContents(file, configData); + return true; + } catch (Exception e) { + return false; + } + } + + /** + * MapをJsonへ変換 失敗した場合はnullを返す + * + * @param pretty 整形 + * @return Jsonの文字列 + */ + public String toJson(boolean pretty) { + try { + Gson gson = new Gson(); + if (pretty) { + gson = new GsonBuilder().setPrettyPrinting().create(); + } + String configData = gson.toJson(configMap); + return configData; + } catch (Exception e) { + return null; + } + } +} diff --git a/common/src/main/java/net/pitan76/easyapi/config/YamlConfig.java b/common/src/main/java/net/pitan76/easyapi/config/YamlConfig.java new file mode 100644 index 000000000..cc3774746 --- /dev/null +++ b/common/src/main/java/net/pitan76/easyapi/config/YamlConfig.java @@ -0,0 +1,114 @@ +package net.pitan76.easyapi.config; + +import net.pitan76.easyapi.FileControl; +import org.yaml.snakeyaml.DumperOptions; +import org.yaml.snakeyaml.Yaml; + +import java.io.File; +import java.util.LinkedHashMap; +import java.util.Map; + +public class YamlConfig extends Config { + + /** + * + * @param file ファイル + */ + public YamlConfig(File file) { + super(file); + } + + /** + * + * @param file ファイル名 + */ + public YamlConfig(String file) { + super(file); + } + + public YamlConfig() { + super(); + } + + /** + * Config→JsonConfigへ変換 + * + * @param config Config + */ + public YamlConfig(Config config) { + super(config); + } + + private DumperOptions.FlowStyle style = DumperOptions.FlowStyle.BLOCK; + + /** + * 出力するYamlのスタイルの設定 + * + * @param flowStyle FlowStyle + */ + public void setStyle(DumperOptions.FlowStyle flowStyle) { + style = flowStyle; + } + + /** + * Yamlファイルを読み込んでMapへ変換 + * + * @param file ファイル + * @return 成功→true / 失敗→false + */ + @SuppressWarnings("unchecked") + public boolean load(File file) { + if (!file.exists()) { + configMap = new LinkedHashMap<>(); + return false; + } + + try { + String configData = FileControl.fileReadContents(file); + Yaml yaml = new Yaml(); + configMap = (Map) yaml.load(configData); + return true; + } catch (Exception e) { + configMap = new LinkedHashMap<>(); + return false; + } + } + + /** + * MapをYamlへ変換し、Yamlファイルとして保存 + * + * @param file ファイル + * @param pretty 整形 + * @return 成功→true / 失敗→false + */ + public boolean save(File file, boolean pretty) { + try { + String configData = this.toYaml(pretty); + FileControl.fileWriteContents(file, configData); + return true; + } catch (Exception e) { + return false; + } + } + + /** + * MapをYamlへ変換 失敗した場合はnullを返す + * + * @param pretty 整形 + * @return Yamlの文字列 + */ + public String toYaml(boolean pretty) { + try { + DumperOptions options = new DumperOptions(); + options.setDefaultFlowStyle(style); + if (pretty) { + options.setPrettyFlow(true); + } + Yaml yaml = new Yaml(options); + String configData = yaml.dump(configMap); + return configData; + } catch (Exception e) { + return null; + } + } +} diff --git a/common/src/main/java/net/pitan76/easyapi/config/package-info.java b/common/src/main/java/net/pitan76/easyapi/config/package-info.java new file mode 100644 index 000000000..88238e2bc --- /dev/null +++ b/common/src/main/java/net/pitan76/easyapi/config/package-info.java @@ -0,0 +1,4 @@ +/** + * Config関連のクラスが入っているパッケージ + */ +package net.pitan76.easyapi.config; diff --git a/common/src/main/java/net/pitan76/mcpitanlib/MCPitanLib.java b/common/src/main/java/net/pitan76/mcpitanlib/MCPitanLib.java new file mode 100644 index 000000000..d91c5ce9b --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/MCPitanLib.java @@ -0,0 +1,127 @@ +/* +Copyright (C) 2022-2024 Pitan + +MCPitanLib is under the MIT license. For more information, please refer to the LICENSE file at the root of the repository. +MCPitanLibはMITライセンスです。ライセンスについてはリポジトリ直下のLICENSEファイルを参照してください。 + */ + +package net.pitan76.mcpitanlib; + +import net.minecraft.util.Identifier; +import net.pitan76.easyapi.config.Config; +import net.pitan76.easyapi.config.JsonConfig; +import net.pitan76.mcpitanlib.api.registry.CompatRegistry; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.api.util.IdentifierUtil; +import net.pitan76.mcpitanlib.api.util.PlatformUtil; +import net.pitan76.mcpitanlib.debug.DebugTool; +import net.pitan76.mcpitanlib.guilib.MPLGuiLib; +import net.pitan76.mcpitanlib.test.ExampleMod; +import net.pitan76.mcpitanlib.test.ExampleModClient; + +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class MCPitanLib { + public static final String MOD_ID = "mcpitanlib"; + + private static final File configFile = new File(PlatformUtil.getConfigFolder().toFile(), "mcpitanlib/blacklist.json"); + private static final File oldConfigFile = new File(PlatformUtil.getConfigFolder().toFile(), "mcpitanlibarch/blacklist.json"); + + public static Config config = new JsonConfig(); + private static boolean configLoaded = false; + + public static List itemBlackList = new ArrayList<>(); + public static List blockBlackList = new ArrayList<>(); + + // MCPitanLibのアイテム、ブロック、タイルエンティティの登録 + public static CompatRegistry registry; + + /** + * MCPitanLibの初期化 + */ + public static void init() { + configInit(); + MPLGuiLib.init(); + + if (PlatformUtil.isDevelopmentEnvironment() || (config.has("debugMode") && config.getBoolean("debugMode"))) { + System.out.println("MCPitanLib: Debug Mode"); + + registry = CompatRegistry.createRegistry(MOD_ID); + DebugTool.register(); + registry.allRegister(); + + new ExampleMod(); + if (PlatformUtil.isClient()) + ExampleModClient.init(); + } + } + + /** + * Configの初期化 + */ + public static void configInit() { + if (oldConfigFile.exists() && !configFile.exists()) { + oldConfigFile.renameTo(configFile); + } + + try { + if (configLoaded) return; + configLoaded = true; + if (!configFile.getParentFile().exists()) + if (!configFile.getParentFile().mkdirs()) + return; + + config.setString("item", "examplemod:hogehoge_item,examplemod:fuga_item"); + config.setString("block", "examplemod:hogehoge_block,examplemod:fuga_block"); + config.setBoolean("debugMode", false); + + if (configFile.exists()) + config.load(configFile); + + if (!config.has("debugMode")) + config.setBoolean("debugMode", false); + + if (config.has("item")) + itemBlackList.addAll(Arrays.asList(config.getString("item").split(","))); + + if (config.has("block")) + blockBlackList.addAll(Arrays.asList(config.getString("block").split(","))); + + config.save(configFile); + } catch (Exception e) { + System.out.println("MCPitanLib: Cannot save config file"); + } + } + + /** + * Identifierを生成 + * @param path パス + * @return Identifier + */ + public static Identifier id(String path) { + return IdentifierUtil.id(MOD_ID, path); + } + + public static CompatIdentifier compatId(String path) { + return CompatIdentifier.fromMinecraft(id(path)); + } + + public static boolean isItemBlackListed(Identifier id) { + try { + return itemBlackList.contains(id.toString()); + } catch (Exception e) { + return false; + } + } + + public static boolean isBlockBlackListed(Identifier id) { + try { + return blockBlackList.contains(id.toString()); + } catch (Exception e) { + return false; + } + } +} \ No newline at end of file diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/CommonModInitializer.java b/common/src/main/java/net/pitan76/mcpitanlib/api/CommonModInitializer.java new file mode 100644 index 000000000..148772679 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/CommonModInitializer.java @@ -0,0 +1,66 @@ +package net.pitan76.mcpitanlib.api; + +import net.minecraft.util.Identifier; +import net.pitan76.mcpitanlib.api.registry.v2.CompatRegistryV2; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.api.util.IdentifierUtil; +import net.pitan76.mcpitanlib.api.util.Logger; + +public abstract class CommonModInitializer { + + public final String MOD_ID; + public final String MOD_NAME; + + public final CompatRegistryV2 registry; + public final Logger logger; + + public CommonModInitializer() { + this.MOD_ID = getId(); + this.MOD_NAME = getName(); + + this.registry = CompatRegistryV2.create(MOD_ID); + this.logger = new Logger(MOD_ID); + + logger.initializeMessage(); + init(); + registry.allRegister(); + } + + public abstract void init(); + + public abstract String getId(); + + public String getName() { + return getId(); + } + + + // Utilities + public Identifier id(String path) { + return IdentifierUtil.id(MOD_ID, path); + } + + public CompatIdentifier compatId(String path) { + return CompatIdentifier.of(MOD_ID, path); + } + + public void info(String message) { + logger.info(message); + } + + public void warn(String message) { + logger.warn(message); + } + + public void error(String message) { + logger.error(message); + } + + public void debug(String message) { + logger.debug(message); + } + + public void trace(String message) { + logger.trace(message); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/block/CompatBlockRenderType.java b/common/src/main/java/net/pitan76/mcpitanlib/api/block/CompatBlockRenderType.java new file mode 100644 index 000000000..5c403aca2 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/block/CompatBlockRenderType.java @@ -0,0 +1,25 @@ +package net.pitan76.mcpitanlib.api.block; + +import net.minecraft.block.BlockRenderType; + +public class CompatBlockRenderType { + + public static final CompatBlockRenderType MODEL = of(BlockRenderType.MODEL); + public static final CompatBlockRenderType ENTITYBLOCK_ANIMATED = of(BlockRenderType.ENTITYBLOCK_ANIMATED); + public static final CompatBlockRenderType INVISIBLE = of(BlockRenderType.INVISIBLE); + + @Deprecated + public final BlockRenderType renderType; + + public CompatBlockRenderType(BlockRenderType renderType) { + this.renderType = renderType; + } + + public static CompatBlockRenderType of(BlockRenderType renderType) { + return new CompatBlockRenderType(renderType); + } + + public BlockRenderType toMinecraft() { + return renderType; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/block/CompatBlocks.java b/common/src/main/java/net/pitan76/mcpitanlib/api/block/CompatBlocks.java new file mode 100644 index 000000000..e855ccf32 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/block/CompatBlocks.java @@ -0,0 +1,96 @@ +package net.pitan76.mcpitanlib.api.block; + +import net.minecraft.block.Block; +import net.minecraft.block.Blocks; + +public class CompatBlocks { + public static final Block AIR = Blocks.AIR; + public static final Block STONE = Blocks.STONE; + public static final Block COBBLESTONE = Blocks.COBBLESTONE; + public static final Block GRASS_BLOCK = Blocks.GRASS_BLOCK; + public static final Block DIRT = Blocks.DIRT; + public static final Block SAND = Blocks.SAND; + public static final Block RED_SAND = Blocks.RED_SAND; + public static final Block GRANITE = Blocks.GRANITE; + public static final Block POLISHED_GRANITE = Blocks.POLISHED_GRANITE; + public static final Block DIORITE = Blocks.DIORITE; + public static final Block POLISHED_DIORITE = Blocks.POLISHED_DIORITE; + public static final Block ANDESITE = Blocks.ANDESITE; + public static final Block POLISHED_ANDESITE = Blocks.POLISHED_ANDESITE; + public static final Block COARSE_DIRT = Blocks.COARSE_DIRT; + public static final Block PODZOL = Blocks.PODZOL; + + public static final Block OAK_LOG = Blocks.OAK_LOG; + public static final Block SPRUCE_LOG = Blocks.SPRUCE_LOG; + public static final Block BIRCH_LOG = Blocks.BIRCH_LOG; + public static final Block JUNGLE_LOG = Blocks.JUNGLE_LOG; + public static final Block ACACIA_LOG = Blocks.ACACIA_LOG; + public static final Block DARK_OAK_LOG = Blocks.DARK_OAK_LOG; + public static final Block OAK_PLANKS = Blocks.OAK_PLANKS; + public static final Block SPRUCE_PLANKS = Blocks.SPRUCE_PLANKS; + public static final Block BIRCH_PLANKS = Blocks.BIRCH_PLANKS; + public static final Block JUNGLE_PLANKS = Blocks.JUNGLE_PLANKS; + public static final Block ACACIA_PLANKS = Blocks.ACACIA_PLANKS; + public static final Block DARK_OAK_PLANKS = Blocks.DARK_OAK_PLANKS; + public static final Block OAK_SAPLING = Blocks.OAK_SAPLING; + public static final Block SPRUCE_SAPLING = Blocks.SPRUCE_SAPLING; + public static final Block BIRCH_SAPLING = Blocks.BIRCH_SAPLING; + public static final Block JUNGLE_SAPLING = Blocks.JUNGLE_SAPLING; + public static final Block ACACIA_SAPLING = Blocks.ACACIA_SAPLING; + public static final Block DARK_OAK_SAPLING = Blocks.DARK_OAK_SAPLING; + + public static final Block SANDSTONE = Blocks.SANDSTONE; + public static final Block CHISELED_SANDSTONE = Blocks.CHISELED_SANDSTONE; + public static final Block CUT_SANDSTONE = Blocks.CUT_SANDSTONE; + public static final Block NOTE_BLOCK = Blocks.NOTE_BLOCK; + public static final Block POWERED_RAIL = Blocks.POWERED_RAIL; + public static final Block DETECTOR_RAIL = Blocks.DETECTOR_RAIL; + public static final Block PISTON = Blocks.PISTON; + public static final Block STICKY_PISTON = Blocks.STICKY_PISTON; + public static final Block COBWEB = Blocks.COBWEB; + public static final Block GRAVEL = Blocks.GRAVEL; + public static final Block GLASS = Blocks.GLASS; + public static final Block DISPENSER = Blocks.DISPENSER; + + public static final Block COAL_ORE = Blocks.COAL_ORE; + public static final Block IRON_ORE = Blocks.IRON_ORE; + public static final Block COPPER_ORE = Blocks.COPPER_ORE; + public static final Block GOLD_ORE = Blocks.GOLD_ORE; + public static final Block DIAMOND_ORE = Blocks.DIAMOND_ORE; + public static final Block REDSTONE_ORE = Blocks.REDSTONE_ORE; + public static final Block EMERALD_ORE = Blocks.EMERALD_ORE; + public static final Block LAPIS_ORE = Blocks.LAPIS_ORE; + public static final Block NETHER_QUARTZ_ORE = Blocks.NETHER_QUARTZ_ORE; + + public static final Block COAL_BLOCK = Blocks.COAL_BLOCK; + public static final Block IRON_BLOCK = Blocks.IRON_BLOCK; + public static final Block COPPER_BLOCK = Blocks.COPPER_BLOCK; + public static final Block GOLD_BLOCK = Blocks.GOLD_BLOCK; + public static final Block DIAMOND_BLOCK = Blocks.DIAMOND_BLOCK; + public static final Block REDSTONE_BLOCK = Blocks.REDSTONE_BLOCK; + public static final Block EMERALD_BLOCK = Blocks.EMERALD_BLOCK; + public static final Block LAPIS_BLOCK = Blocks.LAPIS_BLOCK; + public static final Block QUARTZ_BLOCK = Blocks.QUARTZ_BLOCK; + + public static final Block TNT = Blocks.TNT; + public static final Block BOOKSHELF = Blocks.BOOKSHELF; + public static final Block OBSIDIAN = Blocks.OBSIDIAN; + public static final Block TORCH = Blocks.TORCH; + public static final Block WALL_TORCH = Blocks.WALL_TORCH; + public static final Block FIRE = Blocks.FIRE; + public static final Block SOUL_FIRE = Blocks.SOUL_FIRE; + public static final Block SPAWNER = Blocks.SPAWNER; + public static final Block OAK_STAIRS = Blocks.OAK_STAIRS; + public static final Block CHEST = Blocks.CHEST; + public static final Block REDSTONE_WIRE = Blocks.REDSTONE_WIRE; + + public static final Block WATER = Blocks.WATER; + public static final Block LAVA = Blocks.LAVA; + public static final Block BEDROCK = Blocks.BEDROCK; + + // ---- + + public static boolean isExist(Block block) { + return block != null && block != Blocks.AIR; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/block/CompatChestBlock.java b/common/src/main/java/net/pitan76/mcpitanlib/api/block/CompatChestBlock.java new file mode 100644 index 000000000..f33d401dd --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/block/CompatChestBlock.java @@ -0,0 +1,46 @@ +package net.pitan76.mcpitanlib.api.block; + +import net.minecraft.block.BlockState; +import net.minecraft.block.ChestBlock; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.block.entity.BlockEntityType; +import net.minecraft.block.entity.ChestBlockEntity; +import net.minecraft.util.math.BlockPos; +import net.pitan76.mcpitanlib.api.block.v2.CompatBlockProvider; +import net.pitan76.mcpitanlib.api.block.v2.CompatibleBlockSettings; +import net.pitan76.mcpitanlib.api.event.block.TileCreateEvent; + +import java.util.function.Supplier; + +public class CompatChestBlock extends ChestBlock implements CompatBlockProvider { + public CompatChestBlock(Settings settings, Supplier> supplier) { + super(settings, supplier); + } + + public CompatibleBlockSettings compatSettings; + + public CompatChestBlock(CompatibleBlockSettings settings, Supplier> supplier) { + this(settings.build(), supplier); + } + + /** + * @deprecated Use {@link #createBlockEntity(TileCreateEvent)} instead. + */ + @Deprecated + @Override + public BlockEntity createBlockEntity(BlockPos pos, BlockState state) { + return createBlockEntity(new TileCreateEvent(pos, state)); + } + + /** + * @see ExtendBlockEntityProvider#createBlockEntity(TileCreateEvent) + */ + public BlockEntity createBlockEntity(TileCreateEvent event) { + return super.createBlockEntity(event.getBlockPos(), event.getBlockState()); + } + + @Override + public CompatibleBlockSettings getCompatSettings() { + return compatSettings; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/block/CompatPillarBlock.java b/common/src/main/java/net/pitan76/mcpitanlib/api/block/CompatPillarBlock.java new file mode 100644 index 000000000..d2bf93a5a --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/block/CompatPillarBlock.java @@ -0,0 +1,80 @@ +package net.pitan76.mcpitanlib.api.block; + +import com.mojang.serialization.MapCodec; +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.block.PillarBlock; +import net.minecraft.item.ItemPlacementContext; +import net.minecraft.state.StateManager; +import net.minecraft.util.math.Direction; +import net.pitan76.mcpitanlib.api.block.v2.CompatBlockProvider; +import net.pitan76.mcpitanlib.api.block.v2.CompatibleBlockSettings; +import net.pitan76.mcpitanlib.api.event.block.AppendPropertiesArgs; +import net.pitan76.mcpitanlib.api.event.block.PlacementStateArgs; +import net.pitan76.mcpitanlib.api.state.property.CompatProperties; +import net.pitan76.mcpitanlib.api.state.property.EnumProperty; +import net.pitan76.mcpitanlib.core.serialization.CompatMapCodec; + +public class CompatPillarBlock extends PillarBlock implements CompatBlockProvider { + + public static final EnumProperty AXIS = CompatProperties.of(PillarBlock.AXIS); + + public CompatibleBlockSettings settings; + + @Override + public CompatibleBlockSettings getCompatSettings() { + return settings; + } + + public CompatPillarBlock(Settings settings) { + super(settings); + } + + public CompatPillarBlock(CompatibleBlockSettings settings) { + this(settings.build()); + this.settings = settings; + } + + public void appendProperties(AppendPropertiesArgs args) { + super.appendProperties(args.builder); + } + + public BlockState getPlacementState(PlacementStateArgs args) { + return super.getPlacementState(args.ctx); + } + + @Deprecated + @Override + public void appendProperties(StateManager.Builder builder) { + appendProperties(new AppendPropertiesArgs(builder)); + } + + @Deprecated + @Override + public BlockState getPlacementState(ItemPlacementContext ctx) { + return getPlacementState(new PlacementStateArgs(ctx)); + } + + // ExtendBlockProvider + @Deprecated + @Override + public void appendProperties(AppendPropertiesArgs args, Options options) { + CompatBlockProvider.super.appendProperties(args, options); + } + + @Deprecated + @Override + public BlockState getPlacementState(PlacementStateArgs args, Options options) { + return CompatBlockProvider.super.getPlacementState(args, options); + } + + @Deprecated + @Override + public MapCodec getCodec() { + return getCompatCodec().getCodec(); + } + + public CompatMapCodec getCompatCodec() { + return CompatMapCodec.of(super.getCodec()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/block/CompatSlabBlock.java b/common/src/main/java/net/pitan76/mcpitanlib/api/block/CompatSlabBlock.java new file mode 100644 index 000000000..ac7284995 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/block/CompatSlabBlock.java @@ -0,0 +1,100 @@ +package net.pitan76.mcpitanlib.api.block; + +import com.mojang.serialization.MapCodec; +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.block.SlabBlock; +import net.minecraft.block.enums.SlabType; +import net.minecraft.entity.ai.pathing.NavigationType; +import net.minecraft.item.ItemPlacementContext; +import net.minecraft.state.StateManager; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.BlockView; +import net.pitan76.mcpitanlib.api.block.v2.CompatBlockProvider; +import net.pitan76.mcpitanlib.api.block.v2.CompatibleBlockSettings; +import net.pitan76.mcpitanlib.api.event.block.AppendPropertiesArgs; +import net.pitan76.mcpitanlib.api.event.block.CanPathfindThroughArgs; +import net.pitan76.mcpitanlib.api.event.block.PlacementStateArgs; +import net.pitan76.mcpitanlib.api.state.property.BooleanProperty; +import net.pitan76.mcpitanlib.api.state.property.CompatProperties; +import net.pitan76.mcpitanlib.api.state.property.EnumProperty; +import net.pitan76.mcpitanlib.core.serialization.CompatMapCodec; + +public class CompatSlabBlock extends SlabBlock implements CompatBlockProvider { + + public static final EnumProperty TYPE = CompatProperties.of(SlabBlock.TYPE); + public static final BooleanProperty WATERLOGGED = CompatProperties.of(SlabBlock.WATERLOGGED); + + public CompatibleBlockSettings settings; + + @Override + public CompatibleBlockSettings getCompatSettings() { + return settings; + } + + public CompatSlabBlock(Settings settings) { + super(settings); + } + + public CompatSlabBlock(CompatibleBlockSettings settings) { + this(settings.build()); + } + + public void appendProperties(AppendPropertiesArgs args) { + super.appendProperties(args.builder); + } + + public BlockState getPlacementState(PlacementStateArgs args) { + return super.getPlacementState(args.ctx); + } + + @Deprecated + @Override + public void appendProperties(StateManager.Builder builder) { + appendProperties(new AppendPropertiesArgs(builder)); + } + + @Deprecated + @Override + public BlockState getPlacementState(ItemPlacementContext ctx) { + return getPlacementState(new PlacementStateArgs(ctx)); + } + + // ExtendBlockProvider + @Deprecated + @Override + public void appendProperties(AppendPropertiesArgs args, Options options) { + CompatBlockProvider.super.appendProperties(args, options); + } + + @Deprecated + @Override + public BlockState getPlacementState(PlacementStateArgs args, Options options) { + return CompatBlockProvider.super.getPlacementState(args, options); + } + + @Deprecated + @Override + public MapCodec getCodec() { + return getCompatCodec().getCodec(); + } + + public CompatMapCodec getCompatCodec() { + return CompatMapCodec.of(super.getCodec()); + } + + @Deprecated + @Override + public boolean canPathfindThrough(BlockState state, NavigationType type) { + return canPathfindThrough(new CanPathfindThroughArgs(state, type)); + } + + public boolean canPathfindThrough(CanPathfindThroughArgs args) { + return super.canPathfindThrough(args.state, args.type); + } + + @Override + public Boolean canPathfindThrough(CanPathfindThroughArgs args, Options options) { + return CompatBlockProvider.super.canPathfindThrough(args, options); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/block/CompatStairsBlock.java b/common/src/main/java/net/pitan76/mcpitanlib/api/block/CompatStairsBlock.java new file mode 100644 index 000000000..6ad2e57ab --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/block/CompatStairsBlock.java @@ -0,0 +1,129 @@ +package net.pitan76.mcpitanlib.api.block; + +import com.mojang.serialization.MapCodec; +import net.minecraft.block.*; +import net.minecraft.block.enums.BlockHalf; +import net.minecraft.block.enums.StairShape; +import net.minecraft.entity.ai.pathing.NavigationType; +import net.minecraft.item.ItemPlacementContext; +import net.minecraft.state.StateManager; +import net.minecraft.state.property.BooleanProperty; +import net.minecraft.state.property.EnumProperty; +import net.pitan76.mcpitanlib.api.block.v2.CompatBlockProvider; +import net.pitan76.mcpitanlib.api.block.v2.CompatibleBlockSettings; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.shape.VoxelShape; +import net.minecraft.world.BlockView; +import net.pitan76.mcpitanlib.api.event.block.AppendPropertiesArgs; +import net.pitan76.mcpitanlib.api.event.block.CanPathfindThroughArgs; +import net.pitan76.mcpitanlib.api.event.block.OutlineShapeEvent; +import net.pitan76.mcpitanlib.api.event.block.PlacementStateArgs; +import net.pitan76.mcpitanlib.api.state.property.CompatProperties; +import net.pitan76.mcpitanlib.api.state.property.DirectionProperty; +import net.pitan76.mcpitanlib.core.serialization.CompatMapCodec; + +public class CompatStairsBlock extends StairsBlock implements CompatBlockProvider { + + public static final DirectionProperty FACING = CompatProperties.HORIZONTAL_FACING; + public static final EnumProperty HALF = StairsBlock.HALF; + public static final EnumProperty SHAPE = StairsBlock.SHAPE; + public static final BooleanProperty WATERLOGGED = StairsBlock.WATERLOGGED; + + public CompatibleBlockSettings compatSettings; + + /** + * get compatible block settings + * @return CompatibleBlockSettings + */ + @Override + public CompatibleBlockSettings getCompatSettings() { + return compatSettings; + } + + public CompatStairsBlock(BlockState baseBlockState, Settings settings) { + super(baseBlockState, settings); + } + + public CompatStairsBlock(BlockState baseBlockState, CompatibleBlockSettings settings) { + this(baseBlockState, settings.build()); + this.compatSettings = settings; + } + + public VoxelShape getOutlineShape(OutlineShapeEvent event) { + return super.getOutlineShape(event.state, event.world, event.pos, event.context); + } + + public void appendProperties(AppendPropertiesArgs args) { + super.appendProperties(args.builder); + } + + public BlockState getPlacementState(PlacementStateArgs args) { + return super.getPlacementState(args.ctx); + } + + @Deprecated + @Override + public void appendProperties(StateManager.Builder builder) { + appendProperties(new AppendPropertiesArgs(builder)); + } + + @Deprecated + @Override + public BlockState getPlacementState(ItemPlacementContext ctx) { + return getPlacementState(new PlacementStateArgs(ctx)); + } + + @Deprecated + @Override + protected VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) { + return getOutlineShape(new OutlineShapeEvent(state, world, pos, context)); + } + + // ExtendBlockProvider + @Deprecated + @Override + public void appendProperties(AppendPropertiesArgs args, Options options) { + CompatBlockProvider.super.appendProperties(args, options); + } + + @Deprecated + @Override + public BlockState getPlacementState(PlacementStateArgs args, Options options) { + return CompatBlockProvider.super.getPlacementState(args, options); + } + + @Deprecated + @Override + public VoxelShape getOutlineShape(OutlineShapeEvent event, Options options) { + return CompatBlockProvider.super.getOutlineShape(event, options); + } + + @Deprecated + @Override + public MapCodec getCodec() { + return getCompatCodec().getCodec(); + } + + public CompatMapCodec getCompatCodec() { + return CompatMapCodec.of(super.getCodec()); + } + + @Deprecated + @Override + public boolean canPathfindThrough(BlockState state, NavigationType type) { + return canPathfindThrough(new CanPathfindThroughArgs(state, type)); + } + + public boolean canPathfindThrough(CanPathfindThroughArgs args) { + return super.canPathfindThrough(args.state, args.type); + } + + @Override + public Boolean canPathfindThrough(CanPathfindThroughArgs args, Options options) { + return CompatBlockProvider.super.canPathfindThrough(args, options); + } + + public BlockState getBaseBlockState() { + return super.baseBlockState; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/block/CompatWaterloggable.java b/common/src/main/java/net/pitan76/mcpitanlib/api/block/CompatWaterloggable.java new file mode 100644 index 000000000..0402b719d --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/block/CompatWaterloggable.java @@ -0,0 +1,21 @@ +package net.pitan76.mcpitanlib.api.block; + +import net.minecraft.block.Waterloggable; +import net.minecraft.sound.SoundEvent; +import net.pitan76.mcpitanlib.api.sound.CompatSoundEvent; + +import java.util.Optional; + +public interface CompatWaterloggable extends Waterloggable { + + @Override + default Optional getBucketFillSound() { + return getCompactBucketFillSound() + .map(CompatSoundEvent::get); + } + + default Optional getCompactBucketFillSound() { + return Waterloggable.super.getBucketFillSound() + .map(CompatSoundEvent::of); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/block/CompatibleBlockSettings.java b/common/src/main/java/net/pitan76/mcpitanlib/api/block/CompatibleBlockSettings.java new file mode 100644 index 000000000..56cc62dc5 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/block/CompatibleBlockSettings.java @@ -0,0 +1,252 @@ +package net.pitan76.mcpitanlib.api.block; + +import com.mojang.serialization.Codec; +import net.minecraft.block.AbstractBlock; +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.block.MapColor; +import net.minecraft.sound.BlockSoundGroup; +import net.minecraft.util.DyeColor; +import net.pitan76.mcpitanlib.api.sound.CompatBlockSoundGroup; + +import java.util.function.Function; +import java.util.function.ToIntFunction; + +@Deprecated +public class CompatibleBlockSettings { + public static final Codec CODEC = Codec.unit(CompatibleBlockSettings::of); + + protected final AbstractBlock.Settings settings; + + public CompatibleBlockSettings() { + this.settings = AbstractBlock.Settings.create(); + } + + @Deprecated + public static CompatibleBlockSettings of() { + return new CompatibleBlockSettings(); + } + + @Deprecated + private static CompatibleBlockSettings copyCompatibleMaterial(CompatibleMaterial material, CompatibleBlockSettings settings) { + settings.mapColor(material.getColor()); + if (material.isLiquid()) + settings.settings.liquid(); + if (material.isSolid()) + settings.settings.solid(); + if (material.isReplaceable()) + settings.settings.replaceable(); + if (material.isSolid()) + settings.settings.solid(); + if (material.isBurnable()) + settings.settings.burnable(); + settings.settings.pistonBehavior(material.getPistonBehavior()); + return settings; + } + + public CompatibleBlockSettings(CompatibleMaterial material, MapColor mapColor) { + this.settings = AbstractBlock.Settings.create(); + copyCompatibleMaterial(material, this); + mapColor(mapColor); + } + + public CompatibleBlockSettings(CompatibleMaterial material, DyeColor dyeColor) { + this.settings = AbstractBlock.Settings.create(); + copyCompatibleMaterial(material, this); + mapColor(dyeColor); + } + + public CompatibleBlockSettings(CompatibleMaterial material) { + this.settings = AbstractBlock.Settings.create(); + copyCompatibleMaterial(material, this); + } + + public CompatibleBlockSettings(CompatibleMaterial material, Function mapColor) { + this.settings = AbstractBlock.Settings.create(); + copyCompatibleMaterial(material, this); + mapColor(mapColor); + } + + @Deprecated + public static CompatibleBlockSettings of(CompatibleMaterial material, MapColor mapColor) { + return new CompatibleBlockSettings(material, mapColor); + } + + @Deprecated + public static CompatibleBlockSettings of(CompatibleMaterial material, DyeColor dyeColor) { + return new CompatibleBlockSettings(material, dyeColor); + } + + @Deprecated + public static CompatibleBlockSettings of(CompatibleMaterial material) { + return new CompatibleBlockSettings(material); + } + + @Deprecated + public static CompatibleBlockSettings of(CompatibleMaterial material, Function mapColor) { + return new CompatibleBlockSettings(material, mapColor); + } + + public CompatibleBlockSettings(AbstractBlock block) { + this.settings = AbstractBlock.Settings.copy(block); + } + + @Deprecated + public static CompatibleBlockSettings copy(AbstractBlock block) { + return new CompatibleBlockSettings(block); + } + + public CompatibleBlockSettings air() { + settings.air(); + return this; + } + + public CompatibleBlockSettings blockVision(AbstractBlock.ContextPredicate predicate) { + settings.blockVision(predicate); + return this; + } + + public CompatibleBlockSettings postProcess(AbstractBlock.ContextPredicate predicate) { + settings.postProcess(predicate); + return this; + } + + public CompatibleBlockSettings solidBlock(AbstractBlock.ContextPredicate predicate) { + settings.solidBlock(predicate); + return this; + } + + public CompatibleBlockSettings suffocates(AbstractBlock.ContextPredicate predicate) { + settings.suffocates(predicate); + return this; + } + + public CompatibleBlockSettings mapColor(MapColor color) { + settings.mapColor(color); + return this; + } + + public CompatibleBlockSettings mapColor(DyeColor color) { + settings.mapColor(color); + return this; + } + + public CompatibleBlockSettings mapColor(Function color) { + settings.mapColor(color); + return this; + } + + @Deprecated + public CompatibleBlockSettings dropsLike(Block source) { + return this; + } + + public CompatibleBlockSettings breakInstantly() { + settings.breakInstantly(); + return this; + } + + public CompatibleBlockSettings dropsNothing() { + settings.dropsNothing(); + return this; + } + + public CompatibleBlockSettings dynamicBounds() { + settings.dynamicBounds(); + return this; + } + + public CompatibleBlockSettings hardness(float hardness) { + settings.hardness(hardness); + return this; + } + + public CompatibleBlockSettings noBlockBreakParticles() { + settings.noBlockBreakParticles(); + return this; + } + + public CompatibleBlockSettings requiresTool() { + settings.requiresTool(); + return this; + } + + public CompatibleBlockSettings noCollision() { + settings.noCollision(); + return this; + } + + public CompatibleBlockSettings nonOpaque() { + settings.nonOpaque(); + return this; + } + + public CompatibleBlockSettings resistance(float resistance) { + settings.resistance(resistance); + return this; + } + + public CompatibleBlockSettings strength(float strength) { + settings.strength(strength); + return this; + } + + public CompatibleBlockSettings strength(float hardness, float resistance) { + settings.strength(hardness, resistance); + return this; + } + + public CompatibleBlockSettings ticksRandomly() { + settings.ticksRandomly(); + return this; + } + + public CompatibleBlockSettings sounds(BlockSoundGroup blockSoundGroup) { + settings.sounds(blockSoundGroup); + return this; + } + + public CompatibleBlockSettings sounds(CompatBlockSoundGroup blockSoundGroup) { + return sounds(blockSoundGroup.get()); + } + + public CompatibleBlockSettings luminance(ToIntFunction luminance) { + settings.luminance(luminance); + return this; + } + + public CompatibleBlockSettings jumpVelocityMultiplier(float jumpVelocityMultiplier) { + settings.jumpVelocityMultiplier(jumpVelocityMultiplier); + return this; + } + + public CompatibleBlockSettings slipperiness(float slipperiness) { + settings.slipperiness(slipperiness); + return this; + } + + public CompatibleBlockSettings velocityMultiplier(float velocityMultiplier) { + settings.velocityMultiplier(velocityMultiplier); + return this; + } + + public CompatibleBlockSettings emissiveLighting(AbstractBlock.ContextPredicate predicate) { + settings.emissiveLighting(predicate); + return this; + } + + public CompatibleBlockSettings offset(AbstractBlock.OffsetType offsetType) { + settings.offset(offsetType); + return this; + } + + public CompatibleBlockSettings allowsSpawning(AbstractBlock.TypedContextPredicate> predicate) { + settings.allowsSpawning(predicate); + return this; + } + + public AbstractBlock.Settings build() { + return settings; + + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/block/CompatibleMaterial.java b/common/src/main/java/net/pitan76/mcpitanlib/api/block/CompatibleMaterial.java new file mode 100644 index 000000000..e39962a99 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/block/CompatibleMaterial.java @@ -0,0 +1,206 @@ +package net.pitan76.mcpitanlib.api.block; + +import net.minecraft.block.MapColor; +import net.minecraft.block.piston.PistonBehavior; + +public final class CompatibleMaterial { + public static final CompatibleMaterial AIR; + public static final CompatibleMaterial STRUCTURE_VOID; + public static final CompatibleMaterial PORTAL; + public static final CompatibleMaterial CARPET; + public static final CompatibleMaterial PLANT; + public static final CompatibleMaterial UNDERWATER_PLANT; + public static final CompatibleMaterial REPLACEABLE_PLANT; + public static final CompatibleMaterial NETHER_SHOOTS; + public static final CompatibleMaterial REPLACEABLE_UNDERWATER_PLANT; + public static final CompatibleMaterial WATER; + public static final CompatibleMaterial BUBBLE_COLUMN; + public static final CompatibleMaterial LAVA; + public static final CompatibleMaterial SNOW_LAYER; + public static final CompatibleMaterial FIRE; + public static final CompatibleMaterial DECORATION; + public static final CompatibleMaterial COBWEB; + public static final CompatibleMaterial SCULK; + public static final CompatibleMaterial REDSTONE_LAMP; + public static final CompatibleMaterial ORGANIC_PRODUCT; + public static final CompatibleMaterial SOIL; + public static final CompatibleMaterial SOLID_ORGANIC; + public static final CompatibleMaterial DENSE_ICE; + public static final CompatibleMaterial AGGREGATE; + public static final CompatibleMaterial SPONGE; + public static final CompatibleMaterial SHULKER_BOX; + public static final CompatibleMaterial WOOD; + public static final CompatibleMaterial NETHER_WOOD; + public static final CompatibleMaterial BAMBOO_SAPLING; + public static final CompatibleMaterial BAMBOO; + public static final CompatibleMaterial WOOL; + public static final CompatibleMaterial TNT; + public static final CompatibleMaterial LEAVES; + public static final CompatibleMaterial GLASS; + public static final CompatibleMaterial ICE; + public static final CompatibleMaterial CACTUS; + public static final CompatibleMaterial STONE; + public static final CompatibleMaterial METAL; + public static final CompatibleMaterial SNOW_BLOCK; + public static final CompatibleMaterial REPAIR_STATION; + public static final CompatibleMaterial BARRIER; + public static final CompatibleMaterial PISTON; + public static final CompatibleMaterial MOSS_BLOCK; + public static final CompatibleMaterial GOURD; + public static final CompatibleMaterial EGG; + public static final CompatibleMaterial CAKE; + public static final CompatibleMaterial AMETHYST; + public static final CompatibleMaterial POWDER_SNOW; + private final MapColor color; + private final PistonBehavior pistonBehavior; + private final boolean burnable; + private final boolean liquid; + private final boolean replaceable; + private final boolean solid; + + public CompatibleMaterial(MapColor color, boolean liquid, boolean solid, boolean burnable, boolean replaceable, PistonBehavior pistonBehavior) { + this.color = color; + this.liquid = liquid; + this.solid = solid; + this.burnable = burnable; + this.replaceable = replaceable; + this.pistonBehavior = pistonBehavior; + } + + public boolean isLiquid() { + return this.liquid; + } + + public boolean isSolid() { + return this.solid; + } + + public boolean isBurnable() { + return this.burnable; + } + + public boolean isReplaceable() { + return this.replaceable; + } + + public PistonBehavior getPistonBehavior() { + return this.pistonBehavior; + } + + public MapColor getColor() { + return this.color; + } + + static { + AIR = (new Builder(MapColor.CLEAR)).allowsMovement().lightPassesThrough().notSolid().replaceable().build(); + STRUCTURE_VOID = (new Builder(MapColor.CLEAR)).allowsMovement().lightPassesThrough().notSolid().replaceable().build(); + PORTAL = (new Builder(MapColor.CLEAR)).allowsMovement().lightPassesThrough().notSolid().blocksPistons().build(); + CARPET = (new Builder(MapColor.WHITE_GRAY)).allowsMovement().lightPassesThrough().notSolid().burnable().build(); + PLANT = (new Builder(MapColor.DARK_GREEN)).allowsMovement().lightPassesThrough().notSolid().destroyedByPiston().build(); + UNDERWATER_PLANT = (new Builder(MapColor.WATER_BLUE)).allowsMovement().lightPassesThrough().notSolid().destroyedByPiston().build(); + REPLACEABLE_PLANT = (new Builder(MapColor.DARK_GREEN)).allowsMovement().lightPassesThrough().notSolid().destroyedByPiston().replaceable().burnable().build(); + NETHER_SHOOTS = (new Builder(MapColor.DARK_GREEN)).allowsMovement().lightPassesThrough().notSolid().destroyedByPiston().replaceable().build(); + REPLACEABLE_UNDERWATER_PLANT = (new Builder(MapColor.WATER_BLUE)).allowsMovement().lightPassesThrough().notSolid().destroyedByPiston().replaceable().build(); + WATER = (new Builder(MapColor.WATER_BLUE)).allowsMovement().lightPassesThrough().notSolid().destroyedByPiston().replaceable().liquid().build(); + BUBBLE_COLUMN = (new Builder(MapColor.WATER_BLUE)).allowsMovement().lightPassesThrough().notSolid().destroyedByPiston().replaceable().liquid().build(); + LAVA = (new Builder(MapColor.BRIGHT_RED)).allowsMovement().lightPassesThrough().notSolid().destroyedByPiston().replaceable().liquid().build(); + SNOW_LAYER = (new Builder(MapColor.WHITE)).allowsMovement().lightPassesThrough().notSolid().destroyedByPiston().replaceable().build(); + FIRE = (new Builder(MapColor.CLEAR)).allowsMovement().lightPassesThrough().notSolid().destroyedByPiston().replaceable().build(); + DECORATION = (new Builder(MapColor.CLEAR)).allowsMovement().lightPassesThrough().notSolid().destroyedByPiston().build(); + COBWEB = (new Builder(MapColor.WHITE_GRAY)).allowsMovement().lightPassesThrough().destroyedByPiston().build(); + SCULK = (new Builder(MapColor.BLACK)).build(); + REDSTONE_LAMP = (new Builder(MapColor.CLEAR)).build(); + ORGANIC_PRODUCT = (new Builder(MapColor.LIGHT_BLUE_GRAY)).build(); + SOIL = (new Builder(MapColor.DIRT_BROWN)).build(); + SOLID_ORGANIC = (new Builder(MapColor.PALE_GREEN)).build(); + DENSE_ICE = (new Builder(MapColor.PALE_PURPLE)).build(); + AGGREGATE = (new Builder(MapColor.PALE_YELLOW)).build(); + SPONGE = (new Builder(MapColor.YELLOW)).build(); + SHULKER_BOX = (new Builder(MapColor.PURPLE)).build(); + WOOD = (new Builder(MapColor.OAK_TAN)).burnable().build(); + NETHER_WOOD = (new Builder(MapColor.OAK_TAN)).build(); + BAMBOO_SAPLING = (new Builder(MapColor.OAK_TAN)).burnable().destroyedByPiston().allowsMovement().build(); + BAMBOO = (new Builder(MapColor.OAK_TAN)).burnable().destroyedByPiston().build(); + WOOL = (new Builder(MapColor.WHITE_GRAY)).burnable().build(); + TNT = (new Builder(MapColor.BRIGHT_RED)).burnable().lightPassesThrough().build(); + LEAVES = (new Builder(MapColor.DARK_GREEN)).burnable().lightPassesThrough().destroyedByPiston().build(); + GLASS = (new Builder(MapColor.CLEAR)).lightPassesThrough().build(); + ICE = (new Builder(MapColor.PALE_PURPLE)).lightPassesThrough().build(); + CACTUS = (new Builder(MapColor.DARK_GREEN)).lightPassesThrough().destroyedByPiston().build(); + STONE = (new Builder(MapColor.STONE_GRAY)).build(); + METAL = (new Builder(MapColor.IRON_GRAY)).build(); + SNOW_BLOCK = (new Builder(MapColor.WHITE)).build(); + REPAIR_STATION = (new Builder(MapColor.IRON_GRAY)).blocksPistons().build(); + BARRIER = (new Builder(MapColor.CLEAR)).blocksPistons().build(); + PISTON = (new Builder(MapColor.STONE_GRAY)).blocksPistons().build(); + MOSS_BLOCK = (new Builder(MapColor.DARK_GREEN)).destroyedByPiston().build(); + GOURD = (new Builder(MapColor.DARK_GREEN)).destroyedByPiston().build(); + EGG = (new Builder(MapColor.DARK_GREEN)).destroyedByPiston().build(); + CAKE = (new Builder(MapColor.CLEAR)).destroyedByPiston().build(); + AMETHYST = (new Builder(MapColor.PURPLE)).build(); + POWDER_SNOW = (new Builder(MapColor.WHITE)).notSolid().allowsMovement().build(); + } + + public static class Builder { + private PistonBehavior pistonBehavior; + private boolean blocksMovement; + private boolean burnable; + private boolean liquid; + private boolean replaceable; + private boolean solid; + private final MapColor color; + private boolean blocksLight; + + public Builder(MapColor color) { + this.pistonBehavior = PistonBehavior.NORMAL; + this.blocksMovement = true; + this.solid = true; + this.blocksLight = true; + this.color = color; + } + + public Builder liquid() { + this.liquid = true; + return this; + } + + public Builder notSolid() { + this.solid = false; + return this; + } + + public Builder allowsMovement() { + this.blocksMovement = false; + return this; + } + + Builder lightPassesThrough() { + this.blocksLight = false; + return this; + } + + protected Builder burnable() { + this.burnable = true; + return this; + } + + public Builder replaceable() { + this.replaceable = true; + return this; + } + + protected Builder destroyedByPiston() { + this.pistonBehavior = PistonBehavior.DESTROY; + return this; + } + + protected Builder blocksPistons() { + this.pistonBehavior = PistonBehavior.BLOCK; + return this; + } + + public CompatibleMaterial build() { + return new CompatibleMaterial(this.color, this.liquid, this.solid, this.burnable, this.replaceable, this.pistonBehavior); + } + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/block/ExtendBlock.java b/common/src/main/java/net/pitan76/mcpitanlib/api/block/ExtendBlock.java new file mode 100644 index 000000000..d9eb90483 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/block/ExtendBlock.java @@ -0,0 +1,374 @@ +package net.pitan76.mcpitanlib.api.block; + +import com.google.common.collect.ImmutableMap; +import com.mojang.serialization.MapCodec; +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.block.ShapeContext; +import net.minecraft.entity.Entity; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.ai.pathing.NavigationType; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.fluid.FluidState; +import net.minecraft.item.Item; +import net.minecraft.item.ItemPlacementContext; +import net.minecraft.item.ItemStack; +import net.minecraft.item.tooltip.TooltipType; +import net.minecraft.loot.context.LootContextParameterSet; +import net.minecraft.screen.NamedScreenHandlerFactory; +import net.minecraft.screen.ScreenHandler; +import net.minecraft.screen.SimpleNamedScreenHandlerFactory; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.state.StateManager; +import net.minecraft.text.Text; +import net.minecraft.util.ActionResult; +import net.minecraft.util.hit.BlockHitResult; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import net.minecraft.util.math.random.Random; +import net.minecraft.util.shape.VoxelShape; +import net.minecraft.world.BlockView; +import net.minecraft.world.World; +import net.minecraft.world.WorldAccess; +import net.minecraft.world.WorldView; +import net.pitan76.mcpitanlib.api.entity.Player; +import net.pitan76.mcpitanlib.api.event.block.*; +import net.pitan76.mcpitanlib.api.event.block.result.BlockBreakResult; +import net.pitan76.mcpitanlib.api.event.block.StateForNeighborUpdateArgs; +import net.pitan76.mcpitanlib.api.event.item.ItemAppendTooltipEvent; +import net.pitan76.mcpitanlib.api.util.CompatActionResult; +import net.pitan76.mcpitanlib.api.util.TextUtil; +import net.pitan76.mcpitanlib.core.serialization.CompatMapCodec; +import org.jetbrains.annotations.Nullable; + +import java.util.List; +import java.util.function.Function; + +public class ExtendBlock extends Block { + public CompatibleBlockSettings compatSettings; + + public ExtendBlock(Settings settings) { + super(settings); + } + + public ExtendBlock(CompatibleBlockSettings settings) { + super(settings.build()); + this.compatSettings = settings; + } + + /** + * get compatible block settings + * @return CompatibleBlockSettings + */ + public CompatibleBlockSettings getCompatSettings() { + return compatSettings; + } + + /** + * get collision voxel shape + * @param event CollisionShapeEvent + * @return VoxelShape + */ + public VoxelShape getCollisionShape(CollisionShapeEvent event) { + return super.getCollisionShape(event.state, event.world, event.pos, event.context); + } + + @Deprecated + @Override + public VoxelShape getCollisionShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) { + return getCollisionShape(new CollisionShapeEvent(state, world, pos, context)); + } + + /** + * get outline voxel shape + * @param event OutlineShapeEvent + * @return VoxelShape + */ + public VoxelShape getOutlineShape(OutlineShapeEvent event) { + return super.getOutlineShape(event.state, event.world, event.pos, event.context); + } + + @Deprecated + @Override + public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) { + return getOutlineShape(new OutlineShapeEvent(state, world, pos, context)); + } + + /** + * block scheduled tick event + * @param event BlockScheduledTickEvent + */ + public void scheduledTick(BlockScheduledTickEvent event) { + super.scheduledTick(event.state, event.world, event.pos, event.random.getMcRandom()); + } + + @Override + @Deprecated + public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random) { + scheduledTick(new BlockScheduledTickEvent(state, world, pos, random)); + } + + @Override + @Deprecated + protected ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) { + return onRightClick(new BlockUseEvent(state, world, pos, player, player.getActiveHand(), hit)).toActionResult(); + } + + /** + * block right click event + * @param event ActionResultType + * @return BlockUseEvent + */ + public CompatActionResult onRightClick(BlockUseEvent event) { + return CompatActionResult.create(super.onUse(event.state, event.world, event.pos, event.player.getPlayerEntity(), event.hit)); + } + + @Deprecated + @Nullable + @Override + public NamedScreenHandlerFactory createScreenHandlerFactory(BlockState state, World world, BlockPos pos) { + return new SimpleNamedScreenHandlerFactory((syncId, inventory, player) -> + createScreenHandler(new ScreenHandlerCreateEvent(state, world, pos, syncId, inventory, player)), getScreenTitle() + ); + } + + /** + * screen handler create event + * @param event ScreenHandlerCreateEvent + * @return ScreenHandler + */ + @Nullable + public ScreenHandler createScreenHandler(ScreenHandlerCreateEvent event) { + return null; + } + + /** + * get screen title + * @return Text + */ + @Nullable + public Text getScreenTitle() { + return TextUtil.literal(""); + } + + @Override + @Deprecated + public void onPlaced(World world, BlockPos pos, BlockState state, @Nullable LivingEntity placer, ItemStack itemStack) { + onPlaced(new BlockPlacedEvent(world, pos, state, placer, itemStack)); + } + + /** + * block placed event + * @param event BlockPlacedEvent + */ + public void onPlaced(BlockPlacedEvent event) { + super.onPlaced(event.world, event.pos, event.state, event.placer, event.stack); + } + + @Override + @Deprecated + public BlockState onBreak(World world, BlockPos pos, BlockState state, PlayerEntity player) { + return onBreak(new BlockBreakEvent(world, pos, state, player)).state; + } + + /** + * block break event + * @param event BlockBreakEvent + * @return BlockBreakResult + */ + public BlockBreakResult onBreak(BlockBreakEvent event) { + BlockState state = super.onBreak(event.world, event.pos, event.state, event.getPlayerEntity()); + return new BlockBreakResult(state); + } + + @Override + @Deprecated + public ItemStack getPickStack(WorldView world, BlockPos pos, BlockState state) { + return getPickStack(new PickStackEvent(world, pos, state)); + } + + /** + * block pick stack event + * @param event PickStackEvent + * @return ItemStack + */ + public ItemStack getPickStack(PickStackEvent event) { + return super.getPickStack(event.worldView, event.pos, event.state); + } + + @Override + @Deprecated + public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) { + onStateReplaced(new StateReplacedEvent(state, world, pos, newState, moved)); + } + + /** + * block state replaced event + * @param event StateReplacedEvent + */ + public void onStateReplaced(StateReplacedEvent event) { + super.onStateReplaced(event.state, event.world, event.pos, event.newState, event.moved); + } + + @Deprecated + @Override + public List getDroppedStacks(BlockState state, LootContextParameterSet.Builder builder) { + return getDroppedStacks(new DroppedStacksArgs(state, builder)); + } + + /** + * block dropped stacks event + * @param args DroppedStacksArgs + * @return List + */ + public List getDroppedStacks(DroppedStacksArgs args) { + return super.getDroppedStacks(args.state, args.builder); + } + + @Deprecated + @Override + protected void neighborUpdate(BlockState state, World world, BlockPos pos, Block sourceBlock, BlockPos sourcePos, boolean notify) { + neighborUpdate(new NeighborUpdateEvent(state, world, pos, sourceBlock, sourcePos, notify)); + } + + /** + * block neighbor update event + * @param event NeighborUpdateEvent + */ + public void neighborUpdate(NeighborUpdateEvent event) { + super.neighborUpdate(event.state, event.world, event.pos, event.sourceBlock, event.sourcePos, event.notify); + } + + @Deprecated + @Override + public void appendProperties(StateManager.Builder builder) { + appendProperties(new AppendPropertiesArgs(builder)); + } + + /** + * append properties event + * @param args AppendPropertiesArgs + */ + public void appendProperties(AppendPropertiesArgs args) { + super.appendProperties(args.builder); + } + + /** + * Compatible for getDefaultState() + * @return default block state + */ + public BlockState getNewDefaultState() { + return super.getDefaultState(); + } + + /** + * Compatible for setDefaultState() + * @param state BlockState + */ + public void setNewDefaultState(BlockState state) { + super.setDefaultState(state); + } + + @Deprecated + @Override + public @Nullable BlockState getPlacementState(ItemPlacementContext ctx) { + return this.getPlacementState(new PlacementStateArgs(ctx, this)); + } + + /** + * get placement state + * @param args PlacementStateArgs + * @return BlockState + */ + public @Nullable BlockState getPlacementState(PlacementStateArgs args) { + return super.getPlacementState(args.ctx); + } + + @Deprecated + @Override + public void appendTooltip(ItemStack stack, Item.TooltipContext context, List tooltip, TooltipType type) { + appendTooltip(new ItemAppendTooltipEvent(stack, null, tooltip, type, context)); + } + + /** + * append tooltip to item + * @param event ItemAppendTooltipEvent + */ + public void appendTooltip(ItemAppendTooltipEvent event) { + super.appendTooltip(event.stack, event.context, event.tooltip, event.type); + } + + @Deprecated + @Override + public boolean canPathfindThrough(BlockState state, NavigationType type) { + return canPathfindThrough(new CanPathfindThroughArgs(state, type)); + } + + public boolean canPathfindThrough(CanPathfindThroughArgs args) { + return super.canPathfindThrough(args.state, args.type); + } + + @Deprecated + @Override + public void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity) { + onEntityCollision(new EntityCollisionEvent(state, world, pos, entity)); + } + + public void onEntityCollision(EntityCollisionEvent e) { + super.onEntityCollision(e.state, e.world, e.pos, e.entity); + } + + @Deprecated + @Override + public void onBlockBreakStart(BlockState state, World world, BlockPos pos, PlayerEntity player) { + onBlockBreakStart(new BlockBreakStartEvent(state, world, pos, new Player(player))); + } + + public void onBlockBreakStart(BlockBreakStartEvent e) { + super.onBlockBreakStart(e.state, e.world, e.pos, e.player.getPlayerEntity()); + } + + @Deprecated + @Override + protected MapCodec getCodec() { + return getCompatCodec().getCodec(); + } + + public CompatMapCodec getCompatCodec() { + return CompatMapCodec.of(super.getCodec()); + } + + @Deprecated + @Override + protected FluidState getFluidState(BlockState state) { + return getFluidState(new FluidStateArgs(state)); + } + + public FluidState getFluidState(FluidStateArgs args) { + return super.getFluidState(args.getState()); + } + + @Deprecated + @Override + protected BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) { + return getStateForNeighborUpdate(new StateForNeighborUpdateArgs(state, direction, neighborState, world, pos, neighborPos)); + } + + public BlockState getStateForNeighborUpdate(StateForNeighborUpdateArgs args) { + return super.getStateForNeighborUpdate(args.state, args.direction, args.neighborState, args.world, args.pos, args.neighborPos); + } + + @Deprecated + @Override + protected ImmutableMap getShapesForStates(Function stateToShape) { + return getShapesForStates(new ShapesForStatesArgs(stateToShape)); + } + + public ImmutableMap getShapesForStates(ShapesForStatesArgs args) { + return super.getShapesForStates(args.stateToShape); + } + + public StateManager callGetStateManager() { + return super.getStateManager(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/block/ExtendBlockEntityProvider.java b/common/src/main/java/net/pitan76/mcpitanlib/api/block/ExtendBlockEntityProvider.java new file mode 100644 index 000000000..2b9481a95 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/block/ExtendBlockEntityProvider.java @@ -0,0 +1,79 @@ +package net.pitan76.mcpitanlib.api.block; + +import net.minecraft.block.BlockEntityProvider; +import net.minecraft.block.BlockState; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.block.entity.BlockEntityTicker; +import net.minecraft.block.entity.BlockEntityType; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.event.block.TileCreateEvent; +import net.pitan76.mcpitanlib.api.tile.ExtendBlockEntityTicker; +import org.jetbrains.annotations.Nullable; + +public interface ExtendBlockEntityProvider extends BlockEntityProvider { + + /** + * @deprecated Use {@link #createBlockEntity(TileCreateEvent)} instead. + */ + @Deprecated + @Nullable + default BlockEntity createBlockEntity(BlockPos pos, BlockState state) { + return createBlockEntity(new TileCreateEvent(pos, state)); + } + + /** + * create instance of BlockEntity + * @param event TileCreateEvent + * @return BlockEntity + * + *
{@code
+     * public BlockEntity createBlockEntity(TileCreateEvent e) {
+     *    return new ExampleBlockEntity(e); // ExampleBlockEntity extends CompatBlockEntity
+     * }
+ */ + @Nullable + default BlockEntity createBlockEntity(TileCreateEvent event) { + if (getBlockEntityType() == null) return null; + + // return new ...BlockEntity(pos, state) + return getBlockEntityType().instantiate(event.getBlockPos(), event.getBlockState()); + } + + @Nullable + default BlockEntityType getBlockEntityType() { + return null; + } + + @Nullable + @Override + default BlockEntityTicker getTicker(World world, BlockState state, BlockEntityType type) { + if (isTick()) { + return ((world1, pos, state1, blockEntity) -> { + if (getBlockEntityType() == null || blockEntity == getBlockEntityType().get(world, pos)) { + if (blockEntity instanceof ExtendBlockEntityTicker) { + ExtendBlockEntityTicker ticker = (ExtendBlockEntityTicker) blockEntity; + ticker.tick(world, pos, state, blockEntity); + } else if (blockEntity instanceof BlockEntityTicker) { + BlockEntityTicker ticker = (BlockEntityTicker) blockEntity; + ticker.tick(world, pos, state, blockEntity); + } + } + }); + } + return BlockEntityProvider.super.getTicker(world, state, type); + } + + @Nullable + default ExtendBlockEntityTicker getCompatibleTicker(World world, BlockState state, BlockEntityType type) { + BlockEntityTicker ticker = getTicker(world, state, type); + if (ticker instanceof ExtendBlockEntityTicker) + return (ExtendBlockEntityTicker) ticker; + + return null; + } + + default boolean isTick() { + return false; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/block/ExtendBlockProvider.java b/common/src/main/java/net/pitan76/mcpitanlib/api/block/ExtendBlockProvider.java new file mode 100644 index 000000000..996661e2f --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/block/ExtendBlockProvider.java @@ -0,0 +1,161 @@ +package net.pitan76.mcpitanlib.api.block; + +import net.minecraft.block.BlockState; +import net.minecraft.item.ItemStack; +import net.minecraft.screen.ScreenHandler; +import net.minecraft.text.Text; +import net.minecraft.util.shape.VoxelShape; +import net.pitan76.mcpitanlib.api.event.block.*; +import net.pitan76.mcpitanlib.api.event.block.result.BlockBreakResult; +import net.pitan76.mcpitanlib.api.event.item.ItemAppendTooltipEvent; +import net.pitan76.mcpitanlib.api.util.CompatActionResult; +import net.pitan76.mcpitanlib.api.util.TextUtil; + +import java.util.List; + +public interface ExtendBlockProvider { + + /** + * get collision voxel shape + * @param event CollisionShapeEvent + * @param options Options + * @return VoxelShape + */ + default VoxelShape getCollisionShape(CollisionShapeEvent event, Options options) { + options.cancel = false; + return null; + } + + /** + * get outline voxel shape + * @param event OutlineShapeEvent + * @param options Options + * @return VoxelShape + */ + default VoxelShape getOutlineShape(OutlineShapeEvent event, Options options) { + options.cancel = false; + return null; + } + + /** + * block scheduled tick event + * @param event BlockScheduledTickEvent + * @param options Options + */ + default void scheduledTick(BlockScheduledTickEvent event, Options options) { + options.cancel = false; + } + + /** + * block right click event + * @param event BlockUseEvent + * @param options Options + * @return ActionResult + */ + default CompatActionResult onRightClick(BlockUseEvent event, Options options) { + options.cancel = false; + return null; + } + + /** + * screen handler create event + * @param event ScreenHandlerCreateEvent + * @param options Options + * @return ScreenHandler + */ + default ScreenHandler createScreenHandler(ScreenHandlerCreateEvent event, Options options) { + options.cancel = false; + return null; + } + + /** + * get screen title + * @return Text + */ + default Text getScreenTitle() { + return TextUtil.literal(""); + } + + /** + * block placed event + * @param event BlockPlacedEvent + * @param options Options + */ + default void onPlaced(BlockPlacedEvent event, Options options) { + options.cancel = false; + } + + /** + * block break event + * @param event BlockBreakEvent + * @param options Options + * @return BlockBreakResult + */ + default BlockBreakResult onBreak(BlockBreakEvent event, Options options) { + options.cancel = false; + return null; + } + + /** + * block state replaced event + * @param event StateReplacedEvent + * @param options Options + */ + default void onStateReplaced(StateReplacedEvent event, Options options) { + options.cancel = false; + } + + /** + * get pick stack + * @param event PickStackEvent + * @param options Options + * @return ItemStack + */ + default ItemStack getPickStack(PickStackEvent event, Options options) { + options.cancel = false; + return null; + } + + /** + * get placement state + * @param args PlacementStateArgs + * @param options Options + */ + default BlockState getPlacementState(PlacementStateArgs args, Options options) { + options.cancel = false; + return null; + } + + /** + * append properties + * @param args AppendPropertiesArgs + * @param options Options + */ + default void appendProperties(AppendPropertiesArgs args, Options options) { + options.cancel = false; + } + + /** + * get dropped stacks + * @param args DroppedStacksArgs + * @param options Options + * @return List + */ + default List getDroppedStacks(DroppedStacksArgs args, Options options) { + options.cancel = false; + return null; + } + + default void appendTooltip(ItemAppendTooltipEvent event, Options options) { + options.cancel = false; + } + + default Boolean canPathfindThrough(CanPathfindThroughArgs args, Options options) { + options.cancel = false; + return null; + } + + public static class Options { + public boolean cancel = true; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/block/args/RenderTypeArgs.java b/common/src/main/java/net/pitan76/mcpitanlib/api/block/args/RenderTypeArgs.java new file mode 100644 index 000000000..645b17745 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/block/args/RenderTypeArgs.java @@ -0,0 +1,21 @@ +package net.pitan76.mcpitanlib.api.block.args; + +import net.minecraft.block.BlockState; +import net.pitan76.mcpitanlib.midohra.holder.BlockStatePropertyHolder; + +public class RenderTypeArgs implements BlockStatePropertyHolder { + public BlockState state; + + public RenderTypeArgs(BlockState state) { + this.state = state; + } + + public BlockState getRawBlockState() { + return state; + } + + @Override + public net.pitan76.mcpitanlib.midohra.block.BlockState getBlockState() { + return net.pitan76.mcpitanlib.midohra.block.BlockState.of(getRawBlockState()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/block/args/RotateArgs.java b/common/src/main/java/net/pitan76/mcpitanlib/api/block/args/RotateArgs.java new file mode 100644 index 000000000..0b4e6339e --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/block/args/RotateArgs.java @@ -0,0 +1,38 @@ +package net.pitan76.mcpitanlib.api.block.args; + +import net.minecraft.block.BlockState; +import net.minecraft.util.BlockRotation; +import net.minecraft.util.math.Direction; +import net.pitan76.mcpitanlib.midohra.holder.BlockStatePropertyHolder; + +public class RotateArgs implements BlockStatePropertyHolder { + + public BlockState state; + public BlockRotation rotation; + + public RotateArgs(BlockState state, BlockRotation rotation) { + this.state = state; + this.rotation = rotation; + } + + public BlockState getRawBlockState() { + return state; + } + + public BlockRotation getRawRotation() { + return rotation; + } + + @Override + public net.pitan76.mcpitanlib.midohra.block.BlockState getBlockState() { + return net.pitan76.mcpitanlib.midohra.block.BlockState.of(state); + } + + public Direction rotate(Direction direction) { + return rotation.rotate(direction); + } + + public net.pitan76.mcpitanlib.midohra.util.math.Direction rotate(net.pitan76.mcpitanlib.midohra.util.math.Direction direction) { + return net.pitan76.mcpitanlib.midohra.util.math.Direction.of(rotation.rotate(direction.toMinecraft())); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/block/args/SideInvisibleArgs.java b/common/src/main/java/net/pitan76/mcpitanlib/api/block/args/SideInvisibleArgs.java new file mode 100644 index 000000000..503136183 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/block/args/SideInvisibleArgs.java @@ -0,0 +1,46 @@ +package net.pitan76.mcpitanlib.api.block.args; + +import net.minecraft.block.BlockState; +import net.minecraft.util.math.Direction; + +public class SideInvisibleArgs { + public BlockState state; + public BlockState stateFrom; + public Direction direction; + + public SideInvisibleArgs(BlockState state, BlockState stateFrom, Direction direction) { + this.state = state; + this.stateFrom = stateFrom; + this.direction = direction; + } + + public SideInvisibleArgs(net.pitan76.mcpitanlib.midohra.block.BlockState state, net.pitan76.mcpitanlib.midohra.block.BlockState stateFrom, net.pitan76.mcpitanlib.midohra.util.math.Direction direction) { + this.state = state.toMinecraft(); + this.stateFrom = stateFrom.toMinecraft(); + this.direction = direction.toMinecraft(); + } + + public BlockState getState() { + return state; + } + + public BlockState getStateFrom() { + return stateFrom; + } + + public Direction getDirection() { + return direction; + } + + public net.pitan76.mcpitanlib.midohra.block.BlockState getMidohraState() { + return net.pitan76.mcpitanlib.midohra.block.BlockState.of(getState()); + } + + public net.pitan76.mcpitanlib.midohra.block.BlockState getMidohraStateFrom() { + return net.pitan76.mcpitanlib.midohra.block.BlockState.of(getStateFrom()); + } + + public net.pitan76.mcpitanlib.midohra.util.math.Direction getMidohraDirection() { + return net.pitan76.mcpitanlib.midohra.util.math.Direction.of(getDirection()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/block/args/v2/CanPlaceAtArgs.java b/common/src/main/java/net/pitan76/mcpitanlib/api/block/args/v2/CanPlaceAtArgs.java new file mode 100644 index 000000000..c111c0aa3 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/block/args/v2/CanPlaceAtArgs.java @@ -0,0 +1,54 @@ +package net.pitan76.mcpitanlib.api.block.args.v2; + +import net.pitan76.mcpitanlib.api.event.BaseEvent; +import net.pitan76.mcpitanlib.midohra.block.BlockState; +import net.pitan76.mcpitanlib.midohra.util.math.BlockPos; +import net.pitan76.mcpitanlib.midohra.world.WorldView; + +public class CanPlaceAtArgs extends BaseEvent { + public final net.minecraft.block.BlockState state; + public final net.minecraft.world.WorldView world; + public final net.minecraft.util.math.BlockPos pos; + + public CanPlaceAtArgs(net.minecraft.block.BlockState state, net.minecraft.world.WorldView world, net.minecraft.util.math.BlockPos pos) { + this.state = state; + this.world = world; + this.pos = pos; + } + + public CanPlaceAtArgs(BlockState state, WorldView world, BlockPos pos) { + this(state.toMinecraft(), world.toMinecraft(), pos.toMinecraft()); + } + + public net.minecraft.block.BlockState getState() { + return state; + } + + public net.minecraft.world.WorldView getWorld() { + return world; + } + + public net.minecraft.util.math.BlockPos getPos() { + return pos; + } + + public BlockState getMidohraState() { + return BlockState.of(state); + } + + public WorldView getMidohraWorld() { + return WorldView.of(world); + } + + public BlockPos getMidohraPos() { + return BlockPos.of(pos); + } + + public boolean isClient() { + return world.isClient(); + } + + public boolean isServer() { + return !world.isClient(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/block/args/v2/CollisionShapeEvent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/block/args/v2/CollisionShapeEvent.java new file mode 100644 index 000000000..a5544b4db --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/block/args/v2/CollisionShapeEvent.java @@ -0,0 +1,17 @@ +package net.pitan76.mcpitanlib.api.block.args.v2; + +import net.minecraft.block.ShapeContext; +import net.pitan76.mcpitanlib.midohra.block.BlockState; +import net.pitan76.mcpitanlib.midohra.util.math.BlockPos; +import net.pitan76.mcpitanlib.midohra.world.BlockView; + +public class CollisionShapeEvent extends OutlineShapeEvent { + + public CollisionShapeEvent(BlockState state, BlockView world, BlockPos pos, ShapeContext context) { + super(state, world, pos, context); + } + + public CollisionShapeEvent(net.minecraft.block.BlockState state, net.minecraft.world.BlockView world, net.minecraft.util.math.BlockPos pos, ShapeContext context) { + super(BlockState.of(state), BlockView.of(world), BlockPos.of(pos), context); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/block/args/v2/GetComparatorOutputArgs.java b/common/src/main/java/net/pitan76/mcpitanlib/api/block/args/v2/GetComparatorOutputArgs.java new file mode 100644 index 000000000..2fc46d19f --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/block/args/v2/GetComparatorOutputArgs.java @@ -0,0 +1,53 @@ +package net.pitan76.mcpitanlib.api.block.args.v2; + +import net.minecraft.block.BlockState; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.event.BaseEvent; +import net.pitan76.mcpitanlib.api.util.WorldUtil; +import net.pitan76.mcpitanlib.api.util.screen.ScreenHandlerUtil; + +public class GetComparatorOutputArgs extends BaseEvent { + public BlockState state; + public World world; + public BlockPos pos; + + public GetComparatorOutputArgs(BlockState state, World world, BlockPos pos) { + this.state = state; + this.world = world; + this.pos = pos; + } + + public BlockState getState() { + return state; + } + + public World getWorld() { + return world; + } + + public BlockPos getPos() { + return pos; + } + + public BlockEntity getBlockEntity() { + return WorldUtil.getBlockEntity(world, pos); + } + + public int calcComparatorOutputFromBlockEntity() { + return ScreenHandlerUtil.calcComparatorOutput(getBlockEntity()); + } + + public net.pitan76.mcpitanlib.midohra.block.BlockState getMidohraState() { + return net.pitan76.mcpitanlib.midohra.block.BlockState.of(state); + } + + public net.pitan76.mcpitanlib.midohra.world.World getMidohraWorld() { + return net.pitan76.mcpitanlib.midohra.world.World.of(world); + } + + public net.pitan76.mcpitanlib.midohra.util.math.BlockPos getMidohraPos() { + return net.pitan76.mcpitanlib.midohra.util.math.BlockPos.of(pos); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/block/args/v2/HasComparatorOutputArgs.java b/common/src/main/java/net/pitan76/mcpitanlib/api/block/args/v2/HasComparatorOutputArgs.java new file mode 100644 index 000000000..2fe77f18a --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/block/args/v2/HasComparatorOutputArgs.java @@ -0,0 +1,16 @@ +package net.pitan76.mcpitanlib.api.block.args.v2; + +import net.minecraft.block.BlockState; +import net.pitan76.mcpitanlib.api.event.BaseEvent; + +public class HasComparatorOutputArgs extends BaseEvent { + public BlockState state; + + public HasComparatorOutputArgs(BlockState state) { + this.state = state; + } + + public BlockState getState() { + return state; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/block/args/v2/OutlineShapeEvent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/block/args/v2/OutlineShapeEvent.java new file mode 100644 index 000000000..225949458 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/block/args/v2/OutlineShapeEvent.java @@ -0,0 +1,64 @@ +package net.pitan76.mcpitanlib.api.block.args.v2; + +import net.minecraft.block.ShapeContext; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.item.Item; +import net.pitan76.mcpitanlib.api.event.BaseEvent; +import net.pitan76.mcpitanlib.midohra.block.entity.BlockEntityWrapper; +import net.pitan76.mcpitanlib.midohra.holder.BlockStatePropertyHolder; +import net.pitan76.mcpitanlib.midohra.block.BlockState; +import net.pitan76.mcpitanlib.midohra.item.ItemWrapper; +import net.pitan76.mcpitanlib.midohra.util.math.BlockPos; +import net.pitan76.mcpitanlib.midohra.world.BlockView; +import net.pitan76.mcpitanlib.midohra.world.IWorldView; + +public class OutlineShapeEvent extends BaseEvent implements BlockStatePropertyHolder { + public BlockState state; + public BlockView world; + public BlockPos pos; + public ShapeContext context; + + public OutlineShapeEvent(BlockState state, BlockView world, BlockPos pos, ShapeContext context) { + this.state = state; + this.world = world; + this.pos = pos; + this.context = context; + } + + public OutlineShapeEvent(net.minecraft.block.BlockState state, net.minecraft.world.BlockView world, net.minecraft.util.math.BlockPos pos, net.minecraft.block.ShapeContext context) { + this(BlockState.of(state), BlockView.of(world), BlockPos.of(pos), context); + } + + @Override + public BlockState getBlockState() { + return state; + } + + public BlockEntityWrapper getBlockEntity() { + return world.getBlockEntity(pos); + } + + public BlockEntity getRawBlockEntity() { + return getBlockEntity().get(); + } + + public IWorldView getWorldView() { + return world; + } + + public BlockPos getPos() { + return pos; + } + + public ShapeContext getContext() { + return context; + } + + public boolean isHolding(Item item) { + return getContext().isHolding(item); + } + + public boolean isHolding(ItemWrapper item) { + return isHolding(item.get()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/block/args/v2/PlacementStateArgs.java b/common/src/main/java/net/pitan76/mcpitanlib/api/block/args/v2/PlacementStateArgs.java new file mode 100644 index 000000000..ebc3d207b --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/block/args/v2/PlacementStateArgs.java @@ -0,0 +1,175 @@ +package net.pitan76.mcpitanlib.api.block.args.v2; + +import net.minecraft.block.Block; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.item.ItemPlacementContext; +import net.minecraft.state.property.Property; +import net.minecraft.util.Hand; +import net.minecraft.util.hit.BlockHitResult; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Vec3d; +import net.pitan76.mcpitanlib.api.entity.Player; +import net.pitan76.mcpitanlib.api.event.BaseEvent; +import net.pitan76.mcpitanlib.api.event.item.ItemUseOnBlockEvent; +import net.pitan76.mcpitanlib.api.util.BlockStateUtil; +import net.pitan76.mcpitanlib.midohra.holder.BlockStatePropertyHolder; +import net.pitan76.mcpitanlib.midohra.block.BlockState; +import net.pitan76.mcpitanlib.midohra.block.BlockWrapper; +import net.pitan76.mcpitanlib.midohra.block.entity.BlockEntityWrapper; +import net.pitan76.mcpitanlib.midohra.util.hit.HitResultType; +import net.pitan76.mcpitanlib.midohra.util.math.Direction; +import net.pitan76.mcpitanlib.midohra.world.IWorldView; +import net.pitan76.mcpitanlib.midohra.world.World; +import net.pitan76.mcpitanlib.mixin.ItemUsageContextMixin; +import org.jetbrains.annotations.Nullable; + +public class PlacementStateArgs extends BaseEvent implements BlockStatePropertyHolder { + public ItemPlacementContext ctx; + + @Nullable + public Block block; + + public PlacementStateArgs(ItemPlacementContext ctx) { + this.ctx = ctx; + } + + public PlacementStateArgs(ItemPlacementContext ctx, @Nullable Block block) { + this.ctx = ctx; + this.block = block; + } + + public boolean canPlace() { + return ctx.canPlace(); + } + + public BlockPos getRawPos() { + return ctx.getBlockPos(); + } + + public net.pitan76.mcpitanlib.midohra.util.math.BlockPos getPos() { + return net.pitan76.mcpitanlib.midohra.util.math.BlockPos.of(getRawPos()); + } + + public Player getPlayer() { + return new Player(ctx.getPlayer()); + } + + public Direction[] getPlacementDirections() { + net.minecraft.util.math.Direction[] rawDirs = getRawPlacementDirections(); + Direction[] directions = new Direction[rawDirs.length]; + for (int i = 0; i < directions.length; i++) { + directions[i] = Direction.of(rawDirs[i]); + } + + return directions; + } + + public net.minecraft.util.math.Direction[] getRawPlacementDirections() { + return ctx.getPlacementDirections(); + } + + public Hand getHand() { + return ctx.getHand(); + } + + public Direction getSide() { + return Direction.of(getRawSide()); + } + + public net.minecraft.util.math.Direction getRawSide() { + return ctx.getSide(); + } + + public Direction getHorizontalPlayerFacing() { + return Direction.of(getRawHorizontalPlayerFacing()); + } + + public net.minecraft.util.math.Direction getRawHorizontalPlayerFacing() { + return ctx.getHorizontalPlayerFacing(); + } + + public float getPlayerYaw() { + return ctx.getPlayerYaw(); + } + + public World getWorld() { + return World.of(ctx.getWorld()); + } + + public IWorldView getWorldView() { + return getWorld(); + } + + public boolean isClient() { + return getWorld().isClient(); + } + + public Vec3d getHitPos() { + return ctx.getHitPos(); + } + + public boolean canReplaceExisting() { + return ctx.canReplaceExisting(); + } + + @Deprecated + public ItemUsageContextMixin getIUCAccessor() { + return (ItemUsageContextMixin) ctx; + } + + public BlockHitResult getHitResult() { + return getIUCAccessor().getHit(); + } + + public ItemUseOnBlockEvent toItemUseOnBlockEvent() { + return new ItemUseOnBlockEvent(getWorld().getRaw(), getPlayer().getPlayerEntity(), getHand(), ctx.getStack(), getHitResult()); + } + + public ItemPlacementContext getCtx() { + return ctx; + } + + public @Nullable Block getRawBlock() { + return block; + } + + public boolean isBlockExist() { + return block != null; + } + + public net.minecraft.block.BlockState getRawBlockState() { + return BlockStateUtil.getDefaultState(block); + } + + public BlockEntity getRawBlockEntity() { + return getWorld().getBlockEntity(getRawPos()); + } + + public BlockWrapper getBlock() { + return BlockWrapper.of(block); + } + + public , V extends T> net.minecraft.block.BlockState with(Property property, V value) { + if (block == null) + return null; + + return BlockStateUtil.with(BlockStateUtil.getDefaultState(block), property, value); + } + + @Override + public BlockState getBlockState() { + return BlockState.of(getRawBlockState()); + } + + public BlockEntityWrapper getBlockEntity() { + return getWorld().getBlockEntity(getPos()); + } + + public net.pitan76.mcpitanlib.midohra.util.hit.BlockHitResult getHitResultM() { + return net.pitan76.mcpitanlib.midohra.util.hit.BlockHitResult.of(getHitResult()); + } + + public HitResultType getHitResultTypeM() { + return HitResultType.from(getHitResult().getType()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/block/args/v2/StateForNeighborUpdateArgs.java b/common/src/main/java/net/pitan76/mcpitanlib/api/block/args/v2/StateForNeighborUpdateArgs.java new file mode 100644 index 000000000..c6d7a6845 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/block/args/v2/StateForNeighborUpdateArgs.java @@ -0,0 +1,97 @@ +package net.pitan76.mcpitanlib.api.block.args.v2; + +import net.minecraft.block.BlockState; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import net.minecraft.world.WorldAccess; +import net.minecraft.world.WorldView; +import net.pitan76.mcpitanlib.api.util.math.random.CompatRandom; +import net.pitan76.mcpitanlib.midohra.block.entity.BlockEntityWrapper; +import net.pitan76.mcpitanlib.midohra.holder.BlockStatePropertyHolder; +import net.pitan76.mcpitanlib.midohra.world.IWorldView; + +public class StateForNeighborUpdateArgs implements BlockStatePropertyHolder { + public BlockState state; + public Direction direction; + public BlockState neighborState; + public WorldAccess world; + public BlockPos pos; + public BlockPos neighborPos; + public CompatRandom random; + + public StateForNeighborUpdateArgs(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) { + this.state = state; + this.direction = direction; + this.neighborState = neighborState; + this.world = world; + this.pos = pos; + this.neighborPos = neighborPos; + this.random = new CompatRandom(world.getRandom()); + } + + public Direction getDirection() { + return direction; + } + + public BlockState getRawNeighborState() { + return neighborState; + } + + public WorldView getRawWorld() { + return world; + } + + public BlockPos getRawPos() { + return pos; + } + + public BlockPos getRawNeighborPos() { + return neighborPos; + } + + public net.pitan76.mcpitanlib.midohra.block.BlockState getNeighborState() { + return net.pitan76.mcpitanlib.midohra.block.BlockState.of(getRawNeighborState()); + } + + public net.pitan76.mcpitanlib.midohra.world.WorldView getWorld() { + return net.pitan76.mcpitanlib.midohra.world.WorldView.of(getRawWorld()); + } + + public IWorldView getWorldView() { + return getWorld(); + } + + public net.pitan76.mcpitanlib.midohra.util.math.BlockPos getPos() { + return net.pitan76.mcpitanlib.midohra.util.math.BlockPos.of(getRawPos()); + } + + public net.pitan76.mcpitanlib.midohra.util.math.BlockPos getNeighborPos() { + return net.pitan76.mcpitanlib.midohra.util.math.BlockPos.of(getRawNeighborPos()); + } + + public CompatRandom getRandom() { + return random; + } + + public net.pitan76.mcpitanlib.midohra.world.tick.ScheduledTickView getTickView() { + return net.pitan76.mcpitanlib.midohra.world.tick.ScheduledTickView.of(world); + } + + @Override + public net.pitan76.mcpitanlib.midohra.block.BlockState getBlockState() { + return net.pitan76.mcpitanlib.midohra.block.BlockState.of(state); + } + + public BlockEntityWrapper getBlockEntity() { + return getWorld().getBlockEntity(getPos()); + } + + public BlockEntity getRawBlockEntity() { + return world.getBlockEntity(pos); + } + + public boolean isClient() { + return world.isClient(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/block/v2/BlockSettingsBuilder.java b/common/src/main/java/net/pitan76/mcpitanlib/api/block/v2/BlockSettingsBuilder.java new file mode 100644 index 000000000..95b2afca6 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/block/v2/BlockSettingsBuilder.java @@ -0,0 +1,170 @@ +package net.pitan76.mcpitanlib.api.block.v2; + +import net.minecraft.block.AbstractBlock; +import net.pitan76.mcpitanlib.api.block.CompatibleMaterial; +import net.pitan76.mcpitanlib.api.sound.CompatBlockSoundGroup; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.api.util.color.CompatDyeColor; +import net.pitan76.mcpitanlib.api.util.color.CompatMapColor; +import net.pitan76.mcpitanlib.midohra.block.BlockState; +import net.pitan76.mcpitanlib.midohra.block.BlockWrapper; + +import java.util.function.ToIntFunction; + +public class BlockSettingsBuilder { + + public CompatIdentifier id; + public float hardness = -1; + public float resistance = -1; + public CompatBlockSoundGroup blockSoundGroup; + public CompatibleMaterial material; + public CompatMapColor mapColor; + public CompatDyeColor dyeColor; + public boolean requiresTool; + public boolean dropsNothing; + public ToIntFunction luminance; + + protected BlockWrapper copyFromBlock = null; + + public BlockSettingsBuilder(CompatIdentifier id) { + this.id = id; + } + + public BlockSettingsBuilder() { + + } + + public BlockSettingsBuilder hardness(float hardness) { + this.hardness = hardness; + return this; + } + + public BlockSettingsBuilder resistance(float resistance) { + this.resistance = resistance; + return this; + } + + public BlockSettingsBuilder strength(float hardness, float resistance) { + this.hardness = hardness; + this.resistance = resistance; + return this; + } + + public BlockSettingsBuilder sounds(CompatBlockSoundGroup blockSoundGroup) { + this.blockSoundGroup = blockSoundGroup; + return this; + } + + public BlockSettingsBuilder material(CompatibleMaterial material) { + this.material = material; + return this; + } + + public BlockSettingsBuilder mapColor(CompatMapColor mapColor) { + this.mapColor = mapColor; + return this; + } + + public BlockSettingsBuilder dyeColor(CompatDyeColor dyeColor) { + this.dyeColor = dyeColor; + return this; + } + + public BlockSettingsBuilder requiresTool() { + this.requiresTool = true; + return this; + } + + public BlockSettingsBuilder dropsNothing() { + this.dropsNothing = true; + return this; + } + + public BlockSettingsBuilder luminance(ToIntFunction luminance) { + this.luminance = luminance; + return this; + } + + public CompatibleBlockSettings build() { + return build(id); + } + + public AbstractBlock.Settings _build() { + return build().build(); + } + + public CompatibleBlockSettings build(CompatIdentifier id) { + CompatibleBlockSettings settings; + + if (copyFromBlock != null) { + settings = CompatibleBlockSettings.copy(id, copyFromBlock.get()); + } else { + settings = CompatibleBlockSettings.of(id); + } + + if (material != null) + settings = CompatibleBlockSettings.of(id, material); + + if (mapColor != null) { + settings = settings.mapColor(mapColor.getColor()); + } else if (dyeColor != null) { + settings = settings.mapColor(dyeColor.getColor().getMapColor()); + } + + if (requiresTool) settings.requiresTool(); + if (dropsNothing) settings.dropsNothing(); + if (luminance != null) settings.luminance((state) -> luminance.applyAsInt(BlockState.of(state))); + + if (hardness != -1 && resistance != -1) settings.strength(hardness, resistance); + else if (hardness != -1) settings.strength(hardness); + + if (blockSoundGroup != null) settings.sounds(blockSoundGroup); + + return settings; + } + + public AbstractBlock.Settings _build(CompatIdentifier id) { + return build(id).build(); + } + + public BlockSettingsBuilder copy(CompatIdentifier id) { + BlockSettingsBuilder builder = new BlockSettingsBuilder(); + + builder.copyFromBlock = this.copyFromBlock; + + builder.id = id; + builder.hardness = this.hardness; + builder.resistance = this.resistance; + builder.blockSoundGroup = this.blockSoundGroup; + builder.material = this.material; + builder.mapColor = this.mapColor; + builder.dyeColor = this.dyeColor; + builder.requiresTool = this.requiresTool; + builder.dropsNothing = this.dropsNothing; + builder.luminance = this.luminance; + return builder; + } + + public BlockSettingsBuilder copy() { + return copy(this.id); + } + + public static BlockSettingsBuilder of(CompatIdentifier id) { + return new BlockSettingsBuilder(id); + } + + public static BlockSettingsBuilder of() { + return new BlockSettingsBuilder(); + } + + public static BlockSettingsBuilder copyBlock(BlockWrapper block) { + BlockSettingsBuilder builder = new BlockSettingsBuilder(block.getId()); + builder.copyFromBlock = block; + + return builder; + } + + public static BlockSettingsBuilder copyBlock(CompatIdentifier id) { + return copyBlock(BlockWrapper.of(id)); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/block/v2/CompatBlock.java b/common/src/main/java/net/pitan76/mcpitanlib/api/block/v2/CompatBlock.java new file mode 100644 index 000000000..ffbf00cc3 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/block/v2/CompatBlock.java @@ -0,0 +1,177 @@ +package net.pitan76.mcpitanlib.api.block.v2; + +import net.minecraft.block.BlockRenderType; +import net.minecraft.block.BlockState; +import net.minecraft.block.ShapeContext; +import net.minecraft.item.ItemPlacementContext; +import net.minecraft.util.BlockRotation; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import net.minecraft.util.shape.VoxelShape; +import net.minecraft.world.BlockView; +import net.minecraft.world.World; +import net.minecraft.world.WorldAccess; +import net.minecraft.world.WorldView; +import net.pitan76.mcpitanlib.api.block.CompatBlockRenderType; +import net.pitan76.mcpitanlib.api.block.ExtendBlock; +import net.pitan76.mcpitanlib.api.block.args.RenderTypeArgs; +import net.pitan76.mcpitanlib.api.block.args.RotateArgs; +import net.pitan76.mcpitanlib.api.block.args.SideInvisibleArgs; +import net.pitan76.mcpitanlib.api.block.args.v2.*; +import net.pitan76.mcpitanlib.midohra.block.BlockWrapper; +import org.jetbrains.annotations.Nullable; + +public class CompatBlock extends ExtendBlock { + + public CompatibleBlockSettings settings; + + public CompatBlock(CompatibleBlockSettings settings) { + super(settings); + this.settings = settings; + } + + public CompatibleBlockSettings getCompatSettings() { + return settings; + } + + public BlockWrapper getWrapper() { + return BlockWrapper.of(this); + } + + @Override + @Deprecated + protected BlockRenderType getRenderType(BlockState state) { + return getRenderType(new RenderTypeArgs(state)).renderType; + } + + public CompatBlockRenderType getRenderType(RenderTypeArgs args) { + return new CompatBlockRenderType(super.getRenderType(args.state)); + } + + @Override + @Deprecated + protected BlockState rotate(BlockState state, BlockRotation rotation) { + return rotate(new RotateArgs(state, rotation)).toMinecraft(); + } + + public net.pitan76.mcpitanlib.midohra.block.BlockState rotate(RotateArgs args) { + return net.pitan76.mcpitanlib.midohra.block.BlockState.of(super.rotate(args.state, args.rotation)); + } + + @Override + @Deprecated + protected boolean isSideInvisible(BlockState state, BlockState stateFrom, Direction direction) { + return isSideInvisible(new SideInvisibleArgs(state, stateFrom, direction)); + } + + public boolean isSideInvisible(SideInvisibleArgs args) { + return super.isSideInvisible(args.state, args.stateFrom, args.direction); + } + + /** + * Compatible for getDefaultState() + * @return default block state + */ + public net.pitan76.mcpitanlib.midohra.block.BlockState getDefaultMidohraState() { + return net.pitan76.mcpitanlib.midohra.block.BlockState.of(getNewDefaultState()); + } + + /** + * Compatible for setDefaultState() + * @param state BlockState + */ + public void setDefaultState(net.pitan76.mcpitanlib.midohra.block.BlockState state) { + setNewDefaultState(state.toMinecraft()); + } + + public @Nullable net.pitan76.mcpitanlib.midohra.block.BlockState getPlacementState(PlacementStateArgs args) { + return net.pitan76.mcpitanlib.midohra.block.BlockState.of(super.getPlacementState(args.ctx)); + } + + @Override + public @Nullable BlockState getPlacementState(ItemPlacementContext ctx) { + return getPlacementState(new PlacementStateArgs(ctx)).toMinecraft(); + } + + @Deprecated + @Override + public @Nullable BlockState getPlacementState(net.pitan76.mcpitanlib.api.event.block.PlacementStateArgs args) { + return super.getPlacementState(args); + } + + public net.pitan76.mcpitanlib.midohra.block.BlockState getStateForNeighborUpdate(StateForNeighborUpdateArgs args) { + return net.pitan76.mcpitanlib.midohra.block.BlockState.of(super.getStateForNeighborUpdate(args.state, args.direction, args.neighborState, args.world, args.pos, args.neighborPos)); + } + + @Override + protected BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) { + return getStateForNeighborUpdate(new StateForNeighborUpdateArgs(state, direction, neighborState, world, pos, neighborPos)).toMinecraft(); + } + + @Deprecated + @Override + public BlockState getStateForNeighborUpdate(net.pitan76.mcpitanlib.api.event.block.StateForNeighborUpdateArgs args) { + return super.getStateForNeighborUpdate((args)); + } + + public VoxelShape getOutlineShape(OutlineShapeEvent e) { + return super.getOutlineShape(e.state.toMinecraft(), e.world.getRaw(), e.pos.toMinecraft(), e.context); + } + + @Override + public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) { + return getOutlineShape(new OutlineShapeEvent(state, world, pos, context)); + } + + @Deprecated + @Override + public VoxelShape getOutlineShape(net.pitan76.mcpitanlib.api.event.block.OutlineShapeEvent e) { + return super.getOutlineShape(e); + } + + public VoxelShape getCollisionShape(CollisionShapeEvent e) { + return super.getCollisionShape(e.state.toMinecraft(), e.world.getRaw(), e.pos.toMinecraft(), e.context); + } + + @Deprecated + @Override + public VoxelShape getCollisionShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) { + return getCollisionShape(new CollisionShapeEvent(state, world, pos, context)); + } + + @Deprecated + @Override + public VoxelShape getCollisionShape(net.pitan76.mcpitanlib.api.event.block.CollisionShapeEvent e) { + return super.getCollisionShape(e); + } + + @Deprecated + @Override + public boolean hasComparatorOutput(BlockState state) { + return hasComparatorOutput(new HasComparatorOutputArgs(state)); + } + + public boolean hasComparatorOutput(HasComparatorOutputArgs args) { + return super.hasComparatorOutput(args.state); + } + + @Deprecated + @Override + public int getComparatorOutput(BlockState state, World world, BlockPos pos) { + return getComparatorOutput(new GetComparatorOutputArgs(state, world, pos)); + } + + public int getComparatorOutput(GetComparatorOutputArgs args) { + return super.getComparatorOutput(args.state, args.world, args.pos); + } + + @Deprecated + @Override + protected boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) { + return canPlaceAt(new CanPlaceAtArgs(state, world, pos)); + } + + public boolean canPlaceAt(CanPlaceAtArgs args) { + return super.canPlaceAt(args.state, args.world, args.pos); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/block/v2/CompatBlockProvider.java b/common/src/main/java/net/pitan76/mcpitanlib/api/block/v2/CompatBlockProvider.java new file mode 100644 index 000000000..368be8ddc --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/block/v2/CompatBlockProvider.java @@ -0,0 +1,91 @@ +package net.pitan76.mcpitanlib.api.block.v2; + +import net.minecraft.block.Block; +import net.minecraft.util.shape.VoxelShape; +import net.pitan76.mcpitanlib.api.block.CompatBlockRenderType; +import net.pitan76.mcpitanlib.api.block.ExtendBlockProvider; +import net.pitan76.mcpitanlib.api.block.args.RenderTypeArgs; +import net.pitan76.mcpitanlib.api.block.args.RotateArgs; +import net.pitan76.mcpitanlib.api.block.args.SideInvisibleArgs; +import net.pitan76.mcpitanlib.api.block.args.v2.CollisionShapeEvent; +import net.pitan76.mcpitanlib.api.block.args.v2.OutlineShapeEvent; +import net.pitan76.mcpitanlib.api.block.args.v2.PlacementStateArgs; +import net.pitan76.mcpitanlib.api.block.args.v2.StateForNeighborUpdateArgs; +import net.pitan76.mcpitanlib.midohra.block.BlockState; +import net.pitan76.mcpitanlib.midohra.block.BlockWrapper; +import net.pitan76.mcpitanlib.mixin.BlockInvoker; + +public interface CompatBlockProvider extends ExtendBlockProvider { + CompatibleBlockSettings getCompatSettings(); + + default BlockWrapper getWrapper() { + return this instanceof Block ? BlockWrapper.of((Block) this) : BlockWrapper.of(); + } + + default CompatBlockRenderType getRenderType(RenderTypeArgs args, Options options) { + options.cancel = false; + return null; + } + + default BlockState rotate(RotateArgs args, Options options) { + options.cancel = false; + return null; + } + + default Boolean isSideInvisible(SideInvisibleArgs args, Options options) { + options.cancel = false; + return null; + } + + default BlockState getDefaultMidohraState() { + if (this instanceof Block) { + return BlockState.of(((Block) this).getDefaultState()); + } + + return null; + } + + default void setDefaultState(BlockState state) { + if (this instanceof Block) { + ((BlockInvoker) this).setDefaultState_invoke(state.toMinecraft()); + } + } + + @Override + @Deprecated + default net.minecraft.block.BlockState getPlacementState(net.pitan76.mcpitanlib.api.event.block.PlacementStateArgs args, Options options) { + return ExtendBlockProvider.super.getPlacementState(args, options); + } + + default BlockState getPlacementState(PlacementStateArgs args, Options options) { + options.cancel = false; + return null; + } + + default BlockState getStateForNeighborUpdate(StateForNeighborUpdateArgs args, Options options) { + options.cancel = false; + return null; + } + + @Override + @Deprecated + default VoxelShape getOutlineShape(net.pitan76.mcpitanlib.api.event.block.OutlineShapeEvent event, Options options) { + return ExtendBlockProvider.super.getOutlineShape(event, options); + } + + default VoxelShape getOutlineShape(OutlineShapeEvent event, Options options) { + options.cancel = false; + return null; + } + + @Deprecated + @Override + default VoxelShape getCollisionShape(net.pitan76.mcpitanlib.api.event.block.CollisionShapeEvent event, Options options) { + return ExtendBlockProvider.super.getCollisionShape(event, options); + } + + default VoxelShape getCollisionShape(CollisionShapeEvent event, Options options) { + options.cancel = false; + return null; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/block/v2/CompatStairsBlock.java b/common/src/main/java/net/pitan76/mcpitanlib/api/block/v2/CompatStairsBlock.java new file mode 100644 index 000000000..f92115a8a --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/block/v2/CompatStairsBlock.java @@ -0,0 +1,69 @@ +package net.pitan76.mcpitanlib.api.block.v2; + +import net.minecraft.block.ShapeContext; +import net.minecraft.block.StairsBlock; +import net.minecraft.block.enums.BlockHalf; +import net.minecraft.block.enums.StairShape; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.shape.VoxelShape; +import net.minecraft.world.BlockView; +import net.pitan76.mcpitanlib.api.block.args.v2.CollisionShapeEvent; +import net.pitan76.mcpitanlib.api.block.args.v2.OutlineShapeEvent; +import net.pitan76.mcpitanlib.api.state.property.BooleanProperty; +import net.pitan76.mcpitanlib.api.state.property.CompatProperties; +import net.pitan76.mcpitanlib.api.state.property.DirectionProperty; +import net.pitan76.mcpitanlib.api.state.property.EnumProperty; +import net.pitan76.mcpitanlib.midohra.block.BlockState; + +public class CompatStairsBlock extends net.pitan76.mcpitanlib.api.block.CompatStairsBlock { + + public static final DirectionProperty FACING = CompatProperties.ofDir(StairsBlock.FACING); + public static final EnumProperty HALF = CompatProperties.of(StairsBlock.HALF); + public static final EnumProperty SHAPE = CompatProperties.of(StairsBlock.SHAPE); + public static final BooleanProperty WATERLOGGED = CompatProperties.of(StairsBlock.WATERLOGGED); + + public CompatStairsBlock(net.minecraft.block.BlockState baseBlockState, CompatibleBlockSettings settings) { + super(baseBlockState, settings); + } + + public CompatStairsBlock(BlockState baseBlockState, CompatibleBlockSettings settings) { + this(baseBlockState.toMinecraft(), settings); + } + + public VoxelShape getOutlineShape(OutlineShapeEvent e) { + return super.getOutlineShape(e.state.toMinecraft(), e.world.getRaw(), e.pos.toMinecraft(), e.context); + } + + public VoxelShape getCollisionShape(CollisionShapeEvent e) { + return super.getCollisionShape(e.state.toMinecraft(), e.world.getRaw(), e.pos.toMinecraft(), e.context); + } + + @Deprecated + @Override + public VoxelShape getOutlineShape(net.pitan76.mcpitanlib.api.event.block.OutlineShapeEvent e) { + return getOutlineShape(new OutlineShapeEvent(e.state, e.world, e.pos, e.context)); + } + + @Deprecated + @Override + public VoxelShape getOutlineShape(net.minecraft.block.BlockState state, BlockView world, BlockPos pos, ShapeContext context) { + return getOutlineShape(new OutlineShapeEvent(state, world, pos, context)); + } + + @Deprecated + @Override + public VoxelShape getOutlineShape(OutlineShapeEvent e, Options options) { + return super.getOutlineShape(e, options); + } + + @Override + public VoxelShape getCollisionShape(net.minecraft.block.BlockState state, BlockView world, BlockPos pos, ShapeContext context) { + return getCollisionShape(new CollisionShapeEvent(state, world, pos, context)); + } + + @Deprecated + @Override + public VoxelShape getCollisionShape(CollisionShapeEvent event, Options options) { + return super.getCollisionShape(event, options); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/block/v2/CompatibleBlockSettings.java b/common/src/main/java/net/pitan76/mcpitanlib/api/block/v2/CompatibleBlockSettings.java new file mode 100644 index 000000000..8b1ffdc2b --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/block/v2/CompatibleBlockSettings.java @@ -0,0 +1,286 @@ +package net.pitan76.mcpitanlib.api.block.v2; + +import com.mojang.serialization.Codec; +import net.minecraft.block.AbstractBlock; +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.block.MapColor; +import net.minecraft.registry.RegistryKey; +import net.minecraft.registry.RegistryKeys; +import net.minecraft.sound.BlockSoundGroup; +import net.minecraft.util.DyeColor; +import net.pitan76.mcpitanlib.api.block.CompatibleMaterial; +import net.pitan76.mcpitanlib.api.sound.CompatBlockSoundGroup; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.api.util.color.CompatDyeColor; +import net.pitan76.mcpitanlib.api.util.color.CompatMapColor; + +import java.util.function.Function; +import java.util.function.ToIntFunction; + +@SuppressWarnings("deprecation") +public class CompatibleBlockSettings extends net.pitan76.mcpitanlib.api.block.CompatibleBlockSettings { + protected CompatIdentifier identifier = null; + public boolean changedTranslationKey = false; + + public static final Codec CODEC = Codec.unit(CompatibleBlockSettings::new); + + @Deprecated + protected CompatibleBlockSettings() { + super(); + } + + public CompatibleBlockSettings(CompatIdentifier identifier) { + super(); + setId(identifier); + } + + public static CompatibleBlockSettings of(CompatIdentifier id) { + return new CompatibleBlockSettings(id); + } + + @Deprecated + public CompatibleBlockSettings setId(CompatIdentifier identifier) { + this.identifier = identifier; + return this; + } + + private static CompatibleBlockSettings copy(CompatibleMaterial material, CompatibleBlockSettings settings) { + settings.mapColor(material.getColor()); + if (material.isLiquid()) + settings.settings.liquid(); + if (material.isSolid()) + settings.settings.solid(); + if (material.isReplaceable()) + settings.settings.replaceable(); + if (material.isSolid()) + settings.settings.solid(); + if (material.isBurnable()) + settings.settings.burnable(); + settings.settings.pistonBehavior(material.getPistonBehavior()); + return settings; + } + + public CompatibleBlockSettings(CompatIdentifier id, CompatibleMaterial material, MapColor mapColor) { + this(id); + copy(material, this); + mapColor(mapColor); + } + + public CompatibleBlockSettings(CompatIdentifier id, CompatibleMaterial material, DyeColor dyeColor) { + this(id); + copy(material, this); + mapColor(dyeColor); + } + + public CompatibleBlockSettings(CompatIdentifier id, CompatibleMaterial material) { + this(id); + copy(material, this); + } + + public CompatibleBlockSettings(CompatIdentifier id, CompatibleMaterial material, Function mapColor) { + this(id); + copy(material, this); + mapColor(mapColor); + } + + public static CompatibleBlockSettings of(CompatIdentifier id, CompatibleMaterial material, MapColor mapColor) { + return new CompatibleBlockSettings(id, material, mapColor); + } + + public static CompatibleBlockSettings of(CompatIdentifier id, CompatibleMaterial material, DyeColor dyeColor) { + return new CompatibleBlockSettings(id, material, dyeColor); + } + + public static CompatibleBlockSettings of(CompatIdentifier id, CompatibleMaterial material) { + return new CompatibleBlockSettings(id, material); + } + + public static CompatibleBlockSettings of(CompatIdentifier id, CompatibleMaterial material, Function mapColor) { + return new CompatibleBlockSettings(id, material, mapColor); + } + + public CompatibleBlockSettings(CompatIdentifier id, AbstractBlock block) { + super(block); + setId(id); + } + + public static CompatibleBlockSettings copy(CompatIdentifier id, AbstractBlock block) { + return new CompatibleBlockSettings(id, block); + } + + public CompatibleBlockSettings air() { + super.air(); + return this; + } + + public CompatibleBlockSettings blockVision(AbstractBlock.ContextPredicate predicate) { + super.blockVision(predicate); + return this; + } + + public CompatibleBlockSettings postProcess(AbstractBlock.ContextPredicate predicate) { + super.postProcess(predicate); + return this; + } + + public CompatibleBlockSettings solidBlock(AbstractBlock.ContextPredicate predicate) { + super.solidBlock(predicate); + return this; + } + + public CompatibleBlockSettings suffocates(AbstractBlock.ContextPredicate predicate) { + super.suffocates(predicate); + return this; + } + + public CompatibleBlockSettings mapColor(MapColor color) { + super.mapColor(color); + return this; + } + + public CompatibleBlockSettings mapColor(DyeColor color) { + super.mapColor(color); + return this; + } + + public CompatibleBlockSettings mapColor(CompatMapColor color) { + super.mapColor(color.getColor()); + return this; + } + + public CompatibleBlockSettings mapColor(CompatDyeColor color) { + super.mapColor(color.getColor()); + return this; + } + + public CompatibleBlockSettings mapColor(Function color) { + super.mapColor(color); + return this; + } + + public CompatibleBlockSettings compatMapColor(Function color) { + super.mapColor(state -> color.apply(net.pitan76.mcpitanlib.midohra.block.BlockState.of(state)).getColor()); + return this; + } + + @Deprecated + public CompatibleBlockSettings dropsLike(Block source) { + super.dropsLike(source); + return this; + } + + public CompatibleBlockSettings breakInstantly() { + super.breakInstantly(); + return this; + } + + public CompatibleBlockSettings dropsNothing() { + super.dropsNothing(); + return this; + } + + public CompatibleBlockSettings dynamicBounds() { + super.dynamicBounds(); + return this; + } + + public CompatibleBlockSettings hardness(float hardness) { + super.hardness(hardness); + return this; + } + + public CompatibleBlockSettings noBlockBreakParticles() { + super.noBlockBreakParticles(); + return this; + } + + public CompatibleBlockSettings requiresTool() { + super.requiresTool(); + return this; + } + + public CompatibleBlockSettings noCollision() { + super.noCollision(); + return this; + } + + public CompatibleBlockSettings nonOpaque() { + super.nonOpaque(); + return this; + } + + public CompatibleBlockSettings resistance(float resistance) { + super.resistance(resistance); + return this; + } + + public CompatibleBlockSettings strength(float strength) { + super.strength(strength); + return this; + } + + public CompatibleBlockSettings strength(float hardness, float resistance) { + super.strength(hardness, resistance); + return this; + } + + public CompatibleBlockSettings ticksRandomly() { + super.ticksRandomly(); + return this; + } + + public CompatibleBlockSettings sounds(CompatBlockSoundGroup blockSoundGroup) { + super.sounds(blockSoundGroup); + return this; + } + + public CompatibleBlockSettings luminance(ToIntFunction luminance) { + super.luminance(luminance); + return this; + } + + public CompatibleBlockSettings jumpVelocityMultiplier(float jumpVelocityMultiplier) { + super.jumpVelocityMultiplier(jumpVelocityMultiplier); + return this; + } + + public CompatibleBlockSettings slipperiness(float slipperiness) { + super.slipperiness(slipperiness); + return this; + } + + public CompatibleBlockSettings velocityMultiplier(float velocityMultiplier) { + super.velocityMultiplier(velocityMultiplier); + return this; + } + + public CompatibleBlockSettings emissiveLighting(AbstractBlock.ContextPredicate predicate) { + super.emissiveLighting(predicate); + return this; + } + + public CompatibleBlockSettings offset(AbstractBlock.OffsetType offsetType) { + super.offset(offsetType); + return this; + } + + public CompatibleBlockSettings allowsSpawning(AbstractBlock.TypedContextPredicate> predicate) { + super.allowsSpawning(predicate); + return this; + } + + public AbstractBlock.Settings build() { + super.build(); + return settings; + } + + @Deprecated + @Override + public CompatibleBlockSettings sounds(BlockSoundGroup blockSoundGroup) { + super.sounds(blockSoundGroup); + return this; + } + + +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/client/CompatInventoryScreen.java b/common/src/main/java/net/pitan76/mcpitanlib/api/client/CompatInventoryScreen.java new file mode 100644 index 000000000..28fd67071 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/CompatInventoryScreen.java @@ -0,0 +1,22 @@ +package net.pitan76.mcpitanlib.api.client; + +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.screen.ScreenHandler; +import net.minecraft.text.Text; +import net.minecraft.util.Identifier; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; + +@Deprecated +public abstract class CompatInventoryScreen extends SimpleInventoryScreen { + + public CompatInventoryScreen(ScreenHandler handler, PlayerInventory inventory, Text title) { + super(handler, inventory, title); + } + + public abstract CompatIdentifier getCompatTexture(); + + @Override + public Identifier getTexture() { + return getCompatTexture().toMinecraft(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/client/SimpleHandledScreen.java b/common/src/main/java/net/pitan76/mcpitanlib/api/client/SimpleHandledScreen.java new file mode 100644 index 000000000..060e17547 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/SimpleHandledScreen.java @@ -0,0 +1,316 @@ +package net.pitan76.mcpitanlib.api.client; + +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.font.TextRenderer; +import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.gui.Drawable; +import net.minecraft.client.gui.Element; +import net.minecraft.client.gui.Selectable; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.gui.screen.ingame.HandledScreen; +import net.minecraft.client.render.item.ItemRenderer; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.screen.ScreenHandler; +import net.minecraft.text.Text; +import net.minecraft.util.Identifier; +import net.pitan76.mcpitanlib.api.client.gui.widget.CompatibleTexturedButtonWidget; +import net.pitan76.mcpitanlib.api.client.render.DrawObjectDM; +import net.pitan76.mcpitanlib.api.client.render.handledscreen.*; +import net.pitan76.mcpitanlib.api.client.render.screen.RenderBackgroundTextureArgs; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.api.util.IdentifierUtil; +import net.pitan76.mcpitanlib.api.util.client.ClientUtil; +import net.pitan76.mcpitanlib.api.util.client.RenderUtil; +import net.pitan76.mcpitanlib.core.datafixer.Pair; + +@Deprecated +public abstract class SimpleHandledScreen extends HandledScreen { + + public int width, height, backgroundWidth, backgroundHeight, x, y; + public ScreenHandler handler; + public TextRenderer textRenderer; + public ItemRenderer itemRenderer; + + public Text title; + public MinecraftClient client; + public SimpleHandledScreen(ScreenHandler handler, PlayerInventory inventory, Text title) { + super(handler, inventory, title); + fixScreen(); + this.handler = handler; + this.title = title; + + } + + public T addDrawableChild_compatibility(T drawableElement) { + return super.addDrawableChild(drawableElement); + // addButton + } + + public T addSelectableChild_compatibility(T selectableElement) { + return super.addSelectableChild(selectableElement); + } + + public CompatibleTexturedButtonWidget addDrawableCTBW(CompatibleTexturedButtonWidget widget) { + return addDrawableChild_compatibility(widget); + } + + @Deprecated + @Override + protected void drawBackground(DrawContext context, float delta, int mouseX, int mouseY) { + DrawObjectDM drawObjectDM = new DrawObjectDM(context, this); + drawBackgroundOverride(new DrawBackgroundArgs(drawObjectDM, delta, mouseX, mouseY)); + } + + public abstract void drawBackgroundOverride(DrawBackgroundArgs args); + + @Deprecated + @Override + protected void drawForeground(DrawContext context, int mouseX, int mouseY) { + DrawObjectDM drawObjectDM = new DrawObjectDM(context, this); + drawForegroundOverride(new DrawForegroundArgs(drawObjectDM, mouseX, mouseY)); + } + + protected void drawForegroundOverride(DrawForegroundArgs args) { + super.drawForeground(args.drawObjectDM.getContext(), args.mouseX, args.mouseY); + } + + public void callDrawTexture(DrawObjectDM drawObjectDM, Identifier texture, int x, int y, int u, int v, int width, int height) { + drawObjectDM.getContext().drawTexture(texture, x, y, u, v, width, height, 256, 256); + } + + public void callDrawTexture(DrawObjectDM drawObjectDM, CompatIdentifier texture, int x, int y, int u, int v, int width, int height) { + callDrawTexture(drawObjectDM, texture.toMinecraft(), x, y, u, v, width, height); + } + + @Deprecated + public void callRenderBackground(DrawObjectDM drawObjectDM) { + callRenderBackground(new RenderArgs(drawObjectDM, 0, 0, 0)); + } + + + public void callRenderBackground(RenderArgs args) { + super.renderBackground(args.drawObjectDM.getContext(), args.mouseX, args.mouseY, args.delta); + } + + public void callDrawMouseoverTooltip(DrawMouseoverTooltipArgs args) { + super.drawMouseoverTooltip(args.drawObjectDM.getContext(), args.mouseX, args.mouseY); + } + + public void renderOverride(RenderArgs args) { + super.render(args.drawObjectDM.getContext(), args.mouseX, args.mouseY, args.delta); + } + + public void resizeOverride(MinecraftClient client, int width, int height) { + } + + public void initOverride() { + } + + @Deprecated + @Override + protected void init() { + super.init(); + fixScreen(); + initOverride(); + } + + @Deprecated + @Override + public void resize(MinecraftClient client, int width, int height) { + super.resize(client, width, height); + fixScreen(); + resizeOverride(client, width, height); + } + + public void fixScreen() { + this.backgroundWidth = getBackgroundWidth(); + this.backgroundHeight = getBackgroundHeight(); + this.x = super.x; //(this.width - this.backgroundWidth) / 2; + this.y = super.y; //(this.height - this.backgroundHeight) / 2; + this.textRenderer = super.textRenderer; + this.itemRenderer = MinecraftClient.getInstance().getItemRenderer(); + this.width = super.width; + this.height = super.height; + if (super.client == null) + this.client = MinecraftClient.getInstance(); + else + this.client = super.client; + } + + public void setX(int x) { + this.x = x; + super.x = x; + } + + public void setY(int y) { + this.y = y; + super.y = y; + } + + public void setTextRenderer(TextRenderer textRenderer) { + this.textRenderer = textRenderer; + super.textRenderer = textRenderer; + } + + public void setItemRenderer(ItemRenderer itemRenderer) { + this.itemRenderer = itemRenderer; + } + + public void setWidth(int width) { + this.width = width; + super.width = width; + } + + public void setBackgroundWidth(int backgroundWidth) { + this.backgroundWidth = backgroundWidth; + super.backgroundWidth = backgroundWidth; + } + + public void setBackgroundHeight(int backgroundHeight) { + this.backgroundHeight = backgroundHeight; + super.backgroundHeight = backgroundHeight; + } + + public void setHeight(int height) { + this.height = height; + super.height = height; + } + + public int getBackgroundWidth() { + return super.backgroundWidth; + } + + public int getBackgroundHeight() { + return super.backgroundHeight; + } + + @Deprecated + @Override + public void render(DrawContext context, int mouseX, int mouseY, float delta) { + DrawObjectDM drawObjectDM = new DrawObjectDM(context, this); + renderOverride(new RenderArgs(drawObjectDM, mouseX, mouseY, delta)); + } + + public boolean keyReleased(KeyEventArgs args) { + return super.keyReleased(args.keyCode, args.scanCode, args.modifiers); + } + + public boolean keyPressed(KeyEventArgs args) { + return super.keyPressed(args.keyCode, args.scanCode, args.modifiers); + } + + public void renderBackgroundTexture(RenderBackgroundTextureArgs args) { + if (getBackgroundTexture() != null) + Screen.renderBackgroundTexture(args.getDrawObjectDM().getContext(), getBackgroundTexture(), x, y, 0, 0, this.width, this.height); + + RenderUtil.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); + callDrawTexture(args.drawObjectDM, getBackgroundTexture(), 0, 0, 0, 0, width, height); + } + + @Deprecated + @Override + public boolean keyReleased(int keyCode, int scanCode, int modifiers) { + return this.keyReleased(new KeyEventArgs(keyCode, scanCode, modifiers)); + } + + @Deprecated + @Override + public boolean keyPressed(int keyCode, int scanCode, int modifiers) { + return this.keyPressed(new KeyEventArgs(keyCode, scanCode, modifiers)); + } + + @Deprecated + @Override + public void renderDarkening(DrawContext context) { + this.renderBackgroundTexture(new RenderBackgroundTextureArgs(new DrawObjectDM(context, this), 0)); + } + + public void closeOverride() { + super.close(); + } + + public void removedOverride() { + super.removed(); + } + + @Override + public void close() { + closeOverride(); + } + + @Override + public void removed() { + removedOverride(); + } + + public Identifier getBackgroundTexture() { + return IdentifierUtil.from(getCompatBackgroundTexture()); + } + + public CompatIdentifier getCompatBackgroundTexture() { + return null; + } + + public void setTitleX(int x) { + this.titleX = x; + } + + public void setTitleY(int y) { + this.titleY = y; + } + + public void setTitlePos(int x, int y) { + setTitleX(x); + setTitleY(y); + } + + public void setTitleXCenter() { + if (textRenderer == null) + textRenderer = ClientUtil.getTextRenderer(); + + setTitleX(backgroundWidth / 2 - textRenderer.getWidth(title) / 2); + } + + public int getTitleX() { + return titleX; + } + + public int getTitleY() { + return titleY; + } + + @Deprecated + @Override + public Text getTitle() { + return callGetTitle(); + } + + public Text callGetTitle() { + return super.getTitle(); + } + + public Pair getTitlePosP() { + return new Pair<>(getTitleX(), getTitleY()); + } + + public int getPlayerInvTitleX() { + return playerInventoryTitleX; + } + + public int getPlayerInvTitleY() { + return playerInventoryTitleY; + } + + public void setPlayerInvTitleX(int x) { + playerInventoryTitleX = x; + } + + public void setPlayerInvTitleY(int y) { + playerInventoryTitleY = y; + } + + public void setPlayerInvTitle(int x, int y) { + setPlayerInvTitleX(x); + setPlayerInvTitleY(y); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/client/SimpleInventoryScreen.java b/common/src/main/java/net/pitan76/mcpitanlib/api/client/SimpleInventoryScreen.java new file mode 100644 index 000000000..de34a65fc --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/SimpleInventoryScreen.java @@ -0,0 +1,39 @@ +package net.pitan76.mcpitanlib.api.client; + +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.screen.ScreenHandler; +import net.minecraft.text.Text; +import net.minecraft.util.Identifier; +import net.pitan76.mcpitanlib.api.client.render.handledscreen.DrawBackgroundArgs; +import net.pitan76.mcpitanlib.api.client.render.handledscreen.DrawMouseoverTooltipArgs; +import net.pitan76.mcpitanlib.api.client.render.handledscreen.RenderArgs; +import net.pitan76.mcpitanlib.api.util.client.RenderUtil; + +@Deprecated +public abstract class SimpleInventoryScreen extends SimpleHandledScreen { + + public SimpleInventoryScreen(ScreenHandler handler, PlayerInventory inventory, Text title) { + super(handler, inventory, title); + } + + public abstract Identifier getTexture(); + + @Override + public Identifier getBackgroundTexture() { + return getTexture(); + } + + @Override + public void drawBackgroundOverride(DrawBackgroundArgs args) { + RenderUtil.setShaderToPositionTexProgram(); + RenderUtil.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); + callDrawTexture(args.drawObjectDM, getTexture(), x, y, 0, 0, backgroundWidth, backgroundHeight); + } + + @Override + public void renderOverride(RenderArgs args) { + this.callRenderBackground(args); + super.renderOverride(args); + this.callDrawMouseoverTooltip(new DrawMouseoverTooltipArgs(args.drawObjectDM, args.mouseX, args.mouseY)); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/client/SimpleOptionsScreen.java b/common/src/main/java/net/pitan76/mcpitanlib/api/client/SimpleOptionsScreen.java new file mode 100644 index 000000000..572621b5a --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/SimpleOptionsScreen.java @@ -0,0 +1,27 @@ +package net.pitan76.mcpitanlib.api.client; + +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.option.GameOptions; +import net.minecraft.text.Text; + +public class SimpleOptionsScreen extends SimpleScreen { + + protected final Screen parent; + protected final GameOptions gameOptions; + + public SimpleOptionsScreen(Text title, Screen parent, GameOptions gameOptions) { + super(title); + this.parent = parent; + this.gameOptions = gameOptions; + } + + @Override + public void removed() { + client.options.write(); + } + + @Override + public void close() { + client.setScreen(this.parent); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/client/SimpleScreen.java b/common/src/main/java/net/pitan76/mcpitanlib/api/client/SimpleScreen.java new file mode 100644 index 000000000..7a129ecdb --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/SimpleScreen.java @@ -0,0 +1,192 @@ +package net.pitan76.mcpitanlib.api.client; + +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.font.TextRenderer; +import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.gui.Drawable; +import net.minecraft.client.gui.Element; +import net.minecraft.client.gui.Selectable; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.render.item.ItemRenderer; +import net.minecraft.text.Text; +import net.minecraft.util.Identifier; +import net.pitan76.mcpitanlib.api.client.gui.widget.CompatibleTexturedButtonWidget; +import net.pitan76.mcpitanlib.api.client.render.DrawObjectDM; +import net.pitan76.mcpitanlib.api.client.render.handledscreen.*; +import net.pitan76.mcpitanlib.api.client.render.screen.RenderBackgroundTextureArgs; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.api.util.IdentifierUtil; +import net.pitan76.mcpitanlib.api.util.client.RenderUtil; + +public abstract class SimpleScreen extends Screen { + + public int width, height; + public TextRenderer textRenderer; + public ItemRenderer itemRenderer; + + public Text title; + public MinecraftClient client; + + public SimpleScreen(Text title) { + super(title); + fixScreen(); + this.title = title; + } + + public T addDrawableChild_compatibility(T drawableElement) { + return super.addDrawableChild(drawableElement); + // addButton + } + + public T addSelectableChild_compatibility(T selectableElement) { + return super.addSelectableChild(selectableElement); + } + + public CompatibleTexturedButtonWidget addDrawableCTBW(CompatibleTexturedButtonWidget widget) { + return addDrawableChild_compatibility(widget); + } + + public void callDrawTexture(DrawObjectDM drawObjectDM, Identifier texture, int x, int y, int u, int v, int width, int height) { + //ScreenUtil.setBackground(GUI); + //super.drawTexture(matrices, x, y, u, v, width, height); + drawObjectDM.getContext().drawTexture(texture, x, y, u, v, width, height, 256, 256); + } + + public void callDrawTexture(DrawObjectDM drawObjectDM, CompatIdentifier texture, int x, int y, int u, int v, int width, int height) { + callDrawTexture(drawObjectDM, texture.toMinecraft(), x, y, u, v, width, height); + } + + @Deprecated + @Override + public void renderBackground(DrawContext context, int mouseX, int mouseY, float delta) { + renderBackground(new RenderArgs(new DrawObjectDM(context, this), mouseX, mouseY, delta)); + } + + + public void renderBackground(RenderArgs args) { + super.renderBackground(args.drawObjectDM.getContext(), args.mouseX, args.mouseY, args.delta); + } + + public void render(RenderArgs args) { + super.render(args.drawObjectDM.getContext(), args.mouseX, args.mouseY, args.delta); + } + + public void resizeOverride(MinecraftClient client, int width, int height) { + } + + public void initOverride() { + } + + @Deprecated + @Override + protected void init() { + super.init(); + fixScreen(); + initOverride(); + } + + @Deprecated + @Override + public void resize(MinecraftClient client, int width, int height) { + super.resize(client, width, height); + fixScreen(); + resizeOverride(client, width, height); + } + + public void fixScreen() { + this.textRenderer = super.textRenderer; + this.itemRenderer = MinecraftClient.getInstance().getItemRenderer(); + this.width = super.width; + this.height = super.height; + if (super.client == null) + this.client = MinecraftClient.getInstance(); + else + this.client = super.client; + } + + public void setTextRenderer(TextRenderer textRenderer) { + this.textRenderer = textRenderer; + super.textRenderer = textRenderer; + } + + public void setItemRenderer(ItemRenderer itemRenderer) { + this.itemRenderer = itemRenderer; + } + + public void setWidth(int width) { + this.width = width; + super.width = width; + } + + public void setHeight(int height) { + this.height = height; + super.height = height; + } + + @Deprecated + @Override + public void render(DrawContext context, int mouseX, int mouseY, float delta) { + DrawObjectDM drawObjectDM = new DrawObjectDM(context, this); + render(new RenderArgs(drawObjectDM, mouseX, mouseY, delta)); + } + + public boolean keyReleased(KeyEventArgs args) { + return super.keyReleased(args.keyCode, args.scanCode, args.modifiers); + } + + public boolean keyPressed(KeyEventArgs args) { + return super.keyPressed(args.keyCode, args.scanCode, args.modifiers); + } + + public void renderBackgroundTexture(RenderBackgroundTextureArgs args) { + if (getBackgroundTexture() != null) + Screen.renderBackgroundTexture(args.getDrawObjectDM().getContext(), getBackgroundTexture(), 0, 0, 0, 0, this.width, this.height); + + RenderUtil.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); + callDrawTexture(args.drawObjectDM, getBackgroundTexture(), 0, 0, 0, 0, width, height); + } + + @Deprecated + @Override + public boolean keyReleased(int keyCode, int scanCode, int modifiers) { + return this.keyReleased(new KeyEventArgs(keyCode, scanCode, modifiers)); + } + + @Deprecated + @Override + public boolean keyPressed(int keyCode, int scanCode, int modifiers) { + return this.keyPressed(new KeyEventArgs(keyCode, scanCode, modifiers)); + } + + @Deprecated + @Override + public void renderDarkening(DrawContext context) { + this.renderBackgroundTexture(new RenderBackgroundTextureArgs(new DrawObjectDM(context, this), 0)); + } + + public void closeOverride() { + super.close(); + } + + public void removedOverride() { + super.removed(); + } + + @Override + public void close() { + closeOverride(); + } + + @Override + public void removed() { + removedOverride(); + } + + public Identifier getBackgroundTexture() { + return IdentifierUtil.from(getCompatBackgroundTexture()); + } + + public CompatIdentifier getCompatBackgroundTexture() { + return null; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/client/color/BlockColorEvent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/client/color/BlockColorEvent.java new file mode 100644 index 000000000..7e2873166 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/color/BlockColorEvent.java @@ -0,0 +1,83 @@ +package net.pitan76.mcpitanlib.api.client.color; + +import dev.architectury.injectables.annotations.ExpectPlatform; +import net.minecraft.block.BlockState; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.BlockRenderView; +import net.pitan76.mcpitanlib.midohra.world.BlockView; +import org.jetbrains.annotations.Nullable; + +public class BlockColorEvent { + private final BlockState state; + private final BlockRenderView world; + private final BlockPos pos; + private final int tintIndex; + + public BlockColorEvent(BlockState state, @Nullable BlockRenderView world, @Nullable BlockPos pos, int tintIndex) { + this.state = state; + this.world = world; + this.pos = pos; + this.tintIndex = tintIndex; + } + + public BlockState getState() { + return state; + } + + public BlockRenderView getWorld() { + return world; + } + + public BlockPos getPos() { + return pos; + } + + public int getTintIndex() { + return tintIndex; + } + + public net.pitan76.mcpitanlib.midohra.util.math.BlockPos getMidohraPos() { + return net.pitan76.mcpitanlib.midohra.util.math.BlockPos.of(getPos()); + } + + public net.pitan76.mcpitanlib.midohra.block.BlockState getMidohraState() { + return net.pitan76.mcpitanlib.midohra.block.BlockState.of(getState()); + } + + public boolean hasWorld() { + return getWorld() != null; + } + + public boolean hasPos() { + return getPos() != null; + } + + public BlockView getMidohraWorld() { + if (!hasWorld()) return null; + return net.pitan76.mcpitanlib.midohra.world.BlockView.of(getWorld()); + } + + public BlockEntity getBlockEntity() { + if (!hasWorld() || !hasPos()) return null; + return getWorld().getBlockEntity(getPos()); + } + + public int getDefaultColor() { + return 0xFFFFFF; + } + + public Object getRenderData() { + if (!hasWorld() || !hasPos()) return null; + return getRenderDataD(getBlockEntity()); + } + + @ExpectPlatform + protected static Object getRenderDataD(BlockEntity blockEntity) { + if (blockEntity instanceof net.pitan76.mcpitanlib.api.tile.RenderDataBlockEntity) { + return ((net.pitan76.mcpitanlib.api.tile.RenderDataBlockEntity) blockEntity).getCompatRenderData(); + } + + return null; + } +} \ No newline at end of file diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/client/color/CompatBlockColorProvider.java b/common/src/main/java/net/pitan76/mcpitanlib/api/client/color/CompatBlockColorProvider.java new file mode 100644 index 000000000..50ceb12f4 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/color/CompatBlockColorProvider.java @@ -0,0 +1,15 @@ +package net.pitan76.mcpitanlib.api.client.color; + +import net.minecraft.block.BlockState; +import net.minecraft.client.color.block.BlockColorProvider; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.BlockRenderView; +import org.jetbrains.annotations.Nullable; + +public interface CompatBlockColorProvider extends BlockColorProvider { + default int getColor(BlockState state, @Nullable BlockRenderView world, @Nullable BlockPos pos, int tintIndex) { + return getColor(new BlockColorEvent(state, world, pos, tintIndex)); + } + + int getColor(BlockColorEvent e); +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/client/event/ItemTooltipRegistry.java b/common/src/main/java/net/pitan76/mcpitanlib/api/client/event/ItemTooltipRegistry.java new file mode 100644 index 000000000..8166f7406 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/event/ItemTooltipRegistry.java @@ -0,0 +1,10 @@ +package net.pitan76.mcpitanlib.api.client.event; + +import dev.architectury.event.events.client.ClientTooltipEvent; +import net.pitan76.mcpitanlib.api.client.event.listener.ItemTooltipListener; + +public class ItemTooltipRegistry { + public static void registerItemTooltip(ItemTooltipListener listener) { + ClientTooltipEvent.ITEM.register(listener::onTooltip); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/client/event/WorldRenderRegistry.java b/common/src/main/java/net/pitan76/mcpitanlib/api/client/event/WorldRenderRegistry.java new file mode 100644 index 000000000..6cba6e3aa --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/event/WorldRenderRegistry.java @@ -0,0 +1,21 @@ +package net.pitan76.mcpitanlib.api.client.event; + +import dev.architectury.injectables.annotations.ExpectPlatform; +import net.pitan76.mcpitanlib.api.client.event.listener.BeforeBlockOutlineListener; +import net.pitan76.mcpitanlib.api.client.event.listener.WorldRenderContextListener; + +public class WorldRenderRegistry { + public WorldRenderRegistry() { + + } + + @ExpectPlatform + public static void registerWorldRenderBeforeBlockOutline(BeforeBlockOutlineListener listener) { + throw new AssertionError(); + } + + @ExpectPlatform + public static void registerWorldRenderAfterLevel(WorldRenderContextListener listener) { + throw new AssertionError(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/client/event/listener/BeforeBlockOutlineEvent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/client/event/listener/BeforeBlockOutlineEvent.java new file mode 100644 index 000000000..2f740d104 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/event/listener/BeforeBlockOutlineEvent.java @@ -0,0 +1,116 @@ +package net.pitan76.mcpitanlib.api.client.event.listener; + +import net.minecraft.block.BlockState; +import net.minecraft.client.render.Camera; +import net.minecraft.client.render.VertexConsumer; +import net.minecraft.client.render.WorldRenderer; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.util.hit.BlockHitResult; +import net.minecraft.util.hit.HitResult; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Box; +import net.minecraft.util.shape.VoxelShape; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.midohra.client.render.CameraWrapper; +import net.pitan76.mcpitanlib.midohra.util.hit.HitResultType; + +import java.util.Optional; + +public class BeforeBlockOutlineEvent { + public WorldRenderContext context; + public HitResult hitResult; + + public BeforeBlockOutlineEvent(WorldRenderContext context, HitResult hitResult) { + this.context = context; + this.hitResult = hitResult; + } + + public HitResult getHitResult() { + return hitResult; + } + + public WorldRenderContext getContext() { + return context; + } + + public WorldRenderer getWorldRenderer() { + return context.getWorldRenderer(); + } + + public Optional getBlockState() { + return Optional.ofNullable(getWorld().getBlockState(getBlockPos().orElse(null))); + } + + public World getWorld() { + return context.getWorld(); + } + + public Optional getBlockPos() { + return Optional.ofNullable(((BlockHitResult) hitResult).getBlockPos()); + } + + public boolean isBlockType() { + return getHitResultType() == HitResult.Type.BLOCK; + } + + public HitResult.Type getHitResultType() { + return hitResult.getType(); + } + + @Deprecated + public Camera getCamera() { + return context.getCamera(); + } + + public CameraWrapper getCameraWrapper() { + return CameraWrapper.of(getCamera()); + } + + public Optional getOutlineShape() { + return context.getOutlineShape(); + } + + public MatrixStack getMatrixStack() { + return context.getMatrixStack(); + } + + public void push() { + context.push(); + } + + public void translate(double x, double y, double z) { + context.translate(x, y, z); + } + + public void pop() { + context.pop(); + } + + public Optional getVertexConsumer() { + return context.getVertexConsumer(); + } + + public void drawBox(float red, float green, float blue, float alpha) { + context.drawBox(red, green, blue, alpha); + } + + public void drawBox(Box box, float red, float green, float blue, float alpha) { + context.drawBox(box, red, green, blue, alpha); + } + + public net.pitan76.mcpitanlib.midohra.util.hit.HitResult getHitResultM() { + return net.pitan76.mcpitanlib.midohra.util.hit.HitResult.of(hitResult); + } + + public HitResultType getHitResultTypeM() { + return HitResultType.from(hitResult.getType()); + } + + public BlockState getBlockState2() { + return getWorld().getBlockState(getHitResultM().asBlockHitResult().get().getBlockPos()); + } + + public net.pitan76.mcpitanlib.midohra.block.BlockState getBlockStateM() { + return net.pitan76.mcpitanlib.midohra.block.BlockState.of(getBlockState2()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/client/event/listener/BeforeBlockOutlineListener.java b/common/src/main/java/net/pitan76/mcpitanlib/api/client/event/listener/BeforeBlockOutlineListener.java new file mode 100644 index 000000000..881ee7b11 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/event/listener/BeforeBlockOutlineListener.java @@ -0,0 +1,11 @@ +package net.pitan76.mcpitanlib.api.client.event.listener; + + +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; + +@Environment(EnvType.CLIENT) +@FunctionalInterface +public interface BeforeBlockOutlineListener { + boolean beforeBlockOutline(BeforeBlockOutlineEvent event); +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/client/event/listener/ItemTooltipContext.java b/common/src/main/java/net/pitan76/mcpitanlib/api/client/event/listener/ItemTooltipContext.java new file mode 100644 index 000000000..296fd2778 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/event/listener/ItemTooltipContext.java @@ -0,0 +1,58 @@ +package net.pitan76.mcpitanlib.api.client.event.listener; + +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.item.tooltip.TooltipType; +import net.minecraft.text.Text; + +import java.util.List; + +public class ItemTooltipContext { + + public ItemStack stack; + public List texts; + public Item.TooltipContext tooltipContext; + + @Deprecated + public TooltipType type; + + public ItemTooltipContext(ItemStack stack, List texts, Item.TooltipContext tooltipContext, TooltipType type) { + this.stack = stack; + this.texts = texts; + this.tooltipContext = tooltipContext; + this.type = type; + } + + public ItemStack getStack() { + return stack; + } + + public List getTexts() { + return texts; + } + + public Item.TooltipContext getTooltipContext() { + return tooltipContext; + } + + @Deprecated + public TooltipType getType() { + return type; + } + + public void addTooltip(Text text) { + texts.add(text); + } + + public void addTooltip(List texts) { + this.texts.addAll(texts); + } + + public boolean isAdvanced() { + return type.isAdvanced(); + } + + public boolean isCreative() { + return type.isCreative(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/client/event/listener/ItemTooltipListener.java b/common/src/main/java/net/pitan76/mcpitanlib/api/client/event/listener/ItemTooltipListener.java new file mode 100644 index 000000000..d86227934 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/event/listener/ItemTooltipListener.java @@ -0,0 +1,17 @@ +package net.pitan76.mcpitanlib.api.client.event.listener; + +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.item.tooltip.TooltipType; +import net.minecraft.text.Text; + +import java.util.List; + +@FunctionalInterface +public interface ItemTooltipListener { + void onTooltip(ItemTooltipContext context); + + default void onTooltip(ItemStack stack, List texts, Item.TooltipContext tooltipContext, TooltipType type) { + onTooltip(new ItemTooltipContext(stack, texts, tooltipContext, type)); + } +} \ No newline at end of file diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/client/event/listener/WorldRenderContext.java b/common/src/main/java/net/pitan76/mcpitanlib/api/client/event/listener/WorldRenderContext.java new file mode 100644 index 000000000..8a65518d4 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/event/listener/WorldRenderContext.java @@ -0,0 +1,130 @@ +package net.pitan76.mcpitanlib.api.client.event.listener; + +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.block.BlockState; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.render.*; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.client.world.ClientWorld; +import net.minecraft.entity.Entity; +import net.minecraft.util.hit.BlockHitResult; +import net.minecraft.util.hit.HitResult; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Box; +import net.minecraft.util.shape.VoxelShape; +import net.pitan76.mcpitanlib.api.util.VoxelShapeUtil; +import net.pitan76.mcpitanlib.midohra.client.render.CameraWrapper; +import org.jetbrains.annotations.Nullable; +import org.joml.Matrix4f; + +import java.util.Objects; +import java.util.Optional; + +public interface WorldRenderContext { + + WorldRenderer getWorldRenderer(); + + MatrixStack getMatrixStack(); + + float getTickDelta(); + + Camera getCamera(); + + GameRenderer getGameRenderer(); + + LightmapTextureManager getLightmapTextureManager(); + + @Deprecated + Matrix4f getProjectionMatrix(); + + ClientWorld getWorld(); + + @Deprecated + boolean isAdvancedTranslucency(); + + @Nullable VertexConsumerProvider getConsumers(); + @Nullable Frustum getFrustum(); + + @Environment(EnvType.CLIENT) + interface BlockOutlineContext { + @Deprecated + VertexConsumer vertexConsumer(); + + Entity entity(); + + double cameraX(); + + double cameraY(); + + double cameraZ(); + + BlockPos blockPos(); + + BlockState blockState(); + } + + default HitResult getHitResult() { + return MinecraftClient.getInstance().crosshairTarget; + } + + default Optional getBlockState() { + return Optional.ofNullable(getWorld().getBlockState(getBlockPos().orElse(null))); + } + + default Optional getBlockPos() { + return Optional.ofNullable(((BlockHitResult) getHitResult()).getBlockPos()); + } + + default boolean isBlockType() { + return getHitResultType() == HitResult.Type.BLOCK; + } + + default HitResult.Type getHitResultType() { + return getHitResult().getType(); + } + + default Optional getOutlineShape() { + return getBlockState().map(blockState -> blockState.getOutlineShape(getWorld(), + getBlockPos().orElse(null))); + } + + default void push() { + getMatrixStack().push(); + } + + default void translate(double x, double y, double z) { + getMatrixStack().translate(x, y, z); + } + + default void pop() { + getMatrixStack().pop(); + } + + default Optional getVertexConsumer() { + if (getConsumers() == null) + return Optional.empty(); + + return Optional.of(Objects.requireNonNull(getConsumers()).getBuffer(RenderLayer.getLines())); + } + + default void drawBox(float red, float green, float blue, float alpha) { + Optional outlineShape = getOutlineShape(); + if (!outlineShape.isPresent()) return; + + drawBox(VoxelShapeUtil.getBoundingBox(outlineShape.get()), red, green, blue, alpha); + } + + default void drawBox(Box box, float red, float green, float blue, float alpha) { + Optional vertexConsumer = getVertexConsumer(); + + if (!vertexConsumer.isPresent()) + return; + + WorldRenderer.drawBox(getMatrixStack(), vertexConsumer.get(), box, red, green, blue, alpha); + } + + default CameraWrapper getCameraWrapper() { + return CameraWrapper.of(getCamera()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/client/event/listener/WorldRenderContextListener.java b/common/src/main/java/net/pitan76/mcpitanlib/api/client/event/listener/WorldRenderContextListener.java new file mode 100644 index 000000000..7025eae59 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/event/listener/WorldRenderContextListener.java @@ -0,0 +1,10 @@ +package net.pitan76.mcpitanlib.api.client.event.listener; + +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; + +@Environment(EnvType.CLIENT) +@FunctionalInterface +public interface WorldRenderContextListener { + void render(WorldRenderContext context); +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/client/gui/screen/CompatInventoryScreen.java b/common/src/main/java/net/pitan76/mcpitanlib/api/client/gui/screen/CompatInventoryScreen.java new file mode 100644 index 000000000..675de4d31 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/gui/screen/CompatInventoryScreen.java @@ -0,0 +1,33 @@ +package net.pitan76.mcpitanlib.api.client.gui.screen; + +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.screen.ScreenHandler; +import net.minecraft.screen.slot.Slot; +import net.minecraft.text.Text; +import net.minecraft.util.Identifier; +import net.pitan76.mcpitanlib.api.client.render.DrawObjectDM; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.guilib.api.render.SlotRenderer; + +public abstract class CompatInventoryScreen extends SimpleInventoryScreen { + + public CompatInventoryScreen(S handler, PlayerInventory inventory, Text title) { + super(handler, inventory, title); + } + + public abstract CompatIdentifier getCompatTexture(); + + @Deprecated + @Override + public Identifier getTexture() { + return getCompatTexture().toMinecraft(); + } + + public void drawSlot(DrawObjectDM drawObjectDM, Slot slot) { + SlotRenderer.drawSlot(drawObjectDM, slot, x, y); + } + + public void drawSlots(DrawObjectDM drawObjectDM) { + SlotRenderer.drawSlots(drawObjectDM, handler, x, y); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/client/gui/screen/ScreenTexts.java b/common/src/main/java/net/pitan76/mcpitanlib/api/client/gui/screen/ScreenTexts.java new file mode 100644 index 000000000..da47fb543 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/gui/screen/ScreenTexts.java @@ -0,0 +1,21 @@ +package net.pitan76.mcpitanlib.api.client.gui.screen; + +import net.minecraft.text.Text; +import net.pitan76.mcpitanlib.api.util.TextUtil; + +public class ScreenTexts { + public static final Text ON = TextUtil.translatable("options.on"); + public static final Text OFF = TextUtil.translatable("options.off"); + public static final Text DONE = TextUtil.translatable("gui.done"); + public static final Text CANCEL = TextUtil.translatable("gui.cancel"); + public static final Text YES = TextUtil.translatable("gui.yes"); + public static final Text NO = TextUtil.translatable("gui.no"); + public static final Text PROCEED = TextUtil.translatable("gui.proceed"); + public static final Text BACK = TextUtil.translatable("gui.back"); + public static final Text CONNECT_FAILED = TextUtil.translatable("connect.failed"); + public static final Text LINE_BREAK = TextUtil.literal("\n"); + public static final Text SENTENCE_SEPARATOR = TextUtil.literal(". "); + + public ScreenTexts() { + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/client/gui/screen/SimpleHandledScreen.java b/common/src/main/java/net/pitan76/mcpitanlib/api/client/gui/screen/SimpleHandledScreen.java new file mode 100644 index 000000000..fd7773668 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/gui/screen/SimpleHandledScreen.java @@ -0,0 +1,364 @@ +package net.pitan76.mcpitanlib.api.client.gui.screen; + +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.font.TextRenderer; +import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.gui.Drawable; +import net.minecraft.client.gui.Element; +import net.minecraft.client.gui.Selectable; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.gui.screen.ingame.HandledScreen; +import net.minecraft.client.render.item.ItemRenderer; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.screen.ScreenHandler; +import net.minecraft.text.Text; +import net.minecraft.util.Identifier; +import net.pitan76.mcpitanlib.api.client.gui.widget.CompatibleTexturedButtonWidget; +import net.pitan76.mcpitanlib.api.client.render.DrawObjectDM; +import net.pitan76.mcpitanlib.api.client.render.handledscreen.*; +import net.pitan76.mcpitanlib.api.client.render.screen.RenderBackgroundTextureArgs; +import net.pitan76.mcpitanlib.api.text.TextComponent; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.api.util.IdentifierUtil; +import net.pitan76.mcpitanlib.api.util.client.ClientUtil; +import net.pitan76.mcpitanlib.api.util.client.RenderUtil; +import net.pitan76.mcpitanlib.api.util.client.ScreenUtil; +import net.pitan76.mcpitanlib.core.datafixer.Pair; + +public abstract class SimpleHandledScreen extends HandledScreen { + + public int width, height, backgroundWidth, backgroundHeight, x, y; + public S handler; + public TextRenderer textRenderer; + public ItemRenderer itemRenderer; + + public Text title; + public MinecraftClient client; + public SimpleHandledScreen(S handler, PlayerInventory inventory, Text title) { + super(handler, inventory, title); + fixScreen(); + this.handler = handler; + this.title = title; + + } + + @Deprecated + @Override + public S getScreenHandler() { + return getScreenHandlerOverride(); + } + + public S getScreenHandlerOverride() { + return super.getScreenHandler(); + } + + public T addDrawableChild_compatibility(T drawableElement) { + return super.addDrawableChild(drawableElement); + // addButton + } + + public T addSelectableChild_compatibility(T selectableElement) { + return super.addSelectableChild(selectableElement); + } + + public CompatibleTexturedButtonWidget addDrawableCTBW(CompatibleTexturedButtonWidget widget) { + return addDrawableChild_compatibility(widget); + } + + @Deprecated + @Override + protected void drawBackground(DrawContext context, float delta, int mouseX, int mouseY) { + DrawObjectDM drawObjectDM = new DrawObjectDM(context, this); + drawBackgroundOverride(new DrawBackgroundArgs(drawObjectDM, delta, mouseX, mouseY)); + } + + public abstract void drawBackgroundOverride(DrawBackgroundArgs args); + + @Deprecated + @Override + protected void drawForeground(DrawContext context, int mouseX, int mouseY) { + DrawObjectDM drawObjectDM = new DrawObjectDM(context, this); + drawForegroundOverride(new DrawForegroundArgs(drawObjectDM, mouseX, mouseY)); + } + + protected void drawForegroundOverride(DrawForegroundArgs args) { + super.drawForeground(args.drawObjectDM.getContext(), args.mouseX, args.mouseY); + } + + public void callDrawTexture(DrawObjectDM drawObjectDM, Identifier texture, int x, int y, int u, int v, int width, int height) { + drawObjectDM.getContext().drawTexture(texture, x, y, u, v, width, height, 256, 256); + } + + public void callDrawTexture(DrawObjectDM drawObjectDM, CompatIdentifier texture, int x, int y, int u, int v, int width, int height) { + callDrawTexture(drawObjectDM, texture.toMinecraft(), x, y, u, v, width, height); + } + + @Deprecated + public void callRenderBackground(DrawObjectDM drawObjectDM) { + callRenderBackground(new RenderArgs(drawObjectDM, 0, 0, 0)); + } + + + public void callRenderBackground(RenderArgs args) { + super.renderBackground(args.drawObjectDM.getContext(), args.mouseX, args.mouseY, args.delta); + } + + public void callDrawMouseoverTooltip(DrawMouseoverTooltipArgs args) { + super.drawMouseoverTooltip(args.drawObjectDM.getContext(), args.mouseX, args.mouseY); + } + + public void renderOverride(RenderArgs args) { + super.render(args.drawObjectDM.getContext(), args.mouseX, args.mouseY, args.delta); + } + + public void resizeOverride(MinecraftClient client, int width, int height) { + } + + public void initOverride() { + } + + @Deprecated + @Override + protected void init() { + super.init(); + fixScreen(); + initOverride(); + } + + @Deprecated + @Override + public void resize(MinecraftClient client, int width, int height) { + super.resize(client, width, height); + fixScreen(); + resizeOverride(client, width, height); + } + + public void fixScreen() { + this.backgroundWidth = getBackgroundWidth(); + this.backgroundHeight = getBackgroundHeight(); + this.x = super.x; //(this.width - this.backgroundWidth) / 2; + this.y = super.y; //(this.height - this.backgroundHeight) / 2; + this.textRenderer = super.textRenderer; + this.itemRenderer = MinecraftClient.getInstance().getItemRenderer(); + this.width = super.width; + this.height = super.height; + if (super.client == null) + this.client = MinecraftClient.getInstance(); + else + this.client = super.client; + } + + public void setX(int x) { + this.x = x; + super.x = x; + } + + public void setY(int y) { + this.y = y; + super.y = y; + } + + public void setTextRenderer(TextRenderer textRenderer) { + this.textRenderer = textRenderer; + super.textRenderer = textRenderer; + } + + public void setItemRenderer(ItemRenderer itemRenderer) { + this.itemRenderer = itemRenderer; + } + + public void setWidth(int width) { + this.width = width; + super.width = width; + } + + public void setBackgroundWidth(int backgroundWidth) { + this.backgroundWidth = backgroundWidth; + super.backgroundWidth = backgroundWidth; + } + + public void setBackgroundHeight(int backgroundHeight) { + this.backgroundHeight = backgroundHeight; + super.backgroundHeight = backgroundHeight; + } + + public void setHeight(int height) { + this.height = height; + super.height = height; + } + + public int getBackgroundWidth() { + return super.backgroundWidth; + } + + public int getBackgroundHeight() { + return super.backgroundHeight; + } + + @Deprecated + @Override + public void render(DrawContext context, int mouseX, int mouseY, float delta) { + DrawObjectDM drawObjectDM = new DrawObjectDM(context, this); + renderOverride(new RenderArgs(drawObjectDM, mouseX, mouseY, delta)); + } + + public boolean keyReleased(KeyEventArgs args) { + return super.keyReleased(args.keyCode, args.scanCode, args.modifiers); + } + + public boolean keyPressed(KeyEventArgs args) { + return super.keyPressed(args.keyCode, args.scanCode, args.modifiers); + } + + public void renderBackgroundTexture(RenderBackgroundTextureArgs args) { + if (getBackgroundTexture() != null) + Screen.renderBackgroundTexture(args.getDrawObjectDM().getContext(), getBackgroundTexture(), x, y, 0, 0, this.width, this.height); + + RenderUtil.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); + callDrawTexture(args.drawObjectDM, getBackgroundTexture(), 0, 0, 0, 0, width, height); + } + + @Deprecated + @Override + public boolean keyReleased(int keyCode, int scanCode, int modifiers) { + return this.keyReleased(new KeyEventArgs(keyCode, scanCode, modifiers)); + } + + @Deprecated + @Override + public boolean keyPressed(int keyCode, int scanCode, int modifiers) { + return this.keyPressed(new KeyEventArgs(keyCode, scanCode, modifiers)); + } + + @Deprecated + @Override + public void renderDarkening(DrawContext context) { + this.renderBackgroundTexture(new RenderBackgroundTextureArgs(new DrawObjectDM(context, this), 0)); + } + + public void closeOverride() { + super.close(); + } + + public void removedOverride() { + super.removed(); + } + + @Override + public void close() { + closeOverride(); + } + + @Override + public void removed() { + removedOverride(); + } + + public Identifier getBackgroundTexture() { + return IdentifierUtil.from(getCompatBackgroundTexture()); + } + + public CompatIdentifier getCompatBackgroundTexture() { + return null; + } + + public void setTitleX(int x) { + this.titleX = x; + } + + public void setTitleY(int y) { + this.titleY = y; + } + + public void setTitlePos(int x, int y) { + setTitleX(x); + setTitleY(y); + } + + public void setTitleXCenter() { + if (textRenderer == null) + textRenderer = ClientUtil.getTextRenderer(); + + setTitleX(backgroundWidth / 2 - textRenderer.getWidth(title) / 2); + } + + public int getTitleX() { + return titleX; + } + + public int getTitleY() { + return titleY; + } + + public void drawText(DrawObjectDM drawObjectDM, Text text, int x, int y, int color) { + ScreenUtil.RendererUtil.drawText(textRenderer, drawObjectDM, text, x, y, color); + } + + public void drawText(DrawObjectDM drawObjectDM, TextComponent text, int x, int y, int color) { + ScreenUtil.RendererUtil.drawText(textRenderer, drawObjectDM, text, x, y, color); + } + + public void drawText(DrawObjectDM drawObjectDM, Text text, int x, int y) { + ScreenUtil.RendererUtil.drawText(textRenderer, drawObjectDM, text, x, y); + } + + public void drawText(DrawObjectDM drawObjectDM, TextComponent text, int x, int y) { + ScreenUtil.RendererUtil.drawText(textRenderer, drawObjectDM, text, x, y); + } + + @Deprecated + @Override + public Text getTitle() { + return callGetTitle(); + } + + public Text callGetTitle() { + return super.getTitle(); + } + + public Pair getTitlePosP() { + return new Pair<>(getTitleX(), getTitleY()); + } + + public int getPlayerInvTitleX() { + return playerInventoryTitleX; + } + + public int getPlayerInvTitleY() { + return playerInventoryTitleY; + } + + public void setPlayerInvTitleX(int x) { + playerInventoryTitleX = x; + } + + public void setPlayerInvTitleY(int y) { + playerInventoryTitleY = y; + } + + public void setPlayerInvTitle(int x, int y) { + setPlayerInvTitleX(x); + setPlayerInvTitleY(y); + } + + public TextRenderer callGetTextRenderer() { + if (textRenderer != null) + return textRenderer; + + if (super.textRenderer != null) + return super.textRenderer; + + return ClientUtil.getTextRenderer(); + } + + public ItemRenderer callGetItemRenderer() { + if (itemRenderer != null) + return itemRenderer; + + return ClientUtil.getItemRenderer(); + } + + public Text getPlayerInvTitle() { + return playerInventoryTitle; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/client/gui/screen/SimpleInventoryScreen.java b/common/src/main/java/net/pitan76/mcpitanlib/api/client/gui/screen/SimpleInventoryScreen.java new file mode 100644 index 000000000..daa47269d --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/gui/screen/SimpleInventoryScreen.java @@ -0,0 +1,38 @@ +package net.pitan76.mcpitanlib.api.client.gui.screen; + +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.screen.ScreenHandler; +import net.minecraft.text.Text; +import net.minecraft.util.Identifier; +import net.pitan76.mcpitanlib.api.client.render.handledscreen.DrawBackgroundArgs; +import net.pitan76.mcpitanlib.api.client.render.handledscreen.DrawMouseoverTooltipArgs; +import net.pitan76.mcpitanlib.api.client.render.handledscreen.RenderArgs; +import net.pitan76.mcpitanlib.api.util.client.RenderUtil; + +public abstract class SimpleInventoryScreen extends SimpleHandledScreen { + + public SimpleInventoryScreen(S handler, PlayerInventory inventory, Text title) { + super(handler, inventory, title); + } + + public abstract Identifier getTexture(); + + @Override + public Identifier getBackgroundTexture() { + return getTexture(); + } + + @Override + public void drawBackgroundOverride(DrawBackgroundArgs args) { + RenderUtil.setShaderToPositionTexProgram(); + RenderUtil.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); + callDrawTexture(args.drawObjectDM, getTexture(), x, y, 0, 0, backgroundWidth, backgroundHeight); + } + + @Override + public void renderOverride(RenderArgs args) { + this.callRenderBackground(args); + super.renderOverride(args); + this.callDrawMouseoverTooltip(new DrawMouseoverTooltipArgs(args.drawObjectDM, args.mouseX, args.mouseY)); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/client/gui/widget/CompatTextFieldWidget.java b/common/src/main/java/net/pitan76/mcpitanlib/api/client/gui/widget/CompatTextFieldWidget.java new file mode 100644 index 000000000..a29256a75 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/gui/widget/CompatTextFieldWidget.java @@ -0,0 +1,143 @@ +package net.pitan76.mcpitanlib.api.client.gui.widget; + +import net.minecraft.client.font.TextRenderer; +import net.minecraft.client.gui.widget.TextFieldWidget; +import net.minecraft.text.Text; +import net.pitan76.mcpitanlib.api.util.TextUtil; +import org.jetbrains.annotations.Nullable; + +public class CompatTextFieldWidget extends TextFieldWidget { + public CompatTextFieldWidget(TextRenderer textRenderer, int width, int height) { + this(textRenderer, width, height, TextUtil.empty()); + } + + public CompatTextFieldWidget(TextRenderer textRenderer, int x, int y, int width, int height) { + this(textRenderer, x, y, width, height, TextUtil.empty()); + } + + // ---- + + public CompatTextFieldWidget(TextRenderer textRenderer, int width, int height, Text text) { + super(textRenderer, width, height, text); + } + + public CompatTextFieldWidget(TextRenderer textRenderer, int x, int y, int width, int height, Text text) { + super(textRenderer, x, y, width, height, text); + } + + public CompatTextFieldWidget(TextRenderer textRenderer, int x, int y, int width, int height, @Nullable TextFieldWidget copyFrom, Text text) { + super(textRenderer, x, y, width, height, copyFrom, text); + } + + // ---- + + @Deprecated + @Override + public void setDrawsBackground(boolean drawsBackground) { + callSetDrawsBackground(drawsBackground); + } + + public void callSetDrawsBackground(boolean drawsBackground) { + super.setDrawsBackground(drawsBackground); + } + + @Deprecated + @Override + public void setFocused(boolean focused) { + callSetFocused(focused); + } + + public void callSetFocused(boolean focused) { + super.setFocused(focused); + } + + @Deprecated + @Override + public void setFocusUnlocked(boolean focusUnlocked) { + callSetFocusUnlocked(focusUnlocked); + } + + public void callSetFocusUnlocked(boolean focusUnlocked) { + super.setFocusUnlocked(focusUnlocked); + } + + @Deprecated + @Override + public void setMaxLength(int maxLength) { + callSetMaxLength(maxLength); + } + + public void callSetMaxLength(int maxLength) { + super.setMaxLength(maxLength); + } + + @Deprecated + @Override + public void setText(String text) { + callSetText(text); + } + + public void callSetText(String text) { + super.setText(text); + } + + @Deprecated + @Override + public String getText() { + return callGetText(); + } + + public String callGetText() { + return super.getText(); + } + + @Deprecated + @Override + public void setEditable(boolean editable) { + callSetEditable(editable); + } + + public void callSetEditable(boolean editable) { + super.setEditable(editable); + } + + @Deprecated + @Override + public boolean isFocused() { + return callIsFocused(); + } + + public boolean callIsFocused() { + return super.isFocused(); + } + + @Deprecated + @Override + public boolean keyPressed(int keyCode, int scanCode, int modifiers) { + return callKeyPressed(keyCode, scanCode, modifiers); + } + + public boolean callKeyPressed(int keyCode, int scanCode, int modifiers) { + return super.keyPressed(keyCode, scanCode, modifiers); + } + + @Deprecated + @Override + public boolean keyReleased(int keyCode, int scanCode, int modifiers) { + return callKeyReleased(keyCode, scanCode, modifiers); + } + + public boolean callKeyReleased(int keyCode, int scanCode, int modifiers) { + return super.keyReleased(keyCode, scanCode, modifiers); + } + + @Deprecated + @Override + public boolean charTyped(char chr, int modifiers) { + return callCharTyped(chr, modifiers); + } + + public boolean callCharTyped(char chr, int modifiers) { + return super.charTyped(chr, modifiers); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/client/gui/widget/CompatibleTexturedButtonWidget.java b/common/src/main/java/net/pitan76/mcpitanlib/api/client/gui/widget/CompatibleTexturedButtonWidget.java new file mode 100644 index 000000000..570ccc957 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/gui/widget/CompatibleTexturedButtonWidget.java @@ -0,0 +1,73 @@ +package net.pitan76.mcpitanlib.api.client.gui.widget; + +import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.gui.screen.ButtonTextures; +import net.minecraft.client.gui.widget.ButtonWidget; +import net.minecraft.client.gui.widget.TexturedButtonWidget; +import net.minecraft.text.Text; +import net.minecraft.util.Identifier; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.api.util.TextUtil; + +public class CompatibleTexturedButtonWidget extends TexturedButtonWidget { + private final Identifier texture; + private final int u; + private final int v; + private final int hoveredVOffset; + private final int textureWidth; + private final int textureHeight; + + public CompatibleTexturedButtonWidget(int x, int y, int width, int height, int u, int v, Identifier texture, ButtonWidget.PressAction pressAction) { + this(x, y, width, height, u, v, height, texture, 256, 256, pressAction); + } + + public CompatibleTexturedButtonWidget(int x, int y, int width, int height, int u, int v, int hoveredVOffset, Identifier texture, ButtonWidget.PressAction pressAction) { + this(x, y, width, height, u, v, hoveredVOffset, texture, 256, 256, pressAction); + } + + public CompatibleTexturedButtonWidget(int x, int y, int width, int height, int u, int v, int hoveredVOffset, Identifier texture, int textureWidth, int textureHeight, ButtonWidget.PressAction pressAction) { + this(x, y, width, height, u, v, hoveredVOffset, texture, textureWidth, textureHeight, pressAction, TextUtil.empty()); + } + + public CompatibleTexturedButtonWidget(int x, int y, int width, int height, int u, int v, int hoveredVOffset, Identifier texture, int textureWidth, int textureHeight, ButtonWidget.PressAction pressAction, Text text) { + super(x, y, width, height, new ButtonTextures(texture, texture), pressAction, text); + this.textureWidth = textureWidth; + this.textureHeight = textureHeight; + this.u = u; + this.v = v; + this.hoveredVOffset = hoveredVOffset; + this.texture = texture; + } + + public CompatibleTexturedButtonWidget(int x, int y, int width, int height, int u, int v, CompatIdentifier texture, ButtonWidget.PressAction pressAction) { + this(x, y, width, height, u, v, texture.toMinecraft(), pressAction); + } + + public CompatibleTexturedButtonWidget(int x, int y, int width, int height, int u, int v, int hoveredVOffset, CompatIdentifier texture, ButtonWidget.PressAction pressAction) { + this(x, y, width, height, u, v, hoveredVOffset, texture.toMinecraft(), pressAction); + } + + public CompatibleTexturedButtonWidget(int x, int y, int width, int height, int u, int v, int hoveredVOffset, CompatIdentifier texture, int textureWidth, int textureHeight, ButtonWidget.PressAction pressAction) { + this(x, y, width, height, u, v, hoveredVOffset, texture.toMinecraft(), textureWidth, textureHeight, pressAction); + } + + public CompatibleTexturedButtonWidget(int x, int y, int width, int height, int u, int v, int hoveredVOffset, CompatIdentifier texture, int textureWidth, int textureHeight, ButtonWidget.PressAction pressAction, Text text) { + this(x, y, width, height, u, v, hoveredVOffset, texture.toMinecraft(), textureWidth, textureHeight, pressAction, text); + } + + public void setPos(int x, int y) { + setX(x); + setY(y); + } + + @Override + public void renderWidget(DrawContext context, int mouseX, int mouseY, float delta) { + int i = v; + if (!this.isNarratable()) { + i = v + hoveredVOffset * 2; + } else if (this.isHovered()) { + i += hoveredVOffset; + } + context.drawTexture(texture, this.getX(), this.getY(), u, i, this.width, this.height, textureWidth, textureHeight); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/client/gui/widget/RedrawableTexturedButtonWidget.java b/common/src/main/java/net/pitan76/mcpitanlib/api/client/gui/widget/RedrawableTexturedButtonWidget.java new file mode 100644 index 000000000..ba6363c39 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/gui/widget/RedrawableTexturedButtonWidget.java @@ -0,0 +1,52 @@ +package net.pitan76.mcpitanlib.api.client.gui.widget; + +import net.minecraft.client.gui.DrawContext; +import net.minecraft.text.Text; +import net.minecraft.util.Identifier; + +public class RedrawableTexturedButtonWidget extends CompatibleTexturedButtonWidget { + public Identifier texture; + public int u; + public int v; + public int hoveredVOffset; + public int textureWidth; + public int textureHeight; + + public RedrawableTexturedButtonWidget(int x, int y, int width, int height, int u, int v, int hoveredVOffset, Identifier texture, int textureWidth, int textureHeight, PressAction pressAction, Text message) { + super(x, y, width, height, u, v, hoveredVOffset, texture, textureWidth, textureHeight, pressAction, message); + this.textureWidth = textureWidth; + this.textureHeight = textureHeight; + this.u = u; + this.v = v; + this.hoveredVOffset = hoveredVOffset; + this.texture = texture; + } + + public void renderButton(DrawContext context, int mouseX, int mouseY, float delta) { + super.renderWidget(context, mouseX, mouseY, delta); + } + + public void setTexture(Identifier texture) { + this.texture = texture; + } + + public void setU(int u) { + this.u = u; + } + + public void setV(int v) { + this.v = v; + } + + public void setHoveredVOffset(int hoveredVOffset) { + this.hoveredVOffset = hoveredVOffset; + } + + public void setTextureWidth(int textureWidth) { + this.textureWidth = textureWidth; + } + + public void setTextureHeight(int textureHeight) { + this.textureHeight = textureHeight; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/client/gui/widget/SimpleListWidget.java b/common/src/main/java/net/pitan76/mcpitanlib/api/client/gui/widget/SimpleListWidget.java new file mode 100644 index 000000000..d93a910dd --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/gui/widget/SimpleListWidget.java @@ -0,0 +1,115 @@ +package net.pitan76.mcpitanlib.api.client.gui.widget; + +import com.google.common.collect.ImmutableList; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.gui.Element; +import net.minecraft.client.gui.Selectable; +import net.minecraft.client.gui.widget.ClickableWidget; +import net.minecraft.client.gui.widget.ElementListWidget; +import net.pitan76.mcpitanlib.api.client.render.handledscreen.RenderArgs; +import org.jetbrains.annotations.Nullable; + +import java.util.List; +import java.util.Optional; + +@Environment(EnvType.CLIENT) +public class SimpleListWidget extends ElementListWidget { + + public SimpleListWidget(MinecraftClient client, int width, int height, int top, int bottom, int itemHeight) { + this(client, width, bottom - top, top, itemHeight); + } + + public SimpleListWidget(MinecraftClient client, int width, int height, int y, int itemHeight) { + super(client, width, height, y, itemHeight); + this.centerListVertically = false; + } + + public void add(ClickableWidget widget) { + super.addEntry(WidgetEntry.create(widget)); + } + + @Override + public int getRowWidth() { + return 400; + } + + public int getWidth() { + return this.width; + } + + public int getHeight() { + return this.height; + } + + @Override + protected int getScrollbarX() { + return super.getScrollbarX() + 32; + } + + @Nullable + public ClickableWidget getWidget(int index) { + if (index < 0 || index >= this.children().size()) { + return null; + } + return this.children().get(index).getWidget(); + } + + public Optional getHoveredWidget(double mouseX, double mouseY) { + for (WidgetEntry entry : this.children()) { + if (entry.getWidget().isMouseOver(mouseX, mouseY)) { + return Optional.of(entry.getWidget()); + } + } + return Optional.empty(); + } + + /* + @Override + public void render(DrawContext context, int mouseX, int mouseY, float delta) { + this.render(new RenderArgs(new DrawObjectDM(context), mouseX, mouseY, delta)); + } + */ + + public void render(RenderArgs args) { + super.render(args.drawObjectDM.getContext(), args.mouseX, args.mouseY, args.delta); + } + + @Environment(EnvType.CLIENT) + public static class WidgetEntry extends Entry { + protected final ClickableWidget widget; + + public WidgetEntry(ClickableWidget widget) { + this.widget = widget; + } + + public static WidgetEntry create(ClickableWidget widget) { + return new WidgetEntry(widget); + } + + @Deprecated + @Override + public void render(DrawContext matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) { + widget.setY(y); + widget.render(matrices, mouseX, mouseY, tickDelta); + } + + @Deprecated + @Override + public List children() { + return ImmutableList.of(widget); + } + + @Deprecated + @Override + public List selectableChildren() { + return ImmutableList.of(widget); + } + + public ClickableWidget getWidget() { + return widget; + } + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/client/gui/widget/SimpleSliderWidget.java b/common/src/main/java/net/pitan76/mcpitanlib/api/client/gui/widget/SimpleSliderWidget.java new file mode 100644 index 000000000..7c4b87d68 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/gui/widget/SimpleSliderWidget.java @@ -0,0 +1,82 @@ +package net.pitan76.mcpitanlib.api.client.gui.widget; + +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.gui.widget.SliderWidget; +import net.minecraft.text.Text; +import net.pitan76.mcpitanlib.api.client.render.DrawObjectDM; +import net.pitan76.mcpitanlib.api.client.render.handledscreen.RenderArgs; +import net.pitan76.mcpitanlib.api.util.TextUtil; + +import java.util.function.Consumer; +import java.util.function.Function; + +@Environment(EnvType.CLIENT) +public class SimpleSliderWidget extends SliderWidget { + protected final Function textGetter; + protected final Consumer changeCallback; + public SimpleListWidget listWidget = null; + + public SimpleSliderWidget(int x, int y, int width, int height, Text text, double defaultValue, ValueTextGetter valueTextGetter, Consumer changeCallback) { + super(x, y, width, height, text, defaultValue); + this.textGetter = (Double value) -> valueTextGetter.get(text, value); + this.changeCallback = changeCallback; + this.updateMessage(); + } + public SimpleSliderWidget(int x, int y, int width, int height, double defaultValue, ValueTextGetter valueTextGetter, Consumer changeCallback) { + this(x, y, width, height, TextUtil.empty(), defaultValue, valueTextGetter, changeCallback); + } + + public SimpleSliderWidget(int x, int y, int width, Text text, double defaultValue, ValueTextGetter valueTextGetter, Consumer changeCallback) { + this(x, y, width, 20, text, defaultValue, valueTextGetter, changeCallback); + } + + public SimpleSliderWidget(int x, int y, int width, double defaultValue, ValueTextGetter valueTextGetter, Consumer changeCallback) { + this(x, y, width, 20, defaultValue, valueTextGetter, changeCallback); + } + + public SimpleSliderWidget(SimpleListWidget listWidget, int width, Text text, double defaultValue, ValueTextGetter valueTextGetter, Consumer changeCallback) { + this(listWidget.getWidth() / 2 - 155, 0, width, 20, text, defaultValue, valueTextGetter, changeCallback); + this.listWidget = listWidget; + } + + public SimpleSliderWidget(SimpleListWidget listWidget, int width, double defaultValue, ValueTextGetter valueTextGetter, Consumer changeCallback) { + this(listWidget, width, TextUtil.empty(), defaultValue, valueTextGetter, changeCallback); + } + + /* + @Override + public void render(DrawContext context, int mouseX, int mouseY, float delta) { + this.render(new RenderArgs(new DrawObjectDM(context), mouseX, mouseY, delta)); + } + */ + + public void render(RenderArgs args) { + super.render(args.drawObjectDM.getContext(), args.mouseX, args.mouseY, args.delta); + } + + public void setValue(double value) { + super.value = value; + } + + public double getValue() { + return super.value; + } + + @Override + protected void updateMessage() { + this.setMessage(this.textGetter.apply(this.getValue())); + } + + @Override + protected void applyValue() { + this.changeCallback.accept(this.getValue()); + } + + @Environment(EnvType.CLIENT) + @FunctionalInterface + public interface ValueTextGetter { + Text get(Text optionText, Double value); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/client/option/CompatKeyBinding.java b/common/src/main/java/net/pitan76/mcpitanlib/api/client/option/CompatKeyBinding.java new file mode 100644 index 000000000..ab95ef05b --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/option/CompatKeyBinding.java @@ -0,0 +1,57 @@ +package net.pitan76.mcpitanlib.api.client.option; + +import net.minecraft.client.option.KeyBinding; +import net.minecraft.text.Text; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; + +import java.util.Objects; + +public class CompatKeyBinding { + private final KeyBinding keyBinding; + + public CompatKeyBinding(KeyBinding keyBinding) { + this.keyBinding = keyBinding; + } + + public CompatKeyBinding(String translationKey, int defaultKeyCode, CompatIdentifier category) { + this.keyBinding = new KeyBinding(translationKey, defaultKeyCode, "key.category." + category.getNamespace() + "." + category.getPath()); + } + + public CompatKeyBinding(String translationKey, int defaultKeyCode) { + String[] parts = translationKey.split("\\."); + if (Objects.equals(parts[0], "key") && parts.length == 3) { + CompatIdentifier category = CompatIdentifier.of(parts[1], "main"); + this.keyBinding = new KeyBinding(translationKey, defaultKeyCode, "key.category." + category.getNamespace() + "." + category.getPath()); + } else { + throw new IllegalArgumentException("Cannot infer category from translation key: " + translationKey); + } + } + + public String getTranslationKey() { + return keyBinding.getBoundKeyTranslationKey(); + } + + public Text getBoundKeyLocalizedText() { + return keyBinding.getBoundKeyLocalizedText(); + } + + public int getDefaultKeyCode() { + return keyBinding.getDefaultKey().getCode(); + } + + public static CompatKeyBinding of(String translationKey, int defaultKeyCode, CompatIdentifier category) { + return new CompatKeyBinding(translationKey, defaultKeyCode, category); + } + + public static CompatKeyBinding of(String translationKey, int defaultKeyCode) { + return new CompatKeyBinding(translationKey, defaultKeyCode); + } + + public KeyBinding toMinecraft() { + return keyBinding; + } + + public KeyBinding getRaw() { + return keyBinding; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/client/option/GameOptionsWrapper.java b/common/src/main/java/net/pitan76/mcpitanlib/api/client/option/GameOptionsWrapper.java new file mode 100644 index 000000000..3bdfa6bfe --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/option/GameOptionsWrapper.java @@ -0,0 +1,19 @@ +package net.pitan76.mcpitanlib.api.client.option; + +import net.minecraft.client.option.GameOptions; + +public class GameOptionsWrapper { + public final GameOptions raw; + + public GameOptionsWrapper(GameOptions options) { + this.raw = options; + } + + public GameOptions getRaw() { + return raw; + } + + public void write() { + raw.write(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/client/option/KeyCodes.java b/common/src/main/java/net/pitan76/mcpitanlib/api/client/option/KeyCodes.java new file mode 100644 index 000000000..27187f69f --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/option/KeyCodes.java @@ -0,0 +1,127 @@ +package net.pitan76.mcpitanlib.api.client.option; + +import org.lwjgl.glfw.GLFW; + +public class KeyCodes { + public static final int KEY_UNKNOWN = GLFW.GLFW_KEY_UNKNOWN, + KEY_SPACE = GLFW.GLFW_KEY_SPACE, + KEY_APOSTROPHE = GLFW.GLFW_KEY_APOSTROPHE, + KEY_COMMA = GLFW.GLFW_KEY_COMMA, + KEY_MINUS = GLFW.GLFW_KEY_MINUS, + KEY_PERIOD = GLFW.GLFW_KEY_PERIOD, + KEY_SLASH = GLFW.GLFW_KEY_SLASH, + KEY_0 = GLFW.GLFW_KEY_0, + KEY_1 = GLFW.GLFW_KEY_1, + KEY_2 = GLFW.GLFW_KEY_2, + KEY_3 = GLFW.GLFW_KEY_3, + KEY_4 = GLFW.GLFW_KEY_4, + KEY_5 = GLFW.GLFW_KEY_5, + KEY_6 = GLFW.GLFW_KEY_6, + KEY_7 = GLFW.GLFW_KEY_7, + KEY_8 = GLFW.GLFW_KEY_8, + KEY_9 = GLFW.GLFW_KEY_9, + KEY_SEMICOLON = GLFW.GLFW_KEY_SEMICOLON, + KEY_EQUAL = GLFW.GLFW_KEY_EQUAL, + KEY_A = GLFW.GLFW_KEY_A, + KEY_B = GLFW.GLFW_KEY_B, + KEY_C = GLFW.GLFW_KEY_C, + KEY_D = GLFW.GLFW_KEY_D, + KEY_E = GLFW.GLFW_KEY_E, + KEY_F = GLFW.GLFW_KEY_F, + KEY_G = GLFW.GLFW_KEY_G, + KEY_H = GLFW.GLFW_KEY_H, + KEY_I = GLFW.GLFW_KEY_I, + KEY_J = GLFW.GLFW_KEY_J, + KEY_K = GLFW.GLFW_KEY_K, + KEY_L = GLFW.GLFW_KEY_L, + KEY_M = GLFW.GLFW_KEY_M, + KEY_N = GLFW.GLFW_KEY_N, + KEY_O = GLFW.GLFW_KEY_O, + KEY_P = GLFW.GLFW_KEY_P, + KEY_Q = GLFW.GLFW_KEY_Q, + KEY_R = GLFW.GLFW_KEY_R, + KEY_S = GLFW.GLFW_KEY_S, + KEY_T = GLFW.GLFW_KEY_T, + KEY_U = GLFW.GLFW_KEY_U, + KEY_V = GLFW.GLFW_KEY_V, + KEY_W = GLFW.GLFW_KEY_W, + KEY_X = GLFW.GLFW_KEY_X, + KEY_Y = GLFW.GLFW_KEY_Y, + KEY_Z = GLFW.GLFW_KEY_Z, + KEY_LEFT_BRACKET = GLFW.GLFW_KEY_LEFT_BRACKET, + KEY_BACKSLASH = GLFW.GLFW_KEY_BACKSLASH, + KEY_RIGHT_BRACKET = GLFW.GLFW_KEY_RIGHT_BRACKET, + KEY_GRAVE_ACCENT = GLFW.GLFW_KEY_GRAVE_ACCENT, + KEY_WORLD_1 = GLFW.GLFW_KEY_WORLD_1, + KEY_WORLD_2 = GLFW.GLFW_KEY_WORLD_2, + KEY_ESCAPE = GLFW.GLFW_KEY_ESCAPE, + KEY_ENTER = GLFW.GLFW_KEY_ENTER, + KEY_TAB = GLFW.GLFW_KEY_TAB, + KEY_BACKSPACE = GLFW.GLFW_KEY_BACKSPACE, + KEY_INSERT = GLFW.GLFW_KEY_INSERT, + KEY_DELETE = GLFW.GLFW_KEY_DELETE, + KEY_RIGHT = GLFW.GLFW_KEY_RIGHT, + KEY_LEFT = GLFW.GLFW_KEY_LEFT, + KEY_DOWN = GLFW.GLFW_KEY_DOWN, + KEY_UP = GLFW.GLFW_KEY_UP, + KEY_PAGE_UP = GLFW.GLFW_KEY_PAGE_UP, + KEY_PAGE_DOWN = GLFW.GLFW_KEY_PAGE_DOWN, + KEY_HOME = GLFW.GLFW_KEY_HOME, + KEY_END = GLFW.GLFW_KEY_END, + KEY_CAPS_LOCK = GLFW.GLFW_KEY_CAPS_LOCK, + KEY_SCROLL_LOCK = GLFW.GLFW_KEY_SCROLL_LOCK, + KEY_NUM_LOCK = GLFW.GLFW_KEY_NUM_LOCK, + KEY_PRINT_SCREEN = GLFW.GLFW_KEY_PRINT_SCREEN, + KEY_PAUSE = GLFW.GLFW_KEY_PAUSE, + KEY_F1 = GLFW.GLFW_KEY_F1, + KEY_F2 = GLFW.GLFW_KEY_F2, + KEY_F3 = GLFW.GLFW_KEY_F3, + KEY_F4 = GLFW.GLFW_KEY_F4, + KEY_F5 = GLFW.GLFW_KEY_F5, + KEY_F6 = GLFW.GLFW_KEY_F6, + KEY_F7 = GLFW.GLFW_KEY_F7, + KEY_F8 = GLFW.GLFW_KEY_F8, + KEY_F9 = GLFW.GLFW_KEY_F9, + KEY_F10 = GLFW.GLFW_KEY_F10, + KEY_F11 = GLFW.GLFW_KEY_F11, + KEY_F12 = GLFW.GLFW_KEY_F12, + KEY_F13 = GLFW.GLFW_KEY_F13, + KEY_F14 = GLFW.GLFW_KEY_F14, + KEY_F15 = GLFW.GLFW_KEY_F15, + KEY_F16 = GLFW.GLFW_KEY_F16, + KEY_F17 = GLFW.GLFW_KEY_F17, + KEY_F18 = GLFW.GLFW_KEY_F18, + KEY_F19 = GLFW.GLFW_KEY_F19, + KEY_F20 = GLFW.GLFW_KEY_F20, + KEY_F21 = GLFW.GLFW_KEY_F21, + KEY_F22 = GLFW.GLFW_KEY_F22, + KEY_F23 = GLFW.GLFW_KEY_F23, + KEY_F24 = GLFW.GLFW_KEY_F24, + KEY_F25 = GLFW.GLFW_KEY_F25, + KEY_KP_0 = GLFW.GLFW_KEY_KP_0, + KEY_KP_1 = GLFW.GLFW_KEY_KP_1, + KEY_KP_2 = GLFW.GLFW_KEY_KP_2, + KEY_KP_3 = GLFW.GLFW_KEY_KP_3, + KEY_KP_4 = GLFW.GLFW_KEY_KP_4, + KEY_KP_5 = GLFW.GLFW_KEY_KP_5, + KEY_KP_6 = GLFW.GLFW_KEY_KP_6, + KEY_KP_7 = GLFW.GLFW_KEY_KP_7, + KEY_KP_8 = GLFW.GLFW_KEY_KP_8, + KEY_KP_9 = GLFW.GLFW_KEY_KP_9, + KEY_KP_DECIMAL = GLFW.GLFW_KEY_KP_DECIMAL, + KEY_KP_DIVIDE = GLFW.GLFW_KEY_KP_DIVIDE, + KEY_KP_MULTIPLY = GLFW.GLFW_KEY_KP_MULTIPLY, + KEY_KP_SUBTRACT = GLFW.GLFW_KEY_KP_SUBTRACT, + KEY_KP_ADD = GLFW.GLFW_KEY_KP_ADD, + KEY_KP_ENTER = GLFW.GLFW_KEY_KP_ENTER, + KEY_KP_EQUAL = GLFW.GLFW_KEY_KP_EQUAL, + KEY_LEFT_SHIFT = GLFW.GLFW_KEY_LEFT_SHIFT, + KEY_LEFT_CONTROL = GLFW.GLFW_KEY_LEFT_CONTROL, + KEY_LEFT_ALT = GLFW.GLFW_KEY_LEFT_ALT, + KEY_LEFT_SUPER = GLFW.GLFW_KEY_LEFT_SUPER, + KEY_RIGHT_SHIFT = GLFW.GLFW_KEY_RIGHT_SHIFT, + KEY_RIGHT_CONTROL = GLFW.GLFW_KEY_RIGHT_CONTROL, + KEY_RIGHT_ALT = GLFW.GLFW_KEY_RIGHT_ALT, + KEY_RIGHT_SUPER = GLFW.GLFW_KEY_RIGHT_SUPER, + KEY_MENU = GLFW.GLFW_KEY_MENU; +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/client/registry/ArchRegistryClient.java b/common/src/main/java/net/pitan76/mcpitanlib/api/client/registry/ArchRegistryClient.java new file mode 100644 index 000000000..89a0facf0 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/registry/ArchRegistryClient.java @@ -0,0 +1,180 @@ +package net.pitan76.mcpitanlib.api.client.registry; + +import dev.architectury.registry.client.level.entity.EntityRendererRegistry; +import dev.architectury.registry.client.particle.ParticleProviderRegistry; +import dev.architectury.registry.client.rendering.BlockEntityRendererRegistry; +import dev.architectury.registry.client.rendering.RenderTypeRegistry; +import dev.architectury.registry.menu.MenuRegistry; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.block.Block; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.block.entity.BlockEntityType; +import net.minecraft.client.font.TextRenderer; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.gui.screen.ingame.ScreenHandlerProvider; +import net.minecraft.client.model.ModelPart; +import net.minecraft.client.particle.ParticleFactory; +import net.minecraft.client.particle.SpriteProvider; +import net.minecraft.client.render.RenderLayer; +import net.minecraft.client.render.block.BlockRenderManager; +import net.minecraft.client.render.block.entity.BlockEntityRenderDispatcher; +import net.minecraft.client.render.block.entity.BlockEntityRenderer; +import net.minecraft.client.render.entity.EntityRenderDispatcher; +import net.minecraft.client.render.entity.EntityRendererFactory; +import net.minecraft.client.render.entity.model.EntityModelLayer; +import net.minecraft.client.render.entity.model.EntityModelLoader; +import net.minecraft.client.render.item.ItemRenderer; +import net.minecraft.client.texture.Sprite; +import net.minecraft.client.texture.SpriteAtlasTexture; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityType; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.fluid.Fluid; +import net.minecraft.particle.ParticleEffect; +import net.minecraft.particle.ParticleType; +import net.minecraft.screen.ScreenHandler; +import net.minecraft.screen.ScreenHandlerType; +import net.minecraft.text.Text; +import net.minecraft.util.Identifier; +import net.minecraft.util.math.random.Random; + +import java.util.List; +import java.util.function.Supplier; + +@Deprecated +@Environment(EnvType.CLIENT) +public class ArchRegistryClient { + public static > void registerScreen(ScreenHandlerType type, ScreenFactory factory) { + MenuRegistry.registerScreenFactory(type, factory::create); + } + + public interface ScreenFactory> { + S create(H handler, PlayerInventory inventory, Text text); + } + + public static void registerParticle(ParticleType type, ParticleFactory factory) { + ParticleProviderRegistry.register(type, factory); + } + + public static void registerParticle(ParticleType type, DeferredParticleProvider provider) { + ParticleProviderRegistry.register(type, spriteSet -> provider.create(new ExtendedSpriteSet() { + @Override + public SpriteAtlasTexture getAtlas() { + return spriteSet.getAtlas(); + } + + @Override + public List getSprites() { + return spriteSet.getSprites(); + } + + @Override + public Sprite getSprite(int age, int maxAge) { + return spriteSet.getSprite(age, maxAge); + } + + @Override + public Sprite getSprite(Random random) { + return spriteSet.getSprite(random); + } + })); + } + + public static void registerEntityRenderer(Supplier> type, EntityRendererFactory provider) { + EntityRendererRegistry.register(type, provider); + } + + @FunctionalInterface + public interface DeferredParticleProvider { + ParticleFactory create(ExtendedSpriteSet spriteSet); + } + + public interface ExtendedSpriteSet extends SpriteProvider { + SpriteAtlasTexture getAtlas(); + + List getSprites(); + } + + public static void registryClientSpriteAtlasTexture(Identifier identifier) { + //registryClientSprite(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, identifier); + } + + public static void registryClientSpriteAtlasTexture(Sprite sprite) { + //registryClientSprite(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, sprite); + } + + public static void registryClientSprite(Identifier atlasId, Identifier identifier) { + // ~1.19.2 + } + + public static void registryClientSprite(Identifier atlasId, Sprite sprite) { + // ~1.19.2 + } + + public static void registerBlockEntityRenderer(BlockEntityType type, BlockEntityRendererFactory provider) { + BlockEntityRendererRegistry.register(type, ctx -> provider.create(new BlockEntityRendererFactory.Context( + ctx.getRenderDispatcher(), ctx.getRenderManager(), ctx.getItemRenderer(), ctx.getEntityRenderDispatcher(), ctx.getLayerRenderDispatcher(), ctx.getTextRenderer() + ))); + } + + @FunctionalInterface + public interface BlockEntityRendererFactory { + BlockEntityRenderer create(BlockEntityRendererFactory.Context ctx); + + class Context { + private final BlockEntityRenderDispatcher renderDispatcher; + private final BlockRenderManager renderManager; + private final ItemRenderer itemRenderer; + private final EntityRenderDispatcher entityRenderDispatcher; + private final EntityModelLoader layerRenderDispatcher; + private final TextRenderer textRenderer; + + public Context(BlockEntityRenderDispatcher renderDispatcher, BlockRenderManager renderManager, ItemRenderer itemRenderer, EntityRenderDispatcher entityRenderDispatcher, EntityModelLoader layerRenderDispatcher, TextRenderer textRenderer) { + this.renderDispatcher = renderDispatcher; + this.renderManager = renderManager; + this.itemRenderer = itemRenderer; + this.entityRenderDispatcher = entityRenderDispatcher; + this.layerRenderDispatcher = layerRenderDispatcher; + this.textRenderer = textRenderer; + } + + public BlockEntityRenderDispatcher getRenderDispatcher() { + return this.renderDispatcher; + } + + public BlockRenderManager getRenderManager() { + return this.renderManager; + } + + public EntityRenderDispatcher getEntityRenderDispatcher() { + return this.entityRenderDispatcher; + } + + public ItemRenderer getItemRenderer() { + return this.itemRenderer; + } + + public EntityModelLoader getLayerRenderDispatcher() { + return this.layerRenderDispatcher; + } + + public ModelPart getLayerModelPart(EntityModelLayer modelLayer) { + return this.layerRenderDispatcher.getModelPart(modelLayer); + } + + public TextRenderer getTextRenderer() { + return this.textRenderer; + } + } + } + + + public static void registerRenderTypeBlock(RenderLayer layer, Block block) { + RenderTypeRegistry.register(layer, block); + } + + public static void registerRenderTypeFluid(RenderLayer layer, Fluid fluid) { + RenderTypeRegistry.register(layer, fluid); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/client/registry/CompatRegistryClient.java b/common/src/main/java/net/pitan76/mcpitanlib/api/client/registry/CompatRegistryClient.java new file mode 100644 index 000000000..4925199d1 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/registry/CompatRegistryClient.java @@ -0,0 +1,222 @@ +package net.pitan76.mcpitanlib.api.client.registry; + +import dev.architectury.injectables.annotations.ExpectPlatform; +import dev.architectury.registry.client.level.entity.EntityModelLayerRegistry; +import dev.architectury.registry.client.level.entity.EntityRendererRegistry; +import dev.architectury.registry.client.particle.ParticleProviderRegistry; +import dev.architectury.registry.client.rendering.BlockEntityRendererRegistry; +import dev.architectury.registry.client.rendering.RenderTypeRegistry; +import dev.architectury.registry.menu.MenuRegistry; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.block.Block; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.block.entity.BlockEntityType; +import net.minecraft.client.color.block.BlockColorProvider; +import net.minecraft.client.font.TextRenderer; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.gui.screen.ingame.ScreenHandlerProvider; +import net.minecraft.client.model.ModelPart; +import net.minecraft.client.model.TexturedModelData; +import net.minecraft.client.particle.ParticleFactory; +import net.minecraft.client.particle.SpriteProvider; +import net.minecraft.client.render.RenderLayer; +import net.minecraft.client.render.block.BlockRenderManager; +import net.minecraft.client.render.block.entity.BlockEntityRenderDispatcher; +import net.minecraft.client.render.block.entity.BlockEntityRenderer; +import net.minecraft.client.render.entity.EntityRenderDispatcher; +import net.minecraft.client.render.entity.EntityRendererFactory; +import net.minecraft.client.render.entity.model.EntityModelLayer; +import net.minecraft.client.render.entity.model.EntityModelLoader; +import net.minecraft.client.render.item.ItemRenderer; +import net.minecraft.client.texture.Sprite; +import net.minecraft.client.texture.SpriteAtlasTexture; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityType; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.fluid.Fluid; +import net.minecraft.particle.ParticleEffect; +import net.minecraft.particle.ParticleType; +import net.minecraft.screen.ScreenHandler; +import net.minecraft.screen.ScreenHandlerType; +import net.minecraft.text.Text; +import net.minecraft.util.Identifier; +import net.minecraft.util.math.random.Random; +import net.pitan76.mcpitanlib.MCPitanLib; +import net.pitan76.mcpitanlib.api.client.color.CompatBlockColorProvider; +import net.pitan76.mcpitanlib.api.client.render.CompatRenderLayer; +import net.pitan76.mcpitanlib.api.client.render.EntityModelLayerContext; + +import java.util.List; +import java.util.function.Supplier; + +@Environment(EnvType.CLIENT) +public class CompatRegistryClient { + public static > void registerScreen(ScreenHandlerType type, ScreenFactory factory) { + registerScreen(MCPitanLib.MOD_ID, type, factory); + } + + public static > void registerScreen(String modId, ScreenHandlerType type, ScreenFactory factory) { + MenuRegistry.registerScreenFactory(type, factory::create); + } + + public interface ScreenFactory> { + S create(H handler, PlayerInventory inventory, Text text); + } + + public static void registerParticle(ParticleType type, ParticleFactory factory) { + ParticleProviderRegistry.register(type, factory); + } + + public static void registerParticle(ParticleType type, DeferredParticleProvider provider) { + ParticleProviderRegistry.register(type, spriteSet -> provider.create(new ExtendedSpriteSet() { + @Override + public SpriteAtlasTexture getAtlas() { + return spriteSet.getAtlas(); + } + + @Override + public List getSprites() { + return spriteSet.getSprites(); + } + + @Override + public Sprite getSprite(int age, int maxAge) { + return spriteSet.getSprite(age, maxAge); + } + + @Override + public Sprite getSprite(Random random) { + return spriteSet.getSprite(random); + } + })); + } + + public static void registerEntityModelLayer(EntityModelLayer layer, EntityModelLayerContext context) { + EntityModelLayerRegistry.register(layer, () -> TexturedModelData.of(context.getData(), context.getWidth(), context.getHeight())); + } + + public static void registerEntityRenderer(Supplier> type, EntityRendererFactory provider) { + EntityRendererRegistry.register(type, provider); + } + + @FunctionalInterface + public interface DeferredParticleProvider { + ParticleFactory create(ExtendedSpriteSet spriteSet); + } + + public interface ExtendedSpriteSet extends SpriteProvider { + SpriteAtlasTexture getAtlas(); + + List getSprites(); + } + + public static void registryClientSpriteAtlasTexture(Identifier identifier) { + //registryClientSprite(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, identifier); + } + + public static void registryClientSpriteAtlasTexture(Sprite sprite) { + //registryClientSprite(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, sprite); + } + + public static void registryClientSprite(Identifier atlasId, Identifier identifier) { + // ~1.19.2 + } + + public static void registryClientSprite(Identifier atlasId, Sprite sprite) { + // ~1.19.2 + } + + public static void registerBlockEntityRenderer(BlockEntityType type, BlockEntityRendererFactory provider) { + BlockEntityRendererRegistry.register(type, ctx -> provider.create(new BlockEntityRendererFactory.Context( + ctx.getRenderDispatcher(), ctx.getRenderManager(), ctx.getItemRenderer(), ctx.getEntityRenderDispatcher(), ctx.getLayerRenderDispatcher(), ctx.getTextRenderer() + ))); + } + + @FunctionalInterface + public interface BlockEntityRendererFactory { + BlockEntityRenderer create(Context ctx); + + class Context { + private final BlockEntityRenderDispatcher renderDispatcher; + private final BlockRenderManager renderManager; + private final ItemRenderer itemRenderer; + private final EntityRenderDispatcher entityRenderDispatcher; + private final EntityModelLoader layerRenderDispatcher; + private final TextRenderer textRenderer; + + public Context(BlockEntityRenderDispatcher renderDispatcher, BlockRenderManager renderManager, ItemRenderer itemRenderer, EntityRenderDispatcher entityRenderDispatcher, EntityModelLoader layerRenderDispatcher, TextRenderer textRenderer) { + this.renderDispatcher = renderDispatcher; + this.renderManager = renderManager; + this.itemRenderer = itemRenderer; + this.entityRenderDispatcher = entityRenderDispatcher; + this.layerRenderDispatcher = layerRenderDispatcher; + this.textRenderer = textRenderer; + } + + public BlockEntityRenderDispatcher getRenderDispatcher() { + return this.renderDispatcher; + } + + public BlockRenderManager getRenderManager() { + return this.renderManager; + } + + public EntityRenderDispatcher getEntityRenderDispatcher() { + return this.entityRenderDispatcher; + } + + public ItemRenderer getItemRenderer() { + return this.itemRenderer; + } + + public EntityModelLoader getLayerRenderDispatcher() { + return this.layerRenderDispatcher; + } + + public ModelPart getLayerModelPart(EntityModelLayer modelLayer) { + return this.layerRenderDispatcher.getModelPart(modelLayer); + } + + public TextRenderer getTextRenderer() { + return this.textRenderer; + } + } + } + + + public static void registerRenderTypeBlock(RenderLayer layer, Block block) { + RenderTypeRegistry.register(layer, block); + } + + public static void registerRenderTypeFluid(RenderLayer layer, Fluid fluid) { + RenderTypeRegistry.register(layer, fluid); + } + + public static void registerCutoutBlock(Block block) { + registerRenderTypeBlock(RenderLayer.getCutout(), block); + } + + public static void registerCompatBlockEntityRenderer(BlockEntityType type, BlockEntityRendererFactory provider) { + BlockEntityRendererRegistry.register(type, ctx -> provider.create(new BlockEntityRendererFactory.Context( + ctx.getRenderDispatcher(), ctx.getRenderManager(), ctx.getItemRenderer(), ctx.getEntityRenderDispatcher(), ctx.getLayerRenderDispatcher(), ctx.getTextRenderer() + ))); + } + + public static void registerRenderTypeBlock(CompatRenderLayer layer, Block block) { + registerRenderTypeBlock(layer.layer, block); + } + + public static void registerRenderTypeFluid(CompatRenderLayer layer, Fluid fluid) { + registerRenderTypeFluid(layer.layer, fluid); + } + + @ExpectPlatform + public static void registerColorProviderBlock(BlockColorProvider provider, Block... blocks) { + throw new AssertionError("This method should be replaced by the platform implementation"); + } + + public static void registerColorProviderBlock(CompatBlockColorProvider provider, Block... blocks) { + registerColorProviderBlock((BlockColorProvider) provider, blocks); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/client/registry/EntityRendererRegistry.java b/common/src/main/java/net/pitan76/mcpitanlib/api/client/registry/EntityRendererRegistry.java new file mode 100644 index 000000000..7fa99982f --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/registry/EntityRendererRegistry.java @@ -0,0 +1,13 @@ +package net.pitan76.mcpitanlib.api.client.registry; + +import net.minecraft.client.render.entity.EntityRenderer; +import net.minecraft.client.render.entity.FlyingItemEntityRenderer; +import net.minecraft.entity.EntityType; + +import java.util.function.Supplier; + +public class EntityRendererRegistry { + public static void registerEntityRendererAsFlyingItem(Supplier> entityType) { + CompatRegistryClient.registerEntityRenderer(entityType, (ctx -> (EntityRenderer) new FlyingItemEntityRenderer<>(ctx))); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/client/registry/KeybindingRegistry.java b/common/src/main/java/net/pitan76/mcpitanlib/api/client/registry/KeybindingRegistry.java new file mode 100644 index 000000000..771f39bc4 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/registry/KeybindingRegistry.java @@ -0,0 +1,38 @@ +package net.pitan76.mcpitanlib.api.client.registry; + +import dev.architectury.registry.client.keymappings.KeyMappingRegistry; +import net.minecraft.client.option.KeyBinding; +import net.minecraft.util.Identifier; +import net.pitan76.mcpitanlib.api.event.v0.ClientTickEventRegistry; +import net.pitan76.mcpitanlib.api.network.ClientNetworking; +import net.pitan76.mcpitanlib.api.network.PacketByteUtil; + +public class KeybindingRegistry { + public static void register(KeyBinding keyBinding) { + KeyMappingRegistry.register(keyBinding); + } + + public static void register(KeyBinding keyBinding, ClientTickEventRegistry.Client client) { + register(keyBinding); + ClientTickEventRegistry.registerPost(client); + } + + public static void registerOnLevel(KeyBinding keyBinding, ClientTickEventRegistry.ClientLevel level) { + register(keyBinding); + ClientTickEventRegistry.registerLevelPost(level); + } + + public static void registerWithNetwork(KeyBinding keyBinding, Identifier identifier) { + register(keyBinding, client -> { + if (keyBinding.wasPressed()) + ClientNetworking.send(identifier, PacketByteUtil.create()); + }); + } + + public static void registerOnLevelWithNetwork(KeyBinding keyBinding, Identifier identifier) { + registerOnLevel(keyBinding, client -> { + if (keyBinding.wasPressed()) + ClientNetworking.send(identifier, PacketByteUtil.create()); + }); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/client/registry/v2/KeybindingRegistry.java b/common/src/main/java/net/pitan76/mcpitanlib/api/client/registry/v2/KeybindingRegistry.java new file mode 100644 index 000000000..80a026101 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/registry/v2/KeybindingRegistry.java @@ -0,0 +1,23 @@ +package net.pitan76.mcpitanlib.api.client.registry.v2; + +import net.minecraft.client.option.KeyBinding; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; + +public class KeybindingRegistry extends net.pitan76.mcpitanlib.api.client.registry.KeybindingRegistry { + + public static void registerWithNetwork(KeyBinding keyBinding, CompatIdentifier identifier) { + registerWithNetwork(keyBinding, identifier.toMinecraft()); + } + + public static void registerOnLevelWithNetwork(KeyBinding keyBinding, CompatIdentifier identifier) { + registerOnLevelWithNetwork(keyBinding, identifier.toMinecraft()); + } + + public static void registerWithNetwork(String translationKey, int code, String category, CompatIdentifier identifier) { + registerWithNetwork(new KeyBinding(translationKey, code, category), identifier); + } + + public static void registerOnLevelWithNetwork(String translationKey, int code, String category, CompatIdentifier identifier) { + registerOnLevelWithNetwork(new KeyBinding(translationKey, code, category), identifier); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/client/registry/v3/KeybindingRegistry.java b/common/src/main/java/net/pitan76/mcpitanlib/api/client/registry/v3/KeybindingRegistry.java new file mode 100644 index 000000000..91f382b28 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/registry/v3/KeybindingRegistry.java @@ -0,0 +1,37 @@ +package net.pitan76.mcpitanlib.api.client.registry.v3; + +import net.pitan76.mcpitanlib.api.client.option.CompatKeyBinding; +import net.pitan76.mcpitanlib.api.event.v0.ClientTickEventRegistry; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; + +public class KeybindingRegistry { + public static void registerWithNetwork(CompatKeyBinding keyBinding, CompatIdentifier networkId) { + net.pitan76.mcpitanlib.api.client.registry.v2.KeybindingRegistry.registerWithNetwork(keyBinding.toMinecraft(), networkId.toMinecraft()); + } + + public static void registerOnLevelWithNetwork(CompatKeyBinding keyBinding, CompatIdentifier networkId) { + net.pitan76.mcpitanlib.api.client.registry.v2.KeybindingRegistry.registerOnLevelWithNetwork(keyBinding.toMinecraft(), networkId.toMinecraft()); + } + + public static void registerWithNetwork(String translationKey, int code, CompatIdentifier category, CompatIdentifier networkId) { + registerWithNetwork(CompatKeyBinding.of(translationKey, code, category), networkId); + } + + public static void registerOnLevelWithNetwork(String translationKey, int code, CompatIdentifier category, CompatIdentifier networkId) { + registerOnLevelWithNetwork(CompatKeyBinding.of(translationKey, code, category), networkId); + } + + public static void register(CompatKeyBinding keyBinding) { + net.pitan76.mcpitanlib.api.client.registry.KeybindingRegistry.register(keyBinding.toMinecraft()); + } + + public static void register(CompatKeyBinding keyBinding, ClientTickEventRegistry.Client client) { + register(keyBinding); + ClientTickEventRegistry.registerPost(client); + } + + public static void registerOnLevel(CompatKeyBinding keyBinding, ClientTickEventRegistry.ClientLevel level) { + register(keyBinding); + ClientTickEventRegistry.registerLevelPost(level); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/CompatRenderLayer.java b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/CompatRenderLayer.java new file mode 100644 index 000000000..69c3fc968 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/CompatRenderLayer.java @@ -0,0 +1,45 @@ +package net.pitan76.mcpitanlib.api.client.render; + +import net.minecraft.client.render.RenderLayer; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; + +public class CompatRenderLayer { + public static final CompatRenderLayer CUTOUT = new CompatRenderLayer(RenderLayer.getCutout()); + public static final CompatRenderLayer CUTOUT_MIPPED = new CompatRenderLayer(RenderLayer.getCutoutMipped()); + public static final CompatRenderLayer TRANSLUCENT = new CompatRenderLayer(RenderLayer.getTranslucent()); + public static final CompatRenderLayer TRANSLUCENT_MOVING_BLOCK = new CompatRenderLayer(RenderLayer.getTranslucentMovingBlock()); + public static final CompatRenderLayer SOLID = new CompatRenderLayer(RenderLayer.getSolid()); + public static final CompatRenderLayer LINES = new CompatRenderLayer(RenderLayer.getLines()); + public static final CompatRenderLayer LINE_STRIP = new CompatRenderLayer(RenderLayer.getLineStrip()); + public static final CompatRenderLayer GLINT = new CompatRenderLayer(RenderLayer.getGlint()); + + public final RenderLayer layer; + + public CompatRenderLayer(RenderLayer layer) { + this.layer = layer; + } + + public RenderLayer raw() { + return layer; + } + + public static CompatRenderLayer getEntityCutout(CompatIdentifier id) { + return new CompatRenderLayer(RenderLayer.getEntityCutout(id.toMinecraft())); + } + + public static CompatRenderLayer getEntityCutoutNoCull(CompatIdentifier id) { + return new CompatRenderLayer(RenderLayer.getEntityCutoutNoCull(id.toMinecraft())); + } + + public static CompatRenderLayer getEntityTranslucent(CompatIdentifier id) { + return new CompatRenderLayer(RenderLayer.getEntityTranslucent(id.toMinecraft())); + } + + public static CompatRenderLayer getArmorCutoutNoCull(CompatIdentifier id) { + return new CompatRenderLayer(RenderLayer.getArmorCutoutNoCull(id.toMinecraft())); + } + + public static CompatRenderLayer getEntitySolid(CompatIdentifier id) { + return new CompatRenderLayer(RenderLayer.getEntitySolid(id.toMinecraft())); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/DrawObjectDM.java b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/DrawObjectDM.java new file mode 100644 index 000000000..7f449b306 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/DrawObjectDM.java @@ -0,0 +1,94 @@ +package net.pitan76.mcpitanlib.api.client.render; + +import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.text.Text; +import net.pitan76.mcpitanlib.api.text.TextComponent; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.api.util.client.ScreenUtil.RendererUtil; + +public class DrawObjectDM { + private MatrixStack stack; + private DrawContext context; + + private Screen screen = null; + + public DrawObjectDM(DrawContext context) { + this.context = context; + this.stack = context.getMatrices(); + } + + public DrawObjectDM(MatrixStack stack) { + this.stack = stack; + } + + public DrawObjectDM(DrawContext context, Screen screen) { + this(context); + this.screen = screen; + } + + public DrawContext getContext() { + return context; + } + + public MatrixStack getStack() { + return stack; + } + + public Screen getScreen() { + return screen; + } + + public void setContext(DrawContext context) { + this.context = context; + } + + public void setStack(MatrixStack stack) { + this.stack = stack; + } + + public void setScreen(Screen screen) { + this.screen = screen; + } + + public boolean hasScreen() { + return screen != null; + } + + public void drawTexture(CompatIdentifier texture, int x, int y, float u, float v, int width, int height) { + RendererUtil.drawTexture(this, texture, x, y, u, v, width, height); + } + + public void drawTexture(CompatIdentifier texture, int x, int y, float u, float v, int width, int height, int textureWidth, int textureHeight) { + RendererUtil.drawTexture(this, texture, x, y, u, v, width, height, textureWidth, textureHeight); + } + + public void drawText(Text text, int x, int y) { + RendererUtil.drawText(RendererUtil.getTextRenderer(), this, text, x, y); + } + + public void drawTooltip(Text text, int x, int y) { + RendererUtil.drawTooltip(this, text, x, y); + } + + public void drawText(TextComponent text, int x, int y) { + RendererUtil.drawText(RendererUtil.getTextRenderer(), this, text, x, y); + } + + public void drawTooltip(TextComponent text, int x, int y) { + RendererUtil.drawTooltip(this, text, x, y); + } + + public void drawBorder(int x, int y, int width, int height, int color) { + RendererUtil.drawBorder(this, x, y, width, height, color); + } + + public int getWidth() { + return hasScreen() ? screen.width : -1; + } + + public int getHeight() { + return hasScreen() ? screen.height : -1; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/DrawObjectMV.java b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/DrawObjectMV.java new file mode 100644 index 000000000..37e2df47d --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/DrawObjectMV.java @@ -0,0 +1,119 @@ +package net.pitan76.mcpitanlib.api.client.render; + +import net.minecraft.client.render.OverlayTexture; +import net.minecraft.client.render.VertexConsumer; +import net.minecraft.client.util.math.MatrixStack; +import net.pitan76.mcpitanlib.api.util.client.render.VertexConsumerUtil; +import org.joml.Matrix3f; +import org.joml.Matrix4f; + +public class DrawObjectMV { + private final MatrixStack stack; + private final VertexConsumer buffer; + + public DrawObjectMV(MatrixStack stack, VertexConsumer buffer) { + this.stack = stack; + this.buffer = buffer; + } + + public DrawObjectMV(MatrixStack stack) { + this(stack, null); + } + + public DrawObjectMV(VertexConsumer buffer) { + this(null, buffer); + } + + public MatrixStack getStack() { + return stack; + } + + public VertexConsumer getBuffer() { + return buffer; + } + + public DrawObjectMV vertex(float x, float y, float z) { + return VertexConsumerUtil.vertex(this, x, y, z); + } + + public DrawObjectMV normal(float x, float y, float z) { + return VertexConsumerUtil.normal(this, x, y, z); + } + + public DrawObjectMV color(float red, float green, float blue, float alpha) { + return VertexConsumerUtil.color(this, red, green, blue, alpha); + } + + public DrawObjectMV color(int red, int green, int blue, int alpha) { + return VertexConsumerUtil.color(this, red, green, blue, alpha); + } + + public DrawObjectMV colorARGB(int argb) { + return VertexConsumerUtil.colorARGB(this, argb); + } + + public DrawObjectMV colorRGB(int rgb) { + return VertexConsumerUtil.colorRGB(this, rgb); + } + + public DrawObjectMV light(int light) { + return VertexConsumerUtil.light(this, light); + } + + public DrawObjectMV overlay(int overlay) { + return VertexConsumerUtil.overlay(this, overlay); + } + + public DrawObjectMV overlayDefaultUV() { + return VertexConsumerUtil.overlayDefaultUV(this); + } + + public Matrix4f matrix4f; + public Matrix3f matrix3f; + + public Matrix4f getMatrix4f() { + if (matrix4f == null) + matrix4f = stack.peek().getPositionMatrix(); + + return matrix4f; + } + + public Matrix3f getMatrix3f() { + if (matrix3f == null) + matrix3f = stack.peek().getNormalMatrix(); + + return matrix3f; + } + + public DrawObjectMV vertexWithMatrix4f(float x, float y, float z) { + VertexConsumerUtil.vertex(buffer, getMatrix4f(), x, y, z); + return this; + } + + public DrawObjectMV vertexWithMatrix(float x, float y, float z) { + VertexConsumerUtil.vertex(buffer, stack, x, y, z); + return this; + } + + public DrawObjectMV normalWithMatrix(float x, float y, float z) { + VertexConsumerUtil.normal(buffer, stack, x, y, z); + return this; + } + + public DrawObjectMV texture(float u, float v) { + VertexConsumerUtil.texture(buffer, u, v); + return this; + } + + public DrawObjectMV next() { + VertexConsumerUtil.next(buffer); + return this; + } + + public void renderQuad(float x1, float y1, float z1, float x2, float y2, float z2, + float normalX, float normalY, float normalZ, int r, int g, int b, int alpha, int u, int v, int overlay, int light) { + VertexConsumerUtil.renderQuad(buffer, stack, getMatrix4f(), getMatrix3f(), + x1, y1, z1, x2, y2, z2, + normalX, normalY, normalZ, r, g, b, alpha, u, v, overlay, light); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/EntityModelLayerContext.java b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/EntityModelLayerContext.java new file mode 100644 index 000000000..d1d343924 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/EntityModelLayerContext.java @@ -0,0 +1,27 @@ +package net.pitan76.mcpitanlib.api.client.render; + +import net.minecraft.client.model.ModelData; + +public class EntityModelLayerContext { + private final ModelData data; + private final int width; + private final int height; + + public EntityModelLayerContext(ModelData data, int width, int height) { + this.data = data; + this.width = width; + this.height = height; + } + + public int getHeight() { + return height; + } + + public int getWidth() { + return width; + } + + public ModelData getData() { + return data; + } +} \ No newline at end of file diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/block/entity/CompatBlockEntityRenderer.java b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/block/entity/CompatBlockEntityRenderer.java new file mode 100644 index 000000000..0db5cb14c --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/block/entity/CompatBlockEntityRenderer.java @@ -0,0 +1,37 @@ +package net.pitan76.mcpitanlib.api.client.render.block.entity; + +import net.minecraft.client.render.VertexConsumerProvider; +import net.minecraft.client.render.block.entity.BlockEntityRenderer; +import net.minecraft.client.util.math.MatrixStack; +import net.pitan76.mcpitanlib.api.client.render.block.entity.event.BlockEntityRenderEvent; +import net.pitan76.mcpitanlib.api.tile.CompatBlockEntity; + +@Deprecated +public interface CompatBlockEntityRenderer extends BlockEntityRenderer { + void render(BlockEntityRenderEvent event); + + @Override + default void render(T entity, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay) { + render(new BlockEntityRenderEvent<>(this, entity, tickDelta, matrices, vertexConsumers, light, overlay)); + } + + default boolean rendersOutsideBoundingBoxOverride(T blockEntity) { + return BlockEntityRenderer.super.rendersOutsideBoundingBox(blockEntity); + } + + default int getRenderDistanceOverride() { + return BlockEntityRenderer.super.getRenderDistance(); + } + + @Deprecated + @Override + default boolean rendersOutsideBoundingBox(T blockEntity) { + return rendersOutsideBoundingBoxOverride(blockEntity); + } + + @Deprecated + @Override + default int getRenderDistance() { + return getRenderDistanceOverride(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/block/entity/event/BlockEntityRenderEvent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/block/entity/event/BlockEntityRenderEvent.java new file mode 100644 index 000000000..2d655398c --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/block/entity/event/BlockEntityRenderEvent.java @@ -0,0 +1,143 @@ +package net.pitan76.mcpitanlib.api.client.render.block.entity.event; + +import net.minecraft.client.render.RenderLayer; +import net.minecraft.client.render.VertexConsumer; +import net.minecraft.client.render.VertexConsumerProvider; +import net.minecraft.client.render.item.ItemRenderer; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.item.ItemStack; +import net.minecraft.util.math.BlockPos; +import net.pitan76.mcpitanlib.api.client.registry.CompatRegistryClient; +import net.pitan76.mcpitanlib.api.client.render.CompatRenderLayer; +import net.pitan76.mcpitanlib.api.client.render.DrawObjectMV; +import net.pitan76.mcpitanlib.api.client.render.block.entity.CompatBlockEntityRenderer; +import net.pitan76.mcpitanlib.api.tile.CompatBlockEntity; +import net.pitan76.mcpitanlib.api.util.MathUtil; +import net.pitan76.mcpitanlib.api.util.client.ClientUtil; +import net.pitan76.mcpitanlib.api.util.client.MatrixStackUtil; +import net.pitan76.mcpitanlib.api.util.client.render.CompatItemRenderUtil; +import org.joml.Matrix3f; +import org.joml.Matrix4f; + +public class BlockEntityRenderEvent { + public T blockEntity; + public float tickDelta; + public MatrixStack matrices; + public VertexConsumerProvider vertexConsumers; + int light; + int overlay; + + public BlockEntityRenderEvent(T blockEntity, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay) { + this.blockEntity = blockEntity; + this.tickDelta = tickDelta; + this.matrices = matrices; + this.vertexConsumers = vertexConsumers; + this.light = light; + this.overlay = overlay; + } + + public T getBlockEntity() { + return blockEntity; + } + + public MatrixStack getMatrices() { + return matrices; + } + + public float getTickDelta() { + return tickDelta; + } + + public int getLight() { + return light; + } + + public int getOverlay() { + return overlay; + } + + public VertexConsumer getVertexConsumer(RenderLayer layer) { + return vertexConsumers.getBuffer(layer); + } + + public VertexConsumer getVertexConsumer(CompatRenderLayer layer) { + return getVertexConsumer(layer.raw()); + } + + public VertexConsumerProvider getVertexConsumers() { + return vertexConsumers; + } + + public void push() { + MatrixStackUtil.push(matrices); + } + + public void translate(double x, double y, double z) { + MatrixStackUtil.translate(matrices, x, y, z); + } + + public void pop() { + MatrixStackUtil.pop(matrices); + } + + public void multiply(MathUtil.RotationAxisType type, float deg) { + MatrixStackUtil.multiply(matrices, type, deg); + } + + public void scale(float x, float y, float z) { + MatrixStackUtil.scale(matrices, x, y, z); + } + + public ItemRenderer getItemRenderer() { + return ClientUtil.getItemRenderer(); + } + + public boolean isRemoved() { + return blockEntity.isRemoved(); + } + + public DrawObjectMV getDrawObject(CompatRenderLayer layer) { + return new DrawObjectMV(getMatrices(), getVertexConsumer(layer)); + } + + public Matrix4f matrix4f; + public Matrix3f matrix3f; + + public Matrix4f getMatrix4f() { + if (matrix4f == null) + matrix4f = matrices.peek().getPositionMatrix(); + + return matrix4f; + } + + public Matrix3f getMatrix3f() { + if (matrix3f == null) + matrix3f = matrices.peek().getNormalMatrix(); + + return matrix3f; + } + + public BlockPos getPos() { + return blockEntity.callGetPos(); + } + + public net.pitan76.mcpitanlib.midohra.util.math.BlockPos getMidohraPos() { + return net.pitan76.mcpitanlib.midohra.util.math.BlockPos.of(getPos()); + } + + //---- + + @Deprecated + public CompatRegistryClient.BlockEntityRendererFactory.Context ctx; + + public BlockEntityRenderEvent(CompatBlockEntityRenderer renderer, T blockEntity, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay) { + this(blockEntity, tickDelta, matrices, vertexConsumers, light, overlay); + if (renderer instanceof net.pitan76.mcpitanlib.api.client.render.block.entity.v2.CompatBlockEntityRenderer) { + this.ctx = ((net.pitan76.mcpitanlib.api.client.render.block.entity.v2.CompatBlockEntityRenderer) renderer).ctx; + } + } + + public void renderItemFixed(ItemStack stack) { + CompatItemRenderUtil.renderItemFixed(stack, this, blockEntity.callGetWorld()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/block/entity/event/CompatBlockEntityRendererConstructArgs.java b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/block/entity/event/CompatBlockEntityRendererConstructArgs.java new file mode 100644 index 000000000..d0dc58e39 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/block/entity/event/CompatBlockEntityRendererConstructArgs.java @@ -0,0 +1,16 @@ +package net.pitan76.mcpitanlib.api.client.render.block.entity.event; + +import net.minecraft.client.render.block.entity.BlockEntityRenderDispatcher; +import net.pitan76.mcpitanlib.api.util.client.ClientUtil; + +public class CompatBlockEntityRendererConstructArgs { + public final BlockEntityRenderDispatcher dispatcher; + + public CompatBlockEntityRendererConstructArgs(BlockEntityRenderDispatcher dispatcher) { + this.dispatcher = dispatcher; + } + + public CompatBlockEntityRendererConstructArgs() { + this(ClientUtil.getClient().getBlockEntityRenderDispatcher()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/block/entity/v2/CompatBlockEntityRenderer.java b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/block/entity/v2/CompatBlockEntityRenderer.java new file mode 100644 index 000000000..2d3b4f911 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/block/entity/v2/CompatBlockEntityRenderer.java @@ -0,0 +1,19 @@ +package net.pitan76.mcpitanlib.api.client.render.block.entity.v2; + +import net.pitan76.mcpitanlib.api.client.registry.CompatRegistryClient; +import net.pitan76.mcpitanlib.api.client.render.block.entity.event.CompatBlockEntityRendererConstructArgs; +import net.pitan76.mcpitanlib.api.tile.CompatBlockEntity; + +public abstract class CompatBlockEntityRenderer implements net.pitan76.mcpitanlib.api.client.render.block.entity.CompatBlockEntityRenderer { + + @Deprecated + public CompatRegistryClient.BlockEntityRendererFactory.Context ctx; + + public CompatBlockEntityRenderer(CompatBlockEntityRendererConstructArgs args) { + + } + + public CompatBlockEntityRenderer(CompatRegistryClient.BlockEntityRendererFactory.Context ctx) { + this.ctx = ctx; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/handledscreen/DrawBackgroundArgs.java b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/handledscreen/DrawBackgroundArgs.java new file mode 100644 index 000000000..4c0a4ab27 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/handledscreen/DrawBackgroundArgs.java @@ -0,0 +1,48 @@ +package net.pitan76.mcpitanlib.api.client.render.handledscreen; + +import net.pitan76.mcpitanlib.api.client.render.DrawObjectDM; + +public class DrawBackgroundArgs { + public DrawObjectDM drawObjectDM; + public float delta; + public int mouseX, mouseY; + + public DrawBackgroundArgs(DrawObjectDM drawObjectDM, float delta, int mouseX, int mouseY) { + setDrawObjectDM(drawObjectDM); + setDelta(delta); + setMouseX(mouseX); + setMouseY(mouseY); + } + + public void setDrawObjectDM(DrawObjectDM drawObjectDM) { + this.drawObjectDM = drawObjectDM; + } + + public void setDelta(float delta) { + this.delta = delta; + } + + public void setMouseX(int mouseX) { + this.mouseX = mouseX; + } + + public void setMouseY(int mouseY) { + this.mouseY = mouseY; + } + + public DrawObjectDM getDrawObjectDM() { + return drawObjectDM; + } + + public float getDelta() { + return delta; + } + + public int getMouseX() { + return mouseX; + } + + public int getMouseY() { + return mouseY; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/handledscreen/DrawForegroundArgs.java b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/handledscreen/DrawForegroundArgs.java new file mode 100644 index 000000000..643a5bf80 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/handledscreen/DrawForegroundArgs.java @@ -0,0 +1,38 @@ +package net.pitan76.mcpitanlib.api.client.render.handledscreen; + +import net.pitan76.mcpitanlib.api.client.render.DrawObjectDM; + +public class DrawForegroundArgs { + public DrawObjectDM drawObjectDM; + public int mouseX, mouseY; + + public DrawForegroundArgs(DrawObjectDM drawObjectDM, int mouseX, int mouseY) { + setDrawObjectDM(drawObjectDM); + setMouseX(mouseX); + setMouseY(mouseY); + } + + public void setDrawObjectDM(DrawObjectDM drawObjectDM) { + this.drawObjectDM = drawObjectDM; + } + + public void setMouseX(int mouseX) { + this.mouseX = mouseX; + } + + public void setMouseY(int mouseY) { + this.mouseY = mouseY; + } + + public DrawObjectDM getDrawObjectDM() { + return drawObjectDM; + } + + public int getMouseX() { + return mouseX; + } + + public int getMouseY() { + return mouseY; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/handledscreen/DrawMouseoverTooltipArgs.java b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/handledscreen/DrawMouseoverTooltipArgs.java new file mode 100644 index 000000000..652c5ed68 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/handledscreen/DrawMouseoverTooltipArgs.java @@ -0,0 +1,38 @@ +package net.pitan76.mcpitanlib.api.client.render.handledscreen; + +import net.pitan76.mcpitanlib.api.client.render.DrawObjectDM; + +public class DrawMouseoverTooltipArgs { + public DrawObjectDM drawObjectDM; + public int mouseX, mouseY; + + public DrawMouseoverTooltipArgs(DrawObjectDM drawObjectDM, int mouseX, int mouseY) { + setDrawObjectDM(drawObjectDM); + setMouseX(mouseX); + setMouseY(mouseY); + } + + public void setDrawObjectDM(DrawObjectDM drawObjectDM) { + this.drawObjectDM = drawObjectDM; + } + + public void setMouseX(int mouseX) { + this.mouseX = mouseX; + } + + public void setMouseY(int mouseY) { + this.mouseY = mouseY; + } + + public DrawObjectDM getDrawObjectDM() { + return drawObjectDM; + } + + public int getMouseX() { + return mouseX; + } + + public int getMouseY() { + return mouseY; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/handledscreen/KeyEventArgs.java b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/handledscreen/KeyEventArgs.java new file mode 100644 index 000000000..45c4ceeed --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/handledscreen/KeyEventArgs.java @@ -0,0 +1,35 @@ +package net.pitan76.mcpitanlib.api.client.render.handledscreen; + +public class KeyEventArgs { + public int keyCode, scanCode, modifiers; + + public KeyEventArgs(int keyCode, int scanCode, int modifiers) { + setKeyCode(keyCode); + setScanCode(scanCode); + setModifiers(modifiers); + } + + public void setKeyCode(int keyCode) { + this.keyCode = keyCode; + } + + public void setModifiers(int modifiers) { + this.modifiers = modifiers; + } + + public void setScanCode(int scanCode) { + this.scanCode = scanCode; + } + + public int getKeyCode() { + return keyCode; + } + + public int getModifiers() { + return modifiers; + } + + public int getScanCode() { + return scanCode; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/handledscreen/RenderArgs.java b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/handledscreen/RenderArgs.java new file mode 100644 index 000000000..8b4905d78 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/handledscreen/RenderArgs.java @@ -0,0 +1,48 @@ +package net.pitan76.mcpitanlib.api.client.render.handledscreen; + +import net.pitan76.mcpitanlib.api.client.render.DrawObjectDM; + +public class RenderArgs { + public DrawObjectDM drawObjectDM; + public float delta; + public int mouseX, mouseY; + + public RenderArgs(DrawObjectDM drawObjectDM, int mouseX, int mouseY, float delta) { + setDrawObjectDM(drawObjectDM); + setDelta(delta); + setMouseX(mouseX); + setMouseY(mouseY); + } + + public void setDrawObjectDM(DrawObjectDM drawObjectDM) { + this.drawObjectDM = drawObjectDM; + } + + public void setDelta(float delta) { + this.delta = delta; + } + + public void setMouseX(int mouseX) { + this.mouseX = mouseX; + } + + public void setMouseY(int mouseY) { + this.mouseY = mouseY; + } + + public DrawObjectDM getDrawObjectDM() { + return drawObjectDM; + } + + public float getDelta() { + return delta; + } + + public int getMouseX() { + return mouseX; + } + + public int getMouseY() { + return mouseY; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/screen/RenderBackgroundTextureArgs.java b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/screen/RenderBackgroundTextureArgs.java new file mode 100644 index 000000000..610b56280 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/screen/RenderBackgroundTextureArgs.java @@ -0,0 +1,34 @@ +package net.pitan76.mcpitanlib.api.client.render.screen; + +import net.pitan76.mcpitanlib.api.client.render.DrawObjectDM; +import net.pitan76.mcpitanlib.api.client.render.handledscreen.RenderArgs; + +public class RenderBackgroundTextureArgs { + public DrawObjectDM drawObjectDM; + int vOffset; + + public RenderBackgroundTextureArgs(DrawObjectDM drawObjectDM, int vOffset) { + this.drawObjectDM = drawObjectDM; + this.vOffset = vOffset; + } + + public RenderBackgroundTextureArgs(RenderArgs args) { + this(args.drawObjectDM, 0); + } + + public DrawObjectDM getDrawObjectDM() { + return drawObjectDM; + } + + public int getvOffset() { + return vOffset; + } + + public void setDrawObjectDM(DrawObjectDM drawObjectDM) { + this.drawObjectDM = drawObjectDM; + } + + public void setvOffset(int vOffset) { + this.vOffset = vOffset; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/command/AbstractCommand.java b/common/src/main/java/net/pitan76/mcpitanlib/api/command/AbstractCommand.java new file mode 100644 index 000000000..5b2fbdf00 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/command/AbstractCommand.java @@ -0,0 +1,47 @@ +package net.pitan76.mcpitanlib.api.command; + +import net.pitan76.mcpitanlib.api.command.argument.RequiredCommand; +import net.pitan76.mcpitanlib.api.event.ServerCommandEvent; + +import java.util.HashMap; +import java.util.Map; + +public abstract class AbstractCommand { + + private Map> argumentCommands = new HashMap<>(); + public int isSuccess = 1; + + public void init() { + + } + + public void init(CommandSettings settings) { + init(); + } + + public void success() { + isSuccess = 1; + } + + public void failure() { + isSuccess = 0; + } + + public Map> getArgumentCommands() { + return argumentCommands; + } + + public void setArgumentCommands(Map> argumentCommands) { + this.argumentCommands = argumentCommands; + } + + public void addArgumentCommand(String name, AbstractCommand command) { + getArgumentCommands().put(name, command); + } + + public void addArgumentCommand(RequiredCommand command) { + getArgumentCommands().put(command.getArgumentName(), command); + } + + public abstract void execute(ServerCommandEvent event); +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/command/CommandRegistry.java b/common/src/main/java/net/pitan76/mcpitanlib/api/command/CommandRegistry.java new file mode 100644 index 000000000..03467b2a7 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/command/CommandRegistry.java @@ -0,0 +1,125 @@ +package net.pitan76.mcpitanlib.api.command; + +import com.mojang.brigadier.builder.ArgumentBuilder; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import dev.architectury.event.events.common.CommandRegistrationEvent; +import net.minecraft.command.CommandRegistryAccess; +import net.minecraft.server.command.CommandManager; +import net.minecraft.server.command.ServerCommandSource; +import net.pitan76.mcpitanlib.api.command.argument.*; +import net.pitan76.mcpitanlib.api.event.*; + +import java.util.Map; + +public class CommandRegistry { + + @Deprecated + public static CommandRegistryAccess latestCommandRegistryAccess; + + public static void register(String name, LiteralCommand command) { + CommandRegistrationEvent.EVENT.register((dispatcher, registry, environment) -> { + latestCommandRegistryAccess = registry; + + CommandSettings settings = new CommandSettings(); + command.init(settings); + + LiteralArgumentBuilder builder = LiteralArgumentBuilder.literal(name).requires(settings::requires) + .executes(context -> { + ServerCommandEvent event = new ServerCommandEvent(); + event.setContext(context); + command.execute(event); + return command.isSuccess; + }); + + forArgsCmd(command, builder); + + //register(builder); + dispatcher.register(builder); + }); + } + + public static void register(LiteralArgumentBuilder builder) { + CommandRegistrationEvent.EVENT.register((dispatcher, registry, environment) -> { + latestCommandRegistryAccess = registry; + dispatcher.register(builder); + } + ); + } + + private static > void forArgsCmd(AbstractCommand absCmd, ArgumentBuilder builder) { + + if (!absCmd.getArgumentCommands().isEmpty()) { + // 引数コマンド + for (Map.Entry> argCmd : absCmd.getArgumentCommands().entrySet()) { + ArgumentBuilder nextBuilder = null; + argCmd.getValue().init(new CommandSettings()); + + if (argCmd.getValue() instanceof LiteralCommand) { + LiteralCommand command = (LiteralCommand) argCmd.getValue(); + nextBuilder = CommandManager.literal(argCmd.getKey()) + .executes(context -> { + ServerCommandEvent event = new ServerCommandEvent(); + event.setContext(context); + event.setCommand(command); + command.execute(event); + return command.isSuccess; + } + ); + } + + if (argCmd.getValue() instanceof RequiredCommand) { + RequiredCommand command = (RequiredCommand) argCmd.getValue(); + + nextBuilder = CommandManager.argument(argCmd.getKey(), command.getArgumentType()) + .executes(context -> { + ServerCommandEvent event = new ServerCommandEvent(); + if (command instanceof IntegerCommand) { + event = new IntegerCommandEvent(); + } + if (command instanceof DoubleCommand) { + event = new DoubleCommandEvent(); + } + if (command instanceof FloatCommand) { + event = new FloatCommandEvent(); + } + if (command instanceof LongCommand) { + event = new LongCommandEvent(); + } + if (command instanceof BooleanCommand) { + event = new BooleanCommandEvent(); + } + if (command instanceof StringCommand) { + event = new StringCommandEvent(); + } + if (command instanceof EntityCommand) { + event = new EntityCommandEvent(); + } + if (command instanceof EntitiesCommand) { + event = new EntitiesCommandEvent(); + } + if (command instanceof PlayerCommand) { + event = new PlayerCommandEvent(); + } + if (command instanceof PlayersCommand) { + event = new PlayersCommandEvent(); + } + if (command instanceof ItemCommand) { + event = new ItemCommandEvent(); + } + if (command instanceof BlockCommand) { + event = new BlockCommandEvent(); + } + + event.setContext(context); + event.setCommand(command); + command.execute(event); + return command.isSuccess; + } + ); + } + forArgsCmd(argCmd.getValue(), nextBuilder); + builder.then(nextBuilder); + } + } + } +} \ No newline at end of file diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/command/CommandSettings.java b/common/src/main/java/net/pitan76/mcpitanlib/api/command/CommandSettings.java new file mode 100644 index 000000000..8a1d5fb2d --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/command/CommandSettings.java @@ -0,0 +1,33 @@ +package net.pitan76.mcpitanlib.api.command; + +import net.minecraft.server.command.ServerCommandSource; + +public class CommandSettings { + private int permissionLevel = -1; + private ICustom iCustom = null; + + public boolean requires(ServerCommandSource source) { + + return customRequires(source) && (permissionLevel == -1 || source.hasPermissionLevel(permissionLevel)); + } + + private boolean customRequires(ServerCommandSource source) { + if (iCustom == null) return true; + return iCustom.custom(source); + } + + public CommandSettings permissionLevel(int level) { + this.permissionLevel = level; + return this; + } + + public CommandSettings custom(ICustom iCustom) { + this.iCustom = iCustom; + return this; + } + + @FunctionalInterface + public interface ICustom { + boolean custom(ServerCommandSource source); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/command/ConfigCommand.java b/common/src/main/java/net/pitan76/mcpitanlib/api/command/ConfigCommand.java new file mode 100644 index 000000000..0c4a9fb54 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/command/ConfigCommand.java @@ -0,0 +1,173 @@ +package net.pitan76.mcpitanlib.api.command; + +import com.mojang.brigadier.arguments.StringArgumentType; +import net.pitan76.easyapi.config.Config; +import net.pitan76.mcpitanlib.api.command.argument.StringCommand; +import net.pitan76.mcpitanlib.api.event.ServerCommandEvent; +import net.pitan76.mcpitanlib.api.event.StringCommandEvent; +import net.pitan76.mcpitanlib.api.util.TextUtil; +import org.jetbrains.annotations.Nullable; + +import java.io.File; +import java.util.function.Supplier; + +public class ConfigCommand extends LiteralCommand { + + public final Config config; + public File file; + public Supplier defaultConfigFunction; + public String prefix = "[MCPitanLib]"; + + public ConfigCommand(Config config, File file, String prefix) { + this.config = config; + this.file = file; + this.prefix = prefix; + } + + public ConfigCommand(Config config, File file, String prefix, @Nullable Supplier supplier) { + this.config = config; + this.file = file; + this.defaultConfigFunction = supplier; + this.prefix = prefix; + } + + public ConfigCommand(Config config, File file, @Nullable Supplier supplier) { + this.config = config; + this.file = file; + this.defaultConfigFunction = supplier; + } + + public ConfigCommand(Config config, File file) { + this.config = config; + this.file = file; + } + + public ConfigCommand(Config config) { + this.config = config; + } + + @Override + public void init(CommandSettings settings) { + settings.permissionLevel(3); + + addArgumentCommand("set", new LiteralCommand() { + @Override + public void init(CommandSettings settings) { + + addArgumentCommand("key", new StringCommand() { + @Override + public String getArgumentName() { + return "key"; + } + + + @Override + public void init(CommandSettings settings) { + + addArgumentCommand("value", new StringCommand() { + @Override + public String getArgumentName() { + return "value"; + } + + @Override + public void execute(StringCommandEvent event) { + String key = StringArgumentType.getString(event.context, "key"); + String value = StringArgumentType.getString(event.context, "value"); + if (config.get(key) == null) { + event.sendFailure(TextUtil.literal(prefix + " Key not found.")); + return; + } + if (config.get(key).getClass() == String.class) { + config.setString(key, value); + event.sendSuccess(TextUtil.literal(prefix + " Set " + key + " to " + value), false); + + } else if (config.get(key).getClass() == Integer.class) { + config.setInt(key, Integer.parseInt(value)); + event.sendSuccess(TextUtil.literal(prefix + " Set " + key + " to " + value), false); + + } else if (config.get(key).getClass() == Double.class) { + config.setDouble(key, Double.parseDouble(value)); + event.sendSuccess(TextUtil.literal(prefix + " Set " + key + " to " + value), false); + + } else if (config.get(key).getClass() == Boolean.class) { + config.setBoolean(key, Boolean.parseBoolean(value)); + event.sendSuccess(TextUtil.literal(prefix + " Set " + key + " to " + value), false); + + } else { + event.sendFailure(TextUtil.literal(prefix + " Not supported type.")); + } + if (file != null) + config.save(file); + } + }); + } + + @Override + public void execute(StringCommandEvent event) { + } + }); + } + + @Override + public void execute(ServerCommandEvent event) { + + } + }); + + addArgumentCommand("get", new LiteralCommand() { + @Override + public void init(CommandSettings settings) { + addArgumentCommand("key", new StringCommand() { + @Override + public String getArgumentName() { + return "key"; + } + + @Override + public void execute(StringCommandEvent event) { + String key = StringArgumentType.getString(event.context, "key"); + if (config.get(key) == null) { + event.sendFailure(TextUtil.literal(prefix + " Key not found.")); + return; + } + event.sendSuccess(TextUtil.literal(prefix + " " + key + ": " + config.get(key).toString()), false); + } + }); + } + + @Override + public void execute(ServerCommandEvent event) { + + } + }); + + addArgumentCommand("list", new LiteralCommand() { + @Override + public void execute(ServerCommandEvent event) { + event.sendSuccess(TextUtil.literal(prefix + " Config List"), false); + for (String key : config.configMap.keySet()) { + event.sendSuccess(TextUtil.literal(" - " + key + ": " + config.get(key).toString()), false); + } + } + }); + + if (defaultConfigFunction != null) { + addArgumentCommand("reset", new LiteralCommand() { + @Override + public void execute(ServerCommandEvent event) { + config.configMap.clear(); + defaultConfigFunction.get(); + if (file != null) + config.save(file); + event.sendSuccess(TextUtil.literal(prefix + " Reset config."), false); + } + }); + } + } + + @Override + public void execute(ServerCommandEvent event) { + + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/command/LiteralCommand.java b/common/src/main/java/net/pitan76/mcpitanlib/api/command/LiteralCommand.java new file mode 100644 index 000000000..f382775a9 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/command/LiteralCommand.java @@ -0,0 +1,7 @@ +package net.pitan76.mcpitanlib.api.command; + +import net.pitan76.mcpitanlib.api.event.ServerCommandEvent; + +public abstract class LiteralCommand extends AbstractCommand { + +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/command/argument/BlockCommand.java b/common/src/main/java/net/pitan76/mcpitanlib/api/command/argument/BlockCommand.java new file mode 100644 index 000000000..452c85dac --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/command/argument/BlockCommand.java @@ -0,0 +1,21 @@ +package net.pitan76.mcpitanlib.api.command.argument; + +import net.minecraft.block.Block; +import net.minecraft.command.argument.BlockStateArgumentType; +import net.pitan76.mcpitanlib.api.command.CommandRegistry; +import net.pitan76.mcpitanlib.api.event.BlockCommandEvent; +import net.pitan76.mcpitanlib.api.event.ServerCommandEvent; + +public abstract class BlockCommand extends RequiredCommand { + @Override + public BlockStateArgumentType getArgumentType() { + return BlockStateArgumentType.blockState(CommandRegistry.latestCommandRegistryAccess); + } + + public abstract void execute(BlockCommandEvent event); + + @Override + public void execute(ServerCommandEvent event) { + execute((BlockCommandEvent) event); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/command/argument/BooleanCommand.java b/common/src/main/java/net/pitan76/mcpitanlib/api/command/argument/BooleanCommand.java new file mode 100644 index 000000000..32687d804 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/command/argument/BooleanCommand.java @@ -0,0 +1,19 @@ +package net.pitan76.mcpitanlib.api.command.argument; + +import com.mojang.brigadier.arguments.BoolArgumentType; +import net.pitan76.mcpitanlib.api.event.BooleanCommandEvent; +import net.pitan76.mcpitanlib.api.event.ServerCommandEvent; + +public abstract class BooleanCommand extends RequiredCommand { + @Override + public BoolArgumentType getArgumentType() { + return BoolArgumentType.bool(); + } + + public abstract void execute(BooleanCommandEvent event); + + @Override + public void execute(ServerCommandEvent event) { + execute((BooleanCommandEvent) event); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/command/argument/DoubleCommand.java b/common/src/main/java/net/pitan76/mcpitanlib/api/command/argument/DoubleCommand.java new file mode 100644 index 000000000..b8ede9b0d --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/command/argument/DoubleCommand.java @@ -0,0 +1,19 @@ +package net.pitan76.mcpitanlib.api.command.argument; + +import com.mojang.brigadier.arguments.DoubleArgumentType; +import net.pitan76.mcpitanlib.api.event.DoubleCommandEvent; +import net.pitan76.mcpitanlib.api.event.ServerCommandEvent; + +public abstract class DoubleCommand extends RequiredCommand { + @Override + public DoubleArgumentType getArgumentType() { + return DoubleArgumentType.doubleArg(); + } + + public abstract void execute(DoubleCommandEvent event); + + @Override + public void execute(ServerCommandEvent event) { + execute((DoubleCommandEvent) event); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/command/argument/EntitiesCommand.java b/common/src/main/java/net/pitan76/mcpitanlib/api/command/argument/EntitiesCommand.java new file mode 100644 index 000000000..4157c76d3 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/command/argument/EntitiesCommand.java @@ -0,0 +1,20 @@ +package net.pitan76.mcpitanlib.api.command.argument; + +import net.minecraft.command.argument.EntityArgumentType; +import net.minecraft.entity.Entity; +import net.pitan76.mcpitanlib.api.event.EntitiesCommandEvent; +import net.pitan76.mcpitanlib.api.event.ServerCommandEvent; + +public abstract class EntitiesCommand extends RequiredCommand { + @Override + public EntityArgumentType getArgumentType() { + return EntityArgumentType.entities(); + } + + public abstract void execute(EntitiesCommandEvent event); + + @Override + public void execute(ServerCommandEvent event) { + execute((EntitiesCommandEvent) event); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/command/argument/EntityCommand.java b/common/src/main/java/net/pitan76/mcpitanlib/api/command/argument/EntityCommand.java new file mode 100644 index 000000000..cf0c76ec6 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/command/argument/EntityCommand.java @@ -0,0 +1,20 @@ +package net.pitan76.mcpitanlib.api.command.argument; + +import net.minecraft.command.argument.EntityArgumentType; +import net.minecraft.entity.Entity; +import net.pitan76.mcpitanlib.api.event.EntityCommandEvent; +import net.pitan76.mcpitanlib.api.event.ServerCommandEvent; + +public abstract class EntityCommand extends RequiredCommand { + @Override + public EntityArgumentType getArgumentType() { + return EntityArgumentType.entity(); + } + + public abstract void execute(EntityCommandEvent event); + + @Override + public void execute(ServerCommandEvent event) { + execute((EntityCommandEvent) event); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/command/argument/FloatCommand.java b/common/src/main/java/net/pitan76/mcpitanlib/api/command/argument/FloatCommand.java new file mode 100644 index 000000000..1b178e01b --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/command/argument/FloatCommand.java @@ -0,0 +1,19 @@ +package net.pitan76.mcpitanlib.api.command.argument; + +import com.mojang.brigadier.arguments.FloatArgumentType; +import net.pitan76.mcpitanlib.api.event.FloatCommandEvent; +import net.pitan76.mcpitanlib.api.event.ServerCommandEvent; + +public abstract class FloatCommand extends RequiredCommand { + @Override + public FloatArgumentType getArgumentType() { + return FloatArgumentType.floatArg(); + } + + public abstract void execute(FloatCommandEvent event); + + @Override + public void execute(ServerCommandEvent event) { + execute((FloatCommandEvent) event); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/command/argument/GreedyStringCommand.java b/common/src/main/java/net/pitan76/mcpitanlib/api/command/argument/GreedyStringCommand.java new file mode 100644 index 000000000..afff6b7e8 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/command/argument/GreedyStringCommand.java @@ -0,0 +1,10 @@ +package net.pitan76.mcpitanlib.api.command.argument; + +import com.mojang.brigadier.arguments.StringArgumentType; + +public abstract class GreedyStringCommand extends StringCommand { + @Override + public StringArgumentType getArgumentType() { + return StringArgumentType.greedyString(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/command/argument/IntegerCommand.java b/common/src/main/java/net/pitan76/mcpitanlib/api/command/argument/IntegerCommand.java new file mode 100644 index 000000000..bfcdec912 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/command/argument/IntegerCommand.java @@ -0,0 +1,19 @@ +package net.pitan76.mcpitanlib.api.command.argument; + +import com.mojang.brigadier.arguments.IntegerArgumentType; +import net.pitan76.mcpitanlib.api.event.IntegerCommandEvent; +import net.pitan76.mcpitanlib.api.event.ServerCommandEvent; + +public abstract class IntegerCommand extends RequiredCommand { + @Override + public IntegerArgumentType getArgumentType() { + return IntegerArgumentType.integer(); + } + + public abstract void execute(IntegerCommandEvent event); + + @Override + public void execute(ServerCommandEvent event) { + execute((IntegerCommandEvent) event); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/command/argument/ItemCommand.java b/common/src/main/java/net/pitan76/mcpitanlib/api/command/argument/ItemCommand.java new file mode 100644 index 000000000..2d24871bc --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/command/argument/ItemCommand.java @@ -0,0 +1,21 @@ +package net.pitan76.mcpitanlib.api.command.argument; + +import net.minecraft.command.argument.ItemStackArgumentType; +import net.minecraft.item.Item; +import net.pitan76.mcpitanlib.api.command.CommandRegistry; +import net.pitan76.mcpitanlib.api.event.ItemCommandEvent; +import net.pitan76.mcpitanlib.api.event.ServerCommandEvent; + +public abstract class ItemCommand extends RequiredCommand { + @Override + public ItemStackArgumentType getArgumentType() { + return ItemStackArgumentType.itemStack(CommandRegistry.latestCommandRegistryAccess); + } + + public abstract void execute(ItemCommandEvent event); + + @Override + public void execute(ServerCommandEvent event) { + execute((ItemCommandEvent) event); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/command/argument/LongCommand.java b/common/src/main/java/net/pitan76/mcpitanlib/api/command/argument/LongCommand.java new file mode 100644 index 000000000..45bd3b622 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/command/argument/LongCommand.java @@ -0,0 +1,19 @@ +package net.pitan76.mcpitanlib.api.command.argument; + +import com.mojang.brigadier.arguments.LongArgumentType; +import net.pitan76.mcpitanlib.api.event.LongCommandEvent; +import net.pitan76.mcpitanlib.api.event.ServerCommandEvent; + +public abstract class LongCommand extends RequiredCommand { + @Override + public LongArgumentType getArgumentType() { + return LongArgumentType.longArg(); + } + + public abstract void execute(LongCommandEvent event); + + @Override + public void execute(ServerCommandEvent event) { + execute((LongCommandEvent) event); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/command/argument/PlayerCommand.java b/common/src/main/java/net/pitan76/mcpitanlib/api/command/argument/PlayerCommand.java new file mode 100644 index 000000000..3a674b908 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/command/argument/PlayerCommand.java @@ -0,0 +1,20 @@ +package net.pitan76.mcpitanlib.api.command.argument; + +import net.minecraft.command.argument.EntityArgumentType; +import net.minecraft.entity.Entity; +import net.pitan76.mcpitanlib.api.event.PlayerCommandEvent; +import net.pitan76.mcpitanlib.api.event.ServerCommandEvent; + +public abstract class PlayerCommand extends RequiredCommand { + @Override + public EntityArgumentType getArgumentType() { + return EntityArgumentType.player(); + } + + public abstract void execute(PlayerCommandEvent event); + + @Override + public void execute(ServerCommandEvent event) { + execute((PlayerCommandEvent) event); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/command/argument/PlayersCommand.java b/common/src/main/java/net/pitan76/mcpitanlib/api/command/argument/PlayersCommand.java new file mode 100644 index 000000000..195d81d3b --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/command/argument/PlayersCommand.java @@ -0,0 +1,20 @@ +package net.pitan76.mcpitanlib.api.command.argument; + +import net.minecraft.command.argument.EntityArgumentType; +import net.minecraft.entity.Entity; +import net.pitan76.mcpitanlib.api.event.PlayersCommandEvent; +import net.pitan76.mcpitanlib.api.event.ServerCommandEvent; + +public abstract class PlayersCommand extends RequiredCommand { + @Override + public EntityArgumentType getArgumentType() { + return EntityArgumentType.players(); + } + + public abstract void execute(PlayersCommandEvent event); + + @Override + public void execute(ServerCommandEvent event) { + execute((PlayersCommandEvent) event); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/command/argument/RequiredCommand.java b/common/src/main/java/net/pitan76/mcpitanlib/api/command/argument/RequiredCommand.java new file mode 100644 index 000000000..a3428290f --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/command/argument/RequiredCommand.java @@ -0,0 +1,10 @@ +package net.pitan76.mcpitanlib.api.command.argument; + +import com.mojang.brigadier.arguments.ArgumentType; +import net.pitan76.mcpitanlib.api.command.AbstractCommand; + +public abstract class RequiredCommand extends AbstractCommand { + public abstract String getArgumentName(); + + public abstract ArgumentType getArgumentType(); +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/command/argument/StringCommand.java b/common/src/main/java/net/pitan76/mcpitanlib/api/command/argument/StringCommand.java new file mode 100644 index 000000000..008bfefaf --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/command/argument/StringCommand.java @@ -0,0 +1,19 @@ +package net.pitan76.mcpitanlib.api.command.argument; + +import com.mojang.brigadier.arguments.StringArgumentType; +import net.pitan76.mcpitanlib.api.event.ServerCommandEvent; +import net.pitan76.mcpitanlib.api.event.StringCommandEvent; + +public abstract class StringCommand extends RequiredCommand { + @Override + public StringArgumentType getArgumentType() { + return StringArgumentType.string(); + } + + public abstract void execute(StringCommandEvent event); + + @Override + public void execute(ServerCommandEvent event) { + execute((StringCommandEvent) event); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/datafixer/ItemStackFixer.java b/common/src/main/java/net/pitan76/mcpitanlib/api/datafixer/ItemStackFixer.java new file mode 100644 index 000000000..a3b041b01 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/datafixer/ItemStackFixer.java @@ -0,0 +1,52 @@ +package net.pitan76.mcpitanlib.api.datafixer; + +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +public class ItemStackFixer { + private static final Map> nbt2componentMapIfItemEqualMap = new HashMap<>(); + private static final Map, Map> nbt2componentMapIfitemMatchesMap = new HashMap<>(); + private static final Map nbt2componentMap = new HashMap<>(); + + public static void nbt2componentIfItemEquals(String itemId, String nbtKey, String componentId) { + Map nbt2componentMap; + if (nbt2componentMapIfItemEqualMap.containsKey(itemId)) { + nbt2componentMap = nbt2componentMapIfItemEqualMap.get(itemId); + } else { + nbt2componentMap = new HashMap<>(); + nbt2componentMapIfItemEqualMap.put(itemId, nbt2componentMap); + } + + nbt2componentMap.put(nbtKey, componentId); + } + + public static void nbt2componentIfItemMatches(Set itemId, String nbtKey, String componentId) { + Map nbt2componentMap; + if (nbt2componentMapIfitemMatchesMap.containsKey(itemId)) { + nbt2componentMap = nbt2componentMapIfitemMatchesMap.get(itemId); + } else { + nbt2componentMap = new HashMap<>(); + nbt2componentMapIfitemMatchesMap.put(itemId, nbt2componentMap); + } + + nbt2componentMap.put(nbtKey, componentId); + } + + public static void nbt2component(String nbtKey, String componentId) { + if (nbt2componentMap.containsKey(nbtKey)) return; + nbt2componentMap.put(nbtKey, componentId); + } + + public static Map> getNbt2componentMapIfItemEqualMap() { + return nbt2componentMapIfItemEqualMap; + } + + public static Map, Map> getNbt2componentMapIfitemMatchesMap() { + return nbt2componentMapIfitemMatchesMap; + } + + public static Map getNbt2componentMap() { + return nbt2componentMap; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/enchantment/CompatEnchantment.java b/common/src/main/java/net/pitan76/mcpitanlib/api/enchantment/CompatEnchantment.java new file mode 100644 index 000000000..d20d4a2b4 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/enchantment/CompatEnchantment.java @@ -0,0 +1,69 @@ +package net.pitan76.mcpitanlib.api.enchantment; + +import net.minecraft.enchantment.Enchantment; +import net.minecraft.enchantment.EnchantmentHelper; +import net.minecraft.item.ItemStack; +import net.minecraft.registry.BuiltinRegistries; +import net.minecraft.registry.RegistryKey; +import net.minecraft.registry.RegistryKeys; +import net.minecraft.registry.entry.RegistryEntry; +import net.minecraft.util.Identifier; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.util.EnchantmentUtil; +import org.jetbrains.annotations.Nullable; + +import java.util.Optional; + +public class CompatEnchantment { + private final RegistryKey registryKey; + + @Deprecated + public CompatEnchantment(RegistryKey registryKey) { + this.registryKey = registryKey; + } + + public CompatEnchantment of(Identifier identifier) { + return EnchantmentUtil.getEnchantment(identifier); + } + + public Identifier getId() { + return registryKey.getRegistry(); + } + + @Deprecated + public RegistryKey getRegistryKey() { + return registryKey; + } + + public String toString() { + return getId().toString(); + } + + public boolean equals(Object obj) { + if (obj instanceof CompatEnchantment) { + return ((CompatEnchantment) obj).getId().equals(getId()); + } + return false; + } + + @Deprecated + public RegistryEntry getEntry(@Nullable World world) { + Optional> optionalEntry; + if (world == null) { + optionalEntry = BuiltinRegistries.createWrapperLookup().createRegistryLookup() + .getOptionalEntry(RegistryKeys.ENCHANTMENT, registryKey); + } else { + optionalEntry = world.getRegistryManager().get(RegistryKeys.ENCHANTMENT).getEntry(registryKey); + } + + return optionalEntry.orElseThrow(); + } + + public Enchantment getEnchantment(@Nullable World world) { + return getEntry(world).value(); + } + + public int getLevel(ItemStack stack, @Nullable World world) { + return EnchantmentHelper.getLevel(getEntry(world), stack); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/entity/CompatContainerUser.java b/common/src/main/java/net/pitan76/mcpitanlib/api/entity/CompatContainerUser.java new file mode 100644 index 000000000..ca2ab6026 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/entity/CompatContainerUser.java @@ -0,0 +1,33 @@ +package net.pitan76.mcpitanlib.api.entity; + +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.player.PlayerEntity; + +public class CompatContainerUser { + protected PlayerEntity containerUser; + + public CompatContainerUser(PlayerEntity containerUser) { + this.containerUser = containerUser; + } + + public double getContainerInteractionRange() { + return 4.5d; + } + + public LivingEntity asLivingEntity() { + return containerUser; + } + + public boolean isPlayer() { + return true; + } + + public Player asPlayer() { + return new Player(containerUser); + } + + @Deprecated + public PlayerEntity getRaw() { + return containerUser; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/entity/CompatEntity.java b/common/src/main/java/net/pitan76/mcpitanlib/api/entity/CompatEntity.java new file mode 100644 index 000000000..f78178be2 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/entity/CompatEntity.java @@ -0,0 +1,119 @@ +package net.pitan76.mcpitanlib.api.entity; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityType; +import net.minecraft.entity.data.DataTracker; +import net.minecraft.nbt.NbtCompound; +import net.minecraft.network.listener.ClientPlayPacketListener; +import net.minecraft.network.packet.Packet; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Vec3d; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.event.entity.InitDataTrackerArgs; +import net.pitan76.mcpitanlib.api.event.nbt.ReadNbtArgs; +import net.pitan76.mcpitanlib.api.event.nbt.WriteNbtArgs; +import net.pitan76.mcpitanlib.midohra.util.math.Vector3d; + +public class CompatEntity extends Entity { + public CompatEntity(EntityType type, World world) { + super(type, world); + } + + @Deprecated + @Override + public void initDataTracker(DataTracker.Builder builder) { + initDataTracker(new InitDataTrackerArgs(builder)); + } + + public void initDataTracker(InitDataTrackerArgs args) { + + } + + public void readCustomDataFromNbt(ReadNbtArgs nbt) { + + } + + public void writeCustomDataToNbt(WriteNbtArgs nbt) { + + } + + @Deprecated + @Override + public void readCustomDataFromNbt(NbtCompound nbt) { + readCustomDataFromNbt(new ReadNbtArgs(nbt)); + } + + @Deprecated + @Override + public void writeCustomDataToNbt(NbtCompound nbt) { + writeCustomDataToNbt(new WriteNbtArgs(nbt)); + } + + public Packet createSpawnPacket() { + return null; + } + + public void writeNbt(WriteNbtArgs args) { + super.writeNbt(args.getNbt()); + } + + public void readNbt(ReadNbtArgs args) { + super.readNbt(args.getNbt()); + } + + @Deprecated + @Override + public NbtCompound writeNbt(NbtCompound nbt) { + writeNbt(new WriteNbtArgs(nbt)); + return nbt; + } + + @Deprecated + @Override + public void readNbt(NbtCompound nbt) { + readNbt(new ReadNbtArgs(nbt)); + } + + @Deprecated + @Override + public World getWorld() { + return callGetWorld(); + } + + public World callGetWorld() { + return super.getWorld(); + } + + public BlockPos callGetBlockPos() { + return getBlockPos(); + } + + public Vec3d callGetPos() { + return getPos(); + } + + public boolean hasServerWorld() { + return callGetWorld() instanceof ServerWorld; + } + + public ServerWorld getServerWorld() { + return (ServerWorld) getWorld(); + } + + public net.pitan76.mcpitanlib.midohra.world.World getMidohraWorld() { + return net.pitan76.mcpitanlib.midohra.world.World.of(callGetWorld()); + } + + public net.pitan76.mcpitanlib.midohra.util.math.BlockPos getMidohraBlockPos() { + return net.pitan76.mcpitanlib.midohra.util.math.BlockPos.of(callGetBlockPos()); + } + + public Vector3d getMidohraPos() { + return Vector3d.of(callGetPos()); + } + + public net.pitan76.mcpitanlib.midohra.world.ServerWorld getMidohraServerWorld() { + return net.pitan76.mcpitanlib.midohra.world.ServerWorld.of(getServerWorld()); + } +} \ No newline at end of file diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/entity/CompatThrownItemEntity.java b/common/src/main/java/net/pitan76/mcpitanlib/api/entity/CompatThrownItemEntity.java new file mode 100644 index 000000000..ccfe74e97 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/entity/CompatThrownItemEntity.java @@ -0,0 +1,149 @@ +package net.pitan76.mcpitanlib.api.entity; + +import net.minecraft.entity.EntityType; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.data.DataTracker; +import net.minecraft.entity.projectile.thrown.ThrownItemEntity; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NbtCompound; +import net.minecraft.text.Text; +import net.minecraft.util.hit.EntityHitResult; +import net.minecraft.util.hit.HitResult; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.event.entity.CollisionEvent; +import net.pitan76.mcpitanlib.api.event.entity.EntityHitEvent; +import net.pitan76.mcpitanlib.api.event.entity.InitDataTrackerArgs; +import net.pitan76.mcpitanlib.api.event.nbt.ReadNbtArgs; +import net.pitan76.mcpitanlib.api.event.nbt.WriteNbtArgs; + +public abstract class CompatThrownItemEntity extends ThrownItemEntity { + + public CompatThrownItemEntity(EntityType entityType, World world) { + super(entityType, world); + } + + public CompatThrownItemEntity(EntityType entityType, double d, double e, double f, World world) { + super(entityType, d, e, f, world); + } + + public CompatThrownItemEntity(EntityType entityType, LivingEntity livingEntity, World world) { + super(entityType, livingEntity, world); + } + + public abstract Item getDefaultItemOverride(); + + @Deprecated + @Override + protected Item getDefaultItem() { + return getDefaultItemOverride(); + } + + public ItemStack callGetItem() { + return super.getStack(); + } + + @Deprecated + @Override + public ItemStack getStack() { + return callGetItem(); + } + + public void callSetItem(ItemStack stack) { + super.setItem(stack); + } + + @Deprecated + @Override + public void setItem(ItemStack stack) { + callSetItem(stack); + } + + public void callHandleStatus(byte status) { + super.handleStatus(status); + } + + @Deprecated + @Override + public void handleStatus(byte status) { + callHandleStatus(status); + } + + public void onEntityHit(EntityHitEvent event) { + super.onEntityHit(event.entityHitResult); + } + + @Deprecated + @Override + protected void onEntityHit(EntityHitResult entityHitResult) { + onEntityHit(new EntityHitEvent(entityHitResult)); + } + + public void onCollision(CollisionEvent event) { + super.onCollision(event.hitResult); + } + + @Deprecated + @Override + protected void onCollision(HitResult hitResult) { + onCollision(new CollisionEvent(hitResult)); + } + + // ------------------ ExtendEntity ------------------ + + @Deprecated + @Override + public void initDataTracker(DataTracker.Builder builder) { + initDataTracker(new InitDataTrackerArgs(builder, dataTracker)); + } + + public void initDataTracker(InitDataTrackerArgs args) { + super.initDataTracker(args.getBuilder()); + } + + public void readCustomDataFromNbt(ReadNbtArgs nbt) { + super.readCustomDataFromNbt(nbt.getNbt()); + } + + public void writeCustomDataToNbt(WriteNbtArgs nbt) { + super.writeCustomDataToNbt(nbt.getNbt()); + } + + @Deprecated + @Override + public void readCustomDataFromNbt(NbtCompound nbt) { + readCustomDataFromNbt(new ReadNbtArgs(nbt)); + } + + @Deprecated + @Override + public void writeCustomDataToNbt(NbtCompound nbt) { + writeCustomDataToNbt(new WriteNbtArgs(nbt)); + } + + public void writeNbt(WriteNbtArgs args) { + super.writeNbt(args.getNbt()); + } + + public void readNbt(ReadNbtArgs args) { + super.readNbt(args.getNbt()); + } + + @Deprecated + @Override + public NbtCompound writeNbt(NbtCompound nbt) { + writeNbt(new WriteNbtArgs(nbt)); + return nbt; + } + + @Deprecated + @Override + public void readNbt(NbtCompound nbt) { + readNbt(new ReadNbtArgs(nbt)); + } + + @Override + public World getWorld() { + return super.getWorld(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/entity/EntityTypeBuilder.java b/common/src/main/java/net/pitan76/mcpitanlib/api/entity/EntityTypeBuilder.java new file mode 100644 index 000000000..933e0d8fc --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/entity/EntityTypeBuilder.java @@ -0,0 +1,133 @@ +package net.pitan76.mcpitanlib.api.entity; + +import com.google.common.collect.ImmutableSet; +import net.minecraft.block.Block; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityDimensions; +import net.minecraft.entity.EntityType; +import net.minecraft.entity.SpawnGroup; +import net.minecraft.loot.LootTable; +import net.minecraft.registry.RegistryKey; +import net.pitan76.mcpitanlib.MCPitanLib; + +import java.util.Optional; + +public class EntityTypeBuilder { + + private SpawnGroup spawnGroup; + private ExtendEntityType.EntityFactory factory; + private EntityDimensions entityDimensions; + private boolean saveable; + private boolean summonable; + private boolean fireImmune; + private boolean spawnableFarFromPlayer; + private ImmutableSet canSpawnBlocks; + private int maxTrackDistance; + private int trackTickInterval; + private Boolean alwaysUpdateVelocity = null; + private String translationKey = "entity." + MCPitanLib.MOD_ID; + private Optional> lootTable = Optional.empty(); + + @Deprecated + // Recommend: create() + public EntityTypeBuilder() { + setSaveable(true); + setSummonable(true); + setFireImmune(false); + setChangingDimensions(-1.0f, -1.0f); + spawnableFarFromPlayer = false; + maxTrackDistance = 5; + trackTickInterval = 3; + canSpawnBlocks = ImmutableSet.of(); + } + + @Deprecated + public EntityTypeBuilder(SpawnGroup spawnGroup, ExtendEntityType.EntityFactory factory) { + this(); + this.spawnGroup = spawnGroup; + this.factory = factory; + } + + public static EntityTypeBuilder create() { + return new EntityTypeBuilder<>(); + } + + public static EntityTypeBuilder create(SpawnGroup spawnGroup, ExtendEntityType.EntityFactory factory) { + return new EntityTypeBuilder<>(spawnGroup, factory); + } + + public EntityType build() { + return new ExtendEntityType<>(factory, spawnGroup, saveable, summonable, fireImmune, spawnableFarFromPlayer, canSpawnBlocks, entityDimensions, maxTrackDistance, trackTickInterval, translationKey, lootTable, alwaysUpdateVelocity); + } + + public EntityTypeBuilder setSpawnGroup(SpawnGroup spawnGroup) { + this.spawnGroup = spawnGroup; + return this; + } + + public EntityTypeBuilder setEntityFactory(ExtendEntityType.EntityFactory factory) { + this.factory = factory; + return this; + } + + public EntityTypeBuilder setDimensions(EntityDimensions entityDimensions) { + this.entityDimensions = entityDimensions; + return this; + } + + public EntityTypeBuilder setFixedDimensions(float width, float height) { + return setDimensions(EntityDimensions.fixed(width, height)); + } + + public EntityTypeBuilder setChangingDimensions(float width, float height) { + return setDimensions(EntityDimensions.changing(width, height)); + } + + public EntityTypeBuilder setSaveable(boolean saveable) { + this.saveable = saveable; + return this; + } + + public EntityTypeBuilder setSummonable(boolean summonable) { + this.summonable = summonable; + return this; + } + + public EntityTypeBuilder setFireImmune(boolean fireImmune) { + this.fireImmune = fireImmune; + return this; + } + + public EntityTypeBuilder setSpawnableFarFromPlayer(boolean spawnableFarFromPlayer) { + this.spawnableFarFromPlayer = spawnableFarFromPlayer; + return this; + } + + public EntityTypeBuilder setCanSpawnBlocks(ImmutableSet canSpawnBlocks) { + this.canSpawnBlocks = canSpawnBlocks; + return this; + } + + public EntityTypeBuilder setMaxTrackDistance(int maxTrackDistance) { + this.maxTrackDistance = maxTrackDistance; + return this; + } + + public EntityTypeBuilder setTrackTickInterval(int trackTickInterval) { + this.trackTickInterval = trackTickInterval; + return this; + } + + public EntityTypeBuilder setAlwaysUpdateVelocity(Boolean alwaysUpdateVelocity) { + this.alwaysUpdateVelocity = alwaysUpdateVelocity; + return this; + } + + public void setTranslationKey(String translationKey) { + this.translationKey = translationKey; + } + + public void setLootTable(RegistryKey lootTable) { + this.lootTable = Optional.ofNullable(lootTable); + } +} diff --git a/common/src/main/java/ml/pkom/mcpitanlibarch/api/entity/ExtendEntity.java b/common/src/main/java/net/pitan76/mcpitanlib/api/entity/ExtendEntity.java similarity index 65% rename from common/src/main/java/ml/pkom/mcpitanlibarch/api/entity/ExtendEntity.java rename to common/src/main/java/net/pitan76/mcpitanlib/api/entity/ExtendEntity.java index e4e7126c2..384c69012 100644 --- a/common/src/main/java/ml/pkom/mcpitanlibarch/api/entity/ExtendEntity.java +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/entity/ExtendEntity.java @@ -1,17 +1,27 @@ -package ml.pkom.mcpitanlibarch.api.entity; +package net.pitan76.mcpitanlib.api.entity; -import ml.pkom.mcpitanlibarch.api.nbt.NbtTag; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; +import net.minecraft.entity.damage.DamageSource; +import net.minecraft.entity.data.DataTracker; import net.minecraft.nbt.NbtCompound; -import net.minecraft.network.Packet; +import net.minecraft.network.listener.ClientPlayPacketListener; +import net.minecraft.network.packet.Packet; +import net.minecraft.server.world.ServerWorld; import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.nbt.NbtTag; public class ExtendEntity extends Entity { public ExtendEntity(EntityType type, World world) { super(type, world); } + @Deprecated + @Override + public void initDataTracker(DataTracker.Builder builder) { + initDataTracker(); + } + public void initDataTracker() { } @@ -23,7 +33,7 @@ public void writeCustomDataToNbt(NbtCompound nbt) { } - public Packet createSpawnPacket() { + public Packet createSpawnPacket() { return null; } @@ -58,4 +68,9 @@ public NbtCompound fromTag(NbtCompound nbt) { this.readNbt(NbtTag.from(nbt)); return nbt; } + + @Override + public World getWorld() { + return super.getWorld(); + } } \ No newline at end of file diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/entity/ExtendEntityType.java b/common/src/main/java/net/pitan76/mcpitanlib/api/entity/ExtendEntityType.java new file mode 100644 index 000000000..8490f0e42 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/entity/ExtendEntityType.java @@ -0,0 +1,41 @@ +package net.pitan76.mcpitanlib.api.entity; + +import com.google.common.collect.ImmutableSet; +import net.minecraft.block.Block; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityDimensions; +import net.minecraft.entity.EntityType; +import net.minecraft.entity.SpawnGroup; +import net.minecraft.loot.LootTable; +import net.minecraft.registry.RegistryKey; +import net.minecraft.resource.featuretoggle.FeatureFlags; +import net.minecraft.world.World; + +import java.util.Optional; + +public class ExtendEntityType extends EntityType { + private final Boolean alwaysUpdateVelocity; + + @Deprecated + public ExtendEntityType(EntityFactory factory, SpawnGroup spawnGroup, boolean saveable, boolean summonable, boolean fireImmune, boolean spawnableFarFromPlayer, ImmutableSet canSpawnBlocks, EntityDimensions entityDimensions, float spawnBoxScale, int maxTrackDistance, int trackTickInterval, String translationKey, Optional> lootTable, Boolean alwaysUpdateVelocity) { + super((factory::create), spawnGroup, saveable, summonable, fireImmune, spawnableFarFromPlayer, canSpawnBlocks, entityDimensions, spawnBoxScale, maxTrackDistance, trackTickInterval, FeatureFlags.DEFAULT_ENABLED_FEATURES); + this.alwaysUpdateVelocity = alwaysUpdateVelocity; + } + + public ExtendEntityType(EntityFactory factory, SpawnGroup spawnGroup, boolean saveable, boolean summonable, boolean fireImmune, boolean spawnableFarFromPlayer, ImmutableSet canSpawnBlocks, EntityDimensions entityDimensions, int maxTrackDistance, int trackTickInterval, String translationKey, Optional> lootTable, Boolean alwaysUpdateVelocity) { + super((factory::create), spawnGroup, saveable, summonable, fireImmune, spawnableFarFromPlayer, canSpawnBlocks, entityDimensions, 5, maxTrackDistance, trackTickInterval, FeatureFlags.DEFAULT_ENABLED_FEATURES); + this.alwaysUpdateVelocity = alwaysUpdateVelocity; + } + + @Override + public boolean alwaysUpdateVelocity() { + if (alwaysUpdateVelocity != null) + return alwaysUpdateVelocity; + + return super.alwaysUpdateVelocity(); + } + + public interface EntityFactory { + T create(EntityType type, World world); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/entity/Player.java b/common/src/main/java/net/pitan76/mcpitanlib/api/entity/Player.java new file mode 100644 index 000000000..297b3be05 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/entity/Player.java @@ -0,0 +1,533 @@ +package net.pitan76.mcpitanlib.api.entity; + +import dev.architectury.registry.menu.ExtendedMenuProvider; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.block.BlockState; +import net.minecraft.client.network.ClientPlayerEntity; +import net.minecraft.entity.EquipmentSlot; +import net.minecraft.entity.effect.StatusEffectInstance; +import net.minecraft.entity.player.ItemCooldownManager; +import net.minecraft.entity.player.PlayerAbilities; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NbtCompound; +import net.minecraft.network.PacketByteBuf; +import net.minecraft.screen.NamedScreenHandlerFactory; +import net.minecraft.screen.ScreenHandler; +import net.minecraft.server.network.ServerPlayNetworkHandler; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.sound.SoundCategory; +import net.minecraft.sound.SoundEvent; +import net.minecraft.stat.Stat; +import net.minecraft.stat.StatType; +import net.minecraft.text.Text; +import net.minecraft.util.Hand; +import net.minecraft.util.Identifier; +import net.minecraft.util.collection.DefaultedList; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import net.minecraft.util.math.Vec3d; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.entity.effect.CompatStatusEffect; +import net.pitan76.mcpitanlib.api.entity.effect.CompatStatusEffectInstance; +import net.pitan76.mcpitanlib.api.gui.ExtendedNamedScreenHandlerFactory; +import net.pitan76.mcpitanlib.api.item.CompatFoodComponent; +import net.pitan76.mcpitanlib.api.sound.CompatSoundCategory; +import net.pitan76.mcpitanlib.api.sound.CompatSoundEvent; +import net.pitan76.mcpitanlib.api.text.TextComponent; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.api.util.ScreenHandlerUtil; +import net.pitan76.mcpitanlib.api.util.TextUtil; +import net.pitan76.mcpitanlib.core.player.ItemCooldown; + +import java.util.*; +import java.util.function.Consumer; + +/* +PlayerEntity helper + */ +public class Player { + private final PlayerEntity entity; + + public PlayerEntity getEntity() { + return entity; + } + + public PlayerEntity getPlayerEntity() { + return getEntity(); + } + + public Player(PlayerEntity playerEntity) { + this.entity = playerEntity; + } + + /** + * Get player inventory + * @return PlayerInventory + */ + public PlayerInventory getInv() { + return getEntity().getInventory(); + } + + /** + * Alias of getInv() + * @return PlayerInventory + */ + public PlayerInventory getInventory() { + return getInv(); + } + + /** + * Get armor's item stack list + * @return DefaultedList + */ + public DefaultedList getArmor() { + return getInv().armor; + } + + /** + * Get main's item stack list + * @return DefaultedList + */ + public DefaultedList getMain() { + return getInv().main; + } + + /** + * Get off hand's item stack list + * @return DefaultedList + */ + public DefaultedList getOffHand() { + return getInv().offHand; + } + + /** + * Get select slot integer + * @return int + */ + public int getSelectSlot() { + return getInv().selectedSlot; + } + + /** + * Get player inventory size + * @return player inventory size + */ + public int getInvSize() { + return getInv().size(); + } + + public OptionalInt openGuiScreen(NamedScreenHandlerFactory factory) { + return getEntity().openHandledScreen(factory); + } + + public OptionalInt openGuiScreen(World world, BlockState state, BlockPos pos) { + return openGuiScreen(state.createScreenHandlerFactory(world, pos)); + } + + public boolean isServerPlayerEntity() { + return this.getEntity() instanceof ServerPlayerEntity; + } + + public void openExtendedMenu(NamedScreenHandlerFactory provider, Consumer bufWriter) { + if (isServerPlayerEntity()) + ScreenHandlerUtil.openExtendedMenu((ServerPlayerEntity) this.getPlayerEntity(), provider, bufWriter); + } + + public void openExtendedMenu(ExtendedMenuProvider provider) { + if (isServerPlayerEntity()) + ScreenHandlerUtil.openExtendedMenu((ServerPlayerEntity) this.getPlayerEntity(), provider); + } + + public void openExtendedMenu(ExtendedNamedScreenHandlerFactory provider) { + this.openExtendedMenu((ExtendedMenuProvider) provider); + } + + public void openMenu(NamedScreenHandlerFactory provider) { + if (isServerPlayerEntity()) + ScreenHandlerUtil.openMenu((ServerPlayerEntity) this.getPlayerEntity(), provider); + } + + public void insertStack(ItemStack stack) { + getInv().insertStack(stack); + } + + public void insertStack(int slot, ItemStack stack) { + getInv().insertStack(slot, stack); + } + + public void offerOrDrop(ItemStack itemStack) { + getInv().offerOrDrop(itemStack); + } + + public void giveStack(ItemStack stack) { + getEntity().giveItemStack(stack); + } + + public String getName() { + return getEntity().getName().getString(); + } + + public UUID getUUID() { + return getEntity().getUuid(); + } + + public PlayerAbilities getAbilities() { + return getEntity().getAbilities(); + } + + /** + * Returns whether this player is in creative mode. + */ + public boolean isCreative() { + return getAbilities().creativeMode; + } + + public boolean isFlying() { + return getAbilities().flying; + } + + public boolean isInvulnerable() { + return getAbilities().invulnerable; + } + + public World getWorld() { + return getEntity().getWorld(); + } + + public ScreenHandler getCurrentScreenHandler() { + return getEntity().currentScreenHandler; + } + + public boolean isSneaking() { + return getEntity().isSneaking(); + } + + public ItemStack getCursorStack() { + return getCurrentScreenHandler().getCursorStack(); + } + + public boolean isClient() { + return getWorld().isClient(); + } + public boolean isServer() { + return !isClient(); + } + + public void readCustomDataFromNbt(NbtCompound nbt) { + getEntity().readCustomDataFromNbt(nbt); + } + + public void writeCustomDataToNbt(NbtCompound nbt) { + getEntity().writeCustomDataToNbt(nbt); + } + + public void sendMessage(Text text) { + getEntity().sendMessage(text, false); + } + + public void sendActionBar(Text text) { + getEntity().sendMessage(text, true); + } + + public void equipStack(EquipmentSlot slot, ItemStack stack) { + getEntity().equipStack(slot, stack); + } + + public void dropStack(ItemStack stack, boolean throwRandomly, boolean retainOwnership) { + getEntity().dropItem(stack, throwRandomly, retainOwnership); + } + + public void dropStack(ItemStack stack, boolean retainOwnership) { + dropStack(stack, false, retainOwnership); + } + + public void dropStack(ItemStack stack) { + dropStack(stack, false, false); + } + + public BlockPos getBlockPos() { + return getEntity().getBlockPos(); + } + + public Vec3d getPos() { + return getEntity().getPos(); + } + + public ItemStack getStackInHand(Hand hand) { + return this.getEntity().getStackInHand(hand); + } + + public void heal(float amount) { + this.getEntity().heal(amount); + } + + public float getYaw() { + return this.getEntity().getYaw(); + } + + public float getPitch() { + return this.getEntity().getPitch(); + } + + public void playSound(SoundEvent event, SoundCategory category, float volume, float pitch) { + if (isServerPlayerEntity()) { + Optional player = getServerPlayer(); + if (player.isPresent()) { + player.get().playSoundToPlayer(event, category, volume, pitch); + return; + } + } + + playSound(event, volume, pitch); + } + + public void playSound(SoundEvent event, float volume, float pitch) { + if (isServerPlayerEntity()) { + Optional player = getServerPlayer(); + if (player.isPresent()) { + player.get().playSound(event, volume, pitch); + return; + } + } + + getEntity().playSound(event, volume, pitch); + } + + public void playSound(CompatSoundEvent event, CompatSoundCategory category, float volume, float pitch) { + playSound(event.get(), category.get(), volume, pitch); + } + + public void playSound(CompatSoundEvent event, float volume, float pitch) { + playSound(event.get(), volume, pitch); + } + + public ItemCooldown itemCooldown = new ItemCooldown(this); + + public ItemCooldown getItemCooldown() { + return itemCooldown; + } + + public ItemCooldownManager getItemCooldownManager() { + return getEntity().getItemCooldownManager(); + } + + public void incrementStat(Stat stat) { + getEntity().incrementStat(stat); + } + + public void incrementStat(StatType type, T object) { + getEntity().incrementStat(type.getOrCreateStat(object)); + } + + public void incrementStat(Identifier id) { + getEntity().incrementStat(id); + } + + public void incrementStat(CompatIdentifier id) { + getEntity().incrementStat(id.toMinecraft()); + } + + public void teleport(double x, double y, double z) { + getEntity().teleport(x, y, z, false); + } + + public ItemStack getMainHandStack() { + return getStackInHand(Hand.MAIN_HAND); + } + + public ItemStack getOffHandStack() { + return getStackInHand(Hand.OFF_HAND); + } + + public Direction getHorizontalFacing() { + return getEntity().getHorizontalFacing(); + } + + public double getX() { + return getEntity().getX(); + } + + public double getY() { + return getEntity().getY(); + } + + public double getZ() { + return getEntity().getZ(); + } + + public boolean isServerPlayer() { + return getEntity() instanceof ServerPlayerEntity; + } + + public Optional getServerPlayer() { + if (isServerPlayer()) + return Optional.of((ServerPlayerEntity) getEntity()); + + return Optional.empty(); + } + + @Environment(EnvType.CLIENT) + public Optional getClientPlayer() { + if (getEntity() instanceof ClientPlayerEntity) + return Optional.of((ClientPlayerEntity) getEntity()); + + return Optional.empty(); + } + + public void setVelocity(double x, double y, double z) { + getEntity().setVelocity(x, y, z); + } + + public void setVelocity(Vec3d velocity) { + getEntity().setVelocity(velocity); + } + + public Vec3d getVelocity() { + return getEntity().getVelocity(); + } + + public Optional getNetworkHandler() { + Optional player = getServerPlayer(); + return player.map(sp -> sp.networkHandler); + } + + public boolean hasNetworkHandler() { + return getNetworkHandler().isPresent(); + } + + public boolean isSpectator() { + return getEntity().isSpectator(); + } + + /** + * Returns the current {@link ItemStack} in the {@link Player}'s hand, or offhand if the + * main hand is empty. + * + * @return {@code ItemStack} that the {@link Player} is holding. Can be {@link null}. + */ + public Optional getCurrentHandItem() { + boolean playerIsHoldingInMainHand = !getMainHandStack().isEmpty(); + if (playerIsHoldingInMainHand) + return Optional.ofNullable(getMainHandStack()); + + boolean playerIsHoldingInOffHand = !getOffHandStack().isEmpty(); + + if (playerIsHoldingInOffHand) + return Optional.ofNullable(getOffHandStack()); + + return Optional.empty(); + } + + public void addStatusEffect(CompatStatusEffectInstance effect) { + getEntity().addStatusEffect(effect.getInstance()); + } + + public void removeStatusEffect(CompatStatusEffect effect) { + getEntity().removeStatusEffect(effect.getEntry(getWorld())); + } + + public List getStatusEffects() { + List compatEffects = new ArrayList<>(); + + for (StatusEffectInstance effect : getEntity().getStatusEffects()) { + compatEffects.add(new CompatStatusEffectInstance(effect)); + } + + return compatEffects; + } + + public void addExperience(int experience) { + getEntity().addExperience(experience); + } + + public int getExperienceLevel() { + return getEntity().experienceLevel; + } + + public void addExperienceLevels(int levels) { + getEntity().addExperienceLevels(levels); + } + + public void setExperienceLevel(int level) { + getEntity().experienceLevel = level; + } + + public void addScore(int score) { + getEntity().addScore(score); + } + + public int getScore() { + return getEntity().getScore(); + } + + public void setScore(int score) { + getEntity().setScore(score); + } + + public int getTotalExperience() { + return getEntity().totalExperience; + } + + public void setTotalExperience(int experience) { + getEntity().totalExperience = experience; + } + + public boolean isSwimming() { + return getEntity().isSwimming(); + } + + public void setStackInHand(Hand hand, ItemStack stack) { + getEntity().setStackInHand(hand, stack); + } + + public void setStackInHand(Hand hand, net.pitan76.mcpitanlib.midohra.item.ItemStack stack) { + setStackInHand(hand, stack.toMinecraft()); + } + + public net.pitan76.mcpitanlib.midohra.item.ItemStack getMidohraStackInHand(Hand hand) { + return net.pitan76.mcpitanlib.midohra.item.ItemStack.of(getStackInHand(hand)); + } + + public Hand getActiveHand() { + return getEntity().getActiveHand(); + } + + public float getBlockBreakingSpeed(BlockState state) { + return getEntity().getBlockBreakingSpeed(state); + } + + public boolean canHarvest(BlockState state) { + return getEntity().canHarvest(state); + } + + public net.pitan76.mcpitanlib.midohra.world.World getMidohraWorld() { + return net.pitan76.mcpitanlib.midohra.world.World.of(getWorld()); + } + + public void eatFood(ItemStack stack, CompatFoodComponent foodComponent) { + getEntity().getHungerManager().eat(foodComponent.build()); + } + + public void sendMessage(String message) { + sendMessage(TextUtil.of(message)); + } + + public void sendActionBar(String message) { + sendActionBar(TextUtil.of(message)); + } + + public void sendMessagef(String format, Object... args) { + sendMessage(TextUtil.of(String.format(format, args))); + } + + public void sendMessage(TextComponent textComponent) { + sendMessage(textComponent.getText()); + } + + public void sendActionBar(TextComponent textComponent) { + sendActionBar(textComponent.getText()); + } +} \ No newline at end of file diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/entity/attribute/AttrModifierOperation.java b/common/src/main/java/net/pitan76/mcpitanlib/api/entity/attribute/AttrModifierOperation.java new file mode 100644 index 000000000..dd71d5eb8 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/entity/attribute/AttrModifierOperation.java @@ -0,0 +1,54 @@ +package net.pitan76.mcpitanlib.api.entity.attribute; + +import net.minecraft.entity.attribute.EntityAttributeModifier; + +public class AttrModifierOperation { + private final EntityAttributeModifier.Operation raw; + + public static final AttrModifierOperation ADD = new AttrModifierOperation(EntityAttributeModifier.Operation.ADD_VALUE); + public static final AttrModifierOperation MUL_TOTAL = new AttrModifierOperation(EntityAttributeModifier.Operation.ADD_MULTIPLIED_TOTAL); + public static final AttrModifierOperation MUL_BASE = new AttrModifierOperation(EntityAttributeModifier.Operation.ADD_MULTIPLIED_BASE); + + @Deprecated + public AttrModifierOperation(EntityAttributeModifier.Operation raw) { + this.raw = raw; + } + + public static AttrModifierOperation of(EntityAttributeModifier.Operation raw) { + if (raw == EntityAttributeModifier.Operation.ADD_VALUE) { + return ADD; + } else if (raw == EntityAttributeModifier.Operation.ADD_MULTIPLIED_TOTAL) { + return MUL_TOTAL; + } else if (raw == EntityAttributeModifier.Operation.ADD_MULTIPLIED_BASE) { + return MUL_BASE; + } + + return new AttrModifierOperation(raw); + } + + public EntityAttributeModifier.Operation raw() { + return raw; + } + + public String getName() { + return raw().name(); + } + + public int getId() { + return raw().getId(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (!(obj instanceof AttrModifierOperation)) return false; + AttrModifierOperation that = (AttrModifierOperation) obj; + return raw().equals(that.raw()); + } + + @Override + public int hashCode() { + if (raw() == null) return super.hashCode(); + return raw().hashCode(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/entity/attribute/AttributeModifiersComponentBuilder.java b/common/src/main/java/net/pitan76/mcpitanlib/api/entity/attribute/AttributeModifiersComponentBuilder.java new file mode 100644 index 000000000..120a75040 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/entity/attribute/AttributeModifiersComponentBuilder.java @@ -0,0 +1,26 @@ +package net.pitan76.mcpitanlib.api.entity.attribute; + +import net.minecraft.component.type.AttributeModifiersComponent; + +public class AttributeModifiersComponentBuilder { + + public final AttributeModifiersComponent.Builder builder = AttributeModifiersComponent.builder(); + + public AttributeModifiersComponentBuilder() { + + } + + public AttributeModifiersComponentBuilder add(CompatEntityAttribute attribute, CompatEntityAttributeModifier modifier, CompatAttributeModifierSlot slot) { + builder.add(attribute.raw(), modifier.raw(), slot.raw()); + return this; + } + + @Deprecated + public AttributeModifiersComponent build_raw() { + return builder.build(); + } + + public CompatAttributeModifiersComponent build() { + return CompatAttributeModifiersComponent.of(build_raw()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/entity/attribute/CompatAttributeModifierSlot.java b/common/src/main/java/net/pitan76/mcpitanlib/api/entity/attribute/CompatAttributeModifierSlot.java new file mode 100644 index 000000000..5bbf3de43 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/entity/attribute/CompatAttributeModifierSlot.java @@ -0,0 +1,63 @@ +package net.pitan76.mcpitanlib.api.entity.attribute; + +import net.minecraft.component.type.AttributeModifierSlot; +import net.pitan76.mcpitanlib.api.util.CompatStringIdentifiable; + +public class CompatAttributeModifierSlot implements CompatStringIdentifiable { + + private final AttributeModifierSlot raw; + + public static final CompatAttributeModifierSlot ANY = new CompatAttributeModifierSlot(AttributeModifierSlot.ANY); + public static final CompatAttributeModifierSlot MAIN_HAND = new CompatAttributeModifierSlot(AttributeModifierSlot.MAINHAND); + public static final CompatAttributeModifierSlot OFF_HAND = new CompatAttributeModifierSlot(AttributeModifierSlot.OFFHAND); + public static final CompatAttributeModifierSlot HEAD = new CompatAttributeModifierSlot(AttributeModifierSlot.HEAD); + public static final CompatAttributeModifierSlot FEET = new CompatAttributeModifierSlot(AttributeModifierSlot.FEET); + public static final CompatAttributeModifierSlot LEGS = new CompatAttributeModifierSlot(AttributeModifierSlot.LEGS); + public static final CompatAttributeModifierSlot CHEST = new CompatAttributeModifierSlot(AttributeModifierSlot.CHEST); + public static final CompatAttributeModifierSlot ARMOR = new CompatAttributeModifierSlot(AttributeModifierSlot.ARMOR); + public static final CompatAttributeModifierSlot BODY = new CompatAttributeModifierSlot(AttributeModifierSlot.BODY); + public static final CompatAttributeModifierSlot SADDLE = new CompatAttributeModifierSlot(AttributeModifierSlot.BODY); + + @Deprecated + public CompatAttributeModifierSlot(AttributeModifierSlot raw) { + this.raw = raw; + } + + public static CompatAttributeModifierSlot of(AttributeModifierSlot slot) { + if (slot == AttributeModifierSlot.ANY) return ANY; + if (slot == AttributeModifierSlot.MAINHAND) return MAIN_HAND; + if (slot == AttributeModifierSlot.OFFHAND) return OFF_HAND; + if (slot == AttributeModifierSlot.HEAD) return HEAD; + if (slot == AttributeModifierSlot.FEET) return FEET; + if (slot == AttributeModifierSlot.LEGS) return LEGS; + if (slot == AttributeModifierSlot.CHEST) return CHEST; + if (slot == AttributeModifierSlot.ARMOR) return ARMOR; + if (slot == AttributeModifierSlot.BODY) return BODY; + + return new CompatAttributeModifierSlot(slot); + } + + @Deprecated + public AttributeModifierSlot raw() { + return raw; + } + + @Override + public String asString_compat() { + return raw().asString(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (!(obj instanceof CompatAttributeModifierSlot)) return false; + CompatAttributeModifierSlot that = (CompatAttributeModifierSlot) obj; + return raw().equals(that.raw()); + } + + @Override + public int hashCode() { + if (raw() == null) return super.hashCode(); + return raw().hashCode(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/entity/attribute/CompatAttributeModifiersComponent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/entity/attribute/CompatAttributeModifiersComponent.java new file mode 100644 index 000000000..ec9b8318c --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/entity/attribute/CompatAttributeModifiersComponent.java @@ -0,0 +1,34 @@ +package net.pitan76.mcpitanlib.api.entity.attribute; + +import net.minecraft.component.type.AttributeModifiersComponent; + +public class CompatAttributeModifiersComponent { + private final AttributeModifiersComponent raw; + + @Deprecated + public CompatAttributeModifiersComponent(AttributeModifiersComponent component) { + this.raw = component; + } + + @Deprecated + public AttributeModifiersComponent raw() { + return raw; + } + + public static CompatAttributeModifiersComponent of(AttributeModifiersComponent component) { + return new CompatAttributeModifiersComponent(component); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + CompatAttributeModifiersComponent that = (CompatAttributeModifiersComponent) obj; + return raw.equals(that.raw); + } + + @Override + public int hashCode() { + return raw.hashCode(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/entity/attribute/CompatEntityAttribute.java b/common/src/main/java/net/pitan76/mcpitanlib/api/entity/attribute/CompatEntityAttribute.java new file mode 100644 index 000000000..0b116dc14 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/entity/attribute/CompatEntityAttribute.java @@ -0,0 +1,49 @@ +package net.pitan76.mcpitanlib.api.entity.attribute; + +import net.minecraft.entity.attribute.EntityAttribute; +import net.minecraft.registry.entry.RegistryEntry; + +public class CompatEntityAttribute { + public final RegistryEntry raw; + + @Deprecated + public CompatEntityAttribute(RegistryEntry attribute) { + this.raw = attribute; + } + + @Deprecated + public RegistryEntry raw() { + return raw; + } + + public String getId() { + return raw.getIdAsString(); + } + + public EntityAttribute getValue() { + return raw.value(); + } + + public boolean isNull() { + return raw == null; + } + + @Deprecated + public static CompatEntityAttribute of(RegistryEntry attribute) { + return new CompatEntityAttribute(attribute); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (!(obj instanceof CompatEntityAttribute)) return false; + CompatEntityAttribute that = (CompatEntityAttribute) obj; + return raw.equals(that.raw); + } + + @Override + public int hashCode() { + if (raw == null) return super.hashCode(); + return raw.hashCode(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/entity/attribute/CompatEntityAttributeInstance.java b/common/src/main/java/net/pitan76/mcpitanlib/api/entity/attribute/CompatEntityAttributeInstance.java new file mode 100644 index 000000000..e170013ca --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/entity/attribute/CompatEntityAttributeInstance.java @@ -0,0 +1,70 @@ +package net.pitan76.mcpitanlib.api.entity.attribute; + +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.attribute.EntityAttributeInstance; +import net.pitan76.mcpitanlib.api.entity.Player; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; + +import java.util.function.Consumer; + +public class CompatEntityAttributeInstance { + private final net.minecraft.entity.attribute.EntityAttributeInstance raw; + + @Deprecated + public CompatEntityAttributeInstance(net.minecraft.entity.attribute.EntityAttributeInstance instance) { + this.raw = instance; + } + + @Deprecated + public net.minecraft.entity.attribute.EntityAttributeInstance raw() { + return raw; + } + + @Deprecated + public static CompatEntityAttributeInstance of(net.minecraft.entity.attribute.EntityAttributeInstance instance) { + return new CompatEntityAttributeInstance(instance); + } + + public static CompatEntityAttributeInstance create(CompatEntityAttribute type, Consumer updateCallback) { + return of(new EntityAttributeInstance(type.raw(), modifier -> { + if (updateCallback != null) + updateCallback.accept(of(modifier)); + })); + } + + public static CompatEntityAttributeInstance get(LivingEntity entity, CompatEntityAttribute attribute) { + return new CompatEntityAttributeInstance(entity.getAttributeInstance(attribute.raw())); + } + + public static CompatEntityAttributeInstance get(Player player, CompatEntityAttribute attribute) { + return get(player.getEntity(), attribute); + } + + public boolean hasModifier(CompatIdentifier id) { + return raw().hasModifier(id.toMinecraft()); + } + + public double getValue() { + return raw().getValue(); + } + + public void setBaseValue(double value) { + raw().setBaseValue(value); + } + + public void addPersistentModifier(CompatEntityAttributeModifier modifier) { + raw().addPersistentModifier(modifier.raw()); + } + + public void removeModifier(CompatIdentifier id) { + raw().removeModifier(id.toMinecraft()); + } + + public CompatEntityAttribute getAttribute() { + return CompatEntityAttribute.of(raw().getAttribute()); + } + + public boolean isNull() { + return raw() == null; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/entity/attribute/CompatEntityAttributeModifier.java b/common/src/main/java/net/pitan76/mcpitanlib/api/entity/attribute/CompatEntityAttributeModifier.java new file mode 100644 index 000000000..59b4f2b74 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/entity/attribute/CompatEntityAttributeModifier.java @@ -0,0 +1,57 @@ +package net.pitan76.mcpitanlib.api.entity.attribute; + +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; + +public class CompatEntityAttributeModifier { + private final net.minecraft.entity.attribute.EntityAttributeModifier raw; + + @Deprecated + public CompatEntityAttributeModifier(net.minecraft.entity.attribute.EntityAttributeModifier raw) { + this.raw = raw; + } + + @Deprecated + public static CompatEntityAttributeModifier of(net.minecraft.entity.attribute.EntityAttributeModifier raw) { + return new CompatEntityAttributeModifier(raw); + } + + public static CompatEntityAttributeModifier of(CompatIdentifier id, double value, AttrModifierOperation operation) { + return new CompatEntityAttributeModifier(new net.minecraft.entity.attribute.EntityAttributeModifier(id.toMinecraft(), value, operation.raw())); + } + + @Deprecated + public net.minecraft.entity.attribute.EntityAttributeModifier raw() { + return raw; + } + + public AttrModifierOperation getOperation() { + return AttrModifierOperation.of(raw().operation()); + } + + public double getValue() { + return raw().value(); + } + + public CompatIdentifier getId() { + return CompatIdentifier.fromMinecraft(raw().id()); + } + + @Override + public String toString() { + return raw().toString(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (!(obj instanceof CompatEntityAttributeModifier)) return false; + CompatEntityAttributeModifier that = (CompatEntityAttributeModifier) obj; + return raw().equals(that.raw()); + } + + @Override + public int hashCode() { + if (raw() == null) return super.hashCode(); + return raw().hashCode(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/entity/attribute/CompatEntityAttributes.java b/common/src/main/java/net/pitan76/mcpitanlib/api/entity/attribute/CompatEntityAttributes.java new file mode 100644 index 000000000..34f6d6641 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/entity/attribute/CompatEntityAttributes.java @@ -0,0 +1,28 @@ +package net.pitan76.mcpitanlib.api.entity.attribute; + +import net.minecraft.entity.attribute.EntityAttribute; +import net.minecraft.entity.attribute.EntityAttributes; +import net.minecraft.registry.entry.RegistryEntry; + +public class CompatEntityAttributes { + + public static final CompatEntityAttribute ARMOR = of(EntityAttributes.GENERIC_ARMOR); + public static final CompatEntityAttribute ARMOR_TOUGHNESS = of(EntityAttributes.GENERIC_ARMOR_TOUGHNESS); + public static final CompatEntityAttribute ATTACK_DAMAGE = of(EntityAttributes.GENERIC_ATTACK_DAMAGE); + public static final CompatEntityAttribute ATTACK_KNOCKBACK = of(EntityAttributes.GENERIC_ATTACK_KNOCKBACK); + public static final CompatEntityAttribute ATTACK_SPEED = of(EntityAttributes.GENERIC_ATTACK_SPEED); + public static final CompatEntityAttribute FOLLOW_RANGE = of(EntityAttributes.GENERIC_FOLLOW_RANGE); + public static final CompatEntityAttribute KNOCKBACK_RESISTANCE = of(EntityAttributes.GENERIC_KNOCKBACK_RESISTANCE); + public static final CompatEntityAttribute LUCK = of(EntityAttributes.GENERIC_LUCK); + public static final CompatEntityAttribute MOVEMENT_SPEED = of(EntityAttributes.GENERIC_MOVEMENT_SPEED); + public static final CompatEntityAttribute MAX_HEALTH = of(EntityAttributes.GENERIC_MAX_HEALTH); + public static final CompatEntityAttribute JUMP_STRENGTH = of(EntityAttributes.GENERIC_JUMP_STRENGTH); + public static final CompatEntityAttribute GRAVITY = of(EntityAttributes.GENERIC_GRAVITY); + public static final CompatEntityAttribute FLYING_SPEED = of(EntityAttributes.GENERIC_FLYING_SPEED); + public static final CompatEntityAttribute BLOCK_BREAK_SPEED = of(EntityAttributes.PLAYER_BLOCK_BREAK_SPEED); + public static final CompatEntityAttribute BLOCK_INTERACTION_RANGE = of(EntityAttributes.PLAYER_BLOCK_INTERACTION_RANGE); + + public static CompatEntityAttribute of(RegistryEntry attribute) { + return CompatEntityAttribute.of(attribute); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/entity/effect/CompatStatusEffect.java b/common/src/main/java/net/pitan76/mcpitanlib/api/entity/effect/CompatStatusEffect.java new file mode 100644 index 000000000..a8e9d4a57 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/entity/effect/CompatStatusEffect.java @@ -0,0 +1,63 @@ +package net.pitan76.mcpitanlib.api.entity.effect; + +import net.minecraft.entity.effect.StatusEffect; +import net.minecraft.registry.BuiltinRegistries; +import net.minecraft.registry.RegistryKey; +import net.minecraft.registry.RegistryKeys; +import net.minecraft.registry.entry.RegistryEntry; +import net.minecraft.util.Identifier; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.util.StatusEffectUtil; +import org.jetbrains.annotations.Nullable; + +import java.util.Optional; + +public class CompatStatusEffect { + private final RegistryKey registryKey; + + @Deprecated + public CompatStatusEffect(RegistryKey registryKey) { + this.registryKey = registryKey; + } + + public CompatStatusEffect of(Identifier identifier) { + return StatusEffectUtil.getStatusEffect(identifier); + } + + public Identifier getId() { + return registryKey.getRegistry(); + } + + @Deprecated + public RegistryKey getRegistryKey() { + return registryKey; + } + + public String toString() { + return getId().toString(); + } + + public boolean equals(Object obj) { + if (obj instanceof CompatStatusEffect) { + return ((CompatStatusEffect) obj).getId().equals(getId()); + } + return false; + } + + @Deprecated + public RegistryEntry getEntry(@Nullable World world) { + Optional> optionalEntry; + if (world == null) { + optionalEntry = BuiltinRegistries.createWrapperLookup().createRegistryLookup() + .getOptionalEntry(RegistryKeys.STATUS_EFFECT, registryKey); + } else { + optionalEntry = world.getRegistryManager().get(RegistryKeys.STATUS_EFFECT).getEntry(registryKey); + } + + return optionalEntry.orElseThrow(); + } + + public StatusEffect getStatusEffect(@Nullable World world) { + return getEntry(world).value(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/entity/effect/CompatStatusEffectInstance.java b/common/src/main/java/net/pitan76/mcpitanlib/api/entity/effect/CompatStatusEffectInstance.java new file mode 100644 index 000000000..fe23894f3 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/entity/effect/CompatStatusEffectInstance.java @@ -0,0 +1,74 @@ +package net.pitan76.mcpitanlib.api.entity.effect; + +import net.minecraft.entity.effect.StatusEffect; +import net.minecraft.entity.effect.StatusEffectInstance; +import net.minecraft.registry.RegistryKey; +import org.jetbrains.annotations.Nullable; + +import java.util.Optional; + +public class CompatStatusEffectInstance { + private final StatusEffectInstance instance; + + @Deprecated + public CompatStatusEffectInstance(StatusEffectInstance instance) { + this.instance = instance; + } + + public StatusEffectInstance getInstance() { + return instance; + } + + public Optional getCompatStatusEffect() { + Optional> optional = instance.getEffectType().getKey(); + return optional.map(CompatStatusEffect::new); + } + + public CompatStatusEffectInstance(CompatStatusEffect effect) { + this(effect, 0, 0); + } + + public CompatStatusEffectInstance(CompatStatusEffect effect, int duration) { + this(effect, duration, 0); + } + + public CompatStatusEffectInstance(CompatStatusEffect effect, int duration, int amplifier) { + this(effect, duration, amplifier, false, true); + } + + public CompatStatusEffectInstance(CompatStatusEffect effect, int duration, int amplifier, boolean ambient, boolean visible) { + this(effect, duration, amplifier, ambient, visible, visible); + } + + public CompatStatusEffectInstance(CompatStatusEffect effect, int duration, int amplifier, boolean ambient, boolean showParticles, boolean showIcon) { + this(effect, duration, amplifier, ambient, showParticles, showIcon, null); + } + + public CompatStatusEffectInstance(CompatStatusEffect effect, int duration, int amplifier, boolean ambient, boolean showParticles, boolean showIcon, @Nullable StatusEffectInstance hiddenEffect) { + this.instance = new StatusEffectInstance(effect.getEntry(null), duration, amplifier, ambient, showParticles, showIcon, hiddenEffect); + } + + public int getDuration() { + return instance.getDuration(); + } + + public int getAmplifier() { + return instance.getAmplifier(); + } + + public boolean isAmbient() { + return instance.isAmbient(); + } + + public boolean showParticles() { + return instance.shouldShowParticles(); + } + + public boolean showIcon() { + return instance.shouldShowIcon(); + } + + public boolean isInfinite() { + return instance.isInfinite(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/BaseEvent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/BaseEvent.java new file mode 100644 index 000000000..4e770c96c --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/BaseEvent.java @@ -0,0 +1,4 @@ +package net.pitan76.mcpitanlib.api.event; + +public class BaseEvent { +} \ No newline at end of file diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/BlockCommandEvent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/BlockCommandEvent.java new file mode 100644 index 000000000..b54933766 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/BlockCommandEvent.java @@ -0,0 +1,11 @@ +package net.pitan76.mcpitanlib.api.event; + +import net.minecraft.block.Block; +import net.minecraft.command.argument.BlockStateArgumentType; +import net.pitan76.mcpitanlib.api.command.argument.BlockCommand; + +public class BlockCommandEvent extends RequiredCommandEvent { + public Block getValue() { + return BlockStateArgumentType.getBlockState(context, ((BlockCommand) getCommand()).getArgumentName()).getBlockState().getBlock(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/BooleanCommandEvent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/BooleanCommandEvent.java new file mode 100644 index 000000000..e465945ee --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/BooleanCommandEvent.java @@ -0,0 +1,10 @@ +package net.pitan76.mcpitanlib.api.event; + +import com.mojang.brigadier.arguments.BoolArgumentType; +import net.pitan76.mcpitanlib.api.command.argument.BooleanCommand; + +public class BooleanCommandEvent extends RequiredCommandEvent { + public Boolean getValue() { + return BoolArgumentType.getBool(context, ((BooleanCommand) getCommand()).getArgumentName()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/CommandEvent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/CommandEvent.java new file mode 100644 index 000000000..7b000c562 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/CommandEvent.java @@ -0,0 +1,38 @@ +package net.pitan76.mcpitanlib.api.event; + +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.context.StringRange; +import net.pitan76.mcpitanlib.api.command.AbstractCommand; + +public class CommandEvent { + public CommandContext context; + public AbstractCommand command; + + public CommandContext getContext() { + return context; + } + + public void setContext(CommandContext context) { + this.context = context; + } + + public String getInput() { + return getContext().getInput(); + } + + public StringRange getRange() { + return getContext().getRange(); + } + + public void setCommand(AbstractCommand command) { + this.command = command; + } + + public AbstractCommand getCommand() { + return command; + } + + public V getArgument(String name, Class clazz) { + return getContext().getArgument(name, clazz); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/DoubleCommandEvent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/DoubleCommandEvent.java new file mode 100644 index 000000000..b67d482a7 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/DoubleCommandEvent.java @@ -0,0 +1,10 @@ +package net.pitan76.mcpitanlib.api.event; + +import com.mojang.brigadier.arguments.DoubleArgumentType; +import net.pitan76.mcpitanlib.api.command.argument.DoubleCommand; + +public class DoubleCommandEvent extends RequiredCommandEvent { + public Double getValue() { + return DoubleArgumentType.getDouble(context, ((DoubleCommand) getCommand()).getArgumentName()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/EntitiesCommandEvent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/EntitiesCommandEvent.java new file mode 100644 index 000000000..38110c090 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/EntitiesCommandEvent.java @@ -0,0 +1,16 @@ +package net.pitan76.mcpitanlib.api.event; + +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import net.minecraft.command.argument.EntityArgumentType; +import net.minecraft.entity.Entity; +import net.pitan76.mcpitanlib.api.command.argument.EntitiesCommand; + +public class EntitiesCommandEvent extends RequiredCommandEvent { + public Entity getValue() { + try { + return EntityArgumentType.getEntity(context, ((EntitiesCommand) getCommand()).getArgumentName()); + } catch (CommandSyntaxException e) { + throw new RuntimeException(e); + } + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/EntityCommandEvent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/EntityCommandEvent.java new file mode 100644 index 000000000..ea90b106e --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/EntityCommandEvent.java @@ -0,0 +1,16 @@ +package net.pitan76.mcpitanlib.api.event; + +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import net.minecraft.command.argument.EntityArgumentType; +import net.minecraft.entity.Entity; +import net.pitan76.mcpitanlib.api.command.argument.EntityCommand; + +public class EntityCommandEvent extends RequiredCommandEvent { + public Entity getValue() { + try { + return EntityArgumentType.getEntity(context, ((EntityCommand) getCommand()).getArgumentName()); + } catch (CommandSyntaxException e) { + throw new RuntimeException(e); + } + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/FloatCommandEvent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/FloatCommandEvent.java new file mode 100644 index 000000000..931d4e194 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/FloatCommandEvent.java @@ -0,0 +1,10 @@ +package net.pitan76.mcpitanlib.api.event; + +import com.mojang.brigadier.arguments.FloatArgumentType; +import net.pitan76.mcpitanlib.api.command.argument.FloatCommand; + +public class FloatCommandEvent extends RequiredCommandEvent { + public Float getValue() { + return FloatArgumentType.getFloat(context, ((FloatCommand) getCommand()).getArgumentName()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/IntegerCommandEvent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/IntegerCommandEvent.java new file mode 100644 index 000000000..240e325d3 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/IntegerCommandEvent.java @@ -0,0 +1,10 @@ +package net.pitan76.mcpitanlib.api.event; + +import com.mojang.brigadier.arguments.IntegerArgumentType; +import net.pitan76.mcpitanlib.api.command.argument.IntegerCommand; + +public class IntegerCommandEvent extends RequiredCommandEvent { + public Integer getValue() { + return IntegerArgumentType.getInteger(context, ((IntegerCommand) getCommand()).getArgumentName()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/ItemCommandEvent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/ItemCommandEvent.java new file mode 100644 index 000000000..1888aa422 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/ItemCommandEvent.java @@ -0,0 +1,11 @@ +package net.pitan76.mcpitanlib.api.event; + +import net.minecraft.command.argument.ItemStackArgumentType; +import net.minecraft.item.Item; +import net.pitan76.mcpitanlib.api.command.argument.ItemCommand; + +public class ItemCommandEvent extends RequiredCommandEvent { + public Item getValue() { + return ItemStackArgumentType.getItemStackArgument(context, ((ItemCommand) getCommand()).getArgumentName()).getItem(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/LongCommandEvent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/LongCommandEvent.java new file mode 100644 index 000000000..744678f01 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/LongCommandEvent.java @@ -0,0 +1,10 @@ +package net.pitan76.mcpitanlib.api.event; + +import com.mojang.brigadier.arguments.LongArgumentType; +import net.pitan76.mcpitanlib.api.command.argument.LongCommand; + +public class LongCommandEvent extends RequiredCommandEvent { + public Long getValue() { + return LongArgumentType.getLong(context, ((LongCommand) getCommand()).getArgumentName()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/PlayerCommandEvent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/PlayerCommandEvent.java new file mode 100644 index 000000000..7fad3ba41 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/PlayerCommandEvent.java @@ -0,0 +1,16 @@ +package net.pitan76.mcpitanlib.api.event; + +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import net.minecraft.command.argument.EntityArgumentType; +import net.minecraft.entity.Entity; +import net.pitan76.mcpitanlib.api.command.argument.PlayerCommand; + +public class PlayerCommandEvent extends RequiredCommandEvent { + public Entity getValue() { + try { + return EntityArgumentType.getPlayer(context, ((PlayerCommand) getCommand()).getArgumentName()); + } catch (CommandSyntaxException e) { + throw new RuntimeException(e); + } + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/PlayersCommandEvent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/PlayersCommandEvent.java new file mode 100644 index 000000000..aa845fd17 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/PlayersCommandEvent.java @@ -0,0 +1,16 @@ +package net.pitan76.mcpitanlib.api.event; + +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import net.minecraft.command.argument.EntityArgumentType; +import net.minecraft.entity.Entity; +import net.pitan76.mcpitanlib.api.command.argument.PlayersCommand; + +public class PlayersCommandEvent extends RequiredCommandEvent { + public Entity getValue() { + try { + return EntityArgumentType.getPlayer(context, ((PlayersCommand) getCommand()).getArgumentName()); + } catch (CommandSyntaxException e) { + throw new RuntimeException(e); + } + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/RequiredCommandEvent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/RequiredCommandEvent.java new file mode 100644 index 000000000..0ac500819 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/RequiredCommandEvent.java @@ -0,0 +1,5 @@ +package net.pitan76.mcpitanlib.api.event; + +public abstract class RequiredCommandEvent extends ServerCommandEvent { + public abstract Object getValue(); +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/ServerCommandEvent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/ServerCommandEvent.java new file mode 100644 index 000000000..8cf6a1860 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/ServerCommandEvent.java @@ -0,0 +1,134 @@ +package net.pitan76.mcpitanlib.api.event; + +import com.mojang.brigadier.Command; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.context.StringRange; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.text.Text; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.entity.Player; +import net.pitan76.mcpitanlib.api.text.TextComponent; +import net.pitan76.mcpitanlib.api.util.TextUtil; +import net.pitan76.mcpitanlib.api.util.WorldUtil; + +public class ServerCommandEvent extends CommandEvent { + + public CommandContext getContext() { + return context; + } + + public void setContext(CommandContext context) { + this.context = context; + } + + public ServerCommandSource getSource() { + return getContext().getSource(); + } + + public PlayerEntity getPlayerEntity() throws CommandSyntaxException { + return getSource().getPlayer(); + } + + public Player getPlayer() throws CommandSyntaxException { + return new Player(getPlayerEntity()); + } + + public World getWorld() { + return getSource().getWorld(); + } + + public Entity getEntity() { + return getSource().getEntity(); + } + + public String getInput() { + return getContext().getInput(); + } + + public Command getContextCommand() { + return getContext().getCommand(); + } + + public CommandContext getChild() { + return getContext().getChild(); + } + + public CommandContext getLastChild() { + return getContext().getLastChild(); + } + + public StringRange getRange() { + return getContext().getRange(); + } + + // Text + public void sendSuccess(Text message, boolean broadcastToOps) { + getSource().sendFeedback(() -> message, broadcastToOps); + } + + public void sendFailure(Text message) { + getSource().sendError(message); + } + + public void sendSuccess(Text message) { + sendSuccess(message, false); + } + + // String (Formatted) + public void sendSuccess(String message, boolean broadcastToOps) { + sendSuccess(TextUtil.convert(message), broadcastToOps); + } + + public void sendSuccess(String message) { + sendSuccess(message, false); + } + + public void sendFailure(String message) { + sendFailure(TextUtil.convert(message)); + } + + // Translatable + public void sendSuccessWithTranslatable(String message, boolean broadcastToOps) { + sendSuccess(TextUtil.convertWithTranslatable(message), broadcastToOps); + } + + public void sendSuccessWithTranslatable(String message) { + sendSuccessWithTranslatable(message, false); + } + + public void sendFailureWithTranslatable(String message) { + sendFailure(TextUtil.convertWithTranslatable(message)); + } + + // Raw + public void sendSuccessRaw(String message, boolean broadcastToOps) { + sendSuccess(TextUtil.literal(message), broadcastToOps); + } + + public void sendSuccessRaw(String message) { + sendSuccessRaw(message, false); + } + + public void sendFailureRaw(String message) { + sendFailure(TextUtil.literal(message)); + } + + public boolean isClient() { + return WorldUtil.isClient(getWorld()); + } + + public void sendSuccess(TextComponent message, boolean broadcastToOps) { + sendSuccess(message.getText(), broadcastToOps); + } + + public void sendSuccess(TextComponent message) { + sendSuccess(message.getText()); + } + + public void sendFailure(TextComponent message) { + sendFailure(message.getText()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/StringCommandEvent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/StringCommandEvent.java new file mode 100644 index 000000000..35042c8f6 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/StringCommandEvent.java @@ -0,0 +1,10 @@ +package net.pitan76.mcpitanlib.api.event; + +import com.mojang.brigadier.arguments.StringArgumentType; +import net.pitan76.mcpitanlib.api.command.argument.StringCommand; + +public class StringCommandEvent extends RequiredCommandEvent { + public String getValue() { + return StringArgumentType.getString(context, ((StringCommand) getCommand()).getArgumentName()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/AppendPropertiesArgs.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/AppendPropertiesArgs.java new file mode 100644 index 000000000..087efa37b --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/AppendPropertiesArgs.java @@ -0,0 +1,35 @@ +package net.pitan76.mcpitanlib.api.event.block; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.state.StateManager; +import net.minecraft.state.property.Property; +import net.pitan76.mcpitanlib.api.event.BaseEvent; +import net.pitan76.mcpitanlib.api.state.property.IProperty; +import net.pitan76.mcpitanlib.api.util.DirectionBoolPropertyUtil; + +public class AppendPropertiesArgs extends BaseEvent { + public StateManager.Builder builder; + + public AppendPropertiesArgs(StateManager.Builder builder) { + this.builder = builder; + } + + public StateManager.Builder getBuilder() { + return builder; + } + + public void addProperty(Property... properties) { + builder.add(properties); + } + + public void addProperty(IProperty... properties) { + for (IProperty property : properties) { + builder.add(property.getProperty()); + } + } + + public void addAllDirectionBoolProperties() { + DirectionBoolPropertyUtil.addProperties(this); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/BlockBreakEvent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/BlockBreakEvent.java new file mode 100644 index 000000000..a5351d2aa --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/BlockBreakEvent.java @@ -0,0 +1,79 @@ +package net.pitan76.mcpitanlib.api.event.block; + +import net.minecraft.block.BlockState; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.entity.Player; +import net.pitan76.mcpitanlib.api.event.BaseEvent; +import net.pitan76.mcpitanlib.api.util.WorldUtil; +import net.pitan76.mcpitanlib.midohra.block.BlockWrapper; +import net.pitan76.mcpitanlib.midohra.block.entity.BlockEntityWrapper; +import net.pitan76.mcpitanlib.midohra.world.IWorldView; + +public class BlockBreakEvent extends BaseEvent { + public World world; + public BlockPos pos; + public BlockState state; + public Player player; + + public BlockBreakEvent(World world, BlockPos pos, BlockState state, PlayerEntity player) { + this.world = world; + this.pos = pos; + this.state = state; + this.player = new Player(player); + } + + public BlockPos getPos() { + return pos; + } + + public BlockState getState() { + return state; + } + + public Player getPlayer() { + return player; + } + + public PlayerEntity getPlayerEntity() { + return player.getPlayerEntity(); + } + + public World getWorld() { + return world; + } + + public boolean isClient() { + return world.isClient(); + } + + public BlockEntity getBlockEntity() { + return WorldUtil.getBlockEntity(getWorld(), getPos()); + } + + public net.pitan76.mcpitanlib.midohra.world.World getMidohraWorld() { + return net.pitan76.mcpitanlib.midohra.world.World.of(world); + } + + public IWorldView getWorldView() { + return getMidohraWorld(); + } + + public net.pitan76.mcpitanlib.midohra.block.BlockState getMidohraState() { + return net.pitan76.mcpitanlib.midohra.block.BlockState.of(state); + } + + public net.pitan76.mcpitanlib.midohra.util.math.BlockPos getMidohraPos() { + return net.pitan76.mcpitanlib.midohra.util.math.BlockPos.of(pos); + } + + public BlockWrapper getBlockWrapper() { + return BlockWrapper.of(state.getBlock()); + } + + public BlockEntityWrapper getBlockEntityWrapper() { + return BlockEntityWrapper.of(getBlockEntity()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/BlockBreakStartEvent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/BlockBreakStartEvent.java new file mode 100644 index 000000000..c50170a81 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/BlockBreakStartEvent.java @@ -0,0 +1,61 @@ +package net.pitan76.mcpitanlib.api.event.block; + +import net.minecraft.block.BlockState; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.entity.Player; +import net.pitan76.mcpitanlib.api.event.BaseEvent; +import net.pitan76.mcpitanlib.api.util.WorldUtil; + +public class BlockBreakStartEvent extends BaseEvent { + + public BlockState state; + public World world; + public BlockPos pos; + public Player player; + + public BlockBreakStartEvent(BlockState state, World world, BlockPos pos, Player player) { + this.state = state; + this.world = world; + this.pos = pos; + this.player = player; + } + + public boolean isClient() { + return WorldUtil.isClient(world); + } + + public BlockState getState() { + return state; + } + + public World getWorld() { + return world; + } + + public BlockPos getPos() { + return pos; + } + + public Player getPlayer() { + return player; + } + + public BlockPos getPlayerPos() { + return player.getBlockPos(); + } + + public ItemStack getPlayerMainHandStack() { + return player.getMainHandStack(); + } + + public ItemStack getPlayerOffHandStack() { + return player.getOffHandStack(); + } + + public BlockEntity getBlockEntity() { + return WorldUtil.getBlockEntity(getWorld(), getPos()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/BlockPlacedEvent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/BlockPlacedEvent.java new file mode 100644 index 000000000..c0b365e0a --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/BlockPlacedEvent.java @@ -0,0 +1,82 @@ +package net.pitan76.mcpitanlib.api.event.block; + +import net.minecraft.block.BlockState; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.entity.LivingEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.event.BaseEvent; +import net.pitan76.mcpitanlib.api.util.WorldUtil; +import net.pitan76.mcpitanlib.midohra.block.BlockWrapper; +import net.pitan76.mcpitanlib.midohra.block.entity.BlockEntityWrapper; +import net.pitan76.mcpitanlib.midohra.world.IWorldView; + +public class BlockPlacedEvent extends BaseEvent { + + public World world; + public BlockPos pos; + public BlockState state; + public LivingEntity placer; + public ItemStack stack; + + public BlockPlacedEvent(World world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack itemStack) { + this.world = world; + this.pos = pos; + this.state = state; + this.placer = placer; + this.stack = itemStack; + } + + public BlockState getState() { + return state; + } + + public BlockPos getPos() { + return pos; + } + + public World getWorld() { + return world; + } + + public ItemStack getStack() { + return stack; + } + + public LivingEntity getPlacer() { + return placer; + } + + public boolean isClient() { + return world.isClient(); + } + + public BlockEntity getBlockEntity() { + return WorldUtil.getBlockEntity(getWorld(), getPos()); + } + + public net.pitan76.mcpitanlib.midohra.world.World getMidohraWorld() { + return net.pitan76.mcpitanlib.midohra.world.World.of(world); + } + + public IWorldView getWorldView() { + return getMidohraWorld(); + } + + public net.pitan76.mcpitanlib.midohra.block.BlockState getMidohraState() { + return net.pitan76.mcpitanlib.midohra.block.BlockState.of(state); + } + + public net.pitan76.mcpitanlib.midohra.util.math.BlockPos getMidohraPos() { + return net.pitan76.mcpitanlib.midohra.util.math.BlockPos.of(pos); + } + + public BlockWrapper getBlockWrapper() { + return BlockWrapper.of(state.getBlock()); + } + + public BlockEntityWrapper getBlockEntityWrapper() { + return BlockEntityWrapper.of(getBlockEntity()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/BlockScheduledTickEvent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/BlockScheduledTickEvent.java new file mode 100644 index 000000000..f80420f5b --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/BlockScheduledTickEvent.java @@ -0,0 +1,50 @@ +package net.pitan76.mcpitanlib.api.event.block; + +import net.minecraft.block.BlockState; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.random.Random; +import net.pitan76.mcpitanlib.api.event.BaseEvent; +import net.pitan76.mcpitanlib.api.util.WorldUtil; +import net.pitan76.mcpitanlib.api.util.math.random.CompatRandom; +import net.pitan76.mcpitanlib.midohra.holder.BlockStatePropertyHolder; + +public class BlockScheduledTickEvent extends BaseEvent implements BlockStatePropertyHolder { + public BlockState state; + public ServerWorld world; + public BlockPos pos; + public CompatRandom random; + + public BlockScheduledTickEvent(BlockState state, ServerWorld world, BlockPos pos, Random random) { + this.state = state; + this.world = world; + this.pos = pos; + this.random = new CompatRandom(random); + } + + public BlockState getState() { + return state; + } + + public BlockPos getPos() { + return pos; + } + + public ServerWorld getWorld() { + return world; + } + + public CompatRandom getRandom() { + return random; + } + + public BlockEntity getBlockEntity() { + return WorldUtil.getBlockEntity(getWorld(), getPos()); + } + + @Override + public net.pitan76.mcpitanlib.midohra.block.BlockState getBlockState() { + return net.pitan76.mcpitanlib.midohra.block.BlockState.of(state); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/BlockUseEvent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/BlockUseEvent.java new file mode 100644 index 000000000..f6d29de43 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/BlockUseEvent.java @@ -0,0 +1,129 @@ +package net.pitan76.mcpitanlib.api.event.block; + +import net.minecraft.block.BlockState; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.util.Hand; +import net.minecraft.util.hit.BlockHitResult; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.entity.Player; +import net.pitan76.mcpitanlib.api.event.BaseEvent; +import net.pitan76.mcpitanlib.api.util.CompatActionResult; +import net.pitan76.mcpitanlib.api.util.WorldUtil; +import net.pitan76.mcpitanlib.midohra.block.BlockWrapper; +import net.pitan76.mcpitanlib.midohra.block.entity.BlockEntityWrapper; +import net.pitan76.mcpitanlib.midohra.world.IWorldView; + +public class BlockUseEvent extends BaseEvent { + public BlockState state; + public World world; + public BlockPos pos; + public Player player; + public Hand hand; + public BlockHitResult hit; + public ItemStack stack; + + public BlockUseEvent(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { + this.state = state; + this.world = world; + this.pos = pos; + this.player = new Player(player); + this.hand = hand; + this.hit = hit; + this.stack = this.player.getStackInHand(hand); + } + + public BlockHitResult getHit() { + return hit; + } + + public ItemStack getStack() { + return stack; + } + + public Player getPlayer() { + return player; + } + + public Hand getHand() { + return hand; + } + + public World getWorld() { + return world; + } + + public BlockState getState() { + return state; + } + + public BlockPos getPos() { + return pos; + } + + public boolean isClient() { + return world.isClient(); + } + + public CompatActionResult success() { + return CompatActionResult.SUCCESS; + } + + public CompatActionResult fail() { + return CompatActionResult.FAIL; + } + + public CompatActionResult pass() { + return CompatActionResult.PASS; + } + + public CompatActionResult consume() { + return CompatActionResult.CONSUME; + } + + /** + * check if the block has a block entity + * @return true if the block has a block entity + */ + public boolean hasBlockEntity() { + return WorldUtil.hasBlockEntity(world, pos); + } + + /** + * get the block entity of the block + * @return the block entity of the block + */ + public BlockEntity getBlockEntity() { + return WorldUtil.getBlockEntity(world, pos); + } + + public boolean isSneaking() { + return player.isSneaking(); + } + + public net.pitan76.mcpitanlib.midohra.world.World getMidohraWorld() { + return net.pitan76.mcpitanlib.midohra.world.World.of(world); + } + + public IWorldView getWorldView() { + return getMidohraWorld(); + } + + public net.pitan76.mcpitanlib.midohra.block.BlockState getMidohraState() { + return net.pitan76.mcpitanlib.midohra.block.BlockState.of(state); + } + + public net.pitan76.mcpitanlib.midohra.util.math.BlockPos getMidohraPos() { + return net.pitan76.mcpitanlib.midohra.util.math.BlockPos.of(pos); + } + + public BlockWrapper getBlockWrapper() { + return BlockWrapper.of(state.getBlock()); + } + + public BlockEntityWrapper getBlockEntityWrapper() { + return BlockEntityWrapper.of(getBlockEntity()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/CanPathfindThroughArgs.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/CanPathfindThroughArgs.java new file mode 100644 index 000000000..eb92b3f7f --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/CanPathfindThroughArgs.java @@ -0,0 +1,50 @@ +package net.pitan76.mcpitanlib.api.event.block; + +import net.minecraft.block.BlockState; +import net.minecraft.entity.ai.pathing.NavigationType; +import net.minecraft.fluid.FluidState; +import net.pitan76.mcpitanlib.api.event.BaseEvent; +import net.pitan76.mcpitanlib.api.util.FluidStateUtil; + +public class CanPathfindThroughArgs extends BaseEvent { + public BlockState state; + public NavigationType type; + + public CanPathfindThroughArgs(BlockState state, NavigationType type) { + this.state = state; + + this.type = type; + } + + public BlockState getState() { + return state; + } + + public NavigationType getType() { + return type; + } + + public FluidState getFluidState() { + return state.getFluidState(); + } + + public boolean isWaterNavigationType() { + return type == NavigationType.WATER; + } + + public boolean isAirNavigationType() { + return type == NavigationType.AIR; + } + + public boolean isLandNavigationType() { + return type == NavigationType.LAND; + } + + public boolean isWaterState() { + return FluidStateUtil.isWater(getFluidState()); + } + + public boolean isLavaState() { + return FluidStateUtil.isLava(getFluidState()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/CollisionShapeEvent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/CollisionShapeEvent.java new file mode 100644 index 000000000..43fab8bc5 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/CollisionShapeEvent.java @@ -0,0 +1,13 @@ +package net.pitan76.mcpitanlib.api.event.block; + +import net.minecraft.block.BlockState; +import net.minecraft.block.ShapeContext; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.BlockView; + +public class CollisionShapeEvent extends OutlineShapeEvent { + + public CollisionShapeEvent(BlockState state, BlockView world, BlockPos pos, ShapeContext context) { + super(state, world, pos, context); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/DroppedStacksArgs.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/DroppedStacksArgs.java new file mode 100644 index 000000000..edb85cb20 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/DroppedStacksArgs.java @@ -0,0 +1,30 @@ +package net.pitan76.mcpitanlib.api.event.block; + +import net.minecraft.block.BlockState; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.loot.context.LootContextParameterSet; +import net.minecraft.loot.context.LootContextParameters; +import net.pitan76.mcpitanlib.api.event.BaseEvent; + +public class DroppedStacksArgs extends BaseEvent { + public BlockState state; + public LootContextParameterSet.Builder builder; + + public DroppedStacksArgs(BlockState state, LootContextParameterSet.Builder builder) { + this.state = state; + this.builder = builder; + } + + public BlockState getState() { + return state; + } + + @Deprecated + public LootContextParameterSet.Builder getBuilder() { + return builder; + } + + public BlockEntity getBlockEntity() { + return builder.get(LootContextParameters.BLOCK_ENTITY); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/EntityCollisionEvent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/EntityCollisionEvent.java new file mode 100644 index 000000000..41abb7dcf --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/EntityCollisionEvent.java @@ -0,0 +1,88 @@ +package net.pitan76.mcpitanlib.api.event.block; + +import net.minecraft.block.BlockState; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.sound.SoundCategory; +import net.minecraft.sound.SoundEvent; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.event.BaseEvent; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.api.util.SoundEventUtil; +import net.pitan76.mcpitanlib.api.util.WorldUtil; + +import java.util.Optional; + +public class EntityCollisionEvent extends BaseEvent { + + public BlockState state; + public World world; + public BlockPos pos; + public Entity entity; + + public EntityCollisionEvent(BlockState state, World world, BlockPos pos, Entity entity) { + this.state = state; + this.world = world; + this.pos = pos; + this.entity = entity; + } + + public boolean isClient() { + return WorldUtil.isClient(world); + } + + public BlockPos getEntityPos() { + return entity.getBlockPos(); + } + + public BlockPos getBlockPos() { + return pos; + } + + public BlockState getState() { + return state; + } + + public Entity getEntity() { + return entity; + } + + public World getWorld() { + return world; + } + + public void playSound(SoundEvent event, SoundCategory category, float volume, float pitch) { + WorldUtil.playSound(world, null, entity.getBlockPos(), event, category, volume, pitch); + } + + public void playSound(SoundEvent event, float volume, float pitch) { + playSound(event, SoundCategory.BLOCKS, volume, pitch); + } + + public void playSound(SoundEvent event) { + playSound(event, 1f, 1f); + } + + public void playSound(SoundEvent event, SoundCategory category) { + playSound(event, category, 1f, 1f); + } + + public void playSound(CompatIdentifier id, SoundCategory category, float volume, float pitch) { + playSound(SoundEventUtil.getSoundEvent(id), category, volume, pitch); + } + + public boolean hasPlayerEntity() { + return entity instanceof PlayerEntity; + } + + public Optional getPlayerEntity() { + if (!hasPlayerEntity()) return Optional.empty(); + return Optional.of((PlayerEntity) entity); + } + + public BlockEntity getBlockEntity() { + return WorldUtil.getBlockEntity(getWorld(), getBlockPos()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/FluidStateArgs.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/FluidStateArgs.java new file mode 100644 index 000000000..9bcda6872 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/FluidStateArgs.java @@ -0,0 +1,19 @@ +package net.pitan76.mcpitanlib.api.event.block; + +import net.minecraft.block.BlockState; + +public class FluidStateArgs { + public BlockState state; + + public FluidStateArgs(BlockState state) { + this.state = state; + } + + public BlockState getState() { + return state; + } + + public net.pitan76.mcpitanlib.midohra.block.BlockState getMidohraState() { + return net.pitan76.mcpitanlib.midohra.block.BlockState.of(state); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/ItemScattererUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/ItemScattererUtil.java new file mode 100644 index 000000000..400e211ce --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/ItemScattererUtil.java @@ -0,0 +1,50 @@ +package net.pitan76.mcpitanlib.api.event.block; + +import net.minecraft.block.BlockState; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.inventory.Inventory; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ItemScatterer; +import net.minecraft.util.collection.DefaultedList; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +public class ItemScattererUtil { + public static void spawn(World world, BlockPos pos, BlockEntity blockEntity) { + if (blockEntity instanceof Inventory) { + spawn(world, pos, (Inventory) blockEntity); + } + } + + public static void spawn(World world, BlockPos pos, Inventory inventory) { + ItemScatterer.spawn(world, pos, inventory); + } + + public static void spawn(World world, BlockPos pos, ItemStack stack) { + ItemScatterer.spawn(world, pos.getX(), pos.getY(), pos.getZ(), stack); + } + + public static void spawn(World world, BlockPos pos, DefaultedList stacks) { + ItemScatterer.spawn(world, pos, stacks); + } + + public static void onStateReplaced(StateReplacedEvent e) { + onStateReplaced(e.getState(), e.getNewState(), e.getWorld(), e.getPos()); + } + + public static void onStateReplaced(BlockState state, BlockState newState, World world, BlockPos pos) { + ItemScatterer.onStateReplaced(state, newState, world, pos); + } + + public static void spawn(net.pitan76.mcpitanlib.midohra.world.World world, net.pitan76.mcpitanlib.midohra.util.math.BlockPos pos, ItemStack stack) { + spawn(world.getRaw(), pos.toMinecraft(), stack); + } + + public static void spawn(net.pitan76.mcpitanlib.midohra.world.World world, net.pitan76.mcpitanlib.midohra.util.math.BlockPos pos, DefaultedList stacks) { + spawn(world.getRaw(), pos.toMinecraft(), stacks); + } + + public static void spawn(net.pitan76.mcpitanlib.midohra.world.World world, net.pitan76.mcpitanlib.midohra.util.math.BlockPos pos, Inventory inventory) { + spawn(world.getRaw(), pos.toMinecraft(), inventory); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/NeighborUpdateEvent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/NeighborUpdateEvent.java new file mode 100644 index 000000000..6d55e70f8 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/NeighborUpdateEvent.java @@ -0,0 +1,88 @@ +package net.pitan76.mcpitanlib.api.event.block; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.event.BaseEvent; +import net.pitan76.mcpitanlib.api.util.WorldUtil; +import net.pitan76.mcpitanlib.midohra.block.entity.BlockEntityWrapper; +import org.jetbrains.annotations.Nullable; + +public class NeighborUpdateEvent extends BaseEvent { + public BlockState state; + public World world; + public BlockPos pos; + public Block sourceBlock; + + @Nullable + public BlockPos sourcePos; + + public boolean notify; + + public NeighborUpdateEvent(BlockState state, World world, BlockPos pos, Block sourceBlock, @Nullable BlockPos sourcePos, boolean notify) { + this.state = state; + this.world = world; + this.pos = pos; + this.sourceBlock = sourceBlock; + this.sourcePos = sourcePos; + this.notify = notify; + } + + public NeighborUpdateEvent(BlockState state, World world, BlockPos pos, Block sourceBlock, boolean notify) { + this(state, world, pos, sourceBlock, null, notify); + } + + public BlockState getState() { + return state; + } + + public World getWorld() { + return world; + } + + public BlockPos getPos() { + return pos; + } + + public Block getSourceBlock() { + return sourceBlock; + } + + public @Nullable BlockPos getSourcePos() { + return sourcePos; + } + + public boolean isNotify() { + return notify; + } + + public boolean isReceivingRedstonePower() { + return WorldUtil.isReceivingRedstonePower(world, pos); + } + + public BlockEntity getBlockEntity() { + return WorldUtil.getBlockEntity(world, pos); + } + + public boolean hasBlockEntity() { + return WorldUtil.hasBlockEntity(world, pos); + } + + public net.pitan76.mcpitanlib.midohra.world.World getMidohraWorld() { + return net.pitan76.mcpitanlib.midohra.world.World.of(world); + } + + public net.pitan76.mcpitanlib.midohra.util.math.BlockPos getMidohraPos() { + return net.pitan76.mcpitanlib.midohra.util.math.BlockPos.of(pos); + } + + public net.pitan76.mcpitanlib.midohra.block.BlockState getMidohraState() { + return net.pitan76.mcpitanlib.midohra.block.BlockState.of(state); + } + + public BlockEntityWrapper getBlockEntityWrapper() { + return BlockEntityWrapper.of(getBlockEntity()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/OutlineShapeEvent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/OutlineShapeEvent.java new file mode 100644 index 000000000..7131ee630 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/OutlineShapeEvent.java @@ -0,0 +1,63 @@ +package net.pitan76.mcpitanlib.api.event.block; + +import net.minecraft.block.BlockState; +import net.minecraft.block.ShapeContext; +import net.minecraft.state.property.Property; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.BlockView; +import net.pitan76.mcpitanlib.api.event.BaseEvent; +import net.pitan76.mcpitanlib.api.state.property.IProperty; + +public class OutlineShapeEvent extends BaseEvent { + public BlockState state; + public BlockView world; + public BlockPos pos; + public ShapeContext context; + + public OutlineShapeEvent(BlockState state, BlockView world, BlockPos pos, ShapeContext context) { + this.state = state; + this.world = world; + this.pos = pos; + this.context = context; + } + + public BlockPos getPos() { + return pos; + } + + public BlockState getState() { + return state; + } + + public BlockView getWorld() { + return world; + } + + public ShapeContext getContext() { + return context; + } + + public > T getProperty(Property property) { + return state.get(property); + } + + public > boolean containsProperty(Property property) { + return state.contains(property); + } + + public , V extends T> BlockState with(Property property, V value) { + return state.with(property, value); + } + + public > T get(IProperty property) { + return getProperty(property.getProperty()); + } + + public > boolean contains(IProperty property) { + return containsProperty(property.getProperty()); + } + + public , V extends T> net.pitan76.mcpitanlib.midohra.block.BlockState with(IProperty property, V value) { + return net.pitan76.mcpitanlib.midohra.block.BlockState.of(with(property.getProperty(), value)); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/PickStackEvent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/PickStackEvent.java new file mode 100644 index 000000000..762907be8 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/PickStackEvent.java @@ -0,0 +1,93 @@ +package net.pitan76.mcpitanlib.api.event.block; + +import net.minecraft.block.BlockState; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.BlockView; +import net.minecraft.world.WorldView; +import org.jetbrains.annotations.Nullable; + +public class PickStackEvent { + + @Deprecated + public WorldView worldView; + + @Deprecated + public BlockView blockView; + + public BlockPos pos; + public BlockState state; + + public boolean includeData = true; + + public PickStackEvent(WorldView world, BlockPos pos, BlockState state) { + this.worldView = world; + this.pos = pos; + this.state = state; + } + + public PickStackEvent(BlockView world, BlockPos pos, BlockState state) { + this.blockView = world; + this.pos = pos; + this.state = state; + } + + public BlockState getState() { + return state; + } + + public BlockPos getPos() { + return pos; + } + + @Nullable + public BlockView getBlockView() { + return blockView; + } + + @Nullable + public WorldView getWorldView() { + return worldView; + } + + /** + * check if the block has a block entity + * @return boolean + */ + public boolean hasBlockEntity() { + return getBlockEntity() != null; + } + + /** + * @return BlockEntity + */ + public BlockEntity getBlockEntity() { + if (blockView != null) + return blockView.getBlockEntity(pos); + if (worldView != null) + return worldView.getBlockEntity(pos); + return null; + } + + public boolean isClient() { + if (blockView != null) + return getBlockEntity().getWorld().isClient(); + if (worldView != null) + return worldView.isClient(); + + try { + net.minecraft.client.MinecraftClient.getInstance(); + return true; + } catch (Error e) { + return false; + } + } + + public void setIncludeData(boolean includeData) { + this.includeData = includeData; + } + + public boolean isIncludeData() { + return includeData; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/PlacementStateArgs.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/PlacementStateArgs.java new file mode 100644 index 000000000..63df37634 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/PlacementStateArgs.java @@ -0,0 +1,125 @@ +package net.pitan76.mcpitanlib.api.event.block; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.item.ItemPlacementContext; +import net.minecraft.state.property.Property; +import net.minecraft.util.Hand; +import net.minecraft.util.hit.BlockHitResult; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import net.minecraft.util.math.Vec3d; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.entity.Player; +import net.pitan76.mcpitanlib.api.event.BaseEvent; +import net.pitan76.mcpitanlib.api.event.item.ItemUseOnBlockEvent; +import net.pitan76.mcpitanlib.api.state.property.IProperty; +import net.pitan76.mcpitanlib.api.util.BlockStateUtil; +import net.pitan76.mcpitanlib.api.util.WorldUtil; +import net.pitan76.mcpitanlib.mixin.ItemUsageContextMixin; +import org.jetbrains.annotations.Nullable; + +public class PlacementStateArgs extends BaseEvent { + public ItemPlacementContext ctx; + + @Nullable + public Block block; + + public PlacementStateArgs(ItemPlacementContext ctx) { + this.ctx = ctx; + } + + public PlacementStateArgs(ItemPlacementContext ctx, @Nullable Block block) { + this.ctx = ctx; + this.block = block; + } + + public boolean canPlace() { + return ctx.canPlace(); + } + + public BlockPos getPos() { + return ctx.getBlockPos(); + } + + public Player getPlayer() { + return new Player(ctx.getPlayer()); + } + + public Direction[] getPlacementDirections() { + return ctx.getPlacementDirections(); + } + + public Hand getHand() { + return ctx.getHand(); + } + + public Direction getSide() { + return ctx.getSide(); + } + + public Direction getHorizontalPlayerFacing() { + return ctx.getHorizontalPlayerFacing(); + } + + public float getPlayerYaw() { + return ctx.getPlayerYaw(); + } + + public World getWorld() { + return ctx.getWorld(); + } + + public boolean isClient() { + return getWorld().isClient(); + } + + public Vec3d getHitPos() { + return ctx.getHitPos(); + } + + public boolean canReplaceExisting() { + return ctx.canReplaceExisting(); + } + + @Deprecated + public ItemUsageContextMixin getIUCAccessor() { + return (ItemUsageContextMixin) ctx; + } + + public BlockHitResult getHitResult() { + return getIUCAccessor().getHit(); + } + + public ItemUseOnBlockEvent toItemUseOnBlockEvent() { + return new ItemUseOnBlockEvent(getWorld(), getPlayer().getPlayerEntity(), getHand(), ctx.getStack(), getHitResult()); + } + + public ItemPlacementContext getCtx() { + return ctx; + } + + public , V extends T> BlockState withBlockState(Property property, V value) { + if (block == null) + return null; + + return BlockStateUtil.with(BlockStateUtil.getDefaultState(block), property, value); + } + + public , V extends T> net.pitan76.mcpitanlib.midohra.block.BlockState with(IProperty property, V value) { + return net.pitan76.mcpitanlib.midohra.block.BlockState.of(withBlockState(property.getProperty(), value)); + } + + public BlockState getBlockState() { + return BlockStateUtil.getDefaultState(block); + } + + public net.pitan76.mcpitanlib.midohra.block.BlockState getMidohraBlockState() { + return net.pitan76.mcpitanlib.midohra.block.BlockState.of(getBlockState()); + } + + public BlockEntity getBlockEntity() { + return WorldUtil.getBlockEntity(getWorld(), getPos()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/ScreenHandlerCreateEvent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/ScreenHandlerCreateEvent.java new file mode 100644 index 000000000..013f0c069 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/ScreenHandlerCreateEvent.java @@ -0,0 +1,56 @@ +package net.pitan76.mcpitanlib.api.event.block; + +import net.minecraft.block.BlockState; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.entity.Player; +import net.pitan76.mcpitanlib.api.event.BaseEvent; + +public class ScreenHandlerCreateEvent extends BaseEvent { + + public BlockState state; + public World world; + public BlockPos pos; + public int syncId; + public PlayerInventory inventory; + public Player player; + + public ScreenHandlerCreateEvent(BlockState state, World world, BlockPos pos, int syncId, PlayerInventory inventory, PlayerEntity player) { + this.state = state; + this.world = world; + this.pos = pos; + this.syncId = syncId; + this.inventory = inventory; + this.player = new Player(player); + } + + public BlockState getState() { + return state; + } + + public BlockPos getPos() { + return pos; + } + + public World getWorld() { + return world; + } + + public int getSyncId() { + return syncId; + } + + public PlayerInventory getInventory() { + return inventory; + } + + public Player getPlayer() { + return player; + } + + public boolean isClient() { + return world.isClient; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/ShapesForStatesArgs.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/ShapesForStatesArgs.java new file mode 100644 index 000000000..75cacef6a --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/ShapesForStatesArgs.java @@ -0,0 +1,22 @@ +package net.pitan76.mcpitanlib.api.event.block; + +import net.minecraft.block.BlockState; +import net.minecraft.util.shape.VoxelShape; + +import java.util.function.Function; + +public class ShapesForStatesArgs { + public Function stateToShape; + + public ShapesForStatesArgs(Function stateToShape) { + this.stateToShape = stateToShape; + } + + public Function getStateToShape() { + return stateToShape; + } + + public VoxelShape getShape(BlockState state) { + return stateToShape.apply(state); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/StateForNeighborUpdateArgs.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/StateForNeighborUpdateArgs.java new file mode 100644 index 000000000..65109040e --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/StateForNeighborUpdateArgs.java @@ -0,0 +1,69 @@ +package net.pitan76.mcpitanlib.api.event.block; + +import net.minecraft.block.BlockState; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import net.minecraft.world.WorldAccess; +import net.minecraft.world.WorldView; +import net.pitan76.mcpitanlib.api.util.math.random.CompatRandom; + +public class StateForNeighborUpdateArgs { + public BlockState state; + public Direction direction; + public BlockState neighborState; + public WorldAccess world; + public BlockPos pos; + public BlockPos neighborPos; + public CompatRandom random; + + public StateForNeighborUpdateArgs(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) { + this.state = state; + this.direction = direction; + this.neighborState = neighborState; + this.world = world; + this.pos = pos; + this.neighborPos = neighborPos; + this.random = CompatRandom.of(); + } + + public BlockState getState() { + return state; + } + + public BlockEntity getBlockEntity() { + return world.getBlockEntity(pos); + } + + public BlockState getBlockState(BlockPos pos) { + return world.getBlockState(pos); + } + + public BlockEntity getBlockEntity(BlockPos pos) { + return world.getBlockEntity(pos); + } + + public Direction getDirection() { + return direction; + } + + public BlockState getNeighborState() { + return neighborState; + } + + public WorldView getWorld() { + return world; + } + + public BlockPos getPos() { + return pos; + } + + public BlockPos getNeighborPos() { + return neighborPos; + } + + public CompatRandom getRandom() { + return random; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/StateReplacedEvent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/StateReplacedEvent.java new file mode 100644 index 000000000..4be061fb6 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/StateReplacedEvent.java @@ -0,0 +1,132 @@ +package net.pitan76.mcpitanlib.api.event.block; + +import net.minecraft.block.BlockState; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.inventory.Inventory; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.event.BaseEvent; +import net.pitan76.mcpitanlib.api.util.WorldUtil; +import net.pitan76.mcpitanlib.midohra.block.BlockWrapper; +import net.pitan76.mcpitanlib.midohra.block.entity.BlockEntityWrapper; +import net.pitan76.mcpitanlib.midohra.world.IWorldView; + +public class StateReplacedEvent extends BaseEvent { + + public BlockState state; + public World world; + public BlockPos pos; + public BlockState newState; + public boolean moved; + + // Captured at construction time so getBlockEntity() works even after the world (1.21.x) + private final BlockEntity cachedBlockEntity; + + public StateReplacedEvent(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) { + this.state = state; + this.world = world; + this.pos = pos; + this.newState = newState; + this.moved = moved; + + this.cachedBlockEntity = WorldUtil.hasBlockEntity(world, pos) ? WorldUtil.getBlockEntity(world, pos) : null; + } + + public BlockState getState() { + return state; + } + + public World getWorld() { + return world; + } + + public BlockPos getPos() { + return pos; + } + + public BlockState getNewState() { + return newState; + } + + public boolean isMoved() { + return moved; + } + + public boolean isClient() { + return world.isClient(); + } + + /** + * check if the block is the same state + * @return boolean + */ + public boolean isSameState() { + return state.isOf(newState.getBlock()); + } + + /** + * check if the block has a block entity + * @return boolean + */ + public boolean hasBlockEntity() { + return getBlockEntity() != null; + } + + /** + * get the block entity + *

+ * The block entity is captured at event creation time, so this returns a valid + * reference even in MC 1.21.x where the world removes the BE before + * onStateReplaced is invoked. + * @return BlockEntity + */ + public BlockEntity getBlockEntity() { + if (cachedBlockEntity != null) return cachedBlockEntity; + return WorldUtil.getBlockEntity(world, pos); + } + + /** + * spawn the drops in the container + */ + public void spawnDropsInContainer() { + if (isSameState() || !hasInventory()) return; + + ItemScattererUtil.spawn(getWorld(), getPos(), getBlockEntity()); + updateComparators(); + } + + public boolean hasInventory() { + return getBlockEntity() instanceof Inventory; + } + + /** + * update the comparators + */ + public void updateComparators() { + WorldUtil.updateComparators(getWorld(), getPos(), getState().getBlock()); + } + + public net.pitan76.mcpitanlib.midohra.world.World getMidohraWorld() { + return net.pitan76.mcpitanlib.midohra.world.World.of(world); + } + + public IWorldView getWorldView() { + return getMidohraWorld(); + } + + public net.pitan76.mcpitanlib.midohra.block.BlockState getMidohraState() { + return net.pitan76.mcpitanlib.midohra.block.BlockState.of(state); + } + + public net.pitan76.mcpitanlib.midohra.util.math.BlockPos getMidohraPos() { + return net.pitan76.mcpitanlib.midohra.util.math.BlockPos.of(pos); + } + + public BlockWrapper getBlockWrapper() { + return BlockWrapper.of(state.getBlock()); + } + + public BlockEntityWrapper getBlockEntityWrapper() { + return BlockEntityWrapper.of(getBlockEntity()); + } +} diff --git a/common/src/main/java/ml/pkom/mcpitanlibarch/api/event/TileCreateEvent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/TileCreateEvent.java similarity index 93% rename from common/src/main/java/ml/pkom/mcpitanlibarch/api/event/TileCreateEvent.java rename to common/src/main/java/net/pitan76/mcpitanlib/api/event/block/TileCreateEvent.java index 56bc84c61..ff0ad3ed9 100644 --- a/common/src/main/java/ml/pkom/mcpitanlibarch/api/event/TileCreateEvent.java +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/TileCreateEvent.java @@ -1,8 +1,9 @@ -package ml.pkom.mcpitanlibarch.api.event; +package net.pitan76.mcpitanlib.api.event.block; import net.minecraft.block.BlockState; import net.minecraft.util.math.BlockPos; import net.minecraft.world.BlockView; +import net.pitan76.mcpitanlib.api.event.BaseEvent; public class TileCreateEvent extends BaseEvent { diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/result/BlockBreakResult.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/result/BlockBreakResult.java new file mode 100644 index 000000000..4973eee09 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/result/BlockBreakResult.java @@ -0,0 +1,15 @@ +package net.pitan76.mcpitanlib.api.event.block.result; + +import net.minecraft.block.BlockState; + +public class BlockBreakResult { + public BlockState state; + + public BlockBreakResult(BlockState state) { + this.state = state; + } + + public BlockState getState() { + return state; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/container/factory/DisplayNameArgs.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/container/factory/DisplayNameArgs.java new file mode 100644 index 000000000..b82cfe48a --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/container/factory/DisplayNameArgs.java @@ -0,0 +1,9 @@ +package net.pitan76.mcpitanlib.api.event.container.factory; + +import net.pitan76.mcpitanlib.api.event.BaseEvent; + +public class DisplayNameArgs extends BaseEvent { + public DisplayNameArgs() { + super(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/container/factory/ExtraDataArgs.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/container/factory/ExtraDataArgs.java new file mode 100644 index 000000000..2b8c2d729 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/container/factory/ExtraDataArgs.java @@ -0,0 +1,55 @@ +package net.pitan76.mcpitanlib.api.event.container.factory; + +import net.minecraft.network.PacketByteBuf; +import net.minecraft.server.network.ServerPlayerEntity; +import net.pitan76.mcpitanlib.api.entity.Player; +import net.pitan76.mcpitanlib.api.event.BaseEvent; +import net.pitan76.mcpitanlib.api.network.PacketByteUtil; + +public class ExtraDataArgs extends BaseEvent { + public PacketByteBuf buf; + public ServerPlayerEntity player; + + public ExtraDataArgs(PacketByteBuf buf, ServerPlayerEntity player) { + super(); + this.buf = buf; + this.player = player; + } + + public ExtraDataArgs() { + super(); + } + + public ExtraDataArgs(PacketByteBuf buf) { + super(); + this.buf = buf; + } + + public boolean hasPlayer() { + return player != null; + } + + public boolean hasBuf() { + return buf != null; + } + + public PacketByteBuf getBuf() { + return buf; + } + + public ServerPlayerEntity getPlayer() { + return player; + } + + public Player getCompatPlayer() { + return new Player(player); + } + + /** + * @param obj The object to write + * @see PacketByteUtil#writeVar(PacketByteBuf, Object) + */ + public void writeVar(Object obj) { + PacketByteUtil.writeVar(getBuf(), obj); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/entity/CollisionEvent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/entity/CollisionEvent.java new file mode 100644 index 000000000..0ea55b691 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/entity/CollisionEvent.java @@ -0,0 +1,34 @@ +package net.pitan76.mcpitanlib.api.event.entity; + +import net.minecraft.util.hit.HitResult; +import net.minecraft.util.math.Vec3d; +import net.pitan76.mcpitanlib.midohra.util.hit.HitResultType; + +public class CollisionEvent { + + public HitResult hitResult; + + public CollisionEvent(HitResult hitResult) { + this.hitResult = hitResult; + } + + public HitResult getHitResult() { + return hitResult; + } + + public HitResult.Type getType() { + return hitResult.getType(); + } + + public Vec3d getPos() { + return hitResult.getPos(); + } + + public net.pitan76.mcpitanlib.midohra.util.hit.HitResult getHitResultM() { + return net.pitan76.mcpitanlib.midohra.util.hit.HitResult.of(getHitResult()); + } + + public HitResultType getHitResultTypeM() { + return HitResultType.from(getType()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/entity/EntityHitEvent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/entity/EntityHitEvent.java new file mode 100644 index 000000000..048b496ed --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/entity/EntityHitEvent.java @@ -0,0 +1,26 @@ +package net.pitan76.mcpitanlib.api.event.entity; + +import net.minecraft.entity.Entity; +import net.minecraft.util.hit.EntityHitResult; +import net.minecraft.util.hit.HitResult; + +public class EntityHitEvent { + + public EntityHitResult entityHitResult; + + public EntityHitEvent(EntityHitResult result) { + this.entityHitResult = result; + } + + public EntityHitResult getEntityHitResult() { + return entityHitResult; + } + + public Entity getEntity() { + return entityHitResult.getEntity(); + } + + public HitResult.Type getType() { + return entityHitResult.getType(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/entity/InitDataTrackerArgs.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/entity/InitDataTrackerArgs.java new file mode 100644 index 000000000..875b6a939 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/entity/InitDataTrackerArgs.java @@ -0,0 +1,47 @@ +package net.pitan76.mcpitanlib.api.event.entity; + +import net.minecraft.entity.data.DataTracker; +import net.minecraft.entity.data.TrackedData; +import org.jetbrains.annotations.Nullable; + +public class InitDataTrackerArgs { + public DataTracker.Builder builder; + public DataTracker tracker; + + public InitDataTrackerArgs(DataTracker.Builder builder) { + this.builder = builder; + } + + public InitDataTrackerArgs(DataTracker tracker) { + this.tracker = tracker; + } + + public InitDataTrackerArgs(DataTracker.Builder builder, @Nullable DataTracker tracker) { + this.builder = builder; + this.tracker = tracker; + } + + public DataTracker.Builder getBuilder() { + return builder; + } + + public DataTracker.Builder add(TrackedData data, T value) { + return builder.add(data, value); + } + + public void set(TrackedData data, T value) { + tracker.set(data, value); + } + + public void addTracking(TrackedData data, T value) { + if (builder != null) { + add(data, value); + return; + } + + if (tracker != null) { + set(data, value); + return; + } + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/item/BonusAttackDamageArgs.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/item/BonusAttackDamageArgs.java new file mode 100644 index 000000000..769b66b63 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/item/BonusAttackDamageArgs.java @@ -0,0 +1,29 @@ +package net.pitan76.mcpitanlib.api.event.item; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.damage.DamageSource; + +public class BonusAttackDamageArgs { + + public Entity target; + public float baseAttackDamage; + public DamageSource damageSource; + + public BonusAttackDamageArgs(Entity target, float baseAttackDamage, DamageSource damageSource) { + this.target = target; + this.baseAttackDamage = baseAttackDamage; + this.damageSource = damageSource; + } + + public Entity getTarget() { + return target; + } + + public float getBaseAttackDamage() { + return baseAttackDamage; + } + + public DamageSource getDamageSource() { + return damageSource; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/item/CanMineArgs.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/item/CanMineArgs.java new file mode 100644 index 000000000..8456d4488 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/item/CanMineArgs.java @@ -0,0 +1,76 @@ +package net.pitan76.mcpitanlib.api.event.item; + +import net.minecraft.block.BlockState; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.entity.Player; +import net.pitan76.mcpitanlib.api.util.WorldUtil; + +public class CanMineArgs { + public BlockState state; + public World world; + public BlockPos pos; + + @Deprecated + public Player miner; + + @Deprecated + public ItemStack stack; + + public LivingEntity entity; + + public CanMineArgs(BlockState state, World world, BlockPos pos, PlayerEntity miner) { + this.state = state; + this.world = world; + this.pos = pos; + this.miner = new Player(miner); + this.entity = miner; + } + + public CanMineArgs(ItemStack stack, BlockState state, World world, BlockPos pos, LivingEntity entity) { + this.stack = stack; + this.state = state; + this.world = world; + this.pos = pos; + this.entity = entity; + + if (entity instanceof PlayerEntity) { + this.miner = new Player((PlayerEntity) entity); + } + } + + public BlockState getState() { + return state; + } + + public World getWorld() { + return world; + } + + public BlockPos getPos() { + return pos; + } + + public Player getMiner() { + return miner; + } + + public boolean isExistMiner() { + return miner.getEntity() != null; + } + + public boolean isClient() { + return WorldUtil.isClient(world); + } + + public ItemStack getStack() { + return stack != null ? stack : entity.getMainHandStack(); + } + + public LivingEntity getEntity() { + return entity; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/item/CanRepairArgs.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/item/CanRepairArgs.java new file mode 100644 index 000000000..2bd98d890 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/item/CanRepairArgs.java @@ -0,0 +1,22 @@ +package net.pitan76.mcpitanlib.api.event.item; + +import net.minecraft.item.ItemStack; +import net.pitan76.mcpitanlib.api.event.BaseEvent; + +public class CanRepairArgs extends BaseEvent { + public ItemStack stack; + public ItemStack ingredient; + + public CanRepairArgs(ItemStack stack, ItemStack ingredient) { + this.stack = stack; + this.ingredient = ingredient; + } + + public ItemStack getStack() { + return stack; + } + + public ItemStack getIngredient() { + return ingredient; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/item/CraftEvent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/item/CraftEvent.java new file mode 100644 index 000000000..a80abdbba --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/item/CraftEvent.java @@ -0,0 +1,48 @@ +package net.pitan76.mcpitanlib.api.event.item; + +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.entity.Player; +import org.jetbrains.annotations.Nullable; + +public class CraftEvent { + + public ItemStack stack; + public World world; + public Player player; + + public CraftEvent(ItemStack stack, World world, Player player) { + this.stack = stack; + this.world = world; + this.player = player; + } + + public CraftEvent(ItemStack stack, World world, PlayerEntity player) { + this.stack = stack; + this.world = world; + this.player = new Player(player); + } + + public CraftEvent(ItemStack stack, World world) { + this.stack = stack; + this.world = world; + } + + public ItemStack getStack() { + return stack; + } + + public World getWorld() { + return world; + } + + @Nullable + public Player getPlayer() { + return player; + } + + public boolean isClient() { + return world.isClient(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/item/EnchantabilityArgs.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/item/EnchantabilityArgs.java new file mode 100644 index 000000000..17392a835 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/item/EnchantabilityArgs.java @@ -0,0 +1,7 @@ +package net.pitan76.mcpitanlib.api.event.item; + +public class EnchantabilityArgs { + public EnchantabilityArgs() { + + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/item/EnchantableArgs.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/item/EnchantableArgs.java new file mode 100644 index 000000000..d466f2a51 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/item/EnchantableArgs.java @@ -0,0 +1,16 @@ +package net.pitan76.mcpitanlib.api.event.item; + +import net.minecraft.item.ItemStack; + +public class EnchantableArgs { + + public ItemStack stack; + + public EnchantableArgs(ItemStack stack) { + this.stack = stack; + } + + public ItemStack getStack() { + return stack; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/item/InventoryTickEvent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/item/InventoryTickEvent.java new file mode 100644 index 000000000..58b0913e9 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/item/InventoryTickEvent.java @@ -0,0 +1,81 @@ +package net.pitan76.mcpitanlib.api.event.item; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.EquipmentSlot; +import net.minecraft.entity.LivingEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.event.BaseEvent; +import net.pitan76.mcpitanlib.api.util.WorldUtil; +import net.pitan76.mcpitanlib.api.util.entity.EquipmentSlotUtil; +import net.pitan76.mcpitanlib.api.util.entity.LivingEntityUtil; + +public class InventoryTickEvent extends BaseEvent { + public ItemStack stack; + public World world; + public Entity entity; + public int slot; + public boolean selected; + public EquipmentSlot equipmentSlot; + + public InventoryTickEvent(ItemStack stack, World world, Entity entity, int slot, boolean selected) { + this.stack = stack; + this.world = world; + this.entity = entity; + this.slot = slot; + this.selected = selected; + this.equipmentSlot = EquipmentSlotUtil.fromEntitySlotId(slot); + } + + public InventoryTickEvent(ItemStack stack, ServerWorld world, Entity entity, EquipmentSlot slot) { + this(stack, world, entity, EquipmentSlotUtil.getEntitySlotId(slot), isSelected(entity, slot, stack)); + this.equipmentSlot = slot; + } + + private static boolean isSelected(Entity entity, EquipmentSlot slot, ItemStack stack) { + if (entity instanceof LivingEntity) { + LivingEntity livingEntity = (LivingEntity) entity; + ItemStack equippedStack = LivingEntityUtil.getEquippedStack(livingEntity, slot); + return equippedStack.isOf(stack.getItem()) && equippedStack.getCount() == stack.getCount(); + } else { + return false; + } + } + + public ItemStack getStack() { + return stack; + } + + public World getWorld() { + return world; + } + + public boolean isServer() { + return !isClient(); + } + + public ServerWorld getServerWorld() { + return (ServerWorld) world; + } + + public Entity getEntity() { + return entity; + } + + public int getSlot() { + return slot; + } + + public boolean isSelected() { + return selected; + } + + public boolean isClient() { + return WorldUtil.isClient(world); + } + + public EquipmentSlot getEquipmentSlot() { + return equipmentSlot; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/item/ItemAppendTooltipEvent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/item/ItemAppendTooltipEvent.java new file mode 100644 index 000000000..e004a31ff --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/item/ItemAppendTooltipEvent.java @@ -0,0 +1,75 @@ +package net.pitan76.mcpitanlib.api.event.item; + +import net.minecraft.item.tooltip.TooltipType; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.text.Text; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.event.BaseEvent; +import net.pitan76.mcpitanlib.api.registry.CompatRegistryLookup; +import net.pitan76.mcpitanlib.api.text.TextComponent; +import net.pitan76.mcpitanlib.api.util.RegistryLookupUtil; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +public class ItemAppendTooltipEvent extends BaseEvent { + public ItemStack stack; + public World world; + public List tooltip; + + public TooltipType type; + public Item.TooltipContext context; + + public ItemAppendTooltipEvent(ItemStack stack, @Nullable World world, List tooltip, TooltipType type, Item.TooltipContext context) { + this.stack = stack; + this.world = world; + this.tooltip = tooltip; + this.type = type; + this.context = context; + } + + public ItemStack getStack() { + return stack; + } + + public World getWorld() { + return world; + } + + public List getTooltip() { + return tooltip; + } + + public Item.TooltipContext getContext() { + return context; + } + + public void addTooltip(Text text) { + tooltip.add(text); + } + + public void addTooltip(List texts) { + tooltip.addAll(texts); + } + + public boolean removeTooltip(Text text) { + return tooltip.remove(text); + } + + public boolean isCreative() { + return type.isCreative(); + } + + public boolean isAdvanced() { + return type.isAdvanced(); + } + + public CompatRegistryLookup getRegistryLookup() { + return RegistryLookupUtil.getRegistryLookup(this); + } + + public void addTooltip(TextComponent textComponent) { + addTooltip(textComponent.getText()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/item/ItemBarColorArgs.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/item/ItemBarColorArgs.java new file mode 100644 index 000000000..aae12a9a0 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/item/ItemBarColorArgs.java @@ -0,0 +1,16 @@ +package net.pitan76.mcpitanlib.api.event.item; + +import net.minecraft.item.ItemStack; + +public class ItemBarColorArgs { + + public ItemStack stack; + + public ItemBarColorArgs(ItemStack stack) { + this.stack = stack; + } + + public ItemStack getStack() { + return stack; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/item/ItemBarStepArgs.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/item/ItemBarStepArgs.java new file mode 100644 index 000000000..86742fa45 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/item/ItemBarStepArgs.java @@ -0,0 +1,16 @@ +package net.pitan76.mcpitanlib.api.event.item; + +import net.minecraft.item.ItemStack; + +public class ItemBarStepArgs { + + public ItemStack stack; + + public ItemBarStepArgs(ItemStack stack) { + this.stack = stack; + } + + public ItemStack getStack() { + return stack; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/item/ItemBarVisibleArgs.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/item/ItemBarVisibleArgs.java new file mode 100644 index 000000000..509bb4634 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/item/ItemBarVisibleArgs.java @@ -0,0 +1,16 @@ +package net.pitan76.mcpitanlib.api.event.item; + +import net.minecraft.item.ItemStack; + +public class ItemBarVisibleArgs { + + public ItemStack stack; + + public ItemBarVisibleArgs(ItemStack stack) { + this.stack = stack; + } + + public ItemStack getStack() { + return stack; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/item/ItemFinishUsingEvent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/item/ItemFinishUsingEvent.java new file mode 100644 index 000000000..27f74b53b --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/item/ItemFinishUsingEvent.java @@ -0,0 +1,34 @@ +package net.pitan76.mcpitanlib.api.event.item; + +import net.minecraft.entity.LivingEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.event.BaseEvent; + +public class ItemFinishUsingEvent extends BaseEvent { + public ItemStack stack; + public World world; + public LivingEntity user; + + public ItemFinishUsingEvent(ItemStack stack, World world, LivingEntity user) { + this.stack = stack; + this.world = world; + this.user = user; + } + + public ItemStack getStack() { + return stack; + } + + public World getWorld() { + return world; + } + + public LivingEntity getUser() { + return user; + } + + public boolean isClient() { + return world.isClient(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/item/ItemUseEvent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/item/ItemUseEvent.java new file mode 100644 index 000000000..da5d8d2f4 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/item/ItemUseEvent.java @@ -0,0 +1,110 @@ +package net.pitan76.mcpitanlib.api.event.item; + +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.util.Hand; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.entity.Player; +import net.pitan76.mcpitanlib.api.event.BaseEvent; +import net.pitan76.mcpitanlib.api.util.CompatActionResult; +import net.pitan76.mcpitanlib.api.util.StackActionResult; +import net.pitan76.mcpitanlib.midohra.block.BlockWrapper; +import net.pitan76.mcpitanlib.midohra.block.entity.BlockEntityWrapper; +import net.pitan76.mcpitanlib.midohra.world.IWorldView; + +public class ItemUseEvent extends BaseEvent { + + public World world; + public Player user; + public Hand hand; + public ItemStack stack; + + public ItemUseEvent(World world, PlayerEntity user, Hand hand) { + this.world = world; + this.user = new Player(user); + this.hand = hand; + this.stack = user.getStackInHand(hand); + } + + public ItemStack getStack() { + return stack; + } + + public net.pitan76.mcpitanlib.midohra.item.ItemStack getMidohraStack() { + return net.pitan76.mcpitanlib.midohra.item.ItemStack.of(stack); + } + + public Hand getHand() { + return hand; + } + + public World getWorld() { + return world; + } + + public Player getUser() { + return user; + } + + public boolean isClient() { + return world.isClient(); + } + + public StackActionResult success(ItemStack stack) { + if (getStack() != stack) + StackActionResult.success(stack); + + return success(); + } + + public StackActionResult success(net.pitan76.mcpitanlib.midohra.item.ItemStack stack) { + return success(stack.toMinecraft()); + } + + public StackActionResult success() { + return StackActionResult.create(CompatActionResult.SUCCESS, stack); + } + + public StackActionResult fail() { + return new StackActionResult(CompatActionResult.FAIL, stack); + } + + public StackActionResult fail(net.pitan76.mcpitanlib.midohra.item.ItemStack stack) { + return StackActionResult.fail(stack.toMinecraft()); + } + + public StackActionResult pass() { + return new StackActionResult(CompatActionResult.PASS, stack); + } + + public StackActionResult pass(net.pitan76.mcpitanlib.midohra.item.ItemStack stack) { + return StackActionResult.pass(stack.toMinecraft()); + } + + public StackActionResult consume(ItemStack stack) { + if (getStack() != stack) + StackActionResult.consume(stack); + + return consume(); + } + + public CompatActionResult consume(net.pitan76.mcpitanlib.midohra.item.ItemStack stack) { + return consume(stack.toMinecraft()); + } + + public StackActionResult consume() { + return StackActionResult.create(CompatActionResult.CONSUME, stack); + } + + public boolean isSneaking() { + return user.isSneaking(); + } + + public net.pitan76.mcpitanlib.midohra.world.World getMidohraWorld() { + return net.pitan76.mcpitanlib.midohra.world.World.of(world); + } + + public IWorldView getWorldView() { + return getMidohraWorld(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/item/ItemUseOnBlockEvent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/item/ItemUseOnBlockEvent.java new file mode 100644 index 000000000..0ac1977e8 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/item/ItemUseOnBlockEvent.java @@ -0,0 +1,140 @@ +package net.pitan76.mcpitanlib.api.event.item; + +import net.minecraft.block.BlockState; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.item.ItemUsageContext; +import net.minecraft.util.Hand; +import net.minecraft.util.hit.BlockHitResult; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import net.minecraft.util.math.Vec3d; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.entity.Player; +import net.pitan76.mcpitanlib.api.event.BaseEvent; +import net.pitan76.mcpitanlib.api.util.CompatActionResult; +import net.pitan76.mcpitanlib.api.util.WorldUtil; +import net.pitan76.mcpitanlib.midohra.block.BlockWrapper; +import net.pitan76.mcpitanlib.midohra.block.entity.BlockEntityWrapper; +import net.pitan76.mcpitanlib.midohra.world.IWorldView; +import org.jetbrains.annotations.Nullable; + +public class ItemUseOnBlockEvent extends BaseEvent { + public Player player; + public Hand hand; + public BlockHitResult hit; + public ItemStack stack; + public World world; + public BlockPos blockPos; + + public ItemUseOnBlockEvent(PlayerEntity player, Hand hand, BlockHitResult hit) { + this(player.getWorld(), player, hand, player.getStackInHand(hand), hit); + } + + public ItemUseOnBlockEvent(World world, @Nullable PlayerEntity player, Hand hand, ItemStack stack, BlockHitResult hit) { + if (player != null) + this.player = new Player(player); + this.hand = hand; + this.hit = hit; + this.stack = stack; + this.world = world; + this.blockPos = hit.getBlockPos(); + } + + public ItemUseOnBlockEvent(Player player, Hand hand, BlockHitResult hit) { + this(player.getWorld(), player.getEntity(), hand, player.getStackInHand(hand), hit); + } + + public ItemUsageContext toIUC() { + return new ItemUsageContext(player.getPlayerEntity(), hand, hit); + } + + public boolean isClient() { + return world.isClient(); + } + + public Player getPlayer() { + return player; + } + + public World getWorld() { + return world; + } + + public BlockHitResult getHit() { + return hit; + } + + public BlockPos getBlockPos() { + return blockPos; + } + + public Hand getHand() { + return hand; + } + + public ItemStack getStack() { + return stack; + } + + public CompatActionResult success() { + return CompatActionResult.SUCCESS; + } + + public CompatActionResult fail() { + return CompatActionResult.FAIL; + } + + public CompatActionResult pass() { + return CompatActionResult.PASS; + } + + public CompatActionResult consume() { + return CompatActionResult.CONSUME; + } + + public BlockEntity getBlockEntity() { + return WorldUtil.getBlockEntity(world, blockPos); + } + + public boolean hasBlockEntity() { + return WorldUtil.hasBlockEntity(world, blockPos); + } + + public BlockState getBlockState() { + return WorldUtil.getBlockState(world, blockPos); + } + + public Vec3d getPos() { + return hit.getPos(); + } + + public Direction getSide() { + return hit.getSide(); + } + + public net.pitan76.mcpitanlib.midohra.world.World getMidohraWorld() { + return net.pitan76.mcpitanlib.midohra.world.World.of(world); + } + + public IWorldView getWorldView() { + return getMidohraWorld(); + } + + public net.pitan76.mcpitanlib.midohra.block.BlockState getMidohraState() { + return net.pitan76.mcpitanlib.midohra.block.BlockState.of(getBlockState()); + } + + public net.pitan76.mcpitanlib.midohra.util.math.BlockPos getMidohraPos() { + return net.pitan76.mcpitanlib.midohra.util.math.BlockPos.of(getBlockPos()); + } + + public BlockWrapper getBlockWrapper() { + return getMidohraState().getBlock(); + } + + public BlockEntityWrapper getBlockEntityWrapper() { + return BlockEntityWrapper.of(getBlockEntity()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/item/ItemUseOnEntityEvent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/item/ItemUseOnEntityEvent.java new file mode 100644 index 000000000..53c2822f4 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/item/ItemUseOnEntityEvent.java @@ -0,0 +1,67 @@ +package net.pitan76.mcpitanlib.api.event.item; + +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.util.Hand; +import net.pitan76.mcpitanlib.api.entity.Player; +import net.pitan76.mcpitanlib.api.event.BaseEvent; +import net.pitan76.mcpitanlib.api.util.CompatActionResult; + +public class ItemUseOnEntityEvent extends BaseEvent { + + public ItemStack stack; + public Player user; + public LivingEntity entity; + public Hand hand; + + public ItemUseOnEntityEvent(ItemStack stack, PlayerEntity user, LivingEntity entity, Hand hand) { + this.stack = stack; + this.user = new Player(user); + this.hand = hand; + this.entity = entity; + } + + public ItemUseOnEntityEvent(ItemStack stack, Player user, LivingEntity entity, Hand hand) { + this.stack = stack; + this.user = user; + this.hand = hand; + this.entity = entity; + } + + public ItemStack getStack() { + return stack; + } + + public Hand getHand() { + return hand; + } + + public Player getUser() { + return user; + } + + public LivingEntity getEntity() { + return entity; + } + + public boolean isClient() { + return user.isClient(); + } + + public CompatActionResult success() { + return CompatActionResult.SUCCESS; + } + + public CompatActionResult fail() { + return CompatActionResult.FAIL; + } + + public CompatActionResult pass() { + return CompatActionResult.PASS; + } + + public CompatActionResult consume() { + return CompatActionResult.CONSUME; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/item/PostHitEvent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/item/PostHitEvent.java new file mode 100644 index 000000000..1f5083152 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/item/PostHitEvent.java @@ -0,0 +1,39 @@ +package net.pitan76.mcpitanlib.api.event.item; + +import net.minecraft.entity.EquipmentSlot; +import net.minecraft.entity.LivingEntity; +import net.minecraft.item.ItemStack; +import net.pitan76.mcpitanlib.api.event.BaseEvent; + +public class PostHitEvent extends BaseEvent { + public ItemStack stack; + public LivingEntity target; + public LivingEntity attacker; + + public PostHitEvent(ItemStack stack, LivingEntity target, LivingEntity attacker) { + this.stack = stack; + this.target = target; + this.attacker = attacker; + } + + public ItemStack getStack() { + return stack; + } + + public LivingEntity getAttacker() { + return attacker; + } + + public LivingEntity getTarget() { + return target; + } + + /** + * Damages the stack in the given slot + * @param amount the amount of damage to deal + * @param slot the slot to damage + */ + public void damageStack(int amount, EquipmentSlot slot) { + stack.damage(amount, attacker, slot); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/item/PostMineEvent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/item/PostMineEvent.java new file mode 100644 index 000000000..e5294cce0 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/item/PostMineEvent.java @@ -0,0 +1,118 @@ +package net.pitan76.mcpitanlib.api.event.item; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.entity.EquipmentSlot; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.entity.Player; +import net.pitan76.mcpitanlib.api.event.BaseEvent; +import net.pitan76.mcpitanlib.api.item.ArmorEquipmentType; +import net.pitan76.mcpitanlib.api.tag.TagKey; +import net.pitan76.mcpitanlib.api.util.BlockUtil; +import net.pitan76.mcpitanlib.api.util.WorldUtil; + +public class PostMineEvent extends BaseEvent { + public ItemStack stack; + public World world; + public BlockState state; + public BlockPos pos; + public LivingEntity miner; + + public PostMineEvent(ItemStack stack, World world, BlockState state, BlockPos pos, LivingEntity miner) { + this.stack = stack; + this.world = world; + this.state = state; + this.pos = pos; + this.miner = miner; + } + + public BlockState getState() { + return state; + } + + public BlockPos getPos() { + return pos; + } + + public World getWorld() { + return world; + } + + public ItemStack getStack() { + return stack; + } + + public LivingEntity getMiner() { + return miner; + } + + public BlockEntity getBlockEntity() { + return WorldUtil.getBlockEntity(world, pos); + } + + public boolean isClient() { + return world.isClient; + } + + public boolean stateIsIn(TagKey tagKey) { + return BlockUtil.isIn(state.getBlock(), tagKey); + } + + public boolean stateIsOf(Block block) { + return BlockUtil.isEqual(state.getBlock(), block); + } + + /** + * Damages the stack in the given slot + * @param amount the amount of damage to deal + * @param slot the slot to damage + */ + public void damageStack(int amount, EquipmentSlot slot) { + stack.damage(amount, miner, slot); + } + + /** + * Damages the stack in the given slot + * @param amount the amount of damage to deal + * @param type the type of armor equipment + */ + public void damageStack(int amount, ArmorEquipmentType type) { + stack.damage(amount, miner, type.getSlot()); + } + + /** + * Damages the stack in the main hand + * @param amount the amount of damage to deal + */ + public void damageStack(int amount) { + stack.damage(amount, miner, EquipmentSlot.MAINHAND); + } + + public boolean isPlayer() { + return miner instanceof PlayerEntity; + } + + public Player getPlayer() { + if (isPlayer()) + return new Player((PlayerEntity) miner); + + return null; + } + + public boolean isCreative() { + return isPlayer() && getPlayer().isCreative(); + } + + public boolean isSneaking() { + return miner.isSneaking(); + } + + public ItemStack getMainHandStack() { + return miner.getMainHandStack(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/nbt/NbtRWArgs.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/nbt/NbtRWArgs.java new file mode 100644 index 000000000..598e5fa03 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/nbt/NbtRWArgs.java @@ -0,0 +1,60 @@ +package net.pitan76.mcpitanlib.api.event.nbt; + +import net.minecraft.nbt.NbtCompound; +import net.minecraft.registry.RegistryWrapper; +import net.pitan76.mcpitanlib.api.registry.CompatRegistryLookup; + +public class NbtRWArgs { + public NbtCompound nbt; + public CompatRegistryLookup registryLookup; + + public NbtRWArgs(NbtCompound nbt, CompatRegistryLookup registryLookup) { + this.nbt = nbt; + this.registryLookup = registryLookup; + } + + @Deprecated + public NbtRWArgs(NbtCompound nbt, RegistryWrapper.WrapperLookup wrapperLookup) { + this(nbt, new CompatRegistryLookup(wrapperLookup)); + } + + public NbtRWArgs(NbtCompound nbt) { + this(nbt, (CompatRegistryLookup) null); + } + + public NbtCompound getNbt() { + return nbt; + } + + public CompatRegistryLookup getRegistryLookup() { + return registryLookup; + } + + public boolean hasRegistryLookup() { + return registryLookup != null; + } + + @Deprecated + public RegistryWrapper.WrapperLookup getWrapperLookup() { + if (registryLookup == null) + registryLookup = new CompatRegistryLookup(); + + return registryLookup.getRegistryLookup(); + } + + public boolean isNbtEmpty() { + return nbt != null && !nbt.isEmpty(); + } + + public boolean isViewEmpty() { + return false; + } + + public boolean isEmpty() { + return isNbtEmpty() || isViewEmpty(); + } + + public NbtRWArgs copy() { + return new NbtRWArgs(nbt.copy(), registryLookup); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/nbt/ReadNbtArgs.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/nbt/ReadNbtArgs.java new file mode 100644 index 000000000..b4e77f14f --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/nbt/ReadNbtArgs.java @@ -0,0 +1,31 @@ +package net.pitan76.mcpitanlib.api.event.nbt; + +import net.minecraft.nbt.NbtCompound; +import net.minecraft.registry.RegistryWrapper; +import net.pitan76.mcpitanlib.api.registry.CompatRegistryLookup; + +public class ReadNbtArgs extends NbtRWArgs { + + @Deprecated + public ReadNbtArgs(NbtCompound nbt, RegistryWrapper.WrapperLookup wrapperLookup) { + super(nbt, wrapperLookup); + } + + public ReadNbtArgs(NbtCompound nbt) { + super(nbt); + } + + public ReadNbtArgs(NbtCompound nbt, CompatRegistryLookup registryLookup) { + super(nbt, registryLookup); + } + + @Override + public boolean isViewEmpty() { + return false; + } + + @Override + public NbtRWArgs copy() { + return new ReadNbtArgs(nbt.copy(), registryLookup); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/nbt/WriteNbtArgs.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/nbt/WriteNbtArgs.java new file mode 100644 index 000000000..ca7bf3be8 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/nbt/WriteNbtArgs.java @@ -0,0 +1,31 @@ +package net.pitan76.mcpitanlib.api.event.nbt; + +import net.minecraft.nbt.NbtCompound; +import net.minecraft.registry.RegistryWrapper; +import net.pitan76.mcpitanlib.api.registry.CompatRegistryLookup; + +public class WriteNbtArgs extends NbtRWArgs { + + @Deprecated + public WriteNbtArgs(NbtCompound nbt, RegistryWrapper.WrapperLookup wrapperLookup) { + super(nbt, wrapperLookup); + } + + public WriteNbtArgs(NbtCompound nbt, CompatRegistryLookup registryLookup) { + super(nbt, registryLookup); + } + + public WriteNbtArgs(NbtCompound nbt) { + super(nbt); + } + + @Override + public boolean isViewEmpty() { + return false; + } + + @Override + public NbtRWArgs copy() { + return new WriteNbtArgs(nbt.copy(), registryLookup); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/result/EventResult.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/result/EventResult.java new file mode 100644 index 000000000..67dcae814 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/result/EventResult.java @@ -0,0 +1,48 @@ +package net.pitan76.mcpitanlib.api.event.result; + +import net.minecraft.util.ActionResult; +import net.pitan76.mcpitanlib.api.util.CompatActionResult; + +public class EventResult { + + protected final dev.architectury.event.EventResult result; + + private static final EventResult TRUE = new EventResult(dev.architectury.event.EventResult.interruptTrue()); + private static final EventResult STOP = new EventResult(dev.architectury.event.EventResult.interruptDefault()); + private static final EventResult PASS = new EventResult(dev.architectury.event.EventResult.pass()); + private static final EventResult FALSE = new EventResult(dev.architectury.event.EventResult.interruptFalse()); + + + protected EventResult(dev.architectury.event.EventResult result) { + this.result = result; + } + + public static EventResult success() { + return TRUE; + } + + public static EventResult stop() { + return STOP; + } + + public static EventResult pass() { + return PASS; + } + + public static EventResult fail() { + return FALSE; + } + + @Deprecated + public dev.architectury.event.EventResult getResult() { + return result; + } + + public ActionResult toActionResult() { + return result.asMinecraft(); + } + + public CompatActionResult toCompatActionResult() { + return CompatActionResult.create(toActionResult()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/result/TypedEventResult.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/result/TypedEventResult.java new file mode 100644 index 000000000..78487eedb --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/result/TypedEventResult.java @@ -0,0 +1,61 @@ +package net.pitan76.mcpitanlib.api.event.result; + +import dev.architectury.event.CompoundEventResult; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ActionResult; +import net.pitan76.mcpitanlib.api.util.CompatActionResult; +import net.pitan76.mcpitanlib.api.util.StackActionResult; + +public class TypedEventResult { + protected final dev.architectury.event.CompoundEventResult result; + + protected TypedEventResult(dev.architectury.event.CompoundEventResult result) { + this.result = result; + } + + public static TypedEventResult success(T value) { + return new TypedEventResult<>(CompoundEventResult.interruptTrue(value)); + } + + public static TypedEventResult stop(T value) { + return new TypedEventResult<>(CompoundEventResult.interruptDefault(value)); + } + + public static TypedEventResult pass() { + return new TypedEventResult<>(CompoundEventResult.pass()); + } + + public static TypedEventResult fail(T value) { + return new TypedEventResult<>(CompoundEventResult.interruptFalse(value)); + } + + @Deprecated + public dev.architectury.event.CompoundEventResult getResult() { + return result; + } + + public ActionResult toActionResult() { + return result.result().asMinecraft(); + } + + public CompatActionResult toCompatActionResult() { + return CompatActionResult.of(result.result().asMinecraft()); + } + + public CompatActionResult toCompatActionResult(ItemStack stack) { + if (result.object() != stack) + return toCompatActionResult(); + + if (toActionResult() == ActionResult.SUCCESS) + return StackActionResult.success(stack); + + if (toActionResult() == ActionResult.CONSUME) + return StackActionResult.consume(stack); + + return toCompatActionResult(); + } + + public CompatActionResult toCompatActionResult(net.pitan76.mcpitanlib.midohra.item.ItemStack stack) { + return toCompatActionResult(stack.toMinecraft()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/tile/TileTickEvent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/tile/TileTickEvent.java new file mode 100644 index 000000000..4dea5f138 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/tile/TileTickEvent.java @@ -0,0 +1,92 @@ +package net.pitan76.mcpitanlib.api.event.tile; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.midohra.block.BlockWrapper; +import net.pitan76.mcpitanlib.midohra.block.entity.BlockEntityWrapper; +import net.pitan76.mcpitanlib.midohra.holder.BlockStatePropertyHolder; +import net.pitan76.mcpitanlib.midohra.world.IWorldView; + +public class TileTickEvent implements BlockStatePropertyHolder { + public World world; + public BlockPos pos; + public BlockState state; + public T blockEntity; + + public TileTickEvent(World world, BlockPos pos, BlockState state, T blockEntity) { + this.world = world; + this.pos = pos; + this.state = state; + this.blockEntity = blockEntity; + } + + public boolean isClient() { + return world.isClient(); + } + + public boolean isServer() { + return !isClient(); + } + + public boolean hasWorld() { + return world != null; + } + + public World getWorld() { + return world; + } + + public BlockPos getPos() { + return pos; + } + + public BlockState getState() { + if (state == null) + state = getWorldView().getBlockState(getPos()); + + return state; + } + + public T getBlockEntity() { + return blockEntity; + } + + public net.pitan76.mcpitanlib.midohra.world.World getMidohraWorld() { + return net.pitan76.mcpitanlib.midohra.world.World.of(getWorld()); + } + + public net.pitan76.mcpitanlib.midohra.util.math.BlockPos getMidohraPos() { + return net.pitan76.mcpitanlib.midohra.util.math.BlockPos.of(getPos()); + } + + public net.pitan76.mcpitanlib.midohra.block.BlockState getMidohraState() { + if (state == null) + return getWorldView().getBlockState(getMidohraPos()); + + return net.pitan76.mcpitanlib.midohra.block.BlockState.of(getState()); + } + + public BlockEntityWrapper getBlockEntityWrapper() { + return BlockEntityWrapper.of(getBlockEntity()); + } + + public IWorldView getWorldView() { + return getMidohraWorld(); + } + + @Override + public net.pitan76.mcpitanlib.midohra.block.BlockState getBlockState() { + return getMidohraState(); + } + + public Block getBlock() { + return getState().getBlock(); + } + + public BlockWrapper getBlockWrapper() { + return BlockWrapper.of(getBlock()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/v0/AttackEntityEventRegistry.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/v0/AttackEntityEventRegistry.java new file mode 100644 index 000000000..466ac1f70 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/v0/AttackEntityEventRegistry.java @@ -0,0 +1,26 @@ +package net.pitan76.mcpitanlib.api.event.v0; + +import dev.architectury.event.EventResult; +import dev.architectury.event.events.common.PlayerEvent; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.util.Hand; +import net.minecraft.util.hit.EntityHitResult; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.entity.Player; +import org.jetbrains.annotations.Nullable; + +@Deprecated +public class AttackEntityEventRegistry { + public static void register(AttackEntity attackEntity) { + PlayerEvent.ATTACK_ENTITY.register(attackEntity::attack); + } + + public interface AttackEntity { + default EventResult attack(PlayerEntity player, World level, Entity target, Hand hand, @Nullable EntityHitResult result) { + return attack(new Player(player), level, target, hand, result); + } + + EventResult attack(Player player, World level, Entity target, Hand hand, @Nullable EntityHitResult result); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/v0/ClientTickEventRegistry.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/v0/ClientTickEventRegistry.java new file mode 100644 index 000000000..4c4efbe16 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/v0/ClientTickEventRegistry.java @@ -0,0 +1,35 @@ +package net.pitan76.mcpitanlib.api.event.v0; + +import dev.architectury.event.events.client.ClientTickEvent; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.world.ClientWorld; + +public class ClientTickEventRegistry { + public static void registerPost(Client client) { + ClientTickEvent.CLIENT_POST.register(client::tick); + } + + public static void registerPre(Client client) { + ClientTickEvent.CLIENT_PRE.register(client::tick); + } + + public static void registerLevelPost(ClientLevel world) { + ClientTickEvent.CLIENT_LEVEL_POST.register(world::tick); + } + + public static void registerLevelPre(ClientLevel world) { + ClientTickEvent.CLIENT_LEVEL_PRE.register(world::tick); + } + + @Environment(EnvType.CLIENT) + public interface Client { + void tick(MinecraftClient instance); + } + + @Environment(EnvType.CLIENT) + public interface ClientLevel { + void tick(ClientWorld instance); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/v0/EventRegistry.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/v0/EventRegistry.java new file mode 100644 index 000000000..17b2fa79d --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/v0/EventRegistry.java @@ -0,0 +1,87 @@ +package net.pitan76.mcpitanlib.api.event.v0; + +import dev.architectury.event.events.common.LifecycleEvent; +import net.minecraft.item.ItemStack; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.event.v0.event.ItemStackActionEvent; +import net.pitan76.mcpitanlib.api.event.v0.event.ServerConnectionEvent; + +public class EventRegistry { + + public static class ServerConnection { + // Architectury: PlayerEvent + public static void join(PlayerJoin state) { + ServerConnectionEvent.join(state); + } + + public static void quit(PlayerQuit state) { + ServerConnectionEvent.quit(state); + } + + public interface PlayerJoin { + void join(ServerPlayerEntity player); + } + + public interface PlayerQuit { + void quit(ServerPlayerEntity player); + } + } + + public static class ItemStackAction { + public static void damage(ItemStackDamageState state) { + ItemStackActionEvent.register(state); + } + + public interface ItemStackDamageState { + void onDamage(ItemStack stack); + } + } + + public static class ServerLifecycle { + // Architectury: LifecycleEvent + public static void serverStarted(ServerState state) { + LifecycleEvent.SERVER_STARTED.register(state::stateChanged); + } + + public static void serverStarting(ServerState state) { + LifecycleEvent.SERVER_STARTING.register(state::stateChanged); + } + + public static void serverStopped(ServerState state) { + LifecycleEvent.SERVER_STOPPED.register(state::stateChanged); + } + + public static void serverStopping(ServerState state) { + LifecycleEvent.SERVER_STOPPING.register(state::stateChanged); + } + + public static void serverWorldLoad(ServerWorldState state) { + LifecycleEvent.SERVER_LEVEL_LOAD.register(state::act); + } + + public static void serverWorldSave(ServerWorldState state) { + LifecycleEvent.SERVER_LEVEL_SAVE.register(state::act); + } + + public static void serverWorldUnload(ServerWorldState state) { + LifecycleEvent.SERVER_LEVEL_UNLOAD.register(state::act); + } + + public interface ServerState extends InstanceState { + } + + public interface InstanceState { + void stateChanged(T instance); + } + + public interface WorldState { + void act(T world); + } + + public interface ServerWorldState extends WorldState { + } + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/v0/InteractionEventRegistry.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/v0/InteractionEventRegistry.java new file mode 100644 index 000000000..d31cf54c5 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/v0/InteractionEventRegistry.java @@ -0,0 +1,84 @@ +package net.pitan76.mcpitanlib.api.event.v0; + +import dev.architectury.event.CompoundEventResult; +import dev.architectury.event.events.common.InteractionEvent; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.util.Hand; +import net.pitan76.mcpitanlib.api.entity.Player; +import net.pitan76.mcpitanlib.api.event.result.EventResult; +import net.pitan76.mcpitanlib.api.event.result.TypedEventResult; +import net.pitan76.mcpitanlib.api.event.v0.event.ClickBlockEvent; + +public class InteractionEventRegistry { + @SuppressWarnings("deprecation") + public static void registerRightClickBlock(RightClickBlock rightClickBlock) { + InteractionEvent.RIGHT_CLICK_BLOCK.register((player, hand, pos, direction) -> rightClickBlock.click(new ClickBlockEvent(player, hand, pos, direction)).getResult()); + } + + @SuppressWarnings("deprecation") + public static void registerLeftClickBlock(LeftClickBlock leftClickBlock) { + InteractionEvent.LEFT_CLICK_BLOCK.register((player, hand, pos, direction) -> leftClickBlock.click(new ClickBlockEvent(player, hand, pos, direction)).getResult()); + } + + public static void registerRightClickItem(RightClickItem rightClickItem) { + InteractionEvent.RIGHT_CLICK_ITEM.register(rightClickItem::click); + } + + public static void registerClientLeftClickAir(ClientLeftClickAir clientLeftClickAir) { + InteractionEvent.CLIENT_LEFT_CLICK_AIR.register(clientLeftClickAir::click); + } + + public static void registerClientRightClickAir(ClientRightClickAir clientRightClickAir) { + InteractionEvent.CLIENT_RIGHT_CLICK_AIR.register(clientRightClickAir::click); + } + + public static void registerInteractEntity(InteractEntity interactEntity) { + InteractionEvent.INTERACT_ENTITY.register(interactEntity::interact); + } + + // ---- + + public interface LeftClickBlock { + EventResult click(ClickBlockEvent event); + } + + public interface RightClickBlock { + EventResult click(ClickBlockEvent event); + } + + public interface RightClickItem { + @SuppressWarnings("deprecation") + default CompoundEventResult click(PlayerEntity var1, Hand var2) { + return click(new Player(var1), var2).getResult(); + } + + TypedEventResult click(Player player, Hand hand); + } + + public interface ClientLeftClickAir { + default void click(PlayerEntity var1, Hand var2) { + click(new Player(var1), var2); + } + + void click(Player player, Hand hand); + } + + public interface ClientRightClickAir { + default void click(PlayerEntity var1, Hand var2) { + click(new Player(var1), var2); + } + + void click(Player player, Hand hand); + } + + public interface InteractEntity { + @SuppressWarnings("deprecation") + default dev.architectury.event.EventResult interact(PlayerEntity var1, Entity var2, Hand var3) { + return interact(new Player(var1), var2, var3).getResult(); + } + + EventResult interact(Player player, Entity entity, Hand hand); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/v0/LivingHurtEventRegistry.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/v0/LivingHurtEventRegistry.java new file mode 100644 index 000000000..3777e195e --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/v0/LivingHurtEventRegistry.java @@ -0,0 +1,21 @@ +package net.pitan76.mcpitanlib.api.event.v0; + +import dev.architectury.event.EventResult; +import dev.architectury.event.events.common.EntityEvent; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.damage.DamageSource; +import net.pitan76.mcpitanlib.api.event.v0.event.LivingHurtEvent; + +public class LivingHurtEventRegistry { + public static void register(LivingHurt livingHurt) { + EntityEvent.LIVING_HURT.register(livingHurt::hurt); + } + + public interface LivingHurt { + default EventResult hurt(LivingEntity var1, DamageSource var2, float var3) { + return hurt(new LivingHurtEvent(var1, var2, var3)); + } + + EventResult hurt(LivingHurtEvent event); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/v0/event/ClickBlockEvent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/v0/event/ClickBlockEvent.java new file mode 100644 index 000000000..231235154 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/v0/event/ClickBlockEvent.java @@ -0,0 +1,78 @@ +package net.pitan76.mcpitanlib.api.event.v0.event; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.util.Hand; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.entity.Player; +import net.pitan76.mcpitanlib.api.util.BlockStateUtil; +import net.pitan76.mcpitanlib.api.util.WorldUtil; + +public class ClickBlockEvent { + public Player player; + public Hand hand; + public BlockPos pos; + public Direction direction; + + public ClickBlockEvent(Player player, Hand hand, BlockPos pos, Direction direction) { + this.player = player; + this.hand = hand; + this.pos = pos; + this.direction = direction; + } + + public ClickBlockEvent(PlayerEntity player, Hand hand, BlockPos pos, Direction direction) { + this.player = new Player(player); + this.hand = hand; + this.pos = pos; + this.direction = direction; + } + + public Player getPlayer() { + return player; + } + + public Hand getHand() { + return hand; + } + + public BlockPos getPos() { + return pos; + } + + public Direction getDirection() { + return direction; + } + + public boolean isExistPlayer() { + return player.getEntity() != null; + } + + public ItemStack getStackInHand() { + return player.getStackInHand(hand); + } + + public boolean isEmptyStackInHand() { + return getStackInHand().isEmpty(); + } + + public World getWorld() { + return player.getWorld(); + } + + public BlockState getBlockState() { + return WorldUtil.getBlockState(getWorld(), getPos()); + } + + public Block getBlock() { + return BlockStateUtil.getBlock(getBlockState()); + } + + + + +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/v0/event/ItemStackActionEvent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/v0/event/ItemStackActionEvent.java new file mode 100644 index 000000000..f8872ead7 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/v0/event/ItemStackActionEvent.java @@ -0,0 +1,34 @@ +package net.pitan76.mcpitanlib.api.event.v0.event; + +import net.minecraft.item.ItemStack; +import net.pitan76.mcpitanlib.api.event.v0.EventRegistry; + +import java.util.ArrayList; +import java.util.List; + +public class ItemStackActionEvent { + + public static Boolean returnValue = null; + + public static void setReturnValue(boolean setReturnValue) { + ItemStackActionEvent.returnValue = setReturnValue; + } + + private static final List states = new ArrayList<>(); + + public static void register(EventRegistry.ItemStackAction.ItemStackDamageState state) { + states.add(state); + } + + public static void call(ItemStack stack) { + if (states.isEmpty()) return; + for (EventRegistry.ItemStackAction.ItemStackDamageState state : states) { + state.onDamage(stack); + } + } + + public static void unregister(EventRegistry.ItemStackAction.ItemStackDamageState state) { + states.remove(state); + } + +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/v0/event/LivingHurtEvent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/v0/event/LivingHurtEvent.java new file mode 100644 index 000000000..903d4c658 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/v0/event/LivingHurtEvent.java @@ -0,0 +1,83 @@ +package net.pitan76.mcpitanlib.api.event.v0.event; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.damage.DamageSource; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.entity.Player; + +public class LivingHurtEvent { + public LivingEntity entity; + public DamageSource damageSource; + public float damageAmount; + + public LivingHurtEvent(LivingEntity entity, DamageSource damageSource, float damageAmount) { + this.entity = entity; + this.damageSource = damageSource; + this.damageAmount = damageAmount; + } + + public LivingEntity getEntity() { + return entity; + } + + public DamageSource getDamageSource() { + return damageSource; + } + + public float getDamageAmount() { + return damageAmount; + } + + public Entity getAttacker() { + return damageSource.getAttacker(); + } + + public Entity getSource() { + return damageSource.getSource(); + } + + public boolean isDirect() { + return damageSource.isDirect(); + } + + public boolean isPlayerAttacker() { + return getAttacker() instanceof PlayerEntity; + } + + public PlayerEntity getPlayerEntityAttacker() { + return (PlayerEntity) getAttacker(); + } + + public Player getPlayerAttacker() { + return new Player(getPlayerEntityAttacker()); + } + + public World getWorld() { + return entity.getWorld(); + } + + public boolean isClient() { + return getWorld().isClient(); + } + + public ItemStack getWeaponStack() { + return getAttacker().getWeaponStack(); + } + + public Item getWeaponItem() { + return getWeaponStack().getItem(); + } + + public boolean isWeaponEmpty() { + return getWeaponStack().isEmpty(); + } + + public boolean isWeaponItemEqual(Item item) { + if (isWeaponEmpty()) return false; + return getWeaponItem() == item; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/v0/event/RecipeManagerEvent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/v0/event/RecipeManagerEvent.java new file mode 100644 index 000000000..e79b9e791 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/v0/event/RecipeManagerEvent.java @@ -0,0 +1,86 @@ +package net.pitan76.mcpitanlib.api.event.v0.event; + +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableMultimap; +import com.google.gson.JsonElement; +import net.minecraft.recipe.Recipe; +import net.minecraft.recipe.RecipeEntry; +import net.minecraft.recipe.RecipeType; +import net.minecraft.resource.ResourceManager; +import net.minecraft.util.Identifier; +import net.minecraft.util.profiler.Profiler; +import net.pitan76.mcpitanlib.api.recipe.CompatibleRecipeEntry; +import net.pitan76.mcpitanlib.api.recipe.v2.CompatRecipeEntry; +import net.pitan76.mcpitanlib.api.recipe.v3.CompatRecipe; + +import java.util.Map; + +public class RecipeManagerEvent { + public Map jsonMap; + public ResourceManager resourceManager; + public Profiler profiler; + + @Deprecated + public ImmutableMap.Builder> recipesById; + + @Deprecated + public ImmutableMultimap.Builder, RecipeEntry> recipesByType; + + public RecipeManagerEvent(Map map, ResourceManager resourceManager, Profiler profiler, ImmutableMap.Builder> recipesById, ImmutableMultimap.Builder, RecipeEntry> recipesByType) { + this.jsonMap = map; + this.resourceManager = resourceManager; + this.profiler = profiler; + this.recipesById = recipesById; + this.recipesByType = recipesByType; + } + + public Map getJsonMap() { + return jsonMap; + } + + @Deprecated + public ImmutableMap.Builder> getRecipesById() { + return recipesById; + } + + @Deprecated + public ImmutableMultimap.Builder, RecipeEntry> getRecipesByType() { + return recipesByType; + } + + public Profiler getProfiler() { + return profiler; + } + + public ResourceManager getResourceManager() { + return resourceManager; + } + + public net.pitan76.mcpitanlib.midohra.resource.ResourceManager getResourceManagerM() { + return net.pitan76.mcpitanlib.midohra.resource.ResourceManager.of(resourceManager); + } + + public void putCompatibleRecipeEntry(Identifier id, CompatibleRecipeEntry entry) { + putCompatibleRecipeEntry(entry); + } + + public void putCompatibleRecipeEntry(CompatibleRecipeEntry entry) { + recipesById.put(entry.getId(), entry.getRecipeEntry()); + recipesByType.put(entry.getType(), entry.getRecipeEntry()); + } + + public > void putCompatibleRecipeEntry(CompatRecipeEntry entry) { + recipesById.put(entry.getId(), entry.getRecipeEntry()); + recipesByType.put(entry.getType(), entry.getRecipeEntry()); + } + + public void putRecipeEntry(net.pitan76.mcpitanlib.midohra.recipe.entry.RecipeEntry entry) { + recipesById.put(entry.getId().toMinecraft(), entry.toMinecraft()); + recipesByType.put(entry.getRawRecipeType(), entry.toMinecraft()); + } + + public void putRecipe(CompatRecipe recipe) { + recipesById.put(recipe.getId(), recipe.getRecipeEntry().getRecipeEntry()); + recipesByType.put(recipe.getType(), recipe.getRecipeEntry().getRecipeEntry()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/v0/event/ServerConnectionEvent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/v0/event/ServerConnectionEvent.java new file mode 100644 index 000000000..ec21cc0e7 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/v0/event/ServerConnectionEvent.java @@ -0,0 +1,15 @@ +package net.pitan76.mcpitanlib.api.event.v0.event; + +import dev.architectury.event.events.common.PlayerEvent; +import net.pitan76.mcpitanlib.api.event.v0.EventRegistry; + +public class ServerConnectionEvent { + // Architectury: PlayerEvent + public static void join(EventRegistry.ServerConnection.PlayerJoin state) { + PlayerEvent.PLAYER_JOIN.register(state::join); + } + + public static void quit(EventRegistry.ServerConnection.PlayerQuit state) { + PlayerEvent.PLAYER_QUIT.register(state::quit); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/v1/AttackEntityEventRegistry.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/v1/AttackEntityEventRegistry.java new file mode 100644 index 000000000..894a89cd8 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/v1/AttackEntityEventRegistry.java @@ -0,0 +1,26 @@ +package net.pitan76.mcpitanlib.api.event.v1; + +import dev.architectury.event.EventResult; +import dev.architectury.event.events.common.PlayerEvent; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.util.Hand; +import net.minecraft.util.hit.EntityHitResult; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.event.v1.event.AttackEntityEvent; +import net.pitan76.mcpitanlib.api.util.CompatActionResult; +import org.jetbrains.annotations.Nullable; + +public class AttackEntityEventRegistry { + public static void register(AttackEntity attackEntity) { + PlayerEvent.ATTACK_ENTITY.register(attackEntity::attack); + } + + public interface AttackEntity { + default EventResult attack(PlayerEntity player, World level, Entity target, Hand hand, @Nullable EntityHitResult result) { + return attack(new AttackEntityEvent(player, level, target, hand, result)).toEventResult().getResult(); + } + + CompatActionResult attack(AttackEntityEvent event); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/v1/BlockEventRegistry.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/v1/BlockEventRegistry.java new file mode 100644 index 000000000..cfc8397de --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/v1/BlockEventRegistry.java @@ -0,0 +1,26 @@ +package net.pitan76.mcpitanlib.api.event.v1; + +import net.pitan76.mcpitanlib.api.event.v1.listener.BlockBreakTask; +import net.pitan76.mcpitanlib.api.event.v1.listener.BlockPlacedTask; + +@Deprecated +public class BlockEventRegistry { + @Deprecated + public static void register(BlockPlacedTask listener) { + net.pitan76.mcpitanlib.api.event.v2.BlockEventRegistry.ON_PLACED.register(listener); + } + + @Deprecated + public static void register(BlockBreakTask listener) { + net.pitan76.mcpitanlib.api.event.v2.BlockEventRegistry.ON_BREAK.register(listener); + } + + public static void registerPlacedListener(BlockPlacedTask listener) { + net.pitan76.mcpitanlib.api.event.v2.BlockEventRegistry.ON_PLACED.register(listener); + + } + + public static void registerBreakListener(BlockBreakTask listener) { + net.pitan76.mcpitanlib.api.event.v2.BlockEventRegistry.ON_BREAK.register(listener); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/v1/LivingHurtEventRegistry.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/v1/LivingHurtEventRegistry.java new file mode 100644 index 000000000..a95a7e9be --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/v1/LivingHurtEventRegistry.java @@ -0,0 +1,23 @@ +package net.pitan76.mcpitanlib.api.event.v1; + +import dev.architectury.event.EventResult; +import dev.architectury.event.events.common.EntityEvent; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.damage.DamageSource; +import net.pitan76.mcpitanlib.api.event.v0.event.LivingHurtEvent; + +public class LivingHurtEventRegistry { + public static void register(LivingHurt livingHurt) { + EntityEvent.LIVING_HURT.register(livingHurt::hurt); + } + + public interface LivingHurt { + + @SuppressWarnings("deprecation") + default EventResult hurt(LivingEntity var1, DamageSource var2, float var3) { + return hurt(new LivingHurtEvent(var1, var2, var3)).getResult(); + } + + net.pitan76.mcpitanlib.api.event.result.EventResult hurt(LivingHurtEvent event); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/v1/RecipeManagerRegistry.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/v1/RecipeManagerRegistry.java new file mode 100644 index 000000000..840b0f04e --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/v1/RecipeManagerRegistry.java @@ -0,0 +1,19 @@ +package net.pitan76.mcpitanlib.api.event.v1; + +import net.pitan76.mcpitanlib.api.event.v0.event.RecipeManagerEvent; + +import java.util.ArrayList; +import java.util.List; + +public class RecipeManagerRegistry { + public static List managers = new ArrayList<>(); + + public static void register(CustomRecipeManager manager) { + managers.add(manager); + } + + @FunctionalInterface + public interface CustomRecipeManager { + void apply(RecipeManagerEvent event); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/v1/event/AttackEntityEvent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/v1/event/AttackEntityEvent.java new file mode 100644 index 000000000..4748c9ca4 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/v1/event/AttackEntityEvent.java @@ -0,0 +1,73 @@ +package net.pitan76.mcpitanlib.api.event.v1.event; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.Hand; +import net.minecraft.util.hit.EntityHitResult; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.entity.Player; +import net.pitan76.mcpitanlib.midohra.item.ItemWrapper; +import org.jetbrains.annotations.Nullable; + +public class AttackEntityEvent { + + public Player player; + public World world; + public Entity target; + public Hand hand; + public EntityHitResult result; + + public AttackEntityEvent(PlayerEntity player, World level, Entity target, Hand hand, @Nullable EntityHitResult result) { + this(new Player(player), level, target, hand, result); + } + + public AttackEntityEvent(Player player, World level, Entity target, Hand hand, @Nullable EntityHitResult result) { + this.player = player; + this.world = level; + this.target = target; + this.hand = hand; + this.result = result; + } + + public Player getPlayer() { + return player; + } + + public World getWorld() { + return world; + } + + public Entity getTarget() { + return target; + } + + public EntityHitResult getResult() { + return result; + } + + public Hand getHand() { + return hand; + } + + public ItemStack getStackInPlayer() { + return player.getStackInHand(hand); + } + + public Item getItemInPlayer() { + return getStackInPlayer().getItem(); + } + + public net.pitan76.mcpitanlib.midohra.world.World getWorldAsMidohra() { + return net.pitan76.mcpitanlib.midohra.world.World.of(world); + } + + public net.pitan76.mcpitanlib.midohra.item.ItemStack getStackInPlayerAsMidohra() { + return net.pitan76.mcpitanlib.midohra.item.ItemStack.of(getStackInPlayer()); + } + + public ItemWrapper getItemWrapperInPlayer() { + return ItemWrapper.of(getItemInPlayer()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/v1/listener/BlockBreakTask.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/v1/listener/BlockBreakTask.java new file mode 100644 index 000000000..ae0300d00 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/v1/listener/BlockBreakTask.java @@ -0,0 +1,9 @@ +package net.pitan76.mcpitanlib.api.event.v1.listener; + +import net.pitan76.mcpitanlib.api.event.block.BlockBreakEvent; +import net.pitan76.mcpitanlib.api.event.block.result.BlockBreakResult; + +@FunctionalInterface +public interface BlockBreakTask { + BlockBreakResult onBreak(BlockBreakEvent event); +} \ No newline at end of file diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/v1/listener/BlockPlacedTask.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/v1/listener/BlockPlacedTask.java new file mode 100644 index 000000000..eca682318 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/v1/listener/BlockPlacedTask.java @@ -0,0 +1,8 @@ +package net.pitan76.mcpitanlib.api.event.v1.listener; + +import net.pitan76.mcpitanlib.api.event.block.BlockPlacedEvent; + +@FunctionalInterface +public interface BlockPlacedTask { + void onPlaced(BlockPlacedEvent event); +} \ No newline at end of file diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/v2/AbstractEvent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/v2/AbstractEvent.java new file mode 100644 index 000000000..4ad62500e --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/v2/AbstractEvent.java @@ -0,0 +1,18 @@ +package net.pitan76.mcpitanlib.api.event.v2; + +import java.util.List; + +public abstract class AbstractEvent { + + public abstract void register(T listener); + + public abstract void unregister(T listener); + + public abstract T getListener(int index); + + public abstract List getListenersAsList(); + + public int getListenerCount() { + return getListenersAsList().size(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/v2/BlockEventRegistry.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/v2/BlockEventRegistry.java new file mode 100644 index 000000000..50f50a605 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/v2/BlockEventRegistry.java @@ -0,0 +1,25 @@ +package net.pitan76.mcpitanlib.api.event.v2; + +import net.pitan76.mcpitanlib.api.event.v1.listener.BlockBreakTask; +import net.pitan76.mcpitanlib.api.event.v1.listener.BlockPlacedTask; + +public class BlockEventRegistry { + /** + * Event that is called when a block is placed + *

{@code
+     * BlockEventRegistry.ON_PLACED.register((event) -> {
+     *     // Do something
+     * }
+ */ + public static OrderedEvent ON_PLACED = new OrderedEvent<>(); + + /** + * Event that is called when a block is broken + *
{@code
+     * BlockEventRegistry.ON_BREAK.register((event) -> {
+     *     // Do something
+     *     return new BlockBreakResult(event.state);
+     * }
+ */ + public static OrderedEvent ON_BREAK = new OrderedEvent<>(); +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/v2/ItemEventRegistry.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/v2/ItemEventRegistry.java new file mode 100644 index 000000000..822804845 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/v2/ItemEventRegistry.java @@ -0,0 +1,7 @@ +package net.pitan76.mcpitanlib.api.event.v2; + +import net.pitan76.mcpitanlib.api.event.v2.listener.InventoryTickTask; + +public class ItemEventRegistry { + public static OrderedEvent INVENTORY_TICK = new OrderedEvent<>(); +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/v2/OrderedEvent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/v2/OrderedEvent.java new file mode 100644 index 000000000..019d5f5a7 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/v2/OrderedEvent.java @@ -0,0 +1,167 @@ +package net.pitan76.mcpitanlib.api.event.v2; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class OrderedEvent extends AbstractEvent { + + public volatile Map listeners = new HashMap<>(); + public volatile int maxPriority = 0; + + /** + * Check if the event has any listeners + * @return Whether the event has any listeners + */ + public boolean isEmpty() { + return listeners.isEmpty(); + } + + /** + * Check if a listener is registered + * @param listener The listener to check + * @return Whether the listener is registered + */ + public boolean isExists(T listener) { + return listeners.containsKey(listener); + } + + /** + * Alias for isExists + * @param listener The listener to check + * @return Whether the listener is registered + */ + public boolean has(T listener) { + return isExists(listener); + } + + /** + * Check if a listener has a priority + * @param listener The listener to check + * @return Whether the listener has a priority + */ + public boolean hasPriority(T listener) { + if (!isExists(listener)) return false; + return listeners.get(listener) != null && listeners.get(listener) != 0; + } + + /** + * Set the priority of a listener + * @param listener The listener to set the priority of + * @param priority The priority to set + */ + public void setPriority(T listener, int priority) { + if (!isExists(listener)) { + listeners.put(listener, priority); + return; + } + listeners.replace(listener, priority); + } + + /** + * Register a listener with a priority + * @param listener The listener to register + * @param priority The priority of the listener + */ + public void register(T listener, int priority) { + this.listeners.put(listener, priority); + if (priority > maxPriority) { + maxPriority = priority; + } + } + + /** + * Register a listener (no priority) + * @param listener The listener to register + * @throws IllegalArgumentException If the listener is already registered + */ + @Override + public void register(T listener) { + if (isExists(listener)) throw new IllegalArgumentException("Listener already exists"); + this.listeners.put(listener, 0); + } + + /** + * Register a listener (no priority) + * @param listener The listener to register + */ + public void registerNonSafe(T listener) { + if (isExists(listener)) return; + register(listener); + } + + /** + * Unregister a listener + * @param listener The listener to unregister + */ + @Override + public void unregister(T listener) { + if (!isExists(listener)) return; + this.listeners.remove(listener); + } + + /** + * Get all listeners + * @return A list of all listeners + */ + @Override + public List getListenersAsList() { + return listeners.keySet().stream().toList(); + } + + /** + * get the priority of a listener + * @param listener The listener to get the priority of + * @return The priority of the listener + */ + public int getPriority(T listener) { + return listeners.get(listener); + } + + /** + * Get the highest priority + * @return The highest priority + */ + public int getMaxPriority() { + return maxPriority; + } + + /** + * Get the next priority + * @return The next priority + */ + public int nextPriority() { + return maxPriority + 1; + } + + @Deprecated + public T getListener(int index) { + return getListenersAsList().get(index); + } + + /** + * Get all listeners with a specific priority + * @param priority The priority to get listeners for + * @return A list of listeners with the specified priority + */ + public List getListenersAsList(int priority) { + List listeners = new ArrayList<>(); + for (Map.Entry entry : this.listeners.entrySet()) { + if (entry.getValue() == priority) { + listeners.add(entry.getKey()); + } + } + return listeners; + } + + @Deprecated + @SuppressWarnings("unchecked") + public T[] getListeners(int priority) { + return (T[]) getListenersAsList(priority).toArray(); + } + + public Map getListeners() { + return listeners; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/event/v2/listener/InventoryTickTask.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/v2/listener/InventoryTickTask.java new file mode 100644 index 000000000..4f66ba34f --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/v2/listener/InventoryTickTask.java @@ -0,0 +1,8 @@ +package net.pitan76.mcpitanlib.api.event.v2.listener; + +import net.pitan76.mcpitanlib.api.event.item.InventoryTickEvent; + +@FunctionalInterface +public interface InventoryTickTask { + void inventoryTick(InventoryTickEvent event); +} \ No newline at end of file diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/gen/OreRegistry.java b/common/src/main/java/net/pitan76/mcpitanlib/api/gen/OreRegistry.java new file mode 100644 index 000000000..f1ce3ec98 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/gen/OreRegistry.java @@ -0,0 +1,42 @@ +package net.pitan76.mcpitanlib.api.gen; + +import net.minecraft.block.Block; +import net.minecraft.util.Identifier; +import net.minecraft.world.gen.GenerationStep; +import net.minecraft.world.gen.feature.ConfiguredFeature; +import net.minecraft.world.gen.feature.PlacedFeature; +import net.pitan76.mcpitanlib.api.registry.WorldGenRegistry; +import net.pitan76.mcpitanlib.api.registry.result.RegistryResult; +import net.pitan76.mcpitanlib.api.util.BlockUtil; +import net.pitan76.mcpitanlib.api.util.FeatureConfigUtil; +import net.pitan76.mcpitanlib.api.util.PlacedFutureUtil; + +@Deprecated +public class OreRegistry { + /** + * Generating custom ore in stone + * @param registry WorldGenRegistry + * @param block Block + * @param size Ore size + * @param height generating height + * @param count generating count per chunk + * @return Identifier of feature + */ + public static Identifier registerStoneOre(WorldGenRegistry registry, Block block, int size, int height, int count) { + Identifier identifier = BlockUtil.toID(block).withSuffixedPath("_ore_feature"); + RegistryResult> configuredFuture = registry.registerFeature(identifier, + () -> FeatureConfigUtil.createConfiguredFeature( + FeatureConfigUtil.createStoneOreFeatureConfig(block.getDefaultState(), size) + ) + ); + + RegistryResult placedFeature = registry.registerPlacedFeature(identifier, + () -> PlacedFutureUtil.create(configuredFuture.getOrNull(), + PlacedFutureUtil.createPlacementModifiers(count, height) + ) + ); + + WorldGenRegistry.addProperties(GenerationStep.Feature.UNDERGROUND_DECORATION, placedFeature); + return identifier; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/gui/ExtendedNamedScreenHandlerFactory.java b/common/src/main/java/net/pitan76/mcpitanlib/api/gui/ExtendedNamedScreenHandlerFactory.java new file mode 100644 index 000000000..e5324df34 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/gui/ExtendedNamedScreenHandlerFactory.java @@ -0,0 +1,46 @@ +package net.pitan76.mcpitanlib.api.gui; + +import dev.architectury.registry.menu.ExtendedMenuProvider; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.network.PacketByteBuf; +import net.minecraft.screen.ScreenHandler; +import net.minecraft.screen.ScreenHandlerFactory; +import net.minecraft.text.Text; +import org.jetbrains.annotations.Nullable; + +@Deprecated +public class ExtendedNamedScreenHandlerFactory implements ExtendedMenuProvider { + + private final Text name; + private final ScreenHandlerFactory baseFactory; + private final PacketByteBufFactory bufFactory; + + public ExtendedNamedScreenHandlerFactory(Text name, ScreenHandlerFactory baseFactory, PacketByteBufFactory bufFactory) { + this.name = name; + this.baseFactory = baseFactory; + this.bufFactory = bufFactory; + } + + @Override + public void saveExtraData(PacketByteBuf buf) { + bufFactory.saveExtraData(buf); + } + + @Override + public Text getDisplayName() { + return name; + } + + @Nullable + @Override + public ScreenHandler createMenu(int syncId, PlayerInventory inv, PlayerEntity player) { + return baseFactory.createMenu(syncId, inv, player); + + } + + @FunctionalInterface + public interface PacketByteBufFactory { + void saveExtraData(PacketByteBuf buf); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/gui/ExtendedScreenHandler.java b/common/src/main/java/net/pitan76/mcpitanlib/api/gui/ExtendedScreenHandler.java new file mode 100644 index 000000000..45d413cfb --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/gui/ExtendedScreenHandler.java @@ -0,0 +1,15 @@ +package net.pitan76.mcpitanlib.api.gui; + +import net.minecraft.network.PacketByteBuf; +import net.minecraft.screen.ScreenHandlerType; +import org.jetbrains.annotations.Nullable; + +public class ExtendedScreenHandler extends SimpleScreenHandler { + protected ExtendedScreenHandler(@Nullable ScreenHandlerType type, int syncId, PacketByteBuf buf) { + this(type, syncId); + } + + protected ExtendedScreenHandler(@Nullable ScreenHandlerType type, int syncId) { + super(type, syncId); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/gui/ExtendedScreenHandlerFactory.java b/common/src/main/java/net/pitan76/mcpitanlib/api/gui/ExtendedScreenHandlerFactory.java new file mode 100644 index 000000000..17d6586b0 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/gui/ExtendedScreenHandlerFactory.java @@ -0,0 +1,24 @@ +package net.pitan76.mcpitanlib.api.gui; + +import dev.architectury.registry.menu.ExtendedMenuProvider; +import net.minecraft.network.PacketByteBuf; +import net.minecraft.text.Text; +import net.pitan76.mcpitanlib.api.event.container.factory.DisplayNameArgs; +import net.pitan76.mcpitanlib.api.event.container.factory.ExtraDataArgs; + +@Deprecated +public interface ExtendedScreenHandlerFactory extends ExtendedMenuProvider { + @Override + default Text getDisplayName() { + return getDisplayName(new DisplayNameArgs()); + } + + @Override + default void saveExtraData(PacketByteBuf buf) { + writeExtraData(new ExtraDataArgs(buf)); + } + + Text getDisplayName(DisplayNameArgs args); + + void writeExtraData(ExtraDataArgs args); +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/gui/ExtendedScreenHandlerTypeBuilder.java b/common/src/main/java/net/pitan76/mcpitanlib/api/gui/ExtendedScreenHandlerTypeBuilder.java new file mode 100644 index 000000000..dd672f9a6 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/gui/ExtendedScreenHandlerTypeBuilder.java @@ -0,0 +1,40 @@ +package net.pitan76.mcpitanlib.api.gui; + +import dev.architectury.registry.menu.MenuRegistry; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.network.PacketByteBuf; +import net.minecraft.screen.ScreenHandler; +import net.minecraft.screen.ScreenHandlerType; +import net.pitan76.mcpitanlib.api.gui.args.CreateMenuEvent; + +public class ExtendedScreenHandlerTypeBuilder { + + private final Factory factory; + + public ExtendedScreenHandlerTypeBuilder(Factory factory) { + this.factory = factory; + } + + public ExtendedScreenHandlerTypeBuilder(Factory2 factory) { + this.factory = factory; + } + + public ScreenHandlerType build() { + return MenuRegistry.ofExtended(factory::create); + } + + @FunctionalInterface + public interface Factory { + T create(int syncId, PlayerInventory inventory, PacketByteBuf buf); + } + + @FunctionalInterface + public interface Factory2 extends Factory { + T create(CreateMenuEvent e, PacketByteBuf buf); + + @Override + default T create(int syncId, PlayerInventory inventory, PacketByteBuf buf) { + return create(new CreateMenuEvent(syncId, inventory), buf); + } + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/gui/SimpleScreenHandler.java b/common/src/main/java/net/pitan76/mcpitanlib/api/gui/SimpleScreenHandler.java new file mode 100644 index 000000000..334c42388 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/gui/SimpleScreenHandler.java @@ -0,0 +1,276 @@ +package net.pitan76.mcpitanlib.api.gui; + +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.inventory.Inventory; +import net.minecraft.item.ItemStack; +import net.minecraft.screen.ScreenHandler; +import net.minecraft.screen.ScreenHandlerType; +import net.minecraft.screen.slot.Slot; +import net.minecraft.screen.slot.SlotActionType; +import net.pitan76.mcpitanlib.api.entity.Player; +import net.pitan76.mcpitanlib.api.gui.args.CreateMenuEvent; +import net.pitan76.mcpitanlib.api.gui.args.SlotClickEvent; +import net.pitan76.mcpitanlib.api.util.ItemStackUtil; +import net.pitan76.mcpitanlib.api.util.ScreenHandlerUtil; +import net.pitan76.mcpitanlib.api.util.SlotUtil; +import org.jetbrains.annotations.Nullable; + +import java.util.ArrayList; +import java.util.List; + +public class SimpleScreenHandler extends ScreenHandler { + protected SimpleScreenHandler(@Nullable ScreenHandlerType type, int syncId) { + super(type, syncId); + } + + protected SimpleScreenHandler(@Nullable ScreenHandlerType type, CreateMenuEvent e) { + this(type, e.getSyncId()); + } + + public boolean hasMainInventory = false; + public boolean hasHotbar = false; + + @Deprecated + @Override + public boolean canUse(PlayerEntity player) { + return canUse(new Player(player)); + } + + public boolean canUse(Player player) { + return true; + } + + public Slot addNormalSlot(Inventory inventory, int index, int x, int y) { + Slot slot = new Slot(inventory, index, x, y); + return this.addSlot(slot); + } + + public Slot addSlot(Inventory inventory, int index, int x, int y, SlotFactory factory) { + Slot slot = factory.create(inventory, index, x, y); + return this.addSlot(slot); + } + + public interface SlotFactory { + T create(Inventory inventory, int index, int x, int y); + } + + public Slot callAddSlot(Slot slot) { + return this.addSlot(slot); + } + + @Deprecated + @Override + protected Slot addSlot(Slot slot) { + return super.addSlot(slot); + } + + @Deprecated + @Override + public void onClosed(PlayerEntity player) { + this.close(new Player(player)); + } + + public void close(Player player) { + super.onClosed(player.getPlayerEntity()); + } + + + public static final int DEFAULT_SLOT_SIZE = 18; + + /** + * Add player main inventory slots + * @param inventory target player inventory + * @param x start x + * @param y start y + */ + protected List addPlayerMainInventorySlots(PlayerInventory inventory, int x, int y) { + hasMainInventory = true; + return this.addSlots(inventory, 9, x, y, DEFAULT_SLOT_SIZE, 9, 3); + } + + /** + * Add player hotbar slots + * @param inventory target player inventory + * @param x start x + * @param y start y + */ + protected List addPlayerHotbarSlots(PlayerInventory inventory, int x, int y) { + hasHotbar = true; + return this.addSlotsX(inventory, 0, x, y, DEFAULT_SLOT_SIZE, 9); + } + + /** + * 一括でスロットを設置する + * @param inventory target inventory + * @param firstIndex fisrt index + * @param firstX first x + * @param firstY first y + * @param size a slot size (if this is -1, set 18 to this) + * @param maxAmountX x line slot max amount + * @param maxAmountY y line slot max amount + * @return Slot list + */ + protected List addSlots(Inventory inventory, int firstIndex, int firstX, int firstY, int size, int maxAmountX, int maxAmountY) { + if (size < 0) size = DEFAULT_SLOT_SIZE; + List slots = new ArrayList<>(); + for (int y = 0; y < maxAmountY; ++y) { + List xSlots = this.addSlotsX(inventory, firstIndex + (y * maxAmountX), firstX, firstY + (y * size), size, maxAmountX); + slots.addAll(xSlots); + } + return slots; + } + + /** + * 一括で横にスロットを設置する + * @param inventory target inventory + * @param firstIndex first index + * @param firstX first x + * @param y y + * @param size a slot size (if this is -1, set 18 to this) + * @param amount slot amount + * @return Slot list + */ + protected List addSlotsX(Inventory inventory, int firstIndex, int firstX, int y, int size, int amount) { + if (size < 0) size = DEFAULT_SLOT_SIZE; + List slots = new ArrayList<>(); + for (int x = 0; x < amount; ++x) { + Slot slot = this.addNormalSlot(inventory, firstIndex + x, firstX + (x * size), y); + slots.add(slot); + } + return slots; + } + + /** + * 一括で縦にスロットを設置する + * @param inventory target inventory + * @param firstIndex first index + * @param x x + * @param firstY first y + * @param size a slot size (if this is -1, set 18 to this) + * @param amount slot amount + * @return Slot list + */ + protected List addSlotsY(Inventory inventory, int firstIndex, int x, int firstY, int size, int amount) { + if (size < 0) size = DEFAULT_SLOT_SIZE; + List slots = new ArrayList<>(); + for (int y = 0; y < amount; ++y) { + Slot slot = this.addNormalSlot(inventory, firstIndex + x, x, firstY + (y * size)); + slots.add(slot); + } + return slots; + } + + @Deprecated + public ItemStack quickMoveOverride(PlayerEntity player, int index) { + return quickMoveOverride(new Player(player), index); + } + + public boolean callInsertItem(ItemStack stack, int startIndex, int endIndex, boolean fromLast) { + return this.insertItem(stack, startIndex, endIndex, fromLast); + } + + @Deprecated + @Override + protected boolean insertItem(ItemStack stack, int startIndex, int endIndex, boolean fromLast) { + return super.insertItem(stack, startIndex, endIndex, fromLast); + } + + public ItemStack quickMoveOverride(Player player, int index) { + ItemStack itemStack = ItemStackUtil.empty(); + Slot slot = ScreenHandlerUtil.getSlot(this, index); + int size = ScreenHandlerUtil.getSlots(this).size(); + + if (SlotUtil.hasStack(slot)) { + ItemStack itemStack2 = SlotUtil.getStack(slot); + itemStack = itemStack2.copy(); + + if (hasMainInventory && hasHotbar) { + if (index > 35) { + if (!this.callInsertItem(itemStack2, 0, 9, false)) { + if (!this.callInsertItem(itemStack2, 9, 36, true)) { + return ItemStackUtil.empty(); + } + } + } else if (size > 36 && !this.callInsertItem(itemStack2, 36, size, false)) { + return ItemStackUtil.empty(); + } + } + + if (itemStack2.isEmpty()) { + SlotUtil.setStack(slot, ItemStackUtil.empty()); + } else { + SlotUtil.markDirty(slot); + } + + if (itemStack2.getCount() == itemStack.getCount()) { + return ItemStackUtil.empty(); + } + + SlotUtil.onTakeItem(slot, player, itemStack2); + } + + return itemStack; + } + + + @Deprecated + @Override + public ItemStack quickMove(PlayerEntity player, int slot) { + return quickMoveOverride(player, slot); + } + + @Deprecated + @Override + public Slot getSlot(int index) { + return callGetSlot(index); + } + + public Slot callGetSlot(int index) { + return super.getSlot(index); + } + + @Deprecated + @Override + public void onSlotClick(int slotIndex, int button, SlotActionType actionType, PlayerEntity player) { + overrideOnSlotClick(slotIndex, button, actionType, new Player(player)); + } + + public void overrideOnSlotClick(int slotIndex, int button, SlotActionType actionType, Player player) { + onSlotClick(new SlotClickEvent(slotIndex, button, actionType, player)); + } + + public void onSlotClick(SlotClickEvent e) { + super.onSlotClick(e.slot, e.button, e.actionType, e.player.getEntity()); + } + + @Override + @Deprecated + public void setCursorStack(ItemStack stack) { + callSetCursorStack(stack); + } + + public void callSetCursorStack(ItemStack stack) { + super.setCursorStack(stack); + } + + @Override + @Deprecated + public void setStackInSlot(int slot, int revision, ItemStack stack) { + callSetStackInSlot(slot, revision, stack); + } + + public void callSetStackInSlot(int slot, int revision, ItemStack stack) { + super.setStackInSlot(slot, revision, stack); + } + + @Override + @Deprecated + public int getRevision() { + return callGetRevision(); + } + + public int callGetRevision() { + return super.getRevision(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/gui/SimpleScreenHandlerTypeBuilder.java b/common/src/main/java/net/pitan76/mcpitanlib/api/gui/SimpleScreenHandlerTypeBuilder.java new file mode 100644 index 000000000..39d18ee67 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/gui/SimpleScreenHandlerTypeBuilder.java @@ -0,0 +1,39 @@ +package net.pitan76.mcpitanlib.api.gui; + +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.resource.featuretoggle.FeatureFlags; +import net.minecraft.screen.ScreenHandler; +import net.minecraft.screen.ScreenHandlerType; +import net.pitan76.mcpitanlib.api.gui.args.CreateMenuEvent; + +public class SimpleScreenHandlerTypeBuilder { + + private final Factory factory; + + public SimpleScreenHandlerTypeBuilder(Factory factory) { + this.factory = factory; + } + + public SimpleScreenHandlerTypeBuilder(Factory2 factory) { + this.factory = factory; + } + + public ScreenHandlerType build() { + return new ScreenHandlerType<>(factory::create, FeatureFlags.VANILLA_FEATURES); + } + + @FunctionalInterface + public interface Factory { + T create(int syncId, PlayerInventory inventory); + } + + @FunctionalInterface + public interface Factory2 extends Factory { + T create(CreateMenuEvent e); + + @Override + default T create(int syncId, PlayerInventory inventory) { + return create(new CreateMenuEvent(syncId, inventory)); + } + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/gui/args/CreateMenuEvent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/gui/args/CreateMenuEvent.java new file mode 100644 index 000000000..1fface96e --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/gui/args/CreateMenuEvent.java @@ -0,0 +1,58 @@ +package net.pitan76.mcpitanlib.api.gui.args; + +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.entity.Player; + +public class CreateMenuEvent { + public int syncId; + public PlayerInventory playerInventory; + public PlayerEntity player; + + public CreateMenuEvent(int syncId, PlayerInventory playerInventory, PlayerEntity player) { + this.syncId = syncId; + this.playerInventory = playerInventory; + this.player = player; + } + + public CreateMenuEvent(int syncId, PlayerInventory playerInventory) { + this.syncId = syncId; + this.playerInventory = playerInventory; + this.player = playerInventory.player; + } + + public CreateMenuEvent(int syncId, Player player) { + this.syncId = syncId; + this.playerInventory = player.getInv(); + this.player = player.getEntity(); + } + + public int getSyncId() { + return syncId; + } + + public PlayerInventory getPlayerInventory() { + return playerInventory; + } + + public PlayerEntity getPlayerEntity() { + return player; + } + + public Player getPlayer() { + return new Player(player); + } + + public boolean isExistPlayer() { + return player != null; + } + + public boolean isClient() { + return getPlayer().isClient(); + } + + public World getWorld() { + return getPlayer().getWorld(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/gui/args/SlotClickEvent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/gui/args/SlotClickEvent.java new file mode 100644 index 000000000..2c63f0d20 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/gui/args/SlotClickEvent.java @@ -0,0 +1,67 @@ +package net.pitan76.mcpitanlib.api.gui.args; + +import net.minecraft.screen.slot.SlotActionType; +import net.pitan76.mcpitanlib.api.entity.Player; +import net.pitan76.mcpitanlib.api.gui.slot.CompatSlotActionType; + +public class SlotClickEvent { + public int slot; + public int button; + public SlotActionType actionType; + public Player player; + + public SlotClickEvent(int slot, int button, SlotActionType actionType, Player player) { + this.slot = slot; + this.button = button; + this.actionType = actionType; + this.player = player; + } + + public int getSlot() { + return slot; + } + + public int getButton() { + return button; + } + + public SlotActionType getRawActionType() { + return actionType; + } + + public CompatSlotActionType getActionType() { + return CompatSlotActionType.of(actionType); + } + + public Player getPlayer() { + return player; + } + + public boolean isClient() { + return player.isClient(); + } + + public boolean isServer() { + return player.isServer(); + } + + public boolean isSwapAction() { + return actionType == SlotActionType.SWAP; + } + + public boolean isPickupAction() { + return actionType == SlotActionType.PICKUP; + } + + public boolean isQuickCraftAction() { + return actionType == SlotActionType.QUICK_CRAFT; + } + + public boolean isQuickMoveAction() { + return actionType == SlotActionType.QUICK_MOVE; + } + + public boolean isThrowAction() { + return actionType == SlotActionType.THROW; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/gui/inventory/IInventory.java b/common/src/main/java/net/pitan76/mcpitanlib/api/gui/inventory/IInventory.java new file mode 100644 index 000000000..aea703cca --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/gui/inventory/IInventory.java @@ -0,0 +1,77 @@ +package net.pitan76.mcpitanlib.api.gui.inventory; + +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.inventory.Inventories; +import net.minecraft.inventory.Inventory; +import net.minecraft.item.ItemStack; +import net.minecraft.util.collection.DefaultedList; + +public interface IInventory extends Inventory { + + DefaultedList getItems(); + + static IInventory of(DefaultedList items) { + return () -> items; + } + + static IInventory ofSize(int size) { + return of(DefaultedList.ofSize(size, ItemStack.EMPTY)); + } + + @Override + default int size() { + return getItems().size(); + } + + @Override + default boolean isEmpty() { + for (int i = 0; i < size(); i++) { + ItemStack stack = getStack(i); + if (!stack.isEmpty()) { + return false; + } + } + return true; + } + + @Override + default ItemStack getStack(int slot) { + return getItems().get(slot); + } + + @Override + default ItemStack removeStack(int slot, int count) { + ItemStack result = Inventories.splitStack(getItems(), slot, count); + if (!result.isEmpty()) { + markDirty(); + } + return result; + } + + @Override + default ItemStack removeStack(int slot) { + return Inventories.removeStack(getItems(), slot); + } + + @Override + default void setStack(int slot, ItemStack stack) { + getItems().set(slot, stack); + if (stack.getCount() > getMaxCountPerStack()) { + stack.setCount(getMaxCountPerStack()); + } + } + + @Override + default void clear() { + getItems().clear(); + } + + @Override + default void markDirty() { + } + + @Override + default boolean canPlayerUse(PlayerEntity player) { + return true; + } +} \ No newline at end of file diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/gui/inventory/sided/ChestStyleSidedInventory.java b/common/src/main/java/net/pitan76/mcpitanlib/api/gui/inventory/sided/ChestStyleSidedInventory.java new file mode 100644 index 000000000..a4cd6f4f3 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/gui/inventory/sided/ChestStyleSidedInventory.java @@ -0,0 +1,10 @@ +package net.pitan76.mcpitanlib.api.gui.inventory.sided; + +import net.pitan76.mcpitanlib.api.gui.inventory.sided.args.AvailableSlotsArgs; + +public interface ChestStyleSidedInventory extends VanillaStyleSidedInventory { + @Override + default int[] getAvailableSlots(AvailableSlotsArgs args) { + return args.getAllSlots(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/gui/inventory/sided/CompatSidedInventory.java b/common/src/main/java/net/pitan76/mcpitanlib/api/gui/inventory/sided/CompatSidedInventory.java new file mode 100644 index 000000000..5f4ce81b3 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/gui/inventory/sided/CompatSidedInventory.java @@ -0,0 +1,35 @@ +package net.pitan76.mcpitanlib.api.gui.inventory.sided; + +import net.minecraft.inventory.SidedInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.util.math.Direction; +import net.pitan76.mcpitanlib.api.gui.inventory.sided.args.AvailableSlotsArgs; +import net.pitan76.mcpitanlib.api.gui.inventory.sided.args.CanExtractArgs; +import net.pitan76.mcpitanlib.api.gui.inventory.sided.args.CanInsertArgs; +import org.jetbrains.annotations.Nullable; + +public interface CompatSidedInventory extends SidedInventory { + @Override + @Deprecated + default int[] getAvailableSlots(Direction side) { + return getAvailableSlots(new AvailableSlotsArgs(side, this)); + } + + int[] getAvailableSlots(AvailableSlotsArgs args); + + @Override + @Deprecated + default boolean canInsert(int slot, ItemStack stack, @Nullable Direction dir) { + return canInsert(new CanInsertArgs(slot, stack, dir)); + } + + boolean canInsert(CanInsertArgs args); + + @Override + @Deprecated + default boolean canExtract(int slot, ItemStack stack, Direction dir) { + return canExtract(new CanExtractArgs(slot, stack, dir)); + } + + boolean canExtract(CanExtractArgs args); +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/gui/inventory/sided/VanillaStyleSidedInventory.java b/common/src/main/java/net/pitan76/mcpitanlib/api/gui/inventory/sided/VanillaStyleSidedInventory.java new file mode 100644 index 000000000..119a59057 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/gui/inventory/sided/VanillaStyleSidedInventory.java @@ -0,0 +1,20 @@ +package net.pitan76.mcpitanlib.api.gui.inventory.sided; + +import net.minecraft.util.math.Direction; +import net.pitan76.mcpitanlib.api.gui.inventory.sided.args.CanExtractArgs; +import net.pitan76.mcpitanlib.api.gui.inventory.sided.args.CanInsertArgs; + +public interface VanillaStyleSidedInventory extends CompatSidedInventory { + @Override + default boolean canInsert(CanInsertArgs args) { + if (args.getDir() == null) + return false; + + return args.getDir() != Direction.DOWN; + } + + @Override + default boolean canExtract(CanExtractArgs args) { + return args.getDir() == Direction.DOWN; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/gui/inventory/sided/args/AvailableSlotsArgs.java b/common/src/main/java/net/pitan76/mcpitanlib/api/gui/inventory/sided/args/AvailableSlotsArgs.java new file mode 100644 index 000000000..748b47420 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/gui/inventory/sided/args/AvailableSlotsArgs.java @@ -0,0 +1,38 @@ +package net.pitan76.mcpitanlib.api.gui.inventory.sided.args; + +import net.minecraft.util.math.Direction; +import net.pitan76.mcpitanlib.api.gui.inventory.sided.CompatSidedInventory; +import net.pitan76.mcpitanlib.api.gui.inventory.IInventory; + +public class AvailableSlotsArgs { + public Direction side; + public CompatSidedInventory inventory; + + public AvailableSlotsArgs(Direction side, CompatSidedInventory inventory) { + this.side = side; + this.inventory = inventory; + } + + public Direction getSide() { + return side; + } + + public CompatSidedInventory getInventory() { + return inventory; + } + + public int[] getAllSlots() { + if (!(inventory instanceof IInventory)) + return new int[0]; + + IInventory inv = (IInventory) inventory; + int size = inv.size(); + + int[] slots = new int[size]; + for (int i = 0; i < size; i++) { + slots[i] = i; + } + + return slots; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/gui/inventory/sided/args/CanExtractArgs.java b/common/src/main/java/net/pitan76/mcpitanlib/api/gui/inventory/sided/args/CanExtractArgs.java new file mode 100644 index 000000000..568dcbe4c --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/gui/inventory/sided/args/CanExtractArgs.java @@ -0,0 +1,32 @@ +package net.pitan76.mcpitanlib.api.gui.inventory.sided.args; + +import net.minecraft.item.ItemStack; +import net.minecraft.util.math.Direction; + +public class CanExtractArgs { + public int slot; + public ItemStack stack; + public Direction dir; + + public CanExtractArgs(int slot, ItemStack stack, Direction dir) { + this.slot = slot; + this.stack = stack; + this.dir = dir; + } + + public int getSlot() { + return slot; + } + + public ItemStack getStack() { + return stack; + } + + public Direction getDir() { + return dir; + } + + public net.pitan76.mcpitanlib.midohra.item.ItemStack getStack_midohra() { + return net.pitan76.mcpitanlib.midohra.item.ItemStack.of(getStack()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/gui/inventory/sided/args/CanInsertArgs.java b/common/src/main/java/net/pitan76/mcpitanlib/api/gui/inventory/sided/args/CanInsertArgs.java new file mode 100644 index 000000000..a6aa1a662 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/gui/inventory/sided/args/CanInsertArgs.java @@ -0,0 +1,35 @@ +package net.pitan76.mcpitanlib.api.gui.inventory.sided.args; + +import net.minecraft.item.ItemStack; +import net.minecraft.util.math.Direction; +import org.jetbrains.annotations.Nullable; + +public class CanInsertArgs { + public int slot; + public ItemStack stack; + + @Nullable + public Direction dir; + + public CanInsertArgs(int slot, ItemStack stack, @Nullable Direction dir) { + this.slot = slot; + this.stack = stack; + this.dir = dir; + } + + public int getSlot() { + return slot; + } + + public ItemStack getStack() { + return stack; + } + + public @Nullable Direction getDir() { + return dir; + } + + public net.pitan76.mcpitanlib.midohra.item.ItemStack getStack_midohra() { + return net.pitan76.mcpitanlib.midohra.item.ItemStack.of(getStack()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/gui/slot/CompatSlotActionType.java b/common/src/main/java/net/pitan76/mcpitanlib/api/gui/slot/CompatSlotActionType.java new file mode 100644 index 000000000..b95c48eec --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/gui/slot/CompatSlotActionType.java @@ -0,0 +1,50 @@ +package net.pitan76.mcpitanlib.api.gui.slot; + +import net.minecraft.screen.slot.SlotActionType; + +public class CompatSlotActionType { + public static final CompatSlotActionType PICKUP = new CompatSlotActionType(SlotActionType.PICKUP); + public static final CompatSlotActionType QUICK_MOVE = new CompatSlotActionType(SlotActionType.QUICK_MOVE); + public static final CompatSlotActionType SWAP = new CompatSlotActionType(SlotActionType.SWAP); + public static final CompatSlotActionType THROW = new CompatSlotActionType(SlotActionType.THROW); + public static final CompatSlotActionType CLONE = new CompatSlotActionType(SlotActionType.CLONE); + public static final CompatSlotActionType QUICK_CRAFT = new CompatSlotActionType(SlotActionType.QUICK_CRAFT); + public static final CompatSlotActionType PICKUP_ALL = new CompatSlotActionType(SlotActionType.PICKUP_ALL); + + public final SlotActionType raw; + + protected CompatSlotActionType(SlotActionType raw) { + this.raw = raw; + } + + public static CompatSlotActionType of(SlotActionType raw) { + if (raw == SlotActionType.PICKUP) return PICKUP; + if (raw == SlotActionType.QUICK_MOVE) return QUICK_MOVE; + if (raw == SlotActionType.SWAP) return SWAP; + if (raw == SlotActionType.THROW) return THROW; + if (raw == SlotActionType.CLONE) return CLONE; + if (raw == SlotActionType.QUICK_CRAFT) return QUICK_CRAFT; + if (raw == SlotActionType.PICKUP_ALL) return PICKUP_ALL; + return new CompatSlotActionType(raw); + } + + public boolean isSwapOrPickupOrQuickMoveOrThrow() { + return raw == SlotActionType.SWAP || raw == SlotActionType.PICKUP || raw == SlotActionType.QUICK_MOVE || raw == SlotActionType.THROW; + } + + public SlotActionType getRaw() { + return raw; + } + + public int getIndex() { + return raw.ordinal(); + } + + public String getName() { + return raw.name(); + } + + public boolean isOf(CompatSlotActionType type) { + return raw == type.raw; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/gui/slot/CompatibleSlot.java b/common/src/main/java/net/pitan76/mcpitanlib/api/gui/slot/CompatibleSlot.java new file mode 100644 index 000000000..f49db49df --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/gui/slot/CompatibleSlot.java @@ -0,0 +1,125 @@ +package net.pitan76.mcpitanlib.api.gui.slot; + +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.inventory.Inventory; +import net.minecraft.item.ItemStack; +import net.minecraft.screen.slot.Slot; +import net.pitan76.mcpitanlib.api.entity.Player; + +public class CompatibleSlot extends Slot { + + public Inventory inventory; + public int index; + public int x; + public int y; + + public CompatibleSlot(Inventory inventory, int index, int x, int y) { + super(inventory, index, x, y); + this.inventory = inventory; + this.index = index; + this.x = x; + this.y = y; + } + + public void callSetStack(ItemStack stack) { + super.setStack(stack); + } + + public void callSetStackNoCallbacks(ItemStack stack) { + super.setStackNoCallbacks(stack); + } + + public ItemStack callGetStack() { + return super.getStack(); + } + + public ItemStack callTakeStack(int amount) { + return super.takeStack(amount); + } + + public boolean callHasStack() { + return super.hasStack(); + } + + @Deprecated + @Override + public void setStack(ItemStack stack) { + callSetStack(stack); + } + + @Deprecated + @Override + public void setStackNoCallbacks(ItemStack stack) { + callSetStackNoCallbacks(stack); + } + + @Deprecated + @Override + public ItemStack getStack() { + return callGetStack(); + } + + @Deprecated + @Override + public ItemStack takeStack(int amount) { + return callTakeStack(amount); + } + + @Deprecated + @Override + public boolean hasStack() { + return callHasStack(); + } + + public Inventory callGetInventory() { + return inventory; + } + + public int callGetIndex() { + return super.getIndex(); + } + + public int callGetId() { + return super.id; + } + + public int callGetX() { + return super.x; + } + + public int callGetY() { + return super.y; + } + + public void callMarkDirty() { + super.markDirty(); + } + + @Override + public boolean canInsert(ItemStack stack) { + return canInsert(net.pitan76.mcpitanlib.midohra.item.ItemStack.of(stack)); + } + + @Override + public boolean canTakeItems(PlayerEntity playerEntity) { + return canTakeItems(new Player(playerEntity)); + } + + public boolean canInsert(net.pitan76.mcpitanlib.midohra.item.ItemStack stack) { + return super.canInsert(stack.toMinecraft()); + } + + public boolean canTakeItems(Player player) { + return super.canTakeItems(player.getEntity()); + } + + @Deprecated + @Override + public boolean canTakePartial(PlayerEntity player) { + return canTakePartial(new Player(player)); + } + + public boolean canTakePartial(Player player) { + return super.canTakePartial(player.getEntity()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/gui/v2/ExtendedScreenHandlerFactory.java b/common/src/main/java/net/pitan76/mcpitanlib/api/gui/v2/ExtendedScreenHandlerFactory.java new file mode 100644 index 000000000..b26d1915f --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/gui/v2/ExtendedScreenHandlerFactory.java @@ -0,0 +1,17 @@ +package net.pitan76.mcpitanlib.api.gui.v2; + +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.screen.ScreenHandler; +import net.pitan76.mcpitanlib.api.gui.args.CreateMenuEvent; + +@SuppressWarnings("deprecation") +public interface ExtendedScreenHandlerFactory extends net.pitan76.mcpitanlib.api.gui.ExtendedScreenHandlerFactory { + + @Override + default ScreenHandler createMenu(int syncId, PlayerInventory playerInventory, PlayerEntity player) { + return createMenu(new CreateMenuEvent(syncId, playerInventory, player)); + } + + ScreenHandler createMenu(CreateMenuEvent event); +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/gui/v2/SimpleScreenHandlerFactory.java b/common/src/main/java/net/pitan76/mcpitanlib/api/gui/v2/SimpleScreenHandlerFactory.java new file mode 100644 index 000000000..8d447ebb3 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/gui/v2/SimpleScreenHandlerFactory.java @@ -0,0 +1,25 @@ +package net.pitan76.mcpitanlib.api.gui.v2; + +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.screen.NamedScreenHandlerFactory; +import net.minecraft.screen.ScreenHandler; +import net.minecraft.text.Text; +import net.pitan76.mcpitanlib.api.event.container.factory.DisplayNameArgs; +import net.pitan76.mcpitanlib.api.gui.args.CreateMenuEvent; + +public interface SimpleScreenHandlerFactory extends NamedScreenHandlerFactory { + @Override + default Text getDisplayName() { + return getDisplayName(new DisplayNameArgs()); + } + + Text getDisplayName(DisplayNameArgs args); + + @Override + default ScreenHandler createMenu(int syncId, PlayerInventory playerInventory, PlayerEntity player) { + return createMenu(new CreateMenuEvent(syncId, playerInventory, player)); + } + + ScreenHandler createMenu(CreateMenuEvent event); +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/helper/SimpleRegister.java b/common/src/main/java/net/pitan76/mcpitanlib/api/helper/SimpleRegister.java new file mode 100644 index 000000000..763444f86 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/helper/SimpleRegister.java @@ -0,0 +1,69 @@ +package net.pitan76.mcpitanlib.api.helper; + +import net.minecraft.item.Item; +import net.minecraft.item.ItemConvertible; +import net.minecraft.item.ItemStack; +import net.pitan76.mcpitanlib.api.block.CompatibleBlockSettings; +import net.pitan76.mcpitanlib.api.block.ExtendBlock; +import net.pitan76.mcpitanlib.api.item.CompatFoodComponent; +import net.pitan76.mcpitanlib.api.item.CompatibleItemSettings; +import net.pitan76.mcpitanlib.api.item.CreativeTabBuilder; +import net.pitan76.mcpitanlib.api.item.ExtendItem; +import net.pitan76.mcpitanlib.api.registry.result.RegistryResult; +import net.pitan76.mcpitanlib.api.registry.v2.CompatRegistryV2; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.api.util.ItemStackUtil; +import net.pitan76.mcpitanlib.api.util.ItemUtil; +import net.pitan76.mcpitanlib.core.datafixer.Pair; + +import java.util.function.Supplier; + +public class SimpleRegister { + public static Supplier createItem(CompatRegistryV2 registry, CompatIdentifier id, CompatibleItemSettings settings) { + return registry.registerExtendItem(id, () -> new ExtendItem(settings)); + } + + public static Supplier createSimpleItem(CompatRegistryV2 registry, CompatIdentifier id) { + return createItem(registry, id, new CompatibleItemSettings()); + } + + public static Supplier createFoodItem(CompatRegistryV2 registry, CompatIdentifier id, CompatFoodComponent component) { + return createItem(registry, id, new CompatibleItemSettings().food(component)); + } + + public static Supplier createSimpleFoodItem(CompatRegistryV2 registry, CompatIdentifier id, int hunger, float saturation, boolean meat, boolean snack) { + CompatFoodComponent component = new CompatFoodComponent().setHunger(hunger).setSaturation(saturation); + if (meat) component.setMeat(); + if (snack) component.setSnack(); + return createFoodItem(registry, id, component); + } + + public static Supplier createSimpleFoodItem(CompatRegistryV2 registry, CompatIdentifier id, int hunger, float saturation) { + return createSimpleFoodItem(registry, id, hunger, saturation, false, false); + } + + public static Pair, Supplier> createBlock(CompatRegistryV2 registry, CompatIdentifier id, CompatibleBlockSettings blockSettings, CompatibleItemSettings itemSettings) { + Supplier blockSupplier = registry.registerExtendBlock(id, () -> new ExtendBlock(blockSettings)); + RegistryResult itemRegistryResult = registry.registerItem(id, () -> ItemUtil.ofBlock(blockSupplier.get(), itemSettings)); + Supplier itemSupplier = itemRegistryResult::getOrNull; + return new Pair<>(blockSupplier, itemSupplier); + } + + public static Pair, Supplier> createSimpleBlock(CompatRegistryV2 registry, CompatIdentifier id, CompatibleItemSettings itemSettings) { + return createBlock(registry, id, new CompatibleBlockSettings(), itemSettings); + } + + public static Pair, Supplier> createSimpleBlock(CompatRegistryV2 registry, CompatIdentifier id) { + return createBlock(registry, id, new CompatibleBlockSettings(), new CompatibleItemSettings()); + } + + public static CreativeTabBuilder createCreativeTab(CompatRegistryV2 registry, CompatIdentifier id, Supplier icon) { + CreativeTabBuilder builder = CreativeTabBuilder.create(id).setIcon(icon); + registry.registerItemGroup(builder); + return builder; + } + + public static CreativeTabBuilder createCreativeTabByItem(CompatRegistryV2 registry, CompatIdentifier id, Supplier item) { + return createCreativeTab(registry, id, () -> ItemStackUtil.create(item.get())); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/item/ArmorEquipmentType.java b/common/src/main/java/net/pitan76/mcpitanlib/api/item/ArmorEquipmentType.java new file mode 100644 index 000000000..c1ec04ae7 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/ArmorEquipmentType.java @@ -0,0 +1,76 @@ +package net.pitan76.mcpitanlib.api.item; + +import net.minecraft.entity.EquipmentSlot; +import net.minecraft.item.ArmorItem; +import org.jetbrains.annotations.Nullable; + +public class ArmorEquipmentType { + + public static ArmorEquipmentType HEAD = new ArmorEquipmentType(EquipmentSlot.HEAD, ArmorItem.Type.HELMET); + public static ArmorEquipmentType CHEST = new ArmorEquipmentType(EquipmentSlot.CHEST, ArmorItem.Type.CHESTPLATE); + public static ArmorEquipmentType LEGS = new ArmorEquipmentType(EquipmentSlot.LEGS, ArmorItem.Type.LEGGINGS); + public static ArmorEquipmentType FEET = new ArmorEquipmentType(EquipmentSlot.FEET, ArmorItem.Type.BOOTS); + + // New type for animals from 1.20.5 + public static ArmorEquipmentType BODY = new ArmorEquipmentType(EquipmentSlot.BODY, ArmorItem.Type.BODY); + + protected final EquipmentSlot slot; + protected final ArmorItem.Type type; + + protected ArmorEquipmentType(EquipmentSlot slot, ArmorItem.Type type) { + this.slot = slot; + this.type = type; + } + + @Deprecated + public EquipmentSlot getSlot() { + return slot; + } + + @Deprecated + public ArmorItem.Type getType() { + return type; + } + + @Nullable + public static ArmorEquipmentType of(EquipmentSlot slot) { + switch (slot) { + case HEAD -> { + return HEAD; + } + case CHEST -> { + return CHEST; + } + case LEGS -> { + return LEGS; + } + case FEET -> { + return FEET; + } + default -> { + return null; + } + } + } + + @Nullable + public static ArmorEquipmentType of(ArmorItem.Type type) { + switch (type) { + case HELMET -> { + return HEAD; + } + case CHESTPLATE -> { + return CHEST; + } + case LEGGINGS -> { + return LEGS; + } + case BOOTS -> { + return FEET; + } + default -> { + return null; + } + } + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/item/CompatFoodComponent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/item/CompatFoodComponent.java new file mode 100644 index 000000000..cc6115cad --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/CompatFoodComponent.java @@ -0,0 +1,129 @@ +package net.pitan76.mcpitanlib.api.item; + +import com.google.common.collect.ImmutableList; +import com.mojang.datafixers.util.Pair; +import net.minecraft.component.type.FoodComponent; +import net.minecraft.entity.effect.StatusEffectInstance; +import net.pitan76.mcpitanlib.api.entity.effect.CompatStatusEffectInstance; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +public class CompatFoodComponent { + private int hunger; + private float saturation; + private boolean meat; + private boolean alwaysEdible; + private boolean snack; + private final List> statusEffects = new ArrayList<>(); + + private FoodComponent latestComponent = null; + + public static CompatFoodComponent create() { + return new CompatFoodComponent(); + } + + public CompatFoodComponent setHunger(int hunger) { + this.hunger = hunger; + return this; + } + + public CompatFoodComponent setSaturation(float saturation) { + this.saturation = saturation; + return this; + } + + public CompatFoodComponent setAlwaysEdible() { + this.alwaysEdible = true; + return this; + } + + public CompatFoodComponent setSnack() { + this.snack = true; + return this; + } + + public CompatFoodComponent setMeat() { + this.meat = true; + return this; + } + + @Deprecated + public CompatFoodComponent addStatusEffect(StatusEffectInstance effect, float chance) { + statusEffects.add(Pair.of(effect, chance)); + return this; + } + + public CompatFoodComponent addStatusEffect(CompatStatusEffectInstance instance, float chance) { + return addStatusEffect(instance.getInstance(), chance); + } + + public FoodComponent.Builder getVanillaBuilder() { + FoodComponent.Builder builder = new FoodComponent.Builder(); + builder.nutrition(hunger).saturationModifier(saturation); + if (alwaysEdible) builder.alwaysEdible(); + if (snack) builder.snack(); + //if (meat) builder.meat(); + for (Pair pair : statusEffects) { + builder.statusEffect(pair.getFirst(), pair.getSecond()); + } + return builder; + } + + public FoodComponent build() { + if (latestComponent != null) return latestComponent; + + float eatSeconds = 1.6f; + ImmutableList.Builder effects = ImmutableList.builder(); + effects.addAll(statusEffects.stream().map(pair -> new FoodComponent.StatusEffectEntry(pair.getFirst(), pair.getSecond())).iterator()); + if (snack) eatSeconds = 0.8f; + if (meat) eatSeconds = 1.6f; + + latestComponent = new FoodComponent(hunger, saturation, alwaysEdible, eatSeconds, Optional.empty(), effects.build()); + + return latestComponent; + } + + public FoodComponent vanillaBuild() { + if (latestComponent != null) return latestComponent; + + latestComponent = getVanillaBuilder().build(); + return latestComponent; + } + + // ---- + + public int getHunger() { + return hunger; + } + + public float getSaturation() { + return saturation; + } + + public boolean isMeat() { + return meat; + } + + public boolean isSnack() { + return snack; + } + + public boolean isAlwaysEdible() { + return alwaysEdible; + } + + @Deprecated + public List> getStatusEffects() { + return statusEffects; + } + + public List> getCompatStatusEffects() { + List> compatStatusEffects = new ArrayList<>(); + for (Pair pair : statusEffects) { + compatStatusEffects.add(Pair.of(new CompatStatusEffectInstance(pair.getFirst()), pair.getSecond())); + } + return compatStatusEffects; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/item/CompatItems.java b/common/src/main/java/net/pitan76/mcpitanlib/api/item/CompatItems.java new file mode 100644 index 000000000..d7c0e9958 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/CompatItems.java @@ -0,0 +1,69 @@ +package net.pitan76.mcpitanlib.api.item; + +import net.minecraft.item.Item; +import net.minecraft.item.Items; + +public class CompatItems { + public static Item SHORT_GRASS = Items.SHORT_GRASS; + public static Item TALL_GRASS = Items.TALL_GRASS; + public static Item TURTLE_SCUTE = Items.TURTLE_SCUTE; + + // Compatibility + public static Item GRASS = SHORT_GRASS; + public static Item SCUTE = TURTLE_SCUTE; + + // ---- + + public static Item AIR = Items.AIR; + public static Item STONE = Items.STONE; + public static Item COBBLESTONE = Items.COBBLESTONE; + public static Item GRASS_BLOCK = Items.GRASS_BLOCK; + public static Item DIRT = Items.DIRT; + public static Item SAND = Items.SAND; + public static Item RED_SAND = Items.RED_SAND; + public static Item GRANITE = Items.GRANITE; + public static Item POLISHED_GRANITE = Items.POLISHED_GRANITE; + public static Item DIORITE = Items.DIORITE; + public static Item POLISHED_DIORITE = Items.POLISHED_DIORITE; + public static Item ANDESITE = Items.ANDESITE; + public static Item POLISHED_ANDESITE = Items.POLISHED_ANDESITE; + public static Item COARSE_DIRT = Items.COARSE_DIRT; + public static Item PODZOL = Items.PODZOL; + public static Item OAK_LOG = Items.OAK_LOG; + public static Item SPRUCE_LOG = Items.SPRUCE_LOG; + public static Item BIRCH_LOG = Items.BIRCH_LOG; + public static Item JUNGLE_LOG = Items.JUNGLE_LOG; + public static Item ACACIA_LOG = Items.ACACIA_LOG; + public static Item DARK_OAK_LOG = Items.DARK_OAK_LOG; + public static Item OAK_PLANKS = Items.OAK_PLANKS; + public static Item SPRUCE_PLANKS = Items.SPRUCE_PLANKS; + public static Item BIRCH_PLANKS = Items.BIRCH_PLANKS; + public static Item JUNGLE_PLANKS = Items.JUNGLE_PLANKS; + public static Item ACACIA_PLANKS = Items.ACACIA_PLANKS; + public static Item DARK_OAK_PLANKS = Items.DARK_OAK_PLANKS; + public static Item GLASS = Items.GLASS; + + public static Item STICK = Items.STICK; + public static Item GLASS_BOTTLE = Items.GLASS_BOTTLE; + public static Item EXP_BOTTLE = Items.EXPERIENCE_BOTTLE; + + public static Item GUNPOWDER = Items.GUNPOWDER; + public static Item REDSTONE = Items.REDSTONE; + public static Item COAL = Items.COAL; + public static Item CHARCOAL = Items.CHARCOAL; + public static Item IRON_INGOT = Items.IRON_INGOT; + public static Item COPPER_INGOT = Items.COPPER_INGOT; + public static Item GOLD_INGOT = Items.GOLD_INGOT; + public static Item DIAMOND = Items.DIAMOND; + public static Item EMERALD = Items.EMERALD; + public static Item LAPIS_LAZULI = Items.LAPIS_LAZULI; + public static Item NETHERITE_INGOT = Items.NETHERITE_INGOT; + public static Item NETHERITE_SCRAP = Items.NETHERITE_SCRAP; + public static Item QUARTZ = Items.QUARTZ; + + // ---- + + public static boolean isExist(Item item) { + return item != null && item != Items.AIR; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/item/CompatibleArmorItem.java b/common/src/main/java/net/pitan76/mcpitanlib/api/item/CompatibleArmorItem.java new file mode 100644 index 000000000..adb91a906 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/CompatibleArmorItem.java @@ -0,0 +1,48 @@ +package net.pitan76.mcpitanlib.api.item; + +import net.minecraft.item.ArmorItem; +import net.minecraft.item.ArmorMaterial; +import net.minecraft.registry.entry.RegistryEntry; + +import java.util.Map; +import net.pitan76.mcpitanlib.api.item.v2.CompatItemProvider; +import net.pitan76.mcpitanlib.api.item.v2.CompatibleItemSettings; + +public class CompatibleArmorItem extends ArmorItem implements CompatItemProvider { + public final ArmorEquipmentType type; + public final CompatibleArmorMaterial material; + + @Deprecated + public static final Map> CACHE = new java.util.HashMap<>(); + + public CompatibleItemSettings settings; + + public CompatibleArmorItem(CompatibleArmorMaterial material, ArmorEquipmentType type, CompatibleItemSettings settings) { + super(material.build(), type.getType(), settings.build()); + this.type = type; + this.material = material; + + this.settings = settings; + } + + @Override + public CompatibleItemSettings getCompatSettings() { + return settings; + } + + /** + * get ArmorEquipmentType + * @return ArmorEquipmentType + */ + public ArmorEquipmentType getArmorEquipmentType() { + return type; + } + + /** + * get ArmorMaterial + * @return CompatibleArmorMaterial + */ + public CompatibleArmorMaterial getArmorMaterial() { + return material; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/item/CompatibleArmorMaterial.java b/common/src/main/java/net/pitan76/mcpitanlib/api/item/CompatibleArmorMaterial.java new file mode 100644 index 000000000..19bb91e67 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/CompatibleArmorMaterial.java @@ -0,0 +1,80 @@ +package net.pitan76.mcpitanlib.api.item; + +import net.minecraft.item.ArmorItem; +import net.minecraft.item.ArmorMaterial; +import net.minecraft.recipe.Ingredient; +import net.minecraft.registry.Registries; +import net.minecraft.registry.Registry; +import net.minecraft.registry.entry.RegistryEntry; +import net.minecraft.sound.SoundEvent; +import net.minecraft.sound.SoundEvents; +import net.minecraft.util.Identifier; +import net.minecraft.util.Util; + +import java.util.EnumMap; +import java.util.List; +import java.util.function.Supplier; + +public interface CompatibleArmorMaterial { + int getDurability(ArmorEquipmentType type); + + int getProtection(ArmorEquipmentType type); + + int getEnchantability(); + + SoundEvent getEquipSound(); + + Ingredient getRepairIngredient(); + + /** + * @return the name of the material + */ + default String getName() { + return getId().getPath(); + } + + /** + * @return the id of the material + */ + Identifier getId(); + + float getToughness(); + + float getKnockbackResistance(); + + @Deprecated + default RegistryEntry build() { + if (CompatibleArmorItem.CACHE.containsKey(this)) { + return CompatibleArmorItem.CACHE.get(this); + } + + RegistryEntry entry = register(getId(), Util.make(new EnumMap<>(ArmorItem.Type.class), (map) -> { + map.put(ArmorItem.Type.HELMET, this.getProtection(ArmorEquipmentType.HEAD)); + map.put(ArmorItem.Type.CHESTPLATE, this.getProtection(ArmorEquipmentType.CHEST)); + map.put(ArmorItem.Type.LEGGINGS, this.getProtection(ArmorEquipmentType.LEGS)); + map.put(ArmorItem.Type.BOOTS, this.getProtection(ArmorEquipmentType.FEET)); + + map.put(ArmorItem.Type.BODY, this.getProtection(ArmorEquipmentType.BODY)); + }), getEnchantability(), SoundEvents.ITEM_ARMOR_EQUIP_LEATHER, getToughness(), getKnockbackResistance(), + this::getRepairIngredient + ); + CompatibleArmorItem.CACHE.put(this, entry); + return entry; + } + + private static RegistryEntry register(Identifier id, EnumMap defense, int enchantability, RegistryEntry equipSound, float toughness, float knockbackResistance, Supplier repairIngredient) { + List list = List.of(new ArmorMaterial.Layer(id)); + return register(id, defense, enchantability, equipSound, toughness, knockbackResistance, repairIngredient, list); + } + + private static RegistryEntry register(Identifier id, EnumMap defense, int enchantability, RegistryEntry equipSound, float toughness, float knockbackResistance, Supplier repairIngredient, List layers) { + EnumMap enumMap = new EnumMap<>(ArmorItem.Type.class); + ArmorItem.Type[] var9 = ArmorItem.Type.values(); + + for (ArmorItem.Type type : var9) { + enumMap.put(type, defense.get(type)); + } + + return Registry.registerReference(Registries.ARMOR_MATERIAL, id, new ArmorMaterial(enumMap, enchantability, equipSound, repairIngredient, layers, toughness, knockbackResistance)); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/item/CompatibleItemSettings.java b/common/src/main/java/net/pitan76/mcpitanlib/api/item/CompatibleItemSettings.java new file mode 100644 index 000000000..6bdd9592a --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/CompatibleItemSettings.java @@ -0,0 +1,101 @@ +package net.pitan76.mcpitanlib.api.item; + +import dev.architectury.registry.registries.RegistrySupplier; +import net.minecraft.component.type.FoodComponent; +import net.minecraft.item.Item; +import net.minecraft.item.ItemGroup; +import net.minecraft.util.Identifier; +import net.minecraft.util.Rarity; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.core.registry.MCPLRegistry1_20; + +import java.util.function.Supplier; + +@Deprecated +public class CompatibleItemSettings { + protected final ExtendSettings settings = new ExtendSettings(); + + protected Identifier itemGroupId = null; + + @Deprecated + public static CompatibleItemSettings of() { + return new CompatibleItemSettings(); + } + + // ~1.19.2 + public CompatibleItemSettings addGroup(ItemGroup itemGroup) { + settings.addGroup(itemGroup); + return this; + } + + // 1.19.3~ + // identifier: Item ID + public CompatibleItemSettings addGroup(ItemGroup itemGroup, Identifier identifier) { + settings.addGroup(itemGroup, identifier); + return this; + } + + public CompatibleItemSettings addGroup(Supplier itemGroup, Identifier identifier) { + settings.addGroup(itemGroup, identifier); + return this; + } + + public CompatibleItemSettings addGroup(CreativeTabBuilder itemGroup) { + this.itemGroupId = itemGroup.getIdentifier(); + return this; + } + + public CompatibleItemSettings maxCount(int maxCount) { + settings.maxCount(maxCount); + return this; + } + + public CompatibleItemSettings maxDamage(int maxDamage) { + settings.maxDamage(maxDamage); + return this; + } + + public CompatibleItemSettings maxDamageIfAbsent(int maxDamage) { + try { + settings.maxDamage(maxDamage); + } catch (Exception ignored) {} + + return this; + } + + @Deprecated + public CompatibleItemSettings food(FoodComponent foodComponent) { + settings.food(foodComponent); + return this; + } + + public CompatibleItemSettings rarity(Rarity rarity) { + settings.rarity(rarity); + return this; + } + + public CompatibleItemSettings recipeRemainder(Item recipeRemainder) { + settings.recipeRemainder(recipeRemainder); + return this; + } + + public ExtendSettings build() { + if (itemGroupId != null) { + RegistrySupplier itemGroup = MCPLRegistry1_20.REGISTRY_SUPPLIER_ITEM_GROUP_CACHE.get(itemGroupId); + settings.arch$tab(itemGroup); + } + return settings; + } + + public CompatibleItemSettings addGroup(ItemGroup itemGroup, CompatIdentifier identifier) { + return addGroup(itemGroup, identifier.toMinecraft()); + } + + public CompatibleItemSettings addGroup(Supplier itemGroup, CompatIdentifier identifier) { + return addGroup(itemGroup, identifier.toMinecraft()); + } + + public CompatibleItemSettings food(CompatFoodComponent foodComponent) { + return food(foodComponent.build()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/item/CreativeTabBuilder.java b/common/src/main/java/net/pitan76/mcpitanlib/api/item/CreativeTabBuilder.java new file mode 100644 index 000000000..fc7e9851a --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/CreativeTabBuilder.java @@ -0,0 +1,112 @@ +package net.pitan76.mcpitanlib.api.item; + +import dev.architectury.registry.CreativeTabRegistry; +import net.minecraft.item.Item; +import net.minecraft.item.ItemGroup; +import net.minecraft.item.ItemStack; +import net.minecraft.text.Text; +import net.minecraft.util.Identifier; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.api.util.IdentifierUtil; +import net.pitan76.mcpitanlib.api.util.TextUtil; +import net.pitan76.mcpitanlib.core.registry.MCPLRegistry1_20; +import net.pitan76.mcpitanlib.midohra.item.ItemGroupWrapper; + +import java.util.function.Supplier; + +public class CreativeTabBuilder { + private final Identifier identifier; + private Text displayName = null; + private Supplier iconSupplier = null; + private boolean noRenderedName = false; + private boolean noScrollbar = false; + private boolean special = false; + private String texture; + + @Deprecated + // Recommend: create(identifier) + public CreativeTabBuilder(Identifier identifier) { + this.identifier = identifier; + } + + public static CreativeTabBuilder create(Identifier identifier) { + return new CreativeTabBuilder(identifier); + } + + public static CreativeTabBuilder create(CompatIdentifier identifier) { + return create(identifier.toMinecraft()); + } + + public CreativeTabBuilder setDisplayName(Text text) { + this.displayName = text; + return this; + } + + /** + * Set icon + * @param iconSupplier Icon supplier + * @return CreativeTabBuilder + */ + public CreativeTabBuilder setIcon(Supplier iconSupplier) { + this.iconSupplier = iconSupplier; + return this; + } + + /** + * Set icon (Already registered item only) + * @param item Item + * @return CreativeTabBuilder + */ + public CreativeTabBuilder setIcon(Item item) { + return setIcon(() -> new ItemStack(item)); + } + + public void noRenderedName() { + this.noRenderedName = true; + } + + public void noScrollbar() { + this.noScrollbar = true; + } + + public void special() { + this.special = true; + } + + public void setTexture(String texture) { + this.texture = texture; + } + + /** + * Build ItemGroup (If loader is forge, not recommended) + * @return ItemGroup + */ + public ItemGroup build() { + return CreativeTabRegistry.create((builder -> { + if (displayName != null) builder.displayName(displayName); + else builder.displayName(TextUtil.translatable("itemGroup." + identifier.getNamespace() + "." + identifier.getPath())); + + if (iconSupplier != null) builder.icon(iconSupplier); + if (noRenderedName) builder.noRenderedName(); + if (noScrollbar) builder.noScrollbar(); + if (special) builder.special(); + if (texture != null) builder.texture(IdentifierUtil.id(texture)); + })); + } + + @SuppressWarnings("deprecation") + public ItemGroupWrapper getBuiltWrapper() { + if (MCPLRegistry1_20.REGISTRY_SUPPLIER_ITEM_GROUP_CACHE.containsKey(identifier)) + return ItemGroupWrapper.of(MCPLRegistry1_20.REGISTRY_SUPPLIER_ITEM_GROUP_CACHE.get(identifier).getOrNull()); + + return ItemGroupWrapper.of(build()); + } + + public Identifier getIdentifier() { + return identifier; + } + + public CompatIdentifier getCompatIdentifier() { + return CompatIdentifier.fromMinecraft(identifier); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/item/CreativeTabManager.java b/common/src/main/java/net/pitan76/mcpitanlib/api/item/CreativeTabManager.java new file mode 100644 index 000000000..b8de65096 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/CreativeTabManager.java @@ -0,0 +1,112 @@ +package net.pitan76.mcpitanlib.api.item; + +import dev.architectury.registry.CreativeTabRegistry; +import net.minecraft.item.ItemGroup; +import net.minecraft.item.ItemStack; +import net.minecraft.util.Identifier; +import net.pitan76.mcpitanlib.api.util.ItemUtil; + +import java.util.ArrayList; +import java.util.List; +import java.util.function.Supplier; + +public class CreativeTabManager { + private static List bookingItems = new ArrayList<>(); + private static List bookingStacks = new ArrayList<>(); + + // グループ予約済みアイテム + public static class BookingItem { + @Deprecated + public ItemGroup itemGroup; + + public Supplier itemGroupSupplier; + public Identifier identifier; + + @Deprecated + private BookingItem(ItemGroup itemGroup, Identifier identifier) { + this.itemGroup = itemGroup; + this.identifier = identifier; + } + + private BookingItem(Supplier itemGroup, Identifier identifier) { + this.itemGroupSupplier = itemGroup; + this.identifier = identifier; + } + + public ItemGroup getItemGroup() { + if (itemGroupSupplier != null) + return itemGroupSupplier.get(); + return itemGroup; + } + } + + // グループ予約済みアイテムスタック + public static class BookingStack { + @Deprecated + public ItemGroup itemGroup; + + public Supplier itemGroupSupplier; + public ItemStack stack; + + @Deprecated + private BookingStack(ItemGroup itemGroup, ItemStack stack) { + this.itemGroup = itemGroup; + this.stack = stack; + } + + private BookingStack(Supplier itemGroup, ItemStack stack) { + this.itemGroupSupplier = itemGroup; + this.stack = stack; + } + + public ItemGroup getItemGroup() { + if (itemGroupSupplier != null) + return itemGroupSupplier.get(); + return itemGroup; + } + } + + public static void allRegister() { + if (!bookingItems.isEmpty()) { + for (BookingItem bookingItem : bookingItems) { + CreativeTabRegistry.appendBuiltin(bookingItem.getItemGroup(), ItemUtil.fromId(bookingItem.identifier)); + } + bookingItems = new ArrayList<>(); + } + + if (!bookingStacks.isEmpty()) { + for (BookingStack bookingStack : bookingStacks) { + CreativeTabRegistry.appendBuiltinStack(bookingStack.getItemGroup(), bookingStack.stack); + } + bookingStacks = new ArrayList<>(); + } + } + + public static void register(Identifier identifier) { + if (bookingItems.isEmpty()) return; + for (BookingItem bookingItem : bookingItems) { + if (!bookingItem.identifier.toString().equals(identifier.toString())) continue; + CreativeTabRegistry.appendBuiltin(bookingItem.getItemGroup(), ItemUtil.fromId(bookingItem.identifier)); + bookingItems.remove(bookingItem); + break; + } + } + + @Deprecated + public static void addItem(ItemGroup itemGroup, Identifier identifier) { + bookingItems.add(new BookingItem(itemGroup, identifier)); + } + + @Deprecated + public static void addStack(ItemGroup itemGroup, ItemStack stack) { + bookingStacks.add(new BookingStack(itemGroup, stack)); + } + + public static void addItem(Supplier itemGroup, Identifier identifier) { + bookingItems.add(new BookingItem(itemGroup, identifier)); + } + + public static void addStack(Supplier itemGroup, ItemStack stack) { + bookingStacks.add(new BookingStack(itemGroup, stack)); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/item/DefaultItemGroups.java b/common/src/main/java/net/pitan76/mcpitanlib/api/item/DefaultItemGroups.java new file mode 100644 index 000000000..b5d5f17ce --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/DefaultItemGroups.java @@ -0,0 +1,28 @@ +package net.pitan76.mcpitanlib.api.item; + +import net.minecraft.item.ItemGroup; +import net.minecraft.item.ItemGroups; +import net.minecraft.registry.Registries; + +public class DefaultItemGroups { + public static final ItemGroup BUILDING_BLOCKS = Registries.ITEM_GROUP.get(ItemGroups.BUILDING_BLOCKS); + public static final ItemGroup COLORED_BLOCKS = Registries.ITEM_GROUP.get(ItemGroups.COLORED_BLOCKS); // if 1.19.2 and below, BUILDING_BLOCKS + public static final ItemGroup NATURAL = Registries.ITEM_GROUP.get(ItemGroups.NATURAL); // if 1.19.2 and below, DECORATIONS + public static final ItemGroup FUNCTIONAL = Registries.ITEM_GROUP.get(ItemGroups.FUNCTIONAL); // if 1.19.2 and below, TRANSPORTATION + public static final ItemGroup REDSTONE = Registries.ITEM_GROUP.get(ItemGroups.REDSTONE); + public static final ItemGroup HOTBAR = Registries.ITEM_GROUP.get(ItemGroups.HOTBAR); + public static final ItemGroup SEARCH = Registries.ITEM_GROUP.get(ItemGroups.SEARCH); + public static final ItemGroup TOOLS = Registries.ITEM_GROUP.get(ItemGroups.TOOLS); + public static final ItemGroup COMBAT = Registries.ITEM_GROUP.get(ItemGroups.COMBAT); + public static final ItemGroup FOOD_AND_DRINK = Registries.ITEM_GROUP.get(ItemGroups.FOOD_AND_DRINK); // if 1.19.2 and below, FOOD + public static final ItemGroup INGREDIENTS = Registries.ITEM_GROUP.get(ItemGroups.INGREDIENTS); // if 1.19.2 and below, MISC + public static final ItemGroup SPAWN_EGGS = Registries.ITEM_GROUP.get(ItemGroups.SPAWN_EGGS); // if 1.19.2 and below, MISC + public static final ItemGroup OPERATOR = Registries.ITEM_GROUP.get(ItemGroups.OPERATOR); // if 1.19.2 and below, MISC + public static final ItemGroup INVENTORY = Registries.ITEM_GROUP.get(ItemGroups.INVENTORY); + + // ~1.19.2 Item Group + public static final ItemGroup BREWING = FOOD_AND_DRINK; + public static final ItemGroup TRANSPORTATION = FUNCTIONAL; + public static final ItemGroup DECORATIONS = NATURAL; + public static final ItemGroup MISC = INGREDIENTS; +} \ No newline at end of file diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/item/ExtendBlockItem.java b/common/src/main/java/net/pitan76/mcpitanlib/api/item/ExtendBlockItem.java new file mode 100644 index 000000000..226e8ed29 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/ExtendBlockItem.java @@ -0,0 +1,137 @@ +package net.pitan76.mcpitanlib.api.item; + +import net.minecraft.block.Block; +import net.minecraft.item.tooltip.TooltipType; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.BlockItem; +import net.minecraft.item.ItemStack; +import net.minecraft.item.ItemUsageContext; +import net.minecraft.text.Text; +import net.minecraft.util.ActionResult; +import net.minecraft.util.Hand; +import net.minecraft.util.TypedActionResult; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.event.item.*; +import net.pitan76.mcpitanlib.api.util.CompatActionResult; +import net.pitan76.mcpitanlib.api.util.StackActionResult; +import net.pitan76.mcpitanlib.core.Dummy; +import net.pitan76.mcpitanlib.mixin.ItemUsageContextMixin; + +import java.util.List; + +public class ExtendBlockItem extends BlockItem implements ExtendItemProvider { + + public ExtendBlockItem(Block block, Settings settings) { + super(block, settings); + } + + public ExtendBlockItem(Block block, CompatibleItemSettings settings) { + super(block, settings.build()); + } + + // ExtendItem + @Deprecated + @Override + public TypedActionResult use(World world, PlayerEntity user, Hand hand) { + return onRightClick(new ItemUseEvent(world, user, hand)).toTypedActionResult(); + } + + @Deprecated + @Override + public ActionResult useOnBlock(ItemUsageContext context) { + ItemUsageContextMixin contextAccessor = (ItemUsageContextMixin) context; + return onRightClickOnBlock(new ItemUseOnBlockEvent(context.getPlayer(), context.getHand(), contextAccessor.getHit())).toActionResult(); + } + + @Deprecated + @Override + public ItemStack finishUsing(ItemStack stack, World world, LivingEntity user) { + return onFinishUsing(new ItemFinishUsingEvent(stack, world, user)); + } + + @Deprecated + @Override + public ActionResult useOnEntity(ItemStack stack, PlayerEntity user, LivingEntity entity, Hand hand) { + return onRightClickOnEntity(new ItemUseOnEntityEvent(stack, user, entity, hand)).toActionResult(); + } + + @Deprecated + public boolean hasRecipeRemainder() { + return hasRecipeRemainder(new Dummy()); + } + + @Deprecated + @Override + public void appendTooltip(ItemStack stack, TooltipContext context, List tooltip, TooltipType type) { + appendTooltip(new ItemAppendTooltipEvent(stack, null, tooltip, type, context)); + } + + @Deprecated + @Override + public void onCraft(ItemStack stack, World world) { + onCraft(new CraftEvent(stack, world)); + } + + /** + * item right click event + * + * @param event ItemUseEvent + * @return ActionResultType + */ + public StackActionResult onRightClick(ItemUseEvent event) { + return StackActionResult.create(super.use(event.world, event.user.getPlayerEntity(), event.hand)); + } + + /** + * item right click event on block + * @param event ItemUseOnBlockEvent + * @return ActionResultType + */ + public CompatActionResult onRightClickOnBlock(ItemUseOnBlockEvent event) { + return CompatActionResult.create(super.useOnBlock(event.toIUC())); + } + + /** + * item finish using event + * @param event ItemFinishUsingEvent + * @return ItemStack + */ + public ItemStack onFinishUsing(ItemFinishUsingEvent event) { + return super.finishUsing(event.stack, event.world, event.user); + } + + /** + * item right click event on entity + * @param event ItemUseOnEntityEvent + * @return ActionResultType + */ + public CompatActionResult onRightClickOnEntity(ItemUseOnEntityEvent event) { + return CompatActionResult.create(super.useOnEntity(event.stack, event.user.getEntity(), event.entity, event.hand)); + } + + /** + * check if item has recipe remainder + * @param dummy Dummy + * @return boolean + */ + public boolean hasRecipeRemainder(Dummy dummy) { + return false; + } + + /** + * append tooltip to item + * @param event ItemAppendTooltipEvent + */ + public void appendTooltip(ItemAppendTooltipEvent event) { + super.appendTooltip(event.stack, event.context, event.tooltip, event.type); + } + + /** + * on craft event + * @param event CraftEvent + */ + public void onCraft(CraftEvent event) { + super.onCraft(event.stack, event.world); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/item/ExtendItem.java b/common/src/main/java/net/pitan76/mcpitanlib/api/item/ExtendItem.java new file mode 100644 index 000000000..28b8af8e0 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/ExtendItem.java @@ -0,0 +1,258 @@ +package net.pitan76.mcpitanlib.api.item; + +import net.minecraft.block.BlockState; +import net.minecraft.entity.Entity; +import net.minecraft.entity.damage.DamageSource; +import net.minecraft.item.tooltip.TooltipType; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.item.ItemUsageContext; +import net.minecraft.text.Text; +import net.minecraft.util.*; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.event.item.*; +import net.pitan76.mcpitanlib.api.util.CompatActionResult; +import net.pitan76.mcpitanlib.api.util.StackActionResult; +import net.pitan76.mcpitanlib.core.Dummy; +import net.pitan76.mcpitanlib.mixin.ItemUsageContextMixin; + +import java.util.List; + +public class ExtendItem extends Item { + + public ExtendItem(Settings settings) { + super(settings); + } + + public ExtendItem(CompatibleItemSettings settings) { + super(settings.build()); + } + + @Deprecated + @Override + public TypedActionResult use(World world, PlayerEntity user, Hand hand) { + return onRightClick(new ItemUseEvent(world, user, hand)).toTypedActionResult(); + } + + @Deprecated + @Override + public ActionResult useOnBlock(ItemUsageContext context) { + ItemUsageContextMixin contextAccessor = (ItemUsageContextMixin) context; + return onRightClickOnBlock(new ItemUseOnBlockEvent(context.getPlayer(), context.getHand(), contextAccessor.getHit())).toActionResult(); + } + + @Deprecated + @Override + public ItemStack finishUsing(ItemStack stack, World world, LivingEntity user) { + return onFinishUsing(new ItemFinishUsingEvent(stack, world, user)); + } + + @Deprecated + @Override + public ActionResult useOnEntity(ItemStack stack, PlayerEntity user, LivingEntity entity, Hand hand) { + return onRightClickOnEntity(new ItemUseOnEntityEvent(stack, user, entity, hand)).toActionResult(); + } + + @Override + public UseAction getUseAction(ItemStack stack) { + return super.getUseAction(stack); + } + + @Deprecated + @Override + public boolean hasRecipeRemainder() { + return hasRecipeRemainder(new Dummy()); + } + + @Deprecated + @Override + public void appendTooltip(ItemStack stack, TooltipContext context, List tooltip, TooltipType type) { + appendTooltip(new ItemAppendTooltipEvent(stack, null, tooltip, type, context)); + } + + @Deprecated + @Override + public void onCraft(ItemStack stack, World world) { + onCraft(new CraftEvent(stack, world)); + } + + @Deprecated + @Override + public boolean postHit(ItemStack stack, LivingEntity target, LivingEntity attacker) { + return postHit(new PostHitEvent(stack, target, attacker)); + } + + @Deprecated + @Override + public boolean postMine(ItemStack stack, World world, BlockState state, BlockPos pos, LivingEntity miner) { + return postMine(new PostMineEvent(stack, world, state, pos, miner)); + } + + /** + * item right click event + * + * @param event ItemUseEvent + * @return ActionResultType + */ + public StackActionResult onRightClick(ItemUseEvent event) { + return StackActionResult.create(CompatActionResult.create(super.use(event.world, event.user.getPlayerEntity(), event.hand).getResult()), event.stack); + } + + /** + * item right click event on block + * @param event ItemUseOnBlockEvent + * @return ActionResultType + */ + public CompatActionResult onRightClickOnBlock(ItemUseOnBlockEvent event) { + return CompatActionResult.create(super.useOnBlock(event.toIUC())); + } + + /** + * item finish using event + * @param event ItemFinishUsingEvent + * @return ItemStack + */ + public ItemStack onFinishUsing(ItemFinishUsingEvent event) { + return super.finishUsing(event.stack, event.world, event.user); + } + + /** + * item right click event on entity + * @param event ItemUseOnEntityEvent + * @return ActionResultType + */ + public CompatActionResult onRightClickOnEntity(ItemUseOnEntityEvent event) { + return CompatActionResult.create(super.useOnEntity(event.stack, event.user.getEntity(), event.entity, event.hand)); + } + + /** + * check if item has recipe remainder + * @param dummy Dummy + * @return boolean + */ + public boolean hasRecipeRemainder(Dummy dummy) { + return false; + } + + /** + * append tooltip to item + * @param event ItemAppendTooltipEvent + */ + public void appendTooltip(ItemAppendTooltipEvent event) { + super.appendTooltip(event.stack, event.context, event.tooltip, event.type); + } + + /** + * on craft event + * @param event CraftEvent + */ + public void onCraft(CraftEvent event) { + super.onCraft(event.stack, event.world); + } + + /** + * post hit event + * @param event PostHitEvent + * @return boolean + */ + public boolean postHit(PostHitEvent event) { + return super.postHit(event.stack, event.target, event.attacker); + } + + /** + * post mine event + * @param event PostMineEvent + * @return boolean + */ + public boolean postMine(PostMineEvent event) { + return super.postMine(event.stack, event.world, event.state, event.pos, event.miner); + } + + // -1.20.6 + public Rarity getRarity(ItemStack stack) { + return Rarity.COMMON; + } + + @Deprecated + @Override + public boolean isEnchantable(ItemStack stack) { + return isEnchantable(new EnchantableArgs(stack)); + } + + public boolean isEnchantable(EnchantableArgs args) { + return false; + } + + @Deprecated + @Override + public int getEnchantability() { + return getEnchantability(new EnchantabilityArgs()); + } + + public int getEnchantability(EnchantabilityArgs args) { + return 0; + } + + @Deprecated + @Override + public int getItemBarColor(ItemStack stack) { + return getItemBarColor(new ItemBarColorArgs(stack)); + } + + public int getItemBarColor(ItemBarColorArgs args) { + return super.getItemBarColor(args.stack); + } + + @Deprecated + @Override + public boolean isItemBarVisible(ItemStack stack) { + return isItemBarVisible(new ItemBarVisibleArgs(stack)); + } + + public boolean isItemBarVisible(ItemBarVisibleArgs args) { + return super.isItemBarVisible(args.stack); + } + + @Deprecated + @Override + public int getItemBarStep(ItemStack stack) { + return getItemBarStep(new ItemBarStepArgs(stack)); + } + + public int getItemBarStep(ItemBarStepArgs args) { + return super.getItemBarStep(args.stack); + } + + @Deprecated + @Override + public float getBonusAttackDamage(Entity target, float baseAttackDamage, DamageSource damageSource) { + return getBonusAttackDamage(new BonusAttackDamageArgs(target, baseAttackDamage, damageSource)); + } + + public float getBonusAttackDamage(BonusAttackDamageArgs args) { + return super.getBonusAttackDamage(args.target, args.baseAttackDamage, args.damageSource); + } + + @Deprecated + @Override + public boolean canRepair(ItemStack stack, ItemStack ingredient) { + return canRepair(new CanRepairArgs(stack, ingredient)); + } + + public boolean canRepair(CanRepairArgs args) { + return super.canRepair(args.stack, args.ingredient); + } + + @Deprecated + @Override + public boolean canMine(BlockState state, World world, BlockPos pos, PlayerEntity miner) { + return canMine(new CanMineArgs(state, world, pos, miner)); + } + + public boolean canMine(CanMineArgs args) { + return super.canMine(args.state, args.world, args.pos, args.miner.getEntity()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/item/ExtendItemProvider.java b/common/src/main/java/net/pitan76/mcpitanlib/api/item/ExtendItemProvider.java new file mode 100644 index 000000000..7742fa05e --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/ExtendItemProvider.java @@ -0,0 +1,136 @@ +package net.pitan76.mcpitanlib.api.item; + +import net.minecraft.item.ItemStack; +import net.minecraft.util.Rarity; +import net.pitan76.mcpitanlib.api.event.item.*; +import net.pitan76.mcpitanlib.api.util.CompatActionResult; +import net.pitan76.mcpitanlib.api.util.StackActionResult; + +public interface ExtendItemProvider { + + /** + * item right click event + * + * @param event ItemUseEvent + * @return ActionResultType + */ + default StackActionResult onRightClick(ItemUseEvent event, Options options) { + options.cancel = false; + return null; + } + + /** + * item right click event on block + * @param event ItemUseOnBlockEvent + * @return ActionResultType + */ + default CompatActionResult onRightClickOnBlock(ItemUseOnBlockEvent event, Options options) { + options.cancel = false; + return null; + } + + /** + * using finish with item + * @param event ItemFinishUsingEvent + * @return ItemStack + */ + default ItemStack onFinishUsing(ItemFinishUsingEvent event, Options options) { + options.cancel = false; + return null; + } + + /** + * on click with item on entity + * @param event ItemUseOnEntityEvent + * @return ActionResult + */ + default CompatActionResult onRightClickOnEntity(ItemUseOnEntityEvent event, Options options) { + options.cancel = false; + return null; + } + + /** + * item has recipe remainder + * @param options Options + * @return boolean + */ + default boolean hasRecipeRemainder(Options options) { + options.cancel = false; + return false; + } + + /** + * add tooltip + * @param event ItemAppendTooltipEvent + */ + default void appendTooltip(ItemAppendTooltipEvent event, Options options) { + options.cancel = false; + } + + /** + * post hit event + * @param event PostHitEvent + * @return boolean + */ + default boolean postHit(PostHitEvent event, Options options) { + options.cancel = false; + return false; + } + + /** + * post mine event + * @param event PostMineEvent + * @return boolean + */ + default boolean postMine(PostMineEvent event, Options options) { + options.cancel = false; + return false; + } + + /** + * on craft event + * @param event CraftEvent + */ + default void onCraft(CraftEvent event, Options options) { + options.cancel = false; + } + + default Rarity getRarity(ItemStack stack, Options options) { + options.cancel = false; + return null; + } + + default boolean isEnchantable(EnchantableArgs args, Options options) { + options.cancel = false; + return false; + } + + default int getEnchantability(EnchantabilityArgs args, Options options) { + options.cancel = false; + return 0; + } + + default int getItemBarColor(ItemBarColorArgs args, Options options) { + options.cancel = false; + return 0; + } + + default boolean isItemBarVisible(ItemBarVisibleArgs args, Options options) { + options.cancel = false; + return false; + } + + default int getItemBarStep(ItemBarStepArgs args, Options options) { + options.cancel = false; + return 0; + } + + default float getBonusAttackDamage(BonusAttackDamageArgs args, Options options) { + options.cancel = false; + return 0; + } + + public static class Options { + public boolean cancel = true; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/item/ExtendSettings.java b/common/src/main/java/net/pitan76/mcpitanlib/api/item/ExtendSettings.java new file mode 100644 index 000000000..bbf502359 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/ExtendSettings.java @@ -0,0 +1,34 @@ +package net.pitan76.mcpitanlib.api.item; + +import net.minecraft.item.Item; +import net.minecraft.item.ItemGroup; +import net.minecraft.util.Identifier; + +import java.util.function.Supplier; + +/** + * Use {@link CompatibleItemSettings} instead. + */ +public class ExtendSettings extends Item.Settings { + + // ~1.19.2 + @Deprecated + public ExtendSettings addGroup(ItemGroup itemGroup) { + return this; + } + + // 1.19.3~ + // identifier: Item ID + @Deprecated + public ExtendSettings addGroup(ItemGroup itemGroup, Identifier identifier) { + this.arch$tab(itemGroup); + CreativeTabManager.addItem(itemGroup, identifier); + return this; + } + + @Deprecated + public ExtendSettings addGroup(Supplier itemGroup, Identifier identifier) { + CreativeTabManager.addItem(itemGroup, identifier); + return this; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/item/FixedRecipeRemainderItem.java b/common/src/main/java/net/pitan76/mcpitanlib/api/item/FixedRecipeRemainderItem.java new file mode 100644 index 000000000..c96382ed2 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/FixedRecipeRemainderItem.java @@ -0,0 +1,7 @@ +package net.pitan76.mcpitanlib.api.item; + +import net.minecraft.item.ItemStack; + +public interface FixedRecipeRemainderItem { + ItemStack getFixedRecipeRemainder(ItemStack stack); +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/item/FoodItem.java b/common/src/main/java/net/pitan76/mcpitanlib/api/item/FoodItem.java new file mode 100644 index 000000000..a188233b2 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/FoodItem.java @@ -0,0 +1,28 @@ +package net.pitan76.mcpitanlib.api.item; + +import net.pitan76.mcpitanlib.api.item.v2.CompatItem; +import net.pitan76.mcpitanlib.api.item.v2.CompatibleItemSettings; +import net.pitan76.mcpitanlib.api.item.v2.ItemSettingsBuilder; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; + +public class FoodItem extends CompatItem { + public FoodItem(int hunger, float saturation, CompatIdentifier id) { + this(new ItemSettingsBuilder().foodComponent(CompatFoodComponent.create().setHunger(hunger).setSaturation(saturation)).build(id)); + } + + public FoodItem(CompatFoodComponent component, CompatIdentifier id) { + this(new ItemSettingsBuilder().foodComponent(component).build(id)); + } + + public FoodItem(CompatFoodComponent component, ItemSettingsBuilder builder, CompatIdentifier id) { + this(builder.foodComponent(component).build(id)); + } + + public FoodItem(CompatFoodComponent component, CompatibleItemSettings settings) { + this(settings.food(component)); + } + + public FoodItem(CompatibleItemSettings settings) { + super(settings); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/item/args/RarityArgs.java b/common/src/main/java/net/pitan76/mcpitanlib/api/item/args/RarityArgs.java new file mode 100644 index 000000000..6db9d79f4 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/args/RarityArgs.java @@ -0,0 +1,19 @@ +package net.pitan76.mcpitanlib.api.item.args; + +import net.minecraft.item.ItemStack; + +public class RarityArgs { + public ItemStack stack; + + public RarityArgs(ItemStack stack) { + this.stack = stack; + } + + public ItemStack getStack() { + return stack; + } + + public net.pitan76.mcpitanlib.midohra.item.ItemStack getMidohraStack() { + return net.pitan76.mcpitanlib.midohra.item.ItemStack.of(stack); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/item/args/StoppedUsingArgs.java b/common/src/main/java/net/pitan76/mcpitanlib/api/item/args/StoppedUsingArgs.java new file mode 100644 index 000000000..e7c9e8446 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/args/StoppedUsingArgs.java @@ -0,0 +1,80 @@ +package net.pitan76.mcpitanlib.api.item.args; + +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.entity.Player; + +import java.util.Optional; + +public class StoppedUsingArgs { + + public ItemStack stack; + public World world; + public LivingEntity user; + public int remainingUseTicks; + + public StoppedUsingArgs(ItemStack stack, World world, LivingEntity user, int remainingUseTicks) { + this.stack = stack; + this.world = world; + this.user = user; + this.remainingUseTicks = remainingUseTicks; + } + + public StoppedUsingArgs(ItemStack stack, World world, LivingEntity user) { + this(stack, world, user, 0); + } + + public StoppedUsingArgs(ItemStack stack, World world, Player player, int remainingUseTicks) { + this(stack, world, player.getEntity(), remainingUseTicks); + } + + public StoppedUsingArgs(ItemStack stack, World world, Player player) { + this(stack, world, player, 0); + } + + public ItemStack getStack() { + return stack; + } + + public net.pitan76.mcpitanlib.midohra.item.ItemStack getMidohraStack() { + return net.pitan76.mcpitanlib.midohra.item.ItemStack.of(stack); + } + + public World getWorld() { + return world; + } + + public LivingEntity getUser() { + return user; + } + + public int getRemainingUseTicks() { + return remainingUseTicks; + } + + public boolean hasRemainingUseTicks() { + return remainingUseTicks > 0; + } + + public boolean hasNoRemainingUseTicks() { + return !hasRemainingUseTicks(); + } + + public boolean isClient() { + return world.isClient(); + } + + public boolean isServer() { + return !isClient(); + } + + public boolean isPlayer() { + return user instanceof PlayerEntity; + } + + public Optional getPlayer() { + return isPlayer() ? Optional.of(new Player((PlayerEntity) user)) : Optional.empty(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/item/args/UseActionArgs.java b/common/src/main/java/net/pitan76/mcpitanlib/api/item/args/UseActionArgs.java new file mode 100644 index 000000000..acdbd404d --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/args/UseActionArgs.java @@ -0,0 +1,27 @@ +package net.pitan76.mcpitanlib.api.item.args; + +import net.minecraft.item.ItemStack; + +public class UseActionArgs { + public ItemStack stack; + + public UseActionArgs(ItemStack stack) { + this.stack = stack; + } + + public static UseActionArgs of(ItemStack stack) { + return new UseActionArgs(stack); + } + + public static UseActionArgs of(net.pitan76.mcpitanlib.midohra.item.ItemStack stack) { + return of(stack.toMinecraft()); + } + + public ItemStack getStack() { + return stack; + } + + public net.pitan76.mcpitanlib.midohra.item.ItemStack getMidohraStack() { + return net.pitan76.mcpitanlib.midohra.item.ItemStack.of(stack); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/item/consume/CompatUseAction.java b/common/src/main/java/net/pitan76/mcpitanlib/api/item/consume/CompatUseAction.java new file mode 100644 index 000000000..66aed1404 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/consume/CompatUseAction.java @@ -0,0 +1,45 @@ +package net.pitan76.mcpitanlib.api.item.consume; + +import net.minecraft.util.UseAction; +import net.pitan76.mcpitanlib.api.util.CompatStringIdentifiable; + +public class CompatUseAction implements CompatStringIdentifiable { + private final UseAction useAction; + + public static final CompatUseAction NONE = of(UseAction.NONE); + public static final CompatUseAction EAT = of(UseAction.EAT); + public static final CompatUseAction DRINK = of(UseAction.DRINK); + public static final CompatUseAction BLOCK = of(UseAction.BLOCK); + public static final CompatUseAction BOW = of(UseAction.BOW); + public static final CompatUseAction SPEAR = of(UseAction.SPEAR); + public static final CompatUseAction CROSSBOW = of(UseAction.CROSSBOW); + public static final CompatUseAction SPYGLASS = of(UseAction.SPYGLASS); + public static final CompatUseAction TOOT_HORN = of(UseAction.TOOT_HORN); + public static final CompatUseAction BRUSH = of(UseAction.BRUSH); + + public CompatUseAction(UseAction useAction) { + this.useAction = useAction; + } + + public static CompatUseAction of(UseAction useAction) { + return new CompatUseAction(useAction); + } + + @Deprecated + public UseAction getUseAction() { + return useAction; + } + + public int getId() { + return -1; + } + + public String getName() { + return useAction.name(); + } + + @Override + public String asString_compat() { + return getName(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/item/equipment/CompatEquipmentAsset.java b/common/src/main/java/net/pitan76/mcpitanlib/api/item/equipment/CompatEquipmentAsset.java new file mode 100644 index 000000000..a61c24184 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/equipment/CompatEquipmentAsset.java @@ -0,0 +1,28 @@ +package net.pitan76.mcpitanlib.api.item.equipment; + +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; + +public class CompatEquipmentAsset { + + @Deprecated + public CompatEquipmentAsset() { + + } + + public CompatIdentifier getId() { + return CompatIdentifier.empty(); + } + + @Deprecated + public static CompatEquipmentAsset of() { + return new CompatEquipmentAsset(); + } + + public static CompatEquipmentAsset of(CompatIdentifier id) { + return of(); + } + + public static CompatEquipmentAsset of(String id) { + return of(CompatIdentifier.of(id)); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/item/equipment/CompatEquippableComponent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/item/equipment/CompatEquippableComponent.java new file mode 100644 index 000000000..c5cae0c54 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/equipment/CompatEquippableComponent.java @@ -0,0 +1,9 @@ +package net.pitan76.mcpitanlib.api.item.equipment; + +public class CompatEquippableComponent { + + @Deprecated + public CompatEquippableComponent() { + + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/item/equipment/EquippableComponentBuilder.java b/common/src/main/java/net/pitan76/mcpitanlib/api/item/equipment/EquippableComponentBuilder.java new file mode 100644 index 000000000..7f7f82771 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/equipment/EquippableComponentBuilder.java @@ -0,0 +1,76 @@ +package net.pitan76.mcpitanlib.api.item.equipment; + +import net.pitan76.mcpitanlib.api.item.ArmorEquipmentType; +import net.pitan76.mcpitanlib.api.sound.CompatSoundEvent; +import net.pitan76.mcpitanlib.api.tag.TagKey; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; + +public class EquippableComponentBuilder { + + public ArmorEquipmentType equipmentType; + public CompatSoundEvent equipSound; + public CompatSoundEvent shearingSound; + public boolean equipOnInteract = false; + public boolean canBeSheared = false; + public CompatEquipmentAsset model; + public TagKey allowedEntities = null; + + public EquippableComponentBuilder() { + + } + + public EquippableComponentBuilder(ArmorEquipmentType equipmentType) { + this.equipmentType = equipmentType; + } + + public EquippableComponentBuilder equipmentType(ArmorEquipmentType equipmentType) { + this.equipmentType = equipmentType; + return this; + } + + public EquippableComponentBuilder equipSound(CompatSoundEvent equipSound) { + this.equipSound = equipSound; + return this; + } + + public EquippableComponentBuilder shearingSound(CompatSoundEvent shearingSound) { + this.shearingSound = shearingSound; + return this; + } + + public EquippableComponentBuilder equipOnInteract(boolean equipOnInteract) { + this.equipOnInteract = equipOnInteract; + return this; + } + + public EquippableComponentBuilder canBeSheared(boolean canBeSheared) { + this.canBeSheared = canBeSheared; + return this; + } + + public EquippableComponentBuilder model(CompatEquipmentAsset model) { + this.model = model; + return this; + } + + public EquippableComponentBuilder model(CompatIdentifier id) { + return model(CompatEquipmentAsset.of(id)); + } + + public EquippableComponentBuilder allowedEntities(TagKey allowedEntities) { + this.allowedEntities = allowedEntities; + return this; + } + + public EquippableComponentBuilder allowedEntities(CompatIdentifier tagId) { + return allowedEntities(TagKey.create(TagKey.Type.ENTITY_TYPE, tagId)); + } + + public EquippableComponentBuilder allowedEntities(String tagId) { + return allowedEntities(CompatIdentifier.of(tagId)); + } + + public CompatEquippableComponent build() { + return new CompatEquippableComponent(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/item/stack/LoreUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/item/stack/LoreUtil.java new file mode 100644 index 000000000..e29531d73 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/stack/LoreUtil.java @@ -0,0 +1,46 @@ +package net.pitan76.mcpitanlib.api.item.stack; + +import net.minecraft.component.DataComponentTypes; +import net.minecraft.component.type.LoreComponent; +import net.minecraft.item.ItemStack; +import net.minecraft.text.Text; + +import java.util.List; + +public class LoreUtil { + public static boolean hasLore(ItemStack stack) { + return stack.contains(DataComponentTypes.LORE); + } + + public static List getLore(ItemStack stack) { + if (!hasLore(stack)) return List.of(); + return stack.get(DataComponentTypes.LORE).lines(); + } + + public static List getLoreAsStringList(ItemStack stack) { + return getLore(stack).stream() + .map(Text::getString) + .toList(); + } + + public static String getLoreAsString(ItemStack stack) { + return getLoreAsStringList(stack).stream() + .reduce("", (a, b) -> a + "\n" + b); + } + + public static void setLore(ItemStack stack, List lore) { + stack.set(DataComponentTypes.LORE, new LoreComponent(lore)); + } + + public static void setLoreStringList(ItemStack stack, List lore) { + setLore(stack, lore.stream() + .map(Text::of) + .toList()); + } + + public static void setLore(ItemStack stack, String lore) { + setLore(stack, lore.lines() + .map(Text::of) + .toList()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/item/tool/CompatibleAxeItem.java b/common/src/main/java/net/pitan76/mcpitanlib/api/item/tool/CompatibleAxeItem.java new file mode 100644 index 000000000..708c87ca5 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/tool/CompatibleAxeItem.java @@ -0,0 +1,89 @@ +package net.pitan76.mcpitanlib.api.item.tool; + +import net.minecraft.block.BlockState; +import net.minecraft.entity.LivingEntity; +import net.minecraft.item.AxeItem; +import net.minecraft.item.ItemStack; +import net.minecraft.item.ToolMaterial; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.event.item.PostHitEvent; +import net.pitan76.mcpitanlib.api.event.item.PostMineEvent; +import net.pitan76.mcpitanlib.api.item.v2.CompatibleItemSettings; +import net.pitan76.mcpitanlib.api.item.v2.CompatItemProvider; +import net.pitan76.mcpitanlib.api.util.ItemStackUtil; + +public class CompatibleAxeItem extends AxeItem implements CompatItemProvider { + + public CompatibleItemSettings settings; + + public CompatibleAxeItem(CompatibleToolMaterial material, float attackDamage, float attackSpeed, CompatibleItemSettings settings) { + super(material.build(), settings.build()); + this.settings = settings; + } + + public CompatibleAxeItem(float attackDamage, float attackSpeed, ToolMaterial material, CompatibleItemSettings settings) { + super(material, settings.build()); + this.settings = settings; + } + + @Override + public CompatibleItemSettings getCompatSettings() { + return settings; + } + + public boolean overrideIsSuitableFor(BlockState state) { + return super.isCorrectForDrops(getDefaultStack(), state); + } + + @Deprecated + @Override + public boolean isCorrectForDrops(ItemStack stack, BlockState state) { + return overrideIsSuitableFor(state); + } + + public float overrideGetMiningSpeedMultiplier(ItemStack stack, BlockState state) { + return 1.0F; + } + + @Deprecated + @Override + public float getMiningSpeed(ItemStack stack, BlockState state) { + return overrideGetMiningSpeedMultiplier(stack, state) * super.getMiningSpeed(stack, state); + } + + @Deprecated + @Override + public boolean postHit(ItemStack stack, LivingEntity target, LivingEntity attacker) { + return postHit(new PostHitEvent(stack, target, attacker)); + } + + @Deprecated + @Override + public boolean postMine(ItemStack stack, World world, BlockState state, BlockPos pos, LivingEntity miner) { + return postMine(new PostMineEvent(stack, world, state, pos, miner)); + } + + /** + * post hit event + * @param event PostHitEvent + * @return boolean + */ + public boolean postHit(PostHitEvent event) { + return super.postHit(event.stack, event.target, event.attacker); + } + + /** + * post mine event + * @param event PostMineEvent + * @return boolean + */ + public boolean postMine(PostMineEvent event) { + return super.postMine(event.stack, event.world, event.state, event.pos, event.miner); + } + + // -1.20.6 + public boolean isDamageableOnDefault() { + return ItemStackUtil.getMaxDamage(this) > 0; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/item/tool/CompatibleHoeItem.java b/common/src/main/java/net/pitan76/mcpitanlib/api/item/tool/CompatibleHoeItem.java new file mode 100644 index 000000000..252146370 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/tool/CompatibleHoeItem.java @@ -0,0 +1,89 @@ +package net.pitan76.mcpitanlib.api.item.tool; + +import net.minecraft.block.BlockState; +import net.minecraft.entity.LivingEntity; +import net.minecraft.item.HoeItem; +import net.minecraft.item.ItemStack; +import net.minecraft.item.ToolMaterial; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.event.item.PostHitEvent; +import net.pitan76.mcpitanlib.api.event.item.PostMineEvent; +import net.pitan76.mcpitanlib.api.item.v2.CompatibleItemSettings; +import net.pitan76.mcpitanlib.api.util.ItemStackUtil; +import net.pitan76.mcpitanlib.api.item.v2.CompatItemProvider; + +public class CompatibleHoeItem extends HoeItem implements CompatItemProvider { + + public CompatibleItemSettings settings; + + public CompatibleHoeItem(CompatibleToolMaterial material, int attackDamage, float attackSpeed, CompatibleItemSettings settings) { + super(material.build(), settings.build()); + this.settings = settings; + } + + public CompatibleHoeItem(int attackDamage, float attackSpeed, ToolMaterial material, CompatibleItemSettings settings) { + super(material, settings.build()); + this.settings = settings; + } + + @Override + public net.pitan76.mcpitanlib.api.item.v2.CompatibleItemSettings getCompatSettings() { + return settings; + } + + public boolean overrideIsSuitableFor(BlockState state) { + return super.isCorrectForDrops(getDefaultStack(), state); + } + + @Deprecated + @Override + public boolean isCorrectForDrops(ItemStack stack, BlockState state) { + return overrideIsSuitableFor(state); + } + + public float overrideGetMiningSpeedMultiplier(ItemStack stack, BlockState state) { + return 1.0F; + } + + @Deprecated + @Override + public float getMiningSpeed(ItemStack stack, BlockState state) { + return overrideGetMiningSpeedMultiplier(stack, state) * super.getMiningSpeed(stack, state); + } + + @Deprecated + @Override + public boolean postHit(ItemStack stack, LivingEntity target, LivingEntity attacker) { + return postHit(new PostHitEvent(stack, target, attacker)); + } + + @Deprecated + @Override + public boolean postMine(ItemStack stack, World world, BlockState state, BlockPos pos, LivingEntity miner) { + return postMine(new PostMineEvent(stack, world, state, pos, miner)); + } + + /** + * post hit event + * @param event PostHitEvent + * @return boolean + */ + public boolean postHit(PostHitEvent event) { + return super.postHit(event.stack, event.target, event.attacker); + } + + /** + * post mine event + * @param event PostMineEvent + * @return boolean + */ + public boolean postMine(PostMineEvent event) { + return super.postMine(event.stack, event.world, event.state, event.pos, event.miner); + } + + // -1.20.6 + public boolean isDamageableOnDefault() { + return ItemStackUtil.getMaxDamage(this) > 0; + } +} \ No newline at end of file diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/item/tool/CompatibleMiningToolItem.java b/common/src/main/java/net/pitan76/mcpitanlib/api/item/tool/CompatibleMiningToolItem.java new file mode 100644 index 000000000..48ab15647 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/tool/CompatibleMiningToolItem.java @@ -0,0 +1,124 @@ +package net.pitan76.mcpitanlib.api.item.tool; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.item.MiningToolItem; +import net.minecraft.item.ToolMaterial; +import net.minecraft.util.ActionResult; +import net.minecraft.util.Hand; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.event.item.ItemUseOnEntityEvent; +import net.pitan76.mcpitanlib.api.event.item.PostHitEvent; +import net.pitan76.mcpitanlib.api.event.item.PostMineEvent; +import net.pitan76.mcpitanlib.api.item.v2.CompatItemProvider; +import net.pitan76.mcpitanlib.api.item.v2.CompatibleItemSettings; +import net.pitan76.mcpitanlib.api.tag.TagKey; +import net.pitan76.mcpitanlib.api.tag.v2.CompatTagKey; +import net.pitan76.mcpitanlib.api.tag.v2.typed.BlockTagKey; +import net.pitan76.mcpitanlib.api.util.CompatActionResult; +import net.pitan76.mcpitanlib.api.util.ItemStackUtil; + +public class CompatibleMiningToolItem extends MiningToolItem implements CompatItemProvider { + + public CompatibleItemSettings settings; + + @Deprecated + protected CompatibleMiningToolItem(float attackDamage, float attackSpeed, ToolMaterial material, net.minecraft.registry.tag.TagKey effectiveBlocks, Settings settings) { + super(material, effectiveBlocks, settings); + } + + public CompatibleMiningToolItem(CompatibleToolMaterial material, int attackDamage, float attackSpeed, TagKey tagKey, CompatibleItemSettings settings) { + this(attackDamage, attackSpeed, material.build(), tagKey.getTagKey(), settings.build()); + this.settings = settings; + } + + public CompatibleMiningToolItem(CompatibleToolMaterial material, int attackDamage, float attackSpeed, CompatTagKey tagKey, CompatibleItemSettings settings) { + this(attackDamage, attackSpeed, material.build(), tagKey.getTagKey(), settings.build()); + this.settings = settings; + } + + public CompatibleMiningToolItem(CompatibleToolMaterial material, int attackDamage, float attackSpeed, BlockTagKey tagKey, CompatibleItemSettings settings) { + this(attackDamage, attackSpeed, material.build(), tagKey.getTagKey(), settings.build()); + this.settings = settings; + } + + @Override + public CompatibleItemSettings getCompatSettings() { + return settings; + } + + public boolean overrideIsSuitableFor(BlockState state) { + return super.isCorrectForDrops(getDefaultStack(), state); + } + + @Deprecated + @Override + public boolean isCorrectForDrops(ItemStack stack, BlockState state) { + return overrideIsSuitableFor(state); + } + + public float overrideGetMiningSpeedMultiplier(ItemStack stack, BlockState state) { + return 1.0F; + } + + @Deprecated + @Override + public float getMiningSpeed(ItemStack stack, BlockState state) { + return overrideGetMiningSpeedMultiplier(stack, state) * super.getMiningSpeed(stack, state); + } + + /** + * post hit event + * @param event PostHitEvent + * @return boolean + */ + public boolean postHit(PostHitEvent event) { + return super.postHit(event.stack, event.target, event.attacker); + } + + /** + * post mine event + * @param event PostMineEvent + * @return boolean + */ + public boolean postMine(PostMineEvent event) { + return super.postMine(event.stack, event.world, event.state, event.pos, event.miner); + } + + @Deprecated + @Override + public boolean postHit(ItemStack stack, LivingEntity target, LivingEntity attacker) { + return postHit(new PostHitEvent(stack, target, attacker)); + } + + @Deprecated + @Override + public boolean postMine(ItemStack stack, World world, BlockState state, BlockPos pos, LivingEntity miner) { + return postMine(new PostMineEvent(stack, world, state, pos, miner)); + } + + // -1.20.6 + public boolean isDamageableOnDefault() { + return ItemStackUtil.getMaxDamage(this) > 0; + } + + @Deprecated + @Override + public ActionResult useOnEntity(ItemStack stack, PlayerEntity user, LivingEntity entity, Hand hand) { + return onRightClickOnEntity(new ItemUseOnEntityEvent(stack, user, entity, hand)).toActionResult(); + } + + @Deprecated + @Override + public CompatActionResult onRightClickOnEntity(ItemUseOnEntityEvent event, Options options) { + return CompatItemProvider.super.onRightClickOnEntity(event, options); + } + + public CompatActionResult onRightClickOnEntity(ItemUseOnEntityEvent e) { + return CompatActionResult.of(super.useOnEntity(e.stack, e.user.getEntity(), e.entity, e.hand)); + } +} \ No newline at end of file diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/item/tool/CompatiblePickaxeItem.java b/common/src/main/java/net/pitan76/mcpitanlib/api/item/tool/CompatiblePickaxeItem.java new file mode 100644 index 000000000..cd0752d20 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/tool/CompatiblePickaxeItem.java @@ -0,0 +1,89 @@ +package net.pitan76.mcpitanlib.api.item.tool; + +import net.minecraft.block.BlockState; +import net.minecraft.entity.LivingEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.item.PickaxeItem; +import net.minecraft.item.ToolMaterial; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.event.item.PostHitEvent; +import net.pitan76.mcpitanlib.api.event.item.PostMineEvent; +import net.pitan76.mcpitanlib.api.item.v2.CompatibleItemSettings; +import net.pitan76.mcpitanlib.api.util.ItemStackUtil; +import net.pitan76.mcpitanlib.api.item.v2.CompatItemProvider; + +public class CompatiblePickaxeItem extends PickaxeItem implements CompatItemProvider { + + public CompatibleItemSettings settings; + + public CompatiblePickaxeItem(CompatibleToolMaterial material, int attackDamage, float attackSpeed, CompatibleItemSettings settings) { + super(material.build(), settings.build()); + this.settings = settings; + } + + public CompatiblePickaxeItem(int attackDamage, float attackSpeed, ToolMaterial material, CompatibleItemSettings settings) { + super(material, settings.build()); + this.settings = settings; + } + + @Override + public CompatibleItemSettings getCompatSettings() { + return settings; + } + + public boolean overrideIsSuitableFor(BlockState state) { + return super.isCorrectForDrops(getDefaultStack(), state); + } + + @Deprecated + @Override + public boolean isCorrectForDrops(ItemStack stack, BlockState state) { + return overrideIsSuitableFor(state); + } + + public float overrideGetMiningSpeedMultiplier(ItemStack stack, BlockState state) { + return 1.0F; + } + + @Deprecated + @Override + public float getMiningSpeed(ItemStack stack, BlockState state) { + return overrideGetMiningSpeedMultiplier(stack, state) * super.getMiningSpeed(stack, state); + } + + @Deprecated + @Override + public boolean postHit(ItemStack stack, LivingEntity target, LivingEntity attacker) { + return postHit(new PostHitEvent(stack, target, attacker)); + } + + @Deprecated + @Override + public boolean postMine(ItemStack stack, World world, BlockState state, BlockPos pos, LivingEntity miner) { + return postMine(new PostMineEvent(stack, world, state, pos, miner)); + } + + /** + * post hit event + * @param event PostHitEvent + * @return boolean + */ + public boolean postHit(PostHitEvent event) { + return super.postHit(event.stack, event.target, event.attacker); + } + + /** + * post mine event + * @param event PostMineEvent + * @return boolean + */ + public boolean postMine(PostMineEvent event) { + return super.postMine(event.stack, event.world, event.state, event.pos, event.miner); + } + + // -1.20.6 + public boolean isDamageableOnDefault() { + return ItemStackUtil.getMaxDamage(this) > 0; + } +} \ No newline at end of file diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/item/tool/CompatibleShearsItem.java b/common/src/main/java/net/pitan76/mcpitanlib/api/item/tool/CompatibleShearsItem.java new file mode 100644 index 000000000..9b3b190c3 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/tool/CompatibleShearsItem.java @@ -0,0 +1,88 @@ +package net.pitan76.mcpitanlib.api.item.tool; + +import net.minecraft.block.BlockState; +import net.minecraft.entity.LivingEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.item.ShearsItem; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.event.item.PostHitEvent; +import net.pitan76.mcpitanlib.api.event.item.PostMineEvent; +import net.pitan76.mcpitanlib.api.item.v2.CompatibleItemSettings; +import net.pitan76.mcpitanlib.api.item.v2.CompatItemProvider; +import net.pitan76.mcpitanlib.api.util.ItemStackUtil; + +public class CompatibleShearsItem extends ShearsItem implements CompatItemProvider { + + public CompatibleItemSettings settings; + + @Deprecated + public CompatibleShearsItem(Settings settings) { + super(settings); + } + + public CompatibleShearsItem(CompatibleItemSettings settings) { + this(settings.build()); + this.settings = settings; + } + + @Override + public CompatibleItemSettings getCompatSettings() { + return settings; + } + + public boolean overrideIsSuitableFor(BlockState state) { + return super.isCorrectForDrops(getDefaultStack(), state); + } + + @Deprecated + @Override + public boolean isCorrectForDrops(ItemStack stack, BlockState state) { + return overrideIsSuitableFor(state); + } + + public float overrideGetMiningSpeedMultiplier(ItemStack stack, BlockState state) { + return 1.0F; + } + + @Deprecated + @Override + public float getMiningSpeed(ItemStack stack, BlockState state) { + return overrideGetMiningSpeedMultiplier(stack, state) * super.getMiningSpeed(stack, state); + } + + @Deprecated + @Override + public boolean postHit(ItemStack stack, LivingEntity target, LivingEntity attacker) { + return postHit(new PostHitEvent(stack, target, attacker)); + } + + @Deprecated + @Override + public boolean postMine(ItemStack stack, World world, BlockState state, BlockPos pos, LivingEntity miner) { + return postMine(new PostMineEvent(stack, world, state, pos, miner)); + } + + /** + * post hit event + * @param event PostHitEvent + * @return boolean + */ + public boolean postHit(PostHitEvent event) { + return super.postHit(event.stack, event.target, event.attacker); + } + + /** + * post mine event + * @param event PostMineEvent + * @return boolean + */ + public boolean postMine(PostMineEvent event) { + return super.postMine(event.stack, event.world, event.state, event.pos, event.miner); + } + + // -1.20.6 + public boolean isDamageableOnDefault() { + return ItemStackUtil.getMaxDamage(this) > 0; + } +} \ No newline at end of file diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/item/tool/CompatibleShovelItem.java b/common/src/main/java/net/pitan76/mcpitanlib/api/item/tool/CompatibleShovelItem.java new file mode 100644 index 000000000..e9b2df5d1 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/tool/CompatibleShovelItem.java @@ -0,0 +1,89 @@ +package net.pitan76.mcpitanlib.api.item.tool; + +import net.minecraft.block.BlockState; +import net.minecraft.entity.LivingEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.item.ShovelItem; +import net.minecraft.item.ToolMaterial; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.event.item.PostHitEvent; +import net.pitan76.mcpitanlib.api.event.item.PostMineEvent; +import net.pitan76.mcpitanlib.api.item.v2.CompatItemProvider; +import net.pitan76.mcpitanlib.api.item.v2.CompatibleItemSettings; +import net.pitan76.mcpitanlib.api.util.ItemStackUtil; + +public class CompatibleShovelItem extends ShovelItem implements CompatItemProvider { + + public CompatibleItemSettings settings; + + public CompatibleShovelItem(CompatibleToolMaterial material, float attackDamage, float attackSpeed, CompatibleItemSettings settings) { + super(material.build(), settings.build()); + } + + public CompatibleShovelItem(float attackDamage, float attackSpeed, ToolMaterial material, CompatibleItemSettings settings) { + super(material, settings.build()); + } + + @Override + public CompatibleItemSettings getCompatSettings() { + return settings; + } + + public boolean overrideIsSuitableFor(BlockState state) { + return super.isCorrectForDrops(getDefaultStack(), state); + } + + @Deprecated + @Override + public boolean isCorrectForDrops(ItemStack stack, BlockState state) { + return overrideIsSuitableFor(state); + } + + public float overrideGetMiningSpeedMultiplier(ItemStack stack, BlockState state) { + return 1.0F; + } + + @Deprecated + @Override + public float getMiningSpeed(ItemStack stack, BlockState state) { + return overrideGetMiningSpeedMultiplier(stack, state) * super.getMiningSpeed(stack, state); + } + + @Deprecated + @Override + public boolean postHit(ItemStack stack, LivingEntity target, LivingEntity attacker) { + return postHit(new PostHitEvent(stack, target, attacker)); + } + + @Deprecated + @Override + public boolean postMine(ItemStack stack, World world, BlockState state, BlockPos pos, LivingEntity miner) { + return postMine(new PostMineEvent(stack, world, state, pos, miner)); + } + + /** + * post hit event + * + * @param event PostHitEvent + * @return boolean + */ + public boolean postHit(PostHitEvent event) { + return super.postHit(event.stack, event.target, event.attacker); + } + + /** + * post mine event + * + * @param event PostMineEvent + * @return boolean + */ + public boolean postMine(PostMineEvent event) { + return super.postMine(event.stack, event.world, event.state, event.pos, event.miner); + } + + // -1.20.6 + public boolean isDamageableOnDefault() { + return ItemStackUtil.getMaxDamage(this) > 0; + } +} \ No newline at end of file diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/item/tool/CompatibleSwordItem.java b/common/src/main/java/net/pitan76/mcpitanlib/api/item/tool/CompatibleSwordItem.java new file mode 100644 index 000000000..1fa2f0ea3 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/tool/CompatibleSwordItem.java @@ -0,0 +1,89 @@ +package net.pitan76.mcpitanlib.api.item.tool; + +import net.minecraft.block.BlockState; +import net.minecraft.entity.LivingEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.item.SwordItem; +import net.minecraft.item.ToolMaterial; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.event.item.PostHitEvent; +import net.pitan76.mcpitanlib.api.event.item.PostMineEvent; +import net.pitan76.mcpitanlib.api.util.ItemStackUtil; +import net.pitan76.mcpitanlib.api.item.v2.CompatItemProvider; +import net.pitan76.mcpitanlib.api.item.v2.CompatibleItemSettings; + +public class CompatibleSwordItem extends SwordItem implements CompatItemProvider { + + public CompatibleItemSettings settings; + + public CompatibleSwordItem(CompatibleToolMaterial material, int attackDamage, float attackSpeed, CompatibleItemSettings settings) { + super(material.build(), settings.build()); + this.settings = settings; + } + + public CompatibleSwordItem(int attackDamage, float attackSpeed, ToolMaterial material, CompatibleItemSettings settings) { + super(material, settings.build()); + this.settings = settings; + } + + @Override + public CompatibleItemSettings getCompatSettings() { + return settings; + } + + public boolean overrideIsSuitableFor(BlockState state) { + return super.isCorrectForDrops(getDefaultStack(), state); + } + + @Deprecated + @Override + public boolean isCorrectForDrops(ItemStack stack, BlockState state) { + return overrideIsSuitableFor(state); + } + + public float overrideGetMiningSpeedMultiplier(ItemStack stack, BlockState state) { + return 1.0F; + } + + @Deprecated + @Override + public float getMiningSpeed(ItemStack stack, BlockState state) { + return overrideGetMiningSpeedMultiplier(stack, state) * super.getMiningSpeed(stack, state); + } + + @Deprecated + @Override + public boolean postHit(ItemStack stack, LivingEntity target, LivingEntity attacker) { + return postHit(new PostHitEvent(stack, target, attacker)); + } + + @Deprecated + @Override + public boolean postMine(ItemStack stack, World world, BlockState state, BlockPos pos, LivingEntity miner) { + return postMine(new PostMineEvent(stack, world, state, pos, miner)); + } + + /** + * post hit event + * @param event PostHitEvent + * @return boolean + */ + public boolean postHit(PostHitEvent event) { + return super.postHit(event.stack, event.target, event.attacker); + } + + /** + * post mine event + * @param event PostMineEvent + * @return boolean + */ + public boolean postMine(PostMineEvent event) { + return super.postMine(event.stack, event.world, event.state, event.pos, event.miner); + } + + // -1.20.6 + public boolean isDamageableOnDefault() { + return ItemStackUtil.getMaxDamage(this) > 0; + } +} \ No newline at end of file diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/item/tool/CompatibleToolItem.java b/common/src/main/java/net/pitan76/mcpitanlib/api/item/tool/CompatibleToolItem.java new file mode 100644 index 000000000..f9649951d --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/tool/CompatibleToolItem.java @@ -0,0 +1,83 @@ +package net.pitan76.mcpitanlib.api.item.tool; + +import net.minecraft.block.BlockState; +import net.minecraft.entity.LivingEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.item.ToolItem; +import net.minecraft.item.ToolMaterial; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.event.item.PostHitEvent; +import net.pitan76.mcpitanlib.api.event.item.PostMineEvent; +import net.pitan76.mcpitanlib.api.item.v2.CompatibleItemSettings; +import net.pitan76.mcpitanlib.api.item.v2.CompatItemProvider; + +public class CompatibleToolItem extends ToolItem implements CompatItemProvider { + + public CompatibleItemSettings settings; + + @Deprecated + protected CompatibleToolItem(ToolMaterial material, Settings settings) { + super(material, settings); + } + + public CompatibleToolItem(CompatibleToolMaterial material, CompatibleItemSettings settings) { + this(material.build(), settings.build()); + this.settings = settings; + } + + @Override + public CompatibleItemSettings getCompatSettings() { + return settings; + } + + public boolean overrideIsSuitableFor(BlockState state) { + return super.isCorrectForDrops(getDefaultStack(), state); + } + + @Deprecated + @Override + public boolean isCorrectForDrops(ItemStack stack, BlockState state) { + return overrideIsSuitableFor(state); + } + + public float overrideGetMiningSpeedMultiplier(ItemStack stack, BlockState state) { + return 1.0F; + } + + @Deprecated + @Override + public float getMiningSpeed(ItemStack stack, BlockState state) { + return overrideGetMiningSpeedMultiplier(stack, state) * super.getMiningSpeed(stack, state); + } + + @Deprecated + @Override + public boolean postHit(ItemStack stack, LivingEntity target, LivingEntity attacker) { + return postHit(new PostHitEvent(stack, target, attacker)); + } + + @Deprecated + @Override + public boolean postMine(ItemStack stack, World world, BlockState state, BlockPos pos, LivingEntity miner) { + return postMine(new PostMineEvent(stack, world, state, pos, miner)); + } + + /** + * post hit event + * @param event PostHitEvent + * @return boolean + */ + public boolean postHit(PostHitEvent event) { + return super.postHit(event.stack, event.target, event.attacker); + } + + /** + * post mine event + * @param event PostMineEvent + * @return boolean + */ + public boolean postMine(PostMineEvent event) { + return super.postMine(event.stack, event.world, event.state, event.pos, event.miner); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/item/tool/CompatibleToolMaterial.java b/common/src/main/java/net/pitan76/mcpitanlib/api/item/tool/CompatibleToolMaterial.java new file mode 100644 index 000000000..7559366c7 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/tool/CompatibleToolMaterial.java @@ -0,0 +1,120 @@ +package net.pitan76.mcpitanlib.api.item.tool; + +import net.minecraft.block.Block; +import net.minecraft.item.Item; +import net.minecraft.item.ToolMaterial; +import net.minecraft.recipe.Ingredient; +import net.minecraft.registry.tag.BlockTags; +import net.minecraft.registry.tag.ItemTags; +import net.minecraft.registry.tag.TagKey; +import net.pitan76.mcpitanlib.api.util.IngredientUtil; + +public interface CompatibleToolMaterial { + + int getCompatMiningLevel(); + + float getCompatAttackDamage(); + + float getCompatMiningSpeedMultiplier(); + + default Ingredient getCompatRepairIngredient() { + return IngredientUtil.fromTagByIdentifier(getRepairTag().id()); + } + + int getCompatDurability(); + + int getCompatEnchantability(); + + default TagKey getInverseTag() { + + return level2inverseTag(getCompatMiningLevel()); + } + + @Deprecated + default TagKey _getInverseTag() { + return getInverseTag(); + } + + public static TagKey level2inverseTag(int level) { + switch (level) { + case 1: + return BlockTags.INCORRECT_FOR_WOODEN_TOOL; + case 2: + return BlockTags.INCORRECT_FOR_STONE_TOOL; + case 3: + return BlockTags.INCORRECT_FOR_IRON_TOOL; + case 4: + return BlockTags.INCORRECT_FOR_GOLD_TOOL; + case 5: + return BlockTags.INCORRECT_FOR_DIAMOND_TOOL; + case 6: + return BlockTags.INCORRECT_FOR_NETHERITE_TOOL; + + default: + return BlockTags.INCORRECT_FOR_WOODEN_TOOL; + } + } + + @Deprecated + default float getAttackDamage() { + return getCompatAttackDamage(); + } + + @Deprecated + default float getMiningSpeedMultiplier() { + return getCompatMiningSpeedMultiplier(); + } + + @Deprecated + default Ingredient getRepairIngredient() { + return getCompatRepairIngredient(); + } + + @Deprecated + default int getDurability() { + return getCompatDurability(); + } + + @Deprecated + default int getEnchantability() { + return getCompatEnchantability(); + } + + default TagKey getRepairTag() { + return ItemTags.IRON_ORES; + } + + default ToolMaterial build() { + return new ToolMaterial() { + @Override + public int getDurability() { + return getCompatDurability(); + } + + @Override + public float getMiningSpeedMultiplier() { + return getCompatMiningSpeedMultiplier(); + } + + @Override + public float getAttackDamage() { + return getCompatAttackDamage(); + } + + @Override + public TagKey getInverseTag() { + return _getInverseTag(); + } + + @Override + public int getEnchantability() { + return getCompatEnchantability(); + } + + @Override + public Ingredient getRepairIngredient() { + return getCompatRepairIngredient(); + } + }; + } +} \ No newline at end of file diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/item/v2/CompatArmorMaterial.java b/common/src/main/java/net/pitan76/mcpitanlib/api/item/v2/CompatArmorMaterial.java new file mode 100644 index 000000000..8d757d099 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/v2/CompatArmorMaterial.java @@ -0,0 +1,25 @@ +package net.pitan76.mcpitanlib.api.item.v2; + +import net.minecraft.sound.SoundEvent; +import net.minecraft.util.Identifier; +import net.pitan76.mcpitanlib.api.item.CompatibleArmorMaterial; +import net.pitan76.mcpitanlib.api.sound.CompatSoundEvent; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; + +@Deprecated +public interface CompatArmorMaterial extends CompatibleArmorMaterial { + + @Override + default SoundEvent getEquipSound() { + return getEquipCompatSound().get(); + } + + CompatSoundEvent getEquipCompatSound(); + + @Override + default Identifier getId() { + return getCompatId().toMinecraft(); + } + + CompatIdentifier getCompatId(); +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/item/v2/CompatItem.java b/common/src/main/java/net/pitan76/mcpitanlib/api/item/v2/CompatItem.java new file mode 100644 index 000000000..4b0439dac --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/v2/CompatItem.java @@ -0,0 +1,111 @@ +package net.pitan76.mcpitanlib.api.item.v2; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.EquipmentSlot; +import net.minecraft.entity.LivingEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.util.Rarity; +import net.minecraft.util.UseAction; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.event.item.CanRepairArgs; +import net.pitan76.mcpitanlib.api.event.item.EnchantabilityArgs; +import net.pitan76.mcpitanlib.api.event.item.EnchantableArgs; +import net.pitan76.mcpitanlib.api.event.item.InventoryTickEvent; +import net.pitan76.mcpitanlib.api.item.ExtendItem; +import net.pitan76.mcpitanlib.api.item.args.RarityArgs; +import net.pitan76.mcpitanlib.api.item.args.StoppedUsingArgs; +import net.pitan76.mcpitanlib.api.item.args.UseActionArgs; +import net.pitan76.mcpitanlib.api.item.consume.CompatUseAction; +import net.pitan76.mcpitanlib.api.tag.item.RepairIngredientTag; +import net.pitan76.mcpitanlib.api.util.CompatRarity; +import net.pitan76.mcpitanlib.core.Dummy; +import net.pitan76.mcpitanlib.midohra.item.ItemWrapper; +import org.jetbrains.annotations.Nullable; + +public class CompatItem extends ExtendItem { + + public CompatibleItemSettings settings; + + public CompatItem(CompatibleItemSettings settings) { + super(settings); + this.settings = settings; + } + + public CompatibleItemSettings getCompatSettings() { + return settings; + } + + public ItemWrapper getWrapper() { + return ItemWrapper.of(this); + } + + @Deprecated + @Override + public UseAction getUseAction(ItemStack stack) { + return getUseAction(new UseActionArgs(stack)).getUseAction(); + } + + public CompatUseAction getUseAction(UseActionArgs args) { + return CompatUseAction.of(super.getUseAction(args.stack)); + } + + @Deprecated + @Override + public Rarity getRarity(ItemStack stack) { + return getRarity(new RarityArgs(stack)).get(); + } + + public CompatRarity getRarity(RarityArgs args) { + return settings.rarity; + } + + @Override + public boolean isEnchantable(EnchantableArgs args) { + return settings.enchantability != -1; + } + + @Override + public int getEnchantability(EnchantabilityArgs args) { + return settings.enchantability; + } + + @Override + public boolean canRepair(CanRepairArgs args) { + RepairIngredientTag tag = settings.repairIngredientTag; + return tag != null && tag.contains(args.stack); + } + + @Override + public boolean hasRecipeRemainder(Dummy dummy) { + return settings.recipeRemainder != null; + } + + @Override + protected String getOrCreateTranslationKey() { + if (settings.changedTranslationKey) + return settings.translationKey; + + return super.getOrCreateTranslationKey(); + } + + @Deprecated + @Override + public void onStoppedUsing(ItemStack stack, World world, LivingEntity user, int remainingUseTicks) { + onStoppedUsing(new StoppedUsingArgs(stack, world, user, remainingUseTicks)); + } + + public boolean onStoppedUsing(StoppedUsingArgs args) { + super.onStoppedUsing(args.stack, args.world, args.user, args.remainingUseTicks); + return false; + } + + @Deprecated + @Override + public void inventoryTick(ItemStack stack, World world, Entity entity, int slot, boolean selected) { + inventoryTick(new InventoryTickEvent(stack, world, entity, slot, selected)); + } + + public void inventoryTick(InventoryTickEvent e) { + super.inventoryTick(e.stack, e.world, e.entity, e.slot, e.selected); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/item/v2/CompatItemProvider.java b/common/src/main/java/net/pitan76/mcpitanlib/api/item/v2/CompatItemProvider.java new file mode 100644 index 000000000..67cb774ea --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/v2/CompatItemProvider.java @@ -0,0 +1,48 @@ +package net.pitan76.mcpitanlib.api.item.v2; + +import net.minecraft.item.Item; +import net.pitan76.mcpitanlib.api.event.item.CanRepairArgs; +import net.pitan76.mcpitanlib.api.event.item.EnchantabilityArgs; +import net.pitan76.mcpitanlib.api.event.item.EnchantableArgs; +import net.pitan76.mcpitanlib.api.event.item.InventoryTickEvent; +import net.pitan76.mcpitanlib.api.item.ExtendItemProvider; +import net.pitan76.mcpitanlib.api.item.args.RarityArgs; +import net.pitan76.mcpitanlib.api.item.args.UseActionArgs; +import net.pitan76.mcpitanlib.api.item.consume.CompatUseAction; +import net.pitan76.mcpitanlib.api.tag.item.RepairIngredientTag; +import net.pitan76.mcpitanlib.api.util.CompatRarity; +import net.pitan76.mcpitanlib.midohra.item.ItemWrapper; + +public interface CompatItemProvider extends ExtendItemProvider { + CompatibleItemSettings getCompatSettings(); + + default ItemWrapper getWrapper() { + return this instanceof Item ? ItemWrapper.of((Item) this) : ItemWrapper.of(); + } + + default CompatUseAction getUseAction(UseActionArgs args, Options options) { + options.cancel = false; + return null; + } + + default CompatRarity getRarity(RarityArgs args) { + return getCompatSettings().rarity; + } + + default boolean isEnchantable(EnchantableArgs args) { + return getCompatSettings().enchantability != -1; + } + + default int getEnchantability(EnchantabilityArgs args) { + return getCompatSettings().enchantability; + } + + default boolean canRepair(CanRepairArgs args) { + RepairIngredientTag tag = getCompatSettings().repairIngredientTag; + return tag != null && tag.contains(args.stack); + } + + default void inventoryTick(InventoryTickEvent e, Options options) { + options.cancel = false; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/item/v2/CompatibleItemSettings.java b/common/src/main/java/net/pitan76/mcpitanlib/api/item/v2/CompatibleItemSettings.java new file mode 100644 index 000000000..f85e55fb5 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/v2/CompatibleItemSettings.java @@ -0,0 +1,194 @@ +package net.pitan76.mcpitanlib.api.item.v2; + +import net.minecraft.component.DataComponentTypes; +import net.minecraft.item.Item; +import net.minecraft.item.ItemGroup; +import net.minecraft.registry.RegistryKey; +import net.minecraft.registry.RegistryKeys; +import net.minecraft.util.Identifier; +import net.minecraft.util.Rarity; +import net.pitan76.mcpitanlib.api.entity.attribute.AttributeModifiersComponentBuilder; +import net.pitan76.mcpitanlib.api.entity.attribute.CompatAttributeModifiersComponent; +import net.pitan76.mcpitanlib.api.item.CompatFoodComponent; +import net.pitan76.mcpitanlib.api.item.CreativeTabBuilder; +import net.pitan76.mcpitanlib.api.item.ExtendSettings; +import net.pitan76.mcpitanlib.api.item.equipment.CompatEquippableComponent; +import net.pitan76.mcpitanlib.api.item.equipment.EquippableComponentBuilder; +import net.pitan76.mcpitanlib.api.tag.item.RepairIngredientTag; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.api.util.CompatRarity; +import net.pitan76.mcpitanlib.midohra.item.ItemGroupWrapper; +import net.pitan76.mcpitanlib.midohra.item.ItemWrapper; + +import java.util.function.Supplier; + +@SuppressWarnings("deprecation") +public class CompatibleItemSettings extends net.pitan76.mcpitanlib.api.item.CompatibleItemSettings { + protected CompatIdentifier identifier = null; + public boolean changedTranslationKey = false; + public CompatRarity rarity = CompatRarity.COMMON; + public int enchantability = -1; + public RepairIngredientTag repairIngredientTag = null; + public Item recipeRemainder = null; + + public CompatibleItemSettings(CompatIdentifier identifier) { + super(); + setId(identifier); + } + + public static CompatibleItemSettings of(CompatIdentifier id) { + return new CompatibleItemSettings(id); + } + + @Deprecated + public CompatibleItemSettings setId(CompatIdentifier identifier) { + this.identifier = identifier; + return this; + } + + public CompatibleItemSettings addGroup(ItemGroup itemGroup) { + super.addGroup(itemGroup, identifier); + return this; + } + + public CompatibleItemSettings addGroup(Supplier itemGroup) { + super.addGroup(itemGroup, identifier); + return this; + } + + @Override + public CompatibleItemSettings addGroup(CreativeTabBuilder itemGroup) { + super.addGroup(itemGroup); + return this; + } + + public CompatibleItemSettings addGroup(ItemGroupWrapper itemGroup) { + return addGroup(itemGroup.get()); + } + + @Override + public CompatibleItemSettings maxCount(int maxCount) { + super.maxCount(maxCount); + return this; + } + + @Override + public CompatibleItemSettings maxDamage(int maxDamage) { + super.maxDamage(maxDamage); + return this; + } + + @Override + public CompatibleItemSettings maxDamageIfAbsent(int maxDamage) { + super.maxDamageIfAbsent(maxDamage); + return this; + } + + @Override + public CompatibleItemSettings recipeRemainder(Item recipeRemainder) { + super.recipeRemainder(recipeRemainder); + this.recipeRemainder = recipeRemainder; + return this; + } + + public CompatibleItemSettings recipeRemainder(ItemWrapper recipeRemainder) { + return recipeRemainder(recipeRemainder.get()); + } + + @Deprecated + @Override + public CompatibleItemSettings rarity(Rarity rarity) { + super.rarity(rarity); + this.rarity = CompatRarity.of(rarity); + return this; + } + + public CompatibleItemSettings rarity(CompatRarity rarity) { + super.rarity(rarity.get()); + this.rarity = rarity; + return this; + } + + @Override + public CompatibleItemSettings food(CompatFoodComponent foodComponent) { + super.food(foodComponent); + return this; + } + + public CompatibleItemSettings useItemPrefixedTranslationKey() { + changedTranslationKey = true; + return this; + } + + public CompatibleItemSettings useBlockPrefixedTranslationKey() { + changedTranslationKey = true; + return this; + } + + public String translationKey = null; + + public CompatibleItemSettings translationKey(String translationKey) { + changedTranslationKey = true; + this.translationKey = translationKey; + return this; + } + + public CompatibleItemSettings enchantable(int enchantability) { + this.enchantability = enchantability; + return this; + } + + public CompatibleItemSettings repairable(RepairIngredientTag tag) { + this.repairIngredientTag = tag; + return this; + } + + public CompatibleItemSettings equipable(CompatEquippableComponent component) { + return this; + } + + public CompatibleItemSettings equipable(EquippableComponentBuilder builder) { + return equipable(builder.build()); + } + + public CompatibleItemSettings attributeModifiers(CompatAttributeModifiersComponent component) { + settings.component(DataComponentTypes.ATTRIBUTE_MODIFIERS, component.raw()); + return this; + } + + public CompatibleItemSettings attributeModifiers(AttributeModifiersComponentBuilder builder) { + return attributeModifiers(builder.build()); + } + + @Override + public ExtendSettings build() { + super.build(); + return settings; + } + + // Deprecated + + @Deprecated + @Override + public net.pitan76.mcpitanlib.api.item.CompatibleItemSettings addGroup(ItemGroup itemGroup, Identifier identifier) { + return super.addGroup(itemGroup, identifier); + } + + @Deprecated + @Override + public net.pitan76.mcpitanlib.api.item.CompatibleItemSettings addGroup(Supplier itemGroup, Identifier identifier) { + return super.addGroup(itemGroup, identifier); + } + + @Deprecated + @Override + public net.pitan76.mcpitanlib.api.item.CompatibleItemSettings addGroup(Supplier itemGroup, CompatIdentifier identifier) { + return super.addGroup(itemGroup, identifier); + } + + @Deprecated + @Override + public net.pitan76.mcpitanlib.api.item.CompatibleItemSettings addGroup(ItemGroup itemGroup, CompatIdentifier identifier) { + return super.addGroup(itemGroup, identifier); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/item/v2/ExtendBlockItem.java b/common/src/main/java/net/pitan76/mcpitanlib/api/item/v2/ExtendBlockItem.java new file mode 100644 index 000000000..518062201 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/v2/ExtendBlockItem.java @@ -0,0 +1,73 @@ +package net.pitan76.mcpitanlib.api.item.v2; + +import net.minecraft.block.Block; +import net.minecraft.item.BlockItem; +import net.minecraft.item.ItemStack; +import net.minecraft.item.ItemUsageContext; +import net.minecraft.item.tooltip.TooltipType; +import net.minecraft.text.Text; +import net.minecraft.util.ActionResult; +import net.pitan76.mcpitanlib.api.event.item.ItemAppendTooltipEvent; +import net.pitan76.mcpitanlib.api.event.item.ItemUseOnBlockEvent; +import net.pitan76.mcpitanlib.api.util.CompatActionResult; +import net.pitan76.mcpitanlib.mixin.ItemUsageContextMixin; + +import java.util.List; + +public class ExtendBlockItem extends BlockItem implements CompatItemProvider { + + public CompatibleItemSettings settings; + + @Deprecated + public ExtendBlockItem(Block block, Settings settings) { + super(block, settings); + } + + public ExtendBlockItem(Block block, CompatibleItemSettings settings) { + this(block, settings.build()); + this.settings = settings; + } + + @Override + public CompatibleItemSettings getCompatSettings() { + return settings; + } + + @Deprecated + @Override + public ActionResult useOnBlock(ItemUsageContext context) { + ItemUsageContextMixin contextAccessor = (ItemUsageContextMixin) context; + return onRightClickOnBlock(new ItemUseOnBlockEvent(context.getPlayer(), context.getHand(), contextAccessor.getHit())).toActionResult(); + } + + @Deprecated + @Override + public CompatActionResult onRightClickOnBlock(ItemUseOnBlockEvent event, Options options) { + return CompatItemProvider.super.onRightClickOnBlock(event, options); + } + + public CompatActionResult onRightClickOnBlock(ItemUseOnBlockEvent event) { + return CompatActionResult.create(super.useOnBlock(event.toIUC())); + } + + @Deprecated + @Override + public void appendTooltip(ItemStack stack, TooltipContext context, List tooltip, TooltipType type) { + appendTooltip(new ItemAppendTooltipEvent(stack, null, tooltip, type, context)); + } + + @Deprecated + @Override + public void appendTooltip(ItemAppendTooltipEvent event, Options options) { + CompatItemProvider.super.appendTooltip(event, options); + } + + public void appendTooltip(ItemAppendTooltipEvent event) { + super.appendTooltip(event.getStack(), event.getContext(), event.getTooltip(), event.type); + } + + @Override + public Block getBlock() { + return super.getBlock(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/item/v2/ItemSettingsBuilder.java b/common/src/main/java/net/pitan76/mcpitanlib/api/item/v2/ItemSettingsBuilder.java new file mode 100644 index 000000000..a980204e6 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/v2/ItemSettingsBuilder.java @@ -0,0 +1,153 @@ +package net.pitan76.mcpitanlib.api.item.v2; + +import net.pitan76.mcpitanlib.api.item.CompatFoodComponent; +import net.pitan76.mcpitanlib.api.item.CreativeTabBuilder; +import net.pitan76.mcpitanlib.api.item.ExtendSettings; +import net.pitan76.mcpitanlib.api.tag.item.RepairIngredientTag; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.api.util.CompatRarity; +import net.pitan76.mcpitanlib.midohra.item.ItemGroupWrapper; +import net.pitan76.mcpitanlib.midohra.item.ItemWrapper; + +public class ItemSettingsBuilder { + + public CompatIdentifier id; + public int maxCount = -1; + public int maxDamage = -1; + public int maxDamageIfAbsent = -1; + public int enchantability = -1; + public RepairIngredientTag repairIngredientTag; + public CompatFoodComponent foodComponent; + public CompatRarity rarity; + public ItemWrapper recipeRemainder; + + public ItemGroupWrapper itemGroupWrapper; + public CreativeTabBuilder itemGroupBuilder; + + public ItemSettingsBuilder(CompatIdentifier id) { + this.id = id; + } + + public ItemSettingsBuilder() { + + } + + public ItemSettingsBuilder addGroup(ItemGroupWrapper itemGroup) { + itemGroupWrapper = itemGroup; + return this; + } + + public ItemSettingsBuilder addGroup(CreativeTabBuilder itemGroup) { + itemGroupBuilder = itemGroup; + return this; + } + + public ItemSettingsBuilder maxCount(int maxCount) { + this.maxCount = maxCount; + return this; + } + + public ItemSettingsBuilder maxDamage(int maxDamage) { + this.maxDamage = maxDamage; + return this; + } + + public ItemSettingsBuilder maxDamageIfAbsent(int maxDamage) { + this.maxDamageIfAbsent = maxDamage; + return this; + } + + public ItemSettingsBuilder recipeRemainder(ItemWrapper recipeRemainder) { + this.recipeRemainder = recipeRemainder; + return this; + } + + public ItemSettingsBuilder enchantability(int enchantability) { + this.enchantability = enchantability; + return this; + } + + public ItemSettingsBuilder repairable(RepairIngredientTag repairIngredientTag) { + this.repairIngredientTag = repairIngredientTag; + return this; + } + + public ItemSettingsBuilder repairable(CompatIdentifier repairIngredientTag) { + this.repairIngredientTag = new RepairIngredientTag(repairIngredientTag); + return this; + } + + public ItemSettingsBuilder foodComponent(CompatFoodComponent foodComponent) { + this.foodComponent = foodComponent; + return this; + } + + public ItemSettingsBuilder rarity(CompatRarity rarity) { + this.rarity = rarity; + return this; + } + + public CompatibleItemSettings build() { + return build(id); + } + + public ExtendSettings _build() { + return build().build(); + } + + public CompatibleItemSettings build(CompatIdentifier id) { + CompatibleItemSettings settings = new CompatibleItemSettings(id); + + if (itemGroupWrapper != null) settings.addGroup(itemGroupWrapper); + if (itemGroupBuilder != null) settings.addGroup(itemGroupBuilder); + + if (maxCount != -1) settings.maxCount(maxCount); + + if (maxDamage != -1) settings.maxDamage(maxDamage); + + if (maxDamageIfAbsent != -1) settings.maxDamageIfAbsent(maxDamageIfAbsent); + + if (rarity != null) settings.rarity(rarity); + if (foodComponent != null) settings.food(foodComponent); + + if (recipeRemainder != null) settings.recipeRemainder(recipeRemainder); + + if (enchantability != -1) settings.enchantable(enchantability); + + if (repairIngredientTag != null) settings.repairable(repairIngredientTag); + + return settings; + } + + public ExtendSettings _build(CompatIdentifier id) { + return build(id).build(); + } + + public ItemSettingsBuilder copy(CompatIdentifier id) { + ItemSettingsBuilder builder = new ItemSettingsBuilder(); + builder.id = id; + builder.maxCount = this.maxCount; + builder.maxDamage = this.maxDamage; + builder.maxDamageIfAbsent = this.maxDamageIfAbsent; + builder.enchantability = this.enchantability; + builder.repairIngredientTag = this.repairIngredientTag; + builder.foodComponent = this.foodComponent; + builder.rarity = this.rarity; + builder.recipeRemainder = this.recipeRemainder; + builder.itemGroupWrapper = this.itemGroupWrapper; + builder.itemGroupBuilder = this.itemGroupBuilder; + return builder; + } + + public ItemSettingsBuilder copy() { + return copy(this.id); + } + + public static ItemSettingsBuilder of(CompatIdentifier id) { + return new ItemSettingsBuilder(id); + } + + public static ItemSettingsBuilder of() { + return new ItemSettingsBuilder(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/item/v3/CompatArmorMaterial.java b/common/src/main/java/net/pitan76/mcpitanlib/api/item/v3/CompatArmorMaterial.java new file mode 100644 index 000000000..4981d29fa --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/v3/CompatArmorMaterial.java @@ -0,0 +1,15 @@ +package net.pitan76.mcpitanlib.api.item.v3; + +import net.minecraft.recipe.Ingredient; +import net.pitan76.mcpitanlib.api.tag.item.RepairIngredientTag; + +public interface CompatArmorMaterial extends net.pitan76.mcpitanlib.api.item.v2.CompatArmorMaterial { + + @Deprecated + @Override + default Ingredient getRepairIngredient() { + return getRepairIngredientTag().getIngredient(); + } + + RepairIngredientTag getRepairIngredientTag(); +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/item/v3/CompatToolMaterial.java b/common/src/main/java/net/pitan76/mcpitanlib/api/item/v3/CompatToolMaterial.java new file mode 100644 index 000000000..02070e0f2 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/v3/CompatToolMaterial.java @@ -0,0 +1,15 @@ +package net.pitan76.mcpitanlib.api.item.v3; + +import net.minecraft.recipe.Ingredient; +import net.pitan76.mcpitanlib.api.item.tool.CompatibleToolMaterial; +import net.pitan76.mcpitanlib.api.tag.item.RepairIngredientTag; + +public interface CompatToolMaterial extends CompatibleToolMaterial { + @Deprecated + @Override + default Ingredient getRepairIngredient() { + return getRepairIngredientTag().getIngredient(); + } + + RepairIngredientTag getRepairIngredientTag(); +} \ No newline at end of file diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/item/v3/VanillaCompatToolMaterial.java b/common/src/main/java/net/pitan76/mcpitanlib/api/item/v3/VanillaCompatToolMaterial.java new file mode 100644 index 000000000..8d3ca27b9 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/v3/VanillaCompatToolMaterial.java @@ -0,0 +1,78 @@ +package net.pitan76.mcpitanlib.api.item.v3; + +import net.minecraft.block.Block; +import net.minecraft.item.ToolMaterial; +import net.minecraft.item.ToolMaterials; +import net.minecraft.registry.tag.TagKey; +import net.pitan76.mcpitanlib.api.tag.item.RepairIngredientTag; + +public class VanillaCompatToolMaterial implements CompatToolMaterial { + private final ToolMaterial material; + + public static final VanillaCompatToolMaterial WOOD = of(ToolMaterials.WOOD); + public static final VanillaCompatToolMaterial STONE = of(ToolMaterials.STONE); + public static final VanillaCompatToolMaterial IRON = of(ToolMaterials.IRON); + public static final VanillaCompatToolMaterial GOLD = of(ToolMaterials.GOLD); + public static final VanillaCompatToolMaterial DIAMOND = of(ToolMaterials.DIAMOND); + public static final VanillaCompatToolMaterial NETHERITE = of(ToolMaterials.NETHERITE); + + protected VanillaCompatToolMaterial(ToolMaterial material) { + this.material = material; + } + + private static VanillaCompatToolMaterial of(ToolMaterial material) { + return new VanillaCompatToolMaterial(material); + } + + @Override + public RepairIngredientTag getRepairIngredientTag() { + if (material == ToolMaterials.STONE) return RepairIngredientTag.STONE_TOOL_MATERIALS; + if (material == ToolMaterials.IRON) return RepairIngredientTag.IRON_TOOL_MATERIALS; + if (material == ToolMaterials.GOLD) return RepairIngredientTag.GOLDEN_TOOL_MATERIALS; + if (material == ToolMaterials.DIAMOND) return RepairIngredientTag.DIAMOND_TOOL_MATERIALS; + if (material == ToolMaterials.NETHERITE) return RepairIngredientTag.NETHERITE_TOOL_MATERIALS; + return RepairIngredientTag.WOODEN_TOOL_MATERIALS; + } + + @Override + public int getCompatDurability() { + return material.getDurability(); + } + + @Override + public float getCompatMiningSpeedMultiplier() { + return material.getMiningSpeedMultiplier(); + } + + @Override + public float getCompatAttackDamage() { + return material.getAttackDamage(); + } + + @Override + public int getCompatMiningLevel() { + TagKey tag = material.getInverseTag(); + if (tag == ToolMaterials.WOOD.getInverseTag()) return 0; + if (tag == ToolMaterials.STONE.getInverseTag()) return 1; + if (tag == ToolMaterials.IRON.getInverseTag()) return 2; + if (tag == ToolMaterials.GOLD.getInverseTag()) return 2; + if (tag == ToolMaterials.DIAMOND.getInverseTag()) return 3; + if (tag == ToolMaterials.NETHERITE.getInverseTag()) return 4; + return -1; + } + + @Override + public int getCompatEnchantability() { + return material.getEnchantability(); + } + + @Deprecated + public ToolMaterial toMinecraft() { + return material; + } + + @Override + public ToolMaterial build() { + return material; + } +} diff --git a/common/src/main/java/ml/pkom/mcpitanlibarch/api/nbt/NbtTag.java b/common/src/main/java/net/pitan76/mcpitanlib/api/nbt/NbtTag.java similarity index 78% rename from common/src/main/java/ml/pkom/mcpitanlibarch/api/nbt/NbtTag.java rename to common/src/main/java/net/pitan76/mcpitanlib/api/nbt/NbtTag.java index d27ae8aad..7d379f6e9 100644 --- a/common/src/main/java/ml/pkom/mcpitanlibarch/api/nbt/NbtTag.java +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/nbt/NbtTag.java @@ -1,9 +1,12 @@ -package ml.pkom.mcpitanlibarch.api.nbt; +package net.pitan76.mcpitanlib.api.nbt; +import net.minecraft.component.DataComponentTypes; +import net.minecraft.component.type.NbtComponent; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtType; +@Deprecated public class NbtTag extends NbtCompound { public NbtTag() { super(); @@ -35,7 +38,7 @@ public static NbtTag from(Object nbt) { * @return boolean */ public static boolean hasNbt(ItemStack stack) { - return stack.hasNbt(); + return !stack.getComponents().isEmpty(); } /** @@ -44,7 +47,7 @@ public static boolean hasNbt(ItemStack stack) { * @return NbtTag */ public static NbtTag getNbt(ItemStack stack) { - return from(stack.getNbt()); + return from(stack.get(DataComponentTypes.CUSTOM_DATA).copyNbt()); } /** @@ -53,7 +56,7 @@ public static NbtTag getNbt(ItemStack stack) { * @param nbt NbtTag */ public static void setNbt(ItemStack stack, NbtTag nbt) { - stack.setNbt(nbt); + stack.set(DataComponentTypes.CUSTOM_DATA, NbtComponent.of(nbt)); } public boolean contains(String key) { diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/nbt/NbtTypeBytes.java b/common/src/main/java/net/pitan76/mcpitanlib/api/nbt/NbtTypeBytes.java new file mode 100644 index 000000000..6f5a9757f --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/nbt/NbtTypeBytes.java @@ -0,0 +1,20 @@ +package net.pitan76.mcpitanlib.api.nbt; + +import net.minecraft.nbt.NbtElement; + +public class NbtTypeBytes { + public static final byte END = NbtElement.END_TYPE; + public static final byte BYTE = NbtElement.BYTE_TYPE; + public static final byte SHORT = NbtElement.SHORT_TYPE; + public static final byte INT = NbtElement.INT_TYPE; + public static final byte LONG = NbtElement.LONG_TYPE; + public static final byte FLOAT = NbtElement.FLOAT_TYPE; + public static final byte DOUBLE = NbtElement.DOUBLE_TYPE; + public static final byte BYTE_ARRAY = NbtElement.BYTE_ARRAY_TYPE; + public static final byte STRING = NbtElement.STRING_TYPE; + public static final byte LIST = NbtElement.LIST_TYPE; + public static final byte COMPOUND = NbtElement.COMPOUND_TYPE; + public static final byte INT_ARRAY = NbtElement.INT_ARRAY_TYPE; + public static final byte LONG_ARRAY = NbtElement.LONG_ARRAY_TYPE; + public static final byte NUMBER = NbtElement.NUMBER_TYPE; +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/network/ClientNetworking.java b/common/src/main/java/net/pitan76/mcpitanlib/api/network/ClientNetworking.java new file mode 100644 index 000000000..fada6c1bf --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/network/ClientNetworking.java @@ -0,0 +1,61 @@ +package net.pitan76.mcpitanlib.api.network; + +import dev.architectury.networking.NetworkManager; +import dev.architectury.networking.transformers.PacketTransformer; +import io.netty.buffer.Unpooled; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.network.ClientPlayerEntity; +import net.minecraft.network.PacketByteBuf; +import net.minecraft.network.RegistryByteBuf; +import net.minecraft.network.codec.PacketCodec; +import net.minecraft.network.packet.CustomPayload; +import net.minecraft.util.Identifier; +import net.pitan76.mcpitanlib.core.network.BufPayload; + +import java.util.List; + +import static dev.architectury.impl.NetworkAggregator.*; + +public class ClientNetworking { + public static void send(Identifier identifier, PacketByteBuf buf) { + /* + if (!C2S_TYPE.containsKey(identifier)) { + CustomPayload.Id type = new CustomPayload.Id<>(identifier); + C2S_TYPE.put(identifier, type); + //registerC2SType(type, NetworkAggregator.BufCustomPacketPayload.streamCodec(type), List.of()); + } + */ + + BufPayload payload = new BufPayload(buf, identifier); + NetworkManager.sendToServer(payload); + } + + public static void registerReceiver(Identifier identifier, ClientNetworkHandler handler) { + BufPayload.Id id = BufPayload.id(identifier); + + NetworkManager.registerReceiver(NetworkManager.Side.S2C, id, BufPayload.getCodec(id), + (payload, context) -> { + PacketByteBuf buf = new PacketByteBuf(Unpooled.wrappedBuffer(payload.getData())); + + ClientPlayerEntity player = null; + if (context.getPlayer() instanceof ClientPlayerEntity) + player = (ClientPlayerEntity) context.getPlayer(); + + handler.receive(MinecraftClient.getInstance(), player, buf); + buf.release(); + }); + } + + @FunctionalInterface + public interface ClientNetworkHandler { + void receive(MinecraftClient client, ClientPlayerEntity player, PacketByteBuf buf); + } + + + public static void registerC2SType(CustomPayload.Id type, PacketCodec codec, List packetTransformers) { +// Objects.requireNonNull(type, "Cannot register a null type!"); +// packetTransformers = Objects.requireNonNullElse(packetTransformers, List.of()); +// C2S_CODECS.put(type.id(), (PacketCodec) codec); +// C2S_TRANSFORMERS.put(type.id(), PacketTransformer.concat(packetTransformers)); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/network/PacketByteUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/network/PacketByteUtil.java new file mode 100644 index 000000000..e1d651760 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/network/PacketByteUtil.java @@ -0,0 +1,259 @@ +package net.pitan76.mcpitanlib.api.network; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NbtCompound; +import net.minecraft.nbt.NbtElement; +import net.minecraft.nbt.NbtSizeTracker; +import net.minecraft.network.PacketByteBuf; +import net.minecraft.text.Text; +import net.minecraft.util.Identifier; +import net.minecraft.util.math.BlockPos; +import net.pitan76.mcpitanlib.api.util.TextUtil; + +import java.util.Map; +import java.util.UUID; +import java.util.function.BiConsumer; +import java.util.function.Function; + +public class PacketByteUtil { + public static PacketByteBuf create() { + return new PacketByteBuf(Unpooled.buffer()); + } + + + public static PacketByteBuf empty() { + return new PacketByteBuf(Unpooled.EMPTY_BUFFER); + } + + public static Map readMap(PacketByteBuf buf, Function keyParser, Function valueParser) { + return buf.readMap(keyParser::apply, valueParser::apply); + } + + public static void writeMap(PacketByteBuf buf, Map map) { + writeMap(buf, map, PacketByteUtil::writeVar, PacketByteUtil::writeVar); + } + + public static void writeMap(PacketByteBuf buf, Map map, BiConsumer keySerializer, BiConsumer valueSerializer) { + buf.writeMap(map, keySerializer::accept, valueSerializer::accept); + } + + public static void writeVar(PacketByteBuf buf, Object obj) { + if (obj instanceof String) { + String s = (String) obj; + buf.writeString(s); + } + if (obj instanceof Integer) { + int i = (int) obj; + buf.writeInt(i); + } + if (obj instanceof Long) { + long l = (long) obj; + buf.writeLong(l); + } + if (obj instanceof Short) { + short s = (short) obj; + buf.writeShort(s); + } + if (obj instanceof Boolean) { + boolean b = (boolean) obj; + buf.writeBoolean(b); + } + if (obj instanceof Byte) { + byte b = (byte) obj; + buf.writeByte(b); + } + if (obj instanceof NbtCompound) { + NbtCompound nbt = (NbtCompound) obj; + buf.writeNbt(nbt); + } + if (obj instanceof ItemStack) { + ItemStack stack = (ItemStack) obj; + buf.encodeAsJson(ItemStack.CODEC, stack); + } + if (obj instanceof Identifier) { + Identifier identifier = (Identifier) obj; + buf.writeIdentifier(identifier); + } + if (obj instanceof Float) { + Float f = (Float) obj; + buf.writeFloat(f); + } + if (obj instanceof UUID) { + UUID uuid = (UUID) obj; + buf.writeUuid(uuid); + } + if (obj instanceof Text) { + Text text = (Text) obj; + buf.writeString(text.getString()); + } + if (obj instanceof BlockPos) { + BlockPos pos = (BlockPos) obj; + buf.writeBlockPos(pos); + } + if (obj instanceof Map) { + Map map = (Map) obj; + writeMap(buf, map); + } + } + + public static PacketByteBuf writeNbt(PacketByteBuf buf, NbtCompound nbt) { + return buf.writeNbt(nbt); + } + + public static NbtCompound readNbt(PacketByteBuf buf) { + return buf.readNbt(); + } + + public static PacketByteBuf writeItemStack(PacketByteBuf buf, ItemStack stack) { + buf.encodeAsJson(ItemStack.CODEC, stack); + return buf; + } + + public static ItemStack readItemStack(PacketByteBuf buf) { + return buf.decodeAsJson(ItemStack.CODEC); + } + + public static PacketByteBuf writeIdentifier(PacketByteBuf buf, Identifier identifier) { + return buf.writeIdentifier(identifier); + } + + public static Identifier readIdentifier(PacketByteBuf buf) { + return buf.readIdentifier(); + } + + public static PacketByteBuf writeText(PacketByteBuf buf, Text text) { + return buf.writeString(text.getString()); + } + + public static Text readText(PacketByteBuf buf) { + return TextUtil.literal(buf.readString()); + } + + public static PacketByteBuf writeBlockPos(PacketByteBuf buf, BlockPos pos) { + return buf.writeBlockPos(pos); + } + + public static BlockPos readBlockPos(PacketByteBuf buf) { + return buf.readBlockPos(); + } + + public static PacketByteBuf writeUuid(PacketByteBuf buf, UUID uuid) { + return buf.writeUuid(uuid); + } + + public static UUID readUuid(PacketByteBuf buf) { + return buf.readUuid(); + } + + public static PacketByteBuf writeVarInt(PacketByteBuf buf, int i) { + return buf.writeVarInt(i); + } + + public static int readVarInt(PacketByteBuf buf) { + return buf.readVarInt(); + } + + public static PacketByteBuf writeVarLong(PacketByteBuf buf, long l) { + return buf.writeVarLong(l); + } + + public static long readVarLong(PacketByteBuf buf) { + return buf.readVarLong(); + } + + public static ByteBuf writeBoolean(PacketByteBuf buf, boolean b) { + return buf.writeBoolean(b); + } + + public static boolean readBoolean(PacketByteBuf buf) { + return buf.readBoolean(); + } + + public static ByteBuf writeByte(PacketByteBuf buf, byte b) { + return buf.writeByte(b); + } + + public static byte readByte(PacketByteBuf buf) { + return buf.readByte(); + } + + public static ByteBuf writeShort(PacketByteBuf buf, short s) { + return buf.writeShort(s); + } + + public static short readShort(PacketByteBuf buf) { + return buf.readShort(); + } + + public static ByteBuf writeInt(PacketByteBuf buf, int i) { + return buf.writeInt(i); + } + + public static int readInt(PacketByteBuf buf) { + return buf.readInt(); + } + + public static ByteBuf writeLong(PacketByteBuf buf, long l) { + return buf.writeLong(l); + } + + public static long readLong(PacketByteBuf buf) { + return buf.readLong(); + } + + public static ByteBuf writeFloat(PacketByteBuf buf, float f) { + return buf.writeFloat(f); + } + + public static float readFloat(PacketByteBuf buf) { + return buf.readFloat(); + } + + public static ByteBuf writeDouble(PacketByteBuf buf, double d) { + return buf.writeDouble(d); + } + + public static double readDouble(PacketByteBuf buf) { + return buf.readDouble(); + } + + public static PacketByteBuf writeByteArray(PacketByteBuf buf, byte[] bytes) { + return buf.writeByteArray(bytes); + } + + public static byte[] readByteArray(PacketByteBuf buf) { + return buf.readByteArray(); + } + + public static PacketByteBuf writeString(PacketByteBuf buf, String s) { + return buf.writeString(s); + } + + public static String readString(PacketByteBuf buf) { + return buf.readString(); + } + + public static PacketByteBuf writeIntArray(PacketByteBuf buf, int[] ints) { + return buf.writeIntArray(ints); + } + + public static int[] readIntArray(PacketByteBuf buf) { + return buf.readIntArray(); + } + + public static PacketByteBuf writeLongArray(PacketByteBuf buf, long[] longs) { + return buf.writeLongArray(longs); + } + + public static long[] readLongArray(PacketByteBuf buf) { + return buf.readLongArray(); + } + + public static NbtElement readUnlimitedNbt(PacketByteBuf buf) { + return buf.readNbt(NbtSizeTracker.ofUnlimitedBytes()); + } +} + + diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/network/ServerNetworking.java b/common/src/main/java/net/pitan76/mcpitanlib/api/network/ServerNetworking.java new file mode 100644 index 000000000..be46acde0 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/network/ServerNetworking.java @@ -0,0 +1,65 @@ +package net.pitan76.mcpitanlib.api.network; + +import dev.architectury.impl.NetworkAggregator; +import dev.architectury.networking.NetworkManager; +import io.netty.buffer.Unpooled; +import net.minecraft.network.PacketByteBuf; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.util.Identifier; +import net.pitan76.mcpitanlib.core.network.BufPayload; + +import java.util.ArrayList; +import java.util.List; + +public class ServerNetworking { + public static void send(ServerPlayerEntity player, Identifier identifier, PacketByteBuf buf) { + registerS2CPayloadType(identifier); + + BufPayload payload = new BufPayload(buf, identifier); + NetworkManager.sendToPlayer(player, payload); + } + + public static void send(Iterable players, Identifier identifier, PacketByteBuf buf) { + registerS2CPayloadType(identifier); + + BufPayload payload = new BufPayload(buf, identifier); + NetworkManager.sendToPlayers(players, payload); + } + + public static void sendAll(MinecraftServer server, Identifier identifier, PacketByteBuf buf) { + send(server.getPlayerManager().getPlayerList(), identifier, buf); + } + + public static void registerReceiver(Identifier identifier, ServerNetworkHandler handler) { + BufPayload.Id id = BufPayload.id(identifier); + NetworkManager.registerReceiver(NetworkManager.Side.C2S, id, BufPayload.getCodec(id), + (payload, context) -> { + PacketByteBuf buf = new PacketByteBuf(Unpooled.wrappedBuffer(payload.getData())); + + ServerPlayerEntity player = null; + if (context.getPlayer() instanceof ServerPlayerEntity) + player = (ServerPlayerEntity) context.getPlayer(); + + handler.receive(context.getPlayer().getServer(), player, buf); + buf.release(); + }); + } + + private static final List registeredList = new ArrayList<>(); + + public static void registerS2CPayloadType(Identifier identifier) { + if (registeredList.contains(identifier)) return; + registeredList.add(identifier); + + if (NetworkAggregator.S2C_CODECS.containsKey(identifier)) return; + + BufPayload.Id id = BufPayload.id(identifier); + NetworkManager.registerS2CPayloadType(id, BufPayload.getCodec(id)); + } + + @FunctionalInterface + public interface ServerNetworkHandler { + void receive(MinecraftServer server, ServerPlayerEntity player, PacketByteBuf buf); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/network/v2/ClientNetworking.java b/common/src/main/java/net/pitan76/mcpitanlib/api/network/v2/ClientNetworking.java new file mode 100644 index 000000000..67fef00ce --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/network/v2/ClientNetworking.java @@ -0,0 +1,29 @@ +package net.pitan76.mcpitanlib.api.network.v2; + +import net.minecraft.network.PacketByteBuf; +import net.pitan76.mcpitanlib.api.network.PacketByteUtil; +import net.pitan76.mcpitanlib.api.network.v2.args.ClientReceiveEvent; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.midohra.network.CompatPacketByteBuf; + +import java.util.function.Consumer; + +public class ClientNetworking { + public static void send(CompatIdentifier id, PacketByteBuf buf) { + net.pitan76.mcpitanlib.api.network.ClientNetworking.send(id.toMinecraft(), buf); + } + + public static void registerReceiver(CompatIdentifier id, Consumer consumer) { + net.pitan76.mcpitanlib.api.network.ClientNetworking.registerReceiver(id.toMinecraft(), (client, player, buf) -> { + consumer.accept(new ClientReceiveEvent(client, player, buf)); + }); + } + + public static void send(CompatIdentifier id, CompatPacketByteBuf buf) { + send(id, buf.getRaw()); + } + + public static void send(CompatIdentifier id) { + send(id, PacketByteUtil.create()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/network/v2/ServerNetworking.java b/common/src/main/java/net/pitan76/mcpitanlib/api/network/v2/ServerNetworking.java new file mode 100644 index 000000000..f5356c9d0 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/network/v2/ServerNetworking.java @@ -0,0 +1,97 @@ +package net.pitan76.mcpitanlib.api.network.v2; + +import net.minecraft.network.PacketByteBuf; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.entity.Player; +import net.pitan76.mcpitanlib.api.network.PacketByteUtil; +import net.pitan76.mcpitanlib.api.network.v2.args.ServerReceiveEvent; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.midohra.network.CompatPacketByteBuf; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import java.util.function.Consumer; + +public class ServerNetworking { + public static void send(ServerPlayerEntity serverPlayerEntity, CompatIdentifier id, PacketByteBuf buf) { + net.pitan76.mcpitanlib.api.network.ServerNetworking.send(serverPlayerEntity, id.toMinecraft(), buf); + } + + public static void sendByServerPlayerEntity(Iterable players, CompatIdentifier id, PacketByteBuf buf) { + net.pitan76.mcpitanlib.api.network.ServerNetworking.send(players, id.toMinecraft(), buf); + } + + public static void send(Player player, CompatIdentifier id, PacketByteBuf buf) { + Optional optional = player.getServerPlayer(); + if (optional.isEmpty()) return; + + send(optional.get(), id, buf); + } + + public static void send(Iterable players, CompatIdentifier id, PacketByteBuf buf) { + List list = new ArrayList<>(); + for (Player player : players) { + Optional optional = player.getServerPlayer(); + optional.ifPresent(list::add); + } + + sendByServerPlayerEntity(list, id, buf); + } + + public static void sendAll(MinecraftServer server, CompatIdentifier id, PacketByteBuf buf) { + net.pitan76.mcpitanlib.api.network.ServerNetworking.sendAll(server, id.toMinecraft(), buf); + } + + public static void sendAll(World world, CompatIdentifier id, PacketByteBuf buf) { + sendAll(world.getServer(), id, buf); + } + + public static void registerReceiver(CompatIdentifier id, Consumer consumer) { + net.pitan76.mcpitanlib.api.network.ServerNetworking.registerReceiver(id.toMinecraft(), (server, player, buf) -> { + consumer.accept(new ServerReceiveEvent(server, player, buf)); + }); + } + + public static void send(ServerPlayerEntity serverPlayerEntity, CompatIdentifier id, CompatPacketByteBuf buf) { + send(serverPlayerEntity, id, buf.getRaw()); + } + + public static void send(Player player, CompatIdentifier id, CompatPacketByteBuf buf) { + send(player, id, buf.getRaw()); + } + + public static void send(Iterable players, CompatIdentifier id, CompatPacketByteBuf buf) { + send(players, id, buf.getRaw()); + } + + public static void sendAll(MinecraftServer server, CompatIdentifier id, CompatPacketByteBuf buf) { + sendAll(server, id, buf.getRaw()); + } + + public static void sendAll(World world, CompatIdentifier id, CompatPacketByteBuf buf) { + sendAll(world.getServer(), id, buf.getRaw()); + } + + public static void send(ServerPlayerEntity serverPlayerEntity, CompatIdentifier id) { + send(serverPlayerEntity, id, PacketByteUtil.create()); + } + + public static void send(Player player, CompatIdentifier id) { + send(player, id, PacketByteUtil.create()); + } + + public static void send(Iterable players, CompatIdentifier id) { + send(players, id, PacketByteUtil.create()); + } + + public static void sendAll(MinecraftServer server, CompatIdentifier id) { + sendAll(server, id, PacketByteUtil.create()); + } + + public static void sendAll(World world, CompatIdentifier id) { + sendAll(world.getServer(), id, PacketByteUtil.create()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/network/v2/args/ClientReceiveEvent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/network/v2/args/ClientReceiveEvent.java new file mode 100644 index 000000000..568c74d07 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/network/v2/args/ClientReceiveEvent.java @@ -0,0 +1,50 @@ +package net.pitan76.mcpitanlib.api.network.v2.args; + +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.network.ClientPlayerEntity; +import net.minecraft.network.PacketByteBuf; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.entity.Player; +import net.pitan76.mcpitanlib.midohra.network.CompatPacketByteBuf; + +public class ClientReceiveEvent { + public MinecraftClient client; + public ClientPlayerEntity clientPlayer; + public Player player; + public PacketByteBuf buf; + + public ClientReceiveEvent(MinecraftClient client, ClientPlayerEntity player, PacketByteBuf buf) { + this.client = client; + this.clientPlayer = player; + this.player = new Player(player); + this.buf = buf; + } + + public ClientPlayerEntity getClientPlayer() { + return clientPlayer; + } + + public Player getPlayer() { + return player; + } + + public MinecraftClient getClient() { + return client; + } + + public PacketByteBuf getBuf() { + return buf; + } + + public CompatPacketByteBuf getCompatBuf() { + return CompatPacketByteBuf.of(buf); + } + + public World getWorld() { + return getPlayer().getWorld(); + } + + public net.pitan76.mcpitanlib.midohra.world.World getMidohraWorld() { + return net.pitan76.mcpitanlib.midohra.world.World.of(getWorld()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/network/v2/args/ServerReceiveEvent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/network/v2/args/ServerReceiveEvent.java new file mode 100644 index 000000000..3fbe2834e --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/network/v2/args/ServerReceiveEvent.java @@ -0,0 +1,59 @@ +package net.pitan76.mcpitanlib.api.network.v2.args; + +import net.minecraft.network.PacketByteBuf; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.entity.Player; +import net.pitan76.mcpitanlib.midohra.network.CompatPacketByteBuf; +import net.pitan76.mcpitanlib.midohra.server.MCServer; + +public class ServerReceiveEvent { + public MinecraftServer server; + public ServerPlayerEntity serverPlayer; + public Player player; + public PacketByteBuf buf; + + public ServerReceiveEvent(MinecraftServer server, ServerPlayerEntity player, PacketByteBuf buf) { + this.server = server; + this.serverPlayer = player; + this.player = new Player(player); + this.buf = buf; + } + + public ServerPlayerEntity getServerPlayer() { + return serverPlayer; + } + + public Player getPlayer() { + return player; + } + + public MinecraftServer getServer() { + return server; + } + + public PacketByteBuf getBuf() { + return buf; + } + + public World getWorld() { + return getPlayer().getWorld(); + } + + public net.pitan76.mcpitanlib.midohra.world.World getMidohraWorld() { + return net.pitan76.mcpitanlib.midohra.world.World.of(getWorld()); + } + + public MCServer getMidohraServer() { + return MCServer.of(server); + } + + public CompatPacketByteBuf getCompatBuf() { + return CompatPacketByteBuf.of(buf); + } + + public void execute(Runnable runnable) { + server.execute(runnable); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/offlineplayer/OfflinePlayer.java b/common/src/main/java/net/pitan76/mcpitanlib/api/offlineplayer/OfflinePlayer.java new file mode 100644 index 000000000..1bb470b52 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/offlineplayer/OfflinePlayer.java @@ -0,0 +1,37 @@ +package net.pitan76.mcpitanlib.api.offlineplayer; + +import net.pitan76.mcpitanlib.api.entity.Player; +import net.pitan76.mcpitanlib.midohra.server.PlayerManager; + +import java.util.Optional; +import java.util.UUID; + +public class OfflinePlayer { + public String uuid; + public String name; + + public OfflinePlayer(String uuid, String name) { + this.uuid = uuid; + this.name = name; + } + + public String getUUIDasString() { + return uuid; + } + + public String getName() { + return name; + } + + public UUID getUUID() { + return UUID.fromString(uuid); + } + + public Optional getOnlinePlayer(PlayerManager playerManager) { + return OfflinePlayerManager.getOnlinePlayer(this, playerManager); + } + + public boolean isOnline(PlayerManager playerManager) { + return playerManager.hasPlayerByUUID(getUUID()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/offlineplayer/OfflinePlayerManager.java b/common/src/main/java/net/pitan76/mcpitanlib/api/offlineplayer/OfflinePlayerManager.java new file mode 100644 index 000000000..7eecbaf2c --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/offlineplayer/OfflinePlayerManager.java @@ -0,0 +1,229 @@ +package net.pitan76.mcpitanlib.api.offlineplayer; + +import net.pitan76.easyapi.FileControl; +import net.pitan76.easyapi.config.JsonConfig; +import net.pitan76.mcpitanlib.api.entity.Player; +import net.pitan76.mcpitanlib.api.util.PlatformUtil; +import net.pitan76.mcpitanlib.midohra.server.PlayerManager; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import java.util.UUID; + +public class OfflinePlayerManager { + public static OfflinePlayerManager INSTANCE = new OfflinePlayerManager(); + public static final File DEFAULT_FILE = new File(PlatformUtil.getConfigFolderAsFile(), "mcpitanlib/offlineplayer.json"); + + private final List offlinePlayers = new ArrayList<>(); + + protected OfflinePlayerManager() { + if (INSTANCE == null) + INSTANCE = this; + load(); + } + + public File getFile() { + return DEFAULT_FILE; + } + + public void load() { + if (FileControl.fileExists(getFile())) { + JsonConfig config = new JsonConfig(getFile()); + config.configMap.forEach((key, value) -> offlinePlayers.add(new OfflinePlayer(key, (String) value))); + } + } + + public void save() { + if (!FileControl.fileExists(getFile().getParentFile())) { + getFile().getParentFile().mkdirs(); + } + JsonConfig config = new JsonConfig(); + offlinePlayers.forEach(offlinePlayer -> config.set(offlinePlayer.uuid, offlinePlayer.name)); + config.save(getFile(), true); + } + + public OfflinePlayer getPlayer(String uuid) { + for (OfflinePlayer offlinePlayer : offlinePlayers) { + if (offlinePlayer.uuid.equals(uuid)) { + return offlinePlayer; + } + } + return null; + } + + public OfflinePlayer getPlayerByName(String name) { + for (OfflinePlayer offlinePlayer : offlinePlayers) { + if (offlinePlayer.name.equals(name)) { + return offlinePlayer; + } + } + return null; + } + + public void addPlayer(OfflinePlayer offlinePlayer) { + offlinePlayers.add(offlinePlayer); + } + + public void removePlayer(OfflinePlayer offlinePlayer) { + offlinePlayers.remove(offlinePlayer); + } + + public void addPlayer(String uuid, String name) { + if (containsPlayerByUUID(uuid)) + return; + addPlayer(new OfflinePlayer(uuid, name)); + } + + public void removePlayer(String uuid) { + removePlayer(getPlayer(uuid)); + } + + public boolean containsPlayerByUUID(String uuid) { + return getPlayer(uuid) != null; + } + + public boolean containsPlayerByName(String name) { + return getPlayerByName(name) != null; + } + + public boolean containsPlayer(OfflinePlayer offlinePlayer) { + return offlinePlayers.contains(offlinePlayer); + } + + public boolean containsPlayer(UUID uuid) { + return containsPlayerByUUID(uuid.toString()); + } + + public static Optional getOnlinePlayer(UUID uuid, PlayerManager playerManager) { + if (playerManager.hasPlayerByUUID(uuid)) + return Optional.of(playerManager.getPlayerByUUID(uuid)); + + return Optional.empty(); + } + + public static Optional getOnlinePlayerByName(String name, PlayerManager playerManager) { + if (playerManager.hasPlayerByName(name)) + return Optional.of(playerManager.getPlayerByName(name)); + + return Optional.empty(); + } + + public static Optional getOnlinePlayerByUUID(String uuid, PlayerManager playerManager) { + return getOnlinePlayer(UUID.fromString(uuid), playerManager); + } + + public static Optional getOnlinePlayer(OfflinePlayer offlinePlayer, PlayerManager playerManager) { + return getOnlinePlayer(UUID.fromString(offlinePlayer.uuid), playerManager); + } + + public UUID getUUID(String name) { + return UUID.fromString(getUUIDasString(name)); + } + + public String getName(UUID uuid) { + for (OfflinePlayer offlinePlayer : offlinePlayers) { + if (offlinePlayer.uuid.equals(uuid.toString())) { + return offlinePlayer.name; + } + } + return null; + } + + public String getUUIDasString(String name) { + for (OfflinePlayer offlinePlayer : offlinePlayers) { + if (offlinePlayer.name.equals(name)) { + return offlinePlayer.uuid; + } + } + return null; + } + + public List getOfflinePlayers() { + return offlinePlayers; + } + + public void clear() { + offlinePlayers.clear(); + } + + public void reload() { + clear(); + load(); + } + + public void saveAndReload() { + save(); + reload(); + } + + public void saveAndReloadAsync() { + new Thread(() -> { + save(); + reload(); + }).start(); + } + + public void saveAsync() { + new Thread(this::save).start(); + } + + public void reloadAsync() { + new Thread(this::reload).start(); + } + + public void clearAsync() { + new Thread(this::clear).start(); + } + + public void saveAndReloadAsync(Runnable runnable) { + new Thread(() -> { + save(); + reload(); + runnable.run(); + }).start(); + } + + public void saveAsync(Runnable runnable) { + new Thread(() -> { + save(); + runnable.run(); + }).start(); + } + + public void reloadAsync(Runnable runnable) { + new Thread(() -> { + reload(); + runnable.run(); + }).start(); + } + + public void clearAsync(Runnable runnable) { + new Thread(() -> { + clear(); + runnable.run(); + }).start(); + } + + public void saveAndReload(Runnable runnable) { + save(); + reload(); + runnable.run(); + } + + public void save(Runnable runnable) { + save(); + runnable.run(); + } + + public void reload(Runnable runnable) { + reload(); + runnable.run(); + } + + public void clear(Runnable runnable) { + clear(); + runnable.run(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/packet/UpdatePacketType.java b/common/src/main/java/net/pitan76/mcpitanlib/api/packet/UpdatePacketType.java new file mode 100644 index 000000000..2690dae1c --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/packet/UpdatePacketType.java @@ -0,0 +1,26 @@ +package net.pitan76.mcpitanlib.api.packet; + +public class UpdatePacketType { + public static final UpdatePacketType NONE = new UpdatePacketType("NONE"); + public static final UpdatePacketType BLOCK_ENTITY_UPDATE_S2C = new UpdatePacketType("BLOCK_ENTITY_UPDATE_S2C"); + + public final String name; + + public UpdatePacketType(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public UpdatePacketType fromName(String name) { + switch (name) { + case "NONE": + return NONE; + case "BLOCK_ENTITY_UPDATE_S2C": + return BLOCK_ENTITY_UPDATE_S2C; + } + return null; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/recipe/CompatRecipeType.java b/common/src/main/java/net/pitan76/mcpitanlib/api/recipe/CompatRecipeType.java new file mode 100644 index 000000000..a68005e01 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/recipe/CompatRecipeType.java @@ -0,0 +1,57 @@ +package net.pitan76.mcpitanlib.api.recipe; + +import net.minecraft.recipe.*; +import net.minecraft.registry.Registries; +import net.minecraft.util.Identifier; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; + +@Deprecated +public class CompatRecipeType> { + public static final CompatRecipeType CRAFTING = new CompatRecipeType<>(RecipeType.CRAFTING); + public static final CompatRecipeType SMELTING = new CompatRecipeType<>(RecipeType.SMELTING); + public static final CompatRecipeType BLASTING = new CompatRecipeType<>(RecipeType.BLASTING); + public static final CompatRecipeType SMOKING = new CompatRecipeType<>(RecipeType.SMOKING); + public static final CompatRecipeType CAMPFIRE_COOKING = new CompatRecipeType<>(RecipeType.CAMPFIRE_COOKING); + public static final CompatRecipeType STONECUTTING = new CompatRecipeType<>(RecipeType.STONECUTTING); + public static final CompatRecipeType SMITHING = new CompatRecipeType<>(RecipeType.SMITHING); + + private final RecipeType type; + + public CompatRecipeType(String id) { + this(RecipeType.register(id)); + } + + public CompatRecipeType(RecipeType type) { + this.type = type; + } + + public RecipeType getType() { + return type; + } + + public CompatIdentifier getName() { + Identifier id = Registries.RECIPE_TYPE.getId(type); + if (id == null) return CompatIdentifier.empty(); + + return CompatIdentifier.fromMinecraft(id); + } + + public static CompatRecipeType of(CompatIdentifier id) { + RecipeType type = Registries.RECIPE_TYPE.get(id.toMinecraft()); + if (type == null) return null; + + return new CompatRecipeType<>(type); + } + + public static > CompatRecipeType of(CompatIdentifier id, Class clazz) { + return (CompatRecipeType) of(id); + } + + public static > CompatRecipeType of(RecipeType type) { + return new CompatRecipeType<>(type); + } + + public net.pitan76.mcpitanlib.midohra.recipe.RecipeType toMidohra() { + return net.pitan76.mcpitanlib.midohra.recipe.RecipeType.of(type); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/recipe/CompatibleRecipeEntry.java b/common/src/main/java/net/pitan76/mcpitanlib/api/recipe/CompatibleRecipeEntry.java new file mode 100644 index 000000000..b4971fbef --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/recipe/CompatibleRecipeEntry.java @@ -0,0 +1,74 @@ +package net.pitan76.mcpitanlib.api.recipe; + +import net.minecraft.recipe.*; +import net.minecraft.util.Identifier; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.api.util.RecipeUtil; +import org.jetbrains.annotations.Nullable; + +@Deprecated +public class CompatibleRecipeEntry { + private final RecipeEntry entry; + + public String group = ""; + public RecipeUtil.CompatibilityCraftingRecipeCategory category = null; + + @Deprecated + public CompatibleRecipeEntry(RecipeEntry entry) { + this.entry = entry; + } + + public CompatibleRecipeEntry(Identifier id, String group, RecipeUtil.CompatibilityCraftingRecipeCategory category, ShapelessRecipe shapelessRecipe) { + this.entry = new RecipeEntry<>(id, shapelessRecipe); + this.group = group; + this.category = category; + } + + public CompatibleRecipeEntry(CompatIdentifier id, String group, RecipeUtil.CompatibilityCraftingRecipeCategory category, ShapelessRecipe shapelessRecipe) { + this(id.toMinecraft(), group, category, shapelessRecipe); + } + + @Deprecated + public RecipeEntry getRecipeEntry() { + return entry; + } + + public Recipe getRecipe() { + Object object = entry.value(); + if (object instanceof Recipe) { + return (Recipe) object; + } + return null; + } + + public Identifier getId() { + return entry.id(); + } + + public CompatIdentifier getCompatId() { + return CompatIdentifier.fromMinecraft(getId()); + } + + public RecipeType getType() { + Recipe recipe = getRecipe(); + if (recipe == null) return null; + + return recipe.getType(); + } + + public RecipeSerializer getSerializer() { + Recipe recipe = getRecipe(); + if (recipe == null) return null; + + return recipe.getSerializer(); + } + + @Nullable + public RecipeUtil.CompatibilityCraftingRecipeCategory getCategory() { + return category; + } + + public String getGroup() { + return group; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/recipe/MatchGetter.java b/common/src/main/java/net/pitan76/mcpitanlib/api/recipe/MatchGetter.java new file mode 100644 index 000000000..e0ec74ef3 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/recipe/MatchGetter.java @@ -0,0 +1,14 @@ +package net.pitan76.mcpitanlib.api.recipe; + +import net.minecraft.recipe.Recipe; +import net.minecraft.recipe.input.RecipeInput; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.recipe.input.CompatRecipeInput; +import net.pitan76.mcpitanlib.api.recipe.v2.CompatRecipeEntry; + +import java.util.Optional; + +@Deprecated +public interface MatchGetter> { + Optional> getFirstMatch(CompatRecipeInput input, World world); +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/recipe/input/CompatRecipeInput.java b/common/src/main/java/net/pitan76/mcpitanlib/api/recipe/input/CompatRecipeInput.java new file mode 100644 index 000000000..c7904361e --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/recipe/input/CompatRecipeInput.java @@ -0,0 +1,32 @@ +package net.pitan76.mcpitanlib.api.recipe.input; + +import net.minecraft.item.ItemStack; +import net.minecraft.recipe.input.RecipeInput; + +public class CompatRecipeInput { + protected I input; + + public CompatRecipeInput(I input) { + this.input = input; + } + + public I getInput() { + return input; + } + + public ItemStack getStack(int slot) { + return input.getStackInSlot(slot); + } + + public net.pitan76.mcpitanlib.midohra.item.ItemStack getMidohraStack(int slot) { + return net.pitan76.mcpitanlib.midohra.item.ItemStack.of(getStack(slot)); + } + + public int getSize() { + return input.getSize(); + } + + public boolean isEmpty() { + return input.isEmpty(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/recipe/v2/CompatRecipeEntry.java b/common/src/main/java/net/pitan76/mcpitanlib/api/recipe/v2/CompatRecipeEntry.java new file mode 100644 index 000000000..643ee203a --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/recipe/v2/CompatRecipeEntry.java @@ -0,0 +1,74 @@ +package net.pitan76.mcpitanlib.api.recipe.v2; + +import net.minecraft.recipe.*; +import net.minecraft.util.Identifier; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.api.util.RecipeUtil; +import org.jetbrains.annotations.Nullable; + +@Deprecated +public class CompatRecipeEntry> { + private final RecipeEntry entry; + + public String group = ""; + public RecipeUtil.CompatibilityCraftingRecipeCategory category = null; + + @Deprecated + public CompatRecipeEntry(RecipeEntry entry) { + this.entry = entry; + } + + public CompatRecipeEntry(Identifier id, String group, RecipeUtil.CompatibilityCraftingRecipeCategory category, T recipe) { + this.entry = new RecipeEntry<>(id, recipe); + this.group = group; + this.category = category; + } + + public CompatRecipeEntry(CompatIdentifier id, String group, RecipeUtil.CompatibilityCraftingRecipeCategory category, T recipe) { + this(id.toMinecraft(), group, category, recipe); + } + + public boolean isNull() { + return entry == null; + } + + @Deprecated + public RecipeEntry getRecipeEntry() { + return entry; + } + + public T getRecipe() { + return entry.value(); + } + + public Identifier getId() { + return entry.id(); + } + + public CompatIdentifier getCompatId() { + return CompatIdentifier.fromMinecraft(getId()); + } + + public RecipeType getType() { + T recipe = getRecipe(); + if (recipe == null) return null; + + return recipe.getType(); + } + + public RecipeSerializer getSerializer() { + Recipe recipe = getRecipe(); + if (recipe == null) return null; + + return recipe.getSerializer(); + } + + @Nullable + public RecipeUtil.CompatibilityCraftingRecipeCategory getCategory() { + return category; + } + + public String getGroup() { + return group; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/recipe/v2/CompatRecipeNonEntry.java b/common/src/main/java/net/pitan76/mcpitanlib/api/recipe/v2/CompatRecipeNonEntry.java new file mode 100644 index 000000000..09b62e257 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/recipe/v2/CompatRecipeNonEntry.java @@ -0,0 +1,25 @@ +package net.pitan76.mcpitanlib.api.recipe.v2; + +import net.minecraft.recipe.Recipe; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.api.util.RecipeUtil; + +@Deprecated +public class CompatRecipeNonEntry> extends CompatRecipeEntry { + public CompatRecipeNonEntry(T recipe) { + super(CompatIdentifier.EMPTY, "", RecipeUtil.CompatibilityCraftingRecipeCategory.MISC, recipe); + } + + public static CompatRecipeNonEntry create(Recipe recipe) { + return new CompatRecipeNonEntry<>(recipe); + } + + @Override + public T getRecipe() { + return super.getRecipe(); + } + + public Recipe getRawRecipe() { + return super.getRecipe(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/recipe/v3/CompatRecipe.java b/common/src/main/java/net/pitan76/mcpitanlib/api/recipe/v3/CompatRecipe.java new file mode 100644 index 000000000..4a26ce4e4 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/recipe/v3/CompatRecipe.java @@ -0,0 +1,85 @@ +package net.pitan76.mcpitanlib.api.recipe.v3; + +import net.minecraft.recipe.Recipe; +import net.minecraft.recipe.RecipeType; +import net.minecraft.util.Identifier; +import net.pitan76.mcpitanlib.api.recipe.CompatibleRecipeEntry; +import net.pitan76.mcpitanlib.api.recipe.v2.CompatRecipeEntry; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.api.util.RecipeUtil; +import net.pitan76.mcpitanlib.midohra.recipe.entry.RecipeEntry; + +public class CompatRecipe { + public Recipe recipe; + public Identifier id; + + public CompatRecipe(Recipe recipe, Identifier id) { + this.recipe = recipe; + this.id = id; + } + + @Deprecated + public CompatRecipe(net.minecraft.recipe.RecipeEntry entry) { + this(entry.value(), entry.id()); + } + + @Deprecated + public CompatRecipe(Recipe recipe) { + this.recipe = recipe; + this.id = RecipeUtil.getId(recipe); + } + + public boolean isNull() { + return recipe == null; + } + + public Recipe getRecipe() { + return recipe; + } + + public Identifier getId() { + return id; + } + + public CompatIdentifier getCompatId() { + return CompatIdentifier.fromMinecraft(getId()); + } + + public RecipeType getType() { + Recipe recipe = getRecipe(); + if (recipe == null) return null; + + return recipe.getType(); + } + + @Deprecated + public CompatRecipeEntry getRecipeEntry() { + return new CompatRecipeEntry<>(getId(), "", null, getRecipe()); + } + + @Deprecated + public CompatibleRecipeEntry getCompatibleRecipeEntry() { + return new CompatibleRecipeEntry(new net.minecraft.recipe.RecipeEntry>(getId(), getRecipe())); + } + + // MidohraAPI + public net.pitan76.mcpitanlib.midohra.recipe.Recipe getMidohraRecipe() { + if (getMidohraType() == net.pitan76.mcpitanlib.midohra.recipe.RecipeType.CRAFTING) { + return net.pitan76.mcpitanlib.midohra.recipe.CraftingRecipe.of((net.minecraft.recipe.CraftingRecipe) getRecipe()); + } + + return net.pitan76.mcpitanlib.midohra.recipe.Recipe.of(getRecipe()); + } + + public net.pitan76.mcpitanlib.midohra.recipe.entry.RecipeEntry getMidohraRecipeEntry() { + if (getMidohraType() == net.pitan76.mcpitanlib.midohra.recipe.RecipeType.CRAFTING) { + return net.pitan76.mcpitanlib.midohra.recipe.entry.CraftingRecipeEntry.of((net.minecraft.recipe.CraftingRecipe) getRecipe(), getCompatId()); + } + + return RecipeEntry.of(getRecipe(), getCompatId()); + } + + public net.pitan76.mcpitanlib.midohra.recipe.RecipeType getMidohraType() { + return net.pitan76.mcpitanlib.midohra.recipe.RecipeType.of(getType()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/registry/CompatRegistry.java b/common/src/main/java/net/pitan76/mcpitanlib/api/registry/CompatRegistry.java new file mode 100644 index 000000000..2bb439e04 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/registry/CompatRegistry.java @@ -0,0 +1,191 @@ +package net.pitan76.mcpitanlib.api.registry; + +import dev.architectury.registry.registries.RegistrySupplier; +import net.minecraft.block.Block; +import net.minecraft.block.entity.BlockEntityType; +import net.minecraft.component.ComponentType; +import net.minecraft.enchantment.Enchantment; +import net.minecraft.entity.EntityType; +import net.minecraft.entity.effect.StatusEffect; +import net.minecraft.fluid.Fluid; +import net.minecraft.item.Item; +import net.minecraft.item.ItemConvertible; +import net.minecraft.item.ItemGroup; +import net.minecraft.particle.ParticleType; +import net.minecraft.screen.ScreenHandlerType; +import net.minecraft.sound.SoundEvent; +import net.minecraft.util.Identifier; +import net.pitan76.mcpitanlib.MCPitanLib; +import net.pitan76.mcpitanlib.api.block.CompatibleBlockSettings; +import net.pitan76.mcpitanlib.api.block.CompatibleMaterial; +import net.pitan76.mcpitanlib.api.gui.ExtendedScreenHandlerTypeBuilder; +import net.pitan76.mcpitanlib.api.item.CreativeTabBuilder; +import net.pitan76.mcpitanlib.api.item.CreativeTabManager; +import net.pitan76.mcpitanlib.api.item.v2.CompatibleItemSettings; +import net.pitan76.mcpitanlib.api.registry.result.RegistryResult; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.api.util.block.BlockUtil; +import net.pitan76.mcpitanlib.api.util.item.ItemUtil; +import net.pitan76.mcpitanlib.core.registry.FuelRegistry; +import net.pitan76.mcpitanlib.core.registry.MCPLRegistry; +import net.pitan76.mcpitanlib.core.registry.MCPLRegistry1_20; +import net.pitan76.mcpitanlib.core.registry.MCPLRegistry1_21; + +import java.util.function.Supplier; + +public class CompatRegistry { + + protected final MCPLRegistry mcplr; + protected final MCPLRegistry1_20 mcplr1_20; + protected final MCPLRegistry1_21 mcplr1_21; + protected final WorldGenRegistry worldGenRegistry; + + protected String MOD_ID; + + /** + * @deprecated Use {@link #createRegistry(String)} instead + */ + @Deprecated + public CompatRegistry(String MOD_ID) { + mcplr = new MCPLRegistry(MOD_ID); + mcplr1_20 = new MCPLRegistry1_20(mcplr, MOD_ID); + mcplr1_21 = new MCPLRegistry1_21(mcplr, MOD_ID); + worldGenRegistry = new WorldGenRegistry(MOD_ID); + this.MOD_ID = MOD_ID; + } + + /** + * create(new CompatRegistry)'s alias + * @see #create(String) + */ + public static CompatRegistry createRegistry(String MOD_ID) { + return new CompatRegistry(MOD_ID); + } + + /** + * Create a new CompatRegistry + * @param MOD_ID The mod id + * @return The new CompatRegistry + */ + public static CompatRegistry create(String MOD_ID) { + return createRegistry(MOD_ID); + } + + /** + * Register an item + * @param id The item id + * @param supplier The item supplier + * @return The registry result + */ + public RegistryResult registerItem(Identifier id, Supplier supplier) { + if (MCPitanLib.isItemBlackListed(id)) supplier = () -> ItemUtil.create(CompatibleItemSettings.of(CompatIdentifier.fromMinecraft(id))); + RegistrySupplier registrySupplier = mcplr.registryItem(id, supplier); + CreativeTabManager.register(id); + return new RegistryResult<>(registrySupplier); + } + + public RegistryResult registerBlock(Identifier id, Supplier supplier) { + if (MCPitanLib.isBlockBlackListed(id)) supplier = () -> BlockUtil.create(CompatibleBlockSettings.of(CompatibleMaterial.STONE)); + return new RegistryResult<>(mcplr.registryBlock(id, supplier)); + } + + public RegistryResult> registerScreenHandlerType(Identifier id, Supplier> supplier) { + return new RegistryResult<>(mcplr.registryScreenHandlerType(id, supplier)); + } + + @Deprecated + public RegistryResult> registerExtendedScreenHandlerType(Identifier id, Supplier> supplier) { + return registerScreenHandlerType(id, () -> supplier.get().build()); + } + + public RegistryResult> registerMenu(Identifier id, Supplier> supplier) { + return registerScreenHandlerType(id, supplier); + } + + public RegistryResult> registerBlockEntityType(Identifier id, Supplier> supplier) { + return new RegistryResult<>(mcplr.registryBlockEntityType(id, supplier)); + } + + public RegistryResult> registerEntity(Identifier id, Supplier> supplier) { + return new RegistryResult<>(mcplr.registryEntityType(id, supplier)); + } + + @Deprecated + public RegistryResult registerSoundEvent(Identifier id, Supplier supplier) { + return new RegistryResult<>(mcplr.registrySoundEvent(id, supplier)); + } + + public RegistryResult registerSoundEvent(Identifier id) { + return registerSoundEvent(id, () -> SoundEvent.of(id)); + } + + public RegistryResult registerSoundEvent(Identifier id, float distanceToTravel) { + return registerSoundEvent(id, () -> SoundEvent.of(id, distanceToTravel)); + } + + public RegistryResult registerFluid(Identifier id, Supplier supplier) { + return new RegistryResult<>(mcplr.registryFluid(id, supplier)); + } + + public RegistryResult> registerParticleType(Identifier id, Supplier> supplier) { + return new RegistryResult<>(mcplr.registryParticleType(id, supplier)); + } + + public RegistryResult registerEnchantment(Identifier id, Supplier supplier) { + return new RegistryResult<>(mcplr.registryEnchantment(id, supplier)); + } + + public RegistryResult registerStatusEffect(Identifier id, Supplier supplier) { + return new RegistryResult<>(mcplr.registryStatusEffect(id, supplier)); + } + + public RegistryResult registerItemGroup(Identifier id, Supplier supplier) { + return new RegistryResult<>(mcplr1_20.registryItemGroup(id, supplier)); + } + + public RegistryResult registerItemGroup(Identifier id, CreativeTabBuilder builder) { + return new RegistryResult<>(mcplr1_20.registryItemGroup(id, builder)); + } + + public RegistryResult registerItemGroup(CreativeTabBuilder builder) { + return registerItemGroup(builder.getIdentifier(), builder); + } + + public RegistryResult> registerDataComponentType(Identifier id, Supplier> supplier) { + return new RegistryResult<>(mcplr1_21.registryDataComponentType(id, supplier)); + } + + public static void registerFuel(int time, ItemConvertible... item) { + FuelRegistry.register(time, item); + } + + public void allRegister() { + // 1.16 Register + mcplr.allRegister1_16(); + + mcplr1_20.register(); + mcplr1_21.register(); + + // ItemGroup + CreativeTabManager.allRegister(); + } + + @Deprecated + public MCPLRegistry getMcplr() { + return mcplr; + } + + @Deprecated + public MCPLRegistry1_20 getMcplr1_20() { + return mcplr1_20; + } + + @Deprecated + public MCPLRegistry1_21 getMcplr1_21() { + return mcplr1_21; + } + + public String getNamespace() { + return MOD_ID; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/registry/CompatRegistryLookup.java b/common/src/main/java/net/pitan76/mcpitanlib/api/registry/CompatRegistryLookup.java new file mode 100644 index 000000000..1a3afc996 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/registry/CompatRegistryLookup.java @@ -0,0 +1,42 @@ +package net.pitan76.mcpitanlib.api.registry; + +import net.minecraft.nbt.NbtCompound; +import net.minecraft.registry.BuiltinRegistries; +import net.minecraft.registry.RegistryWrapper; +import net.pitan76.mcpitanlib.api.event.nbt.NbtRWArgs; +import net.pitan76.mcpitanlib.api.event.nbt.ReadNbtArgs; +import net.pitan76.mcpitanlib.api.event.nbt.WriteNbtArgs; + +public class CompatRegistryLookup { + + private final RegistryWrapper.WrapperLookup registryLookup; + + @Deprecated + public CompatRegistryLookup(RegistryWrapper.WrapperLookup registryLookup) { + this.registryLookup = registryLookup; + } + + public CompatRegistryLookup() { + this.registryLookup = BuiltinRegistries.createWrapperLookup(); + } + + @Deprecated + public RegistryWrapper.WrapperLookup getRegistryLookup() { + if (registryLookup == null) + return BuiltinRegistries.createWrapperLookup(); + + return registryLookup; + } + + public NbtRWArgs getNbtRWArgs(NbtCompound nbt) { + return new NbtRWArgs(nbt, registryLookup); + } + + public WriteNbtArgs createWriteNbtArgs(NbtCompound nbt) { + return new WriteNbtArgs(nbt, registryLookup); + } + + public ReadNbtArgs createReadNbtArgs(NbtCompound nbt) { + return new ReadNbtArgs(nbt, registryLookup); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/registry/FuelRegistry.java b/common/src/main/java/net/pitan76/mcpitanlib/api/registry/FuelRegistry.java new file mode 100644 index 000000000..f5dc51bb4 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/registry/FuelRegistry.java @@ -0,0 +1,31 @@ +package net.pitan76.mcpitanlib.api.registry; + +import net.minecraft.item.ItemConvertible; + +import java.util.HashMap; +import java.util.Map; +import java.util.function.Supplier; + +public class FuelRegistry { + + private static final Map, Integer>> FUEL_MAP = new HashMap<>(); + + public static void register(Supplier itemSupplier, int time, String namespace) { + Map, Integer> map = new HashMap<>(); + map.put(itemSupplier, time); + + FUEL_MAP.put(namespace, map); + } + + @Deprecated + public static void allRegister(String namespace) { + if (!FUEL_MAP.containsKey(namespace)) return; + + Map, Integer> map = FUEL_MAP.get(namespace); + for (Map.Entry, Integer> entry : map.entrySet()) { + net.pitan76.mcpitanlib.core.registry.FuelRegistry.register(entry.getValue(), entry.getKey().get()); + } + + FUEL_MAP.remove(namespace); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/registry/WorldGenRegistry.java b/common/src/main/java/net/pitan76/mcpitanlib/api/registry/WorldGenRegistry.java new file mode 100644 index 000000000..4a4071011 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/registry/WorldGenRegistry.java @@ -0,0 +1,107 @@ +package net.pitan76.mcpitanlib.api.registry; + +import dev.architectury.registry.level.biome.BiomeModifications; +import dev.architectury.registry.registries.DeferredRegister; +import dev.architectury.registry.registries.RegistrySupplier; +import net.minecraft.registry.RegistryKeys; +import net.minecraft.registry.entry.RegistryEntry; +import net.minecraft.util.Identifier; +import net.minecraft.world.gen.GenerationStep; +import net.minecraft.world.gen.feature.ConfiguredFeature; +import net.minecraft.world.gen.feature.PlacedFeature; +import net.pitan76.mcpitanlib.api.registry.result.RegistryResult; + +import java.util.function.Supplier; + +public class WorldGenRegistry { + protected String MOD_ID; + + protected DeferredRegister> CONFIGURED_FEATURE; + protected DeferredRegister PLACED_FEATURE; + + @Deprecated + public WorldGenRegistry(String MOD_ID) { + this.MOD_ID = MOD_ID; + CONFIGURED_FEATURE = DeferredRegister.create(MOD_ID, RegistryKeys.CONFIGURED_FEATURE); + PLACED_FEATURE = DeferredRegister.create(MOD_ID, RegistryKeys.PLACED_FEATURE); + } + + /** + * Create a new CompatRegistry + * @param MOD_ID The mod id + * @return The new CompatRegistry + */ + public static WorldGenRegistry createRegistry(String MOD_ID) { + return new WorldGenRegistry(MOD_ID); + } + + public static WorldGenRegistry createRegistry(CompatRegistry registry) { + return registry.worldGenRegistry; + } + + /** + * Register a configured feature + * @param id The id of the configured feature + * @param supplier The supplier of the configured feature + * @return The result of the registration + */ + public RegistryResult> registerFeature(Identifier id, Supplier> supplier) { + RegistrySupplier> feature = CONFIGURED_FEATURE.register(id, supplier); + return new RegistryResult<>(feature); + } + + /** + * Register a placed feature + * @param id The id of the placed feature + * @param supplier The supplier of the placed feature + * @return The result of the registration + */ + public RegistryResult registerPlacedFeature(Identifier id, Supplier supplier) { + RegistrySupplier feature = PLACED_FEATURE.register(id, supplier); + return new RegistryResult<>(feature); + } + + /** + * Replace the properties of a biome + * @param decoration The decoration step + * @param feature The feature to replace + */ + public static void replaceProperties(GenerationStep.Feature decoration, RegistrySupplier feature) { + BiomeModifications.replaceProperties((ctx, mutable) -> mutable.getGenerationProperties().addFeature(decoration, feature)); + } + + public static void replaceProperties(GenerationStep.Feature decoration, RegistryResult feature) { + replaceProperties(decoration, feature.supplier); + } + + /** + * Replace the properties of a biome + * @param decoration The decoration step + * @param feature The feature to replace + */ + public static void replaceProperties(GenerationStep.Feature decoration, PlacedFeature feature) { + BiomeModifications.replaceProperties((ctx, mutable) -> mutable.getGenerationProperties().addFeature(decoration, RegistryEntry.of(feature))); + } + + /** + * Add a feature to the biome properties + * @param decoration The decoration step + * @param feature The feature to add + */ + public static void addProperties(GenerationStep.Feature decoration, RegistrySupplier feature) { + BiomeModifications.addProperties((ctx, mutable) -> mutable.getGenerationProperties().addFeature(decoration, feature)); + } + + public static void addProperties(GenerationStep.Feature decoration, RegistryResult feature) { + addProperties(decoration, feature.supplier); + } + + /** + * Add a feature to the biome properties + * @param decoration The decoration step + * @param feature The feature to add + */ + public static void addProperties(GenerationStep.Feature decoration, PlacedFeature feature) { + BiomeModifications.addProperties((ctx, mutable) -> mutable.getGenerationProperties().addFeature(decoration, RegistryEntry.of(feature))); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/registry/result/RegistryResult.java b/common/src/main/java/net/pitan76/mcpitanlib/api/registry/result/RegistryResult.java new file mode 100644 index 000000000..3bcf95488 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/registry/result/RegistryResult.java @@ -0,0 +1,31 @@ +package net.pitan76.mcpitanlib.api.registry.result; + +import dev.architectury.registry.registries.RegistrySupplier; +import org.jetbrains.annotations.Nullable; + +/** + * The result of a registry + * @param The type of the registry + * + *
{@code
+ * RegistryResult ITEM = registry.registerItem(IdentifierUtil.id("mcpitanlib", "example"), ExampleItem::new);
+ * ITEM.getOrNull(); => The item (Item.class) or null
+ * ITEM.get(); => The item (Item.class)
+ * }
+ */ +public class RegistryResult { + public RegistrySupplier supplier; + + public RegistryResult(RegistrySupplier supplier) { + this.supplier = supplier; + } + + public T get() { + return supplier.get(); + } + + @Nullable + public T getOrNull() { + return supplier.getOrNull(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/registry/result/SupplierResult.java b/common/src/main/java/net/pitan76/mcpitanlib/api/registry/result/SupplierResult.java new file mode 100644 index 000000000..4e2a538c2 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/registry/result/SupplierResult.java @@ -0,0 +1,52 @@ +package net.pitan76.mcpitanlib.api.registry.result; + +import dev.architectury.registry.registries.RegistrySupplier; +import org.jetbrains.annotations.Nullable; + +import java.util.Optional; +import java.util.function.Supplier; + +public class SupplierResult extends RegistryResult { + protected Supplier supplier; + + protected SupplierResult(Supplier supplier) { + super(null); + this.supplier = supplier; + } + + protected SupplierResult(RegistrySupplier supplier) { + this(supplier::getOrNull); + } + + protected SupplierResult(RegistryResult result) { + this(result.supplier); + } + + public static SupplierResult of(Supplier supplier) { + return new SupplierResult<>(supplier); + } + + public static SupplierResult of(RegistrySupplier supplier) { + return new SupplierResult<>(supplier); + } + + public static SupplierResult of(RegistryResult result) { + return new SupplierResult<>(result); + } + + @Override + public T get() { + return supplier.get(); + } + + @Override + public @Nullable T getOrNull() { + if (supplier == null) + return null; + return supplier.get(); + } + + public Optional getOptional() { + return Optional.ofNullable(getOrNull()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/registry/v2/CompatRegistryV2.java b/common/src/main/java/net/pitan76/mcpitanlib/api/registry/v2/CompatRegistryV2.java new file mode 100644 index 000000000..b72feed66 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/registry/v2/CompatRegistryV2.java @@ -0,0 +1,179 @@ +package net.pitan76.mcpitanlib.api.registry.v2; + +import net.minecraft.block.Block; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.block.entity.BlockEntityType; +import net.minecraft.enchantment.Enchantment; +import net.minecraft.entity.EntityType; +import net.minecraft.entity.effect.StatusEffect; +import net.minecraft.fluid.Fluid; +import net.minecraft.item.Item; +import net.minecraft.item.ItemGroup; +import net.minecraft.particle.ParticleType; +import net.minecraft.screen.ScreenHandler; +import net.minecraft.screen.ScreenHandlerType; +import net.minecraft.sound.SoundEvent; +import net.minecraft.util.Identifier; +import net.pitan76.mcpitanlib.api.block.ExtendBlock; +import net.pitan76.mcpitanlib.api.enchantment.CompatEnchantment; +import net.pitan76.mcpitanlib.api.entity.effect.CompatStatusEffect; +import net.pitan76.mcpitanlib.api.gui.ExtendedScreenHandlerTypeBuilder; +import net.pitan76.mcpitanlib.api.gui.SimpleScreenHandlerTypeBuilder; +import net.pitan76.mcpitanlib.api.item.CreativeTabBuilder; +import net.pitan76.mcpitanlib.api.item.ExtendItem; +import net.pitan76.mcpitanlib.api.registry.CompatRegistry; +import net.pitan76.mcpitanlib.api.registry.FuelRegistry; +import net.pitan76.mcpitanlib.api.registry.result.RegistryResult; +import net.pitan76.mcpitanlib.api.registry.result.SupplierResult; +import net.pitan76.mcpitanlib.api.sound.CompatSoundEvent; +import net.pitan76.mcpitanlib.api.sound.RegistryResultCompatSoundEvent; +import net.pitan76.mcpitanlib.api.tile.BlockEntityTypeBuilder; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.midohra.world.chunk.ChunkTicketType; + +import java.util.function.Supplier; + +public class CompatRegistryV2 { + + public final CompatRegistry cr1; + + @Deprecated + public CompatRegistryV2(CompatRegistry compatRegistry) { + this.cr1 = compatRegistry; + } + + /** + * Create a new CompatRegistryV2 + * @param MOD_ID The mod id + * @return The new CompatRegistryV2 + */ + public static CompatRegistryV2 create(String MOD_ID) { + CompatRegistry cr1 = CompatRegistry.create(MOD_ID); + return new CompatRegistryV2(cr1); + } + + public static CompatRegistryV2 create(CompatRegistry compatRegistry) { + return new CompatRegistryV2(compatRegistry); + } + + /** + * Register an item + * @param id The item id + * @param supplier The item supplier + * @return The registry result + */ + public RegistryResult registerItem(CompatIdentifier id, Supplier supplier) { + return cr1.registerItem(id.toMinecraft(), supplier); + } + + public Supplier registerExtendItem(CompatIdentifier id, Supplier supplier) { + RegistryResult result = registerItem(id, supplier::get); + return () -> (ExtendItem) result.get(); + } + + /** + * Register a block + * @param id The block id + * @param supplier The block supplier + * @return The registry result + */ + public RegistryResult registerBlock(CompatIdentifier id, Supplier supplier) { + return cr1.registerBlock(id.toMinecraft(), supplier); + } + + public Supplier registerExtendBlock(CompatIdentifier id, Supplier supplier) { + RegistryResult result = registerBlock(id, supplier::get); + return () -> (ExtendBlock) result.get(); + } + + public RegistryResult> registerScreenHandlerType(CompatIdentifier id, Supplier> supplier) { + return cr1.registerScreenHandlerType(id.toMinecraft(), supplier); + } + + public Supplier> registerScreenHandlerTypeSavingGenerics(CompatIdentifier id, Supplier> supplier) { + RegistryResult> result = cr1.registerScreenHandlerType(id.toMinecraft(), supplier::get); + return () -> (ScreenHandlerType) result.getOrNull(); + } + + public SupplierResult> registerScreenHandlerType(CompatIdentifier id, SimpleScreenHandlerTypeBuilder builder) { + return SupplierResult.of(registerScreenHandlerTypeSavingGenerics(id, builder::build)); + } + + public SupplierResult> registerScreenHandlerType(CompatIdentifier id, ExtendedScreenHandlerTypeBuilder builder) { + return SupplierResult.of(registerScreenHandlerTypeSavingGenerics(id, builder::build)); + } + + public RegistryResult> registerBlockEntityType(CompatIdentifier id, Supplier> supplier) { + return cr1.registerBlockEntityType(id.toMinecraft(), supplier); + } + + public SupplierResult> registerBlockEntityType(CompatIdentifier id, BlockEntityTypeBuilder builder) { + RegistryResult> result = cr1.registerBlockEntityType(id.toMinecraft(), builder::build); + return SupplierResult.of(() -> (BlockEntityType) result.getOrNull()); + } + + public RegistryResult> registerEntity(CompatIdentifier id, Supplier> supplier) { + return cr1.registerEntity(id.toMinecraft(), supplier); + } + + public RegistryResult registerSoundEvent(CompatIdentifier id) { + return cr1.registerSoundEvent(id.toMinecraft()); + } + + public RegistryResult registerSoundEvent(CompatIdentifier id, float distanceToTravel) { + return cr1.registerSoundEvent(id.toMinecraft(), distanceToTravel); + } + + public CompatSoundEvent registerCompatSoundEvent(CompatIdentifier id) { + return RegistryResultCompatSoundEvent.of(registerSoundEvent(id)); + } + + public CompatSoundEvent registerCompatSoundEvent(CompatIdentifier id, float distanceToTravel) { + return RegistryResultCompatSoundEvent.of(registerSoundEvent(id, distanceToTravel)); + } + + public RegistryResult registerFluid(CompatIdentifier id, Supplier supplier) { + return cr1.registerFluid(id.toMinecraft(), supplier); + } + + public RegistryResult> registerParticleType(CompatIdentifier id, Supplier> supplier) { + return cr1.registerParticleType(id.toMinecraft(), supplier); + } + + public RegistryResult registerEnchantment(CompatIdentifier id, Supplier supplier) { + return cr1.registerEnchantment(id.toMinecraft(), () -> supplier.get().getEnchantment(null)); + } + + public RegistryResult registryStatusEffect(CompatIdentifier id, Supplier supplier) { + return cr1.registerStatusEffect(id.toMinecraft(), () -> supplier.get().getStatusEffect(null)); + } + + public RegistryResult registerItemGroup(CompatIdentifier id, Supplier supplier) { + return cr1.registerItemGroup(id.toMinecraft(), supplier); + } + + public RegistryResult registerItemGroup(CompatIdentifier id, CreativeTabBuilder builder) { + return cr1.registerItemGroup(id.toMinecraft(), builder); + } + + public RegistryResult registerItemGroup(CreativeTabBuilder builder) { + return cr1.registerItemGroup(builder.getIdentifier(), builder); + } + + public RegistryResult> registerChunkTicketType(Identifier id, Supplier> supplier) { + return SupplierResult.of(supplier); + } + + public RegistryResult> registerChunkTicketType(CompatIdentifier id, Supplier> supplier) { + return registerChunkTicketType(id.toMinecraft(), supplier); + } + + public void registerFuel(Supplier itemSupplier, int time) { + FuelRegistry.register(itemSupplier::get, time, cr1.getNamespace()); + } + + public void allRegister() { + cr1.allRegister(); + FuelRegistry.allRegister(cr1.getNamespace()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/simple/block/SimpleGuiBlock.java b/common/src/main/java/net/pitan76/mcpitanlib/api/simple/block/SimpleGuiBlock.java new file mode 100644 index 000000000..2353be362 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/simple/block/SimpleGuiBlock.java @@ -0,0 +1,28 @@ +package net.pitan76.mcpitanlib.api.simple.block; + +import net.minecraft.text.Text; +import net.pitan76.mcpitanlib.api.block.ExtendBlock; +import net.pitan76.mcpitanlib.api.event.block.BlockUseEvent; +import net.pitan76.mcpitanlib.api.event.container.factory.DisplayNameArgs; +import net.pitan76.mcpitanlib.api.gui.v2.SimpleScreenHandlerFactory; +import net.pitan76.mcpitanlib.api.util.CompatActionResult; + +public abstract class SimpleGuiBlock extends ExtendBlock implements SimpleScreenHandlerFactory { + + public SimpleGuiBlock(Settings settings) { + super(settings); + } + + @Override + public CompatActionResult onRightClick(BlockUseEvent e) { + if (e.isClient()) + e.player.openGuiScreen(this); + + return e.success(); + } + + @Override + public Text getDisplayName(DisplayNameArgs args) { + return getName(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/simple/item/SimpleGuiItem.java b/common/src/main/java/net/pitan76/mcpitanlib/api/simple/item/SimpleGuiItem.java new file mode 100644 index 000000000..570410379 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/simple/item/SimpleGuiItem.java @@ -0,0 +1,61 @@ +package net.pitan76.mcpitanlib.api.simple.item; + +import net.minecraft.screen.ScreenHandler; +import net.minecraft.text.Text; +import net.pitan76.mcpitanlib.api.event.container.factory.DisplayNameArgs; +import net.pitan76.mcpitanlib.api.event.item.ItemUseEvent; +import net.pitan76.mcpitanlib.api.gui.args.CreateMenuEvent; +import net.pitan76.mcpitanlib.api.gui.v2.SimpleScreenHandlerFactory; +import net.pitan76.mcpitanlib.api.item.v2.CompatibleItemSettings; +import net.pitan76.mcpitanlib.api.item.v2.CompatItem; +import net.pitan76.mcpitanlib.api.util.StackActionResult; + +public class SimpleGuiItem extends CompatItem implements SimpleScreenHandlerFactory { + + public ScreenHandlerFactory factory; + public Text name; + + public SimpleGuiItem(CompatibleItemSettings settings, ScreenHandlerFactory factory, Text name) { + super(settings); + this.factory = factory; + this.name = name; + } + + public SimpleGuiItem(CompatibleItemSettings settings, ScreenHandlerFactory factory) { + super(settings); + this.factory = factory; + } + + public SimpleGuiItem(CompatibleItemSettings settings) { + super(settings); + } + + @Override + public StackActionResult onRightClick(ItemUseEvent e) { + if (!e.isClient()) + e.user.openGuiScreen(this); + + return e.success(); + } + + @Override + public Text getDisplayName(DisplayNameArgs args) { + if (name == null) + return getName(); + + return name; + } + + @Override + public ScreenHandler createMenu(CreateMenuEvent e) { + if (factory == null) + return null; + + return factory.create(e); + } + + @FunctionalInterface + public interface ScreenHandlerFactory { + ScreenHandler create(CreateMenuEvent e); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/sound/CompatBlockSoundGroup.java b/common/src/main/java/net/pitan76/mcpitanlib/api/sound/CompatBlockSoundGroup.java new file mode 100644 index 000000000..671dedf9e --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/sound/CompatBlockSoundGroup.java @@ -0,0 +1,221 @@ +package net.pitan76.mcpitanlib.api.sound; + +import net.minecraft.sound.BlockSoundGroup; +import net.minecraft.sound.SoundEvent; + +public class CompatBlockSoundGroup { + public static final CompatBlockSoundGroup INTENTIONALLY_EMPTY = of(BlockSoundGroup.INTENTIONALLY_EMPTY); + public static final CompatBlockSoundGroup WOOD = of(BlockSoundGroup.WOOD); + public static final CompatBlockSoundGroup GRAVEL = of(BlockSoundGroup.GRAVEL); + public static final CompatBlockSoundGroup GRASS = of(BlockSoundGroup.GRASS); + public static final CompatBlockSoundGroup LILY_PAD = of(BlockSoundGroup.LILY_PAD); + public static final CompatBlockSoundGroup STONE = of(BlockSoundGroup.STONE); + public static final CompatBlockSoundGroup METAL = of(BlockSoundGroup.METAL); + public static final CompatBlockSoundGroup GLASS = of(BlockSoundGroup.GLASS); + public static final CompatBlockSoundGroup WOOL = of(BlockSoundGroup.WOOL); + public static final CompatBlockSoundGroup SAND = of(BlockSoundGroup.SAND); + public static final CompatBlockSoundGroup SNOW = of(BlockSoundGroup.SNOW); + public static final CompatBlockSoundGroup POWDER_SNOW = of(BlockSoundGroup.POWDER_SNOW); + public static final CompatBlockSoundGroup LADDER = of(BlockSoundGroup.LADDER); + public static final CompatBlockSoundGroup ANVIL = of(BlockSoundGroup.ANVIL); + public static final CompatBlockSoundGroup SLIME = of(BlockSoundGroup.SLIME); + public static final CompatBlockSoundGroup HONEY = of(BlockSoundGroup.HONEY); + public static final CompatBlockSoundGroup WET_GRASS = of(BlockSoundGroup.WET_GRASS); + public static final CompatBlockSoundGroup CORAL = of(BlockSoundGroup.CORAL); + public static final CompatBlockSoundGroup BAMBOO = of(BlockSoundGroup.BAMBOO); + public static final CompatBlockSoundGroup BAMBOO_SAPLING = of(BlockSoundGroup.BAMBOO_SAPLING); + public static final CompatBlockSoundGroup SCAFFOLDING = of(BlockSoundGroup.SCAFFOLDING); + public static final CompatBlockSoundGroup SWEET_BERRY_BUSH = of(BlockSoundGroup.SWEET_BERRY_BUSH); + public static final CompatBlockSoundGroup CROP = of(BlockSoundGroup.CROP); + public static final CompatBlockSoundGroup STEM = of(BlockSoundGroup.STEM); + public static final CompatBlockSoundGroup VINE = of(BlockSoundGroup.VINE); + public static final CompatBlockSoundGroup NETHER_WART = of(BlockSoundGroup.NETHER_WART); + public static final CompatBlockSoundGroup LANTERN = of(BlockSoundGroup.LANTERN); + public static final CompatBlockSoundGroup NETHER_STEM = of(BlockSoundGroup.NETHER_STEM); + public static final CompatBlockSoundGroup NYLIUM = of(BlockSoundGroup.NYLIUM); + public static final CompatBlockSoundGroup FUNGUS = of(BlockSoundGroup.FUNGUS); + public static final CompatBlockSoundGroup ROOTS = of(BlockSoundGroup.ROOTS); + public static final CompatBlockSoundGroup SHROOMLIGHT = of(BlockSoundGroup.SHROOMLIGHT); + public static final CompatBlockSoundGroup WEEPING_VINES = of(BlockSoundGroup.WEEPING_VINES); + public static final CompatBlockSoundGroup WEEPING_VINES_LOW_PITCH = of(BlockSoundGroup.WEEPING_VINES_LOW_PITCH); + public static final CompatBlockSoundGroup SOUL_SAND = of(BlockSoundGroup.SOUL_SAND); + public static final CompatBlockSoundGroup SOUL_SOIL = of(BlockSoundGroup.SOUL_SOIL); + public static final CompatBlockSoundGroup BASALT = of(BlockSoundGroup.BASALT); + public static final CompatBlockSoundGroup WART_BLOCK = of(BlockSoundGroup.WART_BLOCK); + public static final CompatBlockSoundGroup NETHERRACK = of(BlockSoundGroup.NETHERRACK); + public static final CompatBlockSoundGroup NETHER_BRICKS = of(BlockSoundGroup.NETHER_BRICKS); + public static final CompatBlockSoundGroup NETHER_SPROUTS = of(BlockSoundGroup.NETHER_SPROUTS); + public static final CompatBlockSoundGroup NETHER_ORE = of(BlockSoundGroup.NETHER_ORE); + public static final CompatBlockSoundGroup BONE = of(BlockSoundGroup.BONE); + public static final CompatBlockSoundGroup NETHERITE = of(BlockSoundGroup.NETHERITE); + public static final CompatBlockSoundGroup ANCIENT_DEBRIS = of(BlockSoundGroup.ANCIENT_DEBRIS); + public static final CompatBlockSoundGroup LODESTONE = of(BlockSoundGroup.LODESTONE); + public static final CompatBlockSoundGroup CHAIN = of(BlockSoundGroup.CHAIN); + public static final CompatBlockSoundGroup NETHER_GOLD_ORE = of(BlockSoundGroup.NETHER_GOLD_ORE); + public static final CompatBlockSoundGroup GILDED_BLACKSTONE = of(BlockSoundGroup.GILDED_BLACKSTONE); + public static final CompatBlockSoundGroup CANDLE = of(BlockSoundGroup.CANDLE); + public static final CompatBlockSoundGroup AMETHYST_BLOCK = of(BlockSoundGroup.AMETHYST_BLOCK); + public static final CompatBlockSoundGroup AMETHYST_CLUSTER = of(BlockSoundGroup.AMETHYST_CLUSTER); + public static final CompatBlockSoundGroup SMALL_AMETHYST_BUD = of(BlockSoundGroup.SMALL_AMETHYST_BUD); + public static final CompatBlockSoundGroup MEDIUM_AMETHYST_BUD = of(BlockSoundGroup.MEDIUM_AMETHYST_BUD); + public static final CompatBlockSoundGroup LARGE_AMETHYST_BUD = of(BlockSoundGroup.LARGE_AMETHYST_BUD); + public static final CompatBlockSoundGroup TUFF = of(BlockSoundGroup.TUFF); + public static final CompatBlockSoundGroup TUFF_BRICKS = of(BlockSoundGroup.TUFF_BRICKS); + public static final CompatBlockSoundGroup POLISHED_TUFF = of(BlockSoundGroup.POLISHED_TUFF); + public static final CompatBlockSoundGroup CALCITE = of(BlockSoundGroup.CALCITE); + public static final CompatBlockSoundGroup DRIPSTONE_BLOCK = of(BlockSoundGroup.DRIPSTONE_BLOCK); + public static final CompatBlockSoundGroup POINTED_DRIPSTONE = of(BlockSoundGroup.POINTED_DRIPSTONE); + public static final CompatBlockSoundGroup COPPER = of(BlockSoundGroup.COPPER); + public static final CompatBlockSoundGroup COPPER_BULB = of(BlockSoundGroup.COPPER_BULB); + public static final CompatBlockSoundGroup COPPER_GRATE = of(BlockSoundGroup.COPPER_GRATE); + public static final CompatBlockSoundGroup CAVE_VINES = of(BlockSoundGroup.CAVE_VINES); + public static final CompatBlockSoundGroup SPORE_BLOSSOM = of(BlockSoundGroup.SPORE_BLOSSOM); + public static final CompatBlockSoundGroup AZALEA = of(BlockSoundGroup.AZALEA); + public static final CompatBlockSoundGroup FLOWERING_AZALEA = of(BlockSoundGroup.FLOWERING_AZALEA); + public static final CompatBlockSoundGroup MOSS_CARPET = of(BlockSoundGroup.MOSS_CARPET); + public static final CompatBlockSoundGroup PINK_PETALS = of(BlockSoundGroup.PINK_PETALS); + public static final CompatBlockSoundGroup MOSS_BLOCK = of(BlockSoundGroup.MOSS_BLOCK); + public static final CompatBlockSoundGroup BIG_DRIPLEAF = of(BlockSoundGroup.BIG_DRIPLEAF); + public static final CompatBlockSoundGroup SMALL_DRIPLEAF = of(BlockSoundGroup.SMALL_DRIPLEAF); + public static final CompatBlockSoundGroup ROOTED_DIRT = of(BlockSoundGroup.ROOTED_DIRT); + public static final CompatBlockSoundGroup HANGING_ROOTS = of(BlockSoundGroup.HANGING_ROOTS); + public static final CompatBlockSoundGroup AZALEA_LEAVES = of(BlockSoundGroup.AZALEA_LEAVES); + public static final CompatBlockSoundGroup SCULK_SENSOR = of(BlockSoundGroup.SCULK_SENSOR); + public static final CompatBlockSoundGroup SCULK_CATALYST = of(BlockSoundGroup.SCULK_CATALYST); + public static final CompatBlockSoundGroup SCULK = of(BlockSoundGroup.SCULK); + public static final CompatBlockSoundGroup SCULK_VEIN = of(BlockSoundGroup.SCULK_VEIN); + public static final CompatBlockSoundGroup SCULK_SHRIEKER = of(BlockSoundGroup.SCULK_SHRIEKER); + public static final CompatBlockSoundGroup GLOW_LICHEN = of(BlockSoundGroup.GLOW_LICHEN); + public static final CompatBlockSoundGroup DEEPSLATE = of(BlockSoundGroup.DEEPSLATE); + public static final CompatBlockSoundGroup DEEPSLATE_BRICKS = of(BlockSoundGroup.DEEPSLATE_BRICKS); + public static final CompatBlockSoundGroup DEEPSLATE_TILES = of(BlockSoundGroup.DEEPSLATE_TILES); + public static final CompatBlockSoundGroup POLISHED_DEEPSLATE = of(BlockSoundGroup.POLISHED_DEEPSLATE); + public static final CompatBlockSoundGroup FROGLIGHT = of(BlockSoundGroup.FROGLIGHT); + public static final CompatBlockSoundGroup FROGSPAWN = of(BlockSoundGroup.FROGSPAWN); + public static final CompatBlockSoundGroup MANGROVE_ROOTS = of(BlockSoundGroup.MANGROVE_ROOTS); + public static final CompatBlockSoundGroup MUDDY_MANGROVE_ROOTS = of(BlockSoundGroup.MUDDY_MANGROVE_ROOTS); + public static final CompatBlockSoundGroup MUD = of(BlockSoundGroup.MUD); + public static final CompatBlockSoundGroup MUD_BRICKS = of(BlockSoundGroup.MUD_BRICKS); + public static final CompatBlockSoundGroup PACKED_MUD = of(BlockSoundGroup.PACKED_MUD); + public static final CompatBlockSoundGroup HANGING_SIGN = of(BlockSoundGroup.HANGING_SIGN); + public static final CompatBlockSoundGroup NETHER_WOOD_HANGING_SIGN = of(BlockSoundGroup.NETHER_WOOD_HANGING_SIGN); + public static final CompatBlockSoundGroup BAMBOO_WOOD_HANGING_SIGN = of(BlockSoundGroup.BAMBOO_WOOD_HANGING_SIGN); + public static final CompatBlockSoundGroup BAMBOO_WOOD = of(BlockSoundGroup.BAMBOO_WOOD); + public static final CompatBlockSoundGroup NETHER_WOOD = of(BlockSoundGroup.NETHER_WOOD); + public static final CompatBlockSoundGroup CHERRY_WOOD = of(BlockSoundGroup.CHERRY_WOOD); + public static final CompatBlockSoundGroup CHERRY_SAPLING = of(BlockSoundGroup.CHERRY_SAPLING); + public static final CompatBlockSoundGroup CHERRY_LEAVES = of(BlockSoundGroup.CHERRY_LEAVES); + public static final CompatBlockSoundGroup CHERRY_WOOD_HANGING_SIGN = of(BlockSoundGroup.CHERRY_WOOD_HANGING_SIGN); + public static final CompatBlockSoundGroup CHISELED_BOOKSHELF = of(BlockSoundGroup.CHISELED_BOOKSHELF); + public static final CompatBlockSoundGroup SUSPICIOUS_SAND = of(BlockSoundGroup.SUSPICIOUS_SAND); + public static final CompatBlockSoundGroup SUSPICIOUS_GRAVEL = of(BlockSoundGroup.SUSPICIOUS_GRAVEL); + public static final CompatBlockSoundGroup DECORATED_POT = of(BlockSoundGroup.DECORATED_POT); + public static final CompatBlockSoundGroup DECORATED_POT_SHATTER = of(BlockSoundGroup.DECORATED_POT_SHATTER); + public static final CompatBlockSoundGroup TRIAL_SPAWNER = of(BlockSoundGroup.TRIAL_SPAWNER); + public static final CompatBlockSoundGroup SPONGE = of(BlockSoundGroup.SPONGE); + public static final CompatBlockSoundGroup WET_SPONGE = of(BlockSoundGroup.WET_SPONGE); + public static final CompatBlockSoundGroup VAULT = of(BlockSoundGroup.VAULT); + public static final CompatBlockSoundGroup HEAVY_CORE = of(BlockSoundGroup.HEAVY_CORE); + public static final CompatBlockSoundGroup COBWEB = of(BlockSoundGroup.COBWEB); + + public BlockSoundGroup blockSoundGroup; + + private final float volume; + private final float pitch; + private final SoundEvent breakSound; + private final SoundEvent stepSound; + private final SoundEvent placeSound; + private final SoundEvent hitSound; + private final SoundEvent fallSound; + + public CompatBlockSoundGroup(BlockSoundGroup blockSoundGroup) { + this.blockSoundGroup = blockSoundGroup; + + this.volume = blockSoundGroup.getVolume(); + this.pitch = blockSoundGroup.getPitch(); + this.breakSound = blockSoundGroup.getBreakSound(); + this.stepSound = blockSoundGroup.getStepSound(); + this.placeSound = blockSoundGroup.getPlaceSound(); + this.hitSound = blockSoundGroup.getHitSound(); + this.fallSound = blockSoundGroup.getFallSound(); + } + + public CompatBlockSoundGroup(float volume, float pitch, SoundEvent breakSound, SoundEvent stepSound, SoundEvent placeSound, SoundEvent hitSound, SoundEvent fallSound) { + this.blockSoundGroup = new BlockSoundGroup(volume, pitch, breakSound, stepSound, placeSound, hitSound, fallSound); + + this.volume = volume; + this.pitch = pitch; + this.breakSound = breakSound; + this.stepSound = stepSound; + this.placeSound = placeSound; + this.hitSound = hitSound; + this.fallSound = fallSound; + } + + public BlockSoundGroup get() { + if (blockSoundGroup == null) { + return new BlockSoundGroup(volume, pitch, breakSound, stepSound, placeSound, hitSound, fallSound); + } + return blockSoundGroup; + } + + public static CompatBlockSoundGroup of(BlockSoundGroup blockSoundGroup) { + return new CompatBlockSoundGroup(blockSoundGroup); + } + + public static CompatBlockSoundGroup of(float volume, float pitch, SoundEvent breakSound, SoundEvent stepSound, SoundEvent placeSound, SoundEvent hitSound, SoundEvent fallSound) { + return new CompatBlockSoundGroup(volume, pitch, breakSound, stepSound, placeSound, hitSound, fallSound); + } + + public static CompatBlockSoundGroup of(float volume, float pitch, CompatSoundEvent breakSound, CompatSoundEvent stepSound, CompatSoundEvent placeSound, CompatSoundEvent hitSound, CompatSoundEvent fallSound) { + return new CompatBlockSoundGroup(volume, pitch, breakSound.get(), stepSound.get(), placeSound.get(), hitSound.get(), fallSound.get()); + } + + public float getVolume() { + return volume; + } + + public float getPitch() { + return pitch; + } + + public SoundEvent getRawBreakSound() { + return breakSound; + } + + public SoundEvent getRawStepSound() { + return stepSound; + } + + public SoundEvent getRawPlaceSound() { + return placeSound; + } + + public SoundEvent getRawHitSound() { + return hitSound; + } + + public SoundEvent getRawFallSound() { + return fallSound; + } + + public CompatSoundEvent getBreakSound() { + return CompatSoundEvent.of(breakSound); + } + + public CompatSoundEvent getStepSound() { + return CompatSoundEvent.of(stepSound); + } + + public CompatSoundEvent getPlaceSound() { + return CompatSoundEvent.of(placeSound); + } + + public CompatSoundEvent getHitSound() { + return CompatSoundEvent.of(hitSound); + } + + public CompatSoundEvent getFallSound() { + return CompatSoundEvent.of(fallSound); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/sound/CompatSoundCategory.java b/common/src/main/java/net/pitan76/mcpitanlib/api/sound/CompatSoundCategory.java new file mode 100644 index 000000000..4fdd2bd18 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/sound/CompatSoundCategory.java @@ -0,0 +1,35 @@ +package net.pitan76.mcpitanlib.api.sound; + +import net.minecraft.sound.SoundCategory; + +public class CompatSoundCategory { + + public static final CompatSoundCategory MASTER = of(SoundCategory.MASTER); + public static final CompatSoundCategory MUSIC = of(SoundCategory.MUSIC); + public static final CompatSoundCategory RECORDS = of(SoundCategory.RECORDS); + public static final CompatSoundCategory WEATHER = of(SoundCategory.WEATHER); + public static final CompatSoundCategory BLOCKS = of(SoundCategory.BLOCKS); + public static final CompatSoundCategory HOSTILE = of(SoundCategory.HOSTILE); + public static final CompatSoundCategory NEUTRAL = of(SoundCategory.NEUTRAL); + public static final CompatSoundCategory PLAYERS = of(SoundCategory.PLAYERS); + public static final CompatSoundCategory AMBIENT = of(SoundCategory.AMBIENT); + public static final CompatSoundCategory VOICE = of(SoundCategory.VOICE); + + public SoundCategory soundCategory; + + public CompatSoundCategory(SoundCategory soundCategory) { + this.soundCategory = soundCategory; + } + + public static CompatSoundCategory of(SoundCategory soundCategory) { + return new CompatSoundCategory(soundCategory); + } + + public SoundCategory get() { + return soundCategory; + } + + public String getName() { + return soundCategory.getName(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/sound/CompatSoundEvent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/sound/CompatSoundEvent.java new file mode 100644 index 000000000..f18fcf204 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/sound/CompatSoundEvent.java @@ -0,0 +1,55 @@ +package net.pitan76.mcpitanlib.api.sound; + +import net.minecraft.registry.entry.RegistryEntry; +import net.minecraft.sound.SoundEvent; +import org.jetbrains.annotations.Nullable; + +public class CompatSoundEvent { + private SoundEvent soundEvent; + private RegistryEntry.Reference reference; + private RegistryEntry entry; + + public CompatSoundEvent(SoundEvent soundEvent) { + this.soundEvent = soundEvent; + } + + public CompatSoundEvent(RegistryEntry.Reference reference) { + this.reference = reference; + } + + public CompatSoundEvent(RegistryEntry entry) { + this.entry = entry; + } + + public static CompatSoundEvent of(SoundEvent soundEvent) { + return new CompatSoundEvent(soundEvent); + } + + public SoundEvent get() { + if (soundEvent == null) { + if (reference != null) { + soundEvent = reference.value(); + } else if (entry != null) { + soundEvent = entry.value(); + } + } + + return soundEvent; + } + + @Nullable + @Deprecated + public RegistryEntry.Reference getReference() { + return reference; + } + + @Nullable + @Deprecated + public RegistryEntry getEntry() { + if (entry == null) { + entry = RegistryEntry.of(soundEvent); + } + + return entry; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/sound/CompatSoundEvents.java b/common/src/main/java/net/pitan76/mcpitanlib/api/sound/CompatSoundEvents.java new file mode 100644 index 000000000..1cd5fd036 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/sound/CompatSoundEvents.java @@ -0,0 +1,1624 @@ +package net.pitan76.mcpitanlib.api.sound; + +import com.google.common.collect.ImmutableList; +import net.minecraft.sound.SoundEvents; + +public class CompatSoundEvents { + public static final CompatSoundEvent ENTITY_ALLAY_AMBIENT_WITH_ITEM = new CompatSoundEvent(SoundEvents.ENTITY_ALLAY_AMBIENT_WITH_ITEM); + public static final CompatSoundEvent ENTITY_ALLAY_AMBIENT_WITHOUT_ITEM = new CompatSoundEvent(SoundEvents.ENTITY_ALLAY_AMBIENT_WITHOUT_ITEM); + public static final CompatSoundEvent ENTITY_ALLAY_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_ALLAY_DEATH); + public static final CompatSoundEvent ENTITY_ALLAY_HURT = new CompatSoundEvent(SoundEvents.ENTITY_ALLAY_HURT); + public static final CompatSoundEvent ENTITY_ALLAY_ITEM_GIVEN = new CompatSoundEvent(SoundEvents.ENTITY_ALLAY_ITEM_GIVEN); + public static final CompatSoundEvent ENTITY_ALLAY_ITEM_TAKEN = new CompatSoundEvent(SoundEvents.ENTITY_ALLAY_ITEM_TAKEN); + public static final CompatSoundEvent ENTITY_ALLAY_ITEM_THROWN = new CompatSoundEvent(SoundEvents.ENTITY_ALLAY_ITEM_THROWN); + public static final CompatSoundEvent AMBIENT_CAVE = new CompatSoundEvent(SoundEvents.AMBIENT_CAVE); + public static final CompatSoundEvent AMBIENT_BASALT_DELTAS_ADDITIONS = new CompatSoundEvent(SoundEvents.AMBIENT_BASALT_DELTAS_ADDITIONS); + public static final CompatSoundEvent AMBIENT_BASALT_DELTAS_LOOP = new CompatSoundEvent(SoundEvents.AMBIENT_BASALT_DELTAS_LOOP); + public static final CompatSoundEvent AMBIENT_BASALT_DELTAS_MOOD = new CompatSoundEvent(SoundEvents.AMBIENT_BASALT_DELTAS_MOOD); + public static final CompatSoundEvent AMBIENT_CRIMSON_FOREST_ADDITIONS = new CompatSoundEvent(SoundEvents.AMBIENT_CRIMSON_FOREST_ADDITIONS); + public static final CompatSoundEvent AMBIENT_CRIMSON_FOREST_LOOP = new CompatSoundEvent(SoundEvents.AMBIENT_CRIMSON_FOREST_LOOP); + public static final CompatSoundEvent AMBIENT_CRIMSON_FOREST_MOOD = new CompatSoundEvent(SoundEvents.AMBIENT_CRIMSON_FOREST_MOOD); + public static final CompatSoundEvent AMBIENT_NETHER_WASTES_ADDITIONS = new CompatSoundEvent(SoundEvents.AMBIENT_NETHER_WASTES_ADDITIONS); + public static final CompatSoundEvent AMBIENT_NETHER_WASTES_LOOP = new CompatSoundEvent(SoundEvents.AMBIENT_NETHER_WASTES_LOOP); + public static final CompatSoundEvent AMBIENT_NETHER_WASTES_MOOD = new CompatSoundEvent(SoundEvents.AMBIENT_NETHER_WASTES_MOOD); + public static final CompatSoundEvent AMBIENT_SOUL_SAND_VALLEY_ADDITIONS = new CompatSoundEvent(SoundEvents.AMBIENT_SOUL_SAND_VALLEY_ADDITIONS); + public static final CompatSoundEvent AMBIENT_SOUL_SAND_VALLEY_LOOP = new CompatSoundEvent(SoundEvents.AMBIENT_SOUL_SAND_VALLEY_LOOP); + public static final CompatSoundEvent AMBIENT_SOUL_SAND_VALLEY_MOOD = new CompatSoundEvent(SoundEvents.AMBIENT_SOUL_SAND_VALLEY_MOOD); + public static final CompatSoundEvent AMBIENT_WARPED_FOREST_ADDITIONS = new CompatSoundEvent(SoundEvents.AMBIENT_WARPED_FOREST_ADDITIONS); + public static final CompatSoundEvent AMBIENT_WARPED_FOREST_LOOP = new CompatSoundEvent(SoundEvents.AMBIENT_WARPED_FOREST_LOOP); + public static final CompatSoundEvent AMBIENT_WARPED_FOREST_MOOD = new CompatSoundEvent(SoundEvents.AMBIENT_WARPED_FOREST_MOOD); + public static final CompatSoundEvent AMBIENT_UNDERWATER_ENTER = new CompatSoundEvent(SoundEvents.AMBIENT_UNDERWATER_ENTER); + public static final CompatSoundEvent AMBIENT_UNDERWATER_EXIT = new CompatSoundEvent(SoundEvents.AMBIENT_UNDERWATER_EXIT); + public static final CompatSoundEvent AMBIENT_UNDERWATER_LOOP = new CompatSoundEvent(SoundEvents.AMBIENT_UNDERWATER_LOOP); + public static final CompatSoundEvent AMBIENT_UNDERWATER_LOOP_ADDITIONS = new CompatSoundEvent(SoundEvents.AMBIENT_UNDERWATER_LOOP_ADDITIONS); + public static final CompatSoundEvent AMBIENT_UNDERWATER_LOOP_ADDITIONS_RARE = new CompatSoundEvent(SoundEvents.AMBIENT_UNDERWATER_LOOP_ADDITIONS_RARE); + public static final CompatSoundEvent AMBIENT_UNDERWATER_LOOP_ADDITIONS_ULTRA_RARE = new CompatSoundEvent(SoundEvents.AMBIENT_UNDERWATER_LOOP_ADDITIONS_ULTRA_RARE); + public static final CompatSoundEvent BLOCK_AMETHYST_BLOCK_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_AMETHYST_BLOCK_BREAK); + public static final CompatSoundEvent BLOCK_AMETHYST_BLOCK_CHIME = new CompatSoundEvent(SoundEvents.BLOCK_AMETHYST_BLOCK_CHIME); + public static final CompatSoundEvent BLOCK_AMETHYST_BLOCK_FALL = new CompatSoundEvent(SoundEvents.BLOCK_AMETHYST_BLOCK_FALL); + public static final CompatSoundEvent BLOCK_AMETHYST_BLOCK_HIT = new CompatSoundEvent(SoundEvents.BLOCK_AMETHYST_BLOCK_HIT); + public static final CompatSoundEvent BLOCK_AMETHYST_BLOCK_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_AMETHYST_BLOCK_PLACE); + public static final CompatSoundEvent BLOCK_AMETHYST_BLOCK_RESONATE = new CompatSoundEvent(SoundEvents.BLOCK_AMETHYST_BLOCK_RESONATE); + public static final CompatSoundEvent BLOCK_AMETHYST_BLOCK_STEP = new CompatSoundEvent(SoundEvents.BLOCK_AMETHYST_BLOCK_STEP); + public static final CompatSoundEvent BLOCK_AMETHYST_CLUSTER_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_AMETHYST_CLUSTER_BREAK); + public static final CompatSoundEvent BLOCK_AMETHYST_CLUSTER_FALL = new CompatSoundEvent(SoundEvents.BLOCK_AMETHYST_CLUSTER_FALL); + public static final CompatSoundEvent BLOCK_AMETHYST_CLUSTER_HIT = new CompatSoundEvent(SoundEvents.BLOCK_AMETHYST_CLUSTER_HIT); + public static final CompatSoundEvent BLOCK_AMETHYST_CLUSTER_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_AMETHYST_CLUSTER_PLACE); + public static final CompatSoundEvent BLOCK_AMETHYST_CLUSTER_STEP = new CompatSoundEvent(SoundEvents.BLOCK_AMETHYST_CLUSTER_STEP); + public static final CompatSoundEvent BLOCK_ANCIENT_DEBRIS_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_ANCIENT_DEBRIS_BREAK); + public static final CompatSoundEvent BLOCK_ANCIENT_DEBRIS_STEP = new CompatSoundEvent(SoundEvents.BLOCK_ANCIENT_DEBRIS_STEP); + public static final CompatSoundEvent BLOCK_ANCIENT_DEBRIS_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_ANCIENT_DEBRIS_PLACE); + public static final CompatSoundEvent BLOCK_ANCIENT_DEBRIS_HIT = new CompatSoundEvent(SoundEvents.BLOCK_ANCIENT_DEBRIS_HIT); + public static final CompatSoundEvent BLOCK_ANCIENT_DEBRIS_FALL = new CompatSoundEvent(SoundEvents.BLOCK_ANCIENT_DEBRIS_FALL); + public static final CompatSoundEvent BLOCK_ANVIL_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_ANVIL_BREAK); + public static final CompatSoundEvent BLOCK_ANVIL_DESTROY = new CompatSoundEvent(SoundEvents.BLOCK_ANVIL_DESTROY); + public static final CompatSoundEvent BLOCK_ANVIL_FALL = new CompatSoundEvent(SoundEvents.BLOCK_ANVIL_FALL); + public static final CompatSoundEvent BLOCK_ANVIL_HIT = new CompatSoundEvent(SoundEvents.BLOCK_ANVIL_HIT); + public static final CompatSoundEvent BLOCK_ANVIL_LAND = new CompatSoundEvent(SoundEvents.BLOCK_ANVIL_LAND); + public static final CompatSoundEvent BLOCK_ANVIL_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_ANVIL_PLACE); + public static final CompatSoundEvent BLOCK_ANVIL_STEP = new CompatSoundEvent(SoundEvents.BLOCK_ANVIL_STEP); + public static final CompatSoundEvent BLOCK_ANVIL_USE = new CompatSoundEvent(SoundEvents.BLOCK_ANVIL_USE); + public static final CompatSoundEvent ENTITY_ARMADILLO_EAT = new CompatSoundEvent(SoundEvents.ENTITY_ARMADILLO_EAT); + public static final CompatSoundEvent ENTITY_ARMADILLO_HURT = new CompatSoundEvent(SoundEvents.ENTITY_ARMADILLO_HURT); + public static final CompatSoundEvent ENTITY_ARMADILLO_HURT_REDUCED = new CompatSoundEvent(SoundEvents.ENTITY_ARMADILLO_HURT_REDUCED); + public static final CompatSoundEvent ENTITY_ARMADILLO_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_ARMADILLO_AMBIENT); + public static final CompatSoundEvent ENTITY_ARMADILLO_STEP = new CompatSoundEvent(SoundEvents.ENTITY_ARMADILLO_STEP); + public static final CompatSoundEvent ENTITY_ARMADILLO_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_ARMADILLO_DEATH); + public static final CompatSoundEvent ENTITY_ARMADILLO_ROLL = new CompatSoundEvent(SoundEvents.ENTITY_ARMADILLO_ROLL); + public static final CompatSoundEvent ENTITY_ARMADILLO_LAND = new CompatSoundEvent(SoundEvents.ENTITY_ARMADILLO_LAND); + public static final CompatSoundEvent ENTITY_ARMADILLO_SCUTE_DROP = new CompatSoundEvent(SoundEvents.ENTITY_ARMADILLO_SCUTE_DROP); + public static final CompatSoundEvent ENTITY_ARMADILLO_UNROLL_FINISH = new CompatSoundEvent(SoundEvents.ENTITY_ARMADILLO_UNROLL_FINISH); + public static final CompatSoundEvent ENTITY_ARMADILLO_PEEK = new CompatSoundEvent(SoundEvents.ENTITY_ARMADILLO_PEEK); + public static final CompatSoundEvent ENTITY_ARMADILLO_UNROLL_START = new CompatSoundEvent(SoundEvents.ENTITY_ARMADILLO_UNROLL_START); + public static final CompatSoundEvent ENTITY_ARMADILLO_BRUSH = new CompatSoundEvent(SoundEvents.ENTITY_ARMADILLO_BRUSH); + public static final CompatSoundEvent ITEM_ARMOR_EQUIP_CHAIN = new CompatSoundEvent(SoundEvents.ITEM_ARMOR_EQUIP_CHAIN); + public static final CompatSoundEvent ITEM_ARMOR_EQUIP_DIAMOND = new CompatSoundEvent(SoundEvents.ITEM_ARMOR_EQUIP_DIAMOND); + public static final CompatSoundEvent ITEM_ARMOR_EQUIP_ELYTRA = new CompatSoundEvent(SoundEvents.ITEM_ARMOR_EQUIP_ELYTRA); + public static final CompatSoundEvent ITEM_ARMOR_EQUIP_GENERIC = new CompatSoundEvent(SoundEvents.ITEM_ARMOR_EQUIP_GENERIC); + public static final CompatSoundEvent ITEM_ARMOR_EQUIP_GOLD = new CompatSoundEvent(SoundEvents.ITEM_ARMOR_EQUIP_GOLD); + public static final CompatSoundEvent ITEM_ARMOR_EQUIP_IRON = new CompatSoundEvent(SoundEvents.ITEM_ARMOR_EQUIP_IRON); + public static final CompatSoundEvent ITEM_ARMOR_EQUIP_LEATHER = new CompatSoundEvent(SoundEvents.ITEM_ARMOR_EQUIP_LEATHER); + public static final CompatSoundEvent ITEM_ARMOR_EQUIP_NETHERITE = new CompatSoundEvent(SoundEvents.ITEM_ARMOR_EQUIP_NETHERITE); + public static final CompatSoundEvent ITEM_ARMOR_EQUIP_TURTLE = new CompatSoundEvent(SoundEvents.ITEM_ARMOR_EQUIP_TURTLE); + public static final CompatSoundEvent ITEM_ARMOR_EQUIP_WOLF = new CompatSoundEvent(SoundEvents.ITEM_ARMOR_EQUIP_WOLF); + public static final CompatSoundEvent ITEM_ARMOR_UNEQUIP_WOLF = new CompatSoundEvent(SoundEvents.ITEM_ARMOR_UNEQUIP_WOLF); + public static final CompatSoundEvent ENTITY_ARMOR_STAND_BREAK = new CompatSoundEvent(SoundEvents.ENTITY_ARMOR_STAND_BREAK); + public static final CompatSoundEvent ENTITY_ARMOR_STAND_FALL = new CompatSoundEvent(SoundEvents.ENTITY_ARMOR_STAND_FALL); + public static final CompatSoundEvent ENTITY_ARMOR_STAND_HIT = new CompatSoundEvent(SoundEvents.ENTITY_ARMOR_STAND_HIT); + public static final CompatSoundEvent ENTITY_ARMOR_STAND_PLACE = new CompatSoundEvent(SoundEvents.ENTITY_ARMOR_STAND_PLACE); + public static final CompatSoundEvent ENTITY_ARROW_HIT = new CompatSoundEvent(SoundEvents.ENTITY_ARROW_HIT); + public static final CompatSoundEvent ENTITY_ARROW_HIT_PLAYER = new CompatSoundEvent(SoundEvents.ENTITY_ARROW_HIT_PLAYER); + public static final CompatSoundEvent ENTITY_ARROW_SHOOT = new CompatSoundEvent(SoundEvents.ENTITY_ARROW_SHOOT); + public static final CompatSoundEvent ITEM_AXE_STRIP = new CompatSoundEvent(SoundEvents.ITEM_AXE_STRIP); + public static final CompatSoundEvent ITEM_AXE_SCRAPE = new CompatSoundEvent(SoundEvents.ITEM_AXE_SCRAPE); + public static final CompatSoundEvent ITEM_AXE_WAX_OFF = new CompatSoundEvent(SoundEvents.ITEM_AXE_WAX_OFF); + public static final CompatSoundEvent ENTITY_AXOLOTL_ATTACK = new CompatSoundEvent(SoundEvents.ENTITY_AXOLOTL_ATTACK); + public static final CompatSoundEvent ENTITY_AXOLOTL_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_AXOLOTL_DEATH); + public static final CompatSoundEvent ENTITY_AXOLOTL_HURT = new CompatSoundEvent(SoundEvents.ENTITY_AXOLOTL_HURT); + public static final CompatSoundEvent ENTITY_AXOLOTL_IDLE_AIR = new CompatSoundEvent(SoundEvents.ENTITY_AXOLOTL_IDLE_AIR); + public static final CompatSoundEvent ENTITY_AXOLOTL_IDLE_WATER = new CompatSoundEvent(SoundEvents.ENTITY_AXOLOTL_IDLE_WATER); + public static final CompatSoundEvent ENTITY_AXOLOTL_SPLASH = new CompatSoundEvent(SoundEvents.ENTITY_AXOLOTL_SPLASH); + public static final CompatSoundEvent ENTITY_AXOLOTL_SWIM = new CompatSoundEvent(SoundEvents.ENTITY_AXOLOTL_SWIM); + public static final CompatSoundEvent BLOCK_AZALEA_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_AZALEA_BREAK); + public static final CompatSoundEvent BLOCK_AZALEA_FALL = new CompatSoundEvent(SoundEvents.BLOCK_AZALEA_FALL); + public static final CompatSoundEvent BLOCK_AZALEA_HIT = new CompatSoundEvent(SoundEvents.BLOCK_AZALEA_HIT); + public static final CompatSoundEvent BLOCK_AZALEA_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_AZALEA_PLACE); + public static final CompatSoundEvent BLOCK_AZALEA_STEP = new CompatSoundEvent(SoundEvents.BLOCK_AZALEA_STEP); + public static final CompatSoundEvent BLOCK_AZALEA_LEAVES_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_AZALEA_LEAVES_BREAK); + public static final CompatSoundEvent BLOCK_AZALEA_LEAVES_FALL = new CompatSoundEvent(SoundEvents.BLOCK_AZALEA_LEAVES_FALL); + public static final CompatSoundEvent BLOCK_AZALEA_LEAVES_HIT = new CompatSoundEvent(SoundEvents.BLOCK_AZALEA_LEAVES_HIT); + public static final CompatSoundEvent BLOCK_AZALEA_LEAVES_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_AZALEA_LEAVES_PLACE); + public static final CompatSoundEvent BLOCK_AZALEA_LEAVES_STEP = new CompatSoundEvent(SoundEvents.BLOCK_AZALEA_LEAVES_STEP); + public static final CompatSoundEvent BLOCK_BAMBOO_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_BAMBOO_BREAK); + public static final CompatSoundEvent BLOCK_BAMBOO_FALL = new CompatSoundEvent(SoundEvents.BLOCK_BAMBOO_FALL); + public static final CompatSoundEvent BLOCK_BAMBOO_HIT = new CompatSoundEvent(SoundEvents.BLOCK_BAMBOO_HIT); + public static final CompatSoundEvent BLOCK_BAMBOO_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_BAMBOO_PLACE); + public static final CompatSoundEvent BLOCK_BAMBOO_STEP = new CompatSoundEvent(SoundEvents.BLOCK_BAMBOO_STEP); + public static final CompatSoundEvent BLOCK_BAMBOO_SAPLING_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_BAMBOO_SAPLING_BREAK); + public static final CompatSoundEvent BLOCK_BAMBOO_SAPLING_HIT = new CompatSoundEvent(SoundEvents.BLOCK_BAMBOO_SAPLING_HIT); + public static final CompatSoundEvent BLOCK_BAMBOO_SAPLING_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_BAMBOO_SAPLING_PLACE); + public static final CompatSoundEvent BLOCK_BAMBOO_WOOD_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_BAMBOO_WOOD_BREAK); + public static final CompatSoundEvent BLOCK_BAMBOO_WOOD_FALL = new CompatSoundEvent(SoundEvents.BLOCK_BAMBOO_WOOD_FALL); + public static final CompatSoundEvent BLOCK_BAMBOO_WOOD_HIT = new CompatSoundEvent(SoundEvents.BLOCK_BAMBOO_WOOD_HIT); + public static final CompatSoundEvent BLOCK_BAMBOO_WOOD_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_BAMBOO_WOOD_PLACE); + public static final CompatSoundEvent BLOCK_BAMBOO_WOOD_STEP = new CompatSoundEvent(SoundEvents.BLOCK_BAMBOO_WOOD_STEP); + public static final CompatSoundEvent BLOCK_BAMBOO_WOOD_DOOR_CLOSE = new CompatSoundEvent(SoundEvents.BLOCK_BAMBOO_WOOD_DOOR_CLOSE); + public static final CompatSoundEvent BLOCK_BAMBOO_WOOD_DOOR_OPEN = new CompatSoundEvent(SoundEvents.BLOCK_BAMBOO_WOOD_DOOR_OPEN); + public static final CompatSoundEvent BLOCK_BAMBOO_WOOD_TRAPDOOR_CLOSE = new CompatSoundEvent(SoundEvents.BLOCK_BAMBOO_WOOD_TRAPDOOR_CLOSE); + public static final CompatSoundEvent BLOCK_BAMBOO_WOOD_TRAPDOOR_OPEN = new CompatSoundEvent(SoundEvents.BLOCK_BAMBOO_WOOD_TRAPDOOR_OPEN); + public static final CompatSoundEvent BLOCK_BAMBOO_WOOD_BUTTON_CLICK_OFF = new CompatSoundEvent(SoundEvents.BLOCK_BAMBOO_WOOD_BUTTON_CLICK_OFF); + public static final CompatSoundEvent BLOCK_BAMBOO_WOOD_BUTTON_CLICK_ON = new CompatSoundEvent(SoundEvents.BLOCK_BAMBOO_WOOD_BUTTON_CLICK_ON); + public static final CompatSoundEvent BLOCK_BAMBOO_WOOD_PRESSURE_PLATE_CLICK_OFF = new CompatSoundEvent(SoundEvents.BLOCK_BAMBOO_WOOD_PRESSURE_PLATE_CLICK_OFF); + public static final CompatSoundEvent BLOCK_BAMBOO_WOOD_PRESSURE_PLATE_CLICK_ON = new CompatSoundEvent(SoundEvents.BLOCK_BAMBOO_WOOD_PRESSURE_PLATE_CLICK_ON); + public static final CompatSoundEvent BLOCK_BAMBOO_WOOD_FENCE_GATE_CLOSE = new CompatSoundEvent(SoundEvents.BLOCK_BAMBOO_WOOD_FENCE_GATE_CLOSE); + public static final CompatSoundEvent BLOCK_BAMBOO_WOOD_FENCE_GATE_OPEN = new CompatSoundEvent(SoundEvents.BLOCK_BAMBOO_WOOD_FENCE_GATE_OPEN); + public static final CompatSoundEvent BLOCK_BARREL_CLOSE = new CompatSoundEvent(SoundEvents.BLOCK_BARREL_CLOSE); + public static final CompatSoundEvent BLOCK_BARREL_OPEN = new CompatSoundEvent(SoundEvents.BLOCK_BARREL_OPEN); + public static final CompatSoundEvent BLOCK_BASALT_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_BASALT_BREAK); + public static final CompatSoundEvent BLOCK_BASALT_STEP = new CompatSoundEvent(SoundEvents.BLOCK_BASALT_STEP); + public static final CompatSoundEvent BLOCK_BASALT_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_BASALT_PLACE); + public static final CompatSoundEvent BLOCK_BASALT_HIT = new CompatSoundEvent(SoundEvents.BLOCK_BASALT_HIT); + public static final CompatSoundEvent BLOCK_BASALT_FALL = new CompatSoundEvent(SoundEvents.BLOCK_BASALT_FALL); + public static final CompatSoundEvent ENTITY_BAT_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_BAT_AMBIENT); + public static final CompatSoundEvent ENTITY_BAT_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_BAT_DEATH); + public static final CompatSoundEvent ENTITY_BAT_HURT = new CompatSoundEvent(SoundEvents.ENTITY_BAT_HURT); + public static final CompatSoundEvent ENTITY_BAT_LOOP = new CompatSoundEvent(SoundEvents.ENTITY_BAT_LOOP); + public static final CompatSoundEvent ENTITY_BAT_TAKEOFF = new CompatSoundEvent(SoundEvents.ENTITY_BAT_TAKEOFF); + public static final CompatSoundEvent BLOCK_BEACON_ACTIVATE = new CompatSoundEvent(SoundEvents.BLOCK_BEACON_ACTIVATE); + public static final CompatSoundEvent BLOCK_BEACON_AMBIENT = new CompatSoundEvent(SoundEvents.BLOCK_BEACON_AMBIENT); + public static final CompatSoundEvent BLOCK_BEACON_DEACTIVATE = new CompatSoundEvent(SoundEvents.BLOCK_BEACON_DEACTIVATE); + public static final CompatSoundEvent BLOCK_BEACON_POWER_SELECT = new CompatSoundEvent(SoundEvents.BLOCK_BEACON_POWER_SELECT); + public static final CompatSoundEvent ENTITY_BEE_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_BEE_DEATH); + public static final CompatSoundEvent ENTITY_BEE_HURT = new CompatSoundEvent(SoundEvents.ENTITY_BEE_HURT); + public static final CompatSoundEvent ENTITY_BEE_LOOP_AGGRESSIVE = new CompatSoundEvent(SoundEvents.ENTITY_BEE_LOOP_AGGRESSIVE); + public static final CompatSoundEvent ENTITY_BEE_LOOP = new CompatSoundEvent(SoundEvents.ENTITY_BEE_LOOP); + public static final CompatSoundEvent ENTITY_BEE_STING = new CompatSoundEvent(SoundEvents.ENTITY_BEE_STING); + public static final CompatSoundEvent ENTITY_BEE_POLLINATE = new CompatSoundEvent(SoundEvents.ENTITY_BEE_POLLINATE); + public static final CompatSoundEvent BLOCK_BEEHIVE_DRIP = new CompatSoundEvent(SoundEvents.BLOCK_BEEHIVE_DRIP); + public static final CompatSoundEvent BLOCK_BEEHIVE_ENTER = new CompatSoundEvent(SoundEvents.BLOCK_BEEHIVE_ENTER); + public static final CompatSoundEvent BLOCK_BEEHIVE_EXIT = new CompatSoundEvent(SoundEvents.BLOCK_BEEHIVE_EXIT); + public static final CompatSoundEvent BLOCK_BEEHIVE_SHEAR = new CompatSoundEvent(SoundEvents.BLOCK_BEEHIVE_SHEAR); + public static final CompatSoundEvent BLOCK_BEEHIVE_WORK = new CompatSoundEvent(SoundEvents.BLOCK_BEEHIVE_WORK); + public static final CompatSoundEvent BLOCK_BELL_USE = new CompatSoundEvent(SoundEvents.BLOCK_BELL_USE); + public static final CompatSoundEvent BLOCK_BELL_RESONATE = new CompatSoundEvent(SoundEvents.BLOCK_BELL_RESONATE); + public static final CompatSoundEvent BLOCK_BIG_DRIPLEAF_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_BIG_DRIPLEAF_BREAK); + public static final CompatSoundEvent BLOCK_BIG_DRIPLEAF_FALL = new CompatSoundEvent(SoundEvents.BLOCK_BIG_DRIPLEAF_FALL); + public static final CompatSoundEvent BLOCK_BIG_DRIPLEAF_HIT = new CompatSoundEvent(SoundEvents.BLOCK_BIG_DRIPLEAF_HIT); + public static final CompatSoundEvent BLOCK_BIG_DRIPLEAF_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_BIG_DRIPLEAF_PLACE); + public static final CompatSoundEvent BLOCK_BIG_DRIPLEAF_STEP = new CompatSoundEvent(SoundEvents.BLOCK_BIG_DRIPLEAF_STEP); + public static final CompatSoundEvent ENTITY_BLAZE_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_BLAZE_AMBIENT); + public static final CompatSoundEvent ENTITY_BLAZE_BURN = new CompatSoundEvent(SoundEvents.ENTITY_BLAZE_BURN); + public static final CompatSoundEvent ENTITY_BLAZE_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_BLAZE_DEATH); + public static final CompatSoundEvent ENTITY_BLAZE_HURT = new CompatSoundEvent(SoundEvents.ENTITY_BLAZE_HURT); + public static final CompatSoundEvent ENTITY_BLAZE_SHOOT = new CompatSoundEvent(SoundEvents.ENTITY_BLAZE_SHOOT); + public static final CompatSoundEvent ENTITY_BOAT_PADDLE_LAND = new CompatSoundEvent(SoundEvents.ENTITY_BOAT_PADDLE_LAND); + public static final CompatSoundEvent ENTITY_BOAT_PADDLE_WATER = new CompatSoundEvent(SoundEvents.ENTITY_BOAT_PADDLE_WATER); + public static final CompatSoundEvent ENTITY_BOGGED_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_BOGGED_AMBIENT); + public static final CompatSoundEvent ENTITY_BOGGED_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_BOGGED_DEATH); + public static final CompatSoundEvent ENTITY_BOGGED_HURT = new CompatSoundEvent(SoundEvents.ENTITY_BOGGED_HURT); + public static final CompatSoundEvent ENTITY_BOGGED_SHEAR = new CompatSoundEvent(SoundEvents.ENTITY_BOGGED_SHEAR); + public static final CompatSoundEvent ENTITY_BOGGED_STEP = new CompatSoundEvent(SoundEvents.ENTITY_BOGGED_STEP); + public static final CompatSoundEvent BLOCK_BONE_BLOCK_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_BONE_BLOCK_BREAK); + public static final CompatSoundEvent BLOCK_BONE_BLOCK_FALL = new CompatSoundEvent(SoundEvents.BLOCK_BONE_BLOCK_FALL); + public static final CompatSoundEvent BLOCK_BONE_BLOCK_HIT = new CompatSoundEvent(SoundEvents.BLOCK_BONE_BLOCK_HIT); + public static final CompatSoundEvent BLOCK_BONE_BLOCK_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_BONE_BLOCK_PLACE); + public static final CompatSoundEvent BLOCK_BONE_BLOCK_STEP = new CompatSoundEvent(SoundEvents.BLOCK_BONE_BLOCK_STEP); + public static final CompatSoundEvent ITEM_BONE_MEAL_USE = new CompatSoundEvent(SoundEvents.ITEM_BONE_MEAL_USE); + public static final CompatSoundEvent ITEM_BOOK_PAGE_TURN = new CompatSoundEvent(SoundEvents.ITEM_BOOK_PAGE_TURN); + public static final CompatSoundEvent ITEM_BOOK_PUT = new CompatSoundEvent(SoundEvents.ITEM_BOOK_PUT); + public static final CompatSoundEvent BLOCK_BLASTFURNACE_FIRE_CRACKLE = new CompatSoundEvent(SoundEvents.BLOCK_BLASTFURNACE_FIRE_CRACKLE); + public static final CompatSoundEvent ITEM_BOTTLE_EMPTY = new CompatSoundEvent(SoundEvents.ITEM_BOTTLE_EMPTY); + public static final CompatSoundEvent ITEM_BOTTLE_FILL = new CompatSoundEvent(SoundEvents.ITEM_BOTTLE_FILL); + public static final CompatSoundEvent ITEM_BOTTLE_FILL_DRAGONBREATH = new CompatSoundEvent(SoundEvents.ITEM_BOTTLE_FILL_DRAGONBREATH); + public static final CompatSoundEvent ENTITY_BREEZE_CHARGE = new CompatSoundEvent(SoundEvents.ENTITY_BREEZE_CHARGE); + public static final CompatSoundEvent ENTITY_BREEZE_DEFLECT = new CompatSoundEvent(SoundEvents.ENTITY_BREEZE_DEFLECT); + public static final CompatSoundEvent ENTITY_BREEZE_INHALE = new CompatSoundEvent(SoundEvents.ENTITY_BREEZE_INHALE); + public static final CompatSoundEvent ENTITY_BREEZE_IDLE_GROUND = new CompatSoundEvent(SoundEvents.ENTITY_BREEZE_IDLE_GROUND); + public static final CompatSoundEvent ENTITY_BREEZE_IDLE_AIR = new CompatSoundEvent(SoundEvents.ENTITY_BREEZE_IDLE_AIR); + public static final CompatSoundEvent ENTITY_BREEZE_SHOOT = new CompatSoundEvent(SoundEvents.ENTITY_BREEZE_SHOOT); + public static final CompatSoundEvent ENTITY_BREEZE_JUMP = new CompatSoundEvent(SoundEvents.ENTITY_BREEZE_JUMP); + public static final CompatSoundEvent ENTITY_BREEZE_LAND = new CompatSoundEvent(SoundEvents.ENTITY_BREEZE_LAND); + public static final CompatSoundEvent ENTITY_BREEZE_SLIDE = new CompatSoundEvent(SoundEvents.ENTITY_BREEZE_SLIDE); + public static final CompatSoundEvent ENTITY_BREEZE_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_BREEZE_DEATH); + public static final CompatSoundEvent ENTITY_BREEZE_HURT = new CompatSoundEvent(SoundEvents.ENTITY_BREEZE_HURT); + public static final CompatSoundEvent ENTITY_BREEZE_WHIRL = new CompatSoundEvent(SoundEvents.ENTITY_BREEZE_WHIRL); + public static final CompatSoundEvent ENTITY_BREEZE_WIND_BURST = new CompatSoundEvent(SoundEvents.ENTITY_BREEZE_WIND_BURST); + public static final CompatSoundEvent BLOCK_BREWING_STAND_BREW = new CompatSoundEvent(SoundEvents.BLOCK_BREWING_STAND_BREW); + public static final CompatSoundEvent ITEM_BRUSH_BRUSHING_GENERIC = new CompatSoundEvent(SoundEvents.ITEM_BRUSH_BRUSHING_GENERIC); + public static final CompatSoundEvent ITEM_BRUSH_BRUSHING_SAND = new CompatSoundEvent(SoundEvents.ITEM_BRUSH_BRUSHING_SAND); + public static final CompatSoundEvent ITEM_BRUSH_BRUSHING_GRAVEL = new CompatSoundEvent(SoundEvents.ITEM_BRUSH_BRUSHING_GRAVEL); + public static final CompatSoundEvent ITEM_BRUSH_BRUSHING_SAND_COMPLETE = new CompatSoundEvent(SoundEvents.ITEM_BRUSH_BRUSHING_SAND_COMPLETE); + public static final CompatSoundEvent ITEM_BRUSH_BRUSHING_GRAVEL_COMPLETE = new CompatSoundEvent(SoundEvents.ITEM_BRUSH_BRUSHING_GRAVEL_COMPLETE); + public static final CompatSoundEvent BLOCK_BUBBLE_COLUMN_BUBBLE_POP = new CompatSoundEvent(SoundEvents.BLOCK_BUBBLE_COLUMN_BUBBLE_POP); + public static final CompatSoundEvent BLOCK_BUBBLE_COLUMN_UPWARDS_AMBIENT = new CompatSoundEvent(SoundEvents.BLOCK_BUBBLE_COLUMN_UPWARDS_AMBIENT); + public static final CompatSoundEvent BLOCK_BUBBLE_COLUMN_UPWARDS_INSIDE = new CompatSoundEvent(SoundEvents.BLOCK_BUBBLE_COLUMN_UPWARDS_INSIDE); + public static final CompatSoundEvent BLOCK_BUBBLE_COLUMN_WHIRLPOOL_AMBIENT = new CompatSoundEvent(SoundEvents.BLOCK_BUBBLE_COLUMN_WHIRLPOOL_AMBIENT); + public static final CompatSoundEvent BLOCK_BUBBLE_COLUMN_WHIRLPOOL_INSIDE = new CompatSoundEvent(SoundEvents.BLOCK_BUBBLE_COLUMN_WHIRLPOOL_INSIDE); + public static final CompatSoundEvent ITEM_BUCKET_EMPTY = new CompatSoundEvent(SoundEvents.ITEM_BUCKET_EMPTY); + public static final CompatSoundEvent ITEM_BUCKET_EMPTY_AXOLOTL = new CompatSoundEvent(SoundEvents.ITEM_BUCKET_EMPTY_AXOLOTL); + public static final CompatSoundEvent ITEM_BUCKET_EMPTY_FISH = new CompatSoundEvent(SoundEvents.ITEM_BUCKET_EMPTY_FISH); + public static final CompatSoundEvent ITEM_BUCKET_EMPTY_LAVA = new CompatSoundEvent(SoundEvents.ITEM_BUCKET_EMPTY_LAVA); + public static final CompatSoundEvent ITEM_BUCKET_EMPTY_POWDER_SNOW = new CompatSoundEvent(SoundEvents.ITEM_BUCKET_EMPTY_POWDER_SNOW); + public static final CompatSoundEvent ITEM_BUCKET_EMPTY_TADPOLE = new CompatSoundEvent(SoundEvents.ITEM_BUCKET_EMPTY_TADPOLE); + public static final CompatSoundEvent ITEM_BUCKET_FILL = new CompatSoundEvent(SoundEvents.ITEM_BUCKET_FILL); + public static final CompatSoundEvent ITEM_BUCKET_FILL_AXOLOTL = new CompatSoundEvent(SoundEvents.ITEM_BUCKET_FILL_AXOLOTL); + public static final CompatSoundEvent ITEM_BUCKET_FILL_FISH = new CompatSoundEvent(SoundEvents.ITEM_BUCKET_FILL_FISH); + public static final CompatSoundEvent ITEM_BUCKET_FILL_LAVA = new CompatSoundEvent(SoundEvents.ITEM_BUCKET_FILL_LAVA); + public static final CompatSoundEvent ITEM_BUCKET_FILL_POWDER_SNOW = new CompatSoundEvent(SoundEvents.ITEM_BUCKET_FILL_POWDER_SNOW); + public static final CompatSoundEvent ITEM_BUCKET_FILL_TADPOLE = new CompatSoundEvent(SoundEvents.ITEM_BUCKET_FILL_TADPOLE); + public static final CompatSoundEvent ITEM_BUNDLE_DROP_CONTENTS = new CompatSoundEvent(SoundEvents.ITEM_BUNDLE_DROP_CONTENTS); + public static final CompatSoundEvent ITEM_BUNDLE_INSERT = new CompatSoundEvent(SoundEvents.ITEM_BUNDLE_INSERT); + public static final CompatSoundEvent ITEM_BUNDLE_REMOVE_ONE = new CompatSoundEvent(SoundEvents.ITEM_BUNDLE_REMOVE_ONE); + public static final CompatSoundEvent BLOCK_CAKE_ADD_CANDLE = new CompatSoundEvent(SoundEvents.BLOCK_CAKE_ADD_CANDLE); + public static final CompatSoundEvent BLOCK_CALCITE_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_CALCITE_BREAK); + public static final CompatSoundEvent BLOCK_CALCITE_STEP = new CompatSoundEvent(SoundEvents.BLOCK_CALCITE_STEP); + public static final CompatSoundEvent BLOCK_CALCITE_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_CALCITE_PLACE); + public static final CompatSoundEvent BLOCK_CALCITE_HIT = new CompatSoundEvent(SoundEvents.BLOCK_CALCITE_HIT); + public static final CompatSoundEvent BLOCK_CALCITE_FALL = new CompatSoundEvent(SoundEvents.BLOCK_CALCITE_FALL); + public static final CompatSoundEvent ENTITY_CAMEL_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_CAMEL_AMBIENT); + public static final CompatSoundEvent ENTITY_CAMEL_DASH = new CompatSoundEvent(SoundEvents.ENTITY_CAMEL_DASH); + public static final CompatSoundEvent ENTITY_CAMEL_DASH_READY = new CompatSoundEvent(SoundEvents.ENTITY_CAMEL_DASH_READY); + public static final CompatSoundEvent ENTITY_CAMEL_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_CAMEL_DEATH); + public static final CompatSoundEvent ENTITY_CAMEL_EAT = new CompatSoundEvent(SoundEvents.ENTITY_CAMEL_EAT); + public static final CompatSoundEvent ENTITY_CAMEL_HURT = new CompatSoundEvent(SoundEvents.ENTITY_CAMEL_HURT); + public static final CompatSoundEvent ENTITY_CAMEL_SADDLE = new CompatSoundEvent(SoundEvents.ENTITY_CAMEL_SADDLE); + public static final CompatSoundEvent ENTITY_CAMEL_SIT = new CompatSoundEvent(SoundEvents.ENTITY_CAMEL_SIT); + public static final CompatSoundEvent ENTITY_CAMEL_STAND = new CompatSoundEvent(SoundEvents.ENTITY_CAMEL_STAND); + public static final CompatSoundEvent ENTITY_CAMEL_STEP = new CompatSoundEvent(SoundEvents.ENTITY_CAMEL_STEP); + public static final CompatSoundEvent ENTITY_CAMEL_STEP_SAND = new CompatSoundEvent(SoundEvents.ENTITY_CAMEL_STEP_SAND); + public static final CompatSoundEvent BLOCK_CAMPFIRE_CRACKLE = new CompatSoundEvent(SoundEvents.BLOCK_CAMPFIRE_CRACKLE); + public static final CompatSoundEvent BLOCK_CANDLE_AMBIENT = new CompatSoundEvent(SoundEvents.BLOCK_CANDLE_AMBIENT); + public static final CompatSoundEvent BLOCK_CANDLE_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_CANDLE_BREAK); + public static final CompatSoundEvent BLOCK_CANDLE_EXTINGUISH = new CompatSoundEvent(SoundEvents.BLOCK_CANDLE_EXTINGUISH); + public static final CompatSoundEvent BLOCK_CANDLE_FALL = new CompatSoundEvent(SoundEvents.BLOCK_CANDLE_FALL); + public static final CompatSoundEvent BLOCK_CANDLE_HIT = new CompatSoundEvent(SoundEvents.BLOCK_CANDLE_HIT); + public static final CompatSoundEvent BLOCK_CANDLE_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_CANDLE_PLACE); + public static final CompatSoundEvent BLOCK_CANDLE_STEP = new CompatSoundEvent(SoundEvents.BLOCK_CANDLE_STEP); + public static final CompatSoundEvent ENTITY_CAT_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_CAT_AMBIENT); + public static final CompatSoundEvent ENTITY_CAT_STRAY_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_CAT_STRAY_AMBIENT); + public static final CompatSoundEvent ENTITY_CAT_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_CAT_DEATH); + public static final CompatSoundEvent ENTITY_CAT_EAT = new CompatSoundEvent(SoundEvents.ENTITY_CAT_EAT); + public static final CompatSoundEvent ENTITY_CAT_HISS = new CompatSoundEvent(SoundEvents.ENTITY_CAT_HISS); + public static final CompatSoundEvent ENTITY_CAT_BEG_FOR_FOOD = new CompatSoundEvent(SoundEvents.ENTITY_CAT_BEG_FOR_FOOD); + public static final CompatSoundEvent ENTITY_CAT_HURT = new CompatSoundEvent(SoundEvents.ENTITY_CAT_HURT); + public static final CompatSoundEvent ENTITY_CAT_PURR = new CompatSoundEvent(SoundEvents.ENTITY_CAT_PURR); + public static final CompatSoundEvent ENTITY_CAT_PURREOW = new CompatSoundEvent(SoundEvents.ENTITY_CAT_PURREOW); + public static final CompatSoundEvent BLOCK_CAVE_VINES_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_CAVE_VINES_BREAK); + public static final CompatSoundEvent BLOCK_CAVE_VINES_FALL = new CompatSoundEvent(SoundEvents.BLOCK_CAVE_VINES_FALL); + public static final CompatSoundEvent BLOCK_CAVE_VINES_HIT = new CompatSoundEvent(SoundEvents.BLOCK_CAVE_VINES_HIT); + public static final CompatSoundEvent BLOCK_CAVE_VINES_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_CAVE_VINES_PLACE); + public static final CompatSoundEvent BLOCK_CAVE_VINES_STEP = new CompatSoundEvent(SoundEvents.BLOCK_CAVE_VINES_STEP); + public static final CompatSoundEvent BLOCK_CAVE_VINES_PICK_BERRIES = new CompatSoundEvent(SoundEvents.BLOCK_CAVE_VINES_PICK_BERRIES); + public static final CompatSoundEvent BLOCK_CHAIN_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_CHAIN_BREAK); + public static final CompatSoundEvent BLOCK_CHAIN_FALL = new CompatSoundEvent(SoundEvents.BLOCK_CHAIN_FALL); + public static final CompatSoundEvent BLOCK_CHAIN_HIT = new CompatSoundEvent(SoundEvents.BLOCK_CHAIN_HIT); + public static final CompatSoundEvent BLOCK_CHAIN_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_CHAIN_PLACE); + public static final CompatSoundEvent BLOCK_CHAIN_STEP = new CompatSoundEvent(SoundEvents.BLOCK_CHAIN_STEP); + public static final CompatSoundEvent BLOCK_CHERRY_WOOD_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_CHERRY_WOOD_BREAK); + public static final CompatSoundEvent BLOCK_CHERRY_WOOD_FALL = new CompatSoundEvent(SoundEvents.BLOCK_CHERRY_WOOD_FALL); + public static final CompatSoundEvent BLOCK_CHERRY_WOOD_HIT = new CompatSoundEvent(SoundEvents.BLOCK_CHERRY_WOOD_HIT); + public static final CompatSoundEvent BLOCK_CHERRY_WOOD_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_CHERRY_WOOD_PLACE); + public static final CompatSoundEvent BLOCK_CHERRY_WOOD_STEP = new CompatSoundEvent(SoundEvents.BLOCK_CHERRY_WOOD_STEP); + public static final CompatSoundEvent BLOCK_CHERRY_SAPLING_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_CHERRY_SAPLING_BREAK); + public static final CompatSoundEvent BLOCK_CHERRY_SAPLING_FALL = new CompatSoundEvent(SoundEvents.BLOCK_CHERRY_SAPLING_FALL); + public static final CompatSoundEvent BLOCK_CHERRY_SAPLING_HIT = new CompatSoundEvent(SoundEvents.BLOCK_CHERRY_SAPLING_HIT); + public static final CompatSoundEvent BLOCK_CHERRY_SAPLING_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_CHERRY_SAPLING_PLACE); + public static final CompatSoundEvent BLOCK_CHERRY_SAPLING_STEP = new CompatSoundEvent(SoundEvents.BLOCK_CHERRY_SAPLING_STEP); + public static final CompatSoundEvent BLOCK_CHERRY_LEAVES_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_CHERRY_LEAVES_BREAK); + public static final CompatSoundEvent BLOCK_CHERRY_LEAVES_FALL = new CompatSoundEvent(SoundEvents.BLOCK_CHERRY_LEAVES_FALL); + public static final CompatSoundEvent BLOCK_CHERRY_LEAVES_HIT = new CompatSoundEvent(SoundEvents.BLOCK_CHERRY_LEAVES_HIT); + public static final CompatSoundEvent BLOCK_CHERRY_LEAVES_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_CHERRY_LEAVES_PLACE); + public static final CompatSoundEvent BLOCK_CHERRY_LEAVES_STEP = new CompatSoundEvent(SoundEvents.BLOCK_CHERRY_LEAVES_STEP); + public static final CompatSoundEvent BLOCK_CHERRY_WOOD_HANGING_SIGN_STEP = new CompatSoundEvent(SoundEvents.BLOCK_CHERRY_WOOD_HANGING_SIGN_STEP); + public static final CompatSoundEvent BLOCK_CHERRY_WOOD_HANGING_SIGN_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_CHERRY_WOOD_HANGING_SIGN_BREAK); + public static final CompatSoundEvent BLOCK_CHERRY_WOOD_HANGING_SIGN_FALL = new CompatSoundEvent(SoundEvents.BLOCK_CHERRY_WOOD_HANGING_SIGN_FALL); + public static final CompatSoundEvent BLOCK_CHERRY_WOOD_HANGING_SIGN_HIT = new CompatSoundEvent(SoundEvents.BLOCK_CHERRY_WOOD_HANGING_SIGN_HIT); + public static final CompatSoundEvent BLOCK_CHERRY_WOOD_HANGING_SIGN_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_CHERRY_WOOD_HANGING_SIGN_PLACE); + public static final CompatSoundEvent BLOCK_CHERRY_WOOD_DOOR_CLOSE = new CompatSoundEvent(SoundEvents.BLOCK_CHERRY_WOOD_DOOR_CLOSE); + public static final CompatSoundEvent BLOCK_CHERRY_WOOD_DOOR_OPEN = new CompatSoundEvent(SoundEvents.BLOCK_CHERRY_WOOD_DOOR_OPEN); + public static final CompatSoundEvent BLOCK_CHERRY_WOOD_TRAPDOOR_CLOSE = new CompatSoundEvent(SoundEvents.BLOCK_CHERRY_WOOD_TRAPDOOR_CLOSE); + public static final CompatSoundEvent BLOCK_CHERRY_WOOD_TRAPDOOR_OPEN = new CompatSoundEvent(SoundEvents.BLOCK_CHERRY_WOOD_TRAPDOOR_OPEN); + public static final CompatSoundEvent BLOCK_CHERRY_WOOD_BUTTON_CLICK_OFF = new CompatSoundEvent(SoundEvents.BLOCK_CHERRY_WOOD_BUTTON_CLICK_OFF); + public static final CompatSoundEvent BLOCK_CHERRY_WOOD_BUTTON_CLICK_ON = new CompatSoundEvent(SoundEvents.BLOCK_CHERRY_WOOD_BUTTON_CLICK_ON); + public static final CompatSoundEvent BLOCK_CHERRY_WOOD_PRESSURE_PLATE_CLICK_OFF = new CompatSoundEvent(SoundEvents.BLOCK_CHERRY_WOOD_PRESSURE_PLATE_CLICK_OFF); + public static final CompatSoundEvent BLOCK_CHERRY_WOOD_PRESSURE_PLATE_CLICK_ON = new CompatSoundEvent(SoundEvents.BLOCK_CHERRY_WOOD_PRESSURE_PLATE_CLICK_ON); + public static final CompatSoundEvent BLOCK_CHERRY_WOOD_FENCE_GATE_CLOSE = new CompatSoundEvent(SoundEvents.BLOCK_CHERRY_WOOD_FENCE_GATE_CLOSE); + public static final CompatSoundEvent BLOCK_CHERRY_WOOD_FENCE_GATE_OPEN = new CompatSoundEvent(SoundEvents.BLOCK_CHERRY_WOOD_FENCE_GATE_OPEN); + public static final CompatSoundEvent BLOCK_CHEST_CLOSE = new CompatSoundEvent(SoundEvents.BLOCK_CHEST_CLOSE); + public static final CompatSoundEvent BLOCK_CHEST_LOCKED = new CompatSoundEvent(SoundEvents.BLOCK_CHEST_LOCKED); + public static final CompatSoundEvent BLOCK_CHEST_OPEN = new CompatSoundEvent(SoundEvents.BLOCK_CHEST_OPEN); + public static final CompatSoundEvent ENTITY_CHICKEN_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_CHICKEN_AMBIENT); + public static final CompatSoundEvent ENTITY_CHICKEN_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_CHICKEN_DEATH); + public static final CompatSoundEvent ENTITY_CHICKEN_EGG = new CompatSoundEvent(SoundEvents.ENTITY_CHICKEN_EGG); + public static final CompatSoundEvent ENTITY_CHICKEN_HURT = new CompatSoundEvent(SoundEvents.ENTITY_CHICKEN_HURT); + public static final CompatSoundEvent ENTITY_CHICKEN_STEP = new CompatSoundEvent(SoundEvents.ENTITY_CHICKEN_STEP); + public static final CompatSoundEvent BLOCK_CHISELED_BOOKSHELF_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_CHISELED_BOOKSHELF_BREAK); + public static final CompatSoundEvent BLOCK_CHISELED_BOOKSHELF_FALL = new CompatSoundEvent(SoundEvents.BLOCK_CHISELED_BOOKSHELF_FALL); + public static final CompatSoundEvent BLOCK_CHISELED_BOOKSHELF_HIT = new CompatSoundEvent(SoundEvents.BLOCK_CHISELED_BOOKSHELF_HIT); + public static final CompatSoundEvent BLOCK_CHISELED_BOOKSHELF_INSERT = new CompatSoundEvent(SoundEvents.BLOCK_CHISELED_BOOKSHELF_INSERT); + public static final CompatSoundEvent BLOCK_CHISELED_BOOKSHELF_INSERT_ENCHANTED = new CompatSoundEvent(SoundEvents.BLOCK_CHISELED_BOOKSHELF_INSERT_ENCHANTED); + public static final CompatSoundEvent BLOCK_CHISELED_BOOKSHELF_STEP = new CompatSoundEvent(SoundEvents.BLOCK_CHISELED_BOOKSHELF_STEP); + public static final CompatSoundEvent BLOCK_CHISELED_BOOKSHELF_PICKUP = new CompatSoundEvent(SoundEvents.BLOCK_CHISELED_BOOKSHELF_PICKUP); + public static final CompatSoundEvent BLOCK_CHISELED_BOOKSHELF_PICKUP_ENCHANTED = new CompatSoundEvent(SoundEvents.BLOCK_CHISELED_BOOKSHELF_PICKUP_ENCHANTED); + public static final CompatSoundEvent BLOCK_CHISELED_BOOKSHELF_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_CHISELED_BOOKSHELF_PLACE); + public static final CompatSoundEvent BLOCK_CHORUS_FLOWER_DEATH = new CompatSoundEvent(SoundEvents.BLOCK_CHORUS_FLOWER_DEATH); + public static final CompatSoundEvent BLOCK_CHORUS_FLOWER_GROW = new CompatSoundEvent(SoundEvents.BLOCK_CHORUS_FLOWER_GROW); + public static final CompatSoundEvent ITEM_CHORUS_FRUIT_TELEPORT = new CompatSoundEvent(SoundEvents.ITEM_CHORUS_FRUIT_TELEPORT); + public static final CompatSoundEvent BLOCK_COBWEB_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_COBWEB_BREAK); + public static final CompatSoundEvent BLOCK_COBWEB_STEP = new CompatSoundEvent(SoundEvents.BLOCK_COBWEB_STEP); + public static final CompatSoundEvent BLOCK_COBWEB_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_COBWEB_PLACE); + public static final CompatSoundEvent BLOCK_COBWEB_HIT = new CompatSoundEvent(SoundEvents.BLOCK_COBWEB_HIT); + public static final CompatSoundEvent BLOCK_COBWEB_FALL = new CompatSoundEvent(SoundEvents.BLOCK_COBWEB_FALL); + public static final CompatSoundEvent ENTITY_COD_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_COD_AMBIENT); + public static final CompatSoundEvent ENTITY_COD_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_COD_DEATH); + public static final CompatSoundEvent ENTITY_COD_FLOP = new CompatSoundEvent(SoundEvents.ENTITY_COD_FLOP); + public static final CompatSoundEvent ENTITY_COD_HURT = new CompatSoundEvent(SoundEvents.ENTITY_COD_HURT); + public static final CompatSoundEvent BLOCK_COMPARATOR_CLICK = new CompatSoundEvent(SoundEvents.BLOCK_COMPARATOR_CLICK); + public static final CompatSoundEvent BLOCK_COMPOSTER_EMPTY = new CompatSoundEvent(SoundEvents.BLOCK_COMPOSTER_EMPTY); + public static final CompatSoundEvent BLOCK_COMPOSTER_FILL = new CompatSoundEvent(SoundEvents.BLOCK_COMPOSTER_FILL); + public static final CompatSoundEvent BLOCK_COMPOSTER_FILL_SUCCESS = new CompatSoundEvent(SoundEvents.BLOCK_COMPOSTER_FILL_SUCCESS); + public static final CompatSoundEvent BLOCK_COMPOSTER_READY = new CompatSoundEvent(SoundEvents.BLOCK_COMPOSTER_READY); + public static final CompatSoundEvent BLOCK_CONDUIT_ACTIVATE = new CompatSoundEvent(SoundEvents.BLOCK_CONDUIT_ACTIVATE); + public static final CompatSoundEvent BLOCK_CONDUIT_AMBIENT = new CompatSoundEvent(SoundEvents.BLOCK_CONDUIT_AMBIENT); + public static final CompatSoundEvent BLOCK_CONDUIT_AMBIENT_SHORT = new CompatSoundEvent(SoundEvents.BLOCK_CONDUIT_AMBIENT_SHORT); + public static final CompatSoundEvent BLOCK_CONDUIT_ATTACK_TARGET = new CompatSoundEvent(SoundEvents.BLOCK_CONDUIT_ATTACK_TARGET); + public static final CompatSoundEvent BLOCK_CONDUIT_DEACTIVATE = new CompatSoundEvent(SoundEvents.BLOCK_CONDUIT_DEACTIVATE); + public static final CompatSoundEvent BLOCK_COPPER_BULB_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_COPPER_BULB_BREAK); + public static final CompatSoundEvent BLOCK_COPPER_BULB_STEP = new CompatSoundEvent(SoundEvents.BLOCK_COPPER_BULB_STEP); + public static final CompatSoundEvent BLOCK_COPPER_BULB_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_COPPER_BULB_PLACE); + public static final CompatSoundEvent BLOCK_COPPER_BULB_HIT = new CompatSoundEvent(SoundEvents.BLOCK_COPPER_BULB_HIT); + public static final CompatSoundEvent BLOCK_COPPER_BULB_FALL = new CompatSoundEvent(SoundEvents.BLOCK_COPPER_BULB_FALL); + public static final CompatSoundEvent BLOCK_COPPER_BULB_TURN_ON = new CompatSoundEvent(SoundEvents.BLOCK_COPPER_BULB_TURN_ON); + public static final CompatSoundEvent BLOCK_COPPER_BULB_TURN_OFF = new CompatSoundEvent(SoundEvents.BLOCK_COPPER_BULB_TURN_OFF); + public static final CompatSoundEvent BLOCK_COPPER_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_COPPER_BREAK); + public static final CompatSoundEvent BLOCK_COPPER_STEP = new CompatSoundEvent(SoundEvents.BLOCK_COPPER_STEP); + public static final CompatSoundEvent BLOCK_COPPER_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_COPPER_PLACE); + public static final CompatSoundEvent BLOCK_COPPER_HIT = new CompatSoundEvent(SoundEvents.BLOCK_COPPER_HIT); + public static final CompatSoundEvent BLOCK_COPPER_FALL = new CompatSoundEvent(SoundEvents.BLOCK_COPPER_FALL); + public static final CompatSoundEvent BLOCK_COPPER_DOOR_CLOSE = new CompatSoundEvent(SoundEvents.BLOCK_COPPER_DOOR_CLOSE); + public static final CompatSoundEvent BLOCK_COPPER_DOOR_OPEN = new CompatSoundEvent(SoundEvents.BLOCK_COPPER_DOOR_OPEN); + public static final CompatSoundEvent BLOCK_COPPER_GRATE_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_COPPER_GRATE_BREAK); + public static final CompatSoundEvent BLOCK_COPPER_GRATE_STEP = new CompatSoundEvent(SoundEvents.BLOCK_COPPER_GRATE_STEP); + public static final CompatSoundEvent BLOCK_COPPER_GRATE_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_COPPER_GRATE_PLACE); + public static final CompatSoundEvent BLOCK_COPPER_GRATE_HIT = new CompatSoundEvent(SoundEvents.BLOCK_COPPER_GRATE_HIT); + public static final CompatSoundEvent BLOCK_COPPER_GRATE_FALL = new CompatSoundEvent(SoundEvents.BLOCK_COPPER_GRATE_FALL); + public static final CompatSoundEvent BLOCK_COPPER_TRAPDOOR_CLOSE = new CompatSoundEvent(SoundEvents.BLOCK_COPPER_TRAPDOOR_CLOSE); + public static final CompatSoundEvent BLOCK_COPPER_TRAPDOOR_OPEN = new CompatSoundEvent(SoundEvents.BLOCK_COPPER_TRAPDOOR_OPEN); + public static final CompatSoundEvent BLOCK_CORAL_BLOCK_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_CORAL_BLOCK_BREAK); + public static final CompatSoundEvent BLOCK_CORAL_BLOCK_FALL = new CompatSoundEvent(SoundEvents.BLOCK_CORAL_BLOCK_FALL); + public static final CompatSoundEvent BLOCK_CORAL_BLOCK_HIT = new CompatSoundEvent(SoundEvents.BLOCK_CORAL_BLOCK_HIT); + public static final CompatSoundEvent BLOCK_CORAL_BLOCK_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_CORAL_BLOCK_PLACE); + public static final CompatSoundEvent BLOCK_CORAL_BLOCK_STEP = new CompatSoundEvent(SoundEvents.BLOCK_CORAL_BLOCK_STEP); + public static final CompatSoundEvent ENTITY_COW_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_COW_AMBIENT); + public static final CompatSoundEvent ENTITY_COW_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_COW_DEATH); + public static final CompatSoundEvent ENTITY_COW_HURT = new CompatSoundEvent(SoundEvents.ENTITY_COW_HURT); + public static final CompatSoundEvent ENTITY_COW_MILK = new CompatSoundEvent(SoundEvents.ENTITY_COW_MILK); + public static final CompatSoundEvent ENTITY_COW_STEP = new CompatSoundEvent(SoundEvents.ENTITY_COW_STEP); + public static final CompatSoundEvent BLOCK_CRAFTER_CRAFT = new CompatSoundEvent(SoundEvents.BLOCK_CRAFTER_CRAFT); + public static final CompatSoundEvent BLOCK_CRAFTER_FAIL = new CompatSoundEvent(SoundEvents.BLOCK_CRAFTER_FAIL); + public static final CompatSoundEvent ENTITY_CREEPER_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_CREEPER_DEATH); + public static final CompatSoundEvent ENTITY_CREEPER_HURT = new CompatSoundEvent(SoundEvents.ENTITY_CREEPER_HURT); + public static final CompatSoundEvent ENTITY_CREEPER_PRIMED = new CompatSoundEvent(SoundEvents.ENTITY_CREEPER_PRIMED); + public static final CompatSoundEvent BLOCK_CROP_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_CROP_BREAK); + public static final CompatSoundEvent ITEM_CROP_PLANT = new CompatSoundEvent(SoundEvents.ITEM_CROP_PLANT); + public static final CompatSoundEvent ITEM_CROSSBOW_HIT = new CompatSoundEvent(SoundEvents.ITEM_CROSSBOW_HIT); + public static final CompatSoundEvent ITEM_CROSSBOW_LOADING_END = new CompatSoundEvent(SoundEvents.ITEM_CROSSBOW_LOADING_END); + public static final CompatSoundEvent ITEM_CROSSBOW_LOADING_MIDDLE = new CompatSoundEvent(SoundEvents.ITEM_CROSSBOW_LOADING_MIDDLE); + public static final CompatSoundEvent ITEM_CROSSBOW_LOADING_START = new CompatSoundEvent(SoundEvents.ITEM_CROSSBOW_LOADING_START); + public static final CompatSoundEvent ITEM_CROSSBOW_QUICK_CHARGE_1 = new CompatSoundEvent(SoundEvents.ITEM_CROSSBOW_QUICK_CHARGE_1); + public static final CompatSoundEvent ITEM_CROSSBOW_QUICK_CHARGE_2 = new CompatSoundEvent(SoundEvents.ITEM_CROSSBOW_QUICK_CHARGE_2); + public static final CompatSoundEvent ITEM_CROSSBOW_QUICK_CHARGE_3 = new CompatSoundEvent(SoundEvents.ITEM_CROSSBOW_QUICK_CHARGE_3); + public static final CompatSoundEvent ITEM_CROSSBOW_SHOOT = new CompatSoundEvent(SoundEvents.ITEM_CROSSBOW_SHOOT); + public static final CompatSoundEvent BLOCK_DECORATED_POT_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_DECORATED_POT_BREAK); + public static final CompatSoundEvent BLOCK_DECORATED_POT_FALL = new CompatSoundEvent(SoundEvents.BLOCK_DECORATED_POT_FALL); + public static final CompatSoundEvent BLOCK_DECORATED_POT_HIT = new CompatSoundEvent(SoundEvents.BLOCK_DECORATED_POT_HIT); + public static final CompatSoundEvent BLOCK_DECORATED_POT_INSERT = new CompatSoundEvent(SoundEvents.BLOCK_DECORATED_POT_INSERT); + public static final CompatSoundEvent BLOCK_DECORATED_POT_INSERT_FAIL = new CompatSoundEvent(SoundEvents.BLOCK_DECORATED_POT_INSERT_FAIL); + public static final CompatSoundEvent BLOCK_DECORATED_POT_STEP = new CompatSoundEvent(SoundEvents.BLOCK_DECORATED_POT_STEP); + public static final CompatSoundEvent BLOCK_DECORATED_POT_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_DECORATED_POT_PLACE); + public static final CompatSoundEvent BLOCK_DECORATED_POT_SHATTER = new CompatSoundEvent(SoundEvents.BLOCK_DECORATED_POT_SHATTER); + public static final CompatSoundEvent BLOCK_DEEPSLATE_BRICKS_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_DEEPSLATE_BRICKS_BREAK); + public static final CompatSoundEvent BLOCK_DEEPSLATE_BRICKS_FALL = new CompatSoundEvent(SoundEvents.BLOCK_DEEPSLATE_BRICKS_FALL); + public static final CompatSoundEvent BLOCK_DEEPSLATE_BRICKS_HIT = new CompatSoundEvent(SoundEvents.BLOCK_DEEPSLATE_BRICKS_HIT); + public static final CompatSoundEvent BLOCK_DEEPSLATE_BRICKS_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_DEEPSLATE_BRICKS_PLACE); + public static final CompatSoundEvent BLOCK_DEEPSLATE_BRICKS_STEP = new CompatSoundEvent(SoundEvents.BLOCK_DEEPSLATE_BRICKS_STEP); + public static final CompatSoundEvent BLOCK_DEEPSLATE_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_DEEPSLATE_BREAK); + public static final CompatSoundEvent BLOCK_DEEPSLATE_FALL = new CompatSoundEvent(SoundEvents.BLOCK_DEEPSLATE_FALL); + public static final CompatSoundEvent BLOCK_DEEPSLATE_HIT = new CompatSoundEvent(SoundEvents.BLOCK_DEEPSLATE_HIT); + public static final CompatSoundEvent BLOCK_DEEPSLATE_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_DEEPSLATE_PLACE); + public static final CompatSoundEvent BLOCK_DEEPSLATE_STEP = new CompatSoundEvent(SoundEvents.BLOCK_DEEPSLATE_STEP); + public static final CompatSoundEvent BLOCK_DEEPSLATE_TILES_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_DEEPSLATE_TILES_BREAK); + public static final CompatSoundEvent BLOCK_DEEPSLATE_TILES_FALL = new CompatSoundEvent(SoundEvents.BLOCK_DEEPSLATE_TILES_FALL); + public static final CompatSoundEvent BLOCK_DEEPSLATE_TILES_HIT = new CompatSoundEvent(SoundEvents.BLOCK_DEEPSLATE_TILES_HIT); + public static final CompatSoundEvent BLOCK_DEEPSLATE_TILES_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_DEEPSLATE_TILES_PLACE); + public static final CompatSoundEvent BLOCK_DEEPSLATE_TILES_STEP = new CompatSoundEvent(SoundEvents.BLOCK_DEEPSLATE_TILES_STEP); + public static final CompatSoundEvent BLOCK_DISPENSER_DISPENSE = new CompatSoundEvent(SoundEvents.BLOCK_DISPENSER_DISPENSE); + public static final CompatSoundEvent BLOCK_DISPENSER_FAIL = new CompatSoundEvent(SoundEvents.BLOCK_DISPENSER_FAIL); + public static final CompatSoundEvent BLOCK_DISPENSER_LAUNCH = new CompatSoundEvent(SoundEvents.BLOCK_DISPENSER_LAUNCH); + public static final CompatSoundEvent ENTITY_DOLPHIN_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_DOLPHIN_AMBIENT); + public static final CompatSoundEvent ENTITY_DOLPHIN_AMBIENT_WATER = new CompatSoundEvent(SoundEvents.ENTITY_DOLPHIN_AMBIENT_WATER); + public static final CompatSoundEvent ENTITY_DOLPHIN_ATTACK = new CompatSoundEvent(SoundEvents.ENTITY_DOLPHIN_ATTACK); + public static final CompatSoundEvent ENTITY_DOLPHIN_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_DOLPHIN_DEATH); + public static final CompatSoundEvent ENTITY_DOLPHIN_EAT = new CompatSoundEvent(SoundEvents.ENTITY_DOLPHIN_EAT); + public static final CompatSoundEvent ENTITY_DOLPHIN_HURT = new CompatSoundEvent(SoundEvents.ENTITY_DOLPHIN_HURT); + public static final CompatSoundEvent ENTITY_DOLPHIN_JUMP = new CompatSoundEvent(SoundEvents.ENTITY_DOLPHIN_JUMP); + public static final CompatSoundEvent ENTITY_DOLPHIN_PLAY = new CompatSoundEvent(SoundEvents.ENTITY_DOLPHIN_PLAY); + public static final CompatSoundEvent ENTITY_DOLPHIN_SPLASH = new CompatSoundEvent(SoundEvents.ENTITY_DOLPHIN_SPLASH); + public static final CompatSoundEvent ENTITY_DOLPHIN_SWIM = new CompatSoundEvent(SoundEvents.ENTITY_DOLPHIN_SWIM); + public static final CompatSoundEvent ENTITY_DONKEY_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_DONKEY_AMBIENT); + public static final CompatSoundEvent ENTITY_DONKEY_ANGRY = new CompatSoundEvent(SoundEvents.ENTITY_DONKEY_ANGRY); + public static final CompatSoundEvent ENTITY_DONKEY_CHEST = new CompatSoundEvent(SoundEvents.ENTITY_DONKEY_CHEST); + public static final CompatSoundEvent ENTITY_DONKEY_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_DONKEY_DEATH); + public static final CompatSoundEvent ENTITY_DONKEY_EAT = new CompatSoundEvent(SoundEvents.ENTITY_DONKEY_EAT); + public static final CompatSoundEvent ENTITY_DONKEY_HURT = new CompatSoundEvent(SoundEvents.ENTITY_DONKEY_HURT); + public static final CompatSoundEvent ENTITY_DONKEY_JUMP = new CompatSoundEvent(SoundEvents.ENTITY_DONKEY_JUMP); + public static final CompatSoundEvent BLOCK_DRIPSTONE_BLOCK_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_DRIPSTONE_BLOCK_BREAK); + public static final CompatSoundEvent BLOCK_DRIPSTONE_BLOCK_STEP = new CompatSoundEvent(SoundEvents.BLOCK_DRIPSTONE_BLOCK_STEP); + public static final CompatSoundEvent BLOCK_DRIPSTONE_BLOCK_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_DRIPSTONE_BLOCK_PLACE); + public static final CompatSoundEvent BLOCK_DRIPSTONE_BLOCK_HIT = new CompatSoundEvent(SoundEvents.BLOCK_DRIPSTONE_BLOCK_HIT); + public static final CompatSoundEvent BLOCK_DRIPSTONE_BLOCK_FALL = new CompatSoundEvent(SoundEvents.BLOCK_DRIPSTONE_BLOCK_FALL); + public static final CompatSoundEvent BLOCK_POINTED_DRIPSTONE_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_POINTED_DRIPSTONE_BREAK); + public static final CompatSoundEvent BLOCK_POINTED_DRIPSTONE_STEP = new CompatSoundEvent(SoundEvents.BLOCK_POINTED_DRIPSTONE_STEP); + public static final CompatSoundEvent BLOCK_POINTED_DRIPSTONE_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_POINTED_DRIPSTONE_PLACE); + public static final CompatSoundEvent BLOCK_POINTED_DRIPSTONE_HIT = new CompatSoundEvent(SoundEvents.BLOCK_POINTED_DRIPSTONE_HIT); + public static final CompatSoundEvent BLOCK_POINTED_DRIPSTONE_FALL = new CompatSoundEvent(SoundEvents.BLOCK_POINTED_DRIPSTONE_FALL); + public static final CompatSoundEvent BLOCK_POINTED_DRIPSTONE_LAND = new CompatSoundEvent(SoundEvents.BLOCK_POINTED_DRIPSTONE_LAND); + public static final CompatSoundEvent BLOCK_POINTED_DRIPSTONE_DRIP_LAVA = new CompatSoundEvent(SoundEvents.BLOCK_POINTED_DRIPSTONE_DRIP_LAVA); + public static final CompatSoundEvent BLOCK_POINTED_DRIPSTONE_DRIP_WATER = new CompatSoundEvent(SoundEvents.BLOCK_POINTED_DRIPSTONE_DRIP_WATER); + public static final CompatSoundEvent BLOCK_POINTED_DRIPSTONE_DRIP_LAVA_INTO_CAULDRON = new CompatSoundEvent(SoundEvents.BLOCK_POINTED_DRIPSTONE_DRIP_LAVA_INTO_CAULDRON); + public static final CompatSoundEvent BLOCK_POINTED_DRIPSTONE_DRIP_WATER_INTO_CAULDRON = new CompatSoundEvent(SoundEvents.BLOCK_POINTED_DRIPSTONE_DRIP_WATER_INTO_CAULDRON); + public static final CompatSoundEvent BLOCK_BIG_DRIPLEAF_TILT_DOWN = new CompatSoundEvent(SoundEvents.BLOCK_BIG_DRIPLEAF_TILT_DOWN); + public static final CompatSoundEvent BLOCK_BIG_DRIPLEAF_TILT_UP = new CompatSoundEvent(SoundEvents.BLOCK_BIG_DRIPLEAF_TILT_UP); + public static final CompatSoundEvent ENTITY_DROWNED_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_DROWNED_AMBIENT); + public static final CompatSoundEvent ENTITY_DROWNED_AMBIENT_WATER = new CompatSoundEvent(SoundEvents.ENTITY_DROWNED_AMBIENT_WATER); + public static final CompatSoundEvent ENTITY_DROWNED_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_DROWNED_DEATH); + public static final CompatSoundEvent ENTITY_DROWNED_DEATH_WATER = new CompatSoundEvent(SoundEvents.ENTITY_DROWNED_DEATH_WATER); + public static final CompatSoundEvent ENTITY_DROWNED_HURT = new CompatSoundEvent(SoundEvents.ENTITY_DROWNED_HURT); + public static final CompatSoundEvent ENTITY_DROWNED_HURT_WATER = new CompatSoundEvent(SoundEvents.ENTITY_DROWNED_HURT_WATER); + public static final CompatSoundEvent ENTITY_DROWNED_SHOOT = new CompatSoundEvent(SoundEvents.ENTITY_DROWNED_SHOOT); + public static final CompatSoundEvent ENTITY_DROWNED_STEP = new CompatSoundEvent(SoundEvents.ENTITY_DROWNED_STEP); + public static final CompatSoundEvent ENTITY_DROWNED_SWIM = new CompatSoundEvent(SoundEvents.ENTITY_DROWNED_SWIM); + public static final CompatSoundEvent ITEM_DYE_USE = new CompatSoundEvent(SoundEvents.ITEM_DYE_USE); + public static final CompatSoundEvent ENTITY_EGG_THROW = new CompatSoundEvent(SoundEvents.ENTITY_EGG_THROW); + public static final CompatSoundEvent ENTITY_ELDER_GUARDIAN_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_ELDER_GUARDIAN_AMBIENT); + public static final CompatSoundEvent ENTITY_ELDER_GUARDIAN_AMBIENT_LAND = new CompatSoundEvent(SoundEvents.ENTITY_ELDER_GUARDIAN_AMBIENT_LAND); + public static final CompatSoundEvent ENTITY_ELDER_GUARDIAN_CURSE = new CompatSoundEvent(SoundEvents.ENTITY_ELDER_GUARDIAN_CURSE); + public static final CompatSoundEvent ENTITY_ELDER_GUARDIAN_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_ELDER_GUARDIAN_DEATH); + public static final CompatSoundEvent ENTITY_ELDER_GUARDIAN_DEATH_LAND = new CompatSoundEvent(SoundEvents.ENTITY_ELDER_GUARDIAN_DEATH_LAND); + public static final CompatSoundEvent ENTITY_ELDER_GUARDIAN_FLOP = new CompatSoundEvent(SoundEvents.ENTITY_ELDER_GUARDIAN_FLOP); + public static final CompatSoundEvent ENTITY_ELDER_GUARDIAN_HURT = new CompatSoundEvent(SoundEvents.ENTITY_ELDER_GUARDIAN_HURT); + public static final CompatSoundEvent ENTITY_ELDER_GUARDIAN_HURT_LAND = new CompatSoundEvent(SoundEvents.ENTITY_ELDER_GUARDIAN_HURT_LAND); + public static final CompatSoundEvent ITEM_ELYTRA_FLYING = new CompatSoundEvent(SoundEvents.ITEM_ELYTRA_FLYING); + public static final CompatSoundEvent BLOCK_ENCHANTMENT_TABLE_USE = new CompatSoundEvent(SoundEvents.BLOCK_ENCHANTMENT_TABLE_USE); + public static final CompatSoundEvent BLOCK_ENDER_CHEST_CLOSE = new CompatSoundEvent(SoundEvents.BLOCK_ENDER_CHEST_CLOSE); + public static final CompatSoundEvent BLOCK_ENDER_CHEST_OPEN = new CompatSoundEvent(SoundEvents.BLOCK_ENDER_CHEST_OPEN); + public static final CompatSoundEvent ENTITY_ENDER_DRAGON_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_ENDER_DRAGON_AMBIENT); + public static final CompatSoundEvent ENTITY_ENDER_DRAGON_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_ENDER_DRAGON_DEATH); + public static final CompatSoundEvent ENTITY_DRAGON_FIREBALL_EXPLODE = new CompatSoundEvent(SoundEvents.ENTITY_DRAGON_FIREBALL_EXPLODE); + public static final CompatSoundEvent ENTITY_ENDER_DRAGON_FLAP = new CompatSoundEvent(SoundEvents.ENTITY_ENDER_DRAGON_FLAP); + public static final CompatSoundEvent ENTITY_ENDER_DRAGON_GROWL = new CompatSoundEvent(SoundEvents.ENTITY_ENDER_DRAGON_GROWL); + public static final CompatSoundEvent ENTITY_ENDER_DRAGON_HURT = new CompatSoundEvent(SoundEvents.ENTITY_ENDER_DRAGON_HURT); + public static final CompatSoundEvent ENTITY_ENDER_DRAGON_SHOOT = new CompatSoundEvent(SoundEvents.ENTITY_ENDER_DRAGON_SHOOT); + public static final CompatSoundEvent ENTITY_ENDER_EYE_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_ENDER_EYE_DEATH); + public static final CompatSoundEvent ENTITY_ENDER_EYE_LAUNCH = new CompatSoundEvent(SoundEvents.ENTITY_ENDER_EYE_LAUNCH); + public static final CompatSoundEvent ENTITY_ENDERMAN_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_ENDERMAN_AMBIENT); + public static final CompatSoundEvent ENTITY_ENDERMAN_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_ENDERMAN_DEATH); + public static final CompatSoundEvent ENTITY_ENDERMAN_HURT = new CompatSoundEvent(SoundEvents.ENTITY_ENDERMAN_HURT); + public static final CompatSoundEvent ENTITY_ENDERMAN_SCREAM = new CompatSoundEvent(SoundEvents.ENTITY_ENDERMAN_SCREAM); + public static final CompatSoundEvent ENTITY_ENDERMAN_STARE = new CompatSoundEvent(SoundEvents.ENTITY_ENDERMAN_STARE); + public static final CompatSoundEvent ENTITY_ENDERMAN_TELEPORT = new CompatSoundEvent(SoundEvents.ENTITY_ENDERMAN_TELEPORT); + public static final CompatSoundEvent ENTITY_ENDERMITE_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_ENDERMITE_AMBIENT); + public static final CompatSoundEvent ENTITY_ENDERMITE_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_ENDERMITE_DEATH); + public static final CompatSoundEvent ENTITY_ENDERMITE_HURT = new CompatSoundEvent(SoundEvents.ENTITY_ENDERMITE_HURT); + public static final CompatSoundEvent ENTITY_ENDERMITE_STEP = new CompatSoundEvent(SoundEvents.ENTITY_ENDERMITE_STEP); + public static final CompatSoundEvent ENTITY_ENDER_PEARL_THROW = new CompatSoundEvent(SoundEvents.ENTITY_ENDER_PEARL_THROW); + public static final CompatSoundEvent BLOCK_END_GATEWAY_SPAWN = new CompatSoundEvent(SoundEvents.BLOCK_END_GATEWAY_SPAWN); + public static final CompatSoundEvent BLOCK_END_PORTAL_FRAME_FILL = new CompatSoundEvent(SoundEvents.BLOCK_END_PORTAL_FRAME_FILL); + public static final CompatSoundEvent BLOCK_END_PORTAL_SPAWN = new CompatSoundEvent(SoundEvents.BLOCK_END_PORTAL_SPAWN); + public static final CompatSoundEvent ENTITY_EVOKER_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_EVOKER_AMBIENT); + public static final CompatSoundEvent ENTITY_EVOKER_CAST_SPELL = new CompatSoundEvent(SoundEvents.ENTITY_EVOKER_CAST_SPELL); + public static final CompatSoundEvent ENTITY_EVOKER_CELEBRATE = new CompatSoundEvent(SoundEvents.ENTITY_EVOKER_CELEBRATE); + public static final CompatSoundEvent ENTITY_EVOKER_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_EVOKER_DEATH); + public static final CompatSoundEvent ENTITY_EVOKER_FANGS_ATTACK = new CompatSoundEvent(SoundEvents.ENTITY_EVOKER_FANGS_ATTACK); + public static final CompatSoundEvent ENTITY_EVOKER_HURT = new CompatSoundEvent(SoundEvents.ENTITY_EVOKER_HURT); + public static final CompatSoundEvent ENTITY_EVOKER_PREPARE_ATTACK = new CompatSoundEvent(SoundEvents.ENTITY_EVOKER_PREPARE_ATTACK); + public static final CompatSoundEvent ENTITY_EVOKER_PREPARE_SUMMON = new CompatSoundEvent(SoundEvents.ENTITY_EVOKER_PREPARE_SUMMON); + public static final CompatSoundEvent ENTITY_EVOKER_PREPARE_WOLOLO = new CompatSoundEvent(SoundEvents.ENTITY_EVOKER_PREPARE_WOLOLO); + public static final CompatSoundEvent ENTITY_EXPERIENCE_BOTTLE_THROW = new CompatSoundEvent(SoundEvents.ENTITY_EXPERIENCE_BOTTLE_THROW); + public static final CompatSoundEvent ENTITY_EXPERIENCE_ORB_PICKUP = new CompatSoundEvent(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP); + public static final CompatSoundEvent BLOCK_FENCE_GATE_CLOSE = new CompatSoundEvent(SoundEvents.BLOCK_FENCE_GATE_CLOSE); + public static final CompatSoundEvent BLOCK_FENCE_GATE_OPEN = new CompatSoundEvent(SoundEvents.BLOCK_FENCE_GATE_OPEN); + public static final CompatSoundEvent ITEM_FIRECHARGE_USE = new CompatSoundEvent(SoundEvents.ITEM_FIRECHARGE_USE); + public static final CompatSoundEvent ENTITY_FIREWORK_ROCKET_BLAST = new CompatSoundEvent(SoundEvents.ENTITY_FIREWORK_ROCKET_BLAST); + public static final CompatSoundEvent ENTITY_FIREWORK_ROCKET_BLAST_FAR = new CompatSoundEvent(SoundEvents.ENTITY_FIREWORK_ROCKET_BLAST_FAR); + public static final CompatSoundEvent ENTITY_FIREWORK_ROCKET_LARGE_BLAST = new CompatSoundEvent(SoundEvents.ENTITY_FIREWORK_ROCKET_LARGE_BLAST); + public static final CompatSoundEvent ENTITY_FIREWORK_ROCKET_LARGE_BLAST_FAR = new CompatSoundEvent(SoundEvents.ENTITY_FIREWORK_ROCKET_LARGE_BLAST_FAR); + public static final CompatSoundEvent ENTITY_FIREWORK_ROCKET_LAUNCH = new CompatSoundEvent(SoundEvents.ENTITY_FIREWORK_ROCKET_LAUNCH); + public static final CompatSoundEvent ENTITY_FIREWORK_ROCKET_SHOOT = new CompatSoundEvent(SoundEvents.ENTITY_FIREWORK_ROCKET_SHOOT); + public static final CompatSoundEvent ENTITY_FIREWORK_ROCKET_TWINKLE = new CompatSoundEvent(SoundEvents.ENTITY_FIREWORK_ROCKET_TWINKLE); + public static final CompatSoundEvent ENTITY_FIREWORK_ROCKET_TWINKLE_FAR = new CompatSoundEvent(SoundEvents.ENTITY_FIREWORK_ROCKET_TWINKLE_FAR); + public static final CompatSoundEvent BLOCK_FIRE_AMBIENT = new CompatSoundEvent(SoundEvents.BLOCK_FIRE_AMBIENT); + public static final CompatSoundEvent BLOCK_FIRE_EXTINGUISH = new CompatSoundEvent(SoundEvents.BLOCK_FIRE_EXTINGUISH); + public static final CompatSoundEvent ENTITY_FISH_SWIM = new CompatSoundEvent(SoundEvents.ENTITY_FISH_SWIM); + public static final CompatSoundEvent ENTITY_FISHING_BOBBER_RETRIEVE = new CompatSoundEvent(SoundEvents.ENTITY_FISHING_BOBBER_RETRIEVE); + public static final CompatSoundEvent ENTITY_FISHING_BOBBER_SPLASH = new CompatSoundEvent(SoundEvents.ENTITY_FISHING_BOBBER_SPLASH); + public static final CompatSoundEvent ENTITY_FISHING_BOBBER_THROW = new CompatSoundEvent(SoundEvents.ENTITY_FISHING_BOBBER_THROW); + public static final CompatSoundEvent ITEM_FLINTANDSTEEL_USE = new CompatSoundEvent(SoundEvents.ITEM_FLINTANDSTEEL_USE); + public static final CompatSoundEvent BLOCK_FLOWERING_AZALEA_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_FLOWERING_AZALEA_BREAK); + public static final CompatSoundEvent BLOCK_FLOWERING_AZALEA_FALL = new CompatSoundEvent(SoundEvents.BLOCK_FLOWERING_AZALEA_FALL); + public static final CompatSoundEvent BLOCK_FLOWERING_AZALEA_HIT = new CompatSoundEvent(SoundEvents.BLOCK_FLOWERING_AZALEA_HIT); + public static final CompatSoundEvent BLOCK_FLOWERING_AZALEA_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_FLOWERING_AZALEA_PLACE); + public static final CompatSoundEvent BLOCK_FLOWERING_AZALEA_STEP = new CompatSoundEvent(SoundEvents.BLOCK_FLOWERING_AZALEA_STEP); + public static final CompatSoundEvent ENTITY_FOX_AGGRO = new CompatSoundEvent(SoundEvents.ENTITY_FOX_AGGRO); + public static final CompatSoundEvent ENTITY_FOX_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_FOX_AMBIENT); + public static final CompatSoundEvent ENTITY_FOX_BITE = new CompatSoundEvent(SoundEvents.ENTITY_FOX_BITE); + public static final CompatSoundEvent ENTITY_FOX_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_FOX_DEATH); + public static final CompatSoundEvent ENTITY_FOX_EAT = new CompatSoundEvent(SoundEvents.ENTITY_FOX_EAT); + public static final CompatSoundEvent ENTITY_FOX_HURT = new CompatSoundEvent(SoundEvents.ENTITY_FOX_HURT); + public static final CompatSoundEvent ENTITY_FOX_SCREECH = new CompatSoundEvent(SoundEvents.ENTITY_FOX_SCREECH); + public static final CompatSoundEvent ENTITY_FOX_SLEEP = new CompatSoundEvent(SoundEvents.ENTITY_FOX_SLEEP); + public static final CompatSoundEvent ENTITY_FOX_SNIFF = new CompatSoundEvent(SoundEvents.ENTITY_FOX_SNIFF); + public static final CompatSoundEvent ENTITY_FOX_SPIT = new CompatSoundEvent(SoundEvents.ENTITY_FOX_SPIT); + public static final CompatSoundEvent ENTITY_FOX_TELEPORT = new CompatSoundEvent(SoundEvents.ENTITY_FOX_TELEPORT); + public static final CompatSoundEvent BLOCK_SUSPICIOUS_SAND_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_SUSPICIOUS_SAND_BREAK); + public static final CompatSoundEvent BLOCK_SUSPICIOUS_SAND_STEP = new CompatSoundEvent(SoundEvents.BLOCK_SUSPICIOUS_SAND_STEP); + public static final CompatSoundEvent BLOCK_SUSPICIOUS_SAND_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_SUSPICIOUS_SAND_PLACE); + public static final CompatSoundEvent BLOCK_SUSPICIOUS_SAND_HIT = new CompatSoundEvent(SoundEvents.BLOCK_SUSPICIOUS_SAND_HIT); + public static final CompatSoundEvent BLOCK_SUSPICIOUS_SAND_FALL = new CompatSoundEvent(SoundEvents.BLOCK_SUSPICIOUS_SAND_FALL); + public static final CompatSoundEvent BLOCK_SUSPICIOUS_GRAVEL_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_SUSPICIOUS_GRAVEL_BREAK); + public static final CompatSoundEvent BLOCK_SUSPICIOUS_GRAVEL_STEP = new CompatSoundEvent(SoundEvents.BLOCK_SUSPICIOUS_GRAVEL_STEP); + public static final CompatSoundEvent BLOCK_SUSPICIOUS_GRAVEL_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_SUSPICIOUS_GRAVEL_PLACE); + public static final CompatSoundEvent BLOCK_SUSPICIOUS_GRAVEL_HIT = new CompatSoundEvent(SoundEvents.BLOCK_SUSPICIOUS_GRAVEL_HIT); + public static final CompatSoundEvent BLOCK_SUSPICIOUS_GRAVEL_FALL = new CompatSoundEvent(SoundEvents.BLOCK_SUSPICIOUS_GRAVEL_FALL); + public static final CompatSoundEvent BLOCK_FROGLIGHT_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_FROGLIGHT_BREAK); + public static final CompatSoundEvent BLOCK_FROGLIGHT_FALL = new CompatSoundEvent(SoundEvents.BLOCK_FROGLIGHT_FALL); + public static final CompatSoundEvent BLOCK_FROGLIGHT_HIT = new CompatSoundEvent(SoundEvents.BLOCK_FROGLIGHT_HIT); + public static final CompatSoundEvent BLOCK_FROGLIGHT_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_FROGLIGHT_PLACE); + public static final CompatSoundEvent BLOCK_FROGLIGHT_STEP = new CompatSoundEvent(SoundEvents.BLOCK_FROGLIGHT_STEP); + public static final CompatSoundEvent BLOCK_FROGSPAWN_STEP = new CompatSoundEvent(SoundEvents.BLOCK_FROGSPAWN_STEP); + public static final CompatSoundEvent BLOCK_FROGSPAWN_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_FROGSPAWN_BREAK); + public static final CompatSoundEvent BLOCK_FROGSPAWN_FALL = new CompatSoundEvent(SoundEvents.BLOCK_FROGSPAWN_FALL); + public static final CompatSoundEvent BLOCK_FROGSPAWN_HATCH = new CompatSoundEvent(SoundEvents.BLOCK_FROGSPAWN_HATCH); + public static final CompatSoundEvent BLOCK_FROGSPAWN_HIT = new CompatSoundEvent(SoundEvents.BLOCK_FROGSPAWN_HIT); + public static final CompatSoundEvent BLOCK_FROGSPAWN_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_FROGSPAWN_PLACE); + public static final CompatSoundEvent ENTITY_FROG_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_FROG_AMBIENT); + public static final CompatSoundEvent ENTITY_FROG_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_FROG_DEATH); + public static final CompatSoundEvent ENTITY_FROG_EAT = new CompatSoundEvent(SoundEvents.ENTITY_FROG_EAT); + public static final CompatSoundEvent ENTITY_FROG_HURT = new CompatSoundEvent(SoundEvents.ENTITY_FROG_HURT); + public static final CompatSoundEvent ENTITY_FROG_LAY_SPAWN = new CompatSoundEvent(SoundEvents.ENTITY_FROG_LAY_SPAWN); + public static final CompatSoundEvent ENTITY_FROG_LONG_JUMP = new CompatSoundEvent(SoundEvents.ENTITY_FROG_LONG_JUMP); + public static final CompatSoundEvent ENTITY_FROG_STEP = new CompatSoundEvent(SoundEvents.ENTITY_FROG_STEP); + public static final CompatSoundEvent ENTITY_FROG_TONGUE = new CompatSoundEvent(SoundEvents.ENTITY_FROG_TONGUE); + public static final CompatSoundEvent BLOCK_ROOTS_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_ROOTS_BREAK); + public static final CompatSoundEvent BLOCK_ROOTS_STEP = new CompatSoundEvent(SoundEvents.BLOCK_ROOTS_STEP); + public static final CompatSoundEvent BLOCK_ROOTS_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_ROOTS_PLACE); + public static final CompatSoundEvent BLOCK_ROOTS_HIT = new CompatSoundEvent(SoundEvents.BLOCK_ROOTS_HIT); + public static final CompatSoundEvent BLOCK_ROOTS_FALL = new CompatSoundEvent(SoundEvents.BLOCK_ROOTS_FALL); + public static final CompatSoundEvent BLOCK_FURNACE_FIRE_CRACKLE = new CompatSoundEvent(SoundEvents.BLOCK_FURNACE_FIRE_CRACKLE); + public static final CompatSoundEvent ENTITY_GENERIC_BIG_FALL = new CompatSoundEvent(SoundEvents.ENTITY_GENERIC_BIG_FALL); + public static final CompatSoundEvent ENTITY_GENERIC_BURN = new CompatSoundEvent(SoundEvents.ENTITY_GENERIC_BURN); + public static final CompatSoundEvent ENTITY_GENERIC_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_GENERIC_DEATH); + public static final CompatSoundEvent ENTITY_GENERIC_DRINK = new CompatSoundEvent(SoundEvents.ENTITY_GENERIC_DRINK); + public static final CompatSoundEvent ENTITY_GENERIC_EAT = new CompatSoundEvent(SoundEvents.ENTITY_GENERIC_EAT); + public static final CompatSoundEvent ENTITY_GENERIC_EXPLODE = new CompatSoundEvent(SoundEvents.ENTITY_GENERIC_EXPLODE); + public static final CompatSoundEvent ENTITY_GENERIC_EXTINGUISH_FIRE = new CompatSoundEvent(SoundEvents.ENTITY_GENERIC_EXTINGUISH_FIRE); + public static final CompatSoundEvent ENTITY_GENERIC_HURT = new CompatSoundEvent(SoundEvents.ENTITY_GENERIC_HURT); + public static final CompatSoundEvent ENTITY_GENERIC_SMALL_FALL = new CompatSoundEvent(SoundEvents.ENTITY_GENERIC_SMALL_FALL); + public static final CompatSoundEvent ENTITY_GENERIC_SPLASH = new CompatSoundEvent(SoundEvents.ENTITY_GENERIC_SPLASH); + public static final CompatSoundEvent ENTITY_GENERIC_SWIM = new CompatSoundEvent(SoundEvents.ENTITY_GENERIC_SWIM); + public static final CompatSoundEvent ENTITY_GHAST_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_GHAST_AMBIENT); + public static final CompatSoundEvent ENTITY_GHAST_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_GHAST_DEATH); + public static final CompatSoundEvent ENTITY_GHAST_HURT = new CompatSoundEvent(SoundEvents.ENTITY_GHAST_HURT); + public static final CompatSoundEvent ENTITY_GHAST_SCREAM = new CompatSoundEvent(SoundEvents.ENTITY_GHAST_SCREAM); + public static final CompatSoundEvent ENTITY_GHAST_SHOOT = new CompatSoundEvent(SoundEvents.ENTITY_GHAST_SHOOT); + public static final CompatSoundEvent ENTITY_GHAST_WARN = new CompatSoundEvent(SoundEvents.ENTITY_GHAST_WARN); + public static final CompatSoundEvent BLOCK_GILDED_BLACKSTONE_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_GILDED_BLACKSTONE_BREAK); + public static final CompatSoundEvent BLOCK_GILDED_BLACKSTONE_FALL = new CompatSoundEvent(SoundEvents.BLOCK_GILDED_BLACKSTONE_FALL); + public static final CompatSoundEvent BLOCK_GILDED_BLACKSTONE_HIT = new CompatSoundEvent(SoundEvents.BLOCK_GILDED_BLACKSTONE_HIT); + public static final CompatSoundEvent BLOCK_GILDED_BLACKSTONE_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_GILDED_BLACKSTONE_PLACE); + public static final CompatSoundEvent BLOCK_GILDED_BLACKSTONE_STEP = new CompatSoundEvent(SoundEvents.BLOCK_GILDED_BLACKSTONE_STEP); + public static final CompatSoundEvent BLOCK_GLASS_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_GLASS_BREAK); + public static final CompatSoundEvent BLOCK_GLASS_FALL = new CompatSoundEvent(SoundEvents.BLOCK_GLASS_FALL); + public static final CompatSoundEvent BLOCK_GLASS_HIT = new CompatSoundEvent(SoundEvents.BLOCK_GLASS_HIT); + public static final CompatSoundEvent BLOCK_GLASS_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_GLASS_PLACE); + public static final CompatSoundEvent BLOCK_GLASS_STEP = new CompatSoundEvent(SoundEvents.BLOCK_GLASS_STEP); + public static final CompatSoundEvent ITEM_GLOW_INK_SAC_USE = new CompatSoundEvent(SoundEvents.ITEM_GLOW_INK_SAC_USE); + public static final CompatSoundEvent ENTITY_GLOW_ITEM_FRAME_ADD_ITEM = new CompatSoundEvent(SoundEvents.ENTITY_GLOW_ITEM_FRAME_ADD_ITEM); + public static final CompatSoundEvent ENTITY_GLOW_ITEM_FRAME_BREAK = new CompatSoundEvent(SoundEvents.ENTITY_GLOW_ITEM_FRAME_BREAK); + public static final CompatSoundEvent ENTITY_GLOW_ITEM_FRAME_PLACE = new CompatSoundEvent(SoundEvents.ENTITY_GLOW_ITEM_FRAME_PLACE); + public static final CompatSoundEvent ENTITY_GLOW_ITEM_FRAME_REMOVE_ITEM = new CompatSoundEvent(SoundEvents.ENTITY_GLOW_ITEM_FRAME_REMOVE_ITEM); + public static final CompatSoundEvent ENTITY_GLOW_ITEM_FRAME_ROTATE_ITEM = new CompatSoundEvent(SoundEvents.ENTITY_GLOW_ITEM_FRAME_ROTATE_ITEM); + public static final CompatSoundEvent ENTITY_GLOW_SQUID_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_GLOW_SQUID_AMBIENT); + public static final CompatSoundEvent ENTITY_GLOW_SQUID_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_GLOW_SQUID_DEATH); + public static final CompatSoundEvent ENTITY_GLOW_SQUID_HURT = new CompatSoundEvent(SoundEvents.ENTITY_GLOW_SQUID_HURT); + public static final CompatSoundEvent ENTITY_GLOW_SQUID_SQUIRT = new CompatSoundEvent(SoundEvents.ENTITY_GLOW_SQUID_SQUIRT); + public static final CompatSoundEvent ENTITY_GOAT_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_GOAT_AMBIENT); + public static final CompatSoundEvent ENTITY_GOAT_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_GOAT_DEATH); + public static final CompatSoundEvent ENTITY_GOAT_EAT = new CompatSoundEvent(SoundEvents.ENTITY_GOAT_EAT); + public static final CompatSoundEvent ENTITY_GOAT_HURT = new CompatSoundEvent(SoundEvents.ENTITY_GOAT_HURT); + public static final CompatSoundEvent ENTITY_GOAT_LONG_JUMP = new CompatSoundEvent(SoundEvents.ENTITY_GOAT_LONG_JUMP); + public static final CompatSoundEvent ENTITY_GOAT_MILK = new CompatSoundEvent(SoundEvents.ENTITY_GOAT_MILK); + public static final CompatSoundEvent ENTITY_GOAT_PREPARE_RAM = new CompatSoundEvent(SoundEvents.ENTITY_GOAT_PREPARE_RAM); + public static final CompatSoundEvent ENTITY_GOAT_RAM_IMPACT = new CompatSoundEvent(SoundEvents.ENTITY_GOAT_RAM_IMPACT); + public static final CompatSoundEvent ENTITY_GOAT_HORN_BREAK = new CompatSoundEvent(SoundEvents.ENTITY_GOAT_HORN_BREAK); + public static final CompatSoundEvent ITEM_GOAT_HORN_PLAY = new CompatSoundEvent(SoundEvents.ENTITY_GOAT_STEP); + public static final CompatSoundEvent ENTITY_GOAT_SCREAMING_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_GOAT_SCREAMING_AMBIENT); + public static final CompatSoundEvent ENTITY_GOAT_SCREAMING_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_GOAT_SCREAMING_DEATH); + public static final CompatSoundEvent ENTITY_GOAT_SCREAMING_EAT = new CompatSoundEvent(SoundEvents.ENTITY_GOAT_SCREAMING_EAT); + public static final CompatSoundEvent ENTITY_GOAT_SCREAMING_HURT = new CompatSoundEvent(SoundEvents.ENTITY_GOAT_SCREAMING_HURT); + public static final CompatSoundEvent ENTITY_GOAT_SCREAMING_LONG_JUMP = new CompatSoundEvent(SoundEvents.ENTITY_GOAT_SCREAMING_LONG_JUMP); + public static final CompatSoundEvent ENTITY_GOAT_SCREAMING_MILK = new CompatSoundEvent(SoundEvents.ENTITY_GOAT_SCREAMING_MILK); + public static final CompatSoundEvent ENTITY_GOAT_SCREAMING_PREPARE_RAM = new CompatSoundEvent(SoundEvents.ENTITY_GOAT_SCREAMING_PREPARE_RAM); + public static final CompatSoundEvent ENTITY_GOAT_SCREAMING_RAM_IMPACT = new CompatSoundEvent(SoundEvents.ENTITY_GOAT_SCREAMING_RAM_IMPACT); + public static final CompatSoundEvent ENTITY_GOAT_SCREAMING_HORN_BREAK = new CompatSoundEvent(SoundEvents.ENTITY_GOAT_HORN_BREAK); + public static final CompatSoundEvent ENTITY_GOAT_STEP = new CompatSoundEvent(SoundEvents.ENTITY_GOAT_STEP); + public static final CompatSoundEvent BLOCK_GRASS_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_GRASS_BREAK); + public static final CompatSoundEvent BLOCK_GRASS_FALL = new CompatSoundEvent(SoundEvents.BLOCK_GRASS_FALL); + public static final CompatSoundEvent BLOCK_GRASS_HIT = new CompatSoundEvent(SoundEvents.BLOCK_GRASS_HIT); + public static final CompatSoundEvent BLOCK_GRASS_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_GRASS_PLACE); + public static final CompatSoundEvent BLOCK_GRASS_STEP = new CompatSoundEvent(SoundEvents.BLOCK_GRASS_STEP); + public static final CompatSoundEvent BLOCK_GRAVEL_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_GRAVEL_BREAK); + public static final CompatSoundEvent BLOCK_GRAVEL_FALL = new CompatSoundEvent(SoundEvents.BLOCK_GRAVEL_FALL); + public static final CompatSoundEvent BLOCK_GRAVEL_HIT = new CompatSoundEvent(SoundEvents.BLOCK_GRAVEL_HIT); + public static final CompatSoundEvent BLOCK_GRAVEL_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_GRAVEL_PLACE); + public static final CompatSoundEvent BLOCK_GRAVEL_STEP = new CompatSoundEvent(SoundEvents.BLOCK_GRAVEL_STEP); + public static final CompatSoundEvent BLOCK_GRINDSTONE_USE = new CompatSoundEvent(SoundEvents.BLOCK_GRINDSTONE_USE); + public static final CompatSoundEvent BLOCK_GROWING_PLANT_CROP = new CompatSoundEvent(SoundEvents.BLOCK_GROWING_PLANT_CROP); + public static final CompatSoundEvent ENTITY_GUARDIAN_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_GUARDIAN_AMBIENT); + public static final CompatSoundEvent ENTITY_GUARDIAN_AMBIENT_LAND = new CompatSoundEvent(SoundEvents.ENTITY_GUARDIAN_AMBIENT_LAND); + public static final CompatSoundEvent ENTITY_GUARDIAN_ATTACK = new CompatSoundEvent(SoundEvents.ENTITY_GUARDIAN_ATTACK); + public static final CompatSoundEvent ENTITY_GUARDIAN_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_GUARDIAN_DEATH); + public static final CompatSoundEvent ENTITY_GUARDIAN_DEATH_LAND = new CompatSoundEvent(SoundEvents.ENTITY_GUARDIAN_DEATH_LAND); + public static final CompatSoundEvent ENTITY_GUARDIAN_FLOP = new CompatSoundEvent(SoundEvents.ENTITY_GUARDIAN_FLOP); + public static final CompatSoundEvent ENTITY_GUARDIAN_HURT = new CompatSoundEvent(SoundEvents.ENTITY_GUARDIAN_HURT); + public static final CompatSoundEvent ENTITY_GUARDIAN_HURT_LAND = new CompatSoundEvent(SoundEvents.ENTITY_GUARDIAN_HURT_LAND); + public static final CompatSoundEvent BLOCK_HANGING_ROOTS_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_HANGING_ROOTS_BREAK); + public static final CompatSoundEvent BLOCK_HANGING_ROOTS_FALL = new CompatSoundEvent(SoundEvents.BLOCK_HANGING_ROOTS_FALL); + public static final CompatSoundEvent BLOCK_HANGING_ROOTS_HIT = new CompatSoundEvent(SoundEvents.BLOCK_HANGING_ROOTS_HIT); + public static final CompatSoundEvent BLOCK_HANGING_ROOTS_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_HANGING_ROOTS_PLACE); + public static final CompatSoundEvent BLOCK_HANGING_ROOTS_STEP = new CompatSoundEvent(SoundEvents.BLOCK_HANGING_ROOTS_STEP); + public static final CompatSoundEvent BLOCK_HANGING_SIGN_STEP = new CompatSoundEvent(SoundEvents.BLOCK_HANGING_SIGN_STEP); + public static final CompatSoundEvent BLOCK_HANGING_SIGN_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_HANGING_SIGN_BREAK); + public static final CompatSoundEvent BLOCK_HANGING_SIGN_FALL = new CompatSoundEvent(SoundEvents.BLOCK_HANGING_SIGN_FALL); + public static final CompatSoundEvent BLOCK_HANGING_SIGN_HIT = new CompatSoundEvent(SoundEvents.BLOCK_HANGING_SIGN_HIT); + public static final CompatSoundEvent BLOCK_HANGING_SIGN_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_HANGING_SIGN_PLACE); + public static final CompatSoundEvent BLOCK_HEAVY_CORE_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_HEAVY_CORE_BREAK); + public static final CompatSoundEvent BLOCK_HEAVY_CORE_FALL = new CompatSoundEvent(SoundEvents.BLOCK_HEAVY_CORE_FALL); + public static final CompatSoundEvent BLOCK_HEAVY_CORE_HIT = new CompatSoundEvent(SoundEvents.BLOCK_HEAVY_CORE_HIT); + public static final CompatSoundEvent BLOCK_HEAVY_CORE_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_HEAVY_CORE_PLACE); + public static final CompatSoundEvent BLOCK_HEAVY_CORE_STEP = new CompatSoundEvent(SoundEvents.BLOCK_HEAVY_CORE_STEP); + public static final CompatSoundEvent BLOCK_NETHER_WOOD_HANGING_SIGN_STEP = new CompatSoundEvent(SoundEvents.BLOCK_NETHER_WOOD_HANGING_SIGN_STEP); + public static final CompatSoundEvent BLOCK_NETHER_WOOD_HANGING_SIGN_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_NETHER_WOOD_HANGING_SIGN_BREAK); + public static final CompatSoundEvent BLOCK_NETHER_WOOD_HANGING_SIGN_FALL = new CompatSoundEvent(SoundEvents.BLOCK_NETHER_WOOD_HANGING_SIGN_FALL); + public static final CompatSoundEvent BLOCK_NETHER_WOOD_HANGING_SIGN_HIT = new CompatSoundEvent(SoundEvents.BLOCK_NETHER_WOOD_HANGING_SIGN_HIT); + public static final CompatSoundEvent BLOCK_NETHER_WOOD_HANGING_SIGN_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_NETHER_WOOD_HANGING_SIGN_PLACE); + public static final CompatSoundEvent BLOCK_BAMBOO_WOOD_HANGING_SIGN_STEP = new CompatSoundEvent(SoundEvents.BLOCK_BAMBOO_WOOD_HANGING_SIGN_STEP); + public static final CompatSoundEvent BLOCK_BAMBOO_WOOD_HANGING_SIGN_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_BAMBOO_WOOD_HANGING_SIGN_BREAK); + public static final CompatSoundEvent BLOCK_BAMBOO_WOOD_HANGING_SIGN_FALL = new CompatSoundEvent(SoundEvents.BLOCK_BAMBOO_WOOD_HANGING_SIGN_FALL); + public static final CompatSoundEvent BLOCK_BAMBOO_WOOD_HANGING_SIGN_HIT = new CompatSoundEvent(SoundEvents.BLOCK_BAMBOO_WOOD_HANGING_SIGN_HIT); + public static final CompatSoundEvent BLOCK_BAMBOO_WOOD_HANGING_SIGN_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_BAMBOO_WOOD_HANGING_SIGN_PLACE); + public static final CompatSoundEvent BLOCK_TRIAL_SPAWNER_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_TRIAL_SPAWNER_BREAK); + public static final CompatSoundEvent BLOCK_TRIAL_SPAWNER_STEP = new CompatSoundEvent(SoundEvents.BLOCK_TRIAL_SPAWNER_STEP); + public static final CompatSoundEvent BLOCK_TRIAL_SPAWNER_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_TRIAL_SPAWNER_PLACE); + public static final CompatSoundEvent BLOCK_TRIAL_SPAWNER_HIT = new CompatSoundEvent(SoundEvents.BLOCK_TRIAL_SPAWNER_HIT); + public static final CompatSoundEvent BLOCK_TRIAL_SPAWNER_FALL = new CompatSoundEvent(SoundEvents.BLOCK_TRIAL_SPAWNER_FALL); + public static final CompatSoundEvent BLOCK_TRIAL_SPAWNER_SPAWN_MOB = new CompatSoundEvent(SoundEvents.BLOCK_TRIAL_SPAWNER_SPAWN_MOB); + public static final CompatSoundEvent BLOCK_TRIAL_SPAWNER_ABOUT_TO_SPAWN_ITEM = new CompatSoundEvent(SoundEvents.BLOCK_TRIAL_SPAWNER_ABOUT_TO_SPAWN_ITEM); + public static final CompatSoundEvent BLOCK_TRIAL_SPAWNER_SPAWN_ITEM = new CompatSoundEvent(SoundEvents.BLOCK_TRIAL_SPAWNER_SPAWN_ITEM); + public static final CompatSoundEvent BLOCK_TRIAL_SPAWNER_SPAWN_ITEM_BEGIN = new CompatSoundEvent(SoundEvents.BLOCK_TRIAL_SPAWNER_SPAWN_ITEM_BEGIN); + public static final CompatSoundEvent BLOCK_TRIAL_SPAWNER_DETECT_PLAYER = new CompatSoundEvent(SoundEvents.BLOCK_TRIAL_SPAWNER_DETECT_PLAYER); + public static final CompatSoundEvent BLOCK_TRIAL_SPAWNER_OMINOUS_ACTIVATE = new CompatSoundEvent(SoundEvents.BLOCK_TRIAL_SPAWNER_OMINOUS_ACTIVATE); + public static final CompatSoundEvent BLOCK_TRIAL_SPAWNER_AMBIENT = new CompatSoundEvent(SoundEvents.BLOCK_TRIAL_SPAWNER_AMBIENT); + public static final CompatSoundEvent BLOCK_TRIAL_SPAWNER_AMBIENT_OMINOUS = new CompatSoundEvent(SoundEvents.BLOCK_TRIAL_SPAWNER_AMBIENT_OMINOUS); + public static final CompatSoundEvent BLOCK_TRIAL_SPAWNER_OPEN_SHUTTER = new CompatSoundEvent(SoundEvents.BLOCK_TRIAL_SPAWNER_OPEN_SHUTTER); + public static final CompatSoundEvent BLOCK_TRIAL_SPAWNER_CLOSE_SHUTTER = new CompatSoundEvent(SoundEvents.BLOCK_TRIAL_SPAWNER_CLOSE_SHUTTER); + public static final CompatSoundEvent BLOCK_TRIAL_SPAWNER_EJECT_ITEM = new CompatSoundEvent(SoundEvents.BLOCK_TRIAL_SPAWNER_EJECT_ITEM); + public static final CompatSoundEvent ITEM_HOE_TILL = new CompatSoundEvent(SoundEvents.ITEM_HOE_TILL); + public static final CompatSoundEvent ENTITY_HOGLIN_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_HOGLIN_AMBIENT); + public static final CompatSoundEvent ENTITY_HOGLIN_ANGRY = new CompatSoundEvent(SoundEvents.ENTITY_HOGLIN_ANGRY); + public static final CompatSoundEvent ENTITY_HOGLIN_ATTACK = new CompatSoundEvent(SoundEvents.ENTITY_HOGLIN_ATTACK); + public static final CompatSoundEvent ENTITY_HOGLIN_CONVERTED_TO_ZOMBIFIED = new CompatSoundEvent(SoundEvents.ENTITY_HOGLIN_CONVERTED_TO_ZOMBIFIED); + public static final CompatSoundEvent ENTITY_HOGLIN_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_HOGLIN_DEATH); + public static final CompatSoundEvent ENTITY_HOGLIN_HURT = new CompatSoundEvent(SoundEvents.ENTITY_HOGLIN_HURT); + public static final CompatSoundEvent ENTITY_HOGLIN_RETREAT = new CompatSoundEvent(SoundEvents.ENTITY_HOGLIN_RETREAT); + public static final CompatSoundEvent ENTITY_HOGLIN_STEP = new CompatSoundEvent(SoundEvents.ENTITY_HOGLIN_STEP); + public static final CompatSoundEvent BLOCK_HONEY_BLOCK_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_HONEY_BLOCK_BREAK); + public static final CompatSoundEvent BLOCK_HONEY_BLOCK_FALL = new CompatSoundEvent(SoundEvents.BLOCK_HONEY_BLOCK_FALL); + public static final CompatSoundEvent BLOCK_HONEY_BLOCK_HIT = new CompatSoundEvent(SoundEvents.BLOCK_HONEY_BLOCK_HIT); + public static final CompatSoundEvent BLOCK_HONEY_BLOCK_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_HONEY_BLOCK_PLACE); + public static final CompatSoundEvent BLOCK_HONEY_BLOCK_SLIDE = new CompatSoundEvent(SoundEvents.BLOCK_HONEY_BLOCK_SLIDE); + public static final CompatSoundEvent BLOCK_HONEY_BLOCK_STEP = new CompatSoundEvent(SoundEvents.BLOCK_HONEY_BLOCK_STEP); + public static final CompatSoundEvent ITEM_HONEYCOMB_WAX_ON = new CompatSoundEvent(SoundEvents.ITEM_HONEYCOMB_WAX_ON); + public static final CompatSoundEvent ITEM_HONEY_BOTTLE_DRINK = new CompatSoundEvent(SoundEvents.ITEM_HONEY_BOTTLE_DRINK); + public static final int GOAT_HORN_SOUNDS_COUNT = SoundEvents.GOAT_HORN_SOUND_COUNT; + public static final ImmutableList GOAT_HORN_SOUNDS; + public static final CompatSoundEvent ENTITY_HORSE_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_HORSE_AMBIENT); + public static final CompatSoundEvent ENTITY_HORSE_ANGRY = new CompatSoundEvent(SoundEvents.ENTITY_HORSE_ANGRY); + public static final CompatSoundEvent ENTITY_HORSE_ARMOR = new CompatSoundEvent(SoundEvents.ENTITY_HORSE_ARMOR); + public static final CompatSoundEvent ENTITY_HORSE_BREATHE = new CompatSoundEvent(SoundEvents.ENTITY_HORSE_BREATHE); + public static final CompatSoundEvent ENTITY_HORSE_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_HORSE_DEATH); + public static final CompatSoundEvent ENTITY_HORSE_EAT = new CompatSoundEvent(SoundEvents.ENTITY_HORSE_EAT); + public static final CompatSoundEvent ENTITY_HORSE_GALLOP = new CompatSoundEvent(SoundEvents.ENTITY_HORSE_GALLOP); + public static final CompatSoundEvent ENTITY_HORSE_HURT = new CompatSoundEvent(SoundEvents.ENTITY_HORSE_HURT); + public static final CompatSoundEvent ENTITY_HORSE_JUMP = new CompatSoundEvent(SoundEvents.ENTITY_HORSE_JUMP); + public static final CompatSoundEvent ENTITY_HORSE_LAND = new CompatSoundEvent(SoundEvents.ENTITY_HORSE_LAND); + public static final CompatSoundEvent ENTITY_HORSE_SADDLE = new CompatSoundEvent(SoundEvents.ENTITY_HORSE_SADDLE); + public static final CompatSoundEvent ENTITY_HORSE_STEP = new CompatSoundEvent(SoundEvents.ENTITY_HORSE_STEP); + public static final CompatSoundEvent ENTITY_HORSE_STEP_WOOD = new CompatSoundEvent(SoundEvents.ENTITY_HORSE_STEP_WOOD); + public static final CompatSoundEvent ENTITY_HOSTILE_BIG_FALL = new CompatSoundEvent(SoundEvents.ENTITY_HOSTILE_BIG_FALL); + public static final CompatSoundEvent ENTITY_HOSTILE_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_HOSTILE_DEATH); + public static final CompatSoundEvent ENTITY_HOSTILE_HURT = new CompatSoundEvent(SoundEvents.ENTITY_HOSTILE_HURT); + public static final CompatSoundEvent ENTITY_HOSTILE_SMALL_FALL = new CompatSoundEvent(SoundEvents.ENTITY_HOSTILE_SMALL_FALL); + public static final CompatSoundEvent ENTITY_HOSTILE_SPLASH = new CompatSoundEvent(SoundEvents.ENTITY_HOSTILE_SPLASH); + public static final CompatSoundEvent ENTITY_HOSTILE_SWIM = new CompatSoundEvent(SoundEvents.ENTITY_HOSTILE_SWIM); + public static final CompatSoundEvent ENTITY_HUSK_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_HUSK_AMBIENT); + public static final CompatSoundEvent ENTITY_HUSK_CONVERTED_TO_ZOMBIE = new CompatSoundEvent(SoundEvents.ENTITY_HUSK_CONVERTED_TO_ZOMBIE); + public static final CompatSoundEvent ENTITY_HUSK_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_HUSK_DEATH); + public static final CompatSoundEvent ENTITY_HUSK_HURT = new CompatSoundEvent(SoundEvents.ENTITY_HUSK_HURT); + public static final CompatSoundEvent ENTITY_HUSK_STEP = new CompatSoundEvent(SoundEvents.ENTITY_HUSK_STEP); + public static final CompatSoundEvent ENTITY_ILLUSIONER_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_ILLUSIONER_AMBIENT); + public static final CompatSoundEvent ENTITY_ILLUSIONER_CAST_SPELL = new CompatSoundEvent(SoundEvents.ENTITY_ILLUSIONER_CAST_SPELL); + public static final CompatSoundEvent ENTITY_ILLUSIONER_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_ILLUSIONER_DEATH); + public static final CompatSoundEvent ENTITY_ILLUSIONER_HURT = new CompatSoundEvent(SoundEvents.ENTITY_ILLUSIONER_HURT); + public static final CompatSoundEvent ENTITY_ILLUSIONER_MIRROR_MOVE = new CompatSoundEvent(SoundEvents.ENTITY_ILLUSIONER_MIRROR_MOVE); + public static final CompatSoundEvent ENTITY_ILLUSIONER_PREPARE_BLINDNESS = new CompatSoundEvent(SoundEvents.ENTITY_ILLUSIONER_PREPARE_BLINDNESS); + public static final CompatSoundEvent ENTITY_ILLUSIONER_PREPARE_MIRROR = new CompatSoundEvent(SoundEvents.ENTITY_ILLUSIONER_PREPARE_MIRROR); + public static final CompatSoundEvent ITEM_INK_SAC_USE = new CompatSoundEvent(SoundEvents.ITEM_INK_SAC_USE); + public static final CompatSoundEvent BLOCK_IRON_DOOR_CLOSE = new CompatSoundEvent(SoundEvents.BLOCK_IRON_DOOR_CLOSE); + public static final CompatSoundEvent BLOCK_IRON_DOOR_OPEN = new CompatSoundEvent(SoundEvents.BLOCK_IRON_DOOR_OPEN); + public static final CompatSoundEvent ENTITY_IRON_GOLEM_ATTACK = new CompatSoundEvent(SoundEvents.ENTITY_IRON_GOLEM_ATTACK); + public static final CompatSoundEvent ENTITY_IRON_GOLEM_DAMAGE = new CompatSoundEvent(SoundEvents.ENTITY_IRON_GOLEM_DAMAGE); + public static final CompatSoundEvent ENTITY_IRON_GOLEM_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_IRON_GOLEM_DEATH); + public static final CompatSoundEvent ENTITY_IRON_GOLEM_HURT = new CompatSoundEvent(SoundEvents.ENTITY_IRON_GOLEM_HURT); + public static final CompatSoundEvent ENTITY_IRON_GOLEM_REPAIR = new CompatSoundEvent(SoundEvents.ENTITY_IRON_GOLEM_REPAIR); + public static final CompatSoundEvent ENTITY_IRON_GOLEM_STEP = new CompatSoundEvent(SoundEvents.ENTITY_IRON_GOLEM_STEP); + public static final CompatSoundEvent BLOCK_IRON_TRAPDOOR_CLOSE = new CompatSoundEvent(SoundEvents.BLOCK_IRON_TRAPDOOR_CLOSE); + public static final CompatSoundEvent BLOCK_IRON_TRAPDOOR_OPEN = new CompatSoundEvent(SoundEvents.BLOCK_IRON_TRAPDOOR_OPEN); + public static final CompatSoundEvent ENTITY_ITEM_FRAME_ADD_ITEM = new CompatSoundEvent(SoundEvents.ENTITY_ITEM_FRAME_ADD_ITEM); + public static final CompatSoundEvent ENTITY_ITEM_FRAME_BREAK = new CompatSoundEvent(SoundEvents.ENTITY_ITEM_FRAME_BREAK); + public static final CompatSoundEvent ENTITY_ITEM_FRAME_PLACE = new CompatSoundEvent(SoundEvents.ENTITY_ITEM_FRAME_PLACE); + public static final CompatSoundEvent ENTITY_ITEM_FRAME_REMOVE_ITEM = new CompatSoundEvent(SoundEvents.ENTITY_ITEM_FRAME_REMOVE_ITEM); + public static final CompatSoundEvent ENTITY_ITEM_FRAME_ROTATE_ITEM = new CompatSoundEvent(SoundEvents.ENTITY_ITEM_FRAME_ROTATE_ITEM); + public static final CompatSoundEvent ENTITY_ITEM_BREAK = new CompatSoundEvent(SoundEvents.ENTITY_ITEM_BREAK); + public static final CompatSoundEvent ENTITY_ITEM_PICKUP = new CompatSoundEvent(SoundEvents.ENTITY_ITEM_PICKUP); + public static final CompatSoundEvent BLOCK_LADDER_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_LADDER_BREAK); + public static final CompatSoundEvent BLOCK_LADDER_FALL = new CompatSoundEvent(SoundEvents.BLOCK_LADDER_FALL); + public static final CompatSoundEvent BLOCK_LADDER_HIT = new CompatSoundEvent(SoundEvents.BLOCK_LADDER_HIT); + public static final CompatSoundEvent BLOCK_LADDER_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_LADDER_PLACE); + public static final CompatSoundEvent BLOCK_LADDER_STEP = new CompatSoundEvent(SoundEvents.BLOCK_LADDER_STEP); + public static final CompatSoundEvent BLOCK_LANTERN_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_LANTERN_BREAK); + public static final CompatSoundEvent BLOCK_LANTERN_FALL = new CompatSoundEvent(SoundEvents.BLOCK_LANTERN_FALL); + public static final CompatSoundEvent BLOCK_LANTERN_HIT = new CompatSoundEvent(SoundEvents.BLOCK_LANTERN_HIT); + public static final CompatSoundEvent BLOCK_LANTERN_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_LANTERN_PLACE); + public static final CompatSoundEvent BLOCK_LANTERN_STEP = new CompatSoundEvent(SoundEvents.BLOCK_LANTERN_STEP); + public static final CompatSoundEvent BLOCK_LARGE_AMETHYST_BUD_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_LARGE_AMETHYST_BUD_BREAK); + public static final CompatSoundEvent BLOCK_LARGE_AMETHYST_BUD_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_LARGE_AMETHYST_BUD_PLACE); + public static final CompatSoundEvent BLOCK_LAVA_AMBIENT = new CompatSoundEvent(SoundEvents.BLOCK_LAVA_AMBIENT); + public static final CompatSoundEvent BLOCK_LAVA_EXTINGUISH = new CompatSoundEvent(SoundEvents.BLOCK_LAVA_EXTINGUISH); + public static final CompatSoundEvent BLOCK_LAVA_POP = new CompatSoundEvent(SoundEvents.BLOCK_LAVA_POP); + public static final CompatSoundEvent ENTITY_LEASH_KNOT_BREAK = new CompatSoundEvent(SoundEvents.ENTITY_LEASH_KNOT_BREAK); + public static final CompatSoundEvent ENTITY_LEASH_KNOT_PLACE = new CompatSoundEvent(SoundEvents.ENTITY_LEASH_KNOT_PLACE); + public static final CompatSoundEvent BLOCK_LEVER_CLICK = new CompatSoundEvent(SoundEvents.BLOCK_LEVER_CLICK); + public static final CompatSoundEvent ENTITY_LIGHTNING_BOLT_IMPACT = new CompatSoundEvent(SoundEvents.ENTITY_LIGHTNING_BOLT_IMPACT); + public static final CompatSoundEvent ENTITY_LIGHTNING_BOLT_THUNDER = new CompatSoundEvent(SoundEvents.ENTITY_LIGHTNING_BOLT_THUNDER); + public static final CompatSoundEvent ENTITY_LINGERING_POTION_THROW = new CompatSoundEvent(SoundEvents.ENTITY_LINGERING_POTION_THROW); + public static final CompatSoundEvent ENTITY_LLAMA_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_LLAMA_AMBIENT); + public static final CompatSoundEvent ENTITY_LLAMA_ANGRY = new CompatSoundEvent(SoundEvents.ENTITY_LLAMA_ANGRY); + public static final CompatSoundEvent ENTITY_LLAMA_CHEST = new CompatSoundEvent(SoundEvents.ENTITY_LLAMA_CHEST); + public static final CompatSoundEvent ENTITY_LLAMA_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_LLAMA_DEATH); + public static final CompatSoundEvent ENTITY_LLAMA_EAT = new CompatSoundEvent(SoundEvents.ENTITY_LLAMA_EAT); + public static final CompatSoundEvent ENTITY_LLAMA_HURT = new CompatSoundEvent(SoundEvents.ENTITY_LLAMA_HURT); + public static final CompatSoundEvent ENTITY_LLAMA_SPIT = new CompatSoundEvent(SoundEvents.ENTITY_LLAMA_SPIT); + public static final CompatSoundEvent ENTITY_LLAMA_STEP = new CompatSoundEvent(SoundEvents.ENTITY_LLAMA_STEP); + public static final CompatSoundEvent ENTITY_LLAMA_SWAG = new CompatSoundEvent(SoundEvents.ENTITY_LLAMA_SWAG); + public static final CompatSoundEvent ENTITY_MAGMA_CUBE_DEATH_SMALL = new CompatSoundEvent(SoundEvents.ENTITY_MAGMA_CUBE_DEATH_SMALL); + public static final CompatSoundEvent BLOCK_LODESTONE_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_LODESTONE_BREAK); + public static final CompatSoundEvent BLOCK_LODESTONE_STEP = new CompatSoundEvent(SoundEvents.BLOCK_LODESTONE_STEP); + public static final CompatSoundEvent BLOCK_LODESTONE_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_LODESTONE_PLACE); + public static final CompatSoundEvent BLOCK_LODESTONE_HIT = new CompatSoundEvent(SoundEvents.BLOCK_LODESTONE_HIT); + public static final CompatSoundEvent BLOCK_LODESTONE_FALL = new CompatSoundEvent(SoundEvents.BLOCK_LODESTONE_FALL); + public static final CompatSoundEvent ITEM_LODESTONE_COMPASS_LOCK = new CompatSoundEvent(SoundEvents.ITEM_LODESTONE_COMPASS_LOCK); + public static final CompatSoundEvent ITEM_MACE_SMASH_AIR = new CompatSoundEvent(SoundEvents.ITEM_MACE_SMASH_AIR); + public static final CompatSoundEvent ITEM_MACE_SMASH_GROUND = new CompatSoundEvent(SoundEvents.ITEM_MACE_SMASH_GROUND); + public static final CompatSoundEvent ITEM_MACE_SMASH_GROUND_HEAVY = new CompatSoundEvent(SoundEvents.ITEM_MACE_SMASH_GROUND_HEAVY); + public static final CompatSoundEvent ENTITY_MAGMA_CUBE_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_MAGMA_CUBE_DEATH); + public static final CompatSoundEvent ENTITY_MAGMA_CUBE_HURT = new CompatSoundEvent(SoundEvents.ENTITY_MAGMA_CUBE_HURT); + public static final CompatSoundEvent ENTITY_MAGMA_CUBE_HURT_SMALL = new CompatSoundEvent(SoundEvents.ENTITY_MAGMA_CUBE_HURT_SMALL); + public static final CompatSoundEvent ENTITY_MAGMA_CUBE_JUMP = new CompatSoundEvent(SoundEvents.ENTITY_MAGMA_CUBE_JUMP); + public static final CompatSoundEvent ENTITY_MAGMA_CUBE_SQUISH = new CompatSoundEvent(SoundEvents.ENTITY_MAGMA_CUBE_SQUISH); + public static final CompatSoundEvent ENTITY_MAGMA_CUBE_SQUISH_SMALL = new CompatSoundEvent(SoundEvents.ENTITY_MAGMA_CUBE_SQUISH_SMALL); + public static final CompatSoundEvent BLOCK_MANGROVE_ROOTS_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_MANGROVE_ROOTS_BREAK); + public static final CompatSoundEvent BLOCK_MANGROVE_ROOTS_FALL = new CompatSoundEvent(SoundEvents.BLOCK_MANGROVE_ROOTS_FALL); + public static final CompatSoundEvent BLOCK_MANGROVE_ROOTS_HIT = new CompatSoundEvent(SoundEvents.BLOCK_MANGROVE_ROOTS_HIT); + public static final CompatSoundEvent BLOCK_MANGROVE_ROOTS_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_MANGROVE_ROOTS_PLACE); + public static final CompatSoundEvent BLOCK_MANGROVE_ROOTS_STEP = new CompatSoundEvent(SoundEvents.BLOCK_MANGROVE_ROOTS_STEP); + public static final CompatSoundEvent BLOCK_MEDIUM_AMETHYST_BUD_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_MEDIUM_AMETHYST_BUD_BREAK); + public static final CompatSoundEvent BLOCK_MEDIUM_AMETHYST_BUD_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_MEDIUM_AMETHYST_BUD_PLACE); + public static final CompatSoundEvent BLOCK_METAL_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_METAL_BREAK); + public static final CompatSoundEvent BLOCK_METAL_FALL = new CompatSoundEvent(SoundEvents.BLOCK_METAL_FALL); + public static final CompatSoundEvent BLOCK_METAL_HIT = new CompatSoundEvent(SoundEvents.BLOCK_METAL_HIT); + public static final CompatSoundEvent BLOCK_METAL_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_METAL_PLACE); + public static final CompatSoundEvent BLOCK_METAL_PRESSURE_PLATE_CLICK_OFF = new CompatSoundEvent(SoundEvents.BLOCK_METAL_PRESSURE_PLATE_CLICK_OFF); + public static final CompatSoundEvent BLOCK_METAL_PRESSURE_PLATE_CLICK_ON = new CompatSoundEvent(SoundEvents.BLOCK_METAL_PRESSURE_PLATE_CLICK_ON); + public static final CompatSoundEvent BLOCK_METAL_STEP = new CompatSoundEvent(SoundEvents.BLOCK_METAL_STEP); + public static final CompatSoundEvent ENTITY_MINECART_INSIDE_UNDERWATER = new CompatSoundEvent(SoundEvents.ENTITY_MINECART_INSIDE_UNDERWATER); + public static final CompatSoundEvent ENTITY_MINECART_INSIDE = new CompatSoundEvent(SoundEvents.ENTITY_MINECART_INSIDE); + public static final CompatSoundEvent ENTITY_MINECART_RIDING = new CompatSoundEvent(SoundEvents.ENTITY_MINECART_RIDING); + public static final CompatSoundEvent ENTITY_MOOSHROOM_CONVERT = new CompatSoundEvent(SoundEvents.ENTITY_MOOSHROOM_CONVERT); + public static final CompatSoundEvent ENTITY_MOOSHROOM_EAT = new CompatSoundEvent(SoundEvents.ENTITY_MOOSHROOM_EAT); + public static final CompatSoundEvent ENTITY_MOOSHROOM_MILK = new CompatSoundEvent(SoundEvents.ENTITY_MOOSHROOM_MILK); + public static final CompatSoundEvent ENTITY_MOOSHROOM_SUSPICIOUS_MILK = new CompatSoundEvent(SoundEvents.ENTITY_MOOSHROOM_SUSPICIOUS_MILK); + public static final CompatSoundEvent ENTITY_MOOSHROOM_SHEAR = new CompatSoundEvent(SoundEvents.ENTITY_MOOSHROOM_SHEAR); + public static final CompatSoundEvent BLOCK_MOSS_CARPET_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_MOSS_CARPET_BREAK); + public static final CompatSoundEvent BLOCK_MOSS_CARPET_FALL = new CompatSoundEvent(SoundEvents.BLOCK_MOSS_CARPET_FALL); + public static final CompatSoundEvent BLOCK_MOSS_CARPET_HIT = new CompatSoundEvent(SoundEvents.BLOCK_MOSS_CARPET_HIT); + public static final CompatSoundEvent BLOCK_MOSS_CARPET_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_MOSS_CARPET_PLACE); + public static final CompatSoundEvent BLOCK_MOSS_CARPET_STEP = new CompatSoundEvent(SoundEvents.BLOCK_MOSS_CARPET_STEP); + public static final CompatSoundEvent BLOCK_PINK_PETALS_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_PINK_PETALS_BREAK); + public static final CompatSoundEvent BLOCK_PINK_PETALS_FALL = new CompatSoundEvent(SoundEvents.BLOCK_PINK_PETALS_FALL); + public static final CompatSoundEvent BLOCK_PINK_PETALS_HIT = new CompatSoundEvent(SoundEvents.BLOCK_PINK_PETALS_HIT); + public static final CompatSoundEvent BLOCK_PINK_PETALS_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_PINK_PETALS_PLACE); + public static final CompatSoundEvent BLOCK_PINK_PETALS_STEP = new CompatSoundEvent(SoundEvents.BLOCK_PINK_PETALS_STEP); + public static final CompatSoundEvent BLOCK_MOSS_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_MOSS_BREAK); + public static final CompatSoundEvent BLOCK_MOSS_FALL = new CompatSoundEvent(SoundEvents.BLOCK_MOSS_FALL); + public static final CompatSoundEvent BLOCK_MOSS_HIT = new CompatSoundEvent(SoundEvents.BLOCK_MOSS_HIT); + public static final CompatSoundEvent BLOCK_MOSS_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_MOSS_PLACE); + public static final CompatSoundEvent BLOCK_MOSS_STEP = new CompatSoundEvent(SoundEvents.BLOCK_MOSS_STEP); + public static final CompatSoundEvent BLOCK_MUD_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_MUD_BREAK); + public static final CompatSoundEvent BLOCK_MUD_FALL = new CompatSoundEvent(SoundEvents.BLOCK_MUD_FALL); + public static final CompatSoundEvent BLOCK_MUD_HIT = new CompatSoundEvent(SoundEvents.BLOCK_MUD_HIT); + public static final CompatSoundEvent BLOCK_MUD_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_MUD_PLACE); + public static final CompatSoundEvent BLOCK_MUD_STEP = new CompatSoundEvent(SoundEvents.BLOCK_MUD_STEP); + public static final CompatSoundEvent BLOCK_MUD_BRICKS_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_MUD_BRICKS_BREAK); + public static final CompatSoundEvent BLOCK_MUD_BRICKS_FALL = new CompatSoundEvent(SoundEvents.BLOCK_MUD_BRICKS_FALL); + public static final CompatSoundEvent BLOCK_MUD_BRICKS_HIT = new CompatSoundEvent(SoundEvents.BLOCK_MUD_BRICKS_HIT); + public static final CompatSoundEvent BLOCK_MUD_BRICKS_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_MUD_BRICKS_PLACE); + public static final CompatSoundEvent BLOCK_MUD_BRICKS_STEP = new CompatSoundEvent(SoundEvents.BLOCK_MUD_BRICKS_STEP); + public static final CompatSoundEvent BLOCK_MUDDY_MANGROVE_ROOTS_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_MUDDY_MANGROVE_ROOTS_BREAK); + public static final CompatSoundEvent BLOCK_MUDDY_MANGROVE_ROOTS_FALL = new CompatSoundEvent(SoundEvents.BLOCK_MUDDY_MANGROVE_ROOTS_FALL); + public static final CompatSoundEvent BLOCK_MUDDY_MANGROVE_ROOTS_HIT = new CompatSoundEvent(SoundEvents.BLOCK_MUDDY_MANGROVE_ROOTS_HIT); + public static final CompatSoundEvent BLOCK_MUDDY_MANGROVE_ROOTS_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_MUDDY_MANGROVE_ROOTS_PLACE); + public static final CompatSoundEvent BLOCK_MUDDY_MANGROVE_ROOTS_STEP = new CompatSoundEvent(SoundEvents.BLOCK_MUDDY_MANGROVE_ROOTS_STEP); + public static final CompatSoundEvent ENTITY_MULE_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_MULE_AMBIENT); + public static final CompatSoundEvent ENTITY_MULE_ANGRY = new CompatSoundEvent(SoundEvents.ENTITY_MULE_ANGRY); + public static final CompatSoundEvent ENTITY_MULE_CHEST = new CompatSoundEvent(SoundEvents.ENTITY_MULE_CHEST); + public static final CompatSoundEvent ENTITY_MULE_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_MULE_DEATH); + public static final CompatSoundEvent ENTITY_MULE_EAT = new CompatSoundEvent(SoundEvents.ENTITY_MULE_EAT); + public static final CompatSoundEvent ENTITY_MULE_HURT = new CompatSoundEvent(SoundEvents.ENTITY_MULE_HURT); + public static final CompatSoundEvent ENTITY_MULE_JUMP = new CompatSoundEvent(SoundEvents.ENTITY_MULE_JUMP); + public static final CompatSoundEvent MUSIC_CREATIVE = new CompatSoundEvent(SoundEvents.MUSIC_CREATIVE); + public static final CompatSoundEvent MUSIC_CREDITS = new CompatSoundEvent(SoundEvents.MUSIC_CREDITS); + public static final CompatSoundEvent MUSIC_DISC_5 = new CompatSoundEvent(SoundEvents.MUSIC_DISC_5); + public static final CompatSoundEvent MUSIC_DISC_11 = new CompatSoundEvent(SoundEvents.MUSIC_DISC_11); + public static final CompatSoundEvent MUSIC_DISC_13 = new CompatSoundEvent(SoundEvents.MUSIC_DISC_13); + public static final CompatSoundEvent MUSIC_DISC_BLOCKS = new CompatSoundEvent(SoundEvents.MUSIC_DISC_BLOCKS); + public static final CompatSoundEvent MUSIC_DISC_CAT = new CompatSoundEvent(SoundEvents.MUSIC_DISC_CAT); + public static final CompatSoundEvent MUSIC_DISC_CHIRP = new CompatSoundEvent(SoundEvents.MUSIC_DISC_CHIRP); + public static final CompatSoundEvent MUSIC_DISC_FAR = new CompatSoundEvent(SoundEvents.MUSIC_DISC_FAR); + public static final CompatSoundEvent MUSIC_DISC_MALL = new CompatSoundEvent(SoundEvents.MUSIC_DISC_MALL); + public static final CompatSoundEvent MUSIC_DISC_MELLOHI = new CompatSoundEvent(SoundEvents.MUSIC_DISC_MELLOHI); + public static final CompatSoundEvent MUSIC_DISC_PIGSTEP = new CompatSoundEvent(SoundEvents.MUSIC_DISC_PIGSTEP); + public static final CompatSoundEvent MUSIC_DISC_STAL = new CompatSoundEvent(SoundEvents.MUSIC_DISC_STAL); + public static final CompatSoundEvent MUSIC_DISC_STRAD = new CompatSoundEvent(SoundEvents.MUSIC_DISC_STRAD); + public static final CompatSoundEvent MUSIC_DISC_WAIT = new CompatSoundEvent(SoundEvents.MUSIC_DISC_WAIT); + public static final CompatSoundEvent MUSIC_DISC_WARD = new CompatSoundEvent(SoundEvents.MUSIC_DISC_WARD); + public static final CompatSoundEvent MUSIC_DISC_OTHERSIDE = new CompatSoundEvent(SoundEvents.MUSIC_DISC_OTHERSIDE); + public static final CompatSoundEvent MUSIC_DISC_RELIC = new CompatSoundEvent(SoundEvents.MUSIC_DISC_RELIC); + public static final CompatSoundEvent MUSIC_DISC_CREATOR = new CompatSoundEvent(SoundEvents.MUSIC_DISC_CREATOR); + public static final CompatSoundEvent MUSIC_DISC_CREATOR_MUSIC_BOX = new CompatSoundEvent(SoundEvents.MUSIC_DISC_CREATOR_MUSIC_BOX); + public static final CompatSoundEvent MUSIC_DISC_PRECIPICE = new CompatSoundEvent(SoundEvents.MUSIC_DISC_PRECIPICE); + public static final CompatSoundEvent MUSIC_DRAGON = new CompatSoundEvent(SoundEvents.MUSIC_DRAGON); + public static final CompatSoundEvent MUSIC_END = new CompatSoundEvent(SoundEvents.MUSIC_END); + public static final CompatSoundEvent MUSIC_GAME = new CompatSoundEvent(SoundEvents.MUSIC_GAME); + public static final CompatSoundEvent MUSIC_MENU = new CompatSoundEvent(SoundEvents.MUSIC_MENU); + public static final CompatSoundEvent MUSIC_NETHER_BASALT_DELTAS = new CompatSoundEvent(SoundEvents.MUSIC_NETHER_BASALT_DELTAS); + public static final CompatSoundEvent MUSIC_NETHER_CRIMSON_FOREST = new CompatSoundEvent(SoundEvents.MUSIC_NETHER_CRIMSON_FOREST); + public static final CompatSoundEvent MUSIC_OVERWORLD_DEEP_DARK = new CompatSoundEvent(SoundEvents.MUSIC_OVERWORLD_DEEP_DARK); + public static final CompatSoundEvent MUSIC_OVERWORLD_DRIPSTONE_CAVES = new CompatSoundEvent(SoundEvents.MUSIC_OVERWORLD_DRIPSTONE_CAVES); + public static final CompatSoundEvent MUSIC_OVERWORLD_GROVE = new CompatSoundEvent(SoundEvents.MUSIC_OVERWORLD_GROVE); + public static final CompatSoundEvent MUSIC_OVERWORLD_JAGGED_PEAKS = new CompatSoundEvent(SoundEvents.MUSIC_OVERWORLD_JAGGED_PEAKS); + public static final CompatSoundEvent MUSIC_OVERWORLD_LUSH_CAVES = new CompatSoundEvent(SoundEvents.MUSIC_OVERWORLD_LUSH_CAVES); + public static final CompatSoundEvent MUSIC_OVERWORLD_SWAMP = new CompatSoundEvent(SoundEvents.MUSIC_OVERWORLD_SWAMP); + public static final CompatSoundEvent MUSIC_OVERWORLD_FOREST = new CompatSoundEvent(SoundEvents.MUSIC_OVERWORLD_FOREST); + public static final CompatSoundEvent MUSIC_OVERWORLD_OLD_GROWTH_TAIGA = new CompatSoundEvent(SoundEvents.MUSIC_OVERWORLD_OLD_GROWTH_TAIGA); + public static final CompatSoundEvent MUSIC_OVERWORLD_MEADOW = new CompatSoundEvent(SoundEvents.MUSIC_OVERWORLD_MEADOW); + public static final CompatSoundEvent MUSIC_OVERWORLD_CHERRY_GROVE = new CompatSoundEvent(SoundEvents.MUSIC_OVERWORLD_CHERRY_GROVE); + public static final CompatSoundEvent MUSIC_NETHER_NETHER_WASTES = new CompatSoundEvent(SoundEvents.MUSIC_NETHER_NETHER_WASTES); + public static final CompatSoundEvent MUSIC_OVERWORLD_FROZEN_PEAKS = new CompatSoundEvent(SoundEvents.MUSIC_OVERWORLD_FROZEN_PEAKS); + public static final CompatSoundEvent MUSIC_OVERWORLD_SNOWY_SLOPES = new CompatSoundEvent(SoundEvents.MUSIC_OVERWORLD_SNOWY_SLOPES); + public static final CompatSoundEvent MUSIC_NETHER_SOUL_SAND_VALLEY = new CompatSoundEvent(SoundEvents.MUSIC_NETHER_SOUL_SAND_VALLEY); + public static final CompatSoundEvent MUSIC_OVERWORLD_STONY_PEAKS = new CompatSoundEvent(SoundEvents.MUSIC_OVERWORLD_STONY_PEAKS); + public static final CompatSoundEvent MUSIC_NETHER_WARPED_FOREST = new CompatSoundEvent(SoundEvents.MUSIC_NETHER_WARPED_FOREST); + public static final CompatSoundEvent MUSIC_OVERWORLD_FLOWER_FOREST = new CompatSoundEvent(SoundEvents.MUSIC_OVERWORLD_FLOWER_FOREST); + public static final CompatSoundEvent MUSIC_OVERWORLD_DESERT = new CompatSoundEvent(SoundEvents.MUSIC_OVERWORLD_DESERT); + public static final CompatSoundEvent MUSIC_OVERWORLD_BADLANDS = new CompatSoundEvent(SoundEvents.MUSIC_OVERWORLD_BADLANDS); + public static final CompatSoundEvent MUSIC_OVERWORLD_JUNGLE = new CompatSoundEvent(SoundEvents.MUSIC_OVERWORLD_JUNGLE); + public static final CompatSoundEvent MUSIC_OVERWORLD_SPARSE_JUNGLE = new CompatSoundEvent(SoundEvents.MUSIC_OVERWORLD_SPARSE_JUNGLE); + public static final CompatSoundEvent MUSIC_OVERWORLD_BAMBOO_JUNGLE = new CompatSoundEvent(SoundEvents.MUSIC_OVERWORLD_BAMBOO_JUNGLE); + public static final CompatSoundEvent MUSIC_UNDER_WATER = new CompatSoundEvent(SoundEvents.MUSIC_UNDER_WATER); + public static final CompatSoundEvent BLOCK_NETHER_BRICKS_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_NETHER_BRICKS_BREAK); + public static final CompatSoundEvent BLOCK_NETHER_BRICKS_STEP = new CompatSoundEvent(SoundEvents.BLOCK_NETHER_BRICKS_STEP); + public static final CompatSoundEvent BLOCK_NETHER_BRICKS_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_NETHER_BRICKS_PLACE); + public static final CompatSoundEvent BLOCK_NETHER_BRICKS_HIT = new CompatSoundEvent(SoundEvents.BLOCK_NETHER_BRICKS_HIT); + public static final CompatSoundEvent BLOCK_NETHER_BRICKS_FALL = new CompatSoundEvent(SoundEvents.BLOCK_NETHER_BRICKS_FALL); + public static final CompatSoundEvent BLOCK_NETHER_WART_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_NETHER_WART_BREAK); + public static final CompatSoundEvent ITEM_NETHER_WART_PLANT = new CompatSoundEvent(SoundEvents.ITEM_NETHER_WART_PLANT); + public static final CompatSoundEvent BLOCK_NETHER_WOOD_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_NETHER_WOOD_BREAK); + public static final CompatSoundEvent BLOCK_NETHER_WOOD_FALL = new CompatSoundEvent(SoundEvents.BLOCK_NETHER_WOOD_FALL); + public static final CompatSoundEvent BLOCK_NETHER_WOOD_HIT = new CompatSoundEvent(SoundEvents.BLOCK_NETHER_WOOD_HIT); + public static final CompatSoundEvent BLOCK_NETHER_WOOD_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_NETHER_WOOD_PLACE); + public static final CompatSoundEvent BLOCK_NETHER_WOOD_STEP = new CompatSoundEvent(SoundEvents.BLOCK_NETHER_WOOD_STEP); + public static final CompatSoundEvent BLOCK_NETHER_WOOD_DOOR_CLOSE = new CompatSoundEvent(SoundEvents.BLOCK_NETHER_WOOD_DOOR_CLOSE); + public static final CompatSoundEvent BLOCK_NETHER_WOOD_DOOR_OPEN = new CompatSoundEvent(SoundEvents.BLOCK_NETHER_WOOD_DOOR_OPEN); + public static final CompatSoundEvent BLOCK_NETHER_WOOD_TRAPDOOR_CLOSE = new CompatSoundEvent(SoundEvents.BLOCK_NETHER_WOOD_TRAPDOOR_CLOSE); + public static final CompatSoundEvent BLOCK_NETHER_WOOD_TRAPDOOR_OPEN = new CompatSoundEvent(SoundEvents.BLOCK_NETHER_WOOD_TRAPDOOR_OPEN); + public static final CompatSoundEvent BLOCK_NETHER_WOOD_BUTTON_CLICK_OFF = new CompatSoundEvent(SoundEvents.BLOCK_NETHER_WOOD_BUTTON_CLICK_OFF); + public static final CompatSoundEvent BLOCK_NETHER_WOOD_BUTTON_CLICK_ON = new CompatSoundEvent(SoundEvents.BLOCK_NETHER_WOOD_BUTTON_CLICK_ON); + public static final CompatSoundEvent BLOCK_NETHER_WOOD_PRESSURE_PLATE_CLICK_OFF = new CompatSoundEvent(SoundEvents.BLOCK_NETHER_WOOD_PRESSURE_PLATE_CLICK_OFF); + public static final CompatSoundEvent BLOCK_NETHER_WOOD_PRESSURE_PLATE_CLICK_ON = new CompatSoundEvent(SoundEvents.BLOCK_NETHER_WOOD_PRESSURE_PLATE_CLICK_ON); + public static final CompatSoundEvent BLOCK_NETHER_WOOD_FENCE_GATE_CLOSE = new CompatSoundEvent(SoundEvents.BLOCK_NETHER_WOOD_FENCE_GATE_CLOSE); + public static final CompatSoundEvent BLOCK_NETHER_WOOD_FENCE_GATE_OPEN = new CompatSoundEvent(SoundEvents.BLOCK_NETHER_WOOD_FENCE_GATE_OPEN); + public static final CompatSoundEvent INTENTIONALLY_EMPTY = new CompatSoundEvent(SoundEvents.INTENTIONALLY_EMPTY); + public static final CompatSoundEvent BLOCK_PACKED_MUD_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_PACKED_MUD_BREAK); + public static final CompatSoundEvent BLOCK_PACKED_MUD_FALL = new CompatSoundEvent(SoundEvents.BLOCK_PACKED_MUD_FALL); + public static final CompatSoundEvent BLOCK_PACKED_MUD_HIT = new CompatSoundEvent(SoundEvents.BLOCK_PACKED_MUD_HIT); + public static final CompatSoundEvent BLOCK_PACKED_MUD_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_PACKED_MUD_PLACE); + public static final CompatSoundEvent BLOCK_PACKED_MUD_STEP = new CompatSoundEvent(SoundEvents.BLOCK_PACKED_MUD_STEP); + public static final CompatSoundEvent BLOCK_STEM_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_STEM_BREAK); + public static final CompatSoundEvent BLOCK_STEM_STEP = new CompatSoundEvent(SoundEvents.BLOCK_STEM_STEP); + public static final CompatSoundEvent BLOCK_STEM_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_STEM_PLACE); + public static final CompatSoundEvent BLOCK_STEM_HIT = new CompatSoundEvent(SoundEvents.BLOCK_STEM_HIT); + public static final CompatSoundEvent BLOCK_STEM_FALL = new CompatSoundEvent(SoundEvents.BLOCK_STEM_FALL); + public static final CompatSoundEvent BLOCK_NYLIUM_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_NYLIUM_BREAK); + public static final CompatSoundEvent BLOCK_NYLIUM_STEP = new CompatSoundEvent(SoundEvents.BLOCK_NYLIUM_STEP); + public static final CompatSoundEvent BLOCK_NYLIUM_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_NYLIUM_PLACE); + public static final CompatSoundEvent BLOCK_NYLIUM_HIT = new CompatSoundEvent(SoundEvents.BLOCK_NYLIUM_HIT); + public static final CompatSoundEvent BLOCK_NYLIUM_FALL = new CompatSoundEvent(SoundEvents.BLOCK_NYLIUM_FALL); + public static final CompatSoundEvent BLOCK_NETHER_SPROUTS_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_NETHER_SPROUTS_BREAK); + public static final CompatSoundEvent BLOCK_NETHER_SPROUTS_STEP = new CompatSoundEvent(SoundEvents.BLOCK_NETHER_SPROUTS_STEP); + public static final CompatSoundEvent BLOCK_NETHER_SPROUTS_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_NETHER_SPROUTS_PLACE); + public static final CompatSoundEvent BLOCK_NETHER_SPROUTS_HIT = new CompatSoundEvent(SoundEvents.BLOCK_NETHER_SPROUTS_HIT); + public static final CompatSoundEvent BLOCK_NETHER_SPROUTS_FALL = new CompatSoundEvent(SoundEvents.BLOCK_NETHER_SPROUTS_FALL); + public static final CompatSoundEvent BLOCK_FUNGUS_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_FUNGUS_BREAK); + public static final CompatSoundEvent BLOCK_FUNGUS_STEP = new CompatSoundEvent(SoundEvents.BLOCK_FUNGUS_STEP); + public static final CompatSoundEvent BLOCK_FUNGUS_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_FUNGUS_PLACE); + public static final CompatSoundEvent BLOCK_FUNGUS_HIT = new CompatSoundEvent(SoundEvents.BLOCK_FUNGUS_HIT); + public static final CompatSoundEvent BLOCK_FUNGUS_FALL = new CompatSoundEvent(SoundEvents.BLOCK_FUNGUS_FALL); + public static final CompatSoundEvent BLOCK_WEEPING_VINES_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_WEEPING_VINES_BREAK); + public static final CompatSoundEvent BLOCK_WEEPING_VINES_STEP = new CompatSoundEvent(SoundEvents.BLOCK_WEEPING_VINES_STEP); + public static final CompatSoundEvent BLOCK_WEEPING_VINES_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_WEEPING_VINES_PLACE); + public static final CompatSoundEvent BLOCK_WEEPING_VINES_HIT = new CompatSoundEvent(SoundEvents.BLOCK_WEEPING_VINES_HIT); + public static final CompatSoundEvent BLOCK_WEEPING_VINES_FALL = new CompatSoundEvent(SoundEvents.BLOCK_WEEPING_VINES_FALL); + public static final CompatSoundEvent BLOCK_WART_BLOCK_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_WART_BLOCK_BREAK); + public static final CompatSoundEvent BLOCK_WART_BLOCK_STEP = new CompatSoundEvent(SoundEvents.BLOCK_WART_BLOCK_STEP); + public static final CompatSoundEvent BLOCK_WART_BLOCK_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_WART_BLOCK_PLACE); + public static final CompatSoundEvent BLOCK_WART_BLOCK_HIT = new CompatSoundEvent(SoundEvents.BLOCK_WART_BLOCK_HIT); + public static final CompatSoundEvent BLOCK_WART_BLOCK_FALL = new CompatSoundEvent(SoundEvents.BLOCK_WART_BLOCK_FALL); + public static final CompatSoundEvent BLOCK_NETHERITE_BLOCK_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_NETHERITE_BLOCK_BREAK); + public static final CompatSoundEvent BLOCK_NETHERITE_BLOCK_STEP = new CompatSoundEvent(SoundEvents.BLOCK_NETHERITE_BLOCK_STEP); + public static final CompatSoundEvent BLOCK_NETHERITE_BLOCK_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_NETHERITE_BLOCK_PLACE); + public static final CompatSoundEvent BLOCK_NETHERITE_BLOCK_HIT = new CompatSoundEvent(SoundEvents.BLOCK_NETHERITE_BLOCK_HIT); + public static final CompatSoundEvent BLOCK_NETHERITE_BLOCK_FALL = new CompatSoundEvent(SoundEvents.BLOCK_NETHERITE_BLOCK_FALL); + public static final CompatSoundEvent BLOCK_NETHERRACK_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_NETHERRACK_BREAK); + public static final CompatSoundEvent BLOCK_NETHERRACK_STEP = new CompatSoundEvent(SoundEvents.BLOCK_NETHERRACK_STEP); + public static final CompatSoundEvent BLOCK_NETHERRACK_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_NETHERRACK_PLACE); + public static final CompatSoundEvent BLOCK_NETHERRACK_HIT = new CompatSoundEvent(SoundEvents.BLOCK_NETHERRACK_HIT); + public static final CompatSoundEvent BLOCK_NETHERRACK_FALL = new CompatSoundEvent(SoundEvents.BLOCK_NETHERRACK_FALL); + public static final CompatSoundEvent BLOCK_NOTE_BLOCK_BASEDRUM = new CompatSoundEvent(SoundEvents.BLOCK_NOTE_BLOCK_BASEDRUM); + public static final CompatSoundEvent BLOCK_NOTE_BLOCK_BASS = new CompatSoundEvent(SoundEvents.BLOCK_NOTE_BLOCK_BASS); + public static final CompatSoundEvent BLOCK_NOTE_BLOCK_BELL = new CompatSoundEvent(SoundEvents.BLOCK_NOTE_BLOCK_BELL); + public static final CompatSoundEvent BLOCK_NOTE_BLOCK_CHIME = new CompatSoundEvent(SoundEvents.BLOCK_NOTE_BLOCK_CHIME); + public static final CompatSoundEvent BLOCK_NOTE_BLOCK_FLUTE = new CompatSoundEvent(SoundEvents.BLOCK_NOTE_BLOCK_FLUTE); + public static final CompatSoundEvent BLOCK_NOTE_BLOCK_GUITAR = new CompatSoundEvent(SoundEvents.BLOCK_NOTE_BLOCK_GUITAR); + public static final CompatSoundEvent BLOCK_NOTE_BLOCK_HARP = new CompatSoundEvent(SoundEvents.BLOCK_NOTE_BLOCK_HARP); + public static final CompatSoundEvent BLOCK_NOTE_BLOCK_HAT = new CompatSoundEvent(SoundEvents.BLOCK_NOTE_BLOCK_HAT); + public static final CompatSoundEvent BLOCK_NOTE_BLOCK_PLING = new CompatSoundEvent(SoundEvents.BLOCK_NOTE_BLOCK_PLING); + public static final CompatSoundEvent BLOCK_NOTE_BLOCK_SNARE = new CompatSoundEvent(SoundEvents.BLOCK_NOTE_BLOCK_SNARE); + public static final CompatSoundEvent BLOCK_NOTE_BLOCK_XYLOPHONE = new CompatSoundEvent(SoundEvents.BLOCK_NOTE_BLOCK_XYLOPHONE); + public static final CompatSoundEvent BLOCK_NOTE_BLOCK_IRON_XYLOPHONE = new CompatSoundEvent(SoundEvents.BLOCK_NOTE_BLOCK_IRON_XYLOPHONE); + public static final CompatSoundEvent BLOCK_NOTE_BLOCK_COW_BELL = new CompatSoundEvent(SoundEvents.BLOCK_NOTE_BLOCK_COW_BELL); + public static final CompatSoundEvent BLOCK_NOTE_BLOCK_DIDGERIDOO = new CompatSoundEvent(SoundEvents.BLOCK_NOTE_BLOCK_DIDGERIDOO); + public static final CompatSoundEvent BLOCK_NOTE_BLOCK_BIT = new CompatSoundEvent(SoundEvents.BLOCK_NOTE_BLOCK_BIT); + public static final CompatSoundEvent BLOCK_NOTE_BLOCK_BANJO = new CompatSoundEvent(SoundEvents.BLOCK_NOTE_BLOCK_BANJO); + public static final CompatSoundEvent BLOCK_NOTE_BLOCK_IMITATE_ZOMBIE = new CompatSoundEvent(SoundEvents.BLOCK_NOTE_BLOCK_IMITATE_ZOMBIE); + public static final CompatSoundEvent BLOCK_NOTE_BLOCK_IMITATE_SKELETON = new CompatSoundEvent(SoundEvents.BLOCK_NOTE_BLOCK_IMITATE_SKELETON); + public static final CompatSoundEvent BLOCK_NOTE_BLOCK_IMITATE_CREEPER = new CompatSoundEvent(SoundEvents.BLOCK_NOTE_BLOCK_IMITATE_CREEPER); + public static final CompatSoundEvent BLOCK_NOTE_BLOCK_IMITATE_ENDER_DRAGON = new CompatSoundEvent(SoundEvents.BLOCK_NOTE_BLOCK_IMITATE_ENDER_DRAGON); + public static final CompatSoundEvent BLOCK_NOTE_BLOCK_IMITATE_WITHER_SKELETON = new CompatSoundEvent(SoundEvents.BLOCK_NOTE_BLOCK_IMITATE_WITHER_SKELETON); + public static final CompatSoundEvent BLOCK_NOTE_BLOCK_IMITATE_PIGLIN = new CompatSoundEvent(SoundEvents.BLOCK_NOTE_BLOCK_IMITATE_PIGLIN); + public static final CompatSoundEvent ENTITY_OCELOT_HURT = new CompatSoundEvent(SoundEvents.ENTITY_OCELOT_HURT); + public static final CompatSoundEvent ENTITY_OCELOT_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_OCELOT_AMBIENT); + public static final CompatSoundEvent ENTITY_OCELOT_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_OCELOT_DEATH); + public static final CompatSoundEvent ITEM_OMINOUS_BOTTLE_DISPOSE = new CompatSoundEvent(SoundEvents.ITEM_OMINOUS_BOTTLE_DISPOSE); + public static final CompatSoundEvent ENTITY_PAINTING_BREAK = new CompatSoundEvent(SoundEvents.ENTITY_PAINTING_BREAK); + public static final CompatSoundEvent ENTITY_PAINTING_PLACE = new CompatSoundEvent(SoundEvents.ENTITY_PAINTING_PLACE); + public static final CompatSoundEvent ENTITY_PANDA_PRE_SNEEZE = new CompatSoundEvent(SoundEvents.ENTITY_PANDA_PRE_SNEEZE); + public static final CompatSoundEvent ENTITY_PANDA_SNEEZE = new CompatSoundEvent(SoundEvents.ENTITY_PANDA_SNEEZE); + public static final CompatSoundEvent ENTITY_PANDA_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_PANDA_AMBIENT); + public static final CompatSoundEvent ENTITY_PANDA_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_PANDA_DEATH); + public static final CompatSoundEvent ENTITY_PANDA_EAT = new CompatSoundEvent(SoundEvents.ENTITY_PANDA_EAT); + public static final CompatSoundEvent ENTITY_PANDA_STEP = new CompatSoundEvent(SoundEvents.ENTITY_PANDA_STEP); + public static final CompatSoundEvent ENTITY_PANDA_CANT_BREED = new CompatSoundEvent(SoundEvents.ENTITY_PANDA_CANT_BREED); + public static final CompatSoundEvent ENTITY_PANDA_AGGRESSIVE_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_PANDA_AGGRESSIVE_AMBIENT); + public static final CompatSoundEvent ENTITY_PANDA_WORRIED_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_PANDA_WORRIED_AMBIENT); + public static final CompatSoundEvent ENTITY_PANDA_HURT = new CompatSoundEvent(SoundEvents.ENTITY_PANDA_HURT); + public static final CompatSoundEvent ENTITY_PANDA_BITE = new CompatSoundEvent(SoundEvents.ENTITY_PANDA_BITE); + public static final CompatSoundEvent ENTITY_PARROT_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_PARROT_AMBIENT); + public static final CompatSoundEvent ENTITY_PARROT_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_PARROT_DEATH); + public static final CompatSoundEvent ENTITY_PARROT_EAT = new CompatSoundEvent(SoundEvents.ENTITY_PARROT_EAT); + public static final CompatSoundEvent ENTITY_PARROT_FLY = new CompatSoundEvent(SoundEvents.ENTITY_PARROT_FLY); + public static final CompatSoundEvent ENTITY_PARROT_HURT = new CompatSoundEvent(SoundEvents.ENTITY_PARROT_HURT); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_BLAZE = new CompatSoundEvent(SoundEvents.ENTITY_PARROT_IMITATE_BLAZE); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_BOGGED = new CompatSoundEvent(SoundEvents.ENTITY_PARROT_IMITATE_BOGGED); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_BREEZE = new CompatSoundEvent(SoundEvents.ENTITY_PARROT_IMITATE_BREEZE); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_CREEPER = new CompatSoundEvent(SoundEvents.ENTITY_PARROT_IMITATE_CREEPER); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_DROWNED = new CompatSoundEvent(SoundEvents.ENTITY_PARROT_IMITATE_DROWNED); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_ELDER_GUARDIAN = new CompatSoundEvent(SoundEvents.ENTITY_PARROT_IMITATE_ELDER_GUARDIAN); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_ENDER_DRAGON = new CompatSoundEvent(SoundEvents.ENTITY_PARROT_IMITATE_ENDER_DRAGON); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_ENDERMITE = new CompatSoundEvent(SoundEvents.ENTITY_PARROT_IMITATE_ENDERMITE); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_EVOKER = new CompatSoundEvent(SoundEvents.ENTITY_PARROT_IMITATE_EVOKER); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_GHAST = new CompatSoundEvent(SoundEvents.ENTITY_PARROT_IMITATE_GHAST); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_GUARDIAN = new CompatSoundEvent(SoundEvents.ENTITY_PARROT_IMITATE_GUARDIAN); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_HOGLIN = new CompatSoundEvent(SoundEvents.ENTITY_PARROT_IMITATE_HOGLIN); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_HUSK = new CompatSoundEvent(SoundEvents.ENTITY_PARROT_IMITATE_HUSK); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_ILLUSIONER = new CompatSoundEvent(SoundEvents.ENTITY_PARROT_IMITATE_ILLUSIONER); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_MAGMA_CUBE = new CompatSoundEvent(SoundEvents.ENTITY_PARROT_IMITATE_MAGMA_CUBE); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_PHANTOM = new CompatSoundEvent(SoundEvents.ENTITY_PARROT_IMITATE_PHANTOM); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_PIGLIN = new CompatSoundEvent(SoundEvents.ENTITY_PARROT_IMITATE_PIGLIN); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_PIGLIN_BRUTE = new CompatSoundEvent(SoundEvents.ENTITY_PARROT_IMITATE_PIGLIN_BRUTE); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_PILLAGER = new CompatSoundEvent(SoundEvents.ENTITY_PARROT_IMITATE_PILLAGER); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_RAVAGER = new CompatSoundEvent(SoundEvents.ENTITY_PARROT_IMITATE_RAVAGER); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_SHULKER = new CompatSoundEvent(SoundEvents.ENTITY_PARROT_IMITATE_SHULKER); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_SILVERFISH = new CompatSoundEvent(SoundEvents.ENTITY_PARROT_IMITATE_SILVERFISH); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_SKELETON = new CompatSoundEvent(SoundEvents.ENTITY_PARROT_IMITATE_SKELETON); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_SLIME = new CompatSoundEvent(SoundEvents.ENTITY_PARROT_IMITATE_SLIME); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_SPIDER = new CompatSoundEvent(SoundEvents.ENTITY_PARROT_IMITATE_SPIDER); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_STRAY = new CompatSoundEvent(SoundEvents.ENTITY_PARROT_IMITATE_STRAY); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_VEX = new CompatSoundEvent(SoundEvents.ENTITY_PARROT_IMITATE_VEX); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_VINDICATOR = new CompatSoundEvent(SoundEvents.ENTITY_PARROT_IMITATE_VINDICATOR); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_WARDEN = new CompatSoundEvent(SoundEvents.ENTITY_PARROT_IMITATE_WARDEN); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_WITCH = new CompatSoundEvent(SoundEvents.ENTITY_PARROT_IMITATE_WITCH); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_WITHER = new CompatSoundEvent(SoundEvents.ENTITY_PARROT_IMITATE_WITHER); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_WITHER_SKELETON = new CompatSoundEvent(SoundEvents.ENTITY_PARROT_IMITATE_WITHER_SKELETON); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_ZOGLIN = new CompatSoundEvent(SoundEvents.ENTITY_PARROT_IMITATE_ZOGLIN); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_ZOMBIE = new CompatSoundEvent(SoundEvents.ENTITY_PARROT_IMITATE_ZOMBIE); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_ZOMBIE_VILLAGER = new CompatSoundEvent(SoundEvents.ENTITY_PARROT_IMITATE_ZOMBIE_VILLAGER); + public static final CompatSoundEvent ENTITY_PARROT_STEP = new CompatSoundEvent(SoundEvents.ENTITY_PARROT_STEP); + public static final CompatSoundEvent ENTITY_PHANTOM_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_PHANTOM_AMBIENT); + public static final CompatSoundEvent ENTITY_PHANTOM_BITE = new CompatSoundEvent(SoundEvents.ENTITY_PHANTOM_BITE); + public static final CompatSoundEvent ENTITY_PHANTOM_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_PHANTOM_DEATH); + public static final CompatSoundEvent ENTITY_PHANTOM_FLAP = new CompatSoundEvent(SoundEvents.ENTITY_PHANTOM_FLAP); + public static final CompatSoundEvent ENTITY_PHANTOM_HURT = new CompatSoundEvent(SoundEvents.ENTITY_PHANTOM_HURT); + public static final CompatSoundEvent ENTITY_PHANTOM_SWOOP = new CompatSoundEvent(SoundEvents.ENTITY_PHANTOM_SWOOP); + public static final CompatSoundEvent ENTITY_PIG_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_PIG_AMBIENT); + public static final CompatSoundEvent ENTITY_PIG_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_PIG_DEATH); + public static final CompatSoundEvent ENTITY_PIG_HURT = new CompatSoundEvent(SoundEvents.ENTITY_PIG_HURT); + public static final CompatSoundEvent ENTITY_PIG_SADDLE = new CompatSoundEvent(SoundEvents.ENTITY_PIG_SADDLE); + public static final CompatSoundEvent ENTITY_PIG_STEP = new CompatSoundEvent(SoundEvents.ENTITY_PIG_STEP); + public static final CompatSoundEvent ENTITY_PIGLIN_ADMIRING_ITEM = new CompatSoundEvent(SoundEvents.ENTITY_PIGLIN_ADMIRING_ITEM); + public static final CompatSoundEvent ENTITY_PIGLIN_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_PIGLIN_AMBIENT); + public static final CompatSoundEvent ENTITY_PIGLIN_ANGRY = new CompatSoundEvent(SoundEvents.ENTITY_PIGLIN_ANGRY); + public static final CompatSoundEvent ENTITY_PIGLIN_CELEBRATE = new CompatSoundEvent(SoundEvents.ENTITY_PIGLIN_CELEBRATE); + public static final CompatSoundEvent ENTITY_PIGLIN_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_PIGLIN_DEATH); + public static final CompatSoundEvent ENTITY_PIGLIN_JEALOUS = new CompatSoundEvent(SoundEvents.ENTITY_PIGLIN_JEALOUS); + public static final CompatSoundEvent ENTITY_PIGLIN_HURT = new CompatSoundEvent(SoundEvents.ENTITY_PIGLIN_HURT); + public static final CompatSoundEvent ENTITY_PIGLIN_RETREAT = new CompatSoundEvent(SoundEvents.ENTITY_PIGLIN_RETREAT); + public static final CompatSoundEvent ENTITY_PIGLIN_STEP = new CompatSoundEvent(SoundEvents.ENTITY_PIGLIN_STEP); + public static final CompatSoundEvent ENTITY_PIGLIN_CONVERTED_TO_ZOMBIFIED = new CompatSoundEvent(SoundEvents.ENTITY_PIGLIN_CONVERTED_TO_ZOMBIFIED); + public static final CompatSoundEvent ENTITY_PIGLIN_BRUTE_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_PIGLIN_BRUTE_AMBIENT); + public static final CompatSoundEvent ENTITY_PIGLIN_BRUTE_ANGRY = new CompatSoundEvent(SoundEvents.ENTITY_PIGLIN_BRUTE_ANGRY); + public static final CompatSoundEvent ENTITY_PIGLIN_BRUTE_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_PIGLIN_BRUTE_DEATH); + public static final CompatSoundEvent ENTITY_PIGLIN_BRUTE_HURT = new CompatSoundEvent(SoundEvents.ENTITY_PIGLIN_BRUTE_HURT); + public static final CompatSoundEvent ENTITY_PIGLIN_BRUTE_STEP = new CompatSoundEvent(SoundEvents.ENTITY_PIGLIN_BRUTE_STEP); + public static final CompatSoundEvent ENTITY_PIGLIN_BRUTE_CONVERTED_TO_ZOMBIFIED = new CompatSoundEvent(SoundEvents.ENTITY_PIGLIN_BRUTE_CONVERTED_TO_ZOMBIFIED); + public static final CompatSoundEvent ENTITY_PILLAGER_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_PILLAGER_AMBIENT); + public static final CompatSoundEvent ENTITY_PILLAGER_CELEBRATE = new CompatSoundEvent(SoundEvents.ENTITY_PILLAGER_CELEBRATE); + public static final CompatSoundEvent ENTITY_PILLAGER_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_PILLAGER_DEATH); + public static final CompatSoundEvent ENTITY_PILLAGER_HURT = new CompatSoundEvent(SoundEvents.ENTITY_PILLAGER_HURT); + public static final CompatSoundEvent BLOCK_PISTON_CONTRACT = new CompatSoundEvent(SoundEvents.BLOCK_PISTON_CONTRACT); + public static final CompatSoundEvent BLOCK_PISTON_EXTEND = new CompatSoundEvent(SoundEvents.BLOCK_PISTON_EXTEND); + public static final CompatSoundEvent ENTITY_PLAYER_ATTACK_CRIT = new CompatSoundEvent(SoundEvents.ENTITY_PLAYER_ATTACK_CRIT); + public static final CompatSoundEvent ENTITY_PLAYER_ATTACK_KNOCKBACK = new CompatSoundEvent(SoundEvents.ENTITY_PLAYER_ATTACK_KNOCKBACK); + public static final CompatSoundEvent ENTITY_PLAYER_ATTACK_NODAMAGE = new CompatSoundEvent(SoundEvents.ENTITY_PLAYER_ATTACK_NODAMAGE); + public static final CompatSoundEvent ENTITY_PLAYER_ATTACK_STRONG = new CompatSoundEvent(SoundEvents.ENTITY_PLAYER_ATTACK_STRONG); + public static final CompatSoundEvent ENTITY_PLAYER_ATTACK_SWEEP = new CompatSoundEvent(SoundEvents.ENTITY_PLAYER_ATTACK_SWEEP); + public static final CompatSoundEvent ENTITY_PLAYER_ATTACK_WEAK = new CompatSoundEvent(SoundEvents.ENTITY_PLAYER_ATTACK_WEAK); + public static final CompatSoundEvent ENTITY_PLAYER_BIG_FALL = new CompatSoundEvent(SoundEvents.ENTITY_PLAYER_BIG_FALL); + public static final CompatSoundEvent ENTITY_PLAYER_BREATH = new CompatSoundEvent(SoundEvents.ENTITY_PLAYER_BREATH); + public static final CompatSoundEvent ENTITY_PLAYER_BURP = new CompatSoundEvent(SoundEvents.ENTITY_PLAYER_BURP); + public static final CompatSoundEvent ENTITY_PLAYER_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_PLAYER_DEATH); + public static final CompatSoundEvent ENTITY_PLAYER_HURT = new CompatSoundEvent(SoundEvents.ENTITY_PLAYER_HURT); + public static final CompatSoundEvent ENTITY_PLAYER_HURT_DROWN = new CompatSoundEvent(SoundEvents.ENTITY_PLAYER_HURT_DROWN); + public static final CompatSoundEvent ENTITY_PLAYER_HURT_FREEZE = new CompatSoundEvent(SoundEvents.ENTITY_PLAYER_HURT_FREEZE); + public static final CompatSoundEvent ENTITY_PLAYER_HURT_ON_FIRE = new CompatSoundEvent(SoundEvents.ENTITY_PLAYER_HURT_ON_FIRE); + public static final CompatSoundEvent ENTITY_PLAYER_HURT_SWEET_BERRY_BUSH = new CompatSoundEvent(SoundEvents.ENTITY_PLAYER_HURT_SWEET_BERRY_BUSH); + public static final CompatSoundEvent ENTITY_PLAYER_LEVELUP = new CompatSoundEvent(SoundEvents.ENTITY_PLAYER_LEVELUP); + public static final CompatSoundEvent ENTITY_PLAYER_SMALL_FALL = new CompatSoundEvent(SoundEvents.ENTITY_PLAYER_SMALL_FALL); + public static final CompatSoundEvent ENTITY_PLAYER_SPLASH = new CompatSoundEvent(SoundEvents.ENTITY_PLAYER_SPLASH); + public static final CompatSoundEvent ENTITY_PLAYER_SPLASH_HIGH_SPEED = new CompatSoundEvent(SoundEvents.ENTITY_PLAYER_SPLASH_HIGH_SPEED); + public static final CompatSoundEvent ENTITY_PLAYER_SWIM = new CompatSoundEvent(SoundEvents.ENTITY_PLAYER_SWIM); + public static final CompatSoundEvent ENTITY_PLAYER_TELEPORT = new CompatSoundEvent(SoundEvents.ENTITY_PLAYER_TELEPORT); + public static final CompatSoundEvent ENTITY_POLAR_BEAR_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_POLAR_BEAR_AMBIENT); + public static final CompatSoundEvent ENTITY_POLAR_BEAR_AMBIENT_BABY = new CompatSoundEvent(SoundEvents.ENTITY_POLAR_BEAR_AMBIENT_BABY); + public static final CompatSoundEvent ENTITY_POLAR_BEAR_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_POLAR_BEAR_DEATH); + public static final CompatSoundEvent ENTITY_POLAR_BEAR_HURT = new CompatSoundEvent(SoundEvents.ENTITY_POLAR_BEAR_HURT); + public static final CompatSoundEvent ENTITY_POLAR_BEAR_STEP = new CompatSoundEvent(SoundEvents.ENTITY_POLAR_BEAR_STEP); + public static final CompatSoundEvent ENTITY_POLAR_BEAR_WARNING = new CompatSoundEvent(SoundEvents.ENTITY_POLAR_BEAR_WARNING); + public static final CompatSoundEvent BLOCK_POLISHED_DEEPSLATE_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_POLISHED_DEEPSLATE_BREAK); + public static final CompatSoundEvent BLOCK_POLISHED_DEEPSLATE_FALL = new CompatSoundEvent(SoundEvents.BLOCK_POLISHED_DEEPSLATE_FALL); + public static final CompatSoundEvent BLOCK_POLISHED_DEEPSLATE_HIT = new CompatSoundEvent(SoundEvents.BLOCK_POLISHED_DEEPSLATE_HIT); + public static final CompatSoundEvent BLOCK_POLISHED_DEEPSLATE_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_POLISHED_DEEPSLATE_PLACE); + public static final CompatSoundEvent BLOCK_POLISHED_DEEPSLATE_STEP = new CompatSoundEvent(SoundEvents.BLOCK_POLISHED_DEEPSLATE_STEP); + public static final CompatSoundEvent BLOCK_PORTAL_AMBIENT = new CompatSoundEvent(SoundEvents.BLOCK_PORTAL_AMBIENT); + public static final CompatSoundEvent BLOCK_PORTAL_TRAVEL = new CompatSoundEvent(SoundEvents.BLOCK_PORTAL_TRAVEL); + public static final CompatSoundEvent BLOCK_PORTAL_TRIGGER = new CompatSoundEvent(SoundEvents.BLOCK_PORTAL_TRIGGER); + public static final CompatSoundEvent BLOCK_POWDER_SNOW_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_POWDER_SNOW_BREAK); + public static final CompatSoundEvent BLOCK_POWDER_SNOW_FALL = new CompatSoundEvent(SoundEvents.BLOCK_POWDER_SNOW_FALL); + public static final CompatSoundEvent BLOCK_POWDER_SNOW_HIT = new CompatSoundEvent(SoundEvents.BLOCK_POWDER_SNOW_HIT); + public static final CompatSoundEvent BLOCK_POWDER_SNOW_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_POWDER_SNOW_PLACE); + public static final CompatSoundEvent BLOCK_POWDER_SNOW_STEP = new CompatSoundEvent(SoundEvents.BLOCK_POWDER_SNOW_STEP); + public static final CompatSoundEvent ENTITY_PUFFER_FISH_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_PUFFER_FISH_AMBIENT); + public static final CompatSoundEvent ENTITY_PUFFER_FISH_BLOW_OUT = new CompatSoundEvent(SoundEvents.ENTITY_PUFFER_FISH_BLOW_OUT); + public static final CompatSoundEvent ENTITY_PUFFER_FISH_BLOW_UP = new CompatSoundEvent(SoundEvents.ENTITY_PUFFER_FISH_BLOW_UP); + public static final CompatSoundEvent ENTITY_PUFFER_FISH_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_PUFFER_FISH_DEATH); + public static final CompatSoundEvent ENTITY_PUFFER_FISH_FLOP = new CompatSoundEvent(SoundEvents.ENTITY_PUFFER_FISH_FLOP); + public static final CompatSoundEvent ENTITY_PUFFER_FISH_HURT = new CompatSoundEvent(SoundEvents.ENTITY_PUFFER_FISH_HURT); + public static final CompatSoundEvent ENTITY_PUFFER_FISH_STING = new CompatSoundEvent(SoundEvents.ENTITY_PUFFER_FISH_STING); + public static final CompatSoundEvent BLOCK_PUMPKIN_CARVE = new CompatSoundEvent(SoundEvents.BLOCK_PUMPKIN_CARVE); + public static final CompatSoundEvent ENTITY_RABBIT_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_RABBIT_AMBIENT); + public static final CompatSoundEvent ENTITY_RABBIT_ATTACK = new CompatSoundEvent(SoundEvents.ENTITY_RABBIT_ATTACK); + public static final CompatSoundEvent ENTITY_RABBIT_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_RABBIT_DEATH); + public static final CompatSoundEvent ENTITY_RABBIT_HURT = new CompatSoundEvent(SoundEvents.ENTITY_RABBIT_HURT); + public static final CompatSoundEvent ENTITY_RABBIT_JUMP = new CompatSoundEvent(SoundEvents.ENTITY_RABBIT_JUMP); + public static final CompatSoundEvent EVENT_RAID_HORN = new CompatSoundEvent(SoundEvents.EVENT_RAID_HORN); + public static final CompatSoundEvent ENTITY_RAVAGER_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_RAVAGER_AMBIENT); + public static final CompatSoundEvent ENTITY_RAVAGER_ATTACK = new CompatSoundEvent(SoundEvents.ENTITY_RAVAGER_ATTACK); + public static final CompatSoundEvent ENTITY_RAVAGER_CELEBRATE = new CompatSoundEvent(SoundEvents.ENTITY_RAVAGER_CELEBRATE); + public static final CompatSoundEvent ENTITY_RAVAGER_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_RAVAGER_DEATH); + public static final CompatSoundEvent ENTITY_RAVAGER_HURT = new CompatSoundEvent(SoundEvents.ENTITY_RAVAGER_HURT); + public static final CompatSoundEvent ENTITY_RAVAGER_STEP = new CompatSoundEvent(SoundEvents.ENTITY_RAVAGER_STEP); + public static final CompatSoundEvent ENTITY_RAVAGER_STUNNED = new CompatSoundEvent(SoundEvents.ENTITY_RAVAGER_STUNNED); + public static final CompatSoundEvent ENTITY_RAVAGER_ROAR = new CompatSoundEvent(SoundEvents.ENTITY_RAVAGER_ROAR); + public static final CompatSoundEvent BLOCK_NETHER_GOLD_ORE_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_NETHER_GOLD_ORE_BREAK); + public static final CompatSoundEvent BLOCK_NETHER_GOLD_ORE_FALL = new CompatSoundEvent(SoundEvents.BLOCK_NETHER_GOLD_ORE_FALL); + public static final CompatSoundEvent BLOCK_NETHER_GOLD_ORE_HIT = new CompatSoundEvent(SoundEvents.BLOCK_NETHER_GOLD_ORE_HIT); + public static final CompatSoundEvent BLOCK_NETHER_GOLD_ORE_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_NETHER_GOLD_ORE_PLACE); + public static final CompatSoundEvent BLOCK_NETHER_GOLD_ORE_STEP = new CompatSoundEvent(SoundEvents.BLOCK_NETHER_GOLD_ORE_STEP); + public static final CompatSoundEvent BLOCK_NETHER_ORE_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_NETHER_ORE_BREAK); + public static final CompatSoundEvent BLOCK_NETHER_ORE_FALL = new CompatSoundEvent(SoundEvents.BLOCK_NETHER_ORE_FALL); + public static final CompatSoundEvent BLOCK_NETHER_ORE_HIT = new CompatSoundEvent(SoundEvents.BLOCK_NETHER_ORE_HIT); + public static final CompatSoundEvent BLOCK_NETHER_ORE_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_NETHER_ORE_PLACE); + public static final CompatSoundEvent BLOCK_NETHER_ORE_STEP = new CompatSoundEvent(SoundEvents.BLOCK_NETHER_ORE_STEP); + public static final CompatSoundEvent BLOCK_REDSTONE_TORCH_BURNOUT = new CompatSoundEvent(SoundEvents.BLOCK_REDSTONE_TORCH_BURNOUT); + public static final CompatSoundEvent BLOCK_RESPAWN_ANCHOR_AMBIENT = new CompatSoundEvent(SoundEvents.BLOCK_RESPAWN_ANCHOR_AMBIENT); + public static final CompatSoundEvent BLOCK_RESPAWN_ANCHOR_CHARGE = new CompatSoundEvent(SoundEvents.BLOCK_RESPAWN_ANCHOR_CHARGE); + public static final CompatSoundEvent BLOCK_RESPAWN_ANCHOR_DEPLETE = new CompatSoundEvent(SoundEvents.BLOCK_RESPAWN_ANCHOR_DEPLETE); + public static final CompatSoundEvent BLOCK_RESPAWN_ANCHOR_SET_SPAWN = new CompatSoundEvent(SoundEvents.BLOCK_RESPAWN_ANCHOR_SET_SPAWN); + public static final CompatSoundEvent BLOCK_ROOTED_DIRT_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_ROOTED_DIRT_BREAK); + public static final CompatSoundEvent BLOCK_ROOTED_DIRT_FALL = new CompatSoundEvent(SoundEvents.BLOCK_ROOTED_DIRT_FALL); + public static final CompatSoundEvent BLOCK_ROOTED_DIRT_HIT = new CompatSoundEvent(SoundEvents.BLOCK_ROOTED_DIRT_HIT); + public static final CompatSoundEvent BLOCK_ROOTED_DIRT_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_ROOTED_DIRT_PLACE); + public static final CompatSoundEvent BLOCK_ROOTED_DIRT_STEP = new CompatSoundEvent(SoundEvents.BLOCK_ROOTED_DIRT_STEP); + public static final CompatSoundEvent ENTITY_SALMON_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_SALMON_AMBIENT); + public static final CompatSoundEvent ENTITY_SALMON_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_SALMON_DEATH); + public static final CompatSoundEvent ENTITY_SALMON_FLOP = new CompatSoundEvent(SoundEvents.ENTITY_SALMON_FLOP); + public static final CompatSoundEvent ENTITY_SALMON_HURT = new CompatSoundEvent(SoundEvents.ENTITY_SALMON_HURT); + public static final CompatSoundEvent BLOCK_SAND_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_SAND_BREAK); + public static final CompatSoundEvent BLOCK_SAND_FALL = new CompatSoundEvent(SoundEvents.BLOCK_SAND_FALL); + public static final CompatSoundEvent BLOCK_SAND_HIT = new CompatSoundEvent(SoundEvents.BLOCK_SAND_HIT); + public static final CompatSoundEvent BLOCK_SAND_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_SAND_PLACE); + public static final CompatSoundEvent BLOCK_SAND_STEP = new CompatSoundEvent(SoundEvents.BLOCK_SAND_STEP); + public static final CompatSoundEvent BLOCK_SCAFFOLDING_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_SCAFFOLDING_BREAK); + public static final CompatSoundEvent BLOCK_SCAFFOLDING_FALL = new CompatSoundEvent(SoundEvents.BLOCK_SCAFFOLDING_FALL); + public static final CompatSoundEvent BLOCK_SCAFFOLDING_HIT = new CompatSoundEvent(SoundEvents.BLOCK_SCAFFOLDING_HIT); + public static final CompatSoundEvent BLOCK_SCAFFOLDING_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_SCAFFOLDING_PLACE); + public static final CompatSoundEvent BLOCK_SCAFFOLDING_STEP = new CompatSoundEvent(SoundEvents.BLOCK_SCAFFOLDING_STEP); + public static final CompatSoundEvent BLOCK_SCULK_SPREAD = new CompatSoundEvent(SoundEvents.BLOCK_SCULK_SPREAD); + public static final CompatSoundEvent BLOCK_SCULK_CHARGE = new CompatSoundEvent(SoundEvents.BLOCK_SCULK_CHARGE); + public static final CompatSoundEvent BLOCK_SCULK_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_SCULK_BREAK); + public static final CompatSoundEvent BLOCK_SCULK_FALL = new CompatSoundEvent(SoundEvents.BLOCK_SCULK_FALL); + public static final CompatSoundEvent BLOCK_SCULK_HIT = new CompatSoundEvent(SoundEvents.BLOCK_SCULK_HIT); + public static final CompatSoundEvent BLOCK_SCULK_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_SCULK_PLACE); + public static final CompatSoundEvent BLOCK_SCULK_STEP = new CompatSoundEvent(SoundEvents.BLOCK_SCULK_STEP); + public static final CompatSoundEvent BLOCK_SCULK_CATALYST_BLOOM = new CompatSoundEvent(SoundEvents.BLOCK_SCULK_CATALYST_BLOOM); + public static final CompatSoundEvent BLOCK_SCULK_CATALYST_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_SCULK_CATALYST_BREAK); + public static final CompatSoundEvent BLOCK_SCULK_CATALYST_FALL = new CompatSoundEvent(SoundEvents.BLOCK_SCULK_CATALYST_FALL); + public static final CompatSoundEvent BLOCK_SCULK_CATALYST_HIT = new CompatSoundEvent(SoundEvents.BLOCK_SCULK_CATALYST_HIT); + public static final CompatSoundEvent BLOCK_SCULK_CATALYST_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_SCULK_CATALYST_PLACE); + public static final CompatSoundEvent BLOCK_SCULK_CATALYST_STEP = new CompatSoundEvent(SoundEvents.BLOCK_SCULK_CATALYST_STEP); + public static final CompatSoundEvent BLOCK_SCULK_SENSOR_CLICKING = new CompatSoundEvent(SoundEvents.BLOCK_SCULK_SENSOR_CLICKING); + public static final CompatSoundEvent BLOCK_SCULK_SENSOR_CLICKING_STOP = new CompatSoundEvent(SoundEvents.BLOCK_SCULK_SENSOR_CLICKING_STOP); + public static final CompatSoundEvent BLOCK_SCULK_SENSOR_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_SCULK_SENSOR_BREAK); + public static final CompatSoundEvent BLOCK_SCULK_SENSOR_FALL = new CompatSoundEvent(SoundEvents.BLOCK_SCULK_SENSOR_FALL); + public static final CompatSoundEvent BLOCK_SCULK_SENSOR_HIT = new CompatSoundEvent(SoundEvents.BLOCK_SCULK_SENSOR_HIT); + public static final CompatSoundEvent BLOCK_SCULK_SENSOR_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_SCULK_SENSOR_PLACE); + public static final CompatSoundEvent BLOCK_SCULK_SENSOR_STEP = new CompatSoundEvent(SoundEvents.BLOCK_SCULK_SENSOR_STEP); + public static final CompatSoundEvent BLOCK_SCULK_SHRIEKER_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_SCULK_SHRIEKER_BREAK); + public static final CompatSoundEvent BLOCK_SCULK_SHRIEKER_FALL = new CompatSoundEvent(SoundEvents.BLOCK_SCULK_SHRIEKER_FALL); + public static final CompatSoundEvent BLOCK_SCULK_SHRIEKER_HIT = new CompatSoundEvent(SoundEvents.BLOCK_SCULK_SHRIEKER_HIT); + public static final CompatSoundEvent BLOCK_SCULK_SHRIEKER_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_SCULK_SHRIEKER_PLACE); + public static final CompatSoundEvent BLOCK_SCULK_SHRIEKER_SHRIEK = new CompatSoundEvent(SoundEvents.BLOCK_SCULK_SHRIEKER_SHRIEK); + public static final CompatSoundEvent BLOCK_SCULK_SHRIEKER_STEP = new CompatSoundEvent(SoundEvents.BLOCK_SCULK_SHRIEKER_STEP); + public static final CompatSoundEvent BLOCK_SCULK_VEIN_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_SCULK_VEIN_BREAK); + public static final CompatSoundEvent BLOCK_SCULK_VEIN_FALL = new CompatSoundEvent(SoundEvents.BLOCK_SCULK_VEIN_FALL); + public static final CompatSoundEvent BLOCK_SCULK_VEIN_HIT = new CompatSoundEvent(SoundEvents.BLOCK_SCULK_VEIN_HIT); + public static final CompatSoundEvent BLOCK_SCULK_VEIN_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_SCULK_VEIN_PLACE); + public static final CompatSoundEvent BLOCK_SCULK_VEIN_STEP = new CompatSoundEvent(SoundEvents.BLOCK_SCULK_VEIN_STEP); + public static final CompatSoundEvent ENTITY_SHEEP_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_SHEEP_AMBIENT); + public static final CompatSoundEvent ENTITY_SHEEP_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_SHEEP_DEATH); + public static final CompatSoundEvent ENTITY_SHEEP_HURT = new CompatSoundEvent(SoundEvents.ENTITY_SHEEP_HURT); + public static final CompatSoundEvent ENTITY_SHEEP_SHEAR = new CompatSoundEvent(SoundEvents.ENTITY_SHEEP_SHEAR); + public static final CompatSoundEvent ENTITY_SHEEP_STEP = new CompatSoundEvent(SoundEvents.ENTITY_SHEEP_STEP); + public static final CompatSoundEvent ITEM_SHIELD_BLOCK = new CompatSoundEvent(SoundEvents.ITEM_SHIELD_BLOCK); + public static final CompatSoundEvent ITEM_SHIELD_BREAK = new CompatSoundEvent(SoundEvents.ITEM_SHIELD_BREAK); + public static final CompatSoundEvent BLOCK_SHROOMLIGHT_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_SHROOMLIGHT_BREAK); + public static final CompatSoundEvent BLOCK_SHROOMLIGHT_STEP = new CompatSoundEvent(SoundEvents.BLOCK_SHROOMLIGHT_STEP); + public static final CompatSoundEvent BLOCK_SHROOMLIGHT_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_SHROOMLIGHT_PLACE); + public static final CompatSoundEvent BLOCK_SHROOMLIGHT_HIT = new CompatSoundEvent(SoundEvents.BLOCK_SHROOMLIGHT_HIT); + public static final CompatSoundEvent BLOCK_SHROOMLIGHT_FALL = new CompatSoundEvent(SoundEvents.BLOCK_SHROOMLIGHT_FALL); + public static final CompatSoundEvent ITEM_SHOVEL_FLATTEN = new CompatSoundEvent(SoundEvents.ITEM_SHOVEL_FLATTEN); + public static final CompatSoundEvent ENTITY_SHULKER_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_SHULKER_AMBIENT); + public static final CompatSoundEvent BLOCK_SHULKER_BOX_CLOSE = new CompatSoundEvent(SoundEvents.BLOCK_SHULKER_BOX_CLOSE); + public static final CompatSoundEvent BLOCK_SHULKER_BOX_OPEN = new CompatSoundEvent(SoundEvents.BLOCK_SHULKER_BOX_OPEN); + public static final CompatSoundEvent ENTITY_SHULKER_BULLET_HIT = new CompatSoundEvent(SoundEvents.ENTITY_SHULKER_BULLET_HIT); + public static final CompatSoundEvent ENTITY_SHULKER_BULLET_HURT = new CompatSoundEvent(SoundEvents.ENTITY_SHULKER_BULLET_HURT); + public static final CompatSoundEvent ENTITY_SHULKER_CLOSE = new CompatSoundEvent(SoundEvents.ENTITY_SHULKER_CLOSE); + public static final CompatSoundEvent ENTITY_SHULKER_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_SHULKER_DEATH); + public static final CompatSoundEvent ENTITY_SHULKER_HURT = new CompatSoundEvent(SoundEvents.ENTITY_SHULKER_HURT); + public static final CompatSoundEvent ENTITY_SHULKER_HURT_CLOSED = new CompatSoundEvent(SoundEvents.ENTITY_SHULKER_HURT_CLOSED); + public static final CompatSoundEvent ENTITY_SHULKER_OPEN = new CompatSoundEvent(SoundEvents.ENTITY_SHULKER_OPEN); + public static final CompatSoundEvent ENTITY_SHULKER_SHOOT = new CompatSoundEvent(SoundEvents.ENTITY_SHULKER_SHOOT); + public static final CompatSoundEvent ENTITY_SHULKER_TELEPORT = new CompatSoundEvent(SoundEvents.ENTITY_SHULKER_TELEPORT); + public static final CompatSoundEvent ENTITY_SILVERFISH_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_SILVERFISH_AMBIENT); + public static final CompatSoundEvent ENTITY_SILVERFISH_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_SILVERFISH_DEATH); + public static final CompatSoundEvent ENTITY_SILVERFISH_HURT = new CompatSoundEvent(SoundEvents.ENTITY_SILVERFISH_HURT); + public static final CompatSoundEvent ENTITY_SILVERFISH_STEP = new CompatSoundEvent(SoundEvents.ENTITY_SILVERFISH_STEP); + public static final CompatSoundEvent ENTITY_SKELETON_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_SKELETON_AMBIENT); + public static final CompatSoundEvent ENTITY_SKELETON_CONVERTED_TO_STRAY = new CompatSoundEvent(SoundEvents.ENTITY_SKELETON_CONVERTED_TO_STRAY); + public static final CompatSoundEvent ENTITY_SKELETON_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_SKELETON_DEATH); + public static final CompatSoundEvent ENTITY_SKELETON_HORSE_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_SKELETON_HORSE_AMBIENT); + public static final CompatSoundEvent ENTITY_SKELETON_HORSE_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_SKELETON_HORSE_DEATH); + public static final CompatSoundEvent ENTITY_SKELETON_HORSE_HURT = new CompatSoundEvent(SoundEvents.ENTITY_SKELETON_HORSE_HURT); + public static final CompatSoundEvent ENTITY_SKELETON_HORSE_SWIM = new CompatSoundEvent(SoundEvents.ENTITY_SKELETON_HORSE_SWIM); + public static final CompatSoundEvent ENTITY_SKELETON_HORSE_AMBIENT_WATER = new CompatSoundEvent(SoundEvents.ENTITY_SKELETON_HORSE_AMBIENT_WATER); + public static final CompatSoundEvent ENTITY_SKELETON_HORSE_GALLOP_WATER = new CompatSoundEvent(SoundEvents.ENTITY_SKELETON_HORSE_GALLOP_WATER); + public static final CompatSoundEvent ENTITY_SKELETON_HORSE_JUMP_WATER = new CompatSoundEvent(SoundEvents.ENTITY_SKELETON_HORSE_JUMP_WATER); + public static final CompatSoundEvent ENTITY_SKELETON_HORSE_STEP_WATER = new CompatSoundEvent(SoundEvents.ENTITY_SKELETON_HORSE_STEP_WATER); + public static final CompatSoundEvent ENTITY_SKELETON_HURT = new CompatSoundEvent(SoundEvents.ENTITY_SKELETON_HURT); + public static final CompatSoundEvent ENTITY_SKELETON_SHOOT = new CompatSoundEvent(SoundEvents.ENTITY_SKELETON_SHOOT); + public static final CompatSoundEvent ENTITY_SKELETON_STEP = new CompatSoundEvent(SoundEvents.ENTITY_SKELETON_STEP); + public static final CompatSoundEvent ENTITY_SLIME_ATTACK = new CompatSoundEvent(SoundEvents.ENTITY_SLIME_ATTACK); + public static final CompatSoundEvent ENTITY_SLIME_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_SLIME_DEATH); + public static final CompatSoundEvent ENTITY_SLIME_HURT = new CompatSoundEvent(SoundEvents.ENTITY_SLIME_HURT); + public static final CompatSoundEvent ENTITY_SLIME_JUMP = new CompatSoundEvent(SoundEvents.ENTITY_SLIME_JUMP); + public static final CompatSoundEvent ENTITY_SLIME_SQUISH = new CompatSoundEvent(SoundEvents.ENTITY_SLIME_SQUISH); + public static final CompatSoundEvent BLOCK_SLIME_BLOCK_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_SLIME_BLOCK_BREAK); + public static final CompatSoundEvent BLOCK_SLIME_BLOCK_FALL = new CompatSoundEvent(SoundEvents.BLOCK_SLIME_BLOCK_FALL); + public static final CompatSoundEvent BLOCK_SLIME_BLOCK_HIT = new CompatSoundEvent(SoundEvents.BLOCK_SLIME_BLOCK_HIT); + public static final CompatSoundEvent BLOCK_SLIME_BLOCK_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_SLIME_BLOCK_PLACE); + public static final CompatSoundEvent BLOCK_SLIME_BLOCK_STEP = new CompatSoundEvent(SoundEvents.BLOCK_SLIME_BLOCK_STEP); + public static final CompatSoundEvent BLOCK_SMALL_AMETHYST_BUD_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_SMALL_AMETHYST_BUD_BREAK); + public static final CompatSoundEvent BLOCK_SMALL_AMETHYST_BUD_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_SMALL_AMETHYST_BUD_PLACE); + public static final CompatSoundEvent BLOCK_SMALL_DRIPLEAF_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_SMALL_DRIPLEAF_BREAK); + public static final CompatSoundEvent BLOCK_SMALL_DRIPLEAF_FALL = new CompatSoundEvent(SoundEvents.BLOCK_SMALL_DRIPLEAF_FALL); + public static final CompatSoundEvent BLOCK_SMALL_DRIPLEAF_HIT = new CompatSoundEvent(SoundEvents.BLOCK_SMALL_DRIPLEAF_HIT); + public static final CompatSoundEvent BLOCK_SMALL_DRIPLEAF_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_SMALL_DRIPLEAF_PLACE); + public static final CompatSoundEvent BLOCK_SMALL_DRIPLEAF_STEP = new CompatSoundEvent(SoundEvents.BLOCK_SMALL_DRIPLEAF_STEP); + public static final CompatSoundEvent BLOCK_SOUL_SAND_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_SOUL_SAND_BREAK); + public static final CompatSoundEvent BLOCK_SOUL_SAND_STEP = new CompatSoundEvent(SoundEvents.BLOCK_SOUL_SAND_STEP); + public static final CompatSoundEvent BLOCK_SOUL_SAND_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_SOUL_SAND_PLACE); + public static final CompatSoundEvent BLOCK_SOUL_SAND_HIT = new CompatSoundEvent(SoundEvents.BLOCK_SOUL_SAND_HIT); + public static final CompatSoundEvent BLOCK_SOUL_SAND_FALL = new CompatSoundEvent(SoundEvents.BLOCK_SOUL_SAND_FALL); + public static final CompatSoundEvent BLOCK_SOUL_SOIL_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_SOUL_SOIL_BREAK); + public static final CompatSoundEvent BLOCK_SOUL_SOIL_STEP = new CompatSoundEvent(SoundEvents.BLOCK_SOUL_SOIL_STEP); + public static final CompatSoundEvent BLOCK_SOUL_SOIL_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_SOUL_SOIL_PLACE); + public static final CompatSoundEvent BLOCK_SOUL_SOIL_HIT = new CompatSoundEvent(SoundEvents.BLOCK_SOUL_SOIL_HIT); + public static final CompatSoundEvent BLOCK_SOUL_SOIL_FALL = new CompatSoundEvent(SoundEvents.BLOCK_SOUL_SOIL_FALL); + public static final CompatSoundEvent PARTICLE_SOUL_ESCAPE = new CompatSoundEvent(SoundEvents.PARTICLE_SOUL_ESCAPE); + public static final CompatSoundEvent BLOCK_SPORE_BLOSSOM_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_SPORE_BLOSSOM_BREAK); + public static final CompatSoundEvent BLOCK_SPORE_BLOSSOM_FALL = new CompatSoundEvent(SoundEvents.BLOCK_SPORE_BLOSSOM_FALL); + public static final CompatSoundEvent BLOCK_SPORE_BLOSSOM_HIT = new CompatSoundEvent(SoundEvents.BLOCK_SPORE_BLOSSOM_HIT); + public static final CompatSoundEvent BLOCK_SPORE_BLOSSOM_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_SPORE_BLOSSOM_PLACE); + public static final CompatSoundEvent BLOCK_SPORE_BLOSSOM_STEP = new CompatSoundEvent(SoundEvents.BLOCK_SPORE_BLOSSOM_STEP); + public static final CompatSoundEvent ENTITY_STRIDER_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_STRIDER_AMBIENT); + public static final CompatSoundEvent ENTITY_STRIDER_HAPPY = new CompatSoundEvent(SoundEvents.ENTITY_STRIDER_HAPPY); + public static final CompatSoundEvent ENTITY_STRIDER_RETREAT = new CompatSoundEvent(SoundEvents.ENTITY_STRIDER_RETREAT); + public static final CompatSoundEvent ENTITY_STRIDER_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_STRIDER_DEATH); + public static final CompatSoundEvent ENTITY_STRIDER_HURT = new CompatSoundEvent(SoundEvents.ENTITY_STRIDER_HURT); + public static final CompatSoundEvent ENTITY_STRIDER_STEP = new CompatSoundEvent(SoundEvents.ENTITY_STRIDER_STEP); + public static final CompatSoundEvent ENTITY_STRIDER_STEP_LAVA = new CompatSoundEvent(SoundEvents.ENTITY_STRIDER_STEP_LAVA); + public static final CompatSoundEvent ENTITY_STRIDER_EAT = new CompatSoundEvent(SoundEvents.ENTITY_STRIDER_EAT); + public static final CompatSoundEvent ENTITY_STRIDER_SADDLE = new CompatSoundEvent(SoundEvents.ENTITY_STRIDER_SADDLE); + public static final CompatSoundEvent ENTITY_SLIME_DEATH_SMALL = new CompatSoundEvent(SoundEvents.ENTITY_SLIME_DEATH_SMALL); + public static final CompatSoundEvent ENTITY_SLIME_HURT_SMALL = new CompatSoundEvent(SoundEvents.ENTITY_SLIME_HURT_SMALL); + public static final CompatSoundEvent ENTITY_SLIME_JUMP_SMALL = new CompatSoundEvent(SoundEvents.ENTITY_SLIME_JUMP_SMALL); + public static final CompatSoundEvent ENTITY_SLIME_SQUISH_SMALL = new CompatSoundEvent(SoundEvents.ENTITY_SLIME_SQUISH_SMALL); + public static final CompatSoundEvent BLOCK_SMITHING_TABLE_USE = new CompatSoundEvent(SoundEvents.BLOCK_SMITHING_TABLE_USE); + public static final CompatSoundEvent BLOCK_SMOKER_SMOKE = new CompatSoundEvent(SoundEvents.BLOCK_SMOKER_SMOKE); + public static final CompatSoundEvent ENTITY_SNIFFER_STEP = new CompatSoundEvent(SoundEvents.ENTITY_SNIFFER_STEP); + public static final CompatSoundEvent ENTITY_SNIFFER_EAT = new CompatSoundEvent(SoundEvents.ENTITY_SNIFFER_EAT); + public static final CompatSoundEvent ENTITY_SNIFFER_IDLE = new CompatSoundEvent(SoundEvents.ENTITY_SNIFFER_IDLE); + public static final CompatSoundEvent ENTITY_SNIFFER_HURT = new CompatSoundEvent(SoundEvents.ENTITY_SNIFFER_HURT); + public static final CompatSoundEvent ENTITY_SNIFFER_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_SNIFFER_DEATH); + public static final CompatSoundEvent ENTITY_SNIFFER_DROP_SEED = new CompatSoundEvent(SoundEvents.ENTITY_SNIFFER_DROP_SEED); + public static final CompatSoundEvent ENTITY_SNIFFER_SCENTING = new CompatSoundEvent(SoundEvents.ENTITY_SNIFFER_SCENTING); + public static final CompatSoundEvent ENTITY_SNIFFER_SNIFFING = new CompatSoundEvent(SoundEvents.ENTITY_SNIFFER_SNIFFING); + public static final CompatSoundEvent ENTITY_SNIFFER_SEARCHING = new CompatSoundEvent(SoundEvents.ENTITY_SNIFFER_SEARCHING); + public static final CompatSoundEvent ENTITY_SNIFFER_DIGGING = new CompatSoundEvent(SoundEvents.ENTITY_SNIFFER_DIGGING); + public static final CompatSoundEvent ENTITY_SNIFFER_DIGGING_STOP = new CompatSoundEvent(SoundEvents.ENTITY_SNIFFER_DIGGING_STOP); + public static final CompatSoundEvent ENTITY_SNIFFER_HAPPY = new CompatSoundEvent(SoundEvents.ENTITY_SNIFFER_HAPPY); + public static final CompatSoundEvent BLOCK_SNIFFER_EGG_PLOP = new CompatSoundEvent(SoundEvents.BLOCK_SNIFFER_EGG_PLOP); + public static final CompatSoundEvent BLOCK_SNIFFER_EGG_CRACK = new CompatSoundEvent(SoundEvents.BLOCK_SNIFFER_EGG_CRACK); + public static final CompatSoundEvent BLOCK_SNIFFER_EGG_HATCH = new CompatSoundEvent(SoundEvents.BLOCK_SNIFFER_EGG_HATCH); + public static final CompatSoundEvent ENTITY_SNOWBALL_THROW = new CompatSoundEvent(SoundEvents.ENTITY_SNOWBALL_THROW); + public static final CompatSoundEvent BLOCK_SNOW_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_SNOW_BREAK); + public static final CompatSoundEvent BLOCK_SNOW_FALL = new CompatSoundEvent(SoundEvents.BLOCK_SNOW_FALL); + public static final CompatSoundEvent ENTITY_SNOW_GOLEM_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_SNOW_GOLEM_AMBIENT); + public static final CompatSoundEvent ENTITY_SNOW_GOLEM_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_SNOW_GOLEM_DEATH); + public static final CompatSoundEvent ENTITY_SNOW_GOLEM_HURT = new CompatSoundEvent(SoundEvents.ENTITY_SNOW_GOLEM_HURT); + public static final CompatSoundEvent ENTITY_SNOW_GOLEM_SHOOT = new CompatSoundEvent(SoundEvents.ENTITY_SNOW_GOLEM_SHOOT); + public static final CompatSoundEvent ENTITY_SNOW_GOLEM_SHEAR = new CompatSoundEvent(SoundEvents.ENTITY_SNOW_GOLEM_SHEAR); + public static final CompatSoundEvent BLOCK_SNOW_HIT = new CompatSoundEvent(SoundEvents.BLOCK_SNOW_HIT); + public static final CompatSoundEvent BLOCK_SNOW_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_SNOW_PLACE); + public static final CompatSoundEvent BLOCK_SNOW_STEP = new CompatSoundEvent(SoundEvents.BLOCK_SNOW_STEP); + public static final CompatSoundEvent ENTITY_SPIDER_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_SPIDER_AMBIENT); + public static final CompatSoundEvent ENTITY_SPIDER_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_SPIDER_DEATH); + public static final CompatSoundEvent ENTITY_SPIDER_HURT = new CompatSoundEvent(SoundEvents.ENTITY_SPIDER_HURT); + public static final CompatSoundEvent ENTITY_SPIDER_STEP = new CompatSoundEvent(SoundEvents.ENTITY_SPIDER_STEP); + public static final CompatSoundEvent ENTITY_SPLASH_POTION_BREAK = new CompatSoundEvent(SoundEvents.ENTITY_SPLASH_POTION_BREAK); + public static final CompatSoundEvent ENTITY_SPLASH_POTION_THROW = new CompatSoundEvent(SoundEvents.ENTITY_SPLASH_POTION_THROW); + public static final CompatSoundEvent BLOCK_SPONGE_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_SPONGE_BREAK); + public static final CompatSoundEvent BLOCK_SPONGE_FALL = new CompatSoundEvent(SoundEvents.BLOCK_SPONGE_FALL); + public static final CompatSoundEvent BLOCK_SPONGE_HIT = new CompatSoundEvent(SoundEvents.BLOCK_SPONGE_HIT); + public static final CompatSoundEvent BLOCK_SPONGE_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_SPONGE_PLACE); + public static final CompatSoundEvent BLOCK_SPONGE_STEP = new CompatSoundEvent(SoundEvents.BLOCK_SPONGE_STEP); + public static final CompatSoundEvent BLOCK_SPONGE_ABSORB = new CompatSoundEvent(SoundEvents.BLOCK_SPONGE_ABSORB); + public static final CompatSoundEvent ITEM_SPYGLASS_USE = new CompatSoundEvent(SoundEvents.ITEM_SPYGLASS_USE); + public static final CompatSoundEvent ITEM_SPYGLASS_STOP_USING = new CompatSoundEvent(SoundEvents.ITEM_SPYGLASS_STOP_USING); + public static final CompatSoundEvent ENTITY_SQUID_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_SQUID_AMBIENT); + public static final CompatSoundEvent ENTITY_SQUID_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_SQUID_DEATH); + public static final CompatSoundEvent ENTITY_SQUID_HURT = new CompatSoundEvent(SoundEvents.ENTITY_SQUID_HURT); + public static final CompatSoundEvent ENTITY_SQUID_SQUIRT = new CompatSoundEvent(SoundEvents.ENTITY_SQUID_SQUIRT); + public static final CompatSoundEvent BLOCK_STONE_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_STONE_BREAK); + public static final CompatSoundEvent BLOCK_STONE_BUTTON_CLICK_OFF = new CompatSoundEvent(SoundEvents.BLOCK_STONE_BUTTON_CLICK_OFF); + public static final CompatSoundEvent BLOCK_STONE_BUTTON_CLICK_ON = new CompatSoundEvent(SoundEvents.BLOCK_STONE_BUTTON_CLICK_ON); + public static final CompatSoundEvent BLOCK_STONE_FALL = new CompatSoundEvent(SoundEvents.BLOCK_STONE_FALL); + public static final CompatSoundEvent BLOCK_STONE_HIT = new CompatSoundEvent(SoundEvents.BLOCK_STONE_HIT); + public static final CompatSoundEvent BLOCK_STONE_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_STONE_PLACE); + public static final CompatSoundEvent BLOCK_STONE_PRESSURE_PLATE_CLICK_OFF = new CompatSoundEvent(SoundEvents.BLOCK_STONE_PRESSURE_PLATE_CLICK_OFF); + public static final CompatSoundEvent BLOCK_STONE_PRESSURE_PLATE_CLICK_ON = new CompatSoundEvent(SoundEvents.BLOCK_STONE_PRESSURE_PLATE_CLICK_ON); + public static final CompatSoundEvent BLOCK_STONE_STEP = new CompatSoundEvent(SoundEvents.BLOCK_STONE_STEP); + public static final CompatSoundEvent ENTITY_STRAY_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_STRAY_AMBIENT); + public static final CompatSoundEvent ENTITY_STRAY_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_STRAY_DEATH); + public static final CompatSoundEvent ENTITY_STRAY_HURT = new CompatSoundEvent(SoundEvents.ENTITY_STRAY_HURT); + public static final CompatSoundEvent ENTITY_STRAY_STEP = new CompatSoundEvent(SoundEvents.ENTITY_STRAY_STEP); + public static final CompatSoundEvent BLOCK_SWEET_BERRY_BUSH_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_SWEET_BERRY_BUSH_BREAK); + public static final CompatSoundEvent BLOCK_SWEET_BERRY_BUSH_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_SWEET_BERRY_BUSH_PLACE); + public static final CompatSoundEvent BLOCK_SWEET_BERRY_BUSH_PICK_BERRIES = new CompatSoundEvent(SoundEvents.BLOCK_SWEET_BERRY_BUSH_PICK_BERRIES); + public static final CompatSoundEvent ENTITY_TADPOLE_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_TADPOLE_DEATH); + public static final CompatSoundEvent ENTITY_TADPOLE_FLOP = new CompatSoundEvent(SoundEvents.ENTITY_TADPOLE_FLOP); + public static final CompatSoundEvent ENTITY_TADPOLE_GROW_UP = new CompatSoundEvent(SoundEvents.ENTITY_TADPOLE_GROW_UP); + public static final CompatSoundEvent ENTITY_TADPOLE_HURT = new CompatSoundEvent(SoundEvents.ENTITY_TADPOLE_HURT); + public static final CompatSoundEvent ENCHANT_THORNS_HIT = new CompatSoundEvent(SoundEvents.ENCHANT_THORNS_HIT); + public static final CompatSoundEvent ENTITY_TNT_PRIMED = new CompatSoundEvent(SoundEvents.ENTITY_TNT_PRIMED); + public static final CompatSoundEvent ITEM_TOTEM_USE = new CompatSoundEvent(SoundEvents.ITEM_TOTEM_USE); + public static final CompatSoundEvent ITEM_TRIDENT_HIT = new CompatSoundEvent(SoundEvents.ITEM_TRIDENT_HIT); + public static final CompatSoundEvent ITEM_TRIDENT_HIT_GROUND = new CompatSoundEvent(SoundEvents.ITEM_TRIDENT_HIT_GROUND); + public static final CompatSoundEvent ITEM_TRIDENT_RETURN = new CompatSoundEvent(SoundEvents.ITEM_TRIDENT_RETURN); + public static final CompatSoundEvent ITEM_TRIDENT_RIPTIDE_1 = new CompatSoundEvent(SoundEvents.ITEM_TRIDENT_RIPTIDE_1); + public static final CompatSoundEvent ITEM_TRIDENT_RIPTIDE_2 = new CompatSoundEvent(SoundEvents.ITEM_TRIDENT_RIPTIDE_2); + public static final CompatSoundEvent ITEM_TRIDENT_RIPTIDE_3 = new CompatSoundEvent(SoundEvents.ITEM_TRIDENT_RIPTIDE_3); + public static final CompatSoundEvent ITEM_TRIDENT_THROW = new CompatSoundEvent(SoundEvents.ITEM_TRIDENT_THROW); + public static final CompatSoundEvent ITEM_TRIDENT_THUNDER = new CompatSoundEvent(SoundEvents.ITEM_TRIDENT_THUNDER); + public static final CompatSoundEvent BLOCK_TRIPWIRE_ATTACH = new CompatSoundEvent(SoundEvents.BLOCK_TRIPWIRE_ATTACH); + public static final CompatSoundEvent BLOCK_TRIPWIRE_CLICK_OFF = new CompatSoundEvent(SoundEvents.BLOCK_TRIPWIRE_CLICK_OFF); + public static final CompatSoundEvent BLOCK_TRIPWIRE_CLICK_ON = new CompatSoundEvent(SoundEvents.BLOCK_TRIPWIRE_CLICK_ON); + public static final CompatSoundEvent BLOCK_TRIPWIRE_DETACH = new CompatSoundEvent(SoundEvents.BLOCK_TRIPWIRE_DETACH); + public static final CompatSoundEvent ENTITY_TROPICAL_FISH_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_TROPICAL_FISH_AMBIENT); + public static final CompatSoundEvent ENTITY_TROPICAL_FISH_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_TROPICAL_FISH_DEATH); + public static final CompatSoundEvent ENTITY_TROPICAL_FISH_FLOP = new CompatSoundEvent(SoundEvents.ENTITY_TROPICAL_FISH_FLOP); + public static final CompatSoundEvent ENTITY_TROPICAL_FISH_HURT = new CompatSoundEvent(SoundEvents.ENTITY_TROPICAL_FISH_HURT); + public static final CompatSoundEvent BLOCK_TUFF_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_TUFF_BREAK); + public static final CompatSoundEvent BLOCK_TUFF_STEP = new CompatSoundEvent(SoundEvents.BLOCK_TUFF_STEP); + public static final CompatSoundEvent BLOCK_TUFF_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_TUFF_PLACE); + public static final CompatSoundEvent BLOCK_TUFF_HIT = new CompatSoundEvent(SoundEvents.BLOCK_TUFF_HIT); + public static final CompatSoundEvent BLOCK_TUFF_FALL = new CompatSoundEvent(SoundEvents.BLOCK_TUFF_FALL); + public static final CompatSoundEvent BLOCK_TUFF_BRICKS_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_TUFF_BRICKS_BREAK); + public static final CompatSoundEvent BLOCK_TUFF_BRICKS_FALL = new CompatSoundEvent(SoundEvents.BLOCK_TUFF_BRICKS_FALL); + public static final CompatSoundEvent BLOCK_TUFF_BRICKS_HIT = new CompatSoundEvent(SoundEvents.BLOCK_TUFF_BRICKS_HIT); + public static final CompatSoundEvent BLOCK_TUFF_BRICKS_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_TUFF_BRICKS_PLACE); + public static final CompatSoundEvent BLOCK_TUFF_BRICKS_STEP = new CompatSoundEvent(SoundEvents.BLOCK_TUFF_BRICKS_STEP); + public static final CompatSoundEvent BLOCK_POLISHED_TUFF_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_POLISHED_TUFF_BREAK); + public static final CompatSoundEvent BLOCK_POLISHED_TUFF_FALL = new CompatSoundEvent(SoundEvents.BLOCK_POLISHED_TUFF_FALL); + public static final CompatSoundEvent BLOCK_POLISHED_TUFF_HIT = new CompatSoundEvent(SoundEvents.BLOCK_POLISHED_TUFF_HIT); + public static final CompatSoundEvent BLOCK_POLISHED_TUFF_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_POLISHED_TUFF_PLACE); + public static final CompatSoundEvent BLOCK_POLISHED_TUFF_STEP = new CompatSoundEvent(SoundEvents.BLOCK_POLISHED_TUFF_STEP); + public static final CompatSoundEvent ENTITY_TURTLE_AMBIENT_LAND = new CompatSoundEvent(SoundEvents.ENTITY_TURTLE_AMBIENT_LAND); + public static final CompatSoundEvent ENTITY_TURTLE_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_TURTLE_DEATH); + public static final CompatSoundEvent ENTITY_TURTLE_DEATH_BABY = new CompatSoundEvent(SoundEvents.ENTITY_TURTLE_DEATH_BABY); + public static final CompatSoundEvent ENTITY_TURTLE_EGG_BREAK = new CompatSoundEvent(SoundEvents.ENTITY_TURTLE_EGG_BREAK); + public static final CompatSoundEvent ENTITY_TURTLE_EGG_CRACK = new CompatSoundEvent(SoundEvents.ENTITY_TURTLE_EGG_CRACK); + public static final CompatSoundEvent ENTITY_TURTLE_EGG_HATCH = new CompatSoundEvent(SoundEvents.ENTITY_TURTLE_EGG_HATCH); + public static final CompatSoundEvent ENTITY_TURTLE_HURT = new CompatSoundEvent(SoundEvents.ENTITY_TURTLE_HURT); + public static final CompatSoundEvent ENTITY_TURTLE_HURT_BABY = new CompatSoundEvent(SoundEvents.ENTITY_TURTLE_HURT_BABY); + public static final CompatSoundEvent ENTITY_TURTLE_LAY_EGG = new CompatSoundEvent(SoundEvents.ENTITY_TURTLE_LAY_EGG); + public static final CompatSoundEvent ENTITY_TURTLE_SHAMBLE = new CompatSoundEvent(SoundEvents.ENTITY_TURTLE_SHAMBLE); + public static final CompatSoundEvent ENTITY_TURTLE_SHAMBLE_BABY = new CompatSoundEvent(SoundEvents.ENTITY_TURTLE_SHAMBLE_BABY); + public static final CompatSoundEvent ENTITY_TURTLE_SWIM = new CompatSoundEvent(SoundEvents.ENTITY_TURTLE_SWIM); + public static final CompatSoundEvent UI_BUTTON_CLICK = new CompatSoundEvent(SoundEvents.UI_BUTTON_CLICK); + public static final CompatSoundEvent UI_LOOM_SELECT_PATTERN = new CompatSoundEvent(SoundEvents.UI_LOOM_SELECT_PATTERN); + public static final CompatSoundEvent UI_LOOM_TAKE_RESULT = new CompatSoundEvent(SoundEvents.UI_LOOM_TAKE_RESULT); + public static final CompatSoundEvent UI_CARTOGRAPHY_TABLE_TAKE_RESULT = new CompatSoundEvent(SoundEvents.UI_CARTOGRAPHY_TABLE_TAKE_RESULT); + public static final CompatSoundEvent UI_STONECUTTER_TAKE_RESULT = new CompatSoundEvent(SoundEvents.UI_STONECUTTER_TAKE_RESULT); + public static final CompatSoundEvent UI_STONECUTTER_SELECT_RECIPE = new CompatSoundEvent(SoundEvents.UI_STONECUTTER_SELECT_RECIPE); + public static final CompatSoundEvent UI_TOAST_CHALLENGE_COMPLETE = new CompatSoundEvent(SoundEvents.UI_TOAST_CHALLENGE_COMPLETE); + public static final CompatSoundEvent UI_TOAST_IN = new CompatSoundEvent(SoundEvents.UI_TOAST_IN); + public static final CompatSoundEvent UI_TOAST_OUT = new CompatSoundEvent(SoundEvents.UI_TOAST_OUT); + public static final CompatSoundEvent BLOCK_VAULT_ACTIVATE = new CompatSoundEvent(SoundEvents.BLOCK_VAULT_ACTIVATE); + public static final CompatSoundEvent BLOCK_VAULT_AMBIENT = new CompatSoundEvent(SoundEvents.BLOCK_VAULT_AMBIENT); + public static final CompatSoundEvent BLOCK_VAULT_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_VAULT_BREAK); + public static final CompatSoundEvent BLOCK_VAULT_CLOSE_SHUTTER = new CompatSoundEvent(SoundEvents.BLOCK_VAULT_CLOSE_SHUTTER); + public static final CompatSoundEvent BLOCK_VAULT_DEACTIVATE = new CompatSoundEvent(SoundEvents.BLOCK_VAULT_DEACTIVATE); + public static final CompatSoundEvent BLOCK_VAULT_EJECT_ITEM = new CompatSoundEvent(SoundEvents.BLOCK_VAULT_EJECT_ITEM); + public static final CompatSoundEvent BLOCK_VAULT_REJECT_REWARDED_PLAYER = new CompatSoundEvent(SoundEvents.BLOCK_VAULT_REJECT_REWARDED_PLAYER); + public static final CompatSoundEvent BLOCK_VAULT_FALL = new CompatSoundEvent(SoundEvents.BLOCK_VAULT_FALL); + public static final CompatSoundEvent BLOCK_VAULT_HIT = new CompatSoundEvent(SoundEvents.BLOCK_VAULT_HIT); + public static final CompatSoundEvent BLOCK_VAULT_INSERT_ITEM = new CompatSoundEvent(SoundEvents.BLOCK_VAULT_INSERT_ITEM); + public static final CompatSoundEvent BLOCK_VAULT_INSERT_ITEM_FAIL = new CompatSoundEvent(SoundEvents.BLOCK_VAULT_INSERT_ITEM_FAIL); + public static final CompatSoundEvent BLOCK_VAULT_OPEN_SHUTTER = new CompatSoundEvent(SoundEvents.BLOCK_VAULT_OPEN_SHUTTER); + public static final CompatSoundEvent BLOCK_VAULT_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_VAULT_PLACE); + public static final CompatSoundEvent BLOCK_VAULT_STEP = new CompatSoundEvent(SoundEvents.BLOCK_VAULT_STEP); + public static final CompatSoundEvent ENTITY_VEX_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_VEX_AMBIENT); + public static final CompatSoundEvent ENTITY_VEX_CHARGE = new CompatSoundEvent(SoundEvents.ENTITY_VEX_CHARGE); + public static final CompatSoundEvent ENTITY_VEX_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_VEX_DEATH); + public static final CompatSoundEvent ENTITY_VEX_HURT = new CompatSoundEvent(SoundEvents.ENTITY_VEX_HURT); + public static final CompatSoundEvent ENTITY_VILLAGER_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_VILLAGER_AMBIENT); + public static final CompatSoundEvent ENTITY_VILLAGER_CELEBRATE = new CompatSoundEvent(SoundEvents.ENTITY_VILLAGER_CELEBRATE); + public static final CompatSoundEvent ENTITY_VILLAGER_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_VILLAGER_DEATH); + public static final CompatSoundEvent ENTITY_VILLAGER_HURT = new CompatSoundEvent(SoundEvents.ENTITY_VILLAGER_HURT); + public static final CompatSoundEvent ENTITY_VILLAGER_NO = new CompatSoundEvent(SoundEvents.ENTITY_VILLAGER_NO); + public static final CompatSoundEvent ENTITY_VILLAGER_TRADE = new CompatSoundEvent(SoundEvents.ENTITY_VILLAGER_TRADE); + public static final CompatSoundEvent ENTITY_VILLAGER_YES = new CompatSoundEvent(SoundEvents.ENTITY_VILLAGER_YES); + public static final CompatSoundEvent ENTITY_VILLAGER_WORK_ARMORER = new CompatSoundEvent(SoundEvents.ENTITY_VILLAGER_WORK_ARMORER); + public static final CompatSoundEvent ENTITY_VILLAGER_WORK_BUTCHER = new CompatSoundEvent(SoundEvents.ENTITY_VILLAGER_WORK_BUTCHER); + public static final CompatSoundEvent ENTITY_VILLAGER_WORK_CARTOGRAPHER = new CompatSoundEvent(SoundEvents.ENTITY_VILLAGER_WORK_CARTOGRAPHER); + public static final CompatSoundEvent ENTITY_VILLAGER_WORK_CLERIC = new CompatSoundEvent(SoundEvents.ENTITY_VILLAGER_WORK_CLERIC); + public static final CompatSoundEvent ENTITY_VILLAGER_WORK_FARMER = new CompatSoundEvent(SoundEvents.ENTITY_VILLAGER_WORK_FARMER); + public static final CompatSoundEvent ENTITY_VILLAGER_WORK_FISHERMAN = new CompatSoundEvent(SoundEvents.ENTITY_VILLAGER_WORK_FISHERMAN); + public static final CompatSoundEvent ENTITY_VILLAGER_WORK_FLETCHER = new CompatSoundEvent(SoundEvents.ENTITY_VILLAGER_WORK_FLETCHER); + public static final CompatSoundEvent ENTITY_VILLAGER_WORK_LEATHERWORKER = new CompatSoundEvent(SoundEvents.ENTITY_VILLAGER_WORK_LEATHERWORKER); + public static final CompatSoundEvent ENTITY_VILLAGER_WORK_LIBRARIAN = new CompatSoundEvent(SoundEvents.ENTITY_VILLAGER_WORK_LIBRARIAN); + public static final CompatSoundEvent ENTITY_VILLAGER_WORK_MASON = new CompatSoundEvent(SoundEvents.ENTITY_VILLAGER_WORK_MASON); + public static final CompatSoundEvent ENTITY_VILLAGER_WORK_SHEPHERD = new CompatSoundEvent(SoundEvents.ENTITY_VILLAGER_WORK_SHEPHERD); + public static final CompatSoundEvent ENTITY_VILLAGER_WORK_TOOLSMITH = new CompatSoundEvent(SoundEvents.ENTITY_VILLAGER_WORK_TOOLSMITH); + public static final CompatSoundEvent ENTITY_VILLAGER_WORK_WEAPONSMITH = new CompatSoundEvent(SoundEvents.ENTITY_VILLAGER_WORK_WEAPONSMITH); + public static final CompatSoundEvent ENTITY_VINDICATOR_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_VINDICATOR_AMBIENT); + public static final CompatSoundEvent ENTITY_VINDICATOR_CELEBRATE = new CompatSoundEvent(SoundEvents.ENTITY_VINDICATOR_CELEBRATE); + public static final CompatSoundEvent ENTITY_VINDICATOR_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_VINDICATOR_DEATH); + public static final CompatSoundEvent ENTITY_VINDICATOR_HURT = new CompatSoundEvent(SoundEvents.ENTITY_VINDICATOR_HURT); + public static final CompatSoundEvent BLOCK_VINE_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_VINE_BREAK); + public static final CompatSoundEvent BLOCK_VINE_FALL = new CompatSoundEvent(SoundEvents.BLOCK_VINE_FALL); + public static final CompatSoundEvent BLOCK_VINE_HIT = new CompatSoundEvent(SoundEvents.BLOCK_VINE_HIT); + public static final CompatSoundEvent BLOCK_VINE_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_VINE_PLACE); + public static final CompatSoundEvent BLOCK_VINE_STEP = new CompatSoundEvent(SoundEvents.BLOCK_VINE_STEP); + public static final CompatSoundEvent BLOCK_LILY_PAD_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_LILY_PAD_PLACE); + public static final CompatSoundEvent ENTITY_WANDERING_TRADER_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_WANDERING_TRADER_AMBIENT); + public static final CompatSoundEvent ENTITY_WANDERING_TRADER_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_WANDERING_TRADER_DEATH); + public static final CompatSoundEvent ENTITY_WANDERING_TRADER_DISAPPEARED = new CompatSoundEvent(SoundEvents.ENTITY_WANDERING_TRADER_DISAPPEARED); + public static final CompatSoundEvent ENTITY_WANDERING_TRADER_DRINK_MILK = new CompatSoundEvent(SoundEvents.ENTITY_WANDERING_TRADER_DRINK_MILK); + public static final CompatSoundEvent ENTITY_WANDERING_TRADER_DRINK_POTION = new CompatSoundEvent(SoundEvents.ENTITY_WANDERING_TRADER_DRINK_POTION); + public static final CompatSoundEvent ENTITY_WANDERING_TRADER_HURT = new CompatSoundEvent(SoundEvents.ENTITY_WANDERING_TRADER_HURT); + public static final CompatSoundEvent ENTITY_WANDERING_TRADER_NO = new CompatSoundEvent(SoundEvents.ENTITY_WANDERING_TRADER_NO); + public static final CompatSoundEvent ENTITY_WANDERING_TRADER_REAPPEARED = new CompatSoundEvent(SoundEvents.ENTITY_WANDERING_TRADER_REAPPEARED); + public static final CompatSoundEvent ENTITY_WANDERING_TRADER_TRADE = new CompatSoundEvent(SoundEvents.ENTITY_WANDERING_TRADER_TRADE); + public static final CompatSoundEvent ENTITY_WANDERING_TRADER_YES = new CompatSoundEvent(SoundEvents.ENTITY_WANDERING_TRADER_YES); + public static final CompatSoundEvent ENTITY_WARDEN_AGITATED = new CompatSoundEvent(SoundEvents.ENTITY_WARDEN_AGITATED); + public static final CompatSoundEvent ENTITY_WARDEN_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_WARDEN_AMBIENT); + public static final CompatSoundEvent ENTITY_WARDEN_ANGRY = new CompatSoundEvent(SoundEvents.ENTITY_WARDEN_ANGRY); + public static final CompatSoundEvent ENTITY_WARDEN_ATTACK_IMPACT = new CompatSoundEvent(SoundEvents.ENTITY_WARDEN_ATTACK_IMPACT); + public static final CompatSoundEvent ENTITY_WARDEN_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_WARDEN_DEATH); + public static final CompatSoundEvent ENTITY_WARDEN_DIG = new CompatSoundEvent(SoundEvents.ENTITY_WARDEN_DIG); + public static final CompatSoundEvent ENTITY_WARDEN_EMERGE = new CompatSoundEvent(SoundEvents.ENTITY_WARDEN_EMERGE); + public static final CompatSoundEvent ENTITY_WARDEN_HEARTBEAT = new CompatSoundEvent(SoundEvents.ENTITY_WARDEN_HEARTBEAT); + public static final CompatSoundEvent ENTITY_WARDEN_HURT = new CompatSoundEvent(SoundEvents.ENTITY_WARDEN_HURT); + public static final CompatSoundEvent ENTITY_WARDEN_LISTENING = new CompatSoundEvent(SoundEvents.ENTITY_WARDEN_LISTENING); + public static final CompatSoundEvent ENTITY_WARDEN_LISTENING_ANGRY = new CompatSoundEvent(SoundEvents.ENTITY_WARDEN_LISTENING_ANGRY); + public static final CompatSoundEvent ENTITY_WARDEN_NEARBY_CLOSE = new CompatSoundEvent(SoundEvents.ENTITY_WARDEN_NEARBY_CLOSE); + public static final CompatSoundEvent ENTITY_WARDEN_NEARBY_CLOSER = new CompatSoundEvent(SoundEvents.ENTITY_WARDEN_NEARBY_CLOSER); + public static final CompatSoundEvent ENTITY_WARDEN_NEARBY_CLOSEST = new CompatSoundEvent(SoundEvents.ENTITY_WARDEN_NEARBY_CLOSEST); + public static final CompatSoundEvent ENTITY_WARDEN_ROAR = new CompatSoundEvent(SoundEvents.ENTITY_WARDEN_ROAR); + public static final CompatSoundEvent ENTITY_WARDEN_SNIFF = new CompatSoundEvent(SoundEvents.ENTITY_WARDEN_SNIFF); + public static final CompatSoundEvent ENTITY_WARDEN_SONIC_BOOM = new CompatSoundEvent(SoundEvents.ENTITY_WARDEN_SONIC_BOOM); + public static final CompatSoundEvent ENTITY_WARDEN_SONIC_CHARGE = new CompatSoundEvent(SoundEvents.ENTITY_WARDEN_SONIC_CHARGE); + public static final CompatSoundEvent ENTITY_WARDEN_STEP = new CompatSoundEvent(SoundEvents.ENTITY_WARDEN_STEP); + public static final CompatSoundEvent ENTITY_WARDEN_TENDRIL_CLICKS = new CompatSoundEvent(SoundEvents.ENTITY_WARDEN_TENDRIL_CLICKS); + public static final CompatSoundEvent BLOCK_HANGING_SIGN_WAXED_INTERACT_FAIL = new CompatSoundEvent(SoundEvents.BLOCK_HANGING_SIGN_WAXED_INTERACT_FAIL); + public static final CompatSoundEvent BLOCK_SIGN_WAXED_INTERACT_FAIL = new CompatSoundEvent(SoundEvents.BLOCK_SIGN_WAXED_INTERACT_FAIL); + public static final CompatSoundEvent BLOCK_WATER_AMBIENT = new CompatSoundEvent(SoundEvents.BLOCK_WATER_AMBIENT); + public static final CompatSoundEvent WEATHER_RAIN = new CompatSoundEvent(SoundEvents.WEATHER_RAIN); + public static final CompatSoundEvent WEATHER_RAIN_ABOVE = new CompatSoundEvent(SoundEvents.WEATHER_RAIN_ABOVE); + public static final CompatSoundEvent BLOCK_WET_GRASS_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_WET_GRASS_BREAK); + public static final CompatSoundEvent BLOCK_WET_GRASS_FALL = new CompatSoundEvent(SoundEvents.BLOCK_WET_GRASS_FALL); + public static final CompatSoundEvent BLOCK_WET_GRASS_HIT = new CompatSoundEvent(SoundEvents.BLOCK_WET_GRASS_HIT); + public static final CompatSoundEvent BLOCK_WET_GRASS_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_WET_GRASS_PLACE); + public static final CompatSoundEvent BLOCK_WET_GRASS_STEP = new CompatSoundEvent(SoundEvents.BLOCK_WET_GRASS_STEP); + public static final CompatSoundEvent BLOCK_WET_SPONGE_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_WET_SPONGE_BREAK); + public static final CompatSoundEvent BLOCK_WET_SPONGE_DRIES = new CompatSoundEvent(SoundEvents.BLOCK_WET_SPONGE_DRIES); + public static final CompatSoundEvent BLOCK_WET_SPONGE_FALL = new CompatSoundEvent(SoundEvents.BLOCK_WET_SPONGE_FALL); + public static final CompatSoundEvent BLOCK_WET_SPONGE_HIT = new CompatSoundEvent(SoundEvents.BLOCK_WET_SPONGE_HIT); + public static final CompatSoundEvent BLOCK_WET_SPONGE_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_WET_SPONGE_PLACE); + public static final CompatSoundEvent BLOCK_WET_SPONGE_STEP = new CompatSoundEvent(SoundEvents.BLOCK_WET_SPONGE_STEP); + public static final CompatSoundEvent ENTITY_WIND_CHARGE_WIND_BURST = new CompatSoundEvent(SoundEvents.ENTITY_WIND_CHARGE_WIND_BURST); + public static final CompatSoundEvent ENTITY_WIND_CHARGE_THROW = new CompatSoundEvent(SoundEvents.ENTITY_WIND_CHARGE_THROW); + public static final CompatSoundEvent ENTITY_WITCH_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_WITCH_AMBIENT); + public static final CompatSoundEvent ENTITY_WITCH_CELEBRATE = new CompatSoundEvent(SoundEvents.ENTITY_WITCH_CELEBRATE); + public static final CompatSoundEvent ENTITY_WITCH_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_WITCH_DEATH); + public static final CompatSoundEvent ENTITY_WITCH_DRINK = new CompatSoundEvent(SoundEvents.ENTITY_WITCH_DRINK); + public static final CompatSoundEvent ENTITY_WITCH_HURT = new CompatSoundEvent(SoundEvents.ENTITY_WITCH_HURT); + public static final CompatSoundEvent ENTITY_WITCH_THROW = new CompatSoundEvent(SoundEvents.ENTITY_WITCH_THROW); + public static final CompatSoundEvent ENTITY_WITHER_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_WITHER_AMBIENT); + public static final CompatSoundEvent ENTITY_WITHER_BREAK_BLOCK = new CompatSoundEvent(SoundEvents.ENTITY_WITHER_BREAK_BLOCK); + public static final CompatSoundEvent ENTITY_WITHER_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_WITHER_DEATH); + public static final CompatSoundEvent ENTITY_WITHER_HURT = new CompatSoundEvent(SoundEvents.ENTITY_WITHER_HURT); + public static final CompatSoundEvent ENTITY_WITHER_SHOOT = new CompatSoundEvent(SoundEvents.ENTITY_WITHER_SHOOT); + public static final CompatSoundEvent ENTITY_WITHER_SKELETON_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_WITHER_SKELETON_AMBIENT); + public static final CompatSoundEvent ENTITY_WITHER_SKELETON_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_WITHER_SKELETON_DEATH); + public static final CompatSoundEvent ENTITY_WITHER_SKELETON_HURT = new CompatSoundEvent(SoundEvents.ENTITY_WITHER_SKELETON_HURT); + public static final CompatSoundEvent ENTITY_WITHER_SKELETON_STEP = new CompatSoundEvent(SoundEvents.ENTITY_WITHER_SKELETON_STEP); + public static final CompatSoundEvent ENTITY_WITHER_SPAWN = new CompatSoundEvent(SoundEvents.ENTITY_WITHER_SPAWN); + public static final CompatSoundEvent ITEM_WOLF_ARMOR_BREAK = new CompatSoundEvent(SoundEvents.ITEM_WOLF_ARMOR_BREAK); + public static final CompatSoundEvent ITEM_WOLF_ARMOR_CRACK = new CompatSoundEvent(SoundEvents.ITEM_WOLF_ARMOR_CRACK); + public static final CompatSoundEvent ITEM_WOLF_ARMOR_DAMAGE = new CompatSoundEvent(SoundEvents.ITEM_WOLF_ARMOR_DAMAGE); + public static final CompatSoundEvent ITEM_WOLF_ARMOR_REPAIR = new CompatSoundEvent(SoundEvents.ITEM_WOLF_ARMOR_REPAIR); + public static final CompatSoundEvent ENTITY_WOLF_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_WOLF_AMBIENT); + public static final CompatSoundEvent ENTITY_WOLF_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_WOLF_DEATH); + public static final CompatSoundEvent ENTITY_WOLF_GROWL = new CompatSoundEvent(SoundEvents.ENTITY_WOLF_GROWL); + public static final CompatSoundEvent ENTITY_WOLF_HOWL = new CompatSoundEvent(SoundEvents.ENTITY_WOLF_HOWL); + public static final CompatSoundEvent ENTITY_WOLF_HURT = new CompatSoundEvent(SoundEvents.ENTITY_WOLF_HURT); + public static final CompatSoundEvent ENTITY_WOLF_PANT = new CompatSoundEvent(SoundEvents.ENTITY_WOLF_PANT); + public static final CompatSoundEvent ENTITY_WOLF_SHAKE = new CompatSoundEvent(SoundEvents.ENTITY_WOLF_SHAKE); + public static final CompatSoundEvent ENTITY_WOLF_STEP = new CompatSoundEvent(SoundEvents.ENTITY_WOLF_STEP); + public static final CompatSoundEvent ENTITY_WOLF_WHINE = new CompatSoundEvent(SoundEvents.ENTITY_WOLF_WHINE); + public static final CompatSoundEvent BLOCK_WOODEN_DOOR_CLOSE = new CompatSoundEvent(SoundEvents.BLOCK_WOODEN_DOOR_CLOSE); + public static final CompatSoundEvent BLOCK_WOODEN_DOOR_OPEN = new CompatSoundEvent(SoundEvents.BLOCK_WOODEN_DOOR_OPEN); + public static final CompatSoundEvent BLOCK_WOODEN_TRAPDOOR_CLOSE = new CompatSoundEvent(SoundEvents.BLOCK_WOODEN_TRAPDOOR_CLOSE); + public static final CompatSoundEvent BLOCK_WOODEN_TRAPDOOR_OPEN = new CompatSoundEvent(SoundEvents.BLOCK_WOODEN_TRAPDOOR_OPEN); + public static final CompatSoundEvent BLOCK_WOODEN_BUTTON_CLICK_OFF = new CompatSoundEvent(SoundEvents.BLOCK_WOODEN_BUTTON_CLICK_OFF); + public static final CompatSoundEvent BLOCK_WOODEN_BUTTON_CLICK_ON = new CompatSoundEvent(SoundEvents.BLOCK_WOODEN_BUTTON_CLICK_ON); + public static final CompatSoundEvent BLOCK_WOODEN_PRESSURE_PLATE_CLICK_OFF = new CompatSoundEvent(SoundEvents.BLOCK_WOODEN_PRESSURE_PLATE_CLICK_OFF); + public static final CompatSoundEvent BLOCK_WOODEN_PRESSURE_PLATE_CLICK_ON = new CompatSoundEvent(SoundEvents.BLOCK_WOODEN_PRESSURE_PLATE_CLICK_ON); + public static final CompatSoundEvent BLOCK_WOOD_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_WOOD_BREAK); + public static final CompatSoundEvent BLOCK_WOOD_FALL = new CompatSoundEvent(SoundEvents.BLOCK_WOOD_FALL); + public static final CompatSoundEvent BLOCK_WOOD_HIT = new CompatSoundEvent(SoundEvents.BLOCK_WOOD_HIT); + public static final CompatSoundEvent BLOCK_WOOD_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_WOOD_PLACE); + public static final CompatSoundEvent BLOCK_WOOD_STEP = new CompatSoundEvent(SoundEvents.BLOCK_WOOD_STEP); + public static final CompatSoundEvent BLOCK_WOOL_BREAK = new CompatSoundEvent(SoundEvents.BLOCK_WOOL_BREAK); + public static final CompatSoundEvent BLOCK_WOOL_FALL = new CompatSoundEvent(SoundEvents.BLOCK_WOOL_FALL); + public static final CompatSoundEvent BLOCK_WOOL_HIT = new CompatSoundEvent(SoundEvents.BLOCK_WOOL_HIT); + public static final CompatSoundEvent BLOCK_WOOL_PLACE = new CompatSoundEvent(SoundEvents.BLOCK_WOOL_PLACE); + public static final CompatSoundEvent BLOCK_WOOL_STEP = new CompatSoundEvent(SoundEvents.BLOCK_WOOL_STEP); + public static final CompatSoundEvent ENTITY_ZOGLIN_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_ZOGLIN_AMBIENT); + public static final CompatSoundEvent ENTITY_ZOGLIN_ANGRY = new CompatSoundEvent(SoundEvents.ENTITY_ZOGLIN_ANGRY); + public static final CompatSoundEvent ENTITY_ZOGLIN_ATTACK = new CompatSoundEvent(SoundEvents.ENTITY_ZOGLIN_ATTACK); + public static final CompatSoundEvent ENTITY_ZOGLIN_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_ZOGLIN_DEATH); + public static final CompatSoundEvent ENTITY_ZOGLIN_HURT = new CompatSoundEvent(SoundEvents.ENTITY_ZOGLIN_HURT); + public static final CompatSoundEvent ENTITY_ZOGLIN_STEP = new CompatSoundEvent(SoundEvents.ENTITY_ZOGLIN_STEP); + public static final CompatSoundEvent ENTITY_ZOMBIE_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_ZOMBIE_AMBIENT); + public static final CompatSoundEvent ENTITY_ZOMBIE_ATTACK_WOODEN_DOOR = new CompatSoundEvent(SoundEvents.ENTITY_ZOMBIE_ATTACK_WOODEN_DOOR); + public static final CompatSoundEvent ENTITY_ZOMBIE_ATTACK_IRON_DOOR = new CompatSoundEvent(SoundEvents.ENTITY_ZOMBIE_ATTACK_IRON_DOOR); + public static final CompatSoundEvent ENTITY_ZOMBIE_BREAK_WOODEN_DOOR = new CompatSoundEvent(SoundEvents.ENTITY_ZOMBIE_BREAK_WOODEN_DOOR); + public static final CompatSoundEvent ENTITY_ZOMBIE_CONVERTED_TO_DROWNED = new CompatSoundEvent(SoundEvents.ENTITY_ZOMBIE_CONVERTED_TO_DROWNED); + public static final CompatSoundEvent ENTITY_ZOMBIE_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_ZOMBIE_DEATH); + public static final CompatSoundEvent ENTITY_ZOMBIE_DESTROY_EGG = new CompatSoundEvent(SoundEvents.ENTITY_ZOMBIE_DESTROY_EGG); + public static final CompatSoundEvent ENTITY_ZOMBIE_HORSE_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_ZOMBIE_HORSE_AMBIENT); + public static final CompatSoundEvent ENTITY_ZOMBIE_HORSE_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_ZOMBIE_HORSE_DEATH); + public static final CompatSoundEvent ENTITY_ZOMBIE_HORSE_HURT = new CompatSoundEvent(SoundEvents.ENTITY_ZOMBIE_HORSE_HURT); + public static final CompatSoundEvent ENTITY_ZOMBIE_HURT = new CompatSoundEvent(SoundEvents.ENTITY_ZOMBIE_HURT); + public static final CompatSoundEvent ENTITY_ZOMBIE_INFECT = new CompatSoundEvent(SoundEvents.ENTITY_ZOMBIE_INFECT); + public static final CompatSoundEvent ENTITY_ZOMBIFIED_PIGLIN_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_ZOMBIFIED_PIGLIN_AMBIENT); + public static final CompatSoundEvent ENTITY_ZOMBIFIED_PIGLIN_ANGRY = new CompatSoundEvent(SoundEvents.ENTITY_ZOMBIFIED_PIGLIN_ANGRY); + public static final CompatSoundEvent ENTITY_ZOMBIFIED_PIGLIN_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_ZOMBIFIED_PIGLIN_DEATH); + public static final CompatSoundEvent ENTITY_ZOMBIFIED_PIGLIN_HURT = new CompatSoundEvent(SoundEvents.ENTITY_ZOMBIFIED_PIGLIN_HURT); + public static final CompatSoundEvent ENTITY_ZOMBIE_STEP = new CompatSoundEvent(SoundEvents.ENTITY_ZOMBIE_STEP); + public static final CompatSoundEvent ENTITY_ZOMBIE_VILLAGER_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_ZOMBIE_VILLAGER_AMBIENT); + public static final CompatSoundEvent ENTITY_ZOMBIE_VILLAGER_CONVERTED = new CompatSoundEvent(SoundEvents.ENTITY_ZOMBIE_VILLAGER_CONVERTED); + public static final CompatSoundEvent ENTITY_ZOMBIE_VILLAGER_CURE = new CompatSoundEvent(SoundEvents.ENTITY_ZOMBIE_VILLAGER_CURE); + public static final CompatSoundEvent ENTITY_ZOMBIE_VILLAGER_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_ZOMBIE_VILLAGER_DEATH); + public static final CompatSoundEvent ENTITY_ZOMBIE_VILLAGER_HURT = new CompatSoundEvent(SoundEvents.ENTITY_ZOMBIE_VILLAGER_HURT); + public static final CompatSoundEvent ENTITY_ZOMBIE_VILLAGER_STEP = new CompatSoundEvent(SoundEvents.ENTITY_ZOMBIE_VILLAGER_STEP); + public static final CompatSoundEvent EVENT_MOB_EFFECT_BAD_OMEN = new CompatSoundEvent(SoundEvents.EVENT_MOB_EFFECT_BAD_OMEN); + public static final CompatSoundEvent EVENT_MOB_EFFECT_TRIAL_OMEN = new CompatSoundEvent(SoundEvents.EVENT_MOB_EFFECT_TRIAL_OMEN); + public static final CompatSoundEvent EVENT_MOB_EFFECT_RAID_OMEN = new CompatSoundEvent(SoundEvents.EVENT_MOB_EFFECT_RAID_OMEN); + public static final CompatSoundEvent ENTITY_HAPPY_GHAST_EQUIP = new CompatSoundEvent(SoundEvents.ITEM_ARMOR_EQUIP_WOLF); + public static final CompatSoundEvent ENTITY_HAPPY_GHAST_AMBIENT = new CompatSoundEvent(SoundEvents.ENTITY_GHAST_AMBIENT); + public static final CompatSoundEvent ENTITY_HAPPY_GHAST_DEATH = new CompatSoundEvent(SoundEvents.ENTITY_GHAST_DEATH); + public static final CompatSoundEvent ENTITY_HAPPY_GHAST_HURT = new CompatSoundEvent(SoundEvents.ENTITY_GHAST_HURT); + public static final CompatSoundEvent ENTITY_HAPPY_GHAST_RIDING = new CompatSoundEvent(SoundEvents.ENTITY_MINECART_RIDING); + public static final CompatSoundEvent ENTITY_HAPPY_GHAST_HARNESS_GOGGLES_DOWN = new CompatSoundEvent(SoundEvents.ENTITY_GHAST_AMBIENT); + public static final CompatSoundEvent ENTITY_HAPPY_GHAST_HARNESS_GOGGLES_UP = new CompatSoundEvent(SoundEvents.ENTITY_GHAST_AMBIENT); + public static final CompatSoundEvent ENTITY_HAPPY_GHAST_UNEQUIP = new CompatSoundEvent(SoundEvents.ITEM_ARMOR_UNEQUIP_WOLF); + + static { + GOAT_HORN_SOUNDS = SoundEvents.GOAT_HORN_SOUNDS.stream().map(CompatSoundEvent::new).collect(ImmutableList.toImmutableList()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/sound/RegistryResultCompatSoundEvent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/sound/RegistryResultCompatSoundEvent.java new file mode 100644 index 000000000..c9a68ee56 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/sound/RegistryResultCompatSoundEvent.java @@ -0,0 +1,26 @@ +package net.pitan76.mcpitanlib.api.sound; + +import net.minecraft.sound.SoundEvent; +import net.pitan76.mcpitanlib.api.registry.result.RegistryResult; + +public class RegistryResultCompatSoundEvent extends CompatSoundEvent { + + public RegistryResult result; + + public RegistryResultCompatSoundEvent(RegistryResult result) { + super((SoundEvent) null); + this.result = result; + } + + public static RegistryResultCompatSoundEvent of(RegistryResult result) { + return new RegistryResultCompatSoundEvent(result); + } + + @Override + public SoundEvent get() { + if ((result == null || result.getOrNull() == null) && super.get() != null) + return super.get(); + + return result.get(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/state/property/BooleanProperty.java b/common/src/main/java/net/pitan76/mcpitanlib/api/state/property/BooleanProperty.java new file mode 100644 index 000000000..a6b7775be --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/state/property/BooleanProperty.java @@ -0,0 +1,27 @@ +package net.pitan76.mcpitanlib.api.state.property; + +public class BooleanProperty implements IProperty { + + private final net.minecraft.state.property.BooleanProperty property; + + public BooleanProperty(String name) { + this(net.minecraft.state.property.BooleanProperty.of(name)); + } + + public BooleanProperty(net.minecraft.state.property.BooleanProperty property) { + this.property = property; + } + + public static BooleanProperty of(String name) { + return new BooleanProperty(name); + } + + public static BooleanProperty of(net.minecraft.state.property.BooleanProperty property) { + return new BooleanProperty(property); + } + + @Override + public net.minecraft.state.property.BooleanProperty getProperty() { + return property; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/state/property/CompatProperties.java b/common/src/main/java/net/pitan76/mcpitanlib/api/state/property/CompatProperties.java new file mode 100644 index 000000000..c6da2b2cb --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/state/property/CompatProperties.java @@ -0,0 +1,117 @@ +package net.pitan76.mcpitanlib.api.state.property; + +import net.minecraft.block.enums.*; +import net.minecraft.state.property.Properties; +import net.minecraft.state.property.Property; +import net.minecraft.util.StringIdentifiable; +import net.minecraft.util.math.Direction; + +public class CompatProperties { + public static final DirectionProperty FACING = new DirectionProperty(Properties.FACING); + public static final DirectionProperty HORIZONTAL_FACING = new DirectionProperty(Properties.HORIZONTAL_FACING); + public static final DirectionProperty HOPPER_FACING = new DirectionProperty(Properties.HOPPER_FACING); + public static final DirectionProperty VERTICAL_DIRECTION = new DirectionProperty(Properties.VERTICAL_DIRECTION); + + public static final BooleanProperty POWERED = new BooleanProperty(Properties.POWERED); + public static final BooleanProperty ENABLED = new BooleanProperty(Properties.ENABLED); + public static final BooleanProperty WATERLOGGED = new BooleanProperty(Properties.WATERLOGGED); + public static final BooleanProperty LIT = new BooleanProperty(Properties.LIT); + public static final BooleanProperty OCCUPIED = new BooleanProperty(Properties.OCCUPIED); + public static final BooleanProperty ATTACHED = new BooleanProperty(Properties.ATTACHED); + public static final BooleanProperty HANGING = new BooleanProperty(Properties.HANGING); + public static final BooleanProperty BOTTOM = new BooleanProperty(Properties.BOTTOM); + public static final BooleanProperty OPEN = new BooleanProperty(Properties.OPEN); + public static final BooleanProperty UNSTABLE = new BooleanProperty(Properties.UNSTABLE); + public static final BooleanProperty UP = new BooleanProperty(Properties.UP); + public static final BooleanProperty DOWN = new BooleanProperty(Properties.DOWN); + public static final BooleanProperty NORTH = new BooleanProperty(Properties.NORTH); + public static final BooleanProperty EAST = new BooleanProperty(Properties.EAST); + public static final BooleanProperty SOUTH = new BooleanProperty(Properties.SOUTH); + public static final BooleanProperty WEST = new BooleanProperty(Properties.WEST); + + public static final IntProperty POWER = new IntProperty(Properties.POWER); + public static final IntProperty LAYERS = new IntProperty(Properties.LAYERS); + public static final IntProperty NOTE = new IntProperty(Properties.NOTE); + public static final IntProperty ROTATION = new IntProperty(Properties.ROTATION); + public static final IntProperty EGGS = new IntProperty(Properties.EGGS); + public static final IntProperty DELAY = new IntProperty(Properties.DELAY); + + public static final EnumProperty BLOCK_HALF = new EnumProperty<>(Properties.BLOCK_HALF); + public static final EnumProperty STAIR_SHAPE = new EnumProperty<>(Properties.STAIR_SHAPE); + public static final EnumProperty SLAB_TYPE = new EnumProperty<>(Properties.SLAB_TYPE); + public static final EnumProperty CHEST_TYPE = new EnumProperty<>(Properties.CHEST_TYPE); + public static final EnumProperty PISTON_TYPE = new EnumProperty<>(Properties.PISTON_TYPE); + public static final EnumProperty AXIS = new EnumProperty<>(Properties.AXIS); + public static final EnumProperty HORIZONTAL_AXIS = new EnumProperty<>(Properties.HORIZONTAL_AXIS); + public static final EnumProperty COMPARATOR_MODE = new EnumProperty<>(Properties.COMPARATOR_MODE); + + public static IProperty of(Property property) { + if (property instanceof net.minecraft.state.property.IntProperty) { + return of((net.minecraft.state.property.IntProperty) property); + } + if (property instanceof net.minecraft.state.property.BooleanProperty) { + return of((net.minecraft.state.property.BooleanProperty) property); + } + if (property instanceof net.minecraft.state.property.EnumProperty) { + return of((net.minecraft.state.property.EnumProperty) property); + } + if (property instanceof net.minecraft.state.property.DirectionProperty) { + return ofDir((net.minecraft.state.property.DirectionProperty) property); + } + return UnknownProperty.of(property); + } + + public static IntProperty of(net.minecraft.state.property.IntProperty property) { + if (property == Properties.POWER) return POWER; + if (property == Properties.LAYERS) return LAYERS; + if (property == Properties.NOTE) return NOTE; + if (property == Properties.ROTATION) return ROTATION; + if (property == Properties.EGGS) return EGGS; + if (property == Properties.DELAY) return DELAY; + + return new IntProperty(property); + } + + public static BooleanProperty of(net.minecraft.state.property.BooleanProperty property) { + if (property == Properties.POWERED) return POWERED; + if (property == Properties.ENABLED) return ENABLED; + if (property == Properties.WATERLOGGED) return WATERLOGGED; + if (property == Properties.LIT) return LIT; + if (property == Properties.OCCUPIED) return OCCUPIED; + if (property == Properties.ATTACHED) return ATTACHED; + if (property == Properties.HANGING) return HANGING; + if (property == Properties.BOTTOM) return BOTTOM; + if (property == Properties.OPEN) return OPEN; + if (property == Properties.UNSTABLE) return UNSTABLE; + if (property == Properties.UP) return UP; + if (property == Properties.DOWN) return DOWN; + if (property == Properties.NORTH) return NORTH; + if (property == Properties.EAST) return EAST; + if (property == Properties.SOUTH) return SOUTH; + if (property == Properties.WEST) return WEST; + + return new BooleanProperty(property); + } + + public static & StringIdentifiable> EnumProperty of(net.minecraft.state.property.EnumProperty property) { + if (property.equals(Properties.BLOCK_HALF)) return (EnumProperty) BLOCK_HALF; + if (property.equals(Properties.STAIR_SHAPE)) return (EnumProperty) STAIR_SHAPE; + if (property.equals(Properties.SLAB_TYPE)) return (EnumProperty) SLAB_TYPE; + if (property.equals(Properties.CHEST_TYPE)) return (EnumProperty) CHEST_TYPE; + if (property.equals(Properties.PISTON_TYPE)) return (EnumProperty) PISTON_TYPE; + if (property.equals(Properties.AXIS)) return (EnumProperty) AXIS; + if (property.equals(Properties.HORIZONTAL_AXIS)) return (EnumProperty) HORIZONTAL_AXIS; + if (property.equals(Properties.COMPARATOR_MODE)) return (EnumProperty) COMPARATOR_MODE; + + return new EnumProperty<>(property); + } + + public static DirectionProperty ofDir(net.minecraft.state.property.DirectionProperty property) { + if (property == Properties.FACING) return FACING; + if (property == Properties.HORIZONTAL_FACING) return HORIZONTAL_FACING; + if (property == Properties.HOPPER_FACING) return HOPPER_FACING; + if (property == Properties.VERTICAL_DIRECTION) return VERTICAL_DIRECTION; + + return new DirectionProperty(property); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/state/property/DirectionProperty.java b/common/src/main/java/net/pitan76/mcpitanlib/api/state/property/DirectionProperty.java new file mode 100644 index 000000000..f1bd61a7b --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/state/property/DirectionProperty.java @@ -0,0 +1,50 @@ +package net.pitan76.mcpitanlib.api.state.property; + +import net.minecraft.state.property.EnumProperty; +import net.minecraft.state.property.Property; +import net.minecraft.util.math.Direction; +import net.pitan76.mcpitanlib.midohra.block.BlockState; + +import java.util.function.Predicate; + +public class DirectionProperty implements IProperty { + + private final EnumProperty property; + + public DirectionProperty(String name, Predicate filter) { + this(EnumProperty.of(name, Direction.class, filter)); + } + + public DirectionProperty(String name) { + this(name, direction -> true); + } + + public DirectionProperty(EnumProperty property) { + this.property = property; + } + + public static DirectionProperty of(String name) { + return new DirectionProperty(name); + } + + public static DirectionProperty of(String name, Predicate filter) { + return new DirectionProperty(name, filter); + } + + public net.pitan76.mcpitanlib.midohra.util.math.Direction getAsMidohra(BlockState state) { + return net.pitan76.mcpitanlib.midohra.util.math.Direction.of(get(state.toMinecraft())); + } + + public BlockState with(BlockState state, net.pitan76.mcpitanlib.midohra.util.math.Direction value) { + return BlockState.of(with(state.toMinecraft(), value.toMinecraft())); + } + + public BlockState cycle(BlockState state) { + return BlockState.of(cycle(state.toMinecraft())); + } + + @Override + public Property getProperty() { + return property; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/state/property/EnumProperty.java b/common/src/main/java/net/pitan76/mcpitanlib/api/state/property/EnumProperty.java new file mode 100644 index 000000000..7e7e9522b --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/state/property/EnumProperty.java @@ -0,0 +1,40 @@ +package net.pitan76.mcpitanlib.api.state.property; + +import net.minecraft.util.StringIdentifiable; + +import java.util.function.Predicate; + +public class EnumProperty & StringIdentifiable> implements IProperty { + + private final net.minecraft.state.property.EnumProperty property; + + public EnumProperty(String name, Class type) { + this(net.minecraft.state.property.EnumProperty.of(name, type)); + } + + public EnumProperty(String name, Class type, Predicate filter) { + this(net.minecraft.state.property.EnumProperty.of(name, type, filter)); + } + + public EnumProperty(net.minecraft.state.property.EnumProperty property) { + this.property = property; + } + + public static & StringIdentifiable> EnumProperty of(String name, Class type) { + return new EnumProperty<>(name, type); + } + + public static & StringIdentifiable> EnumProperty of(String name, Class type, Predicate filter) { + return new EnumProperty<>(name, type, filter); + } + + + public static & StringIdentifiable> EnumProperty of(net.minecraft.state.property.EnumProperty property) { + return new EnumProperty<>(property); + } + + @Override + public net.minecraft.state.property.EnumProperty getProperty() { + return property; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/state/property/IProperty.java b/common/src/main/java/net/pitan76/mcpitanlib/api/state/property/IProperty.java new file mode 100644 index 000000000..2274a41e3 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/state/property/IProperty.java @@ -0,0 +1,49 @@ +package net.pitan76.mcpitanlib.api.state.property; + +import net.minecraft.block.BlockState; +import net.minecraft.state.property.Property; +import net.pitan76.mcpitanlib.api.event.block.AppendPropertiesArgs; + +public interface IProperty> { + default void apply(AppendPropertiesArgs args) { + args.addProperty(getProperty()); + } + + default T get(BlockState state) { + return state.get(getProperty()); + } + + default BlockState with(BlockState state, T value) { + return state.with(getProperty(), value); + } + + default boolean contains(BlockState state) { + return state.contains(getProperty()); + } + + default BlockState cycle(BlockState state) { + return state.cycle(getProperty()); + } + + default String getName() { + return getProperty().getName(); + } + + Property getProperty(); + + default net.pitan76.mcpitanlib.midohra.block.BlockState with(net.pitan76.mcpitanlib.midohra.block.BlockState state, T value) { + return state.with(getProperty(), value); + } + + default T get(net.pitan76.mcpitanlib.midohra.block.BlockState state) { + return state.get(getProperty()); + } + + default boolean contains(net.pitan76.mcpitanlib.midohra.block.BlockState state) { + return state.contains(getProperty()); + } + + default net.pitan76.mcpitanlib.midohra.block.BlockState cycle(net.pitan76.mcpitanlib.midohra.block.BlockState state) { + return state.cycle(getProperty()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/state/property/IntProperty.java b/common/src/main/java/net/pitan76/mcpitanlib/api/state/property/IntProperty.java new file mode 100644 index 000000000..850604d9f --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/state/property/IntProperty.java @@ -0,0 +1,35 @@ +package net.pitan76.mcpitanlib.api.state.property; + +public class IntProperty implements IProperty { + + private final net.minecraft.state.property.IntProperty property; + + public IntProperty(String name, int min, int max) { + this(net.minecraft.state.property.IntProperty.of(name, min, max)); + } + + public IntProperty(String name) { + this(name, 0, 15); + } + + public IntProperty(net.minecraft.state.property.IntProperty property) { + this.property = property; + } + + public static IntProperty of(String name) { + return new IntProperty(name); + } + + public static IntProperty of(String name, int min, int max) { + return new IntProperty(name, min, max); + } + + public static IntProperty of(net.minecraft.state.property.IntProperty property) { + return new IntProperty(property); + } + + @Override + public net.minecraft.state.property.IntProperty getProperty() { + return property; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/state/property/UnknownProperty.java b/common/src/main/java/net/pitan76/mcpitanlib/api/state/property/UnknownProperty.java new file mode 100644 index 000000000..e59d0cad5 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/state/property/UnknownProperty.java @@ -0,0 +1,21 @@ +package net.pitan76.mcpitanlib.api.state.property; + +import net.minecraft.state.property.Property; + +public class UnknownProperty implements IProperty { + + private final net.minecraft.state.property.Property property; + + public UnknownProperty(net.minecraft.state.property.Property property) { + this.property = property; + } + + public static UnknownProperty of(net.minecraft.state.property.Property property) { + return new UnknownProperty(property); + } + + @Override + public Property getProperty() { + return property; + } +} diff --git a/common/src/main/java/ml/pkom/mcpitanlibarch/api/tag/MineableToolTags.java b/common/src/main/java/net/pitan76/mcpitanlib/api/tag/MineableToolTags.java similarity index 73% rename from common/src/main/java/ml/pkom/mcpitanlibarch/api/tag/MineableToolTags.java rename to common/src/main/java/net/pitan76/mcpitanlib/api/tag/MineableToolTags.java index 5f383d112..85aeaacf9 100644 --- a/common/src/main/java/ml/pkom/mcpitanlibarch/api/tag/MineableToolTags.java +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/tag/MineableToolTags.java @@ -1,4 +1,4 @@ -package ml.pkom.mcpitanlibarch.api.tag; +package net.pitan76.mcpitanlib.api.tag; public enum MineableToolTags { NONE, diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/tag/TagKey.java b/common/src/main/java/net/pitan76/mcpitanlib/api/tag/TagKey.java new file mode 100644 index 000000000..8c023e3a3 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/tag/TagKey.java @@ -0,0 +1,57 @@ +package net.pitan76.mcpitanlib.api.tag; + +import net.minecraft.block.Block; +import net.minecraft.entity.EntityType; +import net.minecraft.fluid.Fluid; +import net.minecraft.item.Item; +import net.minecraft.registry.RegistryKeys; +import net.minecraft.registry.entry.RegistryEntry; +import net.minecraft.util.Identifier; +import net.pitan76.mcpitanlib.api.util.*; + +public class TagKey { + private final net.minecraft.registry.tag.TagKey tagKey; + + @Deprecated + public TagKey(net.minecraft.registry.tag.TagKey tagKey) { + this.tagKey = tagKey; + } + + public static TagKey create(Type type, Identifier identifier) { + return switch (type) { + case BLOCK -> new TagKey<>(net.minecraft.registry.tag.TagKey.of(RegistryKeys.BLOCK, identifier)); + case ITEM -> new TagKey<>(net.minecraft.registry.tag.TagKey.of(RegistryKeys.ITEM, identifier)); + case FLUID -> new TagKey<>(net.minecraft.registry.tag.TagKey.of(RegistryKeys.FLUID, identifier)); + case ENTITY_TYPE -> new TagKey<>(net.minecraft.registry.tag.TagKey.of(RegistryKeys.ENTITY_TYPE, identifier)); + }; + } + + public static TagKey create(Type type, CompatIdentifier id) { + return create(type, id.toMinecraft()); + } + + @Deprecated + public net.minecraft.registry.tag.TagKey getTagKey() { + return tagKey; + } + + public enum Type { + BLOCK, + ITEM, + FLUID, + ENTITY_TYPE, + } + + public boolean isOf(T value) { + if (value instanceof Item) + return getTagKey() == net.minecraft.registry.tag.TagKey.of(RegistryKeys.ITEM, ItemUtil.toID((Item) value)); + if (value instanceof Block) + return getTagKey() == net.minecraft.registry.tag.TagKey.of(RegistryKeys.BLOCK, BlockUtil.toID((Block) value)); + if (value instanceof Fluid) + return getTagKey() == net.minecraft.registry.tag.TagKey.of(RegistryKeys.FLUID, FluidUtil.toID((Fluid) value)); + if (value instanceof EntityType) + return getTagKey() == net.minecraft.registry.tag.TagKey.of(RegistryKeys.ENTITY_TYPE, EntityTypeUtil.toID((EntityType) value)); + + return RegistryEntry.of(value).isIn(getTagKey()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/tag/item/RepairIngredientTag.java b/common/src/main/java/net/pitan76/mcpitanlib/api/tag/item/RepairIngredientTag.java new file mode 100644 index 000000000..1e4c1a482 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/tag/item/RepairIngredientTag.java @@ -0,0 +1,69 @@ +package net.pitan76.mcpitanlib.api.tag.item; + +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.recipe.Ingredient; +import net.minecraft.registry.RegistryKeys; +import net.minecraft.registry.tag.ItemTags; +import net.minecraft.registry.tag.TagKey; +import net.pitan76.mcpitanlib.MCPitanLib; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.api.util.IngredientUtil; +import net.pitan76.mcpitanlib.api.util.item.ItemUtil; + +public class RepairIngredientTag { + + public static final RepairIngredientTag REPAIRS_LEATHER_ARMOR = of("leather_armor_materials"); + public static final RepairIngredientTag REPAIRS_CHAIN_ARMOR = of("iron_tool_materials"); + public static final RepairIngredientTag REPAIRS_IRON_ARMOR = of("iron_tool_materials"); + public static final RepairIngredientTag REPAIRS_GOLD_ARMOR = of("golden_tool_materials"); + public static final RepairIngredientTag REPAIRS_DIAMOND_ARMOR = of("diamond_tool_materials"); + public static final RepairIngredientTag REPAIRS_NETHERITE_ARMOR = of("netherite_tool_materials"); + public static final RepairIngredientTag REPAIRS_TURTLE_HELMET = of("turtle_helmet_materials"); + public static final RepairIngredientTag REPAIRS_WOLF_ARMOR = of("leather_armor_materials"); + public static final RepairIngredientTag WOODEN_TOOL_MATERIALS = of("wooden_tool_materials"); + public static final RepairIngredientTag STONE_TOOL_MATERIALS = of("stone_tool_materials"); + public static final RepairIngredientTag IRON_TOOL_MATERIALS = of("iron_tool_materials"); + public static final RepairIngredientTag GOLDEN_TOOL_MATERIALS = of("golden_tool_materials"); + public static final RepairIngredientTag DIAMOND_TOOL_MATERIALS = of("diamond_tool_materials"); + public static final RepairIngredientTag NETHERITE_TOOL_MATERIALS = of("netherite_tool_materials"); + + private TagKey tag; + + protected static RepairIngredientTag of(String path) { + return new RepairIngredientTag(CompatIdentifier.of(MCPitanLib.MOD_ID, path)); + } + + public RepairIngredientTag(CompatIdentifier identifier) { + this.tag = TagKey.of(RegistryKeys.ITEM, identifier.toMinecraft()); + } + + @Deprecated + public RepairIngredientTag(TagKey tag) { + this.tag = tag; + } + + @Deprecated + public TagKey getTag() { + return tag; + } + + @Deprecated + public Ingredient getIngredient() { + return IngredientUtil.fromTagByIdentifier(tag.id()); + } + + public boolean contains(Item item) { + if (item == null || tag == null) + return false; + + return ItemUtil.isInTag(item, CompatIdentifier.fromMinecraft(tag.id())); + } + + public boolean contains(ItemStack stack) { + if (stack.isEmpty() || tag == null) + return false; + + return getIngredient().test(stack); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/tag/v2/CompatTagKey.java b/common/src/main/java/net/pitan76/mcpitanlib/api/tag/v2/CompatTagKey.java new file mode 100644 index 000000000..63f4df308 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/tag/v2/CompatTagKey.java @@ -0,0 +1,29 @@ +package net.pitan76.mcpitanlib.api.tag.v2; + +import net.minecraft.registry.entry.RegistryEntry; +import net.pitan76.mcpitanlib.api.tag.TagKey; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; + +public class CompatTagKey extends TagKey { + @Deprecated + public CompatTagKey(net.minecraft.registry.tag.TagKey tagKey) { + super(tagKey); + } + + @Deprecated + public static CompatTagKey of(net.minecraft.registry.tag.TagKey tagKey) { + return new CompatTagKey<>(tagKey); + } + + public static CompatTagKey of(CompatTagKeyType type, CompatIdentifier identifier) { + return of(net.minecraft.registry.tag.TagKey.of(type.getRegistryKey(), identifier.toMinecraft())); + } + + public boolean isOf(T value) { + return RegistryEntry.of(value).isIn(getTagKey()); + } + + public CompatIdentifier getId() { + return CompatIdentifier.fromMinecraft(getTagKey().id()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/tag/v2/CompatTagKeyType.java b/common/src/main/java/net/pitan76/mcpitanlib/api/tag/v2/CompatTagKeyType.java new file mode 100644 index 000000000..2a0dabc61 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/tag/v2/CompatTagKeyType.java @@ -0,0 +1,48 @@ +package net.pitan76.mcpitanlib.api.tag.v2; + +import net.minecraft.block.Block; +import net.minecraft.block.entity.BlockEntityType; +import net.minecraft.entity.EntityType; +import net.minecraft.fluid.Fluid; +import net.minecraft.item.Item; +import net.minecraft.registry.Registry; +import net.minecraft.registry.RegistryKey; +import net.minecraft.registry.RegistryKeys; +import net.minecraft.screen.ScreenHandlerType; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; + +public class CompatTagKeyType { + public static final CompatTagKeyType BLOCK = of(RegistryKeys.BLOCK); + public static final CompatTagKeyType ITEM = new CompatTagKeyType<>(RegistryKeys.ITEM); + public static final CompatTagKeyType FLUID = new CompatTagKeyType<>(RegistryKeys.FLUID); + public static final CompatTagKeyType> ENTITY_TYPE = new CompatTagKeyType<>(RegistryKeys.ENTITY_TYPE); + public static final CompatTagKeyType> BLOCK_ENTITY_TYPE = new CompatTagKeyType<>(RegistryKeys.BLOCK_ENTITY_TYPE); + public static final CompatTagKeyType> SCREEN_HANDLER = new CompatTagKeyType<>(RegistryKeys.SCREEN_HANDLER); + + public final CompatIdentifier id; + + protected CompatTagKeyType(CompatIdentifier id) { + this.id = id; + } + + public static CompatTagKeyType of(CompatIdentifier id) { + return new CompatTagKeyType<>(id); + } + + // RegistryKey + private RegistryKey> key; + + protected CompatTagKeyType(RegistryKey> key) { + this.id = CompatIdentifier.fromMinecraft(key.getRegistry()); + this.key = key; + } + + public static CompatTagKeyType of(RegistryKey> key) { + return new CompatTagKeyType<>(key); + } + + @Deprecated + public RegistryKey> getRegistryKey() { + return key; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/tag/v2/typed/BlockTagKey.java b/common/src/main/java/net/pitan76/mcpitanlib/api/tag/v2/typed/BlockTagKey.java new file mode 100644 index 000000000..382e101b8 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/tag/v2/typed/BlockTagKey.java @@ -0,0 +1,25 @@ +package net.pitan76.mcpitanlib.api.tag.v2.typed; + +import net.minecraft.block.Block; +import net.minecraft.registry.tag.TagKey; +import net.pitan76.mcpitanlib.api.tag.v2.CompatTagKey; +import net.pitan76.mcpitanlib.api.tag.v2.CompatTagKeyType; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.api.util.block.BlockUtil; + +import java.util.List; + +public class BlockTagKey extends CompatTagKey { + @Deprecated + public BlockTagKey(TagKey tagKey) { + super(tagKey); + } + + public static BlockTagKey of(CompatIdentifier identifier) { + return new BlockTagKey(TagKey.of(CompatTagKeyType.BLOCK.getRegistryKey(), identifier.toMinecraft())); + } + + public List values() { + return BlockUtil.getInTag(this); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/tag/v2/typed/EntityTagKey.java b/common/src/main/java/net/pitan76/mcpitanlib/api/tag/v2/typed/EntityTagKey.java new file mode 100644 index 000000000..61d57fee9 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/tag/v2/typed/EntityTagKey.java @@ -0,0 +1,20 @@ +package net.pitan76.mcpitanlib.api.tag.v2.typed; + +import net.minecraft.entity.EntityType; +import net.minecraft.registry.tag.TagKey; +import net.pitan76.mcpitanlib.api.tag.v2.CompatTagKey; +import net.pitan76.mcpitanlib.api.tag.v2.CompatTagKeyType; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; + +import java.util.List; + +public class EntityTagKey extends CompatTagKey> { + @Deprecated + public EntityTagKey(TagKey> tagKey) { + super(tagKey); + } + + public static EntityTagKey of(CompatIdentifier identifier) { + return new EntityTagKey(TagKey.of(CompatTagKeyType.ENTITY_TYPE.getRegistryKey(), identifier.toMinecraft())); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/tag/v2/typed/FluidTagKey.java b/common/src/main/java/net/pitan76/mcpitanlib/api/tag/v2/typed/FluidTagKey.java new file mode 100644 index 000000000..03cdeb507 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/tag/v2/typed/FluidTagKey.java @@ -0,0 +1,18 @@ +package net.pitan76.mcpitanlib.api.tag.v2.typed; + +import net.minecraft.fluid.Fluid; +import net.minecraft.registry.tag.TagKey; +import net.pitan76.mcpitanlib.api.tag.v2.CompatTagKey; +import net.pitan76.mcpitanlib.api.tag.v2.CompatTagKeyType; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; + +public class FluidTagKey extends CompatTagKey { + @Deprecated + public FluidTagKey(TagKey tagKey) { + super(tagKey); + } + + public static FluidTagKey of(CompatIdentifier identifier) { + return new FluidTagKey(TagKey.of(CompatTagKeyType.FLUID.getRegistryKey(), identifier.toMinecraft())); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/tag/v2/typed/ItemTagKey.java b/common/src/main/java/net/pitan76/mcpitanlib/api/tag/v2/typed/ItemTagKey.java new file mode 100644 index 000000000..cce0a7cb2 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/tag/v2/typed/ItemTagKey.java @@ -0,0 +1,31 @@ +package net.pitan76.mcpitanlib.api.tag.v2.typed; + +import net.minecraft.item.Item; +import net.minecraft.recipe.Ingredient; +import net.minecraft.registry.tag.TagKey; +import net.pitan76.mcpitanlib.api.tag.v2.CompatTagKey; +import net.pitan76.mcpitanlib.api.tag.v2.CompatTagKeyType; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.api.util.IngredientUtil; +import net.pitan76.mcpitanlib.api.util.item.ItemUtil; + +import java.util.List; + +public class ItemTagKey extends CompatTagKey { + @Deprecated + public ItemTagKey(TagKey tagKey) { + super(tagKey); + } + + public static ItemTagKey of(CompatIdentifier identifier) { + return new ItemTagKey(net.minecraft.registry.tag.TagKey.of(CompatTagKeyType.ITEM.getRegistryKey(), identifier.toMinecraft())); + } + + public Ingredient asIngredient() { + return IngredientUtil.fromTagByIdentifier(getTagKey().id()); + } + + public List values() { + return ItemUtil.getInTag(this); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/text/CompatFormatting.java b/common/src/main/java/net/pitan76/mcpitanlib/api/text/CompatFormatting.java new file mode 100644 index 000000000..1de5acf72 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/text/CompatFormatting.java @@ -0,0 +1,86 @@ +package net.pitan76.mcpitanlib.api.text; + +import net.minecraft.util.Formatting; +import net.pitan76.mcpitanlib.api.util.CompatStringIdentifiable; + +public class CompatFormatting implements CompatStringIdentifiable { + private final Formatting formatting; + + public static final CompatFormatting BLACK = of(Formatting.BLACK); + public static final CompatFormatting DARK_BLUE = of(Formatting.DARK_BLUE); + public static final CompatFormatting DARK_GREEN = of(Formatting.DARK_GREEN); + public static final CompatFormatting DARK_AQUA = of(Formatting.DARK_AQUA); + public static final CompatFormatting DARK_RED = of(Formatting.DARK_RED); + public static final CompatFormatting DARK_PURPLE = of(Formatting.DARK_PURPLE); + public static final CompatFormatting GOLD = of(Formatting.GOLD); + public static final CompatFormatting GRAY = of(Formatting.GRAY); + public static final CompatFormatting DARK_GRAY = of(Formatting.DARK_GRAY); + public static final CompatFormatting BLUE = of(Formatting.BLUE); + public static final CompatFormatting GREEN = of(Formatting.GREEN); + public static final CompatFormatting AQUA = of(Formatting.AQUA); + public static final CompatFormatting RED = of(Formatting.RED); + public static final CompatFormatting LIGHT_PURPLE = of(Formatting.LIGHT_PURPLE); + public static final CompatFormatting YELLOW = of(Formatting.YELLOW); + public static final CompatFormatting WHITE = of(Formatting.WHITE); + public static final CompatFormatting OBFUSCATED = of(Formatting.OBFUSCATED); + public static final CompatFormatting BOLD = of(Formatting.BOLD); + public static final CompatFormatting STRIKETHROUGH = of(Formatting.STRIKETHROUGH); + public static final CompatFormatting UNDERLINE = of(Formatting.UNDERLINE); + public static final CompatFormatting ITALIC = of(Formatting.ITALIC); + public static final CompatFormatting RESET = of(Formatting.RESET); + + public CompatFormatting(Formatting formatting) { + this.formatting = formatting; + } + + public static CompatFormatting of(Formatting formatting) { + return new CompatFormatting(formatting); + } + + public Formatting getRaw() { + return formatting; + } + + @Override + public String asString_compat() { + return formatting.asString(); + } + + public boolean isColor() { + return formatting.isColor(); + } + + public boolean isModifier() { + return formatting.isModifier(); + } + + public char getCode() { + return formatting.getCode(); + } + + public Integer getColorValue() { + return formatting.getColorValue(); + } + + public int getColorIndex() { + return formatting.getColorIndex(); + } + + @Override + public String toString() { + return formatting.toString(); + } + + @Override + public int hashCode() { + return formatting.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + CompatFormatting other = (CompatFormatting) obj; + return formatting.equals(other.formatting); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/text/CompatStyle.java b/common/src/main/java/net/pitan76/mcpitanlib/api/text/CompatStyle.java new file mode 100644 index 000000000..43b9aee73 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/text/CompatStyle.java @@ -0,0 +1,105 @@ +package net.pitan76.mcpitanlib.api.text; + +import net.minecraft.text.Style; + +public class CompatStyle { + private final Style style; + + public CompatStyle(Style style) { + this.style = style; + } + + public CompatStyle() { + this(Style.EMPTY); + } + + public static CompatStyle of(Style style) { + return new CompatStyle(style); + } + + public static CompatStyle of() { + return new CompatStyle(); + } + + public CompatStyle withColor(CompatTextColor color) { + return new CompatStyle(style.withColor(color.getRaw())); + } + + public CompatStyle withColor(CompatFormatting formatting) { + return new CompatStyle(style.withColor(formatting.getRaw())); + } + + public CompatStyle withColor(int rgbColor) { + return new CompatStyle(style.withColor(rgbColor)); + } + + public CompatStyle withBold(boolean bold) { + return new CompatStyle(style.withBold(bold)); + } + + public CompatStyle withItalic(boolean italic) { + return new CompatStyle(style.withItalic(italic)); + } + + public CompatStyle withUnderline(boolean underline) { + return new CompatStyle(style.withUnderline(underline)); + } + + public CompatStyle withStrikethrough(boolean strikethrough) { + return new CompatStyle(style.withStrikethrough(strikethrough)); + } + + public CompatStyle withObfuscated(boolean obfuscated) { + return new CompatStyle(style.withObfuscated(obfuscated)); + } + + public CompatTextColor getColor() { + if (style.getColor() == null) return null; + return new CompatTextColor(style.getColor()); + } + + public boolean isBold() { + return style.isBold(); + } + + public boolean isItalic() { + return style.isItalic(); + } + + public boolean isUnderlined() { + return style.isUnderlined(); + } + + public boolean isStrikethrough() { + return style.isStrikethrough(); + } + + public boolean isObfuscated() { + return style.isObfuscated(); + } + + public boolean isEmpty() { + return style.isEmpty(); + } + + public CompatStyle withFormatting(CompatFormatting formatting) { + return withColor(formatting); + } + + public Style getRaw() { + return style; + } + + @Override + public int hashCode() { + return style.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + CompatStyle that = (CompatStyle) obj; + return style.equals(that.style); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/text/CompatTextColor.java b/common/src/main/java/net/pitan76/mcpitanlib/api/text/CompatTextColor.java new file mode 100644 index 000000000..306034382 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/text/CompatTextColor.java @@ -0,0 +1,79 @@ +package net.pitan76.mcpitanlib.api.text; + +import net.minecraft.text.TextColor; +import net.minecraft.util.Formatting; + +public class CompatTextColor { + private final TextColor textColor; + + public static final CompatTextColor BLACK = of(TextColor.fromFormatting(Formatting.BLACK)); + public static final CompatTextColor DARK_BLUE = of(TextColor.fromFormatting(Formatting.DARK_BLUE)); + public static final CompatTextColor DARK_GREEN = of(TextColor.fromFormatting(Formatting.DARK_GREEN)); + public static final CompatTextColor DARK_AQUA = of(TextColor.fromFormatting(Formatting.DARK_AQUA)); + public static final CompatTextColor DARK_RED = of(TextColor.fromFormatting(Formatting.DARK_RED)); + public static final CompatTextColor DARK_PURPLE = of(TextColor.fromFormatting(Formatting.DARK_PURPLE)); + public static final CompatTextColor GOLD = of(TextColor.fromFormatting(Formatting.GOLD)); + public static final CompatTextColor GRAY = of(TextColor.fromFormatting(Formatting.GRAY)); + public static final CompatTextColor DARK_GRAY = of(TextColor.fromFormatting(Formatting.DARK_GRAY)); + public static final CompatTextColor BLUE = of(TextColor.fromFormatting(Formatting.BLUE)); + public static final CompatTextColor GREEN = of(TextColor.fromFormatting(Formatting.GREEN)); + public static final CompatTextColor AQUA = of(TextColor.fromFormatting(Formatting.AQUA)); + public static final CompatTextColor RED = of(TextColor.fromFormatting(Formatting.RED)); + public static final CompatTextColor LIGHT_PURPLE = of(TextColor.fromFormatting(Formatting.LIGHT_PURPLE)); + public static final CompatTextColor YELLOW = of(TextColor.fromFormatting(Formatting.YELLOW)); + public static final CompatTextColor WHITE = of(TextColor.fromFormatting(Formatting.WHITE)); + + public CompatTextColor(TextColor textColor) { + this.textColor = textColor; + } + + public TextColor getRaw() { + return textColor; + } + + public static CompatTextColor of(TextColor textColor) { + return new CompatTextColor(textColor); + } + + public static CompatTextColor fromFormatting(Formatting formatting) { + return new CompatTextColor(TextColor.fromFormatting(formatting)); + } + + public static CompatTextColor fromFormatting(CompatFormatting formatting) { + return fromFormatting(formatting.getRaw()); + } + + public static CompatTextColor fromRgb(int rgb) { + return new CompatTextColor(TextColor.fromRgb(rgb)); + } + + public static CompatTextColor fromRgb(int r, int g, int b) { + int rgb = (r << 16) | (g << 8) | b; + return fromRgb(rgb); + } + + public static CompatTextColor parse(String string) { + try { + return parseOrThrow(string); + } catch (Exception e) { + return null; + } + } + + public static CompatTextColor parseOrThrow(String string) { + return new CompatTextColor(TextColor.parse(string).getOrThrow()); + } + + @Override + public int hashCode() { + return textColor.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + CompatTextColor other = (CompatTextColor) obj; + return textColor.equals(other.textColor); + } +} diff --git a/common/src/main/java/ml/pkom/mcpitanlibarch/api/text/TextComponent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/text/TextComponent.java similarity index 52% rename from common/src/main/java/ml/pkom/mcpitanlibarch/api/text/TextComponent.java rename to common/src/main/java/net/pitan76/mcpitanlib/api/text/TextComponent.java index f7c701f5a..08ee2e869 100644 --- a/common/src/main/java/ml/pkom/mcpitanlibarch/api/text/TextComponent.java +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/text/TextComponent.java @@ -1,10 +1,10 @@ -package ml.pkom.mcpitanlibarch.api.text; +package net.pitan76.mcpitanlib.api.text; -import ml.pkom.mcpitanlibarch.api.util.TextUtil; import net.minecraft.text.MutableText; +import net.minecraft.text.Style; import net.minecraft.text.Text; - -import javax.annotation.Nullable; +import net.pitan76.mcpitanlib.api.util.TextUtil; +import org.jetbrains.annotations.Nullable; public class TextComponent { @@ -62,6 +62,14 @@ public static TextComponent translatable(String key, Object... args) { return new TextComponent(TextUtil.translatable(key, args)); } + public static TextComponent empty() { + return new TextComponent(TextUtil.empty()); + } + + public static TextComponent format(String format, Object... args) { + return literal(String.format(format, args)); + } + @Override public String toString() { return getString(); @@ -78,4 +86,45 @@ public String superToString() { public TextComponent copy() { return new TextComponent(getText()); } + + public Style getStyle() { + return text.getStyle(); + } + + public TextComponent setStyle(Style style) { + if (text instanceof MutableText) + TextUtil.setStyle((MutableText) text, style); + + return this; + } + + public TextComponent setStyle(CompatStyle style) { + return setStyle(style.getRaw()); + } + + public CompatStyle getCompatStyle() { + return CompatStyle.of(getStyle()); + } + + public boolean contains(TextComponent other) { + return TextUtil.contains(getText(), other.getText()); + } + + /** + * Convert string to TextComponent with formatting + * @param text String + * @return TextComponent + */ + public static TextComponent convert(String text) { + return new TextComponent(TextUtil.convert(text)); + } + + /** + * Convert string to TextComponent with translatable + * @param text String + * @return TextComponent + */ + public static TextComponent convertWithTranslatable(String text) { + return new TextComponent(TextUtil.convertWithTranslatable(text)); + } } \ No newline at end of file diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/text/TextConverter.java b/common/src/main/java/net/pitan76/mcpitanlib/api/text/TextConverter.java new file mode 100644 index 000000000..85836c4f8 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/text/TextConverter.java @@ -0,0 +1,102 @@ +package net.pitan76.mcpitanlib.api.text; + +import net.minecraft.text.MutableText; +import net.minecraft.text.Text; +import net.minecraft.util.Formatting; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class TextConverter { + + public static MutableText convert(String string) { + return convert(string, false); + } + + /** + * Convert string to MutableText with formatting + * + * @param text String + * @param translatable boolean + * @return MutableText + */ + public static MutableText convert(String text, boolean translatable) { + String[] splits = split(text); + MutableText result = Text.literal(""); + Formatting[] currentFormatting = {}; + + for (String part : splits) { + // Section + if (part.startsWith("§") && part.length() == 2) { + char code = part.charAt(1); + // Reset + if (code == 'r') { + currentFormatting = new Formatting[]{}; + continue; + } + + Formatting format = Formatting.byCode(code); + if (format == null) + continue; + + // Bold, Italic, Underline, Strikethrough, Obfuscated + if (code >= 'k' && code <= 'o') { + ArrayList list = new ArrayList<>(Arrays.asList(currentFormatting)); + list.add(format); + currentFormatting = list.toArray(new Formatting[0]); + continue; + } + + // Color + currentFormatting = new Formatting[]{format}; + continue; + } + + // Translatable + if (translatable) { + Pattern pattern = Pattern.compile("\\{(.+?)\\}"); + Matcher matcher = pattern.matcher(part); + MutableText tempText = Text.literal(""); + int lastIndex = 0; + + while (matcher.find()) { + // {translatable key} より前の文字列を追加 + if (matcher.start() > lastIndex) { + tempText.append(Text.literal(part.substring(lastIndex, matcher.start())).formatted(currentFormatting)); + } + + // {translatable key} を追加 + String key = matcher.group(1); + tempText.append(Text.translatable(key).formatted(currentFormatting)); + + lastIndex = matcher.end(); + } + + // 最後の文字列を追加 + if (lastIndex < part.length()) { + tempText.append(Text.literal(part.substring(lastIndex)).formatted(currentFormatting)); + } + + result.append(tempText); + continue; + } + + result.append(Text.literal(part).formatted(currentFormatting)); + } + + return result; + } + + public static String[] split(String text) { + Matcher matcher = Pattern.compile("(?i)§[0-9a-fk-or]|[^§]+").matcher(text); + List parts = new ArrayList<>(); + + while (matcher.find()) + parts.add(matcher.group()); + + return parts.toArray(new String[0]); + } +} diff --git a/common/src/main/java/ml/pkom/mcpitanlibarch/api/text/VariableTextComponent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/text/VariableTextComponent.java similarity index 82% rename from common/src/main/java/ml/pkom/mcpitanlibarch/api/text/VariableTextComponent.java rename to common/src/main/java/net/pitan76/mcpitanlib/api/text/VariableTextComponent.java index fd3905b7c..b231f4071 100644 --- a/common/src/main/java/ml/pkom/mcpitanlibarch/api/text/VariableTextComponent.java +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/text/VariableTextComponent.java @@ -1,6 +1,6 @@ -package ml.pkom.mcpitanlibarch.api.text; +package net.pitan76.mcpitanlib.api.text; -import ml.pkom.mcpitanlibarch.api.util.TextUtil; +import net.pitan76.mcpitanlib.api.util.TextUtil; // 可変TextComponent public class VariableTextComponent extends TextComponent { diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/tile/BlockEntityTypeBuilder.java b/common/src/main/java/net/pitan76/mcpitanlib/api/tile/BlockEntityTypeBuilder.java new file mode 100644 index 000000000..f70657be2 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/tile/BlockEntityTypeBuilder.java @@ -0,0 +1,59 @@ +package net.pitan76.mcpitanlib.api.tile; + +import com.mojang.datafixers.types.Type; +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.block.entity.BlockEntityType; +import net.minecraft.util.math.BlockPos; +import net.pitan76.mcpitanlib.api.event.block.TileCreateEvent; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class BlockEntityTypeBuilder { + private final Factory factory; + private final List blocks; + + public BlockEntityTypeBuilder(Factory factory, List blocks) { + this.factory = factory; + this.blocks = blocks; + } + + public static BlockEntityTypeBuilder create(Factory factory, Block... blocks) { + List blocksList = new ArrayList<>(blocks.length); + Collections.addAll(blocksList, blocks); + + return new BlockEntityTypeBuilder<>(factory, blocksList); + } + + public BlockEntityTypeBuilder addBlock(Block block) { + this.blocks.add(block); + return this; + } + + public BlockEntityTypeBuilder addBlocks(Block... blocks) { + Collections.addAll(this.blocks, blocks); + return this; + } + + + public BlockEntityType build() { + return build(null); + } + + public BlockEntityType build(Type type) { + return BlockEntityType.Builder.create(factory::create, blocks.toArray(new Block[0])).build(type); + } + + @FunctionalInterface + public interface Factory { + T create(TileCreateEvent event); + + @Deprecated + default T create(BlockPos pos, BlockState state) { + return create(new TileCreateEvent(pos, state)); + } + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/tile/CompatBlockEntity.java b/common/src/main/java/net/pitan76/mcpitanlib/api/tile/CompatBlockEntity.java new file mode 100644 index 000000000..60b7fac3a --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/tile/CompatBlockEntity.java @@ -0,0 +1,182 @@ +package net.pitan76.mcpitanlib.api.tile; + +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.registry.RegistryWrapper; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.event.block.TileCreateEvent; +import net.pitan76.mcpitanlib.api.event.nbt.ReadNbtArgs; +import net.pitan76.mcpitanlib.api.event.nbt.WriteNbtArgs; +import net.pitan76.mcpitanlib.api.packet.UpdatePacketType; +import net.pitan76.mcpitanlib.api.registry.CompatRegistryLookup; +import net.pitan76.mcpitanlib.api.util.BlockEntityUtil; +import net.pitan76.mcpitanlib.api.util.WorldUtil; +import org.jetbrains.annotations.Nullable; + +public class CompatBlockEntity extends BlockEntity { + public CompatBlockEntity(BlockEntityType type, BlockPos pos, BlockState state) { + super(type, pos, state); + } + + public CompatBlockEntity(BlockEntityType type, TileCreateEvent event) { + this(type, event.getBlockPos(), event.getBlockState()); + } + + @Nullable + @Override + @Deprecated + public Packet toUpdatePacket() { + switch (getUpdatePacketType().name) { + case "BLOCK_ENTITY_UPDATE_S2C": + return BlockEntityUpdateS2CPacket.create(this); + } + return super.toUpdatePacket(); + } + + public UpdatePacketType getUpdatePacketType() { + return UpdatePacketType.NONE; + } + + public void writeNbt(WriteNbtArgs args) { + + } + + public void readNbt(ReadNbtArgs args) { + + } + + public NbtCompound toInitialChunkDataNbt(CompatRegistryLookup registryLookup) { + return super.toInitialChunkDataNbt(registryLookup.getRegistryLookup()); + } + + @Deprecated + @Override + public NbtCompound toInitialChunkDataNbt(RegistryWrapper.WrapperLookup registries) { + return toInitialChunkDataNbt(new CompatRegistryLookup(registries)); + } + + // deprecated + + /** + * @deprecated Use {@link #writeNbt(WriteNbtArgs)} instead + */ + @Deprecated + public void writeNbtOverride(NbtCompound nbt) { + super.writeNbt(nbt, wrapperLookupCache); + } + + /** + * @deprecated Use {@link #readNbt(ReadNbtArgs)} instead + */ + @Deprecated + public void readNbtOverride(NbtCompound nbt) { + super.readNbt(nbt, wrapperLookupCache); + } + + @Deprecated + private RegistryWrapper.WrapperLookup wrapperLookupCache; + + // ---- + + @Deprecated + @Override + public void writeNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup registryLookup) { + // deprecated + wrapperLookupCache = registryLookup; + writeNbtOverride(nbt); + // ---- + + writeNbt(new WriteNbtArgs(nbt, registryLookup)); + } + + @Deprecated + @Override + public void readNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup registryLookup) { + // deprecated + wrapperLookupCache = registryLookup; + readNbtOverride(nbt); + // ---- + + readNbt(new ReadNbtArgs(nbt, registryLookup)); + } + + public boolean isClient() { + if (getWorld() == null) + return false; + + return WorldUtil.isClient(getWorld()); + } + + @Deprecated + @Override + public @Nullable World getWorld() { + return callGetWorld(); + } + + @Deprecated + @Override + public BlockPos getPos() { + return callGetPos(); + } + + public World callGetWorld() { + return super.getWorld(); + } + + public BlockPos callGetPos() { + return super.getPos(); + } + + public BlockState callGetBlockState() { + return BlockEntityUtil.getBlockState(this); + } + + public BlockState callGetCachedState() { + return BlockEntityUtil.getCachedState(this); + } + + public boolean hasServerWorld() { + return callGetWorld() instanceof ServerWorld; + } + + public ServerWorld getServerWorld() { + return BlockEntityUtil.getServerWorld(this); + } + + public void callMarkDirty() { + BlockEntityUtil.markDirty(this); + } + + @Deprecated + @Override + public void markRemoved() { + markRemovedOverride(); + } + + public void markRemovedOverride() { + super.markRemoved(); + } + + public net.pitan76.mcpitanlib.midohra.world.World getMidohraWorld() { + return net.pitan76.mcpitanlib.midohra.world.World.of(callGetWorld()); + } + + public net.pitan76.mcpitanlib.midohra.util.math.BlockPos getMidohraPos() { + return net.pitan76.mcpitanlib.midohra.util.math.BlockPos.of(callGetPos()); + } + + public net.pitan76.mcpitanlib.midohra.block.BlockState getMidohraBlockState() { + return net.pitan76.mcpitanlib.midohra.block.BlockState.of(callGetBlockState()); + } + + public net.pitan76.mcpitanlib.midohra.block.BlockState getMidohraCachedState() { + return net.pitan76.mcpitanlib.midohra.block.BlockState.of(callGetCachedState()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/tile/CompatChestBlockEntity.java b/common/src/main/java/net/pitan76/mcpitanlib/api/tile/CompatChestBlockEntity.java new file mode 100644 index 000000000..70bde7cea --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/tile/CompatChestBlockEntity.java @@ -0,0 +1,96 @@ +package net.pitan76.mcpitanlib.api.tile; + +import net.minecraft.block.BlockState; +import net.minecraft.block.entity.BlockEntityType; +import net.minecraft.block.entity.ChestBlockEntity; +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.registry.RegistryWrapper; +import net.minecraft.util.math.BlockPos; +import net.pitan76.mcpitanlib.api.event.block.TileCreateEvent; +import net.pitan76.mcpitanlib.api.event.nbt.ReadNbtArgs; +import net.pitan76.mcpitanlib.api.event.nbt.WriteNbtArgs; +import net.pitan76.mcpitanlib.api.packet.UpdatePacketType; +import org.jetbrains.annotations.Nullable; + +public class CompatChestBlockEntity extends ChestBlockEntity { + protected CompatChestBlockEntity(BlockEntityType blockEntityType, BlockPos blockPos, BlockState blockState) { + super(blockEntityType, blockPos, blockState); + } + + public CompatChestBlockEntity(BlockEntityType type, TileCreateEvent event) { + this(type, event.getBlockPos(), event.getBlockState()); + } + + @Nullable + @Override + @Deprecated + public Packet toUpdatePacket() { + switch (getUpdatePacketType().name) { + case "BLOCK_ENTITY_UPDATE_S2C": + return BlockEntityUpdateS2CPacket.create(this); + } + return super.toUpdatePacket(); + } + + public UpdatePacketType getUpdatePacketType() { + return UpdatePacketType.NONE; + } + + public void writeNbt(WriteNbtArgs args) { + + } + + public void readNbt(ReadNbtArgs args) { + + } + + + // deprecated + + /** + * @deprecated Use {@link #writeNbt(WriteNbtArgs)} instead + */ + @Deprecated + public void writeNbtOverride(NbtCompound nbt) { + super.writeNbt(nbt, wrapperLookupCache); + } + + /** + * @deprecated Use {@link #readNbt(ReadNbtArgs)} instead + */ + @Deprecated + public void readNbtOverride(NbtCompound nbt) { + super.readNbt(nbt, wrapperLookupCache); + } + + @Deprecated + private RegistryWrapper.WrapperLookup wrapperLookupCache; + + // ---- + + @Deprecated + @Override + public void writeNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup registryLookup) { + // deprecated + wrapperLookupCache = registryLookup; + writeNbtOverride(nbt); + // ---- + + writeNbt(new WriteNbtArgs(nbt, registryLookup)); + } + + @Deprecated + @Override + public void readNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup registryLookup) { + // deprecated + wrapperLookupCache = registryLookup; + readNbtOverride(nbt); + // ---- + + readNbt(new ReadNbtArgs(nbt, registryLookup)); + } + +} \ No newline at end of file diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/tile/ExtendBlockEntity.java b/common/src/main/java/net/pitan76/mcpitanlib/api/tile/ExtendBlockEntity.java new file mode 100644 index 000000000..01ea4f2e2 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/tile/ExtendBlockEntity.java @@ -0,0 +1,26 @@ +package net.pitan76.mcpitanlib.api.tile; + +import net.minecraft.block.BlockState; +import net.minecraft.block.entity.BlockEntityType; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.event.block.TileCreateEvent; +import net.pitan76.mcpitanlib.api.world.ExtendWorld; + +public class ExtendBlockEntity extends CompatBlockEntity { + public ExtendWorld world; + + public ExtendBlockEntity(BlockEntityType type, BlockPos pos, BlockState state) { + super(type, pos, state); + } + + public ExtendBlockEntity(BlockEntityType type, TileCreateEvent event) { + this(type, event.getBlockPos(), event.getBlockState()); + } + + @Override + public void setWorld(World world) { + super.setWorld(world); + this.world = new ExtendWorld(world); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/tile/ExtendBlockEntityTicker.java b/common/src/main/java/net/pitan76/mcpitanlib/api/tile/ExtendBlockEntityTicker.java new file mode 100644 index 000000000..8bce6ee96 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/tile/ExtendBlockEntityTicker.java @@ -0,0 +1,17 @@ +package net.pitan76.mcpitanlib.api.tile; + +import net.minecraft.block.BlockState; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.block.entity.BlockEntityTicker; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.event.tile.TileTickEvent; + +public interface ExtendBlockEntityTicker extends BlockEntityTicker { + @Override + default void tick(World world, BlockPos pos, BlockState state, T blockEntity) { + tick(new TileTickEvent<>(world, pos, state, blockEntity)); + } + + void tick(TileTickEvent event); +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/tile/RenderDataBlockEntity.java b/common/src/main/java/net/pitan76/mcpitanlib/api/tile/RenderDataBlockEntity.java new file mode 100644 index 000000000..4ce375ada --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/tile/RenderDataBlockEntity.java @@ -0,0 +1,14 @@ +package net.pitan76.mcpitanlib.api.tile; + +import org.jetbrains.annotations.Nullable; + +@Deprecated +public interface RenderDataBlockEntity { + + @Nullable + Object getCompatRenderData(); + + default boolean hasCompatRenderData() { + return getCompatRenderData() != null; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/tile/v2/BlockEntityTypeBuilder.java b/common/src/main/java/net/pitan76/mcpitanlib/api/tile/v2/BlockEntityTypeBuilder.java new file mode 100644 index 000000000..b2c0b1a98 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/tile/v2/BlockEntityTypeBuilder.java @@ -0,0 +1,69 @@ +package net.pitan76.mcpitanlib.api.tile.v2; + +import com.mojang.datafixers.types.Type; +import net.minecraft.block.Block; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.block.entity.BlockEntityType; +import net.pitan76.mcpitanlib.midohra.block.SupplierBlockWrapper; + +import java.util.ArrayList; +import java.util.List; +import java.util.function.Consumer; +import java.util.function.Supplier; + +public class BlockEntityTypeBuilder extends net.pitan76.mcpitanlib.api.tile.BlockEntityTypeBuilder { + private final Factory factory; + private final Consumer> consumer; + + public BlockEntityTypeBuilder(Factory factory, Consumer> blocks) { + super(null, null); + + this.factory = factory; + this.consumer = blocks; + } + + @Deprecated + public static BlockEntityTypeBuilder create(Factory factory, Block... blocks) { + throw new IllegalStateException("Use create(Factory, Consumer>) instead"); + } + + public static BlockEntityTypeBuilder create(BlockEntityTypeBuilder.Factory factory, Consumer> blocks) { + return new BlockEntityTypeBuilder<>(factory, blocks); + } + + public static BlockEntityTypeBuilder createA(BlockEntityTypeBuilder.Factory factory, Supplier block) { + return new BlockEntityTypeBuilder<>(factory, blocks -> { + blocks.add(block.get()); + }); + } + + public static BlockEntityTypeBuilder create(BlockEntityTypeBuilder.Factory factory, SupplierBlockWrapper wrapper) { + return new BlockEntityTypeBuilder<>(factory, blocks -> { + blocks.add(wrapper.get()); + }); + } + + @Override + @Deprecated + public BlockEntityTypeBuilder addBlock(Block block) { + return this; + } + + @Override + @Deprecated + public BlockEntityTypeBuilder addBlocks(Block... blocks) { + return this; + } + + public BlockEntityType build() { + return build(null); + } + + public BlockEntityType build(Type type) { + List blocks = new ArrayList<>(); + if (consumer != null) + consumer.accept(blocks); + + return BlockEntityType.Builder.create(factory::create, blocks.toArray(new Block[0])).build(type); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/timer/MinecraftServerTimerAccess.java b/common/src/main/java/net/pitan76/mcpitanlib/api/timer/MinecraftServerTimerAccess.java new file mode 100644 index 000000000..58e042b3e --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/timer/MinecraftServerTimerAccess.java @@ -0,0 +1,7 @@ +package net.pitan76.mcpitanlib.api.timer; + +import java.util.function.Supplier; + +public interface MinecraftServerTimerAccess { + void mcpitanlib$addTimer(long ticksUntilSomething, Supplier supplier); +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/timer/ServerWorldTimerAccess.java b/common/src/main/java/net/pitan76/mcpitanlib/api/timer/ServerWorldTimerAccess.java new file mode 100644 index 000000000..8dbd2dc14 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/timer/ServerWorldTimerAccess.java @@ -0,0 +1,7 @@ +package net.pitan76.mcpitanlib.api.timer; + +import java.util.function.Supplier; + +public interface ServerWorldTimerAccess { + void mcpitanlib$addTimer(long ticksUntilSomething, Supplier supplier); +} \ No newline at end of file diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/timer/TimerItem.java b/common/src/main/java/net/pitan76/mcpitanlib/api/timer/TimerItem.java new file mode 100644 index 000000000..ecf00fc80 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/timer/TimerItem.java @@ -0,0 +1,14 @@ +package net.pitan76.mcpitanlib.api.timer; + +import java.util.function.Supplier; + +public class TimerItem { + public long ticksUntilSomething; + + public Supplier executeSupplier; + + public TimerItem(long ticksUntilSomething, Supplier executeSupplier) { + this.ticksUntilSomething = ticksUntilSomething; + this.executeSupplier = executeSupplier; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/transfer/fluid/v1/FluidStorageUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/transfer/fluid/v1/FluidStorageUtil.java new file mode 100644 index 000000000..0576fca2f --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/transfer/fluid/v1/FluidStorageUtil.java @@ -0,0 +1,16 @@ +package net.pitan76.mcpitanlib.api.transfer.fluid.v1; + +import dev.architectury.injectables.annotations.ExpectPlatform; +import net.minecraft.fluid.Fluid; + +public class FluidStorageUtil { + @ExpectPlatform + public static IFluidStorage withFixedCapacity(long capacity, Runnable onChange) { + throw new AssertionError(); + } + + @ExpectPlatform + public static IFluidVariant getVariant(Fluid fluid) { + throw new AssertionError(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/transfer/fluid/v1/IFluidStorage.java b/common/src/main/java/net/pitan76/mcpitanlib/api/transfer/fluid/v1/IFluidStorage.java new file mode 100644 index 000000000..f239e8608 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/transfer/fluid/v1/IFluidStorage.java @@ -0,0 +1,104 @@ +package net.pitan76.mcpitanlib.api.transfer.fluid.v1; + +import net.minecraft.fluid.Fluid; +import net.minecraft.fluid.FluidState; +import net.minecraft.nbt.NbtCompound; +import net.pitan76.mcpitanlib.api.event.nbt.ReadNbtArgs; +import net.pitan76.mcpitanlib.api.event.nbt.WriteNbtArgs; +import net.pitan76.mcpitanlib.api.registry.CompatRegistryLookup; +import net.pitan76.mcpitanlib.midohra.fluid.FluidWrapper; + +public interface IFluidStorage { + long getAmount(); + + long getCapacity(); + + IFluidVariant getResource(); + + void setResource(IFluidVariant variant); + + long insert(IFluidVariant variant, long maxAmount, boolean simulate); + + long extract(IFluidVariant variant, long maxAmount, boolean simulate); + + void writeNbt(WriteNbtArgs args); + + void readNbt(ReadNbtArgs args); + + default void readNbt(WriteNbtArgs args) { + readNbt(new ReadNbtArgs(args.getNbt(), args.getWrapperLookup())); + } + + default long insert(IFluidVariant variant, long maxAmount) { + return insert(variant, maxAmount, false); + } + + default long extract(IFluidVariant variant, long maxAmount) { + return extract(variant, maxAmount, false); + } + + default long insert(Fluid fluid, long maxAmount) { + return insert(FluidStorageUtil.getVariant(fluid), maxAmount); + } + + default long extract(Fluid fluid, long maxAmount) { + return extract(FluidStorageUtil.getVariant(fluid), maxAmount); + } + + default long insert(FluidWrapper wrapper, long maxAmount) { + return insert(wrapper.get(), maxAmount); + } + + default long extract(FluidWrapper wrapper, long maxAmount) { + return extract(wrapper.get(), maxAmount); + } + + default boolean isResourceBlank() { + return getResource() == null || getAmount() <= 0; + } + + default boolean isResource(IFluidVariant variant) { + return getResource() == variant; + } + + default boolean isEmpty() { + return getAmount() <= 0; + } + + default boolean isFull() { + return getAmount() >= getCapacity(); + } + + default boolean canInsert(IFluidVariant variant, long amount) { + return insert(variant, amount, true) == amount; + } + + default boolean canExtract(IFluidVariant variant, long amount) { + return extract(variant, amount, true) == amount; + } + + default boolean canInsert(Fluid fluid, long amount) { + return canInsert(FluidStorageUtil.getVariant(fluid), amount); + } + + default boolean canExtract(Fluid fluid, long amount) { + return canExtract(FluidStorageUtil.getVariant(fluid), amount); + } + + default boolean canInsert(FluidWrapper wrapper, long amount) { + return canInsert(wrapper.get(), amount); + } + + default boolean canExtract(FluidWrapper wrapper, long amount) { + return canExtract(wrapper.get(), amount); + } + + default void writeNbt(NbtCompound nbt, CompatRegistryLookup registryLookup) { + writeNbt(new WriteNbtArgs(nbt, registryLookup)); + } + + default void readNbt(NbtCompound nbt, CompatRegistryLookup registryLookup) { + readNbt(new WriteNbtArgs(nbt, registryLookup)); + } + +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/transfer/fluid/v1/IFluidVariant.java b/common/src/main/java/net/pitan76/mcpitanlib/api/transfer/fluid/v1/IFluidVariant.java new file mode 100644 index 000000000..cc78339a4 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/transfer/fluid/v1/IFluidVariant.java @@ -0,0 +1,29 @@ +package net.pitan76.mcpitanlib.api.transfer.fluid.v1; + +import net.minecraft.fluid.Fluid; +import net.minecraft.fluid.Fluids; +import net.pitan76.mcpitanlib.midohra.fluid.FluidWrapper; + +public interface IFluidVariant { + Fluid getFluid(); + + default FluidWrapper getWrapper() { + return FluidWrapper.of(getFluid()); + } + + default boolean isSame(IFluidVariant variant) { + return getFluid() == variant.getFluid(); + } + + default boolean isSame(Fluid fluid) { + return getFluid() == fluid; + } + + default boolean isBlank() { + return getFluid() == null || getFluid() == Fluids.EMPTY; + } + + static IFluidVariant of(Fluid fluid) { + return FluidStorageUtil.getVariant(fluid); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/ArmorMaterialUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/ArmorMaterialUtil.java new file mode 100644 index 000000000..17dda5fe0 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/ArmorMaterialUtil.java @@ -0,0 +1,138 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.recipe.Ingredient; +import net.minecraft.sound.SoundEvent; +import net.minecraft.util.Identifier; +import net.pitan76.mcpitanlib.api.item.ArmorEquipmentType; +import net.pitan76.mcpitanlib.api.item.CompatibleArmorMaterial; + +public class ArmorMaterialUtil { + public static CompatibleArmorMaterial create(String name, int[] durability, int[] protectionAmounts, int enchantability, SoundEvent equipSound, float toughness, float knockbackResistance, Ingredient repairIngredient) { + return create(IdentifierUtil.id(name), durability, protectionAmounts, enchantability, equipSound, toughness, knockbackResistance, repairIngredient); + } + public static CompatibleArmorMaterial create(String name, int durability, int protectionAmount, int enchantability, SoundEvent equipSound, float toughness, float knockbackResistance, Ingredient repairIngredient) { + return create(IdentifierUtil.id(name), durability, protectionAmount, enchantability, equipSound, toughness, knockbackResistance, repairIngredient); + } + + @Deprecated + public static CompatibleArmorMaterial create(Identifier id, int[] durability, int[] protectionAmounts, int enchantability, SoundEvent equipSound, float toughness, float knockbackResistance, Ingredient repairIngredient) { + return new CompatibleArmorMaterial() { + @Override + public int getDurability(ArmorEquipmentType type) { + switch (type.getSlot()) { + case HEAD -> { + return durability[0]; + } + case CHEST -> { + return durability[1]; + } + case LEGS -> { + return durability[2]; + } + case FEET -> { + return durability[3]; + } + default -> { + return 0; + } + } + } + + @Override + public int getProtection(ArmorEquipmentType type) { + switch (type.getSlot()) { + case HEAD -> { + return protectionAmounts[0]; + } + case CHEST -> { + return protectionAmounts[1]; + } + case LEGS -> { + return protectionAmounts[2]; + } + case FEET -> { + return protectionAmounts[3]; + } + default -> { + return 0; + } + } + } + + @Override + public int getEnchantability() { + return enchantability; + } + + @Override + public SoundEvent getEquipSound() { + return equipSound; + } + + @Override + public Ingredient getRepairIngredient() { + return repairIngredient; + } + + @Override + public Identifier getId() { + return id; + } + + @Override + public float getToughness() { + return toughness; + } + + @Override + public float getKnockbackResistance() { + return knockbackResistance; + } + }; + } + + @Deprecated + public static CompatibleArmorMaterial create(Identifier id, int durability, int protectionAmount, int enchantability, SoundEvent equipSound, float toughness, float knockbackResistance, Ingredient repairIngredient) { + return new CompatibleArmorMaterial() { + @Override + public int getDurability(ArmorEquipmentType type) { + return durability; + } + + @Override + public int getProtection(ArmorEquipmentType type) { + return protectionAmount; + } + + @Override + public int getEnchantability() { + return enchantability; + } + + @Override + public SoundEvent getEquipSound() { + return equipSound; + } + + @Override + public Ingredient getRepairIngredient() { + return repairIngredient; + } + + @Override + public Identifier getId() { + return id; + } + + @Override + public float getToughness() { + return toughness; + } + + @Override + public float getKnockbackResistance() { + return knockbackResistance; + } + }; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/BlockEntityDataUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/BlockEntityDataUtil.java new file mode 100644 index 000000000..85e260414 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/BlockEntityDataUtil.java @@ -0,0 +1,45 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.component.DataComponentTypes; +import net.minecraft.component.type.NbtComponent; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NbtCompound; +import net.pitan76.mcpitanlib.api.event.nbt.ReadNbtArgs; +import net.pitan76.mcpitanlib.api.event.nbt.WriteNbtArgs; +import net.pitan76.mcpitanlib.api.tile.CompatBlockEntity; + +public class BlockEntityDataUtil { + public static NbtCompound getBlockEntityNbt(ItemStack stack) { + if (!stack.contains(DataComponentTypes.BLOCK_ENTITY_DATA)) return NbtUtil.create(); + NbtComponent component = stack.get(DataComponentTypes.BLOCK_ENTITY_DATA); + if (component == null) return NbtUtil.create(); + + NbtCompound nbt = component.copyNbt(); + if (nbt == null) return NbtUtil.create(); + return nbt; + } + + public static void setBlockEntityNbt(ItemStack stack, NbtCompound nbt) { + stack.set(DataComponentTypes.BLOCK_ENTITY_DATA, NbtComponent.of(nbt)); + } + + public static boolean hasBlockEntityNbt(ItemStack stack) { + return stack.get(DataComponentTypes.BLOCK_ENTITY_DATA) != null; + } + + public static void readCompatBlockEntityNbtFromStack(ItemStack stack, CompatBlockEntity blockEntity) { + NbtCompound nbt = getBlockEntityNbt(stack); + blockEntity.readNbt(new ReadNbtArgs(nbt, RegistryLookupUtil.getRegistryLookup(blockEntity))); + } + + public static void writeCompatBlockEntityNbtToStack(ItemStack stack, CompatBlockEntity blockEntity) { + NbtCompound nbt = getBlockEntityNbt(stack); + blockEntity.writeNbt(new WriteNbtArgs(nbt, RegistryLookupUtil.getRegistryLookup(blockEntity))); + NbtUtil.set(nbt, "id", BlockEntityTypeUtil.toID(blockEntity.getType()).toString()); + setBlockEntityNbt(stack, nbt); + } + + public static void removeBlockEntityNbt(ItemStack stack) { + stack.remove(DataComponentTypes.BLOCK_ENTITY_DATA); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/BlockEntityTypeUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/BlockEntityTypeUtil.java new file mode 100644 index 000000000..22355031b --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/BlockEntityTypeUtil.java @@ -0,0 +1,39 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.block.entity.BlockEntityType; +import net.minecraft.registry.Registries; +import net.minecraft.util.Identifier; + +public class BlockEntityTypeUtil { + public static Identifier toID(BlockEntityType entityType) { + return Registries.BLOCK_ENTITY_TYPE.getId(entityType); + } + + public static BlockEntityType fromId(Identifier identifier) { + return Registries.BLOCK_ENTITY_TYPE.get(identifier); + } + + public static boolean isExist(Identifier identifier) { + return Registries.BLOCK_ENTITY_TYPE.containsId(identifier); + } + + public static CompatIdentifier toCompatID(BlockEntityType entityType) { + return CompatIdentifier.fromMinecraft(toID(entityType)); + } + + public static BlockEntityType fromId(CompatIdentifier identifier) { + return fromId(identifier.toMinecraft()); + } + + public static boolean isExist(CompatIdentifier identifier) { + return isExist(identifier.toMinecraft()); + } + + public static int getRawId(BlockEntityType type) { + return Registries.BLOCK_ENTITY_TYPE.getRawId(type); + } + + public static BlockEntityType fromIndex(int index) { + return Registries.BLOCK_ENTITY_TYPE.get(index); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/BlockEntityUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/BlockEntityUtil.java new file mode 100644 index 000000000..59d344fb2 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/BlockEntityUtil.java @@ -0,0 +1,107 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.block.entity.BlockEntityType; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NbtCompound; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.registry.CompatRegistryLookup; +import org.jetbrains.annotations.Nullable; + +public class BlockEntityUtil { + + public static BlockEntity getBlockEntity(World world, BlockPos pos) { + return WorldUtil.getBlockEntity(world, pos); + } + + public static NbtCompound getBlockEntityNbt(@Nullable World world, BlockEntity blockEntity) { + if (world == null) + world = getWorld(blockEntity); + if (world == null) + return NbtUtil.create(); + + return blockEntity.createNbt(world.getRegistryManager()); + } + + public static NbtCompound getBlockEntityNbt(BlockEntity blockEntity) { + return getBlockEntityNbt(null, blockEntity); + } + + public static World getWorld(BlockEntity blockEntity) { + return blockEntity.getWorld(); + } + + public static boolean hasWorld(BlockEntity blockEntity) { + return blockEntity.hasWorld(); + } + + public static BlockPos getPos(BlockEntity blockEntity) { + return blockEntity.getPos(); + } + + public static BlockState getCachedState(BlockEntity blockEntity) { + return blockEntity.getCachedState(); + } + + public static BlockState getBlockState(BlockEntity blockEntity) { + return getWorld(blockEntity).getBlockState(getPos(blockEntity)); + } + + public static Block getBlock(BlockEntity blockEntity) { + return getBlockState(blockEntity).getBlock(); + } + + public static void markRemoved(BlockEntity blockEntity) { + blockEntity.markRemoved(); + } + + public static void markDirty(BlockEntity blockEntity) { + blockEntity.markDirty(); + } + + public static BlockEntityType getType(BlockEntity blockEntity) { + return blockEntity.getType(); + } + + public static void readNbt(BlockEntity blockEntity, NbtCompound nbt, CompatRegistryLookup registryLookup) { + blockEntity.readNbt(nbt, registryLookup.getRegistryLookup()); + } + + public static void writeNbt(BlockEntity blockEntity, NbtCompound nbt, CompatRegistryLookup registryLookup) { + blockEntity.writeNbt(nbt, registryLookup.getRegistryLookup()); + } + + public static void read(BlockEntity blockEntity, NbtCompound nbt, CompatRegistryLookup registryLookup) { + blockEntity.read(nbt, registryLookup.getRegistryLookup()); + } + + public static NbtCompound createNbt(BlockEntity blockEntity, CompatRegistryLookup registryLookup) { + return blockEntity.createNbt(registryLookup.getRegistryLookup()); + } + + public static void setStackNbt(BlockEntity blockEntity, ItemStack stack, CompatRegistryLookup registryLookup) { + blockEntity.setStackNbt(stack, registryLookup.getRegistryLookup()); + } + + public static ServerWorld getServerWorld(BlockEntity blockEntity) { + return (ServerWorld) getWorld(blockEntity); + } + + public static void writeToStack(ItemStack stack, BlockEntity blockEntity, CompatRegistryLookup registryLookup) { + NbtCompound nbt = blockEntity.createComponentlessNbt(registryLookup.getRegistryLookup()); + if (!NbtUtil.has(nbt, "id")) + NbtUtil.putString(nbt, "id", BlockEntityTypeUtil.toID(BlockEntityUtil.getType(blockEntity)).toString()); + + BlockEntityDataUtil.setBlockEntityNbt(stack, nbt); + + stack.applyComponentsFrom(blockEntity.createComponentMap()); + } + + public static boolean isRemoved(BlockEntity blockEntity) { + return blockEntity.isRemoved(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/BlockStateUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/BlockStateUtil.java new file mode 100644 index 000000000..b49fd782c --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/BlockStateUtil.java @@ -0,0 +1,154 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.fluid.Fluid; +import net.minecraft.fluid.FluidState; +import net.minecraft.item.ItemStack; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.sound.BlockSoundGroup; +import net.minecraft.state.StateManager; +import net.minecraft.state.property.Property; +import net.minecraft.util.BlockRotation; +import net.minecraft.util.Hand; +import net.minecraft.util.hit.BlockHitResult; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import net.minecraft.world.BlockView; +import net.minecraft.world.World; +import net.minecraft.world.WorldAccess; +import net.pitan76.mcpitanlib.api.entity.Player; +import net.pitan76.mcpitanlib.api.sound.CompatBlockSoundGroup; +import net.pitan76.mcpitanlib.api.util.block.BlockHitResultUtil; +import net.pitan76.mcpitanlib.midohra.block.BlockWrapper; + +public class BlockStateUtil { + public static Block getBlock(BlockState state) { + return state.getBlock(); + } + + public static boolean isAir(BlockState state) { + return state.isAir(); + } + + public static boolean isOpaque(BlockState state) { + return state.isOpaque(); + } + + public static BlockSoundGroup getSoundGroup(BlockState state) { + return state.getSoundGroup(); + } + + public static CompatBlockSoundGroup getCompatSoundGroup(BlockState state) { + return CompatBlockSoundGroup.of(getSoundGroup(state)); + } + + public static BlockState getDefaultState(Block block) { + return block.getDefaultState(); + } + + public static StateManager getStateManager(Block block) { + return block.getStateManager(); + } + + public static , V extends T> BlockState with(BlockState state, Property property, V value) { + return state.with(property, value); + } + + public static void neighborUpdate(BlockState state, World world, BlockPos pos, Block block, BlockPos fromPos, boolean notify) { + state.neighborUpdate(world, pos, block, fromPos, notify); + } + + public static void updateNeighbors(BlockState state, WorldAccess world, BlockPos pos, int flags) { + state.updateNeighbors(world, pos, flags); + } + + public static boolean hasRandomTicks(BlockState state) { + return state.hasRandomTicks(); + } + + public static void randomTick(BlockState state, ServerWorld world, BlockPos pos) { + state.randomTick(world, pos, world.random); + } + + public static CompatActionResult onUse(BlockState state, World world, Player player, BlockHitResult hitResult) { + return CompatActionResult.create(state.onUse(world, player.getEntity(), hitResult)); + } + + public static CompatActionResult onUse(BlockState state, World world, Player player, Direction dir, BlockPos blockPos) { + return onUse(state, world, player, BlockHitResultUtil.create(player.getPos(), dir, blockPos)); + } + + public static CompatActionResult onUseWithItem(BlockState state, ItemStack stack, World world, PlayerEntity player, Hand hand, BlockHitResult hit) { + return CompatActionResult.create(state.onUseWithItem(stack, world, player, hand, hit).toActionResult()); + } + + public static CompatActionResult onUseWithItem_actionResult(BlockState state, ItemStack stack, World world, PlayerEntity player, Hand hand, BlockHitResult hit) { + return onUseWithItem(state, stack, world, player, hand, hit); + } + + public static FluidState getFluidState(BlockState state) { + return state.getFluidState(); + } + + public static Fluid getFluid(BlockState state) { + return getFluidState(state).getFluid(); + } + + public static BlockState rotate(BlockState state, BlockRotation rotation) { + return state.rotate(rotation); + } + + public static net.pitan76.mcpitanlib.midohra.block.BlockState getMidohraDefaultState(Block block) { + return net.pitan76.mcpitanlib.midohra.block.BlockState.of(getDefaultState(block)); + } + + public static net.pitan76.mcpitanlib.midohra.block.BlockState getDefaultState(BlockWrapper block) { + return block.getDefaultState(); + } + + public static float getHardness(BlockState state, BlockView world, BlockPos pos) { + return state.getHardness(world, pos); + } + + public static float getHardness(BlockState state, World world, BlockPos pos) { + return state.getHardness(world, pos); + } + + public static int getLuminance(BlockState state) { + return state.getLuminance(); + } + + public static int getOpacity(BlockState state) { + return state.getOpacity(null, null); + } + + public static int getComparatorOutput(BlockState state, World world, BlockPos pos) { + return state.getComparatorOutput(world, pos); + } + + public static float getHardness(net.pitan76.mcpitanlib.midohra.block.BlockState state, net.pitan76.mcpitanlib.midohra.world.BlockView world, net.pitan76.mcpitanlib.midohra.util.math.BlockPos pos) { + return getHardness(state.toMinecraft(), world.getRaw(), pos.toMinecraft()); + } + + public static int getLuminance(net.pitan76.mcpitanlib.midohra.block.BlockState state) { + return getLuminance(state.toMinecraft()); + } + + public static int getOpacity(net.pitan76.mcpitanlib.midohra.block.BlockState state) { + return getOpacity(state.toMinecraft()); + } + + public static int getComparatorOutput(net.pitan76.mcpitanlib.midohra.block.BlockState state, net.pitan76.mcpitanlib.midohra.world.World world, net.pitan76.mcpitanlib.midohra.util.math.BlockPos pos) { + return getComparatorOutput(state.toMinecraft(), world.getRaw(), pos.toMinecraft()); + } + + public static boolean canPlaceAt(BlockState state, BlockPos pos, World world) { + return state.canPlaceAt(world, pos); + } + + public static boolean canPlaceAt(net.pitan76.mcpitanlib.midohra.block.BlockState state, net.pitan76.mcpitanlib.midohra.util.math.BlockPos pos, net.pitan76.mcpitanlib.midohra.world.World world) { + return canPlaceAt(state.toMinecraft(), pos.toMinecraft(), world.getRaw()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/BlockUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/BlockUtil.java new file mode 100644 index 000000000..0a5532540 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/BlockUtil.java @@ -0,0 +1,258 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.block.AbstractBlock; +import net.minecraft.block.Block; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.Identifier; +import net.pitan76.mcpitanlib.api.block.CompatibleBlockSettings; +import net.pitan76.mcpitanlib.api.tag.MineableToolTags; +import net.pitan76.mcpitanlib.api.tag.TagKey; +import net.pitan76.mcpitanlib.api.util.v1.BlockUtilV1; +import net.pitan76.mcpitanlib.api.util.v2.BlockUtilV2; + +import java.util.List; + +@Deprecated +public class BlockUtil { + /** + * Get block from Identifier. + * @param id Identifier of the block. + * @return Block of the Identifier. + */ + public static Block block(Identifier id) { + return BlockUtilV1.block(id); + } + + /** + * Check if two blocks are equal. + * @param block Block to compare. + * @param block2 Block to compare. + * @return If two blocks are equal. + */ + public static boolean isEqual(Block block, Block block2) { + return BlockUtilV2.isEqual(block, block2); + } + + /** + * Check if the block is in the tag. (MCPitanLib TagKey) + * @param block Block to check. + * @param tagKey TagKey of the tag. + * @return If the block is in the tag. + */ + public static boolean isIn(Block block, TagKey tagKey) { + return BlockUtilV2.isIn(block, tagKey); + } + + /** + * set break tool tag and level to block + * @param settings Block settings + * @param toolTags Tool tags + * @param level Level + * @return Block settings + */ + public static AbstractBlock.Settings breakByTool(AbstractBlock.Settings settings, MineableToolTags toolTags, int level) { + return BlockUtilV1.breakByTool(settings, toolTags, level); + } + + /** + * not drop anything when block is broken + * @param settings Block settings + * @return Block settings + */ + public static AbstractBlock.Settings dropsNothing(AbstractBlock.Settings settings) { + return BlockUtilV1.dropsNothing(settings); + } + /** + * block breaking requires any tool + * @param settings Block settings + * @return Block settings + */ + public static AbstractBlock.Settings requiresTool(AbstractBlock.Settings settings) { + return BlockUtilV1.requiresTool(settings); + } + + /** + * Check if the block is existed. + * @param identifier Identifier of the block. + * @return If the block is existed. + */ + public static boolean isExist(Identifier identifier) { + return BlockUtilV1.isExist(identifier); + } + + /** + * Get Identifier from block. + * @param block Block to get Identifier. + * @return Identifier of the block. + */ + public static Identifier toID(Block block) { + return BlockUtilV1.toID(block); + } + + /** + * Get block from Identifier. + * @param identifier Identifier of the block. + * @return Block of the Identifier. + */ + public static Block fromId(Identifier identifier) { + return BlockUtilV1.fromId(identifier); + } + + /** + * Get CompatIdentifier from block. + * @param block Block to get CompatIdentifier. + * @return CompatIdentifier of the block. + */ + public static CompatIdentifier toCompatID(Block block) { + return CompatIdentifier.fromMinecraft(toID(block)); + } + + /** + * Get block from CompatIdentifier. + * @param identifier CompatIdentifier of the block. + * @return Block of the CompatIdentifier. + */ + public static Block fromId(CompatIdentifier identifier) { + return fromId(identifier.toMinecraft()); + } + + /** + * Check if the block is existed. + * @param identifier CompatIdentifier of the block. + * @return If the block is existed. + */ + public static boolean isExist(CompatIdentifier identifier) { + return isExist(identifier.toMinecraft()); + } + + /** + * Get all blocks. + * @return List of all blocks. + */ + public static List getAllBlocks() { + return BlockUtilV1.getAllBlocks(); + } + + /** + * Create Block from Block.Settings. + * @param settings Block.Settings to create Block. + * @return Block created from Block.Settings. + */ + @Deprecated + public static Block of(AbstractBlock.Settings settings) { + return BlockUtilV1.of(settings); + } + + /** + * Create Block from CompatibleBlockSettings. + * @param settings CompatibleBlockSettings to create Block. + * @return Block created from CompatibleBlockSettings. + */ + public static Block of(CompatibleBlockSettings settings) { + return BlockUtilV1.of(settings); + } + + /** + * Get raw id of the block. + * @param block Block to get raw id. + * @return Raw id of the block. + */ + public static int getRawId(Block block) { + return BlockUtilV1.getRawId(block); + } + + /** + * Get block from raw id. + * @param index Raw id of the block. + * @return Block from raw id. + */ + public static Block fromIndex(int index) { + return BlockUtilV1.fromIndex(index); + } + + /** + * Get all blocks in the tag. (MCPitanLib TagKey) + * @param tagKey TagKey of the tag. + * @return List of blocks in the tag. + */ + public static List getBlocks(TagKey tagKey) { + return BlockUtilV2.getBlocks(tagKey); + } + + /** + * Get given the list of blocks in the tag. (MCPitanLib TagKey) + * @param tagKey TagKey of the tag. + * @param blocks List of blocks to search. + * @return List of blocks in the tag. + */ + public static List getBlocks(TagKey tagKey, List blocks) { + return BlockUtilV2.getBlocks(tagKey, blocks); + } + + /** + * Get all blocks in the tag. + * @param identifier Identifier of the tag. + * @return List of blocks in the tag. + */ + public static List getBlocks(Identifier identifier) { + return BlockUtilV2.getBlocks(identifier); + } + + /** + * Get given the list of blocks in the tag. + * @param identifier Identifier of the tag. + * @param blocks List of blocks to search. + * @return List of blocks in the tag. + */ + public static List getBlocks(Identifier identifier, List blocks) { + return BlockUtilV2.getBlocks(identifier, blocks); + } + + /** + * Get all blocks in the tag. + * @param id String of the tag. + * @return List of blocks in the tag. + */ + public static List getBlocks(String id) { + return BlockUtilV2.getBlocks(id); + } + + /** + * Get given the list of blocks in the tag. + * @param id String of the tag. + * @param blocks List of blocks to search. + * @return List of blocks in the tag. + */ + public static List getBlocks(String id, List blocks) { + return BlockUtilV2.getBlocks(id, blocks); + } + + /** + * Check if the block is in the tag. + * @param block Block to check. + * @param identifier Identifier of the tag. + * @return If the block is in the tag. + */ + public static boolean isBlockInTag(Block block, Identifier identifier) { + return BlockUtilV2.isBlockInTag(block, identifier); + } + + /** + * Check if the block is in the tag. + * @param block Block to check. + * @param id String of the tag. + * @return If the block is in the tag. + */ + public static boolean isBlockInTag(Block block, String id) { + return BlockUtilV2.isBlockInTag(block, id); + } + + public static Block fromItem(Item item) { + return BlockUtilV2.fromItem(item); + } + + public static Block fromItem(ItemStack stack) { + return BlockUtilV2.fromItem(stack); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/BlockViewUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/BlockViewUtil.java new file mode 100644 index 000000000..a95953baf --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/BlockViewUtil.java @@ -0,0 +1,24 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.block.BlockState; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.BlockView; + +public class BlockViewUtil { + public static BlockState getBlockState(BlockView blockView, BlockPos pos) { + return blockView.getBlockState(pos); + } + + public static BlockEntity getBlockEntity(BlockView blockView, BlockPos pos) { + return blockView.getBlockEntity(pos); + } + + public static boolean hasBlockEntity(BlockView blockView, BlockPos pos) { + return getBlockEntity(blockView, pos) != null; + } + + public static boolean isAir(BlockView blockView, BlockPos pos) { + return getBlockState(blockView, pos).isAir(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/CommandManagerUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/CommandManagerUtil.java new file mode 100644 index 000000000..30ef31a72 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/CommandManagerUtil.java @@ -0,0 +1,84 @@ +package net.pitan76.mcpitanlib.api.util; + +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.command.CommandManager; +import net.minecraft.server.command.ServerCommandSource; +import net.pitan76.mcpitanlib.api.entity.Player; +import net.pitan76.mcpitanlib.core.command.CommandResult; + +public class CommandManagerUtil { + public static CommandManager getCommandManager(MinecraftServer server) { + return server.getCommandManager(); + } + + public static CommandResult execute(MinecraftServer server, String command) { + CommandDispatcher dispatcher = getCommandManager(server).getDispatcher(); + ServerCommandSource source = server.getCommandSource(); + + if (command.startsWith("/")) { + command = command.substring(1); + } + + CommandResult cr = new CommandResult(); + cr.setSuccess(false); + cr.setSource(source); + + try { + int result = dispatcher.execute(command, source); + cr.setResult(result); + cr.setSuccess(true); + } catch (CommandSyntaxException e) { + cr.setMessage(e.getMessage()); + cr.setErrorType(CommandResult.ErrorType.COMMAND_SYNTAX_ERROR); + } catch (RuntimeException e) { + cr.setMessage(e.getMessage()); + cr.setErrorType(CommandResult.ErrorType.RUNTIME_ERROR); + } + + return cr; + } + + public static CommandResult execute(ServerCommandSource source, String command) { + CommandDispatcher dispatcher = source.getServer().getCommandManager().getDispatcher(); + + if (command.startsWith("/")) { + command = command.substring(1); + } + + CommandResult cr = new CommandResult(); + cr.setSuccess(false); + cr.setSource(source); + + try { + int result = dispatcher.execute(command, source); + cr.setResult(result); + cr.setSuccess(true); + } catch (CommandSyntaxException e) { + cr.setMessage(e.getMessage()); + cr.setErrorType(CommandResult.ErrorType.COMMAND_SYNTAX_ERROR); + } catch (RuntimeException e) { + cr.setMessage(e.getMessage()); + cr.setErrorType(CommandResult.ErrorType.RUNTIME_ERROR); + } + + return cr; + } + + public static CommandResult execute(Player player, String command) { + return execute(getCommandSource(player), command); + } + + public static ServerCommandSource getCommandSource(MinecraftServer server) { + return server.getCommandSource(); + } + + public static ServerCommandSource getCommandSource(Player player) { + return player.getEntity().getCommandSource(); + } + + public static ServerCommandSource withLevel(ServerCommandSource source, int level) { + return source.withLevel(level); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/CommandUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/CommandUtil.java new file mode 100644 index 000000000..8ba934d53 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/CommandUtil.java @@ -0,0 +1,53 @@ +package net.pitan76.mcpitanlib.api.util; + +import com.mojang.brigadier.arguments.*; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import net.minecraft.block.Block; +import net.minecraft.command.argument.BlockStateArgumentType; +import net.minecraft.command.argument.EntityArgumentType; +import net.minecraft.command.argument.ItemStackArgumentType; +import net.minecraft.entity.Entity; +import net.minecraft.item.Item; +import net.pitan76.mcpitanlib.api.event.ServerCommandEvent; + +public class CommandUtil { + public static Item getItemArgument(String name, ServerCommandEvent e) { + return ItemStackArgumentType.getItemStackArgument(e.getContext(), name).getItem(); + } + + public static Block getBlockArgument(String name, ServerCommandEvent e) { + return BlockStateArgumentType.getBlockState(e.getContext(), name).getBlockState().getBlock(); + } + + public static Integer getIntegerArgument(String name, ServerCommandEvent e) { + return IntegerArgumentType.getInteger(e.getContext(), name); + } + + public static Double getDoubleArgument(String name, ServerCommandEvent e) { + return DoubleArgumentType.getDouble(e.getContext(), name); + } + + public static Float getFloatArgument(String name, ServerCommandEvent e) { + return FloatArgumentType.getFloat(e.getContext(), name); + } + + public static Long getLongArgument(String name, ServerCommandEvent e) { + return LongArgumentType.getLong(e.getContext(), name); + } + + public static Boolean getBooleanArgument(String name, ServerCommandEvent e) { + return BoolArgumentType.getBool(e.getContext(), name); + } + + public static String getStringArgument(String name, ServerCommandEvent e) { + return StringArgumentType.getString(e.getContext(), name); + } + + public static Entity getEntityArgument(String name, ServerCommandEvent e) { + try { + return EntityArgumentType.getEntity(e.getContext(), name); + } catch (CommandSyntaxException ex) { + return null; + } + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/CompatActionResult.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/CompatActionResult.java new file mode 100644 index 000000000..426389c42 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/CompatActionResult.java @@ -0,0 +1,114 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.util.ActionResult; +import net.pitan76.mcpitanlib.api.event.result.EventResult; +import net.pitan76.mcpitanlib.midohra.item.ItemStack; + +import java.util.Optional; + +public class CompatActionResult { + public static final CompatActionResult SUCCESS = new CompatActionResult(ActionResult.SUCCESS, EventResult.success()); + public static final CompatActionResult PASS = new CompatActionResult(ActionResult.PASS, EventResult.pass()); + public static final CompatActionResult FAIL = new CompatActionResult(ActionResult.FAIL, EventResult.fail()); + public static final CompatActionResult CONSUME = new CompatActionResult(ActionResult.CONSUME, EventResult.success()); + public static final CompatActionResult PASS_TO_DEFAULT_BLOCK_ACTION = new CompatActionResult(ActionResult.PASS, EventResult.pass()); + public static final CompatActionResult SUCCESS_SERVER = new CompatActionResult(ActionResult.SUCCESS, EventResult.success()); + public static final CompatActionResult STOP = new CompatActionResult(ActionResult.FAIL, EventResult.stop()); + + private final ActionResult actionResult; + private final EventResult eventResult; + + protected CompatActionResult(ActionResult actionResult, EventResult eventResult) { + this.actionResult = actionResult; + this.eventResult = eventResult; + } + + public ActionResult toActionResult() { + return actionResult; + } + + public EventResult toEventResult() { + return eventResult; + } + + public Optional getNewMidohraHandStack() { + return getNewHandStack().map(ItemStack::of); + } + + public Optional getNewHandStack() { + return Optional.empty(); + } + + public static CompatActionResult of(ActionResult result) { + if (result == ActionResult.SUCCESS) + return SUCCESS; + + if (result == ActionResult.PASS) + return PASS; + + if (result == ActionResult.FAIL) + return FAIL; + + if (result == ActionResult.CONSUME) + return CONSUME; + + return PASS; + } + + public static CompatActionResult of(EventResult result) { + if (result == EventResult.success()) + return SUCCESS; + + if (result == EventResult.pass()) + return PASS; + + if (result == EventResult.fail()) + return FAIL; + + if (result == EventResult.stop()) + return STOP; + + return PASS; + } + + @Deprecated + public static CompatActionResult create(ActionResult result, EventResult eventResult) { + return new CompatActionResult(result, eventResult); + } + + /** + * @deprecated Use {@link #of(ActionResult)} instead. + */ + @Deprecated + public static CompatActionResult create(ActionResult result) { + return of(result); + } + + @Deprecated + public static CompatActionResult create2(ActionResult result) { + return create(result, EventResult.stop()); + } + + @Override + public boolean equals(Object obj) { + if (super.equals(obj)) return true; + if (!(obj instanceof CompatActionResult)) return false; + if (actionResult.equals(((CompatActionResult) obj).actionResult)) { + return eventResult.equals(((CompatActionResult) obj).eventResult); + } + + return false; + } + + public String getName() { + if (this == SUCCESS) return "SUCCESS"; + if (this == PASS) return "PASS"; + if (this == FAIL) return "FAIL"; + if (this == CONSUME) return "CONSUME"; + if (this == PASS_TO_DEFAULT_BLOCK_ACTION) return "PASS_TO_DEFAULT_BLOCK_ACTION"; + if (this == SUCCESS_SERVER) return "SUCCESS_SERVER"; + if (this == STOP) return "STOP"; + + return "UNKNOWN"; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/CompatIdentifier.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/CompatIdentifier.java new file mode 100644 index 000000000..999fa63cd --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/CompatIdentifier.java @@ -0,0 +1,160 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.util.Identifier; + +import java.util.Objects; + +/** + * This is the Identifier class unique to MCPitanLib. + * It is different from Minecraft's Identifier class. + */ +public class CompatIdentifier { + private final String namespace; + private final String path; + + public static final CompatIdentifier EMPTY = CompatIdentifier.of("mcpitanlib:empty"); + + /** + * Creates a new Identifier with the given namespace and path. + * @param namespace The namespace of the Identifier. + * @param path The path of the Identifier. + */ + public CompatIdentifier(String namespace, String path) { + this.namespace = namespace; + this.path = path; + } + + /** + * Creates a new Identifier with the given id. + * @param id The id of the Identifier. + */ + public CompatIdentifier(String id) { + if (!id.contains(":")) { + this.namespace = "minecraft"; + this.path = id; + return; + } + String[] split = id.split(":"); + this.namespace = split[0]; + this.path = split[1]; + } + + /** + * Creates a new Identifier with the given id. + * @param id The id of the Identifier. + * @return The Identifier. + */ + public static CompatIdentifier of(String id) { + return new CompatIdentifier(id); + } + + /** + * Creates a new Identifier with the given namespace and path. + * @param namespace The namespace of the Identifier. + * @param path The path of the Identifier. + * @return The Identifier. + */ + public static CompatIdentifier of(String namespace, String path) { + return new CompatIdentifier(namespace, path); + } + + /** + * Returns the string representation of the Identifier. + * @return The string representation of the Identifier. + */ + public String toString() { + return this.namespace + ":" + this.path; + } + + /** + * Returns the namespace of the Identifier. + * @return The namespace of the Identifier. + */ + public String getNamespace() { + return this.namespace; + } + + /** + * Returns the path of the Identifier. + * @return The path of the Identifier. + */ + public String getPath() { + return this.path; + } + + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if (obj != null && this.getClass() == obj.getClass()) { + CompatIdentifier identifier = (CompatIdentifier)obj; + return this.namespace.equals(identifier.namespace) && this.path.equals(identifier.path); + } else if (obj instanceof Identifier) { + return this.toString().equals(obj.toString()); + } else if (obj instanceof String) { + return this.toString().equals(obj); + } else { + return false; + } + } + + public boolean equals(CompatIdentifier identifier) { + return this.namespace.equals(identifier.namespace) && this.path.equals(identifier.path); + } + + public boolean equals(String id) { + return this.toString().equals(id); + } + + public static boolean equals(CompatIdentifier id1, CompatIdentifier id2) { + return id1.namespace.equals(id2.namespace) && id1.path.equals(id2.path); + } + + public static boolean equals(CompatIdentifier id1, Identifier id2) { + return id1.toString().equals(id2.toString()); + } + + public static boolean equals(Identifier id1, CompatIdentifier id2) { + return id1.toString().equals(id2.toString()); + } + + public static boolean equals(Identifier id1, Identifier id2) { + return id1.toString().equals(id2.toString()); + } + + @Override + public int hashCode() { + return 31 * this.namespace.hashCode() + this.path.hashCode(); + } + + // ---- + + /** + * Converts this MCPitanLib Identifier to a Minecraft Identifier. + * @return The Minecraft Identifier. + */ + public Identifier toMinecraft() { + return IdentifierUtil.id(this.toString()); + } + + /** + * Converts a Minecraft Identifier to an MCPitanLib Identifier. + * @param id The Minecraft Identifier. + * @return The Identifier. + */ + public static CompatIdentifier fromMinecraft(Identifier id) { + if (id == null) return EMPTY; + return of(id.toString()); + } + + public static CompatIdentifier empty() { + return EMPTY; + } + + public boolean isEmpty() { + return equals(EMPTY); + } + + public static boolean isMinecraftNamespace(CompatIdentifier id) { + return id.getNamespace().equals("minecraft"); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/CompatRarity.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/CompatRarity.java new file mode 100644 index 000000000..e11866da2 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/CompatRarity.java @@ -0,0 +1,54 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.util.Formatting; +import net.minecraft.util.Rarity; + +public class CompatRarity implements CompatStringIdentifiable { + private final Rarity rarity; + + public static final CompatRarity NONE = of(Rarity.COMMON); + public static final CompatRarity COMMON = of(Rarity.COMMON); + public static final CompatRarity UNCOMMON = of(Rarity.UNCOMMON); + public static final CompatRarity RARE = of(Rarity.RARE); + public static final CompatRarity EPIC = of(Rarity.EPIC); + + public CompatRarity(Rarity rarity) { + this.rarity = rarity; + } + + public static CompatRarity of(Rarity rarity) { + return new CompatRarity(rarity); + } + + public Rarity get() { + return rarity; + } + + public Formatting getFormatting() { + return rarity.getFormatting(); + } + + public String getName() { + return rarity.name(); + } + + @Override + public String asString_compat() { + return getName(); + } + + public static CompatRarity fromString(String name) { + switch (name) { + case "common": + return COMMON; + case "uncommon": + return UNCOMMON; + case "rare": + return RARE; + case "epic": + return EPIC; + default: + return NONE; + } + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/CompatStringIdentifiable.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/CompatStringIdentifiable.java new file mode 100644 index 000000000..2fb01f76e --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/CompatStringIdentifiable.java @@ -0,0 +1,17 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.util.StringIdentifiable; + +public interface CompatStringIdentifiable extends StringIdentifiable { + @Deprecated + @Override + default String asString() { + return asString_compat(); + } + + String asString_compat(); + + default StringIdentifiable get() { + return this; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/CompatibleRecipeEntryUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/CompatibleRecipeEntryUtil.java new file mode 100644 index 000000000..6201ecc60 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/CompatibleRecipeEntryUtil.java @@ -0,0 +1,27 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.item.ItemStack; +import net.minecraft.recipe.Ingredient; +import net.minecraft.util.Identifier; +import net.minecraft.util.collection.DefaultedList; +import net.pitan76.mcpitanlib.api.recipe.CompatibleRecipeEntry; +import net.pitan76.mcpitanlib.api.recipe.v3.CompatRecipe; +import net.pitan76.mcpitanlib.midohra.recipe.entry.RecipeEntry; + +public class CompatibleRecipeEntryUtil { + public static CompatibleRecipeEntry createShapelessRecipe(Identifier id, String group, RecipeUtil.CompatibilityCraftingRecipeCategory category, ItemStack output, DefaultedList input) { + return new CompatibleRecipeEntry(id, group, category, RecipeUtil.createShapelessRecipe(id, group, category, output, input)); + } + + public static CompatibleRecipeEntry createShapelessRecipe(CompatIdentifier id, String group, RecipeUtil.CompatibilityCraftingRecipeCategory category, ItemStack output, DefaultedList input) { + return createShapelessRecipe(id.toMinecraft(), group, category, output, input); + } + + public static RecipeEntry createShapelessRecipeM(CompatIdentifier id, String group, RecipeUtil.CompatibilityCraftingRecipeCategory category, ItemStack output, DefaultedList input) { + return RecipeEntry.of(RecipeUtil.createShapelessRecipe(id.toMinecraft(), group, category, output, input), id); + } + + public static CompatRecipe createShapelessAsCompatRecipe(CompatIdentifier id, String group, RecipeUtil.CompatibilityCraftingRecipeCategory category, ItemStack output, DefaultedList input) { + return new CompatRecipe(RecipeUtil.createShapelessRecipe(id.toMinecraft(), group, category, output, input), id.toMinecraft()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/CustomDataUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/CustomDataUtil.java new file mode 100644 index 000000000..a35fe58ab --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/CustomDataUtil.java @@ -0,0 +1,175 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.component.DataComponentTypes; +import net.minecraft.component.type.NbtComponent; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NbtCompound; + +import java.util.Set; + +/** + * カスタムデータのユーティリティクラス + */ +public class CustomDataUtil { + /** + * NBTを取得する。存在しない場合は新しいNBTを作成する。 + * @param stack ItemStack + * @return NBT + */ + public static NbtCompound getOrCreateNbt(ItemStack stack) { + if (!hasNbt(stack)) { + return NbtUtil.create(); + } + + return getNbt(stack); + } + + /** + * NBTを設定する。 + * @param stack ItemStack + * @param nbt NBT + */ + public static void setNbt(ItemStack stack, NbtCompound nbt) { + stack.set(DataComponentTypes.CUSTOM_DATA, NbtComponent.of(nbt)); + } + + /** + * NBTが存在するかどうかを取得する。 + * @param stack ItemStack + * @return NBTが存在するかどうか + */ + public static boolean hasNbt(ItemStack stack) { + return stack.get(DataComponentTypes.CUSTOM_DATA) != null; + } + + /** + * NBTを取得する。 + * @param stack ItemStack + * @return NBT + */ + public static NbtCompound getNbt(ItemStack stack) { + if (stack.get(DataComponentTypes.CUSTOM_DATA) == null) + return NbtUtil.create(); + + return stack.get(DataComponentTypes.CUSTOM_DATA).copyNbt(); + } + + /** + * 値を設定する。 + * @param stack ItemStack + * @param key キー + * @param value 値 + */ + public static void put(ItemStack stack, String key, NbtCompound value) { + NbtCompound nbt = getOrCreateNbt(stack); + NbtUtil.put(nbt, key, value); + setNbt(stack, nbt); + } + + /** + * 値を取得する。 + * @param stack ItemStack + * @param key キー + * @return 値 + */ + public static NbtCompound get(ItemStack stack, String key) { + NbtCompound nbt = getNbt(stack); + return nbt.getCompound(key); + } + + /** + * 値を削除する。 + * @param stack ItemStack + * @param key キー + */ + public static void remove(ItemStack stack, String key) { + NbtCompound nbt = getNbt(stack); + nbt.remove(key); + setNbt(stack, nbt); + } + + /** + * 値が存在するかどうかを取得する。 + * @param stack ItemStack + * @param key キー + * @return 値が存在するかどうか + */ + public static boolean has(ItemStack stack, String key) { + if (!hasNbt(stack)) + return false; + + NbtCompound nbt = getNbt(stack); + return nbt.contains(key); + } + + /** + * 指定した型の値を取得する + * @param stack ItemStack + * @param key キー + * @param clazz クラス + * @param 値 + */ + public static T get(ItemStack stack, String key, Class clazz) { + NbtCompound nbt = getNbt(stack); + return NbtUtil.get(nbt, key, clazz); + } + + /** + * 値を設定する。 + * @param stack ItemStack + * @param key キー + * @param value 値 + */ + public static void set(ItemStack stack, String key, T value) { + NbtCompound nbt = getOrCreateNbt(stack); + NbtUtil.set(nbt, key, value); + setNbt(stack, nbt); + } + + /** + * キーの一覧を取得する。 + * @param stack ItemStack + * @return キーの一覧 + */ + public static Set getKeys(ItemStack stack) { + NbtCompound nbt = getNbt(stack); + return NbtUtil.getKeys(nbt); + } + + /** + * set(stack, key, value) のエイリアス + * @param stack ItemStack + * @param key キー + * @param value 値 + */ + public static void put(ItemStack stack, String key, T value) { + set(stack, key, value); + } + + /** + * has(stack, key) のエイリアス + * @param stack ItemStack + * @param key キー + * @return 値が存在するかどうか + */ + public static boolean contains(ItemStack stack, String key) { + return has(stack, key); + } + + /** + * 1.20.3以前下位互換のための修正用 + * @param stack ItemStack + * @param keys 移植するキー + */ + public static void fix_oldNbt(ItemStack stack, String[] keys) { + + } + + /** + * カスタムNBTを削除する + * @param stack ItemStack + */ + public static void remove(ItemStack stack) { + stack.remove(DataComponentTypes.CUSTOM_DATA); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/DamageSourceUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/DamageSourceUtil.java new file mode 100644 index 000000000..b5733480d --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/DamageSourceUtil.java @@ -0,0 +1,44 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.damage.DamageSource; +import net.pitan76.mcpitanlib.api.entity.Player; + +public class DamageSourceUtil { + public static DamageSource thrownProjectile(Entity projectile, Entity attacker, Entity source) { + return source.getDamageSources().thrown(projectile, attacker); + } + + public static DamageSource thrownProjectile(Entity projectile, Entity attacker) { + return thrownProjectile(projectile, attacker, projectile); + } + + public static DamageSource playerAttack(Player attacker, Entity source) { + return source.getDamageSources().playerAttack(attacker.getPlayerEntity()); + } + + public static DamageSource playerAttack(Player attacker) { + return playerAttack(attacker, attacker.getPlayerEntity()); + } + + public static DamageSource mobAttack(LivingEntity attacker, Entity source) { + return source.getDamageSources().mobAttack(attacker); + } + + public static DamageSource mobAttack(LivingEntity attacker) { + return mobAttack(attacker, attacker); + } + + public static DamageSource mobProjectile(Entity projectile, LivingEntity attacker, Entity source) { + return source.getDamageSources().mobProjectile(projectile, attacker); + } + + public static DamageSource mobProjectile(Entity projectile, LivingEntity attacker) { + return mobProjectile(projectile, attacker, projectile); + } + + public static DamageSource fall(Entity source) { + return source.getDamageSources().fall(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/DirectionBoolPropertyUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/DirectionBoolPropertyUtil.java new file mode 100644 index 000000000..13d9ad550 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/DirectionBoolPropertyUtil.java @@ -0,0 +1,68 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.pitan76.mcpitanlib.api.event.block.AppendPropertiesArgs; +import net.pitan76.mcpitanlib.api.state.property.CompatProperties; +import net.pitan76.mcpitanlib.midohra.block.BlockState; +import net.pitan76.mcpitanlib.midohra.util.math.BlockPos; +import net.pitan76.mcpitanlib.midohra.util.math.Direction; +import net.pitan76.mcpitanlib.midohra.world.World; + +public class DirectionBoolPropertyUtil { + /** + * 指定位置のブロック状態に対して、方向に対応する Boolean プロパティを設定してワールドに反映する。 + * 例: Direction.UP => CompatProperties.UP + * @return プロパティが存在して設定に成功した場合は true、プロパティが存在しない場合やブロック状態が null の場合は false + */ + public static boolean setProperty(World world, BlockPos pos, Direction dir, boolean value) { + BlockState state = world.getBlockState(pos); + + if (dir == Direction.UP && state.contains(CompatProperties.UP)) { + state = state.with(CompatProperties.UP, value); + } else if (dir == Direction.DOWN && state.contains(CompatProperties.DOWN)) { + state = state.with(CompatProperties.DOWN, value); + } else if (dir == Direction.NORTH && state.contains(CompatProperties.NORTH)) { + state = state.with(CompatProperties.NORTH, value); + } else if (dir == Direction.SOUTH && state.contains(CompatProperties.SOUTH)) { + state = state.with(CompatProperties.SOUTH, value); + } else if (dir == Direction.WEST && state.contains(CompatProperties.WEST)) { + state = state.with(CompatProperties.WEST, value); + } else if (dir == Direction.EAST && state.contains(CompatProperties.EAST)) { + state = state.with(CompatProperties.EAST, value); + } else { + return false; + } + + world.setBlockState(pos, state); + return true; + } + + public static boolean hasAll(BlockState state) { + return state.contains(CompatProperties.UP) && state.contains(CompatProperties.DOWN) && state.contains(CompatProperties.NORTH) && + state.contains(CompatProperties.SOUTH) && state.contains(CompatProperties.WEST) && state.contains(CompatProperties.EAST); + } + + public static BlockState clearAll(BlockState state) { + return state + .with(CompatProperties.UP, false) + .with(CompatProperties.DOWN, false) + .with(CompatProperties.NORTH, false) + .with(CompatProperties.EAST, false) + .with(CompatProperties.SOUTH, false) + .with(CompatProperties.WEST, false); + } + + public static void addProperties(AppendPropertiesArgs args) { + args.addProperty(CompatProperties.UP, CompatProperties.DOWN, CompatProperties.NORTH, + CompatProperties.EAST, CompatProperties.SOUTH, CompatProperties.WEST); + } + + public static BlockState withAll(BlockState state, boolean value) { + return state + .with(CompatProperties.UP, value) + .with(CompatProperties.DOWN, value) + .with(CompatProperties.NORTH, value) + .with(CompatProperties.EAST, value) + .with(CompatProperties.SOUTH, value) + .with(CompatProperties.WEST, value); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/EnchantmentUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/EnchantmentUtil.java new file mode 100644 index 000000000..8f449872f --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/EnchantmentUtil.java @@ -0,0 +1,82 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.component.DataComponentTypes; +import net.minecraft.component.type.ItemEnchantmentsComponent; +import net.minecraft.enchantment.Enchantment; +import net.minecraft.enchantment.EnchantmentHelper; +import net.minecraft.item.ItemStack; +import net.minecraft.registry.RegistryKey; +import net.minecraft.registry.RegistryKeys; +import net.minecraft.util.Identifier; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.enchantment.CompatEnchantment; +import org.jetbrains.annotations.Nullable; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class EnchantmentUtil { + public static CompatEnchantment getEnchantment(Identifier identifier) { + RegistryKey registryKey = RegistryKey.of(RegistryKeys.ENCHANTMENT, identifier); + return new CompatEnchantment(registryKey); + } + + public static Identifier getId(CompatEnchantment enchantment) { + return enchantment.getId(); + } + + public static int getLevel(CompatEnchantment enchantment, ItemStack stack, @Nullable World world) { + return enchantment.getLevel(stack, world); + } + + // CompatIdentifier + public static CompatEnchantment getEnchantment(CompatIdentifier identifier) { + return getEnchantment(identifier.toMinecraft()); + } + + public static CompatIdentifier getCompatId(CompatEnchantment enchantment) { + return CompatIdentifier.fromMinecraft(enchantment.getId()); + } + + public static List getEnchantments(ItemStack stack) { + List enchantments = new ArrayList<>(); + + EnchantmentHelper.getEnchantments(stack).getEnchantments().forEach((enchantment) -> { + if (enchantment.getKey().isPresent()) + enchantments.add(new CompatEnchantment(enchantment.getKey().get())); + }); + + return enchantments; + } + + public static boolean hasEnchantment(ItemStack stack) { + return EnchantmentHelper.hasEnchantments(stack); + } + + public static Map getEnchantment(ItemStack stack, @Nullable World world) { + Map enchantments = new HashMap<>(); + + List enchantmentList = getEnchantments(stack); + enchantmentList.forEach((enchantment) -> { + enchantments.put(enchantment, getLevel(enchantment, stack, world)); + }); + + return enchantments; + } + + public static void setEnchantment(ItemStack stack, Map enchantments, @Nullable World world) { + ItemEnchantmentsComponent.Builder builder = new ItemEnchantmentsComponent.Builder(ItemEnchantmentsComponent.DEFAULT); + + enchantments.forEach((compatEnchantment, integer) -> { + builder.add(compatEnchantment.getEntry(world), integer); + }); + + EnchantmentHelper.set(stack, builder.build()); + } + + public static void removeEnchantment(ItemStack stack) { + stack.remove(DataComponentTypes.ENCHANTMENTS); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/EntityTypeUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/EntityTypeUtil.java new file mode 100644 index 000000000..196fb231c --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/EntityTypeUtil.java @@ -0,0 +1,48 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.entity.EntityType; +import net.minecraft.registry.Registries; +import net.minecraft.text.Text; +import net.minecraft.util.Identifier; + +public class EntityTypeUtil { + public static Identifier toID(EntityType entityType) { + return Registries.ENTITY_TYPE.getId(entityType); + } + + public static EntityType fromId(Identifier identifier) { + return Registries.ENTITY_TYPE.get(identifier); + } + + public static boolean isExist(Identifier identifier) { + return Registries.ENTITY_TYPE.containsId(identifier); + } + + public static CompatIdentifier toCompatID(EntityType entityType) { + return CompatIdentifier.fromMinecraft(toID(entityType)); + } + + public static EntityType fromId(CompatIdentifier identifier) { + return fromId(identifier.toMinecraft()); + } + + public static boolean isExist(CompatIdentifier identifier) { + return isExist(identifier.toMinecraft()); + } + + public static int getRawId(EntityType type) { + return Registries.ENTITY_TYPE.getRawId(type); + } + + public static EntityType fromIndex(int index) { + return Registries.ENTITY_TYPE.get(index); + } + + public static Text getName(EntityType entityType) { + return entityType.getName(); + } + + public static String getTranslationKey(EntityType entityType) { + return entityType.getTranslationKey(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/EntityUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/EntityUtil.java new file mode 100644 index 000000000..291a4a252 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/EntityUtil.java @@ -0,0 +1,306 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.damage.DamageSource; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.text.Text; +import net.minecraft.util.BlockRotation; +import net.minecraft.util.math.Vec3d; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.entity.Player; +import net.pitan76.mcpitanlib.midohra.util.math.BlockPos; +import net.pitan76.mcpitanlib.midohra.util.math.Vector3d; + +import java.util.UUID; + +public class EntityUtil { + public static World getWorld(Entity entity) { + return entity.getWorld(); + } + + public static boolean damage(Entity target, DamageSource damageSource, float amount) { + return target.damage(damageSource, amount); + } + + public static boolean damageWithThrownProjectile(Entity target, float damageAmount, Entity projectile, Entity attacker) { + return target.damage(DamageSourceUtil.thrownProjectile(projectile, attacker), damageAmount); + } + + public static boolean damageWithMobProjectile(Entity target, float damageAmount, Entity projectile, LivingEntity attacker) { + return target.damage(DamageSourceUtil.mobProjectile(projectile, attacker), damageAmount); + } + + public static boolean damageWithMobAttack(Entity target, float damageAmount, Entity source, LivingEntity attacker) { + return target.damage(DamageSourceUtil.mobAttack(attacker, source), damageAmount); + } + + public static boolean damageWithPlayerAttack(Entity target, float damageAmount, Entity source, Player attacker) { + return target.damage(DamageSourceUtil.playerAttack(attacker, source), damageAmount); + } + + public static void discard(Entity entity) { + entity.discard(); + } + + public static void kill(Entity entity) { + entity.kill(); + } + + public static void setVelocity(Entity entity, double x, double y, double z) { + entity.setVelocity(x, y, z); + } + + public static Vec3d getVelocity(Entity entity) { + return entity.getVelocity(); + } + + public static void setNoGravity(Entity entity, boolean noGravity) { + entity.setNoGravity(noGravity); + } + + public static boolean hasNoGravity(Entity entity) { + return entity.hasNoGravity(); + } + + public static void setInvulnerable(Entity entity, boolean invulnerable) { + entity.setInvulnerable(invulnerable); + } + + public static boolean isInvulnerable(Entity entity) { + return entity.isInvulnerable(); + } + + public static void setSilent(Entity entity, boolean silent) { + entity.setSilent(silent); + } + + public static boolean isSilent(Entity entity) { + return entity.isSilent(); + } + + public static void setGlowing(Entity entity, boolean glowing) { + entity.setGlowing(glowing); + } + + public static boolean isGlowing(Entity entity) { + return entity.isGlowing(); + } + + public static void setFire(Entity entity, int seconds) { + entity.setOnFireFor(seconds); + } + + public static void extinguish(Entity entity) { + entity.extinguish(); + } + + public static boolean isOnFire(Entity entity) { + return entity.isOnFire(); + } + + public static void setInvisible(Entity entity, boolean invisible) { + entity.setInvisible(invisible); + } + + public static boolean isInvisible(Entity entity) { + return entity.isInvisible(); + } + + public static void setSneaking(Entity entity, boolean sneaking) { + entity.setSneaking(sneaking); + } + + public static boolean isSneaking(Entity entity) { + return entity.isSneaking(); + } + + public static void setSprinting(Entity entity, boolean sprinting) { + entity.setSprinting(sprinting); + } + + public static boolean isSprinting(Entity entity) { + return entity.isSprinting(); + } + + public static void setSwimming(Entity entity, boolean swimming) { + entity.setSwimming(swimming); + } + + public static boolean isSwimming(Entity entity) { + return entity.isSwimming(); + } + + public static void detach(Entity entity) { + entity.detach(); + } + + public static void attach(Entity entity, Entity vehicle) { + entity.startRiding(vehicle, true); + } + + public static void detachFromVehicle(Entity entity) { + entity.stopRiding(); + } + + public static boolean isRiding(Entity entity) { + return entity.hasVehicle(); + } + + public static Entity getVehicle(Entity entity) { + return entity.getVehicle(); + } + + public static void setVehicle(Entity entity, Entity vehicle) { + entity.startRiding(vehicle, true); + } + + public static void applyRotation(Entity entity, BlockRotation rotation) { + entity.applyRotation(rotation); + } + + public static void setVelocity(Entity entity, Vec3d velocity) { + entity.setVelocity(velocity); + } + + public static void setFallDistance(Entity entity, double fallDistance) { + entity.fallDistance = (float) fallDistance; + } + + public static double getFallDistance(Entity entity) { + return entity.fallDistance; + } + + public static void setVelocityModified(Entity entity, boolean velocityModified) { + entity.velocityModified = velocityModified; + } + + public static boolean isVelocityModified(Entity entity) { + return entity.velocityModified; + } + + public static float getYaw(Entity entity) { + return entity.getYaw(); + } + + public static float getPitch(Entity entity) { + return entity.getPitch(); + } + + public static void setYaw(Entity entity, float yaw) { + entity.setYaw(yaw); + } + + public static void setPitch(Entity entity, float pitch) { + entity.setPitch(pitch); + } + + public static float getSpeed(Entity entity) { + return entity.speed; + } + + public static void setSpeed(Entity entity, float speed) { + entity.speed = speed; + } + + public static boolean isOnGround(Entity entity) { + return entity.isOnGround(); + } + + public static void setOnGround(Entity entity, boolean onGround) { + entity.setOnGround(onGround); + } + + public static boolean isAlive(Entity entity) { + return entity.isAlive(); + } + + public static UUID getUuid(Entity entity) { + return entity.getUuid(); + } + + public static String getUuidString(Entity entity) { + return entity.getUuidAsString(); + } + + public static void setUuid(Entity entity, UUID uuid) { + entity.setUuid(uuid); + } + + public static Text getName(Entity entity) { + return entity.getName(); + } + + public static Text getDisplayName(Entity entity) { + return entity.getDisplayName(); + } + + public static void setCustomName(Entity entity, Text customName) { + entity.setCustomName(customName); + } + + public static Text getCustomName(Entity entity) { + return entity.getCustomName(); + } + + public static void setCustomNameVisible(Entity entity, boolean visible) { + entity.setCustomNameVisible(visible); + } + + public static boolean isCustomNameVisible(Entity entity) { + return entity.isCustomNameVisible(); + } + + public static boolean hasCustomName(Entity entity) { + return entity.hasCustomName(); + } + + public static String getNameAsString(Entity entity) { + return entity.getName().getString(); + } + + public static String getDisplayNameAsString(Entity entity) { + if (entity.getDisplayName() == null) + return null; + return entity.getDisplayName().getString(); + } + + public static String getCustomNameAsString(Entity entity) { + if (entity.getCustomName() == null) + return null; + return entity.getCustomName().getString(); + } + + public static void setCustomName(Entity entity, String customName) { + entity.setCustomName(TextUtil.literal(customName)); + } + + public static Vec3d getRotationVector(Entity entity) { + return entity.getRotationVector(); + } + + public static Vec3d getPos(Entity entity) { + return entity.getPos(); + } + + public static Vector3d getPosM(Entity entity) { + return Vector3d.of(getPos(entity)); + } + + public static void setPos(Entity entity, double x, double y, double z) { + entity.setPos(x, y, z); + } + + public static void addVelocity(Entity entity, double x, double y, double z) { + entity.addVelocity(x, y, z); + } + + public static void addVelocity(Entity entity, Vec3d velocity) { + entity.addVelocity(velocity); + } + + public static void addVelocity(Entity entity, Vector3d velocity) { + addVelocity(entity, velocity.toMinecraft()); + } + +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/EquipMaterialUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/EquipMaterialUtil.java new file mode 100644 index 000000000..e99799b58 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/EquipMaterialUtil.java @@ -0,0 +1,77 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.block.Block; +import net.minecraft.item.ToolMaterial; +import net.minecraft.recipe.Ingredient; +import net.minecraft.registry.tag.TagKey; +import net.minecraft.sound.SoundEvent; +import net.minecraft.util.Identifier; +import net.pitan76.mcpitanlib.api.item.ArmorEquipmentType; +import net.pitan76.mcpitanlib.api.item.CompatibleArmorMaterial; +import net.pitan76.mcpitanlib.api.item.tool.CompatibleToolMaterial; +import net.pitan76.mcpitanlib.api.tag.item.RepairIngredientTag; + +public class EquipMaterialUtil { + @Deprecated + public static ToolMaterial createToolMaterial(int durability, float miningSpeedMultiplier, float attackDamage, int miningLevel, int enchantability, Ingredient repairIngredient) { + return createToolMaterial(durability, miningSpeedMultiplier, attackDamage, miningLevel, enchantability, RepairIngredientTag.IRON_TOOL_MATERIALS); + } + + public static ToolMaterial createToolMaterial(int durability, float miningSpeedMultiplier, float attackDamage, int miningLevel, int enchantability, RepairIngredientTag ingredientTag) { + return new ToolMaterial() { + @Override + public int getDurability() { + return durability; + } + + @Override + public float getMiningSpeedMultiplier() { + return miningSpeedMultiplier; + } + + @Override + public float getAttackDamage() { + return attackDamage; + } + + @Override + public TagKey getInverseTag() { + return CompatibleToolMaterial.level2inverseTag(miningLevel); + } + + @Override + public int getEnchantability() { + return enchantability; + } + + @Override + public Ingredient getRepairIngredient() { + return ingredientTag.getIngredient(); + } + }; + } + + public static int toInt(ArmorEquipmentType type) { + switch (type.getSlot()) { + case HEAD: + return 0; + case CHEST: + return 1; + case LEGS: + return 2; + case FEET: + return 3; + default: + return 0; + } + } + + public static CompatibleArmorMaterial createArmorMaterial(int[] durability, int[] protection, int enchantability, SoundEvent equipSound, Ingredient repairIngredient, String name, float toughness, float knockbackResistance) { + return ArmorMaterialUtil.create(name, durability, protection, enchantability, equipSound, toughness, knockbackResistance, repairIngredient); + } + + @Deprecated + public static CompatibleArmorMaterial createArmorMaterial(int[] durability, int[] protection, int enchantability, SoundEvent equipSound, Ingredient repairIngredient, Identifier id, float toughness, float knockbackResistance) { + return ArmorMaterialUtil.create(id, durability, protection, enchantability, equipSound, toughness, knockbackResistance, repairIngredient); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/FeatureConfigUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/FeatureConfigUtil.java new file mode 100644 index 000000000..5b2a4a017 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/FeatureConfigUtil.java @@ -0,0 +1,81 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.registry.tag.BlockTags; +import net.minecraft.structure.rule.RuleTest; +import net.minecraft.structure.rule.TagMatchRuleTest; +import net.minecraft.world.gen.feature.ConfiguredFeature; +import net.minecraft.world.gen.feature.Feature; +import net.minecraft.world.gen.feature.OreFeatureConfig; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +public class FeatureConfigUtil { + + /** + * Create a new ConfiguredFeature + * @param oreFeatureConfig The ore feature config + * @return The new ConfiguredFeature + */ + public static ConfiguredFeature createConfiguredFeature(OreFeatureConfig oreFeatureConfig) { + return new ConfiguredFeature<>(Feature.ORE, oreFeatureConfig); + } + + /** + * Create a new OreFeatureConfig + * @param test The rule test + * @param state The block state + * @param size The size + * @return The new OreFeatureConfig + */ + public static OreFeatureConfig createOreFeatureConfig(RuleTest test, BlockState state, int size) { + return new OreFeatureConfig(test, state, size); + } + + /** + * Create a new OreFeatureConfig + * @param test The rule test + * @param block The block + * @param size The size + * @return The new OreFeatureConfig + */ + public static OreFeatureConfig createOreFeatureConfig(RuleTest test, Block block, int size) { + return createOreFeatureConfig(test, block.getDefaultState(), size); + } + + /** + * Create a new OreFeatureConfig + * @param targets The targets + * @param size The size + * @return The new OreFeatureConfig + */ + public static OreFeatureConfig createOreFeatureConfig(List targets, int size) { + return new OreFeatureConfig(targets, size); + } + + /** + * Create a new OreFeatureConfig + * @param targetMap The target map + * @param size The size + * @return The new OreFeatureConfig + */ + public static OreFeatureConfig createOreFeatureConfig(Map targetMap, int size) { + List targets = new ArrayList<>(); + targetMap.forEach((ruleTest, blockState) -> targets.add(OreFeatureConfig.createTarget(ruleTest, blockState))); + return createOreFeatureConfig(targets, size); + } + + /** + * Create a new OreFeatureConfig + * @param state The block state + * @param size The size + * @return The new OreFeatureConfig + */ + public static OreFeatureConfig createStoneOreFeatureConfig(BlockState state, int size) { + RuleTest ruleTest = new TagMatchRuleTest(BlockTags.BASE_STONE_OVERWORLD); + return createOreFeatureConfig(ruleTest, state, size); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/FluidStateUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/FluidStateUtil.java new file mode 100644 index 000000000..848547d07 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/FluidStateUtil.java @@ -0,0 +1,48 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.block.BlockState; +import net.minecraft.fluid.Fluid; +import net.minecraft.fluid.FluidState; +import net.minecraft.registry.tag.FluidTags; +import net.pitan76.mcpitanlib.midohra.fluid.FluidWrapper; +import net.pitan76.mcpitanlib.midohra.util.math.BlockPos; +import net.pitan76.mcpitanlib.midohra.world.World; + +public class FluidStateUtil { + public static boolean isWater(FluidState state) { + return state.isIn(FluidTags.WATER); + } + + public static boolean isLava(FluidState state) { + return state.isIn(FluidTags.LAVA); + } + + @Deprecated + public static FluidState getFluidState(BlockState state) { + return state.getFluidState(); + } + + public static FluidState getDefaultState(Fluid state) { + return state.getDefaultState(); + } + + public static Fluid getFluid(FluidState state) { + return state.getFluid(); + } + + public static FluidWrapper getFluidWrapper(FluidState state) { + return FluidWrapper.of(getFluid(state)); + } + + public static FluidWrapper getFluidWrapper(BlockState state) { + return getFluidWrapper(getFluidState(state)); + } + + public static FluidWrapper getFluidWrapper(net.pitan76.mcpitanlib.midohra.block.BlockState state) { + return getFluidWrapper(state.toMinecraft()); + } + + public static FluidWrapper getFluidWrapper(World world, BlockPos pos) { + return getFluidWrapper(world.getBlockState(pos)); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/FluidUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/FluidUtil.java new file mode 100644 index 000000000..8195dd203 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/FluidUtil.java @@ -0,0 +1,109 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.fluid.FlowableFluid; +import net.minecraft.fluid.Fluid; +import net.minecraft.fluid.FluidState; +import net.minecraft.fluid.Fluids; +import net.minecraft.item.Item; +import net.minecraft.registry.Registries; +import net.minecraft.util.Identifier; +import net.minecraft.world.WorldView; + +public class FluidUtil { + public static Identifier toID(Fluid fluid) { + return Registries.FLUID.getId(fluid); + } + + public static Fluid fromId(Identifier identifier) { + return Registries.FLUID.get(identifier); + } + + public static Fluid fromId(CompatIdentifier identifier) { + return fromId(identifier.toMinecraft()); + } + + public static int getRawId(Fluid fluid) { + return Registries.FLUID.getRawId(fluid); + } + + public static Fluid fromIndex(int index) { + return Registries.FLUID.get(index); + } + + public static boolean isExist(CompatIdentifier id) { + return Registries.FLUID.containsId(id.toMinecraft()); + } + + public static CompatIdentifier toCompatId(Fluid fluid) { + return CompatIdentifier.fromMinecraft(toID(fluid)); + } + + public static Fluid fromCompatId(CompatIdentifier id) { + return fromId(id.toMinecraft()); + } + + public static FlowableFluid water() { + return Fluids.WATER; + } + + public static FlowableFluid lava() { + return Fluids.LAVA; + } + + public static Fluid empty() { + return Fluids.EMPTY; + } + + public static FlowableFluid flowingWater() { + return Fluids.FLOWING_WATER; + } + + public static FlowableFluid flowingLava() { + return Fluids.FLOWING_LAVA; + } + + public static boolean isStill(Fluid fluid) { + return fluid == water() || fluid == lava(); + } + + public static boolean isStill(FluidState state) { + return state.isStill(); + } + + public static FluidState getStill(FlowableFluid fluid, boolean falling) { + return fluid.getStill(falling); + } + + public static FluidState getFlowing(FlowableFluid fluid, int level, boolean falling) { + return fluid.getFlowing(level, falling); + } + + public static FluidState getStill(FlowableFluid fluid) { + return getStill(fluid, false); + } + + public static FluidState getStillWater() { + return getStill(water()); + } + + public static FluidState getStillLava() { + return getStill(lava()); + } + + public static boolean isFlowing(Fluid fluid) { + return fluid == flowingWater() || fluid == flowingLava(); + } + + public static int getTickRate(Fluid fluid, WorldView world) { + return fluid.getTickRate(world); + } + + public static FluidState getDefaultState(Fluid fluid) { + return fluid.getDefaultState(); + } + + + public static Item getBucketItem(Fluid fluid) { + return fluid.getBucketItem(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/HandUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/HandUtil.java new file mode 100644 index 000000000..8690b4db9 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/HandUtil.java @@ -0,0 +1,38 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.entity.EquipmentSlot; +import net.minecraft.util.Hand; + +public class HandUtil { + public static Hand getOppositeHand(Hand hand) { + return hand == Hand.MAIN_HAND ? Hand.OFF_HAND : Hand.MAIN_HAND; + } + + public static EquipmentSlot getEquipmentSlot(Hand hand) { + return hand == Hand.MAIN_HAND ? EquipmentSlot.MAINHAND : EquipmentSlot.OFFHAND; + } + + public static Hand getHand(EquipmentSlot slot) { + return slot == EquipmentSlot.MAINHAND ? Hand.MAIN_HAND : Hand.OFF_HAND; + } + + public static Hand getHand(boolean mainHand) { + return mainHand ? Hand.MAIN_HAND : Hand.OFF_HAND; + } + + public static boolean isMainHand(Hand hand) { + return hand == Hand.MAIN_HAND; + } + + public static boolean isOffHand(Hand hand) { + return hand == Hand.OFF_HAND; + } + + public static boolean isMainHand(EquipmentSlot slot) { + return slot == EquipmentSlot.MAINHAND; + } + + public static boolean isOffHand(EquipmentSlot slot) { + return slot == EquipmentSlot.OFFHAND; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/IdentifierUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/IdentifierUtil.java new file mode 100644 index 000000000..2b2841b69 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/IdentifierUtil.java @@ -0,0 +1,32 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.util.Identifier; + +public class IdentifierUtil { + public static Identifier id(String id) { + return Identifier.of(id); + } + + public static Identifier id(String namespace, String path) { + return Identifier.of(namespace, path); + } + + public static String toString(Identifier identifier) { + return identifier.toString(); + } + + public static String getNamespace(Identifier identifier) { + return identifier.getNamespace(); + } + + public static String getPath(Identifier identifier) { + return identifier.getPath(); + } + + public static Identifier from(CompatIdentifier id) { + if (id == null) + return null; + + return id.toMinecraft(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/IngredientUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/IngredientUtil.java new file mode 100644 index 000000000..ef9f00870 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/IngredientUtil.java @@ -0,0 +1,74 @@ +package net.pitan76.mcpitanlib.api.util; + +import it.unimi.dsi.fastutil.ints.IntList; +import net.minecraft.item.Item; +import net.minecraft.item.ItemConvertible; +import net.minecraft.item.ItemStack; +import net.minecraft.recipe.Ingredient; +import net.minecraft.registry.Registries; +import net.minecraft.registry.tag.TagKey; +import net.minecraft.util.Identifier; +import net.minecraft.util.collection.DefaultedList; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class IngredientUtil { + public static Ingredient fromTagByIdentifier(Identifier id) { + return Ingredient.fromTag(TagKey.of(Registries.ITEM.getKey(), id)); + } + + public static Ingredient fromTagByString(String id) { + return fromTagByIdentifier(IdentifierUtil.id(id)); + } + + public static Ingredient fromTagByIdentifier(CompatIdentifier id) { + return fromTagByIdentifier(id.toMinecraft()); + } + + public static List getItems(Ingredient ingredient) { + List items = new ArrayList<>(); + for (int rawId : ingredient.getMatchingItemIds()) { + try { + items.add(ItemUtil.fromIndex(rawId)); + } catch (Exception ignored) {} + } + return items; + } + + public static IntList getMatchingStacksIds(Ingredient ingredient) { + return ingredient.getMatchingItemIds(); + } + + public static List getMatchingStacksAsList(Ingredient ingredient) { + return new ArrayList<>(Arrays.asList(getMatchingStacks(ingredient))); + } + + public static ItemStack[] getMatchingStacks(Ingredient ingredient) { + return ingredient.getMatchingStacks(); + } + + public static Ingredient empty() { + return Ingredient.EMPTY; + } + + public static Ingredient ofItems(ItemConvertible... items) { + return Ingredient.ofItems(items); + } + + public static DefaultedList buildInput(Object[] input) { + DefaultedList list = DefaultedList.of(); + for (Object obj : input) { + if (obj instanceof Ingredient) { + list.add((Ingredient) obj); + continue; + } + + if (obj instanceof ItemConvertible) { + list.add(ofItems((ItemConvertible) obj)); + } + } + return list; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/InteractUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/InteractUtil.java new file mode 100644 index 000000000..74ad850d4 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/InteractUtil.java @@ -0,0 +1,56 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.block.BlockState; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.item.ItemUsageContext; +import net.minecraft.util.hit.BlockHitResult; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.entity.Player; +import net.pitan76.mcpitanlib.api.event.item.ItemUseEvent; +import net.pitan76.mcpitanlib.api.event.item.ItemUseOnBlockEvent; +import net.pitan76.mcpitanlib.api.event.item.ItemUseOnEntityEvent; +import net.pitan76.mcpitanlib.api.item.args.UseActionArgs; +import net.pitan76.mcpitanlib.api.item.consume.CompatUseAction; + +public class InteractUtil { + + public static StackActionResult useItem(Item item, ItemUseEvent event) { + return StackActionResult.create(item.use(event.getWorld(), event.user.getEntity(), event.getHand())); + } + + public static CompatActionResult useItemOnBlock(Item item, ItemUsageContext context) { + return CompatActionResult.create(item.useOnBlock(context)); + } + + public static CompatActionResult useItemOnBlock(Item item, ItemUseOnBlockEvent event) { + return useItemOnBlock(item, event.toIUC()); + } + + public static CompatActionResult useItemOnEntity(Item item, ItemUseOnEntityEvent event) { + return CompatActionResult.create(item.useOnEntity(event.getStack(), event.getUser().getEntity(), event.getEntity(), event.getHand())); + } + + public static CompatUseAction getUseAction(Item item, UseActionArgs args) { + return CompatUseAction.of(item.getUseAction(args.stack)); + } + + public static CompatUseAction getUseAction(Item item, ItemStack stack) { + return CompatUseAction.of(item.getUseAction(stack)); + } + + public static CompatActionResult useBlock(BlockState state, World world, Player player, BlockHitResult hitResult) { + return BlockStateUtil.onUse(state, world, player, hitResult); + } + + public static CompatActionResult useBlock(BlockState state, World world, Player player, Direction dir, BlockPos blockPos) { + return BlockStateUtil.onUse(state, world, player, dir, blockPos); + } + + public static boolean onStoppingUsing(Item item, ItemStack stack, World world, Player player, int remainingUseTicks) { + item.onStoppedUsing(stack, world, player.getEntity(), remainingUseTicks); + return true; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/InventoryUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/InventoryUtil.java new file mode 100644 index 000000000..2829c34a9 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/InventoryUtil.java @@ -0,0 +1,155 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.inventory.Inventories; +import net.minecraft.inventory.Inventory; +import net.minecraft.inventory.SimpleInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NbtCompound; +import net.minecraft.util.collection.DefaultedList; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.event.nbt.NbtRWArgs; +import net.pitan76.mcpitanlib.api.registry.CompatRegistryLookup; + +public class InventoryUtil { + public static boolean insertItem(ItemStack insertStack, DefaultedList inventory) { + return insertItem(insertStack, inventory, false); + } + + public static boolean insertItem(ItemStack insertStack, DefaultedList inventory, boolean test) { + boolean isInserted = false; + for (int i = 0; i < inventory.size(); i++) { + ItemStack stack = inventory.get(i); + if (stack.isEmpty()) { + if (!test) inventory.set(i, insertStack); + isInserted = true; + break; + } else if (canMergeItems(stack, insertStack)) { + int j = insertStack.getCount(); + if (!test) stack.increment(j); + isInserted = j > 0; + break; + } + } + return isInserted; + + } + + public static boolean canMergeItems(ItemStack first, ItemStack second) { + if (!first.isOf(second.getItem())) { + return false; + } + if (first.getDamage() != second.getDamage()) { + return false; + } + if (first.getCount() + second.getCount() > first.getMaxCount()) { + return false; + } + return ItemStackUtil.areNbtOrComponentEqual(first, second); + } + + public static NbtCompound writeNbt(NbtRWArgs args, NbtCompound nbt, DefaultedList stacks, boolean setIfEmpty) { + return Inventories.writeNbt(nbt, stacks, setIfEmpty, args.getWrapperLookup()); + } + + public static void readNbt(NbtRWArgs args, NbtCompound nbt, DefaultedList stacks) { + Inventories.readNbt(nbt, stacks, args.getWrapperLookup()); + } + + public static NbtCompound writeNbt(NbtRWArgs args, DefaultedList stacks, boolean setIfEmpty) { + return writeNbt(args, args.getNbt(), stacks, setIfEmpty); + } + + public static NbtCompound writeNbt(NbtRWArgs args, DefaultedList stacks) { + return writeNbt(args, stacks, true); + } + + public static void readNbt(NbtRWArgs args, DefaultedList stacks) { + readNbt(args, args.getNbt(), stacks); + } + + public static void readNbt(CompatRegistryLookup registryLookup, NbtCompound nbt, DefaultedList stacks) { + Inventories.readNbt(nbt, stacks, registryLookup.getRegistryLookup()); + } + + public static NbtCompound writeNbt(CompatRegistryLookup registryLookup, NbtCompound nbt, DefaultedList stacks, boolean setIfEmpty) { + return Inventories.writeNbt(nbt, stacks, setIfEmpty, registryLookup.getRegistryLookup()); + } + + public static NbtCompound writeNbt(CompatRegistryLookup registryLookup, NbtCompound nbt, DefaultedList stacks) { + return writeNbt(registryLookup, nbt, stacks, true); + } + + // deprecated + /** + * @deprecated Use {@link #writeNbt(NbtRWArgs, DefaultedList)} instead + */ + @Deprecated + public static NbtCompound writeNbt(World world, NbtCompound nbt, DefaultedList stacks) { + return writeNbt(world, nbt, true, stacks); + } + + /** + * @deprecated Use {@link #writeNbt(NbtRWArgs, DefaultedList, boolean)} instead + */ + @Deprecated + public static NbtCompound writeNbt(World world, NbtCompound nbt, boolean setIfEmpty, DefaultedList stacks) { + return Inventories.writeNbt(nbt, stacks, setIfEmpty, world.getRegistryManager()); + } + + /** + * @deprecated Use {@link #readNbt(NbtRWArgs, DefaultedList)} instead + */ + @Deprecated + public static void readNbt(World world, NbtCompound nbt, DefaultedList stacks) { + Inventories.readNbt(nbt, stacks, world.getRegistryManager()); + } + // ---- + + public static SimpleInventory createSimpleInventory(int size) { + return new SimpleInventory(size); + } + + public static void copyToInv(DefaultedList from, Inventory to) { + for (int i = 0; i < from.size(); i++) { + to.setStack(i, from.get(i)); + } + } + + public static void copyToList(Inventory from, DefaultedList to) { + for (int i = 0; i < from.size(); i++) { + to.set(i, from.getStack(i)); + } + } + + public static int getSize(Inventory inventory) { + return inventory.size(); + } + + public static ItemStack getStack(Inventory inventory, int slot) { + return inventory.getStack(slot); + } + + public static void setStack(Inventory inventory, int slot, ItemStack stack) { + inventory.setStack(slot, stack); + } + + public static boolean isEmpty(Inventory inventory) { + return inventory.isEmpty(); + } + + public static ItemStack removeStack(Inventory inventory, int slot) { + return inventory.removeStack(slot); + } + + public static ItemStack removeStack(Inventory inventory, int slot, int amount) { + return inventory.removeStack(slot, amount); + } + + public static void clear(Inventory inventory) { + inventory.clear(); + } + + public static void markDirty(Inventory inventory) { + inventory.markDirty(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/ItemStackUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/ItemStackUtil.java new file mode 100644 index 000000000..95c879614 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/ItemStackUtil.java @@ -0,0 +1,184 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.entity.EquipmentSlot; +import net.minecraft.entity.LivingEntity; +import net.minecraft.item.Item; +import net.minecraft.item.ItemConvertible; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NbtCompound; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.entity.Player; +import net.pitan76.mcpitanlib.api.event.nbt.NbtRWArgs; +import net.pitan76.mcpitanlib.midohra.item.ItemWrapper; + +import java.util.Objects; +import java.util.Optional; + +public class ItemStackUtil { + public static ItemStack copy(ItemStack stack) { + return stack.copy(); + } + + public static ItemStack copyWithCount(ItemStack stack, int count) { + return stack.copyWithCount(count); + } + + public static boolean areItemsEqual(ItemStack left, ItemStack right) { + return ItemStack.areItemsEqual(left, right); + } + + @Deprecated + public static boolean areNbtEqual(ItemStack left, ItemStack right) { + return areNbtOrComponentEqual(left, right); + } + + /** + * NBT (1.20.4) か Component (1.20.5以降) が一致するかどうかを取得する。 + * @param left ItemStack + * @param right ItemStack + * @return NBTかComponentが一致するかどうか + */ + public static boolean areNbtOrComponentEqual(ItemStack left, ItemStack right) { + return Objects.equals(left.getComponents(), right.getComponents()); + } + + /** + * NBTかComponentが存在するかどうか + * @param stack ItemStack + * @return Whether NBT or Component exists + */ + public static boolean hasNbtOrComponent(ItemStack stack) { + return !stack.getComponents().isEmpty(); + } + + /** + * NBTからItemStackを取得する + * @param world World + * @param nbt NbtCompound + * @return ItemStack + */ + public static ItemStack fromNbt(World world, NbtCompound nbt) { + return ItemStack.fromNbt(world.getRegistryManager(), nbt).orElse(ItemStack.EMPTY); + } + + /** + * NBTからItemStackを取得する + * @param args NbtRWArgs + * @return ItemStack + */ + public static ItemStack fromNbt(NbtRWArgs args) { + return ItemStack.fromNbt(args.getWrapperLookup(), args.getNbt()).orElse(ItemStack.EMPTY); + } + + public static ItemStack getDefaultStack(Item item) { + return item.getDefaultStack(); + } + + public static int getMaxDamage(ItemStack stack) { + return stack.getMaxDamage(); + } + + public static int getMaxDamage(Item item) { + return getMaxDamage(getDefaultStack(item)); + } + + public static int getDamage(ItemStack stack) { + return stack.getDamage(); + } + + public static void setDamage(ItemStack stack, int damage) { + stack.setDamage(damage); + } + + public static int getCount(ItemStack stack) { + return stack.getCount(); + } + + public static void setCount(ItemStack stack, int count) { + stack.setCount(count); + } + + public static void decrementCount(ItemStack stack, int count) { + stack.decrement(count); + } + + public static void incrementCount(ItemStack stack, int count) { + stack.increment(count); + } + + public static void damage(ItemStack stack, int amount, ServerPlayerEntity entity, Runnable breakCallback) { + stack.damage(amount, entity.getServerWorld(), entity, (item) -> breakCallback.run()); + } + + public static void damage(ItemStack stack, int amount, LivingEntity entity, EquipmentSlot slot) { + stack.damage(amount, entity, slot); + } + + public static void damage(ItemStack stack, int amount, ServerPlayerEntity entity) { + stack.damage(amount, entity.getServerWorld(), entity, (item) -> entity.sendEquipmentBreakStatus(item, EquipmentSlot.MAINHAND)); + } + + public static void damage(ItemStack stack, int amount, Player entity) { + Optional player = entity.getServerPlayer(); + if (player.isEmpty()) return; + + damage(stack, amount, player.get()); + } + + public static ItemStack empty() { + return ItemStack.EMPTY; + } + + public static ItemStack create(Item item) { + if (item == null) return empty(); + return new ItemStack(item); + } + + public static ItemStack create(Item item, int count) { + if (item == null) return empty(); + return new ItemStack(item, count); + } + + public static ItemStack create(ItemConvertible item) { + if (item == null) return empty(); + return new ItemStack(item); + } + + public static ItemStack create(ItemConvertible item, int count) { + if (item == null) return empty(); + return new ItemStack(item, count); + } + + public static boolean isEmpty(ItemStack stack) { + if (stack == null) return true; + return stack.isEmpty(); + } + + public static boolean isEnchantable(ItemStack stack) { + return stack.isEnchantable(); + } + + public static boolean isDamageable(ItemStack stack) { + return stack.isDamageable(); + } + + public static boolean isBreak(ItemStack stack) { + if (isDamageable(stack)) + return getDamage(stack) >= getMaxDamage(stack); + + return false; + } + + public static ItemWrapper getItemWrapper(ItemStack stack) { + return ItemWrapper.of(stack.getItem()); + } + + public static int getMaxCount(ItemStack stack) { + return stack.getMaxCount(); + } + + public static Item getItem(ItemStack stack) { + return stack.getItem(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/ItemUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/ItemUtil.java new file mode 100644 index 000000000..70cfe5a75 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/ItemUtil.java @@ -0,0 +1,275 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.block.Block; +import net.minecraft.item.BlockItem; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.Identifier; +import net.pitan76.mcpitanlib.api.item.CompatibleItemSettings; +import net.pitan76.mcpitanlib.api.tag.TagKey; +import net.pitan76.mcpitanlib.api.util.v1.ItemUtilV1; +import net.pitan76.mcpitanlib.api.util.v2.ItemUtilV2; + +import java.util.List; + +@Deprecated +public class ItemUtil { + + /** + * Get item from Identifier. + * @param id Identifier of the item. + * @return Item of the Identifier. + */ + public static Item item(Identifier id) { + return ItemUtilV1.item(id); + } + + /** + * Check if two items are equal. + * @param item Item to compare. + * @param item2 Item to compare. + * @return If two items are equal. + */ + public static boolean isEqual(Item item, Item item2) { + return ItemUtilV1.isEqual(item, item2); + } + + /** + * Check if the item is of the given item. + * @param stack ItemStack to check. + * @param item Item to check. + * @return If the item is of the given item. + */ + public static boolean isOf(ItemStack stack, Item item) { + return ItemUtilV1.isOf(stack, item); + } + + /** + * Check if the item is in the tag. (MCPitanLib TagKey) + * @param stack ItemStack to check. + * @param tagKey TagKey of the tag. + * @return If the item is in the tag. + */ + public static boolean isIn(ItemStack stack, TagKey tagKey) { + return ItemUtilV1.isIn(stack, tagKey); + } + + /** + * Check if the item is in the tag. (MCPitanLib TagKey) + * @param item Item to check. + * @param tagKey TagKey of the tag. + * @return If the item is in the tag. + */ + public static boolean isIn(Item item, TagKey tagKey) { + return ItemUtilV1.isIn(item, tagKey); + } + + /** + * Check if the item is existed. + * @param identifier Identifier of the item. + * @return If the item is existed. + */ + public static boolean isExist(Identifier identifier) { + return ItemUtilV1.isExist(identifier); + } + + /** + * Get Identifier from Item. + * @param item Item to get Identifier. + * @return Identifier of the Item. + */ + public static Identifier toID(Item item) { + return ItemUtilV1.toID(item); + } + + /** + * Get item from Identifier. + * @param identifier Identifier of the item. + * @return Item of the Identifier. + */ + public static Item fromId(Identifier identifier) { + return ItemUtilV1.fromId(identifier); + } + + /** + * Get CompatIdentifier from Item. + * @param item Item to get CompatIdentifier. + * @return CompatIdentifier of the Item. + */ + public static CompatIdentifier toCompatID(Item item) { + return CompatIdentifier.fromMinecraft(toID(item)); + } + + /** + * Get item from CompatIdentifier. + * @param identifier CompatIdentifier of the item. + * @return Item of the CompatIdentifier. + */ + public static Item fromId(CompatIdentifier identifier) { + return fromId(identifier.toMinecraft()); + } + + /** + * Check if the item is existed. + * @param identifier CompatIdentifier of the item. + * @return If the item is existed. + */ + public static boolean isExist(CompatIdentifier identifier) { + return isExist(identifier.toMinecraft()); + } + + /** + * Create BlockItem from Block and Item.Settings. + * @param block Block to create BlockItem. + * @param settings Item.Settings to create BlockItem. + * @return BlockItem created from Block and Item.Settings. + */ + @Deprecated + public static BlockItem ofBlock(Block block, Item.Settings settings) { + return ItemUtilV1.ofBlock(block, settings); + } + + /** + * Create BlockItem from Block and CompatibleItemSettings. + * @param block Block to create BlockItem. + * @param settings CompatibleItemSettings to create BlockItem. + * @return BlockItem created from Block and CompatibleItemSettings. + */ + public static BlockItem ofBlock(Block block, CompatibleItemSettings settings) { + return ItemUtilV1.ofBlock(block, settings); + } + + /** + * Create Item from Item.Settings. + * @param settings Item.Settings to create Item. + * @return Item created from Item.Settings. + */ + @Deprecated + public static Item of(Item.Settings settings) { + return ItemUtilV1.of(settings); + } + + /** + * Create Item from CompatibleItemSettings. + * @param settings CompatibleItemSettings to create Item. + * @return Item created from CompatibleItemSettings. + */ + public static Item of(CompatibleItemSettings settings) { + return ItemUtilV1.of(settings); + } + + /** + * Get all items. + * @return List of all items. + */ + public static List getAllItems() { + return ItemUtilV1.getAllItems(); + } + + /** + * Get raw id of the item. + * @param item Item to get raw id. + * @return Raw id of the item. + */ + public static int getRawId(Item item) { + return ItemUtilV1.getRawId(item); + } + + /** + * Get item from index. + * @param index Index of the item. + * @return Item of the index. + */ + public static Item fromIndex(int index) { + return ItemUtilV1.fromIndex(index); + } + + /** + * Get all items in the tag. (MCPitanLib TagKey) + * @param tagKey TagKey of the tag. + * @return List of items in the tag. + */ + public static List getItems(TagKey tagKey) { + return ItemUtilV2.getItems(tagKey); + } + + /** + * Get given the list of items in the tag. (MCPitanLib TagKey) + * @param tagKey TagKey of the tag. + * @param items List of items to search. + * @return List of items in the tag. + */ + public static List getItems(TagKey tagKey, List items) { + return ItemUtilV2.getItems(tagKey, items); + } + + /** + * Get all items in the tag. + * @param identifier Identifier of the tag. + * @return List of items in the tag. + */ + public static List getItems(Identifier identifier) { + return ItemUtilV2.getItems(identifier); + } + + /** + * Get given the list of items in the tag. + * @param identifier Identifier of the tag. + * @param items List of items to search. + * @return List of items in the tag. + */ + public static List getItems(Identifier identifier, List items) { + return ItemUtilV2.getItems(identifier, items); + } + + public static List getItems(CompatIdentifier identifier) { + return getItems(identifier.toMinecraft()); + } + + public static List getItems(CompatIdentifier identifier, List items) { + return getItems(identifier.toMinecraft(), items); + } + + /** + * Get all items in the tag. + * @param id String of the tag. + * @return List of items in the tag. + */ + public static List getItems(String id) { + return ItemUtilV2.getItems(id); + } + + /** + * Get given the list of items in the tag. + * @param id String of the tag. + * @param items List of items to search. + * @return List of items in the tag. + */ + public static List getItems(String id, List items) { + return ItemUtilV2.getItems(id, items); + } + + /** + * Check if the item is in the tag. + * @param item Item to check. + * @param identifier Identifier of the tag. + * @return If the item is in the tag. + */ + public static boolean isItemInTag(Item item, Identifier identifier) { + return ItemUtilV2.isItemInTag(item, identifier); + } + + public static boolean isItemInTag(Item item, CompatIdentifier identifier) { + return isItemInTag(item, identifier.toMinecraft()); + } + + /** + * Check if the item is in the tag. + * @param item Item to check. + * @param id String of the tag. + * @return If the item is in the tag. + */ + public static boolean isItemInTag(Item item, String id) { + return ItemUtilV2.isItemInTag(item, id); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/Logger.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/Logger.java new file mode 100644 index 000000000..00967c3cb --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/Logger.java @@ -0,0 +1,190 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.util.client.ClientUtil; + +public class Logger { + public String name = ""; + + public boolean usingPrefix = true; + + private final org.apache.logging.log4j.Logger logger; + + public Logger(String name) { + this.name = name; + this.logger = LoggerUtil.getLogger(name); + } + + public Logger() { + this.logger = LoggerUtil.getLogger(); + } + + public Logger(Class clazz) { + this.logger = LoggerUtil.getLogger(clazz); + } + + public Logger(String name, boolean usePrefix) { + this(name); + usePrefix(usePrefix); + } + + public org.apache.logging.log4j.Logger getLogger() { + return logger; + } + + public void info(String message) { + LoggerUtil.info(logger, message); + } + + public void warn(String message) { + LoggerUtil.warn(logger, message); + } + + public void error(String message) { + LoggerUtil.error(logger, message); + } + + public void debug(String message) { + LoggerUtil.debug(logger, message); + } + + public void infoIfDev(String message) { + if (!PlatformUtil.isDevelopmentEnvironment()) return; + LoggerUtil.debug(logger, message); + } + + public void trace(String message) { + LoggerUtil.trace(logger, message); + } + + // ---- + + public void error(Exception e) { + error(e.getMessage()); + } + + public void initializeMessage() { + info(prefix() + "Initializing..."); + } + + public void initializedMessage() { + info(prefix() + "Initialized"); + } + + public String prefix() { + if (name.isEmpty() || !isUsingPrefix()) + return ""; + + return "[" + name + "] "; + } + + public void usePrefix(boolean use) { + usingPrefix = use; + } + + public boolean isUsingPrefix() { + return usingPrefix; + } + + /** + * Log message + * @param message log message + * @param isDebug if true, log as debug + */ + public void log(String message, boolean isDebug) { + if (isDebug) { + debug(message); + return; + } + info(message); + } + + public void log_onClientTick(int tick, String message, boolean isDebug) { + if (!PlatformUtil.isClient()) return; + long time = ClientUtil.getRenderTime(); + if (time % tick != 0) return; + + log(message, isDebug); + } + + public void log_onWorldTick(int tick, String message, World world, boolean isDebug) { + long time = WorldUtil.getTime(world); + if (time % tick != 0) return; + + log(message, isDebug); + } + + public void log_onSystemTick(int tick, String message, boolean isDebug) { + long millis = System.currentTimeMillis(); + long time = millis / 1000 * 60; + + if (time % tick != 0) return; + + log(message, isDebug); + } + + public void log_onClientTick(int tick, String message) { + log_onClientTick(tick, message, false); + } + + public void log_onWorldTick(int tick, String message, World world) { + log_onWorldTick(tick, message, world, false); + } + + public void log_onSystemTick(int tick, String message) { + log_onSystemTick(tick, message, false); + } + + /** + * Log message every second on ClientTick + * @param message log message + * @param isDebug if true, log as debug + */ + public void log_onClientTick(String message, boolean isDebug) { + log_onClientTick(60, message, isDebug); + } + + /** + * Log message every second on WorldTick + * @param message log message + * @param world world + * @param isDebug if true, log as debug + */ + public void log_onWorldTick(String message, World world, boolean isDebug) { + log_onWorldTick(60, message, world, isDebug); + } + + /** + * Log message every second on SystemTick + * @param message log message + * @param isDebug if true, log as debug + */ + public void log_onSystemTick(String message, boolean isDebug) { + log_onSystemTick(60, message, isDebug); + } + + /** + * Log message every second on ClientTick + * @param message log message + */ + public void log_onClientTick(String message) { + log_onClientTick(message, false); + } + + /** + * Log message every second on WorldTick + * @param message log message + * @param world world + */ + public void log_onWorldTick(String message, World world) { + log_onWorldTick(message, world, false); + } + + /** + * Log message every second on SystemTick + * @param message log message + */ + public void log_onSystemTick(String message) { + log_onSystemTick(message, false); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/LoggerUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/LoggerUtil.java new file mode 100644 index 000000000..666a367b5 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/LoggerUtil.java @@ -0,0 +1,38 @@ +package net.pitan76.mcpitanlib.api.util; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +public class LoggerUtil { + public static Logger getLogger(String name) { + return LogManager.getLogger(name); + } + + public static Logger getLogger(Class clazz) { + return LogManager.getLogger(clazz); + } + + public static Logger getLogger() { + return LogManager.getLogger(); + } + + public static void info(Logger logger, String message) { + logger.info(message); + } + + public static void warn(Logger logger, String message) { + logger.warn(message); + } + + public static void error(Logger logger, String message) { + logger.error(message); + } + + public static void debug(Logger logger, String message) { + logger.debug(message); + } + + public static void trace(Logger logger, String message) { + logger.trace(message); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/MCVersionUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/MCVersionUtil.java new file mode 100644 index 000000000..7ec6e5315 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/MCVersionUtil.java @@ -0,0 +1,19 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.SharedConstants; +import net.pitan76.mcpitanlib.api.util.client.ClientUtil; + +public class MCVersionUtil { + + public static int getProtocolVersion() { + return SharedConstants.getProtocolVersion(); + } + + public static String getGameVersion() { + return ClientUtil.getClient().getGameVersion(); + } + + public static boolean isSupportedComponent() { + return SharedConstants.getProtocolVersion() >= 766; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/MathUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/MathUtil.java new file mode 100644 index 000000000..2cb21eb12 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/MathUtil.java @@ -0,0 +1,33 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.util.math.RotationAxis; +import net.pitan76.mcpitanlib.api.util.math.random.CompatRandom; +import org.joml.Quaternionf; + +public class MathUtil { + + public static CompatRandom createRandom(long seed) { + return CompatRandom.of(seed); + } + + public static CompatRandom createRandom() { + return CompatRandom.of(); + } + + @Deprecated + public static Quaternionf getRotationDegrees(RotationAxisType type, float deg) { + return type.axis.rotationDegrees(deg); + } + + public static class RotationAxisType { + + public static RotationAxisType POSITIVE_X = new RotationAxisType(RotationAxis.POSITIVE_X); + public static RotationAxisType POSITIVE_Y = new RotationAxisType(RotationAxis.POSITIVE_Y); + public static RotationAxisType POSITIVE_Z = new RotationAxisType(RotationAxis.POSITIVE_Z); + + protected final RotationAxis axis; + protected RotationAxisType(RotationAxis axis) { + this.axis = axis; + } + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/NbtUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/NbtUtil.java new file mode 100644 index 000000000..013f1cd04 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/NbtUtil.java @@ -0,0 +1,554 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.*; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Vec3d; +import net.minecraft.util.math.Vec3i; +import net.pitan76.mcpitanlib.api.registry.CompatRegistryLookup; +import net.pitan76.mcpitanlib.api.util.math.PosUtil; +import net.pitan76.mcpitanlib.api.util.math.Vec3dUtil; +import net.pitan76.mcpitanlib.api.util.math.Vec3iUtil; + +import java.util.Optional; +import java.util.Set; +import java.util.UUID; + +public class NbtUtil { + + /** + * 新しいNbtCompoundを作成する。 + * @return NbtCompound + */ + public static NbtCompound create() { + return new NbtCompound(); + } + + /** + * 値を設定する。 + * @param nbt NbtCompound + * @param key キー + * @param value 値 + */ + public static void put(NbtCompound nbt, String key, NbtCompound value) { + nbt.put(key, value); + } + + /** + * 値を設定する。 + * @param nbt NbtCompound + * @param key キー + * @param value 値 + */ + public static void put(NbtCompound nbt, String key, NbtElement value) { + nbt.put(key, value); + } + + /** + * 値を取得する。 + * @param nbt NbtCompound + * @param key キー + * @return 値 + */ + public static NbtCompound get(NbtCompound nbt, String key) { + return nbt.getCompound(key); + } + + /** + * 値を削除する。 + * @param nbt NbtCompound + * @param key キー + */ + public static void remove(NbtCompound nbt, String key) { + nbt.remove(key); + } + + /** + * 値が存在するかどうかを取得する。 + * @param nbt NbtCompound + * @param key キー + * @return 値が存在するかどうか + */ + public static boolean has(NbtCompound nbt, String key) { + return nbt.contains(key); + } + + /** + * 指定した型の値を取得する + * @param nbt NbtCompound + * @param key キー + * @param clazz クラス + * @param 値 + */ + public static T get(NbtCompound nbt, String key, Class clazz) { + if (clazz == Integer.class) { + return (T) Integer.valueOf(nbt.getInt(key)); + } + if (clazz == String.class) { + return (T) nbt.getString(key); + } + if (clazz == Boolean.class) { + return (T) Boolean.valueOf(nbt.getBoolean(key)); + } + if (clazz == Float.class) { + return (T) Float.valueOf(nbt.getFloat(key)); + } + if (clazz == Double.class) { + return (T) Double.valueOf(nbt.getDouble(key)); + } + if (clazz == Long.class) { + return (T) Long.valueOf(nbt.getLong(key)); + } + if (clazz == NbtCompound.class) { + return (T) nbt.getCompound(key); + } + if (clazz == NbtList.class) { + return (T) nbt.get(key); + } + if (clazz == Byte.class) { + return (T) Byte.valueOf(nbt.getByte(key)); + } + if (clazz == Short.class) { + return (T) Short.valueOf(nbt.getShort(key)); + } + if (clazz == UUID.class) { + return (T) nbt.getUuid(key); + } + return null; + } + + /** + * 値を設定する。 + * @param nbt NbtCompound + * @param key キー + * @param value 値 + */ + public static void set(NbtCompound nbt, String key, T value) { + if (value instanceof Integer) { + nbt.putInt(key, (Integer) value); + return; + } + if (value instanceof String) { + nbt.putString(key, (String) value); + return; + } + if (value instanceof Boolean) { + nbt.putBoolean(key, (Boolean) value); + return; + } + if (value instanceof Float) { + nbt.putFloat(key, (Float) value); + return; + } + if (value instanceof Double) { + nbt.putDouble(key, (Double) value); + return; + } + if (value instanceof Long) { + nbt.putLong(key, (Long) value); + return; + } + if (value instanceof NbtCompound) { + nbt.put(key, (NbtCompound) value); + return; + } + if (value instanceof NbtList) { + nbt.put(key, (NbtList) value); + return; + } + if (value instanceof Byte) { + nbt.putByte(key, (Byte) value); + return; + } + if (value instanceof Short) { + nbt.putShort(key, (Short) value); + return; + } + if (value instanceof UUID) { + nbt.putUuid(key, (UUID) value); + return; + } + } + + /** + * キーの一覧を取得する。 + * @param nbt NbtCompound + * @return キーの一覧 + */ + public static Set getKeys(NbtCompound nbt) { + return nbt.getKeys(); + } + + /** + * NbtListを取得する。 + * @return NbtList + */ + public static NbtList getList(NbtCompound nbt, String key) { + return (NbtList) nbt.get(key); + } + + /** + * NbtListを取得する。 + * @return NbtList + */ + public static NbtList getList(NbtCompound nbt, String key, int type) { + return nbt.getList(key, type); + } + + /** + * NbtCompoundのリストを取得する。 + * @return NbtList + */ + public static NbtList getNbtCompoundList(NbtCompound nbt, String key) { + return nbt.getList(key, NbtElement.COMPOUND_TYPE); + } + + /** + * NbtCompoundをコピーする。 + * @return NbtCompound + */ + public static NbtCompound copy(NbtCompound nbt) { + return nbt.copy(); + } + + // Helper methods + + public static void putInt(NbtCompound nbt, String key, int value) { + set(nbt, key, value); + } + + public static int getInt(NbtCompound nbt, String key) { + if (has(nbt, key)) + return get(nbt, key, Integer.class); + return 0; + } + + public static void putString(NbtCompound nbt, String key, String value) { + set(nbt, key, value); + } + + public static String getString(NbtCompound nbt, String key) { + if (has(nbt, key)) + return get(nbt, key, String.class); + return ""; + } + + public static void putBoolean(NbtCompound nbt, String key, boolean value) { + set(nbt, key, value); + } + + public static boolean getBoolean(NbtCompound nbt, String key) { + if (has(nbt, key)) + return get(nbt, key, Boolean.class); + return false; + } + + public static void putFloat(NbtCompound nbt, String key, float value) { + set(nbt, key, value); + } + + public static float getFloat(NbtCompound nbt, String key) { + if (has(nbt, key)) + return get(nbt, key, Float.class); + return 0; + } + + public static void putDouble(NbtCompound nbt, String key, double value) { + set(nbt, key, value); + } + + public static double getDouble(NbtCompound nbt, String key) { + if (has(nbt, key)) + return get(nbt, key, Double.class); + return 0; + } + + public static void putLong(NbtCompound nbt, String key, long value) { + set(nbt, key, value); + } + + public static long getLong(NbtCompound nbt, String key) { + if (has(nbt, key)) + return get(nbt, key, Long.class); + return 0; + } + + public static void putByte(NbtCompound nbt, String key, byte value) { + set(nbt, key, value); + } + + public static byte getByte(NbtCompound nbt, String key) { + if (has(nbt, key)) + return get(nbt, key, Byte.class); + return 0; + } + + public static void putShort(NbtCompound nbt, String key, short value) { + set(nbt, key, value); + } + + public static short getShort(NbtCompound nbt, String key) { + if (has(nbt, key)) + return get(nbt, key, Short.class); + return 0; + } + + public static void putUuid(NbtCompound nbt, String key, UUID value) { + set(nbt, key, value); + } + + public static UUID getUuid(NbtCompound nbt, String key) { + if (has(nbt, key)) + return get(nbt, key, UUID.class); + return null; + } + + /** + * BlockPosを設定する。 + * key: { + * "x": pos.getX(), + * "y": pos.getY(), + * "z": pos.getZ() + * } + * + * @param nbt NbtCompound + * @param key キー + * @param pos BlockPos + */ + public static void setBlockPos(NbtCompound nbt, String key, BlockPos pos) { + NbtCompound posNbt = create(); + putInt(posNbt, "x", pos.getX()); + putInt(posNbt, "y", pos.getY()); + putInt(posNbt, "z", pos.getZ()); + put(nbt, key, posNbt); + } + + /** + * BlockPosを取得する。 + * + * @param nbt NbtCompound + * @param key キー + * @return BlockPos + */ + public static BlockPos getBlockPos(NbtCompound nbt, String key) { + NbtCompound posNbt = get(nbt, key); + return PosUtil.flooredBlockPos(getInt(posNbt, "x"), getInt(posNbt, "y"), getInt(posNbt, "z")); + } + + public static void putVec3i(NbtCompound nbt, String key, Vec3i vec3i) { + NbtCompound vec3iNbt = create(); + putInt(vec3iNbt, "x", vec3i.getX()); + putInt(vec3iNbt, "y", vec3i.getY()); + putInt(vec3iNbt, "z", vec3i.getZ()); + put(nbt, key, vec3iNbt); + } + + public static Vec3i getVec3i(NbtCompound nbt, String key) { + NbtCompound vec3iNbt = get(nbt, key); + return Vec3iUtil.create(getInt(vec3iNbt, "x"), getInt(vec3iNbt, "y"), getInt(vec3iNbt, "z")); + } + + public static void putVec3d(NbtCompound nbt, String key, Vec3d vec3d) { + NbtCompound vec3dNbt = create(); + putDouble(vec3dNbt, "x", vec3d.getX()); + putDouble(vec3dNbt, "y", vec3d.getY()); + putDouble(vec3dNbt, "z", vec3d.getZ()); + put(nbt, key, vec3dNbt); + } + + public static Vec3d getVec3d(NbtCompound nbt, String key) { + NbtCompound vec3dNbt = get(nbt, key); + return Vec3dUtil.create(getDouble(vec3dNbt, "x"), getDouble(vec3dNbt, "y"), getDouble(vec3dNbt, "z")); + } + + public static void putItemStack(NbtCompound nbt, String key, ItemStack stack, CompatRegistryLookup registryLookup) { + NbtElement stackNbt = stack.encode(registryLookup.getRegistryLookup()); + put(nbt, key, stackNbt); + } + + public static Optional getItemStack(NbtCompound nbt, String key, CompatRegistryLookup registryLookup) { + NbtElement stackNbt = get(nbt, key); + return ItemStack.fromNbt(registryLookup.getRegistryLookup(), stackNbt); + } + + public static void putSimpleItemStack(NbtCompound nbt, String key, ItemStack stack) { + NbtCompound stackNbt = create(); + putString(stackNbt, "id", ItemUtil.toID(stack.getItem()).toString()); + putByte(stackNbt, "Count", (byte) ItemStackUtil.getCount(stack)); + + NbtCompound tagNbt = create(); + NbtCompound componentsNbt = create(); + put(componentsNbt, "minecraft:custom_data", CustomDataUtil.getOrCreateNbt(stack)); + put(tagNbt, "components", componentsNbt); + put(stackNbt, "tag", tagNbt); + put(nbt, key, stackNbt); + } + + public static Optional getSimpleItemStack(NbtCompound nbt, String key) { + if (!has(nbt, key)) return Optional.empty(); + NbtCompound stackNbt = get(nbt, key); + + if (!has(stackNbt, "id") || !has(stackNbt, "Count")) return Optional.empty(); + Item item = ItemUtil.fromId(CompatIdentifier.of(getString(stackNbt, "id"))); + int count = getByte(stackNbt, "Count"); + + ItemStack stack = ItemStackUtil.create(item, count); + + if (has(stackNbt, "tag")) { + NbtCompound tagNbt = get(stackNbt, "tag"); + if (has(tagNbt, "components")) { + NbtCompound componentsNbt = get(tagNbt, "components"); + if (has(componentsNbt, "minecraft:custom_data")) { + CustomDataUtil.setNbt(stack, get(componentsNbt, "minecraft:custom_data")); + } + } + } + + return Optional.of(stack); + } + + public static NbtList createNbtList() { + return new NbtList(); + } + + public static int getIntOrDefault(NbtCompound nbt, String key, int defaultValue) { + if (has(nbt, key)) + return getInt(nbt, key); + return defaultValue; + } + + public static String getStringOrDefault(NbtCompound nbt, String key, String defaultValue) { + if (has(nbt, key)) + return getString(nbt, key); + return defaultValue; + } + + public static boolean getBooleanOrDefault(NbtCompound nbt, String key, boolean defaultValue) { + if (has(nbt, key)) + return getBoolean(nbt, key); + return defaultValue; + } + + public static float getFloatOrDefault(NbtCompound nbt, String key, float defaultValue) { + if (has(nbt, key)) + return getFloat(nbt, key); + return defaultValue; + } + + public static double getDoubleOrDefault(NbtCompound nbt, String key, double defaultValue) { + if (has(nbt, key)) + return getDouble(nbt, key); + return defaultValue; + } + + public static long getLongOrDefault(NbtCompound nbt, String key, long defaultValue) { + if (has(nbt, key)) + return getLong(nbt, key); + return defaultValue; + } + + public static byte getByteOrDefault(NbtCompound nbt, String key, byte defaultValue) { + if (has(nbt, key)) + return getByte(nbt, key); + return defaultValue; + } + + public static short getShortOrDefault(NbtCompound nbt, String key, short defaultValue) { + if (has(nbt, key)) + return getShort(nbt, key); + return defaultValue; + } + + public static UUID getUuidOrDefault(NbtCompound nbt, String key, UUID defaultValue) { + if (has(nbt, key)) + return getUuid(nbt, key); + return defaultValue; + } + + public static NbtElement getElement(NbtCompound nbt, String key) { + return nbt.get(key); + } + + public static void putElement(NbtCompound nbt, String key, NbtElement element) { + nbt.put(key, element); + } + + public static void setBlockPosDirect(NbtCompound nbt, BlockPos pos) { + putInt(nbt, "x", pos.getX()); + putInt(nbt, "y", pos.getY()); + putInt(nbt, "z", pos.getZ()); + } + + public static BlockPos getBlockPosDirect(NbtCompound nbt) { + return PosUtil.flooredBlockPos(getInt(nbt, "x"), getInt(nbt, "y"), getInt(nbt, "z")); + } + + public static void setVec3iDirect(NbtCompound nbt, Vec3i vec3i) { + putInt(nbt, "x", vec3i.getX()); + putInt(nbt, "y", vec3i.getY()); + putInt(nbt, "z", vec3i.getZ()); + } + + public static Vec3i getVec3iDirect(NbtCompound nbt) { + return Vec3iUtil.create(getInt(nbt, "x"), getInt(nbt, "y"), getInt(nbt, "z")); + } + + public static void setVec3dDirect(NbtCompound nbt, Vec3d vec3d) { + putDouble(nbt, "x", vec3d.getX()); + putDouble(nbt, "y", vec3d.getY()); + putDouble(nbt, "z", vec3d.getZ()); + } + + public static Vec3d getVec3dDirect(NbtCompound nbt) { + return Vec3dUtil.create(getDouble(nbt, "x"), getDouble(nbt, "y"), getDouble(nbt, "z")); + } + + public static void setVec3iDirect(NbtCompound nbt, int x, int y, int z) { + putInt(nbt, "x", x); + putInt(nbt, "y", y); + putInt(nbt, "z", z); + } + + public static void setVec3dDirect(NbtCompound nbt, double x, double y, double z) { + putDouble(nbt, "x", x); + putDouble(nbt, "y", y); + putDouble(nbt, "z", z); + } + + public static String asString(NbtElement nbt) { + return nbt.asString(); + } + + public static NbtString createString(String string) { + return NbtString.of(string); + } + + public static NbtInt createInt(int value) { + return NbtInt.of(value); + } + + public static NbtFloat createFloat(float value) { + return NbtFloat.of(value); + } + + public static NbtDouble createDouble(double value) { + return NbtDouble.of(value); + } + + public static NbtLong createLong(long value) { + return NbtLong.of(value); + } + + public static NbtByte createByte(byte value) { + return NbtByte.of(value); + } + + public static NbtShort createShort(short value) { + return NbtShort.of(value); + } + + public static void copyFrom(NbtCompound target, NbtCompound source) { + target.copyFrom(source); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/ParticleEffectUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/ParticleEffectUtil.java new file mode 100644 index 000000000..bcfa9d246 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/ParticleEffectUtil.java @@ -0,0 +1,13 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.particle.ParticleEffect; +import net.minecraft.particle.ParticleType; +import net.pitan76.mcpitanlib.api.util.particle.effect.ItemStackParticleEffectUtil; + +public class ParticleEffectUtil { + public static ItemStackParticleEffectUtil itemStack = new ItemStackParticleEffectUtil(); + + public static ParticleType getType(ParticleEffect effect) { + return effect.getType(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/PersistentStateUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/PersistentStateUtil.java new file mode 100644 index 000000000..dca5fce8d --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/PersistentStateUtil.java @@ -0,0 +1,31 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.datafixer.DataFixTypes; +import net.minecraft.nbt.NbtCompound; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.world.PersistentState; +import net.minecraft.world.PersistentStateManager; +import net.minecraft.world.World; + +import java.util.function.Function; +import java.util.function.Supplier; + +public class PersistentStateUtil { + public static T getOrCreate(PersistentStateManager manager, String id, Supplier supplier, Function function) { + PersistentState.Type type = new PersistentState.Type<>(supplier, (nbtCompound, wrapperLookup) -> function.apply(nbtCompound), DataFixTypes.LEVEL); + return manager.getOrCreate(type, id); + } + + public static PersistentStateManager getManagerFromServer(MinecraftServer server) { + return server.getWorld(World.OVERWORLD).getPersistentStateManager(); + } + + public static PersistentStateManager getManagerFromWorld(ServerWorld world) { + return world.getPersistentStateManager(); + } + + public static void markDirty(PersistentState state) { + state.markDirty(); + } +} \ No newline at end of file diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/PlacedFutureUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/PlacedFutureUtil.java new file mode 100644 index 000000000..228e4eedd --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/PlacedFutureUtil.java @@ -0,0 +1,38 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.registry.entry.RegistryEntry; +import net.minecraft.world.gen.YOffset; +import net.minecraft.world.gen.feature.ConfiguredFeature; +import net.minecraft.world.gen.feature.PlacedFeature; +import net.minecraft.world.gen.placementmodifier.CountPlacementModifier; +import net.minecraft.world.gen.placementmodifier.HeightRangePlacementModifier; +import net.minecraft.world.gen.placementmodifier.PlacementModifier; +import net.minecraft.world.gen.placementmodifier.SquarePlacementModifier; + +import java.util.List; + +public class PlacedFutureUtil { + public static PlacedFeature create(ConfiguredFeature configuredFeature, List placementModifiers) { + return new PlacedFeature(RegistryEntry.of(configuredFeature), placementModifiers); + } + + public static List createPlacementModifiers(CountPlacementModifier countPlacementModifier, SquarePlacementModifier squarePlacementModifier, HeightRangePlacementModifier heightRangePlacementModifier) { + return List.of(countPlacementModifier, squarePlacementModifier, heightRangePlacementModifier); + } + + public static List createPlacementModifiers(int chunkCount, int top, int bottom) { + return createPlacementModifiers( +CountPlacementModifier.of(chunkCount), + SquarePlacementModifier.of(), + HeightRangePlacementModifier.uniform(YOffset.fixed(bottom), YOffset.fixed(top)) + ); + } + + public static List createPlacementModifiers(int chunkCount, int top) { + return createPlacementModifiers( + CountPlacementModifier.of(chunkCount), + SquarePlacementModifier.of(), + HeightRangePlacementModifier.uniform(YOffset.getBottom(), YOffset.fixed(top)) + ); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/PlatformUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/PlatformUtil.java new file mode 100644 index 000000000..bf25068fa --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/PlatformUtil.java @@ -0,0 +1,80 @@ +package net.pitan76.mcpitanlib.api.util; + +import dev.architectury.injectables.annotations.ExpectPlatform; +import dev.architectury.platform.Platform; +import dev.architectury.utils.Env; +import net.fabricmc.api.EnvType; + +import java.io.File; +import java.nio.file.Path; +import java.util.Collection; + +public class PlatformUtil { + public static boolean isDevelopmentEnvironment() { + return Platform.isDevelopmentEnvironment(); + } + + public static boolean isFabric() { + return Platform.isFabric(); + } + + public static boolean isForge() { + return Platform.isMinecraftForge(); + } + + public static boolean isNeoForge() { + return Platform.isNeoForge(); + } + + @ExpectPlatform + public static boolean isModLoaded(String id) { + return Platform.isModLoaded(id); + } + + @ExpectPlatform + public static boolean isClient() { + return Platform.getEnvironment() == Env.CLIENT; + } + + @ExpectPlatform + public static boolean isServer() { + return Platform.getEnvironment() == Env.SERVER; + } + + @ExpectPlatform + public static Path getConfigFolder() { + return Platform.getConfigFolder(); + } + + public static Path getGameFolder() { + return Platform.getGameFolder(); + } + + public static Path getModsFolder() { + return Platform.getModsFolder(); + } + + public static File getConfigFolderAsFile() { + return getConfigFolder().toFile(); + } + + public static File getGameFolderAsFile() { + return getGameFolder().toFile(); + } + + public static File getModsFolderAsFile() { + return getModsFolder().toFile(); + } + + public static Collection getModIds() { + return Platform.getModIds(); + } + + public static EnvType getEnv() { + return Platform.getEnv(); + } + + public static String getGameVersion() { + return Platform.getMinecraftVersion(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/PlayerManagerUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/PlayerManagerUtil.java new file mode 100644 index 000000000..ae2e7ecc5 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/PlayerManagerUtil.java @@ -0,0 +1,130 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.PlayerManager; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.entity.Player; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +public class PlayerManagerUtil { + + /** + * Get player by UUID + * @param server MinecraftServer + * @param uuid UUID + * @return Player + */ + public static Player getPlayerByUUID(MinecraftServer server, UUID uuid) { + return PlayerUtil.getPlayerByUUID(server, uuid); + } + + /** + * Get player by name + * @param server MinecraftServer + * @param name String + * @return Player + */ + public static Player getPlayerByName(MinecraftServer server, String name) { + return PlayerUtil.getPlayerByName(server, name); + } + + /** + * Get players by IP + * @param server MinecraftServer + * @param ip String + * @return List + */ + public static List getPlayersByIP(MinecraftServer server, String ip) { + return PlayerUtil.getPlayersByIP(server, ip); + } + + /** + * Get players + * @param server MinecraftServer + * @return List + */ + public static List getPlayers(MinecraftServer server) { + return PlayerUtil.getPlayers(server); + } + + /** + * Get players + * @param world World + * @return List + */ + public static List getPlayers(World world) { + List players = new ArrayList<>(); + for (PlayerEntity p : world.getPlayers()) { + players.add(new Player(p)); + } + return players; + } + + /** + * Get player by UUID + * @param world World + * @param uuid UUID + * @return Player + */ + public static Player getPlayerByUUID(World world, UUID uuid) { + return PlayerUtil.getPlayerByUUID(world, uuid); + } + + /** + * Get player by name + * @param world World + * @param name String + * @return Player + */ + public static Player getPlayerByName(World world, String name) { + return PlayerUtil.getPlayerByName(world, name); + } + + public static PlayerManager getPlayerManager(MinecraftServer server) { + return ServerUtil.getPlayerManager(server); + } + + public static PlayerManager getPlayerManager(World world) { + return getPlayerManager(world.getServer()); + } + + public static boolean hasPlayerByUUID(PlayerManager playerManager, UUID uuid) { + return playerManager.getPlayer(uuid) != null; + } + + public static boolean hasPlayerByName(PlayerManager playerManager, String name) { + return playerManager.getPlayer(name) != null; + } + + public static boolean hasPlayerByIP(PlayerManager playerManager, String ip) { + return !playerManager.getPlayersByIp(ip).isEmpty(); + } + + public static boolean hasPlayerByUUID(MinecraftServer server, UUID uuid) { + return hasPlayerByUUID(getPlayerManager(server), uuid); + } + + public static boolean hasPlayerByName(MinecraftServer server, String name) { + return hasPlayerByName(getPlayerManager(server), name); + } + + public static boolean hasPlayerByIP(MinecraftServer server, String ip) { + return hasPlayerByIP(getPlayerManager(server), ip); + } + + public static boolean hasPlayerByUUID(World world, UUID uuid) { + return hasPlayerByUUID(getPlayerManager(world), uuid); + } + + public static boolean hasPlayerByName(World world, String name) { + return hasPlayerByName(getPlayerManager(world), name); + } + + public static boolean hasPlayerByIP(World world, String ip) { + return hasPlayerByIP(getPlayerManager(world), ip); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/PlayerUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/PlayerUtil.java new file mode 100644 index 000000000..90f67e846 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/PlayerUtil.java @@ -0,0 +1,98 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.server.MinecraftServer; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.entity.Player; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +public class PlayerUtil { + + public static Player getPlayerByUUID(MinecraftServer server, UUID uuid) { + return new Player(server.getPlayerManager().getPlayer(uuid)); + } + + public static Player getPlayerByName(MinecraftServer server, String name) { + return new Player(server.getPlayerManager().getPlayer(name)); + } + + public static List getPlayersByIP(MinecraftServer server, String ip) { + List players = new ArrayList<>(); + for (PlayerEntity p: server.getPlayerManager().getPlayersByIp(ip)) { + players.add(new Player(p)); + } + return players; + } + + public static List getPlayers(MinecraftServer server) { + List players = new ArrayList<>(); + for (PlayerEntity p : server.getPlayerManager().getPlayerList()) { + players.add(new Player(p)); + } + return players; + } + + public static Player getPlayerByUUID(World world, UUID uuid) { + return getPlayerByUUID(world.getServer(), uuid); + } + + public static Player getPlayerByName(World world, String name) { + return getPlayerByName(world.getServer(), name); + } + + public static boolean isExistByUUID(MinecraftServer server, UUID uuid) { + return server.getPlayerManager().getPlayer(uuid) != null; + } + + public static boolean isExistByUUID(World world, UUID uuid) { + return isExistByUUID(world.getServer(), uuid); + } + + public static boolean isExistByName(MinecraftServer server, String name) { + return server.getPlayerManager().getPlayer(name) != null; + } + + public static boolean isExistByName(World world, String name) { + return isExistByName(world.getServer(), name); + } + + public static boolean isExistByIP(MinecraftServer server, String ip) { + return !server.getPlayerManager().getPlayersByIp(ip).isEmpty(); + } + + public static boolean isExistByIP(World world, String ip) { + return isExistByIP(world.getServer(), ip); + } + + public static void sendMessage(Player player, String message) { + player.sendMessage(TextUtil.literal(message)); + } + + public static float getYaw(Player player) { + return player.getYaw(); + } + + public static float getPitch(Player player) { + return player.getPitch(); + } + + public static BlockPos getBlockPos(Player player) { + return player.getBlockPos(); + } + + public static World getWorld(Player player) { + return player.getWorld(); + } + + public static boolean isClient(Player player) { + return player.isClient(); + } + + public static void teleport(Player player, double x, double y, double z) { + player.teleport(x, y, z); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/PropertyUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/PropertyUtil.java new file mode 100644 index 000000000..a97c8dc53 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/PropertyUtil.java @@ -0,0 +1,161 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.block.BlockState; +import net.minecraft.block.enums.BlockHalf; +import net.minecraft.block.enums.StairShape; +import net.minecraft.state.property.*; +import net.minecraft.util.StringIdentifiable; +import net.minecraft.util.math.Direction; +import net.pitan76.mcpitanlib.api.event.block.AppendPropertiesArgs; +import net.pitan76.mcpitanlib.api.state.property.CompatProperties; +import net.pitan76.mcpitanlib.api.state.property.DirectionProperty; + +public class PropertyUtil { + public static BooleanProperty createBooleanProperty(String name) { + return BooleanProperty.of(name); + } + + public static DirectionProperty createDirectionProperty(String name) { + return DirectionProperty.of(name); + } + + public static IntProperty createIntProperty(String name, int min, int max) { + return IntProperty.of(name, min, max); + } + + public static & StringIdentifiable> EnumProperty createEnumProperty(String name, Class type) { + return EnumProperty.of(name, type); + } + + public static BlockState with(BlockState state, BooleanProperty property, boolean value) { + return state.with(property, value); + } + + public static BlockState with(BlockState state, IntProperty property, int value) { + return state.with(property, value); + } + + public static BlockState with(BlockState state, DirectionProperty property, Direction value) { + return property.with(state, value); + } + + public static boolean get(BlockState state, BooleanProperty property) { + return state.get(property); + } + + public static int get(BlockState state, IntProperty property) { + return state.get(property); + } + + public static Direction get(BlockState state, DirectionProperty property) { + return property.get(state); + } + + public static net.pitan76.mcpitanlib.midohra.util.math.Direction getAsMidohra(BlockState state, DirectionProperty property) { + return net.pitan76.mcpitanlib.midohra.util.math.Direction.of(property.get(state)); + } + + public static Direction getFacing(BlockState state) { + return facing().get(state); + } + + public static Direction getHorizontalFacing(BlockState state) { + return horizontalFacing().get(state); + } + + public static int getPower(BlockState state) { + return state.get(power()); + } + + public static boolean isPowered(BlockState state) { + return state.get(powered()); + } + + public static void append(AppendPropertiesArgs args, Property... properties) { + args.addProperty(properties); + } + + public static void appendFacing(AppendPropertiesArgs args) { + facing().apply(args); + } + + public static void appendHorizontalFacing(AppendPropertiesArgs args) { + horizontalFacing().apply(args); + } + + public static void appendPower(AppendPropertiesArgs args) { + args.addProperty(power()); + } + + public static void appendPowered(AppendPropertiesArgs args) { + args.addProperty(powered()); + } + + public static IntProperty power() { + return Properties.POWER; + } + + public static BooleanProperty powered() { + return Properties.POWERED; + } + + public static DirectionProperty facing() { + return CompatProperties.FACING; + } + + public static DirectionProperty horizontalFacing() { + return CompatProperties.HORIZONTAL_FACING; + } + + public static EnumProperty axis() { + return Properties.AXIS; + } + + public static EnumProperty blockHalf() { + return Properties.BLOCK_HALF; + } + + public static EnumProperty stairShape() { + return Properties.STAIR_SHAPE; + } + + public static BooleanProperty lit() { + return Properties.LIT; + } + + public static BooleanProperty waterlogged() { + return Properties.WATERLOGGED; + } + + public static BooleanProperty attached() { + return Properties.ATTACHED; + } + + public static BooleanProperty hanging() { + return Properties.HANGING; + } + + public static BooleanProperty bottom() { + return Properties.BOTTOM; + } + + public static BooleanProperty conditional() { + return Properties.CONDITIONAL; + } + + public static BooleanProperty inWall() { + return Properties.IN_WALL; + } + + public static BooleanProperty open() { + return Properties.OPEN; + } + + public static BooleanProperty occupied() { + return Properties.OCCUPIED; + } + + public static boolean contains(BlockState state, Property property) { + return state.contains(property); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/RecipeUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/RecipeUtil.java new file mode 100644 index 000000000..d296477f0 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/RecipeUtil.java @@ -0,0 +1,170 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.inventory.Inventory; +import net.minecraft.item.ItemStack; +import net.minecraft.recipe.*; +import net.minecraft.recipe.book.CraftingRecipeCategory; +import net.minecraft.recipe.input.RecipeInput; +import net.minecraft.util.Identifier; +import net.minecraft.util.collection.DefaultedList; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.recipe.CompatRecipeType; +import net.pitan76.mcpitanlib.api.recipe.MatchGetter; +import net.pitan76.mcpitanlib.api.recipe.input.CompatRecipeInput; +import net.pitan76.mcpitanlib.api.recipe.v2.CompatRecipeEntry; +import net.pitan76.mcpitanlib.api.recipe.v2.CompatRecipeNonEntry; +import net.pitan76.mcpitanlib.api.registry.CompatRegistryLookup; +import net.pitan76.mcpitanlib.api.util.collection.ItemStackList; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Optional; + +public class RecipeUtil { + public static ShapelessRecipe createShapelessRecipe(Identifier id, String group, CompatibilityCraftingRecipeCategory category, ItemStack output, DefaultedList input) { + return new ShapelessRecipe(group, CraftingRecipeCategory.valueOf(category.name()), output, input); + } + + public static ShapelessRecipe createShapelessRecipe(Identifier id, String group, ItemStack output, DefaultedList input) { + return createShapelessRecipe(id, group, CompatibilityCraftingRecipeCategory.MISC, output, input); + } + + @Deprecated + public static ItemStack craft_2(Recipe recipe, C inventory, World world) { + return recipe.craft(inventory, world.getRegistryManager()); + } + + @Deprecated + public static ItemStack getOutput_2(Recipe recipe, World world) { + return recipe.getResult(world.getRegistryManager()); + } + + public static ItemStack craft(Recipe recipe, Inventory inventory, World world) { + if (inventory instanceof RecipeInput) { + Recipe inputRecipe = (Recipe) recipe; + return inputRecipe.craft((RecipeInput) inventory, world.getRegistryManager()); + } + return ItemStack.EMPTY; + } + + public static ItemStack getOutput(Recipe recipe, World world) { + return getOutput(recipe, RegistryLookupUtil.getRegistryLookup(world)); + } + + public static List> getAllRecipes(World world) { + Collection> recipes = getRecipeManager(world).values(); + List> outRecipes = new ArrayList<>(); + for (Object recipeEntryObj : recipes) { + if (recipeEntryObj instanceof RecipeEntry) { + RecipeEntry recipeEntry = (RecipeEntry) recipeEntryObj; + if (recipeEntry.value() instanceof Recipe) { + outRecipes.add(recipeEntry.value()); + } + } + } + return outRecipes; + } + + public static List> getAllCompatRecipeEntry(World world) { + List> recipes = getAllRecipes(world); + List> outRecipes = new ArrayList<>(); + for (Recipe recipe : recipes) { + outRecipes.add(new CompatRecipeNonEntry<>(recipe)); + } + return outRecipes; + } + + public static RecipeType getType(Recipe recipe) { + return recipe.getType(); + } + + public static Identifier getId(Recipe recipe) { + return IdentifierUtil.id(recipe.getClass().hashCode() + ""); + } + + public static > CompatRecipeEntry getFirstMatch(RecipeManager recipeManager, CompatRecipeType type, CompatRecipeInput input, World world) { + Optional> recipe = recipeManager.getFirstMatch(type.getType(), input.getInput(), world); + return recipe.map(CompatRecipeEntry::new).orElseGet(() -> new CompatRecipeEntry<>(null)); + } + + public static > CompatRecipeEntry getFirstMatch(RecipeManager recipeManager, CompatRecipeType type, CompatRecipeInput input, World world, CompatIdentifier identifier) { + Optional> recipe = recipeManager.getFirstMatch(type.getType(), input.getInput(), world, identifier.toMinecraft()); + return recipe.map(CompatRecipeEntry::new).orElseGet(() -> new CompatRecipeEntry<>(null)); + } + + public static > CompatRecipeEntry getFirstMatch(World world, CompatRecipeType type, CompatRecipeInput input) { + return getFirstMatch(getRecipeManager(world), type, input, world); + } + + public static > CompatRecipeEntry getFirstMatch(World world, CompatRecipeType type, CompatRecipeInput input, CompatIdentifier identifier) { + return getFirstMatch(getRecipeManager(world), type, input, world, identifier); + } + + public static RecipeManager getRecipeManager(World world) { + return world.getRecipeManager(); + } + + public Optional> get(World world, CompatIdentifier id) { + return get(getRecipeManager(world), id); + } + + public Optional> get(RecipeManager recipeManager, CompatIdentifier id) { + return recipeManager.get(id.toMinecraft()); + } + + public static > MatchGetter createCachedMatchGetter(RecipeType type) { + return (input, world) -> { + Optional> optional = RecipeManager.createCachedMatchGetter(type).getFirstMatch(input.getInput(), world); + return optional.map(CompatRecipeEntry::new); + }; + } + + public static > MatchGetter createCachedMatchGetter(CompatRecipeType type) { + return createCachedMatchGetter(type.getType()); + } + + public static DefaultedList getInputs(Recipe recipe) { + return recipe.getIngredients(); + } + + public static DefaultedList getInputs(CompatRecipeEntry recipeEntry) { + return getInputs(recipeEntry.getRecipe()); + } + + public static ItemStackList getInputsAsStack(Recipe recipe) { + DefaultedList ingredients = getInputs(recipe); + ItemStackList stacks = ItemStackList.ofSize(ingredients.size(), ItemStackUtil.empty()); + for (Ingredient ingredient : ingredients) { + stacks.addAll(IngredientUtil.getMatchingStacksAsList(ingredient)); + } + return stacks; + } + + public static ItemStackList getInputsAsStack(CompatRecipeEntry recipeEntry) { + return getInputsAsStack(recipeEntry.getRecipe()); + } + + public static ItemStack getOutput(Recipe recipe, CompatRegistryLookup registryLookup) { + return recipe.getResult(registryLookup.getRegistryLookup()); + } + + public static ItemStack getOutput(CompatRecipeEntry recipeEntry, CompatRegistryLookup registryLookup) { + return getOutput(recipeEntry.getRecipe(), registryLookup); + } + + public static CompatRecipeType getType(CompatRecipeEntry recipeEntry) { + return CompatRecipeType.of(recipeEntry.getRecipe().getType()); + } + + public static > ItemStackList getRemainder(CompatRecipeEntry recipeEntry, CompatRecipeInput input) { + return ItemStackList.of(recipeEntry.getRecipe().getRemainder(input.getInput())); + } + + public enum CompatibilityCraftingRecipeCategory { + BUILDING, + REDSTONE, + EQUIPMENT, + MISC; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/RegistryLookupUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/RegistryLookupUtil.java new file mode 100644 index 000000000..b507e75ee --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/RegistryLookupUtil.java @@ -0,0 +1,40 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.entity.Entity; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.entity.CompatEntity; +import net.pitan76.mcpitanlib.api.event.item.ItemAppendTooltipEvent; +import net.pitan76.mcpitanlib.api.event.nbt.NbtRWArgs; +import net.pitan76.mcpitanlib.api.registry.CompatRegistryLookup; +import net.pitan76.mcpitanlib.api.tile.CompatBlockEntity; + +public class RegistryLookupUtil { + public static CompatRegistryLookup getRegistryLookup(ItemAppendTooltipEvent e) { + return new CompatRegistryLookup(e.context.getRegistryLookup()); + } + + public static CompatRegistryLookup getRegistryLookup(CompatEntity entity) { + return new CompatRegistryLookup(entity.getRegistryManager()); + } + + public static CompatRegistryLookup getRegistryLookup(Entity entity) { + return new CompatRegistryLookup(entity.getRegistryManager()); + } + + public static CompatRegistryLookup getRegistryLookup(CompatBlockEntity entity) { + return new CompatRegistryLookup(entity.getWorld().getRegistryManager()); + } + + public static CompatRegistryLookup getRegistryLookup(BlockEntity entity) { + return new CompatRegistryLookup(entity.getWorld().getRegistryManager()); + } + + public static CompatRegistryLookup getRegistryLookup(NbtRWArgs args) { + return args.getRegistryLookup(); + } + + public static CompatRegistryLookup getRegistryLookup(World world) { + return new CompatRegistryLookup(world.getRegistryManager()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/ResourceUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/ResourceUtil.java new file mode 100644 index 000000000..cfb5df1d5 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/ResourceUtil.java @@ -0,0 +1,27 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.resource.Resource; +import net.minecraft.resource.ResourceManager; +import net.minecraft.util.Identifier; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Map; + +public class ResourceUtil { + public static Resource getResource(ResourceManager resourceManager, Identifier identifier) { + return resourceManager.getResource(identifier).get(); + } + + public static InputStream getInputStream(Resource resource) throws IOException { + return resource.getInputStream(); + } + + public static Map findResources(ResourceManager resourceManager, String startingPath, String endingPath) throws IOException { + return resourceManager.findResources(startingPath, s -> s.toString().endsWith(endingPath)); + } + + public static void close(Resource resource) throws IOException { + getInputStream(resource).close(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/ScreenHandlerUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/ScreenHandlerUtil.java new file mode 100644 index 000000000..7ce969235 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/ScreenHandlerUtil.java @@ -0,0 +1,54 @@ +package net.pitan76.mcpitanlib.api.util; + +import dev.architectury.registry.menu.ExtendedMenuProvider; +import dev.architectury.registry.menu.MenuRegistry; +import net.minecraft.network.PacketByteBuf; +import net.minecraft.registry.Registries; +import net.minecraft.screen.NamedScreenHandlerFactory; +import net.minecraft.screen.ScreenHandler; +import net.minecraft.screen.ScreenHandlerType; +import net.minecraft.screen.slot.Slot; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.util.collection.DefaultedList; + +import java.util.ArrayList; +import java.util.List; +import java.util.function.Consumer; + +public class ScreenHandlerUtil { + public static DefaultedList getSlots(ScreenHandler screenHandler) { + return screenHandler.slots; + } + + public static Slot getSlot(ScreenHandler screenHandler, int index) { + return screenHandler.getSlot(index); + } + + public static List> getAllScreenHandlerTypes() { + List> screenHandlerTypes = new ArrayList<>(); + for (ScreenHandlerType screenHandler : Registries.SCREEN_HANDLER) { + screenHandlerTypes.add(screenHandler); + } + return screenHandlerTypes; + } + + public static void openExtendedMenu(ServerPlayerEntity player, NamedScreenHandlerFactory provider, Consumer bufWriter) { + MenuRegistry.openExtendedMenu(player, provider, bufWriter); + } + + public static void openExtendedMenu(ServerPlayerEntity player, ExtendedMenuProvider provider) { + MenuRegistry.openExtendedMenu(player, provider); + } + + public static void openMenu(ServerPlayerEntity player, NamedScreenHandlerFactory provider) { + MenuRegistry.openMenu(player, provider); + } + + public static int getRawId(ScreenHandlerType type) { + return Registries.SCREEN_HANDLER.getRawId(type); + } + + public static ScreenHandlerType fromIndex(int index) { + return Registries.SCREEN_HANDLER.get(index); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/ServerUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/ServerUtil.java new file mode 100644 index 000000000..6718b610d --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/ServerUtil.java @@ -0,0 +1,64 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.PlayerManager; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.entity.Player; + +public class ServerUtil { + public static MinecraftServer getServer(World world) { + return world.getServer(); + } + + public static String getIP(MinecraftServer server) { + return server.getServerIp(); + } + + public static int getPort(MinecraftServer server) { + return server.getServerPort(); + } + + public static String getMotd(MinecraftServer server) { + return server.getServerMotd(); + } + + public static String getServerModName(MinecraftServer server) { + return server.getServerModName(); + } + + public static int getMaxPlayerCount(MinecraftServer server) { + return server.getMaxPlayerCount(); + } + + public static int getCurrentPlayerCount(MinecraftServer server) { + return server.getCurrentPlayerCount(); + } + + public static boolean isOnlineMode(MinecraftServer server) { + return server.isOnlineMode(); + } + + public static boolean isServerRunning(MinecraftServer server) { + return server.isRunning(); + } + + public static boolean isServerDedicated(MinecraftServer server) { + return server.isDedicated(); + } + + public static boolean isSingleplayer(MinecraftServer server) { + return server.isSingleplayer(); + } + + public static PlayerManager getPlayerManager(MinecraftServer server) { + return server.getPlayerManager(); + } + + public static MinecraftServer getServer(Player player) { + return getServer(player.getWorld()); + } + + public static void execute(MinecraftServer server, Runnable runnable) { + server.execute(runnable); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/SimpleInventoryUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/SimpleInventoryUtil.java new file mode 100644 index 000000000..9176cee25 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/SimpleInventoryUtil.java @@ -0,0 +1,35 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.inventory.SimpleInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.util.collection.DefaultedList; + +public class SimpleInventoryUtil { + public static DefaultedList getHeldStacks(SimpleInventory inventory) { + return inventory.getHeldStacks(); + } + + public static SimpleInventory create(int size) { + return InventoryUtil.createSimpleInventory(size); + } + + public static ItemStack getStack(SimpleInventory inventory, int slot) { + return inventory.getStack(slot); + } + + public static void setStack(SimpleInventory inventory, int slot, ItemStack stack) { + inventory.setStack(slot, stack); + } + + public static void clear(SimpleInventory inventory) { + inventory.clear(); + } + + public static int size(SimpleInventory inventory) { + return inventory.size(); + } + + public static boolean isEmpty(SimpleInventory inventory) { + return inventory.isEmpty(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/SlotUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/SlotUtil.java new file mode 100644 index 000000000..018aad006 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/SlotUtil.java @@ -0,0 +1,44 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.inventory.Inventory; +import net.minecraft.item.ItemStack; +import net.minecraft.screen.slot.Slot; +import net.pitan76.mcpitanlib.api.entity.Player; + +public class SlotUtil { + public static void setStack(Slot slot, ItemStack stack) { + slot.setStack(stack); + } + + public static ItemStack getStack(Slot slot) { + return slot.getStack(); + } + + public static void takeStack(Slot slot, int amount) { + slot.takeStack(amount); + } + + public static boolean hasStack(Slot slot) { + return slot.hasStack(); + } + + public static void markDirty(Slot slot) { + slot.markDirty(); + } + + public static boolean canInsert(Slot slot, ItemStack stack) { + return slot.canInsert(stack); + } + + public static boolean canTakeItems(Slot slot) { + return slot.canTakeItems(null); + } + + public static void onTakeItem(Slot slot, Player player, ItemStack stack) { + slot.onTakeItem(player.getEntity(), stack); + } + + public static Inventory getInventory(Slot slot) { + return slot.inventory; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/SoundEventUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/SoundEventUtil.java new file mode 100644 index 000000000..a6f367799 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/SoundEventUtil.java @@ -0,0 +1,35 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.registry.Registries; +import net.minecraft.sound.SoundEvent; +import net.minecraft.util.Identifier; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +public class SoundEventUtil { + public static Identifier getId(SoundEvent soundEvent) { + return soundEvent.getId(); + } + + public static SoundEvent getSoundEvent(Identifier id) { + return SoundEvent.of(id); + } + + public static CompatIdentifier getCompatId(SoundEvent soundEvent) { + return CompatIdentifier.fromMinecraft(getId(soundEvent)); + } + + public static SoundEvent getSoundEvent(CompatIdentifier id) { + return getSoundEvent(id.toMinecraft()); + } + + public static List getAllSoundEvents() { + return Registries.SOUND_EVENT.stream().collect(Collectors.toList()); + } + + public static List getAllSoundEventIds() { + return new ArrayList<>(Registries.SOUND_EVENT.getIds()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/StackActionResult.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/StackActionResult.java new file mode 100644 index 000000000..3711e987f --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/StackActionResult.java @@ -0,0 +1,126 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.item.ItemStack; +import net.minecraft.util.ActionResult; +import net.minecraft.util.TypedActionResult; +import net.pitan76.mcpitanlib.api.event.result.EventResult; + +import java.util.Optional; + +public class StackActionResult extends CompatActionResult { + private final ItemStack stack; + private final CompatActionResult compatActionResult; + private boolean isNewStack = false; + + public StackActionResult(ActionResult actionResult, EventResult eventResult, ItemStack stack) { + this(new CompatActionResult(actionResult, eventResult), stack); + } + + public StackActionResult(CompatActionResult actionResult, ItemStack stack) { + super(null, null); + compatActionResult = actionResult; + this.stack = stack; + } + + public void setNewStack(boolean b) { + isNewStack = b; + } + + @Override + public ActionResult toActionResult() { + return compatActionResult.toActionResult(); + } + + @Override + public EventResult toEventResult() { + return compatActionResult.toEventResult(); + } + + @Deprecated + @Override + public Optional getNewHandStack() { + if (hasNewStack()) + return Optional.ofNullable(getStack()); + + return Optional.empty(); + } + + public boolean hasNewStack() { + return isNewStack; + } + + public boolean hasStack() { + return getStack() != null; + } + + public CompatActionResult asCompatActionResult() { + return compatActionResult; + } + + public static StackActionResult create(CompatActionResult compatActionResult, ItemStack stack) { + return new StackActionResult(compatActionResult, stack); + } + + public static StackActionResult create(CompatActionResult compatActionResult) { + return new StackActionResult(compatActionResult, null); + } + + public static StackActionResult create(ActionResult actionResult, EventResult eventResult, ItemStack stack) { + return new StackActionResult(actionResult, eventResult, stack); + } + + public static StackActionResult create(ActionResult actionResult, ItemStack stack) { + return new StackActionResult(actionResult, null, stack); + } + + public static StackActionResult create(TypedActionResult result) { + StackActionResult actionResult = create(CompatActionResult.create(result.getResult()), result.getValue()); + actionResult.setNewStack(true); + return actionResult; + } + + public static StackActionResult success(ItemStack stack) { + CompatActionResult compatActionResult = CompatActionResult.create(ActionResult.SUCCESS); + StackActionResult actionResult = create(compatActionResult, stack); + actionResult.setNewStack(true); + return actionResult; + } + + public static StackActionResult successServer(ItemStack stack) { + CompatActionResult compatActionResult = CompatActionResult.create(ActionResult.SUCCESS); + StackActionResult actionResult = create(compatActionResult, stack); + actionResult.setNewStack(true); + return actionResult; + } + + public static StackActionResult consume(ItemStack stack) { + CompatActionResult compatActionResult = CompatActionResult.create(ActionResult.CONSUME); + StackActionResult actionResult = create(compatActionResult, stack); + actionResult.setNewStack(true); + return actionResult; + } + + public TypedActionResult toTypedActionResult() { + return new TypedActionResult<>(toActionResult(), getStack()); + } + + public static StackActionResult pass(ItemStack stack) { + return create(CompatActionResult.PASS, stack); + } + + public static StackActionResult pass() { + return create(CompatActionResult.PASS); + } + + public static StackActionResult fail(ItemStack stack) { + return create(CompatActionResult.FAIL, stack); + } + + public static StackActionResult fail() { + return create(CompatActionResult.FAIL); + } + + public ItemStack getStack() { + return stack; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/StateManagerUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/StateManagerUtil.java new file mode 100644 index 000000000..a51ef0e36 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/StateManagerUtil.java @@ -0,0 +1,15 @@ +package net.pitan76.mcpitanlib.api.util; + +import com.google.common.collect.ImmutableList; +import net.minecraft.state.State; +import net.minecraft.state.StateManager; + +public class StateManagerUtil { + public static > S getDefaultState(StateManager manager) { + return manager.getDefaultState(); + } + + public > ImmutableList getStates(StateManager manager) { + return manager.getStates(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/StatusEffectUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/StatusEffectUtil.java new file mode 100644 index 000000000..333f996f8 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/StatusEffectUtil.java @@ -0,0 +1,27 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.entity.effect.StatusEffect; +import net.minecraft.registry.RegistryKey; +import net.minecraft.registry.RegistryKeys; +import net.minecraft.util.Identifier; +import net.pitan76.mcpitanlib.api.entity.effect.CompatStatusEffect; + +public class StatusEffectUtil { + public static CompatStatusEffect getStatusEffect(Identifier identifier) { + RegistryKey registryKey = RegistryKey.of(RegistryKeys.STATUS_EFFECT, identifier); + return new CompatStatusEffect(registryKey); + } + + public static CompatStatusEffect getStatusEffect(CompatIdentifier identifier) { + return getStatusEffect(identifier.toMinecraft()); + } + + public static Identifier getId(CompatStatusEffect statusEffect) { + return statusEffect.getId(); + } + + public static CompatIdentifier getCompatId(CompatStatusEffect statusEffect) { + return CompatIdentifier.fromMinecraft(statusEffect.getId()); + } + +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/StyleUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/StyleUtil.java new file mode 100644 index 000000000..6bbaac18b --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/StyleUtil.java @@ -0,0 +1,60 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.text.ClickEvent; +import net.minecraft.text.HoverEvent; +import net.minecraft.text.Style; +import net.minecraft.util.Formatting; + +public class StyleUtil { + public static Style emptyStyle() { + return Style.EMPTY; + } + + public static Style withColor(Style style, int color) { + return style.withColor(color); + } + + public static Style withBold(Style style, boolean bold) { + return style.withBold(bold); + } + + public static Style withItalic(Style style, boolean italic) { + return style.withItalic(italic); + } + + public static Style withUnderline(Style style, boolean underline) { + return style.withUnderline(underline); + } + + public static Style withStrikethrough(Style style, boolean strikethrough) { + return style.withStrikethrough(strikethrough); + } + + public static Style withObfuscated(Style style, boolean obfuscated) { + return style.withObfuscated(obfuscated); + } + + public static Style withInsertion(Style style, String insertion) { + return style.withInsertion(insertion); + } + + public static Style withClickEvent(Style style, ClickEvent clickEvent) { + return style.withClickEvent(clickEvent); + } + + public static Style withHoverEvent(Style style, HoverEvent hoverEvent) { + return style.withHoverEvent(hoverEvent); + } + + public static Style withFont(Style style, CompatIdentifier font) { + return style.withFont(font.toMinecraft()); + } + + public static Style withFormatting(Style style, Formatting formatting) { + return style.withFormatting(formatting); + } + + public static Style withExclusiveFormatting(Style style, Formatting formatting) { + return style.withExclusiveFormatting(formatting); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/TextUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/TextUtil.java new file mode 100644 index 000000000..388da58de --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/TextUtil.java @@ -0,0 +1,72 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.text.MutableText; +import net.minecraft.text.Style; +import net.minecraft.text.Text; +import net.pitan76.mcpitanlib.api.text.TextConverter; + +public class TextUtil { + public static MutableText literal(String string) { + return Text.literal(string); + } + + public static MutableText translatable(String key) { + return Text.translatable(key); + } + + public static MutableText translatable(String key, Object... args) { + return Text.translatable(key, args); + } + + public static MutableText empty() { + return literal(""); + } + + public static MutableText keybind(String string) { + return Text.keybind(string); + } + + public static String txt2str(Text text) { + return text.getString(); + } + + public static MutableText setStyle(MutableText text, Style style) { + return text.setStyle(style); + } + + public static Style getStyle(MutableText text) { + return text.getStyle(); + } + + public static MutableText withColor(MutableText text, int color) { + return setStyle(text, StyleUtil.withColor(text.getStyle(), color)); + } + + public static MutableText withBold(MutableText text, boolean bold) { + return setStyle(text, StyleUtil.withBold(text.getStyle(), bold)); + } + + public static MutableText append(MutableText text, Text sibling) { + return text.append(sibling); + } + + public static MutableText append(MutableText text, String string) { + return text.append(string); + } + + public static MutableText of(String string) { + return literal(string); + } + + public static MutableText convert(String text) { + return TextConverter.convert(text, false); + } + + public static MutableText convertWithTranslatable(String text) { + return TextConverter.convert(text, true); + } + + public static boolean contains(Text text, Text text1) { + return text.contains(text1); + } +} \ No newline at end of file diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/TimerUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/TimerUtil.java new file mode 100644 index 000000000..eaf08acdb --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/TimerUtil.java @@ -0,0 +1,18 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.world.ServerWorld; +import net.pitan76.mcpitanlib.api.timer.MinecraftServerTimerAccess; +import net.pitan76.mcpitanlib.api.timer.ServerWorldTimerAccess; + +import java.util.function.Supplier; + +public class TimerUtil { + public static void addTimer(ServerWorld world, long ticksUntilSomething, Supplier supplier) { + ((ServerWorldTimerAccess) world).mcpitanlib$addTimer(ticksUntilSomething, supplier); + } + + public static void addTimer(MinecraftServer server, long ticksUntilSomething, Supplier supplier) { + ((MinecraftServerTimerAccess) server).mcpitanlib$addTimer(ticksUntilSomething, supplier); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/ToolMaterialUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/ToolMaterialUtil.java new file mode 100644 index 000000000..87571de96 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/ToolMaterialUtil.java @@ -0,0 +1,55 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.recipe.Ingredient; +import net.pitan76.mcpitanlib.api.item.tool.CompatibleToolMaterial; + +public class ToolMaterialUtil { + // ミスでstatic化し忘れていたが、互換性のため保持しておく + public CompatibleToolMaterial create(int miningLevel, int durability, float miningSpeed, float attackDamage, int enchantability, Ingredient repairIngredient) { + return create2(miningLevel, durability, miningSpeed, attackDamage, enchantability, repairIngredient); + } + + /** + * Create CompatibleToolMaterial + * @param miningLevel Mining Level + * @param durability Durability + * @param miningSpeed Mining Speed + * @param attackDamage Attack Damage + * @param enchantability Enchantability + * @param repairIngredient Repair Ingredient + * @return CompatibleToolMaterial + */ + public static CompatibleToolMaterial create2(int miningLevel, int durability, float miningSpeed, float attackDamage, int enchantability, Ingredient repairIngredient) { + return new CompatibleToolMaterial() { + @Override + public int getCompatMiningLevel() { + return miningLevel; + } + + @Override + public int getCompatDurability() { + return durability; + } + + @Override + public float getCompatMiningSpeedMultiplier() { + return miningSpeed; + } + + @Override + public Ingredient getCompatRepairIngredient() { + return repairIngredient; + } + + @Override + public float getCompatAttackDamage() { + return attackDamage; + } + + @Override + public int getCompatEnchantability() { + return enchantability; + } + }; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/VoxelShapeUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/VoxelShapeUtil.java new file mode 100644 index 000000000..f68dd0bfb --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/VoxelShapeUtil.java @@ -0,0 +1,43 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.util.math.Box; +import net.minecraft.util.shape.VoxelShape; +import net.minecraft.util.shape.VoxelShapes; + +public class VoxelShapeUtil { + public static VoxelShape union(VoxelShape shape,VoxelShape... shapes) { + return VoxelShapes.union(shape, shapes); + } + + public static VoxelShape cuboid(double x1, double y1, double z1, double x2, double y2, double z2) { + return VoxelShapes.cuboid(x1, y1, z1, x2, y2, z2); + } + + public static VoxelShape cuboid(double x, double y, double z, double size) { + return VoxelShapes.cuboid(x, y, z, x + size, y + size, z + size); + } + + public static VoxelShape cuboid(double size) { + return VoxelShapes.cuboid(0, 0, 0, size, size, size); + } + + public static VoxelShape centeredCuboid(double x, double y, double z, double size) { + return VoxelShapes.cuboid(x - size / 2, y - size / 2, z - size / 2, x + size / 2, y + size / 2, z + size / 2); + } + + public static VoxelShape empty() { + return VoxelShapes.empty(); + } + + public static VoxelShape fullCube() { + return VoxelShapes.fullCube(); + } + + public static VoxelShape blockCuboid(double minX, double minY, double minZ, double maxX, double maxY, double maxZ) { + return VoxelShapes.cuboid(minX / 16.0, minY / 16.0, minZ / 16.0, maxX / 16.0, maxY / 16.0, maxZ / 16.0); + } + + public static Box getBoundingBox(VoxelShape shape) { + return shape.getBoundingBox(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/WorldRandomUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/WorldRandomUtil.java new file mode 100644 index 000000000..183a6e34f --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/WorldRandomUtil.java @@ -0,0 +1,37 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.world.World; + +public class WorldRandomUtil { + public static int nextInt(World world) { + return world.getRandom().nextInt(); + } + + public static int nextInt(World world, int bound) { + return world.getRandom().nextInt(bound); + } + + public static long nextLong(World world) { + return world.getRandom().nextLong(); + } + + public static double nextDouble(World world) { + return world.getRandom().nextDouble(); + } + + public static double nextGaussian(World world) { + return world.getRandom().nextGaussian(); + } + + public static float nextFloat(World world) { + return world.getRandom().nextFloat(); + } + + public static int nextBetween(World world, int min, int max) { + return world.getRandom().nextBetween(min, max); + } + + public static int nextBetweenExclusive(World world, int min, int max) { + return world.getRandom().nextBetweenExclusive(min, max); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/WorldUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/WorldUtil.java new file mode 100644 index 000000000..d324f023f --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/WorldUtil.java @@ -0,0 +1,477 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.block.Blocks; +import net.minecraft.block.ShapeContext; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.entity.*; +import net.minecraft.entity.mob.Monster; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.fluid.Fluid; +import net.minecraft.fluid.FluidState; +import net.minecraft.item.ItemStack; +import net.minecraft.particle.ParticleEffect; +import net.minecraft.predicate.entity.EntityPredicates; +import net.minecraft.registry.RegistryKey; +import net.minecraft.registry.RegistryKeys; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.sound.SoundCategory; +import net.minecraft.sound.SoundEvent; +import net.minecraft.util.Identifier; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Box; +import net.minecraft.util.math.ChunkPos; +import net.minecraft.util.math.Vec3d; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.entity.Player; +import net.pitan76.mcpitanlib.api.sound.CompatSoundCategory; +import net.pitan76.mcpitanlib.api.sound.CompatSoundEvent; +import net.pitan76.mcpitanlib.api.util.math.BoxUtil; +import net.pitan76.mcpitanlib.api.util.math.random.CompatRandom; +import net.pitan76.mcpitanlib.api.util.particle.CompatParticleType; +import net.pitan76.mcpitanlib.midohra.block.BlockWrapper; +import net.pitan76.mcpitanlib.midohra.entity.EntityTypeWrapper; +import net.pitan76.mcpitanlib.midohra.util.math.Vector3d; +import net.pitan76.mcpitanlib.midohra.world.chunk.ChunkTicketType; +import org.jetbrains.annotations.Nullable; + +import java.util.*; +import java.util.function.Predicate; + +public class WorldUtil { + public static boolean hasSkyLight(World world) { + return world.getDimension().hasSkyLight(); + } + + public static boolean isThundering(World world) { + return world.isThundering(); + } + + public static boolean isRaining(World world) { + return world.isRaining(); + } + + public static boolean isNight(World world) { + return world.isNight(); + } + + public static boolean isDay(World world) { + return world.isDay(); + } + + public static boolean isSkyVisible(World world, BlockPos pos) { + return world.isSkyVisible(pos); + } + + public static boolean isClient(World world) { + return world.isClient(); + } + + public static void scheduleBlockTick(World world, BlockPos pos, Block block, int delay) { + world.scheduleBlockTick(pos, block, delay); + } + + public static void scheduleFluidTick(World world, BlockPos pos, Fluid fluid, int delay) { + world.scheduleFluidTick(pos, fluid, delay); + } + + public static boolean isServer(World world) { + return !isClient(world); + } + + public static void spawnStack(World world, BlockPos pos, ItemStack stack) { + spawnEntity(world, new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(), stack)); + } + + public static void spawnExperienceOrb(World world, Vec3d pos, int amount) { + if (world instanceof ServerWorld) + ExperienceOrbEntity.spawn((ServerWorld) world, pos, amount); + } + + public static void spawnExperienceOrb(World world, BlockPos pos, int amount) { + spawnExperienceOrb(world, pos.toCenterPos(), amount); + } + + public static void spawnEntity(World world, Entity entity) { + world.spawnEntity(entity); + } + + public static void playSound(World world, @Nullable Player player, BlockPos pos, SoundEvent sound, SoundCategory category, float volume, float pitch) { + PlayerEntity entity = player == null ? null : player.getEntity(); + world.playSound(entity, pos, sound, category, volume, pitch); + } + + public static void playSound(World world, @Nullable Player player, BlockPos pos, CompatSoundEvent sound, CompatSoundCategory category, float volume, float pitch) { + playSound(world, player, pos, sound.get(), category.get(), volume, pitch); + } + + public static void playSound(World world, BlockPos pos, CompatSoundEvent sound, CompatSoundCategory category, float volume, float pitch) { + playSound(world, null, pos, sound.get(), category.get(), volume, pitch); + } + + public static void playSound(World world, double x, double y, double z, CompatSoundEvent sound, CompatSoundCategory category, float volume, float pitch, boolean useDistance) { + world.playSound(x, y, z, sound.get(), category.get(), volume, pitch, useDistance); + } + + public static void sendEntityStatus(World world, Entity entity, byte status) { + world.sendEntityStatus(entity, status); + } + + public static BlockPos getSpawnPos(World world) { + return world.getSpawnPos(); + } + + public static Optional getServer(World world) { + if (isClient(world)) return Optional.empty(); + return Optional.ofNullable(world.getServer()); + } + + public static ServerWorld getWorld(World world, Identifier worldId) { + Optional server = getServer(world); + if (!server.isPresent()) return null; + + return getWorld(server.get(), worldId); + } + + public static Optional getWorld(World world, CompatIdentifier worldId) { + return Optional.ofNullable(getWorld(world, worldId.toMinecraft())); + } + + public static ServerWorld getOverworld(MinecraftServer server) { + return server.getWorld(World.OVERWORLD); + } + + public static ServerWorld getNether(MinecraftServer server) { + return server.getWorld(World.NETHER); + } + + public static ServerWorld getEnd(MinecraftServer server) { + return server.getWorld(World.END); + } + + public static ServerWorld getWorld(MinecraftServer server, Identifier worldId) { + return server.getWorld(RegistryKey.of(RegistryKeys.WORLD, worldId)); + } + + public static ServerWorld getWorld(MinecraftServer server, CompatIdentifier worldId) { + return getWorld(server, worldId.toMinecraft()); + } + + public static Identifier getWorldId(World world) { + return world.getRegistryKey().getValue(); + } + + public static CompatIdentifier getCompatWorldId(World world) { + return CompatIdentifier.fromMinecraft(getWorldId(world)); + } + + public static boolean equals(World world, World world2) { + return Objects.equals(getWorldId(world), getWorldId(world2)); + } + + @Deprecated + public static void addTicket(ServerWorld world, net.minecraft.server.world.ChunkTicketType type, ChunkPos pos, int radius, T argument) { + world.getChunkManager().addTicket(type, pos, radius, argument); + } + + @Deprecated + public static void removeTicket(ServerWorld world, net.minecraft.server.world.ChunkTicketType type, ChunkPos pos, int radius, T argument) { + world.getChunkManager().removeTicket(type, pos, radius, argument); + } + + public static void addTicket(ServerWorld world, ChunkTicketType type, ChunkPos pos, int radius, T argument) { + addTicket(world, type.getRaw(), pos, radius, argument); + } + + public static void removeTicket(ServerWorld world, ChunkTicketType type, ChunkPos pos, int radius, T argument) { + removeTicket(world, type.getRaw(), pos, radius, argument); + } + + public static void addTicket(ServerWorld world, ChunkTicketType type, ChunkPos pos, int radius) { + net.minecraft.server.world.ChunkTicketType rawType = type.getRaw(); + world.getChunkManager().addTicket( rawType, pos, radius, pos); + } + + public static void removeTicket(ServerWorld world, ChunkTicketType type, ChunkPos pos, int radius) { + net.minecraft.server.world.ChunkTicketType rawType = type.getRaw(); + world.getChunkManager().removeTicket(rawType, pos, radius, pos); + } + + public static boolean isReceivingRedstonePower(World world, BlockPos pos) { + return world.isReceivingRedstonePower(pos); + } + + public static int getBottomY(World world) { + return world.getBottomY(); + } + + public static int getTopY(World world) { + return world.getTopY(); + } + + public static int getDimensionHeight(World world) { + return world.getDimension().height(); + } + + public static BlockEntity getBlockEntity(World world, BlockPos pos) { + return world.getBlockEntity(pos); + } + + public static boolean hasBlockEntity(World world, BlockPos pos) { + return getBlockEntity(world, pos) != null; + } + + public static BlockState getBlockState(World world, BlockPos pos) { + return world.getBlockState(pos); + } + + public static FluidState getFluidState(World world, BlockPos pos) { + return world.getFluidState(pos); + } + + public static boolean hasFluidState(World world, BlockPos pos) { + return ! getFluidState(world, pos).isEmpty(); + } + + public static boolean isAir(World world, BlockPos pos) { + return getBlockState(world, pos).isAir(); + } + + public static boolean setBlockState(World world, BlockPos pos, BlockState state, int flags) { + return world.setBlockState(pos, state, flags); + } + + public static boolean setBlockState(World world, BlockPos pos, BlockState state) { + return setBlockState(world, pos, state, 3); + } + + public static boolean setBlockState(World world, BlockPos pos, Block block, int flags) { + return setBlockState(world, pos, block.getDefaultState(), flags); + } + + public static boolean setBlockState(World world, BlockPos pos, Block block) { + return setBlockState(world, pos, block, 3); + } + + public static boolean breakBlock(World world, BlockPos pos, boolean drop) { + return world.breakBlock(pos, drop); + } + + public static boolean breakBlock(World world, BlockPos pos) { + return breakBlock(world, pos, true); + } + + public static boolean breakBlock(World world, BlockPos pos, boolean drop, @Nullable Player player) { + if (player == null) + return world.breakBlock(pos, drop, null); + + return world.breakBlock(pos, drop, player.getPlayerEntity()); + } + + public static boolean breakBlock(World world, BlockPos pos, @Nullable Player player) { + return breakBlock(world, pos, true, player); + } + + public static void removeBlockEntity(World world, BlockPos pos) { + world.removeBlockEntity(pos); + } + + public static boolean removeBlock(World world, BlockPos pos, boolean move) { + return world.removeBlock(pos, move); + } + + public static void addParticle(World world, ParticleEffect parameters, double x, double y, double z, double velocityX, double velocityY, double velocityZ) { + world.addParticle(parameters, x, y, z, velocityX, velocityY, velocityZ); + } + + public static boolean canSetBlock(World world, BlockPos pos) { + return world.canPlace(Blocks.STONE.getDefaultState(), pos, ShapeContext.absent()); + } + + public static void updateComparators(World world, BlockPos pos, Block block) { + world.updateComparators(pos, block); + } + + public static List getPlayers(World world) { + List players = new ArrayList<>(); + for (PlayerEntity player : world.getPlayers()) { + players.add(new Player(player)); + } + + return players; + } + + public static Player getPlayer(World world, UUID uuid) { + return new Player(world.getPlayerByUuid(uuid)); + } + + public static CompatRandom getRandom(World world) { + return new CompatRandom(world.getRandom()); + } + + public static long getTime(World world) { + return world.getTime(); + } + + public static List getEntitiesByType(World world, EntityType filter, Box box, Predicate predicate) { + return world.getEntitiesByType(filter, box, predicate); + } + + public static List getEntitiesByClass(World world, Class entityClass, Box box, Predicate predicate) { + return world.getEntitiesByClass(entityClass, box, predicate); + } + + public static void spawnParticles(World world, ParticleEffect parameters, double x, double y, double z, int count, double velocityX, double velocityY, double velocityZ, double speed) { + if (!isServer(world)) return; + + ((ServerWorld) world).spawnParticles(parameters, x, y, z, count, velocityX, velocityY, velocityZ, speed); + } + + public static void updateListeners(World world, BlockPos pos, BlockState oldState, BlockState newState, int flags) { + world.updateListeners(pos, oldState, newState, flags); + } + + public static net.pitan76.mcpitanlib.midohra.block.BlockState getMidohraBlockState(World world, BlockPos pos) { + return net.pitan76.mcpitanlib.midohra.block.BlockState.of(getBlockState(world, pos)); + } + + public static boolean setBlockState(World world, BlockPos pos, net.pitan76.mcpitanlib.midohra.block.BlockState state, int flags) { + return setBlockState(world, pos, state.toMinecraft(), flags); + } + + public static boolean setBlockState(World world, BlockPos pos, net.pitan76.mcpitanlib.midohra.block.BlockState state) { + return setBlockState(world, pos, state, 3); + } + + public static boolean setBlockState(World world, net.pitan76.mcpitanlib.midohra.util.math.BlockPos pos, net.pitan76.mcpitanlib.midohra.block.BlockState state, int flags) { + return setBlockState(world, pos.toMinecraft(), state.toMinecraft(), flags); + } + + public static boolean setBlockState(World world, net.pitan76.mcpitanlib.midohra.util.math.BlockPos pos, net.pitan76.mcpitanlib.midohra.block.BlockState state) { + return setBlockState(world, pos, state, 3); + } + + public static boolean breakBlock(World world, net.pitan76.mcpitanlib.midohra.util.math.BlockPos pos, boolean drop) { + return breakBlock(world, pos.toMinecraft(), drop); + } + + public static boolean breakBlock(World world, net.pitan76.mcpitanlib.midohra.util.math.BlockPos pos) { + return breakBlock(world, pos, true); + } + + public static boolean breakBlock(World world, net.pitan76.mcpitanlib.midohra.util.math.BlockPos pos, boolean drop, @Nullable Player player) { + return breakBlock(world, pos.toMinecraft(), drop, player); + } + + public static boolean breakBlock(World world, net.pitan76.mcpitanlib.midohra.util.math.BlockPos pos, @Nullable Player player) { + return breakBlock(world, pos, true, player); + } + + public static void removeBlockEntity(World world, net.pitan76.mcpitanlib.midohra.util.math.BlockPos pos) { + removeBlockEntity(world, pos.toMinecraft()); + } + + public static boolean removeBlock(World world, net.pitan76.mcpitanlib.midohra.util.math.BlockPos pos, boolean move) { + return removeBlock(world, pos.toMinecraft(), move); + } + + public static void playSound(net.pitan76.mcpitanlib.midohra.world.World world, @Nullable Player player, net.pitan76.mcpitanlib.midohra.util.math.BlockPos pos, CompatSoundEvent sound, CompatSoundCategory category, float volume, float pitch) { + playSound(world.getRaw(), player, pos.toMinecraft(), sound, category, volume, pitch); + } + + public static void dropStackOnBlock(World world, BlockPos pos, ItemStack stack) { + Block.dropStack(world, pos, stack); + } + + public static float getSkyAngle(World world, float tickDelta) { + return world.getSkyAngle(tickDelta); + } + + public static Block getBlock(World world, BlockPos pos) { + return getBlockState(world, pos).getBlock(); + } + + public static BlockWrapper getBlockWrapper(World world, BlockPos pos) { + return BlockWrapper.of(getBlock(world, pos)); + } + + public static List getEntitiesByType(World world, EntityType filter, Box box) { + return getEntitiesByType(world, filter, box, EntityPredicates.VALID_ENTITY); + } + + public static List getEntitiesByType(World world, EntityTypeWrapper filter, Box box, Predicate predicate) { + return getEntitiesByType(world, (EntityType) filter.get(), box, predicate); + } + + public static List getEntitiesByType(World world, EntityTypeWrapper filter, Box box) { + return getEntitiesByType(world, filter.get(), box); + } + + public static CompatIdentifier getOverworldId() { + return CompatIdentifier.fromMinecraft(World.OVERWORLD.getValue()); + } + + public static CompatIdentifier getNetherId() { + return CompatIdentifier.fromMinecraft(World.NETHER.getValue()); + } + + public static CompatIdentifier getEndId() { + return CompatIdentifier.fromMinecraft(World.END.getValue()); + } + + public static long getTimeOfDay(World world) { + return world.getTimeOfDay(); + } + + public static List getEntitiesByClass(World world, Class entityClass, net.pitan76.mcpitanlib.midohra.util.math.Box box) { + return getEntitiesByClass(world, entityClass, box, EntityPredicates.VALID_ENTITY); + } + + public static List getEntitiesByClass(World world, Class entityClass, Box box) { + return getEntitiesByClass(world, entityClass, box, EntityPredicates.VALID_ENTITY); + } + + public static List getEntitiesByClass(World world, Class entityClass, net.pitan76.mcpitanlib.midohra.util.math.Box box, Predicate predicate) { + return getEntitiesByClass(world, entityClass, box.toMinecraft(), predicate); + } + + public static List getEntitiesByClass(World world, Class entityClass, Vector3d center, double radius, Predicate predicate) { + Box box = BoxUtil.createBox(center.x - radius, center.y - radius, center.z - radius, center.x + radius, center.y + radius, center.z + radius); + return getEntitiesByClass(world, entityClass, box, predicate); + } + + public static List getEntitiesByClass(World world, Class entityClass, Vector3d center, double radius) { + return getEntitiesByClass(world, entityClass, center, radius, EntityPredicates.VALID_ENTITY); + } + + public static List getMonsters(World world, Box box) { + return world.getEntitiesByClass(LivingEntity.class, box, entity -> entity instanceof Monster); + } + + public static List getMonsters(World world, net.pitan76.mcpitanlib.midohra.util.math.Box box) { + return getMonsters(world, box.toMinecraft()); + } + + public static List getMonsters(World world, Vector3d center, double radius) { + Box box = BoxUtil.createBox(center.x - radius, center.y - radius, center.z - radius, center.x + radius, center.y + radius, center.z + radius); + return getMonsters(world, box); + } + + public static List getEntitiesByType(World world, EntityTypeWrapper filter, net.pitan76.mcpitanlib.midohra.util.math.Box box) { + return getEntitiesByType(world, filter, box.toMinecraft()); + } + + public static List getEntitiesByType(World world, EntityTypeWrapper filter, net.pitan76.mcpitanlib.midohra.util.math.Box box, Predicate predicate) { + return getEntitiesByType(world, filter, box.toMinecraft(), predicate); + } + + /** + * ParticleType is a ParticleEffect only. + */ + public static void addParticle(World world, CompatParticleType parameters, double x, double y, double z, double velocityX, double velocityY, double velocityZ) { + if (parameters.getRaw() instanceof ParticleEffect) + addParticle(world, (ParticleEffect) parameters.getRaw(), x, y, z, velocityX, velocityY, velocityZ); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/block/BlockHitResultUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/block/BlockHitResultUtil.java new file mode 100644 index 000000000..4c42a10e8 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/block/BlockHitResultUtil.java @@ -0,0 +1,33 @@ +package net.pitan76.mcpitanlib.api.util.block; + +import net.minecraft.util.hit.BlockHitResult; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import net.minecraft.util.math.Vec3d; + +public class BlockHitResultUtil { + + public static BlockHitResult create(Vec3d pos, Direction direction, BlockPos blockPos, boolean insideBlock) { + return new BlockHitResult(pos, direction, blockPos, insideBlock); + } + + public static BlockHitResult create(Vec3d pos, Direction direction, BlockPos blockPos) { + return new BlockHitResult(pos, direction, blockPos, false); + } + + public static Vec3d getPos(BlockHitResult blockHitResult) { + return blockHitResult.getPos(); + } + + public static Direction getSide(BlockHitResult blockHitResult) { + return blockHitResult.getSide(); + } + + public static BlockPos getBlockPos(BlockHitResult blockHitResult) { + return blockHitResult.getBlockPos(); + } + + public static boolean isInsideBlock(BlockHitResult blockHitResult) { + return blockHitResult.isInsideBlock(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/block/BlockUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/block/BlockUtil.java new file mode 100644 index 000000000..4f1eae397 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/block/BlockUtil.java @@ -0,0 +1,235 @@ +package net.pitan76.mcpitanlib.api.util.block; + +import net.minecraft.block.Block; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.pitan76.mcpitanlib.api.block.CompatibleBlockSettings; +import net.pitan76.mcpitanlib.api.tag.TagKey; +import net.pitan76.mcpitanlib.api.text.TextComponent; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.api.util.v2.BlockUtilV2; + +import java.util.ArrayList; +import java.util.List; + +@SuppressWarnings("deprecation") +public class BlockUtil { + /** + * Check if two blocks are equal. + * @param block Block to compare. + * @param block2 Block to compare. + * @return If two blocks are equal. + */ + public static boolean isEqual(Block block, Block block2) { + return net.pitan76.mcpitanlib.api.util.BlockUtil.isEqual(block, block2); + } + + /** + * Get block from CompatIdentifier. + * @param id CompatIdentifier of the block. + * @return Block of the CompatIdentifier. + */ + public static Block fromId(CompatIdentifier id) { + return net.pitan76.mcpitanlib.api.util.BlockUtil.fromId(id); + } + + public static Block fromId(String id) { + return fromId(CompatIdentifier.of(id)); + } + + public static Block fromId(String namespace, String path) { + return fromId(CompatIdentifier.of(namespace, path)); + } + + /** + * Get CompatIdentifier from Block. + * @param block Block to get CompatIdentifier. + * @return CompatIdentifier of the Block. + */ + public static CompatIdentifier toId(Block block) { + return net.pitan76.mcpitanlib.api.util.BlockUtil.toCompatID(block); + } + + public static String toIdAsString(Block block) { + return toId(block).toString(); + } + + /** + * Check if the block exist. + * @param id CompatIdentifier of the block. + * @return If the block exist. + */ + public static boolean isExist(CompatIdentifier id) { + return net.pitan76.mcpitanlib.api.util.BlockUtil.isExist(id); + } + + public static boolean isExist(String id) { + return isExist(CompatIdentifier.of(id)); + } + + public static boolean isExist(String namespace, String path) { + return isExist(CompatIdentifier.of(namespace, path)); + } + + public static boolean isMinecraftBlock(Block block) { + return CompatIdentifier.isMinecraftNamespace(toId(block)); + } + + /** + * Create a new Block + * @param settings Block settings + * @return The new Block + */ + public static Block create(CompatibleBlockSettings settings) { + return net.pitan76.mcpitanlib.api.util.BlockUtil.of(settings); + } + + /** + * Get all blocks. + * @return List of all blocks. + */ + public static List getBlocks() { + return net.pitan76.mcpitanlib.api.util.BlockUtil.getAllBlocks(); + } + + /** + * Get blocks from tag key. + * @param tagKey Tag key of the blocks. + * @return Blocks of the tag key. + */ + public static List getInTag(TagKey tagKey) { + return net.pitan76.mcpitanlib.api.util.BlockUtil.getBlocks(tagKey); + } + + /** + * Get blocks from tag key. + * @param id CompatIdentifier of the tag key. + * @return Blocks of the tag key. + */ + public static List getInTag(CompatIdentifier id) { + return net.pitan76.mcpitanlib.api.util.BlockUtil.getBlocks(id.toMinecraft()); + } + + public static List getInTag(String id) { + return getInTag(CompatIdentifier.of(id)); + } + + public static List getInTag(String namespace, String path) { + return getInTag(CompatIdentifier.of(namespace, path)); + } + + /** + * Check if the block is in the tag. + * @param block Block to check. + * @param tagKey Tag key of the tag. + * @return If the block is in the tag. + */ + public static boolean isInTag(Block block, TagKey tagKey) { + return net.pitan76.mcpitanlib.api.util.BlockUtil.isIn(block, tagKey); + } + + /** + * Check if the block is in the tag. + * @param block Block to check. + * @param id CompatIdentifier of the tag. + * @return If the block is in the tag. + */ + public static boolean isInTag(Block block, CompatIdentifier id) { + return net.pitan76.mcpitanlib.api.util.BlockUtil.isBlockInTag(block, id.toMinecraft()); + } + + public static boolean isInTag(Block block, String id) { + return isInTag(block, CompatIdentifier.of(id)); + } + + public static boolean isInTag(Block block, String namespace, String path) { + return isInTag(block, CompatIdentifier.of(namespace, path)); + } + + /** + * Get raw id of the block. + * @param block Block to get raw id. + * @return Raw id of the block. + */ + public static int getRawId(Block block) { + return net.pitan76.mcpitanlib.api.util.BlockUtil.getRawId(block); + } + + /** + * Get block from raw id. + * @param rawId Raw id of the block. + * @return Block of the raw id. + */ + public static Block fromRawId(int rawId) { + return net.pitan76.mcpitanlib.api.util.BlockUtil.fromIndex(rawId); + } + + /** + * Get blocks in the namespace. + * @param namespace Namespace of the blocks. + * @return List of blocks in the namespace. + */ + public static List getBlocksInNamespace(String namespace) { + List blocks = new ArrayList<>(); + + for (Block block : getBlocks()) { + if (toId(block).getNamespace().equals(namespace)) { + blocks.add(block); + } + } + + return blocks; + } + + /** + * Get number of all blocks. + * @return Number of all blocks. + */ + public static int getNumberOfBlocks() { + return getBlocks().size(); + } + + /** + * Get item from block. + * @param block Block + * @return Item + */ + public static Item toItem(Block block) { + return block.asItem(); + } + + /** + * Get name of the block. + * @param block Block + * @return Name of the block. + */ + public static String getNameAsString(Block block) { + return block.getName().getString(); + } + + /** + * Get name of the block. + * @param block Block + * @return Name of the block. + */ + public static TextComponent getName(Block block) { + return new TextComponent(block.getName()); + } + + /** + * Get translation key of the block. + * @param block Block + * @return Translation key of the block. + */ + public static String getTranslationKey(Block block) { + return block.getTranslationKey(); + } + + public static Block fromItem(Item item) { + return BlockUtilV2.fromItem(item); + } + + public static Block fromItem(ItemStack stack) { + return BlockUtilV2.fromItem(stack); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/block/entity/FurnaceUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/block/entity/FurnaceUtil.java new file mode 100644 index 000000000..1a6fd78a8 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/block/entity/FurnaceUtil.java @@ -0,0 +1,43 @@ +package net.pitan76.mcpitanlib.api.util.block.entity; + +import net.minecraft.block.entity.AbstractFurnaceBlockEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.recipe.AbstractCookingRecipe; +import net.minecraft.recipe.input.SingleStackRecipeInput; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.recipe.MatchGetter; +import net.pitan76.mcpitanlib.api.recipe.input.CompatRecipeInput; +import net.pitan76.mcpitanlib.api.util.WorldUtil; +import net.pitan76.mcpitanlib.api.util.recipe.input.SingleStackRecipeInputUtil; + +public class FurnaceUtil { + public static int getDefaultCookTime() { + return AbstractFurnaceBlockEntity.DEFAULT_COOK_TIME; + } + + public static boolean canUseAsFuel(net.pitan76.mcpitanlib.midohra.item.ItemStack stack) { + return canUseAsFuel(stack.toMinecraft()); + } + + public static boolean canUseAsFuel(ItemStack stack) { + return AbstractFurnaceBlockEntity.canUseAsFuel(stack); + } + + public static void tick(World world, BlockPos pos, AbstractFurnaceBlockEntity blockEntity) { + AbstractFurnaceBlockEntity.tick(world, pos, WorldUtil.getBlockState(world, pos), blockEntity); + } + + public static int getCookTime(World world, AbstractFurnaceBlockEntity furnace, MatchGetter matchGetter) { + return getCookTime(world, furnace.getStack(0), matchGetter); + } + + public static int getCookTime(World world, ItemStack stack, MatchGetter matchGetter) { + CompatRecipeInput input = (CompatRecipeInput) SingleStackRecipeInputUtil.create(stack); + + matchGetter.getFirstMatch(input, world); + + return matchGetter.getFirstMatch(input, world).map( + (recipe) -> (recipe.getRecipe()).getCookingTime()).orElse(200); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/client/BlockEntityRendererUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/client/BlockEntityRendererUtil.java new file mode 100644 index 000000000..a6481e5e5 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/client/BlockEntityRendererUtil.java @@ -0,0 +1,14 @@ +package net.pitan76.mcpitanlib.api.util.client; + +import net.minecraft.client.render.block.entity.BlockEntityRendererFactory; +import net.pitan76.mcpitanlib.api.client.registry.CompatRegistryClient; + +public class BlockEntityRendererUtil { + public static BlockEntityRendererFactory.Context convert(CompatRegistryClient.BlockEntityRendererFactory.Context ctx) { + return new BlockEntityRendererFactory.Context(ctx.getRenderDispatcher(), ctx.getRenderManager(), ctx.getItemRenderer(), ctx.getEntityRenderDispatcher(), ctx.getLayerRenderDispatcher(), ctx.getTextRenderer()); + } + + public static CompatRegistryClient.BlockEntityRendererFactory.Context convert(BlockEntityRendererFactory.Context ctx) { + return new CompatRegistryClient.BlockEntityRendererFactory.Context(ctx.getRenderDispatcher(), ctx.getRenderManager(), ctx.getItemRenderer(), ctx.getEntityRenderDispatcher(), ctx.getLayerRenderDispatcher(), ctx.getTextRenderer()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/client/ClientUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/client/ClientUtil.java new file mode 100644 index 000000000..06c17a933 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/client/ClientUtil.java @@ -0,0 +1,118 @@ +package net.pitan76.mcpitanlib.api.util.client; + +import com.mojang.authlib.GameProfile; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.Mouse; +import net.minecraft.client.font.TextRenderer; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.network.ClientPlayerEntity; +import net.minecraft.client.render.GameRenderer; +import net.minecraft.client.render.WorldRenderer; +import net.minecraft.client.render.item.ItemRenderer; +import net.minecraft.client.texture.TextureManager; +import net.minecraft.client.util.Window; +import net.minecraft.client.world.ClientWorld; +import net.minecraft.resource.ResourceManager; +import net.minecraft.util.hit.HitResult; +import net.minecraft.util.profiler.Profiler; +import net.pitan76.mcpitanlib.api.client.option.GameOptionsWrapper; +import net.pitan76.mcpitanlib.api.entity.Player; + +import java.io.File; +import java.util.Optional; + +public class ClientUtil { + public static void setScreen(Screen screen) { + getClient().setScreen(screen); + } + + public static Screen getScreen() { + return getClient().currentScreen; + } + + public static Player getPlayer() { + return new Player(getClientPlayer()); + } + + public static ClientPlayerEntity getClientPlayer() { + return getClient().player; + } + + public static MinecraftClient getClient() { + return MinecraftClient.getInstance(); + } + + public static TextRenderer getTextRenderer() { + return getClient().textRenderer; + } + + public static ItemRenderer getItemRenderer() { + return getClient().getItemRenderer(); + } + + public static ResourceManager getResourceManager() { + return getClient().getResourceManager(); + } + + public static TextureManager getTextureManager() { + return getClient().getTextureManager(); + } + + public static ClientWorld getWorld() { + return getClient().world; + } + + public static GameRenderer getGameRenderer() { + return getClient().gameRenderer; + } + + public static Optional getTime() { + if (getClient().world == null) return Optional.empty(); + return Optional.of(getClient().world.getTime()); + } + + public static long getRenderTime() { + return getClient().getRenderTime(); + } + + public static HitResult getTarget() { + return getClient().crosshairTarget; + } + + public static WorldRenderer getWorldRenderer() { + return getClient().worldRenderer; + } + + public static File getRunDirectory() { + return getClient().runDirectory; + } + + // TODO: 1.21.2 + public static Profiler getProfiler() { + return null; + } + + public static GameProfile getGameProfile() { + return getClient().getGameProfile(); + } + + public static Window getWindow() { + return getClient().getWindow(); + } + + public static Mouse getMouse() { + return getClient().mouse; + } + + public static boolean isInSingleplayer() { + return getClient().isInSingleplayer(); + } + + public static boolean isPaused() { + return getClient().isPaused(); + } + + public static GameOptionsWrapper getOptions() { + return new GameOptionsWrapper(getClient().options); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/client/LanguageUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/client/LanguageUtil.java new file mode 100644 index 000000000..89ce635d4 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/client/LanguageUtil.java @@ -0,0 +1,47 @@ +package net.pitan76.mcpitanlib.api.util.client; + +import net.minecraft.client.resource.language.I18n; +import net.minecraft.client.resource.language.LanguageManager; +import net.pitan76.mcpitanlib.midohra.resource.ResourceManager; + +public class LanguageUtil { + public static boolean hasTranslation(String key) { + return I18n.hasTranslation(key); + } + + public static String translate(String key) { + return I18n.translate(key); + } + + public static String translate(String key, Object... args) { + return I18n.translate(key, args); + } + + public static String translateWithFallback(String key, String fallback) { + return I18n.hasTranslation(key) ? I18n.translate(key) : fallback; + } + + public static String translateWithFallback(String key, String fallback, Object... args) { + return I18n.hasTranslation(key) ? I18n.translate(key, args) : fallback; + } + + public static LanguageManager getLanguageManager() { + return ClientUtil.getClient().getLanguageManager(); + } + + public static String getLanguage() { + return getLanguageManager().getLanguage(); + } + + public static void setLanguage(String language) { + getLanguageManager().setLanguage(language); + } + + public static void reload(net.minecraft.resource.ResourceManager resourceManager) { + getLanguageManager().reload(resourceManager); + } + + public static void reload(ResourceManager resourceManager) { + reload(resourceManager.getRaw()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/client/MatrixStackUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/client/MatrixStackUtil.java new file mode 100644 index 000000000..52a5d0a56 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/client/MatrixStackUtil.java @@ -0,0 +1,32 @@ +package net.pitan76.mcpitanlib.api.util.client; + +import net.minecraft.client.util.math.MatrixStack; +import net.pitan76.mcpitanlib.api.util.MathUtil; + +import static net.pitan76.mcpitanlib.api.util.MathUtil.getRotationDegrees; + +public class MatrixStackUtil { + public static void multiply(MatrixStack matrixStack, MathUtil.RotationAxisType type, float deg) { + matrixStack.multiply(getRotationDegrees(type, deg)); + } + + public static void push(MatrixStack matrices) { + matrices.push(); + } + + public static void pop(MatrixStack matrices) { + matrices.pop(); + } + + public static void translate(MatrixStack matrices, double x, double y, double z) { + matrices.translate(x, y, z); + } + + public static void scale(MatrixStack matrices, float x, float y, float z) { + matrices.scale(x, y, z); + } + + public static MatrixStack.Entry peek(MatrixStack matrices) { + return matrices.peek(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/client/MouseUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/client/MouseUtil.java new file mode 100644 index 000000000..898acde1d --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/client/MouseUtil.java @@ -0,0 +1,46 @@ +package net.pitan76.mcpitanlib.api.util.client; + +import net.minecraft.client.Mouse; + +public class MouseUtil { + + public static Mouse getMouse() { + return ClientUtil.getMouse(); + } + + public static double getMouseX() { + return getMouse().getX(); + } + + public static double getMouseY() { + return getMouse().getY(); + } + + public static boolean isCursorLocked() { + return getMouse().isCursorLocked(); + } + + public static void lockCursor() { + getMouse().lockCursor(); + } + + public static void unlockCursor() { + getMouse().unlockCursor(); + } + + public static void tick() { + getMouse().tick(); + } + + public static boolean wasLeftButtonClicked() { + return getMouse().wasLeftButtonClicked(); + } + + public static boolean wasRightButtonClicked() { + return getMouse().wasRightButtonClicked(); + } + + public static boolean wasMiddleButtonClicked() { + return getMouse().wasMiddleButtonClicked(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/client/RenderUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/client/RenderUtil.java new file mode 100644 index 000000000..0632da0b3 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/client/RenderUtil.java @@ -0,0 +1,33 @@ +package net.pitan76.mcpitanlib.api.util.client; + +import com.mojang.blaze3d.systems.RenderSystem; +import net.minecraft.client.render.GameRenderer; +import net.minecraft.util.Identifier; + +public class RenderUtil { + public static void setShaderToPositionTexProgram() { + RenderSystem.setShader(GameRenderer::getPositionTexProgram); + } + + public static void setShaderColor(float red, float green, float blue, float alpha) { + RenderSystem.setShaderColor(red, green, blue, alpha); + } + + public static void setShaderTexture(int texture, Identifier id) { + RenderSystem.setShaderTexture(texture, id); + } + + public static void enableDepthTest() { + RenderSystem.enableDepthTest(); + } + + public static void enableTexture() { + // ~1.19.2 + } + + public static void disableTexture() { + // ~1.19.2 + } + + public static class RendererUtil extends ScreenUtil.RendererUtil {} +} \ No newline at end of file diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/client/ScreenUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/client/ScreenUtil.java new file mode 100644 index 000000000..7ba434766 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/client/ScreenUtil.java @@ -0,0 +1,210 @@ +package net.pitan76.mcpitanlib.api.util.client; + +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.font.TextRenderer; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.gui.widget.ButtonWidget; +import net.minecraft.screen.ScreenTexts; +import net.minecraft.text.OrderedText; +import net.minecraft.text.Text; +import net.minecraft.util.Identifier; +import net.pitan76.mcpitanlib.api.client.gui.widget.CompatibleTexturedButtonWidget; +import net.pitan76.mcpitanlib.api.client.gui.widget.RedrawableTexturedButtonWidget; +import net.pitan76.mcpitanlib.api.client.render.DrawObjectDM; +import net.pitan76.mcpitanlib.api.text.TextComponent; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +@Environment(EnvType.CLIENT) +public class ScreenUtil { + public static void setBackground(Identifier GUI, float f, float g, float h, float i) { + RenderUtil.setShaderToPositionTexProgram(); + RenderUtil.setShaderColor(f, g, h, i); + RenderUtil.setShaderTexture(0, GUI); + + // GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F); + // MinecraftClient.getInstance().getTextureManager().bindTexture(GUI); + } + + public static void setBackground(Identifier GUI) { + setBackground(GUI, 1.0F, 1.0F, 1.0F, 1.0F); + } + + // ~1.19.2 + public static void setRepeatEvents(boolean isRepeatEvents) { + } + + // ~1.19.4 + public static void setPassEvents(Screen screen, boolean isPassEvents) { + } + + public static ButtonWidget createButtonWidget(int x, int y, int width, int height, Text message, ButtonWidget.PressAction onPress) { + return createButtonWidget(x, y, width, height, message, onPress, null); + } + + public static ButtonWidget createButtonWidget(int x, int y, int width, int height, Text message, ButtonWidget.PressAction onPress, @Nullable ButtonWidget.NarrationSupplier tooltipSupplier) { + ButtonWidget.Builder builder = ButtonWidget.builder(message, onPress).dimensions(x, y, width , height); + if (tooltipSupplier != null) + builder.narrationSupplier(tooltipSupplier); + + return builder.build(); + } + + public static CompatibleTexturedButtonWidget createTexturedButtonWidget(int x, int y, int width, int height, int u, int v, Identifier texture, ButtonWidget.PressAction pressAction) { + return createTexturedButtonWidget(x, y, width, height, u, v, height, texture, pressAction); + } + + public static CompatibleTexturedButtonWidget createTexturedButtonWidget(int x, int y, int width, int height, int u, int v, int hoveredVOffset, Identifier texture, ButtonWidget.PressAction pressAction) { + return createTexturedButtonWidget(x, y, width, height, u, v, hoveredVOffset, texture, 256, 256, pressAction); + } + + public static CompatibleTexturedButtonWidget createTexturedButtonWidget(int x, int y, int width, int height, int u, int v, int hoveredVOffset, Identifier texture, int textureWidth, int textureHeight, ButtonWidget.PressAction pressAction) { + return createTexturedButtonWidget(x, y, width, height, u, v, hoveredVOffset, texture, textureWidth, textureHeight, pressAction, Texts.empty()); + } + + public static CompatibleTexturedButtonWidget createTexturedButtonWidget(int x, int y, int width, int height, int u, int v, int hoveredVOffset, Identifier texture, int textureWidth, int textureHeight, ButtonWidget.PressAction pressAction, Text message) { + return new CompatibleTexturedButtonWidget(x, y, width, height, u, v, hoveredVOffset, texture, textureWidth, textureHeight, pressAction, message); + } + + public static RedrawableTexturedButtonWidget createRedrawableTexturedButtonWidget(int x, int y, int width, int height, int u, int v, Identifier texture, ButtonWidget.PressAction pressAction) { + return createRedrawableTexturedButtonWidget(x, y, width, height, u, v, height, texture, pressAction); + } + + public static RedrawableTexturedButtonWidget createRedrawableTexturedButtonWidget(int x, int y, int width, int height, int u, int v, int hoveredVOffset, Identifier texture, ButtonWidget.PressAction pressAction) { + return createRedrawableTexturedButtonWidget(x, y, width, height, u, v, hoveredVOffset, texture, 256, 256, pressAction); + } + + public static RedrawableTexturedButtonWidget createRedrawableTexturedButtonWidget(int x, int y, int width, int height, int u, int v, int hoveredVOffset, Identifier texture, int textureWidth, int textureHeight, ButtonWidget.PressAction pressAction) { + return createRedrawableTexturedButtonWidget(x, y, width, height, u, v, hoveredVOffset, texture, textureWidth, textureHeight, pressAction, Texts.empty()); + } + + public static RedrawableTexturedButtonWidget createRedrawableTexturedButtonWidget(int x, int y, int width, int height, int u, int v, int hoveredVOffset, Identifier texture, int textureWidth, int textureHeight, ButtonWidget.PressAction pressAction, Text message) { + return new RedrawableTexturedButtonWidget(x, y, width, height, u, v, hoveredVOffset, texture, textureWidth, textureHeight, pressAction, message); + } + + public static CompatibleTexturedButtonWidget createTexturedButtonWidget(int x, int y, int width, int height, int u, int v, CompatIdentifier texture, ButtonWidget.PressAction pressAction) { + return createTexturedButtonWidget(x, y, width, height, u, v, height, texture.toMinecraft(), pressAction); + } + + public static CompatibleTexturedButtonWidget createTexturedButtonWidget(int x, int y, int width, int height, int u, int v, int hoveredVOffset, CompatIdentifier texture, ButtonWidget.PressAction pressAction) { + return createTexturedButtonWidget(x, y, width, height, u, v, hoveredVOffset, texture.toMinecraft(), pressAction); + } + + public static CompatibleTexturedButtonWidget createTexturedButtonWidget(int x, int y, int width, int height, int u, int v, int hoveredVOffset, CompatIdentifier texture, int textureWidth, int textureHeight, ButtonWidget.PressAction pressAction) { + return createTexturedButtonWidget(x, y, width, height, u, v, hoveredVOffset, texture.toMinecraft(), textureWidth, textureHeight, pressAction); + } + + public static CompatibleTexturedButtonWidget createTexturedButtonWidget(int x, int y, int width, int height, int u, int v, int hoveredVOffset, CompatIdentifier texture, int textureWidth, int textureHeight, ButtonWidget.PressAction pressAction, Text message) { + return createTexturedButtonWidget(x, y, width, height, u, v, hoveredVOffset, texture.toMinecraft(), textureWidth, textureHeight, pressAction, message); + } + + public static RedrawableTexturedButtonWidget createRedrawableTexturedButtonWidget(int x, int y, int width, int height, int u, int v, CompatIdentifier texture, ButtonWidget.PressAction pressAction) { + return createRedrawableTexturedButtonWidget(x, y, width, height, u, v, texture.toMinecraft(), pressAction); + } + + public static RedrawableTexturedButtonWidget createRedrawableTexturedButtonWidget(int x, int y, int width, int height, int u, int v, int hoveredVOffset, CompatIdentifier texture, ButtonWidget.PressAction pressAction) { + return createRedrawableTexturedButtonWidget(x, y, width, height, u, v, hoveredVOffset, texture.toMinecraft(), pressAction); + } + + public static RedrawableTexturedButtonWidget createRedrawableTexturedButtonWidget(int x, int y, int width, int height, int u, int v, int hoveredVOffset, CompatIdentifier texture, int textureWidth, int textureHeight, ButtonWidget.PressAction pressAction) { + return createRedrawableTexturedButtonWidget(x, y, width, height, u, v, hoveredVOffset, texture.toMinecraft(), textureWidth, textureHeight, pressAction); + } + + public static RedrawableTexturedButtonWidget createRedrawableTexturedButtonWidget(int x, int y, int width, int height, int u, int v, int hoveredVOffset, CompatIdentifier texture, int textureWidth, int textureHeight, ButtonWidget.PressAction pressAction, Text message) { + return createRedrawableTexturedButtonWidget(x, y, width, height, u, v, hoveredVOffset, texture.toMinecraft(), textureWidth, textureHeight, pressAction, message); + } + + + + public static class Texts { + public static Text empty() { + return ScreenTexts.EMPTY; + } + } + + public static class TextFieldUtil extends net.pitan76.mcpitanlib.api.util.client.widget.TextFieldUtil { + // Nothing + } + + public static class ClickableWidgetUtil extends net.pitan76.mcpitanlib.api.util.client.widget.ClickableWidgetUtil { + // Nothing + } + + public static class RendererUtil { + public static int drawText(TextRenderer renderer, DrawObjectDM drawObjectDM, Text text, int x, int y, int color) { + return drawObjectDM.getContext().drawText(renderer, text, x, y, color, false); + } + + public static int drawText(TextRenderer renderer, DrawObjectDM drawObjectDM, String text, int x, int y, int color) { + return drawObjectDM.getContext().drawText(renderer, text, x, y, color, false); + } + + public static int drawText(TextRenderer renderer, DrawObjectDM drawObjectDM, OrderedText text, int x, int y, int color) { + return drawObjectDM.getContext().drawText(renderer, text, x, y, color, false); + } + + public static void drawTexture(DrawObjectDM drawObjectDM, Identifier texture, int x, int y, float u, float v, int width, int height, int textureWidth, int textureHeight) { + drawObjectDM.getContext().drawTexture(texture, x, y, u, v, width, height, textureWidth, textureHeight); + } + + public static void drawTexture(DrawObjectDM drawObjectDM, Identifier texture, int x, int y, float u, float v, int width, int height) { + drawObjectDM.getContext().drawTexture(texture, x, y, u, v, width, height, 256, 256); + } + + public static TextRenderer getTextRenderer() { + return MinecraftClient.getInstance().textRenderer; + } + + public static void drawTexture(DrawObjectDM drawObjectDM, CompatIdentifier texture, int x, int y, float u, float v, int width, int height, int textureWidth, int textureHeight) { + drawTexture(drawObjectDM, texture.toMinecraft(), x, y, u, v, width, height, textureWidth, textureHeight); + } + + public static void drawTexture(DrawObjectDM drawObjectDM, CompatIdentifier texture, int x, int y, float u, float v, int width, int height) { + drawTexture(drawObjectDM, texture.toMinecraft(), x, y, u, v, width, height); + } + + public static int drawText(TextRenderer renderer, DrawObjectDM drawObjectDM, TextComponent text, int x, int y, int color) { + return drawText(renderer, drawObjectDM, text.getText(), x, y, color); + } + + public static int drawText(TextRenderer renderer, DrawObjectDM drawObjectDM, Text text, int x, int y) { + return drawText(renderer, drawObjectDM, text, x, y, 4210752); + } + + public static int drawText(TextRenderer renderer, DrawObjectDM drawObjectDM, TextComponent text, int x, int y) { + return drawText(renderer, drawObjectDM, text, x, y, 4210752); + } + + public static void drawTooltip(DrawObjectDM drawObjectDM, TextRenderer textRenderer, Text text, int x, int y) { + drawObjectDM.getContext().drawTooltip(textRenderer, text, x, y); + } + + public static void drawTooltip(DrawObjectDM drawObjectDM, TextRenderer textRenderer, List texts, int x, int y) { + drawObjectDM.getContext().drawTooltip(textRenderer, texts, x, y); + } + + public static void drawBorder(DrawObjectDM drawObjectDM, int x, int y, int width, int height, int color) { + drawObjectDM.getContext().drawBorder(x, y, width, height, color); + } + + public static void drawTooltip(DrawObjectDM drawObjectDM, Text text, int x, int y) { + drawObjectDM.getContext().drawTooltip(getTextRenderer(), text, x, y); + } + + public static void drawTooltip(DrawObjectDM drawObjectDM, TextComponent text, int x, int y) { + drawTooltip(drawObjectDM, text.getText(), x, y); + } + + public static void drawTooltip(DrawObjectDM drawObjectDM, List texts, int x, int y) { + drawObjectDM.getContext().drawTooltip(getTextRenderer(), texts, x, y); + } + } + + public static int getWidth(Text text) { + return RendererUtil.getTextRenderer().getWidth(text); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/client/WindowUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/client/WindowUtil.java new file mode 100644 index 000000000..a57e74910 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/client/WindowUtil.java @@ -0,0 +1,42 @@ +package net.pitan76.mcpitanlib.api.util.client; + +import net.minecraft.client.util.Window; + +public class WindowUtil { + + public static Window getWindow() { + return ClientUtil.getWindow(); + } + + public static int getWindowScaledWidth() { + return getWindow().getScaledWidth(); + } + + public static int getWindowScaledHeight() { + return getWindow().getScaledHeight(); + } + + public static int getWindowWidth() { + return getWindow().getWidth(); + } + + public static int getWindowHeight() { + return getWindow().getHeight(); + } + + public static int getWindowX() { + return getWindow().getX(); + } + + public static int getWindowY() { + return getWindow().getY(); + } + + public static void setTitle(String title) { + getWindow().setTitle(title); + } + + public static void close() { + getWindow().close(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/client/render/CompatItemDisplayContext.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/client/render/CompatItemDisplayContext.java new file mode 100644 index 000000000..ea6d92e62 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/client/render/CompatItemDisplayContext.java @@ -0,0 +1,39 @@ +package net.pitan76.mcpitanlib.api.util.client.render; + +import net.minecraft.client.render.model.json.ModelTransformationMode; +import net.pitan76.mcpitanlib.api.util.CompatStringIdentifiable; + +public class CompatItemDisplayContext implements CompatStringIdentifiable { + private final ModelTransformationMode context; + + public static final CompatItemDisplayContext NONE = of(ModelTransformationMode.NONE); + public static final CompatItemDisplayContext THIRD_PERSON_LEFT_HAND = of(ModelTransformationMode.THIRD_PERSON_LEFT_HAND); + public static final CompatItemDisplayContext THIRD_PERSON_RIGHT_HAND = of(ModelTransformationMode.THIRD_PERSON_RIGHT_HAND); + public static final CompatItemDisplayContext FIRST_PERSON_LEFT_HAND = of(ModelTransformationMode.FIRST_PERSON_LEFT_HAND); + public static final CompatItemDisplayContext FIRST_PERSON_RIGHT_HAND = of(ModelTransformationMode.FIRST_PERSON_RIGHT_HAND); + public static final CompatItemDisplayContext HEAD = of(ModelTransformationMode.HEAD); + public static final CompatItemDisplayContext GUI = of(ModelTransformationMode.GUI); + public static final CompatItemDisplayContext GROUND = of(ModelTransformationMode.GROUND); + public static final CompatItemDisplayContext FIXED = of(ModelTransformationMode.FIXED); + + public CompatItemDisplayContext(ModelTransformationMode context) { + this.context = context; + } + + public static CompatItemDisplayContext of(ModelTransformationMode context) { + return new CompatItemDisplayContext(context); + } + + public ModelTransformationMode getContext() { + return context; + } + + public String getName() { + return context.name(); + } + + @Override + public String asString_compat() { + return getName(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/client/render/CompatItemRenderUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/client/render/CompatItemRenderUtil.java new file mode 100644 index 000000000..a1bd8dae9 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/client/render/CompatItemRenderUtil.java @@ -0,0 +1,27 @@ +package net.pitan76.mcpitanlib.api.util.client.render; + +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.render.item.ItemRenderer; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.client.render.block.entity.event.BlockEntityRenderEvent; + +/** + * Cross-version utility for rendering items in block entity renderers. + */ +public class CompatItemRenderUtil { + /** + * Renders an ItemStack in FIXED transform mode. + */ + public static void renderItemFixed(ItemStack stack, BlockEntityRenderEvent e, World world) { + renderItem(stack, CompatItemDisplayContext.FIXED, e, world); + } + + /** + * Renders an ItemStack + */ + public static void renderItem(ItemStack stack, CompatItemDisplayContext displayContext, BlockEntityRenderEvent e, World world) { + ItemRenderer renderer = e.getItemRenderer() != null ? e.getItemRenderer() : MinecraftClient.getInstance().getItemRenderer(); + renderer.renderItem(stack, displayContext.getContext(), e.getLight(), e.getOverlay(), e.matrices, e.vertexConsumers, world, 0); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/client/render/VertexConsumerUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/client/render/VertexConsumerUtil.java new file mode 100644 index 000000000..8848cd85c --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/client/render/VertexConsumerUtil.java @@ -0,0 +1,203 @@ +package net.pitan76.mcpitanlib.api.util.client.render; + +import net.minecraft.client.render.OverlayTexture; +import net.minecraft.client.render.VertexConsumer; +import net.minecraft.client.util.math.MatrixStack; +import net.pitan76.mcpitanlib.api.client.render.DrawObjectMV; +import org.joml.Matrix3f; +import org.joml.Matrix4f; + +public class VertexConsumerUtil { + public static VertexConsumer vertex(VertexConsumer vertexConsumer, float x, float y, float z) { + return vertexConsumer.vertex(x, y, z); + } + + public static VertexConsumer vertex(VertexConsumer vertexConsumer, MatrixStack stack, float x, float y, float z) { + return vertexConsumer.vertex(stack.peek(), x, y, z); + } + + public static VertexConsumer normal(VertexConsumer vertexConsumer, float x, float y, float z) { + return vertexConsumer.normal(x, y, z); + } + + public static VertexConsumer color(VertexConsumer vertexConsumer, float red, float green, float blue, float alpha) { + return vertexConsumer.color(red, green, blue, alpha); + } + + public static VertexConsumer color(VertexConsumer vertexConsumer, int red, int green, int blue, int alpha) { + return vertexConsumer.color(red, green, blue, alpha); + } + + public static VertexConsumer colorARGB(VertexConsumer vertexConsumer, int argb) { + return vertexConsumer.color(argb); + } + + public static VertexConsumer colorRGB(VertexConsumer vertexConsumer, int rgb) { + return vertexConsumer.colorRgb(rgb); + } + + public static VertexConsumer light(VertexConsumer vertexConsumer, int light) { + return vertexConsumer.light(light); + } + + public static VertexConsumer overlay(VertexConsumer vertexConsumer, int overlay) { + return vertexConsumer.overlay(overlay); + } + + public static VertexConsumer overlayDefaultUV(VertexConsumer vertexConsumer) { + return vertexConsumer.overlay(OverlayTexture.DEFAULT_UV); + } + + public static DrawObjectMV vertex(DrawObjectMV drawObject, float x, float y, float z) { + vertex(drawObject.getBuffer(), drawObject.getStack(), x, y, z); + return drawObject; + } + + public static DrawObjectMV normal(DrawObjectMV drawObject, float x, float y, float z) { + normal(drawObject.getBuffer(), x, y, z); + return drawObject; + } + + public static DrawObjectMV color(DrawObjectMV drawObject, float red, float green, float blue, float alpha) { + color(drawObject.getBuffer(), red, green, blue, alpha); + return drawObject; + } + + public static DrawObjectMV color(DrawObjectMV drawObject, int red, int green, int blue, int alpha) { + color(drawObject.getBuffer(), red, green, blue, alpha); + return drawObject; + } + + public static DrawObjectMV colorARGB(DrawObjectMV drawObject, int argb) { + colorARGB(drawObject.getBuffer(), argb); + return drawObject; + } + + public static DrawObjectMV colorRGB(DrawObjectMV drawObject, int rgb) { + colorRGB(drawObject.getBuffer(), rgb); + return drawObject; + } + + public static DrawObjectMV light(DrawObjectMV drawObject, int light) { + light(drawObject.getBuffer(), light); + return drawObject; + } + + public static DrawObjectMV overlay(DrawObjectMV drawObject, int overlay) { + overlay(drawObject.getBuffer(), overlay); + return drawObject; + } + + public static DrawObjectMV overlayDefaultUV(DrawObjectMV drawObject) { + overlayDefaultUV(drawObject.getBuffer()); + return drawObject; + } + + public static VertexConsumer texture(VertexConsumer vertexConsumer, float u, float v) { + return vertexConsumer.texture(u, v); + } + + public static VertexConsumer vertex(VertexConsumer vertexConsumer, Matrix4f matrix4f, float x, float y, float z) { + return vertexConsumer.vertex(matrix4f, x, y, z); + } + + public static VertexConsumer normal(VertexConsumer vertexConsumer, MatrixStack stack, float x, float y, float z) { + return vertexConsumer.normal(stack.peek(), x, y, z); + } + + public static VertexConsumer next(VertexConsumer vertexConsumer) { + return vertexConsumer; + } + + public static void renderQuad(VertexConsumer vertexConsumer, MatrixStack stack, Matrix4f matrix4f, Matrix3f matrix3f, + float x1, float y1, float z1, float x2, float y2, float z2, + float normalX, float normalY, float normalZ, int r, int g, int b, int alpha, int u, int v, int overlay, int light) { + + float[][] vertexes = new float[4][3]; + + if (Math.abs(normalY) > 0.5f) { + if (normalY > 0) { + vertexes = new float[][]{ + {x1, y1, z1}, + {x1, y1, z2}, + {x2, y1, z2}, + {x2, y1, z1} + }; + + } else { + vertexes = new float[][]{ + {x1, y1, z1}, + {x2, y1, z1}, + {x2, y1, z2}, + {x1, y1, z2} + }; + } + } else if (Math.abs(normalZ) > 0.5f) { + if (normalZ > 0) { + vertexes = new float[][]{ + {x1, y1, z1}, + {x2, y1, z1}, + {x2, y2, z1}, + {x1, y2, z1} + }; + } else { + vertexes = new float[][]{ + {x1, y1, z1}, + {x1, y2, z1}, + {x2, y2, z1}, + {x2, y1, z1} + }; + } + } else if (Math.abs(normalX) > 0.5f) { + if (normalX > 0) { + vertexes = new float[][]{ + {x1, y1, z1}, + {x1, y2, z1}, + {x1, y2, z2}, + {x1, y1, z2} + }; + } else { + vertexes = new float[][]{ + {x1, y1, z1}, + {x1, y1, z2}, + {x1, y2, z2}, + {x1, y2, z1} + }; + } + } + + for (float[] vertex : vertexes) { + if (vertex.length != 3) continue; + + vertex(vertexConsumer, matrix4f, vertex[0], vertex[1], vertex[2]); + color(vertexConsumer, r, g, b, alpha); + texture(vertexConsumer, u, v); + light(vertexConsumer, light); + normal(vertexConsumer, stack, normalX, normalY, normalZ); + next(vertexConsumer); + } + } + + public static void renderQuad(DrawObjectMV drawObject, Matrix4f matrix4f, Matrix3f matrix3f, + float x1, float y1, float z1, float x2, float y2, float z2, + float normalX, float normalY, float normalZ, int r, int g, int b, int alpha, int u, int v, int overlay, int light) { + renderQuad(drawObject.getBuffer(), drawObject.getStack(), matrix4f, matrix3f, + x1, y1, z1, x2, y2, z2, + normalX, normalY, normalZ, r, g, b, alpha, u, v, overlay, light); + + } + + public static void renderQuad(DrawObjectMV drawObject, + float x1, float y1, float z1, float x2, float y2, float z2, + float normalX, float normalY, float normalZ, int r, int g, int b, int alpha, int u, int v, int overlay, int light) { + + Matrix4f matrix4f = drawObject.getMatrix4f(); + Matrix3f matrix3f = drawObject.getMatrix3f(); + + renderQuad(drawObject.getBuffer(), drawObject.getStack(), matrix4f, matrix3f, + x1, y1, z1, x2, y2, z2, + normalX, normalY, normalZ, r, g, b, alpha, u, v, overlay, light); + + } +} + diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/client/render/VertexRenderingUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/client/render/VertexRenderingUtil.java new file mode 100644 index 000000000..4eeee7e64 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/client/render/VertexRenderingUtil.java @@ -0,0 +1,42 @@ +package net.pitan76.mcpitanlib.api.util.client.render; + +import net.minecraft.client.render.VertexConsumer; +import net.minecraft.client.render.WorldRenderer; +import net.minecraft.client.util.math.MatrixStack; +import net.pitan76.mcpitanlib.api.client.render.DrawObjectMV; +import org.joml.Matrix3f; +import org.joml.Matrix4f; + +public class VertexRenderingUtil { + public static void drawBox(MatrixStack matrices, VertexConsumer buffer, double minX, double minY, double minZ, double maxX, double maxY, double maxZ, float red, float green, float blue, float alpha) { + WorldRenderer.drawBox(matrices, buffer, minX, minY, minZ, maxX, maxY, maxZ, red, green, blue, alpha); + } + + public static void drawBox(MatrixStack matrices, VertexConsumer buffer, double minX, double minY, double minZ, double maxX, double maxY, double maxZ, float red, float green, float blue, float alpha, float xAxisRed, float yAxisGreen, float zAxisBlue) { + WorldRenderer.drawBox(matrices, buffer, minX, minY, minZ, maxX, maxY, maxZ, red, green, blue, alpha, xAxisRed, yAxisGreen, zAxisBlue); + } + + public static void drawFilledBox(MatrixStack matrices, VertexConsumer buffer, double minX, double minY, double minZ, double maxX, double maxY, double maxZ, float red, float green, float blue, float alpha) { + WorldRenderer.renderFilledBox(matrices, buffer, minX, minY, minZ, maxX, maxY, maxZ, red, green, blue, alpha); + } + + public static void drawBox(DrawObjectMV drawObject, double minX, double minY, double minZ, double maxX, double maxY, double maxZ, float red, float green, float blue, float alpha) { + drawBox(drawObject.getStack(), drawObject.getBuffer(), minX, minY, minZ, maxX, maxY, maxZ, red, green, blue, alpha); + } + + public static void drawBox(DrawObjectMV drawObject, double minX, double minY, double minZ, double maxX, double maxY, double maxZ, float red, float green, float blue, float alpha, float xAxisRed, float yAxisGreen, float zAxisBlue) { + drawBox(drawObject.getStack(), drawObject.getBuffer(), minX, minY, minZ, maxX, maxY, maxZ, red, green, blue, alpha, xAxisRed, yAxisGreen, zAxisBlue); + } + + public static void drawFilledBox(DrawObjectMV drawObject, double minX, double minY, double minZ, double maxX, double maxY, double maxZ, float red, float green, float blue, float alpha) { + drawFilledBox(drawObject.getStack(), drawObject.getBuffer(), minX, minY, minZ, maxX, maxY, maxZ, red, green, blue, alpha); + } + + public static void renderQuad(VertexConsumer vertexConsumer, MatrixStack stack, Matrix4f matrix4f, Matrix3f matrix3f, float x1, float y1, float z1, float x2, float y2, float z2, float normalX, float normalY, float normalZ, int r, int g, int b, int alpha, int u, int v, int overlay, int light) { + VertexConsumerUtil.renderQuad(vertexConsumer, stack, matrix4f, matrix3f, x1, y1, z1, x2, y2, z2, normalX, normalY, normalZ, r, g, b, alpha, u, v, overlay, light); + } + + public static void renderQuad(DrawObjectMV drawObject, float x1, float y1, float z1, float x2, float y2, float z2, float normalX, float normalY, float normalZ, int r, int g, int b, int alpha, int u, int v, int overlay, int light) { + renderQuad(drawObject.getBuffer(), drawObject.getStack(), drawObject.getMatrix4f(), drawObject.getMatrix3f(), x1, y1, z1, x2, y2, z2, normalX, normalY, normalZ, r, g, b, alpha, u, v, overlay, light); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/client/render/WorldRendererUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/client/render/WorldRendererUtil.java new file mode 100644 index 000000000..8160f8ba9 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/client/render/WorldRendererUtil.java @@ -0,0 +1,15 @@ +package net.pitan76.mcpitanlib.api.util.client.render; + +import net.minecraft.client.render.WorldRenderer; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +public class WorldRendererUtil { + public static int getLightmapCoordinates(World world, BlockPos pos) { + return WorldRenderer.getLightmapCoordinates(world, pos); + } + + public static int getLightmapCoordinates(net.pitan76.mcpitanlib.midohra.world.World world, net.pitan76.mcpitanlib.midohra.util.math.BlockPos pos) { + return getLightmapCoordinates(world.getRaw(), pos.toMinecraft()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/client/v2/RenderUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/client/v2/RenderUtil.java new file mode 100644 index 000000000..cc3313a48 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/client/v2/RenderUtil.java @@ -0,0 +1,9 @@ +package net.pitan76.mcpitanlib.api.util.client.v2; + +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; + +public class RenderUtil extends net.pitan76.mcpitanlib.api.util.client.RenderUtil { + public static void setShaderTexture(int texture, CompatIdentifier id) { + setShaderTexture(texture, id.toMinecraft()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/client/v2/ScreenUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/client/v2/ScreenUtil.java new file mode 100644 index 000000000..ac619fbdd --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/client/v2/ScreenUtil.java @@ -0,0 +1,35 @@ +package net.pitan76.mcpitanlib.api.util.client.v2; + +import net.minecraft.client.gui.Element; +import net.minecraft.client.gui.screen.Screen; + +public class ScreenUtil extends net.pitan76.mcpitanlib.api.util.client.ScreenUtil { + + public static void setFocus(Screen screen, boolean focus) { + screen.setFocused(focus); + } + + public static void setFocus(Screen screen, Element element) { + screen.setFocused(element); + } + + public static boolean isFocused(Screen screen) { + return screen.isFocused(); + } + + public static void setDragging(Screen screen, boolean dragging) { + screen.setDragging(dragging); + } + + public static boolean isDragging(Screen screen) { + return screen.isDragging(); + } + + public static int getWidth(Screen screen) { + return screen.width; + } + + public static int getHeight(Screen screen) { + return screen.height; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/client/widget/ClickableWidgetUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/client/widget/ClickableWidgetUtil.java new file mode 100644 index 000000000..7182eb723 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/client/widget/ClickableWidgetUtil.java @@ -0,0 +1,10 @@ +package net.pitan76.mcpitanlib.api.util.client.widget; + +import net.minecraft.client.gui.widget.ClickableWidget; +import net.pitan76.mcpitanlib.api.client.render.handledscreen.RenderArgs; + +public class ClickableWidgetUtil { + public static void render(ClickableWidget widget, RenderArgs args) { + widget.render(args.drawObjectDM.getContext(), args.mouseX, args.mouseY, args.delta); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/client/widget/TextFieldUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/client/widget/TextFieldUtil.java new file mode 100644 index 000000000..fb7cce693 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/client/widget/TextFieldUtil.java @@ -0,0 +1,77 @@ +package net.pitan76.mcpitanlib.api.util.client.widget; + +import net.minecraft.client.font.TextRenderer; +import net.minecraft.client.gui.widget.TextFieldWidget; +import net.minecraft.text.Text; +import net.pitan76.mcpitanlib.api.client.render.handledscreen.RenderArgs; +import net.pitan76.mcpitanlib.api.util.TextUtil; + +public class TextFieldUtil { + public static void setFocused(TextFieldWidget widget, boolean focused) { + widget.setFocused(focused); + } + + public static void render(TextFieldWidget widget, RenderArgs args) { + widget.render(args.drawObjectDM.getContext(), args.mouseX, args.mouseY, args.delta); + } + + public static void setEditable(TextFieldWidget widget, boolean editable) { + widget.setEditable(editable); + } + + public static void setMaxLength(TextFieldWidget widget, int maxLength) { + widget.setMaxLength(maxLength); + } + + public static void setSuggestion(TextFieldWidget widget, String suggestion) { + widget.setSuggestion(suggestion); + } + + public static void setText(TextFieldWidget widget, String text) { + widget.setText(text); + } + + public static String getText(TextFieldWidget widget) { + return widget.getText(); + } + + public static void setDrawsBackground(TextFieldWidget widget, boolean drawsBackground) { + widget.setDrawsBackground(drawsBackground); + } + + public static void setFocusUnlocked(TextFieldWidget widget, boolean focusUnlocked) { + widget.setFocusUnlocked(focusUnlocked); + } + + public static boolean isFocused(TextFieldWidget widget) { + return widget.isFocused(); + } + + public static boolean keyPressed(TextFieldWidget widget, int keyCode, int scanCode, int modifiers) { + return widget.keyPressed(keyCode, scanCode, modifiers); + } + + public static boolean keyReleased(TextFieldWidget widget, int keyCode, int scanCode, int modifiers) { + return widget.keyReleased(keyCode, scanCode, modifiers); + } + + public static boolean charTyped(TextFieldWidget widget, char chr, int modifiers) { + return widget.charTyped(chr, modifiers); + } + + public static TextFieldWidget create(TextRenderer renderer, int x, int y, int width, int height, Text text) { + return new TextFieldWidget(renderer, x, y, width, height, text); + } + + public static TextFieldWidget create(TextRenderer renderer, int width, int height, Text text) { + return new TextFieldWidget(renderer, width, height, text); + } + + public static TextFieldWidget create(TextRenderer renderer, int x, int y, int width, int height) { + return new TextFieldWidget(renderer, x, y, width, height, TextUtil.empty()); + } + + public static TextFieldWidget create(TextRenderer renderer, int width, int height) { + return new TextFieldWidget(renderer, width, height, TextUtil.empty()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/collection/ClippedItemStackList.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/collection/ClippedItemStackList.java new file mode 100644 index 000000000..432caf05f --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/collection/ClippedItemStackList.java @@ -0,0 +1,100 @@ +package net.pitan76.mcpitanlib.api.util.collection; + +import net.minecraft.inventory.Inventory; +import net.minecraft.item.ItemStack; +import net.minecraft.util.collection.DefaultedList; +import net.pitan76.mcpitanlib.api.util.inventory.ClippedInventory; +import net.pitan76.mcpitanlib.api.util.ItemStackUtil; +import org.jetbrains.annotations.NotNull; + +public class ClippedItemStackList extends ItemStackList { + + public final ItemStackList list; + public final int start; + public final int end; + + public ClippedItemStackList(ItemStackList list, int start, int end) { + super(null, null); + this.list = list; + if (start < 0 || end > list.size() || start >= end) { + throw new IllegalArgumentException("Invalid start or end indices for clipping item stack list."); + } + this.start = start; + this.end = end; + } + + public static ClippedItemStackList of(ItemStackList list, int start, int end) { + return new ClippedItemStackList(list, start, end); + } + + public static ClippedItemStackList of(ItemStackList list) { + return of(list, 0, list.size()); + } + + public static ClippedItemStackList of(ItemStackList list, int start) { + return of(list, start, list.size()); + } + + @Override + public int size() { + return end - start; + } + + @Override + public Inventory toInventory() { + return ClippedInventory.of(list.toInventory(), start, end); + } + + @Override + public DefaultedList defaultedList() { + DefaultedList clippedList = DefaultedList.ofSize(size(), ItemStackUtil.empty()); + for (int i = 0; i < size(); i++) + clippedList.set(i, get(i)); + + return clippedList; + } + + @Override + public @NotNull ItemStack get(int index) { + return list.get(start + index); + } + + @Override + public ItemStack set(int index, ItemStack element) { + return list.set(start + index, element); + } + + @Override + public ItemStack remove(int index) { + return list.remove(start + index); + } + + @Override + public boolean contains(Object o) { + for (int i = start; i < end; i++) { + if (list.get(i).equals(o)) { + return true; + } + } + return false; + } + + @Override + public boolean isEmpty() { + for (int i = start; i < end; i++) { + if (!list.get(i).isEmpty()) { + return false; + } + } + return true; + } + + @Override + public void clear() { + for (int i = start; i < end; i++) { + list.set(i, ItemStackUtil.empty()); + } + } + + +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/collection/DefaultedListUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/collection/DefaultedListUtil.java new file mode 100644 index 000000000..5db1133ae --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/collection/DefaultedListUtil.java @@ -0,0 +1,15 @@ +package net.pitan76.mcpitanlib.api.util.collection; + +import net.minecraft.util.collection.DefaultedList; + +public class DefaultedListUtil { + + public static DefaultedList of() { + return DefaultedList.of(); + } + + public static DefaultedList ofSize(int size, E defaultElement) { + return DefaultedList.ofSize(size, defaultElement); + } + +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/collection/ItemStackList.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/collection/ItemStackList.java new file mode 100644 index 000000000..3bf041152 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/collection/ItemStackList.java @@ -0,0 +1,214 @@ +package net.pitan76.mcpitanlib.api.util.collection; + +import com.google.common.collect.Lists; +import net.minecraft.inventory.Inventory; +import net.minecraft.item.ItemStack; +import net.minecraft.util.collection.DefaultedList; +import net.pitan76.mcpitanlib.api.gui.inventory.IInventory; +import net.pitan76.mcpitanlib.api.util.ItemStackUtil; +import org.apache.commons.lang3.Validate; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class ItemStackList extends DefaultedList { + + public ItemStackList(List delegate, @Nullable ItemStack initialElement) { + super(delegate, initialElement); + } + + public static ItemStackList of() { + return new ItemStackList(Lists.newArrayList(), ItemStackUtil.empty()); + } + + public static ItemStackList ofSize(int size) { + return ofSize(size, ItemStackUtil.empty()); + } + + public static ItemStackList ofSize(int size, ItemStack defaultStack) { + Validate.notNull(defaultStack); + ItemStack[] objects = new ItemStack[size]; + Arrays.fill(objects, defaultStack); + return new ItemStackList(Arrays.asList(objects), defaultStack); + } + + public static ItemStackList copyOf(ItemStack defaultStack, ItemStack... stacks) { + return new ItemStackList(Arrays.asList(stacks), defaultStack); + } + + public static Inventory toInventory(DefaultedList list) { + return IInventory.of(list); + } + + public static DefaultedList toDefaultedList(Inventory inventory) { + DefaultedList list = DefaultedList.ofSize(inventory.size(), ItemStackUtil.empty()); + for (int i = 0; i < inventory.size(); i++) { + list.set(i, inventory.getStack(i)); + } + + return list; + } + + public static ItemStackList fromInventory(Inventory inventory) { + return new ItemStackList(toDefaultedList(inventory), ItemStackUtil.empty()); + } + + public Inventory toInventory() { + return toInventory(this); + } + + public DefaultedList defaultedList() { + return this; + } + + public static ItemStackList of(DefaultedList defaultedList) { + ItemStackList stacks = ItemStackList.ofSize(defaultedList.size()); + for (int i = 0; i < defaultedList.size(); i++) { + stacks.set(i , defaultedList.get(i)); + } + + return stacks; + } + + public static ItemStackList of(ItemStack stack) { + return ItemStackList.ofSize(1, stack); + } + + // Midohra + public List toMidohra() { + List stacks = new ArrayList<>(); + for (ItemStack stack : this) { + stacks.add(net.pitan76.mcpitanlib.midohra.item.ItemStack.of(stack)); + } + + return stacks; + } + + public @NotNull net.pitan76.mcpitanlib.midohra.item.ItemStack getAsMidohra(int index) { + return net.pitan76.mcpitanlib.midohra.item.ItemStack.of(get(index)); + } + + public net.pitan76.mcpitanlib.midohra.item.ItemStack getFirstAsMidohra() { + return net.pitan76.mcpitanlib.midohra.item.ItemStack.of(getFirst()); + } + + public net.pitan76.mcpitanlib.midohra.item.ItemStack getLastAsMidohra() { + return net.pitan76.mcpitanlib.midohra.item.ItemStack.of(getLast()); + } + + public boolean add(net.pitan76.mcpitanlib.midohra.item.ItemStack stack) { + return add(stack.toMinecraft()); + } + + public boolean addAll(List stacks) { + boolean changed = false; + for (net.pitan76.mcpitanlib.midohra.item.ItemStack stack : stacks) { + changed |= add(stack); + } + + return changed; + } + + public boolean addAll(net.pitan76.mcpitanlib.midohra.item.ItemStack... stacks) { + return addAll(Arrays.asList(stacks)); + } + + public boolean remove(net.pitan76.mcpitanlib.midohra.item.ItemStack stack) { + return remove(stack.toMinecraft()); + } + + public boolean removeAll(List stacks) { + boolean changed = false; + for (net.pitan76.mcpitanlib.midohra.item.ItemStack stack : stacks) { + changed |= remove(stack); + } + + return changed; + } + + public boolean removeAll(net.pitan76.mcpitanlib.midohra.item.ItemStack... stacks) { + return removeAll(Arrays.asList(stacks)); + } + + public boolean contains(net.pitan76.mcpitanlib.midohra.item.ItemStack stack) { + return contains(stack.toMinecraft()); + } + + public boolean containsAll(List stacks) { + for (net.pitan76.mcpitanlib.midohra.item.ItemStack stack : stacks) { + if (!contains(stack)) { + return false; + } + } + + return true; + } + + public boolean containsAll(net.pitan76.mcpitanlib.midohra.item.ItemStack... stacks) { + return containsAll(Arrays.asList(stacks)); + } + + public boolean containsAny(List stacks) { + for (net.pitan76.mcpitanlib.midohra.item.ItemStack stack : stacks) { + if (contains(stack)) { + return true; + } + } + + return false; + } + + public boolean containsAny(net.pitan76.mcpitanlib.midohra.item.ItemStack... stacks) { + return containsAny(Arrays.asList(stacks)); + } + + public boolean equals(List stacks) { + if (size() != stacks.size()) { + return false; + } + + for (int i = 0; i < size(); i++) { + if (!get(i).equals(stacks.get(i).toMinecraft())) { + return false; + } + } + + return true; + } + + public boolean equals(net.pitan76.mcpitanlib.midohra.item.ItemStack... stacks) { + return equals(Arrays.asList(stacks)); + } + + public static ItemStackList of(List stacks) { + ItemStackList list = ItemStackList.ofSize(stacks.size()); + for (int i = 0; i < stacks.size(); i++) { + list.set(i, stacks.get(i).toMinecraft()); + } + + return list; + } + + public static ItemStackList of(net.pitan76.mcpitanlib.midohra.item.ItemStack... stacks) { + return ItemStackList.of(Arrays.asList(stacks)); + } + + public static ItemStackList of(net.pitan76.mcpitanlib.midohra.item.ItemStack stack) { + return of(stack, 1); + } + + public static ItemStackList of(net.pitan76.mcpitanlib.midohra.item.ItemStack stack, int size) { + return ItemStackList.ofSize(size, stack.toMinecraft()); + } + + public static ItemStackList of2(List stacks) { + ItemStackList list = ItemStackList.ofSize(stacks.size()); + for (int i = 0; i < stacks.size(); i++) + list.set(i, stacks.get(i)); + + return list; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/color/CompatBrightness.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/color/CompatBrightness.java new file mode 100644 index 000000000..bb113ce46 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/color/CompatBrightness.java @@ -0,0 +1,40 @@ +package net.pitan76.mcpitanlib.api.util.color; + +import net.minecraft.block.MapColor; + +public class CompatBrightness { + private final MapColor.Brightness brightness; + + public static final CompatBrightness LOW = of(MapColor.Brightness.LOW); + public static final CompatBrightness NORMAL = of(MapColor.Brightness.NORMAL); + public static final CompatBrightness HIGH = of(MapColor.Brightness.HIGH); + public static final CompatBrightness LOWEST = of(MapColor.Brightness.LOWEST); + + public CompatBrightness(MapColor.Brightness brightness) { + this.brightness = brightness; + } + + public static CompatBrightness of(MapColor.Brightness brightness) { + return new CompatBrightness(brightness); + } + + public MapColor.Brightness get() { + return brightness; + } + + public String getName() { + return get().name(); + } + + public int getId() { + return get().id; + } + + public int getBrightness() { + return get().brightness; + } + + + + +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/color/CompatDyeColor.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/color/CompatDyeColor.java new file mode 100644 index 000000000..82c31796e --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/color/CompatDyeColor.java @@ -0,0 +1,46 @@ +package net.pitan76.mcpitanlib.api.util.color; + +import net.minecraft.util.DyeColor; +import net.pitan76.mcpitanlib.api.util.CompatStringIdentifiable; + +public class CompatDyeColor implements CompatStringIdentifiable { + private final DyeColor color; + + public static final CompatDyeColor WHITE = of(DyeColor.WHITE); + public static final CompatDyeColor ORANGE = of(DyeColor.ORANGE); + public static final CompatDyeColor MAGENTA = of(DyeColor.MAGENTA); + public static final CompatDyeColor LIGHT_BLUE = of(DyeColor.LIGHT_BLUE); + public static final CompatDyeColor YELLOW = of(DyeColor.YELLOW); + public static final CompatDyeColor LIME = of(DyeColor.LIME); + public static final CompatDyeColor PINK = of(DyeColor.PINK); + public static final CompatDyeColor GRAY = of(DyeColor.GRAY); + public static final CompatDyeColor LIGHT_GRAY = of(DyeColor.LIGHT_GRAY); + public static final CompatDyeColor CYAN = of(DyeColor.CYAN); + public static final CompatDyeColor PURPLE = of(DyeColor.PURPLE); + public static final CompatDyeColor BLUE = of(DyeColor.BLUE); + public static final CompatDyeColor BROWN = of(DyeColor.BROWN); + public static final CompatDyeColor GREEN = of(DyeColor.GREEN); + public static final CompatDyeColor RED = of(DyeColor.RED); + public static final CompatDyeColor BLACK = of(DyeColor.BLACK); + + public CompatDyeColor(DyeColor color) { + this.color = color; + } + + public static CompatDyeColor of(DyeColor color) { + return new CompatDyeColor(color); + } + + public DyeColor getColor() { + return color; + } + + public String getName() { + return color.getName(); + } + + @Override + public String asString_compat() { + return getName(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/color/CompatMapColor.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/color/CompatMapColor.java new file mode 100644 index 000000000..08c7084cc --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/color/CompatMapColor.java @@ -0,0 +1,94 @@ +package net.pitan76.mcpitanlib.api.util.color; + +import net.minecraft.block.MapColor; + +public class CompatMapColor { + private final MapColor color; + + public static final CompatMapColor CLEAR = of(MapColor.CLEAR); + public static final CompatMapColor PALE_GREEN = of(MapColor.PALE_GREEN); + public static final CompatMapColor PALE_YELLOW = of(MapColor.PALE_YELLOW); + public static final CompatMapColor WHITE_GRAY = of(MapColor.WHITE_GRAY); + public static final CompatMapColor BRIGHT_RED = of(MapColor.BRIGHT_RED); + public static final CompatMapColor PALE_PURPLE = of(MapColor.PALE_PURPLE); + public static final CompatMapColor IRON_GRAY = of(MapColor.IRON_GRAY); + public static final CompatMapColor DARK_GREEN = of(MapColor.DARK_GREEN); + public static final CompatMapColor WHITE = of(MapColor.WHITE); + public static final CompatMapColor LIGHT_BLUE_GRAY = of(MapColor.LIGHT_BLUE_GRAY); + public static final CompatMapColor DIRT_BROWN = of(MapColor.DIRT_BROWN); + public static final CompatMapColor STONE_GRAY = of(MapColor.STONE_GRAY); + public static final CompatMapColor WATER_BLUE = of(MapColor.WATER_BLUE); + public static final CompatMapColor OAK_TAN = of(MapColor.OAK_TAN); + public static final CompatMapColor OFF_WHITE = of(MapColor.OFF_WHITE); + public static final CompatMapColor ORANGE = of(MapColor.ORANGE); + public static final CompatMapColor MAGENTA = of(MapColor.MAGENTA); + public static final CompatMapColor LIGHT_BLUE = of(MapColor.LIGHT_BLUE); + public static final CompatMapColor YELLOW = of(MapColor.YELLOW); + public static final CompatMapColor LIME = of(MapColor.LIME); + public static final CompatMapColor PINK = of(MapColor.PINK); + public static final CompatMapColor GRAY = of(MapColor.GRAY); + public static final CompatMapColor LIGHT_GRAY = of(MapColor.LIGHT_GRAY); + public static final CompatMapColor CYAN = of(MapColor.CYAN); + public static final CompatMapColor PURPLE = of(MapColor.PURPLE); + public static final CompatMapColor BLUE = of(MapColor.BLUE); + public static final CompatMapColor BROWN = of(MapColor.BROWN); + public static final CompatMapColor GREEN = of(MapColor.GREEN); + public static final CompatMapColor RED = of(MapColor.RED); + public static final CompatMapColor BLACK = of(MapColor.BLACK); + public static final CompatMapColor GOLD = of(MapColor.GOLD); + public static final CompatMapColor DIAMOND_BLUE = of(MapColor.DIAMOND_BLUE); + public static final CompatMapColor LAPIS_BLUE = of(MapColor.LAPIS_BLUE); + public static final CompatMapColor EMERALD_GREEN = of(MapColor.EMERALD_GREEN); + public static final CompatMapColor SPRUCE_BROWN = of(MapColor.SPRUCE_BROWN); + public static final CompatMapColor DARK_RED = of(MapColor.DARK_RED); + public static final CompatMapColor TERRACOTTA_WHITE = of(MapColor.TERRACOTTA_WHITE); + public static final CompatMapColor TERRACOTTA_ORANGE = of(MapColor.TERRACOTTA_ORANGE); + public static final CompatMapColor TERRACOTTA_MAGENTA = of(MapColor.TERRACOTTA_MAGENTA); + public static final CompatMapColor TERRACOTTA_LIGHT_BLUE = of(MapColor.TERRACOTTA_LIGHT_BLUE); + public static final CompatMapColor TERRACOTTA_YELLOW = of(MapColor.TERRACOTTA_YELLOW); + public static final CompatMapColor TERRACOTTA_LIME = of(MapColor.TERRACOTTA_LIME); + public static final CompatMapColor TERRACOTTA_PINK = of(MapColor.TERRACOTTA_PINK); + public static final CompatMapColor TERRACOTTA_GRAY = of(MapColor.TERRACOTTA_GRAY); + public static final CompatMapColor TERRACOTTA_LIGHT_GRAY = of(MapColor.TERRACOTTA_LIGHT_GRAY); + public static final CompatMapColor TERRACOTTA_CYAN = of(MapColor.TERRACOTTA_CYAN); + public static final CompatMapColor TERRACOTTA_PURPLE = of(MapColor.TERRACOTTA_PURPLE); + public static final CompatMapColor TERRACOTTA_BLUE = of(MapColor.TERRACOTTA_BLUE); + public static final CompatMapColor TERRACOTTA_BROWN = of(MapColor.TERRACOTTA_BROWN); + public static final CompatMapColor TERRACOTTA_GREEN = of(MapColor.TERRACOTTA_GREEN); + public static final CompatMapColor TERRACOTTA_RED = of(MapColor.TERRACOTTA_RED); + public static final CompatMapColor TERRACOTTA_BLACK = of(MapColor.TERRACOTTA_BLACK); + public static final CompatMapColor DULL_RED = of(MapColor.DULL_RED); + public static final CompatMapColor DULL_PINK = of(MapColor.DULL_PINK); + public static final CompatMapColor DARK_CRIMSON = of(MapColor.DARK_CRIMSON); + public static final CompatMapColor TEAL = of(MapColor.TEAL); + public static final CompatMapColor DARK_AQUA = of(MapColor.DARK_AQUA); + public static final CompatMapColor DARK_DULL_PINK = of(MapColor.DARK_DULL_PINK); + public static final CompatMapColor BRIGHT_TEAL = of(MapColor.BRIGHT_TEAL); + public static final CompatMapColor DEEPSLATE_GRAY = of(MapColor.DEEPSLATE_GRAY); + public static final CompatMapColor RAW_IRON_PINK = of(MapColor.RAW_IRON_PINK); + public static final CompatMapColor LICHEN_GREEN = of(MapColor.LICHEN_GREEN); + + public CompatMapColor(MapColor color) { + this.color = color; + } + + public static CompatMapColor of(MapColor color) { + return new CompatMapColor(color); + } + + public MapColor getColor() { + return color; + } + + public int getId() { + return color.id; + } + + public int getRgb() { + return color.color; + } + + public int getRenderColor(CompatBrightness brightness) { + return color.getRenderColor(brightness.get()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/debug/OutputUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/debug/OutputUtil.java new file mode 100644 index 000000000..2fb569972 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/debug/OutputUtil.java @@ -0,0 +1,69 @@ +package net.pitan76.mcpitanlib.api.util.debug; + +import net.minecraft.inventory.Inventory; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.pitan76.mcpitanlib.api.util.ItemUtil; +import net.pitan76.mcpitanlib.api.util.PlatformUtil; + +public class OutputUtil { + + public static boolean dev = PlatformUtil.isDevelopmentEnvironment(); + + public static void print(Item item) { + if (!dev) return; + System.out.println(getString(item)); + } + + public static void print(ItemStack stack) { + if (!dev) return; + System.out.println(getString(stack)); + } + + public static void print(Inventory inventory) { + if (!dev) return; + System.out.println(getString(inventory)); + } + + public static String getString(Item item) { + StringBuilder sb = new StringBuilder(); + sb.append("Item: {").append("\n"); + + sb.append(" Name: ").append(item.getTranslationKey()).append("\n"); + sb.append(" Id: ").append(ItemUtil.toCompatID(item)).append("\n"); + sb.append("}\n"); + + return sb.toString(); + } + + public static String getString(ItemStack stack) { + Item item = stack.getItem(); + + StringBuilder sb = new StringBuilder(); + sb.append("ItemStack: {").append("\n"); + + sb.append(getString(item)); + sb.append(" Count: ").append(stack.getCount()).append("\n"); + sb.append("}\n"); + + return sb.toString(); + } + + public static String getString(Inventory inventory) { + StringBuilder sb = new StringBuilder(); + sb.append("Inventory: {").append("\n"); + + for (int i = 0; i < inventory.size(); i++) { + ItemStack stack = inventory.getStack(i); + if (stack.isEmpty()) continue; + + sb.append(" Slot ").append(i).append(": {").append("\n"); + sb.append(getString(stack)); + sb.append(" }\n"); + } + + sb.append("}\n"); + + return sb.toString(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/entity/ArrowEntityUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/entity/ArrowEntityUtil.java new file mode 100644 index 000000000..e12d3910f --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/entity/ArrowEntityUtil.java @@ -0,0 +1,26 @@ +package net.pitan76.mcpitanlib.api.util.entity; + +import net.minecraft.entity.projectile.ArrowEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.util.ItemStackUtil; +import org.jetbrains.annotations.Nullable; + +public class ArrowEntityUtil { + public static ArrowEntity create(World world, double x, double y, double z, ItemStack stack, @Nullable ItemStack shotFrom) { + return new ArrowEntity(world, x, y, z, stack, shotFrom); + } + + public static ArrowEntity create(World world, double x, double y, double z, ItemStack stack) { + return create(world, x, y, z, stack, null); + } + + public static ArrowEntity create(World world, double x, double y, double z) { + return create(world, x, y, z, ItemStackUtil.getDefaultStack(Items.ARROW)); + } + + public static void setVelocity(ArrowEntity arrow, double x, double y, double z, float velocity, float divergence) { + arrow.setVelocity(x, y, z, velocity, divergence); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/entity/EquipmentSlotUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/entity/EquipmentSlotUtil.java new file mode 100644 index 000000000..dec1f836b --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/entity/EquipmentSlotUtil.java @@ -0,0 +1,55 @@ +package net.pitan76.mcpitanlib.api.util.entity; + +import net.minecraft.entity.EquipmentSlot; +import net.pitan76.mcpitanlib.api.item.ArmorEquipmentType; + +public class EquipmentSlotUtil { + public static boolean isArmor(EquipmentSlot slot) { + return slot == EquipmentSlot.HEAD || slot == EquipmentSlot.CHEST || slot == EquipmentSlot.LEGS || slot == EquipmentSlot.FEET; + } + + public static boolean isMainHand(EquipmentSlot slot) { + return slot == EquipmentSlot.MAINHAND; + } + + public static boolean isOffHand(EquipmentSlot slot) { + return slot == EquipmentSlot.OFFHAND; + } + + public static boolean isWeapon(EquipmentSlot slot) { + return slot == EquipmentSlot.MAINHAND || slot == EquipmentSlot.OFFHAND; + } + + public static int getEntitySlotId(EquipmentSlot slot) { + if (slot == null) + return 0; + + return slot.getEntitySlotId(); + } + + public static EquipmentSlot fromEntitySlotId(int id) { + for (EquipmentSlot slot : EquipmentSlot.values()) { + if (slot.getEntitySlotId() == id) { + return slot; + } + } + return EquipmentSlot.MAINHAND; + } + + public static ArmorEquipmentType getArmorEquipmentType(EquipmentSlot slot) { + switch (slot) { + case HEAD: + return ArmorEquipmentType.HEAD; + case CHEST: + return ArmorEquipmentType.CHEST; + case LEGS: + return ArmorEquipmentType.LEGS; + case FEET: + return ArmorEquipmentType.FEET; + case BODY: + return ArmorEquipmentType.BODY; + default: + return null; + } + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/entity/ItemEntityUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/entity/ItemEntityUtil.java new file mode 100644 index 000000000..4562d3619 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/entity/ItemEntityUtil.java @@ -0,0 +1,68 @@ +package net.pitan76.mcpitanlib.api.util.entity; + +import net.minecraft.entity.EntityType; +import net.minecraft.entity.ItemEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Box; +import net.minecraft.util.math.Vec3d; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.util.WorldUtil; + +import java.util.List; + +public class ItemEntityUtil { + public static ItemEntity create(World world, double x, double y, double z, ItemStack stack) { + return new ItemEntity(world, x, y, z, stack); + } + + public static ItemEntity create(World world, BlockPos pos, ItemStack stack) { + return create(world, pos.getX(), pos.getY(), pos.getZ(), stack); + } + + public static ItemEntity create(World world, Vec3d pos, ItemStack stack) { + return create(world, pos.x, pos.y, pos.z, stack); + } + + public static ItemEntity create(World world, double x, double y, double z, ItemStack stack, double velocityX, double velocityY, double velocityZ) { + ItemEntity itemEntity = create(world, x, y, z, stack); + setVelocity(itemEntity, velocityX, velocityY, velocityZ); + return itemEntity; + } + + public static void setVelocity(ItemEntity itemEntity, double velocityX, double velocityY, double velocityZ) { + itemEntity.setVelocity(velocityX, velocityY, velocityZ); + } + + public static void setVelocity(ItemEntity itemEntity, Vec3d vec3d) { + itemEntity.setVelocity(vec3d); + } + + public static void setPickupDelay(ItemEntity itemEntity, int pickupDelay) { + itemEntity.setPickupDelay(pickupDelay); + } + + public static void setToDefaultPickupDelay(ItemEntity itemEntity) { + itemEntity.setToDefaultPickupDelay(); + } + + public static ItemStack getStack(ItemEntity entity) { + return entity.getStack(); + } + + public static List getEntities(World world, Box box) { + return WorldUtil.getEntitiesByType(world, EntityType.ITEM, box); + } + + public static ItemEntity createWithSpawn(World world, ItemStack stack, double x, double y, double z) { + ItemEntity itemEntity = create(world, x, y, z, stack); + setToDefaultPickupDelay(itemEntity); + setVelocity(itemEntity, 0.0D, 0.0D, 0.0D); + WorldUtil.spawnEntity(world, itemEntity); + return itemEntity; + } + + public static ItemEntity createWithSpawn(World world, ItemStack stack, BlockPos pos) { + return createWithSpawn(world, stack, pos.getX(), pos.getY(), pos.getZ()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/entity/LivingEntityUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/entity/LivingEntityUtil.java new file mode 100644 index 000000000..9e74fc58f --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/entity/LivingEntityUtil.java @@ -0,0 +1,57 @@ +package net.pitan76.mcpitanlib.api.util.entity; + +import net.minecraft.entity.EquipmentSlot; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.effect.StatusEffectInstance; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.entity.effect.CompatStatusEffect; +import net.pitan76.mcpitanlib.api.entity.effect.CompatStatusEffectInstance; +import net.pitan76.mcpitanlib.api.util.EntityUtil; + +import java.util.ArrayList; +import java.util.List; + +public class LivingEntityUtil extends EntityUtil { + public static void addStatusEffect(LivingEntity entity, CompatStatusEffectInstance effect) { + entity.addStatusEffect(effect.getInstance()); + } + + public static void removeStatusEffect(LivingEntity entity, CompatStatusEffectInstance effect) { + entity.removeStatusEffect(effect.getInstance().getEffectType()); + } + + public static void removeStatusEffect(LivingEntity entity, CompatStatusEffect effect, World world) { + entity.removeStatusEffect(effect.getEntry(world)); + } + + public static List getStatusEffects(LivingEntity entity) { + List compatEffects = new ArrayList<>(); + + for (StatusEffectInstance effect : entity.getStatusEffects()) { + compatEffects.add(new CompatStatusEffectInstance(effect)); + } + + return compatEffects; + } + + public static float getHealth(LivingEntity entity) { + return entity.getHealth(); + } + + public static void setHealth(LivingEntity entity, float health) { + entity.setHealth(health); + } + + public static float getMaxHealth(LivingEntity entity) { + return entity.getMaxHealth(); + } + + public static ItemStack getEquippedStack(LivingEntity entity, EquipmentSlot slot) { + return entity.getEquippedStack(slot); + } + + public static void setEquippedStack(LivingEntity entity, EquipmentSlot slot, ItemStack stack) { + entity.equipStack(slot, stack); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/entity/ProjectileEntityUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/entity/ProjectileEntityUtil.java new file mode 100644 index 000000000..806215177 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/entity/ProjectileEntityUtil.java @@ -0,0 +1,14 @@ +package net.pitan76.mcpitanlib.api.util.entity; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.projectile.ProjectileEntity; + +public class ProjectileEntityUtil { + public static void setVelocity(ProjectileEntity projectileEntity, Entity shooter, float pitch, float yaw, float roll, float speed, float divergence) { + projectileEntity.setVelocity(shooter, pitch, yaw, roll, speed, divergence); + } + + public static void setVelocity(ProjectileEntity projectileEntity, double x, double y, double z, float power, float uncertainty) { + projectileEntity.setVelocity(x, y, z, power, uncertainty); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/entity/ServerPlayerUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/entity/ServerPlayerUtil.java new file mode 100644 index 000000000..2ea786e13 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/entity/ServerPlayerUtil.java @@ -0,0 +1,108 @@ +package net.pitan76.mcpitanlib.api.util.entity; + +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.server.world.ServerWorld; +import net.pitan76.mcpitanlib.api.entity.Player; +import net.pitan76.mcpitanlib.api.sound.CompatSoundCategory; +import net.pitan76.mcpitanlib.api.sound.CompatSoundEvent; + +import java.util.Collections; +import java.util.Optional; + +public class ServerPlayerUtil { + public static boolean teleport(ServerPlayerEntity serverPlayerEntity, ServerWorld serverWorld, double x, double y, double z, float yaw, float pitch, boolean resetCamera) { + if (resetCamera) { + serverPlayerEntity.stopRiding(); + serverPlayerEntity.setCameraEntity(serverPlayerEntity); + } + + return serverPlayerEntity.teleport(serverWorld, x, y, z, Collections.emptySet(), yaw, pitch); + } + + public static boolean teleport(ServerPlayerEntity serverPlayerEntity, ServerWorld serverWorld, double x, double y, double z, float yaw, float pitch) { + serverPlayerEntity.teleport(serverWorld, x, y, z, yaw, pitch); + return true; + } + + public static boolean teleport(ServerPlayerEntity serverPlayerEntity, ServerWorld serverWorld, double x, double y, double z) { + return teleport(serverPlayerEntity, serverWorld, x, y, z, serverPlayerEntity.getYaw(), serverPlayerEntity.getPitch()); + } + public static boolean teleport(ServerPlayerEntity serverPlayerEntity, net.pitan76.mcpitanlib.midohra.world.ServerWorld serverWorld, double x, double y, double z, float yaw, float pitch, boolean resetCamera) { + return teleport(serverPlayerEntity, serverWorld.getRaw(), x, y, z, yaw, pitch, resetCamera); + } + + public static boolean teleport(ServerPlayerEntity serverPlayerEntity, net.pitan76.mcpitanlib.midohra.world.ServerWorld serverWorld, double x, double y, double z, float yaw, float pitch) { + return teleport(serverPlayerEntity, serverWorld, x, y, z, yaw, pitch, false); + } + + public static boolean teleport(ServerPlayerEntity serverPlayerEntity, net.pitan76.mcpitanlib.midohra.world.ServerWorld serverWorld, double x, double y, double z) { + return teleport(serverPlayerEntity, serverWorld, x, y, z, serverPlayerEntity.getYaw(), serverPlayerEntity.getPitch()); + } + + public static boolean teleport(Player player, net.pitan76.mcpitanlib.midohra.world.ServerWorld serverWorld, double x, double y, double z, float yaw, float pitch, boolean resetCamera) { + Optional optionalServerPlayer = player.getServerPlayer(); + if (!optionalServerPlayer.isPresent()) return false; + + return teleport(optionalServerPlayer.get(), serverWorld, x, y, z, yaw, pitch, resetCamera); + } + + public static boolean teleport(Player player, net.pitan76.mcpitanlib.midohra.world.ServerWorld serverWorld, double x, double y, double z, float yaw, float pitch) { + return teleport(player, serverWorld, x, y, z, yaw, pitch, false); + } + + public static boolean teleport(Player player, net.pitan76.mcpitanlib.midohra.world.ServerWorld serverWorld, double x, double y, double z) { + return teleport(player, serverWorld, x, y, z, player.getYaw(), player.getPitch()); + } + + public static boolean teleport(ServerPlayerEntity serverPlayerEntity, double x, double y, double z, boolean particleEffects) { + return serverPlayerEntity.teleport(x, y, z, particleEffects); + } + + public static boolean teleport(ServerPlayerEntity serverPlayerEntity, double x, double y, double z) { + return teleport(serverPlayerEntity, x, y, z, false); + } + + public static boolean teleport(Player player, double x, double y, double z, boolean particleEffects) { + Optional optionalServerPlayer = player.getServerPlayer(); + if (!optionalServerPlayer.isPresent()) return false; + + return teleport(optionalServerPlayer.get(), x, y, z, particleEffects); + } + + public static boolean teleport(Player player, double x, double y, double z) { + return teleport(player, x, y, z, false); + } + + public static void playSound(ServerPlayerEntity serverPlayerEntity, CompatSoundEvent soundEvent, CompatSoundCategory category, float volume, float pitch) { + serverPlayerEntity.playSoundToPlayer(soundEvent.get(), category.get(), volume, pitch); + } + + public static void playSound(ServerPlayerEntity serverPlayerEntity, CompatSoundEvent soundEvent, float volume, float pitch) { + serverPlayerEntity.playSound(soundEvent.get(), volume, pitch); + } + + public static void playSound(ServerPlayerEntity serverPlayerEntity, CompatSoundEvent soundEvent) { + serverPlayerEntity.playSound(soundEvent.get()); + } + + public static void playSound(Player player, CompatSoundEvent soundEvent, CompatSoundCategory category, float volume, float pitch) { + Optional optionalServerPlayer = player.getServerPlayer(); + if (!optionalServerPlayer.isPresent()) return; + + playSound(optionalServerPlayer.get(), soundEvent, category, volume, pitch); + } + + public static void playSound(Player player, CompatSoundEvent soundEvent, float volume, float pitch) { + Optional optionalServerPlayer = player.getServerPlayer(); + if (!optionalServerPlayer.isPresent()) return; + + playSound(optionalServerPlayer.get(), soundEvent, volume, pitch); + } + + public static void playSound(Player player, CompatSoundEvent soundEvent) { + Optional optionalServerPlayer = player.getServerPlayer(); + if (!optionalServerPlayer.isPresent()) return; + + playSound(optionalServerPlayer.get(), soundEvent); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/entity/SmallFireballEntityUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/entity/SmallFireballEntityUtil.java new file mode 100644 index 000000000..38f484a37 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/entity/SmallFireballEntityUtil.java @@ -0,0 +1,29 @@ +package net.pitan76.mcpitanlib.api.util.entity; + +import net.minecraft.entity.projectile.SmallFireballEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.util.math.Vec3d; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.util.math.Vec3dUtil; + +public class SmallFireballEntityUtil { + public static SmallFireballEntity create(World world, double x, double y, double z, double velocityX, double velocityY, double velocityZ) { + return new SmallFireballEntity(world, x, y, z, Vec3dUtil.create(velocityX, velocityY, velocityZ)); + } + + public static SmallFireballEntity create(World world, double x, double y, double z, Vec3d velocity) { + return new SmallFireballEntity(world, x, y, z, velocity); + } + + public static void setVelocity(SmallFireballEntity entity, double x, double y, double z, float velocity, float divergence) { + entity.setVelocity(x, y, z, velocity, divergence); + } + + public static void setItem(SmallFireballEntity entity, ItemStack stack) { + entity.setItem(stack); + } + + public static ItemStack getItem(SmallFireballEntity entity) { + return entity.getStack(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/entity/SnowballEntityUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/entity/SnowballEntityUtil.java new file mode 100644 index 000000000..272bf5fdc --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/entity/SnowballEntityUtil.java @@ -0,0 +1,30 @@ +package net.pitan76.mcpitanlib.api.util.entity; + +import net.minecraft.entity.projectile.thrown.SnowballEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.util.ItemStackUtil; + +public class SnowballEntityUtil { + public static SnowballEntity create(World world, double x, double y, double z) { + return new SnowballEntity(world, x, y, z); + } + + public static SnowballEntity create(World world, double x, double y, double z, ItemStack stack) { + SnowballEntity entity = create(world, x, y, z); + entity.setItem(stack); + return entity; + } + + public static void setVelocity(SnowballEntity entity, double x, double y, double z, float velocity, float divergence) { + entity.setVelocity(x, y, z, velocity, divergence); + } + + public static void setItem(SnowballEntity entity, ItemStack stack) { + entity.setItem(stack); + } + + public static ItemStack getItem(SnowballEntity entity) { + return entity.getStack(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/entity/SpectralArrowEntityUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/entity/SpectralArrowEntityUtil.java new file mode 100644 index 000000000..2f83e9548 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/entity/SpectralArrowEntityUtil.java @@ -0,0 +1,26 @@ +package net.pitan76.mcpitanlib.api.util.entity; + +import net.minecraft.entity.projectile.SpectralArrowEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.util.ItemStackUtil; +import org.jetbrains.annotations.Nullable; + +public class SpectralArrowEntityUtil { + public static SpectralArrowEntity create(World world, double x, double y, double z, ItemStack stack, @Nullable ItemStack shotFrom) { + return new SpectralArrowEntity(world, x, y, z, stack, shotFrom); + } + + public static SpectralArrowEntity create(World world, double x, double y, double z, ItemStack stack) { + return create(world, x, y, z, stack, null); + } + + public static SpectralArrowEntity create(World world, double x, double y, double z) { + return create(world, x, y, z, ItemStackUtil.getDefaultStack(Items.ARROW)); + } + + public static void setVelocity(SpectralArrowEntity arrow, double x, double y, double z, float velocity, float divergence) { + arrow.setVelocity(x, y, z, velocity, divergence); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/entity/ThrownItemEntityUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/entity/ThrownItemEntityUtil.java new file mode 100644 index 000000000..73dfb6cc4 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/entity/ThrownItemEntityUtil.java @@ -0,0 +1,36 @@ +package net.pitan76.mcpitanlib.api.util.entity; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.projectile.thrown.ThrownItemEntity; +import net.minecraft.item.ItemStack; +import net.pitan76.mcpitanlib.api.entity.CompatThrownItemEntity; + +public class ThrownItemEntityUtil { + public static ItemStack getItem(ThrownItemEntity entity) { + return entity.getStack(); + } + + public static void setItem(ThrownItemEntity entity, ItemStack stack) { + entity.setItem(stack); + } + + public static ItemStack getStack(ThrownItemEntity entity) { + return entity.getStack(); + } + + public static void setVelocity(ThrownItemEntity entity, Entity shooter, float pitch, float yaw, float roll, float speed, float divergence) { + ProjectileEntityUtil.setVelocity(entity, shooter, pitch, yaw, roll, speed, divergence); + } + + public static void setVelocity(CompatThrownItemEntity entity, Entity shooter, float pitch, float yaw, float roll, float speed, float divergence) { + ProjectileEntityUtil.setVelocity(entity, shooter, pitch, yaw, roll, speed, divergence); + } + + public static void setVelocity(ThrownItemEntity entity, double x, double y, double z, float power, float uncertainty) { + ProjectileEntityUtil.setVelocity(entity, x, y, z, power, uncertainty); + } + + public static void setVelocity(CompatThrownItemEntity entity, double x, double y, double z, float power, float uncertainty) { + ProjectileEntityUtil.setVelocity(entity, x, y, z, power, uncertainty); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/event/BlockEventGenerator.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/event/BlockEventGenerator.java new file mode 100644 index 000000000..9b6d83c3d --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/event/BlockEventGenerator.java @@ -0,0 +1,20 @@ +package net.pitan76.mcpitanlib.api.util.event; + +import net.minecraft.block.Block; +import net.pitan76.mcpitanlib.api.event.block.BlockBreakEvent; +import net.pitan76.mcpitanlib.api.event.block.BlockPlacedEvent; +import net.pitan76.mcpitanlib.api.event.block.StateReplacedEvent; + +public class BlockEventGenerator { + public static void onPlaced(Block block, BlockPlacedEvent e) { + block.onPlaced(e.world, e.pos, e.state, e.placer, e.stack); + } + + public static void onBreak(Block block, BlockBreakEvent e) { + block.onBreak(e.world, e.pos, e.state, e.getPlayerEntity()); + } + + public static void onStateReplaced(Block block, StateReplacedEvent e) { + block.onStateReplaced(e.state, e.world, e.pos, e.newState, e.moved); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/event/ItemEventGenerator.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/event/ItemEventGenerator.java new file mode 100644 index 000000000..82bffcfb1 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/event/ItemEventGenerator.java @@ -0,0 +1,11 @@ +package net.pitan76.mcpitanlib.api.util.event; + +import net.minecraft.item.Item; +import net.pitan76.mcpitanlib.api.event.item.ItemUseEvent; +import net.pitan76.mcpitanlib.api.util.CompatActionResult; + +public class ItemEventGenerator { + public static CompatActionResult onRightClick(Item item, ItemUseEvent e) { + return CompatActionResult.create(item.use(e.world, e.user.getPlayerEntity(), e.hand).getResult()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/inventory/ClippedInventory.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/inventory/ClippedInventory.java new file mode 100644 index 000000000..49bcbc196 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/inventory/ClippedInventory.java @@ -0,0 +1,91 @@ +package net.pitan76.mcpitanlib.api.util.inventory; + +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.inventory.Inventory; +import net.minecraft.item.ItemStack; +import net.pitan76.mcpitanlib.api.util.ItemStackUtil; + +public class ClippedInventory implements Inventory, ICompatInventory { + + private final Inventory inventory; + private final int start; + private final int end; + + public static ClippedInventory of(Inventory inventory, int start, int end) { + if (start < 0 || end > inventory.size() || start >= end) { + throw new IllegalArgumentException("Invalid start or end indices for clipping inventory."); + } + return new ClippedInventory(inventory, start, end); + } + + public static ClippedInventory of(Inventory inventory) { + return of(inventory, 0, inventory.size()); + } + + public static ClippedInventory of(Inventory inventory, int start) { + return of(inventory, start, inventory.size()); + } + + public ClippedInventory(Inventory inventory, int start, int end) { + this.inventory = inventory; + this.start = start; + this.end = end; + } + + @Override + public int size() { + return end - start; + } + + @Override + public boolean isEmpty() { + for (int i = start; i < end; i++) { + if (!inventory.getStack(i).isEmpty()) { + return false; + } + } + return true; + } + + @Override + public ItemStack getStack(int slot) { + return inventory.getStack(start + slot); + } + + @Override + public ItemStack removeStack(int slot, int amount) { + return inventory.removeStack(start + slot, amount); + } + + @Override + public ItemStack removeStack(int slot) { + return inventory.removeStack(start + slot); + } + + @Override + public void setStack(int slot, ItemStack stack) { + inventory.setStack(start + slot, stack); + } + + @Override + public void markDirty() { + inventory.markDirty(); + } + + @Override + public boolean canPlayerUse(PlayerEntity player) { + return inventory.canPlayerUse(player); + } + + @Override + public void clear() { + for (int i = start; i < end; i++) { + inventory.setStack(i, ItemStackUtil.empty()); + } + } + + @Override + public int getMaxCountPerStack() { + return inventory.getMaxCountPerStack(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/inventory/CompatInventory.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/inventory/CompatInventory.java new file mode 100644 index 000000000..1f8fc9524 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/inventory/CompatInventory.java @@ -0,0 +1,213 @@ +package net.pitan76.mcpitanlib.api.util.inventory; + +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.inventory.Inventory; +import net.minecraft.inventory.SimpleInventory; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.registry.RegistryWrapper; +import net.minecraft.util.collection.DefaultedList; +import net.pitan76.mcpitanlib.api.entity.CompatContainerUser; +import net.pitan76.mcpitanlib.api.entity.Player; +import net.pitan76.mcpitanlib.api.registry.CompatRegistryLookup; +import net.pitan76.mcpitanlib.api.util.collection.ItemStackList; +import net.pitan76.mcpitanlib.api.util.inventory.args.CanInsertArgs; +import net.pitan76.mcpitanlib.midohra.nbt.NbtList; + +import java.util.List; + +public class CompatInventory extends SimpleInventory { + public CompatInventory(int size) { + super(size); + } + + @Override + public void setStack(int slot, ItemStack stack) { + super.setStack(slot, stack); + } + + /** + * super method of setStack(slot, stack) + */ + public final void superSetStack(int slot, ItemStack stack) { + super.setStack(slot, stack); + } + + /** + * super method of removeStack(slot, amount) + */ + public final ItemStack superRemoveStack(int slot, int amount) { + return super.removeStack(slot, amount); + } + + @Override + public ItemStack removeStack(int slot, int amount) { + return callRemoveStack(slot, amount); + } + + public ItemStack callRemoveStack(int slot, int amount) { + return super.removeStack(slot, amount); + } + + @Override + public ItemStack removeStack(int slot) { + return super.removeStack(slot); + } + + @Override + public ItemStack removeItem(Item item, int count) { + return super.removeItem(item, count); + } + + @Deprecated + @Override + public void onOpen(PlayerEntity player) { + onOpen(new Player(player)); + } + + @Deprecated + @Override + public void onClose(PlayerEntity player) { + onClose(new Player(player)); + } + + @Deprecated + @Override + public net.minecraft.nbt.NbtList toNbtList(RegistryWrapper.WrapperLookup registries) { + return toNbtList(new CompatRegistryLookup(registries)).toMinecraft(); + } + + @Deprecated + @Override + public void readNbtList(net.minecraft.nbt.NbtList list, RegistryWrapper.WrapperLookup registries) { + readNbtList(NbtList.of(list), new CompatRegistryLookup(registries)); + } + + @Deprecated + @Override + public boolean canPlayerUse(PlayerEntity player) { + return canPlayerUse(new Player(player)); + } + + @Deprecated + @Override + public boolean canInsert(ItemStack stack) { + return canInsert(new CanInsertArgs(stack)); + } + + public void onOpen(Player player) { + this.onOpen(new CompatContainerUser(player.getEntity())); + } + + public void onClose(Player player) { + this.onClose(new CompatContainerUser(player.getEntity())); + } + + public void onOpen(CompatContainerUser user) { + super.onOpen(user.getRaw()); + } + + public void onClose(CompatContainerUser user) { + super.onClose(user.getRaw()); + } + + public NbtList toNbtList(CompatRegistryLookup registries) { + return NbtList.of(super.toNbtList(registries.getRegistryLookup())); + } + + public void readNbtList(NbtList list, CompatRegistryLookup registries) { + super.readNbtList(list.toMinecraft(), registries.getRegistryLookup()); + } + + public boolean canPlayerUse(Player player) { + return true; + } + + public boolean canInsert(CanInsertArgs args) { + return super.canInsert(args.getMcStack()); + } + + @Deprecated + @Override + public List clearToList() { + return callClearToList(); + } + + public List callClearToList() { + return super.clearToList(); + } + + @Deprecated + @Override + public DefaultedList getHeldStacks() { + return callGetHeldStacks(); + } + + public DefaultedList callGetHeldStacks() { + return super.getHeldStacks(); + } + + public ItemStackList callGetHeldStacksAsItemStackList() { + return ItemStackList.of(callGetHeldStacks()); + } + + @Deprecated + @Override + public ItemStack getStack(int slot) { + return callGetStack(slot); + } + + public ItemStack callGetStack(int slot) { + return super.getStack(slot); + } + + @Deprecated + @Override + public int size() { + return getSize(); + } + + public int getSize() { + return super.size(); + } + + @Deprecated + @Override + public boolean isEmpty() { + return callIsEmpty(); + } + + public boolean callIsEmpty() { + return super.isEmpty(); + } + + @Deprecated + @Override + public boolean canTransferTo(Inventory hopperInventory, int slot, ItemStack stack) { + return callCanTransferTo(hopperInventory, slot, stack); + } + + public boolean callCanTransferTo(Inventory hopperInventory, int slot, ItemStack stack) { + return super.canTransferTo(hopperInventory, slot, stack); + } + + @Deprecated + @Override + public ItemStack addStack(ItemStack stack) { + return callAddStack(stack); + } + + public ItemStack callAddStack(ItemStack stack) { + return super.addStack(stack); + } + + @Deprecated + @Override + public int getMaxCountPerStack() { + return callGetMaxCountPerStack(); + } + + public int callGetMaxCountPerStack() { + return super.getMaxCountPerStack(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/inventory/CompatPlayerInventory.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/inventory/CompatPlayerInventory.java new file mode 100644 index 000000000..9f9ab0730 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/inventory/CompatPlayerInventory.java @@ -0,0 +1,42 @@ +package net.pitan76.mcpitanlib.api.util.inventory; + +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.item.ItemStack; +import net.pitan76.mcpitanlib.api.entity.Player; + +public class CompatPlayerInventory { + public PlayerInventory inv; + + public CompatPlayerInventory(PlayerInventory inv) { + this.inv = inv; + } + + public Player getPlayer() { + return PlayerInventoryUtil.getPlayer(inv); + } + + public int getSelectedSlot() { + return PlayerInventoryUtil.getSelectedSlot(inv); + } + + public void setSelectedSlot(int slot) { + PlayerInventoryUtil.setSelectedSlot(inv, slot); + } + + public void dropAllItems() { + PlayerInventoryUtil.dropAllItems(inv); + } + + public void offerOrDrop(ItemStack stack) { + inv.offerOrDrop(stack); + } + + public void offerOrDrop(net.pitan76.mcpitanlib.midohra.item.ItemStack stack) { + offerOrDrop(stack.toMinecraft()); + } + + public PlayerInventory getRaw() { + return inv; + } +} + diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/inventory/ContainerInventory.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/inventory/ContainerInventory.java new file mode 100644 index 000000000..b4be9a037 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/inventory/ContainerInventory.java @@ -0,0 +1,17 @@ +package net.pitan76.mcpitanlib.api.util.inventory; + +import net.minecraft.screen.ScreenHandler; + +public class ContainerInventory extends CompatInventory { + + public final T screenHandler; + + public ContainerInventory(T screenHandler, int size) { + super(size); + this.screenHandler = screenHandler; + } + + public T getScreenHandler() { + return screenHandler; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/inventory/ICompatInventory.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/inventory/ICompatInventory.java new file mode 100644 index 000000000..b33afd6be --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/inventory/ICompatInventory.java @@ -0,0 +1,60 @@ +package net.pitan76.mcpitanlib.api.util.inventory; + +import net.minecraft.inventory.Inventory; +import net.minecraft.item.ItemStack; +import net.pitan76.mcpitanlib.api.entity.Player; + +public interface ICompatInventory extends Inventory { + default void callSetStack(int slot, ItemStack stack) { + setStack(slot, stack); + } + + default ItemStack callGetStack(int slot) { + return getStack(slot); + } + + default int callSize() { + return size(); + } + + default boolean callIsEmpty() { + return isEmpty(); + } + + default ItemStack callRemoveStack(int slot, int amount) { + return removeStack(slot, amount); + } + + default ItemStack callRemoveStack(int slot) { + return removeStack(slot); + } + + default void callClear() { + clear(); + } + + default void callMarkDirty() { + markDirty(); + } + + default boolean callCanPlayerUse(net.minecraft.entity.player.PlayerEntity player) { + return canPlayerUse(player); + } + + default boolean canPlayerUse(Player player) { + return canPlayerUse(player.getEntity()); + } + + + default void callSetStack(int slot, net.pitan76.mcpitanlib.midohra.item.ItemStack stack) { + setStack(slot, stack.toMinecraft()); + } + + default net.pitan76.mcpitanlib.midohra.item.ItemStack callGetStackAsMidohra(int slot) { + return net.pitan76.mcpitanlib.midohra.item.ItemStack.of(getStack(slot)); + } + + default int callGetMaxCountPerStack() { + return getMaxCountPerStack(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/inventory/PlayerInventoryUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/inventory/PlayerInventoryUtil.java new file mode 100644 index 000000000..e4d3c32fa --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/inventory/PlayerInventoryUtil.java @@ -0,0 +1,40 @@ +package net.pitan76.mcpitanlib.api.util.inventory; + +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.util.collection.DefaultedList; +import net.pitan76.mcpitanlib.api.entity.Player; + +public class PlayerInventoryUtil { + public static Player getPlayer(PlayerInventory playerInventory) { + return new Player(playerInventory.player); + } + + public static int getSelectedSlot(PlayerInventory playerInventory) { + return playerInventory.selectedSlot; + } + + public static void setSelectedSlot(PlayerInventory playerInventory, int slot) { + playerInventory.selectedSlot = slot; + } + + public static void dropAllItems(PlayerInventory inv) { + inv.dropAll(); + } + + public static DefaultedList getMain(PlayerInventory inv) { + return inv.main; + } + + public static DefaultedList getArmor(PlayerInventory inv) { + return inv.armor; + } + + public static DefaultedList getOffHand(PlayerInventory inv) { + return inv.offHand; + } + + public static ItemStack getMainHandStack(PlayerInventory inv) { + return inv.getMainHandStack(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/inventory/args/CanInsertArgs.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/inventory/args/CanInsertArgs.java new file mode 100644 index 000000000..aeb15f5e9 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/inventory/args/CanInsertArgs.java @@ -0,0 +1,23 @@ +package net.pitan76.mcpitanlib.api.util.inventory.args; + +import net.pitan76.mcpitanlib.midohra.item.ItemStack; + +public class CanInsertArgs { + public ItemStack stack; + + public CanInsertArgs(ItemStack stack) { + this.stack = stack; + } + + public CanInsertArgs(net.minecraft.item.ItemStack stack) { + this(ItemStack.of(stack)); + } + + public ItemStack getStack() { + return stack; + } + + public net.minecraft.item.ItemStack getMcStack() { + return stack.toMinecraft(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/item/FuelUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/item/FuelUtil.java new file mode 100644 index 000000000..4024ce047 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/item/FuelUtil.java @@ -0,0 +1,16 @@ +package net.pitan76.mcpitanlib.api.util.item; + +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.core.registry.FuelRegistry; + +public class FuelUtil { + + public static int getTime(World world, ItemStack stack) { + return FuelRegistry.get(world, stack); + } + + public static boolean isFuel(World world, ItemStack stack) { + return FuelRegistry.isFuel(world, stack); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/item/ItemGroupUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/item/ItemGroupUtil.java new file mode 100644 index 000000000..44138ad5e --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/item/ItemGroupUtil.java @@ -0,0 +1,40 @@ +package net.pitan76.mcpitanlib.api.util.item; + +import net.minecraft.item.ItemGroup; +import net.minecraft.registry.Registries; +import net.minecraft.util.Identifier; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; + +public class ItemGroupUtil { + public static Identifier toID(ItemGroup itemGroup) { + return Registries.ITEM_GROUP.getId(itemGroup); + } + + public static ItemGroup fromId(Identifier identifier) { + return Registries.ITEM_GROUP.get(identifier); + } + + public static boolean isExist(Identifier identifier) { + return Registries.ITEM_GROUP.containsId(identifier); + } + + public static CompatIdentifier toCompatID(ItemGroup itemGroup) { + return CompatIdentifier.fromMinecraft(toID(itemGroup)); + } + + public static ItemGroup fromId(CompatIdentifier identifier) { + return fromId(identifier.toMinecraft()); + } + + public static boolean isExist(CompatIdentifier identifier) { + return isExist(identifier.toMinecraft()); + } + + public static int getRawId(ItemGroup itemGroup) { + return Registries.ITEM_GROUP.getRawId(itemGroup); + } + + public static ItemGroup fromIndex(int index) { + return Registries.ITEM_GROUP.get(index); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/item/ItemUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/item/ItemUtil.java new file mode 100644 index 000000000..f2522401e --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/item/ItemUtil.java @@ -0,0 +1,263 @@ +package net.pitan76.mcpitanlib.api.util.item; + +import net.minecraft.block.Block; +import net.minecraft.item.BlockItem; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.pitan76.mcpitanlib.api.item.v2.CompatibleItemSettings; +import net.pitan76.mcpitanlib.api.tag.TagKey; +import net.pitan76.mcpitanlib.api.text.TextComponent; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.api.util.ItemStackUtil; + +import java.util.ArrayList; +import java.util.List; + +@SuppressWarnings("deprecation") +public class ItemUtil { + + /** + * Check if the item is equal. + * @param item Item to compare. + * @param item2 Item to compare. + * @return If the item is equal. + */ + public static boolean isEqual(Item item, Item item2) { + return net.pitan76.mcpitanlib.api.util.ItemUtil.isEqual(item, item2); + } + + /** + * Get item from CompatIdentifier. + * @param id CompatIdentifier of the item. + * @return Item of the CompatIdentifier. + */ + public static Item fromId(CompatIdentifier id) { + return net.pitan76.mcpitanlib.api.util.ItemUtil.fromId(id); + } + + public static Item fromId(String id) { + return fromId(CompatIdentifier.of(id)); + } + + public static Item fromId(String namespace, String path) { + return fromId(CompatIdentifier.of(namespace, path)); + } + + /** + * Get CompatIdentifier from Item. + * @param item Item to get CompatIdentifier. + * @return CompatIdentifier of the Item. + */ + public static CompatIdentifier toId(Item item) { + return net.pitan76.mcpitanlib.api.util.ItemUtil.toCompatID(item); + } + + public static String toIdAsString(Item item) { + return toId(item).toString(); + } + + /** + * Check if the item exist. + * @param id CompatIdentifier of the item. + * @return If the item exist. + */ + public static boolean isExist(CompatIdentifier id) { + return net.pitan76.mcpitanlib.api.util.ItemUtil.isExist(id); + } + + public static boolean isExist(String id) { + return isExist(CompatIdentifier.of(id)); + } + + public static boolean isExist(String namespace, String path) { + return isExist(CompatIdentifier.of(namespace, path)); + } + + public static boolean isMinecraftItem(Item item) { + return CompatIdentifier.isMinecraftNamespace(toId(item)); + } + + /** + * Create a new BlockItem. + * @param block Block to create BlockItem. + * @param settings CompatItemSettings of the BlockItem. + * @return The new BlockItem. + */ + public static BlockItem create(Block block, CompatibleItemSettings settings) { + if (!settings.changedTranslationKey) + settings.useBlockPrefixedTranslationKey(); + + return net.pitan76.mcpitanlib.api.util.ItemUtil.ofBlock(block, settings); + } + + /** + * Create a new Item. + * @param settings CompatItemSettings of the Item. + * @return The new Item. + */ + public static Item create(CompatibleItemSettings settings) { + return net.pitan76.mcpitanlib.api.util.ItemUtil.of(settings); + } + + /** + * Get all items. + * @return List of all items. + */ + public static List getItems() { + return net.pitan76.mcpitanlib.api.util.ItemUtil.getAllItems(); + } + + /** + * Get items in the tag. + * @param tagKey TagKey of the items. + * @return List of items in the tag. + */ + public static List getInTag(TagKey tagKey) { + return net.pitan76.mcpitanlib.api.util.ItemUtil.getItems(tagKey); + } + + /** + * Get items in the tag. + * @param id CompatIdentifier of the tag. + * @return List of items in the tag. + */ + public static List getInTag(CompatIdentifier id) { + return net.pitan76.mcpitanlib.api.util.ItemUtil.getItems(id); + } + + public static List getInTag(String id) { + return getInTag(CompatIdentifier.of(id)); + } + + public static List getInTag(String namespace, String path) { + return getInTag(CompatIdentifier.of(namespace, path)); + } + + /** + * Check if the item is in the tag. + * @param item Item to check. + * @param tagKey TagKey of the tag. + * @return If the item is in the tag. + */ + public static boolean isInTag(Item item, TagKey tagKey) { + return net.pitan76.mcpitanlib.api.util.ItemUtil.isIn(item, tagKey); + } + + /** + * Check if the item is in the tag. + * @param item Item to check. + * @param id CompatIdentifier of the tag. + * @return If the item is in the tag. + */ + public static boolean isInTag(Item item, CompatIdentifier id) { + return net.pitan76.mcpitanlib.api.util.ItemUtil.isItemInTag(item, id); + } + + public static boolean isInTag(Item item, String id) { + return isInTag(item, CompatIdentifier.of(id)); + } + + public static boolean isInTag(Item item, String namespace, String path) { + return isInTag(item, CompatIdentifier.of(namespace, path)); + } + + /** + * Get raw id of the item. + * @param item Item to get raw id. + * @return Raw id of the item. + */ + public static int toRawId(Item item) { + return net.pitan76.mcpitanlib.api.util.ItemUtil.getRawId(item); + } + + /** + * Get item from raw id. + * @param rawId Raw id of the item. + * @return Item from raw id. + */ + public static Item fromRawId(int rawId) { + return net.pitan76.mcpitanlib.api.util.ItemUtil.fromIndex(rawId); + } + + /** + * Get items by namespace. + * @param namespace Namespace of the items. + * @return List of items by namespace. + */ + public static List getItemsByNamespace(String namespace) { + List items = new ArrayList<>(); + + for (Item item : getItems()) { + if (toId(item).getNamespace().equals(namespace)) + items.add(item); + } + + return items; + } + + /** + * Get number of all items. + * @return Number of all items. + */ + public static int getNumberOfItems() { + return getItems().size(); + } + + /** + * Get item from stack. + * @param stack ItemStack to get item. + * @return Item of the stack. + */ + public static Item of(ItemStack stack) { + return stack.getItem(); + } + + /** + * Check if the item is of the item. + * @param stack ItemStack to check. + * @param item Item to check. + * @return If the item is of the item. + */ + public static boolean isOf(ItemStack stack, Item item) { + return net.pitan76.mcpitanlib.api.util.ItemUtil.isOf(stack, item); + } + + /** + * Get name of the item. + * @param item Item + * @return Name of the item. + */ + public static String getNameAsString(Item item) { + return item.getName().getString(); + } + + /** + * Get name of the item. + * @param item Item + * @return Name of the item. + */ + public static TextComponent getName(Item item) { + return new TextComponent(item.getName()); + } + + /** + * Get translation key of the item. + * @param item Item + * @return Translation key of the item. + */ + public static String getTranslationKey(Item item) { + return item.getTranslationKey(); + } + + public static boolean hasRecipeRemainder(Item item) { + return !ItemStackUtil.isEmpty(getRecipeRemainderStack(item)); + } + + public static Item getRecipeRemainder(Item item) { + return item.getRecipeRemainder(); + } + + public static ItemStack getRecipeRemainderStack(Item item) { + return ItemStackUtil.create(getRecipeRemainder(item)); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/math/BlockRotations.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/math/BlockRotations.java new file mode 100644 index 000000000..6f19c06bd --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/math/BlockRotations.java @@ -0,0 +1,19 @@ +package net.pitan76.mcpitanlib.api.util.math; + +import net.minecraft.util.BlockRotation; +import net.pitan76.mcpitanlib.api.util.math.random.CompatRandom; + +public class BlockRotations { + public static BlockRotation NONE = BlockRotation.NONE; + public static BlockRotation CLOCKWISE_90 = BlockRotation.CLOCKWISE_90; + public static BlockRotation CLOCKWISE_180 = BlockRotation.CLOCKWISE_180; + public static BlockRotation COUNTERCLOCKWISE_90 = BlockRotation.COUNTERCLOCKWISE_90; + + public static BlockRotation rotate(BlockRotation rotation, BlockRotation rotation2) { + return rotation.rotate(rotation2); + } + + public static BlockRotation random(CompatRandom random) { + return BlockRotation.random(random.getMcRandom()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/math/BoxUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/math/BoxUtil.java new file mode 100644 index 000000000..8bf031508 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/math/BoxUtil.java @@ -0,0 +1,54 @@ +package net.pitan76.mcpitanlib.api.util.math; + +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Box; + +public class BoxUtil { + public static Box createBox(double x1, double y1, double z1, double x2, double y2, double z2) { + return new Box(x1, y1, z1, x2, y2, z2); + } + + public static Box createBox(double x, double y, double z, double size) { + return new Box(x, y, z, x + size, y + size, z + size); + } + + public static Box createBox(double size) { + return new Box(0, 0, 0, size, size, size); + } + + public static Box createBox(double x1, double y1, double z1, double x2, double y2, double z2, double size) { + return new Box(x1, y1, z1, x2 + size, y2 + size, z2 + size); + } + + public static Box createBox(BlockPos pos) { + return new Box(pos); + } + + public static Box createBox(BlockPos pos1, BlockPos pos2) { + return new Box(pos1.toCenterPos(), pos2.toCenterPos()); + } + + public static Box createBox(BlockPos pos, int size) { + return createBox(pos, pos.add(size, size, size)); + } + + public static Box createBox(BlockPos pos, int sizeX, int sizeY, int sizeZ) { + return createBox(pos, pos.add(sizeX, sizeY, sizeZ)); + } + + public static Box createBoxCenter(BlockPos pos, int size) { + return createBox(pos.add(-size, -size, -size), pos.add(size, size, size)); + } + + public static Box expand(Box box, double x, double y, double z) { + return new Box(box.minX - x, box.minY - y, box.minZ - z, box.maxX + x, box.maxY + y, box.maxZ + z); + } + + public static Box expand(Box box, double size) { + return expand(box, size, size, size); + } + + public static Box union(Box box1, Box box2) { + return box1.union(box2); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/math/DirectionUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/math/DirectionUtil.java new file mode 100644 index 000000000..08ac22244 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/math/DirectionUtil.java @@ -0,0 +1,34 @@ +package net.pitan76.mcpitanlib.api.util.math; + +import net.minecraft.util.math.Direction; + +public class DirectionUtil { + + public static Direction north() { + return Direction.NORTH; + } + + public static Direction south() { + return Direction.SOUTH; + } + + public static Direction east() { + return Direction.EAST; + } + + public static Direction west() { + return Direction.WEST; + } + + public static Direction up() { + return Direction.UP; + } + + public static Direction down() { + return Direction.DOWN; + } + + public static Direction getOpposite(Direction direction) { + return direction.getOpposite(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/math/PointUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/math/PointUtil.java new file mode 100644 index 000000000..9af8468c3 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/math/PointUtil.java @@ -0,0 +1,15 @@ +package net.pitan76.mcpitanlib.api.util.math; + +public class PointUtil { + public static boolean isInRegion(int x, int y, int width, int height, int pointX, int pointY) { + return pointX >= x && pointX < x + width && pointY >= y && pointY < y + height; + } + + public static boolean isInRegion(int x, int y, int width, int height, double pointX, double pointY) { + return pointX >= x && pointX < x + width && pointY >= y && pointY < y + height; + } + + public static boolean isInRegion2(int x1, int y1, int x2, int y2, int pointX, int pointY) { + return pointX >= x1 && pointX < x2 && pointY >= y1 && pointY < y2; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/math/PosUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/math/PosUtil.java new file mode 100644 index 000000000..2ed72acda --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/math/PosUtil.java @@ -0,0 +1,112 @@ +package net.pitan76.mcpitanlib.api.util.math; + +import net.minecraft.util.math.*; + +public class PosUtil { + public static BlockPos flooredBlockPos(double x, double y, double z) { + return BlockPos.ofFloored(x, y, z); + } + + public static BlockPos flooredBlockPos(Position pos) { + return BlockPos.ofFloored(pos); + } + + public static BlockPos flooredBlockPos(Vec3d pos) { + return BlockPos.ofFloored(pos); + } + + public static net.pitan76.mcpitanlib.midohra.util.math.BlockPos midohraBlockPos(int x, int y, int z) { + return net.pitan76.mcpitanlib.midohra.util.math.BlockPos.of(x, y, z); + } + + public static net.pitan76.mcpitanlib.midohra.util.math.BlockPos flooredMidohraBlockPos(double x, double y, double z) { + int x1 = (int) Math.floor(x); + int y1 = (int) Math.floor(y); + int z1 = (int) Math.floor(z); + return midohraBlockPos(x1, y1, z1); + } + + public static double getSquaredDistance(BlockPos pos1, BlockPos pos2) { + return pos1.getSquaredDistance(pos2); + } + + public static double getSquaredDistance(BlockPos pos1, double x, double y, double z) { + return pos1.getSquaredDistance(x, y, z); + } + + public static Iterable iterate(BlockPos start, BlockPos end) { + return BlockPos.iterate(start, end); + } + + public static BlockPos[] getNeighborPoses(BlockPos pos) { + return new BlockPos[]{pos.north(), pos.south(), pos.east(), pos.west(), pos.up(), pos.down()}; + } + + public static BlockPos up(BlockPos pos) { + return pos.up(); + } + + public static BlockPos down(BlockPos pos) { + return pos.down(); + } + + public static BlockPos north(BlockPos pos) { + return pos.north(); + } + + public static BlockPos south(BlockPos pos) { + return pos.south(); + } + + public static BlockPos east(BlockPos pos) { + return pos.east(); + } + + public static BlockPos west(BlockPos pos) { + return pos.west(); + } + + public static BlockPos add(BlockPos pos, int x, int y, int z) { + return pos.add(x, y, z); + } + + public static BlockPos sub(BlockPos pos, int x, int y, int z) { + return pos.subtract(new Vec3i(x, y, z)); + } + + public static BlockPos mul(BlockPos pos, int n) { + return pos.multiply(n); + } + + public static int x(BlockPos pos) { + return pos.getX(); + } + + public static int y(BlockPos pos) { + return pos.getY(); + } + + public static int z(BlockPos pos) { + return pos.getZ(); + } + + public static BlockPos offset(BlockPos pos, Direction direction) { + return pos.offset(direction); + } + + public static BlockPos offset(BlockPos pos, Direction direction, int n) { + return pos.offset(direction, n); + } + + public static BlockPos offset(BlockPos pos, net.pitan76.mcpitanlib.midohra.util.math.Direction direction) { + return pos.offset(direction.toMinecraft()); + } + + public static BlockPos offset(BlockPos pos, net.pitan76.mcpitanlib.midohra.util.math.Direction direction, int n) { + return pos.offset(direction.toMinecraft(), n); + } + + public static BlockPos toImmutable(BlockPos pos) { + return pos.toImmutable(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/math/Vec3dUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/math/Vec3dUtil.java new file mode 100644 index 000000000..f239b0a40 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/math/Vec3dUtil.java @@ -0,0 +1,69 @@ +package net.pitan76.mcpitanlib.api.util.math; + +import net.minecraft.util.math.Vec3d; + +public class Vec3dUtil { + public static Vec3d create(double x, double y, double z) { + return new Vec3d(x, y, z); + } + + public static Vec3d add(Vec3d a, Vec3d b) { + return a.add(b); + } + + public static Vec3d subtract(Vec3d a, Vec3d b) { + return a.subtract(b); + } + + public static Vec3d multiply(Vec3d a, double b) { + return a.multiply(b); + } + + public static Vec3d divide(Vec3d a, double b) { + return a.multiply(1.0D / b); + } + + public static double dot(Vec3d a, Vec3d b) { + return a.dotProduct(b); + } + + public static Vec3d cross(Vec3d a, Vec3d b) { + return a.crossProduct(b); + } + + public static Vec3d normalize(Vec3d a) { + return a.normalize(); + } + + public static Vec3d rotateX(Vec3d a, float angle) { + return a.rotateX(angle); + } + + public static Vec3d rotateY(Vec3d a, float angle) { + return a.rotateY(angle); + } + + public static Vec3d rotateZ(Vec3d a, float angle) { + return a.rotateZ(angle); + } + + public static Vec3d add(Vec3d a, double x, double y, double z) { + return a.add(x, y, z); + } + + public static Vec3d subtract(Vec3d a, double x, double y, double z) { + return a.subtract(x, y, z); + } + + public static Vec3d multiply(Vec3d a, double x, double y, double z) { + return a.multiply(x, y, z); + } + + public static double distanceTo(Vec3d a, Vec3d b) { + return a.distanceTo(b); + } + + public static Vec3d ofCenter(double x, double y, double z) { + return new Vec3d(x + 0.5, y + 0.5, z + 0.5); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/math/Vec3iUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/math/Vec3iUtil.java new file mode 100644 index 000000000..4def019b0 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/math/Vec3iUtil.java @@ -0,0 +1,33 @@ +package net.pitan76.mcpitanlib.api.util.math; + +import net.minecraft.util.math.Vec3i; + +public class Vec3iUtil { + public static Vec3i create(int x, int y, int z) { + return new Vec3i(x, y, z); + } + + public static Vec3i add(Vec3i a, Vec3i b) { + return a.add(b); + } + + public static Vec3i subtract(Vec3i a, Vec3i b) { + return a.subtract(b); + } + + public static Vec3i multiply(Vec3i a, int b) { + return a.multiply(b); + } + + public static Vec3i cross(Vec3i a, Vec3i b) { + return a.crossProduct(b); + } + + public static Vec3i add(Vec3i a, int x, int y, int z) { + return a.add(x, y, z); + } + + public static Vec3i subtract(Vec3i a, int x, int y, int z) { + return a.add(-x, -y, -z); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/math/random/CompatRandom.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/math/random/CompatRandom.java new file mode 100644 index 000000000..93cd723d5 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/math/random/CompatRandom.java @@ -0,0 +1,140 @@ +package net.pitan76.mcpitanlib.api.util.math.random; + +public class CompatRandom { + private java.util.Random javaRandom; + private net.minecraft.util.math.random.Random mcRandom; + + public CompatRandom(java.util.Random javaRandom) { + this.javaRandom = javaRandom; + } + + public CompatRandom(net.minecraft.util.math.random.Random mcRandom) { + this.mcRandom = mcRandom; + } + + @Deprecated + public CompatRandom() { + this.mcRandom = net.minecraft.util.math.random.Random.create(); + } + + @Deprecated + public CompatRandom(long seed) { + this.mcRandom = net.minecraft.util.math.random.Random.create(seed); + } + + public static CompatRandom of(long seed) { + return new CompatRandom(seed); + } + + public static CompatRandom of() { + return new CompatRandom(); + } + + public void setSeed(long seed) { + if (javaRandom != null) { + javaRandom.setSeed(seed); + } else { + mcRandom.setSeed(seed); + } + } + + public void skip(int count) { + if (javaRandom != null) { + for (int i = 0; i < count; i++) { + javaRandom.nextInt(); + } + } else { + mcRandom.skip(count); + } + } + + public void split() { + if (javaRandom != null) { + javaRandom.nextInt(); + } else { + mcRandom.split(); + } + } + + public int nextInt() { + if (javaRandom != null) { + return javaRandom.nextInt(); + } else { + return mcRandom.nextInt(); + } + } + + public int nextInt(int bound) { + if (javaRandom != null) { + return javaRandom.nextInt(bound); + } else { + return mcRandom.nextInt(bound); + } + } + + public long nextLong() { + if (javaRandom != null) { + return javaRandom.nextLong(); + } else { + return mcRandom.nextLong(); + } + } + + public double nextDouble() { + if (javaRandom != null) { + return javaRandom.nextDouble(); + } else { + return mcRandom.nextDouble(); + } + } + + public double nextGaussian() { + if (javaRandom != null) { + return javaRandom.nextGaussian(); + } else { + return mcRandom.nextGaussian(); + } + } + + public float nextFloat() { + if (javaRandom != null) { + return javaRandom.nextFloat(); + } else { + return mcRandom.nextFloat(); + } + } + + public int nextBetween(int min, int max) { + if (javaRandom != null) { + return min + javaRandom.nextInt(max - min); + } else { + return min + mcRandom.nextInt(max - min); + } + } + + public int nextBetweenExclusive(int min, int max) { + if (javaRandom != null) { + return min + javaRandom.nextInt(max - min - 1); + } else { + return min + mcRandom.nextInt(max - min - 1); + } + } + + public boolean nextBoolean() { + if (javaRandom != null) { + return javaRandom.nextBoolean(); + } else { + return mcRandom.nextBoolean(); + } + } + + @Deprecated + public java.util.Random getJavaRandom() { + return javaRandom; + } + + @Deprecated + public net.minecraft.util.math.random.Random getMcRandom() { + return mcRandom; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/nbt/InvRWUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/nbt/InvRWUtil.java new file mode 100644 index 000000000..65eb6c244 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/nbt/InvRWUtil.java @@ -0,0 +1,26 @@ +package net.pitan76.mcpitanlib.api.util.nbt; + +import net.minecraft.item.ItemStack; +import net.minecraft.util.collection.DefaultedList; +import net.pitan76.mcpitanlib.api.event.nbt.ReadNbtArgs; +import net.pitan76.mcpitanlib.api.event.nbt.WriteNbtArgs; +import net.pitan76.mcpitanlib.api.util.InventoryUtil; +import net.pitan76.mcpitanlib.api.util.collection.ItemStackList; + +public class InvRWUtil { + public static void putInv(WriteNbtArgs args, DefaultedList stacks) { + InventoryUtil.writeNbt(args.getRegistryLookup(), args.getNbt(), stacks); + } + + public static void getInv(ReadNbtArgs args, DefaultedList stacks) { + InventoryUtil.readNbt(args.getRegistryLookup(), args.getNbt(), stacks); + } + + public static void putInv(WriteNbtArgs args, ItemStackList stacks) { + putInv(args, (DefaultedList) stacks); + } + + public static void getInv(ReadNbtArgs args, ItemStackList stacks) { + getInv(args, (DefaultedList) stacks); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/nbt/NbtListUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/nbt/NbtListUtil.java new file mode 100644 index 000000000..076e0c11f --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/nbt/NbtListUtil.java @@ -0,0 +1,91 @@ +package net.pitan76.mcpitanlib.api.util.nbt; + +import net.minecraft.nbt.NbtCompound; +import net.minecraft.nbt.NbtElement; +import net.minecraft.nbt.NbtList; +import net.pitan76.mcpitanlib.api.util.NbtUtil; + +import java.util.Optional; +import java.util.stream.Stream; + +public class NbtListUtil { + public static NbtList create() { + return NbtUtil.createNbtList(); + } + + public static NbtList copy(NbtList list) { + return list.copy(); + } + + public static Stream stream(NbtList list) { + return list.stream(); + } + + public static Optional getStringOptional(NbtList list, int index) { + if (index < 0 || index >= list.size()) + return Optional.empty(); + + return Optional.of(list.getString(index)); + } + + public static NbtElement get(NbtList list, int index) { + return list.get(index); + } + + public static NbtElement getOrDefault(NbtList list, int index, NbtElement defaultValue) { + NbtElement nbt = get(list, index); + return nbt == null ? defaultValue : nbt; + } + + public static void set(NbtList list, int index, NbtElement value) { + list.set(index, value); + } + + public static void add(NbtList list, NbtElement value) { + list.add(value); + } + + public static void set(NbtList list, int index, String value) { + set(list, index, NbtUtil.createString(value)); + } + + public static boolean has(NbtList list, NbtElement value) { + return list.contains(value); + } + + public static int size(NbtList list) { + return list.size(); + } + + public static void remove(NbtList list, int index) { + list.remove(index); + } + + public static void clear(NbtList list) { + list.clear(); + } + + public static boolean isEmpty(NbtList list) { + return list.isEmpty(); + } + + public static String getString(NbtList list, int index) { + return getStringOptional(list, index).orElse(""); + } + + public static void setString(NbtList list, int index, String value) { + list.set(index, NbtUtil.createString(value)); + } + + public static void addString(NbtList list, String value) { + list.add(NbtUtil.createString(value)); + } + + public static NbtList getList(NbtList list, int index) { + return list.getList(index); + } + + public static NbtCompound getCompound(NbtList list, int index) { + return list.getCompound(index); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/nbt/NbtRWUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/nbt/NbtRWUtil.java new file mode 100644 index 000000000..4cfd30313 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/nbt/NbtRWUtil.java @@ -0,0 +1,138 @@ +package net.pitan76.mcpitanlib.api.util.nbt; + +import net.minecraft.nbt.NbtCompound; +import net.pitan76.mcpitanlib.api.event.nbt.NbtRWArgs; +import net.pitan76.mcpitanlib.api.event.nbt.ReadNbtArgs; +import net.pitan76.mcpitanlib.api.event.nbt.WriteNbtArgs; +import net.pitan76.mcpitanlib.api.util.NbtUtil; + +public class NbtRWUtil { + + public static void putBoolean(WriteNbtArgs args, String key, boolean value) { + NbtUtil.putBoolean(args.getNbt(), key, value); + } + + public static boolean getBoolean(ReadNbtArgs args, String key) { + return NbtUtil.getBoolean(args.getNbt(), key); + } + + public static void putByte(WriteNbtArgs args, String key, byte value) { + NbtUtil.putByte(args.getNbt(), key, value); + } + + public static byte getByte(ReadNbtArgs args, String key) { + return NbtUtil.getByte(args.getNbt(), key); + } + + public static void putInt(WriteNbtArgs args, String key, int value) { + NbtUtil.putInt(args.getNbt(), key, value); + } + + public static int getInt(ReadNbtArgs args, String key) { + return NbtUtil.getInt(args.getNbt(), key); + } + + public static void putLong(WriteNbtArgs args, String key, long value) { + NbtUtil.putLong(args.getNbt(), key, value); + } + + public static long getLong(ReadNbtArgs args, String key) { + return NbtUtil.getLong(args.getNbt(), key); + } + + public static void putShort(WriteNbtArgs args, String key, short value) { + NbtUtil.putShort(args.getNbt(), key, value); + } + + public static short getShort(ReadNbtArgs args, String key) { + return NbtUtil.getShort(args.getNbt(), key); + } + + public static void putFloat(WriteNbtArgs args, String key, float value) { + NbtUtil.putFloat(args.getNbt(), key, value); + } + + public static float getFloat(ReadNbtArgs args, String key) { + return NbtUtil.getFloat(args.getNbt(), key); + } + + public static void putDouble(WriteNbtArgs args, String key, double value) { + NbtUtil.putDouble(args.getNbt(), key, value); + } + + public static double getDouble(ReadNbtArgs args, String key) { + return NbtUtil.getDouble(args.getNbt(), key); + } + public static void putString(WriteNbtArgs args, String key, String value) { + NbtUtil.putString(args.getNbt(), key, value); + } + + public static String getString(ReadNbtArgs args, String key) { + return NbtUtil.getString(args.getNbt(), key); + } + + public static void putIntArray(WriteNbtArgs args, String key, int[] value) { + args.getNbt().putIntArray(key, value); + } + + public static int[] getIntArray(ReadNbtArgs args, String key) { + return args.nbt.getIntArray(key); + } + + public static boolean getBooleanOrDefault(ReadNbtArgs args, String key, boolean defaultValue) { + return NbtUtil.getBooleanOrDefault(args.getNbt(), key, defaultValue); + } + + public static byte getByteOrDefault(ReadNbtArgs args, String key, byte defaultValue) { + return NbtUtil.getByteOrDefault(args.getNbt(), key, defaultValue); + } + + public static int getIntOrDefault(ReadNbtArgs args, String key, int defaultValue) { + return NbtUtil.getIntOrDefault(args.getNbt(), key, defaultValue); + } + + public static long getLongOrDefault(ReadNbtArgs args, String key, long defaultValue) { + return NbtUtil.getLongOrDefault(args.getNbt(), key, defaultValue); + } + + public static short getShortOrDefault(ReadNbtArgs args, String key, short defaultValue) { + return NbtUtil.getShortOrDefault(args.getNbt(), key, defaultValue); + } + + public static float getFloatOrDefault(ReadNbtArgs args, String key, float defaultValue) { + return NbtUtil.getFloatOrDefault(args.getNbt(), key, defaultValue); + } + + public static double getDoubleOrDefault(ReadNbtArgs args, String key, double defaultValue) { + return NbtUtil.getDoubleOrDefault(args.getNbt(), key, defaultValue); + } + + public static String getStringOrDefault(ReadNbtArgs args, String key, String defaultValue) { + return NbtUtil.getStringOrDefault(args.getNbt(), key, defaultValue); + } + + public static int[] getIntArrayOrDefault(ReadNbtArgs args, String key, int[] defaultValue) { + if (!NbtUtil.has(args.nbt, key)) return defaultValue; + return args.nbt.getIntArray(key); + } + + public static boolean isEmpty(NbtRWArgs args) { + return args.nbt.isEmpty(); + } + + public static void put(WriteNbtArgs args, String key, NbtRWArgs other) { + putCompound(args, key, other.nbt); + } + + public static NbtRWArgs get(ReadNbtArgs args, String key) { + return new NbtRWArgs(getCompound(args, key)); + } + + public static void putCompound(WriteNbtArgs args, String key, NbtCompound other) { + NbtUtil.put(args.nbt, key, other); + } + + public static NbtCompound getCompound(ReadNbtArgs args, String key) { + return NbtUtil.get(args.nbt, key); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/nbt/v2/NbtRWUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/nbt/v2/NbtRWUtil.java new file mode 100644 index 000000000..e57b9b23a --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/nbt/v2/NbtRWUtil.java @@ -0,0 +1,118 @@ +package net.pitan76.mcpitanlib.api.util.nbt.v2; + +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NbtCompound; +import net.minecraft.util.math.Vec3d; +import net.minecraft.util.math.Vec3i; +import net.pitan76.mcpitanlib.api.event.nbt.ReadNbtArgs; +import net.pitan76.mcpitanlib.api.event.nbt.WriteNbtArgs; +import net.pitan76.mcpitanlib.api.registry.CompatRegistryLookup; +import net.pitan76.mcpitanlib.api.util.NbtUtil; +import net.pitan76.mcpitanlib.api.util.collection.ItemStackList; +import net.pitan76.mcpitanlib.api.util.math.PosUtil; +import net.pitan76.mcpitanlib.api.util.math.Vec3dUtil; +import net.pitan76.mcpitanlib.api.util.math.Vec3iUtil; +import net.pitan76.mcpitanlib.api.util.nbt.InvRWUtil; +import net.pitan76.mcpitanlib.midohra.util.math.BlockPos; + +import java.util.Optional; + +public class NbtRWUtil extends net.pitan76.mcpitanlib.api.util.nbt.NbtRWUtil { + public static void putInv(WriteNbtArgs args, ItemStackList stacks) { + InvRWUtil.putInv(args, stacks); + } + + public static void getInv(ReadNbtArgs args, ItemStackList stacks) { + InvRWUtil.getInv(args, stacks); + } + + public static WriteNbtArgs create(CompatRegistryLookup registryLookup) { + return new WriteNbtArgs(NbtUtil.create(), registryLookup); + } + + public static WriteNbtArgs create() { + return create(null); + } + + public static void put(WriteNbtArgs parent, WriteNbtArgs child, String key) { + NbtUtil.put(parent.nbt, key, child.nbt); + } + + public static WriteNbtArgs putWithCreate(WriteNbtArgs parent, String key) { + NbtCompound nbt = NbtUtil.create(); + NbtUtil.put(parent.nbt, key, nbt); + + return new WriteNbtArgs(nbt, parent.registryLookup); + } + + public static ReadNbtArgs get(ReadNbtArgs parent, String key) { + NbtCompound nbt = NbtUtil.get(parent.nbt, key); + return new ReadNbtArgs(nbt, parent.registryLookup); + } + + public static ReadNbtArgs getOrDefault(ReadNbtArgs parent, String key, ReadNbtArgs defaultValue) { + return NbtUtil.has(parent.nbt, key) ? get(parent, key) : defaultValue; + } + + public static void putPos3i(WriteNbtArgs args, String key, int x, int y, int z) { + WriteNbtArgs args2 = putWithCreate(args, key); + putInt(args2, "x", x); + putInt(args2, "y", y); + putInt(args2, "z", z); + } + + public static void putPos3d(WriteNbtArgs args, String key, double x, double y, double z) { + WriteNbtArgs args2 = putWithCreate(args, key); + putDouble(args2, "x", x); + putDouble(args2, "y", y); + putDouble(args2, "z", z); + } + + public static Vec3i getPos3i(ReadNbtArgs args, String key) { + ReadNbtArgs args2 = get(args, key); + int x = getInt(args2, "x"); + int y = getInt(args2, "y"); + int z = getInt(args2, "z"); + return Vec3iUtil.create(x, y, z); + } + + public static Vec3d getPos3d(ReadNbtArgs args, String key) { + ReadNbtArgs args2 = get(args, key); + double x = getDouble(args2, "x"); + double y = getDouble(args2, "y"); + double z = getDouble(args2, "z"); + return Vec3dUtil.create(x, y, z); + } + + public static void putBlockPos(WriteNbtArgs args, String key, BlockPos pos) { + putPos3i(args, key, pos.getX(), pos.getY(), pos.getZ()); + } + + public static BlockPos getBlockPos(ReadNbtArgs args, String key) { + ReadNbtArgs args2 = get(args, key); + int x = getInt(args2, "x"); + int y = getInt(args2, "y"); + int z = getInt(args2, "z"); + return BlockPos.of(x, y, z); + } + + public static void putBlockPos(WriteNbtArgs args, String key, net.minecraft.util.math.BlockPos pos) { + putPos3i(args, key, PosUtil.x(pos), PosUtil.y(pos), PosUtil.z(pos)); + } + + public static net.minecraft.util.math.BlockPos getBlockPosV(ReadNbtArgs args, String key) { + ReadNbtArgs args2 = get(args, key); + int x = getInt(args2, "x"); + int y = getInt(args2, "y"); + int z = getInt(args2, "z"); + return PosUtil.flooredBlockPos(x, y, z); + } + + public static void putItemStack(WriteNbtArgs args, String key, ItemStack stack) { + NbtUtil.putItemStack(args.getNbt(), key, stack, args.getRegistryLookup()); + } + + public static Optional getItemStack(ReadNbtArgs args, String key) { + return NbtUtil.getItemStack(args.getNbt(), key, args.getRegistryLookup()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/particle/CompatParticleType.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/particle/CompatParticleType.java new file mode 100644 index 000000000..758900a07 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/particle/CompatParticleType.java @@ -0,0 +1,34 @@ +package net.pitan76.mcpitanlib.api.util.particle; + +import net.minecraft.particle.ParticleType; +import net.minecraft.registry.Registries; +import net.minecraft.util.Identifier; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; + +public class CompatParticleType { + private final ParticleType particleType; + + public CompatParticleType(ParticleType particleType) { + this.particleType = particleType; + } + + public static CompatParticleType of(ParticleType particleType) { + return new CompatParticleType(particleType); + } + + public ParticleType getRaw() { + return particleType; + } + + public boolean shouldAlwaysSpawn() { + return particleType.shouldAlwaysSpawn(); + } + + public Identifier getId() { + return Registries.PARTICLE_TYPE.getId(particleType); + } + + public CompatIdentifier getCompatId() { + return CompatIdentifier.fromMinecraft(getId()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/particle/CompatParticleTypes.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/particle/CompatParticleTypes.java new file mode 100644 index 000000000..e19059ab7 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/particle/CompatParticleTypes.java @@ -0,0 +1,121 @@ +package net.pitan76.mcpitanlib.api.util.particle; + +import net.minecraft.particle.*; + +public class CompatParticleTypes { + public static final CompatParticleType ANGRY_VILLAGER = new CompatParticleType(ParticleTypes.ANGRY_VILLAGER); + public static final CompatParticleType BLOCK = new CompatParticleType(ParticleTypes.BLOCK); + public static final CompatParticleType BLOCK_MARKER = new CompatParticleType(ParticleTypes.BLOCK_MARKER); + public static final CompatParticleType BUBBLE = new CompatParticleType(ParticleTypes.BUBBLE); + public static final CompatParticleType CLOUD = new CompatParticleType(ParticleTypes.CLOUD); + public static final CompatParticleType COPPER_FIRE_FLAME = new CompatParticleType(ParticleTypes.FLAME); + public static final CompatParticleType CRIT = new CompatParticleType(ParticleTypes.CRIT); + public static final CompatParticleType DAMAGE_INDICATOR = new CompatParticleType(ParticleTypes.DAMAGE_INDICATOR); + public static final CompatParticleType DRAGON_BREATH = new CompatParticleType(ParticleTypes.DRAGON_BREATH); + public static final CompatParticleType DRIPPING_LAVA = new CompatParticleType(ParticleTypes.DRIPPING_LAVA); + public static final CompatParticleType FALLING_LAVA = new CompatParticleType(ParticleTypes.FALLING_LAVA); + public static final CompatParticleType LANDING_LAVA = new CompatParticleType(ParticleTypes.LANDING_LAVA); + public static final CompatParticleType DRIPPING_WATER = new CompatParticleType(ParticleTypes.DRIPPING_WATER); + public static final CompatParticleType FALLING_WATER = new CompatParticleType(ParticleTypes.FALLING_WATER); + public static final CompatParticleType DUST = new CompatParticleType(ParticleTypes.DUST); + public static final CompatParticleType DUST_COLOR_TRANSITION = new CompatParticleType(ParticleTypes.DUST_COLOR_TRANSITION); + public static final CompatParticleType EFFECT = new CompatParticleType(ParticleTypes.EFFECT); + public static final CompatParticleType ELDER_GUARDIAN = new CompatParticleType(ParticleTypes.ELDER_GUARDIAN); + public static final CompatParticleType ENCHANTED_HIT = new CompatParticleType(ParticleTypes.ENCHANTED_HIT); + public static final CompatParticleType ENCHANT = new CompatParticleType(ParticleTypes.ENCHANT); + public static final CompatParticleType END_ROD = new CompatParticleType(ParticleTypes.END_ROD); + public static final CompatParticleType ENTITY_EFFECT = new CompatParticleType(ParticleTypes.ENTITY_EFFECT); + public static final CompatParticleType EXPLOSION_EMITTER = new CompatParticleType(ParticleTypes.EXPLOSION_EMITTER); + public static final CompatParticleType EXPLOSION = new CompatParticleType(ParticleTypes.EXPLOSION); + public static final CompatParticleType GUST = new CompatParticleType(ParticleTypes.GUST); + public static final CompatParticleType SMALL_GUST = new CompatParticleType(ParticleTypes.SMALL_GUST); + public static final CompatParticleType GUST_EMITTER_LARGE = new CompatParticleType(ParticleTypes.GUST_EMITTER_LARGE); + public static final CompatParticleType GUST_EMITTER_SMALL = new CompatParticleType(ParticleTypes.GUST_EMITTER_SMALL); + public static final CompatParticleType SONIC_BOOM = new CompatParticleType(ParticleTypes.SONIC_BOOM); + public static final CompatParticleType FALLING_DUST = new CompatParticleType(ParticleTypes.FALLING_DUST); + public static final CompatParticleType FIREWORK = new CompatParticleType(ParticleTypes.FIREWORK); + public static final CompatParticleType FISHING = new CompatParticleType(ParticleTypes.FISHING); + public static final CompatParticleType FLAME = new CompatParticleType(ParticleTypes.FLAME); + public static final CompatParticleType INFESTED = new CompatParticleType(ParticleTypes.INFESTED); + public static final CompatParticleType CHERRY_LEAVES = new CompatParticleType(ParticleTypes.CHERRY_LEAVES); + public static final CompatParticleType PALE_OAK_LEAVES = new CompatParticleType(ParticleTypes.BLOCK); + public static final CompatParticleType TINTED_LEAVES = new CompatParticleType(ParticleTypes.BLOCK); + public static final CompatParticleType SCULK_SOUL = new CompatParticleType(ParticleTypes.SCULK_SOUL); + public static final CompatParticleType SCULK_CHARGE = new CompatParticleType(ParticleTypes.SCULK_CHARGE); + public static final CompatParticleType SCULK_CHARGE_POP = new CompatParticleType(ParticleTypes.SCULK_CHARGE_POP); + public static final CompatParticleType SOUL_FIRE_FLAME = new CompatParticleType(ParticleTypes.SOUL_FIRE_FLAME); + public static final CompatParticleType SOUL = new CompatParticleType(ParticleTypes.SOUL); + public static final CompatParticleType FLASH = new CompatParticleType(ParticleTypes.FLASH); + public static final CompatParticleType HAPPY_VILLAGER = new CompatParticleType(ParticleTypes.HAPPY_VILLAGER); + public static final CompatParticleType COMPOSTER = new CompatParticleType(ParticleTypes.COMPOSTER); + public static final CompatParticleType HEART = new CompatParticleType(ParticleTypes.HEART); + public static final CompatParticleType INSTANT_EFFECT = new CompatParticleType(ParticleTypes.INSTANT_EFFECT); + public static final CompatParticleType ITEM = new CompatParticleType(ParticleTypes.ITEM); + public static final CompatParticleType VIBRATION = new CompatParticleType(ParticleTypes.VIBRATION); + public static final CompatParticleType TRAIL = new CompatParticleType(ParticleTypes.EFFECT); + public static final CompatParticleType ITEM_SLIME = new CompatParticleType(ParticleTypes.ITEM_SLIME); + public static final CompatParticleType ITEM_COBWEB = new CompatParticleType(ParticleTypes.ITEM_COBWEB); + public static final CompatParticleType ITEM_SNOWBALL = new CompatParticleType(ParticleTypes.ITEM_SNOWBALL); + public static final CompatParticleType LARGE_SMOKE = new CompatParticleType(ParticleTypes.LARGE_SMOKE); + public static final CompatParticleType LAVA = new CompatParticleType(ParticleTypes.LAVA); + public static final CompatParticleType MYCELIUM = new CompatParticleType(ParticleTypes.MYCELIUM); + public static final CompatParticleType NOTE = new CompatParticleType(ParticleTypes.NOTE); + public static final CompatParticleType POOF = new CompatParticleType(ParticleTypes.POOF); + public static final CompatParticleType PORTAL = new CompatParticleType(ParticleTypes.PORTAL); + public static final CompatParticleType RAIN = new CompatParticleType(ParticleTypes.RAIN); + public static final CompatParticleType SMOKE = new CompatParticleType(ParticleTypes.SMOKE); + public static final CompatParticleType WHITE_SMOKE = new CompatParticleType(ParticleTypes.WHITE_SMOKE); + public static final CompatParticleType SNEEZE = new CompatParticleType(ParticleTypes.SNEEZE); + public static final CompatParticleType SPIT = new CompatParticleType(ParticleTypes.SPIT); + public static final CompatParticleType SQUID_INK = new CompatParticleType(ParticleTypes.SQUID_INK); + public static final CompatParticleType SWEEP_ATTACK = new CompatParticleType(ParticleTypes.SWEEP_ATTACK); + public static final CompatParticleType TOTEM_OF_UNDYING = new CompatParticleType(ParticleTypes.TOTEM_OF_UNDYING); + public static final CompatParticleType UNDERWATER = new CompatParticleType(ParticleTypes.UNDERWATER); + public static final CompatParticleType SPLASH = new CompatParticleType(ParticleTypes.SPLASH); + public static final CompatParticleType WITCH = new CompatParticleType(ParticleTypes.WITCH); + public static final CompatParticleType BUBBLE_POP = new CompatParticleType(ParticleTypes.BUBBLE_POP); + public static final CompatParticleType CURRENT_DOWN = new CompatParticleType(ParticleTypes.CURRENT_DOWN); + public static final CompatParticleType BUBBLE_COLUMN_UP = new CompatParticleType(ParticleTypes.BUBBLE_COLUMN_UP); + public static final CompatParticleType NAUTILUS = new CompatParticleType(ParticleTypes.NAUTILUS); + public static final CompatParticleType DOLPHIN = new CompatParticleType(ParticleTypes.DOLPHIN); + public static final CompatParticleType CAMPFIRE_COSY_SMOKE = new CompatParticleType(ParticleTypes.CAMPFIRE_COSY_SMOKE); + public static final CompatParticleType CAMPFIRE_SIGNAL_SMOKE = new CompatParticleType(ParticleTypes.CAMPFIRE_SIGNAL_SMOKE); + public static final CompatParticleType DRIPPING_HONEY = new CompatParticleType(ParticleTypes.DRIPPING_HONEY); + public static final CompatParticleType FALLING_HONEY = new CompatParticleType(ParticleTypes.FALLING_HONEY); + public static final CompatParticleType LANDING_HONEY = new CompatParticleType(ParticleTypes.LANDING_HONEY); + public static final CompatParticleType FALLING_NECTAR = new CompatParticleType(ParticleTypes.FALLING_NECTAR); + public static final CompatParticleType FALLING_SPORE_BLOSSOM = new CompatParticleType(ParticleTypes.FALLING_SPORE_BLOSSOM); + public static final CompatParticleType ASH = new CompatParticleType(ParticleTypes.ASH); + public static final CompatParticleType CRIMSON_SPORE = new CompatParticleType(ParticleTypes.CRIMSON_SPORE); + public static final CompatParticleType WARPED_SPORE = new CompatParticleType(ParticleTypes.WARPED_SPORE); + public static final CompatParticleType SPORE_BLOSSOM_AIR = new CompatParticleType(ParticleTypes.SPORE_BLOSSOM_AIR); + public static final CompatParticleType DRIPPING_OBSIDIAN_TEAR = new CompatParticleType(ParticleTypes.DRIPPING_OBSIDIAN_TEAR); + public static final CompatParticleType FALLING_OBSIDIAN_TEAR = new CompatParticleType(ParticleTypes.FALLING_OBSIDIAN_TEAR); + public static final CompatParticleType LANDING_OBSIDIAN_TEAR = new CompatParticleType(ParticleTypes.LANDING_OBSIDIAN_TEAR); + public static final CompatParticleType REVERSE_PORTAL = new CompatParticleType(ParticleTypes.REVERSE_PORTAL); + public static final CompatParticleType WHITE_ASH = new CompatParticleType(ParticleTypes.WHITE_ASH); + public static final CompatParticleType SMALL_FLAME = new CompatParticleType(ParticleTypes.SMALL_FLAME); + public static final CompatParticleType SNOWFLAKE = new CompatParticleType(ParticleTypes.SNOWFLAKE); + public static final CompatParticleType DRIPPING_DRIPSTONE_LAVA = new CompatParticleType(ParticleTypes.DRIPPING_DRIPSTONE_LAVA); + public static final CompatParticleType FALLING_DRIPSTONE_LAVA = new CompatParticleType(ParticleTypes.FALLING_DRIPSTONE_LAVA); + public static final CompatParticleType DRIPPING_DRIPSTONE_WATER = new CompatParticleType(ParticleTypes.DRIPPING_DRIPSTONE_WATER); + public static final CompatParticleType FALLING_DRIPSTONE_WATER = new CompatParticleType(ParticleTypes.FALLING_DRIPSTONE_WATER); + public static final CompatParticleType GLOW_SQUID_INK = new CompatParticleType(ParticleTypes.GLOW_SQUID_INK); + public static final CompatParticleType GLOW = new CompatParticleType(ParticleTypes.GLOW); + public static final CompatParticleType WAX_ON = new CompatParticleType(ParticleTypes.WAX_ON); + public static final CompatParticleType WAX_OFF = new CompatParticleType(ParticleTypes.WAX_OFF); + public static final CompatParticleType ELECTRIC_SPARK = new CompatParticleType(ParticleTypes.ELECTRIC_SPARK); + public static final CompatParticleType SCRAPE = new CompatParticleType(ParticleTypes.SCRAPE); + public static final CompatParticleType SHRIEK = new CompatParticleType(ParticleTypes.SHRIEK); + public static final CompatParticleType EGG_CRACK = new CompatParticleType(ParticleTypes.EGG_CRACK); + public static final CompatParticleType DUST_PLUME = new CompatParticleType(ParticleTypes.DUST_PLUME); + public static final CompatParticleType TRIAL_SPAWNER_DETECTION = new CompatParticleType(ParticleTypes.TRIAL_SPAWNER_DETECTION); + public static final CompatParticleType TRIAL_SPAWNER_DETECTION_OMINOUS = new CompatParticleType(ParticleTypes.TRIAL_SPAWNER_DETECTION_OMINOUS); + public static final CompatParticleType VAULT_CONNECTION = new CompatParticleType(ParticleTypes.VAULT_CONNECTION); + public static final CompatParticleType DUST_PILLAR = new CompatParticleType(ParticleTypes.DUST_PILLAR); + public static final CompatParticleType OMINOUS_SPAWNING = new CompatParticleType(ParticleTypes.OMINOUS_SPAWNING); + public static final CompatParticleType RAID_OMEN = new CompatParticleType(ParticleTypes.RAID_OMEN); + public static final CompatParticleType TRIAL_OMEN = new CompatParticleType(ParticleTypes.TRIAL_OMEN); + public static final CompatParticleType BLOCK_CRUMBLE = new CompatParticleType(ParticleTypes.BLOCK); + public static final CompatParticleType FIREFLY = new CompatParticleType(ParticleTypes.NOTE); +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/particle/effect/ItemStackParticleEffectUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/particle/effect/ItemStackParticleEffectUtil.java new file mode 100644 index 000000000..9eab41f4d --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/particle/effect/ItemStackParticleEffectUtil.java @@ -0,0 +1,22 @@ +package net.pitan76.mcpitanlib.api.util.particle.effect; + +import net.minecraft.item.ItemStack; +import net.minecraft.particle.ItemStackParticleEffect; +import net.minecraft.particle.ParticleType; +import net.minecraft.particle.ParticleTypes; + +// Use: ParticleEffectUtil +public class ItemStackParticleEffectUtil { + + public ItemStackParticleEffectUtil() { + // Empty constructor + } + + public ItemStackParticleEffect create(ParticleType type, ItemStack stack) { + return new ItemStackParticleEffect(type, stack); + } + + public ItemStackParticleEffect createTypedItem(ItemStack stack) { + return new ItemStackParticleEffect(ParticleTypes.ITEM, stack); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/recipe/RecipeMatcherUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/recipe/RecipeMatcherUtil.java new file mode 100644 index 000000000..6143cfd33 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/recipe/RecipeMatcherUtil.java @@ -0,0 +1,37 @@ +package net.pitan76.mcpitanlib.api.util.recipe; + +import it.unimi.dsi.fastutil.ints.IntList; +import net.minecraft.item.ItemStack; +import net.minecraft.recipe.Recipe; +import net.minecraft.recipe.RecipeMatcher; +import net.pitan76.mcpitanlib.api.recipe.CompatibleRecipeEntry; + +public class RecipeMatcherUtil { + public static ItemStack getStackFromId(int itemId) { + return RecipeMatcher.getStackFromId(itemId); + } + + public static int getItemId(ItemStack stack) { + return RecipeMatcher.getItemId(stack); + } + + public static boolean match(RecipeMatcher matcher, CompatibleRecipeEntry entry, IntList output) { + return match(matcher, entry.getRecipe(), output); + } + + public static boolean match(RecipeMatcher matcher, CompatibleRecipeEntry entry, IntList output, int multiplier) { + return match(matcher, entry.getRecipe(), output, multiplier); + } + + public static boolean match(RecipeMatcher matcher, Recipe recipe, IntList output) { + return matcher.match(recipe, output); + } + + public static boolean match(RecipeMatcher matcher, Recipe recipe, IntList output, int multiplier) { + return matcher.match(recipe, output, multiplier); + } + + public static void clear(RecipeMatcher matcher) { + matcher.clear(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/recipe/RecipeUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/recipe/RecipeUtil.java new file mode 100644 index 000000000..c8db30315 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/recipe/RecipeUtil.java @@ -0,0 +1,95 @@ +package net.pitan76.mcpitanlib.api.util.recipe; + +import net.minecraft.recipe.Recipe; +import net.minecraft.recipe.RecipeType; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.recipe.v3.CompatRecipe; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.midohra.recipe.CraftingRecipe; +import net.pitan76.mcpitanlib.midohra.recipe.entry.CraftingRecipeEntry; +import net.pitan76.mcpitanlib.midohra.recipe.entry.RecipeEntry; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +public class RecipeUtil { + public static Collection> getMCRecipes(World world) { + Collection> recipes = new ArrayList<>(); + + for (net.minecraft.recipe.RecipeEntry entry : getMCRecipeEntries(world)) { + recipes.add(entry.value()); + } + + return recipes; + } + + public static Collection> getMCRecipeEntries(World world) { + return world.getRecipeManager().values(); + } + + public static Collection getRecipes(World world) { + List recipes = new ArrayList<>(); + + for (net.minecraft.recipe.RecipeEntry entry : getMCRecipeEntries(world)) { + recipes.add(new CompatRecipe(entry)); + } + + return recipes; + } + + public static Collection getRecipesByType(World world, RecipeType type) { + List recipes = new ArrayList<>(); + + for (net.minecraft.recipe.RecipeEntry entry : getMCRecipeEntries(world)) { + if (entry.value().getType() == type) { + recipes.add(new CompatRecipe(entry)); + } + } + + return recipes; + } + + // MidohraAPI + public static Collection getRecipes(net.pitan76.mcpitanlib.midohra.world.World world) { + return getRecipes(world.getRaw()); + } + + public static Collection getRecipesByType(net.pitan76.mcpitanlib.midohra.world.World world, net.pitan76.mcpitanlib.midohra.recipe.RecipeType type) { + return getRecipesByType(world.getRaw(), type.getRaw()); + } + + public static Collection getRecipeEntries(net.pitan76.mcpitanlib.midohra.world.World world) { + List entries = new ArrayList<>(); + + for (net.minecraft.recipe.RecipeEntry entry : getMCRecipeEntries(world.getRaw())) { + entries.add(RecipeEntry.of(entry.value(), CompatIdentifier.fromMinecraft(entry.id()))); + } + + return entries; + } + + public static Collection getCraftingRecipes(net.pitan76.mcpitanlib.midohra.world.World world) { + List recipes = new ArrayList<>(); + + for (CompatRecipe recipe : getRecipesByType(world, net.pitan76.mcpitanlib.midohra.recipe.RecipeType.CRAFTING)) { + if (recipe.getRecipe() instanceof net.minecraft.recipe.CraftingRecipe) { + recipes.add(CraftingRecipe.of((net.minecraft.recipe.CraftingRecipe) recipe.getRecipe())); + } + } + + return recipes; + } + + public static Collection getCraftingRecipeEntries(net.pitan76.mcpitanlib.midohra.world.World world) { + List entries = new ArrayList<>(); + + for (net.minecraft.recipe.RecipeEntry entry : getMCRecipeEntries(world.getRaw())) { + if (entry.value() instanceof net.minecraft.recipe.CraftingRecipe) { + entries.add(CraftingRecipeEntry.of((net.minecraft.recipe.CraftingRecipe) entry.value(), CompatIdentifier.fromMinecraft(entry.id()))); + } + } + + return entries; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/recipe/input/CraftingRecipeInputUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/recipe/input/CraftingRecipeInputUtil.java new file mode 100644 index 000000000..130d63767 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/recipe/input/CraftingRecipeInputUtil.java @@ -0,0 +1,97 @@ +package net.pitan76.mcpitanlib.api.util.recipe.input; + +import net.minecraft.item.ItemStack; +import net.minecraft.recipe.RecipeMatcher; +import net.minecraft.recipe.input.CraftingRecipeInput; +import net.pitan76.mcpitanlib.api.recipe.input.CompatRecipeInput; +import net.pitan76.mcpitanlib.api.util.ItemStackUtil; + +import java.util.List; +import java.util.Optional; + +public class CraftingRecipeInputUtil { + public static Optional get(CompatRecipeInput input) { + if (input.getInput() instanceof CraftingRecipeInput) { + return Optional.of((CraftingRecipeInput) input.getInput()); + } + return Optional.empty(); + } + + public static CompatRecipeInput create(CraftingRecipeInput input) { + return new CompatRecipeInput<>(input); + } + + public static CompatRecipeInput create(int width, int height, List stacks) { + return new CompatRecipeInput<>(CraftingRecipeInput.create(width, height, stacks)); + } + + public static ItemStack getStack(CraftingRecipeInput input, int x, int y) { + return input.getStackInSlot(x, y); + } + + public static ItemStack getStack(CompatRecipeInput input, int x, int y) { + Optional recipeInput = get(input); + if (!recipeInput.isPresent()) return ItemStackUtil.empty(); + + return getStack(recipeInput.get(), x, y); + } + + public static net.pitan76.mcpitanlib.midohra.item.ItemStack getMidohraStack(CompatRecipeInput input, int x, int y) { + return net.pitan76.mcpitanlib.midohra.item.ItemStack.of(getStack(input, x, y)); + } + + public static RecipeMatcher getRecipeMatcher(CraftingRecipeInput input) { + return input.getRecipeMatcher(); + } + + public static RecipeMatcher getRecipeMatcher(CompatRecipeInput input) { + Optional recipeInput = get(input); + if (!recipeInput.isPresent()) return null; + + return getRecipeMatcher(recipeInput.get()); + } + + public static List getStacks(CraftingRecipeInput input) { + return input.getStacks(); + } + + public static List getStacks(CompatRecipeInput input) { + Optional recipeInput = get(input); + if (!recipeInput.isPresent()) return null; + + return getStacks(recipeInput.get()); + } + + public static int getWidth(CraftingRecipeInput input) { + return input.getWidth(); + } + + public static int getWidth(CompatRecipeInput input) { + Optional recipeInput = get(input); + if (!recipeInput.isPresent()) return -1; + + return getWidth(recipeInput.get()); + } + + public static int getHeight(CraftingRecipeInput input) { + return input.getHeight(); + } + + public static int getHeight(CompatRecipeInput input) { + Optional recipeInput = get(input); + if (!recipeInput.isPresent()) return -1; + + return getHeight(recipeInput.get()); + } + + public static int getStackCount(CraftingRecipeInput input) { + return input.getStackCount(); + } + + public static int getStackCount(CompatRecipeInput input) { + Optional recipeInput = get(input); + if (!recipeInput.isPresent()) return -1; + + return getStackCount(recipeInput.get()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/recipe/input/SingleStackRecipeInputUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/recipe/input/SingleStackRecipeInputUtil.java new file mode 100644 index 000000000..daf08816f --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/recipe/input/SingleStackRecipeInputUtil.java @@ -0,0 +1,32 @@ +package net.pitan76.mcpitanlib.api.util.recipe.input; + +import net.minecraft.item.ItemStack; +import net.minecraft.recipe.input.SingleStackRecipeInput; +import net.pitan76.mcpitanlib.api.recipe.input.CompatRecipeInput; +import net.pitan76.mcpitanlib.api.util.ItemStackUtil; + +import java.util.Optional; + +public class SingleStackRecipeInputUtil { + public static Optional get(CompatRecipeInput input) { + if (input.getInput() instanceof SingleStackRecipeInput) { + return Optional.of((SingleStackRecipeInput) input.getInput()); + } + return Optional.empty(); + } + + public static CompatRecipeInput create(SingleStackRecipeInput input) { + return new CompatRecipeInput<>(input); + } + + public static CompatRecipeInput create(ItemStack stack) { + return new CompatRecipeInput<>(new SingleStackRecipeInput(stack)); + } + + public static ItemStack getStack(CompatRecipeInput input) { + Optional recipeInput = get(input); + if (!recipeInput.isPresent()) return ItemStackUtil.empty(); + + return recipeInput.get().getStackInSlot(0); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/screen/ScreenHandlerUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/screen/ScreenHandlerUtil.java new file mode 100644 index 000000000..fbc99fb76 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/screen/ScreenHandlerUtil.java @@ -0,0 +1,28 @@ +package net.pitan76.mcpitanlib.api.util.screen; + +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.inventory.Inventory; +import net.minecraft.item.ItemStack; +import net.minecraft.screen.ScreenHandler; +import net.minecraft.screen.slot.Slot; +import org.jetbrains.annotations.Nullable; + +import java.util.Set; + +public class ScreenHandlerUtil { + public static int calcComparatorOutput(@Nullable Inventory inventory) { + return ScreenHandler.calculateComparatorOutput(inventory); + } + + public static int calcComparatorOutput(@Nullable BlockEntity blockEntity) { + return ScreenHandler.calculateComparatorOutput(blockEntity); + } + + public static int calculateStackSize(Set slots, int mode, ItemStack stack) { + return ScreenHandler.calculateStackSize(slots, mode, stack); + } + + public static boolean canInsertItemIntoSlot(@Nullable Slot slot, ItemStack stack, boolean allowOverflow) { + return ScreenHandler.canInsertItemIntoSlot(slot, stack, allowOverflow); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/v1/BlockUtilV1.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/v1/BlockUtilV1.java new file mode 100644 index 000000000..42b63a52c --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/v1/BlockUtilV1.java @@ -0,0 +1,73 @@ +package net.pitan76.mcpitanlib.api.util.v1; + +import net.minecraft.block.AbstractBlock; +import net.minecraft.block.Block; +import net.minecraft.registry.Registries; +import net.minecraft.util.Identifier; +import net.pitan76.mcpitanlib.api.block.CompatibleBlockSettings; +import net.pitan76.mcpitanlib.api.tag.MineableToolTags; + +import java.util.ArrayList; +import java.util.List; + +public class BlockUtilV1 { + public static Block block(Identifier id) { + return Registries.BLOCK.get(id); + } + + /** + * ~1.16? + * @param settings + * @param toolTags + * @param level + * @return + */ + public static AbstractBlock.Settings breakByTool(AbstractBlock.Settings settings, MineableToolTags toolTags, int level) { + return settings; + } + + public static AbstractBlock.Settings dropsNothing(AbstractBlock.Settings settings) { + return settings.dropsNothing(); + } + + public static AbstractBlock.Settings requiresTool(AbstractBlock.Settings settings) { + return settings.requiresTool(); + } + + public static boolean isExist(Identifier identifier) { + return Registries.BLOCK.containsId(identifier); + } + + public static Identifier toID(Block block) { + return Registries.BLOCK.getId(block); + } + + public static Block fromId(Identifier identifier) { + return Registries.BLOCK.get(identifier); + } + + public static List getAllBlocks() { + List blocks = new ArrayList<>(); + for (Block block : Registries.BLOCK) { + blocks.add(block); + } + return blocks; + } + + @Deprecated + public static Block of(AbstractBlock.Settings settings) { + return new Block(settings); + } + + public static Block of(CompatibleBlockSettings settings) { + return of(settings.build()); + } + + public static int getRawId(Block block) { + return Registries.BLOCK.getRawId(block); + } + + public static Block fromIndex(int index) { + return Registries.BLOCK.get(index); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/v1/ItemUtilV1.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/v1/ItemUtilV1.java new file mode 100644 index 000000000..b44c13657 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/v1/ItemUtilV1.java @@ -0,0 +1,81 @@ +package net.pitan76.mcpitanlib.api.util.v1; + +import net.minecraft.block.Block; +import net.minecraft.item.BlockItem; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.registry.Registries; +import net.minecraft.util.Identifier; +import net.pitan76.mcpitanlib.api.item.CompatibleItemSettings; +import net.pitan76.mcpitanlib.api.tag.TagKey; + +import java.util.ArrayList; +import java.util.List; + +public class ItemUtilV1 { + public static Item item(Identifier id) { + return Registries.ITEM.get(id); + } + + public static boolean isEqual(Item item, Item item2) { + return item == item2; + } + + public static boolean isOf(ItemStack stack, Item item) { + return stack.isOf(item); + } + + public static boolean isIn(ItemStack stack, TagKey tagKey) { + return isIn(stack.getItem(), tagKey); + } + + public static boolean isIn(Item item, TagKey tagKey) { + if (item.getRegistryEntry().isIn(tagKey.getTagKey())) return true; + return tagKey.isOf(item); + } + + public static boolean isExist(Identifier identifier) { + return Registries.ITEM.containsId(identifier); + } + public static Identifier toID(Item item) { + return Registries.ITEM.getId(item); + } + + public static Item fromId(Identifier identifier) { + return Registries.ITEM.get(identifier); + } + + @Deprecated + public static BlockItem ofBlock(Block block, Item.Settings settings) { + return new BlockItem(block, settings); + } + + public static BlockItem ofBlock(Block block, CompatibleItemSettings settings) { + return ofBlock(block, settings.build()); + } + + @Deprecated + public static Item of(Item.Settings settings) { + return new Item(settings); + } + + public static Item of(CompatibleItemSettings settings) { + return of(settings.build()); + } + + public static List getAllItems() { + List items = new ArrayList<>(); + for (Item item : Registries.ITEM) { + items.add(item); + } + return items; + } + + public static int getRawId(Item item) { + return Registries.ITEM.getRawId(item); + } + + public static Item fromIndex(int index) { + return Registries.ITEM.get(index); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/v2/BlockUtilV2.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/v2/BlockUtilV2.java new file mode 100644 index 000000000..5024e1b7a --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/v2/BlockUtilV2.java @@ -0,0 +1,125 @@ +package net.pitan76.mcpitanlib.api.util.v2; + +import net.minecraft.block.Block; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.Identifier; +import net.pitan76.mcpitanlib.api.tag.TagKey; +import net.pitan76.mcpitanlib.api.util.BlockUtil; +import net.pitan76.mcpitanlib.api.util.IdentifierUtil; + +import java.util.ArrayList; +import java.util.List; + +public class BlockUtilV2 { + /** + * Check if the block is in the tag. (MCPitanLib TagKey) + * @param block Block to check. + * @param tagKey TagKey of the tag. + * @return If the block is in the tag. + */ + public static boolean isIn(Block block, TagKey tagKey) { + if (block.getRegistryEntry().isIn(tagKey.getTagKey())) return true; + return tagKey.isOf(block); + } + + /** + * Check if two blocks are equal. + * @param block Block to compare. + * @param block2 Block to compare. + * @return If two blocks are equal. + */ + public static boolean isEqual(Block block, Block block2) { + return block == block2; + } + + /** + * Get all blocks in the tag. + * @param tagKey TagKey of the tag. + * @return List of blocks in the tag. + */ + public static List getBlocks(TagKey tagKey) { + return getBlocks(tagKey, BlockUtil.getAllBlocks()); + } + /** + * Get given the list of blocks in the tag. + * @param tagKey TagKey of the tag. + * @param blocks List of blocks to search. + * @return List of blocks in the tag. + */ + public static List getBlocks(TagKey tagKey, List blocks) { + List result = new ArrayList<>(); + for (Block block : blocks) { + if (!BlockUtil.isIn(block, tagKey)) continue; + result.add(block); + } + return result; + } + + /** + * Get all blocks in the tag. + * @param identifier Identifier of the tag. + * @return List of blocks in the tag. + */ + public static List getBlocks(Identifier identifier) { + return getBlocks((TagKey) TagKey.create(TagKey.Type.BLOCK, identifier)); + } + + /** + * Get given the list of blocks in the tag. + * @param identifier Identifier of the tag. + * @param blocks List of blocks to search. + * @return List of blocks in the tag. + */ + public static List getBlocks(Identifier identifier, List blocks) { + return getBlocks((TagKey) TagKey.create(TagKey.Type.BLOCK, identifier), blocks); + } + + /** + * Get all blocks in the tag. + * @param id String of the tag. + * @return List of blocks in the tag. + */ + public static List getBlocks(String id) { + return getBlocks(IdentifierUtil.id(id)); + } + + /** + * Get given the list of blocks in the tag. + * @param id String of the tag. + * @param blocks List of blocks to search. + * @return List of blocks in the tag. + */ + + public static List getBlocks(String id, List blocks) { + return getBlocks(IdentifierUtil.id(id), blocks); + } + + /** + * Check if the block is in the tag. + * @param block Block to check. + * @param identifier Identifier of the tag. + * @return If the block is in the tag. + */ + public static boolean isBlockInTag(Block block, Identifier identifier) { + return BlockUtil.isIn(block, (TagKey) TagKey.create(TagKey.Type.BLOCK, identifier)); + } + + /** + * Check if the block is in the tag. + * @param block Block to check. + * @param id String of the tag. + * @return If the block is in the tag. + */ + public static boolean isBlockInTag(Block block, String id) { + return isBlockInTag(block, IdentifierUtil.id(id)); + } + + public static Block fromItem(Item item) { + return Block.getBlockFromItem(item); + } + + public static Block fromItem(ItemStack stack) { + return fromItem(stack.getItem()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/v2/CustomNameUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/v2/CustomNameUtil.java new file mode 100644 index 000000000..c24eb0df9 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/v2/CustomNameUtil.java @@ -0,0 +1,50 @@ +package net.pitan76.mcpitanlib.api.util.v2; + +import net.minecraft.component.DataComponentTypes; +import net.minecraft.item.ItemStack; +import net.minecraft.text.Text; +import net.pitan76.mcpitanlib.api.text.TextComponent; +import net.pitan76.mcpitanlib.api.util.TextUtil; + +public class CustomNameUtil { + + public static void setCustomName(ItemStack stack, Text name) { + stack.set(DataComponentTypes.CUSTOM_NAME, name); + } + + public static void setCustomName(ItemStack stack, String name) { + setCustomNameFromString(stack, name); + } + + public static void setCustomNameFromString(ItemStack stack, String name) { + setCustomName(stack, TextUtil.literal(name)); + } + + public static void setCustomNameFromTranslatable(ItemStack stack, String key) { + setCustomName(stack, TextUtil.translatable(key)); + } + + public static void setCustomName(ItemStack stack, TextComponent name) { + setCustomName(stack, name.getText()); + } + + public static Text getCustomName(ItemStack stack) { + return stack.get(DataComponentTypes.CUSTOM_NAME); + } + + public static String getCustomNameAsString(ItemStack stack) { + return getCustomName(stack).getString(); + } + + public static TextComponent getCustomNameAsTextComponent(ItemStack stack) { + return new TextComponent(getCustomName(stack)); + } + + public static boolean hasCustomName(ItemStack stack) { + return stack.contains(DataComponentTypes.CUSTOM_NAME); + } + + public static void removeCustomName(ItemStack stack) { + stack.remove(DataComponentTypes.CUSTOM_NAME); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/v2/ItemUtilV2.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/v2/ItemUtilV2.java new file mode 100644 index 000000000..636e449c7 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/v2/ItemUtilV2.java @@ -0,0 +1,94 @@ +package net.pitan76.mcpitanlib.api.util.v2; + +import net.minecraft.item.Item; +import net.minecraft.util.Identifier; +import net.pitan76.mcpitanlib.api.tag.TagKey; +import net.pitan76.mcpitanlib.api.util.IdentifierUtil; +import net.pitan76.mcpitanlib.api.util.ItemUtil; + +import java.util.ArrayList; +import java.util.List; + +public class ItemUtilV2 { + /** + * Get all items in the tag. + * @param tagKey TagKey of the tag. + * @return List of items in the tag. + */ + public static List getItems(TagKey tagKey) { + return getItems(tagKey, ItemUtil.getAllItems()); + } + + /** + * Get given the list of items in the tag. + * @param tagKey TagKey of the tag. + * @param items List of items to search. + * @return List of items in the tag. + */ + public static List getItems(TagKey tagKey, List items) { + List result = new ArrayList<>(); + for (Item item : items) { + if (!ItemUtil.isIn(item, tagKey)) continue; + result.add(item); + } + return result; + } + + /** + * Get all items in the tag. + * @param identifier Identifier of the tag. + * @return List of items in the tag. + */ + public static List getItems(Identifier identifier) { + return getItems((TagKey) TagKey.create(TagKey.Type.ITEM, identifier)); + } + + /** + * Get given the list of items in the tag. + * @param identifier Identifier of the tag. + * @param items List of items to search. + * @return List of items in the tag. + */ + public static List getItems(Identifier identifier, List items) { + return getItems((TagKey) TagKey.create(TagKey.Type.ITEM, identifier), items); + } + + /** + * Get all items in the tag. + * @param id String of the tag. + * @return List of items in the tag. + */ + public static List getItems(String id) { + return getItems(IdentifierUtil.id(id)); + } + + /** + * Get given the list of items in the tag. + * @param id String of the tag. + * @param items List of items to search. + * @return List of items in the tag. + */ + public static List getItems(String id, List items) { + return getItems(IdentifierUtil.id(id), items); + } + + /** + * Check if the item is in the tag. + * @param item Item to check. + * @param identifier Identifier of the tag. + * @return True if the item is in the tag. + */ + public static boolean isItemInTag(Item item, Identifier identifier) { + return ItemUtil.isIn(item, (TagKey) TagKey.create(TagKey.Type.ITEM, identifier)); + } + + /** + * Check if the item is in the tag. + * @param item Item to check. + * @param id String of the tag. + * @return True if the item is in the tag. + */ + public static boolean isItemInTag(Item item, String id) { + return isItemInTag(item, IdentifierUtil.id(id)); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/world/ChunkManagerUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/world/ChunkManagerUtil.java new file mode 100644 index 000000000..436192e5d --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/world/ChunkManagerUtil.java @@ -0,0 +1,26 @@ +package net.pitan76.mcpitanlib.api.util.world; + +import net.minecraft.server.world.ServerChunkManager; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.midohra.util.math.BlockPos; + +public class ChunkManagerUtil { + + public static void markForUpdate(ServerChunkManager manager, BlockPos pos) { + markForUpdate(manager, pos.toRaw()); + } + + public static void markForUpdate(ServerChunkManager manager, net.minecraft.util.math.BlockPos pos) { + manager.markForUpdate(pos); + } + + public static void markForUpdate(ServerWorld world, net.minecraft.util.math.BlockPos pos) { + markForUpdate(ServerWorldUtil.getChunkManager(world), pos); + } + + public static void markForUpdate(World world, net.minecraft.util.math.BlockPos pos) { + if (!(world instanceof ServerWorld)) return; + markForUpdate((ServerWorld) world, pos); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/world/ServerWorldUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/world/ServerWorldUtil.java new file mode 100644 index 000000000..5d1097d1d --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/world/ServerWorldUtil.java @@ -0,0 +1,44 @@ +package net.pitan76.mcpitanlib.api.util.world; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.entity.Entity; +import net.minecraft.item.ItemStack; +import net.minecraft.particle.ParticleEffect; +import net.minecraft.server.world.ServerChunkManager; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.util.math.BlockPos; +import net.pitan76.mcpitanlib.api.entity.Player; +import net.pitan76.mcpitanlib.midohra.block.entity.BlockEntityWrapper; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +public class ServerWorldUtil { + public static void spawnParticles(ServerWorld world, ParticleEffect particle, double x, double y, double z, int count, double velocityX, double velocityY, double velocityZ, double speed) { + world.spawnParticles(particle, x, y, z, count, velocityX, velocityY, velocityZ, speed); + } + + public static void spawnParticles(ServerWorld world, Player player, ParticleEffect particle, boolean force, double x, double y, double z, int count, double velocityX, double velocityY, double velocityZ, double speed) { + if (player.isServer()) { + world.spawnParticles(player.getServerPlayer().get(), particle, force, x, y, z, count, velocityX, velocityY, velocityZ, speed); + } + } + + public static List getDroppedStacksOnBlock(BlockState state, ServerWorld world, BlockPos pos, @Nullable BlockEntity blockEntity) { + return Block.getDroppedStacks(state, world, pos, blockEntity); + } + + public static List getDroppedStacksOnBlock(BlockState state, ServerWorld world, BlockPos pos, @Nullable BlockEntityWrapper blockEntity) { + return getDroppedStacksOnBlock(state, world, pos, blockEntity.get()); + } + + public static List getDroppedStacksOnBlock(BlockState state, ServerWorld world, BlockPos pos, @Nullable BlockEntity blockEntity, @Nullable Entity entity, ItemStack stack) { + return Block.getDroppedStacks(state, world, pos, blockEntity, entity, stack); + } + + public static ServerChunkManager getChunkManager(ServerWorld world) { + return world.getChunkManager(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/world/TickerUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/world/TickerUtil.java new file mode 100644 index 000000000..eebe3f823 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/world/TickerUtil.java @@ -0,0 +1,32 @@ +package net.pitan76.mcpitanlib.api.util.world; + +import net.minecraft.block.BlockState; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.block.entity.BlockEntityTicker; +import net.minecraft.entity.Entity; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.util.WorldUtil; + +public class TickerUtil { + public static void tick(T blockEntity, World world, BlockPos pos, BlockState state) { + if (isTicker(blockEntity)) + ((BlockEntityTicker) blockEntity).tick(world, pos, state, blockEntity); + } + + public static void tick(T blockEntity, World world, BlockPos pos) { + tick(blockEntity, world, pos, WorldUtil.getBlockState(world, pos)); + } + + public static void tick(T blockEntity) { + tick(blockEntity, blockEntity.getWorld(), blockEntity.getPos()); + } + + public static void tick(T entity) { + entity.tick(); + } + + public static boolean isTicker(BlockEntity blockEntity) { + return blockEntity instanceof BlockEntityTicker; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/world/WorldAccessUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/world/WorldAccessUtil.java new file mode 100644 index 000000000..6bf8142a5 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/world/WorldAccessUtil.java @@ -0,0 +1,52 @@ +package net.pitan76.mcpitanlib.api.util.world; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.entity.Entity; +import net.minecraft.fluid.Fluid; +import net.minecraft.server.MinecraftServer; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.WorldAccess; + +public class WorldAccessUtil extends WorldViewUtil { + + public static void scheduleBlockTick(WorldAccess world, BlockPos pos, Block block, int delay) { + world.scheduleBlockTick(pos, block, delay); + } + + public static void scheduleFluidTick(WorldAccess world, BlockPos pos, Fluid fluid, int delay) { + world.scheduleFluidTick(pos, fluid, delay); + } + + public static boolean setBlockState(WorldAccess world, BlockPos pos, BlockState state, int flags) { + return world.setBlockState(pos, state, flags); + } + + public static boolean setBlockState(WorldAccess world, BlockPos pos, BlockState state, int flags, int maxUpdateDepth) { + return world.setBlockState(pos, state, flags, maxUpdateDepth); + } + + public static boolean setBlockState(WorldAccess world, BlockPos pos, BlockState state) { + return setBlockState(world, pos, state, 3); + } + + public static BlockState getBlockState(WorldAccess world, BlockPos pos) { + return world.getBlockState(pos); + } + + public static boolean breakBlock(WorldAccess world, BlockPos pos, boolean drop) { + return world.breakBlock(pos, drop); + } + + public static boolean breakBlock(WorldAccess world, BlockPos pos, boolean drop, Entity entity) { + return world.breakBlock(pos, drop, entity); + } + + public static boolean removeBlock(WorldAccess world, BlockPos pos, boolean move) { + return world.removeBlock(pos, move); + } + + public static MinecraftServer getServer(WorldAccess world) { + return world.getServer(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/world/WorldViewUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/world/WorldViewUtil.java new file mode 100644 index 000000000..f90af366b --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/world/WorldViewUtil.java @@ -0,0 +1,77 @@ +package net.pitan76.mcpitanlib.api.util.world; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.block.entity.BlockEntityType; +import net.minecraft.fluid.Fluid; +import net.minecraft.fluid.FluidState; +import net.minecraft.registry.tag.FluidTags; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.WorldView; +import net.minecraft.world.dimension.DimensionType; + +import java.util.Optional; + +public class WorldViewUtil { + + public static boolean isClient(WorldView world) { + return world.isClient(); + } + + public static BlockState getBlockState(WorldView world, BlockPos pos) { + return world.getBlockState(pos); + } + + public static Block getBlock(WorldView world, BlockPos pos) { + return getBlockState(world, pos).getBlock(); + } + + public static BlockEntity getBlockEntity(WorldView world, BlockPos pos) { + return world.getBlockEntity(pos); + } + + public static Optional getBlockEntity(WorldView world, BlockPos pos, BlockEntityType type) { + return world.getBlockEntity(pos, type); + } + + public static FluidState getFluidState(WorldView world, BlockPos pos) { + return getBlockState(world, pos).getFluidState(); + } + + public static Fluid getFluid(WorldView world, BlockPos pos) { + return getFluidState(world, pos).getFluid(); + } + + public static int getBottomY(WorldView world) { + return world.getBottomY(); + } + + public static int getTopY(WorldView world) { + return world.getTopY(); + } + + public static boolean isChunkLoaded(WorldView world, BlockPos pos) { + return world.isChunkLoaded(pos); + } + + public static boolean isRegionLoaded(WorldView world, BlockPos min, BlockPos max) { + return world.isRegionLoaded(min, max); + } + + public static DimensionType getDimensionType(WorldView world) { + return world.getDimension(); + } + + public static boolean isAirBlock(WorldView world, BlockPos pos) { + return getBlockState(world, pos).isAir(); + } + + public static boolean isOpaqueBlock(WorldView world, BlockPos pos) { + return getBlockState(world, pos).isOpaque(); + } + + public static boolean isWater(WorldView world, BlockPos pos) { + return getFluidState(world, pos).isIn(FluidTags.WATER); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/world/CompatiblePersistentState.java b/common/src/main/java/net/pitan76/mcpitanlib/api/world/CompatiblePersistentState.java new file mode 100644 index 000000000..e473dd8d1 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/world/CompatiblePersistentState.java @@ -0,0 +1,54 @@ +package net.pitan76.mcpitanlib.api.world; + +import net.minecraft.nbt.NbtCompound; +import net.minecraft.registry.RegistryWrapper; +import net.minecraft.world.PersistentState; +import net.pitan76.mcpitanlib.api.event.nbt.ReadNbtArgs; +import net.pitan76.mcpitanlib.api.event.nbt.WriteNbtArgs; + +public abstract class CompatiblePersistentState extends PersistentState { + // 1.16 + public CompatiblePersistentState(String key) { + super(); + } + + public CompatiblePersistentState() { + super(); + } + + // 1.16 + @Deprecated + public void readNbt(NbtCompound tag) { + readNbt(new ReadNbtArgs(tag)); + } + + public abstract void readNbt(ReadNbtArgs args); + + @Deprecated + @Override + public NbtCompound writeNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup registryLookup) { + return writeNbt(new WriteNbtArgs(nbt, registryLookup)); + } + + public abstract NbtCompound writeNbt(WriteNbtArgs args); + + @Deprecated + @Override + public void markDirty() { + callMarkDirty(); + } + + public void callMarkDirty() { + super.markDirty(); + } + + @Deprecated + @Override + public void setDirty(boolean dirty) { + callSetDirty(dirty); + } + + public void callSetDirty(boolean dirty) { + super.setDirty(dirty); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/world/ExtendWorld.java b/common/src/main/java/net/pitan76/mcpitanlib/api/world/ExtendWorld.java new file mode 100644 index 000000000..865a2694f --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/world/ExtendWorld.java @@ -0,0 +1,48 @@ +package net.pitan76.mcpitanlib.api.world; + +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.util.WorldUtil; + +public class ExtendWorld { + public World world; + public ExtendWorld(World world) { + this.world = world; + } + + public boolean isDay() { + return WorldUtil.isDay(world); + } + + public boolean isThundering() { + return WorldUtil.isThundering(world); + } + + public boolean isSkyVisible(BlockPos pos) { + return WorldUtil.isSkyVisible(world, pos); + } + + public boolean isRaining() { + return WorldUtil.isRaining(world); + } + + public boolean hasSkyLight() { + return WorldUtil.hasSkyLight(world); + } + + public boolean isNight() { + return WorldUtil.isNight(world); + } + + public boolean isClient() { + return WorldUtil.isClient(world); + } + + public boolean isServer() { + return WorldUtil.isServer(world); + } + + public World getMinecraftWorld() { + return world; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/core/Dummy.java b/common/src/main/java/net/pitan76/mcpitanlib/core/Dummy.java new file mode 100644 index 000000000..0386ac276 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/core/Dummy.java @@ -0,0 +1,4 @@ +package net.pitan76.mcpitanlib.core; + +public class Dummy { +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/core/command/CommandResult.java b/common/src/main/java/net/pitan76/mcpitanlib/core/command/CommandResult.java new file mode 100644 index 000000000..c93a48bcd --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/core/command/CommandResult.java @@ -0,0 +1,73 @@ +package net.pitan76.mcpitanlib.core.command; + +import net.minecraft.server.command.ServerCommandSource; + +public class CommandResult { + private boolean isSuccess = false; + private String message = ""; + private int result = 0; + private ErrorType errorType = ErrorType.NONE; + private ServerCommandSource source; + + public CommandResult() { + + } + + public CommandResult(boolean isSuccess, String message) { + this.isSuccess = isSuccess; + this.message = message; + } + + public void setResult(int result) { + this.result = result; + } + + public void setMessage(String message) { + this.message = message; + } + + public void setSuccess(boolean success) { + isSuccess = success; + } + + public boolean isSuccess() { + return isSuccess; + } + + public String getMessage() { + return message; + } + + public int getResult() { + return result; + } + + public void setErrorType(ErrorType errorType) { + this.errorType = errorType; + } + + public ErrorType getErrorType() { + return errorType; + } + + public void setSource(ServerCommandSource source) { + this.source = source; + } + + public ServerCommandSource getSource() { + return source; + } + + public boolean hasError() { + return errorType != ErrorType.NONE; + } + + public enum ErrorType { + NONE, + COMMAND_SYNTAX_ERROR, + COMMAND_NOT_FOUND, + COMMAND_PERMISSION_ERROR, + COMMAND_UNKNOWN_ERROR, + RUNTIME_ERROR + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/core/datafixer/Pair.java b/common/src/main/java/net/pitan76/mcpitanlib/core/datafixer/Pair.java new file mode 100644 index 000000000..d6d85643f --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/core/datafixer/Pair.java @@ -0,0 +1,43 @@ +package net.pitan76.mcpitanlib.core.datafixer; + +public class Pair { + private A a; + private B b; + + public Pair(A a, B b) { + this.a = a; + this.b = b; + } + + public A getA() { + return a; + } + + public B getB() { + return b; + } + + public void setA(A a) { + this.a = a; + } + + public void setB(B b) { + this.b = b; + } + + public static Pair of(A a, B b) { + return new Pair<>(a, b); + } + + public static Pair of() { + return new Pair<>(null, null); + } + + public static Pair ofA(A a) { + return new Pair<>(a, null); + } + + public static Pair ofB(B b) { + return new Pair<>(null, b); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/core/network/BufPayload.java b/common/src/main/java/net/pitan76/mcpitanlib/core/network/BufPayload.java new file mode 100644 index 000000000..ca4b437c2 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/core/network/BufPayload.java @@ -0,0 +1,67 @@ +package net.pitan76.mcpitanlib.core.network; + +import io.netty.buffer.ByteBufUtil; +import net.minecraft.network.PacketByteBuf; +import net.minecraft.network.codec.PacketCodec; +import net.minecraft.network.codec.PacketCodecs; +import net.minecraft.network.packet.CustomPayload; +import net.minecraft.util.Identifier; + +import java.util.HashMap; +import java.util.Map; + +public class BufPayload implements CustomPayload { + + public final Id ID; + + public BufPayload(byte[] data, Id id) { + this.data = data; + this.ID = id; + + createCodec(id); + } + + public BufPayload(PacketByteBuf buf, Id id) { + this(ByteBufUtil.getBytes(buf), id); + } + + public BufPayload(PacketByteBuf buf, Identifier id) { + this(ByteBufUtil.getBytes(buf), id(id)); + } + + public byte[] data; + + public byte[] getData() { + return data; + } + + private static final Map, PacketCodec> CODEC_CACHE = new HashMap<>(); + + public static PacketCodec getCodec(Id id) { + if (CODEC_CACHE.containsKey(id)) return CODEC_CACHE.get(id); + + return createCodec(id); + } + + private static PacketCodec createCodec(Id id) { + PacketCodec codec = PacketCodecs.BYTE_ARRAY.xmap((data) -> new BufPayload(data, id), BufPayload::getData).cast(); + CODEC_CACHE.put(id, codec); + return codec; + } + + @Override + public Id getId() { + return ID; + } + + public static Id id(Identifier id) { + if (CODEC_CACHE.isEmpty()) return new Id<>(id); + + for (Id key : CODEC_CACHE.keySet()) { + if (key.id().equals(id)) + return key; + } + + return new Id<>(id); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/core/player/ItemCooldown.java b/common/src/main/java/net/pitan76/mcpitanlib/core/player/ItemCooldown.java new file mode 100644 index 000000000..7a1572db1 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/core/player/ItemCooldown.java @@ -0,0 +1,31 @@ +package net.pitan76.mcpitanlib.core.player; + +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.pitan76.mcpitanlib.api.entity.Player; + +public class ItemCooldown { + public final Player player; + + public ItemCooldown(Player player) { + this.player = player; + } + + public boolean isCoolingDown(Item item) { + for (ItemStack stack : player.getMain()) { + if (stack.getItem() == item) { + return player.getItemCooldownManager().isCoolingDown(item); + } + } + + return false; + } + + public void set(Item item, int duration) { + for (ItemStack stack : player.getMain()) { + if (stack.getItem() == item) { + player.getItemCooldownManager().set(item, duration); + } + } + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/core/registry/FuelRegistry.java b/common/src/main/java/net/pitan76/mcpitanlib/core/registry/FuelRegistry.java new file mode 100644 index 000000000..b895feb2c --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/core/registry/FuelRegistry.java @@ -0,0 +1,29 @@ +package net.pitan76.mcpitanlib.core.registry; + +import net.minecraft.block.entity.AbstractFurnaceBlockEntity; +import net.minecraft.item.ItemConvertible; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +public class FuelRegistry { + private FuelRegistry() { + + } + + public static void register(int time, ItemConvertible... item) { + dev.architectury.registry.fuel.FuelRegistry.register(time, item); + } + + @Deprecated + public static int get(ItemStack stack) { + return dev.architectury.registry.fuel.FuelRegistry.get(stack); + } + + public static int get(World world, ItemStack stack) { + return dev.architectury.registry.fuel.FuelRegistry.get(stack); + } + + public static boolean isFuel(World world, ItemStack stack) { + return AbstractFurnaceBlockEntity.canUseAsFuel(stack); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/core/registry/MCPLRegistry.java b/common/src/main/java/net/pitan76/mcpitanlib/core/registry/MCPLRegistry.java new file mode 100644 index 000000000..526c44366 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/core/registry/MCPLRegistry.java @@ -0,0 +1,95 @@ +package net.pitan76.mcpitanlib.core.registry; + +import com.google.common.base.Suppliers; +import dev.architectury.registry.registries.Registrar; +import dev.architectury.registry.registries.RegistrarManager; +import dev.architectury.registry.registries.RegistrySupplier; +import net.minecraft.block.Block; +import net.minecraft.block.entity.BlockEntityType; +import net.minecraft.enchantment.Enchantment; +import net.minecraft.entity.EntityType; +import net.minecraft.entity.effect.StatusEffect; +import net.minecraft.fluid.Fluid; +import net.minecraft.item.Item; +import net.minecraft.particle.ParticleType; +import net.minecraft.registry.RegistryKeys; +import net.minecraft.screen.ScreenHandlerType; +import net.minecraft.sound.SoundEvent; +import net.minecraft.util.Identifier; + +import java.util.function.Supplier; + +@Deprecated +public class MCPLRegistry { + + public Supplier REGISTRIES; + + public Registrar ITEMS; + public Registrar BLOCKS; + public Registrar> SCREEN_HANDLER_TYPE; + public Registrar> BLOCK_ENTITY_TYPE; + public Registrar> ENTITY_TYPE; + public Registrar SOUND_EVENT; + public Registrar FLUID; + public Registrar> PARTICLE_TYPE; + public Registrar STATUS_EFFECT; + + public MCPLRegistry(String MOD_ID) { + REGISTRIES = Suppliers.memoize(() -> RegistrarManager.get(MOD_ID)); + + ITEMS = REGISTRIES.get().get(RegistryKeys.ITEM); + BLOCKS = REGISTRIES.get().get(RegistryKeys.BLOCK); + SCREEN_HANDLER_TYPE = REGISTRIES.get().get(RegistryKeys.SCREEN_HANDLER); + BLOCK_ENTITY_TYPE = REGISTRIES.get().get(RegistryKeys.BLOCK_ENTITY_TYPE); + ENTITY_TYPE = REGISTRIES.get().get(RegistryKeys.ENTITY_TYPE); + SOUND_EVENT = REGISTRIES.get().get(RegistryKeys.SOUND_EVENT); + FLUID = REGISTRIES.get().get(RegistryKeys.FLUID); + PARTICLE_TYPE = REGISTRIES.get().get(RegistryKeys.PARTICLE_TYPE); + STATUS_EFFECT = REGISTRIES.get().get(RegistryKeys.STATUS_EFFECT); + } + + public RegistrySupplier registryItem(Identifier id, Supplier supplier) { + return ITEMS.register(id, supplier); + } + + public RegistrySupplier registryBlock(Identifier id, Supplier supplier) { + return BLOCKS.register(id, supplier); + } + + public RegistrySupplier> registryScreenHandlerType(Identifier id, Supplier> supplier) { + return SCREEN_HANDLER_TYPE.register(id, supplier); + } + + public RegistrySupplier> registryBlockEntityType(Identifier id, Supplier> supplier) { + return BLOCK_ENTITY_TYPE.register(id, supplier); + } + + public RegistrySupplier> registryEntityType(Identifier id, Supplier> supplier) { + return ENTITY_TYPE.register(id, supplier); + } + + public RegistrySupplier registrySoundEvent(Identifier id, Supplier supplier) { + return SOUND_EVENT.register(id, supplier); + } + + public RegistrySupplier registryFluid(Identifier id, Supplier supplier) { + return FLUID.register(id, supplier); + } + + public RegistrySupplier> registryParticleType(Identifier id, Supplier> supplier) { + return PARTICLE_TYPE.register(id, supplier); + } + + public RegistrySupplier registryEnchantment(Identifier id, Supplier supplier) { + return null; + //return ENCHANTMENT.register(id, supplier); + } + + public RegistrySupplier registryStatusEffect(Identifier id, Supplier supplier) { + return STATUS_EFFECT.register(id, supplier); + } + + public void allRegister1_16() { + + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/core/registry/MCPLRegistry1_20.java b/common/src/main/java/net/pitan76/mcpitanlib/core/registry/MCPLRegistry1_20.java new file mode 100644 index 000000000..52a1d7fca --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/core/registry/MCPLRegistry1_20.java @@ -0,0 +1,43 @@ +package net.pitan76.mcpitanlib.core.registry; + +import dev.architectury.registry.registries.DeferredRegister; +import dev.architectury.registry.registries.RegistrySupplier; +import net.minecraft.item.ItemGroup; +import net.minecraft.registry.RegistryKeys; +import net.minecraft.util.Identifier; +import net.pitan76.mcpitanlib.api.item.CreativeTabBuilder; + +import java.util.HashMap; +import java.util.Map; +import java.util.function.Supplier; + +@Deprecated +public class MCPLRegistry1_20 { + @Deprecated + public static final Map> REGISTRY_SUPPLIER_ITEM_GROUP_CACHE = new HashMap<>(); + + private final MCPLRegistry mcplr; + + protected DeferredRegister ITEM_GROUP; + + public MCPLRegistry1_20(MCPLRegistry mcplr, String MOD_ID) { + this.mcplr = mcplr; + ITEM_GROUP = DeferredRegister.create(MOD_ID, RegistryKeys.ITEM_GROUP); + } + + public void register() { + ITEM_GROUP.register(); + } + + public RegistrySupplier registryItemGroup(Identifier id, Supplier supplier) { + RegistrySupplier itemGroup = ITEM_GROUP.register(id, supplier); + REGISTRY_SUPPLIER_ITEM_GROUP_CACHE.put(id, itemGroup); + return itemGroup; + } + + public RegistrySupplier registryItemGroup(Identifier id, CreativeTabBuilder builder) { + RegistrySupplier itemGroup = ITEM_GROUP.register(id, builder::build); + REGISTRY_SUPPLIER_ITEM_GROUP_CACHE.put(id, itemGroup); + return itemGroup; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/core/registry/MCPLRegistry1_21.java b/common/src/main/java/net/pitan76/mcpitanlib/core/registry/MCPLRegistry1_21.java new file mode 100644 index 000000000..fe6cd62be --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/core/registry/MCPLRegistry1_21.java @@ -0,0 +1,30 @@ +package net.pitan76.mcpitanlib.core.registry; + +import dev.architectury.registry.registries.DeferredRegister; +import dev.architectury.registry.registries.RegistrySupplier; +import net.minecraft.component.ComponentType; +import net.minecraft.registry.RegistryKeys; +import net.minecraft.util.Identifier; + +import java.util.function.Supplier; + +@Deprecated +public class MCPLRegistry1_21 { + + public final DeferredRegister> DATA_COMPONENT_TYPE; + + private final MCPLRegistry mcplr; + + public MCPLRegistry1_21(MCPLRegistry mcplr, String MOD_ID) { + this.mcplr = mcplr; + DATA_COMPONENT_TYPE = DeferredRegister.create(MOD_ID, RegistryKeys.DATA_COMPONENT_TYPE); + } + + public void register() { + DATA_COMPONENT_TYPE.register(); + } + + public RegistrySupplier> registryDataComponentType(Identifier id, Supplier> supplier) { + return DATA_COMPONENT_TYPE.register(id, supplier); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/core/serialization/CompatMapCodec.java b/common/src/main/java/net/pitan76/mcpitanlib/core/serialization/CompatMapCodec.java new file mode 100644 index 000000000..a5a70af11 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/core/serialization/CompatMapCodec.java @@ -0,0 +1,76 @@ +package net.pitan76.mcpitanlib.core.serialization; + +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import net.minecraft.block.AbstractBlock; +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.pitan76.mcpitanlib.api.block.CompatStairsBlock; +import net.pitan76.mcpitanlib.api.block.v2.CompatBlock; +import net.pitan76.mcpitanlib.api.block.v2.CompatibleBlockSettings; +import net.pitan76.mcpitanlib.api.block.ExtendBlock; +import net.pitan76.mcpitanlib.core.serialization.codecs.CompatBlockMapCodecUtil; + +import java.util.function.BiFunction; +import java.util.function.Function; + +public class CompatMapCodec { + @Deprecated + public MapCodec codec; + + @Deprecated + public CompatMapCodec(MapCodec codec) { + this.codec = codec; + } + + @Deprecated + public static CompatMapCodec of(MapCodec codec) { + return new CompatMapCodec<>(codec); + } + + public CompatMapCodec() { + + } + + public static CompatMapCodec of() { + return new CompatMapCodec<>(); + } + + @Deprecated + public MapCodec getCodec() { + return codec; + } + + public static RecordCodecBuilder createSettingsCodec() { + return AbstractBlock.Settings.CODEC.fieldOf("properties").forGetter(AbstractBlock::getSettings); + } + + public static CompatMapCodec createCodec(Function blockFromSettings) { + return of(RecordCodecBuilder.mapCodec((instance) -> instance.group(createSettingsCodec()).apply(instance, blockFromSettings))); + } + + @Deprecated + public static RecordCodecBuilder createCompatSettingsCodec() { + return net.pitan76.mcpitanlib.api.block.CompatibleBlockSettings.CODEC.fieldOf("properties").forGetter(ExtendBlock::getCompatSettings); + } + + @Deprecated + public static CompatMapCodec createCodecOfExtendBlock(Function blockFromSettings) { + return of(RecordCodecBuilder.mapCodec((instance) -> instance.group(createCompatSettingsCodec()).apply(instance, blockFromSettings))); + } + + public static RecordCodecBuilder createCompatSettingsV2Codec() { + return CompatBlockMapCodecUtil.createSettingsCodec(); + } + + public static CompatMapCodec createCodecOfCompatBlock(Function blockFromSettings) { + return CompatBlockMapCodecUtil.createCodec(blockFromSettings); + } + + public static CompatMapCodec createCodecOfCompatStairsBlock(BiFunction createFunction) { + return of(RecordCodecBuilder.mapCodec((instance) -> instance.group( + BlockState.CODEC.fieldOf("base_state").forGetter(CompatStairsBlock::getBaseBlockState), + net.pitan76.mcpitanlib.api.block.CompatibleBlockSettings.CODEC.fieldOf("properties").forGetter(CompatStairsBlock::getCompatSettings) + ).apply(instance, createFunction))); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/core/serialization/codecs/CompatBlockMapCodecUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/core/serialization/codecs/CompatBlockMapCodecUtil.java new file mode 100644 index 000000000..12d5880b6 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/core/serialization/codecs/CompatBlockMapCodecUtil.java @@ -0,0 +1,57 @@ +package net.pitan76.mcpitanlib.core.serialization.codecs; + +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.pitan76.mcpitanlib.api.block.CompatChestBlock; +import net.pitan76.mcpitanlib.api.block.CompatPillarBlock; +import net.pitan76.mcpitanlib.api.block.CompatSlabBlock; +import net.pitan76.mcpitanlib.api.block.CompatStairsBlock; +import net.pitan76.mcpitanlib.api.block.v2.CompatBlock; +import net.pitan76.mcpitanlib.api.block.v2.CompatibleBlockSettings; +import net.pitan76.mcpitanlib.core.serialization.CompatMapCodec; + +import java.util.function.BiFunction; +import java.util.function.Function; + +public class CompatBlockMapCodecUtil { + + @Deprecated + protected static CompatMapCodec of(MapCodec codec) { + return new CompatMapCodec<>(codec); + } + + public static RecordCodecBuilder createSettingsCodec() { + return CompatibleBlockSettings.CODEC.fieldOf("properties").forGetter(CompatBlock::getCompatSettings); + } + + public static CompatMapCodec createCodec(Function blockFromSettings) { + return of(RecordCodecBuilder.mapCodec((instance) -> instance.group(createSettingsCodec()).apply(instance, blockFromSettings))); + } + + public static CompatMapCodec createCodecOfStairsBlock(BiFunction createFunction) { + return of(RecordCodecBuilder.mapCodec((instance) -> instance.group( + BlockState.CODEC.fieldOf("base_state").forGetter(CompatStairsBlock::getBaseBlockState), + CompatibleBlockSettings.CODEC.fieldOf("properties").forGetter(CompatStairsBlock::getCompatSettings) + ).apply(instance, createFunction))); + } + + public static CompatMapCodec createCodecOfSlabBlock(Function createFunction) { + return of(RecordCodecBuilder.mapCodec((instance) -> instance.group( + CompatibleBlockSettings.CODEC.fieldOf("properties").forGetter(CompatSlabBlock::getCompatSettings) + ).apply(instance, createFunction))); + } + + public static CompatMapCodec createCodecOfPillarBlock(Function createFunction) { + return of(RecordCodecBuilder.mapCodec((instance) -> instance.group( + CompatibleBlockSettings.CODEC.fieldOf("properties").forGetter(CompatPillarBlock::getCompatSettings) + ).apply(instance, createFunction))); + } + + public static CompatMapCodec createCodecOfChestBlock(Function createFunction) { + return of(RecordCodecBuilder.mapCodec((instance) -> instance.group( + CompatibleBlockSettings.CODEC.fieldOf("properties").forGetter(CompatChestBlock::getCompatSettings) + ).apply(instance, createFunction))); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/debug/DebugTool.java b/common/src/main/java/net/pitan76/mcpitanlib/debug/DebugTool.java new file mode 100644 index 000000000..55e1cffd3 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/debug/DebugTool.java @@ -0,0 +1,27 @@ +package net.pitan76.mcpitanlib.debug; + +import net.pitan76.mcpitanlib.api.item.v2.CompatibleItemSettings; +import net.pitan76.mcpitanlib.api.item.v2.CompatItem; + +import static net.pitan76.mcpitanlib.MCPitanLib.*; + +/** + * A tool for debugging. + * Example of condition: item instance DebugTool + */ +public class DebugTool extends CompatItem { + + public static CompatibleItemSettings defaultSettings = CompatibleItemSettings.of(compatId("debug_tool")); + + public DebugTool() { + super(defaultSettings); + } + + public static void debug(String message) { + System.out.println(message); + } + + public static void register() { + registry.registerItem(id("debug_tool"), DebugTool::new); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/guilib/GuiRegistry.java b/common/src/main/java/net/pitan76/mcpitanlib/guilib/GuiRegistry.java new file mode 100644 index 000000000..c928bb1f1 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/guilib/GuiRegistry.java @@ -0,0 +1,46 @@ +package net.pitan76.mcpitanlib.guilib; + +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.gui.screen.ingame.ScreenHandlerProvider; +import net.minecraft.screen.ScreenHandler; +import net.minecraft.screen.ScreenHandlerType; +import net.pitan76.mcpitanlib.api.client.registry.CompatRegistryClient; +import net.pitan76.mcpitanlib.api.gui.ExtendedScreenHandlerTypeBuilder; +import net.pitan76.mcpitanlib.api.gui.SimpleScreenHandlerTypeBuilder; +import net.pitan76.mcpitanlib.api.registry.result.SupplierResult; +import net.pitan76.mcpitanlib.api.registry.v2.CompatRegistryV2; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.guilib.api.container.SimpleContainerGui; +import net.pitan76.mcpitanlib.guilib.api.screen.SimpleContainerGuiScreen; + +import java.util.function.Supplier; + +public class GuiRegistry { + public static SupplierResult> register(CompatRegistryV2 registry, CompatIdentifier id, SimpleScreenHandlerTypeBuilder.Factory factory) { + return register(registry, id, new SimpleScreenHandlerTypeBuilder<>(factory)); + } + + public static Supplier> register(CompatRegistryV2 registry, CompatIdentifier id, ScreenHandlerType type) { + return registry.registerScreenHandlerTypeSavingGenerics(id, () -> type); + } + + @Environment(EnvType.CLIENT) + public static > void register(String id, ScreenHandlerType type, CompatRegistryClient.ScreenFactory factory) { + CompatRegistryClient.registerScreen(id, type, factory); + } + + @Environment(EnvType.CLIENT) + public static void registerSimpleContainerGui(String id, ScreenHandlerType type) { + CompatRegistryClient.registerScreen(id, type, SimpleContainerGuiScreen::new); + } + + public static SupplierResult> register(CompatRegistryV2 registry, CompatIdentifier id, SimpleScreenHandlerTypeBuilder builder) { + return registry.registerScreenHandlerType(id, builder); + } + + public static SupplierResult> register(CompatRegistryV2 registry, CompatIdentifier id, ExtendedScreenHandlerTypeBuilder builder) { + return registry.registerScreenHandlerType(id, builder); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/guilib/GuiTextures.java b/common/src/main/java/net/pitan76/mcpitanlib/guilib/GuiTextures.java new file mode 100644 index 000000000..fad6d9331 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/guilib/GuiTextures.java @@ -0,0 +1,9 @@ +package net.pitan76.mcpitanlib.guilib; + +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; + +public class GuiTextures { + public static CompatIdentifier GUI_PARTS = CompatIdentifier.of("mplguilib", "textures/container/gui_parts.png"); + public static CompatIdentifier BASE_FURNACE_BACKGROUND = CompatIdentifier.of("mplguilib", "textures/container/base_furnace.png"); + public static CompatIdentifier BASE_BACKGROUND = CompatIdentifier.of("mplguilib", "textures/container/base.png"); +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/guilib/MGLClientNetworks.java b/common/src/main/java/net/pitan76/mcpitanlib/guilib/MGLClientNetworks.java new file mode 100644 index 000000000..4d9bc3bad --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/guilib/MGLClientNetworks.java @@ -0,0 +1,23 @@ +package net.pitan76.mcpitanlib.guilib; + +import net.pitan76.mcpitanlib.api.network.v2.ClientNetworking; +import net.pitan76.mcpitanlib.guilib.api.container.ExtendedBlockEntityContainerGui; + +import static net.pitan76.mcpitanlib.guilib.api.NetworkDefines.SYNC_GUI_WITH_TILE; + +public class MGLClientNetworks { + + public static boolean isInitialized = false; + + public static void init() { + if (isInitialized) return; + isInitialized = true; + + ClientNetworking.registerReceiver(SYNC_GUI_WITH_TILE, (e) -> { + if (e.player.getCurrentScreenHandler() instanceof ExtendedBlockEntityContainerGui) { + ExtendedBlockEntityContainerGui gui = (ExtendedBlockEntityContainerGui) e.player.getCurrentScreenHandler(); + gui.receiveSync(e.buf); + } + }); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/guilib/MPLGuiLib.java b/common/src/main/java/net/pitan76/mcpitanlib/guilib/MPLGuiLib.java new file mode 100644 index 000000000..f3122c706 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/guilib/MPLGuiLib.java @@ -0,0 +1,31 @@ +package net.pitan76.mcpitanlib.guilib; + +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.api.util.PlatformUtil; + +public class MPLGuiLib { + public static final String MOD_ID = "mplguilib"; + public static final String MOD_NAME = "MPL GuiLib"; + + public static void init() { + if (PlatformUtil.isClient()) + MGLClientNetworks.init(); + } + + // ---- + /** + * @param path The path of the id + * @return The id + */ + public static CompatIdentifier _id(String path) { + return CompatIdentifier.of(MOD_ID, path); + } + + public String getId() { + return MOD_ID; + } + + public String getName() { + return MOD_NAME; + } +} \ No newline at end of file diff --git a/common/src/main/java/net/pitan76/mcpitanlib/guilib/api/IScreenInfo.java b/common/src/main/java/net/pitan76/mcpitanlib/guilib/api/IScreenInfo.java new file mode 100644 index 000000000..2e002e555 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/guilib/api/IScreenInfo.java @@ -0,0 +1,38 @@ +package net.pitan76.mcpitanlib.guilib.api; + +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.guilib.GuiTextures; + +public interface IScreenInfo { + default int getScreenBackgroundWidth() { + return getScreenWidth(); + } + + default int getScreenBackgroundHeight() { + return getScreenHeight(); + } + + int getScreenWidth(); + + int getScreenHeight(); + + default int getScreenX() { + return -1; + } + + default int getScreenY() { + return -1; + } + + default int getScreenTitleX() { + return -1; + } + + default int getScreenTitleY() { + return -1; + } + + default CompatIdentifier getTexture() { + return GuiTextures.BASE_BACKGROUND; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/guilib/api/ISimpleScreenInfo.java b/common/src/main/java/net/pitan76/mcpitanlib/guilib/api/ISimpleScreenInfo.java new file mode 100644 index 000000000..8ff931938 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/guilib/api/ISimpleScreenInfo.java @@ -0,0 +1,14 @@ +package net.pitan76.mcpitanlib.guilib.api; + +public interface ISimpleScreenInfo extends IScreenInfo { + + @Override + default int getScreenWidth() { + return 176; + } + + @Override + default int getScreenHeight() { + return 166; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/guilib/api/NetworkDefines.java b/common/src/main/java/net/pitan76/mcpitanlib/guilib/api/NetworkDefines.java new file mode 100644 index 000000000..c0631c9ec --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/guilib/api/NetworkDefines.java @@ -0,0 +1,8 @@ +package net.pitan76.mcpitanlib.guilib.api; + +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.guilib.MPLGuiLib; + +public class NetworkDefines { + public static CompatIdentifier SYNC_GUI_WITH_TILE = MPLGuiLib._id("sync_gui_with_tile"); +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/guilib/api/block/entity/BlockEntityWithContainer.java b/common/src/main/java/net/pitan76/mcpitanlib/guilib/api/block/entity/BlockEntityWithContainer.java new file mode 100644 index 000000000..f6e88a29e --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/guilib/api/block/entity/BlockEntityWithContainer.java @@ -0,0 +1,40 @@ +package net.pitan76.mcpitanlib.guilib.api.block.entity; + +import net.minecraft.block.entity.BlockEntityType; +import net.pitan76.mcpitanlib.api.event.block.TileCreateEvent; +import net.pitan76.mcpitanlib.api.event.nbt.ReadNbtArgs; +import net.pitan76.mcpitanlib.api.event.nbt.WriteNbtArgs; +import net.pitan76.mcpitanlib.api.gui.inventory.IInventory; +import net.pitan76.mcpitanlib.api.gui.inventory.sided.ChestStyleSidedInventory; +import net.pitan76.mcpitanlib.api.tile.CompatBlockEntity; +import net.pitan76.mcpitanlib.api.util.InventoryUtil; +import net.pitan76.mcpitanlib.api.util.ItemStackUtil; +import net.pitan76.mcpitanlib.api.util.collection.ItemStackList; + +public abstract class BlockEntityWithContainer extends CompatBlockEntity implements IInventory, ChestStyleSidedInventory { + + private final ItemStackList inventory = ItemStackList.ofSize(getDefaultInvSize(), ItemStackUtil.empty()); + + public BlockEntityWithContainer(BlockEntityType type, TileCreateEvent e) { + super(type, e); + } + + public abstract int getDefaultInvSize(); + + @Override + public void writeNbt(WriteNbtArgs args) { + super.writeNbt(args); + InventoryUtil.writeNbt(args, inventory); + } + + @Override + public void readNbt(ReadNbtArgs args) { + super.readNbt(args); + InventoryUtil.readNbt(args, inventory); + } + + @Override + public ItemStackList getItems() { + return inventory; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/guilib/api/block/entity/ExtendedBlockEntityWithContainer.java b/common/src/main/java/net/pitan76/mcpitanlib/guilib/api/block/entity/ExtendedBlockEntityWithContainer.java new file mode 100644 index 000000000..dfa884739 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/guilib/api/block/entity/ExtendedBlockEntityWithContainer.java @@ -0,0 +1,59 @@ +package net.pitan76.mcpitanlib.guilib.api.block.entity; + +import net.minecraft.block.entity.BlockEntityType; +import net.minecraft.network.PacketByteBuf; +import net.minecraft.text.Text; +import net.pitan76.mcpitanlib.api.entity.Player; +import net.pitan76.mcpitanlib.api.event.block.TileCreateEvent; +import net.pitan76.mcpitanlib.api.event.container.factory.DisplayNameArgs; +import net.pitan76.mcpitanlib.api.event.container.factory.ExtraDataArgs; +import net.pitan76.mcpitanlib.api.event.tile.TileTickEvent; +import net.pitan76.mcpitanlib.api.gui.v2.ExtendedScreenHandlerFactory; +import net.pitan76.mcpitanlib.api.network.PacketByteUtil; +import net.pitan76.mcpitanlib.api.network.v2.ServerNetworking; +import net.pitan76.mcpitanlib.api.tile.ExtendBlockEntityTicker; +import net.pitan76.mcpitanlib.api.util.TextUtil; +import net.pitan76.mcpitanlib.api.util.WorldUtil; +import net.pitan76.mcpitanlib.guilib.api.container.ExtendedBlockEntityContainerGui; + +import java.util.List; +import java.util.Objects; + +import static net.pitan76.mcpitanlib.guilib.api.NetworkDefines.SYNC_GUI_WITH_TILE; + +public abstract class ExtendedBlockEntityWithContainer extends BlockEntityWithContainer implements ExtendedScreenHandlerFactory, ExtendBlockEntityTicker { + + public ExtendedBlockEntityWithContainer(BlockEntityType type, TileCreateEvent e) { + super(type, e); + } + + @Override + public void tick(TileTickEvent e) { + if (isClient()) return; + + List players = WorldUtil.getPlayers(Objects.requireNonNull(getWorld())); + for (Player player : players) { + if (player.hasNetworkHandler() && player.getCurrentScreenHandler() instanceof ExtendedBlockEntityContainerGui && ((ExtendedBlockEntityContainerGui) player.getCurrentScreenHandler()).blockEntity == this ) { + PacketByteBuf buf = PacketByteUtil.create(); + sync(player, buf); + ServerNetworking.send(player, SYNC_GUI_WITH_TILE, buf); + } + } + } + + @Override + public Text getDisplayName(DisplayNameArgs args) { + if (getCachedState() == null) + return TextUtil.of("unknown"); + + return getCachedState().getBlock().getName(); + } + + @Override + public void writeExtraData(ExtraDataArgs args) { + PacketByteUtil.writeBlockPos(args.buf, getPos()); + sync(args.getCompatPlayer(), args.buf); + } + + public abstract void sync(Player player, PacketByteBuf buf); +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/guilib/api/container/BlockEntityContainerGui.java b/common/src/main/java/net/pitan76/mcpitanlib/guilib/api/container/BlockEntityContainerGui.java new file mode 100644 index 000000000..54445322c --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/guilib/api/container/BlockEntityContainerGui.java @@ -0,0 +1,11 @@ +package net.pitan76.mcpitanlib.guilib.api.container; + +import net.minecraft.screen.ScreenHandlerType; +import net.pitan76.mcpitanlib.api.gui.args.CreateMenuEvent; +import net.pitan76.mcpitanlib.guilib.api.ISimpleScreenInfo; + +public abstract class BlockEntityContainerGui extends ContainerGui implements ISimpleScreenInfo { + protected BlockEntityContainerGui(ScreenHandlerType type, CreateMenuEvent e) { + super(type, e); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/guilib/api/container/ContainerGui.java b/common/src/main/java/net/pitan76/mcpitanlib/guilib/api/container/ContainerGui.java new file mode 100644 index 000000000..04dcc52b3 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/guilib/api/container/ContainerGui.java @@ -0,0 +1,66 @@ +package net.pitan76.mcpitanlib.guilib.api.container; + +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.inventory.Inventory; +import net.minecraft.screen.ScreenHandlerType; +import net.minecraft.screen.slot.Slot; +import net.pitan76.mcpitanlib.api.entity.Player; +import net.pitan76.mcpitanlib.api.gui.SimpleScreenHandler; +import net.pitan76.mcpitanlib.api.gui.args.CreateMenuEvent; +import net.pitan76.mcpitanlib.guilib.api.IScreenInfo; + +import java.util.ArrayList; +import java.util.List; + +public abstract class ContainerGui extends SimpleScreenHandler implements IScreenInfo { + + private final List INVENTORIES = new ArrayList<>(); + + protected ContainerGui(ScreenHandlerType type, int syncId) { + super(type, syncId); + } + + protected ContainerGui(ScreenHandlerType type, CreateMenuEvent e) { + super(type, e); + } + + @Override + public boolean canUse(Player player) { + return true; + } + + @Override + protected Slot addSlot(Slot slot) { + if (slot.inventory instanceof Inventory && !INVENTORIES.contains(slot.inventory)) + INVENTORIES.add(slot.inventory); + + return super.addSlot(slot); + } + + public int playerMainInventoryX = 8; + public int playerMainInventoryY = 84; + + public int playerHotbarX = 8; + public int playerHotbarY = 142; + + @Override + protected List addPlayerMainInventorySlots(PlayerInventory inventory, int x, int y) { + playerMainInventoryX = x; + playerMainInventoryY = y; + + return super.addPlayerMainInventorySlots(inventory, x, y); + } + + @Override + protected List addPlayerHotbarSlots(PlayerInventory inventory, int x, int y) { + playerHotbarX = x; + playerHotbarY = y; + + return super.addPlayerHotbarSlots(inventory, x, y); + } + + @Override + public void close(Player player) { + INVENTORIES.forEach((inv -> inv.onClose(player.getEntity()))); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/guilib/api/container/ExtendedBlockEntityContainerGui.java b/common/src/main/java/net/pitan76/mcpitanlib/guilib/api/container/ExtendedBlockEntityContainerGui.java new file mode 100644 index 000000000..496c046c6 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/guilib/api/container/ExtendedBlockEntityContainerGui.java @@ -0,0 +1,39 @@ +package net.pitan76.mcpitanlib.guilib.api.container; + +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.network.PacketByteBuf; +import net.minecraft.screen.ScreenHandlerType; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.entity.Player; +import net.pitan76.mcpitanlib.api.gui.args.CreateMenuEvent; +import net.pitan76.mcpitanlib.api.tile.CompatBlockEntity; +import net.pitan76.mcpitanlib.api.util.WorldUtil; +import net.pitan76.mcpitanlib.guilib.api.ISimpleScreenInfo; + +public abstract class ExtendedBlockEntityContainerGui extends BlockEntityContainerGui implements ISimpleScreenInfo { + + public T blockEntity; + + public ExtendedBlockEntityContainerGui(ScreenHandlerType type, CreateMenuEvent e, PacketByteBuf buf) { + this(type, e); + + if (buf == null) return; + + Player player = e.getPlayer(); + World world = player.getWorld(); + BlockPos pos = buf.readBlockPos(); + + BlockEntity blockEntity = WorldUtil.getBlockEntity(world, pos); + if (blockEntity instanceof CompatBlockEntity) + this.blockEntity = (T) blockEntity; + + receiveSync(buf); + } + + protected ExtendedBlockEntityContainerGui(ScreenHandlerType type, CreateMenuEvent e) { + super(type, e); + } + + public abstract void receiveSync(PacketByteBuf buf); +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/guilib/api/container/SimpleContainerGui.java b/common/src/main/java/net/pitan76/mcpitanlib/guilib/api/container/SimpleContainerGui.java new file mode 100644 index 000000000..46e5fb903 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/guilib/api/container/SimpleContainerGui.java @@ -0,0 +1,16 @@ +package net.pitan76.mcpitanlib.guilib.api.container; + +import net.minecraft.screen.ScreenHandlerType; +import net.pitan76.mcpitanlib.api.gui.args.CreateMenuEvent; +import net.pitan76.mcpitanlib.guilib.api.ISimpleScreenInfo; + +public abstract class SimpleContainerGui extends ContainerGui implements ISimpleScreenInfo { + + protected SimpleContainerGui(ScreenHandlerType type, int syncId) { + super(type, syncId); + } + + protected SimpleContainerGui(ScreenHandlerType type, CreateMenuEvent e) { + super(type, e); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/guilib/api/render/PartsRenderer.java b/common/src/main/java/net/pitan76/mcpitanlib/guilib/api/render/PartsRenderer.java new file mode 100644 index 000000000..facc1262a --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/guilib/api/render/PartsRenderer.java @@ -0,0 +1,72 @@ +package net.pitan76.mcpitanlib.guilib.api.render; + +import net.pitan76.mcpitanlib.api.client.render.DrawObjectDM; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.api.util.client.RenderUtil.RendererUtil; +import net.pitan76.mcpitanlib.guilib.GuiTextures; + +public class PartsRenderer { + public static void drawBottom2TopProgressBar(DrawObjectDM drawObjectDM, int x, int y, int u, int v, int u2, int v2, int width, int height, int percentage, CompatIdentifier texture) { + RendererUtil.drawTexture(drawObjectDM, texture, x, y, u, v, width, height); + + if (percentage > 0) { + int progress = (int) ((double) percentage / 100 * height); + RendererUtil.drawTexture(drawObjectDM, texture, x, y + height - progress, u2, v2 + height - progress, width, progress); + } + } + + public static void drawBottom2TopProgressBar(DrawObjectDM drawObjectDM, int x, int y, int u1, int v1, int u2, int v2, int width, int height, double value, double maxValue, CompatIdentifier texture) { + int percentage = (maxValue != 0) ? (int) (value / maxValue * 100) : 0; + drawBottom2TopProgressBar(drawObjectDM, x, y, u1, v1, u2, v2, width, height, percentage, texture); + } + + public static void drawTop2BottomProgressBar(DrawObjectDM drawObjectDM, int x, int y, int u, int v, int u2, int v2, int width, int height, int percentage, CompatIdentifier texture) { + RendererUtil.drawTexture(drawObjectDM, texture, x, y, u, v, width, height); + + if (percentage > 0) { + int progress = (int) ((double) percentage / 100 * height); + RendererUtil.drawTexture(drawObjectDM, texture, x, y, u2, v2, width, progress); + } + } + + public static void drawTop2BottomProgressBar(DrawObjectDM drawObjectDM, int x, int y, int u1, int v1, int u2, int v2, int width, int height, double value, double maxValue, CompatIdentifier texture) { + int percentage = (maxValue != 0) ? (int) (value / maxValue * 100) : 0; + drawTop2BottomProgressBar(drawObjectDM, x, y, u1, v1, u2, v2, width, height, percentage, texture); + } + + public static void drawLeft2RightProgressBar(DrawObjectDM drawObjectDM, int x, int y, int u, int v, int u2, int v2, int width, int height, int percentage, CompatIdentifier texture) { + RendererUtil.drawTexture(drawObjectDM, texture, x, y, u, v, width, height); + + if (percentage > 0) { + int progress = (int) ((double) percentage / 100 * width); + RendererUtil.drawTexture(drawObjectDM, texture, x, y, u2, v2, progress, height); + } + } + + public static void drawLeft2RightProgressBar(DrawObjectDM drawObjectDM, int x, int y, int u1, int v1, int u2, int v2, int width, int height, double value, double maxValue, CompatIdentifier texture) { + int percentage = (maxValue != 0) ? (int) (value / maxValue * 100) : 0; + drawLeft2RightProgressBar(drawObjectDM, x, y, u1, v1, u2, v2, width, height, percentage, texture); + } + + public static void drawRight2LeftProgressBar(DrawObjectDM drawObjectDM, int x, int y, int u, int v, int u2, int v2, int width, int height, int percentage, CompatIdentifier texture) { + RendererUtil.drawTexture(drawObjectDM, texture, x, y, u, v, width, height); + + if (percentage > 0) { + int progress = (int) ((double) percentage / 100 * width); + RendererUtil.drawTexture(drawObjectDM, texture, x + width - progress, y, u2 + width - progress, v2, progress, height); + } + } + + public static void drawRight2LeftProgressBar(DrawObjectDM drawObjectDM, int x, int y, int u1, int v1, int u2, int v2, int width, int height, double value, double maxValue, CompatIdentifier texture) { + int percentage = (maxValue != 0) ? (int) (value / maxValue * 100) : 0; + drawRight2LeftProgressBar(drawObjectDM, x, y, u1, v1, u2, v2, width, height, percentage, texture); + } + + public static void drawBurningBar(DrawObjectDM drawObjectDM, int x, int y, int burnTime, int maxBurnTime) { + drawBottom2TopProgressBar(drawObjectDM, x, y, 0, 168, 0, 184, 16, 14, burnTime, maxBurnTime, GuiTextures.BASE_FURNACE_BACKGROUND); + } + + public static void drawHorizontalArrowBar(DrawObjectDM drawObjectDM, int x, int y, double value, double maxValue) { + drawLeft2RightProgressBar(drawObjectDM, x, y, 0, 168, 16, 184, 24, 16, value, maxValue, GuiTextures.BASE_FURNACE_BACKGROUND); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/guilib/api/render/SlotRenderer.java b/common/src/main/java/net/pitan76/mcpitanlib/guilib/api/render/SlotRenderer.java new file mode 100644 index 000000000..0c23c9e94 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/guilib/api/render/SlotRenderer.java @@ -0,0 +1,27 @@ +package net.pitan76.mcpitanlib.guilib.api.render; + +import net.minecraft.screen.ScreenHandler; +import net.minecraft.screen.slot.Slot; +import net.pitan76.mcpitanlib.api.client.render.DrawObjectDM; +import net.pitan76.mcpitanlib.api.util.ScreenHandlerUtil; +import net.pitan76.mcpitanlib.api.util.client.ScreenUtil.RendererUtil; +import net.pitan76.mcpitanlib.guilib.GuiTextures; + +public class SlotRenderer { + + public static void drawSlot(DrawObjectDM drawObjectDM, Slot slot, int x, int y) { + RendererUtil.drawTexture(drawObjectDM, GuiTextures.GUI_PARTS, x + slot.x - 1, y + slot.y - 1, 0, 0, 18, 18); + } + + public static void drawSlots(DrawObjectDM drawObjectDM, ScreenHandler handler, int x, int y) { + ScreenHandlerUtil.getSlots(handler).forEach((slot) -> drawSlot(drawObjectDM, slot, x, y)); + } + + public static void drawPlayerMainInventorySlots(DrawObjectDM drawObjectDM, ScreenHandler handler, int x, int y) { + RendererUtil.drawTexture(drawObjectDM, GuiTextures.GUI_PARTS, x, y, 0, 32, 162, 54); + } + + public static void drawPlayerHotbarSlots(DrawObjectDM drawObjectDM, ScreenHandler handler, int x, int y) { + RendererUtil.drawTexture(drawObjectDM, GuiTextures.GUI_PARTS, x, y, 0, 90, 162, 18); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/guilib/api/screen/ContainerGuiScreen.java b/common/src/main/java/net/pitan76/mcpitanlib/guilib/api/screen/ContainerGuiScreen.java new file mode 100644 index 000000000..70b6158eb --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/guilib/api/screen/ContainerGuiScreen.java @@ -0,0 +1,86 @@ +package net.pitan76.mcpitanlib.guilib.api.screen; + +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.text.Text; +import net.pitan76.mcpitanlib.api.client.gui.screen.CompatInventoryScreen; +import net.pitan76.mcpitanlib.api.client.render.DrawObjectDM; +import net.pitan76.mcpitanlib.api.client.render.handledscreen.DrawBackgroundArgs; +import net.pitan76.mcpitanlib.api.client.render.handledscreen.DrawForegroundArgs; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.api.util.ScreenHandlerUtil; +import net.pitan76.mcpitanlib.guilib.GuiTextures; +import net.pitan76.mcpitanlib.guilib.api.container.ContainerGui; +import net.pitan76.mcpitanlib.guilib.api.render.SlotRenderer; + +public class ContainerGuiScreen extends CompatInventoryScreen { + public ContainerGuiScreen(T handler, PlayerInventory inventory, Text title) { + super(handler, inventory, title); + setBackgroundWidth(handler.getScreenBackgroundWidth()); + setBackgroundHeight(handler.getScreenBackgroundHeight()); + + if (handler.getScreenX() != -1) + setX(handler.getScreenX()); + if (handler.getScreenY() != -1) + setY(handler.getScreenY()); + + if (handler.getScreenTitleX() != -1) + setTitleX(handler.getScreenTitleX()); + if (handler.getScreenTitleY() != -1) + setTitleY(handler.getScreenTitleY()); + } + + @Override + public void initOverride() { + super.initOverride(); + } + + @Override + public void drawBackgroundOverride(DrawBackgroundArgs args) { + super.drawBackgroundOverride(args); + + if (handler.hasMainInventory && !containPlayerInventoryInBackground()) + drawPlayerMainInventorySlots(args.drawObjectDM); + + if (handler.hasHotbar && !containPlayerInventoryInBackground()) + drawPlayerHotbarSlots(args.drawObjectDM); + + drawSlots(args.drawObjectDM); + } + + @Override + protected void drawForegroundOverride(DrawForegroundArgs args) { + if (!handler.hasMainInventory && !containPlayerInventoryInBackground()) { + drawText(args.drawObjectDM, title, titleX, titleY); + return; + } + + super.drawForegroundOverride(args); + } + + @Override + public CompatIdentifier getCompatTexture() { + return handler.getTexture(); + } + + public void drawPlayerMainInventorySlots(DrawObjectDM drawObjectDM) { + SlotRenderer.drawPlayerMainInventorySlots(drawObjectDM, handler, x + handler.playerMainInventoryX - 1, y + handler.playerMainInventoryY - 1); + } + + public void drawPlayerHotbarSlots(DrawObjectDM drawObjectDM) { + SlotRenderer.drawPlayerHotbarSlots(drawObjectDM, handler, x + handler.playerHotbarX - 1, y + handler.playerHotbarY - 1); + } + + public boolean containPlayerInventoryInBackground() { + return getCompatTexture() == GuiTextures.BASE_FURNACE_BACKGROUND; + } + + @Override + public void drawSlots(DrawObjectDM drawObjectDM) { + ScreenHandlerUtil.getSlots(handler).forEach((slot) -> { + if (slot.inventory instanceof PlayerInventory || containPlayerInventoryInBackground()) + return; + + SlotRenderer.drawSlot(drawObjectDM, slot, x, y); + }); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/guilib/api/screen/SimpleContainerGuiScreen.java b/common/src/main/java/net/pitan76/mcpitanlib/guilib/api/screen/SimpleContainerGuiScreen.java new file mode 100644 index 000000000..3ac5ebed4 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/guilib/api/screen/SimpleContainerGuiScreen.java @@ -0,0 +1,16 @@ +package net.pitan76.mcpitanlib.guilib.api.screen; + +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.text.Text; +import net.pitan76.mcpitanlib.guilib.api.container.SimpleContainerGui; + +public class SimpleContainerGuiScreen extends ContainerGuiScreen { + public SimpleContainerGuiScreen(SimpleContainerGui handler, PlayerInventory inventory, Text title) { + super(handler, inventory, title); + } + + @Override + public void initOverride() { + super.initOverride(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/guilib/test/TestContainer.java b/common/src/main/java/net/pitan76/mcpitanlib/guilib/test/TestContainer.java new file mode 100644 index 000000000..f1ce318d4 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/guilib/test/TestContainer.java @@ -0,0 +1,55 @@ +package net.pitan76.mcpitanlib.guilib.test; + +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.screen.ScreenHandlerType; +import net.pitan76.mcpitanlib.guilib.api.container.ContainerGui; + +public class TestContainer extends ContainerGui { + public TestContainer(ScreenHandlerType type, int syncId) { + super(type, syncId); + } + + public TestContainer(int i, PlayerInventory inventory) { + this(null, i); + } + + @Override + public int getScreenBackgroundWidth() { + return 176; + } + + @Override + public int getScreenBackgroundHeight() { + return 166; + } + + @Override + public int getScreenWidth() { + return 176; + } + + @Override + public int getScreenHeight() { + return 166; + } + + @Override + public int getScreenX() { + return 0; + } + + @Override + public int getScreenY() { + return 0; + } + + @Override + public int getScreenTitleX() { + return 0; + } + + @Override + public int getScreenTitleY() { + return 0; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/Midohra.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/Midohra.java new file mode 100644 index 000000000..ba5f4535e --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/Midohra.java @@ -0,0 +1,160 @@ +package net.pitan76.mcpitanlib.midohra; + +import net.minecraft.block.Block; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.item.Item; +import net.minecraft.item.ItemGroup; +import net.pitan76.mcpitanlib.api.registry.result.RegistryResult; +import net.pitan76.mcpitanlib.midohra.block.BlockState; +import net.pitan76.mcpitanlib.midohra.block.BlockWrapper; +import net.pitan76.mcpitanlib.midohra.block.SupplierBlockWrapper; +import net.pitan76.mcpitanlib.midohra.block.entity.BlockEntityWrapper; +import net.pitan76.mcpitanlib.midohra.fluid.FluidWrapper; +import net.pitan76.mcpitanlib.midohra.item.ItemGroupWrapper; +import net.pitan76.mcpitanlib.midohra.item.ItemWrapper; +import net.pitan76.mcpitanlib.midohra.nbt.NbtCompound; +import net.pitan76.mcpitanlib.midohra.nbt.NbtElement; +import net.pitan76.mcpitanlib.midohra.nbt.NbtList; +import net.pitan76.mcpitanlib.midohra.util.math.BlockPos; +import net.pitan76.mcpitanlib.midohra.util.math.Direction; +import net.pitan76.mcpitanlib.midohra.world.*; + +import java.util.function.Supplier; + +public class Midohra { + + public static ItemWrapper of(Item item) { + return ItemWrapper.of(item); + } + + public static ItemGroupWrapper of(ItemGroup itemGroup) { + return ItemGroupWrapper.of(itemGroup); + } + public static BlockWrapper of(Block block) { + return BlockWrapper.of(block); + } + + public static SupplierBlockWrapper of(Supplier block) { + return SupplierBlockWrapper.of(block); + } + + public static SupplierBlockWrapper of(RegistryResult block) { + return SupplierBlockWrapper.of(block); + } + + public static BlockEntityWrapper of(BlockEntity blockEntity) { + return BlockEntityWrapper.of(blockEntity); + } + + public static FluidWrapper of(net.minecraft.fluid.Fluid fluid) { + return FluidWrapper.of(fluid); + } + + public static BlockState of(net.minecraft.block.BlockState state) { + return BlockState.of(state); + } + + public static NbtElement of(net.minecraft.nbt.NbtElement nbt) { + return NbtElement.of(nbt); + } + + public static NbtCompound of(net.minecraft.nbt.NbtCompound nbt) { + return NbtCompound.of(nbt); + } + + public static NbtList of(net.minecraft.nbt.NbtList nbt) { + return NbtList.of(nbt); + } + + public static BlockPos of(net.minecraft.util.math.BlockPos pos) { + return BlockPos.of(pos); + } + + public static Direction of(net.minecraft.util.math.Direction direction) { + return Direction.of(direction); + } + + public static World of(net.minecraft.world.World world) { + return World.of(world); + } + + public static WorldView of(net.minecraft.world.WorldView world) { + return WorldView.of(world); + } + + public static WorldAccess of(net.minecraft.world.WorldAccess world) { + return WorldAccess.of(world); + } + + public static BlockView of(net.minecraft.world.BlockView world) { + return BlockView.of(world); + } + + public static IWorldView asWV(net.minecraft.world.WorldView world) { + return of(world); + } + + public static IWorldView asWV(net.minecraft.world.BlockView world) { + return of(world); + } + + public static Item raw(ItemWrapper item) { + return item.get(); + } + + public static ItemGroup raw(ItemGroupWrapper itemGroup) { + return itemGroup.get(); + } + + public static Block raw(BlockWrapper block) { + return block.get(); + } + + public static BlockEntity raw(BlockEntityWrapper blockEntity) { + return blockEntity.get(); + } + + public static net.minecraft.fluid.Fluid raw(FluidWrapper fluid) { + return fluid.get(); + } + + public static net.minecraft.block.BlockState raw(BlockState state) { + return state.toMinecraft(); + } + + public static net.minecraft.nbt.NbtElement raw(NbtElement nbt) { + return nbt.toMinecraft(); + } + + public static net.minecraft.nbt.NbtCompound raw(NbtCompound nbt) { + return nbt.toMinecraft(); + } + + public static net.minecraft.nbt.NbtList raw(NbtList nbt) { + return nbt.toMinecraft(); + } + + public static net.minecraft.util.math.BlockPos raw(BlockPos pos) { + return pos.toMinecraft(); + } + + public static net.minecraft.util.math.Direction raw(Direction direction) { + return direction.toMinecraft(); + } + + public static net.minecraft.world.World raw(World world) { + return world.toMinecraft(); + } + + public static net.minecraft.world.WorldView raw(WorldView world) { + return world.toMinecraft(); + } + + public static net.minecraft.world.WorldAccess raw(WorldAccess world) { + return world.toMinecraft(); + } + + public static net.minecraft.world.BlockView raw(BlockView world) { + return world.toMinecraft(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/MidohraAPI.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/MidohraAPI.java new file mode 100644 index 000000000..d27730312 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/MidohraAPI.java @@ -0,0 +1,13 @@ +package net.pitan76.mcpitanlib.midohra; + +/** + * MidohraAPI + * Experimental API of MCPitanLib + * + * @author Pitan + * @version 0.0.1 + * @since 2024.09.28 + */ +public class MidohraAPI { + +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/BlockState.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/BlockState.java new file mode 100644 index 000000000..7d6d9d0f3 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/BlockState.java @@ -0,0 +1,134 @@ +package net.pitan76.mcpitanlib.midohra.block; + +import net.minecraft.state.property.Property; +import net.pitan76.mcpitanlib.api.sound.CompatBlockSoundGroup; +import net.pitan76.mcpitanlib.api.state.property.DirectionProperty; +import net.pitan76.mcpitanlib.api.state.property.IProperty; +import net.pitan76.mcpitanlib.api.util.BlockStateUtil; +import net.pitan76.mcpitanlib.midohra.util.math.BlockPos; +import net.pitan76.mcpitanlib.midohra.world.World; + +public class BlockState { + private final net.minecraft.block.BlockState state; + + private BlockWrapper blockWrapper; + + protected BlockState(net.minecraft.block.BlockState state) { + this.state = state; + } + + public static BlockState of(net.minecraft.block.BlockState state) { + return new BlockState(state); + } + + public static BlockState of(net.minecraft.block.Block block) { + if (block == null) + return of((net.minecraft.block.BlockState) null); + + return of(BlockStateUtil.getDefaultState(block)); + } + + public boolean isExist() { + return !isEmpty(); + } + + public boolean isEmpty() { + return toMinecraft() == null; + } + + public boolean isAir() { + return isEmpty() || BlockStateUtil.isAir(toMinecraft()); + } + + public CompatBlockSoundGroup getSoundGroup() { + return BlockStateUtil.getCompatSoundGroup(toMinecraft()); + } + + public BlockWrapper getBlock() { + if (blockWrapper == null) + blockWrapper = BlockWrapper.of(BlockStateUtil.getBlock(toMinecraft())); + + return blockWrapper; + } + + public String getName() { + return getBlock().getName(); + } + + public net.minecraft.block.BlockState toMinecraft() { + return state; + } + + public , V extends T> BlockState with(Property property, V value) { + return of(toMinecraft().with(property, value)); + } + + public , V extends T> BlockState with(IProperty property, V value) { + return with(property.getProperty(), value); + } + + public BlockState with(DirectionProperty property, net.pitan76.mcpitanlib.midohra.util.math.Direction value) { + return of(property.with(toMinecraft(), value.toMinecraft())); + } + + public > BlockState cycle(Property property) { + return of(toMinecraft().cycle(property)); + } + + public > BlockState cycle(IProperty property) { + return cycle(property.getProperty()); + } + + public BlockState cycle(DirectionProperty property) { + return of(property.cycle(toMinecraft())); + } + + public > T get(Property property) { + return toMinecraft().get(property); + } + + public > T get(IProperty property) { + return get(property.getProperty()); + } + + public net.pitan76.mcpitanlib.midohra.util.math.Direction get(DirectionProperty property) { + return net.pitan76.mcpitanlib.midohra.util.math.Direction.of(get(property.getProperty())); + } + + public > boolean contains(Property property) { + return toMinecraft().contains(property); + } + + public > boolean contains(IProperty property) { + return contains(property.getProperty()); + } + + public boolean contains(DirectionProperty property) { + return contains(property.getProperty()); + } + + @Override + public int hashCode() { + return toMinecraft().hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + BlockState state = (BlockState) obj; + return toMinecraft().equals(state.toMinecraft()); + } + + public boolean isOpaque() { + return BlockStateUtil.isOpaque(toMinecraft()); + } + + public boolean hasRandomTicks() { + return BlockStateUtil.hasRandomTicks(toMinecraft()); + } + + public boolean canPlaceAt(BlockPos pos, World world) { + return BlockStateUtil.canPlaceAt(this, pos, world); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/BlockWrapper.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/BlockWrapper.java new file mode 100644 index 000000000..9b0a7b54a --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/BlockWrapper.java @@ -0,0 +1,106 @@ +package net.pitan76.mcpitanlib.midohra.block; + +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.api.util.block.BlockUtil; +import net.pitan76.mcpitanlib.midohra.item.ItemWrapper; +import org.jetbrains.annotations.Nullable; + +public class BlockWrapper { + private final net.minecraft.block.Block block; + + protected BlockWrapper() { + this.block = null; + } + + protected BlockWrapper(net.minecraft.block.Block block) { + this.block = block; + } + + public static BlockWrapper of(net.minecraft.block.Block block) { + return new BlockWrapper(block); + } + + public static BlockWrapper of() { + return new BlockWrapper(); + } + + public static BlockWrapper of(CompatIdentifier id) { + if (BlockUtil.isExist(id)) + return of(BlockUtil.fromId(id)); + + return of(); + } + + public static BlockWrapper of(CompatIdentifier id, CompatIdentifier... ids) { + if (of(id).isPresent()) return of(id); + + for (CompatIdentifier id1 : ids) { + if (of(id1).isPresent()) + return of(id1); + } + + return of(); + } + + public boolean isPresent() { + return !isEmpty(); + } + + public boolean isEmpty() { + return get() == null; + } + + @Nullable + public net.minecraft.block.Block get() { + return block; + } + + public net.minecraft.block.Block gerOrDefault(net.minecraft.block.Block defaultItem) { + return isEmpty() ? defaultItem : get(); + } + + public CompatIdentifier getId() { + if (isEmpty()) + return CompatIdentifier.empty(); + + return BlockUtil.toId(get()); + } + + public String getName() { + if (isEmpty()) return ""; + return BlockUtil.getNameAsString(get()); + } + + public String getTranslationKey() { + if (isEmpty()) return ""; + return BlockUtil.getTranslationKey(get()); + } + + public ItemWrapper asItem() { + if (isEmpty()) + return ItemWrapper.of(); + + return ItemWrapper.of(BlockUtil.toItem(get())); + } + + public BlockState getDefaultState() { + return BlockState.of(get()); + } + + public boolean rawEquals(BlockWrapper block) { + return get() == block.get(); + } + + @Override + public int hashCode() { + return get() != null ? get().hashCode() : 0; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + BlockWrapper other = (BlockWrapper) obj; + return rawEquals(other); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/SupplierBlockWrapper.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/SupplierBlockWrapper.java new file mode 100644 index 000000000..ba604f61b --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/SupplierBlockWrapper.java @@ -0,0 +1,27 @@ +package net.pitan76.mcpitanlib.midohra.block; + +import net.minecraft.block.Block; +import net.pitan76.mcpitanlib.api.registry.result.RegistryResult; + +import java.util.function.Supplier; + +public class SupplierBlockWrapper extends BlockWrapper { + private final Supplier supplier; + + protected SupplierBlockWrapper(Supplier supplier) { + this.supplier = supplier; + } + + public static SupplierBlockWrapper of(Supplier supplier) { + return new SupplierBlockWrapper(supplier); + } + + public static SupplierBlockWrapper of(RegistryResult result) { + return new SupplierBlockWrapper(result::get); + } + + @Override + public Block get() { + return supplier.get(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/entity/BlockEntityTypeWrapper.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/entity/BlockEntityTypeWrapper.java new file mode 100644 index 000000000..0a066a984 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/entity/BlockEntityTypeWrapper.java @@ -0,0 +1,58 @@ +package net.pitan76.mcpitanlib.midohra.block.entity; + +import net.pitan76.mcpitanlib.api.event.block.TileCreateEvent; +import net.pitan76.mcpitanlib.midohra.block.BlockState; +import net.pitan76.mcpitanlib.midohra.util.math.BlockPos; +import net.pitan76.mcpitanlib.midohra.world.BlockView; + +public class BlockEntityTypeWrapper { + private final net.minecraft.block.entity.BlockEntityType type; + + public static final BlockEntityTypeWrapper EMPTY = new BlockEntityTypeWrapper(); + + protected BlockEntityTypeWrapper() { + this.type = null; + } + + protected BlockEntityTypeWrapper(net.minecraft.block.entity.BlockEntityType blockEntity) { + this.type = blockEntity; + } + + public static BlockEntityTypeWrapper of(net.minecraft.block.entity.BlockEntityType blockEntity) { + return new BlockEntityTypeWrapper(blockEntity); + } + + public static BlockEntityTypeWrapper of() { + return EMPTY; + } + + public net.minecraft.block.entity.BlockEntityType get() { + return type; + } + + public boolean isEmpty() { + return get() == null; + } + + public boolean isPresent() { + return get() != null; + } + + public boolean supports(BlockState state) { + return isPresent() && get().supports(state.toMinecraft()); + } + + public BlockEntityWrapper getBlockEntity(BlockView world, BlockPos pos) { + if (isEmpty()) + return BlockEntityWrapper.EMPTY; + + return SupplierBlockEntityWrapper.of(get().get(world.getRaw(), pos.toMinecraft())); + } + + public BlockEntityWrapper createBlockEntity(TileCreateEvent e) { + if (isEmpty()) + return BlockEntityWrapper.EMPTY; + + return SupplierBlockEntityWrapper.of(get().instantiate(e.getBlockPos(), e.getBlockState())); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/entity/BlockEntityWrapper.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/entity/BlockEntityWrapper.java new file mode 100644 index 000000000..5b3ab35a0 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/entity/BlockEntityWrapper.java @@ -0,0 +1,97 @@ +package net.pitan76.mcpitanlib.midohra.block.entity; + +import net.pitan76.mcpitanlib.api.registry.CompatRegistryLookup; +import net.pitan76.mcpitanlib.api.util.BlockEntityUtil; +import net.pitan76.mcpitanlib.api.util.RegistryLookupUtil; +import net.pitan76.mcpitanlib.midohra.block.BlockState; +import net.pitan76.mcpitanlib.midohra.block.BlockWrapper; +import net.pitan76.mcpitanlib.midohra.nbt.NbtCompound; +import net.pitan76.mcpitanlib.midohra.util.math.BlockPos; +import net.pitan76.mcpitanlib.midohra.world.World; + +public class BlockEntityWrapper { + private final net.minecraft.block.entity.BlockEntity blockEntity; + + public static final BlockEntityWrapper EMPTY = new BlockEntityWrapper(null); + + protected BlockEntityWrapper() { + this.blockEntity = null; + } + + protected BlockEntityWrapper(net.minecraft.block.entity.BlockEntity blockEntity) { + this.blockEntity = blockEntity; + } + + public static BlockEntityWrapper of(net.minecraft.block.entity.BlockEntity blockEntity) { + return new BlockEntityWrapper(blockEntity); + } + + public static BlockEntityWrapper of() { + return EMPTY; + } + + public net.minecraft.block.entity.BlockEntity get() { + return blockEntity; + } + + public BlockPos getPos() { + return BlockPos.of(get().getPos()); + } + + public boolean isPresent() { + return !isEmpty(); + } + + public boolean isEmpty() { + return this == EMPTY || get() == null; + } + + public boolean isRemoved() { + return get().isRemoved(); + } + + public void markDirty() { + BlockEntityUtil.markDirty(get()); + } + + public World getWorld() { + return World.of(BlockEntityUtil.getWorld(get())); + } + + public BlockWrapper getBlock() { + return BlockWrapper.of(BlockEntityUtil.getBlock(get())); + } + + + public BlockState getBlockState() { + return BlockState.of(BlockEntityUtil.getBlockState(get())); + } + + public BlockState getCachedState() { + return BlockState.of(BlockEntityUtil.getCachedState(get())); + } + + public NbtCompound createNbt() { + return NbtCompound.of(BlockEntityUtil.getBlockEntityNbt(get())); + } + + public void markRemoved() { + BlockEntityUtil.markRemoved(get()); + } + + public void writeNbt(NbtCompound nbt, CompatRegistryLookup registryLookup) { + BlockEntityUtil.writeNbt(get(), nbt.toMinecraft(), registryLookup); + } + + public void readNbt(NbtCompound nbt, CompatRegistryLookup registryLookup) { + BlockEntityUtil.readNbt(get(), nbt.toMinecraft(), registryLookup); + } + + public void writeNbt(NbtCompound nbt) { + writeNbt(nbt, RegistryLookupUtil.getRegistryLookup(get())); + } + + public void readNbt(NbtCompound nbt) { + readNbt(nbt, RegistryLookupUtil.getRegistryLookup(get())); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/entity/RewritableBlockEntityTypeWrapper.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/entity/RewritableBlockEntityTypeWrapper.java new file mode 100644 index 000000000..c8f5b38cf --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/entity/RewritableBlockEntityTypeWrapper.java @@ -0,0 +1,32 @@ +package net.pitan76.mcpitanlib.midohra.block.entity; + +import net.minecraft.block.entity.BlockEntityType; + +public class RewritableBlockEntityTypeWrapper extends BlockEntityTypeWrapper { + private BlockEntityType type; + + protected RewritableBlockEntityTypeWrapper(BlockEntityType type) { + this.type = type; + } + + protected RewritableBlockEntityTypeWrapper() { + + } + + public static RewritableBlockEntityTypeWrapper of(BlockEntityType type) { + return new RewritableBlockEntityTypeWrapper(type); + } + + public static RewritableBlockEntityTypeWrapper of() { + return new RewritableBlockEntityTypeWrapper(); + } + + public void set(BlockEntityType type) { + this.type = type; + } + + @Override + public BlockEntityType get() { + return type; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/entity/SupplierBlockEntityTypeWrapper.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/entity/SupplierBlockEntityTypeWrapper.java new file mode 100644 index 000000000..c0ea96ed4 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/entity/SupplierBlockEntityTypeWrapper.java @@ -0,0 +1,27 @@ +package net.pitan76.mcpitanlib.midohra.block.entity; + +import net.minecraft.block.entity.BlockEntityType; +import net.pitan76.mcpitanlib.api.registry.result.RegistryResult; + +import java.util.function.Supplier; + +public class SupplierBlockEntityTypeWrapper extends BlockEntityTypeWrapper { + private final Supplier> supplier; + + protected SupplierBlockEntityTypeWrapper(Supplier> supplier) { + this.supplier = supplier; + } + + public static SupplierBlockEntityTypeWrapper of(Supplier> supplier) { + return new SupplierBlockEntityTypeWrapper(supplier); + } + + public static SupplierBlockEntityTypeWrapper of(RegistryResult> result) { + return new SupplierBlockEntityTypeWrapper(result::get); + } + + @Override + public BlockEntityType get() { + return supplier.get(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/entity/SupplierBlockEntityWrapper.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/entity/SupplierBlockEntityWrapper.java new file mode 100644 index 000000000..202a0d31a --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/entity/SupplierBlockEntityWrapper.java @@ -0,0 +1,27 @@ +package net.pitan76.mcpitanlib.midohra.block.entity; + +import net.minecraft.block.entity.BlockEntity; +import net.pitan76.mcpitanlib.api.registry.result.RegistryResult; + +import java.util.function.Supplier; + +public class SupplierBlockEntityWrapper extends BlockEntityWrapper { + private final Supplier supplier; + + protected SupplierBlockEntityWrapper(Supplier supplier) { + this.supplier = supplier; + } + + public static SupplierBlockEntityWrapper of(Supplier supplier) { + return new SupplierBlockEntityWrapper(supplier); + } + + public static SupplierBlockEntityWrapper of(RegistryResult result) { + return new SupplierBlockEntityWrapper(result::get); + } + + @Override + public BlockEntity get() { + return supplier.get(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/client/render/CameraWrapper.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/client/render/CameraWrapper.java new file mode 100644 index 000000000..f6203ec42 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/client/render/CameraWrapper.java @@ -0,0 +1,72 @@ +package net.pitan76.mcpitanlib.midohra.client.render; + +import net.minecraft.client.render.Camera; +import net.pitan76.mcpitanlib.midohra.util.math.BlockPos; +import net.pitan76.mcpitanlib.midohra.util.math.Vector3d; + +import java.util.Objects; + +public class CameraWrapper { + private final Camera camera; + + protected CameraWrapper(Camera camera) { + this.camera = camera; + } + + protected CameraWrapper() { + this.camera = null; + } + + public static CameraWrapper of(Camera camera) { + return new CameraWrapper(camera); + } + + public static CameraWrapper of() { + return new CameraWrapper(); + } + + public Camera get() { + return camera; + } + + public boolean isPresent() { + return !isEmpty(); + } + + public boolean isEmpty() { + return camera == null; + } + + public Vector3d getCameraPos() { + if (isEmpty()) return Vector3d.zero(); + return Vector3d.of(camera.getPos()); + } + + public BlockPos getBlockPos() { + if (isEmpty()) return BlockPos.of(0, 0, 0); + return BlockPos.of(camera.getBlockPos()); + } + + public float getYaw() { + if (isEmpty()) return 0f; + return camera.getYaw(); + } + + public float getPitch() { + if (isEmpty()) return 0f; + return camera.getPitch(); + } + + @Override + public int hashCode() { + return camera != null ? camera.hashCode() : 0; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + CameraWrapper other = (CameraWrapper) obj; + return Objects.equals(camera, other.camera); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/component/ItemComponentTypes.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/component/ItemComponentTypes.java new file mode 100644 index 000000000..abc105a9e --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/component/ItemComponentTypes.java @@ -0,0 +1,125 @@ +package net.pitan76.mcpitanlib.midohra.component; + +import net.minecraft.component.DataComponentTypes; +import net.minecraft.component.type.NbtComponent; +import net.minecraft.component.type.UnbreakableComponent; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NbtCompound; +import net.minecraft.text.Text; +import net.minecraft.util.Rarity; +import net.pitan76.mcpitanlib.api.item.stack.LoreUtil; +import net.pitan76.mcpitanlib.api.util.BlockEntityDataUtil; +import net.pitan76.mcpitanlib.api.util.CustomDataUtil; +import net.pitan76.mcpitanlib.api.util.NbtUtil; +import net.pitan76.mcpitanlib.midohra.component.item.CustomNameComponentType; +import net.pitan76.mcpitanlib.midohra.component.item.ItemComponentType; +import net.pitan76.mcpitanlib.midohra.component.item.RarityComponentType; + +import java.util.List; + +public class ItemComponentTypes { + public static final ItemComponentType CUSTOM_DATA = new ItemComponentType<>(DataComponentTypes.CUSTOM_DATA) { + @Override + public void put(ItemStack stack, NbtCompound value) { + CustomDataUtil.setNbt(stack, value); + } + + @Override + public NbtCompound get(ItemStack stack) { + return CustomDataUtil.getNbt(stack); + } + }; + + public static final ItemComponentType MAX_STACK_SIZE = new ItemComponentType<>(DataComponentTypes.MAX_STACK_SIZE) { + @Override + public void put(ItemStack stack, Integer value) { + stack.set(DataComponentTypes.MAX_STACK_SIZE, value); + } + + @Override + public Integer get(ItemStack stack) { + return stack.getMaxCount(); + } + }; + + public static final ItemComponentType MAX_DAMAGE = new ItemComponentType<>(DataComponentTypes.MAX_DAMAGE) { + @Override + public void put(ItemStack stack, Integer value) { + stack.set(DataComponentTypes.MAX_DAMAGE, value); + } + + @Override + public Integer get(ItemStack stack) { + return stack.getMaxDamage(); + } + }; + + public static final ItemComponentType DAMAGE = new ItemComponentType<>(DataComponentTypes.DAMAGE) { + @Override + public void put(ItemStack stack, Integer value) { + stack.setDamage(value); + } + + @Override + public Integer get(ItemStack stack) { + return stack.getDamage(); + } + }; + + public static final ItemComponentType UNBREAKABLE = new ItemComponentType<>(DataComponentTypes.UNBREAKABLE) { + @Override + public void put(ItemStack stack, Boolean value) { + if (value) { + stack.set(DataComponentTypes.UNBREAKABLE, new UnbreakableComponent(true)); + } else { + stack.remove(DataComponentTypes.UNBREAKABLE); + } + } + + @Override + public Boolean get(ItemStack stack) { + return has(stack); + } + }; + + public static final ItemComponentType RARITY = new RarityComponentType(); + + public static final CustomNameComponentType CUSTOM_NAME = new CustomNameComponentType(); + + public static final ItemComponentType BLOCK_ENTITY_DATA = new ItemComponentType<>(DataComponentTypes.BLOCK_ENTITY_DATA) { + @Override + public void put(ItemStack stack, NbtCompound value) { + BlockEntityDataUtil.setBlockEntityNbt(stack, value); + } + + @Override + public NbtCompound get(ItemStack stack) { + return BlockEntityDataUtil.getBlockEntityNbt(stack); + } + }; + + public static final ItemComponentType ENTITY_DATA = new ItemComponentType<>(DataComponentTypes.ENTITY_DATA) { + @Override + public void put(ItemStack stack, NbtCompound value) { + stack.set(DataComponentTypes.ENTITY_DATA, NbtComponent.of(value)); + } + + @Override + public NbtCompound get(ItemStack stack) { + if (!has(stack)) return NbtUtil.create(); + return stack.get(DataComponentTypes.ENTITY_DATA).copyNbt(); + } + }; + + public static final ItemComponentType> LORE = new ItemComponentType<>(DataComponentTypes.LORE) { + @Override + public void put(ItemStack stack, List value) { + LoreUtil.setLore(stack, value); + } + + @Override + public List get(ItemStack stack) { + return LoreUtil.getLore(stack); + } + }; +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/component/item/CustomNameComponentType.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/component/item/CustomNameComponentType.java new file mode 100644 index 000000000..b4fd2b700 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/component/item/CustomNameComponentType.java @@ -0,0 +1,31 @@ +package net.pitan76.mcpitanlib.midohra.component.item; + +import net.minecraft.component.DataComponentTypes; +import net.minecraft.item.ItemStack; +import net.minecraft.text.Text; + +public class CustomNameComponentType extends ItemComponentType { + + public CustomNameComponentType() { + super(DataComponentTypes.CUSTOM_NAME); + } + + @Override + public void put(ItemStack stack, Text value) { + stack.set(DataComponentTypes.CUSTOM_NAME, value); + } + + @Override + public Text get(ItemStack stack) { + if (!has(stack)) return Text.empty(); + return stack.get(DataComponentTypes.CUSTOM_NAME); + } + + public String getAsString(ItemStack stack) { + return get(stack).getString(); + } + + public void put(ItemStack stack, String name) { + put(stack, Text.literal(name)); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/component/item/ItemComponentType.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/component/item/ItemComponentType.java new file mode 100644 index 000000000..e45e00eef --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/component/item/ItemComponentType.java @@ -0,0 +1,31 @@ +package net.pitan76.mcpitanlib.midohra.component.item; + +import net.minecraft.component.ComponentType; +import net.minecraft.item.ItemStack; + +public abstract class ItemComponentType { + + private final ComponentType type; + + protected ItemComponentType(ComponentType type) { + this.type = type; + } + + public abstract void put(ItemStack stack, T value); + + public abstract T get(ItemStack stack); + + public boolean has(ItemStack stack) { + return stack.contains(type); + } + + public void putOrDefault(ItemStack stack, T value, T defaultValue) { + if (value.equals(defaultValue)) return; + put(stack, value); + } + + public T getOrDefault(ItemStack stack, T defaultValue) { + if (!has(stack)) return defaultValue; + return get(stack); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/component/item/RarityComponentType.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/component/item/RarityComponentType.java new file mode 100644 index 000000000..2fb1ef26e --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/component/item/RarityComponentType.java @@ -0,0 +1,31 @@ +package net.pitan76.mcpitanlib.midohra.component.item; + +import net.minecraft.component.DataComponentTypes; +import net.minecraft.item.ItemStack; +import net.minecraft.util.Rarity; +import net.pitan76.mcpitanlib.api.util.CompatRarity; + +public class RarityComponentType extends ItemComponentType { + + public RarityComponentType() { + super(DataComponentTypes.RARITY); + } + + @Override + public void put(ItemStack stack, Rarity value) { + stack.set(DataComponentTypes.RARITY, value); + } + + @Override + public Rarity get(ItemStack stack) { + return stack.getRarity(); + } + + public void put(ItemStack stack, CompatRarity rarity) { + put(stack, rarity.get()); + } + + public CompatRarity getCompatRarity(ItemStack stack) { + return CompatRarity.of(get(stack)); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/easybuilder/BlockBuilder.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/easybuilder/BlockBuilder.java new file mode 100644 index 000000000..587531855 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/easybuilder/BlockBuilder.java @@ -0,0 +1,308 @@ +package net.pitan76.mcpitanlib.midohra.easybuilder; + +import net.minecraft.item.Item; +import net.pitan76.mcpitanlib.api.CommonModInitializer; +import net.pitan76.mcpitanlib.api.block.CompatBlockRenderType; +import net.pitan76.mcpitanlib.api.block.CompatibleMaterial; +import net.pitan76.mcpitanlib.api.block.ExtendBlock; +import net.pitan76.mcpitanlib.api.block.args.RenderTypeArgs; +import net.pitan76.mcpitanlib.api.block.args.v2.CollisionShapeEvent; +import net.pitan76.mcpitanlib.api.block.args.v2.OutlineShapeEvent; +import net.pitan76.mcpitanlib.api.block.args.v2.PlacementStateArgs; +import net.pitan76.mcpitanlib.api.block.args.v2.StateForNeighborUpdateArgs; +import net.pitan76.mcpitanlib.api.block.v2.BlockSettingsBuilder; +import net.pitan76.mcpitanlib.api.event.block.AppendPropertiesArgs; +import net.pitan76.mcpitanlib.api.event.block.BlockUseEvent; +import net.pitan76.mcpitanlib.api.event.block.DroppedStacksArgs; +import net.pitan76.mcpitanlib.api.event.block.StateReplacedEvent; +import net.pitan76.mcpitanlib.api.event.item.ItemAppendTooltipEvent; +import net.pitan76.mcpitanlib.api.item.v2.CompatibleItemSettings; +import net.pitan76.mcpitanlib.api.registry.result.RegistryResult; +import net.pitan76.mcpitanlib.api.registry.v2.CompatRegistryV2; +import net.pitan76.mcpitanlib.api.sound.CompatBlockSoundGroup; +import net.pitan76.mcpitanlib.api.text.TextComponent; +import net.pitan76.mcpitanlib.api.util.CompatActionResult; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.api.util.color.CompatDyeColor; +import net.pitan76.mcpitanlib.api.util.color.CompatMapColor; +import net.pitan76.mcpitanlib.api.util.item.ItemUtil; +import net.pitan76.mcpitanlib.core.datafixer.Pair; +import net.pitan76.mcpitanlib.midohra.block.BlockState; +import net.pitan76.mcpitanlib.midohra.block.BlockWrapper; +import net.pitan76.mcpitanlib.midohra.block.SupplierBlockWrapper; +import net.pitan76.mcpitanlib.midohra.easybuilder.built.BuiltBlock; +import net.pitan76.mcpitanlib.midohra.item.ItemStack; +import net.pitan76.mcpitanlib.midohra.item.SupplierItemWrapper; +import net.pitan76.mcpitanlib.midohra.util.shape.VoxelShape; +import org.jetbrains.annotations.Nullable; + +import java.util.ArrayList; +import java.util.List; +import java.util.function.*; + +public class BlockBuilder { + + public BlockSettingsBuilder settingsBuilder; + public Function onRightClick; + public Consumer onStateReplaced; + public Consumer onAppendTooltip; + public Consumer onAppendProperties; + public BlockState defaultState; + public BiConsumer onInit; + public Function onOutlineShape; + public Function onCollisionShape; + public Function onRenderType; + public Function onPlacementState; + public Function onStateForNeighborUpdate; + public Function> onDroppedStacks; + + public BlockBuilder(BlockSettingsBuilder settingsBuilder) { + this.settingsBuilder = settingsBuilder; + } + + public BlockBuilder(CompatIdentifier id) { + this(new BlockSettingsBuilder(id)); + } + + public static BlockBuilder of(CompatIdentifier id) { + return new BlockBuilder(id); + } + + public static BlockBuilder of(BlockSettingsBuilder settingsBuilder) { + return new BlockBuilder(settingsBuilder); + } + + public SupplierBlockWrapper build(CompatRegistryV2 registry) { + if (settingsBuilder.id == null) + throw new IllegalStateException("Block id is not set. hint: use build(CompatRegistryV2, CompatIdentifier)"); + + Supplier result = registry.registerExtendBlock(settingsBuilder.id, () -> new BuiltBlock(this)); + + return SupplierBlockWrapper.of(result::get); + } + + public SupplierBlockWrapper build(CompatRegistryV2 registry, CompatIdentifier id) { + Supplier result = registry.registerExtendBlock(id, () -> new BuiltBlock(this, id)); + + return SupplierBlockWrapper.of(result::get); + } + + public SupplierBlockWrapper build(CommonModInitializer initializer) { + return build(initializer.registry); + } + + public SupplierBlockWrapper build(CommonModInitializer initializer, CompatIdentifier id) { + return build(initializer.registry, id); + } + + public Pair buildWithItem(CompatRegistryV2 registry, CompatibleItemSettings settings) { + SupplierBlockWrapper block = build(registry); + + RegistryResult result = registry.registerItem(settingsBuilder.id, () -> ItemUtil.create(block.get(), settings)); + + return Pair.of(block, SupplierItemWrapper.of(result::get)); + } + + public Pair buildWithItem(CompatRegistryV2 registry, CompatIdentifier id, CompatibleItemSettings settings) { + SupplierBlockWrapper block = build(registry, id); + + RegistryResult result = registry.registerItem(id, () -> ItemUtil.create(block.get(), settings.setId(id))); + + return Pair.of(block, SupplierItemWrapper.of(result::get)); + } + + public Pair buildWithItem(CommonModInitializer initializer, CompatibleItemSettings settings) { + return buildWithItem(initializer.registry, settings); + } + + public Pair buildWithItem(CommonModInitializer initializer, CompatIdentifier id, CompatibleItemSettings settings) { + return buildWithItem(initializer.registry, id, settings); + } + + public BlockBuilder material(CompatibleMaterial material) { + settingsBuilder.material(material); + return this; + } + + public BlockBuilder sounds(CompatBlockSoundGroup sounds) { + settingsBuilder.sounds(sounds); + return this; + } + + public BlockBuilder strength(float hardness, float resistance) { + settingsBuilder.strength(hardness, resistance); + return this; + } + + public BlockBuilder strength(float hardness) { + settingsBuilder.hardness(hardness); + return this; + } + + public BlockBuilder resistance(float resistance) { + settingsBuilder.resistance(resistance); + return this; + } + + public BlockBuilder mapColor(CompatMapColor color) { + settingsBuilder.mapColor(color); + return this; + } + + public BlockBuilder mapColor(CompatDyeColor color) { + settingsBuilder.dyeColor(color); + return this; + } + + public BlockBuilder luminance(ToIntFunction luminance) { + settingsBuilder.luminance(luminance); + return this; + } + + public BlockBuilder requiresTool() { + settingsBuilder.requiresTool(); + return this; + } + + public BlockBuilder dropsNothing() { + settingsBuilder.dropsNothing(); + return this; + } + + public BlockBuilder onRightClick(Function onRightClick) { + this.onRightClick = onRightClick; + return this; + } + + public BlockBuilder onStateReplaced(Consumer onStateReplaced) { + this.onStateReplaced = onStateReplaced; + return this; + } + + public BlockBuilder onAppendTooltip(Consumer onAppendTooltip) { + this.onAppendTooltip = onAppendTooltip; + return this; + } + + public BlockBuilder onAppendProperties(Consumer onAppendProperties) { + this.onAppendProperties = onAppendProperties; + return this; + } + + public BlockBuilder onOutlineShape(Function onOutlineShape) { + return onOutlineShapeRaw(e -> onOutlineShape.apply(e).raw()); + } + + public BlockBuilder onCollisionShape(Function onCollisionShape) { + return onCollisionShapeRaw(e -> onCollisionShape.apply(e).raw()); + } + + public BlockBuilder onOutlineShapeRaw(Function onOutlineShape) { + this.onOutlineShape = onOutlineShape; + return this; + } + + public BlockBuilder onCollisionShapeRaw(Function onCollisionShape) { + this.onCollisionShape = onCollisionShape; + return this; + } + + public BlockBuilder onRenderType(Function onRenderType) { + this.onRenderType = onRenderType; + return this; + } + + public BlockBuilder onPlacementState(Function onPlacementState) { + this.onPlacementState = onPlacementState; + return this; + } + + public BlockBuilder onStateForNeighborUpdate(Function onStateForNeighborUpdate) { + this.onStateForNeighborUpdate = onStateForNeighborUpdate; + return this; + } + + public BlockBuilder setOutlineShape(VoxelShape shape) { + return onOutlineShape(e -> shape); + } + + public BlockBuilder setCollisionShape(VoxelShape shape) { + return onCollisionShape(e -> shape); + } + + public BlockBuilder setOutlineShape(net.minecraft.util.shape.VoxelShape shape) { + return onOutlineShapeRaw(e -> shape); + } + + public BlockBuilder setCollisionShape(net.minecraft.util.shape.VoxelShape shape) { + return onCollisionShapeRaw(e -> shape); + } + + public BlockBuilder setRenderType(CompatBlockRenderType renderType) { + return onRenderType(e -> renderType); + } + + public BlockBuilder onInit(BiConsumer onInit) { + this.onInit = onInit; + return this; + } + + public BlockBuilder setDefaultState(BlockState defaultState) { + this.defaultState = defaultState; + return this; + } + + private final List tooltip = new ArrayList<>(); + + public BlockBuilder addTooltip(TextComponent text) { + if (tooltip.isEmpty()) { + onAppendTooltip = e -> e.getTooltip().add(text.getText()); + } else { + onAppendTooltip = e -> { + for (TextComponent t : tooltip) { + e.getTooltip().add(t.getText()); + } + e.getTooltip().add(text.getText()); + }; + } + + this.tooltip.add(text); + return this; + } + + public BlockBuilder onDroppedStacksRaw(Function> onDroppedStacks) { + this.onDroppedStacks = onDroppedStacks; + return this; + } + + public BlockBuilder onDroppedStacks(Function> onDroppedStacks) { + return onDroppedStacksRaw(e -> onDroppedStacks.apply(e).stream() + .map(ItemStack::toMinecraft) + .toList()); + } + + public BlockBuilder write(BlockBuilder copy) { + copy.onRightClick = onRightClick; + copy.onStateReplaced = onStateReplaced; + copy.onAppendTooltip = onAppendTooltip; + copy.onAppendProperties = onAppendProperties; + copy.defaultState = defaultState; + copy.onInit = onInit; + copy.onOutlineShape = onOutlineShape; + copy.onCollisionShape = onCollisionShape; + copy.onRenderType = onRenderType; + copy.onPlacementState = onPlacementState; + copy.onStateForNeighborUpdate = onStateForNeighborUpdate; + copy.onDroppedStacks = onDroppedStacks; + + return copy; + } + + public BlockBuilder copy(BlockSettingsBuilder settingsBuilder) { + return write(new BlockBuilder(settingsBuilder)); + } + + public BlockBuilder copy() { + return copy(this.settingsBuilder.copy()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/easybuilder/BlockEntityBuilder.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/easybuilder/BlockEntityBuilder.java new file mode 100644 index 000000000..b85331534 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/easybuilder/BlockEntityBuilder.java @@ -0,0 +1,88 @@ +package net.pitan76.mcpitanlib.midohra.easybuilder; + +import net.minecraft.block.Block; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.block.entity.BlockEntityType; +import net.pitan76.mcpitanlib.api.event.nbt.ReadNbtArgs; +import net.pitan76.mcpitanlib.api.event.nbt.WriteNbtArgs; +import net.pitan76.mcpitanlib.api.registry.result.SupplierResult; +import net.pitan76.mcpitanlib.api.registry.v2.CompatRegistryV2; +import net.pitan76.mcpitanlib.api.tile.BlockEntityTypeBuilder; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.midohra.block.BlockWrapper; +import net.pitan76.mcpitanlib.midohra.block.entity.BlockEntityTypeWrapper; +import net.pitan76.mcpitanlib.midohra.block.entity.BlockEntityWrapper; +import net.pitan76.mcpitanlib.midohra.block.entity.RewritableBlockEntityTypeWrapper; +import net.pitan76.mcpitanlib.midohra.easybuilder.built.BuiltBlockEntity; + +import java.util.Arrays; +import java.util.function.BiConsumer; + +public class BlockEntityBuilder { + + public BiConsumer onWriteNbt; + public BiConsumer onReadNbt; + public BiConsumer onInit; + + public CompatIdentifier id; + + public BlockEntityBuilder(CompatIdentifier id) { + this.id = id; + } + + public static BlockEntityBuilder of(CompatIdentifier id) { + return new BlockEntityBuilder(id); + } + + public BlockEntityTypeWrapper build(CompatRegistryV2 registry, CompatIdentifier id, BlockWrapper... blocks) { + RewritableBlockEntityTypeWrapper type = RewritableBlockEntityTypeWrapper.of(); + BlockEntityBuilder builder = this; + + SupplierResult> result = registry.registerBlockEntityType(id, BlockEntityTypeBuilder.create( + e -> new BuiltBlockEntity(type, builder, e), + Arrays.stream(blocks).map(BlockWrapper::get).toArray(Block[]::new) + )); + + type.set(result.get()); + + return type; + } + + public BlockEntityTypeWrapper build(CompatRegistryV2 registry, BlockWrapper... blocks) { + if (id == null) + throw new IllegalStateException("BlockEntity id is not set. hint: use build(CompatRegistryV2, CompatIdentifier, BlockWrapper...)"); + + return build(registry, id, blocks); + } + + public BlockEntityBuilder onInit(BiConsumer onInit) { + this.onInit = onInit; + return this; + } + + public BlockEntityBuilder onWriteNbt(BiConsumer onWriteNbt) { + this.onWriteNbt = onWriteNbt; + return this; + } + + public BlockEntityBuilder onReadNbt(BiConsumer onReadNbt) { + this.onReadNbt = onReadNbt; + return this; + } + + public BlockEntityBuilder write(BlockEntityBuilder copy) { + copy.onInit = this.onInit; + copy.onWriteNbt = this.onWriteNbt; + copy.onReadNbt = this.onReadNbt; + + return copy; + } + + public BlockEntityBuilder copy(CompatIdentifier id) { + return write(new BlockEntityBuilder(id)); + } + + public BlockEntityBuilder copy() { + return copy(this.id); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/easybuilder/BlockWithBlockEntityBuilder.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/easybuilder/BlockWithBlockEntityBuilder.java new file mode 100644 index 000000000..16ce75a16 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/easybuilder/BlockWithBlockEntityBuilder.java @@ -0,0 +1,107 @@ +package net.pitan76.mcpitanlib.midohra.easybuilder; + +import net.minecraft.block.entity.BlockEntityType; +import net.pitan76.mcpitanlib.api.CommonModInitializer; +import net.pitan76.mcpitanlib.api.block.ExtendBlock; +import net.pitan76.mcpitanlib.api.block.v2.BlockSettingsBuilder; +import net.pitan76.mcpitanlib.api.registry.v2.CompatRegistryV2; +import net.pitan76.mcpitanlib.api.util.BlockEntityTypeUtil; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.midohra.block.SupplierBlockWrapper; +import net.pitan76.mcpitanlib.midohra.easybuilder.built.BuiltBlockWithEntity; + +import java.util.function.Supplier; + +public class BlockWithBlockEntityBuilder extends BlockBuilder { + + public Supplier> blockEntityType; + + public BlockWithBlockEntityBuilder(BlockSettingsBuilder settingsBuilder) { + super(settingsBuilder); + } + + public BlockWithBlockEntityBuilder(CompatIdentifier id) { + super(id); + } + + public BlockWithBlockEntityBuilder(BlockSettingsBuilder settingsBuilder, Supplier> blockEntityType) { + super(settingsBuilder); + this.blockEntityType = blockEntityType; + } + + public BlockWithBlockEntityBuilder(CompatIdentifier id, Supplier> blockEntityType) { + super(id); + this.blockEntityType = blockEntityType; + } + + @Override + public SupplierBlockWrapper build(CompatRegistryV2 registry) { + if (settingsBuilder.id == null) + throw new IllegalStateException("Block id is not set. hint: use build(CompatRegistryV2, CompatIdentifier)"); + + Supplier result = registry.registerExtendBlock(settingsBuilder.id, () -> new BuiltBlockWithEntity(this)); + + return SupplierBlockWrapper.of(result::get); + } + + @Override + public SupplierBlockWrapper build(CompatRegistryV2 registry, CompatIdentifier id) { + Supplier result = registry.registerExtendBlock(id, () -> new BuiltBlockWithEntity(this, id)); + + return SupplierBlockWrapper.of(result::get); + } + + public SupplierBlockWrapper build(CommonModInitializer initializer) { + return build(initializer.registry); + } + + public SupplierBlockWrapper build(CommonModInitializer initializer, CompatIdentifier id) { + return build(initializer.registry, id); + } + + public static BlockWithBlockEntityBuilder of(CompatIdentifier id) { + return new BlockWithBlockEntityBuilder(id); + } + + public static BlockWithBlockEntityBuilder of(BlockSettingsBuilder settingsBuilder) { + return new BlockWithBlockEntityBuilder(settingsBuilder); + } + + public static BlockWithBlockEntityBuilder of(CompatIdentifier id, Supplier> blockEntityType) { + return new BlockWithBlockEntityBuilder(id, blockEntityType); + } + + public static BlockWithBlockEntityBuilder of(BlockSettingsBuilder settingsBuilder, Supplier> blockEntityType) { + return new BlockWithBlockEntityBuilder(settingsBuilder, blockEntityType); + } + + public BlockWithBlockEntityBuilder applyBlockEntity(Supplier> blockEntityType) { + this.blockEntityType = blockEntityType; + return this; + } + + public BlockWithBlockEntityBuilder applyBlockEntity(BlockEntityType blockEntityType) { + this.blockEntityType = () -> blockEntityType; + return this; + } + + public BlockWithBlockEntityBuilder applyBlockEntity(CompatIdentifier id) { + return applyBlockEntity(BlockEntityTypeUtil.fromId(id)); + } + + public BlockWithBlockEntityBuilder write(BlockWithBlockEntityBuilder copy) { + copy.settingsBuilder = this.settingsBuilder; + copy.blockEntityType = this.blockEntityType; + super.write(copy); + + return copy; + } + + public BlockWithBlockEntityBuilder copy(BlockSettingsBuilder settingsBuilder) { + return write(new BlockWithBlockEntityBuilder(settingsBuilder)); + } + + public BlockWithBlockEntityBuilder copy() { + return copy(this.settingsBuilder.copy()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/easybuilder/ItemBuilder.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/easybuilder/ItemBuilder.java new file mode 100644 index 000000000..14c4b6a1b --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/easybuilder/ItemBuilder.java @@ -0,0 +1,198 @@ +package net.pitan76.mcpitanlib.midohra.easybuilder; + +import net.pitan76.mcpitanlib.api.CommonModInitializer; +import net.pitan76.mcpitanlib.api.event.item.*; +import net.pitan76.mcpitanlib.api.item.CompatFoodComponent; +import net.pitan76.mcpitanlib.api.item.CreativeTabBuilder; +import net.pitan76.mcpitanlib.api.item.ExtendItem; +import net.pitan76.mcpitanlib.api.item.v2.ItemSettingsBuilder; +import net.pitan76.mcpitanlib.api.registry.v2.CompatRegistryV2; +import net.pitan76.mcpitanlib.api.tag.item.RepairIngredientTag; +import net.pitan76.mcpitanlib.api.text.TextComponent; +import net.pitan76.mcpitanlib.api.util.CompatActionResult; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.api.util.CompatRarity; +import net.pitan76.mcpitanlib.api.util.StackActionResult; +import net.pitan76.mcpitanlib.midohra.easybuilder.built.BuiltItem; +import net.pitan76.mcpitanlib.midohra.item.ItemGroupWrapper; +import net.pitan76.mcpitanlib.midohra.item.ItemWrapper; +import net.pitan76.mcpitanlib.midohra.item.SupplierItemWrapper; + +import java.util.ArrayList; +import java.util.List; +import java.util.function.Consumer; +import java.util.function.Function; +import java.util.function.Supplier; + +public class ItemBuilder { + + public ItemSettingsBuilder settingsBuilder; + public Function onRightClick; + public Function onRightClickOnBlock; + public Function onRightClickOnEntity; + public Consumer onAppendTooltip; + public Function onItemBarColor; + public Function onItemBarStep; + + public ItemBuilder(ItemSettingsBuilder settingsBuilder) { + this.settingsBuilder = settingsBuilder; + } + + public ItemBuilder(CompatIdentifier id) { + this(new ItemSettingsBuilder(id)); + } + + public static ItemBuilder of(CompatIdentifier id) { + return new ItemBuilder(id); + } + + public static ItemBuilder of(ItemSettingsBuilder settingsBuilder) { + return new ItemBuilder(settingsBuilder); + } + + public SupplierItemWrapper build(CompatRegistryV2 registry) { + if (settingsBuilder.id == null) + throw new IllegalStateException("Item id is not set. hint: use build(CompatRegistryV2, CompatIdentifier)"); + + Supplier result = registry.registerExtendItem(settingsBuilder.id, () -> new BuiltItem(this)); + + return SupplierItemWrapper.of(result::get); + } + + public SupplierItemWrapper build(CompatRegistryV2 registry, CompatIdentifier id) { + Supplier result = registry.registerExtendItem(settingsBuilder.id, () -> new BuiltItem(this, id)); + + return SupplierItemWrapper.of(result::get); + } + + public SupplierItemWrapper build(CommonModInitializer initializer) { + return build(initializer.registry); + } + + public SupplierItemWrapper build(CommonModInitializer initializer, CompatIdentifier id) { + return build(initializer.registry, id); + } + + public ItemBuilder maxCount(int maxCount) { + settingsBuilder.maxCount(maxCount); + return this; + } + + public ItemBuilder maxDamage(int maxDamage) { + settingsBuilder.maxDamage(maxDamage); + return this; + } + + public ItemBuilder maxDamageIfAbsent(int maxDamage) { + settingsBuilder.maxDamageIfAbsent(maxDamage); + return this; + } + + public ItemBuilder food(CompatFoodComponent foodComponent) { + settingsBuilder.foodComponent(foodComponent); + return this; + } + + public ItemBuilder recipeRemainder(ItemWrapper recipeRemainder) { + settingsBuilder.recipeRemainder(recipeRemainder); + return this; + } + + public ItemBuilder enchantability(int enchantability) { + settingsBuilder.enchantability(enchantability); + return this; + } + + public ItemBuilder repairable(CompatIdentifier repairIngredientTag) { + settingsBuilder.repairable(repairIngredientTag); + return this; + } + + public ItemBuilder repairable(RepairIngredientTag repairIngredientTag) { + settingsBuilder.repairable(repairIngredientTag); + return this; + } + + public ItemBuilder rarity(CompatRarity rarity) { + settingsBuilder.rarity(rarity); + return this; + } + + public ItemBuilder group(ItemGroupWrapper itemGroup) { + settingsBuilder.addGroup(itemGroup); + return this; + } + + public ItemBuilder group(CreativeTabBuilder itemGroup) { + settingsBuilder.addGroup(itemGroup); + return this; + } + + public ItemBuilder onRightClick(Function onRightClick) { + this.onRightClick = onRightClick; + return this; + } + + public ItemBuilder onRightClickOnBlock(Function onRightClickOnBlock) { + this.onRightClickOnBlock = onRightClickOnBlock; + return this; + } + + public ItemBuilder onRightClickOnEntity(Function onRightClickOnEntity) { + this.onRightClickOnEntity = onRightClickOnEntity; + return this; + } + + public ItemBuilder onAppendTooltip(Consumer onAppendTooltip) { + this.onAppendTooltip = onAppendTooltip; + return this; + } + + public ItemBuilder onItemBarColor(Function onItemBarColor) { + this.onItemBarColor = onItemBarColor; + return this; + } + + public ItemBuilder onItemBarStep(Function onItemBarStep) { + this.onItemBarStep = onItemBarStep; + return this; + } + + private final List tooltip = new ArrayList<>(); + + public ItemBuilder addTooltip(TextComponent text) { + if (tooltip.isEmpty()) { + onAppendTooltip = e -> e.getTooltip().add(text.getText()); + } else { + onAppendTooltip = e -> { + for (TextComponent t : tooltip) { + e.getTooltip().add(t.getText()); + } + e.getTooltip().add(text.getText()); + }; + } + + this.tooltip.add(text); + return this; + } + + public ItemBuilder write(ItemBuilder copy) { + copy.settingsBuilder = this.settingsBuilder; + copy.onRightClick = this.onRightClick; + copy.onRightClickOnBlock = this.onRightClickOnBlock; + copy.onRightClickOnEntity = this.onRightClickOnEntity; + copy.onAppendTooltip = this.onAppendTooltip; + copy.onItemBarColor = this.onItemBarColor; + copy.onItemBarStep = this.onItemBarStep; + + return copy; + } + + public ItemBuilder copy(ItemSettingsBuilder builder) { + return write(new ItemBuilder(builder)); + } + + public ItemBuilder copy() { + return copy(this.settingsBuilder.copy()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/easybuilder/built/BuiltBlock.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/easybuilder/built/BuiltBlock.java new file mode 100644 index 000000000..c74686013 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/easybuilder/built/BuiltBlock.java @@ -0,0 +1,146 @@ +package net.pitan76.mcpitanlib.midohra.easybuilder.built; + +import net.minecraft.item.ItemStack; +import net.minecraft.util.shape.VoxelShape; +import net.pitan76.mcpitanlib.api.block.CompatBlockRenderType; +import net.pitan76.mcpitanlib.api.block.args.RenderTypeArgs; +import net.pitan76.mcpitanlib.api.block.args.v2.CollisionShapeEvent; +import net.pitan76.mcpitanlib.api.block.args.v2.OutlineShapeEvent; +import net.pitan76.mcpitanlib.api.block.args.v2.PlacementStateArgs; +import net.pitan76.mcpitanlib.api.block.args.v2.StateForNeighborUpdateArgs; +import net.pitan76.mcpitanlib.api.block.v2.CompatBlock; +import net.pitan76.mcpitanlib.api.block.v2.CompatibleBlockSettings; +import net.pitan76.mcpitanlib.api.event.block.AppendPropertiesArgs; +import net.pitan76.mcpitanlib.api.event.block.BlockUseEvent; +import net.pitan76.mcpitanlib.api.event.block.DroppedStacksArgs; +import net.pitan76.mcpitanlib.api.event.block.StateReplacedEvent; +import net.pitan76.mcpitanlib.api.event.item.ItemAppendTooltipEvent; +import net.pitan76.mcpitanlib.api.util.CompatActionResult; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.midohra.block.BlockState; +import net.pitan76.mcpitanlib.midohra.easybuilder.BlockBuilder; +import org.jetbrains.annotations.Nullable; + +import java.util.List; +import java.util.function.Consumer; +import java.util.function.Function; + +public class BuiltBlock extends CompatBlock { + + protected Function onRightClick; + protected Consumer onStateReplaced; + protected Consumer onAppendTooltip; + protected Consumer onAppendProperties; + protected Function onOutlineShape; + protected Function onCollisionShape; + protected Function onRenderType; + protected Function onPlacementState; + protected Function onStateForNeighborUpdate; + protected Function> onDroppedStacks; + + public BuiltBlock(CompatibleBlockSettings settings) { + super(settings); + } + + public BuiltBlock(BlockBuilder builder) { + this(builder.settingsBuilder.build()); + init(builder); + } + + public BuiltBlock(BlockBuilder builder, CompatIdentifier id) { + this(builder.settingsBuilder.build(id)); + init(builder); + } + + protected void init(BlockBuilder builder) { + this.onRightClick = builder.onRightClick; + this.onStateReplaced = builder.onStateReplaced; + this.onAppendTooltip = builder.onAppendTooltip; + this.onAppendProperties = builder.onAppendProperties; + this.onOutlineShape = builder.onOutlineShape; + this.onCollisionShape = builder.onCollisionShape; + this.onRenderType = builder.onRenderType; + this.onPlacementState = builder.onPlacementState; + this.onStateForNeighborUpdate = builder.onStateForNeighborUpdate; + + if (builder.onInit != null) + builder.onInit.accept(this.getWrapper(), builder); + + if (builder.defaultState != null) + this.setDefaultState(builder.defaultState); + } + + @Override + public CompatActionResult onRightClick(BlockUseEvent e) { + if (onRightClick == null) + return e.pass(); + + return onRightClick.apply(e); + } + + @Override + public void onStateReplaced(StateReplacedEvent e) { + if (onStateReplaced != null) + onStateReplaced.accept(e); + } + + @Override + public void appendTooltip(ItemAppendTooltipEvent e) { + if (onAppendTooltip != null) + onAppendTooltip.accept(e); + } + + @Override + public void appendProperties(AppendPropertiesArgs args) { + if (onAppendProperties != null) + onAppendProperties.accept(args); + } + + @Override + public VoxelShape getOutlineShape(OutlineShapeEvent e) { + if (onOutlineShape != null) + return onOutlineShape.apply(e); + + return super.getOutlineShape(e); + } + + @Override + public VoxelShape getCollisionShape(CollisionShapeEvent e) { + if (onCollisionShape != null) + return onCollisionShape.apply(e); + + return super.getCollisionShape(e); + } + + @Override + public CompatBlockRenderType getRenderType(RenderTypeArgs args) { + if (onRenderType != null) + return onRenderType.apply(args); + + return super.getRenderType(args); + } + + @Override + public @Nullable BlockState getPlacementState(PlacementStateArgs args) { + if (onPlacementState != null) + return onPlacementState.apply(args); + + return super.getPlacementState(args); + } + + @Override + public BlockState getStateForNeighborUpdate(StateForNeighborUpdateArgs args) { + if (onStateForNeighborUpdate != null) + return onStateForNeighborUpdate.apply(args); + + return super.getStateForNeighborUpdate(args); + } + + @Override + public List getDroppedStacks(DroppedStacksArgs args) { + if (onDroppedStacks != null) + return onDroppedStacks.apply(args); + + return super.getDroppedStacks(args); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/easybuilder/built/BuiltBlockEntity.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/easybuilder/built/BuiltBlockEntity.java new file mode 100644 index 000000000..4143b69e7 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/easybuilder/built/BuiltBlockEntity.java @@ -0,0 +1,65 @@ +package net.pitan76.mcpitanlib.midohra.easybuilder.built; + +import net.minecraft.block.BlockState; +import net.minecraft.block.entity.BlockEntityType; +import net.minecraft.util.math.BlockPos; +import net.pitan76.mcpitanlib.api.event.block.TileCreateEvent; +import net.pitan76.mcpitanlib.api.event.nbt.ReadNbtArgs; +import net.pitan76.mcpitanlib.api.event.nbt.WriteNbtArgs; +import net.pitan76.mcpitanlib.api.tile.CompatBlockEntity; +import net.pitan76.mcpitanlib.midohra.block.entity.BlockEntityTypeWrapper; +import net.pitan76.mcpitanlib.midohra.block.entity.BlockEntityWrapper; +import net.pitan76.mcpitanlib.midohra.easybuilder.BlockEntityBuilder; + +import java.util.function.BiConsumer; + +public class BuiltBlockEntity extends CompatBlockEntity { + + public BiConsumer onWriteNbt; + public BiConsumer onReadNbt; + + public BuiltBlockEntity(BlockEntityType type, BlockPos pos, BlockState state) { + super(type, pos, state); + } + + public BuiltBlockEntity(BlockEntityType type, TileCreateEvent e) { + super(type, e); + } + + public BuiltBlockEntity(BlockEntityTypeWrapper type, TileCreateEvent e) { + super(type.get(), e); + } + + public BuiltBlockEntity(BlockEntityTypeWrapper type, BlockEntityBuilder builder, TileCreateEvent e) { + this(type, e); + init(builder); + } + + protected void init(BlockEntityBuilder builder) { + this.onWriteNbt = builder.onWriteNbt; + this.onReadNbt = builder.onReadNbt; + + if (builder.onInit != null) + builder.onInit.accept(_wrap(), builder); + } + + @Override + public void writeNbt(WriteNbtArgs args) { + super.writeNbt(args); + if (onWriteNbt != null) { + onWriteNbt.accept(_wrap(), args); + } + } + + @Override + public void readNbt(ReadNbtArgs args) { + super.readNbt(args); + if (onReadNbt != null) { + onReadNbt.accept(_wrap(), args); + } + } + + public BlockEntityWrapper _wrap() { + return BlockEntityWrapper.of(this); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/easybuilder/built/BuiltBlockWithEntity.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/easybuilder/built/BuiltBlockWithEntity.java new file mode 100644 index 000000000..6297eb9c0 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/easybuilder/built/BuiltBlockWithEntity.java @@ -0,0 +1,40 @@ +package net.pitan76.mcpitanlib.midohra.easybuilder.built; + +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.block.entity.BlockEntityType; +import net.pitan76.mcpitanlib.api.block.ExtendBlockEntityProvider; +import net.pitan76.mcpitanlib.api.block.v2.CompatibleBlockSettings; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.midohra.easybuilder.BlockWithBlockEntityBuilder; +import org.jetbrains.annotations.Nullable; + +import java.util.function.Supplier; + +public class BuiltBlockWithEntity extends BuiltBlock implements ExtendBlockEntityProvider { + + public Supplier> blockEntityType; + + public BuiltBlockWithEntity(CompatibleBlockSettings settings) { + super(settings); + } + + public BuiltBlockWithEntity(BlockWithBlockEntityBuilder builder) { + super(builder); + + this.blockEntityType = builder.blockEntityType; + } + + public BuiltBlockWithEntity(BlockWithBlockEntityBuilder builder, CompatIdentifier id) { + super(builder, id); + + this.blockEntityType = builder.blockEntityType; + } + + @Override + public @Nullable BlockEntityType getBlockEntityType() { + if (blockEntityType == null) + return null; + + return (BlockEntityType) blockEntityType.get(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/easybuilder/built/BuiltItem.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/easybuilder/built/BuiltItem.java new file mode 100644 index 000000000..bd7ff8330 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/easybuilder/built/BuiltItem.java @@ -0,0 +1,91 @@ +package net.pitan76.mcpitanlib.midohra.easybuilder.built; + +import net.pitan76.mcpitanlib.api.event.item.*; +import net.pitan76.mcpitanlib.api.item.v2.CompatItem; +import net.pitan76.mcpitanlib.api.item.v2.CompatibleItemSettings; +import net.pitan76.mcpitanlib.api.util.CompatActionResult; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.api.util.StackActionResult; +import net.pitan76.mcpitanlib.midohra.easybuilder.ItemBuilder; + +import java.util.function.Consumer; +import java.util.function.Function; + +public class BuiltItem extends CompatItem { + + protected Function onRightClick; + protected Function onRightClickOnBlock; + protected Function onRightClickOnEntity; + protected Consumer onAppendTooltip; + protected Function onItemBarColor; + protected Function onItemBarStep; + + protected BuiltItem(CompatibleItemSettings settings) { + super(settings); + } + + public BuiltItem(ItemBuilder builder) { + this(builder.settingsBuilder.build()); + init(builder); + } + + public BuiltItem(ItemBuilder builder, CompatIdentifier id) { + this(builder.settingsBuilder.build(id)); + init(builder); + } + + protected void init(ItemBuilder builder) { + this.onRightClick = builder.onRightClick; + this.onRightClickOnBlock = builder.onRightClickOnBlock; + this.onRightClickOnEntity = builder.onRightClickOnEntity; + this.onAppendTooltip = builder.onAppendTooltip; + this.onItemBarColor = builder.onItemBarColor; + this.onItemBarStep = builder.onItemBarStep; + } + + @Override + public StackActionResult onRightClick(ItemUseEvent e) { + if (onRightClick == null) + return e.pass(); + + return onRightClick.apply(e); + } + + @Override + public CompatActionResult onRightClickOnBlock(ItemUseOnBlockEvent e) { + if (onRightClickOnBlock == null) + return e.pass(); + + return onRightClickOnBlock.apply(e); + } + + @Override + public CompatActionResult onRightClickOnEntity(ItemUseOnEntityEvent e) { + if (onRightClickOnEntity == null) + return e.pass(); + + return onRightClickOnEntity.apply(e); + } + + @Override + public void appendTooltip(ItemAppendTooltipEvent e) { + if (onAppendTooltip != null) + onAppendTooltip.accept(e); + } + + @Override + public int getItemBarColor(ItemBarColorArgs args) { + if (onItemBarColor != null) + return onItemBarColor.apply(args); + + return super.getItemBarColor(args); + } + + @Override + public int getItemBarStep(ItemBarStepArgs args) { + if (onItemBarStep != null) + return onItemBarStep.apply(args); + + return super.getItemBarStep(args); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/entity/EntityTypeWrapper.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/entity/EntityTypeWrapper.java new file mode 100644 index 000000000..af0d640c8 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/entity/EntityTypeWrapper.java @@ -0,0 +1,69 @@ +package net.pitan76.mcpitanlib.midohra.entity; + +import net.pitan76.mcpitanlib.api.text.TextComponent; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.api.util.EntityTypeUtil; + +public class EntityTypeWrapper { + private final net.minecraft.entity.EntityType entityType; + + protected EntityTypeWrapper() { + this.entityType = null; + } + + protected EntityTypeWrapper(net.minecraft.entity.EntityType entityType) { + this.entityType = entityType; + } + + public static EntityTypeWrapper of(net.minecraft.entity.EntityType entityType) { + return new EntityTypeWrapper(entityType); + } + + public static EntityTypeWrapper of() { + return new EntityTypeWrapper(); + } + + public boolean isExist() { + return !isEmpty(); + } + + public boolean isEmpty() { + return entityType == null; + } + + public net.minecraft.entity.EntityType get() { + return entityType; + } + + public CompatIdentifier getId() { + if (isEmpty()) return CompatIdentifier.empty(); + return EntityTypeUtil.toCompatID(entityType); + } + + public TextComponent getName() { + if (isEmpty()) return TextComponent.of(""); + return new TextComponent(EntityTypeUtil.getName(entityType)); + } + + public String getTranslationKey() { + if (isEmpty()) return ""; + return EntityTypeUtil.getTranslationKey(entityType); + } + + public boolean rawEquals(EntityTypeWrapper other) { + return entityType == other.entityType; + } + + @Override + public int hashCode() { + return get() != null ? get().hashCode() : 0; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + EntityTypeWrapper other = (EntityTypeWrapper) obj; + return rawEquals(other); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/entity/EntityTypes.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/entity/EntityTypes.java new file mode 100644 index 000000000..c4a866ef0 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/entity/EntityTypes.java @@ -0,0 +1,75 @@ +package net.pitan76.mcpitanlib.midohra.entity; + +import net.minecraft.entity.EntityType; + +public class EntityTypes { + public static final EntityTypeWrapper BOAT = EntityTypeWrapper.of(EntityType.BOAT); + public static final EntityTypeWrapper ACACIA_BOAT = EntityTypeWrapper.of(net.minecraft.entity.EntityType.BOAT); + public static final EntityTypeWrapper ACACIA_CHEST_BOAT = EntityTypeWrapper.of(EntityType.CHEST_BOAT); + public static final EntityTypeWrapper BIRCH_BOAT = EntityTypeWrapper.of(net.minecraft.entity.EntityType.BOAT); + public static final EntityTypeWrapper BIRCH_CHEST_BOAT = EntityTypeWrapper.of(net.minecraft.entity.EntityType.CHEST_BOAT); + public static final EntityTypeWrapper DARK_OAK_BOAT = EntityTypeWrapper.of(net.minecraft.entity.EntityType.BOAT); + public static final EntityTypeWrapper DARK_OAK_CHEST_BOAT = EntityTypeWrapper.of(net.minecraft.entity.EntityType.CHEST_BOAT); + public static final EntityTypeWrapper JUNGLE_BOAT = EntityTypeWrapper.of(net.minecraft.entity.EntityType.BOAT); + public static final EntityTypeWrapper JUNGLE_CHEST_BOAT = EntityTypeWrapper.of(net.minecraft.entity.EntityType.CHEST_BOAT); + public static final EntityTypeWrapper SPRUCE_BOAT = EntityTypeWrapper.of(net.minecraft.entity.EntityType.BOAT); + public static final EntityTypeWrapper SPRUCE_CHEST_BOAT = EntityTypeWrapper.of(net.minecraft.entity.EntityType.CHEST_BOAT); + public static final EntityTypeWrapper FURNACE_MINECART = EntityTypeWrapper.of(net.minecraft.entity.EntityType.FURNACE_MINECART); + public static final EntityTypeWrapper HOPPER_MINECART = EntityTypeWrapper.of(net.minecraft.entity.EntityType.HOPPER_MINECART); + public static final EntityTypeWrapper MINECART = EntityTypeWrapper.of(net.minecraft.entity.EntityType.MINECART); + public static final EntityTypeWrapper TNT_MINECART = EntityTypeWrapper.of(net.minecraft.entity.EntityType.TNT_MINECART); + public static final EntityTypeWrapper CHEST_MINECART = EntityTypeWrapper.of(EntityType.CHEST_MINECART); + public static final EntityTypeWrapper HORSE = EntityTypeWrapper.of(net.minecraft.entity.EntityType.HORSE); + public static final EntityTypeWrapper LLAMA = EntityTypeWrapper.of(net.minecraft.entity.EntityType.LLAMA); + + public static final EntityTypeWrapper ITEM = EntityTypeWrapper.of(net.minecraft.entity.EntityType.ITEM); + public static final EntityTypeWrapper ITEM_DISPLAY = EntityTypeWrapper.of(EntityType.ITEM_DISPLAY); + public static final EntityTypeWrapper ITEM_FRAME = EntityTypeWrapper.of(net.minecraft.entity.EntityType.ITEM_FRAME); + public static final EntityTypeWrapper GLOW_ITEM_FRAME = EntityTypeWrapper.of(EntityType.GLOW_ITEM_FRAME); + public static final EntityTypeWrapper EXPERIENCE_BOTTLE = EntityTypeWrapper.of(EntityType.EXPERIENCE_BOTTLE); + public static final EntityTypeWrapper EXPERIENCE_ORB = EntityTypeWrapper.of(EntityType.EXPERIENCE_ORB); + + public static final EntityTypeWrapper SNOWBALL = EntityTypeWrapper.of(EntityType.SNOWBALL); + public static final EntityTypeWrapper FIREBALL = EntityTypeWrapper.of(EntityType.FIREBALL); + public static final EntityTypeWrapper SMALL_FIREBALL = EntityTypeWrapper.of(EntityType.SMALL_FIREBALL); + public static final EntityTypeWrapper DRAGON_FIREBALL = EntityTypeWrapper.of(EntityType.DRAGON_FIREBALL); + public static final EntityTypeWrapper FIREWORK_ROCKET = EntityTypeWrapper.of(EntityType.FIREWORK_ROCKET); + + public static final EntityTypeWrapper ALLAY = EntityTypeWrapper.of(net.minecraft.entity.EntityType.ALLAY); + public static final EntityTypeWrapper AXOLOTL = EntityTypeWrapper.of(net.minecraft.entity.EntityType.AXOLOTL); + public static final EntityTypeWrapper BAT = EntityTypeWrapper.of(net.minecraft.entity.EntityType.BAT); + public static final EntityTypeWrapper BEE = EntityTypeWrapper.of(net.minecraft.entity.EntityType.BEE); + public static final EntityTypeWrapper BLAZE = EntityTypeWrapper.of(net.minecraft.entity.EntityType.BLAZE); + public static final EntityTypeWrapper CAT = EntityTypeWrapper.of(net.minecraft.entity.EntityType.CAT); + public static final EntityTypeWrapper CHICKEN = EntityTypeWrapper.of(net.minecraft.entity.EntityType.CHICKEN); + public static final EntityTypeWrapper COD = EntityTypeWrapper.of(net.minecraft.entity.EntityType.COD); + public static final EntityTypeWrapper COW = EntityTypeWrapper.of(net.minecraft.entity.EntityType.COW); + public static final EntityTypeWrapper CREEPER = EntityTypeWrapper.of(net.minecraft.entity.EntityType.CREEPER); + public static final EntityTypeWrapper DOLPHIN = EntityTypeWrapper.of(net.minecraft.entity.EntityType.DOLPHIN); + public static final EntityTypeWrapper DONKEY = EntityTypeWrapper.of(net.minecraft.entity.EntityType.DONKEY); + public static final EntityTypeWrapper DROWNED = EntityTypeWrapper.of(net.minecraft.entity.EntityType.DROWNED); + public static final EntityTypeWrapper ELDER_GUARDIAN = EntityTypeWrapper.of(net.minecraft.entity.EntityType.ELDER_GUARDIAN); + public static final EntityTypeWrapper ENDER_DRAGON = EntityTypeWrapper.of(net.minecraft.entity.EntityType.ENDER_DRAGON); + public static final EntityTypeWrapper ENDERMAN = EntityTypeWrapper.of(net.minecraft.entity.EntityType.ENDERMAN); + public static final EntityTypeWrapper ENDERMITE = EntityTypeWrapper.of(net.minecraft.entity.EntityType.ENDERMITE); + public static final EntityTypeWrapper EVOKER = EntityTypeWrapper.of(net.minecraft.entity.EntityType.EVOKER); + public static final EntityTypeWrapper FOX = EntityTypeWrapper.of(net.minecraft.entity.EntityType.FOX); + public static final EntityTypeWrapper FROG = EntityTypeWrapper.of(net.minecraft.entity.EntityType.FROG); + public static final EntityTypeWrapper GHAST = EntityTypeWrapper.of(net.minecraft.entity.EntityType.GHAST); + public static final EntityTypeWrapper GIANT = EntityTypeWrapper.of(net.minecraft.entity.EntityType.GIANT); + public static final EntityTypeWrapper GLOW_SQUID = EntityTypeWrapper.of(net.minecraft.entity.EntityType.GLOW_SQUID); + public static final EntityTypeWrapper GOAT = EntityTypeWrapper.of(net.minecraft.entity.EntityType.GOAT); + public static final EntityTypeWrapper GUARDIAN = EntityTypeWrapper.of(net.minecraft.entity.EntityType.GUARDIAN); + public static final EntityTypeWrapper HUSK = EntityTypeWrapper.of(net.minecraft.entity.EntityType.HUSK); + public static final EntityTypeWrapper ILLUSIONER = EntityTypeWrapper.of(net.minecraft.entity.EntityType.ILLUSIONER); + public static final EntityTypeWrapper IRON_GOLEM = EntityTypeWrapper.of(net.minecraft.entity.EntityType.IRON_GOLEM); + public static final EntityTypeWrapper LLAMA_SPIT = EntityTypeWrapper.of(net.minecraft.entity.EntityType.LLAMA_SPIT); + public static final EntityTypeWrapper MAGMA_CUBE = EntityTypeWrapper.of(net.minecraft.entity.EntityType.MAGMA_CUBE); + public static final EntityTypeWrapper MARKER = EntityTypeWrapper.of(net.minecraft.entity.EntityType.MARKER); + public static final EntityTypeWrapper MOOSHROOM = EntityTypeWrapper.of(net.minecraft.entity.EntityType.MOOSHROOM); + public static final EntityTypeWrapper MULE = EntityTypeWrapper.of(net.minecraft.entity.EntityType.MULE); + public static final EntityTypeWrapper SKELETON = EntityTypeWrapper.of(net.minecraft.entity.EntityType.SKELETON); + public static final EntityTypeWrapper VILLAGER = EntityTypeWrapper.of(net.minecraft.entity.EntityType.VILLAGER); + public static final EntityTypeWrapper ZOMBIE = EntityTypeWrapper.of(net.minecraft.entity.EntityType.ZOMBIE); + public static final EntityTypeWrapper ZOMBIE_VILLAGER = EntityTypeWrapper.of(net.minecraft.entity.EntityType.ZOMBIE_VILLAGER); +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/fluid/FluidWrapper.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/fluid/FluidWrapper.java new file mode 100644 index 000000000..720de5698 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/fluid/FluidWrapper.java @@ -0,0 +1,100 @@ +package net.pitan76.mcpitanlib.midohra.fluid; + +import net.minecraft.fluid.FluidState; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.api.util.FluidStateUtil; +import net.pitan76.mcpitanlib.api.util.FluidUtil; +import net.pitan76.mcpitanlib.midohra.item.ItemWrapper; +import org.jetbrains.annotations.Nullable; + +public class FluidWrapper { + private final net.minecraft.fluid.Fluid fluid; + + protected FluidWrapper() { + this.fluid = null; + } + + protected FluidWrapper(net.minecraft.fluid.Fluid fluid) { + this.fluid = fluid; + } + + public static FluidWrapper of(net.minecraft.fluid.Fluid fluid) { + return new FluidWrapper(fluid); + } + + public static FluidWrapper of() { + return new FluidWrapper(); + } + + public static FluidWrapper of(CompatIdentifier id) { + if (FluidUtil.isExist(id)) + return of(FluidUtil.fromId(id)); + + return of(); + } + + public static FluidWrapper of(CompatIdentifier id, CompatIdentifier... ids) { + if (of(id).isExist()) return of(id); + + for (CompatIdentifier id1 : ids) { + if (of(id1).isExist()) + return of(id1); + } + + return of(); + } + + public boolean isExist() { + return !isEmpty(); + } + + public boolean isEmpty() { + return get() == null; + } + + @Nullable + public net.minecraft.fluid.Fluid get() { + return fluid; + } + + public net.minecraft.fluid.Fluid gerOrDefault(net.minecraft.fluid.Fluid defaultFluid) { + return isEmpty() ? defaultFluid : get(); + } + + public CompatIdentifier getId() { + if (isEmpty()) + return CompatIdentifier.empty(); + + return FluidUtil.toCompatId(get()); + } + + public String getName() { + if (isEmpty()) return ""; + return get().toString(); + } + + public FluidState getDefaultState() { + return FluidStateUtil.getDefaultState(get()); + } + + public ItemWrapper getBucketItem() { + return ItemWrapper.of(FluidUtil.getBucketItem(get())); + } + + public boolean rawEquals(FluidWrapper fluid) { + return get() == fluid.get(); + } + + @Override + public int hashCode() { + return isEmpty() ? 0 : get().hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + FluidWrapper other = (FluidWrapper) obj; + return rawEquals(other); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/fluid/Fluids.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/fluid/Fluids.java new file mode 100644 index 000000000..15a200faa --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/fluid/Fluids.java @@ -0,0 +1,9 @@ +package net.pitan76.mcpitanlib.midohra.fluid; + +public class Fluids { + public static final FluidWrapper EMPTY = FluidWrapper.of(net.minecraft.fluid.Fluids.EMPTY); + public static final FluidWrapper WATER = FluidWrapper.of(net.minecraft.fluid.Fluids.WATER); + public static final FluidWrapper LAVA = FluidWrapper.of(net.minecraft.fluid.Fluids.LAVA); + public static final FluidWrapper FLOWING_WATER = FluidWrapper.of(net.minecraft.fluid.Fluids.FLOWING_WATER); + public static final FluidWrapper FLOWING_LAVA = FluidWrapper.of(net.minecraft.fluid.Fluids.FLOWING_LAVA); +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/holder/BlockStatePropertyHolder.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/holder/BlockStatePropertyHolder.java new file mode 100644 index 000000000..9601ef3d1 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/holder/BlockStatePropertyHolder.java @@ -0,0 +1,35 @@ +package net.pitan76.mcpitanlib.midohra.holder; + +import net.pitan76.mcpitanlib.api.state.property.DirectionProperty; +import net.pitan76.mcpitanlib.api.state.property.IProperty; +import net.pitan76.mcpitanlib.midohra.block.BlockState; +import net.pitan76.mcpitanlib.midohra.util.math.Direction; + +public interface BlockStatePropertyHolder { + BlockState getBlockState(); + + default , V extends T> BlockState with(IProperty property, V value) { + return getBlockState().with(property, value); + } + + default boolean has(IProperty property) { + return getBlockState().contains(property); + } + + default > T get(IProperty property) { + return getBlockState().get(property); + } + + default > BlockState cycle(IProperty property) { + return getBlockState().cycle(property); + } + + // DirectionProperty + default BlockState with(DirectionProperty property, Direction value) { + return with(property, value.toMinecraft()); + } + + default Direction get(DirectionProperty property) { + return Direction.of(get((IProperty) property)); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/item/ItemGroupWrapper.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/item/ItemGroupWrapper.java new file mode 100644 index 000000000..2773aaa7a --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/item/ItemGroupWrapper.java @@ -0,0 +1,57 @@ +package net.pitan76.mcpitanlib.midohra.item; + +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.api.util.item.ItemGroupUtil; + +public class ItemGroupWrapper { + private final net.minecraft.item.ItemGroup itemGroup; + + protected ItemGroupWrapper() { + this.itemGroup = null; + } + + protected ItemGroupWrapper(net.minecraft.item.ItemGroup itemGroup) { + this.itemGroup = itemGroup; + } + + public static ItemGroupWrapper of(net.minecraft.item.ItemGroup itemGroup) { + return new ItemGroupWrapper(itemGroup); + } + + public static ItemGroupWrapper of(CompatIdentifier id) { + if (ItemGroupUtil.isExist(id)) + return of(ItemGroupUtil.fromId(id)); + + return of(); + } + + public static ItemGroupWrapper of() { + return new ItemGroupWrapper(); + } + + public boolean isPresent() { + return !isEmpty(); + } + + public boolean isEmpty() { + return itemGroup == null; + } + + public net.minecraft.item.ItemGroup get() { + return itemGroup; + } + + public CompatIdentifier getId() { + if (isEmpty()) return CompatIdentifier.empty(); + return ItemGroupUtil.toCompatID(itemGroup); + } + + public ItemStack getIcon() { + if (isEmpty()) return ItemStack.EMPTY; + return ItemStack.of(itemGroup.getIcon()); + } + + public boolean rawEquals(ItemGroupWrapper other) { + return itemGroup == other.itemGroup; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/item/ItemGroups.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/item/ItemGroups.java new file mode 100644 index 000000000..7ceefce5a --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/item/ItemGroups.java @@ -0,0 +1,30 @@ +package net.pitan76.mcpitanlib.midohra.item; + +import net.pitan76.mcpitanlib.api.item.DefaultItemGroups; + +public class ItemGroups { + public static final ItemGroupWrapper BUILDING_BLOCKS = of(DefaultItemGroups.BUILDING_BLOCKS); + public static final ItemGroupWrapper COLORED_BLOCKS = of(DefaultItemGroups.COLORED_BLOCKS); + public static final ItemGroupWrapper NATURAL = of(DefaultItemGroups.NATURAL); + public static final ItemGroupWrapper FUNCTIONAL = of(DefaultItemGroups.FUNCTIONAL); + public static final ItemGroupWrapper REDSTONE = of(DefaultItemGroups.REDSTONE); + public static final ItemGroupWrapper HOTBAR = of(DefaultItemGroups.HOTBAR); + public static final ItemGroupWrapper SEARCH = of(DefaultItemGroups.SEARCH); + public static final ItemGroupWrapper TOOLS = of(DefaultItemGroups.TOOLS); + public static final ItemGroupWrapper COMBAT = of(DefaultItemGroups.COMBAT); + public static final ItemGroupWrapper FOOD_AND_DRINK = of(DefaultItemGroups.FOOD_AND_DRINK); + public static final ItemGroupWrapper INGREDIENTS = of(DefaultItemGroups.INGREDIENTS); + public static final ItemGroupWrapper SPAWN_EGGS = of(DefaultItemGroups.SPAWN_EGGS); + public static final ItemGroupWrapper OPERATOR = of(DefaultItemGroups.OPERATOR); + public static final ItemGroupWrapper INVENTORY = of(DefaultItemGroups.INVENTORY); + + // - 1.19.2 Item Group + public static final ItemGroupWrapper BREWING = FOOD_AND_DRINK; + public static final ItemGroupWrapper TRANSPORTATION = FUNCTIONAL; + public static final ItemGroupWrapper DECORATIONS = NATURAL; + public static final ItemGroupWrapper MISC = INGREDIENTS; + + private static ItemGroupWrapper of(net.minecraft.item.ItemGroup itemGroup) { + return ItemGroupWrapper.of(itemGroup); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/item/ItemStack.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/item/ItemStack.java new file mode 100644 index 000000000..5081a2cb0 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/item/ItemStack.java @@ -0,0 +1,177 @@ +package net.pitan76.mcpitanlib.midohra.item; + +import net.minecraft.item.Item; +import net.minecraft.item.ItemConvertible; +import net.minecraft.nbt.NbtCompound; +import net.minecraft.text.Text; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.enchantment.CompatEnchantment; +import net.pitan76.mcpitanlib.api.item.stack.LoreUtil; +import net.pitan76.mcpitanlib.api.util.*; +import org.jetbrains.annotations.Nullable; + +import java.util.List; +import java.util.Map; + +public class ItemStack { + private final net.minecraft.item.ItemStack stack; + public static final ItemStack EMPTY = new ItemStack(ItemStackUtil.empty()); + + protected ItemStack(net.minecraft.item.ItemStack stack) { + this.stack = stack; + } + + public static ItemStack of(net.minecraft.item.ItemStack stack) { + if (stack == null || stack.isEmpty()) + return EMPTY; + + return new ItemStack(stack); + } + + public static ItemStack of(ItemConvertible item) { + return new Builder().item(item).build(); + } + + public static ItemStack of(ItemConvertible item, int count) { + return new Builder().item(item).count(count).build(); + } + + public static ItemStack empty() { + return EMPTY; + } + + public int getCount() { + return stack.getCount(); + } + + public void setCount(int count) { + stack.setCount(count); + } + + public NbtCompound getCustomNbt() { + return CustomDataUtil.getNbt(stack); + } + + public void setCustomNbt(NbtCompound nbt) { + CustomDataUtil.setNbt(stack, nbt); + } + + public void removeCustomNbt() { + CustomDataUtil.remove(stack); + } + + public boolean hasCustomNbt() { + return CustomDataUtil.hasNbt(stack); + } + + public boolean isEmpty() { + return stack.isEmpty(); + } + + public CompatIdentifier getItemId() { + return ItemUtil.toCompatID(stack.getItem()); + } + + public ItemStack copy() { + return new ItemStack(stack.copy()); + } + + public ItemStack copyWithCount(int count) { + return new ItemStack(stack.copyWithCount(count)); + } + + public Map getEnchantments(@Nullable World world) { + return EnchantmentUtil.getEnchantment(stack, world); + } + + public void setEnchantments(Map enchantments, @Nullable World world) { + EnchantmentUtil.setEnchantment(stack, enchantments, world); + } + + public int getMaxCount() { + return ItemStackUtil.getMaxCount(stack); + } + + public boolean hasLore() { + return LoreUtil.hasLore(stack); + } + + public List getLore() { + return LoreUtil.getLore(stack); + } + + public List getLoreAsStringList() { + return LoreUtil.getLoreAsStringList(stack); + } + + public void setLore(List lore) { + LoreUtil.setLore(stack, lore); + } + + public void setLoreString(List lore) { + LoreUtil.setLoreStringList(stack, lore); + } + + public void setLore(String lore) { + LoreUtil.setLore(stack, lore); + } + + @Deprecated + public net.minecraft.item.ItemStack toMinecraft() { + return stack; + } + + public ItemWrapper getItem() { + if (isEmpty()) + return ItemWrapper.of(); + + return ItemWrapper.of(getRawItem()); + } + + public Item getRawItem() { + return ItemStackUtil.getItem(stack); + } + + public static class Builder { + + protected CompatIdentifier id; + protected int count = 1; + protected NbtCompound nbt = NbtUtil.create(); + + public Builder() { + + } + + public Builder item(CompatIdentifier id) { + this.id = id; + return this; + } + + public Builder item(ItemConvertible item) { + this.id = ItemUtil.toCompatID(item.asItem()); + return this; + } + + public Builder count(int count) { + this.count = count; + return this; + } + + public Builder nbt(NbtCompound nbt) { + this.nbt = nbt; + return this; + } + + public ItemStack build() { + net.minecraft.item.ItemStack stack = new net.minecraft.item.ItemStack(ItemUtil.fromId(id), count); + CustomDataUtil.setNbt(stack, nbt); + + return new ItemStack(stack); + } + } + + @Override + public String toString() { + return stack.toString(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/item/ItemWrapper.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/item/ItemWrapper.java new file mode 100644 index 000000000..c16fc5f0f --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/item/ItemWrapper.java @@ -0,0 +1,111 @@ +package net.pitan76.mcpitanlib.midohra.item; + +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.api.util.ItemStackUtil; +import net.pitan76.mcpitanlib.api.util.item.ItemUtil; +import net.pitan76.mcpitanlib.midohra.block.BlockWrapper; +import org.jetbrains.annotations.Nullable; + +public class ItemWrapper { + private final net.minecraft.item.Item item; + + protected ItemWrapper() { + this.item = null; + } + + protected ItemWrapper(net.minecraft.item.Item item) { + this.item = item; + } + + public static ItemWrapper of(net.minecraft.item.Item item) { + return new ItemWrapper(item); + } + + public static ItemWrapper of() { + return new ItemWrapper(); + } + + public static ItemWrapper of(CompatIdentifier id) { + if (ItemUtil.isExist(id)) + return of(ItemUtil.fromId(id)); + + return of(); + } + + public static ItemWrapper of(CompatIdentifier id, CompatIdentifier... ids) { + if (of(id).isPresent()) return of(id); + + for (CompatIdentifier id1 : ids) { + if (of(id1).isPresent()) + return of(id1); + } + + return of(); + } + + public boolean isPresent() { + return !isEmpty(); + } + + public boolean isEmpty() { + return get() == null; + } + + public boolean isAir() { + return isEmpty() || get() == net.minecraft.item.Items.AIR; + } + + @Nullable + public net.minecraft.item.Item get() { + return item; + } + + public net.minecraft.item.Item gerOrDefault(net.minecraft.item.Item defaultItem) { + return isEmpty() ? defaultItem : get(); + } + + public CompatIdentifier getId() { + if (isEmpty()) + return CompatIdentifier.empty(); + + return ItemUtil.toId(get()); + } + + public String getName() { + if (isEmpty()) return ""; + return ItemUtil.getNameAsString(get()); + } + + public String getTranslationKey() { + if (isEmpty()) return ""; + return ItemUtil.getTranslationKey(get()); + } + + public ItemStack createStack(int count) { + if (isEmpty()) return ItemStack.EMPTY; + return ItemStack.of(ItemStackUtil.create(get(), count)); + } + + public ItemStack createStack() { + return createStack(1); + } + + public boolean isInTag(CompatIdentifier id) { + return ItemUtil.isInTag(get(), id); + } + + public boolean isBlock() { + return !isEmpty() && get() instanceof net.minecraft.item.BlockItem; + } + + public BlockWrapper asBlock() { + if (!isBlock()) + return BlockWrapper.of(); + + return BlockWrapper.of(((net.minecraft.item.BlockItem) get()).getBlock()); + } + + public boolean rawEquals(ItemWrapper item) { + return get() == item.get(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/item/Items.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/item/Items.java new file mode 100644 index 000000000..07adf908a --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/item/Items.java @@ -0,0 +1,20 @@ +package net.pitan76.mcpitanlib.midohra.item; + +public class Items { + + public static ItemWrapper AIR = of(net.minecraft.item.Items.AIR); + public static ItemWrapper DIRT = of(net.minecraft.item.Items.DIRT); + public static ItemWrapper GRASS_BLOCK = of(net.minecraft.item.Items.GRASS_BLOCK); + public static ItemWrapper STONE = of(net.minecraft.item.Items.STONE); + public static ItemWrapper SAND = of(net.minecraft.item.Items.SAND); + public static ItemWrapper COBBLESTONE = of(net.minecraft.item.Items.COBBLESTONE); + public static ItemWrapper OAK_LOG = of(net.minecraft.item.Items.OAK_LOG); + public static ItemWrapper OAK_PLANKS = of(net.minecraft.item.Items.OAK_PLANKS); + public static ItemWrapper OAK_LEAVES = of(net.minecraft.item.Items.OAK_LEAVES); + public static ItemWrapper WHITE_WOOL = of(net.minecraft.item.Items.WHITE_WOOL); + public static ItemWrapper GLASS = of(net.minecraft.item.Items.GLASS); + + public static ItemWrapper of(net.minecraft.item.Item item) { + return ItemWrapper.of(item); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/item/SupplierItemWrapper.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/item/SupplierItemWrapper.java new file mode 100644 index 000000000..c39629242 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/item/SupplierItemWrapper.java @@ -0,0 +1,22 @@ +package net.pitan76.mcpitanlib.midohra.item; + +import net.minecraft.item.Item; + +import java.util.function.Supplier; + +public class SupplierItemWrapper extends ItemWrapper { + private final Supplier supplier; + + protected SupplierItemWrapper(Supplier supplier) { + this.supplier = supplier; + } + + public static SupplierItemWrapper of(Supplier supplier) { + return new SupplierItemWrapper(supplier); + } + + @Override + public Item get() { + return supplier.get(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/nbt/ElementConvertible.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/nbt/ElementConvertible.java new file mode 100644 index 000000000..d92a636ac --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/nbt/ElementConvertible.java @@ -0,0 +1,9 @@ +package net.pitan76.mcpitanlib.midohra.nbt; + +public interface ElementConvertible { + NbtElement toElement(); + + default net.minecraft.nbt.NbtElement toMinecraftNbtElement() { + return toElement().toMinecraft(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/nbt/NbtCompound.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/nbt/NbtCompound.java new file mode 100644 index 000000000..6615a06be --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/nbt/NbtCompound.java @@ -0,0 +1,146 @@ +package net.pitan76.mcpitanlib.midohra.nbt; + +import net.pitan76.mcpitanlib.api.registry.CompatRegistryLookup; +import net.pitan76.mcpitanlib.api.util.NbtUtil; +import net.pitan76.mcpitanlib.midohra.item.ItemStack; + +import java.util.UUID; + +@SuppressWarnings("deprecation") +public class NbtCompound implements ElementConvertible { + protected final net.minecraft.nbt.NbtCompound nbt; + + protected NbtCompound(net.minecraft.nbt.NbtCompound nbt) { + this.nbt = nbt; + } + + public static NbtCompound of(net.minecraft.nbt.NbtCompound nbt) { + return new NbtCompound(nbt); + } + + public static NbtCompound of() { + return new NbtCompound(NbtUtil.create()); + } + + public NbtCompound copy() { + return new NbtCompound(NbtUtil.copy(nbt)); + } + + public boolean has(String key) { + return NbtUtil.has(nbt, key); + } + + public void putByte(String key, byte value) { + NbtUtil.putByte(nbt, key, value); + } + + public byte getByte(String key) { + return NbtUtil.getByte(nbt, key); + } + + public void putShort(String key, short value) { + NbtUtil.putShort(nbt, key, value); + } + + public short getShort(String key) { + return NbtUtil.getShort(nbt, key); + } + + public void putInt(String key, int value) { + NbtUtil.putInt(nbt, key, value); + } + + public int getInt(String key) { + return NbtUtil.getInt(nbt, key); + } + + public void putLong(String key, long value) { + NbtUtil.putLong(nbt, key, value); + } + + public long getLong(String key) { + return NbtUtil.getLong(nbt, key); + } + + public void putFloat(String key, float value) { + NbtUtil.putFloat(nbt, key, value); + } + + public float getFloat(String key) { + return NbtUtil.getFloat(nbt, key); + } + + public void putDouble(String key, double value) { + NbtUtil.putDouble(nbt, key, value); + } + + public double getDouble(String key) { + return NbtUtil.getDouble(nbt, key); + } + + public void putString(String key, String value) { + NbtUtil.putString(nbt, key, value); + } + + public String getString(String key) { + return NbtUtil.getString(nbt, key); + } + + public void putBoolean(String key, boolean value) { + NbtUtil.putBoolean(nbt, key, value); + } + + public boolean getBoolean(String key) { + return NbtUtil.getBoolean(nbt, key); + } + + public void putUuid(String key, UUID value) { + NbtUtil.putUuid(nbt, key, value); + } + + public UUID getUuid(String key) { + return NbtUtil.getUuid(nbt, key); + } + + public void putItemStack(String key, net.pitan76.mcpitanlib.midohra.item.ItemStack stack, CompatRegistryLookup registryLookup) { + NbtUtil.putItemStack(nbt, key, stack.toMinecraft(), registryLookup); + } + + public net.pitan76.mcpitanlib.midohra.item.ItemStack getItemStack(String key, CompatRegistryLookup registryLookup) { + return ItemStack.of(NbtUtil.getItemStack(nbt, key, registryLookup).get()); + } + + public void put(String key, NbtCompound compound) { + NbtUtil.put(nbt, key, compound.nbt); + } + + public void put(String key, net.minecraft.nbt.NbtCompound nbt) { + NbtUtil.put(this.nbt, key, nbt); + } + + public void put(String key, ElementConvertible element) { + NbtUtil.put(nbt, key, element.toMinecraftNbtElement()); + } + + public NbtCompound getCompound(String key) { + return new NbtCompound(NbtUtil.get(nbt, key)); + } + + public NbtElement get(String key) { + return NbtElement.of(NbtUtil.getElement(nbt, key)); + } + + public net.minecraft.nbt.NbtCompound toMinecraft() { + return nbt; + } + + @Override + public String toString() { + return nbt.toString(); + } + + @Override + public NbtElement toElement() { + return NbtElement.of(nbt); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/nbt/NbtElement.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/nbt/NbtElement.java new file mode 100644 index 000000000..ac7d84d13 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/nbt/NbtElement.java @@ -0,0 +1,49 @@ +package net.pitan76.mcpitanlib.midohra.nbt; + +import net.minecraft.nbt.NbtType; + +public class NbtElement implements ElementConvertible { + protected final net.minecraft.nbt.NbtElement nbt; + + protected NbtElement(net.minecraft.nbt.NbtElement nbt) { + this.nbt = nbt; + } + + public static NbtElement of(net.minecraft.nbt.NbtElement nbt) { + return new NbtElement(nbt); + } + + public NbtElement copy() { + return new NbtElement(nbt.copy()); + } + + public byte getType() { + return nbt.getType(); + } + + public NbtType getNbtType() { + return nbt.getNbtType(); + } + + public int getSizeInBytes() { + return nbt.getSizeInBytes(); + } + + @Override + public String toString() { + return nbt.toString(); + } + + public net.minecraft.nbt.NbtElement toMinecraft() { + return nbt; + } + + @Override + public NbtElement toElement() { + return this; + } + + public String asString() { + return nbt.asString(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/nbt/NbtList.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/nbt/NbtList.java new file mode 100644 index 000000000..9881d8bdb --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/nbt/NbtList.java @@ -0,0 +1,110 @@ +package net.pitan76.mcpitanlib.midohra.nbt; + +import java.util.AbstractList; +import java.util.Optional; + +@SuppressWarnings("deprecation") +public class NbtList extends AbstractList implements ElementConvertible { + protected final net.minecraft.nbt.NbtList nbtList; + + protected NbtList(net.minecraft.nbt.NbtList nbtList) { + this.nbtList = nbtList; + } + + public static NbtList of(net.minecraft.nbt.NbtList nbtList) { + return new NbtList(nbtList); + } + + public static Optional ofOptional(NbtElement nbtElement) { + if (nbtElement.toMinecraft() instanceof net.minecraft.nbt.NbtList) + return Optional.of(new NbtList((net.minecraft.nbt.NbtList) nbtElement.toMinecraft())); + + return Optional.empty(); + } + + public NbtList copy() { + return new NbtList(nbtList.copy()); + } + + @Override + public int size() { + return nbtList.size(); + } + + public byte getType() { + return nbtList.getType(); + } + + @Override + public NbtElement get(int index) { + return NbtElement.of(nbtList.get(index)); + } + + public boolean add(net.minecraft.nbt.NbtElement nbtElement) { + return nbtList.add(nbtElement); + } + + @Override + public boolean add(NbtElement nbtElement) { + return add(nbtElement.toMinecraft()); + } + + public void add(int index, net.minecraft.nbt.NbtElement nbtElement) { + nbtList.add(index, nbtElement); + } + + @Override + public void add(int index, NbtElement nbtElement) { + add(index, nbtElement.toMinecraft()); + } + + @Override + public NbtElement set(int index, NbtElement element) { + return NbtElement.of(nbtList.set(index, element.toMinecraft())); + } + + @Override + public NbtElement remove(int index) { + return NbtElement.of(nbtList.remove(index)); + } + + @Override + public boolean isEmpty() { + return nbtList.isEmpty(); + } + + @Override + public void clear() { + nbtList.clear(); + } + + public String asString() { + return nbtList.asString(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + + return o instanceof NbtList && nbtList.equals(((NbtList) o).nbtList); + } + + @Override + public int hashCode() { + return nbtList.hashCode(); + } + + @Override + public String toString() { + return nbtList.toString(); + } + + public net.minecraft.nbt.NbtList toMinecraft() { + return nbtList; + } + + @Override + public NbtElement toElement() { + return NbtElement.of(nbtList); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/network/CompatPacketByteBuf.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/network/CompatPacketByteBuf.java new file mode 100644 index 000000000..c2c5566fe --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/network/CompatPacketByteBuf.java @@ -0,0 +1,116 @@ +package net.pitan76.mcpitanlib.midohra.network; + +import net.minecraft.network.PacketByteBuf; +import net.pitan76.mcpitanlib.api.network.PacketByteUtil; +import net.pitan76.mcpitanlib.midohra.util.math.BlockPos; + +public class CompatPacketByteBuf extends PacketByteBuf { + public CompatPacketByteBuf(PacketByteBuf buf) { + super(buf); + } + + public CompatPacketByteBuf() { + super(PacketByteUtil.create()); + } + + public static CompatPacketByteBuf create() { + return new CompatPacketByteBuf(); + } + + public static CompatPacketByteBuf of(PacketByteBuf buf) { + return new CompatPacketByteBuf(buf); + } + + public PacketByteBuf getRaw() { + return this; + } + + public CompatPacketByteBuf writeInt(int value) { + super.writeInt(value); + return this; + } + + public int readInt() { + return super.readInt(); + } + + public CompatPacketByteBuf writeLong(long value) { + super.writeLong(value); + return this; + } + + public long readLong() { + return super.readLong(); + } + + public CompatPacketByteBuf writeBoolean(boolean value) { + super.writeBoolean(value); + return this; + } + + public boolean readBoolean() { + return super.readBoolean(); + } + + public CompatPacketByteBuf writeFloat(float value) { + super.writeFloat(value); + return this; + } + + public float readFloat() { + return super.readFloat(); + } + + public CompatPacketByteBuf writeDouble(double value) { + super.writeDouble(value); + return this; + } + + public double readDouble() { + return super.readDouble(); + } + + public CompatPacketByteBuf writeShort(short value) { + super.writeShort(value); + return this; + } + + public short readShort() { + return super.readShort(); + } + + public CompatPacketByteBuf writeByteArray(byte[] array) { + super.writeByteArray(array); + return this; + } + + public byte[] readByteArray() { + return super.readByteArray(); + } + + public CompatPacketByteBuf writeString(String string) { + super.writeString(string); + return this; + } + + public String readString() { + return super.readString(); + } + + public CompatPacketByteBuf writeBlockPos(net.minecraft.util.math.BlockPos pos) { + super.writeBlockPos(pos); + return this; + } + + public net.minecraft.util.math.BlockPos readBlockPos() { + return super.readBlockPos(); + } + + public CompatPacketByteBuf writeBlockPos(BlockPos pos) { + return writeBlockPos(pos.toMinecraft()); + } + + public BlockPos readBlockPosMidohra() { + return BlockPos.of(readBlockPos()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/recipe/CraftingRecipe.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/recipe/CraftingRecipe.java new file mode 100644 index 000000000..1b452dbef --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/recipe/CraftingRecipe.java @@ -0,0 +1,74 @@ +package net.pitan76.mcpitanlib.midohra.recipe; + +import net.minecraft.recipe.book.CraftingRecipeCategory; +import net.minecraft.util.collection.DefaultedList; +import net.pitan76.mcpitanlib.api.registry.CompatRegistryLookup; +import net.pitan76.mcpitanlib.api.util.collection.ItemStackList; +import net.pitan76.mcpitanlib.midohra.item.ItemStack; +import net.pitan76.mcpitanlib.midohra.recipe.input.CraftingRecipeInputOrInventory; +import net.pitan76.mcpitanlib.midohra.world.World; + +public class CraftingRecipe extends Recipe { + private final net.minecraft.recipe.CraftingRecipe recipe; + + protected CraftingRecipe(net.minecraft.recipe.CraftingRecipe recipe) { + super(null); + this.recipe = recipe; + } + + public static CraftingRecipe of(net.minecraft.recipe.CraftingRecipe recipe) { + return new CraftingRecipe(recipe); + } + + public net.minecraft.recipe.CraftingRecipe getRaw() { + return recipe; + } + + public net.minecraft.recipe.CraftingRecipe toMinecraft() { + return getRaw(); + } + + public CraftingRecipeCategory getRawCategory() { + return getRaw().getCategory(); + } + + public boolean matches(CraftingRecipeInputOrInventory input, World world) { + return getRaw().matches(input.getRaw(), world.getRaw()); + } + + public net.minecraft.item.ItemStack craft(CraftingRecipeInputOrInventory input, World world) { + return getRaw().craft(input.getRaw(), world.getRaw().getRegistryManager()); + } + + public ItemStack craftMidohra(CraftingRecipeInputOrInventory input, World world) { + return ItemStack.of(craft(input, world)); + } + + public net.minecraft.item.ItemStack craft(CraftingRecipeInputOrInventory input, CompatRegistryLookup registryLookup) { + return getRaw().craft(input.getRaw(), registryLookup.getRegistryLookup()); + } + + public net.minecraft.item.ItemStack craft(CraftingRecipeInputOrInventory input, net.minecraft.world.World world) { + return getRaw().craft(input.getRaw(), world.getRegistryManager()); + } + + public DefaultedList getRecipeRemaindersDefaultedList(CraftingRecipeInputOrInventory input) { + return getRaw().getRemainder(input.getRaw()); + } + + public ItemStackList getRecipeRemainders(CraftingRecipeInputOrInventory input) { + return ItemStackList.of(getRecipeRemaindersDefaultedList(input)); + } + + public net.minecraft.item.ItemStack getOutput(CraftingRecipeInputOrInventory input, net.minecraft.world.World world) { + return getRaw().getResult(world.getRegistryManager()); + } + + public net.minecraft.item.ItemStack getOutput(CraftingRecipeInputOrInventory input, World world) { + return getOutput(input, world.getRaw()); + } + + public ItemStack getOutputMidohra(CraftingRecipeInputOrInventory input, World world) { + return ItemStack.of(getOutput(input, world)); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/recipe/Ingredient.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/recipe/Ingredient.java new file mode 100644 index 000000000..496089b5f --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/recipe/Ingredient.java @@ -0,0 +1,95 @@ +package net.pitan76.mcpitanlib.midohra.recipe; + +import net.minecraft.item.Item; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.api.util.IngredientUtil; +import net.pitan76.mcpitanlib.midohra.item.ItemStack; +import net.pitan76.mcpitanlib.midohra.item.ItemWrapper; + +import java.util.ArrayList; +import java.util.List; + +public class Ingredient { + private final net.minecraft.recipe.Ingredient ingredient; + + protected Ingredient(net.minecraft.recipe.Ingredient ingredient) { + this.ingredient = ingredient; + } + + public static Ingredient of(net.minecraft.recipe.Ingredient ingredient) { + return new Ingredient(ingredient); + } + + public static Ingredient ofItems(Item... items) { + return of(net.minecraft.recipe.Ingredient.ofItems(items)); + } + + public static Ingredient ofItem(Item items) { + return of(net.minecraft.recipe.Ingredient.ofItems(items)); + } + + public static Ingredient fromTagById(CompatIdentifier id) { + return of(IngredientUtil.fromTagByIdentifier(id)); + } + + public static Ingredient fromTagByString(String id) { + return of(IngredientUtil.fromTagByString(id)); + } + + public net.minecraft.recipe.Ingredient getRaw() { + return ingredient; + } + + public net.minecraft.recipe.Ingredient toMinecraft() { + return getRaw(); + } + + public boolean test(net.minecraft.item.ItemStack stack) { + return ingredient.test(stack); + } + + public boolean equals(Ingredient other) { + return ingredient.equals(other.getRaw()); + } + + public List getMatchingItems() { + return IngredientUtil.getItems(ingredient); + } + + public it.unimi.dsi.fastutil.ints.IntList getMatchingStacksIds() { + return IngredientUtil.getMatchingStacksIds(ingredient); + } + + public List getMatchingStacksAsList() { + return IngredientUtil.getMatchingStacksAsList(ingredient); + } + + public net.minecraft.item.ItemStack[] getMatchingStacks() { + return IngredientUtil.getMatchingStacks(ingredient); + } + + public List getMatchingItemWrappers() { + List wrappers = new ArrayList<>(); + + for (Item item : getMatchingItems()) { + wrappers.add(ItemWrapper.of(item)); + } + + return wrappers; + } + + public List getMatchingStacksAsMidohraList() { + List stacks = new ArrayList<>(); + + for (net.minecraft.item.ItemStack stack : getMatchingStacksAsList()) { + stacks.add(ItemStack.of(stack)); + } + + return stacks; + } + + public ItemStack[] getMatchingStacksAsMidohra() { + List stacks = getMatchingStacksAsMidohraList(); + return stacks.toArray(new ItemStack[0]); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/recipe/Recipe.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/recipe/Recipe.java new file mode 100644 index 000000000..286e061aa --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/recipe/Recipe.java @@ -0,0 +1,91 @@ +package net.pitan76.mcpitanlib.midohra.recipe; + +import net.minecraft.recipe.Ingredient; +import net.minecraft.recipe.RecipeSerializer; +import net.minecraft.recipe.input.RecipeInput; +import net.pitan76.mcpitanlib.midohra.item.ItemStack; +import net.pitan76.mcpitanlib.midohra.recipe.input.RecipeInputOrInventory; +import net.pitan76.mcpitanlib.midohra.recipe.input.TypedRecipeInputOrInventory; +import net.pitan76.mcpitanlib.midohra.world.World; + +import java.util.List; + +public class Recipe { + private final net.minecraft.recipe.Recipe recipe; + + protected Recipe(net.minecraft.recipe.Recipe recipe) { + this.recipe = recipe; + } + + public static Recipe of(net.minecraft.recipe.Recipe recipe) { + return new Recipe(recipe); + } + + public static CraftingRecipe of(net.minecraft.recipe.CraftingRecipe recipe) { + return new CraftingRecipe(recipe); + } + + public static ShapedRecipe of(net.minecraft.recipe.ShapedRecipe recipe) { + return new ShapedRecipe(recipe); + } + + public static ShapelessRecipe of(net.minecraft.recipe.ShapelessRecipe recipe) { + return new ShapelessRecipe(recipe); + } + + public net.minecraft.recipe.Recipe getRaw() { + return recipe; + } + + public net.minecraft.recipe.Recipe toMinecraft() { + return getRaw(); + } + + public RecipeSerializer getRawSerializer() { + return recipe.getSerializer(); + } + + public boolean matches(RecipeInputOrInventory input, World world) { + if (input instanceof TypedRecipeInputOrInventory) { + return matches((TypedRecipeInputOrInventory) input, world); + } + + return false; + } + + public net.minecraft.item.ItemStack craft(RecipeInputOrInventory input, World world) { + if (input instanceof TypedRecipeInputOrInventory) { + return craft((TypedRecipeInputOrInventory) input, world); + } + + return net.minecraft.item.ItemStack.EMPTY; + } + + public ItemStack craftMidohra(RecipeInputOrInventory input, World world) { + return ItemStack.of(craft(input, world)); + } + + public boolean matches(TypedRecipeInputOrInventory input, World world) { + return ((net.minecraft.recipe.Recipe)getRaw()).matches(input.getRecipeInput(), world.getRaw()); + } + + public net.minecraft.item.ItemStack craft(TypedRecipeInputOrInventory input, World world) { + return ((net.minecraft.recipe.Recipe)getRaw()).craft(input.getRecipeInput(), world.getRaw().getRegistryManager()); + } + + public ItemStack craftMidohra(TypedRecipeInputOrInventory input, World world) { + return ItemStack.of(craft(input, world)); + } + + public String getGroup() { + return getRaw().getGroup(); + } + + public RecipeType getType() { + return RecipeType.of(getRaw().getType()); + } + + public List getInputs() { + return getRaw().getIngredients(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/recipe/RecipeManager.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/recipe/RecipeManager.java new file mode 100644 index 000000000..5b039fe10 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/recipe/RecipeManager.java @@ -0,0 +1,21 @@ +package net.pitan76.mcpitanlib.midohra.recipe; + +public class RecipeManager { + private final net.minecraft.recipe.RecipeManager recipeManager; + + protected RecipeManager(net.minecraft.recipe.RecipeManager recipeManager) { + this.recipeManager = recipeManager; + } + + public static RecipeManager of(net.minecraft.recipe.RecipeManager recipeManager) { + return new RecipeManager(recipeManager); + } + + public net.minecraft.recipe.RecipeManager getRaw() { + return recipeManager; + } + + public net.minecraft.recipe.RecipeManager toMinecraft() { + return getRaw(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/recipe/RecipeType.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/recipe/RecipeType.java new file mode 100644 index 000000000..d8348bab6 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/recipe/RecipeType.java @@ -0,0 +1,57 @@ +package net.pitan76.mcpitanlib.midohra.recipe; + +import net.minecraft.registry.Registries; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; + +public class RecipeType { + private final net.minecraft.recipe.RecipeType recipeType; + + public static final RecipeType CRAFTING = new RecipeType(net.minecraft.recipe.RecipeType.CRAFTING); + public static final RecipeType SMELTING = new RecipeType(net.minecraft.recipe.RecipeType.SMELTING); + public static final RecipeType BLASTING = new RecipeType(net.minecraft.recipe.RecipeType.BLASTING); + public static final RecipeType SMOKING = new RecipeType(net.minecraft.recipe.RecipeType.SMOKING); + public static final RecipeType CAMPFIRE_COOKING = new RecipeType(net.minecraft.recipe.RecipeType.CAMPFIRE_COOKING); + public static final RecipeType STONECUTTING = new RecipeType(net.minecraft.recipe.RecipeType.STONECUTTING); + public static final RecipeType SMITHING = new RecipeType(net.minecraft.recipe.RecipeType.SMITHING); + + protected RecipeType(net.minecraft.recipe.RecipeType recipeType) { + this.recipeType = recipeType; + } + + public static RecipeType of(net.minecraft.recipe.RecipeType recipeType) { + if (recipeType == net.minecraft.recipe.RecipeType.CRAFTING) { + return CRAFTING; + } else if (recipeType == net.minecraft.recipe.RecipeType.SMELTING) { + return SMELTING; + } else if (recipeType == net.minecraft.recipe.RecipeType.BLASTING) { + return BLASTING; + } else if (recipeType == net.minecraft.recipe.RecipeType.SMOKING) { + return SMOKING; + } else if (recipeType == net.minecraft.recipe.RecipeType.CAMPFIRE_COOKING) { + return CAMPFIRE_COOKING; + } else if (recipeType == net.minecraft.recipe.RecipeType.STONECUTTING) { + return STONECUTTING; + } else if (recipeType == net.minecraft.recipe.RecipeType.SMITHING) { + return SMITHING; + } + + return new RecipeType(recipeType); + } + + public static RecipeType of(CompatIdentifier id) { + return of(Registries.RECIPE_TYPE.get(id.toMinecraft())); + } + + public net.minecraft.recipe.RecipeType getRaw() { + return recipeType; + } + + public net.minecraft.recipe.RecipeType toMinecraft() { + return getRaw(); + } + + public CompatIdentifier getId() { + return CompatIdentifier.fromMinecraft(Registries.RECIPE_TYPE.getId(recipeType)); + } + +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/recipe/ServerRecipeManager.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/recipe/ServerRecipeManager.java new file mode 100644 index 000000000..0e9aa4ea3 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/recipe/ServerRecipeManager.java @@ -0,0 +1,145 @@ +package net.pitan76.mcpitanlib.midohra.recipe; + +import net.pitan76.mcpitanlib.midohra.recipe.entry.CraftingRecipeEntry; +import net.pitan76.mcpitanlib.midohra.recipe.entry.RecipeEntry; +import net.pitan76.mcpitanlib.midohra.recipe.entry.ShapedRecipeEntry; +import net.pitan76.mcpitanlib.midohra.recipe.entry.ShapelessRecipeEntry; +import net.pitan76.mcpitanlib.midohra.world.ServerWorld; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +public class ServerRecipeManager extends RecipeManager { + + protected ServerRecipeManager(net.minecraft.recipe.RecipeManager recipeManager) { + super(recipeManager); + } + + public static ServerRecipeManager of(net.minecraft.recipe.RecipeManager serverRecipeManager) { + return new ServerRecipeManager(serverRecipeManager); + } + + public static ServerRecipeManager of(net.minecraft.server.world.ServerWorld world) { + return of(world.getRecipeManager()); + } + + public static ServerRecipeManager of(ServerWorld world) { + return of(world.getRaw()); + } + + @Deprecated + public Collection> getRawRecipes() { + return getRaw().values(); + } + + public Collection getRecipeEntries() { + List recipes = new ArrayList<>(); + for (net.minecraft.recipe.RecipeEntry recipe : getRaw().values()) { + recipes.add(RecipeEntry.of(recipe)); + } + + return recipes; + } + + public Collection getCraftingRecipeEntries() { + List recipes = new ArrayList<>(); + for (net.minecraft.recipe.RecipeEntry recipe : getRaw().values()) { + if (recipe.value() instanceof net.minecraft.recipe.CraftingRecipe) { + recipes.add(CraftingRecipeEntry.of(recipe)); + } + } + + return recipes; + } + + public Collection getShapelessRecipeEntries() { + List recipes = new ArrayList<>(); + for (net.minecraft.recipe.RecipeEntry recipe : getRaw().values()) { + if (recipe.value() instanceof net.minecraft.recipe.ShapelessRecipe) { + recipes.add(ShapelessRecipeEntry.of(recipe)); + } + } + + return recipes; + } + + public Collection getShapedRecipeEntries() { + List recipes = new ArrayList<>(); + for (net.minecraft.recipe.RecipeEntry recipe : getRaw().values()) { + if (recipe.value() instanceof net.minecraft.recipe.ShapedRecipe) { + recipes.add(ShapedRecipeEntry.of(recipe)); + } + } + + return recipes; + } + + public Collection getNormalRecipeEntries() { + List recipes = new ArrayList<>(); + for (net.minecraft.recipe.RecipeEntry recipe : getRaw().values()) { + if (recipe.value() instanceof net.minecraft.recipe.ShapelessRecipe) { + recipes.add(ShapelessRecipeEntry.of(recipe)); + } else if (recipe.value() instanceof net.minecraft.recipe.ShapedRecipe) { + recipes.add(ShapedRecipeEntry.of(recipe)); + } + } + + return recipes; + } + + public Collection getRecipes() { + List recipes = new ArrayList<>(); + for (net.minecraft.recipe.RecipeEntry recipe : getRaw().values()) { + recipes.add(Recipe.of(recipe.value())); + } + + return recipes; + } + + public Collection getCraftingRecipes() { + List recipes = new ArrayList<>(); + for (net.minecraft.recipe.RecipeEntry recipe : getRaw().values()) { + if (recipe.value() instanceof net.minecraft.recipe.CraftingRecipe) { + recipes.add(CraftingRecipe.of((net.minecraft.recipe.CraftingRecipe) recipe.value())); + } + } + + return recipes; + } + + public Collection getShapelessRecipes() { + List recipes = new ArrayList<>(); + for (net.minecraft.recipe.RecipeEntry recipe : getRaw().values()) { + if (recipe.value() instanceof net.minecraft.recipe.ShapelessRecipe) { + recipes.add(ShapelessRecipe.of((net.minecraft.recipe.ShapelessRecipe) recipe.value())); + } + } + + return recipes; + } + + public Collection getShapedRecipes() { + List recipes = new ArrayList<>(); + for (net.minecraft.recipe.RecipeEntry recipe : getRaw().values()) { + if (recipe.value() instanceof net.minecraft.recipe.ShapedRecipe) { + recipes.add(ShapedRecipe.of((net.minecraft.recipe.ShapedRecipe) recipe.value())); + } + } + + return recipes; + } + + public Collection getNormalRecipes() { + List recipes = new ArrayList<>(); + for (net.minecraft.recipe.RecipeEntry recipe : getRaw().values()) { + if (recipe.value() instanceof net.minecraft.recipe.ShapelessRecipe) { + recipes.add(ShapelessRecipe.of((net.minecraft.recipe.ShapelessRecipe) recipe.value())); + } else if (recipe.value() instanceof net.minecraft.recipe.ShapedRecipe) { + recipes.add(ShapedRecipe.of((net.minecraft.recipe.ShapedRecipe) recipe.value())); + } + } + + return recipes; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/recipe/ShapedRecipe.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/recipe/ShapedRecipe.java new file mode 100644 index 000000000..3d75164fe --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/recipe/ShapedRecipe.java @@ -0,0 +1,60 @@ +package net.pitan76.mcpitanlib.midohra.recipe; + +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.registry.CompatRegistryLookup; +import net.pitan76.mcpitanlib.midohra.item.ItemStack; +import net.pitan76.mcpitanlib.midohra.recipe.input.CraftingRecipeInputOrInventory; + +public class ShapedRecipe extends CraftingRecipe { + private final net.minecraft.recipe.ShapedRecipe recipe; + + protected ShapedRecipe(net.minecraft.recipe.ShapedRecipe recipe) { + super(null); + this.recipe = recipe; + } + + public static ShapedRecipe of(net.minecraft.recipe.ShapedRecipe recipe) { + return new ShapedRecipe(recipe); + } + + public net.minecraft.recipe.ShapedRecipe getRaw() { + return recipe; + } + + public net.minecraft.recipe.ShapedRecipe toMinecraft() { + return getRaw(); + } + + public boolean matches(CraftingRecipeInputOrInventory input) { + return getRaw().matches(input.getRaw(), null); + } + + @Deprecated + public net.minecraft.item.ItemStack craft() { + return getRaw().craft(null, null); + } + + public net.minecraft.item.ItemStack craft(CompatRegistryLookup registryLookup) { + return getRaw().craft(null, registryLookup.getRegistryLookup()); + } + + public net.minecraft.item.ItemStack craft(World world) { + return getRaw().craft(null, world.getRegistryManager()); + } + + public net.minecraft.item.ItemStack craft(net.pitan76.mcpitanlib.midohra.world.World world) { + return craft(world.getRaw()); + } + + public ItemStack craftMidohra() { + return ItemStack.of(craft()); + } + + public int getWidth() { + return getRaw().getWidth(); + } + + public int getHeight() { + return getRaw().getHeight(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/recipe/ShapelessRecipe.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/recipe/ShapelessRecipe.java new file mode 100644 index 000000000..26d28b05b --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/recipe/ShapelessRecipe.java @@ -0,0 +1,52 @@ +package net.pitan76.mcpitanlib.midohra.recipe; + +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.registry.CompatRegistryLookup; +import net.pitan76.mcpitanlib.midohra.item.ItemStack; +import net.pitan76.mcpitanlib.midohra.recipe.input.CraftingRecipeInputOrInventory; + +public class ShapelessRecipe extends CraftingRecipe { + private final net.minecraft.recipe.ShapelessRecipe recipe; + + protected ShapelessRecipe(net.minecraft.recipe.ShapelessRecipe recipe) { + super(null); + this.recipe = recipe; + } + + public static ShapelessRecipe of(net.minecraft.recipe.ShapelessRecipe recipe) { + return new ShapelessRecipe(recipe); + } + + public net.minecraft.recipe.ShapelessRecipe getRaw() { + return recipe; + } + + public net.minecraft.recipe.ShapelessRecipe toMinecraft() { + return getRaw(); + } + + public boolean matches(CraftingRecipeInputOrInventory input) { + return getRaw().matches(input.getRaw(), null); + } + + @Deprecated + public net.minecraft.item.ItemStack craft() { + return getRaw().craft(null, null); + } + + public net.minecraft.item.ItemStack craft(CompatRegistryLookup registryLookup) { + return getRaw().craft(null, registryLookup.getRegistryLookup()); + } + + public net.minecraft.item.ItemStack craft(World world) { + return getRaw().craft(null, world.getRegistryManager()); + } + + public net.minecraft.item.ItemStack craft(net.pitan76.mcpitanlib.midohra.world.World world) { + return craft(world.getRaw()); + } + + public ItemStack craftMidohra() { + return ItemStack.of(craft()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/recipe/entry/CraftingRecipeEntry.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/recipe/entry/CraftingRecipeEntry.java new file mode 100644 index 000000000..879746910 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/recipe/entry/CraftingRecipeEntry.java @@ -0,0 +1,51 @@ +package net.pitan76.mcpitanlib.midohra.recipe.entry; + +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.midohra.recipe.CraftingRecipe; + +public class CraftingRecipeEntry extends RecipeEntry { + private final net.minecraft.recipe.RecipeEntry recipeEntry; + + protected CraftingRecipeEntry(net.minecraft.recipe.RecipeEntry recipeEntry) { + super(null); + this.recipeEntry = recipeEntry; + } + + public static CraftingRecipeEntry _of(net.minecraft.recipe.RecipeEntry recipeEntry) { + return new CraftingRecipeEntry(recipeEntry); + } + + public static CraftingRecipeEntry of(net.minecraft.recipe.RecipeEntry recipeEntry) { + return _of((net.minecraft.recipe.RecipeEntry) recipeEntry); + } + + public static CraftingRecipeEntry of(net.minecraft.recipe.CraftingRecipe recipe, CompatIdentifier id) { + net.minecraft.recipe.RecipeEntry recipeEntry = new net.minecraft.recipe.RecipeEntry<>(id.toMinecraft(), recipe); + + return of(recipeEntry); + } + + public static CraftingRecipeEntry of(CraftingRecipe recipe, CompatIdentifier id) { + return of(recipe.toMinecraft(), id); + } + + @Override + public net.minecraft.recipe.RecipeEntry getRaw() { + return recipeEntry; + } + + @Override + public net.minecraft.recipe.RecipeEntry toMinecraft() { + return getRaw(); + } + + @Override + public CraftingRecipe getRecipe() { + return CraftingRecipe.of(getRawRecipe()); + } + + @Override + public net.minecraft.recipe.CraftingRecipe getRawRecipe() { + return getRaw().value(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/recipe/entry/RecipeEntry.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/recipe/entry/RecipeEntry.java new file mode 100644 index 000000000..bd5658b7d --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/recipe/entry/RecipeEntry.java @@ -0,0 +1,84 @@ +package net.pitan76.mcpitanlib.midohra.recipe.entry; + +import net.pitan76.mcpitanlib.api.recipe.v2.CompatRecipeEntry; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.midohra.recipe.CraftingRecipe; +import net.pitan76.mcpitanlib.midohra.recipe.Recipe; +import net.pitan76.mcpitanlib.midohra.recipe.RecipeType; + +public class RecipeEntry { + private final net.minecraft.recipe.RecipeEntry recipeEntry; + + protected RecipeEntry(net.minecraft.recipe.RecipeEntry recipeEntry) { + this.recipeEntry = recipeEntry; + } + + public static RecipeEntry of(net.minecraft.recipe.RecipeEntry recipeEntry) { + return new RecipeEntry(recipeEntry); + } + + public static RecipeEntry of(net.minecraft.recipe.Recipe recipe, CompatIdentifier id) { + net.minecraft.recipe.RecipeEntry recipeEntry = new net.minecraft.recipe.RecipeEntry<>(id.toMinecraft(), recipe); + return of(recipeEntry); + } + + public static RecipeEntry of(Recipe recipe, CompatIdentifier id) { + return of(recipe.toMinecraft(), id); + } + + public static CraftingRecipeEntry of(net.minecraft.recipe.CraftingRecipe recipe, CompatIdentifier id) { + return CraftingRecipeEntry.of(recipe, id); + } + + public static CraftingRecipeEntry of(CraftingRecipe recipe, CompatIdentifier id) { + return CraftingRecipeEntry.of(recipe, id); + } + + public static ShapedRecipeEntry of(net.minecraft.recipe.ShapedRecipe recipe, CompatIdentifier id) { + return ShapedRecipeEntry.of(recipe, id); + } + + public static ShapedRecipeEntry of(net.pitan76.mcpitanlib.midohra.recipe.ShapedRecipe recipe, CompatIdentifier id) { + return ShapedRecipeEntry.of(recipe, id); + } + + public static ShapelessRecipeEntry of(net.minecraft.recipe.ShapelessRecipe recipe, CompatIdentifier id) { + return ShapelessRecipeEntry.of(recipe, id); + } + + public static ShapelessRecipeEntry of(net.pitan76.mcpitanlib.midohra.recipe.ShapelessRecipe recipe, CompatIdentifier id) { + return ShapelessRecipeEntry.of(recipe, id); + } + + public net.minecraft.recipe.RecipeEntry getRaw() { + return recipeEntry; + } + + public net.minecraft.recipe.RecipeEntry toMinecraft() { + return getRaw(); + } + + public CompatIdentifier getId() { + return CompatIdentifier.fromMinecraft(getRaw().id()); + } + + public CompatRecipeEntry toCompatRecipeEntry() { + return new CompatRecipeEntry(getRaw()); + } + + public net.minecraft.recipe.Recipe getRawRecipe() { + return getRaw().value(); + } + + public Recipe getRecipe() { + return Recipe.of(getRaw().value()); + } + + public RecipeType getRecipeType() { + return RecipeType.of(getRawRecipeType()); + } + + public net.minecraft.recipe.RecipeType getRawRecipeType() { + return getRaw().value().getType(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/recipe/entry/ShapedRecipeEntry.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/recipe/entry/ShapedRecipeEntry.java new file mode 100644 index 000000000..aeabb3868 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/recipe/entry/ShapedRecipeEntry.java @@ -0,0 +1,51 @@ +package net.pitan76.mcpitanlib.midohra.recipe.entry; + +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.midohra.recipe.ShapedRecipe; + +public class ShapedRecipeEntry extends RecipeEntry { + private final net.minecraft.recipe.RecipeEntry recipeEntry; + + protected ShapedRecipeEntry(net.minecraft.recipe.RecipeEntry recipeEntry) { + super(null); + this.recipeEntry = recipeEntry; + } + + public static ShapedRecipeEntry _of(net.minecraft.recipe.RecipeEntry recipeEntry) { + return new ShapedRecipeEntry(recipeEntry); + } + + public static ShapedRecipeEntry of(net.minecraft.recipe.RecipeEntry recipeEntry) { + return _of((net.minecraft.recipe.RecipeEntry) recipeEntry); + } + + public static ShapedRecipeEntry of(net.minecraft.recipe.ShapedRecipe recipe, CompatIdentifier id) { + net.minecraft.recipe.RecipeEntry recipeEntry = new net.minecraft.recipe.RecipeEntry<>(id.toMinecraft(), recipe); + + return of(recipeEntry); + } + + public static ShapedRecipeEntry of(ShapedRecipe recipe, CompatIdentifier id) { + return of(recipe.toMinecraft(), id); + } + + @Override + public net.minecraft.recipe.RecipeEntry getRaw() { + return recipeEntry; + } + + @Override + public net.minecraft.recipe.RecipeEntry toMinecraft() { + return getRaw(); + } + + @Override + public ShapedRecipe getRecipe() { + return ShapedRecipe.of(getRawRecipe()); + } + + @Override + public net.minecraft.recipe.ShapedRecipe getRawRecipe() { + return getRaw().value(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/recipe/entry/ShapelessRecipeEntry.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/recipe/entry/ShapelessRecipeEntry.java new file mode 100644 index 000000000..e834796af --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/recipe/entry/ShapelessRecipeEntry.java @@ -0,0 +1,51 @@ +package net.pitan76.mcpitanlib.midohra.recipe.entry; + +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.midohra.recipe.ShapelessRecipe; + +public class ShapelessRecipeEntry extends RecipeEntry { + private final net.minecraft.recipe.RecipeEntry recipeEntry; + + protected ShapelessRecipeEntry(net.minecraft.recipe.RecipeEntry recipeEntry) { + super(null); + this.recipeEntry = recipeEntry; + } + + public static ShapelessRecipeEntry _of(net.minecraft.recipe.RecipeEntry recipeEntry) { + return new ShapelessRecipeEntry(recipeEntry); + } + + public static ShapelessRecipeEntry of(net.minecraft.recipe.RecipeEntry recipeEntry) { + return _of((net.minecraft.recipe.RecipeEntry) recipeEntry); + } + + public static ShapelessRecipeEntry of(net.minecraft.recipe.ShapelessRecipe recipe, CompatIdentifier id) { + net.minecraft.recipe.RecipeEntry recipeEntry = new net.minecraft.recipe.RecipeEntry<>(id.toMinecraft(), recipe); + + return of(recipeEntry); + } + + public static ShapelessRecipeEntry of(ShapelessRecipe recipe, CompatIdentifier id) { + return of(recipe.toMinecraft(), id); + } + + @Override + public net.minecraft.recipe.RecipeEntry getRaw() { + return recipeEntry; + } + + @Override + public net.minecraft.recipe.RecipeEntry toMinecraft() { + return getRaw(); + } + + @Override + public ShapelessRecipe getRecipe() { + return ShapelessRecipe.of(getRawRecipe()); + } + + @Override + public net.minecraft.recipe.ShapelessRecipe getRawRecipe() { + return getRaw().value(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/recipe/input/CraftingRecipeInputOrInventory.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/recipe/input/CraftingRecipeInputOrInventory.java new file mode 100644 index 000000000..2b65cfda1 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/recipe/input/CraftingRecipeInputOrInventory.java @@ -0,0 +1,67 @@ +package net.pitan76.mcpitanlib.midohra.recipe.input; + +import net.minecraft.inventory.CraftingInventory; +import net.minecraft.inventory.Inventory; +import net.minecraft.recipe.input.CraftingRecipeInput; +import org.jetbrains.annotations.Nullable; + +public class CraftingRecipeInputOrInventory extends RecipeInputOrInventory { + private final CraftingRecipeInput recipeInput; + private CraftingInventory inventory = null; + + public static CraftingRecipeInputOrInventory EMPTY = new CraftingRecipeInputOrInventory(CraftingRecipeInput.EMPTY); + + protected CraftingRecipeInputOrInventory(CraftingRecipeInput recipeInput) { + super(null); + this.recipeInput = recipeInput; + } + + protected CraftingRecipeInputOrInventory(CraftingInventory inventory) { + super(null); + this.recipeInput = inventory.createRecipeInput(); + this.inventory = inventory; + } + + public static CraftingRecipeInputOrInventory of(CraftingRecipeInput recipeInput) { + return new CraftingRecipeInputOrInventory(recipeInput); + } + + public static CraftingRecipeInputOrInventory of(Inventory inventory) { + if (inventory instanceof CraftingRecipeInput) { + return of((CraftingRecipeInput) inventory); + } + + return EMPTY; + } + + public static CraftingRecipeInputOrInventory of(CraftingInventory inventory) { + return new CraftingRecipeInputOrInventory(inventory); + } + + @Nullable + @Override + public CraftingRecipeInput getRaw() { + return recipeInput; + } + + @Nullable + @Override + public CraftingRecipeInput toMinecraft() { + return getRaw(); + } + + @Nullable + @Override + public CraftingRecipeInput getRecipeInput() { + return getRaw(); + } + + @Nullable + @Override + public Inventory getInventory() { + if (inventory != null) + return inventory; + + return super.getInventory(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/recipe/input/RecipeInputOrInventory.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/recipe/input/RecipeInputOrInventory.java new file mode 100644 index 000000000..77e052b0e --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/recipe/input/RecipeInputOrInventory.java @@ -0,0 +1,80 @@ +package net.pitan76.mcpitanlib.midohra.recipe.input; + +import net.minecraft.inventory.Inventory; +import net.minecraft.recipe.input.RecipeInput; +import net.pitan76.mcpitanlib.midohra.item.ItemStack; +import org.jetbrains.annotations.Nullable; + +public class RecipeInputOrInventory { + private final RecipeInput recipeInput; + + public static RecipeInputOrInventory NONE = new RecipeInputOrInventory(null); + + protected RecipeInputOrInventory(RecipeInput recipeInput) { + this.recipeInput = recipeInput; + } + + public static RecipeInputOrInventory of(RecipeInput recipeInput) { + return new RecipeInputOrInventory(recipeInput); + } + + public static RecipeInputOrInventory of(Inventory inventory) { + if (inventory instanceof RecipeInput) { + return of((RecipeInput) inventory); + } + + return NONE; + } + + @Nullable + public RecipeInput getRaw() { + return recipeInput; + } + + @Nullable + public RecipeInput toMinecraft() { + return getRaw(); + } + + @Nullable + public RecipeInput getRecipeInput() { + return getRaw(); + } + + @Nullable + public Inventory getInventory() { + if (getRaw() instanceof Inventory) { + return (Inventory) getRaw(); + } + + return null; + } + + public boolean isNone() { + return getRaw() == null; + } + + public int size() { + if (isNone()) return 0; + + return getRaw().getSize(); + } + + public boolean isEmpty() { + if (isNone()) return true; + + return getRaw().isEmpty(); + } + + public net.minecraft.item.ItemStack getStack(int slot) { + if (isNone()) return net.minecraft.item.ItemStack.EMPTY; + + return getRaw().getStackInSlot(slot); + } + + public ItemStack getMidohraStack(int slot) { + if (isNone()) return ItemStack.EMPTY; + + return ItemStack.of(getStack(slot)); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/recipe/input/TypedRecipeInputOrInventory.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/recipe/input/TypedRecipeInputOrInventory.java new file mode 100644 index 000000000..66f46d30d --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/recipe/input/TypedRecipeInputOrInventory.java @@ -0,0 +1,56 @@ +package net.pitan76.mcpitanlib.midohra.recipe.input; + +import net.minecraft.inventory.Inventory; +import net.minecraft.recipe.input.RecipeInput; +import org.jetbrains.annotations.Nullable; + +public class TypedRecipeInputOrInventory extends RecipeInputOrInventory { + private final T recipeInput; + + public static TypedRecipeInputOrInventory NONE = new TypedRecipeInputOrInventory<>(null); + + protected TypedRecipeInputOrInventory(T recipeInput) { + super(null); + this.recipeInput = recipeInput; + } + + public static TypedRecipeInputOrInventory _of(T recipeInput) { + return new TypedRecipeInputOrInventory<>(recipeInput); + } + + public static TypedRecipeInputOrInventory of(Inventory inventory) { + if (inventory instanceof RecipeInput) { + return _of((RecipeInput) inventory); + } + + return NONE; + } + + @Nullable + @Override + public T getRaw() { + return recipeInput; + } + + @Nullable + @Override + public T getRecipeInput() { + return getRaw(); + } + + @Nullable + @Override + public T toMinecraft() { + return getRaw(); + } + + @Nullable + @Override + public Inventory getInventory() { + if (getRaw() instanceof Inventory) { + return (Inventory) getRaw(); + } + + return null; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/resource/Resource.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/resource/Resource.java new file mode 100644 index 000000000..ecfae63c7 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/resource/Resource.java @@ -0,0 +1,74 @@ +package net.pitan76.mcpitanlib.midohra.resource; + +import net.pitan76.mcpitanlib.api.util.LoggerUtil; +import net.pitan76.mcpitanlib.api.util.ResourceUtil; +import org.apache.commons.io.IOUtils; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; + +public class Resource { + private final net.minecraft.resource.Resource resource; + + protected Resource(net.minecraft.resource.Resource resource) { + this.resource = resource; + } + + public static Resource of(net.minecraft.resource.Resource resource) { + return new Resource(resource); + } + + public net.minecraft.resource.Resource getRaw() { + return resource; + } + + public net.minecraft.resource.Resource toMinecraft() { + return getRaw(); + } + + public BufferedReader getReader() throws IOException { + return resource.getReader(); + } + + public String getPackId() { + return resource.getPackId(); + } + + public InputStream getInputStream() { + try { + return ResourceUtil.getInputStream(resource); + } catch (IOException e) { + LoggerUtil.error(LoggerUtil.getLogger(), "Failed to read resource: " + e.getMessage()); + return null; + } + } + + public void close() { + try { + ResourceUtil.close(resource); + } catch (IOException e) { + LoggerUtil.error(LoggerUtil.getLogger(), "Failed to close resource: " + e.getMessage()); + } + } + + public String getContent() throws IOException { + String content = IOUtils.toString(getInputStream(), StandardCharsets.UTF_8); + close(); + return content; + } + + public String getContent(String encoding) throws IOException { + String content = IOUtils.toString(getInputStream(), encoding); + close(); + return content; + } + + public String getContent(Charset encoding) throws IOException { + String content = IOUtils.toString(getInputStream(), encoding); + close(); + return content; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/resource/ResourceManager.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/resource/ResourceManager.java new file mode 100644 index 000000000..76b541509 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/resource/ResourceManager.java @@ -0,0 +1,84 @@ +package net.pitan76.mcpitanlib.midohra.resource; + +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.MinecraftClient; +import net.minecraft.util.Identifier; +import net.minecraft.world.WorldAccess; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.api.util.LoggerUtil; +import net.pitan76.mcpitanlib.api.util.ResourceUtil; +import net.pitan76.mcpitanlib.midohra.server.MCServer; + +import java.io.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +public class ResourceManager { + private final net.minecraft.resource.ResourceManager resourceManager; + + protected ResourceManager(net.minecraft.resource.ResourceManager resourceManager) { + this.resourceManager = resourceManager; + } + + public static ResourceManager of(net.minecraft.resource.ResourceManager resourceManager) { + return new ResourceManager(resourceManager); + } + + public static ResourceManager of(net.minecraft.server.MinecraftServer server) { + return of(MCServer.of(server)); + } + + public static ResourceManager of(MCServer server) { + return of(server.getRaw()); + } + + @Environment(EnvType.CLIENT) + public static ResourceManager of(MinecraftClient client) { + return of(client.getResourceManager()); + } + + public static ResourceManager of(WorldAccess worldAccess) { + return of(worldAccess.getServer()); + } + + public static ResourceManager of(net.pitan76.mcpitanlib.midohra.world.WorldAccess worldAccess) { + return of(worldAccess.getServer()); + } + + public net.minecraft.resource.ResourceManager getRaw() { + return resourceManager; + } + + public net.minecraft.resource.ResourceManager toMinecraft() { + return getRaw(); + } + + public Map findResources(String startPath, String endPath) { + Map map = new HashMap<>(); + try { + Map rawMap = ResourceUtil.findResources(resourceManager, startPath, endPath); + for (Map.Entry entry : rawMap.entrySet()) { + map.put(CompatIdentifier.fromMinecraft(entry.getKey()), Resource.of(entry.getValue())); + } + } catch (IOException e) { + LoggerUtil.error(LoggerUtil.getLogger(), "Failed to read " + startPath + ": " + e.getMessage()); + return null; + } + + return map; + } + + public Resource getResource(CompatIdentifier id) { + Optional resource = resourceManager.getResource(id.toMinecraft()); + return resource.map(Resource::of).orElse(null); + } + + public List getAllResources(CompatIdentifier id) { + return resourceManager.getAllResources(id.toMinecraft()) + .stream().map(Resource::of).toList(); + } + +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/server/MCServer.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/server/MCServer.java new file mode 100644 index 000000000..997dafb98 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/server/MCServer.java @@ -0,0 +1,96 @@ +package net.pitan76.mcpitanlib.midohra.server; + +import net.minecraft.server.MinecraftServer; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.api.util.ServerUtil; +import net.pitan76.mcpitanlib.api.util.WorldUtil; +import net.pitan76.mcpitanlib.midohra.resource.ResourceManager; +import net.pitan76.mcpitanlib.midohra.world.ServerWorld; + +public class MCServer { + private final MinecraftServer server; + + protected MCServer(MinecraftServer server) { + this.server = server; + } + + public static MCServer of(MinecraftServer server) { + return new MCServer(server); + } + + public MinecraftServer getRaw() { + return server; + } + + public MinecraftServer toMinecraft() { + return getRaw(); + } + + public String getIP() { + return ServerUtil.getIP(server); + } + + public int getPort() { + return ServerUtil.getPort(server); + } + + public String getMotd() { + return ServerUtil.getMotd(server); + } + + public String getServerModName() { + return ServerUtil.getServerModName(server); + } + + public int getMaxPlayerCount() { + return ServerUtil.getMaxPlayerCount(server); + } + + public int getCurrentPlayerCount() { + return ServerUtil.getCurrentPlayerCount(server); + } + + public boolean isOnlineMode() { + return ServerUtil.isOnlineMode(server); + } + + public boolean isServerRunning() { + return ServerUtil.isServerRunning(server); + } + + public boolean isServerDedicated() { + return ServerUtil.isServerDedicated(server); + } + + public boolean isSingleplayer() { + return ServerUtil.isSingleplayer(server); + } + + public PlayerManager getPlayerManager() { + return PlayerManager.of(ServerUtil.getPlayerManager(server)); + } + + public ServerWorld getWorld(CompatIdentifier id) { + return ServerWorld.of(WorldUtil.getWorld(server, id)); + } + + public ServerWorld getOverworld() { + return ServerWorld.of(WorldUtil.getOverworld(server)); + } + + public ServerWorld getNether() { + return ServerWorld.of(WorldUtil.getNether(server)); + } + + public ServerWorld getEnd() { + return ServerWorld.of(WorldUtil.getEnd(server)); + } + + public ResourceManager getResourceManager() { + return ResourceManager.of(server.getResourceManager()); + } + + public void execute(Runnable runnable) { + ServerUtil.execute(getRaw(), runnable); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/server/PlayerManager.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/server/PlayerManager.java new file mode 100644 index 000000000..22dd9fcd3 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/server/PlayerManager.java @@ -0,0 +1,152 @@ +package net.pitan76.mcpitanlib.midohra.server; + +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.server.BannedIpList; +import net.minecraft.server.BannedPlayerList; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.Whitelist; +import net.pitan76.mcpitanlib.api.entity.Player; +import net.pitan76.mcpitanlib.api.text.TextComponent; +import net.pitan76.mcpitanlib.api.util.TextUtil; +import net.pitan76.mcpitanlib.midohra.world.ServerWorld; +import net.pitan76.mcpitanlib.midohra.world.World; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +public class PlayerManager { + private final net.minecraft.server.PlayerManager playerManager; + + protected PlayerManager(net.minecraft.server.PlayerManager playerManager) { + this.playerManager = playerManager; + } + + public static PlayerManager of(net.minecraft.server.PlayerManager playerManager) { + return new PlayerManager(playerManager); + } + + public static PlayerManager of(MinecraftServer server) { + return of(server.getPlayerManager()); + } + + public static PlayerManager of(MCServer server) { + return of(server.getRaw()); + } + + public static PlayerManager of(ServerWorld world) { + return of(world.getServer()); + } + + public static PlayerManager of(World world) { + return of(world.getServer()); + } + + public net.minecraft.server.PlayerManager getRaw() { + return playerManager; + } + + public net.minecraft.server.PlayerManager toMinecraft() { + return getRaw(); + } + + public void broadcast(TextComponent message, boolean overlay) { + getRaw().broadcast(message.getText(), overlay); + } + + public void broadcast(TextComponent message) { + broadcast(message, false); + } + + public void broadcast(String message, boolean overlay) { + getRaw().broadcast(TextUtil.literal(message), overlay); + } + + public void broadcast(String message) { + broadcast(message, false); + } + + public void removePlayer(Player player) { + getRaw().remove(player.getServerPlayer().get()); + } + + public Player getPlayerByUUID(UUID uuid) { + return new Player(getRaw().getPlayer(uuid)); + } + + public Player getPlayerByName(String name) { + return new Player(getRaw().getPlayer(name)); + } + + public List getPlayersByIP(String ip) { + List players = new ArrayList<>(); + for (net.minecraft.entity.player.PlayerEntity p: getRaw().getPlayersByIp(ip)) { + players.add(new Player(p)); + } + return players; + } + + public List getPlayers() { + List players = new ArrayList<>(); + for (PlayerEntity p : getRaw().getPlayerList()) { + players.add(new Player(p)); + } + return players; + } + + public boolean isExistByUUID(UUID uuid) { + return getRaw().getPlayer(uuid) != null; + } + + public boolean isExistByName(String name) { + return getRaw().getPlayer(name) != null; + } + + public boolean isExistByIP(String ip) { + return !getRaw().getPlayersByIp(ip).isEmpty(); + } + + public boolean hasPlayerByUUID(UUID uuid) { + return getRaw().getPlayer(uuid) != null; + } + + public boolean hasPlayerByName(String name) { + return getRaw().getPlayer(name) != null; + } + + public boolean hasPlayerByIP(String ip) { + return !getRaw().getPlayersByIp(ip).isEmpty(); + } + + public int getCurrentPlayerCount() { + return getRaw().getCurrentPlayerCount(); + } + + public int getMaxPlayerCount() { + return getRaw().getMaxPlayerCount(); + } + + public boolean isWhitelistEnabled() { + return getRaw().isWhitelistEnabled(); + } + + public void setWhitelistEnabled(boolean enabled) { + getRaw().setWhitelistEnabled(enabled); + } + + public Whitelist getWhitelist() { + return getRaw().getWhitelist(); + } + + public void reloadWhitelist() { + getRaw().reloadWhitelist(); + } + + public BannedIpList getBannedIpList() { + return getRaw().getIpBanList(); + } + + public BannedPlayerList getBannedPlayerList() { + return getRaw().getUserBanList(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/util/hit/BlockHitResult.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/util/hit/BlockHitResult.java new file mode 100644 index 000000000..5e9fac97e --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/util/hit/BlockHitResult.java @@ -0,0 +1,59 @@ +package net.pitan76.mcpitanlib.midohra.util.hit; + +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; + +public class BlockHitResult extends HitResult { + public BlockHitResult(net.minecraft.util.hit.BlockHitResult raw) { + super(raw); + } + + public static BlockHitResult of(net.minecraft.util.hit.BlockHitResult raw) { + return new BlockHitResult(raw); + } + + @Deprecated + public net.minecraft.util.hit.BlockHitResult getRaw() { + return (net.minecraft.util.hit.BlockHitResult) super.getRaw(); + } + + public net.minecraft.util.hit.BlockHitResult withSide(Direction side) { + return getRaw().withSide(side); + } + + public net.minecraft.util.hit.BlockHitResult withBlockPos(BlockPos blockPos) { + return getRaw().withBlockPos(blockPos); + } + + public net.minecraft.util.hit.BlockHitResult againstWorldBorder() { + return null; + } + + public BlockPos getBlockPos() { + return getRaw().getBlockPos(); + } + + public net.pitan76.mcpitanlib.midohra.util.math.BlockPos getBlockPosM() { + return net.pitan76.mcpitanlib.midohra.util.math.BlockPos.of(getBlockPos()); + } + + public Direction getSide() { + return getRaw().getSide(); + } + + public net.pitan76.mcpitanlib.midohra.util.math.Direction getSideM() { + return net.pitan76.mcpitanlib.midohra.util.math.Direction.of(getSide()); + } + + public boolean isInsideBlock() { + return getRaw().isInsideBlock(); + } + + public boolean isAgainstWorldBorder() { + return false; + } + + public HitResultType getType() { + return HitResultType.from(getRaw().getType()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/util/hit/HitResult.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/util/hit/HitResult.java new file mode 100644 index 000000000..97e521de9 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/util/hit/HitResult.java @@ -0,0 +1,106 @@ +package net.pitan76.mcpitanlib.midohra.util.hit; + +import net.minecraft.entity.Entity; +import net.minecraft.util.math.Vec3d; + +import java.util.Optional; + +public class HitResult { + protected final net.minecraft.util.hit.HitResult raw; + + public HitResult(net.minecraft.util.hit.HitResult raw) { + this.raw = raw; + } + + public static HitResult of(net.minecraft.util.hit.HitResult raw) { + return new HitResult(raw); + } + + @Deprecated + public net.minecraft.util.hit.HitResult getRaw() { + return raw; + } + + @Deprecated + public net.minecraft.util.hit.HitResult.Type getRawType() { + return getRaw().getType(); + } + + public Vec3d getPos() { + return getRaw().getPos(); + } + + public double getX() { + return pos().x; + } + + public double getY() { + return pos().y; + } + + public double getZ() { + return pos().z; + } + + public HitResultType getType() { + return HitResultType.of(this); + } + + public double squaredDistanceTo(Vec3d point) { + Vec3d hitPos = getPos(); + double dx = hitPos.x - point.x; + double dy = hitPos.y - point.y; + double dz = hitPos.z - point.z; + return dx * dx + dy * dy + dz * dz; + } + + public double squaredDistanceTo(Entity entity) { + return getRaw().squaredDistanceTo(entity); + } + + public Vec3d pos() { + return getPos(); + } + + public double x() { + return getX(); + } + + public double y() { + return getY(); + } + + public double z() { + return getZ(); + } + + public Optional asBlockHitResult() { + if (this instanceof BlockHitResult) { + return Optional.of((BlockHitResult) this); + } + + if (raw instanceof net.minecraft.util.hit.BlockHitResult) { + return Optional.of(BlockHitResult.of((net.minecraft.util.hit.BlockHitResult) raw)); + } + + return Optional.empty(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + HitResult other = (HitResult) obj; + return getRaw().equals(other.getRaw()); + } + + @Override + public int hashCode() { + return getRaw().hashCode(); + } + + @Override + public String toString() { + return getRaw().toString(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/util/hit/HitResultType.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/util/hit/HitResultType.java new file mode 100644 index 000000000..6002f2195 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/util/hit/HitResultType.java @@ -0,0 +1,36 @@ +package net.pitan76.mcpitanlib.midohra.util.hit; + +import net.minecraft.util.hit.HitResult; + +public enum HitResultType { + MISS(HitResult.Type.MISS), + BLOCK(HitResult.Type.BLOCK), + ENTITY(HitResult.Type.ENTITY); + + private final HitResult.Type raw; + + HitResultType(HitResult.Type raw) { + this.raw = raw; + } + + @Deprecated + public HitResult.Type getRaw() { + return raw; + } + + public static HitResultType from(HitResult.Type raw) { + switch (raw) { + case MISS: + return MISS; + case BLOCK: + return BLOCK; + case ENTITY: + return ENTITY; + } + throw new IllegalArgumentException("Unknown HitResult.Type: " + raw); + } + + public static HitResultType of(net.pitan76.mcpitanlib.midohra.util.hit.HitResult result) { + return from(result.getRawType()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/util/math/BlockPos.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/util/math/BlockPos.java new file mode 100644 index 000000000..fe07631fe --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/util/math/BlockPos.java @@ -0,0 +1,137 @@ +package net.pitan76.mcpitanlib.midohra.util.math; + +import net.minecraft.util.math.Vec3i; + +import java.util.Iterator; + +public class BlockPos { + private final net.minecraft.util.math.BlockPos blockPos; + + protected BlockPos(net.minecraft.util.math.BlockPos blockPos) { + this.blockPos = blockPos; + } + + public static BlockPos of(net.minecraft.util.math.BlockPos blockPos) { + return new BlockPos(blockPos); + } + + public static BlockPos of(int x, int y, int z) { + return new BlockPos(new net.minecraft.util.math.BlockPos(x, y, z)); + } + + public int getX() { + return blockPos.getX(); + } + + public int getY() { + return blockPos.getY(); + } + + public int getZ() { + return blockPos.getZ(); + } + + public net.minecraft.util.math.BlockPos toMinecraft() { + return blockPos; + } + + public net.minecraft.util.math.BlockPos toRaw() { + return toMinecraft(); + } + + public BlockPos add(int x, int y, int z) { + return new BlockPos(blockPos.add(x, y, z)); + } + + public BlockPos add(BlockPos pos) { + return new BlockPos(blockPos.add(pos.blockPos)); + } + + public BlockPos subtract(int x, int y, int z) { + return new BlockPos(blockPos.subtract(new Vec3i(x, y, z))); + } + + public BlockPos subtract(BlockPos pos) { + return new BlockPos(blockPos.subtract(pos.blockPos)); + } + + public BlockPos up() { + return new BlockPos(blockPos.up()); + } + + public BlockPos down() { + return new BlockPos(blockPos.down()); + } + + public BlockPos north() { + return new BlockPos(blockPos.north()); + } + + public BlockPos south() { + return new BlockPos(blockPos.south()); + } + + public BlockPos east() { + return new BlockPos(blockPos.east()); + } + + public BlockPos west() { + return new BlockPos(blockPos.west()); + } + + public BlockPos offset(Direction direction, int amount) { + return new BlockPos(blockPos.offset(direction.toMinecraft(), amount)); + } + + public BlockPos offset(Direction direction) { + return new BlockPos(blockPos.offset(direction.toMinecraft())); + } + + public ChunkPos toChunkPos() { + return ChunkPos.of(this); + } + + @Override + public int hashCode() { + return blockPos.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + BlockPos pos = (BlockPos) obj; + return blockPos.equals(pos.blockPos); + } + + public static Iterator iterate(BlockPos start, BlockPos end) { + return new Iterator() { + private final net.minecraft.util.math.BlockPos startRaw = start.toMinecraft(); + private final net.minecraft.util.math.BlockPos endRaw = end.toMinecraft(); + private int x = startRaw.getX(); + private int y = startRaw.getY(); + private int z = startRaw.getZ(); + + @Override + public boolean hasNext() { + return x <= endRaw.getX() && y <= endRaw.getY() && z <= endRaw.getZ(); + } + + @Override + public BlockPos next() { + BlockPos current = new BlockPos(new net.minecraft.util.math.BlockPos(x, y, z)); + if (x < endRaw.getX()) { + x++; + } else if (y < endRaw.getY()) { + x = startRaw.getX(); + y++; + } else if (z < endRaw.getZ()) { + x = startRaw.getX(); + y = startRaw.getY(); + z++; + } + return current; + } + }; + } +} \ No newline at end of file diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/util/math/Box.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/util/math/Box.java new file mode 100644 index 000000000..393cec15c --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/util/math/Box.java @@ -0,0 +1,128 @@ +package net.pitan76.mcpitanlib.midohra.util.math; + +import net.minecraft.util.math.Vec3d; +import net.pitan76.mcpitanlib.api.util.math.BoxUtil; + +public class Box { + protected final net.minecraft.util.math.Box box; + + @Deprecated + public Box(net.minecraft.util.math.Box box) { + this.box = box; + } + + @Deprecated + public net.minecraft.util.math.Box toMinecraft() { + return box; + } + + public Box(double x1, double y1, double z1, double x2, double y2, double z2) { + this(BoxUtil.createBox(x1, y1, z1, x2, y2, z2)); + } + + public Box(double x, double y, double z, double size) { + this(x, y, z, x + size, y + size, z + size); + } + + public Box(double size) { + this(0, 0, 0, size, size, size); + } + + public Box(BlockPos pos) { + this(pos.getX(), pos.getY(), pos.getZ(), pos.getX() + 1, pos.getY() + 1, pos.getZ() + 1); + } + + public Box(net.pitan76.mcpitanlib.midohra.util.math.v0.BlockPos pos) { + this(pos.getX(), pos.getY(), pos.getZ(), pos.getX() + 1, pos.getY() + 1, pos.getZ() + 1); + } + + public Box(BlockPos pos1, BlockPos pos2) { + this(pos1.getX(), pos1.getY(), pos1.getZ(), pos2.getX(), pos2.getY(), pos2.getZ()); + } + + public Box(net.pitan76.mcpitanlib.midohra.util.math.v0.BlockPos pos1, net.pitan76.mcpitanlib.midohra.util.math.v0.BlockPos pos2) { + this(pos1.getX(), pos1.getY(), pos1.getZ(), pos2.getX(), pos2.getY(), pos2.getZ()); + } + + public Box(Vector3i pos) { + this(pos.getX(), pos.getY(), pos.getZ(), pos.getX() + 1, pos.getY() + 1, pos.getZ() + 1); + } + + public Box(Vector3i pos1, Vector3i pos2) { + this(pos1.getX(), pos1.getY(), pos1.getZ(), pos2.getX(), pos2.getY(), pos2.getZ()); + } + + public Box(Vector3d pos) { + this(pos.getX(), pos.getY(), pos.getZ(), pos.getX() + 1, pos.getY() + 1, pos.getZ() + 1); + } + + public Box(Vector3d pos1, Vector3d pos2) { + this(pos1.getX(), pos1.getY(), pos1.getZ(), pos2.getX(), pos2.getY(), pos2.getZ()); + } + + public Box expand(double x, double y, double z) { + return new Box(BoxUtil.expand(box, x, y, z)); + } + + public Box expand(double size) { + return expand(size, size, size); + } + + public Box union(Box other) { + return new Box(BoxUtil.union(box, other.box)); + } + + public double getMinX() { + return box.minX; + } + + public double getMinY() { + return box.minY; + } + + public double getMinZ() { + return box.minZ; + } + + public double getMaxX() { + return box.maxX; + } + + public double getMaxY() { + return box.maxY; + } + + public double getMaxZ() { + return box.maxZ; + } + + public Vector3d getCenter() { + Vec3d center = box.getCenter(); + return new Vector3d(center.x, center.y, center.z); + } + + public double getLengthX() { + return box.getLengthX(); + } + + public double getLengthY() { + return box.getLengthY(); + } + + public double getLengthZ() { + return box.getLengthZ(); + } + + @Override + public int hashCode() { + return box.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + Box other = (Box) obj; + return box.equals(other.box); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/util/math/ChunkPos.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/util/math/ChunkPos.java new file mode 100644 index 000000000..da5a979e7 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/util/math/ChunkPos.java @@ -0,0 +1,154 @@ +package net.pitan76.mcpitanlib.midohra.util.math; + +import java.util.stream.Stream; + +public class ChunkPos { + private final net.minecraft.util.math.ChunkPos pos; + + protected ChunkPos(net.minecraft.util.math.ChunkPos pos) { + this.pos = pos; + } + + public static ChunkPos of(net.minecraft.util.math.ChunkPos pos) { + return new ChunkPos(pos); + } + + public static ChunkPos of(int x, int z) { + return of(new net.minecraft.util.math.ChunkPos(x, z)); + } + + public static ChunkPos of(BlockPos pos) { + return of(new net.minecraft.util.math.ChunkPos(pos.toMinecraft())); + } + + public static ChunkPos of(long pos) { + return of(new net.minecraft.util.math.ChunkPos(pos)); + } + + public static ChunkPos fromRegion(int x, int z) { + return of(net.minecraft.util.math.ChunkPos.fromRegion(x, z)); + } + + public static ChunkPos fromRegionCenter(int x, int z) { + return of(net.minecraft.util.math.ChunkPos.fromRegionCenter(x, z)); + } + + public net.minecraft.util.math.ChunkPos getRaw() { + return pos; + } + + public net.minecraft.util.math.ChunkPos toMinecraft() { + return getRaw(); + } + + public int getX() { + return getRaw().x; + } + + public int getZ() { + return getRaw().z; + } + + public int getOffsetX(int offsetX) { + return getRaw().getOffsetX(offsetX); + } + + public int getOffsetZ(int offsetZ) { + return getRaw().getOffsetZ(offsetZ); + } + + public int getStartX() { + return getRaw().getStartX(); + } + + public int getStartZ() { + return getRaw().getStartZ(); + } + + public int getEndX() { + return getRaw().getEndX(); + } + + public int getEndZ() { + return getRaw().getEndZ(); + } + + public int getCenterX() { + return getRaw().getCenterX(); + } + + public int getCenterZ() { + return getRaw().getCenterZ(); + } + + public int getRegionX() { + return getRaw().getRegionX(); + } + + public int getRegionZ() { + return getRaw().getRegionZ(); + } + + public int getRegionRelativeX() { + return getRaw().getRegionRelativeX(); + } + + public int getRegionRelativeZ() { + return getRaw().getRegionRelativeZ(); + } + + public BlockPos getStartPos() { + return BlockPos.of(getRaw().getStartPos()); + } + + public BlockPos getCenterAtY(int y) { + return BlockPos.of(getRaw().getCenterAtY(y)); + } + + public BlockPos getBlockPos(int offsetX, int y, int offsetZ) { + return BlockPos.of(getRaw().getBlockPos(offsetX, y, offsetZ)); + } + + public long toLong() { + return getRaw().toLong(); + } + + @Override + public String toString() { + return getRaw().toString(); + } + + @Override + public boolean equals(Object obj) { + return obj instanceof ChunkPos && getRaw().equals(((ChunkPos) obj).getRaw()); + } + + @Override + public int hashCode() { + return getRaw().hashCode(); + } + + public int getChebyshevDistance(ChunkPos pos) { + return getRaw().getChebyshevDistance(pos.getRaw()); + } + + public int getChebyshevDistance(int x, int z) { + return getRaw().getChebyshevDistance(x, z); + } + + public int getSquaredDistance(ChunkPos pos) { + return getRaw().getSquaredDistance(pos.getRaw()); + } + + public int getSquaredDistance(long pos) { + return getRaw().getSquaredDistance(pos); + } + + public static Stream stream(ChunkPos center, int radius) { + return net.minecraft.util.math.ChunkPos.stream(center.getRaw(), radius).map(ChunkPos::of); + } + + public static Stream stream(final ChunkPos pos1, final ChunkPos pos2) { + return net.minecraft.util.math.ChunkPos.stream(pos1.getRaw(), pos2.getRaw()).map(ChunkPos::of); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/util/math/Direction.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/util/math/Direction.java new file mode 100644 index 000000000..eebc3da6f --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/util/math/Direction.java @@ -0,0 +1,133 @@ +package net.pitan76.mcpitanlib.midohra.util.math; + +public class Direction { + + public static final Direction UP = new Direction(net.minecraft.util.math.Direction.UP); + public static final Direction DOWN = new Direction(net.minecraft.util.math.Direction.DOWN); + public static final Direction NORTH = new Direction(net.minecraft.util.math.Direction.NORTH); + public static final Direction SOUTH = new Direction(net.minecraft.util.math.Direction.SOUTH); + public static final Direction EAST = new Direction(net.minecraft.util.math.Direction.EAST); + public static final Direction WEST = new Direction(net.minecraft.util.math.Direction.WEST); + + private final net.minecraft.util.math.Direction direction; + + protected Direction(net.minecraft.util.math.Direction direction) { + this.direction = direction; + } + + public static Direction of(net.minecraft.util.math.Direction direction) { + switch (direction) { + case UP: + return UP; + case DOWN: + return DOWN; + case NORTH: + return NORTH; + case SOUTH: + return SOUTH; + case EAST: + return EAST; + case WEST: + return WEST; + default: + return new Direction(direction); + } + } + + public Direction getOpposite() { + switch (getRaw()) { + case UP: + return DOWN; + case DOWN: + return UP; + case NORTH: + return SOUTH; + case SOUTH: + return NORTH; + case EAST: + return WEST; + case WEST: + return EAST; + default: + return null; + } + } + + public net.minecraft.util.math.Direction getRaw() { + return direction; + } + + public net.minecraft.util.math.Direction toMinecraft() { + return getRaw(); + } + + public boolean isHorizontal() { + return getRaw().getAxis().isHorizontal(); + } + + public boolean isVertical() { + return getRaw().getAxis().isVertical(); + } + + public boolean isPositive() { + return getRaw().getDirection() == net.minecraft.util.math.Direction.AxisDirection.POSITIVE; + } + + public boolean isNegative() { + return getRaw().getDirection() == net.minecraft.util.math.Direction.AxisDirection.NEGATIVE; + } + + public int getOffsetX() { + return getRaw().getOffsetX(); + } + + public int getOffsetY() { + return getRaw().getOffsetY(); + } + + public int getOffsetZ() { + return getRaw().getOffsetZ(); + } + + public Direction rotateYClockwise() { + return of(getRaw().rotateYClockwise()); + } + + public Direction rotateYCounterclockwise() { + return of(getRaw().rotateYCounterclockwise()); + } + + @Override + public String toString() { + return getRaw().toString(); + } + + public String getName() { + return getRaw().name(); + } + + public static Direction[] values() { + return new Direction[]{UP, DOWN, NORTH, SOUTH, EAST, WEST}; + } + + public Direction[] horizontal() { + return new Direction[]{NORTH, SOUTH, EAST, WEST}; + } + + public Direction[] vertical() { + return new Direction[]{UP, DOWN}; + } + + @Override + public int hashCode() { + return getRaw().hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + Direction dir = (Direction) obj; + return getRaw() == dir.getRaw(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/util/math/Vector3d.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/util/math/Vector3d.java new file mode 100644 index 000000000..3da170a7b --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/util/math/Vector3d.java @@ -0,0 +1,191 @@ +package net.pitan76.mcpitanlib.midohra.util.math; + +import net.minecraft.util.math.Position; +import net.minecraft.util.math.Vec3d; + +public class Vector3d { + public final double x; + public final double y; + public final double z; + + public Vector3d(double x, double y, double z) { + this.x = x; + this.y = y; + this.z = z; + } + + public static Vector3d of(double x, double y, double z) { + return new Vector3d(x, y, z); + } + + public static Vector3d of(Vector3i vec) { + return new Vector3d(vec.x, vec.y, vec.z); + } + + public static Vector3d of(Vector3f vec) { + return new Vector3d(vec.x, vec.y, vec.z); + } + + public static Vector3d of(org.joml.Vector3d vec) { + return new Vector3d(vec.x, vec.y, vec.z); + } + + public static Vector3d of(Vec3d vec) { + return new Vector3d(vec.x, vec.y, vec.z); + } + + public static Vector3d of(Position vec) { + return new Vector3d(vec.getX(), vec.getY(), vec.getZ()); + } + + public Vector3i toInt() { + return new Vector3i((int) x, (int) y, (int) z); + } + + public Vector3f toFloat() { + return new Vector3f((float) x, (float) y, (float) z); + } + + public org.joml.Vector3d toJoml() { + return new org.joml.Vector3d(x, y, z); + } + + public Vector3d add(Vector3d other) { + return new Vector3d(this.x + other.x, this.y + other.y, this.z + other.z); + } + + public Vector3d sub(Vector3d other) { + return new Vector3d(this.x - other.x, this.y - other.y, this.z - other.z); + } + + public Vector3d mul(double scalar) { + return new Vector3d(this.x * scalar, this.y * scalar, this.z * scalar); + } + + public Vector3d div(double scalar) { + return new Vector3d(this.x / scalar, this.y / scalar, this.z / scalar); + } + + public double dot(Vector3d other) { + return this.x * other.x + this.y * other.y + this.z * other.z; + } + + public Vector3d cross(Vector3d other) { + return new Vector3d( + this.y * other.z - this.z * other.y, + this.z * other.x - this.x * other.z, + this.x * other.y - this.y * other.x + ); + } + + public double length() { + return Math.sqrt(x * x + y * y + z * z); + } + + public Vector3d normalize() { + double len = length(); + if (len == 0) return new Vector3d(0, 0, 0); + return div(len); + } + + public Vector3d add(double x, double y, double z) { + return new Vector3d(this.x + x, this.y + y, this.z + z); + } + + public Vector3d sub(double x, double y, double z) { + return new Vector3d(this.x - x, this.y - y, this.z - z); + } + + public Vector3d lerp(Vector3d to, double delta) { + return this.mul(1 - delta).add(to.mul(delta)); + } + + public Vector3d rotateX(double angleDegrees) { + double angleRadians = Math.toRadians(angleDegrees); + double cos = Math.cos(angleRadians); + double sin = Math.sin(angleRadians); + double newY = y * cos - z * sin; + double newZ = y * sin + z * cos; + return new Vector3d(x, newY, newZ); + } + + public Vector3d rotateY(double angleDegrees) { + double angleRadians = Math.toRadians(angleDegrees); + double cos = Math.cos(angleRadians); + double sin = Math.sin(angleRadians); + double newX = x * cos - z * sin; + double newZ = x * sin + z * cos; + return new Vector3d(newX, y, newZ); + } + + public Vector3d rotateZ(double angleDegrees) { + double angleRadians = Math.toRadians(angleDegrees); + double cos = Math.cos(angleRadians); + double sin = Math.sin(angleRadians); + double newX = x * cos - y * sin; + double newY = x * sin + y * cos; + return new Vector3d(newX, newY, z); + } + + public Vector3d negate() { + return new Vector3d(-x, -y, -z); + } + + public Vector3d abs() { + return new Vector3d(Math.abs(x), Math.abs(y), Math.abs(z)); + } + + public Vector3d distanceTo(Vector3d other) { + return this.sub(other); + } + + public double getX() { + return x; + } + + public double getY() { + return y; + } + + public double getZ() { + return z; + } + + public static Vector3d zero() { + return new Vector3d(0, 0, 0); + } + + public static Vector3d distance(Vector3d a, Vector3d b) { + return a.sub(b); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + Vector3d vec = (Vector3d) obj; + return x == vec.x && y == vec.y && z == vec.z; + } + + @Override + public String toString() { + return "(" + x + ", " + y + ", " + z + ")"; + } + + @Override + public int hashCode() { + int h; + h = Double.hashCode(x); + h = 31 * h + Double.hashCode(y); + h = 31 * h + Double.hashCode(z); + return h; + } + + public Vector3d ofCenter() { + return new Vector3d(x + 0.5, y + 0.5, z + 0.5); + } + + public Vec3d toMinecraft() { + return new Vec3d(x, y, z); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/util/math/Vector3f.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/util/math/Vector3f.java new file mode 100644 index 000000000..c04deb552 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/util/math/Vector3f.java @@ -0,0 +1,182 @@ +package net.pitan76.mcpitanlib.midohra.util.math; + +import net.minecraft.util.math.Vec3d; + +public class Vector3f { + public final float x; + public final float y; + public final float z; + + public Vector3f(float x, float y, float z) { + this.x = x; + this.y = y; + this.z = z; + } + + public static Vector3f of(float x, float y, float z) { + return new Vector3f(x, y, z); + } + + public static Vector3f of(Vector3i vec) { + return new Vector3f(vec.x, vec.y, vec.z); + } + + public static Vector3f of(Vector3d vec) { + return new Vector3f((float) vec.x, (float) vec.y, (float) vec.z); + } + + public static Vector3f of(org.joml.Vector3f vec) { + return new Vector3f(vec.x, vec.y, vec.z); + } + + public Vector3i toInt() { + return new Vector3i((int) x, (int) y, (int) z); + } + + public Vector3d toDouble() { + return new Vector3d((double) x, (double) y, (double) z); + } + + public org.joml.Vector3f toJoml() { + return new org.joml.Vector3f(x, y, z); + } + + public Vector3f add(Vector3f other) { + return new Vector3f(this.x + other.x, this.y + other.y, this.z + other.z); + } + + public Vector3f sub(Vector3f other) { + return new Vector3f(this.x - other.x, this.y - other.y, this.z - other.z); + } + + public Vector3f mul(float scalar) { + return new Vector3f(this.x * scalar, this.y * scalar, this.z * scalar); + } + + public Vector3f div(float scalar) { + return new Vector3f(this.x / scalar, this.y / scalar, this.z / scalar); + } + + public float dot(Vector3f other) { + return this.x * other.x + this.y * other.y + this.z * other.z; + } + + public Vector3f cross(Vector3f other) { + return new Vector3f( + this.y * other.z - this.z * other.y, + this.z * other.x - this.x * other.z, + this.x * other.y - this.y * other.x + ); + } + + public float length() { + return (float) Math.sqrt(x * x + y * y + z * z); + } + + public Vector3f normalize() { + float len = length(); + if (len == 0) return new Vector3f(0, 0, 0); + return div(len); + } + + public Vector3f add(float x, float y, float z) { + return new Vector3f(this.x + x, this.y + y, this.z + z); + } + + public Vector3f sub(float x, float y, float z) { + return new Vector3f(this.x - x, this.y - y, this.z - z); + } + + public Vector3f lerp(Vector3f to, float delta) { + return this.mul(1 - delta).add(to.mul(delta)); + } + + public Vector3f rotateX(float angleDegrees) { + double angleRadians = Math.toRadians(angleDegrees); + float cos = (float) Math.cos(angleRadians); + float sin = (float) Math.sin(angleRadians); + float newY = y * cos - z * sin; + float newZ = y * sin + z * cos; + return new Vector3f(x, newY, newZ); + } + + public Vector3f rotateY(float angleDegrees) { + double angleRadians = Math.toRadians(angleDegrees); + float cos = (float) Math.cos(angleRadians); + float sin = (float) Math.sin(angleRadians); + float newX = z * sin + x * cos; + float newZ = z * cos - x * sin; + return new Vector3f(newX, y, newZ); + } + + public Vector3f rotateZ(float angleDegrees) { + double angleRadians = Math.toRadians(angleDegrees); + float cos = (float) Math.cos(angleRadians); + float sin = (float) Math.sin(angleRadians); + float newX = x * cos - y * sin; + float newY = x * sin + y * cos; + return new Vector3f(newX, newY, z); + } + + public Vector3f negate() { + return new Vector3f(-x, -y, -z); + } + + public Vector3f abs() { + return new Vector3f(Math.abs(x), Math.abs(y), Math.abs(z)); + } + + public Vector3f distanceTo(Vector3f other) { + return this.sub(other); + } + + public float getX() { + return x; + } + + public float getY() { + return y; + } + + public float getZ() { + return z; + } + + public static Vector3f zero() { + return new Vector3f(0, 0, 0); + } + + public static Vector3f distance(Vector3f a, Vector3f b) { + return a.sub(b); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + Vector3f vec = (Vector3f) obj; + return x == vec.x && y == vec.y && z == vec.z; + } + + @Override + public String toString() { + return "(" + x + ", " + y + ", " + z + ")"; + } + + @Override + public int hashCode() { + int h; + h = Float.hashCode(x); + h = 31 * h + Float.hashCode(y); + h = 31 * h + Float.hashCode(z); + return h; + } + + public Vector3f ofCenter() { + return this.add(0.5f, 0.5f, 0.5f); + } + + public org.joml.Vector3f toMinecraft() { + return new org.joml.Vector3f(x, y, z); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/util/math/Vector3i.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/util/math/Vector3i.java new file mode 100644 index 000000000..0606d7997 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/util/math/Vector3i.java @@ -0,0 +1,196 @@ +package net.pitan76.mcpitanlib.midohra.util.math; + +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Vec3d; +import net.minecraft.util.math.Vec3i; + +public class Vector3i { + public final int x; + public final int y; + public final int z; + + public Vector3i(int x, int y, int z) { + this.x = x; + this.y = y; + this.z = z; + } + + public static Vector3i of(int x, int y, int z) { + return new Vector3i(x, y, z); + } + + public static Vector3i of(Vector3d vec) { + return new Vector3i((int) vec.x, (int) vec.y, (int) vec.z); + } + + public static Vector3i of(Vector3f vec) { + return new Vector3i((int) vec.x, (int) vec.y, (int) vec.z); + } + + public static Vector3i of(org.joml.Vector3i vec) { + return new Vector3i(vec.x, vec.y, vec.z); + } + + public static Vector3i of(Vec3i vec) { + return new Vector3i(vec.getX(), vec.getY(), vec.getZ()); + } + + public static Vector3i of(BlockPos vec) { + return new Vector3i(vec.getX(), vec.getY(), vec.getZ()); + } + + public static Vector3i of(net.pitan76.mcpitanlib.midohra.util.math.BlockPos vec) { + return new Vector3i(vec.getX(), vec.getY(), vec.getZ()); + } + + public static Vector3i of(net.pitan76.mcpitanlib.midohra.util.math.v0.BlockPos vec) { + return new Vector3i(vec.getX(), vec.getY(), vec.getZ()); + } + + public Vector3d toDouble() { + return new Vector3d(x, y, z); + } + + public Vector3f toFloat() { + return new Vector3f((float) x, (float) y, (float) z); + } + + public org.joml.Vector3i toJoml() { + return new org.joml.Vector3i(x, y, z); + } + + public Vector3i add(Vector3i other) { + return new Vector3i(this.x + other.x, this.y + other.y, this.z + other.z); + } + + public Vector3i sub(Vector3i other) { + return new Vector3i(this.x - other.x, this.y - other.y, this.z - other.z); + } + + public Vector3i mul(int scalar) { + return new Vector3i(this.x * scalar, this.y * scalar, this.z * scalar); + } + + public Vector3i div(int scalar) { + return new Vector3i(this.x / scalar, this.y / scalar, this.z / scalar); + } + + public int dot(Vector3i other) { + return this.x * other.x + this.y * other.y + this.z * other.z; + } + + public Vector3i cross(Vector3i other) { + return new Vector3i( + this.y * other.z - this.z * other.y, + this.z * other.x - this.x * other.z, + this.x * other.y - this.y * other.x + ); + } + + public int length() { + return (int) Math.sqrt(x * x + y * y + z * z); + } + + public Vector3i normalize() { + int len = length(); + if (len == 0) return new Vector3i(0, 0, 0); + return div(len); + } + + public Vector3i add(int x, int y, int z) { + return new Vector3i(this.x + x, this.y + y, this.z + z); + } + + public Vector3i sub(int x, int y, int z) { + return new Vector3i(this.x - x, this.y - y, this.z - z); + } + + public Vector3i lerp(Vector3i to, int delta) { + return this.mul(1 - delta).add(to.mul(delta)); + } + + public Vector3i rotateX(double angleDegrees) { + double angleRadians = Math.toRadians(angleDegrees); + int cos = (int) Math.cos(angleRadians); + int sin = (int) Math.sin(angleRadians); + int newY = this.y * cos - this.z * sin; + int newZ = this.y * sin + this.z * cos; + return new Vector3i(this.x, newY, newZ); + } + + public Vector3i rotateY(double angleDegrees) { + double angleRadians = Math.toRadians(angleDegrees); + int cos = (int) Math.cos(angleRadians); + int sin = (int) Math.sin(angleRadians); + int newX = this.z * sin + this.x * cos; + int newZ = this.z * cos - this.x * sin; + return new Vector3i(newX, this.y, newZ); + } + + public Vector3i rotateZ(double angleDegrees) { + double angleRadians = Math.toRadians(angleDegrees); + int cos = (int) Math.cos(angleRadians); + int sin = (int) Math.sin(angleRadians); + int newX = this.x * cos - this.y * sin; + int newY = this.x * sin + this.y * cos; + return new Vector3i(newX, newY, this.z); + } + + public Vector3i negate() { + return new Vector3i(-this.x, -this.y, -this.z); + } + + public Vector3i abs() { + return new Vector3i(Math.abs(this.x), Math.abs(this.y), Math.abs(this.z)); + } + + public Vector3i distanceTo(Vector3i other) { + return this.sub(other); + } + + public int getX() { + return x; + } + + public int getY() { + return y; + } + + public int getZ() { + return z; + } + + public static Vector3i zero() { + return new Vector3i(0, 0, 0); + } + + public static Vector3i distance(Vector3i a, Vector3i b) { + return a.sub(b); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + Vector3i vec = (Vector3i) obj; + return x == vec.x && y == vec.y && z == vec.z; + } + + @Override + public String toString() { + return "(" + x + ", " + y + ", " + z + ")"; + } + + @Override + public int hashCode() { + int h; + h = Integer.hashCode(x); + h = 31 * h + Integer.hashCode(y); + h = 31 * h + Integer.hashCode(z); + return h; + } + + public Vec3i toMinecraft() { + return new Vec3i(x, y, z); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/util/math/v0/BlockPos.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/util/math/v0/BlockPos.java new file mode 100644 index 000000000..fb0f6d0c3 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/util/math/v0/BlockPos.java @@ -0,0 +1,90 @@ +package net.pitan76.mcpitanlib.midohra.util.math.v0; + +import net.minecraft.util.math.Vec3i; +import net.pitan76.mcpitanlib.midohra.util.math.Direction; + +public class BlockPos extends net.minecraft.util.math.BlockPos { + private final net.minecraft.util.math.BlockPos blockPos; + + protected BlockPos(net.minecraft.util.math.BlockPos blockPos) { + super(blockPos.getX(), blockPos.getY(), blockPos.getZ()); + this.blockPos = blockPos; + } + + public static BlockPos of(net.minecraft.util.math.BlockPos blockPos) { + return new BlockPos(blockPos); + } + + public static BlockPos of(int x, int y, int z) { + return new BlockPos(new net.minecraft.util.math.BlockPos(x, y, z)); + } + + public int getX() { + return blockPos.getX(); + } + + public int getY() { + return blockPos.getY(); + } + + public int getZ() { + return blockPos.getZ(); + } + + public net.minecraft.util.math.BlockPos toMinecraft() { + return blockPos; + } + + public BlockPos add(int x, int y, int z) { + return new BlockPos(blockPos.add(x, y, z)); + } + + public BlockPos add(BlockPos pos) { + return new BlockPos(blockPos.add(pos.blockPos)); + } + + public BlockPos subtract(int x, int y, int z) { + return new BlockPos(blockPos.subtract(new Vec3i(x, y, z))); + } + + public BlockPos subtract(BlockPos pos) { + return new BlockPos(blockPos.subtract(pos.blockPos)); + } + + public BlockPos up() { + return new BlockPos(blockPos.up()); + } + + public BlockPos down() { + return new BlockPos(blockPos.down()); + } + + public BlockPos north() { + return new BlockPos(blockPos.north()); + } + + public BlockPos south() { + return new BlockPos(blockPos.south()); + } + + public BlockPos east() { + return new BlockPos(blockPos.east()); + } + + public BlockPos west() { + return new BlockPos(blockPos.west()); + } + + public BlockPos offset(Direction direction, int amount) { + return new BlockPos(blockPos.offset(direction.toMinecraft(), amount)); + } + + public BlockPos offset(Direction direction) { + return new BlockPos(blockPos.offset(direction.toMinecraft())); + } + + @Override + public BlockPos add(Vec3i vec3i) { + return new BlockPos(blockPos.add(vec3i)); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/util/shape/VoxelShape.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/util/shape/VoxelShape.java new file mode 100644 index 000000000..a0e536955 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/util/shape/VoxelShape.java @@ -0,0 +1,76 @@ +package net.pitan76.mcpitanlib.midohra.util.shape; + +import net.pitan76.mcpitanlib.midohra.util.math.Direction; + +public class VoxelShape { + private final net.minecraft.util.shape.VoxelShape voxelShape; + + public static final VoxelShape EMPTY = of(net.minecraft.util.shape.VoxelShapes.empty()); + public static final VoxelShape FULL_CUBE = of(net.minecraft.util.shape.VoxelShapes.fullCube()); + + public VoxelShape(net.minecraft.util.shape.VoxelShape voxelShape) { + this.voxelShape = voxelShape; + } + + public static VoxelShape of(net.minecraft.util.shape.VoxelShape shape) { + return new VoxelShape(shape); + } + + @Deprecated + public net.minecraft.util.shape.VoxelShape raw() { + return voxelShape; + } + + public boolean isEmpty() { + return raw().isEmpty(); + } + + public VoxelShape union(VoxelShape other) { + return of(net.minecraft.util.shape.VoxelShapes.union(this.raw(), other.raw())); + } + + public VoxelShape asCuboid() { + return of(raw().asCuboid()); + } + + public VoxelShape offset(double x, double y, double z) { + return of(raw().offset(x, y, z)); + } + + public VoxelShape getFace(Direction direction) { + return of(raw().getFace(direction.toMinecraft())); + } + + public VoxelShape simplify() { + return of(raw().simplify()); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (!(obj instanceof VoxelShape)) return false; + VoxelShape other = (VoxelShape) obj; + return this.raw().equals(other.raw()); + } + + @Override + public int hashCode() { + return raw().hashCode(); + } + + public static VoxelShape empty() { + return EMPTY; + } + + public static VoxelShape fullCube() { + return FULL_CUBE; + } + + public static VoxelShape union(VoxelShape... shapes) { + net.minecraft.util.shape.VoxelShape result = net.minecraft.util.shape.VoxelShapes.empty(); + for (VoxelShape shape : shapes) { + result = net.minecraft.util.shape.VoxelShapes.union(result, shape.raw()); + } + return of(result); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/world/BlockView.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/world/BlockView.java new file mode 100644 index 000000000..60a94b216 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/world/BlockView.java @@ -0,0 +1,41 @@ +package net.pitan76.mcpitanlib.midohra.world; + +import net.minecraft.block.BlockState; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.fluid.FluidState; +import net.minecraft.util.math.BlockPos; + +public class BlockView implements IWorldView { + private net.minecraft.world.BlockView blockView; + + public BlockView(net.minecraft.world.BlockView blockView) { + this.blockView = blockView; + } + + public static BlockView of(net.minecraft.world.BlockView blockView) { + return new BlockView(blockView); + } + + public net.minecraft.world.BlockView getRaw() { + return blockView; + } + + public net.minecraft.world.BlockView toMinecraft() { + return getRaw(); + } + + @Override + public BlockEntity getBlockEntity(BlockPos pos) { + return getRaw().getBlockEntity(pos); + } + + @Override + public BlockState getBlockState(BlockPos pos) { + return getRaw().getBlockState(pos); + } + + @Override + public FluidState getFluidState(BlockPos pos) { + return getRaw().getFluidState(pos); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/world/IWorldView.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/world/IWorldView.java new file mode 100644 index 000000000..95d95ab78 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/world/IWorldView.java @@ -0,0 +1,28 @@ +package net.pitan76.mcpitanlib.midohra.world; + +import net.minecraft.block.BlockState; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.fluid.FluidState; +import net.minecraft.util.math.BlockPos; +import net.pitan76.mcpitanlib.midohra.block.entity.BlockEntityWrapper; +import net.pitan76.mcpitanlib.midohra.fluid.FluidWrapper; + +public interface IWorldView { + BlockEntity getBlockEntity(BlockPos pos); + + BlockState getBlockState(BlockPos pos); + + FluidState getFluidState(BlockPos pos); + + default BlockEntityWrapper getBlockEntity(net.pitan76.mcpitanlib.midohra.util.math.BlockPos pos) { + return BlockEntityWrapper.of(getBlockEntity(pos.toMinecraft())); + } + + default net.pitan76.mcpitanlib.midohra.block.BlockState getBlockState(net.pitan76.mcpitanlib.midohra.util.math.BlockPos pos) { + return net.pitan76.mcpitanlib.midohra.block.BlockState.of(getBlockState(pos.toMinecraft())); + } + + default FluidWrapper getFluid(net.pitan76.mcpitanlib.midohra.util.math.BlockPos pos) { + return FluidWrapper.of(getFluidState(pos.toMinecraft()).getFluid()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/world/RedstoneView.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/world/RedstoneView.java new file mode 100644 index 000000000..4d8bc2f0e --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/world/RedstoneView.java @@ -0,0 +1,41 @@ +package net.pitan76.mcpitanlib.midohra.world; + +import net.pitan76.mcpitanlib.midohra.util.math.BlockPos; +import net.pitan76.mcpitanlib.midohra.util.math.Direction; + +public interface RedstoneView { + + net.minecraft.world.RedstoneView getRedstoneView(); + + default boolean isReceivingRedstonePower(BlockPos pos) { + return getRedstoneView().isReceivingRedstonePower(pos.toMinecraft()); + } + + default int getEmittedRedstonePower(BlockPos pos, Direction direction) { + return getRedstoneView().getEmittedRedstonePower(pos.toMinecraft(), direction.toMinecraft()); + } + + default int getEmittedRedstonePower(BlockPos pos, Direction direction, boolean onlyFromGate) { + return getRedstoneView().getEmittedRedstonePower(pos.toMinecraft(), direction.toMinecraft(), onlyFromGate); + } + + default boolean isEmittingRedstonePower(BlockPos pos, Direction direction) { + return getRedstoneView().isEmittingRedstonePower(pos.toMinecraft(), direction.toMinecraft()); + } + + default int getStrongRedstonePower(BlockPos pos, Direction direction) { + return getRedstoneView().getStrongRedstonePower(pos.toMinecraft(), direction.toMinecraft()); + } + + default int getReceivedStrongRedstonePower(BlockPos pos) { + return getRedstoneView().getReceivedStrongRedstonePower(pos.toMinecraft()); + } + + static RedstoneView of(net.minecraft.world.RedstoneView redstoneView) { + return () -> redstoneView; + } + + static RedstoneView of(net.minecraft.world.WorldView world) { + return WorldView.of(world); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/world/ServerWorld.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/world/ServerWorld.java new file mode 100644 index 000000000..9ee497435 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/world/ServerWorld.java @@ -0,0 +1,63 @@ +package net.pitan76.mcpitanlib.midohra.world; + +import net.minecraft.server.MinecraftServer; +import net.pitan76.mcpitanlib.api.entity.Player; +import net.pitan76.mcpitanlib.api.sound.CompatSoundCategory; +import net.pitan76.mcpitanlib.api.sound.CompatSoundEvent; +import net.pitan76.mcpitanlib.midohra.recipe.ServerRecipeManager; +import net.pitan76.mcpitanlib.midohra.server.MCServer; +import net.pitan76.mcpitanlib.midohra.server.PlayerManager; +import net.pitan76.mcpitanlib.midohra.util.math.BlockPos; +import net.pitan76.mcpitanlib.midohra.world.chunk.ServerChunkManager; + +public class ServerWorld extends World { + private final net.minecraft.server.world.ServerWorld world; + + protected ServerWorld(net.minecraft.server.world.ServerWorld world) { + super(null); + this.world = world; + } + + public static ServerWorld of(net.minecraft.server.world.ServerWorld world) { + return new ServerWorld(world); + } + + @Override + public net.minecraft.server.world.ServerWorld getRaw() { + return world; + } + + @Override + public net.minecraft.server.world.ServerWorld toMinecraft() { + return getRaw(); + } + + public void playSound(Player player, BlockPos pos, CompatSoundEvent sound, CompatSoundCategory category, float volume, float pitch, long seed) { + getRaw().playSound(player.getEntity(), pos.getX(), pos.getY(), pos.getZ(), sound.getEntry(), category.get(), volume, pitch, seed); + } + + public void playSoundFromEntity(Player player, Player target, CompatSoundEvent sound, CompatSoundCategory category, float volume, float pitch, long seed) { + getRaw().playSoundFromEntity(player.getEntity(), target.getEntity(), sound.getEntry(), category.get(), volume, pitch, seed); + } + + public MinecraftServer getServer() { + return getRaw().getServer(); + } + + public MCServer getMCServer() { + return MCServer.of(getServer()); + } + + public PlayerManager getPlayerManager() { + return PlayerManager.of(this); + } + + public ServerChunkManager getChunkManager() { + return ServerChunkManager.of(this); + } + + @Override + public ServerRecipeManager getRecipeManager() { + return ServerRecipeManager.of(this); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/world/World.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/world/World.java new file mode 100644 index 000000000..3a94bf8ba --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/world/World.java @@ -0,0 +1,158 @@ +package net.pitan76.mcpitanlib.midohra.world; + +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.fluid.FluidState; +import net.minecraft.sound.SoundCategory; +import net.minecraft.sound.SoundEvent; +import net.pitan76.mcpitanlib.api.entity.Player; +import net.pitan76.mcpitanlib.api.registry.CompatRegistryLookup; +import net.pitan76.mcpitanlib.api.sound.CompatSoundCategory; +import net.pitan76.mcpitanlib.api.sound.CompatSoundEvent; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.api.util.RegistryLookupUtil; +import net.pitan76.mcpitanlib.api.util.WorldUtil; +import net.pitan76.mcpitanlib.midohra.block.entity.BlockEntityWrapper; +import net.pitan76.mcpitanlib.midohra.recipe.RecipeManager; +import net.pitan76.mcpitanlib.midohra.util.math.BlockPos; + +import java.util.List; +import java.util.Optional; +import java.util.UUID; + +public class World extends WorldAccess { + + private final net.minecraft.world.World world; + + protected World(net.minecraft.world.World world) { + super(null); + this.world = world; + } + + public static World of(net.minecraft.world.World world) { + return new World(world); + } + + @Override + public net.minecraft.world.World getRaw() { + return world; + } + + public net.minecraft.world.World toMinecraft() { + return getRaw(); + } + + public void addBlockEntity(BlockEntityWrapper blockEntity) { + addBlockEntity(blockEntity.get()); + } + + public void addBlockEntity(BlockEntity blockEntity) { + getRaw().addBlockEntity(blockEntity); + } + + public void removeBlockEntity(BlockPos pos) { + getRaw().removeBlockEntity(pos.toMinecraft()); + } + + public long getTime() { + return WorldUtil.getTime(getRaw()); + } + + public long getTopY() { + return WorldUtil.getTopY(getRaw()); + } + + public long getBottomY() { + return WorldUtil.getBottomY(getRaw()); + } + + public long getDimensionHeight() { + return WorldUtil.getDimensionHeight(getRaw()); + } + + public CompatIdentifier getId() { + return WorldUtil.getCompatWorldId(getRaw()); + } + + public FluidState getRawFluidState(BlockPos pos) { + return WorldUtil.getFluidState(getRaw(), pos.toMinecraft()); + } + + public Player getPlayerByUUID(UUID uuid) { + return WorldUtil.getPlayer(getRaw(), uuid); + } + + public List getPlayers() { + return WorldUtil.getPlayers(getRaw()); + } + + public BlockPos getSpawnPos() { + return BlockPos.of(WorldUtil.getSpawnPos(getRaw())); + } + + public Optional getWorld(CompatIdentifier id) { + Optional optional = WorldUtil.getWorld(getRaw(), id); + return optional.map(World::of); + } + + public Optional getServerWorld(CompatIdentifier id) { + Optional optional = WorldUtil.getWorld(getRaw(), id); + return optional.map(ServerWorld::of); + } + + public void spawnEntity(Entity entity) { + WorldUtil.spawnEntity(getRaw(), entity); + } + + public void spawnStack(net.minecraft.item.ItemStack stack, BlockPos pos) { + WorldUtil.spawnStack(getRaw(), pos.toMinecraft(), stack); + } + + public RecipeManager getRecipeManager() { + return RecipeManager.of(getRaw().getRecipeManager()); + } + + @Deprecated + @Override + public void playSound(PlayerEntity playerEntity, net.minecraft.util.math.BlockPos pos, SoundEvent sound, SoundCategory category) { + getRaw().playSound(playerEntity, pos, sound, category); + } + + @Deprecated + @Override + public void playSound(PlayerEntity playerEntity, net.minecraft.util.math.BlockPos pos, SoundEvent sound, SoundCategory category, float volume, float pitch) { + getRaw().playSound(playerEntity, pos, sound, category, volume, pitch); + } + + @Override + public void playSound(Player player, BlockPos pos, CompatSoundEvent soundEvent, CompatSoundCategory category, float volume, float pitch) { + WorldUtil.playSound(getRaw(), player, pos.toMinecraft(), soundEvent, category, volume, pitch); + } + + @Override + public void playSound(BlockPos pos, CompatSoundEvent soundEvent, CompatSoundCategory category) { + playSound(null, pos, soundEvent, category, 1f, 1f); + } + + @Override + public void playSound(Player player, BlockPos pos, CompatSoundEvent soundEvent, CompatSoundCategory category) { + playSound(player, pos, soundEvent, category, 1f, 1f); + } + + @Override + public void playSound(BlockPos pos, CompatSoundEvent soundEvent, CompatSoundCategory category, float volume, float pitch) { + playSound(null, pos, soundEvent, category, volume, pitch); + } + + public Optional toServerWorld() { + if (getRaw() instanceof net.minecraft.server.world.ServerWorld) { + return Optional.of(ServerWorld.of((net.minecraft.server.world.ServerWorld) getRaw())); + } + return Optional.empty(); + } + + public CompatRegistryLookup getRegistryLookup() { + return RegistryLookupUtil.getRegistryLookup(getRaw()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/world/WorldAccess.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/world/WorldAccess.java new file mode 100644 index 000000000..dda78a0c0 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/world/WorldAccess.java @@ -0,0 +1,129 @@ +package net.pitan76.mcpitanlib.midohra.world; + +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.block.entity.BlockEntityType; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.server.MinecraftServer; +import net.minecraft.sound.SoundCategory; +import net.minecraft.sound.SoundEvent; +import net.pitan76.mcpitanlib.api.entity.Player; +import net.pitan76.mcpitanlib.api.sound.CompatSoundCategory; +import net.pitan76.mcpitanlib.api.sound.CompatSoundEvent; +import net.pitan76.mcpitanlib.api.util.math.random.CompatRandom; +import net.pitan76.mcpitanlib.api.util.world.WorldAccessUtil; +import net.pitan76.mcpitanlib.midohra.block.BlockState; +import net.pitan76.mcpitanlib.midohra.block.entity.BlockEntityWrapper; +import net.pitan76.mcpitanlib.midohra.server.MCServer; +import net.pitan76.mcpitanlib.midohra.util.math.BlockPos; + +import java.util.Optional; + +public class WorldAccess extends WorldView { + private final net.minecraft.world.WorldAccess world; + + protected WorldAccess(net.minecraft.world.WorldAccess world) { + super(null); + this.world = world; + } + + public static WorldAccess of(net.minecraft.world.WorldAccess world) { + return new WorldAccess(world); + } + + @Override + protected net.minecraft.world.WorldAccess getRaw() { + return world; + } + + public net.minecraft.world.WorldAccess toMinecraft() { + return getRaw(); + } + + public boolean isClient() { + return WorldAccessUtil.isClient(getRaw()); + } + + public boolean isServer() { + return !isClient(); + } + + public CompatRandom getRandom() { + return new CompatRandom(getRaw().getRandom()); + } + + public MinecraftServer getServer() { + return WorldAccessUtil.getServer(getRaw()); + } + + public BlockEntityWrapper getBlockEntity(BlockPos pos) { + return BlockEntityWrapper.of(WorldAccessUtil.getBlockEntity(getRaw(), pos.toMinecraft())); + } + + public Optional getRawBlockEntity(BlockPos pos, BlockEntityType type) { + return WorldAccessUtil.getBlockEntity(getRaw(), pos.toMinecraft(), type); + } + + public BlockEntityWrapper getBlockEntity(BlockPos pos, BlockEntityType type) { + Optional blockEntity = WorldAccessUtil.getBlockEntity(getRaw(), pos.toMinecraft(), type); + return blockEntity.map(BlockEntityWrapper::of).orElse(BlockEntityWrapper.of()); + } + + public boolean removeBlock(BlockPos pos, boolean move) { + return WorldAccessUtil.removeBlock(getRaw(), pos.toMinecraft(), move); + } + + public boolean breakBlock(BlockPos pos, boolean drop) { + return WorldAccessUtil.breakBlock(getRaw(), pos.toMinecraft(), drop); + } + + public boolean breakBlock(BlockPos pos, boolean drop, Entity entity) { + return WorldAccessUtil.breakBlock(getRaw(), pos.toMinecraft(), drop, entity); + } + + public BlockState getBlockState(BlockPos pos) { + return BlockState.of(WorldAccessUtil.getBlockState(getRaw(), pos.toMinecraft())); + } + + public boolean setBlockState(BlockPos pos, BlockState state, int flags) { + return WorldAccessUtil.setBlockState(getRaw(), pos.toMinecraft(), state.toMinecraft(), flags); + } + + public boolean setBlockState(BlockPos pos, BlockState state, int flags, int maxUpdateDepth) { + return WorldAccessUtil.setBlockState(getRaw(), pos.toMinecraft(), state.toMinecraft(), flags, maxUpdateDepth); + } + + public boolean setBlockState(BlockPos pos, BlockState state) { + return WorldAccessUtil.setBlockState(getRaw(), pos.toMinecraft(), state.toMinecraft()); + } + + @Deprecated + public void playSound(PlayerEntity playerEntity, net.minecraft.util.math.BlockPos pos, SoundEvent sound, SoundCategory category, float volume, float pitch) { + getRaw().playSound(playerEntity, pos, sound, category, volume, pitch); + } + + @Deprecated + public void playSound(PlayerEntity playerEntity, net.minecraft.util.math.BlockPos pos, SoundEvent sound, SoundCategory category) { + getRaw().playSound(playerEntity, pos, sound, category); + } + + public void playSound(Player player, BlockPos pos, CompatSoundEvent soundEvent, CompatSoundCategory category, float volume, float pitch) { + playSound(player.getEntity(), pos.toMinecraft(), soundEvent.get(), category.get(), volume, pitch); + } + + public void playSound(Player player, BlockPos pos, CompatSoundEvent soundEvent, CompatSoundCategory category) { + playSound(player.getEntity(), pos.toMinecraft(), soundEvent.get(), category.get()); + } + + public void playSound(BlockPos pos, CompatSoundEvent soundEvent, CompatSoundCategory category, float volume, float pitch) { + playSound(null, pos.toMinecraft(), soundEvent.get(), category.get(), volume, pitch); + } + + public void playSound(BlockPos pos, CompatSoundEvent soundEvent, CompatSoundCategory category) { + playSound(null, pos.toMinecraft(), soundEvent.get(), category.get()); + } + + public MCServer getMCServer() { + return MCServer.of(getServer()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/world/WorldView.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/world/WorldView.java new file mode 100644 index 000000000..dc836d089 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/world/WorldView.java @@ -0,0 +1,87 @@ +package net.pitan76.mcpitanlib.midohra.world; + +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.block.entity.BlockEntityType; +import net.minecraft.fluid.FluidState; +import net.pitan76.mcpitanlib.api.util.WorldUtil; +import net.pitan76.mcpitanlib.api.util.world.WorldAccessUtil; +import net.pitan76.mcpitanlib.midohra.block.entity.BlockEntityWrapper; +import net.pitan76.mcpitanlib.midohra.util.math.BlockPos; +import net.pitan76.mcpitanlib.midohra.util.math.Direction; + +import java.util.Optional; + +public class WorldView implements IWorldView, RedstoneView { + private final net.minecraft.world.WorldView world; + + protected WorldView(net.minecraft.world.WorldView world) { + this.world = world; + } + + public static WorldView of(net.minecraft.world.WorldView world) { + return new WorldView(world); + } + + protected net.minecraft.world.WorldView getRaw() { + return world; + } + + public net.minecraft.world.WorldView toMinecraft() { + return getRaw(); + } + + public boolean isClient() { + return WorldAccessUtil.isClient(getRaw()); + } + + public boolean isServer() { + return !isClient(); + } + + public BlockEntityWrapper getBlockEntity(BlockPos pos) { + return BlockEntityWrapper.of(WorldAccessUtil.getBlockEntity(getRaw(), pos.toMinecraft())); + } + + public Optional getRawBlockEntity(BlockPos pos, BlockEntityType type) { + return WorldAccessUtil.getBlockEntity(getRaw(), pos.toMinecraft(), type); + } + + public BlockEntityWrapper getBlockEntity(BlockPos pos, BlockEntityType type) { + Optional blockEntity = WorldAccessUtil.getBlockEntity(getRaw(), pos.toMinecraft(), type); + return blockEntity.map(BlockEntityWrapper::of).orElse(BlockEntityWrapper.of()); + } + + @Override + public BlockEntity getBlockEntity(net.minecraft.util.math.BlockPos pos) { + return getRaw().getBlockEntity(pos); + } + + @Override + public net.minecraft.block.BlockState getBlockState(net.minecraft.util.math.BlockPos pos) { + return getRaw().getBlockState(pos); + } + + @Override + public FluidState getFluidState(net.minecraft.util.math.BlockPos pos) { + return getRaw().getFluidState(pos); + } + + @Override + @Deprecated + public net.minecraft.world.RedstoneView getRedstoneView() { + return getRaw(); + } + + @Override + public int hashCode() { + return getRaw() != null ? getRaw().hashCode() : 0; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + WorldView other = (WorldView) obj; + return getRaw() != null ? getRaw().equals(other.getRaw()) : other.getRaw() == null; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/world/chunk/ChunkManager.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/world/chunk/ChunkManager.java new file mode 100644 index 000000000..7f3084f67 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/world/chunk/ChunkManager.java @@ -0,0 +1,41 @@ +package net.pitan76.mcpitanlib.midohra.world.chunk; + +import net.pitan76.mcpitanlib.midohra.world.BlockView; +import net.pitan76.mcpitanlib.midohra.world.IWorldView; +import net.pitan76.mcpitanlib.midohra.world.World; + +public class ChunkManager { + private final net.minecraft.world.chunk.ChunkManager chunkManager; + + protected ChunkManager(net.minecraft.world.chunk.ChunkManager chunkManager) { + this.chunkManager = chunkManager; + } + + public static ChunkManager of(net.minecraft.world.chunk.ChunkManager chunkManager) { + return new ChunkManager(chunkManager); + } + + public static ChunkManager of(net.minecraft.world.World world) { + return of(world.getChunkManager()); + } + + public static ChunkManager of(World world) { + return of(world.getRaw()); + } + + public net.minecraft.world.chunk.ChunkManager getRaw() { + return chunkManager; + } + + public net.minecraft.world.chunk.ChunkManager toMinecraft() { + return getRaw(); + } + + public IWorldView getWorld() { + return BlockView.of(getRaw().getWorld()); + } + + public boolean isChunkLoaded(int x, int z) { + return getRaw().isChunkLoaded(x, z); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/world/chunk/ChunkTicketType.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/world/chunk/ChunkTicketType.java new file mode 100644 index 000000000..8b3a65c63 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/world/chunk/ChunkTicketType.java @@ -0,0 +1,92 @@ +package net.pitan76.mcpitanlib.midohra.world.chunk; + +import net.minecraft.util.Unit; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.ChunkPos; + +import java.util.Comparator; + +public class ChunkTicketType { + + public static final ChunkTicketType START = of(net.minecraft.server.world.ChunkTicketType.START); + public static final ChunkTicketType DRAGON = of(net.minecraft.server.world.ChunkTicketType.DRAGON); + public static final ChunkTicketType PLAYER = of(net.minecraft.server.world.ChunkTicketType.PLAYER); + public static final ChunkTicketType FORCED = of(net.minecraft.server.world.ChunkTicketType.FORCED); + public static final ChunkTicketType PORTAL = of(net.minecraft.server.world.ChunkTicketType.PORTAL); + public static final ChunkTicketType ENDER_PEARL = of(net.minecraft.server.world.ChunkTicketType.UNKNOWN); + public static final ChunkTicketType POST_TELEPORT = of(net.minecraft.server.world.ChunkTicketType.POST_TELEPORT); + public static final ChunkTicketType UNKNOWN = of(net.minecraft.server.world.ChunkTicketType.UNKNOWN); + + private final net.minecraft.server.world.ChunkTicketType ticketType; + + protected ChunkTicketType(net.minecraft.server.world.ChunkTicketType ticketType) { + this.ticketType = ticketType; + } + + public static ChunkTicketType of(net.minecraft.server.world.ChunkTicketType ticketType) { + return new ChunkTicketType<>(ticketType); + } + + public net.minecraft.server.world.ChunkTicketType getRaw() { + return ticketType; + } + + public net.minecraft.server.world.ChunkTicketType toMinecraft() { + return getRaw(); + } + + public static ChunkTicketType create(String name, Comparator argumentComparator) { + return of(net.minecraft.server.world.ChunkTicketType.create(name, argumentComparator)); + } + + public static ChunkTicketType create(String name, Comparator argumentComparator, int expiryTicks) { + return of(net.minecraft.server.world.ChunkTicketType.create(name, argumentComparator, expiryTicks)); + } + + public Comparator getArgumentComparator() { + return getRaw().getArgumentComparator(); + } + + public long getExpiryTicks() { + return getRaw().getExpiryTicks(); + } + + @Override + public String toString() { + return getRaw().toString(); + } + + public ChunkTicketType(String name, long expiryTicks) { + this(_of(name, expiryTicks)); + } + + public ChunkTicketType(String name) { + this(name, 0); + } + + public static ChunkTicketType create(String name, long expiryTicks) { + return new ChunkTicketType<>(name, expiryTicks); + } + + public static ChunkTicketType create(String name) { + return new ChunkTicketType<>(name); + } + + private static net.minecraft.server.world.ChunkTicketType _of(String name, long expiryTicks) { + net.minecraft.server.world.ChunkTicketType type = net.minecraft.server.world.ChunkTicketType.create(name, Comparator.comparingLong(ChunkPos::toLong), (int) expiryTicks); + return (net.minecraft.server.world.ChunkTicketType) type; + } + + @Override + public int hashCode() { + return ticketType.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (!(obj instanceof ChunkTicketType)) return false; + ChunkTicketType that = (ChunkTicketType) obj; + return ticketType.equals(that.ticketType); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/world/chunk/ServerChunkManager.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/world/chunk/ServerChunkManager.java new file mode 100644 index 000000000..281c72dbb --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/world/chunk/ServerChunkManager.java @@ -0,0 +1,51 @@ +package net.pitan76.mcpitanlib.midohra.world.chunk; + +import net.pitan76.mcpitanlib.api.util.world.ChunkManagerUtil; +import net.pitan76.mcpitanlib.midohra.util.math.BlockPos; +import net.pitan76.mcpitanlib.midohra.util.math.ChunkPos; +import net.pitan76.mcpitanlib.midohra.world.ServerWorld; +import net.pitan76.mcpitanlib.midohra.world.World; + +public class ServerChunkManager extends ChunkManager { + private final net.minecraft.server.world.ServerChunkManager chunkManager; + + protected ServerChunkManager(net.minecraft.server.world.ServerChunkManager chunkManager) { + super(null); + this.chunkManager = chunkManager; + } + + public static ServerChunkManager of(net.minecraft.server.world.ServerChunkManager chunkManager) { + return new ServerChunkManager(chunkManager); + } + + public static ServerChunkManager of(ServerWorld world) { + return of(world.getRaw().getChunkManager()); + } + + @Override + public net.minecraft.server.world.ServerChunkManager getRaw() { + return chunkManager; + } + + @Override + public net.minecraft.server.world.ServerChunkManager toMinecraft() { + return getRaw(); + } + + @Override + public World getWorld() { + return World.of(getRaw().getWorld()); + } + + public void addTicket(ChunkTicketType ticketType, ChunkPos pos, int radius, T argument) { + getRaw().addTicket(ticketType.getRaw(), pos.getRaw(), radius, argument); + } + + public void removeTicket(ChunkTicketType ticketType, ChunkPos pos, int radius, T argument) { + getRaw().removeTicket(ticketType.getRaw(), pos.getRaw(), radius, argument); + } + + public void markForUpdate(BlockPos pos) { + ChunkManagerUtil.markForUpdate(getRaw(), pos); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/world/tick/ScheduledTickView.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/world/tick/ScheduledTickView.java new file mode 100644 index 000000000..b616ed645 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/world/tick/ScheduledTickView.java @@ -0,0 +1,48 @@ +package net.pitan76.mcpitanlib.midohra.world.tick; + +import net.minecraft.block.Block; +import net.minecraft.fluid.Fluid; +import net.minecraft.world.WorldAccess; +import net.pitan76.mcpitanlib.midohra.block.BlockWrapper; +import net.pitan76.mcpitanlib.midohra.fluid.FluidWrapper; +import net.pitan76.mcpitanlib.midohra.util.math.BlockPos; + +public class ScheduledTickView { + private final WorldAccess scheduledTickView; + + public ScheduledTickView(WorldAccess scheduledTickView) { + this.scheduledTickView = scheduledTickView; + } + + public static net.pitan76.mcpitanlib.midohra.world.tick.ScheduledTickView of(net.minecraft.world.World world) { + return of((WorldAccess) world); + } + + public static net.pitan76.mcpitanlib.midohra.world.tick.ScheduledTickView of(WorldAccess world) { + return new net.pitan76.mcpitanlib.midohra.world.tick.ScheduledTickView(world); + } + + public WorldAccess toMinecraft() { + return get(); + } + + protected WorldAccess get() { + return scheduledTickView; + } + + public void scheduleBlockTick(BlockPos blockPos, BlockWrapper blockWrapper, int delay) { + scheduleBlockTick(blockPos.toMinecraft(), blockWrapper.get(), delay); + } + + public void scheduleBlockTick(net.minecraft.util.math.BlockPos blockPos, Block block, int delay) { + get().scheduleBlockTick(blockPos, block, delay); + } + + public void scheduleFluidTick(BlockPos blockPos, FluidWrapper fluidWrapper, int delay) { + scheduleFluidTick(blockPos.toMinecraft(), fluidWrapper.get(), delay); + } + + public void scheduleFluidTick(net.minecraft.util.math.BlockPos blockPos, Fluid block, int delay) { + get().scheduleFluidTick(blockPos, block, delay); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/mixin/AbstractBlock4CompatProviderMixin.java b/common/src/main/java/net/pitan76/mcpitanlib/mixin/AbstractBlock4CompatProviderMixin.java new file mode 100644 index 000000000..54fa33ca7 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/mixin/AbstractBlock4CompatProviderMixin.java @@ -0,0 +1,94 @@ +package net.pitan76.mcpitanlib.mixin; + +import net.minecraft.block.AbstractBlock; +import net.minecraft.block.BlockRenderType; +import net.minecraft.block.BlockState; +import net.minecraft.block.ShapeContext; +import net.minecraft.util.BlockRotation; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import net.minecraft.util.shape.VoxelShape; +import net.minecraft.world.BlockView; +import net.minecraft.world.WorldAccess; +import net.pitan76.mcpitanlib.api.block.CompatBlockRenderType; +import net.pitan76.mcpitanlib.api.block.ExtendBlockProvider.Options; +import net.pitan76.mcpitanlib.api.block.args.RenderTypeArgs; +import net.pitan76.mcpitanlib.api.block.args.RotateArgs; +import net.pitan76.mcpitanlib.api.block.args.SideInvisibleArgs; +import net.pitan76.mcpitanlib.api.block.args.v2.CollisionShapeEvent; +import net.pitan76.mcpitanlib.api.block.args.v2.OutlineShapeEvent; +import net.pitan76.mcpitanlib.api.block.args.v2.StateForNeighborUpdateArgs; +import net.pitan76.mcpitanlib.api.block.v2.CompatBlockProvider; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(AbstractBlock.class) +public class AbstractBlock4CompatProviderMixin { + @Inject(method = "getCollisionShape", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$inject_getCollisionShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context, CallbackInfoReturnable cir) { + if (this instanceof CompatBlockProvider) { + CompatBlockProvider provider = (CompatBlockProvider) this; + Options options = new Options(); + VoxelShape returnValue = provider.getCollisionShape(new CollisionShapeEvent(state, world, pos, context), options); + if (options.cancel && returnValue != null) + cir.setReturnValue(returnValue); + } + } + + @Inject(method = "getOutlineShape", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$inject_getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context, CallbackInfoReturnable cir) { + if (this instanceof CompatBlockProvider) { + CompatBlockProvider provider = (CompatBlockProvider) this; + Options options = new Options(); + VoxelShape returnValue = provider.getOutlineShape(new OutlineShapeEvent(state, world, pos, context), options); + if (options.cancel && returnValue != null) + cir.setReturnValue(returnValue); + } + } + + @Inject(method = "getStateForNeighborUpdate", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$inject_getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos, CallbackInfoReturnable cir) { + if (this instanceof CompatBlockProvider) { + CompatBlockProvider provider = (CompatBlockProvider) this; + Options options = new Options(); + net.pitan76.mcpitanlib.midohra.block.BlockState returnValue = provider.getStateForNeighborUpdate(new StateForNeighborUpdateArgs(state, direction, neighborState, world, pos, neighborPos), options); + if (options.cancel && returnValue != null) + cir.setReturnValue(returnValue.toMinecraft()); + } + } + + @Inject(method = "getRenderType", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$inject_getRenderType(BlockState state, CallbackInfoReturnable cir) { + if (this instanceof CompatBlockProvider) { + CompatBlockProvider provider = (CompatBlockProvider) this; + Options options = new Options(); + CompatBlockRenderType returnValue = provider.getRenderType(new RenderTypeArgs(state), options); + if (options.cancel && returnValue != null) + cir.setReturnValue(returnValue.toMinecraft()); + } + } + + @Inject(method = "rotate", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$inject_rotate(BlockState state, BlockRotation rotation, CallbackInfoReturnable cir) { + if (this instanceof CompatBlockProvider) { + CompatBlockProvider provider = (CompatBlockProvider) this; + Options options = new Options(); + net.pitan76.mcpitanlib.midohra.block.BlockState returnValue = provider.rotate(new RotateArgs(state, rotation), options); + if (options.cancel && returnValue != null) + cir.setReturnValue(returnValue.toMinecraft()); + } + } + + @Inject(method = "isSideInvisible", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$inject_isSideInvisible(BlockState state, BlockState stateFrom, Direction direction, CallbackInfoReturnable cir) { + if (this instanceof CompatBlockProvider) { + CompatBlockProvider provider = (CompatBlockProvider) this; + Options options = new Options(); + Boolean returnValue = provider.isSideInvisible(new SideInvisibleArgs(state, stateFrom, direction), options); + if (options.cancel && returnValue != null) + cir.setReturnValue(returnValue); + } + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/mixin/AbstractBlockMixin.java b/common/src/main/java/net/pitan76/mcpitanlib/mixin/AbstractBlockMixin.java new file mode 100644 index 000000000..711fa65a6 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/mixin/AbstractBlockMixin.java @@ -0,0 +1,123 @@ +package net.pitan76.mcpitanlib.mixin; + +import net.minecraft.block.AbstractBlock; +import net.minecraft.block.BlockState; +import net.minecraft.block.ShapeContext; +import net.minecraft.entity.ai.pathing.NavigationType; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.loot.context.LootContextParameterSet; +import net.minecraft.screen.NamedScreenHandlerFactory; +import net.minecraft.screen.SimpleNamedScreenHandlerFactory; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.util.ActionResult; +import net.minecraft.util.hit.BlockHitResult; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.random.Random; +import net.minecraft.util.shape.VoxelShape; +import net.minecraft.world.BlockView; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.block.ExtendBlockProvider; +import net.pitan76.mcpitanlib.api.block.ExtendBlockProvider.Options; +import net.pitan76.mcpitanlib.api.event.block.*; +import net.pitan76.mcpitanlib.api.util.CompatActionResult; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import java.util.List; + +@Mixin(AbstractBlock.class) +public class AbstractBlockMixin { + @Inject(method = "getCollisionShape", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$inject_getCollisionShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context, CallbackInfoReturnable cir) { + if (this instanceof ExtendBlockProvider) { + ExtendBlockProvider provider = (ExtendBlockProvider) this; + Options options = new Options(); + VoxelShape returnValue = provider.getCollisionShape(new CollisionShapeEvent(state, world, pos, context), options); + if (options.cancel && returnValue != null) + cir.setReturnValue(returnValue); + } + } + + @Inject(method = "getOutlineShape", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$inject_getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context, CallbackInfoReturnable cir) { + if (this instanceof ExtendBlockProvider) { + ExtendBlockProvider provider = (ExtendBlockProvider) this; + Options options = new Options(); + VoxelShape returnValue = provider.getOutlineShape(new OutlineShapeEvent(state, world, pos, context), options); + if (options.cancel && returnValue != null) + cir.setReturnValue(returnValue); + } + } + + @Inject(method = "scheduledTick", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$inject_scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random, CallbackInfo ci) { + if (this instanceof ExtendBlockProvider) { + ExtendBlockProvider provider = (ExtendBlockProvider) this; + Options options = new Options(); + provider.scheduledTick(new BlockScheduledTickEvent(state, world, pos, random), options); + if (options.cancel) + ci.cancel(); + } + } + + @Inject(method = "onUse", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$inject_onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit, CallbackInfoReturnable cir) { + if (this instanceof ExtendBlockProvider) { + ExtendBlockProvider provider = (ExtendBlockProvider) this; + Options options = new Options(); + CompatActionResult returnValue = provider.onRightClick(new BlockUseEvent(state, world, pos, player, player.getActiveHand(), hit), options); + if (options.cancel && returnValue != null) + cir.setReturnValue(returnValue.toActionResult()); + } + } + + @Inject(method = "createScreenHandlerFactory", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$inject_createScreenHandlerFactory(BlockState state, World world, BlockPos pos, CallbackInfoReturnable cir) { + if (this instanceof ExtendBlockProvider) { + ExtendBlockProvider provider = (ExtendBlockProvider) this; + Options options = new Options(); + NamedScreenHandlerFactory returnValue = new SimpleNamedScreenHandlerFactory((syncId, inventory, player) -> + provider.createScreenHandler(new ScreenHandlerCreateEvent(state, world, pos, syncId, inventory, player), options), provider.getScreenTitle()); + if (options.cancel && returnValue != null) + cir.setReturnValue(returnValue); + } + } + + @Inject(method = "onStateReplaced", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$inject_onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved, CallbackInfo ci) { + if (this instanceof ExtendBlockProvider) { + ExtendBlockProvider provider = (ExtendBlockProvider) this; + Options options = new Options(); + provider.onStateReplaced(new StateReplacedEvent(state, world, pos, newState, moved), options); + if (options.cancel) + ci.cancel(); + } + } + + @Inject(method = "getDroppedStacks", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$inject_getDroppedStacks(BlockState state, LootContextParameterSet.Builder builder, CallbackInfoReturnable> cir) { + if (this instanceof ExtendBlockProvider) { + ExtendBlockProvider provider = (ExtendBlockProvider) this; + Options options = new Options(); + List returnValue = provider.getDroppedStacks(new DroppedStacksArgs(state, builder), options); + if (options.cancel && returnValue != null) + cir.setReturnValue(returnValue); + } + } + + @Inject(method = "canPathfindThrough", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$inject_canPathfindThrough(BlockState state, NavigationType type, CallbackInfoReturnable cir) { + if (this instanceof ExtendBlockProvider) { + ExtendBlockProvider provider = (ExtendBlockProvider) this; + Options options = new Options(); + Boolean returnValue = provider.canPathfindThrough(new CanPathfindThroughArgs(state, type), options); + if (options.cancel && returnValue != null) + cir.setReturnValue(returnValue); + } + } + +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/mixin/Block4CompatProviderMixin.java b/common/src/main/java/net/pitan76/mcpitanlib/mixin/Block4CompatProviderMixin.java new file mode 100644 index 000000000..79e84aa7c --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/mixin/Block4CompatProviderMixin.java @@ -0,0 +1,28 @@ +package net.pitan76.mcpitanlib.mixin; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.item.ItemPlacementContext; +import net.pitan76.mcpitanlib.api.block.ExtendBlockProvider.Options; +import net.pitan76.mcpitanlib.api.block.args.v2.PlacementStateArgs; +import net.pitan76.mcpitanlib.api.block.v2.CompatBlockProvider; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(Block.class) +public class Block4CompatProviderMixin { + + @Inject(method = "getPlacementState", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$getPlacementState(ItemPlacementContext ctx, CallbackInfoReturnable cir) { + // ExtendBlockProviderを実装している場合 + if (this instanceof CompatBlockProvider) { + CompatBlockProvider provider = (CompatBlockProvider) this; + Options options = new Options(); + net.pitan76.mcpitanlib.midohra.block.BlockState returnValue = provider.getPlacementState(new PlacementStateArgs(ctx), options); + if (options.cancel && returnValue != null) + cir.setReturnValue(returnValue.toMinecraft()); + } + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/mixin/BlockInvoker.java b/common/src/main/java/net/pitan76/mcpitanlib/mixin/BlockInvoker.java new file mode 100644 index 000000000..edf1d6c7b --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/mixin/BlockInvoker.java @@ -0,0 +1,12 @@ +package net.pitan76.mcpitanlib.mixin; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Invoker; + +@Mixin(Block.class) +public interface BlockInvoker { + @Invoker("setDefaultState") + void setDefaultState_invoke(BlockState state); +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/mixin/BlockMixin.java b/common/src/main/java/net/pitan76/mcpitanlib/mixin/BlockMixin.java new file mode 100644 index 000000000..5aa0bcbcc --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/mixin/BlockMixin.java @@ -0,0 +1,131 @@ +package net.pitan76.mcpitanlib.mixin; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.Item; +import net.minecraft.item.ItemPlacementContext; +import net.minecraft.item.ItemStack; +import net.minecraft.item.tooltip.TooltipType; +import net.minecraft.state.StateManager; +import net.minecraft.text.Text; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraft.world.WorldView; +import net.pitan76.mcpitanlib.api.block.ExtendBlockProvider; +import net.pitan76.mcpitanlib.api.block.ExtendBlockProvider.Options; +import net.pitan76.mcpitanlib.api.event.block.*; +import net.pitan76.mcpitanlib.api.event.block.result.BlockBreakResult; +import net.pitan76.mcpitanlib.api.event.item.ItemAppendTooltipEvent; +import net.pitan76.mcpitanlib.api.event.v1.listener.BlockBreakTask; +import net.pitan76.mcpitanlib.api.event.v1.listener.BlockPlacedTask; +import net.pitan76.mcpitanlib.api.event.v2.BlockEventRegistry; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import java.util.List; + +@Mixin(Block.class) +public class BlockMixin { + + @Inject(method = "onPlaced", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$onPlaced(World world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack, CallbackInfo ci) { + // イベントを呼び出す + if (!BlockEventRegistry.ON_PLACED.isEmpty()) { + int maxPriority = BlockEventRegistry.ON_PLACED.getMaxPriority(); + for (int p = maxPriority; p >= 0; p--) { + for (BlockPlacedTask listener : BlockEventRegistry.ON_PLACED.getListenersAsList(p)) { + listener.onPlaced(new BlockPlacedEvent(world, pos, state, placer, stack)); + } + } + } + + // ExtendBlockProviderを実装している場合 + if (this instanceof ExtendBlockProvider) { + ExtendBlockProvider provider = (ExtendBlockProvider) this; + Options options = new Options(); + provider.onPlaced(new BlockPlacedEvent(world, pos, state, placer, stack), options); + if (options.cancel) + ci.cancel(); + } + } + + @Inject(method = "onBreak", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$onBreak(World world, BlockPos pos, BlockState state, PlayerEntity player, CallbackInfoReturnable cir) { + // イベントを呼び出す + if (!BlockEventRegistry.ON_BREAK.isEmpty()) { + BlockState newState = state; + int maxPriority = BlockEventRegistry.ON_BREAK.getMaxPriority(); + for (int p = maxPriority; p >= 0; p--) { + for (BlockBreakTask listener : BlockEventRegistry.ON_BREAK.getListenersAsList(p)) { + newState = listener.onBreak(new BlockBreakEvent(world, pos, newState, player)).state; + } + } + if (newState != state) { + cir.setReturnValue(newState); + state = newState; + } + } + + // ExtendBlockProviderを実装している場合 + if (this instanceof ExtendBlockProvider) { + ExtendBlockProvider provider = (ExtendBlockProvider) this; + Options options = new Options(); + BlockBreakResult returnValue = provider.onBreak(new BlockBreakEvent(world, pos, state, player), options); + if (options.cancel && returnValue != null) + cir.setReturnValue(returnValue.getState()); + } + } + + @Inject(method = "getPickStack", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$getPickStack(WorldView world, BlockPos pos, BlockState state, CallbackInfoReturnable cir) { + // ExtendBlockProviderを実装している場合 + if (this instanceof ExtendBlockProvider) { + ExtendBlockProvider provider = (ExtendBlockProvider) this; + Options options = new Options(); + ItemStack returnValue = provider.getPickStack(new PickStackEvent(world, pos, state), options); + if (options.cancel && returnValue != null) + cir.setReturnValue(returnValue); + } + } + + @Inject(method = "appendProperties", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$appendProperties(StateManager.Builder builder, CallbackInfo ci) { + // ExtendBlockProviderを実装している場合 + if (this instanceof ExtendBlockProvider) { + ExtendBlockProvider provider = (ExtendBlockProvider) this; + Options options = new Options(); + provider.appendProperties(new AppendPropertiesArgs(builder), options); + if (options.cancel) + ci.cancel(); + } + } + + @Inject(method = "getPlacementState", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$getPlacementState(ItemPlacementContext ctx, CallbackInfoReturnable cir) { + // ExtendBlockProviderを実装している場合 + if (this instanceof ExtendBlockProvider) { + ExtendBlockProvider provider = (ExtendBlockProvider) this; + Options options = new Options(); + BlockState returnValue = provider.getPlacementState(new PlacementStateArgs(ctx), options); + if (options.cancel && returnValue != null) + cir.setReturnValue(returnValue); + } + } + + @Inject(method = "appendTooltip", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$appendTooltip(ItemStack stack, Item.TooltipContext context, List tooltip, TooltipType type, CallbackInfo ci) { + // ExtendBlockProviderを実装している場合 + if (this instanceof ExtendBlockProvider) { + ExtendBlockProvider provider = (ExtendBlockProvider) this; + Options options = new Options(); + provider.appendTooltip(new ItemAppendTooltipEvent(stack, null, tooltip, type, context), options); + if (options.cancel) + ci.cancel(); + } + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/mixin/ItemMixin.java b/common/src/main/java/net/pitan76/mcpitanlib/mixin/ItemMixin.java new file mode 100644 index 000000000..81aff5888 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/mixin/ItemMixin.java @@ -0,0 +1,248 @@ +package net.pitan76.mcpitanlib.mixin; + +import net.minecraft.block.BlockState; +import net.minecraft.entity.Entity; +import net.minecraft.entity.damage.DamageSource; +import net.minecraft.item.tooltip.TooltipType; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.item.ItemUsageContext; +import net.minecraft.text.Text; +import net.minecraft.util.ActionResult; +import net.minecraft.util.Hand; +import net.minecraft.util.TypedActionResult; +import net.minecraft.util.UseAction; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.event.item.*; +import net.pitan76.mcpitanlib.api.event.v2.ItemEventRegistry; +import net.pitan76.mcpitanlib.api.event.v2.listener.InventoryTickTask; +import net.pitan76.mcpitanlib.api.item.ExtendItemProvider; +import net.pitan76.mcpitanlib.api.item.ExtendItemProvider.Options; +import net.pitan76.mcpitanlib.api.item.FixedRecipeRemainderItem; +import net.pitan76.mcpitanlib.api.item.args.UseActionArgs; +import net.pitan76.mcpitanlib.api.item.consume.CompatUseAction; +import net.pitan76.mcpitanlib.api.item.v2.CompatItemProvider; +import net.pitan76.mcpitanlib.api.util.CompatActionResult; +import net.pitan76.mcpitanlib.api.util.ItemStackUtil; +import net.pitan76.mcpitanlib.api.util.StackActionResult; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import java.util.List; + +@Mixin(Item.class) +public class ItemMixin { + @Inject(method = "use", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$use(World world, PlayerEntity user, Hand hand, CallbackInfoReturnable> cir) { + if (this instanceof ExtendItemProvider) { + ExtendItemProvider provider = (ExtendItemProvider) this; + Options options = new Options(); + StackActionResult returnValue = provider.onRightClick(new ItemUseEvent(world, user, hand), options); + if (options.cancel && returnValue != null) + cir.setReturnValue(returnValue.toTypedActionResult()); + } + } + + @Inject(method = "useOnBlock", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$useOnBlock(ItemUsageContext context, CallbackInfoReturnable cir) { + if (this instanceof ExtendItemProvider) { + ExtendItemProvider provider = (ExtendItemProvider) this; + ItemUsageContextMixin contextAccessor = (ItemUsageContextMixin) context; + Options options = new Options(); + CompatActionResult returnValue = provider.onRightClickOnBlock(new ItemUseOnBlockEvent(context.getPlayer(), context.getHand(), contextAccessor.getHit()), options); + if (options.cancel && returnValue != null) + cir.setReturnValue(returnValue.toActionResult()); + } + } + + @Inject(method = "useOnEntity", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$useOnEntity(ItemStack stack, PlayerEntity user, LivingEntity entity, Hand hand, CallbackInfoReturnable cir) { + if (this instanceof ExtendItemProvider) { + ExtendItemProvider provider = (ExtendItemProvider) this; + Options options = new Options(); + CompatActionResult returnValue = provider.onRightClickOnEntity(new ItemUseOnEntityEvent(stack, user, entity, hand), options); + if (options.cancel && returnValue != null) + cir.setReturnValue(returnValue.toActionResult()); + } + } + + @Inject(method = "finishUsing", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$finishUsing(ItemStack stack, World world, LivingEntity user, CallbackInfoReturnable cir) { + if (this instanceof ExtendItemProvider) { + ExtendItemProvider provider = (ExtendItemProvider) this; + Options options = new Options(); + ItemStack returnValue = provider.onFinishUsing(new ItemFinishUsingEvent(stack, world, user), options); + if (options.cancel && returnValue != null) + cir.setReturnValue(returnValue); + } + } + + @Inject(method = "hasRecipeRemainder", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$hasRecipeRemainder(CallbackInfoReturnable cir) { + if (this instanceof ExtendItemProvider) { + ExtendItemProvider provider = (ExtendItemProvider) this; + Options options = new Options(); + boolean returnValue = provider.hasRecipeRemainder(options); + if (options.cancel) + cir.setReturnValue(returnValue); + } + } + + @Inject(method = "appendTooltip", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$appendTooltip(ItemStack stack, Item.TooltipContext context, List tooltip, TooltipType type, CallbackInfo ci) { + if (this instanceof ExtendItemProvider) { + ExtendItemProvider provider = (ExtendItemProvider) this; + Options options = new Options(); + provider.appendTooltip(new ItemAppendTooltipEvent(stack, null, tooltip, type, context), options); + if (options.cancel) + ci.cancel(); + } + } + + @Inject(method = "postHit", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$postHit(ItemStack stack, LivingEntity target, LivingEntity attacker, CallbackInfoReturnable cir) { + if (this instanceof ExtendItemProvider) { + ExtendItemProvider provider = (ExtendItemProvider) this; + Options options = new Options(); + boolean returnValue = provider.postHit(new PostHitEvent(stack, target, attacker), options); + if (options.cancel) + cir.setReturnValue(returnValue); + } + } + + @Inject(method = "postMine", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$postMine(ItemStack stack, World world, BlockState state, BlockPos pos, LivingEntity miner, CallbackInfoReturnable cir) { + if (this instanceof ExtendItemProvider) { + ExtendItemProvider provider = (ExtendItemProvider) this; + Options options = new Options(); + boolean returnValue = provider.postMine(new PostMineEvent(stack, world, state, pos, miner), options); + if (options.cancel) + cir.setReturnValue(returnValue); + } + } + + @Inject(method = "onCraft", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$onCraft(ItemStack stack, World world, CallbackInfo ci) { + if (this instanceof ExtendItemProvider) { + ExtendItemProvider provider = (ExtendItemProvider) this; + Options options = new Options(); + provider.onCraft(new CraftEvent(stack, world), options); + if (options.cancel) + ci.cancel(); + } + } + + @Inject(method = "isEnchantable", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$isEnchantable(ItemStack stack, CallbackInfoReturnable cir) { + if (this instanceof ExtendItemProvider) { + ExtendItemProvider provider = (ExtendItemProvider) this; + Options options = new Options(); + boolean returnValue = provider.isEnchantable(new EnchantableArgs(stack), options); + if (options.cancel) + cir.setReturnValue(returnValue); + } + } + + @Inject(method = "getEnchantability", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$getEnchantability(CallbackInfoReturnable cir) { + if (this instanceof ExtendItemProvider) { + ExtendItemProvider provider = (ExtendItemProvider) this; + Options options = new Options(); + int returnValue = provider.getEnchantability(new EnchantabilityArgs(), options); + if (options.cancel) + cir.setReturnValue(returnValue); + } + } + + @Inject(method = "getItemBarColor", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$getItemBarColor(ItemStack stack, CallbackInfoReturnable cir) { + if (this instanceof ExtendItemProvider) { + ExtendItemProvider provider = (ExtendItemProvider) this; + Options options = new Options(); + int returnValue = provider.getItemBarColor(new ItemBarColorArgs(stack), options); + if (options.cancel) + cir.setReturnValue(returnValue); + } + } + + @Inject(method = "isItemBarVisible", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$isItemBarVisible(ItemStack stack, CallbackInfoReturnable cir) { + if (this instanceof ExtendItemProvider) { + ExtendItemProvider provider = (ExtendItemProvider) this; + Options options = new Options(); + boolean returnValue = provider.isItemBarVisible(new ItemBarVisibleArgs(stack), options); + if (options.cancel) + cir.setReturnValue(returnValue); + } + } + + @Inject(method = "getItemBarStep", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$getItemBarStep(ItemStack stack, CallbackInfoReturnable cir) { + if (this instanceof ExtendItemProvider) { + ExtendItemProvider provider = (ExtendItemProvider) this; + Options options = new Options(); + int returnValue = provider.getItemBarStep(new ItemBarStepArgs(stack), options); + if (options.cancel) + cir.setReturnValue(returnValue); + } + } + + @Inject(method = "getBonusAttackDamage", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$getBonusAttackDamage(Entity target, float baseAttackDamage, DamageSource damageSource, CallbackInfoReturnable cir) { + if (this instanceof ExtendItemProvider) { + ExtendItemProvider provider = (ExtendItemProvider) this; + Options options = new Options(); + float returnValue = provider.getBonusAttackDamage(new BonusAttackDamageArgs(target, baseAttackDamage, damageSource), options); + if (options.cancel) + cir.setReturnValue(returnValue); + } + } + + @Inject(method = "getUseAction", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$getUseAction(ItemStack stack, CallbackInfoReturnable cir) { + if (this instanceof CompatItemProvider) { + CompatItemProvider provider = (CompatItemProvider) this; + Options options = new Options(); + CompatUseAction returnValue = provider.getUseAction(new UseActionArgs(stack), options); + if (options.cancel) + cir.setReturnValue(returnValue.getUseAction()); + } + } + + @Inject(method = "inventoryTick", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$inventoryTick(ItemStack stack, World world, Entity entity, int slot, boolean selected, CallbackInfo ci) { + // イベントを呼び出す + if (!ItemEventRegistry.INVENTORY_TICK.isEmpty()) { + int maxPriority = ItemEventRegistry.INVENTORY_TICK.getMaxPriority(); + for (int p = maxPriority; p >= 0; p--) { + for (InventoryTickTask listener : ItemEventRegistry.INVENTORY_TICK.getListenersAsList(p)) { + listener.inventoryTick(new InventoryTickEvent(stack, world, entity, slot, selected)); + } + } + } + + // CompatItemProviderを実装している場合 + if (this instanceof CompatItemProvider) { + CompatItemProvider provider = (CompatItemProvider) this; + Options options = new Options(); + provider.inventoryTick(new InventoryTickEvent(stack, world, entity, slot, selected), options); + if (options.cancel) + ci.cancel(); + } + } + + @Inject(method = "getRecipeRemainder", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$getRecipeRemainder(CallbackInfoReturnable cir) { + if (this instanceof FixedRecipeRemainderItem) { + ItemStack returnValue = ((FixedRecipeRemainderItem) this) + .getFixedRecipeRemainder(ItemStackUtil.create((Item) (Object) this)); + cir.setReturnValue(returnValue); + } + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/mixin/ItemStackComponentizationFixMixin.java b/common/src/main/java/net/pitan76/mcpitanlib/mixin/ItemStackComponentizationFixMixin.java new file mode 100644 index 000000000..86b0a5bc8 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/mixin/ItemStackComponentizationFixMixin.java @@ -0,0 +1,40 @@ +package net.pitan76.mcpitanlib.mixin; + +import com.mojang.serialization.Dynamic; +import net.minecraft.datafixer.fix.ItemStackComponentizationFix; +import net.pitan76.mcpitanlib.api.datafixer.ItemStackFixer; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(ItemStackComponentizationFix.class) +public class ItemStackComponentizationFixMixin { + @Inject(method = "fixStack", at = @At("TAIL")) + private static void mcpitanlib$fixStack(ItemStackComponentizationFix.StackData data, Dynamic dynamic, CallbackInfo ci) { + if (!ItemStackFixer.getNbt2componentMapIfItemEqualMap().isEmpty()) { + ItemStackFixer.getNbt2componentMapIfItemEqualMap().forEach((itemId, map) -> { + for (String nbtKey : map.keySet()) { + if (data.itemEquals(itemId)) { + data.moveToComponent(nbtKey, map.get(nbtKey)); + } + } + }); + } + + if (!ItemStackFixer.getNbt2componentMapIfitemMatchesMap().isEmpty()) { + ItemStackFixer.getNbt2componentMapIfitemMatchesMap().forEach((itemIds, map) -> { + for (String nbtKey : map.keySet()) { + if (data.itemMatches(itemIds)) { + data.moveToComponent(nbtKey, map.get(nbtKey)); + } + } + }); + } + + if (!ItemStackFixer.getNbt2componentMap().isEmpty()) { + ItemStackFixer.getNbt2componentMap().forEach(data::moveToComponent); + } + } + +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/mixin/ItemStackMixin.java b/common/src/main/java/net/pitan76/mcpitanlib/mixin/ItemStackMixin.java new file mode 100644 index 000000000..cc416d13c --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/mixin/ItemStackMixin.java @@ -0,0 +1,25 @@ +package net.pitan76.mcpitanlib.mixin; + +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.server.world.ServerWorld; +import net.pitan76.mcpitanlib.api.event.v0.event.ItemStackActionEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import java.util.function.Consumer; + +@Mixin(ItemStack.class) +public abstract class ItemStackMixin { + + @Inject(method = "damage(ILnet/minecraft/server/world/ServerWorld;Lnet/minecraft/server/network/ServerPlayerEntity;Ljava/util/function/Consumer;)V", at = @At("HEAD"), cancellable = true) + public void mcpitanlib$damage(int amount, ServerWorld world, ServerPlayerEntity player, Consumer breakCallback, CallbackInfo ci) { + ItemStackActionEvent.returnValue = null; + ItemStackActionEvent.call((ItemStack) (Object) this); + if (ItemStackActionEvent.returnValue != null) + ci.cancel(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/mixin/ItemUsageContextMixin.java b/common/src/main/java/net/pitan76/mcpitanlib/mixin/ItemUsageContextMixin.java new file mode 100644 index 000000000..5d5557f7e --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/mixin/ItemUsageContextMixin.java @@ -0,0 +1,12 @@ +package net.pitan76.mcpitanlib.mixin; + +import net.minecraft.item.ItemUsageContext; +import net.minecraft.util.hit.BlockHitResult; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +@Mixin(ItemUsageContext.class) +public interface ItemUsageContextMixin { + @Accessor + public BlockHitResult getHit(); +} \ No newline at end of file diff --git a/common/src/main/java/net/pitan76/mcpitanlib/mixin/MinecraftServerTimer.java b/common/src/main/java/net/pitan76/mcpitanlib/mixin/MinecraftServerTimer.java new file mode 100644 index 000000000..f4c81ebb0 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/mixin/MinecraftServerTimer.java @@ -0,0 +1,38 @@ +package net.pitan76.mcpitanlib.mixin; + +import net.minecraft.server.MinecraftServer; +import net.pitan76.mcpitanlib.api.timer.MinecraftServerTimerAccess; +import net.pitan76.mcpitanlib.api.timer.TimerItem; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import java.util.ArrayList; +import java.util.List; +import java.util.function.Supplier; + +@Mixin(MinecraftServer.class) +public class MinecraftServerTimer implements MinecraftServerTimerAccess { + @Unique + private final List mcpitanlib$timerItems = new ArrayList<>(); + + @Inject(method = "tick", at = @At("TAIL")) + private void mcpitanlib$onTick(CallbackInfo ci) { + if (mcpitanlib$timerItems.isEmpty()) return; + List items = new ArrayList<>(mcpitanlib$timerItems); + + for (TimerItem item : items) { + if (--item.ticksUntilSomething == 0L) { + if (item.executeSupplier.get()) + mcpitanlib$timerItems.remove(item); + } + } + } + + @Override + public void mcpitanlib$addTimer(long ticksUntilSomething, Supplier executeSupplier) { + mcpitanlib$timerItems.add(new TimerItem(ticksUntilSomething, executeSupplier)); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/mixin/RecipeManagerMixin.java b/common/src/main/java/net/pitan76/mcpitanlib/mixin/RecipeManagerMixin.java new file mode 100644 index 000000000..9a79a2f02 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/mixin/RecipeManagerMixin.java @@ -0,0 +1,32 @@ +package net.pitan76.mcpitanlib.mixin; + +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableMultimap; +import com.google.gson.JsonElement; +import net.minecraft.recipe.RecipeEntry; +import net.minecraft.recipe.RecipeManager; +import net.minecraft.recipe.RecipeType; +import net.minecraft.resource.ResourceManager; +import net.minecraft.util.Identifier; +import net.minecraft.util.profiler.Profiler; +import net.pitan76.mcpitanlib.api.event.v0.event.RecipeManagerEvent; +import net.pitan76.mcpitanlib.api.event.v1.RecipeManagerRegistry; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +import java.util.Map; + +@Mixin(RecipeManager.class) +public class RecipeManagerMixin { + + @Inject(method = "apply(Ljava/util/Map;Lnet/minecraft/resource/ResourceManager;Lnet/minecraft/util/profiler/Profiler;)V", locals = LocalCapture.CAPTURE_FAILHARD, + at = @At(value = "TAIL")) + private void mcpitanlib$invokeApply(Map map, ResourceManager resourceManager, Profiler profiler, CallbackInfo ci, ImmutableMultimap.Builder, RecipeEntry> builder, ImmutableMap.Builder> builder2) { + if (RecipeManagerRegistry.managers.isEmpty()) return; + RecipeManagerRegistry.managers.forEach((manager) -> manager.apply(new RecipeManagerEvent(map, resourceManager, profiler, builder2, builder))); + } + +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/mixin/RecipeMixin.java b/common/src/main/java/net/pitan76/mcpitanlib/mixin/RecipeMixin.java new file mode 100644 index 000000000..8d58cb4ed --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/mixin/RecipeMixin.java @@ -0,0 +1,28 @@ +package net.pitan76.mcpitanlib.mixin; + +import net.minecraft.item.ItemStack; +import net.minecraft.recipe.Recipe; +import net.minecraft.recipe.input.RecipeInput; +import net.minecraft.util.collection.DefaultedList; +import net.pitan76.mcpitanlib.api.item.FixedRecipeRemainderItem; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(Recipe.class) +public interface RecipeMixin { + @Inject(method = "getRemainder", at = @At("RETURN")) + private void mcpitanlib$getRemainder(T input, CallbackInfoReturnable> cir) { + DefaultedList defaultedList = cir.getReturnValue(); + + int i = 0; + for (ItemStack stack : defaultedList) { + if (stack.getItem() instanceof FixedRecipeRemainderItem) { + FixedRecipeRemainderItem remainder = (FixedRecipeRemainderItem) stack.getItem(); + defaultedList.set(i, remainder.getFixedRecipeRemainder(stack.copy())); + } + i++; + } + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/mixin/ServerWorldTimer.java b/common/src/main/java/net/pitan76/mcpitanlib/mixin/ServerWorldTimer.java new file mode 100644 index 000000000..72663172e --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/mixin/ServerWorldTimer.java @@ -0,0 +1,38 @@ +package net.pitan76.mcpitanlib.mixin; + +import net.minecraft.server.world.ServerWorld; +import net.pitan76.mcpitanlib.api.timer.ServerWorldTimerAccess; +import net.pitan76.mcpitanlib.api.timer.TimerItem; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import java.util.ArrayList; +import java.util.List; +import java.util.function.Supplier; + +@Mixin(ServerWorld.class) +public class ServerWorldTimer implements ServerWorldTimerAccess { + @Unique + private final List mcpitanlib$timerItems = new ArrayList<>(); + + @Inject(method = "tick", at = @At("TAIL")) + private void onTick(CallbackInfo ci) { + if (mcpitanlib$timerItems.isEmpty()) return; + List items = new ArrayList<>(mcpitanlib$timerItems); + + for (TimerItem item : items) { + if (--item.ticksUntilSomething == 0L) { + if (item.executeSupplier.get()) + mcpitanlib$timerItems.remove(item); + } + } + } + + @Override + public void mcpitanlib$addTimer(long ticksUntilSomething, Supplier executeSupplier) { + mcpitanlib$timerItems.add(new TimerItem(ticksUntilSomething, executeSupplier)); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/test/ExampleCommand.java b/common/src/main/java/net/pitan76/mcpitanlib/test/ExampleCommand.java new file mode 100644 index 000000000..568fa9c5d --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/test/ExampleCommand.java @@ -0,0 +1,50 @@ +package net.pitan76.mcpitanlib.test; + +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import net.minecraft.item.ItemStack; +import net.pitan76.mcpitanlib.api.command.CommandSettings; +import net.pitan76.mcpitanlib.api.command.LiteralCommand; +import net.pitan76.mcpitanlib.api.command.argument.IntegerCommand; +import net.pitan76.mcpitanlib.api.event.IntegerCommandEvent; +import net.pitan76.mcpitanlib.api.event.ServerCommandEvent; + +public class ExampleCommand extends LiteralCommand { + + @Override + public void init(CommandSettings settings) { + addArgumentCommand("item", new LiteralCommand() { + @Override + public void init(CommandSettings settings) { + addArgumentCommand(new IntegerCommand() { + @Override + public void execute(IntegerCommandEvent event) { + try { + event.getPlayer().offerOrDrop(new ItemStack(ExampleMod.EXAMPLE_ITEM.getOrNull(), event.getValue())); + } catch (CommandSyntaxException ignored) { + + } + } + + @Override + public String getArgumentName() { + return "count"; + } + }); + } + + @Override + public void execute(ServerCommandEvent event) { + try { + event.getPlayer().offerOrDrop(new ItemStack(ExampleMod.EXAMPLE_ITEM.getOrNull())); + } catch (CommandSyntaxException ignored) { + + } + } + }); + } + + @Override + public void execute(ServerCommandEvent event) { + System.out.println(event.getInput()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/test/ExampleContainerGui.java b/common/src/main/java/net/pitan76/mcpitanlib/test/ExampleContainerGui.java new file mode 100644 index 000000000..ab182e28c --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/test/ExampleContainerGui.java @@ -0,0 +1,26 @@ +package net.pitan76.mcpitanlib.test; + +import net.minecraft.inventory.Inventory; +import net.pitan76.mcpitanlib.api.entity.Player; +import net.pitan76.mcpitanlib.api.gui.args.CreateMenuEvent; +import net.pitan76.mcpitanlib.api.util.InventoryUtil; +import net.pitan76.mcpitanlib.api.util.debug.OutputUtil; +import net.pitan76.mcpitanlib.guilib.api.container.SimpleContainerGui; + +public class ExampleContainerGui extends SimpleContainerGui { + + public static Inventory EXAMPLE_INVENTORY = InventoryUtil.createSimpleInventory(1); + + public ExampleContainerGui(CreateMenuEvent e) { + super(ExampleMod.EXAMPLE_CONTAINER_GUI.get(), e); + addPlayerMainInventorySlots(e.playerInventory, 8, 84); + addPlayerHotbarSlots(e.playerInventory, 8, 142); + + addNormalSlot(EXAMPLE_INVENTORY, 0, 24, 24); + } + + @Override + public void close(Player player) { + OutputUtil.print(EXAMPLE_INVENTORY); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/test/ExampleContainerGuiScreen.java b/common/src/main/java/net/pitan76/mcpitanlib/test/ExampleContainerGuiScreen.java new file mode 100644 index 000000000..3e6d42413 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/test/ExampleContainerGuiScreen.java @@ -0,0 +1,30 @@ +package net.pitan76.mcpitanlib.test; + +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.text.Text; +import net.pitan76.mcpitanlib.api.client.gui.screen.CompatInventoryScreen; +import net.pitan76.mcpitanlib.api.client.gui.widget.CompatibleTexturedButtonWidget; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; + +public class ExampleContainerGuiScreen extends CompatInventoryScreen { + + public static CompatIdentifier GUI = CompatIdentifier.of("textures/gui/container/blast_furnace.png"); + + public ExampleContainerGuiScreen(ExampleScreenHandler handler, PlayerInventory inventory, Text title) { + super(handler, inventory, title); + } + + @Override + public CompatIdentifier getCompatTexture() { + return GUI; + } + + @Override + public void initOverride() { + super.initOverride(); + System.out.println("hogehogehoge1111"); + this.addDrawableCTBW(new CompatibleTexturedButtonWidget(0, 0, 30, 30, 0, 0, GUI, (buttonWidget) -> { + System.out.println("hogehoge"); + })); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/test/ExampleGuiBlock.java b/common/src/main/java/net/pitan76/mcpitanlib/test/ExampleGuiBlock.java new file mode 100644 index 000000000..7a52d1587 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/test/ExampleGuiBlock.java @@ -0,0 +1,36 @@ +package net.pitan76.mcpitanlib.test; + +import net.minecraft.screen.ScreenHandler; +import net.minecraft.text.Text; +import net.pitan76.mcpitanlib.api.block.v2.CompatibleBlockSettings; +import net.pitan76.mcpitanlib.api.block.v2.CompatBlock; +import net.pitan76.mcpitanlib.api.event.block.BlockUseEvent; +import net.pitan76.mcpitanlib.api.event.container.factory.DisplayNameArgs; +import net.pitan76.mcpitanlib.api.gui.args.CreateMenuEvent; +import net.pitan76.mcpitanlib.api.gui.v2.SimpleScreenHandlerFactory; +import net.pitan76.mcpitanlib.api.util.CompatActionResult; + +public class ExampleGuiBlock extends CompatBlock implements SimpleScreenHandlerFactory { + + public ExampleGuiBlock(CompatibleBlockSettings settings) { + super(settings); + } + + @Override + public CompatActionResult onRightClick(BlockUseEvent e) { + if (e.isClient()) + e.player.openGuiScreen(this); + + return e.success(); + } + + @Override + public Text getDisplayName(DisplayNameArgs args) { + return getName(); + } + + @Override + public ScreenHandler createMenu(CreateMenuEvent e) { + return new ExampleScreenHandler(e); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/test/ExampleGuiItem.java b/common/src/main/java/net/pitan76/mcpitanlib/test/ExampleGuiItem.java new file mode 100644 index 000000000..7f3571e0a --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/test/ExampleGuiItem.java @@ -0,0 +1,37 @@ +package net.pitan76.mcpitanlib.test; + +import net.minecraft.screen.ScreenHandler; +import net.minecraft.text.Text; +import net.pitan76.mcpitanlib.api.event.container.factory.DisplayNameArgs; +import net.pitan76.mcpitanlib.api.event.item.ItemUseEvent; +import net.pitan76.mcpitanlib.api.gui.args.CreateMenuEvent; +import net.pitan76.mcpitanlib.api.gui.v2.SimpleScreenHandlerFactory; +import net.pitan76.mcpitanlib.api.item.v2.CompatibleItemSettings; +import net.pitan76.mcpitanlib.api.item.v2.CompatItem; +import net.pitan76.mcpitanlib.api.util.StackActionResult; +import net.pitan76.mcpitanlib.api.util.TextUtil; + +public class ExampleGuiItem extends CompatItem implements SimpleScreenHandlerFactory { + + public ExampleGuiItem(CompatibleItemSettings settings) { + super(settings); + } + + @Override + public StackActionResult onRightClick(ItemUseEvent e) { + if (!e.isClient()) + e.user.openGuiScreen(this); + + return e.success(); + } + + @Override + public Text getDisplayName(DisplayNameArgs args) { + return TextUtil.literal("Example Title"); + } + + @Override + public ScreenHandler createMenu(CreateMenuEvent e) { + return new ExampleScreenHandler(e); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/test/ExampleMod.java b/common/src/main/java/net/pitan76/mcpitanlib/test/ExampleMod.java new file mode 100644 index 000000000..0f33c0938 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/test/ExampleMod.java @@ -0,0 +1,88 @@ +package net.pitan76.mcpitanlib.test; + +import net.minecraft.block.Block; +import net.minecraft.item.Item; +import net.minecraft.screen.ScreenHandlerType; +import net.pitan76.mcpitanlib.api.CommonModInitializer; +import net.pitan76.mcpitanlib.api.block.v2.CompatibleBlockSettings; +import net.pitan76.mcpitanlib.api.block.CompatibleMaterial; +import net.pitan76.mcpitanlib.api.block.v2.CompatBlock; +import net.pitan76.mcpitanlib.api.command.CommandRegistry; +import net.pitan76.mcpitanlib.api.gui.SimpleScreenHandlerTypeBuilder; +import net.pitan76.mcpitanlib.api.item.v2.CompatItem; +import net.pitan76.mcpitanlib.api.item.v2.CompatibleItemSettings; +import net.pitan76.mcpitanlib.api.simple.item.SimpleGuiItem; +import net.pitan76.mcpitanlib.api.registry.result.RegistryResult; +import net.pitan76.mcpitanlib.api.registry.result.SupplierResult; +import net.pitan76.mcpitanlib.api.registry.v2.CompatRegistryV2; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.api.util.item.ItemUtil; +import net.pitan76.mcpitanlib.guilib.GuiRegistry; +import net.pitan76.mcpitanlib.midohra.item.ItemGroups; + +public class ExampleMod extends CommonModInitializer { + public static final String MOD_ID = "examplemod"; + public static final String MOD_NAME = "ExampleMod"; + + public static ExampleMod INSTANCE; + public static CompatRegistryV2 registry; + + public static SupplierResult> EXAMPLE_SCREENHANDLER; + public static SupplierResult> EXAMPLE_CONTAINER_GUI; + + public static RegistryResult EXAMPLE_ITEM; + public static RegistryResult EXAMPLE_BLOCK; + public static RegistryResult EXAMPLE_BLOCK_ITEM; + public static RegistryResult EXAMPLE_GUI_ITEM; + public static RegistryResult EXAMPLE_CONTAINER_GUI_ITEM; + public static RegistryResult EXAMPLE_GUI_BLOCK; + public static RegistryResult EXAMPLE_GUI_BLOCK_ITEM; + + public static CompatIdentifier EXAMPLE_ITEM_ID = _id("example_item"); + public static CompatIdentifier EXAMPLE_BLOCK_ID = _id("example_block"); + public static CompatIdentifier EXAMPLE_GUI_ITEM_ID = _id("example_gui_item"); + public static CompatIdentifier EXAMPLE_GUI_BLOCK_ID = _id("example_gui_block"); + public static CompatIdentifier EXAMPLE_CONTAINER_GUI_ITEM_ID = _id("example_container_gui_item"); + + + public void init() { + INSTANCE = this; + registry = super.registry; + + // en: Register all items, blocks and others. , ja: 全てのアイテム、ブロック、その他を登録します。 + EXAMPLE_SCREENHANDLER = registry.registerScreenHandlerType(compatId("example_gui"), new SimpleScreenHandlerTypeBuilder<>(ExampleScreenHandler::new)); + EXAMPLE_CONTAINER_GUI = GuiRegistry.register(registry, compatId("example_container_gui"), new SimpleScreenHandlerTypeBuilder<>(ExampleContainerGui::new)); + + EXAMPLE_ITEM = registry.registerItem(EXAMPLE_ITEM_ID, () -> new CompatItem(CompatibleItemSettings.of(EXAMPLE_ITEM_ID).addGroup(ItemGroups.INGREDIENTS))); + EXAMPLE_BLOCK = registry.registerBlock(EXAMPLE_BLOCK_ID, () -> new CompatBlock(CompatibleBlockSettings.of(EXAMPLE_BLOCK_ID, CompatibleMaterial.STONE))); + EXAMPLE_BLOCK_ITEM = registry.registerItem(EXAMPLE_BLOCK_ID, () -> ItemUtil.create(EXAMPLE_BLOCK.supplier.get(), CompatibleItemSettings.of(EXAMPLE_BLOCK_ID).addGroup(ItemGroups.INGREDIENTS))); + + EXAMPLE_GUI_ITEM = registry.registerItem(EXAMPLE_GUI_ITEM_ID, () -> new ExampleGuiItem(CompatibleItemSettings.of(EXAMPLE_GUI_ITEM_ID).addGroup(ItemGroups.INGREDIENTS))); + + EXAMPLE_GUI_BLOCK = registry.registerBlock(EXAMPLE_GUI_BLOCK_ID, () -> new ExampleGuiBlock(CompatibleBlockSettings.of(EXAMPLE_GUI_BLOCK_ID, CompatibleMaterial.STONE))); + EXAMPLE_GUI_BLOCK_ITEM = registry.registerItem(EXAMPLE_GUI_BLOCK_ID, () -> ItemUtil.create(EXAMPLE_GUI_BLOCK.supplier.get(), CompatibleItemSettings.of(EXAMPLE_GUI_BLOCK_ID).addGroup(ItemGroups.INGREDIENTS))); + + EXAMPLE_CONTAINER_GUI_ITEM = registry.registerItem(EXAMPLE_CONTAINER_GUI_ITEM_ID, + () -> new SimpleGuiItem(CompatibleItemSettings.of(EXAMPLE_CONTAINER_GUI_ITEM_ID) + .addGroup(ItemGroups.INGREDIENTS), + ExampleContainerGui::new) + ); + + // en: Register the command , ja: コマンドを登録します + CommandRegistry.register("mpla", new ExampleCommand()); + } + + public static CompatIdentifier _id(String id) { + return CompatIdentifier.of(MOD_ID, id); + } + + @Override + public String getId() { + return MOD_ID; + } + + @Override + public String getName() { + return MOD_NAME; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/test/ExampleModClient.java b/common/src/main/java/net/pitan76/mcpitanlib/test/ExampleModClient.java new file mode 100644 index 000000000..aa3b041be --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/test/ExampleModClient.java @@ -0,0 +1,12 @@ +package net.pitan76.mcpitanlib.test; + +import net.pitan76.mcpitanlib.api.client.registry.CompatRegistryClient; +import net.pitan76.mcpitanlib.guilib.GuiRegistry; + +public class ExampleModClient { + public static void init() { + CompatRegistryClient.registerScreen(ExampleMod.MOD_ID, ExampleMod.EXAMPLE_SCREENHANDLER.get(), ExampleScreen::new); + + GuiRegistry.registerSimpleContainerGui(ExampleMod.MOD_ID, ExampleMod.EXAMPLE_CONTAINER_GUI.get()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/test/ExampleScreen.java b/common/src/main/java/net/pitan76/mcpitanlib/test/ExampleScreen.java new file mode 100644 index 000000000..17bd18c72 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/test/ExampleScreen.java @@ -0,0 +1,30 @@ +package net.pitan76.mcpitanlib.test; + +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.text.Text; +import net.pitan76.mcpitanlib.api.client.gui.screen.CompatInventoryScreen; +import net.pitan76.mcpitanlib.api.client.gui.widget.CompatibleTexturedButtonWidget; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; + +public class ExampleScreen extends CompatInventoryScreen { + + public static CompatIdentifier GUI = CompatIdentifier.of("textures/gui/container/blast_furnace.png"); + + public ExampleScreen(ExampleScreenHandler handler, PlayerInventory inventory, Text title) { + super(handler, inventory, title); + } + + @Override + public CompatIdentifier getCompatTexture() { + return GUI; + } + + @Override + public void initOverride() { + super.initOverride(); + System.out.println("hogehogehoge1111"); + this.addDrawableCTBW(new CompatibleTexturedButtonWidget(0, 0, 30, 30, 0, 0, GUI, (buttonWidget) -> { + System.out.println("hogehoge"); + })); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/test/ExampleScreenHandler.java b/common/src/main/java/net/pitan76/mcpitanlib/test/ExampleScreenHandler.java new file mode 100644 index 000000000..ff99d6ae9 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/test/ExampleScreenHandler.java @@ -0,0 +1,24 @@ +package net.pitan76.mcpitanlib.test; + +import net.minecraft.item.ItemStack; +import net.pitan76.mcpitanlib.api.entity.Player; +import net.pitan76.mcpitanlib.api.gui.SimpleScreenHandler; +import net.pitan76.mcpitanlib.api.gui.args.CreateMenuEvent; + +public class ExampleScreenHandler extends SimpleScreenHandler { + + public ExampleScreenHandler(CreateMenuEvent e) { + super(ExampleMod.EXAMPLE_SCREENHANDLER.get(), e); + + } + + @Override + public ItemStack quickMoveOverride(Player player, int slot) { + return null; + } + + @Override + public boolean canUse(Player player) { + return true; + } +} diff --git a/common/src/main/resources/assets/mplguilib/textures/container/base.png b/common/src/main/resources/assets/mplguilib/textures/container/base.png new file mode 100644 index 000000000..e5fca7df1 Binary files /dev/null and b/common/src/main/resources/assets/mplguilib/textures/container/base.png differ diff --git a/common/src/main/resources/assets/mplguilib/textures/container/base_furnace.png b/common/src/main/resources/assets/mplguilib/textures/container/base_furnace.png new file mode 100644 index 000000000..20a8bd98b Binary files /dev/null and b/common/src/main/resources/assets/mplguilib/textures/container/base_furnace.png differ diff --git a/common/src/main/resources/assets/mplguilib/textures/container/gui_parts.png b/common/src/main/resources/assets/mplguilib/textures/container/gui_parts.png new file mode 100644 index 000000000..917a9616a Binary files /dev/null and b/common/src/main/resources/assets/mplguilib/textures/container/gui_parts.png differ diff --git a/common/src/main/resources/data/mcpitanlib/tags/items/diamond_tool_materials.json b/common/src/main/resources/data/mcpitanlib/tags/items/diamond_tool_materials.json new file mode 100644 index 000000000..f44f30dd5 --- /dev/null +++ b/common/src/main/resources/data/mcpitanlib/tags/items/diamond_tool_materials.json @@ -0,0 +1,5 @@ +{ + "values": [ + "minecraft:diamond" + ] +} \ No newline at end of file diff --git a/common/src/main/resources/data/mcpitanlib/tags/items/gold_tool_materials.json b/common/src/main/resources/data/mcpitanlib/tags/items/gold_tool_materials.json new file mode 100644 index 000000000..07e9f66a3 --- /dev/null +++ b/common/src/main/resources/data/mcpitanlib/tags/items/gold_tool_materials.json @@ -0,0 +1,5 @@ +{ + "values": [ + "minecraft:gold_ingot" + ] +} \ No newline at end of file diff --git a/common/src/main/resources/data/mcpitanlib/tags/items/iron_tool_materials.json b/common/src/main/resources/data/mcpitanlib/tags/items/iron_tool_materials.json new file mode 100644 index 000000000..c656021bd --- /dev/null +++ b/common/src/main/resources/data/mcpitanlib/tags/items/iron_tool_materials.json @@ -0,0 +1,5 @@ +{ + "values": [ + "minecraft:iron_ingot" + ] +} \ No newline at end of file diff --git a/common/src/main/resources/data/mcpitanlib/tags/items/leather_armor_materials.json b/common/src/main/resources/data/mcpitanlib/tags/items/leather_armor_materials.json new file mode 100644 index 000000000..71b797d35 --- /dev/null +++ b/common/src/main/resources/data/mcpitanlib/tags/items/leather_armor_materials.json @@ -0,0 +1,5 @@ +{ + "values": [ + "minecraft:leather" + ] +} \ No newline at end of file diff --git a/common/src/main/resources/data/mcpitanlib/tags/items/netherite_tool_materials.json b/common/src/main/resources/data/mcpitanlib/tags/items/netherite_tool_materials.json new file mode 100644 index 000000000..bd6929df7 --- /dev/null +++ b/common/src/main/resources/data/mcpitanlib/tags/items/netherite_tool_materials.json @@ -0,0 +1,5 @@ +{ + "values": [ + "minecraft:netherite_ingot" + ] +} \ No newline at end of file diff --git a/common/src/main/resources/data/mcpitanlib/tags/items/stone_tool_materials.json b/common/src/main/resources/data/mcpitanlib/tags/items/stone_tool_materials.json new file mode 100644 index 000000000..e579c141b --- /dev/null +++ b/common/src/main/resources/data/mcpitanlib/tags/items/stone_tool_materials.json @@ -0,0 +1,7 @@ +{ + "values": [ + "minecraft:cobblestone", + "minecraft:blackstone", + "minecraft:cobbled_deepslate" + ] +} \ No newline at end of file diff --git a/common/src/main/resources/data/mcpitanlib/tags/items/turtle_helmet_materials.json b/common/src/main/resources/data/mcpitanlib/tags/items/turtle_helmet_materials.json new file mode 100644 index 000000000..d1d4c27fb --- /dev/null +++ b/common/src/main/resources/data/mcpitanlib/tags/items/turtle_helmet_materials.json @@ -0,0 +1,5 @@ +{ + "values": [ + "minecraft:turtle_scute" + ] +} \ No newline at end of file diff --git a/common/src/main/resources/data/mcpitanlib/tags/items/wooden_tool_materials.json b/common/src/main/resources/data/mcpitanlib/tags/items/wooden_tool_materials.json new file mode 100644 index 000000000..97fee2c01 --- /dev/null +++ b/common/src/main/resources/data/mcpitanlib/tags/items/wooden_tool_materials.json @@ -0,0 +1,5 @@ +{ + "values": [ + "#minecraft:planks" + ] +} \ No newline at end of file diff --git a/common/src/main/resources/icon.png b/common/src/main/resources/icon.png new file mode 100644 index 000000000..cdbbf1fa0 Binary files /dev/null and b/common/src/main/resources/icon.png differ diff --git a/common/src/main/resources/mcpitanlib-common.mixins.json b/common/src/main/resources/mcpitanlib-common.mixins.json new file mode 100644 index 000000000..076c45dea --- /dev/null +++ b/common/src/main/resources/mcpitanlib-common.mixins.json @@ -0,0 +1,26 @@ +{ + "required": true, + "minVersion": "0.8", + "package": "net.pitan76.mcpitanlib.mixin", + "compatibilityLevel": "JAVA_8", + "mixins": [ + "AbstractBlock4CompatProviderMixin", + "AbstractBlockMixin", + "Block4CompatProviderMixin", + "BlockInvoker", + "BlockMixin", + "RecipeMixin", + "ItemMixin", + "ItemStackComponentizationFixMixin", + "ItemStackMixin", + "ItemUsageContextMixin", + "MinecraftServerTimer", + "RecipeManagerMixin", + "ServerWorldTimer" + ], + "client": [ + ], + "injectors": { + "defaultRequire": 1 + } +} diff --git a/common/src/main/resources/mcpitanlib.accesswidener b/common/src/main/resources/mcpitanlib.accesswidener new file mode 100644 index 000000000..bb30c381c --- /dev/null +++ b/common/src/main/resources/mcpitanlib.accesswidener @@ -0,0 +1,26 @@ +accessWidener v2 named +accessible field net/minecraft/item/ItemGroups BUILDING_BLOCKS Lnet/minecraft/registry/RegistryKey; +accessible field net/minecraft/item/ItemGroups COLORED_BLOCKS Lnet/minecraft/registry/RegistryKey; +accessible field net/minecraft/item/ItemGroups NATURAL Lnet/minecraft/registry/RegistryKey; +accessible field net/minecraft/item/ItemGroups FUNCTIONAL Lnet/minecraft/registry/RegistryKey; +accessible field net/minecraft/item/ItemGroups REDSTONE Lnet/minecraft/registry/RegistryKey; +accessible field net/minecraft/item/ItemGroups HOTBAR Lnet/minecraft/registry/RegistryKey; +accessible field net/minecraft/item/ItemGroups SEARCH Lnet/minecraft/registry/RegistryKey; +accessible field net/minecraft/item/ItemGroups TOOLS Lnet/minecraft/registry/RegistryKey; +accessible field net/minecraft/item/ItemGroups COMBAT Lnet/minecraft/registry/RegistryKey; +accessible field net/minecraft/item/ItemGroups FOOD_AND_DRINK Lnet/minecraft/registry/RegistryKey; +accessible field net/minecraft/item/ItemGroups INGREDIENTS Lnet/minecraft/registry/RegistryKey; +accessible field net/minecraft/item/ItemGroups SPAWN_EGGS Lnet/minecraft/registry/RegistryKey; +accessible field net/minecraft/item/ItemGroups OPERATOR Lnet/minecraft/registry/RegistryKey; +accessible field net/minecraft/item/ItemGroups INVENTORY Lnet/minecraft/registry/RegistryKey; + +accessible method net/minecraft/block/AbstractBlock onStateReplaced (Lnet/minecraft/block/BlockState;Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;Z)V + +accessible class net/minecraft/screen/ScreenHandlerType$Factory +accessible method net/minecraft/screen/ScreenHandlerType (Lnet/minecraft/screen/ScreenHandlerType$Factory;Lnet/minecraft/resource/featuretoggle/FeatureSet;)V +extendable method net/minecraft/screen/ScreenHandlerType (Lnet/minecraft/screen/ScreenHandlerType$Factory;Lnet/minecraft/resource/featuretoggle/FeatureSet;)V + +accessible class net/minecraft/datafixer/fix/ItemStackComponentizationFix$StackData + +accessible method net/minecraft/block/entity/BlockEntity readNbt (Lnet/minecraft/nbt/NbtCompound;Lnet/minecraft/registry/RegistryWrapper$WrapperLookup;)V +accessible method net/minecraft/block/entity/BlockEntity writeNbt (Lnet/minecraft/nbt/NbtCompound;Lnet/minecraft/registry/RegistryWrapper$WrapperLookup;)V diff --git a/fabric/build.gradle b/fabric/build.gradle index efcb67ddc..78517ba62 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -1,5 +1,5 @@ plugins { - id "com.github.johnrengelman.shadow" version "7.1.2" + id "com.github.johnrengelman.shadow" version "8.1.1" } architectury { @@ -7,6 +7,10 @@ architectury { fabric() } +loom { + accessWidenerPath = project(":common").loom.accessWidenerPath +} + configurations { common shadowCommon // Don't use shadow from the shadow plugin because we don't want IDEA to index this. @@ -23,6 +27,15 @@ dependencies { common(project(path: ":common", configuration: "namedElements")) { transitive false } shadowCommon(project(path: ":common", configuration: "transformProductionFabric")) { transitive false } + + shadowCommon 'org.yaml:snakeyaml:2.0' + + modApi("me.shedaniel.cloth:cloth-config-fabric:${rootProject.cloth_config_version}") { + exclude(group: "net.fabricmc.fabric-api") + } + include("me.shedaniel.cloth:cloth-config-fabric:${rootProject.cloth_config_version}") + + include("net.pitan76:compatdatapacks76-fabric:${rootProject.compatdatapacks76_version}") } processResources { @@ -31,21 +44,28 @@ processResources { filesMatching("fabric.mod.json") { expand "version": project.version } + + project.version = project.version + "-fabric" } shadowJar { + relocate "org.yaml.snakeyaml", "net.pitan76.mcpitanlib.shadow.yaml.snakeyaml" + + exclude "architectury.common.json" + configurations = [project.configurations.shadowCommon] - classifier "dev-shadow" + archiveClassifier.set "dev-shadow" } remapJar { - input.set shadowJar.archiveFile + injectAccessWidener = true + inputFile.set shadowJar.archiveFile dependsOn shadowJar - classifier null + archiveClassifier.set null } jar { - classifier "dev" + archiveClassifier.set "dev" } sourcesJar { @@ -61,15 +81,37 @@ components.java { } publishing { - publications { - mavenFabric(MavenPublication) { - artifactId = rootProject.archives_base_name + "-" + project.name - from components.java + publishing { + publications { + mavenFabric(MavenPublication) { + artifactId = info.archives_base_name + "-" + project.name + "-" + rootProject.minecraft_version + version = info.mod_version + from components.java + } + } + + // See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing. + repositories { + maven { + name = "GitHubPackages" + url = uri("https://maven.pkg.github.com/PTOM76/maven") + credentials { + username = project.findProperty("gpr.user") ?: System.getenv("GITHUB_ACTOR") + password = project.findProperty("gpr.key") ?: System.getenv("GITHUB_TOKEN") + } + } } } +} + +tasks.runClient.doFirst { + def from = new File("../common/src/main/resources/mcpitanlib.accesswidener") + def to = new File("src/main/resources/mcpitanlib.accesswidener") + to.bytes = from.bytes +} - // See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing. - repositories { - // Add repositories to publish to here. +tasks.remapJar.doFirst { + if (file("src/main/resources/mcpitanlib.accesswidener").exists()) { + delete file("src/main/resources/mcpitanlib.accesswidener") } } \ No newline at end of file diff --git a/fabric/src/main/java/ml/pkom/mcpitanlibarch/fabric/MCPitanLibarchFabric.java b/fabric/src/main/java/ml/pkom/mcpitanlibarch/fabric/MCPitanLibarchFabric.java deleted file mode 100644 index 9a7e82d3b..000000000 --- a/fabric/src/main/java/ml/pkom/mcpitanlibarch/fabric/MCPitanLibarchFabric.java +++ /dev/null @@ -1,11 +0,0 @@ -package ml.pkom.mcpitanlibarch.fabric; - -import ml.pkom.mcpitanlibarch.MCPitanLibarch; -import net.fabricmc.api.ModInitializer; - -public class MCPitanLibarchFabric implements ModInitializer { - @Override - public void onInitialize() { - MCPitanLibarch.init(); - } -} \ No newline at end of file diff --git a/fabric/src/main/java/net/pitan76/mcpitanlib/api/client/color/fabric/BlockColorEventImpl.java b/fabric/src/main/java/net/pitan76/mcpitanlib/api/client/color/fabric/BlockColorEventImpl.java new file mode 100644 index 000000000..a4eef8c36 --- /dev/null +++ b/fabric/src/main/java/net/pitan76/mcpitanlib/api/client/color/fabric/BlockColorEventImpl.java @@ -0,0 +1,18 @@ +package net.pitan76.mcpitanlib.api.client.color.fabric; + +import net.minecraft.block.entity.BlockEntity; +import net.pitan76.mcpitanlib.api.tile.RenderAttachmentBlockEntity; + +public class BlockColorEventImpl { + public static Object getRenderDataD(BlockEntity blockEntity) { + if (blockEntity instanceof RenderAttachmentBlockEntity) { + return ((RenderAttachmentBlockEntity) blockEntity).getCompatRenderData(); + } + + if (blockEntity instanceof net.pitan76.mcpitanlib.api.tile.RenderDataBlockEntity) { + return ((net.pitan76.mcpitanlib.api.tile.RenderDataBlockEntity) blockEntity).getCompatRenderData(); + } + + return blockEntity.getRenderData(); + } +} \ No newline at end of file diff --git a/fabric/src/main/java/net/pitan76/mcpitanlib/api/client/event/fabric/WorldRenderRegistryImpl.java b/fabric/src/main/java/net/pitan76/mcpitanlib/api/client/event/fabric/WorldRenderRegistryImpl.java new file mode 100644 index 000000000..1af714858 --- /dev/null +++ b/fabric/src/main/java/net/pitan76/mcpitanlib/api/client/event/fabric/WorldRenderRegistryImpl.java @@ -0,0 +1,136 @@ +package net.pitan76.mcpitanlib.api.client.event.fabric; + +import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents; +import net.minecraft.client.render.*; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.client.world.ClientWorld; +import net.minecraft.util.profiler.Profiler; +import net.pitan76.mcpitanlib.api.client.event.listener.BeforeBlockOutlineEvent; +import net.pitan76.mcpitanlib.api.client.event.listener.BeforeBlockOutlineListener; +import net.pitan76.mcpitanlib.api.client.event.listener.WorldRenderContext; +import net.pitan76.mcpitanlib.api.client.event.listener.WorldRenderContextListener; +import org.jetbrains.annotations.Nullable; +import org.joml.Matrix4f; + +public class WorldRenderRegistryImpl { + public static void registerWorldRenderBeforeBlockOutline(BeforeBlockOutlineListener listener) { + WorldRenderEvents.BEFORE_BLOCK_OUTLINE.register(((worldRenderContext, hitResult) -> listener.beforeBlockOutline(new BeforeBlockOutlineEvent( + new WorldRenderContext() { + @Override + public WorldRenderer getWorldRenderer() { + return worldRenderContext.worldRenderer(); + } + + @Override + public MatrixStack getMatrixStack() { + return worldRenderContext.matrixStack(); + } + + @Override + public float getTickDelta() { + return worldRenderContext.tickCounter().getTickDelta(true); + } + + @Override + public Camera getCamera() { + return worldRenderContext.camera(); + } + + @Override + public GameRenderer getGameRenderer() { + return worldRenderContext.gameRenderer(); + } + + @Override + public LightmapTextureManager getLightmapTextureManager() { + return worldRenderContext.lightmapTextureManager(); + } + + @Override + public Matrix4f getProjectionMatrix() { + return worldRenderContext.projectionMatrix(); + } + + @Override + public ClientWorld getWorld() { + return worldRenderContext.world(); + } + + @Override + public boolean isAdvancedTranslucency() { + return worldRenderContext.advancedTranslucency(); + } + + @Override + public @Nullable VertexConsumerProvider getConsumers() { + return worldRenderContext.consumers(); + } + + @Override + public @Nullable Frustum getFrustum() { + return worldRenderContext.frustum(); + } + }, hitResult)))); + } + + public static void registerWorldRenderAfterLevel(WorldRenderContextListener listener) { + WorldRenderEvents.END.register((context -> { + listener.render(new WorldRenderContext() { + @Override + public WorldRenderer getWorldRenderer() { + return context.worldRenderer(); + } + + @Override + public MatrixStack getMatrixStack() { + return context.matrixStack(); + } + + @Override + public float getTickDelta() { + return context.tickCounter().getTickDelta(true); + } + + @Override + public Camera getCamera() { + return context.camera(); + } + + @Override + public GameRenderer getGameRenderer() { + return context.gameRenderer(); + } + + @Override + public LightmapTextureManager getLightmapTextureManager() { + return context.lightmapTextureManager(); + } + + @Override + public Matrix4f getProjectionMatrix() { + return context.projectionMatrix(); + } + + @Override + public ClientWorld getWorld() { + return context.world(); + } + + @Override + public boolean isAdvancedTranslucency() { + return context.advancedTranslucency(); + } + + @Override + public @Nullable VertexConsumerProvider getConsumers() { + return context.consumers(); + } + + @Override + public @Nullable Frustum getFrustum() { + return context.frustum(); + } + }); + })); + } +} diff --git a/fabric/src/main/java/net/pitan76/mcpitanlib/api/client/registry/fabric/CompatRegistryClientImpl.java b/fabric/src/main/java/net/pitan76/mcpitanlib/api/client/registry/fabric/CompatRegistryClientImpl.java new file mode 100644 index 000000000..c4b7f7486 --- /dev/null +++ b/fabric/src/main/java/net/pitan76/mcpitanlib/api/client/registry/fabric/CompatRegistryClientImpl.java @@ -0,0 +1,25 @@ +package net.pitan76.mcpitanlib.api.client.registry.fabric; + +import dev.architectury.registry.menu.MenuRegistry; +import net.fabricmc.fabric.api.client.rendering.v1.ColorProviderRegistry; +import net.minecraft.block.Block; +import net.minecraft.client.color.block.BlockColorProvider; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.gui.screen.ingame.ScreenHandlerProvider; +import net.minecraft.screen.ScreenHandler; +import net.minecraft.screen.ScreenHandlerType; +import net.pitan76.mcpitanlib.api.client.registry.CompatRegistryClient; + +public class CompatRegistryClientImpl { + public static > void registerScreen(String modId, ScreenHandlerType type, CompatRegistryClient.ScreenFactory factory) { + MenuRegistry.registerScreenFactory(type, factory::create); + } + + public static void registerColorProviderBlock(BlockColorProvider provider, Block... blocks) { + if (blocks == null || blocks.length == 0) { + ColorProviderRegistry.BLOCK.register(provider); + } else { + ColorProviderRegistry.BLOCK.register(provider, blocks); + } + } +} diff --git a/fabric/src/main/java/net/pitan76/mcpitanlib/api/extra/transfer/util/FluidStorageUtil.java b/fabric/src/main/java/net/pitan76/mcpitanlib/api/extra/transfer/util/FluidStorageUtil.java new file mode 100644 index 000000000..42f7ec93f --- /dev/null +++ b/fabric/src/main/java/net/pitan76/mcpitanlib/api/extra/transfer/util/FluidStorageUtil.java @@ -0,0 +1,94 @@ +package net.pitan76.mcpitanlib.api.extra.transfer.util; + +import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant; +import net.fabricmc.fabric.api.transfer.v1.fluid.base.SingleFluidStorage; +import net.fabricmc.fabric.api.transfer.v1.transaction.Transaction; +import net.minecraft.fluid.FluidState; +import net.minecraft.nbt.NbtCompound; +import net.minecraft.world.World; +import net.pitan76.mcpitanlib.api.event.nbt.NbtRWArgs; +import net.pitan76.mcpitanlib.api.registry.CompatRegistryLookup; + +public class FluidStorageUtil { + public static SingleFluidStorage withFixedCapacity(long capacity, Runnable onChange) { + return SingleFluidStorage.withFixedCapacity(capacity, onChange); + } + + public static void readNbt(SingleFluidStorage storage, NbtRWArgs args) { + storage.readNbt(args.getNbt(), args.getWrapperLookup()); + } + + public static void writeNbt(SingleFluidStorage storage, NbtRWArgs args) { + storage.writeNbt(args.getNbt(), args.getWrapperLookup()); + } + + public static void readNbt(SingleFluidStorage storage, NbtCompound nbt, CompatRegistryLookup registryLookup) { + storage.readNbt(nbt, registryLookup.getRegistryLookup()); + } + + public static void writeNbt(SingleFluidStorage storage, NbtCompound nbt, CompatRegistryLookup registryLookup) { + storage.writeNbt(nbt, registryLookup.getRegistryLookup()); + } + + /** + * @deprecated Use {@link #readNbt(SingleFluidStorage, NbtRWArgs)} instead + */ + @Deprecated + public static void readNbt(SingleFluidStorage storage, NbtCompound nbt, World world) { + storage.readNbt(nbt, world.getRegistryManager()); + } + + /** + * @deprecated Use {@link #writeNbt(SingleFluidStorage, NbtRWArgs)} instead + */ + @Deprecated + public static void writeNbt(SingleFluidStorage storage, NbtCompound nbt, World world) { + storage.writeNbt(nbt, world.getRegistryManager()); + } + + public static long getAmount(SingleFluidStorage storage) { + return storage.getAmount(); + } + + public static long getCapacity(SingleFluidStorage storage) { + return storage.getCapacity(); + } + + public static FluidVariant getResource(SingleFluidStorage storage) { + return storage.getResource(); + } + + public static boolean isResourceBlank(SingleFluidStorage storage) { + return storage.isResourceBlank(); + } + + public static long insert(SingleFluidStorage storage, FluidVariant insertedVariant, long maxAmount, Transaction transaction) { + return storage.insert(insertedVariant, maxAmount, transaction); + } + + public static long extract(SingleFluidStorage storage, FluidVariant extractedVariant, long maxAmount, Transaction transaction) { + return storage.extract(extractedVariant, maxAmount, transaction); + } + + public static void insert(SingleFluidStorage storage, FluidState fluidState, long maxAmount) { + try (Transaction transaction = Transaction.openOuter()) { + insert(storage, FluidVariant.of(fluidState.getFluid()), maxAmount, transaction); + transaction.commit(); + } + } + + public static void extract(SingleFluidStorage storage, FluidState fluidState, long maxAmount) { + try (Transaction transaction = Transaction.openOuter()) { + extract(storage, FluidVariant.of(fluidState.getFluid()), maxAmount, transaction); + transaction.commit(); + } + } + + public static boolean isEmpty(SingleFluidStorage storage) { + return getAmount(storage) == 0; + } + + public static boolean isFull(SingleFluidStorage storage) { + return getAmount(storage) >= getCapacity(storage); + } +} diff --git a/fabric/src/main/java/net/pitan76/mcpitanlib/api/lookup/block/BlockApiLookupWithDirection.java b/fabric/src/main/java/net/pitan76/mcpitanlib/api/lookup/block/BlockApiLookupWithDirection.java new file mode 100644 index 000000000..9f5e6d946 --- /dev/null +++ b/fabric/src/main/java/net/pitan76/mcpitanlib/api/lookup/block/BlockApiLookupWithDirection.java @@ -0,0 +1,56 @@ +package net.pitan76.mcpitanlib.api.lookup.block; + +import net.fabricmc.fabric.api.lookup.v1.block.BlockApiLookup; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.block.entity.BlockEntityType; +import net.pitan76.mcpitanlib.midohra.block.BlockState; +import net.pitan76.mcpitanlib.midohra.block.entity.BlockEntityTypeWrapper; +import net.pitan76.mcpitanlib.midohra.block.entity.BlockEntityWrapper; +import net.pitan76.mcpitanlib.midohra.util.math.BlockPos; +import net.pitan76.mcpitanlib.midohra.util.math.Direction; +import net.pitan76.mcpitanlib.midohra.world.World; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.function.BiFunction; + +public class BlockApiLookupWithDirection extends BlockApiLookupWrapper { + + public BlockApiLookupWithDirection(BlockApiLookup<@NotNull A, net.minecraft.util.math.Direction> lookup) { + super(lookup); + } + + @Deprecated + public static BlockApiLookupWrapper of(BlockApiLookup<@NotNull A, C> lookup) { + return new BlockApiLookupWrapper<>(lookup); + } + + public static BlockApiLookupWithDirection ofDir(BlockApiLookup<@NotNull A, net.minecraft.util.math.Direction> lookup) { + return new BlockApiLookupWithDirection<>(lookup); + } + + public @Nullable A find(World world, BlockPos pos, Direction direction) { + return super.find(world, pos, direction.toMinecraft()); + } + + public @Nullable A find(World world, BlockPos pos, BlockState state, BlockEntity blockEntity, Direction direction) { + return super.find(world, pos, state, blockEntity, direction.toMinecraft()); + } + + public @Nullable A find(World world, BlockPos pos, BlockState state, BlockEntityWrapper blockEntity, Direction direction) { + return super.find(world, pos, state, blockEntity, direction.toMinecraft()); + } + + public void registerForBlockEntityM(BiFunction provider, BlockEntityType blockEntityType) { + super.registerForBlockEntity((blockEntity, direction) -> provider.apply(blockEntity, Direction.of(direction)), blockEntityType); + } + + @Deprecated + public void registerForBlockEntity(BiFunction provider, BlockEntityType blockEntityType) { + super.registerForBlockEntity(provider, blockEntityType); + } + + public void registerForBlockEntityWrapperM(BiFunction provider, BlockEntityTypeWrapper blockEntityType) { + super.registerForBlockEntityWrapper((blockEntity, direction) -> provider.apply(blockEntity, Direction.of(direction)), blockEntityType); + } +} \ No newline at end of file diff --git a/fabric/src/main/java/net/pitan76/mcpitanlib/api/lookup/block/BlockApiLookupWrapper.java b/fabric/src/main/java/net/pitan76/mcpitanlib/api/lookup/block/BlockApiLookupWrapper.java new file mode 100644 index 000000000..0651be594 --- /dev/null +++ b/fabric/src/main/java/net/pitan76/mcpitanlib/api/lookup/block/BlockApiLookupWrapper.java @@ -0,0 +1,57 @@ +package net.pitan76.mcpitanlib.api.lookup.block; + +import net.fabricmc.fabric.api.lookup.v1.block.BlockApiLookup; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.block.entity.BlockEntityType; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.midohra.block.BlockState; +import net.pitan76.mcpitanlib.midohra.block.entity.BlockEntityTypeWrapper; +import net.pitan76.mcpitanlib.midohra.block.entity.BlockEntityWrapper; +import net.pitan76.mcpitanlib.midohra.util.math.BlockPos; +import net.pitan76.mcpitanlib.midohra.world.World; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.function.BiFunction; + +public class BlockApiLookupWrapper { + + private final BlockApiLookup<@NotNull A, C> lookup; + + public BlockApiLookupWrapper(BlockApiLookup<@NotNull A, C> lookup) { + this.lookup = lookup; + } + + public BlockApiLookup<@NotNull A, C> getRaw() { + return lookup; + } + + public static BlockApiLookupWrapper of(BlockApiLookup<@NotNull A, C> lookup) { + return new BlockApiLookupWrapper<>(lookup); + } + + public @Nullable A find(World world, BlockPos pos, C context) { + return lookup.find(world.getRaw(), pos.toMinecraft(), context); + } + + public @Nullable A find(World world, BlockPos pos, BlockState state, BlockEntity blockEntity, C context) { + return lookup.find(world.getRaw(), pos.toMinecraft(), state.toMinecraft(), blockEntity, context); + } + + public @Nullable A find(World world, BlockPos pos, BlockState state, BlockEntityWrapper blockEntity, C context) { + return lookup.find(world.getRaw(), pos.toMinecraft(), state.toMinecraft(), blockEntity.get(), context); + } + + public void registerForBlockEntity(BiFunction provider, BlockEntityType blockEntityType) { + lookup.registerForBlockEntity(provider, blockEntityType); + } + + public void registerForBlockEntityWrapper(BiFunction provider, BlockEntityTypeWrapper blockEntityWrapperType) { + lookup.registerForBlockEntity((blockEntity, context) -> + provider.apply(BlockEntityWrapper.of(blockEntity), context), blockEntityWrapperType.get()); + } + + public CompatIdentifier getId() { + return CompatIdentifier.fromMinecraft(lookup.getId()); + } +} \ No newline at end of file diff --git a/fabric/src/main/java/net/pitan76/mcpitanlib/api/tile/RenderAttachmentBlockEntity.java b/fabric/src/main/java/net/pitan76/mcpitanlib/api/tile/RenderAttachmentBlockEntity.java new file mode 100644 index 000000000..94bf987ba --- /dev/null +++ b/fabric/src/main/java/net/pitan76/mcpitanlib/api/tile/RenderAttachmentBlockEntity.java @@ -0,0 +1,21 @@ +package net.pitan76.mcpitanlib.api.tile; + +import net.fabricmc.fabric.api.blockview.v2.RenderDataBlockEntity; +import org.jetbrains.annotations.Nullable; + +public interface RenderAttachmentBlockEntity extends RenderDataBlockEntity { + + @Override + @Nullable + @Deprecated + default Object getRenderData() { + return getCompatRenderData(); + } + + default boolean hasCompatRenderData() { + return getCompatRenderData() != null; + } + + @Nullable + Object getCompatRenderData(); +} diff --git a/fabric/src/main/java/net/pitan76/mcpitanlib/api/tile/fabric/RenderDataBlockEntityImpl.java b/fabric/src/main/java/net/pitan76/mcpitanlib/api/tile/fabric/RenderDataBlockEntityImpl.java new file mode 100644 index 000000000..45966b733 --- /dev/null +++ b/fabric/src/main/java/net/pitan76/mcpitanlib/api/tile/fabric/RenderDataBlockEntityImpl.java @@ -0,0 +1,14 @@ +package net.pitan76.mcpitanlib.api.tile.fabric; + +import net.fabricmc.fabric.api.blockview.v2.RenderDataBlockEntity; + +@Deprecated +public interface RenderDataBlockEntityImpl extends RenderDataBlockEntity { + + default Object getRenderData() { + if (this instanceof net.pitan76.mcpitanlib.api.tile.RenderDataBlockEntity) { + return ((net.pitan76.mcpitanlib.api.tile.RenderDataBlockEntity) this).getCompatRenderData(); + } + return null; + } +} diff --git a/fabric/src/main/java/net/pitan76/mcpitanlib/api/transfer/fluid/v1/fabric/FabricFluidStorage.java b/fabric/src/main/java/net/pitan76/mcpitanlib/api/transfer/fluid/v1/fabric/FabricFluidStorage.java new file mode 100644 index 000000000..533d1288d --- /dev/null +++ b/fabric/src/main/java/net/pitan76/mcpitanlib/api/transfer/fluid/v1/fabric/FabricFluidStorage.java @@ -0,0 +1,79 @@ +package net.pitan76.mcpitanlib.api.transfer.fluid.v1.fabric; + +import net.fabricmc.fabric.api.transfer.v1.fluid.base.SingleFluidStorage; +import net.fabricmc.fabric.api.transfer.v1.transaction.Transaction; +import net.pitan76.mcpitanlib.api.event.nbt.ReadNbtArgs; +import net.pitan76.mcpitanlib.api.event.nbt.WriteNbtArgs; +import net.pitan76.mcpitanlib.api.transfer.fluid.v1.IFluidStorage; +import net.pitan76.mcpitanlib.api.transfer.fluid.v1.IFluidVariant; + +public class FabricFluidStorage implements IFluidStorage { + + public final SingleFluidStorage storage; + + public FabricFluidStorage(SingleFluidStorage storage) { + this.storage = storage; + } + + @Override + public long getAmount() { + return storage.getAmount(); + } + + @Override + public long getCapacity() { + return storage.getCapacity(); + } + + @Override + public IFluidVariant getResource() { + return new FabricFluidVariant(storage.getResource()); + } + + @Override + public void setResource(IFluidVariant variant) { + storage.variant = ((FabricFluidVariant) variant).raw; + } + + @Override + public boolean isResourceBlank() { + return storage.isResourceBlank(); + } + + @Override + public long insert(IFluidVariant variant, long maxAmount, boolean simulate) { + if (simulate) + return storage.insert(((FabricFluidVariant) variant).raw, maxAmount, Transaction.openOuter()); + + long inserted = 0; + try (Transaction transaction = Transaction.openOuter()) { + inserted += storage.insert(((FabricFluidVariant) variant).raw, maxAmount, transaction); + transaction.commit(); + } + return inserted; + } + + @Override + public long extract(IFluidVariant variant, long maxAmount, boolean simulate) { + if (simulate) + return storage.extract(((FabricFluidVariant) variant).raw, maxAmount, Transaction.openOuter()); + + long extracted = 0; + try (Transaction transaction = Transaction.openOuter()) { + extracted += storage.extract(((FabricFluidVariant) variant).raw, maxAmount, transaction); + transaction.commit(); + } + return extracted; + } + + @Override + public void writeNbt(WriteNbtArgs args) { + storage.writeNbt(args.nbt, args.getWrapperLookup()); + } + + @Override + public void readNbt(ReadNbtArgs args) { + storage.readNbt(args.nbt, args.getWrapperLookup()); + + } +} diff --git a/fabric/src/main/java/net/pitan76/mcpitanlib/api/transfer/fluid/v1/fabric/FabricFluidVariant.java b/fabric/src/main/java/net/pitan76/mcpitanlib/api/transfer/fluid/v1/fabric/FabricFluidVariant.java new file mode 100644 index 000000000..fe003ced9 --- /dev/null +++ b/fabric/src/main/java/net/pitan76/mcpitanlib/api/transfer/fluid/v1/fabric/FabricFluidVariant.java @@ -0,0 +1,33 @@ +package net.pitan76.mcpitanlib.api.transfer.fluid.v1.fabric; + +import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant; +import net.minecraft.fluid.Fluid; +import net.pitan76.mcpitanlib.api.transfer.fluid.v1.IFluidVariant; + +public class FabricFluidVariant implements IFluidVariant { + + public final FluidVariant raw; + + public FabricFluidVariant() { + this.raw = FluidVariant.blank(); + } + + public FabricFluidVariant(FluidVariant variant) { + this.raw = variant; + } + + @Override + public Fluid getFluid() { + return raw.getFluid(); + } + + @Override + public boolean isBlank() { + return raw.isBlank(); + } + + @Override + public boolean isSame(Fluid fluid) { + return raw.isOf(fluid); + } +} diff --git a/fabric/src/main/java/net/pitan76/mcpitanlib/api/transfer/fluid/v1/fabric/FluidStorageUtilImpl.java b/fabric/src/main/java/net/pitan76/mcpitanlib/api/transfer/fluid/v1/fabric/FluidStorageUtilImpl.java new file mode 100644 index 000000000..c5d494ab7 --- /dev/null +++ b/fabric/src/main/java/net/pitan76/mcpitanlib/api/transfer/fluid/v1/fabric/FluidStorageUtilImpl.java @@ -0,0 +1,17 @@ +package net.pitan76.mcpitanlib.api.transfer.fluid.v1.fabric; + +import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant; +import net.fabricmc.fabric.api.transfer.v1.fluid.base.SingleFluidStorage; +import net.minecraft.fluid.Fluid; +import net.pitan76.mcpitanlib.api.transfer.fluid.v1.IFluidStorage; +import net.pitan76.mcpitanlib.api.transfer.fluid.v1.IFluidVariant; + +public class FluidStorageUtilImpl { + public static IFluidStorage withFixedCapacity(long capacity, Runnable onChange) { + return new FabricFluidStorage(SingleFluidStorage.withFixedCapacity(capacity, onChange)); + } + + public static IFluidVariant getVariant(Fluid fluid) { + return new FabricFluidVariant(FluidVariant.of(fluid)); + } +} diff --git a/fabric/src/main/java/net/pitan76/mcpitanlib/api/util/fabric/PlatformUtilImpl.java b/fabric/src/main/java/net/pitan76/mcpitanlib/api/util/fabric/PlatformUtilImpl.java new file mode 100644 index 000000000..5645a7e76 --- /dev/null +++ b/fabric/src/main/java/net/pitan76/mcpitanlib/api/util/fabric/PlatformUtilImpl.java @@ -0,0 +1,24 @@ +package net.pitan76.mcpitanlib.api.util.fabric; + +import net.fabricmc.api.EnvType; +import net.fabricmc.loader.api.FabricLoader; + +import java.nio.file.Path; + +public class PlatformUtilImpl { + public static boolean isClient() { + return FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT; + } + + public static boolean isServer() { + return FabricLoader.getInstance().getEnvironmentType() == EnvType.SERVER; + } + + public static Path getConfigFolder() { + return FabricLoader.getInstance().getConfigDir(); + } + + public static boolean isModLoaded(String id) { + return FabricLoader.getInstance().isModLoaded(id); + } +} diff --git a/fabric/src/main/java/net/pitan76/mcpitanlib/fabric/ExtendModInitializer.java b/fabric/src/main/java/net/pitan76/mcpitanlib/fabric/ExtendModInitializer.java new file mode 100644 index 000000000..e0244894c --- /dev/null +++ b/fabric/src/main/java/net/pitan76/mcpitanlib/fabric/ExtendModInitializer.java @@ -0,0 +1,68 @@ +package net.pitan76.mcpitanlib.fabric; + +import net.fabricmc.api.ModInitializer; +import net.minecraft.util.Identifier; +import net.pitan76.mcpitanlib.api.registry.v2.CompatRegistryV2; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.api.util.IdentifierUtil; +import net.pitan76.mcpitanlib.api.util.Logger; + +public abstract class ExtendModInitializer implements ModInitializer { + + public String MOD_ID; + public String MOD_NAME; + + public CompatRegistryV2 registry; + public Logger logger; + + @Override + public void onInitialize() { + this.MOD_ID = getId(); + this.MOD_NAME = getName(); + + this.registry = CompatRegistryV2.create(MOD_ID); + this.logger = new Logger(MOD_ID); + + logger.initializeMessage(); + init(); + registry.allRegister(); + } + + public abstract void init(); + + public abstract String getId(); + + public String getName() { + return getId(); + } + + + // Utilities + public Identifier id(String path) { + return IdentifierUtil.id(MOD_ID, path); + } + + public CompatIdentifier compatId(String path) { + return CompatIdentifier.of(MOD_ID, path); + } + + public void info(String message) { + logger.info(message); + } + + public void warn(String message) { + logger.warn(message); + } + + public void error(String message) { + logger.error(message); + } + + public void debug(String message) { + logger.debug(message); + } + + public void trace(String message) { + logger.trace(message); + } +} diff --git a/fabric/src/main/java/net/pitan76/mcpitanlib/fabric/MCPitanLibFabric.java b/fabric/src/main/java/net/pitan76/mcpitanlib/fabric/MCPitanLibFabric.java new file mode 100644 index 000000000..939cd37a0 --- /dev/null +++ b/fabric/src/main/java/net/pitan76/mcpitanlib/fabric/MCPitanLibFabric.java @@ -0,0 +1,17 @@ +package net.pitan76.mcpitanlib.fabric; + +import net.fabricmc.api.ModInitializer; +import net.pitan76.mcpitanlib.MCPitanLib; + +public class MCPitanLibFabric implements ModInitializer { + @Override + public void onInitialize() { + MCPitanLib.init(); + /* + if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) + if (FabricLoader.getInstance().isDevelopmentEnvironment()) + ExampleModClient.init(); + + */ + } +} \ No newline at end of file diff --git a/fabric/src/main/java/net/pitan76/mcpitanlib/fabric/mixin/RecipeMixin.java b/fabric/src/main/java/net/pitan76/mcpitanlib/fabric/mixin/RecipeMixin.java new file mode 100644 index 000000000..13ecb0947 --- /dev/null +++ b/fabric/src/main/java/net/pitan76/mcpitanlib/fabric/mixin/RecipeMixin.java @@ -0,0 +1,26 @@ +package net.pitan76.mcpitanlib.fabric.mixin; + +import net.minecraft.recipe.Recipe; +import net.minecraft.recipe.input.RecipeInput; +import org.spongepowered.asm.mixin.Mixin; + +@Mixin(Recipe.class) +public interface RecipeMixin { + + /* + @Inject(method = "getRemainder", at = @At("RETURN")) + default void injectGetRemainder(C input, CallbackInfoReturnable> cir) { + DefaultedList defaultedList = cir.getReturnValue(); + + int i = 0; + for(ItemStack stack : defaultedList) { + if (stack.getItem() instanceof FixedRecipeRemainderItem) { + FixedRecipeRemainderItem remainder = (FixedRecipeRemainderItem) stack.getItem(); + defaultedList.set(i, remainder.getFixedRecipeRemainder(stack.copy())); + } + i++; + } + } + + */ +} diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json index b6234c75d..be727ab43 100644 --- a/fabric/src/main/resources/fabric.mod.json +++ b/fabric/src/main/resources/fabric.mod.json @@ -1,31 +1,42 @@ { "schemaVersion": 1, - "id": "mcpitanlibarch", + "id": "mcpitanlib", "version": "${version}", - "name": "MCPitanLibarch", + "name": "MCPitanLib", "description": "Pitan's Minecraft Mod Library", "authors": [ "Pitan" ], "contact": { "website": "https://www.curseforge.com/minecraft/mc-mods/mcpitanlibarch", - "repo": "https://github.com/Pitan76/mcpitanlibarch", - "issues": "https://github.com/Pitan76/mcpitanlibarch/issue" + "repo": "https://github.com/Pitan76/MCPitanLib", + "issues": "https://github.com/Pitan76/MCPitanLib/issue" }, "license": "MIT", "icon": "icon.png", "environment": "*", "entrypoints": { "main": [ - "ml.pkom.mcpitanlibarch.fabric.MCPitanLibarchFabric" + "net.pitan76.mcpitanlib.fabric.MCPitanLibFabric" ] }, + "provides": [ + "mcpitanlibarch", + "mcpitanlib-impl" + ], + "custom": { + "modmenu": { + "badges": ["library"] + } + }, "mixins": [ - "mcpitanlibarch.mixins.json", - "mcpitanlibarch-common.mixins.json" + "mcpitanlib.mixins.json", + "mcpitanlib-common.mixins.json" ], + "accessWidener": "mcpitanlib.accesswidener", "depends": { - "fabricloader": ">=0.14.9", - "minecraft": ">=1.18" + "minecraft": ">1.20.6", + "fabricloader": "*", + "architectury": "*" } } diff --git a/fabric/src/main/resources/mcpitanlibarch.mixins.json b/fabric/src/main/resources/mcpitanlib.mixins.json similarity index 55% rename from fabric/src/main/resources/mcpitanlibarch.mixins.json rename to fabric/src/main/resources/mcpitanlib.mixins.json index 4be53d8ed..0a36c5829 100644 --- a/fabric/src/main/resources/mcpitanlibarch.mixins.json +++ b/fabric/src/main/resources/mcpitanlib.mixins.json @@ -1,9 +1,10 @@ { "required": true, "minVersion": "0.8", - "package": "ml.pkom.mcpitanlibarch.mixin.fabric", - "compatibilityLevel": "JAVA_17", + "package": "net.pitan76.mcpitanlib.fabric.mixin", + "compatibilityLevel": "JAVA_8", "mixins": [ + "RecipeMixin" ], "client": [ ], diff --git a/forge/build.gradle b/forge/build.gradle index 01c52e51f..cd23560c2 100644 --- a/forge/build.gradle +++ b/forge/build.gradle @@ -6,6 +6,18 @@ architectury { forge() } +loom { + accessWidenerPath = project(":common").loom.accessWidenerPath + + forge { + convertAccessWideners = true + extraAccessWideners.add loom.accessWidenerPath.get().asFile.name + + mixinConfig "mcpitanlib-common.mixins.json" + mixinConfig "mcpitanlib.mixins.json" + } +} + configurations { common shadowCommon // Don't use shadow from the shadow plugin because we don't want IDEA to index this. @@ -17,10 +29,17 @@ configurations { dependencies { forge "net.minecraftforge:forge:${rootProject.forge_version}" // Remove the next line if you don't want to depend on the API - modApi "dev.architectury:architectury-forge:${rootProject.architectury_version}" + //modApi "dev.architectury:architectury-forge:${rootProject.architectury_version}" common(project(path: ":common", configuration: "namedElements")) { transitive false } shadowCommon(project(path: ":common", configuration: "transformProductionForge")) { transitive = false } + + shadowCommon 'org.yaml:snakeyaml:2.0' + compileOnly 'org.yaml:snakeyaml:2.0' + + include("me.shedaniel.cloth:cloth-config-forge:${rootProject.cloth_config_version}") + + include("net.pitan76:compatdatapacks76-forge:${rootProject.compatdatapacks76_version}") } processResources { @@ -29,23 +48,26 @@ processResources { filesMatching("META-INF/mods.toml") { expand "version": project.version } + + project.version = project.version + "-forge" } shadowJar { exclude "fabric.mod.json" + exclude "architectury.common.json" configurations = [project.configurations.shadowCommon] - classifier "dev-shadow" + archiveClassifier.set "dev-shadow" } remapJar { - input.set shadowJar.archiveFile + inputFile.set shadowJar.archiveFile dependsOn shadowJar - classifier null + archiveClassifier.set null } jar { - classifier "dev" + archiveClassifier.set "dev" } sourcesJar { @@ -63,7 +85,7 @@ components.java { publishing { publications { mavenForge(MavenPublication) { - artifactId = rootProject.archives_base_name + "-" + project.name + artifactId = info.archives_base_name + "-" + project.name from components.java } } diff --git a/forge/src/main/java/ml/pkom/mcpitanlibarch/forge/MCPitanLibarchForge.java b/forge/src/main/java/ml/pkom/mcpitanlibarch/forge/MCPitanLibarchForge.java deleted file mode 100644 index 0e5012e9a..000000000 --- a/forge/src/main/java/ml/pkom/mcpitanlibarch/forge/MCPitanLibarchForge.java +++ /dev/null @@ -1,15 +0,0 @@ -package ml.pkom.mcpitanlibarch.forge; - -import dev.architectury.platform.forge.EventBuses; -import ml.pkom.mcpitanlibarch.MCPitanLibarch; -import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; - -@Mod(MCPitanLibarch.MOD_ID) -public class MCPitanLibarchForge { - public MCPitanLibarchForge() { - // Submit our event bus to let architectury register our content on the right time - EventBuses.registerModEventBus(MCPitanLibarch.MOD_ID, FMLJavaModLoadingContext.get().getModEventBus()); - MCPitanLibarch.init(); - } -} \ No newline at end of file diff --git a/forge/src/main/java/net/pitan76/mcpitanlib/api/util/forge/PlatformUtilImpl.java b/forge/src/main/java/net/pitan76/mcpitanlib/api/util/forge/PlatformUtilImpl.java new file mode 100644 index 000000000..80019e102 --- /dev/null +++ b/forge/src/main/java/net/pitan76/mcpitanlib/api/util/forge/PlatformUtilImpl.java @@ -0,0 +1,26 @@ +package net.pitan76.mcpitanlib.api.util.forge; + +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.fml.ModList; +import net.minecraftforge.fml.loading.FMLEnvironment; +import net.minecraftforge.fml.loading.FMLPaths; + +import java.nio.file.Path; + +public class PlatformUtilImpl { + public static boolean isClient() { + return FMLEnvironment.dist == Dist.CLIENT; + } + + public static boolean isServer() { + return FMLEnvironment.dist == Dist.DEDICATED_SERVER; + } + + public static Path getConfigFolder() { + return FMLPaths.CONFIGDIR.get(); + } + + public static boolean isModLoaded(String id) { + return ModList.get().isLoaded(id); + } +} diff --git a/forge/src/main/java/net/pitan76/mcpitanlib/forge/MCPitanLibForge.java b/forge/src/main/java/net/pitan76/mcpitanlib/forge/MCPitanLibForge.java new file mode 100644 index 000000000..3347f2852 --- /dev/null +++ b/forge/src/main/java/net/pitan76/mcpitanlib/forge/MCPitanLibForge.java @@ -0,0 +1,14 @@ +package net.pitan76.mcpitanlib.forge; + +import dev.architectury.platform.forge.EventBuses; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; +import net.pitan76.mcpitanlib.MCPitanLib; + +@Mod(MCPitanLib.MOD_ID) +public class MCPitanLibForge { + public MCPitanLibForge() { + EventBuses.registerModEventBus(MCPitanLib.MOD_ID, FMLJavaModLoadingContext.get().getModEventBus()); + MCPitanLib.init(); + } +} \ No newline at end of file diff --git a/forge/src/main/java/net/pitan76/mcpitanlib/forge/client/MCPitanLibForgeClient.java b/forge/src/main/java/net/pitan76/mcpitanlib/forge/client/MCPitanLibForgeClient.java new file mode 100644 index 000000000..90e629464 --- /dev/null +++ b/forge/src/main/java/net/pitan76/mcpitanlib/forge/client/MCPitanLibForgeClient.java @@ -0,0 +1,10 @@ +package net.pitan76.mcpitanlib.forge.client; + +import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; + +public class MCPitanLibForgeClient { + public static void clientInit(FMLClientSetupEvent event) { + //if (PlatformUtil.isDevelopmentEnvironment()) + // ExampleModClient.init(); + } +} diff --git a/forge/src/main/resources/META-INF/mods.toml b/forge/src/main/resources/META-INF/mods.toml index d222c9899..1c158fd73 100644 --- a/forge/src/main/resources/META-INF/mods.toml +++ b/forge/src/main/resources/META-INF/mods.toml @@ -11,17 +11,17 @@ loaderVersion = "[40,)" #mandatory This is typically bumped every Minecraft vers # Review your options at https://choosealicense.com/. All rights reserved is the default copyright stance, and is thus the default here. license = "MIT" # A URL to refer people to when problems occur with this mod -issueTrackerURL = "https://github.com/Pitan76/mcpitanlibarch/issue" +issueTrackerURL = "https://github.com/Pitan76/MCPitanLib/issue" # A list of mods - how many allowed here is determined by the individual mod loader [[mods]] #mandatory # The modid of the mod -modId = "mcpitanlibarch" #mandatory +modId = "mcpitanlib" #mandatory # The version number of the mod - there's a few well known ${} variables useable here or just hardcode it # ${version} will substitute the value of the Implementation-Version as read from the mod's JAR file metadata # see the associated build.gradle script for how to populate this completely automatically during a build version = "${version}" #mandatory # A display name for the mod -displayName = "MCPitanLibarch" #mandatory +displayName = "MCPitanLib" #mandatory # A URL to query for updates for this mod. See the JSON update specification #updateJSONURL="http://myurl.me/" #optional # A URL for the "homepage" for this mod, displayed in the mod UI @@ -37,7 +37,7 @@ description = ''' Pitan's Minecraft Mod Library ''' # A dependency - use the . to indicate dependency for a specific modid. Dependencies are optional. -[[dependencies.mcpitanlibarch]] #optional +[[dependencies.mcpitanlib]] #optional # the modid of the dependency modId = "forge" #mandatory # Does this dependency have to exist - if not, ordering below must be specified @@ -49,10 +49,10 @@ ordering = "NONE" # Side this dependency is applied on - BOTH, CLIENT or SERVER side = "BOTH" # Here's another dependency -[[dependencies.mcpitanlibarch]] +[[dependencies.mcpitanlib]] modId = "minecraft" mandatory = true # This version range declares a minimum of the current minecraft version up to but not including the next major version -versionRange = "[1.18,)" +versionRange = "[1.19.4,)" ordering = "NONE" side = "BOTH" diff --git a/common/src/main/resources/mcpitanlibarch-common.mixins.json b/forge/src/main/resources/mcpitanlib.mixins.json similarity index 60% rename from common/src/main/resources/mcpitanlibarch-common.mixins.json rename to forge/src/main/resources/mcpitanlib.mixins.json index 72d6fe3ab..df01c3ab5 100644 --- a/common/src/main/resources/mcpitanlibarch-common.mixins.json +++ b/forge/src/main/resources/mcpitanlib.mixins.json @@ -1,8 +1,8 @@ { "required": true, "minVersion": "0.8", - "package": "ml.pkom.mcpitanlibarch.mixin.forge", - "compatibilityLevel": "JAVA_17", + "package": "net.pitan76.mcpitanlib.forge.mixin", + "compatibilityLevel": "JAVA_8", "mixins": [ ], "client": [ diff --git a/forge/src/main/resources/pack.mcmeta b/forge/src/main/resources/pack.mcmeta index 547096ba2..03e89dcaa 100644 --- a/forge/src/main/resources/pack.mcmeta +++ b/forge/src/main/resources/pack.mcmeta @@ -1,6 +1,6 @@ { "pack": { - "description": "mcpitanlibarch resources", + "description": "mcpitanlib resources", "pack_format": 8, "forge:resource_pack_format": 8, "forge:data_pack_format": 9 diff --git a/gradle.properties b/gradle.properties index 0277f9edc..863db69d0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,17 +1,34 @@ org.gradle.jvmargs=-Xmx3G -minecraft_version=1.18.2 -archives_base_name=mcpitanlibarch -mod_version=1.0.0 -maven_group=ml.pkom +minecraft_version=1.21.1 # https://www.curseforge.com/minecraft/mc-mods/architectury-api -architectury_version=4.9.84 +architectury_version=13.0.8 # https://fabricmc.net/develop/ -fabric_loader_version=0.14.9 -yarn_mappings=1.18.2+build.4 -fabric_api_version=0.58.0+1.18.2 +fabric_loader_version=0.16.9 +yarn_mappings=1.21.1+build.3 +fabric_api_version=0.107.0+1.21.1 # https://files.minecraftforge.net/net/minecraftforge/forge/ -forge_version=1.18.2-40.1.80 +forge_version=1.21.1-52.0.27 + +# https://lambdaurora.dev/tools/import_quilt.html +quilt_loader_version=0.23.1 +quilt_fabric_api_version=6.0.2 + +# https://projects.neoforged.net/neoforged/neoforge +neoforge_version=21.1.76 + +cloth_config_version=15.0.140 + +# https://maven.pitan76.net/net/pitan76/compatdatapacks76/ +compatdatapacks76_version=1.0.13.210 + +fabricEnabled=true +forgeEnabled=false +quiltEnabled=false +neoforgeEnabled=true + +org.gradle.parallel=true +org.gradle.workers.max=4 \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 2e6e5897b..0d1842103 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/info.properties b/info.properties new file mode 100644 index 000000000..d6856a9aa --- /dev/null +++ b/info.properties @@ -0,0 +1,4 @@ +archives_base_name=mcpitanlib +mod_version=3.5.0 +maven_group=net.pitan76 +changelog=Add Compat APIs diff --git a/mappings/121-1fix.tiny b/mappings/121-1fix.tiny new file mode 100644 index 000000000..08cb84244 --- /dev/null +++ b/mappings/121-1fix.tiny @@ -0,0 +1,5 @@ +tiny 2 0 intermediary named +c net/minecraft/class_1496 + m ()Lnet/minecraft/class_1263; method_56680 getInventoryYarn +c net/minecraft/class_329 + m (Lnet/minecraft/class_332;Lnet/minecraft/class_9779;)V method_1759 renderHotbarYarn diff --git a/mappings/yarnpatch.tiny b/mappings/yarnpatch.tiny new file mode 100644 index 000000000..c47c3f32f --- /dev/null +++ b/mappings/yarnpatch.tiny @@ -0,0 +1,3 @@ +tiny 2 0 intermediary named +c net/minecraft/class_1927 net/minecraft/world/explosion/Explosion + m ()Lnet/minecraft/class_243; method_55109 getPositionYarn diff --git a/neoforge/build.gradle b/neoforge/build.gradle new file mode 100644 index 000000000..c1c5fa30e --- /dev/null +++ b/neoforge/build.gradle @@ -0,0 +1,111 @@ +plugins { + id "com.github.johnrengelman.shadow" version "8.1.1" +} +architectury { + platformSetupLoomIde() + neoForge() +} + +loom { + accessWidenerPath = project(":common").loom.accessWidenerPath + + /* + forge { + convertAccessWideners = true + extraAccessWideners.add loom.accessWidenerPath.get().asFile.name + + mixinConfig "mcpitanlib-common.mixins.json" + mixinConfig "mcpitanlib.mixins.json" + } + + */ +} + +configurations { + common + shadowCommon // Don't use shadow from the shadow plugin because we don't want IDEA to index this. + compileClasspath.extendsFrom common + runtimeClasspath.extendsFrom common + developmentNeoForge.extendsFrom common +} + +dependencies { + neoForge "net.neoforged:neoforge:${rootProject.neoforge_version}" + // Remove the next line if you don't want to depend on the API + modApi "dev.architectury:architectury-neoforge:${rootProject.architectury_version}" + + common(project(path: ":common", configuration: "namedElements")) { transitive false } + shadowCommon(project(path: ":common", configuration: "transformProductionNeoForge")) { transitive = false } + + shadowCommon 'org.yaml:snakeyaml:2.0' + + include("me.shedaniel.cloth:cloth-config-neoforge:${rootProject.cloth_config_version}") + + include("net.pitan76:compatdatapacks76-neoforge:${rootProject.compatdatapacks76_version}") +} + +processResources { + inputs.property "version", project.version + + filesMatching("META-INF/neoforge.mods.toml") { + expand "version": project.version + } + + project.version = project.version + "-neoforge" +} + +shadowJar { + relocate "org.yaml.snakeyaml", "net.pitan76.mcpitanlib.shadow.yaml.snakeyaml" + + exclude "fabric.mod.json" + exclude "architectury.common.json" + + configurations = [project.configurations.shadowCommon] + archiveClassifier.set "dev-shadow" +} + +remapJar { + inputFile.set shadowJar.archiveFile + dependsOn shadowJar + archiveClassifier.set null + + atAccessWideners.add(loom.accessWidenerPath.get().asFile.name) +} + +jar { + archiveClassifier.set "dev" +} + +sourcesJar { + def commonSources = project(":common").sourcesJar + dependsOn commonSources + from commonSources.archiveFile.map { zipTree(it) } +} + +components.java { + withVariantsFromConfiguration(project.configurations.shadowRuntimeElements) { + skip() + } +} + +publishing { + publications { + mavenNeoForge(MavenPublication) { + artifactId = info.archives_base_name + "-" + project.name + "-" + rootProject.minecraft_version + version = info.mod_version + from components.java + } + } + + // See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing. + repositories { + maven { + name = "GitHubPackages" + url = uri("https://maven.pkg.github.com/PTOM76/maven") + credentials { + username = project.findProperty("gpr.user") ?: System.getenv("GITHUB_ACTOR") + password = project.findProperty("gpr.key") ?: System.getenv("GITHUB_TOKEN") + } + } + } +} \ No newline at end of file diff --git a/neoforge/gradle.properties b/neoforge/gradle.properties new file mode 100644 index 000000000..2914393db --- /dev/null +++ b/neoforge/gradle.properties @@ -0,0 +1 @@ +loom.platform=neoforge \ No newline at end of file diff --git a/neoforge/src/main/java/net/pitan76/mcpitanlib/api/client/event/neoforge/WorldRenderRegistryImpl.java b/neoforge/src/main/java/net/pitan76/mcpitanlib/api/client/event/neoforge/WorldRenderRegistryImpl.java new file mode 100644 index 000000000..421bd6016 --- /dev/null +++ b/neoforge/src/main/java/net/pitan76/mcpitanlib/api/client/event/neoforge/WorldRenderRegistryImpl.java @@ -0,0 +1,228 @@ +package net.pitan76.mcpitanlib.api.client.event.neoforge; + +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.render.*; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.client.world.ClientWorld; +import net.minecraft.util.profiler.Profiler; +import net.neoforged.neoforge.client.event.RenderHighlightEvent; +import net.neoforged.neoforge.client.event.RenderLevelStageEvent; +import net.pitan76.mcpitanlib.api.client.event.listener.BeforeBlockOutlineEvent; +import net.pitan76.mcpitanlib.api.client.event.listener.BeforeBlockOutlineListener; +import net.pitan76.mcpitanlib.api.client.event.listener.WorldRenderContext; +import net.pitan76.mcpitanlib.api.client.event.listener.WorldRenderContextListener; +import org.joml.Matrix4f; + +import java.util.ArrayList; +import java.util.List; + +public class WorldRenderRegistryImpl { + + public static List beforeBlockOutlineListeners = new ArrayList<>(); + public static List worldRenderAfterLevelListeners = new ArrayList<>(); + + public static void renderOutlineEventBlock(RenderHighlightEvent.Block event) { + for (BeforeBlockOutlineListener listener : beforeBlockOutlineListeners) { + boolean eventContinue = listener.beforeBlockOutline(new BeforeBlockOutlineEvent(new WorldRenderContext() { + @Override + public WorldRenderer getWorldRenderer() { + return event.getLevelRenderer(); + } + + @Override + public MatrixStack getMatrixStack() { + return event.getPoseStack(); + } + + @Override + public float getTickDelta() { + return event.getDeltaTracker().getTickDelta(true); + } + + @Override + public Camera getCamera() { + return event.getCamera(); + } + + @Override + public GameRenderer getGameRenderer() { + return MinecraftClient.getInstance().gameRenderer; + } + + @Override + public LightmapTextureManager getLightmapTextureManager() { + return MinecraftClient.getInstance().gameRenderer.getLightmapTextureManager(); + } + + @Deprecated + @Override + public Matrix4f getProjectionMatrix() { + return null; + } + + @Override + public ClientWorld getWorld() { + return MinecraftClient.getInstance().world; + } + + @Deprecated + @Override + public boolean isAdvancedTranslucency() { + return event.getLevelRenderer().isTerrainRenderComplete(); + } + + @Override + public VertexConsumerProvider getConsumers() { + return event.getMultiBufferSource(); + } + + @Override + public Frustum getFrustum() { + return event.getLevelRenderer().getFrustum(); + } + }, event.getTarget())); + + if (!eventContinue) { + event.setCanceled(true); + break; + } + } + } + + public static void renderOutlineEvent(RenderHighlightEvent.Entity event) { + for (BeforeBlockOutlineListener listener : beforeBlockOutlineListeners) { + listener.beforeBlockOutline(new BeforeBlockOutlineEvent(new WorldRenderContext() { + @Override + public WorldRenderer getWorldRenderer() { + return event.getLevelRenderer(); + } + + @Override + public MatrixStack getMatrixStack() { + return event.getPoseStack(); + } + + @Override + public float getTickDelta() { + return event.getDeltaTracker().getTickDelta(true); + } + + @Override + public Camera getCamera() { + return event.getCamera(); + } + + @Override + public GameRenderer getGameRenderer() { + return MinecraftClient.getInstance().gameRenderer; + } + + @Override + public LightmapTextureManager getLightmapTextureManager() { + return MinecraftClient.getInstance().gameRenderer.getLightmapTextureManager(); + } + + @Deprecated + @Override + public Matrix4f getProjectionMatrix() { + return null; + } + + @Override + public ClientWorld getWorld() { + return MinecraftClient.getInstance().world; + } + + @Deprecated + @Override + public boolean isAdvancedTranslucency() { + return event.getLevelRenderer().isTerrainRenderComplete(); + } + + @Override + public VertexConsumerProvider getConsumers() { + return event.getMultiBufferSource(); + } + + @Override + public Frustum getFrustum() { + return event.getLevelRenderer().getFrustum(); + } + }, event.getTarget())); + } + } + + public static void renderLevelStageEvent(RenderLevelStageEvent event) { + if (!event.getStage().equals(RenderLevelStageEvent.Stage.AFTER_LEVEL)) return; + + for (WorldRenderContextListener listener : worldRenderAfterLevelListeners) { + listener.render(new WorldRenderContext() { + @Override + public WorldRenderer getWorldRenderer() { + return event.getLevelRenderer(); + } + + @Override + public MatrixStack getMatrixStack() { + return event.getPoseStack(); + } + + @Override + public float getTickDelta() { + return event.getPartialTick().getTickDelta(true); + } + + @Override + public Camera getCamera() { + return event.getCamera(); + } + + @Override + public GameRenderer getGameRenderer() { + return MinecraftClient.getInstance().gameRenderer; + } + + @Override + public LightmapTextureManager getLightmapTextureManager() { + return MinecraftClient.getInstance().gameRenderer.getLightmapTextureManager(); + } + + @Deprecated + @Override + public Matrix4f getProjectionMatrix() { + return event.getProjectionMatrix(); + } + + @Override + public ClientWorld getWorld() { + return MinecraftClient.getInstance().world; + } + + @Deprecated + @Override + public boolean isAdvancedTranslucency() { + return event.getLevelRenderer().isTerrainRenderComplete(); + } + + @Override + public VertexConsumerProvider getConsumers() { + return MinecraftClient.getInstance().getBufferBuilders().getOutlineVertexConsumers(); + } + + @Override + public Frustum getFrustum() { + return event.getLevelRenderer().getFrustum(); + } + }); + } + } + + public static void registerWorldRenderBeforeBlockOutline(BeforeBlockOutlineListener listener) { + beforeBlockOutlineListeners.add(listener); + } + + public static void registerWorldRenderAfterLevel(WorldRenderContextListener listener) { + worldRenderAfterLevelListeners.add(listener); + } +} + diff --git a/neoforge/src/main/java/net/pitan76/mcpitanlib/api/client/registry/neoforge/CompatRegistryClientImpl.java b/neoforge/src/main/java/net/pitan76/mcpitanlib/api/client/registry/neoforge/CompatRegistryClientImpl.java new file mode 100644 index 000000000..a639bf61e --- /dev/null +++ b/neoforge/src/main/java/net/pitan76/mcpitanlib/api/client/registry/neoforge/CompatRegistryClientImpl.java @@ -0,0 +1,32 @@ +package net.pitan76.mcpitanlib.api.client.registry.neoforge; + +import net.minecraft.block.Block; +import net.minecraft.client.color.block.BlockColorProvider; +import net.neoforged.neoforge.client.event.RegisterColorHandlersEvent; + +import java.util.HashMap; +import java.util.Map; + +public class CompatRegistryClientImpl { + + public static Map blockColorProviders = new HashMap<>(); + + public static void registerColorProviderBlock(BlockColorProvider provider, Block... blocks) { + blockColorProviders.put(provider, blocks); + } + + public static void registerBlockColors(RegisterColorHandlersEvent.Block event){ + if (blockColorProviders.isEmpty()) return; + + for (Map.Entry entry : blockColorProviders.entrySet()) { + BlockColorProvider provider = entry.getKey(); + Block[] blocks = entry.getValue(); + + if (blocks == null || blocks.length == 0) { + event.register(provider); + } else { + event.register(provider, blocks); + } + } + } +} diff --git a/neoforge/src/main/java/net/pitan76/mcpitanlib/api/transfer/fluid/v1/neoforge/FluidStorageUtilImpl.java b/neoforge/src/main/java/net/pitan76/mcpitanlib/api/transfer/fluid/v1/neoforge/FluidStorageUtilImpl.java new file mode 100644 index 000000000..26ee978ec --- /dev/null +++ b/neoforge/src/main/java/net/pitan76/mcpitanlib/api/transfer/fluid/v1/neoforge/FluidStorageUtilImpl.java @@ -0,0 +1,17 @@ +package net.pitan76.mcpitanlib.api.transfer.fluid.v1.neoforge; + +import net.minecraft.fluid.Fluid; +import net.neoforged.neoforge.fluids.FluidStack; +import net.neoforged.neoforge.fluids.capability.templates.FluidTank; +import net.pitan76.mcpitanlib.api.transfer.fluid.v1.IFluidStorage; +import net.pitan76.mcpitanlib.api.transfer.fluid.v1.IFluidVariant; + +public class FluidStorageUtilImpl { + public static IFluidStorage withFixedCapacity(long capacity, Runnable onChange) { + return new NeoForgeFluidStorage(new FluidTank((int) capacity), onChange); + } + + public static IFluidVariant getVariant(Fluid fluid) { + return new NeoForgeFluidVariant(new FluidStack(fluid, 1)); + } +} diff --git a/neoforge/src/main/java/net/pitan76/mcpitanlib/api/transfer/fluid/v1/neoforge/NeoForgeFluidStorage.java b/neoforge/src/main/java/net/pitan76/mcpitanlib/api/transfer/fluid/v1/neoforge/NeoForgeFluidStorage.java new file mode 100644 index 000000000..990129320 --- /dev/null +++ b/neoforge/src/main/java/net/pitan76/mcpitanlib/api/transfer/fluid/v1/neoforge/NeoForgeFluidStorage.java @@ -0,0 +1,73 @@ +package net.pitan76.mcpitanlib.api.transfer.fluid.v1.neoforge; + +import net.neoforged.neoforge.fluids.capability.IFluidHandler; +import net.neoforged.neoforge.fluids.capability.templates.FluidTank; +import net.pitan76.mcpitanlib.api.event.nbt.ReadNbtArgs; +import net.pitan76.mcpitanlib.api.event.nbt.WriteNbtArgs; +import net.pitan76.mcpitanlib.api.transfer.fluid.v1.IFluidStorage; +import net.pitan76.mcpitanlib.api.transfer.fluid.v1.IFluidVariant; + +public class NeoForgeFluidStorage implements IFluidStorage { + + public final FluidTank storage; + + public Runnable onChange; + + public NeoForgeFluidStorage(FluidTank storage, Runnable onChange) { + this.storage = storage; + this.onChange = onChange; + } + + @Override + public long getAmount() { + return storage.getFluidAmount(); + } + + @Override + public long getCapacity() { + return storage.getCapacity(); + } + + @Override + public IFluidVariant getResource() { + return new NeoForgeFluidVariant(storage.getFluid()); + } + + @Override + public void setResource(IFluidVariant variant) { + storage.setFluid(((NeoForgeFluidVariant) variant).raw); + } + + @Override + public boolean isResourceBlank() { + return storage.isEmpty(); + } + + @Override + public long insert(IFluidVariant variant, long maxAmount, boolean simulate) { + if (simulate) + return storage.fill(((NeoForgeFluidVariant) variant).raw.copyWithAmount((int) maxAmount), IFluidHandler.FluidAction.SIMULATE); + + onChange.run(); + return storage.fill(((NeoForgeFluidVariant) variant).raw.copyWithAmount((int) maxAmount), IFluidHandler.FluidAction.EXECUTE); + } + + @Override + public long extract(IFluidVariant variant, long maxAmount, boolean simulate) { + if (simulate) + return storage.drain(((NeoForgeFluidVariant) variant).raw.copyWithAmount((int) maxAmount), IFluidHandler.FluidAction.SIMULATE).getAmount(); + + onChange.run(); + return storage.drain(((NeoForgeFluidVariant) variant).raw.copyWithAmount((int) maxAmount), IFluidHandler.FluidAction.EXECUTE).getAmount(); + } + + @Override + public void writeNbt(WriteNbtArgs args) { + storage.writeToNBT(args.getWrapperLookup(), args.nbt); + } + + @Override + public void readNbt(ReadNbtArgs args) { + storage.readFromNBT(args.getWrapperLookup(), args.nbt); + } +} diff --git a/neoforge/src/main/java/net/pitan76/mcpitanlib/api/transfer/fluid/v1/neoforge/NeoForgeFluidVariant.java b/neoforge/src/main/java/net/pitan76/mcpitanlib/api/transfer/fluid/v1/neoforge/NeoForgeFluidVariant.java new file mode 100644 index 000000000..8c5e0a995 --- /dev/null +++ b/neoforge/src/main/java/net/pitan76/mcpitanlib/api/transfer/fluid/v1/neoforge/NeoForgeFluidVariant.java @@ -0,0 +1,33 @@ +package net.pitan76.mcpitanlib.api.transfer.fluid.v1.neoforge; + +import net.minecraft.fluid.Fluid; +import net.neoforged.neoforge.fluids.FluidStack; +import net.pitan76.mcpitanlib.api.transfer.fluid.v1.IFluidVariant; + +public class NeoForgeFluidVariant implements IFluidVariant { + + public final FluidStack raw; + + public NeoForgeFluidVariant() { + this.raw = FluidStack.EMPTY; + } + + public NeoForgeFluidVariant(FluidStack stack) { + this.raw = stack; + } + + @Override + public Fluid getFluid() { + return raw.getFluid(); + } + + @Override + public boolean isBlank() { + return raw.isEmpty(); + } + + @Override + public boolean isSame(Fluid fluid) { + return raw.is(fluid); + } +} diff --git a/neoforge/src/main/java/net/pitan76/mcpitanlib/api/util/neoforge/PlatformUtilImpl.java b/neoforge/src/main/java/net/pitan76/mcpitanlib/api/util/neoforge/PlatformUtilImpl.java new file mode 100644 index 000000000..d3836ed5e --- /dev/null +++ b/neoforge/src/main/java/net/pitan76/mcpitanlib/api/util/neoforge/PlatformUtilImpl.java @@ -0,0 +1,26 @@ +package net.pitan76.mcpitanlib.api.util.neoforge; + +import net.neoforged.api.distmarker.Dist; +import net.neoforged.fml.ModList; +import net.neoforged.fml.loading.FMLEnvironment; +import net.neoforged.fml.loading.FMLPaths; + +import java.nio.file.Path; + +public class PlatformUtilImpl { + public static boolean isClient() { + return FMLEnvironment.dist == Dist.CLIENT; + } + + public static boolean isServer() { + return FMLEnvironment.dist == Dist.DEDICATED_SERVER; + } + + public static Path getConfigFolder() { + return FMLPaths.CONFIGDIR.get(); + } + + public static boolean isModLoaded(String id) { + return ModList.get().isLoaded(id); + } +} diff --git a/neoforge/src/main/java/net/pitan76/mcpitanlib/neoforge/MCPitanLibNeoForge.java b/neoforge/src/main/java/net/pitan76/mcpitanlib/neoforge/MCPitanLibNeoForge.java new file mode 100644 index 000000000..d36a8bde6 --- /dev/null +++ b/neoforge/src/main/java/net/pitan76/mcpitanlib/neoforge/MCPitanLibNeoForge.java @@ -0,0 +1,28 @@ +package net.pitan76.mcpitanlib.neoforge; + +import net.neoforged.bus.api.IEventBus; +import net.neoforged.fml.ModContainer; +import net.neoforged.fml.common.Mod; +import net.neoforged.neoforge.common.NeoForge; +import net.pitan76.mcpitanlib.MCPitanLib; +import net.pitan76.mcpitanlib.api.client.event.neoforge.WorldRenderRegistryImpl; +import net.pitan76.mcpitanlib.api.client.registry.neoforge.CompatRegistryClientImpl; +import net.pitan76.mcpitanlib.api.util.PlatformUtil; + +@Mod(MCPitanLib.MOD_ID) +public class MCPitanLibNeoForge { + public MCPitanLibNeoForge(ModContainer modContainer) { + IEventBus bus = modContainer.getEventBus(); + + if (PlatformUtil.isClient()) { + IEventBus nfBus = NeoForge.EVENT_BUS; + nfBus.addListener(WorldRenderRegistryImpl::renderOutlineEventBlock); + nfBus.addListener(WorldRenderRegistryImpl::renderOutlineEvent); + nfBus.addListener(WorldRenderRegistryImpl::renderLevelStageEvent); + if (bus != null) + bus.addListener(CompatRegistryClientImpl::registerBlockColors); + } + + MCPitanLib.init(); + } +} \ No newline at end of file diff --git a/neoforge/src/main/java/net/pitan76/mcpitanlib/neoforge/client/MCPitanLibNeoForgeClient.java b/neoforge/src/main/java/net/pitan76/mcpitanlib/neoforge/client/MCPitanLibNeoForgeClient.java new file mode 100644 index 000000000..d5ae9a7c4 --- /dev/null +++ b/neoforge/src/main/java/net/pitan76/mcpitanlib/neoforge/client/MCPitanLibNeoForgeClient.java @@ -0,0 +1,10 @@ +package net.pitan76.mcpitanlib.neoforge.client; + +import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent; + +public class MCPitanLibNeoForgeClient { + public static void clientInit(FMLClientSetupEvent event) { + //if (PlatformUtil.isDevelopmentEnvironment()) + // ExampleModClient.init(); + } +} diff --git a/neoforge/src/main/resources/META-INF/neoforge.mods.toml b/neoforge/src/main/resources/META-INF/neoforge.mods.toml new file mode 100644 index 000000000..e3512a605 --- /dev/null +++ b/neoforge/src/main/resources/META-INF/neoforge.mods.toml @@ -0,0 +1,42 @@ +modLoader = "javafml" +loaderVersion = "[1,)" +license = "MIT" +issueTrackerURL = "https://github.com/Pitan76/MCPitanLib/issue" + +[[mods]] +modId = "mcpitanlib" +version = "${version}" +displayName = "MCPitanLib" +displayURL = "https://www.curseforge.com/minecraft/mc-mods/mcpitanlibarch" +logoFile = "icon.png" +authors = "Pitan" +description = ''' +Pitan's Minecraft Mod Library +''' + +[[dependencies.mcpitanlib]] +modId = "neoforge" +type = "required" +versionRange = "[20,)" +ordering = "NONE" +side = "BOTH" + +[[dependencies.mcpitanlib]] +modId = "minecraft" +type = "required" +versionRange = "[1.20,)" +ordering = "NONE" +side = "BOTH" + +[[dependencies.mcpitanlib]] +modId = "architectury" +type = "required" +versionRange = "[1.3.80,)" +ordering = "NONE" +side = "BOTH" + +[[mixins]] +config = "mcpitanlib-common.mixins.json" + +[[mixins]] +config = "mcpitanlib.mixins.json" \ No newline at end of file diff --git a/forge/src/main/resources/mcpitanlibarch.mixins.json b/neoforge/src/main/resources/mcpitanlib.mixins.json similarity index 60% rename from forge/src/main/resources/mcpitanlibarch.mixins.json rename to neoforge/src/main/resources/mcpitanlib.mixins.json index 72d6fe3ab..df01c3ab5 100644 --- a/forge/src/main/resources/mcpitanlibarch.mixins.json +++ b/neoforge/src/main/resources/mcpitanlib.mixins.json @@ -1,8 +1,8 @@ { "required": true, "minVersion": "0.8", - "package": "ml.pkom.mcpitanlibarch.mixin.forge", - "compatibilityLevel": "JAVA_17", + "package": "net.pitan76.mcpitanlib.forge.mixin", + "compatibilityLevel": "JAVA_8", "mixins": [ ], "client": [ diff --git a/neoforge/src/main/resources/pack.mcmeta b/neoforge/src/main/resources/pack.mcmeta new file mode 100644 index 000000000..03e89dcaa --- /dev/null +++ b/neoforge/src/main/resources/pack.mcmeta @@ -0,0 +1,8 @@ +{ + "pack": { + "description": "mcpitanlib resources", + "pack_format": 8, + "forge:resource_pack_format": 8, + "forge:data_pack_format": 9 + } +} diff --git a/publish.bat b/publish.bat new file mode 100644 index 000000000..e7b7155b9 --- /dev/null +++ b/publish.bat @@ -0,0 +1,127 @@ +git fetch origin + +git checkout 1.16.5 +timeout /T 1 +call gradlew.bat build +call gradlew.bat publish publishMavenCommonPublicationToGitHubPackagesRepository +call gradlew.bat publish publishMavenFabricPublicationToGitHubPackagesRepository +call gradlew.bat publish publishMavenForgePublicationToGitHubPackagesRepository +call gradlew.bat curseforge +call gradlew.bat :fabric:modrinth +call gradlew.bat :forge:modrinth + +git checkout 1.18.2 +timeout /T 1 +call gradlew.bat build +call gradlew.bat publish publishMavenCommonPublicationToGitHubPackagesRepository +call gradlew.bat publish publishMavenFabricPublicationToGitHubPackagesRepository +call gradlew.bat publish publishMavenForgePublicationToGitHubPackagesRepository +call gradlew.bat curseforge +call gradlew.bat :fabric:modrinth +call gradlew.bat :forge:modrinth + +git checkout 1.19.2 +timeout /T 1 +call gradlew.bat build +call gradlew.bat publish publishMavenCommonPublicationToGitHubPackagesRepository +call gradlew.bat publish publishMavenFabricPublicationToGitHubPackagesRepository +call gradlew.bat publish publishMavenForgePublicationToGitHubPackagesRepository +call gradlew.bat curseforge +call gradlew.bat :fabric:modrinth +call gradlew.bat :forge:modrinth + +git checkout 1.20.1 +timeout /T 1 +call gradlew.bat build +call gradlew.bat publish publishMavenCommonPublicationToGitHubPackagesRepository +call gradlew.bat publish publishMavenFabricPublicationToGitHubPackagesRepository +call gradlew.bat publish publishMavenForgePublicationToGitHubPackagesRepository +call gradlew.bat curseforge +call gradlew.bat :fabric:modrinth +call gradlew.bat :forge:modrinth + +git checkout 1.20.4 +timeout /T 1 +call gradlew.bat build +call gradlew.bat publish publishMavenCommonPublicationToGitHubPackagesRepository +call gradlew.bat publish publishMavenFabricPublicationToGitHubPackagesRepository +call gradlew.bat publish publishMavenForgePublicationToGitHubPackagesRepository +call gradlew.bat publish publishMavenNeoForgePublicationToGitHubPackagesRepository +call gradlew.bat curseforge +call gradlew.bat :fabric:modrinth +call gradlew.bat :forge:modrinth +call gradlew.bat :neoforge:modrinth + +git checkout 1.21.1 +timeout /T 1 +call gradlew.bat build +call gradlew.bat publish publishMavenCommonPublicationToGitHubPackagesRepository +call gradlew.bat publish publishMavenFabricPublicationToGitHubPackagesRepository +call gradlew.bat publish publishMavenNeoForgePublicationToGitHubPackagesRepository +call gradlew.bat curseforge +call gradlew.bat :fabric:modrinth +call gradlew.bat :neoforge:modrinth + +git checkout 1.21.3 +timeout /T 1 +call gradlew.bat build +call gradlew.bat publish publishMavenCommonPublicationToGitHubPackagesRepository +call gradlew.bat publish publishMavenFabricPublicationToGitHubPackagesRepository +call gradlew.bat publish publishMavenNeoForgePublicationToGitHubPackagesRepository +call gradlew.bat curseforge +call gradlew.bat :fabric:modrinth +call gradlew.bat :neoforge:modrinth + +git checkout 1.21.4 +timeout /T 1 +call gradlew.bat build +call gradlew.bat publish publishMavenCommonPublicationToGitHubPackagesRepository +call gradlew.bat publish publishMavenFabricPublicationToGitHubPackagesRepository +call gradlew.bat publish publishMavenNeoForgePublicationToGitHubPackagesRepository +call gradlew.bat curseforge +call gradlew.bat :fabric:modrinth +call gradlew.bat :neoforge:modrinth + +git checkout 1.21.5 +timeout /T 1 +call gradlew.bat build +call gradlew.bat publish publishMavenCommonPublicationToGitHubPackagesRepository +call gradlew.bat publish publishMavenFabricPublicationToGitHubPackagesRepository +call gradlew.bat publish publishMavenNeoForgePublicationToGitHubPackagesRepository +call gradlew.bat curseforge +call gradlew.bat :fabric:modrinth +call gradlew.bat :neoforge:modrinth + +git checkout 1.21.6 +timeout /T 1 +call gradlew.bat build +call gradlew.bat publish publishMavenCommonPublicationToGitHubPackagesRepository +call gradlew.bat publish publishMavenFabricPublicationToGitHubPackagesRepository +call gradlew.bat publish publishMavenNeoForgePublicationToGitHubPackagesRepository +call gradlew.bat curseforge +call gradlew.bat :fabric:modrinth +call gradlew.bat :neoforge:modrinth + + +git checkout 1.21.9 +timeout /T 1 +call gradlew.bat build +call gradlew.bat publish publishMavenCommonPublicationToGitHubPackagesRepository +call gradlew.bat publish publishMavenFabricPublicationToGitHubPackagesRepository +call gradlew.bat publish publishMavenNeoForgePublicationToGitHubPackagesRepository +call gradlew.bat curseforge +call gradlew.bat :fabric:modrinth +call gradlew.bat :neoforge:modrinth + + +git checkout 1.21.11 +timeout /T 1 +call gradlew.bat build +call gradlew.bat publish publishMavenCommonPublicationToGitHubPackagesRepository +call gradlew.bat publish publishMavenFabricPublicationToGitHubPackagesRepository +call gradlew.bat publish publishMavenNeoForgePublicationToGitHubPackagesRepository +call gradlew.bat curseforge +call gradlew.bat :fabric:modrinth +call gradlew.bat :neoforge:modrinth + +pause \ No newline at end of file diff --git a/pull.bat b/pull.bat new file mode 100644 index 000000000..cb05fbf86 --- /dev/null +++ b/pull.bat @@ -0,0 +1,63 @@ +git fetch origin +git checkout 1.21.11 +timeout /T 1 +git pull + +git fetch origin +git checkout 1.21.9 +timeout /T 1 +git pull + +git checkout 1.21.6 +timeout /T 1 +git pull + +git fetch origin +git checkout 1.21.5 +timeout /T 1 +git pull + +git fetch origin +git checkout 1.21.4 +timeout /T 1 +git pull + +git fetch origin +git checkout 1.21.3 +timeout /T 1 +git pull + +git fetch origin +git checkout 1.21.1 +timeout /T 1 +git pull + +git fetch origin +git checkout 1.20.4 +timeout /T 1 +git pull + +git fetch origin +git checkout 1.20.1 +timeout /T 1 +git pull + +git fetch origin +git checkout 1.19.2 +timeout /T 1 +git pull + +git fetch origin +git checkout 1.18.2 +timeout /T 1 +git pull + +git fetch origin +git checkout 1.16.5 +timeout /T 1 +git pull + +git fetch origin +git checkout 1.21.11 + +pause \ No newline at end of file diff --git a/quilt/build.gradle b/quilt/build.gradle new file mode 100644 index 000000000..316fda87e --- /dev/null +++ b/quilt/build.gradle @@ -0,0 +1,91 @@ +plugins { + id "com.github.johnrengelman.shadow" version "7.1.2" +} + +architectury { + platformSetupLoomIde() + loader("quilt") +} + +repositories { + maven { url "https://maven.quiltmc.org/repository/release/" } +} + +loom { + accessWidenerPath = project(":common").loom.accessWidenerPath +} + +configurations { + common + shadowCommon // Don't use shadow from the shadow plugin because we don't want IDEA to index this. + compileClasspath.extendsFrom common + runtimeClasspath.extendsFrom common + developmentQuilt.extendsFrom common +} + +dependencies { + modImplementation "org.quiltmc:quilt-loader:${rootProject.quilt_loader_version}" + modApi "org.quiltmc.quilted-fabric-api:quilted-fabric-api:${rootProject.quilt_fabric_api_version}-${rootProject.minecraft_version}" + // Remove the next line if you don't want to depend on the API + modApi "dev.architectury:architectury-fabric:${rootProject.architectury_version}" + + common(project(path: ":common", configuration: "namedElements")) { transitive false } + shadowCommon(project(path: ":common", configuration: "transformProductionQuilt")) { transitive false } + + shadowCommon 'org.yaml:snakeyaml:2.0' + +} + +processResources { + inputs.property "version", project.version + + filesMatching("quilt.mod.json") { + expand "version": project.version + } + + project.version = project.version + "-quilt" +} + +shadowJar { + exclude "architectury.common.json" + + configurations = [project.configurations.shadowCommon] + archiveClassifier.set "dev-shadow" +} + +remapJar { + injectAccessWidener = true + inputFile.set shadowJar.archiveFile + dependsOn shadowJar + archiveClassifier.set null +} + +jar { + archiveClassifier.set "dev" +} + +sourcesJar { + def commonSources = project(":common").sourcesJar + dependsOn commonSources + from commonSources.archiveFile.map { zipTree(it) } +} + +components.java { + withVariantsFromConfiguration(project.configurations.shadowRuntimeElements) { + skip() + } +} + +publishing { + publications { + mavenFabric(MavenPublication) { + artifactId = rootProject.archives_base_name + "-" + project.name + from components.java + } + } + + // See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing. + repositories { + // Add repositories to publish to here. + } +} \ No newline at end of file diff --git a/quilt/src/main/java/net/pitan76/mcpitanlib/quilt/MCPitanLibQuilt.java b/quilt/src/main/java/net/pitan76/mcpitanlib/quilt/MCPitanLibQuilt.java new file mode 100644 index 000000000..72eb72979 --- /dev/null +++ b/quilt/src/main/java/net/pitan76/mcpitanlib/quilt/MCPitanLibQuilt.java @@ -0,0 +1,13 @@ +package net.pitan76.mcpitanlib.quilt; + +import net.pitan76.mcpitanlib.MCPitanLib; +import org.quiltmc.loader.api.ModContainer; +import org.quiltmc.qsl.base.api.entrypoint.ModInitializer; + +public class MCPitanLibQuilt implements ModInitializer { + + @Override + public void onInitialize(ModContainer mod) { + MCPitanLib.init(); + } +} \ No newline at end of file diff --git a/quilt/src/main/java/net/pitan76/mcpitanlib/quilt/mixin/RecipeMixin.java b/quilt/src/main/java/net/pitan76/mcpitanlib/quilt/mixin/RecipeMixin.java new file mode 100644 index 000000000..8c3380f7d --- /dev/null +++ b/quilt/src/main/java/net/pitan76/mcpitanlib/quilt/mixin/RecipeMixin.java @@ -0,0 +1,28 @@ +package net.pitan76.mcpitanlib.fabric.mixin; + +import net.pitan76.mcpitanlib.api.item.FixedRecipeRemainderItem; +import net.minecraft.inventory.Inventory; +import net.minecraft.item.ItemStack; +import net.minecraft.recipe.Recipe; +import net.minecraft.util.collection.DefaultedList; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(Recipe.class) +public interface RecipeMixin { + @Inject(method = "getRemainder", at = @At("RETURN")) + default void injectGetRemainder(C inventory, CallbackInfoReturnable> cir) { + DefaultedList defaultedList = cir.getReturnValue(); + + int i = 0; + for(ItemStack stack : defaultedList) { + if (stack.getItem() instanceof FixedRecipeRemainderItem) { + FixedRecipeRemainderItem remainder = (FixedRecipeRemainderItem) stack.getItem(); + defaultedList.set(i, remainder.getFixedRecipeRemainder(stack.copy())); + } + i++; + } + } +} diff --git a/quilt/src/main/resources/mcpitanlib.mixins.json b/quilt/src/main/resources/mcpitanlib.mixins.json new file mode 100644 index 000000000..0a36c5829 --- /dev/null +++ b/quilt/src/main/resources/mcpitanlib.mixins.json @@ -0,0 +1,14 @@ +{ + "required": true, + "minVersion": "0.8", + "package": "net.pitan76.mcpitanlib.fabric.mixin", + "compatibilityLevel": "JAVA_8", + "mixins": [ + "RecipeMixin" + ], + "client": [ + ], + "injectors": { + "defaultRequire": 1 + } +} diff --git a/quilt/src/main/resources/quilt.mod.json b/quilt/src/main/resources/quilt.mod.json new file mode 100644 index 000000000..1ad121415 --- /dev/null +++ b/quilt/src/main/resources/quilt.mod.json @@ -0,0 +1,55 @@ +{ + "schemaVersion": 1, + "quilt_loader" : { + "group": "net.pitan76", + "id": "mcpitanlib", + "version": "${version}", + "metadata" : { + "name": "MCPitanLib", + "description": "Pitan's Minecraft Mod Library", + "authors": [ + "Pitan" + ], + "contact": { + "homepage": "https://www.curseforge.com/minecraft/mc-mods/mcpitanlibarch", + "sources": "https://github.com/Pitan76/MCPitanLib", + "issues": "https://github.com/Pitan76/MCPitanLib/issue" + }, + "license": "MIT", + "icon": "icon.png" + }, + "intermediate_mappings": "net.fabricmc:intermediary", + "environment": "*", + "entrypoints": { + "init": [ + "net.pitan76.mcpitanlib.quilt.MCPitanLibQuilt" + ] + }, + "custom": { + "modmenu": { + "badges": [ + "library" + ] + } + }, + "depends": [ + { + "id": "minecraft", + "version": ">1.19.2" + }, + { + "id": "quilt_loader", + "version": "*" + }, + { + "id": "architectury", + "version": "*" + } + ] + }, + "accessWidener": "mcpitanlib.accesswidener", + "mixins": [ + "mcpitanlib.mixins.json", + "mcpitanlib-common.mixins.json" + ] +} diff --git a/settings.gradle b/settings.gradle index 06a89e44e..588050bed 100644 --- a/settings.gradle +++ b/settings.gradle @@ -8,5 +8,11 @@ pluginManagement { } include("common") -include("fabric") -include("forge") \ No newline at end of file +if (fabricEnabled.toBoolean()) + include("fabric") +if (forgeEnabled.toBoolean()) + include("forge") +if (quiltEnabled.toBoolean()) + include("quilt") +if (neoforgeEnabled.toBoolean()) + include("neoforge")