diff --git a/.github/workflows/auto-cherry-pick.yml b/.github/workflows/auto-cherry-pick.yml new file mode 100644 index 000000000..4f7fc1869 --- /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 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..c44ae5407 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2022 Pitan +Copyright (c) 2022-2026 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..584ca6d0c 100644 --- a/build.gradle +++ b/build.gradle @@ -1,51 +1,130 @@ plugins { - id "architectury-plugin" version "3.4-SNAPSHOT" - id "dev.architectury.loom" version "0.11.0-SNAPSHOT" apply false + id "architectury-plugin" version "3.5-SNAPSHOT" + id "dev.architectury.loom-no-remap" version "1.14-SNAPSHOT" apply false + id 'com.matthewprenger.cursegradle' version '1.5.0-SNAPSHOT' // FORK: maven.pitan76.net + id "com.modrinth.minotaur" version "2.+" + id "com.gradleup.shadow" version "9.4.0" } 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") + +allprojects { + version = info.mod_version + "-" + rootProject.minecraft_version + group = info.maven_group +} + subprojects { - apply plugin: "dev.architectury.loom" + apply plugin: "architectury-plugin" + apply plugin: "dev.architectury.loom-no-remap" + apply plugin: "maven-publish" + apply plugin: "com.modrinth.minotaur" + apply plugin: "com.matthewprenger.cursegradle" + apply plugin: "com.gradleup.shadow" - loom { - silentMojangMappingsLicense() + base { + // Set up a suffixed format for the mod jar names, e.g. `example-fabric`. + archivesName = info.archives_base_name + } + + 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" + + // https://mvnrepository.com/artifact/org.yaml/snakeyaml + implementation 'org.yaml:snakeyaml:2.0' } -} -allprojects { - apply plugin: "java" - apply plugin: "architectury-plugin" - apply plugin: "maven-publish" + if (name in "fabric,neoforge".split(",")) { + var modLoader = name - archivesBaseName = rootProject.archives_base_name - version = rootProject.mod_version - group = rootProject.maven_group + if (System.getenv("CURSEFORGE_TOKEN") != null) { + curseforge { + apiKey = System.getenv("CURSEFORGE_TOKEN") + project { + id = '682213' + changelog = info.changelog + releaseType = 'beta' + if (modLoader == "fabric") { + addGameVersion "Fabric" + } + if (modLoader == "forge") { + addGameVersion "Forge" + } + if (modLoader == "neoforge") { + addGameVersion "NeoForge" + } + addGameVersion "26.1" + addGameVersion "26.1.1" + addGameVersion "26.1.2" - repositories { - // Add repositories to retrieve artifacts from in here. - // You should only use this when depending on other mods because - // Loom adds the essential maven repositories to download Minecraft and libraries from automatically. - // See https://docs.gradle.org/current/userguide/declaring_repositories.html - // for more information about repositories. + relations { + if (modLoader == "fabric") { + requiredDependency "fabric-api" + } + + embeddedLibrary 'cloth-config' + embeddedLibrary 'compatdatapacks' + embeddedLibrary 'legacyitemmodels' + } + + mainArtifact(shadowJar) + } + options { + forgeGradleIntegration = false + } + } + + } + + afterEvaluate { + if (System.getenv("MODRINTH_TOKEN") != null) { + modrinth { + token = System.getenv("MODRINTH_TOKEN") + projectId = 'mcpitanlibarch' + versionNumber = info.mod_version + "-" + modLoader + "-" + project.minecraft_version + gameVersions = ["26.1", "26.1.1", "26.1.2"] + versionType = 'beta' + uploadFile = tasks.named("shadowJar").get().archiveFile.get().asFile + changelog = info.changelog + loaders = [modLoader] + dependencies { + if (modLoader == "fabric") { + required.project "fabric-api" // Fabric API + } + embedded.project "cloth-config" + embedded.project "compatdatapacks" + embedded.project "legacyitemmodels" + } + } + } + } } - tasks.withType(JavaCompile) { + tasks.withType(JavaCompile).configureEach { options.encoding = "UTF-8" - options.release = 17 + options.release = 25 + sourceCompatibility = JavaVersion.VERSION_25 + targetCompatibility = JavaVersion.VERSION_25 } java { withSourcesJar() } -} +} \ No newline at end of file diff --git a/common/build.gradle b/common/build.gradle index 22df1ed86..e5a5c5525 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -1,25 +1,41 @@ dependencies { - // We depend on fabric loader here to use the fabric @Environment annotations and get the mixin dependencies - // Do NOT use other classes from fabric loader - modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}" - // Remove the next line if you don't want to depend on the API - modApi "dev.architectury:architectury:${rootProject.architectury_version}" + implementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}" } architectury { - common() + common("fabric", "neoforge") +} + +loom { + accessWidenerPath = file("src/main/resources/mcpitanlib.accesswidener") +} + +tasks.shadowJar { + enabled = false +} + +tasks.jar { + setArchiveClassifier(null) } 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/ExtendEntity.java b/common/src/main/java/ml/pkom/mcpitanlibarch/api/entity/ExtendEntity.java deleted file mode 100644 index e4e7126c2..000000000 --- a/common/src/main/java/ml/pkom/mcpitanlibarch/api/entity/ExtendEntity.java +++ /dev/null @@ -1,61 +0,0 @@ -package ml.pkom.mcpitanlibarch.api.entity; - -import ml.pkom.mcpitanlibarch.api.nbt.NbtTag; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityType; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.network.Packet; -import net.minecraft.world.World; - -public class ExtendEntity extends Entity { - public ExtendEntity(EntityType type, World world) { - super(type, world); - } - - public void initDataTracker() { - } - - public void readCustomDataFromNbt(NbtCompound nbt) { - - } - - public void writeCustomDataToNbt(NbtCompound nbt) { - - } - - public Packet createSpawnPacket() { - return null; - } - - // 互換性用 (NbtTag型をOverrideすること) - public void writeNbt(NbtTag nbt) { - super.writeNbt(nbt); - } - - public void readNbt(NbtTag nbt) { - super.readNbt(nbt); - } - - // 1.18 - @Override - public NbtCompound writeNbt(NbtCompound nbt) { - this.writeNbt(NbtTag.from(nbt)); - return nbt; - } - - @Override - public void readNbt(NbtCompound nbt) { - this.readNbt(NbtTag.from(nbt)); - } - - // 1.14 - public NbtCompound toTag(NbtCompound nbt) { - this.writeNbt(NbtTag.from(nbt)); - return nbt; - } - - public NbtCompound fromTag(NbtCompound nbt) { - this.readNbt(NbtTag.from(nbt)); - return nbt; - } -} \ 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/event/TileCreateEvent.java b/common/src/main/java/ml/pkom/mcpitanlibarch/api/event/TileCreateEvent.java deleted file mode 100644 index 56bc84c61..000000000 --- a/common/src/main/java/ml/pkom/mcpitanlibarch/api/event/TileCreateEvent.java +++ /dev/null @@ -1,65 +0,0 @@ -package ml.pkom.mcpitanlibarch.api.event; - -import net.minecraft.block.BlockState; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.BlockView; - -public class TileCreateEvent extends BaseEvent { - - // ~1.16.5 - private BlockView blockView; - - public TileCreateEvent(BlockView blockView) { - this.blockView = blockView; - this.blockPos = null; - this.blockState = null; - } - - public BlockView getBlockView() { - return blockView; - } - - public void setBlockView(BlockView blockView) { - this.blockView = blockView; - } - - public boolean hasBlockView() { - return (blockView != null); - } - // ---- - - // 1.17~ - private BlockPos blockPos; - private BlockState blockState; - - public TileCreateEvent(BlockPos blockPos, BlockState blockState) { - this.blockView = null; - this.blockPos = blockPos; - this.blockState = blockState; - } - - public BlockPos getBlockPos() { - return blockPos; - } - - public void setBlockPos(BlockPos blockPos) { - this.blockPos = blockPos; - } - - public boolean hasBlockPos() { - return (blockPos != null); - } - - public BlockState getBlockState() { - return blockState; - } - - public void setBlockState(BlockState blockState) { - this.blockState = blockState; - } - - public boolean hasBlockState() { - return (blockState != null); - } - // ---- -} \ No newline at end of file diff --git a/common/src/main/java/ml/pkom/mcpitanlibarch/api/nbt/NbtTag.java b/common/src/main/java/ml/pkom/mcpitanlibarch/api/nbt/NbtTag.java deleted file mode 100644 index d27ae8aad..000000000 --- a/common/src/main/java/ml/pkom/mcpitanlibarch/api/nbt/NbtTag.java +++ /dev/null @@ -1,66 +0,0 @@ -package ml.pkom.mcpitanlibarch.api.nbt; - -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.nbt.NbtType; - -public class NbtTag extends NbtCompound { - public NbtTag() { - super(); - } - - /** - * Create NbtTag instance - * @return NbtTag instance - */ - public static NbtTag create() { - return new NbtTag(); - } - - /** - * Cast to NbtTag - * @param nbt Nbt Object - * @return NbtTag - */ - public static NbtTag from(Object nbt) { - if (nbt instanceof NbtCompound) { - return (NbtTag) nbt; - } - return (NbtTag) nbt; - } - - /** - * Check item stack nbt - * @param stack Item stack - * @return boolean - */ - public static boolean hasNbt(ItemStack stack) { - return stack.hasNbt(); - } - - /** - * Get nbt from item stack - * @param stack Item stack - * @return NbtTag - */ - public static NbtTag getNbt(ItemStack stack) { - return from(stack.getNbt()); - } - - /** - * Set nbt to item stack - * @param stack Item stack - * @param nbt NbtTag - */ - public static void setNbt(ItemStack stack, NbtTag nbt) { - stack.setNbt(nbt); - } - - public boolean contains(String key) { - return super.contains(key); - } - - public NbtType getNbtType() { - return super.getNbtType(); - } -} \ 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/text/TextComponent.java b/common/src/main/java/ml/pkom/mcpitanlibarch/api/text/TextComponent.java deleted file mode 100644 index f7c701f5a..000000000 --- a/common/src/main/java/ml/pkom/mcpitanlibarch/api/text/TextComponent.java +++ /dev/null @@ -1,81 +0,0 @@ -package ml.pkom.mcpitanlibarch.api.text; - -import ml.pkom.mcpitanlibarch.api.util.TextUtil; -import net.minecraft.text.MutableText; -import net.minecraft.text.Text; - -import javax.annotation.Nullable; - -public class TextComponent { - - private Text text; - - public TextComponent() { - this(TextUtil.empty()); - } - - public TextComponent(Text text) { - this.text = text; - } - - public TextComponent(String string) { - this(TextUtil.literal(string)); - } - - public Text getText() { - return text; - } - - public void setText(Text text) { - this.text = text; - } - - public MutableText asMutableText() { - return (MutableText) text; - } - - public VariableTextComponent asVariableTextComponent() { - return new VariableTextComponent(this); - } - - @Nullable - public MutableText asMutableTextOrNull() { - if (text instanceof MutableText) { - return asMutableText(); - } - return null; - } - - public static TextComponent literal(String string) { - return new TextComponent(string); - } - - public static TextComponent of(String string) { - return TextComponent.literal(string); - } - - public static TextComponent translatable(String key) { - return new TextComponent(TextUtil.translatable(key)); - } - - public static TextComponent translatable(String key, Object... args) { - return new TextComponent(TextUtil.translatable(key, args)); - } - - @Override - public String toString() { - return getString(); - } - - public String getString() { - return TextUtil.txt2str(getText()); - } - - public String superToString() { - return super.toString(); - } - - public TextComponent copy() { - return new TextComponent(getText()); - } -} \ No newline at end of file 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..3b56f40ad --- /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.resources.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..95ab7a0a5 --- /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.resources.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/BlockItemByExtendBlock1215.java b/common/src/main/java/net/pitan76/mcpitanlib/api/block/BlockItemByExtendBlock1215.java new file mode 100644 index 000000000..c7f9eb875 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/block/BlockItemByExtendBlock1215.java @@ -0,0 +1,38 @@ +package net.pitan76.mcpitanlib.api.block; + +import net.minecraft.world.item.Item.Properties; +import net.minecraft.world.item.Item.TooltipContext; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.item.component.TooltipDisplay; +import net.minecraft.world.item.BlockItem; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.TooltipFlag; +import net.minecraft.network.chat.Component; +import net.pitan76.mcpitanlib.api.event.item.ItemAppendTooltipEvent; + +import java.util.function.Consumer; + +@Deprecated +public class BlockItemByExtendBlock1215 extends BlockItem { + private ExtendBlock block; + private ExtendBlockProvider provider; + + public BlockItemByExtendBlock1215(ExtendBlock block, Properties settings) { + super(block, settings); + this.block = block; + } + + public BlockItemByExtendBlock1215(ExtendBlockProvider provider, Properties settings) { + super((Block) provider, settings); + this.provider = provider; + } + + @Override + public void appendHoverText(ItemStack stack, TooltipContext context, TooltipDisplay displayComponent, Consumer textConsumer, TooltipFlag type) { + if (block != null) + block.appendTooltip(new ItemAppendTooltipEvent(stack, context, displayComponent, textConsumer, type)); + + if (provider != null) + provider.appendTooltip(new ItemAppendTooltipEvent(stack, context, displayComponent, textConsumer, type), new ExtendBlockProvider.Options()); + } +} 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..a81c34c8a --- /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.world.level.block.RenderShape; + +public class CompatBlockRenderType { + + public static final CompatBlockRenderType MODEL = of(RenderShape.MODEL); + public static final CompatBlockRenderType ENTITYBLOCK_ANIMATED = of(RenderShape.MODEL); + public static final CompatBlockRenderType INVISIBLE = of(RenderShape.INVISIBLE); + + @Deprecated + public final RenderShape renderType; + + public CompatBlockRenderType(RenderShape renderType) { + this.renderType = renderType; + } + + public static CompatBlockRenderType of(RenderShape renderType) { + return new CompatBlockRenderType(renderType); + } + + public RenderShape 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..43e05da4b --- /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.world.level.block.Block; +import net.minecraft.world.level.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..cb72d173f --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/block/CompatChestBlock.java @@ -0,0 +1,48 @@ +package net.pitan76.mcpitanlib.api.block; + +import net.minecraft.world.level.block.state.BlockBehaviour.Properties; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.ChestBlock; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.level.block.entity.ChestBlockEntity; +import net.minecraft.core.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 net.pitan76.mcpitanlib.api.sound.CompatSoundEvents; + +import java.util.function.Supplier; + +public class CompatChestBlock extends ChestBlock implements CompatBlockProvider { + public CompatChestBlock(Properties settings, Supplier> supplier) { + super(supplier, CompatSoundEvents.BLOCK_CHEST_OPEN.get(), CompatSoundEvents.BLOCK_CHEST_CLOSE.get(), settings); + } + + public CompatibleBlockSettings compatSettings; + + public CompatChestBlock(CompatibleBlockSettings settings, Supplier> supplier) { + this(settings.build(), supplier); + } + + /** + * @deprecated Use {@link #createBlockEntity(TileCreateEvent)} instead. + */ + @Deprecated + @Override + public BlockEntity newBlockEntity(BlockPos pos, BlockState state) { + return createBlockEntity(new TileCreateEvent(pos, state)); + } + + /** + * @see ExtendBlockEntityProvider#createBlockEntity(TileCreateEvent) + */ + public BlockEntity createBlockEntity(TileCreateEvent event) { + return super.newBlockEntity(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..d266e1e80 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/block/CompatPillarBlock.java @@ -0,0 +1,81 @@ +package net.pitan76.mcpitanlib.api.block; + +import com.mojang.serialization.MapCodec; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockBehaviour.Properties; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.RotatedPillarBlock; +import net.minecraft.world.item.context.BlockPlaceContext; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.core.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 RotatedPillarBlock implements CompatBlockProvider { + + public static final EnumProperty AXIS = CompatProperties.of(RotatedPillarBlock.AXIS); + + public CompatibleBlockSettings settings; + + @Override + public CompatibleBlockSettings getCompatSettings() { + return settings; + } + + public CompatPillarBlock(Properties settings) { + super(settings); + } + + public CompatPillarBlock(CompatibleBlockSettings settings) { + this(settings.build()); + this.settings = settings; + } + + public void appendProperties(AppendPropertiesArgs args) { + super.createBlockStateDefinition(args.builder); + } + + public BlockState getPlacementState(PlacementStateArgs args) { + return super.getStateForPlacement(args.ctx); + } + + @Deprecated + @Override + public void createBlockStateDefinition(StateDefinition.Builder builder) { + appendProperties(new AppendPropertiesArgs(builder)); + } + + @Deprecated + @Override + public BlockState getStateForPlacement(BlockPlaceContext 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 codec() { + return getCompatCodec().getCodec(); + } + + public CompatMapCodec getCompatCodec() { + return CompatMapCodec.of(super.codec()); + } +} 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..943cfd824 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/block/CompatSlabBlock.java @@ -0,0 +1,101 @@ +package net.pitan76.mcpitanlib.api.block; + +import com.mojang.serialization.MapCodec; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockBehaviour.Properties; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.SlabBlock; +import net.minecraft.world.level.block.state.properties.SlabType; +import net.minecraft.world.level.pathfinder.PathComputationType; +import net.minecraft.world.item.context.BlockPlaceContext; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.BlockGetter; +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(Properties settings) { + super(settings); + } + + public CompatSlabBlock(CompatibleBlockSettings settings) { + this(settings.build()); + } + + public void appendProperties(AppendPropertiesArgs args) { + super.createBlockStateDefinition(args.builder); + } + + public BlockState getPlacementState(PlacementStateArgs args) { + return super.getStateForPlacement(args.ctx); + } + + @Deprecated + @Override + public void createBlockStateDefinition(StateDefinition.Builder builder) { + appendProperties(new AppendPropertiesArgs(builder)); + } + + @Deprecated + @Override + public BlockState getStateForPlacement(BlockPlaceContext 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 codec() { + return getCompatCodec().getCodec(); + } + + public CompatMapCodec getCompatCodec() { + return CompatMapCodec.of(super.codec()); + } + + @Deprecated + @Override + public boolean isPathfindable(BlockState state, PathComputationType type) { + return canPathfindThrough(new CanPathfindThroughArgs(state, type)); + } + + public boolean canPathfindThrough(CanPathfindThroughArgs args) { + return super.isPathfindable(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..c31f34d8b --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/block/CompatStairsBlock.java @@ -0,0 +1,132 @@ +package net.pitan76.mcpitanlib.api.block; + +import com.mojang.serialization.MapCodec; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.StairBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.properties.Half; +import net.minecraft.world.level.block.state.properties.StairsShape; +import net.minecraft.world.level.pathfinder.PathComputationType; +import net.minecraft.world.item.context.BlockPlaceContext; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.BooleanProperty; +import net.minecraft.world.level.block.state.properties.EnumProperty; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.pitan76.mcpitanlib.api.block.v2.CompatBlockProvider; +import net.pitan76.mcpitanlib.api.block.v2.CompatibleBlockSettings; +import net.minecraft.core.BlockPos; +import net.minecraft.world.phys.shapes.VoxelShape; +import net.minecraft.world.level.BlockGetter; +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 StairBlock implements CompatBlockProvider { + + public static final DirectionProperty FACING = CompatProperties.HORIZONTAL_FACING; + public static final EnumProperty HALF = StairBlock.HALF; + public static final EnumProperty SHAPE = StairBlock.SHAPE; + public static final BooleanProperty WATERLOGGED = StairBlock.WATERLOGGED; + + public CompatibleBlockSettings compatSettings; + + /** + * get compatible block settings + * @return CompatibleBlockSettings + */ + @Override + public CompatibleBlockSettings getCompatSettings() { + return compatSettings; + } + + public CompatStairsBlock(BlockState baseBlockState, Properties settings) { + super(baseBlockState, settings); + } + + public CompatStairsBlock(BlockState baseBlockState, CompatibleBlockSettings settings) { + this(baseBlockState, settings.build()); + this.compatSettings = settings; + } + + public VoxelShape getOutlineShape(OutlineShapeEvent event) { + return super.getShape(event.state, event.world, event.pos, event.context); + } + + public void appendProperties(AppendPropertiesArgs args) { + super.createBlockStateDefinition(args.builder); + } + + public BlockState getPlacementState(PlacementStateArgs args) { + return super.getStateForPlacement(args.ctx); + } + + @Deprecated + @Override + public void createBlockStateDefinition(StateDefinition.Builder builder) { + appendProperties(new AppendPropertiesArgs(builder)); + } + + @Deprecated + @Override + public BlockState getStateForPlacement(BlockPlaceContext ctx) { + return getPlacementState(new PlacementStateArgs(ctx)); + } + + @Deprecated + @Override + protected VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext 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 codec() { + return getCompatCodec().getCodec(); + } + + public CompatMapCodec getCompatCodec() { + return CompatMapCodec.of(super.codec()); + } + + @Deprecated + @Override + public boolean isPathfindable(BlockState state, PathComputationType type) { + return canPathfindThrough(new CanPathfindThroughArgs(state, type)); + } + + public boolean canPathfindThrough(CanPathfindThroughArgs args) { + return super.isPathfindable(args.state, args.type); + } + + @Override + public Boolean canPathfindThrough(CanPathfindThroughArgs args, Options options) { + return CompatBlockProvider.super.canPathfindThrough(args, options); + } + + public BlockState getBaseBlockState() { + return super.baseState; + } +} 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..aae0037b2 --- /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.world.level.block.SimpleWaterloggedBlock; +import net.minecraft.sounds.SoundEvent; +import net.pitan76.mcpitanlib.api.sound.CompatSoundEvent; + +import java.util.Optional; + +public interface CompatWaterloggable extends SimpleWaterloggedBlock { + + @Override + default Optional getPickupSound() { + return getCompactBucketFillSound() + .map(CompatSoundEvent::get); + } + + default Optional getCompactBucketFillSound() { + return SimpleWaterloggedBlock.super.getPickupSound() + .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..d00af1584 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/block/CompatibleBlockSettings.java @@ -0,0 +1,253 @@ +package net.pitan76.mcpitanlib.api.block; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.MapCodec; +import net.minecraft.world.level.block.state.BlockBehaviour; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.material.MapColor; +import net.minecraft.world.level.block.SoundType; +import net.minecraft.world.item.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 = MapCodec.unitCodec(CompatibleBlockSettings::of); + + protected final BlockBehaviour.Properties settings; + + public CompatibleBlockSettings() { + this.settings = BlockBehaviour.Properties.of(); + } + + @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.forceSolidOn(); + if (material.isReplaceable()) + settings.settings.replaceable(); + if (material.isSolid()) + settings.settings.forceSolidOn(); + if (material.isBurnable()) + settings.settings.ignitedByLava(); + settings.settings.pushReaction(material.getPistonBehavior()); + return settings; + } + + public CompatibleBlockSettings(CompatibleMaterial material, MapColor mapColor) { + this.settings = BlockBehaviour.Properties.of(); + copyCompatibleMaterial(material, this); + mapColor(mapColor); + } + + public CompatibleBlockSettings(CompatibleMaterial material, DyeColor dyeColor) { + this.settings = BlockBehaviour.Properties.of(); + copyCompatibleMaterial(material, this); + mapColor(dyeColor); + } + + public CompatibleBlockSettings(CompatibleMaterial material) { + this.settings = BlockBehaviour.Properties.of(); + copyCompatibleMaterial(material, this); + } + + public CompatibleBlockSettings(CompatibleMaterial material, Function mapColor) { + this.settings = BlockBehaviour.Properties.of(); + 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(BlockBehaviour block) { + this.settings = BlockBehaviour.Properties.ofFullCopy(block); + } + + @Deprecated + public static CompatibleBlockSettings copy(BlockBehaviour block) { + return new CompatibleBlockSettings(block); + } + + public CompatibleBlockSettings air() { + settings.air(); + return this; + } + + public CompatibleBlockSettings blockVision(BlockBehaviour.StatePredicate predicate) { + settings.isViewBlocking(predicate); + return this; + } + + public CompatibleBlockSettings postProcess(BlockBehaviour.PostProcess predicate) { + settings.postProcess(predicate); + return this; + } + + public CompatibleBlockSettings solidBlock(BlockBehaviour.StatePredicate predicate) { + settings.isRedstoneConductor(predicate); + return this; + } + + public CompatibleBlockSettings suffocates(BlockBehaviour.StatePredicate predicate) { + settings.isSuffocating(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.instabreak(); + return this; + } + + public CompatibleBlockSettings dropsNothing() { + settings.noLootTable(); + return this; + } + + public CompatibleBlockSettings dynamicBounds() { + settings.dynamicShape(); + return this; + } + + public CompatibleBlockSettings hardness(float hardness) { + settings.destroyTime(hardness); + return this; + } + + public CompatibleBlockSettings noBlockBreakParticles() { + settings.noTerrainParticles(); + return this; + } + + public CompatibleBlockSettings requiresTool() { + settings.requiresCorrectToolForDrops(); + return this; + } + + public CompatibleBlockSettings noCollision() { + settings.noCollision(); + return this; + } + + public CompatibleBlockSettings nonOpaque() { + settings.noOcclusion(); + return this; + } + + public CompatibleBlockSettings resistance(float resistance) { + settings.explosionResistance(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.randomTicks(); + return this; + } + + public CompatibleBlockSettings sounds(SoundType blockSoundGroup) { + settings.sound(blockSoundGroup); + return this; + } + + public CompatibleBlockSettings sounds(CompatBlockSoundGroup blockSoundGroup) { + return sounds(blockSoundGroup.get()); + } + + public CompatibleBlockSettings luminance(ToIntFunction luminance) { + settings.lightLevel(luminance); + return this; + } + + public CompatibleBlockSettings jumpVelocityMultiplier(float jumpVelocityMultiplier) { + settings.jumpFactor(jumpVelocityMultiplier); + return this; + } + + public CompatibleBlockSettings slipperiness(float slipperiness) { + settings.friction(slipperiness); + return this; + } + + public CompatibleBlockSettings velocityMultiplier(float velocityMultiplier) { + settings.speedFactor(velocityMultiplier); + return this; + } + + public CompatibleBlockSettings emissiveLighting(BlockBehaviour.StatePredicate predicate) { + settings.emissiveRendering(predicate); + return this; + } + + public CompatibleBlockSettings offset(BlockBehaviour.OffsetType offsetType) { + settings.offsetType(offsetType); + return this; + } + + public CompatibleBlockSettings allowsSpawning(BlockBehaviour.StateArgumentPredicate> predicate) { + settings.isValidSpawn(predicate); + return this; + } + + public BlockBehaviour.Properties 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..c59a8288d --- /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.world.level.material.MapColor; +import net.minecraft.world.level.material.PushReaction; + +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 PushReaction 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, PushReaction 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 PushReaction getPistonBehavior() { + return this.pistonBehavior; + } + + public MapColor getColor() { + return this.color; + } + + static { + AIR = (new Builder(MapColor.NONE)).allowsMovement().lightPassesThrough().notSolid().replaceable().build(); + STRUCTURE_VOID = (new Builder(MapColor.NONE)).allowsMovement().lightPassesThrough().notSolid().replaceable().build(); + PORTAL = (new Builder(MapColor.NONE)).allowsMovement().lightPassesThrough().notSolid().blocksPistons().build(); + CARPET = (new Builder(MapColor.WOOL)).allowsMovement().lightPassesThrough().notSolid().burnable().build(); + PLANT = (new Builder(MapColor.PLANT)).allowsMovement().lightPassesThrough().notSolid().destroyedByPiston().build(); + UNDERWATER_PLANT = (new Builder(MapColor.WATER)).allowsMovement().lightPassesThrough().notSolid().destroyedByPiston().build(); + REPLACEABLE_PLANT = (new Builder(MapColor.PLANT)).allowsMovement().lightPassesThrough().notSolid().destroyedByPiston().replaceable().burnable().build(); + NETHER_SHOOTS = (new Builder(MapColor.PLANT)).allowsMovement().lightPassesThrough().notSolid().destroyedByPiston().replaceable().build(); + REPLACEABLE_UNDERWATER_PLANT = (new Builder(MapColor.WATER)).allowsMovement().lightPassesThrough().notSolid().destroyedByPiston().replaceable().build(); + WATER = (new Builder(MapColor.WATER)).allowsMovement().lightPassesThrough().notSolid().destroyedByPiston().replaceable().liquid().build(); + BUBBLE_COLUMN = (new Builder(MapColor.WATER)).allowsMovement().lightPassesThrough().notSolid().destroyedByPiston().replaceable().liquid().build(); + LAVA = (new Builder(MapColor.FIRE)).allowsMovement().lightPassesThrough().notSolid().destroyedByPiston().replaceable().liquid().build(); + SNOW_LAYER = (new Builder(MapColor.SNOW)).allowsMovement().lightPassesThrough().notSolid().destroyedByPiston().replaceable().build(); + FIRE = (new Builder(MapColor.NONE)).allowsMovement().lightPassesThrough().notSolid().destroyedByPiston().replaceable().build(); + DECORATION = (new Builder(MapColor.NONE)).allowsMovement().lightPassesThrough().notSolid().destroyedByPiston().build(); + COBWEB = (new Builder(MapColor.WOOL)).allowsMovement().lightPassesThrough().destroyedByPiston().build(); + SCULK = (new Builder(MapColor.COLOR_BLACK)).build(); + REDSTONE_LAMP = (new Builder(MapColor.NONE)).build(); + ORGANIC_PRODUCT = (new Builder(MapColor.CLAY)).build(); + SOIL = (new Builder(MapColor.DIRT)).build(); + SOLID_ORGANIC = (new Builder(MapColor.GRASS)).build(); + DENSE_ICE = (new Builder(MapColor.ICE)).build(); + AGGREGATE = (new Builder(MapColor.SAND)).build(); + SPONGE = (new Builder(MapColor.COLOR_YELLOW)).build(); + SHULKER_BOX = (new Builder(MapColor.COLOR_PURPLE)).build(); + WOOD = (new Builder(MapColor.WOOD)).burnable().build(); + NETHER_WOOD = (new Builder(MapColor.WOOD)).build(); + BAMBOO_SAPLING = (new Builder(MapColor.WOOD)).burnable().destroyedByPiston().allowsMovement().build(); + BAMBOO = (new Builder(MapColor.WOOD)).burnable().destroyedByPiston().build(); + WOOL = (new Builder(MapColor.WOOL)).burnable().build(); + TNT = (new Builder(MapColor.FIRE)).burnable().lightPassesThrough().build(); + LEAVES = (new Builder(MapColor.PLANT)).burnable().lightPassesThrough().destroyedByPiston().build(); + GLASS = (new Builder(MapColor.NONE)).lightPassesThrough().build(); + ICE = (new Builder(MapColor.ICE)).lightPassesThrough().build(); + CACTUS = (new Builder(MapColor.PLANT)).lightPassesThrough().destroyedByPiston().build(); + STONE = (new Builder(MapColor.STONE)).build(); + METAL = (new Builder(MapColor.METAL)).build(); + SNOW_BLOCK = (new Builder(MapColor.SNOW)).build(); + REPAIR_STATION = (new Builder(MapColor.METAL)).blocksPistons().build(); + BARRIER = (new Builder(MapColor.NONE)).blocksPistons().build(); + PISTON = (new Builder(MapColor.STONE)).blocksPistons().build(); + MOSS_BLOCK = (new Builder(MapColor.PLANT)).destroyedByPiston().build(); + GOURD = (new Builder(MapColor.PLANT)).destroyedByPiston().build(); + EGG = (new Builder(MapColor.PLANT)).destroyedByPiston().build(); + CAKE = (new Builder(MapColor.NONE)).destroyedByPiston().build(); + AMETHYST = (new Builder(MapColor.COLOR_PURPLE)).build(); + POWDER_SNOW = (new Builder(MapColor.SNOW)).notSolid().allowsMovement().build(); + } + + public static class Builder { + private PushReaction 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 = PushReaction.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 = PushReaction.DESTROY; + return this; + } + + protected Builder blocksPistons() { + this.pistonBehavior = PushReaction.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..651d24e4d --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/block/ExtendBlock.java @@ -0,0 +1,368 @@ +package net.pitan76.mcpitanlib.api.block; + +import com.mojang.serialization.MapCodec; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.InsideBlockEffectApplier; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.level.pathfinder.PathComputationType; +import net.minecraft.world.level.material.FluidState; +import net.minecraft.world.item.context.BlockPlaceContext; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.storage.loot.LootParams; +import net.minecraft.world.MenuProvider; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.SimpleMenuProvider; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.network.chat.Component; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.util.RandomSource; +import net.minecraft.world.phys.shapes.VoxelShape; +import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.redstone.Orientation; +import net.minecraft.world.level.ScheduledTickAccess; +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.api.util.math.random.CompatRandom; +import net.pitan76.mcpitanlib.core.serialization.CompatMapCodec; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +public class ExtendBlock extends Block implements ICompatBlock { + public CompatibleBlockSettings compatSettings; + + public ExtendBlock(Properties 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, BlockGetter world, BlockPos pos, CollisionContext 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.getShape(event.state, event.world, event.pos, event.context); + } + + @Deprecated + @Override + public VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext context) { + return getOutlineShape(new OutlineShapeEvent(state, world, pos, context)); + } + + /** + * block scheduled tick event + * @param event BlockScheduledTickEvent + */ + public void scheduledTick(BlockScheduledTickEvent event) { + super.tick(event.state, event.world, event.pos, event.random.getMcRandom()); + } + + @Override + @Deprecated + public void tick(BlockState state, ServerLevel world, BlockPos pos, RandomSource random) { + scheduledTick(new BlockScheduledTickEvent(state, world, pos, random)); + } + + @Override + @Deprecated + protected InteractionResult useWithoutItem(BlockState state, Level world, BlockPos pos, net.minecraft.world.entity.player.Player player, BlockHitResult hit) { + return onRightClick(new BlockUseEvent(state, world, pos, player, player.getUsedItemHand(), hit)).toActionResult(); + } + + /** + * block right click event + * @param event ActionResultType + * @return BlockUseEvent + */ + public CompatActionResult onRightClick(BlockUseEvent event) { + return CompatActionResult.create(super.useWithoutItem(event.state, event.world, event.pos, event.player.getPlayerEntity(), event.hit)); + } + + @Deprecated + @Nullable + @Override + public MenuProvider getMenuProvider(BlockState state, Level world, BlockPos pos) { + return new SimpleMenuProvider((syncId, inventory, player) -> + createScreenHandler(new ScreenHandlerCreateEvent(state, world, pos, syncId, inventory, player)), getScreenTitle() + ); + } + + /** + * screen handler create event + * @param event ScreenHandlerCreateEvent + * @return ScreenHandler + */ + @Nullable + public AbstractContainerMenu createScreenHandler(ScreenHandlerCreateEvent event) { + return null; + } + + /** + * get screen title + * @return Text + */ + @Nullable + public Component getScreenTitle() { + return TextUtil.literal(""); + } + + @Override + @Deprecated + public void setPlacedBy(Level 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.setPlacedBy(event.world, event.pos, event.state, event.placer, event.stack); + } + + @Override + @Deprecated + public BlockState playerWillDestroy(Level world, BlockPos pos, BlockState state, net.minecraft.world.entity.player.Player 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.playerWillDestroy(event.world, event.pos, event.state, event.getPlayerEntity()); + return new BlockBreakResult(state); + } + + @Override + @Deprecated + public ItemStack getCloneItemStack(LevelReader world, BlockPos pos, BlockState state, boolean includeData) { + PickStackEvent event = new PickStackEvent(world, pos, state); + event.setIncludeData(includeData); + return getPickStack(event); + } + + /** + * block pick stack event + * @param event PickStackEvent + * @return ItemStack + */ + public ItemStack getPickStack(PickStackEvent event) { + return super.getCloneItemStack(event.worldView, event.pos, event.state, event.includeData); + } + + @Override + @Deprecated + public void affectNeighborsAfterRemoval(BlockState state, ServerLevel world, BlockPos pos, boolean moved) { + onStateReplaced(new StateReplacedEvent(state, world, pos, world.getBlockState(pos), moved)); + } + + /** + * block state replaced event + * @param event StateReplacedEvent + */ + public void onStateReplaced(StateReplacedEvent event) { + super.affectNeighborsAfterRemoval(event.state, (ServerLevel) event.world, event.pos, event.moved); + } + + @Deprecated + @Override + public List getDrops(BlockState state, LootParams.Builder builder) { + return getDroppedStacks(new DroppedStacksArgs(state, builder)); + } + + /** + * block dropped stacks event + * @param args DroppedStacksArgs + * @return List + */ + public List getDroppedStacks(DroppedStacksArgs args) { + return super.getDrops(args.state, args.builder); + } + + @Deprecated + @Override + public void neighborChanged(BlockState state, Level world, BlockPos pos, Block sourceBlock, Orientation wireOrientation, boolean notify) { + neighborUpdate(new NeighborUpdateEvent(state, world, pos, sourceBlock, wireOrientation, notify)); + } + + /** + * block neighbor update event + * @param event NeighborUpdateEvent + */ + public void neighborUpdate(NeighborUpdateEvent event) { + super.neighborChanged(event.state, event.world, event.pos, event.sourceBlock, event.wireOrientation, event.notify); + } + + @Deprecated + @Override + public void createBlockStateDefinition(net.minecraft.world.level.block.state.StateDefinition.Builder builder) { + appendProperties(new AppendPropertiesArgs(builder)); + } + + /** + * append properties event + * @param args AppendPropertiesArgs + */ + public void appendProperties(AppendPropertiesArgs args) { + super.createBlockStateDefinition(args.builder); + } + + /** + * Compatible for getDefaultState() + * @return default block state + */ + public BlockState getNewDefaultState() { + return super.defaultBlockState(); + } + + /** + * Compatible for setDefaultState() + * @param state BlockState + */ + public void setNewDefaultState(BlockState state) { + super.registerDefaultState(state); + } + + @Deprecated + @Override + public @Nullable BlockState getStateForPlacement(BlockPlaceContext ctx) { + return this.getPlacementState(new PlacementStateArgs(ctx, this)); + } + + /** + * get placement state + * @param args PlacementStateArgs + * @return BlockState + */ + public @Nullable BlockState getPlacementState(PlacementStateArgs args) { + return super.getStateForPlacement(args.ctx); + } + + /** + * append tooltip to item + * @param event ItemAppendTooltipEvent + */ + public void appendTooltip(ItemAppendTooltipEvent event) { + + } + + @Deprecated + @Override + public boolean isPathfindable(BlockState state, PathComputationType type) { + return canPathfindThrough(new CanPathfindThroughArgs(state, type)); + } + + public boolean canPathfindThrough(CanPathfindThroughArgs args) { + return super.isPathfindable(args.state, args.type); + } + + @Deprecated + @Override + protected void entityInside(BlockState state, Level world, BlockPos pos, Entity entity, InsideBlockEffectApplier handler, boolean bl) { + onEntityCollision(new EntityCollisionEvent(state, world, pos, entity, handler, bl)); + } + + public void onEntityCollision(EntityCollisionEvent e) { + super.entityInside(e.state, e.world, e.pos, e.entity, e.handler, e.bl); + } + + @Deprecated + @Override + public void attack(BlockState state, Level world, BlockPos pos, net.minecraft.world.entity.player.Player player) { + onBlockBreakStart(new BlockBreakStartEvent(state, world, pos, new Player(player))); + } + + public void onBlockBreakStart(BlockBreakStartEvent e) { + super.attack(e.state, e.world, e.pos, e.player.getPlayerEntity()); + } + + @Deprecated + @Override + protected MapCodec codec() { + return getCompatCodec().getCodec(); + } + + public CompatMapCodec getCompatCodec() { + return CompatMapCodec.of(super.codec()); + } + + @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 updateShape(BlockState state, LevelReader world, ScheduledTickAccess tickView, BlockPos pos, Direction direction, BlockPos neighborPos, BlockState neighborState, RandomSource random) { + return getStateForNeighborUpdate(new StateForNeighborUpdateArgs(state, direction, neighborState, world, pos, neighborPos, tickView, new CompatRandom(random))); + } + + public BlockState getStateForNeighborUpdate(StateForNeighborUpdateArgs args) { + return super.updateShape(args.state, args.world, args.tickView, args.pos, args.direction, args.neighborPos, args.neighborState, args.random.getMcRandom()); + } + +// @Deprecated +// @Override +// protected ImmutableMap getShapesForStates(Function stateToShape) { +// return getShapesForStates(new ShapesForStatesArgs(stateToShape)); +// } +// +// public ImmutableMap getShapesForStates(ShapesForStatesArgs args) { +// return super.(args.stateToShape); +// } + + public StateDefinition callGetStateManager() { + return super.getStateDefinition(); + } +} 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..1e9ebd80f --- /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.world.level.block.EntityBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.BlockEntityTicker; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +import net.pitan76.mcpitanlib.api.event.block.TileCreateEvent; +import net.pitan76.mcpitanlib.api.tile.ExtendBlockEntityTicker; +import org.jetbrains.annotations.Nullable; + +public interface ExtendBlockEntityProvider extends EntityBlock { + + /** + * @deprecated Use {@link #createBlockEntity(TileCreateEvent)} instead. + */ + @Deprecated + @Nullable + default BlockEntity newBlockEntity(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().create(event.getBlockPos(), event.getBlockState()); + } + + @Nullable + default BlockEntityType getBlockEntityType() { + return null; + } + + @Nullable + @Override + default BlockEntityTicker getTicker(Level world, BlockState state, BlockEntityType type) { + if (isTick()) { + return ((world1, pos, state1, blockEntity) -> { + if (getBlockEntityType() == null || blockEntity == getBlockEntityType().getBlockEntity(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 EntityBlock.super.getTicker(world, state, type); + } + + @Nullable + default ExtendBlockEntityTicker getCompatibleTicker(Level 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..f3b62aad2 --- /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.world.level.block.state.BlockState; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.network.chat.Component; +import net.minecraft.world.phys.shapes.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 extends ICompatBlock { + + /** + * 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 AbstractContainerMenu createScreenHandler(ScreenHandlerCreateEvent event, Options options) { + options.cancel = false; + return null; + } + + /** + * get screen title + * @return Text + */ + default Component 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/ICompatBlock.java b/common/src/main/java/net/pitan76/mcpitanlib/api/block/ICompatBlock.java new file mode 100644 index 000000000..7647e49a5 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/block/ICompatBlock.java @@ -0,0 +1,10 @@ +package net.pitan76.mcpitanlib.api.block; + +import net.minecraft.world.level.block.Block; +import net.pitan76.mcpitanlib.midohra.block.BlockWrapper; + +public interface ICompatBlock { + default BlockWrapper getWrapper() { + return this instanceof Block ? BlockWrapper.of((Block) this) : BlockWrapper.of(); + } +} 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..03d51bbfd --- /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.world.level.block.state.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..73b42a692 --- /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.world.level.block.state.BlockState; +import net.minecraft.world.level.block.Rotation; +import net.minecraft.core.Direction; +import net.pitan76.mcpitanlib.midohra.holder.BlockStatePropertyHolder; + +public class RotateArgs implements BlockStatePropertyHolder { + + public BlockState state; + public Rotation rotation; + + public RotateArgs(BlockState state, Rotation rotation) { + this.state = state; + this.rotation = rotation; + } + + public BlockState getRawBlockState() { + return state; + } + + public Rotation 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..cf7f5496a --- /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.world.level.block.state.BlockState; +import net.minecraft.core.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..87d133df0 --- /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.world.level.block.state.BlockState state; + public final net.minecraft.world.level.LevelReader world; + public final net.minecraft.core.BlockPos pos; + + public CanPlaceAtArgs(net.minecraft.world.level.block.state.BlockState state, net.minecraft.world.level.LevelReader world, net.minecraft.core.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.world.level.block.state.BlockState getState() { + return state; + } + + public net.minecraft.world.level.LevelReader getWorld() { + return world; + } + + public net.minecraft.core.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.isClientSide(); + } + + public boolean isServer() { + return !world.isClientSide(); + } +} 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..1fe0b12b2 --- /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.world.phys.shapes.CollisionContext; +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, CollisionContext context) { + super(state, world, pos, context); + } + + public CollisionShapeEvent(net.minecraft.world.level.block.state.BlockState state, net.minecraft.world.level.BlockGetter world, net.minecraft.core.BlockPos pos, CollisionContext 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..4503ffd9c --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/block/args/v2/GetComparatorOutputArgs.java @@ -0,0 +1,60 @@ +package net.pitan76.mcpitanlib.api.block.args.v2; + +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.level.Level; +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 Level world; + public BlockPos pos; + public Direction direction; + + public GetComparatorOutputArgs(BlockState state, Level world, BlockPos pos) { + this(state, world, pos, Direction.NORTH); + } + + public GetComparatorOutputArgs(BlockState state, Level world, BlockPos pos, Direction direction) { + this.state = state; + this.world = world; + this.pos = pos; + this.direction = direction; + } + + public BlockState getState() { + return state; + } + + public Level 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..38d2db82e --- /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.world.level.block.state.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..5aaade166 --- /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.world.phys.shapes.CollisionContext; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.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 CollisionContext context; + + public OutlineShapeEvent(BlockState state, BlockView world, BlockPos pos, CollisionContext context) { + this.state = state; + this.world = world; + this.pos = pos; + this.context = context; + } + + public OutlineShapeEvent(net.minecraft.world.level.block.state.BlockState state, net.minecraft.world.level.BlockGetter world, net.minecraft.core.BlockPos pos, net.minecraft.world.phys.shapes.CollisionContext 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 CollisionContext getContext() { + return context; + } + + public boolean isHolding(Item item) { + return getContext().isHoldingItem(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..3f0a8ea03 --- /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.world.level.block.Block; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.item.context.BlockPlaceContext; +import net.minecraft.world.level.block.state.properties.Property; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.core.BlockPos; +import net.minecraft.world.phys.Vec3; +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.UseOnContextMixin; +import org.jetbrains.annotations.Nullable; + +public class PlacementStateArgs extends BaseEvent implements BlockStatePropertyHolder { + public BlockPlaceContext ctx; + + @Nullable + public Block block; + + public PlacementStateArgs(BlockPlaceContext ctx) { + this.ctx = ctx; + } + + public PlacementStateArgs(BlockPlaceContext ctx, @Nullable Block block) { + this.ctx = ctx; + this.block = block; + } + + public boolean canPlace() { + return ctx.canPlace(); + } + + public BlockPos getRawPos() { + return ctx.getClickedPos(); + } + + 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.core.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.core.Direction[] getRawPlacementDirections() { + return ctx.getNearestLookingDirections(); + } + + public InteractionHand getHand() { + return ctx.getHand(); + } + + public Direction getSide() { + return Direction.of(getRawSide()); + } + + public net.minecraft.core.Direction getRawSide() { + return ctx.getClickedFace(); + } + + public Direction getHorizontalPlayerFacing() { + return Direction.of(getRawHorizontalPlayerFacing()); + } + + public net.minecraft.core.Direction getRawHorizontalPlayerFacing() { + return ctx.getHorizontalDirection(); + } + + public float getPlayerYaw() { + return ctx.getRotation(); + } + + public World getWorld() { + return World.of(ctx.getLevel()); + } + + public IWorldView getWorldView() { + return getWorld(); + } + + public boolean isClient() { + return getWorld().isClient(); + } + + public Vec3 getHitPos() { + return ctx.getClickLocation(); + } + + public boolean canReplaceExisting() { + return ctx.replacingClickedOnBlock(); + } + + @Deprecated + public UseOnContextMixin getIUCAccessor() { + return (UseOnContextMixin) ctx; + } + + public BlockHitResult getHitResult() { + return getIUCAccessor().getHitResult(); + } + + public ItemUseOnBlockEvent toItemUseOnBlockEvent() { + return new ItemUseOnBlockEvent(getWorld().getRaw(), getPlayer().getPlayerEntity(), getHand(), ctx.getItemInHand(), getHitResult()); + } + + public BlockPlaceContext getCtx() { + return ctx; + } + + public @Nullable Block getRawBlock() { + return block; + } + + public boolean isBlockExist() { + return block != null; + } + + public net.minecraft.world.level.block.state.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.world.level.block.state.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..38dfc1a21 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/block/args/v2/StateForNeighborUpdateArgs.java @@ -0,0 +1,109 @@ +package net.pitan76.mcpitanlib.api.block.args.v2; + +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.level.LevelAccessor; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.ScheduledTickAccess; +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 LevelReader world; + public BlockPos pos; + public BlockPos neighborPos; + public ScheduledTickAccess tickView; + public CompatRandom random; + + public StateForNeighborUpdateArgs(BlockState state, Direction direction, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) { + this.state = state; + this.direction = direction; + this.neighborState = neighborState; + this.world = world; + this.pos = pos; + this.neighborPos = neighborPos; + } + + public StateForNeighborUpdateArgs(BlockState state, Direction direction, BlockState neighborState, LevelReader world, BlockPos pos, BlockPos neighborPos, ScheduledTickAccess tickView, CompatRandom random) { + this.state = state; + this.direction = direction; + this.neighborState = neighborState; + this.world = world; + this.pos = pos; + this.neighborPos = neighborPos; + this.tickView = tickView; + this.random = random; + } + + public Direction getDirection() { + return direction; + } + + public BlockState getRawNeighborState() { + return neighborState; + } + + public LevelReader 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(tickView); + } + + @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.isClientSide(); + } +} 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..722514432 --- /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.world.level.block.state.BlockBehaviour; +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 BlockBehaviour.Properties _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 BlockBehaviour.Properties _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..8c67c9888 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/block/v2/CompatBlock.java @@ -0,0 +1,179 @@ +package net.pitan76.mcpitanlib.api.block.v2; + +import net.minecraft.world.level.block.RenderShape; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.item.context.BlockPlaceContext; +import net.minecraft.world.level.block.Rotation; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.util.RandomSource; +import net.minecraft.world.phys.shapes.VoxelShape; +import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.ScheduledTickAccess; +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.api.util.math.random.CompatRandom; +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 RenderShape getRenderShape(BlockState state) { + return getRenderType(new RenderTypeArgs(state)).renderType; + } + + public CompatBlockRenderType getRenderType(RenderTypeArgs args) { + return new CompatBlockRenderType(super.getRenderShape(args.state)); + } + + @Override + @Deprecated + protected BlockState rotate(BlockState state, Rotation 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 skipRendering(BlockState state, BlockState stateFrom, Direction direction) { + return isSideInvisible(new SideInvisibleArgs(state, stateFrom, direction)); + } + + public boolean isSideInvisible(SideInvisibleArgs args) { + return super.skipRendering(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.getStateForPlacement(args.ctx)); + } + + @Override + public @Nullable BlockState getStateForPlacement(BlockPlaceContext 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.updateShape(args.state, args.world, args.tickView, args.pos, args.direction, args.neighborPos, args.neighborState, args.random.getMcRandom())); + } + + @Override + protected BlockState updateShape(BlockState state, LevelReader world, ScheduledTickAccess tickView, BlockPos pos, Direction direction, BlockPos neighborPos, BlockState neighborState, RandomSource random) { + return getStateForNeighborUpdate(new StateForNeighborUpdateArgs(state, direction, neighborState, world, pos, neighborPos, tickView, new CompatRandom(random))).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.getShape(e.state.toMinecraft(), e.world.getRaw(), e.pos.toMinecraft(), e.context); + } + + @Override + public VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext 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, BlockGetter world, BlockPos pos, CollisionContext 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 hasAnalogOutputSignal(BlockState state) { + return hasComparatorOutput(new HasComparatorOutputArgs(state)); + } + + public boolean hasComparatorOutput(HasComparatorOutputArgs args) { + return super.hasAnalogOutputSignal(args.state); + } + + @Deprecated + @Override + public int getAnalogOutputSignal(BlockState state, Level world, BlockPos pos, Direction direction) { + return getComparatorOutput(new GetComparatorOutputArgs(state, world, pos, direction)); + } + + public int getComparatorOutput(GetComparatorOutputArgs args) { + return super.getAnalogOutputSignal(args.state, args.world, args.pos, args.direction); + } + + @Deprecated + @Override + protected boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { + return canPlaceAt(new CanPlaceAtArgs(state, world, pos)); + } + + public boolean canPlaceAt(CanPlaceAtArgs args) { + return super.canSurvive(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..4c677aa45 --- /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.world.level.block.Block; +import net.minecraft.world.phys.shapes.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).defaultBlockState()); + } + + return null; + } + + default void setDefaultState(BlockState state) { + if (this instanceof Block) { + ((BlockInvoker) this).setDefaultState_invoke(state.toMinecraft()); + } + } + + @Override + @Deprecated + default net.minecraft.world.level.block.state.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..fb8ce089d --- /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.world.phys.shapes.CollisionContext; +import net.minecraft.world.level.block.StairBlock; +import net.minecraft.world.level.block.state.properties.Half; +import net.minecraft.world.level.block.state.properties.StairsShape; +import net.minecraft.core.BlockPos; +import net.minecraft.world.phys.shapes.VoxelShape; +import net.minecraft.world.level.BlockGetter; +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.*; +import net.pitan76.mcpitanlib.midohra.block.BlockState; + +public class CompatStairsBlock extends net.pitan76.mcpitanlib.api.block.CompatStairsBlock { + + public static final DirectionProperty FACING = CompatProperties.ofDir(StairBlock.FACING); + public static final EnumProperty HALF = CompatProperties.of(StairBlock.HALF); + public static final EnumProperty SHAPE = CompatProperties.of(StairBlock.SHAPE); + public static final BooleanProperty WATERLOGGED = CompatProperties.of(StairBlock.WATERLOGGED); + + public static final BlockHalfProperty COMPAT_HALF = BlockHalfProperty.ofRaw(StairBlock.HALF); + public static final StairShapeProperty COMPAT_SHAPE = StairShapeProperty.ofRaw(StairBlock.SHAPE); + + public CompatStairsBlock(net.minecraft.world.level.block.state.BlockState baseBlockState, CompatibleBlockSettings settings) { + super(baseBlockState, settings); + } + + public CompatStairsBlock(BlockState baseBlockState, CompatibleBlockSettings settings) { + this(baseBlockState.toMinecraft(), settings); + } + + public VoxelShape getOutlineShape(OutlineShapeEvent e) { + return super.getShape(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 getShape(net.minecraft.world.level.block.state.BlockState state, BlockGetter world, BlockPos pos, CollisionContext 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.world.level.block.state.BlockState state, BlockGetter world, BlockPos pos, CollisionContext 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..0a06eb1d1 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/block/v2/CompatibleBlockSettings.java @@ -0,0 +1,292 @@ +package net.pitan76.mcpitanlib.api.block.v2; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.MapCodec; +import net.minecraft.world.level.block.state.BlockBehaviour; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.material.MapColor; +import net.minecraft.resources.ResourceKey; +import net.minecraft.core.registries.Registries; +import net.minecraft.world.level.block.SoundType; +import net.minecraft.world.item.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 = MapCodec.unitCodec(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.forceSolidOn(); + if (material.isReplaceable()) + settings.settings.replaceable(); + if (material.isSolid()) + settings.settings.forceSolidOn(); + if (material.isBurnable()) + settings.settings.ignitedByLava(); + settings.settings.pushReaction(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, BlockBehaviour block) { + super(block); + setId(id); + } + + public static CompatibleBlockSettings copy(CompatIdentifier id, BlockBehaviour block) { + return new CompatibleBlockSettings(id, block); + } + + public CompatibleBlockSettings air() { + super.air(); + return this; + } + + public CompatibleBlockSettings blockVision(BlockBehaviour.StatePredicate predicate) { + super.blockVision(predicate); + return this; + } + + public CompatibleBlockSettings postProcess(BlockBehaviour.PostProcess predicate) { + super.postProcess(predicate); + return this; + } + + public CompatibleBlockSettings solidBlock(BlockBehaviour.StatePredicate predicate) { + super.solidBlock(predicate); + return this; + } + + public CompatibleBlockSettings suffocates(BlockBehaviour.StatePredicate 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(BlockBehaviour.StatePredicate predicate) { + super.emissiveLighting(predicate); + return this; + } + + public CompatibleBlockSettings offset(BlockBehaviour.OffsetType offsetType) { + super.offset(offsetType); + return this; + } + + public CompatibleBlockSettings allowsSpawning(BlockBehaviour.StateArgumentPredicate> predicate) { + super.allowsSpawning(predicate); + return this; + } + + public BlockBehaviour.Properties build() { + super.build(); + + if (identifier != null) { + settings.setId(ResourceKey.create(Registries.BLOCK, identifier.toMinecraft())); + } + + return settings; + } + + @Deprecated + @Override + public CompatibleBlockSettings sounds(SoundType blockSoundGroup) { + super.sounds(blockSoundGroup); + return this; + } + + +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/block/v3/CompatBlock.java b/common/src/main/java/net/pitan76/mcpitanlib/api/block/v3/CompatBlock.java new file mode 100644 index 000000000..f040d159d --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/block/v3/CompatBlock.java @@ -0,0 +1,60 @@ +package net.pitan76.mcpitanlib.api.block.v3; + +import net.pitan76.mcpitanlib.api.block.args.v2.CollisionShapeEvent; +import net.pitan76.mcpitanlib.api.block.args.v2.OutlineShapeEvent; +import net.pitan76.mcpitanlib.api.block.v2.BlockSettingsBuilder; +import net.pitan76.mcpitanlib.api.block.v2.CompatibleBlockSettings; +import net.pitan76.mcpitanlib.api.event.block.FluidStateArgs; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.midohra.fluid.FluidState; +import net.pitan76.mcpitanlib.midohra.item.ItemWrapper; +import net.pitan76.mcpitanlib.midohra.util.shape.VoxelShape; + +public class CompatBlock extends net.pitan76.mcpitanlib.api.block.v2.CompatBlock { + + public CompatBlock(CompatibleBlockSettings settings) { + super(settings); + } + + public CompatBlock(BlockSettingsBuilder builder, CompatIdentifier id) { + super(builder.build(id)); + } + + public CompatBlock(BlockSettingsBuilder builder) { + super(builder.build()); + } + + public ItemWrapper getItemWrapper() { + return getWrapper().asItem(); + } + + public VoxelShape getCollisionShapeM(CollisionShapeEvent e) { + return VoxelShape.of(super.getCollisionShape(e)); + } + + public VoxelShape getOutlineShapeM(OutlineShapeEvent e) { + return VoxelShape.of(super.getOutlineShape(e)); + } + + public FluidState getFluidStateM(FluidStateArgs args) { + return FluidState.of(super.getFluidState(args)); + } + + @Override + @Deprecated + public net.minecraft.world.phys.shapes.VoxelShape getCollisionShape(CollisionShapeEvent e) { + return getCollisionShapeM(e).raw(); + } + + @Override + @Deprecated + public net.minecraft.world.phys.shapes.VoxelShape getOutlineShape(OutlineShapeEvent e) { + return getOutlineShapeM(e).raw(); + } + + @Override + @Deprecated + public net.minecraft.world.level.material.FluidState getFluidState(FluidStateArgs args) { + return getFluidStateM(args).getRaw(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/block/v3/CompatBlockEntity.java b/common/src/main/java/net/pitan76/mcpitanlib/api/block/v3/CompatBlockEntity.java new file mode 100644 index 000000000..493a6fc08 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/block/v3/CompatBlockEntity.java @@ -0,0 +1,34 @@ +package net.pitan76.mcpitanlib.api.block.v3; + +import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.level.block.state.BlockState; +import net.pitan76.mcpitanlib.api.event.block.TileCreateEvent; +import net.pitan76.mcpitanlib.api.registry.CompatRegistryLookup; +import net.pitan76.mcpitanlib.midohra.block.entity.BlockEntityTypeWrapper; +import net.pitan76.mcpitanlib.midohra.nbt.NbtCompound; + +public class CompatBlockEntity extends net.pitan76.mcpitanlib.api.tile.CompatBlockEntity { + public CompatBlockEntity(BlockEntityType type, BlockPos pos, BlockState state) { + super(type, pos, state); + } + + public CompatBlockEntity(BlockEntityType type, TileCreateEvent event) { + super(type, event); + } + + public CompatBlockEntity(BlockEntityTypeWrapper type, TileCreateEvent event) { + super(type, event); + } + + public NbtCompound toInitChunkDataNbt(CompatRegistryLookup registryLookup) { + return NbtCompound.of(super.toInitialChunkDataNbt(registryLookup)); + } + + @Override + @Deprecated + public CompoundTag toInitialChunkDataNbt(CompatRegistryLookup registryLookup) { + return toInitChunkDataNbt(registryLookup).toMinecraft(); + } +} 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..e20a330ab --- /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.world.entity.player.Inventory; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.Identifier; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; + +@Deprecated +public abstract class CompatInventoryScreen extends SimpleInventoryScreen { + + public CompatInventoryScreen(AbstractContainerMenu handler, Inventory inventory, Component 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..8c61a7640 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/SimpleHandledScreen.java @@ -0,0 +1,318 @@ +package net.pitan76.mcpitanlib.api.client; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Font; +import net.minecraft.client.gui.GuiGraphicsExtractor; +import net.minecraft.client.gui.components.Renderable; +import net.minecraft.client.gui.components.events.GuiEventListener; +import net.minecraft.client.gui.narration.NarratableEntry; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; +import net.minecraft.client.input.KeyEvent; +import net.minecraft.client.renderer.item.ItemModelResolver; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.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.api.util.client.ScreenUtil; +import net.pitan76.mcpitanlib.core.datafixer.Pair; + +@Deprecated +public abstract class SimpleHandledScreen extends AbstractContainerScreen { + + public int width, height, backgroundWidth, backgroundHeight, x, y; + public AbstractContainerMenu handler; + public Font textRenderer; + public ItemModelResolver itemRenderer; + + public Component title; + public Minecraft client; + public SimpleHandledScreen(AbstractContainerMenu handler, Inventory inventory, Component title) { + super(handler, inventory, title); + fixScreen(); + this.handler = handler; + this.title = title; + + } + + public T addDrawableChild_compatibility(T drawableElement) { + return super.addRenderableWidget(drawableElement); + // addButton + } + + public T addSelectableChild_compatibility(T selectableElement) { + return super.addWidget(selectableElement); + } + + public CompatibleTexturedButtonWidget addDrawableCTBW(CompatibleTexturedButtonWidget widget) { + return addDrawableChild_compatibility(widget); + } + + @Deprecated + @Override + public void extractBackground(GuiGraphicsExtractor context, int mouseX, int mouseY, float delta) { + super.extractBackground(context, mouseX, mouseY, delta); + DrawObjectDM drawObjectDM = new DrawObjectDM(context, this); + drawBackgroundOverride(new DrawBackgroundArgs(drawObjectDM, delta, mouseX, mouseY)); + } + + public abstract void drawBackgroundOverride(DrawBackgroundArgs args); + + @Deprecated + @Override + protected void extractLabels(GuiGraphicsExtractor context, int mouseX, int mouseY) { + DrawObjectDM drawObjectDM = new DrawObjectDM(context, this); + drawForegroundOverride(new DrawForegroundArgs(drawObjectDM, mouseX, mouseY)); + } + + protected void drawForegroundOverride(DrawForegroundArgs args) { + super.extractLabels(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) { + ScreenUtil.RendererUtil.drawTexture(drawObjectDM, 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.extractMenuBackground(args.drawObjectDM.getContext()); + } + + public void callDrawMouseoverTooltip(DrawMouseoverTooltipArgs args) { + super.extractTooltip(args.drawObjectDM.getContext(), args.mouseX, args.mouseY); + } + + public void renderOverride(RenderArgs args) { + super.extractRenderState(args.drawObjectDM.getContext(), args.mouseX, args.mouseY, args.delta); + } + + public void resizeOverride(Minecraft client, int width, int height) { + } + + public void initOverride() { + } + + @Deprecated + @Override + protected void init() { + super.init(); + fixScreen(); + initOverride(); + } + + @Deprecated + @Override + public void resize(int width, int height) { + super.resize(width, height); + fixScreen(); + resizeOverride(Minecraft.getInstance(), width, height); + } + + public void fixScreen() { + this.backgroundWidth = getBackgroundWidth(); + this.backgroundHeight = getBackgroundHeight(); + this.x = super.leftPos; //(this.width - this.backgroundWidth) / 2; + this.y = super.topPos; //(this.height - this.backgroundHeight) / 2; + this.textRenderer = super.font; + this.itemRenderer = Minecraft.getInstance().getItemModelResolver(); + this.width = super.width; + this.height = super.height; + if (super.minecraft == null) + this.client = Minecraft.getInstance(); + else + this.client = super.minecraft; + } + + public void setX(int x) { + this.x = x; + super.leftPos = x; + } + + public void setY(int y) { + this.y = y; + super.topPos = y; + } + + public void setTextRenderer(Font textRenderer) { + this.textRenderer = textRenderer; + } + + public void setItemRenderer(ItemModelResolver itemRenderer) { + this.itemRenderer = itemRenderer; + } + + public void setWidth(int width) { + this.width = width; + super.width = width; + } + + public void setBackgroundWidth(int backgroundWidth) { + this.backgroundWidth = backgroundWidth; + super.imageWidth = backgroundWidth; + } + + public void setBackgroundHeight(int backgroundHeight) { + this.backgroundHeight = backgroundHeight; + super.imageHeight = backgroundHeight; + } + + public void setHeight(int height) { + this.height = height; + super.height = height; + } + + public int getBackgroundWidth() { + return super.imageWidth; + } + + public int getBackgroundHeight() { + return super.imageHeight; + } + + @Deprecated + @Override + public void extractRenderState(GuiGraphicsExtractor 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(new KeyEvent(args.keyCode, args.scanCode, args.modifiers)); + } + + public boolean keyPressed(KeyEventArgs args) { + return super.keyPressed(new KeyEvent(args.keyCode, args.scanCode, args.modifiers)); + } + + public void renderBackgroundTexture(RenderBackgroundTextureArgs args) { + if (getBackgroundTexture() != null) + Screen.extractMenuBackgroundTexture(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(KeyEvent input) { + return this.keyReleased(new KeyEventArgs(input.key(), input.scancode(), input.modifiers())); + } + + @Deprecated + @Override + public boolean keyPressed(KeyEvent input) { + return this.keyPressed(new KeyEventArgs(input.key(), input.scancode(), input.modifiers())); + } + + @Deprecated + @Override + public void extractMenuBackground(GuiGraphicsExtractor context) { + this.renderBackgroundTexture(new RenderBackgroundTextureArgs(new DrawObjectDM(context, this), 0)); + } + + public void closeOverride() { + super.onClose(); + } + + public void removedOverride() { + super.removed(); + } + + @Override + public void onClose() { + closeOverride(); + } + + @Override + public void removed() { + removedOverride(); + } + + public Identifier getBackgroundTexture() { + return IdentifierUtil.from(getCompatBackgroundTexture()); + } + + public CompatIdentifier getCompatBackgroundTexture() { + return null; + } + + public void setTitleX(int x) { + this.titleLabelX = x; + } + + public void setTitleY(int y) { + this.titleLabelY = 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.width(title) / 2); + } + + public int getTitleX() { + return titleLabelX; + } + + public int getTitleY() { + return titleLabelY; + } + + @Deprecated + @Override + public Component getTitle() { + return callGetTitle(); + } + + public Component callGetTitle() { + return super.getTitle(); + } + + public Pair getTitlePosP() { + return new Pair<>(getTitleX(), getTitleY()); + } + + public int getPlayerInvTitleX() { + return inventoryLabelX; + } + + public int getPlayerInvTitleY() { + return inventoryLabelY; + } + + public void setPlayerInvTitleX(int x) { + inventoryLabelX = x; + } + + public void setPlayerInvTitleY(int y) { + inventoryLabelY = 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..c04f5ba63 --- /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.world.entity.player.Inventory; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.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(AbstractContainerMenu handler, Inventory inventory, Component 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..1464212bf --- /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.screens.Screen; +import net.minecraft.client.Options; +import net.minecraft.network.chat.Component; + +public class SimpleOptionsScreen extends SimpleScreen { + + protected final Screen parent; + protected final Options gameOptions; + + public SimpleOptionsScreen(Component title, Screen parent, Options gameOptions) { + super(title); + this.parent = parent; + this.gameOptions = gameOptions; + } + + @Override + public void removed() { + client.options.save(); + } + + @Override + public void onClose() { + 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..cc0f9f2cf --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/SimpleScreen.java @@ -0,0 +1,195 @@ +package net.pitan76.mcpitanlib.api.client; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Font; +import net.minecraft.client.gui.GuiGraphicsExtractor; +import net.minecraft.client.gui.components.Renderable; +import net.minecraft.client.gui.components.events.GuiEventListener; +import net.minecraft.client.gui.narration.NarratableEntry; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.input.KeyEvent; +import net.minecraft.client.renderer.item.ItemModelResolver; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.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.RenderUtil; +import net.pitan76.mcpitanlib.api.util.client.ScreenUtil; + +public abstract class SimpleScreen extends Screen { + + public int width, height; + public Font textRenderer; + public ItemModelResolver itemRenderer; + + public Component title; + public Minecraft client; + + public SimpleScreen(Component title) { + super(title); + fixScreen(); + this.title = title; + } + + public SimpleScreen(TextComponent title) { + this(title.getText()); + } + + public T addDrawableChild_compatibility(T drawableElement) { + return super.addRenderableWidget(drawableElement); + // addButton + } + + public T addSelectableChild_compatibility(T selectableElement) { + return super.addWidget(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.RendererUtil.drawTexture(drawObjectDM, texture, x, y, u, v, width, height); + } + + 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 extractBackground(GuiGraphicsExtractor context, int mouseX, int mouseY, float delta) { + renderBackground(new RenderArgs(new DrawObjectDM(context, this), mouseX, mouseY, delta)); + } + + public void renderBackground(RenderArgs args) { + super.extractBackground(args.drawObjectDM.getContext(), args.mouseX, args.mouseY, args.delta); + } + + public void render(RenderArgs args) { + super.extractRenderState(args.drawObjectDM.getContext(), args.mouseX, args.mouseY, args.delta); + } + + public void resizeOverride(Minecraft client, int width, int height) { + } + + public void initOverride() { + } + + @Deprecated + @Override + protected void init() { + super.init(); + fixScreen(); + initOverride(); + } + + @Deprecated + @Override + public void resize(int width, int height) { + super.resize(width, height); + fixScreen(); + resizeOverride(Minecraft.getInstance(), width, height); + } + + public void fixScreen() { + this.textRenderer = super.font; + this.itemRenderer = Minecraft.getInstance().getItemModelResolver(); + this.width = super.width; + this.height = super.height; + if (super.minecraft == null) + this.client = Minecraft.getInstance(); + else + this.client = super.minecraft; + } + + public void setTextRenderer(Font textRenderer) { + this.textRenderer = textRenderer; + } + + public void setItemRenderer(ItemModelResolver 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 extractRenderState(GuiGraphicsExtractor 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(new KeyEvent(args.keyCode, args.scanCode, args.modifiers)); + } + + public boolean keyPressed(KeyEventArgs args) { + return super.keyPressed(new KeyEvent(args.keyCode, args.scanCode, args.modifiers)); + } + + public void renderBackgroundTexture(RenderBackgroundTextureArgs args) { + if (getBackgroundTexture() != null) + Screen.extractMenuBackgroundTexture(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(KeyEvent keyInput) { + return this.keyReleased(new KeyEventArgs(keyInput.key(), keyInput.scancode(), keyInput.modifiers())); + } + + @Deprecated + @Override + public boolean keyPressed(KeyEvent keyInput) { + return this.keyPressed(new KeyEventArgs(keyInput.key(), keyInput.scancode(), keyInput.modifiers())); + } + + @Deprecated + @Override + public void extractMenuBackground(GuiGraphicsExtractor context) { + this.renderBackgroundTexture(new RenderBackgroundTextureArgs(new DrawObjectDM(context, this), 0)); + } + + public void closeOverride() { + super.onClose(); + } + + public void removedOverride() { + super.removed(); + } + + @Override + public void onClose() { + 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..a0cbe1ee5 --- /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.client.renderer.block.BlockAndTintGetter; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.BlockState; +import net.pitan76.mcpitanlib.midohra.world.BlockView; +import org.jetbrains.annotations.Nullable; + +public class BlockColorEvent { + private final BlockState state; + private final BlockAndTintGetter world; + private final BlockPos pos; + private final int tintIndex; + + public BlockColorEvent(BlockState state, @Nullable BlockAndTintGetter world, @Nullable BlockPos pos, int tintIndex) { + this.state = state; + this.world = world; + this.pos = pos; + this.tintIndex = tintIndex; + } + + public BlockState getState() { + return state; + } + + public BlockAndTintGetter 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 + public 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..254841506 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/color/CompatBlockColorProvider.java @@ -0,0 +1,54 @@ +package net.pitan76.mcpitanlib.api.client.color; + +import net.minecraft.client.color.block.BlockTintSource; +import net.minecraft.client.renderer.block.BlockAndTintGetter; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.core.BlockPos; +import org.jetbrains.annotations.Nullable; + +import java.util.ArrayList; +import java.util.List; + +public interface CompatBlockColorProvider { + default int getColor(BlockState state, @Nullable BlockAndTintGetter world, @Nullable BlockPos pos, int tintIndex) { + return getColor(new BlockColorEvent(state, world, pos, tintIndex)); + } + + int getColor(BlockColorEvent e); + + class BuiltBlockTintSource implements BlockTintSource { + private final CompatBlockColorProvider provider; + private final int tintIndex; + + public BuiltBlockTintSource(CompatBlockColorProvider provider, int tintIndex) { + this.provider = provider; + this.tintIndex = tintIndex; + } + + @Override + public int color(BlockState state) { + return provider.getColor(new BlockColorEvent(state, null, null, tintIndex)); + } + + @Override + public int colorInWorld(BlockState state, BlockAndTintGetter level, BlockPos pos) { + return provider.getColor(new BlockColorEvent(state, level, pos, tintIndex)); + } + + + @Override + public int colorAsTerrainParticle(BlockState state, BlockAndTintGetter level, BlockPos pos) { + return provider.getColor(new BlockColorEvent(state, level, pos, tintIndex)); + } + } + + default List toTintSource() { + List tintSources = new ArrayList<>(); + + // TODO: 16は適当な数。実際にはtintIndexの最大値に合わせて増やす必要があるかもしれない + for (int i = 0; i < 16; i++) { + tintSources.add(new BuiltBlockTintSource(this, i)); + } + return tintSources; + } +} 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..ef0efff4e --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/event/ItemTooltipRegistry.java @@ -0,0 +1,11 @@ +package net.pitan76.mcpitanlib.api.client.event; + +import dev.architectury.injectables.annotations.ExpectPlatform; +import net.pitan76.mcpitanlib.api.client.event.listener.ItemTooltipListener; + +public class ItemTooltipRegistry { + @ExpectPlatform + public static void registerItemTooltip(ItemTooltipListener listener) { + + } +} 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..87973b6bf --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/event/WorldRenderRegistry.java @@ -0,0 +1,160 @@ +package net.pitan76.mcpitanlib.api.client.event; + +//import dev.architectury.injectables.annotations.ExpectPlatform; +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 net.pitan76.mcpitanlib.api.util.client.ClientUtil; +import org.jetbrains.annotations.Nullable; +import org.joml.Matrix4f; + +import java.util.ArrayList; +import java.util.List; + +public class WorldRenderRegistry { + + public static List beforeBlockOutlineListeners = new ArrayList<>(); + public static List worldRenderAfterLevelListeners = new ArrayList<>(); + + public static boolean isEmptyBlockOutlineListeners = true; + public static boolean isEmptyWorldRenderAfterLevelListeners = true; + + public WorldRenderRegistry() { + + } + + //@ExpectPlatform + public static void registerWorldRenderBeforeBlockOutline(BeforeBlockOutlineListener listener) { + beforeBlockOutlineListeners.add(listener); + isEmptyBlockOutlineListeners = false; + //throw new AssertionError(); + } + + //@ExpectPlatform + public static void registerWorldRenderAfterLevel(WorldRenderContextListener listener) { + worldRenderAfterLevelListeners.add(listener); + isEmptyWorldRenderAfterLevelListeners = false; + //throw new AssertionError(); + } +// public static void _registerWorldRenderBeforeBlockOutline(BeforeBlockOutlineListener listener) { +// WorldRenderEvents.BEFORE_BLOCK_OUTLINE.register(((worldRenderContext, renderState) -> listener.beforeBlockOutline(new BeforeBlockOutlineEvent( +// new WorldRenderContext() { +// @Override +// public WorldRenderer getWorldRenderer() { +// return worldRenderContext.worldRenderer(); +// } +// +// @Override +// public MatrixStack getMatrixStack() { +// return worldRenderContext.matrices(); +// } +// +// @Override +// public float getTickDelta() { +// return MinecraftClient.getInstance().getRenderTickCounter().getDynamicDeltaTicks(); +// } +// +// @Override +// public Camera getCamera() { +// return worldRenderContext.gameRenderer().getCamera(); +// } +// +// @Override +// public GameRenderer getGameRenderer() { +// return worldRenderContext.gameRenderer(); +// } +// +// @Override +// public LightmapTextureManager getLightmapTextureManager() { +// return getGameRenderer().getLightmapTextureManager(); +// } +// +// @Override +// public Matrix4f getProjectionMatrix() { +// return worldRenderContext.gameRenderer().getBasicProjectionMatrix(0); +// } +// +// @Override +// public ClientWorld getWorld() { +// return ClientUtil.getWorld(); +// } +// +// @Override +// public boolean isAdvancedTranslucency() { +// return renderState.isTranslucent(); +// } +// +// @Override +// public VertexConsumerProvider getConsumers() { +// return worldRenderContext.consumers(); +// } +// +// @Override +// public Frustum getFrustum() { +// return worldRenderContext.worldRenderer().getCapturedFrustum(); +// } +// }, renderState)))); +// } +// +// public static void _registerWorldRenderAfterLevel(WorldRenderContextListener listener) { +// WorldRenderEvents.END_MAIN.register((context -> { +// listener.render(new WorldRenderContext() { +// @Override +// public WorldRenderer getWorldRenderer() { +// return context.worldRenderer(); +// } +// +// @Override +// public MatrixStack getMatrixStack() { +// return context.matrices(); +// } +// +// @Override +// public float getTickDelta() { +// return MinecraftClient.getInstance().getRenderTickCounter().getDynamicDeltaTicks(); +// } +// +// @Override +// public Camera getCamera() { +// return context.gameRenderer().getCamera(); +// } +// +// @Override +// public GameRenderer getGameRenderer() { +// return context.gameRenderer(); +// } +// +// @Override +// public LightmapTextureManager getLightmapTextureManager() { +// return getGameRenderer().getLightmapTextureManager(); +// } +// +// @Override +// public Matrix4f getProjectionMatrix() { +// return context.gameRenderer().getBasicProjectionMatrix(0); +// } +// +// @Override +// public ClientWorld getWorld() { +// return ClientUtil.getWorld(); +// } +// +// @Override +// public boolean isAdvancedTranslucency() { +// return true; +// } +// +// @Override +// public @Nullable VertexConsumerProvider getConsumers() { +// return context.consumers(); +// } +// +// @Override +// public @Nullable Frustum getFrustum() { +// return context.worldRenderer().getCapturedFrustum(); +// } +// }); +// })); +// } +} 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..36114a46b --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/event/listener/BeforeBlockOutlineEvent.java @@ -0,0 +1,122 @@ +package net.pitan76.mcpitanlib.api.client.event.listener; + +import net.minecraft.client.renderer.state.level.BlockOutlineRenderState; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.client.Camera; +import com.mojang.blaze3d.vertex.VertexConsumer; +import net.minecraft.client.renderer.LevelRenderer; +import com.mojang.blaze3d.vertex.PoseStack; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.world.phys.HitResult; +import net.minecraft.core.BlockPos; +import net.minecraft.world.phys.AABB; +import net.minecraft.world.phys.shapes.VoxelShape; +import net.minecraft.world.level.Level; +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, BlockOutlineRenderState renderState) { + this.context = context; + this.hitResult = context.getHitResult(); + } + + public BeforeBlockOutlineEvent(WorldRenderContext context, HitResult hitResult) { + this.context = context; + this.hitResult = hitResult; + } + + public HitResult getHitResult() { + return hitResult; + } + + public WorldRenderContext getContext() { + return context; + } + + public LevelRenderer getWorldRenderer() { + return context.getWorldRenderer(); + } + + public Optional getBlockState() { + return Optional.ofNullable(getWorld().getBlockState(getBlockPos().orElse(null))); + } + + public Level 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 PoseStack 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(AABB 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..a538df618 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/event/listener/ItemTooltipContext.java @@ -0,0 +1,68 @@ +package net.pitan76.mcpitanlib.api.client.event.listener; + +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.TooltipFlag; +import net.minecraft.network.chat.Component; +import net.pitan76.mcpitanlib.api.text.TextComponent; +import net.pitan76.mcpitanlib.api.util.TextUtil; + +import java.util.List; + +public class ItemTooltipContext { + + public ItemStack stack; + public List texts; + public Item.TooltipContext tooltipContext; + + @Deprecated + public TooltipFlag type; + + public ItemTooltipContext(ItemStack stack, List texts, Item.TooltipContext tooltipContext, TooltipFlag 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 TooltipFlag getType() { + return type; + } + + public void addTooltip(Component 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(); + } + + public void addTooltip(TextComponent textComponent) { + addTooltip(textComponent.getText()); + } + + public void addTooltip(String text) { + addTooltip(TextUtil.literal(text)); + } +} 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..dc83f5a08 --- /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.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.TooltipFlag; +import net.minecraft.network.chat.Component; + +import java.util.List; + +@FunctionalInterface +public interface ItemTooltipListener { + void onTooltip(ItemTooltipContext context); + + default void onTooltip(ItemStack stack, List texts, Item.TooltipContext tooltipContext, TooltipFlag 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..ce15a1e54 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/event/listener/WorldRenderContext.java @@ -0,0 +1,151 @@ +package net.pitan76.mcpitanlib.api.client.event.listener; + +import com.mojang.blaze3d.vertex.VertexConsumer; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.Camera; +import net.minecraft.client.renderer.GameRenderer; +import net.minecraft.client.renderer.LevelRenderer; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.culling.Frustum; +import net.minecraft.client.renderer.rendertype.RenderTypes; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.client.Minecraft; +import com.mojang.blaze3d.vertex.PoseStack; +import net.minecraft.client.multiplayer.ClientLevel; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.world.phys.HitResult; +import net.minecraft.core.BlockPos; +import net.minecraft.world.phys.AABB; +import net.minecraft.world.phys.shapes.VoxelShape; +import net.pitan76.mcpitanlib.api.client.render.CompatMatrixStack; +import net.pitan76.mcpitanlib.api.util.VoxelShapeUtil; +import net.pitan76.mcpitanlib.api.util.client.render.VertexRenderingUtil; +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 { + + LevelRenderer getWorldRenderer(); + + PoseStack getMatrixStack(); + + float getTickDelta(); + + Camera getCamera(); + + GameRenderer getGameRenderer(); + +// LightTexture getLightmapTextureManager(); + + @Deprecated + Matrix4f getProjectionMatrix(); + + ClientLevel getWorld(); + + @Deprecated + boolean isAdvancedTranslucency(); + + @Nullable MultiBufferSource 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 Minecraft.getInstance().hitResult; + } + + 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.getShape(getWorld(), + getBlockPos().orElse(null))); + } + + default void push() { + getMatrixStack().pushPose(); + } + + default void translate(double x, double y, double z) { + getMatrixStack().translate(x, y, z); + } + + default void pop() { + getMatrixStack().popPose(); + } + + default CompatMatrixStack getCompatMatrices() { + return CompatMatrixStack.of(getMatrixStack()); + } + + default Optional getVertexConsumer() { + if (getConsumers() == null) + return Optional.empty(); + + return Optional.of(Objects.requireNonNull(getConsumers()).getBuffer(RenderTypes.lines())); + } + + 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(AABB box, float red, float green, float blue, float alpha) { + Optional vertexConsumer = getVertexConsumer(); + + if (!vertexConsumer.isPresent()) + return; + + VertexConsumer consumer = vertexConsumer.get(); + + double x1 = box.minX; + double y1 = box.minY; + double z1 = box.minZ; + double x2 = box.maxX; + double y2 = box.maxY; + double z2 = box.maxZ; + + VertexRenderingUtil.drawBox(getMatrixStack(), consumer, x1, y1, z1, x2, y2, z2, 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/WorldRenderContextImpl.java b/common/src/main/java/net/pitan76/mcpitanlib/api/client/event/listener/WorldRenderContextImpl.java new file mode 100644 index 000000000..fd7c04ec6 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/event/listener/WorldRenderContextImpl.java @@ -0,0 +1,118 @@ +package net.pitan76.mcpitanlib.api.client.event.listener; + +import net.minecraft.client.Camera; +import net.minecraft.client.DeltaTracker; +import net.minecraft.client.renderer.GameRenderer; +import net.minecraft.client.renderer.LevelRenderer; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.culling.Frustum; +import com.mojang.blaze3d.vertex.PoseStack; +import net.minecraft.client.multiplayer.ClientLevel; +import com.mojang.math.Axis; +import net.minecraft.world.phys.Vec3; +import net.pitan76.mcpitanlib.api.util.client.ClientUtil; +import org.jetbrains.annotations.Nullable; +import org.joml.Matrix4f; + +public class WorldRenderContextImpl implements WorldRenderContext { + + public LevelRenderer worldRenderer; + public PoseStack matrixStack; + public float tickDelta; + public Camera camera; + public GameRenderer gameRenderer; +// public LightTexture lightmapTextureManager; + public Matrix4f projectionMatrix; + public ClientLevel world; + public boolean advancedTranslucency; + public @Nullable MultiBufferSource consumers; + public @Nullable Frustum frustum; + + @Override + public LevelRenderer getWorldRenderer() { + return worldRenderer; + } + + @Override + public PoseStack getMatrixStack() { + return matrixStack; + } + + @Override + public float getTickDelta() { + return tickDelta; + } + + @Override + public Camera getCamera() { + if (camera == null) { + return getGameRenderer().getMainCamera(); + } + return camera; + } + + @Override + public GameRenderer getGameRenderer() { + if (gameRenderer == null) { + return ClientUtil.getGameRenderer(); + } + return gameRenderer; + } + +// @Override +// public LightTexture getLightmapTextureManager() { +// return lightmapTextureManager; +// } + + @Override + public Matrix4f getProjectionMatrix() { + return projectionMatrix; + } + + @Override + public ClientLevel getWorld() { + if (world == null) { + return ClientUtil.getWorld(); + } + return world; + } + + @Override + public boolean isAdvancedTranslucency() { + return advancedTranslucency; + } + + @Override + public @Nullable MultiBufferSource getConsumers() { + return consumers; + } + + @Override + public @Nullable Frustum getFrustum() { + return frustum; + } + + public void prepare(GameRenderer gameRenderer, LevelRenderer worldRenderer, @Nullable ClientLevel world, DeltaTracker tickCounter, boolean renderBlockOutline, Camera camera, Matrix4f positionMatrix, Matrix4f matrix4f, Matrix4f projectionMatrix) { + this.gameRenderer = gameRenderer; + this.worldRenderer = worldRenderer; + this.world = world; + this.camera = camera; + this.matrixStack = new PoseStack(); + this.matrixStack.mulPose(projectionMatrix); + this.matrixStack.pushPose(); + + matrixStack.mulPose(Axis.YP.rotationDegrees(-camera.yRot())); + matrixStack.mulPose(Axis.XP.rotationDegrees(camera.xRot())); + + Vec3 camPos = camera.position(); + matrixStack.translate(-camPos.x, -camPos.y, -camPos.z); + + this.matrixStack.popPose(); + + this.projectionMatrix = projectionMatrix;; + this.tickDelta = tickCounter.getGameTimeDeltaTicks(); + this.frustum = gameRenderer.getMainCamera().getCapturedFrustum(); + } + + +} 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..9691117f6 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/gui/screen/CompatInventoryScreen.java @@ -0,0 +1,39 @@ +package net.pitan76.mcpitanlib.api.client.gui.screen; + +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.Slot; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.Identifier; +import net.pitan76.mcpitanlib.api.client.render.DrawObjectDM; +import net.pitan76.mcpitanlib.api.text.TextComponent; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.api.util.inventory.CompatPlayerInventory; +import net.pitan76.mcpitanlib.guilib.api.render.SlotRenderer; + +public abstract class CompatInventoryScreen extends SimpleInventoryScreen { + + public CompatInventoryScreen(S handler, Inventory inventory, Component title) { + super(handler, inventory, title); + } + + public CompatInventoryScreen(S handler, CompatPlayerInventory inventory, TextComponent title) { + this(handler, inventory.getRaw(), title.getText()); + } + + 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..df09019ac --- /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.network.chat.Component; +import net.pitan76.mcpitanlib.api.util.TextUtil; + +public class ScreenTexts { + public static final Component ON = TextUtil.translatable("options.on"); + public static final Component OFF = TextUtil.translatable("options.off"); + public static final Component DONE = TextUtil.translatable("gui.done"); + public static final Component CANCEL = TextUtil.translatable("gui.cancel"); + public static final Component YES = TextUtil.translatable("gui.yes"); + public static final Component NO = TextUtil.translatable("gui.no"); + public static final Component PROCEED = TextUtil.translatable("gui.proceed"); + public static final Component BACK = TextUtil.translatable("gui.back"); + public static final Component CONNECT_FAILED = TextUtil.translatable("connect.failed"); + public static final Component LINE_BREAK = TextUtil.literal("\n"); + public static final Component 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..788253e2f --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/gui/screen/SimpleHandledScreen.java @@ -0,0 +1,422 @@ +package net.pitan76.mcpitanlib.api.client.gui.screen; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Font; +import net.minecraft.client.gui.GuiGraphicsExtractor; +import net.minecraft.client.gui.components.Renderable; +import net.minecraft.client.gui.components.events.GuiEventListener; +import net.minecraft.client.gui.narration.NarratableEntry; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; +import net.minecraft.client.input.CharacterEvent; +import net.minecraft.client.input.KeyEvent; +import net.minecraft.client.input.MouseButtonEvent; +import net.minecraft.client.renderer.item.ItemModelResolver; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.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.api.util.inventory.CompatPlayerInventory; +import net.pitan76.mcpitanlib.core.datafixer.Pair; + +public abstract class SimpleHandledScreen extends AbstractContainerScreen { + + public int width, height, backgroundWidth, backgroundHeight, x, y; + public S handler; + public Font textRenderer; + public ItemModelResolver itemRenderer; + + public Component title; + public Minecraft client; + public SimpleHandledScreen(S handler, Inventory inventory, Component title) { + super(handler, inventory, title); + fixScreen(); + this.handler = handler; + this.title = title; + } + + public SimpleHandledScreen(S handler, CompatPlayerInventory inventory, TextComponent title) { + this(handler, inventory.getRaw(), title.getText()); + } + + @Deprecated + @Override + public S getMenu() { + return getScreenHandlerOverride(); + } + + public S getScreenHandlerOverride() { + return super.getMenu(); + } + + public T addDrawableChild_compatibility(T drawableElement) { + return super.addRenderableWidget(drawableElement); + // addButton + } + + public T addSelectableChild_compatibility(T selectableElement) { + return super.addWidget(selectableElement); + } + + public CompatibleTexturedButtonWidget addDrawableCTBW(CompatibleTexturedButtonWidget widget) { + return addDrawableChild_compatibility(widget); + } + + @Deprecated + @Override + public void extractBackground(GuiGraphicsExtractor context, int mouseX, int mouseY, float delta) { + super.extractBackground(context, mouseX, mouseY, delta); + DrawObjectDM drawObjectDM = new DrawObjectDM(context, this); + drawBackgroundOverride(new DrawBackgroundArgs(drawObjectDM, delta, mouseX, mouseY)); + } + + public abstract void drawBackgroundOverride(DrawBackgroundArgs args); + + @Deprecated + @Override + protected void extractLabels(GuiGraphicsExtractor context, int mouseX, int mouseY) { + DrawObjectDM drawObjectDM = new DrawObjectDM(context, this); + drawForegroundOverride(new DrawForegroundArgs(drawObjectDM, mouseX, mouseY)); + } + + protected void drawForegroundOverride(DrawForegroundArgs args) { + super.extractLabels(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) { + ScreenUtil.RendererUtil.drawTexture(drawObjectDM, texture, x, y, u, v, width, height); + } + + 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) { + // TODO: 以前のバージョンではどう機能しているかチェックする必要がある。このバージョンで利用すると全体が暗くなる + // super.extractBackground(args.drawObjectDM.getContext(), args.mouseX, args.mouseY, args.delta); + } + + public void callDrawMouseoverTooltip(DrawMouseoverTooltipArgs args) { + super.extractTooltip(args.drawObjectDM.getContext(), args.mouseX, args.mouseY); + } + + public void renderOverride(RenderArgs args) { + super.extractRenderState(args.drawObjectDM.getContext(), args.mouseX, args.mouseY, args.delta); + } + + public void resizeOverride(Minecraft client, int width, int height) { + } + + public void initOverride() { + } + + @Deprecated + @Override + protected void init() { + super.init(); + fixScreen(); + initOverride(); + } + + @Deprecated + @Override + public void resize(int width, int height) { + super.resize(width, height); + fixScreen(); + resizeOverride(Minecraft.getInstance(), width, height); + } + + public void fixScreen() { + this.backgroundWidth = getBackgroundWidth(); + this.backgroundHeight = getBackgroundHeight(); + this.x = super.leftPos; //(this.width - this.backgroundWidth) / 2; + this.y = super.topPos; //(this.height - this.backgroundHeight) / 2; + this.textRenderer = super.font; + this.itemRenderer = Minecraft.getInstance().getItemModelResolver(); + this.width = super.width; + this.height = super.height; + if (super.minecraft == null) + this.client = Minecraft.getInstance(); + else + this.client = super.minecraft; + } + + public void setX(int x) { + this.x = x; + super.leftPos = x; + } + + public void setY(int y) { + this.y = y; + super.topPos = y; + } + + public void setTextRenderer(Font textRenderer) { + this.textRenderer = textRenderer; + } + + public void setItemRenderer(ItemModelResolver itemRenderer) { + this.itemRenderer = itemRenderer; + } + + public void setWidth(int width) { + this.width = width; + super.width = width; + } + + public void setBackgroundWidth(int backgroundWidth) { + this.backgroundWidth = backgroundWidth; + super.imageWidth = backgroundWidth; + } + + public void setBackgroundHeight(int backgroundHeight) { + this.backgroundHeight = backgroundHeight; + super.imageHeight = backgroundHeight; + } + + public void setHeight(int height) { + this.height = height; + super.height = height; + } + + public int getBackgroundWidth() { + return super.imageWidth; + } + + public int getBackgroundHeight() { + return super.imageHeight; + } + + @Deprecated + @Override + public void extractRenderState(GuiGraphicsExtractor 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(new KeyEvent(args.keyCode, args.scanCode, args.modifiers)); + } + + public boolean keyPressed(KeyEventArgs args) { + return super.keyPressed(new KeyEvent(args.keyCode, args.scanCode, args.modifiers)); + } + + public void renderBackgroundTexture(RenderBackgroundTextureArgs args) { + if (getBackgroundTexture() != null) + Screen.extractMenuBackgroundTexture(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(KeyEvent input) { + return this.keyReleased(new KeyEventArgs(input.key(), input.scancode(), input.modifiers())); + } + + @Deprecated + @Override + public boolean keyPressed(KeyEvent input) { + return this.keyPressed(new KeyEventArgs(input.key(), input.scancode(), input.modifiers())); + } + + @Deprecated + @Override + public void extractMenuBackground(GuiGraphicsExtractor context) { + callRenderBackground(new RenderArgs(new DrawObjectDM(context, this), 0, 0, 0)); + } + + public void closeOverride() { + super.onClose(); + } + + public void removedOverride() { + super.removed(); + } + + @Override + public void onClose() { + closeOverride(); + } + + @Override + public void removed() { + removedOverride(); + } + + public Identifier getBackgroundTexture() { + return IdentifierUtil.from(getCompatBackgroundTexture()); + } + + public CompatIdentifier getCompatBackgroundTexture() { + return null; + } + + public void setTitleX(int x) { + this.titleLabelX = x; + } + + public void setTitleY(int y) { + this.titleLabelY = 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.width(title) / 2); + } + + public int getTitleX() { + return titleLabelX; + } + + public int getTitleY() { + return titleLabelY; + } + + public void drawText(DrawObjectDM drawObjectDM, Component 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, Component 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 Component getTitle() { + return callGetTitle(); + } + + public Component callGetTitle() { + return super.getTitle(); + } + + public Pair getTitlePosP() { + return new Pair<>(getTitleX(), getTitleY()); + } + + public int getPlayerInvTitleX() { + return inventoryLabelX; + } + + public int getPlayerInvTitleY() { + return inventoryLabelY; + } + + public void setPlayerInvTitleX(int x) { + inventoryLabelX = x; + } + + public void setPlayerInvTitleY(int y) { + inventoryLabelY = y; + } + + public void setPlayerInvTitle(int x, int y) { + setPlayerInvTitleX(x); + setPlayerInvTitleY(y); + } + + public Font callGetTextRenderer() { + if (textRenderer != null) + return textRenderer; + + if (super.getFont() != null) + return super.getFont(); + + return ClientUtil.getTextRenderer(); + } + + public ItemModelResolver callGetItemRenderer() { + if (itemRenderer != null) + return itemRenderer; + + return ClientUtil.getItemRenderer(); + } + + public Component getPlayerInvTitle() { + return playerInventoryTitle; + } + + public boolean charTyped(CharEventArgs args) { + return super.charTyped(new CharacterEvent(args.getCharacter())); + } + + @Deprecated + @Override + public boolean charTyped(CharacterEvent event) { + return charTyped(new CharEventArgs(event.codepoint())); + } + + public boolean mouseScrolled(MouseScrolledArgs args) { + return super.mouseScrolled(args.getMouseX(), args.getMouseY(), args.getScrollX(), args.getScrollY()); + } + + @Deprecated + @Override + public boolean mouseScrolled(double x, double y, double scrollX, double scrollY) { + return mouseScrolled(new MouseScrolledArgs(x, y, scrollX, scrollY)); + } + + public boolean mouseClicked(MouseClickedArgs args) { + return super.mouseClicked(new MouseButtonEvent(args.getX(), args.getY(), args.getButtonInfo()), args.isDoubleClick()); + } + + @Deprecated + @Override + public boolean mouseClicked(MouseButtonEvent event, boolean doubleClick) { + return mouseClicked(new MouseClickedArgs(event.x(), event.y(), event.buttonInfo(), doubleClick)); + } + + public boolean mouseDragged(MouseDraggedArgs args) { + return super.mouseDragged(new MouseButtonEvent(args.getX(), args.getY(), args.getButtonInfo()), args.getDeltaX(), args.getDeltaY()); + } + + @Deprecated + @Override + public boolean mouseDragged(MouseButtonEvent event, double dx, double dy) { + return mouseDragged(new MouseDraggedArgs(event.x(), event.y(), event.buttonInfo(), dx, dy)); + } + + public boolean mouseReleased(MouseReleasedArgs args) { + return super.mouseReleased(new MouseButtonEvent(args.getX(), args.getY(), args.getButtonInfo())); + } + + @Deprecated + @Override + public boolean mouseReleased(MouseButtonEvent event) { + return mouseReleased(new MouseReleasedArgs(event.x(), event.y(), event.buttonInfo())); + } +} 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..39b5f47a4 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/gui/screen/SimpleInventoryScreen.java @@ -0,0 +1,44 @@ +package net.pitan76.mcpitanlib.api.client.gui.screen; + +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.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.text.TextComponent; +import net.pitan76.mcpitanlib.api.util.client.RenderUtil; +import net.pitan76.mcpitanlib.api.util.inventory.CompatPlayerInventory; + +public abstract class SimpleInventoryScreen extends SimpleHandledScreen { + + public SimpleInventoryScreen(S handler, Inventory inventory, Component title) { + super(handler, inventory, title); + } + + public SimpleInventoryScreen(S handler, CompatPlayerInventory inventory, TextComponent title) { + this(handler, inventory.getRaw(), title.getText()); + } + + 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..349b51deb --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/gui/widget/CompatTextFieldWidget.java @@ -0,0 +1,145 @@ +package net.pitan76.mcpitanlib.api.client.gui.widget; + +import net.minecraft.client.gui.Font; +import net.minecraft.client.gui.components.EditBox; +import net.minecraft.client.input.CharacterEvent; +import net.minecraft.client.input.KeyEvent; +import net.minecraft.network.chat.Component; +import net.pitan76.mcpitanlib.api.util.TextUtil; +import org.jetbrains.annotations.Nullable; + +public class CompatTextFieldWidget extends EditBox { + public CompatTextFieldWidget(Font textRenderer, int width, int height) { + this(textRenderer, width, height, TextUtil.empty()); + } + + public CompatTextFieldWidget(Font textRenderer, int x, int y, int width, int height) { + this(textRenderer, x, y, width, height, TextUtil.empty()); + } + + // ---- + + public CompatTextFieldWidget(Font textRenderer, int width, int height, Component text) { + super(textRenderer, width, height, text); + } + + public CompatTextFieldWidget(Font textRenderer, int x, int y, int width, int height, Component text) { + super(textRenderer, x, y, width, height, text); + } + + public CompatTextFieldWidget(Font textRenderer, int x, int y, int width, int height, @Nullable EditBox copyFrom, Component text) { + super(textRenderer, x, y, width, height, copyFrom, text); + } + + // ---- + + @Deprecated + @Override + public void setBordered(boolean drawsBackground) { + callSetDrawsBackground(drawsBackground); + } + + public void callSetDrawsBackground(boolean drawsBackground) { + super.setBordered(drawsBackground); + } + + @Deprecated + @Override + public void setFocused(boolean focused) { + callSetFocused(focused); + } + + public void callSetFocused(boolean focused) { + super.setFocused(focused); + } + + @Deprecated + @Override + public void setCanLoseFocus(boolean focusUnlocked) { + callSetFocusUnlocked(focusUnlocked); + } + + public void callSetFocusUnlocked(boolean focusUnlocked) { + super.setCanLoseFocus(focusUnlocked); + } + + @Deprecated + @Override + public void setMaxLength(int maxLength) { + callSetMaxLength(maxLength); + } + + public void callSetMaxLength(int maxLength) { + super.setMaxLength(maxLength); + } + + @Deprecated + @Override + public void setValue(String text) { + callSetText(text); + } + + public void callSetText(String text) { + super.setValue(text); + } + + @Deprecated + @Override + public String getValue() { + return callGetText(); + } + + public String callGetText() { + return super.getValue(); + } + + @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(KeyEvent input) { + return callKeyPressed(input.key(), input.scancode(), input.modifiers()); + } + + public boolean callKeyPressed(int keyCode, int scanCode, int modifiers) { + return super.keyPressed(new KeyEvent(keyCode, scanCode, modifiers)); + } + + @Deprecated + @Override + public boolean keyReleased(KeyEvent input) { + return callKeyReleased(input.key(), input.scancode(), input.modifiers()); + } + + public boolean callKeyReleased(int keyCode, int scanCode, int modifiers) { + return super.keyReleased(new KeyEvent(keyCode, scanCode, modifiers)); + } + + @Deprecated + @Override + public boolean charTyped(CharacterEvent input) { + return callCharTyped((char) input.codepoint(), -1); + } + + public boolean callCharTyped(char chr, int modifiers) { + return super.charTyped(new CharacterEvent(chr)); + } +} 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..ddceb64de --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/gui/widget/CompatibleTexturedButtonWidget.java @@ -0,0 +1,74 @@ +package net.pitan76.mcpitanlib.api.client.gui.widget; + +import net.minecraft.client.gui.GuiGraphicsExtractor; +import net.minecraft.client.renderer.RenderPipelines; +import net.minecraft.client.gui.components.WidgetSprites; +import net.minecraft.client.gui.components.Button; +import net.minecraft.client.gui.components.ImageButton; +import net.minecraft.resources.Identifier; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.api.util.TextUtil; + +public class CompatibleTexturedButtonWidget extends ImageButton { + 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, Button.OnPress 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, Button.OnPress 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, Button.OnPress 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, Button.OnPress pressAction, net.minecraft.network.chat.Component text) { + super(x, y, width, height, new WidgetSprites(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, Button.OnPress 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, Button.OnPress 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, Button.OnPress 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, Button.OnPress pressAction, net.minecraft.network.chat.Component 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 extractContents(GuiGraphicsExtractor graphics, int mouseX, int mouseY, float delta) { + int i = v; + if (this.createNarrationMessage().toString().isEmpty()) { + i = v + hoveredVOffset * 2; + } else if (this.isHovered()) { + i += hoveredVOffset; + } + + graphics.blit(RenderPipelines.GUI_TEXTURED, 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..b157c5c43 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/gui/widget/RedrawableTexturedButtonWidget.java @@ -0,0 +1,46 @@ +package net.pitan76.mcpitanlib.api.client.gui.widget; + +import net.minecraft.resources.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, OnPress pressAction, net.minecraft.network.chat.Component 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 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..f09f5d8f5 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/gui/widget/SimpleListWidget.java @@ -0,0 +1,114 @@ +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.Minecraft; +import net.minecraft.client.gui.GuiGraphicsExtractor; +import net.minecraft.client.gui.components.events.GuiEventListener; +import net.minecraft.client.gui.narration.NarratableEntry; +import net.minecraft.client.gui.components.AbstractWidget; +import net.minecraft.client.gui.components.ContainerObjectSelectionList; +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 ContainerObjectSelectionList { + + public SimpleListWidget(Minecraft client, int width, int height, int top, int bottom, int itemHeight) { + this(client, width, bottom - top, top, itemHeight); + } + + public SimpleListWidget(Minecraft client, int width, int height, int y, int itemHeight) { + super(client, width, height, y, itemHeight); + this.centerListVertically = false; + } + + public void add(AbstractWidget 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 scrollBarX() { + return super.scrollBarX() + 32; + } + + @Nullable + public AbstractWidget 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.extractWidgetRenderState(args.drawObjectDM.getContext(), args.mouseX, args.mouseY, args.delta); + } + + @Environment(EnvType.CLIENT) + public static class WidgetEntry extends Entry { + protected final AbstractWidget widget; + + public WidgetEntry(AbstractWidget widget) { + this.widget = widget; + } + + public static WidgetEntry create(AbstractWidget widget) { + return new WidgetEntry(widget); + } + + @Deprecated + @Override + public void extractContent(GuiGraphicsExtractor context, int mouseX, int mouseY, boolean hovered, float deltaTicks) { + widget.extractRenderState(context, mouseX, mouseY, deltaTicks); + } + + @Deprecated + @Override + public List children() { + return ImmutableList.of(widget); + } + + @Deprecated + @Override + public List narratables() { + return ImmutableList.of(widget); + } + + public AbstractWidget 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..a8571e6c9 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/gui/widget/SimpleSliderWidget.java @@ -0,0 +1,80 @@ +package net.pitan76.mcpitanlib.api.client.gui.widget; + +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.gui.components.AbstractSliderButton; +import net.minecraft.network.chat.Component; +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 AbstractSliderButton { + protected final Function textGetter; + protected final Consumer changeCallback; + public SimpleListWidget listWidget = null; + + public SimpleSliderWidget(int x, int y, int width, int height, Component 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, Component 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, Component 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.extractRenderState(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 { + Component get(Component 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..1681b0053 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/option/CompatKeyBinding.java @@ -0,0 +1,83 @@ +package net.pitan76.mcpitanlib.api.client.option; + +import net.minecraft.client.KeyMapping; +import net.minecraft.client.input.KeyEvent; +import net.minecraft.network.chat.Component; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; + +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +public class CompatKeyBinding { + private final KeyMapping keyBinding; + public static final Map categories = new HashMap<>(); + + public CompatKeyBinding(KeyMapping keyBinding) { + this.keyBinding = keyBinding; + } + + public CompatKeyBinding(String translationKey, int defaultKeyCode, CompatIdentifier category) { + KeyMapping.Category cat; + + if (categories.containsKey(category)) { + cat = categories.get(category); + } else { + cat = KeyMapping.Category.register(category.toMinecraft()); + categories.put(category, cat); + } + + this.keyBinding = new KeyMapping(translationKey, defaultKeyCode, cat); + } + + 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"); + KeyMapping.Category cat; + + if (categories.containsKey(category)) { + cat = categories.get(category); + } else { + cat = KeyMapping.Category.register(category.toMinecraft()); + categories.put(category, cat); + } + + this.keyBinding = new KeyMapping(translationKey, defaultKeyCode, cat); + } else { + throw new IllegalArgumentException("Cannot infer category from translation key: " + translationKey); + } + } + + public String getTranslationKey() { + return keyBinding.saveString(); + } + + public Component getBoundKeyLocalizedText() { + return keyBinding.getTranslatedKeyMessage(); + } + + public int getDefaultKeyCode() { + return keyBinding.getDefaultKey().getValue(); + } + + 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 KeyMapping toMinecraft() { + return keyBinding; + } + + public KeyMapping getRaw() { + return keyBinding; + } + + public boolean matches(int keyCode, int scanCode, int modifiers) { + return keyBinding.matches(new KeyEvent(keyCode, scanCode, modifiers)); + } +} 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..141034cf5 --- /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.Options; + +public class GameOptionsWrapper { + public final Options raw; + + public GameOptionsWrapper(Options options) { + this.raw = options; + } + + public Options getRaw() { + return raw; + } + + public void write() { + raw.save(); + } +} 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..e2868c3ee --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/registry/ArchRegistryClient.java @@ -0,0 +1,179 @@ +package net.pitan76.mcpitanlib.api.client.registry; + +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.renderer.block.BlockModelResolver; +import net.minecraft.client.renderer.item.ItemModelResolver; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.client.gui.Font; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.gui.screens.inventory.MenuAccess; +import net.minecraft.client.model.geom.ModelPart; +import net.minecraft.client.particle.ParticleProvider; +import net.minecraft.client.particle.SpriteSet; +import net.minecraft.client.renderer.rendertype.RenderType; +import net.minecraft.client.renderer.blockentity.BlockEntityRenderDispatcher; +import net.minecraft.client.renderer.blockentity.BlockEntityRenderer; +import net.minecraft.client.renderer.blockentity.state.BlockEntityRenderState; +import net.minecraft.client.renderer.entity.EntityRenderDispatcher; +import net.minecraft.client.renderer.entity.EntityRendererProvider; +import net.minecraft.client.model.geom.ModelLayerLocation; +import net.minecraft.client.model.geom.EntityModelSet; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.client.renderer.texture.TextureAtlas; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.level.material.Fluid; +import net.minecraft.core.particles.ParticleOptions; +import net.minecraft.core.particles.ParticleType; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.Identifier; +import net.minecraft.util.RandomSource; + +import java.util.List; +import java.util.function.Supplier; + +@Deprecated +@Environment(EnvType.CLIENT) +public class ArchRegistryClient { + public static > void registerScreen(MenuType type, ScreenFactory factory) { + CompatRegistryClient.registerScreen(type, factory::create); + } + + public interface ScreenFactory> { + S create(H handler, Inventory inventory, Component text); + } + + public static void registerParticle(ParticleType type, ParticleProvider factory) { + CompatRegistryClient.registerParticle(type, factory); + } + + public static void registerParticle(ParticleType type, DeferredParticleProvider provider) { + CompatRegistryClient.registerParticle(type, (spriteSet -> provider.create(new ExtendedSpriteSet() { + @Override + public TextureAtlas getAtlas() { + return spriteSet.getAtlas(); + } + + @Override + public List getSprites() { + return spriteSet.getSprites(); + } + + @Override + public TextureAtlasSprite get(int index, int max) { + return spriteSet.get(index, max); + } + + @Override + public TextureAtlasSprite get(RandomSource random) { + return spriteSet.get(random); + } + + @Override + public TextureAtlasSprite first() { + return spriteSet.first(); + } + }))); + } + + public static void registerEntityRenderer(Supplier> type, EntityRendererProvider provider) { + CompatRegistryClient.registerEntityRenderer(type, provider); + } + + @FunctionalInterface + public interface DeferredParticleProvider { + ParticleProvider create(ExtendedSpriteSet spriteSet); + } + + public interface ExtendedSpriteSet extends SpriteSet { + TextureAtlas getAtlas(); + + List getSprites(); + } + + public static void registryClientSpriteAtlasTexture(Identifier identifier) { + //registryClientSprite(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, identifier); + } + + public static void registryClientSpriteAtlasTexture(TextureAtlasSprite sprite) { + //registryClientSprite(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, sprite); + } + + public static void registryClientSprite(Identifier atlasId, Identifier identifier) { + // ~1.19.2 + } + + public static void registryClientSprite(Identifier atlasId, TextureAtlasSprite sprite) { + // ~1.19.2 + } + + public static void registerBlockEntityRenderer(BlockEntityType type, BlockEntityRendererFactory provider) { + CompatRegistryClient.registerBlockEntityRenderer(type, (ctx) -> provider.create(new BlockEntityRendererFactory.Context(ctx.getRenderDispatcher(), ctx.getRenderManager(), ctx.getItemModelManager(), ctx.getEntityRenderDispatcher(), ctx.getLayerRenderDispatcher(), ctx.getTextRenderer()))); + } + + @FunctionalInterface + public interface BlockEntityRendererFactory { + BlockEntityRenderer create(BlockEntityRendererFactory.Context ctx); + + class Context { + private final BlockEntityRenderDispatcher renderDispatcher; + private final BlockModelResolver renderManager; + private final ItemModelResolver itemRenderer; + private final EntityRenderDispatcher entityRenderDispatcher; + private final EntityModelSet layerRenderDispatcher; + private final Font textRenderer; + + public Context(BlockEntityRenderDispatcher renderDispatcher, BlockModelResolver renderManager, ItemModelResolver itemRenderer, EntityRenderDispatcher entityRenderDispatcher, EntityModelSet layerRenderDispatcher, Font 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 BlockModelResolver getRenderManager() { + return this.renderManager; + } + + public EntityRenderDispatcher getEntityRenderDispatcher() { + return this.entityRenderDispatcher; + } + + public ItemModelResolver getItemRenderer() { + return this.itemRenderer; + } + + public EntityModelSet getLayerRenderDispatcher() { + return this.layerRenderDispatcher; + } + + public ModelPart getLayerModelPart(ModelLayerLocation modelLayer) { + return this.layerRenderDispatcher.bakeLayer(modelLayer); + } + + public Font getTextRenderer() { + return this.textRenderer; + } + } + } + + + public static void registerRenderTypeBlock(RenderType layer, Block block) { + CompatRegistryClient.registerRenderTypeBlock(layer, block); + } + + public static void registerRenderTypeFluid(RenderType layer, Fluid fluid) { + CompatRegistryClient.registerRenderTypeFluid(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..cad03cf8b --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/registry/CompatRegistryClient.java @@ -0,0 +1,258 @@ +package net.pitan76.mcpitanlib.api.client.registry; + +import dev.architectury.injectables.annotations.ExpectPlatform; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.color.block.BlockTintSource; +import net.minecraft.client.renderer.block.BlockModelResolver; +import net.minecraft.client.resources.model.sprite.SpriteGetter; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.client.gui.Font; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.gui.screens.inventory.MenuAccess; +import net.minecraft.client.renderer.item.ItemModelResolver; +import net.minecraft.client.model.geom.ModelPart; +import net.minecraft.client.particle.ParticleProvider; +import net.minecraft.client.particle.SpriteSet; +import net.minecraft.client.renderer.chunk.ChunkSectionLayer; +import net.minecraft.client.renderer.rendertype.RenderType; +import net.minecraft.client.renderer.rendertype.RenderTypes; +import net.minecraft.client.renderer.blockentity.BlockEntityRenderDispatcher; +import net.minecraft.client.renderer.blockentity.BlockEntityRenderer; +import net.minecraft.client.renderer.blockentity.state.BlockEntityRenderState; +import net.minecraft.client.renderer.entity.EntityRenderDispatcher; +import net.minecraft.client.renderer.entity.EntityRendererProvider; +import net.minecraft.client.model.geom.ModelLayerLocation; +import net.minecraft.client.model.geom.EntityModelSet; +import net.minecraft.client.renderer.PlayerSkinRenderCache; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.client.renderer.texture.TextureAtlas; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.level.material.Fluid; +import net.minecraft.core.particles.ParticleOptions; +import net.minecraft.core.particles.ParticleType; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.Identifier; +import net.pitan76.mcpitanlib.MCPitanLib; +import net.pitan76.mcpitanlib.api.client.color.CompatBlockColorProvider; +import net.pitan76.mcpitanlib.api.client.gui.screen.SimpleHandledScreen; +import net.pitan76.mcpitanlib.api.client.render.CompatRenderLayer; +import net.pitan76.mcpitanlib.api.client.render.EntityModelLayerContext; +import net.pitan76.mcpitanlib.api.gui.SimpleScreenHandler; +import net.pitan76.mcpitanlib.api.text.TextComponent; +import net.pitan76.mcpitanlib.api.util.inventory.CompatPlayerInventory; + +import java.util.List; +import java.util.function.Supplier; + +@Environment(EnvType.CLIENT) +public class CompatRegistryClient { + public static > void registerScreen(MenuType type, ScreenFactory factory) { + registerScreen(MCPitanLib.MOD_ID, type, factory); + } + + public static & MenuAccess> void registerScreen(MenuType type, ScreenFactory2 factory) { + registerScreen(MCPitanLib.MOD_ID, type, factory); + } + + @ExpectPlatform + public static > void registerScreen(String modId, MenuType type, ScreenFactory factory) { + throw new AssertionError(); + } + + public static & MenuAccess> void registerScreen(String modId, MenuType type, ScreenFactory2 factory) { + registerScreen(modId, type, factory); + } + + public interface ScreenFactory> { + S create(H handler, Inventory inventory, Component text); + } + + public interface ScreenFactory2 & MenuAccess> extends ScreenFactory { + @Override + default S create(H handler, Inventory inventory, Component text) { + return create(handler, new CompatPlayerInventory(inventory), new TextComponent(text)); + } + + S create(H handler, CompatPlayerInventory inventory, TextComponent text); + } + + @ExpectPlatform + public static void registerParticle(ParticleType type, ParticleProvider factory) { + throw new AssertionError(); + } + + @ExpectPlatform + public static void registerParticle(ParticleType type, DeferredParticleProvider provider) { + throw new AssertionError(); + } + + @ExpectPlatform + public static void registerEntityModelLayer(ModelLayerLocation layer, EntityModelLayerContext context) { + throw new AssertionError(); + } + + @ExpectPlatform + public static void registerEntityRenderer(Supplier> type, EntityRendererProvider provider) { + throw new AssertionError(); + } + + @FunctionalInterface + public interface DeferredParticleProvider { + ParticleProvider create(ExtendedSpriteSet spriteSet); + } + + public interface ExtendedSpriteSet extends SpriteSet { + TextureAtlas getAtlas(); + + List getSprites(); + } + + public static void registryClientSpriteAtlasTexture(Identifier identifier) { + //registryClientSprite(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, identifier); + } + + public static void registryClientSpriteAtlasTexture(TextureAtlasSprite sprite) { + //registryClientSprite(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, sprite); + } + + public static void registryClientSprite(Identifier atlasId, Identifier identifier) { + // ~1.19.2 + } + + public static void registryClientSprite(Identifier atlasId, TextureAtlasSprite sprite) { + // ~1.19.2 + } + + @ExpectPlatform + public static void registerBlockEntityRenderer(BlockEntityType type, BlockEntityRendererFactory provider) { + throw new AssertionError(); + } + + @FunctionalInterface + public interface BlockEntityRendererFactory { + BlockEntityRenderer create(Context ctx); + + class Context { + private final BlockEntityRenderDispatcher renderDispatcher; + private final BlockModelResolver renderManager; + private final ItemModelResolver itemModelManager; + private final EntityRenderDispatcher entityRenderDispatcher; + private final EntityModelSet layerRenderDispatcher; + private final Font textRenderer; + private final SpriteGetter spriteHolder; + + private final PlayerSkinRenderCache playerSkinRenderCache; + + public Context(BlockEntityRenderDispatcher renderDispatcher, BlockModelResolver renderManager, ItemModelResolver itemModelManager, EntityRenderDispatcher entityRenderDispatcher, EntityModelSet layerRenderDispatcher, Font textRenderer, SpriteGetter spriteHolder, PlayerSkinRenderCache playerSkinRenderCache) { + this.renderDispatcher = renderDispatcher; + this.renderManager = renderManager; + this.itemModelManager = itemModelManager; + this.entityRenderDispatcher = entityRenderDispatcher; + this.layerRenderDispatcher = layerRenderDispatcher; + this.textRenderer = textRenderer; + this.spriteHolder = spriteHolder; + this.playerSkinRenderCache = playerSkinRenderCache; + } + + public BlockEntityRenderDispatcher getRenderDispatcher() { + return this.renderDispatcher; + } + + public BlockModelResolver getRenderManager() { + return this.renderManager; + } + + public EntityRenderDispatcher getEntityRenderDispatcher() { + return this.entityRenderDispatcher; + } + + public ItemModelResolver getItemModelManager() { + return itemModelManager; + } + + public EntityModelSet getLayerRenderDispatcher() { + return this.layerRenderDispatcher; + } + + public ModelPart getLayerModelPart(ModelLayerLocation modelLayer) { + return this.layerRenderDispatcher.bakeLayer(modelLayer); + } + + public Font getTextRenderer() { + return this.textRenderer; + } + + public SpriteGetter getSpriteHolder() { + return spriteHolder; + } + + public PlayerSkinRenderCache getPlayerSkinRenderCache() { + return playerSkinRenderCache; + } + } + } + + + public static void registerRenderTypeBlock(RenderType layer, Block block) { + ChunkSectionLayer blockRenderLayer = null; + if (layer == RenderTypes.cutoutMovingBlock()) { + blockRenderLayer = ChunkSectionLayer.CUTOUT; + } else if (layer == RenderTypes.glintTranslucent()) { + blockRenderLayer = ChunkSectionLayer.TRANSLUCENT; + } else if (layer == RenderTypes.solidMovingBlock()) { + blockRenderLayer = ChunkSectionLayer.SOLID; + } + + if (blockRenderLayer == null) return; + +// ChunkSectionLayerMap.register(blockRenderLayer, block); + } + + public static void registerRenderTypeFluid(RenderType layer, Fluid fluid) { + ChunkSectionLayer blockRenderLayer = null; + if (layer == RenderTypes.cutoutMovingBlock()) { + blockRenderLayer = ChunkSectionLayer.CUTOUT; + } else if (layer == RenderTypes.glintTranslucent()) { + blockRenderLayer = ChunkSectionLayer.TRANSLUCENT; + } else if (layer == RenderTypes.solidMovingBlock()) { + blockRenderLayer = ChunkSectionLayer.SOLID; + } + + if (blockRenderLayer == null) return; + +// ChunkSectionLayerMap.register(blockRenderLayer, fluid); + } + + public static void registerCutoutBlock(Block block) { + registerRenderTypeBlock(RenderTypes.cutoutMovingBlock(), block); + } + + @ExpectPlatform + public static void registerCompatBlockEntityRenderer(BlockEntityType type, BlockEntityRendererFactory provider) { + + } + + 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(List provider, Block... blocks) { + throw new AssertionError(); + } + + public static void registerColorProviderBlock(CompatBlockColorProvider provider, Block... blocks) { + registerColorProviderBlock(provider.toTintSource(), 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..56564d8e1 --- /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.renderer.entity.EntityRenderer; +import net.minecraft.client.renderer.entity.ThrownItemRenderer; +import net.minecraft.world.entity.EntityType; + +import java.util.function.Supplier; + +public class EntityRendererRegistry { + public static void registerEntityRendererAsFlyingItem(Supplier> entityType) { + CompatRegistryClient.registerEntityRenderer(entityType, (ctx -> (EntityRenderer) new ThrownItemRenderer<>(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..dca6d41e1 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/registry/KeybindingRegistry.java @@ -0,0 +1,39 @@ +package net.pitan76.mcpitanlib.api.client.registry; + +import dev.architectury.injectables.annotations.ExpectPlatform; +import net.minecraft.client.KeyMapping; +import net.minecraft.resources.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 { + @ExpectPlatform + public static void register(KeyMapping keyBinding) { + + } + + public static void register(KeyMapping keyBinding, ClientTickEventRegistry.Client client) { + register(keyBinding); + ClientTickEventRegistry.registerPost(client); + } + + public static void registerOnLevel(KeyMapping keyBinding, ClientTickEventRegistry.ClientLevel level) { + register(keyBinding); + ClientTickEventRegistry.registerLevelPost(level); + } + + public static void registerWithNetwork(KeyMapping keyBinding, Identifier identifier) { + register(keyBinding, client -> { + if (keyBinding.consumeClick()) + ClientNetworking.send(identifier, PacketByteUtil.create()); + }); + } + + public static void registerOnLevelWithNetwork(KeyMapping keyBinding, Identifier identifier) { + registerOnLevel(keyBinding, client -> { + if (keyBinding.consumeClick()) + 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..c6279645b --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/registry/v2/KeybindingRegistry.java @@ -0,0 +1,24 @@ +package net.pitan76.mcpitanlib.api.client.registry.v2; + +import net.minecraft.client.KeyMapping; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; + +public class KeybindingRegistry extends net.pitan76.mcpitanlib.api.client.registry.KeybindingRegistry { + + public static void registerWithNetwork(KeyMapping keyBinding, CompatIdentifier identifier) { + registerWithNetwork(keyBinding, identifier.toMinecraft()); + } + + public static void registerOnLevelWithNetwork(KeyMapping keyBinding, CompatIdentifier identifier) { + registerOnLevelWithNetwork(keyBinding, identifier.toMinecraft()); + } + + public static void registerWithNetwork(String translationKey, int code, String category, CompatIdentifier identifier) { + registerWithNetwork(new KeyMapping(translationKey, code, KeyMapping.Category.register(CompatIdentifier.of(category).toMinecraft())), identifier); + } + + public static void registerOnLevelWithNetwork(String translationKey, int code, String category, CompatIdentifier identifier) { + // TODO: categoryの互換性 + registerOnLevelWithNetwork(new KeyMapping(translationKey, code, KeyMapping.Category.register(CompatIdentifier.of(category).toMinecraft())), 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/CompatMatrix3x2fStack.java b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/CompatMatrix3x2fStack.java new file mode 100644 index 000000000..10fefbc48 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/CompatMatrix3x2fStack.java @@ -0,0 +1,48 @@ +package net.pitan76.mcpitanlib.api.client.render; + +import net.pitan76.mcpitanlib.api.util.MathUtil; +import org.joml.Matrix3x2fStack; + +public class CompatMatrix3x2fStack extends CompatMatrixStack { + private final Matrix3x2fStack matrices; + + public CompatMatrix3x2fStack(Matrix3x2fStack matrices) { + super(null); + this.matrices = matrices; + } + + @Deprecated + public Matrix3x2fStack get3x2fRaw() { + return matrices; + } + + public CompatMatrix3x2fStack push() { + get3x2fRaw().pushMatrix(); + return this; + } + + public CompatMatrix3x2fStack pop() { + get3x2fRaw().popMatrix(); + return this; + } + + public CompatMatrix3x2fStack translate(double x, double y, double z) { + get3x2fRaw().translate((float) x, (float) y); + return this; + } + + @Override + public CompatMatrixStack translate(float x, float y, float z) { + get3x2fRaw().translate(x, y); + return this; + } + + public CompatMatrix3x2fStack scale(float x, float y, float z) { + get3x2fRaw().scale(x, y); + return this; + } + + public CompatMatrix3x2fStack multiply(MathUtil.RotationAxisType type, float deg) { + return this; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/CompatMatrixStack.java b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/CompatMatrixStack.java new file mode 100644 index 000000000..ad3962cac --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/CompatMatrixStack.java @@ -0,0 +1,51 @@ +package net.pitan76.mcpitanlib.api.client.render; + +import net.pitan76.mcpitanlib.api.util.MathUtil; +import net.pitan76.mcpitanlib.api.util.client.MatrixStackUtil; + +public class CompatMatrixStack { + private final com.mojang.blaze3d.vertex.PoseStack matrices; + + public CompatMatrixStack(com.mojang.blaze3d.vertex.PoseStack matrices) { + this.matrices = matrices; + } + + public static CompatMatrixStack of(com.mojang.blaze3d.vertex.PoseStack matrixStack) { + return new CompatMatrixStack(matrixStack); + } + + @Deprecated + public com.mojang.blaze3d.vertex.PoseStack getRaw() { + return matrices; + } + + public CompatMatrixStack push() { + MatrixStackUtil.push(getRaw()); + return this; + } + + public CompatMatrixStack pop() { + MatrixStackUtil.pop(getRaw()); + return this; + } + + public CompatMatrixStack translate(double x, double y, double z) { + MatrixStackUtil.translate(getRaw(), x, y, z); + return this; + } + + public CompatMatrixStack translate(float x, float y, float z) { + getRaw().translate(x, y, z); + return this; + } + + public CompatMatrixStack scale(float x, float y, float z) { + MatrixStackUtil.scale(getRaw(), x, y, z); + return this; + } + + public CompatMatrixStack multiply(MathUtil.RotationAxisType type, float deg) { + MatrixStackUtil.multiply(getRaw(), type, deg); + return this; + } +} 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..5cdf9e8f6 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/CompatRenderLayer.java @@ -0,0 +1,46 @@ +package net.pitan76.mcpitanlib.api.client.render; + +import net.minecraft.client.renderer.rendertype.RenderType; +import net.minecraft.client.renderer.rendertype.RenderTypes; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; + +public class CompatRenderLayer { + public static final CompatRenderLayer CUTOUT = new CompatRenderLayer(RenderTypes.cutoutMovingBlock()); + public static final CompatRenderLayer CUTOUT_MIPPED = new CompatRenderLayer(RenderTypes.cutoutMovingBlock()); + public static final CompatRenderLayer TRANSLUCENT = new CompatRenderLayer(RenderTypes.glintTranslucent()); + public static final CompatRenderLayer TRANSLUCENT_MOVING_BLOCK = new CompatRenderLayer(RenderTypes.translucentMovingBlock()); + public static final CompatRenderLayer SOLID = new CompatRenderLayer(RenderTypes.solidMovingBlock()); + public static final CompatRenderLayer LINES = new CompatRenderLayer(RenderTypes.lines()); + public static final CompatRenderLayer LINE_STRIP = new CompatRenderLayer(RenderTypes.linesTranslucent()); + public static final CompatRenderLayer GLINT = new CompatRenderLayer(RenderTypes.glint()); + + public final RenderType layer; + + public CompatRenderLayer(RenderType layer) { + this.layer = layer; + } + + public RenderType raw() { + return layer; + } + + public static CompatRenderLayer getEntityCutout(CompatIdentifier id) { + return new CompatRenderLayer(RenderTypes.entityCutoutCull(id.toMinecraft())); + } + + public static CompatRenderLayer getEntityCutoutNoCull(CompatIdentifier id) { + return new CompatRenderLayer(RenderTypes.entityCutout(id.toMinecraft())); + } + + public static CompatRenderLayer getEntityTranslucent(CompatIdentifier id) { + return new CompatRenderLayer(RenderTypes.entityTranslucent(id.toMinecraft())); + } + + public static CompatRenderLayer getArmorCutoutNoCull(CompatIdentifier id) { + return new CompatRenderLayer(RenderTypes.armorCutoutNoCull(id.toMinecraft())); + } + + public static CompatRenderLayer getEntitySolid(CompatIdentifier id) { + return new CompatRenderLayer(RenderTypes.entitySolid(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..8b50aeb1a --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/DrawObjectDM.java @@ -0,0 +1,110 @@ +package net.pitan76.mcpitanlib.api.client.render; + +import net.minecraft.client.gui.GuiGraphicsExtractor; +import net.minecraft.client.gui.screens.Screen; +import com.mojang.blaze3d.vertex.PoseStack; +import net.minecraft.network.chat.Component; +import net.pitan76.mcpitanlib.api.text.TextComponent; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.api.util.client.ScreenUtil.RendererUtil; +import org.joml.Matrix3x2fStack; + +import java.util.List; + +public class DrawObjectDM { + private PoseStack stack; + private Matrix3x2fStack matrix3x2fStack; + private GuiGraphicsExtractor context; + + private Screen screen = null; + + public DrawObjectDM(GuiGraphicsExtractor context) { + this.context = context; + this.matrix3x2fStack = context.pose(); + } + + public DrawObjectDM(Matrix3x2fStack matrix3x2fStack) { + this.matrix3x2fStack = matrix3x2fStack; + } + + public DrawObjectDM(PoseStack stack) { + this.stack = stack; + } + + public DrawObjectDM(GuiGraphicsExtractor context, Screen screen) { + this(context); + this.screen = screen; + } + + public GuiGraphicsExtractor getContext() { + return context; + } + + public PoseStack getStack() { + return stack; + } + + public Screen getScreen() { + return screen; + } + + public void setContext(GuiGraphicsExtractor context) { + this.context = context; + } + + public void setStack(PoseStack 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(Component text, int x, int y) { + RendererUtil.drawText(RendererUtil.getTextRenderer(), this, text, x, y); + } + + public void drawTooltip(Component 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 drawTooltip(List texts, int x, int y) { + RendererUtil.drawTooltip2(this, texts, 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; + } + + public CompatMatrixStack getMatrixStack() { + return new CompatMatrix3x2fStack(context.pose()); + } +} 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..c69abb2f5 --- /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.renderer.texture.OverlayTexture; +import com.mojang.blaze3d.vertex.VertexConsumer; +import com.mojang.blaze3d.vertex.PoseStack; +import net.pitan76.mcpitanlib.api.util.client.render.VertexConsumerUtil; +import org.joml.Matrix3f; +import org.joml.Matrix4f; + +public class DrawObjectMV { + private final PoseStack stack; + private final VertexConsumer buffer; + + public DrawObjectMV(PoseStack stack, VertexConsumer buffer) { + this.stack = stack; + this.buffer = buffer; + } + + public DrawObjectMV(PoseStack stack) { + this(stack, null); + } + + public DrawObjectMV(VertexConsumer buffer) { + this(null, buffer); + } + + public PoseStack 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.last().pose(); + + return matrix4f; + } + + public Matrix3f getMatrix3f() { + if (matrix3f == null) + matrix3f = stack.last().normal(); + + 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..6655fb13e --- /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.geom.builders.MeshDefinition; + +public class EntityModelLayerContext { + private final MeshDefinition data; + private final int width; + private final int height; + + public EntityModelLayerContext(MeshDefinition 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 MeshDefinition 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..0d631b3d6 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/block/entity/CompatBlockEntityRenderer.java @@ -0,0 +1,45 @@ +package net.pitan76.mcpitanlib.api.client.render.block.entity; + +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.blockentity.BlockEntityRenderer; +import net.minecraft.client.renderer.blockentity.state.BlockEntityRenderState; +import net.minecraft.client.renderer.SubmitNodeCollector; +import com.mojang.blaze3d.vertex.PoseStack; +import net.minecraft.client.renderer.state.level.CameraRenderState; +import net.minecraft.world.phys.Vec3; +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); + + default void render(T entity, float tickProgress, PoseStack matrices, MultiBufferSource vertexConsumers, int light, int overlay, Vec3 cameraPos) { + render(new BlockEntityRenderEvent<>(this, entity, tickProgress, matrices, vertexConsumers, light, overlay)); + } + + @Override + default void submit(S state, PoseStack matrices, SubmitNodeCollector queue, CameraRenderState cameraState) { + render(new BlockEntityRenderEvent<>(this, state, matrices, queue, cameraState)); + } + + default boolean rendersOutsideBoundingBoxOverride(T blockEntity) { + return BlockEntityRenderer.super.shouldRenderOffScreen(); + } + + default int getRenderDistanceOverride() { + return BlockEntityRenderer.super.getViewDistance(); + } + + @Deprecated + @Override + default boolean shouldRenderOffScreen() { + return rendersOutsideBoundingBoxOverride(null); + } + + @Deprecated + @Override + default int getViewDistance() { + 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..6928a24c4 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/block/entity/event/BlockEntityRenderEvent.java @@ -0,0 +1,204 @@ +package net.pitan76.mcpitanlib.api.client.render.block.entity.event; + +import net.minecraft.client.renderer.item.ItemModelResolver; +import net.minecraft.client.renderer.state.level.CameraRenderState; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.rendertype.RenderType; +import com.mojang.blaze3d.vertex.VertexConsumer; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.blockentity.state.BlockEntityRenderState; +import net.minecraft.client.renderer.SubmitNodeCollector; +import com.mojang.blaze3d.vertex.PoseStack; +import net.minecraft.world.item.ItemStack; +import net.minecraft.core.BlockPos; +import net.pitan76.mcpitanlib.api.client.registry.CompatRegistryClient; +import net.pitan76.mcpitanlib.api.client.render.CompatMatrixStack; +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 PoseStack matrices; + public MultiBufferSource vertexConsumers; + int light; + int overlay; + + public BlockEntityRenderEvent(T blockEntity, float tickDelta, PoseStack matrices, MultiBufferSource vertexConsumers, int light, int overlay) { + this.blockEntity = blockEntity; + this.tickDelta = tickDelta; + this.matrices = matrices; + this.vertexConsumers = vertexConsumers; + this.light = light; + this.overlay = overlay; + } + + private BlockEntityRenderState state; + private SubmitNodeCollector queue; + private CameraRenderState cameraState; + + + public BlockEntityRenderEvent(S state, PoseStack matrices, SubmitNodeCollector queue, CameraRenderState cameraState) { + this.state = state; + this.queue = queue; + this.cameraState = cameraState; + + this.matrices = matrices; + this.queue = queue; + this.cameraState = cameraState; + this.tickDelta = Minecraft.getInstance().getDeltaTracker().getGameTimeDeltaTicks(); + BlockEntity blockEntity = state.blockEntityType.getBlockEntity(Minecraft.getInstance().level, state.blockPos); + if (blockEntity instanceof CompatBlockEntity) { + this.blockEntity = (T) blockEntity; + } else { + //throw new IllegalArgumentException("BlockEntityRenderEvent: BlockEntity is not an instance of CompatBlockEntity"); + } + + this.vertexConsumers = Minecraft.getInstance().renderBuffers().bufferSource(); + this.light = state.lightCoords; + if (state.breakProgress != null) + this.overlay = state.breakProgress.progress(); + else + this.overlay = 0; + } + + public T getBlockEntity() { + return blockEntity; + } + + public PoseStack getMatrices() { + return matrices; + } + + public float getTickDelta() { + return tickDelta; + } + + public int getLight() { + return light; + } + + public int getOverlay() { + return overlay; + } + + public VertexConsumer getVertexConsumer(RenderType layer) { + return vertexConsumers.getBuffer(layer); + } + + public VertexConsumer getVertexConsumer(CompatRenderLayer layer) { + return getVertexConsumer(layer.raw()); + } + + public MultiBufferSource 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 CompatMatrixStack getCompatMatrices() { + return CompatMatrixStack.of(matrices); + } + + public ItemModelResolver 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.last().pose(); + + return matrix4f; + } + + public Matrix3f getMatrix3f() { + if (matrix3f == null) + matrix3f = matrices.last().normal(); + + return matrix3f; + } + + public BlockPos getPos() { + return state.blockPos; + } + + 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, PoseStack matrices, MultiBufferSource 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 BlockEntityRenderEvent(CompatBlockEntityRenderer renderer, BlockEntityRenderState state, PoseStack matrices, SubmitNodeCollector queue, CameraRenderState cameraState) { + this(state, matrices, queue, cameraState); + 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()); + } + + @Deprecated + public SubmitNodeCollector getQueue() { + return queue; + } + + @Deprecated + public BlockEntityRenderState getState() { + return state; + } + + @Deprecated + public CameraRenderState getCameraState() { + return cameraState; + } +} 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..6839a8f33 --- /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.renderer.blockentity.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..3bee38c06 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/block/entity/v2/CompatBlockEntityRenderer.java @@ -0,0 +1,25 @@ +package net.pitan76.mcpitanlib.api.client.render.block.entity.v2; + +import net.minecraft.client.renderer.blockentity.state.BlockEntityRenderState; +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; + } + + @Override + public BlockEntityRenderState createRenderState() { + return new BlockEntityRenderState(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/handledscreen/CharEventArgs.java b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/handledscreen/CharEventArgs.java new file mode 100644 index 000000000..934f2a628 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/handledscreen/CharEventArgs.java @@ -0,0 +1,25 @@ +package net.pitan76.mcpitanlib.api.client.render.handledscreen; + +public class CharEventArgs { + private final int character; + + public CharEventArgs(char character, int modifiers) { + this.character = character; + } + + public CharEventArgs(int codepoint) { + this.character = codepoint; + } + + public int getCharacter() { + return character; + } + + public char getChar() { + return (char) character; + } + + public int getModifiers() { + return 0; + } +} 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/MouseButtonArgs.java b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/handledscreen/MouseButtonArgs.java new file mode 100644 index 000000000..f1560c4f9 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/handledscreen/MouseButtonArgs.java @@ -0,0 +1,38 @@ +package net.pitan76.mcpitanlib.api.client.render.handledscreen; + +import net.minecraft.client.input.MouseButtonInfo; + +public class MouseButtonArgs { + public final double mouseX, mouseY; + public MouseButtonInfo buttonInfo = null; + + public MouseButtonArgs(double mouseX, double mouseY, MouseButtonInfo buttonInfo) { + this.mouseX = mouseX; + this.mouseY = mouseY; + this.buttonInfo = buttonInfo; + } + + public MouseButtonArgs(double mouseX, double mouseY, int button) { + this.mouseX = mouseX; + this.mouseY = mouseY; + this.buttonInfo = new MouseButtonInfo(button, 0); + } + + public double getX() { + return mouseX; + } + + public double getY() { + return mouseY; + } + + public int getButton() { + if (getButtonInfo() == null) return -1; + return getButtonInfo().button(); + } + + @Deprecated + public MouseButtonInfo getButtonInfo() { + return buttonInfo; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/handledscreen/MouseClickedArgs.java b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/handledscreen/MouseClickedArgs.java new file mode 100644 index 000000000..5e3a494c0 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/handledscreen/MouseClickedArgs.java @@ -0,0 +1,26 @@ +package net.pitan76.mcpitanlib.api.client.render.handledscreen; + +import net.minecraft.client.input.MouseButtonInfo; + +public class MouseClickedArgs extends MouseButtonArgs { + public boolean doubleClick; + + public MouseClickedArgs(double mouseX, double mouseY, MouseButtonInfo buttonInfo, boolean doubleClick) { + super(mouseX, mouseY, buttonInfo); + this.doubleClick = doubleClick; + } + + public MouseClickedArgs(double mouseX, double mouseY, int button, boolean doubleClick) { + super(mouseX, mouseY, button); + this.doubleClick = doubleClick; + } + + public MouseClickedArgs(double mouseX, double mouseY, int button) { + this(mouseX, mouseY, button, false); + } + + @Deprecated + public boolean isDoubleClick() { + return doubleClick; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/handledscreen/MouseDraggedArgs.java b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/handledscreen/MouseDraggedArgs.java new file mode 100644 index 000000000..f7889533e --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/handledscreen/MouseDraggedArgs.java @@ -0,0 +1,29 @@ +package net.pitan76.mcpitanlib.api.client.render.handledscreen; + +import net.minecraft.client.input.MouseButtonInfo; + +public class MouseDraggedArgs extends MouseButtonArgs { + + public final double dx; + public final double dy; + + public MouseDraggedArgs(double mouseX, double mouseY, MouseButtonInfo buttonInfo, double dx, double dy) { + super(mouseX, mouseY, buttonInfo); + this.dx = dx; + this.dy = dy; + } + + public MouseDraggedArgs(double mouseX, double mouseY, int button, double dx, double dy) { + super(mouseX, mouseY, button); + this.dx = dx; + this.dy = dy; + } + + public double getDeltaX() { + return dx; + } + + public double getDeltaY() { + return dy; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/handledscreen/MouseReleasedArgs.java b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/handledscreen/MouseReleasedArgs.java new file mode 100644 index 000000000..9fc2948a6 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/handledscreen/MouseReleasedArgs.java @@ -0,0 +1,14 @@ +package net.pitan76.mcpitanlib.api.client.render.handledscreen; + +import net.minecraft.client.input.MouseButtonInfo; + +public class MouseReleasedArgs extends MouseButtonArgs { + + public MouseReleasedArgs(double mouseX, double mouseY, MouseButtonInfo buttonInfo) { + super(mouseX, mouseY, buttonInfo); + } + + public MouseReleasedArgs(double mouseX, double mouseY, int button) { + super(mouseX, mouseY, button); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/handledscreen/MouseScrolledArgs.java b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/handledscreen/MouseScrolledArgs.java new file mode 100644 index 000000000..0daf0c5b4 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/handledscreen/MouseScrolledArgs.java @@ -0,0 +1,37 @@ +package net.pitan76.mcpitanlib.api.client.render.handledscreen; + +public class MouseScrolledArgs { + private final double mouseX; + private final double mouseY; + private final double scrollX; + private final double scrollY; + private final double amount; + + public MouseScrolledArgs(double mouseX, double mouseY, double scrollX, double scrollY) { + this.mouseX = mouseX; + this.mouseY = mouseY; + this.scrollX = scrollX; + this.scrollY = scrollY; + this.amount = Math.sqrt(scrollX * scrollX + scrollY * scrollY); + } + + public double getMouseX() { + return mouseX; + } + + public double getMouseY() { + return mouseY; + } + + public double getScrollX() { + return scrollX; + } + + public double getScrollY() { + return scrollY; + } + + public double getAmount() { + return amount; + } +} 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..0e64f0485 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/command/CommandRegistry.java @@ -0,0 +1,106 @@ +package net.pitan76.mcpitanlib.api.command; + +import com.mojang.brigadier.builder.ArgumentBuilder; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import dev.architectury.injectables.annotations.ExpectPlatform; +import net.minecraft.commands.CommandBuildContext; +import net.minecraft.commands.Commands; +import net.minecraft.commands.CommandSourceStack; +import net.pitan76.mcpitanlib.api.command.argument.*; +import net.pitan76.mcpitanlib.api.event.*; + +import java.util.Map; + +public class CommandRegistry { + + @Deprecated + public static CommandBuildContext latestCommandRegistryAccess; + + @ExpectPlatform + public static void register(String name, LiteralCommand command) { + + } + + @ExpectPlatform + public static void register(LiteralArgumentBuilder builder) { + + } + + @Deprecated + public 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 = Commands.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 = Commands.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..8e7326e64 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/command/CommandSettings.java @@ -0,0 +1,43 @@ +package net.pitan76.mcpitanlib.api.command; + +import net.minecraft.server.permissions.Permission; +import net.minecraft.server.permissions.PermissionLevel; +import net.minecraft.commands.CommandSourceStack; + +public class CommandSettings { + private int permissionLevel = -1; + private ICustom iCustom = null; + + private Permission.HasCommandLevel _level = null; + + public boolean requires(CommandSourceStack source) { + if (customRequires(source)) { + if (permissionLevel == -1) return true; + if (_level == null) + _level = new Permission.HasCommandLevel(PermissionLevel.byId(permissionLevel)); + + return source.permissions().hasPermission(_level); + } + return false; + } + + private boolean customRequires(CommandSourceStack 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(CommandSourceStack 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..992b43c29 --- /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.world.level.block.Block; +import net.minecraft.commands.arguments.blocks.BlockStateArgument; +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 BlockStateArgument getArgumentType() { + return BlockStateArgument.block(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..e30a2651b --- /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.commands.arguments.EntityArgument; +import net.minecraft.world.entity.Entity; +import net.pitan76.mcpitanlib.api.event.EntitiesCommandEvent; +import net.pitan76.mcpitanlib.api.event.ServerCommandEvent; + +public abstract class EntitiesCommand extends RequiredCommand { + @Override + public EntityArgument getArgumentType() { + return EntityArgument.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..0af7e0e0c --- /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.commands.arguments.EntityArgument; +import net.minecraft.world.entity.Entity; +import net.pitan76.mcpitanlib.api.event.EntityCommandEvent; +import net.pitan76.mcpitanlib.api.event.ServerCommandEvent; + +public abstract class EntityCommand extends RequiredCommand { + @Override + public EntityArgument getArgumentType() { + return EntityArgument.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..aeaac8193 --- /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.commands.arguments.item.ItemArgument; +import net.minecraft.world.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 ItemArgument getArgumentType() { + return ItemArgument.item(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..c9e444c7d --- /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.commands.arguments.EntityArgument; +import net.minecraft.world.entity.Entity; +import net.pitan76.mcpitanlib.api.event.PlayerCommandEvent; +import net.pitan76.mcpitanlib.api.event.ServerCommandEvent; + +public abstract class PlayerCommand extends RequiredCommand { + @Override + public EntityArgument getArgumentType() { + return EntityArgument.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..0003ec262 --- /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.commands.arguments.EntityArgument; +import net.minecraft.world.entity.Entity; +import net.pitan76.mcpitanlib.api.event.PlayersCommandEvent; +import net.pitan76.mcpitanlib.api.event.ServerCommandEvent; + +public abstract class PlayersCommand extends RequiredCommand { + @Override + public EntityArgument getArgumentType() { + return EntityArgument.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..a6a795834 --- /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.world.item.enchantment.Enchantment; +import net.minecraft.world.item.enchantment.EnchantmentHelper; +import net.minecraft.world.item.ItemStack; +import net.minecraft.data.registries.VanillaRegistries; +import net.minecraft.resources.ResourceKey; +import net.minecraft.core.registries.Registries; +import net.minecraft.core.Holder; +import net.minecraft.resources.Identifier; +import net.minecraft.world.level.Level; +import net.pitan76.mcpitanlib.api.util.EnchantmentUtil; +import org.jetbrains.annotations.Nullable; + +import java.util.Optional; + +public class CompatEnchantment { + private final ResourceKey registryKey; + + @Deprecated + public CompatEnchantment(ResourceKey registryKey) { + this.registryKey = registryKey; + } + + public CompatEnchantment of(Identifier identifier) { + return EnchantmentUtil.getEnchantment(identifier); + } + + public Identifier getId() { + return registryKey.registry(); + } + + @Deprecated + public ResourceKey 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 Holder getEntry(@Nullable Level world) { + Optional> optionalEntry; + if (world == null) { + optionalEntry = VanillaRegistries.createLookup() + .get(registryKey); + } else { + optionalEntry = world.registryAccess().get(registryKey); + } + + return optionalEntry.orElseThrow(); + } + + public Enchantment getEnchantment(@Nullable Level world) { + return getEntry(world).value(); + } + + public int getLevel(ItemStack stack, @Nullable Level world) { + return EnchantmentHelper.getItemEnchantmentLevel(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..2af53c486 --- /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.world.entity.ContainerUser; +import net.minecraft.world.entity.LivingEntity; + +public class CompatContainerUser { + protected ContainerUser containerUser; + + public CompatContainerUser(ContainerUser containerUser) { + this.containerUser = containerUser; + } + + public double getContainerInteractionRange() { + return containerUser.getContainerInteractionRange(); + } + + public LivingEntity asLivingEntity() { + return containerUser.getLivingEntity(); + } + + public boolean isPlayer() { + return containerUser instanceof net.minecraft.world.entity.player.Player; + } + + public Player asPlayer() { + return new Player((net.minecraft.world.entity.player.Player) containerUser); + } + + @Deprecated + public ContainerUser 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..f0513e362 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/entity/CompatEntity.java @@ -0,0 +1,140 @@ +package net.pitan76.mcpitanlib.api.entity; + +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.protocol.game.ClientGamePacketListener; +import net.minecraft.network.protocol.Packet; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.storage.ValueInput; +import net.minecraft.world.level.storage.ValueOutput; +import net.minecraft.core.BlockPos; +import net.minecraft.world.phys.Vec3; +import net.minecraft.world.level.Level; +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.core.mc1216.NbtDataConverter; +import net.pitan76.mcpitanlib.midohra.entity.EntityTypeWrapper; +import net.pitan76.mcpitanlib.midohra.util.math.Vector3d; + +public class CompatEntity extends Entity implements ICompatEntity { + public CompatEntity(EntityType type, Level world) { + super(type, world); + } + + @Deprecated + @Override + public void defineSynchedData(SynchedEntityData.Builder builder) { + initDataTracker(new InitDataTrackerArgs(builder)); + } + + @Override + public boolean hurtServer(ServerLevel world, DamageSource source, float amount) { + return false; + } + + public void initDataTracker(InitDataTrackerArgs args) { + + } + + public void readCustomDataFromNbt(ReadNbtArgs nbt) { + readAdditionalSaveData(nbt.view); + } + + public void writeCustomDataToNbt(WriteNbtArgs nbt) { + addAdditionalSaveData(nbt.view); + } + + @Deprecated + @Override + protected void readAdditionalSaveData(ValueInput view) { + CompoundTag nbt = NbtDataConverter.data2nbt(view); + readCustomDataFromNbt(new ReadNbtArgs(nbt, view)); + } + + @Deprecated + @Override + protected void addAdditionalSaveData(ValueOutput view) { + CompoundTag nbt = new CompoundTag(); + writeCustomDataToNbt(new WriteNbtArgs(nbt, view)); + NbtDataConverter.nbt2writeData(nbt, view); + } + + public Packet createSpawnPacket() { + return null; + } + + public void writeNbt(WriteNbtArgs args) { + saveWithoutId(args.view); + } + + public void readNbt(ReadNbtArgs args) { + load(args.view); + } + + @Deprecated + @Override + public void saveWithoutId(ValueOutput view) { + super.saveWithoutId(view); + CompoundTag nbt = new CompoundTag(); + writeNbt(new WriteNbtArgs(nbt, view)); + NbtDataConverter.nbt2writeData(nbt, view); + } + + @Deprecated + @Override + public void load(ValueInput view) { + super.load(view); + CompoundTag nbt = NbtDataConverter.data2nbt(view); + readNbt(new ReadNbtArgs(nbt, view)); + } + + @Deprecated + @Override + public Level level() { + return callGetWorld(); + } + + public Level callGetWorld() { + return super.level(); + } + + public BlockPos callGetBlockPos() { + return blockPosition(); + } + + public Vec3 callGetPos() { + return position(); + } + + public boolean hasServerWorld() { + return callGetWorld() instanceof ServerLevel; + } + + public ServerLevel getServerWorld() { + return (ServerLevel) level(); + } + + 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()); + } + + public CompatEntity(EntityTypeWrapper type, net.pitan76.mcpitanlib.midohra.world.World world) { + super(type.get(), world.toMinecraft()); + } +} \ 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..5e0bede7e --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/entity/CompatThrownItemEntity.java @@ -0,0 +1,173 @@ +package net.pitan76.mcpitanlib.api.entity; + +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.world.entity.projectile.throwableitemprojectile.ThrowableItemProjectile; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.level.storage.ValueInput; +import net.minecraft.world.level.storage.ValueOutput; +import net.minecraft.world.phys.EntityHitResult; +import net.minecraft.world.phys.HitResult; +import net.minecraft.world.level.Level; +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; +import net.pitan76.mcpitanlib.api.util.ItemStackUtil; +import net.pitan76.mcpitanlib.core.mc1216.NbtDataConverter; +import net.pitan76.mcpitanlib.midohra.entity.EntityTypeWrapper; +import net.pitan76.mcpitanlib.midohra.entity.IEntityM; + +public abstract class CompatThrownItemEntity extends ThrowableItemProjectile implements IEntityM, ICompatEntity { + + public CompatThrownItemEntity(EntityType entityType, Level world) { + super(entityType, world); + } + + public CompatThrownItemEntity(EntityType entityType, double d, double e, double f, Level world) { + super(entityType, d, e, f, world, ItemStackUtil.empty()); + } + + public CompatThrownItemEntity(EntityType entityType, LivingEntity livingEntity, Level world) { + super(entityType, livingEntity, world, ItemStackUtil.empty()); + } + + public abstract Item getDefaultItemOverride(); + + @Deprecated + @Override + protected Item getDefaultItem() { + return getDefaultItemOverride(); + } + + public ItemStack callGetItem() { + return super.getItem(); + } + + @Deprecated + @Override + public ItemStack getItem() { + 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.handleEntityEvent(status); + } + + @Deprecated + @Override + public void handleEntityEvent(byte status) { + callHandleStatus(status); + } + + public void onEntityHit(EntityHitEvent event) { + super.onHitEntity(event.entityHitResult); + } + + @Deprecated + @Override + protected void onHitEntity(EntityHitResult entityHitResult) { + onEntityHit(new EntityHitEvent(entityHitResult)); + } + + public void onCollision(CollisionEvent event) { + super.onHit(event.hitResult); + } + + @Deprecated + @Override + protected void onHit(HitResult hitResult) { + onCollision(new CollisionEvent(hitResult)); + } + + // ------------------ ExtendEntity ------------------ + + @Deprecated + @Override + public void defineSynchedData(SynchedEntityData.Builder builder) { + initDataTracker(new InitDataTrackerArgs(builder, entityData)); + } + + public void initDataTracker(InitDataTrackerArgs args) { + super.defineSynchedData(args.getBuilder()); + } + + public void readCustomDataFromNbt(ReadNbtArgs nbt) { + super.readAdditionalSaveData(nbt.view); + } + + public void writeCustomDataToNbt(WriteNbtArgs nbt) { + super.addAdditionalSaveData(nbt.view); + } + + @Deprecated + @Override + protected void readAdditionalSaveData(ValueInput view) { + CompoundTag nbt = NbtDataConverter.data2nbt(view); + readCustomDataFromNbt(new ReadNbtArgs(nbt, view)); + } + + @Deprecated + @Override + protected void addAdditionalSaveData(ValueOutput view) { + CompoundTag nbt = new CompoundTag(); + writeCustomDataToNbt(new WriteNbtArgs(nbt, view)); + NbtDataConverter.nbt2writeData(nbt, view); + } + + public void writeNbt(WriteNbtArgs args) { + super.saveWithoutId(args.view); + } + + public void readNbt(ReadNbtArgs args) { + super.load(args.view); + } + + @Deprecated + @Override + public void saveWithoutId(ValueOutput view) { + super.saveWithoutId(view); + CompoundTag nbt = new CompoundTag(); + writeNbt(new WriteNbtArgs(nbt, view)); + NbtDataConverter.nbt2writeData(nbt, view); + } + + @Deprecated + @Override + public void load(ValueInput view) { + super.load(view); + CompoundTag nbt = NbtDataConverter.data2nbt(view); + readNbt(new ReadNbtArgs(nbt, view)); + } + + @Override + public Level level() { + return super.level(); + } + + public void setStack(net.pitan76.mcpitanlib.midohra.item.ItemStack stack) { + callSetItem(stack.toMinecraft()); + } + + public net.pitan76.mcpitanlib.midohra.item.ItemStack getStackM() { + return net.pitan76.mcpitanlib.midohra.item.ItemStack.of(callGetItem()); + } + + public CompatThrownItemEntity(EntityTypeWrapper type, net.pitan76.mcpitanlib.midohra.world.World world) { + this((EntityType) type.get(), world.toMinecraft()); + } +} 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..e6835bd8e --- /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.world.level.block.Block; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityDimensions; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.MobCategory; +import net.minecraft.world.level.storage.loot.LootTable; +import net.minecraft.resources.ResourceKey; +import net.pitan76.mcpitanlib.MCPitanLib; + +import java.util.Optional; + +public class EntityTypeBuilder { + + private MobCategory 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(MobCategory spawnGroup, ExtendEntityType.EntityFactory factory) { + this(); + this.spawnGroup = spawnGroup; + this.factory = factory; + } + + public static EntityTypeBuilder create() { + return new EntityTypeBuilder<>(); + } + + public static EntityTypeBuilder create(MobCategory 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(MobCategory 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.scalable(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(ResourceKey lootTable) { + this.lootTable = Optional.ofNullable(lootTable); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/entity/ExtendEntity.java b/common/src/main/java/net/pitan76/mcpitanlib/api/entity/ExtendEntity.java new file mode 100644 index 000000000..afe7c33a7 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/entity/ExtendEntity.java @@ -0,0 +1,102 @@ +package net.pitan76.mcpitanlib.api.entity; + +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.protocol.game.ClientGamePacketListener; +import net.minecraft.network.protocol.Packet; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.storage.ValueInput; +import net.minecraft.world.level.storage.ValueOutput; +import net.minecraft.world.level.Level; +import net.pitan76.mcpitanlib.api.nbt.NbtTag; +import net.pitan76.mcpitanlib.core.mc1216.NbtDataConverter; + +public class ExtendEntity extends Entity implements ICompatEntity { + public ExtendEntity(EntityType type, Level world) { + super(type, world); + } + + @Deprecated + @Override + public void defineSynchedData(SynchedEntityData.Builder builder) { + initDataTracker(); + } + + @Override + public boolean hurtServer(ServerLevel world, DamageSource source, float amount) { + return false; + } + + public void initDataTracker() { + } + + public void readCustomDataFromNbt(CompoundTag nbt) { + + } + + public void writeCustomDataToNbt(CompoundTag nbt) { + + } + + public Packet createSpawnPacket() { + return null; + } + + // 互換性用 (NbtTag型をOverrideすること) + public void writeNbt(NbtTag nbt) { + + } + + public void readNbt(NbtTag nbt) { + + } + + @Deprecated + @Override + public void saveWithoutId(ValueOutput view) { + super.saveWithoutId(view); + CompoundTag nbt = new CompoundTag(); + writeNbt(NbtTag.from(nbt)); + NbtDataConverter.nbt2writeData(nbt, view); + } + + @Deprecated + @Override + public void load(ValueInput view) { + super.load(view); + CompoundTag nbt = NbtDataConverter.data2nbt(view); + readNbt(NbtTag.from(nbt)); + } + + @Override + protected void readAdditionalSaveData(ValueInput view) { + CompoundTag nbt = NbtDataConverter.data2nbt(view); + readCustomDataFromNbt(nbt); + } + + @Override + protected void addAdditionalSaveData(ValueOutput view) { + CompoundTag nbt = new CompoundTag(); + writeCustomDataToNbt(nbt); + NbtDataConverter.nbt2writeData(nbt, view); + } + + // 1.14 + public CompoundTag toTag(CompoundTag nbt) { + this.writeNbt(NbtTag.from(nbt)); + return nbt; + } + + public CompoundTag fromTag(CompoundTag nbt) { + this.readNbt(NbtTag.from(nbt)); + return nbt; + } + + @Override + public Level level() { + return super.level(); + } +} \ 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..e62aa7c88 --- /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.world.level.block.Block; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityDimensions; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.MobCategory; +import net.minecraft.world.level.storage.loot.LootTable; +import net.minecraft.resources.ResourceKey; +import net.minecraft.world.flag.FeatureFlags; +import net.minecraft.world.level.Level; + +import java.util.Optional; + +public class ExtendEntityType extends EntityType { + private final Boolean alwaysUpdateVelocity; + + @Deprecated + public ExtendEntityType(EntityFactory factory, MobCategory 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, translationKey, lootTable, FeatureFlags.DEFAULT_FLAGS, spawnGroup.isFriendly()); + this.alwaysUpdateVelocity = alwaysUpdateVelocity; + } + + public ExtendEntityType(EntityFactory factory, MobCategory 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, translationKey, lootTable, FeatureFlags.DEFAULT_FLAGS, spawnGroup.isFriendly()); + this.alwaysUpdateVelocity = alwaysUpdateVelocity; + } + + @Override + public boolean trackDeltas() { + if (alwaysUpdateVelocity != null) + return alwaysUpdateVelocity; + + return super.trackDeltas(); + } + + public interface EntityFactory { + T create(EntityType type, Level world); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/entity/ICompatEntity.java b/common/src/main/java/net/pitan76/mcpitanlib/api/entity/ICompatEntity.java new file mode 100644 index 000000000..e603e5654 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/entity/ICompatEntity.java @@ -0,0 +1,16 @@ +package net.pitan76.mcpitanlib.api.entity; + +import net.minecraft.world.entity.Entity; +import net.pitan76.mcpitanlib.api.util.EntityUtil; +import net.pitan76.mcpitanlib.midohra.entity.EntityTypeWrapper; +import net.pitan76.mcpitanlib.midohra.entity.EntityWrapper; + +public interface ICompatEntity { + default EntityWrapper getWrapper() { + return this instanceof Entity ? EntityWrapper.of((Entity) this) : EntityWrapper.of(); + } + + default EntityTypeWrapper getTypeWrapper() { + return EntityTypeWrapper.of(EntityUtil.getType((Entity) this)); + } +} 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..1098b3d55 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/entity/Player.java @@ -0,0 +1,632 @@ +package net.pitan76.mcpitanlib.api.entity; + +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.client.player.LocalPlayer; +import net.minecraft.core.component.DataComponents; +import net.minecraft.world.item.component.CustomData; +import net.minecraft.world.entity.EquipmentSlot; +import net.minecraft.world.effect.MobEffectInstance; +import net.minecraft.world.item.ItemCooldowns; +import net.minecraft.world.entity.player.Abilities; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.item.ItemStack; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.world.MenuProvider; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.server.network.ServerGamePacketListenerImpl; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.sounds.SoundSource; +import net.minecraft.sounds.SoundEvent; +import net.minecraft.stats.Stat; +import net.minecraft.stats.StatType; +import net.minecraft.network.chat.Component; +import net.minecraft.world.InteractionHand; +import net.minecraft.resources.Identifier; +import net.minecraft.core.NonNullList; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.phys.Vec3; +import net.minecraft.world.level.Level; +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.gui.v2.ExtendedScreenHandlerFactory; +import net.pitan76.mcpitanlib.api.item.ArmorEquipmentType; +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.NbtUtil; +import net.pitan76.mcpitanlib.api.util.ScreenHandlerUtil; +import net.pitan76.mcpitanlib.api.util.TextUtil; +import net.pitan76.mcpitanlib.api.util.collection.ItemStackList; +import net.pitan76.mcpitanlib.api.util.entity.LivingEntityUtil; +import net.pitan76.mcpitanlib.api.util.inventory.CompatPlayerInventory; +import net.pitan76.mcpitanlib.api.util.inventory.ICompatInventory; +import net.pitan76.mcpitanlib.core.mc261.ExtendedMenuProvider; +import net.pitan76.mcpitanlib.core.player.ItemCooldown; +import net.pitan76.mcpitanlib.midohra.entity.EntityWrapper; +import net.pitan76.mcpitanlib.midohra.server.MCServer; +import net.pitan76.mcpitanlib.midohra.util.math.Vector3d; + +import java.util.*; +import java.util.function.Consumer; + +/* +PlayerEntity helper + */ +public class Player { + private final net.minecraft.world.entity.player.Player entity; + + public net.minecraft.world.entity.player.Player getEntity() { + return entity; + } + + public net.minecraft.world.entity.player.Player getPlayerEntity() { + return getEntity(); + } + + public Player(net.minecraft.world.entity.player.Player playerEntity) { + this.entity = playerEntity; + } + + /** + * Get player inventory + * @return PlayerInventory + */ + public Inventory getInv() { + return getEntity().getInventory(); + } + + /** + * Alias of getInv() + * @return PlayerInventory + */ + public Inventory getInventory() { + return getInv(); + } + + /** + * Get armor's item stack list + * @return DefaultedList + */ + public NonNullList getArmor() { + NonNullList stacks = NonNullList.withSize(4, ItemStack.EMPTY); + stacks.set(0, getInv().getItem(36)); + stacks.set(1, getInv().getItem(37)); + stacks.set(2, getInv().getItem(38)); + stacks.set(3, getInv().getItem(39)); + return stacks; + } + + /** + * Get main's item stack list + * @return DefaultedList + */ + public NonNullList getMain() { + return getInv().getNonEquipmentItems(); + } + + /** + * Get off hand's item stack list + * @return DefaultedList + */ + public NonNullList getOffHand() { + NonNullList stacks = NonNullList.withSize(1, ItemStack.EMPTY); + stacks.set(0, getInv().getItem(Inventory.SLOT_OFFHAND)); + return stacks; + } + + /** + * Get select slot integer + * @return int + */ + public int getSelectSlot() { + return getInv().getSelectedSlot(); + } + + /** + * Get player inventory size + * @return player inventory size + */ + public int getInvSize() { + return getInv().getContainerSize(); + } + + public OptionalInt openGuiScreen(MenuProvider factory) { + return getEntity().openMenu(factory); + } + + public OptionalInt openGuiScreen(Level world, BlockState state, BlockPos pos) { + return openGuiScreen(state.getMenuProvider(world, pos)); + } + + public boolean isServerPlayerEntity() { + return this.getEntity() instanceof ServerPlayer; + } + + public void openExtendedMenu(MenuProvider provider, Consumer bufWriter) { + if (isServerPlayerEntity()) + ScreenHandlerUtil.openExtendedMenu((ServerPlayer) this.getPlayerEntity(), provider, bufWriter); + } + + public void openExtendedMenu(ExtendedMenuProvider provider) { + if (isServerPlayerEntity()) + ScreenHandlerUtil.openExtendedMenu((ServerPlayer) this.getPlayerEntity(), provider); + } + + public void openExtendedMenu(ExtendedNamedScreenHandlerFactory provider) { + this.openExtendedMenu((ExtendedMenuProvider) provider); + } + + public void openMenu(MenuProvider provider) { + if (isServerPlayerEntity()) + ScreenHandlerUtil.openMenu((ServerPlayer) this.getPlayerEntity(), provider); + } + + public void insertStack(ItemStack stack) { + getInv().add(stack); + } + + public void insertStack(int slot, ItemStack stack) { + getInv().add(slot, stack); + } + + public void offerOrDrop(ItemStack itemStack) { + getInv().placeItemBackInInventory(itemStack); + } + + public void giveStack(ItemStack stack) { + getEntity().addItem(stack); + } + + public String getName() { + return getEntity().getName().getString(); + } + + public UUID getUUID() { + return getEntity().getUUID(); + } + + public Abilities getAbilities() { + return getEntity().getAbilities(); + } + + /** + * Returns whether this player is in creative mode. + */ + public boolean isCreative() { + return getAbilities().instabuild; + } + + public boolean isFlying() { + return getAbilities().flying; + } + + public boolean isInvulnerable() { + return getAbilities().invulnerable; + } + + public Level getWorld() { + return getEntity().level(); + } + + public AbstractContainerMenu getCurrentScreenHandler() { + return getEntity().containerMenu; + } + + public boolean isSneaking() { + return getEntity().isShiftKeyDown(); + } + + public ItemStack getCursorStack() { + return getCurrentScreenHandler().getCarried(); + } + + public boolean isClient() { + return getWorld().isClientSide(); + } + public boolean isServer() { + return !isClient(); + } + + public void readCustomDataFromNbt(CompoundTag nbt) { + getEntity().setComponent(DataComponents.CUSTOM_DATA, CustomData.of(nbt)); + } + + public void writeCustomDataToNbt(CompoundTag nbt) { + CompoundTag source = getEntity().get(DataComponents.CUSTOM_DATA).copyTag(); + NbtUtil.copyFrom(source, nbt); + } + + public void sendMessage(Component text) { + getEntity().sendSystemMessage(text); + } + + public void sendActionBar(Component text) { + getEntity().sendOverlayMessage(text); + } + + public void equipStack(EquipmentSlot slot, ItemStack stack) { + getEntity().setItemSlot(slot, stack); + } + + public void dropStack(ItemStack stack, boolean throwRandomly, boolean retainOwnership) { + getEntity().drop(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().blockPosition(); + } + + public Vec3 getPos() { + return getEntity().position(); + } + + public ItemStack getStackInHand(InteractionHand hand) { + return this.getEntity().getItemInHand(hand); + } + + public void heal(float amount) { + this.getEntity().heal(amount); + } + + public float getYaw() { + return this.getEntity().getViewYRot(0); + } + + public float getPitch() { + return this.getEntity().getViewXRot(0); + } + + public void playSound(SoundEvent event, SoundSource category, float volume, float pitch) { + if (isServerPlayerEntity()) { + Optional player = getServerPlayer(); + if (player.isPresent()) { + player.get().playSound(event, 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 ItemCooldowns getItemCooldownManager() { + return getEntity().getCooldowns(); + } + + public void incrementStat(Stat stat) { + getEntity().awardStat(stat); + } + + public void incrementStat(StatType type, T object) { + getEntity().awardStat(type.get(object)); + } + + public void incrementStat(Identifier id) { + getEntity().awardStat(id); + } + + public void incrementStat(CompatIdentifier id) { + getEntity().awardStat(id.toMinecraft()); + } + + public void teleport(double x, double y, double z) { + getEntity().randomTeleport(x, y, z, false); + } + + public ItemStack getMainHandStack() { + return getStackInHand(InteractionHand.MAIN_HAND); + } + + public ItemStack getOffHandStack() { + return getStackInHand(InteractionHand.OFF_HAND); + } + + public Direction getHorizontalFacing() { + return getEntity().getDirection(); + } + + public double getX() { + return getEntity().getX(); + } + + public double getY() { + return getEntity().getY(); + } + + public double getZ() { + return getEntity().getZ(); + } + + public boolean isServerPlayer() { + return getEntity() instanceof ServerPlayer; + } + + public Optional getServerPlayer() { + if (isServerPlayer()) + return Optional.of((ServerPlayer) getEntity()); + + return Optional.empty(); + } + + @Environment(EnvType.CLIENT) + public Optional getClientPlayer() { + if (getEntity() instanceof LocalPlayer) + return Optional.of((LocalPlayer) getEntity()); + + return Optional.empty(); + } + + public void setVelocity(double x, double y, double z) { + getEntity().setDeltaMovement(x, y, z); + } + + public void setVelocity(Vec3 velocity) { + getEntity().setDeltaMovement(velocity); + } + + public Vec3 getVelocity() { + return getEntity().getDeltaMovement(); + } + + public Optional getNetworkHandler() { + Optional player = getServerPlayer(); + return player.map(sp -> sp.connection); + } + + 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().addEffect(effect.getInstance()); + } + + public void removeStatusEffect(CompatStatusEffect effect) { + getEntity().removeEffect(effect.getEntry(getWorld())); + } + + public List getStatusEffects() { + List compatEffects = new ArrayList<>(); + + for (MobEffectInstance effect : getEntity().getActiveEffects()) { + compatEffects.add(new CompatStatusEffectInstance(effect)); + } + + return compatEffects; + } + + public void addExperience(int experience) { + getEntity().giveExperiencePoints(experience); + } + + public int getExperienceLevel() { + return getEntity().experienceLevel; + } + + public void addExperienceLevels(int levels) { + getEntity().giveExperienceLevels(levels); + } + + public void setExperienceLevel(int level) { + getEntity().experienceLevel = level; + } + + public void addScore(int score) { + getEntity().increaseScore(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(InteractionHand hand, ItemStack stack) { + getEntity().setItemInHand(hand, stack); + } + + public void setStackInHand(InteractionHand hand, net.pitan76.mcpitanlib.midohra.item.ItemStack stack) { + setStackInHand(hand, stack.toMinecraft()); + } + + public net.pitan76.mcpitanlib.midohra.item.ItemStack getMidohraStackInHand(InteractionHand hand) { + return net.pitan76.mcpitanlib.midohra.item.ItemStack.of(getStackInHand(hand)); + } + + public InteractionHand getActiveHand() { + return getEntity().getUsedItemHand(); + } + + public float getBlockBreakingSpeed(BlockState state) { + return getEntity().getDestroySpeed(state); + } + + public boolean canHarvest(BlockState state) { + return getEntity().hasCorrectToolForDrops(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().getFoodData().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()); + } + + public void openExtendedMenu(ExtendedScreenHandlerFactory provider) { + this.openExtendedMenu((ExtendedMenuProvider) provider); + } + + public void offerOrDrop(net.pitan76.mcpitanlib.midohra.item.ItemStack stack) { + offerOrDrop(stack.toMinecraft()); + } + + public void insertStack(net.pitan76.mcpitanlib.midohra.item.ItemStack stack) { + insertStack(stack.toMinecraft()); + } + + public void insertStack(int slot, net.pitan76.mcpitanlib.midohra.item.ItemStack stack) { + insertStack(slot, stack.toMinecraft()); + } + + public void giveStack(net.pitan76.mcpitanlib.midohra.item.ItemStack stack) { + giveStack(stack.toMinecraft()); + } + + public Vector3d getPosM() { + return Vector3d.of(getPos()); + } + + public net.pitan76.mcpitanlib.midohra.util.math.BlockPos getBlockPosM() { + return net.pitan76.mcpitanlib.midohra.util.math.BlockPos.of(getBlockPos()); + } + + public ItemStack getEquippedStack(ArmorEquipmentType type) { + return LivingEntityUtil.getEquippedStack(getEntity(), type.getSlot()); + } + + public net.pitan76.mcpitanlib.midohra.item.ItemStack getEquippedStackM(ArmorEquipmentType type) { + return net.pitan76.mcpitanlib.midohra.item.ItemStack.of(getEquippedStack(type)); + } + + public ItemStackList getMainAsM() { + return ItemStackList.of(getMain()); + } + + public ItemStackList getOffHandAsM() { + return ItemStackList.of(getOffHand()); + } + + public ItemStackList getArmorAsM() { + return ItemStackList.of(getArmor()); + } + + public ICompatInventory getInventoryAsM() { + return new CompatPlayerInventory(getInv()); + } + + public net.pitan76.mcpitanlib.midohra.item.ItemStack getMainHandStackAsM() { + return net.pitan76.mcpitanlib.midohra.item.ItemStack.of(getMainHandStack()); + } + + public net.pitan76.mcpitanlib.midohra.item.ItemStack getOffHandStackAsM() { + return net.pitan76.mcpitanlib.midohra.item.ItemStack.of(getOffHandStack()); + } + + public net.pitan76.mcpitanlib.midohra.util.math.Direction getHorizontalFacingM() { + return net.pitan76.mcpitanlib.midohra.util.math.Direction.of(getHorizontalFacing()); + } + + public net.pitan76.mcpitanlib.midohra.item.ItemStack getCursorStackAsM() { + return net.pitan76.mcpitanlib.midohra.item.ItemStack.of(getCursorStack()); + } + + public EntityWrapper wrap() { + return EntityWrapper.of(getEntity()); + } + + public MCServer getServer() { + return getMidohraWorld().getMCServer(); + } + + public Optional getCurrentHandItemM() { + return getCurrentHandItem().map(net.pitan76.mcpitanlib.midohra.item.ItemStack::of); + } +} \ 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..4879677ad --- /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.world.entity.ai.attributes.AttributeModifier; + +public class AttrModifierOperation { + private final AttributeModifier.Operation raw; + + public static final AttrModifierOperation ADD = new AttrModifierOperation(AttributeModifier.Operation.ADD_VALUE); + public static final AttrModifierOperation MUL_TOTAL = new AttrModifierOperation(AttributeModifier.Operation.ADD_MULTIPLIED_TOTAL); + public static final AttrModifierOperation MUL_BASE = new AttrModifierOperation(AttributeModifier.Operation.ADD_MULTIPLIED_BASE); + + @Deprecated + public AttrModifierOperation(AttributeModifier.Operation raw) { + this.raw = raw; + } + + public static AttrModifierOperation of(AttributeModifier.Operation raw) { + if (raw == AttributeModifier.Operation.ADD_VALUE) { + return ADD; + } else if (raw == AttributeModifier.Operation.ADD_MULTIPLIED_TOTAL) { + return MUL_TOTAL; + } else if (raw == AttributeModifier.Operation.ADD_MULTIPLIED_BASE) { + return MUL_BASE; + } + + return new AttrModifierOperation(raw); + } + + public AttributeModifier.Operation raw() { + return raw; + } + + public String getName() { + return raw().name(); + } + + public int getId() { + return raw().id(); + } + + @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..076eb00a1 --- /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.world.item.component.ItemAttributeModifiers; + +public class AttributeModifiersComponentBuilder { + + public final ItemAttributeModifiers.Builder builder = ItemAttributeModifiers.builder(); + + public AttributeModifiersComponentBuilder() { + + } + + public AttributeModifiersComponentBuilder add(CompatEntityAttribute attribute, CompatEntityAttributeModifier modifier, CompatAttributeModifierSlot slot) { + builder.add(attribute.raw(), modifier.raw(), slot.raw()); + return this; + } + + @Deprecated + public ItemAttributeModifiers 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..53b44517e --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/entity/attribute/CompatAttributeModifierSlot.java @@ -0,0 +1,64 @@ +package net.pitan76.mcpitanlib.api.entity.attribute; + +import net.minecraft.world.entity.EquipmentSlotGroup; +import net.pitan76.mcpitanlib.api.util.CompatStringIdentifiable; + +public class CompatAttributeModifierSlot implements CompatStringIdentifiable { + + private final EquipmentSlotGroup raw; + + public static final CompatAttributeModifierSlot ANY = new CompatAttributeModifierSlot(EquipmentSlotGroup.ANY); + public static final CompatAttributeModifierSlot MAIN_HAND = new CompatAttributeModifierSlot(EquipmentSlotGroup.MAINHAND); + public static final CompatAttributeModifierSlot OFF_HAND = new CompatAttributeModifierSlot(EquipmentSlotGroup.OFFHAND); + public static final CompatAttributeModifierSlot HEAD = new CompatAttributeModifierSlot(EquipmentSlotGroup.HEAD); + public static final CompatAttributeModifierSlot FEET = new CompatAttributeModifierSlot(EquipmentSlotGroup.FEET); + public static final CompatAttributeModifierSlot LEGS = new CompatAttributeModifierSlot(EquipmentSlotGroup.LEGS); + public static final CompatAttributeModifierSlot CHEST = new CompatAttributeModifierSlot(EquipmentSlotGroup.CHEST); + public static final CompatAttributeModifierSlot ARMOR = new CompatAttributeModifierSlot(EquipmentSlotGroup.ARMOR); + public static final CompatAttributeModifierSlot BODY = new CompatAttributeModifierSlot(EquipmentSlotGroup.BODY); + public static final CompatAttributeModifierSlot SADDLE = new CompatAttributeModifierSlot(EquipmentSlotGroup.SADDLE); + + @Deprecated + public CompatAttributeModifierSlot(EquipmentSlotGroup raw) { + this.raw = raw; + } + + public static CompatAttributeModifierSlot of(EquipmentSlotGroup slot) { + if (slot == EquipmentSlotGroup.ANY) return ANY; + if (slot == EquipmentSlotGroup.MAINHAND) return MAIN_HAND; + if (slot == EquipmentSlotGroup.OFFHAND) return OFF_HAND; + if (slot == EquipmentSlotGroup.HEAD) return HEAD; + if (slot == EquipmentSlotGroup.FEET) return FEET; + if (slot == EquipmentSlotGroup.LEGS) return LEGS; + if (slot == EquipmentSlotGroup.CHEST) return CHEST; + if (slot == EquipmentSlotGroup.ARMOR) return ARMOR; + if (slot == EquipmentSlotGroup.BODY) return BODY; + if (slot == EquipmentSlotGroup.SADDLE) return SADDLE; + + return new CompatAttributeModifierSlot(slot); + } + + @Deprecated + public EquipmentSlotGroup raw() { + return raw; + } + + @Override + public String asString_compat() { + return raw().getSerializedName(); + } + + @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..62358b356 --- /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.world.item.component.ItemAttributeModifiers; + +public class CompatAttributeModifiersComponent { + private final ItemAttributeModifiers raw; + + @Deprecated + public CompatAttributeModifiersComponent(ItemAttributeModifiers component) { + this.raw = component; + } + + @Deprecated + public ItemAttributeModifiers raw() { + return raw; + } + + public static CompatAttributeModifiersComponent of(ItemAttributeModifiers 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..a018655fc --- /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.world.entity.ai.attributes.Attribute; +import net.minecraft.core.Holder; + +public class CompatEntityAttribute { + public final Holder raw; + + @Deprecated + public CompatEntityAttribute(Holder attribute) { + this.raw = attribute; + } + + @Deprecated + public Holder raw() { + return raw; + } + + public String getId() { + return raw.getRegisteredName(); + } + + public Attribute getValue() { + return raw.value(); + } + + public boolean isNull() { + return raw == null; + } + + @Deprecated + public static CompatEntityAttribute of(Holder 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..f35752684 --- /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.world.entity.LivingEntity; +import net.minecraft.world.entity.ai.attributes.AttributeInstance; +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.world.entity.ai.attributes.AttributeInstance raw; + + @Deprecated + public CompatEntityAttributeInstance(net.minecraft.world.entity.ai.attributes.AttributeInstance instance) { + this.raw = instance; + } + + @Deprecated + public net.minecraft.world.entity.ai.attributes.AttributeInstance raw() { + return raw; + } + + @Deprecated + public static CompatEntityAttributeInstance of(net.minecraft.world.entity.ai.attributes.AttributeInstance instance) { + return new CompatEntityAttributeInstance(instance); + } + + public static CompatEntityAttributeInstance create(CompatEntityAttribute type, Consumer updateCallback) { + return of(new AttributeInstance(type.raw(), modifier -> { + if (updateCallback != null) + updateCallback.accept(of(modifier)); + })); + } + + public static CompatEntityAttributeInstance get(LivingEntity entity, CompatEntityAttribute attribute) { + return new CompatEntityAttributeInstance(entity.getAttribute(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().addPermanentModifier(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..28726e95e --- /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.world.entity.ai.attributes.AttributeModifier raw; + + @Deprecated + public CompatEntityAttributeModifier(net.minecraft.world.entity.ai.attributes.AttributeModifier raw) { + this.raw = raw; + } + + @Deprecated + public static CompatEntityAttributeModifier of(net.minecraft.world.entity.ai.attributes.AttributeModifier raw) { + return new CompatEntityAttributeModifier(raw); + } + + public static CompatEntityAttributeModifier of(CompatIdentifier id, double value, AttrModifierOperation operation) { + return new CompatEntityAttributeModifier(new net.minecraft.world.entity.ai.attributes.AttributeModifier(id.toMinecraft(), value, operation.raw())); + } + + @Deprecated + public net.minecraft.world.entity.ai.attributes.AttributeModifier raw() { + return raw; + } + + public AttrModifierOperation getOperation() { + return AttrModifierOperation.of(raw().operation()); + } + + public double getValue() { + return raw().amount(); + } + + 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..4676293a3 --- /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.world.entity.ai.attributes.Attribute; +import net.minecraft.world.entity.ai.attributes.Attributes; +import net.minecraft.core.Holder; + +public class CompatEntityAttributes { + + public static final CompatEntityAttribute ARMOR = of(Attributes.ARMOR); + public static final CompatEntityAttribute ARMOR_TOUGHNESS = of(Attributes.ARMOR_TOUGHNESS); + public static final CompatEntityAttribute ATTACK_DAMAGE = of(Attributes.ATTACK_DAMAGE); + public static final CompatEntityAttribute ATTACK_KNOCKBACK = of(Attributes.ATTACK_KNOCKBACK); + public static final CompatEntityAttribute ATTACK_SPEED = of(Attributes.ATTACK_SPEED); + public static final CompatEntityAttribute FOLLOW_RANGE = of(Attributes.FOLLOW_RANGE); + public static final CompatEntityAttribute KNOCKBACK_RESISTANCE = of(Attributes.KNOCKBACK_RESISTANCE); + public static final CompatEntityAttribute LUCK = of(Attributes.LUCK); + public static final CompatEntityAttribute MOVEMENT_SPEED = of(Attributes.MOVEMENT_SPEED); + public static final CompatEntityAttribute MAX_HEALTH = of(Attributes.MAX_HEALTH); + public static final CompatEntityAttribute JUMP_STRENGTH = of(Attributes.JUMP_STRENGTH); + public static final CompatEntityAttribute GRAVITY = of(Attributes.GRAVITY); + public static final CompatEntityAttribute FLYING_SPEED = of(Attributes.FLYING_SPEED); + public static final CompatEntityAttribute BLOCK_BREAK_SPEED = of(Attributes.BLOCK_BREAK_SPEED); + public static final CompatEntityAttribute BLOCK_INTERACTION_RANGE = of(Attributes.BLOCK_INTERACTION_RANGE); + + public static CompatEntityAttribute of(Holder 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..00d8f54f8 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/entity/effect/CompatStatusEffect.java @@ -0,0 +1,62 @@ +package net.pitan76.mcpitanlib.api.entity.effect; + +import net.minecraft.world.effect.MobEffect; +import net.minecraft.data.registries.VanillaRegistries; +import net.minecraft.resources.ResourceKey; +import net.minecraft.core.Holder; +import net.minecraft.resources.Identifier; +import net.minecraft.world.level.Level; +import net.pitan76.mcpitanlib.api.util.StatusEffectUtil; +import org.jetbrains.annotations.Nullable; + +import java.util.Optional; + +public class CompatStatusEffect { + private final ResourceKey registryKey; + + @Deprecated + public CompatStatusEffect(ResourceKey registryKey) { + this.registryKey = registryKey; + } + + public CompatStatusEffect of(Identifier identifier) { + return StatusEffectUtil.getStatusEffect(identifier); + } + + public Identifier getId() { + return registryKey.registry(); + } + + @Deprecated + public ResourceKey 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 Holder getEntry(@Nullable Level world) { + Optional> optionalEntry; + if (world == null) { + optionalEntry = VanillaRegistries.createLookup() + .get(registryKey); + } else { + optionalEntry = world.registryAccess().get(registryKey); + } + + return optionalEntry.orElseThrow(); + } + + public MobEffect getStatusEffect(@Nullable Level 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..c5f7fe2c0 --- /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.world.effect.MobEffect; +import net.minecraft.world.effect.MobEffectInstance; +import net.minecraft.resources.ResourceKey; +import org.jetbrains.annotations.Nullable; + +import java.util.Optional; + +public class CompatStatusEffectInstance { + private final MobEffectInstance instance; + + @Deprecated + public CompatStatusEffectInstance(MobEffectInstance instance) { + this.instance = instance; + } + + public MobEffectInstance getInstance() { + return instance; + } + + public Optional getCompatStatusEffect() { + Optional> optional = instance.getEffect().unwrapKey(); + 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 MobEffectInstance hiddenEffect) { + this.instance = new MobEffectInstance(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.isVisible(); + } + + public boolean showIcon() { + return instance.showIcon(); + } + + public boolean isInfinite() { + return instance.isInfiniteDuration(); + } +} 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..5019fc031 --- /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.world.level.block.Block; +import net.minecraft.commands.arguments.blocks.BlockStateArgument; +import net.pitan76.mcpitanlib.api.command.argument.BlockCommand; + +public class BlockCommandEvent extends RequiredCommandEvent { + public Block getValue() { + return BlockStateArgument.getBlock(context, ((BlockCommand) getCommand()).getArgumentName()).getState().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..b006fb665 --- /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.commands.arguments.EntityArgument; +import net.minecraft.world.entity.Entity; +import net.pitan76.mcpitanlib.api.command.argument.EntitiesCommand; + +public class EntitiesCommandEvent extends RequiredCommandEvent { + public Entity getValue() { + try { + return EntityArgument.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..7b5e73655 --- /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.commands.arguments.EntityArgument; +import net.minecraft.world.entity.Entity; +import net.pitan76.mcpitanlib.api.command.argument.EntityCommand; + +public class EntityCommandEvent extends RequiredCommandEvent { + public Entity getValue() { + try { + return EntityArgument.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..7128b0537 --- /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.commands.arguments.item.ItemArgument; +import net.minecraft.world.item.Item; +import net.pitan76.mcpitanlib.api.command.argument.ItemCommand; + +public class ItemCommandEvent extends RequiredCommandEvent { + public Item getValue() { + return ItemArgument.getItem(context, ((ItemCommand) getCommand()).getArgumentName()).item().value(); + } +} 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..f9ede4ac3 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/PlayerCommandEvent.java @@ -0,0 +1,26 @@ +package net.pitan76.mcpitanlib.api.event; + +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import net.minecraft.commands.arguments.EntityArgument; +import net.minecraft.world.entity.Entity; +import net.pitan76.mcpitanlib.api.command.argument.PlayerCommand; +import net.pitan76.mcpitanlib.api.entity.Player; +import net.pitan76.mcpitanlib.midohra.entity.EntityWrapper; + +public class PlayerCommandEvent extends RequiredCommandEvent { + public Entity getValue() { + try { + return EntityArgument.getPlayer(context, ((PlayerCommand) getCommand()).getArgumentName()); + } catch (CommandSyntaxException e) { + throw new RuntimeException(e); + } + } + + public EntityWrapper getWrapper() { + return EntityWrapper.of(getValue()); + } + + public Player getValueAsPlayer() { + return getWrapper().toPlayer().orElse(null); + } +} 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..7908087c5 --- /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.commands.arguments.EntityArgument; +import net.minecraft.world.entity.Entity; +import net.pitan76.mcpitanlib.api.command.argument.PlayersCommand; + +public class PlayersCommandEvent extends RequiredCommandEvent { + public Entity getValue() { + try { + return EntityArgument.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..a775f63f5 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/ServerCommandEvent.java @@ -0,0 +1,142 @@ +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.world.entity.Entity; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.network.chat.Component; +import net.minecraft.world.level.Level; +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; +import net.pitan76.mcpitanlib.midohra.entity.EntityWrapper; + +public class ServerCommandEvent extends CommandEvent { + + public CommandContext getContext() { + return context; + } + + public void setContext(CommandContext context) { + this.context = context; + } + + public CommandSourceStack getSource() { + return getContext().getSource(); + } + + public net.minecraft.world.entity.player.Player getPlayerEntity() throws CommandSyntaxException { + return getSource().getPlayer(); + } + + public Player getPlayer() throws CommandSyntaxException { + return new Player(getPlayerEntity()); + } + + public Level getWorld() { + return getSource().getLevel(); + } + + 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(Component message, boolean broadcastToOps) { + getSource().sendSuccess(() -> message, broadcastToOps); + } + + public void sendFailure(Component message) { + getSource().sendFailure(message); + } + + public void sendSuccess(Component 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()); + } + + public net.pitan76.mcpitanlib.midohra.world.World getMidohraWorld() { + return net.pitan76.mcpitanlib.midohra.world.World.of(getWorld()); + } + + public EntityWrapper getEntityWrapper() { + return EntityWrapper.of(getEntity()); + } +} 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..696a73505 --- /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.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.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 StateDefinition.Builder builder; + + public AppendPropertiesArgs(StateDefinition.Builder builder) { + this.builder = builder; + } + + public StateDefinition.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..a495aef5b --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/BlockBreakEvent.java @@ -0,0 +1,78 @@ +package net.pitan76.mcpitanlib.api.event.block; + +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +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 Level world; + public BlockPos pos; + public BlockState state; + public Player player; + + public BlockBreakEvent(Level world, BlockPos pos, BlockState state, net.minecraft.world.entity.player.Player 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 net.minecraft.world.entity.player.Player getPlayerEntity() { + return player.getPlayerEntity(); + } + + public Level getWorld() { + return world; + } + + public boolean isClient() { + return world.isClientSide(); + } + + 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..a73cfcd2c --- /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.world.level.block.state.BlockState; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.item.ItemStack; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +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 Level world; + public BlockPos pos; + public Player player; + + public BlockBreakStartEvent(BlockState state, Level 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 Level 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..3f68af73c --- /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.world.level.block.state.BlockState; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.item.ItemStack; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +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 Level world; + public BlockPos pos; + public BlockState state; + public LivingEntity placer; + public ItemStack stack; + + public BlockPlacedEvent(Level 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 Level getWorld() { + return world; + } + + public ItemStack getStack() { + return stack; + } + + public LivingEntity getPlacer() { + return placer; + } + + public boolean isClient() { + return world.isClientSide(); + } + + 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..e9f0db538 --- /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.world.level.block.state.BlockState; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.core.BlockPos; +import net.minecraft.util.RandomSource; +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 ServerLevel world; + public BlockPos pos; + public CompatRandom random; + + public BlockScheduledTickEvent(BlockState state, ServerLevel world, BlockPos pos, RandomSource 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 ServerLevel 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..73506b118 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/BlockUseEvent.java @@ -0,0 +1,146 @@ +package net.pitan76.mcpitanlib.api.event.block; + +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +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.item.ItemWrapper; +import net.pitan76.mcpitanlib.midohra.world.IWorldView; + +public class BlockUseEvent extends BaseEvent { + public BlockState state; + public Level world; + public BlockPos pos; + public Player player; + public InteractionHand hand; + public BlockHitResult hit; + public ItemStack stack; + + public BlockUseEvent(BlockState state, Level world, BlockPos pos, net.minecraft.world.entity.player.Player player, InteractionHand 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 InteractionHand getHand() { + return hand; + } + + public Level getWorld() { + return world; + } + + public BlockState getState() { + return state; + } + + public BlockPos getPos() { + return pos; + } + + public boolean isClient() { + return world.isClientSide(); + } + + 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()); + } + + public net.pitan76.mcpitanlib.midohra.item.ItemStack getStackM() { + return net.pitan76.mcpitanlib.midohra.item.ItemStack.of(stack); + } + + public Item getItem() { + return stack.getItem(); + } + + public ItemWrapper getItemWrapper() { + return ItemWrapper.of(getItem()); + } + + public BlockUseEvent(net.pitan76.mcpitanlib.midohra.block.BlockState state, net.pitan76.mcpitanlib.midohra.world.World world, net.pitan76.mcpitanlib.midohra.util.math.BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { + this(state.toMinecraft(), world.toMinecraft(), pos.toMinecraft(), player.getEntity(), hand, hit); + } +} 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..3c7e26970 --- /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.world.level.block.state.BlockState; +import net.minecraft.world.level.pathfinder.PathComputationType; +import net.minecraft.world.level.material.FluidState; +import net.pitan76.mcpitanlib.api.event.BaseEvent; +import net.pitan76.mcpitanlib.api.util.FluidStateUtil; + +public class CanPathfindThroughArgs extends BaseEvent { + public BlockState state; + public PathComputationType type; + + public CanPathfindThroughArgs(BlockState state, PathComputationType type) { + this.state = state; + + this.type = type; + } + + public BlockState getState() { + return state; + } + + public PathComputationType getType() { + return type; + } + + public FluidState getFluidState() { + return state.getFluidState(); + } + + public boolean isWaterNavigationType() { + return type == PathComputationType.WATER; + } + + public boolean isAirNavigationType() { + return type == PathComputationType.AIR; + } + + public boolean isLandNavigationType() { + return type == PathComputationType.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..575291168 --- /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.world.level.block.state.BlockState; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.BlockGetter; + +public class CollisionShapeEvent extends OutlineShapeEvent { + + public CollisionShapeEvent(BlockState state, BlockGetter world, BlockPos pos, CollisionContext 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..891ed850c --- /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.world.level.block.state.BlockState; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.storage.loot.parameters.LootContextParams; +import net.minecraft.world.level.storage.loot.LootParams; +import net.pitan76.mcpitanlib.api.event.BaseEvent; + +public class DroppedStacksArgs extends BaseEvent { + public BlockState state; + public LootParams.Builder builder; + + public DroppedStacksArgs(BlockState state, LootParams.Builder builder) { + this.state = state; + this.builder = builder; + } + + public BlockState getState() { + return state; + } + + @Deprecated + public LootParams.Builder getBuilder() { + return builder; + } + + public BlockEntity getBlockEntity() { + return builder.getParameter(LootContextParams.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..a6b5fd63e --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/EntityCollisionEvent.java @@ -0,0 +1,112 @@ +package net.pitan76.mcpitanlib.api.event.block; + +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.InsideBlockEffectApplier; +import net.minecraft.world.entity.player.Player; +import net.minecraft.sounds.SoundSource; +import net.minecraft.sounds.SoundEvent; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +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 Level world; + public BlockPos pos; + public Entity entity; + public InsideBlockEffectApplier handler; + public boolean bl = false; + + public EntityCollisionEvent(BlockState state, Level world, BlockPos pos, Entity entity) { + this.state = state; + this.world = world; + this.pos = pos; + this.entity = entity; + } + + public EntityCollisionEvent(BlockState state, Level world, BlockPos pos, Entity entity, InsideBlockEffectApplier handler) { + this.state = state; + this.world = world; + this.pos = pos; + this.entity = entity; + this.handler = handler; + } + + public EntityCollisionEvent(BlockState state, Level world, BlockPos pos, Entity entity, InsideBlockEffectApplier handler, boolean bl) { + this.state = state; + this.world = world; + this.pos = pos; + this.entity = entity; + this.handler = handler; + this.bl = bl; + } + + public boolean isClient() { + return WorldUtil.isClient(world); + } + + public BlockPos getEntityPos() { + return entity.blockPosition(); + } + + public BlockPos getBlockPos() { + return pos; + } + + public BlockState getState() { + return state; + } + + public Entity getEntity() { + return entity; + } + + public Level getWorld() { + return world; + } + + public void playSound(SoundEvent event, SoundSource category, float volume, float pitch) { + WorldUtil.playSound(world, null, entity.blockPosition(), event, category, volume, pitch); + } + + public void playSound(SoundEvent event, float volume, float pitch) { + playSound(event, SoundSource.BLOCKS, volume, pitch); + } + + public void playSound(SoundEvent event) { + playSound(event, 1f, 1f); + } + + public void playSound(SoundEvent event, SoundSource category) { + playSound(event, category, 1f, 1f); + } + + public void playSound(CompatIdentifier id, SoundSource category, float volume, float pitch) { + playSound(SoundEventUtil.getSoundEvent(id), category, volume, pitch); + } + + public boolean hasPlayerEntity() { + return entity instanceof Player; + } + + public Optional getPlayerEntity() { + if (!hasPlayerEntity()) return Optional.empty(); + return Optional.of((Player) entity); + } + + public BlockEntity getBlockEntity() { + return WorldUtil.getBlockEntity(getWorld(), getBlockPos()); + } + + public InsideBlockEffectApplier getHandler() { + return handler; + } +} 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..890e373f4 --- /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.world.level.block.state.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..c84c2c985 --- /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.world.level.block.state.BlockState; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.Container; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.Containers; +import net.minecraft.core.NonNullList; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; + +public class ItemScattererUtil { + public static void spawn(Level world, BlockPos pos, BlockEntity blockEntity) { + if (blockEntity instanceof Container) { + spawn(world, pos, (Container) blockEntity); + } + } + + public static void spawn(Level world, BlockPos pos, Container inventory) { + Containers.dropContents(world, pos, inventory); + } + + public static void spawn(Level world, BlockPos pos, ItemStack stack) { + Containers.dropItemStack(world, pos.getX(), pos.getY(), pos.getZ(), stack); + } + + public static void spawn(Level world, BlockPos pos, NonNullList stacks) { + Containers.dropContents(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, Level world, BlockPos pos) { + Containers.updateNeighboursAfterDestroy(state, 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, NonNullList 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, Container 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..989c88743 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/NeighborUpdateEvent.java @@ -0,0 +1,98 @@ +package net.pitan76.mcpitanlib.api.event.block; + +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.redstone.Orientation; +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 Level world; + public BlockPos pos; + public Block sourceBlock; + + @Nullable + public BlockPos sourcePos; + + @Nullable + public Orientation wireOrientation; + + public boolean notify; + + public NeighborUpdateEvent(BlockState state, Level 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, Level world, BlockPos pos, Block sourceBlock, @Nullable Orientation wireOrientation, boolean notify) { + this(state, world, pos, sourceBlock, (BlockPos) null, notify); + this.wireOrientation = wireOrientation; + } + + public BlockState getState() { + return state; + } + + public Level 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); + } + + @Deprecated + public @Nullable Orientation getWireOrientation() { + return wireOrientation; + } + + 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..b62f9f0fd --- /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.world.level.block.state.BlockState; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.level.block.state.properties.Property; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.BlockGetter; +import net.pitan76.mcpitanlib.api.event.BaseEvent; +import net.pitan76.mcpitanlib.api.state.property.IProperty; + +public class OutlineShapeEvent extends BaseEvent { + public BlockState state; + public BlockGetter world; + public BlockPos pos; + public CollisionContext context; + + public OutlineShapeEvent(BlockState state, BlockGetter world, BlockPos pos, CollisionContext context) { + this.state = state; + this.world = world; + this.pos = pos; + this.context = context; + } + + public BlockPos getPos() { + return pos; + } + + public BlockState getState() { + return state; + } + + public BlockGetter getWorld() { + return world; + } + + public CollisionContext getContext() { + return context; + } + + public > T getProperty(Property property) { + return state.getValue(property); + } + + public > boolean containsProperty(Property property) { + return state.hasProperty(property); + } + + public , V extends T> BlockState with(Property property, V value) { + return state.setValue(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..0b63f3223 --- /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.world.level.block.state.BlockState; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.LevelReader; +import org.jetbrains.annotations.Nullable; + +public class PickStackEvent { + + @Deprecated + public LevelReader worldView; + + @Deprecated + public BlockGetter blockView; + + public BlockPos pos; + public BlockState state; + + public boolean includeData = true; + + public PickStackEvent(LevelReader world, BlockPos pos, BlockState state) { + this.worldView = world; + this.pos = pos; + this.state = state; + } + + public PickStackEvent(BlockGetter 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 BlockGetter getBlockView() { + return blockView; + } + + @Nullable + public LevelReader 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().getLevel().isClientSide(); + if (worldView != null) + return worldView.isClientSide(); + + try { + net.minecraft.client.Minecraft.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..766cb874b --- /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.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.item.context.BlockPlaceContext; +import net.minecraft.world.level.block.state.properties.Property; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.phys.Vec3; +import net.minecraft.world.level.Level; +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.UseOnContextMixin; +import org.jetbrains.annotations.Nullable; + +public class PlacementStateArgs extends BaseEvent { + public BlockPlaceContext ctx; + + @Nullable + public Block block; + + public PlacementStateArgs(BlockPlaceContext ctx) { + this.ctx = ctx; + } + + public PlacementStateArgs(BlockPlaceContext ctx, @Nullable Block block) { + this.ctx = ctx; + this.block = block; + } + + public boolean canPlace() { + return ctx.canPlace(); + } + + public BlockPos getPos() { + return ctx.getClickedPos(); + } + + public Player getPlayer() { + return new Player(ctx.getPlayer()); + } + + public Direction[] getPlacementDirections() { + return ctx.getNearestLookingDirections(); + } + + public InteractionHand getHand() { + return ctx.getHand(); + } + + public Direction getSide() { + return ctx.getClickedFace(); + } + + public Direction getHorizontalPlayerFacing() { + return ctx.getHorizontalDirection(); + } + + public float getPlayerYaw() { + return ctx.getRotation(); + } + + public Level getWorld() { + return ctx.getLevel(); + } + + public boolean isClient() { + return getWorld().isClientSide(); + } + + public Vec3 getHitPos() { + return ctx.getClickLocation(); + } + + public boolean canReplaceExisting() { + return ctx.replacingClickedOnBlock(); + } + + @Deprecated + public UseOnContextMixin getIUCAccessor() { + return (UseOnContextMixin) ctx; + } + + public BlockHitResult getHitResult() { + return getIUCAccessor().getHitResult(); + } + + public ItemUseOnBlockEvent toItemUseOnBlockEvent() { + return new ItemUseOnBlockEvent(getWorld(), getPlayer().getPlayerEntity(), getHand(), ctx.getItemInHand(), getHitResult()); + } + + public BlockPlaceContext 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..6bf3f94fb --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/ScreenHandlerCreateEvent.java @@ -0,0 +1,55 @@ +package net.pitan76.mcpitanlib.api.event.block; + +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +import net.pitan76.mcpitanlib.api.entity.Player; +import net.pitan76.mcpitanlib.api.event.BaseEvent; + +public class ScreenHandlerCreateEvent extends BaseEvent { + + public BlockState state; + public Level world; + public BlockPos pos; + public int syncId; + public Inventory inventory; + public Player player; + + public ScreenHandlerCreateEvent(BlockState state, Level world, BlockPos pos, int syncId, Inventory inventory, net.minecraft.world.entity.player.Player 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 Level getWorld() { + return world; + } + + public int getSyncId() { + return syncId; + } + + public Inventory getInventory() { + return inventory; + } + + public Player getPlayer() { + return player; + } + + public boolean isClient() { + return world.isClientSide(); + } +} 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..d8023b86e --- /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.world.level.block.state.BlockState; +import net.minecraft.world.phys.shapes.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..44cf25443 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/StateForNeighborUpdateArgs.java @@ -0,0 +1,86 @@ +package net.pitan76.mcpitanlib.api.event.block; + +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.level.LevelAccessor; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.ScheduledTickAccess; +import net.pitan76.mcpitanlib.api.util.math.random.CompatRandom; + +public class StateForNeighborUpdateArgs { + public BlockState state; + public Direction direction; + public BlockState neighborState; + public LevelReader world; + public BlockPos pos; + public BlockPos neighborPos; + public ScheduledTickAccess tickView; + public CompatRandom random; + + public StateForNeighborUpdateArgs(BlockState state, Direction direction, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) { + this.state = state; + this.direction = direction; + this.neighborState = neighborState; + this.world = world; + this.pos = pos; + this.neighborPos = neighborPos; + } + + public StateForNeighborUpdateArgs(BlockState state, Direction direction, BlockState neighborState, LevelReader world, BlockPos pos, BlockPos neighborPos, ScheduledTickAccess tickView, CompatRandom random) { + this.state = state; + this.direction = direction; + this.neighborState = neighborState; + this.world = world; + this.pos = pos; + this.neighborPos = neighborPos; + this.tickView = tickView; + this.random = random; + } + + 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 LevelReader getWorld() { + return world; + } + + public BlockPos getPos() { + return pos; + } + + public BlockPos getNeighborPos() { + return neighborPos; + } + + public CompatRandom getRandom() { + return random; + } + + @Deprecated + public ScheduledTickAccess getTickView() { + return tickView; + } +} 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..7e16a481d --- /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.world.level.block.state.BlockState; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.Container; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +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 Level 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, Level 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 Level getWorld() { + return world; + } + + public BlockPos getPos() { + return pos; + } + + public BlockState getNewState() { + return newState; + } + + public boolean isMoved() { + return moved; + } + + public boolean isClient() { + return world.isClientSide(); + } + + /** + * check if the block is the same state + * @return boolean + */ + public boolean isSameState() { + return state.is(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 Container; + } + + /** + * 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/net/pitan76/mcpitanlib/api/event/block/TileCreateEvent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/TileCreateEvent.java new file mode 100644 index 000000000..64c13ad7e --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/block/TileCreateEvent.java @@ -0,0 +1,88 @@ +package net.pitan76.mcpitanlib.api.event.block; + +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.BlockGetter; +import net.pitan76.mcpitanlib.api.event.BaseEvent; + +public class TileCreateEvent extends BaseEvent { + + // ~1.16.5 + private BlockGetter blockView; + + public TileCreateEvent(BlockGetter blockView) { + this.blockView = blockView; + this.blockPos = null; + this.blockState = null; + } + + public BlockGetter getBlockView() { + return blockView; + } + + public void setBlockView(BlockGetter blockView) { + this.blockView = blockView; + } + + public boolean hasBlockView() { + return (blockView != null); + } + // ---- + + // 1.17~ + private BlockPos blockPos; + private BlockState blockState; + + public TileCreateEvent(BlockPos blockPos, BlockState blockState) { + this.blockView = null; + this.blockPos = blockPos; + this.blockState = blockState; + } + + public BlockPos getBlockPos() { + return blockPos; + } + + public void setBlockPos(BlockPos blockPos) { + this.blockPos = blockPos; + } + + public boolean hasBlockPos() { + return (blockPos != null); + } + + public BlockState getBlockState() { + return blockState; + } + + public void setBlockState(BlockState blockState) { + this.blockState = blockState; + } + + public boolean hasBlockState() { + return (blockState != null); + } + // ---- + + public TileCreateEvent(net.pitan76.mcpitanlib.midohra.util.math.BlockPos blockPos, net.pitan76.mcpitanlib.midohra.block.BlockState blockState) { + this.blockView = null; + this.blockPos = blockPos.toMinecraft(); + this.blockState = blockState.toMinecraft(); + } + + public net.pitan76.mcpitanlib.midohra.util.math.BlockPos getBlockPosM() { + return net.pitan76.mcpitanlib.midohra.util.math.BlockPos.of(getBlockPos()); + } + + public net.pitan76.mcpitanlib.midohra.block.BlockState getBlockStateM() { + return net.pitan76.mcpitanlib.midohra.block.BlockState.of(getBlockState()); + } + + public void setBlockPos(net.pitan76.mcpitanlib.midohra.util.math.BlockPos blockPos) { + setBlockPos(blockPos.toMinecraft()); + } + + public void setBlockState(net.pitan76.mcpitanlib.midohra.block.BlockState blockState) { + setBlockState(blockState.toMinecraft()); + } +} \ No newline at end of file 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..a6ebd9ac5 --- /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.world.level.block.state.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..ad67208c4 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/container/factory/ExtraDataArgs.java @@ -0,0 +1,60 @@ +package net.pitan76.mcpitanlib.api.event.container.factory; + +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.server.level.ServerPlayer; +import net.pitan76.mcpitanlib.api.entity.Player; +import net.pitan76.mcpitanlib.api.event.BaseEvent; +import net.pitan76.mcpitanlib.api.network.PacketByteUtil; +import net.pitan76.mcpitanlib.midohra.network.CompatPacketByteBuf; + +public class ExtraDataArgs extends BaseEvent { + public FriendlyByteBuf buf; + public ServerPlayer player; + + public ExtraDataArgs(FriendlyByteBuf buf, ServerPlayer player) { + super(); + this.buf = buf; + this.player = player; + } + + public ExtraDataArgs() { + super(); + } + + public ExtraDataArgs(FriendlyByteBuf buf) { + super(); + this.buf = buf; + } + + public boolean hasPlayer() { + return player != null; + } + + public boolean hasBuf() { + return buf != null; + } + + public FriendlyByteBuf getBuf() { + return buf; + } + + public ServerPlayer getPlayer() { + return player; + } + + public Player getCompatPlayer() { + return new Player(player); + } + + /** + * @param obj The object to write + * @see PacketByteUtil#writeVar(FriendlyByteBuf, Object) + */ + public void writeVar(Object obj) { + PacketByteUtil.writeVar(getBuf(), obj); + } + + public CompatPacketByteBuf getCompatBuf() { + return CompatPacketByteBuf.of(getBuf()); + } +} 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..257db4d00 --- /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.world.phys.HitResult; +import net.minecraft.world.phys.Vec3; +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 Vec3 getPos() { + return hitResult.getLocation(); + } + + 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..066660e0f --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/entity/EntityHitEvent.java @@ -0,0 +1,36 @@ +package net.pitan76.mcpitanlib.api.event.entity; + +import net.minecraft.world.entity.Entity; +import net.minecraft.world.phys.EntityHitResult; +import net.minecraft.world.phys.HitResult; +import net.pitan76.mcpitanlib.midohra.entity.EntityWrapper; +import net.pitan76.mcpitanlib.midohra.util.hit.HitResultType; + +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(); + } + + public EntityWrapper getEntityWrapper() { + return EntityWrapper.of(getEntity()); + } + + public HitResultType getTypeM() { + return HitResultType.from(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..9b6c1a676 --- /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.network.syncher.SynchedEntityData; +import net.minecraft.network.syncher.EntityDataAccessor; +import org.jetbrains.annotations.Nullable; + +public class InitDataTrackerArgs { + public SynchedEntityData.Builder builder; + public SynchedEntityData tracker; + + public InitDataTrackerArgs(SynchedEntityData.Builder builder) { + this.builder = builder; + } + + public InitDataTrackerArgs(SynchedEntityData tracker) { + this.tracker = tracker; + } + + public InitDataTrackerArgs(SynchedEntityData.Builder builder, @Nullable SynchedEntityData tracker) { + this.builder = builder; + this.tracker = tracker; + } + + public SynchedEntityData.Builder getBuilder() { + return builder; + } + + public SynchedEntityData.Builder add(EntityDataAccessor data, T value) { + return builder.define(data, value); + } + + public void set(EntityDataAccessor data, T value) { + tracker.set(data, value); + } + + public void addTracking(EntityDataAccessor 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..31bb70acb --- /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.world.entity.Entity; +import net.minecraft.world.damagesource.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..b887d296f --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/item/CanMineArgs.java @@ -0,0 +1,75 @@ +package net.pitan76.mcpitanlib.api.event.item; + +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.item.ItemStack; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +import net.pitan76.mcpitanlib.api.entity.Player; +import net.pitan76.mcpitanlib.api.util.WorldUtil; + +public class CanMineArgs { + public BlockState state; + public Level world; + public BlockPos pos; + + @Deprecated + public Player miner; + + @Deprecated + public ItemStack stack; + + public LivingEntity entity; + + public CanMineArgs(BlockState state, Level world, BlockPos pos, net.minecraft.world.entity.player.Player miner) { + this.state = state; + this.world = world; + this.pos = pos; + this.miner = new Player(miner); + this.entity = miner; + } + + public CanMineArgs(ItemStack stack, BlockState state, Level world, BlockPos pos, LivingEntity entity) { + this.stack = stack; + this.state = state; + this.world = world; + this.pos = pos; + this.entity = entity; + + if (entity instanceof net.minecraft.world.entity.player.Player) { + this.miner = new Player((net.minecraft.world.entity.player.Player) entity); + } + } + + public BlockState getState() { + return state; + } + + public Level 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.getMainHandItem(); + } + + 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..4392e550f --- /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.world.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..18a799d4a --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/item/CraftEvent.java @@ -0,0 +1,47 @@ +package net.pitan76.mcpitanlib.api.event.item; + +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; +import net.pitan76.mcpitanlib.api.entity.Player; +import org.jetbrains.annotations.Nullable; + +public class CraftEvent { + + public ItemStack stack; + public Level world; + public Player player; + + public CraftEvent(ItemStack stack, Level world, Player player) { + this.stack = stack; + this.world = world; + this.player = player; + } + + public CraftEvent(ItemStack stack, Level world, net.minecraft.world.entity.player.Player player) { + this.stack = stack; + this.world = world; + this.player = new Player(player); + } + + public CraftEvent(ItemStack stack, Level world) { + this.stack = stack; + this.world = world; + } + + public ItemStack getStack() { + return stack; + } + + public Level getWorld() { + return world; + } + + @Nullable + public Player getPlayer() { + return player; + } + + public boolean isClient() { + return world.isClientSide(); + } +} 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..3ac396201 --- /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.world.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..6defd4f25 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/item/InventoryTickEvent.java @@ -0,0 +1,116 @@ +package net.pitan76.mcpitanlib.api.event.item; + +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EquipmentSlot; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.item.ItemStack; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.Level; +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.util.WorldUtil; +import net.pitan76.mcpitanlib.api.util.entity.EquipmentSlotUtil; +import net.pitan76.mcpitanlib.api.util.entity.LivingEntityUtil; +import net.pitan76.mcpitanlib.midohra.entity.EntityWrapper; + +public class InventoryTickEvent extends BaseEvent { + public ItemStack stack; + public Level world; + public Entity entity; + public int slot; + public boolean selected; + public EquipmentSlot equipmentSlot; + + public InventoryTickEvent(ItemStack stack, Level 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, ServerLevel 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.is(stack.getItem()) && equippedStack.getCount() == stack.getCount(); + } else { + return false; + } + } + + public ItemStack getStack() { + return stack; + } + + public Level getWorld() { + return world; + } + + public boolean isServer() { + return !isClient(); + } + + public ServerLevel getServerWorld() { + return (ServerLevel) 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; + } + + public ArmorEquipmentType getArmorEquipmentType() { + return EquipmentSlotUtil.getArmorEquipmentType(equipmentSlot); + } + + public boolean isPlayer() { + return getEntity() instanceof net.minecraft.world.entity.player.Player; + } + + public Player getPlayer() { + if (isPlayer()) { + return new Player((net.minecraft.world.entity.player.Player) getEntity()); + } else { + return null; + } + } + + public EntityWrapper getEntityWrapper() { + return EntityWrapper.of(getEntity()); + } + + public net.pitan76.mcpitanlib.midohra.world.World getMidohraWorld() { + return net.pitan76.mcpitanlib.midohra.world.World.of(getWorld()); + } + + public net.pitan76.mcpitanlib.midohra.item.ItemStack getStackM() { + return net.pitan76.mcpitanlib.midohra.item.ItemStack.of(getStack()); + } + + public net.pitan76.mcpitanlib.midohra.world.ServerWorld getServerWorldM() { + return net.pitan76.mcpitanlib.midohra.world.ServerWorld.of(getServerWorld()); + } +} 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..0e4b5d1fb --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/item/ItemAppendTooltipEvent.java @@ -0,0 +1,113 @@ +package net.pitan76.mcpitanlib.api.event.item; + +import net.minecraft.world.item.component.TooltipDisplay; +import net.minecraft.world.item.TooltipFlag; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.network.chat.Component; +import net.minecraft.world.level.Level; +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 net.pitan76.mcpitanlib.api.util.TextUtil; +import org.jetbrains.annotations.Nullable; + +import java.util.ArrayList; +import java.util.List; +import java.util.function.Consumer; +import java.util.stream.Collectors; + +public class ItemAppendTooltipEvent extends BaseEvent { + public ItemStack stack; + + @Deprecated + public Level world; + + @Deprecated + public List tooltip; + + public TooltipFlag type; + public Item.TooltipContext context; + + public TooltipDisplay displayComponent; + public Consumer textConsumer; + + public ItemAppendTooltipEvent(ItemStack stack, @Nullable Level world, List tooltip, TooltipFlag type, Item.TooltipContext context) { + this.stack = stack; + this.world = world; + this.tooltip = tooltip; + this.type = type; + this.context = context; + } + + public ItemAppendTooltipEvent(ItemStack stack, Item.TooltipContext context, TooltipDisplay displayComponent, Consumer textConsumer, TooltipFlag type) { + this.stack = stack; + this.context = context; + this.displayComponent = displayComponent; + this.textConsumer = textConsumer; + this.type = type; + } + + public ItemStack getStack() { + return stack; + } + + public Level getWorld() { + return world; + } + + public List getTooltip() { + return new ArrayList<>(); + } + + public Item.TooltipContext getContext() { + return context; + } + + public void addTooltip(Component text) { + textConsumer.accept(text); + } + + public void addTooltip(List texts) { + for (Component text : texts) { + addTooltip(text); + } + } + + public boolean removeTooltip(Component text) { + return false; + } + + 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()); + } + + public void addTooltip(String text) { + addTooltip(TextUtil.literal(text)); + } + + public net.pitan76.mcpitanlib.midohra.world.World getWorldM() { + return net.pitan76.mcpitanlib.midohra.world.World.of(getWorld()); + } + + public net.pitan76.mcpitanlib.midohra.item.ItemStack getStackM() { + return net.pitan76.mcpitanlib.midohra.item.ItemStack.of(getStack()); + } + + public List getCompatTooltip() { + return getTooltip().stream().map(TextComponent::new).collect(Collectors.toList()); + } +} 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..e81d85983 --- /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.world.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..09b0d2971 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/item/ItemBarStepArgs.java @@ -0,0 +1,20 @@ +package net.pitan76.mcpitanlib.api.event.item; + +import net.minecraft.world.item.ItemStack; + +public class ItemBarStepArgs { + + public ItemStack stack; + + public ItemBarStepArgs(ItemStack stack) { + this.stack = stack; + } + + public ItemStack getStack() { + return stack; + } + + public net.pitan76.mcpitanlib.midohra.item.ItemStack getStackM() { + return net.pitan76.mcpitanlib.midohra.item.ItemStack.of(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..5a95772fe --- /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.world.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..3a4b6ce7d --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/item/ItemFinishUsingEvent.java @@ -0,0 +1,52 @@ +package net.pitan76.mcpitanlib.api.event.item; + +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; +import net.pitan76.mcpitanlib.api.event.BaseEvent; +import net.pitan76.mcpitanlib.midohra.item.ItemWrapper; + +public class ItemFinishUsingEvent extends BaseEvent { + public ItemStack stack; + public Level world; + public LivingEntity user; + + public ItemFinishUsingEvent(ItemStack stack, Level world, LivingEntity user) { + this.stack = stack; + this.world = world; + this.user = user; + } + + public ItemStack getStack() { + return stack; + } + + public Level getWorld() { + return world; + } + + public LivingEntity getUser() { + return user; + } + + public boolean isClient() { + return world.isClientSide(); + } + + public net.pitan76.mcpitanlib.midohra.item.ItemStack getStackM() { + return net.pitan76.mcpitanlib.midohra.item.ItemStack.of(stack); + } + + public net.pitan76.mcpitanlib.midohra.world.World getWorldM() { + return net.pitan76.mcpitanlib.midohra.world.World.of(world); + } + + public Item getItem() { + return stack.getItem(); + } + + public ItemWrapper getItemWrapper() { + return ItemWrapper.of(getItem()); + } +} 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..9f367c4e5 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/item/ItemUseEvent.java @@ -0,0 +1,121 @@ +package net.pitan76.mcpitanlib.api.event.item; + +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.level.Level; +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.item.ItemWrapper; +import net.pitan76.mcpitanlib.midohra.world.IWorldView; + +public class ItemUseEvent extends BaseEvent { + + public Level world; + public Player user; + public InteractionHand hand; + public ItemStack stack; + + public ItemUseEvent(Level world, net.minecraft.world.entity.player.Player user, InteractionHand hand) { + this.world = world; + this.user = new Player(user); + this.hand = hand; + this.stack = user.getItemInHand(hand); + } + + public ItemStack getStack() { + return stack; + } + + public net.pitan76.mcpitanlib.midohra.item.ItemStack getMidohraStack() { + return net.pitan76.mcpitanlib.midohra.item.ItemStack.of(stack); + } + + public InteractionHand getHand() { + return hand; + } + + public Level getWorld() { + return world; + } + + public Player getUser() { + return user; + } + + public boolean isClient() { + return world.isClientSide(); + } + + 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); + } + + public StackActionResult fail() { + return StackActionResult.fail(); + } + + public StackActionResult fail(net.pitan76.mcpitanlib.midohra.item.ItemStack stack) { + return StackActionResult.fail(stack.toMinecraft()); + } + + public StackActionResult pass() { + return StackActionResult.pass(); + } + + 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); + } + + 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(); + } + + public net.pitan76.mcpitanlib.midohra.item.ItemStack getStackM() { + return net.pitan76.mcpitanlib.midohra.item.ItemStack.of(getStack()); + } + + public Item getItem() { + return stack.getItem(); + } + + public ItemWrapper getItemWrapper() { + return ItemWrapper.of(getItem()); + } +} 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..c2d383e20 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/item/ItemUseOnBlockEvent.java @@ -0,0 +1,157 @@ +package net.pitan76.mcpitanlib.api.event.item; + +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.context.UseOnContext; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.phys.Vec3; +import net.minecraft.world.level.Level; +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.item.ItemWrapper; +import net.pitan76.mcpitanlib.midohra.world.IWorldView; +import org.jetbrains.annotations.Nullable; + +public class ItemUseOnBlockEvent extends BaseEvent { + public Player player; + public InteractionHand hand; + public BlockHitResult hit; + public ItemStack stack; + public Level world; + public BlockPos blockPos; + + public ItemUseOnBlockEvent(net.minecraft.world.entity.player.Player player, InteractionHand hand, BlockHitResult hit) { + this(player.level(), player, hand, player.getItemInHand(hand), hit); + } + + public ItemUseOnBlockEvent(Level world, @Nullable net.minecraft.world.entity.player.Player player, InteractionHand 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, InteractionHand hand, BlockHitResult hit) { + this(player.getWorld(), player.getEntity(), hand, player.getStackInHand(hand), hit); + } + + public UseOnContext toIUC() { + return new UseOnContext(player.getPlayerEntity(), hand, hit); + } + + public boolean isClient() { + return world.isClientSide(); + } + + public Player getPlayer() { + return player; + } + + public Level getWorld() { + return world; + } + + public BlockHitResult getHit() { + return hit; + } + + public BlockPos getBlockPos() { + return blockPos; + } + + public InteractionHand 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 Vec3 getPos() { + return hit.getLocation(); + } + + public Direction getSide() { + return hit.getDirection(); + } + + 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()); + } + + public boolean isSneaking() { + return player.isSneaking(); + } + + public net.pitan76.mcpitanlib.midohra.item.ItemStack getStackM() { + return net.pitan76.mcpitanlib.midohra.item.ItemStack.of(stack); + } + + public Item getItem() { + return stack.getItem(); + } + + public ItemWrapper getItemWrapper() { + return ItemWrapper.of(getItem()); + } +} 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..cd181ac54 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/item/ItemUseOnEntityEvent.java @@ -0,0 +1,89 @@ +package net.pitan76.mcpitanlib.api.event.item; + +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.InteractionHand; +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.midohra.entity.EntityWrapper; +import net.pitan76.mcpitanlib.midohra.item.ItemWrapper; + +public class ItemUseOnEntityEvent extends BaseEvent { + + public ItemStack stack; + public Player user; + public LivingEntity entity; + public InteractionHand hand; + + public ItemUseOnEntityEvent(ItemStack stack, net.minecraft.world.entity.player.Player user, LivingEntity entity, InteractionHand hand) { + this.stack = stack; + this.user = new Player(user); + this.hand = hand; + this.entity = entity; + } + + public ItemUseOnEntityEvent(ItemStack stack, Player user, LivingEntity entity, InteractionHand hand) { + this.stack = stack; + this.user = user; + this.hand = hand; + this.entity = entity; + } + + public ItemStack getStack() { + return stack; + } + + public InteractionHand 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; + } + + public boolean isSneaking() { + return user.isSneaking(); + } + + public net.pitan76.mcpitanlib.midohra.item.ItemStack getStackM() { + return net.pitan76.mcpitanlib.midohra.item.ItemStack.of(stack); + } + + public Item getItem() { + return stack.getItem(); + } + + public ItemWrapper getItemWrapper() { + return ItemWrapper.of(getItem()); + } + + public EntityWrapper getEntityWrapper() { + return EntityWrapper.of(getEntity()); + } +} 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..c602d0973 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/item/PostHitEvent.java @@ -0,0 +1,57 @@ +package net.pitan76.mcpitanlib.api.event.item; + +import net.minecraft.world.entity.EquipmentSlot; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.item.ItemStack; +import net.pitan76.mcpitanlib.api.event.BaseEvent; +import net.pitan76.mcpitanlib.api.item.ArmorEquipmentType; +import net.pitan76.mcpitanlib.midohra.entity.EntityWrapper; + +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.hurtAndBreak(amount, attacker, slot); + } + + public net.pitan76.mcpitanlib.midohra.item.ItemStack getStackM() { + return net.pitan76.mcpitanlib.midohra.item.ItemStack.of(getStack()); + } + + public EntityWrapper getAttackerM() { + return EntityWrapper.of(getAttacker()); + } + + public EntityWrapper getTargetM() { + return EntityWrapper.of(getTarget()); + } + + public void damageStack(int amount, ArmorEquipmentType type) { + damageStack(amount, type.getSlot()); + } +} 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..4fb7744fb --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/item/PostMineEvent.java @@ -0,0 +1,157 @@ +package net.pitan76.mcpitanlib.api.event.item; + +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.entity.EquipmentSlot; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.item.ItemStack; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +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; +import net.pitan76.mcpitanlib.midohra.block.BlockWrapper; +import net.pitan76.mcpitanlib.midohra.block.entity.BlockEntityWrapper; +import net.pitan76.mcpitanlib.midohra.entity.EntityWrapper; +import net.pitan76.mcpitanlib.midohra.world.World; + +public class PostMineEvent extends BaseEvent { + public ItemStack stack; + public Level world; + public BlockState state; + public BlockPos pos; + public LivingEntity miner; + + public PostMineEvent(ItemStack stack, Level 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 Level 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.isClientSide(); + } + + 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.hurtAndBreak(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.hurtAndBreak(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.hurtAndBreak(amount, miner, EquipmentSlot.MAINHAND); + } + + public boolean isPlayer() { + return miner instanceof net.minecraft.world.entity.player.Player; + } + + public Player getPlayer() { + if (isPlayer()) + return new Player((net.minecraft.world.entity.player.Player) miner); + + return null; + } + + public boolean isCreative() { + return isPlayer() && getPlayer().isCreative(); + } + + public boolean isSneaking() { + return miner.isShiftKeyDown(); + } + + public ItemStack getMainHandStack() { + return miner.getMainHandItem(); + } + + public net.pitan76.mcpitanlib.midohra.item.ItemStack getStackM() { + return net.pitan76.mcpitanlib.midohra.item.ItemStack.of(getStack()); + } + + public net.pitan76.mcpitanlib.midohra.item.ItemStack getMainHandStackM() { + return net.pitan76.mcpitanlib.midohra.item.ItemStack.of(getMainHandStack()); + } + + public World getWorldM() { + return World.of(getWorld()); + } + + public net.pitan76.mcpitanlib.midohra.block.BlockState getStateM() { + return net.pitan76.mcpitanlib.midohra.block.BlockState.of(getState()); + } + + public net.pitan76.mcpitanlib.midohra.util.math.BlockPos getPosM() { + return net.pitan76.mcpitanlib.midohra.util.math.BlockPos.of(getPos()); + } + + public BlockEntityWrapper getBlockEntityM() { + BlockEntity blockEntity = getBlockEntity(); + if (blockEntity != null) { + return BlockEntityWrapper.of(blockEntity); + } + return null; + } + + public EntityWrapper getMinerM() { + return EntityWrapper.of(getMiner()); + } + + public boolean stateIsOf(BlockWrapper block) { + return stateIsOf(block.get()); + } +} 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..45e32ff4d --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/nbt/NbtRWArgs.java @@ -0,0 +1,64 @@ +package net.pitan76.mcpitanlib.api.event.nbt; + +import net.minecraft.nbt.CompoundTag; +import net.minecraft.core.HolderLookup; +import net.pitan76.mcpitanlib.api.registry.CompatRegistryLookup; + +public class NbtRWArgs { + public CompoundTag nbt; + public CompatRegistryLookup registryLookup; + + public NbtRWArgs(CompoundTag nbt, CompatRegistryLookup registryLookup) { + this.nbt = nbt; + this.registryLookup = registryLookup; + } + + @Deprecated + public NbtRWArgs(CompoundTag nbt, HolderLookup.Provider wrapperLookup) { + this(nbt, new CompatRegistryLookup(wrapperLookup)); + } + + public NbtRWArgs(CompoundTag nbt) { + this(nbt, (CompatRegistryLookup) null); + } + + public CompoundTag getNbt() { + return nbt; + } + + public CompatRegistryLookup getRegistryLookup() { + return registryLookup; + } + + public boolean hasRegistryLookup() { + return registryLookup != null; + } + + @Deprecated + public HolderLookup.Provider 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); + } + + public net.pitan76.mcpitanlib.midohra.nbt.NbtCompound getNbtM() { + return net.pitan76.mcpitanlib.midohra.nbt.NbtCompound.of(nbt); + } +} 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..45c0d5ef0 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/nbt/ReadNbtArgs.java @@ -0,0 +1,60 @@ +package net.pitan76.mcpitanlib.api.event.nbt; + +import net.minecraft.nbt.CompoundTag; +import net.minecraft.core.HolderLookup; +import net.minecraft.world.level.storage.TagValueInput; +import net.minecraft.world.level.storage.ValueInput; +import net.pitan76.mcpitanlib.api.registry.CompatRegistryLookup; +import net.pitan76.mcpitanlib.core.mc1216.NbtDataConverter; + +public class ReadNbtArgs extends NbtRWArgs { + @Deprecated + public ValueInput view; + + @Deprecated + public ReadNbtArgs(CompoundTag nbt, HolderLookup.Provider wrapperLookup) { + super(nbt, wrapperLookup); + } + + public ReadNbtArgs(CompoundTag nbt) { + super(nbt); + if (registryLookup == null) + registryLookup = new CompatRegistryLookup(); + view = NbtDataConverter.nbt2readData(nbt, registryLookup); + } + + public ReadNbtArgs(CompoundTag nbt, CompatRegistryLookup registryLookup) { + super(nbt, registryLookup); + view = NbtDataConverter.nbt2readData(nbt, registryLookup); + } + + @Deprecated + public ReadNbtArgs(CompoundTag nbt, ValueInput view) { + this(nbt); + this.view = view; + } + + @Deprecated + public ReadNbtArgs(CompoundTag nbt, ValueInput view, CompatRegistryLookup registryLookup) { + this(nbt, registryLookup); + this.view = view; + } + + @Override + public boolean isViewEmpty() { + return view == null; + } + + @Override + public NbtRWArgs copy() { + return new ReadNbtArgs(nbt.copy(), view, registryLookup); + } + + public ReadNbtArgs(net.pitan76.mcpitanlib.midohra.nbt.NbtCompound nbt, CompatRegistryLookup registryLookup) { + this(nbt.toMinecraft(), registryLookup); + } + + public ReadNbtArgs(net.pitan76.mcpitanlib.midohra.nbt.NbtCompound nbt) { + this(nbt.toMinecraft()); + } +} 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..c702ada20 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/nbt/WriteNbtArgs.java @@ -0,0 +1,57 @@ +package net.pitan76.mcpitanlib.api.event.nbt; + +import net.minecraft.nbt.CompoundTag; +import net.minecraft.core.HolderLookup; +import net.minecraft.world.level.storage.ValueOutput; +import net.pitan76.mcpitanlib.api.registry.CompatRegistryLookup; +import net.pitan76.mcpitanlib.core.mc1216.NbtDataConverter; + +public class WriteNbtArgs extends NbtRWArgs { + @Deprecated + public ValueOutput view; + + @Deprecated + public WriteNbtArgs(CompoundTag nbt, HolderLookup.Provider wrapperLookup) { + super(nbt, wrapperLookup); + } + + public WriteNbtArgs(CompoundTag nbt, CompatRegistryLookup registryLookup) { + super(nbt, registryLookup); + view = NbtDataConverter.nbt2writeData(nbt, registryLookup); + } + + public WriteNbtArgs(CompoundTag nbt) { + super(nbt); + view = NbtDataConverter.nbt2writeData(nbt, (CompatRegistryLookup) null); + } + + @Deprecated + public WriteNbtArgs(CompoundTag nbt, ValueOutput view) { + this(nbt); + this.view = view; + } + + @Deprecated + public WriteNbtArgs(CompoundTag nbt, ValueOutput view, CompatRegistryLookup registryLookup) { + this(nbt, registryLookup); + this.view = view; + } + + @Override + public boolean isViewEmpty() { + return view == null; + } + + @Override + public NbtRWArgs copy() { + return new WriteNbtArgs(nbt.copy(), view, registryLookup); + } + + public WriteNbtArgs(net.pitan76.mcpitanlib.midohra.nbt.NbtCompound nbt, CompatRegistryLookup registryLookup) { + this(nbt.toMinecraft(), registryLookup); + } + + public WriteNbtArgs(net.pitan76.mcpitanlib.midohra.nbt.NbtCompound nbt) { + this(nbt.toMinecraft()); + } +} 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..90fd66d05 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/result/EventResult.java @@ -0,0 +1,44 @@ +package net.pitan76.mcpitanlib.api.event.result; + +import net.minecraft.world.InteractionResult; +import net.pitan76.mcpitanlib.api.util.CompatActionResult; + +public class EventResult { + private static final EventResult TRUE = new EventResult(); + private static final EventResult STOP = new EventResult(); + private static final EventResult PASS = new EventResult(); + private static final EventResult FALSE = new EventResult(); + + + protected EventResult() { + + } + + public static EventResult success() { + return TRUE; + } + + public static EventResult stop() { + return STOP; + } + + public static EventResult pass() { + return PASS; + } + + public static EventResult fail() { + return FALSE; + } + + public InteractionResult toActionResult() { + if (this == TRUE) return InteractionResult.SUCCESS; + if (this == STOP) return InteractionResult.FAIL; + if (this == PASS) return InteractionResult.PASS; + if (this == FALSE) return InteractionResult.FAIL; + throw new IllegalStateException("Unknown EventResult: " + this); + } + + 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..437908aab --- /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 net.minecraft.world.item.ItemStack; +import net.minecraft.world.InteractionResult; +import net.pitan76.mcpitanlib.api.util.CompatActionResult; + +public class TypedEventResult { + protected final InteractionResult result; + protected final T object; + + protected TypedEventResult(InteractionResult result, T object) { + this.result = result; + this.object = object; + } + + public static TypedEventResult success(T value) { + return new TypedEventResult<>(InteractionResult.SUCCESS, value); + } + + public static TypedEventResult stop(T value) { + return new TypedEventResult<>(InteractionResult.FAIL, value); + } + + public static TypedEventResult pass() { + return new TypedEventResult<>(InteractionResult.PASS, null); + } + + public static TypedEventResult fail(T value) { + return new TypedEventResult<>(InteractionResult.FAIL, value); + } + + @Deprecated + public InteractionResult getResult() { + return result; + } + + public InteractionResult toActionResult() { + return result; + } + + public CompatActionResult toCompatActionResult() { + return CompatActionResult.of(result); + } + + public CompatActionResult toCompatActionResult(ItemStack stack) { + if (object != stack) + return toCompatActionResult(); + + if (toActionResult() instanceof InteractionResult.Success) { + InteractionResult.Success success = (InteractionResult.Success) toActionResult(); + + return CompatActionResult.create(success.heldItemTransformedTo(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..1b26b63b2 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/tile/TileTickEvent.java @@ -0,0 +1,103 @@ +package net.pitan76.mcpitanlib.api.event.tile; + +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +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; +import net.pitan76.mcpitanlib.midohra.world.ServerWorld; + +import java.util.Optional; + +public class TileTickEvent implements BlockStatePropertyHolder { + public Level world; + public BlockPos pos; + public BlockState state; + public T blockEntity; + + public TileTickEvent(Level world, BlockPos pos, BlockState state, T blockEntity) { + this.world = world; + this.pos = pos; + this.state = state; + this.blockEntity = blockEntity; + } + + public boolean isClient() { + return world.isClientSide(); + } + + public boolean isServer() { + return !isClient(); + } + + public boolean hasWorld() { + return world != null; + } + + public Level 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()); + } + + public Optional getOptionalServerWorld() { + return getMidohraWorld().toServerWorld(); + } + + public ServerWorld getServerWorld() { + return getOptionalServerWorld().orElse(null); + } +} 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..66575afd4 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/v0/AttackEntityEventRegistry.java @@ -0,0 +1,27 @@ +package net.pitan76.mcpitanlib.api.event.v0; + +import dev.architectury.injectables.annotations.ExpectPlatform; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.phys.EntityHitResult; +import net.minecraft.world.level.Level; +import net.pitan76.mcpitanlib.api.entity.Player; +import net.pitan76.mcpitanlib.api.util.CompatActionResult; +import org.jetbrains.annotations.Nullable; + +@Deprecated +public class AttackEntityEventRegistry { + @ExpectPlatform + public static void register(AttackEntity attackEntity) { + + } + + public interface AttackEntity { + default InteractionResult attack(net.minecraft.world.entity.player.Player player, Level level, InteractionHand hand, Entity target, @Nullable EntityHitResult result) { + return attack(new Player(player), level, target, hand, result).toActionResult(); + } + + CompatActionResult attack(Player player, Level level, Entity target, InteractionHand 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..2d05a102a --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/v0/ClientTickEventRegistry.java @@ -0,0 +1,38 @@ +package net.pitan76.mcpitanlib.api.event.v0; + +import dev.architectury.injectables.annotations.ExpectPlatform; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.Minecraft; + +public class ClientTickEventRegistry { + @ExpectPlatform + public static void registerPost(Client client) { + + } + + @ExpectPlatform + public static void registerPre(Client client) { + + } + + @ExpectPlatform + public static void registerLevelPost(ClientLevel world) { + + } + + @ExpectPlatform + public static void registerLevelPre(ClientLevel world) { + + } + + @Environment(EnvType.CLIENT) + public interface Client { + void tick(Minecraft instance); + } + + @Environment(EnvType.CLIENT) + public interface ClientLevel { + void tick(net.minecraft.client.multiplayer.ClientLevel 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..533e6982b --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/v0/EventRegistry.java @@ -0,0 +1,94 @@ +package net.pitan76.mcpitanlib.api.event.v0; + +import dev.architectury.injectables.annotations.ExpectPlatform; +import net.minecraft.world.item.ItemStack; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.Level; +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(ServerPlayer player); + } + + public interface PlayerQuit { + void quit(ServerPlayer 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 + @ExpectPlatform + public static void serverStarted(ServerState state) { + + } + + @ExpectPlatform + public static void serverStarting(ServerState state) { + + } + + @ExpectPlatform + public static void serverStopped(ServerState state) { + + } + + @ExpectPlatform + public static void serverStopping(ServerState state) { + + } + + @ExpectPlatform + public static void serverWorldLoad(ServerWorldState state) { + + } + + @ExpectPlatform + public static void serverWorldSave(ServerWorldState state) { + + } + + @ExpectPlatform + public static void serverWorldUnload(ServerWorldState state) { + + } + + 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..1bf7e6e9c --- /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.injectables.annotations.ExpectPlatform; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.InteractionHand; +import net.pitan76.mcpitanlib.api.entity.Player; +import net.pitan76.mcpitanlib.api.event.result.EventResult; +import net.pitan76.mcpitanlib.api.event.v0.event.ClickBlockEvent; +import net.pitan76.mcpitanlib.api.util.CompatActionResult; + +public class InteractionEventRegistry { + @ExpectPlatform + public static void registerRightClickBlock(RightClickBlock rightClickBlock) { + } + + @ExpectPlatform + public static void registerLeftClickBlock(LeftClickBlock leftClickBlock) { + + } + + @ExpectPlatform + public static void registerRightClickItem(RightClickItem rightClickItem) { + + } + + @ExpectPlatform + public static void registerClientLeftClickAir(ClientLeftClickAir clientLeftClickAir) { + + } + + @ExpectPlatform + public static void registerClientRightClickAir(ClientRightClickAir clientRightClickAir) { + + } + + @ExpectPlatform + public static void registerInteractEntity(InteractEntity interactEntity) { + + } + + // ---- + + public interface LeftClickBlock { + EventResult click(ClickBlockEvent event); + } + + public interface RightClickBlock { + EventResult click(ClickBlockEvent event); + } + + public interface RightClickItem { + default InteractionResult click2(net.minecraft.world.entity.player.Player var1, InteractionHand var2) { + return click(new Player(var1), var2).toActionResult(); + } + + CompatActionResult click(Player player, InteractionHand hand); + } + + public interface ClientLeftClickAir { + default void click(net.minecraft.world.entity.player.Player var1, InteractionHand var2) { + click(new Player(var1), var2); + } + + void click(Player player, InteractionHand hand); + } + + public interface ClientRightClickAir { + default void click(net.minecraft.world.entity.player.Player var1, InteractionHand var2) { + click(new Player(var1), var2); + } + + void click(Player player, InteractionHand hand); + } + + public interface InteractEntity { + @SuppressWarnings("deprecation") + default InteractionResult interact(net.minecraft.world.entity.player.Player var1, Entity var2, InteractionHand var3) { + return interact(new Player(var1), var2, var3).toActionResult(); + } + + CompatActionResult interact(Player player, Entity entity, InteractionHand 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..68956b8ea --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/v0/LivingHurtEventRegistry.java @@ -0,0 +1,24 @@ +package net.pitan76.mcpitanlib.api.event.v0; + +import dev.architectury.injectables.annotations.ExpectPlatform; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.damagesource.DamageSource; +import net.pitan76.mcpitanlib.api.event.result.EventResult; +import net.pitan76.mcpitanlib.api.event.v0.event.LivingHurtEvent; + +@Deprecated +public class LivingHurtEventRegistry { + @ExpectPlatform + public static void register(LivingHurt livingHurt) { + + } + + public interface LivingHurt { + default boolean hurt(LivingEntity var1, DamageSource var2, float var3) { + return hurt(new LivingHurtEvent(var1, var2, var3)).toActionResult() == InteractionResult.SUCCESS; + } + + 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..d7247e6f4 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/v0/event/ClickBlockEvent.java @@ -0,0 +1,77 @@ +package net.pitan76.mcpitanlib.api.event.v0.event; + +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.InteractionHand; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.level.Level; +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 InteractionHand hand; + public BlockPos pos; + public Direction direction; + + public ClickBlockEvent(Player player, InteractionHand hand, BlockPos pos, Direction direction) { + this.player = player; + this.hand = hand; + this.pos = pos; + this.direction = direction; + } + + public ClickBlockEvent(net.minecraft.world.entity.player.Player player, InteractionHand 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 InteractionHand 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 Level 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..07e2b0095 --- /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.world.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..1e98c59e0 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/v0/event/LivingHurtEvent.java @@ -0,0 +1,82 @@ +package net.pitan76.mcpitanlib.api.event.v0.event; + +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; +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.getEntity(); + } + + public Entity getSource() { + return damageSource.getDirectEntity(); + } + + public boolean isDirect() { + return damageSource.isDirect(); + } + + public boolean isPlayerAttacker() { + return getAttacker() instanceof net.minecraft.world.entity.player.Player; + } + + public net.minecraft.world.entity.player.Player getPlayerEntityAttacker() { + return (net.minecraft.world.entity.player.Player) getAttacker(); + } + + public Player getPlayerAttacker() { + return new Player(getPlayerEntityAttacker()); + } + + public Level getWorld() { + return entity.level(); + } + + public boolean isClient() { + return getWorld().isClientSide(); + } + + public ItemStack getWeaponStack() { + return getAttacker().getWeaponItem(); + } + + 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..35a3171d2 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/v0/event/RecipeManagerEvent.java @@ -0,0 +1,59 @@ +package net.pitan76.mcpitanlib.api.event.v0.event; + +import net.minecraft.world.item.crafting.Recipe; +import net.minecraft.server.packs.resources.ResourceManager; +import net.minecraft.resources.Identifier; +import net.minecraft.util.profiling.ProfilerFiller; +import net.pitan76.mcpitanlib.api.recipe.CompatibleRecipeEntry; +import net.pitan76.mcpitanlib.api.recipe.v2.CompatRecipeEntry; +import net.pitan76.mcpitanlib.api.recipe.v3.CompatRecipe; +import net.pitan76.mcpitanlib.midohra.recipe.entry.RecipeEntry; + +import java.util.SortedMap; + +public class RecipeManagerEvent { + + @Deprecated + private SortedMap> sortedMap; + + public ResourceManager resourceManager; + public ProfilerFiller profiler; + + public RecipeManagerEvent(SortedMap> sortedMap, ResourceManager resourceManager, ProfilerFiller profiler) { + this.sortedMap = sortedMap; + this.resourceManager = resourceManager; + this.profiler = profiler; + } + + public ProfilerFiller 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) { + sortedMap.put(entry.getId(), entry.getRecipe()); + } + + public > void putCompatibleRecipeEntry(CompatRecipeEntry entry) { + sortedMap.put(entry.getId(), entry.getRecipe()); + } + + public void putRecipeEntry(RecipeEntry entry) { + sortedMap.put(entry.getId().toMinecraft(), entry.getRawRecipe()); + } + + public void putRecipe(CompatRecipe recipe) { + sortedMap.put(recipe.getId(), recipe.getRecipe()); + } +} 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..06eed0e8b --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/v0/event/ServerConnectionEvent.java @@ -0,0 +1,17 @@ +package net.pitan76.mcpitanlib.api.event.v0.event; + +import dev.architectury.injectables.annotations.ExpectPlatform; +import net.pitan76.mcpitanlib.api.event.v0.EventRegistry; + +public class ServerConnectionEvent { + // Architectury: PlayerEvent + @ExpectPlatform + public static void join(EventRegistry.ServerConnection.PlayerJoin state) { + + } + + @ExpectPlatform + public static void quit(EventRegistry.ServerConnection.PlayerQuit state) { + + } +} 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..ca5b033ac --- /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.injectables.annotations.ExpectPlatform; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.phys.EntityHitResult; +import net.minecraft.world.level.Level; +import net.pitan76.mcpitanlib.api.event.v1.event.AttackEntityEvent; +import net.pitan76.mcpitanlib.api.util.CompatActionResult; +import org.jetbrains.annotations.Nullable; + +public class AttackEntityEventRegistry { + @ExpectPlatform + public static void register(AttackEntity attackEntity) { + + } + + public interface AttackEntity { + default InteractionResult attack(net.minecraft.world.entity.player.Player player, Level level, InteractionHand hand, Entity target, @Nullable EntityHitResult result) { + return attack(new AttackEntityEvent(player, level, target, hand, result)).toActionResult(); + } + + 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..54cdbcd2e --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/v1/LivingHurtEventRegistry.java @@ -0,0 +1,24 @@ +package net.pitan76.mcpitanlib.api.event.v1; + +import dev.architectury.injectables.annotations.ExpectPlatform; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.damagesource.DamageSource; +import net.pitan76.mcpitanlib.api.event.v0.event.LivingHurtEvent; + +public class LivingHurtEventRegistry { + @ExpectPlatform + public static void register(LivingHurt livingHurt) { + + } + + public interface LivingHurt { + + @SuppressWarnings("deprecation") + default boolean hurt(LivingEntity var1, DamageSource var2, float var3) { + return hurt(new LivingHurtEvent(var1, var2, var3)).toActionResult() == InteractionResult.SUCCESS; + } + + 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..2ec2075a7 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/v1/event/AttackEntityEvent.java @@ -0,0 +1,72 @@ +package net.pitan76.mcpitanlib.api.event.v1.event; + +import net.minecraft.world.entity.Entity; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.phys.EntityHitResult; +import net.minecraft.world.level.Level; +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 Level world; + public Entity target; + public InteractionHand hand; + public EntityHitResult result; + + public AttackEntityEvent(net.minecraft.world.entity.player.Player player, Level level, Entity target, InteractionHand hand, @Nullable EntityHitResult result) { + this(new Player(player), level, target, hand, result); + } + + public AttackEntityEvent(Player player, Level level, Entity target, InteractionHand 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 Level getWorld() { + return world; + } + + public Entity getTarget() { + return target; + } + + public EntityHitResult getResult() { + return result; + } + + public InteractionHand 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..19fada63a --- /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.world.level.block.Block; +import net.minecraft.resources.Identifier; +import net.minecraft.world.level.levelgen.GenerationStep; +import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; +import net.minecraft.world.level.levelgen.placement.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).withSuffix("_ore_feature"); + RegistryResult> configuredFuture = registry.registerFeature(identifier, + () -> FeatureConfigUtil.createConfiguredFeature( + FeatureConfigUtil.createStoneOreFeatureConfig(block.defaultBlockState(), size) + ) + ); + + RegistryResult placedFeature = registry.registerPlacedFeature(identifier, + () -> PlacedFutureUtil.create(configuredFuture.getOrNull(), + PlacedFutureUtil.createPlacementModifiers(count, height) + ) + ); + + WorldGenRegistry.addProperties(GenerationStep.Decoration.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..a1a8b6229 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/gui/ExtendedNamedScreenHandlerFactory.java @@ -0,0 +1,50 @@ +package net.pitan76.mcpitanlib.api.gui; + +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.MenuConstructor; +import net.minecraft.network.chat.Component; +import net.pitan76.mcpitanlib.api.network.PacketByteUtil; +import net.pitan76.mcpitanlib.core.mc261.ExtendedMenuProvider; +import org.jetbrains.annotations.Nullable; + +@Deprecated +public class ExtendedNamedScreenHandlerFactory implements ExtendedMenuProvider { + + private final Component name; + private final MenuConstructor baseFactory; + private final PacketByteBufFactory bufFactory; + + public ExtendedNamedScreenHandlerFactory(Component name, MenuConstructor baseFactory, PacketByteBufFactory bufFactory) { + this.name = name; + this.baseFactory = baseFactory; + this.bufFactory = bufFactory; + } + + @Override + public Component getDisplayName() { + return name; + } + + @Nullable + @Override + public AbstractContainerMenu createMenu(int syncId, Inventory inv, Player player) { + return baseFactory.createMenu(syncId, inv, player); + + } + + @Override + public FriendlyByteBuf getScreenOpeningData(ServerPlayer player) { + FriendlyByteBuf buf = PacketByteUtil.create(); + bufFactory.saveExtraData(buf); + return buf; + } + + @FunctionalInterface + public interface PacketByteBufFactory { + void saveExtraData(FriendlyByteBuf 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..6454e86e5 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/gui/ExtendedScreenHandler.java @@ -0,0 +1,33 @@ +package net.pitan76.mcpitanlib.api.gui; + +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.world.inventory.MenuType; +import net.pitan76.mcpitanlib.midohra.network.IByteBuf; +import net.pitan76.mcpitanlib.midohra.screen.ScreenHandlerTypeWrapper; +import org.jetbrains.annotations.Nullable; + +public class ExtendedScreenHandler extends SimpleScreenHandler { + protected ExtendedScreenHandler(@Nullable MenuType type, int syncId, FriendlyByteBuf buf) { + this(type, syncId); + } + + protected ExtendedScreenHandler(@Nullable MenuType type, int syncId) { + super(type, syncId); + } + + protected ExtendedScreenHandler(@Nullable MenuType type, int syncId, IByteBuf buf) { + this(type, syncId, buf.toRaw()); + } + + protected ExtendedScreenHandler(ScreenHandlerTypeWrapper type, int syncId) { + this(type.get(), syncId); + } + + protected ExtendedScreenHandler(ScreenHandlerTypeWrapper type, int syncId, IByteBuf buf) { + this(type.get(), syncId, buf); + } + + protected ExtendedScreenHandler(ScreenHandlerTypeWrapper type, int syncId, net.pitan76.mcpitanlib.midohra.network.PacketByteBuf buf) { + this(type.get(), syncId, buf); + } +} 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..08ce5f056 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/gui/ExtendedScreenHandlerFactory.java @@ -0,0 +1,28 @@ +package net.pitan76.mcpitanlib.api.gui; + +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.chat.Component; +import net.minecraft.server.level.ServerPlayer; +import net.pitan76.mcpitanlib.api.event.container.factory.DisplayNameArgs; +import net.pitan76.mcpitanlib.api.event.container.factory.ExtraDataArgs; +import net.pitan76.mcpitanlib.api.network.PacketByteUtil; +import net.pitan76.mcpitanlib.core.mc261.ExtendedMenuProvider; + +@Deprecated +public interface ExtendedScreenHandlerFactory extends ExtendedMenuProvider { + @Override + default Component getDisplayName() { + return getDisplayName(new DisplayNameArgs()); + } + + @Override + default FriendlyByteBuf getScreenOpeningData(ServerPlayer player) { + FriendlyByteBuf buf = PacketByteUtil.create(); + writeExtraData(new ExtraDataArgs(buf)); + return buf; + } + + Component 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..1b79983a4 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/gui/ExtendedScreenHandlerTypeBuilder.java @@ -0,0 +1,73 @@ +package net.pitan76.mcpitanlib.api.gui; + +import dev.architectury.injectables.annotations.ExpectPlatform; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufUtil; +import io.netty.buffer.Unpooled; +import net.minecraft.network.codec.ByteBufCodecs; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.MenuType; +import net.pitan76.mcpitanlib.api.gui.args.CreateMenuEvent; +import net.pitan76.mcpitanlib.midohra.screen.TypedScreenHandlerTypeWrapper; + +public class ExtendedScreenHandlerTypeBuilder { + + private final Factory factory; + + public ExtendedScreenHandlerTypeBuilder(Factory factory) { + this.factory = factory; + } + + public ExtendedScreenHandlerTypeBuilder(Factory2 factory) { + this.factory = factory; + } + + public ExtendedScreenHandlerTypeBuilder(Factory3 factory) { + this.factory = factory; + } + + public static StreamCodec CODEC = ByteBufCodecs.BYTE_ARRAY.map( + (data) -> new FriendlyByteBuf(Unpooled.wrappedBuffer(data)) + , (buf) -> ByteBufUtil.getBytes(buf.unwrap())); + + public MenuType build() { + return build(factory); + } + + @ExpectPlatform + public static MenuType build(Factory factory) { + throw new AssertionError(); + } + + public TypedScreenHandlerTypeWrapper buildWrapper() { + return TypedScreenHandlerTypeWrapper.ofRaw(build(factory)); + } + + @FunctionalInterface + public interface Factory { + T create(int syncId, Inventory inventory, FriendlyByteBuf buf); + } + + @FunctionalInterface + public interface Factory2 extends Factory { + T create(CreateMenuEvent e, FriendlyByteBuf buf); + + @Override + default T create(int syncId, Inventory inventory, FriendlyByteBuf buf) { + return create(new CreateMenuEvent(syncId, inventory), buf); + } + } + + @FunctionalInterface + public interface Factory3 extends Factory2 { + T create(CreateMenuEvent e, net.pitan76.mcpitanlib.midohra.network.PacketByteBuf buf); + + @Override + default T create(CreateMenuEvent e, FriendlyByteBuf buf) { + return create(e, net.pitan76.mcpitanlib.midohra.network.PacketByteBuf.of(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..5772c90a5 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/gui/SimpleScreenHandler.java @@ -0,0 +1,337 @@ +package net.pitan76.mcpitanlib.api.gui; + +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.ContainerInput; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.Slot; +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 net.pitan76.mcpitanlib.api.util.inventory.CompatPlayerInventory; +import net.pitan76.mcpitanlib.midohra.screen.ScreenHandlerTypeWrapper; +import org.jetbrains.annotations.Nullable; + +import java.util.ArrayList; +import java.util.List; + +public class SimpleScreenHandler extends AbstractContainerMenu { + protected SimpleScreenHandler(@Nullable MenuType type, int syncId) { + super(type, syncId); + } + + protected SimpleScreenHandler(@Nullable MenuType type, CreateMenuEvent e) { + this(type, e.getSyncId()); + } + + public boolean hasMainInventory = false; + public boolean hasHotbar = false; + + @Deprecated + @Override + public boolean stillValid(net.minecraft.world.entity.player.Player player) { + return canUse(new Player(player)); + } + + public boolean canUse(Player player) { + return true; + } + + public Slot addNormalSlot(Container inventory, int index, int x, int y) { + Slot slot = new Slot(inventory, index, x, y); + return this.addSlot(slot); + } + + public Slot addSlot(Container 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(Container 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 removed(net.minecraft.world.entity.player.Player player) { + this.close(new Player(player)); + } + + public void close(Player player) { + super.removed(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(Inventory 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(Inventory 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(Container 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(Container 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(Container 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(net.minecraft.world.entity.player.Player player, int index) { + return quickMoveOverride(new Player(player), index); + } + + public boolean callInsertItem(ItemStack stack, int startIndex, int endIndex, boolean fromLast) { + return this.moveItemStackTo(stack, startIndex, endIndex, fromLast); + } + + @Deprecated + @Override + protected boolean moveItemStackTo(ItemStack stack, int startIndex, int endIndex, boolean fromLast) { + return super.moveItemStackTo(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 quickMoveStack(net.minecraft.world.entity.player.Player 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 clicked(int slotIndex, int button, ContainerInput actionType, net.minecraft.world.entity.player.Player player) { + overrideOnSlotClick(slotIndex, button, actionType, new Player(player)); + } + + public void overrideOnSlotClick(int slotIndex, int button, ContainerInput actionType, Player player) { + onSlotClick(new SlotClickEvent(slotIndex, button, actionType, player)); + } + + public void onSlotClick(SlotClickEvent e) { + super.clicked(e.slot, e.button, e.actionType, e.player.getEntity()); + } + + @Override + @Deprecated + public void setCarried(ItemStack stack) { + callSetCursorStack(stack); + } + + public void callSetCursorStack(ItemStack stack) { + super.setCarried(stack); + } + + @Override + @Deprecated + public void setItem(int slot, int revision, ItemStack stack) { + callSetStackInSlot(slot, revision, stack); + } + + public void callSetStackInSlot(int slot, int revision, ItemStack stack) { + super.setItem(slot, revision, stack); + } + + @Override + @Deprecated + public int getStateId() { + return callGetRevision(); + } + + public int callGetRevision() { + return super.getStateId(); + } + + public net.pitan76.mcpitanlib.midohra.item.ItemStack getCursorStackM() { + return ScreenHandlerUtil.getCursorStackM(this); + } + + public ItemStack callGetCursorStack() { + return ScreenHandlerUtil.getCursorStack(this); + } + + public void setCursorStack(net.pitan76.mcpitanlib.midohra.item.ItemStack stack) { + ScreenHandlerUtil.setCursorStackM(this, stack); + } + + @Deprecated + @Override + public boolean canTakeItemForPickAll(ItemStack carried, Slot target) { + return canInsertIntoSlotOverride(net.pitan76.mcpitanlib.midohra.item.ItemStack.of(carried), target); + } + + @Deprecated + @Override + public boolean canDragTo(Slot slot) { + return canInsertIntoSlotOverride(slot); + } + + public boolean canInsertIntoSlotOverride(net.pitan76.mcpitanlib.midohra.item.ItemStack carried, Slot target) { + return super.canTakeItemForPickAll(carried.toMinecraft(), target); + } + + public boolean canInsertIntoSlotOverride(Slot slot) { + return super.canDragTo(slot); + } + + /** + * Add player main inventory slots + * @param inventory target player inventory + * @param x start x + * @param y start y + */ + protected List addPlayerMainInventorySlots(CompatPlayerInventory inventory, int x, int y) { + return this.addPlayerMainInventorySlots(inventory.getRaw(), x, y); + } + + /** + * Add player hotbar slots + * @param inventory target player inventory + * @param x start x + * @param y start y + */ + protected List addPlayerHotbarSlots(CompatPlayerInventory inventory, int x, int y) { + return this.addPlayerHotbarSlots(inventory.getRaw(), x, y); + } + + protected SimpleScreenHandler(ScreenHandlerTypeWrapper type, int syncId) { + super(type.get(), syncId); + } + + protected SimpleScreenHandler(ScreenHandlerTypeWrapper type, CreateMenuEvent e) { + this(type, e.getSyncId()); + } +} 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..a03ae4c4a --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/gui/SimpleScreenHandlerTypeBuilder.java @@ -0,0 +1,49 @@ +package net.pitan76.mcpitanlib.api.gui; + +import dev.architectury.injectables.annotations.ExpectPlatform; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.MenuType; +import net.pitan76.mcpitanlib.api.gui.args.CreateMenuEvent; +import net.pitan76.mcpitanlib.midohra.screen.TypedScreenHandlerTypeWrapper; + +public class SimpleScreenHandlerTypeBuilder { + + private final Factory factory; + + public SimpleScreenHandlerTypeBuilder(Factory factory) { + this.factory = factory; + } + + public SimpleScreenHandlerTypeBuilder(Factory2 factory) { + this.factory = factory; + } + + public MenuType build() { + return build(factory); + } + + public TypedScreenHandlerTypeWrapper buildWrapper() { + return TypedScreenHandlerTypeWrapper.ofRaw(build(factory)); + } + + @ExpectPlatform + public static MenuType build(Factory factory) { + throw new AssertionError(); + } + + @FunctionalInterface + public interface Factory { + T create(int syncId, Inventory inventory); + } + + @FunctionalInterface + public interface Factory2 extends Factory { + T create(CreateMenuEvent e); + + @Override + default T create(int syncId, Inventory 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..d028a10ba --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/gui/args/CreateMenuEvent.java @@ -0,0 +1,66 @@ +package net.pitan76.mcpitanlib.api.gui.args; + +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.level.Level; +import net.pitan76.mcpitanlib.api.entity.Player; +import net.pitan76.mcpitanlib.api.util.inventory.CompatPlayerInventory; + +public class CreateMenuEvent { + public int syncId; + public Inventory playerInventory; + public net.minecraft.world.entity.player.Player player; + + public CreateMenuEvent(int syncId, Inventory playerInventory, net.minecraft.world.entity.player.Player player) { + this.syncId = syncId; + this.playerInventory = playerInventory; + this.player = player; + } + + public CreateMenuEvent(int syncId, Inventory 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 Inventory getPlayerInventory() { + return playerInventory; + } + + public net.minecraft.world.entity.player.Player getPlayerEntity() { + return player; + } + + public Player getPlayer() { + return new Player(player); + } + + public boolean isExistPlayer() { + return player != null; + } + + public boolean isClient() { + return getPlayer().isClient(); + } + + public Level getWorld() { + return getPlayer().getWorld(); + } + + public CompatPlayerInventory getCompatPlayerInventory() { + return new CompatPlayerInventory(getPlayerInventory()); + } + + public net.pitan76.mcpitanlib.midohra.world.World getWorldM() { + return net.pitan76.mcpitanlib.midohra.world.World.of(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..3e32f803f --- /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.world.inventory.ContainerInput; +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 ContainerInput actionType; + public Player player; + + public SlotClickEvent(int slot, int button, ContainerInput 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 ContainerInput 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 == ContainerInput.SWAP; + } + + public boolean isPickupAction() { + return actionType == ContainerInput.PICKUP; + } + + public boolean isQuickCraftAction() { + return actionType == ContainerInput.QUICK_CRAFT; + } + + public boolean isQuickMoveAction() { + return actionType == ContainerInput.QUICK_MOVE; + } + + public boolean isThrowAction() { + return actionType == ContainerInput.THROW; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/gui/inventory/CompatIInventory.java b/common/src/main/java/net/pitan76/mcpitanlib/api/gui/inventory/CompatIInventory.java new file mode 100644 index 000000000..4a052d2b6 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/gui/inventory/CompatIInventory.java @@ -0,0 +1,62 @@ +package net.pitan76.mcpitanlib.api.gui.inventory; + +import net.pitan76.mcpitanlib.api.entity.Player; +import net.pitan76.mcpitanlib.api.util.collection.ItemStackList; +import net.pitan76.mcpitanlib.midohra.item.ItemStack; + +public interface CompatIInventory extends IInventory { + static CompatIInventory of(ItemStackList items) { + return () -> items; + } + + static CompatIInventory ofSize(int size) { + return of(ItemStackList.ofSize(size)); + } + + default int callSize() { + return getContainerSize(); + } + + default boolean callIsEmpty() { + return isEmpty(); + } + + default ItemStack getStackM(int slot) { + return ItemStack.of(getItem(slot)); + } + + + default ItemStack removeStackM(int slot, int count) { + return ItemStack.of(removeItem(slot, count)); + } + + default ItemStack removeStackM(int slot) { + return ItemStack.of(removeItemNoUpdate(slot)); + } + + default void setStack(int slot, ItemStack stack) { + setItem(slot, stack.toMinecraft()); + } + + default void callClearCII() { + clearContent(); + } + + default void callMarkDirtyCII() { + setChanged(); + } + + default boolean canPlayerUseCII(Player player) { + return true; + } + + @Deprecated + @Override + default boolean stillValid(net.minecraft.world.entity.player.Player player) { + return canPlayerUseCII(new Player(player)); + } + + default ItemStackList getCompatItems() { + return ItemStackList.of(getItemsM()); + } +} 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..6f3627469 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/gui/inventory/IInventory.java @@ -0,0 +1,84 @@ +package net.pitan76.mcpitanlib.api.gui.inventory; + +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.ContainerHelper; +import net.minecraft.world.Container; +import net.minecraft.world.item.ItemStack; +import net.minecraft.core.NonNullList; + +import java.util.List; +import java.util.stream.Collectors; + +public interface IInventory extends Container { + + NonNullList getItems(); + + static IInventory of(NonNullList items) { + return () -> items; + } + + static IInventory ofSize(int size) { + return of(NonNullList.withSize(size, ItemStack.EMPTY)); + } + + @Override + default int getContainerSize() { + return getItems().size(); + } + + @Override + default boolean isEmpty() { + for (int i = 0; i < getContainerSize(); i++) { + ItemStack stack = getItem(i); + if (!stack.isEmpty()) { + return false; + } + } + return true; + } + + @Override + default ItemStack getItem(int slot) { + return getItems().get(slot); + } + + @Override + default ItemStack removeItem(int slot, int count) { + ItemStack result = ContainerHelper.removeItem(getItems(), slot, count); + if (!result.isEmpty()) { + setChanged(); + } + return result; + } + + @Override + default ItemStack removeItemNoUpdate(int slot) { + return ContainerHelper.takeItem(getItems(), slot); + } + + @Override + default void setItem(int slot, ItemStack stack) { + getItems().set(slot, stack); + if (stack.getCount() > getMaxStackSize()) { + stack.setCount(getMaxStackSize()); + } + } + + @Override + default void clearContent() { + getItems().clear(); + } + + @Override + default void setChanged() { + } + + @Override + default boolean stillValid(Player player) { + return true; + } + + default List getItemsM() { + return getItems().stream().map(net.pitan76.mcpitanlib.midohra.item.ItemStack::of).collect(Collectors.toList()); + } +} \ 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..51b268cac --- /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.world.WorldlyContainer; +import net.minecraft.world.item.ItemStack; +import net.minecraft.core.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 WorldlyContainer { + @Override + @Deprecated + default int[] getSlotsForFace(Direction side) { + return getAvailableSlots(new AvailableSlotsArgs(side, this)); + } + + int[] getAvailableSlots(AvailableSlotsArgs args); + + @Override + @Deprecated + default boolean canPlaceItemThroughFace(int slot, ItemStack stack, @Nullable Direction dir) { + return canInsert(new CanInsertArgs(slot, stack, dir)); + } + + boolean canInsert(CanInsertArgs args); + + @Override + @Deprecated + default boolean canTakeItemThroughFace(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..de089581e --- /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.core.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..b137b989e --- /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.core.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.getContainerSize(); + + 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..62f24ed49 --- /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.world.item.ItemStack; +import net.minecraft.core.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..5fdf4ff9c --- /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.world.item.ItemStack; +import net.minecraft.core.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..7f1fb5070 --- /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.world.inventory.ContainerInput; + +public class CompatSlotActionType { + public static final CompatSlotActionType PICKUP = new CompatSlotActionType(ContainerInput.PICKUP); + public static final CompatSlotActionType QUICK_MOVE = new CompatSlotActionType(ContainerInput.QUICK_MOVE); + public static final CompatSlotActionType SWAP = new CompatSlotActionType(ContainerInput.SWAP); + public static final CompatSlotActionType THROW = new CompatSlotActionType(ContainerInput.THROW); + public static final CompatSlotActionType CLONE = new CompatSlotActionType(ContainerInput.CLONE); + public static final CompatSlotActionType QUICK_CRAFT = new CompatSlotActionType(ContainerInput.QUICK_CRAFT); + public static final CompatSlotActionType PICKUP_ALL = new CompatSlotActionType(ContainerInput.PICKUP_ALL); + + public final ContainerInput raw; + + protected CompatSlotActionType(ContainerInput raw) { + this.raw = raw; + } + + public static CompatSlotActionType of(ContainerInput raw) { + if (raw == ContainerInput.PICKUP) return PICKUP; + if (raw == ContainerInput.QUICK_MOVE) return QUICK_MOVE; + if (raw == ContainerInput.SWAP) return SWAP; + if (raw == ContainerInput.THROW) return THROW; + if (raw == ContainerInput.CLONE) return CLONE; + if (raw == ContainerInput.QUICK_CRAFT) return QUICK_CRAFT; + if (raw == ContainerInput.PICKUP_ALL) return PICKUP_ALL; + return new CompatSlotActionType(raw); + } + + public boolean isSwapOrPickupOrQuickMoveOrThrow() { + return raw == ContainerInput.SWAP || raw == ContainerInput.PICKUP || raw == ContainerInput.QUICK_MOVE || raw == ContainerInput.THROW; + } + + public ContainerInput getRaw() { + return raw; + } + + public int getIndex() { + return raw.id(); + } + + 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..c3ab9a336 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/gui/slot/CompatibleSlot.java @@ -0,0 +1,133 @@ +package net.pitan76.mcpitanlib.api.gui.slot; + +import net.minecraft.world.Container; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.inventory.Slot; +import net.pitan76.mcpitanlib.api.entity.Player; +import net.pitan76.mcpitanlib.api.util.inventory.ICompatInventory; + +public class CompatibleSlot extends Slot { + + public Container inventory; + public int index; + public int x; + public int y; + + public CompatibleSlot(Container 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 CompatibleSlot(ICompatInventory 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.setByPlayer(stack); + } + + public void callSetStackNoCallbacks(ItemStack stack) { + super.set(stack); + } + + public ItemStack callGetStack() { + return super.getItem(); + } + + public ItemStack callTakeStack(int amount) { + return super.remove(amount); + } + + public boolean callHasStack() { + return super.hasItem(); + } + + @Deprecated + @Override + public void setByPlayer(ItemStack stack) { + callSetStack(stack); + } + + @Deprecated + @Override + public void set(ItemStack stack) { + callSetStackNoCallbacks(stack); + } + + @Deprecated + @Override + public ItemStack getItem() { + return callGetStack(); + } + + @Deprecated + @Override + public ItemStack remove(int amount) { + return callTakeStack(amount); + } + + @Deprecated + @Override + public boolean hasItem() { + return callHasStack(); + } + + public Container callGetInventory() { + return inventory; + } + + public int callGetIndex() { + return super.getContainerSlot(); + } + + public int callGetId() { + return super.index; + } + + public int callGetX() { + return super.x; + } + + public int callGetY() { + return super.y; + } + + public void callMarkDirty() { + super.setChanged(); + } + + @Override + public boolean mayPlace(ItemStack stack) { + return canInsert(net.pitan76.mcpitanlib.midohra.item.ItemStack.of(stack)); + } + + @Override + public boolean mayPickup(net.minecraft.world.entity.player.Player playerEntity) { + return canTakeItems(new Player(playerEntity)); + } + + public boolean canInsert(net.pitan76.mcpitanlib.midohra.item.ItemStack stack) { + return super.mayPlace(stack.toMinecraft()); + } + + public boolean canTakeItems(Player player) { + return super.mayPickup(player.getEntity()); + } + + @Deprecated + @Override + public boolean allowModification(net.minecraft.world.entity.player.Player player) { + return canTakePartial(new Player(player)); + } + + public boolean canTakePartial(Player player) { + return super.allowModification(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..306dea95f --- /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.world.entity.player.Player; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.pitan76.mcpitanlib.api.gui.args.CreateMenuEvent; + +@SuppressWarnings("deprecation") +public interface ExtendedScreenHandlerFactory extends net.pitan76.mcpitanlib.api.gui.ExtendedScreenHandlerFactory { + + @Override + default AbstractContainerMenu createMenu(int syncId, Inventory playerInventory, Player player) { + return createMenu(new CreateMenuEvent(syncId, playerInventory, player)); + } + + AbstractContainerMenu 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..775d9790f --- /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.world.entity.player.Player; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.MenuProvider; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.network.chat.Component; +import net.pitan76.mcpitanlib.api.event.container.factory.DisplayNameArgs; +import net.pitan76.mcpitanlib.api.gui.args.CreateMenuEvent; + +public interface SimpleScreenHandlerFactory extends MenuProvider { + @Override + default Component getDisplayName() { + return getDisplayName(new DisplayNameArgs()); + } + + Component getDisplayName(DisplayNameArgs args); + + @Override + default AbstractContainerMenu createMenu(int syncId, Inventory playerInventory, Player player) { + return createMenu(new CreateMenuEvent(syncId, playerInventory, player)); + } + + AbstractContainerMenu createMenu(CreateMenuEvent event); +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/gui/v3/ExtendedScreenHandlerFactory.java b/common/src/main/java/net/pitan76/mcpitanlib/api/gui/v3/ExtendedScreenHandlerFactory.java new file mode 100644 index 000000000..c8beb6c7b --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/gui/v3/ExtendedScreenHandlerFactory.java @@ -0,0 +1,25 @@ +package net.pitan76.mcpitanlib.api.gui.v3; + +import net.minecraft.network.chat.Component; +import net.pitan76.mcpitanlib.api.event.container.factory.DisplayNameArgs; +import net.pitan76.mcpitanlib.api.gui.SimpleScreenHandler; +import net.pitan76.mcpitanlib.api.gui.args.CreateMenuEvent; +import net.pitan76.mcpitanlib.api.text.TextComponent; + +public interface ExtendedScreenHandlerFactory extends net.pitan76.mcpitanlib.api.gui.v2.ExtendedScreenHandlerFactory { + TextComponent getDisplayText(DisplayNameArgs args); + + @Deprecated + @Override + default Component getDisplayName(DisplayNameArgs args) { + return getDisplayText(args).getText(); + } + + @Override + default Component getDisplayName() { + return getDisplayText(new DisplayNameArgs()).getText(); + } + + @Override + SimpleScreenHandler createMenu(CreateMenuEvent event); +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/gui/v3/SimpleScreenHandlerFactory.java b/common/src/main/java/net/pitan76/mcpitanlib/api/gui/v3/SimpleScreenHandlerFactory.java new file mode 100644 index 000000000..52b8f807d --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/gui/v3/SimpleScreenHandlerFactory.java @@ -0,0 +1,24 @@ +package net.pitan76.mcpitanlib.api.gui.v3; + +import net.minecraft.network.chat.Component; +import net.pitan76.mcpitanlib.api.event.container.factory.DisplayNameArgs; +import net.pitan76.mcpitanlib.api.gui.SimpleScreenHandler; +import net.pitan76.mcpitanlib.api.gui.args.CreateMenuEvent; +import net.pitan76.mcpitanlib.api.text.TextComponent; + +public interface SimpleScreenHandlerFactory extends net.pitan76.mcpitanlib.api.gui.v2.SimpleScreenHandlerFactory { + TextComponent getDisplayText(DisplayNameArgs args); + + @Deprecated + @Override + default Component getDisplayName(DisplayNameArgs args) { + return getDisplayText(args).getText(); + } + + @Override + default Component getDisplayName() { + return getDisplayText(new DisplayNameArgs()).getText(); + } + + SimpleScreenHandler 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..b3dab7cb9 --- /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.world.item.Item; +import net.minecraft.world.level.ItemLike; +import net.minecraft.world.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..154f8ad94 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/ArmorEquipmentType.java @@ -0,0 +1,75 @@ +package net.pitan76.mcpitanlib.api.item; + +import net.minecraft.world.entity.EquipmentSlot; +import net.minecraft.world.item.equipment.ArmorType; +import org.jetbrains.annotations.Nullable; + +public class ArmorEquipmentType { + public static ArmorEquipmentType HEAD = new ArmorEquipmentType(EquipmentSlot.HEAD, ArmorType.HELMET); + public static ArmorEquipmentType CHEST = new ArmorEquipmentType(EquipmentSlot.CHEST, ArmorType.CHESTPLATE); + public static ArmorEquipmentType LEGS = new ArmorEquipmentType(EquipmentSlot.LEGS, ArmorType.LEGGINGS); + public static ArmorEquipmentType FEET = new ArmorEquipmentType(EquipmentSlot.FEET, ArmorType.BOOTS); + + // New type for animals from 1.20.5 + public static ArmorEquipmentType BODY = new ArmorEquipmentType(EquipmentSlot.BODY, ArmorType.BODY); + + protected final EquipmentSlot slot; + protected final ArmorType type; + + protected ArmorEquipmentType(EquipmentSlot slot, ArmorType type) { + this.slot = slot; + this.type = type; + } + + @Deprecated + public EquipmentSlot getSlot() { + return slot; + } + + @Deprecated + public ArmorType 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(ArmorType 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..bdfea8efb --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/CompatFoodComponent.java @@ -0,0 +1,120 @@ +package net.pitan76.mcpitanlib.api.item; + +import com.mojang.datafixers.util.Pair; +import net.minecraft.world.food.FoodProperties; +import net.minecraft.world.effect.MobEffectInstance; +import net.pitan76.mcpitanlib.api.entity.effect.CompatStatusEffectInstance; + +import java.util.ArrayList; +import java.util.List; + +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 FoodProperties 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(MobEffectInstance effect, float chance) { + statusEffects.add(Pair.of(effect, chance)); + return this; + } + + public CompatFoodComponent addStatusEffect(CompatStatusEffectInstance instance, float chance) { + return addStatusEffect(instance.getInstance(), chance); + } + + public FoodProperties.Builder getVanillaBuilder() { + FoodProperties.Builder builder = new FoodProperties.Builder(); + builder.nutrition(hunger).saturationModifier(saturation); + if (alwaysEdible) builder.alwaysEdible(); + return builder; + } + + public FoodProperties build() { + if (latestComponent != null) return latestComponent; + + float eatSeconds = 1.6f; + if (snack) eatSeconds = 0.8f; + if (meat) eatSeconds = 1.6f; + + latestComponent = new FoodProperties(hunger, saturation, alwaysEdible); + + return latestComponent; + } + + public FoodProperties 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..a35a073d6 --- /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.world.item.Item; +import net.minecraft.world.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..c6e4cd33b --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/CompatibleArmorItem.java @@ -0,0 +1,41 @@ +package net.pitan76.mcpitanlib.api.item; + +import net.minecraft.world.item.Item; +import net.pitan76.mcpitanlib.api.item.v2.CompatItemProvider; +import net.pitan76.mcpitanlib.api.item.v2.CompatibleItemSettings; + +public class CompatibleArmorItem extends Item implements CompatItemProvider { + public final ArmorEquipmentType type; + public final CompatibleArmorMaterial material; + + public CompatibleItemSettings settings; + + public CompatibleArmorItem(CompatibleArmorMaterial material, ArmorEquipmentType type, CompatibleItemSettings settings) { + super(settings.build().humanoidArmor(material.build(), type.getType())); + 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..ab7438054 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/CompatibleArmorMaterial.java @@ -0,0 +1,64 @@ +package net.pitan76.mcpitanlib.api.item; + +import net.minecraft.world.item.Item; +import net.minecraft.world.item.equipment.ArmorMaterial; +import net.minecraft.world.item.equipment.EquipmentAssets; +import net.minecraft.world.item.equipment.ArmorType; +import net.minecraft.world.item.crafting.Ingredient; +import net.minecraft.resources.ResourceKey; +import net.minecraft.core.Holder; +import net.minecraft.tags.ItemTags; +import net.minecraft.tags.TagKey; +import net.minecraft.sounds.SoundEvent; +import net.minecraft.resources.Identifier; +import net.pitan76.mcpitanlib.api.util.IngredientUtil; + +import java.util.EnumMap; + +public interface CompatibleArmorMaterial { + int getDurability(ArmorEquipmentType type); + + int getProtection(ArmorEquipmentType type); + + int getEnchantability(); + + SoundEvent getEquipSound(); + + default Ingredient getRepairIngredient() { + return IngredientUtil.fromTagByIdentifier(getRepairTag().location()); + } + + /** + * @return the name of the material + */ + default String getName() { + return getId().getPath(); + } + + /** + * @return the id of the material + */ + Identifier getId(); + + float getToughness(); + + float getKnockbackResistance(); + + default TagKey getRepairTag() { + return ItemTags.REPAIRS_IRON_ARMOR; + } + + @Deprecated + default ArmorMaterial build() { + return new ArmorMaterial(0, getDefense(), getEnchantability(), Holder.direct(getEquipSound()), getToughness(), getKnockbackResistance(), getRepairTag(), ResourceKey.create(EquipmentAssets.ROOT_ID, getId())); + } + + default EnumMap getDefense() { + EnumMap map = new EnumMap<>(ArmorType.class); + map.put(ArmorType.HELMET, this.getProtection(ArmorEquipmentType.HEAD)); + map.put(ArmorType.CHESTPLATE, this.getProtection(ArmorEquipmentType.CHEST)); + map.put(ArmorType.LEGGINGS, this.getProtection(ArmorEquipmentType.LEGS)); + map.put(ArmorType.BOOTS, this.getProtection(ArmorEquipmentType.FEET)); + return map; + } +} 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..744c340cd --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/CompatibleItemSettings.java @@ -0,0 +1,116 @@ +package net.pitan76.mcpitanlib.api.item; + +import net.minecraft.world.food.FoodProperties; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.CreativeModeTab; +import net.minecraft.resources.ResourceKey; +import net.minecraft.core.registries.Registries; +import net.minecraft.resources.Identifier; +import net.minecraft.world.item.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; + protected Identifier _itemId = null; + + @Deprecated + public static CompatibleItemSettings of() { + return new CompatibleItemSettings(); + } + + // ~1.19.2 + public CompatibleItemSettings addGroup(CreativeModeTab itemGroup) { + settings.addGroup(itemGroup); + return this; + } + + // 1.19.3~ + // identifier: Item ID + public CompatibleItemSettings addGroup(CreativeModeTab itemGroup, Identifier identifier) { + settings.addGroup(itemGroup, identifier); + _itemId = identifier; + return this; + } + + public CompatibleItemSettings addGroup(Supplier itemGroup, Identifier identifier) { + settings.addGroup(itemGroup, identifier); + _itemId = identifier; + return this; + } + + public CompatibleItemSettings addGroup(CreativeTabBuilder itemGroup) { + this.itemGroupId = itemGroup.getIdentifier(); + return this; + } + + public CompatibleItemSettings maxCount(int maxCount) { + settings.stacksTo(maxCount); + return this; + } + + public CompatibleItemSettings maxDamage(int maxDamage) { + settings.durability(maxDamage); + return this; + } + + public CompatibleItemSettings maxDamageIfAbsent(int maxDamage) { + try { + settings.durability(maxDamage); + } catch (Exception ignored) {} + + return this; + } + + @Deprecated + public CompatibleItemSettings food(FoodProperties foodComponent) { + settings.food(foodComponent); + return this; + } + + public CompatibleItemSettings rarity(Rarity rarity) { + settings.rarity(rarity); + return this; + } + + public CompatibleItemSettings recipeRemainder(Item recipeRemainder) { + settings.craftRemainder(recipeRemainder); + return this; + } + + public ExtendSettings build() { + if (itemGroupId != null && _itemId != null) { + ResourceKey key = ResourceKey.create(Registries.CREATIVE_MODE_TAB, itemGroupId); +// RegistrySupplier itemGroup = MCPLRegistry1_20.REGISTRY_SUPPLIER_ITEM_GROUP_CACHE.get(key); +// CreativeModeTabEvents.modifyOutputEvent(key).register(entries -> { +// entries.accept(new ItemStack()); +// }); +// if (output instanceof Item.Settings settings) +// settings.arch$tab(itemGroup); + MCPLRegistry1_20.addItemGroupItem(key, _itemId); + } + + if (_itemId != null && !(this instanceof net.pitan76.mcpitanlib.api.item.v2.CompatibleItemSettings)) { + settings.setId(ResourceKey.create(Registries.ITEM, _itemId)); + } + + return settings; + } + + public CompatibleItemSettings addGroup(CreativeModeTab 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..9f9601c58 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/CreativeTabBuilder.java @@ -0,0 +1,143 @@ +package net.pitan76.mcpitanlib.api.item; + +import dev.architectury.injectables.annotations.ExpectPlatform; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.CreativeModeTab; +import net.minecraft.world.item.ItemStack; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.Identifier; +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.TextUtil; +import net.pitan76.mcpitanlib.core.registry.MCPLRegistry1_20; +import net.pitan76.mcpitanlib.midohra.item.ItemGroupWrapper; +import net.pitan76.mcpitanlib.midohra.item.ItemWrapper; +import net.pitan76.mcpitanlib.midohra.item.SupplierItemWrapper; + +import java.util.function.Supplier; + +public class CreativeTabBuilder { + private final Identifier identifier; + private Component 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(Component 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 CreativeModeTab build() { + return build(identifier, displayName, iconSupplier, noRenderedName, noScrollbar, special, texture); + } + + @ExpectPlatform + public static CreativeModeTab build(Identifier identifier, Component displayName, Supplier iconSupplier, boolean noRenderedName, boolean noScrollbar, boolean special, String texture) { + throw new AssertionError(); + } + + @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); + } + + /** + * Set icon + * @param iconSupplier Icon supplier + * @return CreativeTabBuilder + */ + public CreativeTabBuilder setIconM(Supplier iconSupplier) { + this.iconSupplier = () -> iconSupplier.get().toMinecraft(); + return this; + } + + /** + * Set icon (Already registered item only) + * @param item Item + * @return CreativeTabBuilder + */ + public CreativeTabBuilder setIcon(ItemWrapper item) { + return setIcon(() -> item.createStack().toMinecraft()); + } + + /** + * Set icon (Already registered item only) + * @param item Item + * @return CreativeTabBuilder + */ + public CreativeTabBuilder setIcon(SupplierItemWrapper item) { + return setIcon(() -> item.createStack().toMinecraft()); + } + + public CreativeTabBuilder setDisplayName(TextComponent text) { + return setDisplayName(text.getText()); + } +} 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..fe9069bc5 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/CreativeTabManager.java @@ -0,0 +1,139 @@ +package net.pitan76.mcpitanlib.api.item; + +import net.minecraft.core.registries.Registries; +import net.minecraft.resources.ResourceKey; +import net.minecraft.world.item.CreativeModeTab; +import net.minecraft.world.item.ItemStack; +import net.minecraft.resources.Identifier; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.api.util.item.ItemGroupUtil; +import net.pitan76.mcpitanlib.api.util.item.ItemUtil; +import net.pitan76.mcpitanlib.core.mc261.CreativeModeTabEventRegistry; +import net.pitan76.mcpitanlib.core.registry.MCPLRegistry1_20; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +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 CreativeModeTab itemGroup; + + public Supplier itemGroupSupplier; + public Identifier identifier; + + @Deprecated + private BookingItem(CreativeModeTab itemGroup, Identifier identifier) { + this.itemGroup = itemGroup; + this.identifier = identifier; + } + + private BookingItem(Supplier itemGroup, Identifier identifier) { + this.itemGroupSupplier = itemGroup; + this.identifier = identifier; + } + + public CreativeModeTab getItemGroup() { + if (itemGroupSupplier != null) + return itemGroupSupplier.get(); + return itemGroup; + } + } + + // グループ予約済みアイテムスタック + public static class BookingStack { + @Deprecated + public CreativeModeTab itemGroup; + + public Supplier itemGroupSupplier; + public ItemStack stack; + + @Deprecated + private BookingStack(CreativeModeTab itemGroup, ItemStack stack) { + this.itemGroup = itemGroup; + this.stack = stack; + } + + private BookingStack(Supplier itemGroup, ItemStack stack) { + this.itemGroupSupplier = itemGroup; + this.stack = stack; + } + + public CreativeModeTab getItemGroup() { + if (itemGroupSupplier != null) + return itemGroupSupplier.get(); + return itemGroup; + } + } + + public static void allRegister() { + if (!MCPLRegistry1_20.ITEM_GROUP_ITEM_ID_CACHE.isEmpty()) { + for (Map.Entry, List> entry : MCPLRegistry1_20.ITEM_GROUP_ITEM_ID_CACHE.entrySet()) { + CreativeModeTabEventRegistry.addStacks(entry.getKey(), () -> entry.getValue().stream().map(id -> new ItemStack(ItemUtil.fromId(CompatIdentifier.fromMinecraft(id)))).toList()); + } + } + + if (!bookingItems.isEmpty()) { + for (BookingItem bookingItem : bookingItems) { +// CreativeTabRegistry.appendBuiltin(bookingItem.getItemGroup(), ItemUtil.fromId(bookingItem.identifier)); + ResourceKey key = ResourceKey.create(Registries.CREATIVE_MODE_TAB, ItemGroupUtil.toID(bookingItem.getItemGroup())); + CreativeModeTabEventRegistry.addStack(key, () -> new ItemStack(ItemUtil.fromId(CompatIdentifier.fromMinecraft(bookingItem.identifier)))); +// CreativeModeTabEvents.modifyOutputEvent(key).register(entries -> { +// entries.accept(new ItemStack(ItemUtil.fromId(bookingItem.identifier))); +// }); + } + bookingItems = new ArrayList<>(); + } + + if (!bookingStacks.isEmpty()) { + for (BookingStack bookingStack : bookingStacks) { +// CreativeTabRegistry.appendBuiltinStack(bookingStack.getItemGroup(), bookingStack.stack); + ResourceKey key = ResourceKey.create(Registries.CREATIVE_MODE_TAB, ItemGroupUtil.toID(bookingStack.getItemGroup())); + CreativeModeTabEventRegistry.addStack(key, () -> bookingStack.stack); +// CreativeModeTabEvents.modifyOutputEvent(key).register(entries -> { +// entries.accept(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)); + ResourceKey key = ResourceKey.create(Registries.CREATIVE_MODE_TAB, ItemGroupUtil.toID(bookingItem.getItemGroup())); + CreativeModeTabEventRegistry.addStack(key, () -> new ItemStack(ItemUtil.fromId(CompatIdentifier.fromMinecraft(bookingItem.identifier)))); +// CreativeModeTabEvents.modifyOutputEvent(key).register(entries -> { +// entries.accept(new ItemStack(ItemUtil.fromId(bookingItem.identifier))); +// }); + bookingItems.remove(bookingItem); + break; + } + } + + @Deprecated + public static void addItem(CreativeModeTab itemGroup, Identifier identifier) { + bookingItems.add(new BookingItem(itemGroup, identifier)); + } + + @Deprecated + public static void addStack(CreativeModeTab 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..47dfed0ec --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/DefaultItemGroups.java @@ -0,0 +1,50 @@ +package net.pitan76.mcpitanlib.api.item; + +import net.minecraft.core.registries.Registries; +import net.minecraft.resources.Identifier; +import net.minecraft.resources.ResourceKey; +import net.minecraft.world.item.CreativeModeTab; +import net.minecraft.core.registries.BuiltInRegistries; + +public class DefaultItemGroups { + + private static final ResourceKey _BUILDING_BLOCKS = createKey("building_blocks"); + private static final ResourceKey _COLORED_BLOCKS = createKey("colored_blocks"); + private static final ResourceKey _NATURAL_BLOCKS = createKey("natural_blocks"); + private static final ResourceKey _FUNCTIONAL_BLOCKS = createKey("functional_blocks"); + private static final ResourceKey _REDSTONE_BLOCKS = createKey("redstone_blocks"); + private static final ResourceKey _HOTBAR = createKey("hotbar"); + private static final ResourceKey _SEARCH = createKey("search"); + private static final ResourceKey _TOOLS_AND_UTILITIES = createKey("tools_and_utilities"); + private static final ResourceKey _COMBAT = createKey("combat"); + private static final ResourceKey _FOOD_AND_DRINKS = createKey("food_and_drinks"); + private static final ResourceKey _INGREDIENTS = createKey("ingredients"); + private static final ResourceKey _SPAWN_EGGS = createKey("spawn_eggs"); + private static final ResourceKey _OP_BLOCKS = createKey("op_blocks"); + private static final ResourceKey _INVENTORY = createKey("inventory"); + + private static ResourceKey createKey(final String id) { + return ResourceKey.create(Registries.CREATIVE_MODE_TAB, Identifier.withDefaultNamespace(id)); + } + + public static final CreativeModeTab BUILDING_BLOCKS = BuiltInRegistries.CREATIVE_MODE_TAB.getValue(_BUILDING_BLOCKS); + public static final CreativeModeTab COLORED_BLOCKS = BuiltInRegistries.CREATIVE_MODE_TAB.getValue(_COLORED_BLOCKS); // if 1.19.2 and below, BUILDING_BLOCKS + public static final CreativeModeTab NATURAL = BuiltInRegistries.CREATIVE_MODE_TAB.getValue(_NATURAL_BLOCKS); // if 1.19.2 and below, DECORATIONS + public static final CreativeModeTab FUNCTIONAL = BuiltInRegistries.CREATIVE_MODE_TAB.getValue(_FUNCTIONAL_BLOCKS); // if 1.19.2 and below, TRANSPORTATION + public static final CreativeModeTab REDSTONE = BuiltInRegistries.CREATIVE_MODE_TAB.getValue(_REDSTONE_BLOCKS); + public static final CreativeModeTab HOTBAR = BuiltInRegistries.CREATIVE_MODE_TAB.getValue(_HOTBAR); + public static final CreativeModeTab SEARCH = BuiltInRegistries.CREATIVE_MODE_TAB.getValue(_SEARCH); + public static final CreativeModeTab TOOLS = BuiltInRegistries.CREATIVE_MODE_TAB.getValue(_TOOLS_AND_UTILITIES); + public static final CreativeModeTab COMBAT = BuiltInRegistries.CREATIVE_MODE_TAB.getValue(_COMBAT); + public static final CreativeModeTab FOOD_AND_DRINK = BuiltInRegistries.CREATIVE_MODE_TAB.getValue(_FOOD_AND_DRINKS); // if 1.19.2 and below, FOOD + public static final CreativeModeTab INGREDIENTS = BuiltInRegistries.CREATIVE_MODE_TAB.getValue(_INGREDIENTS); // if 1.19.2 and below, MISC + public static final CreativeModeTab SPAWN_EGGS = BuiltInRegistries.CREATIVE_MODE_TAB.getValue(_SPAWN_EGGS); // if 1.19.2 and below, MISC + public static final CreativeModeTab OPERATOR = BuiltInRegistries.CREATIVE_MODE_TAB.getValue(_OP_BLOCKS); // if 1.19.2 and below, MISC + public static final CreativeModeTab INVENTORY = BuiltInRegistries.CREATIVE_MODE_TAB.getValue(_INVENTORY); + + // ~1.19.2 Item Group + public static final CreativeModeTab BREWING = FOOD_AND_DRINK; + public static final CreativeModeTab TRANSPORTATION = FUNCTIONAL; + public static final CreativeModeTab DECORATIONS = NATURAL; + public static final CreativeModeTab 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..9743f07cb --- /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.world.level.block.Block; +import net.minecraft.world.item.component.TooltipDisplay; +import net.minecraft.world.item.TooltipFlag; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.BlockItem; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.context.UseOnContext; +import net.minecraft.network.chat.Component; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.level.Level; +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.UseOnContextMixin; + +import java.util.function.Consumer; + +public class ExtendBlockItem extends BlockItem implements ExtendItemProvider { + + public ExtendBlockItem(Block block, Properties settings) { + super(block, settings); + } + + public ExtendBlockItem(Block block, CompatibleItemSettings settings) { + super(block, settings.build()); + } + + // ExtendItem + @Deprecated + @Override + public InteractionResult use(Level world, Player user, InteractionHand hand) { + return onRightClick(new ItemUseEvent(world, user, hand)).toActionResult(); + } + + @Deprecated + @Override + public InteractionResult useOn(UseOnContext context) { + UseOnContextMixin contextAccessor = (UseOnContextMixin) context; + return onRightClickOnBlock(new ItemUseOnBlockEvent(context.getPlayer(), context.getHand(), contextAccessor.getHitResult())).toActionResult(); + } + + @Deprecated + @Override + public ItemStack finishUsingItem(ItemStack stack, Level world, LivingEntity user) { + return onFinishUsing(new ItemFinishUsingEvent(stack, world, user)); + } + + @Deprecated + @Override + public InteractionResult interactLivingEntity(ItemStack stack, Player user, LivingEntity entity, InteractionHand hand) { + return onRightClickOnEntity(new ItemUseOnEntityEvent(stack, user, entity, hand)).toActionResult(); + } + + @Deprecated + public boolean hasRecipeRemainder() { + return hasRecipeRemainder(new Dummy()); + } + + @Deprecated + @Override + public void appendHoverText(ItemStack stack, TooltipContext context, TooltipDisplay displayComponent, Consumer textConsumer, TooltipFlag type) { + appendTooltip(new ItemAppendTooltipEvent(stack, context, displayComponent, textConsumer, type)); + } + + @Deprecated + @Override + public void onCraftedPostProcess(ItemStack stack, Level world) { + onCraft(new CraftEvent(stack, world)); + } + + /** + * 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)), event.stack); + } + + /** + * item right click event on block + * @param event ItemUseOnBlockEvent + * @return ActionResultType + */ + public CompatActionResult onRightClickOnBlock(ItemUseOnBlockEvent event) { + return CompatActionResult.create(super.useOn(event.toIUC())); + } + + /** + * item finish using event + * @param event ItemFinishUsingEvent + * @return ItemStack + */ + public ItemStack onFinishUsing(ItemFinishUsingEvent event) { + return super.finishUsingItem(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.interactLivingEntity(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.appendHoverText(event.stack, event.context, event.displayComponent, event.textConsumer, event.type); + } + + /** + * on craft event + * @param event CraftEvent + */ + public void onCraft(CraftEvent event) { + super.onCraftedPostProcess(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..94b50ba06 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/ExtendItem.java @@ -0,0 +1,261 @@ +package net.pitan76.mcpitanlib.api.item; + +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.item.component.TooltipDisplay; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.item.ItemUseAnimation; +import net.minecraft.world.item.TooltipFlag; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.context.UseOnContext; +import net.minecraft.network.chat.Component; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.item.Rarity; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +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.UseOnContextMixin; + +import java.util.function.Consumer; + +public class ExtendItem extends Item implements ICompatItem { + + public ExtendItem(Properties settings) { + super(settings); + } + + public ExtendItem(CompatibleItemSettings settings) { + super(settings.build()); + } + + @Deprecated + @Override + public InteractionResult use(Level world, Player user, InteractionHand hand) { + return onRightClick(new ItemUseEvent(world, user, hand)).toActionResult(); + } + + @Deprecated + @Override + public InteractionResult useOn(UseOnContext context) { + UseOnContextMixin contextAccessor = (UseOnContextMixin) context; + return onRightClickOnBlock(new ItemUseOnBlockEvent(context.getPlayer(), context.getHand(), contextAccessor.getHitResult())).toActionResult(); + } + + @Deprecated + @Override + public ItemStack finishUsingItem(ItemStack stack, Level world, LivingEntity user) { + return onFinishUsing(new ItemFinishUsingEvent(stack, world, user)); + } + + @Deprecated + @Override + public InteractionResult interactLivingEntity(ItemStack stack, Player user, LivingEntity entity, InteractionHand hand) { + return onRightClickOnEntity(new ItemUseOnEntityEvent(stack, user, entity, hand)).toActionResult(); + } + + @Override + public ItemUseAnimation getUseAnimation(ItemStack stack) { + return super.getUseAnimation(stack); + } + + @Deprecated + //@Override + public boolean hasRecipeRemainder() { + return hasRecipeRemainder(new Dummy()); + } + + @Deprecated + @Override + public void appendHoverText(ItemStack stack, TooltipContext context, TooltipDisplay displayComponent, Consumer textConsumer, TooltipFlag type) { + appendTooltip(new ItemAppendTooltipEvent(stack, context, displayComponent, textConsumer, type)); + } + + @Deprecated + @Override + public void onCraftedPostProcess(ItemStack stack, Level world) { + onCraft(new CraftEvent(stack, world)); + } + + @Deprecated + @Override + public void hurtEnemy(ItemStack stack, LivingEntity target, LivingEntity attacker) { + postHit(new PostHitEvent(stack, target, attacker)); + } + + @Deprecated + @Override + public boolean mineBlock(ItemStack stack, Level 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)), event.stack); + } + + /** + * item right click event on block + * @param event ItemUseOnBlockEvent + * @return ActionResultType + */ + public CompatActionResult onRightClickOnBlock(ItemUseOnBlockEvent event) { + return CompatActionResult.create(super.useOn(event.toIUC())); + } + + /** + * item finish using event + * @param event ItemFinishUsingEvent + * @return ItemStack + */ + public ItemStack onFinishUsing(ItemFinishUsingEvent event) { + return super.finishUsingItem(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.interactLivingEntity(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.appendHoverText(event.stack, event.context, event.displayComponent, event.textConsumer, event.type); + } + + /** + * on craft event + * @param event CraftEvent + */ + public void onCraft(CraftEvent event) { + super.onCraftedPostProcess(event.stack, event.world); + } + + /** + * post hit event + * @param event PostHitEvent + * @return boolean + */ + public boolean postHit(PostHitEvent event) { + super.hurtEnemy(event.stack, event.target, event.attacker); + return true; + } + + /** + * post mine event + * @param event PostMineEvent + * @return boolean + */ + public boolean postMine(PostMineEvent event) { + return super.mineBlock(event.stack, event.world, event.state, event.pos, event.miner); + } + + // -1.20.6 + public Rarity getRarity(ItemStack stack) { + return Rarity.COMMON; + } + + @Deprecated + public boolean isEnchantable(ItemStack stack) { + return isEnchantable(new EnchantableArgs(stack)); + } + + public boolean isEnchantable(EnchantableArgs args) { + return false; + } + + @Deprecated + public int getEnchantability() { + return getEnchantability(new EnchantabilityArgs()); + } + + public int getEnchantability(EnchantabilityArgs args) { + return 0; + } + + @Deprecated + @Override + public int getBarColor(ItemStack stack) { + return getItemBarColor(new ItemBarColorArgs(stack)); + } + + public int getItemBarColor(ItemBarColorArgs args) { + return super.getBarColor(args.stack); + } + + @Deprecated + @Override + public boolean isBarVisible(ItemStack stack) { + return isItemBarVisible(new ItemBarVisibleArgs(stack)); + } + + public boolean isItemBarVisible(ItemBarVisibleArgs args) { + return super.isBarVisible(args.stack); + } + + @Deprecated + @Override + public int getBarWidth(ItemStack stack) { + return getItemBarStep(new ItemBarStepArgs(stack)); + } + + public int getItemBarStep(ItemBarStepArgs args) { + return super.getBarWidth(args.stack); + } + + @Deprecated + @Override + public float getAttackDamageBonus(Entity target, float baseAttackDamage, DamageSource damageSource) { + return getBonusAttackDamage(new BonusAttackDamageArgs(target, baseAttackDamage, damageSource)); + } + + public float getBonusAttackDamage(BonusAttackDamageArgs args) { + return super.getAttackDamageBonus(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 false; + } + + @Deprecated + @Override + public boolean canDestroyBlock(ItemStack stack, BlockState state, Level world, BlockPos pos, LivingEntity user) { + return canMine(new CanMineArgs(stack, state, world, pos, user)); + } + + public boolean canMine(CanMineArgs args) { + return super.canDestroyBlock(args.stack, args.state, args.world, args.pos, args.entity); + } +} 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..b553d08b4 --- /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.world.item.ItemStack; +import net.minecraft.world.item.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 extends ICompatItem { + + /** + * 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..c1b76fb09 --- /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.world.item.Item; +import net.minecraft.world.item.CreativeModeTab; +import net.minecraft.resources.Identifier; + +import java.util.function.Supplier; + +/** + * Use {@link CompatibleItemSettings} instead. + */ +public class ExtendSettings extends Item.Properties { + + // ~1.19.2 + @Deprecated + public ExtendSettings addGroup(CreativeModeTab itemGroup) { + return this; + } + + // 1.19.3~ + // identifier: Item ID + @Deprecated + public ExtendSettings addGroup(CreativeModeTab 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..9e712d0ac --- /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.world.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/ICompatItem.java b/common/src/main/java/net/pitan76/mcpitanlib/api/item/ICompatItem.java new file mode 100644 index 000000000..3130b8fdc --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/ICompatItem.java @@ -0,0 +1,10 @@ +package net.pitan76.mcpitanlib.api.item; + +import net.minecraft.world.item.Item; +import net.pitan76.mcpitanlib.midohra.item.ItemWrapper; + +public interface ICompatItem { + default ItemWrapper getWrapper() { + return this instanceof Item ? ItemWrapper.of((Item) this) : ItemWrapper.of(); + } +} 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..3d5e8b752 --- /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.world.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..0dcd6c387 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/args/StoppedUsingArgs.java @@ -0,0 +1,79 @@ +package net.pitan76.mcpitanlib.api.item.args; + +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; +import net.pitan76.mcpitanlib.api.entity.Player; + +import java.util.Optional; + +public class StoppedUsingArgs { + + public ItemStack stack; + public Level world; + public LivingEntity user; + public int remainingUseTicks; + + public StoppedUsingArgs(ItemStack stack, Level world, LivingEntity user, int remainingUseTicks) { + this.stack = stack; + this.world = world; + this.user = user; + this.remainingUseTicks = remainingUseTicks; + } + + public StoppedUsingArgs(ItemStack stack, Level world, LivingEntity user) { + this(stack, world, user, 0); + } + + public StoppedUsingArgs(ItemStack stack, Level world, Player player, int remainingUseTicks) { + this(stack, world, player.getEntity(), remainingUseTicks); + } + + public StoppedUsingArgs(ItemStack stack, Level 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 Level 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.isClientSide(); + } + + public boolean isServer() { + return !isClient(); + } + + public boolean isPlayer() { + return user instanceof net.minecraft.world.entity.player.Player; + } + + public Optional getPlayer() { + return isPlayer() ? Optional.of(new Player((net.minecraft.world.entity.player.Player) 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..db37fb3a0 --- /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.world.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/args/tool/MiningSpeedMultiplierArgs.java b/common/src/main/java/net/pitan76/mcpitanlib/api/item/args/tool/MiningSpeedMultiplierArgs.java new file mode 100644 index 000000000..6ef871d2c --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/args/tool/MiningSpeedMultiplierArgs.java @@ -0,0 +1,23 @@ +package net.pitan76.mcpitanlib.api.item.args.tool; + +import net.pitan76.mcpitanlib.api.event.BaseEvent; +import net.pitan76.mcpitanlib.midohra.block.BlockState; +import net.pitan76.mcpitanlib.midohra.item.ItemStack; + +public class MiningSpeedMultiplierArgs extends BaseEvent { + public ItemStack stack; + public BlockState state; + + public MiningSpeedMultiplierArgs(ItemStack stack, BlockState state) { + this.stack = stack; + this.state = state; + } + + public BlockState getState() { + return state; + } + + public ItemStack getStack() { + return stack; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/item/args/tool/SuitableForArgs.java b/common/src/main/java/net/pitan76/mcpitanlib/api/item/args/tool/SuitableForArgs.java new file mode 100644 index 000000000..29f7b6b78 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/args/tool/SuitableForArgs.java @@ -0,0 +1,21 @@ +package net.pitan76.mcpitanlib.api.item.args.tool; + +import net.pitan76.mcpitanlib.api.event.BaseEvent; +import net.pitan76.mcpitanlib.midohra.block.BlockState; +import net.pitan76.mcpitanlib.midohra.block.BlockWrapper; + +public class SuitableForArgs extends BaseEvent { + public BlockState state; + + public SuitableForArgs(BlockState state) { + this.state = state; + } + + public BlockState getState() { + return state; + } + + public BlockWrapper getBlock() { + return state.getBlock(); + } +} 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..4a923b921 --- /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.world.item.ItemUseAnimation; +import net.pitan76.mcpitanlib.api.util.CompatStringIdentifiable; + +public class CompatUseAction implements CompatStringIdentifiable { + private final ItemUseAnimation useAction; + + public static final CompatUseAction NONE = of(ItemUseAnimation.NONE); + public static final CompatUseAction EAT = of(ItemUseAnimation.EAT); + public static final CompatUseAction DRINK = of(ItemUseAnimation.DRINK); + public static final CompatUseAction BLOCK = of(ItemUseAnimation.BLOCK); + public static final CompatUseAction BOW = of(ItemUseAnimation.BOW); + public static final CompatUseAction SPEAR = of(ItemUseAnimation.SPEAR); + public static final CompatUseAction CROSSBOW = of(ItemUseAnimation.CROSSBOW); + public static final CompatUseAction SPYGLASS = of(ItemUseAnimation.SPYGLASS); + public static final CompatUseAction TOOT_HORN = of(ItemUseAnimation.TOOT_HORN); + public static final CompatUseAction BRUSH = of(ItemUseAnimation.BRUSH); + + public CompatUseAction(ItemUseAnimation useAction) { + this.useAction = useAction; + } + + public static CompatUseAction of(ItemUseAnimation useAction) { + return new CompatUseAction(useAction); + } + + @Deprecated + public ItemUseAnimation get() { + return useAction; + } + + public int getId() { + return useAction.getId(); + } + + public String getName() { + return useAction.getSerializedName(); + } + + @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..c2d20f70f --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/equipment/CompatEquipmentAsset.java @@ -0,0 +1,50 @@ +package net.pitan76.mcpitanlib.api.item.equipment; + +import net.minecraft.world.item.equipment.EquipmentAssets; +import net.minecraft.resources.ResourceKey; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; + +public class CompatEquipmentAsset { + private final ResourceKey raw; + + @Deprecated + public CompatEquipmentAsset(ResourceKey key) { + this.raw = key; + } + + @Deprecated + public ResourceKey raw() { + return raw; + } + + public CompatIdentifier getId() { + return CompatIdentifier.fromMinecraft(raw.identifier()); + } + + @Deprecated + public static CompatEquipmentAsset of(ResourceKey key) { + return new CompatEquipmentAsset(key); + } + + public static CompatEquipmentAsset of(CompatIdentifier id) { + return of(ResourceKey.create(EquipmentAssets.ROOT_ID, id.toMinecraft())); + } + + public static CompatEquipmentAsset of(String id) { + return of(CompatIdentifier.of(id)); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (!(obj instanceof CompatEquipmentAsset)) return false; + CompatEquipmentAsset that = (CompatEquipmentAsset) 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/item/equipment/CompatEquippableComponent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/item/equipment/CompatEquippableComponent.java new file mode 100644 index 000000000..993c4bbae --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/equipment/CompatEquippableComponent.java @@ -0,0 +1,36 @@ +package net.pitan76.mcpitanlib.api.item.equipment; + +import net.minecraft.world.item.equipment.Equippable; + +public class CompatEquippableComponent { + private final Equippable raw; + + @Deprecated + public CompatEquippableComponent(Equippable component) { + this.raw = component; + } + + @Deprecated + public Equippable raw() { + return raw; + } + + @Deprecated + public static CompatEquippableComponent of(Equippable component) { + return new CompatEquippableComponent(component); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (!(obj instanceof CompatEquippableComponent)) return false; + CompatEquippableComponent that = (CompatEquippableComponent) 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/item/equipment/EquippableComponentBuilder.java b/common/src/main/java/net/pitan76/mcpitanlib/api/item/equipment/EquippableComponentBuilder.java new file mode 100644 index 000000000..bf47cb0b9 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/equipment/EquippableComponentBuilder.java @@ -0,0 +1,94 @@ +package net.pitan76.mcpitanlib.api.item.equipment; + +import net.minecraft.world.item.equipment.Equippable; +import net.minecraft.world.entity.EntityType; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.core.HolderGetter; +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() { + Equippable.Builder component = Equippable.builder(equipmentType.getSlot()); + if (equipSound != null) + component.setEquipSound(equipSound.getEntry() != null ? equipSound.getEntry() : equipSound.getReference()); + if (shearingSound != null) + component.setShearingSound(shearingSound.getEntry() != null ? shearingSound.getEntry() : shearingSound.getReference()); + + component.setEquipOnInteract(equipOnInteract); + component.setCanBeSheared(canBeSheared); + if (model != null) component.setAsset(model.raw()); + if (allowedEntities != null) { + HolderGetter> registryEntryLookup = BuiltInRegistries.acquireBootstrapRegistrationLookup(BuiltInRegistries.ENTITY_TYPE); + component.setAllowedEntities(registryEntryLookup.getOrThrow((net.minecraft.tags.TagKey>) allowedEntities.getTagKey())); + } + + return CompatEquippableComponent.of(component.build()); + } +} 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..54d6ce9f4 --- /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.core.component.DataComponents; +import net.minecraft.world.item.component.ItemLore; +import net.minecraft.world.item.ItemStack; +import net.minecraft.network.chat.Component; + +import java.util.List; + +public class LoreUtil { + public static boolean hasLore(ItemStack stack) { + return stack.has(DataComponents.LORE); + } + + public static List getLore(ItemStack stack) { + if (!hasLore(stack)) return List.of(); + return stack.get(DataComponents.LORE).lines(); + } + + public static List getLoreAsStringList(ItemStack stack) { + return getLore(stack).stream() + .map(Component::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(DataComponents.LORE, new ItemLore(lore)); + } + + public static void setLoreStringList(ItemStack stack, List lore) { + setLore(stack, lore.stream() + .map(Component::nullToEmpty) + .toList()); + } + + public static void setLore(ItemStack stack, String lore) { + setLore(stack, lore.lines() + .map(Component::nullToEmpty) + .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..81f794924 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/tool/CompatibleAxeItem.java @@ -0,0 +1,90 @@ +package net.pitan76.mcpitanlib.api.item.tool; + +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.item.AxeItem; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.ToolMaterial; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +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(), attackDamage, attackSpeed, settings.build()); + this.settings = settings; + } + + public CompatibleAxeItem(float attackDamage, float attackSpeed, ToolMaterial material, CompatibleItemSettings settings) { + super(material, attackDamage, attackSpeed, settings.build()); + this.settings = settings; + } + + @Override + public CompatibleItemSettings getCompatSettings() { + return settings; + } + + public boolean overrideIsSuitableFor(BlockState state) { + return super.isCorrectToolForDrops(getDefaultInstance(), state); + } + + @Deprecated + @Override + public boolean isCorrectToolForDrops(ItemStack stack, BlockState state) { + return overrideIsSuitableFor(state); + } + + public float overrideGetMiningSpeedMultiplier(ItemStack stack, BlockState state) { + return 1.0F; + } + + @Deprecated + @Override + public float getDestroySpeed(ItemStack stack, BlockState state) { + return overrideGetMiningSpeedMultiplier(stack, state) * super.getDestroySpeed(stack, state); + } + + @Deprecated + @Override + public void hurtEnemy(ItemStack stack, LivingEntity target, LivingEntity attacker) { + postHit(new PostHitEvent(stack, target, attacker)); + } + + @Deprecated + @Override + public boolean mineBlock(ItemStack stack, Level 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) { + super.hurtEnemy(event.stack, event.target, event.attacker); + return true; + } + + /** + * post mine event + * @param event PostMineEvent + * @return boolean + */ + public boolean postMine(PostMineEvent event) { + return super.mineBlock(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..7a7f8ee02 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/tool/CompatibleHoeItem.java @@ -0,0 +1,90 @@ +package net.pitan76.mcpitanlib.api.item.tool; + +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.item.HoeItem; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.ToolMaterial; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +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(), attackDamage, attackSpeed, settings.build()); + this.settings = settings; + } + + public CompatibleHoeItem(int attackDamage, float attackSpeed, ToolMaterial material, CompatibleItemSettings settings) { + super(material, attackDamage, attackSpeed, settings.build()); + this.settings = settings; + } + + @Override + public net.pitan76.mcpitanlib.api.item.v2.CompatibleItemSettings getCompatSettings() { + return settings; + } + + public boolean overrideIsSuitableFor(BlockState state) { + return super.isCorrectToolForDrops(getDefaultInstance(), state); + } + + @Deprecated + @Override + public boolean isCorrectToolForDrops(ItemStack stack, BlockState state) { + return overrideIsSuitableFor(state); + } + + public float overrideGetMiningSpeedMultiplier(ItemStack stack, BlockState state) { + return 1.0F; + } + + @Deprecated + @Override + public float getDestroySpeed(ItemStack stack, BlockState state) { + return overrideGetMiningSpeedMultiplier(stack, state) * super.getDestroySpeed(stack, state); + } + + @Deprecated + @Override + public void hurtEnemy(ItemStack stack, LivingEntity target, LivingEntity attacker) { + postHit(new PostHitEvent(stack, target, attacker)); + } + + @Deprecated + @Override + public boolean mineBlock(ItemStack stack, Level 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) { + super.hurtEnemy(event.stack, event.target, event.attacker); + return true; + } + + /** + * post mine event + * @param event PostMineEvent + * @return boolean + */ + public boolean postMine(PostMineEvent event) { + return super.mineBlock(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..57dc79af3 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/tool/CompatibleMiningToolItem.java @@ -0,0 +1,126 @@ +package net.pitan76.mcpitanlib.api.item.tool; + +import net.minecraft.world.item.Item.Properties; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.ToolMaterial; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.InteractionHand; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +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 Item implements CompatItemProvider { + + public CompatibleItemSettings settings; + + @Deprecated + protected CompatibleMiningToolItem(float attackDamage, float attackSpeed, ToolMaterial material, net.minecraft.tags.TagKey effectiveBlocks, Properties settings) { + super(settings.tool(material, effectiveBlocks, attackDamage, attackSpeed, 0)); + } + + 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.isCorrectToolForDrops(getDefaultInstance(), state); + } + + @Deprecated + @Override + public boolean isCorrectToolForDrops(ItemStack stack, BlockState state) { + return overrideIsSuitableFor(state); + } + + public float overrideGetMiningSpeedMultiplier(ItemStack stack, BlockState state) { + return 1.0F; + } + + @Deprecated + @Override + public float getDestroySpeed(ItemStack stack, BlockState state) { + return overrideGetMiningSpeedMultiplier(stack, state); + } + + /** + * post hit event + * @param event PostHitEvent + * @return boolean + */ + public boolean postHit(PostHitEvent event) { + super.hurtEnemy(event.stack, event.target, event.attacker); + return true; + } + + /** + * post mine event + * @param event PostMineEvent + * @return boolean + */ + public boolean postMine(PostMineEvent event) { + return super.mineBlock(event.stack, event.world, event.state, event.pos, event.miner); + } + + @Deprecated + @Override + public void hurtEnemy(ItemStack stack, LivingEntity target, LivingEntity attacker) { + postHit(new PostHitEvent(stack, target, attacker)); + } + + @Deprecated + @Override + public boolean mineBlock(ItemStack stack, Level 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 InteractionResult interactLivingEntity(ItemStack stack, Player user, LivingEntity entity, InteractionHand 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.interactLivingEntity(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..cba7a7722 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/tool/CompatiblePickaxeItem.java @@ -0,0 +1,90 @@ +package net.pitan76.mcpitanlib.api.item.tool; + +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.ToolMaterial; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +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 Item implements CompatItemProvider { + + public CompatibleItemSettings settings; + + public CompatiblePickaxeItem(CompatibleToolMaterial material, int attackDamage, float attackSpeed, CompatibleItemSettings settings) { + super(settings.build().pickaxe(material.build(), attackDamage, attackSpeed)); + this.settings = settings; + } + + public CompatiblePickaxeItem(int attackDamage, float attackSpeed, ToolMaterial material, CompatibleItemSettings settings) { + super(settings.build().pickaxe(material, attackDamage, attackSpeed)); + this.settings = settings; + } + + @Override + public CompatibleItemSettings getCompatSettings() { + return settings; + } + + public boolean overrideIsSuitableFor(BlockState state) { + return super.isCorrectToolForDrops(getDefaultInstance(), state); + } + + @Deprecated + @Override + public boolean isCorrectToolForDrops(ItemStack stack, BlockState state) { + return overrideIsSuitableFor(state); + } + + public float overrideGetMiningSpeedMultiplier(ItemStack stack, BlockState state) { + return 1.0F; + } + + @Deprecated + @Override + public float getDestroySpeed(ItemStack stack, BlockState state) { + return overrideGetMiningSpeedMultiplier(stack, state) * super.getDestroySpeed(stack, state); + } + + @Deprecated + @Override + public void hurtEnemy(ItemStack stack, LivingEntity target, LivingEntity attacker) { + postHit(new PostHitEvent(stack, target, attacker)); + } + + @Deprecated + @Override + public boolean mineBlock(ItemStack stack, Level 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) { + super.hurtEnemy(event.stack, event.target, event.attacker); + return true; + } + + /** + * post mine event + * @param event PostMineEvent + * @return boolean + */ + public boolean postMine(PostMineEvent event) { + return super.mineBlock(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..478348ecb --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/tool/CompatibleShearsItem.java @@ -0,0 +1,90 @@ +package net.pitan76.mcpitanlib.api.item.tool; + +import net.minecraft.world.item.Item.Properties; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.ShearsItem; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +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(Properties 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.isCorrectToolForDrops(getDefaultInstance(), state); + } + + @Deprecated + @Override + public boolean isCorrectToolForDrops(ItemStack stack, BlockState state) { + return overrideIsSuitableFor(state); + } + + public float overrideGetMiningSpeedMultiplier(ItemStack stack, BlockState state) { + return 1.0F; + } + + @Deprecated + @Override + public float getDestroySpeed(ItemStack stack, BlockState state) { + return overrideGetMiningSpeedMultiplier(stack, state) * super.getDestroySpeed(stack, state); + } + + @Deprecated + @Override + public void hurtEnemy(ItemStack stack, LivingEntity target, LivingEntity attacker) { + postHit(new PostHitEvent(stack, target, attacker)); + } + + @Deprecated + @Override + public boolean mineBlock(ItemStack stack, Level 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) { + super.hurtEnemy(event.stack, event.target, event.attacker); + return true; + } + + /** + * post mine event + * @param event PostMineEvent + * @return boolean + */ + public boolean postMine(PostMineEvent event) { + return super.mineBlock(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..268b15cd4 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/tool/CompatibleShovelItem.java @@ -0,0 +1,90 @@ +package net.pitan76.mcpitanlib.api.item.tool; + +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.ShovelItem; +import net.minecraft.world.item.ToolMaterial; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +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(), attackDamage, attackSpeed, settings.build()); + } + + public CompatibleShovelItem(float attackDamage, float attackSpeed, ToolMaterial material, CompatibleItemSettings settings) { + super(material, attackDamage, attackSpeed, settings.build()); + } + + @Override + public CompatibleItemSettings getCompatSettings() { + return settings; + } + + public boolean overrideIsSuitableFor(BlockState state) { + return super.isCorrectToolForDrops(getDefaultInstance(), state); + } + + @Deprecated + @Override + public boolean isCorrectToolForDrops(ItemStack stack, BlockState state) { + return overrideIsSuitableFor(state); + } + + public float overrideGetMiningSpeedMultiplier(ItemStack stack, BlockState state) { + return 1.0F; + } + + @Deprecated + @Override + public float getDestroySpeed(ItemStack stack, BlockState state) { + return overrideGetMiningSpeedMultiplier(stack, state) * super.getDestroySpeed(stack, state); + } + + @Deprecated + @Override + public void hurtEnemy(ItemStack stack, LivingEntity target, LivingEntity attacker) { + postHit(new PostHitEvent(stack, target, attacker)); + } + + @Deprecated + @Override + public boolean mineBlock(ItemStack stack, Level 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) { + super.hurtEnemy(event.stack, event.target, event.attacker); + return true; + } + + /** + * post mine event + * + * @param event PostMineEvent + * @return boolean + */ + public boolean postMine(PostMineEvent event) { + return super.mineBlock(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..145df647e --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/tool/CompatibleSwordItem.java @@ -0,0 +1,90 @@ +package net.pitan76.mcpitanlib.api.item.tool; + +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.ToolMaterial; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +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 Item implements CompatItemProvider { + + public CompatibleItemSettings settings; + + public CompatibleSwordItem(CompatibleToolMaterial material, int attackDamage, float attackSpeed, CompatibleItemSettings settings) { + super(settings.build().sword(material.build(), attackDamage, attackSpeed)); + this.settings = settings; + } + + public CompatibleSwordItem(int attackDamage, float attackSpeed, ToolMaterial material, CompatibleItemSettings settings) { + super(settings.build().sword(material, attackDamage, attackSpeed)); + this.settings = settings; + } + + @Override + public CompatibleItemSettings getCompatSettings() { + return settings; + } + + public boolean overrideIsSuitableFor(BlockState state) { + return super.isCorrectToolForDrops(getDefaultInstance(), state); + } + + @Deprecated + @Override + public boolean isCorrectToolForDrops(ItemStack stack, BlockState state) { + return overrideIsSuitableFor(state); + } + + public float overrideGetMiningSpeedMultiplier(ItemStack stack, BlockState state) { + return 1.0F; + } + + @Deprecated + @Override + public float getDestroySpeed(ItemStack stack, BlockState state) { + return overrideGetMiningSpeedMultiplier(stack, state) * super.getDestroySpeed(stack, state); + } + + @Deprecated + @Override + public void hurtEnemy(ItemStack stack, LivingEntity target, LivingEntity attacker) { + postHit(new PostHitEvent(stack, target, attacker)); + } + + @Deprecated + @Override + public boolean mineBlock(ItemStack stack, Level 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) { + super.hurtEnemy(event.stack, event.target, event.attacker); + return true; + } + + /** + * post mine event + * @param event PostMineEvent + * @return boolean + */ + public boolean postMine(PostMineEvent event) { + return super.mineBlock(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..10ddc81fb --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/tool/CompatibleToolItem.java @@ -0,0 +1,87 @@ +package net.pitan76.mcpitanlib.api.item.tool; + +import net.minecraft.world.item.Item.Properties; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +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 Item implements CompatItemProvider { + + public CompatibleToolMaterial material; + + public CompatibleItemSettings settings; + + @Deprecated + protected CompatibleToolItem(Properties settings) { + super(settings); + } + + public CompatibleToolItem(CompatibleToolMaterial material, CompatibleItemSettings settings) { + this(settings.build().tool(material.build(), null, 0, 0, 0)); + this.material = material; + this.settings = settings; + } + + @Override + public CompatibleItemSettings getCompatSettings() { + return settings; + } + + public boolean overrideIsSuitableFor(BlockState state) { + return super.isCorrectToolForDrops(getDefaultInstance(), state); + } + + @Deprecated + @Override + public boolean isCorrectToolForDrops(ItemStack stack, BlockState state) { + return overrideIsSuitableFor(state); + } + + public float overrideGetMiningSpeedMultiplier(ItemStack stack, BlockState state) { + return 1.0F; + } + + @Deprecated + @Override + public float getDestroySpeed(ItemStack stack, BlockState state) { + return overrideGetMiningSpeedMultiplier(stack, state) * material.getCompatMiningSpeedMultiplier(); + } + + @Deprecated + @Override + public void hurtEnemy(ItemStack stack, LivingEntity target, LivingEntity attacker) { + postHit(new PostHitEvent(stack, target, attacker)); + } + + @Deprecated + @Override + public boolean mineBlock(ItemStack stack, Level 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) { + super.hurtEnemy(event.stack, event.target, event.attacker); + return true; + } + + /** + * post mine event + * @param event PostMineEvent + * @return boolean + */ + public boolean postMine(PostMineEvent event) { + return super.mineBlock(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..90b0dd03a --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/tool/CompatibleToolMaterial.java @@ -0,0 +1,85 @@ +package net.pitan76.mcpitanlib.api.item.tool; + +import net.minecraft.world.level.block.Block; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ToolMaterial; +import net.minecraft.world.item.crafting.Ingredient; +import net.minecraft.tags.BlockTags; +import net.minecraft.tags.ItemTags; +import net.minecraft.tags.TagKey; +import net.pitan76.mcpitanlib.api.util.IngredientUtil; + +public interface CompatibleToolMaterial { + + int getCompatMiningLevel(); + + float getCompatAttackDamage(); + + float getCompatMiningSpeedMultiplier(); + + default Ingredient getCompatRepairIngredient() { + return IngredientUtil.fromTagByIdentifier(getRepairTag().location()); + } + + int getCompatDurability(); + + int getCompatEnchantability(); + + default TagKey getInverseTag() { + + return level2inverseTag(getCompatMiningLevel()); + } + + 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_TOOL_MATERIALS; + } + + default ToolMaterial build() { + return new ToolMaterial(getInverseTag(), getCompatDurability(), getCompatMiningSpeedMultiplier(), getCompatAttackDamage(), getCompatEnchantability(), getRepairTag()); + } +} \ 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..bfb10e892 --- /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.sounds.SoundEvent; +import net.minecraft.resources.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..3d109d387 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/v2/CompatItem.java @@ -0,0 +1,103 @@ +package net.pitan76.mcpitanlib.api.item.v2; + +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EquipmentSlot; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.ItemUseAnimation; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.item.Rarity; +import net.minecraft.world.level.Level; +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 ItemUseAnimation getUseAnimation(ItemStack stack) { + return getUseAction(new UseActionArgs(stack)).get(); + } + + public CompatUseAction getUseAction(UseActionArgs args) { + return CompatUseAction.of(super.getUseAnimation(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; + } + + @Deprecated + @Override + public boolean releaseUsing(ItemStack stack, Level world, LivingEntity user, int remainingUseTicks) { + return onStoppedUsing(new StoppedUsingArgs(stack, world, user, remainingUseTicks)); + } + + public boolean onStoppedUsing(StoppedUsingArgs args) { + return super.releaseUsing(args.stack, args.world, args.user, args.remainingUseTicks); + } + + @Deprecated + @Override + public void inventoryTick(ItemStack stack, ServerLevel world, Entity entity, @Nullable EquipmentSlot slot) { + inventoryTick(new InventoryTickEvent(stack, world, entity, slot)); + } + + public void inventoryTick(InventoryTickEvent e) { + super.inventoryTick(e.stack, e.getServerWorld(), e.entity, e.equipmentSlot); + } +} 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..c0a540983 --- /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.world.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..86e74fd93 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/v2/CompatibleItemSettings.java @@ -0,0 +1,208 @@ +package net.pitan76.mcpitanlib.api.item.v2; + +import net.minecraft.core.component.DataComponents; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.CreativeModeTab; +import net.minecraft.resources.ResourceKey; +import net.minecraft.core.registries.Registries; +import net.minecraft.resources.Identifier; +import net.minecraft.world.item.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.core.registry.MCPLRegistry1_20; +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(CreativeModeTab 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() { + settings.useItemDescriptionPrefix(); + changedTranslationKey = true; + return this; + } + + public CompatibleItemSettings useBlockPrefixedTranslationKey() { + settings.useBlockDescriptionPrefix(); + changedTranslationKey = true; + return this; + } + + public CompatibleItemSettings translationKey(String translationKey) { + settings.overrideDescription(translationKey); + changedTranslationKey = true; + return this; + } + + public CompatibleItemSettings enchantable(int enchantability) { + settings.enchantable(enchantability); + this.enchantability = enchantability; + return this; + } + + public CompatibleItemSettings repairable(RepairIngredientTag tag) { + settings.repairable(tag.getTag()); + this.repairIngredientTag = tag; + return this; + } + + public CompatibleItemSettings equipable(CompatEquippableComponent component) { + settings.component(DataComponents.EQUIPPABLE, component.raw()); + return this; + } + + public CompatibleItemSettings equipable(EquippableComponentBuilder builder) { + return equipable(builder.build()); + } + + public CompatibleItemSettings attributeModifiers(CompatAttributeModifiersComponent component) { + settings.component(DataComponents.ATTRIBUTE_MODIFIERS, component.raw()); + return this; + } + + public CompatibleItemSettings attributeModifiers(AttributeModifiersComponentBuilder builder) { + return attributeModifiers(builder.build()); + } + + @Override + public ExtendSettings build() { + super.build(); + + if (identifier != null) { + settings.setId(ResourceKey.create(Registries.ITEM, identifier.toMinecraft())); + + if (itemGroupId != null) { + ResourceKey key = ResourceKey.create(Registries.CREATIVE_MODE_TAB, itemGroupId); + MCPLRegistry1_20.addItemGroupItem(key, identifier.toMinecraft()); + } + } + + return settings; + } + + // Deprecated + + @Deprecated + @Override + public net.pitan76.mcpitanlib.api.item.CompatibleItemSettings addGroup(CreativeModeTab 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(CreativeModeTab 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..7a58c2d1e --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/v2/ExtendBlockItem.java @@ -0,0 +1,77 @@ +package net.pitan76.mcpitanlib.api.item.v2; + +import net.minecraft.world.item.Item.Properties; +import net.minecraft.world.item.Item.TooltipContext; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.item.component.TooltipDisplay; +import net.minecraft.world.item.BlockItem; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.context.UseOnContext; +import net.minecraft.world.item.TooltipFlag; +import net.minecraft.network.chat.Component; +import net.minecraft.world.InteractionResult; +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.UseOnContextMixin; + +import java.util.List; +import java.util.function.Consumer; + +public class ExtendBlockItem extends BlockItem implements CompatItemProvider { + + public CompatibleItemSettings settings; + + @Deprecated + public ExtendBlockItem(Block block, Properties 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 InteractionResult useOn(UseOnContext context) { + UseOnContextMixin contextAccessor = (UseOnContextMixin) context; + return onRightClickOnBlock(new ItemUseOnBlockEvent(context.getPlayer(), context.getHand(), contextAccessor.getHitResult())).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.useOn(event.toIUC())); + } + + @Deprecated + @Override + public void appendHoverText(ItemStack stack, TooltipContext context, TooltipDisplay displayComponent, Consumer textConsumer, TooltipFlag type) { + appendTooltip(new ItemAppendTooltipEvent(stack, context, displayComponent, textConsumer, type)); + } + + @Deprecated + @Override + public void appendTooltip(ItemAppendTooltipEvent event, Options options) { + CompatItemProvider.super.appendTooltip(event, options); + } + + public void appendTooltip(ItemAppendTooltipEvent event) { + super.appendHoverText(event.getStack(), event.getContext(), event.displayComponent, event.textConsumer, 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..1e0dbc712 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/v3/CompatArmorMaterial.java @@ -0,0 +1,16 @@ +package net.pitan76.mcpitanlib.api.item.v3; + +import net.minecraft.world.item.Item; +import net.minecraft.tags.TagKey; +import net.pitan76.mcpitanlib.api.tag.item.RepairIngredientTag; + +public interface CompatArmorMaterial extends net.pitan76.mcpitanlib.api.item.v2.CompatArmorMaterial { + + @Deprecated + @Override + default TagKey getRepairTag() { + return getRepairIngredientTag().getTag(); + } + + RepairIngredientTag getRepairIngredientTag(); +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/item/v3/CompatItem.java b/common/src/main/java/net/pitan76/mcpitanlib/api/item/v3/CompatItem.java new file mode 100644 index 000000000..5de0fd647 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/v3/CompatItem.java @@ -0,0 +1,19 @@ +package net.pitan76.mcpitanlib.api.item.v3; + +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 CompatItem extends net.pitan76.mcpitanlib.api.item.v2.CompatItem { + public CompatItem(CompatibleItemSettings settings) { + super(settings); + } + + public CompatItem(ItemSettingsBuilder builder, CompatIdentifier id) { + super(builder.build(id)); + } + + public CompatItem(ItemSettingsBuilder builder) { + super(builder.build()); + } +} 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..00748c68e --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/v3/CompatToolMaterial.java @@ -0,0 +1,16 @@ +package net.pitan76.mcpitanlib.api.item.v3; + +import net.minecraft.world.item.Item; +import net.minecraft.tags.TagKey; +import net.pitan76.mcpitanlib.api.item.tool.CompatibleToolMaterial; +import net.pitan76.mcpitanlib.api.tag.item.RepairIngredientTag; + +public interface CompatToolMaterial extends CompatibleToolMaterial { + @Deprecated + @Override + default TagKey getRepairTag() { + return getRepairIngredientTag().getTag(); + } + + 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..305d63f1f --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/v3/VanillaCompatToolMaterial.java @@ -0,0 +1,72 @@ +package net.pitan76.mcpitanlib.api.item.v3; + +import net.minecraft.world.level.block.Block; +import net.minecraft.world.item.ToolMaterial; +import net.minecraft.tags.TagKey; +import net.pitan76.mcpitanlib.api.tag.item.RepairIngredientTag; + +public class VanillaCompatToolMaterial implements CompatToolMaterial { + private final ToolMaterial material; + + public static final VanillaCompatToolMaterial WOOD = of(ToolMaterial.WOOD); + public static final VanillaCompatToolMaterial STONE = of(ToolMaterial.STONE); + public static final VanillaCompatToolMaterial IRON = of(ToolMaterial.IRON); + public static final VanillaCompatToolMaterial GOLD = of(ToolMaterial.GOLD); + public static final VanillaCompatToolMaterial DIAMOND = of(ToolMaterial.DIAMOND); + public static final VanillaCompatToolMaterial NETHERITE = of(ToolMaterial.NETHERITE); + + protected VanillaCompatToolMaterial(ToolMaterial material) { + this.material = material; + } + + private static VanillaCompatToolMaterial of(ToolMaterial material) { + return new VanillaCompatToolMaterial(material); + } + + @Override + public RepairIngredientTag getRepairIngredientTag() { + return new RepairIngredientTag(material.repairItems()); + } + + @Override + public int getCompatDurability() { + return material.durability(); + } + + @Override + public float getCompatMiningSpeedMultiplier() { + return material.speed(); + } + + @Override + public float getCompatAttackDamage() { + return material.attackDamageBonus(); + } + + @Override + public int getCompatMiningLevel() { + TagKey tag = material.incorrectBlocksForDrops(); + if (tag == ToolMaterial.WOOD.incorrectBlocksForDrops()) return 0; + if (tag == ToolMaterial.STONE.incorrectBlocksForDrops()) return 1; + if (tag == ToolMaterial.IRON.incorrectBlocksForDrops()) return 2; + if (tag == ToolMaterial.GOLD.incorrectBlocksForDrops()) return 2; + if (tag == ToolMaterial.DIAMOND.incorrectBlocksForDrops()) return 3; + if (tag == ToolMaterial.NETHERITE.incorrectBlocksForDrops()) return 4; + return -1; + } + + @Override + public int getCompatEnchantability() { + return material.enchantmentValue(); + } + + @Deprecated + public ToolMaterial toMinecraft() { + return material; + } + + @Override + public ToolMaterial build() { + return material; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/item/v3/tool/CompatAxeItem.java b/common/src/main/java/net/pitan76/mcpitanlib/api/item/v3/tool/CompatAxeItem.java new file mode 100644 index 000000000..fe745bee9 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/v3/tool/CompatAxeItem.java @@ -0,0 +1,48 @@ +package net.pitan76.mcpitanlib.api.item.v3.tool; + +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.state.BlockState; +import net.pitan76.mcpitanlib.api.item.args.tool.MiningSpeedMultiplierArgs; +import net.pitan76.mcpitanlib.api.item.args.tool.SuitableForArgs; +import net.pitan76.mcpitanlib.api.item.tool.CompatibleAxeItem; +import net.pitan76.mcpitanlib.api.item.tool.CompatibleToolMaterial; +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 CompatAxeItem extends CompatibleAxeItem { + + public CompatAxeItem(CompatibleToolMaterial material, float attackDamage, float attackSpeed, CompatibleItemSettings settings) { + super(material, attackDamage, attackSpeed, settings); + } + + public CompatAxeItem(CompatibleToolMaterial material, float attackDamage, float attackSpeed, ItemSettingsBuilder builder, CompatIdentifier id) { + this(material, attackDamage, attackSpeed, builder.build(id)); + } + + public CompatAxeItem(CompatibleToolMaterial material, float attackDamage, float attackSpeed, ItemSettingsBuilder builder) { + this(material, attackDamage, attackSpeed, builder.build()); + } + + public float getMiningSpeedMultiplier(MiningSpeedMultiplierArgs args) { + return super.overrideGetMiningSpeedMultiplier(args.stack.toMinecraft(), args.state.toMinecraft()); + } + + @Override + @Deprecated + public float overrideGetMiningSpeedMultiplier(ItemStack stack, BlockState state) { + return getMiningSpeedMultiplier( + new MiningSpeedMultiplierArgs(net.pitan76.mcpitanlib.midohra.item.ItemStack.of(stack), + net.pitan76.mcpitanlib.midohra.block.BlockState.of(state))); + } + + public boolean isSuitableFor(SuitableForArgs args) { + return super.overrideIsSuitableFor(args.state.toMinecraft()); + } + + @Override + @Deprecated + public boolean overrideIsSuitableFor(BlockState state) { + return isSuitableFor(new SuitableForArgs(net.pitan76.mcpitanlib.midohra.block.BlockState.of(state))); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/item/v3/tool/CompatHoeItem.java b/common/src/main/java/net/pitan76/mcpitanlib/api/item/v3/tool/CompatHoeItem.java new file mode 100644 index 000000000..ab101244c --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/v3/tool/CompatHoeItem.java @@ -0,0 +1,48 @@ +package net.pitan76.mcpitanlib.api.item.v3.tool; + +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.state.BlockState; +import net.pitan76.mcpitanlib.api.item.args.tool.MiningSpeedMultiplierArgs; +import net.pitan76.mcpitanlib.api.item.args.tool.SuitableForArgs; +import net.pitan76.mcpitanlib.api.item.tool.CompatibleHoeItem; +import net.pitan76.mcpitanlib.api.item.tool.CompatibleToolMaterial; +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 CompatHoeItem extends CompatibleHoeItem { + + public CompatHoeItem(CompatibleToolMaterial material, int attackDamage, float attackSpeed, CompatibleItemSettings settings) { + super(material, attackDamage, attackSpeed, settings); + } + + public CompatHoeItem(CompatibleToolMaterial material, int attackDamage, float attackSpeed, ItemSettingsBuilder builder, CompatIdentifier id) { + this(material, attackDamage, attackSpeed, builder.build(id)); + } + + public CompatHoeItem(CompatibleToolMaterial material, int attackDamage, float attackSpeed, ItemSettingsBuilder builder) { + this(material, attackDamage, attackSpeed, builder.build()); + } + + public float getMiningSpeedMultiplier(MiningSpeedMultiplierArgs args) { + return super.overrideGetMiningSpeedMultiplier(args.stack.toMinecraft(), args.state.toMinecraft()); + } + + @Override + @Deprecated + public float overrideGetMiningSpeedMultiplier(ItemStack stack, BlockState state) { + return getMiningSpeedMultiplier( + new MiningSpeedMultiplierArgs(net.pitan76.mcpitanlib.midohra.item.ItemStack.of(stack), + net.pitan76.mcpitanlib.midohra.block.BlockState.of(state))); + } + + public boolean isSuitableFor(SuitableForArgs args) { + return super.overrideIsSuitableFor(args.state.toMinecraft()); + } + + @Override + @Deprecated + public boolean overrideIsSuitableFor(BlockState state) { + return isSuitableFor(new SuitableForArgs(net.pitan76.mcpitanlib.midohra.block.BlockState.of(state))); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/item/v3/tool/CompatMiningToolItem.java b/common/src/main/java/net/pitan76/mcpitanlib/api/item/v3/tool/CompatMiningToolItem.java new file mode 100644 index 000000000..72fdb5c03 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/v3/tool/CompatMiningToolItem.java @@ -0,0 +1,60 @@ +package net.pitan76.mcpitanlib.api.item.v3.tool; + +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import net.pitan76.mcpitanlib.api.item.args.tool.MiningSpeedMultiplierArgs; +import net.pitan76.mcpitanlib.api.item.args.tool.SuitableForArgs; +import net.pitan76.mcpitanlib.api.item.tool.CompatibleMiningToolItem; +import net.pitan76.mcpitanlib.api.item.tool.CompatibleToolMaterial; +import net.pitan76.mcpitanlib.api.item.v2.CompatibleItemSettings; +import net.pitan76.mcpitanlib.api.item.v2.ItemSettingsBuilder; +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.CompatIdentifier; + +public class CompatMiningToolItem extends CompatibleMiningToolItem { + + public CompatMiningToolItem(CompatibleToolMaterial material, int attackDamage, float attackSpeed, TagKey tagKey, CompatibleItemSettings settings) { + super(material, attackDamage, attackSpeed, tagKey, settings); + } + + public CompatMiningToolItem(CompatibleToolMaterial material, int attackDamage, float attackSpeed, CompatTagKey tagKey, CompatibleItemSettings settings) { + super(material, attackDamage, attackSpeed, tagKey, settings); + } + + public CompatMiningToolItem(CompatibleToolMaterial material, int attackDamage, float attackSpeed, BlockTagKey tagKey, CompatibleItemSettings settings) { + super(material, attackDamage, attackSpeed, tagKey, settings); + } + + public CompatMiningToolItem(CompatibleToolMaterial material, int attackDamage, float attackSpeed, TagKey tagKey, ItemSettingsBuilder builder, CompatIdentifier id) { + this(material, attackDamage, attackSpeed, tagKey, builder.build(id)); + } + + public CompatMiningToolItem(CompatibleToolMaterial material, int attackDamage, float attackSpeed, TagKey tagKey, ItemSettingsBuilder builder) { + this(material, attackDamage, attackSpeed, tagKey, builder.build()); + } + + public float getMiningSpeedMultiplier(MiningSpeedMultiplierArgs args) { + return super.overrideGetMiningSpeedMultiplier(args.stack.toMinecraft(), args.state.toMinecraft()); + } + + @Override + @Deprecated + public float overrideGetMiningSpeedMultiplier(ItemStack stack, BlockState state) { + return getMiningSpeedMultiplier( + new MiningSpeedMultiplierArgs(net.pitan76.mcpitanlib.midohra.item.ItemStack.of(stack), + net.pitan76.mcpitanlib.midohra.block.BlockState.of(state))); + } + + public boolean isSuitableFor(SuitableForArgs args) { + return super.overrideIsSuitableFor(args.state.toMinecraft()); + } + + @Override + @Deprecated + public boolean overrideIsSuitableFor(BlockState state) { + return isSuitableFor(new SuitableForArgs(net.pitan76.mcpitanlib.midohra.block.BlockState.of(state))); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/item/v3/tool/CompatPickaxeItem.java b/common/src/main/java/net/pitan76/mcpitanlib/api/item/v3/tool/CompatPickaxeItem.java new file mode 100644 index 000000000..674398e16 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/v3/tool/CompatPickaxeItem.java @@ -0,0 +1,48 @@ +package net.pitan76.mcpitanlib.api.item.v3.tool; + +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.state.BlockState; +import net.pitan76.mcpitanlib.api.item.args.tool.MiningSpeedMultiplierArgs; +import net.pitan76.mcpitanlib.api.item.args.tool.SuitableForArgs; +import net.pitan76.mcpitanlib.api.item.tool.CompatiblePickaxeItem; +import net.pitan76.mcpitanlib.api.item.tool.CompatibleToolMaterial; +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 CompatPickaxeItem extends CompatiblePickaxeItem { + + public CompatPickaxeItem(CompatibleToolMaterial material, int attackDamage, float attackSpeed, CompatibleItemSettings settings) { + super(material, attackDamage, attackSpeed, settings); + } + + public CompatPickaxeItem(CompatibleToolMaterial material, int attackDamage, float attackSpeed, ItemSettingsBuilder builder, CompatIdentifier id) { + this(material, attackDamage, attackSpeed, builder.build(id)); + } + + public CompatPickaxeItem(CompatibleToolMaterial material, int attackDamage, float attackSpeed, ItemSettingsBuilder builder) { + this(material, attackDamage, attackSpeed, builder.build()); + } + + public float getMiningSpeedMultiplier(MiningSpeedMultiplierArgs args) { + return super.overrideGetMiningSpeedMultiplier(args.stack.toMinecraft(), args.state.toMinecraft()); + } + + @Override + @Deprecated + public float overrideGetMiningSpeedMultiplier(ItemStack stack, BlockState state) { + return getMiningSpeedMultiplier( + new MiningSpeedMultiplierArgs(net.pitan76.mcpitanlib.midohra.item.ItemStack.of(stack), + net.pitan76.mcpitanlib.midohra.block.BlockState.of(state))); + } + + public boolean isSuitableFor(SuitableForArgs args) { + return super.overrideIsSuitableFor(args.state.toMinecraft()); + } + + @Override + @Deprecated + public boolean overrideIsSuitableFor(BlockState state) { + return isSuitableFor(new SuitableForArgs(net.pitan76.mcpitanlib.midohra.block.BlockState.of(state))); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/item/v3/tool/CompatShearsItem.java b/common/src/main/java/net/pitan76/mcpitanlib/api/item/v3/tool/CompatShearsItem.java new file mode 100644 index 000000000..f51ddf2cd --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/v3/tool/CompatShearsItem.java @@ -0,0 +1,47 @@ +package net.pitan76.mcpitanlib.api.item.v3.tool; + +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.state.BlockState; +import net.pitan76.mcpitanlib.api.item.args.tool.MiningSpeedMultiplierArgs; +import net.pitan76.mcpitanlib.api.item.args.tool.SuitableForArgs; +import net.pitan76.mcpitanlib.api.item.tool.CompatibleShearsItem; +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 CompatShearsItem extends CompatibleShearsItem { + + public CompatShearsItem(CompatibleItemSettings settings) { + super(settings); + } + + public CompatShearsItem(ItemSettingsBuilder builder, CompatIdentifier id) { + this(builder.build(id)); + } + + public CompatShearsItem(ItemSettingsBuilder builder) { + this(builder.build()); + } + + public float getMiningSpeedMultiplier(MiningSpeedMultiplierArgs args) { + return super.overrideGetMiningSpeedMultiplier(args.stack.toMinecraft(), args.state.toMinecraft()); + } + + @Override + @Deprecated + public float overrideGetMiningSpeedMultiplier(ItemStack stack, BlockState state) { + return getMiningSpeedMultiplier( + new MiningSpeedMultiplierArgs(net.pitan76.mcpitanlib.midohra.item.ItemStack.of(stack), + net.pitan76.mcpitanlib.midohra.block.BlockState.of(state))); + } + + public boolean isSuitableFor(SuitableForArgs args) { + return super.overrideIsSuitableFor(args.state.toMinecraft()); + } + + @Override + @Deprecated + public boolean overrideIsSuitableFor(BlockState state) { + return isSuitableFor(new SuitableForArgs(net.pitan76.mcpitanlib.midohra.block.BlockState.of(state))); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/item/v3/tool/CompatShovelItem.java b/common/src/main/java/net/pitan76/mcpitanlib/api/item/v3/tool/CompatShovelItem.java new file mode 100644 index 000000000..522c8a87f --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/v3/tool/CompatShovelItem.java @@ -0,0 +1,48 @@ +package net.pitan76.mcpitanlib.api.item.v3.tool; + +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.state.BlockState; +import net.pitan76.mcpitanlib.api.item.args.tool.MiningSpeedMultiplierArgs; +import net.pitan76.mcpitanlib.api.item.args.tool.SuitableForArgs; +import net.pitan76.mcpitanlib.api.item.tool.CompatibleShovelItem; +import net.pitan76.mcpitanlib.api.item.tool.CompatibleToolMaterial; +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 CompatShovelItem extends CompatibleShovelItem { + + public CompatShovelItem(CompatibleToolMaterial material, float attackDamage, float attackSpeed, CompatibleItemSettings settings) { + super(material, attackDamage, attackSpeed, settings); + } + + public CompatShovelItem(CompatibleToolMaterial material, float attackDamage, float attackSpeed, ItemSettingsBuilder builder, CompatIdentifier id) { + this(material, attackDamage, attackSpeed, builder.build(id)); + } + + public CompatShovelItem(CompatibleToolMaterial material, float attackDamage, float attackSpeed, ItemSettingsBuilder builder) { + this(material, attackDamage, attackSpeed, builder.build()); + } + + public float getMiningSpeedMultiplier(MiningSpeedMultiplierArgs args) { + return super.overrideGetMiningSpeedMultiplier(args.stack.toMinecraft(), args.state.toMinecraft()); + } + + @Override + @Deprecated + public float overrideGetMiningSpeedMultiplier(ItemStack stack, BlockState state) { + return getMiningSpeedMultiplier( + new MiningSpeedMultiplierArgs(net.pitan76.mcpitanlib.midohra.item.ItemStack.of(stack), + net.pitan76.mcpitanlib.midohra.block.BlockState.of(state))); + } + + public boolean isSuitableFor(SuitableForArgs args) { + return super.overrideIsSuitableFor(args.state.toMinecraft()); + } + + @Override + @Deprecated + public boolean overrideIsSuitableFor(BlockState state) { + return isSuitableFor(new SuitableForArgs(net.pitan76.mcpitanlib.midohra.block.BlockState.of(state))); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/item/v3/tool/CompatSwordItem.java b/common/src/main/java/net/pitan76/mcpitanlib/api/item/v3/tool/CompatSwordItem.java new file mode 100644 index 000000000..0a52e8121 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/v3/tool/CompatSwordItem.java @@ -0,0 +1,48 @@ +package net.pitan76.mcpitanlib.api.item.v3.tool; + +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.state.BlockState; +import net.pitan76.mcpitanlib.api.item.args.tool.MiningSpeedMultiplierArgs; +import net.pitan76.mcpitanlib.api.item.args.tool.SuitableForArgs; +import net.pitan76.mcpitanlib.api.item.tool.CompatibleSwordItem; +import net.pitan76.mcpitanlib.api.item.tool.CompatibleToolMaterial; +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 CompatSwordItem extends CompatibleSwordItem { + + public CompatSwordItem(CompatibleToolMaterial material, int attackDamage, float attackSpeed, CompatibleItemSettings settings) { + super(material, attackDamage, attackSpeed, settings); + } + + public CompatSwordItem(CompatibleToolMaterial material, int attackDamage, float attackSpeed, ItemSettingsBuilder builder, CompatIdentifier id) { + this(material, attackDamage, attackSpeed, builder.build(id)); + } + + public CompatSwordItem(CompatibleToolMaterial material, int attackDamage, float attackSpeed, ItemSettingsBuilder builder) { + this(material, attackDamage, attackSpeed, builder.build()); + } + + public float getMiningSpeedMultiplier(MiningSpeedMultiplierArgs args) { + return super.overrideGetMiningSpeedMultiplier(args.stack.toMinecraft(), args.state.toMinecraft()); + } + + @Override + @Deprecated + public float overrideGetMiningSpeedMultiplier(ItemStack stack, BlockState state) { + return getMiningSpeedMultiplier( + new MiningSpeedMultiplierArgs(net.pitan76.mcpitanlib.midohra.item.ItemStack.of(stack), + net.pitan76.mcpitanlib.midohra.block.BlockState.of(state))); + } + + public boolean isSuitableFor(SuitableForArgs args) { + return super.overrideIsSuitableFor(args.state.toMinecraft()); + } + + @Override + @Deprecated + public boolean overrideIsSuitableFor(BlockState state) { + return isSuitableFor(new SuitableForArgs(net.pitan76.mcpitanlib.midohra.block.BlockState.of(state))); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/item/v3/tool/CompatToolItem.java b/common/src/main/java/net/pitan76/mcpitanlib/api/item/v3/tool/CompatToolItem.java new file mode 100644 index 000000000..58174dc9e --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/item/v3/tool/CompatToolItem.java @@ -0,0 +1,48 @@ +package net.pitan76.mcpitanlib.api.item.v3.tool; + +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.state.BlockState; +import net.pitan76.mcpitanlib.api.item.args.tool.MiningSpeedMultiplierArgs; +import net.pitan76.mcpitanlib.api.item.args.tool.SuitableForArgs; +import net.pitan76.mcpitanlib.api.item.tool.CompatibleToolItem; +import net.pitan76.mcpitanlib.api.item.tool.CompatibleToolMaterial; +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 CompatToolItem extends CompatibleToolItem { + + public CompatToolItem(CompatibleToolMaterial material, CompatibleItemSettings settings) { + super(material, settings); + } + + public CompatToolItem(CompatibleToolMaterial material, ItemSettingsBuilder builder, CompatIdentifier id) { + super(material, builder.build(id)); + } + + public CompatToolItem(CompatibleToolMaterial material, ItemSettingsBuilder builder) { + super(material, builder.build()); + } + + public float getMiningSpeedMultiplier(MiningSpeedMultiplierArgs args) { + return super.overrideGetMiningSpeedMultiplier(args.stack.toMinecraft(), args.state.toMinecraft()); + } + + @Override + @Deprecated + public float overrideGetMiningSpeedMultiplier(ItemStack stack, BlockState state) { + return getMiningSpeedMultiplier( + new MiningSpeedMultiplierArgs(net.pitan76.mcpitanlib.midohra.item.ItemStack.of(stack), + net.pitan76.mcpitanlib.midohra.block.BlockState.of(state))); + } + + public boolean isSuitableFor(SuitableForArgs args) { + return super.overrideIsSuitableFor(args.state.toMinecraft()); + } + + @Override + @Deprecated + public boolean overrideIsSuitableFor(BlockState state) { + return isSuitableFor(new SuitableForArgs(net.pitan76.mcpitanlib.midohra.block.BlockState.of(state))); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/nbt/NbtTag.java b/common/src/main/java/net/pitan76/mcpitanlib/api/nbt/NbtTag.java new file mode 100644 index 000000000..eed193c6e --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/nbt/NbtTag.java @@ -0,0 +1,102 @@ +package net.pitan76.mcpitanlib.api.nbt; + +import net.minecraft.core.component.DataComponents; +import net.minecraft.world.item.component.CustomData; +import net.minecraft.world.item.ItemStack; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.TagType; + +import net.minecraft.nbt.Tag; +import net.minecraft.nbt.StreamTagVisitor; +import net.minecraft.nbt.TagVisitor; + +import java.io.DataOutput; +import java.io.IOException; + +@Deprecated +public class NbtTag { + public CompoundTag nbt; + + public NbtTag() { + super(); + } + + /** + * Create NbtTag instance + * @return NbtTag instance + */ + public static NbtTag create() { + return new NbtTag(); + } + + /** + * Cast to NbtTag + * @param nbt Nbt Object + * @return NbtTag + */ + public static NbtTag from(Object nbt) { + if (nbt instanceof CompoundTag) { + return (NbtTag) nbt; + } + return (NbtTag) nbt; + } + + /** + * Check item stack nbt + * @param stack Item stack + * @return boolean + */ + public static boolean hasNbt(ItemStack stack) { + return !stack.getComponents().isEmpty(); + } + + /** + * Get nbt from item stack + * @param stack Item stack + * @return NbtTag + */ + public static NbtTag getNbt(ItemStack stack) { + return from(stack.get(DataComponents.CUSTOM_DATA).copyTag()); + } + + /** + * Set nbt to item stack + * @param stack Item stack + * @param nbt NbtTag + */ + public static void setNbt(ItemStack stack, NbtTag nbt) { + stack.set(DataComponents.CUSTOM_DATA, CustomData.of(nbt.nbt)); + } + + public boolean contains(String key) { + return nbt.contains(key); + } + + public void write(DataOutput output) throws IOException { + nbt.write(output); + } + + public byte getType() { + return nbt.getId(); + } + + public TagType getNbtType() { + return nbt.getType(); + } + + public Tag copy() { + return nbt.copy(); + } + + public int getSizeInBytes() { + return nbt.sizeInBytes(); + } + + public void accept(TagVisitor visitor) { + nbt.accept(visitor); + } + + public StreamTagVisitor.ValueResult doAccept(StreamTagVisitor visitor) { + return nbt.accept(visitor); + } +} \ No newline at end of file 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..b1d6d464f --- /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.Tag; + +public class NbtTypeBytes { + public static final byte END = Tag.TAG_END; + public static final byte BYTE = Tag.TAG_BYTE; + public static final byte SHORT = Tag.TAG_SHORT; + public static final byte INT = Tag.TAG_INT; + public static final byte LONG = Tag.TAG_LONG; + public static final byte FLOAT = Tag.TAG_FLOAT; + public static final byte DOUBLE = Tag.TAG_DOUBLE; + public static final byte BYTE_ARRAY = Tag.TAG_BYTE_ARRAY; + public static final byte STRING = Tag.TAG_STRING; + public static final byte LIST = Tag.TAG_LIST; + public static final byte COMPOUND = Tag.TAG_COMPOUND; + public static final byte INT_ARRAY = Tag.TAG_INT_ARRAY; + public static final byte LONG_ARRAY = Tag.TAG_LONG_ARRAY; + public static final byte NUMBER = Tag.TAG_INT; +} 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..679f470fe --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/network/ClientNetworking.java @@ -0,0 +1,41 @@ +package net.pitan76.mcpitanlib.api.network; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.player.LocalPlayer; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.resources.Identifier; +import net.pitan76.mcpitanlib.core.mc261.ClientPlayNetworking; +import net.pitan76.mcpitanlib.core.network.BufPayload; + +import java.util.ArrayList; +import java.util.List; + +public class ClientNetworking { + public static void send(Identifier identifier, FriendlyByteBuf buf) { + registerC2SPayloadType(identifier); + + BufPayload payload = new BufPayload(buf, identifier); + ClientPlayNetworking.send(payload); + } + + public static void registerReceiver(Identifier identifier, ClientNetworkHandler handler) { + BufPayload.Type id = BufPayload.id(identifier); + registerC2SPayloadType(identifier); + + ClientPlayNetworking.registerGlobalReceiver(id, handler); + } + + @FunctionalInterface + public interface ClientNetworkHandler { + void receive(Minecraft client, LocalPlayer player, FriendlyByteBuf buf); + } + + private static final List registeredList = new ArrayList<>(); + + public static void registerC2SPayloadType(Identifier identifier) { + if (registeredList.contains(identifier)) return; + registeredList.add(identifier); + + ClientPlayNetworking.registerC2SPayloadType(identifier); + } +} 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..390cfb287 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/network/PacketByteUtil.java @@ -0,0 +1,287 @@ +package net.pitan76.mcpitanlib.api.network; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import net.minecraft.world.item.ItemStack; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.Tag; +import net.minecraft.nbt.NbtAccounter; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.Identifier; +import net.minecraft.core.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 FriendlyByteBuf create() { + return new FriendlyByteBuf(Unpooled.buffer()); + } + + + public static FriendlyByteBuf empty() { + return new FriendlyByteBuf(Unpooled.EMPTY_BUFFER); + } + + public static Map readMap(FriendlyByteBuf buf, Function keyParser, Function valueParser) { + return buf.readMap(keyParser::apply, valueParser::apply); + } + + public static void writeMap(FriendlyByteBuf buf, Map map) { + writeMap(buf, map, PacketByteUtil::writeVar, PacketByteUtil::writeVar); + } + + public static void writeMap(FriendlyByteBuf buf, Map map, BiConsumer keySerializer, BiConsumer valueSerializer) { + buf.writeMap(map, keySerializer::accept, valueSerializer::accept); + } + + public static void writeVar(FriendlyByteBuf buf, Object obj) { + if (obj instanceof String) { + String s = (String) obj; + buf.writeUtf(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 CompoundTag) { + CompoundTag nbt = (CompoundTag) obj; + buf.writeNbt(nbt); + } + if (obj instanceof ItemStack) { + ItemStack stack = (ItemStack) obj; + buf.writeJsonWithCodec(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 Component) { + Component text = (Component) obj; + buf.writeUtf(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 FriendlyByteBuf writeNbt(FriendlyByteBuf buf, CompoundTag nbt) { + return buf.writeNbt(nbt); + } + + public static CompoundTag readNbt(FriendlyByteBuf buf) { + return buf.readNbt(); + } + + public static FriendlyByteBuf writeItemStack(FriendlyByteBuf buf, ItemStack stack) { + buf.writeJsonWithCodec(ItemStack.CODEC, stack); + return buf; + } + + public static ItemStack readItemStack(FriendlyByteBuf buf) { + return buf.readLenientJsonWithCodec(ItemStack.CODEC); + } + + public static FriendlyByteBuf writeIdentifier(FriendlyByteBuf buf, Identifier identifier) { + return buf.writeIdentifier(identifier); + } + + public static Identifier readIdentifier(FriendlyByteBuf buf) { + return buf.readIdentifier(); + } + + public static FriendlyByteBuf writeText(FriendlyByteBuf buf, Component text) { + return buf.writeUtf(text.getString()); + } + + public static Component readText(FriendlyByteBuf buf) { + return TextUtil.literal(buf.readUtf()); + } + + public static FriendlyByteBuf writeBlockPos(FriendlyByteBuf buf, BlockPos pos) { + return buf.writeBlockPos(pos); + } + + public static BlockPos readBlockPos(FriendlyByteBuf buf) { + return buf.readBlockPos(); + } + + public static FriendlyByteBuf writeUuid(FriendlyByteBuf buf, UUID uuid) { + return buf.writeUUID(uuid); + } + + public static UUID readUuid(FriendlyByteBuf buf) { + return buf.readUUID(); + } + + public static FriendlyByteBuf writeVarInt(FriendlyByteBuf buf, int i) { + return buf.writeVarInt(i); + } + + public static int readVarInt(FriendlyByteBuf buf) { + return buf.readVarInt(); + } + + public static FriendlyByteBuf writeVarLong(FriendlyByteBuf buf, long l) { + return buf.writeVarLong(l); + } + + public static long readVarLong(FriendlyByteBuf buf) { + return buf.readVarLong(); + } + + public static ByteBuf writeBoolean(FriendlyByteBuf buf, boolean b) { + return buf.writeBoolean(b); + } + + public static boolean readBoolean(FriendlyByteBuf buf) { + return buf.readBoolean(); + } + + public static ByteBuf writeByte(FriendlyByteBuf buf, byte b) { + return buf.writeByte(b); + } + + public static byte readByte(FriendlyByteBuf buf) { + return buf.readByte(); + } + + public static ByteBuf writeShort(FriendlyByteBuf buf, short s) { + return buf.writeShort(s); + } + + public static short readShort(FriendlyByteBuf buf) { + return buf.readShort(); + } + + public static ByteBuf writeInt(FriendlyByteBuf buf, int i) { + return buf.writeInt(i); + } + + public static int readInt(FriendlyByteBuf buf) { + return buf.readInt(); + } + + public static ByteBuf writeLong(FriendlyByteBuf buf, long l) { + return buf.writeLong(l); + } + + public static long readLong(FriendlyByteBuf buf) { + return buf.readLong(); + } + + public static ByteBuf writeFloat(FriendlyByteBuf buf, float f) { + return buf.writeFloat(f); + } + + public static float readFloat(FriendlyByteBuf buf) { + return buf.readFloat(); + } + + public static ByteBuf writeDouble(FriendlyByteBuf buf, double d) { + return buf.writeDouble(d); + } + + public static double readDouble(FriendlyByteBuf buf) { + return buf.readDouble(); + } + + public static FriendlyByteBuf writeByteArray(FriendlyByteBuf buf, byte[] bytes) { + return buf.writeByteArray(bytes); + } + + public static byte[] readByteArray(FriendlyByteBuf buf) { + return buf.readByteArray(); + } + + public static FriendlyByteBuf writeString(FriendlyByteBuf buf, String s) { + return buf.writeUtf(s); + } + + public static String readString(FriendlyByteBuf buf) { + return buf.readUtf(); + } + + public static FriendlyByteBuf writeIntArray(FriendlyByteBuf buf, int[] ints) { + return buf.writeVarIntArray(ints); + } + + public static int[] readIntArray(FriendlyByteBuf buf) { + return buf.readVarIntArray(); + } + + public static FriendlyByteBuf writeLongArray(FriendlyByteBuf buf, long[] longs) { + return buf.writeLongArray(longs); + } + + public static long[] readLongArray(FriendlyByteBuf buf) { + return buf.readLongArray(); + } + + public static Tag readUnlimitedNbt(FriendlyByteBuf buf) { + return buf.readNbt(NbtAccounter.unlimitedHeap()); + } + + public static net.pitan76.mcpitanlib.midohra.nbt.NbtCompound readNbtM(FriendlyByteBuf buf) { + return net.pitan76.mcpitanlib.midohra.nbt.NbtCompound.of(readNbt(buf)); + } + + public static FriendlyByteBuf writeNbt(FriendlyByteBuf buf, net.pitan76.mcpitanlib.midohra.nbt.NbtCompound nbt) { + return writeNbt(buf, nbt.toMinecraft()); + } + + public static net.pitan76.mcpitanlib.midohra.util.math.BlockPos readBlockPosM(FriendlyByteBuf buf) { + return net.pitan76.mcpitanlib.midohra.util.math.BlockPos.of(readBlockPos(buf)); + } + + public static FriendlyByteBuf writeBlockPos(FriendlyByteBuf buf, net.pitan76.mcpitanlib.midohra.util.math.BlockPos pos) { + return writeBlockPos(buf, pos.toMinecraft()); + } + + public static boolean isReadable(FriendlyByteBuf buf) {; + return buf.isReadable(); + } + + public static boolean isWritable(FriendlyByteBuf buf) { + return buf.isWritable(); + } + + public static boolean isReadable(FriendlyByteBuf buf, int size) { + return buf.isReadable(size); + } +} + + 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..e2763152a --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/network/ServerNetworking.java @@ -0,0 +1,54 @@ +package net.pitan76.mcpitanlib.api.network; + +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.resources.Identifier; +import net.pitan76.mcpitanlib.core.mc261.ServerPlayNetworking; +import net.pitan76.mcpitanlib.core.network.BufPayload; + +import java.util.ArrayList; +import java.util.List; + +public class ServerNetworking { + public static void send(ServerPlayer player, Identifier identifier, FriendlyByteBuf buf) { + registerS2CPayloadType(identifier); + + BufPayload payload = new BufPayload(buf, identifier); + ServerPlayNetworking.send(player, payload); + } + + public static void send(Iterable players, Identifier identifier, FriendlyByteBuf buf) { + registerS2CPayloadType(identifier); + + BufPayload payload = new BufPayload(buf, identifier); + for (ServerPlayer player : players) { + ServerPlayNetworking.send(player, payload); + } + } + + public static void sendAll(MinecraftServer server, Identifier identifier, FriendlyByteBuf buf) { + send(server.getPlayerList().getPlayers(), identifier, buf); + } + + public static void registerReceiver(Identifier identifier, ServerNetworkHandler handler) { + registerS2CPayloadType(identifier); + BufPayload.Type id = BufPayload.id(identifier); + + ServerPlayNetworking.registerGlobalReceiver(id, (server, player, buf) -> { + handler.receive(server, player, buf); + buf.release(); + }); + } + + private static final List registeredList = new ArrayList<>(); + + public static void registerS2CPayloadType(Identifier identifier) { + ServerPlayNetworking.registerS2CPayloadType(identifier); + } + + @FunctionalInterface + public interface ServerNetworkHandler { + void receive(MinecraftServer server, ServerPlayer player, FriendlyByteBuf 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..0ba88114a --- /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.FriendlyByteBuf; +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, FriendlyByteBuf 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..4a34df57c --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/network/v2/ServerNetworking.java @@ -0,0 +1,114 @@ +package net.pitan76.mcpitanlib.api.network.v2; + +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.level.Level; +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 net.pitan76.mcpitanlib.midohra.server.MCServer; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import java.util.function.Consumer; + +public class ServerNetworking { + public static void send(ServerPlayer serverPlayerEntity, CompatIdentifier id, FriendlyByteBuf buf) { + net.pitan76.mcpitanlib.api.network.ServerNetworking.send(serverPlayerEntity, id.toMinecraft(), buf); + } + + public static void sendByServerPlayerEntity(Iterable players, CompatIdentifier id, FriendlyByteBuf buf) { + net.pitan76.mcpitanlib.api.network.ServerNetworking.send(players, id.toMinecraft(), buf); + } + + public static void send(Player player, CompatIdentifier id, FriendlyByteBuf buf) { + Optional optional = player.getServerPlayer(); + if (optional.isEmpty()) return; + + send(optional.get(), id, buf); + } + + public static void send(Iterable players, CompatIdentifier id, FriendlyByteBuf 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, FriendlyByteBuf buf) { + net.pitan76.mcpitanlib.api.network.ServerNetworking.sendAll(server, id.toMinecraft(), buf); + } + + public static void sendAll(Level world, CompatIdentifier id, FriendlyByteBuf 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(ServerPlayer 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(Level world, CompatIdentifier id, CompatPacketByteBuf buf) { + sendAll(world.getServer(), id, buf.getRaw()); + } + + public static void send(ServerPlayer 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(Level world, CompatIdentifier id) { + sendAll(world.getServer(), id, PacketByteUtil.create()); + } + + public static void sendAll(MCServer server, CompatIdentifier id, CompatPacketByteBuf buf) { + sendAll(server.getRaw(), id, buf); + } + + public static void sendAll(MCServer server, CompatIdentifier id) { + sendAll(server.getRaw(), id); + } + + public static void sendAll(net.pitan76.mcpitanlib.midohra.world.World world, CompatIdentifier id, CompatPacketByteBuf buf) { + sendAll(world.getRaw(), id, buf); + } + + public static void sendAll(net.pitan76.mcpitanlib.midohra.world.World world, CompatIdentifier id) { + sendAll(world.getRaw(), id); + } +} 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..7f83fcb14 --- /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.Minecraft; +import net.minecraft.client.player.LocalPlayer; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.world.level.Level; +import net.pitan76.mcpitanlib.api.entity.Player; +import net.pitan76.mcpitanlib.midohra.network.CompatPacketByteBuf; + +public class ClientReceiveEvent { + public Minecraft client; + public LocalPlayer clientPlayer; + public Player player; + public FriendlyByteBuf buf; + + public ClientReceiveEvent(Minecraft client, LocalPlayer player, FriendlyByteBuf buf) { + this.client = client; + this.clientPlayer = player; + this.player = new Player(player); + this.buf = buf; + } + + public LocalPlayer getClientPlayer() { + return clientPlayer; + } + + public Player getPlayer() { + return player; + } + + public Minecraft getClient() { + return client; + } + + public FriendlyByteBuf getBuf() { + return buf; + } + + public CompatPacketByteBuf getCompatBuf() { + return CompatPacketByteBuf.of(buf); + } + + public Level 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..dee978341 --- /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.FriendlyByteBuf; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.level.Level; +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 ServerPlayer serverPlayer; + public Player player; + public FriendlyByteBuf buf; + + public ServerReceiveEvent(MinecraftServer server, ServerPlayer player, FriendlyByteBuf buf) { + this.server = server; + this.serverPlayer = player; + this.player = new Player(player); + this.buf = buf; + } + + public ServerPlayer getServerPlayer() { + return serverPlayer; + } + + public Player getPlayer() { + return player; + } + + public MinecraftServer getServer() { + return server; + } + + public FriendlyByteBuf getBuf() { + return buf; + } + + public Level 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..8e356bb06 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/recipe/CompatRecipeType.java @@ -0,0 +1,65 @@ +package net.pitan76.mcpitanlib.api.recipe; + +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.resources.Identifier; +import net.minecraft.world.item.crafting.BlastingRecipe; +import net.minecraft.world.item.crafting.CampfireCookingRecipe; +import net.minecraft.world.item.crafting.CraftingRecipe; +import net.minecraft.world.item.crafting.Recipe; +import net.minecraft.world.item.crafting.RecipeType; +import net.minecraft.world.item.crafting.SmeltingRecipe; +import net.minecraft.world.item.crafting.SmithingRecipe; +import net.minecraft.world.item.crafting.SmokingRecipe; +import net.minecraft.world.item.crafting.StonecutterRecipe; +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 = BuiltInRegistries.RECIPE_TYPE.getKey(type); + if (id == null) return CompatIdentifier.empty(); + + return CompatIdentifier.fromMinecraft(id); + } + + public static CompatRecipeType of(CompatIdentifier id) { + RecipeType type = BuiltInRegistries.RECIPE_TYPE.getValue(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..d4beab35a --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/recipe/CompatibleRecipeEntry.java @@ -0,0 +1,80 @@ +package net.pitan76.mcpitanlib.api.recipe; + +import net.minecraft.resources.ResourceKey; +import net.minecraft.core.registries.Registries; +import net.minecraft.resources.Identifier; +import net.minecraft.world.item.crafting.Recipe; +import net.minecraft.world.item.crafting.RecipeHolder; +import net.minecraft.world.item.crafting.RecipeSerializer; +import net.minecraft.world.item.crafting.RecipeType; +import net.minecraft.world.item.crafting.ShapelessRecipe; +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 RecipeHolder entry; + + public String group = ""; + public RecipeUtil.CompatibilityCraftingRecipeCategory category = null; + + @Deprecated + public CompatibleRecipeEntry(RecipeHolder entry) { + this.entry = entry; + } + + public CompatibleRecipeEntry(Identifier id, String group, RecipeUtil.CompatibilityCraftingRecipeCategory category, ShapelessRecipe shapelessRecipe) { + this.entry = new RecipeHolder<>(ResourceKey.create(Registries.RECIPE, 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 RecipeHolder 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().identifier(); + } + + 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..59eb2a97d --- /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.world.item.crafting.Recipe; +import net.minecraft.world.item.crafting.RecipeInput; +import net.minecraft.world.level.Level; +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, Level 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..41beec474 --- /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.world.item.ItemStack; +import net.minecraft.world.item.crafting.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.getItem(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.size(); + } + + 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..441436cdc --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/recipe/v2/CompatRecipeEntry.java @@ -0,0 +1,79 @@ +package net.pitan76.mcpitanlib.api.recipe.v2; + +import net.minecraft.resources.ResourceKey; +import net.minecraft.core.registries.Registries; +import net.minecraft.resources.Identifier; +import net.minecraft.world.item.crafting.Recipe; +import net.minecraft.world.item.crafting.RecipeHolder; +import net.minecraft.world.item.crafting.RecipeSerializer; +import net.minecraft.world.item.crafting.RecipeType; +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 RecipeHolder entry; + + public String group = ""; + public RecipeUtil.CompatibilityCraftingRecipeCategory category = null; + + @Deprecated + public CompatRecipeEntry(RecipeHolder entry) { + this.entry = entry; + } + + public CompatRecipeEntry(Identifier id, String group, RecipeUtil.CompatibilityCraftingRecipeCategory category, T recipe) { + this.entry = new RecipeHolder<>(ResourceKey.create(Registries.RECIPE, 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 RecipeHolder getRecipeEntry() { + return entry; + } + + public T getRecipe() { + return entry.value(); + } + + public Identifier getId() { + return entry.id().identifier(); + } + + 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..332c62b73 --- /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.world.item.crafting.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..0dbf26188 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/recipe/v3/CompatRecipe.java @@ -0,0 +1,87 @@ +package net.pitan76.mcpitanlib.api.recipe.v3; + +import net.minecraft.world.item.crafting.Recipe; +import net.minecraft.world.item.crafting.RecipeType; +import net.minecraft.resources.ResourceKey; +import net.minecraft.core.registries.Registries; +import net.minecraft.resources.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.world.item.crafting.RecipeHolder entry) { + this(entry.value(), entry.id().identifier()); + } + + @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.world.item.crafting.RecipeHolder>(ResourceKey.create(Registries.RECIPE, 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.world.item.crafting.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.world.item.crafting.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..c57720e2b --- /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 net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.core.component.DataComponentType; +import net.minecraft.world.item.enchantment.Enchantment; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.effect.MobEffect; +import net.minecraft.world.level.material.Fluid; +import net.minecraft.world.item.Item; +import net.minecraft.world.level.ItemLike; +import net.minecraft.world.item.CreativeModeTab; +import net.minecraft.core.particles.ParticleType; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.sounds.SoundEvent; +import net.minecraft.resources.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.registry.result.RegistrySupplier; +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.createVariableRangeEvent(id)); + } + + public RegistryResult registerSoundEvent(Identifier id, float distanceToTravel) { + return registerSoundEvent(id, () -> SoundEvent.createFixedRangeEvent(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, ItemLike... 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..2866c6dcf --- /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.CompoundTag; +import net.minecraft.data.registries.VanillaRegistries; +import net.minecraft.core.HolderLookup; +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 HolderLookup.Provider registryLookup; + + @Deprecated + public CompatRegistryLookup(HolderLookup.Provider registryLookup) { + this.registryLookup = registryLookup; + } + + public CompatRegistryLookup() { + this.registryLookup = VanillaRegistries.createLookup(); + } + + @Deprecated + public HolderLookup.Provider getRegistryLookup() { + if (registryLookup == null) + return VanillaRegistries.createLookup(); + + return registryLookup; + } + + public NbtRWArgs getNbtRWArgs(CompoundTag nbt) { + return new NbtRWArgs(nbt, registryLookup); + } + + public WriteNbtArgs createWriteNbtArgs(CompoundTag nbt) { + return new WriteNbtArgs(nbt, registryLookup); + } + + public ReadNbtArgs createReadNbtArgs(CompoundTag 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..3e05afcd8 --- /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.world.level.ItemLike; + +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()); + } + + 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..f832c691c --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/registry/WorldGenRegistry.java @@ -0,0 +1,104 @@ +package net.pitan76.mcpitanlib.api.registry; + +import net.minecraft.resources.Identifier; +import net.minecraft.world.level.levelgen.GenerationStep; +import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; +import net.minecraft.world.level.levelgen.placement.PlacedFeature; +import net.pitan76.mcpitanlib.api.registry.result.RegistryResult; +import net.pitan76.mcpitanlib.api.registry.result.RegistrySupplier; + +import java.util.function.Supplier; + +// TODO: Add support for biome modifiers and other world gen related things +public class WorldGenRegistry { + protected String MOD_ID; + + @Deprecated + public WorldGenRegistry(String MOD_ID) { + this.MOD_ID = MOD_ID; + } + + /** + * 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); +// ResourceKey> key = ResourceKey.create(Registries.CONFIGURED_FEATURE, id); +// return new RegistryResult<>(Registry.register(BuiltInRegistries.FEATURE, key, supplier.get())); + return null; + } + + /** + * 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); +// ResourceKey PlacedFeatureKey = ResourceKey.create(Registries.PLACED_FEATURE, id); +// return new RegistryResult<>(Registry.register(BuiltInRegistries.FEATURE, PlacedFeatureKey, supplier.get())); + return null; + } + + /** + * Replace the properties of a biome + * @param decoration The decoration step + * @param feature The feature to replace + */ + public static void replaceProperties(GenerationStep.Decoration decoration, RegistrySupplier feature) { +// BiomeModifications.replaceProperties((ctx, mutable) -> mutable.getGenerationProperties().addFeature(decoration, feature)); + } + + public static void replaceProperties(GenerationStep.Decoration 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.Decoration decoration, PlacedFeature feature) { +// BiomeModifications.replaceProperties((ctx, mutable) -> mutable.getGenerationProperties().addFeature(decoration, Holder.direct(feature))); + } + + /** + * Add a feature to the biome properties + * @param decoration The decoration step + * @param feature The feature to add + */ + public static void addProperties(GenerationStep.Decoration decoration, RegistrySupplier feature) { +// BiomeModifications.addProperties((ctx, mutable) -> mutable.getGenerationProperties().addFeature(decoration, feature)); + } + + public static void addProperties(GenerationStep.Decoration 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.Decoration decoration, PlacedFeature feature) { +// BiomeModifications.addProperties((ctx, mutable) -> mutable.getGenerationProperties().addFeature(decoration, Holder.direct(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..ed04a4f24 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/registry/result/RegistryResult.java @@ -0,0 +1,30 @@ +package net.pitan76.mcpitanlib.api.registry.result; + +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/RegistrySupplier.java b/common/src/main/java/net/pitan76/mcpitanlib/api/registry/result/RegistrySupplier.java new file mode 100644 index 000000000..a427d1326 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/registry/result/RegistrySupplier.java @@ -0,0 +1,30 @@ +package net.pitan76.mcpitanlib.api.registry.result; + +public class RegistrySupplier { + public T value; + public boolean isRegistered; + + public RegistrySupplier() { + this.value = null; + this.isRegistered = false; + } + + public RegistrySupplier(T value) { + this.value = value; + this.isRegistered = true; + } + + public void set(T value) { + this.value = value; + this.isRegistered = true; + } + + public T get() { + if (!isRegistered) throw new IllegalStateException("The registry is not registered yet"); + return value; + } + + public T getOrNull() { + return isRegistered ? value : null; + } +} \ No newline at end of file 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..c9ac80cb7 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/registry/result/SupplierResult.java @@ -0,0 +1,51 @@ +package net.pitan76.mcpitanlib.api.registry.result; + +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..40560cbd4 --- /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.world.level.block.Block; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.item.enchantment.Enchantment; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.effect.MobEffect; +import net.minecraft.world.level.material.Fluid; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.CreativeModeTab; +import net.minecraft.core.particles.ParticleType; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.sounds.SoundEvent; +import net.minecraft.resources.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 () -> (MenuType) 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(cr1.getMcplr1_21().registryChunkTicketType(id, 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..e42c5d580 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/simple/block/SimpleGuiBlock.java @@ -0,0 +1,29 @@ +package net.pitan76.mcpitanlib.api.simple.block; + +import net.minecraft.network.chat.Component; +import net.minecraft.world.level.block.state.BlockBehaviour.Properties; +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(Properties settings) { + super(settings); + } + + @Override + public CompatActionResult onRightClick(BlockUseEvent e) { + if (e.isClient()) + e.player.openGuiScreen(this); + + return e.success(); + } + + @Override + public Component 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..ed8574cd5 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/simple/item/SimpleGuiItem.java @@ -0,0 +1,62 @@ +package net.pitan76.mcpitanlib.api.simple.item; + +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.network.chat.Component; +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.ItemStackUtil; +import net.pitan76.mcpitanlib.api.util.StackActionResult; + +public class SimpleGuiItem extends CompatItem implements SimpleScreenHandlerFactory { + + public ScreenHandlerFactory factory; + public Component name; + + public SimpleGuiItem(CompatibleItemSettings settings, ScreenHandlerFactory factory, Component 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 Component getDisplayName(DisplayNameArgs args) { + if (name == null) + return getName(ItemStackUtil.getDefaultStack(this)); + + return name; + } + + @Override + public AbstractContainerMenu createMenu(CreateMenuEvent e) { + if (factory == null) + return null; + + return factory.create(e); + } + + @FunctionalInterface + public interface ScreenHandlerFactory { + AbstractContainerMenu 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..fd0241215 --- /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.world.level.block.SoundType; +import net.minecraft.sounds.SoundEvent; + +public class CompatBlockSoundGroup { + public static final CompatBlockSoundGroup INTENTIONALLY_EMPTY = of(SoundType.EMPTY); + public static final CompatBlockSoundGroup WOOD = of(SoundType.WOOD); + public static final CompatBlockSoundGroup GRAVEL = of(SoundType.GRAVEL); + public static final CompatBlockSoundGroup GRASS = of(SoundType.GRASS); + public static final CompatBlockSoundGroup LILY_PAD = of(SoundType.LILY_PAD); + public static final CompatBlockSoundGroup STONE = of(SoundType.STONE); + public static final CompatBlockSoundGroup METAL = of(SoundType.METAL); + public static final CompatBlockSoundGroup GLASS = of(SoundType.GLASS); + public static final CompatBlockSoundGroup WOOL = of(SoundType.WOOL); + public static final CompatBlockSoundGroup SAND = of(SoundType.SAND); + public static final CompatBlockSoundGroup SNOW = of(SoundType.SNOW); + public static final CompatBlockSoundGroup POWDER_SNOW = of(SoundType.POWDER_SNOW); + public static final CompatBlockSoundGroup LADDER = of(SoundType.LADDER); + public static final CompatBlockSoundGroup ANVIL = of(SoundType.ANVIL); + public static final CompatBlockSoundGroup SLIME = of(SoundType.SLIME_BLOCK); + public static final CompatBlockSoundGroup HONEY = of(SoundType.HONEY_BLOCK); + public static final CompatBlockSoundGroup WET_GRASS = of(SoundType.WET_GRASS); + public static final CompatBlockSoundGroup CORAL = of(SoundType.CORAL_BLOCK); + public static final CompatBlockSoundGroup BAMBOO = of(SoundType.BAMBOO); + public static final CompatBlockSoundGroup BAMBOO_SAPLING = of(SoundType.BAMBOO_SAPLING); + public static final CompatBlockSoundGroup SCAFFOLDING = of(SoundType.SCAFFOLDING); + public static final CompatBlockSoundGroup SWEET_BERRY_BUSH = of(SoundType.SWEET_BERRY_BUSH); + public static final CompatBlockSoundGroup CROP = of(SoundType.CROP); + public static final CompatBlockSoundGroup STEM = of(SoundType.HARD_CROP); + public static final CompatBlockSoundGroup VINE = of(SoundType.VINE); + public static final CompatBlockSoundGroup NETHER_WART = of(SoundType.NETHER_WART); + public static final CompatBlockSoundGroup LANTERN = of(SoundType.LANTERN); + public static final CompatBlockSoundGroup NETHER_STEM = of(SoundType.STEM); + public static final CompatBlockSoundGroup NYLIUM = of(SoundType.NYLIUM); + public static final CompatBlockSoundGroup FUNGUS = of(SoundType.FUNGUS); + public static final CompatBlockSoundGroup ROOTS = of(SoundType.ROOTS); + public static final CompatBlockSoundGroup SHROOMLIGHT = of(SoundType.SHROOMLIGHT); + public static final CompatBlockSoundGroup WEEPING_VINES = of(SoundType.WEEPING_VINES); + public static final CompatBlockSoundGroup WEEPING_VINES_LOW_PITCH = of(SoundType.TWISTING_VINES); + public static final CompatBlockSoundGroup SOUL_SAND = of(SoundType.SOUL_SAND); + public static final CompatBlockSoundGroup SOUL_SOIL = of(SoundType.SOUL_SOIL); + public static final CompatBlockSoundGroup BASALT = of(SoundType.BASALT); + public static final CompatBlockSoundGroup WART_BLOCK = of(SoundType.WART_BLOCK); + public static final CompatBlockSoundGroup NETHERRACK = of(SoundType.NETHERRACK); + public static final CompatBlockSoundGroup NETHER_BRICKS = of(SoundType.NETHER_BRICKS); + public static final CompatBlockSoundGroup NETHER_SPROUTS = of(SoundType.NETHER_SPROUTS); + public static final CompatBlockSoundGroup NETHER_ORE = of(SoundType.NETHER_ORE); + public static final CompatBlockSoundGroup BONE = of(SoundType.BONE_BLOCK); + public static final CompatBlockSoundGroup NETHERITE = of(SoundType.NETHERITE_BLOCK); + public static final CompatBlockSoundGroup ANCIENT_DEBRIS = of(SoundType.ANCIENT_DEBRIS); + public static final CompatBlockSoundGroup LODESTONE = of(SoundType.LODESTONE); + public static final CompatBlockSoundGroup CHAIN = of(SoundType.CHAIN); + public static final CompatBlockSoundGroup NETHER_GOLD_ORE = of(SoundType.NETHER_GOLD_ORE); + public static final CompatBlockSoundGroup GILDED_BLACKSTONE = of(SoundType.GILDED_BLACKSTONE); + public static final CompatBlockSoundGroup CANDLE = of(SoundType.CANDLE); + public static final CompatBlockSoundGroup AMETHYST_BLOCK = of(SoundType.AMETHYST); + public static final CompatBlockSoundGroup AMETHYST_CLUSTER = of(SoundType.AMETHYST_CLUSTER); + public static final CompatBlockSoundGroup SMALL_AMETHYST_BUD = of(SoundType.SMALL_AMETHYST_BUD); + public static final CompatBlockSoundGroup MEDIUM_AMETHYST_BUD = of(SoundType.MEDIUM_AMETHYST_BUD); + public static final CompatBlockSoundGroup LARGE_AMETHYST_BUD = of(SoundType.LARGE_AMETHYST_BUD); + public static final CompatBlockSoundGroup TUFF = of(SoundType.TUFF); + public static final CompatBlockSoundGroup TUFF_BRICKS = of(SoundType.TUFF_BRICKS); + public static final CompatBlockSoundGroup POLISHED_TUFF = of(SoundType.POLISHED_TUFF); + public static final CompatBlockSoundGroup CALCITE = of(SoundType.CALCITE); + public static final CompatBlockSoundGroup DRIPSTONE_BLOCK = of(SoundType.DRIPSTONE_BLOCK); + public static final CompatBlockSoundGroup POINTED_DRIPSTONE = of(SoundType.POINTED_DRIPSTONE); + public static final CompatBlockSoundGroup COPPER = of(SoundType.COPPER); + public static final CompatBlockSoundGroup COPPER_BULB = of(SoundType.COPPER_BULB); + public static final CompatBlockSoundGroup COPPER_GRATE = of(SoundType.COPPER_GRATE); + public static final CompatBlockSoundGroup CAVE_VINES = of(SoundType.CAVE_VINES); + public static final CompatBlockSoundGroup SPORE_BLOSSOM = of(SoundType.SPORE_BLOSSOM); + public static final CompatBlockSoundGroup AZALEA = of(SoundType.AZALEA); + public static final CompatBlockSoundGroup FLOWERING_AZALEA = of(SoundType.FLOWERING_AZALEA); + public static final CompatBlockSoundGroup MOSS_CARPET = of(SoundType.MOSS_CARPET); + public static final CompatBlockSoundGroup PINK_PETALS = of(SoundType.CHERRY_LEAVES); + public static final CompatBlockSoundGroup MOSS_BLOCK = of(SoundType.MOSS); + public static final CompatBlockSoundGroup BIG_DRIPLEAF = of(SoundType.BIG_DRIPLEAF); + public static final CompatBlockSoundGroup SMALL_DRIPLEAF = of(SoundType.SMALL_DRIPLEAF); + public static final CompatBlockSoundGroup ROOTED_DIRT = of(SoundType.ROOTED_DIRT); + public static final CompatBlockSoundGroup HANGING_ROOTS = of(SoundType.HANGING_ROOTS); + public static final CompatBlockSoundGroup AZALEA_LEAVES = of(SoundType.AZALEA_LEAVES); + public static final CompatBlockSoundGroup SCULK_SENSOR = of(SoundType.SCULK_SENSOR); + public static final CompatBlockSoundGroup SCULK_CATALYST = of(SoundType.SCULK_CATALYST); + public static final CompatBlockSoundGroup SCULK = of(SoundType.SCULK); + public static final CompatBlockSoundGroup SCULK_VEIN = of(SoundType.SCULK_VEIN); + public static final CompatBlockSoundGroup SCULK_SHRIEKER = of(SoundType.SCULK_SHRIEKER); + public static final CompatBlockSoundGroup GLOW_LICHEN = of(SoundType.GLOW_LICHEN); + public static final CompatBlockSoundGroup DEEPSLATE = of(SoundType.DEEPSLATE); + public static final CompatBlockSoundGroup DEEPSLATE_BRICKS = of(SoundType.DEEPSLATE_BRICKS); + public static final CompatBlockSoundGroup DEEPSLATE_TILES = of(SoundType.DEEPSLATE_TILES); + public static final CompatBlockSoundGroup POLISHED_DEEPSLATE = of(SoundType.POLISHED_DEEPSLATE); + public static final CompatBlockSoundGroup FROGLIGHT = of(SoundType.FROGLIGHT); + public static final CompatBlockSoundGroup FROGSPAWN = of(SoundType.FROGSPAWN); + public static final CompatBlockSoundGroup MANGROVE_ROOTS = of(SoundType.MANGROVE_ROOTS); + public static final CompatBlockSoundGroup MUDDY_MANGROVE_ROOTS = of(SoundType.MUDDY_MANGROVE_ROOTS); + public static final CompatBlockSoundGroup MUD = of(SoundType.MUD); + public static final CompatBlockSoundGroup MUD_BRICKS = of(SoundType.MUD_BRICKS); + public static final CompatBlockSoundGroup PACKED_MUD = of(SoundType.PACKED_MUD); + public static final CompatBlockSoundGroup HANGING_SIGN = of(SoundType.HANGING_SIGN); + public static final CompatBlockSoundGroup NETHER_WOOD_HANGING_SIGN = of(SoundType.NETHER_WOOD_HANGING_SIGN); + public static final CompatBlockSoundGroup BAMBOO_WOOD_HANGING_SIGN = of(SoundType.BAMBOO_WOOD_HANGING_SIGN); + public static final CompatBlockSoundGroup BAMBOO_WOOD = of(SoundType.BAMBOO_WOOD); + public static final CompatBlockSoundGroup NETHER_WOOD = of(SoundType.NETHER_WOOD); + public static final CompatBlockSoundGroup CHERRY_WOOD = of(SoundType.CHERRY_WOOD); + public static final CompatBlockSoundGroup CHERRY_SAPLING = of(SoundType.CHERRY_SAPLING); + public static final CompatBlockSoundGroup CHERRY_LEAVES = of(SoundType.CHERRY_LEAVES); + public static final CompatBlockSoundGroup CHERRY_WOOD_HANGING_SIGN = of(SoundType.CHERRY_WOOD_HANGING_SIGN); + public static final CompatBlockSoundGroup CHISELED_BOOKSHELF = of(SoundType.CHISELED_BOOKSHELF); + public static final CompatBlockSoundGroup SUSPICIOUS_SAND = of(SoundType.SUSPICIOUS_SAND); + public static final CompatBlockSoundGroup SUSPICIOUS_GRAVEL = of(SoundType.SUSPICIOUS_GRAVEL); + public static final CompatBlockSoundGroup DECORATED_POT = of(SoundType.DECORATED_POT); + public static final CompatBlockSoundGroup DECORATED_POT_SHATTER = of(SoundType.DECORATED_POT_CRACKED); + public static final CompatBlockSoundGroup TRIAL_SPAWNER = of(SoundType.TRIAL_SPAWNER); + public static final CompatBlockSoundGroup SPONGE = of(SoundType.SPONGE); + public static final CompatBlockSoundGroup WET_SPONGE = of(SoundType.WET_SPONGE); + public static final CompatBlockSoundGroup VAULT = of(SoundType.VAULT); + public static final CompatBlockSoundGroup HEAVY_CORE = of(SoundType.HEAVY_CORE); + public static final CompatBlockSoundGroup COBWEB = of(SoundType.COBWEB); + + public SoundType 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(SoundType 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 SoundType(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 SoundType get() { + if (blockSoundGroup == null) { + return new SoundType(volume, pitch, breakSound, stepSound, placeSound, hitSound, fallSound); + } + return blockSoundGroup; + } + + public static CompatBlockSoundGroup of(SoundType 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..ad9ece4ce --- /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.sounds.SoundSource; + +public class CompatSoundCategory { + + public static final CompatSoundCategory MASTER = of(SoundSource.MASTER); + public static final CompatSoundCategory MUSIC = of(SoundSource.MUSIC); + public static final CompatSoundCategory RECORDS = of(SoundSource.RECORDS); + public static final CompatSoundCategory WEATHER = of(SoundSource.WEATHER); + public static final CompatSoundCategory BLOCKS = of(SoundSource.BLOCKS); + public static final CompatSoundCategory HOSTILE = of(SoundSource.HOSTILE); + public static final CompatSoundCategory NEUTRAL = of(SoundSource.NEUTRAL); + public static final CompatSoundCategory PLAYERS = of(SoundSource.PLAYERS); + public static final CompatSoundCategory AMBIENT = of(SoundSource.AMBIENT); + public static final CompatSoundCategory VOICE = of(SoundSource.VOICE); + + public SoundSource soundCategory; + + public CompatSoundCategory(SoundSource soundCategory) { + this.soundCategory = soundCategory; + } + + public static CompatSoundCategory of(SoundSource soundCategory) { + return new CompatSoundCategory(soundCategory); + } + + public SoundSource 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..454f218aa --- /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.core.Holder; +import net.minecraft.sounds.SoundEvent; +import org.jetbrains.annotations.Nullable; + +public class CompatSoundEvent { + private SoundEvent soundEvent; + private Holder.Reference reference; + private Holder entry; + + public CompatSoundEvent(SoundEvent soundEvent) { + this.soundEvent = soundEvent; + } + + public CompatSoundEvent(Holder.Reference reference) { + this.reference = reference; + } + + public CompatSoundEvent(Holder 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 Holder.Reference getReference() { + return reference; + } + + @Nullable + @Deprecated + public Holder getEntry() { + if (entry == null) { + entry = Holder.direct(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..44615c9cc --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/sound/CompatSoundEvents.java @@ -0,0 +1,1629 @@ +package net.pitan76.mcpitanlib.api.sound; + +import com.google.common.collect.ImmutableList; +import net.minecraft.world.entity.animal.chicken.ChickenSoundVariants; +import net.minecraft.world.entity.animal.cow.CowSoundVariants; +import net.minecraft.world.entity.animal.feline.CatSoundVariants; +import net.minecraft.world.entity.animal.pig.PigSoundVariants; +import net.minecraft.world.entity.animal.wolf.WolfSoundVariants; +import net.minecraft.sounds.SoundEvents; + +public class CompatSoundEvents { + public static final CompatSoundEvent ENTITY_ALLAY_AMBIENT_WITH_ITEM = new CompatSoundEvent(SoundEvents.ALLAY_AMBIENT_WITH_ITEM); + public static final CompatSoundEvent ENTITY_ALLAY_AMBIENT_WITHOUT_ITEM = new CompatSoundEvent(SoundEvents.ALLAY_AMBIENT_WITHOUT_ITEM); + public static final CompatSoundEvent ENTITY_ALLAY_DEATH = new CompatSoundEvent(SoundEvents.ALLAY_DEATH); + public static final CompatSoundEvent ENTITY_ALLAY_HURT = new CompatSoundEvent(SoundEvents.ALLAY_HURT); + public static final CompatSoundEvent ENTITY_ALLAY_ITEM_GIVEN = new CompatSoundEvent(SoundEvents.ALLAY_ITEM_GIVEN); + public static final CompatSoundEvent ENTITY_ALLAY_ITEM_TAKEN = new CompatSoundEvent(SoundEvents.ALLAY_ITEM_TAKEN); + public static final CompatSoundEvent ENTITY_ALLAY_ITEM_THROWN = new CompatSoundEvent(SoundEvents.ALLAY_THROW); + 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.AMETHYST_BLOCK_BREAK); + public static final CompatSoundEvent BLOCK_AMETHYST_BLOCK_CHIME = new CompatSoundEvent(SoundEvents.AMETHYST_BLOCK_CHIME); + public static final CompatSoundEvent BLOCK_AMETHYST_BLOCK_FALL = new CompatSoundEvent(SoundEvents.AMETHYST_BLOCK_FALL); + public static final CompatSoundEvent BLOCK_AMETHYST_BLOCK_HIT = new CompatSoundEvent(SoundEvents.AMETHYST_BLOCK_HIT); + public static final CompatSoundEvent BLOCK_AMETHYST_BLOCK_PLACE = new CompatSoundEvent(SoundEvents.AMETHYST_BLOCK_PLACE); + public static final CompatSoundEvent BLOCK_AMETHYST_BLOCK_RESONATE = new CompatSoundEvent(SoundEvents.AMETHYST_BLOCK_RESONATE); + public static final CompatSoundEvent BLOCK_AMETHYST_BLOCK_STEP = new CompatSoundEvent(SoundEvents.AMETHYST_BLOCK_STEP); + public static final CompatSoundEvent BLOCK_AMETHYST_CLUSTER_BREAK = new CompatSoundEvent(SoundEvents.AMETHYST_CLUSTER_BREAK); + public static final CompatSoundEvent BLOCK_AMETHYST_CLUSTER_FALL = new CompatSoundEvent(SoundEvents.AMETHYST_CLUSTER_FALL); + public static final CompatSoundEvent BLOCK_AMETHYST_CLUSTER_HIT = new CompatSoundEvent(SoundEvents.AMETHYST_CLUSTER_HIT); + public static final CompatSoundEvent BLOCK_AMETHYST_CLUSTER_PLACE = new CompatSoundEvent(SoundEvents.AMETHYST_CLUSTER_PLACE); + public static final CompatSoundEvent BLOCK_AMETHYST_CLUSTER_STEP = new CompatSoundEvent(SoundEvents.AMETHYST_CLUSTER_STEP); + public static final CompatSoundEvent BLOCK_ANCIENT_DEBRIS_BREAK = new CompatSoundEvent(SoundEvents.ANCIENT_DEBRIS_BREAK); + public static final CompatSoundEvent BLOCK_ANCIENT_DEBRIS_STEP = new CompatSoundEvent(SoundEvents.ANCIENT_DEBRIS_STEP); + public static final CompatSoundEvent BLOCK_ANCIENT_DEBRIS_PLACE = new CompatSoundEvent(SoundEvents.ANCIENT_DEBRIS_PLACE); + public static final CompatSoundEvent BLOCK_ANCIENT_DEBRIS_HIT = new CompatSoundEvent(SoundEvents.ANCIENT_DEBRIS_HIT); + public static final CompatSoundEvent BLOCK_ANCIENT_DEBRIS_FALL = new CompatSoundEvent(SoundEvents.ANCIENT_DEBRIS_FALL); + public static final CompatSoundEvent BLOCK_ANVIL_BREAK = new CompatSoundEvent(SoundEvents.ANVIL_BREAK); + public static final CompatSoundEvent BLOCK_ANVIL_DESTROY = new CompatSoundEvent(SoundEvents.ANVIL_DESTROY); + public static final CompatSoundEvent BLOCK_ANVIL_FALL = new CompatSoundEvent(SoundEvents.ANVIL_FALL); + public static final CompatSoundEvent BLOCK_ANVIL_HIT = new CompatSoundEvent(SoundEvents.ANVIL_HIT); + public static final CompatSoundEvent BLOCK_ANVIL_LAND = new CompatSoundEvent(SoundEvents.ANVIL_LAND); + public static final CompatSoundEvent BLOCK_ANVIL_PLACE = new CompatSoundEvent(SoundEvents.ANVIL_PLACE); + public static final CompatSoundEvent BLOCK_ANVIL_STEP = new CompatSoundEvent(SoundEvents.ANVIL_STEP); + public static final CompatSoundEvent BLOCK_ANVIL_USE = new CompatSoundEvent(SoundEvents.ANVIL_USE); + public static final CompatSoundEvent ENTITY_ARMADILLO_EAT = new CompatSoundEvent(SoundEvents.ARMADILLO_EAT); + public static final CompatSoundEvent ENTITY_ARMADILLO_HURT = new CompatSoundEvent(SoundEvents.ARMADILLO_HURT); + public static final CompatSoundEvent ENTITY_ARMADILLO_HURT_REDUCED = new CompatSoundEvent(SoundEvents.ARMADILLO_HURT_REDUCED); + public static final CompatSoundEvent ENTITY_ARMADILLO_AMBIENT = new CompatSoundEvent(SoundEvents.ARMADILLO_AMBIENT); + public static final CompatSoundEvent ENTITY_ARMADILLO_STEP = new CompatSoundEvent(SoundEvents.ARMADILLO_STEP); + public static final CompatSoundEvent ENTITY_ARMADILLO_DEATH = new CompatSoundEvent(SoundEvents.ARMADILLO_DEATH); + public static final CompatSoundEvent ENTITY_ARMADILLO_ROLL = new CompatSoundEvent(SoundEvents.ARMADILLO_ROLL); + public static final CompatSoundEvent ENTITY_ARMADILLO_LAND = new CompatSoundEvent(SoundEvents.ARMADILLO_LAND); + public static final CompatSoundEvent ENTITY_ARMADILLO_SCUTE_DROP = new CompatSoundEvent(SoundEvents.ARMADILLO_SCUTE_DROP); + public static final CompatSoundEvent ENTITY_ARMADILLO_UNROLL_FINISH = new CompatSoundEvent(SoundEvents.ARMADILLO_UNROLL_FINISH); + public static final CompatSoundEvent ENTITY_ARMADILLO_PEEK = new CompatSoundEvent(SoundEvents.ARMADILLO_PEEK); + public static final CompatSoundEvent ENTITY_ARMADILLO_UNROLL_START = new CompatSoundEvent(SoundEvents.ARMADILLO_UNROLL_START); + public static final CompatSoundEvent ENTITY_ARMADILLO_BRUSH = new CompatSoundEvent(SoundEvents.ARMADILLO_BRUSH); + public static final CompatSoundEvent ITEM_ARMOR_EQUIP_CHAIN = new CompatSoundEvent(SoundEvents.ARMOR_EQUIP_CHAIN); + public static final CompatSoundEvent ITEM_ARMOR_EQUIP_DIAMOND = new CompatSoundEvent(SoundEvents.ARMOR_EQUIP_DIAMOND); + public static final CompatSoundEvent ITEM_ARMOR_EQUIP_ELYTRA = new CompatSoundEvent(SoundEvents.ARMOR_EQUIP_ELYTRA); + public static final CompatSoundEvent ITEM_ARMOR_EQUIP_GENERIC = new CompatSoundEvent(SoundEvents.ARMOR_EQUIP_GENERIC); + public static final CompatSoundEvent ITEM_ARMOR_EQUIP_GOLD = new CompatSoundEvent(SoundEvents.ARMOR_EQUIP_GOLD); + public static final CompatSoundEvent ITEM_ARMOR_EQUIP_IRON = new CompatSoundEvent(SoundEvents.ARMOR_EQUIP_IRON); + public static final CompatSoundEvent ITEM_ARMOR_EQUIP_LEATHER = new CompatSoundEvent(SoundEvents.ARMOR_EQUIP_LEATHER); + public static final CompatSoundEvent ITEM_ARMOR_EQUIP_NETHERITE = new CompatSoundEvent(SoundEvents.ARMOR_EQUIP_NETHERITE); + public static final CompatSoundEvent ITEM_ARMOR_EQUIP_TURTLE = new CompatSoundEvent(SoundEvents.ARMOR_EQUIP_TURTLE); + public static final CompatSoundEvent ITEM_ARMOR_EQUIP_WOLF = new CompatSoundEvent(SoundEvents.ARMOR_EQUIP_WOLF); + public static final CompatSoundEvent ITEM_ARMOR_UNEQUIP_WOLF = new CompatSoundEvent(SoundEvents.ARMOR_UNEQUIP_WOLF); + public static final CompatSoundEvent ENTITY_ARMOR_STAND_BREAK = new CompatSoundEvent(SoundEvents.ARMOR_STAND_BREAK); + public static final CompatSoundEvent ENTITY_ARMOR_STAND_FALL = new CompatSoundEvent(SoundEvents.ARMOR_STAND_FALL); + public static final CompatSoundEvent ENTITY_ARMOR_STAND_HIT = new CompatSoundEvent(SoundEvents.ARMOR_STAND_HIT); + public static final CompatSoundEvent ENTITY_ARMOR_STAND_PLACE = new CompatSoundEvent(SoundEvents.ARMOR_STAND_PLACE); + public static final CompatSoundEvent ENTITY_ARROW_HIT = new CompatSoundEvent(SoundEvents.ARROW_HIT); + public static final CompatSoundEvent ENTITY_ARROW_HIT_PLAYER = new CompatSoundEvent(SoundEvents.ARROW_HIT_PLAYER); + public static final CompatSoundEvent ENTITY_ARROW_SHOOT = new CompatSoundEvent(SoundEvents.ARROW_SHOOT); + public static final CompatSoundEvent ITEM_AXE_STRIP = new CompatSoundEvent(SoundEvents.AXE_STRIP); + public static final CompatSoundEvent ITEM_AXE_SCRAPE = new CompatSoundEvent(SoundEvents.AXE_SCRAPE); + public static final CompatSoundEvent ITEM_AXE_WAX_OFF = new CompatSoundEvent(SoundEvents.AXE_WAX_OFF); + public static final CompatSoundEvent ENTITY_AXOLOTL_ATTACK = new CompatSoundEvent(SoundEvents.AXOLOTL_ATTACK); + public static final CompatSoundEvent ENTITY_AXOLOTL_DEATH = new CompatSoundEvent(SoundEvents.AXOLOTL_DEATH); + public static final CompatSoundEvent ENTITY_AXOLOTL_HURT = new CompatSoundEvent(SoundEvents.AXOLOTL_HURT); + public static final CompatSoundEvent ENTITY_AXOLOTL_IDLE_AIR = new CompatSoundEvent(SoundEvents.AXOLOTL_IDLE_AIR); + public static final CompatSoundEvent ENTITY_AXOLOTL_IDLE_WATER = new CompatSoundEvent(SoundEvents.AXOLOTL_IDLE_WATER); + public static final CompatSoundEvent ENTITY_AXOLOTL_SPLASH = new CompatSoundEvent(SoundEvents.AXOLOTL_SPLASH); + public static final CompatSoundEvent ENTITY_AXOLOTL_SWIM = new CompatSoundEvent(SoundEvents.AXOLOTL_SWIM); + public static final CompatSoundEvent BLOCK_AZALEA_BREAK = new CompatSoundEvent(SoundEvents.AZALEA_BREAK); + public static final CompatSoundEvent BLOCK_AZALEA_FALL = new CompatSoundEvent(SoundEvents.AZALEA_FALL); + public static final CompatSoundEvent BLOCK_AZALEA_HIT = new CompatSoundEvent(SoundEvents.AZALEA_HIT); + public static final CompatSoundEvent BLOCK_AZALEA_PLACE = new CompatSoundEvent(SoundEvents.AZALEA_PLACE); + public static final CompatSoundEvent BLOCK_AZALEA_STEP = new CompatSoundEvent(SoundEvents.AZALEA_STEP); + public static final CompatSoundEvent BLOCK_AZALEA_LEAVES_BREAK = new CompatSoundEvent(SoundEvents.AZALEA_LEAVES_BREAK); + public static final CompatSoundEvent BLOCK_AZALEA_LEAVES_FALL = new CompatSoundEvent(SoundEvents.AZALEA_LEAVES_FALL); + public static final CompatSoundEvent BLOCK_AZALEA_LEAVES_HIT = new CompatSoundEvent(SoundEvents.AZALEA_LEAVES_HIT); + public static final CompatSoundEvent BLOCK_AZALEA_LEAVES_PLACE = new CompatSoundEvent(SoundEvents.AZALEA_LEAVES_PLACE); + public static final CompatSoundEvent BLOCK_AZALEA_LEAVES_STEP = new CompatSoundEvent(SoundEvents.AZALEA_LEAVES_STEP); + public static final CompatSoundEvent BLOCK_BAMBOO_BREAK = new CompatSoundEvent(SoundEvents.BAMBOO_BREAK); + public static final CompatSoundEvent BLOCK_BAMBOO_FALL = new CompatSoundEvent(SoundEvents.BAMBOO_FALL); + public static final CompatSoundEvent BLOCK_BAMBOO_HIT = new CompatSoundEvent(SoundEvents.BAMBOO_HIT); + public static final CompatSoundEvent BLOCK_BAMBOO_PLACE = new CompatSoundEvent(SoundEvents.BAMBOO_PLACE); + public static final CompatSoundEvent BLOCK_BAMBOO_STEP = new CompatSoundEvent(SoundEvents.BAMBOO_STEP); + public static final CompatSoundEvent BLOCK_BAMBOO_SAPLING_BREAK = new CompatSoundEvent(SoundEvents.BAMBOO_SAPLING_BREAK); + public static final CompatSoundEvent BLOCK_BAMBOO_SAPLING_HIT = new CompatSoundEvent(SoundEvents.BAMBOO_SAPLING_HIT); + public static final CompatSoundEvent BLOCK_BAMBOO_SAPLING_PLACE = new CompatSoundEvent(SoundEvents.BAMBOO_SAPLING_PLACE); + public static final CompatSoundEvent BLOCK_BAMBOO_WOOD_BREAK = new CompatSoundEvent(SoundEvents.BAMBOO_WOOD_BREAK); + public static final CompatSoundEvent BLOCK_BAMBOO_WOOD_FALL = new CompatSoundEvent(SoundEvents.BAMBOO_WOOD_FALL); + public static final CompatSoundEvent BLOCK_BAMBOO_WOOD_HIT = new CompatSoundEvent(SoundEvents.BAMBOO_WOOD_HIT); + public static final CompatSoundEvent BLOCK_BAMBOO_WOOD_PLACE = new CompatSoundEvent(SoundEvents.BAMBOO_WOOD_PLACE); + public static final CompatSoundEvent BLOCK_BAMBOO_WOOD_STEP = new CompatSoundEvent(SoundEvents.BAMBOO_WOOD_STEP); + public static final CompatSoundEvent BLOCK_BAMBOO_WOOD_DOOR_CLOSE = new CompatSoundEvent(SoundEvents.BAMBOO_WOOD_DOOR_CLOSE); + public static final CompatSoundEvent BLOCK_BAMBOO_WOOD_DOOR_OPEN = new CompatSoundEvent(SoundEvents.BAMBOO_WOOD_DOOR_OPEN); + public static final CompatSoundEvent BLOCK_BAMBOO_WOOD_TRAPDOOR_CLOSE = new CompatSoundEvent(SoundEvents.BAMBOO_WOOD_TRAPDOOR_CLOSE); + public static final CompatSoundEvent BLOCK_BAMBOO_WOOD_TRAPDOOR_OPEN = new CompatSoundEvent(SoundEvents.BAMBOO_WOOD_TRAPDOOR_OPEN); + public static final CompatSoundEvent BLOCK_BAMBOO_WOOD_BUTTON_CLICK_OFF = new CompatSoundEvent(SoundEvents.BAMBOO_WOOD_BUTTON_CLICK_OFF); + public static final CompatSoundEvent BLOCK_BAMBOO_WOOD_BUTTON_CLICK_ON = new CompatSoundEvent(SoundEvents.BAMBOO_WOOD_BUTTON_CLICK_ON); + public static final CompatSoundEvent BLOCK_BAMBOO_WOOD_PRESSURE_PLATE_CLICK_OFF = new CompatSoundEvent(SoundEvents.BAMBOO_WOOD_PRESSURE_PLATE_CLICK_OFF); + public static final CompatSoundEvent BLOCK_BAMBOO_WOOD_PRESSURE_PLATE_CLICK_ON = new CompatSoundEvent(SoundEvents.BAMBOO_WOOD_PRESSURE_PLATE_CLICK_ON); + public static final CompatSoundEvent BLOCK_BAMBOO_WOOD_FENCE_GATE_CLOSE = new CompatSoundEvent(SoundEvents.BAMBOO_WOOD_FENCE_GATE_CLOSE); + public static final CompatSoundEvent BLOCK_BAMBOO_WOOD_FENCE_GATE_OPEN = new CompatSoundEvent(SoundEvents.BAMBOO_WOOD_FENCE_GATE_OPEN); + public static final CompatSoundEvent BLOCK_BARREL_CLOSE = new CompatSoundEvent(SoundEvents.BARREL_CLOSE); + public static final CompatSoundEvent BLOCK_BARREL_OPEN = new CompatSoundEvent(SoundEvents.BARREL_OPEN); + public static final CompatSoundEvent BLOCK_BASALT_BREAK = new CompatSoundEvent(SoundEvents.BASALT_BREAK); + public static final CompatSoundEvent BLOCK_BASALT_STEP = new CompatSoundEvent(SoundEvents.BASALT_STEP); + public static final CompatSoundEvent BLOCK_BASALT_PLACE = new CompatSoundEvent(SoundEvents.BASALT_PLACE); + public static final CompatSoundEvent BLOCK_BASALT_HIT = new CompatSoundEvent(SoundEvents.BASALT_HIT); + public static final CompatSoundEvent BLOCK_BASALT_FALL = new CompatSoundEvent(SoundEvents.BASALT_FALL); + public static final CompatSoundEvent ENTITY_BAT_AMBIENT = new CompatSoundEvent(SoundEvents.BAT_AMBIENT); + public static final CompatSoundEvent ENTITY_BAT_DEATH = new CompatSoundEvent(SoundEvents.BAT_DEATH); + public static final CompatSoundEvent ENTITY_BAT_HURT = new CompatSoundEvent(SoundEvents.BAT_HURT); + public static final CompatSoundEvent ENTITY_BAT_LOOP = new CompatSoundEvent(SoundEvents.BAT_LOOP); + public static final CompatSoundEvent ENTITY_BAT_TAKEOFF = new CompatSoundEvent(SoundEvents.BAT_TAKEOFF); + public static final CompatSoundEvent BLOCK_BEACON_ACTIVATE = new CompatSoundEvent(SoundEvents.BEACON_ACTIVATE); + public static final CompatSoundEvent BLOCK_BEACON_AMBIENT = new CompatSoundEvent(SoundEvents.BEACON_AMBIENT); + public static final CompatSoundEvent BLOCK_BEACON_DEACTIVATE = new CompatSoundEvent(SoundEvents.BEACON_DEACTIVATE); + public static final CompatSoundEvent BLOCK_BEACON_POWER_SELECT = new CompatSoundEvent(SoundEvents.BEACON_POWER_SELECT); + public static final CompatSoundEvent ENTITY_BEE_DEATH = new CompatSoundEvent(SoundEvents.BEE_DEATH); + public static final CompatSoundEvent ENTITY_BEE_HURT = new CompatSoundEvent(SoundEvents.BEE_HURT); + public static final CompatSoundEvent ENTITY_BEE_LOOP_AGGRESSIVE = new CompatSoundEvent(SoundEvents.BEE_LOOP_AGGRESSIVE); + public static final CompatSoundEvent ENTITY_BEE_LOOP = new CompatSoundEvent(SoundEvents.BEE_LOOP); + public static final CompatSoundEvent ENTITY_BEE_STING = new CompatSoundEvent(SoundEvents.BEE_STING); + public static final CompatSoundEvent ENTITY_BEE_POLLINATE = new CompatSoundEvent(SoundEvents.BEE_POLLINATE); + public static final CompatSoundEvent BLOCK_BEEHIVE_DRIP = new CompatSoundEvent(SoundEvents.BEEHIVE_DRIP); + public static final CompatSoundEvent BLOCK_BEEHIVE_ENTER = new CompatSoundEvent(SoundEvents.BEEHIVE_ENTER); + public static final CompatSoundEvent BLOCK_BEEHIVE_EXIT = new CompatSoundEvent(SoundEvents.BEEHIVE_EXIT); + public static final CompatSoundEvent BLOCK_BEEHIVE_SHEAR = new CompatSoundEvent(SoundEvents.BEEHIVE_SHEAR); + public static final CompatSoundEvent BLOCK_BEEHIVE_WORK = new CompatSoundEvent(SoundEvents.BEEHIVE_WORK); + public static final CompatSoundEvent BLOCK_BELL_USE = new CompatSoundEvent(SoundEvents.BELL_BLOCK); + public static final CompatSoundEvent BLOCK_BELL_RESONATE = new CompatSoundEvent(SoundEvents.BELL_RESONATE); + public static final CompatSoundEvent BLOCK_BIG_DRIPLEAF_BREAK = new CompatSoundEvent(SoundEvents.BIG_DRIPLEAF_BREAK); + public static final CompatSoundEvent BLOCK_BIG_DRIPLEAF_FALL = new CompatSoundEvent(SoundEvents.BIG_DRIPLEAF_FALL); + public static final CompatSoundEvent BLOCK_BIG_DRIPLEAF_HIT = new CompatSoundEvent(SoundEvents.BIG_DRIPLEAF_HIT); + public static final CompatSoundEvent BLOCK_BIG_DRIPLEAF_PLACE = new CompatSoundEvent(SoundEvents.BIG_DRIPLEAF_PLACE); + public static final CompatSoundEvent BLOCK_BIG_DRIPLEAF_STEP = new CompatSoundEvent(SoundEvents.BIG_DRIPLEAF_STEP); + public static final CompatSoundEvent ENTITY_BLAZE_AMBIENT = new CompatSoundEvent(SoundEvents.BLAZE_AMBIENT); + public static final CompatSoundEvent ENTITY_BLAZE_BURN = new CompatSoundEvent(SoundEvents.BLAZE_BURN); + public static final CompatSoundEvent ENTITY_BLAZE_DEATH = new CompatSoundEvent(SoundEvents.BLAZE_DEATH); + public static final CompatSoundEvent ENTITY_BLAZE_HURT = new CompatSoundEvent(SoundEvents.BLAZE_HURT); + public static final CompatSoundEvent ENTITY_BLAZE_SHOOT = new CompatSoundEvent(SoundEvents.BLAZE_SHOOT); + public static final CompatSoundEvent ENTITY_BOAT_PADDLE_LAND = new CompatSoundEvent(SoundEvents.BOAT_PADDLE_LAND); + public static final CompatSoundEvent ENTITY_BOAT_PADDLE_WATER = new CompatSoundEvent(SoundEvents.BOAT_PADDLE_WATER); + public static final CompatSoundEvent ENTITY_BOGGED_AMBIENT = new CompatSoundEvent(SoundEvents.BOGGED_AMBIENT); + public static final CompatSoundEvent ENTITY_BOGGED_DEATH = new CompatSoundEvent(SoundEvents.BOGGED_DEATH); + public static final CompatSoundEvent ENTITY_BOGGED_HURT = new CompatSoundEvent(SoundEvents.BOGGED_HURT); + public static final CompatSoundEvent ENTITY_BOGGED_SHEAR = new CompatSoundEvent(SoundEvents.BOGGED_SHEAR); + public static final CompatSoundEvent ENTITY_BOGGED_STEP = new CompatSoundEvent(SoundEvents.BOGGED_STEP); + public static final CompatSoundEvent BLOCK_BONE_BLOCK_BREAK = new CompatSoundEvent(SoundEvents.BONE_BLOCK_BREAK); + public static final CompatSoundEvent BLOCK_BONE_BLOCK_FALL = new CompatSoundEvent(SoundEvents.BONE_BLOCK_FALL); + public static final CompatSoundEvent BLOCK_BONE_BLOCK_HIT = new CompatSoundEvent(SoundEvents.BONE_BLOCK_HIT); + public static final CompatSoundEvent BLOCK_BONE_BLOCK_PLACE = new CompatSoundEvent(SoundEvents.BONE_BLOCK_PLACE); + public static final CompatSoundEvent BLOCK_BONE_BLOCK_STEP = new CompatSoundEvent(SoundEvents.BONE_BLOCK_STEP); + public static final CompatSoundEvent ITEM_BONE_MEAL_USE = new CompatSoundEvent(SoundEvents.BONE_MEAL_USE); + public static final CompatSoundEvent ITEM_BOOK_PAGE_TURN = new CompatSoundEvent(SoundEvents.BOOK_PAGE_TURN); + public static final CompatSoundEvent ITEM_BOOK_PUT = new CompatSoundEvent(SoundEvents.BOOK_PUT); + public static final CompatSoundEvent BLOCK_BLASTFURNACE_FIRE_CRACKLE = new CompatSoundEvent(SoundEvents.BLASTFURNACE_FIRE_CRACKLE); + public static final CompatSoundEvent ITEM_BOTTLE_EMPTY = new CompatSoundEvent(SoundEvents.BOTTLE_EMPTY); + public static final CompatSoundEvent ITEM_BOTTLE_FILL = new CompatSoundEvent(SoundEvents.BOTTLE_FILL); + public static final CompatSoundEvent ITEM_BOTTLE_FILL_DRAGONBREATH = new CompatSoundEvent(SoundEvents.BOTTLE_FILL_DRAGONBREATH); + public static final CompatSoundEvent ENTITY_BREEZE_CHARGE = new CompatSoundEvent(SoundEvents.BREEZE_CHARGE); + public static final CompatSoundEvent ENTITY_BREEZE_DEFLECT = new CompatSoundEvent(SoundEvents.BREEZE_DEFLECT); + public static final CompatSoundEvent ENTITY_BREEZE_INHALE = new CompatSoundEvent(SoundEvents.BREEZE_INHALE); + public static final CompatSoundEvent ENTITY_BREEZE_IDLE_GROUND = new CompatSoundEvent(SoundEvents.BREEZE_IDLE_GROUND); + public static final CompatSoundEvent ENTITY_BREEZE_IDLE_AIR = new CompatSoundEvent(SoundEvents.BREEZE_IDLE_AIR); + public static final CompatSoundEvent ENTITY_BREEZE_SHOOT = new CompatSoundEvent(SoundEvents.BREEZE_SHOOT); + public static final CompatSoundEvent ENTITY_BREEZE_JUMP = new CompatSoundEvent(SoundEvents.BREEZE_JUMP); + public static final CompatSoundEvent ENTITY_BREEZE_LAND = new CompatSoundEvent(SoundEvents.BREEZE_LAND); + public static final CompatSoundEvent ENTITY_BREEZE_SLIDE = new CompatSoundEvent(SoundEvents.BREEZE_SLIDE); + public static final CompatSoundEvent ENTITY_BREEZE_DEATH = new CompatSoundEvent(SoundEvents.BREEZE_DEATH); + public static final CompatSoundEvent ENTITY_BREEZE_HURT = new CompatSoundEvent(SoundEvents.BREEZE_HURT); + public static final CompatSoundEvent ENTITY_BREEZE_WHIRL = new CompatSoundEvent(SoundEvents.BREEZE_WHIRL); + public static final CompatSoundEvent ENTITY_BREEZE_WIND_BURST = new CompatSoundEvent(SoundEvents.BREEZE_WIND_CHARGE_BURST); + public static final CompatSoundEvent BLOCK_BREWING_STAND_BREW = new CompatSoundEvent(SoundEvents.BREWING_STAND_BREW); + public static final CompatSoundEvent ITEM_BRUSH_BRUSHING_GENERIC = new CompatSoundEvent(SoundEvents.BRUSH_GENERIC); + public static final CompatSoundEvent ITEM_BRUSH_BRUSHING_SAND = new CompatSoundEvent(SoundEvents.BRUSH_SAND); + public static final CompatSoundEvent ITEM_BRUSH_BRUSHING_GRAVEL = new CompatSoundEvent(SoundEvents.BRUSH_GRAVEL); + public static final CompatSoundEvent ITEM_BRUSH_BRUSHING_SAND_COMPLETE = new CompatSoundEvent(SoundEvents.BRUSH_SAND_COMPLETED); + public static final CompatSoundEvent ITEM_BRUSH_BRUSHING_GRAVEL_COMPLETE = new CompatSoundEvent(SoundEvents.BRUSH_GRAVEL_COMPLETED); + public static final CompatSoundEvent BLOCK_BUBBLE_COLUMN_BUBBLE_POP = new CompatSoundEvent(SoundEvents.BUBBLE_COLUMN_BUBBLE_POP); + public static final CompatSoundEvent BLOCK_BUBBLE_COLUMN_UPWARDS_AMBIENT = new CompatSoundEvent(SoundEvents.BUBBLE_COLUMN_UPWARDS_AMBIENT); + public static final CompatSoundEvent BLOCK_BUBBLE_COLUMN_UPWARDS_INSIDE = new CompatSoundEvent(SoundEvents.BUBBLE_COLUMN_UPWARDS_INSIDE); + public static final CompatSoundEvent BLOCK_BUBBLE_COLUMN_WHIRLPOOL_AMBIENT = new CompatSoundEvent(SoundEvents.BUBBLE_COLUMN_WHIRLPOOL_AMBIENT); + public static final CompatSoundEvent BLOCK_BUBBLE_COLUMN_WHIRLPOOL_INSIDE = new CompatSoundEvent(SoundEvents.BUBBLE_COLUMN_WHIRLPOOL_INSIDE); + public static final CompatSoundEvent ITEM_BUCKET_EMPTY = new CompatSoundEvent(SoundEvents.BUCKET_EMPTY); + public static final CompatSoundEvent ITEM_BUCKET_EMPTY_AXOLOTL = new CompatSoundEvent(SoundEvents.BUCKET_EMPTY_AXOLOTL); + public static final CompatSoundEvent ITEM_BUCKET_EMPTY_FISH = new CompatSoundEvent(SoundEvents.BUCKET_EMPTY_FISH); + public static final CompatSoundEvent ITEM_BUCKET_EMPTY_LAVA = new CompatSoundEvent(SoundEvents.BUCKET_EMPTY_LAVA); + public static final CompatSoundEvent ITEM_BUCKET_EMPTY_POWDER_SNOW = new CompatSoundEvent(SoundEvents.BUCKET_EMPTY_POWDER_SNOW); + public static final CompatSoundEvent ITEM_BUCKET_EMPTY_TADPOLE = new CompatSoundEvent(SoundEvents.BUCKET_EMPTY_TADPOLE); + public static final CompatSoundEvent ITEM_BUCKET_FILL = new CompatSoundEvent(SoundEvents.BUCKET_FILL); + public static final CompatSoundEvent ITEM_BUCKET_FILL_AXOLOTL = new CompatSoundEvent(SoundEvents.BUCKET_FILL_AXOLOTL); + public static final CompatSoundEvent ITEM_BUCKET_FILL_FISH = new CompatSoundEvent(SoundEvents.BUCKET_FILL_FISH); + public static final CompatSoundEvent ITEM_BUCKET_FILL_LAVA = new CompatSoundEvent(SoundEvents.BUCKET_FILL_LAVA); + public static final CompatSoundEvent ITEM_BUCKET_FILL_POWDER_SNOW = new CompatSoundEvent(SoundEvents.BUCKET_FILL_POWDER_SNOW); + public static final CompatSoundEvent ITEM_BUCKET_FILL_TADPOLE = new CompatSoundEvent(SoundEvents.BUCKET_FILL_TADPOLE); + public static final CompatSoundEvent ITEM_BUNDLE_DROP_CONTENTS = new CompatSoundEvent(SoundEvents.BUNDLE_DROP_CONTENTS); + public static final CompatSoundEvent ITEM_BUNDLE_INSERT = new CompatSoundEvent(SoundEvents.BUNDLE_INSERT); + public static final CompatSoundEvent ITEM_BUNDLE_REMOVE_ONE = new CompatSoundEvent(SoundEvents.BUNDLE_REMOVE_ONE); + public static final CompatSoundEvent BLOCK_CAKE_ADD_CANDLE = new CompatSoundEvent(SoundEvents.CAKE_ADD_CANDLE); + public static final CompatSoundEvent BLOCK_CALCITE_BREAK = new CompatSoundEvent(SoundEvents.CALCITE_BREAK); + public static final CompatSoundEvent BLOCK_CALCITE_STEP = new CompatSoundEvent(SoundEvents.CALCITE_STEP); + public static final CompatSoundEvent BLOCK_CALCITE_PLACE = new CompatSoundEvent(SoundEvents.CALCITE_PLACE); + public static final CompatSoundEvent BLOCK_CALCITE_HIT = new CompatSoundEvent(SoundEvents.CALCITE_HIT); + public static final CompatSoundEvent BLOCK_CALCITE_FALL = new CompatSoundEvent(SoundEvents.CALCITE_FALL); + public static final CompatSoundEvent ENTITY_CAMEL_AMBIENT = new CompatSoundEvent(SoundEvents.CAMEL_AMBIENT); + public static final CompatSoundEvent ENTITY_CAMEL_DASH = new CompatSoundEvent(SoundEvents.CAMEL_DASH); + public static final CompatSoundEvent ENTITY_CAMEL_DASH_READY = new CompatSoundEvent(SoundEvents.CAMEL_DASH_READY); + public static final CompatSoundEvent ENTITY_CAMEL_DEATH = new CompatSoundEvent(SoundEvents.CAMEL_DEATH); + public static final CompatSoundEvent ENTITY_CAMEL_EAT = new CompatSoundEvent(SoundEvents.CAMEL_EAT); + public static final CompatSoundEvent ENTITY_CAMEL_HURT = new CompatSoundEvent(SoundEvents.CAMEL_HURT); + public static final CompatSoundEvent ENTITY_CAMEL_SADDLE = new CompatSoundEvent(SoundEvents.CAMEL_SADDLE); + public static final CompatSoundEvent ENTITY_CAMEL_SIT = new CompatSoundEvent(SoundEvents.CAMEL_SIT); + public static final CompatSoundEvent ENTITY_CAMEL_STAND = new CompatSoundEvent(SoundEvents.CAMEL_STAND); + public static final CompatSoundEvent ENTITY_CAMEL_STEP = new CompatSoundEvent(SoundEvents.CAMEL_STEP); + public static final CompatSoundEvent ENTITY_CAMEL_STEP_SAND = new CompatSoundEvent(SoundEvents.CAMEL_STEP_SAND); + public static final CompatSoundEvent BLOCK_CAMPFIRE_CRACKLE = new CompatSoundEvent(SoundEvents.CAMPFIRE_CRACKLE); + public static final CompatSoundEvent BLOCK_CANDLE_AMBIENT = new CompatSoundEvent(SoundEvents.CANDLE_AMBIENT); + public static final CompatSoundEvent BLOCK_CANDLE_BREAK = new CompatSoundEvent(SoundEvents.CANDLE_BREAK); + public static final CompatSoundEvent BLOCK_CANDLE_EXTINGUISH = new CompatSoundEvent(SoundEvents.CANDLE_EXTINGUISH); + public static final CompatSoundEvent BLOCK_CANDLE_FALL = new CompatSoundEvent(SoundEvents.CANDLE_FALL); + public static final CompatSoundEvent BLOCK_CANDLE_HIT = new CompatSoundEvent(SoundEvents.CANDLE_HIT); + public static final CompatSoundEvent BLOCK_CANDLE_PLACE = new CompatSoundEvent(SoundEvents.CANDLE_PLACE); + public static final CompatSoundEvent BLOCK_CANDLE_STEP = new CompatSoundEvent(SoundEvents.CANDLE_STEP); + public static final CompatSoundEvent ENTITY_CAT_AMBIENT = new CompatSoundEvent(SoundEvents.CAT_SOUNDS.get(CatSoundVariants.SoundSet.CLASSIC).adultSounds().ambientSound()); + public static final CompatSoundEvent ENTITY_CAT_STRAY_AMBIENT = new CompatSoundEvent(SoundEvents.CAT_SOUNDS.get(CatSoundVariants.SoundSet.CLASSIC).adultSounds().strayAmbientSound()); + public static final CompatSoundEvent ENTITY_CAT_DEATH = new CompatSoundEvent(SoundEvents.CAT_SOUNDS.get(CatSoundVariants.SoundSet.CLASSIC).adultSounds().deathSound()); + public static final CompatSoundEvent ENTITY_CAT_EAT = new CompatSoundEvent(SoundEvents.CAT_SOUNDS.get(CatSoundVariants.SoundSet.CLASSIC).adultSounds().eatSound()); + public static final CompatSoundEvent ENTITY_CAT_HISS = new CompatSoundEvent(SoundEvents.CAT_SOUNDS.get(CatSoundVariants.SoundSet.CLASSIC).adultSounds().hissSound()); + public static final CompatSoundEvent ENTITY_CAT_BEG_FOR_FOOD = new CompatSoundEvent(SoundEvents.CAT_SOUNDS.get(CatSoundVariants.SoundSet.CLASSIC).adultSounds().begForFoodSound()); + public static final CompatSoundEvent ENTITY_CAT_HURT = new CompatSoundEvent(SoundEvents.CAT_SOUNDS.get(CatSoundVariants.SoundSet.CLASSIC).adultSounds().hurtSound()); + public static final CompatSoundEvent ENTITY_CAT_PURR = new CompatSoundEvent(SoundEvents.CAT_SOUNDS.get(CatSoundVariants.SoundSet.CLASSIC).adultSounds().purrSound()); + public static final CompatSoundEvent ENTITY_CAT_PURREOW = new CompatSoundEvent(SoundEvents.CAT_SOUNDS.get(CatSoundVariants.SoundSet.CLASSIC).adultSounds().purreowSound()); + public static final CompatSoundEvent BLOCK_CAVE_VINES_BREAK = new CompatSoundEvent(SoundEvents.CAVE_VINES_BREAK); + public static final CompatSoundEvent BLOCK_CAVE_VINES_FALL = new CompatSoundEvent(SoundEvents.CAVE_VINES_FALL); + public static final CompatSoundEvent BLOCK_CAVE_VINES_HIT = new CompatSoundEvent(SoundEvents.CAVE_VINES_HIT); + public static final CompatSoundEvent BLOCK_CAVE_VINES_PLACE = new CompatSoundEvent(SoundEvents.CAVE_VINES_PLACE); + public static final CompatSoundEvent BLOCK_CAVE_VINES_STEP = new CompatSoundEvent(SoundEvents.CAVE_VINES_STEP); + public static final CompatSoundEvent BLOCK_CAVE_VINES_PICK_BERRIES = new CompatSoundEvent(SoundEvents.CAVE_VINES_PICK_BERRIES); + public static final CompatSoundEvent BLOCK_CHAIN_BREAK = new CompatSoundEvent(SoundEvents.CHAIN_BREAK); + public static final CompatSoundEvent BLOCK_CHAIN_FALL = new CompatSoundEvent(SoundEvents.CHAIN_FALL); + public static final CompatSoundEvent BLOCK_CHAIN_HIT = new CompatSoundEvent(SoundEvents.CHAIN_HIT); + public static final CompatSoundEvent BLOCK_CHAIN_PLACE = new CompatSoundEvent(SoundEvents.CHAIN_PLACE); + public static final CompatSoundEvent BLOCK_CHAIN_STEP = new CompatSoundEvent(SoundEvents.CHAIN_STEP); + public static final CompatSoundEvent BLOCK_CHERRY_WOOD_BREAK = new CompatSoundEvent(SoundEvents.CHERRY_WOOD_BREAK); + public static final CompatSoundEvent BLOCK_CHERRY_WOOD_FALL = new CompatSoundEvent(SoundEvents.CHERRY_WOOD_FALL); + public static final CompatSoundEvent BLOCK_CHERRY_WOOD_HIT = new CompatSoundEvent(SoundEvents.CHERRY_WOOD_HIT); + public static final CompatSoundEvent BLOCK_CHERRY_WOOD_PLACE = new CompatSoundEvent(SoundEvents.CHERRY_WOOD_PLACE); + public static final CompatSoundEvent BLOCK_CHERRY_WOOD_STEP = new CompatSoundEvent(SoundEvents.CHERRY_WOOD_STEP); + public static final CompatSoundEvent BLOCK_CHERRY_SAPLING_BREAK = new CompatSoundEvent(SoundEvents.CHERRY_SAPLING_BREAK); + public static final CompatSoundEvent BLOCK_CHERRY_SAPLING_FALL = new CompatSoundEvent(SoundEvents.CHERRY_SAPLING_FALL); + public static final CompatSoundEvent BLOCK_CHERRY_SAPLING_HIT = new CompatSoundEvent(SoundEvents.CHERRY_SAPLING_HIT); + public static final CompatSoundEvent BLOCK_CHERRY_SAPLING_PLACE = new CompatSoundEvent(SoundEvents.CHERRY_SAPLING_PLACE); + public static final CompatSoundEvent BLOCK_CHERRY_SAPLING_STEP = new CompatSoundEvent(SoundEvents.CHERRY_SAPLING_STEP); + public static final CompatSoundEvent BLOCK_CHERRY_LEAVES_BREAK = new CompatSoundEvent(SoundEvents.CHERRY_LEAVES_BREAK); + public static final CompatSoundEvent BLOCK_CHERRY_LEAVES_FALL = new CompatSoundEvent(SoundEvents.CHERRY_LEAVES_FALL); + public static final CompatSoundEvent BLOCK_CHERRY_LEAVES_HIT = new CompatSoundEvent(SoundEvents.CHERRY_LEAVES_HIT); + public static final CompatSoundEvent BLOCK_CHERRY_LEAVES_PLACE = new CompatSoundEvent(SoundEvents.CHERRY_LEAVES_PLACE); + public static final CompatSoundEvent BLOCK_CHERRY_LEAVES_STEP = new CompatSoundEvent(SoundEvents.CHERRY_LEAVES_STEP); + public static final CompatSoundEvent BLOCK_CHERRY_WOOD_HANGING_SIGN_STEP = new CompatSoundEvent(SoundEvents.CHERRY_WOOD_HANGING_SIGN_STEP); + public static final CompatSoundEvent BLOCK_CHERRY_WOOD_HANGING_SIGN_BREAK = new CompatSoundEvent(SoundEvents.CHERRY_WOOD_HANGING_SIGN_BREAK); + public static final CompatSoundEvent BLOCK_CHERRY_WOOD_HANGING_SIGN_FALL = new CompatSoundEvent(SoundEvents.CHERRY_WOOD_HANGING_SIGN_FALL); + public static final CompatSoundEvent BLOCK_CHERRY_WOOD_HANGING_SIGN_HIT = new CompatSoundEvent(SoundEvents.CHERRY_WOOD_HANGING_SIGN_HIT); + public static final CompatSoundEvent BLOCK_CHERRY_WOOD_HANGING_SIGN_PLACE = new CompatSoundEvent(SoundEvents.CHERRY_WOOD_HANGING_SIGN_PLACE); + public static final CompatSoundEvent BLOCK_CHERRY_WOOD_DOOR_CLOSE = new CompatSoundEvent(SoundEvents.CHERRY_WOOD_DOOR_CLOSE); + public static final CompatSoundEvent BLOCK_CHERRY_WOOD_DOOR_OPEN = new CompatSoundEvent(SoundEvents.CHERRY_WOOD_DOOR_OPEN); + public static final CompatSoundEvent BLOCK_CHERRY_WOOD_TRAPDOOR_CLOSE = new CompatSoundEvent(SoundEvents.CHERRY_WOOD_TRAPDOOR_CLOSE); + public static final CompatSoundEvent BLOCK_CHERRY_WOOD_TRAPDOOR_OPEN = new CompatSoundEvent(SoundEvents.CHERRY_WOOD_TRAPDOOR_OPEN); + public static final CompatSoundEvent BLOCK_CHERRY_WOOD_BUTTON_CLICK_OFF = new CompatSoundEvent(SoundEvents.CHERRY_WOOD_BUTTON_CLICK_OFF); + public static final CompatSoundEvent BLOCK_CHERRY_WOOD_BUTTON_CLICK_ON = new CompatSoundEvent(SoundEvents.CHERRY_WOOD_BUTTON_CLICK_ON); + public static final CompatSoundEvent BLOCK_CHERRY_WOOD_PRESSURE_PLATE_CLICK_OFF = new CompatSoundEvent(SoundEvents.CHERRY_WOOD_PRESSURE_PLATE_CLICK_OFF); + public static final CompatSoundEvent BLOCK_CHERRY_WOOD_PRESSURE_PLATE_CLICK_ON = new CompatSoundEvent(SoundEvents.CHERRY_WOOD_PRESSURE_PLATE_CLICK_ON); + public static final CompatSoundEvent BLOCK_CHERRY_WOOD_FENCE_GATE_CLOSE = new CompatSoundEvent(SoundEvents.CHERRY_WOOD_FENCE_GATE_CLOSE); + public static final CompatSoundEvent BLOCK_CHERRY_WOOD_FENCE_GATE_OPEN = new CompatSoundEvent(SoundEvents.CHERRY_WOOD_FENCE_GATE_OPEN); + public static final CompatSoundEvent BLOCK_CHEST_CLOSE = new CompatSoundEvent(SoundEvents.CHEST_CLOSE); + public static final CompatSoundEvent BLOCK_CHEST_LOCKED = new CompatSoundEvent(SoundEvents.CHEST_LOCKED); + public static final CompatSoundEvent BLOCK_CHEST_OPEN = new CompatSoundEvent(SoundEvents.CHEST_OPEN); + public static final CompatSoundEvent ENTITY_CHICKEN_AMBIENT = new CompatSoundEvent(SoundEvents.CHICKEN_SOUNDS.get(ChickenSoundVariants.SoundSet.CLASSIC).adultSounds().ambientSound()); + public static final CompatSoundEvent ENTITY_CHICKEN_DEATH = new CompatSoundEvent(SoundEvents.CHICKEN_SOUNDS.get(ChickenSoundVariants.SoundSet.CLASSIC).adultSounds().deathSound()); + public static final CompatSoundEvent ENTITY_CHICKEN_EGG = new CompatSoundEvent(SoundEvents.CHICKEN_EGG); + public static final CompatSoundEvent ENTITY_CHICKEN_HURT = new CompatSoundEvent(SoundEvents.CHICKEN_SOUNDS.get(ChickenSoundVariants.SoundSet.CLASSIC).adultSounds().hurtSound()); + public static final CompatSoundEvent ENTITY_CHICKEN_STEP = new CompatSoundEvent(SoundEvents.CHICKEN_STEP); + public static final CompatSoundEvent BLOCK_CHISELED_BOOKSHELF_BREAK = new CompatSoundEvent(SoundEvents.CHISELED_BOOKSHELF_BREAK); + public static final CompatSoundEvent BLOCK_CHISELED_BOOKSHELF_FALL = new CompatSoundEvent(SoundEvents.CHISELED_BOOKSHELF_FALL); + public static final CompatSoundEvent BLOCK_CHISELED_BOOKSHELF_HIT = new CompatSoundEvent(SoundEvents.CHISELED_BOOKSHELF_HIT); + public static final CompatSoundEvent BLOCK_CHISELED_BOOKSHELF_INSERT = new CompatSoundEvent(SoundEvents.CHISELED_BOOKSHELF_INSERT); + public static final CompatSoundEvent BLOCK_CHISELED_BOOKSHELF_INSERT_ENCHANTED = new CompatSoundEvent(SoundEvents.CHISELED_BOOKSHELF_INSERT_ENCHANTED); + public static final CompatSoundEvent BLOCK_CHISELED_BOOKSHELF_STEP = new CompatSoundEvent(SoundEvents.CHISELED_BOOKSHELF_STEP); + public static final CompatSoundEvent BLOCK_CHISELED_BOOKSHELF_PICKUP = new CompatSoundEvent(SoundEvents.CHISELED_BOOKSHELF_PICKUP); + public static final CompatSoundEvent BLOCK_CHISELED_BOOKSHELF_PICKUP_ENCHANTED = new CompatSoundEvent(SoundEvents.CHISELED_BOOKSHELF_PICKUP_ENCHANTED); + public static final CompatSoundEvent BLOCK_CHISELED_BOOKSHELF_PLACE = new CompatSoundEvent(SoundEvents.CHISELED_BOOKSHELF_PLACE); + public static final CompatSoundEvent BLOCK_CHORUS_FLOWER_DEATH = new CompatSoundEvent(SoundEvents.CHORUS_FLOWER_DEATH); + public static final CompatSoundEvent BLOCK_CHORUS_FLOWER_GROW = new CompatSoundEvent(SoundEvents.CHORUS_FLOWER_GROW); + public static final CompatSoundEvent ITEM_CHORUS_FRUIT_TELEPORT = new CompatSoundEvent(SoundEvents.CHORUS_FRUIT_TELEPORT); + public static final CompatSoundEvent BLOCK_COBWEB_BREAK = new CompatSoundEvent(SoundEvents.COBWEB_BREAK); + public static final CompatSoundEvent BLOCK_COBWEB_STEP = new CompatSoundEvent(SoundEvents.COBWEB_STEP); + public static final CompatSoundEvent BLOCK_COBWEB_PLACE = new CompatSoundEvent(SoundEvents.COBWEB_PLACE); + public static final CompatSoundEvent BLOCK_COBWEB_HIT = new CompatSoundEvent(SoundEvents.COBWEB_HIT); + public static final CompatSoundEvent BLOCK_COBWEB_FALL = new CompatSoundEvent(SoundEvents.COBWEB_FALL); + public static final CompatSoundEvent ENTITY_COD_AMBIENT = new CompatSoundEvent(SoundEvents.COD_AMBIENT); + public static final CompatSoundEvent ENTITY_COD_DEATH = new CompatSoundEvent(SoundEvents.COD_DEATH); + public static final CompatSoundEvent ENTITY_COD_FLOP = new CompatSoundEvent(SoundEvents.COD_FLOP); + public static final CompatSoundEvent ENTITY_COD_HURT = new CompatSoundEvent(SoundEvents.COD_HURT); + public static final CompatSoundEvent BLOCK_COMPARATOR_CLICK = new CompatSoundEvent(SoundEvents.COMPARATOR_CLICK); + public static final CompatSoundEvent BLOCK_COMPOSTER_EMPTY = new CompatSoundEvent(SoundEvents.COMPOSTER_EMPTY); + public static final CompatSoundEvent BLOCK_COMPOSTER_FILL = new CompatSoundEvent(SoundEvents.COMPOSTER_FILL); + public static final CompatSoundEvent BLOCK_COMPOSTER_FILL_SUCCESS = new CompatSoundEvent(SoundEvents.COMPOSTER_FILL_SUCCESS); + public static final CompatSoundEvent BLOCK_COMPOSTER_READY = new CompatSoundEvent(SoundEvents.COMPOSTER_READY); + public static final CompatSoundEvent BLOCK_CONDUIT_ACTIVATE = new CompatSoundEvent(SoundEvents.CONDUIT_ACTIVATE); + public static final CompatSoundEvent BLOCK_CONDUIT_AMBIENT = new CompatSoundEvent(SoundEvents.CONDUIT_AMBIENT); + public static final CompatSoundEvent BLOCK_CONDUIT_AMBIENT_SHORT = new CompatSoundEvent(SoundEvents.CONDUIT_AMBIENT_SHORT); + public static final CompatSoundEvent BLOCK_CONDUIT_ATTACK_TARGET = new CompatSoundEvent(SoundEvents.CONDUIT_ATTACK_TARGET); + public static final CompatSoundEvent BLOCK_CONDUIT_DEACTIVATE = new CompatSoundEvent(SoundEvents.CONDUIT_DEACTIVATE); + public static final CompatSoundEvent BLOCK_COPPER_BULB_BREAK = new CompatSoundEvent(SoundEvents.COPPER_BULB_BREAK); + public static final CompatSoundEvent BLOCK_COPPER_BULB_STEP = new CompatSoundEvent(SoundEvents.COPPER_BULB_STEP); + public static final CompatSoundEvent BLOCK_COPPER_BULB_PLACE = new CompatSoundEvent(SoundEvents.COPPER_BULB_PLACE); + public static final CompatSoundEvent BLOCK_COPPER_BULB_HIT = new CompatSoundEvent(SoundEvents.COPPER_BULB_HIT); + public static final CompatSoundEvent BLOCK_COPPER_BULB_FALL = new CompatSoundEvent(SoundEvents.COPPER_BULB_FALL); + public static final CompatSoundEvent BLOCK_COPPER_BULB_TURN_ON = new CompatSoundEvent(SoundEvents.COPPER_BULB_TURN_ON); + public static final CompatSoundEvent BLOCK_COPPER_BULB_TURN_OFF = new CompatSoundEvent(SoundEvents.COPPER_BULB_TURN_OFF); + public static final CompatSoundEvent BLOCK_COPPER_BREAK = new CompatSoundEvent(SoundEvents.COPPER_BREAK); + public static final CompatSoundEvent BLOCK_COPPER_STEP = new CompatSoundEvent(SoundEvents.COPPER_STEP); + public static final CompatSoundEvent BLOCK_COPPER_PLACE = new CompatSoundEvent(SoundEvents.COPPER_PLACE); + public static final CompatSoundEvent BLOCK_COPPER_HIT = new CompatSoundEvent(SoundEvents.COPPER_HIT); + public static final CompatSoundEvent BLOCK_COPPER_FALL = new CompatSoundEvent(SoundEvents.COPPER_FALL); + public static final CompatSoundEvent BLOCK_COPPER_DOOR_CLOSE = new CompatSoundEvent(SoundEvents.COPPER_DOOR_CLOSE); + public static final CompatSoundEvent BLOCK_COPPER_DOOR_OPEN = new CompatSoundEvent(SoundEvents.COPPER_DOOR_OPEN); + public static final CompatSoundEvent BLOCK_COPPER_GRATE_BREAK = new CompatSoundEvent(SoundEvents.COPPER_GRATE_BREAK); + public static final CompatSoundEvent BLOCK_COPPER_GRATE_STEP = new CompatSoundEvent(SoundEvents.COPPER_GRATE_STEP); + public static final CompatSoundEvent BLOCK_COPPER_GRATE_PLACE = new CompatSoundEvent(SoundEvents.COPPER_GRATE_PLACE); + public static final CompatSoundEvent BLOCK_COPPER_GRATE_HIT = new CompatSoundEvent(SoundEvents.COPPER_GRATE_HIT); + public static final CompatSoundEvent BLOCK_COPPER_GRATE_FALL = new CompatSoundEvent(SoundEvents.COPPER_GRATE_FALL); + public static final CompatSoundEvent BLOCK_COPPER_TRAPDOOR_CLOSE = new CompatSoundEvent(SoundEvents.COPPER_TRAPDOOR_CLOSE); + public static final CompatSoundEvent BLOCK_COPPER_TRAPDOOR_OPEN = new CompatSoundEvent(SoundEvents.COPPER_TRAPDOOR_OPEN); + public static final CompatSoundEvent BLOCK_CORAL_BLOCK_BREAK = new CompatSoundEvent(SoundEvents.CORAL_BLOCK_BREAK); + public static final CompatSoundEvent BLOCK_CORAL_BLOCK_FALL = new CompatSoundEvent(SoundEvents.CORAL_BLOCK_FALL); + public static final CompatSoundEvent BLOCK_CORAL_BLOCK_HIT = new CompatSoundEvent(SoundEvents.CORAL_BLOCK_HIT); + public static final CompatSoundEvent BLOCK_CORAL_BLOCK_PLACE = new CompatSoundEvent(SoundEvents.CORAL_BLOCK_PLACE); + public static final CompatSoundEvent BLOCK_CORAL_BLOCK_STEP = new CompatSoundEvent(SoundEvents.CORAL_BLOCK_STEP); + public static final CompatSoundEvent ENTITY_COW_AMBIENT = new CompatSoundEvent(SoundEvents.COW_SOUNDS.get(CowSoundVariants.SoundSet.CLASSIC).ambientSound()); + public static final CompatSoundEvent ENTITY_COW_DEATH = new CompatSoundEvent(SoundEvents.COW_SOUNDS.get(CowSoundVariants.SoundSet.CLASSIC).deathSound()); + public static final CompatSoundEvent ENTITY_COW_HURT = new CompatSoundEvent(SoundEvents.COW_SOUNDS.get(CowSoundVariants.SoundSet.CLASSIC).hurtSound()); + public static final CompatSoundEvent ENTITY_COW_MILK = new CompatSoundEvent(SoundEvents.COW_MILK); + public static final CompatSoundEvent ENTITY_COW_STEP = new CompatSoundEvent(SoundEvents.COW_SOUNDS.get(CowSoundVariants.SoundSet.CLASSIC).stepSound()); + public static final CompatSoundEvent BLOCK_CRAFTER_CRAFT = new CompatSoundEvent(SoundEvents.CRAFTER_CRAFT); + public static final CompatSoundEvent BLOCK_CRAFTER_FAIL = new CompatSoundEvent(SoundEvents.CRAFTER_FAIL); + public static final CompatSoundEvent ENTITY_CREEPER_DEATH = new CompatSoundEvent(SoundEvents.CREEPER_DEATH); + public static final CompatSoundEvent ENTITY_CREEPER_HURT = new CompatSoundEvent(SoundEvents.CREEPER_HURT); + public static final CompatSoundEvent ENTITY_CREEPER_PRIMED = new CompatSoundEvent(SoundEvents.CREEPER_PRIMED); + public static final CompatSoundEvent BLOCK_CROP_BREAK = new CompatSoundEvent(SoundEvents.CROP_BREAK); + public static final CompatSoundEvent ITEM_CROP_PLANT = new CompatSoundEvent(SoundEvents.CROP_PLANTED); + public static final CompatSoundEvent ITEM_CROSSBOW_HIT = new CompatSoundEvent(SoundEvents.CROSSBOW_HIT); + public static final CompatSoundEvent ITEM_CROSSBOW_LOADING_END = new CompatSoundEvent(SoundEvents.CROSSBOW_LOADING_END); + public static final CompatSoundEvent ITEM_CROSSBOW_LOADING_MIDDLE = new CompatSoundEvent(SoundEvents.CROSSBOW_LOADING_MIDDLE); + public static final CompatSoundEvent ITEM_CROSSBOW_LOADING_START = new CompatSoundEvent(SoundEvents.CROSSBOW_LOADING_START); + public static final CompatSoundEvent ITEM_CROSSBOW_QUICK_CHARGE_1 = new CompatSoundEvent(SoundEvents.CROSSBOW_QUICK_CHARGE_1); + public static final CompatSoundEvent ITEM_CROSSBOW_QUICK_CHARGE_2 = new CompatSoundEvent(SoundEvents.CROSSBOW_QUICK_CHARGE_2); + public static final CompatSoundEvent ITEM_CROSSBOW_QUICK_CHARGE_3 = new CompatSoundEvent(SoundEvents.CROSSBOW_QUICK_CHARGE_3); + public static final CompatSoundEvent ITEM_CROSSBOW_SHOOT = new CompatSoundEvent(SoundEvents.CROSSBOW_SHOOT); + public static final CompatSoundEvent BLOCK_DECORATED_POT_BREAK = new CompatSoundEvent(SoundEvents.DECORATED_POT_BREAK); + public static final CompatSoundEvent BLOCK_DECORATED_POT_FALL = new CompatSoundEvent(SoundEvents.DECORATED_POT_FALL); + public static final CompatSoundEvent BLOCK_DECORATED_POT_HIT = new CompatSoundEvent(SoundEvents.DECORATED_POT_HIT); + public static final CompatSoundEvent BLOCK_DECORATED_POT_INSERT = new CompatSoundEvent(SoundEvents.DECORATED_POT_INSERT); + public static final CompatSoundEvent BLOCK_DECORATED_POT_INSERT_FAIL = new CompatSoundEvent(SoundEvents.DECORATED_POT_INSERT_FAIL); + public static final CompatSoundEvent BLOCK_DECORATED_POT_STEP = new CompatSoundEvent(SoundEvents.DECORATED_POT_STEP); + public static final CompatSoundEvent BLOCK_DECORATED_POT_PLACE = new CompatSoundEvent(SoundEvents.DECORATED_POT_PLACE); + public static final CompatSoundEvent BLOCK_DECORATED_POT_SHATTER = new CompatSoundEvent(SoundEvents.DECORATED_POT_SHATTER); + public static final CompatSoundEvent BLOCK_DEEPSLATE_BRICKS_BREAK = new CompatSoundEvent(SoundEvents.DEEPSLATE_BRICKS_BREAK); + public static final CompatSoundEvent BLOCK_DEEPSLATE_BRICKS_FALL = new CompatSoundEvent(SoundEvents.DEEPSLATE_BRICKS_FALL); + public static final CompatSoundEvent BLOCK_DEEPSLATE_BRICKS_HIT = new CompatSoundEvent(SoundEvents.DEEPSLATE_BRICKS_HIT); + public static final CompatSoundEvent BLOCK_DEEPSLATE_BRICKS_PLACE = new CompatSoundEvent(SoundEvents.DEEPSLATE_BRICKS_PLACE); + public static final CompatSoundEvent BLOCK_DEEPSLATE_BRICKS_STEP = new CompatSoundEvent(SoundEvents.DEEPSLATE_BRICKS_STEP); + public static final CompatSoundEvent BLOCK_DEEPSLATE_BREAK = new CompatSoundEvent(SoundEvents.DEEPSLATE_BREAK); + public static final CompatSoundEvent BLOCK_DEEPSLATE_FALL = new CompatSoundEvent(SoundEvents.DEEPSLATE_FALL); + public static final CompatSoundEvent BLOCK_DEEPSLATE_HIT = new CompatSoundEvent(SoundEvents.DEEPSLATE_HIT); + public static final CompatSoundEvent BLOCK_DEEPSLATE_PLACE = new CompatSoundEvent(SoundEvents.DEEPSLATE_PLACE); + public static final CompatSoundEvent BLOCK_DEEPSLATE_STEP = new CompatSoundEvent(SoundEvents.DEEPSLATE_STEP); + public static final CompatSoundEvent BLOCK_DEEPSLATE_TILES_BREAK = new CompatSoundEvent(SoundEvents.DEEPSLATE_TILES_BREAK); + public static final CompatSoundEvent BLOCK_DEEPSLATE_TILES_FALL = new CompatSoundEvent(SoundEvents.DEEPSLATE_TILES_FALL); + public static final CompatSoundEvent BLOCK_DEEPSLATE_TILES_HIT = new CompatSoundEvent(SoundEvents.DEEPSLATE_TILES_HIT); + public static final CompatSoundEvent BLOCK_DEEPSLATE_TILES_PLACE = new CompatSoundEvent(SoundEvents.DEEPSLATE_TILES_PLACE); + public static final CompatSoundEvent BLOCK_DEEPSLATE_TILES_STEP = new CompatSoundEvent(SoundEvents.DEEPSLATE_TILES_STEP); + public static final CompatSoundEvent BLOCK_DISPENSER_DISPENSE = new CompatSoundEvent(SoundEvents.DISPENSER_DISPENSE); + public static final CompatSoundEvent BLOCK_DISPENSER_FAIL = new CompatSoundEvent(SoundEvents.DISPENSER_FAIL); + public static final CompatSoundEvent BLOCK_DISPENSER_LAUNCH = new CompatSoundEvent(SoundEvents.DISPENSER_LAUNCH); + public static final CompatSoundEvent ENTITY_DOLPHIN_AMBIENT = new CompatSoundEvent(SoundEvents.DOLPHIN_AMBIENT); + public static final CompatSoundEvent ENTITY_DOLPHIN_AMBIENT_WATER = new CompatSoundEvent(SoundEvents.DOLPHIN_AMBIENT_WATER); + public static final CompatSoundEvent ENTITY_DOLPHIN_ATTACK = new CompatSoundEvent(SoundEvents.DOLPHIN_ATTACK); + public static final CompatSoundEvent ENTITY_DOLPHIN_DEATH = new CompatSoundEvent(SoundEvents.DOLPHIN_DEATH); + public static final CompatSoundEvent ENTITY_DOLPHIN_EAT = new CompatSoundEvent(SoundEvents.DOLPHIN_EAT); + public static final CompatSoundEvent ENTITY_DOLPHIN_HURT = new CompatSoundEvent(SoundEvents.DOLPHIN_HURT); + public static final CompatSoundEvent ENTITY_DOLPHIN_JUMP = new CompatSoundEvent(SoundEvents.DOLPHIN_JUMP); + public static final CompatSoundEvent ENTITY_DOLPHIN_PLAY = new CompatSoundEvent(SoundEvents.DOLPHIN_PLAY); + public static final CompatSoundEvent ENTITY_DOLPHIN_SPLASH = new CompatSoundEvent(SoundEvents.DOLPHIN_SPLASH); + public static final CompatSoundEvent ENTITY_DOLPHIN_SWIM = new CompatSoundEvent(SoundEvents.DOLPHIN_SWIM); + public static final CompatSoundEvent ENTITY_DONKEY_AMBIENT = new CompatSoundEvent(SoundEvents.DONKEY_AMBIENT); + public static final CompatSoundEvent ENTITY_DONKEY_ANGRY = new CompatSoundEvent(SoundEvents.DONKEY_ANGRY); + public static final CompatSoundEvent ENTITY_DONKEY_CHEST = new CompatSoundEvent(SoundEvents.DONKEY_CHEST); + public static final CompatSoundEvent ENTITY_DONKEY_DEATH = new CompatSoundEvent(SoundEvents.DONKEY_DEATH); + public static final CompatSoundEvent ENTITY_DONKEY_EAT = new CompatSoundEvent(SoundEvents.DONKEY_EAT); + public static final CompatSoundEvent ENTITY_DONKEY_HURT = new CompatSoundEvent(SoundEvents.DONKEY_HURT); + public static final CompatSoundEvent ENTITY_DONKEY_JUMP = new CompatSoundEvent(SoundEvents.DONKEY_JUMP); + public static final CompatSoundEvent BLOCK_DRIPSTONE_BLOCK_BREAK = new CompatSoundEvent(SoundEvents.DRIPSTONE_BLOCK_BREAK); + public static final CompatSoundEvent BLOCK_DRIPSTONE_BLOCK_STEP = new CompatSoundEvent(SoundEvents.DRIPSTONE_BLOCK_STEP); + public static final CompatSoundEvent BLOCK_DRIPSTONE_BLOCK_PLACE = new CompatSoundEvent(SoundEvents.DRIPSTONE_BLOCK_PLACE); + public static final CompatSoundEvent BLOCK_DRIPSTONE_BLOCK_HIT = new CompatSoundEvent(SoundEvents.DRIPSTONE_BLOCK_HIT); + public static final CompatSoundEvent BLOCK_DRIPSTONE_BLOCK_FALL = new CompatSoundEvent(SoundEvents.DRIPSTONE_BLOCK_FALL); + public static final CompatSoundEvent BLOCK_POINTED_DRIPSTONE_BREAK = new CompatSoundEvent(SoundEvents.POINTED_DRIPSTONE_BREAK); + public static final CompatSoundEvent BLOCK_POINTED_DRIPSTONE_STEP = new CompatSoundEvent(SoundEvents.POINTED_DRIPSTONE_STEP); + public static final CompatSoundEvent BLOCK_POINTED_DRIPSTONE_PLACE = new CompatSoundEvent(SoundEvents.POINTED_DRIPSTONE_PLACE); + public static final CompatSoundEvent BLOCK_POINTED_DRIPSTONE_HIT = new CompatSoundEvent(SoundEvents.POINTED_DRIPSTONE_HIT); + public static final CompatSoundEvent BLOCK_POINTED_DRIPSTONE_FALL = new CompatSoundEvent(SoundEvents.POINTED_DRIPSTONE_FALL); + public static final CompatSoundEvent BLOCK_POINTED_DRIPSTONE_LAND = new CompatSoundEvent(SoundEvents.POINTED_DRIPSTONE_LAND); + public static final CompatSoundEvent BLOCK_POINTED_DRIPSTONE_DRIP_LAVA = new CompatSoundEvent(SoundEvents.POINTED_DRIPSTONE_DRIP_LAVA); + public static final CompatSoundEvent BLOCK_POINTED_DRIPSTONE_DRIP_WATER = new CompatSoundEvent(SoundEvents.POINTED_DRIPSTONE_DRIP_WATER); + public static final CompatSoundEvent BLOCK_POINTED_DRIPSTONE_DRIP_LAVA_INTO_CAULDRON = new CompatSoundEvent(SoundEvents.POINTED_DRIPSTONE_DRIP_LAVA_INTO_CAULDRON); + public static final CompatSoundEvent BLOCK_POINTED_DRIPSTONE_DRIP_WATER_INTO_CAULDRON = new CompatSoundEvent(SoundEvents.POINTED_DRIPSTONE_DRIP_WATER_INTO_CAULDRON); + public static final CompatSoundEvent BLOCK_BIG_DRIPLEAF_TILT_DOWN = new CompatSoundEvent(SoundEvents.BIG_DRIPLEAF_TILT_DOWN); + public static final CompatSoundEvent BLOCK_BIG_DRIPLEAF_TILT_UP = new CompatSoundEvent(SoundEvents.BIG_DRIPLEAF_TILT_UP); + public static final CompatSoundEvent ENTITY_DROWNED_AMBIENT = new CompatSoundEvent(SoundEvents.DROWNED_AMBIENT); + public static final CompatSoundEvent ENTITY_DROWNED_AMBIENT_WATER = new CompatSoundEvent(SoundEvents.DROWNED_AMBIENT_WATER); + public static final CompatSoundEvent ENTITY_DROWNED_DEATH = new CompatSoundEvent(SoundEvents.DROWNED_DEATH); + public static final CompatSoundEvent ENTITY_DROWNED_DEATH_WATER = new CompatSoundEvent(SoundEvents.DROWNED_DEATH_WATER); + public static final CompatSoundEvent ENTITY_DROWNED_HURT = new CompatSoundEvent(SoundEvents.DROWNED_HURT); + public static final CompatSoundEvent ENTITY_DROWNED_HURT_WATER = new CompatSoundEvent(SoundEvents.DROWNED_HURT_WATER); + public static final CompatSoundEvent ENTITY_DROWNED_SHOOT = new CompatSoundEvent(SoundEvents.DROWNED_SHOOT); + public static final CompatSoundEvent ENTITY_DROWNED_STEP = new CompatSoundEvent(SoundEvents.DROWNED_STEP); + public static final CompatSoundEvent ENTITY_DROWNED_SWIM = new CompatSoundEvent(SoundEvents.DROWNED_SWIM); + public static final CompatSoundEvent ITEM_DYE_USE = new CompatSoundEvent(SoundEvents.DYE_USE); + public static final CompatSoundEvent ENTITY_EGG_THROW = new CompatSoundEvent(SoundEvents.EGG_THROW); + public static final CompatSoundEvent ENTITY_ELDER_GUARDIAN_AMBIENT = new CompatSoundEvent(SoundEvents.ELDER_GUARDIAN_AMBIENT); + public static final CompatSoundEvent ENTITY_ELDER_GUARDIAN_AMBIENT_LAND = new CompatSoundEvent(SoundEvents.ELDER_GUARDIAN_AMBIENT_LAND); + public static final CompatSoundEvent ENTITY_ELDER_GUARDIAN_CURSE = new CompatSoundEvent(SoundEvents.ELDER_GUARDIAN_CURSE); + public static final CompatSoundEvent ENTITY_ELDER_GUARDIAN_DEATH = new CompatSoundEvent(SoundEvents.ELDER_GUARDIAN_DEATH); + public static final CompatSoundEvent ENTITY_ELDER_GUARDIAN_DEATH_LAND = new CompatSoundEvent(SoundEvents.ELDER_GUARDIAN_DEATH_LAND); + public static final CompatSoundEvent ENTITY_ELDER_GUARDIAN_FLOP = new CompatSoundEvent(SoundEvents.ELDER_GUARDIAN_FLOP); + public static final CompatSoundEvent ENTITY_ELDER_GUARDIAN_HURT = new CompatSoundEvent(SoundEvents.ELDER_GUARDIAN_HURT); + public static final CompatSoundEvent ENTITY_ELDER_GUARDIAN_HURT_LAND = new CompatSoundEvent(SoundEvents.ELDER_GUARDIAN_HURT_LAND); + public static final CompatSoundEvent ITEM_ELYTRA_FLYING = new CompatSoundEvent(SoundEvents.ELYTRA_FLYING); + public static final CompatSoundEvent BLOCK_ENCHANTMENT_TABLE_USE = new CompatSoundEvent(SoundEvents.ENCHANTMENT_TABLE_USE); + public static final CompatSoundEvent BLOCK_ENDER_CHEST_CLOSE = new CompatSoundEvent(SoundEvents.ENDER_CHEST_CLOSE); + public static final CompatSoundEvent BLOCK_ENDER_CHEST_OPEN = new CompatSoundEvent(SoundEvents.ENDER_CHEST_OPEN); + public static final CompatSoundEvent ENTITY_ENDER_DRAGON_AMBIENT = new CompatSoundEvent(SoundEvents.ENDER_DRAGON_AMBIENT); + public static final CompatSoundEvent ENTITY_ENDER_DRAGON_DEATH = new CompatSoundEvent(SoundEvents.ENDER_DRAGON_DEATH); + public static final CompatSoundEvent ENTITY_DRAGON_FIREBALL_EXPLODE = new CompatSoundEvent(SoundEvents.DRAGON_FIREBALL_EXPLODE); + public static final CompatSoundEvent ENTITY_ENDER_DRAGON_FLAP = new CompatSoundEvent(SoundEvents.ENDER_DRAGON_FLAP); + public static final CompatSoundEvent ENTITY_ENDER_DRAGON_GROWL = new CompatSoundEvent(SoundEvents.ENDER_DRAGON_GROWL); + public static final CompatSoundEvent ENTITY_ENDER_DRAGON_HURT = new CompatSoundEvent(SoundEvents.ENDER_DRAGON_HURT); + public static final CompatSoundEvent ENTITY_ENDER_DRAGON_SHOOT = new CompatSoundEvent(SoundEvents.ENDER_DRAGON_SHOOT); + public static final CompatSoundEvent ENTITY_ENDER_EYE_DEATH = new CompatSoundEvent(SoundEvents.ENDER_EYE_DEATH); + public static final CompatSoundEvent ENTITY_ENDER_EYE_LAUNCH = new CompatSoundEvent(SoundEvents.ENDER_EYE_LAUNCH); + public static final CompatSoundEvent ENTITY_ENDERMAN_AMBIENT = new CompatSoundEvent(SoundEvents.ENDERMAN_AMBIENT); + public static final CompatSoundEvent ENTITY_ENDERMAN_DEATH = new CompatSoundEvent(SoundEvents.ENDERMAN_DEATH); + public static final CompatSoundEvent ENTITY_ENDERMAN_HURT = new CompatSoundEvent(SoundEvents.ENDERMAN_HURT); + public static final CompatSoundEvent ENTITY_ENDERMAN_SCREAM = new CompatSoundEvent(SoundEvents.ENDERMAN_SCREAM); + public static final CompatSoundEvent ENTITY_ENDERMAN_STARE = new CompatSoundEvent(SoundEvents.ENDERMAN_STARE); + public static final CompatSoundEvent ENTITY_ENDERMAN_TELEPORT = new CompatSoundEvent(SoundEvents.ENDERMAN_TELEPORT); + public static final CompatSoundEvent ENTITY_ENDERMITE_AMBIENT = new CompatSoundEvent(SoundEvents.ENDERMITE_AMBIENT); + public static final CompatSoundEvent ENTITY_ENDERMITE_DEATH = new CompatSoundEvent(SoundEvents.ENDERMITE_DEATH); + public static final CompatSoundEvent ENTITY_ENDERMITE_HURT = new CompatSoundEvent(SoundEvents.ENDERMITE_HURT); + public static final CompatSoundEvent ENTITY_ENDERMITE_STEP = new CompatSoundEvent(SoundEvents.ENDERMITE_STEP); + public static final CompatSoundEvent ENTITY_ENDER_PEARL_THROW = new CompatSoundEvent(SoundEvents.ENDER_PEARL_THROW); + public static final CompatSoundEvent BLOCK_END_GATEWAY_SPAWN = new CompatSoundEvent(SoundEvents.END_GATEWAY_SPAWN); + public static final CompatSoundEvent BLOCK_END_PORTAL_FRAME_FILL = new CompatSoundEvent(SoundEvents.END_PORTAL_FRAME_FILL); + public static final CompatSoundEvent BLOCK_END_PORTAL_SPAWN = new CompatSoundEvent(SoundEvents.END_PORTAL_SPAWN); + public static final CompatSoundEvent ENTITY_EVOKER_AMBIENT = new CompatSoundEvent(SoundEvents.EVOKER_AMBIENT); + public static final CompatSoundEvent ENTITY_EVOKER_CAST_SPELL = new CompatSoundEvent(SoundEvents.EVOKER_CAST_SPELL); + public static final CompatSoundEvent ENTITY_EVOKER_CELEBRATE = new CompatSoundEvent(SoundEvents.EVOKER_CELEBRATE); + public static final CompatSoundEvent ENTITY_EVOKER_DEATH = new CompatSoundEvent(SoundEvents.EVOKER_DEATH); + public static final CompatSoundEvent ENTITY_EVOKER_FANGS_ATTACK = new CompatSoundEvent(SoundEvents.EVOKER_FANGS_ATTACK); + public static final CompatSoundEvent ENTITY_EVOKER_HURT = new CompatSoundEvent(SoundEvents.EVOKER_HURT); + public static final CompatSoundEvent ENTITY_EVOKER_PREPARE_ATTACK = new CompatSoundEvent(SoundEvents.EVOKER_PREPARE_ATTACK); + public static final CompatSoundEvent ENTITY_EVOKER_PREPARE_SUMMON = new CompatSoundEvent(SoundEvents.EVOKER_PREPARE_SUMMON); + public static final CompatSoundEvent ENTITY_EVOKER_PREPARE_WOLOLO = new CompatSoundEvent(SoundEvents.EVOKER_PREPARE_WOLOLO); + public static final CompatSoundEvent ENTITY_EXPERIENCE_BOTTLE_THROW = new CompatSoundEvent(SoundEvents.EXPERIENCE_BOTTLE_THROW); + public static final CompatSoundEvent ENTITY_EXPERIENCE_ORB_PICKUP = new CompatSoundEvent(SoundEvents.EXPERIENCE_ORB_PICKUP); + public static final CompatSoundEvent BLOCK_FENCE_GATE_CLOSE = new CompatSoundEvent(SoundEvents.FENCE_GATE_CLOSE); + public static final CompatSoundEvent BLOCK_FENCE_GATE_OPEN = new CompatSoundEvent(SoundEvents.FENCE_GATE_OPEN); + public static final CompatSoundEvent ITEM_FIRECHARGE_USE = new CompatSoundEvent(SoundEvents.FIRECHARGE_USE); + public static final CompatSoundEvent ENTITY_FIREWORK_ROCKET_BLAST = new CompatSoundEvent(SoundEvents.FIREWORK_ROCKET_BLAST); + public static final CompatSoundEvent ENTITY_FIREWORK_ROCKET_BLAST_FAR = new CompatSoundEvent(SoundEvents.FIREWORK_ROCKET_BLAST_FAR); + public static final CompatSoundEvent ENTITY_FIREWORK_ROCKET_LARGE_BLAST = new CompatSoundEvent(SoundEvents.FIREWORK_ROCKET_LARGE_BLAST); + public static final CompatSoundEvent ENTITY_FIREWORK_ROCKET_LARGE_BLAST_FAR = new CompatSoundEvent(SoundEvents.FIREWORK_ROCKET_LARGE_BLAST_FAR); + public static final CompatSoundEvent ENTITY_FIREWORK_ROCKET_LAUNCH = new CompatSoundEvent(SoundEvents.FIREWORK_ROCKET_LAUNCH); + public static final CompatSoundEvent ENTITY_FIREWORK_ROCKET_SHOOT = new CompatSoundEvent(SoundEvents.FIREWORK_ROCKET_SHOOT); + public static final CompatSoundEvent ENTITY_FIREWORK_ROCKET_TWINKLE = new CompatSoundEvent(SoundEvents.FIREWORK_ROCKET_TWINKLE); + public static final CompatSoundEvent ENTITY_FIREWORK_ROCKET_TWINKLE_FAR = new CompatSoundEvent(SoundEvents.FIREWORK_ROCKET_TWINKLE_FAR); + public static final CompatSoundEvent BLOCK_FIRE_AMBIENT = new CompatSoundEvent(SoundEvents.FIRE_AMBIENT); + public static final CompatSoundEvent BLOCK_FIRE_EXTINGUISH = new CompatSoundEvent(SoundEvents.FIRE_EXTINGUISH); + public static final CompatSoundEvent ENTITY_FISH_SWIM = new CompatSoundEvent(SoundEvents.FISH_SWIM); + public static final CompatSoundEvent ENTITY_FISHING_BOBBER_RETRIEVE = new CompatSoundEvent(SoundEvents.FISHING_BOBBER_RETRIEVE); + public static final CompatSoundEvent ENTITY_FISHING_BOBBER_SPLASH = new CompatSoundEvent(SoundEvents.FISHING_BOBBER_SPLASH); + public static final CompatSoundEvent ENTITY_FISHING_BOBBER_THROW = new CompatSoundEvent(SoundEvents.FISHING_BOBBER_THROW); + public static final CompatSoundEvent ITEM_FLINTANDSTEEL_USE = new CompatSoundEvent(SoundEvents.FLINTANDSTEEL_USE); + public static final CompatSoundEvent BLOCK_FLOWERING_AZALEA_BREAK = new CompatSoundEvent(SoundEvents.FLOWERING_AZALEA_BREAK); + public static final CompatSoundEvent BLOCK_FLOWERING_AZALEA_FALL = new CompatSoundEvent(SoundEvents.FLOWERING_AZALEA_FALL); + public static final CompatSoundEvent BLOCK_FLOWERING_AZALEA_HIT = new CompatSoundEvent(SoundEvents.FLOWERING_AZALEA_HIT); + public static final CompatSoundEvent BLOCK_FLOWERING_AZALEA_PLACE = new CompatSoundEvent(SoundEvents.FLOWERING_AZALEA_PLACE); + public static final CompatSoundEvent BLOCK_FLOWERING_AZALEA_STEP = new CompatSoundEvent(SoundEvents.FLOWERING_AZALEA_STEP); + public static final CompatSoundEvent ENTITY_FOX_AGGRO = new CompatSoundEvent(SoundEvents.FOX_AGGRO); + public static final CompatSoundEvent ENTITY_FOX_AMBIENT = new CompatSoundEvent(SoundEvents.FOX_AMBIENT); + public static final CompatSoundEvent ENTITY_FOX_BITE = new CompatSoundEvent(SoundEvents.FOX_BITE); + public static final CompatSoundEvent ENTITY_FOX_DEATH = new CompatSoundEvent(SoundEvents.FOX_DEATH); + public static final CompatSoundEvent ENTITY_FOX_EAT = new CompatSoundEvent(SoundEvents.FOX_EAT); + public static final CompatSoundEvent ENTITY_FOX_HURT = new CompatSoundEvent(SoundEvents.FOX_HURT); + public static final CompatSoundEvent ENTITY_FOX_SCREECH = new CompatSoundEvent(SoundEvents.FOX_SCREECH); + public static final CompatSoundEvent ENTITY_FOX_SLEEP = new CompatSoundEvent(SoundEvents.FOX_SLEEP); + public static final CompatSoundEvent ENTITY_FOX_SNIFF = new CompatSoundEvent(SoundEvents.FOX_SNIFF); + public static final CompatSoundEvent ENTITY_FOX_SPIT = new CompatSoundEvent(SoundEvents.FOX_SPIT); + public static final CompatSoundEvent ENTITY_FOX_TELEPORT = new CompatSoundEvent(SoundEvents.FOX_TELEPORT); + public static final CompatSoundEvent BLOCK_SUSPICIOUS_SAND_BREAK = new CompatSoundEvent(SoundEvents.SUSPICIOUS_SAND_BREAK); + public static final CompatSoundEvent BLOCK_SUSPICIOUS_SAND_STEP = new CompatSoundEvent(SoundEvents.SUSPICIOUS_SAND_STEP); + public static final CompatSoundEvent BLOCK_SUSPICIOUS_SAND_PLACE = new CompatSoundEvent(SoundEvents.SUSPICIOUS_SAND_PLACE); + public static final CompatSoundEvent BLOCK_SUSPICIOUS_SAND_HIT = new CompatSoundEvent(SoundEvents.SUSPICIOUS_SAND_HIT); + public static final CompatSoundEvent BLOCK_SUSPICIOUS_SAND_FALL = new CompatSoundEvent(SoundEvents.SUSPICIOUS_SAND_FALL); + public static final CompatSoundEvent BLOCK_SUSPICIOUS_GRAVEL_BREAK = new CompatSoundEvent(SoundEvents.SUSPICIOUS_GRAVEL_BREAK); + public static final CompatSoundEvent BLOCK_SUSPICIOUS_GRAVEL_STEP = new CompatSoundEvent(SoundEvents.SUSPICIOUS_GRAVEL_STEP); + public static final CompatSoundEvent BLOCK_SUSPICIOUS_GRAVEL_PLACE = new CompatSoundEvent(SoundEvents.SUSPICIOUS_GRAVEL_PLACE); + public static final CompatSoundEvent BLOCK_SUSPICIOUS_GRAVEL_HIT = new CompatSoundEvent(SoundEvents.SUSPICIOUS_GRAVEL_HIT); + public static final CompatSoundEvent BLOCK_SUSPICIOUS_GRAVEL_FALL = new CompatSoundEvent(SoundEvents.SUSPICIOUS_GRAVEL_FALL); + public static final CompatSoundEvent BLOCK_FROGLIGHT_BREAK = new CompatSoundEvent(SoundEvents.FROGLIGHT_BREAK); + public static final CompatSoundEvent BLOCK_FROGLIGHT_FALL = new CompatSoundEvent(SoundEvents.FROGLIGHT_FALL); + public static final CompatSoundEvent BLOCK_FROGLIGHT_HIT = new CompatSoundEvent(SoundEvents.FROGLIGHT_HIT); + public static final CompatSoundEvent BLOCK_FROGLIGHT_PLACE = new CompatSoundEvent(SoundEvents.FROGLIGHT_PLACE); + public static final CompatSoundEvent BLOCK_FROGLIGHT_STEP = new CompatSoundEvent(SoundEvents.FROGLIGHT_STEP); + public static final CompatSoundEvent BLOCK_FROGSPAWN_STEP = new CompatSoundEvent(SoundEvents.FROGSPAWNSTEP); + public static final CompatSoundEvent BLOCK_FROGSPAWN_BREAK = new CompatSoundEvent(SoundEvents.FROGSPAWN_BREAK); + public static final CompatSoundEvent BLOCK_FROGSPAWN_FALL = new CompatSoundEvent(SoundEvents.FROGSPAWN_FALL); + public static final CompatSoundEvent BLOCK_FROGSPAWN_HATCH = new CompatSoundEvent(SoundEvents.FROGSPAWN_HATCH); + public static final CompatSoundEvent BLOCK_FROGSPAWN_HIT = new CompatSoundEvent(SoundEvents.FROGSPAWN_HIT); + public static final CompatSoundEvent BLOCK_FROGSPAWN_PLACE = new CompatSoundEvent(SoundEvents.FROGSPAWN_PLACE); + public static final CompatSoundEvent ENTITY_FROG_AMBIENT = new CompatSoundEvent(SoundEvents.FROG_AMBIENT); + public static final CompatSoundEvent ENTITY_FROG_DEATH = new CompatSoundEvent(SoundEvents.FROG_DEATH); + public static final CompatSoundEvent ENTITY_FROG_EAT = new CompatSoundEvent(SoundEvents.FROG_EAT); + public static final CompatSoundEvent ENTITY_FROG_HURT = new CompatSoundEvent(SoundEvents.FROG_HURT); + public static final CompatSoundEvent ENTITY_FROG_LAY_SPAWN = new CompatSoundEvent(SoundEvents.FROG_LAY_SPAWN); + public static final CompatSoundEvent ENTITY_FROG_LONG_JUMP = new CompatSoundEvent(SoundEvents.FROG_LONG_JUMP); + public static final CompatSoundEvent ENTITY_FROG_STEP = new CompatSoundEvent(SoundEvents.FROG_STEP); + public static final CompatSoundEvent ENTITY_FROG_TONGUE = new CompatSoundEvent(SoundEvents.FROG_TONGUE); + public static final CompatSoundEvent BLOCK_ROOTS_BREAK = new CompatSoundEvent(SoundEvents.ROOTS_BREAK); + public static final CompatSoundEvent BLOCK_ROOTS_STEP = new CompatSoundEvent(SoundEvents.ROOTS_STEP); + public static final CompatSoundEvent BLOCK_ROOTS_PLACE = new CompatSoundEvent(SoundEvents.ROOTS_PLACE); + public static final CompatSoundEvent BLOCK_ROOTS_HIT = new CompatSoundEvent(SoundEvents.ROOTS_HIT); + public static final CompatSoundEvent BLOCK_ROOTS_FALL = new CompatSoundEvent(SoundEvents.ROOTS_FALL); + public static final CompatSoundEvent BLOCK_FURNACE_FIRE_CRACKLE = new CompatSoundEvent(SoundEvents.FURNACE_FIRE_CRACKLE); + public static final CompatSoundEvent ENTITY_GENERIC_BIG_FALL = new CompatSoundEvent(SoundEvents.GENERIC_BIG_FALL); + public static final CompatSoundEvent ENTITY_GENERIC_BURN = new CompatSoundEvent(SoundEvents.GENERIC_BURN); + public static final CompatSoundEvent ENTITY_GENERIC_DEATH = new CompatSoundEvent(SoundEvents.GENERIC_DEATH); + public static final CompatSoundEvent ENTITY_GENERIC_DRINK = new CompatSoundEvent(SoundEvents.GENERIC_DRINK); + public static final CompatSoundEvent ENTITY_GENERIC_EAT = new CompatSoundEvent(SoundEvents.GENERIC_EAT); + public static final CompatSoundEvent ENTITY_GENERIC_EXPLODE = new CompatSoundEvent(SoundEvents.GENERIC_EXPLODE); + public static final CompatSoundEvent ENTITY_GENERIC_EXTINGUISH_FIRE = new CompatSoundEvent(SoundEvents.GENERIC_EXTINGUISH_FIRE); + public static final CompatSoundEvent ENTITY_GENERIC_HURT = new CompatSoundEvent(SoundEvents.GENERIC_HURT); + public static final CompatSoundEvent ENTITY_GENERIC_SMALL_FALL = new CompatSoundEvent(SoundEvents.GENERIC_SMALL_FALL); + public static final CompatSoundEvent ENTITY_GENERIC_SPLASH = new CompatSoundEvent(SoundEvents.GENERIC_SPLASH); + public static final CompatSoundEvent ENTITY_GENERIC_SWIM = new CompatSoundEvent(SoundEvents.GENERIC_SWIM); + public static final CompatSoundEvent ENTITY_GHAST_AMBIENT = new CompatSoundEvent(SoundEvents.GHAST_AMBIENT); + public static final CompatSoundEvent ENTITY_GHAST_DEATH = new CompatSoundEvent(SoundEvents.GHAST_DEATH); + public static final CompatSoundEvent ENTITY_GHAST_HURT = new CompatSoundEvent(SoundEvents.GHAST_HURT); + public static final CompatSoundEvent ENTITY_GHAST_SCREAM = new CompatSoundEvent(SoundEvents.GHAST_SCREAM); + public static final CompatSoundEvent ENTITY_GHAST_SHOOT = new CompatSoundEvent(SoundEvents.GHAST_SHOOT); + public static final CompatSoundEvent ENTITY_GHAST_WARN = new CompatSoundEvent(SoundEvents.GHAST_WARN); + public static final CompatSoundEvent BLOCK_GILDED_BLACKSTONE_BREAK = new CompatSoundEvent(SoundEvents.GILDED_BLACKSTONE_BREAK); + public static final CompatSoundEvent BLOCK_GILDED_BLACKSTONE_FALL = new CompatSoundEvent(SoundEvents.GILDED_BLACKSTONE_FALL); + public static final CompatSoundEvent BLOCK_GILDED_BLACKSTONE_HIT = new CompatSoundEvent(SoundEvents.GILDED_BLACKSTONE_HIT); + public static final CompatSoundEvent BLOCK_GILDED_BLACKSTONE_PLACE = new CompatSoundEvent(SoundEvents.GILDED_BLACKSTONE_PLACE); + public static final CompatSoundEvent BLOCK_GILDED_BLACKSTONE_STEP = new CompatSoundEvent(SoundEvents.GILDED_BLACKSTONE_STEP); + public static final CompatSoundEvent BLOCK_GLASS_BREAK = new CompatSoundEvent(SoundEvents.GLASS_BREAK); + public static final CompatSoundEvent BLOCK_GLASS_FALL = new CompatSoundEvent(SoundEvents.GLASS_FALL); + public static final CompatSoundEvent BLOCK_GLASS_HIT = new CompatSoundEvent(SoundEvents.GLASS_HIT); + public static final CompatSoundEvent BLOCK_GLASS_PLACE = new CompatSoundEvent(SoundEvents.GLASS_PLACE); + public static final CompatSoundEvent BLOCK_GLASS_STEP = new CompatSoundEvent(SoundEvents.GLASS_STEP); + public static final CompatSoundEvent ITEM_GLOW_INK_SAC_USE = new CompatSoundEvent(SoundEvents.GLOW_INK_SAC_USE); + public static final CompatSoundEvent ENTITY_GLOW_ITEM_FRAME_ADD_ITEM = new CompatSoundEvent(SoundEvents.GLOW_ITEM_FRAME_ADD_ITEM); + public static final CompatSoundEvent ENTITY_GLOW_ITEM_FRAME_BREAK = new CompatSoundEvent(SoundEvents.GLOW_ITEM_FRAME_BREAK); + public static final CompatSoundEvent ENTITY_GLOW_ITEM_FRAME_PLACE = new CompatSoundEvent(SoundEvents.GLOW_ITEM_FRAME_PLACE); + public static final CompatSoundEvent ENTITY_GLOW_ITEM_FRAME_REMOVE_ITEM = new CompatSoundEvent(SoundEvents.GLOW_ITEM_FRAME_REMOVE_ITEM); + public static final CompatSoundEvent ENTITY_GLOW_ITEM_FRAME_ROTATE_ITEM = new CompatSoundEvent(SoundEvents.GLOW_ITEM_FRAME_ROTATE_ITEM); + public static final CompatSoundEvent ENTITY_GLOW_SQUID_AMBIENT = new CompatSoundEvent(SoundEvents.GLOW_SQUID_AMBIENT); + public static final CompatSoundEvent ENTITY_GLOW_SQUID_DEATH = new CompatSoundEvent(SoundEvents.GLOW_SQUID_DEATH); + public static final CompatSoundEvent ENTITY_GLOW_SQUID_HURT = new CompatSoundEvent(SoundEvents.GLOW_SQUID_HURT); + public static final CompatSoundEvent ENTITY_GLOW_SQUID_SQUIRT = new CompatSoundEvent(SoundEvents.GLOW_SQUID_SQUIRT); + public static final CompatSoundEvent ENTITY_GOAT_AMBIENT = new CompatSoundEvent(SoundEvents.GOAT_AMBIENT); + public static final CompatSoundEvent ENTITY_GOAT_DEATH = new CompatSoundEvent(SoundEvents.GOAT_DEATH); + public static final CompatSoundEvent ENTITY_GOAT_EAT = new CompatSoundEvent(SoundEvents.GOAT_EAT); + public static final CompatSoundEvent ENTITY_GOAT_HURT = new CompatSoundEvent(SoundEvents.GOAT_HURT); + public static final CompatSoundEvent ENTITY_GOAT_LONG_JUMP = new CompatSoundEvent(SoundEvents.GOAT_LONG_JUMP); + public static final CompatSoundEvent ENTITY_GOAT_MILK = new CompatSoundEvent(SoundEvents.GOAT_MILK); + public static final CompatSoundEvent ENTITY_GOAT_PREPARE_RAM = new CompatSoundEvent(SoundEvents.GOAT_PREPARE_RAM); + public static final CompatSoundEvent ENTITY_GOAT_RAM_IMPACT = new CompatSoundEvent(SoundEvents.GOAT_RAM_IMPACT); + public static final CompatSoundEvent ENTITY_GOAT_HORN_BREAK = new CompatSoundEvent(SoundEvents.GOAT_HORN_BREAK); + public static final CompatSoundEvent ITEM_GOAT_HORN_PLAY = new CompatSoundEvent(SoundEvents.GOAT_STEP); + public static final CompatSoundEvent ENTITY_GOAT_SCREAMING_AMBIENT = new CompatSoundEvent(SoundEvents.GOAT_SCREAMING_AMBIENT); + public static final CompatSoundEvent ENTITY_GOAT_SCREAMING_DEATH = new CompatSoundEvent(SoundEvents.GOAT_SCREAMING_DEATH); + public static final CompatSoundEvent ENTITY_GOAT_SCREAMING_EAT = new CompatSoundEvent(SoundEvents.GOAT_SCREAMING_EAT); + public static final CompatSoundEvent ENTITY_GOAT_SCREAMING_HURT = new CompatSoundEvent(SoundEvents.GOAT_SCREAMING_HURT); + public static final CompatSoundEvent ENTITY_GOAT_SCREAMING_LONG_JUMP = new CompatSoundEvent(SoundEvents.GOAT_SCREAMING_LONG_JUMP); + public static final CompatSoundEvent ENTITY_GOAT_SCREAMING_MILK = new CompatSoundEvent(SoundEvents.GOAT_SCREAMING_MILK); + public static final CompatSoundEvent ENTITY_GOAT_SCREAMING_PREPARE_RAM = new CompatSoundEvent(SoundEvents.GOAT_SCREAMING_PREPARE_RAM); + public static final CompatSoundEvent ENTITY_GOAT_SCREAMING_RAM_IMPACT = new CompatSoundEvent(SoundEvents.GOAT_SCREAMING_RAM_IMPACT); + public static final CompatSoundEvent ENTITY_GOAT_SCREAMING_HORN_BREAK = new CompatSoundEvent(SoundEvents.GOAT_HORN_BREAK); + public static final CompatSoundEvent ENTITY_GOAT_STEP = new CompatSoundEvent(SoundEvents.GOAT_STEP); + public static final CompatSoundEvent BLOCK_GRASS_BREAK = new CompatSoundEvent(SoundEvents.GRASS_BREAK); + public static final CompatSoundEvent BLOCK_GRASS_FALL = new CompatSoundEvent(SoundEvents.GRASS_FALL); + public static final CompatSoundEvent BLOCK_GRASS_HIT = new CompatSoundEvent(SoundEvents.GRASS_HIT); + public static final CompatSoundEvent BLOCK_GRASS_PLACE = new CompatSoundEvent(SoundEvents.GRASS_PLACE); + public static final CompatSoundEvent BLOCK_GRASS_STEP = new CompatSoundEvent(SoundEvents.GRASS_STEP); + public static final CompatSoundEvent BLOCK_GRAVEL_BREAK = new CompatSoundEvent(SoundEvents.GRAVEL_BREAK); + public static final CompatSoundEvent BLOCK_GRAVEL_FALL = new CompatSoundEvent(SoundEvents.GRAVEL_FALL); + public static final CompatSoundEvent BLOCK_GRAVEL_HIT = new CompatSoundEvent(SoundEvents.GRAVEL_HIT); + public static final CompatSoundEvent BLOCK_GRAVEL_PLACE = new CompatSoundEvent(SoundEvents.GRAVEL_PLACE); + public static final CompatSoundEvent BLOCK_GRAVEL_STEP = new CompatSoundEvent(SoundEvents.GRAVEL_STEP); + public static final CompatSoundEvent BLOCK_GRINDSTONE_USE = new CompatSoundEvent(SoundEvents.GRINDSTONE_USE); + public static final CompatSoundEvent BLOCK_GROWING_PLANT_CROP = new CompatSoundEvent(SoundEvents.GROWING_PLANT_CROP); + public static final CompatSoundEvent ENTITY_GUARDIAN_AMBIENT = new CompatSoundEvent(SoundEvents.GUARDIAN_AMBIENT); + public static final CompatSoundEvent ENTITY_GUARDIAN_AMBIENT_LAND = new CompatSoundEvent(SoundEvents.GUARDIAN_AMBIENT_LAND); + public static final CompatSoundEvent ENTITY_GUARDIAN_ATTACK = new CompatSoundEvent(SoundEvents.GUARDIAN_ATTACK); + public static final CompatSoundEvent ENTITY_GUARDIAN_DEATH = new CompatSoundEvent(SoundEvents.GUARDIAN_DEATH); + public static final CompatSoundEvent ENTITY_GUARDIAN_DEATH_LAND = new CompatSoundEvent(SoundEvents.GUARDIAN_DEATH_LAND); + public static final CompatSoundEvent ENTITY_GUARDIAN_FLOP = new CompatSoundEvent(SoundEvents.GUARDIAN_FLOP); + public static final CompatSoundEvent ENTITY_GUARDIAN_HURT = new CompatSoundEvent(SoundEvents.GUARDIAN_HURT); + public static final CompatSoundEvent ENTITY_GUARDIAN_HURT_LAND = new CompatSoundEvent(SoundEvents.GUARDIAN_HURT_LAND); + public static final CompatSoundEvent BLOCK_HANGING_ROOTS_BREAK = new CompatSoundEvent(SoundEvents.HANGING_ROOTS_BREAK); + public static final CompatSoundEvent BLOCK_HANGING_ROOTS_FALL = new CompatSoundEvent(SoundEvents.HANGING_ROOTS_FALL); + public static final CompatSoundEvent BLOCK_HANGING_ROOTS_HIT = new CompatSoundEvent(SoundEvents.HANGING_ROOTS_HIT); + public static final CompatSoundEvent BLOCK_HANGING_ROOTS_PLACE = new CompatSoundEvent(SoundEvents.HANGING_ROOTS_PLACE); + public static final CompatSoundEvent BLOCK_HANGING_ROOTS_STEP = new CompatSoundEvent(SoundEvents.HANGING_ROOTS_STEP); + public static final CompatSoundEvent BLOCK_HANGING_SIGN_STEP = new CompatSoundEvent(SoundEvents.HANGING_SIGN_STEP); + public static final CompatSoundEvent BLOCK_HANGING_SIGN_BREAK = new CompatSoundEvent(SoundEvents.HANGING_SIGN_BREAK); + public static final CompatSoundEvent BLOCK_HANGING_SIGN_FALL = new CompatSoundEvent(SoundEvents.HANGING_SIGN_FALL); + public static final CompatSoundEvent BLOCK_HANGING_SIGN_HIT = new CompatSoundEvent(SoundEvents.HANGING_SIGN_HIT); + public static final CompatSoundEvent BLOCK_HANGING_SIGN_PLACE = new CompatSoundEvent(SoundEvents.HANGING_SIGN_PLACE); + public static final CompatSoundEvent BLOCK_HEAVY_CORE_BREAK = new CompatSoundEvent(SoundEvents.HEAVY_CORE_BREAK); + public static final CompatSoundEvent BLOCK_HEAVY_CORE_FALL = new CompatSoundEvent(SoundEvents.HEAVY_CORE_FALL); + public static final CompatSoundEvent BLOCK_HEAVY_CORE_HIT = new CompatSoundEvent(SoundEvents.HEAVY_CORE_HIT); + public static final CompatSoundEvent BLOCK_HEAVY_CORE_PLACE = new CompatSoundEvent(SoundEvents.HEAVY_CORE_PLACE); + public static final CompatSoundEvent BLOCK_HEAVY_CORE_STEP = new CompatSoundEvent(SoundEvents.HEAVY_CORE_STEP); + public static final CompatSoundEvent BLOCK_NETHER_WOOD_HANGING_SIGN_STEP = new CompatSoundEvent(SoundEvents.NETHER_WOOD_HANGING_SIGN_STEP); + public static final CompatSoundEvent BLOCK_NETHER_WOOD_HANGING_SIGN_BREAK = new CompatSoundEvent(SoundEvents.NETHER_WOOD_HANGING_SIGN_BREAK); + public static final CompatSoundEvent BLOCK_NETHER_WOOD_HANGING_SIGN_FALL = new CompatSoundEvent(SoundEvents.NETHER_WOOD_HANGING_SIGN_FALL); + public static final CompatSoundEvent BLOCK_NETHER_WOOD_HANGING_SIGN_HIT = new CompatSoundEvent(SoundEvents.NETHER_WOOD_HANGING_SIGN_HIT); + public static final CompatSoundEvent BLOCK_NETHER_WOOD_HANGING_SIGN_PLACE = new CompatSoundEvent(SoundEvents.NETHER_WOOD_HANGING_SIGN_PLACE); + public static final CompatSoundEvent BLOCK_BAMBOO_WOOD_HANGING_SIGN_STEP = new CompatSoundEvent(SoundEvents.BAMBOO_WOOD_HANGING_SIGN_STEP); + public static final CompatSoundEvent BLOCK_BAMBOO_WOOD_HANGING_SIGN_BREAK = new CompatSoundEvent(SoundEvents.BAMBOO_WOOD_HANGING_SIGN_BREAK); + public static final CompatSoundEvent BLOCK_BAMBOO_WOOD_HANGING_SIGN_FALL = new CompatSoundEvent(SoundEvents.BAMBOO_WOOD_HANGING_SIGN_FALL); + public static final CompatSoundEvent BLOCK_BAMBOO_WOOD_HANGING_SIGN_HIT = new CompatSoundEvent(SoundEvents.BAMBOO_WOOD_HANGING_SIGN_HIT); + public static final CompatSoundEvent BLOCK_BAMBOO_WOOD_HANGING_SIGN_PLACE = new CompatSoundEvent(SoundEvents.BAMBOO_WOOD_HANGING_SIGN_PLACE); + public static final CompatSoundEvent BLOCK_TRIAL_SPAWNER_BREAK = new CompatSoundEvent(SoundEvents.TRIAL_SPAWNER_BREAK); + public static final CompatSoundEvent BLOCK_TRIAL_SPAWNER_STEP = new CompatSoundEvent(SoundEvents.TRIAL_SPAWNER_STEP); + public static final CompatSoundEvent BLOCK_TRIAL_SPAWNER_PLACE = new CompatSoundEvent(SoundEvents.TRIAL_SPAWNER_PLACE); + public static final CompatSoundEvent BLOCK_TRIAL_SPAWNER_HIT = new CompatSoundEvent(SoundEvents.TRIAL_SPAWNER_HIT); + public static final CompatSoundEvent BLOCK_TRIAL_SPAWNER_FALL = new CompatSoundEvent(SoundEvents.TRIAL_SPAWNER_FALL); + public static final CompatSoundEvent BLOCK_TRIAL_SPAWNER_SPAWN_MOB = new CompatSoundEvent(SoundEvents.TRIAL_SPAWNER_SPAWN_MOB); + public static final CompatSoundEvent BLOCK_TRIAL_SPAWNER_ABOUT_TO_SPAWN_ITEM = new CompatSoundEvent(SoundEvents.TRIAL_SPAWNER_ABOUT_TO_SPAWN_ITEM); + public static final CompatSoundEvent BLOCK_TRIAL_SPAWNER_SPAWN_ITEM = new CompatSoundEvent(SoundEvents.TRIAL_SPAWNER_SPAWN_ITEM); + public static final CompatSoundEvent BLOCK_TRIAL_SPAWNER_SPAWN_ITEM_BEGIN = new CompatSoundEvent(SoundEvents.TRIAL_SPAWNER_SPAWN_ITEM_BEGIN); + public static final CompatSoundEvent BLOCK_TRIAL_SPAWNER_DETECT_PLAYER = new CompatSoundEvent(SoundEvents.TRIAL_SPAWNER_DETECT_PLAYER); + public static final CompatSoundEvent BLOCK_TRIAL_SPAWNER_OMINOUS_ACTIVATE = new CompatSoundEvent(SoundEvents.TRIAL_SPAWNER_OMINOUS_ACTIVATE); + public static final CompatSoundEvent BLOCK_TRIAL_SPAWNER_AMBIENT = new CompatSoundEvent(SoundEvents.TRIAL_SPAWNER_AMBIENT); + public static final CompatSoundEvent BLOCK_TRIAL_SPAWNER_AMBIENT_OMINOUS = new CompatSoundEvent(SoundEvents.TRIAL_SPAWNER_AMBIENT_OMINOUS); + public static final CompatSoundEvent BLOCK_TRIAL_SPAWNER_OPEN_SHUTTER = new CompatSoundEvent(SoundEvents.TRIAL_SPAWNER_OPEN_SHUTTER); + public static final CompatSoundEvent BLOCK_TRIAL_SPAWNER_CLOSE_SHUTTER = new CompatSoundEvent(SoundEvents.TRIAL_SPAWNER_CLOSE_SHUTTER); + public static final CompatSoundEvent BLOCK_TRIAL_SPAWNER_EJECT_ITEM = new CompatSoundEvent(SoundEvents.TRIAL_SPAWNER_EJECT_ITEM); + public static final CompatSoundEvent ITEM_HOE_TILL = new CompatSoundEvent(SoundEvents.HOE_TILL); + public static final CompatSoundEvent ENTITY_HOGLIN_AMBIENT = new CompatSoundEvent(SoundEvents.HOGLIN_AMBIENT); + public static final CompatSoundEvent ENTITY_HOGLIN_ANGRY = new CompatSoundEvent(SoundEvents.HOGLIN_ANGRY); + public static final CompatSoundEvent ENTITY_HOGLIN_ATTACK = new CompatSoundEvent(SoundEvents.HOGLIN_ATTACK); + public static final CompatSoundEvent ENTITY_HOGLIN_CONVERTED_TO_ZOMBIFIED = new CompatSoundEvent(SoundEvents.HOGLIN_CONVERTED_TO_ZOMBIFIED); + public static final CompatSoundEvent ENTITY_HOGLIN_DEATH = new CompatSoundEvent(SoundEvents.HOGLIN_DEATH); + public static final CompatSoundEvent ENTITY_HOGLIN_HURT = new CompatSoundEvent(SoundEvents.HOGLIN_HURT); + public static final CompatSoundEvent ENTITY_HOGLIN_RETREAT = new CompatSoundEvent(SoundEvents.HOGLIN_RETREAT); + public static final CompatSoundEvent ENTITY_HOGLIN_STEP = new CompatSoundEvent(SoundEvents.HOGLIN_STEP); + public static final CompatSoundEvent BLOCK_HONEY_BLOCK_BREAK = new CompatSoundEvent(SoundEvents.HONEY_BLOCK_BREAK); + public static final CompatSoundEvent BLOCK_HONEY_BLOCK_FALL = new CompatSoundEvent(SoundEvents.HONEY_BLOCK_FALL); + public static final CompatSoundEvent BLOCK_HONEY_BLOCK_HIT = new CompatSoundEvent(SoundEvents.HONEY_BLOCK_HIT); + public static final CompatSoundEvent BLOCK_HONEY_BLOCK_PLACE = new CompatSoundEvent(SoundEvents.HONEY_BLOCK_PLACE); + public static final CompatSoundEvent BLOCK_HONEY_BLOCK_SLIDE = new CompatSoundEvent(SoundEvents.HONEY_BLOCK_SLIDE); + public static final CompatSoundEvent BLOCK_HONEY_BLOCK_STEP = new CompatSoundEvent(SoundEvents.HONEY_BLOCK_STEP); + public static final CompatSoundEvent ITEM_HONEYCOMB_WAX_ON = new CompatSoundEvent(SoundEvents.HONEYCOMB_WAX_ON); + public static final CompatSoundEvent ITEM_HONEY_BOTTLE_DRINK = new CompatSoundEvent(SoundEvents.HONEY_DRINK); + public static final int GOAT_HORN_SOUNDS_COUNT = SoundEvents.GOAT_HORN_VARIANT_COUNT; + public static final ImmutableList GOAT_HORN_SOUNDS; + public static final CompatSoundEvent ENTITY_HORSE_AMBIENT = new CompatSoundEvent(SoundEvents.HORSE_AMBIENT); + public static final CompatSoundEvent ENTITY_HORSE_ANGRY = new CompatSoundEvent(SoundEvents.HORSE_ANGRY); + public static final CompatSoundEvent ENTITY_HORSE_ARMOR = new CompatSoundEvent(SoundEvents.HORSE_ARMOR); + public static final CompatSoundEvent ENTITY_HORSE_BREATHE = new CompatSoundEvent(SoundEvents.HORSE_BREATHE); + public static final CompatSoundEvent ENTITY_HORSE_DEATH = new CompatSoundEvent(SoundEvents.HORSE_DEATH); + public static final CompatSoundEvent ENTITY_HORSE_EAT = new CompatSoundEvent(SoundEvents.HORSE_EAT); + public static final CompatSoundEvent ENTITY_HORSE_GALLOP = new CompatSoundEvent(SoundEvents.HORSE_GALLOP); + public static final CompatSoundEvent ENTITY_HORSE_HURT = new CompatSoundEvent(SoundEvents.HORSE_HURT); + public static final CompatSoundEvent ENTITY_HORSE_JUMP = new CompatSoundEvent(SoundEvents.HORSE_JUMP); + public static final CompatSoundEvent ENTITY_HORSE_LAND = new CompatSoundEvent(SoundEvents.HORSE_LAND); + public static final CompatSoundEvent ENTITY_HORSE_SADDLE = new CompatSoundEvent(SoundEvents.HORSE_SADDLE); + public static final CompatSoundEvent ENTITY_HORSE_STEP = new CompatSoundEvent(SoundEvents.HORSE_STEP); + public static final CompatSoundEvent ENTITY_HORSE_STEP_WOOD = new CompatSoundEvent(SoundEvents.HORSE_STEP_WOOD); + public static final CompatSoundEvent ENTITY_HOSTILE_BIG_FALL = new CompatSoundEvent(SoundEvents.HOSTILE_BIG_FALL); + public static final CompatSoundEvent ENTITY_HOSTILE_DEATH = new CompatSoundEvent(SoundEvents.HOSTILE_DEATH); + public static final CompatSoundEvent ENTITY_HOSTILE_HURT = new CompatSoundEvent(SoundEvents.HOSTILE_HURT); + public static final CompatSoundEvent ENTITY_HOSTILE_SMALL_FALL = new CompatSoundEvent(SoundEvents.HOSTILE_SMALL_FALL); + public static final CompatSoundEvent ENTITY_HOSTILE_SPLASH = new CompatSoundEvent(SoundEvents.HOSTILE_SPLASH); + public static final CompatSoundEvent ENTITY_HOSTILE_SWIM = new CompatSoundEvent(SoundEvents.HOSTILE_SWIM); + public static final CompatSoundEvent ENTITY_HUSK_AMBIENT = new CompatSoundEvent(SoundEvents.HUSK_AMBIENT); + public static final CompatSoundEvent ENTITY_HUSK_CONVERTED_TO_ZOMBIE = new CompatSoundEvent(SoundEvents.HUSK_CONVERTED_TO_ZOMBIE); + public static final CompatSoundEvent ENTITY_HUSK_DEATH = new CompatSoundEvent(SoundEvents.HUSK_DEATH); + public static final CompatSoundEvent ENTITY_HUSK_HURT = new CompatSoundEvent(SoundEvents.HUSK_HURT); + public static final CompatSoundEvent ENTITY_HUSK_STEP = new CompatSoundEvent(SoundEvents.HUSK_STEP); + public static final CompatSoundEvent ENTITY_ILLUSIONER_AMBIENT = new CompatSoundEvent(SoundEvents.ILLUSIONER_AMBIENT); + public static final CompatSoundEvent ENTITY_ILLUSIONER_CAST_SPELL = new CompatSoundEvent(SoundEvents.ILLUSIONER_CAST_SPELL); + public static final CompatSoundEvent ENTITY_ILLUSIONER_DEATH = new CompatSoundEvent(SoundEvents.ILLUSIONER_DEATH); + public static final CompatSoundEvent ENTITY_ILLUSIONER_HURT = new CompatSoundEvent(SoundEvents.ILLUSIONER_HURT); + public static final CompatSoundEvent ENTITY_ILLUSIONER_MIRROR_MOVE = new CompatSoundEvent(SoundEvents.ILLUSIONER_MIRROR_MOVE); + public static final CompatSoundEvent ENTITY_ILLUSIONER_PREPARE_BLINDNESS = new CompatSoundEvent(SoundEvents.ILLUSIONER_PREPARE_BLINDNESS); + public static final CompatSoundEvent ENTITY_ILLUSIONER_PREPARE_MIRROR = new CompatSoundEvent(SoundEvents.ILLUSIONER_PREPARE_MIRROR); + public static final CompatSoundEvent ITEM_INK_SAC_USE = new CompatSoundEvent(SoundEvents.INK_SAC_USE); + public static final CompatSoundEvent BLOCK_IRON_DOOR_CLOSE = new CompatSoundEvent(SoundEvents.IRON_DOOR_CLOSE); + public static final CompatSoundEvent BLOCK_IRON_DOOR_OPEN = new CompatSoundEvent(SoundEvents.IRON_DOOR_OPEN); + public static final CompatSoundEvent ENTITY_IRON_GOLEM_ATTACK = new CompatSoundEvent(SoundEvents.IRON_GOLEM_ATTACK); + public static final CompatSoundEvent ENTITY_IRON_GOLEM_DAMAGE = new CompatSoundEvent(SoundEvents.IRON_GOLEM_DAMAGE); + public static final CompatSoundEvent ENTITY_IRON_GOLEM_DEATH = new CompatSoundEvent(SoundEvents.IRON_GOLEM_DEATH); + public static final CompatSoundEvent ENTITY_IRON_GOLEM_HURT = new CompatSoundEvent(SoundEvents.IRON_GOLEM_HURT); + public static final CompatSoundEvent ENTITY_IRON_GOLEM_REPAIR = new CompatSoundEvent(SoundEvents.IRON_GOLEM_REPAIR); + public static final CompatSoundEvent ENTITY_IRON_GOLEM_STEP = new CompatSoundEvent(SoundEvents.IRON_GOLEM_STEP); + public static final CompatSoundEvent BLOCK_IRON_TRAPDOOR_CLOSE = new CompatSoundEvent(SoundEvents.IRON_TRAPDOOR_CLOSE); + public static final CompatSoundEvent BLOCK_IRON_TRAPDOOR_OPEN = new CompatSoundEvent(SoundEvents.IRON_TRAPDOOR_OPEN); + public static final CompatSoundEvent ENTITY_ITEM_FRAME_ADD_ITEM = new CompatSoundEvent(SoundEvents.ITEM_FRAME_ADD_ITEM); + public static final CompatSoundEvent ENTITY_ITEM_FRAME_BREAK = new CompatSoundEvent(SoundEvents.ITEM_FRAME_BREAK); + public static final CompatSoundEvent ENTITY_ITEM_FRAME_PLACE = new CompatSoundEvent(SoundEvents.ITEM_FRAME_PLACE); + public static final CompatSoundEvent ENTITY_ITEM_FRAME_REMOVE_ITEM = new CompatSoundEvent(SoundEvents.ITEM_FRAME_REMOVE_ITEM); + public static final CompatSoundEvent ENTITY_ITEM_FRAME_ROTATE_ITEM = new CompatSoundEvent(SoundEvents.ITEM_FRAME_ROTATE_ITEM); + public static final CompatSoundEvent ENTITY_ITEM_BREAK = new CompatSoundEvent(SoundEvents.ITEM_BREAK); + public static final CompatSoundEvent ENTITY_ITEM_PICKUP = new CompatSoundEvent(SoundEvents.ITEM_PICKUP); + public static final CompatSoundEvent BLOCK_LADDER_BREAK = new CompatSoundEvent(SoundEvents.LADDER_BREAK); + public static final CompatSoundEvent BLOCK_LADDER_FALL = new CompatSoundEvent(SoundEvents.LADDER_FALL); + public static final CompatSoundEvent BLOCK_LADDER_HIT = new CompatSoundEvent(SoundEvents.LADDER_HIT); + public static final CompatSoundEvent BLOCK_LADDER_PLACE = new CompatSoundEvent(SoundEvents.LADDER_PLACE); + public static final CompatSoundEvent BLOCK_LADDER_STEP = new CompatSoundEvent(SoundEvents.LADDER_STEP); + public static final CompatSoundEvent BLOCK_LANTERN_BREAK = new CompatSoundEvent(SoundEvents.LANTERN_BREAK); + public static final CompatSoundEvent BLOCK_LANTERN_FALL = new CompatSoundEvent(SoundEvents.LANTERN_FALL); + public static final CompatSoundEvent BLOCK_LANTERN_HIT = new CompatSoundEvent(SoundEvents.LANTERN_HIT); + public static final CompatSoundEvent BLOCK_LANTERN_PLACE = new CompatSoundEvent(SoundEvents.LANTERN_PLACE); + public static final CompatSoundEvent BLOCK_LANTERN_STEP = new CompatSoundEvent(SoundEvents.LANTERN_STEP); + public static final CompatSoundEvent BLOCK_LARGE_AMETHYST_BUD_BREAK = new CompatSoundEvent(SoundEvents.LARGE_AMETHYST_BUD_BREAK); + public static final CompatSoundEvent BLOCK_LARGE_AMETHYST_BUD_PLACE = new CompatSoundEvent(SoundEvents.LARGE_AMETHYST_BUD_PLACE); + public static final CompatSoundEvent BLOCK_LAVA_AMBIENT = new CompatSoundEvent(SoundEvents.LAVA_AMBIENT); + public static final CompatSoundEvent BLOCK_LAVA_EXTINGUISH = new CompatSoundEvent(SoundEvents.LAVA_EXTINGUISH); + public static final CompatSoundEvent BLOCK_LAVA_POP = new CompatSoundEvent(SoundEvents.LAVA_POP); + public static final CompatSoundEvent ENTITY_LEASH_KNOT_BREAK = new CompatSoundEvent(SoundEvents.LEAD_BREAK); + public static final CompatSoundEvent ENTITY_LEASH_KNOT_PLACE = new CompatSoundEvent(SoundEvents.LEAD_TIED); + public static final CompatSoundEvent BLOCK_LEVER_CLICK = new CompatSoundEvent(SoundEvents.LEVER_CLICK); + public static final CompatSoundEvent ENTITY_LIGHTNING_BOLT_IMPACT = new CompatSoundEvent(SoundEvents.LIGHTNING_BOLT_IMPACT); + public static final CompatSoundEvent ENTITY_LIGHTNING_BOLT_THUNDER = new CompatSoundEvent(SoundEvents.LIGHTNING_BOLT_THUNDER); + public static final CompatSoundEvent ENTITY_LINGERING_POTION_THROW = new CompatSoundEvent(SoundEvents.LINGERING_POTION_THROW); + public static final CompatSoundEvent ENTITY_LLAMA_AMBIENT = new CompatSoundEvent(SoundEvents.LLAMA_AMBIENT); + public static final CompatSoundEvent ENTITY_LLAMA_ANGRY = new CompatSoundEvent(SoundEvents.LLAMA_ANGRY); + public static final CompatSoundEvent ENTITY_LLAMA_CHEST = new CompatSoundEvent(SoundEvents.LLAMA_CHEST); + public static final CompatSoundEvent ENTITY_LLAMA_DEATH = new CompatSoundEvent(SoundEvents.LLAMA_DEATH); + public static final CompatSoundEvent ENTITY_LLAMA_EAT = new CompatSoundEvent(SoundEvents.LLAMA_EAT); + public static final CompatSoundEvent ENTITY_LLAMA_HURT = new CompatSoundEvent(SoundEvents.LLAMA_HURT); + public static final CompatSoundEvent ENTITY_LLAMA_SPIT = new CompatSoundEvent(SoundEvents.LLAMA_SPIT); + public static final CompatSoundEvent ENTITY_LLAMA_STEP = new CompatSoundEvent(SoundEvents.LLAMA_STEP); + public static final CompatSoundEvent ENTITY_LLAMA_SWAG = new CompatSoundEvent(SoundEvents.LLAMA_SWAG); + public static final CompatSoundEvent ENTITY_MAGMA_CUBE_DEATH_SMALL = new CompatSoundEvent(SoundEvents.MAGMA_CUBE_DEATH_SMALL); + public static final CompatSoundEvent BLOCK_LODESTONE_BREAK = new CompatSoundEvent(SoundEvents.LODESTONE_BREAK); + public static final CompatSoundEvent BLOCK_LODESTONE_STEP = new CompatSoundEvent(SoundEvents.LODESTONE_STEP); + public static final CompatSoundEvent BLOCK_LODESTONE_PLACE = new CompatSoundEvent(SoundEvents.LODESTONE_PLACE); + public static final CompatSoundEvent BLOCK_LODESTONE_HIT = new CompatSoundEvent(SoundEvents.LODESTONE_HIT); + public static final CompatSoundEvent BLOCK_LODESTONE_FALL = new CompatSoundEvent(SoundEvents.LODESTONE_FALL); + public static final CompatSoundEvent ITEM_LODESTONE_COMPASS_LOCK = new CompatSoundEvent(SoundEvents.LODESTONE_COMPASS_LOCK); + public static final CompatSoundEvent ITEM_MACE_SMASH_AIR = new CompatSoundEvent(SoundEvents.MACE_SMASH_AIR); + public static final CompatSoundEvent ITEM_MACE_SMASH_GROUND = new CompatSoundEvent(SoundEvents.MACE_SMASH_GROUND); + public static final CompatSoundEvent ITEM_MACE_SMASH_GROUND_HEAVY = new CompatSoundEvent(SoundEvents.MACE_SMASH_GROUND_HEAVY); + public static final CompatSoundEvent ENTITY_MAGMA_CUBE_DEATH = new CompatSoundEvent(SoundEvents.MAGMA_CUBE_DEATH); + public static final CompatSoundEvent ENTITY_MAGMA_CUBE_HURT = new CompatSoundEvent(SoundEvents.MAGMA_CUBE_HURT); + public static final CompatSoundEvent ENTITY_MAGMA_CUBE_HURT_SMALL = new CompatSoundEvent(SoundEvents.MAGMA_CUBE_HURT_SMALL); + public static final CompatSoundEvent ENTITY_MAGMA_CUBE_JUMP = new CompatSoundEvent(SoundEvents.MAGMA_CUBE_JUMP); + public static final CompatSoundEvent ENTITY_MAGMA_CUBE_SQUISH = new CompatSoundEvent(SoundEvents.MAGMA_CUBE_SQUISH); + public static final CompatSoundEvent ENTITY_MAGMA_CUBE_SQUISH_SMALL = new CompatSoundEvent(SoundEvents.MAGMA_CUBE_SQUISH_SMALL); + public static final CompatSoundEvent BLOCK_MANGROVE_ROOTS_BREAK = new CompatSoundEvent(SoundEvents.MANGROVE_ROOTS_BREAK); + public static final CompatSoundEvent BLOCK_MANGROVE_ROOTS_FALL = new CompatSoundEvent(SoundEvents.MANGROVE_ROOTS_FALL); + public static final CompatSoundEvent BLOCK_MANGROVE_ROOTS_HIT = new CompatSoundEvent(SoundEvents.MANGROVE_ROOTS_HIT); + public static final CompatSoundEvent BLOCK_MANGROVE_ROOTS_PLACE = new CompatSoundEvent(SoundEvents.MANGROVE_ROOTS_PLACE); + public static final CompatSoundEvent BLOCK_MANGROVE_ROOTS_STEP = new CompatSoundEvent(SoundEvents.MANGROVE_ROOTS_STEP); + public static final CompatSoundEvent BLOCK_MEDIUM_AMETHYST_BUD_BREAK = new CompatSoundEvent(SoundEvents.MEDIUM_AMETHYST_BUD_BREAK); + public static final CompatSoundEvent BLOCK_MEDIUM_AMETHYST_BUD_PLACE = new CompatSoundEvent(SoundEvents.MEDIUM_AMETHYST_BUD_PLACE); + public static final CompatSoundEvent BLOCK_METAL_BREAK = new CompatSoundEvent(SoundEvents.METAL_BREAK); + public static final CompatSoundEvent BLOCK_METAL_FALL = new CompatSoundEvent(SoundEvents.METAL_FALL); + public static final CompatSoundEvent BLOCK_METAL_HIT = new CompatSoundEvent(SoundEvents.METAL_HIT); + public static final CompatSoundEvent BLOCK_METAL_PLACE = new CompatSoundEvent(SoundEvents.METAL_PLACE); + public static final CompatSoundEvent BLOCK_METAL_PRESSURE_PLATE_CLICK_OFF = new CompatSoundEvent(SoundEvents.METAL_PRESSURE_PLATE_CLICK_OFF); + public static final CompatSoundEvent BLOCK_METAL_PRESSURE_PLATE_CLICK_ON = new CompatSoundEvent(SoundEvents.METAL_PRESSURE_PLATE_CLICK_ON); + public static final CompatSoundEvent BLOCK_METAL_STEP = new CompatSoundEvent(SoundEvents.METAL_STEP); + public static final CompatSoundEvent ENTITY_MINECART_INSIDE_UNDERWATER = new CompatSoundEvent(SoundEvents.MINECART_INSIDE_UNDERWATER); + public static final CompatSoundEvent ENTITY_MINECART_INSIDE = new CompatSoundEvent(SoundEvents.MINECART_INSIDE); + public static final CompatSoundEvent ENTITY_MINECART_RIDING = new CompatSoundEvent(SoundEvents.MINECART_RIDING); + public static final CompatSoundEvent ENTITY_MOOSHROOM_CONVERT = new CompatSoundEvent(SoundEvents.MOOSHROOM_CONVERT); + public static final CompatSoundEvent ENTITY_MOOSHROOM_EAT = new CompatSoundEvent(SoundEvents.MOOSHROOM_EAT); + public static final CompatSoundEvent ENTITY_MOOSHROOM_MILK = new CompatSoundEvent(SoundEvents.MOOSHROOM_MILK); + public static final CompatSoundEvent ENTITY_MOOSHROOM_SUSPICIOUS_MILK = new CompatSoundEvent(SoundEvents.MOOSHROOM_MILK_SUSPICIOUSLY); + public static final CompatSoundEvent ENTITY_MOOSHROOM_SHEAR = new CompatSoundEvent(SoundEvents.MOOSHROOM_SHEAR); + public static final CompatSoundEvent BLOCK_MOSS_CARPET_BREAK = new CompatSoundEvent(SoundEvents.MOSS_CARPET_BREAK); + public static final CompatSoundEvent BLOCK_MOSS_CARPET_FALL = new CompatSoundEvent(SoundEvents.MOSS_CARPET_FALL); + public static final CompatSoundEvent BLOCK_MOSS_CARPET_HIT = new CompatSoundEvent(SoundEvents.MOSS_CARPET_HIT); + public static final CompatSoundEvent BLOCK_MOSS_CARPET_PLACE = new CompatSoundEvent(SoundEvents.MOSS_CARPET_PLACE); + public static final CompatSoundEvent BLOCK_MOSS_CARPET_STEP = new CompatSoundEvent(SoundEvents.MOSS_CARPET_STEP); + public static final CompatSoundEvent BLOCK_PINK_PETALS_BREAK = new CompatSoundEvent(SoundEvents.PINK_PETALS_BREAK); + public static final CompatSoundEvent BLOCK_PINK_PETALS_FALL = new CompatSoundEvent(SoundEvents.PINK_PETALS_FALL); + public static final CompatSoundEvent BLOCK_PINK_PETALS_HIT = new CompatSoundEvent(SoundEvents.PINK_PETALS_HIT); + public static final CompatSoundEvent BLOCK_PINK_PETALS_PLACE = new CompatSoundEvent(SoundEvents.PINK_PETALS_PLACE); + public static final CompatSoundEvent BLOCK_PINK_PETALS_STEP = new CompatSoundEvent(SoundEvents.PINK_PETALS_STEP); + public static final CompatSoundEvent BLOCK_MOSS_BREAK = new CompatSoundEvent(SoundEvents.MOSS_BREAK); + public static final CompatSoundEvent BLOCK_MOSS_FALL = new CompatSoundEvent(SoundEvents.MOSS_FALL); + public static final CompatSoundEvent BLOCK_MOSS_HIT = new CompatSoundEvent(SoundEvents.MOSS_HIT); + public static final CompatSoundEvent BLOCK_MOSS_PLACE = new CompatSoundEvent(SoundEvents.MOSS_PLACE); + public static final CompatSoundEvent BLOCK_MOSS_STEP = new CompatSoundEvent(SoundEvents.MOSS_STEP); + public static final CompatSoundEvent BLOCK_MUD_BREAK = new CompatSoundEvent(SoundEvents.MUD_BREAK); + public static final CompatSoundEvent BLOCK_MUD_FALL = new CompatSoundEvent(SoundEvents.MUD_FALL); + public static final CompatSoundEvent BLOCK_MUD_HIT = new CompatSoundEvent(SoundEvents.MUD_HIT); + public static final CompatSoundEvent BLOCK_MUD_PLACE = new CompatSoundEvent(SoundEvents.MUD_PLACE); + public static final CompatSoundEvent BLOCK_MUD_STEP = new CompatSoundEvent(SoundEvents.MUD_STEP); + public static final CompatSoundEvent BLOCK_MUD_BRICKS_BREAK = new CompatSoundEvent(SoundEvents.MUD_BRICKS_BREAK); + public static final CompatSoundEvent BLOCK_MUD_BRICKS_FALL = new CompatSoundEvent(SoundEvents.MUD_BRICKS_FALL); + public static final CompatSoundEvent BLOCK_MUD_BRICKS_HIT = new CompatSoundEvent(SoundEvents.MUD_BRICKS_HIT); + public static final CompatSoundEvent BLOCK_MUD_BRICKS_PLACE = new CompatSoundEvent(SoundEvents.MUD_BRICKS_PLACE); + public static final CompatSoundEvent BLOCK_MUD_BRICKS_STEP = new CompatSoundEvent(SoundEvents.MUD_BRICKS_STEP); + public static final CompatSoundEvent BLOCK_MUDDY_MANGROVE_ROOTS_BREAK = new CompatSoundEvent(SoundEvents.MUDDY_MANGROVE_ROOTS_BREAK); + public static final CompatSoundEvent BLOCK_MUDDY_MANGROVE_ROOTS_FALL = new CompatSoundEvent(SoundEvents.MUDDY_MANGROVE_ROOTS_FALL); + public static final CompatSoundEvent BLOCK_MUDDY_MANGROVE_ROOTS_HIT = new CompatSoundEvent(SoundEvents.MUDDY_MANGROVE_ROOTS_HIT); + public static final CompatSoundEvent BLOCK_MUDDY_MANGROVE_ROOTS_PLACE = new CompatSoundEvent(SoundEvents.MUDDY_MANGROVE_ROOTS_PLACE); + public static final CompatSoundEvent BLOCK_MUDDY_MANGROVE_ROOTS_STEP = new CompatSoundEvent(SoundEvents.MUDDY_MANGROVE_ROOTS_STEP); + public static final CompatSoundEvent ENTITY_MULE_AMBIENT = new CompatSoundEvent(SoundEvents.MULE_AMBIENT); + public static final CompatSoundEvent ENTITY_MULE_ANGRY = new CompatSoundEvent(SoundEvents.MULE_ANGRY); + public static final CompatSoundEvent ENTITY_MULE_CHEST = new CompatSoundEvent(SoundEvents.MULE_CHEST); + public static final CompatSoundEvent ENTITY_MULE_DEATH = new CompatSoundEvent(SoundEvents.MULE_DEATH); + public static final CompatSoundEvent ENTITY_MULE_EAT = new CompatSoundEvent(SoundEvents.MULE_EAT); + public static final CompatSoundEvent ENTITY_MULE_HURT = new CompatSoundEvent(SoundEvents.MULE_HURT); + public static final CompatSoundEvent ENTITY_MULE_JUMP = new CompatSoundEvent(SoundEvents.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_BIOME_BASALT_DELTAS); + public static final CompatSoundEvent MUSIC_NETHER_CRIMSON_FOREST = new CompatSoundEvent(SoundEvents.MUSIC_BIOME_CRIMSON_FOREST); + public static final CompatSoundEvent MUSIC_OVERWORLD_DEEP_DARK = new CompatSoundEvent(SoundEvents.MUSIC_BIOME_DEEP_DARK); + public static final CompatSoundEvent MUSIC_OVERWORLD_DRIPSTONE_CAVES = new CompatSoundEvent(SoundEvents.MUSIC_BIOME_DRIPSTONE_CAVES); + public static final CompatSoundEvent MUSIC_OVERWORLD_GROVE = new CompatSoundEvent(SoundEvents.MUSIC_BIOME_GROVE); + public static final CompatSoundEvent MUSIC_OVERWORLD_JAGGED_PEAKS = new CompatSoundEvent(SoundEvents.MUSIC_BIOME_JAGGED_PEAKS); + public static final CompatSoundEvent MUSIC_OVERWORLD_LUSH_CAVES = new CompatSoundEvent(SoundEvents.MUSIC_BIOME_LUSH_CAVES); + public static final CompatSoundEvent MUSIC_OVERWORLD_SWAMP = new CompatSoundEvent(SoundEvents.MUSIC_BIOME_SWAMP); + public static final CompatSoundEvent MUSIC_OVERWORLD_FOREST = new CompatSoundEvent(SoundEvents.MUSIC_BIOME_FOREST); + public static final CompatSoundEvent MUSIC_OVERWORLD_OLD_GROWTH_TAIGA = new CompatSoundEvent(SoundEvents.MUSIC_BIOME_OLD_GROWTH_TAIGA); + public static final CompatSoundEvent MUSIC_OVERWORLD_MEADOW = new CompatSoundEvent(SoundEvents.MUSIC_BIOME_MEADOW); + public static final CompatSoundEvent MUSIC_OVERWORLD_CHERRY_GROVE = new CompatSoundEvent(SoundEvents.MUSIC_BIOME_CHERRY_GROVE); + public static final CompatSoundEvent MUSIC_NETHER_NETHER_WASTES = new CompatSoundEvent(SoundEvents.MUSIC_BIOME_NETHER_WASTES); + public static final CompatSoundEvent MUSIC_OVERWORLD_FROZEN_PEAKS = new CompatSoundEvent(SoundEvents.MUSIC_BIOME_FROZEN_PEAKS); + public static final CompatSoundEvent MUSIC_OVERWORLD_SNOWY_SLOPES = new CompatSoundEvent(SoundEvents.MUSIC_BIOME_SNOWY_SLOPES); + public static final CompatSoundEvent MUSIC_NETHER_SOUL_SAND_VALLEY = new CompatSoundEvent(SoundEvents.MUSIC_BIOME_SOUL_SAND_VALLEY); + public static final CompatSoundEvent MUSIC_OVERWORLD_STONY_PEAKS = new CompatSoundEvent(SoundEvents.MUSIC_BIOME_STONY_PEAKS); + public static final CompatSoundEvent MUSIC_NETHER_WARPED_FOREST = new CompatSoundEvent(SoundEvents.MUSIC_BIOME_WARPED_FOREST); + public static final CompatSoundEvent MUSIC_OVERWORLD_FLOWER_FOREST = new CompatSoundEvent(SoundEvents.MUSIC_BIOME_FLOWER_FOREST); + public static final CompatSoundEvent MUSIC_OVERWORLD_DESERT = new CompatSoundEvent(SoundEvents.MUSIC_BIOME_DESERT); + public static final CompatSoundEvent MUSIC_OVERWORLD_BADLANDS = new CompatSoundEvent(SoundEvents.MUSIC_BIOME_BADLANDS); + public static final CompatSoundEvent MUSIC_OVERWORLD_JUNGLE = new CompatSoundEvent(SoundEvents.MUSIC_BIOME_JUNGLE); + public static final CompatSoundEvent MUSIC_OVERWORLD_SPARSE_JUNGLE = new CompatSoundEvent(SoundEvents.MUSIC_BIOME_SPARSE_JUNGLE); + public static final CompatSoundEvent MUSIC_OVERWORLD_BAMBOO_JUNGLE = new CompatSoundEvent(SoundEvents.MUSIC_BIOME_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.NETHER_BRICKS_BREAK); + public static final CompatSoundEvent BLOCK_NETHER_BRICKS_STEP = new CompatSoundEvent(SoundEvents.NETHER_BRICKS_STEP); + public static final CompatSoundEvent BLOCK_NETHER_BRICKS_PLACE = new CompatSoundEvent(SoundEvents.NETHER_BRICKS_PLACE); + public static final CompatSoundEvent BLOCK_NETHER_BRICKS_HIT = new CompatSoundEvent(SoundEvents.NETHER_BRICKS_HIT); + public static final CompatSoundEvent BLOCK_NETHER_BRICKS_FALL = new CompatSoundEvent(SoundEvents.NETHER_BRICKS_FALL); + public static final CompatSoundEvent BLOCK_NETHER_WART_BREAK = new CompatSoundEvent(SoundEvents.NETHER_WART_BREAK); + public static final CompatSoundEvent ITEM_NETHER_WART_PLANT = new CompatSoundEvent(SoundEvents.NETHER_WART_PLANTED); + public static final CompatSoundEvent BLOCK_NETHER_WOOD_BREAK = new CompatSoundEvent(SoundEvents.NETHER_WOOD_BREAK); + public static final CompatSoundEvent BLOCK_NETHER_WOOD_FALL = new CompatSoundEvent(SoundEvents.NETHER_WOOD_FALL); + public static final CompatSoundEvent BLOCK_NETHER_WOOD_HIT = new CompatSoundEvent(SoundEvents.NETHER_WOOD_HIT); + public static final CompatSoundEvent BLOCK_NETHER_WOOD_PLACE = new CompatSoundEvent(SoundEvents.NETHER_WOOD_PLACE); + public static final CompatSoundEvent BLOCK_NETHER_WOOD_STEP = new CompatSoundEvent(SoundEvents.NETHER_WOOD_STEP); + public static final CompatSoundEvent BLOCK_NETHER_WOOD_DOOR_CLOSE = new CompatSoundEvent(SoundEvents.NETHER_WOOD_DOOR_CLOSE); + public static final CompatSoundEvent BLOCK_NETHER_WOOD_DOOR_OPEN = new CompatSoundEvent(SoundEvents.NETHER_WOOD_DOOR_OPEN); + public static final CompatSoundEvent BLOCK_NETHER_WOOD_TRAPDOOR_CLOSE = new CompatSoundEvent(SoundEvents.NETHER_WOOD_TRAPDOOR_CLOSE); + public static final CompatSoundEvent BLOCK_NETHER_WOOD_TRAPDOOR_OPEN = new CompatSoundEvent(SoundEvents.NETHER_WOOD_TRAPDOOR_OPEN); + public static final CompatSoundEvent BLOCK_NETHER_WOOD_BUTTON_CLICK_OFF = new CompatSoundEvent(SoundEvents.NETHER_WOOD_BUTTON_CLICK_OFF); + public static final CompatSoundEvent BLOCK_NETHER_WOOD_BUTTON_CLICK_ON = new CompatSoundEvent(SoundEvents.NETHER_WOOD_BUTTON_CLICK_ON); + public static final CompatSoundEvent BLOCK_NETHER_WOOD_PRESSURE_PLATE_CLICK_OFF = new CompatSoundEvent(SoundEvents.NETHER_WOOD_PRESSURE_PLATE_CLICK_OFF); + public static final CompatSoundEvent BLOCK_NETHER_WOOD_PRESSURE_PLATE_CLICK_ON = new CompatSoundEvent(SoundEvents.NETHER_WOOD_PRESSURE_PLATE_CLICK_ON); + public static final CompatSoundEvent BLOCK_NETHER_WOOD_FENCE_GATE_CLOSE = new CompatSoundEvent(SoundEvents.NETHER_WOOD_FENCE_GATE_CLOSE); + public static final CompatSoundEvent BLOCK_NETHER_WOOD_FENCE_GATE_OPEN = new CompatSoundEvent(SoundEvents.NETHER_WOOD_FENCE_GATE_OPEN); + public static final CompatSoundEvent INTENTIONALLY_EMPTY = new CompatSoundEvent(SoundEvents.EMPTY); + public static final CompatSoundEvent BLOCK_PACKED_MUD_BREAK = new CompatSoundEvent(SoundEvents.PACKED_MUD_BREAK); + public static final CompatSoundEvent BLOCK_PACKED_MUD_FALL = new CompatSoundEvent(SoundEvents.PACKED_MUD_FALL); + public static final CompatSoundEvent BLOCK_PACKED_MUD_HIT = new CompatSoundEvent(SoundEvents.PACKED_MUD_HIT); + public static final CompatSoundEvent BLOCK_PACKED_MUD_PLACE = new CompatSoundEvent(SoundEvents.PACKED_MUD_PLACE); + public static final CompatSoundEvent BLOCK_PACKED_MUD_STEP = new CompatSoundEvent(SoundEvents.PACKED_MUD_STEP); + public static final CompatSoundEvent BLOCK_STEM_BREAK = new CompatSoundEvent(SoundEvents.STEM_BREAK); + public static final CompatSoundEvent BLOCK_STEM_STEP = new CompatSoundEvent(SoundEvents.STEM_STEP); + public static final CompatSoundEvent BLOCK_STEM_PLACE = new CompatSoundEvent(SoundEvents.STEM_PLACE); + public static final CompatSoundEvent BLOCK_STEM_HIT = new CompatSoundEvent(SoundEvents.STEM_HIT); + public static final CompatSoundEvent BLOCK_STEM_FALL = new CompatSoundEvent(SoundEvents.STEM_FALL); + public static final CompatSoundEvent BLOCK_NYLIUM_BREAK = new CompatSoundEvent(SoundEvents.NYLIUM_BREAK); + public static final CompatSoundEvent BLOCK_NYLIUM_STEP = new CompatSoundEvent(SoundEvents.NYLIUM_STEP); + public static final CompatSoundEvent BLOCK_NYLIUM_PLACE = new CompatSoundEvent(SoundEvents.NYLIUM_PLACE); + public static final CompatSoundEvent BLOCK_NYLIUM_HIT = new CompatSoundEvent(SoundEvents.NYLIUM_HIT); + public static final CompatSoundEvent BLOCK_NYLIUM_FALL = new CompatSoundEvent(SoundEvents.NYLIUM_FALL); + public static final CompatSoundEvent BLOCK_NETHER_SPROUTS_BREAK = new CompatSoundEvent(SoundEvents.NETHER_SPROUTS_BREAK); + public static final CompatSoundEvent BLOCK_NETHER_SPROUTS_STEP = new CompatSoundEvent(SoundEvents.NETHER_SPROUTS_STEP); + public static final CompatSoundEvent BLOCK_NETHER_SPROUTS_PLACE = new CompatSoundEvent(SoundEvents.NETHER_SPROUTS_PLACE); + public static final CompatSoundEvent BLOCK_NETHER_SPROUTS_HIT = new CompatSoundEvent(SoundEvents.NETHER_SPROUTS_HIT); + public static final CompatSoundEvent BLOCK_NETHER_SPROUTS_FALL = new CompatSoundEvent(SoundEvents.NETHER_SPROUTS_FALL); + public static final CompatSoundEvent BLOCK_FUNGUS_BREAK = new CompatSoundEvent(SoundEvents.FUNGUS_BREAK); + public static final CompatSoundEvent BLOCK_FUNGUS_STEP = new CompatSoundEvent(SoundEvents.FUNGUS_STEP); + public static final CompatSoundEvent BLOCK_FUNGUS_PLACE = new CompatSoundEvent(SoundEvents.FUNGUS_PLACE); + public static final CompatSoundEvent BLOCK_FUNGUS_HIT = new CompatSoundEvent(SoundEvents.FUNGUS_HIT); + public static final CompatSoundEvent BLOCK_FUNGUS_FALL = new CompatSoundEvent(SoundEvents.FUNGUS_FALL); + public static final CompatSoundEvent BLOCK_WEEPING_VINES_BREAK = new CompatSoundEvent(SoundEvents.WEEPING_VINES_BREAK); + public static final CompatSoundEvent BLOCK_WEEPING_VINES_STEP = new CompatSoundEvent(SoundEvents.WEEPING_VINES_STEP); + public static final CompatSoundEvent BLOCK_WEEPING_VINES_PLACE = new CompatSoundEvent(SoundEvents.WEEPING_VINES_PLACE); + public static final CompatSoundEvent BLOCK_WEEPING_VINES_HIT = new CompatSoundEvent(SoundEvents.WEEPING_VINES_HIT); + public static final CompatSoundEvent BLOCK_WEEPING_VINES_FALL = new CompatSoundEvent(SoundEvents.WEEPING_VINES_FALL); + public static final CompatSoundEvent BLOCK_WART_BLOCK_BREAK = new CompatSoundEvent(SoundEvents.WART_BLOCK_BREAK); + public static final CompatSoundEvent BLOCK_WART_BLOCK_STEP = new CompatSoundEvent(SoundEvents.WART_BLOCK_STEP); + public static final CompatSoundEvent BLOCK_WART_BLOCK_PLACE = new CompatSoundEvent(SoundEvents.WART_BLOCK_PLACE); + public static final CompatSoundEvent BLOCK_WART_BLOCK_HIT = new CompatSoundEvent(SoundEvents.WART_BLOCK_HIT); + public static final CompatSoundEvent BLOCK_WART_BLOCK_FALL = new CompatSoundEvent(SoundEvents.WART_BLOCK_FALL); + public static final CompatSoundEvent BLOCK_NETHERITE_BLOCK_BREAK = new CompatSoundEvent(SoundEvents.NETHERITE_BLOCK_BREAK); + public static final CompatSoundEvent BLOCK_NETHERITE_BLOCK_STEP = new CompatSoundEvent(SoundEvents.NETHERITE_BLOCK_STEP); + public static final CompatSoundEvent BLOCK_NETHERITE_BLOCK_PLACE = new CompatSoundEvent(SoundEvents.NETHERITE_BLOCK_PLACE); + public static final CompatSoundEvent BLOCK_NETHERITE_BLOCK_HIT = new CompatSoundEvent(SoundEvents.NETHERITE_BLOCK_HIT); + public static final CompatSoundEvent BLOCK_NETHERITE_BLOCK_FALL = new CompatSoundEvent(SoundEvents.NETHERITE_BLOCK_FALL); + public static final CompatSoundEvent BLOCK_NETHERRACK_BREAK = new CompatSoundEvent(SoundEvents.NETHERRACK_BREAK); + public static final CompatSoundEvent BLOCK_NETHERRACK_STEP = new CompatSoundEvent(SoundEvents.NETHERRACK_STEP); + public static final CompatSoundEvent BLOCK_NETHERRACK_PLACE = new CompatSoundEvent(SoundEvents.NETHERRACK_PLACE); + public static final CompatSoundEvent BLOCK_NETHERRACK_HIT = new CompatSoundEvent(SoundEvents.NETHERRACK_HIT); + public static final CompatSoundEvent BLOCK_NETHERRACK_FALL = new CompatSoundEvent(SoundEvents.NETHERRACK_FALL); + public static final CompatSoundEvent BLOCK_NOTE_BLOCK_BASEDRUM = new CompatSoundEvent(SoundEvents.NOTE_BLOCK_BASEDRUM); + public static final CompatSoundEvent BLOCK_NOTE_BLOCK_BASS = new CompatSoundEvent(SoundEvents.NOTE_BLOCK_BASS); + public static final CompatSoundEvent BLOCK_NOTE_BLOCK_BELL = new CompatSoundEvent(SoundEvents.NOTE_BLOCK_BELL); + public static final CompatSoundEvent BLOCK_NOTE_BLOCK_CHIME = new CompatSoundEvent(SoundEvents.NOTE_BLOCK_CHIME); + public static final CompatSoundEvent BLOCK_NOTE_BLOCK_FLUTE = new CompatSoundEvent(SoundEvents.NOTE_BLOCK_FLUTE); + public static final CompatSoundEvent BLOCK_NOTE_BLOCK_GUITAR = new CompatSoundEvent(SoundEvents.NOTE_BLOCK_GUITAR); + public static final CompatSoundEvent BLOCK_NOTE_BLOCK_HARP = new CompatSoundEvent(SoundEvents.NOTE_BLOCK_HARP); + public static final CompatSoundEvent BLOCK_NOTE_BLOCK_HAT = new CompatSoundEvent(SoundEvents.NOTE_BLOCK_HAT); + public static final CompatSoundEvent BLOCK_NOTE_BLOCK_PLING = new CompatSoundEvent(SoundEvents.NOTE_BLOCK_PLING); + public static final CompatSoundEvent BLOCK_NOTE_BLOCK_SNARE = new CompatSoundEvent(SoundEvents.NOTE_BLOCK_SNARE); + public static final CompatSoundEvent BLOCK_NOTE_BLOCK_XYLOPHONE = new CompatSoundEvent(SoundEvents.NOTE_BLOCK_XYLOPHONE); + public static final CompatSoundEvent BLOCK_NOTE_BLOCK_IRON_XYLOPHONE = new CompatSoundEvent(SoundEvents.NOTE_BLOCK_IRON_XYLOPHONE); + public static final CompatSoundEvent BLOCK_NOTE_BLOCK_COW_BELL = new CompatSoundEvent(SoundEvents.NOTE_BLOCK_COW_BELL); + public static final CompatSoundEvent BLOCK_NOTE_BLOCK_DIDGERIDOO = new CompatSoundEvent(SoundEvents.NOTE_BLOCK_DIDGERIDOO); + public static final CompatSoundEvent BLOCK_NOTE_BLOCK_BIT = new CompatSoundEvent(SoundEvents.NOTE_BLOCK_BIT); + public static final CompatSoundEvent BLOCK_NOTE_BLOCK_BANJO = new CompatSoundEvent(SoundEvents.NOTE_BLOCK_BANJO); + public static final CompatSoundEvent BLOCK_NOTE_BLOCK_IMITATE_ZOMBIE = new CompatSoundEvent(SoundEvents.NOTE_BLOCK_IMITATE_ZOMBIE); + public static final CompatSoundEvent BLOCK_NOTE_BLOCK_IMITATE_SKELETON = new CompatSoundEvent(SoundEvents.NOTE_BLOCK_IMITATE_SKELETON); + public static final CompatSoundEvent BLOCK_NOTE_BLOCK_IMITATE_CREEPER = new CompatSoundEvent(SoundEvents.NOTE_BLOCK_IMITATE_CREEPER); + public static final CompatSoundEvent BLOCK_NOTE_BLOCK_IMITATE_ENDER_DRAGON = new CompatSoundEvent(SoundEvents.NOTE_BLOCK_IMITATE_ENDER_DRAGON); + public static final CompatSoundEvent BLOCK_NOTE_BLOCK_IMITATE_WITHER_SKELETON = new CompatSoundEvent(SoundEvents.NOTE_BLOCK_IMITATE_WITHER_SKELETON); + public static final CompatSoundEvent BLOCK_NOTE_BLOCK_IMITATE_PIGLIN = new CompatSoundEvent(SoundEvents.NOTE_BLOCK_IMITATE_PIGLIN); + public static final CompatSoundEvent ENTITY_OCELOT_HURT = new CompatSoundEvent(SoundEvents.OCELOT_HURT); + public static final CompatSoundEvent ENTITY_OCELOT_AMBIENT = new CompatSoundEvent(SoundEvents.OCELOT_AMBIENT); + public static final CompatSoundEvent ENTITY_OCELOT_DEATH = new CompatSoundEvent(SoundEvents.OCELOT_DEATH); + public static final CompatSoundEvent ITEM_OMINOUS_BOTTLE_DISPOSE = new CompatSoundEvent(SoundEvents.OMINOUS_BOTTLE_DISPOSE); + public static final CompatSoundEvent ENTITY_PAINTING_BREAK = new CompatSoundEvent(SoundEvents.PAINTING_BREAK); + public static final CompatSoundEvent ENTITY_PAINTING_PLACE = new CompatSoundEvent(SoundEvents.PAINTING_PLACE); + public static final CompatSoundEvent ENTITY_PANDA_PRE_SNEEZE = new CompatSoundEvent(SoundEvents.PANDA_PRE_SNEEZE); + public static final CompatSoundEvent ENTITY_PANDA_SNEEZE = new CompatSoundEvent(SoundEvents.PANDA_SNEEZE); + public static final CompatSoundEvent ENTITY_PANDA_AMBIENT = new CompatSoundEvent(SoundEvents.PANDA_AMBIENT); + public static final CompatSoundEvent ENTITY_PANDA_DEATH = new CompatSoundEvent(SoundEvents.PANDA_DEATH); + public static final CompatSoundEvent ENTITY_PANDA_EAT = new CompatSoundEvent(SoundEvents.PANDA_EAT); + public static final CompatSoundEvent ENTITY_PANDA_STEP = new CompatSoundEvent(SoundEvents.PANDA_STEP); + public static final CompatSoundEvent ENTITY_PANDA_CANT_BREED = new CompatSoundEvent(SoundEvents.PANDA_CANT_BREED); + public static final CompatSoundEvent ENTITY_PANDA_AGGRESSIVE_AMBIENT = new CompatSoundEvent(SoundEvents.PANDA_AGGRESSIVE_AMBIENT); + public static final CompatSoundEvent ENTITY_PANDA_WORRIED_AMBIENT = new CompatSoundEvent(SoundEvents.PANDA_WORRIED_AMBIENT); + public static final CompatSoundEvent ENTITY_PANDA_HURT = new CompatSoundEvent(SoundEvents.PANDA_HURT); + public static final CompatSoundEvent ENTITY_PANDA_BITE = new CompatSoundEvent(SoundEvents.PANDA_BITE); + public static final CompatSoundEvent ENTITY_PARROT_AMBIENT = new CompatSoundEvent(SoundEvents.PARROT_AMBIENT); + public static final CompatSoundEvent ENTITY_PARROT_DEATH = new CompatSoundEvent(SoundEvents.PARROT_DEATH); + public static final CompatSoundEvent ENTITY_PARROT_EAT = new CompatSoundEvent(SoundEvents.PARROT_EAT); + public static final CompatSoundEvent ENTITY_PARROT_FLY = new CompatSoundEvent(SoundEvents.PARROT_FLY); + public static final CompatSoundEvent ENTITY_PARROT_HURT = new CompatSoundEvent(SoundEvents.PARROT_HURT); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_BLAZE = new CompatSoundEvent(SoundEvents.PARROT_IMITATE_BLAZE); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_BOGGED = new CompatSoundEvent(SoundEvents.PARROT_IMITATE_BOGGED); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_BREEZE = new CompatSoundEvent(SoundEvents.PARROT_IMITATE_BREEZE); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_CREEPER = new CompatSoundEvent(SoundEvents.PARROT_IMITATE_CREEPER); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_DROWNED = new CompatSoundEvent(SoundEvents.PARROT_IMITATE_DROWNED); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_ELDER_GUARDIAN = new CompatSoundEvent(SoundEvents.PARROT_IMITATE_ELDER_GUARDIAN); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_ENDER_DRAGON = new CompatSoundEvent(SoundEvents.PARROT_IMITATE_ENDER_DRAGON); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_ENDERMITE = new CompatSoundEvent(SoundEvents.PARROT_IMITATE_ENDERMITE); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_EVOKER = new CompatSoundEvent(SoundEvents.PARROT_IMITATE_EVOKER); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_GHAST = new CompatSoundEvent(SoundEvents.PARROT_IMITATE_GHAST); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_GUARDIAN = new CompatSoundEvent(SoundEvents.PARROT_IMITATE_GUARDIAN); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_HOGLIN = new CompatSoundEvent(SoundEvents.PARROT_IMITATE_HOGLIN); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_HUSK = new CompatSoundEvent(SoundEvents.PARROT_IMITATE_HUSK); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_ILLUSIONER = new CompatSoundEvent(SoundEvents.PARROT_IMITATE_ILLUSIONER); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_MAGMA_CUBE = new CompatSoundEvent(SoundEvents.PARROT_IMITATE_MAGMA_CUBE); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_PHANTOM = new CompatSoundEvent(SoundEvents.PARROT_IMITATE_PHANTOM); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_PIGLIN = new CompatSoundEvent(SoundEvents.PARROT_IMITATE_PIGLIN); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_PIGLIN_BRUTE = new CompatSoundEvent(SoundEvents.PARROT_IMITATE_PIGLIN_BRUTE); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_PILLAGER = new CompatSoundEvent(SoundEvents.PARROT_IMITATE_PILLAGER); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_RAVAGER = new CompatSoundEvent(SoundEvents.PARROT_IMITATE_RAVAGER); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_SHULKER = new CompatSoundEvent(SoundEvents.PARROT_IMITATE_SHULKER); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_SILVERFISH = new CompatSoundEvent(SoundEvents.PARROT_IMITATE_SILVERFISH); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_SKELETON = new CompatSoundEvent(SoundEvents.PARROT_IMITATE_SKELETON); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_SLIME = new CompatSoundEvent(SoundEvents.PARROT_IMITATE_SLIME); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_SPIDER = new CompatSoundEvent(SoundEvents.PARROT_IMITATE_SPIDER); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_STRAY = new CompatSoundEvent(SoundEvents.PARROT_IMITATE_STRAY); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_VEX = new CompatSoundEvent(SoundEvents.PARROT_IMITATE_VEX); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_VINDICATOR = new CompatSoundEvent(SoundEvents.PARROT_IMITATE_VINDICATOR); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_WARDEN = new CompatSoundEvent(SoundEvents.PARROT_IMITATE_WARDEN); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_WITCH = new CompatSoundEvent(SoundEvents.PARROT_IMITATE_WITCH); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_WITHER = new CompatSoundEvent(SoundEvents.PARROT_IMITATE_WITHER); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_WITHER_SKELETON = new CompatSoundEvent(SoundEvents.PARROT_IMITATE_WITHER_SKELETON); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_ZOGLIN = new CompatSoundEvent(SoundEvents.PARROT_IMITATE_ZOGLIN); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_ZOMBIE = new CompatSoundEvent(SoundEvents.PARROT_IMITATE_ZOMBIE); + public static final CompatSoundEvent ENTITY_PARROT_IMITATE_ZOMBIE_VILLAGER = new CompatSoundEvent(SoundEvents.PARROT_IMITATE_ZOMBIE_VILLAGER); + public static final CompatSoundEvent ENTITY_PARROT_STEP = new CompatSoundEvent(SoundEvents.PARROT_STEP); + public static final CompatSoundEvent ENTITY_PHANTOM_AMBIENT = new CompatSoundEvent(SoundEvents.PHANTOM_AMBIENT); + public static final CompatSoundEvent ENTITY_PHANTOM_BITE = new CompatSoundEvent(SoundEvents.PHANTOM_BITE); + public static final CompatSoundEvent ENTITY_PHANTOM_DEATH = new CompatSoundEvent(SoundEvents.PHANTOM_DEATH); + public static final CompatSoundEvent ENTITY_PHANTOM_FLAP = new CompatSoundEvent(SoundEvents.PHANTOM_FLAP); + public static final CompatSoundEvent ENTITY_PHANTOM_HURT = new CompatSoundEvent(SoundEvents.PHANTOM_HURT); + public static final CompatSoundEvent ENTITY_PHANTOM_SWOOP = new CompatSoundEvent(SoundEvents.PHANTOM_SWOOP); + public static final CompatSoundEvent ENTITY_PIG_AMBIENT = new CompatSoundEvent(SoundEvents.PIG_SOUNDS.get(PigSoundVariants.SoundSet.CLASSIC).adultSounds().ambientSound()); + public static final CompatSoundEvent ENTITY_PIG_DEATH = new CompatSoundEvent(SoundEvents.PIG_SOUNDS.get(PigSoundVariants.SoundSet.CLASSIC).adultSounds().deathSound()); + public static final CompatSoundEvent ENTITY_PIG_HURT = new CompatSoundEvent(SoundEvents.PIG_SOUNDS.get(PigSoundVariants.SoundSet.CLASSIC).adultSounds().hurtSound()); + public static final CompatSoundEvent ENTITY_PIG_SADDLE = new CompatSoundEvent(SoundEvents.PIG_SADDLE); + public static final CompatSoundEvent ENTITY_PIG_STEP = new CompatSoundEvent(SoundEvents.PIG_STEP); + public static final CompatSoundEvent ENTITY_PIGLIN_ADMIRING_ITEM = new CompatSoundEvent(SoundEvents.PIGLIN_ADMIRING_ITEM); + public static final CompatSoundEvent ENTITY_PIGLIN_AMBIENT = new CompatSoundEvent(SoundEvents.PIGLIN_AMBIENT); + public static final CompatSoundEvent ENTITY_PIGLIN_ANGRY = new CompatSoundEvent(SoundEvents.PIGLIN_ANGRY); + public static final CompatSoundEvent ENTITY_PIGLIN_CELEBRATE = new CompatSoundEvent(SoundEvents.PIGLIN_CELEBRATE); + public static final CompatSoundEvent ENTITY_PIGLIN_DEATH = new CompatSoundEvent(SoundEvents.PIGLIN_DEATH); + public static final CompatSoundEvent ENTITY_PIGLIN_JEALOUS = new CompatSoundEvent(SoundEvents.PIGLIN_JEALOUS); + public static final CompatSoundEvent ENTITY_PIGLIN_HURT = new CompatSoundEvent(SoundEvents.PIGLIN_HURT); + public static final CompatSoundEvent ENTITY_PIGLIN_RETREAT = new CompatSoundEvent(SoundEvents.PIGLIN_RETREAT); + public static final CompatSoundEvent ENTITY_PIGLIN_STEP = new CompatSoundEvent(SoundEvents.PIGLIN_STEP); + public static final CompatSoundEvent ENTITY_PIGLIN_CONVERTED_TO_ZOMBIFIED = new CompatSoundEvent(SoundEvents.PIGLIN_CONVERTED_TO_ZOMBIFIED); + public static final CompatSoundEvent ENTITY_PIGLIN_BRUTE_AMBIENT = new CompatSoundEvent(SoundEvents.PIGLIN_BRUTE_AMBIENT); + public static final CompatSoundEvent ENTITY_PIGLIN_BRUTE_ANGRY = new CompatSoundEvent(SoundEvents.PIGLIN_BRUTE_ANGRY); + public static final CompatSoundEvent ENTITY_PIGLIN_BRUTE_DEATH = new CompatSoundEvent(SoundEvents.PIGLIN_BRUTE_DEATH); + public static final CompatSoundEvent ENTITY_PIGLIN_BRUTE_HURT = new CompatSoundEvent(SoundEvents.PIGLIN_BRUTE_HURT); + public static final CompatSoundEvent ENTITY_PIGLIN_BRUTE_STEP = new CompatSoundEvent(SoundEvents.PIGLIN_BRUTE_STEP); + public static final CompatSoundEvent ENTITY_PIGLIN_BRUTE_CONVERTED_TO_ZOMBIFIED = new CompatSoundEvent(SoundEvents.PIGLIN_BRUTE_CONVERTED_TO_ZOMBIFIED); + public static final CompatSoundEvent ENTITY_PILLAGER_AMBIENT = new CompatSoundEvent(SoundEvents.PILLAGER_AMBIENT); + public static final CompatSoundEvent ENTITY_PILLAGER_CELEBRATE = new CompatSoundEvent(SoundEvents.PILLAGER_CELEBRATE); + public static final CompatSoundEvent ENTITY_PILLAGER_DEATH = new CompatSoundEvent(SoundEvents.PILLAGER_DEATH); + public static final CompatSoundEvent ENTITY_PILLAGER_HURT = new CompatSoundEvent(SoundEvents.PILLAGER_HURT); + public static final CompatSoundEvent BLOCK_PISTON_CONTRACT = new CompatSoundEvent(SoundEvents.PISTON_CONTRACT); + public static final CompatSoundEvent BLOCK_PISTON_EXTEND = new CompatSoundEvent(SoundEvents.PISTON_EXTEND); + public static final CompatSoundEvent ENTITY_PLAYER_ATTACK_CRIT = new CompatSoundEvent(SoundEvents.PLAYER_ATTACK_CRIT); + public static final CompatSoundEvent ENTITY_PLAYER_ATTACK_KNOCKBACK = new CompatSoundEvent(SoundEvents.PLAYER_ATTACK_KNOCKBACK); + public static final CompatSoundEvent ENTITY_PLAYER_ATTACK_NODAMAGE = new CompatSoundEvent(SoundEvents.PLAYER_ATTACK_NODAMAGE); + public static final CompatSoundEvent ENTITY_PLAYER_ATTACK_STRONG = new CompatSoundEvent(SoundEvents.PLAYER_ATTACK_STRONG); + public static final CompatSoundEvent ENTITY_PLAYER_ATTACK_SWEEP = new CompatSoundEvent(SoundEvents.PLAYER_ATTACK_SWEEP); + public static final CompatSoundEvent ENTITY_PLAYER_ATTACK_WEAK = new CompatSoundEvent(SoundEvents.PLAYER_ATTACK_WEAK); + public static final CompatSoundEvent ENTITY_PLAYER_BIG_FALL = new CompatSoundEvent(SoundEvents.PLAYER_BIG_FALL); + public static final CompatSoundEvent ENTITY_PLAYER_BREATH = new CompatSoundEvent(SoundEvents.PLAYER_BREATH); + public static final CompatSoundEvent ENTITY_PLAYER_BURP = new CompatSoundEvent(SoundEvents.PLAYER_BURP); + public static final CompatSoundEvent ENTITY_PLAYER_DEATH = new CompatSoundEvent(SoundEvents.PLAYER_DEATH); + public static final CompatSoundEvent ENTITY_PLAYER_HURT = new CompatSoundEvent(SoundEvents.PLAYER_HURT); + public static final CompatSoundEvent ENTITY_PLAYER_HURT_DROWN = new CompatSoundEvent(SoundEvents.PLAYER_HURT_DROWN); + public static final CompatSoundEvent ENTITY_PLAYER_HURT_FREEZE = new CompatSoundEvent(SoundEvents.PLAYER_HURT_FREEZE); + public static final CompatSoundEvent ENTITY_PLAYER_HURT_ON_FIRE = new CompatSoundEvent(SoundEvents.PLAYER_HURT_ON_FIRE); + public static final CompatSoundEvent ENTITY_PLAYER_HURT_SWEET_BERRY_BUSH = new CompatSoundEvent(SoundEvents.PLAYER_HURT_SWEET_BERRY_BUSH); + public static final CompatSoundEvent ENTITY_PLAYER_LEVELUP = new CompatSoundEvent(SoundEvents.PLAYER_LEVELUP); + public static final CompatSoundEvent ENTITY_PLAYER_SMALL_FALL = new CompatSoundEvent(SoundEvents.PLAYER_SMALL_FALL); + public static final CompatSoundEvent ENTITY_PLAYER_SPLASH = new CompatSoundEvent(SoundEvents.PLAYER_SPLASH); + public static final CompatSoundEvent ENTITY_PLAYER_SPLASH_HIGH_SPEED = new CompatSoundEvent(SoundEvents.PLAYER_SPLASH_HIGH_SPEED); + public static final CompatSoundEvent ENTITY_PLAYER_SWIM = new CompatSoundEvent(SoundEvents.PLAYER_SWIM); + public static final CompatSoundEvent ENTITY_PLAYER_TELEPORT = new CompatSoundEvent(SoundEvents.PLAYER_TELEPORT); + public static final CompatSoundEvent ENTITY_POLAR_BEAR_AMBIENT = new CompatSoundEvent(SoundEvents.POLAR_BEAR_AMBIENT); + public static final CompatSoundEvent ENTITY_POLAR_BEAR_AMBIENT_BABY = new CompatSoundEvent(SoundEvents.POLAR_BEAR_AMBIENT_BABY); + public static final CompatSoundEvent ENTITY_POLAR_BEAR_DEATH = new CompatSoundEvent(SoundEvents.POLAR_BEAR_DEATH); + public static final CompatSoundEvent ENTITY_POLAR_BEAR_HURT = new CompatSoundEvent(SoundEvents.POLAR_BEAR_HURT); + public static final CompatSoundEvent ENTITY_POLAR_BEAR_STEP = new CompatSoundEvent(SoundEvents.POLAR_BEAR_STEP); + public static final CompatSoundEvent ENTITY_POLAR_BEAR_WARNING = new CompatSoundEvent(SoundEvents.POLAR_BEAR_WARNING); + public static final CompatSoundEvent BLOCK_POLISHED_DEEPSLATE_BREAK = new CompatSoundEvent(SoundEvents.POLISHED_DEEPSLATE_BREAK); + public static final CompatSoundEvent BLOCK_POLISHED_DEEPSLATE_FALL = new CompatSoundEvent(SoundEvents.POLISHED_DEEPSLATE_FALL); + public static final CompatSoundEvent BLOCK_POLISHED_DEEPSLATE_HIT = new CompatSoundEvent(SoundEvents.POLISHED_DEEPSLATE_HIT); + public static final CompatSoundEvent BLOCK_POLISHED_DEEPSLATE_PLACE = new CompatSoundEvent(SoundEvents.POLISHED_DEEPSLATE_PLACE); + public static final CompatSoundEvent BLOCK_POLISHED_DEEPSLATE_STEP = new CompatSoundEvent(SoundEvents.POLISHED_DEEPSLATE_STEP); + public static final CompatSoundEvent BLOCK_PORTAL_AMBIENT = new CompatSoundEvent(SoundEvents.PORTAL_AMBIENT); + public static final CompatSoundEvent BLOCK_PORTAL_TRAVEL = new CompatSoundEvent(SoundEvents.PORTAL_TRAVEL); + public static final CompatSoundEvent BLOCK_PORTAL_TRIGGER = new CompatSoundEvent(SoundEvents.PORTAL_TRIGGER); + public static final CompatSoundEvent BLOCK_POWDER_SNOW_BREAK = new CompatSoundEvent(SoundEvents.POWDER_SNOW_BREAK); + public static final CompatSoundEvent BLOCK_POWDER_SNOW_FALL = new CompatSoundEvent(SoundEvents.POWDER_SNOW_FALL); + public static final CompatSoundEvent BLOCK_POWDER_SNOW_HIT = new CompatSoundEvent(SoundEvents.POWDER_SNOW_HIT); + public static final CompatSoundEvent BLOCK_POWDER_SNOW_PLACE = new CompatSoundEvent(SoundEvents.POWDER_SNOW_PLACE); + public static final CompatSoundEvent BLOCK_POWDER_SNOW_STEP = new CompatSoundEvent(SoundEvents.POWDER_SNOW_STEP); + public static final CompatSoundEvent ENTITY_PUFFER_FISH_AMBIENT = new CompatSoundEvent(SoundEvents.PUFFER_FISH_STING); + public static final CompatSoundEvent ENTITY_PUFFER_FISH_BLOW_OUT = new CompatSoundEvent(SoundEvents.PUFFER_FISH_BLOW_OUT); + public static final CompatSoundEvent ENTITY_PUFFER_FISH_BLOW_UP = new CompatSoundEvent(SoundEvents.PUFFER_FISH_BLOW_UP); + public static final CompatSoundEvent ENTITY_PUFFER_FISH_DEATH = new CompatSoundEvent(SoundEvents.PUFFER_FISH_DEATH); + public static final CompatSoundEvent ENTITY_PUFFER_FISH_FLOP = new CompatSoundEvent(SoundEvents.PUFFER_FISH_FLOP); + public static final CompatSoundEvent ENTITY_PUFFER_FISH_HURT = new CompatSoundEvent(SoundEvents.PUFFER_FISH_HURT); + public static final CompatSoundEvent ENTITY_PUFFER_FISH_STING = new CompatSoundEvent(SoundEvents.PUFFER_FISH_STING); + public static final CompatSoundEvent BLOCK_PUMPKIN_CARVE = new CompatSoundEvent(SoundEvents.PUMPKIN_CARVE); + public static final CompatSoundEvent ENTITY_RABBIT_AMBIENT = new CompatSoundEvent(SoundEvents.RABBIT_AMBIENT); + public static final CompatSoundEvent ENTITY_RABBIT_ATTACK = new CompatSoundEvent(SoundEvents.RABBIT_ATTACK); + public static final CompatSoundEvent ENTITY_RABBIT_DEATH = new CompatSoundEvent(SoundEvents.RABBIT_DEATH); + public static final CompatSoundEvent ENTITY_RABBIT_HURT = new CompatSoundEvent(SoundEvents.RABBIT_HURT); + public static final CompatSoundEvent ENTITY_RABBIT_JUMP = new CompatSoundEvent(SoundEvents.RABBIT_JUMP); + public static final CompatSoundEvent EVENT_RAID_HORN = new CompatSoundEvent(SoundEvents.RAID_HORN); + public static final CompatSoundEvent ENTITY_RAVAGER_AMBIENT = new CompatSoundEvent(SoundEvents.RAVAGER_AMBIENT); + public static final CompatSoundEvent ENTITY_RAVAGER_ATTACK = new CompatSoundEvent(SoundEvents.RAVAGER_ATTACK); + public static final CompatSoundEvent ENTITY_RAVAGER_CELEBRATE = new CompatSoundEvent(SoundEvents.RAVAGER_CELEBRATE); + public static final CompatSoundEvent ENTITY_RAVAGER_DEATH = new CompatSoundEvent(SoundEvents.RAVAGER_DEATH); + public static final CompatSoundEvent ENTITY_RAVAGER_HURT = new CompatSoundEvent(SoundEvents.RAVAGER_HURT); + public static final CompatSoundEvent ENTITY_RAVAGER_STEP = new CompatSoundEvent(SoundEvents.RAVAGER_STEP); + public static final CompatSoundEvent ENTITY_RAVAGER_STUNNED = new CompatSoundEvent(SoundEvents.RAVAGER_STUNNED); + public static final CompatSoundEvent ENTITY_RAVAGER_ROAR = new CompatSoundEvent(SoundEvents.RAVAGER_ROAR); + public static final CompatSoundEvent BLOCK_NETHER_GOLD_ORE_BREAK = new CompatSoundEvent(SoundEvents.NETHER_GOLD_ORE_BREAK); + public static final CompatSoundEvent BLOCK_NETHER_GOLD_ORE_FALL = new CompatSoundEvent(SoundEvents.NETHER_GOLD_ORE_FALL); + public static final CompatSoundEvent BLOCK_NETHER_GOLD_ORE_HIT = new CompatSoundEvent(SoundEvents.NETHER_GOLD_ORE_HIT); + public static final CompatSoundEvent BLOCK_NETHER_GOLD_ORE_PLACE = new CompatSoundEvent(SoundEvents.NETHER_GOLD_ORE_PLACE); + public static final CompatSoundEvent BLOCK_NETHER_GOLD_ORE_STEP = new CompatSoundEvent(SoundEvents.NETHER_GOLD_ORE_STEP); + public static final CompatSoundEvent BLOCK_NETHER_ORE_BREAK = new CompatSoundEvent(SoundEvents.NETHER_ORE_BREAK); + public static final CompatSoundEvent BLOCK_NETHER_ORE_FALL = new CompatSoundEvent(SoundEvents.NETHER_ORE_FALL); + public static final CompatSoundEvent BLOCK_NETHER_ORE_HIT = new CompatSoundEvent(SoundEvents.NETHER_ORE_HIT); + public static final CompatSoundEvent BLOCK_NETHER_ORE_PLACE = new CompatSoundEvent(SoundEvents.NETHER_ORE_PLACE); + public static final CompatSoundEvent BLOCK_NETHER_ORE_STEP = new CompatSoundEvent(SoundEvents.NETHER_ORE_STEP); + public static final CompatSoundEvent BLOCK_REDSTONE_TORCH_BURNOUT = new CompatSoundEvent(SoundEvents.REDSTONE_TORCH_BURNOUT); + public static final CompatSoundEvent BLOCK_RESPAWN_ANCHOR_AMBIENT = new CompatSoundEvent(SoundEvents.RESPAWN_ANCHOR_AMBIENT); + public static final CompatSoundEvent BLOCK_RESPAWN_ANCHOR_CHARGE = new CompatSoundEvent(SoundEvents.RESPAWN_ANCHOR_CHARGE); + public static final CompatSoundEvent BLOCK_RESPAWN_ANCHOR_DEPLETE = new CompatSoundEvent(SoundEvents.RESPAWN_ANCHOR_DEPLETE); + public static final CompatSoundEvent BLOCK_RESPAWN_ANCHOR_SET_SPAWN = new CompatSoundEvent(SoundEvents.RESPAWN_ANCHOR_SET_SPAWN); + public static final CompatSoundEvent BLOCK_ROOTED_DIRT_BREAK = new CompatSoundEvent(SoundEvents.ROOTED_DIRT_BREAK); + public static final CompatSoundEvent BLOCK_ROOTED_DIRT_FALL = new CompatSoundEvent(SoundEvents.ROOTED_DIRT_FALL); + public static final CompatSoundEvent BLOCK_ROOTED_DIRT_HIT = new CompatSoundEvent(SoundEvents.ROOTED_DIRT_HIT); + public static final CompatSoundEvent BLOCK_ROOTED_DIRT_PLACE = new CompatSoundEvent(SoundEvents.ROOTED_DIRT_PLACE); + public static final CompatSoundEvent BLOCK_ROOTED_DIRT_STEP = new CompatSoundEvent(SoundEvents.ROOTED_DIRT_STEP); + public static final CompatSoundEvent ENTITY_SALMON_AMBIENT = new CompatSoundEvent(SoundEvents.SALMON_AMBIENT); + public static final CompatSoundEvent ENTITY_SALMON_DEATH = new CompatSoundEvent(SoundEvents.SALMON_DEATH); + public static final CompatSoundEvent ENTITY_SALMON_FLOP = new CompatSoundEvent(SoundEvents.SALMON_FLOP); + public static final CompatSoundEvent ENTITY_SALMON_HURT = new CompatSoundEvent(SoundEvents.SALMON_HURT); + public static final CompatSoundEvent BLOCK_SAND_BREAK = new CompatSoundEvent(SoundEvents.SAND_BREAK); + public static final CompatSoundEvent BLOCK_SAND_FALL = new CompatSoundEvent(SoundEvents.SAND_FALL); + public static final CompatSoundEvent BLOCK_SAND_HIT = new CompatSoundEvent(SoundEvents.SAND_HIT); + public static final CompatSoundEvent BLOCK_SAND_PLACE = new CompatSoundEvent(SoundEvents.SAND_PLACE); + public static final CompatSoundEvent BLOCK_SAND_STEP = new CompatSoundEvent(SoundEvents.SAND_STEP); + public static final CompatSoundEvent BLOCK_SCAFFOLDING_BREAK = new CompatSoundEvent(SoundEvents.SCAFFOLDING_BREAK); + public static final CompatSoundEvent BLOCK_SCAFFOLDING_FALL = new CompatSoundEvent(SoundEvents.SCAFFOLDING_FALL); + public static final CompatSoundEvent BLOCK_SCAFFOLDING_HIT = new CompatSoundEvent(SoundEvents.SCAFFOLDING_HIT); + public static final CompatSoundEvent BLOCK_SCAFFOLDING_PLACE = new CompatSoundEvent(SoundEvents.SCAFFOLDING_PLACE); + public static final CompatSoundEvent BLOCK_SCAFFOLDING_STEP = new CompatSoundEvent(SoundEvents.SCAFFOLDING_STEP); + public static final CompatSoundEvent BLOCK_SCULK_SPREAD = new CompatSoundEvent(SoundEvents.SCULK_BLOCK_SPREAD); + public static final CompatSoundEvent BLOCK_SCULK_CHARGE = new CompatSoundEvent(SoundEvents.SCULK_BLOCK_CHARGE); + public static final CompatSoundEvent BLOCK_SCULK_BREAK = new CompatSoundEvent(SoundEvents.SCULK_BLOCK_BREAK); + public static final CompatSoundEvent BLOCK_SCULK_FALL = new CompatSoundEvent(SoundEvents.SCULK_BLOCK_FALL); + public static final CompatSoundEvent BLOCK_SCULK_HIT = new CompatSoundEvent(SoundEvents.SCULK_BLOCK_HIT); + public static final CompatSoundEvent BLOCK_SCULK_PLACE = new CompatSoundEvent(SoundEvents.SCULK_BLOCK_PLACE); + public static final CompatSoundEvent BLOCK_SCULK_STEP = new CompatSoundEvent(SoundEvents.SCULK_BLOCK_STEP); + public static final CompatSoundEvent BLOCK_SCULK_CATALYST_BLOOM = new CompatSoundEvent(SoundEvents.SCULK_CATALYST_BLOOM); + public static final CompatSoundEvent BLOCK_SCULK_CATALYST_BREAK = new CompatSoundEvent(SoundEvents.SCULK_CATALYST_BREAK); + public static final CompatSoundEvent BLOCK_SCULK_CATALYST_FALL = new CompatSoundEvent(SoundEvents.SCULK_CATALYST_FALL); + public static final CompatSoundEvent BLOCK_SCULK_CATALYST_HIT = new CompatSoundEvent(SoundEvents.SCULK_CATALYST_HIT); + public static final CompatSoundEvent BLOCK_SCULK_CATALYST_PLACE = new CompatSoundEvent(SoundEvents.SCULK_CATALYST_PLACE); + public static final CompatSoundEvent BLOCK_SCULK_CATALYST_STEP = new CompatSoundEvent(SoundEvents.SCULK_CATALYST_STEP); + public static final CompatSoundEvent BLOCK_SCULK_SENSOR_CLICKING = new CompatSoundEvent(SoundEvents.SCULK_CLICKING); + public static final CompatSoundEvent BLOCK_SCULK_SENSOR_CLICKING_STOP = new CompatSoundEvent(SoundEvents.SCULK_CLICKING_STOP); + public static final CompatSoundEvent BLOCK_SCULK_SENSOR_BREAK = new CompatSoundEvent(SoundEvents.SCULK_SENSOR_BREAK); + public static final CompatSoundEvent BLOCK_SCULK_SENSOR_FALL = new CompatSoundEvent(SoundEvents.SCULK_SENSOR_FALL); + public static final CompatSoundEvent BLOCK_SCULK_SENSOR_HIT = new CompatSoundEvent(SoundEvents.SCULK_SENSOR_HIT); + public static final CompatSoundEvent BLOCK_SCULK_SENSOR_PLACE = new CompatSoundEvent(SoundEvents.SCULK_SENSOR_PLACE); + public static final CompatSoundEvent BLOCK_SCULK_SENSOR_STEP = new CompatSoundEvent(SoundEvents.SCULK_SENSOR_STEP); + public static final CompatSoundEvent BLOCK_SCULK_SHRIEKER_BREAK = new CompatSoundEvent(SoundEvents.SCULK_SHRIEKER_BREAK); + public static final CompatSoundEvent BLOCK_SCULK_SHRIEKER_FALL = new CompatSoundEvent(SoundEvents.SCULK_SHRIEKER_FALL); + public static final CompatSoundEvent BLOCK_SCULK_SHRIEKER_HIT = new CompatSoundEvent(SoundEvents.SCULK_SHRIEKER_HIT); + public static final CompatSoundEvent BLOCK_SCULK_SHRIEKER_PLACE = new CompatSoundEvent(SoundEvents.SCULK_SHRIEKER_PLACE); + public static final CompatSoundEvent BLOCK_SCULK_SHRIEKER_SHRIEK = new CompatSoundEvent(SoundEvents.SCULK_SHRIEKER_SHRIEK); + public static final CompatSoundEvent BLOCK_SCULK_SHRIEKER_STEP = new CompatSoundEvent(SoundEvents.SCULK_SHRIEKER_STEP); + public static final CompatSoundEvent BLOCK_SCULK_VEIN_BREAK = new CompatSoundEvent(SoundEvents.SCULK_VEIN_BREAK); + public static final CompatSoundEvent BLOCK_SCULK_VEIN_FALL = new CompatSoundEvent(SoundEvents.SCULK_VEIN_FALL); + public static final CompatSoundEvent BLOCK_SCULK_VEIN_HIT = new CompatSoundEvent(SoundEvents.SCULK_VEIN_HIT); + public static final CompatSoundEvent BLOCK_SCULK_VEIN_PLACE = new CompatSoundEvent(SoundEvents.SCULK_VEIN_PLACE); + public static final CompatSoundEvent BLOCK_SCULK_VEIN_STEP = new CompatSoundEvent(SoundEvents.SCULK_VEIN_STEP); + public static final CompatSoundEvent ENTITY_SHEEP_AMBIENT = new CompatSoundEvent(SoundEvents.SHEEP_AMBIENT); + public static final CompatSoundEvent ENTITY_SHEEP_DEATH = new CompatSoundEvent(SoundEvents.SHEEP_DEATH); + public static final CompatSoundEvent ENTITY_SHEEP_HURT = new CompatSoundEvent(SoundEvents.SHEEP_HURT); + public static final CompatSoundEvent ENTITY_SHEEP_SHEAR = new CompatSoundEvent(SoundEvents.SHEEP_SHEAR); + public static final CompatSoundEvent ENTITY_SHEEP_STEP = new CompatSoundEvent(SoundEvents.SHEEP_STEP); + public static final CompatSoundEvent ITEM_SHIELD_BLOCK = new CompatSoundEvent(SoundEvents.SHIELD_BLOCK); + public static final CompatSoundEvent ITEM_SHIELD_BREAK = new CompatSoundEvent(SoundEvents.SHIELD_BREAK); + public static final CompatSoundEvent BLOCK_SHROOMLIGHT_BREAK = new CompatSoundEvent(SoundEvents.SHROOMLIGHT_BREAK); + public static final CompatSoundEvent BLOCK_SHROOMLIGHT_STEP = new CompatSoundEvent(SoundEvents.SHROOMLIGHT_STEP); + public static final CompatSoundEvent BLOCK_SHROOMLIGHT_PLACE = new CompatSoundEvent(SoundEvents.SHROOMLIGHT_PLACE); + public static final CompatSoundEvent BLOCK_SHROOMLIGHT_HIT = new CompatSoundEvent(SoundEvents.SHROOMLIGHT_HIT); + public static final CompatSoundEvent BLOCK_SHROOMLIGHT_FALL = new CompatSoundEvent(SoundEvents.SHROOMLIGHT_FALL); + public static final CompatSoundEvent ITEM_SHOVEL_FLATTEN = new CompatSoundEvent(SoundEvents.SHOVEL_FLATTEN); + public static final CompatSoundEvent ENTITY_SHULKER_AMBIENT = new CompatSoundEvent(SoundEvents.SHULKER_AMBIENT); + public static final CompatSoundEvent BLOCK_SHULKER_BOX_CLOSE = new CompatSoundEvent(SoundEvents.SHULKER_BOX_CLOSE); + public static final CompatSoundEvent BLOCK_SHULKER_BOX_OPEN = new CompatSoundEvent(SoundEvents.SHULKER_BOX_OPEN); + public static final CompatSoundEvent ENTITY_SHULKER_BULLET_HIT = new CompatSoundEvent(SoundEvents.SHULKER_BULLET_HIT); + public static final CompatSoundEvent ENTITY_SHULKER_BULLET_HURT = new CompatSoundEvent(SoundEvents.SHULKER_BULLET_HURT); + public static final CompatSoundEvent ENTITY_SHULKER_CLOSE = new CompatSoundEvent(SoundEvents.SHULKER_CLOSE); + public static final CompatSoundEvent ENTITY_SHULKER_DEATH = new CompatSoundEvent(SoundEvents.SHULKER_DEATH); + public static final CompatSoundEvent ENTITY_SHULKER_HURT = new CompatSoundEvent(SoundEvents.SHULKER_HURT); + public static final CompatSoundEvent ENTITY_SHULKER_HURT_CLOSED = new CompatSoundEvent(SoundEvents.SHULKER_HURT_CLOSED); + public static final CompatSoundEvent ENTITY_SHULKER_OPEN = new CompatSoundEvent(SoundEvents.SHULKER_OPEN); + public static final CompatSoundEvent ENTITY_SHULKER_SHOOT = new CompatSoundEvent(SoundEvents.SHULKER_SHOOT); + public static final CompatSoundEvent ENTITY_SHULKER_TELEPORT = new CompatSoundEvent(SoundEvents.SHULKER_TELEPORT); + public static final CompatSoundEvent ENTITY_SILVERFISH_AMBIENT = new CompatSoundEvent(SoundEvents.SILVERFISH_AMBIENT); + public static final CompatSoundEvent ENTITY_SILVERFISH_DEATH = new CompatSoundEvent(SoundEvents.SILVERFISH_DEATH); + public static final CompatSoundEvent ENTITY_SILVERFISH_HURT = new CompatSoundEvent(SoundEvents.SILVERFISH_HURT); + public static final CompatSoundEvent ENTITY_SILVERFISH_STEP = new CompatSoundEvent(SoundEvents.SILVERFISH_STEP); + public static final CompatSoundEvent ENTITY_SKELETON_AMBIENT = new CompatSoundEvent(SoundEvents.SKELETON_AMBIENT); + public static final CompatSoundEvent ENTITY_SKELETON_CONVERTED_TO_STRAY = new CompatSoundEvent(SoundEvents.SKELETON_CONVERTED_TO_STRAY); + public static final CompatSoundEvent ENTITY_SKELETON_DEATH = new CompatSoundEvent(SoundEvents.SKELETON_DEATH); + public static final CompatSoundEvent ENTITY_SKELETON_HORSE_AMBIENT = new CompatSoundEvent(SoundEvents.SKELETON_HORSE_AMBIENT); + public static final CompatSoundEvent ENTITY_SKELETON_HORSE_DEATH = new CompatSoundEvent(SoundEvents.SKELETON_HORSE_DEATH); + public static final CompatSoundEvent ENTITY_SKELETON_HORSE_HURT = new CompatSoundEvent(SoundEvents.SKELETON_HORSE_HURT); + public static final CompatSoundEvent ENTITY_SKELETON_HORSE_SWIM = new CompatSoundEvent(SoundEvents.SKELETON_HORSE_SWIM); + public static final CompatSoundEvent ENTITY_SKELETON_HORSE_AMBIENT_WATER = new CompatSoundEvent(SoundEvents.SKELETON_HORSE_AMBIENT_WATER); + public static final CompatSoundEvent ENTITY_SKELETON_HORSE_GALLOP_WATER = new CompatSoundEvent(SoundEvents.SKELETON_HORSE_GALLOP_WATER); + public static final CompatSoundEvent ENTITY_SKELETON_HORSE_JUMP_WATER = new CompatSoundEvent(SoundEvents.SKELETON_HORSE_JUMP_WATER); + public static final CompatSoundEvent ENTITY_SKELETON_HORSE_STEP_WATER = new CompatSoundEvent(SoundEvents.SKELETON_HORSE_STEP_WATER); + public static final CompatSoundEvent ENTITY_SKELETON_HURT = new CompatSoundEvent(SoundEvents.SKELETON_HURT); + public static final CompatSoundEvent ENTITY_SKELETON_SHOOT = new CompatSoundEvent(SoundEvents.SKELETON_SHOOT); + public static final CompatSoundEvent ENTITY_SKELETON_STEP = new CompatSoundEvent(SoundEvents.SKELETON_STEP); + public static final CompatSoundEvent ENTITY_SLIME_ATTACK = new CompatSoundEvent(SoundEvents.SLIME_ATTACK); + public static final CompatSoundEvent ENTITY_SLIME_DEATH = new CompatSoundEvent(SoundEvents.SLIME_DEATH); + public static final CompatSoundEvent ENTITY_SLIME_HURT = new CompatSoundEvent(SoundEvents.SLIME_HURT); + public static final CompatSoundEvent ENTITY_SLIME_JUMP = new CompatSoundEvent(SoundEvents.SLIME_JUMP); + public static final CompatSoundEvent ENTITY_SLIME_SQUISH = new CompatSoundEvent(SoundEvents.SLIME_SQUISH); + public static final CompatSoundEvent BLOCK_SLIME_BLOCK_BREAK = new CompatSoundEvent(SoundEvents.SLIME_BLOCK_BREAK); + public static final CompatSoundEvent BLOCK_SLIME_BLOCK_FALL = new CompatSoundEvent(SoundEvents.SLIME_BLOCK_FALL); + public static final CompatSoundEvent BLOCK_SLIME_BLOCK_HIT = new CompatSoundEvent(SoundEvents.SLIME_BLOCK_HIT); + public static final CompatSoundEvent BLOCK_SLIME_BLOCK_PLACE = new CompatSoundEvent(SoundEvents.SLIME_BLOCK_PLACE); + public static final CompatSoundEvent BLOCK_SLIME_BLOCK_STEP = new CompatSoundEvent(SoundEvents.SLIME_BLOCK_STEP); + public static final CompatSoundEvent BLOCK_SMALL_AMETHYST_BUD_BREAK = new CompatSoundEvent(SoundEvents.SMALL_AMETHYST_BUD_BREAK); + public static final CompatSoundEvent BLOCK_SMALL_AMETHYST_BUD_PLACE = new CompatSoundEvent(SoundEvents.SMALL_AMETHYST_BUD_PLACE); + public static final CompatSoundEvent BLOCK_SMALL_DRIPLEAF_BREAK = new CompatSoundEvent(SoundEvents.SMALL_DRIPLEAF_BREAK); + public static final CompatSoundEvent BLOCK_SMALL_DRIPLEAF_FALL = new CompatSoundEvent(SoundEvents.SMALL_DRIPLEAF_FALL); + public static final CompatSoundEvent BLOCK_SMALL_DRIPLEAF_HIT = new CompatSoundEvent(SoundEvents.SMALL_DRIPLEAF_HIT); + public static final CompatSoundEvent BLOCK_SMALL_DRIPLEAF_PLACE = new CompatSoundEvent(SoundEvents.SMALL_DRIPLEAF_PLACE); + public static final CompatSoundEvent BLOCK_SMALL_DRIPLEAF_STEP = new CompatSoundEvent(SoundEvents.SMALL_DRIPLEAF_STEP); + public static final CompatSoundEvent BLOCK_SOUL_SAND_BREAK = new CompatSoundEvent(SoundEvents.SOUL_SAND_BREAK); + public static final CompatSoundEvent BLOCK_SOUL_SAND_STEP = new CompatSoundEvent(SoundEvents.SOUL_SAND_STEP); + public static final CompatSoundEvent BLOCK_SOUL_SAND_PLACE = new CompatSoundEvent(SoundEvents.SOUL_SAND_PLACE); + public static final CompatSoundEvent BLOCK_SOUL_SAND_HIT = new CompatSoundEvent(SoundEvents.SOUL_SAND_HIT); + public static final CompatSoundEvent BLOCK_SOUL_SAND_FALL = new CompatSoundEvent(SoundEvents.SOUL_SAND_FALL); + public static final CompatSoundEvent BLOCK_SOUL_SOIL_BREAK = new CompatSoundEvent(SoundEvents.SOUL_SOIL_BREAK); + public static final CompatSoundEvent BLOCK_SOUL_SOIL_STEP = new CompatSoundEvent(SoundEvents.SOUL_SOIL_STEP); + public static final CompatSoundEvent BLOCK_SOUL_SOIL_PLACE = new CompatSoundEvent(SoundEvents.SOUL_SOIL_PLACE); + public static final CompatSoundEvent BLOCK_SOUL_SOIL_HIT = new CompatSoundEvent(SoundEvents.SOUL_SOIL_HIT); + public static final CompatSoundEvent BLOCK_SOUL_SOIL_FALL = new CompatSoundEvent(SoundEvents.SOUL_SOIL_FALL); + public static final CompatSoundEvent PARTICLE_SOUL_ESCAPE = new CompatSoundEvent(SoundEvents.SOUL_ESCAPE); + public static final CompatSoundEvent BLOCK_SPORE_BLOSSOM_BREAK = new CompatSoundEvent(SoundEvents.SPORE_BLOSSOM_BREAK); + public static final CompatSoundEvent BLOCK_SPORE_BLOSSOM_FALL = new CompatSoundEvent(SoundEvents.SPORE_BLOSSOM_FALL); + public static final CompatSoundEvent BLOCK_SPORE_BLOSSOM_HIT = new CompatSoundEvent(SoundEvents.SPORE_BLOSSOM_HIT); + public static final CompatSoundEvent BLOCK_SPORE_BLOSSOM_PLACE = new CompatSoundEvent(SoundEvents.SPORE_BLOSSOM_PLACE); + public static final CompatSoundEvent BLOCK_SPORE_BLOSSOM_STEP = new CompatSoundEvent(SoundEvents.SPORE_BLOSSOM_STEP); + public static final CompatSoundEvent ENTITY_STRIDER_AMBIENT = new CompatSoundEvent(SoundEvents.STRIDER_AMBIENT); + public static final CompatSoundEvent ENTITY_STRIDER_HAPPY = new CompatSoundEvent(SoundEvents.STRIDER_HAPPY); + public static final CompatSoundEvent ENTITY_STRIDER_RETREAT = new CompatSoundEvent(SoundEvents.STRIDER_RETREAT); + public static final CompatSoundEvent ENTITY_STRIDER_DEATH = new CompatSoundEvent(SoundEvents.STRIDER_DEATH); + public static final CompatSoundEvent ENTITY_STRIDER_HURT = new CompatSoundEvent(SoundEvents.STRIDER_HURT); + public static final CompatSoundEvent ENTITY_STRIDER_STEP = new CompatSoundEvent(SoundEvents.STRIDER_STEP); + public static final CompatSoundEvent ENTITY_STRIDER_STEP_LAVA = new CompatSoundEvent(SoundEvents.STRIDER_STEP_LAVA); + public static final CompatSoundEvent ENTITY_STRIDER_EAT = new CompatSoundEvent(SoundEvents.STRIDER_EAT); + public static final CompatSoundEvent ENTITY_STRIDER_SADDLE = new CompatSoundEvent(SoundEvents.STRIDER_SADDLE); + public static final CompatSoundEvent ENTITY_SLIME_DEATH_SMALL = new CompatSoundEvent(SoundEvents.SLIME_DEATH_SMALL); + public static final CompatSoundEvent ENTITY_SLIME_HURT_SMALL = new CompatSoundEvent(SoundEvents.SLIME_HURT_SMALL); + public static final CompatSoundEvent ENTITY_SLIME_JUMP_SMALL = new CompatSoundEvent(SoundEvents.SLIME_JUMP_SMALL); + public static final CompatSoundEvent ENTITY_SLIME_SQUISH_SMALL = new CompatSoundEvent(SoundEvents.SLIME_SQUISH_SMALL); + public static final CompatSoundEvent BLOCK_SMITHING_TABLE_USE = new CompatSoundEvent(SoundEvents.SMITHING_TABLE_USE); + public static final CompatSoundEvent BLOCK_SMOKER_SMOKE = new CompatSoundEvent(SoundEvents.SMOKER_SMOKE); + public static final CompatSoundEvent ENTITY_SNIFFER_STEP = new CompatSoundEvent(SoundEvents.SNIFFER_STEP); + public static final CompatSoundEvent ENTITY_SNIFFER_EAT = new CompatSoundEvent(SoundEvents.SNIFFER_EAT); + public static final CompatSoundEvent ENTITY_SNIFFER_IDLE = new CompatSoundEvent(SoundEvents.SNIFFER_IDLE); + public static final CompatSoundEvent ENTITY_SNIFFER_HURT = new CompatSoundEvent(SoundEvents.SNIFFER_HURT); + public static final CompatSoundEvent ENTITY_SNIFFER_DEATH = new CompatSoundEvent(SoundEvents.SNIFFER_DEATH); + public static final CompatSoundEvent ENTITY_SNIFFER_DROP_SEED = new CompatSoundEvent(SoundEvents.SNIFFER_DROP_SEED); + public static final CompatSoundEvent ENTITY_SNIFFER_SCENTING = new CompatSoundEvent(SoundEvents.SNIFFER_SCENTING); + public static final CompatSoundEvent ENTITY_SNIFFER_SNIFFING = new CompatSoundEvent(SoundEvents.SNIFFER_SNIFFING); + public static final CompatSoundEvent ENTITY_SNIFFER_SEARCHING = new CompatSoundEvent(SoundEvents.SNIFFER_SEARCHING); + public static final CompatSoundEvent ENTITY_SNIFFER_DIGGING = new CompatSoundEvent(SoundEvents.SNIFFER_DIGGING); + public static final CompatSoundEvent ENTITY_SNIFFER_DIGGING_STOP = new CompatSoundEvent(SoundEvents.SNIFFER_DIGGING_STOP); + public static final CompatSoundEvent ENTITY_SNIFFER_HAPPY = new CompatSoundEvent(SoundEvents.SNIFFER_HAPPY); + public static final CompatSoundEvent BLOCK_SNIFFER_EGG_PLOP = new CompatSoundEvent(SoundEvents.SNIFFER_EGG_PLOP); + public static final CompatSoundEvent BLOCK_SNIFFER_EGG_CRACK = new CompatSoundEvent(SoundEvents.SNIFFER_EGG_CRACK); + public static final CompatSoundEvent BLOCK_SNIFFER_EGG_HATCH = new CompatSoundEvent(SoundEvents.SNIFFER_EGG_HATCH); + public static final CompatSoundEvent ENTITY_SNOWBALL_THROW = new CompatSoundEvent(SoundEvents.SNOWBALL_THROW); + public static final CompatSoundEvent BLOCK_SNOW_BREAK = new CompatSoundEvent(SoundEvents.SNOW_BREAK); + public static final CompatSoundEvent BLOCK_SNOW_FALL = new CompatSoundEvent(SoundEvents.SNOW_FALL); + public static final CompatSoundEvent ENTITY_SNOW_GOLEM_AMBIENT = new CompatSoundEvent(SoundEvents.SNOW_GOLEM_AMBIENT); + public static final CompatSoundEvent ENTITY_SNOW_GOLEM_DEATH = new CompatSoundEvent(SoundEvents.SNOW_GOLEM_DEATH); + public static final CompatSoundEvent ENTITY_SNOW_GOLEM_HURT = new CompatSoundEvent(SoundEvents.SNOW_GOLEM_HURT); + public static final CompatSoundEvent ENTITY_SNOW_GOLEM_SHOOT = new CompatSoundEvent(SoundEvents.SNOW_GOLEM_SHOOT); + public static final CompatSoundEvent ENTITY_SNOW_GOLEM_SHEAR = new CompatSoundEvent(SoundEvents.SNOW_GOLEM_SHEAR); + public static final CompatSoundEvent BLOCK_SNOW_HIT = new CompatSoundEvent(SoundEvents.SNOW_HIT); + public static final CompatSoundEvent BLOCK_SNOW_PLACE = new CompatSoundEvent(SoundEvents.SNOW_PLACE); + public static final CompatSoundEvent BLOCK_SNOW_STEP = new CompatSoundEvent(SoundEvents.SNOW_STEP); + public static final CompatSoundEvent ENTITY_SPIDER_AMBIENT = new CompatSoundEvent(SoundEvents.SPIDER_AMBIENT); + public static final CompatSoundEvent ENTITY_SPIDER_DEATH = new CompatSoundEvent(SoundEvents.SPIDER_DEATH); + public static final CompatSoundEvent ENTITY_SPIDER_HURT = new CompatSoundEvent(SoundEvents.SPIDER_HURT); + public static final CompatSoundEvent ENTITY_SPIDER_STEP = new CompatSoundEvent(SoundEvents.SPIDER_STEP); + public static final CompatSoundEvent ENTITY_SPLASH_POTION_BREAK = new CompatSoundEvent(SoundEvents.SPLASH_POTION_BREAK); + public static final CompatSoundEvent ENTITY_SPLASH_POTION_THROW = new CompatSoundEvent(SoundEvents.SPLASH_POTION_THROW); + public static final CompatSoundEvent BLOCK_SPONGE_BREAK = new CompatSoundEvent(SoundEvents.SPONGE_BREAK); + public static final CompatSoundEvent BLOCK_SPONGE_FALL = new CompatSoundEvent(SoundEvents.SPONGE_FALL); + public static final CompatSoundEvent BLOCK_SPONGE_HIT = new CompatSoundEvent(SoundEvents.SPONGE_HIT); + public static final CompatSoundEvent BLOCK_SPONGE_PLACE = new CompatSoundEvent(SoundEvents.SPONGE_PLACE); + public static final CompatSoundEvent BLOCK_SPONGE_STEP = new CompatSoundEvent(SoundEvents.SPONGE_STEP); + public static final CompatSoundEvent BLOCK_SPONGE_ABSORB = new CompatSoundEvent(SoundEvents.SPONGE_ABSORB); + public static final CompatSoundEvent ITEM_SPYGLASS_USE = new CompatSoundEvent(SoundEvents.SPYGLASS_USE); + public static final CompatSoundEvent ITEM_SPYGLASS_STOP_USING = new CompatSoundEvent(SoundEvents.SPYGLASS_STOP_USING); + public static final CompatSoundEvent ENTITY_SQUID_AMBIENT = new CompatSoundEvent(SoundEvents.SQUID_AMBIENT); + public static final CompatSoundEvent ENTITY_SQUID_DEATH = new CompatSoundEvent(SoundEvents.SQUID_DEATH); + public static final CompatSoundEvent ENTITY_SQUID_HURT = new CompatSoundEvent(SoundEvents.SQUID_HURT); + public static final CompatSoundEvent ENTITY_SQUID_SQUIRT = new CompatSoundEvent(SoundEvents.SQUID_SQUIRT); + public static final CompatSoundEvent BLOCK_STONE_BREAK = new CompatSoundEvent(SoundEvents.STONE_BREAK); + public static final CompatSoundEvent BLOCK_STONE_BUTTON_CLICK_OFF = new CompatSoundEvent(SoundEvents.STONE_BUTTON_CLICK_OFF); + public static final CompatSoundEvent BLOCK_STONE_BUTTON_CLICK_ON = new CompatSoundEvent(SoundEvents.STONE_BUTTON_CLICK_ON); + public static final CompatSoundEvent BLOCK_STONE_FALL = new CompatSoundEvent(SoundEvents.STONE_FALL); + public static final CompatSoundEvent BLOCK_STONE_HIT = new CompatSoundEvent(SoundEvents.STONE_HIT); + public static final CompatSoundEvent BLOCK_STONE_PLACE = new CompatSoundEvent(SoundEvents.STONE_PLACE); + public static final CompatSoundEvent BLOCK_STONE_PRESSURE_PLATE_CLICK_OFF = new CompatSoundEvent(SoundEvents.STONE_PRESSURE_PLATE_CLICK_OFF); + public static final CompatSoundEvent BLOCK_STONE_PRESSURE_PLATE_CLICK_ON = new CompatSoundEvent(SoundEvents.STONE_PRESSURE_PLATE_CLICK_ON); + public static final CompatSoundEvent BLOCK_STONE_STEP = new CompatSoundEvent(SoundEvents.STONE_STEP); + public static final CompatSoundEvent ENTITY_STRAY_AMBIENT = new CompatSoundEvent(SoundEvents.STRAY_AMBIENT); + public static final CompatSoundEvent ENTITY_STRAY_DEATH = new CompatSoundEvent(SoundEvents.STRAY_DEATH); + public static final CompatSoundEvent ENTITY_STRAY_HURT = new CompatSoundEvent(SoundEvents.STRAY_HURT); + public static final CompatSoundEvent ENTITY_STRAY_STEP = new CompatSoundEvent(SoundEvents.STRAY_STEP); + public static final CompatSoundEvent BLOCK_SWEET_BERRY_BUSH_BREAK = new CompatSoundEvent(SoundEvents.SWEET_BERRY_BUSH_BREAK); + public static final CompatSoundEvent BLOCK_SWEET_BERRY_BUSH_PLACE = new CompatSoundEvent(SoundEvents.SWEET_BERRY_BUSH_PLACE); + public static final CompatSoundEvent BLOCK_SWEET_BERRY_BUSH_PICK_BERRIES = new CompatSoundEvent(SoundEvents.SWEET_BERRY_BUSH_PICK_BERRIES); + public static final CompatSoundEvent ENTITY_TADPOLE_DEATH = new CompatSoundEvent(SoundEvents.TADPOLE_DEATH); + public static final CompatSoundEvent ENTITY_TADPOLE_FLOP = new CompatSoundEvent(SoundEvents.TADPOLE_FLOP); + public static final CompatSoundEvent ENTITY_TADPOLE_GROW_UP = new CompatSoundEvent(SoundEvents.TADPOLE_GROW_UP); + public static final CompatSoundEvent ENTITY_TADPOLE_HURT = new CompatSoundEvent(SoundEvents.TADPOLE_HURT); + public static final CompatSoundEvent ENCHANT_THORNS_HIT = new CompatSoundEvent(SoundEvents.THORNS_HIT); + public static final CompatSoundEvent ENTITY_TNT_PRIMED = new CompatSoundEvent(SoundEvents.TNT_PRIMED); + public static final CompatSoundEvent ITEM_TOTEM_USE = new CompatSoundEvent(SoundEvents.TOTEM_USE); + public static final CompatSoundEvent ITEM_TRIDENT_HIT = new CompatSoundEvent(SoundEvents.TRIDENT_HIT); + public static final CompatSoundEvent ITEM_TRIDENT_HIT_GROUND = new CompatSoundEvent(SoundEvents.TRIDENT_HIT_GROUND); + public static final CompatSoundEvent ITEM_TRIDENT_RETURN = new CompatSoundEvent(SoundEvents.TRIDENT_RETURN); + public static final CompatSoundEvent ITEM_TRIDENT_RIPTIDE_1 = new CompatSoundEvent(SoundEvents.TRIDENT_RIPTIDE_1); + public static final CompatSoundEvent ITEM_TRIDENT_RIPTIDE_2 = new CompatSoundEvent(SoundEvents.TRIDENT_RIPTIDE_2); + public static final CompatSoundEvent ITEM_TRIDENT_RIPTIDE_3 = new CompatSoundEvent(SoundEvents.TRIDENT_RIPTIDE_3); + public static final CompatSoundEvent ITEM_TRIDENT_THROW = new CompatSoundEvent(SoundEvents.TRIDENT_THROW); + public static final CompatSoundEvent ITEM_TRIDENT_THUNDER = new CompatSoundEvent(SoundEvents.TRIDENT_THUNDER); + public static final CompatSoundEvent BLOCK_TRIPWIRE_ATTACH = new CompatSoundEvent(SoundEvents.TRIPWIRE_ATTACH); + public static final CompatSoundEvent BLOCK_TRIPWIRE_CLICK_OFF = new CompatSoundEvent(SoundEvents.TRIPWIRE_CLICK_OFF); + public static final CompatSoundEvent BLOCK_TRIPWIRE_CLICK_ON = new CompatSoundEvent(SoundEvents.TRIPWIRE_CLICK_ON); + public static final CompatSoundEvent BLOCK_TRIPWIRE_DETACH = new CompatSoundEvent(SoundEvents.TRIPWIRE_DETACH); + public static final CompatSoundEvent ENTITY_TROPICAL_FISH_AMBIENT = new CompatSoundEvent(SoundEvents.TROPICAL_FISH_AMBIENT); + public static final CompatSoundEvent ENTITY_TROPICAL_FISH_DEATH = new CompatSoundEvent(SoundEvents.TROPICAL_FISH_DEATH); + public static final CompatSoundEvent ENTITY_TROPICAL_FISH_FLOP = new CompatSoundEvent(SoundEvents.TROPICAL_FISH_FLOP); + public static final CompatSoundEvent ENTITY_TROPICAL_FISH_HURT = new CompatSoundEvent(SoundEvents.TROPICAL_FISH_HURT); + public static final CompatSoundEvent BLOCK_TUFF_BREAK = new CompatSoundEvent(SoundEvents.TUFF_BREAK); + public static final CompatSoundEvent BLOCK_TUFF_STEP = new CompatSoundEvent(SoundEvents.TUFF_STEP); + public static final CompatSoundEvent BLOCK_TUFF_PLACE = new CompatSoundEvent(SoundEvents.TUFF_PLACE); + public static final CompatSoundEvent BLOCK_TUFF_HIT = new CompatSoundEvent(SoundEvents.TUFF_HIT); + public static final CompatSoundEvent BLOCK_TUFF_FALL = new CompatSoundEvent(SoundEvents.TUFF_FALL); + public static final CompatSoundEvent BLOCK_TUFF_BRICKS_BREAK = new CompatSoundEvent(SoundEvents.TUFF_BRICKS_BREAK); + public static final CompatSoundEvent BLOCK_TUFF_BRICKS_FALL = new CompatSoundEvent(SoundEvents.TUFF_BRICKS_FALL); + public static final CompatSoundEvent BLOCK_TUFF_BRICKS_HIT = new CompatSoundEvent(SoundEvents.TUFF_BRICKS_HIT); + public static final CompatSoundEvent BLOCK_TUFF_BRICKS_PLACE = new CompatSoundEvent(SoundEvents.TUFF_BRICKS_PLACE); + public static final CompatSoundEvent BLOCK_TUFF_BRICKS_STEP = new CompatSoundEvent(SoundEvents.TUFF_BRICKS_STEP); + public static final CompatSoundEvent BLOCK_POLISHED_TUFF_BREAK = new CompatSoundEvent(SoundEvents.POLISHED_TUFF_BREAK); + public static final CompatSoundEvent BLOCK_POLISHED_TUFF_FALL = new CompatSoundEvent(SoundEvents.POLISHED_TUFF_FALL); + public static final CompatSoundEvent BLOCK_POLISHED_TUFF_HIT = new CompatSoundEvent(SoundEvents.POLISHED_TUFF_HIT); + public static final CompatSoundEvent BLOCK_POLISHED_TUFF_PLACE = new CompatSoundEvent(SoundEvents.POLISHED_TUFF_PLACE); + public static final CompatSoundEvent BLOCK_POLISHED_TUFF_STEP = new CompatSoundEvent(SoundEvents.POLISHED_TUFF_STEP); + public static final CompatSoundEvent ENTITY_TURTLE_AMBIENT_LAND = new CompatSoundEvent(SoundEvents.TURTLE_AMBIENT_LAND); + public static final CompatSoundEvent ENTITY_TURTLE_DEATH = new CompatSoundEvent(SoundEvents.TURTLE_DEATH); + public static final CompatSoundEvent ENTITY_TURTLE_DEATH_BABY = new CompatSoundEvent(SoundEvents.TURTLE_DEATH_BABY); + public static final CompatSoundEvent ENTITY_TURTLE_EGG_BREAK = new CompatSoundEvent(SoundEvents.TURTLE_EGG_BREAK); + public static final CompatSoundEvent ENTITY_TURTLE_EGG_CRACK = new CompatSoundEvent(SoundEvents.TURTLE_EGG_CRACK); + public static final CompatSoundEvent ENTITY_TURTLE_EGG_HATCH = new CompatSoundEvent(SoundEvents.TURTLE_EGG_HATCH); + public static final CompatSoundEvent ENTITY_TURTLE_HURT = new CompatSoundEvent(SoundEvents.TURTLE_HURT); + public static final CompatSoundEvent ENTITY_TURTLE_HURT_BABY = new CompatSoundEvent(SoundEvents.TURTLE_HURT_BABY); + public static final CompatSoundEvent ENTITY_TURTLE_LAY_EGG = new CompatSoundEvent(SoundEvents.TURTLE_LAY_EGG); + public static final CompatSoundEvent ENTITY_TURTLE_SHAMBLE = new CompatSoundEvent(SoundEvents.TURTLE_SHAMBLE); + public static final CompatSoundEvent ENTITY_TURTLE_SHAMBLE_BABY = new CompatSoundEvent(SoundEvents.TURTLE_SHAMBLE_BABY); + public static final CompatSoundEvent ENTITY_TURTLE_SWIM = new CompatSoundEvent(SoundEvents.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.VAULT_ACTIVATE); + public static final CompatSoundEvent BLOCK_VAULT_AMBIENT = new CompatSoundEvent(SoundEvents.VAULT_AMBIENT); + public static final CompatSoundEvent BLOCK_VAULT_BREAK = new CompatSoundEvent(SoundEvents.VAULT_BREAK); + public static final CompatSoundEvent BLOCK_VAULT_CLOSE_SHUTTER = new CompatSoundEvent(SoundEvents.VAULT_CLOSE_SHUTTER); + public static final CompatSoundEvent BLOCK_VAULT_DEACTIVATE = new CompatSoundEvent(SoundEvents.VAULT_DEACTIVATE); + public static final CompatSoundEvent BLOCK_VAULT_EJECT_ITEM = new CompatSoundEvent(SoundEvents.VAULT_EJECT_ITEM); + public static final CompatSoundEvent BLOCK_VAULT_REJECT_REWARDED_PLAYER = new CompatSoundEvent(SoundEvents.VAULT_REJECT_REWARDED_PLAYER); + public static final CompatSoundEvent BLOCK_VAULT_FALL = new CompatSoundEvent(SoundEvents.VAULT_FALL); + public static final CompatSoundEvent BLOCK_VAULT_HIT = new CompatSoundEvent(SoundEvents.VAULT_HIT); + public static final CompatSoundEvent BLOCK_VAULT_INSERT_ITEM = new CompatSoundEvent(SoundEvents.VAULT_INSERT_ITEM); + public static final CompatSoundEvent BLOCK_VAULT_INSERT_ITEM_FAIL = new CompatSoundEvent(SoundEvents.VAULT_INSERT_ITEM_FAIL); + public static final CompatSoundEvent BLOCK_VAULT_OPEN_SHUTTER = new CompatSoundEvent(SoundEvents.VAULT_OPEN_SHUTTER); + public static final CompatSoundEvent BLOCK_VAULT_PLACE = new CompatSoundEvent(SoundEvents.VAULT_PLACE); + public static final CompatSoundEvent BLOCK_VAULT_STEP = new CompatSoundEvent(SoundEvents.VAULT_STEP); + public static final CompatSoundEvent ENTITY_VEX_AMBIENT = new CompatSoundEvent(SoundEvents.VEX_AMBIENT); + public static final CompatSoundEvent ENTITY_VEX_CHARGE = new CompatSoundEvent(SoundEvents.VEX_CHARGE); + public static final CompatSoundEvent ENTITY_VEX_DEATH = new CompatSoundEvent(SoundEvents.VEX_DEATH); + public static final CompatSoundEvent ENTITY_VEX_HURT = new CompatSoundEvent(SoundEvents.VEX_HURT); + public static final CompatSoundEvent ENTITY_VILLAGER_AMBIENT = new CompatSoundEvent(SoundEvents.VILLAGER_AMBIENT); + public static final CompatSoundEvent ENTITY_VILLAGER_CELEBRATE = new CompatSoundEvent(SoundEvents.VILLAGER_CELEBRATE); + public static final CompatSoundEvent ENTITY_VILLAGER_DEATH = new CompatSoundEvent(SoundEvents.VILLAGER_DEATH); + public static final CompatSoundEvent ENTITY_VILLAGER_HURT = new CompatSoundEvent(SoundEvents.VILLAGER_HURT); + public static final CompatSoundEvent ENTITY_VILLAGER_NO = new CompatSoundEvent(SoundEvents.VILLAGER_NO); + public static final CompatSoundEvent ENTITY_VILLAGER_TRADE = new CompatSoundEvent(SoundEvents.VILLAGER_TRADE); + public static final CompatSoundEvent ENTITY_VILLAGER_YES = new CompatSoundEvent(SoundEvents.VILLAGER_YES); + public static final CompatSoundEvent ENTITY_VILLAGER_WORK_ARMORER = new CompatSoundEvent(SoundEvents.VILLAGER_WORK_ARMORER); + public static final CompatSoundEvent ENTITY_VILLAGER_WORK_BUTCHER = new CompatSoundEvent(SoundEvents.VILLAGER_WORK_BUTCHER); + public static final CompatSoundEvent ENTITY_VILLAGER_WORK_CARTOGRAPHER = new CompatSoundEvent(SoundEvents.VILLAGER_WORK_CARTOGRAPHER); + public static final CompatSoundEvent ENTITY_VILLAGER_WORK_CLERIC = new CompatSoundEvent(SoundEvents.VILLAGER_WORK_CLERIC); + public static final CompatSoundEvent ENTITY_VILLAGER_WORK_FARMER = new CompatSoundEvent(SoundEvents.VILLAGER_WORK_FARMER); + public static final CompatSoundEvent ENTITY_VILLAGER_WORK_FISHERMAN = new CompatSoundEvent(SoundEvents.VILLAGER_WORK_FISHERMAN); + public static final CompatSoundEvent ENTITY_VILLAGER_WORK_FLETCHER = new CompatSoundEvent(SoundEvents.VILLAGER_WORK_FLETCHER); + public static final CompatSoundEvent ENTITY_VILLAGER_WORK_LEATHERWORKER = new CompatSoundEvent(SoundEvents.VILLAGER_WORK_LEATHERWORKER); + public static final CompatSoundEvent ENTITY_VILLAGER_WORK_LIBRARIAN = new CompatSoundEvent(SoundEvents.VILLAGER_WORK_LIBRARIAN); + public static final CompatSoundEvent ENTITY_VILLAGER_WORK_MASON = new CompatSoundEvent(SoundEvents.VILLAGER_WORK_MASON); + public static final CompatSoundEvent ENTITY_VILLAGER_WORK_SHEPHERD = new CompatSoundEvent(SoundEvents.VILLAGER_WORK_SHEPHERD); + public static final CompatSoundEvent ENTITY_VILLAGER_WORK_TOOLSMITH = new CompatSoundEvent(SoundEvents.VILLAGER_WORK_TOOLSMITH); + public static final CompatSoundEvent ENTITY_VILLAGER_WORK_WEAPONSMITH = new CompatSoundEvent(SoundEvents.VILLAGER_WORK_WEAPONSMITH); + public static final CompatSoundEvent ENTITY_VINDICATOR_AMBIENT = new CompatSoundEvent(SoundEvents.VINDICATOR_AMBIENT); + public static final CompatSoundEvent ENTITY_VINDICATOR_CELEBRATE = new CompatSoundEvent(SoundEvents.VINDICATOR_CELEBRATE); + public static final CompatSoundEvent ENTITY_VINDICATOR_DEATH = new CompatSoundEvent(SoundEvents.VINDICATOR_DEATH); + public static final CompatSoundEvent ENTITY_VINDICATOR_HURT = new CompatSoundEvent(SoundEvents.VINDICATOR_HURT); + public static final CompatSoundEvent BLOCK_VINE_BREAK = new CompatSoundEvent(SoundEvents.VINE_BREAK); + public static final CompatSoundEvent BLOCK_VINE_FALL = new CompatSoundEvent(SoundEvents.VINE_FALL); + public static final CompatSoundEvent BLOCK_VINE_HIT = new CompatSoundEvent(SoundEvents.VINE_HIT); + public static final CompatSoundEvent BLOCK_VINE_PLACE = new CompatSoundEvent(SoundEvents.VINE_PLACE); + public static final CompatSoundEvent BLOCK_VINE_STEP = new CompatSoundEvent(SoundEvents.VINE_STEP); + public static final CompatSoundEvent BLOCK_LILY_PAD_PLACE = new CompatSoundEvent(SoundEvents.LILY_PAD_PLACE); + public static final CompatSoundEvent ENTITY_WANDERING_TRADER_AMBIENT = new CompatSoundEvent(SoundEvents.WANDERING_TRADER_AMBIENT); + public static final CompatSoundEvent ENTITY_WANDERING_TRADER_DEATH = new CompatSoundEvent(SoundEvents.WANDERING_TRADER_DEATH); + public static final CompatSoundEvent ENTITY_WANDERING_TRADER_DISAPPEARED = new CompatSoundEvent(SoundEvents.WANDERING_TRADER_DISAPPEARED); + public static final CompatSoundEvent ENTITY_WANDERING_TRADER_DRINK_MILK = new CompatSoundEvent(SoundEvents.WANDERING_TRADER_DRINK_MILK); + public static final CompatSoundEvent ENTITY_WANDERING_TRADER_DRINK_POTION = new CompatSoundEvent(SoundEvents.WANDERING_TRADER_DRINK_POTION); + public static final CompatSoundEvent ENTITY_WANDERING_TRADER_HURT = new CompatSoundEvent(SoundEvents.WANDERING_TRADER_HURT); + public static final CompatSoundEvent ENTITY_WANDERING_TRADER_NO = new CompatSoundEvent(SoundEvents.WANDERING_TRADER_NO); + public static final CompatSoundEvent ENTITY_WANDERING_TRADER_REAPPEARED = new CompatSoundEvent(SoundEvents.WANDERING_TRADER_REAPPEARED); + public static final CompatSoundEvent ENTITY_WANDERING_TRADER_TRADE = new CompatSoundEvent(SoundEvents.WANDERING_TRADER_TRADE); + public static final CompatSoundEvent ENTITY_WANDERING_TRADER_YES = new CompatSoundEvent(SoundEvents.WANDERING_TRADER_YES); + public static final CompatSoundEvent ENTITY_WARDEN_AGITATED = new CompatSoundEvent(SoundEvents.WARDEN_AGITATED); + public static final CompatSoundEvent ENTITY_WARDEN_AMBIENT = new CompatSoundEvent(SoundEvents.WARDEN_AMBIENT); + public static final CompatSoundEvent ENTITY_WARDEN_ANGRY = new CompatSoundEvent(SoundEvents.WARDEN_ANGRY); + public static final CompatSoundEvent ENTITY_WARDEN_ATTACK_IMPACT = new CompatSoundEvent(SoundEvents.WARDEN_ATTACK_IMPACT); + public static final CompatSoundEvent ENTITY_WARDEN_DEATH = new CompatSoundEvent(SoundEvents.WARDEN_DEATH); + public static final CompatSoundEvent ENTITY_WARDEN_DIG = new CompatSoundEvent(SoundEvents.WARDEN_DIG); + public static final CompatSoundEvent ENTITY_WARDEN_EMERGE = new CompatSoundEvent(SoundEvents.WARDEN_EMERGE); + public static final CompatSoundEvent ENTITY_WARDEN_HEARTBEAT = new CompatSoundEvent(SoundEvents.WARDEN_HEARTBEAT); + public static final CompatSoundEvent ENTITY_WARDEN_HURT = new CompatSoundEvent(SoundEvents.WARDEN_HURT); + public static final CompatSoundEvent ENTITY_WARDEN_LISTENING = new CompatSoundEvent(SoundEvents.WARDEN_LISTENING); + public static final CompatSoundEvent ENTITY_WARDEN_LISTENING_ANGRY = new CompatSoundEvent(SoundEvents.WARDEN_LISTENING_ANGRY); + public static final CompatSoundEvent ENTITY_WARDEN_NEARBY_CLOSE = new CompatSoundEvent(SoundEvents.WARDEN_NEARBY_CLOSE); + public static final CompatSoundEvent ENTITY_WARDEN_NEARBY_CLOSER = new CompatSoundEvent(SoundEvents.WARDEN_NEARBY_CLOSER); + public static final CompatSoundEvent ENTITY_WARDEN_NEARBY_CLOSEST = new CompatSoundEvent(SoundEvents.WARDEN_NEARBY_CLOSEST); + public static final CompatSoundEvent ENTITY_WARDEN_ROAR = new CompatSoundEvent(SoundEvents.WARDEN_ROAR); + public static final CompatSoundEvent ENTITY_WARDEN_SNIFF = new CompatSoundEvent(SoundEvents.WARDEN_SNIFF); + public static final CompatSoundEvent ENTITY_WARDEN_SONIC_BOOM = new CompatSoundEvent(SoundEvents.WARDEN_SONIC_BOOM); + public static final CompatSoundEvent ENTITY_WARDEN_SONIC_CHARGE = new CompatSoundEvent(SoundEvents.WARDEN_SONIC_CHARGE); + public static final CompatSoundEvent ENTITY_WARDEN_STEP = new CompatSoundEvent(SoundEvents.WARDEN_STEP); + public static final CompatSoundEvent ENTITY_WARDEN_TENDRIL_CLICKS = new CompatSoundEvent(SoundEvents.WARDEN_TENDRIL_CLICKS); + public static final CompatSoundEvent BLOCK_HANGING_SIGN_WAXED_INTERACT_FAIL = new CompatSoundEvent(SoundEvents.WAXED_HANGING_SIGN_INTERACT_FAIL); + public static final CompatSoundEvent BLOCK_SIGN_WAXED_INTERACT_FAIL = new CompatSoundEvent(SoundEvents.WAXED_SIGN_INTERACT_FAIL); + public static final CompatSoundEvent BLOCK_WATER_AMBIENT = new CompatSoundEvent(SoundEvents.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.WET_GRASS_BREAK); + public static final CompatSoundEvent BLOCK_WET_GRASS_FALL = new CompatSoundEvent(SoundEvents.WET_GRASS_FALL); + public static final CompatSoundEvent BLOCK_WET_GRASS_HIT = new CompatSoundEvent(SoundEvents.WET_GRASS_HIT); + public static final CompatSoundEvent BLOCK_WET_GRASS_PLACE = new CompatSoundEvent(SoundEvents.WET_GRASS_PLACE); + public static final CompatSoundEvent BLOCK_WET_GRASS_STEP = new CompatSoundEvent(SoundEvents.WET_GRASS_STEP); + public static final CompatSoundEvent BLOCK_WET_SPONGE_BREAK = new CompatSoundEvent(SoundEvents.WET_SPONGE_BREAK); + public static final CompatSoundEvent BLOCK_WET_SPONGE_DRIES = new CompatSoundEvent(SoundEvents.WET_SPONGE_DRIES); + public static final CompatSoundEvent BLOCK_WET_SPONGE_FALL = new CompatSoundEvent(SoundEvents.WET_SPONGE_FALL); + public static final CompatSoundEvent BLOCK_WET_SPONGE_HIT = new CompatSoundEvent(SoundEvents.WET_SPONGE_HIT); + public static final CompatSoundEvent BLOCK_WET_SPONGE_PLACE = new CompatSoundEvent(SoundEvents.WET_SPONGE_PLACE); + public static final CompatSoundEvent BLOCK_WET_SPONGE_STEP = new CompatSoundEvent(SoundEvents.WET_SPONGE_STEP); + public static final CompatSoundEvent ENTITY_WIND_CHARGE_WIND_BURST = new CompatSoundEvent(SoundEvents.WIND_CHARGE_BURST); + public static final CompatSoundEvent ENTITY_WIND_CHARGE_THROW = new CompatSoundEvent(SoundEvents.WIND_CHARGE_THROW); + public static final CompatSoundEvent ENTITY_WITCH_AMBIENT = new CompatSoundEvent(SoundEvents.WITCH_AMBIENT); + public static final CompatSoundEvent ENTITY_WITCH_CELEBRATE = new CompatSoundEvent(SoundEvents.WITCH_CELEBRATE); + public static final CompatSoundEvent ENTITY_WITCH_DEATH = new CompatSoundEvent(SoundEvents.WITCH_DEATH); + public static final CompatSoundEvent ENTITY_WITCH_DRINK = new CompatSoundEvent(SoundEvents.WITCH_DRINK); + public static final CompatSoundEvent ENTITY_WITCH_HURT = new CompatSoundEvent(SoundEvents.WITCH_HURT); + public static final CompatSoundEvent ENTITY_WITCH_THROW = new CompatSoundEvent(SoundEvents.WITCH_THROW); + public static final CompatSoundEvent ENTITY_WITHER_AMBIENT = new CompatSoundEvent(SoundEvents.WITHER_AMBIENT); + public static final CompatSoundEvent ENTITY_WITHER_BREAK_BLOCK = new CompatSoundEvent(SoundEvents.WITHER_BREAK_BLOCK); + public static final CompatSoundEvent ENTITY_WITHER_DEATH = new CompatSoundEvent(SoundEvents.WITHER_DEATH); + public static final CompatSoundEvent ENTITY_WITHER_HURT = new CompatSoundEvent(SoundEvents.WITHER_HURT); + public static final CompatSoundEvent ENTITY_WITHER_SHOOT = new CompatSoundEvent(SoundEvents.WITHER_SHOOT); + public static final CompatSoundEvent ENTITY_WITHER_SKELETON_AMBIENT = new CompatSoundEvent(SoundEvents.WITHER_SKELETON_AMBIENT); + public static final CompatSoundEvent ENTITY_WITHER_SKELETON_DEATH = new CompatSoundEvent(SoundEvents.WITHER_SKELETON_DEATH); + public static final CompatSoundEvent ENTITY_WITHER_SKELETON_HURT = new CompatSoundEvent(SoundEvents.WITHER_SKELETON_HURT); + public static final CompatSoundEvent ENTITY_WITHER_SKELETON_STEP = new CompatSoundEvent(SoundEvents.WITHER_SKELETON_STEP); + public static final CompatSoundEvent ENTITY_WITHER_SPAWN = new CompatSoundEvent(SoundEvents.WITHER_SPAWN); + public static final CompatSoundEvent ITEM_WOLF_ARMOR_BREAK = new CompatSoundEvent(SoundEvents.WOLF_ARMOR_BREAK); + public static final CompatSoundEvent ITEM_WOLF_ARMOR_CRACK = new CompatSoundEvent(SoundEvents.WOLF_ARMOR_CRACK); + public static final CompatSoundEvent ITEM_WOLF_ARMOR_DAMAGE = new CompatSoundEvent(SoundEvents.WOLF_ARMOR_DAMAGE); + public static final CompatSoundEvent ITEM_WOLF_ARMOR_REPAIR = new CompatSoundEvent(SoundEvents.WOLF_ARMOR_REPAIR); + public static final CompatSoundEvent ENTITY_WOLF_AMBIENT = new CompatSoundEvent(SoundEvents.WOLF_SOUNDS.get(WolfSoundVariants.SoundSet.CLASSIC).adultSounds().ambientSound()); + public static final CompatSoundEvent ENTITY_WOLF_DEATH = new CompatSoundEvent(SoundEvents.WOLF_SOUNDS.get(WolfSoundVariants.SoundSet.CLASSIC).adultSounds().deathSound()); + public static final CompatSoundEvent ENTITY_WOLF_GROWL = new CompatSoundEvent(SoundEvents.WOLF_SOUNDS.get(WolfSoundVariants.SoundSet.CLASSIC).adultSounds().growlSound()); + public static final CompatSoundEvent ENTITY_WOLF_HOWL = new CompatSoundEvent(SoundEvents.WOLF_SOUNDS.get(WolfSoundVariants.SoundSet.CLASSIC).adultSounds().ambientSound()); + public static final CompatSoundEvent ENTITY_WOLF_HURT = new CompatSoundEvent(SoundEvents.WOLF_SOUNDS.get(WolfSoundVariants.SoundSet.CLASSIC).adultSounds().hurtSound()); + public static final CompatSoundEvent ENTITY_WOLF_PANT = new CompatSoundEvent(SoundEvents.WOLF_SOUNDS.get(WolfSoundVariants.SoundSet.CLASSIC).adultSounds().pantSound()); + public static final CompatSoundEvent ENTITY_WOLF_SHAKE = new CompatSoundEvent(SoundEvents.WOLF_SHAKE); + public static final CompatSoundEvent ENTITY_WOLF_STEP = new CompatSoundEvent(SoundEvents.WOLF_STEP); + public static final CompatSoundEvent ENTITY_WOLF_WHINE = new CompatSoundEvent(SoundEvents.WOLF_SOUNDS.get(WolfSoundVariants.SoundSet.CLASSIC).adultSounds().whineSound()); + public static final CompatSoundEvent BLOCK_WOODEN_DOOR_CLOSE = new CompatSoundEvent(SoundEvents.WOODEN_DOOR_CLOSE); + public static final CompatSoundEvent BLOCK_WOODEN_DOOR_OPEN = new CompatSoundEvent(SoundEvents.WOODEN_DOOR_OPEN); + public static final CompatSoundEvent BLOCK_WOODEN_TRAPDOOR_CLOSE = new CompatSoundEvent(SoundEvents.WOODEN_TRAPDOOR_CLOSE); + public static final CompatSoundEvent BLOCK_WOODEN_TRAPDOOR_OPEN = new CompatSoundEvent(SoundEvents.WOODEN_TRAPDOOR_OPEN); + public static final CompatSoundEvent BLOCK_WOODEN_BUTTON_CLICK_OFF = new CompatSoundEvent(SoundEvents.WOODEN_BUTTON_CLICK_OFF); + public static final CompatSoundEvent BLOCK_WOODEN_BUTTON_CLICK_ON = new CompatSoundEvent(SoundEvents.WOODEN_BUTTON_CLICK_ON); + public static final CompatSoundEvent BLOCK_WOODEN_PRESSURE_PLATE_CLICK_OFF = new CompatSoundEvent(SoundEvents.WOODEN_PRESSURE_PLATE_CLICK_OFF); + public static final CompatSoundEvent BLOCK_WOODEN_PRESSURE_PLATE_CLICK_ON = new CompatSoundEvent(SoundEvents.WOODEN_PRESSURE_PLATE_CLICK_ON); + public static final CompatSoundEvent BLOCK_WOOD_BREAK = new CompatSoundEvent(SoundEvents.WOOD_BREAK); + public static final CompatSoundEvent BLOCK_WOOD_FALL = new CompatSoundEvent(SoundEvents.WOOD_FALL); + public static final CompatSoundEvent BLOCK_WOOD_HIT = new CompatSoundEvent(SoundEvents.WOOD_HIT); + public static final CompatSoundEvent BLOCK_WOOD_PLACE = new CompatSoundEvent(SoundEvents.WOOD_PLACE); + public static final CompatSoundEvent BLOCK_WOOD_STEP = new CompatSoundEvent(SoundEvents.WOOD_STEP); + public static final CompatSoundEvent BLOCK_WOOL_BREAK = new CompatSoundEvent(SoundEvents.WOOL_BREAK); + public static final CompatSoundEvent BLOCK_WOOL_FALL = new CompatSoundEvent(SoundEvents.WOOL_FALL); + public static final CompatSoundEvent BLOCK_WOOL_HIT = new CompatSoundEvent(SoundEvents.WOOL_HIT); + public static final CompatSoundEvent BLOCK_WOOL_PLACE = new CompatSoundEvent(SoundEvents.WOOL_PLACE); + public static final CompatSoundEvent BLOCK_WOOL_STEP = new CompatSoundEvent(SoundEvents.WOOL_STEP); + public static final CompatSoundEvent ENTITY_ZOGLIN_AMBIENT = new CompatSoundEvent(SoundEvents.ZOGLIN_AMBIENT); + public static final CompatSoundEvent ENTITY_ZOGLIN_ANGRY = new CompatSoundEvent(SoundEvents.ZOGLIN_ANGRY); + public static final CompatSoundEvent ENTITY_ZOGLIN_ATTACK = new CompatSoundEvent(SoundEvents.ZOGLIN_ATTACK); + public static final CompatSoundEvent ENTITY_ZOGLIN_DEATH = new CompatSoundEvent(SoundEvents.ZOGLIN_DEATH); + public static final CompatSoundEvent ENTITY_ZOGLIN_HURT = new CompatSoundEvent(SoundEvents.ZOGLIN_HURT); + public static final CompatSoundEvent ENTITY_ZOGLIN_STEP = new CompatSoundEvent(SoundEvents.ZOGLIN_STEP); + public static final CompatSoundEvent ENTITY_ZOMBIE_AMBIENT = new CompatSoundEvent(SoundEvents.ZOMBIE_AMBIENT); + public static final CompatSoundEvent ENTITY_ZOMBIE_ATTACK_WOODEN_DOOR = new CompatSoundEvent(SoundEvents.ZOMBIE_ATTACK_WOODEN_DOOR); + public static final CompatSoundEvent ENTITY_ZOMBIE_ATTACK_IRON_DOOR = new CompatSoundEvent(SoundEvents.ZOMBIE_ATTACK_IRON_DOOR); + public static final CompatSoundEvent ENTITY_ZOMBIE_BREAK_WOODEN_DOOR = new CompatSoundEvent(SoundEvents.ZOMBIE_BREAK_WOODEN_DOOR); + public static final CompatSoundEvent ENTITY_ZOMBIE_CONVERTED_TO_DROWNED = new CompatSoundEvent(SoundEvents.ZOMBIE_CONVERTED_TO_DROWNED); + public static final CompatSoundEvent ENTITY_ZOMBIE_DEATH = new CompatSoundEvent(SoundEvents.ZOMBIE_DEATH); + public static final CompatSoundEvent ENTITY_ZOMBIE_DESTROY_EGG = new CompatSoundEvent(SoundEvents.ZOMBIE_DESTROY_EGG); + public static final CompatSoundEvent ENTITY_ZOMBIE_HORSE_AMBIENT = new CompatSoundEvent(SoundEvents.ZOMBIE_HORSE_AMBIENT); + public static final CompatSoundEvent ENTITY_ZOMBIE_HORSE_DEATH = new CompatSoundEvent(SoundEvents.ZOMBIE_HORSE_DEATH); + public static final CompatSoundEvent ENTITY_ZOMBIE_HORSE_HURT = new CompatSoundEvent(SoundEvents.ZOMBIE_HORSE_HURT); + public static final CompatSoundEvent ENTITY_ZOMBIE_HURT = new CompatSoundEvent(SoundEvents.ZOMBIE_HURT); + public static final CompatSoundEvent ENTITY_ZOMBIE_INFECT = new CompatSoundEvent(SoundEvents.ZOMBIE_INFECT); + public static final CompatSoundEvent ENTITY_ZOMBIFIED_PIGLIN_AMBIENT = new CompatSoundEvent(SoundEvents.ZOMBIFIED_PIGLIN_AMBIENT); + public static final CompatSoundEvent ENTITY_ZOMBIFIED_PIGLIN_ANGRY = new CompatSoundEvent(SoundEvents.ZOMBIFIED_PIGLIN_ANGRY); + public static final CompatSoundEvent ENTITY_ZOMBIFIED_PIGLIN_DEATH = new CompatSoundEvent(SoundEvents.ZOMBIFIED_PIGLIN_DEATH); + public static final CompatSoundEvent ENTITY_ZOMBIFIED_PIGLIN_HURT = new CompatSoundEvent(SoundEvents.ZOMBIFIED_PIGLIN_HURT); + public static final CompatSoundEvent ENTITY_ZOMBIE_STEP = new CompatSoundEvent(SoundEvents.ZOMBIE_STEP); + public static final CompatSoundEvent ENTITY_ZOMBIE_VILLAGER_AMBIENT = new CompatSoundEvent(SoundEvents.ZOMBIE_VILLAGER_AMBIENT); + public static final CompatSoundEvent ENTITY_ZOMBIE_VILLAGER_CONVERTED = new CompatSoundEvent(SoundEvents.ZOMBIE_VILLAGER_CONVERTED); + public static final CompatSoundEvent ENTITY_ZOMBIE_VILLAGER_CURE = new CompatSoundEvent(SoundEvents.ZOMBIE_VILLAGER_CURE); + public static final CompatSoundEvent ENTITY_ZOMBIE_VILLAGER_DEATH = new CompatSoundEvent(SoundEvents.ZOMBIE_VILLAGER_DEATH); + public static final CompatSoundEvent ENTITY_ZOMBIE_VILLAGER_HURT = new CompatSoundEvent(SoundEvents.ZOMBIE_VILLAGER_HURT); + public static final CompatSoundEvent ENTITY_ZOMBIE_VILLAGER_STEP = new CompatSoundEvent(SoundEvents.ZOMBIE_VILLAGER_STEP); + public static final CompatSoundEvent EVENT_MOB_EFFECT_BAD_OMEN = new CompatSoundEvent(SoundEvents.APPLY_EFFECT_BAD_OMEN); + public static final CompatSoundEvent EVENT_MOB_EFFECT_TRIAL_OMEN = new CompatSoundEvent(SoundEvents.APPLY_EFFECT_TRIAL_OMEN); + public static final CompatSoundEvent EVENT_MOB_EFFECT_RAID_OMEN = new CompatSoundEvent(SoundEvents.APPLY_EFFECT_RAID_OMEN); + public static final CompatSoundEvent ENTITY_HAPPY_GHAST_EQUIP = new CompatSoundEvent(SoundEvents.HARNESS_EQUIP); + public static final CompatSoundEvent ENTITY_HAPPY_GHAST_AMBIENT = new CompatSoundEvent(SoundEvents.HAPPY_GHAST_AMBIENT); + public static final CompatSoundEvent ENTITY_HAPPY_GHAST_DEATH = new CompatSoundEvent(SoundEvents.HAPPY_GHAST_DEATH); + public static final CompatSoundEvent ENTITY_HAPPY_GHAST_HURT = new CompatSoundEvent(SoundEvents.HAPPY_GHAST_HURT); + public static final CompatSoundEvent ENTITY_HAPPY_GHAST_RIDING = new CompatSoundEvent(SoundEvents.HAPPY_GHAST_RIDING); + public static final CompatSoundEvent ENTITY_HAPPY_GHAST_HARNESS_GOGGLES_DOWN = new CompatSoundEvent(SoundEvents.HARNESS_GOGGLES_DOWN); + public static final CompatSoundEvent ENTITY_HAPPY_GHAST_HARNESS_GOGGLES_UP = new CompatSoundEvent(SoundEvents.HARNESS_GOGGLES_UP); + public static final CompatSoundEvent ENTITY_HAPPY_GHAST_UNEQUIP = new CompatSoundEvent(SoundEvents.HARNESS_UNEQUIP); + + static { + GOAT_HORN_SOUNDS = SoundEvents.GOAT_HORN_SOUND_VARIANTS.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..46f4f14db --- /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.sounds.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/BlockHalfProperty.java b/common/src/main/java/net/pitan76/mcpitanlib/api/state/property/BlockHalfProperty.java new file mode 100644 index 000000000..0736b97b0 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/state/property/BlockHalfProperty.java @@ -0,0 +1,34 @@ +package net.pitan76.mcpitanlib.api.state.property; + +import net.minecraft.world.level.block.state.properties.Half; +import net.pitan76.mcpitanlib.api.util.block.properties.CompatBlockHalf; +import net.pitan76.mcpitanlib.midohra.block.BlockState; + +import java.util.function.Predicate; + +public class BlockHalfProperty extends EnumProperty { + + public BlockHalfProperty(String name, Class type) { + super(name, type); + } + + public BlockHalfProperty(String name, Class type, Predicate filter) { + super(name, type, filter); + } + + public BlockHalfProperty(net.minecraft.world.level.block.state.properties.EnumProperty property) { + super(property); + } + + public static BlockHalfProperty ofRaw(net.minecraft.world.level.block.state.properties.EnumProperty property) { + return new BlockHalfProperty(property); + } + + public BlockState with(BlockState state, CompatBlockHalf value) { + return super.with(state, value.getBlockHalf()); + } + + public CompatBlockHalf getCompat(BlockState state) { + return CompatBlockHalf.of(super.get(state)); + } +} 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..86bcdd66f --- /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.world.level.block.state.properties.BooleanProperty property; + + public BooleanProperty(String name) { + this(net.minecraft.world.level.block.state.properties.BooleanProperty.create(name)); + } + + public BooleanProperty(net.minecraft.world.level.block.state.properties.BooleanProperty property) { + this.property = property; + } + + public static BooleanProperty of(String name) { + return new BooleanProperty(name); + } + + public static BooleanProperty of(net.minecraft.world.level.block.state.properties.BooleanProperty property) { + return new BooleanProperty(property); + } + + @Override + public net.minecraft.world.level.block.state.properties.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..0bd546f71 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/state/property/CompatProperties.java @@ -0,0 +1,122 @@ +package net.pitan76.mcpitanlib.api.state.property; + +import net.minecraft.world.level.block.state.properties.BlockStateProperties; +import net.minecraft.world.level.block.state.properties.ChestType; +import net.minecraft.world.level.block.state.properties.ComparatorMode; +import net.minecraft.world.level.block.state.properties.Half; +import net.minecraft.world.level.block.state.properties.PistonType; +import net.minecraft.world.level.block.state.properties.Property; +import net.minecraft.util.StringRepresentable; +import net.minecraft.core.Direction; +import net.minecraft.world.level.block.state.properties.SlabType; +import net.minecraft.world.level.block.state.properties.StairsShape; + +public class CompatProperties { + public static final DirectionProperty FACING = new DirectionProperty(BlockStateProperties.FACING); + public static final DirectionProperty HORIZONTAL_FACING = new DirectionProperty(BlockStateProperties.HORIZONTAL_FACING); + public static final DirectionProperty HOPPER_FACING = new DirectionProperty(BlockStateProperties.FACING_HOPPER); + public static final DirectionProperty VERTICAL_DIRECTION = new DirectionProperty(BlockStateProperties.VERTICAL_DIRECTION); + + public static final BooleanProperty POWERED = new BooleanProperty(BlockStateProperties.POWERED); + public static final BooleanProperty ENABLED = new BooleanProperty(BlockStateProperties.ENABLED); + public static final BooleanProperty WATERLOGGED = new BooleanProperty(BlockStateProperties.WATERLOGGED); + public static final BooleanProperty LIT = new BooleanProperty(BlockStateProperties.LIT); + public static final BooleanProperty OCCUPIED = new BooleanProperty(BlockStateProperties.OCCUPIED); + public static final BooleanProperty ATTACHED = new BooleanProperty(BlockStateProperties.ATTACHED); + public static final BooleanProperty HANGING = new BooleanProperty(BlockStateProperties.HANGING); + public static final BooleanProperty BOTTOM = new BooleanProperty(BlockStateProperties.BOTTOM); + public static final BooleanProperty OPEN = new BooleanProperty(BlockStateProperties.OPEN); + public static final BooleanProperty UNSTABLE = new BooleanProperty(BlockStateProperties.UNSTABLE); + public static final BooleanProperty UP = new BooleanProperty(BlockStateProperties.UP); + public static final BooleanProperty DOWN = new BooleanProperty(BlockStateProperties.DOWN); + public static final BooleanProperty NORTH = new BooleanProperty(BlockStateProperties.NORTH); + public static final BooleanProperty EAST = new BooleanProperty(BlockStateProperties.EAST); + public static final BooleanProperty SOUTH = new BooleanProperty(BlockStateProperties.SOUTH); + public static final BooleanProperty WEST = new BooleanProperty(BlockStateProperties.WEST); + + public static final IntProperty POWER = new IntProperty(BlockStateProperties.POWER); + public static final IntProperty LAYERS = new IntProperty(BlockStateProperties.LAYERS); + public static final IntProperty NOTE = new IntProperty(BlockStateProperties.NOTE); + public static final IntProperty ROTATION = new IntProperty(BlockStateProperties.ROTATION_16); + public static final IntProperty EGGS = new IntProperty(BlockStateProperties.EGGS); + public static final IntProperty DELAY = new IntProperty(BlockStateProperties.DELAY); + + public static final EnumProperty BLOCK_HALF = new EnumProperty<>(BlockStateProperties.HALF); + public static final EnumProperty STAIR_SHAPE = new EnumProperty<>(BlockStateProperties.STAIRS_SHAPE); + public static final EnumProperty SLAB_TYPE = new EnumProperty<>(BlockStateProperties.SLAB_TYPE); + public static final EnumProperty CHEST_TYPE = new EnumProperty<>(BlockStateProperties.CHEST_TYPE); + public static final EnumProperty PISTON_TYPE = new EnumProperty<>(BlockStateProperties.PISTON_TYPE); + public static final EnumProperty AXIS = new EnumProperty<>(BlockStateProperties.AXIS); + public static final EnumProperty HORIZONTAL_AXIS = new EnumProperty<>(BlockStateProperties.HORIZONTAL_AXIS); + public static final EnumProperty COMPARATOR_MODE = new EnumProperty<>(BlockStateProperties.MODE_COMPARATOR); + + public static IProperty of(Property property) { + if (property instanceof net.minecraft.world.level.block.state.properties.IntegerProperty) { + return of((net.minecraft.world.level.block.state.properties.IntegerProperty) property); + } + if (property instanceof net.minecraft.world.level.block.state.properties.BooleanProperty) { + return of((net.minecraft.world.level.block.state.properties.BooleanProperty) property); + } + if (property instanceof net.minecraft.world.level.block.state.properties.EnumProperty) { + if (property.getValueClass() == Direction.class) { + return ofDir((net.minecraft.world.level.block.state.properties.EnumProperty) property); + } + return of((net.minecraft.world.level.block.state.properties.EnumProperty) property); + } + return UnknownProperty.of(property); + } + + public static IntProperty of(net.minecraft.world.level.block.state.properties.IntegerProperty property) { + if (property == BlockStateProperties.POWER) return POWER; + if (property == BlockStateProperties.LAYERS) return LAYERS; + if (property == BlockStateProperties.NOTE) return NOTE; + if (property == BlockStateProperties.ROTATION_16) return ROTATION; + if (property == BlockStateProperties.EGGS) return EGGS; + if (property == BlockStateProperties.DELAY) return DELAY; + + return new IntProperty(property); + } + + public static BooleanProperty of(net.minecraft.world.level.block.state.properties.BooleanProperty property) { + if (property == BlockStateProperties.POWERED) return POWERED; + if (property == BlockStateProperties.ENABLED) return ENABLED; + if (property == BlockStateProperties.WATERLOGGED) return WATERLOGGED; + if (property == BlockStateProperties.LIT) return LIT; + if (property == BlockStateProperties.OCCUPIED) return OCCUPIED; + if (property == BlockStateProperties.ATTACHED) return ATTACHED; + if (property == BlockStateProperties.HANGING) return HANGING; + if (property == BlockStateProperties.BOTTOM) return BOTTOM; + if (property == BlockStateProperties.OPEN) return OPEN; + if (property == BlockStateProperties.UNSTABLE) return UNSTABLE; + if (property == BlockStateProperties.UP) return UP; + if (property == BlockStateProperties.DOWN) return DOWN; + if (property == BlockStateProperties.NORTH) return NORTH; + if (property == BlockStateProperties.EAST) return EAST; + if (property == BlockStateProperties.SOUTH) return SOUTH; + if (property == BlockStateProperties.WEST) return WEST; + + return new BooleanProperty(property); + } + + public static & StringRepresentable> EnumProperty of(net.minecraft.world.level.block.state.properties.EnumProperty property) { + if (property.equals(BlockStateProperties.HALF)) return (EnumProperty) BLOCK_HALF; + if (property.equals(BlockStateProperties.STAIRS_SHAPE)) return (EnumProperty) STAIR_SHAPE; + if (property.equals(BlockStateProperties.SLAB_TYPE)) return (EnumProperty) SLAB_TYPE; + if (property.equals(BlockStateProperties.CHEST_TYPE)) return (EnumProperty) CHEST_TYPE; + if (property.equals(BlockStateProperties.PISTON_TYPE)) return (EnumProperty) PISTON_TYPE; + if (property.equals(BlockStateProperties.AXIS)) return (EnumProperty) AXIS; + if (property.equals(BlockStateProperties.HORIZONTAL_AXIS)) return (EnumProperty) HORIZONTAL_AXIS; + if (property.equals(BlockStateProperties.MODE_COMPARATOR)) return (EnumProperty) COMPARATOR_MODE; + + return new EnumProperty<>(property); + } + + public static DirectionProperty ofDir(net.minecraft.world.level.block.state.properties.EnumProperty property) { + if (property == BlockStateProperties.FACING) return FACING; + if (property == BlockStateProperties.HORIZONTAL_FACING) return HORIZONTAL_FACING; + if (property == BlockStateProperties.FACING_HOPPER) return HOPPER_FACING; + if (property == BlockStateProperties.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..2fa278e1c --- /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.world.level.block.state.properties.EnumProperty; +import net.minecraft.world.level.block.state.properties.Property; +import net.minecraft.core.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.create(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..2d6b94f03 --- /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.StringRepresentable; + +import java.util.function.Predicate; + +public class EnumProperty & StringRepresentable> implements IProperty { + + private final net.minecraft.world.level.block.state.properties.EnumProperty property; + + public EnumProperty(String name, Class type) { + this(net.minecraft.world.level.block.state.properties.EnumProperty.create(name, type)); + } + + public EnumProperty(String name, Class type, Predicate filter) { + this(net.minecraft.world.level.block.state.properties.EnumProperty.create(name, type, filter)); + } + + public EnumProperty(net.minecraft.world.level.block.state.properties.EnumProperty property) { + this.property = property; + } + + public static & StringRepresentable> EnumProperty of(String name, Class type) { + return new EnumProperty<>(name, type); + } + + public static & StringRepresentable> EnumProperty of(String name, Class type, Predicate filter) { + return new EnumProperty<>(name, type, filter); + } + + + public static & StringRepresentable> EnumProperty of(net.minecraft.world.level.block.state.properties.EnumProperty property) { + return new EnumProperty<>(property); + } + + @Override + public net.minecraft.world.level.block.state.properties.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..868ff1e4b --- /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.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.properties.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.getValue(getProperty()); + } + + default BlockState with(BlockState state, T value) { + return state.setValue(getProperty(), value); + } + + default boolean contains(BlockState state) { + return state.hasProperty(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..b1e2e62e9 --- /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.world.level.block.state.properties.IntegerProperty property; + + public IntProperty(String name, int min, int max) { + this(net.minecraft.world.level.block.state.properties.IntegerProperty.create(name, min, max)); + } + + public IntProperty(String name) { + this(name, 0, 15); + } + + public IntProperty(net.minecraft.world.level.block.state.properties.IntegerProperty 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.world.level.block.state.properties.IntegerProperty property) { + return new IntProperty(property); + } + + @Override + public net.minecraft.world.level.block.state.properties.IntegerProperty getProperty() { + return property; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/state/property/StairShapeProperty.java b/common/src/main/java/net/pitan76/mcpitanlib/api/state/property/StairShapeProperty.java new file mode 100644 index 000000000..e5b241e45 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/state/property/StairShapeProperty.java @@ -0,0 +1,34 @@ +package net.pitan76.mcpitanlib.api.state.property; + +import net.minecraft.world.level.block.state.properties.StairsShape; +import net.pitan76.mcpitanlib.api.util.block.properties.CompatStairShape; +import net.pitan76.mcpitanlib.midohra.block.BlockState; + +import java.util.function.Predicate; + +public class StairShapeProperty extends EnumProperty { + + public StairShapeProperty(String name, Class type) { + super(name, type); + } + + public StairShapeProperty(String name, Class type, Predicate filter) { + super(name, type, filter); + } + + public StairShapeProperty(net.minecraft.world.level.block.state.properties.EnumProperty property) { + super(property); + } + + public static StairShapeProperty ofRaw(net.minecraft.world.level.block.state.properties.EnumProperty property) { + return new StairShapeProperty(property); + } + + public BlockState with(BlockState state, CompatStairShape value) { + return super.with(state, value.getStairShape()); + } + + public CompatStairShape getCompat(BlockState state) { + return CompatStairShape.of(super.get(state)); + } +} 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..10f241c52 --- /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.world.level.block.state.properties.Property; + +public class UnknownProperty implements IProperty { + + private final net.minecraft.world.level.block.state.properties.Property property; + + public UnknownProperty(net.minecraft.world.level.block.state.properties.Property property) { + this.property = property; + } + + public static UnknownProperty of(net.minecraft.world.level.block.state.properties.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..6f37c9dfb --- /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.world.level.block.Block; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.level.material.Fluid; +import net.minecraft.world.item.Item; +import net.minecraft.core.registries.Registries; +import net.minecraft.core.Holder; +import net.minecraft.resources.Identifier; +import net.pitan76.mcpitanlib.api.util.*; + +public class TagKey { + private final net.minecraft.tags.TagKey tagKey; + + @Deprecated + public TagKey(net.minecraft.tags.TagKey tagKey) { + this.tagKey = tagKey; + } + + public static TagKey create(Type type, Identifier identifier) { + return switch (type) { + case BLOCK -> new TagKey<>(net.minecraft.tags.TagKey.create(Registries.BLOCK, identifier)); + case ITEM -> new TagKey<>(net.minecraft.tags.TagKey.create(Registries.ITEM, identifier)); + case FLUID -> new TagKey<>(net.minecraft.tags.TagKey.create(Registries.FLUID, identifier)); + case ENTITY_TYPE -> new TagKey<>(net.minecraft.tags.TagKey.create(Registries.ENTITY_TYPE, identifier)); + }; + } + + public static TagKey create(Type type, CompatIdentifier id) { + return create(type, id.toMinecraft()); + } + + @Deprecated + public net.minecraft.tags.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.tags.TagKey.create(Registries.ITEM, ItemUtil.toID((Item) value)); + if (value instanceof Block) + return getTagKey() == net.minecraft.tags.TagKey.create(Registries.BLOCK, BlockUtil.toID((Block) value)); + if (value instanceof Fluid) + return getTagKey() == net.minecraft.tags.TagKey.create(Registries.FLUID, FluidUtil.toID((Fluid) value)); + if (value instanceof EntityType) + return getTagKey() == net.minecraft.tags.TagKey.create(Registries.ENTITY_TYPE, EntityTypeUtil.toID((EntityType) value)); + + return Holder.direct(value).is(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..9cddf078b --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/tag/item/RepairIngredientTag.java @@ -0,0 +1,64 @@ +package net.pitan76.mcpitanlib.api.tag.item; + +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.Ingredient; +import net.minecraft.core.registries.Registries; +import net.minecraft.tags.ItemTags; +import net.minecraft.tags.TagKey; +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 = new RepairIngredientTag(ItemTags.REPAIRS_LEATHER_ARMOR); + public static final RepairIngredientTag REPAIRS_CHAIN_ARMOR = new RepairIngredientTag(ItemTags.REPAIRS_CHAIN_ARMOR); + public static final RepairIngredientTag REPAIRS_IRON_ARMOR = new RepairIngredientTag(ItemTags.REPAIRS_IRON_ARMOR); + public static final RepairIngredientTag REPAIRS_GOLD_ARMOR = new RepairIngredientTag(ItemTags.REPAIRS_GOLD_ARMOR); + public static final RepairIngredientTag REPAIRS_DIAMOND_ARMOR = new RepairIngredientTag(ItemTags.REPAIRS_DIAMOND_ARMOR); + public static final RepairIngredientTag REPAIRS_NETHERITE_ARMOR = new RepairIngredientTag(ItemTags.REPAIRS_NETHERITE_ARMOR); + public static final RepairIngredientTag REPAIRS_TURTLE_HELMET = new RepairIngredientTag(ItemTags.REPAIRS_TURTLE_HELMET); + public static final RepairIngredientTag REPAIRS_WOLF_ARMOR = new RepairIngredientTag(ItemTags.REPAIRS_WOLF_ARMOR); + public static final RepairIngredientTag WOODEN_TOOL_MATERIALS = new RepairIngredientTag(ItemTags.WOODEN_TOOL_MATERIALS); + public static final RepairIngredientTag STONE_TOOL_MATERIALS = new RepairIngredientTag(ItemTags.STONE_TOOL_MATERIALS); + public static final RepairIngredientTag IRON_TOOL_MATERIALS = new RepairIngredientTag(ItemTags.IRON_TOOL_MATERIALS); + public static final RepairIngredientTag GOLDEN_TOOL_MATERIALS = new RepairIngredientTag(ItemTags.GOLD_TOOL_MATERIALS); + public static final RepairIngredientTag DIAMOND_TOOL_MATERIALS = new RepairIngredientTag(ItemTags.DIAMOND_TOOL_MATERIALS); + public static final RepairIngredientTag NETHERITE_TOOL_MATERIALS = new RepairIngredientTag(ItemTags.NETHERITE_TOOL_MATERIALS); + + private TagKey tag; + + public RepairIngredientTag(CompatIdentifier identifier) { + this.tag = TagKey.create(Registries.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.location()); + } + + public boolean contains(Item item) { + if (item == null || tag == null) + return false; + + return ItemUtil.isInTag(item, CompatIdentifier.fromMinecraft(tag.location())); + } + + 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..627036a1f --- /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.core.Holder; +import net.pitan76.mcpitanlib.api.tag.TagKey; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; + +public class CompatTagKey extends TagKey { + @Deprecated + public CompatTagKey(net.minecraft.tags.TagKey tagKey) { + super(tagKey); + } + + @Deprecated + public static CompatTagKey of(net.minecraft.tags.TagKey tagKey) { + return new CompatTagKey<>(tagKey); + } + + public static CompatTagKey of(CompatTagKeyType type, CompatIdentifier identifier) { + return of(net.minecraft.tags.TagKey.create(type.getRegistryKey(), identifier.toMinecraft())); + } + + public boolean isOf(T value) { + return Holder.direct(value).is(getTagKey()); + } + + public CompatIdentifier getId() { + return CompatIdentifier.fromMinecraft(getTagKey().location()); + } +} 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..c66bb0523 --- /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.world.level.block.Block; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.level.material.Fluid; +import net.minecraft.world.item.Item; +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceKey; +import net.minecraft.core.registries.Registries; +import net.minecraft.world.inventory.MenuType; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; + +public class CompatTagKeyType { + public static final CompatTagKeyType BLOCK = of(Registries.BLOCK); + public static final CompatTagKeyType ITEM = new CompatTagKeyType<>(Registries.ITEM); + public static final CompatTagKeyType FLUID = new CompatTagKeyType<>(Registries.FLUID); + public static final CompatTagKeyType> ENTITY_TYPE = new CompatTagKeyType<>(Registries.ENTITY_TYPE); + public static final CompatTagKeyType> BLOCK_ENTITY_TYPE = new CompatTagKeyType<>(Registries.BLOCK_ENTITY_TYPE); + public static final CompatTagKeyType> SCREEN_HANDLER = new CompatTagKeyType<>(Registries.MENU); + + public final CompatIdentifier id; + + protected CompatTagKeyType(CompatIdentifier id) { + this.id = id; + } + + public static CompatTagKeyType of(CompatIdentifier id) { + return new CompatTagKeyType<>(id); + } + + // RegistryKey + private ResourceKey> key; + + protected CompatTagKeyType(ResourceKey> key) { + this.id = CompatIdentifier.fromMinecraft(key.registry()); + this.key = key; + } + + public static CompatTagKeyType of(ResourceKey> key) { + return new CompatTagKeyType<>(key); + } + + @Deprecated + public ResourceKey> 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..84feb6333 --- /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.world.level.block.Block; +import net.minecraft.tags.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.create(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..2a4de2769 --- /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.world.entity.EntityType; +import net.minecraft.tags.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.create(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..15810680d --- /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.world.level.material.Fluid; +import net.minecraft.tags.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.create(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..ba7da7d87 --- /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.world.item.Item; +import net.minecraft.world.item.crafting.Ingredient; +import net.minecraft.tags.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.tags.TagKey.create(CompatTagKeyType.ITEM.getRegistryKey(), identifier.toMinecraft())); + } + + public Ingredient asIngredient() { + return IngredientUtil.fromTagByIdentifier(getTagKey().location()); + } + + 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..6a53061d4 --- /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.ChatFormatting; +import net.pitan76.mcpitanlib.api.util.CompatStringIdentifiable; + +public class CompatFormatting implements CompatStringIdentifiable { + private final ChatFormatting formatting; + + public static final CompatFormatting BLACK = of(ChatFormatting.BLACK); + public static final CompatFormatting DARK_BLUE = of(ChatFormatting.DARK_BLUE); + public static final CompatFormatting DARK_GREEN = of(ChatFormatting.DARK_GREEN); + public static final CompatFormatting DARK_AQUA = of(ChatFormatting.DARK_AQUA); + public static final CompatFormatting DARK_RED = of(ChatFormatting.DARK_RED); + public static final CompatFormatting DARK_PURPLE = of(ChatFormatting.DARK_PURPLE); + public static final CompatFormatting GOLD = of(ChatFormatting.GOLD); + public static final CompatFormatting GRAY = of(ChatFormatting.GRAY); + public static final CompatFormatting DARK_GRAY = of(ChatFormatting.DARK_GRAY); + public static final CompatFormatting BLUE = of(ChatFormatting.BLUE); + public static final CompatFormatting GREEN = of(ChatFormatting.GREEN); + public static final CompatFormatting AQUA = of(ChatFormatting.AQUA); + public static final CompatFormatting RED = of(ChatFormatting.RED); + public static final CompatFormatting LIGHT_PURPLE = of(ChatFormatting.LIGHT_PURPLE); + public static final CompatFormatting YELLOW = of(ChatFormatting.YELLOW); + public static final CompatFormatting WHITE = of(ChatFormatting.WHITE); + public static final CompatFormatting OBFUSCATED = of(ChatFormatting.OBFUSCATED); + public static final CompatFormatting BOLD = of(ChatFormatting.BOLD); + public static final CompatFormatting STRIKETHROUGH = of(ChatFormatting.STRIKETHROUGH); + public static final CompatFormatting UNDERLINE = of(ChatFormatting.UNDERLINE); + public static final CompatFormatting ITALIC = of(ChatFormatting.ITALIC); + public static final CompatFormatting RESET = of(ChatFormatting.RESET); + + public CompatFormatting(ChatFormatting formatting) { + this.formatting = formatting; + } + + public static CompatFormatting of(ChatFormatting formatting) { + return new CompatFormatting(formatting); + } + + public ChatFormatting getRaw() { + return formatting; + } + + @Override + public String asString_compat() { + return formatting.getSerializedName(); + } + + public boolean isColor() { + return formatting.isColor(); + } + + public boolean isModifier() { + return formatting.isFormat(); + } + + public char getCode() { + return formatting.getChar(); + } + + public Integer getColorValue() { + return formatting.getColor(); + } + + public int getColorIndex() { + return formatting.getId(); + } + + @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..c7c291ae4 --- /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.network.chat.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.withUnderlined(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..a9436a1ea --- /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.network.chat.TextColor; +import net.minecraft.ChatFormatting; + +public class CompatTextColor { + private final TextColor textColor; + + public static final CompatTextColor BLACK = of(TextColor.fromLegacyFormat(ChatFormatting.BLACK)); + public static final CompatTextColor DARK_BLUE = of(TextColor.fromLegacyFormat(ChatFormatting.DARK_BLUE)); + public static final CompatTextColor DARK_GREEN = of(TextColor.fromLegacyFormat(ChatFormatting.DARK_GREEN)); + public static final CompatTextColor DARK_AQUA = of(TextColor.fromLegacyFormat(ChatFormatting.DARK_AQUA)); + public static final CompatTextColor DARK_RED = of(TextColor.fromLegacyFormat(ChatFormatting.DARK_RED)); + public static final CompatTextColor DARK_PURPLE = of(TextColor.fromLegacyFormat(ChatFormatting.DARK_PURPLE)); + public static final CompatTextColor GOLD = of(TextColor.fromLegacyFormat(ChatFormatting.GOLD)); + public static final CompatTextColor GRAY = of(TextColor.fromLegacyFormat(ChatFormatting.GRAY)); + public static final CompatTextColor DARK_GRAY = of(TextColor.fromLegacyFormat(ChatFormatting.DARK_GRAY)); + public static final CompatTextColor BLUE = of(TextColor.fromLegacyFormat(ChatFormatting.BLUE)); + public static final CompatTextColor GREEN = of(TextColor.fromLegacyFormat(ChatFormatting.GREEN)); + public static final CompatTextColor AQUA = of(TextColor.fromLegacyFormat(ChatFormatting.AQUA)); + public static final CompatTextColor RED = of(TextColor.fromLegacyFormat(ChatFormatting.RED)); + public static final CompatTextColor LIGHT_PURPLE = of(TextColor.fromLegacyFormat(ChatFormatting.LIGHT_PURPLE)); + public static final CompatTextColor YELLOW = of(TextColor.fromLegacyFormat(ChatFormatting.YELLOW)); + public static final CompatTextColor WHITE = of(TextColor.fromLegacyFormat(ChatFormatting.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(ChatFormatting formatting) { + return new CompatTextColor(TextColor.fromLegacyFormat(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.parseColor(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/net/pitan76/mcpitanlib/api/text/TextComponent.java b/common/src/main/java/net/pitan76/mcpitanlib/api/text/TextComponent.java new file mode 100644 index 000000000..9a2f82e35 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/text/TextComponent.java @@ -0,0 +1,130 @@ +package net.pitan76.mcpitanlib.api.text; + +import net.minecraft.network.chat.MutableComponent; +import net.minecraft.network.chat.Style; +import net.minecraft.network.chat.Component; +import net.pitan76.mcpitanlib.api.util.TextUtil; +import org.jetbrains.annotations.Nullable; + +public class TextComponent { + + private Component text; + + public TextComponent() { + this(TextUtil.empty()); + } + + public TextComponent(Component text) { + this.text = text; + } + + public TextComponent(String string) { + this(TextUtil.literal(string)); + } + + public Component getText() { + return text; + } + + public void setText(Component text) { + this.text = text; + } + + public MutableComponent asMutableText() { + return (MutableComponent) text; + } + + public VariableTextComponent asVariableTextComponent() { + return new VariableTextComponent(this); + } + + @Nullable + public MutableComponent asMutableTextOrNull() { + if (text instanceof MutableComponent) { + return asMutableText(); + } + return null; + } + + public static TextComponent literal(String string) { + return new TextComponent(string); + } + + public static TextComponent of(String string) { + return TextComponent.literal(string); + } + + public static TextComponent translatable(String key) { + return new TextComponent(TextUtil.translatable(key)); + } + + 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(); + } + + public String getString() { + return TextUtil.txt2str(getText()); + } + + public String superToString() { + return super.toString(); + } + + public TextComponent copy() { + return new TextComponent(getText()); + } + + public Style getStyle() { + return text.getStyle(); + } + + public TextComponent setStyle(Style style) { + if (text instanceof MutableComponent) + TextUtil.setStyle((MutableComponent) 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..a38ad0d7d --- /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.network.chat.MutableComponent; +import net.minecraft.network.chat.Component; +import net.minecraft.ChatFormatting; + +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 MutableComponent convert(String string) { + return convert(string, false); + } + + /** + * Convert string to MutableText with formatting + * + * @param text String + * @param translatable boolean + * @return MutableText + */ + public static MutableComponent convert(String text, boolean translatable) { + String[] splits = split(text); + MutableComponent result = Component.literal(""); + ChatFormatting[] currentFormatting = {}; + + for (String part : splits) { + // Section + if (part.startsWith("§") && part.length() == 2) { + char code = part.charAt(1); + // Reset + if (code == 'r') { + currentFormatting = new ChatFormatting[]{}; + continue; + } + + ChatFormatting format = ChatFormatting.getByCode(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 ChatFormatting[0]); + continue; + } + + // Color + currentFormatting = new ChatFormatting[]{format}; + continue; + } + + // Translatable + if (translatable) { + Pattern pattern = Pattern.compile("\\{(.+?)\\}"); + Matcher matcher = pattern.matcher(part); + MutableComponent tempText = Component.literal(""); + int lastIndex = 0; + + while (matcher.find()) { + // {translatable key} より前の文字列を追加 + if (matcher.start() > lastIndex) { + tempText.append(Component.literal(part.substring(lastIndex, matcher.start())).withStyle(currentFormatting)); + } + + // {translatable key} を追加 + String key = matcher.group(1); + tempText.append(Component.translatable(key).withStyle(currentFormatting)); + + lastIndex = matcher.end(); + } + + // 最後の文字列を追加 + if (lastIndex < part.length()) { + tempText.append(Component.literal(part.substring(lastIndex)).withStyle(currentFormatting)); + } + + result.append(tempText); + continue; + } + + result.append(Component.literal(part).withStyle(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..38dbddc79 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/tile/BlockEntityTypeBuilder.java @@ -0,0 +1,68 @@ +package net.pitan76.mcpitanlib.api.tile; + +import com.mojang.datafixers.types.Type; +import dev.architectury.injectables.annotations.ExpectPlatform; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.level.block.state.BlockState; +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 build(type, factory, blocks.toArray(new Block[0])); + } + + @Deprecated + @ExpectPlatform + public static BlockEntityType build(Type type, BlockEntityTypeBuilder.Factory factory, Block... blocks) { +// FabricBlockEntityTypeBuilder builder = FabricBlockEntityTypeBuilder.create(factory::create, blocks); +// return builder.build(type); + throw new AssertionError(); + } + + @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..304d535b8 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/tile/CompatBlockEntity.java @@ -0,0 +1,203 @@ +package net.pitan76.mcpitanlib.api.tile; + +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.protocol.game.ClientGamePacketListener; +import net.minecraft.network.protocol.Packet; +import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket; +import net.minecraft.core.HolderLookup; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.storage.ValueInput; +import net.minecraft.world.level.storage.ValueOutput; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +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.NbtUtil; +import net.pitan76.mcpitanlib.api.util.WorldUtil; +import net.pitan76.mcpitanlib.core.mc1216.NbtDataConverter; +import net.pitan76.mcpitanlib.midohra.block.entity.BlockEntityTypeWrapper; +import org.jetbrains.annotations.Nullable; + +public class CompatBlockEntity extends BlockEntity implements ICompatBlockEntity { + 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 getUpdatePacket() { + switch (getUpdatePacketType().name) { + case "BLOCK_ENTITY_UPDATE_S2C": + return ClientboundBlockEntityDataPacket.create(this); + } + return super.getUpdatePacket(); + } + + public UpdatePacketType getUpdatePacketType() { + return UpdatePacketType.NONE; + } + + public void writeNbt(WriteNbtArgs args) { + + } + + public void readNbt(ReadNbtArgs args) { + + } + + public CompoundTag toInitialChunkDataNbt(CompatRegistryLookup registryLookup) { + return super.getUpdateTag(registryLookup.getRegistryLookup()); + } + + @Deprecated + @Override + public CompoundTag getUpdateTag(HolderLookup.Provider registries) { + return toInitialChunkDataNbt(new CompatRegistryLookup(registries)); + } + + // deprecated + + /** + * @deprecated Use {@link #writeNbt(WriteNbtArgs)} instead + */ + @Deprecated + public void writeNbtOverride(CompoundTag nbt) { + //super.writeNbt(nbt, wrapperLookupCache); + } + + /** + * @deprecated Use {@link #readNbt(ReadNbtArgs)} instead + */ + @Deprecated + public void readNbtOverride(CompoundTag nbt) { + //super.readNbt(nbt, wrapperLookupCache); + } + + @Deprecated + private HolderLookup.Provider wrapperLookupCache; + + // ---- + + + @Override + protected void saveAdditional(ValueOutput view) { + super.saveAdditional(view); + CompoundTag nbt = NbtUtil.create(); + writeNbt(nbt, this.callGetWorld().registryAccess()); + writeNbt(new WriteNbtArgs(nbt, view, new CompatRegistryLookup(this.callGetWorld().registryAccess()))); + NbtDataConverter.nbt2writeData(nbt, view); + } + + @Override + protected void loadAdditional(ValueInput view) { + super.loadAdditional(view); + CompoundTag nbt = NbtDataConverter.data2nbt(view); + readNbt(nbt, view.lookup()); + readNbt(new ReadNbtArgs(nbt, view, new CompatRegistryLookup(view.lookup()))); + } + + @Deprecated + public void writeNbt(CompoundTag nbt, HolderLookup.Provider registryLookup) { + // deprecated + wrapperLookupCache = registryLookup; + writeNbtOverride(nbt); + // ---- + } + + @Deprecated + public void readNbt(CompoundTag nbt, HolderLookup.Provider registryLookup) { + // deprecated + wrapperLookupCache = registryLookup; + readNbtOverride(nbt); + // ---- + } + + public boolean isClient() { + if (getLevel() == null) + return false; + + return WorldUtil.isClient(getLevel()); + } + + @Deprecated + @Override + public @Nullable Level getLevel() { + return callGetWorld(); + } + + @Deprecated + @Override + public BlockPos getBlockPos() { + return callGetPos(); + } + + public Level callGetWorld() { + return super.getLevel(); + } + + public BlockPos callGetPos() { + return super.getBlockPos(); + } + + public BlockState callGetBlockState() { + return BlockEntityUtil.getBlockState(this); + } + + public BlockState callGetCachedState() { + return BlockEntityUtil.getCachedState(this); + } + + public boolean hasServerWorld() { + return callGetWorld() instanceof ServerLevel; + } + + public ServerLevel getServerWorld() { + return BlockEntityUtil.getServerWorld(this); + } + + public void callMarkDirty() { + BlockEntityUtil.markDirty(this); + } + + @Deprecated + @Override + public void setRemoved() { + markRemovedOverride(); + } + + public void markRemovedOverride() { + super.setRemoved(); + } + + 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()); + } + + public CompatBlockEntity(BlockEntityTypeWrapper type, TileCreateEvent event) { + this(type.get(), event.getBlockPos(), event.getBlockState()); + } +} 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..10c5987b2 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/tile/CompatChestBlockEntity.java @@ -0,0 +1,133 @@ +package net.pitan76.mcpitanlib.api.tile; + +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.level.block.entity.ChestBlockEntity; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.protocol.game.ClientGamePacketListener; +import net.minecraft.network.protocol.Packet; +import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket; +import net.minecraft.core.HolderLookup; +import net.minecraft.world.level.storage.ValueInput; +import net.minecraft.world.level.storage.ValueOutput; +import net.minecraft.core.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 net.pitan76.mcpitanlib.api.registry.CompatRegistryLookup; +import net.pitan76.mcpitanlib.api.util.BlockEntityUtil; +import net.pitan76.mcpitanlib.api.util.NbtUtil; +import net.pitan76.mcpitanlib.core.mc1216.NbtDataConverter; +import net.pitan76.mcpitanlib.midohra.block.entity.BlockEntityTypeWrapper; +import org.jetbrains.annotations.Nullable; + +public class CompatChestBlockEntity extends ChestBlockEntity implements ICompatBlockEntity { + 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 getUpdatePacket() { + switch (getUpdatePacketType().name) { + case "BLOCK_ENTITY_UPDATE_S2C": + return ClientboundBlockEntityDataPacket.create(this); + } + return super.getUpdatePacket(); + } + + 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(CompoundTag nbt) { + + } + + /** + * @deprecated Use {@link #readNbt(ReadNbtArgs)} instead + */ + @Deprecated + public void readNbtOverride(CompoundTag nbt) { + + } + + @Deprecated + private HolderLookup.Provider wrapperLookupCache; + + // ---- + + @Override + protected void saveAdditional(ValueOutput view) { + super.saveAdditional(view); + CompoundTag nbt = NbtUtil.create(); + writeNbt(nbt, this.getLevel().registryAccess()); + writeNbt(new WriteNbtArgs(nbt, view, new CompatRegistryLookup(this.getLevel().registryAccess()))); + NbtDataConverter.nbt2writeData(nbt, view); + } + + @Override + protected void loadAdditional(ValueInput view) { + super.loadAdditional(view); + CompoundTag nbt = NbtDataConverter.data2nbt(view); + readNbt(nbt, view.lookup()); + readNbt(new ReadNbtArgs(nbt, view, new CompatRegistryLookup(view.lookup()))); + } + + @Deprecated + public void writeNbt(CompoundTag nbt, HolderLookup.Provider registryLookup) { + // deprecated + wrapperLookupCache = registryLookup; + writeNbtOverride(nbt); + // ---- + } + + @Deprecated + public void readNbt(CompoundTag nbt, HolderLookup.Provider registryLookup) { + // deprecated + wrapperLookupCache = registryLookup; + readNbtOverride(nbt); + // ---- + } + + public net.pitan76.mcpitanlib.midohra.world.World getMidohraWorld() { + return net.pitan76.mcpitanlib.midohra.world.World.of(BlockEntityUtil.getWorld(this)); + } + + public net.pitan76.mcpitanlib.midohra.util.math.BlockPos getMidohraPos() { + return net.pitan76.mcpitanlib.midohra.util.math.BlockPos.of(BlockEntityUtil.getPos(this)); + } + + public net.pitan76.mcpitanlib.midohra.block.BlockState getMidohraBlockState() { + return net.pitan76.mcpitanlib.midohra.block.BlockState.of(BlockEntityUtil.getBlockState(this)); + } + + public net.pitan76.mcpitanlib.midohra.block.BlockState getMidohraCachedState() { + return net.pitan76.mcpitanlib.midohra.block.BlockState.of(BlockEntityUtil.getCachedState(this)); + } + + public CompatChestBlockEntity(BlockEntityTypeWrapper type, TileCreateEvent event) { + this(type.get(), event.getBlockPos(), event.getBlockState()); + } +} \ 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..e236968b9 --- /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.world.level.block.state.BlockState; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +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 setLevel(Level world) { + super.setLevel(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..05a80b100 --- /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.world.level.block.state.BlockState; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.BlockEntityTicker; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +import net.pitan76.mcpitanlib.api.event.tile.TileTickEvent; + +public interface ExtendBlockEntityTicker extends BlockEntityTicker { + @Override + default void tick(Level 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/ICompatBlockEntity.java b/common/src/main/java/net/pitan76/mcpitanlib/api/tile/ICompatBlockEntity.java new file mode 100644 index 000000000..51847ce14 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/tile/ICompatBlockEntity.java @@ -0,0 +1,16 @@ +package net.pitan76.mcpitanlib.api.tile; + +import net.minecraft.world.level.block.entity.BlockEntity; +import net.pitan76.mcpitanlib.api.util.BlockEntityUtil; +import net.pitan76.mcpitanlib.midohra.block.entity.BlockEntityTypeWrapper; +import net.pitan76.mcpitanlib.midohra.block.entity.BlockEntityWrapper; + +public interface ICompatBlockEntity { + default BlockEntityWrapper getWrapper() { + return this instanceof BlockEntity ? BlockEntityWrapper.of((BlockEntity) this) : BlockEntityWrapper.of(); + } + + default BlockEntityTypeWrapper getTypeWrapper() { + return BlockEntityTypeWrapper.of(BlockEntityUtil.getType((BlockEntity) this)); + } +} 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..352e58bf4 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/tile/v2/BlockEntityTypeBuilder.java @@ -0,0 +1,78 @@ +package net.pitan76.mcpitanlib.api.tile.v2; + +import com.mojang.datafixers.types.Type; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.pitan76.mcpitanlib.midohra.block.SupplierBlockWrapper; +import net.pitan76.mcpitanlib.midohra.core.INonTypedSupplier; + +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())); + } + + public static BlockEntityTypeBuilder create(BlockEntityTypeBuilder.Factory factory, INonTypedSupplier wrapper) { + return create(factory, wrapper.asNonTyped()); + } + + public static BlockEntityTypeBuilder create(BlockEntityTypeBuilder.Factory factory, INonTypedSupplier... wrappers) { + return create(factory, blocks -> { + for (INonTypedSupplier wrapper : wrappers) { + blocks.add(wrapper.asNonTyped().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 build(type, factory, blocks.toArray(new Block[0])); + } +} 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..5d78aaacf --- /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.world.level.material.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(); + } +} \ No newline at end of file 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..2e4117f13 --- /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.world.level.material.Fluid; +import net.minecraft.world.level.material.FluidState; +import net.minecraft.nbt.CompoundTag; +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(CompoundTag nbt, CompatRegistryLookup registryLookup) { + writeNbt(new WriteNbtArgs(nbt, registryLookup)); + } + + default void readNbt(CompoundTag 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..85fa7d87b --- /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.world.level.material.Fluid; +import net.minecraft.world.level.material.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..7b8a0e2e4 --- /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.world.item.crafting.Ingredient; +import net.minecraft.sounds.SoundEvent; +import net.minecraft.resources.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..5286b0057 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/BlockEntityDataUtil.java @@ -0,0 +1,74 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.core.component.DataComponents; +import net.minecraft.world.item.component.TypedEntityData; +import net.minecraft.world.item.ItemStack; +import net.minecraft.nbt.CompoundTag; +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.nbt.NbtCompound; + +public class BlockEntityDataUtil { + public static CompoundTag getBlockEntityNbt(ItemStack stack) { + if (!hasBlockEntityNbt(stack)) return NbtUtil.create(); + TypedEntityData> data = stack.get(DataComponents.BLOCK_ENTITY_DATA); + CompoundTag nbt = data.copyTagWithoutId(); + + String id = BlockEntityTypeUtil.toCompatID(data.type()).toString(); + NbtUtil.putString(nbt, "id", id); + return nbt; + } + + public static void setBlockEntityNbt(ItemStack stack, CompoundTag nbt) { + if (!nbt.contains("id")) return; + + BlockEntityType type = BlockEntityTypeUtil.fromId(CompatIdentifier.of(NbtUtil.getString(nbt, "id"))); + stack.set(DataComponents.BLOCK_ENTITY_DATA, TypedEntityData.of(type, nbt)); + } + + public static boolean hasBlockEntityNbt(ItemStack stack) { + return stack.get(DataComponents.BLOCK_ENTITY_DATA) != null; + } + + public static void readCompatBlockEntityNbtFromStack(ItemStack stack, CompatBlockEntity blockEntity) { + CompoundTag nbt = getBlockEntityNbt(stack); + blockEntity.readNbt(new ReadNbtArgs(nbt, RegistryLookupUtil.getRegistryLookup(blockEntity))); + } + + public static void writeCompatBlockEntityNbtToStack(ItemStack stack, CompatBlockEntity blockEntity) { + CompoundTag nbt = getBlockEntityNbt(stack); + blockEntity.writeNbt(new WriteNbtArgs(nbt, RegistryLookupUtil.getRegistryLookup(blockEntity))); + NbtUtil.putString(nbt, "id", BlockEntityTypeUtil.toCompatID(blockEntity.getType()).toString()); + setBlockEntityNbt(stack, nbt); + } + + public static void removeBlockEntityNbt(ItemStack stack) { + stack.remove(DataComponents.BLOCK_ENTITY_DATA); + } + + public static boolean hasBlockEntityNbt(net.pitan76.mcpitanlib.midohra.item.ItemStack stack) { + return hasBlockEntityNbt(stack.toMinecraft()); + } + + public static NbtCompound getBlockEntityNbt(net.pitan76.mcpitanlib.midohra.item.ItemStack stack) { + return NbtCompound.of(getBlockEntityNbt(stack.toMinecraft())); + } + + public static void setBlockEntityNbt(net.pitan76.mcpitanlib.midohra.item.ItemStack stack, NbtCompound nbt) { + setBlockEntityNbt(stack.toMinecraft(), nbt.toMinecraft()); + } + + public static void removeBlockEntityNbt(net.pitan76.mcpitanlib.midohra.item.ItemStack stack) { + removeBlockEntityNbt(stack.toMinecraft()); + } + + public static void readCompatBlockEntityNbtFromStack(net.pitan76.mcpitanlib.midohra.item.ItemStack stack, CompatBlockEntity blockEntity) { + readCompatBlockEntityNbtFromStack(stack.toMinecraft(), blockEntity); + } + + public static void writeCompatBlockEntityNbtToStack(net.pitan76.mcpitanlib.midohra.item.ItemStack stack, CompatBlockEntity blockEntity) { + writeCompatBlockEntityNbtToStack(stack.toMinecraft(), blockEntity); + } +} 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..210387be5 --- /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.world.level.block.entity.BlockEntityType; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.resources.Identifier; + +public class BlockEntityTypeUtil { + public static Identifier toID(BlockEntityType entityType) { + return BuiltInRegistries.BLOCK_ENTITY_TYPE.getKey(entityType); + } + + public static BlockEntityType fromId(Identifier identifier) { + return BuiltInRegistries.BLOCK_ENTITY_TYPE.getValue(identifier); + } + + public static boolean isExist(Identifier identifier) { + return BuiltInRegistries.BLOCK_ENTITY_TYPE.containsKey(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 BuiltInRegistries.BLOCK_ENTITY_TYPE.getId(type); + } + + public static BlockEntityType fromIndex(int index) { + return BuiltInRegistries.BLOCK_ENTITY_TYPE.byId(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..d2e645cb2 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/BlockEntityUtil.java @@ -0,0 +1,115 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.item.ItemStack; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.storage.TagValueOutput; +import net.minecraft.world.level.storage.ValueInput; +import net.minecraft.util.ProblemReporter; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +import net.pitan76.mcpitanlib.api.registry.CompatRegistryLookup; +import net.pitan76.mcpitanlib.core.mc1216.NbtDataConverter; +import org.jetbrains.annotations.Nullable; + +public class BlockEntityUtil { + + public static BlockEntity getBlockEntity(Level world, BlockPos pos) { + return WorldUtil.getBlockEntity(world, pos); + } + + public static CompoundTag getBlockEntityNbt(@Nullable Level world, BlockEntity blockEntity) { + if (world == null) + world = getWorld(blockEntity); + if (world == null) + return NbtUtil.create(); + + return blockEntity.saveWithoutMetadata(world.registryAccess()); + } + + public static CompoundTag getBlockEntityNbt(BlockEntity blockEntity) { + return getBlockEntityNbt(null, blockEntity); + } + + public static Level getWorld(BlockEntity blockEntity) { + return blockEntity.getLevel(); + } + + public static boolean hasWorld(BlockEntity blockEntity) { + return blockEntity.hasLevel(); + } + + public static BlockPos getPos(BlockEntity blockEntity) { + return blockEntity.getBlockPos(); + } + + public static BlockState getCachedState(BlockEntity blockEntity) { + return blockEntity.getBlockState(); + } + + 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.setRemoved(); + } + + public static void markDirty(BlockEntity blockEntity) { + blockEntity.setChanged(); + } + + public static BlockEntityType getType(BlockEntity blockEntity) { + return blockEntity.getType(); + } + + public static void readNbt(BlockEntity blockEntity, CompoundTag nbt, CompatRegistryLookup registryLookup) { + ValueInput view = NbtDataConverter.nbt2readData(nbt, registryLookup); + blockEntity.loadCustomOnly(view); + } + + public static void writeNbt(BlockEntity blockEntity, CompoundTag nbt, CompatRegistryLookup registryLookup) { + TagValueOutput view = TagValueOutput.createWithoutContext(ProblemReporter.DISCARDING); + blockEntity.saveCustomOnly(view); + NbtDataConverter.data2nbt(view, nbt); + } + + public static void read(BlockEntity blockEntity, CompoundTag nbt, CompatRegistryLookup registryLookup) { + ValueInput view = NbtDataConverter.nbt2readData(nbt, registryLookup); + blockEntity.loadWithComponents(view); + } + + public static CompoundTag createNbt(BlockEntity blockEntity, CompatRegistryLookup registryLookup) { + return blockEntity.saveWithoutMetadata(registryLookup.getRegistryLookup()); + } + + public static void setStackNbt(BlockEntity blockEntity, ItemStack stack, CompatRegistryLookup registryLookup) { + blockEntity.applyComponentsFromItemStack(stack); + } + + public static ServerLevel getServerWorld(BlockEntity blockEntity) { + return (ServerLevel) getWorld(blockEntity); + } + + public static void writeToStack(ItemStack stack, BlockEntity blockEntity, CompatRegistryLookup registryLookup) { + CompoundTag nbt = blockEntity.saveCustomOnly(registryLookup.getRegistryLookup()); + if (!NbtUtil.has(nbt, "id")) + NbtUtil.putString(nbt, "id", BlockEntityTypeUtil.toID(BlockEntityUtil.getType(blockEntity)).toString()); + + BlockEntityDataUtil.setBlockEntityNbt(stack, nbt); + + blockEntity.collectComponents().forEach(stack::set); + } + + 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..45aacc5ff --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/BlockStateUtil.java @@ -0,0 +1,168 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.material.Fluid; +import net.minecraft.world.level.material.FluidState; +import net.minecraft.world.item.ItemStack; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.block.SoundType; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.Property; +import net.minecraft.world.level.block.Rotation; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.LevelAccessor; +import net.minecraft.world.level.redstone.Orientation; +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.canOcclude(); + } + + public static SoundType getSoundGroup(BlockState state) { + return state.getSoundType(); + } + + public static CompatBlockSoundGroup getCompatSoundGroup(BlockState state) { + return CompatBlockSoundGroup.of(getSoundGroup(state)); + } + + public static BlockState getDefaultState(Block block) { + return block.defaultBlockState(); + } + + public static StateDefinition getStateManager(Block block) { + return block.getStateDefinition(); + } + + public static , V extends T> BlockState with(BlockState state, Property property, V value) { + return state.setValue(property, value); + } + + public static void neighborUpdate(BlockState state, Level world, BlockPos pos, Block block, BlockPos fromPos, boolean notify) { + Orientation wireOrientation = Orientation.of(pos.above() == fromPos ? Direction.UP : Direction.DOWN, pos.north() == fromPos ? Direction.NORTH : Direction.SOUTH, pos.east() == fromPos ? Orientation.SideBias.RIGHT : Orientation.SideBias.LEFT); + + state.handleNeighborChanged(world, pos, block, wireOrientation, notify); + } + + public static void updateNeighbors(BlockState state, LevelAccessor world, BlockPos pos, int flags) { + state.updateNeighbourShapes(world, pos, flags); + } + + public static boolean hasRandomTicks(BlockState state) { + return state.isRandomlyTicking(); + } + + public static void randomTick(BlockState state, ServerLevel world, BlockPos pos) { + state.randomTick(world, pos, world.getRandom()); + } + + public static CompatActionResult onUse(BlockState state, Level world, Player player, BlockHitResult hitResult) { + return CompatActionResult.create(state.useWithoutItem(world, player.getEntity(), hitResult)); + } + + public static CompatActionResult onUse(BlockState state, Level 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, Level world, net.minecraft.world.entity.player.Player player, InteractionHand hand, BlockHitResult hit) { + return CompatActionResult.create(state.useItemOn(stack, world, player, hand, hit)); + } + + public static CompatActionResult onUseWithItem_actionResult(BlockState state, ItemStack stack, Level world, net.minecraft.world.entity.player.Player player, InteractionHand 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).getType(); + } + + public static BlockState rotate(BlockState state, Rotation 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, BlockGetter world, BlockPos pos) { + return state.getDestroySpeed(world, pos); + } + + public static float getHardness(BlockState state, Level world, BlockPos pos) { + return state.getDestroySpeed(world, pos); + } + + public static int getLuminance(BlockState state) { + return state.getLightEmission(); + } + + public static int getOpacity(BlockState state) { + return state.getLightDampening(); + } + + public static int getComparatorOutput(BlockState state, Level world, BlockPos pos) { + return state.getAnalogOutputSignal(world, pos, Direction.NORTH); + } + + 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, Level world) { + return state.canSurvive(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()); + } + + public static boolean hasRandomTicks(net.pitan76.mcpitanlib.midohra.block.BlockState state) { + return hasRandomTicks(state.toMinecraft()); + } + + public static void randomTick(net.pitan76.mcpitanlib.midohra.block.BlockState state, ServerLevel world, net.pitan76.mcpitanlib.midohra.util.math.BlockPos pos) { + randomTick(state.toMinecraft(), world, pos.toMinecraft()); + } + + public static void randomTick(net.pitan76.mcpitanlib.midohra.block.BlockState state, net.pitan76.mcpitanlib.midohra.world.ServerWorld world, net.pitan76.mcpitanlib.midohra.util.math.BlockPos pos) { + randomTick(state.toMinecraft(), world.getRaw(), pos.toMinecraft()); + } +} 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..63af9b0f3 --- /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.world.level.block.state.BlockBehaviour; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.resources.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 BlockBehaviour.Properties breakByTool(BlockBehaviour.Properties 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 BlockBehaviour.Properties dropsNothing(BlockBehaviour.Properties settings) { + return BlockUtilV1.dropsNothing(settings); + } + /** + * block breaking requires any tool + * @param settings Block settings + * @return Block settings + */ + public static BlockBehaviour.Properties requiresTool(BlockBehaviour.Properties 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(BlockBehaviour.Properties 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..fe68c971e --- /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.world.level.block.state.BlockState; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.BlockGetter; + +public class BlockViewUtil { + public static BlockState getBlockState(BlockGetter blockView, BlockPos pos) { + return blockView.getBlockState(pos); + } + + public static BlockEntity getBlockEntity(BlockGetter blockView, BlockPos pos) { + return blockView.getBlockEntity(pos); + } + + public static boolean hasBlockEntity(BlockGetter blockView, BlockPos pos) { + return getBlockEntity(blockView, pos) != null; + } + + public static boolean isAir(BlockGetter 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..7e0be00ad --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/CommandManagerUtil.java @@ -0,0 +1,87 @@ +package net.pitan76.mcpitanlib.api.util; + +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import net.minecraft.server.permissions.LevelBasedPermissionSet; +import net.minecraft.server.permissions.PermissionLevel; +import net.minecraft.server.MinecraftServer; +import net.minecraft.commands.Commands; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.server.level.ServerLevel; +import net.pitan76.mcpitanlib.api.entity.Player; +import net.pitan76.mcpitanlib.core.command.CommandResult; + +public class CommandManagerUtil { + public static Commands getCommandManager(MinecraftServer server) { + return server.getCommands(); + } + + public static CommandResult execute(MinecraftServer server, String command) { + CommandDispatcher dispatcher = getCommandManager(server).getDispatcher(); + CommandSourceStack source = server.createCommandSourceStack(); + + 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(CommandSourceStack source, String command) { + CommandDispatcher dispatcher = source.getServer().getCommands().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 CommandSourceStack getCommandSource(MinecraftServer server) { + return server.createCommandSourceStack(); + } + + public static CommandSourceStack getCommandSource(Player player) { + return player.getEntity().createCommandSourceStackForNameResolution((ServerLevel) player.getWorld()); + } + + public static CommandSourceStack withLevel(CommandSourceStack source, int level) { + return source.withPermission(LevelBasedPermissionSet.forLevel(PermissionLevel.byId(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..1ed916d21 --- /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.world.level.block.Block; +import net.minecraft.commands.arguments.blocks.BlockStateArgument; +import net.minecraft.commands.arguments.EntityArgument; +import net.minecraft.commands.arguments.item.ItemArgument; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.item.Item; +import net.pitan76.mcpitanlib.api.event.ServerCommandEvent; + +public class CommandUtil { + public static Item getItemArgument(String name, ServerCommandEvent e) { + return ItemArgument.getItem(e.getContext(), name).item().value(); + } + + public static Block getBlockArgument(String name, ServerCommandEvent e) { + return BlockStateArgument.getBlock(e.getContext(), name).getState().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 EntityArgument.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..1ff24b45f --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/CompatActionResult.java @@ -0,0 +1,123 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.world.InteractionResult; +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(InteractionResult.SUCCESS, EventResult.success()); + public static final CompatActionResult PASS = new CompatActionResult(InteractionResult.PASS, EventResult.pass()); + public static final CompatActionResult FAIL = new CompatActionResult(InteractionResult.FAIL, EventResult.fail()); + public static final CompatActionResult CONSUME = new CompatActionResult(InteractionResult.CONSUME, EventResult.success()); + public static final CompatActionResult PASS_TO_DEFAULT_BLOCK_ACTION = new CompatActionResult(InteractionResult.TRY_WITH_EMPTY_HAND, EventResult.pass()); + public static final CompatActionResult SUCCESS_SERVER = new CompatActionResult(InteractionResult.SUCCESS_SERVER, EventResult.success()); + public static final CompatActionResult STOP = new CompatActionResult(InteractionResult.FAIL, EventResult.stop()); + + private final InteractionResult actionResult; + private final EventResult eventResult; + + protected CompatActionResult(InteractionResult actionResult, EventResult eventResult) { + this.actionResult = actionResult; + this.eventResult = eventResult; + } + + public InteractionResult toActionResult() { + return actionResult; + } + + public EventResult toEventResult() { + return eventResult; + } + + public Optional getNewMidohraHandStack() { + return getNewHandStack().map(ItemStack::of); + } + + public Optional getNewHandStack() { + if (!(actionResult instanceof InteractionResult.Success)) return Optional.empty(); + + InteractionResult.Success success = (InteractionResult.Success) actionResult; + return Optional.ofNullable(success.heldItemTransformedTo()); + } + + public static CompatActionResult of(InteractionResult result) { + if (result == InteractionResult.SUCCESS) + return SUCCESS; + + if (result == InteractionResult.PASS) + return PASS; + + if (result == InteractionResult.FAIL) + return FAIL; + + if (result == InteractionResult.CONSUME) + return CONSUME; + + if (result == InteractionResult.TRY_WITH_EMPTY_HAND) + return PASS_TO_DEFAULT_BLOCK_ACTION; + + if (result == InteractionResult.SUCCESS_SERVER) + return SUCCESS_SERVER; + + 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(InteractionResult result, EventResult eventResult) { + return new CompatActionResult(result, eventResult); + } + + /** + * @deprecated Use {@link #of(InteractionResult)} instead. + */ + @Deprecated + public static CompatActionResult create(InteractionResult result) { + return of(result); + } + + @Deprecated + public static CompatActionResult create2(InteractionResult 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..2dc9ad850 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/CompatIdentifier.java @@ -0,0 +1,173 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.resources.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"); + } + + public boolean isMinecraftNamespace() { + return this.namespace.equals("minecraft"); + } + + public CompatIdentifier(Identifier id) { + this.namespace = id.getNamespace(); + this.path = id.getPath(); + } + + public static CompatIdentifier of(Identifier id) { + return new CompatIdentifier(id); + } +} 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..04535b375 --- /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.ChatFormatting; +import net.minecraft.world.item.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 ChatFormatting getFormatting() { + return rarity.color(); + } + + 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..c284c39d6 --- /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.StringRepresentable; + +public interface CompatStringIdentifiable extends StringRepresentable { + @Deprecated + @Override + default String getSerializedName() { + return asString_compat(); + } + + String asString_compat(); + + default StringRepresentable 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..5f285a0a2 --- /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.world.item.ItemStack; +import net.minecraft.world.item.crafting.Ingredient; +import net.minecraft.resources.Identifier; +import net.minecraft.core.NonNullList; +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, NonNullList 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, NonNullList input) { + return createShapelessRecipe(id.toMinecraft(), group, category, output, input); + } + + public static RecipeEntry createShapelessRecipeM(CompatIdentifier id, String group, RecipeUtil.CompatibilityCraftingRecipeCategory category, ItemStack output, NonNullList 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, NonNullList 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..3abf38884 --- /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.core.component.DataComponents; +import net.minecraft.world.item.component.CustomData; +import net.minecraft.world.item.ItemStack; +import net.minecraft.nbt.CompoundTag; + +import java.util.Set; + +/** + * カスタムデータのユーティリティクラス + */ +public class CustomDataUtil { + /** + * NBTを取得する。存在しない場合は新しいNBTを作成する。 + * @param stack ItemStack + * @return NBT + */ + public static CompoundTag 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, CompoundTag nbt) { + stack.set(DataComponents.CUSTOM_DATA, CustomData.of(nbt)); + } + + /** + * NBTが存在するかどうかを取得する。 + * @param stack ItemStack + * @return NBTが存在するかどうか + */ + public static boolean hasNbt(ItemStack stack) { + return stack.get(DataComponents.CUSTOM_DATA) != null; + } + + /** + * NBTを取得する。 + * @param stack ItemStack + * @return NBT + */ + public static CompoundTag getNbt(ItemStack stack) { + if (stack.get(DataComponents.CUSTOM_DATA) == null) + return NbtUtil.create(); + + return stack.get(DataComponents.CUSTOM_DATA).copyTag(); + } + + /** + * 値を設定する。 + * @param stack ItemStack + * @param key キー + * @param value 値 + */ + public static void put(ItemStack stack, String key, CompoundTag value) { + CompoundTag nbt = getOrCreateNbt(stack); + NbtUtil.put(nbt, key, value); + setNbt(stack, nbt); + } + + /** + * 値を取得する。 + * @param stack ItemStack + * @param key キー + * @return 値 + */ + public static CompoundTag get(ItemStack stack, String key) { + CompoundTag nbt = getNbt(stack); + return nbt.getCompoundOrEmpty(key); + } + + /** + * 値を削除する。 + * @param stack ItemStack + * @param key キー + */ + public static void remove(ItemStack stack, String key) { + CompoundTag 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; + + CompoundTag 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) { + CompoundTag 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) { + CompoundTag nbt = getOrCreateNbt(stack); + NbtUtil.set(nbt, key, value); + setNbt(stack, nbt); + } + + /** + * キーの一覧を取得する。 + * @param stack ItemStack + * @return キーの一覧 + */ + public static Set getKeys(ItemStack stack) { + CompoundTag 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(DataComponents.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..29997850b --- /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.world.entity.Entity; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.damagesource.DamageSource; +import net.pitan76.mcpitanlib.api.entity.Player; + +public class DamageSourceUtil { + public static DamageSource thrownProjectile(Entity projectile, Entity attacker, Entity source) { + return source.damageSources().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.damageSources().playerAttack(attacker.getPlayerEntity()); + } + + public static DamageSource playerAttack(Player attacker) { + return playerAttack(attacker, attacker.getPlayerEntity()); + } + + public static DamageSource mobAttack(LivingEntity attacker, Entity source) { + return source.damageSources().mobAttack(attacker); + } + + public static DamageSource mobAttack(LivingEntity attacker) { + return mobAttack(attacker, attacker); + } + + public static DamageSource mobProjectile(Entity projectile, LivingEntity attacker, Entity source) { + return source.damageSources().mobProjectile(projectile, attacker); + } + + public static DamageSource mobProjectile(Entity projectile, LivingEntity attacker) { + return mobProjectile(projectile, attacker, projectile); + } + + public static DamageSource fall(Entity source) { + return source.damageSources().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..20d967ee6 --- /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.core.component.DataComponents; +import net.minecraft.world.item.enchantment.ItemEnchantments; +import net.minecraft.world.item.enchantment.Enchantment; +import net.minecraft.world.item.enchantment.EnchantmentHelper; +import net.minecraft.world.item.ItemStack; +import net.minecraft.resources.ResourceKey; +import net.minecraft.core.registries.Registries; +import net.minecraft.resources.Identifier; +import net.minecraft.world.level.Level; +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) { + ResourceKey registryKey = ResourceKey.create(Registries.ENCHANTMENT, identifier); + return new CompatEnchantment(registryKey); + } + + public static Identifier getId(CompatEnchantment enchantment) { + return enchantment.getId(); + } + + public static int getLevel(CompatEnchantment enchantment, ItemStack stack, @Nullable Level 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.getEnchantmentsForCrafting(stack).keySet().forEach((enchantment) -> { + if (enchantment.unwrapKey().isPresent()) + enchantments.add(new CompatEnchantment(enchantment.unwrapKey().get())); + }); + + return enchantments; + } + + public static boolean hasEnchantment(ItemStack stack) { + return EnchantmentHelper.hasAnyEnchantments(stack); + } + + public static Map getEnchantment(ItemStack stack, @Nullable Level 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 Level world) { + ItemEnchantments.Mutable builder = new ItemEnchantments.Mutable(ItemEnchantments.EMPTY); + + enchantments.forEach((compatEnchantment, integer) -> { + builder.upgrade(compatEnchantment.getEntry(world), integer); + }); + + EnchantmentHelper.setEnchantments(stack, builder.toImmutable()); + } + + public static void removeEnchantment(ItemStack stack) { + stack.remove(DataComponents.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..78a1af270 --- /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.world.entity.EntityType; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.Identifier; + +public class EntityTypeUtil { + public static Identifier toID(EntityType entityType) { + return BuiltInRegistries.ENTITY_TYPE.getKey(entityType); + } + + public static EntityType fromId(Identifier identifier) { + return BuiltInRegistries.ENTITY_TYPE.getValue(identifier); + } + + public static boolean isExist(Identifier identifier) { + return BuiltInRegistries.ENTITY_TYPE.containsKey(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 BuiltInRegistries.ENTITY_TYPE.getId(type); + } + + public static EntityType fromIndex(int index) { + return BuiltInRegistries.ENTITY_TYPE.byId(index); + } + + public static Component getName(EntityType entityType) { + return entityType.getDescription(); + } + + public static String getTranslationKey(EntityType entityType) { + return entityType.getDescriptionId(); + } +} 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..a4506ce68 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/EntityUtil.java @@ -0,0 +1,369 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.entity.Relative; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.network.chat.Component; +import net.minecraft.world.level.block.Rotation; +import net.minecraft.world.phys.Vec3; +import net.minecraft.world.level.Level; +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 Level getWorld(Entity entity) { + return entity.level(); + } + + public static boolean damage(Entity target, DamageSource damageSource, float amount) { + return target.hurtServer((ServerLevel) target.level(), damageSource, amount); + } + + public static boolean damageWithThrownProjectile(Entity target, float damageAmount, Entity projectile, Entity attacker) { + return target.hurtServer((ServerLevel) target.level(), DamageSourceUtil.thrownProjectile(projectile, attacker), damageAmount); + } + + public static boolean damageWithMobProjectile(Entity target, float damageAmount, Entity projectile, LivingEntity attacker) { + return target.hurtServer((ServerLevel) target.level(), DamageSourceUtil.mobProjectile(projectile, attacker), damageAmount); + } + + public static boolean damageWithMobAttack(Entity target, float damageAmount, Entity source, LivingEntity attacker) { + return target.hurtServer((ServerLevel) target.level(), DamageSourceUtil.mobAttack(attacker, source), damageAmount); + } + + public static boolean damageWithPlayerAttack(Entity target, float damageAmount, Entity source, Player attacker) { + return target.hurtServer((ServerLevel) target.level(), DamageSourceUtil.playerAttack(attacker, source), damageAmount); + } + + public static void discard(Entity entity) { + entity.discard(); + } + + public static void kill(Entity entity) { + if (entity.level() instanceof ServerLevel) + return; + + entity.kill((ServerLevel) entity.level()); + } + + public static void setVelocity(Entity entity, double x, double y, double z) { + entity.setDeltaMovement(x, y, z); + } + + public static Vec3 getVelocity(Entity entity) { + return entity.getDeltaMovement(); + } + + public static void setNoGravity(Entity entity, boolean noGravity) { + entity.setNoGravity(noGravity); + } + + public static boolean hasNoGravity(Entity entity) { + return entity.isNoGravity(); + } + + 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.setGlowingTag(glowing); + } + + public static boolean isGlowing(Entity entity) { + return entity.isCurrentlyGlowing(); + } + + public static void setFire(Entity entity, int seconds) { + entity.igniteForSeconds(seconds); + } + + public static void extinguish(Entity entity) { + entity.clearFire(); + } + + 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.setShiftKeyDown(sneaking); + } + + public static boolean isSneaking(Entity entity) { + return entity.isShiftKeyDown(); + } + + 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.unRide(); + } + + public static void attach(Entity entity, Entity vehicle) { + entity.startRiding(vehicle, true, true); + } + + public static void detachFromVehicle(Entity entity) { + entity.stopRiding(); + } + + public static boolean isRiding(Entity entity) { + return entity.isPassenger(); + } + + public static Entity getVehicle(Entity entity) { + return entity.getVehicle(); + } + + public static void setVehicle(Entity entity, Entity vehicle) { + entity.startRiding(vehicle, true, true); + } + + public static void applyRotation(Entity entity, Rotation rotation) { + entity.rotate(rotation); + } + + public static void setVelocity(Entity entity, Vec3 velocity) { + entity.setDeltaMovement(velocity); + } + + public static void setFallDistance(Entity entity, double fallDistance) { + entity.fallDistance = fallDistance; + } + + public static double getFallDistance(Entity entity) { + return entity.fallDistance; + } + + public static void setVelocityModified(Entity entity, boolean velocityModified) { + entity.needsSync = velocityModified; + } + + public static boolean isVelocityModified(Entity entity) { + return entity.needsSync; + } + + public static float getYaw(Entity entity) { + return entity.getYRot(); + } + + public static float getPitch(Entity entity) { + return entity.getXRot(); + } + + public static void setYaw(Entity entity, float yaw) { + entity.setYRot(yaw); + } + + public static void setPitch(Entity entity, float pitch) { + entity.setXRot(pitch); + } + + public static float getSpeed(Entity entity) { + return entity.flyDist; + } + + public static void setSpeed(Entity entity, float speed) { + entity.flyDist = speed; + } + + public static boolean isOnGround(Entity entity) { + return entity.onGround(); + } + + 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.getStringUUID(); + } + + public static void setUuid(Entity entity, UUID uuid) { + entity.setUUID(uuid); + } + + public static Component getName(Entity entity) { + return entity.getName(); + } + + public static Component getDisplayName(Entity entity) { + return entity.getDisplayName(); + } + + public static void setCustomName(Entity entity, Component customName) { + entity.setCustomName(customName); + } + + public static Component 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 Vec3 getRotationVector(Entity entity) { + return entity.getLookAngle(); + } + + public static Vec3 getPos(Entity entity) { + return entity.position(); + } + + public static Vector3d getPosM(Entity entity) { + return Vector3d.of(getPos(entity)); + } + + public static void setPos(Entity entity, double x, double y, double z) { + entity.setPosRaw(x, y, z); + } + + public static void addVelocity(Entity entity, double x, double y, double z) { + entity.push(x, y, z); + } + + public static void addVelocity(Entity entity, Vec3 velocity) { + entity.push(velocity); + } + + public static void addVelocity(Entity entity, Vector3d velocity) { + addVelocity(entity, velocity.toMinecraft()); + } + + public static void setVelocity(Entity entity, Vector3d velocity) { + entity.setDeltaMovement(velocity.toMinecraft()); + } + + public static void setPos(Entity entity, BlockPos pos) { + setPos(entity, pos.getX(), pos.getY(), pos.getZ()); + } + + public static void setPos(Entity entity, Vector3d pos) { + setPos(entity, pos.getX(), pos.getY(), pos.getZ()); + } + + public static void teleport(Entity entity, ServerLevel world, double x, double y, double z, float yaw, float pitch, boolean resetCamera) { + entity.teleportTo(world, x, y, z, Relative.ALL, yaw, pitch, resetCamera); + } + + public static void teleport(Entity entity, ServerLevel world, double x, double y, double z, float yaw, float pitch) { + teleport(entity, world, x, y, z, yaw, pitch, true); + } + + public static void teleport(Entity entity, ServerLevel world, double x, double y, double z) { + teleport(entity, world, x, y, z, entity.getYRot(), entity.getXRot(), true); + } + + public static void teleport(Entity entity, ServerLevel world, Vector3d pos) { + teleport(entity, world, pos.getX(), pos.getY(), pos.getZ()); + } + + public static void teleport(Entity entity, ServerLevel world, BlockPos pos) { + teleport(entity, world, pos.getX(), pos.getY(), pos.getZ()); + } + + public static void teleport(Entity entity, double x, double y, double z) { + if (!(entity.level() instanceof ServerLevel)) + return; + + teleport(entity, (ServerLevel) entity.level(), x, y, z, entity.getYRot(), entity.getXRot()); + } + + public static void teleport(Entity entity, Vector3d pos) { + teleport(entity, pos.getX(), pos.getY(), pos.getZ()); + } + + public static void teleport(Entity entity, BlockPos pos) { + teleport(entity, pos.getX(), pos.getY(), pos.getZ()); + } + + public static void teleport(Entity entity, ServerLevel world, Vector3d pos, float yaw, float pitch, boolean resetCamera) { + teleport(entity, world, pos.getX(), pos.getY(), pos.getZ(), yaw, pitch, resetCamera); + } + + public static void teleport(Entity entity, ServerLevel raw, BlockPos pos, float yaw, float pitch, boolean resetCamera) { + teleport(entity, raw, pos.getX(), pos.getY(), pos.getZ(), yaw, pitch, resetCamera); + } + + public static EntityType getType(Entity entity) { + return entity.getType(); + } +} 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..98229d799 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/EquipMaterialUtil.java @@ -0,0 +1,46 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.world.item.ToolMaterial; +import net.minecraft.world.item.crafting.Ingredient; +import net.minecraft.tags.ItemTags; +import net.minecraft.sounds.SoundEvent; +import net.minecraft.resources.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 new ToolMaterial(CompatibleToolMaterial.level2inverseTag(miningLevel), durability, miningSpeedMultiplier, attackDamage, enchantability, ItemTags.IRON_TOOL_MATERIALS); + } + + public static ToolMaterial createToolMaterial(int durability, float miningSpeedMultiplier, float attackDamage, int miningLevel, int enchantability, RepairIngredientTag ingredientTag) { + return new ToolMaterial(CompatibleToolMaterial.level2inverseTag(miningLevel), durability, miningSpeedMultiplier, attackDamage, enchantability, ingredientTag.getTag()); + } + + 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..6beb87ca6 --- /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.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.tags.BlockTags; +import net.minecraft.world.level.levelgen.structure.templatesystem.RuleTest; +import net.minecraft.world.level.levelgen.structure.templatesystem.TagMatchTest; +import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; +import net.minecraft.world.level.levelgen.feature.Feature; +import net.minecraft.world.level.levelgen.feature.configurations.OreConfiguration; + +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(OreConfiguration 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 OreConfiguration createOreFeatureConfig(RuleTest test, BlockState state, int size) { + return new OreConfiguration(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 OreConfiguration createOreFeatureConfig(RuleTest test, Block block, int size) { + return createOreFeatureConfig(test, block.defaultBlockState(), size); + } + + /** + * Create a new OreFeatureConfig + * @param targets The targets + * @param size The size + * @return The new OreFeatureConfig + */ + public static OreConfiguration createOreFeatureConfig(List targets, int size) { + return new OreConfiguration(targets, size); + } + + /** + * Create a new OreFeatureConfig + * @param targetMap The target map + * @param size The size + * @return The new OreFeatureConfig + */ + public static OreConfiguration createOreFeatureConfig(Map targetMap, int size) { + List targets = new ArrayList<>(); + targetMap.forEach((ruleTest, blockState) -> targets.add(OreConfiguration.target(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 OreConfiguration createStoneOreFeatureConfig(BlockState state, int size) { + RuleTest ruleTest = new TagMatchTest(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..91cd0fc43 --- /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.world.level.block.state.BlockState; +import net.minecraft.world.level.material.Fluid; +import net.minecraft.world.level.material.FluidState; +import net.minecraft.tags.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.is(FluidTags.WATER); + } + + public static boolean isLava(FluidState state) { + return state.is(FluidTags.LAVA); + } + + @Deprecated + public static FluidState getFluidState(BlockState state) { + return state.getFluidState(); + } + + public static FluidState getDefaultState(Fluid state) { + return state.defaultFluidState(); + } + + public static Fluid getFluid(FluidState state) { + return state.getType(); + } + + 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..891edd8ce --- /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.world.level.material.FlowingFluid; +import net.minecraft.world.level.material.Fluid; +import net.minecraft.world.level.material.FluidState; +import net.minecraft.world.level.material.Fluids; +import net.minecraft.world.item.Item; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.resources.Identifier; +import net.minecraft.world.level.LevelReader; + +public class FluidUtil { + public static Identifier toID(Fluid fluid) { + return BuiltInRegistries.FLUID.getKey(fluid); + } + + public static Fluid fromId(Identifier identifier) { + return BuiltInRegistries.FLUID.getValue(identifier); + } + + public static Fluid fromId(CompatIdentifier identifier) { + return fromId(identifier.toMinecraft()); + } + + public static int getRawId(Fluid fluid) { + return BuiltInRegistries.FLUID.getId(fluid); + } + + public static Fluid fromIndex(int index) { + return BuiltInRegistries.FLUID.byId(index); + } + + public static boolean isExist(CompatIdentifier id) { + return BuiltInRegistries.FLUID.containsKey(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 FlowingFluid water() { + return Fluids.WATER; + } + + public static FlowingFluid lava() { + return Fluids.LAVA; + } + + public static Fluid empty() { + return Fluids.EMPTY; + } + + public static FlowingFluid flowingWater() { + return Fluids.FLOWING_WATER; + } + + public static FlowingFluid flowingLava() { + return Fluids.FLOWING_LAVA; + } + + public static boolean isStill(Fluid fluid) { + return fluid == water() || fluid == lava(); + } + + public static boolean isStill(FluidState state) { + return state.isSource(); + } + + public static FluidState getStill(FlowingFluid fluid, boolean falling) { + return fluid.getSource(falling); + } + + public static FluidState getFlowing(FlowingFluid fluid, int level, boolean falling) { + return fluid.getFlowing(level, falling); + } + + public static FluidState getStill(FlowingFluid 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, LevelReader world) { + return fluid.getTickDelay(world); + } + + public static FluidState getDefaultState(Fluid fluid) { + return fluid.defaultFluidState(); + } + + + public static Item getBucketItem(Fluid fluid) { + return fluid.getBucket(); + } +} 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..d52a7bd0a --- /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.world.entity.EquipmentSlot; +import net.minecraft.world.InteractionHand; + +public class HandUtil { + public static InteractionHand getOppositeHand(InteractionHand hand) { + return hand == InteractionHand.MAIN_HAND ? InteractionHand.OFF_HAND : InteractionHand.MAIN_HAND; + } + + public static EquipmentSlot getEquipmentSlot(InteractionHand hand) { + return hand == InteractionHand.MAIN_HAND ? EquipmentSlot.MAINHAND : EquipmentSlot.OFFHAND; + } + + public static InteractionHand getHand(EquipmentSlot slot) { + return slot == EquipmentSlot.MAINHAND ? InteractionHand.MAIN_HAND : InteractionHand.OFF_HAND; + } + + public static InteractionHand getHand(boolean mainHand) { + return mainHand ? InteractionHand.MAIN_HAND : InteractionHand.OFF_HAND; + } + + public static boolean isMainHand(InteractionHand hand) { + return hand == InteractionHand.MAIN_HAND; + } + + public static boolean isOffHand(InteractionHand hand) { + return hand == InteractionHand.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..c1220e74d --- /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.resources.Identifier; + +public class IdentifierUtil { + public static Identifier id(String id) { + return Identifier.parse(id); + } + + public static Identifier id(String namespace, String path) { + return Identifier.fromNamespaceAndPath(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..968edb6a9 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/IngredientUtil.java @@ -0,0 +1,96 @@ +package net.pitan76.mcpitanlib.api.util; + +import it.unimi.dsi.fastutil.ints.IntArrayList; +import it.unimi.dsi.fastutil.ints.IntList; +import net.minecraft.world.item.Item; +import net.minecraft.world.level.ItemLike; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.Ingredient; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.core.Holder; +import net.minecraft.core.HolderSet; +import net.minecraft.resources.Identifier; +import net.minecraft.core.NonNullList; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class IngredientUtil { + public static Ingredient fromTagByIdentifier(Identifier id) { + List items = ItemUtil.getItems(id); + + List> entryList = new ArrayList<>(); + for (Item item : items) { + entryList.add(BuiltInRegistries.ITEM.wrapAsHolder(item)); + } + + HolderSet entryList2 = HolderSet.direct(entryList); + + return Ingredient.of(entryList2); + } + + 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 (Holder entry : ingredient.items().toList()) { + items.add(entry.value()); + } + + return items; + } + + public static IntList getMatchingStacksIds(Ingredient ingredient) { + IntList ids = new IntArrayList(); + + for (Item item : getItems(ingredient)) { + ids.add(ItemUtil.getRawId(item)); + } + + return ids; + } + + public static List getMatchingStacksAsList(Ingredient ingredient) { + return new ArrayList<>(Arrays.asList(getMatchingStacks(ingredient))); + } + + public static ItemStack[] getMatchingStacks(Ingredient ingredient) { + List stacks = new ArrayList<>(); + for (Item item : getItems(ingredient)) { + stacks.add(new ItemStack(item)); + } + + return stacks.toArray(new ItemStack[0]); + } + + public static Ingredient empty() { + return null; + } + + public static Ingredient ofItems(ItemLike... items) { + return Ingredient.of(items); + } + + public static NonNullList buildInput(Object[] input) { + NonNullList list = NonNullList.create(); + for (Object obj : input) { + if (obj instanceof Ingredient) { + list.add((Ingredient) obj); + continue; + } + + if (obj instanceof ItemLike) { + list.add(ofItems((ItemLike) 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..42b203eda --- /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.world.level.block.state.BlockState; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.context.UseOnContext; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.level.Level; +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) { + CompatActionResult result = CompatActionResult.create(item.use(event.getWorld(), event.user.getEntity(), event.getHand())); + return StackActionResult.create(result, event.getStack()); + } + + public static CompatActionResult useItemOnBlock(Item item, UseOnContext context) { + return CompatActionResult.create(item.useOn(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.interactLivingEntity(event.getStack(), event.getUser().getEntity(), event.getEntity(), event.getHand())); + } + + public static CompatUseAction getUseAction(Item item, UseActionArgs args) { + return CompatUseAction.of(item.getUseAnimation(args.stack)); + } + + public static CompatUseAction getUseAction(Item item, ItemStack stack) { + return CompatUseAction.of(item.getUseAnimation(stack)); + } + + public static CompatActionResult useBlock(BlockState state, Level world, Player player, BlockHitResult hitResult) { + return BlockStateUtil.onUse(state, world, player, hitResult); + } + + public static CompatActionResult useBlock(BlockState state, Level world, Player player, Direction dir, BlockPos blockPos) { + return BlockStateUtil.onUse(state, world, player, dir, blockPos); + } + + public static boolean onStoppingUsing(Item item, ItemStack stack, Level world, Player player, int remainingUseTicks) { + return item.releaseUsing(stack, world, player.getEntity(), remainingUseTicks); + } +} 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..16dabe77b --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/InventoryUtil.java @@ -0,0 +1,230 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.world.ContainerHelper; +import net.minecraft.world.Container; +import net.minecraft.world.SimpleContainer; +import net.minecraft.world.item.ItemStack; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.level.storage.TagValueInput; +import net.minecraft.world.level.storage.TagValueOutput; +import net.minecraft.world.level.storage.ValueInput; +import net.minecraft.world.level.storage.ValueOutput; +import net.minecraft.util.ProblemReporter; +import net.minecraft.core.NonNullList; +import net.minecraft.world.level.Level; +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.registry.CompatRegistryLookup; +import net.pitan76.mcpitanlib.api.util.nbt.NbtListUtil; +import net.pitan76.mcpitanlib.core.mc1216.NbtDataConverter; + +public class InventoryUtil { + public static boolean insertItem(ItemStack insertStack, NonNullList inventory) { + return insertItem(insertStack, inventory, false); + } + + public static boolean insertItem(ItemStack insertStack, NonNullList 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.grow(j); + isInserted = j > 0; + break; + } + } + return isInserted; + + } + + public static boolean canMergeItems(ItemStack first, ItemStack second) { + if (!first.is(second.getItem())) { + return false; + } + if (first.getDamageValue() != second.getDamageValue()) { + return false; + } + if (first.getCount() + second.getCount() > first.getMaxStackSize()) { + return false; + } + return ItemStackUtil.areNbtOrComponentEqual(first, second); + } + + public static CompoundTag writeNbt(NbtRWArgs args, CompoundTag nbt, NonNullList stacks, boolean setIfEmpty) { + boolean nbtNull = nbt == null; + + if (args instanceof WriteNbtArgs) { + WriteNbtArgs writeNbtArgs = (WriteNbtArgs) args; + if (writeNbtArgs.view == null) writeNbtArgs.view = TagValueOutput.createWithoutContext(ProblemReporter.DISCARDING); + + ContainerHelper.saveAllItems(writeNbtArgs.view, stacks, setIfEmpty); + if (!nbtNull) + NbtUtil.put(nbt, "Items", NbtListUtil.create()); // dummy list to compat with old mod + + NbtDataConverter.data2nbt(writeNbtArgs.view, nbt); + return nbt; + } + + ValueOutput view = NbtDataConverter.nbt2writeData(nbt, args.registryLookup); + ContainerHelper.saveAllItems(view, stacks, setIfEmpty); + if (!nbtNull) + NbtUtil.put(nbt, "Items", NbtListUtil.create()); // dummy list to compat with old mod + + NbtDataConverter.data2nbt(view, nbt); + return nbt; + } + + public static void readNbt(NbtRWArgs args, CompoundTag nbt, NonNullList stacks) { + if (args instanceof ReadNbtArgs) { + ReadNbtArgs readNbtArgs = (ReadNbtArgs) args; + if (readNbtArgs.view == null) return; + + ContainerHelper.loadAllItems(readNbtArgs.view, stacks); + return; + } + + ValueInput view = NbtDataConverter.nbt2readData(nbt, args.registryLookup); + ContainerHelper.loadAllItems(view, stacks); + } + + public static CompoundTag writeNbt(NbtRWArgs args, NonNullList stacks, boolean setIfEmpty) { + return writeNbt(args, args.getNbt(), stacks, setIfEmpty); + } + + public static CompoundTag writeNbt(NbtRWArgs args, NonNullList stacks) { + return writeNbt(args, stacks, true); + } + + public static void readNbt(NbtRWArgs args, NonNullList stacks) { + readNbt(args, args.getNbt(), stacks); + } + + public static void readNbt(CompatRegistryLookup registryLookup, CompoundTag nbt, NonNullList stacks) { + ValueInput view = NbtDataConverter.nbt2readData(nbt, registryLookup); + ContainerHelper.loadAllItems(view, stacks); + } + + public static CompoundTag writeNbt(CompatRegistryLookup registryLookup, CompoundTag nbt, NonNullList stacks, boolean setIfEmpty) { + NbtUtil.put(nbt, "Items", NbtListUtil.create()); + ValueOutput view = NbtDataConverter.nbt2writeData(nbt, registryLookup); + ContainerHelper.saveAllItems(view, stacks, setIfEmpty); + + NbtDataConverter.data2nbt(view, nbt); + + System.out.println("writeNbt(): " + nbt); + + return nbt; + } + + public static CompoundTag writeNbt(CompatRegistryLookup registryLookup, CompoundTag nbt, NonNullList stacks) { + return writeNbt(registryLookup, nbt, stacks, true); + } + + // deprecated + /** + * @deprecated Use {@link #writeNbt(NbtRWArgs, NonNullList)} instead + */ + @Deprecated + public static CompoundTag writeNbt(Level world, CompoundTag nbt, NonNullList stacks) { + return writeNbt(world, nbt, true, stacks); + } + + /** + * @deprecated Use {@link #writeNbt(NbtRWArgs, NonNullList, boolean)} instead + */ + @Deprecated + public static CompoundTag writeNbt(Level world, CompoundTag nbt, boolean setIfEmpty, NonNullList stacks) { + return writeNbt(new NbtRWArgs(nbt), stacks, setIfEmpty); + } + + /** + * @deprecated Use {@link #readNbt(NbtRWArgs, NonNullList)} instead + */ + @Deprecated + public static void readNbt(Level world, CompoundTag nbt, NonNullList stacks) { + readNbt(new ReadNbtArgs(nbt), stacks); + } + // ---- + + public static SimpleContainer createSimpleInventory(int size) { + return new SimpleContainer(size); + } + + public static void copyToInv(NonNullList from, Container to) { + for (int i = 0; i < from.size(); i++) { + to.setItem(i, from.get(i)); + } + } + + public static void copyToList(Container from, NonNullList to) { + for (int i = 0; i < from.getContainerSize(); i++) { + to.set(i, from.getItem(i)); + } + } + + public static int getSize(Container inventory) { + return inventory.getContainerSize(); + } + + public static ItemStack getStack(Container inventory, int slot) { + return inventory.getItem(slot); + } + + public static void setStack(Container inventory, int slot, ItemStack stack) { + inventory.setItem(slot, stack); + } + + public static boolean isEmpty(Container inventory) { + return inventory.isEmpty(); + } + + public static ItemStack removeStack(Container inventory, int slot) { + return inventory.removeItemNoUpdate(slot); + } + + public static ItemStack removeStack(Container inventory, int slot, int amount) { + return inventory.removeItem(slot, amount); + } + + public static void clear(Container inventory) { + inventory.clearContent(); + } + + public static void markDirty(Container inventory) { + inventory.setChanged(); + } + + public static net.pitan76.mcpitanlib.midohra.nbt.NbtCompound writeNbt(CompatRegistryLookup registryLookup, net.pitan76.mcpitanlib.midohra.nbt.NbtCompound nbt, NonNullList stacks, boolean setIfEmpty) { + return net.pitan76.mcpitanlib.midohra.nbt.NbtCompound.of(writeNbt(registryLookup, nbt.toMinecraft(), stacks, setIfEmpty)); + } + + public static net.pitan76.mcpitanlib.midohra.nbt.NbtCompound writeNbt(CompatRegistryLookup registryLookup, net.pitan76.mcpitanlib.midohra.nbt.NbtCompound nbt, NonNullList stacks) { + return writeNbt(registryLookup, nbt, stacks, true); + } + + public static void readNbt(CompatRegistryLookup registryLookup, net.pitan76.mcpitanlib.midohra.nbt.NbtCompound nbt, NonNullList stacks) { + readNbt(registryLookup, nbt.toMinecraft(), stacks); + } + + public static net.pitan76.mcpitanlib.midohra.nbt.NbtCompound writeNbt(net.pitan76.mcpitanlib.api.event.nbt.NbtRWArgs args, net.pitan76.mcpitanlib.midohra.nbt.NbtCompound nbt, NonNullList stacks, boolean setIfEmpty) { + return net.pitan76.mcpitanlib.midohra.nbt.NbtCompound.of(writeNbt(args, nbt.toMinecraft(), stacks, setIfEmpty)); + } + + public static net.pitan76.mcpitanlib.midohra.nbt.NbtCompound writeNbt(net.pitan76.mcpitanlib.api.event.nbt.NbtRWArgs args, net.pitan76.mcpitanlib.midohra.nbt.NbtCompound nbt, NonNullList stacks) { + return writeNbt(args, nbt, stacks, true); + } + + public static void readNbt(net.pitan76.mcpitanlib.api.event.nbt.NbtRWArgs args, net.pitan76.mcpitanlib.midohra.nbt.NbtCompound nbt, NonNullList stacks) { + readNbt(args, nbt.toMinecraft(), stacks); + } + + public static boolean canMergeItems(net.pitan76.mcpitanlib.midohra.item.ItemStack first, net.pitan76.mcpitanlib.midohra.item.ItemStack second) { + return canMergeItems(first.toMinecraft(), second.toMinecraft()); + } +} 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..1d5674830 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/ItemStackUtil.java @@ -0,0 +1,193 @@ +package net.pitan76.mcpitanlib.api.util; + +import com.mojang.datafixers.util.Pair; +import com.mojang.serialization.DataResult; +import net.minecraft.world.entity.EquipmentSlot; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.item.Item; +import net.minecraft.world.level.ItemLike; +import net.minecraft.world.item.ItemStack; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.Tag; +import net.minecraft.nbt.NbtOps; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.level.Level; +import net.pitan76.mcpitanlib.api.entity.Player; +import net.pitan76.mcpitanlib.api.event.nbt.NbtRWArgs; +import net.pitan76.mcpitanlib.api.event.nbt.ReadNbtArgs; +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.isSameItem(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(Level world, CompoundTag nbt) { + return fromNbt(new ReadNbtArgs(nbt)); + } + + /** + * NBTからItemStackを取得する + * @param args NbtRWArgs + * @return ItemStack + */ + public static ItemStack fromNbt(NbtRWArgs args) { + DataResult> result = ItemStack.CODEC.decode(NbtOps.INSTANCE, args.nbt); + if (result.error().isPresent()) return ItemStack.EMPTY; + + Pair pair = result.result().orElseThrow(); + return pair.getFirst(); + } + + public static ItemStack getDefaultStack(Item item) { + return item.getDefaultInstance(); + } + + 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.getDamageValue(); + } + + public static void setDamage(ItemStack stack, int damage) { + stack.setDamageValue(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.shrink(count); + } + + public static void incrementCount(ItemStack stack, int count) { + stack.grow(count); + } + + public static void damage(ItemStack stack, int amount, ServerPlayer entity, Runnable breakCallback) { + stack.hurtAndBreak(amount, entity.level(), entity, (item) -> breakCallback.run()); + } + + public static void damage(ItemStack stack, int amount, LivingEntity entity, EquipmentSlot slot) { + stack.hurtAndBreak(amount, entity, slot); + } + + public static void damage(ItemStack stack, int amount, ServerPlayer entity) { + stack.hurtAndBreak(amount, entity.level(), entity, (item) -> entity.onEquippedItemBroken(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(ItemLike item) { + if (item == null) return empty(); + return new ItemStack(item); + } + + public static ItemStack create(ItemLike 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.isDamageableItem(); + } + + 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.getMaxStackSize(); + } + + 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..3c37ceeab --- /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.world.level.block.Block; +import net.minecraft.world.item.BlockItem; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.resources.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.Properties 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.Properties 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..6d7a5b0b2 --- /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.level.Level; +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, Level 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, Level 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, Level 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, Level 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..3446553b3 --- /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().getLaunchedVersion(); + } + + 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..bfa65c6b9 --- /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 com.mojang.math.Axis; +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(Axis.XP); + public static RotationAxisType POSITIVE_Y = new RotationAxisType(Axis.YP); + public static RotationAxisType POSITIVE_Z = new RotationAxisType(Axis.ZP); + + protected final Axis axis; + protected RotationAxisType(Axis 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..7d43ea14e --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/NbtUtil.java @@ -0,0 +1,570 @@ +package net.pitan76.mcpitanlib.api.util; + +import com.mojang.datafixers.util.Pair; +import com.mojang.serialization.DataResult; +import net.minecraft.nbt.ByteTag; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.DoubleTag; +import net.minecraft.nbt.FloatTag; +import net.minecraft.nbt.IntTag; +import net.minecraft.nbt.ListTag; +import net.minecraft.nbt.LongTag; +import net.minecraft.nbt.ShortTag; +import net.minecraft.nbt.StringTag; +import net.minecraft.nbt.Tag; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.nbt.*; +import net.minecraft.core.BlockPos; +import net.minecraft.world.phys.Vec3; +import net.minecraft.core.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 CompoundTag create() { + return new CompoundTag(); + } + + /** + * 値を設定する。 + * @param nbt NbtCompound + * @param key キー + * @param value 値 + */ + public static void put(CompoundTag nbt, String key, CompoundTag value) { + nbt.put(key, value); + } + + /** + * 値を設定する。 + * @param nbt NbtCompound + * @param key キー + * @param value 値 + */ + public static void put(CompoundTag nbt, String key, Tag value) { + nbt.put(key, value); + } + + /** + * 値を取得する。 + * @param nbt NbtCompound + * @param key キー + * @return 値 + */ + public static CompoundTag get(CompoundTag nbt, String key) { + return nbt.getCompoundOrEmpty(key); + } + + /** + * 値を削除する。 + * @param nbt NbtCompound + * @param key キー + */ + public static void remove(CompoundTag nbt, String key) { + nbt.remove(key); + } + + /** + * 値が存在するかどうかを取得する。 + * @param nbt NbtCompound + * @param key キー + * @return 値が存在するかどうか + */ + public static boolean has(CompoundTag nbt, String key) { + return nbt.contains(key); + } + + /** + * 指定した型の値を取得する + * @param nbt NbtCompound + * @param key キー + * @param clazz クラス + * @param 値 + */ + public static T get(CompoundTag nbt, String key, Class clazz) { + if (clazz == Integer.class) { + return (T) Integer.valueOf(nbt.getIntOr(key, 0)); + } + if (clazz == String.class) { + return (T) nbt.getString(key).orElse(""); + } + if (clazz == Boolean.class) { + return (T) Boolean.valueOf(nbt.getBooleanOr(key, false)); + } + if (clazz == Float.class) { + return (T) Float.valueOf(nbt.getFloatOr(key, 0f)); + } + if (clazz == Double.class) { + return (T) Double.valueOf(nbt.getDoubleOr(key, 0d)); + } + if (clazz == Long.class) { + return (T) Long.valueOf(nbt.getLongOr(key, 0l)); + } + if (clazz == CompoundTag.class) { + return (T) nbt.getCompoundOrEmpty(key); + } + if (clazz == ListTag.class) { + return (T) nbt.get(key); + } + if (clazz == Byte.class) { + return (T) Byte.valueOf(nbt.getByteOr(key, (byte) 0)); + } + if (clazz == Short.class) { + return (T) Short.valueOf(nbt.getShortOr(key, (short) 0)); + } + if (clazz == UUID.class) { + return (T) UUID.fromString(nbt.getString(key).orElse("")); + } + return null; + } + + /** + * 値を設定する。 + * @param nbt NbtCompound + * @param key キー + * @param value 値 + */ + public static void set(CompoundTag 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 CompoundTag) { + nbt.put(key, (CompoundTag) value); + return; + } + if (value instanceof ListTag) { + nbt.put(key, (ListTag) 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.putString(key, value.toString()); + return; + } + } + + /** + * キーの一覧を取得する。 + * @param nbt NbtCompound + * @return キーの一覧 + */ + public static Set getKeys(CompoundTag nbt) { + return nbt.keySet(); + } + + /** + * NbtListを取得する。 + * @return NbtList + */ + public static ListTag getList(CompoundTag nbt, String key) { + return (ListTag) nbt.get(key); + } + + /** + * NbtListを取得する。 + * @return NbtList + */ + public static ListTag getList(CompoundTag nbt, String key, int type) { + return nbt.getListOrEmpty(key); + } + + /** + * NbtCompoundのリストを取得する。 + * @return NbtList + */ + public static ListTag getNbtCompoundList(CompoundTag nbt, String key) { + return nbt.getListOrEmpty(key); + } + + /** + * NbtCompoundをコピーする。 + * @return NbtCompound + */ + public static CompoundTag copy(CompoundTag nbt) { + return nbt.copy(); + } + + // Helper methods + + public static void putInt(CompoundTag nbt, String key, int value) { + set(nbt, key, value); + } + + public static int getInt(CompoundTag nbt, String key) { + if (has(nbt, key)) + return get(nbt, key, Integer.class); + return 0; + } + + public static void putString(CompoundTag nbt, String key, String value) { + set(nbt, key, value); + } + + public static String getString(CompoundTag nbt, String key) { + if (has(nbt, key)) + return get(nbt, key, String.class); + return ""; + } + + public static void putBoolean(CompoundTag nbt, String key, boolean value) { + set(nbt, key, value); + } + + public static boolean getBoolean(CompoundTag nbt, String key) { + if (has(nbt, key)) + return get(nbt, key, Boolean.class); + return false; + } + + public static void putFloat(CompoundTag nbt, String key, float value) { + set(nbt, key, value); + } + + public static float getFloat(CompoundTag nbt, String key) { + if (has(nbt, key)) + return get(nbt, key, Float.class); + return 0; + } + + public static void putDouble(CompoundTag nbt, String key, double value) { + set(nbt, key, value); + } + + public static double getDouble(CompoundTag nbt, String key) { + if (has(nbt, key)) + return get(nbt, key, Double.class); + return 0; + } + + public static void putLong(CompoundTag nbt, String key, long value) { + set(nbt, key, value); + } + + public static long getLong(CompoundTag nbt, String key) { + if (has(nbt, key)) + return get(nbt, key, Long.class); + return 0; + } + + public static void putByte(CompoundTag nbt, String key, byte value) { + set(nbt, key, value); + } + + public static byte getByte(CompoundTag nbt, String key) { + if (has(nbt, key)) + return get(nbt, key, Byte.class); + return 0; + } + + public static void putShort(CompoundTag nbt, String key, short value) { + set(nbt, key, value); + } + + public static short getShort(CompoundTag nbt, String key) { + if (has(nbt, key)) + return get(nbt, key, Short.class); + return 0; + } + + public static void putUuid(CompoundTag nbt, String key, UUID value) { + set(nbt, key, value); + } + + public static UUID getUuid(CompoundTag 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(CompoundTag nbt, String key, BlockPos pos) { + CompoundTag 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(CompoundTag nbt, String key) { + CompoundTag posNbt = get(nbt, key); + return PosUtil.flooredBlockPos(getInt(posNbt, "x"), getInt(posNbt, "y"), getInt(posNbt, "z")); + } + + public static void putVec3i(CompoundTag nbt, String key, Vec3i vec3i) { + CompoundTag 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(CompoundTag nbt, String key) { + CompoundTag vec3iNbt = get(nbt, key); + return Vec3iUtil.create(getInt(vec3iNbt, "x"), getInt(vec3iNbt, "y"), getInt(vec3iNbt, "z")); + } + + public static void putVec3d(CompoundTag nbt, String key, Vec3 vec3d) { + CompoundTag vec3dNbt = create(); + putDouble(vec3dNbt, "x", vec3d.x()); + putDouble(vec3dNbt, "y", vec3d.y()); + putDouble(vec3dNbt, "z", vec3d.z()); + put(nbt, key, vec3dNbt); + } + + public static Vec3 getVec3d(CompoundTag nbt, String key) { + CompoundTag vec3dNbt = get(nbt, key); + return Vec3dUtil.create(getDouble(vec3dNbt, "x"), getDouble(vec3dNbt, "y"), getDouble(vec3dNbt, "z")); + } + + public static void putItemStack(CompoundTag nbt, String key, ItemStack stack, CompatRegistryLookup registryLookup) { + DataResult dataResult = ItemStack.CODEC.encodeStart(NbtOps.INSTANCE, stack); + put(nbt, key, dataResult.getOrThrow()); + } + + public static Optional getItemStack(CompoundTag nbt, String key, CompatRegistryLookup registryLookup) { + Tag stackNbt = get(nbt, key); + DataResult> dataResult = ItemStack.CODEC.decode(NbtOps.INSTANCE, stackNbt); + if (dataResult.error().isPresent()) return Optional.empty(); + + Pair pair = dataResult.getOrThrow(); + return Optional.ofNullable(pair.getFirst()); + } + + public static void putSimpleItemStack(CompoundTag nbt, String key, ItemStack stack) { + CompoundTag stackNbt = create(); + putString(stackNbt, "id", ItemUtil.toID(stack.getItem()).toString()); + putByte(stackNbt, "Count", (byte) ItemStackUtil.getCount(stack)); + + CompoundTag tagNbt = create(); + CompoundTag 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(CompoundTag nbt, String key) { + if (!has(nbt, key)) return Optional.empty(); + CompoundTag 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")) { + CompoundTag tagNbt = get(stackNbt, "tag"); + if (has(tagNbt, "components")) { + CompoundTag componentsNbt = get(tagNbt, "components"); + if (has(componentsNbt, "minecraft:custom_data")) { + CustomDataUtil.setNbt(stack, get(componentsNbt, "minecraft:custom_data")); + } + } + } + + return Optional.of(stack); + } + + public static ListTag createNbtList() { + return new ListTag(); + } + + public static int getIntOrDefault(CompoundTag nbt, String key, int defaultValue) { + if (has(nbt, key)) + return getInt(nbt, key); + return defaultValue; + } + + public static String getStringOrDefault(CompoundTag nbt, String key, String defaultValue) { + if (has(nbt, key)) + return getString(nbt, key); + return defaultValue; + } + + public static boolean getBooleanOrDefault(CompoundTag nbt, String key, boolean defaultValue) { + if (has(nbt, key)) + return getBoolean(nbt, key); + return defaultValue; + } + + public static float getFloatOrDefault(CompoundTag nbt, String key, float defaultValue) { + if (has(nbt, key)) + return getFloat(nbt, key); + return defaultValue; + } + + public static double getDoubleOrDefault(CompoundTag nbt, String key, double defaultValue) { + if (has(nbt, key)) + return getDouble(nbt, key); + return defaultValue; + } + + public static long getLongOrDefault(CompoundTag nbt, String key, long defaultValue) { + if (has(nbt, key)) + return getLong(nbt, key); + return defaultValue; + } + + public static byte getByteOrDefault(CompoundTag nbt, String key, byte defaultValue) { + if (has(nbt, key)) + return getByte(nbt, key); + return defaultValue; + } + + public static short getShortOrDefault(CompoundTag nbt, String key, short defaultValue) { + if (has(nbt, key)) + return getShort(nbt, key); + return defaultValue; + } + + public static UUID getUuidOrDefault(CompoundTag nbt, String key, UUID defaultValue) { + if (has(nbt, key)) + return getUuid(nbt, key); + return defaultValue; + } + + public static Tag getElement(CompoundTag nbt, String key) { + return nbt.get(key); + } + + public static void putElement(CompoundTag nbt, String key, Tag element) { + nbt.put(key, element); + } + + public static void setBlockPosDirect(CompoundTag nbt, BlockPos pos) { + putInt(nbt, "x", pos.getX()); + putInt(nbt, "y", pos.getY()); + putInt(nbt, "z", pos.getZ()); + } + + public static BlockPos getBlockPosDirect(CompoundTag nbt) { + return PosUtil.flooredBlockPos(getInt(nbt, "x"), getInt(nbt, "y"), getInt(nbt, "z")); + } + + public static void setVec3iDirect(CompoundTag nbt, Vec3i vec3i) { + putInt(nbt, "x", vec3i.getX()); + putInt(nbt, "y", vec3i.getY()); + putInt(nbt, "z", vec3i.getZ()); + } + + public static Vec3i getVec3iDirect(CompoundTag nbt) { + return Vec3iUtil.create(getInt(nbt, "x"), getInt(nbt, "y"), getInt(nbt, "z")); + } + + public static void setVec3dDirect(CompoundTag nbt, Vec3 vec3d) { + putDouble(nbt, "x", vec3d.x()); + putDouble(nbt, "y", vec3d.y()); + putDouble(nbt, "z", vec3d.z()); + } + + public static Vec3 getVec3dDirect(CompoundTag nbt) { + return Vec3dUtil.create(getDouble(nbt, "x"), getDouble(nbt, "y"), getDouble(nbt, "z")); + } + + public static void setVec3iDirect(CompoundTag nbt, int x, int y, int z) { + putInt(nbt, "x", x); + putInt(nbt, "y", y); + putInt(nbt, "z", z); + } + + public static void setVec3dDirect(CompoundTag nbt, double x, double y, double z) { + putDouble(nbt, "x", x); + putDouble(nbt, "y", y); + putDouble(nbt, "z", z); + } + + public static String asString(Tag nbt) { + return nbt.asString().orElse(""); + } + + public static StringTag createString(String string) { + return StringTag.valueOf(string); + } + + public static IntTag createInt(int value) { + return IntTag.valueOf(value); + } + + public static FloatTag createFloat(float value) { + return FloatTag.valueOf(value); + } + + public static DoubleTag createDouble(double value) { + return DoubleTag.valueOf(value); + } + + public static LongTag createLong(long value) { + return LongTag.valueOf(value); + } + + public static ByteTag createByte(byte value) { + return ByteTag.valueOf(value); + } + + public static ShortTag createShort(short value) { + return ShortTag.valueOf(value); + } + + public static void copyFrom(CompoundTag source, CompoundTag target) { + target.merge(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..ab77baa79 --- /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.core.particles.ParticleOptions; +import net.minecraft.core.particles.ParticleType; +import net.pitan76.mcpitanlib.api.util.particle.effect.ItemStackParticleEffectUtil; + +public class ParticleEffectUtil { + public static ItemStackParticleEffectUtil itemStack = new ItemStackParticleEffectUtil(); + + public static ParticleType getType(ParticleOptions 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..7ed659dc2 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/PersistentStateUtil.java @@ -0,0 +1,55 @@ +package net.pitan76.mcpitanlib.api.util; + +import com.mojang.serialization.Codec; +import net.minecraft.util.datafix.DataFixTypes; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.saveddata.SavedData; +import net.minecraft.world.level.saveddata.SavedDataType; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.storage.SavedDataStorage; +import net.pitan76.mcpitanlib.api.event.nbt.ReadNbtArgs; +import net.pitan76.mcpitanlib.api.event.nbt.WriteNbtArgs; +import net.pitan76.mcpitanlib.api.world.CompatiblePersistentState; + +import java.util.function.Function; +import java.util.function.Supplier; + +public class PersistentStateUtil { + public static T getOrCreate(SavedDataStorage manager, String id, Supplier supplier, Function function) { + Codec codec = CompoundTag.CODEC.xmap( + // NBT -> PersistentState + (nbt) -> { + T state = supplier.get(); + + if (state instanceof CompatiblePersistentState) + ((CompatiblePersistentState) state).readNbt(new ReadNbtArgs(nbt)); + + return state; + }, + // PersistentState -> NBT + (state) -> { + if (state instanceof CompatiblePersistentState) + return ((CompatiblePersistentState) state).writeNbt(new WriteNbtArgs(new CompoundTag())); + + return NbtUtil.create(); + } + ); + + SavedDataType type = new SavedDataType<>(IdentifierUtil.id("mcpitanlib", id), supplier, codec, DataFixTypes.LEVEL); + return manager.computeIfAbsent(type); + } + + public static SavedDataStorage getManagerFromServer(MinecraftServer server) { + return server.getLevel(Level.OVERWORLD).getDataStorage(); + } + + public static SavedDataStorage getManagerFromWorld(ServerLevel world) { + return world.getDataStorage(); + } + + public static void markDirty(SavedData state) { + state.setDirty(); + } +} \ 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..cfe8a7ab4 --- /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.core.Holder; +import net.minecraft.world.level.levelgen.VerticalAnchor; +import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; +import net.minecraft.world.level.levelgen.placement.PlacedFeature; +import net.minecraft.world.level.levelgen.placement.CountPlacement; +import net.minecraft.world.level.levelgen.placement.HeightRangePlacement; +import net.minecraft.world.level.levelgen.placement.PlacementModifier; +import net.minecraft.world.level.levelgen.placement.InSquarePlacement; + +import java.util.List; + +public class PlacedFutureUtil { + public static PlacedFeature create(ConfiguredFeature configuredFeature, List placementModifiers) { + return new PlacedFeature(Holder.direct(configuredFeature), placementModifiers); + } + + public static List createPlacementModifiers(CountPlacement countPlacementModifier, InSquarePlacement squarePlacementModifier, HeightRangePlacement heightRangePlacementModifier) { + return List.of(countPlacementModifier, squarePlacementModifier, heightRangePlacementModifier); + } + + public static List createPlacementModifiers(int chunkCount, int top, int bottom) { + return createPlacementModifiers( +CountPlacement.of(chunkCount), + InSquarePlacement.spread(), + HeightRangePlacement.uniform(VerticalAnchor.absolute(bottom), VerticalAnchor.absolute(top)) + ); + } + + public static List createPlacementModifiers(int chunkCount, int top) { + return createPlacementModifiers( + CountPlacement.of(chunkCount), + InSquarePlacement.spread(), + HeightRangePlacement.uniform(VerticalAnchor.bottom(), VerticalAnchor.absolute(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..150536356 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/PlatformUtil.java @@ -0,0 +1,87 @@ +package net.pitan76.mcpitanlib.api.util; + +import dev.architectury.injectables.annotations.ExpectPlatform; +import net.fabricmc.api.EnvType; +import net.fabricmc.loader.api.FabricLoader; + +import java.io.File; +import java.nio.file.Path; +import java.util.Collection; + +public class PlatformUtil { + @ExpectPlatform + public static boolean isDevelopmentEnvironment() { + return FabricLoader.getInstance().isDevelopmentEnvironment(); + } + + @ExpectPlatform + public static boolean isFabric() { + return false; + } + + @ExpectPlatform + public static boolean isForge() { + return false; + } + + @ExpectPlatform + public static boolean isNeoForge() { + return false; + } + + @ExpectPlatform + public static boolean isClient() { + return FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT; + } + + @ExpectPlatform + public static boolean isServer() { + return FabricLoader.getInstance().getEnvironmentType() == EnvType.SERVER; + } + + @ExpectPlatform + public static Path getConfigFolder() { + return FabricLoader.getInstance().getConfigDir(); + } + + @ExpectPlatform + public static boolean isModLoaded(String id) { + return FabricLoader.getInstance().isModLoaded(id); + } + + @ExpectPlatform + public static Path getGameFolder() { + return FabricLoader.getInstance().getGameDir(); + } + + public static Path getModsFolder() { + return getGameFolder().resolve("mods"); + } + + public static File getConfigFolderAsFile() { + return getConfigFolder().toFile(); + } + + public static File getGameFolderAsFile() { + return getGameFolder().toFile(); + } + + public static File getModsFolderAsFile() { + return getModsFolder().toFile(); + } + + @ExpectPlatform + public static Collection getModIds() { + return FabricLoader.getInstance().getAllMods().stream().map(modContainer -> modContainer.getMetadata().getId()).toList(); + } + + @ExpectPlatform + public static EnvType getEnv() { + return FabricLoader.getInstance().getEnvironmentType(); + } + + @ExpectPlatform + public static String getGameVersion() { + return FabricLoader.getInstance().getRawGameVersion(); + } +} 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..3c38b801f --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/PlayerManagerUtil.java @@ -0,0 +1,129 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.players.PlayerList; +import net.minecraft.world.level.Level; +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(Level world) { + List players = new ArrayList<>(); + for (net.minecraft.world.entity.player.Player p : world.players()) { + players.add(new Player(p)); + } + return players; + } + + /** + * Get player by UUID + * @param world World + * @param uuid UUID + * @return Player + */ + public static Player getPlayerByUUID(Level world, UUID uuid) { + return PlayerUtil.getPlayerByUUID(world, uuid); + } + + /** + * Get player by name + * @param world World + * @param name String + * @return Player + */ + public static Player getPlayerByName(Level world, String name) { + return PlayerUtil.getPlayerByName(world, name); + } + + public static PlayerList getPlayerManager(MinecraftServer server) { + return ServerUtil.getPlayerManager(server); + } + + public static PlayerList getPlayerManager(Level world) { + return getPlayerManager(world.getServer()); + } + + public static boolean hasPlayerByUUID(PlayerList playerManager, UUID uuid) { + return playerManager.getPlayer(uuid) != null; + } + + public static boolean hasPlayerByName(PlayerList playerManager, String name) { + return playerManager.getPlayerByName(name) != null; + } + + public static boolean hasPlayerByIP(PlayerList playerManager, String ip) { + return !playerManager.getPlayersWithAddress(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(Level world, UUID uuid) { + return hasPlayerByUUID(getPlayerManager(world), uuid); + } + + public static boolean hasPlayerByName(Level world, String name) { + return hasPlayerByName(getPlayerManager(world), name); + } + + public static boolean hasPlayerByIP(Level 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..141711dfb --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/PlayerUtil.java @@ -0,0 +1,97 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.server.MinecraftServer; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +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.getPlayerList().getPlayer(uuid)); + } + + public static Player getPlayerByName(MinecraftServer server, String name) { + return new Player(server.getPlayerList().getPlayerByName(name)); + } + + public static List getPlayersByIP(MinecraftServer server, String ip) { + List players = new ArrayList<>(); + for (net.minecraft.world.entity.player.Player p: server.getPlayerList().getPlayersWithAddress(ip)) { + players.add(new Player(p)); + } + return players; + } + + public static List getPlayers(MinecraftServer server) { + List players = new ArrayList<>(); + for (net.minecraft.world.entity.player.Player p : server.getPlayerList().getPlayers()) { + players.add(new Player(p)); + } + return players; + } + + public static Player getPlayerByUUID(Level world, UUID uuid) { + return getPlayerByUUID(world.getServer(), uuid); + } + + public static Player getPlayerByName(Level world, String name) { + return getPlayerByName(world.getServer(), name); + } + + public static boolean isExistByUUID(MinecraftServer server, UUID uuid) { + return server.getPlayerList().getPlayer(uuid) != null; + } + + public static boolean isExistByUUID(Level world, UUID uuid) { + return isExistByUUID(world.getServer(), uuid); + } + + public static boolean isExistByName(MinecraftServer server, String name) { + return server.getPlayerList().getPlayerByName(name) != null; + } + + public static boolean isExistByName(Level world, String name) { + return isExistByName(world.getServer(), name); + } + + public static boolean isExistByIP(MinecraftServer server, String ip) { + return !server.getPlayerList().getPlayersWithAddress(ip).isEmpty(); + } + + public static boolean isExistByIP(Level 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 Level 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..d36f78b91 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/PropertyUtil.java @@ -0,0 +1,165 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.properties.BlockStateProperties; +import net.minecraft.world.level.block.state.properties.BooleanProperty; +import net.minecraft.world.level.block.state.properties.EnumProperty; +import net.minecraft.world.level.block.state.properties.Half; +import net.minecraft.world.level.block.state.properties.IntegerProperty; +import net.minecraft.world.level.block.state.properties.Property; +import net.minecraft.world.level.block.state.properties.StairsShape; +import net.minecraft.util.StringRepresentable; +import net.minecraft.core.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.create(name); + } + + public static DirectionProperty createDirectionProperty(String name) { + return DirectionProperty.of(name); + } + + public static IntegerProperty createIntProperty(String name, int min, int max) { + return IntegerProperty.create(name, min, max); + } + + public static & StringRepresentable> EnumProperty createEnumProperty(String name, Class type) { + return EnumProperty.create(name, type); + } + + public static BlockState with(BlockState state, BooleanProperty property, boolean value) { + return state.setValue(property, value); + } + + public static BlockState with(BlockState state, IntegerProperty property, int value) { + return state.setValue(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.getValue(property); + } + + public static int get(BlockState state, IntegerProperty property) { + return state.getValue(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.getValue(power()); + } + + public static boolean isPowered(BlockState state) { + return state.getValue(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 IntegerProperty power() { + return BlockStateProperties.POWER; + } + + public static BooleanProperty powered() { + return BlockStateProperties.POWERED; + } + + public static DirectionProperty facing() { + return CompatProperties.FACING; + } + + public static DirectionProperty horizontalFacing() { + return CompatProperties.HORIZONTAL_FACING; + } + + public static EnumProperty axis() { + return BlockStateProperties.AXIS; + } + + public static EnumProperty blockHalf() { + return BlockStateProperties.HALF; + } + + public static EnumProperty stairShape() { + return BlockStateProperties.STAIRS_SHAPE; + } + + public static BooleanProperty lit() { + return BlockStateProperties.LIT; + } + + public static BooleanProperty waterlogged() { + return BlockStateProperties.WATERLOGGED; + } + + public static BooleanProperty attached() { + return BlockStateProperties.ATTACHED; + } + + public static BooleanProperty hanging() { + return BlockStateProperties.HANGING; + } + + public static BooleanProperty bottom() { + return BlockStateProperties.BOTTOM; + } + + public static BooleanProperty conditional() { + return BlockStateProperties.CONDITIONAL; + } + + public static BooleanProperty inWall() { + return BlockStateProperties.IN_WALL; + } + + public static BooleanProperty open() { + return BlockStateProperties.OPEN; + } + + public static BooleanProperty occupied() { + return BlockStateProperties.OCCUPIED; + } + + public static boolean contains(BlockState state, Property property) { + return state.hasProperty(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..344f8e136 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/RecipeUtil.java @@ -0,0 +1,224 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.core.NonNullList; +import net.minecraft.core.registries.Registries; +import net.minecraft.resources.Identifier; +import net.minecraft.resources.ResourceKey; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.Container; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.ItemStackTemplate; +import net.minecraft.world.item.crafting.*; +import net.minecraft.world.level.Level; +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, NonNullList input) { + CraftingRecipe.CraftingBookInfo craftingBookInfo = new CraftingRecipe.CraftingBookInfo(CraftingBookCategory.valueOf(category.name()), group); + Recipe.CommonInfo commonInfo = new Recipe.CommonInfo(false); + ItemStackTemplate outputTemplate = ItemStackTemplate.fromNonEmptyStack(output); + return new ShapelessRecipe(commonInfo, craftingBookInfo, outputTemplate, input); + } + + public static ShapelessRecipe createShapelessRecipe(Identifier id, String group, ItemStack output, NonNullList input) { + return createShapelessRecipe(id, group, CompatibilityCraftingRecipeCategory.MISC, output, input); + } + + @Deprecated + public static ItemStack craft_2(Recipe recipe, C inventory, Level world) { + return recipe.assemble(inventory); + } + + @Deprecated + public static ItemStack getOutput_2(Recipe recipe, Level world) { + return craft_2(recipe, (C) CraftingInput.EMPTY, world); + } + + public static ItemStack craft(Recipe recipe, Container inventory, Level world) { + if (inventory instanceof RecipeInput) { + Recipe inputRecipe = (Recipe) recipe; + return inputRecipe.assemble((RecipeInput) inventory); + } + return ItemStack.EMPTY; + } + + public static ItemStack getOutput(Recipe recipe, Level world) { + return getOutput(recipe, RegistryLookupUtil.getRegistryLookup(world)); + } + + public static List> getAllRecipes(Level world) { + RecipeAccess iRecipeManager = getRecipeManager(world); + if (!(iRecipeManager instanceof RecipeManager)) + return new ArrayList<>(); + + RecipeManager recipeManager = (RecipeManager) iRecipeManager; + + Collection> recipes = recipeManager.getRecipes(); + List> outRecipes = new ArrayList<>(); + for (Object recipeEntryObj : recipes) { + if (recipeEntryObj instanceof RecipeHolder) { + RecipeHolder recipeEntry = (RecipeHolder) recipeEntryObj; + if (recipeEntry.value() instanceof Recipe) { + outRecipes.add(recipeEntry.value()); + } + } + } + return outRecipes; + } + + public static List> getAllCompatRecipeEntry(Level 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(RecipeAccess iRecipeManager, CompatRecipeType type, CompatRecipeInput input, Level world) { + if (!(iRecipeManager instanceof RecipeManager)) + return new CompatRecipeEntry<>(null); + + RecipeManager recipeManager = (RecipeManager) iRecipeManager; + + Optional> recipe = recipeManager.getRecipeFor(type.getType(), input.getInput(), world); + return recipe.map(CompatRecipeEntry::new).orElseGet(() -> new CompatRecipeEntry<>(null)); + } + + public static > CompatRecipeEntry getFirstMatch(RecipeAccess iRecipeManager, CompatRecipeType type, CompatRecipeInput input, Level world, CompatIdentifier identifier) { + if (!(iRecipeManager instanceof RecipeManager)) + return new CompatRecipeEntry<>(null); + + RecipeManager recipeManager = (RecipeManager) iRecipeManager; + + Optional> recipe = recipeManager.getRecipeFor(type.getType(), input.getInput(), world, ResourceKey.create(Registries.RECIPE, identifier.toMinecraft())); + return recipe.map(CompatRecipeEntry::new).orElseGet(() -> new CompatRecipeEntry<>(null)); + } + + public static > CompatRecipeEntry getFirstMatch(Level world, CompatRecipeType type, CompatRecipeInput input) { + return getFirstMatch(getRecipeManager(world), type, input, world); + } + + public static > CompatRecipeEntry getFirstMatch(Level world, CompatRecipeType type, CompatRecipeInput input, CompatIdentifier identifier) { + return getFirstMatch(getRecipeManager(world), type, input, world, identifier); + } + + public static RecipeAccess getRecipeManager(Level world) { + return world.recipeAccess(); + } + + public Optional> get(Level world, CompatIdentifier id) { + return get(getRecipeManager(world), id); + } + + public Optional> get(RecipeAccess iRecipeManager, CompatIdentifier id) { + if (!(iRecipeManager instanceof RecipeManager)) + return Optional.empty(); + RecipeManager recipeManager = (RecipeManager) iRecipeManager; + + return recipeManager.byKey(ResourceKey.create(Registries.RECIPE, id.toMinecraft())); + } + + public static > MatchGetter createCachedMatchGetter(RecipeType type) { + return (input, world) -> { + Optional> optional = RecipeManager.createCheck(type).getRecipeFor(input.getInput(), (ServerLevel) world); + return optional.map(CompatRecipeEntry::new); + }; + } + + public static > MatchGetter createCachedMatchGetter(CompatRecipeType type) { + return createCachedMatchGetter(type.getType()); + } + + public static NonNullList getInputs(Recipe recipe) { + List ingredients = recipe.placementInfo().ingredients(); + + NonNullList outIngredients = NonNullList.createWithCapacity(ingredients.size()); + + for (int i = 0; i < ingredients.size(); i++) { + outIngredients.set(i, ingredients.get(i)); + } + + return outIngredients; + } + + public static NonNullList getInputs(CompatRecipeEntry recipeEntry) { + return getInputs(recipeEntry.getRecipe()); + } + + public static ItemStackList getInputsAsStack(Recipe recipe) { + NonNullList 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) { + if (recipe instanceof ShapelessRecipe) { + ShapelessRecipe shapelessRecipe = (ShapelessRecipe) recipe; + return shapelessRecipe.assemble(CraftingInput.EMPTY); + } + + if (recipe instanceof ShapedRecipe) { + ShapedRecipe shapedRecipe = (ShapedRecipe) recipe; + return shapedRecipe.assemble(CraftingInput.EMPTY); + } + + if (recipe instanceof CraftingRecipe) { + CraftingRecipe craftingRecipe = (CraftingRecipe) recipe; + return craftingRecipe.assemble(CraftingInput.EMPTY); + } + + if (recipe instanceof CustomRecipe) { + CustomRecipe specialCraftingRecipe = (CustomRecipe) recipe; + return specialCraftingRecipe.assemble(CraftingInput.EMPTY); + } + + return recipe.assemble(null); + } + + 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(); + //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..e2f2c7fab --- /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.world.level.block.entity.BlockEntity; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.level.Level; +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.registries()); + } + + public static CompatRegistryLookup getRegistryLookup(CompatEntity entity) { + return new CompatRegistryLookup(entity.registryAccess()); + } + + public static CompatRegistryLookup getRegistryLookup(Entity entity) { + return new CompatRegistryLookup(entity.registryAccess()); + } + + public static CompatRegistryLookup getRegistryLookup(CompatBlockEntity entity) { + return new CompatRegistryLookup(entity.getLevel().registryAccess()); + } + + public static CompatRegistryLookup getRegistryLookup(BlockEntity entity) { + return new CompatRegistryLookup(entity.getLevel().registryAccess()); + } + + public static CompatRegistryLookup getRegistryLookup(NbtRWArgs args) { + return args.getRegistryLookup(); + } + + public static CompatRegistryLookup getRegistryLookup(Level world) { + return new CompatRegistryLookup(world.registryAccess()); + } +} 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..7af8ae74e --- /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.server.packs.resources.Resource; +import net.minecraft.server.packs.resources.ResourceManager; +import net.minecraft.resources.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.open(); + } + + public static Map findResources(ResourceManager resourceManager, String startingPath, String endingPath) throws IOException { + return resourceManager.listResources(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..11f21fbb4 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/ScreenHandlerUtil.java @@ -0,0 +1,92 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.network.chat.Component; +import net.minecraft.world.MenuProvider; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.Slot; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.core.NonNullList; +import net.minecraft.world.item.ItemStack; +import net.pitan76.mcpitanlib.api.network.PacketByteUtil; +import net.pitan76.mcpitanlib.core.mc261.ExtendedMenuProvider; +import org.jspecify.annotations.Nullable; + +import java.util.ArrayList; +import java.util.List; +import java.util.function.Consumer; + +public class ScreenHandlerUtil { + public static NonNullList getSlots(AbstractContainerMenu screenHandler) { + return screenHandler.slots; + } + + public static Slot getSlot(AbstractContainerMenu screenHandler, int index) { + return screenHandler.getSlot(index); + } + + public static List> getAllScreenHandlerTypes() { + List> screenHandlerTypes = new ArrayList<>(); + for (MenuType screenHandler : BuiltInRegistries.MENU) { + screenHandlerTypes.add(screenHandler); + } + return screenHandlerTypes; + } + + public static void openExtendedMenu(ServerPlayer player, MenuProvider provider, Consumer bufWriter) { + player.openMenu(new ExtendedMenuProvider<>() { + @Override + public @Nullable AbstractContainerMenu createMenu(int containerId, Inventory inventory, Player player) { + return provider.createMenu(containerId, inventory, player); + } + + @Override + public Component getDisplayName() { + return provider.getDisplayName(); + } + + @Override + public Object getScreenOpeningData(ServerPlayer player) { + FriendlyByteBuf buf = PacketByteUtil.create(); + bufWriter.accept(buf); + return buf; + } + }); + } + + public static void openExtendedMenu(ServerPlayer player, ExtendedMenuProvider provider) { + player.openMenu(provider); + } + + public static void openMenu(ServerPlayer player, MenuProvider provider) { + player.openMenu(provider); + } + + public static int getRawId(MenuType type) { + return BuiltInRegistries.MENU.getId(type); + } + + public static MenuType fromIndex(int index) { + return BuiltInRegistries.MENU.byId(index); + } + + public static ItemStack getCursorStack(AbstractContainerMenu screenHandler) { + return screenHandler.getCarried(); + } + + public static net.pitan76.mcpitanlib.midohra.item.ItemStack getCursorStackM(AbstractContainerMenu screenHandler) { + return net.pitan76.mcpitanlib.midohra.item.ItemStack.of(getCursorStack(screenHandler)); + } + + public static void setCursorStack(AbstractContainerMenu screenHandler, ItemStack stack) { + screenHandler.setCarried(stack); + } + + public static void setCursorStackM(AbstractContainerMenu screenHandler, net.pitan76.mcpitanlib.midohra.item.ItemStack stack) { + setCursorStack(screenHandler, stack.toMinecraft()); + } +} 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..542d32c95 --- /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.players.PlayerList; +import net.minecraft.world.level.Level; +import net.pitan76.mcpitanlib.api.entity.Player; + +public class ServerUtil { + public static MinecraftServer getServer(Level world) { + return world.getServer(); + } + + public static String getIP(MinecraftServer server) { + return server.getLocalIp(); + } + + public static int getPort(MinecraftServer server) { + return server.getPort(); + } + + public static String getMotd(MinecraftServer server) { + return server.getMotd(); + } + + public static String getServerModName(MinecraftServer server) { + return server.getServerModName(); + } + + public static int getMaxPlayerCount(MinecraftServer server) { + return server.getMaxPlayers(); + } + + public static int getCurrentPlayerCount(MinecraftServer server) { + return server.getPlayerCount(); + } + + public static boolean isOnlineMode(MinecraftServer server) { + return server.usesAuthentication(); + } + + public static boolean isServerRunning(MinecraftServer server) { + return server.isRunning(); + } + + public static boolean isServerDedicated(MinecraftServer server) { + return server.isDedicatedServer(); + } + + public static boolean isSingleplayer(MinecraftServer server) { + return server.isSingleplayer(); + } + + public static PlayerList getPlayerManager(MinecraftServer server) { + return server.getPlayerList(); + } + + 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..5bc9b8139 --- /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.world.SimpleContainer; +import net.minecraft.world.item.ItemStack; +import net.minecraft.core.NonNullList; + +public class SimpleInventoryUtil { + public static NonNullList getHeldStacks(SimpleContainer inventory) { + return inventory.getItems(); + } + + public static SimpleContainer create(int size) { + return InventoryUtil.createSimpleInventory(size); + } + + public static ItemStack getStack(SimpleContainer inventory, int slot) { + return inventory.getItem(slot); + } + + public static void setStack(SimpleContainer inventory, int slot, ItemStack stack) { + inventory.setItem(slot, stack); + } + + public static void clear(SimpleContainer inventory) { + inventory.clearContent(); + } + + public static int size(SimpleContainer inventory) { + return inventory.getContainerSize(); + } + + public static boolean isEmpty(SimpleContainer 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..fd795b119 --- /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.world.Container; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.inventory.Slot; +import net.pitan76.mcpitanlib.api.entity.Player; + +public class SlotUtil { + public static void setStack(Slot slot, ItemStack stack) { + slot.setByPlayer(stack); + } + + public static ItemStack getStack(Slot slot) { + return slot.getItem(); + } + + public static void takeStack(Slot slot, int amount) { + slot.remove(amount); + } + + public static boolean hasStack(Slot slot) { + return slot.hasItem(); + } + + public static void markDirty(Slot slot) { + slot.setChanged(); + } + + public static boolean canInsert(Slot slot, ItemStack stack) { + return slot.mayPlace(stack); + } + + public static boolean canTakeItems(Slot slot) { + return slot.mayPickup(null); + } + + public static void onTakeItem(Slot slot, Player player, ItemStack stack) { + slot.onTake(player.getEntity(), stack); + } + + public static Container getInventory(Slot slot) { + return slot.container; + } +} 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..051afa730 --- /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.core.registries.BuiltInRegistries; +import net.minecraft.sounds.SoundEvent; +import net.minecraft.resources.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.location(); + } + + public static SoundEvent getSoundEvent(Identifier id) { + return SoundEvent.createVariableRangeEvent(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 BuiltInRegistries.SOUND_EVENT.stream().collect(Collectors.toList()); + } + + public static List getAllSoundEventIds() { + return new ArrayList<>(BuiltInRegistries.SOUND_EVENT.keySet()); + } +} 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..2c9f276b3 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/StackActionResult.java @@ -0,0 +1,107 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.InteractionResult; +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; + + public StackActionResult(InteractionResult 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; + } + + @Override + public InteractionResult toActionResult() { + return compatActionResult.toActionResult(); + } + + @Override + public EventResult toEventResult() { + return compatActionResult.toEventResult(); + } + + @Deprecated + @Override + public Optional getNewHandStack() { + if (hasNewStack()) + return compatActionResult.getNewHandStack(); + + return Optional.empty(); + } + + public boolean hasNewStack() { + return compatActionResult.getNewHandStack().isPresent(); + } + + public boolean hasStack() { + return getStack() != null; + } + + public CompatActionResult asCompatActionResult() { + return compatActionResult; + } + + public static StackActionResult create(CompatActionResult compatActionResult, ItemStack stack) { + if (compatActionResult.getNewHandStack().isPresent()) + return new StackActionResult(compatActionResult, compatActionResult.getNewHandStack().get()); + + return new StackActionResult(compatActionResult, stack); + } + + public static StackActionResult create(CompatActionResult compatActionResult) { + return new StackActionResult(compatActionResult, null); + } + + public static StackActionResult create(InteractionResult actionResult, EventResult eventResult, ItemStack stack) { + return new StackActionResult(actionResult, eventResult, stack); + } + + public static StackActionResult create(InteractionResult actionResult, ItemStack stack) { + return new StackActionResult(actionResult, null, stack); + } + + public static StackActionResult success(ItemStack stack) { + CompatActionResult compatActionResult = CompatActionResult.create(InteractionResult.SUCCESS.heldItemTransformedTo(stack)); + return create(compatActionResult, stack); + } + + public static StackActionResult successServer(ItemStack stack) { + CompatActionResult compatActionResult = CompatActionResult.create(InteractionResult.SUCCESS_SERVER.heldItemTransformedTo(stack)); + return create(compatActionResult, stack); + } + + public static StackActionResult consume(ItemStack stack) { + CompatActionResult compatActionResult = CompatActionResult.create(InteractionResult.CONSUME.heldItemTransformedTo(stack)); + return create(compatActionResult, stack); + } + + 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..dd80d1c9b --- /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.world.level.block.state.StateHolder; +import net.minecraft.world.level.block.state.StateDefinition; + +public class StateManagerUtil { + public static > S getDefaultState(StateDefinition manager) { + return manager.any(); + } + + public > ImmutableList getStates(StateDefinition manager) { + return manager.getPossibleStates(); + } +} 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..f6c728337 --- /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.world.effect.MobEffect; +import net.minecraft.resources.ResourceKey; +import net.minecraft.core.registries.Registries; +import net.minecraft.resources.Identifier; +import net.pitan76.mcpitanlib.api.entity.effect.CompatStatusEffect; + +public class StatusEffectUtil { + public static CompatStatusEffect getStatusEffect(Identifier identifier) { + ResourceKey registryKey = ResourceKey.create(Registries.MOB_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..39e591ae2 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/StyleUtil.java @@ -0,0 +1,61 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.network.chat.ClickEvent; +import net.minecraft.network.chat.HoverEvent; +import net.minecraft.network.chat.Style; +import net.minecraft.network.chat.FontDescription; +import net.minecraft.ChatFormatting; + +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.withUnderlined(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(new FontDescription.Resource(font.toMinecraft())); + } + + public static Style withFormatting(Style style, ChatFormatting formatting) { + return style.applyFormat(formatting); + } + + public static Style withExclusiveFormatting(Style style, ChatFormatting formatting) { + return style.applyLegacyFormat(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..12ee2e0b3 --- /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.network.chat.MutableComponent; +import net.minecraft.network.chat.Style; +import net.minecraft.network.chat.Component; +import net.pitan76.mcpitanlib.api.text.TextConverter; + +public class TextUtil { + public static MutableComponent literal(String string) { + return Component.literal(string); + } + + public static MutableComponent translatable(String key) { + return Component.translatable(key); + } + + public static MutableComponent translatable(String key, Object... args) { + return Component.translatable(key, args); + } + + public static MutableComponent empty() { + return literal(""); + } + + public static MutableComponent keybind(String string) { + return Component.keybind(string); + } + + public static String txt2str(Component text) { + return text.getString(); + } + + public static MutableComponent setStyle(MutableComponent text, Style style) { + return text.setStyle(style); + } + + public static Style getStyle(MutableComponent text) { + return text.getStyle(); + } + + public static MutableComponent withColor(MutableComponent text, int color) { + return setStyle(text, StyleUtil.withColor(text.getStyle(), color)); + } + + public static MutableComponent withBold(MutableComponent text, boolean bold) { + return setStyle(text, StyleUtil.withBold(text.getStyle(), bold)); + } + + public static MutableComponent append(MutableComponent text, Component sibling) { + return text.append(sibling); + } + + public static MutableComponent append(MutableComponent text, String string) { + return text.append(string); + } + + public static MutableComponent of(String string) { + return literal(string); + } + + public static MutableComponent convert(String text) { + return TextConverter.convert(text, false); + } + + public static MutableComponent convertWithTranslatable(String text) { + return TextConverter.convert(text, true); + } + + public static boolean contains(Component text, Component 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..a855dee29 --- /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.level.ServerLevel; +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(ServerLevel 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..3ec18e2b3 --- /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.world.item.crafting.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..92e04fa64 --- /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.world.phys.AABB; +import net.minecraft.world.phys.shapes.VoxelShape; +import net.minecraft.world.phys.shapes.Shapes; + +public class VoxelShapeUtil { + public static VoxelShape union(VoxelShape shape, VoxelShape... shapes) { + return Shapes.or(shape, shapes); + } + + public static VoxelShape cuboid(double x1, double y1, double z1, double x2, double y2, double z2) { + return Shapes.box(x1, y1, z1, x2, y2, z2); + } + + public static VoxelShape cuboid(double x, double y, double z, double size) { + return Shapes.box(x, y, z, x + size, y + size, z + size); + } + + public static VoxelShape cuboid(double size) { + return Shapes.box(0, 0, 0, size, size, size); + } + + public static VoxelShape centeredCuboid(double x, double y, double z, double size) { + return Shapes.box(x - size / 2, y - size / 2, z - size / 2, x + size / 2, y + size / 2, z + size / 2); + } + + public static VoxelShape empty() { + return Shapes.empty(); + } + + public static VoxelShape fullCube() { + return Shapes.block(); + } + + public static VoxelShape blockCuboid(double minX, double minY, double minZ, double maxX, double maxY, double maxZ) { + return Shapes.box(minX / 16.0, minY / 16.0, minZ / 16.0, maxX / 16.0, maxY / 16.0, maxZ / 16.0); + } + + public static AABB getBoundingBox(VoxelShape shape) { + return shape.bounds(); + } +} 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..7e6eac9b2 --- /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.level.Level; + +public class WorldRandomUtil { + public static int nextInt(Level world) { + return world.getRandom().nextInt(); + } + + public static int nextInt(Level world, int bound) { + return world.getRandom().nextInt(bound); + } + + public static long nextLong(Level world) { + return world.getRandom().nextLong(); + } + + public static double nextDouble(Level world) { + return world.getRandom().nextDouble(); + } + + public static double nextGaussian(Level world) { + return world.getRandom().nextGaussian(); + } + + public static float nextFloat(Level world) { + return world.getRandom().nextFloat(); + } + + public static int nextBetween(Level world, int min, int max) { + return world.getRandom().nextIntBetweenInclusive(min, max); + } + + public static int nextBetweenExclusive(Level world, int min, int max) { + return world.getRandom().nextInt(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..0b0062a28 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/WorldUtil.java @@ -0,0 +1,485 @@ +package net.pitan76.mcpitanlib.api.util; + +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.ExperienceOrb; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.entity.monster.Enemy; +import net.minecraft.world.level.material.Fluid; +import net.minecraft.world.level.material.FluidState; +import net.minecraft.world.item.ItemStack; +import net.minecraft.core.particles.ParticleOptions; +import net.minecraft.world.entity.EntitySelector; +import net.minecraft.resources.ResourceKey; +import net.minecraft.core.registries.Registries; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.sounds.SoundSource; +import net.minecraft.sounds.SoundEvent; +import net.minecraft.resources.Identifier; +import net.minecraft.core.BlockPos; +import net.minecraft.world.phys.AABB; +import net.minecraft.world.level.ChunkPos; +import net.minecraft.world.phys.Vec3; +import net.minecraft.world.level.Level; +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(Level world) { + return world.dimensionType().hasSkyLight(); + } + + public static boolean isThundering(Level world) { + return world.isThundering(); + } + + public static boolean isRaining(Level world) { + return world.isRaining(); + } + + public static boolean isNight(Level world) { + return world.isDarkOutside(); + } + + public static boolean isDay(Level world) { + return world.isBrightOutside(); + } + + public static boolean isSkyVisible(Level world, BlockPos pos) { + return world.canSeeSky(pos); + } + + public static boolean isClient(Level world) { + return world.isClientSide(); + } + + public static void scheduleBlockTick(Level world, BlockPos pos, Block block, int delay) { + world.scheduleTick(pos, block, delay); + } + + public static void scheduleFluidTick(Level world, BlockPos pos, Fluid fluid, int delay) { + world.scheduleTick(pos, fluid, delay); + } + + public static boolean isServer(Level world) { + return !isClient(world); + } + + public static void spawnStack(Level world, BlockPos pos, ItemStack stack) { + spawnEntity(world, new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(), stack)); + } + + public static void spawnExperienceOrb(Level world, Vec3 pos, int amount) { + if (world instanceof ServerLevel) + ExperienceOrb.award((ServerLevel) world, pos, amount); + } + + public static void spawnExperienceOrb(Level world, BlockPos pos, int amount) { + spawnExperienceOrb(world, pos.getCenter(), amount); + } + + public static void spawnEntity(Level world, Entity entity) { + world.addFreshEntity(entity); + } + + public static void playSound(Level world, @Nullable Player player, BlockPos pos, SoundEvent sound, SoundSource category, float volume, float pitch) { + net.minecraft.world.entity.player.Player entity = player == null ? null : player.getEntity(); + world.playSound(entity, pos, sound, category, volume, pitch); + } + + public static void playSound(Level 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(Level 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(Level world, double x, double y, double z, CompatSoundEvent sound, CompatSoundCategory category, float volume, float pitch, boolean useDistance) { + world.playLocalSound(x, y, z, sound.get(), category.get(), volume, pitch, useDistance); + } + + public static void sendEntityStatus(Level world, Entity entity, byte status) { + world.broadcastEntityEvent(entity, status); + } + + public static BlockPos getSpawnPos(Level world) { + return world.getRespawnData().pos(); + } + + public static Optional getServer(Level world) { + if (isClient(world)) return Optional.empty(); + return Optional.ofNullable(world.getServer()); + } + + public static ServerLevel getWorld(Level world, Identifier worldId) { + Optional server = getServer(world); + return server.map(minecraftServer -> getWorld(minecraftServer, worldId)).orElse(null); + + } + + public static Optional getWorld(Level world, CompatIdentifier worldId) { + return Optional.ofNullable(getWorld(world, worldId.toMinecraft())); + } + + public static ServerLevel getOverworld(MinecraftServer server) { + return server.getLevel(Level.OVERWORLD); + } + + public static ServerLevel getNether(MinecraftServer server) { + return server.getLevel(Level.NETHER); + } + + public static ServerLevel getEnd(MinecraftServer server) { + return server.getLevel(Level.END); + } + + public static ServerLevel getWorld(MinecraftServer server, Identifier worldId) { + return server.getLevel(ResourceKey.create(Registries.DIMENSION, worldId)); + } + + public static ServerLevel getWorld(MinecraftServer server, CompatIdentifier worldId) { + return getWorld(server, worldId.toMinecraft()); + } + + public static Identifier getWorldId(Level world) { + return world.dimension().identifier(); + } + + public static CompatIdentifier getCompatWorldId(Level world) { + return CompatIdentifier.fromMinecraft(getWorldId(world)); + } + + public static boolean equals(Level world, Level world2) { + return Objects.equals(getWorldId(world), getWorldId(world2)); + } + + @Deprecated + public static void addTicket(ServerLevel world, net.minecraft.server.level.TicketType type, ChunkPos pos, int radius, T argument) { + world.getChunkSource().addTicketWithRadius(type, pos, radius); + } + + @Deprecated + public static void removeTicket(ServerLevel world, net.minecraft.server.level.TicketType type, ChunkPos pos, int radius, T argument) { + world.getChunkSource().removeTicketWithRadius(type, pos, radius); + } + + public static void addTicket(ServerLevel world, ChunkTicketType type, ChunkPos pos, int radius, T argument) { + addTicket(world, type.getRaw(), pos, radius, argument); + } + + public static void removeTicket(ServerLevel world, ChunkTicketType type, ChunkPos pos, int radius, T argument) { + removeTicket(world, type.getRaw(), pos, radius, argument); + } + + public static void addTicket(ServerLevel world, ChunkTicketType type, ChunkPos pos, int radius) { + world.getChunkSource().addTicketWithRadius(type.getRaw(), pos, radius); + } + + public static void removeTicket(ServerLevel world, ChunkTicketType type, ChunkPos pos, int radius) { + world.getChunkSource().removeTicketWithRadius(type.getRaw(), pos, radius); + } + + public static boolean isReceivingRedstonePower(Level world, BlockPos pos) { + return world.hasNeighborSignal(pos); + } + + public static int getBottomY(Level world) { + return world.getMinY(); + } + + public static int getTopY(Level world) { + return world.getMaxY(); + } + + public static int getDimensionHeight(Level world) { + return world.dimensionType().height(); + } + + public static BlockEntity getBlockEntity(Level world, BlockPos pos) { + return world.getBlockEntity(pos); + } + + public static boolean hasBlockEntity(Level world, BlockPos pos) { + return getBlockEntity(world, pos) != null; + } + + public static BlockState getBlockState(Level world, BlockPos pos) { + return world.getBlockState(pos); + } + + public static FluidState getFluidState(Level world, BlockPos pos) { + return world.getFluidState(pos); + } + + public static boolean hasFluidState(Level world, BlockPos pos) { + return ! getFluidState(world, pos).isEmpty(); + } + + public static boolean isAir(Level world, BlockPos pos) { + return getBlockState(world, pos).isAir(); + } + + public static boolean setBlockState(Level world, BlockPos pos, BlockState state, int flags) { + return world.setBlock(pos, state, flags); + } + + public static boolean setBlockState(Level world, BlockPos pos, BlockState state) { + return setBlockState(world, pos, state, 3); + } + + public static boolean setBlockState(Level world, BlockPos pos, Block block, int flags) { + return setBlockState(world, pos, block.defaultBlockState(), flags); + } + + public static boolean setBlockState(Level world, BlockPos pos, Block block) { + return setBlockState(world, pos, block, 3); + } + + public static boolean breakBlock(Level world, BlockPos pos, boolean drop) { + return world.destroyBlock(pos, drop); + } + + public static boolean breakBlock(Level world, BlockPos pos) { + return breakBlock(world, pos, true); + } + + public static boolean breakBlock(Level world, BlockPos pos, boolean drop, @Nullable Player player) { + if (player == null) + return world.destroyBlock(pos, drop, null); + + return world.destroyBlock(pos, drop, player.getPlayerEntity()); + } + + public static boolean breakBlock(Level world, BlockPos pos, @Nullable Player player) { + return breakBlock(world, pos, true, player); + } + + public static void removeBlockEntity(Level world, BlockPos pos) { + world.removeBlockEntity(pos); + } + + public static boolean removeBlock(Level world, BlockPos pos, boolean move) { + return world.removeBlock(pos, move); + } + + public static void addParticle(Level world, ParticleOptions 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(Level world, BlockPos pos) { + return world.isUnobstructed(Blocks.STONE.defaultBlockState(), pos, CollisionContext.empty()); + } + + public static void updateComparators(Level world, BlockPos pos, Block block) { + world.updateNeighbourForOutputSignal(pos, block); + } + + public static List getPlayers(Level world) { + List players = new ArrayList<>(); + for (net.minecraft.world.entity.player.Player player : world.players()) { + players.add(new Player(player)); + } + + return players; + } + + public static Player getPlayer(Level world, UUID uuid) { + return new Player(world.getPlayerByUUID(uuid)); + } + + public static CompatRandom getRandom(Level world) { + return new CompatRandom(world.getRandom()); + } + + public static long getTime(Level world) { + return world.getGameTime(); + } + + public static List getEntitiesByType(Level world, EntityType filter, AABB box, Predicate predicate) { + return world.getEntities(filter, box, predicate); + } + + public static List getEntitiesByClass(Level world, Class entityClass, AABB box, Predicate predicate) { + return world.getEntitiesOfClass(entityClass, box, predicate); + } + + public static void spawnParticles(Level world, ParticleOptions parameters, double x, double y, double z, int count, double velocityX, double velocityY, double velocityZ, double speed) { + if (!isServer(world)) return; + + ((ServerLevel) world).sendParticles(parameters, x, y, z, count, velocityX, velocityY, velocityZ, speed); + } + + public static void updateListeners(Level world, BlockPos pos, BlockState oldState, BlockState newState, int flags) { + world.sendBlockUpdated(pos, oldState, newState, flags); + } + + public static net.pitan76.mcpitanlib.midohra.block.BlockState getMidohraBlockState(Level world, BlockPos pos) { + return net.pitan76.mcpitanlib.midohra.block.BlockState.of(getBlockState(world, pos)); + } + + public static boolean setBlockState(Level world, BlockPos pos, net.pitan76.mcpitanlib.midohra.block.BlockState state, int flags) { + return setBlockState(world, pos, state.toMinecraft(), flags); + } + + public static boolean setBlockState(Level world, BlockPos pos, net.pitan76.mcpitanlib.midohra.block.BlockState state) { + return setBlockState(world, pos, state, 3); + } + + public static boolean setBlockState(Level 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(Level 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(Level world, net.pitan76.mcpitanlib.midohra.util.math.BlockPos pos, boolean drop) { + return breakBlock(world, pos.toMinecraft(), drop); + } + + public static boolean breakBlock(Level world, net.pitan76.mcpitanlib.midohra.util.math.BlockPos pos) { + return breakBlock(world, pos, true); + } + + public static boolean breakBlock(Level 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(Level world, net.pitan76.mcpitanlib.midohra.util.math.BlockPos pos, @Nullable Player player) { + return breakBlock(world, pos, true, player); + } + + public static void removeBlockEntity(Level world, net.pitan76.mcpitanlib.midohra.util.math.BlockPos pos) { + removeBlockEntity(world, pos.toMinecraft()); + } + + public static boolean removeBlock(Level 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(Level world, BlockPos pos, ItemStack stack) { + Block.popResource(world, pos, stack); + } + + public static float getSkyAngle(Level world, float tickDelta) { + long timeOfDay = world.getDefaultClockTime(); + float f = ((float)(timeOfDay % 24000L) + tickDelta) / 24000.0F - 0.25F; + if (f < 0.0F) { + f += 1.0F; + } + if (f > 1.0F) { + f -= 1.0F; + } + return f; + } + + public static Block getBlock(Level world, BlockPos pos) { + return getBlockState(world, pos).getBlock(); + } + + public static BlockWrapper getBlockWrapper(Level world, BlockPos pos) { + return BlockWrapper.of(getBlock(world, pos)); + } + + public static List getEntitiesByType(Level world, EntityType filter, AABB box) { + return getEntitiesByType(world, filter, box, EntitySelector.ENTITY_STILL_ALIVE); + } + + public static List getEntitiesByType(Level world, EntityTypeWrapper filter, AABB box, Predicate predicate) { + return getEntitiesByType(world, (EntityType) filter.get(), box, predicate); + } + + public static List getEntitiesByType(Level world, EntityTypeWrapper filter, AABB box) { + return getEntitiesByType(world, filter.get(), box); + } + + public static CompatIdentifier getOverworldId() { + return CompatIdentifier.fromMinecraft(Level.OVERWORLD.identifier()); + } + + public static CompatIdentifier getNetherId() { + return CompatIdentifier.fromMinecraft(Level.NETHER.identifier()); + } + + public static CompatIdentifier getEndId() { + return CompatIdentifier.fromMinecraft(Level.END.identifier()); + } + + public static long getTimeOfDay(Level world) { + return world.getDefaultClockTime(); + } + + public static List getEntitiesByClass(Level world, Class entityClass, net.pitan76.mcpitanlib.midohra.util.math.Box box) { + return getEntitiesByClass(world, entityClass, box, EntitySelector.ENTITY_STILL_ALIVE); + } + + public static List getEntitiesByClass(Level world, Class entityClass, AABB box) { + return getEntitiesByClass(world, entityClass, box, EntitySelector.ENTITY_STILL_ALIVE); + } + + public static List getEntitiesByClass(Level world, Class entityClass, net.pitan76.mcpitanlib.midohra.util.math.Box box, Predicate predicate) { + return getEntitiesByClass(world, entityClass, box.toMinecraft(), predicate); + } + + public static List getEntitiesByClass(Level world, Class entityClass, Vector3d center, double radius, Predicate predicate) { + AABB 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(Level world, Class entityClass, Vector3d center, double radius) { + return getEntitiesByClass(world, entityClass, center, radius, EntitySelector.ENTITY_STILL_ALIVE); + } + + public static List getMonsters(Level world, AABB box) { + return world.getEntitiesOfClass(LivingEntity.class, box, entity -> entity instanceof Enemy); + } + + public static List getMonsters(Level world, net.pitan76.mcpitanlib.midohra.util.math.Box box) { + return getMonsters(world, box.toMinecraft()); + } + + public static List getMonsters(Level world, Vector3d center, double radius) { + AABB 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(Level world, EntityTypeWrapper filter, net.pitan76.mcpitanlib.midohra.util.math.Box box) { + return getEntitiesByType(world, filter, box.toMinecraft()); + } + + public static List getEntitiesByType(Level 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(Level world, CompatParticleType parameters, double x, double y, double z, double velocityX, double velocityY, double velocityZ) { + if (parameters.getRaw() instanceof ParticleOptions) + addParticle(world, (ParticleOptions) 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..52cbeeba7 --- /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.world.phys.BlockHitResult; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.phys.Vec3; + +public class BlockHitResultUtil { + + public static BlockHitResult create(Vec3 pos, Direction direction, BlockPos blockPos, boolean insideBlock) { + return new BlockHitResult(pos, direction, blockPos, insideBlock); + } + + public static BlockHitResult create(Vec3 pos, Direction direction, BlockPos blockPos) { + return new BlockHitResult(pos, direction, blockPos, false); + } + + public static Vec3 getPos(BlockHitResult blockHitResult) { + return blockHitResult.getLocation(); + } + + public static Direction getSide(BlockHitResult blockHitResult) { + return blockHitResult.getDirection(); + } + + public static BlockPos getBlockPos(BlockHitResult blockHitResult) { + return blockHitResult.getBlockPos(); + } + + public static boolean isInsideBlock(BlockHitResult blockHitResult) { + return blockHitResult.isInside(); + } +} 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..05d7d21d3 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/block/BlockUtil.java @@ -0,0 +1,239 @@ +package net.pitan76.mcpitanlib.api.util.block; + +import net.minecraft.world.level.block.Block; +import net.minecraft.world.item.Item; +import net.minecraft.world.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.getDescriptionId(); + } + + public static Block fromItem(Item item) { + return BlockUtilV2.fromItem(item); + } + + public static Block fromItem(ItemStack stack) { + return BlockUtilV2.fromItem(stack); + } + + public static float getHardness(Block block) { + return block.defaultDestroyTime(); + } +} 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..c2a1f7fca --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/block/entity/FurnaceUtil.java @@ -0,0 +1,44 @@ +package net.pitan76.mcpitanlib.api.util.block.entity; + +import net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.AbstractCookingRecipe; +import net.minecraft.world.item.crafting.SingleRecipeInput; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +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.BURN_TIME_STANDARD; + } + + public static boolean canUseAsFuel(net.pitan76.mcpitanlib.midohra.item.ItemStack stack, Level world) { + return canUseAsFuel(stack.toMinecraft(), world); + } + + public static boolean canUseAsFuel(ItemStack stack, Level world) { + return world.fuelValues().isFuel(stack); + } + + public static void tick(Level world, BlockPos pos, AbstractFurnaceBlockEntity blockEntity) { + AbstractFurnaceBlockEntity.serverTick((ServerLevel) world, pos, WorldUtil.getBlockState(world, pos), blockEntity); + } + + public static int getCookTime(Level world, AbstractFurnaceBlockEntity furnace, MatchGetter matchGetter) { + return getCookTime(world, furnace.getItem(0), matchGetter); + } + + public static int getCookTime(Level world, ItemStack stack, MatchGetter matchGetter) { + CompatRecipeInput input = (CompatRecipeInput) SingleStackRecipeInputUtil.create(stack); + + matchGetter.getFirstMatch(input, world); + + return matchGetter.getFirstMatch(input, world).map( + (recipe) -> (recipe.getRecipe()).cookingTime()).orElse(200); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/block/properties/CompatBlockHalf.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/block/properties/CompatBlockHalf.java new file mode 100644 index 000000000..f8a764691 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/block/properties/CompatBlockHalf.java @@ -0,0 +1,45 @@ +package net.pitan76.mcpitanlib.api.util.block.properties; + +import net.minecraft.world.level.block.state.properties.Half; +import net.pitan76.mcpitanlib.api.util.CompatStringIdentifiable; + +public class CompatBlockHalf implements CompatStringIdentifiable { + private final Half blockHalf; + + public static final CompatBlockHalf TOP = of(Half.TOP); + public static final CompatBlockHalf BOTTOM = of(Half.BOTTOM); + + public CompatBlockHalf(Half blockHalf) { + this.blockHalf = blockHalf; + } + + public static CompatBlockHalf of(Half blockHalf) { + return new CompatBlockHalf(blockHalf); + } + + public Half getBlockHalf() { + return blockHalf; + } + + public String getName() { + return blockHalf.name(); + } + + @Override + public String asString_compat() { + return getName(); + } + + @Override + public int hashCode() { + return blockHalf.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + CompatBlockHalf other = (CompatBlockHalf) obj; + return blockHalf == other.blockHalf; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/block/properties/CompatStairShape.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/block/properties/CompatStairShape.java new file mode 100644 index 000000000..3a25a73f6 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/block/properties/CompatStairShape.java @@ -0,0 +1,48 @@ +package net.pitan76.mcpitanlib.api.util.block.properties; + +import net.minecraft.world.level.block.state.properties.StairsShape; +import net.pitan76.mcpitanlib.api.util.CompatStringIdentifiable; + +public class CompatStairShape implements CompatStringIdentifiable { + private final StairsShape stairShape; + + public static final CompatStairShape STRAIGHT = of(StairsShape.STRAIGHT); + public static final CompatStairShape INNER_LEFT = of(StairsShape.INNER_LEFT); + public static final CompatStairShape INNER_RIGHT = of(StairsShape.INNER_RIGHT); + public static final CompatStairShape OUTER_LEFT = of(StairsShape.OUTER_LEFT); + public static final CompatStairShape OUTER_RIGHT = of(StairsShape.OUTER_RIGHT); + + public CompatStairShape(StairsShape stairShape) { + this.stairShape = stairShape; + } + + public static CompatStairShape of(StairsShape stairShape) { + return new CompatStairShape(stairShape); + } + + public StairsShape getStairShape() { + return stairShape; + } + + public String getName() { + return stairShape.name(); + } + + @Override + public String asString_compat() { + return getName(); + } + + @Override + public int hashCode() { + return stairShape.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + CompatStairShape other = (CompatStairShape) obj; + return stairShape == other.stairShape; + } +} 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..4ae0a734a --- /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.renderer.blockentity.BlockEntityRendererProvider; +import net.pitan76.mcpitanlib.api.client.registry.CompatRegistryClient; + +public class BlockEntityRendererUtil { + public static BlockEntityRendererProvider.Context convert(CompatRegistryClient.BlockEntityRendererFactory.Context ctx) { + return new BlockEntityRendererProvider.Context(ctx.getRenderDispatcher(), ctx.getRenderManager(), ctx.getItemModelManager(), ctx.getEntityRenderDispatcher(), ctx.getLayerRenderDispatcher(), ctx.getTextRenderer(), ctx.getSpriteHolder(), ctx.getPlayerSkinRenderCache()); + } + + public static CompatRegistryClient.BlockEntityRendererFactory.Context convert(BlockEntityRendererProvider.Context ctx) { + return new CompatRegistryClient.BlockEntityRendererFactory.Context(ctx.blockEntityRenderDispatcher(), ctx.blockModelResolver(), ctx.itemModelResolver(), ctx.entityRenderer(), ctx.entityModelSet(), ctx.font(), ctx.sprites(), ctx.playerSkinRenderCache()); + } +} 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..0e082de2f --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/client/ClientUtil.java @@ -0,0 +1,117 @@ +package net.pitan76.mcpitanlib.api.util.client; + +import com.mojang.authlib.GameProfile; +import net.minecraft.client.Minecraft; +import net.minecraft.client.MouseHandler; +import net.minecraft.client.gui.Font; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.player.LocalPlayer; +import net.minecraft.client.renderer.GameRenderer; +import net.minecraft.client.renderer.LevelRenderer; +import net.minecraft.client.renderer.item.ItemModelResolver; +import net.minecraft.client.renderer.texture.TextureManager; +import com.mojang.blaze3d.platform.Window; +import net.minecraft.client.multiplayer.ClientLevel; +import net.minecraft.server.packs.resources.ResourceManager; +import net.minecraft.world.phys.HitResult; +import net.minecraft.util.profiling.ProfilerFiller; +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().screen; + } + + public static Player getPlayer() { + return new Player(getClientPlayer()); + } + + public static LocalPlayer getClientPlayer() { + return getClient().player; + } + + public static Minecraft getClient() { + return Minecraft.getInstance(); + } + + public static Font getTextRenderer() { + return getClient().font; + } + + public static ItemModelResolver getItemRenderer() { + return getClient().getItemModelResolver(); + } + + public static ResourceManager getResourceManager() { + return getClient().getResourceManager(); + } + + public static TextureManager getTextureManager() { + return getClient().getTextureManager(); + } + + public static ClientLevel getWorld() { + return getClient().level; + } + + public static GameRenderer getGameRenderer() { + return getClient().gameRenderer; + } + + public static Optional getTime() { + if (getClient().level == null) return Optional.empty(); + return Optional.of(getClient().level.getGameTime()); + } + + public static long getRenderTime() { + return getClient().getFrameTimeNs(); + } + + public static HitResult getTarget() { + return getClient().hitResult; + } + + public static LevelRenderer getWorldRenderer() { + return getClient().levelRenderer; + } + + public static File getRunDirectory() { + return getClient().gameDirectory; + } + + public static ProfilerFiller getProfiler() { + return null; + } + + public static GameProfile getGameProfile() { + return getClient().getGameProfile(); + } + + public static Window getWindow() { + return getClient().getWindow(); + } + + public static MouseHandler getMouse() { + return getClient().mouseHandler; + } + + public static boolean isInSingleplayer() { + return getClient().isLocalServer(); + } + + 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..e45c07d23 --- /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.resources.language.I18n; +import net.minecraft.client.resources.language.LanguageManager; +import net.pitan76.mcpitanlib.midohra.resource.ResourceManager; + +public class LanguageUtil { + public static boolean hasTranslation(String key) { + return I18n.exists(key); + } + + public static String translate(String key) { + return I18n.get(key); + } + + public static String translate(String key, Object... args) { + return I18n.get(key, args); + } + + public static String translateWithFallback(String key, String fallback) { + return I18n.exists(key) ? I18n.get(key) : fallback; + } + + public static String translateWithFallback(String key, String fallback, Object... args) { + return I18n.exists(key) ? I18n.get(key, args) : fallback; + } + + public static LanguageManager getLanguageManager() { + return ClientUtil.getClient().getLanguageManager(); + } + + public static String getLanguage() { + return getLanguageManager().getSelected(); + } + + public static void setLanguage(String language) { + getLanguageManager().setSelected(language); + } + + public static void reload(net.minecraft.server.packs.resources.ResourceManager resourceManager) { + getLanguageManager().onResourceManagerReload(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..1d14db8b6 --- /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 com.mojang.blaze3d.vertex.PoseStack; +import net.pitan76.mcpitanlib.api.util.MathUtil; + +import static net.pitan76.mcpitanlib.api.util.MathUtil.getRotationDegrees; + +public class MatrixStackUtil { + public static void multiply(PoseStack matrixStack, MathUtil.RotationAxisType type, float deg) { + matrixStack.mulPose(getRotationDegrees(type, deg)); + } + + public static void push(PoseStack matrices) { + matrices.pushPose(); + } + + public static void pop(PoseStack matrices) { + matrices.popPose(); + } + + public static void translate(PoseStack matrices, double x, double y, double z) { + matrices.translate(x, y, z); + } + + public static void scale(PoseStack matrices, float x, float y, float z) { + matrices.scale(x, y, z); + } + + public static PoseStack.Pose peek(PoseStack matrices) { + return matrices.last(); + } +} 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..8bfe79623 --- /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.MouseHandler; + +public class MouseUtil { + + public static MouseHandler getMouse() { + return ClientUtil.getMouse(); + } + + public static double getMouseX() { + return getMouse().xpos(); + } + + public static double getMouseY() { + return getMouse().ypos(); + } + + public static boolean isCursorLocked() { + return getMouse().isMouseGrabbed(); + } + + public static void lockCursor() { + getMouse().grabMouse(); + } + + public static void unlockCursor() { + getMouse().releaseMouse(); + } + + public static void tick() { + getMouse().handleAccumulatedMovement(); + } + + public static boolean wasLeftButtonClicked() { + return getMouse().isLeftPressed(); + } + + public static boolean wasRightButtonClicked() { + return getMouse().isRightPressed(); + } + + public static boolean wasMiddleButtonClicked() { + return getMouse().isMiddlePressed(); + } +} 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..7f4609c54 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/client/RenderUtil.java @@ -0,0 +1,32 @@ +package net.pitan76.mcpitanlib.api.util.client; + +import com.mojang.blaze3d.systems.RenderSystem; +import net.minecraft.resources.Identifier; + +public class RenderUtil { + public static void setShaderToPositionTexProgram() { + // -1.21.4 + } + + 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) { + // -1.21.4 + } + + public static void enableDepthTest() { + // -1.21.4 + } + + 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..cf1a96038 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/client/ScreenUtil.java @@ -0,0 +1,294 @@ +package net.pitan76.mcpitanlib.api.util.client; + +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Font; +import net.minecraft.client.renderer.RenderPipelines; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.gui.components.Button; +import net.minecraft.network.chat.CommonComponents; +import net.minecraft.util.FormattedCharSequence; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.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 net.pitan76.mcpitanlib.midohra.item.ItemStack; +import org.jetbrains.annotations.Nullable; + +import java.util.List; +import java.util.stream.Collectors; + +@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 Button createButtonWidget(int x, int y, int width, int height, Component message, Button.OnPress onPress) { + return createButtonWidget(x, y, width, height, message, onPress, null); + } + + public static Button createButtonWidget(int x, int y, int width, int height, Component message, Button.OnPress onPress, @Nullable Button.CreateNarration tooltipSupplier) { + Button.Builder builder = Button.builder(message, onPress).bounds(x, y, width , height); + if (tooltipSupplier != null) + builder.createNarration(tooltipSupplier); + + return builder.build(); + } + + public static CompatibleTexturedButtonWidget createTexturedButtonWidget(int x, int y, int width, int height, int u, int v, Identifier texture, Button.OnPress 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, Button.OnPress 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, Button.OnPress 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, Button.OnPress pressAction, Component 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, Button.OnPress 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, Button.OnPress 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, Button.OnPress 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, Button.OnPress pressAction, Component 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, Button.OnPress 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, Button.OnPress 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, Button.OnPress 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, Button.OnPress pressAction, Component 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, Button.OnPress 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, Button.OnPress 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, Button.OnPress 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, Button.OnPress pressAction, Component message) { + return createRedrawableTexturedButtonWidget(x, y, width, height, u, v, hoveredVOffset, texture.toMinecraft(), textureWidth, textureHeight, pressAction, message); + } + + + + public static class Texts { + public static Component empty() { + return CommonComponents.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(Font renderer, DrawObjectDM drawObjectDM, Component text, int x, int y, int color) { + drawObjectDM.getContext().text(renderer, text, x, y, fixColor(color), false); + return -1; + } + + public static int drawText(Font renderer, DrawObjectDM drawObjectDM, String text, int x, int y, int color) { + drawObjectDM.getContext().text(renderer, text, x, y, fixColor(color), false); + return -1; + } + + public static int drawText(Font renderer, DrawObjectDM drawObjectDM, FormattedCharSequence text, int x, int y, int color) { + drawObjectDM.getContext().text(renderer, text, x, y, fixColor(color), false); + return -1; + } + + 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().blit(RenderPipelines.GUI_TEXTURED, 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().blit(RenderPipelines.GUI_TEXTURED, texture, x, y, u, v, width, height, 256, 256); + } + + public static Font getTextRenderer() { + return Minecraft.getInstance().font; + } + + 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(Font renderer, DrawObjectDM drawObjectDM, TextComponent text, int x, int y, int color) { + return drawText(renderer, drawObjectDM, text.getText(), x, y, color); + } + + public static int drawText(Font renderer, DrawObjectDM drawObjectDM, Component text, int x, int y) { + return drawText(renderer, drawObjectDM, text, x, y, -12566464); + } + + public static int drawText(Font renderer, DrawObjectDM drawObjectDM, TextComponent text, int x, int y) { + return drawText(renderer, drawObjectDM, text, x, y, -12566464); + } + + public static void drawTooltip(DrawObjectDM drawObjectDM, Font textRenderer, Component text, int x, int y) { + drawObjectDM.getContext().setTooltipForNextFrame(textRenderer, text, x, y); + } + + public static void drawTooltip(DrawObjectDM drawObjectDM, Font textRenderer, List texts, int x, int y) { + drawObjectDM.getContext().setComponentTooltipForNextFrame(textRenderer, texts, x, y); + } + + public static void drawBorder(DrawObjectDM drawObjectDM, int x, int y, int width, int height, int color) { + // TODO: drawBorderを一時的に廃止 + //drawObjectDM.getContext().drawBorder(x, y, width, height, color); + } + + public static void drawTooltip(DrawObjectDM drawObjectDM, Component text, int x, int y) { + drawObjectDM.getContext().setTooltipForNextFrame(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().setComponentTooltipForNextFrame(getTextRenderer(), texts, x, y); + } + + public static void drawTooltip2(DrawObjectDM drawObjectDM, List texts, int x, int y) { + drawTooltip(drawObjectDM, texts.stream().map(TextComponent::getText).collect(Collectors.toList()), x, y); + } + + public static void drawItem(DrawObjectDM drawObjectDM, ItemStack stack, int x, int y) { + drawItem(drawObjectDM, stack.toMinecraft(), x, y); + } + + public static void drawItem(DrawObjectDM drawObjectDM, net.minecraft.world.item.ItemStack stack, int x, int y) { + drawObjectDM.getContext().item(stack, x, y); + } + + public static void drawItem(DrawObjectDM drawObjectDM, ItemStack stack, int x, int y, int seed) { + drawItem(drawObjectDM, stack.toMinecraft(), x, y, seed); + } + + public static void drawItem(DrawObjectDM drawObjectDM, net.minecraft.world.item.ItemStack stack, int x, int y, int seed) { + drawObjectDM.getContext().item(stack, x, y, seed); + } + + public static void drawItemWithoutEntity(DrawObjectDM drawObjectDM, ItemStack stack, int x, int y) { + drawItemWithoutEntity(drawObjectDM, stack.toMinecraft(), x, y); + } + + public static void drawItemWithoutEntity(DrawObjectDM drawObjectDM, net.minecraft.world.item.ItemStack stack, int x, int y) { + drawObjectDM.getContext().fakeItem(stack, x, y, 0); + } + + public static void drawItemWithoutEntity(DrawObjectDM drawObjectDM, ItemStack stack, int x, int y, int seed) { + drawItemWithoutEntity(drawObjectDM, stack.toMinecraft(), x, y, seed); + } + + public static void drawItemWithoutEntity(DrawObjectDM drawObjectDM, net.minecraft.world.item.ItemStack stack, int x, int y, int seed) { + drawObjectDM.getContext().fakeItem(stack, x, y, seed); + } + + public static void drawItemInSlot(DrawObjectDM drawObjectDM, ItemStack stack, int x, int y) { + drawItemInSlot(drawObjectDM, stack.toMinecraft(), x, y); + } + + public static void drawItemInSlot(DrawObjectDM drawObjectDM, net.minecraft.world.item.ItemStack stack, int x, int y) { + drawObjectDM.getContext().itemDecorations(getTextRenderer(), stack, x, y); + } + + public static void drawItemInSlot(DrawObjectDM drawObjectDM, ItemStack stack, int x, int y, String countText) { + drawItemInSlot(drawObjectDM, stack.toMinecraft(), x, y, countText); + } + + public static void drawItemInSlot(DrawObjectDM drawObjectDM, net.minecraft.world.item.ItemStack stack, int x, int y, String countText) { + drawObjectDM.getContext().itemDecorations(getTextRenderer(), stack, x, y, countText); + } + + public static void enableScissor(DrawObjectDM drawObjectDM, int x0, int y0, int x1, int y1) { + drawObjectDM.getContext().enableScissor(x0, y0, x1, y1); + } + + public static void disableScissor(DrawObjectDM drawObjectDM) { + drawObjectDM.getContext().disableScissor(); + } + + public static void fill(DrawObjectDM drawObjectDM, int x0, int y0, int x1, int y1, int color) { + drawObjectDM.getContext().fill(x0, y0, x1, y1, fixColor(color)); + } + + public static void fillGradient(DrawObjectDM drawObjectDM, int x0, int y0, int x1, int y1, int color0, int color1) { + drawObjectDM.getContext().fillGradient(x0, y0, x1, y1, fixColor(color0), fixColor(color1)); + } + } + + public static int getWidth(Component text) { + return RendererUtil.getTextRenderer().width(text); + } + + // RGBからARGBに変換する (1.21.6からは透明になるため) + private static int fixColor(int color) { + if ((color >>> 24) == 0) { + return 0xFF000000 | color; + } else { + return color; + } + } +} 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..02d1565c3 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/client/WindowUtil.java @@ -0,0 +1,54 @@ +package net.pitan76.mcpitanlib.api.util.client; + +import com.mojang.blaze3d.platform.Window; + +public class WindowUtil { + + public static Window getWindow() { + return ClientUtil.getWindow(); + } + + public static int getWindowScaledWidth() { + return getWindow().getGuiScaledWidth(); + } + + public static int getWindowScaledHeight() { + return getWindow().getGuiScaledHeight(); + } + + public static int getWindowWidth() { + return getWindow().getScreenWidth(); + } + + public static int getWindowHeight() { + return getWindow().getScreenHeight(); + } + + 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(); + } + + public static int getX() { + return getWindow().getX(); + } + + public static int getY() { + return getWindow().getY(); + } + + public static double getScaleFactor() { + return getWindow().getGuiScale(); + } +} 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..c46a05630 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/client/render/CompatItemDisplayContext.java @@ -0,0 +1,40 @@ +package net.pitan76.mcpitanlib.api.util.client.render; + +import net.minecraft.world.item.ItemDisplayContext; +import net.pitan76.mcpitanlib.api.util.CompatStringIdentifiable; + +public class CompatItemDisplayContext implements CompatStringIdentifiable { + private final ItemDisplayContext context; + + public static final CompatItemDisplayContext NONE = of(ItemDisplayContext.NONE); + public static final CompatItemDisplayContext THIRD_PERSON_LEFT_HAND = of(ItemDisplayContext.THIRD_PERSON_LEFT_HAND); + public static final CompatItemDisplayContext THIRD_PERSON_RIGHT_HAND = of(ItemDisplayContext.THIRD_PERSON_RIGHT_HAND); + public static final CompatItemDisplayContext FIRST_PERSON_LEFT_HAND = of(ItemDisplayContext.FIRST_PERSON_LEFT_HAND); + public static final CompatItemDisplayContext FIRST_PERSON_RIGHT_HAND = of(ItemDisplayContext.FIRST_PERSON_RIGHT_HAND); + public static final CompatItemDisplayContext HEAD = of(ItemDisplayContext.HEAD); + public static final CompatItemDisplayContext GUI = of(ItemDisplayContext.GUI); + public static final CompatItemDisplayContext GROUND = of(ItemDisplayContext.GROUND); + public static final CompatItemDisplayContext FIXED = of(ItemDisplayContext.FIXED); + public static final CompatItemDisplayContext ON_SHELF = of(ItemDisplayContext.ON_SHELF); + + public CompatItemDisplayContext(ItemDisplayContext context) { + this.context = context; + } + + public static CompatItemDisplayContext of(ItemDisplayContext context) { + return new CompatItemDisplayContext(context); + } + + public ItemDisplayContext 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..d0e977404 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/client/render/CompatItemRenderUtil.java @@ -0,0 +1,45 @@ +package net.pitan76.mcpitanlib.api.util.client.render; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.item.ItemModelResolver; +import net.minecraft.client.renderer.item.ItemStackRenderState; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; +import net.pitan76.mcpitanlib.api.client.render.block.entity.event.BlockEntityRenderEvent; +import net.pitan76.mcpitanlib.midohra.world.World; + +/** + * 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, Level world) { + renderItem(stack, CompatItemDisplayContext.FIXED, e, world); + } + + /** + * Renders an ItemStack + */ + public static void renderItem(ItemStack stack, CompatItemDisplayContext displayContext, BlockEntityRenderEvent e, Level world) { + ItemModelResolver manager = e.ctx != null ? e.ctx.getItemModelManager() : Minecraft.getInstance().getItemModelResolver(); + + ItemStackRenderState state = new ItemStackRenderState(); + manager.updateForTopItem(state, stack, displayContext.getContext(), world, null, 0); + + int light = e.getLight(); + if (light == 0) light = 0xF000F0; // full-bright fallback if not populated by MCPitanLib + int overlay = e.getOverlay(); + + state.submit(e.matrices, e.getQueue(), light, overlay, 0); + } + + public static void renderItemFixed(net.pitan76.mcpitanlib.midohra.item.ItemStack stack, BlockEntityRenderEvent e, World world) { + renderItemFixed(stack.toMinecraft(), e, world.toMinecraft()); + } + + public static void renderItem(net.pitan76.mcpitanlib.midohra.item.ItemStack stack, CompatItemDisplayContext displayContext, BlockEntityRenderEvent e, World world) { + renderItem(stack.toMinecraft(), displayContext, e, world.toMinecraft()); + } +} 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..62eca1ad8 --- /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.renderer.texture.OverlayTexture; +import com.mojang.blaze3d.vertex.VertexConsumer; +import com.mojang.blaze3d.vertex.PoseStack; +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.addVertex(x, y, z); + } + + public static VertexConsumer vertex(VertexConsumer vertexConsumer, PoseStack stack, float x, float y, float z) { + return vertexConsumer.addVertex(stack.last(), x, y, z); + } + + public static VertexConsumer normal(VertexConsumer vertexConsumer, float x, float y, float z) { + return vertexConsumer.setNormal(x, y, z); + } + + public static VertexConsumer color(VertexConsumer vertexConsumer, float red, float green, float blue, float alpha) { + return vertexConsumer.setColor(red, green, blue, alpha); + } + + public static VertexConsumer color(VertexConsumer vertexConsumer, int red, int green, int blue, int alpha) { + return vertexConsumer.setColor(red, green, blue, alpha); + } + + public static VertexConsumer colorARGB(VertexConsumer vertexConsumer, int argb) { + return vertexConsumer.setColor(argb); + } + + public static VertexConsumer colorRGB(VertexConsumer vertexConsumer, int rgb) { + return colorARGB(vertexConsumer, (0xFF << 24) | (rgb & 0xFFFFFF)); + } + + public static VertexConsumer light(VertexConsumer vertexConsumer, int light) { + return vertexConsumer.setLight(light); + } + + public static VertexConsumer overlay(VertexConsumer vertexConsumer, int overlay) { + return vertexConsumer.setOverlay(overlay); + } + + public static VertexConsumer overlayDefaultUV(VertexConsumer vertexConsumer) { + return vertexConsumer.setOverlay(OverlayTexture.NO_OVERLAY); + } + + 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.setUv(u, v); + } + + public static VertexConsumer vertex(VertexConsumer vertexConsumer, Matrix4f matrix4f, float x, float y, float z) { + return vertexConsumer.addVertex(matrix4f, x, y, z); + } + + public static VertexConsumer normal(VertexConsumer vertexConsumer, PoseStack stack, float x, float y, float z) { + return vertexConsumer.setNormal(stack.last(), x, y, z); + } + + public static VertexConsumer next(VertexConsumer vertexConsumer) { + return vertexConsumer; + } + + public static void renderQuad(VertexConsumer vertexConsumer, PoseStack 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..1f24c7b9f --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/client/render/VertexRenderingUtil.java @@ -0,0 +1,114 @@ +package net.pitan76.mcpitanlib.api.util.client.render; + +import com.mojang.blaze3d.vertex.VertexConsumer; +import net.minecraft.client.renderer.ShapeRenderer; +import com.mojang.blaze3d.vertex.PoseStack; +import net.minecraft.world.phys.AABB; +import net.pitan76.mcpitanlib.api.client.render.DrawObjectMV; +import org.joml.Matrix3f; +import org.joml.Matrix4f; + +import java.util.Optional; + +public class VertexRenderingUtil { + public static void drawBox(PoseStack matrices, VertexConsumer buffer, double minX, double minY, double minZ, double maxX, double maxY, double maxZ, float red, float green, float blue, float alpha) { + PoseStack.Pose entry = matrices.last(); + + drawLine(buffer, entry, minX, minY, minZ, maxX, minY, minZ, red, green, blue, alpha); + drawLine(buffer, entry, minX, minY, maxZ, maxX, minY, maxZ, red, green, blue, alpha); + drawLine(buffer, entry, minX, maxY, minZ, maxX, maxY, minZ, red, green, blue, alpha); + drawLine(buffer, entry, minX, maxY, maxZ, maxX, maxY, maxZ, red, green, blue, alpha); + + drawLine(buffer, entry, minX, minY, minZ, minX, maxY, minZ, red, green, blue, alpha); + drawLine(buffer, entry, maxX, minY, minZ, maxX, maxY, minZ, red, green, blue, alpha); + drawLine(buffer, entry, minX, minY, maxZ, minX, maxY, maxZ, red, green, blue, alpha); + drawLine(buffer, entry, maxX, minY, maxZ, maxX, maxY, maxZ, red, green, blue, alpha); + + drawLine(buffer, entry, minX, minY, minZ, minX, minY, maxZ, red, green, blue, alpha); + drawLine(buffer, entry, maxX, minY, minZ, maxX, minY, maxZ, red, green, blue, alpha); + drawLine(buffer, entry, minX, maxY, minZ, minX, maxY, maxZ, red, green, blue, alpha); + drawLine(buffer, entry, maxX, maxY, minZ, maxX, maxY, maxZ, red, green, blue, alpha); + } + + public static void drawBox(PoseStack 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) { + PoseStack.Pose entry = matrices.last(); + + drawLine(buffer, entry, minX, minY, minZ, maxX, minY, minZ, xAxisRed, green, blue, alpha); + drawLine(buffer, entry, minX, minY, maxZ, maxX, minY, maxZ, xAxisRed, green, blue, alpha); + drawLine(buffer, entry, minX, maxY, minZ, maxX, maxY, minZ, xAxisRed, green, blue, alpha); + drawLine(buffer, entry, minX, maxY, maxZ, maxX, maxY, maxZ, xAxisRed, green, blue, alpha); + + drawLine(buffer, entry, minX, minY, minZ, minX, maxY, minZ, red, yAxisGreen, blue, alpha); + drawLine(buffer, entry, maxX, minY, minZ, maxX, maxY, minZ, red, yAxisGreen, blue, alpha); + drawLine(buffer, entry, minX, minY, maxZ, minX, maxY, maxZ, red, yAxisGreen, blue, alpha); + drawLine(buffer, entry, maxX, minY, maxZ, maxX, maxY, maxZ, red, yAxisGreen, blue, alpha); + + drawLine(buffer, entry, minX, minY, minZ, minX, minY, maxZ, red, green, zAxisBlue, alpha); + drawLine(buffer, entry, maxX, minY, minZ, maxX, minY, maxZ, red, green, zAxisBlue, alpha); + drawLine(buffer, entry, minX, maxY, minZ, minX, maxY, maxZ, red, green, zAxisBlue, alpha); + drawLine(buffer, entry, maxX, maxY, minZ, maxX, maxY, maxZ, red, green, zAxisBlue, alpha); + } + + public static void drawFilledBox(PoseStack matrices, VertexConsumer buffer, double minX, double minY, double minZ, double maxX, double maxY, double maxZ, float red, float green, float blue, float alpha) { + PoseStack.Pose entry = matrices.last(); + Matrix4f positionMatrix = entry.pose(); + + drawQuad(buffer, positionMatrix, minX, minY, minZ, maxX, minY, minZ, maxX, minY, maxZ, minX, minY, maxZ, red, green, blue, alpha); + drawQuad(buffer, positionMatrix, minX, maxY, minZ, minX, maxY, maxZ, maxX, maxY, maxZ, maxX, maxY, minZ, red, green, blue, alpha); + drawQuad(buffer, positionMatrix, minX, minY, minZ, minX, maxY, minZ, maxX, maxY, minZ, maxX, minY, minZ, red, green, blue, alpha); + drawQuad(buffer, positionMatrix, minX, minY, maxZ, maxX, minY, maxZ, maxX, maxY, maxZ, minX, maxY, maxZ, red, green, blue, alpha); + drawQuad(buffer, positionMatrix, minX, minY, minZ, minX, minY, maxZ, minX, maxY, maxZ, minX, maxY, minZ, red, green, blue, alpha); + drawQuad(buffer, positionMatrix, maxX, minY, minZ, maxX, maxY, minZ, maxX, maxY, maxZ, maxX, minY, 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, PoseStack 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); + } + + // TODO: all version impl + private static void drawQuad(VertexConsumer buffer, Matrix4f matrix, double x1, double y1, double z1, double x2, double y2, double z2, double x3, double y3, double z3, double x4, double y4, double z4, float red, float green, float blue, float alpha) { + VertexConsumerUtil.vertex(buffer, matrix, (float)x1, (float)y1, (float)z1).setColor(red, green, blue, alpha); + VertexConsumerUtil.vertex(buffer, matrix, (float)x2, (float)y2, (float)z2).setColor(red, green, blue, alpha); + VertexConsumerUtil.vertex(buffer, matrix, (float)x3, (float)y3, (float)z3).setColor(red, green, blue, alpha); + VertexConsumerUtil.vertex(buffer, matrix, (float)x4, (float)y4, (float)z4).setColor(red, green, blue, alpha); + } + + // TODO: all version impl + private static void drawLine(VertexConsumer consumer, PoseStack.Pose entry, double x1, double y1, double z1, double x2, double y2, double z2, float red, float green, float blue, float alpha) { + float dx = (float)(x2 - x1); + float dy = (float)(y2 - y1); + float dz = (float)(z2 - z1); + float len = (float)Math.sqrt(dx * dx + dy * dy + dz * dz); + float nx = len == 0.0f ? 0.0f : dx / len; + float ny = len == 0.0f ? 1.0f : dy / len; + float nz = len == 0.0f ? 0.0f : dz / len; + + VertexConsumerUtil.vertex(consumer, entry.pose(), (float)x1, (float)y1, (float)z1); + VertexConsumerUtil.color(consumer, red, green, blue, alpha); + VertexConsumerUtil.normal(consumer, nx, ny, nz); + consumer.setLineWidth(2.0f); // + VertexConsumerUtil.next(consumer); + + VertexConsumerUtil.vertex(consumer, entry.pose(), (float)x2, (float)y2, (float)z2); + VertexConsumerUtil.color(consumer, red, green, blue, alpha); + VertexConsumerUtil.normal(consumer, nx, ny, nz); + consumer.setLineWidth(2.0f); // + VertexConsumerUtil.next(consumer); + } +} 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..d1984282f --- /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.renderer.LevelRenderer; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; + +public class WorldRendererUtil { + public static int getLightmapCoordinates(Level world, BlockPos pos) { + return LevelRenderer.getLightCoords(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..df710314b --- /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.components.events.GuiEventListener; +import net.minecraft.client.gui.screens.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, GuiEventListener 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..3b4635c59 --- /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.components.AbstractWidget; +import net.pitan76.mcpitanlib.api.client.render.handledscreen.RenderArgs; + +public class ClickableWidgetUtil { + public static void render(AbstractWidget widget, RenderArgs args) { + widget.extractRenderState(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..c52f39ae2 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/client/widget/TextFieldUtil.java @@ -0,0 +1,79 @@ +package net.pitan76.mcpitanlib.api.util.client.widget; + +import net.minecraft.client.gui.Font; +import net.minecraft.client.gui.components.EditBox; +import net.minecraft.client.input.CharacterEvent; +import net.minecraft.client.input.KeyEvent; +import net.minecraft.network.chat.Component; +import net.pitan76.mcpitanlib.api.client.render.handledscreen.RenderArgs; +import net.pitan76.mcpitanlib.api.util.TextUtil; + +public class TextFieldUtil { + public static void setFocused(EditBox widget, boolean focused) { + widget.setFocused(focused); + } + + public static void render(EditBox widget, RenderArgs args) { + widget.extractRenderState(args.drawObjectDM.getContext(), args.mouseX, args.mouseY, args.delta); + } + + public static void setEditable(EditBox widget, boolean editable) { + widget.setEditable(editable); + } + + public static void setMaxLength(EditBox widget, int maxLength) { + widget.setMaxLength(maxLength); + } + + public static void setSuggestion(EditBox widget, String suggestion) { + widget.setSuggestion(suggestion); + } + + public static void setText(EditBox widget, String text) { + widget.setValue(text); + } + + public static String getText(EditBox widget) { + return widget.getValue(); + } + + public static void setDrawsBackground(EditBox widget, boolean drawsBackground) { + widget.setBordered(drawsBackground); + } + + public static void setFocusUnlocked(EditBox widget, boolean focusUnlocked) { + widget.setCanLoseFocus(focusUnlocked); + } + + public static boolean isFocused(EditBox widget) { + return widget.isFocused(); + } + + public static boolean keyPressed(EditBox widget, int keyCode, int scanCode, int modifiers) { + return widget.keyPressed(new KeyEvent(keyCode, scanCode, modifiers)); + } + + public static boolean keyReleased(EditBox widget, int keyCode, int scanCode, int modifiers) { + return widget.keyReleased(new KeyEvent(keyCode, scanCode, modifiers)); + } + + public static boolean charTyped(EditBox widget, char chr, int modifiers) { + return widget.charTyped(new CharacterEvent(chr)); + } + + public static EditBox create(Font renderer, int x, int y, int width, int height, Component text) { + return new EditBox(renderer, x, y, width, height, text); + } + + public static EditBox create(Font renderer, int width, int height, Component text) { + return new EditBox(renderer, width, height, text); + } + + public static EditBox create(Font renderer, int x, int y, int width, int height) { + return new EditBox(renderer, x, y, width, height, TextUtil.empty()); + } + + public static EditBox create(Font renderer, int width, int height) { + return new EditBox(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..bb5e38f31 --- /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.world.Container; +import net.minecraft.world.item.ItemStack; +import net.minecraft.core.NonNullList; +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 Container toInventory() { + return ClippedInventory.of(list.toInventory(), start, end); + } + + @Override + public NonNullList defaultedList() { + NonNullList clippedList = NonNullList.withSize(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..d032f3939 --- /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.core.NonNullList; + +public class DefaultedListUtil { + + public static NonNullList of() { + return NonNullList.create(); + } + + public static NonNullList ofSize(int size, E defaultElement) { + return NonNullList.withSize(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..cb6f47ea6 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/collection/ItemStackList.java @@ -0,0 +1,246 @@ +package net.pitan76.mcpitanlib.api.util.collection; + +import com.google.common.collect.Lists; +import net.minecraft.world.Container; +import net.minecraft.world.item.ItemStack; +import net.minecraft.core.NonNullList; +import net.pitan76.mcpitanlib.api.gui.inventory.IInventory; +import net.pitan76.mcpitanlib.api.registry.CompatRegistryLookup; +import net.pitan76.mcpitanlib.api.util.InventoryUtil; +import net.pitan76.mcpitanlib.api.util.ItemStackUtil; +import net.pitan76.mcpitanlib.api.util.inventory.CompatInventory; +import net.pitan76.mcpitanlib.api.util.inventory.ICompatInventory; +import net.pitan76.mcpitanlib.api.util.inventory.InventoryWrapper; +import net.pitan76.mcpitanlib.midohra.nbt.NbtCompound; +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 NonNullList { + + 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 Container toInventory(NonNullList list) { + return IInventory.of(list); + } + + public static NonNullList toDefaultedList(Container inventory) { + NonNullList list = NonNullList.withSize(inventory.getContainerSize(), ItemStackUtil.empty()); + for (int i = 0; i < inventory.getContainerSize(); i++) { + list.set(i, inventory.getItem(i)); + } + + return list; + } + + public static ItemStackList fromInventory(Container inventory) { + return new ItemStackList(toDefaultedList(inventory), ItemStackUtil.empty()); + } + + public Container toInventory() { + return toInventory(this); + } + + public NonNullList defaultedList() { + return this; + } + + public static ItemStackList of(NonNullList 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; + } + + public void set(int index, net.pitan76.mcpitanlib.midohra.item.ItemStack stack) { + set(index, stack.toMinecraft()); + } + + public boolean isEmpty(int index) { + return get(index).isEmpty(); + } + + public void writeNbt(NbtCompound nbt, CompatRegistryLookup registryLookup) { + InventoryUtil.writeNbt(registryLookup, nbt, this); + } + + public void readNbt(NbtCompound nbt, CompatRegistryLookup registryLookup) { + InventoryUtil.readNbt(registryLookup, nbt, this); + } + + public static ItemStackList fromNbt(NbtCompound nbt, CompatRegistryLookup registryLookup, int size) { + ItemStackList list = ItemStackList.ofSize(size); + list.readNbt(nbt, registryLookup); + return list; + } + + public ICompatInventory toCompatInventory() { + return InventoryWrapper.of(toInventory()); + } +} 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..a7aa2866b --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/color/CompatBrightness.java @@ -0,0 +1,49 @@ +package net.pitan76.mcpitanlib.api.util.color; + +import net.minecraft.world.level.material.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().modifier; + } + + @Override + public int hashCode() { + return brightness.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + CompatBrightness other = (CompatBrightness) obj; + return brightness == other.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..452b97db7 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/color/CompatDyeColor.java @@ -0,0 +1,59 @@ +package net.pitan76.mcpitanlib.api.util.color; + +import net.minecraft.world.item.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.name(); + } + + @Override + public String asString_compat() { + return getName(); + } + + @Override + public int hashCode() { + return color.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + CompatDyeColor other = (CompatDyeColor) obj; + return color == other.color; + } +} 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..75de88416 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/color/CompatMapColor.java @@ -0,0 +1,107 @@ +package net.pitan76.mcpitanlib.api.util.color; + +import net.minecraft.world.level.material.MapColor; + +public class CompatMapColor { + private final MapColor color; + + public static final CompatMapColor CLEAR = of(MapColor.NONE); + public static final CompatMapColor PALE_GREEN = of(MapColor.GRASS); + public static final CompatMapColor PALE_YELLOW = of(MapColor.SAND); + public static final CompatMapColor WHITE_GRAY = of(MapColor.WOOL); + public static final CompatMapColor BRIGHT_RED = of(MapColor.FIRE); + public static final CompatMapColor PALE_PURPLE = of(MapColor.ICE); + public static final CompatMapColor IRON_GRAY = of(MapColor.METAL); + public static final CompatMapColor DARK_GREEN = of(MapColor.PLANT); + public static final CompatMapColor WHITE = of(MapColor.SNOW); + public static final CompatMapColor LIGHT_BLUE_GRAY = of(MapColor.CLAY); + public static final CompatMapColor DIRT_BROWN = of(MapColor.DIRT); + public static final CompatMapColor STONE_GRAY = of(MapColor.STONE); + public static final CompatMapColor WATER_BLUE = of(MapColor.WATER); + public static final CompatMapColor OAK_TAN = of(MapColor.WOOD); + public static final CompatMapColor OFF_WHITE = of(MapColor.QUARTZ); + public static final CompatMapColor ORANGE = of(MapColor.COLOR_ORANGE); + public static final CompatMapColor MAGENTA = of(MapColor.COLOR_MAGENTA); + public static final CompatMapColor LIGHT_BLUE = of(MapColor.COLOR_LIGHT_BLUE); + public static final CompatMapColor YELLOW = of(MapColor.COLOR_YELLOW); + public static final CompatMapColor LIME = of(MapColor.COLOR_LIGHT_GREEN); + public static final CompatMapColor PINK = of(MapColor.COLOR_PINK); + public static final CompatMapColor GRAY = of(MapColor.COLOR_GRAY); + public static final CompatMapColor LIGHT_GRAY = of(MapColor.COLOR_LIGHT_GRAY); + public static final CompatMapColor CYAN = of(MapColor.COLOR_CYAN); + public static final CompatMapColor PURPLE = of(MapColor.COLOR_PURPLE); + public static final CompatMapColor BLUE = of(MapColor.COLOR_BLUE); + public static final CompatMapColor BROWN = of(MapColor.COLOR_BROWN); + public static final CompatMapColor GREEN = of(MapColor.COLOR_GREEN); + public static final CompatMapColor RED = of(MapColor.COLOR_RED); + public static final CompatMapColor BLACK = of(MapColor.COLOR_BLACK); + public static final CompatMapColor GOLD = of(MapColor.GOLD); + public static final CompatMapColor DIAMOND_BLUE = of(MapColor.DIAMOND); + public static final CompatMapColor LAPIS_BLUE = of(MapColor.LAPIS); + public static final CompatMapColor EMERALD_GREEN = of(MapColor.EMERALD); + public static final CompatMapColor SPRUCE_BROWN = of(MapColor.PODZOL); + public static final CompatMapColor DARK_RED = of(MapColor.NETHER); + 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_LIGHT_GREEN); + 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.CRIMSON_NYLIUM); + public static final CompatMapColor DULL_PINK = of(MapColor.CRIMSON_STEM); + public static final CompatMapColor DARK_CRIMSON = of(MapColor.CRIMSON_HYPHAE); + public static final CompatMapColor TEAL = of(MapColor.WARPED_NYLIUM); + public static final CompatMapColor DARK_AQUA = of(MapColor.WARPED_STEM); + public static final CompatMapColor DARK_DULL_PINK = of(MapColor.WARPED_HYPHAE); + public static final CompatMapColor BRIGHT_TEAL = of(MapColor.WARPED_WART_BLOCK); + public static final CompatMapColor DEEPSLATE_GRAY = of(MapColor.DEEPSLATE); + public static final CompatMapColor RAW_IRON_PINK = of(MapColor.RAW_IRON); + public static final CompatMapColor LICHEN_GREEN = of(MapColor.GLOW_LICHEN); + + 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.col; + } + + public int getRenderColor(CompatBrightness brightness) { + return color.calculateARGBColor(brightness.get()); + } + + @Override + public int hashCode() { + return color.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + CompatMapColor other = (CompatMapColor) obj; + return color.equals(other.color); + } +} 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..740e0d0c0 --- /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.world.Container; +import net.minecraft.world.item.Item; +import net.minecraft.world.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(Container 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.getDescriptionId()).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(Container inventory) { + StringBuilder sb = new StringBuilder(); + sb.append("Inventory: {").append("\n"); + + for (int i = 0; i < inventory.getContainerSize(); i++) { + ItemStack stack = inventory.getItem(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..bfd6780e1 --- /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.world.entity.projectile.arrow.Arrow; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; +import net.minecraft.world.level.Level; +import net.pitan76.mcpitanlib.api.util.ItemStackUtil; +import org.jetbrains.annotations.Nullable; + +public class ArrowEntityUtil { + public static Arrow create(Level world, double x, double y, double z, ItemStack stack, @Nullable ItemStack shotFrom) { + return new Arrow(world, x, y, z, stack, shotFrom); + } + + public static Arrow create(Level world, double x, double y, double z, ItemStack stack) { + return create(world, x, y, z, stack, null); + } + + public static Arrow create(Level world, double x, double y, double z) { + return create(world, x, y, z, ItemStackUtil.getDefaultStack(Items.ARROW)); + } + + public static void setVelocity(Arrow arrow, double x, double y, double z, float velocity, float divergence) { + arrow.shoot(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..71075b679 --- /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.world.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.getId(); + } + + public static EquipmentSlot fromEntitySlotId(int id) { + for (EquipmentSlot slot : EquipmentSlot.values()) { + if (slot.getId() == 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..5524b8b41 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/entity/ItemEntityUtil.java @@ -0,0 +1,137 @@ +package net.pitan76.mcpitanlib.api.util.entity; + +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.item.ItemStack; +import net.minecraft.core.BlockPos; +import net.minecraft.world.phys.AABB; +import net.minecraft.world.phys.Vec3; +import net.minecraft.world.level.Level; +import net.pitan76.mcpitanlib.api.entity.Player; +import net.pitan76.mcpitanlib.api.util.WorldUtil; +import net.pitan76.mcpitanlib.midohra.entity.ItemEntityWrapper; +import net.pitan76.mcpitanlib.midohra.util.math.Vector3d; +import net.pitan76.mcpitanlib.midohra.util.math.Vector3i; + +import java.util.List; +import java.util.stream.Collectors; + +public class ItemEntityUtil { + public static ItemEntity create(Level world, double x, double y, double z, ItemStack stack) { + return new ItemEntity(world, x, y, z, stack); + } + + public static ItemEntity create(Level world, BlockPos pos, ItemStack stack) { + return create(world, pos.getX(), pos.getY(), pos.getZ(), stack); + } + + public static ItemEntity create(Level world, Vec3 pos, ItemStack stack) { + return create(world, pos.x, pos.y, pos.z, stack); + } + + public static ItemEntity create(Level 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.setDeltaMovement(velocityX, velocityY, velocityZ); + } + + public static void setVelocity(ItemEntity itemEntity, Vec3 vec3d) { + itemEntity.setDeltaMovement(vec3d); + } + + public static void setPickupDelay(ItemEntity itemEntity, int pickupDelay) { + itemEntity.setPickUpDelay(pickupDelay); + } + + public static void setToDefaultPickupDelay(ItemEntity itemEntity) { + itemEntity.setDefaultPickUpDelay(); + } + + public static ItemStack getStack(ItemEntity entity) { + return entity.getItem(); + } + + public static List getEntities(Level world, AABB box) { + return WorldUtil.getEntitiesByType(world, EntityType.ITEM, box); + } + + public static ItemEntity createWithSpawn(Level 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(Level world, ItemStack stack, BlockPos pos) { + return createWithSpawn(world, stack, pos.getX(), pos.getY(), pos.getZ()); + } + + public static ItemEntity createWithSpawn(Level world, ItemStack stack, Vector3d pos) { + return createWithSpawn(world, stack, pos.x, pos.y, pos.z); + } + + public static ItemEntity createWithSpawn(Level world, ItemStack stack, Vector3i pos) { + return createWithSpawn(world, stack, pos.toCenter()); + } + + public static ItemEntity createWithSpawn(net.pitan76.mcpitanlib.midohra.world.World world, ItemStack stack, double x, double y, double z) { + return createWithSpawn(world.getRaw(), stack, x, y, z); + } + + public static ItemEntity createWithSpawn(net.pitan76.mcpitanlib.midohra.world.World world, ItemStack stack, BlockPos pos) { + return createWithSpawn(world, stack, pos.getX(), pos.getY(), pos.getZ()); + } + + public static ItemEntity createWithSpawn(net.pitan76.mcpitanlib.midohra.world.World world, ItemStack stack, Vector3i pos) { + return createWithSpawn(world, stack, pos.toCenter()); + } + + public static ItemEntity createWithSpawn(net.pitan76.mcpitanlib.midohra.world.World world, ItemStack stack, net.pitan76.mcpitanlib.midohra.util.math.Vector3d pos) { + return createWithSpawn(world.getRaw(), stack, pos.x, pos.y, pos.z); + } + + public static ItemEntity createWithSpawnAtCenter(net.pitan76.mcpitanlib.midohra.world.World world, ItemStack stack, net.pitan76.mcpitanlib.midohra.util.math.BlockPos pos) { + return createWithSpawn(world, stack, pos.toCenterVector3d()); + } + + public static ItemEntity createWithSpawn(net.pitan76.mcpitanlib.midohra.world.World world, net.pitan76.mcpitanlib.midohra.item.ItemStack stack, double x, double y, double z) { + return createWithSpawn(world.getRaw(), stack.toMinecraft(), x, y, z); + } + + public static ItemEntity createWithSpawn(net.pitan76.mcpitanlib.midohra.world.World world, net.pitan76.mcpitanlib.midohra.item.ItemStack stack, net.pitan76.mcpitanlib.midohra.util.math.BlockPos pos) { + return createWithSpawn(world.getRaw(), stack.toMinecraft(), pos.toRaw()); + } + + public static ItemEntity createWithSpawn(net.pitan76.mcpitanlib.midohra.world.World world, net.pitan76.mcpitanlib.midohra.item.ItemStack stack, net.pitan76.mcpitanlib.midohra.util.math.Vector3d pos) { + return createWithSpawn(world.getRaw(), stack.toMinecraft(), pos.x, pos.y, pos.z); + } + + public static ItemEntity createWithSpawnAtCenter(net.pitan76.mcpitanlib.midohra.world.World world, net.pitan76.mcpitanlib.midohra.item.ItemStack stack, net.pitan76.mcpitanlib.midohra.util.math.BlockPos pos) { + return createWithSpawn(world, stack, pos.toCenterVector3d()); + } + + public static ItemEntity createWithSpawn(net.pitan76.mcpitanlib.midohra.world.World world, net.pitan76.mcpitanlib.midohra.item.ItemStack stack, net.pitan76.mcpitanlib.midohra.util.math.Vector3i pos) { + return createWithSpawn(world, stack, pos.toCenter()); + } + + public static List getEntities(net.pitan76.mcpitanlib.midohra.world.World world, net.pitan76.mcpitanlib.midohra.util.math.Box box) { + return getEntities(world.getRaw(), box.toMinecraft()); + } + + public static List getEntityWrappers(net.pitan76.mcpitanlib.midohra.world.World world, net.pitan76.mcpitanlib.midohra.util.math.Box box) { + return getEntities(world, box).stream().map(ItemEntityWrapper::of).collect(Collectors.toList()); + } + + public static void onPlayerCollision(ItemEntity itemEntity, Player player) { + itemEntity.playerTouch(player.getEntity()); + } + + public static void onPlayerCollision(ItemEntityWrapper itemEntity, Player player) { + onPlayerCollision(itemEntity.get(), player); + } +} 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..829a8190a --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/entity/LivingEntityUtil.java @@ -0,0 +1,84 @@ +package net.pitan76.mcpitanlib.api.util.entity; + +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EquipmentSlot; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.effect.MobEffectInstance; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; +import net.pitan76.mcpitanlib.api.entity.effect.CompatStatusEffect; +import net.pitan76.mcpitanlib.api.entity.effect.CompatStatusEffectInstance; +import net.pitan76.mcpitanlib.api.item.ArmorEquipmentType; +import net.pitan76.mcpitanlib.api.util.EntityUtil; +import net.pitan76.mcpitanlib.midohra.entity.EntityWrapper; + +import java.util.ArrayList; +import java.util.List; + +public class LivingEntityUtil extends EntityUtil { + public static void addStatusEffect(LivingEntity entity, CompatStatusEffectInstance effect) { + entity.addEffect(effect.getInstance()); + } + + public static void removeStatusEffect(LivingEntity entity, CompatStatusEffectInstance effect) { + entity.removeEffect(effect.getInstance().getEffect()); + } + + public static void removeStatusEffect(LivingEntity entity, CompatStatusEffect effect, Level world) { + entity.removeEffect(effect.getEntry(world)); + } + + public static List getStatusEffects(LivingEntity entity) { + List compatEffects = new ArrayList<>(); + + for (MobEffectInstance effect : entity.getActiveEffects()) { + 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.getItemBySlot(slot); + } + + public static void setEquippedStack(LivingEntity entity, EquipmentSlot slot, ItemStack stack) { + entity.setItemSlot(slot, stack); + } + + public static ItemStack getEquippedStack(LivingEntity entity, ArmorEquipmentType type) { + return getEquippedStack(entity, type.getSlot()); + } + + public static void setEquippedStack(LivingEntity entity, ArmorEquipmentType type, ItemStack stack) { + entity.setItemSlot(type.getSlot(), stack); + } + + public static net.pitan76.mcpitanlib.midohra.item.ItemStack getEquippedStack(EntityWrapper entity, ArmorEquipmentType slot) { + Entity e = entity.get(); + if (e instanceof LivingEntity) { + return net.pitan76.mcpitanlib.midohra.item.ItemStack.of(getEquippedStack((LivingEntity) e, slot)); + } + + return net.pitan76.mcpitanlib.midohra.item.ItemStack.empty(); + } + + public static void setEquippedStack(EntityWrapper entity, ArmorEquipmentType slot, net.pitan76.mcpitanlib.midohra.item.ItemStack stack) { + Entity e = entity.get(); + if (e instanceof LivingEntity) { + setEquippedStack((LivingEntity) e, slot, stack.toMinecraft()); + } + } +} 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..f99f5c6a8 --- /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.world.entity.Entity; +import net.minecraft.world.entity.projectile.Projectile; + +public class ProjectileEntityUtil { + public static void setVelocity(Projectile projectileEntity, Entity shooter, float pitch, float yaw, float roll, float speed, float divergence) { + projectileEntity.shootFromRotation(shooter, pitch, yaw, roll, speed, divergence); + } + + public static void setVelocity(Projectile projectileEntity, double x, double y, double z, float power, float uncertainty) { + projectileEntity.shoot(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..11688df99 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/entity/ServerPlayerUtil.java @@ -0,0 +1,102 @@ +package net.pitan76.mcpitanlib.api.util.entity; + +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.level.ServerLevel; +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(ServerPlayer serverPlayerEntity, ServerLevel serverWorld, double x, double y, double z, float yaw, float pitch, boolean resetCamera) { + return serverPlayerEntity.teleportTo(serverWorld, x, y, z, Collections.emptySet(), yaw, pitch, resetCamera); + } + + public static boolean teleport(ServerPlayer serverPlayerEntity, ServerLevel serverWorld, double x, double y, double z, float yaw, float pitch) { + return teleport(serverPlayerEntity, serverWorld, x, y, z, yaw, pitch, true); + } + + public static boolean teleport(ServerPlayer serverPlayerEntity, ServerLevel serverWorld, double x, double y, double z) { + return teleport(serverPlayerEntity, serverWorld, x, y, z, serverPlayerEntity.getYRot(), serverPlayerEntity.getXRot()); + } + public static boolean teleport(ServerPlayer 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(ServerPlayer 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(ServerPlayer serverPlayerEntity, net.pitan76.mcpitanlib.midohra.world.ServerWorld serverWorld, double x, double y, double z) { + return teleport(serverPlayerEntity, serverWorld, x, y, z, serverPlayerEntity.getYRot(), serverPlayerEntity.getXRot()); + } + + 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(ServerPlayer serverPlayerEntity, double x, double y, double z, boolean particleEffects) { + return serverPlayerEntity.randomTeleport(x, y, z, particleEffects); + } + + public static boolean teleport(ServerPlayer 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(ServerPlayer serverPlayerEntity, CompatSoundEvent soundEvent, CompatSoundCategory category, float volume, float pitch) { + playSound(serverPlayerEntity, soundEvent, volume, pitch); + } + + public static void playSound(ServerPlayer serverPlayerEntity, CompatSoundEvent soundEvent, float volume, float pitch) { + serverPlayerEntity.playSound(soundEvent.get(), volume, pitch); + } + + public static void playSound(ServerPlayer serverPlayerEntity, CompatSoundEvent soundEvent) { + serverPlayerEntity.makeSound(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..478f38f0e --- /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.world.entity.projectile.hurtingprojectile.SmallFireball; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.phys.Vec3; +import net.minecraft.world.level.Level; +import net.pitan76.mcpitanlib.api.util.math.Vec3dUtil; + +public class SmallFireballEntityUtil { + public static SmallFireball create(Level world, double x, double y, double z, double velocityX, double velocityY, double velocityZ) { + return new SmallFireball(world, x, y, z, Vec3dUtil.create(velocityX, velocityY, velocityZ)); + } + + public static SmallFireball create(Level world, double x, double y, double z, Vec3 velocity) { + return new SmallFireball(world, x, y, z, velocity); + } + + public static void setVelocity(SmallFireball entity, double x, double y, double z, float velocity, float divergence) { + entity.shoot(x, y, z, velocity, divergence); + } + + public static void setItem(SmallFireball entity, ItemStack stack) { + entity.setItem(stack); + } + + public static ItemStack getItem(SmallFireball entity) { + return entity.getItem(); + } +} 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..4330719e1 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/entity/SnowballEntityUtil.java @@ -0,0 +1,28 @@ +package net.pitan76.mcpitanlib.api.util.entity; + +import net.minecraft.world.entity.projectile.throwableitemprojectile.Snowball; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; +import net.pitan76.mcpitanlib.api.util.ItemStackUtil; + +public class SnowballEntityUtil { + public static Snowball create(Level world, double x, double y, double z) { + return new Snowball(world, x, y, z, ItemStackUtil.empty()); + } + + public static Snowball create(Level world, double x, double y, double z, ItemStack stack) { + return new Snowball(world, x, y, z, stack); + } + + public static void setVelocity(Snowball entity, double x, double y, double z, float velocity, float divergence) { + entity.shoot(x, y, z, velocity, divergence); + } + + public static void setItem(Snowball entity, ItemStack stack) { + entity.setItem(stack); + } + + public static ItemStack getItem(Snowball entity) { + return entity.getItem(); + } +} 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..c4f48e089 --- /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.world.entity.projectile.arrow.SpectralArrow; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; +import net.minecraft.world.level.Level; +import net.pitan76.mcpitanlib.api.util.ItemStackUtil; +import org.jetbrains.annotations.Nullable; + +public class SpectralArrowEntityUtil { + public static SpectralArrow create(Level world, double x, double y, double z, ItemStack stack, @Nullable ItemStack shotFrom) { + return new SpectralArrow(world, x, y, z, stack, shotFrom); + } + + public static SpectralArrow create(Level world, double x, double y, double z, ItemStack stack) { + return create(world, x, y, z, stack, null); + } + + public static SpectralArrow create(Level world, double x, double y, double z) { + return create(world, x, y, z, ItemStackUtil.getDefaultStack(Items.ARROW)); + } + + public static void setVelocity(SpectralArrow arrow, double x, double y, double z, float velocity, float divergence) { + arrow.shoot(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..26f35b016 --- /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.world.entity.Entity; +import net.minecraft.world.entity.projectile.throwableitemprojectile.ThrowableItemProjectile; +import net.minecraft.world.item.ItemStack; +import net.pitan76.mcpitanlib.api.entity.CompatThrownItemEntity; + +public class ThrownItemEntityUtil { + public static ItemStack getItem(ThrowableItemProjectile entity) { + return entity.getItem(); + } + + public static void setItem(ThrowableItemProjectile entity, ItemStack stack) { + entity.setItem(stack); + } + + public static ItemStack getStack(ThrowableItemProjectile entity) { + return entity.getItem(); + } + + public static void setVelocity(ThrowableItemProjectile 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(ThrowableItemProjectile 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..001d34b99 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/event/BlockEventGenerator.java @@ -0,0 +1,21 @@ +package net.pitan76.mcpitanlib.api.util.event; + +import net.minecraft.world.level.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.ItemScattererUtil; +import net.pitan76.mcpitanlib.api.event.block.StateReplacedEvent; + +public class BlockEventGenerator { + public static void onPlaced(Block block, BlockPlacedEvent e) { + block.setPlacedBy(e.world, e.pos, e.state, e.placer, e.stack); + } + + public static void onBreak(Block block, BlockBreakEvent e) { + block.playerWillDestroy(e.world, e.pos, e.state, e.getPlayerEntity()); + } + + public static void onStateReplaced(Block block, StateReplacedEvent e) { + ItemScattererUtil.onStateReplaced(e); + } +} 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..81f428665 --- /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.world.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)); + } +} 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..0a309ddb1 --- /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.world.entity.player.Player; +import net.minecraft.world.Container; +import net.minecraft.world.item.ItemStack; +import net.pitan76.mcpitanlib.api.util.ItemStackUtil; + +public class ClippedInventory implements Container, ICompatInventory { + + private final Container inventory; + private final int start; + private final int end; + + public static ClippedInventory of(Container inventory, int start, int end) { + if (start < 0 || end > inventory.getContainerSize() || start >= end) { + throw new IllegalArgumentException("Invalid start or end indices for clipping inventory."); + } + return new ClippedInventory(inventory, start, end); + } + + public static ClippedInventory of(Container inventory) { + return of(inventory, 0, inventory.getContainerSize()); + } + + public static ClippedInventory of(Container inventory, int start) { + return of(inventory, start, inventory.getContainerSize()); + } + + public ClippedInventory(Container inventory, int start, int end) { + this.inventory = inventory; + this.start = start; + this.end = end; + } + + @Override + public int getContainerSize() { + return end - start; + } + + @Override + public boolean isEmpty() { + for (int i = start; i < end; i++) { + if (!inventory.getItem(i).isEmpty()) { + return false; + } + } + return true; + } + + @Override + public ItemStack getItem(int slot) { + return inventory.getItem(start + slot); + } + + @Override + public ItemStack removeItem(int slot, int amount) { + return inventory.removeItem(start + slot, amount); + } + + @Override + public ItemStack removeItemNoUpdate(int slot) { + return inventory.removeItemNoUpdate(start + slot); + } + + @Override + public void setItem(int slot, ItemStack stack) { + inventory.setItem(start + slot, stack); + } + + @Override + public void setChanged() { + inventory.setChanged(); + } + + @Override + public boolean stillValid(Player player) { + return inventory.stillValid(player); + } + + @Override + public void clearContent() { + for (int i = start; i < end; i++) { + inventory.setItem(i, ItemStackUtil.empty()); + } + } + + @Override + public int getMaxStackSize() { + return inventory.getMaxStackSize(); + } +} 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..b39e393eb --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/inventory/CompatInventory.java @@ -0,0 +1,228 @@ +package net.pitan76.mcpitanlib.api.util.inventory; + +import net.minecraft.world.entity.ContainerUser; +import net.minecraft.world.Container; +import net.minecraft.world.SimpleContainer; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.core.NonNullList; +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.NbtUtil; +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 SimpleContainer implements ICompatInventory { + public CompatInventory(int size) { + super(size); + } + + @Override + public void setItem(int slot, ItemStack stack) { + super.setItem(slot, stack); + } + + /** + * super method of setStack(slot, stack) + */ + public final void superSetStack(int slot, ItemStack stack) { + super.setItem(slot, stack); + } + + /** + * super method of removeStack(slot, amount) + */ + public final ItemStack superRemoveStack(int slot, int amount) { + return super.removeItem(slot, amount); + } + + @Override + public ItemStack removeItem(int slot, int amount) { + return callRemoveStack(slot, amount); + } + + public ItemStack callRemoveStack(int slot, int amount) { + return super.removeItem(slot, amount); + } + + @Override + public ItemStack removeItemNoUpdate(int slot) { + return super.removeItemNoUpdate(slot); + } + + @Override + public ItemStack removeItemType(Item item, int count) { + return super.removeItemType(item, count); + } + + @Deprecated + @Override + public void startOpen(ContainerUser user) { + if (user instanceof Player) { + onOpen(new Player((net.minecraft.world.entity.player.Player) user)); + return; + } + + this.onOpen(new CompatContainerUser(user)); + + } + + @Deprecated + @Override + public void stopOpen(ContainerUser user) { + if (user instanceof Player) { + onClose(new Player((net.minecraft.world.entity.player.Player) user)); + return; + } + + this.onClose(new CompatContainerUser(user)); + } + + // @Deprecated +// public net.minecraft.nbt.NbtList toNbtList(RegistryWrapper.WrapperLookup registries) { +// return toNbtList(new CompatRegistryLookup(registries)).toMinecraft(); +// } +// +// @Deprecated +// public void readNbtList(net.minecraft.nbt.NbtList list, RegistryWrapper.WrapperLookup registries) { +// readNbtList(NbtList.of(list), new CompatRegistryLookup(registries)); +// } + + @Deprecated + @Override + public boolean stillValid(net.minecraft.world.entity.player.Player player) { + return canPlayerUse(new Player(player)); + } + + @Deprecated + @Override + public boolean canAddItem(ItemStack stack) { + return canInsert(new CanInsertArgs(stack)); + } + + public void onOpen(Player player) { + onOpen(new CompatContainerUser(player.getEntity())); + } + + public void onClose(Player player) { + onClose(new CompatContainerUser(player.getEntity())); + } + + public void onOpen(CompatContainerUser user) { + super.startOpen(user.getRaw()); + } + + public void onClose(CompatContainerUser user) { + super.stopOpen(user.getRaw()); + } + + public NbtList toNbtList(CompatRegistryLookup registries) { +// WriteView.ListAppender listAppender = new ListApp +// toDataList(); +// +// super.toDataList(); +// +// return NbtList.of(super.toNbtList(registries.getRegistryLookup())); + return NbtList.of(NbtUtil.createNbtList()); + } + + 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.canAddItem(args.getMcStack()); + } + + @Deprecated + @Override + public List removeAllItems() { + return callClearToList(); + } + + public List callClearToList() { + return super.removeAllItems(); + } + + @Deprecated + @Override + public NonNullList getItems() { + return callGetHeldStacks(); + } + + public NonNullList callGetHeldStacks() { + return super.getItems(); + } + + public ItemStackList callGetHeldStacksAsItemStackList() { + return ItemStackList.of(callGetHeldStacks()); + } + + @Deprecated + @Override + public ItemStack getItem(int slot) { + return callGetStack(slot); + } + + public ItemStack callGetStack(int slot) { + return super.getItem(slot); + } + + @Deprecated + @Override + public int getContainerSize() { + return getSize(); + } + + public int getSize() { + return super.getContainerSize(); + } + + @Deprecated + @Override + public boolean isEmpty() { + return callIsEmpty(); + } + + public boolean callIsEmpty() { + return super.isEmpty(); + } + + @Deprecated + @Override + public boolean canTakeItem(Container hopperInventory, int slot, ItemStack stack) { + return callCanTransferTo(hopperInventory, slot, stack); + } + + public boolean callCanTransferTo(Container hopperInventory, int slot, ItemStack stack) { + return super.canTakeItem(hopperInventory, slot, stack); + } + + @Deprecated + @Override + public ItemStack addItem(ItemStack stack) { + return callAddStack(stack); + } + + public ItemStack callAddStack(ItemStack stack) { + return super.addItem(stack); + } + + @Deprecated + @Override + public int getMaxStackSize() { + return callGetMaxCountPerStack(); + } + + public int callGetMaxCountPerStack() { + return super.getMaxStackSize(); + } +} 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..9bc1e4875 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/inventory/CompatPlayerInventory.java @@ -0,0 +1,87 @@ +package net.pitan76.mcpitanlib.api.util.inventory; + +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.item.ItemStack; +import net.pitan76.mcpitanlib.api.entity.Player; + +public class CompatPlayerInventory implements ICompatInventory { + public Inventory inv; + + public CompatPlayerInventory(Inventory 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.placeItemBackInInventory(stack); + } + + public void offerOrDrop(net.pitan76.mcpitanlib.midohra.item.ItemStack stack) { + offerOrDrop(stack.toMinecraft()); + } + + public Inventory getRaw() { + return inv; + } + + @Override + public int getContainerSize() { + return inv.getContainerSize(); + } + + @Override + public boolean isEmpty() { + return inv.isEmpty(); + } + + @Override + public ItemStack getItem(int slot) { + return inv.getItem(slot); + } + + @Override + public ItemStack removeItem(int slot, int count) { + return inv.removeItem(slot, count); + } + + @Override + public ItemStack removeItemNoUpdate(int slot) { + return inv.removeItemNoUpdate(slot); + } + + @Override + public void setItem(int slot, ItemStack itemStack) { + inv.setItem(slot, itemStack); + } + + @Override + public void setChanged() { + inv.setChanged(); + } + + @Override + public boolean stillValid(net.minecraft.world.entity.player.Player player) { + return inv.stillValid(player); + } + + @Override + public void clearContent() { + inv.clearContent(); + } +} + 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..0dde151dc --- /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.world.inventory.AbstractContainerMenu; + +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..7ada44471 --- /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.world.Container; +import net.minecraft.world.item.ItemStack; +import net.pitan76.mcpitanlib.api.entity.Player; + +public interface ICompatInventory extends Container { + default void callSetStack(int slot, ItemStack stack) { + setItem(slot, stack); + } + + default ItemStack callGetStack(int slot) { + return getItem(slot); + } + + default int callSize() { + return getContainerSize(); + } + + default boolean callIsEmpty() { + return isEmpty(); + } + + default ItemStack callRemoveStack(int slot, int amount) { + return removeItem(slot, amount); + } + + default ItemStack callRemoveStack(int slot) { + return removeItemNoUpdate(slot); + } + + default void callClear() { + clearContent(); + } + + default void callMarkDirty() { + setChanged(); + } + + default boolean callCanPlayerUse(net.minecraft.world.entity.player.Player player) { + return stillValid(player); + } + + default boolean canPlayerUse(Player player) { + return stillValid(player.getEntity()); + } + + + default void callSetStack(int slot, net.pitan76.mcpitanlib.midohra.item.ItemStack stack) { + setItem(slot, stack.toMinecraft()); + } + + default net.pitan76.mcpitanlib.midohra.item.ItemStack callGetStackAsMidohra(int slot) { + return net.pitan76.mcpitanlib.midohra.item.ItemStack.of(getItem(slot)); + } + + default int callGetMaxCountPerStack() { + return getMaxStackSize(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/inventory/InventoryWrapper.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/inventory/InventoryWrapper.java new file mode 100644 index 000000000..5c9dab56b --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/inventory/InventoryWrapper.java @@ -0,0 +1,66 @@ +package net.pitan76.mcpitanlib.api.util.inventory; + +import net.minecraft.world.Container; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; + +public class InventoryWrapper implements ICompatInventory { + private final Container inventory; + + public InventoryWrapper(Container inventory) { + this.inventory = inventory; + } + + public static InventoryWrapper of(Container inventory) { + return new InventoryWrapper(inventory); + } + + public Container getInventory() { + return inventory; + } + + @Override + public int getContainerSize() { + return inventory.getContainerSize(); + } + + @Override + public boolean isEmpty() { + return inventory.isEmpty(); + } + + @Override + public ItemStack getItem(int slot) { + return inventory.getItem(slot); + } + + @Override + public ItemStack removeItem(int slot, int count) { + return inventory.removeItem(slot, count); + } + + @Override + public ItemStack removeItemNoUpdate(int slot) { + return inventory.removeItemNoUpdate(slot); + } + + @Override + public void setItem(int slot, ItemStack itemStack) { + inventory.setItem(slot, itemStack); + } + + @Override + public void setChanged() { + inventory.setChanged(); + } + + @Override + public boolean stillValid(Player player) { + return inventory.stillValid(player); + } + + @Override + public void clearContent() { + inventory.clearContent(); + } +} 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..0e739ff14 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/inventory/PlayerInventoryUtil.java @@ -0,0 +1,47 @@ +package net.pitan76.mcpitanlib.api.util.inventory; + +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.item.ItemStack; +import net.minecraft.core.NonNullList; +import net.pitan76.mcpitanlib.api.entity.Player; + +public class PlayerInventoryUtil { + public static Player getPlayer(Inventory playerInventory) { + return new Player(playerInventory.player); + } + + public static int getSelectedSlot(Inventory playerInventory) { + return playerInventory.getSelectedSlot(); + } + + public static void setSelectedSlot(Inventory playerInventory, int slot) { + playerInventory.setSelectedSlot(slot); + } + + public static void dropAllItems(Inventory inv) { + inv.dropAll(); + } + + public static NonNullList getMain(Inventory inv) { + return inv.getNonEquipmentItems(); + } + + public static NonNullList getArmor(Inventory inv) { + NonNullList stacks = NonNullList.withSize(4, ItemStack.EMPTY); + stacks.set(0, inv.getItem(36)); + stacks.set(1, inv.getItem(37)); + stacks.set(2, inv.getItem(38)); + stacks.set(3, inv.getItem(39)); + return stacks; + } + + public static NonNullList getOffHand(Inventory inv) { + NonNullList stacks = NonNullList.withSize(1, ItemStack.EMPTY); + stacks.set(0, inv.getItem(Inventory.SLOT_OFFHAND)); + return stacks; + } + + public static ItemStack getMainHandStack(Inventory inv) { + return inv.player.getMainHandItem(); + } +} 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..b6271d19a --- /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.world.item.ItemStack stack) { + this(ItemStack.of(stack)); + } + + public ItemStack getStack() { + return stack; + } + + public net.minecraft.world.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..4d396dc50 --- /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.world.item.ItemStack; +import net.minecraft.world.level.Level; +import net.pitan76.mcpitanlib.core.registry.FuelRegistry; + +public class FuelUtil { + + public static int getTime(Level world, ItemStack stack) { + return FuelRegistry.get(world, stack); + } + + public static boolean isFuel(Level 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..b3a599a2e --- /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.world.item.CreativeModeTab; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.resources.Identifier; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; + +public class ItemGroupUtil { + public static Identifier toID(CreativeModeTab itemGroup) { + return BuiltInRegistries.CREATIVE_MODE_TAB.getKey(itemGroup); + } + + public static CreativeModeTab fromId(Identifier identifier) { + return BuiltInRegistries.CREATIVE_MODE_TAB.getValue(identifier); + } + + public static boolean isExist(Identifier identifier) { + return BuiltInRegistries.CREATIVE_MODE_TAB.containsKey(identifier); + } + + public static CompatIdentifier toCompatID(CreativeModeTab itemGroup) { + return CompatIdentifier.fromMinecraft(toID(itemGroup)); + } + + public static CreativeModeTab fromId(CompatIdentifier identifier) { + return fromId(identifier.toMinecraft()); + } + + public static boolean isExist(CompatIdentifier identifier) { + return isExist(identifier.toMinecraft()); + } + + public static int getRawId(CreativeModeTab itemGroup) { + return BuiltInRegistries.CREATIVE_MODE_TAB.getId(itemGroup); + } + + public static CreativeModeTab fromIndex(int index) { + return BuiltInRegistries.CREATIVE_MODE_TAB.byId(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..9b9c0348e --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/item/ItemUtil.java @@ -0,0 +1,266 @@ +package net.pitan76.mcpitanlib.api.util.item; + +import net.minecraft.world.level.block.Block; +import net.minecraft.world.item.BlockItem; +import net.minecraft.world.item.Item; +import net.minecraft.world.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(ItemStackUtil.getDefaultStack(item)).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(ItemStackUtil.getDefaultStack(item))); + } + + /** + * Get translation key of the item. + * @param item Item + * @return Translation key of the item. + */ + public static String getTranslationKey(Item item) { + return item.getDescriptionId(); + } + + public static boolean hasRecipeRemainder(Item item) { + return !ItemStackUtil.isEmpty(getRecipeRemainderStack(item)); + } + + public static Item getRecipeRemainder(Item item) { + return getRecipeRemainderStack(item).getItem(); + } + + public static ItemStack getRecipeRemainderStack(Item item) { + if (item.getCraftingRemainder() == null) + return ItemStackUtil.empty(); + + return item.getCraftingRemainder().create(); + } +} 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..8f353a8f0 --- /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.world.level.block.Rotation; +import net.pitan76.mcpitanlib.api.util.math.random.CompatRandom; + +public class BlockRotations { + public static Rotation NONE = Rotation.NONE; + public static Rotation CLOCKWISE_90 = Rotation.CLOCKWISE_90; + public static Rotation CLOCKWISE_180 = Rotation.CLOCKWISE_180; + public static Rotation COUNTERCLOCKWISE_90 = Rotation.COUNTERCLOCKWISE_90; + + public static Rotation rotate(Rotation rotation, Rotation rotation2) { + return rotation.getRotated(rotation2); + } + + public static Rotation random(CompatRandom random) { + return Rotation.getRandom(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..148375778 --- /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.core.BlockPos; +import net.minecraft.world.phys.AABB; + +public class BoxUtil { + public static AABB createBox(double x1, double y1, double z1, double x2, double y2, double z2) { + return new AABB(x1, y1, z1, x2, y2, z2); + } + + public static AABB createBox(double x, double y, double z, double size) { + return new AABB(x, y, z, x + size, y + size, z + size); + } + + public static AABB createBox(double size) { + return new AABB(0, 0, 0, size, size, size); + } + + public static AABB createBox(double x1, double y1, double z1, double x2, double y2, double z2, double size) { + return new AABB(x1, y1, z1, x2 + size, y2 + size, z2 + size); + } + + public static AABB createBox(BlockPos pos) { + return new AABB(pos); + } + + public static AABB createBox(BlockPos pos1, BlockPos pos2) { + return new AABB(pos1.getCenter(), pos2.getCenter()); + } + + public static AABB createBox(BlockPos pos, int size) { + return createBox(pos, pos.offset(size, size, size)); + } + + public static AABB createBox(BlockPos pos, int sizeX, int sizeY, int sizeZ) { + return createBox(pos, pos.offset(sizeX, sizeY, sizeZ)); + } + + public static AABB createBoxCenter(BlockPos pos, int size) { + return createBox(pos.offset(-size, -size, -size), pos.offset(size, size, size)); + } + + public static AABB expand(AABB box, double x, double y, double z) { + return new AABB(box.minX - x, box.minY - y, box.minZ - z, box.maxX + x, box.maxY + y, box.maxZ + z); + } + + public static AABB expand(AABB box, double size) { + return expand(box, size, size, size); + } + + public static AABB union(AABB box1, AABB box2) { + return box1.minmax(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..33d3c7149 --- /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.core.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/MathUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/math/MathUtil.java new file mode 100644 index 000000000..aa3f34151 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/math/MathUtil.java @@ -0,0 +1,41 @@ +package net.pitan76.mcpitanlib.api.util.math; + +import net.minecraft.util.Mth; + +public class MathUtil { + public static double clamp(double value, double min, double max) { + return Mth.clamp(value, min, max); + } + + public static float clamp(float value, float min, float max) { + return Mth.clamp(value, min, max); + } + + public static int clamp(int value, int min, int max) { + return Mth.clamp(value, min, max); + } + + public static long clamp(long value, long min, long max) { + return Mth.clamp(value, min, max); + } + + public static double lerp(double a, double b, double t) { + return Mth.lerp(t, a, b); + } + + public static float lerp(float a, float b, float t) { + return Mth.lerp(t, a, b); + } + + public static double inverseLerp(double a, double b, double value) { + return Mth.inverseLerp(a, b, value); + } + + public static int hsvToRgb(float hue, float saturation, float value) { + return Mth.hsvToRgb(hue, saturation, value); + } + + public static float hsvToArgb(float hue, float saturation, float value, int alpha) { + return Mth.hsvToArgb(hue, saturation, value, alpha); + } +} 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..a205b2958 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/math/PosUtil.java @@ -0,0 +1,120 @@ +package net.pitan76.mcpitanlib.api.util.math; + +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.core.Position; +import net.minecraft.core.Vec3i; +import net.minecraft.world.phys.Vec3; + +public class PosUtil { + public static BlockPos flooredBlockPos(double x, double y, double z) { + return BlockPos.containing(x, y, z); + } + + public static BlockPos flooredBlockPos(Position pos) { + return BlockPos.containing(pos); + } + + public static BlockPos flooredBlockPos(Vec3 pos) { + return BlockPos.containing(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.distSqr(pos2); + } + + public static double getSquaredDistance(BlockPos pos1, double x, double y, double z) { + return pos1.distToLowCornerSqr(x, y, z); + } + + public static Iterable iterate(BlockPos start, BlockPos end) { + return BlockPos.betweenClosed(start, end); + } + + public static BlockPos[] getNeighborPoses(BlockPos pos) { + return new BlockPos[]{pos.north(), pos.south(), pos.east(), pos.west(), pos.above(), pos.below()}; + } + + public static BlockPos up(BlockPos pos) { + return pos.above(); + } + + public static BlockPos down(BlockPos pos) { + return pos.below(); + } + + 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.offset(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.relative(direction); + } + + public static BlockPos offset(BlockPos pos, Direction direction, int n) { + return pos.relative(direction, n); + } + + public static BlockPos offset(BlockPos pos, net.pitan76.mcpitanlib.midohra.util.math.Direction direction) { + return pos.relative(direction.toMinecraft()); + } + + public static BlockPos offset(BlockPos pos, net.pitan76.mcpitanlib.midohra.util.math.Direction direction, int n) { + return pos.relative(direction.toMinecraft(), n); + } + + public static BlockPos toImmutable(BlockPos pos) { + return pos.immutable(); + } + + public static long asLong(BlockPos pos) { + return pos.asLong(); + } +} 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..d456301b6 --- /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.world.phys.Vec3; + +public class Vec3dUtil { + public static Vec3 create(double x, double y, double z) { + return new Vec3(x, y, z); + } + + public static Vec3 add(Vec3 a, Vec3 b) { + return a.add(b); + } + + public static Vec3 subtract(Vec3 a, Vec3 b) { + return a.subtract(b); + } + + public static Vec3 multiply(Vec3 a, double b) { + return a.scale(b); + } + + public static Vec3 divide(Vec3 a, double b) { + return a.scale(1.0D / b); + } + + public static double dot(Vec3 a, Vec3 b) { + return a.dot(b); + } + + public static Vec3 cross(Vec3 a, Vec3 b) { + return a.cross(b); + } + + public static Vec3 normalize(Vec3 a) { + return a.normalize(); + } + + public static Vec3 rotateX(Vec3 a, float angle) { + return a.xRot(angle); + } + + public static Vec3 rotateY(Vec3 a, float angle) { + return a.yRot(angle); + } + + public static Vec3 rotateZ(Vec3 a, float angle) { + return a.zRot(angle); + } + + public static Vec3 add(Vec3 a, double x, double y, double z) { + return a.add(x, y, z); + } + + public static Vec3 subtract(Vec3 a, double x, double y, double z) { + return a.subtract(x, y, z); + } + + public static Vec3 multiply(Vec3 a, double x, double y, double z) { + return a.multiply(x, y, z); + } + + public static double distanceTo(Vec3 a, Vec3 b) { + return a.distanceTo(b); + } + + public static Vec3 ofCenter(double x, double y, double z) { + return new Vec3(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..fdfc48af9 --- /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.core.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.offset(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.cross(b); + } + + public static Vec3i add(Vec3i a, int x, int y, int z) { + return a.offset(x, y, z); + } + + public static Vec3i subtract(Vec3i a, int x, int y, int z) { + return a.offset(-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..0b1c167e4 --- /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.RandomSource mcRandom; + + public CompatRandom(java.util.Random javaRandom) { + this.javaRandom = javaRandom; + } + + public CompatRandom(net.minecraft.util.RandomSource mcRandom) { + this.mcRandom = mcRandom; + } + + @Deprecated + public CompatRandom() { + this.mcRandom = net.minecraft.util.RandomSource.create(); + } + + @Deprecated + public CompatRandom(long seed) { + this.mcRandom = net.minecraft.util.RandomSource.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.consumeCount(count); + } + } + + public void split() { + if (javaRandom != null) { + javaRandom.nextInt(); + } else { + mcRandom.fork(); + } + } + + 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.RandomSource 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..40a9f6274 --- /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.world.ContainerHelper; +import net.minecraft.world.item.ItemStack; +import net.minecraft.core.NonNullList; +import net.pitan76.mcpitanlib.api.event.nbt.ReadNbtArgs; +import net.pitan76.mcpitanlib.api.event.nbt.WriteNbtArgs; +import net.pitan76.mcpitanlib.api.util.collection.ItemStackList; + +public class InvRWUtil { + public static void putInv(WriteNbtArgs args, NonNullList stacks) { + ContainerHelper.saveAllItems(args.view, stacks); + } + + public static void getInv(ReadNbtArgs args, NonNullList stacks) { + ContainerHelper.loadAllItems(args.view, stacks); + } + + public static void putInv(WriteNbtArgs args, ItemStackList stacks) { + putInv(args, (NonNullList) stacks); + } + + public static void getInv(ReadNbtArgs args, ItemStackList stacks) { + getInv(args, (NonNullList) 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..7d2f7411d --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/nbt/NbtListUtil.java @@ -0,0 +1,88 @@ +package net.pitan76.mcpitanlib.api.util.nbt; + +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.Tag; +import net.minecraft.nbt.ListTag; +import net.pitan76.mcpitanlib.api.util.NbtUtil; + +import java.util.Optional; +import java.util.stream.Stream; + +public class NbtListUtil { + public static ListTag create() { + return NbtUtil.createNbtList(); + } + + public static ListTag copy(ListTag list) { + return list.copy(); + } + + public static Stream stream(ListTag list) { + return list.stream(); + } + + public static Optional getStringOptional(ListTag list, int index) { + return list.getString(index); + } + + public static Tag get(ListTag list, int index) { + return list.get(index); + } + + public static Tag getOrDefault(ListTag list, int index, Tag defaultValue) { + Tag nbt = get(list, index); + return nbt == null ? defaultValue : nbt; + } + + public static void set(ListTag list, int index, Tag value) { + list.set(index, value); + } + + public static void add(ListTag list, Tag value) { + list.add(value); + } + + public static void set(ListTag list, int index, String value) { + set(list, index, NbtUtil.createString(value)); + } + + public static boolean has(ListTag list, Tag value) { + return list.contains(value); + } + + public static int size(ListTag list) { + return list.size(); + } + + public static void remove(ListTag list, int index) { + list.remove(index); + } + + public static void clear(ListTag list) { + list.clear(); + } + + public static boolean isEmpty(ListTag list) { + return list.isEmpty(); + } + + public static String getString(ListTag list, int index) { + return getStringOptional(list, index).orElse(""); + } + + public static void setString(ListTag list, int index, String value) { + list.set(index, NbtUtil.createString(value)); + } + + public static void addString(ListTag list, String value) { + list.add(NbtUtil.createString(value)); + } + + public static ListTag getList(ListTag list, int index) { + return list.getList(index).orElse(create()); + } + + public static CompoundTag getCompound(ListTag list, int index) { + return list.getCompound(index).orElse(NbtUtil.create()); + } +} 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..cd28a9219 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/nbt/NbtRWUtil.java @@ -0,0 +1,141 @@ +package net.pitan76.mcpitanlib.api.util.nbt; + +import net.minecraft.nbt.CompoundTag; +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) { + args.view.putBoolean(key, value); + } + + public static boolean getBoolean(ReadNbtArgs args, String key) { + return args.view.getBooleanOr(key, false); + } + + public static void putByte(WriteNbtArgs args, String key, byte value) { + args.view.putByte(key, value); + } + + public static byte getByte(ReadNbtArgs args, String key) { + return args.view.getByteOr(key, (byte) 0); + } + + public static void putInt(WriteNbtArgs args, String key, int value) { + args.view.putInt(key, value); + } + + public static int getInt(ReadNbtArgs args, String key) { + return args.view.getIntOr(key, 0); + } + + public static void putLong(WriteNbtArgs args, String key, long value) { + args.view.putLong(key, value); + } + + public static long getLong(ReadNbtArgs args, String key) { + return args.view.getLongOr(key, 0L); + } + + public static void putShort(WriteNbtArgs args, String key, short value) { + args.view.putShort(key, value); + } + + public static short getShort(ReadNbtArgs args, String key) { + return (short) args.view.getShortOr(key, (short) 0); + } + + public static void putFloat(WriteNbtArgs args, String key, float value) { + args.view.putFloat(key, value); + } + + public static float getFloat(ReadNbtArgs args, String key) { + return args.view.getFloatOr(key, 0.0f); + } + + public static void putDouble(WriteNbtArgs args, String key, double value) { + args.view.putDouble(key, value); + } + + public static double getDouble(ReadNbtArgs args, String key) { + return args.view.getDoubleOr(key, 0.0); + } + + public static void putString(WriteNbtArgs args, String key, String value) { + args.view.putString(key, value); + } + + public static String getString(ReadNbtArgs args, String key) { + return args.view.getStringOr(key, ""); + } + + public static void putIntArray(WriteNbtArgs args, String key, int[] value) { + args.view.putIntArray(key, value); + } + + public static int[] getIntArray(ReadNbtArgs args, String key) { + return args.view.getIntArray(key).orElse(new int[0]); + } + + public static boolean getBooleanOrDefault(ReadNbtArgs args, String key, boolean defaultValue) { + return args.view.getBooleanOr(key, defaultValue); + } + + public static byte getByteOrDefault(ReadNbtArgs args, String key, byte defaultValue) { + return args.view.getByteOr(key, defaultValue); + } + + public static int getIntOrDefault(ReadNbtArgs args, String key, int defaultValue) { + return args.view.getIntOr(key, defaultValue); + } + + public static long getLongOrDefault(ReadNbtArgs args, String key, long defaultValue) { + return args.view.getLongOr(key, defaultValue); + } + + public static short getShortOrDefault(ReadNbtArgs args, String key, short defaultValue) { + return (short) args.view.getShortOr(key, defaultValue); + } + + public static float getFloatOrDefault(ReadNbtArgs args, String key, float defaultValue) { + return args.view.getFloatOr(key, defaultValue); + } + + public static double getDoubleOrDefault(ReadNbtArgs args, String key, double defaultValue) { + return args.view.getDoubleOr(key, defaultValue); + } + + public static String getStringOrDefault(ReadNbtArgs args, String key, String defaultValue) { + return args.view.getStringOr(key, defaultValue); + } + + public static int[] getIntArrayOrDefault(ReadNbtArgs args, String key, int[] defaultValue) { + return args.view.getIntArray(key).orElse(defaultValue); + } + + public static boolean isEmpty(NbtRWArgs args) { + if (args instanceof WriteNbtArgs) + return ((WriteNbtArgs) args).view.isEmpty(); + else + return true; + } + + 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, CompoundTag other) { + args.view.store(key, CompoundTag.CODEC, other); + } + + public static CompoundTag getCompound(ReadNbtArgs args, String key) { + return args.view.read(key, CompoundTag.CODEC).orElse(NbtUtil.create()); + } +} 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..191836d18 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/nbt/v2/NbtRWUtil.java @@ -0,0 +1,126 @@ +package net.pitan76.mcpitanlib.api.util.nbt.v2; + +import net.minecraft.world.item.ItemStack; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.level.storage.TagValueOutput; +import net.minecraft.world.level.storage.ValueInput; +import net.minecraft.util.ProblemReporter; +import net.minecraft.world.phys.Vec3; +import net.minecraft.core.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.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) { + TagValueOutput view = _view(registryLookup); + return new WriteNbtArgs(view.buildResult(), view, registryLookup); + } + + public static WriteNbtArgs create() { + return create(null); + } + + public static void put(WriteNbtArgs parent, WriteNbtArgs child, String key) { + if (child.view instanceof TagValueOutput childView) + parent.view.store(key, CompoundTag.CODEC, childView.buildResult()); + } + + public static WriteNbtArgs putWithCreate(WriteNbtArgs parent, String key) { + TagValueOutput subView = _view(parent.registryLookup); + parent.view.store(key, CompoundTag.CODEC, subView.buildResult()); + return new WriteNbtArgs(subView.buildResult(), subView, parent.registryLookup); + } + + public static ReadNbtArgs get(ReadNbtArgs parent, String key) { + ValueInput view = parent.view.childOrEmpty(key); + return new ReadNbtArgs(null, view, parent.registryLookup); + } + + public static ReadNbtArgs getOrDefault(ReadNbtArgs parent, String key, ReadNbtArgs defaultValue) { + Optional view = parent.view.child(key); + return view.map(readView -> new ReadNbtArgs(null, readView, parent.registryLookup)).orElse(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 Vec3 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.core.BlockPos pos) { + putPos3i(args, key, PosUtil.x(pos), PosUtil.y(pos), PosUtil.z(pos)); + } + + public static net.minecraft.core.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); + } + + private static TagValueOutput _view(CompatRegistryLookup registryLookup) { + return TagValueOutput.createWithContext(ProblemReporter.DISCARDING, registryLookup.getRegistryLookup()); + } + + public static void putItemStack(WriteNbtArgs args, String key, ItemStack stack) { + args.view.store(key, ItemStack.CODEC, stack); + } + + public static Optional getItemStack(ReadNbtArgs args, String key) { + return args.view.read(key, ItemStack.CODEC); + } +} 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..d6b69364e --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/particle/CompatParticleType.java @@ -0,0 +1,47 @@ +package net.pitan76.mcpitanlib.api.util.particle; + +import net.minecraft.core.particles.ParticleType; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.resources.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.getOverrideLimiter(); + } + + public Identifier getId() { + return BuiltInRegistries.PARTICLE_TYPE.getKey(particleType); + } + + public CompatIdentifier getCompatId() { + return CompatIdentifier.fromMinecraft(getId()); + } + + @Override + public int hashCode() { + return particleType.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + CompatParticleType other = (CompatParticleType) obj; + return particleType.equals(other.particleType); + } +} 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..03042c58f --- /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.core.particles.ParticleTypes; + +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.COPPER_FIRE_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.PALE_OAK_LEAVES); + public static final CompatParticleType TINTED_LEAVES = new CompatParticleType(ParticleTypes.TINTED_LEAVES); + 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.TRAIL); + 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_DETECTED_PLAYER); + public static final CompatParticleType TRIAL_SPAWNER_DETECTION_OMINOUS = new CompatParticleType(ParticleTypes.TRIAL_SPAWNER_DETECTED_PLAYER_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_CRUMBLE); + public static final CompatParticleType FIREFLY = new CompatParticleType(ParticleTypes.FIREFLY); +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/particle/effect/CompatItemStackParticleEffect.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/particle/effect/CompatItemStackParticleEffect.java new file mode 100644 index 000000000..bc63b10e5 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/particle/effect/CompatItemStackParticleEffect.java @@ -0,0 +1,58 @@ +package net.pitan76.mcpitanlib.api.util.particle.effect; + +import net.minecraft.core.particles.ItemParticleOption; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.ItemStackTemplate; +import net.pitan76.mcpitanlib.api.util.ItemStackUtil; +import net.pitan76.mcpitanlib.api.util.ParticleEffectUtil; +import net.pitan76.mcpitanlib.midohra.item.ItemWrapper; + +public class CompatItemStackParticleEffect extends CompatParticleEffect { + @Deprecated + public CompatItemStackParticleEffect(ItemParticleOption effect) { + super(effect); + } + + public CompatItemStackParticleEffect(ItemStack stack) { + this(ParticleEffectUtil.itemStack.createTypedItem(stack)); + } + + @Deprecated + public static CompatItemStackParticleEffect of(ItemParticleOption effect) { + return new CompatItemStackParticleEffect(effect); + } + + public static CompatItemStackParticleEffect of(ItemStack stack) { + return new CompatItemStackParticleEffect(stack); + } + + public static CompatItemStackParticleEffect of(net.pitan76.mcpitanlib.midohra.item.ItemStack stack) { + return new CompatItemStackParticleEffect(stack.toMinecraft()); + } + + public static CompatItemStackParticleEffect of(CompatParticleEffect effect) { + if (effect.getRaw() instanceof ItemParticleOption itemEffect) { + return new CompatItemStackParticleEffect(itemEffect); + } + throw new IllegalArgumentException("The provided particle effect is not an ItemParticleOption."); + } + + public static CompatItemStackParticleEffect of(Item item) { + return new CompatItemStackParticleEffect(ItemStackUtil.create(item)); + } + + public static CompatItemStackParticleEffect of(ItemWrapper item) { + return of(item.get()); + } + + public ItemStack getStack() { + ItemParticleOption itemEffect = (ItemParticleOption) getRaw(); + ItemStackTemplate template = itemEffect.getItem(); + return template.create(); + } + + public net.pitan76.mcpitanlib.midohra.item.ItemStack getStackM() { + return net.pitan76.mcpitanlib.midohra.item.ItemStack.of(getStack()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/particle/effect/CompatParticleEffect.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/particle/effect/CompatParticleEffect.java new file mode 100644 index 000000000..51967cdf4 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/particle/effect/CompatParticleEffect.java @@ -0,0 +1,45 @@ +package net.pitan76.mcpitanlib.api.util.particle.effect; + +import net.minecraft.core.particles.ParticleOptions; +import net.pitan76.mcpitanlib.api.util.particle.CompatParticleType; + +public class CompatParticleEffect { + private final ParticleOptions effect; + + @Deprecated + public CompatParticleEffect(ParticleOptions effect) { + this.effect = effect; + } + + @Deprecated + public static CompatParticleEffect of(ParticleOptions effect) { + return new CompatParticleEffect(effect); + } + + public static CompatParticleEffect of(CompatParticleType type) { + ParticleOptions options = type::getRaw; + return new CompatParticleEffect(options); + } + + @Deprecated + public ParticleOptions getRaw() { + return effect; + } + + public CompatParticleType getType() { + return CompatParticleType.of(getRaw().getType()); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + CompatParticleEffect other = (CompatParticleEffect) obj; + return getRaw().equals(other.getRaw()); + } + + @Override + public int hashCode() { + return getRaw().hashCode(); + } +} 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..a5aeb00b6 --- /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.world.item.ItemStack; +import net.minecraft.core.particles.ItemParticleOption; +import net.minecraft.core.particles.ParticleType; +import net.minecraft.core.particles.ParticleTypes; + +// Use: ParticleEffectUtil +public class ItemStackParticleEffectUtil { + + public ItemStackParticleEffectUtil() { + // Empty constructor + } + + public ItemParticleOption create(ParticleType type, ItemStack stack) { + return new ItemParticleOption(type, stack.getItem()); + } + + public ItemParticleOption createTypedItem(ItemStack stack) { + return new ItemParticleOption(ParticleTypes.ITEM, stack.getItem()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/recipe/CraftingRecipeUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/recipe/CraftingRecipeUtil.java new file mode 100644 index 000000000..d7068de66 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/recipe/CraftingRecipeUtil.java @@ -0,0 +1,67 @@ +package net.pitan76.mcpitanlib.api.util.recipe; + +import net.minecraft.world.level.Level; +import net.pitan76.mcpitanlib.api.util.LoggerUtil; +import net.pitan76.mcpitanlib.midohra.item.ItemStack; +import net.pitan76.mcpitanlib.midohra.recipe.CraftingRecipe; +import net.pitan76.mcpitanlib.midohra.recipe.ShapedRecipe; +import net.pitan76.mcpitanlib.midohra.recipe.ShapelessRecipe; +import net.pitan76.mcpitanlib.midohra.recipe.entry.RecipeEntry; +import net.pitan76.mcpitanlib.midohra.recipe.input.CraftingRecipeInputOrInventory; +import net.pitan76.mcpitanlib.midohra.world.ServerWorld; +import net.pitan76.mcpitanlib.midohra.world.World; +import org.jetbrains.annotations.Nullable; + +import java.util.Collection; +import java.util.stream.Collectors; + +public class CraftingRecipeUtil { + @Nullable + public static ItemStack getOutput(CraftingRecipe recipe, CraftingRecipeInputOrInventory input, World world) { + if (recipe instanceof ShapedRecipe || recipe instanceof ShapelessRecipe) { + return recipe.getOutputMidohra(input, world); + } else { + try { + return recipe.getOutputMidohra(input, world); + } catch (ArrayIndexOutOfBoundsException e) { + String id = "Unknown recipe"; + for (RecipeEntry entry : RecipeUtil.getRecipeEntries(world)) { + if (entry.getRawRecipe() == recipe.getRaw()) { + id = entry.getId().toString(); + break; + } + } + + LoggerUtil.getLogger().error("{}: {}", e.getMessage(), id); + return null; + } catch (Exception ignored) { + return null; + } + } + } + + public static net.minecraft.world.item.ItemStack getOutputRaw(CraftingRecipe recipe, CraftingRecipeInputOrInventory input, Level world) { + return getOutput(recipe, input, World.of(world)).toMinecraft(); + } + + public static Collection getCraftingRecipes(ServerWorld world) { + try { + return RecipeUtil.getCraftingRecipes(world).stream().map( + recipe -> { + if (recipe instanceof ShapedRecipe || recipe instanceof ShapelessRecipe) + return recipe; + + if (recipe.getRaw() instanceof net.minecraft.world.item.crafting.ShapedRecipe) + return ShapedRecipe.of((net.minecraft.world.item.crafting.ShapedRecipe) recipe.getRaw()); + + if (recipe.getRaw() instanceof net.minecraft.world.item.crafting.ShapelessRecipe) + return ShapelessRecipe.of((net.minecraft.world.item.crafting.ShapelessRecipe) recipe.getRaw()); + + return recipe; + } + ).collect(Collectors.toList()); + } catch (Exception e) { + return RecipeUtil.getCraftingRecipes(world); + } + } +} 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..60b2838fc --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/recipe/RecipeMatcherUtil.java @@ -0,0 +1,43 @@ +package net.pitan76.mcpitanlib.api.util.recipe; + +import it.unimi.dsi.fastutil.ints.IntList; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.Recipe; +import net.minecraft.world.entity.player.StackedContents; +import net.pitan76.mcpitanlib.api.recipe.CompatibleRecipeEntry; +import net.pitan76.mcpitanlib.api.util.ItemStackUtil; +import net.pitan76.mcpitanlib.api.util.ItemUtil; + +public class RecipeMatcherUtil { + public static ItemStack getStackFromId(int itemId) { + return ItemStackUtil.create(ItemUtil.fromIndex(itemId)); + } + + public static int getItemId(ItemStack stack) { + return ItemUtil.getRawId(stack.getItem()); + } + + public static boolean match(StackedContents matcher, CompatibleRecipeEntry entry, IntList output) { + return match(matcher, entry.getRecipe(), output); + } + + public static boolean match(StackedContents matcher, CompatibleRecipeEntry entry, IntList output, int multiplier) { + return match(matcher, entry.getRecipe(), output, multiplier); + } + + @Deprecated + public static boolean match(StackedContents matcher, Recipe recipe, IntList output) { + return false; + //return matcher.match(recipe, output); + } + + @Deprecated + public static boolean match(StackedContents matcher, Recipe recipe, IntList output, int multiplier) { + return false; + //return matcher.match(recipe, output, multiplier); + } + + public static void clear(StackedContents 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..d4c7ed609 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/recipe/RecipeUtil.java @@ -0,0 +1,101 @@ +package net.pitan76.mcpitanlib.api.util.recipe; + +import net.minecraft.world.item.crafting.Recipe; +import net.minecraft.world.item.crafting.RecipeType; +import net.minecraft.world.item.crafting.RecipeManager; +import net.minecraft.world.level.Level; +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(Level world) { + Collection> recipes = new ArrayList<>(); + + for (net.minecraft.world.item.crafting.RecipeHolder entry : getMCRecipeEntries(world)) { + recipes.add(entry.value()); + } + + return recipes; + } + + public static Collection> getMCRecipeEntries(Level world) { + if (world.recipeAccess() instanceof RecipeManager) { + return ((RecipeManager) world.recipeAccess()).getRecipes(); + } + + // Client is not supported... TODO: Implement client support for 1.21.3~ + return new ArrayList<>(); + } + + public static Collection getRecipes(Level world) { + List recipes = new ArrayList<>(); + + for (net.minecraft.world.item.crafting.RecipeHolder entry : getMCRecipeEntries(world)) { + recipes.add(new CompatRecipe(entry)); + } + + return recipes; + } + + public static Collection getRecipesByType(Level world, RecipeType type) { + List recipes = new ArrayList<>(); + + for (net.minecraft.world.item.crafting.RecipeHolder 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.world.item.crafting.RecipeHolder entry : getMCRecipeEntries(world.getRaw())) { + entries.add(RecipeEntry.of(entry.value(), CompatIdentifier.fromMinecraft(entry.id().identifier()))); + } + + 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.world.item.crafting.CraftingRecipe) { + recipes.add(CraftingRecipe.of((net.minecraft.world.item.crafting.CraftingRecipe) recipe.getRecipe())); + } + } + + return recipes; + } + + public static Collection getCraftingRecipeEntries(net.pitan76.mcpitanlib.midohra.world.World world) { + List entries = new ArrayList<>(); + + for (net.minecraft.world.item.crafting.RecipeHolder entry : getMCRecipeEntries(world.getRaw())) { + if (entry.value() instanceof net.minecraft.world.item.crafting.CraftingRecipe) { + entries.add(CraftingRecipeEntry.of((net.minecraft.world.item.crafting.CraftingRecipe) entry.value(), CompatIdentifier.fromMinecraft(entry.id().identifier()))); + } + } + + 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..f5c8a5774 --- /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.world.item.ItemStack; +import net.minecraft.world.entity.player.StackedItemContents; +import net.minecraft.world.item.crafting.CraftingInput; +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 CraftingInput) { + return Optional.of((CraftingInput) input.getInput()); + } + return Optional.empty(); + } + + public static CompatRecipeInput create(CraftingInput input) { + return new CompatRecipeInput<>(input); + } + + public static CompatRecipeInput create(int width, int height, List stacks) { + return new CompatRecipeInput<>(CraftingInput.of(width, height, stacks)); + } + + public static ItemStack getStack(CraftingInput input, int x, int y) { + return input.getItem(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 StackedItemContents getRecipeMatcher(CraftingInput input) { + return input.stackedContents(); + } + + public static StackedItemContents getRecipeMatcher(CompatRecipeInput input) { + Optional recipeInput = get(input); + if (!recipeInput.isPresent()) return null; + + return getRecipeMatcher(recipeInput.get()); + } + + public static List getStacks(CraftingInput input) { + return input.items(); + } + + public static List getStacks(CompatRecipeInput input) { + Optional recipeInput = get(input); + if (!recipeInput.isPresent()) return null; + + return getStacks(recipeInput.get()); + } + + public static int getWidth(CraftingInput input) { + return input.width(); + } + + public static int getWidth(CompatRecipeInput input) { + Optional recipeInput = get(input); + if (!recipeInput.isPresent()) return -1; + + return getWidth(recipeInput.get()); + } + + public static int getHeight(CraftingInput input) { + return input.height(); + } + + public static int getHeight(CompatRecipeInput input) { + Optional recipeInput = get(input); + if (!recipeInput.isPresent()) return -1; + + return getHeight(recipeInput.get()); + } + + public static int getStackCount(CraftingInput input) { + return input.ingredientCount(); + } + + 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..8abc5c8a2 --- /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.world.item.ItemStack; +import net.minecraft.world.item.crafting.SingleRecipeInput; +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 SingleRecipeInput) { + return Optional.of((SingleRecipeInput) input.getInput()); + } + return Optional.empty(); + } + + public static CompatRecipeInput create(SingleRecipeInput input) { + return new CompatRecipeInput<>(input); + } + + public static CompatRecipeInput create(ItemStack stack) { + return new CompatRecipeInput<>(new SingleRecipeInput(stack)); + } + + public static ItemStack getStack(CompatRecipeInput input) { + Optional recipeInput = get(input); + if (!recipeInput.isPresent()) return ItemStackUtil.empty(); + + return recipeInput.get().getItem(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..56548e26b --- /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.world.level.block.entity.BlockEntity; +import net.minecraft.world.Container; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.Slot; +import org.jetbrains.annotations.Nullable; + +import java.util.Set; + +public class ScreenHandlerUtil { + public static int calcComparatorOutput(@Nullable Container inventory) { + return AbstractContainerMenu.getRedstoneSignalFromContainer(inventory); + } + + public static int calcComparatorOutput(@Nullable BlockEntity blockEntity) { + return AbstractContainerMenu.getRedstoneSignalFromBlockEntity(blockEntity); + } + + public static int calculateStackSize(Set slots, int mode, ItemStack stack) { + return AbstractContainerMenu.getQuickCraftPlaceCount(slots.size(), mode, stack); + } + + public static boolean canInsertItemIntoSlot(@Nullable Slot slot, ItemStack stack, boolean allowOverflow) { + return AbstractContainerMenu.canItemQuickReplace(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..055265991 --- /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.world.level.block.state.BlockBehaviour; +import net.minecraft.world.level.block.Block; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.resources.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 BuiltInRegistries.BLOCK.getValue(id); + } + + /** + * ~1.16? + * @param settings + * @param toolTags + * @param level + * @return + */ + public static BlockBehaviour.Properties breakByTool(BlockBehaviour.Properties settings, MineableToolTags toolTags, int level) { + return settings; + } + + public static BlockBehaviour.Properties dropsNothing(BlockBehaviour.Properties settings) { + return settings.noLootTable(); + } + + public static BlockBehaviour.Properties requiresTool(BlockBehaviour.Properties settings) { + return settings.requiresCorrectToolForDrops(); + } + + public static boolean isExist(Identifier identifier) { + return BuiltInRegistries.BLOCK.containsKey(identifier); + } + + public static Identifier toID(Block block) { + return BuiltInRegistries.BLOCK.getKey(block); + } + + public static Block fromId(Identifier identifier) { + return BuiltInRegistries.BLOCK.getValue(identifier); + } + + public static List getAllBlocks() { + List blocks = new ArrayList<>(); + for (Block block : BuiltInRegistries.BLOCK) { + blocks.add(block); + } + return blocks; + } + + @Deprecated + public static Block of(BlockBehaviour.Properties settings) { + return new Block(settings); + } + + public static Block of(CompatibleBlockSettings settings) { + return of(settings.build()); + } + + public static int getRawId(Block block) { + return BuiltInRegistries.BLOCK.getId(block); + } + + public static Block fromIndex(int index) { + return BuiltInRegistries.BLOCK.byId(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..01516edd8 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/v1/ItemUtilV1.java @@ -0,0 +1,92 @@ +package net.pitan76.mcpitanlib.api.util.v1; + +import net.minecraft.world.level.block.Block; +import net.minecraft.world.item.BlockItem; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.resources.Identifier; +import net.pitan76.mcpitanlib.api.block.BlockItemByExtendBlock1215; +import net.pitan76.mcpitanlib.api.block.ExtendBlock; +import net.pitan76.mcpitanlib.api.block.ExtendBlockProvider; +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 BuiltInRegistries.ITEM.getValue(id); + } + + public static boolean isEqual(Item item, Item item2) { + return item == item2; + } + + public static boolean isOf(ItemStack stack, Item item) { + return stack.is(item); + } + + public static boolean isIn(ItemStack stack, TagKey tagKey) { + return isIn(stack.getItem(), tagKey); + } + + public static boolean isIn(Item item, TagKey tagKey) { + if (item.builtInRegistryHolder().is(tagKey.getTagKey())) return true; + return tagKey.isOf(item); + } + + public static boolean isExist(Identifier identifier) { + return BuiltInRegistries.ITEM.containsKey(identifier); + } + public static Identifier toID(Item item) { + return BuiltInRegistries.ITEM.getKey(item); + } + + public static Item fromId(Identifier identifier) { + return BuiltInRegistries.ITEM.getValue(identifier); + } + + @Deprecated + public static BlockItem ofBlock(Block block, Item.Properties settings) { + if (block instanceof ExtendBlock) { + return new BlockItemByExtendBlock1215((ExtendBlock) block, settings); + } + + if (block instanceof ExtendBlockProvider) { + return new BlockItemByExtendBlock1215((ExtendBlockProvider) block, 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.Properties 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 : BuiltInRegistries.ITEM) { + items.add(item); + } + return items; + } + + public static int getRawId(Item item) { + return BuiltInRegistries.ITEM.getId(item); + } + + public static Item fromIndex(int index) { + return BuiltInRegistries.ITEM.byId(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..96a98a4ce --- /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.world.level.block.Block; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.resources.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.builtInRegistryHolder().is(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.byItem(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..e9f16a236 --- /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.core.component.DataComponents; +import net.minecraft.world.item.ItemStack; +import net.minecraft.network.chat.Component; +import net.pitan76.mcpitanlib.api.text.TextComponent; +import net.pitan76.mcpitanlib.api.util.TextUtil; + +public class CustomNameUtil { + + public static void setCustomName(ItemStack stack, Component name) { + stack.set(DataComponents.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 Component getCustomName(ItemStack stack) { + return stack.get(DataComponents.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.has(DataComponents.CUSTOM_NAME); + } + + public static void removeCustomName(ItemStack stack) { + stack.remove(DataComponents.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..562b64a9f --- /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.world.item.Item; +import net.minecraft.resources.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..fb6210a05 --- /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.level.ServerChunkCache; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.Level; +import net.pitan76.mcpitanlib.midohra.util.math.BlockPos; + +public class ChunkManagerUtil { + + public static void markForUpdate(ServerChunkCache manager, BlockPos pos) { + markForUpdate(manager, pos.toRaw()); + } + + public static void markForUpdate(ServerChunkCache manager, net.minecraft.core.BlockPos pos) { + manager.blockChanged(pos); + } + + public static void markForUpdate(ServerLevel world, net.minecraft.core.BlockPos pos) { + markForUpdate(ServerWorldUtil.getChunkManager(world), pos); + } + + public static void markForUpdate(Level world, net.minecraft.core.BlockPos pos) { + if (!(world instanceof ServerLevel)) return; + markForUpdate((ServerLevel) 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..728f343a4 --- /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.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.item.ItemStack; +import net.minecraft.core.particles.ParticleOptions; +import net.minecraft.server.level.ServerChunkCache; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.core.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(ServerLevel world, ParticleOptions particle, double x, double y, double z, int count, double velocityX, double velocityY, double velocityZ, double speed) { + world.sendParticles(particle, x, y, z, count, velocityX, velocityY, velocityZ, speed); + } + + public static void spawnParticles(ServerLevel world, Player player, ParticleOptions particle, boolean force, double x, double y, double z, int count, double velocityX, double velocityY, double velocityZ, double speed) { + if (player.isServer()) { + world.sendParticles(player.getServerPlayer().get(), particle, force, false, x, y, z, count, velocityX, velocityY, velocityZ, speed); + } + } + + public static List getDroppedStacksOnBlock(BlockState state, ServerLevel world, BlockPos pos, @Nullable BlockEntity blockEntity) { + return Block.getDrops(state, world, pos, blockEntity); + } + + public static List getDroppedStacksOnBlock(BlockState state, ServerLevel world, BlockPos pos, @Nullable BlockEntityWrapper blockEntity) { + return getDroppedStacksOnBlock(state, world, pos, blockEntity.get()); + } + + public static List getDroppedStacksOnBlock(BlockState state, ServerLevel world, BlockPos pos, @Nullable BlockEntity blockEntity, @Nullable Entity entity, ItemStack stack) { + return Block.getDrops(state, world, pos, blockEntity, entity, stack); + } + + public static ServerChunkCache getChunkManager(ServerLevel world) { + return world.getChunkSource(); + } +} 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..166af0cba --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/world/TickerUtil.java @@ -0,0 +1,53 @@ +package net.pitan76.mcpitanlib.api.util.world; + +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.BlockEntityTicker; +import net.minecraft.world.entity.Entity; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +import net.pitan76.mcpitanlib.api.util.WorldUtil; +import net.pitan76.mcpitanlib.midohra.block.entity.BlockEntityWrapper; + +public class TickerUtil { + public static void tick(T blockEntity, Level world, BlockPos pos, BlockState state) { + if (isTicker(blockEntity)) + ((BlockEntityTicker) blockEntity).tick(world, pos, state, blockEntity); + } + + public static void tick(T blockEntity, Level world, BlockPos pos) { + tick(blockEntity, world, pos, WorldUtil.getBlockState(world, pos)); + } + + public static void tick(T blockEntity) { + tick(blockEntity, blockEntity.getLevel(), blockEntity.getBlockPos()); + } + + public static void tick(T entity) { + entity.tick(); + } + + public static boolean isTicker(BlockEntity blockEntity) { + return blockEntity instanceof BlockEntityTicker; + } + + public static void tick(T blockEntity, net.pitan76.mcpitanlib.midohra.world.World world, net.pitan76.mcpitanlib.midohra.util.math.BlockPos pos, net.pitan76.mcpitanlib.midohra.block.BlockState state) { + tick(blockEntity, world.toMinecraft(), pos.toMinecraft(), state.toMinecraft()); + } + + public static void tick(T blockEntity, net.pitan76.mcpitanlib.midohra.world.World world, net.pitan76.mcpitanlib.midohra.util.math.BlockPos pos) { + tick(blockEntity, world.toMinecraft(), pos.toMinecraft()); + } + + public static void tick(BlockEntityWrapper blockEntity) { + tick(blockEntity.get()); + } + + public static void tick(BlockEntityWrapper blockEntity, net.pitan76.mcpitanlib.midohra.world.World world, net.pitan76.mcpitanlib.midohra.util.math.BlockPos pos, net.pitan76.mcpitanlib.midohra.block.BlockState state) { + tick(blockEntity.get(), world.toMinecraft(), pos.toMinecraft(), state.toMinecraft()); + } + + public static void tick(BlockEntityWrapper blockEntity, net.pitan76.mcpitanlib.midohra.world.World world, net.pitan76.mcpitanlib.midohra.util.math.BlockPos pos) { + tick(blockEntity.get(), world.toMinecraft(), pos.toMinecraft()); + } +} 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..383d36e84 --- /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.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.level.material.Fluid; +import net.minecraft.server.MinecraftServer; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.LevelAccessor; + +public class WorldAccessUtil extends WorldViewUtil { + + public static void scheduleBlockTick(LevelAccessor world, BlockPos pos, Block block, int delay) { + world.scheduleTick(pos, block, delay); + } + + public static void scheduleFluidTick(LevelAccessor world, BlockPos pos, Fluid fluid, int delay) { + world.scheduleTick(pos, fluid, delay); + } + + public static boolean setBlockState(LevelAccessor world, BlockPos pos, BlockState state, int flags) { + return world.setBlock(pos, state, flags); + } + + public static boolean setBlockState(LevelAccessor world, BlockPos pos, BlockState state, int flags, int maxUpdateDepth) { + return world.setBlock(pos, state, flags, maxUpdateDepth); + } + + public static boolean setBlockState(LevelAccessor world, BlockPos pos, BlockState state) { + return setBlockState(world, pos, state, 3); + } + + public static BlockState getBlockState(LevelAccessor world, BlockPos pos) { + return world.getBlockState(pos); + } + + public static boolean breakBlock(LevelAccessor world, BlockPos pos, boolean drop) { + return world.destroyBlock(pos, drop); + } + + public static boolean breakBlock(LevelAccessor world, BlockPos pos, boolean drop, Entity entity) { + return world.destroyBlock(pos, drop, entity); + } + + public static boolean removeBlock(LevelAccessor world, BlockPos pos, boolean move) { + return world.removeBlock(pos, move); + } + + public static MinecraftServer getServer(LevelAccessor 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..05952462e --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/world/WorldViewUtil.java @@ -0,0 +1,104 @@ +package net.pitan76.mcpitanlib.api.util.world; + +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.level.material.Fluid; +import net.minecraft.world.level.material.FluidState; +import net.minecraft.tags.FluidTags; +import net.minecraft.core.BlockPos; +import net.minecraft.world.phys.AABB; +import net.minecraft.world.level.LevelAccessor; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.dimension.DimensionType; +import net.pitan76.mcpitanlib.midohra.entity.EntityTypeWrapper; + +import java.util.List; +import java.util.Optional; +import java.util.function.Predicate; + +public class WorldViewUtil { + + public static boolean isClient(LevelReader world) { + return world.isClientSide(); + } + + public static BlockState getBlockState(LevelReader world, BlockPos pos) { + return world.getBlockState(pos); + } + + public static Block getBlock(LevelReader world, BlockPos pos) { + return getBlockState(world, pos).getBlock(); + } + + public static BlockEntity getBlockEntity(LevelReader world, BlockPos pos) { + return world.getBlockEntity(pos); + } + + public static Optional getBlockEntity(LevelReader world, BlockPos pos, BlockEntityType type) { + return world.getBlockEntity(pos, type); + } + + public static FluidState getFluidState(LevelReader world, BlockPos pos) { + return getBlockState(world, pos).getFluidState(); + } + + public static Fluid getFluid(LevelReader world, BlockPos pos) { + return getFluidState(world, pos).getType(); + } + + public static int getBottomY(LevelReader world) { + return world.getMinY(); + } + + public static int getTopY(LevelReader world) { + return world.getMaxY(); + } + + public static boolean isChunkLoaded(LevelReader world, BlockPos pos) { + return world.hasChunkAt(pos); + } + + public static boolean isRegionLoaded(LevelReader world, BlockPos min, BlockPos max) { + return world.hasChunksAt(min, max); + } + + public static DimensionType getDimensionType(LevelReader world) { + return world.dimensionType(); + } + + public static boolean isAirBlock(LevelReader world, BlockPos pos) { + return getBlockState(world, pos).isAir(); + } + + public static boolean isOpaqueBlock(LevelReader world, BlockPos pos) { + return getBlockState(world, pos).canOcclude(); + } + + public static boolean isWater(LevelReader world, BlockPos pos) { + return getFluidState(world, pos).is(FluidTags.WATER); + } + + public static List getEntitiesByClass(LevelAccessor world, Class entityClass, AABB box, Predicate predicate) { + return world.getEntitiesOfClass(entityClass, box, predicate); + } + + public static List getEntitiesByClass(LevelAccessor world, Class entityClass, net.pitan76.mcpitanlib.midohra.util.math.Box box, Predicate predicate) { + return getEntitiesByClass(world, entityClass, box.toMinecraft(), predicate); + } + + public static List getEntitiesByType(LevelAccessor world, EntityType entityType, AABB box, Predicate predicate) { + return world.getEntities(entityType, box, predicate); + } + + public static List getEntitiesByType(LevelAccessor world, EntityType entityType, net.pitan76.mcpitanlib.midohra.util.math.Box box, Predicate predicate) { + return getEntitiesByType(world, entityType, box.toMinecraft(), predicate); + } + + public static List getEntitiesByType(LevelAccessor world, EntityTypeWrapper entityType, AABB box, Predicate predicate) { + return getEntitiesByType(world, entityType.get(), box, predicate); + } +} 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..b48fc0320 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/api/world/CompatiblePersistentState.java @@ -0,0 +1,47 @@ +package net.pitan76.mcpitanlib.api.world; + +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.level.saveddata.SavedData; +import net.pitan76.mcpitanlib.api.event.nbt.ReadNbtArgs; +import net.pitan76.mcpitanlib.api.event.nbt.WriteNbtArgs; + +public abstract class CompatiblePersistentState extends SavedData { + // 1.16 + public CompatiblePersistentState(String key) { + super(); + } + + public CompatiblePersistentState() { + super(); + } + + // 1.16 + @Deprecated + public void readNbt(CompoundTag tag) { + readNbt(new ReadNbtArgs(tag)); + } + + public abstract void readNbt(ReadNbtArgs args); + + public abstract CompoundTag writeNbt(WriteNbtArgs args); + + @Deprecated + @Override + public void setDirty() { + callMarkDirty(); + } + + public void callMarkDirty() { + super.setDirty(); + } + + @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..6371fa909 --- /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.core.BlockPos; +import net.minecraft.world.level.Level; +import net.pitan76.mcpitanlib.api.util.WorldUtil; + +public class ExtendWorld { + public Level world; + public ExtendWorld(Level 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 Level 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..f67c68268 --- /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.commands.CommandSourceStack; + +public class CommandResult { + private boolean isSuccess = false; + private String message = ""; + private int result = 0; + private ErrorType errorType = ErrorType.NONE; + private CommandSourceStack 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(CommandSourceStack source) { + this.source = source; + } + + public CommandSourceStack 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/mc1216/NbtDataConverter.java b/common/src/main/java/net/pitan76/mcpitanlib/core/mc1216/NbtDataConverter.java new file mode 100644 index 000000000..f9a095d99 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/core/mc1216/NbtDataConverter.java @@ -0,0 +1,198 @@ +package net.pitan76.mcpitanlib.core.mc1216; + +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.Tag; +import net.minecraft.world.level.storage.TagValueInput; +import net.minecraft.world.level.storage.TagValueOutput; +import net.minecraft.world.level.storage.ValueInput; +import net.minecraft.world.level.storage.ValueOutput; +import net.minecraft.util.ProblemReporter; +import net.pitan76.mcpitanlib.api.nbt.NbtTypeBytes; +import net.pitan76.mcpitanlib.api.registry.CompatRegistryLookup; +import net.pitan76.mcpitanlib.api.util.NbtUtil; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +public class NbtDataConverter { + public static void nbt2writeData(CompoundTag nbt, ValueOutput view) { + if (nbt == null || view == null) return; + + List keys = new ArrayList<>(nbt.keySet()); + for (String key : keys) { + Tag value = nbt.get(key); + if (value == null) continue; + + byte type = value.getId(); + view.putByte("__nbttype_" + key + "__", type); + + switch (type) { + case NbtTypeBytes.BYTE: + Optional optional = value.asByte(); + if (optional.isEmpty()) continue; + view.putByte(key, optional.get()); + break; + case NbtTypeBytes.SHORT: + Optional optionalShort = value.asShort(); + if (optionalShort.isEmpty()) continue; + view.putShort(key, optionalShort.get()); + break; + case NbtTypeBytes.INT: + Optional optionalInt = value.asInt(); + if (optionalInt.isEmpty()) continue; + view.putInt(key, optionalInt.get()); + break; + case NbtTypeBytes.LONG: + Optional optionalLong = value.asLong(); + if (optionalLong.isEmpty()) continue; + view.putLong(key, optionalLong.get()); + break; + case NbtTypeBytes.FLOAT: + Optional optionalFloat = value.asFloat(); + if (optionalFloat.isEmpty()) continue; + view.putFloat(key, optionalFloat.get()); + break; + case NbtTypeBytes.DOUBLE: + Optional optionalDouble = value.asDouble(); + if (optionalDouble.isEmpty()) continue; + view.putDouble(key, optionalDouble.get()); + break; + case NbtTypeBytes.STRING: + Optional optionalString = value.asString(); + if (optionalString.isEmpty()) continue; + view.putString(key, optionalString.get()); + break; + case NbtTypeBytes.BYTE_ARRAY: + Optional optionalByteArray = value.asByteArray(); + if (optionalByteArray.isEmpty()) continue; + byte[] byteArray = optionalByteArray.get(); + int[] intArray = new int[byteArray.length]; + for (int i = 0; i < byteArray.length; i++) + intArray[i] = byteArray[i]; + view.putIntArray(key, intArray); + break; + case NbtTypeBytes.INT_ARRAY: + Optional optionalIntArray = value.asIntArray(); + if (optionalIntArray.isEmpty()) continue; + view.putIntArray(key, optionalIntArray.get()); + break; + case NbtTypeBytes.LONG_ARRAY: + Optional optionalLongArray = value.asLongArray(); + if (optionalLongArray.isEmpty()) continue; + long[] longArray = optionalLongArray.get(); + int[] longIntArray = new int[longArray.length]; + for (int i = 0; i < longArray.length; i++) + longIntArray[i] = (int) (longArray[i] & 0xFFFFFFFFL); + view.putIntArray(key, longIntArray); + break; + case NbtTypeBytes.COMPOUND: + Optional optionalCompound = value.asCompound(); + if (optionalCompound.isEmpty()) continue; + CompoundTag nbt2 = optionalCompound.get(); + + //System.out.println("NbtDataConverter nbt(" + key + "): " + nbt2); + + view.store(key, CompoundTag.CODEC, nbt2); + break; + } + } + + view.putString("__all_keys__", String.join(",", keys)); + } + + public static void data2nbt(ValueInput view, CompoundTag nbt) { + if (view == null || nbt == null) return; + + // ReadViewだとgetKeys()がないので__all_keys__からキーを取得する + String keysStr = view.getStringOr("__all_keys__", ""); + if (keysStr.isEmpty()) return; + String[] keys = keysStr.split(","); + for (String key : keys) { + if (key == null || key.isEmpty()) continue; + + byte type = view.getByteOr("__nbttype_" + key + "__", (byte) -1); + if (type == -1) continue; + + switch (type) { + case NbtTypeBytes.BYTE: + nbt.putByte(key, view.getByteOr(key, (byte) 0)); + break; + case NbtTypeBytes.SHORT: + nbt.putShort(key, (short) view.getShortOr(key, (short) 0)); + break; + case NbtTypeBytes.INT: + nbt.putInt(key, view.getIntOr(key, 0)); + break; + case NbtTypeBytes.LONG: + nbt.putLong(key, view.getLongOr(key, 0)); + break; + case NbtTypeBytes.FLOAT: + nbt.putFloat(key, view.getFloatOr(key, 0)); + break; + case NbtTypeBytes.DOUBLE: + nbt.putDouble(key, view.getDoubleOr(key, 0)); + break; + case NbtTypeBytes.STRING: + nbt.putString(key, view.getStringOr(key, "")); + break; + case NbtTypeBytes.BYTE_ARRAY: + int[] intArray = view.getIntArray(key).get(); + byte[] byteArray = new byte[intArray.length]; + for (int i = 0; i < intArray.length; i++) + byteArray[i] = (byte) intArray[i]; + nbt.putByteArray(key, byteArray); + break; + case NbtTypeBytes.INT_ARRAY: + nbt.putIntArray(key, view.getIntArray(key).get()); + break; + case NbtTypeBytes.LONG_ARRAY: + int[] longIntArray = view.getIntArray(key).get(); + long[] longArray = new long[longIntArray.length]; + for (int i = 0; i < longIntArray.length; i++) + longArray[i] = longIntArray[i] & 0xFFFFFFFFL; + nbt.putLongArray(key, longArray); + break; + case NbtTypeBytes.COMPOUND: + CompoundTag nbt2 = view.read(key, CompoundTag.CODEC).get(); + nbt.put(key, nbt2); + break; + default: + nbt.putString(key, "Unsupported NBT type: " + type); + break; + } + } + } + + public static void data2nbt(ValueOutput view, CompoundTag nbt) { + if (view == null || nbt == null) return; + + if (view instanceof TagValueOutput) { + //System.out.println("data2nbt(): " + ((NbtWriteView) view).getNbt()); + NbtUtil.copyFrom(((TagValueOutput) view).buildResult(), nbt); + } + } + + public static ValueOutput nbt2writeData(CompoundTag nbt, CompatRegistryLookup registryLookup) { + ValueOutput view = TagValueOutput.createWithoutContext(ProblemReporter.DISCARDING); + nbt2writeData(nbt, view); + return view; + } + + public static ValueInput nbt2readData(CompoundTag nbt, CompatRegistryLookup registryLookup) { + if (nbt == null) nbt = NbtUtil.create(); + return TagValueInput.create(ProblemReporter.DISCARDING, registryLookup.getRegistryLookup(), nbt); + } + + public static CompoundTag data2nbt(ValueInput view) { + CompoundTag nbt = new CompoundTag(); + data2nbt(view, nbt); + return nbt; + } + + public static CompoundTag data2nbt(ValueOutput view) { + CompoundTag nbt = new CompoundTag(); + data2nbt(view, nbt); + return nbt; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/core/mc261/ClientPlayNetworking.java b/common/src/main/java/net/pitan76/mcpitanlib/core/mc261/ClientPlayNetworking.java new file mode 100644 index 000000000..823acbcd2 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/core/mc261/ClientPlayNetworking.java @@ -0,0 +1,23 @@ +package net.pitan76.mcpitanlib.core.mc261; + +import dev.architectury.injectables.annotations.ExpectPlatform; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import net.minecraft.resources.Identifier; +import net.pitan76.mcpitanlib.api.network.ClientNetworking; +import net.pitan76.mcpitanlib.core.network.BufPayload; + +public class ClientPlayNetworking { + @ExpectPlatform + public static void send(CustomPacketPayload payload) { + } + + @ExpectPlatform + public static void registerGlobalReceiver(BufPayload.Type type, ClientNetworking.ClientNetworkHandler handler) { + + } + + @ExpectPlatform + public static void registerC2SPayloadType(Identifier identifier) { + + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/core/mc261/CreativeModeTabEventRegistry.java b/common/src/main/java/net/pitan76/mcpitanlib/core/mc261/CreativeModeTabEventRegistry.java new file mode 100644 index 000000000..98af67a7d --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/core/mc261/CreativeModeTabEventRegistry.java @@ -0,0 +1,21 @@ +package net.pitan76.mcpitanlib.core.mc261; + +import dev.architectury.injectables.annotations.ExpectPlatform; +import net.minecraft.resources.ResourceKey; +import net.minecraft.world.item.CreativeModeTab; +import net.minecraft.world.item.ItemStack; + +import java.util.List; +import java.util.function.Supplier; + +public class CreativeModeTabEventRegistry { + @ExpectPlatform + public static void addStack(ResourceKey key, Supplier supplier) { + throw new AssertionError(); + } + + @ExpectPlatform + public static void addStacks(ResourceKey key, Supplier> supplier) { + throw new AssertionError(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/core/mc261/ExtendedMenuProvider.java b/common/src/main/java/net/pitan76/mcpitanlib/core/mc261/ExtendedMenuProvider.java new file mode 100644 index 000000000..a3e5ea84a --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/core/mc261/ExtendedMenuProvider.java @@ -0,0 +1,8 @@ +package net.pitan76.mcpitanlib.core.mc261; + +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.MenuProvider; + +public interface ExtendedMenuProvider extends MenuProvider { + D getScreenOpeningData(ServerPlayer player); +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/core/mc261/ServerPlayNetworking.java b/common/src/main/java/net/pitan76/mcpitanlib/core/mc261/ServerPlayNetworking.java new file mode 100644 index 000000000..4587eb0ef --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/core/mc261/ServerPlayNetworking.java @@ -0,0 +1,25 @@ +package net.pitan76.mcpitanlib.core.mc261; + +import dev.architectury.injectables.annotations.ExpectPlatform; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import net.minecraft.resources.Identifier; +import net.minecraft.server.level.ServerPlayer; +import net.pitan76.mcpitanlib.api.network.ServerNetworking; +import net.pitan76.mcpitanlib.core.network.BufPayload; + +public class ServerPlayNetworking { + @ExpectPlatform + public static void send(ServerPlayer player, CustomPacketPayload payload) { + + } + + @ExpectPlatform + public static void registerGlobalReceiver(CustomPacketPayload.Type id, ServerNetworking.ServerNetworkHandler handler) { + + } + + @ExpectPlatform + public static void registerS2CPayloadType(Identifier identifier) { + + } +} 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..46c550992 --- /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.FriendlyByteBuf; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.network.codec.ByteBufCodecs; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import net.minecraft.resources.Identifier; + +import java.util.HashMap; +import java.util.Map; + +public class BufPayload implements CustomPacketPayload { + + public final Type ID; + + public BufPayload(byte[] data, Type id) { + this.data = data; + this.ID = id; + + createCodec(id); + } + + public BufPayload(FriendlyByteBuf buf, Type id) { + this(ByteBufUtil.getBytes(buf), id); + } + + public BufPayload(FriendlyByteBuf buf, Identifier id) { + this(ByteBufUtil.getBytes(buf), id(id)); + } + + public byte[] data; + + public byte[] getData() { + return data; + } + + private static final Map, StreamCodec> CODEC_CACHE = new HashMap<>(); + + public static StreamCodec getCodec(Type id) { + if (CODEC_CACHE.containsKey(id)) return CODEC_CACHE.get(id); + + return createCodec(id); + } + + private static StreamCodec createCodec(Type id) { + StreamCodec codec = ByteBufCodecs.BYTE_ARRAY.map((data) -> new BufPayload(data, id), BufPayload::getData).cast(); + CODEC_CACHE.put(id, codec); + return codec; + } + + @Override + public Type type() { + return ID; + } + + public static Type id(Identifier id) { + if (CODEC_CACHE.isEmpty()) return new Type<>(id); + + for (Type key : CODEC_CACHE.keySet()) { + if (key.id().equals(id)) + return key; + } + + return new Type<>(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..34c7420d8 --- /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.world.item.Item; +import net.minecraft.world.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().isOnCooldown(stack); + } + } + + return false; + } + + public void set(Item item, int duration) { + for (ItemStack stack : player.getMain()) { + if (stack.getItem() == item) { + player.getItemCooldownManager().addCooldown(stack, 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..72a2877ae --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/core/registry/FuelRegistry.java @@ -0,0 +1,51 @@ +package net.pitan76.mcpitanlib.core.registry; + +import dev.architectury.injectables.annotations.ExpectPlatform; +import net.minecraft.world.level.ItemLike; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; +import net.pitan76.mcpitanlib.midohra.item.ItemWrapper; + +import java.util.function.Supplier; + +public class FuelRegistry { + private FuelRegistry() { + + } + + @ExpectPlatform + public static void register(int time, Supplier item) { + + } + + public static void register(int time, ItemLike... item) { + for (ItemLike i : item) { + register(time, () -> i); + } + } + + @Deprecated + public static int get(ItemStack stack) { + return 0; + } + + public static int get(Level world, ItemStack stack) { + return world.fuelValues().burnDuration(stack); + } + + public static boolean isFuel(Level world, ItemStack stack) { + return world.fuelValues().isFuel(stack); + } + + public static void register(int time, ItemWrapper item) { + register(time, item::get); + } + + public static int get(net.pitan76.mcpitanlib.midohra.world.World world, net.pitan76.mcpitanlib.midohra.item.ItemStack stack) { + return get(world.toMinecraft(), stack.toMinecraft()); + } + + public static boolean isFuel(net.pitan76.mcpitanlib.midohra.world.World world, net.pitan76.mcpitanlib.midohra.item.ItemStack stack) { + return isFuel(world.toMinecraft(), stack.toMinecraft()); + } +} 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..5f28f2d61 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/core/registry/MCPLRegistry.java @@ -0,0 +1,68 @@ +package net.pitan76.mcpitanlib.core.registry; + +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.item.enchantment.Enchantment; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.effect.MobEffect; +import net.minecraft.world.level.material.Fluid; +import net.minecraft.world.item.Item; +import net.minecraft.core.particles.ParticleType; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.sounds.SoundEvent; +import net.minecraft.resources.Identifier; +import net.pitan76.mcpitanlib.api.registry.result.RegistrySupplier; + +import java.util.function.Supplier; + +@Deprecated +public class MCPLRegistry { + public MCPLRegistry(String MOD_ID) { + + } + + public RegistrySupplier registryItem(Identifier id, Supplier supplier) { + return Registry.registryItem(id, supplier); + } + + public RegistrySupplier registryBlock(Identifier id, Supplier supplier) { + return Registry.registryBlock(id, supplier); + } + + public RegistrySupplier> registryScreenHandlerType(Identifier id, Supplier> supplier) { + return Registry.registryScreenHandlerType(id, supplier); + } + + public RegistrySupplier> registryBlockEntityType(Identifier id, Supplier> supplier) { + return Registry.registryBlockEntityType(id, supplier); + } + + public RegistrySupplier> registryEntityType(Identifier id, Supplier> supplier) { + return Registry.registryEntityType(id, supplier); + } + + public RegistrySupplier registrySoundEvent(Identifier id, Supplier supplier) { + return Registry.registrySoundEvent(id, supplier); + } + + public RegistrySupplier registryFluid(Identifier id, Supplier supplier) { + return Registry.registryFluid(id, supplier); + } + + public RegistrySupplier> registryParticleType(Identifier id, Supplier> supplier) { + return Registry.registryParticleType(id, supplier); + } + + public RegistrySupplier registryEnchantment(Identifier id, Supplier supplier) { + return null; + //return ENCHANTMENT.register(id, supplier); + } + + public RegistrySupplier registryStatusEffect(Identifier id, Supplier supplier) { + return Registry.registryStatusEffect(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..6700b13d1 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/core/registry/MCPLRegistry1_20.java @@ -0,0 +1,58 @@ +package net.pitan76.mcpitanlib.core.registry; + +import net.minecraft.core.registries.Registries; +import net.minecraft.resources.ResourceKey; +import net.minecraft.world.item.CreativeModeTab; +import net.minecraft.resources.Identifier; +import net.pitan76.mcpitanlib.api.item.CreativeTabBuilder; +import net.pitan76.mcpitanlib.api.registry.result.RegistrySupplier; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.function.Supplier; + +@Deprecated +public class MCPLRegistry1_20 { + @Deprecated + public static final Map, RegistrySupplier> REGISTRY_SUPPLIER_ITEM_GROUP_CACHE = new HashMap<>(); + + @Deprecated + public static final Map, List> ITEM_GROUP_ITEM_ID_CACHE = new HashMap<>(); + + public static void addItemGroupItem(ResourceKey itemGroup, Identifier itemId) { + if (!ITEM_GROUP_ITEM_ID_CACHE.containsKey(itemGroup)) { + ITEM_GROUP_ITEM_ID_CACHE.put(itemGroup, new ArrayList<>()); + } + + ITEM_GROUP_ITEM_ID_CACHE.get(itemGroup).add(itemId); + } + + private final MCPLRegistry mcplr; + + public MCPLRegistry1_20(MCPLRegistry mcplr, String MOD_ID) { + this.mcplr = mcplr; + } + + public void register() { + + } + + public RegistrySupplier registryItemGroup(Identifier id, Supplier supplier) { + ResourceKey key = ResourceKey.create(Registries.CREATIVE_MODE_TAB, id); + RegistrySupplier itemGroup = Registry.registryItemGroup(id, supplier); +// RegistrySupplier itemGroup = ITEM_GROUP.register(id, supplier); + REGISTRY_SUPPLIER_ITEM_GROUP_CACHE.put(key, itemGroup); + return itemGroup; + } + + public RegistrySupplier registryItemGroup(Identifier id, CreativeTabBuilder builder) { + ResourceKey key = ResourceKey.create(Registries.CREATIVE_MODE_TAB, id); + RegistrySupplier itemGroup = Registry.registryItemGroup(id, builder::build); +// new RegistrySupplier<>(Registry.register(BuiltInRegistries.CREATIVE_MODE_TAB, key, builder.build())); +// RegistrySupplier itemGroup = ITEM_GROUP.register(id, builder::build); + REGISTRY_SUPPLIER_ITEM_GROUP_CACHE.put(key, 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..5eade58ce --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/core/registry/MCPLRegistry1_21.java @@ -0,0 +1,39 @@ +package net.pitan76.mcpitanlib.core.registry; + +import net.minecraft.core.component.DataComponentType; +import net.minecraft.core.registries.Registries; +import net.minecraft.resources.Identifier; +import net.minecraft.resources.ResourceKey; +import net.minecraft.server.level.TicketType; +import net.pitan76.mcpitanlib.api.registry.result.RegistrySupplier; +import net.pitan76.mcpitanlib.midohra.world.chunk.ChunkTicketType; + +import java.util.function.Supplier; + +@Deprecated +public class MCPLRegistry1_21 { + + + private final MCPLRegistry mcplr; + + public MCPLRegistry1_21(MCPLRegistry mcplr, String MOD_ID) { + this.mcplr = mcplr; + } + + public void register() { + + } + + public RegistrySupplier> registryDataComponentType(Identifier id, Supplier> supplier) { + ResourceKey> key = ResourceKey.create(Registries.DATA_COMPONENT_TYPE, id); + return Registry.registryDataComponentType(id, supplier); + } + + public Supplier> registryChunkTicketType(Identifier id, Supplier> supplier) { + ResourceKey key = ResourceKey.create(Registries.TICKET_TYPE, id); +// net.minecraft.server.level.TicketType ticketType = Registry.register(BuiltInRegistries.TICKET_TYPE, key, supplier.get().getRaw()); +// net.minecraft.server.level.TicketType ticketType = ; + + return Registry.registryChunkTicketType(id, () -> supplier.get().getRaw()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/core/registry/Registry.java b/common/src/main/java/net/pitan76/mcpitanlib/core/registry/Registry.java new file mode 100644 index 000000000..5b0819f10 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/core/registry/Registry.java @@ -0,0 +1,83 @@ +package net.pitan76.mcpitanlib.core.registry; + +import dev.architectury.injectables.annotations.ExpectPlatform; +import net.minecraft.core.component.DataComponentType; +import net.minecraft.core.particles.ParticleType; +import net.minecraft.resources.Identifier; +import net.minecraft.server.level.TicketType; +import net.minecraft.sounds.SoundEvent; +import net.minecraft.world.effect.MobEffect; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.CreativeModeTab; +import net.minecraft.world.item.Item; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.level.material.Fluid; +import net.pitan76.mcpitanlib.api.registry.result.RegistrySupplier; +import net.pitan76.mcpitanlib.midohra.world.chunk.ChunkTicketType; + +import java.util.function.Supplier; + +public class Registry { + + @ExpectPlatform + public static RegistrySupplier registryItem(Identifier id, Supplier supplier) { + throw new AssertionError(); + } + + @ExpectPlatform + public static RegistrySupplier registryBlock(Identifier id, Supplier supplier) { + throw new AssertionError(); + } + + @ExpectPlatform + public static RegistrySupplier> registryScreenHandlerType(Identifier id, Supplier> supplier) { + throw new AssertionError(); + } + + @ExpectPlatform + public static RegistrySupplier> registryBlockEntityType(Identifier id, Supplier> supplier) { + throw new AssertionError(); + } + + @ExpectPlatform + public static RegistrySupplier> registryEntityType(Identifier id, Supplier> supplier) { + throw new AssertionError(); + } + + @ExpectPlatform + public static RegistrySupplier registrySoundEvent(Identifier id, Supplier supplier) { + throw new AssertionError(); + } + + @ExpectPlatform + public static RegistrySupplier registryFluid(Identifier id, Supplier supplier) { + throw new AssertionError(); + } + + @ExpectPlatform + public static RegistrySupplier> registryParticleType(Identifier id, Supplier> supplier) { + throw new AssertionError(); + } + + @ExpectPlatform + public static RegistrySupplier registryStatusEffect(Identifier id, Supplier supplier) { + throw new AssertionError(); + } + + @ExpectPlatform + public static RegistrySupplier registryItemGroup(Identifier id, Supplier supplier) { + throw new AssertionError(); + } + + @ExpectPlatform + public static RegistrySupplier> registryDataComponentType(Identifier id, Supplier> supplier) { + throw new AssertionError(); + } + + @ExpectPlatform + public static Supplier> registryChunkTicketType(Identifier id, Supplier supplier) { + throw new AssertionError(); + } +} 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..dce1d8b65 --- /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.world.level.block.state.BlockBehaviour; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.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 BlockBehaviour.Properties.CODEC.fieldOf("properties").forGetter(BlockBehaviour::properties); + } + + 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..4a26ab39c --- /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.world.level.block.Block; +import net.minecraft.world.level.block.state.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..36a496407 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/guilib/GuiRegistry.java @@ -0,0 +1,82 @@ +package net.pitan76.mcpitanlib.guilib; + +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.gui.screens.inventory.MenuAccess; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.MenuType; +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.text.TextComponent; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.api.util.inventory.CompatPlayerInventory; +import net.pitan76.mcpitanlib.guilib.api.container.SimpleContainerGui; +import net.pitan76.mcpitanlib.guilib.api.screen.SimpleContainerGuiScreen; +import net.pitan76.mcpitanlib.midohra.screen.SupplierTypedScreenHandlerTypeWrapper; + +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, MenuType type) { + return registry.registerScreenHandlerTypeSavingGenerics(id, () -> type); + } + + @Environment(EnvType.CLIENT) + public static > void register(String id, MenuType type, CompatRegistryClient.ScreenFactory factory) { + CompatRegistryClient.registerScreen(id, type, factory); + } + + @Environment(EnvType.CLIENT) + public static void registerSimpleContainerGui(String id, MenuType type) { + CompatRegistryClient.registerScreen(id, type, new CompatRegistryClient.ScreenFactory2<>() { + @Override + public SimpleContainerGuiScreen create(SimpleContainerGui handler, CompatPlayerInventory inventory, TextComponent text) { + return new SimpleContainerGuiScreen(handler, inventory, text); + } + }); + } + + @Environment(EnvType.CLIENT) + public static > void register(String id, SupplierResult> type, CompatRegistryClient.ScreenFactory factory) { + register(id, type.get(), factory); + } + + @Environment(EnvType.CLIENT) + public static void registerSimpleContainerGui(String id, SupplierResult> type) { + registerSimpleContainerGui(id, type.get()); + } + + @Environment(EnvType.CLIENT) + public static > void register(String id, SupplierTypedScreenHandlerTypeWrapper type, CompatRegistryClient.ScreenFactory factory) { + register(id, type.get(), factory); + } + + @Environment(EnvType.CLIENT) + public static void registerSimpleContainerGui(String id, SupplierTypedScreenHandlerTypeWrapper type) { + registerSimpleContainerGui(id, type.get()); + } + + 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); + } + + public static SupplierTypedScreenHandlerTypeWrapper registerM(CompatRegistryV2 registry, CompatIdentifier id, SimpleScreenHandlerTypeBuilder builder) { + return SupplierTypedScreenHandlerTypeWrapper.of(register(registry, id, builder)); + } + + public static SupplierTypedScreenHandlerTypeWrapper registerM(CompatRegistryV2 registry, CompatIdentifier id, ExtendedScreenHandlerTypeBuilder builder) { + return SupplierTypedScreenHandlerTypeWrapper.of(register(registry, 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..7c23e584d --- /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.world.level.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..cdb5c4868 --- /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.world.level.block.entity.BlockEntityType; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.chat.Component; +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(getLevel())); + for (Player player : players) { + if (player.hasNetworkHandler() && player.getCurrentScreenHandler() instanceof ExtendedBlockEntityContainerGui && ((ExtendedBlockEntityContainerGui) player.getCurrentScreenHandler()).blockEntity == this ) { + FriendlyByteBuf buf = PacketByteUtil.create(); + sync(player, buf); + ServerNetworking.send(player, SYNC_GUI_WITH_TILE, buf); + } + } + } + + @Override + public Component getDisplayName(DisplayNameArgs args) { + if (getBlockState() == null) + return TextUtil.of("unknown"); + + return getBlockState().getBlock().getName(); + } + + @Override + public void writeExtraData(ExtraDataArgs args) { + PacketByteUtil.writeBlockPos(args.buf, getBlockPos()); + sync(args.getCompatPlayer(), args.buf); + } + + public abstract void sync(Player player, FriendlyByteBuf buf); +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/guilib/api/block/entity/v2/BlockEntityWithContainer.java b/common/src/main/java/net/pitan76/mcpitanlib/guilib/api/block/entity/v2/BlockEntityWithContainer.java new file mode 100644 index 000000000..965dcd771 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/guilib/api/block/entity/v2/BlockEntityWithContainer.java @@ -0,0 +1,15 @@ +package net.pitan76.mcpitanlib.guilib.api.block.entity.v2; + +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.pitan76.mcpitanlib.api.event.block.TileCreateEvent; +import net.pitan76.mcpitanlib.midohra.block.entity.BlockEntityTypeWrapper; + +public abstract class BlockEntityWithContainer extends net.pitan76.mcpitanlib.guilib.api.block.entity.BlockEntityWithContainer { + public BlockEntityWithContainer(BlockEntityType type, TileCreateEvent e) { + super(type, e); + } + + public BlockEntityWithContainer(BlockEntityTypeWrapper type, TileCreateEvent e) { + super(type.get(), e); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/guilib/api/block/entity/v2/ExtendedBlockEntityWithContainer.java b/common/src/main/java/net/pitan76/mcpitanlib/guilib/api/block/entity/v2/ExtendedBlockEntityWithContainer.java new file mode 100644 index 000000000..94b574bc7 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/guilib/api/block/entity/v2/ExtendedBlockEntityWithContainer.java @@ -0,0 +1,41 @@ +package net.pitan76.mcpitanlib.guilib.api.block.entity.v2; + +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.world.level.block.entity.BlockEntityType; +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.gui.SimpleScreenHandler; +import net.pitan76.mcpitanlib.api.gui.args.CreateMenuEvent; +import net.pitan76.mcpitanlib.api.gui.v3.ExtendedScreenHandlerFactory; +import net.pitan76.mcpitanlib.api.text.TextComponent; +import net.pitan76.mcpitanlib.midohra.block.entity.BlockEntityTypeWrapper; +import net.pitan76.mcpitanlib.midohra.network.CompatPacketByteBuf; + +public abstract class ExtendedBlockEntityWithContainer extends net.pitan76.mcpitanlib.guilib.api.block.entity.ExtendedBlockEntityWithContainer implements ExtendedScreenHandlerFactory { + public ExtendedBlockEntityWithContainer(BlockEntityType type, TileCreateEvent e) { + super(type, e); + } + + public ExtendedBlockEntityWithContainer(BlockEntityTypeWrapper type, TileCreateEvent e) { + super(type.get(), e); + } + + @Override + public void sync(Player player, FriendlyByteBuf buf) { + sync(player, CompatPacketByteBuf.of(buf)); + } + + public abstract void sync(Player player, CompatPacketByteBuf buf); + + @Override + public SimpleScreenHandler createMenu(CreateMenuEvent event) { + return null; + } + + @Override + public TextComponent getDisplayText(DisplayNameArgs args) { + if (getMidohraBlockState().isEmpty()) return TextComponent.of("unknown"); + return new TextComponent(getMidohraBlockState().getName()); + } +} 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..3279f09be --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/guilib/api/container/BlockEntityContainerGui.java @@ -0,0 +1,29 @@ +package net.pitan76.mcpitanlib.guilib.api.container; + +import net.minecraft.world.inventory.MenuType; +import net.pitan76.mcpitanlib.api.gui.args.CreateMenuEvent; +import net.pitan76.mcpitanlib.api.tile.CompatBlockEntity; +import net.pitan76.mcpitanlib.guilib.api.ISimpleScreenInfo; +import net.pitan76.mcpitanlib.midohra.block.entity.TypedBlockEntityWrapper; +import net.pitan76.mcpitanlib.midohra.screen.ScreenHandlerTypeWrapper; + +public abstract class BlockEntityContainerGui extends ContainerGui implements ISimpleScreenInfo { + + public T blockEntity; + + protected BlockEntityContainerGui(MenuType type, CreateMenuEvent e) { + super(type, e); + } + + protected BlockEntityContainerGui(ScreenHandlerTypeWrapper type, CreateMenuEvent e) { + super(type, e); + } + + public T getBlockEntity() { + return blockEntity; + } + + public TypedBlockEntityWrapper getBlockEntityWrapper() { + return TypedBlockEntityWrapper.ofRaw(blockEntity); + } +} 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..bd124f7e6 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/guilib/api/container/ContainerGui.java @@ -0,0 +1,75 @@ +package net.pitan76.mcpitanlib.guilib.api.container; + +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.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 net.pitan76.mcpitanlib.midohra.screen.ScreenHandlerTypeWrapper; + +import java.util.ArrayList; +import java.util.List; + +public abstract class ContainerGui extends SimpleScreenHandler implements IScreenInfo { + + private final List INVENTORIES = new ArrayList<>(); + + protected ContainerGui(MenuType type, int syncId) { + super(type, syncId); + } + + protected ContainerGui(MenuType type, CreateMenuEvent e) { + super(type, e); + } + + protected ContainerGui(ScreenHandlerTypeWrapper type, int syncId) { + super(type, syncId); + } + + protected ContainerGui(ScreenHandlerTypeWrapper type, CreateMenuEvent e) { + super(type, e); + } + + @Override + public boolean canUse(Player player) { + return true; + } + + @Override + protected Slot addSlot(Slot slot) { + if (slot.container instanceof Container && !INVENTORIES.contains(slot.container)) + INVENTORIES.add(slot.container); + + return super.addSlot(slot); + } + + public int playerMainInventoryX = 8; + public int playerMainInventoryY = 84; + + public int playerHotbarX = 8; + public int playerHotbarY = 142; + + @Override + protected List addPlayerMainInventorySlots(Inventory inventory, int x, int y) { + playerMainInventoryX = x; + playerMainInventoryY = y; + + return super.addPlayerMainInventorySlots(inventory, x, y); + } + + @Override + protected List addPlayerHotbarSlots(Inventory 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.stopOpen(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..0aa1c802d --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/guilib/api/container/ExtendedBlockEntityContainerGui.java @@ -0,0 +1,51 @@ +package net.pitan76.mcpitanlib.guilib.api.container; + +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +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; +import net.pitan76.mcpitanlib.midohra.network.IByteBuf; +import net.pitan76.mcpitanlib.midohra.screen.ScreenHandlerTypeWrapper; + +public abstract class ExtendedBlockEntityContainerGui extends BlockEntityContainerGui implements ISimpleScreenInfo { + + public ExtendedBlockEntityContainerGui(MenuType type, CreateMenuEvent e, FriendlyByteBuf buf) { + this(type, e); + + if (buf == null) return; + + Player player = e.getPlayer(); + Level 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(MenuType type, CreateMenuEvent e) { + super(type, e); + } + + public ExtendedBlockEntityContainerGui(ScreenHandlerTypeWrapper type, CreateMenuEvent e, IByteBuf buf) { + this(type.get(), e, buf.toCompat()); + } + + public ExtendedBlockEntityContainerGui(ScreenHandlerTypeWrapper type, CreateMenuEvent e, net.pitan76.mcpitanlib.midohra.network.PacketByteBuf buf) { + this(type.get(), e, buf.toCompat()); + } + + protected ExtendedBlockEntityContainerGui(ScreenHandlerTypeWrapper type, CreateMenuEvent e) { + this(type.get(), e); + } + + public abstract void receiveSync(FriendlyByteBuf 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..02451b523 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/guilib/api/container/SimpleContainerGui.java @@ -0,0 +1,25 @@ +package net.pitan76.mcpitanlib.guilib.api.container; + +import net.minecraft.world.inventory.MenuType; +import net.pitan76.mcpitanlib.api.gui.args.CreateMenuEvent; +import net.pitan76.mcpitanlib.guilib.api.ISimpleScreenInfo; +import net.pitan76.mcpitanlib.midohra.screen.ScreenHandlerTypeWrapper; + +public abstract class SimpleContainerGui extends ContainerGui implements ISimpleScreenInfo { + + protected SimpleContainerGui(MenuType type, int syncId) { + super(type, syncId); + } + + protected SimpleContainerGui(MenuType type, CreateMenuEvent e) { + super(type, e); + } + + protected SimpleContainerGui(ScreenHandlerTypeWrapper type, int syncId) { + this(type.get(), syncId); + } + + protected SimpleContainerGui(ScreenHandlerTypeWrapper type, CreateMenuEvent e) { + this(type.get(), e); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/guilib/api/container/v2/ExtendedBlockEntityContainerGui.java b/common/src/main/java/net/pitan76/mcpitanlib/guilib/api/container/v2/ExtendedBlockEntityContainerGui.java new file mode 100644 index 000000000..9e9f31a13 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/guilib/api/container/v2/ExtendedBlockEntityContainerGui.java @@ -0,0 +1,30 @@ +package net.pitan76.mcpitanlib.guilib.api.container.v2; + +import net.minecraft.network.FriendlyByteBuf; +import net.pitan76.mcpitanlib.api.gui.args.CreateMenuEvent; +import net.pitan76.mcpitanlib.api.tile.CompatBlockEntity; +import net.pitan76.mcpitanlib.guilib.api.ISimpleScreenInfo; +import net.pitan76.mcpitanlib.midohra.network.IByteBuf; +import net.pitan76.mcpitanlib.midohra.screen.ScreenHandlerTypeWrapper; + +public abstract class ExtendedBlockEntityContainerGui extends net.pitan76.mcpitanlib.guilib.api.container.ExtendedBlockEntityContainerGui implements ISimpleScreenInfo { + + public ExtendedBlockEntityContainerGui(ScreenHandlerTypeWrapper type, CreateMenuEvent e, IByteBuf buf) { + super(type.get(), e, buf.toCompat()); + } + + public ExtendedBlockEntityContainerGui(ScreenHandlerTypeWrapper type, CreateMenuEvent e, net.pitan76.mcpitanlib.midohra.network.PacketByteBuf buf) { + super(type.get(), e, buf.toCompat()); + } + + protected ExtendedBlockEntityContainerGui(ScreenHandlerTypeWrapper type, CreateMenuEvent e) { + super(type.get(), e); + } + + public abstract void receiveSync(net.pitan76.mcpitanlib.midohra.network.PacketByteBuf buf); + + @Override + public void receiveSync(FriendlyByteBuf buf) { + receiveSync(net.pitan76.mcpitanlib.midohra.network.PacketByteBuf.of(buf)); + } +} 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..fd9a2ce3a --- /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.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.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, AbstractContainerMenu handler, int x, int y) { + ScreenHandlerUtil.getSlots(handler).forEach((slot) -> drawSlot(drawObjectDM, slot, x, y)); + } + + public static void drawPlayerMainInventorySlots(DrawObjectDM drawObjectDM, AbstractContainerMenu handler, int x, int y) { + RendererUtil.drawTexture(drawObjectDM, GuiTextures.GUI_PARTS, x, y, 0, 32, 162, 54); + } + + public static void drawPlayerHotbarSlots(DrawObjectDM drawObjectDM, AbstractContainerMenu 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/BlockEntityContainerGuiScreen.java b/common/src/main/java/net/pitan76/mcpitanlib/guilib/api/screen/BlockEntityContainerGuiScreen.java new file mode 100644 index 000000000..2dfdd1829 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/guilib/api/screen/BlockEntityContainerGuiScreen.java @@ -0,0 +1,22 @@ +package net.pitan76.mcpitanlib.guilib.api.screen; + +import net.minecraft.network.chat.Component; +import net.minecraft.world.entity.player.Inventory; +import net.pitan76.mcpitanlib.api.block.v3.CompatBlockEntity; +import net.pitan76.mcpitanlib.api.text.TextComponent; +import net.pitan76.mcpitanlib.api.util.inventory.CompatPlayerInventory; +import net.pitan76.mcpitanlib.guilib.api.container.BlockEntityContainerGui; + +public class BlockEntityContainerGuiScreen, B extends CompatBlockEntity> extends ContainerGuiScreen { + public BlockEntityContainerGuiScreen(T handler, Inventory inventory, Component title) { + super(handler, inventory, title); + } + + public BlockEntityContainerGuiScreen(T handler, CompatPlayerInventory inventory, TextComponent title) { + this(handler, inventory.getRaw(), title.getText()); + } + + public B getBlockEntity() { + return handler.getBlockEntity(); + } +} 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..1642245e0 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/guilib/api/screen/ContainerGuiScreen.java @@ -0,0 +1,92 @@ +package net.pitan76.mcpitanlib.guilib.api.screen; + +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.network.chat.Component; +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.text.TextComponent; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.api.util.ScreenHandlerUtil; +import net.pitan76.mcpitanlib.api.util.inventory.CompatPlayerInventory; +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, Inventory inventory, Component 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()); + } + + public ContainerGuiScreen(T handler, CompatPlayerInventory inventory, TextComponent title) { + this(handler, inventory.getRaw(), title.getText()); + } + + @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, titleLabelX, titleLabelY); + 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.container instanceof Inventory || 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..18dba7eef --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/guilib/api/screen/SimpleContainerGuiScreen.java @@ -0,0 +1,22 @@ +package net.pitan76.mcpitanlib.guilib.api.screen; + +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.network.chat.Component; +import net.pitan76.mcpitanlib.api.text.TextComponent; +import net.pitan76.mcpitanlib.api.util.inventory.CompatPlayerInventory; +import net.pitan76.mcpitanlib.guilib.api.container.SimpleContainerGui; + +public class SimpleContainerGuiScreen extends ContainerGuiScreen { + public SimpleContainerGuiScreen(SimpleContainerGui handler, Inventory inventory, Component title) { + super(handler, inventory, title); + } + + public SimpleContainerGuiScreen(SimpleContainerGui handler, CompatPlayerInventory inventory, TextComponent 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..2919a2a07 --- /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.world.entity.player.Inventory; +import net.minecraft.world.inventory.MenuType; +import net.pitan76.mcpitanlib.guilib.api.container.ContainerGui; + +public class TestContainer extends ContainerGui { + public TestContainer(MenuType type, int syncId) { + super(type, syncId); + } + + public TestContainer(int i, Inventory 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..5bf5c3a8b --- /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.world.level.block.Block; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.CreativeModeTab; +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(CreativeModeTab 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.world.level.material.Fluid fluid) { + return FluidWrapper.of(fluid); + } + + public static BlockState of(net.minecraft.world.level.block.state.BlockState state) { + return BlockState.of(state); + } + + public static NbtElement of(net.minecraft.nbt.Tag nbt) { + return NbtElement.of(nbt); + } + + public static NbtCompound of(net.minecraft.nbt.CompoundTag nbt) { + return NbtCompound.of(nbt); + } + + public static NbtList of(net.minecraft.nbt.ListTag nbt) { + return NbtList.of(nbt); + } + + public static BlockPos of(net.minecraft.core.BlockPos pos) { + return BlockPos.of(pos); + } + + public static Direction of(net.minecraft.core.Direction direction) { + return Direction.of(direction); + } + + public static World of(net.minecraft.world.level.Level world) { + return World.of(world); + } + + public static WorldView of(net.minecraft.world.level.LevelReader world) { + return WorldView.of(world); + } + + public static WorldAccess of(net.minecraft.world.level.LevelAccessor world) { + return WorldAccess.of(world); + } + + public static BlockView of(net.minecraft.world.level.BlockGetter world) { + return BlockView.of(world); + } + + public static IWorldView asWV(net.minecraft.world.level.LevelReader world) { + return of(world); + } + + public static IWorldView asWV(net.minecraft.world.level.BlockGetter world) { + return of(world); + } + + public static Item raw(ItemWrapper item) { + return item.get(); + } + + public static CreativeModeTab 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.world.level.material.Fluid raw(FluidWrapper fluid) { + return fluid.get(); + } + + public static net.minecraft.world.level.block.state.BlockState raw(BlockState state) { + return state.toMinecraft(); + } + + public static net.minecraft.nbt.Tag raw(NbtElement nbt) { + return nbt.toMinecraft(); + } + + public static net.minecraft.nbt.CompoundTag raw(NbtCompound nbt) { + return nbt.toMinecraft(); + } + + public static net.minecraft.nbt.ListTag raw(NbtList nbt) { + return nbt.toMinecraft(); + } + + public static net.minecraft.core.BlockPos raw(BlockPos pos) { + return pos.toMinecraft(); + } + + public static net.minecraft.core.Direction raw(Direction direction) { + return direction.toMinecraft(); + } + + public static net.minecraft.world.level.Level raw(World world) { + return world.toMinecraft(); + } + + public static net.minecraft.world.level.LevelReader raw(WorldView world) { + return world.toMinecraft(); + } + + public static net.minecraft.world.level.LevelAccessor raw(WorldAccess world) { + return world.toMinecraft(); + } + + public static net.minecraft.world.level.BlockGetter 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..458b60bea --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/BlockState.java @@ -0,0 +1,192 @@ +package net.pitan76.mcpitanlib.midohra.block; + +import net.minecraft.world.level.block.state.properties.Property; +import net.pitan76.mcpitanlib.api.sound.CompatBlockSoundGroup; +import net.pitan76.mcpitanlib.api.state.property.BlockHalfProperty; +import net.pitan76.mcpitanlib.api.state.property.DirectionProperty; +import net.pitan76.mcpitanlib.api.state.property.IProperty; +import net.pitan76.mcpitanlib.api.state.property.StairShapeProperty; +import net.pitan76.mcpitanlib.api.util.BlockStateUtil; +import net.pitan76.mcpitanlib.api.util.block.properties.CompatBlockHalf; +import net.pitan76.mcpitanlib.api.util.block.properties.CompatStairShape; +import net.pitan76.mcpitanlib.midohra.fluid.FluidState; +import net.pitan76.mcpitanlib.midohra.util.math.BlockPos; +import net.pitan76.mcpitanlib.midohra.world.ServerWorld; +import net.pitan76.mcpitanlib.midohra.world.World; + +public class BlockState { + private final net.minecraft.world.level.block.state.BlockState state; + + private BlockWrapper blockWrapper; + + protected BlockState(net.minecraft.world.level.block.state.BlockState state) { + this.state = state; + } + + public static BlockState of(net.minecraft.world.level.block.state.BlockState state) { + return new BlockState(state); + } + + public static BlockState of(net.minecraft.world.level.block.Block block) { + if (block == null) + return of((net.minecraft.world.level.block.state.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.world.level.block.state.BlockState toMinecraft() { + return state; + } + + public , V extends T> BlockState with(Property property, V value) { + return of(toMinecraft().setValue(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 with(BlockHalfProperty property, CompatBlockHalf value) { + return of(property.with(toMinecraft(), value.getBlockHalf())); + } + + public BlockState with(StairShapeProperty property, CompatStairShape value) { + return of(property.with(toMinecraft(), value.getStairShape())); + } + + 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().getValue(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 CompatBlockHalf get(BlockHalfProperty property) { + return CompatBlockHalf.of(get(property.getProperty())); + } + + public CompatStairShape get(StairShapeProperty property) { + return CompatStairShape.of(get(property.getProperty())); + } + + public > boolean contains(Property property) { + return toMinecraft().hasProperty(property); + } + + public > boolean contains(IProperty property) { + return contains(property.getProperty()); + } + + public boolean contains(DirectionProperty property) { + return contains(property.getProperty()); + } + + public boolean contains(BlockHalfProperty property) { + return contains(property.getProperty()); + } + + public boolean contains(StairShapeProperty 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); + } + + public int getLuminance() { + return BlockStateUtil.getLuminance(this); + } + + public int getOpacity() { + return BlockStateUtil.getOpacity(this); + } + + public int getComparatorOutput(World world, BlockPos pos) { + return BlockStateUtil.getComparatorOutput(this, world, pos); + } + + public float getHardness(World world, BlockPos pos) { + return BlockStateUtil.getHardness(this.toMinecraft(), world.getRaw(), pos.toRaw()); + } + + public boolean randomTick(ServerWorld world, BlockPos pos) { + if (!hasRandomTicks()) + return false; + + BlockStateUtil.randomTick(this.toMinecraft(), world.getRaw(), pos.toRaw()); + return true; + } + + public FluidState getFluidState() { + return FluidState.of(BlockStateUtil.getFluidState(this.toMinecraft())); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/BlockStateM.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/BlockStateM.java new file mode 100644 index 000000000..540980728 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/BlockStateM.java @@ -0,0 +1,30 @@ +package net.pitan76.mcpitanlib.midohra.block; + +import net.minecraft.world.level.block.Block; +import net.pitan76.mcpitanlib.api.util.BlockStateUtil; + +public class BlockStateM extends BlockState { + + public BlockStateM(net.minecraft.world.level.block.state.BlockState state) { + super(state); + } + + public BlockStateM(Block block) { + this(BlockStateUtil.getDefaultState(block)); + } + + public BlockStateM(BlockWrapper wrapper) { + this(wrapper.get()); + } + + public static BlockStateM of(net.minecraft.world.level.block.state.BlockState state) { + return new BlockStateM(state); + } + + public static BlockStateM of(Block block) { + if (block == null) + return of((net.minecraft.world.level.block.state.BlockState) null); + + return of(BlockStateUtil.getDefaultState(block)); + } +} 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..4e4c0b3ce --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/BlockWrapper.java @@ -0,0 +1,205 @@ +package net.pitan76.mcpitanlib.midohra.block; + +import net.minecraft.world.level.block.Block; +import net.pitan76.mcpitanlib.api.block.ICompatBlock; +import net.pitan76.mcpitanlib.api.block.v2.CompatBlock; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.api.util.block.BlockUtil; +import net.pitan76.mcpitanlib.midohra.easybuilder.built.BuiltBlock; +import net.pitan76.mcpitanlib.midohra.item.ItemWrapper; +import org.jetbrains.annotations.Nullable; + +import java.util.Optional; + +public class BlockWrapper { + private final net.minecraft.world.level.block.Block block; + + protected BlockWrapper() { + this.block = null; + } + + protected BlockWrapper(net.minecraft.world.level.block.Block block) { + this.block = block; + } + + public static BlockWrapper of(net.minecraft.world.level.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.world.level.block.Block get() { + return block; + } + + public net.minecraft.world.level.block.Block gerOrDefault(net.minecraft.world.level.block.Block defaultItem) { + return getOrDefault(defaultItem); + } + + public net.minecraft.world.level.block.Block getOrDefault(net.minecraft.world.level.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); + } + + public static BlockWrapper of(String id) { + return of(CompatIdentifier.of(id)); + } + + public static BlockWrapper of(String namespace, String path) { + return of(CompatIdentifier.of(namespace, path)); + } + + public static BlockWrapper of(CompatBlock block) { + return of((net.minecraft.world.level.block.Block) block); + } + + public Optional toCompatBlock() { + if (get() instanceof CompatBlock) { + return Optional.of((CompatBlock) get()); + } + return Optional.empty(); + } + + public Optional toBuiltBlock() { + if (get() instanceof BuiltBlock) { + return Optional.of((BuiltBlock) get()); + } + return Optional.empty(); + } + + public float getHardness() { + if (isEmpty()) return 0; + return BlockUtil.getHardness(block); + } + + public BlockStateM getDefaultStateM() { + return BlockStateM.of(get()); + } + + /** + * instanceof check for the block of this wrapper. + * @param clazz the class of the block to check + * @return true if the block of this wrapper is an instance of the given class, false otherwise + */ + public boolean instanceOf(Class clazz) { + if (isEmpty()) return false; + + return clazz.isInstance(get()); + } + + /** + * instanceof check for the block of this wrapper. + * @param wrapper the block to check + * @return true if the block of this wrapper is an instance of the given block, false otherwise + */ + public boolean instanceOf(BlockWrapper wrapper) { + if (isEmpty()) return false; + + Block block = wrapper.get(); + if (block == null) return false; + + Class clazz = block.getClass(); + return clazz.isInstance(get()); + } + + public T getCompatBlock(Class clazz) { + if (isEmpty()) return null; + if (get() instanceof CompatBlock) { + CompatBlock compatBlock = (CompatBlock) get(); + if (clazz.isInstance(compatBlock)) + return clazz.cast(compatBlock); + } + return null; + } + + public Optional toCompatBlock(Class clazz) { + return Optional.ofNullable(getCompatBlock(clazz)); + } + + public T getICompatBlock(Class clazz) { + if (isEmpty()) return null; + if (get() instanceof ICompatBlock) { + ICompatBlock compatBlock = (ICompatBlock) get(); + if (clazz.isInstance(compatBlock)) + return clazz.cast(compatBlock); + } + return null; + } + + public Optional toICompatBlock(Class clazz) { + return Optional.ofNullable(getICompatBlock(clazz)); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/Blocks.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/Blocks.java new file mode 100644 index 000000000..609786364 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/Blocks.java @@ -0,0 +1,780 @@ +package net.pitan76.mcpitanlib.midohra.block; + +import net.pitan76.mcpitanlib.api.util.block.BlockUtil; + +import java.util.List; +import java.util.stream.Collectors; + +public class Blocks { + public static BlockWrapper AIR = of(net.minecraft.world.level.block.Blocks.AIR); + public static BlockWrapper STONE = of(net.minecraft.world.level.block.Blocks.STONE); + public static BlockWrapper GRANITE = of(net.minecraft.world.level.block.Blocks.GRANITE); + public static BlockWrapper POLISHED_GRANITE = of(net.minecraft.world.level.block.Blocks.POLISHED_GRANITE); + public static BlockWrapper DIORITE = of(net.minecraft.world.level.block.Blocks.DIORITE); + public static BlockWrapper POLISHED_DIORITE = of(net.minecraft.world.level.block.Blocks.POLISHED_DIORITE); + public static BlockWrapper ANDESITE = of(net.minecraft.world.level.block.Blocks.ANDESITE); + public static BlockWrapper POLISHED_ANDESITE = of(net.minecraft.world.level.block.Blocks.POLISHED_ANDESITE); + public static BlockWrapper GRASS_BLOCK = of(net.minecraft.world.level.block.Blocks.GRASS_BLOCK); + public static BlockWrapper DIRT = of(net.minecraft.world.level.block.Blocks.DIRT); + public static BlockWrapper COARSE_DIRT = of(net.minecraft.world.level.block.Blocks.COARSE_DIRT); + public static BlockWrapper PODZOL = of(net.minecraft.world.level.block.Blocks.PODZOL); + public static BlockWrapper COBBLESTONE = of(net.minecraft.world.level.block.Blocks.COBBLESTONE); + public static BlockWrapper OAK_PLANKS = of(net.minecraft.world.level.block.Blocks.OAK_PLANKS); + public static BlockWrapper SPRUCE_PLANKS = of(net.minecraft.world.level.block.Blocks.SPRUCE_PLANKS); + public static BlockWrapper BIRCH_PLANKS = of(net.minecraft.world.level.block.Blocks.BIRCH_PLANKS); + public static BlockWrapper JUNGLE_PLANKS = of(net.minecraft.world.level.block.Blocks.JUNGLE_PLANKS); + public static BlockWrapper ACACIA_PLANKS = of(net.minecraft.world.level.block.Blocks.ACACIA_PLANKS); + public static BlockWrapper DARK_OAK_PLANKS = of(net.minecraft.world.level.block.Blocks.DARK_OAK_PLANKS); + public static BlockWrapper OAK_SAPLING = of(net.minecraft.world.level.block.Blocks.OAK_SAPLING); + public static BlockWrapper SPRUCE_SAPLING = of(net.minecraft.world.level.block.Blocks.SPRUCE_SAPLING); + public static BlockWrapper BIRCH_SAPLING = of(net.minecraft.world.level.block.Blocks.BIRCH_SAPLING); + public static BlockWrapper JUNGLE_SAPLING = of(net.minecraft.world.level.block.Blocks.JUNGLE_SAPLING); + public static BlockWrapper ACACIA_SAPLING = of(net.minecraft.world.level.block.Blocks.ACACIA_SAPLING); + public static BlockWrapper DARK_OAK_SAPLING = of(net.minecraft.world.level.block.Blocks.DARK_OAK_SAPLING); + public static BlockWrapper BEDROCK = of(net.minecraft.world.level.block.Blocks.BEDROCK); + public static BlockWrapper WATER = of(net.minecraft.world.level.block.Blocks.WATER); + public static BlockWrapper LAVA = of(net.minecraft.world.level.block.Blocks.LAVA); + public static BlockWrapper SAND = of(net.minecraft.world.level.block.Blocks.SAND); + public static BlockWrapper RED_SAND = of(net.minecraft.world.level.block.Blocks.RED_SAND); + public static BlockWrapper GRAVEL = of(net.minecraft.world.level.block.Blocks.GRAVEL); + public static BlockWrapper GOLD_ORE = of(net.minecraft.world.level.block.Blocks.GOLD_ORE); + public static BlockWrapper IRON_ORE = of(net.minecraft.world.level.block.Blocks.IRON_ORE); + public static BlockWrapper COAL_ORE = of(net.minecraft.world.level.block.Blocks.COAL_ORE); + public static BlockWrapper NETHER_GOLD_ORE = of(net.minecraft.world.level.block.Blocks.NETHER_GOLD_ORE); + public static BlockWrapper OAK_LOG = of(net.minecraft.world.level.block.Blocks.OAK_LOG); + public static BlockWrapper SPRUCE_LOG = of(net.minecraft.world.level.block.Blocks.SPRUCE_LOG); + public static BlockWrapper BIRCH_LOG = of(net.minecraft.world.level.block.Blocks.BIRCH_LOG); + public static BlockWrapper JUNGLE_LOG = of(net.minecraft.world.level.block.Blocks.JUNGLE_LOG); + public static BlockWrapper ACACIA_LOG = of(net.minecraft.world.level.block.Blocks.ACACIA_LOG); + public static BlockWrapper DARK_OAK_LOG = of(net.minecraft.world.level.block.Blocks.DARK_OAK_LOG); + public static BlockWrapper STRIPPED_SPRUCE_LOG = of(net.minecraft.world.level.block.Blocks.STRIPPED_SPRUCE_LOG); + public static BlockWrapper STRIPPED_BIRCH_LOG = of(net.minecraft.world.level.block.Blocks.STRIPPED_BIRCH_LOG); + public static BlockWrapper STRIPPED_JUNGLE_LOG = of(net.minecraft.world.level.block.Blocks.STRIPPED_JUNGLE_LOG); + public static BlockWrapper STRIPPED_ACACIA_LOG = of(net.minecraft.world.level.block.Blocks.STRIPPED_ACACIA_LOG); + public static BlockWrapper STRIPPED_DARK_OAK_LOG = of(net.minecraft.world.level.block.Blocks.STRIPPED_DARK_OAK_LOG); + public static BlockWrapper STRIPPED_OAK_LOG = of(net.minecraft.world.level.block.Blocks.STRIPPED_OAK_LOG); + public static BlockWrapper OAK_WOOD = of(net.minecraft.world.level.block.Blocks.OAK_WOOD); + public static BlockWrapper SPRUCE_WOOD = of(net.minecraft.world.level.block.Blocks.SPRUCE_WOOD); + public static BlockWrapper BIRCH_WOOD = of(net.minecraft.world.level.block.Blocks.BIRCH_WOOD); + public static BlockWrapper JUNGLE_WOOD = of(net.minecraft.world.level.block.Blocks.JUNGLE_WOOD); + public static BlockWrapper ACACIA_WOOD = of(net.minecraft.world.level.block.Blocks.ACACIA_WOOD); + public static BlockWrapper DARK_OAK_WOOD = of(net.minecraft.world.level.block.Blocks.DARK_OAK_WOOD); + public static BlockWrapper STRIPPED_OAK_WOOD = of(net.minecraft.world.level.block.Blocks.STRIPPED_OAK_WOOD); + public static BlockWrapper STRIPPED_SPRUCE_WOOD = of(net.minecraft.world.level.block.Blocks.STRIPPED_SPRUCE_WOOD); + public static BlockWrapper STRIPPED_BIRCH_WOOD = of(net.minecraft.world.level.block.Blocks.STRIPPED_BIRCH_WOOD); + public static BlockWrapper STRIPPED_JUNGLE_WOOD = of(net.minecraft.world.level.block.Blocks.STRIPPED_JUNGLE_WOOD); + public static BlockWrapper STRIPPED_ACACIA_WOOD = of(net.minecraft.world.level.block.Blocks.STRIPPED_ACACIA_WOOD); + public static BlockWrapper STRIPPED_DARK_OAK_WOOD = of(net.minecraft.world.level.block.Blocks.STRIPPED_DARK_OAK_WOOD); + public static BlockWrapper OAK_LEAVES = of(net.minecraft.world.level.block.Blocks.OAK_LEAVES); + public static BlockWrapper SPRUCE_LEAVES = of(net.minecraft.world.level.block.Blocks.SPRUCE_LEAVES); + public static BlockWrapper BIRCH_LEAVES = of(net.minecraft.world.level.block.Blocks.BIRCH_LEAVES); + public static BlockWrapper JUNGLE_LEAVES = of(net.minecraft.world.level.block.Blocks.JUNGLE_LEAVES); + public static BlockWrapper ACACIA_LEAVES = of(net.minecraft.world.level.block.Blocks.ACACIA_LEAVES); + public static BlockWrapper DARK_OAK_LEAVES = of(net.minecraft.world.level.block.Blocks.DARK_OAK_LEAVES); + public static BlockWrapper SPONGE = of(net.minecraft.world.level.block.Blocks.SPONGE); + public static BlockWrapper WET_SPONGE = of(net.minecraft.world.level.block.Blocks.WET_SPONGE); + public static BlockWrapper GLASS = of(net.minecraft.world.level.block.Blocks.GLASS); + public static BlockWrapper LAPIS_ORE = of(net.minecraft.world.level.block.Blocks.LAPIS_ORE); + public static BlockWrapper LAPIS_BLOCK = of(net.minecraft.world.level.block.Blocks.LAPIS_BLOCK); + public static BlockWrapper DISPENSER = of(net.minecraft.world.level.block.Blocks.DISPENSER); + public static BlockWrapper SANDSTONE = of(net.minecraft.world.level.block.Blocks.SANDSTONE); + public static BlockWrapper CHISELED_SANDSTONE = of(net.minecraft.world.level.block.Blocks.CHISELED_SANDSTONE); + public static BlockWrapper CUT_SANDSTONE = of(net.minecraft.world.level.block.Blocks.CUT_SANDSTONE); + public static BlockWrapper NOTE_BLOCK = of(net.minecraft.world.level.block.Blocks.NOTE_BLOCK); + public static BlockWrapper WHITE_BED = of(net.minecraft.world.level.block.Blocks.WHITE_BED); + public static BlockWrapper ORANGE_BED = of(net.minecraft.world.level.block.Blocks.ORANGE_BED); + public static BlockWrapper MAGENTA_BED = of(net.minecraft.world.level.block.Blocks.MAGENTA_BED); + public static BlockWrapper LIGHT_BLUE_BED = of(net.minecraft.world.level.block.Blocks.LIGHT_BLUE_BED); + public static BlockWrapper YELLOW_BED = of(net.minecraft.world.level.block.Blocks.YELLOW_BED); + public static BlockWrapper LIME_BED = of(net.minecraft.world.level.block.Blocks.LIME_BED); + public static BlockWrapper PINK_BED = of(net.minecraft.world.level.block.Blocks.PINK_BED); + public static BlockWrapper GRAY_BED = of(net.minecraft.world.level.block.Blocks.GRAY_BED); + public static BlockWrapper LIGHT_GRAY_BED = of(net.minecraft.world.level.block.Blocks.LIGHT_GRAY_BED); + public static BlockWrapper CYAN_BED = of(net.minecraft.world.level.block.Blocks.CYAN_BED); + public static BlockWrapper PURPLE_BED = of(net.minecraft.world.level.block.Blocks.PURPLE_BED); + public static BlockWrapper BLUE_BED = of(net.minecraft.world.level.block.Blocks.BLUE_BED); + public static BlockWrapper BROWN_BED = of(net.minecraft.world.level.block.Blocks.BROWN_BED); + public static BlockWrapper GREEN_BED = of(net.minecraft.world.level.block.Blocks.GREEN_BED); + public static BlockWrapper RED_BED = of(net.minecraft.world.level.block.Blocks.RED_BED); + public static BlockWrapper BLACK_BED = of(net.minecraft.world.level.block.Blocks.BLACK_BED); + public static BlockWrapper POWERED_RAIL = of(net.minecraft.world.level.block.Blocks.POWERED_RAIL); + public static BlockWrapper DETECTOR_RAIL = of(net.minecraft.world.level.block.Blocks.DETECTOR_RAIL); + public static BlockWrapper STICKY_PISTON = of(net.minecraft.world.level.block.Blocks.STICKY_PISTON); + public static BlockWrapper COBWEB = of(net.minecraft.world.level.block.Blocks.COBWEB); + public static BlockWrapper GRASS = of(net.minecraft.world.level.block.Blocks.SHORT_GRASS); + public static BlockWrapper FERN = of(net.minecraft.world.level.block.Blocks.FERN); + public static BlockWrapper DEAD_BUSH = of(net.minecraft.world.level.block.Blocks.DEAD_BUSH); + public static BlockWrapper SEAGRASS = of(net.minecraft.world.level.block.Blocks.SEAGRASS); + public static BlockWrapper TALL_SEAGRASS = of(net.minecraft.world.level.block.Blocks.TALL_SEAGRASS); + public static BlockWrapper PISTON = of(net.minecraft.world.level.block.Blocks.PISTON); + public static BlockWrapper PISTON_HEAD = of(net.minecraft.world.level.block.Blocks.PISTON_HEAD); + public static BlockWrapper WHITE_WOOL = of(net.minecraft.world.level.block.Blocks.WHITE_WOOL); + public static BlockWrapper ORANGE_WOOL = of(net.minecraft.world.level.block.Blocks.ORANGE_WOOL); + public static BlockWrapper MAGENTA_WOOL = of(net.minecraft.world.level.block.Blocks.MAGENTA_WOOL); + public static BlockWrapper LIGHT_BLUE_WOOL = of(net.minecraft.world.level.block.Blocks.LIGHT_BLUE_WOOL); + public static BlockWrapper YELLOW_WOOL = of(net.minecraft.world.level.block.Blocks.YELLOW_WOOL); + public static BlockWrapper LIME_WOOL = of(net.minecraft.world.level.block.Blocks.LIME_WOOL); + public static BlockWrapper PINK_WOOL = of(net.minecraft.world.level.block.Blocks.PINK_WOOL); + public static BlockWrapper GRAY_WOOL = of(net.minecraft.world.level.block.Blocks.GRAY_WOOL); + public static BlockWrapper LIGHT_GRAY_WOOL = of(net.minecraft.world.level.block.Blocks.LIGHT_GRAY_WOOL); + public static BlockWrapper CYAN_WOOL = of(net.minecraft.world.level.block.Blocks.CYAN_WOOL); + public static BlockWrapper PURPLE_WOOL = of(net.minecraft.world.level.block.Blocks.PURPLE_WOOL); + public static BlockWrapper BLUE_WOOL = of(net.minecraft.world.level.block.Blocks.BLUE_WOOL); + public static BlockWrapper BROWN_WOOL = of(net.minecraft.world.level.block.Blocks.BROWN_WOOL); + public static BlockWrapper GREEN_WOOL = of(net.minecraft.world.level.block.Blocks.GREEN_WOOL); + public static BlockWrapper RED_WOOL = of(net.minecraft.world.level.block.Blocks.RED_WOOL); + public static BlockWrapper BLACK_WOOL = of(net.minecraft.world.level.block.Blocks.BLACK_WOOL); + public static BlockWrapper MOVING_PISTON = of(net.minecraft.world.level.block.Blocks.MOVING_PISTON); + public static BlockWrapper DANDELION = of(net.minecraft.world.level.block.Blocks.DANDELION); + public static BlockWrapper POPPY = of(net.minecraft.world.level.block.Blocks.POPPY); + public static BlockWrapper BLUE_ORCHID = of(net.minecraft.world.level.block.Blocks.BLUE_ORCHID); + public static BlockWrapper ALLIUM = of(net.minecraft.world.level.block.Blocks.ALLIUM); + public static BlockWrapper AZURE_BLUET = of(net.minecraft.world.level.block.Blocks.AZURE_BLUET); + public static BlockWrapper RED_TULIP = of(net.minecraft.world.level.block.Blocks.RED_TULIP); + public static BlockWrapper ORANGE_TULIP = of(net.minecraft.world.level.block.Blocks.ORANGE_TULIP); + public static BlockWrapper WHITE_TULIP = of(net.minecraft.world.level.block.Blocks.WHITE_TULIP); + public static BlockWrapper PINK_TULIP = of(net.minecraft.world.level.block.Blocks.PINK_TULIP); + public static BlockWrapper OXEYE_DAISY = of(net.minecraft.world.level.block.Blocks.OXEYE_DAISY); + public static BlockWrapper CORNFLOWER = of(net.minecraft.world.level.block.Blocks.CORNFLOWER); + public static BlockWrapper WITHER_ROSE = of(net.minecraft.world.level.block.Blocks.WITHER_ROSE); + public static BlockWrapper LILY_OF_THE_VALLEY = of(net.minecraft.world.level.block.Blocks.LILY_OF_THE_VALLEY); + public static BlockWrapper BROWN_MUSHROOM = of(net.minecraft.world.level.block.Blocks.BROWN_MUSHROOM); + public static BlockWrapper RED_MUSHROOM = of(net.minecraft.world.level.block.Blocks.RED_MUSHROOM); + public static BlockWrapper GOLD_BLOCK = of(net.minecraft.world.level.block.Blocks.GOLD_BLOCK); + public static BlockWrapper IRON_BLOCK = of(net.minecraft.world.level.block.Blocks.IRON_BLOCK); + public static BlockWrapper BRICKS = of(net.minecraft.world.level.block.Blocks.BRICKS); + public static BlockWrapper TNT = of(net.minecraft.world.level.block.Blocks.TNT); + public static BlockWrapper BOOKSHELF = of(net.minecraft.world.level.block.Blocks.BOOKSHELF); + public static BlockWrapper MOSSY_COBBLESTONE = of(net.minecraft.world.level.block.Blocks.MOSSY_COBBLESTONE); + public static BlockWrapper OBSIDIAN = of(net.minecraft.world.level.block.Blocks.OBSIDIAN); + public static BlockWrapper TORCH = of(net.minecraft.world.level.block.Blocks.TORCH); + public static BlockWrapper WALL_TORCH = of(net.minecraft.world.level.block.Blocks.WALL_TORCH); + public static BlockWrapper FIRE = of(net.minecraft.world.level.block.Blocks.FIRE); + public static BlockWrapper SOUL_FIRE = of(net.minecraft.world.level.block.Blocks.SOUL_FIRE); + public static BlockWrapper SPAWNER = of(net.minecraft.world.level.block.Blocks.SPAWNER); + public static BlockWrapper OAK_STAIRS = of(net.minecraft.world.level.block.Blocks.OAK_STAIRS); + public static BlockWrapper CHEST = of(net.minecraft.world.level.block.Blocks.CHEST); + public static BlockWrapper REDSTONE_WIRE = of(net.minecraft.world.level.block.Blocks.REDSTONE_WIRE); + public static BlockWrapper DIAMOND_ORE = of(net.minecraft.world.level.block.Blocks.DIAMOND_ORE); + public static BlockWrapper DIAMOND_BLOCK = of(net.minecraft.world.level.block.Blocks.DIAMOND_BLOCK); + public static BlockWrapper CRAFTING_TABLE = of(net.minecraft.world.level.block.Blocks.CRAFTING_TABLE); + public static BlockWrapper WHEAT = of(net.minecraft.world.level.block.Blocks.WHEAT); + public static BlockWrapper FARMLAND = of(net.minecraft.world.level.block.Blocks.FARMLAND); + public static BlockWrapper FURNACE = of(net.minecraft.world.level.block.Blocks.FURNACE); + public static BlockWrapper OAK_SIGN = of(net.minecraft.world.level.block.Blocks.OAK_SIGN); + public static BlockWrapper SPRUCE_SIGN = of(net.minecraft.world.level.block.Blocks.SPRUCE_SIGN); + public static BlockWrapper BIRCH_SIGN = of(net.minecraft.world.level.block.Blocks.BIRCH_SIGN); + public static BlockWrapper ACACIA_SIGN = of(net.minecraft.world.level.block.Blocks.ACACIA_SIGN); + public static BlockWrapper JUNGLE_SIGN = of(net.minecraft.world.level.block.Blocks.JUNGLE_SIGN); + public static BlockWrapper DARK_OAK_SIGN = of(net.minecraft.world.level.block.Blocks.DARK_OAK_SIGN); + public static BlockWrapper OAK_DOOR = of(net.minecraft.world.level.block.Blocks.OAK_DOOR); + public static BlockWrapper LADDER = of(net.minecraft.world.level.block.Blocks.LADDER); + public static BlockWrapper RAIL = of(net.minecraft.world.level.block.Blocks.RAIL); + public static BlockWrapper COBBLESTONE_STAIRS = of(net.minecraft.world.level.block.Blocks.COBBLESTONE_STAIRS); + public static BlockWrapper OAK_WALL_SIGN = of(net.minecraft.world.level.block.Blocks.OAK_WALL_SIGN); + public static BlockWrapper SPRUCE_WALL_SIGN = of(net.minecraft.world.level.block.Blocks.SPRUCE_WALL_SIGN); + public static BlockWrapper BIRCH_WALL_SIGN = of(net.minecraft.world.level.block.Blocks.BIRCH_WALL_SIGN); + public static BlockWrapper ACACIA_WALL_SIGN = of(net.minecraft.world.level.block.Blocks.ACACIA_WALL_SIGN); + public static BlockWrapper JUNGLE_WALL_SIGN = of(net.minecraft.world.level.block.Blocks.JUNGLE_WALL_SIGN); + public static BlockWrapper DARK_OAK_WALL_SIGN = of(net.minecraft.world.level.block.Blocks.DARK_OAK_WALL_SIGN); + public static BlockWrapper LEVER = of(net.minecraft.world.level.block.Blocks.LEVER); + public static BlockWrapper STONE_PRESSURE_PLATE = of(net.minecraft.world.level.block.Blocks.STONE_PRESSURE_PLATE); + public static BlockWrapper IRON_DOOR = of(net.minecraft.world.level.block.Blocks.IRON_DOOR); + public static BlockWrapper OAK_PRESSURE_PLATE = of(net.minecraft.world.level.block.Blocks.OAK_PRESSURE_PLATE); + public static BlockWrapper SPRUCE_PRESSURE_PLATE = of(net.minecraft.world.level.block.Blocks.SPRUCE_PRESSURE_PLATE); + public static BlockWrapper BIRCH_PRESSURE_PLATE = of(net.minecraft.world.level.block.Blocks.BIRCH_PRESSURE_PLATE); + public static BlockWrapper JUNGLE_PRESSURE_PLATE = of(net.minecraft.world.level.block.Blocks.JUNGLE_PRESSURE_PLATE); + public static BlockWrapper ACACIA_PRESSURE_PLATE = of(net.minecraft.world.level.block.Blocks.ACACIA_PRESSURE_PLATE); + public static BlockWrapper DARK_OAK_PRESSURE_PLATE = of(net.minecraft.world.level.block.Blocks.DARK_OAK_PRESSURE_PLATE); + public static BlockWrapper REDSTONE_ORE = of(net.minecraft.world.level.block.Blocks.REDSTONE_ORE); + public static BlockWrapper REDSTONE_TORCH = of(net.minecraft.world.level.block.Blocks.REDSTONE_TORCH); + public static BlockWrapper REDSTONE_WALL_TORCH = of(net.minecraft.world.level.block.Blocks.REDSTONE_WALL_TORCH); + public static BlockWrapper STONE_BUTTON = of(net.minecraft.world.level.block.Blocks.STONE_BUTTON); + public static BlockWrapper SNOW = of(net.minecraft.world.level.block.Blocks.SNOW); + public static BlockWrapper ICE = of(net.minecraft.world.level.block.Blocks.ICE); + public static BlockWrapper SNOW_BLOCK = of(net.minecraft.world.level.block.Blocks.SNOW_BLOCK); + public static BlockWrapper CACTUS = of(net.minecraft.world.level.block.Blocks.CACTUS); + public static BlockWrapper CLAY = of(net.minecraft.world.level.block.Blocks.CLAY); + public static BlockWrapper SUGAR_CANE = of(net.minecraft.world.level.block.Blocks.SUGAR_CANE); + public static BlockWrapper JUKEBOX = of(net.minecraft.world.level.block.Blocks.JUKEBOX); + public static BlockWrapper OAK_FENCE = of(net.minecraft.world.level.block.Blocks.OAK_FENCE); + public static BlockWrapper PUMPKIN = of(net.minecraft.world.level.block.Blocks.PUMPKIN); + public static BlockWrapper NETHERRACK = of(net.minecraft.world.level.block.Blocks.NETHERRACK); + public static BlockWrapper SOUL_SAND = of(net.minecraft.world.level.block.Blocks.SOUL_SAND); + public static BlockWrapper SOUL_SOIL = of(net.minecraft.world.level.block.Blocks.SOUL_SOIL); + public static BlockWrapper BASALT = of(net.minecraft.world.level.block.Blocks.BASALT); + public static BlockWrapper POLISHED_BASALT = of(net.minecraft.world.level.block.Blocks.POLISHED_BASALT); + public static BlockWrapper SOUL_TORCH = of(net.minecraft.world.level.block.Blocks.SOUL_TORCH); + public static BlockWrapper SOUL_WALL_TORCH = of(net.minecraft.world.level.block.Blocks.SOUL_WALL_TORCH); + public static BlockWrapper GLOWSTONE = of(net.minecraft.world.level.block.Blocks.GLOWSTONE); + public static BlockWrapper NETHER_PORTAL = of(net.minecraft.world.level.block.Blocks.NETHER_PORTAL); + public static BlockWrapper CARVED_PUMPKIN = of(net.minecraft.world.level.block.Blocks.CARVED_PUMPKIN); + public static BlockWrapper JACK_O_LANTERN = of(net.minecraft.world.level.block.Blocks.JACK_O_LANTERN); + public static BlockWrapper CAKE = of(net.minecraft.world.level.block.Blocks.CAKE); + public static BlockWrapper REPEATER = of(net.minecraft.world.level.block.Blocks.REPEATER); + public static BlockWrapper WHITE_STAINED_GLASS = of(net.minecraft.world.level.block.Blocks.WHITE_STAINED_GLASS); + public static BlockWrapper ORANGE_STAINED_GLASS = of(net.minecraft.world.level.block.Blocks.ORANGE_STAINED_GLASS); + public static BlockWrapper MAGENTA_STAINED_GLASS = of(net.minecraft.world.level.block.Blocks.MAGENTA_STAINED_GLASS); + public static BlockWrapper LIGHT_BLUE_STAINED_GLASS = of(net.minecraft.world.level.block.Blocks.LIGHT_BLUE_STAINED_GLASS); + public static BlockWrapper YELLOW_STAINED_GLASS = of(net.minecraft.world.level.block.Blocks.YELLOW_STAINED_GLASS); + public static BlockWrapper LIME_STAINED_GLASS = of(net.minecraft.world.level.block.Blocks.LIME_STAINED_GLASS); + public static BlockWrapper PINK_STAINED_GLASS = of(net.minecraft.world.level.block.Blocks.PINK_STAINED_GLASS); + public static BlockWrapper GRAY_STAINED_GLASS = of(net.minecraft.world.level.block.Blocks.GRAY_STAINED_GLASS); + public static BlockWrapper LIGHT_GRAY_STAINED_GLASS = of(net.minecraft.world.level.block.Blocks.LIGHT_GRAY_STAINED_GLASS); + public static BlockWrapper CYAN_STAINED_GLASS = of(net.minecraft.world.level.block.Blocks.CYAN_STAINED_GLASS); + public static BlockWrapper PURPLE_STAINED_GLASS = of(net.minecraft.world.level.block.Blocks.PURPLE_STAINED_GLASS); + public static BlockWrapper BLUE_STAINED_GLASS = of(net.minecraft.world.level.block.Blocks.BLUE_STAINED_GLASS); + public static BlockWrapper BROWN_STAINED_GLASS = of(net.minecraft.world.level.block.Blocks.BROWN_STAINED_GLASS); + public static BlockWrapper GREEN_STAINED_GLASS = of(net.minecraft.world.level.block.Blocks.GREEN_STAINED_GLASS); + public static BlockWrapper RED_STAINED_GLASS = of(net.minecraft.world.level.block.Blocks.RED_STAINED_GLASS); + public static BlockWrapper BLACK_STAINED_GLASS = of(net.minecraft.world.level.block.Blocks.BLACK_STAINED_GLASS); + public static BlockWrapper OAK_TRAPDOOR = of(net.minecraft.world.level.block.Blocks.OAK_TRAPDOOR); + public static BlockWrapper SPRUCE_TRAPDOOR = of(net.minecraft.world.level.block.Blocks.SPRUCE_TRAPDOOR); + public static BlockWrapper BIRCH_TRAPDOOR = of(net.minecraft.world.level.block.Blocks.BIRCH_TRAPDOOR); + public static BlockWrapper JUNGLE_TRAPDOOR = of(net.minecraft.world.level.block.Blocks.JUNGLE_TRAPDOOR); + public static BlockWrapper ACACIA_TRAPDOOR = of(net.minecraft.world.level.block.Blocks.ACACIA_TRAPDOOR); + public static BlockWrapper DARK_OAK_TRAPDOOR = of(net.minecraft.world.level.block.Blocks.DARK_OAK_TRAPDOOR); + public static BlockWrapper STONE_BRICKS = of(net.minecraft.world.level.block.Blocks.STONE_BRICKS); + public static BlockWrapper MOSSY_STONE_BRICKS = of(net.minecraft.world.level.block.Blocks.MOSSY_STONE_BRICKS); + public static BlockWrapper CRACKED_STONE_BRICKS = of(net.minecraft.world.level.block.Blocks.CRACKED_STONE_BRICKS); + public static BlockWrapper CHISELED_STONE_BRICKS = of(net.minecraft.world.level.block.Blocks.CHISELED_STONE_BRICKS); + public static BlockWrapper INFESTED_STONE = of(net.minecraft.world.level.block.Blocks.INFESTED_STONE); + public static BlockWrapper INFESTED_COBBLESTONE = of(net.minecraft.world.level.block.Blocks.INFESTED_COBBLESTONE); + public static BlockWrapper INFESTED_STONE_BRICKS = of(net.minecraft.world.level.block.Blocks.INFESTED_STONE_BRICKS); + public static BlockWrapper INFESTED_MOSSY_STONE_BRICKS = of(net.minecraft.world.level.block.Blocks.INFESTED_MOSSY_STONE_BRICKS); + public static BlockWrapper INFESTED_CRACKED_STONE_BRICKS = of(net.minecraft.world.level.block.Blocks.INFESTED_CRACKED_STONE_BRICKS); + public static BlockWrapper INFESTED_CHISELED_STONE_BRICKS = of(net.minecraft.world.level.block.Blocks.INFESTED_CHISELED_STONE_BRICKS); + public static BlockWrapper BROWN_MUSHROOM_BLOCK = of(net.minecraft.world.level.block.Blocks.BROWN_MUSHROOM_BLOCK); + public static BlockWrapper RED_MUSHROOM_BLOCK = of(net.minecraft.world.level.block.Blocks.RED_MUSHROOM_BLOCK); + public static BlockWrapper MUSHROOM_STEM = of(net.minecraft.world.level.block.Blocks.MUSHROOM_STEM); + public static BlockWrapper IRON_BARS = of(net.minecraft.world.level.block.Blocks.IRON_BARS); + public static BlockWrapper CHAIN = of(net.minecraft.world.level.block.Blocks.IRON_CHAIN); + public static BlockWrapper GLASS_PANE = of(net.minecraft.world.level.block.Blocks.GLASS_PANE); + public static BlockWrapper MELON = of(net.minecraft.world.level.block.Blocks.MELON); + public static BlockWrapper ATTACHED_PUMPKIN_STEM = of(net.minecraft.world.level.block.Blocks.ATTACHED_PUMPKIN_STEM); + public static BlockWrapper ATTACHED_MELON_STEM = of(net.minecraft.world.level.block.Blocks.ATTACHED_MELON_STEM); + public static BlockWrapper PUMPKIN_STEM = of(net.minecraft.world.level.block.Blocks.PUMPKIN_STEM); + public static BlockWrapper MELON_STEM = of(net.minecraft.world.level.block.Blocks.MELON_STEM); + public static BlockWrapper VINE = of(net.minecraft.world.level.block.Blocks.VINE); + public static BlockWrapper OAK_FENCE_GATE = of(net.minecraft.world.level.block.Blocks.OAK_FENCE_GATE); + public static BlockWrapper BRICK_STAIRS = of(net.minecraft.world.level.block.Blocks.BRICK_STAIRS); + public static BlockWrapper STONE_BRICK_STAIRS = of(net.minecraft.world.level.block.Blocks.STONE_BRICK_STAIRS); + public static BlockWrapper MYCELIUM = of(net.minecraft.world.level.block.Blocks.MYCELIUM); + public static BlockWrapper LILY_PAD = of(net.minecraft.world.level.block.Blocks.LILY_PAD); + public static BlockWrapper NETHER_BRICKS = of(net.minecraft.world.level.block.Blocks.NETHER_BRICKS); + public static BlockWrapper NETHER_BRICK_FENCE = of(net.minecraft.world.level.block.Blocks.NETHER_BRICK_FENCE); + public static BlockWrapper NETHER_BRICK_STAIRS = of(net.minecraft.world.level.block.Blocks.NETHER_BRICK_STAIRS); + public static BlockWrapper NETHER_WART = of(net.minecraft.world.level.block.Blocks.NETHER_WART); + public static BlockWrapper ENCHANTING_TABLE = of(net.minecraft.world.level.block.Blocks.ENCHANTING_TABLE); + public static BlockWrapper BREWING_STAND = of(net.minecraft.world.level.block.Blocks.BREWING_STAND); + public static BlockWrapper CAULDRON = of(net.minecraft.world.level.block.Blocks.CAULDRON); + public static BlockWrapper END_PORTAL = of(net.minecraft.world.level.block.Blocks.END_PORTAL); + public static BlockWrapper END_PORTAL_FRAME = of(net.minecraft.world.level.block.Blocks.END_PORTAL_FRAME); + public static BlockWrapper END_STONE = of(net.minecraft.world.level.block.Blocks.END_STONE); + public static BlockWrapper DRAGON_EGG = of(net.minecraft.world.level.block.Blocks.DRAGON_EGG); + public static BlockWrapper REDSTONE_LAMP = of(net.minecraft.world.level.block.Blocks.REDSTONE_LAMP); + public static BlockWrapper COCOA = of(net.minecraft.world.level.block.Blocks.COCOA); + public static BlockWrapper SANDSTONE_STAIRS = of(net.minecraft.world.level.block.Blocks.SANDSTONE_STAIRS); + public static BlockWrapper EMERALD_ORE = of(net.minecraft.world.level.block.Blocks.EMERALD_ORE); + public static BlockWrapper ENDER_CHEST = of(net.minecraft.world.level.block.Blocks.ENDER_CHEST); + public static BlockWrapper TRIPWIRE_HOOK = of(net.minecraft.world.level.block.Blocks.TRIPWIRE_HOOK); + public static BlockWrapper TRIPWIRE = of(net.minecraft.world.level.block.Blocks.TRIPWIRE); + public static BlockWrapper EMERALD_BLOCK = of(net.minecraft.world.level.block.Blocks.EMERALD_BLOCK); + public static BlockWrapper SPRUCE_STAIRS = of(net.minecraft.world.level.block.Blocks.SPRUCE_STAIRS); + public static BlockWrapper BIRCH_STAIRS = of(net.minecraft.world.level.block.Blocks.BIRCH_STAIRS); + public static BlockWrapper JUNGLE_STAIRS = of(net.minecraft.world.level.block.Blocks.JUNGLE_STAIRS); + public static BlockWrapper COMMAND_BLOCK = of(net.minecraft.world.level.block.Blocks.COMMAND_BLOCK); + public static BlockWrapper BEACON = of(net.minecraft.world.level.block.Blocks.BEACON); + public static BlockWrapper COBBLESTONE_WALL = of(net.minecraft.world.level.block.Blocks.COBBLESTONE_WALL); + public static BlockWrapper MOSSY_COBBLESTONE_WALL = of(net.minecraft.world.level.block.Blocks.MOSSY_COBBLESTONE_WALL); + public static BlockWrapper FLOWER_POT = of(net.minecraft.world.level.block.Blocks.FLOWER_POT); + public static BlockWrapper POTTED_OAK_SAPLING = of(net.minecraft.world.level.block.Blocks.POTTED_OAK_SAPLING); + public static BlockWrapper POTTED_SPRUCE_SAPLING = of(net.minecraft.world.level.block.Blocks.POTTED_SPRUCE_SAPLING); + public static BlockWrapper POTTED_BIRCH_SAPLING = of(net.minecraft.world.level.block.Blocks.POTTED_BIRCH_SAPLING); + public static BlockWrapper POTTED_JUNGLE_SAPLING = of(net.minecraft.world.level.block.Blocks.POTTED_JUNGLE_SAPLING); + public static BlockWrapper POTTED_ACACIA_SAPLING = of(net.minecraft.world.level.block.Blocks.POTTED_ACACIA_SAPLING); + public static BlockWrapper POTTED_DARK_OAK_SAPLING = of(net.minecraft.world.level.block.Blocks.POTTED_DARK_OAK_SAPLING); + public static BlockWrapper POTTED_FERN = of(net.minecraft.world.level.block.Blocks.POTTED_FERN); + public static BlockWrapper POTTED_DANDELION = of(net.minecraft.world.level.block.Blocks.POTTED_DANDELION); + public static BlockWrapper POTTED_POPPY = of(net.minecraft.world.level.block.Blocks.POTTED_POPPY); + public static BlockWrapper POTTED_BLUE_ORCHID = of(net.minecraft.world.level.block.Blocks.POTTED_BLUE_ORCHID); + public static BlockWrapper POTTED_ALLIUM = of(net.minecraft.world.level.block.Blocks.POTTED_ALLIUM); + public static BlockWrapper POTTED_AZURE_BLUET = of(net.minecraft.world.level.block.Blocks.POTTED_AZURE_BLUET); + public static BlockWrapper POTTED_RED_TULIP = of(net.minecraft.world.level.block.Blocks.POTTED_RED_TULIP); + public static BlockWrapper POTTED_ORANGE_TULIP = of(net.minecraft.world.level.block.Blocks.POTTED_ORANGE_TULIP); + public static BlockWrapper POTTED_WHITE_TULIP = of(net.minecraft.world.level.block.Blocks.POTTED_WHITE_TULIP); + public static BlockWrapper POTTED_PINK_TULIP = of(net.minecraft.world.level.block.Blocks.POTTED_PINK_TULIP); + public static BlockWrapper POTTED_OXEYE_DAISY = of(net.minecraft.world.level.block.Blocks.POTTED_OXEYE_DAISY); + public static BlockWrapper POTTED_CORNFLOWER = of(net.minecraft.world.level.block.Blocks.POTTED_CORNFLOWER); + public static BlockWrapper POTTED_LILY_OF_THE_VALLEY = of(net.minecraft.world.level.block.Blocks.POTTED_LILY_OF_THE_VALLEY); + public static BlockWrapper POTTED_WITHER_ROSE = of(net.minecraft.world.level.block.Blocks.POTTED_WITHER_ROSE); + public static BlockWrapper POTTED_RED_MUSHROOM = of(net.minecraft.world.level.block.Blocks.POTTED_RED_MUSHROOM); + public static BlockWrapper POTTED_BROWN_MUSHROOM = of(net.minecraft.world.level.block.Blocks.POTTED_BROWN_MUSHROOM); + public static BlockWrapper POTTED_DEAD_BUSH = of(net.minecraft.world.level.block.Blocks.POTTED_DEAD_BUSH); + public static BlockWrapper POTTED_CACTUS = of(net.minecraft.world.level.block.Blocks.POTTED_CACTUS); + public static BlockWrapper CARROTS = of(net.minecraft.world.level.block.Blocks.CARROTS); + public static BlockWrapper POTATOES = of(net.minecraft.world.level.block.Blocks.POTATOES); + public static BlockWrapper OAK_BUTTON = of(net.minecraft.world.level.block.Blocks.OAK_BUTTON); + public static BlockWrapper SPRUCE_BUTTON = of(net.minecraft.world.level.block.Blocks.SPRUCE_BUTTON); + public static BlockWrapper BIRCH_BUTTON = of(net.minecraft.world.level.block.Blocks.BIRCH_BUTTON); + public static BlockWrapper JUNGLE_BUTTON = of(net.minecraft.world.level.block.Blocks.JUNGLE_BUTTON); + public static BlockWrapper ACACIA_BUTTON = of(net.minecraft.world.level.block.Blocks.ACACIA_BUTTON); + public static BlockWrapper DARK_OAK_BUTTON = of(net.minecraft.world.level.block.Blocks.DARK_OAK_BUTTON); + public static BlockWrapper SKELETON_SKULL = of(net.minecraft.world.level.block.Blocks.SKELETON_SKULL); + public static BlockWrapper SKELETON_WALL_SKULL = of(net.minecraft.world.level.block.Blocks.SKELETON_WALL_SKULL); + public static BlockWrapper WITHER_SKELETON_SKULL = of(net.minecraft.world.level.block.Blocks.WITHER_SKELETON_SKULL); + public static BlockWrapper WITHER_SKELETON_WALL_SKULL = of(net.minecraft.world.level.block.Blocks.WITHER_SKELETON_WALL_SKULL); + public static BlockWrapper ZOMBIE_HEAD = of(net.minecraft.world.level.block.Blocks.ZOMBIE_HEAD); + public static BlockWrapper ZOMBIE_WALL_HEAD = of(net.minecraft.world.level.block.Blocks.ZOMBIE_WALL_HEAD); + public static BlockWrapper PLAYER_HEAD = of(net.minecraft.world.level.block.Blocks.PLAYER_HEAD); + public static BlockWrapper PLAYER_WALL_HEAD = of(net.minecraft.world.level.block.Blocks.PLAYER_WALL_HEAD); + public static BlockWrapper CREEPER_HEAD = of(net.minecraft.world.level.block.Blocks.CREEPER_HEAD); + public static BlockWrapper CREEPER_WALL_HEAD = of(net.minecraft.world.level.block.Blocks.CREEPER_WALL_HEAD); + public static BlockWrapper DRAGON_HEAD = of(net.minecraft.world.level.block.Blocks.DRAGON_HEAD); + public static BlockWrapper DRAGON_WALL_HEAD = of(net.minecraft.world.level.block.Blocks.DRAGON_WALL_HEAD); + public static BlockWrapper ANVIL = of(net.minecraft.world.level.block.Blocks.ANVIL); + public static BlockWrapper CHIPPED_ANVIL = of(net.minecraft.world.level.block.Blocks.CHIPPED_ANVIL); + public static BlockWrapper DAMAGED_ANVIL = of(net.minecraft.world.level.block.Blocks.DAMAGED_ANVIL); + public static BlockWrapper TRAPPED_CHEST = of(net.minecraft.world.level.block.Blocks.TRAPPED_CHEST); + public static BlockWrapper LIGHT_WEIGHTED_PRESSURE_PLATE = of(net.minecraft.world.level.block.Blocks.LIGHT_WEIGHTED_PRESSURE_PLATE); + public static BlockWrapper HEAVY_WEIGHTED_PRESSURE_PLATE = of(net.minecraft.world.level.block.Blocks.HEAVY_WEIGHTED_PRESSURE_PLATE); + public static BlockWrapper COMPARATOR = of(net.minecraft.world.level.block.Blocks.COMPARATOR); + public static BlockWrapper DAYLIGHT_DETECTOR = of(net.minecraft.world.level.block.Blocks.DAYLIGHT_DETECTOR); + public static BlockWrapper REDSTONE_BLOCK = of(net.minecraft.world.level.block.Blocks.REDSTONE_BLOCK); + public static BlockWrapper NETHER_QUARTZ_ORE = of(net.minecraft.world.level.block.Blocks.NETHER_QUARTZ_ORE); + public static BlockWrapper HOPPER = of(net.minecraft.world.level.block.Blocks.HOPPER); + public static BlockWrapper QUARTZ_BLOCK = of(net.minecraft.world.level.block.Blocks.QUARTZ_BLOCK); + public static BlockWrapper CHISELED_QUARTZ_BLOCK = of(net.minecraft.world.level.block.Blocks.CHISELED_QUARTZ_BLOCK); + public static BlockWrapper QUARTZ_PILLAR = of(net.minecraft.world.level.block.Blocks.QUARTZ_PILLAR); + public static BlockWrapper QUARTZ_STAIRS = of(net.minecraft.world.level.block.Blocks.QUARTZ_STAIRS); + public static BlockWrapper ACTIVATOR_RAIL = of(net.minecraft.world.level.block.Blocks.ACTIVATOR_RAIL); + public static BlockWrapper DROPPER = of(net.minecraft.world.level.block.Blocks.DROPPER); + public static BlockWrapper WHITE_TERRACOTTA = of(net.minecraft.world.level.block.Blocks.WHITE_TERRACOTTA); + public static BlockWrapper ORANGE_TERRACOTTA = of(net.minecraft.world.level.block.Blocks.ORANGE_TERRACOTTA); + public static BlockWrapper MAGENTA_TERRACOTTA = of(net.minecraft.world.level.block.Blocks.MAGENTA_TERRACOTTA); + public static BlockWrapper LIGHT_BLUE_TERRACOTTA = of(net.minecraft.world.level.block.Blocks.LIGHT_BLUE_TERRACOTTA); + public static BlockWrapper YELLOW_TERRACOTTA = of(net.minecraft.world.level.block.Blocks.YELLOW_TERRACOTTA); + public static BlockWrapper LIME_TERRACOTTA = of(net.minecraft.world.level.block.Blocks.LIME_TERRACOTTA); + public static BlockWrapper PINK_TERRACOTTA = of(net.minecraft.world.level.block.Blocks.PINK_TERRACOTTA); + public static BlockWrapper GRAY_TERRACOTTA = of(net.minecraft.world.level.block.Blocks.GRAY_TERRACOTTA); + public static BlockWrapper LIGHT_GRAY_TERRACOTTA = of(net.minecraft.world.level.block.Blocks.LIGHT_GRAY_TERRACOTTA); + public static BlockWrapper CYAN_TERRACOTTA = of(net.minecraft.world.level.block.Blocks.CYAN_TERRACOTTA); + public static BlockWrapper PURPLE_TERRACOTTA = of(net.minecraft.world.level.block.Blocks.PURPLE_TERRACOTTA); + public static BlockWrapper BLUE_TERRACOTTA = of(net.minecraft.world.level.block.Blocks.BLUE_TERRACOTTA); + public static BlockWrapper BROWN_TERRACOTTA = of(net.minecraft.world.level.block.Blocks.BROWN_TERRACOTTA); + public static BlockWrapper GREEN_TERRACOTTA = of(net.minecraft.world.level.block.Blocks.GREEN_TERRACOTTA); + public static BlockWrapper RED_TERRACOTTA = of(net.minecraft.world.level.block.Blocks.RED_TERRACOTTA); + public static BlockWrapper BLACK_TERRACOTTA = of(net.minecraft.world.level.block.Blocks.BLACK_TERRACOTTA); + public static BlockWrapper WHITE_STAINED_GLASS_PANE = of(net.minecraft.world.level.block.Blocks.WHITE_STAINED_GLASS_PANE); + public static BlockWrapper ORANGE_STAINED_GLASS_PANE = of(net.minecraft.world.level.block.Blocks.ORANGE_STAINED_GLASS_PANE); + public static BlockWrapper MAGENTA_STAINED_GLASS_PANE = of(net.minecraft.world.level.block.Blocks.MAGENTA_STAINED_GLASS_PANE); + public static BlockWrapper LIGHT_BLUE_STAINED_GLASS_PANE = of(net.minecraft.world.level.block.Blocks.LIGHT_BLUE_STAINED_GLASS_PANE); + public static BlockWrapper YELLOW_STAINED_GLASS_PANE = of(net.minecraft.world.level.block.Blocks.YELLOW_STAINED_GLASS_PANE); + public static BlockWrapper LIME_STAINED_GLASS_PANE = of(net.minecraft.world.level.block.Blocks.LIME_STAINED_GLASS_PANE); + public static BlockWrapper PINK_STAINED_GLASS_PANE = of(net.minecraft.world.level.block.Blocks.PINK_STAINED_GLASS_PANE); + public static BlockWrapper GRAY_STAINED_GLASS_PANE = of(net.minecraft.world.level.block.Blocks.GRAY_STAINED_GLASS_PANE); + public static BlockWrapper LIGHT_GRAY_STAINED_GLASS_PANE = of(net.minecraft.world.level.block.Blocks.LIGHT_GRAY_STAINED_GLASS_PANE); + public static BlockWrapper CYAN_STAINED_GLASS_PANE = of(net.minecraft.world.level.block.Blocks.CYAN_STAINED_GLASS_PANE); + public static BlockWrapper PURPLE_STAINED_GLASS_PANE = of(net.minecraft.world.level.block.Blocks.PURPLE_STAINED_GLASS_PANE); + public static BlockWrapper BLUE_STAINED_GLASS_PANE = of(net.minecraft.world.level.block.Blocks.BLUE_STAINED_GLASS_PANE); + public static BlockWrapper BROWN_STAINED_GLASS_PANE = of(net.minecraft.world.level.block.Blocks.BROWN_STAINED_GLASS_PANE); + public static BlockWrapper GREEN_STAINED_GLASS_PANE = of(net.minecraft.world.level.block.Blocks.GREEN_STAINED_GLASS_PANE); + public static BlockWrapper RED_STAINED_GLASS_PANE = of(net.minecraft.world.level.block.Blocks.RED_STAINED_GLASS_PANE); + public static BlockWrapper BLACK_STAINED_GLASS_PANE = of(net.minecraft.world.level.block.Blocks.BLACK_STAINED_GLASS_PANE); + public static BlockWrapper ACACIA_STAIRS = of(net.minecraft.world.level.block.Blocks.ACACIA_STAIRS); + public static BlockWrapper DARK_OAK_STAIRS = of(net.minecraft.world.level.block.Blocks.DARK_OAK_STAIRS); + public static BlockWrapper SLIME_BLOCK = of(net.minecraft.world.level.block.Blocks.SLIME_BLOCK); + public static BlockWrapper BARRIER = of(net.minecraft.world.level.block.Blocks.BARRIER); + public static BlockWrapper IRON_TRAPDOOR = of(net.minecraft.world.level.block.Blocks.IRON_TRAPDOOR); + public static BlockWrapper PRISMARINE = of(net.minecraft.world.level.block.Blocks.PRISMARINE); + public static BlockWrapper PRISMARINE_BRICKS = of(net.minecraft.world.level.block.Blocks.PRISMARINE_BRICKS); + public static BlockWrapper DARK_PRISMARINE = of(net.minecraft.world.level.block.Blocks.DARK_PRISMARINE); + public static BlockWrapper PRISMARINE_STAIRS = of(net.minecraft.world.level.block.Blocks.PRISMARINE_STAIRS); + public static BlockWrapper PRISMARINE_BRICK_STAIRS = of(net.minecraft.world.level.block.Blocks.PRISMARINE_BRICK_STAIRS); + public static BlockWrapper DARK_PRISMARINE_STAIRS = of(net.minecraft.world.level.block.Blocks.DARK_PRISMARINE_STAIRS); + public static BlockWrapper PRISMARINE_SLAB = of(net.minecraft.world.level.block.Blocks.PRISMARINE_SLAB); + public static BlockWrapper PRISMARINE_BRICK_SLAB = of(net.minecraft.world.level.block.Blocks.PRISMARINE_BRICK_SLAB); + public static BlockWrapper DARK_PRISMARINE_SLAB = of(net.minecraft.world.level.block.Blocks.DARK_PRISMARINE_SLAB); + public static BlockWrapper SEA_LANTERN = of(net.minecraft.world.level.block.Blocks.SEA_LANTERN); + public static BlockWrapper HAY_BLOCK = of(net.minecraft.world.level.block.Blocks.HAY_BLOCK); + public static BlockWrapper WHITE_CARPET = of(net.minecraft.world.level.block.Blocks.WHITE_CARPET); + public static BlockWrapper ORANGE_CARPET = of(net.minecraft.world.level.block.Blocks.ORANGE_CARPET); + public static BlockWrapper MAGENTA_CARPET = of(net.minecraft.world.level.block.Blocks.MAGENTA_CARPET); + public static BlockWrapper LIGHT_BLUE_CARPET = of(net.minecraft.world.level.block.Blocks.LIGHT_BLUE_CARPET); + public static BlockWrapper YELLOW_CARPET = of(net.minecraft.world.level.block.Blocks.YELLOW_CARPET); + public static BlockWrapper LIME_CARPET = of(net.minecraft.world.level.block.Blocks.LIME_CARPET); + public static BlockWrapper PINK_CARPET = of(net.minecraft.world.level.block.Blocks.PINK_CARPET); + public static BlockWrapper GRAY_CARPET = of(net.minecraft.world.level.block.Blocks.GRAY_CARPET); + public static BlockWrapper LIGHT_GRAY_CARPET = of(net.minecraft.world.level.block.Blocks.LIGHT_GRAY_CARPET); + public static BlockWrapper CYAN_CARPET = of(net.minecraft.world.level.block.Blocks.CYAN_CARPET); + public static BlockWrapper PURPLE_CARPET = of(net.minecraft.world.level.block.Blocks.PURPLE_CARPET); + public static BlockWrapper BLUE_CARPET = of(net.minecraft.world.level.block.Blocks.BLUE_CARPET); + public static BlockWrapper BROWN_CARPET = of(net.minecraft.world.level.block.Blocks.BROWN_CARPET); + public static BlockWrapper GREEN_CARPET = of(net.minecraft.world.level.block.Blocks.GREEN_CARPET); + public static BlockWrapper RED_CARPET = of(net.minecraft.world.level.block.Blocks.RED_CARPET); + public static BlockWrapper BLACK_CARPET = of(net.minecraft.world.level.block.Blocks.BLACK_CARPET); + public static BlockWrapper TERRACOTTA = of(net.minecraft.world.level.block.Blocks.TERRACOTTA); + public static BlockWrapper COAL_BLOCK = of(net.minecraft.world.level.block.Blocks.COAL_BLOCK); + public static BlockWrapper PACKED_ICE = of(net.minecraft.world.level.block.Blocks.PACKED_ICE); + public static BlockWrapper SUNFLOWER = of(net.minecraft.world.level.block.Blocks.SUNFLOWER); + public static BlockWrapper LILAC = of(net.minecraft.world.level.block.Blocks.LILAC); + public static BlockWrapper ROSE_BUSH = of(net.minecraft.world.level.block.Blocks.ROSE_BUSH); + public static BlockWrapper PEONY = of(net.minecraft.world.level.block.Blocks.PEONY); + public static BlockWrapper TALL_GRASS = of(net.minecraft.world.level.block.Blocks.TALL_GRASS); + public static BlockWrapper LARGE_FERN = of(net.minecraft.world.level.block.Blocks.LARGE_FERN); + public static BlockWrapper WHITE_BANNER = of(net.minecraft.world.level.block.Blocks.WHITE_BANNER); + public static BlockWrapper ORANGE_BANNER = of(net.minecraft.world.level.block.Blocks.ORANGE_BANNER); + public static BlockWrapper MAGENTA_BANNER = of(net.minecraft.world.level.block.Blocks.MAGENTA_BANNER); + public static BlockWrapper LIGHT_BLUE_BANNER = of(net.minecraft.world.level.block.Blocks.LIGHT_BLUE_BANNER); + public static BlockWrapper YELLOW_BANNER = of(net.minecraft.world.level.block.Blocks.YELLOW_BANNER); + public static BlockWrapper LIME_BANNER = of(net.minecraft.world.level.block.Blocks.LIME_BANNER); + public static BlockWrapper PINK_BANNER = of(net.minecraft.world.level.block.Blocks.PINK_BANNER); + public static BlockWrapper GRAY_BANNER = of(net.minecraft.world.level.block.Blocks.GRAY_BANNER); + public static BlockWrapper LIGHT_GRAY_BANNER = of(net.minecraft.world.level.block.Blocks.LIGHT_GRAY_BANNER); + public static BlockWrapper CYAN_BANNER = of(net.minecraft.world.level.block.Blocks.CYAN_BANNER); + public static BlockWrapper PURPLE_BANNER = of(net.minecraft.world.level.block.Blocks.PURPLE_BANNER); + public static BlockWrapper BLUE_BANNER = of(net.minecraft.world.level.block.Blocks.BLUE_BANNER); + public static BlockWrapper BROWN_BANNER = of(net.minecraft.world.level.block.Blocks.BROWN_BANNER); + public static BlockWrapper GREEN_BANNER = of(net.minecraft.world.level.block.Blocks.GREEN_BANNER); + public static BlockWrapper RED_BANNER = of(net.minecraft.world.level.block.Blocks.RED_BANNER); + public static BlockWrapper BLACK_BANNER = of(net.minecraft.world.level.block.Blocks.BLACK_BANNER); + public static BlockWrapper WHITE_WALL_BANNER = of(net.minecraft.world.level.block.Blocks.WHITE_WALL_BANNER); + public static BlockWrapper ORANGE_WALL_BANNER = of(net.minecraft.world.level.block.Blocks.ORANGE_WALL_BANNER); + public static BlockWrapper MAGENTA_WALL_BANNER = of(net.minecraft.world.level.block.Blocks.MAGENTA_WALL_BANNER); + public static BlockWrapper LIGHT_BLUE_WALL_BANNER = of(net.minecraft.world.level.block.Blocks.LIGHT_BLUE_WALL_BANNER); + public static BlockWrapper YELLOW_WALL_BANNER = of(net.minecraft.world.level.block.Blocks.YELLOW_WALL_BANNER); + public static BlockWrapper LIME_WALL_BANNER = of(net.minecraft.world.level.block.Blocks.LIME_WALL_BANNER); + public static BlockWrapper PINK_WALL_BANNER = of(net.minecraft.world.level.block.Blocks.PINK_WALL_BANNER); + public static BlockWrapper GRAY_WALL_BANNER = of(net.minecraft.world.level.block.Blocks.GRAY_WALL_BANNER); + public static BlockWrapper LIGHT_GRAY_WALL_BANNER = of(net.minecraft.world.level.block.Blocks.LIGHT_GRAY_WALL_BANNER); + public static BlockWrapper CYAN_WALL_BANNER = of(net.minecraft.world.level.block.Blocks.CYAN_WALL_BANNER); + public static BlockWrapper PURPLE_WALL_BANNER = of(net.minecraft.world.level.block.Blocks.PURPLE_WALL_BANNER); + public static BlockWrapper BLUE_WALL_BANNER = of(net.minecraft.world.level.block.Blocks.BLUE_WALL_BANNER); + public static BlockWrapper BROWN_WALL_BANNER = of(net.minecraft.world.level.block.Blocks.BROWN_WALL_BANNER); + public static BlockWrapper GREEN_WALL_BANNER = of(net.minecraft.world.level.block.Blocks.GREEN_WALL_BANNER); + public static BlockWrapper RED_WALL_BANNER = of(net.minecraft.world.level.block.Blocks.RED_WALL_BANNER); + public static BlockWrapper BLACK_WALL_BANNER = of(net.minecraft.world.level.block.Blocks.BLACK_WALL_BANNER); + public static BlockWrapper RED_SANDSTONE = of(net.minecraft.world.level.block.Blocks.RED_SANDSTONE); + public static BlockWrapper CHISELED_RED_SANDSTONE = of(net.minecraft.world.level.block.Blocks.CHISELED_RED_SANDSTONE); + public static BlockWrapper CUT_RED_SANDSTONE = of(net.minecraft.world.level.block.Blocks.CUT_RED_SANDSTONE); + public static BlockWrapper RED_SANDSTONE_STAIRS = of(net.minecraft.world.level.block.Blocks.RED_SANDSTONE_STAIRS); + public static BlockWrapper OAK_SLAB = of(net.minecraft.world.level.block.Blocks.OAK_SLAB); + public static BlockWrapper SPRUCE_SLAB = of(net.minecraft.world.level.block.Blocks.SPRUCE_SLAB); + public static BlockWrapper BIRCH_SLAB = of(net.minecraft.world.level.block.Blocks.BIRCH_SLAB); + public static BlockWrapper JUNGLE_SLAB = of(net.minecraft.world.level.block.Blocks.JUNGLE_SLAB); + public static BlockWrapper ACACIA_SLAB = of(net.minecraft.world.level.block.Blocks.ACACIA_SLAB); + public static BlockWrapper DARK_OAK_SLAB = of(net.minecraft.world.level.block.Blocks.DARK_OAK_SLAB); + public static BlockWrapper STONE_SLAB = of(net.minecraft.world.level.block.Blocks.STONE_SLAB); + public static BlockWrapper SMOOTH_STONE_SLAB = of(net.minecraft.world.level.block.Blocks.SMOOTH_STONE_SLAB); + public static BlockWrapper SANDSTONE_SLAB = of(net.minecraft.world.level.block.Blocks.SANDSTONE_SLAB); + public static BlockWrapper CUT_SANDSTONE_SLAB = of(net.minecraft.world.level.block.Blocks.CUT_SANDSTONE_SLAB); + public static BlockWrapper PETRIFIED_OAK_SLAB = of(net.minecraft.world.level.block.Blocks.PETRIFIED_OAK_SLAB); + public static BlockWrapper COBBLESTONE_SLAB = of(net.minecraft.world.level.block.Blocks.COBBLESTONE_SLAB); + public static BlockWrapper BRICK_SLAB = of(net.minecraft.world.level.block.Blocks.BRICK_SLAB); + public static BlockWrapper STONE_BRICK_SLAB = of(net.minecraft.world.level.block.Blocks.STONE_BRICK_SLAB); + public static BlockWrapper NETHER_BRICK_SLAB = of(net.minecraft.world.level.block.Blocks.NETHER_BRICK_SLAB); + public static BlockWrapper QUARTZ_SLAB = of(net.minecraft.world.level.block.Blocks.QUARTZ_SLAB); + public static BlockWrapper RED_SANDSTONE_SLAB = of(net.minecraft.world.level.block.Blocks.RED_SANDSTONE_SLAB); + public static BlockWrapper CUT_RED_SANDSTONE_SLAB = of(net.minecraft.world.level.block.Blocks.CUT_RED_SANDSTONE_SLAB); + public static BlockWrapper PURPUR_SLAB = of(net.minecraft.world.level.block.Blocks.PURPUR_SLAB); + public static BlockWrapper SMOOTH_STONE = of(net.minecraft.world.level.block.Blocks.SMOOTH_STONE); + public static BlockWrapper SMOOTH_SANDSTONE = of(net.minecraft.world.level.block.Blocks.SMOOTH_SANDSTONE); + public static BlockWrapper SMOOTH_QUARTZ = of(net.minecraft.world.level.block.Blocks.SMOOTH_QUARTZ); + public static BlockWrapper SMOOTH_RED_SANDSTONE = of(net.minecraft.world.level.block.Blocks.SMOOTH_RED_SANDSTONE); + public static BlockWrapper SPRUCE_FENCE_GATE = of(net.minecraft.world.level.block.Blocks.SPRUCE_FENCE_GATE); + public static BlockWrapper BIRCH_FENCE_GATE = of(net.minecraft.world.level.block.Blocks.BIRCH_FENCE_GATE); + public static BlockWrapper JUNGLE_FENCE_GATE = of(net.minecraft.world.level.block.Blocks.JUNGLE_FENCE_GATE); + public static BlockWrapper ACACIA_FENCE_GATE = of(net.minecraft.world.level.block.Blocks.ACACIA_FENCE_GATE); + public static BlockWrapper DARK_OAK_FENCE_GATE = of(net.minecraft.world.level.block.Blocks.DARK_OAK_FENCE_GATE); + public static BlockWrapper SPRUCE_FENCE = of(net.minecraft.world.level.block.Blocks.SPRUCE_FENCE); + public static BlockWrapper BIRCH_FENCE = of(net.minecraft.world.level.block.Blocks.BIRCH_FENCE); + public static BlockWrapper JUNGLE_FENCE = of(net.minecraft.world.level.block.Blocks.JUNGLE_FENCE); + public static BlockWrapper ACACIA_FENCE = of(net.minecraft.world.level.block.Blocks.ACACIA_FENCE); + public static BlockWrapper DARK_OAK_FENCE = of(net.minecraft.world.level.block.Blocks.DARK_OAK_FENCE); + public static BlockWrapper SPRUCE_DOOR = of(net.minecraft.world.level.block.Blocks.SPRUCE_DOOR); + public static BlockWrapper BIRCH_DOOR = of(net.minecraft.world.level.block.Blocks.BIRCH_DOOR); + public static BlockWrapper JUNGLE_DOOR = of(net.minecraft.world.level.block.Blocks.JUNGLE_DOOR); + public static BlockWrapper ACACIA_DOOR = of(net.minecraft.world.level.block.Blocks.ACACIA_DOOR); + public static BlockWrapper DARK_OAK_DOOR = of(net.minecraft.world.level.block.Blocks.DARK_OAK_DOOR); + public static BlockWrapper END_ROD = of(net.minecraft.world.level.block.Blocks.END_ROD); + public static BlockWrapper CHORUS_PLANT = of(net.minecraft.world.level.block.Blocks.CHORUS_PLANT); + public static BlockWrapper CHORUS_FLOWER = of(net.minecraft.world.level.block.Blocks.CHORUS_FLOWER); + public static BlockWrapper PURPUR_BLOCK = of(net.minecraft.world.level.block.Blocks.PURPUR_BLOCK); + public static BlockWrapper PURPUR_PILLAR = of(net.minecraft.world.level.block.Blocks.PURPUR_PILLAR); + public static BlockWrapper PURPUR_STAIRS = of(net.minecraft.world.level.block.Blocks.PURPUR_STAIRS); + public static BlockWrapper END_STONE_BRICKS = of(net.minecraft.world.level.block.Blocks.END_STONE_BRICKS); + public static BlockWrapper BEETROOTS = of(net.minecraft.world.level.block.Blocks.BEETROOTS); + public static BlockWrapper GRASS_PATH = of(net.minecraft.world.level.block.Blocks.DIRT_PATH); + public static BlockWrapper END_GATEWAY = of(net.minecraft.world.level.block.Blocks.END_GATEWAY); + public static BlockWrapper REPEATING_COMMAND_BLOCK = of(net.minecraft.world.level.block.Blocks.REPEATING_COMMAND_BLOCK); + public static BlockWrapper CHAIN_COMMAND_BLOCK = of(net.minecraft.world.level.block.Blocks.CHAIN_COMMAND_BLOCK); + public static BlockWrapper FROSTED_ICE = of(net.minecraft.world.level.block.Blocks.FROSTED_ICE); + public static BlockWrapper MAGMA_BLOCK = of(net.minecraft.world.level.block.Blocks.MAGMA_BLOCK); + public static BlockWrapper NETHER_WART_BLOCK = of(net.minecraft.world.level.block.Blocks.NETHER_WART_BLOCK); + public static BlockWrapper RED_NETHER_BRICKS = of(net.minecraft.world.level.block.Blocks.RED_NETHER_BRICKS); + public static BlockWrapper BONE_BLOCK = of(net.minecraft.world.level.block.Blocks.BONE_BLOCK); + public static BlockWrapper STRUCTURE_VOID = of(net.minecraft.world.level.block.Blocks.STRUCTURE_VOID); + public static BlockWrapper OBSERVER = of(net.minecraft.world.level.block.Blocks.OBSERVER); + public static BlockWrapper SHULKER_BOX = of(net.minecraft.world.level.block.Blocks.SHULKER_BOX); + public static BlockWrapper WHITE_SHULKER_BOX = of(net.minecraft.world.level.block.Blocks.WHITE_SHULKER_BOX); + public static BlockWrapper ORANGE_SHULKER_BOX = of(net.minecraft.world.level.block.Blocks.ORANGE_SHULKER_BOX); + public static BlockWrapper MAGENTA_SHULKER_BOX = of(net.minecraft.world.level.block.Blocks.MAGENTA_SHULKER_BOX); + public static BlockWrapper LIGHT_BLUE_SHULKER_BOX = of(net.minecraft.world.level.block.Blocks.LIGHT_BLUE_SHULKER_BOX); + public static BlockWrapper YELLOW_SHULKER_BOX = of(net.minecraft.world.level.block.Blocks.YELLOW_SHULKER_BOX); + public static BlockWrapper LIME_SHULKER_BOX = of(net.minecraft.world.level.block.Blocks.LIME_SHULKER_BOX); + public static BlockWrapper PINK_SHULKER_BOX = of(net.minecraft.world.level.block.Blocks.PINK_SHULKER_BOX); + public static BlockWrapper GRAY_SHULKER_BOX = of(net.minecraft.world.level.block.Blocks.GRAY_SHULKER_BOX); + public static BlockWrapper LIGHT_GRAY_SHULKER_BOX = of(net.minecraft.world.level.block.Blocks.LIGHT_GRAY_SHULKER_BOX); + public static BlockWrapper CYAN_SHULKER_BOX = of(net.minecraft.world.level.block.Blocks.CYAN_SHULKER_BOX); + public static BlockWrapper PURPLE_SHULKER_BOX = of(net.minecraft.world.level.block.Blocks.PURPLE_SHULKER_BOX); + public static BlockWrapper BLUE_SHULKER_BOX = of(net.minecraft.world.level.block.Blocks.BLUE_SHULKER_BOX); + public static BlockWrapper BROWN_SHULKER_BOX = of(net.minecraft.world.level.block.Blocks.BROWN_SHULKER_BOX); + public static BlockWrapper GREEN_SHULKER_BOX = of(net.minecraft.world.level.block.Blocks.GREEN_SHULKER_BOX); + public static BlockWrapper RED_SHULKER_BOX = of(net.minecraft.world.level.block.Blocks.RED_SHULKER_BOX); + public static BlockWrapper BLACK_SHULKER_BOX = of(net.minecraft.world.level.block.Blocks.BLACK_SHULKER_BOX); + public static BlockWrapper WHITE_GLAZED_TERRACOTTA = of(net.minecraft.world.level.block.Blocks.WHITE_GLAZED_TERRACOTTA); + public static BlockWrapper ORANGE_GLAZED_TERRACOTTA = of(net.minecraft.world.level.block.Blocks.ORANGE_GLAZED_TERRACOTTA); + public static BlockWrapper MAGENTA_GLAZED_TERRACOTTA = of(net.minecraft.world.level.block.Blocks.MAGENTA_GLAZED_TERRACOTTA); + public static BlockWrapper LIGHT_BLUE_GLAZED_TERRACOTTA = of(net.minecraft.world.level.block.Blocks.LIGHT_BLUE_GLAZED_TERRACOTTA); + public static BlockWrapper YELLOW_GLAZED_TERRACOTTA = of(net.minecraft.world.level.block.Blocks.YELLOW_GLAZED_TERRACOTTA); + public static BlockWrapper LIME_GLAZED_TERRACOTTA = of(net.minecraft.world.level.block.Blocks.LIME_GLAZED_TERRACOTTA); + public static BlockWrapper PINK_GLAZED_TERRACOTTA = of(net.minecraft.world.level.block.Blocks.PINK_GLAZED_TERRACOTTA); + public static BlockWrapper GRAY_GLAZED_TERRACOTTA = of(net.minecraft.world.level.block.Blocks.GRAY_GLAZED_TERRACOTTA); + public static BlockWrapper LIGHT_GRAY_GLAZED_TERRACOTTA = of(net.minecraft.world.level.block.Blocks.LIGHT_GRAY_GLAZED_TERRACOTTA); + public static BlockWrapper CYAN_GLAZED_TERRACOTTA = of(net.minecraft.world.level.block.Blocks.CYAN_GLAZED_TERRACOTTA); + public static BlockWrapper PURPLE_GLAZED_TERRACOTTA = of(net.minecraft.world.level.block.Blocks.PURPLE_GLAZED_TERRACOTTA); + public static BlockWrapper BLUE_GLAZED_TERRACOTTA = of(net.minecraft.world.level.block.Blocks.BLUE_GLAZED_TERRACOTTA); + public static BlockWrapper BROWN_GLAZED_TERRACOTTA = of(net.minecraft.world.level.block.Blocks.BROWN_GLAZED_TERRACOTTA); + public static BlockWrapper GREEN_GLAZED_TERRACOTTA = of(net.minecraft.world.level.block.Blocks.GREEN_GLAZED_TERRACOTTA); + public static BlockWrapper RED_GLAZED_TERRACOTTA = of(net.minecraft.world.level.block.Blocks.RED_GLAZED_TERRACOTTA); + public static BlockWrapper BLACK_GLAZED_TERRACOTTA = of(net.minecraft.world.level.block.Blocks.BLACK_GLAZED_TERRACOTTA); + public static BlockWrapper WHITE_CONCRETE = of(net.minecraft.world.level.block.Blocks.WHITE_CONCRETE); + public static BlockWrapper ORANGE_CONCRETE = of(net.minecraft.world.level.block.Blocks.ORANGE_CONCRETE); + public static BlockWrapper MAGENTA_CONCRETE = of(net.minecraft.world.level.block.Blocks.MAGENTA_CONCRETE); + public static BlockWrapper LIGHT_BLUE_CONCRETE = of(net.minecraft.world.level.block.Blocks.LIGHT_BLUE_CONCRETE); + public static BlockWrapper YELLOW_CONCRETE = of(net.minecraft.world.level.block.Blocks.YELLOW_CONCRETE); + public static BlockWrapper LIME_CONCRETE = of(net.minecraft.world.level.block.Blocks.LIME_CONCRETE); + public static BlockWrapper PINK_CONCRETE = of(net.minecraft.world.level.block.Blocks.PINK_CONCRETE); + public static BlockWrapper GRAY_CONCRETE = of(net.minecraft.world.level.block.Blocks.GRAY_CONCRETE); + public static BlockWrapper LIGHT_GRAY_CONCRETE = of(net.minecraft.world.level.block.Blocks.LIGHT_GRAY_CONCRETE); + public static BlockWrapper CYAN_CONCRETE = of(net.minecraft.world.level.block.Blocks.CYAN_CONCRETE); + public static BlockWrapper PURPLE_CONCRETE = of(net.minecraft.world.level.block.Blocks.PURPLE_CONCRETE); + public static BlockWrapper BLUE_CONCRETE = of(net.minecraft.world.level.block.Blocks.BLUE_CONCRETE); + public static BlockWrapper BROWN_CONCRETE = of(net.minecraft.world.level.block.Blocks.BROWN_CONCRETE); + public static BlockWrapper GREEN_CONCRETE = of(net.minecraft.world.level.block.Blocks.GREEN_CONCRETE); + public static BlockWrapper RED_CONCRETE = of(net.minecraft.world.level.block.Blocks.RED_CONCRETE); + public static BlockWrapper BLACK_CONCRETE = of(net.minecraft.world.level.block.Blocks.BLACK_CONCRETE); + public static BlockWrapper WHITE_CONCRETE_POWDER = of(net.minecraft.world.level.block.Blocks.WHITE_CONCRETE_POWDER); + public static BlockWrapper ORANGE_CONCRETE_POWDER = of(net.minecraft.world.level.block.Blocks.ORANGE_CONCRETE_POWDER); + public static BlockWrapper MAGENTA_CONCRETE_POWDER = of(net.minecraft.world.level.block.Blocks.MAGENTA_CONCRETE_POWDER); + public static BlockWrapper LIGHT_BLUE_CONCRETE_POWDER = of(net.minecraft.world.level.block.Blocks.LIGHT_BLUE_CONCRETE_POWDER); + public static BlockWrapper YELLOW_CONCRETE_POWDER = of(net.minecraft.world.level.block.Blocks.YELLOW_CONCRETE_POWDER); + public static BlockWrapper LIME_CONCRETE_POWDER = of(net.minecraft.world.level.block.Blocks.LIME_CONCRETE_POWDER); + public static BlockWrapper PINK_CONCRETE_POWDER = of(net.minecraft.world.level.block.Blocks.PINK_CONCRETE_POWDER); + public static BlockWrapper GRAY_CONCRETE_POWDER = of(net.minecraft.world.level.block.Blocks.GRAY_CONCRETE_POWDER); + public static BlockWrapper LIGHT_GRAY_CONCRETE_POWDER = of(net.minecraft.world.level.block.Blocks.LIGHT_GRAY_CONCRETE_POWDER); + public static BlockWrapper CYAN_CONCRETE_POWDER = of(net.minecraft.world.level.block.Blocks.CYAN_CONCRETE_POWDER); + public static BlockWrapper PURPLE_CONCRETE_POWDER = of(net.minecraft.world.level.block.Blocks.PURPLE_CONCRETE_POWDER); + public static BlockWrapper BLUE_CONCRETE_POWDER = of(net.minecraft.world.level.block.Blocks.BLUE_CONCRETE_POWDER); + public static BlockWrapper BROWN_CONCRETE_POWDER = of(net.minecraft.world.level.block.Blocks.BROWN_CONCRETE_POWDER); + public static BlockWrapper GREEN_CONCRETE_POWDER = of(net.minecraft.world.level.block.Blocks.GREEN_CONCRETE_POWDER); + public static BlockWrapper RED_CONCRETE_POWDER = of(net.minecraft.world.level.block.Blocks.RED_CONCRETE_POWDER); + public static BlockWrapper BLACK_CONCRETE_POWDER = of(net.minecraft.world.level.block.Blocks.BLACK_CONCRETE_POWDER); + public static BlockWrapper KELP = of(net.minecraft.world.level.block.Blocks.KELP); + public static BlockWrapper KELP_PLANT = of(net.minecraft.world.level.block.Blocks.KELP_PLANT); + public static BlockWrapper DRIED_KELP_BLOCK = of(net.minecraft.world.level.block.Blocks.DRIED_KELP_BLOCK); + public static BlockWrapper TURTLE_EGG = of(net.minecraft.world.level.block.Blocks.TURTLE_EGG); + public static BlockWrapper DEAD_TUBE_CORAL_BLOCK = of(net.minecraft.world.level.block.Blocks.DEAD_TUBE_CORAL_BLOCK); + public static BlockWrapper DEAD_BRAIN_CORAL_BLOCK = of(net.minecraft.world.level.block.Blocks.DEAD_BRAIN_CORAL_BLOCK); + public static BlockWrapper DEAD_BUBBLE_CORAL_BLOCK = of(net.minecraft.world.level.block.Blocks.DEAD_BUBBLE_CORAL_BLOCK); + public static BlockWrapper DEAD_FIRE_CORAL_BLOCK = of(net.minecraft.world.level.block.Blocks.DEAD_FIRE_CORAL_BLOCK); + public static BlockWrapper DEAD_HORN_CORAL_BLOCK = of(net.minecraft.world.level.block.Blocks.DEAD_HORN_CORAL_BLOCK); + public static BlockWrapper TUBE_CORAL_BLOCK = of(net.minecraft.world.level.block.Blocks.TUBE_CORAL_BLOCK); + public static BlockWrapper BRAIN_CORAL_BLOCK = of(net.minecraft.world.level.block.Blocks.BRAIN_CORAL_BLOCK); + public static BlockWrapper BUBBLE_CORAL_BLOCK = of(net.minecraft.world.level.block.Blocks.BUBBLE_CORAL_BLOCK); + public static BlockWrapper FIRE_CORAL_BLOCK = of(net.minecraft.world.level.block.Blocks.FIRE_CORAL_BLOCK); + public static BlockWrapper HORN_CORAL_BLOCK = of(net.minecraft.world.level.block.Blocks.HORN_CORAL_BLOCK); + public static BlockWrapper DEAD_TUBE_CORAL = of(net.minecraft.world.level.block.Blocks.DEAD_TUBE_CORAL); + public static BlockWrapper DEAD_BRAIN_CORAL = of(net.minecraft.world.level.block.Blocks.DEAD_BRAIN_CORAL); + public static BlockWrapper DEAD_BUBBLE_CORAL = of(net.minecraft.world.level.block.Blocks.DEAD_BUBBLE_CORAL); + public static BlockWrapper DEAD_FIRE_CORAL = of(net.minecraft.world.level.block.Blocks.DEAD_FIRE_CORAL); + public static BlockWrapper DEAD_HORN_CORAL = of(net.minecraft.world.level.block.Blocks.DEAD_HORN_CORAL); + public static BlockWrapper TUBE_CORAL = of(net.minecraft.world.level.block.Blocks.TUBE_CORAL); + public static BlockWrapper BRAIN_CORAL = of(net.minecraft.world.level.block.Blocks.BRAIN_CORAL); + public static BlockWrapper BUBBLE_CORAL = of(net.minecraft.world.level.block.Blocks.BUBBLE_CORAL); + public static BlockWrapper FIRE_CORAL = of(net.minecraft.world.level.block.Blocks.FIRE_CORAL); + public static BlockWrapper HORN_CORAL = of(net.minecraft.world.level.block.Blocks.HORN_CORAL); + public static BlockWrapper DEAD_TUBE_CORAL_FAN = of(net.minecraft.world.level.block.Blocks.DEAD_TUBE_CORAL_FAN); + public static BlockWrapper DEAD_BRAIN_CORAL_FAN = of(net.minecraft.world.level.block.Blocks.DEAD_BRAIN_CORAL_FAN); + public static BlockWrapper DEAD_BUBBLE_CORAL_FAN = of(net.minecraft.world.level.block.Blocks.DEAD_BUBBLE_CORAL_FAN); + public static BlockWrapper DEAD_FIRE_CORAL_FAN = of(net.minecraft.world.level.block.Blocks.DEAD_FIRE_CORAL_FAN); + public static BlockWrapper DEAD_HORN_CORAL_FAN = of(net.minecraft.world.level.block.Blocks.DEAD_HORN_CORAL_FAN); + public static BlockWrapper TUBE_CORAL_FAN = of(net.minecraft.world.level.block.Blocks.TUBE_CORAL_FAN); + public static BlockWrapper BRAIN_CORAL_FAN = of(net.minecraft.world.level.block.Blocks.BRAIN_CORAL_FAN); + public static BlockWrapper BUBBLE_CORAL_FAN = of(net.minecraft.world.level.block.Blocks.BUBBLE_CORAL_FAN); + public static BlockWrapper FIRE_CORAL_FAN = of(net.minecraft.world.level.block.Blocks.FIRE_CORAL_FAN); + public static BlockWrapper HORN_CORAL_FAN = of(net.minecraft.world.level.block.Blocks.HORN_CORAL_FAN); + public static BlockWrapper DEAD_TUBE_CORAL_WALL_FAN = of(net.minecraft.world.level.block.Blocks.DEAD_TUBE_CORAL_WALL_FAN); + public static BlockWrapper DEAD_BRAIN_CORAL_WALL_FAN = of(net.minecraft.world.level.block.Blocks.DEAD_BRAIN_CORAL_WALL_FAN); + public static BlockWrapper DEAD_BUBBLE_CORAL_WALL_FAN = of(net.minecraft.world.level.block.Blocks.DEAD_BUBBLE_CORAL_WALL_FAN); + public static BlockWrapper DEAD_FIRE_CORAL_WALL_FAN = of(net.minecraft.world.level.block.Blocks.DEAD_FIRE_CORAL_WALL_FAN); + public static BlockWrapper DEAD_HORN_CORAL_WALL_FAN = of(net.minecraft.world.level.block.Blocks.DEAD_HORN_CORAL_WALL_FAN); + public static BlockWrapper TUBE_CORAL_WALL_FAN = of(net.minecraft.world.level.block.Blocks.TUBE_CORAL_WALL_FAN); + public static BlockWrapper BRAIN_CORAL_WALL_FAN = of(net.minecraft.world.level.block.Blocks.BRAIN_CORAL_WALL_FAN); + public static BlockWrapper BUBBLE_CORAL_WALL_FAN = of(net.minecraft.world.level.block.Blocks.BUBBLE_CORAL_WALL_FAN); + public static BlockWrapper FIRE_CORAL_WALL_FAN = of(net.minecraft.world.level.block.Blocks.FIRE_CORAL_WALL_FAN); + public static BlockWrapper HORN_CORAL_WALL_FAN = of(net.minecraft.world.level.block.Blocks.HORN_CORAL_WALL_FAN); + public static BlockWrapper SEA_PICKLE = of(net.minecraft.world.level.block.Blocks.SEA_PICKLE); + public static BlockWrapper BLUE_ICE = of(net.minecraft.world.level.block.Blocks.BLUE_ICE); + public static BlockWrapper CONDUIT = of(net.minecraft.world.level.block.Blocks.CONDUIT); + public static BlockWrapper BAMBOO_SAPLING = of(net.minecraft.world.level.block.Blocks.BAMBOO_SAPLING); + public static BlockWrapper BAMBOO = of(net.minecraft.world.level.block.Blocks.BAMBOO); + public static BlockWrapper POTTED_BAMBOO = of(net.minecraft.world.level.block.Blocks.POTTED_BAMBOO); + public static BlockWrapper VOID_AIR = of(net.minecraft.world.level.block.Blocks.VOID_AIR); + public static BlockWrapper CAVE_AIR = of(net.minecraft.world.level.block.Blocks.CAVE_AIR); + public static BlockWrapper BUBBLE_COLUMN = of(net.minecraft.world.level.block.Blocks.BUBBLE_COLUMN); + public static BlockWrapper POLISHED_GRANITE_STAIRS = of(net.minecraft.world.level.block.Blocks.POLISHED_GRANITE_STAIRS); + public static BlockWrapper SMOOTH_RED_SANDSTONE_STAIRS = of(net.minecraft.world.level.block.Blocks.SMOOTH_RED_SANDSTONE_STAIRS); + public static BlockWrapper MOSSY_STONE_BRICK_STAIRS = of(net.minecraft.world.level.block.Blocks.MOSSY_STONE_BRICK_STAIRS); + public static BlockWrapper POLISHED_DIORITE_STAIRS = of(net.minecraft.world.level.block.Blocks.POLISHED_DIORITE_STAIRS); + public static BlockWrapper MOSSY_COBBLESTONE_STAIRS = of(net.minecraft.world.level.block.Blocks.MOSSY_COBBLESTONE_STAIRS); + public static BlockWrapper END_STONE_BRICK_STAIRS = of(net.minecraft.world.level.block.Blocks.END_STONE_BRICK_STAIRS); + public static BlockWrapper STONE_STAIRS = of(net.minecraft.world.level.block.Blocks.STONE_STAIRS); + public static BlockWrapper SMOOTH_SANDSTONE_STAIRS = of(net.minecraft.world.level.block.Blocks.SMOOTH_SANDSTONE_STAIRS); + public static BlockWrapper SMOOTH_QUARTZ_STAIRS = of(net.minecraft.world.level.block.Blocks.SMOOTH_QUARTZ_STAIRS); + public static BlockWrapper GRANITE_STAIRS = of(net.minecraft.world.level.block.Blocks.GRANITE_STAIRS); + public static BlockWrapper ANDESITE_STAIRS = of(net.minecraft.world.level.block.Blocks.ANDESITE_STAIRS); + public static BlockWrapper RED_NETHER_BRICK_STAIRS = of(net.minecraft.world.level.block.Blocks.RED_NETHER_BRICK_STAIRS); + public static BlockWrapper POLISHED_ANDESITE_STAIRS = of(net.minecraft.world.level.block.Blocks.POLISHED_ANDESITE_STAIRS); + public static BlockWrapper DIORITE_STAIRS = of(net.minecraft.world.level.block.Blocks.DIORITE_STAIRS); + public static BlockWrapper POLISHED_GRANITE_SLAB = of(net.minecraft.world.level.block.Blocks.POLISHED_GRANITE_SLAB); + public static BlockWrapper SMOOTH_RED_SANDSTONE_SLAB = of(net.minecraft.world.level.block.Blocks.SMOOTH_RED_SANDSTONE_SLAB); + public static BlockWrapper MOSSY_STONE_BRICK_SLAB = of(net.minecraft.world.level.block.Blocks.MOSSY_STONE_BRICK_SLAB); + public static BlockWrapper POLISHED_DIORITE_SLAB = of(net.minecraft.world.level.block.Blocks.POLISHED_DIORITE_SLAB); + public static BlockWrapper MOSSY_COBBLESTONE_SLAB = of(net.minecraft.world.level.block.Blocks.MOSSY_COBBLESTONE_SLAB); + public static BlockWrapper END_STONE_BRICK_SLAB = of(net.minecraft.world.level.block.Blocks.END_STONE_BRICK_SLAB); + public static BlockWrapper SMOOTH_SANDSTONE_SLAB = of(net.minecraft.world.level.block.Blocks.SMOOTH_SANDSTONE_SLAB); + public static BlockWrapper SMOOTH_QUARTZ_SLAB = of(net.minecraft.world.level.block.Blocks.SMOOTH_QUARTZ_SLAB); + public static BlockWrapper GRANITE_SLAB = of(net.minecraft.world.level.block.Blocks.GRANITE_SLAB); + public static BlockWrapper ANDESITE_SLAB = of(net.minecraft.world.level.block.Blocks.ANDESITE_SLAB); + public static BlockWrapper RED_NETHER_BRICK_SLAB = of(net.minecraft.world.level.block.Blocks.RED_NETHER_BRICK_SLAB); + public static BlockWrapper POLISHED_ANDESITE_SLAB = of(net.minecraft.world.level.block.Blocks.POLISHED_ANDESITE_SLAB); + public static BlockWrapper DIORITE_SLAB = of(net.minecraft.world.level.block.Blocks.DIORITE_SLAB); + public static BlockWrapper BRICK_WALL = of(net.minecraft.world.level.block.Blocks.BRICK_WALL); + public static BlockWrapper PRISMARINE_WALL = of(net.minecraft.world.level.block.Blocks.PRISMARINE_WALL); + public static BlockWrapper RED_SANDSTONE_WALL = of(net.minecraft.world.level.block.Blocks.RED_SANDSTONE_WALL); + public static BlockWrapper MOSSY_STONE_BRICK_WALL = of(net.minecraft.world.level.block.Blocks.MOSSY_STONE_BRICK_WALL); + public static BlockWrapper GRANITE_WALL = of(net.minecraft.world.level.block.Blocks.GRANITE_WALL); + public static BlockWrapper STONE_BRICK_WALL = of(net.minecraft.world.level.block.Blocks.STONE_BRICK_WALL); + public static BlockWrapper NETHER_BRICK_WALL = of(net.minecraft.world.level.block.Blocks.NETHER_BRICK_WALL); + public static BlockWrapper ANDESITE_WALL = of(net.minecraft.world.level.block.Blocks.ANDESITE_WALL); + public static BlockWrapper RED_NETHER_BRICK_WALL = of(net.minecraft.world.level.block.Blocks.RED_NETHER_BRICK_WALL); + public static BlockWrapper SANDSTONE_WALL = of(net.minecraft.world.level.block.Blocks.SANDSTONE_WALL); + public static BlockWrapper END_STONE_BRICK_WALL = of(net.minecraft.world.level.block.Blocks.END_STONE_BRICK_WALL); + public static BlockWrapper DIORITE_WALL = of(net.minecraft.world.level.block.Blocks.DIORITE_WALL); + public static BlockWrapper SCAFFOLDING = of(net.minecraft.world.level.block.Blocks.SCAFFOLDING); + public static BlockWrapper LOOM = of(net.minecraft.world.level.block.Blocks.LOOM); + public static BlockWrapper BARREL = of(net.minecraft.world.level.block.Blocks.BARREL); + public static BlockWrapper SMOKER = of(net.minecraft.world.level.block.Blocks.SMOKER); + public static BlockWrapper BLAST_FURNACE = of(net.minecraft.world.level.block.Blocks.BLAST_FURNACE); + public static BlockWrapper CARTOGRAPHY_TABLE = of(net.minecraft.world.level.block.Blocks.CARTOGRAPHY_TABLE); + public static BlockWrapper FLETCHING_TABLE = of(net.minecraft.world.level.block.Blocks.FLETCHING_TABLE); + public static BlockWrapper GRINDSTONE = of(net.minecraft.world.level.block.Blocks.GRINDSTONE); + public static BlockWrapper LECTERN = of(net.minecraft.world.level.block.Blocks.LECTERN); + public static BlockWrapper SMITHING_TABLE = of(net.minecraft.world.level.block.Blocks.SMITHING_TABLE); + public static BlockWrapper STONECUTTER = of(net.minecraft.world.level.block.Blocks.STONECUTTER); + public static BlockWrapper BELL = of(net.minecraft.world.level.block.Blocks.BELL); + public static BlockWrapper LANTERN = of(net.minecraft.world.level.block.Blocks.LANTERN); + public static BlockWrapper SOUL_LANTERN = of(net.minecraft.world.level.block.Blocks.SOUL_LANTERN); + public static BlockWrapper CAMPFIRE = of(net.minecraft.world.level.block.Blocks.CAMPFIRE); + public static BlockWrapper SOUL_CAMPFIRE = of(net.minecraft.world.level.block.Blocks.SOUL_CAMPFIRE); + public static BlockWrapper SWEET_BERRY_BUSH = of(net.minecraft.world.level.block.Blocks.SWEET_BERRY_BUSH); + public static BlockWrapper WARPED_STEM = of(net.minecraft.world.level.block.Blocks.WARPED_STEM); + public static BlockWrapper STRIPPED_WARPED_STEM = of(net.minecraft.world.level.block.Blocks.STRIPPED_WARPED_STEM); + public static BlockWrapper WARPED_HYPHAE = of(net.minecraft.world.level.block.Blocks.WARPED_HYPHAE); + public static BlockWrapper STRIPPED_WARPED_HYPHAE = of(net.minecraft.world.level.block.Blocks.STRIPPED_WARPED_HYPHAE); + public static BlockWrapper WARPED_NYLIUM = of(net.minecraft.world.level.block.Blocks.WARPED_NYLIUM); + public static BlockWrapper WARPED_FUNGUS = of(net.minecraft.world.level.block.Blocks.WARPED_FUNGUS); + public static BlockWrapper WARPED_WART_BLOCK = of(net.minecraft.world.level.block.Blocks.WARPED_WART_BLOCK); + public static BlockWrapper WARPED_ROOTS = of(net.minecraft.world.level.block.Blocks.WARPED_ROOTS); + public static BlockWrapper NETHER_SPROUTS = of(net.minecraft.world.level.block.Blocks.NETHER_SPROUTS); + public static BlockWrapper CRIMSON_STEM = of(net.minecraft.world.level.block.Blocks.CRIMSON_STEM); + public static BlockWrapper STRIPPED_CRIMSON_STEM = of(net.minecraft.world.level.block.Blocks.STRIPPED_CRIMSON_STEM); + public static BlockWrapper CRIMSON_HYPHAE = of(net.minecraft.world.level.block.Blocks.CRIMSON_HYPHAE); + public static BlockWrapper STRIPPED_CRIMSON_HYPHAE = of(net.minecraft.world.level.block.Blocks.STRIPPED_CRIMSON_HYPHAE); + public static BlockWrapper CRIMSON_NYLIUM = of(net.minecraft.world.level.block.Blocks.CRIMSON_NYLIUM); + public static BlockWrapper CRIMSON_FUNGUS = of(net.minecraft.world.level.block.Blocks.CRIMSON_FUNGUS); + public static BlockWrapper SHROOMLIGHT = of(net.minecraft.world.level.block.Blocks.SHROOMLIGHT); + public static BlockWrapper WEEPING_VINES = of(net.minecraft.world.level.block.Blocks.WEEPING_VINES); + public static BlockWrapper WEEPING_VINES_PLANT = of(net.minecraft.world.level.block.Blocks.WEEPING_VINES_PLANT); + public static BlockWrapper TWISTING_VINES = of(net.minecraft.world.level.block.Blocks.TWISTING_VINES); + public static BlockWrapper TWISTING_VINES_PLANT = of(net.minecraft.world.level.block.Blocks.TWISTING_VINES_PLANT); + public static BlockWrapper CRIMSON_ROOTS = of(net.minecraft.world.level.block.Blocks.CRIMSON_ROOTS); + public static BlockWrapper CRIMSON_PLANKS = of(net.minecraft.world.level.block.Blocks.CRIMSON_PLANKS); + public static BlockWrapper WARPED_PLANKS = of(net.minecraft.world.level.block.Blocks.WARPED_PLANKS); + public static BlockWrapper CRIMSON_SLAB = of(net.minecraft.world.level.block.Blocks.CRIMSON_SLAB); + public static BlockWrapper WARPED_SLAB = of(net.minecraft.world.level.block.Blocks.WARPED_SLAB); + public static BlockWrapper CRIMSON_PRESSURE_PLATE = of(net.minecraft.world.level.block.Blocks.CRIMSON_PRESSURE_PLATE); + public static BlockWrapper WARPED_PRESSURE_PLATE = of(net.minecraft.world.level.block.Blocks.WARPED_PRESSURE_PLATE); + public static BlockWrapper CRIMSON_FENCE = of(net.minecraft.world.level.block.Blocks.CRIMSON_FENCE); + public static BlockWrapper WARPED_FENCE = of(net.minecraft.world.level.block.Blocks.WARPED_FENCE); + public static BlockWrapper CRIMSON_TRAPDOOR = of(net.minecraft.world.level.block.Blocks.CRIMSON_TRAPDOOR); + public static BlockWrapper WARPED_TRAPDOOR = of(net.minecraft.world.level.block.Blocks.WARPED_TRAPDOOR); + public static BlockWrapper CRIMSON_FENCE_GATE = of(net.minecraft.world.level.block.Blocks.CRIMSON_FENCE_GATE); + public static BlockWrapper WARPED_FENCE_GATE = of(net.minecraft.world.level.block.Blocks.WARPED_FENCE_GATE); + public static BlockWrapper CRIMSON_STAIRS = of(net.minecraft.world.level.block.Blocks.CRIMSON_STAIRS); + public static BlockWrapper WARPED_STAIRS = of(net.minecraft.world.level.block.Blocks.WARPED_STAIRS); + public static BlockWrapper CRIMSON_BUTTON = of(net.minecraft.world.level.block.Blocks.CRIMSON_BUTTON); + public static BlockWrapper WARPED_BUTTON = of(net.minecraft.world.level.block.Blocks.WARPED_BUTTON); + public static BlockWrapper CRIMSON_DOOR = of(net.minecraft.world.level.block.Blocks.CRIMSON_DOOR); + public static BlockWrapper WARPED_DOOR = of(net.minecraft.world.level.block.Blocks.WARPED_DOOR); + public static BlockWrapper CRIMSON_SIGN = of(net.minecraft.world.level.block.Blocks.CRIMSON_SIGN); + public static BlockWrapper WARPED_SIGN = of(net.minecraft.world.level.block.Blocks.WARPED_SIGN); + public static BlockWrapper CRIMSON_WALL_SIGN = of(net.minecraft.world.level.block.Blocks.CRIMSON_WALL_SIGN); + public static BlockWrapper WARPED_WALL_SIGN = of(net.minecraft.world.level.block.Blocks.WARPED_WALL_SIGN); + public static BlockWrapper STRUCTURE_BLOCK = of(net.minecraft.world.level.block.Blocks.STRUCTURE_BLOCK); + public static BlockWrapper JIGSAW = of(net.minecraft.world.level.block.Blocks.JIGSAW); + public static BlockWrapper COMPOSTER = of(net.minecraft.world.level.block.Blocks.COMPOSTER); + public static BlockWrapper TARGET = of(net.minecraft.world.level.block.Blocks.TARGET); + public static BlockWrapper BEE_NEST = of(net.minecraft.world.level.block.Blocks.BEE_NEST); + public static BlockWrapper BEEHIVE = of(net.minecraft.world.level.block.Blocks.BEEHIVE); + public static BlockWrapper HONEY_BLOCK = of(net.minecraft.world.level.block.Blocks.HONEY_BLOCK); + public static BlockWrapper HONEYCOMB_BLOCK = of(net.minecraft.world.level.block.Blocks.HONEYCOMB_BLOCK); + public static BlockWrapper NETHERITE_BLOCK = of(net.minecraft.world.level.block.Blocks.NETHERITE_BLOCK); + public static BlockWrapper ANCIENT_DEBRIS = of(net.minecraft.world.level.block.Blocks.ANCIENT_DEBRIS); + public static BlockWrapper CRYING_OBSIDIAN = of(net.minecraft.world.level.block.Blocks.CRYING_OBSIDIAN); + public static BlockWrapper RESPAWN_ANCHOR = of(net.minecraft.world.level.block.Blocks.RESPAWN_ANCHOR); + public static BlockWrapper POTTED_CRIMSON_FUNGUS = of(net.minecraft.world.level.block.Blocks.POTTED_CRIMSON_FUNGUS); + public static BlockWrapper POTTED_WARPED_FUNGUS = of(net.minecraft.world.level.block.Blocks.POTTED_WARPED_FUNGUS); + public static BlockWrapper POTTED_CRIMSON_ROOTS = of(net.minecraft.world.level.block.Blocks.POTTED_CRIMSON_ROOTS); + public static BlockWrapper POTTED_WARPED_ROOTS = of(net.minecraft.world.level.block.Blocks.POTTED_WARPED_ROOTS); + public static BlockWrapper LODESTONE = of(net.minecraft.world.level.block.Blocks.LODESTONE); + public static BlockWrapper BLACKSTONE = of(net.minecraft.world.level.block.Blocks.BLACKSTONE); + public static BlockWrapper BLACKSTONE_STAIRS = of(net.minecraft.world.level.block.Blocks.BLACKSTONE_STAIRS); + public static BlockWrapper BLACKSTONE_WALL = of(net.minecraft.world.level.block.Blocks.BLACKSTONE_WALL); + public static BlockWrapper BLACKSTONE_SLAB = of(net.minecraft.world.level.block.Blocks.BLACKSTONE_SLAB); + public static BlockWrapper POLISHED_BLACKSTONE = of(net.minecraft.world.level.block.Blocks.POLISHED_BLACKSTONE); + public static BlockWrapper POLISHED_BLACKSTONE_BRICKS = of(net.minecraft.world.level.block.Blocks.POLISHED_BLACKSTONE_BRICKS); + public static BlockWrapper CRACKED_POLISHED_BLACKSTONE_BRICKS = of(net.minecraft.world.level.block.Blocks.CRACKED_POLISHED_BLACKSTONE_BRICKS); + public static BlockWrapper CHISELED_POLISHED_BLACKSTONE = of(net.minecraft.world.level.block.Blocks.CHISELED_POLISHED_BLACKSTONE); + public static BlockWrapper POLISHED_BLACKSTONE_BRICK_SLAB = of(net.minecraft.world.level.block.Blocks.POLISHED_BLACKSTONE_BRICK_SLAB); + public static BlockWrapper POLISHED_BLACKSTONE_BRICK_STAIRS = of(net.minecraft.world.level.block.Blocks.POLISHED_BLACKSTONE_BRICK_STAIRS); + public static BlockWrapper POLISHED_BLACKSTONE_BRICK_WALL = of(net.minecraft.world.level.block.Blocks.POLISHED_BLACKSTONE_BRICK_WALL); + public static BlockWrapper GILDED_BLACKSTONE = of(net.minecraft.world.level.block.Blocks.GILDED_BLACKSTONE); + public static BlockWrapper POLISHED_BLACKSTONE_STAIRS = of(net.minecraft.world.level.block.Blocks.POLISHED_BLACKSTONE_STAIRS); + public static BlockWrapper POLISHED_BLACKSTONE_SLAB = of(net.minecraft.world.level.block.Blocks.POLISHED_BLACKSTONE_SLAB); + public static BlockWrapper POLISHED_BLACKSTONE_PRESSURE_PLATE = of(net.minecraft.world.level.block.Blocks.POLISHED_BLACKSTONE_PRESSURE_PLATE); + public static BlockWrapper POLISHED_BLACKSTONE_BUTTON = of(net.minecraft.world.level.block.Blocks.POLISHED_BLACKSTONE_BUTTON); + public static BlockWrapper POLISHED_BLACKSTONE_WALL = of(net.minecraft.world.level.block.Blocks.POLISHED_BLACKSTONE_WALL); + public static BlockWrapper CHISELED_NETHER_BRICKS = of(net.minecraft.world.level.block.Blocks.CHISELED_NETHER_BRICKS); + public static BlockWrapper CRACKED_NETHER_BRICKS = of(net.minecraft.world.level.block.Blocks.CRACKED_NETHER_BRICKS); + public static BlockWrapper QUARTZ_BRICKS = of(net.minecraft.world.level.block.Blocks.QUARTZ_BRICKS); + + public static BlockWrapper of(net.minecraft.world.level.block.Block block) { + return BlockWrapper.of(block); + } + + public static List getBlocks() { + return BlockUtil.getBlocks().stream().map(BlockWrapper::of).collect(Collectors.toList()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/ITypedBlockWrapper.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/ITypedBlockWrapper.java new file mode 100644 index 000000000..fca9c46ad --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/ITypedBlockWrapper.java @@ -0,0 +1,32 @@ +package net.pitan76.mcpitanlib.midohra.block; + +import net.minecraft.world.level.block.Block; +import net.pitan76.mcpitanlib.api.block.ICompatBlock; + +public class ITypedBlockWrapper extends BlockWrapper { + protected ITypedBlockWrapper(T block) { + super((Block) block); + } + + public static ITypedBlockWrapper ofRaw(T item) { + return new ITypedBlockWrapper<>(item); + } + + public static ITypedBlockWrapper of(BlockWrapper wrapper) { + if (wrapper instanceof SupplierBlockWrapper) { + SupplierBlockWrapper supplierWrapper = (SupplierBlockWrapper) wrapper; + return SupplierITypedBlockWrapper.of(supplierWrapper); + } + + return new ITypedBlockWrapper<>((T) wrapper.get()); + } + + @Override + public Block get() { + return super.get(); + } + + public T getICompat() { + return (T) super.get(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/MCBlocks.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/MCBlocks.java new file mode 100644 index 000000000..b6426f748 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/MCBlocks.java @@ -0,0 +1,4 @@ +package net.pitan76.mcpitanlib.midohra.block; + +public class MCBlocks extends Blocks { +} 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..3e85fe120 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/SupplierBlockWrapper.java @@ -0,0 +1,38 @@ +package net.pitan76.mcpitanlib.midohra.block; + +import net.minecraft.world.level.block.Block; +import net.pitan76.mcpitanlib.api.registry.result.RegistryResult; +import net.pitan76.mcpitanlib.api.registry.result.RegistrySupplier; +import net.pitan76.mcpitanlib.midohra.core.INonTypedSupplier; + +import java.util.function.Supplier; + +public class SupplierBlockWrapper extends BlockWrapper implements INonTypedSupplier { + 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); + } + + public static SupplierBlockWrapper of(RegistrySupplier result) { + return new SupplierBlockWrapper(result::get); + } + + @Override + public SupplierBlockWrapper asNonTyped() { + return this; + } + + @Override + public Block get() { + return supplier.get(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/SupplierITypedBlockWrapper.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/SupplierITypedBlockWrapper.java new file mode 100644 index 000000000..e6e930fec --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/SupplierITypedBlockWrapper.java @@ -0,0 +1,57 @@ +package net.pitan76.mcpitanlib.midohra.block; + +import net.minecraft.world.level.block.Block; +import net.pitan76.mcpitanlib.api.block.ICompatBlock; +import net.pitan76.mcpitanlib.api.registry.result.RegistryResult; +import net.pitan76.mcpitanlib.api.registry.result.RegistrySupplier; +import net.pitan76.mcpitanlib.midohra.core.INonTypedSupplier; + +import java.util.function.Supplier; + +public class SupplierITypedBlockWrapper extends ITypedBlockWrapper implements INonTypedSupplier { + private final Supplier supplier; + + protected SupplierITypedBlockWrapper(Supplier supplier) { + super(null); + this.supplier = supplier; + } + + public static SupplierITypedBlockWrapper of(BlockWrapper wrapper) { + if (wrapper instanceof SupplierBlockWrapper) { + SupplierBlockWrapper supplierWrapper = (SupplierBlockWrapper) wrapper; + return SupplierITypedBlockWrapper.of(supplierWrapper); + } + + return new SupplierITypedBlockWrapper<>(() -> (T) wrapper.get()); + } + + public static SupplierITypedBlockWrapper of(Supplier supplier) { + return new SupplierITypedBlockWrapper<>(supplier); + } + + public static SupplierITypedBlockWrapper of(RegistryResult result) { + return new SupplierITypedBlockWrapper<>(result::get); + } + + public static SupplierITypedBlockWrapper of(RegistrySupplier result) { + return new SupplierITypedBlockWrapper<>(result::get); + } + + public static SupplierITypedBlockWrapper of(SupplierBlockWrapper result) { + return new SupplierITypedBlockWrapper<>(() -> (T) result.get()); + } + + @Override + public SupplierBlockWrapper asNonTyped() { + return SupplierBlockWrapper.of(this::get); + } + + @Override + public Block get() { + return (Block) supplier.get(); + } + + public T getICompat() { + return supplier.get(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/SupplierTypedBlockWrapper.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/SupplierTypedBlockWrapper.java new file mode 100644 index 000000000..f02e45c6a --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/SupplierTypedBlockWrapper.java @@ -0,0 +1,43 @@ +package net.pitan76.mcpitanlib.midohra.block; + +import net.minecraft.world.level.block.Block; +import net.pitan76.mcpitanlib.api.registry.result.RegistryResult; +import net.pitan76.mcpitanlib.api.registry.result.RegistrySupplier; +import net.pitan76.mcpitanlib.midohra.core.INonTypedSupplier; + +import java.util.function.Supplier; + +public class SupplierTypedBlockWrapper extends TypedBlockWrapper implements INonTypedSupplier { + private final Supplier supplier; + + protected SupplierTypedBlockWrapper(Supplier supplier) { + super(null); + this.supplier = supplier; + } + + public static SupplierTypedBlockWrapper of(Supplier supplier) { + return new SupplierTypedBlockWrapper<>(supplier); + } + + public static SupplierTypedBlockWrapper of(RegistryResult result) { + return new SupplierTypedBlockWrapper<>(result::get); + } + + public static SupplierTypedBlockWrapper of(RegistrySupplier result) { + return new SupplierTypedBlockWrapper<>(result::get); + } + + public static SupplierTypedBlockWrapper of(SupplierBlockWrapper result) { + return new SupplierTypedBlockWrapper<>(() -> (T) result.get()); + } + + @Override + public SupplierBlockWrapper asNonTyped() { + return SupplierBlockWrapper.of(this::get); + } + + @Override + public T get() { + return supplier.get(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/TypedBlockWrapper.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/TypedBlockWrapper.java new file mode 100644 index 000000000..21b5255f9 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/TypedBlockWrapper.java @@ -0,0 +1,27 @@ +package net.pitan76.mcpitanlib.midohra.block; + +import net.minecraft.world.level.block.Block; + +public class TypedBlockWrapper extends BlockWrapper { + protected TypedBlockWrapper(T block) { + super(block); + } + + public static TypedBlockWrapper ofRaw(T block) { + return new TypedBlockWrapper<>(block); + } + + public static TypedBlockWrapper of(BlockWrapper wrapper) { + if (wrapper instanceof SupplierBlockWrapper) { + SupplierBlockWrapper supplierWrapper = (SupplierBlockWrapper) wrapper; + return SupplierTypedBlockWrapper.of(supplierWrapper); + } + + return new TypedBlockWrapper<>((T) wrapper.get()); + } + + @Override + public T get() { + return (T) super.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..b6fe8300d --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/entity/BlockEntityTypeWrapper.java @@ -0,0 +1,81 @@ +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.world.level.block.entity.BlockEntityType type; + + public static final BlockEntityTypeWrapper EMPTY = new BlockEntityTypeWrapper(); + + protected BlockEntityTypeWrapper() { + this.type = null; + } + + protected BlockEntityTypeWrapper(net.minecraft.world.level.block.entity.BlockEntityType blockEntity) { + this.type = blockEntity; + } + + public static BlockEntityTypeWrapper of(net.minecraft.world.level.block.entity.BlockEntityType blockEntity) { + return new BlockEntityTypeWrapper(blockEntity); + } + + public static BlockEntityTypeWrapper of() { + return EMPTY; + } + + public net.minecraft.world.level.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().isValid(state.toMinecraft()); + } + + public boolean hasBlockEntity(BlockView world, BlockPos pos) { + if (isEmpty()) return false; + return get().getBlockEntity(world.getRaw(), pos.toMinecraft()) != null; + } + + public BlockEntityWrapper getBlockEntity(BlockView world, BlockPos pos) { + if (isEmpty()) + return BlockEntityWrapper.EMPTY; + + return BlockEntityWrapper.of(get().getBlockEntity(world.getRaw(), pos.toMinecraft())); + } + + public BlockEntityWrapper createBlockEntity(TileCreateEvent e) { + if (isEmpty()) + return BlockEntityWrapper.EMPTY; + + return BlockEntityWrapper.of(get().create(e.getBlockPos(), e.getBlockState())); + } + + @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; + + BlockEntityTypeWrapper other = (BlockEntityTypeWrapper) obj; + + if (isEmpty() && other.isEmpty()) return true; + if (isEmpty() || other.isEmpty()) return false; + + return get().equals(other.get()); + } +} 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..be5585a64 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/entity/BlockEntityWrapper.java @@ -0,0 +1,210 @@ +package net.pitan76.mcpitanlib.midohra.block.entity; + +import net.minecraft.world.level.block.entity.BlockEntity; +import net.pitan76.mcpitanlib.api.registry.CompatRegistryLookup; +import net.pitan76.mcpitanlib.api.tile.CompatBlockEntity; +import net.pitan76.mcpitanlib.api.tile.ICompatBlockEntity; +import net.pitan76.mcpitanlib.api.util.BlockEntityUtil; +import net.pitan76.mcpitanlib.api.util.RegistryLookupUtil; +import net.pitan76.mcpitanlib.api.util.world.TickerUtil; +import net.pitan76.mcpitanlib.midohra.block.BlockState; +import net.pitan76.mcpitanlib.midohra.block.BlockWrapper; +import net.pitan76.mcpitanlib.midohra.easybuilder.built.BuiltBlockEntity; +import net.pitan76.mcpitanlib.midohra.nbt.NbtCompound; +import net.pitan76.mcpitanlib.midohra.util.math.BlockPos; +import net.pitan76.mcpitanlib.midohra.world.World; + +import java.util.Optional; + +public class BlockEntityWrapper { + private final net.minecraft.world.level.block.entity.BlockEntity blockEntity; + + public static final BlockEntityWrapper EMPTY = new BlockEntityWrapper(null); + + protected BlockEntityWrapper() { + this.blockEntity = null; + } + + protected BlockEntityWrapper(net.minecraft.world.level.block.entity.BlockEntity blockEntity) { + this.blockEntity = blockEntity; + } + + public static BlockEntityWrapper of(net.minecraft.world.level.block.entity.BlockEntity blockEntity) { + return new BlockEntityWrapper(blockEntity); + } + + public static BlockEntityWrapper of() { + return EMPTY; + } + + public net.minecraft.world.level.block.entity.BlockEntity get() { + return blockEntity; + } + + public BlockPos getPos() { + return BlockPos.of(get().getBlockPos()); + } + + 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())); + } + + @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; + BlockEntityWrapper blockEntity = (BlockEntityWrapper) obj; + return get() == blockEntity.get(); + } + + public static BlockEntityWrapper of(BlockPos pos, World world) { + net.minecraft.world.level.block.entity.BlockEntity blockEntity = BlockEntityUtil.getBlockEntity(world.toMinecraft(), pos.toMinecraft()); + return of(blockEntity); + } + + public Optional toCompatBlockEntity() { + if (get() instanceof CompatBlockEntity) { + return Optional.of((CompatBlockEntity) get()); + } + return Optional.empty(); + } + + public Optional toBuiltBlockEntity() { + if (get() instanceof BuiltBlockEntity) { + return Optional.of((BuiltBlockEntity) get()); + } + return Optional.empty(); + } + + /** + * instanceof check for the block entity of this wrapper. + * @param clazz the class of the block entity to check + * @return true if the block entity of this wrapper is an instance of the given class, false otherwise + */ + public boolean instanceOf(Class clazz) { + if (isEmpty()) return false; + + return clazz.isInstance(get()); + } + + /** + * instanceof check for the block entity of this wrapper. + * @param wrapper the block entity to check + * @return true if the block entity of this wrapper is an instance of the given block entity, false otherwise + */ + public boolean instanceOf(BlockEntityWrapper wrapper) { + if (isEmpty()) return false; + + BlockEntity blockEntity = wrapper.get(); + if (blockEntity == null) return false; + + Class clazz = blockEntity.getClass(); + return clazz.isInstance(get()); + } + + public T getCompatBlockEntity(Class clazz) { + if (isEmpty()) return null; + if (get() instanceof CompatBlockEntity) { + CompatBlockEntity blockEntity = (CompatBlockEntity) get(); + if (clazz.isInstance(blockEntity)) + return clazz.cast(blockEntity); + } + return null; + } + + public Optional toCompatBlockEntity(Class clazz) { + return Optional.ofNullable(getCompatBlockEntity(clazz)); + } + + public void tick() { + TickerUtil.tick(get()); + } + + public int getX() { + return getPos().getX(); + } + + public int getY() { + return getPos().getY(); + } + + public int getZ() { + return getPos().getZ(); + } + + public BlockEntityTypeWrapper getType() { + return BlockEntityTypeWrapper.of(BlockEntityUtil.getType(get())); + } + + public T getICompatBlockEntity(Class clazz) { + if (isEmpty()) return null; + if (get() instanceof ICompatBlockEntity) { + ICompatBlockEntity blockEntity = (ICompatBlockEntity) get(); + if (clazz.isInstance(blockEntity)) + return clazz.cast(blockEntity); + } + return null; + } + + public Optional toICompatBlockEntity(Class clazz) { + return Optional.ofNullable(getICompatBlockEntity(clazz)); + } +} 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..eb2670d5b --- /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.world.level.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..aa04508d9 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/entity/SupplierBlockEntityTypeWrapper.java @@ -0,0 +1,38 @@ +package net.pitan76.mcpitanlib.midohra.block.entity; + +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.pitan76.mcpitanlib.api.registry.result.RegistryResult; +import net.pitan76.mcpitanlib.api.registry.result.RegistrySupplier; +import net.pitan76.mcpitanlib.midohra.core.INonTypedSupplier; + +import java.util.function.Supplier; + +public class SupplierBlockEntityTypeWrapper extends BlockEntityTypeWrapper implements INonTypedSupplier { + 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); + } + + public static SupplierBlockEntityTypeWrapper of(RegistrySupplier> result) { + return new SupplierBlockEntityTypeWrapper(result::get); + } + + @Override + public SupplierBlockEntityTypeWrapper asNonTyped() { + return this; + } + + @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..62008af08 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/entity/SupplierBlockEntityWrapper.java @@ -0,0 +1,38 @@ +package net.pitan76.mcpitanlib.midohra.block.entity; + +import net.minecraft.world.level.block.entity.BlockEntity; +import net.pitan76.mcpitanlib.api.registry.result.RegistryResult; +import net.pitan76.mcpitanlib.api.registry.result.RegistrySupplier; +import net.pitan76.mcpitanlib.midohra.core.INonTypedSupplier; + +import java.util.function.Supplier; + +public class SupplierBlockEntityWrapper extends BlockEntityWrapper implements INonTypedSupplier { + 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); + } + + public static SupplierBlockEntityWrapper of(RegistrySupplier result) { + return new SupplierBlockEntityWrapper(result::get); + } + + @Override + public SupplierBlockEntityWrapper asNonTyped() { + return this; + } + + @Override + public BlockEntity get() { + return supplier.get(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/entity/SupplierTypedBlockEntityTypeWrapper.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/entity/SupplierTypedBlockEntityTypeWrapper.java new file mode 100644 index 000000000..6885dd71d --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/entity/SupplierTypedBlockEntityTypeWrapper.java @@ -0,0 +1,44 @@ +package net.pitan76.mcpitanlib.midohra.block.entity; + +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.pitan76.mcpitanlib.api.registry.result.RegistryResult; +import net.pitan76.mcpitanlib.api.registry.result.RegistrySupplier; +import net.pitan76.mcpitanlib.midohra.core.INonTypedSupplier; + +import java.util.function.Supplier; + +public class SupplierTypedBlockEntityTypeWrapper extends TypedBlockEntityTypeWrapper implements INonTypedSupplier { + private final Supplier> supplier; + + protected SupplierTypedBlockEntityTypeWrapper(Supplier> supplier) { + super(null); + this.supplier = supplier; + } + + public static SupplierTypedBlockEntityTypeWrapper of(Supplier> supplier) { + return new SupplierTypedBlockEntityTypeWrapper<>(supplier); + } + + public static SupplierTypedBlockEntityTypeWrapper of(RegistryResult> result) { + return new SupplierTypedBlockEntityTypeWrapper<>(result::get); + } + + public static SupplierTypedBlockEntityTypeWrapper of(RegistrySupplier> result) { + return new SupplierTypedBlockEntityTypeWrapper<>(result::get); + } + + public static SupplierTypedBlockEntityTypeWrapper of(SupplierBlockEntityTypeWrapper result) { + return new SupplierTypedBlockEntityTypeWrapper<>(() -> (BlockEntityType) result.get()); + } + + @Override + public SupplierBlockEntityTypeWrapper asNonTyped() { + return SupplierBlockEntityTypeWrapper.of(this::get); + } + + @Override + public BlockEntityType get() { + return supplier.get(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/entity/SupplierTypedBlockEntityWrapper.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/entity/SupplierTypedBlockEntityWrapper.java new file mode 100644 index 000000000..3aa680cbf --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/entity/SupplierTypedBlockEntityWrapper.java @@ -0,0 +1,43 @@ +package net.pitan76.mcpitanlib.midohra.block.entity; + +import net.minecraft.world.level.block.entity.BlockEntity; +import net.pitan76.mcpitanlib.api.registry.result.RegistryResult; +import net.pitan76.mcpitanlib.api.registry.result.RegistrySupplier; +import net.pitan76.mcpitanlib.midohra.core.INonTypedSupplier; + +import java.util.function.Supplier; + +public class SupplierTypedBlockEntityWrapper extends TypedBlockEntityWrapper implements INonTypedSupplier { + private final Supplier supplier; + + protected SupplierTypedBlockEntityWrapper(Supplier supplier) { + super(null); + this.supplier = supplier; + } + + public static SupplierTypedBlockEntityWrapper of(Supplier supplier) { + return new SupplierTypedBlockEntityWrapper<>(supplier); + } + + public static SupplierTypedBlockEntityWrapper of(RegistryResult result) { + return new SupplierTypedBlockEntityWrapper<>(result::get); + } + + public static SupplierTypedBlockEntityWrapper of(RegistrySupplier result) { + return new SupplierTypedBlockEntityWrapper<>(result::get); + } + + public static SupplierTypedBlockEntityWrapper of(SupplierBlockEntityWrapper result) { + return new SupplierTypedBlockEntityWrapper<>(() -> (T) result.get()); + } + + @Override + public SupplierBlockEntityWrapper asNonTyped() { + return SupplierBlockEntityWrapper.of(this::get); + } + + @Override + public T get() { + return supplier.get(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/entity/TypedBlockEntityTypeWrapper.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/entity/TypedBlockEntityTypeWrapper.java new file mode 100644 index 000000000..26d0a7f3d --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/entity/TypedBlockEntityTypeWrapper.java @@ -0,0 +1,41 @@ +package net.pitan76.mcpitanlib.midohra.block.entity; + +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.pitan76.mcpitanlib.api.event.block.TileCreateEvent; +import net.pitan76.mcpitanlib.midohra.util.math.BlockPos; +import net.pitan76.mcpitanlib.midohra.world.BlockView; + +public class TypedBlockEntityTypeWrapper extends BlockEntityTypeWrapper { + protected TypedBlockEntityTypeWrapper(BlockEntityType type) { + super(type); + } + + public static TypedBlockEntityTypeWrapper ofRaw(BlockEntityType type) { + return new TypedBlockEntityTypeWrapper<>(type); + } + + public static TypedBlockEntityTypeWrapper of(BlockEntityTypeWrapper wrapper) { + if (wrapper instanceof SupplierBlockEntityTypeWrapper) { + SupplierBlockEntityTypeWrapper supplierWrapper = (SupplierBlockEntityTypeWrapper) wrapper; + return SupplierTypedBlockEntityTypeWrapper.of(supplierWrapper); + } + + return new TypedBlockEntityTypeWrapper<>((BlockEntityType) wrapper.get()); + } + + @Override + public BlockEntityType get() { + return (BlockEntityType) super.get(); + } + + @Override + public TypedBlockEntityWrapper getBlockEntity(BlockView world, BlockPos pos) { + return TypedBlockEntityWrapper.ofRaw(get().getBlockEntity(world.getRaw(), pos.toMinecraft())); + } + + @Override + public TypedBlockEntityWrapper createBlockEntity(TileCreateEvent e) { + return TypedBlockEntityWrapper.ofRaw(get().create(e.getBlockPos(), e.getBlockState())); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/entity/TypedBlockEntityWrapper.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/entity/TypedBlockEntityWrapper.java new file mode 100644 index 000000000..056796e36 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/entity/TypedBlockEntityWrapper.java @@ -0,0 +1,27 @@ +package net.pitan76.mcpitanlib.midohra.block.entity; + +import net.minecraft.world.level.block.entity.BlockEntity; + +public class TypedBlockEntityWrapper extends BlockEntityWrapper { + protected TypedBlockEntityWrapper(T blockEntity) { + super(blockEntity); + } + + public static TypedBlockEntityWrapper ofRaw(T blockEntity) { + return new TypedBlockEntityWrapper<>(blockEntity); + } + + public static TypedBlockEntityWrapper of(BlockEntityWrapper wrapper) { + if (wrapper instanceof SupplierBlockEntityWrapper) { + SupplierBlockEntityWrapper supplierWrapper = (SupplierBlockEntityWrapper) wrapper; + return SupplierTypedBlockEntityWrapper.of(supplierWrapper); + } + + return new TypedBlockEntityWrapper<>((T) wrapper.get()); + } + + @Override + public T get() { + return (T) super.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..a8103a2c1 --- /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.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.position()); + } + + public BlockPos getBlockPos() { + if (isEmpty()) return BlockPos.of(0, 0, 0); + return BlockPos.of(camera.blockPosition()); + } + + public float getYaw() { + if (isEmpty()) return 0f; + return camera.yRot(); + } + + public float getPitch() { + if (isEmpty()) return 0f; + return camera.xRot(); + } + + @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..0d57e2eff --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/component/ItemComponentTypes.java @@ -0,0 +1,132 @@ +package net.pitan76.mcpitanlib.midohra.component; + +import net.minecraft.core.component.DataComponents; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.chat.Component; +import net.minecraft.util.Unit; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Rarity; +import net.minecraft.world.item.component.TypedEntityData; +import net.pitan76.mcpitanlib.api.item.stack.LoreUtil; +import net.pitan76.mcpitanlib.api.util.*; +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<>(DataComponents.CUSTOM_DATA) { + @Override + public void put(ItemStack stack, CompoundTag value) { + CustomDataUtil.setNbt(stack, value); + } + + @Override + public CompoundTag get(ItemStack stack) { + return CustomDataUtil.getNbt(stack); + } + }; + + public static final ItemComponentType MAX_STACK_SIZE = new ItemComponentType<>(DataComponents.MAX_STACK_SIZE) { + @Override + public void put(ItemStack stack, Integer value) { + stack.set(DataComponents.MAX_STACK_SIZE, value); + } + + @Override + public Integer get(ItemStack stack) { + return stack.getMaxStackSize(); + } + }; + + public static final ItemComponentType MAX_DAMAGE = new ItemComponentType<>(DataComponents.MAX_DAMAGE) { + @Override + public void put(ItemStack stack, Integer value) { + stack.set(DataComponents.MAX_DAMAGE, value); + } + + @Override + public Integer get(ItemStack stack) { + return stack.getMaxDamage(); + } + }; + + public static final ItemComponentType DAMAGE = new ItemComponentType<>(DataComponents.DAMAGE) { + @Override + public void put(ItemStack stack, Integer value) { + stack.setDamageValue(value); + } + + @Override + public Integer get(ItemStack stack) { + return stack.getDamageValue(); + } + }; + + public static final ItemComponentType UNBREAKABLE = new ItemComponentType<>(DataComponents.UNBREAKABLE) { + @Override + public void put(ItemStack stack, Boolean value) { + if (value) { + stack.set(DataComponents.UNBREAKABLE, Unit.valueOf("")); + } else { + stack.remove(DataComponents.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<>(DataComponents.BLOCK_ENTITY_DATA) { + @Override + public void put(ItemStack stack, CompoundTag value) { + BlockEntityDataUtil.setBlockEntityNbt(stack, value); + } + + @Override + public CompoundTag get(ItemStack stack) { + return BlockEntityDataUtil.getBlockEntityNbt(stack); + } + }; + + public static final ItemComponentType ENTITY_DATA = new ItemComponentType<>(DataComponents.ENTITY_DATA) { + @Override + public void put(ItemStack stack, CompoundTag value) { + EntityType type = EntityTypeUtil.fromId(CompatIdentifier.of(NbtUtil.getString(value, "id"))); + stack.set(DataComponents.ENTITY_DATA, TypedEntityData.of(type, value)); + } + + @Override + public CompoundTag get(ItemStack stack) { + if (!has(stack)) return NbtUtil.create(); + if (!stack.has(DataComponents.ENTITY_DATA)) return NbtUtil.create(); + + TypedEntityData> data = stack.get(DataComponents.ENTITY_DATA); + CompoundTag nbt = data.copyTagWithoutId(); + + String id = EntityTypeUtil.toID(data.type()).toString(); + NbtUtil.putString(nbt, "id", id); + return nbt; + } + }; + + public static final ItemComponentType> LORE = new ItemComponentType<>(DataComponents.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..106de9917 --- /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.core.component.DataComponents; +import net.minecraft.world.item.ItemStack; +import net.minecraft.network.chat.Component; + +public class CustomNameComponentType extends ItemComponentType { + + public CustomNameComponentType() { + super(DataComponents.CUSTOM_NAME); + } + + @Override + public void put(ItemStack stack, Component value) { + stack.set(DataComponents.CUSTOM_NAME, value); + } + + @Override + public Component get(ItemStack stack) { + if (!has(stack)) return Component.empty(); + return stack.get(DataComponents.CUSTOM_NAME); + } + + public String getAsString(ItemStack stack) { + return get(stack).getString(); + } + + public void put(ItemStack stack, String name) { + put(stack, Component.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..d09355e29 --- /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.core.component.DataComponentType; +import net.minecraft.world.item.ItemStack; + +public abstract class ItemComponentType { + + private final DataComponentType type; + + protected ItemComponentType(DataComponentType 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.has(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..1f0dccfde --- /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.core.component.DataComponents; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Rarity; +import net.pitan76.mcpitanlib.api.util.CompatRarity; + +public class RarityComponentType extends ItemComponentType { + + public RarityComponentType() { + super(DataComponents.RARITY); + } + + @Override + public void put(ItemStack stack, Rarity value) { + stack.set(DataComponents.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/core/INonTypedSupplier.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/core/INonTypedSupplier.java new file mode 100644 index 000000000..ec505117d --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/core/INonTypedSupplier.java @@ -0,0 +1,5 @@ +package net.pitan76.mcpitanlib.midohra.core; + +public interface INonTypedSupplier { + T asNonTyped(); +} 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..bdfaa08b6 --- /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.world.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.world.phys.shapes.VoxelShape shape) { + return onOutlineShapeRaw(e -> shape); + } + + public BlockBuilder setCollisionShape(net.minecraft.world.phys.shapes.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..df0003607 --- /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.world.level.block.Block; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.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..84b906e79 --- /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.world.level.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..655fefce3 --- /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.world.item.ItemStack; +import net.minecraft.world.phys.shapes.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..e397a4e47 --- /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.world.level.block.state.BlockState; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.core.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..095e7190a --- /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.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.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..4dd0aa00c --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/entity/EntityTypeWrapper.java @@ -0,0 +1,100 @@ +package net.pitan76.mcpitanlib.midohra.entity; + +import net.minecraft.world.entity.Entity; +import net.pitan76.mcpitanlib.api.text.TextComponent; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.api.util.EntityTypeUtil; +import net.pitan76.mcpitanlib.midohra.util.math.BlockPos; +import net.pitan76.mcpitanlib.midohra.world.ServerWorld; +import org.jspecify.annotations.Nullable; + +import java.util.function.Consumer; + +public class EntityTypeWrapper { + private final net.minecraft.world.entity.EntityType entityType; + + protected EntityTypeWrapper() { + this.entityType = null; + } + + protected EntityTypeWrapper(net.minecraft.world.entity.EntityType entityType) { + this.entityType = entityType; + } + + public static EntityTypeWrapper of(net.minecraft.world.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.world.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); + } + + public EntityWrapper createEntity(ServerWorld world, SpawnReason spawnReason) { + if (isEmpty()) return EntityWrapper.of(); + return EntityWrapper.of(get().create(world.getRaw(), spawnReason.getRaw())); + } + + public EntityWrapper createEntity(ServerWorld world) { + return createEntity(world, SpawnReason.NATURAL); + } + + public EntityWrapper createEntity(ServerWorld world, @Nullable Consumer afterConsumer, BlockPos pos, SpawnReason reason, boolean alignPosition, boolean invertY) { + if (isEmpty()) return EntityWrapper.of(); + + Consumer consumer = afterConsumer != null ? entity -> { + EntityWrapper wrapper = EntityWrapper.of((Entity) entity); + afterConsumer.accept(wrapper); + } : null; + + return EntityWrapper.of(get().create(world.getRaw(), consumer, pos.toMinecraft(), reason.getRaw(), alignPosition, invertY)); + } + + public SpawnGroup getSpawnGroup() { + if (isEmpty()) return SpawnGroup.MISC; + return SpawnGroup.of(get().getCategory()); + } +} 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..5176754df --- /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.world.entity.EntityType; + +public class EntityTypes { + public static final EntityTypeWrapper BOAT = EntityTypeWrapper.of(EntityType.OAK_BOAT); + public static final EntityTypeWrapper ACACIA_BOAT = EntityTypeWrapper.of(net.minecraft.world.entity.EntityType.ACACIA_BOAT); + public static final EntityTypeWrapper ACACIA_CHEST_BOAT = EntityTypeWrapper.of(net.minecraft.world.entity.EntityType.ACACIA_CHEST_BOAT); + public static final EntityTypeWrapper BIRCH_BOAT = EntityTypeWrapper.of(net.minecraft.world.entity.EntityType.BIRCH_BOAT); + public static final EntityTypeWrapper BIRCH_CHEST_BOAT = EntityTypeWrapper.of(net.minecraft.world.entity.EntityType.BIRCH_CHEST_BOAT); + public static final EntityTypeWrapper DARK_OAK_BOAT = EntityTypeWrapper.of(net.minecraft.world.entity.EntityType.DARK_OAK_BOAT); + public static final EntityTypeWrapper DARK_OAK_CHEST_BOAT = EntityTypeWrapper.of(net.minecraft.world.entity.EntityType.DARK_OAK_CHEST_BOAT); + public static final EntityTypeWrapper JUNGLE_BOAT = EntityTypeWrapper.of(net.minecraft.world.entity.EntityType.JUNGLE_BOAT); + public static final EntityTypeWrapper JUNGLE_CHEST_BOAT = EntityTypeWrapper.of(net.minecraft.world.entity.EntityType.JUNGLE_CHEST_BOAT); + public static final EntityTypeWrapper SPRUCE_BOAT = EntityTypeWrapper.of(net.minecraft.world.entity.EntityType.SPRUCE_BOAT); + public static final EntityTypeWrapper SPRUCE_CHEST_BOAT = EntityTypeWrapper.of(net.minecraft.world.entity.EntityType.SPRUCE_CHEST_BOAT); + public static final EntityTypeWrapper FURNACE_MINECART = EntityTypeWrapper.of(net.minecraft.world.entity.EntityType.FURNACE_MINECART); + public static final EntityTypeWrapper HOPPER_MINECART = EntityTypeWrapper.of(net.minecraft.world.entity.EntityType.HOPPER_MINECART); + public static final EntityTypeWrapper MINECART = EntityTypeWrapper.of(net.minecraft.world.entity.EntityType.MINECART); + public static final EntityTypeWrapper TNT_MINECART = EntityTypeWrapper.of(net.minecraft.world.entity.EntityType.TNT_MINECART); + public static final EntityTypeWrapper CHEST_MINECART = EntityTypeWrapper.of(EntityType.CHEST_MINECART); + public static final EntityTypeWrapper HORSE = EntityTypeWrapper.of(net.minecraft.world.entity.EntityType.HORSE); + public static final EntityTypeWrapper LLAMA = EntityTypeWrapper.of(net.minecraft.world.entity.EntityType.LLAMA); + + public static final EntityTypeWrapper ITEM = EntityTypeWrapper.of(net.minecraft.world.entity.EntityType.ITEM); + public static final EntityTypeWrapper ITEM_DISPLAY = EntityTypeWrapper.of(EntityType.ITEM_DISPLAY); + public static final EntityTypeWrapper ITEM_FRAME = EntityTypeWrapper.of(net.minecraft.world.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.world.entity.EntityType.ALLAY); + public static final EntityTypeWrapper AXOLOTL = EntityTypeWrapper.of(net.minecraft.world.entity.EntityType.AXOLOTL); + public static final EntityTypeWrapper BAT = EntityTypeWrapper.of(net.minecraft.world.entity.EntityType.BAT); + public static final EntityTypeWrapper BEE = EntityTypeWrapper.of(net.minecraft.world.entity.EntityType.BEE); + public static final EntityTypeWrapper BLAZE = EntityTypeWrapper.of(net.minecraft.world.entity.EntityType.BLAZE); + public static final EntityTypeWrapper CAT = EntityTypeWrapper.of(net.minecraft.world.entity.EntityType.CAT); + public static final EntityTypeWrapper CHICKEN = EntityTypeWrapper.of(net.minecraft.world.entity.EntityType.CHICKEN); + public static final EntityTypeWrapper COD = EntityTypeWrapper.of(net.minecraft.world.entity.EntityType.COD); + public static final EntityTypeWrapper COW = EntityTypeWrapper.of(net.minecraft.world.entity.EntityType.COW); + public static final EntityTypeWrapper CREEPER = EntityTypeWrapper.of(net.minecraft.world.entity.EntityType.CREEPER); + public static final EntityTypeWrapper DOLPHIN = EntityTypeWrapper.of(net.minecraft.world.entity.EntityType.DOLPHIN); + public static final EntityTypeWrapper DONKEY = EntityTypeWrapper.of(net.minecraft.world.entity.EntityType.DONKEY); + public static final EntityTypeWrapper DROWNED = EntityTypeWrapper.of(net.minecraft.world.entity.EntityType.DROWNED); + public static final EntityTypeWrapper ELDER_GUARDIAN = EntityTypeWrapper.of(net.minecraft.world.entity.EntityType.ELDER_GUARDIAN); + public static final EntityTypeWrapper ENDER_DRAGON = EntityTypeWrapper.of(net.minecraft.world.entity.EntityType.ENDER_DRAGON); + public static final EntityTypeWrapper ENDERMAN = EntityTypeWrapper.of(net.minecraft.world.entity.EntityType.ENDERMAN); + public static final EntityTypeWrapper ENDERMITE = EntityTypeWrapper.of(net.minecraft.world.entity.EntityType.ENDERMITE); + public static final EntityTypeWrapper EVOKER = EntityTypeWrapper.of(net.minecraft.world.entity.EntityType.EVOKER); + public static final EntityTypeWrapper FOX = EntityTypeWrapper.of(net.minecraft.world.entity.EntityType.FOX); + public static final EntityTypeWrapper FROG = EntityTypeWrapper.of(net.minecraft.world.entity.EntityType.FROG); + public static final EntityTypeWrapper GHAST = EntityTypeWrapper.of(net.minecraft.world.entity.EntityType.GHAST); + public static final EntityTypeWrapper GIANT = EntityTypeWrapper.of(net.minecraft.world.entity.EntityType.GIANT); + public static final EntityTypeWrapper GLOW_SQUID = EntityTypeWrapper.of(net.minecraft.world.entity.EntityType.GLOW_SQUID); + public static final EntityTypeWrapper GOAT = EntityTypeWrapper.of(net.minecraft.world.entity.EntityType.GOAT); + public static final EntityTypeWrapper GUARDIAN = EntityTypeWrapper.of(net.minecraft.world.entity.EntityType.GUARDIAN); + public static final EntityTypeWrapper HUSK = EntityTypeWrapper.of(net.minecraft.world.entity.EntityType.HUSK); + public static final EntityTypeWrapper ILLUSIONER = EntityTypeWrapper.of(net.minecraft.world.entity.EntityType.ILLUSIONER); + public static final EntityTypeWrapper IRON_GOLEM = EntityTypeWrapper.of(net.minecraft.world.entity.EntityType.IRON_GOLEM); + public static final EntityTypeWrapper LLAMA_SPIT = EntityTypeWrapper.of(net.minecraft.world.entity.EntityType.LLAMA_SPIT); + public static final EntityTypeWrapper MAGMA_CUBE = EntityTypeWrapper.of(net.minecraft.world.entity.EntityType.MAGMA_CUBE); + public static final EntityTypeWrapper MARKER = EntityTypeWrapper.of(net.minecraft.world.entity.EntityType.MARKER); + public static final EntityTypeWrapper MOOSHROOM = EntityTypeWrapper.of(net.minecraft.world.entity.EntityType.MOOSHROOM); + public static final EntityTypeWrapper MULE = EntityTypeWrapper.of(net.minecraft.world.entity.EntityType.MULE); + public static final EntityTypeWrapper SKELETON = EntityTypeWrapper.of(net.minecraft.world.entity.EntityType.SKELETON); + public static final EntityTypeWrapper VILLAGER = EntityTypeWrapper.of(net.minecraft.world.entity.EntityType.VILLAGER); + public static final EntityTypeWrapper ZOMBIE = EntityTypeWrapper.of(net.minecraft.world.entity.EntityType.ZOMBIE); + public static final EntityTypeWrapper ZOMBIE_VILLAGER = EntityTypeWrapper.of(net.minecraft.world.entity.EntityType.ZOMBIE_VILLAGER); +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/entity/EntityWrapper.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/entity/EntityWrapper.java new file mode 100644 index 000000000..d13581990 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/entity/EntityWrapper.java @@ -0,0 +1,473 @@ +package net.pitan76.mcpitanlib.midohra.entity; + +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.LivingEntity; +import net.pitan76.mcpitanlib.api.entity.CompatEntity; +import net.pitan76.mcpitanlib.api.entity.ICompatEntity; +import net.pitan76.mcpitanlib.api.entity.Player; +import net.pitan76.mcpitanlib.api.text.TextComponent; +import net.pitan76.mcpitanlib.api.util.EntityUtil; +import net.pitan76.mcpitanlib.midohra.util.math.BlockPos; +import net.pitan76.mcpitanlib.midohra.util.math.ChunkPos; +import net.pitan76.mcpitanlib.midohra.util.math.Vector3d; +import net.pitan76.mcpitanlib.midohra.world.ServerWorld; +import net.pitan76.mcpitanlib.midohra.world.World; + +import java.util.Optional; +import java.util.UUID; + +public class EntityWrapper { + private final net.minecraft.world.entity.Entity entity; + + public static final EntityWrapper EMPTY = new EntityWrapper(null); + + protected EntityWrapper() { + this.entity = null; + } + + protected EntityWrapper(net.minecraft.world.entity.Entity entity) { + this.entity = entity; + } + + public static EntityWrapper of(net.minecraft.world.entity.Entity entity) { + return new EntityWrapper(entity); + } + + public static EntityWrapper of() { + return EMPTY; + } + + public boolean isPresent() { + return !isEmpty(); + } + + public boolean isEmpty() { + return get() == null; + } + + public net.minecraft.world.entity.Entity get() { + return entity; + } + + public EntityTypeWrapper getType() { + return EntityTypeWrapper.of(get().getType()); + } + + public Vector3d getPos() { + return EntityUtil.getPosM(get()); + } + + public void setPos(double x, double y, double z) { + EntityUtil.setPos(get(), x, y, z); + } + + public void setPos(Vector3d pos) { + EntityUtil.setPos(get(), pos); + } + + public void setPos(BlockPos pos) { + EntityUtil.setPos(get(), pos); + } + + public void teleport(double x, double y, double z) { + EntityUtil.teleport(get(), x, y, z); + } + + public void teleport(Vector3d pos) { + EntityUtil.teleport(get(), pos); + } + + public void teleport(BlockPos pos) { + EntityUtil.teleport(get(), pos); + } + + public void teleport(ServerWorld world, double x, double y, double z, float yaw, float pitch, boolean resetCamera) { + EntityUtil.teleport(get(), world.getRaw(), x, y, z, yaw, pitch, resetCamera); + } + + public void teleport(ServerWorld world, Vector3d pos, float yaw, float pitch, boolean resetCamera) { + EntityUtil.teleport(get(), world.getRaw(), pos, yaw, pitch, resetCamera); + } + + public void teleport(ServerWorld world, BlockPos pos, float yaw, float pitch, boolean resetCamera) { + EntityUtil.teleport(get(), world.getRaw(), pos, yaw, pitch, resetCamera); + } + + public void teleport(ServerWorld world, double x, double y, double z) { + EntityUtil.teleport(get(), world.getRaw(), x, y, z); + } + + public void teleport(ServerWorld world, Vector3d pos) { + EntityUtil.teleport(get(), world.getRaw(), pos); + } + + public void teleport(ServerWorld world, BlockPos pos) { + EntityUtil.teleport(get(), world.getRaw(), pos); + } + + public BlockPos getBlockPos() { + return BlockPos.of(get().blockPosition()); + } + + public World getWorld() { + return World.of(EntityUtil.getWorld(get())); + } + + public boolean isRemoved() { + return get().isRemoved(); + } + + public void discard() { + EntityUtil.discard(get()); + } + + public void kill() { + EntityUtil.kill(get()); + } + + public float getPitch() { + return EntityUtil.getPitch(get()); + } + + public float getYaw() { + return EntityUtil.getYaw(get()); + } + + public float getSpeed() { + return EntityUtil.getSpeed(get()); + } + + public TextComponent getCustomName() { + return new TextComponent(EntityUtil.getCustomName(get())); + } + + public TextComponent getName() { + return new TextComponent(EntityUtil.getName(get())); + } + + public String getNameAsString() { + return EntityUtil.getNameAsString(get()); + } + + public String getCustomNameAsString() { + return EntityUtil.getCustomNameAsString(get()); + } + + public UUID getUuid() { + return EntityUtil.getUuid(get()); + } + + public String getUuidString() { + return EntityUtil.getUuidString(get()); + } + + public boolean isSneaking() { + return EntityUtil.isSneaking(get()); + } + + public boolean isSprinting() { + return EntityUtil.isSprinting(get()); + } + + public boolean isSwimming() { + return EntityUtil.isSwimming(get()); + } + + public boolean isAlive() { + return EntityUtil.isAlive(get()); + } + + public boolean isOnGround() { + return EntityUtil.isOnGround(get()); + } + + public boolean isGlowing() { + return EntityUtil.isGlowing(get()); + } + + public boolean isInvisible() { + return EntityUtil.isInvisible(get()); + } + + public boolean isInvulnerable() { + return EntityUtil.isInvulnerable(get()); + } + + public boolean isSilent() { + return EntityUtil.isSilent(get()); + } + + public boolean isOnFire() { + return EntityUtil.isOnFire(get()); + } + + public boolean isRiding() { + return EntityUtil.isRiding(get()); + } + + public boolean isVelocityModified() { + return EntityUtil.isVelocityModified(get()); + } + + public boolean isCustomNameVisible() { + return EntityUtil.isCustomNameVisible(get()); + } + + public TextComponent getDisplayName() { + return new TextComponent(EntityUtil.getDisplayName(get())); + } + + public double getFallDistance() { + return EntityUtil.getFallDistance(get()); + } + + public boolean isLivingEntity() { + return get() instanceof LivingEntity; + } + + public boolean damageByMobAttack(float damageAmount, EntityWrapper source, EntityWrapper attacker) { + return EntityUtil.damageWithMobAttack(get(), damageAmount, source.get(), (LivingEntity) attacker.get()); + } + + public boolean damageByPlayerAttack(float damageAmount, EntityWrapper source, Player attacker) { + return EntityUtil.damageWithPlayerAttack(get(), damageAmount, source.get(), attacker); + } + + public boolean damageWithThrownProjectile(float damageAmount, EntityWrapper source, EntityWrapper projectile) { + return EntityUtil.damageWithThrownProjectile(get(), damageAmount, source.get(), projectile.get()); + } + + public boolean damageWithMobProjectile(float damageAmount, EntityWrapper projectile, EntityWrapper attacker) { + return EntityUtil.damageWithMobProjectile(get(), damageAmount, projectile.get(), (LivingEntity) attacker.get()); + } + + public boolean setVelocity(double x, double y, double z) { + EntityUtil.setVelocity(get(), x, y, z); + return true; + } + + public void setVelocity(Vector3d velocity) { + EntityUtil.setVelocity(get(), velocity); + } + + public void addVelocity(double x, double y, double z) { + EntityUtil.addVelocity(get(), x, y, z); + } + + public void addVelocity(Vector3d velocity) { + EntityUtil.addVelocity(get(), velocity); + } + + public Vector3d getVelocity() { + return Vector3d.of(EntityUtil.getVelocity(get())); + } + + public boolean setCustomName(TextComponent name) { + EntityUtil.setCustomName(get(), name.getText()); + return true; + } + + public boolean setInvulnerable(boolean invulnerable) { + EntityUtil.setInvulnerable(get(), invulnerable); + return true; + } + + public boolean setNoGravity(boolean noGravity) { + EntityUtil.setNoGravity(get(), noGravity); + return true; + } + + public boolean setGlowing(boolean glowing) { + EntityUtil.setGlowing(get(), glowing); + return true; + } + + public boolean setInvisible(boolean invisible) { + EntityUtil.setInvisible(get(), invisible); + return true; + } + + public boolean setSilent(boolean silent) { + EntityUtil.setSilent(get(), silent); + return true; + } + + public boolean setFire(int seconds) { + EntityUtil.setFire(get(), seconds); + return true; + } + + public boolean setCustomNameVisible(boolean visible) { + EntityUtil.setCustomNameVisible(get(), visible); + return true; + } + + public EntityWrapper getVehicle() { + return EntityWrapper.of(get().getVehicle()); + } + + public EntityWrapper getRootVehicle() { + return EntityWrapper.of(get().getRootVehicle()); + } + + public EntityWrapper getPassenger(int index) { + return EntityWrapper.of(get().getPassengers().get(index)); + } + + public int getPassengerCount() { + return get().getPassengers().size(); + } + + public Class getEntityClass() { + return get().getClass(); + } + + public Optional toCompatEntity() { + if (get() instanceof CompatEntity) { + return Optional.of((CompatEntity) get()); + } + return Optional.empty(); + } + + public void spawn(World world) { + world.spawnEntity(this); + } + + public ChunkPos getChunkPos() { + return ChunkPos.of(get().chunkPosition()); + } + + @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; + EntityWrapper other = (EntityWrapper) obj; + return get() != null && get().equals(other.get()); + } + + /** + * instanceof check for the entity of this wrapper. + * @param clazz the class of the entity to check + * @return true if the raw item of this stack is an instance of the given class, false otherwise + */ + public boolean instanceOf(Class clazz) { + if (isEmpty()) return false; + + return clazz.isInstance(get()); + } + + /** + * instanceof check for the entity of this wrapper. + * @param wrapper the entity to check + * @return true if the entity of this wrapper is an instance of the given entity, false otherwise + */ + public boolean instanceOf(EntityWrapper wrapper) { + if (isEmpty()) return false; + + Entity entity = wrapper.get(); + if (entity == null) return false; + + Class clazz = entity.getClass(); + return clazz.isInstance(get()); + } + + public SpawnGroup getSpawnGroup() { + return SpawnGroup.of(get().getType().getCategory()); + } + + public T getCompatEntity(Class clazz) { + if (isEmpty()) return null; + if (get() instanceof CompatEntity) { + CompatEntity compatEntity = (CompatEntity) get(); + if (clazz.isInstance(compatEntity)) + return clazz.cast(compatEntity); + } + return null; + } + + public Optional toCompatEntity(Class clazz) { + return Optional.ofNullable(getCompatEntity(clazz)); + } + + public boolean isPlayerEntity() { + return get() instanceof net.minecraft.world.entity.player.Player; + } + + public Optional toPlayer() { + if (isPlayerEntity()) { + return Optional.of(new Player((net.minecraft.world.entity.player.Player) get())); + } + return Optional.empty(); + } + + public void tick() { + get().tick(); + } + + public double getX() { + return getPos().getX(); + } + + public double getY() { + return getPos().getY(); + } + + public double getZ() { + return getPos().getZ(); + } + + public T getICompatEntity(Class clazz) { + if (isEmpty()) return null; + if (get() instanceof ICompatEntity) { + ICompatEntity compatEntity = (ICompatEntity) get(); + if (clazz.isInstance(compatEntity)) + return clazz.cast(compatEntity); + } + return null; + } + + public Optional toICompatEntity(Class clazz) { + return Optional.ofNullable(getICompatEntity(clazz)); + } + + public Vector3d getRotationVector() { + return Vector3d.of(EntityUtil.getRotationVector(get())); + } + + public void setFallDistance(float fallDistance) { + EntityUtil.setFallDistance(get(), fallDistance); + } + + public void setVelocityModified(boolean velocityModified) { + EntityUtil.setVelocityModified(get(), velocityModified); + } + + public void setSwimming(boolean swimming) { + EntityUtil.setSwimming(get(), swimming); + } + + public void setSprinting(boolean sprinting) { + EntityUtil.setSprinting(get(), sprinting); + } + + public void setSneaking(boolean sneaking) { + EntityUtil.setSneaking(get(), sneaking); + } + + public void setOnGround(boolean onGround) { + EntityUtil.setOnGround(get(), onGround); + } + + public void setUuid(UUID uuid) { + EntityUtil.setUuid(get(), uuid); + } + + public void setCustomName(String name) { + EntityUtil.setCustomName(get(), name); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/entity/IEntityM.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/entity/IEntityM.java new file mode 100644 index 000000000..1178c01f6 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/entity/IEntityM.java @@ -0,0 +1,42 @@ +package net.pitan76.mcpitanlib.midohra.entity; + +import net.minecraft.world.entity.Entity; +import net.pitan76.mcpitanlib.midohra.util.math.BlockPos; +import net.pitan76.mcpitanlib.midohra.util.math.Vector3d; +import net.pitan76.mcpitanlib.midohra.world.ServerWorld; +import net.pitan76.mcpitanlib.midohra.world.World; + +/** + * An interface for entities that can be used in the Midohra API. + * This interface provides default methods to get the entity's wrapper, position, world, and type. + * It is recommended to implement this interface in your custom entity classes to easily integrate with the Midohra API. + */ +public interface IEntityM { + default EntityWrapper getEntityWrapper() { + return EntityWrapper.of((Entity) this); + } + + default BlockPos getMidohraBlockPos() { + return getEntityWrapper().getBlockPos(); + } + + default Vector3d getMidohraPos() { + return getEntityWrapper().getPos(); + } + + default World getMidohraWorld() { + return getEntityWrapper().getWorld(); + } + + default EntityTypeWrapper getTypeM() { + return getEntityWrapper().getType(); + } + + default boolean hasServerWorld() { + return getMidohraWorld().isServer(); + } + + default ServerWorld getMidohraServerWorld() { + return getMidohraWorld().toServerWorld().get(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/entity/ItemEntityWrapper.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/entity/ItemEntityWrapper.java new file mode 100644 index 000000000..5878f8af4 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/entity/ItemEntityWrapper.java @@ -0,0 +1,84 @@ +package net.pitan76.mcpitanlib.midohra.entity; + +import net.pitan76.mcpitanlib.api.entity.Player; +import net.pitan76.mcpitanlib.api.util.entity.ItemEntityUtil; +import net.pitan76.mcpitanlib.midohra.item.ItemStack; +import net.pitan76.mcpitanlib.midohra.item.ItemWrapper; +import net.pitan76.mcpitanlib.midohra.util.math.BlockPos; +import net.pitan76.mcpitanlib.midohra.util.math.Vector3d; +import net.pitan76.mcpitanlib.midohra.world.World; + +public class ItemEntityWrapper extends EntityWrapper { + public ItemEntityWrapper(net.minecraft.world.entity.item.ItemEntity entity) { + super(entity); + } + + public static ItemEntityWrapper of(net.minecraft.world.entity.item.ItemEntity entity) { + return new ItemEntityWrapper(entity); + } + + @Override + public net.minecraft.world.entity.item.ItemEntity get() { + return (net.minecraft.world.entity.item.ItemEntity) super.get(); + } + + public net.minecraft.world.item.ItemStack getStackRaw() { + return ItemEntityUtil.getStack(get()); + } + + public ItemStack getStack() { + return ItemStack.of(getStackRaw()); + } + + public void setStack(net.minecraft.world.item.ItemStack stack) { + get().setItem(stack); + } + + public void setStack(ItemStack stack) { + setStack(stack.toMinecraft()); + } + + public ItemWrapper getItem() { + return getStack().getItem(); + } + + public static ItemEntityWrapper create(ItemStack stack, World world, double x, double y, double z) { + return of(ItemEntityUtil.create(world.toMinecraft(), x, y, z, stack.toMinecraft())); + } + + public static ItemEntityWrapper create(ItemStack stack, World world, Vector3d pos) { + return create(stack, world, pos.getX(), pos.getY(), pos.getZ()); + } + + public static ItemEntityWrapper create(ItemStack stack, World world, double x, double y, double z, double velocityX, double velocityY, double velocityZ) { + return of(ItemEntityUtil.create(world.toMinecraft(), x, y, z, stack.toMinecraft(), velocityX, velocityY, velocityZ)); + } + + public static ItemEntityWrapper create(ItemStack stack, World world, Vector3d pos, Vector3d velocity) { + return create(stack, world, pos.getX(), pos.getY(), pos.getZ(), velocity.getX(), velocity.getY(), velocity.getZ()); + } + + public static ItemEntityWrapper create(ItemStack stack, World world, BlockPos pos) { + return create(stack, world, pos.getX(), pos.getY(), pos.getZ()); + } + + public static ItemEntityWrapper createWithSpawn(ItemStack stack, World world, double x, double y, double z) { + return of(ItemEntityUtil.createWithSpawn(world.toMinecraft(), stack.toMinecraft(), x, y, z)); + } + + public static ItemEntityWrapper createWithSpawn(ItemStack stack, World world, Vector3d pos) { + return createWithSpawn(stack, world, pos.getX(), pos.getY(), pos.getZ()); + } + + public static ItemEntityWrapper createWithSpawn(ItemStack stack, World world, BlockPos pos) { + return createWithSpawn(stack, world, pos.getX(), pos.getY(), pos.getZ()); + } + + public void setToDefaultPickupDelay() { + ItemEntityUtil.setToDefaultPickupDelay(get()); + } + + public void onPlayerCollision(Player player) { + ItemEntityUtil.onPlayerCollision(this, player); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/entity/SpawnGroup.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/entity/SpawnGroup.java new file mode 100644 index 000000000..622613148 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/entity/SpawnGroup.java @@ -0,0 +1,76 @@ +package net.pitan76.mcpitanlib.midohra.entity; + +import net.pitan76.mcpitanlib.api.util.CompatStringIdentifiable; + +public class SpawnGroup implements CompatStringIdentifiable { + private final net.minecraft.world.entity.MobCategory spawnGroup; + + public static final SpawnGroup MONSTER = of(net.minecraft.world.entity.MobCategory.MONSTER); + public static final SpawnGroup CREATURE = of(net.minecraft.world.entity.MobCategory.CREATURE); + public static final SpawnGroup AMBIENT = of(net.minecraft.world.entity.MobCategory.AMBIENT); + public static final SpawnGroup AXOLOTLS = of(net.minecraft.world.entity.MobCategory.AXOLOTLS); + public static final SpawnGroup UNDERGROUND_WATER_CREATURE = of(net.minecraft.world.entity.MobCategory.UNDERGROUND_WATER_CREATURE); + public static final SpawnGroup WATER_CREATURE = of(net.minecraft.world.entity.MobCategory.WATER_CREATURE); + public static final SpawnGroup WATER_AMBIENT = of(net.minecraft.world.entity.MobCategory.WATER_AMBIENT); + public static final SpawnGroup MISC = of(net.minecraft.world.entity.MobCategory.MISC); + + protected SpawnGroup(net.minecraft.world.entity.MobCategory spawnGroup) { + this.spawnGroup = spawnGroup; + } + + public static SpawnGroup of(net.minecraft.world.entity.MobCategory spawnGroup) { + return new SpawnGroup(spawnGroup); + } + + public static SpawnGroup byName(String name) { + for (net.minecraft.world.entity.MobCategory group : net.minecraft.world.entity.MobCategory.values()) { + if (group.getName().equals(name)) { + return of(group); + } + } + + throw new IllegalArgumentException("No spawn group with name: " + name); + } + + public net.minecraft.world.entity.MobCategory getRaw() { + return spawnGroup; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + SpawnGroup other = (SpawnGroup) obj; + return getRaw() == other.getRaw(); + } + + @Override + public int hashCode() { + return getRaw().hashCode(); + } + + @Override + public String asString_compat() { + return getRaw().getName(); + } + + public int getCapacity() { + return getRaw().getMaxInstancesPerChunk(); + } + + public boolean isPeaceful() { + return getRaw().isFriendly(); + } + + public boolean isRare() { + return getRaw().isPersistent(); + } + + public int getImmediateDespawnRange() { + return getRaw().getDespawnDistance(); + } + + public int getDespawningStartRange() { + return getRaw().getNoDespawnDistance(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/entity/SpawnReason.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/entity/SpawnReason.java new file mode 100644 index 000000000..b15de0e83 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/entity/SpawnReason.java @@ -0,0 +1,50 @@ +package net.pitan76.mcpitanlib.midohra.entity; + +public class SpawnReason { + private final net.minecraft.world.entity.EntitySpawnReason raw; + + public static final SpawnReason NATURAL = of(net.minecraft.world.entity.EntitySpawnReason.NATURAL); + public static final SpawnReason CHUNK_GENERATION = of(net.minecraft.world.entity.EntitySpawnReason.CHUNK_GENERATION); + public static final SpawnReason SPAWNER = of(net.minecraft.world.entity.EntitySpawnReason.SPAWNER); + public static final SpawnReason STRUCTURE = of(net.minecraft.world.entity.EntitySpawnReason.STRUCTURE); + public static final SpawnReason BREEDING = of(net.minecraft.world.entity.EntitySpawnReason.BREEDING); + public static final SpawnReason MOB_SUMMONED = of(net.minecraft.world.entity.EntitySpawnReason.MOB_SUMMONED); + public static final SpawnReason JOCKEY = of(net.minecraft.world.entity.EntitySpawnReason.JOCKEY); + public static final SpawnReason EVENT = of(net.minecraft.world.entity.EntitySpawnReason.EVENT); + public static final SpawnReason CONVERSION = of(net.minecraft.world.entity.EntitySpawnReason.CONVERSION); + public static final SpawnReason REINFORCEMENT = of(net.minecraft.world.entity.EntitySpawnReason.REINFORCEMENT); + public static final SpawnReason TRIGGERED = of(net.minecraft.world.entity.EntitySpawnReason.TRIGGERED); + public static final SpawnReason BUCKET = of(net.minecraft.world.entity.EntitySpawnReason.BUCKET); + public static final SpawnReason SPAWN_ITEM_USE = of(net.minecraft.world.entity.EntitySpawnReason.SPAWN_ITEM_USE); + public static final SpawnReason COMMAND = of(net.minecraft.world.entity.EntitySpawnReason.COMMAND); + public static final SpawnReason DISPENSER = of(net.minecraft.world.entity.EntitySpawnReason.DISPENSER); + public static final SpawnReason PATROL = of(net.minecraft.world.entity.EntitySpawnReason.PATROL); + public static final SpawnReason TRIAL_SPAWNER = of(net.minecraft.world.entity.EntitySpawnReason.TRIAL_SPAWNER); + public static final SpawnReason LOAD = of(net.minecraft.world.entity.EntitySpawnReason.LOAD); + public static final SpawnReason DIMENSION_TRAVEL = of(net.minecraft.world.entity.EntitySpawnReason.DIMENSION_TRAVEL); + + protected SpawnReason(net.minecraft.world.entity.EntitySpawnReason raw) { + this.raw = raw; + } + + public static SpawnReason of(net.minecraft.world.entity.EntitySpawnReason raw) { + return new SpawnReason(raw); + } + + public net.minecraft.world.entity.EntitySpawnReason getRaw() { + return raw; + } + + @Override + public int hashCode() { + return raw.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + SpawnReason other = (SpawnReason) obj; + return raw == other.raw; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/entity/SupplierEntityTypeWrapper.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/entity/SupplierEntityTypeWrapper.java new file mode 100644 index 000000000..973669b4b --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/entity/SupplierEntityTypeWrapper.java @@ -0,0 +1,38 @@ +package net.pitan76.mcpitanlib.midohra.entity; + +import net.minecraft.world.entity.EntityType; +import net.pitan76.mcpitanlib.api.registry.result.RegistryResult; +import net.pitan76.mcpitanlib.api.registry.result.RegistrySupplier; +import net.pitan76.mcpitanlib.midohra.core.INonTypedSupplier; + +import java.util.function.Supplier; + +public class SupplierEntityTypeWrapper extends EntityTypeWrapper implements INonTypedSupplier { + private final Supplier> supplier; + + protected SupplierEntityTypeWrapper(Supplier> supplier) { + this.supplier = supplier; + } + + public static SupplierEntityTypeWrapper of(Supplier> supplier) { + return new SupplierEntityTypeWrapper(supplier); + } + + public static SupplierEntityTypeWrapper of(RegistryResult> result) { + return new SupplierEntityTypeWrapper(result::get); + } + + public static SupplierEntityTypeWrapper of(RegistrySupplier> result) { + return new SupplierEntityTypeWrapper(result::get); + } + + @Override + public SupplierEntityTypeWrapper asNonTyped() { + return this; + } + + @Override + public EntityType get() { + return supplier.get(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/entity/SupplierEntityWrapper.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/entity/SupplierEntityWrapper.java new file mode 100644 index 000000000..ea1c4d9ff --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/entity/SupplierEntityWrapper.java @@ -0,0 +1,38 @@ +package net.pitan76.mcpitanlib.midohra.entity; + +import net.minecraft.world.entity.Entity; +import net.pitan76.mcpitanlib.api.registry.result.RegistryResult; +import net.pitan76.mcpitanlib.api.registry.result.RegistrySupplier; +import net.pitan76.mcpitanlib.midohra.core.INonTypedSupplier; + +import java.util.function.Supplier; + +public class SupplierEntityWrapper extends EntityWrapper implements INonTypedSupplier { + private final Supplier supplier; + + protected SupplierEntityWrapper(Supplier supplier) { + this.supplier = supplier; + } + + public static SupplierEntityWrapper of(Supplier supplier) { + return new SupplierEntityWrapper(supplier); + } + + public static SupplierEntityWrapper of(RegistryResult result) { + return new SupplierEntityWrapper(result::get); + } + + public static SupplierEntityWrapper of(RegistrySupplier result) { + return new SupplierEntityWrapper(result::get); + } + + @Override + public SupplierEntityWrapper asNonTyped() { + return this; + } + + @Override + public Entity get() { + return supplier.get(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/entity/SupplierTypedEntityTypeWrapper.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/entity/SupplierTypedEntityTypeWrapper.java new file mode 100644 index 000000000..fa362a1e0 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/entity/SupplierTypedEntityTypeWrapper.java @@ -0,0 +1,44 @@ +package net.pitan76.mcpitanlib.midohra.entity; + +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityType; +import net.pitan76.mcpitanlib.api.registry.result.RegistryResult; +import net.pitan76.mcpitanlib.api.registry.result.RegistrySupplier; +import net.pitan76.mcpitanlib.midohra.core.INonTypedSupplier; + +import java.util.function.Supplier; + +public class SupplierTypedEntityTypeWrapper extends TypedEntityTypeWrapper implements INonTypedSupplier { + private final Supplier> supplier; + + protected SupplierTypedEntityTypeWrapper(Supplier> supplier) { + super(null); + this.supplier = supplier; + } + + public static SupplierTypedEntityTypeWrapper of(Supplier> supplier) { + return new SupplierTypedEntityTypeWrapper<>(supplier); + } + + public static SupplierTypedEntityTypeWrapper of(RegistryResult> result) { + return new SupplierTypedEntityTypeWrapper<>(result::get); + } + + public static SupplierTypedEntityTypeWrapper of(RegistrySupplier> result) { + return new SupplierTypedEntityTypeWrapper<>(result::get); + } + + public static SupplierTypedEntityTypeWrapper of(SupplierEntityTypeWrapper result) { + return new SupplierTypedEntityTypeWrapper<>(() -> (EntityType) result.get()); + } + + @Override + public SupplierEntityTypeWrapper asNonTyped() { + return SupplierEntityTypeWrapper.of(this::get); + } + + @Override + public EntityType get() { + return supplier.get(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/entity/TypedEntityTypeWrapper.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/entity/TypedEntityTypeWrapper.java new file mode 100644 index 000000000..9e89a8d6d --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/entity/TypedEntityTypeWrapper.java @@ -0,0 +1,50 @@ +package net.pitan76.mcpitanlib.midohra.entity; + +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityType; +import net.pitan76.mcpitanlib.midohra.util.math.BlockPos; +import net.pitan76.mcpitanlib.midohra.world.ServerWorld; +import org.jspecify.annotations.Nullable; + +import java.util.function.Consumer; + +public class TypedEntityTypeWrapper extends EntityTypeWrapper { + protected TypedEntityTypeWrapper(EntityType type) { + super(type); + } + + public static TypedEntityTypeWrapper ofRaw(EntityType type) { + return new TypedEntityTypeWrapper<>(type); + } + + public static TypedEntityTypeWrapper of(EntityTypeWrapper wrapper) { + if (wrapper instanceof SupplierEntityTypeWrapper) { + SupplierEntityTypeWrapper supplierWrapper = (SupplierEntityTypeWrapper) wrapper; + return SupplierTypedEntityTypeWrapper.of(supplierWrapper); + } + + return new TypedEntityTypeWrapper<>((EntityType) wrapper.get()); + } + + @Override + public EntityType get() { + return (EntityType) super.get(); + } + + public TypedEntityWrapper createEntity(ServerWorld world, SpawnReason spawnReason) { + return TypedEntityWrapper.ofRaw(get().create(world.getRaw(), spawnReason.getRaw())); + } + + public TypedEntityWrapper createEntity(ServerWorld world) { + return createEntity(world, SpawnReason.NATURAL); + } + + public TypedEntityWrapper createTypedEntity(ServerWorld world, @Nullable Consumer> afterConsumer, BlockPos pos, SpawnReason reason, boolean alignPosition, boolean invertY) { + Consumer consumer = afterConsumer != null ? entity -> { + TypedEntityWrapper wrapper = TypedEntityWrapper.ofRaw(entity); + afterConsumer.accept(wrapper); + } : null; + + return TypedEntityWrapper.ofRaw(get().create(world.getRaw(), consumer, pos.toMinecraft(), reason.getRaw(), alignPosition, invertY)); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/entity/TypedEntityWrapper.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/entity/TypedEntityWrapper.java new file mode 100644 index 000000000..350b9b93c --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/entity/TypedEntityWrapper.java @@ -0,0 +1,22 @@ +package net.pitan76.mcpitanlib.midohra.entity; + +import net.minecraft.world.entity.Entity; + +public class TypedEntityWrapper extends EntityWrapper { + protected TypedEntityWrapper(T entity) { + super(entity); + } + + public static TypedEntityWrapper ofRaw(T entity) { + return new TypedEntityWrapper<>(entity); + } + + public static TypedEntityWrapper of(EntityWrapper wrapper) { + return new TypedEntityWrapper<>((T) wrapper.get()); + } + + @Override + public T get() { + return (T) super.get(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/entity/projectile/ArrowEntityWrapper.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/entity/projectile/ArrowEntityWrapper.java new file mode 100644 index 000000000..da7305c90 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/entity/projectile/ArrowEntityWrapper.java @@ -0,0 +1,50 @@ +package net.pitan76.mcpitanlib.midohra.entity.projectile; + +import net.minecraft.world.entity.projectile.arrow.Arrow; +import net.pitan76.mcpitanlib.api.util.entity.ArrowEntityUtil; +import net.pitan76.mcpitanlib.midohra.entity.EntityWrapper; +import net.pitan76.mcpitanlib.midohra.item.ItemStack; +import net.pitan76.mcpitanlib.midohra.util.math.Vector3d; +import net.pitan76.mcpitanlib.midohra.world.World; + +public class ArrowEntityWrapper extends PersistentProjectileEntityWrapper { + protected ArrowEntityWrapper(Arrow entity) { + super(entity); + } + + public static ArrowEntityWrapper ofRaw(Arrow entity) { + return new ArrowEntityWrapper(entity); + } + + public static ArrowEntityWrapper ofArrow(EntityWrapper wrapper) { + return new ArrowEntityWrapper((Arrow) wrapper.get()); + } + + public static boolean isArrow(EntityWrapper wrapper) { + return wrapper.get() instanceof Arrow; + } + + public static ArrowEntityWrapper create(World world, double x, double y, double z) { + return new ArrowEntityWrapper(ArrowEntityUtil.create(world.toMinecraft(), x, y, z)); + } + + public static ArrowEntityWrapper create(World world, Vector3d pos) { + return create(world, pos.x, pos.y, pos.z); + } + + public static ArrowEntityWrapper create(World world, double x, double y, double z, ItemStack stack) { + return new ArrowEntityWrapper(ArrowEntityUtil.create(world.toMinecraft(), x, y, z, stack.toMinecraft())); + } + + public static ArrowEntityWrapper create(World world, Vector3d pos, ItemStack stack) { + return create(world, pos.x, pos.y, pos.z, stack); + } + + public void setVelocity(double x, double y, double z, float velocity, float divergence) { + ArrowEntityUtil.setVelocity(get(), x, y, z, velocity, divergence); + } + + public void setVelocity(Vector3d velocity, float speed, float uncertainty) { + setVelocity(velocity.x, velocity.y, velocity.z, speed, uncertainty); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/entity/projectile/PersistentProjectileEntityWrapper.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/entity/projectile/PersistentProjectileEntityWrapper.java new file mode 100644 index 000000000..0b451546c --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/entity/projectile/PersistentProjectileEntityWrapper.java @@ -0,0 +1,35 @@ +package net.pitan76.mcpitanlib.midohra.entity.projectile; + +import net.minecraft.world.entity.projectile.arrow.AbstractArrow; +import net.pitan76.mcpitanlib.midohra.entity.EntityWrapper; +import net.pitan76.mcpitanlib.midohra.item.ItemStack; + +public class PersistentProjectileEntityWrapper extends ProjectileEntityWrapper { + protected PersistentProjectileEntityWrapper(T entity) { + super(entity); + } + + public static PersistentProjectileEntityWrapper ofRaw(T entity) { + return new PersistentProjectileEntityWrapper<>(entity); + } + + public static boolean isPersistentProjectile(EntityWrapper wrapper) { + return wrapper.get() instanceof AbstractArrow; + } + + public static PersistentProjectileEntityWrapper ofPersistentProjectile(EntityWrapper wrapper) { + return new PersistentProjectileEntityWrapper<>((T) wrapper.get()); + } + + public int getPierceLevel() { + return get().getPierceLevel(); + } + + public ItemStack getStack() { + return ItemStack.of(get().getWeaponItem()); + } + + public void setDamage(double damage) { + get().setBaseDamage(damage); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/entity/projectile/ProjectileEntityWrapper.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/entity/projectile/ProjectileEntityWrapper.java new file mode 100644 index 000000000..232653f0f --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/entity/projectile/ProjectileEntityWrapper.java @@ -0,0 +1,49 @@ +package net.pitan76.mcpitanlib.midohra.entity.projectile; + +import net.minecraft.world.entity.projectile.Projectile; +import net.pitan76.mcpitanlib.api.util.entity.ProjectileEntityUtil; +import net.pitan76.mcpitanlib.midohra.entity.EntityWrapper; +import net.pitan76.mcpitanlib.midohra.entity.TypedEntityWrapper; +import net.pitan76.mcpitanlib.midohra.util.math.Vector3d; + +public class ProjectileEntityWrapper extends TypedEntityWrapper { + protected ProjectileEntityWrapper(T entity) { + super(entity); + } + + public static ProjectileEntityWrapper ofRaw(T entity) { + return new ProjectileEntityWrapper<>(entity); + } + + public static ProjectileEntityWrapper ofProjectile(EntityWrapper wrapper) { + return new ProjectileEntityWrapper<>((T) wrapper.get()); + } + + public static boolean isProjectile(EntityWrapper wrapper) { + return wrapper.get() instanceof Projectile; + } + + public void setVelocity(EntityWrapper shooter, float pitch, float yaw, float roll, float speed, float divergence) { + ProjectileEntityUtil.setVelocity(get(), shooter.get(), pitch, yaw, roll, speed, divergence); + } + + public void setVelocity(double x, double y, double z, float power, float uncertainty) { + ProjectileEntityUtil.setVelocity(get(), x, y, z, power, uncertainty); + } + + public void setVelocity(Vector3d velocity, float power, float uncertainty) { + setVelocity(velocity.x, velocity.y, velocity.z, power, uncertainty); + } + + public void setOwner(EntityWrapper owner) { + get().setOwner(owner.get()); + } + + public boolean hasOwner() { + return get().getOwner() != null; + } + + public EntityWrapper getOwner() { + return EntityWrapper.of(get().getOwner()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/entity/projectile/SmallFireballEntityWrapper.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/entity/projectile/SmallFireballEntityWrapper.java new file mode 100644 index 000000000..9d1cfe17f --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/entity/projectile/SmallFireballEntityWrapper.java @@ -0,0 +1,50 @@ +package net.pitan76.mcpitanlib.midohra.entity.projectile; + +import net.minecraft.world.entity.projectile.hurtingprojectile.SmallFireball; +import net.pitan76.mcpitanlib.api.util.entity.SmallFireballEntityUtil; +import net.pitan76.mcpitanlib.midohra.entity.EntityWrapper; +import net.pitan76.mcpitanlib.midohra.item.ItemStack; +import net.pitan76.mcpitanlib.midohra.util.math.Vector3d; +import net.pitan76.mcpitanlib.midohra.world.World; + +public class SmallFireballEntityWrapper extends ProjectileEntityWrapper { + protected SmallFireballEntityWrapper(SmallFireball entity) { + super(entity); + } + + public static SmallFireballEntityWrapper ofRaw(SmallFireball entity) { + return new SmallFireballEntityWrapper(entity); + } + + public static SmallFireballEntityWrapper ofSmallFireball(EntityWrapper wrapper) { + return new SmallFireballEntityWrapper((SmallFireball) wrapper.get()); + } + + public static boolean isSmallFireball(EntityWrapper wrapper) { + return wrapper.get() instanceof SmallFireball; + } + + public static SmallFireballEntityWrapper create(World world, double x, double y, double z, double velocityX, double velocityY, double velocityZ) { + return new SmallFireballEntityWrapper(SmallFireballEntityUtil.create(world.toMinecraft(), x, y, z, velocityX, velocityY, velocityZ)); + } + + public static SmallFireballEntityWrapper create(World world, Vector3d pos, Vector3d velocity) { + return create(world, pos.x, pos.y, pos.z, velocity.x, velocity.y, velocity.z); + } + + public void setStack(ItemStack stack) { + SmallFireballEntityUtil.setItem(get(), stack.toMinecraft()); + } + + public ItemStack getStack() { + return ItemStack.of(SmallFireballEntityUtil.getItem(get())); + } + + public void setVelocity(double x, double y, double z, float velocity, float divergence) { + SmallFireballEntityUtil.setVelocity(get(), x, y, z, velocity, divergence); + } + + public void setVelocity(Vector3d velocity, float speed, float uncertainty) { + setVelocity(velocity.x, velocity.y, velocity.z, speed, uncertainty); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/entity/projectile/SnowballEntityWrapper.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/entity/projectile/SnowballEntityWrapper.java new file mode 100644 index 000000000..e5f791da0 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/entity/projectile/SnowballEntityWrapper.java @@ -0,0 +1,58 @@ +package net.pitan76.mcpitanlib.midohra.entity.projectile; + +import net.minecraft.world.entity.projectile.throwableitemprojectile.Snowball; +import net.pitan76.mcpitanlib.api.util.entity.SnowballEntityUtil; +import net.pitan76.mcpitanlib.midohra.entity.EntityWrapper; +import net.pitan76.mcpitanlib.midohra.item.ItemStack; +import net.pitan76.mcpitanlib.midohra.util.math.Vector3d; +import net.pitan76.mcpitanlib.midohra.world.World; + +public class SnowballEntityWrapper extends ThrownItemEntityWrapper { + protected SnowballEntityWrapper(Snowball entity) { + super(entity); + } + + public static SnowballEntityWrapper ofRaw(Snowball entity) { + return new SnowballEntityWrapper(entity); + } + + public static SnowballEntityWrapper ofSnowball(EntityWrapper wrapper) { + return new SnowballEntityWrapper((Snowball) wrapper.get()); + } + + public static boolean isSnowball(EntityWrapper wrapper) { + return wrapper.get() instanceof Snowball; + } + + public static SnowballEntityWrapper create(World world, double x, double y, double z) { + return new SnowballEntityWrapper(SnowballEntityUtil.create(world.toMinecraft(), x, y, z)); + } + + public static SnowballEntityWrapper create(World world, Vector3d pos) { + return create(world, pos.x, pos.y, pos.z); + } + + public static SnowballEntityWrapper create(World world, double x, double y, double z, ItemStack stack) { + return new SnowballEntityWrapper(SnowballEntityUtil.create(world.toMinecraft(), x, y, z, stack.toMinecraft())); + } + + public static SnowballEntityWrapper create(World world, Vector3d pos, ItemStack stack) { + return create(world, pos.x, pos.y, pos.z, stack); + } + + public void setStack(ItemStack stack) { + SnowballEntityUtil.setItem(get(), stack.toMinecraft()); + } + + public ItemStack getStack() { + return ItemStack.of(SnowballEntityUtil.getItem(get())); + } + + public void setVelocity(double x, double y, double z, float velocity, float divergence) { + SnowballEntityUtil.setVelocity(get(), x, y, z, velocity, divergence); + } + + public void setVelocity(Vector3d velocity, float speed, float uncertainty) { + setVelocity(velocity.x, velocity.y, velocity.z, speed, uncertainty); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/entity/projectile/SpectralArrowEntityWrapper.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/entity/projectile/SpectralArrowEntityWrapper.java new file mode 100644 index 000000000..f15f9b197 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/entity/projectile/SpectralArrowEntityWrapper.java @@ -0,0 +1,50 @@ +package net.pitan76.mcpitanlib.midohra.entity.projectile; + +import net.minecraft.world.entity.projectile.arrow.SpectralArrow; +import net.pitan76.mcpitanlib.api.util.entity.SpectralArrowEntityUtil; +import net.pitan76.mcpitanlib.midohra.entity.EntityWrapper; +import net.pitan76.mcpitanlib.midohra.item.ItemStack; +import net.pitan76.mcpitanlib.midohra.util.math.Vector3d; +import net.pitan76.mcpitanlib.midohra.world.World; + +public class SpectralArrowEntityWrapper extends PersistentProjectileEntityWrapper { + protected SpectralArrowEntityWrapper(SpectralArrow entity) { + super(entity); + } + + public static SpectralArrowEntityWrapper ofRaw(SpectralArrow entity) { + return new SpectralArrowEntityWrapper(entity); + } + + public static SpectralArrowEntityWrapper ofSpectralArrow(EntityWrapper wrapper) { + return new SpectralArrowEntityWrapper((SpectralArrow) wrapper.get()); + } + + public static boolean isSpectralArrow(EntityWrapper wrapper) { + return wrapper.get() instanceof SpectralArrow; + } + + public static SpectralArrowEntityWrapper create(World world, double x, double y, double z) { + return new SpectralArrowEntityWrapper(SpectralArrowEntityUtil.create(world.toMinecraft(), x, y, z)); + } + + public static SpectralArrowEntityWrapper create(World world, Vector3d pos) { + return create(world, pos.x, pos.y, pos.z); + } + + public static SpectralArrowEntityWrapper create(World world, double x, double y, double z, ItemStack stack) { + return new SpectralArrowEntityWrapper(SpectralArrowEntityUtil.create(world.toMinecraft(), x, y, z, stack.toMinecraft())); + } + + public static SpectralArrowEntityWrapper create(World world, Vector3d pos, ItemStack stack) { + return create(world, pos.x, pos.y, pos.z, stack); + } + + public void setVelocity(double x, double y, double z, float velocity, float divergence) { + SpectralArrowEntityUtil.setVelocity(get(), x, y, z, velocity, divergence); + } + + public void setVelocity(Vector3d velocity, float speed, float uncertainty) { + setVelocity(velocity.x, velocity.y, velocity.z, speed, uncertainty); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/entity/projectile/ThrownEntityWrapper.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/entity/projectile/ThrownEntityWrapper.java new file mode 100644 index 000000000..e80be1e2d --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/entity/projectile/ThrownEntityWrapper.java @@ -0,0 +1,22 @@ +package net.pitan76.mcpitanlib.midohra.entity.projectile; + +import net.minecraft.world.entity.projectile.ThrowableProjectile; +import net.pitan76.mcpitanlib.midohra.entity.EntityWrapper; + +public class ThrownEntityWrapper extends ProjectileEntityWrapper { + protected ThrownEntityWrapper(T entity) { + super(entity); + } + + public static ThrownEntityWrapper ofRaw(T entity) { + return new ThrownEntityWrapper<>(entity); + } + + public static ThrownEntityWrapper ofThrown(EntityWrapper wrapper) { + return new ThrownEntityWrapper<>((T) wrapper.get()); + } + + public static boolean isThrown(EntityWrapper wrapper) { + return wrapper.get() instanceof ThrowableProjectile; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/entity/projectile/ThrownItemEntityWrapper.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/entity/projectile/ThrownItemEntityWrapper.java new file mode 100644 index 000000000..a1ebd0ede --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/entity/projectile/ThrownItemEntityWrapper.java @@ -0,0 +1,60 @@ +package net.pitan76.mcpitanlib.midohra.entity.projectile; + +import net.minecraft.world.entity.projectile.throwableitemprojectile.ThrowableItemProjectile; +import net.pitan76.mcpitanlib.api.entity.CompatThrownItemEntity; +import net.pitan76.mcpitanlib.api.util.entity.ThrownItemEntityUtil; +import net.pitan76.mcpitanlib.midohra.entity.EntityWrapper; +import net.pitan76.mcpitanlib.midohra.item.ItemStack; +import net.pitan76.mcpitanlib.midohra.util.math.Vector3d; + +import java.util.Optional; + +public class ThrownItemEntityWrapper extends ThrownEntityWrapper { + protected ThrownItemEntityWrapper(T entity) { + super(entity); + } + + public static ThrownItemEntityWrapper ofRaw(T entity) { + return new ThrownItemEntityWrapper<>(entity); + } + + public static ThrownItemEntityWrapper ofThrownItem(EntityWrapper wrapper) { + return new ThrownItemEntityWrapper<>((T) wrapper.get()); + } + + public static boolean isThrownItem(EntityWrapper wrapper) { + return wrapper.get() instanceof ThrowableItemProjectile; + } + + public void setStack(ItemStack stack) { + ThrownItemEntityUtil.setItem(get(), stack.toMinecraft()); + } + + public ItemStack getStack() { + return ItemStack.of(ThrownItemEntityUtil.getItem(get())); + } + + public void setVelocity(double x, double y, double z, float velocity, float divergence) { + ThrownItemEntityUtil.setVelocity(get(), x, y, z, velocity, divergence); + } + + public void setVelocity(EntityWrapper shooter, float pitch, float yaw, float roll, float speed, float divergence) { + ThrownItemEntityUtil.setVelocity(get(), shooter.get(), pitch, yaw, roll, speed, divergence); + } + + public void setVelocity(Vector3d velocity, float speed, float uncertainty) { + setVelocity(velocity.x, velocity.y, velocity.z, speed, uncertainty); + } + + public boolean isCompatThrownItemEntity() { + return get() instanceof CompatThrownItemEntity; + } + + public Optional asCompatThrownItemEntity() { + if (isCompatThrownItemEntity()) { + return Optional.of((CompatThrownItemEntity) get()); + } else { + return Optional.empty(); + } + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/fluid/FluidState.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/fluid/FluidState.java new file mode 100644 index 000000000..0a11e2bdc --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/fluid/FluidState.java @@ -0,0 +1,108 @@ +package net.pitan76.mcpitanlib.midohra.fluid; + +import net.pitan76.mcpitanlib.api.util.FluidStateUtil; +import net.pitan76.mcpitanlib.api.util.particle.effect.CompatParticleEffect; +import net.pitan76.mcpitanlib.midohra.block.BlockState; +import net.pitan76.mcpitanlib.midohra.util.math.Box; + +public class FluidState { + private final net.minecraft.world.level.material.FluidState fluidState; + + public FluidState(net.minecraft.world.level.material.FluidState fluidState) { + this.fluidState = fluidState; + } + + public static FluidState of(net.minecraft.world.level.material.FluidState fluidState) { + return new FluidState(fluidState); + } + + public net.minecraft.world.level.material.FluidState getRaw() { + return fluidState; + } + + public net.minecraft.world.level.material.FluidState toMinecraft() { + return getRaw(); + } + + public boolean isNull() { + return getRaw() == null; + } + + public boolean isEmpty() { + return isNull() || getRaw().isEmpty(); + } + + public FluidWrapper getFluid() { + return FluidWrapper.of(getRaw().getType()); + } + + public BlockState getBlockState() { + return BlockState.of(getRaw().createLegacyBlock()); + } + + public boolean hasRandomTicks() { + return getRaw().isRandomlyTicking(); + } + + public CompatParticleEffect getParticle() { + return CompatParticleEffect.of(getRaw().getDripParticle()); + } + + public int getLevel() { + return getRaw().getAmount(); + } + + public boolean isStill() { + return getRaw().isSource(); + } + + public boolean isFull() { + return getRaw().isFull(); + } + + public boolean isWater() { + return FluidStateUtil.isWater(getRaw()); + } + + public boolean isLava() { + return FluidStateUtil.isLava(getRaw()); + } + + + @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; + FluidState other = (FluidState) obj; + return getRaw().equals(other.getRaw()); + } + + public FluidState(FluidWrapper fluid) { + this.fluidState = fluid.getDefaultState(); + } + + public static FluidState of(FluidWrapper fluid) { + return new FluidState(fluid); + } + + public static FluidState water() { + return of(Fluids.WATER); + } + + public static FluidState lava() { + return of(Fluids.LAVA); + } + + public static FluidState flowingWater() { + return of(Fluids.FLOWING_WATER); + } + + public static FluidState flowingLava() { + return of(Fluids.FLOWING_LAVA); + } +} 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..75f2dd376 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/fluid/FluidWrapper.java @@ -0,0 +1,108 @@ +package net.pitan76.mcpitanlib.midohra.fluid; + +import net.minecraft.world.level.material.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.world.level.material.Fluid fluid; + + protected FluidWrapper() { + this.fluid = null; + } + + protected FluidWrapper(net.minecraft.world.level.material.Fluid fluid) { + this.fluid = fluid; + } + + public static FluidWrapper of(net.minecraft.world.level.material.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.world.level.material.Fluid get() { + return fluid; + } + + public net.minecraft.world.level.material.Fluid gerOrDefault(net.minecraft.world.level.material.Fluid defaultFluid) { + return getOrDefault(defaultFluid); + } + + public net.minecraft.world.level.material.Fluid getOrDefault(net.minecraft.world.level.material.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); + } + + public net.pitan76.mcpitanlib.midohra.fluid.FluidState createFluidState() { + return net.pitan76.mcpitanlib.midohra.fluid.FluidState.of(getDefaultState()); + } +} 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..50a525c48 --- /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.world.level.material.Fluids.EMPTY); + public static final FluidWrapper WATER = FluidWrapper.of(net.minecraft.world.level.material.Fluids.WATER); + public static final FluidWrapper LAVA = FluidWrapper.of(net.minecraft.world.level.material.Fluids.LAVA); + public static final FluidWrapper FLOWING_WATER = FluidWrapper.of(net.minecraft.world.level.material.Fluids.FLOWING_WATER); + public static final FluidWrapper FLOWING_LAVA = FluidWrapper.of(net.minecraft.world.level.material.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..de5b84f4e --- /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/ITypedItemWrapper.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/item/ITypedItemWrapper.java new file mode 100644 index 000000000..055d10ad5 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/item/ITypedItemWrapper.java @@ -0,0 +1,32 @@ +package net.pitan76.mcpitanlib.midohra.item; + +import net.minecraft.world.item.Item; +import net.pitan76.mcpitanlib.api.item.ICompatItem; + +public class ITypedItemWrapper extends ItemWrapper { + protected ITypedItemWrapper(T item) { + super((Item) item); + } + + public static ITypedItemWrapper ofRaw(T item) { + return new ITypedItemWrapper<>(item); + } + + public static ITypedItemWrapper of(ItemWrapper wrapper) { + if (wrapper instanceof SupplierItemWrapper) { + SupplierItemWrapper supplierWrapper = (SupplierItemWrapper) wrapper; + return SupplierITypedItemWrapper.of(supplierWrapper); + } + + return new ITypedItemWrapper<>((T) wrapper.get()); + } + + @Override + public Item get() { + return super.get(); + } + + public T getICompat() { + return (T) super.get(); + } +} 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..6c9d5810d --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/item/ItemGroupWrapper.java @@ -0,0 +1,112 @@ +package net.pitan76.mcpitanlib.midohra.item; + +import net.pitan76.mcpitanlib.api.text.TextComponent; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.api.util.item.ItemGroupUtil; + +import java.util.Collection; +import java.util.Collections; +import java.util.stream.Collectors; + +public class ItemGroupWrapper { + private final net.minecraft.world.item.CreativeModeTab itemGroup; + + protected ItemGroupWrapper() { + this.itemGroup = null; + } + + protected ItemGroupWrapper(net.minecraft.world.item.CreativeModeTab itemGroup) { + this.itemGroup = itemGroup; + } + + public static ItemGroupWrapper of(net.minecraft.world.item.CreativeModeTab 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.world.item.CreativeModeTab get() { + return itemGroup; + } + + public CompatIdentifier getId() { + if (isEmpty()) return CompatIdentifier.empty(); + return ItemGroupUtil.toCompatID(get()); + } + + public ItemStack getIcon() { + if (isEmpty()) return ItemStack.EMPTY; + return ItemStack.of(get().getIconItem()); + } + + public boolean rawEquals(ItemGroupWrapper other) { + return get() == other.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; + + ItemGroupWrapper other = (ItemGroupWrapper) obj; + return rawEquals(other); + } + + public ItemWrapper getIconItem() { + return getIcon().getItem(); + } + + public Type getType() { + if (get().getType().equals(net.minecraft.world.item.CreativeModeTab.Type.CATEGORY)) { + return Type.CATEGORY; + } else if (get().getType().equals(net.minecraft.world.item.CreativeModeTab.Type.INVENTORY)) { + return Type.INVENTORY; + } else if (get().getType().equals(net.minecraft.world.item.CreativeModeTab.Type.HOTBAR)) { + return Type.HOTBAR; + } else if (get().getType().equals(net.minecraft.world.item.CreativeModeTab.Type.SEARCH)) { + return Type.SEARCH; + } + + return Type.EMPTY; + } + + public Collection getDisplayItems() { + if (isEmpty()) return Collections.emptyList(); + return get().getDisplayItems().stream().map(ItemStack::of).collect(Collectors.toList()); + } + + public TextComponent getDisplayName() { + if (isEmpty()) return new TextComponent(""); + return new TextComponent(get().getDisplayName()); + } + + public static enum Type { + EMPTY, + CATEGORY, + INVENTORY, + HOTBAR, + SEARCH, + } +} 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..44a155291 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/item/ItemGroups.java @@ -0,0 +1,42 @@ +package net.pitan76.mcpitanlib.midohra.item; + +import net.minecraft.world.item.CreativeModeTabs; +import net.pitan76.mcpitanlib.api.item.DefaultItemGroups; + +import java.util.List; +import java.util.stream.Collectors; + +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.world.item.CreativeModeTab itemGroup) { + return ItemGroupWrapper.of(itemGroup); + } + + public static List getGroupsToDisplay() { + return CreativeModeTabs.allTabs().stream().map(ItemGroupWrapper::of).collect(Collectors.toList()); + } + + public static List getGroups() { + return CreativeModeTabs.tabs().stream().map(ItemGroupWrapper::of).collect(Collectors.toList()); + } +} 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..3769ec767 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/item/ItemStack.java @@ -0,0 +1,303 @@ +package net.pitan76.mcpitanlib.midohra.item; + +import net.minecraft.world.item.Item; +import net.minecraft.world.item.TooltipFlag; +import net.minecraft.world.level.ItemLike; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.chat.Component; +import net.minecraft.world.level.Level; +import net.pitan76.mcpitanlib.api.enchantment.CompatEnchantment; +import net.pitan76.mcpitanlib.api.item.stack.LoreUtil; +import net.pitan76.mcpitanlib.api.text.TextComponent; +import net.pitan76.mcpitanlib.api.util.*; +import net.pitan76.mcpitanlib.api.util.client.ClientUtil; +import net.pitan76.mcpitanlib.midohra.nbt.NbtCompound; +import org.jetbrains.annotations.Nullable; + +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +public class ItemStack { + private final net.minecraft.world.item.ItemStack stack; + public static final ItemStack EMPTY = new ItemStack(ItemStackUtil.empty()); + + protected ItemStack(net.minecraft.world.item.ItemStack stack) { + this.stack = stack; + } + + public static ItemStack of(net.minecraft.world.item.ItemStack stack) { + if (stack == null || stack.isEmpty()) + return EMPTY; + + return new ItemStack(stack); + } + + public static ItemStack of(ItemLike item) { + return new Builder().item(item).build(); + } + + public static ItemStack of(ItemLike 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 CompoundTag getCustomNbt() { + return CustomDataUtil.getNbt(stack); + } + + public void setCustomNbt(CompoundTag 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 Level world) { + return EnchantmentUtil.getEnchantment(stack, world); + } + + public void setEnchantments(Map enchantments, @Nullable Level 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.world.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 CompoundTag nbt = NbtUtil.create(); + + public Builder() { + + } + + public Builder item(CompatIdentifier id) { + this.id = id; + return this; + } + + public Builder item(ItemLike item) { + this.id = ItemUtil.toCompatID(item.asItem()); + return this; + } + + public Builder count(int count) { + this.count = count; + return this; + } + + public Builder nbt(CompoundTag nbt) { + this.nbt = nbt; + return this; + } + + public ItemStack build() { + net.minecraft.world.item.ItemStack stack = new net.minecraft.world.item.ItemStack(ItemUtil.fromId(id), count); + CustomDataUtil.setNbt(stack, nbt); + + return new ItemStack(stack); + } + } + + @Override + public String toString() { + return stack.toString(); + } + + public void increment(int amount) { + ItemStackUtil.incrementCount(stack, amount); + } + + public void decrement(int amount) { + ItemStackUtil.decrementCount(stack, amount); + } + + public void increment() { + increment(1); + } + + public void decrement() { + decrement(1); + } + + public boolean is(ItemWrapper item) { + return getRawItem() == item.get(); + } + + public boolean is(CompatIdentifier id) { + return getItemId().equals(id); + } + + public boolean isBlockItem() { + return getItem().isBlock(); + } + + public net.pitan76.mcpitanlib.midohra.nbt.NbtCompound getCustomNbtM() { + return net.pitan76.mcpitanlib.midohra.nbt.NbtCompound.of(getCustomNbt()); + } + + public void setCustomNbt(net.pitan76.mcpitanlib.midohra.nbt.NbtCompound nbt) { + setCustomNbt(nbt.toMinecraft()); + } + + public void setLoreM(List lore) { + LoreUtil.setLore(stack, lore.stream().map(TextComponent::getText).toList()); + } + + public List getLoreM() { + return getLore().stream().map(TextComponent::new).toList(); + } + + @Override + public int hashCode() { + return stack.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + + ItemStack other = (ItemStack) obj; + return stack.equals(other.stack); + } + + /** + * instanceof check for the raw item of this stack. + * @param clazz the class of the item to check + * @return true if the raw item of this stack is an instance of the given class, false otherwise + */ + public boolean instanceOf(Class clazz) { + if (isEmpty()) return false; + + return clazz.isInstance(getRawItem()); + } + + /** + * instanceof check for the raw item of this stack. + * @param wrapper the item to check + * @return true if the raw item of this stack is an instance of the given item, false otherwise + */ + public boolean instanceOf(ItemWrapper wrapper) { + if (isEmpty()) return false; + + Item item = wrapper.get(); + if (item == null) return false; + + Class clazz = item.getClass(); + return clazz.isInstance(getRawItem()); + } + + public List getTooltip() { + return stack.getTooltipLines(Item.TooltipContext.EMPTY, ClientUtil.getClientPlayer(), ClientUtil.getOptions().getRaw().advancedItemTooltips ? TooltipFlag.Default.ADVANCED : TooltipFlag.Default.NORMAL) + .stream().map(TextComponent::new).collect(Collectors.toList()); + } + + public void putCustomNbt(String key, T value) { + CustomDataUtil.put(stack, key, value); + } + + public void putCustomNbt(String key, NbtCompound value) { + CustomDataUtil.put(stack, key, value.toMinecraft()); + } + + public T getCustomNbt(String key, Class clazz) { + return CustomDataUtil.get(stack, key, clazz); + } + + public NbtCompound getCustomNbt(String key) { + return NbtCompound.of(CustomDataUtil.get(stack, key)); + } + + public boolean hasCustomNbt(String key) { + return CustomDataUtil.has(stack, key); + } + + public void removeCustomNbt(String key) { + CustomDataUtil.remove(stack, key); + } + + public boolean areItemsEqual(ItemStack other) { + return ItemStackUtil.areItemsEqual(this.stack, other.stack); + } + + public boolean areNbtOrComponentEqual(ItemStack other) { + return ItemStackUtil.areNbtOrComponentEqual(this.stack, other.stack); + } +} 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..d946d8a3c --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/item/ItemWrapper.java @@ -0,0 +1,221 @@ +package net.pitan76.mcpitanlib.midohra.item; + +import net.minecraft.world.item.Item; +import net.pitan76.mcpitanlib.api.item.ICompatItem; +import net.pitan76.mcpitanlib.api.item.v2.CompatItem; +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 net.pitan76.mcpitanlib.midohra.easybuilder.built.BuiltItem; +import org.jetbrains.annotations.Nullable; + +import java.util.Optional; + +public class ItemWrapper { + private final net.minecraft.world.item.Item item; + + protected ItemWrapper() { + this.item = null; + } + + protected ItemWrapper(net.minecraft.world.item.Item item) { + this.item = item; + } + + public static ItemWrapper of(net.minecraft.world.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.world.item.Items.AIR; + } + + @Nullable + public net.minecraft.world.item.Item get() { + return item; + } + + public net.minecraft.world.item.Item gerOrDefault(net.minecraft.world.item.Item defaultItem) { + return getOrDefault(defaultItem); + } + + public net.minecraft.world.item.Item getOrDefault(net.minecraft.world.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.world.item.BlockItem; + } + + public BlockWrapper asBlock() { + if (!isBlock()) + return BlockWrapper.of(); + + return BlockWrapper.of(((net.minecraft.world.item.BlockItem) get()).getBlock()); + } + + public boolean rawEquals(ItemWrapper item) { + return get() == item.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; + ItemWrapper item = (ItemWrapper) obj; + return rawEquals(item); + } + + public static ItemWrapper of(BlockWrapper block) { + if (block.isEmpty()) + return of(); + + return of(block.asItem().get()); + } + + public static ItemWrapper of(String id) { + return of(CompatIdentifier.of(id)); + } + + public static ItemWrapper of(String namespace, String path) { + return of(CompatIdentifier.of(namespace, path)); + } + + public static ItemWrapper of(CompatItem item) { + return of((net.minecraft.world.item.Item) item); + } + + public Optional toCompatItem() { + if (get() instanceof CompatItem) { + return Optional.of((CompatItem) get()); + } + return Optional.empty(); + } + + public Optional toBuiltItem() { + if (get() instanceof BuiltItem) { + return Optional.of((BuiltItem) get()); + } + return Optional.empty(); + } + + /** + * instanceof check for the item of this wrapper. + * @param clazz the class of the item to check + * @return true if the item of this wrapper is an instance of the given class, false otherwise + */ + public boolean instanceOf(Class clazz) { + if (isEmpty()) return false; + + return clazz.isInstance(get()); + } + + /** + * instanceof check for the item of this wrapper. + * @param wrapper the item to check + * @return true if the item of this wrapper is an instance of the given item, false otherwise + */ + public boolean instanceOf(ItemWrapper wrapper) { + if (isEmpty()) return false; + + Item item = wrapper.get(); + if (item == null) return false; + + Class clazz = item.getClass(); + return clazz.isInstance(get()); + } + + public T getCompatItem(Class clazz) { + if (isEmpty()) return null; + if (get() instanceof CompatItem) { + CompatItem compatItem = (CompatItem) get(); + if (clazz.isInstance(compatItem)) + return clazz.cast(compatItem); + } + return null; + } + + public Optional toCompatItem(Class clazz) { + return Optional.ofNullable(getCompatItem(clazz)); + } + + public T getICompatItem(Class clazz) { + if (isEmpty()) return null; + if (get() instanceof ICompatItem) { + ICompatItem compatItem = (ICompatItem) get(); + if (clazz.isInstance(compatItem)) + return clazz.cast(compatItem); + } + return null; + } + + public Optional toICompatItem(Class clazz) { + return Optional.ofNullable(getICompatItem(clazz)); + } +} 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..0d540109e --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/item/Items.java @@ -0,0 +1,993 @@ +package net.pitan76.mcpitanlib.midohra.item; + +import net.pitan76.mcpitanlib.api.util.item.ItemUtil; + +import java.util.List; +import java.util.stream.Collectors; + +public class Items { + public static ItemWrapper AIR = of(net.minecraft.world.item.Items.AIR); + public static ItemWrapper STONE = of(net.minecraft.world.item.Items.STONE); + public static ItemWrapper GRANITE = of(net.minecraft.world.item.Items.GRANITE); + public static ItemWrapper POLISHED_GRANITE = of(net.minecraft.world.item.Items.POLISHED_GRANITE); + public static ItemWrapper DIORITE = of(net.minecraft.world.item.Items.DIORITE); + public static ItemWrapper POLISHED_DIORITE = of(net.minecraft.world.item.Items.POLISHED_DIORITE); + public static ItemWrapper ANDESITE = of(net.minecraft.world.item.Items.ANDESITE); + public static ItemWrapper POLISHED_ANDESITE = of(net.minecraft.world.item.Items.POLISHED_ANDESITE); + public static ItemWrapper GRASS_BLOCK = of(net.minecraft.world.item.Items.GRASS_BLOCK); + public static ItemWrapper DIRT = of(net.minecraft.world.item.Items.DIRT); + public static ItemWrapper COARSE_DIRT = of(net.minecraft.world.item.Items.COARSE_DIRT); + public static ItemWrapper PODZOL = of(net.minecraft.world.item.Items.PODZOL); + public static ItemWrapper CRIMSON_NYLIUM = of(net.minecraft.world.item.Items.CRIMSON_NYLIUM); + public static ItemWrapper WARPED_NYLIUM = of(net.minecraft.world.item.Items.WARPED_NYLIUM); + public static ItemWrapper COBBLESTONE = of(net.minecraft.world.item.Items.COBBLESTONE); + public static ItemWrapper OAK_PLANKS = of(net.minecraft.world.item.Items.OAK_PLANKS); + public static ItemWrapper SPRUCE_PLANKS = of(net.minecraft.world.item.Items.SPRUCE_PLANKS); + public static ItemWrapper BIRCH_PLANKS = of(net.minecraft.world.item.Items.BIRCH_PLANKS); + public static ItemWrapper JUNGLE_PLANKS = of(net.minecraft.world.item.Items.JUNGLE_PLANKS); + public static ItemWrapper ACACIA_PLANKS = of(net.minecraft.world.item.Items.ACACIA_PLANKS); + public static ItemWrapper DARK_OAK_PLANKS = of(net.minecraft.world.item.Items.DARK_OAK_PLANKS); + public static ItemWrapper CRIMSON_PLANKS = of(net.minecraft.world.item.Items.CRIMSON_PLANKS); + public static ItemWrapper WARPED_PLANKS = of(net.minecraft.world.item.Items.WARPED_PLANKS); + public static ItemWrapper OAK_SAPLING = of(net.minecraft.world.item.Items.OAK_SAPLING); + public static ItemWrapper SPRUCE_SAPLING = of(net.minecraft.world.item.Items.SPRUCE_SAPLING); + public static ItemWrapper BIRCH_SAPLING = of(net.minecraft.world.item.Items.BIRCH_SAPLING); + public static ItemWrapper JUNGLE_SAPLING = of(net.minecraft.world.item.Items.JUNGLE_SAPLING); + public static ItemWrapper ACACIA_SAPLING = of(net.minecraft.world.item.Items.ACACIA_SAPLING); + public static ItemWrapper DARK_OAK_SAPLING = of(net.minecraft.world.item.Items.DARK_OAK_SAPLING); + public static ItemWrapper BEDROCK = of(net.minecraft.world.item.Items.BEDROCK); + public static ItemWrapper SAND = of(net.minecraft.world.item.Items.SAND); + public static ItemWrapper RED_SAND = of(net.minecraft.world.item.Items.RED_SAND); + public static ItemWrapper GRAVEL = of(net.minecraft.world.item.Items.GRAVEL); + public static ItemWrapper GOLD_ORE = of(net.minecraft.world.item.Items.GOLD_ORE); + public static ItemWrapper IRON_ORE = of(net.minecraft.world.item.Items.IRON_ORE); + public static ItemWrapper COAL_ORE = of(net.minecraft.world.item.Items.COAL_ORE); + public static ItemWrapper NETHER_GOLD_ORE = of(net.minecraft.world.item.Items.NETHER_GOLD_ORE); + public static ItemWrapper OAK_LOG = of(net.minecraft.world.item.Items.OAK_LOG); + public static ItemWrapper SPRUCE_LOG = of(net.minecraft.world.item.Items.SPRUCE_LOG); + public static ItemWrapper BIRCH_LOG = of(net.minecraft.world.item.Items.BIRCH_LOG); + public static ItemWrapper JUNGLE_LOG = of(net.minecraft.world.item.Items.JUNGLE_LOG); + public static ItemWrapper ACACIA_LOG = of(net.minecraft.world.item.Items.ACACIA_LOG); + public static ItemWrapper DARK_OAK_LOG = of(net.minecraft.world.item.Items.DARK_OAK_LOG); + public static ItemWrapper CRIMSON_STEM = of(net.minecraft.world.item.Items.CRIMSON_STEM); + public static ItemWrapper WARPED_STEM = of(net.minecraft.world.item.Items.WARPED_STEM); + public static ItemWrapper STRIPPED_OAK_LOG = of(net.minecraft.world.item.Items.STRIPPED_OAK_LOG); + public static ItemWrapper STRIPPED_SPRUCE_LOG = of(net.minecraft.world.item.Items.STRIPPED_SPRUCE_LOG); + public static ItemWrapper STRIPPED_BIRCH_LOG = of(net.minecraft.world.item.Items.STRIPPED_BIRCH_LOG); + public static ItemWrapper STRIPPED_JUNGLE_LOG = of(net.minecraft.world.item.Items.STRIPPED_JUNGLE_LOG); + public static ItemWrapper STRIPPED_ACACIA_LOG = of(net.minecraft.world.item.Items.STRIPPED_ACACIA_LOG); + public static ItemWrapper STRIPPED_DARK_OAK_LOG = of(net.minecraft.world.item.Items.STRIPPED_DARK_OAK_LOG); + public static ItemWrapper STRIPPED_CRIMSON_STEM = of(net.minecraft.world.item.Items.STRIPPED_CRIMSON_STEM); + public static ItemWrapper STRIPPED_WARPED_STEM = of(net.minecraft.world.item.Items.STRIPPED_WARPED_STEM); + public static ItemWrapper STRIPPED_OAK_WOOD = of(net.minecraft.world.item.Items.STRIPPED_OAK_WOOD); + public static ItemWrapper STRIPPED_SPRUCE_WOOD = of(net.minecraft.world.item.Items.STRIPPED_SPRUCE_WOOD); + public static ItemWrapper STRIPPED_BIRCH_WOOD = of(net.minecraft.world.item.Items.STRIPPED_BIRCH_WOOD); + public static ItemWrapper STRIPPED_JUNGLE_WOOD = of(net.minecraft.world.item.Items.STRIPPED_JUNGLE_WOOD); + public static ItemWrapper STRIPPED_ACACIA_WOOD = of(net.minecraft.world.item.Items.STRIPPED_ACACIA_WOOD); + public static ItemWrapper STRIPPED_DARK_OAK_WOOD = of(net.minecraft.world.item.Items.STRIPPED_DARK_OAK_WOOD); + public static ItemWrapper STRIPPED_CRIMSON_HYPHAE = of(net.minecraft.world.item.Items.STRIPPED_CRIMSON_HYPHAE); + public static ItemWrapper STRIPPED_WARPED_HYPHAE = of(net.minecraft.world.item.Items.STRIPPED_WARPED_HYPHAE); + public static ItemWrapper OAK_WOOD = of(net.minecraft.world.item.Items.OAK_WOOD); + public static ItemWrapper SPRUCE_WOOD = of(net.minecraft.world.item.Items.SPRUCE_WOOD); + public static ItemWrapper BIRCH_WOOD = of(net.minecraft.world.item.Items.BIRCH_WOOD); + public static ItemWrapper JUNGLE_WOOD = of(net.minecraft.world.item.Items.JUNGLE_WOOD); + public static ItemWrapper ACACIA_WOOD = of(net.minecraft.world.item.Items.ACACIA_WOOD); + public static ItemWrapper DARK_OAK_WOOD = of(net.minecraft.world.item.Items.DARK_OAK_WOOD); + public static ItemWrapper CRIMSON_HYPHAE = of(net.minecraft.world.item.Items.CRIMSON_HYPHAE); + public static ItemWrapper WARPED_HYPHAE = of(net.minecraft.world.item.Items.WARPED_HYPHAE); + public static ItemWrapper OAK_LEAVES = of(net.minecraft.world.item.Items.OAK_LEAVES); + public static ItemWrapper SPRUCE_LEAVES = of(net.minecraft.world.item.Items.SPRUCE_LEAVES); + public static ItemWrapper BIRCH_LEAVES = of(net.minecraft.world.item.Items.BIRCH_LEAVES); + public static ItemWrapper JUNGLE_LEAVES = of(net.minecraft.world.item.Items.JUNGLE_LEAVES); + public static ItemWrapper ACACIA_LEAVES = of(net.minecraft.world.item.Items.ACACIA_LEAVES); + public static ItemWrapper DARK_OAK_LEAVES = of(net.minecraft.world.item.Items.DARK_OAK_LEAVES); + public static ItemWrapper SPONGE = of(net.minecraft.world.item.Items.SPONGE); + public static ItemWrapper WET_SPONGE = of(net.minecraft.world.item.Items.WET_SPONGE); + public static ItemWrapper GLASS = of(net.minecraft.world.item.Items.GLASS); + public static ItemWrapper LAPIS_ORE = of(net.minecraft.world.item.Items.LAPIS_ORE); + public static ItemWrapper LAPIS_BLOCK = of(net.minecraft.world.item.Items.LAPIS_BLOCK); + public static ItemWrapper DISPENSER = of(net.minecraft.world.item.Items.DISPENSER); + public static ItemWrapper SANDSTONE = of(net.minecraft.world.item.Items.SANDSTONE); + public static ItemWrapper CHISELED_SANDSTONE = of(net.minecraft.world.item.Items.CHISELED_SANDSTONE); + public static ItemWrapper CUT_SANDSTONE = of(net.minecraft.world.item.Items.CUT_SANDSTONE); + public static ItemWrapper NOTE_BLOCK = of(net.minecraft.world.item.Items.NOTE_BLOCK); + public static ItemWrapper POWERED_RAIL = of(net.minecraft.world.item.Items.POWERED_RAIL); + public static ItemWrapper DETECTOR_RAIL = of(net.minecraft.world.item.Items.DETECTOR_RAIL); + public static ItemWrapper STICKY_PISTON = of(net.minecraft.world.item.Items.STICKY_PISTON); + public static ItemWrapper COBWEB = of(net.minecraft.world.item.Items.COBWEB); + public static ItemWrapper GRASS = of(net.minecraft.world.item.Items.SHORT_GRASS); + public static ItemWrapper FERN = of(net.minecraft.world.item.Items.FERN); + public static ItemWrapper DEAD_BUSH = of(net.minecraft.world.item.Items.DEAD_BUSH); + public static ItemWrapper SEAGRASS = of(net.minecraft.world.item.Items.SEAGRASS); + public static ItemWrapper SEA_PICKLE = of(net.minecraft.world.item.Items.SEA_PICKLE); + public static ItemWrapper PISTON = of(net.minecraft.world.item.Items.PISTON); + public static ItemWrapper WHITE_WOOL = of(net.minecraft.world.item.Items.WHITE_WOOL); + public static ItemWrapper ORANGE_WOOL = of(net.minecraft.world.item.Items.ORANGE_WOOL); + public static ItemWrapper MAGENTA_WOOL = of(net.minecraft.world.item.Items.MAGENTA_WOOL); + public static ItemWrapper LIGHT_BLUE_WOOL = of(net.minecraft.world.item.Items.LIGHT_BLUE_WOOL); + public static ItemWrapper YELLOW_WOOL = of(net.minecraft.world.item.Items.YELLOW_WOOL); + public static ItemWrapper LIME_WOOL = of(net.minecraft.world.item.Items.LIME_WOOL); + public static ItemWrapper PINK_WOOL = of(net.minecraft.world.item.Items.PINK_WOOL); + public static ItemWrapper GRAY_WOOL = of(net.minecraft.world.item.Items.GRAY_WOOL); + public static ItemWrapper LIGHT_GRAY_WOOL = of(net.minecraft.world.item.Items.LIGHT_GRAY_WOOL); + public static ItemWrapper CYAN_WOOL = of(net.minecraft.world.item.Items.CYAN_WOOL); + public static ItemWrapper PURPLE_WOOL = of(net.minecraft.world.item.Items.PURPLE_WOOL); + public static ItemWrapper BLUE_WOOL = of(net.minecraft.world.item.Items.BLUE_WOOL); + public static ItemWrapper BROWN_WOOL = of(net.minecraft.world.item.Items.BROWN_WOOL); + public static ItemWrapper GREEN_WOOL = of(net.minecraft.world.item.Items.GREEN_WOOL); + public static ItemWrapper RED_WOOL = of(net.minecraft.world.item.Items.RED_WOOL); + public static ItemWrapper BLACK_WOOL = of(net.minecraft.world.item.Items.BLACK_WOOL); + public static ItemWrapper DANDELION = of(net.minecraft.world.item.Items.DANDELION); + public static ItemWrapper POPPY = of(net.minecraft.world.item.Items.POPPY); + public static ItemWrapper BLUE_ORCHID = of(net.minecraft.world.item.Items.BLUE_ORCHID); + public static ItemWrapper ALLIUM = of(net.minecraft.world.item.Items.ALLIUM); + public static ItemWrapper AZURE_BLUET = of(net.minecraft.world.item.Items.AZURE_BLUET); + public static ItemWrapper RED_TULIP = of(net.minecraft.world.item.Items.RED_TULIP); + public static ItemWrapper ORANGE_TULIP = of(net.minecraft.world.item.Items.ORANGE_TULIP); + public static ItemWrapper WHITE_TULIP = of(net.minecraft.world.item.Items.WHITE_TULIP); + public static ItemWrapper PINK_TULIP = of(net.minecraft.world.item.Items.PINK_TULIP); + public static ItemWrapper OXEYE_DAISY = of(net.minecraft.world.item.Items.OXEYE_DAISY); + public static ItemWrapper CORNFLOWER = of(net.minecraft.world.item.Items.CORNFLOWER); + public static ItemWrapper LILY_OF_THE_VALLEY = of(net.minecraft.world.item.Items.LILY_OF_THE_VALLEY); + public static ItemWrapper WITHER_ROSE = of(net.minecraft.world.item.Items.WITHER_ROSE); + public static ItemWrapper BROWN_MUSHROOM = of(net.minecraft.world.item.Items.BROWN_MUSHROOM); + public static ItemWrapper RED_MUSHROOM = of(net.minecraft.world.item.Items.RED_MUSHROOM); + public static ItemWrapper CRIMSON_FUNGUS = of(net.minecraft.world.item.Items.CRIMSON_FUNGUS); + public static ItemWrapper WARPED_FUNGUS = of(net.minecraft.world.item.Items.WARPED_FUNGUS); + public static ItemWrapper CRIMSON_ROOTS = of(net.minecraft.world.item.Items.CRIMSON_ROOTS); + public static ItemWrapper WARPED_ROOTS = of(net.minecraft.world.item.Items.WARPED_ROOTS); + public static ItemWrapper NETHER_SPROUTS = of(net.minecraft.world.item.Items.NETHER_SPROUTS); + public static ItemWrapper WEEPING_VINES = of(net.minecraft.world.item.Items.WEEPING_VINES); + public static ItemWrapper TWISTING_VINES = of(net.minecraft.world.item.Items.TWISTING_VINES); + public static ItemWrapper SUGAR_CANE = of(net.minecraft.world.item.Items.SUGAR_CANE); + public static ItemWrapper KELP = of(net.minecraft.world.item.Items.KELP); + public static ItemWrapper BAMBOO = of(net.minecraft.world.item.Items.BAMBOO); + public static ItemWrapper GOLD_BLOCK = of(net.minecraft.world.item.Items.GOLD_BLOCK); + public static ItemWrapper IRON_BLOCK = of(net.minecraft.world.item.Items.IRON_BLOCK); + public static ItemWrapper OAK_SLAB = of(net.minecraft.world.item.Items.OAK_SLAB); + public static ItemWrapper SPRUCE_SLAB = of(net.minecraft.world.item.Items.SPRUCE_SLAB); + public static ItemWrapper BIRCH_SLAB = of(net.minecraft.world.item.Items.BIRCH_SLAB); + public static ItemWrapper JUNGLE_SLAB = of(net.minecraft.world.item.Items.JUNGLE_SLAB); + public static ItemWrapper ACACIA_SLAB = of(net.minecraft.world.item.Items.ACACIA_SLAB); + public static ItemWrapper DARK_OAK_SLAB = of(net.minecraft.world.item.Items.DARK_OAK_SLAB); + public static ItemWrapper CRIMSON_SLAB = of(net.minecraft.world.item.Items.CRIMSON_SLAB); + public static ItemWrapper WARPED_SLAB = of(net.minecraft.world.item.Items.WARPED_SLAB); + public static ItemWrapper STONE_SLAB = of(net.minecraft.world.item.Items.STONE_SLAB); + public static ItemWrapper SMOOTH_STONE_SLAB = of(net.minecraft.world.item.Items.SMOOTH_STONE_SLAB); + public static ItemWrapper SANDSTONE_SLAB = of(net.minecraft.world.item.Items.SANDSTONE_SLAB); + public static ItemWrapper CUT_SANDSTONE_SLAB = of(net.minecraft.world.item.Items.CUT_STANDSTONE_SLAB); + public static ItemWrapper PETRIFIED_OAK_SLAB = of(net.minecraft.world.item.Items.PETRIFIED_OAK_SLAB); + public static ItemWrapper COBBLESTONE_SLAB = of(net.minecraft.world.item.Items.COBBLESTONE_SLAB); + public static ItemWrapper BRICK_SLAB = of(net.minecraft.world.item.Items.BRICK_SLAB); + public static ItemWrapper STONE_BRICK_SLAB = of(net.minecraft.world.item.Items.STONE_BRICK_SLAB); + public static ItemWrapper NETHER_BRICK_SLAB = of(net.minecraft.world.item.Items.NETHER_BRICK_SLAB); + public static ItemWrapper QUARTZ_SLAB = of(net.minecraft.world.item.Items.QUARTZ_SLAB); + public static ItemWrapper RED_SANDSTONE_SLAB = of(net.minecraft.world.item.Items.RED_SANDSTONE_SLAB); + public static ItemWrapper CUT_RED_SANDSTONE_SLAB = of(net.minecraft.world.item.Items.CUT_RED_SANDSTONE_SLAB); + public static ItemWrapper PURPUR_SLAB = of(net.minecraft.world.item.Items.PURPUR_SLAB); + public static ItemWrapper PRISMARINE_SLAB = of(net.minecraft.world.item.Items.PRISMARINE_SLAB); + public static ItemWrapper PRISMARINE_BRICK_SLAB = of(net.minecraft.world.item.Items.PRISMARINE_BRICK_SLAB); + public static ItemWrapper DARK_PRISMARINE_SLAB = of(net.minecraft.world.item.Items.DARK_PRISMARINE_SLAB); + public static ItemWrapper SMOOTH_QUARTZ = of(net.minecraft.world.item.Items.SMOOTH_QUARTZ); + public static ItemWrapper SMOOTH_RED_SANDSTONE = of(net.minecraft.world.item.Items.SMOOTH_RED_SANDSTONE); + public static ItemWrapper SMOOTH_SANDSTONE = of(net.minecraft.world.item.Items.SMOOTH_SANDSTONE); + public static ItemWrapper SMOOTH_STONE = of(net.minecraft.world.item.Items.SMOOTH_STONE); + public static ItemWrapper BRICKS = of(net.minecraft.world.item.Items.BRICKS); + public static ItemWrapper TNT = of(net.minecraft.world.item.Items.TNT); + public static ItemWrapper BOOKSHELF = of(net.minecraft.world.item.Items.BOOKSHELF); + public static ItemWrapper MOSSY_COBBLESTONE = of(net.minecraft.world.item.Items.MOSSY_COBBLESTONE); + public static ItemWrapper OBSIDIAN = of(net.minecraft.world.item.Items.OBSIDIAN); + public static ItemWrapper TORCH = of(net.minecraft.world.item.Items.TORCH); + public static ItemWrapper END_ROD = of(net.minecraft.world.item.Items.END_ROD); + public static ItemWrapper CHORUS_PLANT = of(net.minecraft.world.item.Items.CHORUS_PLANT); + public static ItemWrapper CHORUS_FLOWER = of(net.minecraft.world.item.Items.CHORUS_FLOWER); + public static ItemWrapper PURPUR_BLOCK = of(net.minecraft.world.item.Items.PURPUR_BLOCK); + public static ItemWrapper PURPUR_PILLAR = of(net.minecraft.world.item.Items.PURPUR_PILLAR); + public static ItemWrapper PURPUR_STAIRS = of(net.minecraft.world.item.Items.PURPUR_STAIRS); + public static ItemWrapper SPAWNER = of(net.minecraft.world.item.Items.SPAWNER); + public static ItemWrapper OAK_STAIRS = of(net.minecraft.world.item.Items.OAK_STAIRS); + public static ItemWrapper CHEST = of(net.minecraft.world.item.Items.CHEST); + public static ItemWrapper DIAMOND_ORE = of(net.minecraft.world.item.Items.DIAMOND_ORE); + public static ItemWrapper DIAMOND_BLOCK = of(net.minecraft.world.item.Items.DIAMOND_BLOCK); + public static ItemWrapper CRAFTING_TABLE = of(net.minecraft.world.item.Items.CRAFTING_TABLE); + public static ItemWrapper FARMLAND = of(net.minecraft.world.item.Items.FARMLAND); + public static ItemWrapper FURNACE = of(net.minecraft.world.item.Items.FURNACE); + public static ItemWrapper LADDER = of(net.minecraft.world.item.Items.LADDER); + public static ItemWrapper RAIL = of(net.minecraft.world.item.Items.RAIL); + public static ItemWrapper COBBLESTONE_STAIRS = of(net.minecraft.world.item.Items.COBBLESTONE_STAIRS); + public static ItemWrapper LEVER = of(net.minecraft.world.item.Items.LEVER); + public static ItemWrapper STONE_PRESSURE_PLATE = of(net.minecraft.world.item.Items.STONE_PRESSURE_PLATE); + public static ItemWrapper OAK_PRESSURE_PLATE = of(net.minecraft.world.item.Items.OAK_PRESSURE_PLATE); + public static ItemWrapper SPRUCE_PRESSURE_PLATE = of(net.minecraft.world.item.Items.SPRUCE_PRESSURE_PLATE); + public static ItemWrapper BIRCH_PRESSURE_PLATE = of(net.minecraft.world.item.Items.BIRCH_PRESSURE_PLATE); + public static ItemWrapper JUNGLE_PRESSURE_PLATE = of(net.minecraft.world.item.Items.JUNGLE_PRESSURE_PLATE); + public static ItemWrapper ACACIA_PRESSURE_PLATE = of(net.minecraft.world.item.Items.ACACIA_PRESSURE_PLATE); + public static ItemWrapper DARK_OAK_PRESSURE_PLATE = of(net.minecraft.world.item.Items.DARK_OAK_PRESSURE_PLATE); + public static ItemWrapper CRIMSON_PRESSURE_PLATE = of(net.minecraft.world.item.Items.CRIMSON_PRESSURE_PLATE); + public static ItemWrapper WARPED_PRESSURE_PLATE = of(net.minecraft.world.item.Items.WARPED_PRESSURE_PLATE); + public static ItemWrapper POLISHED_BLACKSTONE_PRESSURE_PLATE = of(net.minecraft.world.item.Items.POLISHED_BLACKSTONE_PRESSURE_PLATE); + public static ItemWrapper REDSTONE_ORE = of(net.minecraft.world.item.Items.REDSTONE_ORE); + public static ItemWrapper REDSTONE_TORCH = of(net.minecraft.world.item.Items.REDSTONE_TORCH); + public static ItemWrapper SNOW = of(net.minecraft.world.item.Items.SNOW); + public static ItemWrapper ICE = of(net.minecraft.world.item.Items.ICE); + public static ItemWrapper SNOW_BLOCK = of(net.minecraft.world.item.Items.SNOW_BLOCK); + public static ItemWrapper CACTUS = of(net.minecraft.world.item.Items.CACTUS); + public static ItemWrapper CLAY = of(net.minecraft.world.item.Items.CLAY); + public static ItemWrapper JUKEBOX = of(net.minecraft.world.item.Items.JUKEBOX); + public static ItemWrapper OAK_FENCE = of(net.minecraft.world.item.Items.OAK_FENCE); + public static ItemWrapper SPRUCE_FENCE = of(net.minecraft.world.item.Items.SPRUCE_FENCE); + public static ItemWrapper BIRCH_FENCE = of(net.minecraft.world.item.Items.BIRCH_FENCE); + public static ItemWrapper JUNGLE_FENCE = of(net.minecraft.world.item.Items.JUNGLE_FENCE); + public static ItemWrapper ACACIA_FENCE = of(net.minecraft.world.item.Items.ACACIA_FENCE); + public static ItemWrapper DARK_OAK_FENCE = of(net.minecraft.world.item.Items.DARK_OAK_FENCE); + public static ItemWrapper CRIMSON_FENCE = of(net.minecraft.world.item.Items.CRIMSON_FENCE); + public static ItemWrapper WARPED_FENCE = of(net.minecraft.world.item.Items.WARPED_FENCE); + public static ItemWrapper PUMPKIN = of(net.minecraft.world.item.Items.PUMPKIN); + public static ItemWrapper CARVED_PUMPKIN = of(net.minecraft.world.item.Items.CARVED_PUMPKIN); + public static ItemWrapper NETHERRACK = of(net.minecraft.world.item.Items.NETHERRACK); + public static ItemWrapper SOUL_SAND = of(net.minecraft.world.item.Items.SOUL_SAND); + public static ItemWrapper SOUL_SOIL = of(net.minecraft.world.item.Items.SOUL_SOIL); + public static ItemWrapper BASALT = of(net.minecraft.world.item.Items.BASALT); + public static ItemWrapper POLISHED_BASALT = of(net.minecraft.world.item.Items.POLISHED_BASALT); + public static ItemWrapper SOUL_TORCH = of(net.minecraft.world.item.Items.SOUL_TORCH); + public static ItemWrapper GLOWSTONE = of(net.minecraft.world.item.Items.GLOWSTONE); + public static ItemWrapper JACK_O_LANTERN = of(net.minecraft.world.item.Items.JACK_O_LANTERN); + public static ItemWrapper OAK_TRAPDOOR = of(net.minecraft.world.item.Items.OAK_TRAPDOOR); + public static ItemWrapper SPRUCE_TRAPDOOR = of(net.minecraft.world.item.Items.SPRUCE_TRAPDOOR); + public static ItemWrapper BIRCH_TRAPDOOR = of(net.minecraft.world.item.Items.BIRCH_TRAPDOOR); + public static ItemWrapper JUNGLE_TRAPDOOR = of(net.minecraft.world.item.Items.JUNGLE_TRAPDOOR); + public static ItemWrapper ACACIA_TRAPDOOR = of(net.minecraft.world.item.Items.ACACIA_TRAPDOOR); + public static ItemWrapper DARK_OAK_TRAPDOOR = of(net.minecraft.world.item.Items.DARK_OAK_TRAPDOOR); + public static ItemWrapper CRIMSON_TRAPDOOR = of(net.minecraft.world.item.Items.CRIMSON_TRAPDOOR); + public static ItemWrapper WARPED_TRAPDOOR = of(net.minecraft.world.item.Items.WARPED_TRAPDOOR); + public static ItemWrapper INFESTED_STONE = of(net.minecraft.world.item.Items.INFESTED_STONE); + public static ItemWrapper INFESTED_COBBLESTONE = of(net.minecraft.world.item.Items.INFESTED_COBBLESTONE); + public static ItemWrapper INFESTED_STONE_BRICKS = of(net.minecraft.world.item.Items.INFESTED_STONE_BRICKS); + public static ItemWrapper INFESTED_MOSSY_STONE_BRICKS = of(net.minecraft.world.item.Items.INFESTED_MOSSY_STONE_BRICKS); + public static ItemWrapper INFESTED_CRACKED_STONE_BRICKS = of(net.minecraft.world.item.Items.INFESTED_CRACKED_STONE_BRICKS); + public static ItemWrapper INFESTED_CHISELED_STONE_BRICKS = of(net.minecraft.world.item.Items.INFESTED_CHISELED_STONE_BRICKS); + public static ItemWrapper STONE_BRICKS = of(net.minecraft.world.item.Items.STONE_BRICKS); + public static ItemWrapper MOSSY_STONE_BRICKS = of(net.minecraft.world.item.Items.MOSSY_STONE_BRICKS); + public static ItemWrapper CRACKED_STONE_BRICKS = of(net.minecraft.world.item.Items.CRACKED_STONE_BRICKS); + public static ItemWrapper CHISELED_STONE_BRICKS = of(net.minecraft.world.item.Items.CHISELED_STONE_BRICKS); + public static ItemWrapper BROWN_MUSHROOM_BLOCK = of(net.minecraft.world.item.Items.BROWN_MUSHROOM_BLOCK); + public static ItemWrapper RED_MUSHROOM_BLOCK = of(net.minecraft.world.item.Items.RED_MUSHROOM_BLOCK); + public static ItemWrapper MUSHROOM_STEM = of(net.minecraft.world.item.Items.MUSHROOM_STEM); + public static ItemWrapper IRON_BARS = of(net.minecraft.world.item.Items.IRON_BARS); + public static ItemWrapper CHAIN = of(net.minecraft.world.item.Items.IRON_CHAIN); + public static ItemWrapper GLASS_PANE = of(net.minecraft.world.item.Items.GLASS_PANE); + public static ItemWrapper MELON = of(net.minecraft.world.item.Items.MELON); + public static ItemWrapper VINE = of(net.minecraft.world.item.Items.VINE); + public static ItemWrapper OAK_FENCE_GATE = of(net.minecraft.world.item.Items.OAK_FENCE_GATE); + public static ItemWrapper SPRUCE_FENCE_GATE = of(net.minecraft.world.item.Items.SPRUCE_FENCE_GATE); + public static ItemWrapper BIRCH_FENCE_GATE = of(net.minecraft.world.item.Items.BIRCH_FENCE_GATE); + public static ItemWrapper JUNGLE_FENCE_GATE = of(net.minecraft.world.item.Items.JUNGLE_FENCE_GATE); + public static ItemWrapper ACACIA_FENCE_GATE = of(net.minecraft.world.item.Items.ACACIA_FENCE_GATE); + public static ItemWrapper DARK_OAK_FENCE_GATE = of(net.minecraft.world.item.Items.DARK_OAK_FENCE_GATE); + public static ItemWrapper CRIMSON_FENCE_GATE = of(net.minecraft.world.item.Items.CRIMSON_FENCE_GATE); + public static ItemWrapper WARPED_FENCE_GATE = of(net.minecraft.world.item.Items.WARPED_FENCE_GATE); + public static ItemWrapper BRICK_STAIRS = of(net.minecraft.world.item.Items.BRICK_STAIRS); + public static ItemWrapper STONE_BRICK_STAIRS = of(net.minecraft.world.item.Items.STONE_BRICK_STAIRS); + public static ItemWrapper MYCELIUM = of(net.minecraft.world.item.Items.MYCELIUM); + public static ItemWrapper LILY_PAD = of(net.minecraft.world.item.Items.LILY_PAD); + public static ItemWrapper NETHER_BRICKS = of(net.minecraft.world.item.Items.NETHER_BRICKS); + public static ItemWrapper CRACKED_NETHER_BRICKS = of(net.minecraft.world.item.Items.CRACKED_NETHER_BRICKS); + public static ItemWrapper CHISELED_NETHER_BRICKS = of(net.minecraft.world.item.Items.CHISELED_NETHER_BRICKS); + public static ItemWrapper NETHER_BRICK_FENCE = of(net.minecraft.world.item.Items.NETHER_BRICK_FENCE); + public static ItemWrapper NETHER_BRICK_STAIRS = of(net.minecraft.world.item.Items.NETHER_BRICK_STAIRS); + public static ItemWrapper ENCHANTING_TABLE = of(net.minecraft.world.item.Items.ENCHANTING_TABLE); + public static ItemWrapper END_PORTAL_FRAME = of(net.minecraft.world.item.Items.END_PORTAL_FRAME); + public static ItemWrapper END_STONE = of(net.minecraft.world.item.Items.END_STONE); + public static ItemWrapper END_STONE_BRICKS = of(net.minecraft.world.item.Items.END_STONE_BRICKS); + public static ItemWrapper DRAGON_EGG = of(net.minecraft.world.item.Items.DRAGON_EGG); + public static ItemWrapper REDSTONE_LAMP = of(net.minecraft.world.item.Items.REDSTONE_LAMP); + public static ItemWrapper SANDSTONE_STAIRS = of(net.minecraft.world.item.Items.SANDSTONE_STAIRS); + public static ItemWrapper EMERALD_ORE = of(net.minecraft.world.item.Items.EMERALD_ORE); + public static ItemWrapper ENDER_CHEST = of(net.minecraft.world.item.Items.ENDER_CHEST); + public static ItemWrapper TRIPWIRE_HOOK = of(net.minecraft.world.item.Items.TRIPWIRE_HOOK); + public static ItemWrapper EMERALD_BLOCK = of(net.minecraft.world.item.Items.EMERALD_BLOCK); + public static ItemWrapper SPRUCE_STAIRS = of(net.minecraft.world.item.Items.SPRUCE_STAIRS); + public static ItemWrapper BIRCH_STAIRS = of(net.minecraft.world.item.Items.BIRCH_STAIRS); + public static ItemWrapper JUNGLE_STAIRS = of(net.minecraft.world.item.Items.JUNGLE_STAIRS); + public static ItemWrapper CRIMSON_STAIRS = of(net.minecraft.world.item.Items.CRIMSON_STAIRS); + public static ItemWrapper WARPED_STAIRS = of(net.minecraft.world.item.Items.WARPED_STAIRS); + public static ItemWrapper COMMAND_BLOCK = of(net.minecraft.world.item.Items.COMMAND_BLOCK); + public static ItemWrapper BEACON = of(net.minecraft.world.item.Items.BEACON); + public static ItemWrapper COBBLESTONE_WALL = of(net.minecraft.world.item.Items.COBBLESTONE_WALL); + public static ItemWrapper MOSSY_COBBLESTONE_WALL = of(net.minecraft.world.item.Items.MOSSY_COBBLESTONE_WALL); + public static ItemWrapper BRICK_WALL = of(net.minecraft.world.item.Items.BRICK_WALL); + public static ItemWrapper PRISMARINE_WALL = of(net.minecraft.world.item.Items.PRISMARINE_WALL); + public static ItemWrapper RED_SANDSTONE_WALL = of(net.minecraft.world.item.Items.RED_SANDSTONE_WALL); + public static ItemWrapper MOSSY_STONE_BRICK_WALL = of(net.minecraft.world.item.Items.MOSSY_STONE_BRICK_WALL); + public static ItemWrapper GRANITE_WALL = of(net.minecraft.world.item.Items.GRANITE_WALL); + public static ItemWrapper STONE_BRICK_WALL = of(net.minecraft.world.item.Items.STONE_BRICK_WALL); + public static ItemWrapper NETHER_BRICK_WALL = of(net.minecraft.world.item.Items.NETHER_BRICK_WALL); + public static ItemWrapper ANDESITE_WALL = of(net.minecraft.world.item.Items.ANDESITE_WALL); + public static ItemWrapper RED_NETHER_BRICK_WALL = of(net.minecraft.world.item.Items.RED_NETHER_BRICK_WALL); + public static ItemWrapper SANDSTONE_WALL = of(net.minecraft.world.item.Items.SANDSTONE_WALL); + public static ItemWrapper END_STONE_BRICK_WALL = of(net.minecraft.world.item.Items.END_STONE_BRICK_WALL); + public static ItemWrapper DIORITE_WALL = of(net.minecraft.world.item.Items.DIORITE_WALL); + public static ItemWrapper BLACKSTONE_WALL = of(net.minecraft.world.item.Items.BLACKSTONE_WALL); + public static ItemWrapper POLISHED_BLACKSTONE_WALL = of(net.minecraft.world.item.Items.POLISHED_BLACKSTONE_WALL); + public static ItemWrapper POLISHED_BLACKSTONE_BRICK_WALL = of(net.minecraft.world.item.Items.POLISHED_BLACKSTONE_BRICK_WALL); + public static ItemWrapper STONE_BUTTON = of(net.minecraft.world.item.Items.STONE_BUTTON); + public static ItemWrapper OAK_BUTTON = of(net.minecraft.world.item.Items.OAK_BUTTON); + public static ItemWrapper SPRUCE_BUTTON = of(net.minecraft.world.item.Items.SPRUCE_BUTTON); + public static ItemWrapper BIRCH_BUTTON = of(net.minecraft.world.item.Items.BIRCH_BUTTON); + public static ItemWrapper JUNGLE_BUTTON = of(net.minecraft.world.item.Items.JUNGLE_BUTTON); + public static ItemWrapper ACACIA_BUTTON = of(net.minecraft.world.item.Items.ACACIA_BUTTON); + public static ItemWrapper DARK_OAK_BUTTON = of(net.minecraft.world.item.Items.DARK_OAK_BUTTON); + public static ItemWrapper CRIMSON_BUTTON = of(net.minecraft.world.item.Items.CRIMSON_BUTTON); + public static ItemWrapper WARPED_BUTTON = of(net.minecraft.world.item.Items.WARPED_BUTTON); + public static ItemWrapper POLISHED_BLACKSTONE_BUTTON = of(net.minecraft.world.item.Items.POLISHED_BLACKSTONE_BUTTON); + public static ItemWrapper ANVIL = of(net.minecraft.world.item.Items.ANVIL); + public static ItemWrapper CHIPPED_ANVIL = of(net.minecraft.world.item.Items.CHIPPED_ANVIL); + public static ItemWrapper DAMAGED_ANVIL = of(net.minecraft.world.item.Items.DAMAGED_ANVIL); + public static ItemWrapper TRAPPED_CHEST = of(net.minecraft.world.item.Items.TRAPPED_CHEST); + public static ItemWrapper LIGHT_WEIGHTED_PRESSURE_PLATE = of(net.minecraft.world.item.Items.LIGHT_WEIGHTED_PRESSURE_PLATE); + public static ItemWrapper HEAVY_WEIGHTED_PRESSURE_PLATE = of(net.minecraft.world.item.Items.HEAVY_WEIGHTED_PRESSURE_PLATE); + public static ItemWrapper DAYLIGHT_DETECTOR = of(net.minecraft.world.item.Items.DAYLIGHT_DETECTOR); + public static ItemWrapper REDSTONE_BLOCK = of(net.minecraft.world.item.Items.REDSTONE_BLOCK); + public static ItemWrapper NETHER_QUARTZ_ORE = of(net.minecraft.world.item.Items.NETHER_QUARTZ_ORE); + public static ItemWrapper HOPPER = of(net.minecraft.world.item.Items.HOPPER); + public static ItemWrapper CHISELED_QUARTZ_BLOCK = of(net.minecraft.world.item.Items.CHISELED_QUARTZ_BLOCK); + public static ItemWrapper QUARTZ_BLOCK = of(net.minecraft.world.item.Items.QUARTZ_BLOCK); + public static ItemWrapper QUARTZ_BRICKS = of(net.minecraft.world.item.Items.QUARTZ_BRICKS); + public static ItemWrapper QUARTZ_PILLAR = of(net.minecraft.world.item.Items.QUARTZ_PILLAR); + public static ItemWrapper QUARTZ_STAIRS = of(net.minecraft.world.item.Items.QUARTZ_STAIRS); + public static ItemWrapper ACTIVATOR_RAIL = of(net.minecraft.world.item.Items.ACTIVATOR_RAIL); + public static ItemWrapper DROPPER = of(net.minecraft.world.item.Items.DROPPER); + public static ItemWrapper WHITE_TERRACOTTA = of(net.minecraft.world.item.Items.WHITE_TERRACOTTA); + public static ItemWrapper ORANGE_TERRACOTTA = of(net.minecraft.world.item.Items.ORANGE_TERRACOTTA); + public static ItemWrapper MAGENTA_TERRACOTTA = of(net.minecraft.world.item.Items.MAGENTA_TERRACOTTA); + public static ItemWrapper LIGHT_BLUE_TERRACOTTA = of(net.minecraft.world.item.Items.LIGHT_BLUE_TERRACOTTA); + public static ItemWrapper YELLOW_TERRACOTTA = of(net.minecraft.world.item.Items.YELLOW_TERRACOTTA); + public static ItemWrapper LIME_TERRACOTTA = of(net.minecraft.world.item.Items.LIME_TERRACOTTA); + public static ItemWrapper PINK_TERRACOTTA = of(net.minecraft.world.item.Items.PINK_TERRACOTTA); + public static ItemWrapper GRAY_TERRACOTTA = of(net.minecraft.world.item.Items.GRAY_TERRACOTTA); + public static ItemWrapper LIGHT_GRAY_TERRACOTTA = of(net.minecraft.world.item.Items.LIGHT_GRAY_TERRACOTTA); + public static ItemWrapper CYAN_TERRACOTTA = of(net.minecraft.world.item.Items.CYAN_TERRACOTTA); + public static ItemWrapper PURPLE_TERRACOTTA = of(net.minecraft.world.item.Items.PURPLE_TERRACOTTA); + public static ItemWrapper BLUE_TERRACOTTA = of(net.minecraft.world.item.Items.BLUE_TERRACOTTA); + public static ItemWrapper BROWN_TERRACOTTA = of(net.minecraft.world.item.Items.BROWN_TERRACOTTA); + public static ItemWrapper GREEN_TERRACOTTA = of(net.minecraft.world.item.Items.GREEN_TERRACOTTA); + public static ItemWrapper RED_TERRACOTTA = of(net.minecraft.world.item.Items.RED_TERRACOTTA); + public static ItemWrapper BLACK_TERRACOTTA = of(net.minecraft.world.item.Items.BLACK_TERRACOTTA); + public static ItemWrapper BARRIER = of(net.minecraft.world.item.Items.BARRIER); + public static ItemWrapper IRON_TRAPDOOR = of(net.minecraft.world.item.Items.IRON_TRAPDOOR); + public static ItemWrapper HAY_BLOCK = of(net.minecraft.world.item.Items.HAY_BLOCK); + public static ItemWrapper WHITE_CARPET = of(net.minecraft.world.item.Items.WHITE_CARPET); + public static ItemWrapper ORANGE_CARPET = of(net.minecraft.world.item.Items.ORANGE_CARPET); + public static ItemWrapper MAGENTA_CARPET = of(net.minecraft.world.item.Items.MAGENTA_CARPET); + public static ItemWrapper LIGHT_BLUE_CARPET = of(net.minecraft.world.item.Items.LIGHT_BLUE_CARPET); + public static ItemWrapper YELLOW_CARPET = of(net.minecraft.world.item.Items.YELLOW_CARPET); + public static ItemWrapper LIME_CARPET = of(net.minecraft.world.item.Items.LIME_CARPET); + public static ItemWrapper PINK_CARPET = of(net.minecraft.world.item.Items.PINK_CARPET); + public static ItemWrapper GRAY_CARPET = of(net.minecraft.world.item.Items.GRAY_CARPET); + public static ItemWrapper LIGHT_GRAY_CARPET = of(net.minecraft.world.item.Items.LIGHT_GRAY_CARPET); + public static ItemWrapper CYAN_CARPET = of(net.minecraft.world.item.Items.CYAN_CARPET); + public static ItemWrapper PURPLE_CARPET = of(net.minecraft.world.item.Items.PURPLE_CARPET); + public static ItemWrapper BLUE_CARPET = of(net.minecraft.world.item.Items.BLUE_CARPET); + public static ItemWrapper BROWN_CARPET = of(net.minecraft.world.item.Items.BROWN_CARPET); + public static ItemWrapper GREEN_CARPET = of(net.minecraft.world.item.Items.GREEN_CARPET); + public static ItemWrapper RED_CARPET = of(net.minecraft.world.item.Items.RED_CARPET); + public static ItemWrapper BLACK_CARPET = of(net.minecraft.world.item.Items.BLACK_CARPET); + public static ItemWrapper TERRACOTTA = of(net.minecraft.world.item.Items.TERRACOTTA); + public static ItemWrapper COAL_BLOCK = of(net.minecraft.world.item.Items.COAL_BLOCK); + public static ItemWrapper PACKED_ICE = of(net.minecraft.world.item.Items.PACKED_ICE); + public static ItemWrapper ACACIA_STAIRS = of(net.minecraft.world.item.Items.ACACIA_STAIRS); + public static ItemWrapper DARK_OAK_STAIRS = of(net.minecraft.world.item.Items.DARK_OAK_STAIRS); + public static ItemWrapper SLIME_BLOCK = of(net.minecraft.world.item.Items.SLIME_BLOCK); + public static ItemWrapper GRASS_PATH = of(net.minecraft.world.item.Items.DIRT_PATH); + public static ItemWrapper SUNFLOWER = of(net.minecraft.world.item.Items.SUNFLOWER); + public static ItemWrapper LILAC = of(net.minecraft.world.item.Items.LILAC); + public static ItemWrapper ROSE_BUSH = of(net.minecraft.world.item.Items.ROSE_BUSH); + public static ItemWrapper PEONY = of(net.minecraft.world.item.Items.PEONY); + public static ItemWrapper TALL_GRASS = of(net.minecraft.world.item.Items.TALL_GRASS); + public static ItemWrapper LARGE_FERN = of(net.minecraft.world.item.Items.LARGE_FERN); + public static ItemWrapper WHITE_STAINED_GLASS = of(net.minecraft.world.item.Items.WHITE_STAINED_GLASS); + public static ItemWrapper ORANGE_STAINED_GLASS = of(net.minecraft.world.item.Items.ORANGE_STAINED_GLASS); + public static ItemWrapper MAGENTA_STAINED_GLASS = of(net.minecraft.world.item.Items.MAGENTA_STAINED_GLASS); + public static ItemWrapper LIGHT_BLUE_STAINED_GLASS = of(net.minecraft.world.item.Items.LIGHT_BLUE_STAINED_GLASS); + public static ItemWrapper YELLOW_STAINED_GLASS = of(net.minecraft.world.item.Items.YELLOW_STAINED_GLASS); + public static ItemWrapper LIME_STAINED_GLASS = of(net.minecraft.world.item.Items.LIME_STAINED_GLASS); + public static ItemWrapper PINK_STAINED_GLASS = of(net.minecraft.world.item.Items.PINK_STAINED_GLASS); + public static ItemWrapper GRAY_STAINED_GLASS = of(net.minecraft.world.item.Items.GRAY_STAINED_GLASS); + public static ItemWrapper LIGHT_GRAY_STAINED_GLASS = of(net.minecraft.world.item.Items.LIGHT_GRAY_STAINED_GLASS); + public static ItemWrapper CYAN_STAINED_GLASS = of(net.minecraft.world.item.Items.CYAN_STAINED_GLASS); + public static ItemWrapper PURPLE_STAINED_GLASS = of(net.minecraft.world.item.Items.PURPLE_STAINED_GLASS); + public static ItemWrapper BLUE_STAINED_GLASS = of(net.minecraft.world.item.Items.BLUE_STAINED_GLASS); + public static ItemWrapper BROWN_STAINED_GLASS = of(net.minecraft.world.item.Items.BROWN_STAINED_GLASS); + public static ItemWrapper GREEN_STAINED_GLASS = of(net.minecraft.world.item.Items.GREEN_STAINED_GLASS); + public static ItemWrapper RED_STAINED_GLASS = of(net.minecraft.world.item.Items.RED_STAINED_GLASS); + public static ItemWrapper BLACK_STAINED_GLASS = of(net.minecraft.world.item.Items.BLACK_STAINED_GLASS); + public static ItemWrapper WHITE_STAINED_GLASS_PANE = of(net.minecraft.world.item.Items.WHITE_STAINED_GLASS_PANE); + public static ItemWrapper ORANGE_STAINED_GLASS_PANE = of(net.minecraft.world.item.Items.ORANGE_STAINED_GLASS_PANE); + public static ItemWrapper MAGENTA_STAINED_GLASS_PANE = of(net.minecraft.world.item.Items.MAGENTA_STAINED_GLASS_PANE); + public static ItemWrapper LIGHT_BLUE_STAINED_GLASS_PANE = of(net.minecraft.world.item.Items.LIGHT_BLUE_STAINED_GLASS_PANE); + public static ItemWrapper YELLOW_STAINED_GLASS_PANE = of(net.minecraft.world.item.Items.YELLOW_STAINED_GLASS_PANE); + public static ItemWrapper LIME_STAINED_GLASS_PANE = of(net.minecraft.world.item.Items.LIME_STAINED_GLASS_PANE); + public static ItemWrapper PINK_STAINED_GLASS_PANE = of(net.minecraft.world.item.Items.PINK_STAINED_GLASS_PANE); + public static ItemWrapper GRAY_STAINED_GLASS_PANE = of(net.minecraft.world.item.Items.GRAY_STAINED_GLASS_PANE); + public static ItemWrapper LIGHT_GRAY_STAINED_GLASS_PANE = of(net.minecraft.world.item.Items.LIGHT_GRAY_STAINED_GLASS_PANE); + public static ItemWrapper CYAN_STAINED_GLASS_PANE = of(net.minecraft.world.item.Items.CYAN_STAINED_GLASS_PANE); + public static ItemWrapper PURPLE_STAINED_GLASS_PANE = of(net.minecraft.world.item.Items.PURPLE_STAINED_GLASS_PANE); + public static ItemWrapper BLUE_STAINED_GLASS_PANE = of(net.minecraft.world.item.Items.BLUE_STAINED_GLASS_PANE); + public static ItemWrapper BROWN_STAINED_GLASS_PANE = of(net.minecraft.world.item.Items.BROWN_STAINED_GLASS_PANE); + public static ItemWrapper GREEN_STAINED_GLASS_PANE = of(net.minecraft.world.item.Items.GREEN_STAINED_GLASS_PANE); + public static ItemWrapper RED_STAINED_GLASS_PANE = of(net.minecraft.world.item.Items.RED_STAINED_GLASS_PANE); + public static ItemWrapper BLACK_STAINED_GLASS_PANE = of(net.minecraft.world.item.Items.BLACK_STAINED_GLASS_PANE); + public static ItemWrapper PRISMARINE = of(net.minecraft.world.item.Items.PRISMARINE); + public static ItemWrapper PRISMARINE_BRICKS = of(net.minecraft.world.item.Items.PRISMARINE_BRICKS); + public static ItemWrapper DARK_PRISMARINE = of(net.minecraft.world.item.Items.DARK_PRISMARINE); + public static ItemWrapper PRISMARINE_STAIRS = of(net.minecraft.world.item.Items.PRISMARINE_STAIRS); + public static ItemWrapper PRISMARINE_BRICK_STAIRS = of(net.minecraft.world.item.Items.PRISMARINE_BRICK_STAIRS); + public static ItemWrapper DARK_PRISMARINE_STAIRS = of(net.minecraft.world.item.Items.DARK_PRISMARINE_STAIRS); + public static ItemWrapper SEA_LANTERN = of(net.minecraft.world.item.Items.SEA_LANTERN); + public static ItemWrapper RED_SANDSTONE = of(net.minecraft.world.item.Items.RED_SANDSTONE); + public static ItemWrapper CHISELED_RED_SANDSTONE = of(net.minecraft.world.item.Items.CHISELED_RED_SANDSTONE); + public static ItemWrapper CUT_RED_SANDSTONE = of(net.minecraft.world.item.Items.CUT_RED_SANDSTONE); + public static ItemWrapper RED_SANDSTONE_STAIRS = of(net.minecraft.world.item.Items.RED_SANDSTONE_STAIRS); + public static ItemWrapper REPEATING_COMMAND_BLOCK = of(net.minecraft.world.item.Items.REPEATING_COMMAND_BLOCK); + public static ItemWrapper CHAIN_COMMAND_BLOCK = of(net.minecraft.world.item.Items.CHAIN_COMMAND_BLOCK); + public static ItemWrapper MAGMA_BLOCK = of(net.minecraft.world.item.Items.MAGMA_BLOCK); + public static ItemWrapper NETHER_WART_BLOCK = of(net.minecraft.world.item.Items.NETHER_WART_BLOCK); + public static ItemWrapper WARPED_WART_BLOCK = of(net.minecraft.world.item.Items.WARPED_WART_BLOCK); + public static ItemWrapper RED_NETHER_BRICKS = of(net.minecraft.world.item.Items.RED_NETHER_BRICKS); + public static ItemWrapper BONE_BLOCK = of(net.minecraft.world.item.Items.BONE_BLOCK); + public static ItemWrapper STRUCTURE_VOID = of(net.minecraft.world.item.Items.STRUCTURE_VOID); + public static ItemWrapper OBSERVER = of(net.minecraft.world.item.Items.OBSERVER); + public static ItemWrapper SHULKER_BOX = of(net.minecraft.world.item.Items.SHULKER_BOX); + public static ItemWrapper WHITE_SHULKER_BOX = of(net.minecraft.world.item.Items.WHITE_SHULKER_BOX); + public static ItemWrapper ORANGE_SHULKER_BOX = of(net.minecraft.world.item.Items.ORANGE_SHULKER_BOX); + public static ItemWrapper MAGENTA_SHULKER_BOX = of(net.minecraft.world.item.Items.MAGENTA_SHULKER_BOX); + public static ItemWrapper LIGHT_BLUE_SHULKER_BOX = of(net.minecraft.world.item.Items.LIGHT_BLUE_SHULKER_BOX); + public static ItemWrapper YELLOW_SHULKER_BOX = of(net.minecraft.world.item.Items.YELLOW_SHULKER_BOX); + public static ItemWrapper LIME_SHULKER_BOX = of(net.minecraft.world.item.Items.LIME_SHULKER_BOX); + public static ItemWrapper PINK_SHULKER_BOX = of(net.minecraft.world.item.Items.PINK_SHULKER_BOX); + public static ItemWrapper GRAY_SHULKER_BOX = of(net.minecraft.world.item.Items.GRAY_SHULKER_BOX); + public static ItemWrapper LIGHT_GRAY_SHULKER_BOX = of(net.minecraft.world.item.Items.LIGHT_GRAY_SHULKER_BOX); + public static ItemWrapper CYAN_SHULKER_BOX = of(net.minecraft.world.item.Items.CYAN_SHULKER_BOX); + public static ItemWrapper PURPLE_SHULKER_BOX = of(net.minecraft.world.item.Items.PURPLE_SHULKER_BOX); + public static ItemWrapper BLUE_SHULKER_BOX = of(net.minecraft.world.item.Items.BLUE_SHULKER_BOX); + public static ItemWrapper BROWN_SHULKER_BOX = of(net.minecraft.world.item.Items.BROWN_SHULKER_BOX); + public static ItemWrapper GREEN_SHULKER_BOX = of(net.minecraft.world.item.Items.GREEN_SHULKER_BOX); + public static ItemWrapper RED_SHULKER_BOX = of(net.minecraft.world.item.Items.RED_SHULKER_BOX); + public static ItemWrapper BLACK_SHULKER_BOX = of(net.minecraft.world.item.Items.BLACK_SHULKER_BOX); + public static ItemWrapper WHITE_GLAZED_TERRACOTTA = of(net.minecraft.world.item.Items.WHITE_GLAZED_TERRACOTTA); + public static ItemWrapper ORANGE_GLAZED_TERRACOTTA = of(net.minecraft.world.item.Items.ORANGE_GLAZED_TERRACOTTA); + public static ItemWrapper MAGENTA_GLAZED_TERRACOTTA = of(net.minecraft.world.item.Items.MAGENTA_GLAZED_TERRACOTTA); + public static ItemWrapper LIGHT_BLUE_GLAZED_TERRACOTTA = of(net.minecraft.world.item.Items.LIGHT_BLUE_GLAZED_TERRACOTTA); + public static ItemWrapper YELLOW_GLAZED_TERRACOTTA = of(net.minecraft.world.item.Items.YELLOW_GLAZED_TERRACOTTA); + public static ItemWrapper LIME_GLAZED_TERRACOTTA = of(net.minecraft.world.item.Items.LIME_GLAZED_TERRACOTTA); + public static ItemWrapper PINK_GLAZED_TERRACOTTA = of(net.minecraft.world.item.Items.PINK_GLAZED_TERRACOTTA); + public static ItemWrapper GRAY_GLAZED_TERRACOTTA = of(net.minecraft.world.item.Items.GRAY_GLAZED_TERRACOTTA); + public static ItemWrapper LIGHT_GRAY_GLAZED_TERRACOTTA = of(net.minecraft.world.item.Items.LIGHT_GRAY_GLAZED_TERRACOTTA); + public static ItemWrapper CYAN_GLAZED_TERRACOTTA = of(net.minecraft.world.item.Items.CYAN_GLAZED_TERRACOTTA); + public static ItemWrapper PURPLE_GLAZED_TERRACOTTA = of(net.minecraft.world.item.Items.PURPLE_GLAZED_TERRACOTTA); + public static ItemWrapper BLUE_GLAZED_TERRACOTTA = of(net.minecraft.world.item.Items.BLUE_GLAZED_TERRACOTTA); + public static ItemWrapper BROWN_GLAZED_TERRACOTTA = of(net.minecraft.world.item.Items.BROWN_GLAZED_TERRACOTTA); + public static ItemWrapper GREEN_GLAZED_TERRACOTTA = of(net.minecraft.world.item.Items.GREEN_GLAZED_TERRACOTTA); + public static ItemWrapper RED_GLAZED_TERRACOTTA = of(net.minecraft.world.item.Items.RED_GLAZED_TERRACOTTA); + public static ItemWrapper BLACK_GLAZED_TERRACOTTA = of(net.minecraft.world.item.Items.BLACK_GLAZED_TERRACOTTA); + public static ItemWrapper WHITE_CONCRETE = of(net.minecraft.world.item.Items.WHITE_CONCRETE); + public static ItemWrapper ORANGE_CONCRETE = of(net.minecraft.world.item.Items.ORANGE_CONCRETE); + public static ItemWrapper MAGENTA_CONCRETE = of(net.minecraft.world.item.Items.MAGENTA_CONCRETE); + public static ItemWrapper LIGHT_BLUE_CONCRETE = of(net.minecraft.world.item.Items.LIGHT_BLUE_CONCRETE); + public static ItemWrapper YELLOW_CONCRETE = of(net.minecraft.world.item.Items.YELLOW_CONCRETE); + public static ItemWrapper LIME_CONCRETE = of(net.minecraft.world.item.Items.LIME_CONCRETE); + public static ItemWrapper PINK_CONCRETE = of(net.minecraft.world.item.Items.PINK_CONCRETE); + public static ItemWrapper GRAY_CONCRETE = of(net.minecraft.world.item.Items.GRAY_CONCRETE); + public static ItemWrapper LIGHT_GRAY_CONCRETE = of(net.minecraft.world.item.Items.LIGHT_GRAY_CONCRETE); + public static ItemWrapper CYAN_CONCRETE = of(net.minecraft.world.item.Items.CYAN_CONCRETE); + public static ItemWrapper PURPLE_CONCRETE = of(net.minecraft.world.item.Items.PURPLE_CONCRETE); + public static ItemWrapper BLUE_CONCRETE = of(net.minecraft.world.item.Items.BLUE_CONCRETE); + public static ItemWrapper BROWN_CONCRETE = of(net.minecraft.world.item.Items.BROWN_CONCRETE); + public static ItemWrapper GREEN_CONCRETE = of(net.minecraft.world.item.Items.GREEN_CONCRETE); + public static ItemWrapper RED_CONCRETE = of(net.minecraft.world.item.Items.RED_CONCRETE); + public static ItemWrapper BLACK_CONCRETE = of(net.minecraft.world.item.Items.BLACK_CONCRETE); + public static ItemWrapper WHITE_CONCRETE_POWDER = of(net.minecraft.world.item.Items.WHITE_CONCRETE_POWDER); + public static ItemWrapper ORANGE_CONCRETE_POWDER = of(net.minecraft.world.item.Items.ORANGE_CONCRETE_POWDER); + public static ItemWrapper MAGENTA_CONCRETE_POWDER = of(net.minecraft.world.item.Items.MAGENTA_CONCRETE_POWDER); + public static ItemWrapper LIGHT_BLUE_CONCRETE_POWDER = of(net.minecraft.world.item.Items.LIGHT_BLUE_CONCRETE_POWDER); + public static ItemWrapper YELLOW_CONCRETE_POWDER = of(net.minecraft.world.item.Items.YELLOW_CONCRETE_POWDER); + public static ItemWrapper LIME_CONCRETE_POWDER = of(net.minecraft.world.item.Items.LIME_CONCRETE_POWDER); + public static ItemWrapper PINK_CONCRETE_POWDER = of(net.minecraft.world.item.Items.PINK_CONCRETE_POWDER); + public static ItemWrapper GRAY_CONCRETE_POWDER = of(net.minecraft.world.item.Items.GRAY_CONCRETE_POWDER); + public static ItemWrapper LIGHT_GRAY_CONCRETE_POWDER = of(net.minecraft.world.item.Items.LIGHT_GRAY_CONCRETE_POWDER); + public static ItemWrapper CYAN_CONCRETE_POWDER = of(net.minecraft.world.item.Items.CYAN_CONCRETE_POWDER); + public static ItemWrapper PURPLE_CONCRETE_POWDER = of(net.minecraft.world.item.Items.PURPLE_CONCRETE_POWDER); + public static ItemWrapper BLUE_CONCRETE_POWDER = of(net.minecraft.world.item.Items.BLUE_CONCRETE_POWDER); + public static ItemWrapper BROWN_CONCRETE_POWDER = of(net.minecraft.world.item.Items.BROWN_CONCRETE_POWDER); + public static ItemWrapper GREEN_CONCRETE_POWDER = of(net.minecraft.world.item.Items.GREEN_CONCRETE_POWDER); + public static ItemWrapper RED_CONCRETE_POWDER = of(net.minecraft.world.item.Items.RED_CONCRETE_POWDER); + public static ItemWrapper BLACK_CONCRETE_POWDER = of(net.minecraft.world.item.Items.BLACK_CONCRETE_POWDER); + public static ItemWrapper TURTLE_EGG = of(net.minecraft.world.item.Items.TURTLE_EGG); + public static ItemWrapper DEAD_TUBE_CORAL_BLOCK = of(net.minecraft.world.item.Items.DEAD_TUBE_CORAL_BLOCK); + public static ItemWrapper DEAD_BRAIN_CORAL_BLOCK = of(net.minecraft.world.item.Items.DEAD_BRAIN_CORAL_BLOCK); + public static ItemWrapper DEAD_BUBBLE_CORAL_BLOCK = of(net.minecraft.world.item.Items.DEAD_BUBBLE_CORAL_BLOCK); + public static ItemWrapper DEAD_FIRE_CORAL_BLOCK = of(net.minecraft.world.item.Items.DEAD_FIRE_CORAL_BLOCK); + public static ItemWrapper DEAD_HORN_CORAL_BLOCK = of(net.minecraft.world.item.Items.DEAD_HORN_CORAL_BLOCK); + public static ItemWrapper TUBE_CORAL_BLOCK = of(net.minecraft.world.item.Items.TUBE_CORAL_BLOCK); + public static ItemWrapper BRAIN_CORAL_BLOCK = of(net.minecraft.world.item.Items.BRAIN_CORAL_BLOCK); + public static ItemWrapper BUBBLE_CORAL_BLOCK = of(net.minecraft.world.item.Items.BUBBLE_CORAL_BLOCK); + public static ItemWrapper FIRE_CORAL_BLOCK = of(net.minecraft.world.item.Items.FIRE_CORAL_BLOCK); + public static ItemWrapper HORN_CORAL_BLOCK = of(net.minecraft.world.item.Items.HORN_CORAL_BLOCK); + public static ItemWrapper TUBE_CORAL = of(net.minecraft.world.item.Items.TUBE_CORAL); + public static ItemWrapper BRAIN_CORAL = of(net.minecraft.world.item.Items.BRAIN_CORAL); + public static ItemWrapper BUBBLE_CORAL = of(net.minecraft.world.item.Items.BUBBLE_CORAL); + public static ItemWrapper FIRE_CORAL = of(net.minecraft.world.item.Items.FIRE_CORAL); + public static ItemWrapper HORN_CORAL = of(net.minecraft.world.item.Items.HORN_CORAL); + public static ItemWrapper DEAD_BRAIN_CORAL = of(net.minecraft.world.item.Items.DEAD_BRAIN_CORAL); + public static ItemWrapper DEAD_BUBBLE_CORAL = of(net.minecraft.world.item.Items.DEAD_BUBBLE_CORAL); + public static ItemWrapper DEAD_FIRE_CORAL = of(net.minecraft.world.item.Items.DEAD_FIRE_CORAL); + public static ItemWrapper DEAD_HORN_CORAL = of(net.minecraft.world.item.Items.DEAD_HORN_CORAL); + public static ItemWrapper DEAD_TUBE_CORAL = of(net.minecraft.world.item.Items.DEAD_TUBE_CORAL); + public static ItemWrapper TUBE_CORAL_FAN = of(net.minecraft.world.item.Items.TUBE_CORAL_FAN); + public static ItemWrapper BRAIN_CORAL_FAN = of(net.minecraft.world.item.Items.BRAIN_CORAL_FAN); + public static ItemWrapper BUBBLE_CORAL_FAN = of(net.minecraft.world.item.Items.BUBBLE_CORAL_FAN); + public static ItemWrapper FIRE_CORAL_FAN = of(net.minecraft.world.item.Items.FIRE_CORAL_FAN); + public static ItemWrapper HORN_CORAL_FAN = of(net.minecraft.world.item.Items.HORN_CORAL_FAN); + public static ItemWrapper DEAD_TUBE_CORAL_FAN = of(net.minecraft.world.item.Items.DEAD_TUBE_CORAL_FAN); + public static ItemWrapper DEAD_BRAIN_CORAL_FAN = of(net.minecraft.world.item.Items.DEAD_BRAIN_CORAL_FAN); + public static ItemWrapper DEAD_BUBBLE_CORAL_FAN = of(net.minecraft.world.item.Items.DEAD_BUBBLE_CORAL_FAN); + public static ItemWrapper DEAD_FIRE_CORAL_FAN = of(net.minecraft.world.item.Items.DEAD_FIRE_CORAL_FAN); + public static ItemWrapper DEAD_HORN_CORAL_FAN = of(net.minecraft.world.item.Items.DEAD_HORN_CORAL_FAN); + public static ItemWrapper BLUE_ICE = of(net.minecraft.world.item.Items.BLUE_ICE); + public static ItemWrapper CONDUIT = of(net.minecraft.world.item.Items.CONDUIT); + public static ItemWrapper POLISHED_GRANITE_STAIRS = of(net.minecraft.world.item.Items.POLISHED_GRANITE_STAIRS); + public static ItemWrapper SMOOTH_RED_SANDSTONE_STAIRS = of(net.minecraft.world.item.Items.SMOOTH_RED_SANDSTONE_STAIRS); + public static ItemWrapper MOSSY_STONE_BRICK_STAIRS = of(net.minecraft.world.item.Items.MOSSY_STONE_BRICK_STAIRS); + public static ItemWrapper POLISHED_DIORITE_STAIRS = of(net.minecraft.world.item.Items.POLISHED_DIORITE_STAIRS); + public static ItemWrapper MOSSY_COBBLESTONE_STAIRS = of(net.minecraft.world.item.Items.MOSSY_COBBLESTONE_STAIRS); + public static ItemWrapper END_STONE_BRICK_STAIRS = of(net.minecraft.world.item.Items.END_STONE_BRICK_STAIRS); + public static ItemWrapper STONE_STAIRS = of(net.minecraft.world.item.Items.STONE_STAIRS); + public static ItemWrapper SMOOTH_SANDSTONE_STAIRS = of(net.minecraft.world.item.Items.SMOOTH_SANDSTONE_STAIRS); + public static ItemWrapper SMOOTH_QUARTZ_STAIRS = of(net.minecraft.world.item.Items.SMOOTH_QUARTZ_STAIRS); + public static ItemWrapper GRANITE_STAIRS = of(net.minecraft.world.item.Items.GRANITE_STAIRS); + public static ItemWrapper ANDESITE_STAIRS = of(net.minecraft.world.item.Items.ANDESITE_STAIRS); + public static ItemWrapper RED_NETHER_BRICK_STAIRS = of(net.minecraft.world.item.Items.RED_NETHER_BRICK_STAIRS); + public static ItemWrapper POLISHED_ANDESITE_STAIRS = of(net.minecraft.world.item.Items.POLISHED_ANDESITE_STAIRS); + public static ItemWrapper DIORITE_STAIRS = of(net.minecraft.world.item.Items.DIORITE_STAIRS); + public static ItemWrapper POLISHED_GRANITE_SLAB = of(net.minecraft.world.item.Items.POLISHED_GRANITE_SLAB); + public static ItemWrapper SMOOTH_RED_SANDSTONE_SLAB = of(net.minecraft.world.item.Items.SMOOTH_RED_SANDSTONE_SLAB); + public static ItemWrapper MOSSY_STONE_BRICK_SLAB = of(net.minecraft.world.item.Items.MOSSY_STONE_BRICK_SLAB); + public static ItemWrapper POLISHED_DIORITE_SLAB = of(net.minecraft.world.item.Items.POLISHED_DIORITE_SLAB); + public static ItemWrapper MOSSY_COBBLESTONE_SLAB = of(net.minecraft.world.item.Items.MOSSY_COBBLESTONE_SLAB); + public static ItemWrapper END_STONE_BRICK_SLAB = of(net.minecraft.world.item.Items.END_STONE_BRICK_SLAB); + public static ItemWrapper SMOOTH_SANDSTONE_SLAB = of(net.minecraft.world.item.Items.SMOOTH_SANDSTONE_SLAB); + public static ItemWrapper SMOOTH_QUARTZ_SLAB = of(net.minecraft.world.item.Items.SMOOTH_QUARTZ_SLAB); + public static ItemWrapper GRANITE_SLAB = of(net.minecraft.world.item.Items.GRANITE_SLAB); + public static ItemWrapper ANDESITE_SLAB = of(net.minecraft.world.item.Items.ANDESITE_SLAB); + public static ItemWrapper RED_NETHER_BRICK_SLAB = of(net.minecraft.world.item.Items.RED_NETHER_BRICK_SLAB); + public static ItemWrapper POLISHED_ANDESITE_SLAB = of(net.minecraft.world.item.Items.POLISHED_ANDESITE_SLAB); + public static ItemWrapper DIORITE_SLAB = of(net.minecraft.world.item.Items.DIORITE_SLAB); + public static ItemWrapper SCAFFOLDING = of(net.minecraft.world.item.Items.SCAFFOLDING); + public static ItemWrapper IRON_DOOR = of(net.minecraft.world.item.Items.IRON_DOOR); + public static ItemWrapper OAK_DOOR = of(net.minecraft.world.item.Items.OAK_DOOR); + public static ItemWrapper SPRUCE_DOOR = of(net.minecraft.world.item.Items.SPRUCE_DOOR); + public static ItemWrapper BIRCH_DOOR = of(net.minecraft.world.item.Items.BIRCH_DOOR); + public static ItemWrapper JUNGLE_DOOR = of(net.minecraft.world.item.Items.JUNGLE_DOOR); + public static ItemWrapper ACACIA_DOOR = of(net.minecraft.world.item.Items.ACACIA_DOOR); + public static ItemWrapper DARK_OAK_DOOR = of(net.minecraft.world.item.Items.DARK_OAK_DOOR); + public static ItemWrapper CRIMSON_DOOR = of(net.minecraft.world.item.Items.CRIMSON_DOOR); + public static ItemWrapper WARPED_DOOR = of(net.minecraft.world.item.Items.WARPED_DOOR); + public static ItemWrapper REPEATER = of(net.minecraft.world.item.Items.REPEATER); + public static ItemWrapper COMPARATOR = of(net.minecraft.world.item.Items.COMPARATOR); + public static ItemWrapper STRUCTURE_BLOCK = of(net.minecraft.world.item.Items.STRUCTURE_BLOCK); + public static ItemWrapper JIGSAW = of(net.minecraft.world.item.Items.JIGSAW); + public static ItemWrapper TURTLE_HELMET = of(net.minecraft.world.item.Items.TURTLE_HELMET); + public static ItemWrapper SCUTE = of(net.minecraft.world.item.Items.TURTLE_SCUTE); + public static ItemWrapper FLINT_AND_STEEL = of(net.minecraft.world.item.Items.FLINT_AND_STEEL); + public static ItemWrapper APPLE = of(net.minecraft.world.item.Items.APPLE); + public static ItemWrapper BOW = of(net.minecraft.world.item.Items.BOW); + public static ItemWrapper ARROW = of(net.minecraft.world.item.Items.ARROW); + public static ItemWrapper COAL = of(net.minecraft.world.item.Items.COAL); + public static ItemWrapper CHARCOAL = of(net.minecraft.world.item.Items.CHARCOAL); + public static ItemWrapper DIAMOND = of(net.minecraft.world.item.Items.DIAMOND); + public static ItemWrapper IRON_INGOT = of(net.minecraft.world.item.Items.IRON_INGOT); + public static ItemWrapper GOLD_INGOT = of(net.minecraft.world.item.Items.GOLD_INGOT); + public static ItemWrapper NETHERITE_INGOT = of(net.minecraft.world.item.Items.NETHERITE_INGOT); + public static ItemWrapper NETHERITE_SCRAP = of(net.minecraft.world.item.Items.NETHERITE_SCRAP); + public static ItemWrapper WOODEN_SWORD = of(net.minecraft.world.item.Items.WOODEN_SWORD); + public static ItemWrapper WOODEN_SHOVEL = of(net.minecraft.world.item.Items.WOODEN_SHOVEL); + public static ItemWrapper WOODEN_PICKAXE = of(net.minecraft.world.item.Items.WOODEN_PICKAXE); + public static ItemWrapper WOODEN_AXE = of(net.minecraft.world.item.Items.WOODEN_AXE); + public static ItemWrapper WOODEN_HOE = of(net.minecraft.world.item.Items.WOODEN_HOE); + public static ItemWrapper STONE_SWORD = of(net.minecraft.world.item.Items.STONE_SWORD); + public static ItemWrapper STONE_SHOVEL = of(net.minecraft.world.item.Items.STONE_SHOVEL); + public static ItemWrapper STONE_PICKAXE = of(net.minecraft.world.item.Items.STONE_PICKAXE); + public static ItemWrapper STONE_AXE = of(net.minecraft.world.item.Items.STONE_AXE); + public static ItemWrapper STONE_HOE = of(net.minecraft.world.item.Items.STONE_HOE); + public static ItemWrapper GOLDEN_SWORD = of(net.minecraft.world.item.Items.GOLDEN_SWORD); + public static ItemWrapper GOLDEN_SHOVEL = of(net.minecraft.world.item.Items.GOLDEN_SHOVEL); + public static ItemWrapper GOLDEN_PICKAXE = of(net.minecraft.world.item.Items.GOLDEN_PICKAXE); + public static ItemWrapper GOLDEN_AXE = of(net.minecraft.world.item.Items.GOLDEN_AXE); + public static ItemWrapper GOLDEN_HOE = of(net.minecraft.world.item.Items.GOLDEN_HOE); + public static ItemWrapper IRON_SWORD = of(net.minecraft.world.item.Items.IRON_SWORD); + public static ItemWrapper IRON_SHOVEL = of(net.minecraft.world.item.Items.IRON_SHOVEL); + public static ItemWrapper IRON_PICKAXE = of(net.minecraft.world.item.Items.IRON_PICKAXE); + public static ItemWrapper IRON_AXE = of(net.minecraft.world.item.Items.IRON_AXE); + public static ItemWrapper IRON_HOE = of(net.minecraft.world.item.Items.IRON_HOE); + public static ItemWrapper DIAMOND_SWORD = of(net.minecraft.world.item.Items.DIAMOND_SWORD); + public static ItemWrapper DIAMOND_SHOVEL = of(net.minecraft.world.item.Items.DIAMOND_SHOVEL); + public static ItemWrapper DIAMOND_PICKAXE = of(net.minecraft.world.item.Items.DIAMOND_PICKAXE); + public static ItemWrapper DIAMOND_AXE = of(net.minecraft.world.item.Items.DIAMOND_AXE); + public static ItemWrapper DIAMOND_HOE = of(net.minecraft.world.item.Items.DIAMOND_HOE); + public static ItemWrapper NETHERITE_SWORD = of(net.minecraft.world.item.Items.NETHERITE_SWORD); + public static ItemWrapper NETHERITE_SHOVEL = of(net.minecraft.world.item.Items.NETHERITE_SHOVEL); + public static ItemWrapper NETHERITE_PICKAXE = of(net.minecraft.world.item.Items.NETHERITE_PICKAXE); + public static ItemWrapper NETHERITE_AXE = of(net.minecraft.world.item.Items.NETHERITE_AXE); + public static ItemWrapper NETHERITE_HOE = of(net.minecraft.world.item.Items.NETHERITE_HOE); + public static ItemWrapper STICK = of(net.minecraft.world.item.Items.STICK); + public static ItemWrapper BOWL = of(net.minecraft.world.item.Items.BOWL); + public static ItemWrapper MUSHROOM_STEW = of(net.minecraft.world.item.Items.MUSHROOM_STEW); + public static ItemWrapper STRING = of(net.minecraft.world.item.Items.STRING); + public static ItemWrapper FEATHER = of(net.minecraft.world.item.Items.FEATHER); + public static ItemWrapper GUNPOWDER = of(net.minecraft.world.item.Items.GUNPOWDER); + public static ItemWrapper WHEAT_SEEDS = of(net.minecraft.world.item.Items.WHEAT_SEEDS); + public static ItemWrapper WHEAT = of(net.minecraft.world.item.Items.WHEAT); + public static ItemWrapper BREAD = of(net.minecraft.world.item.Items.BREAD); + public static ItemWrapper LEATHER_HELMET = of(net.minecraft.world.item.Items.LEATHER_HELMET); + public static ItemWrapper LEATHER_CHESTPLATE = of(net.minecraft.world.item.Items.LEATHER_CHESTPLATE); + public static ItemWrapper LEATHER_LEGGINGS = of(net.minecraft.world.item.Items.LEATHER_LEGGINGS); + public static ItemWrapper LEATHER_BOOTS = of(net.minecraft.world.item.Items.LEATHER_BOOTS); + public static ItemWrapper CHAINMAIL_HELMET = of(net.minecraft.world.item.Items.CHAINMAIL_HELMET); + public static ItemWrapper CHAINMAIL_CHESTPLATE = of(net.minecraft.world.item.Items.CHAINMAIL_CHESTPLATE); + public static ItemWrapper CHAINMAIL_LEGGINGS = of(net.minecraft.world.item.Items.CHAINMAIL_LEGGINGS); + public static ItemWrapper CHAINMAIL_BOOTS = of(net.minecraft.world.item.Items.CHAINMAIL_BOOTS); + public static ItemWrapper IRON_HELMET = of(net.minecraft.world.item.Items.IRON_HELMET); + public static ItemWrapper IRON_CHESTPLATE = of(net.minecraft.world.item.Items.IRON_CHESTPLATE); + public static ItemWrapper IRON_LEGGINGS = of(net.minecraft.world.item.Items.IRON_LEGGINGS); + public static ItemWrapper IRON_BOOTS = of(net.minecraft.world.item.Items.IRON_BOOTS); + public static ItemWrapper DIAMOND_HELMET = of(net.minecraft.world.item.Items.DIAMOND_HELMET); + public static ItemWrapper DIAMOND_CHESTPLATE = of(net.minecraft.world.item.Items.DIAMOND_CHESTPLATE); + public static ItemWrapper DIAMOND_LEGGINGS = of(net.minecraft.world.item.Items.DIAMOND_LEGGINGS); + public static ItemWrapper DIAMOND_BOOTS = of(net.minecraft.world.item.Items.DIAMOND_BOOTS); + public static ItemWrapper GOLDEN_HELMET = of(net.minecraft.world.item.Items.GOLDEN_HELMET); + public static ItemWrapper GOLDEN_CHESTPLATE = of(net.minecraft.world.item.Items.GOLDEN_CHESTPLATE); + public static ItemWrapper GOLDEN_LEGGINGS = of(net.minecraft.world.item.Items.GOLDEN_LEGGINGS); + public static ItemWrapper GOLDEN_BOOTS = of(net.minecraft.world.item.Items.GOLDEN_BOOTS); + public static ItemWrapper NETHERITE_HELMET = of(net.minecraft.world.item.Items.NETHERITE_HELMET); + public static ItemWrapper NETHERITE_CHESTPLATE = of(net.minecraft.world.item.Items.NETHERITE_CHESTPLATE); + public static ItemWrapper NETHERITE_LEGGINGS = of(net.minecraft.world.item.Items.NETHERITE_LEGGINGS); + public static ItemWrapper NETHERITE_BOOTS = of(net.minecraft.world.item.Items.NETHERITE_BOOTS); + public static ItemWrapper FLINT = of(net.minecraft.world.item.Items.FLINT); + public static ItemWrapper PORKCHOP = of(net.minecraft.world.item.Items.PORKCHOP); + public static ItemWrapper COOKED_PORKCHOP = of(net.minecraft.world.item.Items.COOKED_PORKCHOP); + public static ItemWrapper PAINTING = of(net.minecraft.world.item.Items.PAINTING); + public static ItemWrapper GOLDEN_APPLE = of(net.minecraft.world.item.Items.GOLDEN_APPLE); + public static ItemWrapper ENCHANTED_GOLDEN_APPLE = of(net.minecraft.world.item.Items.ENCHANTED_GOLDEN_APPLE); + public static ItemWrapper OAK_SIGN = of(net.minecraft.world.item.Items.OAK_SIGN); + public static ItemWrapper SPRUCE_SIGN = of(net.minecraft.world.item.Items.SPRUCE_SIGN); + public static ItemWrapper BIRCH_SIGN = of(net.minecraft.world.item.Items.BIRCH_SIGN); + public static ItemWrapper JUNGLE_SIGN = of(net.minecraft.world.item.Items.JUNGLE_SIGN); + public static ItemWrapper ACACIA_SIGN = of(net.minecraft.world.item.Items.ACACIA_SIGN); + public static ItemWrapper DARK_OAK_SIGN = of(net.minecraft.world.item.Items.DARK_OAK_SIGN); + public static ItemWrapper CRIMSON_SIGN = of(net.minecraft.world.item.Items.CRIMSON_SIGN); + public static ItemWrapper WARPED_SIGN = of(net.minecraft.world.item.Items.WARPED_SIGN); + public static ItemWrapper BUCKET = of(net.minecraft.world.item.Items.BUCKET); + public static ItemWrapper WATER_BUCKET = of(net.minecraft.world.item.Items.WATER_BUCKET); + public static ItemWrapper LAVA_BUCKET = of(net.minecraft.world.item.Items.LAVA_BUCKET); + public static ItemWrapper MINECART = of(net.minecraft.world.item.Items.MINECART); + public static ItemWrapper SADDLE = of(net.minecraft.world.item.Items.SADDLE); + public static ItemWrapper REDSTONE = of(net.minecraft.world.item.Items.REDSTONE); + public static ItemWrapper SNOWBALL = of(net.minecraft.world.item.Items.SNOWBALL); + public static ItemWrapper OAK_BOAT = of(net.minecraft.world.item.Items.OAK_BOAT); + public static ItemWrapper LEATHER = of(net.minecraft.world.item.Items.LEATHER); + public static ItemWrapper MILK_BUCKET = of(net.minecraft.world.item.Items.MILK_BUCKET); + public static ItemWrapper PUFFERFISH_BUCKET = of(net.minecraft.world.item.Items.PUFFERFISH_BUCKET); + public static ItemWrapper SALMON_BUCKET = of(net.minecraft.world.item.Items.SALMON_BUCKET); + public static ItemWrapper COD_BUCKET = of(net.minecraft.world.item.Items.COD_BUCKET); + public static ItemWrapper TROPICAL_FISH_BUCKET = of(net.minecraft.world.item.Items.TROPICAL_FISH_BUCKET); + public static ItemWrapper BRICK = of(net.minecraft.world.item.Items.BRICK); + public static ItemWrapper CLAY_BALL = of(net.minecraft.world.item.Items.CLAY_BALL); + public static ItemWrapper DRIED_KELP_BLOCK = of(net.minecraft.world.item.Items.DRIED_KELP_BLOCK); + public static ItemWrapper PAPER = of(net.minecraft.world.item.Items.PAPER); + public static ItemWrapper BOOK = of(net.minecraft.world.item.Items.BOOK); + public static ItemWrapper SLIME_BALL = of(net.minecraft.world.item.Items.SLIME_BALL); + public static ItemWrapper CHEST_MINECART = of(net.minecraft.world.item.Items.CHEST_MINECART); + public static ItemWrapper FURNACE_MINECART = of(net.minecraft.world.item.Items.FURNACE_MINECART); + public static ItemWrapper EGG = of(net.minecraft.world.item.Items.EGG); + public static ItemWrapper COMPASS = of(net.minecraft.world.item.Items.COMPASS); + public static ItemWrapper FISHING_ROD = of(net.minecraft.world.item.Items.FISHING_ROD); + public static ItemWrapper CLOCK = of(net.minecraft.world.item.Items.CLOCK); + public static ItemWrapper GLOWSTONE_DUST = of(net.minecraft.world.item.Items.GLOWSTONE_DUST); + public static ItemWrapper COD = of(net.minecraft.world.item.Items.COD); + public static ItemWrapper SALMON = of(net.minecraft.world.item.Items.SALMON); + public static ItemWrapper TROPICAL_FISH = of(net.minecraft.world.item.Items.TROPICAL_FISH); + public static ItemWrapper PUFFERFISH = of(net.minecraft.world.item.Items.PUFFERFISH); + public static ItemWrapper COOKED_COD = of(net.minecraft.world.item.Items.COOKED_COD); + public static ItemWrapper COOKED_SALMON = of(net.minecraft.world.item.Items.COOKED_SALMON); + public static ItemWrapper INK_SAC = of(net.minecraft.world.item.Items.INK_SAC); + public static ItemWrapper COCOA_BEANS = of(net.minecraft.world.item.Items.COCOA_BEANS); + public static ItemWrapper LAPIS_LAZULI = of(net.minecraft.world.item.Items.LAPIS_LAZULI); + public static ItemWrapper WHITE_DYE = of(net.minecraft.world.item.Items.WHITE_DYE); + public static ItemWrapper ORANGE_DYE = of(net.minecraft.world.item.Items.ORANGE_DYE); + public static ItemWrapper MAGENTA_DYE = of(net.minecraft.world.item.Items.MAGENTA_DYE); + public static ItemWrapper LIGHT_BLUE_DYE = of(net.minecraft.world.item.Items.LIGHT_BLUE_DYE); + public static ItemWrapper YELLOW_DYE = of(net.minecraft.world.item.Items.YELLOW_DYE); + public static ItemWrapper LIME_DYE = of(net.minecraft.world.item.Items.LIME_DYE); + public static ItemWrapper PINK_DYE = of(net.minecraft.world.item.Items.PINK_DYE); + public static ItemWrapper GRAY_DYE = of(net.minecraft.world.item.Items.GRAY_DYE); + public static ItemWrapper LIGHT_GRAY_DYE = of(net.minecraft.world.item.Items.LIGHT_GRAY_DYE); + public static ItemWrapper CYAN_DYE = of(net.minecraft.world.item.Items.CYAN_DYE); + public static ItemWrapper PURPLE_DYE = of(net.minecraft.world.item.Items.PURPLE_DYE); + public static ItemWrapper BLUE_DYE = of(net.minecraft.world.item.Items.BLUE_DYE); + public static ItemWrapper BROWN_DYE = of(net.minecraft.world.item.Items.BROWN_DYE); + public static ItemWrapper GREEN_DYE = of(net.minecraft.world.item.Items.GREEN_DYE); + public static ItemWrapper RED_DYE = of(net.minecraft.world.item.Items.RED_DYE); + public static ItemWrapper BLACK_DYE = of(net.minecraft.world.item.Items.BLACK_DYE); + public static ItemWrapper BONE_MEAL = of(net.minecraft.world.item.Items.BONE_MEAL); + public static ItemWrapper BONE = of(net.minecraft.world.item.Items.BONE); + public static ItemWrapper SUGAR = of(net.minecraft.world.item.Items.SUGAR); + public static ItemWrapper CAKE = of(net.minecraft.world.item.Items.CAKE); + public static ItemWrapper WHITE_BED = of(net.minecraft.world.item.Items.WHITE_BED); + public static ItemWrapper ORANGE_BED = of(net.minecraft.world.item.Items.ORANGE_BED); + public static ItemWrapper MAGENTA_BED = of(net.minecraft.world.item.Items.MAGENTA_BED); + public static ItemWrapper LIGHT_BLUE_BED = of(net.minecraft.world.item.Items.LIGHT_BLUE_BED); + public static ItemWrapper YELLOW_BED = of(net.minecraft.world.item.Items.YELLOW_BED); + public static ItemWrapper LIME_BED = of(net.minecraft.world.item.Items.LIME_BED); + public static ItemWrapper PINK_BED = of(net.minecraft.world.item.Items.PINK_BED); + public static ItemWrapper GRAY_BED = of(net.minecraft.world.item.Items.GRAY_BED); + public static ItemWrapper LIGHT_GRAY_BED = of(net.minecraft.world.item.Items.LIGHT_GRAY_BED); + public static ItemWrapper CYAN_BED = of(net.minecraft.world.item.Items.CYAN_BED); + public static ItemWrapper PURPLE_BED = of(net.minecraft.world.item.Items.PURPLE_BED); + public static ItemWrapper BLUE_BED = of(net.minecraft.world.item.Items.BLUE_BED); + public static ItemWrapper BROWN_BED = of(net.minecraft.world.item.Items.BROWN_BED); + public static ItemWrapper GREEN_BED = of(net.minecraft.world.item.Items.GREEN_BED); + public static ItemWrapper RED_BED = of(net.minecraft.world.item.Items.RED_BED); + public static ItemWrapper BLACK_BED = of(net.minecraft.world.item.Items.BLACK_BED); + public static ItemWrapper COOKIE = of(net.minecraft.world.item.Items.COOKIE); + public static ItemWrapper FILLED_MAP = of(net.minecraft.world.item.Items.FILLED_MAP); + public static ItemWrapper SHEARS = of(net.minecraft.world.item.Items.SHEARS); + public static ItemWrapper MELON_SLICE = of(net.minecraft.world.item.Items.MELON_SLICE); + public static ItemWrapper DRIED_KELP = of(net.minecraft.world.item.Items.DRIED_KELP); + public static ItemWrapper PUMPKIN_SEEDS = of(net.minecraft.world.item.Items.PUMPKIN_SEEDS); + public static ItemWrapper MELON_SEEDS = of(net.minecraft.world.item.Items.MELON_SEEDS); + public static ItemWrapper BEEF = of(net.minecraft.world.item.Items.BEEF); + public static ItemWrapper COOKED_BEEF = of(net.minecraft.world.item.Items.COOKED_BEEF); + public static ItemWrapper CHICKEN = of(net.minecraft.world.item.Items.CHICKEN); + public static ItemWrapper COOKED_CHICKEN = of(net.minecraft.world.item.Items.COOKED_CHICKEN); + public static ItemWrapper ROTTEN_FLESH = of(net.minecraft.world.item.Items.ROTTEN_FLESH); + public static ItemWrapper ENDER_PEARL = of(net.minecraft.world.item.Items.ENDER_PEARL); + public static ItemWrapper BLAZE_ROD = of(net.minecraft.world.item.Items.BLAZE_ROD); + public static ItemWrapper GHAST_TEAR = of(net.minecraft.world.item.Items.GHAST_TEAR); + public static ItemWrapper GOLD_NUGGET = of(net.minecraft.world.item.Items.GOLD_NUGGET); + public static ItemWrapper NETHER_WART = of(net.minecraft.world.item.Items.NETHER_WART); + public static ItemWrapper POTION = of(net.minecraft.world.item.Items.POTION); + public static ItemWrapper GLASS_BOTTLE = of(net.minecraft.world.item.Items.GLASS_BOTTLE); + public static ItemWrapper SPIDER_EYE = of(net.minecraft.world.item.Items.SPIDER_EYE); + public static ItemWrapper FERMENTED_SPIDER_EYE = of(net.minecraft.world.item.Items.FERMENTED_SPIDER_EYE); + public static ItemWrapper BLAZE_POWDER = of(net.minecraft.world.item.Items.BLAZE_POWDER); + public static ItemWrapper MAGMA_CREAM = of(net.minecraft.world.item.Items.MAGMA_CREAM); + public static ItemWrapper BREWING_STAND = of(net.minecraft.world.item.Items.BREWING_STAND); + public static ItemWrapper CAULDRON = of(net.minecraft.world.item.Items.CAULDRON); + public static ItemWrapper ENDER_EYE = of(net.minecraft.world.item.Items.ENDER_EYE); + public static ItemWrapper GLISTERING_MELON_SLICE = of(net.minecraft.world.item.Items.GLISTERING_MELON_SLICE); + public static ItemWrapper BAT_SPAWN_EGG = of(net.minecraft.world.item.Items.BAT_SPAWN_EGG); + public static ItemWrapper BEE_SPAWN_EGG = of(net.minecraft.world.item.Items.BEE_SPAWN_EGG); + public static ItemWrapper BLAZE_SPAWN_EGG = of(net.minecraft.world.item.Items.BLAZE_SPAWN_EGG); + public static ItemWrapper CAT_SPAWN_EGG = of(net.minecraft.world.item.Items.CAT_SPAWN_EGG); + public static ItemWrapper CAVE_SPIDER_SPAWN_EGG = of(net.minecraft.world.item.Items.CAVE_SPIDER_SPAWN_EGG); + public static ItemWrapper CHICKEN_SPAWN_EGG = of(net.minecraft.world.item.Items.CHICKEN_SPAWN_EGG); + public static ItemWrapper COD_SPAWN_EGG = of(net.minecraft.world.item.Items.COD_SPAWN_EGG); + public static ItemWrapper COW_SPAWN_EGG = of(net.minecraft.world.item.Items.COW_SPAWN_EGG); + public static ItemWrapper CREEPER_SPAWN_EGG = of(net.minecraft.world.item.Items.CREEPER_SPAWN_EGG); + public static ItemWrapper DOLPHIN_SPAWN_EGG = of(net.minecraft.world.item.Items.DOLPHIN_SPAWN_EGG); + public static ItemWrapper DONKEY_SPAWN_EGG = of(net.minecraft.world.item.Items.DONKEY_SPAWN_EGG); + public static ItemWrapper DROWNED_SPAWN_EGG = of(net.minecraft.world.item.Items.DROWNED_SPAWN_EGG); + public static ItemWrapper ELDER_GUARDIAN_SPAWN_EGG = of(net.minecraft.world.item.Items.ELDER_GUARDIAN_SPAWN_EGG); + public static ItemWrapper ENDERMAN_SPAWN_EGG = of(net.minecraft.world.item.Items.ENDERMAN_SPAWN_EGG); + public static ItemWrapper ENDERMITE_SPAWN_EGG = of(net.minecraft.world.item.Items.ENDERMITE_SPAWN_EGG); + public static ItemWrapper EVOKER_SPAWN_EGG = of(net.minecraft.world.item.Items.EVOKER_SPAWN_EGG); + public static ItemWrapper FOX_SPAWN_EGG = of(net.minecraft.world.item.Items.FOX_SPAWN_EGG); + public static ItemWrapper GHAST_SPAWN_EGG = of(net.minecraft.world.item.Items.GHAST_SPAWN_EGG); + public static ItemWrapper GUARDIAN_SPAWN_EGG = of(net.minecraft.world.item.Items.GUARDIAN_SPAWN_EGG); + public static ItemWrapper HOGLIN_SPAWN_EGG = of(net.minecraft.world.item.Items.HOGLIN_SPAWN_EGG); + public static ItemWrapper HORSE_SPAWN_EGG = of(net.minecraft.world.item.Items.HORSE_SPAWN_EGG); + public static ItemWrapper HUSK_SPAWN_EGG = of(net.minecraft.world.item.Items.HUSK_SPAWN_EGG); + public static ItemWrapper LLAMA_SPAWN_EGG = of(net.minecraft.world.item.Items.LLAMA_SPAWN_EGG); + public static ItemWrapper MAGMA_CUBE_SPAWN_EGG = of(net.minecraft.world.item.Items.MAGMA_CUBE_SPAWN_EGG); + public static ItemWrapper MOOSHROOM_SPAWN_EGG = of(net.minecraft.world.item.Items.MOOSHROOM_SPAWN_EGG); + public static ItemWrapper MULE_SPAWN_EGG = of(net.minecraft.world.item.Items.MULE_SPAWN_EGG); + public static ItemWrapper OCELOT_SPAWN_EGG = of(net.minecraft.world.item.Items.OCELOT_SPAWN_EGG); + public static ItemWrapper PANDA_SPAWN_EGG = of(net.minecraft.world.item.Items.PANDA_SPAWN_EGG); + public static ItemWrapper PARROT_SPAWN_EGG = of(net.minecraft.world.item.Items.PARROT_SPAWN_EGG); + public static ItemWrapper PHANTOM_SPAWN_EGG = of(net.minecraft.world.item.Items.PHANTOM_SPAWN_EGG); + public static ItemWrapper PIG_SPAWN_EGG = of(net.minecraft.world.item.Items.PIG_SPAWN_EGG); + public static ItemWrapper PIGLIN_SPAWN_EGG = of(net.minecraft.world.item.Items.PIGLIN_SPAWN_EGG); + public static ItemWrapper PIGLIN_BRUTE_SPAWN_EGG = of(net.minecraft.world.item.Items.PIGLIN_BRUTE_SPAWN_EGG); + public static ItemWrapper PILLAGER_SPAWN_EGG = of(net.minecraft.world.item.Items.PILLAGER_SPAWN_EGG); + public static ItemWrapper POLAR_BEAR_SPAWN_EGG = of(net.minecraft.world.item.Items.POLAR_BEAR_SPAWN_EGG); + public static ItemWrapper PUFFERFISH_SPAWN_EGG = of(net.minecraft.world.item.Items.PUFFERFISH_SPAWN_EGG); + public static ItemWrapper RABBIT_SPAWN_EGG = of(net.minecraft.world.item.Items.RABBIT_SPAWN_EGG); + public static ItemWrapper RAVAGER_SPAWN_EGG = of(net.minecraft.world.item.Items.RAVAGER_SPAWN_EGG); + public static ItemWrapper SALMON_SPAWN_EGG = of(net.minecraft.world.item.Items.SALMON_SPAWN_EGG); + public static ItemWrapper SHEEP_SPAWN_EGG = of(net.minecraft.world.item.Items.SHEEP_SPAWN_EGG); + public static ItemWrapper SHULKER_SPAWN_EGG = of(net.minecraft.world.item.Items.SHULKER_SPAWN_EGG); + public static ItemWrapper SILVERFISH_SPAWN_EGG = of(net.minecraft.world.item.Items.SILVERFISH_SPAWN_EGG); + public static ItemWrapper SKELETON_SPAWN_EGG = of(net.minecraft.world.item.Items.SKELETON_SPAWN_EGG); + public static ItemWrapper SKELETON_HORSE_SPAWN_EGG = of(net.minecraft.world.item.Items.SKELETON_HORSE_SPAWN_EGG); + public static ItemWrapper SLIME_SPAWN_EGG = of(net.minecraft.world.item.Items.SLIME_SPAWN_EGG); + public static ItemWrapper SPIDER_SPAWN_EGG = of(net.minecraft.world.item.Items.SPIDER_SPAWN_EGG); + public static ItemWrapper SQUID_SPAWN_EGG = of(net.minecraft.world.item.Items.SQUID_SPAWN_EGG); + public static ItemWrapper STRAY_SPAWN_EGG = of(net.minecraft.world.item.Items.STRAY_SPAWN_EGG); + public static ItemWrapper STRIDER_SPAWN_EGG = of(net.minecraft.world.item.Items.STRIDER_SPAWN_EGG); + public static ItemWrapper TRADER_LLAMA_SPAWN_EGG = of(net.minecraft.world.item.Items.TRADER_LLAMA_SPAWN_EGG); + public static ItemWrapper TROPICAL_FISH_SPAWN_EGG = of(net.minecraft.world.item.Items.TROPICAL_FISH_SPAWN_EGG); + public static ItemWrapper TURTLE_SPAWN_EGG = of(net.minecraft.world.item.Items.TURTLE_SPAWN_EGG); + public static ItemWrapper VEX_SPAWN_EGG = of(net.minecraft.world.item.Items.VEX_SPAWN_EGG); + public static ItemWrapper VILLAGER_SPAWN_EGG = of(net.minecraft.world.item.Items.VILLAGER_SPAWN_EGG); + public static ItemWrapper VINDICATOR_SPAWN_EGG = of(net.minecraft.world.item.Items.VINDICATOR_SPAWN_EGG); + public static ItemWrapper WANDERING_TRADER_SPAWN_EGG = of(net.minecraft.world.item.Items.WANDERING_TRADER_SPAWN_EGG); + public static ItemWrapper WITCH_SPAWN_EGG = of(net.minecraft.world.item.Items.WITCH_SPAWN_EGG); + public static ItemWrapper WITHER_SKELETON_SPAWN_EGG = of(net.minecraft.world.item.Items.WITHER_SKELETON_SPAWN_EGG); + public static ItemWrapper WOLF_SPAWN_EGG = of(net.minecraft.world.item.Items.WOLF_SPAWN_EGG); + public static ItemWrapper ZOGLIN_SPAWN_EGG = of(net.minecraft.world.item.Items.ZOGLIN_SPAWN_EGG); + public static ItemWrapper ZOMBIE_SPAWN_EGG = of(net.minecraft.world.item.Items.ZOMBIE_SPAWN_EGG); + public static ItemWrapper ZOMBIE_HORSE_SPAWN_EGG = of(net.minecraft.world.item.Items.ZOMBIE_HORSE_SPAWN_EGG); + public static ItemWrapper ZOMBIE_VILLAGER_SPAWN_EGG = of(net.minecraft.world.item.Items.ZOMBIE_VILLAGER_SPAWN_EGG); + public static ItemWrapper ZOMBIFIED_PIGLIN_SPAWN_EGG = of(net.minecraft.world.item.Items.ZOMBIFIED_PIGLIN_SPAWN_EGG); + public static ItemWrapper EXPERIENCE_BOTTLE = of(net.minecraft.world.item.Items.EXPERIENCE_BOTTLE); + public static ItemWrapper FIRE_CHARGE = of(net.minecraft.world.item.Items.FIRE_CHARGE); + public static ItemWrapper WRITABLE_BOOK = of(net.minecraft.world.item.Items.WRITABLE_BOOK); + public static ItemWrapper WRITTEN_BOOK = of(net.minecraft.world.item.Items.WRITTEN_BOOK); + public static ItemWrapper EMERALD = of(net.minecraft.world.item.Items.EMERALD); + public static ItemWrapper ITEM_FRAME = of(net.minecraft.world.item.Items.ITEM_FRAME); + public static ItemWrapper FLOWER_POT = of(net.minecraft.world.item.Items.FLOWER_POT); + public static ItemWrapper CARROT = of(net.minecraft.world.item.Items.CARROT); + public static ItemWrapper POTATO = of(net.minecraft.world.item.Items.POTATO); + public static ItemWrapper BAKED_POTATO = of(net.minecraft.world.item.Items.BAKED_POTATO); + public static ItemWrapper POISONOUS_POTATO = of(net.minecraft.world.item.Items.POISONOUS_POTATO); + public static ItemWrapper MAP = of(net.minecraft.world.item.Items.MAP); + public static ItemWrapper GOLDEN_CARROT = of(net.minecraft.world.item.Items.GOLDEN_CARROT); + public static ItemWrapper SKELETON_SKULL = of(net.minecraft.world.item.Items.SKELETON_SKULL); + public static ItemWrapper WITHER_SKELETON_SKULL = of(net.minecraft.world.item.Items.WITHER_SKELETON_SKULL); + public static ItemWrapper PLAYER_HEAD = of(net.minecraft.world.item.Items.PLAYER_HEAD); + public static ItemWrapper ZOMBIE_HEAD = of(net.minecraft.world.item.Items.ZOMBIE_HEAD); + public static ItemWrapper CREEPER_HEAD = of(net.minecraft.world.item.Items.CREEPER_HEAD); + public static ItemWrapper DRAGON_HEAD = of(net.minecraft.world.item.Items.DRAGON_HEAD); + public static ItemWrapper CARROT_ON_A_STICK = of(net.minecraft.world.item.Items.CARROT_ON_A_STICK); + public static ItemWrapper WARPED_FUNGUS_ON_A_STICK = of(net.minecraft.world.item.Items.WARPED_FUNGUS_ON_A_STICK); + public static ItemWrapper NETHER_STAR = of(net.minecraft.world.item.Items.NETHER_STAR); + public static ItemWrapper PUMPKIN_PIE = of(net.minecraft.world.item.Items.PUMPKIN_PIE); + public static ItemWrapper FIREWORK_ROCKET = of(net.minecraft.world.item.Items.FIREWORK_ROCKET); + public static ItemWrapper FIREWORK_STAR = of(net.minecraft.world.item.Items.FIREWORK_STAR); + public static ItemWrapper ENCHANTED_BOOK = of(net.minecraft.world.item.Items.ENCHANTED_BOOK); + public static ItemWrapper NETHER_BRICK = of(net.minecraft.world.item.Items.NETHER_BRICK); + public static ItemWrapper QUARTZ = of(net.minecraft.world.item.Items.QUARTZ); + public static ItemWrapper TNT_MINECART = of(net.minecraft.world.item.Items.TNT_MINECART); + public static ItemWrapper HOPPER_MINECART = of(net.minecraft.world.item.Items.HOPPER_MINECART); + public static ItemWrapper PRISMARINE_SHARD = of(net.minecraft.world.item.Items.PRISMARINE_SHARD); + public static ItemWrapper PRISMARINE_CRYSTALS = of(net.minecraft.world.item.Items.PRISMARINE_CRYSTALS); + public static ItemWrapper RABBIT = of(net.minecraft.world.item.Items.RABBIT); + public static ItemWrapper COOKED_RABBIT = of(net.minecraft.world.item.Items.COOKED_RABBIT); + public static ItemWrapper RABBIT_STEW = of(net.minecraft.world.item.Items.RABBIT_STEW); + public static ItemWrapper RABBIT_FOOT = of(net.minecraft.world.item.Items.RABBIT_FOOT); + public static ItemWrapper RABBIT_HIDE = of(net.minecraft.world.item.Items.RABBIT_HIDE); + public static ItemWrapper ARMOR_STAND = of(net.minecraft.world.item.Items.ARMOR_STAND); + public static ItemWrapper IRON_HORSE_ARMOR = of(net.minecraft.world.item.Items.IRON_HORSE_ARMOR); + public static ItemWrapper GOLDEN_HORSE_ARMOR = of(net.minecraft.world.item.Items.GOLDEN_HORSE_ARMOR); + public static ItemWrapper DIAMOND_HORSE_ARMOR = of(net.minecraft.world.item.Items.DIAMOND_HORSE_ARMOR); + public static ItemWrapper LEATHER_HORSE_ARMOR = of(net.minecraft.world.item.Items.LEATHER_HORSE_ARMOR); + public static ItemWrapper LEAD = of(net.minecraft.world.item.Items.LEAD); + public static ItemWrapper NAME_TAG = of(net.minecraft.world.item.Items.NAME_TAG); + public static ItemWrapper COMMAND_BLOCK_MINECART = of(net.minecraft.world.item.Items.COMMAND_BLOCK_MINECART); + public static ItemWrapper MUTTON = of(net.minecraft.world.item.Items.MUTTON); + public static ItemWrapper COOKED_MUTTON = of(net.minecraft.world.item.Items.COOKED_MUTTON); + public static ItemWrapper WHITE_BANNER = of(net.minecraft.world.item.Items.WHITE_BANNER); + public static ItemWrapper ORANGE_BANNER = of(net.minecraft.world.item.Items.ORANGE_BANNER); + public static ItemWrapper MAGENTA_BANNER = of(net.minecraft.world.item.Items.MAGENTA_BANNER); + public static ItemWrapper LIGHT_BLUE_BANNER = of(net.minecraft.world.item.Items.LIGHT_BLUE_BANNER); + public static ItemWrapper YELLOW_BANNER = of(net.minecraft.world.item.Items.YELLOW_BANNER); + public static ItemWrapper LIME_BANNER = of(net.minecraft.world.item.Items.LIME_BANNER); + public static ItemWrapper PINK_BANNER = of(net.minecraft.world.item.Items.PINK_BANNER); + public static ItemWrapper GRAY_BANNER = of(net.minecraft.world.item.Items.GRAY_BANNER); + public static ItemWrapper LIGHT_GRAY_BANNER = of(net.minecraft.world.item.Items.LIGHT_GRAY_BANNER); + public static ItemWrapper CYAN_BANNER = of(net.minecraft.world.item.Items.CYAN_BANNER); + public static ItemWrapper PURPLE_BANNER = of(net.minecraft.world.item.Items.PURPLE_BANNER); + public static ItemWrapper BLUE_BANNER = of(net.minecraft.world.item.Items.BLUE_BANNER); + public static ItemWrapper BROWN_BANNER = of(net.minecraft.world.item.Items.BROWN_BANNER); + public static ItemWrapper GREEN_BANNER = of(net.minecraft.world.item.Items.GREEN_BANNER); + public static ItemWrapper RED_BANNER = of(net.minecraft.world.item.Items.RED_BANNER); + public static ItemWrapper BLACK_BANNER = of(net.minecraft.world.item.Items.BLACK_BANNER); + public static ItemWrapper END_CRYSTAL = of(net.minecraft.world.item.Items.END_CRYSTAL); + public static ItemWrapper CHORUS_FRUIT = of(net.minecraft.world.item.Items.CHORUS_FRUIT); + public static ItemWrapper POPPED_CHORUS_FRUIT = of(net.minecraft.world.item.Items.POPPED_CHORUS_FRUIT); + public static ItemWrapper BEETROOT = of(net.minecraft.world.item.Items.BEETROOT); + public static ItemWrapper BEETROOT_SEEDS = of(net.minecraft.world.item.Items.BEETROOT_SEEDS); + public static ItemWrapper BEETROOT_SOUP = of(net.minecraft.world.item.Items.BEETROOT_SOUP); + public static ItemWrapper DRAGON_BREATH = of(net.minecraft.world.item.Items.DRAGON_BREATH); + public static ItemWrapper SPLASH_POTION = of(net.minecraft.world.item.Items.SPLASH_POTION); + public static ItemWrapper SPECTRAL_ARROW = of(net.minecraft.world.item.Items.SPECTRAL_ARROW); + public static ItemWrapper TIPPED_ARROW = of(net.minecraft.world.item.Items.TIPPED_ARROW); + public static ItemWrapper LINGERING_POTION = of(net.minecraft.world.item.Items.LINGERING_POTION); + public static ItemWrapper SHIELD = of(net.minecraft.world.item.Items.SHIELD); + public static ItemWrapper ELYTRA = of(net.minecraft.world.item.Items.ELYTRA); + public static ItemWrapper SPRUCE_BOAT = of(net.minecraft.world.item.Items.SPRUCE_BOAT); + public static ItemWrapper BIRCH_BOAT = of(net.minecraft.world.item.Items.BIRCH_BOAT); + public static ItemWrapper JUNGLE_BOAT = of(net.minecraft.world.item.Items.JUNGLE_BOAT); + public static ItemWrapper ACACIA_BOAT = of(net.minecraft.world.item.Items.ACACIA_BOAT); + public static ItemWrapper DARK_OAK_BOAT = of(net.minecraft.world.item.Items.DARK_OAK_BOAT); + public static ItemWrapper TOTEM_OF_UNDYING = of(net.minecraft.world.item.Items.TOTEM_OF_UNDYING); + public static ItemWrapper SHULKER_SHELL = of(net.minecraft.world.item.Items.SHULKER_SHELL); + public static ItemWrapper IRON_NUGGET = of(net.minecraft.world.item.Items.IRON_NUGGET); + public static ItemWrapper KNOWLEDGE_BOOK = of(net.minecraft.world.item.Items.KNOWLEDGE_BOOK); + public static ItemWrapper DEBUG_STICK = of(net.minecraft.world.item.Items.DEBUG_STICK); + public static ItemWrapper MUSIC_DISC_13 = of(net.minecraft.world.item.Items.MUSIC_DISC_13); + public static ItemWrapper MUSIC_DISC_CAT = of(net.minecraft.world.item.Items.MUSIC_DISC_CAT); + public static ItemWrapper MUSIC_DISC_BLOCKS = of(net.minecraft.world.item.Items.MUSIC_DISC_BLOCKS); + public static ItemWrapper MUSIC_DISC_CHIRP = of(net.minecraft.world.item.Items.MUSIC_DISC_CHIRP); + public static ItemWrapper MUSIC_DISC_FAR = of(net.minecraft.world.item.Items.MUSIC_DISC_FAR); + public static ItemWrapper MUSIC_DISC_MALL = of(net.minecraft.world.item.Items.MUSIC_DISC_MALL); + public static ItemWrapper MUSIC_DISC_MELLOHI = of(net.minecraft.world.item.Items.MUSIC_DISC_MELLOHI); + public static ItemWrapper MUSIC_DISC_STAL = of(net.minecraft.world.item.Items.MUSIC_DISC_STAL); + public static ItemWrapper MUSIC_DISC_STRAD = of(net.minecraft.world.item.Items.MUSIC_DISC_STRAD); + public static ItemWrapper MUSIC_DISC_WARD = of(net.minecraft.world.item.Items.MUSIC_DISC_WARD); + public static ItemWrapper MUSIC_DISC_11 = of(net.minecraft.world.item.Items.MUSIC_DISC_11); + public static ItemWrapper MUSIC_DISC_WAIT = of(net.minecraft.world.item.Items.MUSIC_DISC_WAIT); + public static ItemWrapper MUSIC_DISC_PIGSTEP = of(net.minecraft.world.item.Items.MUSIC_DISC_PIGSTEP); + public static ItemWrapper TRIDENT = of(net.minecraft.world.item.Items.TRIDENT); + public static ItemWrapper PHANTOM_MEMBRANE = of(net.minecraft.world.item.Items.PHANTOM_MEMBRANE); + public static ItemWrapper NAUTILUS_SHELL = of(net.minecraft.world.item.Items.NAUTILUS_SHELL); + public static ItemWrapper HEART_OF_THE_SEA = of(net.minecraft.world.item.Items.HEART_OF_THE_SEA); + public static ItemWrapper CROSSBOW = of(net.minecraft.world.item.Items.CROSSBOW); + public static ItemWrapper SUSPICIOUS_STEW = of(net.minecraft.world.item.Items.SUSPICIOUS_STEW); + public static ItemWrapper LOOM = of(net.minecraft.world.item.Items.LOOM); + public static ItemWrapper FLOWER_BANNER_PATTERN = of(net.minecraft.world.item.Items.FLOWER_BANNER_PATTERN); + public static ItemWrapper CREEPER_BANNER_PATTERN = of(net.minecraft.world.item.Items.CREEPER_BANNER_PATTERN); + public static ItemWrapper SKULL_BANNER_PATTERN = of(net.minecraft.world.item.Items.SKULL_BANNER_PATTERN); + public static ItemWrapper MOJANG_BANNER_PATTERN = of(net.minecraft.world.item.Items.MOJANG_BANNER_PATTERN); + public static ItemWrapper GLOBE_BANNER_PATTERN = of(net.minecraft.world.item.Items.GLOBE_BANNER_PATTERN); + public static ItemWrapper PIGLIN_BANNER_PATTERN = of(net.minecraft.world.item.Items.PIGLIN_BANNER_PATTERN); + public static ItemWrapper COMPOSTER = of(net.minecraft.world.item.Items.COMPOSTER); + public static ItemWrapper BARREL = of(net.minecraft.world.item.Items.BARREL); + public static ItemWrapper SMOKER = of(net.minecraft.world.item.Items.SMOKER); + public static ItemWrapper BLAST_FURNACE = of(net.minecraft.world.item.Items.BLAST_FURNACE); + public static ItemWrapper CARTOGRAPHY_TABLE = of(net.minecraft.world.item.Items.CARTOGRAPHY_TABLE); + public static ItemWrapper FLETCHING_TABLE = of(net.minecraft.world.item.Items.FLETCHING_TABLE); + public static ItemWrapper GRINDSTONE = of(net.minecraft.world.item.Items.GRINDSTONE); + public static ItemWrapper LECTERN = of(net.minecraft.world.item.Items.LECTERN); + public static ItemWrapper SMITHING_TABLE = of(net.minecraft.world.item.Items.SMITHING_TABLE); + public static ItemWrapper STONECUTTER = of(net.minecraft.world.item.Items.STONECUTTER); + public static ItemWrapper BELL = of(net.minecraft.world.item.Items.BELL); + public static ItemWrapper LANTERN = of(net.minecraft.world.item.Items.LANTERN); + public static ItemWrapper SOUL_LANTERN = of(net.minecraft.world.item.Items.SOUL_LANTERN); + public static ItemWrapper SWEET_BERRIES = of(net.minecraft.world.item.Items.SWEET_BERRIES); + public static ItemWrapper CAMPFIRE = of(net.minecraft.world.item.Items.CAMPFIRE); + public static ItemWrapper SOUL_CAMPFIRE = of(net.minecraft.world.item.Items.SOUL_CAMPFIRE); + public static ItemWrapper SHROOMLIGHT = of(net.minecraft.world.item.Items.SHROOMLIGHT); + public static ItemWrapper HONEYCOMB = of(net.minecraft.world.item.Items.HONEYCOMB); + public static ItemWrapper BEE_NEST = of(net.minecraft.world.item.Items.BEE_NEST); + public static ItemWrapper BEEHIVE = of(net.minecraft.world.item.Items.BEEHIVE); + public static ItemWrapper HONEY_BOTTLE = of(net.minecraft.world.item.Items.HONEY_BOTTLE); + public static ItemWrapper HONEY_BLOCK = of(net.minecraft.world.item.Items.HONEY_BLOCK); + public static ItemWrapper HONEYCOMB_BLOCK = of(net.minecraft.world.item.Items.HONEYCOMB_BLOCK); + public static ItemWrapper LODESTONE = of(net.minecraft.world.item.Items.LODESTONE); + public static ItemWrapper NETHERITE_BLOCK = of(net.minecraft.world.item.Items.NETHERITE_BLOCK); + public static ItemWrapper ANCIENT_DEBRIS = of(net.minecraft.world.item.Items.ANCIENT_DEBRIS); + public static ItemWrapper TARGET = of(net.minecraft.world.item.Items.TARGET); + public static ItemWrapper CRYING_OBSIDIAN = of(net.minecraft.world.item.Items.CRYING_OBSIDIAN); + public static ItemWrapper BLACKSTONE = of(net.minecraft.world.item.Items.BLACKSTONE); + public static ItemWrapper BLACKSTONE_SLAB = of(net.minecraft.world.item.Items.BLACKSTONE_SLAB); + public static ItemWrapper BLACKSTONE_STAIRS = of(net.minecraft.world.item.Items.BLACKSTONE_STAIRS); + public static ItemWrapper GILDED_BLACKSTONE = of(net.minecraft.world.item.Items.GILDED_BLACKSTONE); + public static ItemWrapper POLISHED_BLACKSTONE = of(net.minecraft.world.item.Items.POLISHED_BLACKSTONE); + public static ItemWrapper POLISHED_BLACKSTONE_SLAB = of(net.minecraft.world.item.Items.POLISHED_BLACKSTONE_SLAB); + public static ItemWrapper POLISHED_BLACKSTONE_STAIRS = of(net.minecraft.world.item.Items.POLISHED_BLACKSTONE_STAIRS); + public static ItemWrapper CHISELED_POLISHED_BLACKSTONE = of(net.minecraft.world.item.Items.CHISELED_POLISHED_BLACKSTONE); + public static ItemWrapper POLISHED_BLACKSTONE_BRICKS = of(net.minecraft.world.item.Items.POLISHED_BLACKSTONE_BRICKS); + public static ItemWrapper POLISHED_BLACKSTONE_BRICK_SLAB = of(net.minecraft.world.item.Items.POLISHED_BLACKSTONE_BRICK_SLAB); + public static ItemWrapper POLISHED_BLACKSTONE_BRICK_STAIRS = of(net.minecraft.world.item.Items.POLISHED_BLACKSTONE_BRICK_STAIRS); + public static ItemWrapper CRACKED_POLISHED_BLACKSTONE_BRICKS = of(net.minecraft.world.item.Items.CRACKED_POLISHED_BLACKSTONE_BRICKS); + public static ItemWrapper RESPAWN_ANCHOR = of(net.minecraft.world.item.Items.RESPAWN_ANCHOR); + + public static ItemWrapper of(net.minecraft.world.item.Item item) { + return ItemWrapper.of(item); + } + + public static List getItems() { + return ItemUtil.getItems().stream().map(ItemWrapper::of).collect(Collectors.toList()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/item/MCItems.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/item/MCItems.java new file mode 100644 index 000000000..0384e429a --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/item/MCItems.java @@ -0,0 +1,4 @@ +package net.pitan76.mcpitanlib.midohra.item; + +public class MCItems extends Items { +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/item/SupplierITypedItemWrapper.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/item/SupplierITypedItemWrapper.java new file mode 100644 index 000000000..306c47a01 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/item/SupplierITypedItemWrapper.java @@ -0,0 +1,57 @@ +package net.pitan76.mcpitanlib.midohra.item; + +import net.minecraft.world.item.Item; +import net.pitan76.mcpitanlib.api.item.ICompatItem; +import net.pitan76.mcpitanlib.api.registry.result.RegistryResult; +import net.pitan76.mcpitanlib.api.registry.result.RegistrySupplier; +import net.pitan76.mcpitanlib.midohra.core.INonTypedSupplier; + +import java.util.function.Supplier; + +public class SupplierITypedItemWrapper extends ITypedItemWrapper implements INonTypedSupplier { + private final Supplier supplier; + + protected SupplierITypedItemWrapper(Supplier supplier) { + super(null); + this.supplier = supplier; + } + + public static SupplierITypedItemWrapper of(ItemWrapper wrapper) { + if (wrapper instanceof SupplierItemWrapper) { + SupplierItemWrapper supplierWrapper = (SupplierItemWrapper) wrapper; + return SupplierITypedItemWrapper.of(supplierWrapper); + } + + return new SupplierITypedItemWrapper<>(() -> (T) wrapper.get()); + } + + public static SupplierITypedItemWrapper of(Supplier supplier) { + return new SupplierITypedItemWrapper<>(supplier); + } + + public static SupplierITypedItemWrapper of(RegistryResult result) { + return new SupplierITypedItemWrapper<>(result::get); + } + + public static SupplierITypedItemWrapper of(RegistrySupplier result) { + return new SupplierITypedItemWrapper<>(result::get); + } + + public static SupplierITypedItemWrapper of(SupplierItemWrapper result) { + return new SupplierITypedItemWrapper<>(() -> (T) result.get()); + } + + @Override + public SupplierItemWrapper asNonTyped() { + return SupplierItemWrapper.of(this::get); + } + + @Override + public Item get() { + return (Item) supplier.get(); + } + + public T getICompat() { + return supplier.get(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/item/SupplierItemGroupWrapper.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/item/SupplierItemGroupWrapper.java new file mode 100644 index 000000000..ac6714db4 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/item/SupplierItemGroupWrapper.java @@ -0,0 +1,37 @@ +package net.pitan76.mcpitanlib.midohra.item; + +import net.minecraft.world.item.CreativeModeTab; +import net.pitan76.mcpitanlib.api.item.CreativeTabBuilder; +import net.pitan76.mcpitanlib.api.registry.result.RegistryResult; +import net.pitan76.mcpitanlib.api.registry.result.RegistrySupplier; + +import java.util.function.Supplier; + +public class SupplierItemGroupWrapper extends ItemGroupWrapper { + private final Supplier supplier; + + protected SupplierItemGroupWrapper(Supplier supplier) { + this.supplier = supplier; + } + + public static SupplierItemGroupWrapper of(Supplier supplier) { + return new SupplierItemGroupWrapper(supplier); + } + + public static SupplierItemGroupWrapper of(RegistryResult result) { + return new SupplierItemGroupWrapper(result::get); + } + + public static SupplierItemGroupWrapper of(RegistrySupplier result) { + return new SupplierItemGroupWrapper(result::get); + } + + public static SupplierItemGroupWrapper of(CreativeTabBuilder builder) { + return new SupplierItemGroupWrapper(builder::build); + } + + @Override + public CreativeModeTab get() { + return supplier.get(); + } +} 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..651f28160 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/item/SupplierItemWrapper.java @@ -0,0 +1,38 @@ +package net.pitan76.mcpitanlib.midohra.item; + +import net.minecraft.world.item.Item; +import net.pitan76.mcpitanlib.api.registry.result.RegistryResult; +import net.pitan76.mcpitanlib.api.registry.result.RegistrySupplier; +import net.pitan76.mcpitanlib.midohra.core.INonTypedSupplier; + +import java.util.function.Supplier; + +public class SupplierItemWrapper extends ItemWrapper implements INonTypedSupplier { + private final Supplier supplier; + + protected SupplierItemWrapper(Supplier supplier) { + this.supplier = supplier; + } + + public static SupplierItemWrapper of(Supplier supplier) { + return new SupplierItemWrapper(supplier); + } + + public static SupplierItemWrapper of(RegistryResult result) { + return new SupplierItemWrapper(result::get); + } + + public static SupplierItemWrapper of(RegistrySupplier result) { + return new SupplierItemWrapper(result::get); + } + + @Override + public SupplierItemWrapper asNonTyped() { + return this; + } + + @Override + public Item get() { + return supplier.get(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/item/SupplierTypedBlockItemWrapper.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/item/SupplierTypedBlockItemWrapper.java new file mode 100644 index 000000000..ca99f3122 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/item/SupplierTypedBlockItemWrapper.java @@ -0,0 +1,62 @@ +package net.pitan76.mcpitanlib.midohra.item; + +import net.minecraft.world.item.BlockItem; +import net.minecraft.world.level.block.Block; +import net.pitan76.mcpitanlib.api.registry.result.RegistryResult; +import net.pitan76.mcpitanlib.api.registry.result.RegistrySupplier; +import net.pitan76.mcpitanlib.midohra.block.SupplierTypedBlockWrapper; +import net.pitan76.mcpitanlib.midohra.core.INonTypedSupplier; + +import java.util.function.Supplier; + +public class SupplierTypedBlockItemWrapper extends TypedBlockItemWrapper implements INonTypedSupplier { + private final Supplier supplier; + + protected SupplierTypedBlockItemWrapper(Supplier supplier) { + super(null); + this.supplier = supplier; + } + + public static SupplierTypedBlockItemWrapper of(ItemWrapper wrapper) { + if (wrapper instanceof INonTypedSupplier) { + return SupplierTypedBlockItemWrapper.of(((INonTypedSupplier) wrapper)); + } + + return SupplierTypedBlockItemWrapper.of(() -> (T) wrapper.asBlock().get()); + } + + public static SupplierTypedBlockItemWrapper of(Supplier supplier) { + return new SupplierTypedBlockItemWrapper<>(supplier); + } + + public static SupplierTypedBlockItemWrapper of(RegistryResult result) { + return new SupplierTypedBlockItemWrapper<>(result::get); + } + + public static SupplierTypedBlockItemWrapper of(RegistrySupplier result) { + return new SupplierTypedBlockItemWrapper<>(result::get); + } + + public static SupplierTypedBlockItemWrapper of(SupplierItemWrapper result) { + return new SupplierTypedBlockItemWrapper<>(() -> (T) ((BlockItem) result.get()).getBlock()); + } + + public static SupplierTypedBlockItemWrapper of(INonTypedSupplier result) { + return new SupplierTypedBlockItemWrapper<>(() -> (T) ((BlockItem) result.asNonTyped().get()).getBlock()); + } + + @Override + public SupplierItemWrapper asNonTyped() { + return SupplierItemWrapper.of(() -> get().asItem()); + } + + @Override + public SupplierTypedBlockWrapper asBlock() { + return SupplierTypedBlockWrapper.of(supplier); + } + + @Override + public BlockItem get() { + return (BlockItem) supplier.get().asItem(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/item/SupplierTypedItemWrapper.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/item/SupplierTypedItemWrapper.java new file mode 100644 index 000000000..242034e33 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/item/SupplierTypedItemWrapper.java @@ -0,0 +1,43 @@ +package net.pitan76.mcpitanlib.midohra.item; + +import net.minecraft.world.item.Item; +import net.pitan76.mcpitanlib.api.registry.result.RegistryResult; +import net.pitan76.mcpitanlib.api.registry.result.RegistrySupplier; +import net.pitan76.mcpitanlib.midohra.core.INonTypedSupplier; + +import java.util.function.Supplier; + +public class SupplierTypedItemWrapper extends TypedItemWrapper implements INonTypedSupplier { + private final Supplier supplier; + + protected SupplierTypedItemWrapper(Supplier supplier) { + super(null); + this.supplier = supplier; + } + + public static SupplierTypedItemWrapper of(Supplier supplier) { + return new SupplierTypedItemWrapper<>(supplier); + } + + public static SupplierTypedItemWrapper of(RegistryResult result) { + return new SupplierTypedItemWrapper<>(result::get); + } + + public static SupplierTypedItemWrapper of(RegistrySupplier result) { + return new SupplierTypedItemWrapper<>(result::get); + } + + public static SupplierTypedItemWrapper of(SupplierItemWrapper result) { + return new SupplierTypedItemWrapper<>(() -> (T) result.get()); + } + + @Override + public SupplierItemWrapper asNonTyped() { + return SupplierItemWrapper.of(this::get); + } + + @Override + public T get() { + return supplier.get(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/item/TypedBlockItemWrapper.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/item/TypedBlockItemWrapper.java new file mode 100644 index 000000000..97ee867fe --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/item/TypedBlockItemWrapper.java @@ -0,0 +1,46 @@ +package net.pitan76.mcpitanlib.midohra.item; + +import net.minecraft.world.item.BlockItem; +import net.minecraft.world.level.block.Block; +import net.pitan76.mcpitanlib.midohra.block.TypedBlockWrapper; +import net.pitan76.mcpitanlib.midohra.core.INonTypedSupplier; + +public class TypedBlockItemWrapper extends ItemWrapper { + protected T block; + + protected TypedBlockItemWrapper(T block) { + super(block == null ? null : block.asItem()); + this.block = block; + } + + public static TypedBlockItemWrapper ofRaw(T block) { + return new TypedBlockItemWrapper<>(block); + } + + public static TypedBlockItemWrapper of(TypedBlockWrapper wrapper) { + return ofRaw(wrapper.get()); + } + + public static TypedBlockItemWrapper of(ItemWrapper wrapper) { + if (wrapper instanceof INonTypedSupplier) { + return SupplierTypedBlockItemWrapper.of((INonTypedSupplier) wrapper); + } + + return TypedBlockItemWrapper.ofRaw((T) wrapper.asBlock().get()); + } + + @Override + public TypedBlockWrapper asBlock() { + return TypedBlockWrapper.ofRaw(block); + } + + @Override + public boolean isBlock() { + return true; + } + + @Override + public BlockItem get() { + return (BlockItem) super.get(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/item/TypedItemWrapper.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/item/TypedItemWrapper.java new file mode 100644 index 000000000..6fcccd5bc --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/item/TypedItemWrapper.java @@ -0,0 +1,31 @@ +package net.pitan76.mcpitanlib.midohra.item; + +import net.minecraft.world.item.Item; +import net.pitan76.mcpitanlib.api.registry.result.RegistryResult; +import net.pitan76.mcpitanlib.api.registry.result.RegistrySupplier; + +import java.util.function.Supplier; + +public class TypedItemWrapper extends ItemWrapper { + protected TypedItemWrapper(T item) { + super(item); + } + + public static TypedItemWrapper ofRaw(T item) { + return new TypedItemWrapper<>(item); + } + + public static TypedItemWrapper of(ItemWrapper wrapper) { + if (wrapper instanceof SupplierItemWrapper) { + SupplierItemWrapper supplierWrapper = (SupplierItemWrapper) wrapper; + return SupplierTypedItemWrapper.of(supplierWrapper); + } + + return new TypedItemWrapper<>((T) wrapper.get()); + } + + @Override + public T get() { + return (T) super.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..2a97759ad --- /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.Tag 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..54eea2ee7 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/nbt/NbtCompound.java @@ -0,0 +1,180 @@ +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.Optional; +import java.util.UUID; + +@SuppressWarnings("deprecation") +public class NbtCompound implements ElementConvertible { + protected final net.minecraft.nbt.CompoundTag nbt; + + protected NbtCompound(net.minecraft.nbt.CompoundTag nbt) { + this.nbt = nbt; + } + + public static NbtCompound of(net.minecraft.nbt.CompoundTag 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.CompoundTag 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.CompoundTag toMinecraft() { + return nbt; + } + + @Override + public String toString() { + return nbt.toString(); + } + + @Override + public NbtElement toElement() { + return NbtElement.of(nbt); + } + + public void putSimpleItemStack(String key, ItemStack stack) { + NbtUtil.putSimpleItemStack(nbt, key, stack.toMinecraft()); + } + + public Optional getSimpleItemStack(String key) { + return NbtUtil.getSimpleItemStack(nbt, key).map(ItemStack::of); + } + + public NbtList getList(String key) { + return new NbtList(NbtUtil.getList(nbt, key)); + } + + public NbtList getList(String key, int type) { + return new NbtList(NbtUtil.getList(nbt, key, type)); + } + + public NbtList getNbtCompoundList(String key) { + return new NbtList(NbtUtil.getNbtCompoundList(nbt, key)); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + NbtCompound that = (NbtCompound) obj; + return nbt.equals(that.nbt); + } + + @Override + public int hashCode() { + return nbt.hashCode(); + } +} 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..98301de48 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/nbt/NbtElement.java @@ -0,0 +1,133 @@ +package net.pitan76.mcpitanlib.midohra.nbt; + +import net.minecraft.nbt.TagType; +import org.jetbrains.annotations.Nullable; + +public class NbtElement implements ElementConvertible { + protected final net.minecraft.nbt.Tag nbt; + + protected NbtElement(net.minecraft.nbt.Tag nbt) { + this.nbt = nbt; + } + + public static NbtElement of(net.minecraft.nbt.Tag nbt) { + return new NbtElement(nbt); + } + + public NbtElement copy() { + return new NbtElement(nbt.copy()); + } + + public byte getType() { + return nbt.getId(); + } + + public TagType getNbtType() { + return nbt.getType(); + } + + public int getSizeInBytes() { + return nbt.sizeInBytes(); + } + + @Override + public String toString() { + return nbt.toString(); + } + + public net.minecraft.nbt.Tag toMinecraft() { + return nbt; + } + + @Override + public NbtElement toElement() { + return this; + } + + public String asString() { + return nbt.asString().orElse(""); + } + + public boolean isNbtCompound() { + return nbt instanceof net.minecraft.nbt.CompoundTag; + } + + @Nullable + public NbtCompound asNbtCompound() { + if (isNbtCompound()) { + return NbtCompound.of((net.minecraft.nbt.CompoundTag) nbt); + } + + return null; + } + + public NbtCompound asNbtCompoundOrDefault(NbtCompound defaultCompound) { + NbtCompound compound = asNbtCompound(); + return compound != null ? compound : defaultCompound; + } + + public boolean isNbtList() { + return nbt instanceof net.minecraft.nbt.ListTag; + } + + @Nullable + public NbtList asNbtList() { + if (isNbtList()) { + return NbtList.of((net.minecraft.nbt.ListTag) nbt); + } + + return null; + } + + public NbtList asNbtListOrDefault(NbtList defaultList) { + NbtList list = asNbtList(); + return list != null ? list : defaultList; + } + + public boolean isNbtString() { + return nbt instanceof net.minecraft.nbt.StringTag; + } + + public NbtString asNbtString() { + if (isNbtString()) { + return NbtString.of((net.minecraft.nbt.StringTag) nbt); + } + + return NbtString.of(""); + } + + public NbtString asNbtStringOrDefault(NbtString defaultString) { + NbtString string = asNbtString(); + return string != null ? string : defaultString; + } + + public boolean isNbtInteger() { + return nbt instanceof net.minecraft.nbt.IntTag; + } + + public NbtInteger asNbtInteger() { + if (isNbtInteger()) { + return NbtInteger.of((net.minecraft.nbt.IntTag) nbt); + } + + return NbtInteger.of(0); + } + + public NbtInteger asNbtIntegerOrDefault(NbtInteger defaultInteger) { + NbtInteger integer = asNbtInteger(); + return integer != null ? integer : defaultInteger; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + NbtElement that = (NbtElement) obj; + return nbt.equals(that.nbt); + } + + @Override + public int hashCode() { + return nbt.hashCode(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/nbt/NbtInteger.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/nbt/NbtInteger.java new file mode 100644 index 000000000..52f03cd21 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/nbt/NbtInteger.java @@ -0,0 +1,68 @@ +package net.pitan76.mcpitanlib.midohra.nbt; + +import java.util.Optional; + +public class NbtInteger implements ElementConvertible { + protected final net.minecraft.nbt.IntTag nbtInt; + + protected NbtInteger(net.minecraft.nbt.IntTag nbtInt) { + this.nbtInt = nbtInt; + } + + public static NbtInteger of(net.minecraft.nbt.IntTag nbtInt) { + return new NbtInteger(nbtInt); + } + + public static NbtInteger of(int value) { + return new NbtInteger(net.minecraft.nbt.IntTag.valueOf(value)); + } + + public static Optional ofOptional(NbtElement nbtElement) { + if (nbtElement.toMinecraft() instanceof net.minecraft.nbt.IntTag) + return Optional.of(new NbtInteger((net.minecraft.nbt.IntTag) nbtElement.toMinecraft())); + + return Optional.empty(); + } + + public NbtInteger copy() { + return new NbtInteger(nbtInt.copy()); + } + + public byte getType() { + return nbtInt.getId(); + } + + public int getValue() { + return nbtInt.value(); + } + + public String asString() { + return nbtInt.asString().orElse(""); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + + return o instanceof NbtInteger && nbtInt.equals(((NbtInteger) o).nbtInt); + } + + @Override + public int hashCode() { + return nbtInt.hashCode(); + } + + @Override + public String toString() { + return nbtInt.toString(); + } + + public net.minecraft.nbt.IntTag toMinecraft() { + return nbtInt; + } + + @Override + public NbtElement toElement() { + return NbtElement.of(nbtInt); + } +} 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..1ca1c6841 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/nbt/NbtList.java @@ -0,0 +1,128 @@ +package net.pitan76.mcpitanlib.midohra.nbt; + +import net.pitan76.mcpitanlib.api.util.NbtUtil; + +import java.util.AbstractList; +import java.util.Optional; + +@SuppressWarnings("deprecation") +public class NbtList extends AbstractList implements ElementConvertible { + protected final net.minecraft.nbt.ListTag nbtList; + + protected NbtList(net.minecraft.nbt.ListTag nbtList) { + this.nbtList = nbtList; + } + + public static NbtList of(net.minecraft.nbt.ListTag nbtList) { + return new NbtList(nbtList); + } + + public static Optional ofOptional(NbtElement nbtElement) { + if (nbtElement.toMinecraft() instanceof net.minecraft.nbt.ListTag) + return Optional.of(new NbtList((net.minecraft.nbt.ListTag) 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.getId(); + } + + @Override + public NbtElement get(int index) { + return NbtElement.of(nbtList.get(index)); + } + + public boolean add(net.minecraft.nbt.Tag nbtElement) { + return nbtList.add(nbtElement); + } + + @Override + public boolean add(NbtElement nbtElement) { + return add(nbtElement.toMinecraft()); + } + + public void add(int index, net.minecraft.nbt.Tag 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().orElse(""); + } + + @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.ListTag toMinecraft() { + return nbtList; + } + + @Override + public NbtElement toElement() { + return NbtElement.of(nbtList); + } + + public static NbtList of() { + return new NbtList(NbtUtil.createNbtList()); + } + + public boolean add(ElementConvertible element) { + return add(element.toMinecraftNbtElement()); + } + + public void add(int index, ElementConvertible element) { + add(index, element.toMinecraftNbtElement()); + } + + public NbtElement set(int index, ElementConvertible element) { + return NbtElement.of(nbtList.set(index, element.toMinecraftNbtElement())); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/nbt/NbtString.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/nbt/NbtString.java new file mode 100644 index 000000000..ba8caa92e --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/nbt/NbtString.java @@ -0,0 +1,68 @@ +package net.pitan76.mcpitanlib.midohra.nbt; + +import java.util.Optional; + +public class NbtString implements ElementConvertible { + protected final net.minecraft.nbt.StringTag nbtString; + + protected NbtString(net.minecraft.nbt.StringTag nbtString) { + this.nbtString = nbtString; + } + + public static NbtString of(net.minecraft.nbt.StringTag nbtString) { + return new NbtString(nbtString); + } + + public static NbtString of(String value) { + return new NbtString(net.minecraft.nbt.StringTag.valueOf(value)); + } + + public static Optional ofOptional(NbtElement nbtElement) { + if (nbtElement.toMinecraft() instanceof net.minecraft.nbt.StringTag) + return Optional.of(new NbtString((net.minecraft.nbt.StringTag) nbtElement.toMinecraft())); + + return Optional.empty(); + } + + public NbtString copy() { + return new NbtString(nbtString.copy()); + } + + public byte getType() { + return nbtString.getId(); + } + + public String getValue() { + return nbtString.value(); + } + + public String asString() { + return nbtString.asString().orElse(""); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + + return o instanceof NbtString && nbtString.equals(((NbtString) o).nbtString); + } + + @Override + public int hashCode() { + return nbtString.hashCode(); + } + + @Override + public String toString() { + return nbtString.toString(); + } + + public net.minecraft.nbt.StringTag toMinecraft() { + return nbtString; + } + + @Override + public NbtElement toElement() { + return NbtElement.of(nbtString); + } +} 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..9f279f882 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/network/CompatPacketByteBuf.java @@ -0,0 +1,143 @@ +package net.pitan76.mcpitanlib.midohra.network; + +import net.minecraft.network.FriendlyByteBuf; +import net.pitan76.mcpitanlib.api.network.PacketByteUtil; +import net.pitan76.mcpitanlib.midohra.nbt.NbtCompound; +import net.pitan76.mcpitanlib.midohra.util.math.BlockPos; + +public class CompatPacketByteBuf extends FriendlyByteBuf implements IByteBuf { + public CompatPacketByteBuf(FriendlyByteBuf buf) { + super(buf); + } + + public CompatPacketByteBuf() { + super(PacketByteUtil.create()); + } + + public static CompatPacketByteBuf create() { + return new CompatPacketByteBuf(); + } + + public static CompatPacketByteBuf of(FriendlyByteBuf buf) { + return new CompatPacketByteBuf(buf); + } + + public FriendlyByteBuf 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 writeUtf(String string) { + super.writeUtf(string); + return this; + } + + public String readUtf() { + return super.readUtf(); + } + + public CompatPacketByteBuf writeBlockPos(net.minecraft.core.BlockPos pos) { + super.writeBlockPos(pos); + return this; + } + + public net.minecraft.core.BlockPos readBlockPos() { + return super.readBlockPos(); + } + + public CompatPacketByteBuf writeBlockPos(BlockPos pos) { + return writeBlockPos(pos.toMinecraft()); + } + + public BlockPos readBlockPosMidohra() { + return BlockPos.of(readBlockPos()); + } + + public NbtCompound readNbtM() { + return PacketByteUtil.readNbtM(this); + } + + public CompatPacketByteBuf writeNbt(NbtCompound nbt) { + PacketByteUtil.writeNbt(this, nbt); + return this; + } + + public CompatPacketByteBuf writeVar(Object obj) { + PacketByteUtil.writeVar(this, obj); + return this; + } + + public boolean isReadable() { + return PacketByteUtil.isReadable(this); + } + + public boolean isWritable() { + return PacketByteUtil.isWritable(this); + } + + public boolean isReadable(int size) { + return PacketByteUtil.isReadable(this, size); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/network/IByteBuf.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/network/IByteBuf.java new file mode 100644 index 000000000..4c3db9f8a --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/network/IByteBuf.java @@ -0,0 +1,42 @@ +package net.pitan76.mcpitanlib.midohra.network; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufConvertible; +import net.minecraft.network.FriendlyByteBuf; + +public interface IByteBuf extends ByteBufConvertible { + default CompatPacketByteBuf toCompat() { + if (this instanceof CompatPacketByteBuf) + return (CompatPacketByteBuf) this; + else if (this instanceof FriendlyByteBuf) + return new CompatPacketByteBuf((FriendlyByteBuf) this); + else + throw new UnsupportedOperationException("This IByteBuf cannot be converted to CompatPacketByteBuf"); + } + + default FriendlyByteBuf toRaw() { + if (this instanceof FriendlyByteBuf) + return (FriendlyByteBuf) this; + else + throw new UnsupportedOperationException("This IByteBuf is not a FriendlyByteBuf"); + } + + default net.pitan76.mcpitanlib.midohra.network.PacketByteBuf toMidohra() { + if (this instanceof net.pitan76.mcpitanlib.midohra.network.PacketByteBuf) + return (net.pitan76.mcpitanlib.midohra.network.PacketByteBuf) this; + else if (this instanceof CompatPacketByteBuf) + return new net.pitan76.mcpitanlib.midohra.network.PacketByteBuf((CompatPacketByteBuf) this); + else if (this instanceof FriendlyByteBuf) + return new net.pitan76.mcpitanlib.midohra.network.PacketByteBuf((FriendlyByteBuf) this); + else + throw new UnsupportedOperationException("This IByteBuf cannot be converted to PacketByteBuf"); + } + + @Override + default ByteBuf asByteBuf() { + if (this instanceof ByteBuf) + return (ByteBuf) this; + else + throw new UnsupportedOperationException("This IByteBuf cannot be converted to ByteBuf"); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/network/PacketByteBuf.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/network/PacketByteBuf.java new file mode 100644 index 000000000..a2ba4554f --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/network/PacketByteBuf.java @@ -0,0 +1,266 @@ +package net.pitan76.mcpitanlib.midohra.network; + +import net.minecraft.network.FriendlyByteBuf; +import net.pitan76.mcpitanlib.api.network.PacketByteUtil; +import net.pitan76.mcpitanlib.api.text.TextComponent; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.midohra.item.ItemStack; +import net.pitan76.mcpitanlib.midohra.nbt.NbtCompound; +import net.pitan76.mcpitanlib.midohra.nbt.NbtElement; +import net.pitan76.mcpitanlib.midohra.util.math.BlockPos; + +public class PacketByteBuf implements IByteBuf { + private final CompatPacketByteBuf buf; + + public PacketByteBuf() { + this.buf = new CompatPacketByteBuf(); + } + + public PacketByteBuf(CompatPacketByteBuf buf) { + this.buf = buf; + } + + public PacketByteBuf(FriendlyByteBuf buf) { + this.buf = new CompatPacketByteBuf(buf); + } + + public static PacketByteBuf of() { + return new PacketByteBuf(); + } + + public static PacketByteBuf of(CompatPacketByteBuf buf) { + return new PacketByteBuf(buf); + } + + public static PacketByteBuf of(FriendlyByteBuf buf) { + return new PacketByteBuf(buf); + } + + public CompatPacketByteBuf getBuf() { + return buf; + } + + @Override + public CompatPacketByteBuf toCompat() { + return getBuf(); + } + + @Override + public FriendlyByteBuf toRaw() { + return getBuf().getRaw(); + } + + @Override + public PacketByteBuf toMidohra() { + return this; + } + + @Override + public int hashCode() { + return getBuf().hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + PacketByteBuf other = (PacketByteBuf) obj; + return getBuf().equals(other.getBuf()); + } + + public PacketByteBuf writeInt(int value) { + PacketByteUtil.writeInt(getBuf(), value); + return this; + } + + public int readInt() { + return PacketByteUtil.readInt(getBuf()); + } + + public PacketByteBuf writeLong(long value) { + PacketByteUtil.writeLong(getBuf(), value); + return this; + } + + public long readLong() { + return PacketByteUtil.readLong(getBuf()); + } + + public PacketByteBuf writeBool(boolean value) { + PacketByteUtil.writeBoolean(getBuf(), value); + return this; + } + + public boolean readBool() { + return PacketByteUtil.readBoolean(getBuf()); + } + + public PacketByteBuf writeFloat(float value) { + PacketByteUtil.writeFloat(getBuf(), value); + return this; + } + + public float readFloat() { + return PacketByteUtil.readFloat(getBuf()); + } + + public PacketByteBuf writeDouble(double value) { + PacketByteUtil.writeDouble(getBuf(), value); + return this; + } + + public double readDouble() { + return PacketByteUtil.readDouble(getBuf()); + } + + public PacketByteBuf writeString(String value) { + PacketByteUtil.writeString(getBuf(), value); + return this; + } + + public String readString() { + return PacketByteUtil.readString(getBuf()); + } + + public PacketByteBuf writeByte(byte bytes) { + PacketByteUtil.writeByte(getBuf(), bytes); + return this; + } + + public byte readByte() { + return PacketByteUtil.readByte(getBuf()); + } + + public PacketByteBuf writeBytes(byte[] bytes) { + PacketByteUtil.writeByteArray(getBuf(), bytes); + return this; + } + + public byte[] readBytes() { + return PacketByteUtil.readByteArray(getBuf()); + } + + public PacketByteBuf writeShort(short value) { + PacketByteUtil.writeShort(getBuf(), value); + return this; + } + + public short readShort() { + return PacketByteUtil.readShort(getBuf()); + } + + public PacketByteBuf writeVarInt(int value) { + PacketByteUtil.writeVarInt(getBuf(), value); + return this; + } + + public int readVarInt() { + return PacketByteUtil.readVarInt(getBuf()); + } + + public PacketByteBuf writeVarLong(long value) { + PacketByteUtil.writeVarLong(getBuf(), value); + return this; + } + + public long readVarLong() { + return PacketByteUtil.readVarLong(getBuf()); + } + + public PacketByteBuf writeVar(Object value) { + PacketByteUtil.writeVar(getBuf(), value); + return this; + } + + public ItemStack readItemStack() { + return ItemStack.of(PacketByteUtil.readItemStack(getBuf())); + } + + public PacketByteBuf writeItemStack(ItemStack stack) { + PacketByteUtil.writeItemStack(getBuf(), stack.toMinecraft()); + return this; + } + + public NbtCompound readNbt() { + return PacketByteUtil.readNbtM(getBuf()); + } + + public PacketByteBuf writeNbt(NbtCompound nbt) { + PacketByteUtil.writeNbt(getBuf(), nbt); + return this; + } + + public NbtElement readUnlimitedNbt() { + return NbtElement.of(PacketByteUtil.readUnlimitedNbt(getBuf())); + } + + public BlockPos readBlockPos() { + return PacketByteUtil.readBlockPosM(getBuf()); + } + + public PacketByteBuf writeBlockPos(BlockPos pos) { + PacketByteUtil.writeBlockPos(getBuf(), pos); + return this; + } + + public boolean isReadable() { + return PacketByteUtil.isReadable(getBuf()); + } + + public boolean isWritable() { + return PacketByteUtil.isWritable(getBuf()); + } + + public boolean isReadable(int size) { + return PacketByteUtil.isReadable(getBuf(), size); + } + + public boolean isWritable(int size) { + return getBuf().isWritable(size); + } + + public PacketByteBuf writeIntArray(int[] ints) { + PacketByteUtil.writeIntArray(getBuf(), ints); + return this; + } + + public int[] readIntArray() { + return PacketByteUtil.readIntArray(getBuf()); + } + + public PacketByteBuf writeLongArray(long[] longs) { + PacketByteUtil.writeLongArray(getBuf(), longs); + return this; + } + + public long[] readLongArray() { + return PacketByteUtil.readLongArray(getBuf()); + } + + public PacketByteBuf writeByteArray(byte[] bytes) { + PacketByteUtil.writeByteArray(getBuf(), bytes); + return this; + } + + public byte[] readByteArray() { + return PacketByteUtil.readByteArray(getBuf()); + } + + public PacketByteBuf writeId(CompatIdentifier id) { + PacketByteUtil.writeIdentifier(getBuf(), id.toMinecraft()); + return this; + } + + public CompatIdentifier readId() { + return CompatIdentifier.of(PacketByteUtil.readIdentifier(getBuf())); + } + + public PacketByteBuf writeText(TextComponent text) { + PacketByteUtil.writeText(getBuf(), text.getText()); + return this; + } + + public TextComponent readText() { + return new TextComponent(PacketByteUtil.readText(getBuf())); + } +} 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..361c4d769 --- /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.world.item.crafting.CraftingBookCategory; +import net.minecraft.core.NonNullList; +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.world.item.crafting.CraftingRecipe recipe; + + protected CraftingRecipe(net.minecraft.world.item.crafting.CraftingRecipe recipe) { + super(null); + this.recipe = recipe; + } + + public static CraftingRecipe of(net.minecraft.world.item.crafting.CraftingRecipe recipe) { + return new CraftingRecipe(recipe); + } + + public net.minecraft.world.item.crafting.CraftingRecipe getRaw() { + return recipe; + } + + public net.minecraft.world.item.crafting.CraftingRecipe toMinecraft() { + return getRaw(); + } + + public CraftingBookCategory getRawCategory() { + return getRaw().category(); + } + + public boolean matches(CraftingRecipeInputOrInventory input, World world) { + return getRaw().matches(input.getRaw(), world.getRaw()); + } + + public net.minecraft.world.item.ItemStack craft(CraftingRecipeInputOrInventory input, World world) { + return getRaw().assemble(input.getRaw()); + } + + public ItemStack craftMidohra(CraftingRecipeInputOrInventory input, World world) { + return ItemStack.of(craft(input, world)); + } + + public net.minecraft.world.item.ItemStack craft(CraftingRecipeInputOrInventory input, CompatRegistryLookup registryLookup) { + return getRaw().assemble(input.getRaw()); + } + + public net.minecraft.world.item.ItemStack craft(CraftingRecipeInputOrInventory input, net.minecraft.world.level.Level world) { + return getRaw().assemble(input.getRaw()); + } + + public NonNullList getRecipeRemaindersDefaultedList(CraftingRecipeInputOrInventory input) { + return getRaw().getRemainingItems(input.getRaw()); + } + + public ItemStackList getRecipeRemainders(CraftingRecipeInputOrInventory input) { + return ItemStackList.of(getRecipeRemaindersDefaultedList(input)); + } + + public net.minecraft.world.item.ItemStack getOutput(CraftingRecipeInputOrInventory input, net.minecraft.world.level.Level world) { + return craft(input, world); + } + + public net.minecraft.world.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..e34a99084 --- /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.world.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.world.item.crafting.Ingredient ingredient; + + protected Ingredient(net.minecraft.world.item.crafting.Ingredient ingredient) { + this.ingredient = ingredient; + } + + public static Ingredient of(net.minecraft.world.item.crafting.Ingredient ingredient) { + return new Ingredient(ingredient); + } + + public static Ingredient ofItems(Item... items) { + return of(net.minecraft.world.item.crafting.Ingredient.of(items)); + } + + public static Ingredient ofItem(Item items) { + return of(net.minecraft.world.item.crafting.Ingredient.of(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.world.item.crafting.Ingredient getRaw() { + return ingredient; + } + + public net.minecraft.world.item.crafting.Ingredient toMinecraft() { + return getRaw(); + } + + public boolean test(net.minecraft.world.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.world.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.world.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..136ccd854 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/recipe/Recipe.java @@ -0,0 +1,116 @@ +package net.pitan76.mcpitanlib.midohra.recipe; + +import net.minecraft.world.item.crafting.Ingredient; +import net.minecraft.world.item.crafting.RecipeSerializer; +import net.minecraft.world.item.crafting.RecipeInput; +import net.pitan76.mcpitanlib.api.util.inventory.CompatInventory; +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; +import java.util.stream.Collectors; + +public class Recipe { + private final net.minecraft.world.item.crafting.Recipe recipe; + + protected Recipe(net.minecraft.world.item.crafting.Recipe recipe) { + this.recipe = recipe; + } + + public static Recipe of(net.minecraft.world.item.crafting.Recipe recipe) { + return new Recipe(recipe); + } + + public static CraftingRecipe of(net.minecraft.world.item.crafting.CraftingRecipe recipe) { + return new CraftingRecipe(recipe); + } + + public static ShapedRecipe of(net.minecraft.world.item.crafting.ShapedRecipe recipe) { + return new ShapedRecipe(recipe); + } + + public static ShapelessRecipe of(net.minecraft.world.item.crafting.ShapelessRecipe recipe) { + return new ShapelessRecipe(recipe); + } + + public net.minecraft.world.item.crafting.Recipe getRaw() { + return recipe; + } + + public net.minecraft.world.item.crafting.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.world.item.ItemStack craft(RecipeInputOrInventory input, World world) { + if (input instanceof TypedRecipeInputOrInventory) { + return craft((TypedRecipeInputOrInventory) input, world); + } + + return net.minecraft.world.item.ItemStack.EMPTY; + } + + public ItemStack craftMidohra(RecipeInputOrInventory input, World world) { + return ItemStack.of(craft(input, world)); + } + + public boolean matches(TypedRecipeInputOrInventory input, World world) { + return getRaw().matches(input.getRecipeInput(), world.getRaw()); + } + + public net.minecraft.world.item.ItemStack craft(TypedRecipeInputOrInventory input, World world) { + return getRaw().assemble(input.getRecipeInput()); + } + + public ItemStack craftMidohra(TypedRecipeInputOrInventory input, World world) { + return ItemStack.of(craft(input, world)); + } + + public String getGroup() { + return getRaw().group(); + } + + public RecipeType getType() { + return RecipeType.of(getRaw().getType()); + } + + public List getInputs() { + return getRaw().placementInfo().ingredients(); + } + + public ItemStack getOutput(World world) { + List ingredients = getInputs().stream() + .map(net.pitan76.mcpitanlib.midohra.recipe.Ingredient::of) + .collect(Collectors.toList()); + + CompatInventory inventory = new CompatInventory(ingredients.size()); + for (int i = 0; i < ingredients.size(); i++) { + ItemStack stack = ingredients.get(i).getMatchingStacksAsMidohra()[0]; + inventory.callSetStack(i, stack); + } + + return craftMidohra(TypedRecipeInputOrInventory._of(inventory), world); + } + + private ItemStack cachedOutput = null; + + public ItemStack getCachedOutput(World world) { + if (cachedOutput == null) + cachedOutput = getOutput(world); + + return cachedOutput; + } +} 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..cb1e1dac8 --- /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.world.item.crafting.RecipeAccess recipeManager; + + protected RecipeManager(net.minecraft.world.item.crafting.RecipeAccess recipeManager) { + this.recipeManager = recipeManager; + } + + public static RecipeManager of(net.minecraft.world.item.crafting.RecipeAccess recipeManager) { + return new RecipeManager(recipeManager); + } + + public net.minecraft.world.item.crafting.RecipeAccess getRaw() { + return recipeManager; + } + + public net.minecraft.world.item.crafting.RecipeAccess 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..0eb0c82ed --- /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.core.registries.BuiltInRegistries; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; + +public class RecipeType { + private final net.minecraft.world.item.crafting.RecipeType recipeType; + + public static final RecipeType CRAFTING = new RecipeType(net.minecraft.world.item.crafting.RecipeType.CRAFTING); + public static final RecipeType SMELTING = new RecipeType(net.minecraft.world.item.crafting.RecipeType.SMELTING); + public static final RecipeType BLASTING = new RecipeType(net.minecraft.world.item.crafting.RecipeType.BLASTING); + public static final RecipeType SMOKING = new RecipeType(net.minecraft.world.item.crafting.RecipeType.SMOKING); + public static final RecipeType CAMPFIRE_COOKING = new RecipeType(net.minecraft.world.item.crafting.RecipeType.CAMPFIRE_COOKING); + public static final RecipeType STONECUTTING = new RecipeType(net.minecraft.world.item.crafting.RecipeType.STONECUTTING); + public static final RecipeType SMITHING = new RecipeType(net.minecraft.world.item.crafting.RecipeType.SMITHING); + + protected RecipeType(net.minecraft.world.item.crafting.RecipeType recipeType) { + this.recipeType = recipeType; + } + + public static RecipeType of(net.minecraft.world.item.crafting.RecipeType recipeType) { + if (recipeType == net.minecraft.world.item.crafting.RecipeType.CRAFTING) { + return CRAFTING; + } else if (recipeType == net.minecraft.world.item.crafting.RecipeType.SMELTING) { + return SMELTING; + } else if (recipeType == net.minecraft.world.item.crafting.RecipeType.BLASTING) { + return BLASTING; + } else if (recipeType == net.minecraft.world.item.crafting.RecipeType.SMOKING) { + return SMOKING; + } else if (recipeType == net.minecraft.world.item.crafting.RecipeType.CAMPFIRE_COOKING) { + return CAMPFIRE_COOKING; + } else if (recipeType == net.minecraft.world.item.crafting.RecipeType.STONECUTTING) { + return STONECUTTING; + } else if (recipeType == net.minecraft.world.item.crafting.RecipeType.SMITHING) { + return SMITHING; + } + + return new RecipeType(recipeType); + } + + public static RecipeType of(CompatIdentifier id) { + return of(BuiltInRegistries.RECIPE_TYPE.getValue(id.toMinecraft())); + } + + public net.minecraft.world.item.crafting.RecipeType getRaw() { + return recipeType; + } + + public net.minecraft.world.item.crafting.RecipeType toMinecraft() { + return getRaw(); + } + + public CompatIdentifier getId() { + return CompatIdentifier.fromMinecraft(BuiltInRegistries.RECIPE_TYPE.getKey(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..8c23c4598 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/recipe/ServerRecipeManager.java @@ -0,0 +1,157 @@ +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 { + private net.minecraft.world.item.crafting.RecipeManager serverRecipeManager; + + protected ServerRecipeManager(net.minecraft.world.item.crafting.RecipeManager serverRecipeManager) { + super(null); + this.serverRecipeManager = serverRecipeManager; + } + + public static ServerRecipeManager of(net.minecraft.world.item.crafting.RecipeManager serverRecipeManager) { + return new ServerRecipeManager(serverRecipeManager); + } + + public static ServerRecipeManager of(net.minecraft.server.level.ServerLevel world) { + return of(world.recipeAccess()); + } + + public static ServerRecipeManager of(ServerWorld world) { + return of(world.getRaw()); + } + + @Override + public net.minecraft.world.item.crafting.RecipeManager getRaw() { + return serverRecipeManager; + } + + @Override + public net.minecraft.world.item.crafting.RecipeManager toMinecraft() { + return getRaw(); + } + + @Deprecated + public Collection> getRawRecipes() { + return serverRecipeManager.getRecipes(); + } + + public Collection getRecipeEntries() { + List recipes = new ArrayList<>(); + for (net.minecraft.world.item.crafting.RecipeHolder recipe : serverRecipeManager.getRecipes()) { + recipes.add(RecipeEntry.of(recipe)); + } + + return recipes; + } + + public Collection getCraftingRecipeEntries() { + List recipes = new ArrayList<>(); + for (net.minecraft.world.item.crafting.RecipeHolder recipe : serverRecipeManager.getRecipes()) { + if (recipe.value() instanceof net.minecraft.world.item.crafting.CraftingRecipe) { + recipes.add(CraftingRecipeEntry.of(recipe)); + } + } + + return recipes; + } + + public Collection getShapelessRecipeEntries() { + List recipes = new ArrayList<>(); + for (net.minecraft.world.item.crafting.RecipeHolder recipe : serverRecipeManager.getRecipes()) { + if (recipe.value() instanceof net.minecraft.world.item.crafting.ShapelessRecipe) { + recipes.add(ShapelessRecipeEntry.of(recipe)); + } + } + + return recipes; + } + + public Collection getShapedRecipeEntries() { + List recipes = new ArrayList<>(); + for (net.minecraft.world.item.crafting.RecipeHolder recipe : serverRecipeManager.getRecipes()) { + if (recipe.value() instanceof net.minecraft.world.item.crafting.ShapedRecipe) { + recipes.add(ShapedRecipeEntry.of(recipe)); + } + } + + return recipes; + } + + public Collection getNormalRecipeEntries() { + List recipes = new ArrayList<>(); + for (net.minecraft.world.item.crafting.RecipeHolder recipe : serverRecipeManager.getRecipes()) { + if (recipe.value() instanceof net.minecraft.world.item.crafting.ShapelessRecipe) { + recipes.add(ShapelessRecipeEntry.of(recipe)); + } else if (recipe.value() instanceof net.minecraft.world.item.crafting.ShapedRecipe) { + recipes.add(ShapedRecipeEntry.of(recipe)); + } + } + + return recipes; + } + + public Collection getRecipes() { + List recipes = new ArrayList<>(); + for (net.minecraft.world.item.crafting.RecipeHolder recipe : serverRecipeManager.getRecipes()) { + recipes.add(Recipe.of(recipe.value())); + } + + return recipes; + } + + public Collection getCraftingRecipes() { + List recipes = new ArrayList<>(); + for (net.minecraft.world.item.crafting.RecipeHolder recipe : serverRecipeManager.getRecipes()) { + if (recipe.value() instanceof net.minecraft.world.item.crafting.CraftingRecipe) { + recipes.add(CraftingRecipe.of((net.minecraft.world.item.crafting.CraftingRecipe) recipe.value())); + } + } + + return recipes; + } + + public Collection getShapelessRecipes() { + List recipes = new ArrayList<>(); + for (net.minecraft.world.item.crafting.RecipeHolder recipe : serverRecipeManager.getRecipes()) { + if (recipe.value() instanceof net.minecraft.world.item.crafting.ShapelessRecipe) { + recipes.add(ShapelessRecipe.of((net.minecraft.world.item.crafting.ShapelessRecipe) recipe.value())); + } + } + + return recipes; + } + + public Collection getShapedRecipes() { + List recipes = new ArrayList<>(); + for (net.minecraft.world.item.crafting.RecipeHolder recipe : serverRecipeManager.getRecipes()) { + if (recipe.value() instanceof net.minecraft.world.item.crafting.ShapedRecipe) { + recipes.add(ShapedRecipe.of((net.minecraft.world.item.crafting.ShapedRecipe) recipe.value())); + } + } + + return recipes; + } + + public Collection getNormalRecipes() { + List recipes = new ArrayList<>(); + for (net.minecraft.world.item.crafting.RecipeHolder recipe : serverRecipeManager.getRecipes()) { + if (recipe.value() instanceof net.minecraft.world.item.crafting.ShapelessRecipe) { + recipes.add(ShapelessRecipe.of((net.minecraft.world.item.crafting.ShapelessRecipe) recipe.value())); + } else if (recipe.value() instanceof net.minecraft.world.item.crafting.ShapedRecipe) { + recipes.add(ShapedRecipe.of((net.minecraft.world.item.crafting.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..789f4e20b --- /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.level.Level; +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.world.item.crafting.ShapedRecipe recipe; + + protected ShapedRecipe(net.minecraft.world.item.crafting.ShapedRecipe recipe) { + super(null); + this.recipe = recipe; + } + + public static ShapedRecipe of(net.minecraft.world.item.crafting.ShapedRecipe recipe) { + return new ShapedRecipe(recipe); + } + + public net.minecraft.world.item.crafting.ShapedRecipe getRaw() { + return recipe; + } + + public net.minecraft.world.item.crafting.ShapedRecipe toMinecraft() { + return getRaw(); + } + + public boolean matches(CraftingRecipeInputOrInventory input) { + return getRaw().matches(input.getRaw(), null); + } + + @Deprecated + public net.minecraft.world.item.ItemStack craft() { + return getRaw().assemble(null); + } + + public net.minecraft.world.item.ItemStack craft(CompatRegistryLookup registryLookup) { + return getRaw().assemble(null); + } + + public net.minecraft.world.item.ItemStack craft(Level world) { + return getRaw().assemble(null); + } + + public net.minecraft.world.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..af065075b --- /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.level.Level; +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.world.item.crafting.ShapelessRecipe recipe; + + protected ShapelessRecipe(net.minecraft.world.item.crafting.ShapelessRecipe recipe) { + super(null); + this.recipe = recipe; + } + + public static ShapelessRecipe of(net.minecraft.world.item.crafting.ShapelessRecipe recipe) { + return new ShapelessRecipe(recipe); + } + + public net.minecraft.world.item.crafting.ShapelessRecipe getRaw() { + return recipe; + } + + public net.minecraft.world.item.crafting.ShapelessRecipe toMinecraft() { + return getRaw(); + } + + public boolean matches(CraftingRecipeInputOrInventory input) { + return getRaw().matches(input.getRaw(), null); + } + + @Deprecated + public net.minecraft.world.item.ItemStack craft() { + return getRaw().assemble(null); + } + + public net.minecraft.world.item.ItemStack craft(CompatRegistryLookup registryLookup) { + return getRaw().assemble(null); + } + + public net.minecraft.world.item.ItemStack craft(Level world) { + return getRaw().assemble(null); + } + + public net.minecraft.world.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..748e712a1 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/recipe/entry/CraftingRecipeEntry.java @@ -0,0 +1,55 @@ +package net.pitan76.mcpitanlib.midohra.recipe.entry; + +import net.minecraft.world.item.crafting.Recipe; +import net.minecraft.resources.ResourceKey; +import net.minecraft.core.registries.Registries; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.midohra.recipe.CraftingRecipe; + +public class CraftingRecipeEntry extends RecipeEntry { + private final net.minecraft.world.item.crafting.RecipeHolder recipeEntry; + + protected CraftingRecipeEntry(net.minecraft.world.item.crafting.RecipeHolder recipeEntry) { + super(null); + this.recipeEntry = recipeEntry; + } + + public static CraftingRecipeEntry _of(net.minecraft.world.item.crafting.RecipeHolder recipeEntry) { + return new CraftingRecipeEntry(recipeEntry); + } + + public static CraftingRecipeEntry of(net.minecraft.world.item.crafting.RecipeHolder recipeEntry) { + return _of((net.minecraft.world.item.crafting.RecipeHolder) recipeEntry); + } + + public static CraftingRecipeEntry of(net.minecraft.world.item.crafting.CraftingRecipe recipe, CompatIdentifier id) { + ResourceKey> key = ResourceKey.create(Registries.RECIPE, id.toMinecraft()); + net.minecraft.world.item.crafting.RecipeHolder recipeEntry = new net.minecraft.world.item.crafting.RecipeHolder<>(key, recipe); + + return of(recipeEntry); + } + + public static CraftingRecipeEntry of(CraftingRecipe recipe, CompatIdentifier id) { + return of(recipe.toMinecraft(), id); + } + + @Override + public net.minecraft.world.item.crafting.RecipeHolder getRaw() { + return recipeEntry; + } + + @Override + public net.minecraft.world.item.crafting.RecipeHolder toMinecraft() { + return getRaw(); + } + + @Override + public CraftingRecipe getRecipe() { + return CraftingRecipe.of(getRawRecipe()); + } + + @Override + public net.minecraft.world.item.crafting.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..598f807dd --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/recipe/entry/RecipeEntry.java @@ -0,0 +1,87 @@ +package net.pitan76.mcpitanlib.midohra.recipe.entry; + +import net.minecraft.resources.ResourceKey; +import net.minecraft.core.registries.Registries; +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.world.item.crafting.RecipeHolder recipeEntry; + + protected RecipeEntry(net.minecraft.world.item.crafting.RecipeHolder recipeEntry) { + this.recipeEntry = recipeEntry; + } + + public static RecipeEntry of(net.minecraft.world.item.crafting.RecipeHolder recipeEntry) { + return new RecipeEntry(recipeEntry); + } + + public static RecipeEntry of(net.minecraft.world.item.crafting.Recipe recipe, CompatIdentifier id) { + ResourceKey> key = ResourceKey.create(Registries.RECIPE, id.toMinecraft()); + net.minecraft.world.item.crafting.RecipeHolder recipeEntry = new net.minecraft.world.item.crafting.RecipeHolder<>(key, recipe); + return of(recipeEntry); + } + + public static RecipeEntry of(Recipe recipe, CompatIdentifier id) { + return of(recipe.toMinecraft(), id); + } + + public static CraftingRecipeEntry of(net.minecraft.world.item.crafting.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.world.item.crafting.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.world.item.crafting.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.world.item.crafting.RecipeHolder getRaw() { + return recipeEntry; + } + + public net.minecraft.world.item.crafting.RecipeHolder toMinecraft() { + return getRaw(); + } + + public CompatIdentifier getId() { + return CompatIdentifier.fromMinecraft(getRaw().id().identifier()); + } + + public CompatRecipeEntry toCompatRecipeEntry() { + return new CompatRecipeEntry(getRaw()); + } + + public net.minecraft.world.item.crafting.Recipe getRawRecipe() { + return getRaw().value(); + } + + public Recipe getRecipe() { + return Recipe.of(getRaw().value()); + } + + public RecipeType getRecipeType() { + return RecipeType.of(getRawRecipeType()); + } + + public net.minecraft.world.item.crafting.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..31ab60c23 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/recipe/entry/ShapedRecipeEntry.java @@ -0,0 +1,55 @@ +package net.pitan76.mcpitanlib.midohra.recipe.entry; + +import net.minecraft.world.item.crafting.Recipe; +import net.minecraft.resources.ResourceKey; +import net.minecraft.core.registries.Registries; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.midohra.recipe.ShapedRecipe; + +public class ShapedRecipeEntry extends RecipeEntry { + private final net.minecraft.world.item.crafting.RecipeHolder recipeEntry; + + protected ShapedRecipeEntry(net.minecraft.world.item.crafting.RecipeHolder recipeEntry) { + super(null); + this.recipeEntry = recipeEntry; + } + + public static ShapedRecipeEntry _of(net.minecraft.world.item.crafting.RecipeHolder recipeEntry) { + return new ShapedRecipeEntry(recipeEntry); + } + + public static ShapedRecipeEntry of(net.minecraft.world.item.crafting.RecipeHolder recipeEntry) { + return _of((net.minecraft.world.item.crafting.RecipeHolder) recipeEntry); + } + + public static ShapedRecipeEntry of(net.minecraft.world.item.crafting.ShapedRecipe recipe, CompatIdentifier id) { + ResourceKey> key = ResourceKey.create(Registries.RECIPE, id.toMinecraft()); + net.minecraft.world.item.crafting.RecipeHolder recipeEntry = new net.minecraft.world.item.crafting.RecipeHolder<>(key, recipe); + + return of(recipeEntry); + } + + public static ShapedRecipeEntry of(ShapedRecipe recipe, CompatIdentifier id) { + return of(recipe.toMinecraft(), id); + } + + @Override + public net.minecraft.world.item.crafting.RecipeHolder getRaw() { + return recipeEntry; + } + + @Override + public net.minecraft.world.item.crafting.RecipeHolder toMinecraft() { + return getRaw(); + } + + @Override + public ShapedRecipe getRecipe() { + return ShapedRecipe.of(getRawRecipe()); + } + + @Override + public net.minecraft.world.item.crafting.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..51f459565 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/recipe/entry/ShapelessRecipeEntry.java @@ -0,0 +1,55 @@ +package net.pitan76.mcpitanlib.midohra.recipe.entry; + +import net.minecraft.world.item.crafting.Recipe; +import net.minecraft.resources.ResourceKey; +import net.minecraft.core.registries.Registries; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.midohra.recipe.ShapelessRecipe; + +public class ShapelessRecipeEntry extends RecipeEntry { + private final net.minecraft.world.item.crafting.RecipeHolder recipeEntry; + + protected ShapelessRecipeEntry(net.minecraft.world.item.crafting.RecipeHolder recipeEntry) { + super(null); + this.recipeEntry = recipeEntry; + } + + public static ShapelessRecipeEntry _of(net.minecraft.world.item.crafting.RecipeHolder recipeEntry) { + return new ShapelessRecipeEntry(recipeEntry); + } + + public static ShapelessRecipeEntry of(net.minecraft.world.item.crafting.RecipeHolder recipeEntry) { + return _of((net.minecraft.world.item.crafting.RecipeHolder) recipeEntry); + } + + public static ShapelessRecipeEntry of(net.minecraft.world.item.crafting.ShapelessRecipe recipe, CompatIdentifier id) { + ResourceKey> key = ResourceKey.create(Registries.RECIPE, id.toMinecraft()); + net.minecraft.world.item.crafting.RecipeHolder recipeEntry = new net.minecraft.world.item.crafting.RecipeHolder<>(key, recipe); + + return of(recipeEntry); + } + + public static ShapelessRecipeEntry of(ShapelessRecipe recipe, CompatIdentifier id) { + return of(recipe.toMinecraft(), id); + } + + @Override + public net.minecraft.world.item.crafting.RecipeHolder getRaw() { + return recipeEntry; + } + + @Override + public net.minecraft.world.item.crafting.RecipeHolder toMinecraft() { + return getRaw(); + } + + @Override + public ShapelessRecipe getRecipe() { + return ShapelessRecipe.of(getRawRecipe()); + } + + @Override + public net.minecraft.world.item.crafting.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..cc72d67bf --- /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.world.inventory.TransientCraftingContainer; +import net.minecraft.world.Container; +import net.minecraft.world.item.crafting.CraftingInput; +import org.jetbrains.annotations.Nullable; + +public class CraftingRecipeInputOrInventory extends RecipeInputOrInventory { + private final CraftingInput recipeInput; + private TransientCraftingContainer inventory = null; + + public static CraftingRecipeInputOrInventory EMPTY = new CraftingRecipeInputOrInventory(CraftingInput.EMPTY); + + protected CraftingRecipeInputOrInventory(CraftingInput recipeInput) { + super(null); + this.recipeInput = recipeInput; + } + + protected CraftingRecipeInputOrInventory(TransientCraftingContainer inventory) { + super(null); + this.recipeInput = inventory.asCraftInput(); + this.inventory = inventory; + } + + public static CraftingRecipeInputOrInventory of(CraftingInput recipeInput) { + return new CraftingRecipeInputOrInventory(recipeInput); + } + + public static CraftingRecipeInputOrInventory of(Container inventory) { + if (inventory instanceof CraftingInput) { + return of((CraftingInput) inventory); + } + + return EMPTY; + } + + public static CraftingRecipeInputOrInventory of(TransientCraftingContainer inventory) { + return new CraftingRecipeInputOrInventory(inventory); + } + + @Nullable + @Override + public CraftingInput getRaw() { + return recipeInput; + } + + @Nullable + @Override + public CraftingInput toMinecraft() { + return getRaw(); + } + + @Nullable + @Override + public CraftingInput getRecipeInput() { + return getRaw(); + } + + @Nullable + @Override + public Container 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..f90bd635d --- /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.world.Container; +import net.minecraft.world.item.crafting.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(Container 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 Container getInventory() { + if (getRaw() instanceof Container) { + return (Container) getRaw(); + } + + return null; + } + + public boolean isNone() { + return getRaw() == null; + } + + public int size() { + if (isNone()) return 0; + + return getRaw().size(); + } + + public boolean isEmpty() { + if (isNone()) return true; + + return getRaw().isEmpty(); + } + + public net.minecraft.world.item.ItemStack getStack(int slot) { + if (isNone()) return net.minecraft.world.item.ItemStack.EMPTY; + + return getRaw().getItem(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..a928b371d --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/recipe/input/TypedRecipeInputOrInventory.java @@ -0,0 +1,83 @@ +package net.pitan76.mcpitanlib.midohra.recipe.input; + +import net.minecraft.recipe.input.CraftingRecipeInput; +import net.minecraft.recipe.input.RecipeInput; +import net.minecraft.recipe.input.SingleStackRecipeInput; +import net.minecraft.world.Container; +import net.minecraft.world.item.crafting.RecipeInput; +import net.pitan76.mcpitanlib.api.util.inventory.CompatInventory; +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(CompatInventory recipeInput) { + if (recipeInput instanceof RecipeInput) { + return _of((T) recipeInput); + } + + if (recipeInput.callSize() == 1) { + SingleStackRecipeInput singleStackInput = new SingleStackRecipeInput(recipeInput.getItem(0)); + return _of((T) singleStackInput); + } + + if (recipeInput.callSize() == 4) { + CraftingRecipeInput craftingInput = CraftingRecipeInput.create(2, 2, recipeInput.callGetHeldStacks()); + return _of((T) craftingInput); + } + + if (recipeInput.callSize() == 9) { + CraftingRecipeInput craftingInput = CraftingRecipeInput.create(3, 3, recipeInput.callGetHeldStacks()); + return _of((T) craftingInput); + } + + return new TypedRecipeInputOrInventory<>(null); + } + + public static TypedRecipeInputOrInventory of(Container 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 Container getInventory() { + if (getRaw() instanceof Container) { + return (Container) getRaw(); + } + + return null; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/registry/MidohraRegistry.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/registry/MidohraRegistry.java new file mode 100644 index 000000000..a8887d00f --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/registry/MidohraRegistry.java @@ -0,0 +1,175 @@ +package net.pitan76.mcpitanlib.midohra.registry; + +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.item.Item; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.pitan76.mcpitanlib.api.block.v2.CompatBlock; +import net.pitan76.mcpitanlib.api.entity.CompatEntity; +import net.pitan76.mcpitanlib.api.entity.EntityTypeBuilder; +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.registry.result.RegistryResult; +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.tile.CompatBlockEntity; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.api.util.item.ItemUtil; +import net.pitan76.mcpitanlib.midohra.block.BlockWrapper; +import net.pitan76.mcpitanlib.midohra.block.SupplierBlockWrapper; +import net.pitan76.mcpitanlib.midohra.block.SupplierTypedBlockWrapper; +import net.pitan76.mcpitanlib.midohra.block.TypedBlockWrapper; +import net.pitan76.mcpitanlib.midohra.block.entity.BlockEntityTypeWrapper; +import net.pitan76.mcpitanlib.midohra.block.entity.SupplierBlockEntityTypeWrapper; +import net.pitan76.mcpitanlib.midohra.block.entity.SupplierTypedBlockEntityTypeWrapper; +import net.pitan76.mcpitanlib.midohra.block.entity.TypedBlockEntityTypeWrapper; +import net.pitan76.mcpitanlib.midohra.entity.EntityTypeWrapper; +import net.pitan76.mcpitanlib.midohra.entity.SupplierEntityTypeWrapper; +import net.pitan76.mcpitanlib.midohra.entity.SupplierTypedEntityTypeWrapper; +import net.pitan76.mcpitanlib.midohra.entity.TypedEntityTypeWrapper; +import net.pitan76.mcpitanlib.midohra.item.ItemWrapper; +import net.pitan76.mcpitanlib.midohra.item.SupplierItemWrapper; +import net.pitan76.mcpitanlib.midohra.item.SupplierTypedItemWrapper; +import net.pitan76.mcpitanlib.midohra.item.TypedItemWrapper; + +import java.util.function.Supplier; + +public class MidohraRegistry { + protected final CompatRegistryV2 registry; + + public MidohraRegistry(CompatRegistryV2 registry) { + this.registry = registry; + } + + public static MidohraRegistry of(CompatRegistryV2 registry) { + return new MidohraRegistry(registry); + } + + public CompatRegistryV2 getCompatRegistry() { + return registry; + } + + public ItemWrapper registerRawItem(CompatIdentifier id, Supplier supplier) { + RegistryResult result = registry.registerItem(id, supplier); + return SupplierItemWrapper.of(result); + } + + public ItemWrapper registerRawItem(String id, Supplier supplier) { + return registerRawItem(fixId(id), supplier); + } + + public TypedItemWrapper registerItem(CompatIdentifier id, Supplier supplier) { + ItemWrapper wrapper = registerRawItem(id, supplier::get); + return SupplierTypedItemWrapper.of(wrapper); + } + + public TypedItemWrapper registerItem(String id, Supplier supplier) { + return registerItem(fixId(id), supplier); + } + + public BlockWrapper registerRawBlock(CompatIdentifier id, Supplier supplier) { + RegistryResult result = registry.registerBlock(id, supplier); + return SupplierBlockWrapper.of(result); + } + + public BlockWrapper registerRawBlock(String id, Supplier supplier) { + return registerRawBlock(fixId(id), supplier); + } + + public TypedBlockWrapper registerBlock(CompatIdentifier id, Supplier supplier) { + BlockWrapper wrapper = registerRawBlock(id, supplier::get); + return SupplierTypedBlockWrapper.of(wrapper); + } + + public TypedBlockWrapper registerBlock(String id, Supplier supplier) { + return registerBlock(fixId(id), supplier); + } + + public BlockEntityTypeWrapper registerRawBlockEntityType(CompatIdentifier id, Supplier> supplier) { + RegistryResult> result = registry.registerBlockEntityType(id, supplier); + return SupplierBlockEntityTypeWrapper.of(result); + } + + public BlockEntityTypeWrapper registerRawBlockEntityType(String id, Supplier> supplier) { + return registerRawBlockEntityType(fixId(id), supplier); + } + + public BlockEntityTypeWrapper registerRawBlockEntityType(CompatIdentifier id, BlockEntityTypeBuilder builder) { + SupplierResult> result = registry.registerBlockEntityType(id, builder); + return SupplierBlockEntityTypeWrapper.of(result::get); + } + + public BlockEntityTypeWrapper registerRawBlockEntityType(String id, BlockEntityTypeBuilder builder) { + return registerRawBlockEntityType(fixId(id), builder); + } + + public TypedBlockEntityTypeWrapper registerBlockEntityType(CompatIdentifier id, BlockEntityTypeBuilder builder) { + BlockEntityTypeWrapper wrapper = registerRawBlockEntityType(id, builder); + return SupplierTypedBlockEntityTypeWrapper.of(() -> (BlockEntityType) wrapper.get()); + } + + public EntityTypeWrapper registerRawEntityType(CompatIdentifier id, Supplier> supplier) { + RegistryResult> result = registry.registerEntity(id, supplier); + return SupplierEntityTypeWrapper.of(result); + } + + public EntityTypeWrapper registerRawEntityType(String id, Supplier> supplier) { + return registerRawEntityType(fixId(id), supplier); + } + + public EntityTypeWrapper registerRawEntityType(CompatIdentifier id, EntityTypeBuilder builder) { + RegistryResult> result = registry.registerEntity(id, () -> builder.build()); + return SupplierEntityTypeWrapper.of(result::get); + } + + public EntityTypeWrapper registerRawEntityType(String id, EntityTypeBuilder builder) { + return registerRawEntityType(fixId(id), builder); + } + + public TypedEntityTypeWrapper registerEntityType(CompatIdentifier id, EntityTypeBuilder builder) { + EntityTypeWrapper wrapper = registerRawEntityType(id, builder); + return SupplierTypedEntityTypeWrapper.of(() -> (EntityType) wrapper.get()); + } + + public TypedEntityTypeWrapper registerEntityType(String id, EntityTypeBuilder builder) { + return registerEntityType(fixId(id), builder); + } + + public ItemWrapper registerRawBlockItem(CompatIdentifier id, Supplier block, CompatibleItemSettings settings) { + return registerRawItem(id, () -> ItemUtil.create(block.get(), settings)); + } + + public ItemWrapper registerRawBlockItem(CompatIdentifier id, Supplier block, ItemSettingsBuilder builder) { + return registerRawBlockItem(id, block, builder.build(id)); + } + + public ItemWrapper registerBlockItem(CompatIdentifier id, BlockWrapper block, CompatibleItemSettings settings) { + return registerRawBlockItem(id, block::get, settings); + } + + public ItemWrapper registerBlockItem(CompatIdentifier id, BlockWrapper block, ItemSettingsBuilder builder) { + return registerBlockItem(id, block, builder.build(id)); + } + + public ItemWrapper registerBlockItem(String id, BlockWrapper block, CompatibleItemSettings settings) { + return registerBlockItem(fixId(id), block, settings); + } + + public ItemWrapper registerBlockItem(String id, BlockWrapper block, ItemSettingsBuilder builder) { + return registerBlockItem(fixId(id), block, builder); + } + + /** + * If the id doesn't contain a namespace, add the default namespace to it. + * @param id The id to fix. + * @return The fixed id. + */ + public CompatIdentifier fixId(String id) { + if (!id.contains(":")) { + id = registry.cr1.getNamespace() + ":" + id; + } + return CompatIdentifier.of(id); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/registry/MidohraRegistryV2.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/registry/MidohraRegistryV2.java new file mode 100644 index 000000000..cfd0b0892 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/registry/MidohraRegistryV2.java @@ -0,0 +1,187 @@ +package net.pitan76.mcpitanlib.midohra.registry; + +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.Item; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.pitan76.mcpitanlib.api.block.ICompatBlock; +import net.pitan76.mcpitanlib.api.entity.CompatEntity; +import net.pitan76.mcpitanlib.api.entity.EntityTypeBuilder; +import net.pitan76.mcpitanlib.api.gui.ExtendedScreenHandlerTypeBuilder; +import net.pitan76.mcpitanlib.api.gui.SimpleScreenHandlerTypeBuilder; +import net.pitan76.mcpitanlib.api.item.ICompatItem; +import net.pitan76.mcpitanlib.api.item.v2.CompatibleItemSettings; +import net.pitan76.mcpitanlib.api.item.v2.ItemSettingsBuilder; +import net.pitan76.mcpitanlib.api.registry.v2.CompatRegistryV2; +import net.pitan76.mcpitanlib.api.tile.BlockEntityTypeBuilder; +import net.pitan76.mcpitanlib.api.tile.CompatBlockEntity; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.midohra.block.*; +import net.pitan76.mcpitanlib.midohra.block.entity.BlockEntityTypeWrapper; +import net.pitan76.mcpitanlib.midohra.block.entity.SupplierTypedBlockEntityTypeWrapper; +import net.pitan76.mcpitanlib.midohra.entity.EntityTypeWrapper; +import net.pitan76.mcpitanlib.midohra.entity.SupplierTypedEntityTypeWrapper; +import net.pitan76.mcpitanlib.midohra.item.*; +import net.pitan76.mcpitanlib.midohra.screen.SupplierTypedScreenHandlerTypeWrapper; + +import java.util.function.Supplier; + +public class MidohraRegistryV2 { + protected final MidohraRegistry registry; + + public MidohraRegistryV2(MidohraRegistry registry) { + this.registry = registry; + } + + public MidohraRegistryV2(CompatRegistryV2 registry) { + this(MidohraRegistry.of(registry)); + } + + public static MidohraRegistryV2 of(CompatRegistryV2 registry) { + return new MidohraRegistryV2(registry); + } + + public MidohraRegistry getMidohraRegistryV1() { + return registry; + } + + public CompatRegistryV2 getCompatRegistry() { + return getMidohraRegistryV1().getCompatRegistry(); + } + + public ItemWrapper registerRawItem(CompatIdentifier id, Supplier supplier) { + return registry.registerRawItem(id, supplier); + } + + public ItemWrapper registerRawItem(String id, Supplier supplier) { + return registry.registerRawItem(id, supplier); + } + + public SupplierITypedItemWrapper registerItem(CompatIdentifier id, Supplier supplier) { + ItemWrapper wrapper = registerRawItem(id, () -> (Item) supplier.get()); + return SupplierITypedItemWrapper.of(wrapper); + } + + public SupplierITypedItemWrapper registerItem(String id, Supplier supplier) { + return registerItem(fixId(id), supplier); + } + + public BlockWrapper registerRawBlock(CompatIdentifier id, Supplier supplier) { + return registry.registerRawBlock(id, supplier); + } + + public BlockWrapper registerRawBlock(String id, Supplier supplier) { + return registry.registerRawBlock(id, supplier); + } + + public SupplierITypedBlockWrapper registerBlock(CompatIdentifier id, Supplier supplier) { + BlockWrapper wrapper = registerRawBlock(id, () -> (Block) supplier.get()); + return SupplierITypedBlockWrapper.of(wrapper); + } + + public SupplierITypedBlockWrapper registerBlock(String id, Supplier supplier) { + return registerBlock(fixId(id), supplier); + } + + public BlockEntityTypeWrapper registerRawBlockEntityType(CompatIdentifier id, Supplier> supplier) { + return registry.registerRawBlockEntityType(id, supplier); + } + + public BlockEntityTypeWrapper registerRawBlockEntityType(String id, Supplier> supplier) { + return registry.registerRawBlockEntityType(id, supplier); + } + + public BlockEntityTypeWrapper registerRawBlockEntityType(CompatIdentifier id, BlockEntityTypeBuilder builder) { + return registry.registerRawBlockEntityType(id, builder); + } + + public BlockEntityTypeWrapper registerRawBlockEntityType(String id, BlockEntityTypeBuilder builder) { + return registry.registerRawBlockEntityType(id, builder); + } + + public SupplierTypedBlockEntityTypeWrapper registerBlockEntityType0(CompatIdentifier id, BlockEntityTypeBuilder builder) { + BlockEntityTypeWrapper wrapper = registerRawBlockEntityType(id, builder); + return SupplierTypedBlockEntityTypeWrapper.of(() -> (BlockEntityType) wrapper.get()); + } + + public EntityTypeWrapper registerRawEntityType(CompatIdentifier id, Supplier> supplier) { + return registry.registerRawEntityType(id, supplier); + } + + public EntityTypeWrapper registerRawEntityType(String id, Supplier> supplier) { + return registry.registerRawEntityType(id, supplier); + } + + public EntityTypeWrapper registerRawEntityType(CompatIdentifier id, EntityTypeBuilder builder) { + return registry.registerRawEntityType(id, builder); + } + + public EntityTypeWrapper registerRawEntityType(String id, EntityTypeBuilder builder) { + return registry.registerRawEntityType(id, builder); + } + + public SupplierTypedEntityTypeWrapper registerEntityType0(CompatIdentifier id, EntityTypeBuilder builder) { + EntityTypeWrapper wrapper = registerRawEntityType(id, builder); + return SupplierTypedEntityTypeWrapper.of(() -> (EntityType) wrapper.get()); + } + + public SupplierTypedEntityTypeWrapper registerEntityType0(String id, EntityTypeBuilder builder) { + return registerEntityType0(fixId(id), builder); + } + + public ItemWrapper registerRawBlockItem(CompatIdentifier id, Supplier block, CompatibleItemSettings settings) { + return registry.registerRawBlockItem(id, block, settings); + } + + public ItemWrapper registerRawBlockItem(CompatIdentifier id, Supplier block, ItemSettingsBuilder builder) { + return registry.registerRawBlockItem(id, block, builder); + } + + public SupplierTypedBlockItemWrapper registerBlockItem(CompatIdentifier id, BlockWrapper block, CompatibleItemSettings settings) { + return SupplierTypedBlockItemWrapper.of(registerRawBlockItem(id, block::get, settings)); + } + + public SupplierTypedBlockItemWrapper registerBlockItem(CompatIdentifier id, BlockWrapper block, ItemSettingsBuilder builder) { + return registerBlockItem(id, block, builder.build(id)); + } + + public SupplierTypedBlockItemWrapper registerBlockItem(String id, BlockWrapper block, CompatibleItemSettings settings) { + return registerBlockItem(fixId(id), block, settings); + } + + public SupplierTypedBlockItemWrapper registerBlockItem(String id, BlockWrapper block, ItemSettingsBuilder builder) { + return registerBlockItem(fixId(id), block, builder); + } + + public SupplierTypedScreenHandlerTypeWrapper registerRawScreenHandlerType(CompatIdentifier id, Supplier> supplier) { + Supplier> result = getCompatRegistry().registerScreenHandlerTypeSavingGenerics(id, supplier); + return SupplierTypedScreenHandlerTypeWrapper.of(result); + } + + public SupplierTypedScreenHandlerTypeWrapper registerScreenHandlerType(CompatIdentifier id, SimpleScreenHandlerTypeBuilder builder) { + return registerRawScreenHandlerType(id, builder::build); + } + + public SupplierTypedScreenHandlerTypeWrapper registerScreenHandlerType(CompatIdentifier id, ExtendedScreenHandlerTypeBuilder builder) { + return registerRawScreenHandlerType(id, builder::build); + } + + public SupplierTypedScreenHandlerTypeWrapper registerScreenHandlerType(String id, SimpleScreenHandlerTypeBuilder builder) { + return registerScreenHandlerType(fixId(id), builder); + } + + public SupplierTypedScreenHandlerTypeWrapper registerScreenHandlerType(String id, ExtendedScreenHandlerTypeBuilder builder) { + return registerScreenHandlerType(fixId(id), builder); + } + + /** + * If the id doesn't contain a namespace, add the default namespace to it. + * @param id The id to fix. + * @return The fixed id. + */ + public CompatIdentifier fixId(String id) { + return registry.fixId(id); + } +} 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..6647b30f3 --- /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.server.packs.resources.Resource resource; + + protected Resource(net.minecraft.server.packs.resources.Resource resource) { + this.resource = resource; + } + + public static Resource of(net.minecraft.server.packs.resources.Resource resource) { + return new Resource(resource); + } + + public net.minecraft.server.packs.resources.Resource getRaw() { + return resource; + } + + public net.minecraft.server.packs.resources.Resource toMinecraft() { + return getRaw(); + } + + public BufferedReader getReader() throws IOException { + return resource.openAsReader(); + } + + public String getPackId() { + return resource.sourcePackId(); + } + + 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..47867b74c --- /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.Minecraft; +import net.minecraft.resources.Identifier; +import net.minecraft.world.level.LevelAccessor; +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.server.packs.resources.ResourceManager resourceManager; + + protected ResourceManager(net.minecraft.server.packs.resources.ResourceManager resourceManager) { + this.resourceManager = resourceManager; + } + + public static ResourceManager of(net.minecraft.server.packs.resources.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(Minecraft client) { + return of(client.getResourceManager()); + } + + public static ResourceManager of(LevelAccessor worldAccess) { + return of(worldAccess.getServer()); + } + + public static ResourceManager of(net.pitan76.mcpitanlib.midohra.world.WorldAccess worldAccess) { + return of(worldAccess.getServer()); + } + + public net.minecraft.server.packs.resources.ResourceManager getRaw() { + return resourceManager; + } + + public net.minecraft.server.packs.resources.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.getResourceStack(id.toMinecraft()) + .stream().map(Resource::of).toList(); + } + +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/screen/ScreenHandlerTypeWrapper.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/screen/ScreenHandlerTypeWrapper.java new file mode 100644 index 000000000..7ddb2288b --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/screen/ScreenHandlerTypeWrapper.java @@ -0,0 +1,63 @@ +package net.pitan76.mcpitanlib.midohra.screen; + +import net.pitan76.mcpitanlib.api.util.inventory.CompatPlayerInventory; + +public class ScreenHandlerTypeWrapper { + private final net.minecraft.world.inventory.MenuType type; + + public static final ScreenHandlerTypeWrapper EMPTY = new ScreenHandlerTypeWrapper(); + + protected ScreenHandlerTypeWrapper() { + this.type = null; + } + + protected ScreenHandlerTypeWrapper(net.minecraft.world.inventory.MenuType screenHandlerType) { + this.type = screenHandlerType; + } + + public static ScreenHandlerTypeWrapper of(net.minecraft.world.inventory.MenuType screenHandlerType) { + return new ScreenHandlerTypeWrapper(screenHandlerType); + } + + public static ScreenHandlerTypeWrapper of() { + return EMPTY; + } + + public net.minecraft.world.inventory.MenuType get() { + return type; + } + + public boolean isEmpty() { + return get() == null; + } + + public boolean isPresent() { + return get() != null; + } + + public ScreenHandlerWrapper createScreenHandler(int syncId, net.minecraft.world.entity.player.Inventory playerInventory) { + if (isEmpty()) return ScreenHandlerWrapper.EMPTY; + return ScreenHandlerWrapper.of(get().create(syncId, playerInventory)); + } + + public ScreenHandlerWrapper createScreenHandler(int syncId, CompatPlayerInventory playerInventory) { + return createScreenHandler(syncId, playerInventory.getRaw()); + } + + @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; + + ScreenHandlerTypeWrapper other = (ScreenHandlerTypeWrapper) obj; + if (isEmpty() && other.isEmpty()) return true; + if (isEmpty() || other.isEmpty()) return false; + + return get().equals(other.get()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/screen/ScreenHandlerWrapper.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/screen/ScreenHandlerWrapper.java new file mode 100644 index 000000000..1f771e5d6 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/screen/ScreenHandlerWrapper.java @@ -0,0 +1,121 @@ +package net.pitan76.mcpitanlib.midohra.screen; + +import net.pitan76.mcpitanlib.api.gui.SimpleScreenHandler; +import net.pitan76.mcpitanlib.api.util.ScreenHandlerUtil; +import net.pitan76.mcpitanlib.api.util.collection.ItemStackList; +import net.pitan76.mcpitanlib.midohra.item.ItemStack; + +import java.util.Optional; + +public class ScreenHandlerWrapper { + private final net.minecraft.world.inventory.AbstractContainerMenu screenHandler; + + public static final ScreenHandlerWrapper EMPTY = new ScreenHandlerWrapper(); + + protected ScreenHandlerWrapper() { + this.screenHandler = null; + } + + protected ScreenHandlerWrapper(net.minecraft.world.inventory.AbstractContainerMenu screenHandler) { + this.screenHandler = screenHandler; + } + + public static ScreenHandlerWrapper of(net.minecraft.world.inventory.AbstractContainerMenu screenHandler) { + return new ScreenHandlerWrapper(screenHandler); + } + + public static ScreenHandlerWrapper of() { + return EMPTY; + } + + public net.minecraft.world.inventory.AbstractContainerMenu get() { + return screenHandler; + } + + public ItemStackList getStacks() { + return ItemStackList.of(get().getItems()); + } + + public ItemStack getCursorStack() { + return ScreenHandlerUtil.getCursorStackM(get()); + } + + public void setCursorStack(ItemStack stack) { + ScreenHandlerUtil.setCursorStackM(get(), stack); + } + + public boolean isPresent() { + return get() != null; + } + + public boolean isEmpty() { + return get() == null; + } + + public int getSyncId() { + if (isEmpty()) return -1; + return get().containerId; + } + + @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; + + ScreenHandlerWrapper other = (ScreenHandlerWrapper) obj; + if (isEmpty() && other.isEmpty()) return true; + if (isEmpty() || other.isEmpty()) return false; + + return get().equals(other.get()); + } + + public ScreenHandlerTypeWrapper getType() { + if (isEmpty()) return ScreenHandlerTypeWrapper.EMPTY; + return ScreenHandlerTypeWrapper.of(get().getType()); + } + + /** + * instanceof check for the screen handler of this wrapper. + * @param clazz the class of the screen handler to check + * @return true if the screen handler of this wrapper is an instance of the given class, false otherwise + */ + public boolean instanceOf(Class clazz) { + if (isEmpty()) return false; + + return clazz.isInstance(get()); + } + + /** + * instanceof check for the screen handler of this wrapper. + * @param wrapper the screen handler to check + * @return true if the screen handler of this wrapper is an instance of the given screen handler, false otherwise + */ + public boolean instanceOf(ScreenHandlerWrapper wrapper) { + if (isEmpty()) return false; + + ScreenHandlerWrapper other = wrapper; + if (other.isEmpty()) return false; + + Class clazz = other.get().getClass(); + return clazz.isInstance(get()); + } + + public T getSimpleScreenHandler(Class clazz) { + if (isEmpty()) return null; + if (get() instanceof SimpleScreenHandler) { + SimpleScreenHandler screenHandler = (SimpleScreenHandler) get(); + if (clazz.isInstance(screenHandler)) + return clazz.cast(screenHandler); + } + return null; + } + + public Optional toSimpleScreenHandler(Class clazz) { + return Optional.ofNullable(getSimpleScreenHandler(clazz)); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/screen/SupplierScreenHandlerTypeWrapper.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/screen/SupplierScreenHandlerTypeWrapper.java new file mode 100644 index 000000000..58254e2d1 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/screen/SupplierScreenHandlerTypeWrapper.java @@ -0,0 +1,38 @@ +package net.pitan76.mcpitanlib.midohra.screen; + +import net.minecraft.world.inventory.MenuType; +import net.pitan76.mcpitanlib.api.registry.result.RegistryResult; +import net.pitan76.mcpitanlib.api.registry.result.RegistrySupplier; +import net.pitan76.mcpitanlib.midohra.core.INonTypedSupplier; + +import java.util.function.Supplier; + +public class SupplierScreenHandlerTypeWrapper extends ScreenHandlerTypeWrapper implements INonTypedSupplier { + private final Supplier> supplier; + + protected SupplierScreenHandlerTypeWrapper(Supplier> supplier) { + this.supplier = supplier; + } + + public static SupplierScreenHandlerTypeWrapper of(Supplier> supplier) { + return new SupplierScreenHandlerTypeWrapper(supplier); + } + + public static SupplierScreenHandlerTypeWrapper of(RegistryResult> result) { + return new SupplierScreenHandlerTypeWrapper(result::get); + } + + public static SupplierScreenHandlerTypeWrapper of(RegistrySupplier> result) { + return new SupplierScreenHandlerTypeWrapper(result::get); + } + + @Override + public SupplierScreenHandlerTypeWrapper asNonTyped() { + return this; + } + + @Override + public MenuType get() { + return supplier.get(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/screen/SupplierTypedScreenHandlerTypeWrapper.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/screen/SupplierTypedScreenHandlerTypeWrapper.java new file mode 100644 index 000000000..2e33fc97c --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/screen/SupplierTypedScreenHandlerTypeWrapper.java @@ -0,0 +1,44 @@ +package net.pitan76.mcpitanlib.midohra.screen; + +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.MenuType; +import net.pitan76.mcpitanlib.api.registry.result.RegistryResult; +import net.pitan76.mcpitanlib.api.registry.result.RegistrySupplier; +import net.pitan76.mcpitanlib.midohra.core.INonTypedSupplier; + +import java.util.function.Supplier; + +public class SupplierTypedScreenHandlerTypeWrapper extends TypedScreenHandlerTypeWrapper implements INonTypedSupplier { + private final Supplier> supplier; + + protected SupplierTypedScreenHandlerTypeWrapper(Supplier> supplier) { + super(null); + this.supplier = supplier; + } + + public static SupplierTypedScreenHandlerTypeWrapper of(Supplier> supplier) { + return new SupplierTypedScreenHandlerTypeWrapper<>(supplier); + } + + public static SupplierTypedScreenHandlerTypeWrapper of(RegistryResult> result) { + return new SupplierTypedScreenHandlerTypeWrapper<>(result::get); + } + + public static SupplierTypedScreenHandlerTypeWrapper of(RegistrySupplier> result) { + return new SupplierTypedScreenHandlerTypeWrapper<>(result::get); + } + + public static SupplierTypedScreenHandlerTypeWrapper of(SupplierScreenHandlerTypeWrapper wrapper) { + return new SupplierTypedScreenHandlerTypeWrapper<>(() -> (MenuType) wrapper.get()); + } + + @Override + public SupplierScreenHandlerTypeWrapper asNonTyped() { + return SupplierScreenHandlerTypeWrapper.of(this::get); + } + + @Override + public MenuType get() { + return supplier.get(); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/screen/TypedScreenHandlerTypeWrapper.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/screen/TypedScreenHandlerTypeWrapper.java new file mode 100644 index 000000000..417b1c475 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/screen/TypedScreenHandlerTypeWrapper.java @@ -0,0 +1,33 @@ +package net.pitan76.mcpitanlib.midohra.screen; + +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.MenuType; +import net.pitan76.mcpitanlib.api.util.inventory.CompatPlayerInventory; + +public class TypedScreenHandlerTypeWrapper extends ScreenHandlerTypeWrapper { + protected TypedScreenHandlerTypeWrapper(MenuType type) { + super(type); + } + + public static TypedScreenHandlerTypeWrapper ofRaw(MenuType type) { + return new TypedScreenHandlerTypeWrapper<>(type); + } + + public static TypedScreenHandlerTypeWrapper of(ScreenHandlerTypeWrapper wrapper) { + if (wrapper instanceof SupplierScreenHandlerTypeWrapper) { + SupplierScreenHandlerTypeWrapper supplierWrapper = (SupplierScreenHandlerTypeWrapper) wrapper; + return SupplierTypedScreenHandlerTypeWrapper.of(supplierWrapper); + } + + return new TypedScreenHandlerTypeWrapper<>((MenuType) wrapper.get()); + } + + @Override + public MenuType get() { + return (MenuType) super.get(); + } + + public T create(int syncId, CompatPlayerInventory playerInventory) { + return get().create(syncId, playerInventory.getRaw()); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/screen/TypedScreenHandlerWrapper.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/screen/TypedScreenHandlerWrapper.java new file mode 100644 index 000000000..45fce9826 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/screen/TypedScreenHandlerWrapper.java @@ -0,0 +1,17 @@ +package net.pitan76.mcpitanlib.midohra.screen; + +import net.minecraft.world.inventory.AbstractContainerMenu; + +public class TypedScreenHandlerWrapper extends ScreenHandlerWrapper { + protected TypedScreenHandlerWrapper(T screenHandler) { + super(screenHandler); + } + + public static TypedScreenHandlerWrapper ofRaw(T screenHandler) { + return new TypedScreenHandlerWrapper<>(screenHandler); + } + + public static TypedScreenHandlerWrapper of(ScreenHandlerWrapper wrapper) { + return new TypedScreenHandlerWrapper<>((T) wrapper.get()); + } +} 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..a724371af --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/server/MCServer.java @@ -0,0 +1,102 @@ +package net.pitan76.mcpitanlib.midohra.server; + +import net.minecraft.server.MinecraftServer; +import net.pitan76.mcpitanlib.api.util.CompatIdentifier; +import net.pitan76.mcpitanlib.api.util.PersistentStateUtil; +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.PersistentStateManager; +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); + } + + public PersistentStateManager getPersistentStateManager() { + return PersistentStateManager.of(PersistentStateUtil.getManagerFromServer(server)); + } +} 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..2a48fb11a --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/server/PlayerManager.java @@ -0,0 +1,151 @@ +package net.pitan76.mcpitanlib.midohra.server; + +import net.minecraft.server.players.IpBanList; +import net.minecraft.server.players.UserBanList; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.players.UserWhiteList; +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.players.PlayerList playerManager; + + protected PlayerManager(net.minecraft.server.players.PlayerList playerManager) { + this.playerManager = playerManager; + } + + public static PlayerManager of(net.minecraft.server.players.PlayerList playerManager) { + return new PlayerManager(playerManager); + } + + public static PlayerManager of(MinecraftServer server) { + return of(server.getPlayerList()); + } + + 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.players.PlayerList getRaw() { + return playerManager; + } + + public net.minecraft.server.players.PlayerList toMinecraft() { + return getRaw(); + } + + public void broadcast(TextComponent message, boolean overlay) { + getRaw().broadcastSystemMessage(message.getText(), overlay); + } + + public void broadcast(TextComponent message) { + broadcast(message, false); + } + + public void broadcast(String message, boolean overlay) { + getRaw().broadcastSystemMessage(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().getPlayerByName(name)); + } + + public List getPlayersByIP(String ip) { + List players = new ArrayList<>(); + for (net.minecraft.world.entity.player.Player p: getRaw().getPlayersWithAddress(ip)) { + players.add(new Player(p)); + } + return players; + } + + public List getPlayers() { + List players = new ArrayList<>(); + for (net.minecraft.world.entity.player.Player p : getRaw().getPlayers()) { + players.add(new Player(p)); + } + return players; + } + + public boolean isExistByUUID(UUID uuid) { + return getRaw().getPlayer(uuid) != null; + } + + public boolean isExistByName(String name) { + return getRaw().getPlayerByName(name) != null; + } + + public boolean isExistByIP(String ip) { + return !getRaw().getPlayersWithAddress(ip).isEmpty(); + } + + public boolean hasPlayerByUUID(UUID uuid) { + return getRaw().getPlayer(uuid) != null; + } + + public boolean hasPlayerByName(String name) { + return getRaw().getPlayerByName(name) != null; + } + + public boolean hasPlayerByIP(String ip) { + return !getRaw().getPlayersWithAddress(ip).isEmpty(); + } + + public int getCurrentPlayerCount() { + return getRaw().getPlayerCount(); + } + + public int getMaxPlayerCount() { + return getRaw().getMaxPlayers(); + } + + public boolean isWhitelistEnabled() { + return getRaw().isUsingWhitelist(); + } + + public void setWhitelistEnabled(boolean enabled) { + getRaw().getServer().setUsingWhitelist(enabled); + } + + public UserWhiteList getWhitelist() { + return getRaw().getWhiteList(); + } + + public void reloadWhitelist() { + getRaw().reloadWhiteList(); + } + + public IpBanList getBannedIpList() { + return getRaw().getIpBans(); + } + + public UserBanList getBannedPlayerList() { + return getRaw().getBans(); + } +} 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..12fc38dbb --- /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.core.BlockPos; +import net.minecraft.core.Direction; + +public class BlockHitResult extends HitResult { + public BlockHitResult(net.minecraft.world.phys.BlockHitResult raw) { + super(raw); + } + + public static BlockHitResult of(net.minecraft.world.phys.BlockHitResult raw) { + return new BlockHitResult(raw); + } + + @Deprecated + public net.minecraft.world.phys.BlockHitResult getRaw() { + return (net.minecraft.world.phys.BlockHitResult) super.getRaw(); + } + + public net.minecraft.world.phys.BlockHitResult withSide(Direction side) { + return getRaw().withDirection(side); + } + + public net.minecraft.world.phys.BlockHitResult withBlockPos(BlockPos blockPos) { + return getRaw().withPosition(blockPos); + } + + public net.minecraft.world.phys.BlockHitResult againstWorldBorder() { + return getRaw().hitBorder(); + } + + 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().getDirection(); + } + + public net.pitan76.mcpitanlib.midohra.util.math.Direction getSideM() { + return net.pitan76.mcpitanlib.midohra.util.math.Direction.of(getSide()); + } + + public boolean isInsideBlock() { + return getRaw().isInside(); + } + + public boolean isAgainstWorldBorder() { + return getRaw().isWorldBorderHit(); + } + + 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..49641cc6e --- /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.world.entity.Entity; +import net.minecraft.world.phys.Vec3; + +import java.util.Optional; + +public class HitResult { + protected final net.minecraft.world.phys.HitResult raw; + + public HitResult(net.minecraft.world.phys.HitResult raw) { + this.raw = raw; + } + + public static HitResult of(net.minecraft.world.phys.HitResult raw) { + return new HitResult(raw); + } + + @Deprecated + public net.minecraft.world.phys.HitResult getRaw() { + return raw; + } + + @Deprecated + public net.minecraft.world.phys.HitResult.Type getRawType() { + return getRaw().getType(); + } + + public Vec3 getPos() { + return getRaw().getLocation(); + } + + 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(Vec3 point) { + Vec3 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().distanceTo(entity); + } + + public Vec3 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.world.phys.BlockHitResult) { + return Optional.of(BlockHitResult.of((net.minecraft.world.phys.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..71b989306 --- /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.world.phys.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..25751d2a0 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/util/math/BlockPos.java @@ -0,0 +1,194 @@ +package net.pitan76.mcpitanlib.midohra.util.math; + +import net.minecraft.core.Vec3i; + +import java.util.Iterator; + +public class BlockPos { + private final net.minecraft.core.BlockPos blockPos; + + protected BlockPos(net.minecraft.core.BlockPos blockPos) { + this.blockPos = blockPos; + } + + public static BlockPos of(net.minecraft.core.BlockPos blockPos) { + return new BlockPos(blockPos); + } + + public static BlockPos of(int x, int y, int z) { + return new BlockPos(new net.minecraft.core.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.core.BlockPos toMinecraft() { + return blockPos; + } + + public net.minecraft.core.BlockPos toRaw() { + return toMinecraft(); + } + + public BlockPos add(int x, int y, int z) { + return new BlockPos(blockPos.offset(x, y, z)); + } + + public BlockPos add(BlockPos pos) { + return new BlockPos(blockPos.offset(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.above()); + } + + public BlockPos down() { + return new BlockPos(blockPos.below()); + } + + 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.relative(direction.toMinecraft(), amount)); + } + + public BlockPos offset(Direction direction) { + return new BlockPos(blockPos.relative(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 Iterable iterate(BlockPos start, BlockPos end) { + return () -> new Iterator<>() { + private final Iterator rawIterator = net.minecraft.core.BlockPos.betweenClosed(start.toRaw(), end.toRaw()).iterator(); + + @Override + public boolean hasNext() { + return rawIterator.hasNext(); + } + + @Override + public BlockPos next() { + return new BlockPos(rawIterator.next()); + } + }; + } + + public long asLong() { + return blockPos.asLong(); + } + + public Vector3i toVector3i() { + return new Vector3i(getX(), getY(), getZ()); + } + + public Vector3d toVector3d() { + return new Vector3d(getX(), getY(), getZ()); + } + + public Vector3d toCenterVector3d() { + return new Vector3d(getX() + 0.5, getY() + 0.5, getZ() + 0.5); + } + + public int getManhattanDistance(Vector3i other) { + return blockPos.distManhattan(other.toMinecraft()); + } + + public int getManhattanDistance(BlockPos other) { + return blockPos.distManhattan(other.toMinecraft()); + } + + public BlockPos up(int n) { + return new BlockPos(blockPos.above(n)); + } + + public BlockPos down(int n) { + return new BlockPos(blockPos.below(n)); + } + + public BlockPos north(int n) { + return new BlockPos(blockPos.north(n)); + } + + public BlockPos south(int n) { + return new BlockPos(blockPos.south(n)); + } + + public BlockPos east(int n) { + return new BlockPos(blockPos.east(n)); + } + + public BlockPos west(int n) { + return new BlockPos(blockPos.west(n)); + } + + public BlockPos[] getAllFaces() { + return new BlockPos[] { + up(), down(), north(), south(), east(), west() + }; + } + + public BlockPos[] getAllFaces(int n) { + return new BlockPos[] { + up(n), down(n), north(n), south(n), east(n), west(n) + }; + } + + public BlockPos[] getVerticalFaces() { + return new BlockPos[] { + up(), down() + }; + } + + public BlockPos[] getHorizontalFaces() { + return new BlockPos[] { + north(), south(), east(), west() + }; + } +} \ 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..e677902d8 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/util/math/Box.java @@ -0,0 +1,153 @@ +package net.pitan76.mcpitanlib.midohra.util.math; + +import net.minecraft.world.phys.Vec3; +import net.pitan76.mcpitanlib.api.util.math.BoxUtil; + +public class Box { + protected final net.minecraft.world.phys.AABB box; + + @Deprecated + public Box(net.minecraft.world.phys.AABB box) { + this.box = box; + } + + @Deprecated + public net.minecraft.world.phys.AABB 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() { + Vec3 center = box.getCenter(); + return new Vector3d(center.x, center.y, center.z); + } + + public double getLengthX() { + return box.getXsize(); + } + + public double getLengthY() { + return box.getYsize(); + } + + public double getLengthZ() { + return box.getZsize(); + } + + @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); + } + + public BlockPos getMinPos() { + return BlockPos.of((int) box.minX, (int) box.minY, (int) box.minZ); + } + + public BlockPos getMaxPos() { + return BlockPos.of((int) box.maxX, (int) box.maxY, (int) box.maxZ); + } + + public Vector3i getMinVector() { + return new Vector3i((int) box.minX, (int) box.minY, (int) box.minZ); + } + + public Vector3i getMaxVector() { + return new Vector3i((int) box.maxX, (int) box.maxY, (int) box.maxZ); + } + + public Box(Vector3d center, double sizeX, double sizeY, double sizeZ) { + this(center.getX() - sizeX / 2, center.getY() - sizeY / 2, center.getZ() - sizeZ / 2, + center.getX() + sizeX / 2, center.getY() + sizeY / 2, center.getZ() + sizeZ / 2); + } + + public Box(Vector3d center, double size) { + this(center, size, size, size); + } +} 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..da874f08d --- /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.world.level.ChunkPos pos; + + protected ChunkPos(net.minecraft.world.level.ChunkPos pos) { + this.pos = pos; + } + + public static ChunkPos of(net.minecraft.world.level.ChunkPos pos) { + return new ChunkPos(pos); + } + + public static ChunkPos of(int x, int z) { + return of(new net.minecraft.world.level.ChunkPos(x, z)); + } + + public static ChunkPos of(BlockPos pos) { + return of(net.minecraft.world.level.ChunkPos.containing(pos.toMinecraft())); + } + + public static ChunkPos of(long pos) { + return of(net.minecraft.world.level.ChunkPos.unpack(pos)); + } + + public static ChunkPos fromRegion(int x, int z) { + return of(net.minecraft.world.level.ChunkPos.minFromRegion(x, z)); + } + + public static ChunkPos fromRegionCenter(int x, int z) { + return of(net.minecraft.world.level.ChunkPos.maxFromRegion(x, z)); + } + + public net.minecraft.world.level.ChunkPos getRaw() { + return pos; + } + + public net.minecraft.world.level.ChunkPos toMinecraft() { + return getRaw(); + } + + public int getX() { + return getRaw().x(); + } + + public int getZ() { + return getRaw().z(); + } + + public int getOffsetX(int offsetX) { + return getRaw().getBlockX(offsetX); + } + + public int getOffsetZ(int offsetZ) { + return getRaw().getBlockZ(offsetZ); + } + + public int getStartX() { + return getRaw().getMinBlockX(); + } + + public int getStartZ() { + return getRaw().getMinBlockZ(); + } + + public int getEndX() { + return getRaw().getMaxBlockX(); + } + + public int getEndZ() { + return getRaw().getMaxBlockZ(); + } + + public int getCenterX() { + return getRaw().getMiddleBlockX(); + } + + public int getCenterZ() { + return getRaw().getMiddleBlockZ(); + } + + public int getRegionX() { + return getRaw().getRegionX(); + } + + public int getRegionZ() { + return getRaw().getRegionZ(); + } + + public int getRegionRelativeX() { + return getRaw().getRegionLocalX(); + } + + public int getRegionRelativeZ() { + return getRaw().getRegionLocalZ(); + } + + public BlockPos getStartPos() { + return BlockPos.of(getRaw().getWorldPosition()); + } + + public BlockPos getCenterAtY(int y) { + return BlockPos.of(getRaw().getMiddleBlockPosition(y)); + } + + public BlockPos getBlockPos(int offsetX, int y, int offsetZ) { + return BlockPos.of(getRaw().getBlockAt(offsetX, y, offsetZ)); + } + + public long toLong() { + return getRaw().pack(); + } + + @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().getChessboardDistance(pos.getRaw()); + } + + public int getChebyshevDistance(int x, int z) { + return getRaw().getChessboardDistance(x, z); + } + + public int getSquaredDistance(ChunkPos pos) { + return getRaw().distanceSquared(pos.getRaw()); + } + + public int getSquaredDistance(long pos) { + return getRaw().distanceSquared(pos); + } + + public static Stream stream(ChunkPos center, int radius) { + return net.minecraft.world.level.ChunkPos.rangeClosed(center.getRaw(), radius).map(ChunkPos::of); + } + + public static Stream stream(final ChunkPos pos1, final ChunkPos pos2) { + return net.minecraft.world.level.ChunkPos.rangeClosed(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..a90798a79 --- /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.core.Direction.UP); + public static final Direction DOWN = new Direction(net.minecraft.core.Direction.DOWN); + public static final Direction NORTH = new Direction(net.minecraft.core.Direction.NORTH); + public static final Direction SOUTH = new Direction(net.minecraft.core.Direction.SOUTH); + public static final Direction EAST = new Direction(net.minecraft.core.Direction.EAST); + public static final Direction WEST = new Direction(net.minecraft.core.Direction.WEST); + + private final net.minecraft.core.Direction direction; + + protected Direction(net.minecraft.core.Direction direction) { + this.direction = direction; + } + + public static Direction of(net.minecraft.core.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.core.Direction getRaw() { + return direction; + } + + public net.minecraft.core.Direction toMinecraft() { + return getRaw(); + } + + public boolean isHorizontal() { + return getRaw().getAxis().isHorizontal(); + } + + public boolean isVertical() { + return getRaw().getAxis().isVertical(); + } + + public boolean isPositive() { + return getRaw().getAxisDirection() == net.minecraft.core.Direction.AxisDirection.POSITIVE; + } + + public boolean isNegative() { + return getRaw().getAxisDirection() == net.minecraft.core.Direction.AxisDirection.NEGATIVE; + } + + public int getOffsetX() { + return getRaw().getStepX(); + } + + public int getOffsetY() { + return getRaw().getStepY(); + } + + public int getOffsetZ() { + return getRaw().getStepZ(); + } + + public Direction rotateYClockwise() { + return of(getRaw().getClockWise()); + } + + public Direction rotateYCounterclockwise() { + return of(getRaw().getCounterClockWise()); + } + + @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..3bb26399c --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/util/math/Vector3d.java @@ -0,0 +1,223 @@ +package net.pitan76.mcpitanlib.midohra.util.math; + +import net.minecraft.core.Position; +import net.minecraft.world.phys.Vec3; + +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(Vec3 vec) { + return new Vector3d(vec.x, vec.y, vec.z); + } + + public static Vector3d of(Position vec) { + return new Vector3d(vec.x(), vec.y(), vec.z()); + } + + 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 Vec3 toMinecraft() { + return new Vec3(x, y, z); + } + + public Vector3d mul(Vector3d other) { + return new Vector3d(this.x * other.x, this.y * other.y, this.z * other.z); + } + + public Vector3d mul(double x, double y, double z) { + return new Vector3d(this.x * x, this.y * y, this.z * z); + } + + public Vector3d div(Vector3d other) { + return new Vector3d(this.x / other.x, this.y / other.y, this.z / other.z); + } + + public Vector3d div(double x, double y, double z) { + return new Vector3d(this.x / x, this.y / y, this.z / z); + } + + public Vector3d mod(Vector3d other) { + return new Vector3d(this.x % other.x, this.y % other.y, this.z % other.z); + } + + public Vector3d mod(double x, double y, double z) { + return new Vector3d(this.x % x, this.y % y, this.z % z); + } + + public Vector3d floor() { + return new Vector3d(Math.floor(x), Math.floor(y), Math.floor(z)); + } + + public long asLong() { + return ((long) x & 0xFFFFFFFFL) << 32 | ((long) y & 0xFFFFFFFFL) << 16 | ((long) z & 0xFFFFFFFFL); + } +} 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..aa4b530c5 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/util/math/Vector3f.java @@ -0,0 +1,212 @@ +package net.pitan76.mcpitanlib.midohra.util.math; + +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); + } + + public Vector3f mul(Vector3f other) { + return new Vector3f(this.x * other.x, this.y * other.y, this.z * other.z); + } + + public Vector3f mul(float x, float y, float z) { + return new Vector3f(this.x * x, this.y * y, this.z * z); + } + + public Vector3f div(Vector3f other) { + return new Vector3f(this.x / other.x, this.y / other.y, this.z / other.z); + } + + public Vector3f div(float x, float y, float z) { + return new Vector3f(this.x / x, this.y / y, this.z / z); + } + + public Vector3f mod(Vector3f other) { + return new Vector3f(this.x % other.x, this.y % other.y, this.z % other.z); + } + + public Vector3f mod(float x, float y, float z) { + return new Vector3f(this.x % x, this.y % y, this.z % z); + } + + public Vector3f floor() { + return new Vector3f((float) Math.floor(x), (float) Math.floor(y), (float) Math.floor(z)); + } + + public long asLong() { + return ((long) x & 0xFFFFFFFFL) << 32 | ((long) y & 0xFFFFFFFFL) << 16 | ((long) z & 0xFFFFFFFFL); + } +} 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..62e41843f --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/util/math/Vector3i.java @@ -0,0 +1,231 @@ +package net.pitan76.mcpitanlib.midohra.util.math; + +import net.minecraft.core.BlockPos; +import net.minecraft.core.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); + } + + public Vector3i mul(Vector3i other) { + return new Vector3i(this.x * other.x, this.y * other.y, this.z * other.z); + } + + public Vector3i mul(int x, int y, int z) { + return new Vector3i(this.x * x, this.y * y, this.z * z); + } + + public Vector3i div(Vector3i other) { + return new Vector3i(this.x / other.x, this.y / other.y, this.z / other.z); + } + + public Vector3i div(int x, int y, int z) { + return new Vector3i(this.x / x, this.y / y, this.z / z); + } + + public Vector3i mod(Vector3i other) { + return new Vector3i(this.x % other.x, this.y % other.y, this.z % other.z); + } + + public Vector3i mod(int x, int y, int z) { + return new Vector3i(this.x % x, this.y % y, this.z % z); + } + + public long asLong() { + return ((long) x & 0xFFFFFFFFL) << 32 | ((long) y & 0xFFFFFFFFL) << 16 | ((long) z & 0xFFFFFFFFL); + } + + public net.pitan76.mcpitanlib.midohra.util.math.BlockPos toPos() { + return net.pitan76.mcpitanlib.midohra.util.math.BlockPos.of(x, y, z); + } + + public Vector3d toCenter() { + return new Vector3d(x + 0.5, y + 0.5, z + 0.5); + } +} 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..e257acbe9 --- /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.core.Vec3i; +import net.pitan76.mcpitanlib.midohra.util.math.Direction; + +public class BlockPos extends net.minecraft.core.BlockPos { + private final net.minecraft.core.BlockPos blockPos; + + protected BlockPos(net.minecraft.core.BlockPos blockPos) { + super(blockPos.getX(), blockPos.getY(), blockPos.getZ()); + this.blockPos = blockPos; + } + + public static BlockPos of(net.minecraft.core.BlockPos blockPos) { + return new BlockPos(blockPos); + } + + public static BlockPos of(int x, int y, int z) { + return new BlockPos(new net.minecraft.core.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.core.BlockPos toMinecraft() { + return blockPos; + } + + public BlockPos offset(int x, int y, int z) { + return new BlockPos(blockPos.offset(x, y, z)); + } + + public BlockPos add(BlockPos pos) { + return new BlockPos(blockPos.offset(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 above() { + return new BlockPos(blockPos.above()); + } + + public BlockPos below() { + return new BlockPos(blockPos.below()); + } + + 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.relative(direction.toMinecraft(), amount)); + } + + public BlockPos offset(Direction direction) { + return new BlockPos(blockPos.relative(direction.toMinecraft())); + } + + @Override + public BlockPos offset(Vec3i vec3i) { + return new BlockPos(blockPos.offset(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..0a91e3000 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/util/shape/VoxelShape.java @@ -0,0 +1,102 @@ +package net.pitan76.mcpitanlib.midohra.util.shape; + +import net.pitan76.mcpitanlib.api.util.VoxelShapeUtil; +import net.pitan76.mcpitanlib.midohra.util.math.Box; +import net.pitan76.mcpitanlib.midohra.util.math.Direction; + +public class VoxelShape { + private final net.minecraft.world.phys.shapes.VoxelShape voxelShape; + + public static final VoxelShape EMPTY = of(net.minecraft.world.phys.shapes.Shapes.empty()); + public static final VoxelShape FULL_CUBE = of(net.minecraft.world.phys.shapes.Shapes.block()); + + public VoxelShape(net.minecraft.world.phys.shapes.VoxelShape voxelShape) { + this.voxelShape = voxelShape; + } + + public static VoxelShape of(net.minecraft.world.phys.shapes.VoxelShape shape) { + return new VoxelShape(shape); + } + + @Deprecated + public net.minecraft.world.phys.shapes.VoxelShape raw() { + return voxelShape; + } + + public boolean isEmpty() { + return raw().isEmpty(); + } + + public VoxelShape union(VoxelShape other) { + return of(net.minecraft.world.phys.shapes.Shapes.or(this.raw(), other.raw())); + } + + public VoxelShape asCuboid() { + return of(raw().singleEncompassing()); + } + + public VoxelShape offset(double x, double y, double z) { + return of(raw().move(x, y, z)); + } + + public VoxelShape getFace(Direction direction) { + return of(raw().getFaceShape(direction.toMinecraft())); + } + + public VoxelShape simplify() { + return of(raw().optimize()); + } + + @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.world.phys.shapes.VoxelShape result = net.minecraft.world.phys.shapes.Shapes.empty(); + for (VoxelShape shape : shapes) { + result = net.minecraft.world.phys.shapes.Shapes.or(result, shape.raw()); + } + return of(result); + } + + public static VoxelShape cuboid(double x1, double y1, double z1, double x2, double y2, double z2) { + return of(VoxelShapeUtil.cuboid(x1, y1, z1, x2, y2, z2)); + } + + public static VoxelShape cuboid(double size) { + return of(VoxelShapeUtil.cuboid(size)); + } + + public static VoxelShape cuboid(double x1, double y1, double z1, double size) { + return of(VoxelShapeUtil.cuboid(x1, y1, z1, size)); + } + + public static VoxelShape centeredCuboid(double x, double y, double z, double size) { + return of(VoxelShapeUtil.centeredCuboid(x, y, z, size)); + } + + public static VoxelShape blockCuboid(double x1, double y1, double z1, double x2, double y2, double z2) { + return of(VoxelShapeUtil.blockCuboid(x1, y1, z1, x2, y2, z2)); + } + + public Box getBoundingBox() { + return new Box(VoxelShapeUtil.getBoundingBox(raw())); + } +} 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..c069c243c --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/world/BlockView.java @@ -0,0 +1,46 @@ +package net.pitan76.mcpitanlib.midohra.world; + +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.material.FluidState; +import net.minecraft.core.BlockPos; + +public class BlockView implements IWorldView { + private net.minecraft.world.level.BlockGetter blockView; + + public BlockView(net.minecraft.world.level.BlockGetter blockView) { + this.blockView = blockView; + } + + public static BlockView of(net.minecraft.world.level.BlockGetter blockView) { + return new BlockView(blockView); + } + + public net.minecraft.world.level.BlockGetter getRaw() { + return blockView; + } + + public net.minecraft.world.level.BlockGetter 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); + } + + @Override + public boolean isNull() { + return getRaw() == null; + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/world/CompatPersistentState.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/world/CompatPersistentState.java new file mode 100644 index 000000000..a0cfd79fc --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/world/CompatPersistentState.java @@ -0,0 +1,28 @@ +package net.pitan76.mcpitanlib.midohra.world; + +import net.minecraft.nbt.CompoundTag; +import net.pitan76.mcpitanlib.api.event.nbt.WriteNbtArgs; +import net.pitan76.mcpitanlib.api.world.CompatiblePersistentState; +import net.pitan76.mcpitanlib.midohra.nbt.NbtCompound; + +public abstract class CompatPersistentState extends CompatiblePersistentState { + + @Deprecated + public CompatPersistentState() { + super(); + } + + public CompatPersistentState(String name) { + super(name); + } + + @Deprecated + @Override + public CompoundTag writeNbt(WriteNbtArgs args) { + return writeNbtM(args).toMinecraft(); + } + + public NbtCompound writeNbtM(WriteNbtArgs args) { + return null; + } +} 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..952fcb064 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/world/IWorldView.java @@ -0,0 +1,34 @@ +package net.pitan76.mcpitanlib.midohra.world; + +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.material.FluidState; +import net.minecraft.core.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()).getType()); + } + + default net.pitan76.mcpitanlib.midohra.fluid.FluidState getFluidState(net.pitan76.mcpitanlib.midohra.util.math.BlockPos pos) { + return net.pitan76.mcpitanlib.midohra.fluid.FluidState.of(getFluidState(pos.toMinecraft())); + } + + boolean isNull(); +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/world/PersistentStateManager.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/world/PersistentStateManager.java new file mode 100644 index 000000000..e20d25922 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/world/PersistentStateManager.java @@ -0,0 +1,47 @@ +package net.pitan76.mcpitanlib.midohra.world; + +import net.minecraft.world.level.storage.SavedDataStorage; +import net.pitan76.mcpitanlib.api.util.PersistentStateUtil; +import net.pitan76.mcpitanlib.api.world.CompatiblePersistentState; +import net.pitan76.mcpitanlib.midohra.nbt.NbtCompound; + +import java.util.function.Function; +import java.util.function.Supplier; + +public class PersistentStateManager { + private final net.minecraft.world.level.storage.SavedDataStorage raw; + + public PersistentStateManager(net.minecraft.world.level.storage.SavedDataStorage storage) { + this.raw = storage; + } + + public static PersistentStateManager of(net.minecraft.world.level.storage.SavedDataStorage storage) { + return new PersistentStateManager(storage); + } + + public SavedDataStorage getRaw() { + return raw; + } + + @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; + PersistentStateManager other = (PersistentStateManager) obj; + return getRaw().equals(other.getRaw()); + } + + public T getOrCreateCompatiblePersistentState(String id, Supplier supplier, Function function) { + return PersistentStateUtil.getOrCreate(getRaw(), id, supplier, (nbt) -> function.apply(NbtCompound.of(nbt))); + } + + public PersistentStateWrapper getOrCreate(String id, Supplier supplier, Function function) { + return PersistentStateWrapper.of( + PersistentStateUtil.getOrCreate(getRaw(), id, () -> supplier.get().getRaw() , (nbt) -> function.apply(NbtCompound.of(nbt)).getRaw())); + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/world/PersistentStateWrapper.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/world/PersistentStateWrapper.java new file mode 100644 index 000000000..d86c6181b --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/world/PersistentStateWrapper.java @@ -0,0 +1,44 @@ +package net.pitan76.mcpitanlib.midohra.world; + +public class PersistentStateWrapper { + private final net.minecraft.world.level.saveddata.SavedData raw; + + protected PersistentStateWrapper(net.minecraft.world.level.saveddata.SavedData raw) { + this.raw = raw; + } + + public static PersistentStateWrapper of(net.minecraft.world.level.saveddata.SavedData persistentState) { + return new PersistentStateWrapper(persistentState); + } + + public net.minecraft.world.level.saveddata.SavedData getRaw() { + return raw; + } + + @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; + + PersistentStateWrapper that = (PersistentStateWrapper) obj; + + return getRaw() != null ? getRaw().equals(that.getRaw()) : that.getRaw() == null; + } + + public void markDirty() { + getRaw().setDirty(); + } + + public void setDirty(boolean dirty) { + getRaw().setDirty(dirty); + } + + public boolean isDirty() { + return getRaw().isDirty(); + } +} 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..a3ce10bee --- /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.level.SignalGetter getRedstoneView(); + + default boolean isReceivingRedstonePower(BlockPos pos) { + return getRedstoneView().hasNeighborSignal(pos.toMinecraft()); + } + + default int getEmittedRedstonePower(BlockPos pos, Direction direction) { + return getRedstoneView().getSignal(pos.toMinecraft(), direction.toMinecraft()); + } + + default int getEmittedRedstonePower(BlockPos pos, Direction direction, boolean onlyFromGate) { + return getRedstoneView().getControlInputSignal(pos.toMinecraft(), direction.toMinecraft(), onlyFromGate); + } + + default boolean isEmittingRedstonePower(BlockPos pos, Direction direction) { + return getRedstoneView().hasSignal(pos.toMinecraft(), direction.toMinecraft()); + } + + default int getStrongRedstonePower(BlockPos pos, Direction direction) { + return getRedstoneView().getDirectSignal(pos.toMinecraft(), direction.toMinecraft()); + } + + default int getReceivedStrongRedstonePower(BlockPos pos) { + return getRedstoneView().getDirectSignalTo(pos.toMinecraft()); + } + + static RedstoneView of(net.minecraft.world.level.SignalGetter redstoneView) { + return () -> redstoneView; + } + + static RedstoneView of(net.minecraft.world.level.LevelReader 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..5310000b3 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/world/ServerWorld.java @@ -0,0 +1,101 @@ +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.api.util.WorldUtil; +import net.pitan76.mcpitanlib.api.util.world.ServerWorldUtil; +import net.pitan76.mcpitanlib.midohra.block.BlockState; +import net.pitan76.mcpitanlib.midohra.block.entity.BlockEntityWrapper; +import net.pitan76.mcpitanlib.midohra.entity.EntityWrapper; +import net.pitan76.mcpitanlib.midohra.item.ItemStack; +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.util.math.ChunkPos; +import net.pitan76.mcpitanlib.midohra.world.chunk.ChunkTicketType; +import net.pitan76.mcpitanlib.midohra.world.chunk.ServerChunkManager; +import org.jetbrains.annotations.Nullable; + +import java.util.List; +import java.util.stream.Collectors; + +public class ServerWorld extends World { + private final net.minecraft.server.level.ServerLevel world; + + protected ServerWorld(net.minecraft.server.level.ServerLevel world) { + super(null); + this.world = world; + } + + public static ServerWorld of(net.minecraft.server.level.ServerLevel world) { + return new ServerWorld(world); + } + + @Override + public net.minecraft.server.level.ServerLevel getRaw() { + return world; + } + + @Override + public net.minecraft.server.level.ServerLevel toMinecraft() { + return getRaw(); + } + + public void playSound(Player player, BlockPos pos, CompatSoundEvent sound, CompatSoundCategory category, float volume, float pitch, long seed) { + getRaw().playSeededSound(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().playSeededSound(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); + } + + public void addTicket(ChunkTicketType type, ChunkPos pos, int radius) { + WorldUtil.addTicket(getRaw(), type, pos.getRaw(), radius); + } + + public void removeTicket(ChunkTicketType type, ChunkPos pos, int radius) { + WorldUtil.removeTicket(getRaw(), type, pos.getRaw(), radius); + } + + public PersistentStateManager getPersistentStateManager() { + return getChunkManager().getPersistentStateManager(); + } + + public List getDroppedStacksOnBlock(BlockState state, BlockPos pos, @Nullable BlockEntityWrapper blockEntity) { + return ServerWorldUtil.getDroppedStacksOnBlock(state.toMinecraft(), getRaw(), pos.toMinecraft(), blockEntity) + .stream().map(ItemStack::of).collect(Collectors.toList()); + } + + public List getDroppedStacksOnBlock(BlockState state, BlockPos pos) { + return getDroppedStacksOnBlock(state, pos, null); + } + + public List getDroppedStacksOnBlock(BlockState state, BlockPos pos, @Nullable BlockEntityWrapper blockEntity, @Nullable EntityWrapper entity, ItemStack stack) { + return ServerWorldUtil.getDroppedStacksOnBlock(state.toMinecraft(), getRaw(), pos.toMinecraft(), blockEntity == null ? null : blockEntity.get(), entity == null ? null : entity.get(), stack.toMinecraft()) + .stream().map(ItemStack::of).collect(Collectors.toList()); + } +} 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..94e27d00b --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/world/World.java @@ -0,0 +1,227 @@ +package net.pitan76.mcpitanlib.midohra.world; + +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.level.material.FluidState; +import net.minecraft.sounds.SoundSource; +import net.minecraft.sounds.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.api.util.particle.CompatParticleType; +import net.pitan76.mcpitanlib.api.util.particle.effect.CompatParticleEffect; +import net.pitan76.mcpitanlib.midohra.block.entity.BlockEntityWrapper; +import net.pitan76.mcpitanlib.midohra.entity.EntityWrapper; +import net.pitan76.mcpitanlib.midohra.item.ItemStack; +import net.pitan76.mcpitanlib.midohra.recipe.RecipeManager; +import net.pitan76.mcpitanlib.midohra.util.math.BlockPos; +import net.pitan76.mcpitanlib.midohra.util.math.Vector3d; + +import java.util.List; +import java.util.Optional; +import java.util.UUID; + +public class World extends WorldAccess { + + private final net.minecraft.world.level.Level world; + + protected World(net.minecraft.world.level.Level world) { + super(null); + this.world = world; + } + + public static World of(net.minecraft.world.level.Level world) { + return new World(world); + } + + @Override + public net.minecraft.world.level.Level getRaw() { + return world; + } + + public net.minecraft.world.level.Level toMinecraft() { + return getRaw(); + } + + public void addBlockEntity(BlockEntityWrapper blockEntity) { + addBlockEntity(blockEntity.get()); + } + + public void addBlockEntity(BlockEntity blockEntity) { + getRaw().setBlockEntity(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.world.item.ItemStack stack, BlockPos pos) { + WorldUtil.spawnStack(getRaw(), pos.toMinecraft(), stack); + } + + public RecipeManager getRecipeManager() { + return RecipeManager.of(getRaw().recipeAccess()); + } + + @Deprecated + @Override + public void playSound(net.minecraft.world.entity.player.Player playerEntity, net.minecraft.core.BlockPos pos, SoundEvent sound, SoundSource category) { + getRaw().playSound(playerEntity, pos, sound, category); + } + + @Deprecated + @Override + public void playSound(net.minecraft.world.entity.player.Player playerEntity, net.minecraft.core.BlockPos pos, SoundEvent sound, SoundSource 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.level.ServerLevel) { + return Optional.of(ServerWorld.of((net.minecraft.server.level.ServerLevel) getRaw())); + } + return Optional.empty(); + } + + public CompatRegistryLookup getRegistryLookup() { + return RegistryLookupUtil.getRegistryLookup(getRaw()); + } + + public boolean isAir(BlockPos pos) { + return WorldUtil.isAir(getRaw(), pos.toMinecraft()); + } + + public Block getBlock(BlockPos pos) { + return WorldUtil.getBlock(getRaw(), pos.toMinecraft()); + } + + public void addParticle(CompatParticleEffect effect, double x, double y, double z, double velocityX, double velocityY, double velocityZ) { + WorldUtil.addParticle(getRaw(), effect.getRaw(), x, y, z, velocityX, velocityY, velocityZ); + } + + public void addParticle(CompatParticleEffect effect, Vector3d pos, Vector3d velocity) { + addParticle(effect, pos.getX(), pos.getY(), pos.getZ(), velocity.getX(), velocity.getY(), velocity.getZ()); + } + + public boolean isRaining() { + return WorldUtil.isRaining(getRaw()); + } + + public boolean isThundering() { + return WorldUtil.isThundering(getRaw()); + } + + public boolean hasSkyLight() { + return WorldUtil.hasSkyLight(getRaw()); + } + + public boolean isSkyVisible(BlockPos pos) { + return WorldUtil.isSkyVisible(getRaw(), pos.toMinecraft()); + } + + public boolean isDay() { + return WorldUtil.isDay(getRaw()); + } + + public float getSkyAngle(float partialTicks) { + return WorldUtil.getSkyAngle(getRaw(), partialTicks); + } + + public float getSkyAngle() { + return getSkyAngle(0); + } + + public void dropStackOnBlock(BlockPos pos, ItemStack stack) { + WorldUtil.dropStackOnBlock(getRaw(), pos.toMinecraft(), stack.toMinecraft()); + } + + public void spawnStack(ItemStack stack, BlockPos pos) { + WorldUtil.spawnStack(getRaw(), pos.toMinecraft(), stack.toMinecraft()); + } + + public void addParticle(CompatParticleType type, double x, double y, double z, double velocityX, double velocityY, double velocityZ) { + WorldUtil.addParticle(getRaw(), type, x, y, z, velocityX, velocityY, velocityZ); + } + + public void addParticle(CompatParticleType type, Vector3d pos, Vector3d velocity) { + addParticle(type, pos.getX(), pos.getY(), pos.getZ(), velocity.getX(), velocity.getY(), velocity.getZ()); + } + + public void sendEntityStatus(EntityWrapper entity, byte status) { + WorldUtil.sendEntityStatus(getRaw(), entity.get(), status); + } +} 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..95663681f --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/world/WorldAccess.java @@ -0,0 +1,211 @@ +package net.pitan76.mcpitanlib.midohra.world; + +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.monster.Enemy; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.EntitySelector; +import net.minecraft.server.MinecraftServer; +import net.minecraft.sounds.SoundSource; +import net.minecraft.sounds.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.entity.EntityTypeWrapper; +import net.pitan76.mcpitanlib.midohra.entity.EntityWrapper; +import net.pitan76.mcpitanlib.midohra.server.MCServer; +import net.pitan76.mcpitanlib.midohra.util.math.BlockPos; +import net.pitan76.mcpitanlib.midohra.util.math.Box; + +import java.util.List; +import java.util.Optional; +import java.util.function.Predicate; + +public class WorldAccess extends WorldView { + private final net.minecraft.world.level.LevelAccessor world; + + protected WorldAccess(net.minecraft.world.level.LevelAccessor world) { + super(null); + this.world = world; + } + + public static WorldAccess of(net.minecraft.world.level.LevelAccessor world) { + return new WorldAccess(world); + } + + @Override + protected net.minecraft.world.level.LevelAccessor getRaw() { + return world; + } + + public net.minecraft.world.level.LevelAccessor 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(net.minecraft.world.entity.player.Player playerEntity, net.minecraft.core.BlockPos pos, SoundEvent sound, SoundSource category, float volume, float pitch) { + getRaw().playSound(playerEntity, pos, sound, category, volume, pitch); + } + + @Deprecated + public void playSound(net.minecraft.world.entity.player.Player playerEntity, net.minecraft.core.BlockPos pos, SoundEvent sound, SoundSource 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()); + } + + public boolean isChunkLoaded(BlockPos pos) { + return WorldAccessUtil.isChunkLoaded(getRaw(), pos.toMinecraft()); + } + + public List getEntitiesByClass(Class entityClass, Box box, Predicate predicate) { + return WorldAccessUtil.getEntitiesByClass(getRaw(), entityClass, box, predicate); + } + + public List getEntitiesByType(EntityType entityType, Box box, Predicate predicate) { + return WorldAccessUtil.getEntitiesByType(getRaw(), entityType, box, predicate); + } + + public List getEntitiesByType(EntityTypeWrapper entityType, Box box, Predicate predicate) { + return WorldAccessUtil.getEntitiesByType(getRaw(), entityType.get(), box, predicate); + } + + public List getEntitiesByClass(Class entityClass, Box box) { + return getEntitiesByClass(entityClass, box, EntitySelector.ENTITY_STILL_ALIVE); + } + + public List getEntitiesByType(EntityType entityType, Box box) { + return getEntitiesByType(entityType, box, EntitySelector.ENTITY_STILL_ALIVE); + } + + public boolean breakBlock(BlockPos pos, boolean drop, Player player) { + return breakBlock(pos, drop, player.getEntity()); + } + + public List getEntitiesByTypeM(EntityTypeWrapper entityType, Box box, Predicate predicate) { + return getEntitiesByType(entityType.get(), box, (e) -> predicate.test(EntityWrapper.of(e))) + .stream().map(EntityWrapper::of).toList(); + } + + public List getEntitiesByTypeM(EntityTypeWrapper entityType, Box box) { + return getEntitiesByType(entityType.get(), box).stream().map(EntityWrapper::of).toList(); + } + + public List getEntitiesByClassM(Class entityClass, Box box, Predicate predicate) { + return getEntitiesByClass((Class) entityClass, box, (e) -> predicate.test(EntityWrapper.of(e))) + .stream().map(EntityWrapper::of).toList(); + } + + public List getEntitiesByClassM(Class entityClass, Box box) { + return getEntitiesByClass((Class) entityClass, box).stream().map(EntityWrapper::of).toList(); + } + + public void spawnEntity(Entity entity) { + getRaw().addFreshEntity(entity); + } + + public void spawnEntity(EntityWrapper entity) { + spawnEntity(entity.get()); + } + + public List getMobs(Box box) { + return getEntitiesByClassM(LivingEntity.class, box, entity -> entity.get() instanceof net.minecraft.world.entity.Mob); + } + + public List getMonsters(Box box) { + return getEntitiesByClassM(LivingEntity.class, box, entity -> entity.get() instanceof Enemy); + } + + public List getAnimals(Box box) { + return getEntitiesByClassM(LivingEntity.class, box, entity -> entity.get() instanceof net.minecraft.world.entity.animal.Animal); + } + + public int getLuminance(BlockPos pos) { + return getBlockState(pos).getLuminance(); + } + + public List getLivingEntities(Box box) { + return getEntitiesByClassM(LivingEntity.class, box); + } +} 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..d2f8b2172 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/world/WorldView.java @@ -0,0 +1,90 @@ +package net.pitan76.mcpitanlib.midohra.world; + +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.level.material.FluidState; +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 java.util.Optional; + +public class WorldView implements IWorldView, RedstoneView { + private final net.minecraft.world.level.LevelReader world; + + protected WorldView(net.minecraft.world.level.LevelReader world) { + this.world = world; + } + + public static WorldView of(net.minecraft.world.level.LevelReader world) { + return new WorldView(world); + } + + protected net.minecraft.world.level.LevelReader getRaw() { + return world; + } + + public net.minecraft.world.level.LevelReader 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.core.BlockPos pos) { + return getRaw().getBlockEntity(pos); + } + + @Override + public net.minecraft.world.level.block.state.BlockState getBlockState(net.minecraft.core.BlockPos pos) { + return getRaw().getBlockState(pos); + } + + @Override + public FluidState getFluidState(net.minecraft.core.BlockPos pos) { + return getRaw().getFluidState(pos); + } + + @Override + @Deprecated + public net.minecraft.world.level.SignalGetter 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; + } + + @Override + public boolean isNull() { + return 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..bff1515a7 --- /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.level.chunk.ChunkSource chunkManager; + + protected ChunkManager(net.minecraft.world.level.chunk.ChunkSource chunkManager) { + this.chunkManager = chunkManager; + } + + public static ChunkManager of(net.minecraft.world.level.chunk.ChunkSource chunkManager) { + return new ChunkManager(chunkManager); + } + + public static ChunkManager of(net.minecraft.world.level.Level world) { + return of(world.getChunkSource()); + } + + public static ChunkManager of(World world) { + return of(world.getRaw()); + } + + public net.minecraft.world.level.chunk.ChunkSource getRaw() { + return chunkManager; + } + + public net.minecraft.world.level.chunk.ChunkSource toMinecraft() { + return getRaw(); + } + + public IWorldView getWorld() { + return BlockView.of(getRaw().getLevel()); + } + + public boolean isChunkLoaded(int x, int z) { + return getRaw().hasChunk(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..d7468e60e --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/world/chunk/ChunkTicketType.java @@ -0,0 +1,87 @@ +package net.pitan76.mcpitanlib.midohra.world.chunk; + +import net.minecraft.util.Unit; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.ChunkPos; + +import java.util.Comparator; + +public class ChunkTicketType { + + public static final ChunkTicketType START = of(net.minecraft.server.level.TicketType.PLAYER_SPAWN); + public static final ChunkTicketType DRAGON = of(net.minecraft.server.level.TicketType.DRAGON); + public static final ChunkTicketType PLAYER = of(net.minecraft.server.level.TicketType.PLAYER_SIMULATION); + public static final ChunkTicketType FORCED = of(net.minecraft.server.level.TicketType.FORCED); + public static final ChunkTicketType PORTAL = of(net.minecraft.server.level.TicketType.PORTAL); + public static final ChunkTicketType ENDER_PEARL = of(net.minecraft.server.level.TicketType.ENDER_PEARL); + public static final ChunkTicketType POST_TELEPORT = of(net.minecraft.server.level.TicketType.PORTAL); + public static final ChunkTicketType UNKNOWN = of(net.minecraft.server.level.TicketType.UNKNOWN); + + private final net.minecraft.server.level.TicketType ticketType; + + protected ChunkTicketType(net.minecraft.server.level.TicketType ticketType) { + this.ticketType = ticketType; + } + + public static ChunkTicketType of(net.minecraft.server.level.TicketType ticketType) { + return new ChunkTicketType<>(ticketType); + } + + public net.minecraft.server.level.TicketType getRaw() { + return ticketType; + } + + public net.minecraft.server.level.TicketType toMinecraft() { + return getRaw(); + } + + public static ChunkTicketType create(String name, Comparator argumentComparator) { + return (ChunkTicketType) create(name); + } + + public static ChunkTicketType create(String name, Comparator argumentComparator, int expiryTicks) { + return (ChunkTicketType) create(name, expiryTicks); + } + + public Comparator getArgumentComparator() { + return null; + } + + public long getExpiryTicks() { + return getRaw().timeout(); + } + + @Override + public String toString() { + return getRaw().toString(); + } + + public ChunkTicketType(String name, long expiryTicks) { + this(new net.minecraft.server.level.TicketType(expiryTicks, 6)); + } + + 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); + } + + @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..83a055658 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/world/chunk/ServerChunkManager.java @@ -0,0 +1,56 @@ +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.PersistentStateManager; +import net.pitan76.mcpitanlib.midohra.world.ServerWorld; +import net.pitan76.mcpitanlib.midohra.world.World; + +public class ServerChunkManager extends ChunkManager { + private final net.minecraft.server.level.ServerChunkCache chunkManager; + + protected ServerChunkManager(net.minecraft.server.level.ServerChunkCache chunkManager) { + super(null); + this.chunkManager = chunkManager; + } + + public static ServerChunkManager of(net.minecraft.server.level.ServerChunkCache chunkManager) { + return new ServerChunkManager(chunkManager); + } + + public static ServerChunkManager of(ServerWorld world) { + return of(world.getRaw().getChunkSource()); + } + + @Override + public net.minecraft.server.level.ServerChunkCache getRaw() { + return chunkManager; + } + + @Override + public net.minecraft.server.level.ServerChunkCache toMinecraft() { + return getRaw(); + } + + @Override + public World getWorld() { + return World.of(getRaw().getLevel()); + } + + public void addTicket(ChunkTicketType ticketType, ChunkPos pos, int radius, T argument) { + getRaw().addTicketWithRadius(ticketType.getRaw(), pos.getRaw(), radius); + } + + public void removeTicket(ChunkTicketType ticketType, ChunkPos pos, int radius, T argument) { + getRaw().removeTicketWithRadius(ticketType.getRaw(), pos.getRaw(), radius); + } + + public void markForUpdate(BlockPos pos) { + ChunkManagerUtil.markForUpdate(getRaw(), pos); + } + + public PersistentStateManager getPersistentStateManager() { + return PersistentStateManager.of(getRaw().getDataStorage()); + } +} 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..36bed422c --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/world/tick/ScheduledTickView.java @@ -0,0 +1,47 @@ +package net.pitan76.mcpitanlib.midohra.world.tick; + +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.material.Fluid; +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 net.minecraft.world.level.ScheduledTickAccess scheduledTickView; + + public ScheduledTickView(net.minecraft.world.level.ScheduledTickAccess scheduledTickView) { + this.scheduledTickView = scheduledTickView; + } + + public static net.pitan76.mcpitanlib.midohra.world.tick.ScheduledTickView of(net.minecraft.world.level.ScheduledTickAccess scheduledTickView) { + return new net.pitan76.mcpitanlib.midohra.world.tick.ScheduledTickView(scheduledTickView); + } + + public static net.pitan76.mcpitanlib.midohra.world.tick.ScheduledTickView of(net.minecraft.world.level.Level world) { + return new net.pitan76.mcpitanlib.midohra.world.tick.ScheduledTickView(world); + } + + public net.minecraft.world.level.ScheduledTickAccess toMinecraft() { + return get(); + } + + protected net.minecraft.world.level.ScheduledTickAccess get() { + return scheduledTickView; + } + + public void scheduleBlockTick(BlockPos blockPos, BlockWrapper blockWrapper, int delay) { + scheduleBlockTick(blockPos.toMinecraft(), blockWrapper.get(), delay); + } + + public void scheduleBlockTick(net.minecraft.core.BlockPos blockPos, Block block, int delay) { + get().scheduleTick(blockPos, block, delay); + } + + public void scheduleFluidTick(BlockPos blockPos, FluidWrapper fluidWrapper, int delay) { + scheduleFluidTick(blockPos.toMinecraft(), fluidWrapper.get(), delay); + } + + public void scheduleFluidTick(net.minecraft.core.BlockPos blockPos, Fluid block, int delay) { + get().scheduleTick(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..5d214cc06 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/mixin/AbstractBlock4CompatProviderMixin.java @@ -0,0 +1,97 @@ +package net.pitan76.mcpitanlib.mixin; + +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.util.RandomSource; +import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.ScheduledTickAccess; +import net.minecraft.world.level.block.RenderShape; +import net.minecraft.world.level.block.Rotation; +import net.minecraft.world.level.block.state.BlockBehaviour; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.VoxelShape; +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 net.pitan76.mcpitanlib.api.util.math.random.CompatRandom; +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(BlockBehaviour.class) +public class AbstractBlock4CompatProviderMixin { + @Inject(method = "getCollisionShape", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$inject_getCollisionShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext 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 = "getShape", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$inject_getOutlineShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext 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 = "updateShape", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$inject_getStateForNeighborUpdate(BlockState state, LevelReader world, ScheduledTickAccess tickView, BlockPos pos, Direction direction, BlockPos neighborPos, BlockState neighborState, RandomSource random, 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, tickView, new CompatRandom(random)), options); + if (options.cancel && returnValue != null) + cir.setReturnValue(returnValue.toMinecraft()); + } + } + + @Inject(method = "getRenderShape", 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, Rotation 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 = "skipRendering", 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..903b4c388 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/mixin/AbstractBlockMixin.java @@ -0,0 +1,140 @@ +package net.pitan76.mcpitanlib.mixin; + +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.util.RandomSource; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.MenuProvider; +import net.minecraft.world.SimpleMenuProvider; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.state.BlockBehaviour; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.pathfinder.PathComputationType; +import net.minecraft.world.level.storage.loot.LootParams; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.VoxelShape; +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(BlockBehaviour.class) +public class AbstractBlockMixin { + @Inject(method = "getCollisionShape", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$inject_getCollisionShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext 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 = "getShape", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$inject_getOutlineShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext 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 = "tick", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$inject_scheduledTick(BlockState state, ServerLevel world, BlockPos pos, RandomSource 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 = "useWithoutItem", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$inject_onUse(BlockState state, Level world, BlockPos pos, Player 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.getUsedItemHand(), hit), options); + if (options.cancel && returnValue != null) + cir.setReturnValue(returnValue.toActionResult()); + } + } + + @Inject(method = "getMenuProvider", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$inject_createScreenHandlerFactory(BlockState state, Level world, BlockPos pos, CallbackInfoReturnable cir) { + if (this instanceof ExtendBlockProvider) { + ExtendBlockProvider provider = (ExtendBlockProvider) this; + Options options = new Options(); + SimpleMenuProvider returnValue = new SimpleMenuProvider((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 = "affectNeighborsAfterRemoval", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$inject_onStateReplaced(BlockState state, ServerLevel world, BlockPos pos, boolean moved, CallbackInfo ci) { + if (this instanceof ExtendBlockProvider) { + ExtendBlockProvider provider = (ExtendBlockProvider) this; + Options options = new Options(); + provider.onStateReplaced(new StateReplacedEvent(state, world, pos, world.getBlockState(pos), moved), options); + if (options.cancel) + ci.cancel(); + } + } + + @Inject(method = "getDrops", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$inject_getDroppedStacks(BlockState state, LootParams.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); + } + } + + // TODO(Ravel): no target class + @Inject(method = "isPathfindable", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$inject_canPathfindThrough(BlockState state, PathComputationType 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); + } + } + + @Inject(method = "getCloneItemStack", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$getPickStack(LevelReader world, BlockPos pos, BlockState state, boolean includeData, CallbackInfoReturnable cir) { + // ExtendBlockProviderを実装している場合 (1.21.5からAbstractBlockに移転) + if (this instanceof ExtendBlockProvider) { + ExtendBlockProvider provider = (ExtendBlockProvider) this; + Options options = new Options(); + + PickStackEvent event = new PickStackEvent(world, pos, state); + event.setIncludeData(includeData); + + ItemStack returnValue = provider.getPickStack(event, 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..9f2e05b51 --- /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.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.item.context.BlockPlaceContext; +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 = "getStateForPlacement", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$getPlacementState(BlockPlaceContext 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..e04e3fbde --- /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.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Invoker; + +@Mixin(Block.class) +public interface BlockInvoker { + @Invoker("registerDefaultState") + 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..1ed344b4e --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/mixin/BlockMixin.java @@ -0,0 +1,100 @@ +package net.pitan76.mcpitanlib.mixin; + +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.context.BlockPlaceContext; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +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.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; + +@Mixin(Block.class) +public class BlockMixin { + + @Inject(method = "setPlacedBy", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$onPlaced(Level 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 = "playerWillDestroy", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$onBreak(Level world, BlockPos pos, BlockState state, Player 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 = "createBlockStateDefinition", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$appendProperties(StateDefinition.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 = "getStateForPlacement", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$getPlacementState(BlockPlaceContext 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); + } + } +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/mixin/CraftingRecipeMixin.java b/common/src/main/java/net/pitan76/mcpitanlib/mixin/CraftingRecipeMixin.java new file mode 100644 index 000000000..11913f03c --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/mixin/CraftingRecipeMixin.java @@ -0,0 +1,28 @@ +package net.pitan76.mcpitanlib.mixin; + +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.CraftingRecipe; +import net.minecraft.world.item.crafting.CraftingInput; +import net.minecraft.core.NonNullList; +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(CraftingRecipe.class) +public interface CraftingRecipeMixin { + @Inject(method = "defaultCraftingReminder", at = @At("RETURN")) + private static void mcpitanlib$collectRecipeRemainders(CraftingInput input, CallbackInfoReturnable> cir) { + NonNullList 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/ItemMixin.java b/common/src/main/java/net/pitan76/mcpitanlib/mixin/ItemMixin.java new file mode 100644 index 000000000..7401bb058 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/mixin/ItemMixin.java @@ -0,0 +1,252 @@ +package net.pitan76.mcpitanlib.mixin; + +import net.minecraft.world.item.*; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.item.component.TooltipDisplay; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EquipmentSlot; +import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.context.UseOnContext; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.network.chat.Component; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.InteractionHand; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +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 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.function.Consumer; + +@Mixin(Item.class) +public class ItemMixin { + @Inject(method = "use", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$use(Level world, Player user, InteractionHand hand, CallbackInfoReturnable cir) { + if (this instanceof ExtendItemProvider) { + ExtendItemProvider provider = (ExtendItemProvider) this; + Options options = new Options(); + CompatActionResult returnValue = provider.onRightClick(new ItemUseEvent(world, user, hand), options); + if (options.cancel && returnValue != null) + cir.setReturnValue(returnValue.toActionResult()); + } + } + + @Inject(method = "useOn", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$useOnBlock(UseOnContext context, CallbackInfoReturnable cir) { + if (this instanceof ExtendItemProvider) { + ExtendItemProvider provider = (ExtendItemProvider) this; + UseOnContextMixin contextAccessor = (UseOnContextMixin) context; + Options options = new Options(); + CompatActionResult returnValue = provider.onRightClickOnBlock(new ItemUseOnBlockEvent(context.getPlayer(), context.getHand(), contextAccessor.getHitResult()), options); + if (options.cancel && returnValue != null) + cir.setReturnValue(returnValue.toActionResult()); + } + } + + @Inject(method = "interactLivingEntity", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$useOnEntity(ItemStack stack, Player user, LivingEntity entity, InteractionHand 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 = "finishUsingItem", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$finishUsing(ItemStack stack, Level 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 = "appendHoverText", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$appendTooltip(ItemStack stack, Item.TooltipContext context, TooltipDisplay displayComponent, Consumer textConsumer, TooltipFlag type, CallbackInfo ci) { + if (this instanceof ExtendItemProvider) { + ExtendItemProvider provider = (ExtendItemProvider) this; + Options options = new Options(); + provider.appendTooltip(new ItemAppendTooltipEvent(stack, context, displayComponent, textConsumer, type), options); + if (options.cancel) + ci.cancel(); + } + } + + @Inject(method = "hurtEnemy", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$postHit(ItemStack stack, LivingEntity target, LivingEntity attacker, CallbackInfo ci) { + if (this instanceof ExtendItemProvider) { + ExtendItemProvider provider = (ExtendItemProvider) this; + Options options = new Options(); + provider.postHit(new PostHitEvent(stack, target, attacker), options); + if (options.cancel) + ci.cancel(); + } + } + + @Inject(method = "mineBlock", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$postMine(ItemStack stack, Level 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 = "onCraftedPostProcess", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$onCraft(ItemStack stack, Level 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 = "getBarColor", 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 = "isBarVisible", 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 = "getBarWidth", 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 = "getAttackDamageBonus", 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 = "getUseAnimation", 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.get()); + } + } + + @Inject(method = "inventoryTick", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$inventoryTick(ItemStack stack, ServerLevel world, Entity entity, EquipmentSlot slot, 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)); + } + } + } + + // CompatItemProviderを実装している場合 + if (this instanceof CompatItemProvider) { + CompatItemProvider provider = (CompatItemProvider) this; + Options options = new Options(); + provider.inventoryTick(new InventoryTickEvent(stack, world, entity, slot), options); + if (options.cancel) + ci.cancel(); + } + } + + @Inject(method = "getCraftingRemainder", 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(ItemStackTemplate.fromNonEmptyStack(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..fb8513ca9 --- /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.util.datafix.fixes.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 = "fixItemStack", at = @At("TAIL")) + private static void mcpitanlib$fixStack(ItemStackComponentizationFix.ItemStackData data, Dynamic dynamic, CallbackInfo ci) { + if (!ItemStackFixer.getNbt2componentMapIfItemEqualMap().isEmpty()) { + ItemStackFixer.getNbt2componentMapIfItemEqualMap().forEach((itemId, map) -> { + for (String nbtKey : map.keySet()) { + if (data.is(itemId)) { + data.moveTagToComponent(nbtKey, map.get(nbtKey)); + } + } + }); + } + + if (!ItemStackFixer.getNbt2componentMapIfitemMatchesMap().isEmpty()) { + ItemStackFixer.getNbt2componentMapIfitemMatchesMap().forEach((itemIds, map) -> { + for (String nbtKey : map.keySet()) { + if (data.is(itemIds)) { + data.moveTagToComponent(nbtKey, map.get(nbtKey)); + } + } + }); + } + + if (!ItemStackFixer.getNbt2componentMap().isEmpty()) { + ItemStackFixer.getNbt2componentMap().forEach(data::moveTagToComponent); + } + } + +} 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..e23a50724 --- /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.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.level.ServerLevel; +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 = "hurtAndBreak(ILnet/minecraft/server/level/ServerLevel;Lnet/minecraft/server/level/ServerPlayer;Ljava/util/function/Consumer;)V", at = @At("HEAD"), cancellable = true) + public void mcpitanlib$damage(int amount, ServerLevel world, ServerPlayer 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/LevelRendererMixin.java b/common/src/main/java/net/pitan76/mcpitanlib/mixin/LevelRendererMixin.java new file mode 100644 index 000000000..89a1d2130 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/mixin/LevelRendererMixin.java @@ -0,0 +1,78 @@ +package net.pitan76.mcpitanlib.mixin; + +import com.mojang.blaze3d.buffers.GpuBufferSlice; +import net.minecraft.client.DeltaTracker; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.LevelRenderer; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.chunk.ChunkSectionsToRender; +import com.mojang.blaze3d.resource.GraphicsResourceAllocator; +import com.mojang.blaze3d.vertex.PoseStack; +import net.minecraft.client.multiplayer.ClientLevel; +import net.minecraft.client.renderer.state.level.CameraRenderState; +import net.minecraft.client.renderer.state.level.LevelRenderState; +import net.pitan76.mcpitanlib.api.client.event.WorldRenderRegistry; +import net.pitan76.mcpitanlib.api.client.event.listener.*; +import org.jetbrains.annotations.Nullable; +import org.joml.Matrix4f; +import org.joml.Matrix4fc; +import org.joml.Vector4f; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +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; + +@Mixin(LevelRenderer.class) +public abstract class LevelRendererMixin { + @Shadow private int ticks; + + @Shadow public abstract boolean hasRenderedAllSections(); + + @Shadow @Final private Minecraft minecraft; + @Shadow @Nullable private ClientLevel level; + @Unique + private final WorldRenderContextImpl mcpitanlib$contextCache = new WorldRenderContextImpl(); + + @Inject(method = "renderBlockOutline", at = @At("HEAD"), cancellable = true) + private void mcpitanlib$onRenderTargetBlockOutline(MultiBufferSource.BufferSource immediate, PoseStack matrices, boolean renderBlockOutline, LevelRenderState renderStates, CallbackInfo ci) { + if (WorldRenderRegistry.isEmptyBlockOutlineListeners) return; + + mcpitanlib$contextCache.worldRenderer = (LevelRenderer)(Object) this; + mcpitanlib$contextCache.advancedTranslucency = hasRenderedAllSections(); + mcpitanlib$contextCache.consumers = immediate; + mcpitanlib$contextCache.matrixStack = matrices; + mcpitanlib$contextCache.tickDelta = ticks; + + BeforeBlockOutlineEvent event = new BeforeBlockOutlineEvent(mcpitanlib$contextCache, Minecraft.getInstance().hitResult); + + for (BeforeBlockOutlineListener listener : WorldRenderRegistry.beforeBlockOutlineListeners) { + if (!listener.beforeBlockOutline(event)) { + ci.cancel(); + return; + } + } + } + + @Inject(method = "renderLevel", at = @At("HEAD")) + private void mcpitanlib$beforeRender(GraphicsResourceAllocator allocator, DeltaTracker tickCounter, boolean renderOutline, CameraRenderState cameraRenderState, Matrix4fc modelViewMatrix, GpuBufferSlice terrainFog, Vector4f fogColor, boolean shouldRenderSky, ChunkSectionsToRender chunkSectionsToRender, CallbackInfo ci) { + mcpitanlib$contextCache.prepare(minecraft.gameRenderer, (LevelRenderer) (Object) this, level, tickCounter, renderOutline, Minecraft.getInstance().gameRenderer.getMainCamera(), new Matrix4f(), new Matrix4f(), new Matrix4f()); + } + +// @ModifyExpressionValue(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/LevelRenderer;cullFrustum(Lorg/joml/Matrix4f;Lorg/joml/Matrix4f;Lnet/minecraft/world/phys/Vec3;)Lnet/minecraft/client/renderer/culling/Frustum;")) +// private Frustum onSetupFrustum(Frustum frustum) { +// mcpitanlib$contextCache.frustum = frustum; +// return frustum; +// } + + @Inject(method = "renderLevel", at = @At("TAIL")) + private void mcpitanlib$onWorldRenderEnd(GraphicsResourceAllocator allocator, DeltaTracker tickCounter, boolean renderOutline, CameraRenderState cameraState, Matrix4fc modelViewMatrix, GpuBufferSlice terrainFog, Vector4f fogColor,boolean shouldRenderSky,ChunkSectionsToRender chunkSectionsToRender, CallbackInfo ci) { + if (WorldRenderRegistry.isEmptyWorldRenderAfterLevelListeners) return; + + for (WorldRenderContextListener listener : WorldRenderRegistry.worldRenderAfterLevelListeners) { + listener.render(mcpitanlib$contextCache); + } + } +} 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..608fabf85 --- /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 = "tickServer", 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..b8db642b4 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/mixin/RecipeManagerMixin.java @@ -0,0 +1,29 @@ +package net.pitan76.mcpitanlib.mixin; + +import com.llamalad7.mixinextras.sugar.Local; +import net.minecraft.server.packs.resources.ResourceManager; +import net.minecraft.resources.Identifier; +import net.minecraft.util.profiling.ProfilerFiller; +import net.minecraft.world.item.crafting.Recipe; +import net.minecraft.world.item.crafting.RecipeManager; +import net.minecraft.world.item.crafting.RecipeMap; +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.CallbackInfoReturnable; + +import java.util.SortedMap; + +@Mixin(RecipeManager.class) +public class RecipeManagerMixin { + + @Inject(method = "prepare(Lnet/minecraft/server/packs/resources/ResourceManager;Lnet/minecraft/util/profiling/ProfilerFiller;)Lnet/minecraft/world/item/crafting/RecipeMap;", + at = @At(value = "TAIL")) + private void mcpitanlib$invokeApply(ResourceManager resourceManager, ProfilerFiller profiler, CallbackInfoReturnable cir, @Local SortedMap> sortedMap) { + if (RecipeManagerRegistry.managers.isEmpty()) return; + RecipeManagerRegistry.managers.forEach((manager) -> manager.apply(new RecipeManagerEvent(sortedMap, resourceManager, profiler))); + } + +} diff --git a/common/src/main/java/net/pitan76/mcpitanlib/mixin/ServerLevelTimer.java b/common/src/main/java/net/pitan76/mcpitanlib/mixin/ServerLevelTimer.java new file mode 100644 index 000000000..a68b0332e --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/mixin/ServerLevelTimer.java @@ -0,0 +1,39 @@ +package net.pitan76.mcpitanlib.mixin; + +import net.minecraft.server.level.ServerLevel; +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.BooleanSupplier; +import java.util.function.Supplier; + +@Mixin(ServerLevel.class) +public class ServerLevelTimer implements ServerWorldTimerAccess { + @Unique + private final List mcpitanlib$timerItems = new ArrayList<>(); + + @Inject(method = "tick", at = @At("TAIL")) + private void onTick(BooleanSupplier haveTime, 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/UseOnContextMixin.java b/common/src/main/java/net/pitan76/mcpitanlib/mixin/UseOnContextMixin.java new file mode 100644 index 000000000..6e0babcd1 --- /dev/null +++ b/common/src/main/java/net/pitan76/mcpitanlib/mixin/UseOnContextMixin.java @@ -0,0 +1,12 @@ +package net.pitan76.mcpitanlib.mixin; + +import net.minecraft.world.item.context.UseOnContext; +import net.minecraft.world.phys.BlockHitResult; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +@Mixin(UseOnContext.class) +public interface UseOnContextMixin { + @Accessor + public BlockHitResult getHitResult(); +} \ No newline at end of file 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..31f66b243 --- /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.world.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..549febca6 --- /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.world.Container; +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 Container 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..ea3349649 --- /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.world.entity.player.Inventory; +import net.minecraft.network.chat.Component; +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, Inventory inventory, Component 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..4db7a6e12 --- /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.world.inventory.AbstractContainerMenu; +import net.minecraft.network.chat.Component; +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 Component getDisplayName(DisplayNameArgs args) { + return getName(); + } + + @Override + public AbstractContainerMenu 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..16a1e974c --- /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.world.inventory.AbstractContainerMenu; +import net.minecraft.network.chat.Component; +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 Component getDisplayName(DisplayNameArgs args) { + return TextUtil.literal("Example Title"); + } + + @Override + public AbstractContainerMenu 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..f4faf134e --- /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.world.level.block.Block; +import net.minecraft.world.item.Item; +import net.minecraft.world.inventory.MenuType; +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..1685da685 --- /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.world.entity.player.Inventory; +import net.minecraft.network.chat.Component; +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, Inventory inventory, Component 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..3d5d51503 --- /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.world.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/LICENSE b/common/src/main/resources/LICENSE new file mode 100644 index 000000000..c44ae5407 --- /dev/null +++ b/common/src/main/resources/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022-2026 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 +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/common/src/main/resources/THIRD_PARTY_LICENSES b/common/src/main/resources/THIRD_PARTY_LICENSES new file mode 100644 index 000000000..237160ca3 --- /dev/null +++ b/common/src/main/resources/THIRD_PARTY_LICENSES @@ -0,0 +1,11 @@ +SnakeYAML +- Library: SnakeYAML +- Copyright: SnakeYAML contributors +- License: Apache License 2.0 +- URL: https://bitbucket.org/snakeyaml/snakeyaml/src/master/LICENSE.txt + +Cloth Config API +- Library: Cloth Config API +- Copyright: shedaniel and contributors +- License: GNU Lesser General Public License v3.0 (LGPL-3.0) +- URL: https://github.com/shedaniel/cloth-config/blob/v8/LICENSE.md \ No newline at end of file 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/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..1f8c4e3d5 --- /dev/null +++ b/common/src/main/resources/mcpitanlib-common.mixins.json @@ -0,0 +1,27 @@ +{ + "required": true, + "minVersion": "0.8", + "package": "net.pitan76.mcpitanlib.mixin", + "compatibilityLevel": "JAVA_8", + "mixins": [ + "AbstractBlock4CompatProviderMixin", + "AbstractBlockMixin", + "Block4CompatProviderMixin", + "BlockInvoker", + "BlockMixin", + "CraftingRecipeMixin", + "ItemMixin", + "ItemStackComponentizationFixMixin", + "ItemStackMixin", + "MinecraftServerTimer", + "RecipeManagerMixin", + "ServerLevelTimer", + "UseOnContextMixin" + ], + "client": [ + "LevelRendererMixin" + ], + "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..dcb6a99aa --- /dev/null +++ b/common/src/main/resources/mcpitanlib.accesswidener @@ -0,0 +1,5 @@ +accessWidener v2 official + +accessible class net/minecraft/util/datafix/fixes/ItemStackComponentizationFix$ItemStackData +mutable field net/minecraft/client/gui/screens/inventory/AbstractContainerScreen imageWidth I +mutable field net/minecraft/client/gui/screens/inventory/AbstractContainerScreen imageHeight I diff --git a/fabric/build.gradle b/fabric/build.gradle index efcb67ddc..e458f5909 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.gradleup.shadow" version "9.4.0" } architectury { @@ -7,22 +7,60 @@ 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. + common { + canBeResolved = true + canBeConsumed = false + } + // Don't use the `shadow` configuration from the plugin itself as it's meant for excluding files. + shadowCommon { + canBeResolved = true + canBeConsumed = false + } compileClasspath.extendsFrom common runtimeClasspath.extendsFrom common developmentFabric.extendsFrom common + + apiElements { + outgoing.artifacts.clear() + outgoing.artifact(shadowJar) + } + runtimeElements { + outgoing.artifacts.clear() + outgoing.artifact(shadowJar) + } } dependencies { - modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}" - modApi "net.fabricmc.fabric-api:fabric-api:${rootProject.fabric_api_version}" - // Remove the next line if you don't want to depend on the API - modApi "dev.architectury:architectury-fabric:${rootProject.architectury_version}" + implementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}" + compileOnly "net.fabricmc.fabric-api:fabric-api:${rootProject.fabric_api_version}" - common(project(path: ":common", configuration: "namedElements")) { transitive false } + common(project(path: ":common")) { transitive false } shadowCommon(project(path: ":common", configuration: "transformProductionFabric")) { transitive false } + + shadowCommon 'org.yaml:snakeyaml:2.0' + + api("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}") + + implementation("net.pitan76:compatdatapacks76-fabric:${rootProject.compatdatapacks76_version}") { + exclude(group: "net.fabricmc.fabric-api") + } + implementation("net.pitan76:legacyitemmodels-fabric:${rootProject.legacyitemmodels_version}") { + exclude(group: "net.fabricmc.fabric-api") + } + implementation("net.pitan76:littleintermediaryfallback:${rootProject.littleintermediaryfallback_version}") { + exclude(group: "net.fabricmc.fabric-api") + } + include("net.pitan76:compatdatapacks76-fabric:${rootProject.compatdatapacks76_version}") + include("net.pitan76:legacyitemmodels-fabric:${rootProject.legacyitemmodels_version}") + include("net.pitan76:littleintermediaryfallback:${rootProject.littleintermediaryfallback_version}") } processResources { @@ -31,21 +69,25 @@ processResources { filesMatching("fabric.mod.json") { expand "version": project.version } + + project.version = project.version + "-fabric" } shadowJar { - configurations = [project.configurations.shadowCommon] - classifier "dev-shadow" -} + relocate "org.yaml.snakeyaml", "net.pitan76.mcpitanlib.shadow.yaml.snakeyaml" + + exclude "architectury.common.json" -remapJar { - input.set shadowJar.archiveFile - dependsOn shadowJar - classifier null + dependsOn(jar) + mainSpec.sourcePaths.clear() + from(zipTree(jar.archiveFile)) + + configurations = [project.configurations.shadowCommon] + archiveClassifier.set(null) } jar { - classifier "dev" + setArchiveClassifier("dev") } sourcesJar { @@ -54,22 +96,40 @@ sourcesJar { from commonSources.archiveFile.map { zipTree(it) } } -components.java { - withVariantsFromConfiguration(project.configurations.shadowRuntimeElements) { - skip() - } +shadow { + addShadowVariantIntoJavaComponent = false } publishing { publications { mavenFabric(MavenPublication) { - artifactId = rootProject.archives_base_name + "-" + project.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") + } + } + } +} + +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 +} + +tasks.jar.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/gradle.properties b/fabric/gradle.properties new file mode 100644 index 000000000..90ee7a259 --- /dev/null +++ b/fabric/gradle.properties @@ -0,0 +1 @@ +loom.platform=fabric \ 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..6b3627f94 --- /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.world.level.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/ItemTooltipRegistryImpl.java b/fabric/src/main/java/net/pitan76/mcpitanlib/api/client/event/fabric/ItemTooltipRegistryImpl.java new file mode 100644 index 000000000..84edd2080 --- /dev/null +++ b/fabric/src/main/java/net/pitan76/mcpitanlib/api/client/event/fabric/ItemTooltipRegistryImpl.java @@ -0,0 +1,12 @@ +package net.pitan76.mcpitanlib.api.client.event.fabric; + +import net.fabricmc.fabric.api.client.item.v1.ItemTooltipCallback; +import net.pitan76.mcpitanlib.api.client.event.listener.ItemTooltipListener; + +public class ItemTooltipRegistryImpl { + public static void registerItemTooltip(ItemTooltipListener listener) { + ItemTooltipCallback.EVENT.register(((stack, tooltipContext, type, texts) -> { + listener.onTooltip(stack, texts, tooltipContext, type); + })); + } +} 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..9173f1121 --- /dev/null +++ b/fabric/src/main/java/net/pitan76/mcpitanlib/api/client/registry/fabric/CompatRegistryClientImpl.java @@ -0,0 +1,101 @@ +package net.pitan76.mcpitanlib.api.client.registry.fabric; + +import net.fabricmc.fabric.api.client.particle.v1.ParticleProviderRegistry; +import net.fabricmc.fabric.api.client.rendering.v1.BlockColorRegistry; +import net.fabricmc.fabric.api.client.rendering.v1.BlockEntityRendererRegistry; +import net.fabricmc.fabric.api.client.rendering.v1.ModelLayerRegistry; +import net.minecraft.client.color.block.BlockTintSource; +import net.minecraft.client.gui.screens.MenuScreens; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.gui.screens.inventory.MenuAccess; +import net.minecraft.client.model.geom.ModelLayerLocation; +import net.minecraft.client.model.geom.builders.LayerDefinition; +import net.minecraft.client.particle.ParticleProvider; +import net.minecraft.client.renderer.blockentity.BlockEntityRenderers; +import net.minecraft.client.renderer.blockentity.state.BlockEntityRenderState; +import net.minecraft.client.renderer.entity.EntityRendererProvider; +import net.minecraft.client.renderer.entity.EntityRenderers; +import net.minecraft.client.renderer.texture.TextureAtlas; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.core.particles.ParticleOptions; +import net.minecraft.core.particles.ParticleType; +import net.minecraft.util.RandomSource; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.pitan76.mcpitanlib.api.client.registry.CompatRegistryClient; +import net.pitan76.mcpitanlib.api.client.render.EntityModelLayerContext; + +import java.util.List; +import java.util.function.Supplier; + +public class CompatRegistryClientImpl { + public static > void registerScreen(String modId, MenuType type, CompatRegistryClient.ScreenFactory factory) { + MenuScreens.register(type, factory::create); + } + + public static void registerParticle(ParticleType type, ParticleProvider factory) { + ParticleProviderRegistry.getInstance().register(type, factory); + } + + public static void registerParticle(ParticleType type, CompatRegistryClient.DeferredParticleProvider provider) { + ParticleProviderRegistry.getInstance().register(type, spriteSet -> provider.create(new CompatRegistryClient.ExtendedSpriteSet() { + @Override + public TextureAtlas getAtlas() { + return spriteSet.getAtlas(); + } + + @Override + public List getSprites() { + return spriteSet.getSprites(); + } + + @Override + public TextureAtlasSprite get(int age, int maxAge) { + return spriteSet.get(age, maxAge); + } + + @Override + public TextureAtlasSprite get(RandomSource random) { + return spriteSet.get(random); + } + + @Override + public TextureAtlasSprite first() { + return spriteSet.first(); + } + })); + } + + public static void registerEntityModelLayer(ModelLayerLocation layer, EntityModelLayerContext context) { + ModelLayerRegistry.registerModelLayer(layer, () -> LayerDefinition.create(context.getData(), context.getWidth(), context.getHeight())); + } + + public static void registerEntityRenderer(Supplier> type, EntityRendererProvider provider) { + EntityRenderers.register(type.get(), provider); + } + + public static void registerBlockEntityRenderer(BlockEntityType type, CompatRegistryClient.BlockEntityRendererFactory provider) { + BlockEntityRenderers.register(type, ctx -> provider.create(new CompatRegistryClient.BlockEntityRendererFactory.Context( + ctx.blockEntityRenderDispatcher(), ctx.blockModelResolver(), ctx.itemModelResolver(), ctx.entityRenderer(), ctx.entityModelSet(), ctx.font(), ctx.sprites(), ctx.playerSkinRenderCache() + ))); + } + + public static void registerCompatBlockEntityRenderer(BlockEntityType type, CompatRegistryClient.BlockEntityRendererFactory provider) { + BlockEntityRendererRegistry.register(type, ctx -> provider.create(new CompatRegistryClient.BlockEntityRendererFactory.Context( + ctx.blockEntityRenderDispatcher(), ctx.blockModelResolver(), ctx.itemModelResolver(), ctx.entityRenderer(), ctx.entityModelSet(), ctx.font(), ctx.sprites(), ctx.playerSkinRenderCache() + ))); + } + + public static void registerColorProviderBlock(List provider, Block... blocks) { + if (blocks == null || blocks.length == 0) { + BlockColorRegistry.register(provider); + } else { + BlockColorRegistry.register(provider, blocks); + } + } +} diff --git a/fabric/src/main/java/net/pitan76/mcpitanlib/api/client/registry/fabric/KeybindingRegistryImpl.java b/fabric/src/main/java/net/pitan76/mcpitanlib/api/client/registry/fabric/KeybindingRegistryImpl.java new file mode 100644 index 000000000..c4be00558 --- /dev/null +++ b/fabric/src/main/java/net/pitan76/mcpitanlib/api/client/registry/fabric/KeybindingRegistryImpl.java @@ -0,0 +1,10 @@ +package net.pitan76.mcpitanlib.api.client.registry.fabric; + +import net.fabricmc.fabric.api.client.keymapping.v1.KeyMappingHelper; +import net.minecraft.client.KeyMapping; + +public class KeybindingRegistryImpl { + public static void register(KeyMapping keyBinding) { + KeyMappingHelper.registerKeyMapping(keyBinding); + } +} diff --git a/fabric/src/main/java/net/pitan76/mcpitanlib/api/command/fabric/CommandRegistryImpl.java b/fabric/src/main/java/net/pitan76/mcpitanlib/api/command/fabric/CommandRegistryImpl.java new file mode 100644 index 000000000..1aac2c12d --- /dev/null +++ b/fabric/src/main/java/net/pitan76/mcpitanlib/api/command/fabric/CommandRegistryImpl.java @@ -0,0 +1,44 @@ +package net.pitan76.mcpitanlib.api.command.fabric; + +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; +import net.minecraft.commands.CommandSourceStack; +import net.pitan76.mcpitanlib.api.command.CommandSettings; +import net.pitan76.mcpitanlib.api.command.LiteralCommand; +import net.pitan76.mcpitanlib.api.event.ServerCommandEvent; + +import static net.pitan76.mcpitanlib.api.command.CommandRegistry.forArgsCmd; +import static net.pitan76.mcpitanlib.api.command.CommandRegistry.latestCommandRegistryAccess; + +public class CommandRegistryImpl { + + public static void register(String name, LiteralCommand command) { + CommandRegistrationCallback.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) { + CommandRegistrationCallback.EVENT.register((dispatcher, registry, environment) -> { + latestCommandRegistryAccess = registry; + dispatcher.register(builder); + } + ); + } +} diff --git a/fabric/src/main/java/net/pitan76/mcpitanlib/api/event/v0/event/fabric/ServerConnectionEventImpl.java b/fabric/src/main/java/net/pitan76/mcpitanlib/api/event/v0/event/fabric/ServerConnectionEventImpl.java new file mode 100644 index 000000000..f7707c4cd --- /dev/null +++ b/fabric/src/main/java/net/pitan76/mcpitanlib/api/event/v0/event/fabric/ServerConnectionEventImpl.java @@ -0,0 +1,16 @@ +package net.pitan76.mcpitanlib.api.event.v0.event.fabric; + +import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents; +import net.pitan76.mcpitanlib.api.event.v0.EventRegistry; + +public class ServerConnectionEventImpl { + public static void join(EventRegistry.ServerConnection.PlayerJoin state) { + ServerPlayConnectionEvents.JOIN.register(((listener, _, _) + -> state.join(listener.getPlayer()))); + } + + public static void quit(EventRegistry.ServerConnection.PlayerQuit state) { + ServerPlayConnectionEvents.DISCONNECT.register(((listener, _) + -> state.quit(listener.getPlayer()))); + } +} diff --git a/fabric/src/main/java/net/pitan76/mcpitanlib/api/event/v0/fabric/AttackEntityEventRegistryImpl.java b/fabric/src/main/java/net/pitan76/mcpitanlib/api/event/v0/fabric/AttackEntityEventRegistryImpl.java new file mode 100644 index 000000000..606bdda7d --- /dev/null +++ b/fabric/src/main/java/net/pitan76/mcpitanlib/api/event/v0/fabric/AttackEntityEventRegistryImpl.java @@ -0,0 +1,10 @@ +package net.pitan76.mcpitanlib.api.event.v0.fabric; + +import net.fabricmc.fabric.api.event.player.AttackEntityCallback; +import net.pitan76.mcpitanlib.api.event.v0.AttackEntityEventRegistry; + +public class AttackEntityEventRegistryImpl { + public static void register(AttackEntityEventRegistry.AttackEntity attackEntity) { + AttackEntityCallback.EVENT.register(attackEntity::attack); + } +} diff --git a/fabric/src/main/java/net/pitan76/mcpitanlib/api/event/v0/fabric/ClientTickEventRegistryImpl.java b/fabric/src/main/java/net/pitan76/mcpitanlib/api/event/v0/fabric/ClientTickEventRegistryImpl.java new file mode 100644 index 000000000..ab67e82b5 --- /dev/null +++ b/fabric/src/main/java/net/pitan76/mcpitanlib/api/event/v0/fabric/ClientTickEventRegistryImpl.java @@ -0,0 +1,22 @@ +package net.pitan76.mcpitanlib.api.event.v0.fabric; + +import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; +import net.pitan76.mcpitanlib.api.event.v0.ClientTickEventRegistry; + +public class ClientTickEventRegistryImpl { + public static void registerPost(ClientTickEventRegistry.Client client) { + ClientTickEvents.END_CLIENT_TICK.register(client::tick); + } + + public static void registerPre(ClientTickEventRegistry.Client client) { + ClientTickEvents.START_CLIENT_TICK.register(client::tick); + } + + public static void registerLevelPost(ClientTickEventRegistry.ClientLevel world) { + ClientTickEvents.END_LEVEL_TICK.register(world::tick); + } + + public static void registerLevelPre(ClientTickEventRegistry.ClientLevel world) { + ClientTickEvents.START_LEVEL_TICK.register(world::tick); + } +} diff --git a/fabric/src/main/java/net/pitan76/mcpitanlib/api/event/v0/fabric/EventRegistryServerLifecycleImpl.java b/fabric/src/main/java/net/pitan76/mcpitanlib/api/event/v0/fabric/EventRegistryServerLifecycleImpl.java new file mode 100644 index 000000000..8b5e92085 --- /dev/null +++ b/fabric/src/main/java/net/pitan76/mcpitanlib/api/event/v0/fabric/EventRegistryServerLifecycleImpl.java @@ -0,0 +1,41 @@ +package net.pitan76.mcpitanlib.api.event.v0.fabric; + +import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLevelEvents; +import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; +import net.minecraft.server.level.ServerLevel; +import net.pitan76.mcpitanlib.api.event.v0.EventRegistry; + +public class EventRegistryServerLifecycleImpl { + public static void serverStarted(EventRegistry.ServerLifecycle.ServerState state) { + ServerLifecycleEvents.SERVER_STARTED.register(state::stateChanged); + } + + + public static void serverStarting(EventRegistry.ServerLifecycle.ServerState state) { + ServerLifecycleEvents.SERVER_STARTING.register(state::stateChanged); + } + + public static void serverStopped(EventRegistry.ServerLifecycle.ServerState state) { + ServerLifecycleEvents.SERVER_STOPPED.register(state::stateChanged); + } + + public static void serverStopping(EventRegistry.ServerLifecycle.ServerState state) { + ServerLifecycleEvents.SERVER_STOPPING.register(state::stateChanged); + } + + public static void serverWorldLoad(EventRegistry.ServerLifecycle.ServerWorldState state) { + ServerLevelEvents.LOAD.register((_, level) -> state.act(level)); + } + + public static void serverWorldSave(EventRegistry.ServerLifecycle.ServerWorldState state) { + ServerLifecycleEvents.AFTER_SAVE.register((server, _, _) -> { + for (ServerLevel level : server.getAllLevels()) { + state.act(level); + } + }); + } + + public static void serverWorldUnload(EventRegistry.ServerLifecycle.ServerWorldState state) { + ServerLevelEvents.UNLOAD.register((_, level) -> state.act(level)); + } +} diff --git a/fabric/src/main/java/net/pitan76/mcpitanlib/api/event/v0/fabric/InteractionEventRegistryImpl.java b/fabric/src/main/java/net/pitan76/mcpitanlib/api/event/v0/fabric/InteractionEventRegistryImpl.java new file mode 100644 index 000000000..fa79404fc --- /dev/null +++ b/fabric/src/main/java/net/pitan76/mcpitanlib/api/event/v0/fabric/InteractionEventRegistryImpl.java @@ -0,0 +1,42 @@ +package net.pitan76.mcpitanlib.api.event.v0.fabric; + +import net.fabricmc.fabric.api.event.client.player.ClientPlayerBlockBreakEvents; +import net.fabricmc.fabric.api.event.client.player.ClientPreAttackCallback; +import net.fabricmc.fabric.api.event.player.AttackBlockCallback; +import net.fabricmc.fabric.api.event.player.UseBlockCallback; +import net.fabricmc.fabric.api.event.player.UseEntityCallback; +import net.fabricmc.fabric.api.event.player.UseItemCallback; +import net.pitan76.mcpitanlib.api.event.v0.InteractionEventRegistry.*; +import net.pitan76.mcpitanlib.api.event.v0.event.ClickBlockEvent; + +public class InteractionEventRegistryImpl { + public static void registerRightClickBlock(RightClickBlock rightClickBlock) { + UseBlockCallback.EVENT.register((player, world, hand, result) -> rightClickBlock.click(new ClickBlockEvent(player, hand, result.getBlockPos(), result.getDirection())).toActionResult()); + } + + public static void registerLeftClickBlock(LeftClickBlock leftClickBlock) { + AttackBlockCallback.EVENT.register((player, world, hand, pos, dir) -> leftClickBlock.click(new ClickBlockEvent(player, hand, pos, dir)).toActionResult()); + } + + public static void registerRightClickItem(RightClickItem rightClickItem) { + UseItemCallback.EVENT.register((player, _, hand) + -> rightClickItem.click2(player, hand)); + } + + public static void registerClientLeftClickAir(ClientLeftClickAir clientLeftClickAir) { + ClientPreAttackCallback.EVENT.register((_, player, _) -> { + clientLeftClickAir.click(player, player.getUsedItemHand()); + return false; + }); + } + + public static void registerClientRightClickAir(ClientRightClickAir clientRightClickAir) { + ClientPlayerBlockBreakEvents.AFTER.register((_, player, _, _) + -> clientRightClickAir.click(player, player.getUsedItemHand())); + } + + public static void registerInteractEntity(InteractEntity interactEntity) { + UseEntityCallback.EVENT.register((player, _, hand, entity, _) + -> interactEntity.interact(player, entity, hand)); + } +} diff --git a/fabric/src/main/java/net/pitan76/mcpitanlib/api/event/v0/fabric/LivingHurtEventRegistryImpl.java b/fabric/src/main/java/net/pitan76/mcpitanlib/api/event/v0/fabric/LivingHurtEventRegistryImpl.java new file mode 100644 index 000000000..3344307f8 --- /dev/null +++ b/fabric/src/main/java/net/pitan76/mcpitanlib/api/event/v0/fabric/LivingHurtEventRegistryImpl.java @@ -0,0 +1,10 @@ +package net.pitan76.mcpitanlib.api.event.v0.fabric; + +import net.fabricmc.fabric.api.entity.event.v1.ServerLivingEntityEvents; +import net.pitan76.mcpitanlib.api.event.v0.LivingHurtEventRegistry; + +public class LivingHurtEventRegistryImpl { + public static void register(LivingHurtEventRegistry.LivingHurt livingHurt) { + ServerLivingEntityEvents.ALLOW_DAMAGE.register(livingHurt::hurt); + } +} diff --git a/fabric/src/main/java/net/pitan76/mcpitanlib/api/event/v1/fabric/AttackEntityEventRegistryImpl.java b/fabric/src/main/java/net/pitan76/mcpitanlib/api/event/v1/fabric/AttackEntityEventRegistryImpl.java new file mode 100644 index 000000000..4085df0d6 --- /dev/null +++ b/fabric/src/main/java/net/pitan76/mcpitanlib/api/event/v1/fabric/AttackEntityEventRegistryImpl.java @@ -0,0 +1,10 @@ +package net.pitan76.mcpitanlib.api.event.v1.fabric; + +import net.fabricmc.fabric.api.event.player.AttackEntityCallback; +import net.pitan76.mcpitanlib.api.event.v1.AttackEntityEventRegistry; + +public class AttackEntityEventRegistryImpl { + public static void register(AttackEntityEventRegistry.AttackEntity attackEntity) { + AttackEntityCallback.EVENT.register(attackEntity::attack); + } +} diff --git a/fabric/src/main/java/net/pitan76/mcpitanlib/api/event/v1/fabric/LivingHurtEventRegistryImpl.java b/fabric/src/main/java/net/pitan76/mcpitanlib/api/event/v1/fabric/LivingHurtEventRegistryImpl.java new file mode 100644 index 000000000..b61bd34e4 --- /dev/null +++ b/fabric/src/main/java/net/pitan76/mcpitanlib/api/event/v1/fabric/LivingHurtEventRegistryImpl.java @@ -0,0 +1,10 @@ +package net.pitan76.mcpitanlib.api.event.v1.fabric; + +import net.fabricmc.fabric.api.entity.event.v1.ServerLivingEntityEvents; +import net.pitan76.mcpitanlib.api.event.v1.LivingHurtEventRegistry; + +public class LivingHurtEventRegistryImpl { + public static void register(LivingHurtEventRegistry.LivingHurt livingHurt) { + ServerLivingEntityEvents.ALLOW_DAMAGE.register(livingHurt::hurt); + } +} 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..8760877af --- /dev/null +++ b/fabric/src/main/java/net/pitan76/mcpitanlib/api/extra/transfer/util/FluidStorageUtil.java @@ -0,0 +1,99 @@ +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.nbt.CompoundTag; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.material.FluidState; +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.registry.CompatRegistryLookup; +import net.pitan76.mcpitanlib.core.mc1216.NbtDataConverter; + +public class FluidStorageUtil { + public static SingleFluidStorage withFixedCapacity(long capacity, Runnable onChange) { + return SingleFluidStorage.withFixedCapacity(capacity, onChange); + } + + public static void readNbt(SingleFluidStorage storage, NbtRWArgs args) { + if (args instanceof ReadNbtArgs) + storage.readValue(((ReadNbtArgs) args).view); + } + + public static void writeNbt(SingleFluidStorage storage, NbtRWArgs args) { + if (args instanceof WriteNbtArgs) + storage.writeValue(((WriteNbtArgs) args).view); + } + + public static void readNbt(SingleFluidStorage storage, CompoundTag nbt, CompatRegistryLookup registryLookup) { + storage.readValue(NbtDataConverter.nbt2readData(nbt, registryLookup)); + } + + public static void writeNbt(SingleFluidStorage storage, CompoundTag nbt, CompatRegistryLookup registryLookup) { + storage.writeValue(NbtDataConverter.nbt2writeData(nbt, registryLookup)); + } + + /** + * @deprecated Use {@link #readNbt(SingleFluidStorage, NbtRWArgs)} instead + */ + @Deprecated + public static void readNbt(SingleFluidStorage storage, CompoundTag nbt, Level world) { + readNbt(storage, nbt, new CompatRegistryLookup(world.registryAccess())); + } + + /** + * @deprecated Use {@link #writeNbt(SingleFluidStorage, NbtRWArgs)} instead + */ + @Deprecated + public static void writeNbt(SingleFluidStorage storage, CompoundTag nbt, Level world) { + writeNbt(storage, nbt, new CompatRegistryLookup(world.registryAccess())); + } + + 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.getType()), maxAmount, transaction); + transaction.commit(); + } + } + + public static void extract(SingleFluidStorage storage, FluidState fluidState, long maxAmount) { + try (Transaction transaction = Transaction.openOuter()) { + extract(storage, FluidVariant.of(fluidState.getType()), 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); + } +} \ No newline at end of file diff --git a/fabric/src/main/java/net/pitan76/mcpitanlib/api/gui/fabric/ExtendedScreenHandlerTypeBuilderImpl.java b/fabric/src/main/java/net/pitan76/mcpitanlib/api/gui/fabric/ExtendedScreenHandlerTypeBuilderImpl.java new file mode 100644 index 000000000..967ffa3ba --- /dev/null +++ b/fabric/src/main/java/net/pitan76/mcpitanlib/api/gui/fabric/ExtendedScreenHandlerTypeBuilderImpl.java @@ -0,0 +1,12 @@ +package net.pitan76.mcpitanlib.api.gui.fabric; + +import net.fabricmc.fabric.api.menu.v1.ExtendedMenuType; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.MenuType; +import net.pitan76.mcpitanlib.api.gui.ExtendedScreenHandlerTypeBuilder; + +public class ExtendedScreenHandlerTypeBuilderImpl { + public static MenuType build(ExtendedScreenHandlerTypeBuilder.Factory factory) { + return new ExtendedMenuType<>(factory::create, ExtendedScreenHandlerTypeBuilder.CODEC); + } +} diff --git a/fabric/src/main/java/net/pitan76/mcpitanlib/api/gui/fabric/SimpleScreenHandlerTypeBuilderImpl.java b/fabric/src/main/java/net/pitan76/mcpitanlib/api/gui/fabric/SimpleScreenHandlerTypeBuilderImpl.java new file mode 100644 index 000000000..044c96ebb --- /dev/null +++ b/fabric/src/main/java/net/pitan76/mcpitanlib/api/gui/fabric/SimpleScreenHandlerTypeBuilderImpl.java @@ -0,0 +1,12 @@ +package net.pitan76.mcpitanlib.api.gui.fabric; + +import net.minecraft.world.flag.FeatureFlags; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.MenuType; +import net.pitan76.mcpitanlib.api.gui.SimpleScreenHandlerTypeBuilder; + +public class SimpleScreenHandlerTypeBuilderImpl { + public static MenuType build(SimpleScreenHandlerTypeBuilder.Factory factory) { + return new MenuType<>(factory::create, FeatureFlags.VANILLA_SET); + } +} diff --git a/fabric/src/main/java/net/pitan76/mcpitanlib/api/item/fabric/CreativeTabBuilderImpl.java b/fabric/src/main/java/net/pitan76/mcpitanlib/api/item/fabric/CreativeTabBuilderImpl.java new file mode 100644 index 000000000..2fd7e3767 --- /dev/null +++ b/fabric/src/main/java/net/pitan76/mcpitanlib/api/item/fabric/CreativeTabBuilderImpl.java @@ -0,0 +1,29 @@ +package net.pitan76.mcpitanlib.api.item.fabric; + +import net.fabricmc.fabric.api.creativetab.v1.FabricCreativeModeTab; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.Identifier; +import net.minecraft.world.item.CreativeModeTab; +import net.minecraft.world.item.ItemStack; +import net.pitan76.mcpitanlib.api.util.IdentifierUtil; +import net.pitan76.mcpitanlib.api.util.TextUtil; + +import java.util.function.Supplier; + +public class CreativeTabBuilderImpl { + + public static CreativeModeTab build(Identifier identifier, Component displayName, Supplier iconSupplier, boolean noRenderedName, boolean noScrollbar, boolean special, String texture) { + CreativeModeTab.Builder builder = FabricCreativeModeTab.builder(); + + if (displayName != null) builder.title(displayName); + else builder.title(TextUtil.translatable("itemGroup." + identifier.getNamespace() + "." + identifier.getPath())); + + if (iconSupplier != null) builder.icon(iconSupplier); + if (noRenderedName) builder.hideTitle(); + if (noScrollbar) builder.noScrollBar(); + if (special) builder.alignedRight(); + if (texture != null) builder.backgroundTexture(IdentifierUtil.id(texture)); + + return builder.build(); + } +} 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..64943d6ab --- /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.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.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.core.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.core.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..fbdb36745 --- /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.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.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..4a782142f --- /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.blockgetter.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/BlockEntityTypeBuilderImpl.java b/fabric/src/main/java/net/pitan76/mcpitanlib/api/tile/fabric/BlockEntityTypeBuilderImpl.java new file mode 100644 index 000000000..f0e546dd4 --- /dev/null +++ b/fabric/src/main/java/net/pitan76/mcpitanlib/api/tile/fabric/BlockEntityTypeBuilderImpl.java @@ -0,0 +1,16 @@ +package net.pitan76.mcpitanlib.api.tile.fabric; + +import com.mojang.datafixers.types.Type; +import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.pitan76.mcpitanlib.api.tile.BlockEntityTypeBuilder; + +public class BlockEntityTypeBuilderImpl { + @Deprecated + public static BlockEntityType build(Type type, BlockEntityTypeBuilder.Factory factory, Block... blocks) { + FabricBlockEntityTypeBuilder builder = FabricBlockEntityTypeBuilder.create(factory::create, blocks); + return builder.build(type); + } +} 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..11763ed2a --- /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.blockgetter.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..8c9bdf68e --- /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.writeValue(args.view); + } + + @Override + public void readNbt(ReadNbtArgs args) { + storage.readValue(args.view); + + } +} 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..ea29c5b71 --- /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.world.level.material.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..ae5b9ae98 --- /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.world.level.material.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..bc2118aa1 --- /dev/null +++ b/fabric/src/main/java/net/pitan76/mcpitanlib/api/util/fabric/PlatformUtilImpl.java @@ -0,0 +1,57 @@ +package net.pitan76.mcpitanlib.api.util.fabric; + +import net.fabricmc.api.EnvType; +import net.fabricmc.loader.api.FabricLoader; + +import java.nio.file.Path; +import java.util.Collection; + +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); + } + + public static boolean isDevelopmentEnvironment() { + return FabricLoader.getInstance().isDevelopmentEnvironment(); + } + + public static Path getGameFolder() { + return FabricLoader.getInstance().getGameDir(); + } + + public static Collection getModIds() { + return FabricLoader.getInstance().getAllMods().stream().map(modContainer -> modContainer.getMetadata().getId()).toList(); + } + + public static EnvType getEnv() { + return FabricLoader.getInstance().getEnvironmentType(); + } + + public static String getGameVersion() { + return FabricLoader.getInstance().getRawGameVersion(); + } + + public static boolean isFabric() { + return true; + } + + public static boolean isForge() { + return false; + } + + public static boolean isNeoForge() { + return false; + } +} diff --git a/fabric/src/main/java/net/pitan76/mcpitanlib/core/mc261/fabric/ClientPlayNetworkingImpl.java b/fabric/src/main/java/net/pitan76/mcpitanlib/core/mc261/fabric/ClientPlayNetworkingImpl.java new file mode 100644 index 000000000..9ef0e03bb --- /dev/null +++ b/fabric/src/main/java/net/pitan76/mcpitanlib/core/mc261/fabric/ClientPlayNetworkingImpl.java @@ -0,0 +1,36 @@ +package net.pitan76.mcpitanlib.core.mc261.fabric; + +import io.netty.buffer.Unpooled; +import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; +import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry; +import net.minecraft.client.Minecraft; +import net.minecraft.client.player.LocalPlayer; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import net.minecraft.resources.Identifier; +import net.pitan76.mcpitanlib.api.network.ClientNetworking; +import net.pitan76.mcpitanlib.core.network.BufPayload; + +public class ClientPlayNetworkingImpl { + public static void send(CustomPacketPayload payload) { + ClientPlayNetworking.send(payload); + } + + public static void registerGlobalReceiver(BufPayload.Type type, ClientNetworking.ClientNetworkHandler handler) { + ClientPlayNetworking.registerGlobalReceiver(type, (payload, context) -> { + FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.wrappedBuffer(payload.getData())); + + LocalPlayer player = null; + if (context.player() instanceof LocalPlayer) + player = context.player(); + + handler.receive(Minecraft.getInstance(), player, buf); + buf.release(); + }); + } + + public static void registerC2SPayloadType(Identifier identifier) { + BufPayload.Type id = BufPayload.id(identifier); + PayloadTypeRegistry.clientboundPlay().register(id, BufPayload.getCodec(id)); + } +} diff --git a/fabric/src/main/java/net/pitan76/mcpitanlib/core/mc261/fabric/CreativeModeTabEventRegistryImpl.java b/fabric/src/main/java/net/pitan76/mcpitanlib/core/mc261/fabric/CreativeModeTabEventRegistryImpl.java new file mode 100644 index 000000000..3aa7f09f3 --- /dev/null +++ b/fabric/src/main/java/net/pitan76/mcpitanlib/core/mc261/fabric/CreativeModeTabEventRegistryImpl.java @@ -0,0 +1,19 @@ +package net.pitan76.mcpitanlib.core.mc261.fabric; + +import net.fabricmc.fabric.api.creativetab.v1.CreativeModeTabEvents; +import net.minecraft.resources.ResourceKey; +import net.minecraft.world.item.CreativeModeTab; +import net.minecraft.world.item.ItemStack; + +import java.util.List; +import java.util.function.Supplier; + +public class CreativeModeTabEventRegistryImpl { + public static void addStack(ResourceKey key, Supplier supplier) { + CreativeModeTabEvents.modifyOutputEvent(key).register(entries -> entries.accept(supplier.get())); + } + + public static void addStacks(ResourceKey key, Supplier> supplier) { + CreativeModeTabEvents.modifyOutputEvent(key).register(entries -> entries.acceptAll(supplier.get())); + } +} diff --git a/fabric/src/main/java/net/pitan76/mcpitanlib/core/mc261/fabric/ServerPlayNetworkingImpl.java b/fabric/src/main/java/net/pitan76/mcpitanlib/core/mc261/fabric/ServerPlayNetworkingImpl.java new file mode 100644 index 000000000..4efffea06 --- /dev/null +++ b/fabric/src/main/java/net/pitan76/mcpitanlib/core/mc261/fabric/ServerPlayNetworkingImpl.java @@ -0,0 +1,39 @@ +package net.pitan76.mcpitanlib.core.mc261.fabric; + +import io.netty.buffer.Unpooled; +import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry; +import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import net.minecraft.resources.Identifier; +import net.minecraft.server.level.ServerPlayer; +import net.pitan76.mcpitanlib.api.network.ServerNetworking; +import net.pitan76.mcpitanlib.core.network.BufPayload; + +import java.util.ArrayList; +import java.util.List; + +public class ServerPlayNetworkingImpl { + + public static void send(ServerPlayer player, CustomPacketPayload payload) { + ServerPlayNetworking.send(player, payload); + } + + public static void registerGlobalReceiver(CustomPacketPayload.Type id, ServerNetworking.ServerNetworkHandler handler) { + ServerPlayNetworking.registerGlobalReceiver(id, (payload, context) -> { + FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.wrappedBuffer(payload.getData())); + handler.receive(context.server(), context.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); + + BufPayload.Type id = BufPayload.id(identifier); + PayloadTypeRegistry.serverboundPlay().register(id, BufPayload.getCodec(id)); + } +} diff --git a/fabric/src/main/java/net/pitan76/mcpitanlib/core/registry/fabric/FuelRegistryImpl.java b/fabric/src/main/java/net/pitan76/mcpitanlib/core/registry/fabric/FuelRegistryImpl.java new file mode 100644 index 000000000..a07eb226f --- /dev/null +++ b/fabric/src/main/java/net/pitan76/mcpitanlib/core/registry/fabric/FuelRegistryImpl.java @@ -0,0 +1,12 @@ +package net.pitan76.mcpitanlib.core.registry.fabric; + +import net.fabricmc.fabric.api.registry.FuelValueEvents; +import net.minecraft.world.level.ItemLike; + +import java.util.function.Supplier; + +public class FuelRegistryImpl { + public static void register(int time, Supplier item) { + FuelValueEvents.BUILD.register((builder, context) -> builder.add(item.get(), context.baseSmeltTime() * time)); + } +} diff --git a/fabric/src/main/java/net/pitan76/mcpitanlib/core/registry/fabric/RegistryImpl.java b/fabric/src/main/java/net/pitan76/mcpitanlib/core/registry/fabric/RegistryImpl.java new file mode 100644 index 000000000..899cb3277 --- /dev/null +++ b/fabric/src/main/java/net/pitan76/mcpitanlib/core/registry/fabric/RegistryImpl.java @@ -0,0 +1,73 @@ +package net.pitan76.mcpitanlib.core.registry.fabric; + +import net.minecraft.core.Registry; +import net.minecraft.core.component.DataComponentType; +import net.minecraft.core.particles.ParticleType; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.core.registries.Registries; +import net.minecraft.resources.Identifier; +import net.minecraft.resources.ResourceKey; +import net.minecraft.server.level.TicketType; +import net.minecraft.sounds.SoundEvent; +import net.minecraft.world.effect.MobEffect; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.CreativeModeTab; +import net.minecraft.world.item.Item; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.level.material.Fluid; +import net.pitan76.mcpitanlib.api.registry.result.RegistrySupplier; +import net.pitan76.mcpitanlib.midohra.world.chunk.ChunkTicketType; + +import java.util.function.Supplier; + +public class RegistryImpl { + public static RegistrySupplier registryItem(Identifier id, Supplier supplier) { + return new RegistrySupplier<>(Registry.register(BuiltInRegistries.ITEM, ResourceKey.create(Registries.ITEM, id), supplier.get())); + } + + public static RegistrySupplier registryBlock(Identifier id, Supplier supplier) { + return new RegistrySupplier<>(Registry.register(BuiltInRegistries.BLOCK, ResourceKey.create(Registries.BLOCK, id), supplier.get())); + } + + public static RegistrySupplier> registryScreenHandlerType(Identifier id, Supplier> supplier) { + return new RegistrySupplier<>(Registry.register(BuiltInRegistries.MENU, ResourceKey.create(Registries.MENU, id), supplier.get())); + } + + public static RegistrySupplier> registryBlockEntityType(Identifier id, Supplier> supplier) { + return new RegistrySupplier<>(Registry.register(BuiltInRegistries.BLOCK_ENTITY_TYPE, ResourceKey.create(Registries.BLOCK_ENTITY_TYPE, id), supplier.get())); + } + + public static RegistrySupplier> registryEntityType(Identifier id, Supplier> supplier) { + return new RegistrySupplier<>(Registry.register(BuiltInRegistries.ENTITY_TYPE, ResourceKey.create(Registries.ENTITY_TYPE, id), supplier.get())); + } + + public static RegistrySupplier registrySoundEvent(Identifier id, Supplier supplier) { + return new RegistrySupplier<>(Registry.register(BuiltInRegistries.SOUND_EVENT, ResourceKey.create(Registries.SOUND_EVENT, id), supplier.get())); + } + + public static RegistrySupplier registryFluid(Identifier id, Supplier supplier) { + return new RegistrySupplier<>(Registry.register(BuiltInRegistries.FLUID, ResourceKey.create(Registries.FLUID, id), supplier.get())); + } + + public static RegistrySupplier> registryParticleType(Identifier id, Supplier> supplier) { + return new RegistrySupplier<>(Registry.register(BuiltInRegistries.PARTICLE_TYPE, ResourceKey.create(Registries.PARTICLE_TYPE, id), supplier.get())); + } + + public static RegistrySupplier registryStatusEffect(Identifier id, Supplier supplier) { + return new RegistrySupplier<>(Registry.register(BuiltInRegistries.MOB_EFFECT, ResourceKey.create(Registries.MOB_EFFECT, id), supplier.get())); + } + + public static RegistrySupplier registryItemGroup(Identifier id, Supplier supplier) { + return new RegistrySupplier<>(Registry.register(BuiltInRegistries.CREATIVE_MODE_TAB, ResourceKey.create(Registries.CREATIVE_MODE_TAB, id), supplier.get())); + } + + public static RegistrySupplier> registryDataComponentType(Identifier id, Supplier> supplier) { + return new RegistrySupplier<>(Registry.register(BuiltInRegistries.DATA_COMPONENT_TYPE, ResourceKey.create(Registries.DATA_COMPONENT_TYPE, id), supplier.get())); + } + + public static Supplier> registryChunkTicketType(Identifier id, Supplier supplier) { + return () -> ChunkTicketType.of(Registry.register(BuiltInRegistries.TICKET_TYPE, ResourceKey.create(Registries.TICKET_TYPE, id), supplier.get())); + } +} 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..c8deb4a3b --- /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.resources.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); + } +} \ No newline at end of file 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/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json index b6234c75d..7a3a430c5 100644 --- a/fabric/src/main/resources/fabric.mod.json +++ b/fabric/src/main/resources/fabric.mod.json @@ -1,31 +1,40 @@ { "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-common.mixins.json" ], + "accessWidener": "mcpitanlib.accesswidener", "depends": { - "fabricloader": ">=0.14.9", - "minecraft": ">=1.18" + "minecraft": ">=26.1", + "fabricloader": "*" } } diff --git a/fabric/src/main/resources/mcpitanlibarch.mixins.json b/fabric/src/main/resources/mcpitanlibarch.mixins.json deleted file mode 100644 index 4be53d8ed..000000000 --- a/fabric/src/main/resources/mcpitanlibarch.mixins.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "required": true, - "minVersion": "0.8", - "package": "ml.pkom.mcpitanlibarch.mixin.fabric", - "compatibilityLevel": "JAVA_17", - "mixins": [ - ], - "client": [ - ], - "injectors": { - "defaultRequire": 1 - } -} diff --git a/forge/build.gradle b/forge/build.gradle deleted file mode 100644 index 01c52e51f..000000000 --- a/forge/build.gradle +++ /dev/null @@ -1,75 +0,0 @@ -plugins { - id "com.github.johnrengelman.shadow" version "7.1.2" -} -architectury { - platformSetupLoomIde() - forge() -} - -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 - developmentForge.extendsFrom common -} - -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}" - - common(project(path: ":common", configuration: "namedElements")) { transitive false } - shadowCommon(project(path: ":common", configuration: "transformProductionForge")) { transitive = false } -} - -processResources { - inputs.property "version", project.version - - filesMatching("META-INF/mods.toml") { - expand "version": project.version - } -} - -shadowJar { - exclude "fabric.mod.json" - - configurations = [project.configurations.shadowCommon] - classifier "dev-shadow" -} - -remapJar { - input.set shadowJar.archiveFile - dependsOn shadowJar - classifier null -} - -jar { - classifier "dev" -} - -sourcesJar { - def commonSources = project(":common").sourcesJar - dependsOn commonSources - from commonSources.archiveFile.map { zipTree(it) } -} - -components.java { - withVariantsFromConfiguration(project.configurations.shadowRuntimeElements) { - skip() - } -} - -publishing { - publications { - mavenForge(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/forge/gradle.properties b/forge/gradle.properties deleted file mode 100644 index 32f842a63..000000000 --- a/forge/gradle.properties +++ /dev/null @@ -1 +0,0 @@ -loom.platform=forge \ No newline at end of file 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/resources/META-INF/mods.toml b/forge/src/main/resources/META-INF/mods.toml deleted file mode 100644 index d222c9899..000000000 --- a/forge/src/main/resources/META-INF/mods.toml +++ /dev/null @@ -1,58 +0,0 @@ -# This is an example mods.toml file. It contains the data relating to the loading mods. -# There are several mandatory fields (#mandatory), and many more that are optional (#optional). -# The overall format is standard TOML format, v0.5.0. -# Note that there are a couple of TOML lists in this file. -# Find more information on toml format here: https://github.com/toml-lang/toml -# The name of the mod loader type to load - for regular FML @Mod mods it should be javafml -modLoader = "javafml" #mandatory -# A version range to match for said mod loader - for regular FML @Mod it will be the forge version -loaderVersion = "[40,)" #mandatory This is typically bumped every Minecraft version by Forge. See our download page for lists of versions. -# The license for you mod. This is mandatory metadata and allows for easier comprehension of your redistributive properties. -# 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" -# 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 -# 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 -# 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 -displayURL = "https://www.curseforge.com/minecraft/mc-mods/mcpitanlibarch" -# A file name (in the root of the mod JAR) containing a logo for display -logoFile = "icon.png" #optional -# A text field displayed in the mod UI -#credits="Thanks for this example mod goes to Java" #optional -# A text field displayed in the mod UI -authors = "Pitan" #optional -# The description text for the mod (multi line!) (#mandatory) -description = ''' -Pitan's Minecraft Mod Library -''' -# A dependency - use the . to indicate dependency for a specific modid. Dependencies are optional. -[[dependencies.mcpitanlibarch]] #optional -# the modid of the dependency -modId = "forge" #mandatory -# Does this dependency have to exist - if not, ordering below must be specified -mandatory = true #mandatory -# The version range of the dependency -versionRange = "[40,)" #mandatory -# An ordering relationship for the dependency - BEFORE or AFTER required if the relationship is not mandatory -ordering = "NONE" -# Side this dependency is applied on - BOTH, CLIENT or SERVER -side = "BOTH" -# Here's another dependency -[[dependencies.mcpitanlibarch]] -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,)" -ordering = "NONE" -side = "BOTH" diff --git a/forge/src/main/resources/mcpitanlibarch.mixins.json b/forge/src/main/resources/mcpitanlibarch.mixins.json deleted file mode 100644 index 72d6fe3ab..000000000 --- a/forge/src/main/resources/mcpitanlibarch.mixins.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "required": true, - "minVersion": "0.8", - "package": "ml.pkom.mcpitanlibarch.mixin.forge", - "compatibilityLevel": "JAVA_17", - "mixins": [ - ], - "client": [ - ], - "injectors": { - "defaultRequire": 1 - } -} diff --git a/gradle.properties b/gradle.properties index 0277f9edc..784f528fc 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,17 +1,27 @@ org.gradle.jvmargs=-Xmx3G -minecraft_version=1.18.2 -archives_base_name=mcpitanlibarch -mod_version=1.0.0 -maven_group=ml.pkom +minecraft_version=26.1 # https://www.curseforge.com/minecraft/mc-mods/architectury-api -architectury_version=4.9.84 +#architectury_version=19.0.1 # 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.18.6 +fabric_api_version=0.145.1+26.1 -# https://files.minecraftforge.net/net/minecraftforge/forge/ -forge_version=1.18.2-40.1.80 +# https://projects.neoforged.net/neoforged/neoforge +neoforge_version=26.1.0.1-beta + +cloth_config_version=26.1.154 + +# https://maven.pitan76.net/net/pitan76/compatdatapacks76/ +compatdatapacks76_version=1.0.17.261-SNAPSHOT +legacyitemmodels_version=1.0.3.261-SNAPSHOT +littleintermediaryfallback_version=1.0.0.261-20260419.164849-3 +littleoldnamedfallback_version=1.0.0.261-SNAPSHOT + +fabricEnabled=true +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..f50f69e32 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-9.4.0-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/info.properties b/info.properties new file mode 100644 index 000000000..ee0f8ebf5 --- /dev/null +++ b/info.properties @@ -0,0 +1,4 @@ +archives_base_name=mcpitanlib +mod_version=3.7.0 +maven_group=net.pitan76 +changelog=fix APIs \ No newline at end of file diff --git a/neoforge/build.gradle b/neoforge/build.gradle new file mode 100644 index 000000000..d30f9cf8d --- /dev/null +++ b/neoforge/build.gradle @@ -0,0 +1,105 @@ +plugins { + id "com.gradleup.shadow" version "9.4.0" +} + +architectury { + platformSetupLoomIde() + neoForge() +} + +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 + developmentNeoForge.extendsFrom common + + apiElements { + outgoing.artifacts.clear() + outgoing.artifact(shadowJar) + } + runtimeElements { + outgoing.artifacts.clear() + outgoing.artifact(shadowJar) + } +} + +dependencies { + neoForge "net.neoforged:neoforge:${rootProject.neoforge_version}" + + common(project(path: ":common")) { 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}") + include("net.pitan76:legacyitemmodels-neoforge:${rootProject.legacyitemmodels_version}") + include("net.pitan76:legacyitemmodels-neoforge:${rootProject.legacyitemmodels_version}") + include("net.pitan76:littleoldnamedfallback:${rootProject.littleoldnamedfallback_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" + + dependsOn(jar) + mainSpec.sourcePaths.clear() + from(zipTree(jar.archiveFile)) + + configurations = [project.configurations.shadowCommon] + archiveClassifier.set(null) +} + +jar { + setArchiveClassifier("dev") +} + +sourcesJar { + def commonSources = project(":common").sourcesJar + dependsOn commonSources + from commonSources.archiveFile.map { zipTree(it) } +} + +shadow { + addShadowVariantIntoJavaComponent = false +} + +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/ItemTooltipRegistryImpl.java b/neoforge/src/main/java/net/pitan76/mcpitanlib/api/client/event/neoforge/ItemTooltipRegistryImpl.java new file mode 100644 index 000000000..a9b689eee --- /dev/null +++ b/neoforge/src/main/java/net/pitan76/mcpitanlib/api/client/event/neoforge/ItemTooltipRegistryImpl.java @@ -0,0 +1,23 @@ +package net.pitan76.mcpitanlib.api.client.event.neoforge; + +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.neoforge.event.entity.player.ItemTooltipEvent; +import net.pitan76.mcpitanlib.api.client.event.listener.ItemTooltipListener; + +import java.util.ArrayList; +import java.util.List; + +public class ItemTooltipRegistryImpl { + private static final List listeners = new ArrayList<>(); + + public static void registerItemTooltip(ItemTooltipListener listener) { + listeners.add(listener); + } + + @SubscribeEvent + public static void onItemTooltip(ItemTooltipEvent event) { + for (ItemTooltipListener listener : listeners) { + listener.onTooltip(event.getItemStack(), event.getToolTip(), event.getContext(), event.getFlags()); + } + } +} 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..d2265f2cf --- /dev/null +++ b/neoforge/src/main/java/net/pitan76/mcpitanlib/api/client/event/neoforge/WorldRenderRegistryImpl.java @@ -0,0 +1,219 @@ +package net.pitan76.mcpitanlib.api.client.event.neoforge; + +import com.mojang.blaze3d.vertex.PoseStack; +import net.minecraft.client.Camera; +import net.minecraft.client.multiplayer.ClientLevel; +import net.minecraft.client.renderer.GameRenderer; +import net.minecraft.client.renderer.LevelRenderer; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.culling.Frustum; +import net.neoforged.neoforge.client.event.ExtractBlockOutlineRenderStateEvent; +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 net.pitan76.mcpitanlib.api.util.client.ClientUtil; +import org.jetbrains.annotations.Nullable; +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(ExtractBlockOutlineRenderStateEvent event) { + for (BeforeBlockOutlineListener listener : beforeBlockOutlineListeners) { + boolean eventContinue = listener.beforeBlockOutline(new BeforeBlockOutlineEvent(new WorldRenderContext() { + @Override + public LevelRenderer getWorldRenderer() { + return event.getLevelRenderer(); + } + + @Override + public PoseStack getMatrixStack() { + return new PoseStack(); + } + + @Override + public float getTickDelta() { + return ClientUtil.getClient().getDeltaTracker().getGameTimeDeltaTicks(); + } + + @Override + public Camera getCamera() { + return event.getCamera(); + } + + @Override + public GameRenderer getGameRenderer() { + return ClientUtil.getClient().gameRenderer; + } + + @Deprecated + @Override + public Matrix4f getProjectionMatrix() { + return null; + } + + @Override + public ClientLevel getWorld() { + return ClientUtil.getClient().level; + } + + @Deprecated + @Override + public boolean isAdvancedTranslucency() { + return event.isInTranslucentPass(); + } + + @Override + public @Nullable MultiBufferSource getConsumers() { + return ClientUtil.getClient().renderBuffers().bufferSource(); + } + + @Override + public Frustum getFrustum() { + return ClientUtil.getClient().gameRenderer.getMainCamera().getCapturedFrustum(); + } + }, event.getLevelRenderState().blockOutlineRenderState)); + + 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().getDynamicDeltaTicks(); +// } +// +// @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.AfterLevel event) { + for (WorldRenderContextListener listener : worldRenderAfterLevelListeners) { + listener.render(new WorldRenderContext() { + @Override + public LevelRenderer getWorldRenderer() { + return event.getLevelRenderer(); + } + + @Override + public PoseStack getMatrixStack() { + return event.getPoseStack(); + } + + @Override + public float getTickDelta() { + return event.getLevelRenderer().getTicks(); + } + + @Override + public Camera getCamera() { + return ClientUtil.getGameRenderer().getMainCamera(); + } + + @Override + public GameRenderer getGameRenderer() { + return ClientUtil.getGameRenderer(); + } + + @Override + public Matrix4f getProjectionMatrix() { + return null; + } + + @Override + public ClientLevel getWorld() { + return ClientUtil.getWorld(); + } + + @Deprecated + @Override + public boolean isAdvancedTranslucency() { + return false; + } + + @Override + public @Nullable MultiBufferSource getConsumers() { + return ClientUtil.getClient().renderBuffers().bufferSource(); + } + + @Override + public Frustum getFrustum() { + return ClientUtil.getGameRenderer().getMainCamera().getCapturedFrustum(); + } + }); + } + } + + 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..5a25bd562 --- /dev/null +++ b/neoforge/src/main/java/net/pitan76/mcpitanlib/api/client/registry/neoforge/CompatRegistryClientImpl.java @@ -0,0 +1,134 @@ +package net.pitan76.mcpitanlib.api.client.registry.neoforge; + +import net.minecraft.client.color.block.BlockTintSource; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.gui.screens.inventory.MenuAccess; +import net.minecraft.client.model.geom.ModelLayerLocation; +import net.minecraft.client.model.geom.builders.LayerDefinition; +import net.minecraft.client.particle.ParticleProvider; +import net.minecraft.client.renderer.blockentity.state.BlockEntityRenderState; +import net.minecraft.client.renderer.entity.EntityRendererProvider; +import net.minecraft.client.renderer.texture.TextureAtlas; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.core.particles.ParticleOptions; +import net.minecraft.core.particles.ParticleType; +import net.minecraft.util.RandomSource; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.fml.common.EventBusSubscriber; +import net.neoforged.neoforge.client.event.EntityRenderersEvent; +import net.neoforged.neoforge.client.event.RegisterColorHandlersEvent; +import net.neoforged.neoforge.client.event.RegisterMenuScreensEvent; +import net.neoforged.neoforge.client.event.RegisterParticleProvidersEvent; +import net.pitan76.mcpitanlib.api.client.registry.CompatRegistryClient; +import net.pitan76.mcpitanlib.api.client.render.EntityModelLayerContext; + +import java.util.*; +import java.util.function.Consumer; +import java.util.function.Supplier; + +@EventBusSubscriber(modid = "mcpitanlib", value = Dist.CLIENT) +public class CompatRegistryClientImpl { + private static final List> screenRegistrations = new ArrayList<>(); + private static final List> particleRegistrations = new ArrayList<>(); + private static final List> layerRegistrations = new ArrayList<>(); + private static final List> rendererRegistrations = new ArrayList<>(); + + public static Map, Block[]> blockColorProviders = new HashMap<>(); + + public static > void registerScreen(String modId, MenuType type, CompatRegistryClient.ScreenFactory factory) { + screenRegistrations.add(event -> event.register(type, factory::create)); + } + + public static void registerParticle(ParticleType type, ParticleProvider factory) { + particleRegistrations.add(event -> event.registerSpecial(type, factory)); + } + + public static void registerParticle(ParticleType type, CompatRegistryClient.DeferredParticleProvider provider) { + particleRegistrations.add(event -> event.registerSpriteSet(type, spriteSet -> provider.create(new CompatRegistryClient.ExtendedSpriteSet() { + @Override + public TextureAtlas getAtlas() { return null; } + @Override + public List getSprites() { return Collections.emptyList(); } + @Override + public TextureAtlasSprite get(int age, int maxAge) { return spriteSet.get(age, maxAge); } + @Override + public TextureAtlasSprite get(RandomSource random) { return spriteSet.get(random); } + @Override + public TextureAtlasSprite first() { return spriteSet.first(); } + }))); + } + + public static void registerEntityModelLayer(ModelLayerLocation layer, EntityModelLayerContext context) { + layerRegistrations.add(event -> event.registerLayerDefinition(layer, () -> LayerDefinition.create(context.getData(), context.getWidth(), context.getHeight()))); + } + + public static void registerEntityRenderer(Supplier> type, EntityRendererProvider provider) { + rendererRegistrations.add(event -> event.registerEntityRenderer(type.get(), provider)); + } + + public static void registerBlockEntityRenderer(BlockEntityType type, CompatRegistryClient.BlockEntityRendererFactory provider) { + rendererRegistrations.add(event -> event.registerBlockEntityRenderer(type, ctx -> provider.create(new CompatRegistryClient.BlockEntityRendererFactory.Context( + ctx.blockEntityRenderDispatcher(), ctx.blockModelResolver(), ctx.itemModelResolver(), ctx.entityRenderer(), ctx.entityModelSet(), ctx.font(), ctx.sprites(), ctx.playerSkinRenderCache() + )))); + } + + public static void registerCompatBlockEntityRenderer(BlockEntityType type, CompatRegistryClient.BlockEntityRendererFactory provider) { + registerBlockEntityRenderer(type, provider); + } + + public static void registerColorProviderBlock(List provider, Block... blocks) { + blockColorProviders.put(provider, blocks); + } + + @SubscribeEvent + public static void onRegisterMenuScreens(RegisterMenuScreensEvent event) { + for (Consumer reg : screenRegistrations) { + reg.accept(event); + } + } + + @SubscribeEvent + public static void onRegisterParticleProviders(RegisterParticleProvidersEvent event) { + for (Consumer reg : particleRegistrations) { + reg.accept(event); + } + } + + @SubscribeEvent + public static void onRegisterLayerDefinitions(EntityRenderersEvent.RegisterLayerDefinitions event) { + for (Consumer reg : layerRegistrations) { + reg.accept(event); + } + } + + @SubscribeEvent + public static void onRegisterRenderers(EntityRenderersEvent.RegisterRenderers event) { + for (Consumer reg : rendererRegistrations) { + reg.accept(event); + } + } + + @SubscribeEvent + public static void onRegisterBlockColors(RegisterColorHandlersEvent.BlockTintSources event){ + if (blockColorProviders.isEmpty()) return; + + for (Map.Entry, Block[]> entry : blockColorProviders.entrySet()) { + List 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/client/registry/neoforge/KeybindingRegistryImpl.java b/neoforge/src/main/java/net/pitan76/mcpitanlib/api/client/registry/neoforge/KeybindingRegistryImpl.java new file mode 100644 index 000000000..cca48c33b --- /dev/null +++ b/neoforge/src/main/java/net/pitan76/mcpitanlib/api/client/registry/neoforge/KeybindingRegistryImpl.java @@ -0,0 +1,27 @@ +package net.pitan76.mcpitanlib.api.client.registry.neoforge; + +import net.minecraft.client.KeyMapping; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.fml.common.EventBusSubscriber; +import net.neoforged.neoforge.client.event.RegisterKeyMappingsEvent; + +import java.util.ArrayList; +import java.util.List; + +@EventBusSubscriber(modid = "mcpitanlib", value = Dist.CLIENT) +public class KeybindingRegistryImpl { + + private static final List keyMappings = new ArrayList<>(); + + public static void register(KeyMapping keyBinding) { + keyMappings.add(keyBinding); + } + + @SubscribeEvent + public static void onRegisterKeyMappings(RegisterKeyMappingsEvent event) { + for (KeyMapping keyMapping : keyMappings) { + event.register(keyMapping); + } + } +} \ No newline at end of file diff --git a/neoforge/src/main/java/net/pitan76/mcpitanlib/api/command/neoforge/CommandRegistryImpl.java b/neoforge/src/main/java/net/pitan76/mcpitanlib/api/command/neoforge/CommandRegistryImpl.java new file mode 100644 index 000000000..6947b68c6 --- /dev/null +++ b/neoforge/src/main/java/net/pitan76/mcpitanlib/api/command/neoforge/CommandRegistryImpl.java @@ -0,0 +1,59 @@ +package net.pitan76.mcpitanlib.api.command.neoforge; + +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import net.minecraft.commands.CommandSourceStack; +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.fml.common.EventBusSubscriber; +import net.neoforged.neoforge.event.RegisterCommandsEvent; +import net.pitan76.mcpitanlib.api.command.CommandSettings; +import net.pitan76.mcpitanlib.api.command.LiteralCommand; +import net.pitan76.mcpitanlib.api.event.ServerCommandEvent; + +import java.util.ArrayList; +import java.util.List; +import java.util.function.Consumer; + +import static net.pitan76.mcpitanlib.api.command.CommandRegistry.forArgsCmd; +import static net.pitan76.mcpitanlib.api.command.CommandRegistry.latestCommandRegistryAccess; + +@EventBusSubscriber(modid = "mcpitanlib") +public class CommandRegistryImpl { + + private static final List> commandRegistrations = new ArrayList<>(); + + public static void register(String name, LiteralCommand command) { + commandRegistrations.add(event -> { + latestCommandRegistryAccess = event.getBuildContext(); + + CommandSettings settings = new CommandSettings(); + command.init(settings); + + LiteralArgumentBuilder builder = LiteralArgumentBuilder.literal(name) + .requires(settings::requires) + .executes(context -> { + ServerCommandEvent cmdEvent = new ServerCommandEvent(); + cmdEvent.setContext(context); + command.execute(cmdEvent); + return command.isSuccess; + }); + + forArgsCmd(command, builder); + + event.getDispatcher().register(builder); + }); + } + + public static void register(LiteralArgumentBuilder builder) { + commandRegistrations.add(event -> { + latestCommandRegistryAccess = event.getBuildContext(); + event.getDispatcher().register(builder); + }); + } + + @SubscribeEvent + public static void onRegisterCommands(RegisterCommandsEvent event) { + for (Consumer registration : commandRegistrations) { + registration.accept(event); + } + } +} \ No newline at end of file diff --git a/neoforge/src/main/java/net/pitan76/mcpitanlib/api/event/v0/event/neoforge/ServerConnectionEventImpl.java b/neoforge/src/main/java/net/pitan76/mcpitanlib/api/event/v0/event/neoforge/ServerConnectionEventImpl.java new file mode 100644 index 000000000..bfcf820ea --- /dev/null +++ b/neoforge/src/main/java/net/pitan76/mcpitanlib/api/event/v0/event/neoforge/ServerConnectionEventImpl.java @@ -0,0 +1,43 @@ +package net.pitan76.mcpitanlib.api.event.v0.event.neoforge; + +import net.minecraft.server.level.ServerPlayer; +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.fml.common.EventBusSubscriber; +import net.neoforged.neoforge.event.entity.player.PlayerEvent; +import net.pitan76.mcpitanlib.api.event.v0.EventRegistry; + +import java.util.ArrayList; +import java.util.List; + +@EventBusSubscriber(modid = "mcpitanlib") +public class ServerConnectionEventImpl { + + private static final List joinListeners = new ArrayList<>(); + private static final List quitListeners = new ArrayList<>(); + + public static void join(EventRegistry.ServerConnection.PlayerJoin state) { + joinListeners.add(state); + } + + public static void quit(EventRegistry.ServerConnection.PlayerQuit state) { + quitListeners.add(state); + } + + @SubscribeEvent + public static void onPlayerJoin(PlayerEvent.PlayerLoggedInEvent event) { + if (event.getEntity() instanceof ServerPlayer serverPlayer) { + for (EventRegistry.ServerConnection.PlayerJoin listener : joinListeners) { + listener.join(serverPlayer); + } + } + } + + @SubscribeEvent + public static void onPlayerQuit(PlayerEvent.PlayerLoggedOutEvent event) { + if (event.getEntity() instanceof ServerPlayer serverPlayer) { + for (EventRegistry.ServerConnection.PlayerQuit listener : quitListeners) { + listener.quit(serverPlayer); + } + } + } +} \ No newline at end of file diff --git a/neoforge/src/main/java/net/pitan76/mcpitanlib/api/event/v0/neoforge/ClientTickEventRegistryImpl.java b/neoforge/src/main/java/net/pitan76/mcpitanlib/api/event/v0/neoforge/ClientTickEventRegistryImpl.java new file mode 100644 index 000000000..0a79b71d5 --- /dev/null +++ b/neoforge/src/main/java/net/pitan76/mcpitanlib/api/event/v0/neoforge/ClientTickEventRegistryImpl.java @@ -0,0 +1,73 @@ +package net.pitan76.mcpitanlib.api.event.v0.neoforge; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.multiplayer.ClientLevel; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.fml.common.EventBusSubscriber; +import net.neoforged.neoforge.client.event.ClientTickEvent; +import net.neoforged.neoforge.event.tick.LevelTickEvent; +import net.pitan76.mcpitanlib.api.event.v0.ClientTickEventRegistry; + +import java.util.ArrayList; +import java.util.List; + +@EventBusSubscriber(modid = "mcpitanlib", value = Dist.CLIENT) +public class ClientTickEventRegistryImpl { + + private static final List preClients = new ArrayList<>(); + private static final List postClients = new ArrayList<>(); + private static final List preLevels = new ArrayList<>(); + private static final List postLevels = new ArrayList<>(); + + public static void registerPre(ClientTickEventRegistry.Client client) { + preClients.add(client); + } + + public static void registerPost(ClientTickEventRegistry.Client client) { + postClients.add(client); + } + + public static void registerLevelPre(ClientTickEventRegistry.ClientLevel world) { + preLevels.add(world); + } + + public static void registerLevelPost(ClientTickEventRegistry.ClientLevel world) { + postLevels.add(world); + } + + @SubscribeEvent + public static void onClientTickPre(ClientTickEvent.Pre event) { + Minecraft mc = Minecraft.getInstance(); + for (ClientTickEventRegistry.Client listener : preClients) { + listener.tick(mc); + } + } + + @SubscribeEvent + public static void onClientTickPost(ClientTickEvent.Post event) { + Minecraft mc = Minecraft.getInstance(); + for (ClientTickEventRegistry.Client listener : postClients) { + listener.tick(mc); + } + } + + @SubscribeEvent + public static void onLevelTickPre(LevelTickEvent.Pre event) { + // LevelTickEventはサーバー側のワールドでも発火するため、クライアントワールドかどうかの判定が必須 + if (event.getLevel() instanceof ClientLevel clientLevel) { + for (ClientTickEventRegistry.ClientLevel listener : preLevels) { + listener.tick(clientLevel); + } + } + } + + @SubscribeEvent + public static void onLevelTickPost(LevelTickEvent.Post event) { + if (event.getLevel() instanceof ClientLevel clientLevel) { + for (ClientTickEventRegistry.ClientLevel listener : postLevels) { + listener.tick(clientLevel); + } + } + } +} \ No newline at end of file diff --git a/neoforge/src/main/java/net/pitan76/mcpitanlib/api/event/v0/neoforge/EventRegistryServerLifecycleImpl.java b/neoforge/src/main/java/net/pitan76/mcpitanlib/api/event/v0/neoforge/EventRegistryServerLifecycleImpl.java new file mode 100644 index 000000000..8a33a8b73 --- /dev/null +++ b/neoforge/src/main/java/net/pitan76/mcpitanlib/api/event/v0/neoforge/EventRegistryServerLifecycleImpl.java @@ -0,0 +1,111 @@ +package net.pitan76.mcpitanlib.api.event.v0.neoforge; + +import net.minecraft.server.level.ServerLevel; +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.fml.common.EventBusSubscriber; +import net.neoforged.neoforge.event.level.LevelEvent; +import net.neoforged.neoforge.event.server.ServerStartedEvent; +import net.neoforged.neoforge.event.server.ServerStartingEvent; +import net.neoforged.neoforge.event.server.ServerStoppedEvent; +import net.neoforged.neoforge.event.server.ServerStoppingEvent; +import net.pitan76.mcpitanlib.api.event.v0.EventRegistry; + +import java.util.ArrayList; +import java.util.List; + +@EventBusSubscriber(modid = "mcpitanlib") +public class EventRegistryServerLifecycleImpl { + + private static final List serverStartedListeners = new ArrayList<>(); + private static final List serverStartingListeners = new ArrayList<>(); + private static final List serverStoppedListeners = new ArrayList<>(); + private static final List serverStoppingListeners = new ArrayList<>(); + + private static final List worldLoadListeners = new ArrayList<>(); + private static final List worldSaveListeners = new ArrayList<>(); + private static final List worldUnloadListeners = new ArrayList<>(); + + public static void serverStarted(EventRegistry.ServerLifecycle.ServerState state) { + serverStartedListeners.add(state); + } + + public static void serverStarting(EventRegistry.ServerLifecycle.ServerState state) { + serverStartingListeners.add(state); + } + + public static void serverStopped(EventRegistry.ServerLifecycle.ServerState state) { + serverStoppedListeners.add(state); + } + + public static void serverStopping(EventRegistry.ServerLifecycle.ServerState state) { + serverStoppingListeners.add(state); + } + + public static void serverWorldLoad(EventRegistry.ServerLifecycle.ServerWorldState state) { + worldLoadListeners.add(state); + } + + public static void serverWorldSave(EventRegistry.ServerLifecycle.ServerWorldState state) { + worldSaveListeners.add(state); + } + + public static void serverWorldUnload(EventRegistry.ServerLifecycle.ServerWorldState state) { + worldUnloadListeners.add(state); + } + + @SubscribeEvent + public static void onServerStarting(ServerStartingEvent event) { + for (EventRegistry.ServerLifecycle.ServerState listener : serverStartingListeners) { + listener.stateChanged(event.getServer()); + } + } + + @SubscribeEvent + public static void onServerStarted(ServerStartedEvent event) { + for (EventRegistry.ServerLifecycle.ServerState listener : serverStartedListeners) { + listener.stateChanged(event.getServer()); + } + } + + @SubscribeEvent + public static void onServerStopping(ServerStoppingEvent event) { + for (EventRegistry.ServerLifecycle.ServerState listener : serverStoppingListeners) { + listener.stateChanged(event.getServer()); + } + } + + @SubscribeEvent + public static void onServerStopped(ServerStoppedEvent event) { + for (EventRegistry.ServerLifecycle.ServerState listener : serverStoppedListeners) { + listener.stateChanged(event.getServer()); + } + } + + @SubscribeEvent + public static void onLevelLoad(LevelEvent.Load event) { + // TODO: クライアント側のワールド読み込みでも発火するため、ServerLevelかどうかの判定の確認するべきかも + if (event.getLevel() instanceof ServerLevel serverLevel) { + for (EventRegistry.ServerLifecycle.ServerWorldState listener : worldLoadListeners) { + listener.act(serverLevel); + } + } + } + + @SubscribeEvent + public static void onLevelSave(LevelEvent.Save event) { + if (event.getLevel() instanceof ServerLevel serverLevel) { + for (EventRegistry.ServerLifecycle.ServerWorldState listener : worldSaveListeners) { + listener.act(serverLevel); + } + } + } + + @SubscribeEvent + public static void onLevelUnload(LevelEvent.Unload event) { + if (event.getLevel() instanceof ServerLevel serverLevel) { + for (EventRegistry.ServerLifecycle.ServerWorldState listener : worldUnloadListeners) { + listener.act(serverLevel); + } + } + } +} \ No newline at end of file diff --git a/neoforge/src/main/java/net/pitan76/mcpitanlib/api/event/v0/neoforge/InteractionEventRegistryImpl.java b/neoforge/src/main/java/net/pitan76/mcpitanlib/api/event/v0/neoforge/InteractionEventRegistryImpl.java new file mode 100644 index 000000000..c53ba09df --- /dev/null +++ b/neoforge/src/main/java/net/pitan76/mcpitanlib/api/event/v0/neoforge/InteractionEventRegistryImpl.java @@ -0,0 +1,93 @@ +package net.pitan76.mcpitanlib.api.event.v0.neoforge; + +import net.pitan76.mcpitanlib.api.event.result.EventResult; +import net.pitan76.mcpitanlib.api.event.v0.InteractionEventRegistry.*; +import net.pitan76.mcpitanlib.api.event.v0.event.ClickBlockEvent; +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.fml.common.EventBusSubscriber; +import net.neoforged.neoforge.event.entity.player.PlayerInteractEvent; + +import java.util.ArrayList; +import java.util.List; + +@EventBusSubscriber(modid = "mcpitanlib") +public class InteractionEventRegistryImpl { + + private static final List rightClickBlockListeners = new ArrayList<>(); + private static final List leftClickBlockListeners = new ArrayList<>(); + private static final List rightClickItemListeners = new ArrayList<>(); + private static final List clientLeftClickAirListeners = new ArrayList<>(); + private static final List clientRightClickAirListeners = new ArrayList<>(); + private static final List interactEntityListeners = new ArrayList<>(); + + public static void registerRightClickBlock(RightClickBlock rightClickBlock) { + rightClickBlockListeners.add(rightClickBlock); + } + + public static void registerLeftClickBlock(LeftClickBlock leftClickBlock) { + leftClickBlockListeners.add(leftClickBlock); + } + + public static void registerRightClickItem(RightClickItem rightClickItem) { + rightClickItemListeners.add(rightClickItem); + } + + public static void registerClientLeftClickAir(ClientLeftClickAir clientLeftClickAir) { + clientLeftClickAirListeners.add(clientLeftClickAir); + } + + public static void registerClientRightClickAir(ClientRightClickAir clientRightClickAir) { + clientRightClickAirListeners.add(clientRightClickAir); + } + + public static void registerInteractEntity(InteractEntity interactEntity) { + interactEntityListeners.add(interactEntity); + } + + @SubscribeEvent + public static void onRightClickBlock(PlayerInteractEvent.RightClickBlock event) { + for (RightClickBlock listener : rightClickBlockListeners) { + EventResult result = listener.click(new ClickBlockEvent(event.getEntity(), event.getHand(), event.getPos(), event.getFace())); + if (result != EventResult.pass()) { + event.setCanceled(true); + event.setCancellationResult(result.toActionResult()); + return; + } + } + } + + @SubscribeEvent + public static void onLeftClickBlock(PlayerInteractEvent.LeftClickBlock event) { + for (LeftClickBlock listener : leftClickBlockListeners) { + listener.click(new ClickBlockEvent(event.getEntity(), event.getHand(), event.getPos(), event.getFace())); + } + } + + @SubscribeEvent + public static void onRightClickItem(PlayerInteractEvent.RightClickItem event) { + for (RightClickItem listener : rightClickItemListeners) { + listener.click2(event.getEntity(), event.getHand()); + } + } + + @SubscribeEvent + public static void onClientLeftClickAir(PlayerInteractEvent.LeftClickEmpty event) { + for (ClientLeftClickAir listener : clientLeftClickAirListeners) { + listener.click(event.getEntity(), event.getHand()); + } + } + + @SubscribeEvent + public static void onClientRightClickAir(PlayerInteractEvent.RightClickEmpty event) { + for (ClientRightClickAir listener : clientRightClickAirListeners) { + listener.click(event.getEntity(), event.getHand()); + } + } + + @SubscribeEvent + public static void onInteractEntity(PlayerInteractEvent.EntityInteract event) { + for (InteractEntity listener : interactEntityListeners) { + listener.interact(event.getEntity(), event.getTarget(), event.getHand()); + } + } +} \ No newline at end of file diff --git a/neoforge/src/main/java/net/pitan76/mcpitanlib/api/event/v0/neoforge/LivingHurtEventRegistryImpl.java b/neoforge/src/main/java/net/pitan76/mcpitanlib/api/event/v0/neoforge/LivingHurtEventRegistryImpl.java new file mode 100644 index 000000000..0fe018459 --- /dev/null +++ b/neoforge/src/main/java/net/pitan76/mcpitanlib/api/event/v0/neoforge/LivingHurtEventRegistryImpl.java @@ -0,0 +1,38 @@ +package net.pitan76.mcpitanlib.api.event.v0.neoforge; + +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.fml.common.EventBusSubscriber; +import net.neoforged.neoforge.event.entity.living.LivingIncomingDamageEvent; +import net.pitan76.mcpitanlib.api.event.v0.LivingHurtEventRegistry; + +import java.util.ArrayList; +import java.util.List; + +@EventBusSubscriber(modid = "mcpitanlib") +public class LivingHurtEventRegistryImpl { + + private static final List listeners = new ArrayList<>(); + + public static void register(LivingHurtEventRegistry.LivingHurt livingHurt) { + listeners.add(livingHurt); + } + + @SubscribeEvent + public static void onLivingHurt(LivingIncomingDamageEvent event) { + if (!event.getEntity().level().isClientSide()) { + for (LivingHurtEventRegistry.LivingHurt listener : listeners) { + boolean allow = listener.hurt( + event.getEntity(), + event.getSource(), + event.getAmount() + ); + + if (!allow) { + event.setCanceled(true); + return; + } + } + + } + } +} \ No newline at end of file diff --git a/neoforge/src/main/java/net/pitan76/mcpitanlib/api/event/v1/neoforge/AttackEntityEventRegistryImpl.java b/neoforge/src/main/java/net/pitan76/mcpitanlib/api/event/v1/neoforge/AttackEntityEventRegistryImpl.java new file mode 100644 index 000000000..08040b14a --- /dev/null +++ b/neoforge/src/main/java/net/pitan76/mcpitanlib/api/event/v1/neoforge/AttackEntityEventRegistryImpl.java @@ -0,0 +1,39 @@ +package net.pitan76.mcpitanlib.api.event.v1.neoforge; + +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.fml.common.EventBusSubscriber; +import net.neoforged.neoforge.event.entity.player.AttackEntityEvent; +import net.pitan76.mcpitanlib.api.event.v1.AttackEntityEventRegistry; + +import java.util.ArrayList; +import java.util.List; + +@EventBusSubscriber(modid = "mcpitanlib") +public class AttackEntityEventRegistryImpl { + + private static final List listeners = new ArrayList<>(); + + public static void register(AttackEntityEventRegistry.AttackEntity attackEntity) { + listeners.add(attackEntity); + } + + @SubscribeEvent + public static void onAttackEntity(AttackEntityEvent event) { + for (AttackEntityEventRegistry.AttackEntity listener : listeners) { + InteractionResult result = listener.attack( + event.getEntity(), + event.getEntity().level(), + InteractionHand.MAIN_HAND, + event.getTarget(), + null + ); + + if (result != InteractionResult.PASS) { + event.setCanceled(true); + return; + } + } + } +} \ No newline at end of file diff --git a/neoforge/src/main/java/net/pitan76/mcpitanlib/api/event/v1/neoforge/LivingHurtEventRegistryImpl.java b/neoforge/src/main/java/net/pitan76/mcpitanlib/api/event/v1/neoforge/LivingHurtEventRegistryImpl.java new file mode 100644 index 000000000..45e8d9c36 --- /dev/null +++ b/neoforge/src/main/java/net/pitan76/mcpitanlib/api/event/v1/neoforge/LivingHurtEventRegistryImpl.java @@ -0,0 +1,39 @@ +package net.pitan76.mcpitanlib.api.event.v1.neoforge; + +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.fml.common.EventBusSubscriber; +import net.neoforged.neoforge.event.entity.living.LivingIncomingDamageEvent; +import net.pitan76.mcpitanlib.api.event.v1.LivingHurtEventRegistry; + +import java.util.ArrayList; +import java.util.List; + +@EventBusSubscriber(modid = "mcpitanlib") +public class LivingHurtEventRegistryImpl { + + private static final List listeners = new ArrayList<>(); + + public static void register(LivingHurtEventRegistry.LivingHurt livingHurt) { + listeners.add(livingHurt); + } + + @SubscribeEvent + public static void onLivingHurt(LivingIncomingDamageEvent event) { + + if (!event.getEntity().level().isClientSide()) { + for (LivingHurtEventRegistry.LivingHurt listener : listeners) { + boolean allow = listener.hurt( + event.getEntity(), + event.getSource(), + event.getAmount() + ); + + if (!allow) { + event.setCanceled(true); + return; + } + } + + } + } +} \ No newline at end of file diff --git a/neoforge/src/main/java/net/pitan76/mcpitanlib/api/gui/neoforge/ExtendedScreenHandlerTypeBuilderImpl.java b/neoforge/src/main/java/net/pitan76/mcpitanlib/api/gui/neoforge/ExtendedScreenHandlerTypeBuilderImpl.java new file mode 100644 index 000000000..d9051124d --- /dev/null +++ b/neoforge/src/main/java/net/pitan76/mcpitanlib/api/gui/neoforge/ExtendedScreenHandlerTypeBuilderImpl.java @@ -0,0 +1,12 @@ +package net.pitan76.mcpitanlib.api.gui.neoforge; + +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.MenuType; +import net.neoforged.neoforge.common.extensions.IMenuTypeExtension; +import net.pitan76.mcpitanlib.api.gui.ExtendedScreenHandlerTypeBuilder; + +public class ExtendedScreenHandlerTypeBuilderImpl { + public static MenuType build(ExtendedScreenHandlerTypeBuilder.Factory factory) { + return IMenuTypeExtension.create(factory::create); + } +} diff --git a/neoforge/src/main/java/net/pitan76/mcpitanlib/api/gui/neoforge/SimpleScreenHandlerTypeBuilderImpl.java b/neoforge/src/main/java/net/pitan76/mcpitanlib/api/gui/neoforge/SimpleScreenHandlerTypeBuilderImpl.java new file mode 100644 index 000000000..6024ef5f0 --- /dev/null +++ b/neoforge/src/main/java/net/pitan76/mcpitanlib/api/gui/neoforge/SimpleScreenHandlerTypeBuilderImpl.java @@ -0,0 +1,12 @@ +package net.pitan76.mcpitanlib.api.gui.neoforge; + +import net.minecraft.world.flag.FeatureFlags; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.MenuType; +import net.pitan76.mcpitanlib.api.gui.SimpleScreenHandlerTypeBuilder; + +public class SimpleScreenHandlerTypeBuilderImpl { + public static MenuType build(SimpleScreenHandlerTypeBuilder.Factory factory) { + return new MenuType<>(factory::create, FeatureFlags.VANILLA_SET); + } +} diff --git a/neoforge/src/main/java/net/pitan76/mcpitanlib/api/item/neoforge/CreativeTabBuilderImpl.java b/neoforge/src/main/java/net/pitan76/mcpitanlib/api/item/neoforge/CreativeTabBuilderImpl.java new file mode 100644 index 000000000..e5a100d9a --- /dev/null +++ b/neoforge/src/main/java/net/pitan76/mcpitanlib/api/item/neoforge/CreativeTabBuilderImpl.java @@ -0,0 +1,28 @@ +package net.pitan76.mcpitanlib.api.item.neoforge; + +import net.minecraft.network.chat.Component; +import net.minecraft.resources.Identifier; +import net.minecraft.world.item.CreativeModeTab; +import net.minecraft.world.item.ItemStack; +import net.pitan76.mcpitanlib.api.util.IdentifierUtil; +import net.pitan76.mcpitanlib.api.util.TextUtil; + +import java.util.function.Supplier; + +public class CreativeTabBuilderImpl { + + public static CreativeModeTab build(Identifier identifier, Component displayName, Supplier iconSupplier, boolean noRenderedName, boolean noScrollbar, boolean special, String texture) { + CreativeModeTab.Builder builder = CreativeModeTab.builder(); + + if (displayName != null) builder.title(displayName); + else builder.title(TextUtil.translatable("itemGroup." + identifier.getNamespace() + "." + identifier.getPath())); + + if (iconSupplier != null) builder.icon(iconSupplier); + if (noRenderedName) builder.hideTitle(); + if (noScrollbar) builder.noScrollBar(); + if (special) builder.alignedRight(); + if (texture != null) builder.backgroundTexture(IdentifierUtil.id(texture)); + + return builder.build(); + } +} diff --git a/neoforge/src/main/java/net/pitan76/mcpitanlib/api/tile/neoforge/BlockEntityTypeBuilderImpl.java b/neoforge/src/main/java/net/pitan76/mcpitanlib/api/tile/neoforge/BlockEntityTypeBuilderImpl.java new file mode 100644 index 000000000..dee8dcf0c --- /dev/null +++ b/neoforge/src/main/java/net/pitan76/mcpitanlib/api/tile/neoforge/BlockEntityTypeBuilderImpl.java @@ -0,0 +1,14 @@ +package net.pitan76.mcpitanlib.api.tile.neoforge; + +import com.mojang.datafixers.types.Type; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.pitan76.mcpitanlib.api.tile.BlockEntityTypeBuilder; + +public class BlockEntityTypeBuilderImpl { + @Deprecated + public static BlockEntityType build(Type type, BlockEntityTypeBuilder.Factory factory, Block... blocks) { + return new BlockEntityType<>(factory::create, 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..ef0526a30 --- /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.world.level.material.Fluid; +import net.neoforged.neoforge.fluids.FluidStack; +import net.neoforged.neoforge.transfer.fluid.FluidStacksResourceHandler; +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 FluidStacksResourceHandler(1, (int) capacity), 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..5d9c75a00 --- /dev/null +++ b/neoforge/src/main/java/net/pitan76/mcpitanlib/api/transfer/fluid/v1/neoforge/NeoForgeFluidStorage.java @@ -0,0 +1,89 @@ +package net.pitan76.mcpitanlib.api.transfer.fluid.v1.neoforge; + +import net.neoforged.neoforge.fluids.FluidStack; +import net.neoforged.neoforge.transfer.fluid.FluidResource; +import net.neoforged.neoforge.transfer.fluid.FluidStacksResourceHandler; +import net.neoforged.neoforge.transfer.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 NeoForgeFluidStorage implements IFluidStorage { + + public final FluidStacksResourceHandler handler; + public FluidStack fluid = FluidStack.EMPTY; + public long capacity; + + public Runnable onChange; + + public NeoForgeFluidStorage(FluidStacksResourceHandler handler, long capacity, Runnable onChange) { + this.handler = handler; + this.onChange = onChange; + this.capacity = capacity; + } + + @Override + public long getAmount() { + return handler.getAmountFrom(fluid); + } + + @Override + public long getCapacity() { + return capacity; + } + + @Override + public IFluidVariant getResource() { + return new NeoForgeFluidVariant(fluid); + } + + @Override + public void setResource(IFluidVariant variant) { + fluid = ((NeoForgeFluidVariant) variant).raw; + } + + @Override + public boolean isResourceBlank() { + return fluid.isEmpty(); + } + + @Override + public long insert(IFluidVariant variant, long maxAmount, boolean simulate) { + if (simulate) + return handler.insert(FluidResource.of(((NeoForgeFluidVariant) variant).raw), (int) maxAmount, Transaction.open(null)); + + onChange.run(); + long inserted = 0; + + try (Transaction transaction = Transaction.open(null)) { + inserted += handler.insert(FluidResource.of(((NeoForgeFluidVariant) variant).raw), (int) maxAmount, transaction); + transaction.commit(); + } + return inserted; + } + + @Override + public long extract(IFluidVariant variant, long maxAmount, boolean simulate) { + if (simulate) + return handler.extract(FluidResource.of(((NeoForgeFluidVariant) variant).raw), (int) maxAmount, Transaction.open(null)); + + onChange.run(); + long extracted = 0; + try (Transaction transaction = Transaction.open(null)) { + extracted += handler.extract(FluidResource.of(((NeoForgeFluidVariant) variant).raw), (int) maxAmount, transaction); + transaction.commit(); + } + return extracted; + } + + @Override + public void writeNbt(WriteNbtArgs args) { + handler.serialize(args.view); + } + + @Override + public void readNbt(ReadNbtArgs args) { + handler.deserialize(args.view); + } +} 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..51a988b03 --- /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.world.level.material.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..e78c37310 --- /dev/null +++ b/neoforge/src/main/java/net/pitan76/mcpitanlib/api/util/neoforge/PlatformUtilImpl.java @@ -0,0 +1,57 @@ +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.FMLLoader; +import net.neoforged.fml.loading.FMLPaths; +import net.neoforged.fml.loading.moddiscovery.ModInfo; + +import java.nio.file.Path; +import java.util.Collection; + +public class PlatformUtilImpl { + public static boolean isClient() { + return FMLEnvironment.getDist() == Dist.CLIENT; + } + + public static boolean isServer() { + return FMLEnvironment.getDist() == Dist.DEDICATED_SERVER; + } + + public static Path getConfigFolder() { + return FMLPaths.CONFIGDIR.get(); + } + + public static boolean isModLoaded(String id) { + return ModList.get().isLoaded(id); + } + + public static boolean isDevelopmentEnvironment() { + return !FMLEnvironment.isProduction(); + } + + public static Path getGameFolder() { + return FMLLoader.getCurrent().getGameDir(); + } + + public static Collection getModIds() { + return FMLLoader.getCurrent().getLoadingModList().getMods().stream().map(ModInfo::getModId).toList(); + } + + public static String getGameVersion() { + return FMLLoader.getCurrent().getVersionInfo().mcVersion(); + } + + public static boolean isFabric() { + return false; + } + + public static boolean isForge() { + return false; + } + + public static boolean isNeoForge() { + return true; + } +} diff --git a/neoforge/src/main/java/net/pitan76/mcpitanlib/core/mc261/neoforge/ClientPlayNetworkingImpl.java b/neoforge/src/main/java/net/pitan76/mcpitanlib/core/mc261/neoforge/ClientPlayNetworkingImpl.java new file mode 100644 index 000000000..0576ecac0 --- /dev/null +++ b/neoforge/src/main/java/net/pitan76/mcpitanlib/core/mc261/neoforge/ClientPlayNetworkingImpl.java @@ -0,0 +1,75 @@ +package net.pitan76.mcpitanlib.core.mc261.neoforge; + +import io.netty.buffer.Unpooled; +import net.minecraft.client.Minecraft; +import net.minecraft.client.player.LocalPlayer; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import net.minecraft.resources.Identifier; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.fml.common.EventBusSubscriber; +import net.neoforged.neoforge.client.network.ClientPacketDistributor; +import net.neoforged.neoforge.client.network.event.RegisterClientPayloadHandlersEvent; +import net.neoforged.neoforge.network.event.RegisterPayloadHandlersEvent; +import net.neoforged.neoforge.network.handling.IPayloadHandler; +import net.neoforged.neoforge.network.registration.PayloadRegistrar; +import net.pitan76.mcpitanlib.api.network.ClientNetworking; +import net.pitan76.mcpitanlib.core.network.BufPayload; + +import java.util.HashMap; +import java.util.Map; + +@EventBusSubscriber(modid = "mcpitanlib", value = Dist.CLIENT) +public class ClientPlayNetworkingImpl { + public static void send(CustomPacketPayload payload) { + ClientPacketDistributor.sendToServer(payload); + } + + private static final Map, IPayloadHandler> handlerMap = new HashMap<>(); + + public static void registerGlobalReceiver(BufPayload.Type type, ClientNetworking.ClientNetworkHandler handler) { + handlerMap.put(type, (payload, context) -> { + FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.wrappedBuffer(payload.getData())); + + LocalPlayer player = null; + if (context.player() instanceof LocalPlayer) + player = (LocalPlayer) context.player(); + + handler.receive(Minecraft.getInstance(), player, buf); + buf.release(); + }); + } + + private static final Map> payloadTypeMap = new HashMap<>(); + + + public static void registerC2SPayloadType(Identifier identifier) { + BufPayload.Type id = BufPayload.id(identifier); + if (payloadTypeMap.containsKey(identifier)) return; + payloadTypeMap.put(identifier, id); + } + +// @SubscribeEvent +// public static void register(RegisterClientPayloadHandlersEvent event) { +// for (Map.Entry, IPayloadHandler> entry : handlerMap.entrySet()) { +// event.register(entry.getKey(), entry.getValue()); +// } +// } + + @SubscribeEvent + public static void registerPayloads(RegisterPayloadHandlersEvent event) { + final PayloadRegistrar registrar = event.registrar("1"); + + payloadTypeMap.forEach((_, type) -> { + registrar.playToClient(type, BufPayload.getCodec(type), handlerMap.get(type)); + }); + + // ダミー +// payloadTypeMap.forEach((_, type) -> { +// if (!handlerMap.containsKey(type)) { +// registrar.playToServer(type, BufPayload.getCodec(type), (_, _) -> {}); +// } +// }); + } +} diff --git a/neoforge/src/main/java/net/pitan76/mcpitanlib/core/mc261/neoforge/CreativeModeTabEventRegistryImpl.java b/neoforge/src/main/java/net/pitan76/mcpitanlib/core/mc261/neoforge/CreativeModeTabEventRegistryImpl.java new file mode 100644 index 000000000..9249a121b --- /dev/null +++ b/neoforge/src/main/java/net/pitan76/mcpitanlib/core/mc261/neoforge/CreativeModeTabEventRegistryImpl.java @@ -0,0 +1,42 @@ +package net.pitan76.mcpitanlib.core.mc261.neoforge; + +import net.minecraft.resources.ResourceKey; +import net.minecraft.world.item.CreativeModeTab; +import net.minecraft.world.item.ItemStack; +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.fml.common.EventBusSubscriber; +import net.neoforged.neoforge.event.BuildCreativeModeTabContentsEvent; + +import java.util.ArrayList; +import java.util.List; +import java.util.function.Consumer; +import java.util.function.Supplier; + +@EventBusSubscriber(modid = "mcpitanlib") +public class CreativeModeTabEventRegistryImpl { + + private static final List> tabModifiers = new ArrayList<>(); + + public static void addStack(ResourceKey key, Supplier supplier) { + tabModifiers.add(event -> { + if (event.getTabKey().equals(key)) { + event.accept(supplier.get()); + } + }); + } + + public static void addStacks(ResourceKey key, Supplier> supplier) { + tabModifiers.add(event -> { + if (event.getTabKey().equals(key)) { + event.acceptAll(supplier.get()); + } + }); + } + + @SubscribeEvent + public static void onBuildCreativeTabContents(BuildCreativeModeTabContentsEvent event) { + for (Consumer modifier : tabModifiers) { + modifier.accept(event); + } + } +} \ No newline at end of file diff --git a/neoforge/src/main/java/net/pitan76/mcpitanlib/core/mc261/neoforge/ServerPlayNetworkingImpl.java b/neoforge/src/main/java/net/pitan76/mcpitanlib/core/mc261/neoforge/ServerPlayNetworkingImpl.java new file mode 100644 index 000000000..0d3e0aafb --- /dev/null +++ b/neoforge/src/main/java/net/pitan76/mcpitanlib/core/mc261/neoforge/ServerPlayNetworkingImpl.java @@ -0,0 +1,69 @@ +package net.pitan76.mcpitanlib.core.mc261.neoforge; + +import io.netty.buffer.Unpooled; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import net.minecraft.resources.Identifier; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.level.ServerPlayer; +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.fml.common.EventBusSubscriber; +import net.neoforged.neoforge.network.PacketDistributor; +import net.neoforged.neoforge.network.event.RegisterPayloadHandlersEvent; +import net.neoforged.neoforge.network.handling.IPayloadHandler; +import net.neoforged.neoforge.network.registration.PayloadRegistrar; +import net.pitan76.mcpitanlib.api.network.ServerNetworking; +import net.pitan76.mcpitanlib.core.network.BufPayload; + +import java.util.HashMap; +import java.util.Map; + +@EventBusSubscriber(modid = "mcpitanlib") +public class ServerPlayNetworkingImpl { + + public static void send(ServerPlayer player, CustomPacketPayload payload) { + PacketDistributor.sendToPlayer(player, payload); + } + + private static final Map, IPayloadHandler> handlerMap = new HashMap<>(); + private static final Map> payloadTypeMap = new HashMap<>(); + + public static void registerGlobalReceiver(CustomPacketPayload.Type id, ServerNetworking.ServerNetworkHandler handler) { + handlerMap.put(id, (payload, context) -> { + FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.wrappedBuffer(payload.getData())); + + ServerPlayer player = null; + MinecraftServer server = null; + if (context.player() instanceof ServerPlayer serverPlayer) { + player = serverPlayer; + server = serverPlayer.level().getServer(); + } + + handler.receive(server, player, buf); + + buf.release(); + }); + } + + public static void registerS2CPayloadType(Identifier identifier) { + if (payloadTypeMap.containsKey(identifier)) return; + BufPayload.Type id = BufPayload.id(identifier); + payloadTypeMap.put(identifier, id); + } + + @SubscribeEvent + public static void registerPayloads(RegisterPayloadHandlersEvent event) { + final PayloadRegistrar registrar = event.registrar("1"); + + handlerMap.forEach((type, handler) -> { + registrar.playToServer(type, BufPayload.getCodec(type), handler); + }); + + // ダミー +// payloadTypeMap.forEach((_, type) -> { +// if (!handlerMap.containsKey(type)) { +// registrar.playToClient(type, BufPayload.getCodec(type), (_, _) -> {}); +// } +// }); + } +} \ No newline at end of file diff --git a/neoforge/src/main/java/net/pitan76/mcpitanlib/core/registry/neoforge/FuelRegistryImpl.java b/neoforge/src/main/java/net/pitan76/mcpitanlib/core/registry/neoforge/FuelRegistryImpl.java new file mode 100644 index 000000000..ee359d213 --- /dev/null +++ b/neoforge/src/main/java/net/pitan76/mcpitanlib/core/registry/neoforge/FuelRegistryImpl.java @@ -0,0 +1,33 @@ +package net.pitan76.mcpitanlib.core.registry.neoforge; + +import com.google.common.base.Supplier; +import net.minecraft.world.item.Item; +import net.minecraft.world.level.ItemLike; +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.fml.common.EventBusSubscriber; +import net.neoforged.neoforge.event.furnace.FurnaceFuelBurnTimeEvent; + +import java.util.HashMap; +import java.util.Map; + +@EventBusSubscriber(modid = "mcpitanlib") +public class FuelRegistryImpl { + private static final Map, Integer> FUEL_TIMES = new HashMap<>(); + + public static void register(int time, Supplier item) { + int burnTimeTicks = 200 * time; + FUEL_TIMES.put(item, burnTimeTicks); + } + + @SubscribeEvent + public static void onFurnaceFuelBurnTime(FurnaceFuelBurnTimeEvent event) { + Item item = event.getItemStack().getItem(); + for (Map.Entry, Integer> entry : FUEL_TIMES.entrySet()) { + ItemLike itemLike = entry.getKey().get(); + if (itemLike != null && itemLike.asItem().equals(item)) { + event.setBurnTime(entry.getValue()); + break; + } + } + } +} \ No newline at end of file diff --git a/neoforge/src/main/java/net/pitan76/mcpitanlib/core/registry/neoforge/RegistryImpl.java b/neoforge/src/main/java/net/pitan76/mcpitanlib/core/registry/neoforge/RegistryImpl.java new file mode 100644 index 000000000..e59f68af6 --- /dev/null +++ b/neoforge/src/main/java/net/pitan76/mcpitanlib/core/registry/neoforge/RegistryImpl.java @@ -0,0 +1,122 @@ +package net.pitan76.mcpitanlib.core.registry.neoforge; + +import net.minecraft.core.Registry; +import net.minecraft.core.component.DataComponentType; +import net.minecraft.core.particles.ParticleType; +import net.minecraft.core.registries.Registries; +import net.minecraft.resources.Identifier; +import net.minecraft.resources.ResourceKey; +import net.minecraft.server.level.TicketType; +import net.minecraft.sounds.SoundEvent; +import net.minecraft.world.effect.MobEffect; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.CreativeModeTab; +import net.minecraft.world.item.Item; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.level.material.Fluid; +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.fml.common.EventBusSubscriber; +import net.neoforged.neoforge.registries.RegisterEvent; +import net.pitan76.mcpitanlib.api.registry.result.RegistrySupplier; +import net.pitan76.mcpitanlib.midohra.world.chunk.ChunkTicketType; +import org.jetbrains.annotations.NotNull; + +import java.util.HashMap; +import java.util.Map; +import java.util.function.Supplier; + +@EventBusSubscriber(modid = "mcpitanlib") +public class RegistryImpl { + + private static class PendingEntry { + final Supplier factory; + final RegistrySupplier wrapper; + + PendingEntry(Supplier factory, RegistrySupplier wrapper) { + this.factory = factory; + this.wrapper = wrapper; + } + } + + private static final Map>, Map>> PENDING_REGISTRIES = new HashMap<>(); + + private static RegistrySupplier register(ResourceKey<@NotNull Registry> registryKey, Identifier id, Supplier supplier) { + RegistrySupplier registrySupplier = new RegistrySupplier<>(); + + PENDING_REGISTRIES.computeIfAbsent(registryKey, _ -> new HashMap<>()) + .put(id, new PendingEntry<>(supplier, registrySupplier)); + + return registrySupplier; + } + + public static RegistrySupplier registryItem(Identifier id, Supplier supplier) { + return register(Registries.ITEM, id, supplier); + } + + public static RegistrySupplier registryBlock(Identifier id, Supplier supplier) { + return register(Registries.BLOCK, id, supplier); + } + + public static RegistrySupplier> registryScreenHandlerType(Identifier id, Supplier> supplier) { + return register(Registries.MENU, id, supplier); + } + + public static RegistrySupplier> registryBlockEntityType(Identifier id, Supplier> supplier) { + return register(Registries.BLOCK_ENTITY_TYPE, id, supplier); + } + + public static RegistrySupplier> registryEntityType(Identifier id, Supplier> supplier) { + return register(Registries.ENTITY_TYPE, id, supplier); + } + + public static RegistrySupplier registrySoundEvent(Identifier id, Supplier supplier) { + return register(Registries.SOUND_EVENT, id, supplier); + } + + public static RegistrySupplier registryFluid(Identifier id, Supplier supplier) { + return register(Registries.FLUID, id, supplier); + } + + public static RegistrySupplier> registryParticleType(Identifier id, Supplier> supplier) { + return register(Registries.PARTICLE_TYPE, id, supplier); + } + + public static RegistrySupplier registryStatusEffect(Identifier id, Supplier supplier) { + return register(Registries.MOB_EFFECT, id, supplier); + } + + public static RegistrySupplier registryItemGroup(Identifier id, Supplier supplier) { + return register(Registries.CREATIVE_MODE_TAB, id, supplier); + } + + public static RegistrySupplier> registryDataComponentType(Identifier id, Supplier> supplier) { + return register(Registries.DATA_COMPONENT_TYPE, id, supplier); + } + + public static Supplier> registryChunkTicketType(Identifier id, Supplier supplier) { + RegistrySupplier supplier1 = register(Registries.TICKET_TYPE, id, supplier); + return () -> ChunkTicketType.of(supplier1.get()); + } + + @SubscribeEvent + @SuppressWarnings({"unchecked", "rawtypes"}) + public static void onRegister(RegisterEvent event) { + ResourceKey> key = event.getRegistryKey(); + + if (PENDING_REGISTRIES.containsKey(key)) { + Map> entries = PENDING_REGISTRIES.get(key); + + for (Map.Entry> mapEntry : entries.entrySet()) { + PendingEntry pending = mapEntry.getValue(); + event.register((ResourceKey) key, mapEntry.getKey(), () -> { + Object instance = pending.factory.get(); + ((RegistrySupplier) pending.wrapper).set(instance); + + return instance; + }); + } + } + } +} \ No newline at end of file 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..db0224277 --- /dev/null +++ b/neoforge/src/main/java/net/pitan76/mcpitanlib/neoforge/MCPitanLibNeoForge.java @@ -0,0 +1,22 @@ +package net.pitan76.mcpitanlib.neoforge; + +import net.neoforged.fml.ModContainer; +import net.neoforged.fml.common.Mod; +import net.pitan76.mcpitanlib.MCPitanLib; + +@Mod(MCPitanLib.MOD_ID) +public class MCPitanLibNeoForge { + public MCPitanLibNeoForge(ModContainer modContainer) { +// IEventBus bus = modContainer.getEventBus(); +// +// if (PlatformUtil.isClient()) { +// IEventBus nfBus = NeoForge.EVENT_BUS; +// // TODO: re-implement outline rendering event +//// nfBus.addListener(WorldRenderRegistryImpl::renderOutlineEventBlock); +//// nfBus.addListener(WorldRenderRegistryImpl::renderOutlineEvent); +//// nfBus.addListener(WorldRenderRegistryImpl::renderLevelStageEvent); +// } + + 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..45b5e7143 --- /dev/null +++ b/neoforge/src/main/resources/META-INF/neoforge.mods.toml @@ -0,0 +1,35 @@ +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 = "[26.1,)" +ordering = "NONE" +side = "BOTH" + +[[mixins]] +config = "mcpitanlib-common.mixins.json" + +[[mixins]] +config = "mcpitanlib.mixins.json" \ No newline at end of file diff --git a/common/src/main/resources/mcpitanlibarch-common.mixins.json b/neoforge/src/main/resources/mcpitanlib.mixins.json similarity index 60% rename from common/src/main/resources/mcpitanlibarch-common.mixins.json rename to neoforge/src/main/resources/mcpitanlib.mixins.json index 72d6fe3ab..df01c3ab5 100644 --- a/common/src/main/resources/mcpitanlibarch-common.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/forge/src/main/resources/pack.mcmeta b/neoforge/src/main/resources/pack.mcmeta similarity index 70% rename from forge/src/main/resources/pack.mcmeta rename to neoforge/src/main/resources/pack.mcmeta index 547096ba2..03e89dcaa 100644 --- a/forge/src/main/resources/pack.mcmeta +++ b/neoforge/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/next.patch b/next.patch new file mode 100644 index 000000000..49ec1ec36 --- /dev/null +++ b/next.patch @@ -0,0 +1,1008 @@ +Subject: [PATCH] gradle +--- +Index: common/src/main/java/net/pitan76/mcpitanlib/api/client/render/CompatMatrix3x2fStack.java +IDEA additional info: +Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP +<+>UTF-8 +=================================================================== +diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/CompatMatrix3x2fStack.java b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/CompatMatrix3x2fStack.java +new file mode 100644 +--- /dev/null (date 1777189056266) ++++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/CompatMatrix3x2fStack.java (date 1777189056266) +@@ -0,0 +1,48 @@ ++package net.pitan76.mcpitanlib.api.client.render; ++ ++import net.pitan76.mcpitanlib.api.util.MathUtil; ++import org.joml.Matrix3x2fStack; ++ ++public class CompatMatrix3x2fStack extends CompatMatrixStack { ++ private final Matrix3x2fStack matrices; ++ ++ public CompatMatrix3x2fStack(Matrix3x2fStack matrices) { ++ super(null); ++ this.matrices = matrices; ++ } ++ ++ @Deprecated ++ public Matrix3x2fStack get3x2fRaw() { ++ return matrices; ++ } ++ ++ public CompatMatrix3x2fStack push() { ++ get3x2fRaw().pushMatrix(); ++ return this; ++ } ++ ++ public CompatMatrix3x2fStack pop() { ++ get3x2fRaw().popMatrix(); ++ return this; ++ } ++ ++ public CompatMatrix3x2fStack translate(double x, double y, double z) { ++ get3x2fRaw().translate((float) x, (float) y); ++ return this; ++ } ++ ++ @Override ++ public CompatMatrixStack translate(float x, float y, float z) { ++ get3x2fRaw().translate(x, y); ++ return this; ++ } ++ ++ public CompatMatrix3x2fStack scale(float x, float y, float z) { ++ get3x2fRaw().scale(x, y); ++ return this; ++ } ++ ++ public CompatMatrix3x2fStack multiply(MathUtil.RotationAxisType type, float deg) { ++ return this; ++ } ++} +Index: common/src/main/java/net/pitan76/mcpitanlib/api/client/event/listener/WorldRenderContext.java +IDEA additional info: +Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP +<+>UTF-8 +=================================================================== +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 +--- a/common/src/main/java/net/pitan76/mcpitanlib/api/client/event/listener/WorldRenderContext.java (revision 05711e295c85714a55d91cb74b7f90e41a911b05) ++++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/event/listener/WorldRenderContext.java (date 1777189232790) +@@ -19,6 +19,7 @@ + import net.minecraft.core.BlockPos; + import net.minecraft.world.phys.AABB; + import net.minecraft.world.phys.shapes.VoxelShape; ++import net.pitan76.mcpitanlib.api.client.render.CompatMatrixStack; + import net.pitan76.mcpitanlib.api.util.VoxelShapeUtil; + import net.pitan76.mcpitanlib.api.util.client.render.VertexRenderingUtil; + import net.pitan76.mcpitanlib.midohra.client.render.CameraWrapper; +@@ -108,6 +109,10 @@ + getMatrixStack().popPose(); + } + ++ default CompatMatrixStack getCompatMatrices() { ++ return CompatMatrixStack.of(getMatrixStack()); ++ } ++ + default Optional getVertexConsumer() { + if (getConsumers() == null) + return Optional.empty(); +Index: common/src/main/java/net/pitan76/mcpitanlib/api/util/math/MathUtil.java +IDEA additional info: +Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP +<+>UTF-8 +=================================================================== +diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/util/math/MathUtil.java b/common/src/main/java/net/pitan76/mcpitanlib/api/util/math/MathUtil.java +new file mode 100644 +--- /dev/null (date 1777189486869) ++++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/math/MathUtil.java (date 1777189486869) +@@ -0,0 +1,41 @@ ++package net.pitan76.mcpitanlib.api.util.math; ++ ++import net.minecraft.util.Mth; ++ ++public class MathUtil { ++ public static double clamp(double value, double min, double max) { ++ return Mth.clamp(value, min, max); ++ } ++ ++ public static float clamp(float value, float min, float max) { ++ return Mth.clamp(value, min, max); ++ } ++ ++ public static int clamp(int value, int min, int max) { ++ return Mth.clamp(value, min, max); ++ } ++ ++ public static long clamp(long value, long min, long max) { ++ return Mth.clamp(value, min, max); ++ } ++ ++ public static double lerp(double a, double b, double t) { ++ return Mth.lerp(t, a, b); ++ } ++ ++ public static float lerp(float a, float b, float t) { ++ return Mth.lerp(t, a, b); ++ } ++ ++ public static double inverseLerp(double a, double b, double value) { ++ return Mth.inverseLerp(a, b, value); ++ } ++ ++ public static int hsvToRgb(float hue, float saturation, float value) { ++ return Mth.hsvToRgb(hue, saturation, value); ++ } ++ ++ public static float hsvToArgb(float hue, float saturation, float value, int alpha) { ++ return Mth.hsvToArgb(hue, saturation, value, alpha); ++ } ++} +Index: common/src/main/java/net/pitan76/mcpitanlib/api/client/render/handledscreen/MouseClickedArgs.java +IDEA additional info: +Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP +<+>UTF-8 +=================================================================== +diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/handledscreen/MouseClickedArgs.java b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/handledscreen/MouseClickedArgs.java +new file mode 100644 +--- /dev/null (date 1777191810794) ++++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/handledscreen/MouseClickedArgs.java (date 1777191810794) +@@ -0,0 +1,26 @@ ++package net.pitan76.mcpitanlib.api.client.render.handledscreen; ++ ++import net.minecraft.client.input.MouseButtonInfo; ++ ++public class MouseClickedArgs extends MouseButtonArgs { ++ public boolean doubleClick; ++ ++ public MouseClickedArgs(double mouseX, double mouseY, MouseButtonInfo buttonInfo, boolean doubleClick) { ++ super(mouseX, mouseY, buttonInfo); ++ this.doubleClick = doubleClick; ++ } ++ ++ public MouseClickedArgs(double mouseX, double mouseY, int button, boolean doubleClick) { ++ super(mouseX, mouseY, button); ++ this.doubleClick = doubleClick; ++ } ++ ++ public MouseClickedArgs(double mouseX, double mouseY, int button) { ++ this(mouseX, mouseY, button, false); ++ } ++ ++ @Deprecated ++ public boolean isDoubleClick() { ++ return doubleClick; ++ } ++} +Index: common/src/main/java/net/pitan76/mcpitanlib/api/client/render/handledscreen/CharEventArgs.java +IDEA additional info: +Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP +<+>UTF-8 +=================================================================== +diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/handledscreen/CharEventArgs.java b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/handledscreen/CharEventArgs.java +new file mode 100644 +--- /dev/null (date 1777190665057) ++++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/handledscreen/CharEventArgs.java (date 1777190665057) +@@ -0,0 +1,21 @@ ++package net.pitan76.mcpitanlib.api.client.render.handledscreen; ++ ++public class CharEventArgs { ++ private final int character; ++ ++ public CharEventArgs(char character, int modifiers) { ++ this.character = character; ++ } ++ ++ public CharEventArgs(int codepoint) { ++ this.character = codepoint; ++ } ++ ++ public int getCharacter() { ++ return character; ++ } ++ ++ public char getChar() { ++ return (char) character; ++ } ++} +Index: common/src/main/java/net/pitan76/mcpitanlib/midohra/block/Blocks.java +IDEA additional info: +Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP +<+>UTF-8 +=================================================================== +diff --git a/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/Blocks.java b/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/Blocks.java +--- a/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/Blocks.java (revision 05711e295c85714a55d91cb74b7f90e41a911b05) ++++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/block/Blocks.java (date 1777187815951) +@@ -1,5 +1,10 @@ + package net.pitan76.mcpitanlib.midohra.block; + ++import net.pitan76.mcpitanlib.api.util.block.BlockUtil; ++ ++import java.util.List; ++import java.util.stream.Collectors; ++ + public class Blocks { + public static BlockWrapper AIR = of(net.minecraft.world.level.block.Blocks.AIR); + public static BlockWrapper STONE = of(net.minecraft.world.level.block.Blocks.STONE); +@@ -768,4 +773,8 @@ + public static BlockWrapper of(net.minecraft.world.level.block.Block block) { + return BlockWrapper.of(block); + } ++ ++ public static List getBlocks() { ++ return BlockUtil.getBlocks().stream().map(BlockWrapper::of).collect(Collectors.toList()); ++ } + } +Index: common/src/main/java/net/pitan76/mcpitanlib/api/gui/args/CreateMenuEvent.java +IDEA additional info: +Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP +<+>UTF-8 +=================================================================== +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 +--- a/common/src/main/java/net/pitan76/mcpitanlib/api/gui/args/CreateMenuEvent.java (revision 05711e295c85714a55d91cb74b7f90e41a911b05) ++++ b/common/src/main/java/net/pitan76/mcpitanlib/api/gui/args/CreateMenuEvent.java (date 1777192306521) +@@ -3,6 +3,7 @@ + import net.minecraft.world.entity.player.Inventory; + import net.minecraft.world.level.Level; + import net.pitan76.mcpitanlib.api.entity.Player; ++import net.pitan76.mcpitanlib.api.util.inventory.CompatPlayerInventory; + + public class CreateMenuEvent { + public int syncId; +@@ -54,4 +55,12 @@ + public Level getWorld() { + return getPlayer().getWorld(); + } ++ ++ public CompatPlayerInventory getCompatPlayerInventory() { ++ return new CompatPlayerInventory(getPlayerInventory()); ++ } ++ ++ public net.pitan76.mcpitanlib.midohra.world.World getWorldM() { ++ return net.pitan76.mcpitanlib.midohra.world.World.of(getWorld()); ++ } + } +Index: common/src/main/java/net/pitan76/mcpitanlib/api/network/PacketByteUtil.java +IDEA additional info: +Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP +<+>UTF-8 +=================================================================== +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 +--- a/common/src/main/java/net/pitan76/mcpitanlib/api/network/PacketByteUtil.java (revision 05711e295c85714a55d91cb74b7f90e41a911b05) ++++ b/common/src/main/java/net/pitan76/mcpitanlib/api/network/PacketByteUtil.java (date 1777192630370) +@@ -270,6 +270,18 @@ + public static FriendlyByteBuf writeBlockPos(FriendlyByteBuf buf, net.pitan76.mcpitanlib.midohra.util.math.BlockPos pos) { + return writeBlockPos(buf, pos.toMinecraft()); + } ++ ++ public static boolean isReadable(FriendlyByteBuf buf) {; ++ return buf.isReadable(); ++ } ++ ++ public static boolean isWritable(FriendlyByteBuf buf) { ++ return buf.isWritable(); ++ } ++ ++ public static boolean isReadable(FriendlyByteBuf buf, int size) { ++ return buf.isReadable(size); ++ } + } + + +Index: common/src/main/java/net/pitan76/mcpitanlib/api/client/render/CompatMatrixStack.java +IDEA additional info: +Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP +<+>UTF-8 +=================================================================== +diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/CompatMatrixStack.java b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/CompatMatrixStack.java +new file mode 100644 +--- /dev/null (date 1777189232799) ++++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/CompatMatrixStack.java (date 1777189232799) +@@ -0,0 +1,51 @@ ++package net.pitan76.mcpitanlib.api.client.render; ++ ++import net.pitan76.mcpitanlib.api.util.MathUtil; ++import net.pitan76.mcpitanlib.api.util.client.MatrixStackUtil; ++ ++public class CompatMatrixStack { ++ private final com.mojang.blaze3d.vertex.PoseStack matrices; ++ ++ public CompatMatrixStack(com.mojang.blaze3d.vertex.PoseStack matrices) { ++ this.matrices = matrices; ++ } ++ ++ public static CompatMatrixStack of(com.mojang.blaze3d.vertex.PoseStack matrixStack) { ++ return new CompatMatrixStack(matrixStack); ++ } ++ ++ @Deprecated ++ public com.mojang.blaze3d.vertex.PoseStack getRaw() { ++ return matrices; ++ } ++ ++ public CompatMatrixStack push() { ++ MatrixStackUtil.push(getRaw()); ++ return this; ++ } ++ ++ public CompatMatrixStack pop() { ++ MatrixStackUtil.pop(getRaw()); ++ return this; ++ } ++ ++ public CompatMatrixStack translate(double x, double y, double z) { ++ MatrixStackUtil.translate(getRaw(), x, y, z); ++ return this; ++ } ++ ++ public CompatMatrixStack translate(float x, float y, float z) { ++ getRaw().translate(x, y, z); ++ return this; ++ } ++ ++ public CompatMatrixStack scale(float x, float y, float z) { ++ MatrixStackUtil.scale(getRaw(), x, y, z); ++ return this; ++ } ++ ++ public CompatMatrixStack multiply(MathUtil.RotationAxisType type, float deg) { ++ MatrixStackUtil.multiply(getRaw(), type, deg); ++ return this; ++ } ++} +Index: common/src/main/java/net/pitan76/mcpitanlib/api/event/container/factory/ExtraDataArgs.java +IDEA additional info: +Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP +<+>UTF-8 +=================================================================== +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 +--- a/common/src/main/java/net/pitan76/mcpitanlib/api/event/container/factory/ExtraDataArgs.java (revision 05711e295c85714a55d91cb74b7f90e41a911b05) ++++ b/common/src/main/java/net/pitan76/mcpitanlib/api/event/container/factory/ExtraDataArgs.java (date 1777192460461) +@@ -5,6 +5,7 @@ + import net.pitan76.mcpitanlib.api.entity.Player; + import net.pitan76.mcpitanlib.api.event.BaseEvent; + import net.pitan76.mcpitanlib.api.network.PacketByteUtil; ++import net.pitan76.mcpitanlib.midohra.network.CompatPacketByteBuf; + + public class ExtraDataArgs extends BaseEvent { + public FriendlyByteBuf buf; +@@ -52,4 +53,8 @@ + public void writeVar(Object obj) { + PacketByteUtil.writeVar(getBuf(), obj); + } ++ ++ public CompatPacketByteBuf getCompatBuf() { ++ return CompatPacketByteBuf.of(getBuf()); ++ } + } +Index: common/src/main/java/net/pitan76/mcpitanlib/api/client/option/CompatKeyBinding.java +IDEA additional info: +Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP +<+>UTF-8 +=================================================================== +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 +--- a/common/src/main/java/net/pitan76/mcpitanlib/api/client/option/CompatKeyBinding.java (revision 05711e295c85714a55d91cb74b7f90e41a911b05) ++++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/option/CompatKeyBinding.java (date 1777187202278) +@@ -1,6 +1,7 @@ + package net.pitan76.mcpitanlib.api.client.option; + + import net.minecraft.client.KeyMapping; ++import net.minecraft.client.input.KeyEvent; + import net.minecraft.network.chat.Component; + import net.pitan76.mcpitanlib.api.util.CompatIdentifier; + +@@ -75,4 +76,8 @@ + public KeyMapping getRaw() { + return keyBinding; + } ++ ++ public boolean matches(int keyCode, int scanCode, int modifiers) { ++ return keyBinding.matches(new KeyEvent(keyCode, scanCode, modifiers)); ++ } + } +Index: common/src/main/java/net/pitan76/mcpitanlib/api/client/gui/screen/SimpleHandledScreen.java +IDEA additional info: +Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP +<+>UTF-8 +=================================================================== +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 +--- a/common/src/main/java/net/pitan76/mcpitanlib/api/client/gui/screen/SimpleHandledScreen.java (revision 05711e295c85714a55d91cb74b7f90e41a911b05) ++++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/gui/screen/SimpleHandledScreen.java (date 1777192065101) +@@ -8,7 +8,9 @@ + import net.minecraft.client.gui.narration.NarratableEntry; + import net.minecraft.client.gui.screens.Screen; + import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; ++import net.minecraft.client.input.CharacterEvent; + import net.minecraft.client.input.KeyEvent; ++import net.minecraft.client.input.MouseButtonEvent; + import net.minecraft.client.renderer.item.ItemModelResolver; + import net.minecraft.world.entity.player.Inventory; + import net.minecraft.world.inventory.AbstractContainerMenu; +@@ -362,4 +364,54 @@ + public Component getPlayerInvTitle() { + return playerInventoryTitle; + } ++ ++ public boolean charTyped(CharEventArgs args) { ++ return super.charTyped(new CharacterEvent(args.getCharacter())); ++ } ++ ++ @Deprecated ++ @Override ++ public boolean charTyped(CharacterEvent event) { ++ return charTyped(new CharEventArgs(event.codepoint())); ++ } ++ ++ public boolean mouseScrolled(MouseScrolledArgs args) { ++ return super.mouseScrolled(args.getMouseX(), args.getMouseY(), args.getScrollX(), args.getScrollY()); ++ } ++ ++ @Deprecated ++ @Override ++ public boolean mouseScrolled(double x, double y, double scrollX, double scrollY) { ++ return mouseScrolled(new MouseScrolledArgs(x, y, scrollX, scrollY)); ++ } ++ ++ public boolean mouseClicked(MouseClickedArgs args) { ++ return super.mouseClicked(new MouseButtonEvent(args.getX(), args.getY(), args.getButtonInfo()), args.isDoubleClick()); ++ } ++ ++ @Deprecated ++ @Override ++ public boolean mouseClicked(MouseButtonEvent event, boolean doubleClick) { ++ return mouseClicked(new MouseClickedArgs(event.x(), event.y(), event.buttonInfo(), doubleClick)); ++ } ++ ++ public boolean mouseDragged(MouseDraggedArgs args) { ++ return super.mouseDragged(new MouseButtonEvent(args.getX(), args.getY(), args.getButtonInfo()), args.getDeltaX(), args.getDeltaY()); ++ } ++ ++ @Deprecated ++ @Override ++ public boolean mouseDragged(MouseButtonEvent event, double dx, double dy) { ++ return mouseDragged(new MouseDraggedArgs(event.x(), event.y(), event.buttonInfo(), dx, dy)); ++ } ++ ++ public boolean mouseReleased(MouseReleasedArgs args) { ++ return super.mouseReleased(new MouseButtonEvent(args.getX(), args.getY(), args.getButtonInfo())); ++ } ++ ++ @Deprecated ++ @Override ++ public boolean mouseReleased(MouseButtonEvent event) { ++ return mouseReleased(new MouseReleasedArgs(event.x(), event.y(), event.buttonInfo())); ++ } + } +Index: common/src/main/java/net/pitan76/mcpitanlib/api/client/render/DrawObjectDM.java +IDEA additional info: +Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP +<+>UTF-8 +=================================================================== +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 +--- a/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/DrawObjectDM.java (revision 05711e295c85714a55d91cb74b7f90e41a911b05) ++++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/DrawObjectDM.java (date 1777189771891) +@@ -9,6 +9,8 @@ + import net.pitan76.mcpitanlib.api.util.client.ScreenUtil.RendererUtil; + import org.joml.Matrix3x2fStack; + ++import java.util.List; ++ + public class DrawObjectDM { + private PoseStack stack; + private Matrix3x2fStack matrix3x2fStack; +@@ -86,6 +88,10 @@ + RendererUtil.drawTooltip(this, text, x, y); + } + ++ public void drawTooltip(List texts, int x, int y) { ++ RendererUtil.drawTooltip2(this, texts, x, y); ++ } ++ + public void drawBorder(int x, int y, int width, int height, int color) { + RendererUtil.drawBorder(this, x, y, width, height, color); + } +@@ -97,4 +103,8 @@ + public int getHeight() { + return hasScreen() ? screen.height : -1; + } ++ ++ public CompatMatrixStack getMatrixStack() { ++ return new CompatMatrix3x2fStack(context.pose()); ++ } + } +Index: common/src/main/java/net/pitan76/mcpitanlib/api/client/render/handledscreen/MouseDraggedArgs.java +IDEA additional info: +Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP +<+>UTF-8 +=================================================================== +diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/handledscreen/MouseDraggedArgs.java b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/handledscreen/MouseDraggedArgs.java +new file mode 100644 +--- /dev/null (date 1777191944644) ++++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/handledscreen/MouseDraggedArgs.java (date 1777191944644) +@@ -0,0 +1,29 @@ ++package net.pitan76.mcpitanlib.api.client.render.handledscreen; ++ ++import net.minecraft.client.input.MouseButtonInfo; ++ ++public class MouseDraggedArgs extends MouseButtonArgs { ++ ++ public final double dx; ++ public final double dy; ++ ++ public MouseDraggedArgs(double mouseX, double mouseY, MouseButtonInfo buttonInfo, double dx, double dy) { ++ super(mouseX, mouseY, buttonInfo); ++ this.dx = dx; ++ this.dy = dy; ++ } ++ ++ public MouseDraggedArgs(double mouseX, double mouseY, int button, double dx, double dy) { ++ super(mouseX, mouseY, button); ++ this.dx = dx; ++ this.dy = dy; ++ } ++ ++ public double getDeltaX() { ++ return dx; ++ } ++ ++ public double getDeltaY() { ++ return dy; ++ } ++} +Index: common/src/main/java/net/pitan76/mcpitanlib/api/util/client/ScreenUtil.java +IDEA additional info: +Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP +<+>UTF-8 +=================================================================== +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 +--- a/common/src/main/java/net/pitan76/mcpitanlib/api/util/client/ScreenUtil.java (revision 05711e295c85714a55d91cb74b7f90e41a911b05) ++++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/client/ScreenUtil.java (date 1777189771870) +@@ -16,9 +16,11 @@ + import net.pitan76.mcpitanlib.api.client.render.DrawObjectDM; + import net.pitan76.mcpitanlib.api.text.TextComponent; + import net.pitan76.mcpitanlib.api.util.CompatIdentifier; ++import net.pitan76.mcpitanlib.midohra.item.ItemStack; + import org.jetbrains.annotations.Nullable; + + import java.util.List; ++import java.util.stream.Collectors; + + @Environment(EnvType.CLIENT) + public class ScreenUtil { +@@ -207,6 +209,74 @@ + public static void drawTooltip(DrawObjectDM drawObjectDM, List texts, int x, int y) { + drawObjectDM.getContext().setComponentTooltipForNextFrame(getTextRenderer(), texts, x, y); + } ++ ++ public static void drawTooltip2(DrawObjectDM drawObjectDM, List texts, int x, int y) { ++ drawTooltip(drawObjectDM, texts.stream().map(TextComponent::getText).collect(Collectors.toList()), x, y); ++ } ++ ++ public static void drawItem(DrawObjectDM drawObjectDM, ItemStack stack, int x, int y) { ++ drawItem(drawObjectDM, stack.toMinecraft(), x, y); ++ } ++ ++ public static void drawItem(DrawObjectDM drawObjectDM, net.minecraft.world.item.ItemStack stack, int x, int y) { ++ drawObjectDM.getContext().item(stack, x, y); ++ } ++ ++ public static void drawItem(DrawObjectDM drawObjectDM, ItemStack stack, int x, int y, int seed) { ++ drawItem(drawObjectDM, stack.toMinecraft(), x, y, seed); ++ } ++ ++ public static void drawItem(DrawObjectDM drawObjectDM, net.minecraft.world.item.ItemStack stack, int x, int y, int seed) { ++ drawObjectDM.getContext().item(stack, x, y, seed); ++ } ++ ++ public static void drawItemWithoutEntity(DrawObjectDM drawObjectDM, ItemStack stack, int x, int y) { ++ drawItemWithoutEntity(drawObjectDM, stack.toMinecraft(), x, y); ++ } ++ ++ public static void drawItemWithoutEntity(DrawObjectDM drawObjectDM, net.minecraft.world.item.ItemStack stack, int x, int y) { ++ drawObjectDM.getContext().fakeItem(stack, x, y, 0); ++ } ++ ++ public static void drawItemWithoutEntity(DrawObjectDM drawObjectDM, ItemStack stack, int x, int y, int seed) { ++ drawItemWithoutEntity(drawObjectDM, stack.toMinecraft(), x, y, seed); ++ } ++ ++ public static void drawItemWithoutEntity(DrawObjectDM drawObjectDM, net.minecraft.world.item.ItemStack stack, int x, int y, int seed) { ++ drawObjectDM.getContext().fakeItem(stack, x, y, seed); ++ } ++ ++ public static void drawItemInSlot(DrawObjectDM drawObjectDM, ItemStack stack, int x, int y) { ++ drawItemInSlot(drawObjectDM, stack.toMinecraft(), x, y); ++ } ++ ++ public static void drawItemInSlot(DrawObjectDM drawObjectDM, net.minecraft.world.item.ItemStack stack, int x, int y) { ++ drawObjectDM.getContext().itemDecorations(getTextRenderer(), stack, x, y); ++ } ++ ++ public static void drawItemInSlot(DrawObjectDM drawObjectDM, ItemStack stack, int x, int y, String countText) { ++ drawItemInSlot(drawObjectDM, stack.toMinecraft(), x, y, countText); ++ } ++ ++ public static void drawItemInSlot(DrawObjectDM drawObjectDM, net.minecraft.world.item.ItemStack stack, int x, int y, String countText) { ++ drawObjectDM.getContext().itemDecorations(getTextRenderer(), stack, x, y, countText); ++ } ++ ++ public static void enableScissor(DrawObjectDM drawObjectDM, int x0, int y0, int x1, int y1) { ++ drawObjectDM.getContext().enableScissor(x0, y0, x1, y1); ++ } ++ ++ public static void disableScissor(DrawObjectDM drawObjectDM) { ++ drawObjectDM.getContext().disableScissor(); ++ } ++ ++ public static void fill(DrawObjectDM drawObjectDM, int x0, int y0, int x1, int y1, int color) { ++ drawObjectDM.getContext().fill(x0, y0, x1, y1, fixColor(color)); ++ } ++ ++ public static void fillGradient(DrawObjectDM drawObjectDM, int x0, int y0, int x1, int y1, int color0, int color1) { ++ drawObjectDM.getContext().fillGradient(x0, y0, x1, y1, fixColor(color0), fixColor(color1)); ++ } + } + + public static int getWidth(Component text) { +Index: common/src/main/java/net/pitan76/mcpitanlib/api/client/render/handledscreen/MouseScrolledArgs.java +IDEA additional info: +Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP +<+>UTF-8 +=================================================================== +diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/handledscreen/MouseScrolledArgs.java b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/handledscreen/MouseScrolledArgs.java +new file mode 100644 +--- /dev/null (date 1777191460210) ++++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/handledscreen/MouseScrolledArgs.java (date 1777191460210) +@@ -0,0 +1,37 @@ ++package net.pitan76.mcpitanlib.api.client.render.handledscreen; ++ ++public class MouseScrolledArgs { ++ private final double mouseX; ++ private final double mouseY; ++ private final double scrollX; ++ private final double scrollY; ++ private final double amount; ++ ++ public MouseScrolledArgs(double mouseX, double mouseY, double scrollX, double scrollY) { ++ this.mouseX = mouseX; ++ this.mouseY = mouseY; ++ this.scrollX = scrollX; ++ this.scrollY = scrollY; ++ this.amount = Math.sqrt(scrollX * scrollX + scrollY * scrollY); ++ } ++ ++ public double getMouseX() { ++ return mouseX; ++ } ++ ++ public double getMouseY() { ++ return mouseY; ++ } ++ ++ public double getScrollX() { ++ return scrollX; ++ } ++ ++ public double getScrollY() { ++ return scrollY; ++ } ++ ++ public double getAmount() { ++ return amount; ++ } ++} +Index: common/src/main/java/net/pitan76/mcpitanlib/api/util/client/WindowUtil.java +IDEA additional info: +Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP +<+>UTF-8 +=================================================================== +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 +--- a/common/src/main/java/net/pitan76/mcpitanlib/api/util/client/WindowUtil.java (revision 05711e295c85714a55d91cb74b7f90e41a911b05) ++++ b/common/src/main/java/net/pitan76/mcpitanlib/api/util/client/WindowUtil.java (date 1777187365008) +@@ -39,4 +39,16 @@ + public static void close() { + getWindow().close(); + } ++ ++ public static int getX() { ++ return getWindow().getX(); ++ } ++ ++ public static int getY() { ++ return getWindow().getY(); ++ } ++ ++ public static double getScaleFactor() { ++ return getWindow().getGuiScale(); ++ } + } +Index: common/src/main/java/net/pitan76/mcpitanlib/api/client/render/handledscreen/MouseReleasedArgs.java +IDEA additional info: +Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP +<+>UTF-8 +=================================================================== +diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/handledscreen/MouseReleasedArgs.java b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/handledscreen/MouseReleasedArgs.java +new file mode 100644 +--- /dev/null (date 1777192065068) ++++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/handledscreen/MouseReleasedArgs.java (date 1777192065068) +@@ -0,0 +1,14 @@ ++package net.pitan76.mcpitanlib.api.client.render.handledscreen; ++ ++import net.minecraft.client.input.MouseButtonInfo; ++ ++public class MouseReleasedArgs extends MouseButtonArgs { ++ ++ public MouseReleasedArgs(double mouseX, double mouseY, MouseButtonInfo buttonInfo) { ++ super(mouseX, mouseY, buttonInfo); ++ } ++ ++ public MouseReleasedArgs(double mouseX, double mouseY, int button) { ++ super(mouseX, mouseY, button); ++ } ++} +Index: common/src/main/java/net/pitan76/mcpitanlib/api/client/render/handledscreen/MouseButtonArgs.java +IDEA additional info: +Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP +<+>UTF-8 +=================================================================== +diff --git a/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/handledscreen/MouseButtonArgs.java b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/handledscreen/MouseButtonArgs.java +new file mode 100644 +--- /dev/null (date 1777191810769) ++++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/handledscreen/MouseButtonArgs.java (date 1777191810769) +@@ -0,0 +1,38 @@ ++package net.pitan76.mcpitanlib.api.client.render.handledscreen; ++ ++import net.minecraft.client.input.MouseButtonInfo; ++ ++public class MouseButtonArgs { ++ public final double mouseX, mouseY; ++ public MouseButtonInfo buttonInfo = null; ++ ++ public MouseButtonArgs(double mouseX, double mouseY, MouseButtonInfo buttonInfo) { ++ this.mouseX = mouseX; ++ this.mouseY = mouseY; ++ this.buttonInfo = buttonInfo; ++ } ++ ++ public MouseButtonArgs(double mouseX, double mouseY, int button) { ++ this.mouseX = mouseX; ++ this.mouseY = mouseY; ++ this.buttonInfo = new MouseButtonInfo(button, 0); ++ } ++ ++ public double getX() { ++ return mouseX; ++ } ++ ++ public double getY() { ++ return mouseY; ++ } ++ ++ public int getButton() { ++ if (getButtonInfo() == null) return -1; ++ return getButtonInfo().button(); ++ } ++ ++ @Deprecated ++ public MouseButtonInfo getButtonInfo() { ++ return buttonInfo; ++ } ++} +Index: common/src/main/java/net/pitan76/mcpitanlib/midohra/item/ItemGroupWrapper.java +IDEA additional info: +Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP +<+>UTF-8 +=================================================================== +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 +--- a/common/src/main/java/net/pitan76/mcpitanlib/midohra/item/ItemGroupWrapper.java (revision 05711e295c85714a55d91cb74b7f90e41a911b05) ++++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/item/ItemGroupWrapper.java (date 1777189589604) +@@ -1,8 +1,13 @@ + package net.pitan76.mcpitanlib.midohra.item; + ++import net.pitan76.mcpitanlib.api.text.TextComponent; + import net.pitan76.mcpitanlib.api.util.CompatIdentifier; + import net.pitan76.mcpitanlib.api.util.item.ItemGroupUtil; + ++import java.util.Collection; ++import java.util.Collections; ++import java.util.stream.Collectors; ++ + public class ItemGroupWrapper { + private final net.minecraft.world.item.CreativeModeTab itemGroup; + +@@ -68,4 +73,40 @@ + ItemGroupWrapper other = (ItemGroupWrapper) obj; + return rawEquals(other); + } ++ ++ public ItemWrapper getIconItem() { ++ return getIcon().getItem(); ++ } ++ ++ public Type getType() { ++ if (get().getType().equals(net.minecraft.world.item.CreativeModeTab.Type.CATEGORY)) { ++ return Type.CATEGORY; ++ } else if (get().getType().equals(net.minecraft.world.item.CreativeModeTab.Type.INVENTORY)) { ++ return Type.INVENTORY; ++ } else if (get().getType().equals(net.minecraft.world.item.CreativeModeTab.Type.HOTBAR)) { ++ return Type.HOTBAR; ++ } else if (get().getType().equals(net.minecraft.world.item.CreativeModeTab.Type.SEARCH)) { ++ return Type.SEARCH; ++ } ++ ++ return Type.EMPTY; ++ } ++ ++ public Collection getDisplayItems() { ++ if (isEmpty()) return Collections.emptyList(); ++ return get().getDisplayItems().stream().map(ItemStack::of).collect(Collectors.toList()); ++ } ++ ++ public TextComponent getDisplayName() { ++ if (isEmpty()) return new TextComponent(""); ++ return new TextComponent(get().getDisplayName()); ++ } ++ ++ public static enum Type { ++ EMPTY, ++ CATEGORY, ++ INVENTORY, ++ HOTBAR, ++ SEARCH, ++ } + } +Index: common/src/main/java/net/pitan76/mcpitanlib/midohra/network/CompatPacketByteBuf.java +IDEA additional info: +Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP +<+>UTF-8 +=================================================================== +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 +--- a/common/src/main/java/net/pitan76/mcpitanlib/midohra/network/CompatPacketByteBuf.java (revision 05711e295c85714a55d91cb74b7f90e41a911b05) ++++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/network/CompatPacketByteBuf.java (date 1777192630393) +@@ -123,4 +123,21 @@ + PacketByteUtil.writeNbt(this, nbt); + return this; + } ++ ++ public CompatPacketByteBuf writeVar(Object obj) { ++ PacketByteUtil.writeVar(this, obj); ++ return this; ++ } ++ ++ public boolean isReadable() { ++ return PacketByteUtil.isReadable(this); ++ } ++ ++ public boolean isWritable() { ++ return PacketByteUtil.isWritable(this); ++ } ++ ++ public boolean isReadable(int size) { ++ return PacketByteUtil.isReadable(this, size); ++ } + } +Index: common/src/main/java/net/pitan76/mcpitanlib/midohra/item/ItemGroups.java +IDEA additional info: +Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP +<+>UTF-8 +=================================================================== +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 +--- a/common/src/main/java/net/pitan76/mcpitanlib/midohra/item/ItemGroups.java (revision 05711e295c85714a55d91cb74b7f90e41a911b05) ++++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/item/ItemGroups.java (date 1777187815967) +@@ -1,7 +1,11 @@ + package net.pitan76.mcpitanlib.midohra.item; + ++import net.minecraft.world.item.CreativeModeTabs; + import net.pitan76.mcpitanlib.api.item.DefaultItemGroups; + ++import java.util.List; ++import java.util.stream.Collectors; ++ + public class ItemGroups { + public static final ItemGroupWrapper BUILDING_BLOCKS = of(DefaultItemGroups.BUILDING_BLOCKS); + public static final ItemGroupWrapper COLORED_BLOCKS = of(DefaultItemGroups.COLORED_BLOCKS); +@@ -27,4 +31,12 @@ + private static ItemGroupWrapper of(net.minecraft.world.item.CreativeModeTab itemGroup) { + return ItemGroupWrapper.of(itemGroup); + } ++ ++ public static List getGroupsToDisplay() { ++ return CreativeModeTabs.allTabs().stream().map(ItemGroupWrapper::of).collect(Collectors.toList()); ++ } ++ ++ public static List getGroups() { ++ return CreativeModeTabs.tabs().stream().map(ItemGroupWrapper::of).collect(Collectors.toList()); ++ } + } +Index: common/src/main/java/net/pitan76/mcpitanlib/midohra/item/ItemStack.java +IDEA additional info: +Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP +<+>UTF-8 +=================================================================== +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 +--- a/common/src/main/java/net/pitan76/mcpitanlib/midohra/item/ItemStack.java (revision 05711e295c85714a55d91cb74b7f90e41a911b05) ++++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/item/ItemStack.java (date 1777189962211) +@@ -1,6 +1,7 @@ + package net.pitan76.mcpitanlib.midohra.item; + + import net.minecraft.world.item.Item; ++import net.minecraft.world.item.TooltipFlag; + import net.minecraft.world.level.ItemLike; + import net.minecraft.nbt.CompoundTag; + import net.minecraft.network.chat.Component; +@@ -9,10 +10,12 @@ + import net.pitan76.mcpitanlib.api.item.stack.LoreUtil; + import net.pitan76.mcpitanlib.api.text.TextComponent; + import net.pitan76.mcpitanlib.api.util.*; ++import net.pitan76.mcpitanlib.api.util.client.ClientUtil; + import org.jetbrains.annotations.Nullable; + + import java.util.List; + import java.util.Map; ++import java.util.stream.Collectors; + + public class ItemStack { + private final net.minecraft.world.item.ItemStack stack; +@@ -259,4 +262,9 @@ + Class clazz = item.getClass(); + return clazz.isInstance(getRawItem()); + } ++ ++ public List getTooltip() { ++ return stack.getTooltipLines(Item.TooltipContext.EMPTY, ClientUtil.getClientPlayer(), ClientUtil.getOptions().getRaw().advancedItemTooltips ? TooltipFlag.Default.ADVANCED : TooltipFlag.Default.NORMAL) ++ .stream().map(TextComponent::new).collect(Collectors.toList()); ++ } + } +Index: common/src/main/java/net/pitan76/mcpitanlib/midohra/item/Items.java +IDEA additional info: +Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP +<+>UTF-8 +=================================================================== +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 +--- a/common/src/main/java/net/pitan76/mcpitanlib/midohra/item/Items.java (revision 05711e295c85714a55d91cb74b7f90e41a911b05) ++++ b/common/src/main/java/net/pitan76/mcpitanlib/midohra/item/Items.java (date 1777187815988) +@@ -1,5 +1,10 @@ + package net.pitan76.mcpitanlib.midohra.item; + ++import net.pitan76.mcpitanlib.api.util.item.ItemUtil; ++ ++import java.util.List; ++import java.util.stream.Collectors; ++ + public class Items { + public static ItemWrapper AIR = of(net.minecraft.world.item.Items.AIR); + public static ItemWrapper STONE = of(net.minecraft.world.item.Items.STONE); +@@ -981,4 +986,8 @@ + public static ItemWrapper of(net.minecraft.world.item.Item item) { + return ItemWrapper.of(item); + } ++ ++ public static List getItems() { ++ return ItemUtil.getItems().stream().map(ItemWrapper::of).collect(Collectors.toList()); ++ } + } +Index: common/src/main/java/net/pitan76/mcpitanlib/api/client/render/block/entity/event/BlockEntityRenderEvent.java +IDEA additional info: +Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP +<+>UTF-8 +=================================================================== +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 +--- a/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/block/entity/event/BlockEntityRenderEvent.java (revision 05711e295c85714a55d91cb74b7f90e41a911b05) ++++ b/common/src/main/java/net/pitan76/mcpitanlib/api/client/render/block/entity/event/BlockEntityRenderEvent.java (date 1777189232766) +@@ -13,6 +13,7 @@ + import net.minecraft.world.item.ItemStack; + import net.minecraft.core.BlockPos; + import net.pitan76.mcpitanlib.api.client.registry.CompatRegistryClient; ++import net.pitan76.mcpitanlib.api.client.render.CompatMatrixStack; + 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; +@@ -122,6 +123,10 @@ + MatrixStackUtil.scale(matrices, x, y, z); + } + ++ public CompatMatrixStack getCompatMatrices() { ++ return CompatMatrixStack.of(matrices); ++ } ++ + public ItemModelResolver getItemRenderer() { + return ClientUtil.getItemRenderer(); + } diff --git a/publish.bat b/publish.bat new file mode 100644 index 000000000..5005fdec2 --- /dev/null +++ b/publish.bat @@ -0,0 +1,127 @@ +git fetch origin + +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.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.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/settings.gradle b/settings.gradle index 06a89e44e..befe3057a 100644 --- a/settings.gradle +++ b/settings.gradle @@ -3,10 +3,13 @@ pluginManagement { maven { url "https://maven.fabricmc.net/" } maven { url "https://maven.architectury.dev/" } maven { url "https://maven.minecraftforge.net/" } + maven { url "https://maven.pitan76.net/" } gradlePluginPortal() } } include("common") -include("fabric") -include("forge") \ No newline at end of file +if (fabricEnabled.toBoolean()) + include("fabric") +if (neoforgeEnabled.toBoolean()) + include("neoforge") \ No newline at end of file