From 0fc156316f671adb1f0158c6d1b22f3218978fc8 Mon Sep 17 00:00:00 2001 From: Hugman Date: Fri, 23 Jun 2023 12:15:45 +0200 Subject: [PATCH] Major update --- .github/workflows/check_build.yml | 43 ++-- .github/workflows/publish_new_version.yml | 56 ----- .github/workflows/release.yml | 98 +++++++++ .github/workflows/sync.yml | 27 +++ build.gradle | 19 +- crowdin.yml | 8 + gradle.properties | 43 +--- gradle/wrapper/gradle-wrapper.properties | 2 +- src/main/java/fr/hugman/dawn/DawnFactory.java | 193 ++++++++++-------- .../hugman/dawn/block/DawnBlockSettings.java | 93 ++++++--- .../fr/hugman/dawn/block/FlyingBlock.java | 9 +- .../fr/hugman/dawn/command/ExportCommand.java | 6 +- .../hugman/dawn/command/FoodBarCommand.java | 12 +- .../fr/hugman/dawn/command/HealthCommand.java | 10 +- .../fr/hugman/dawn/command/MotionCommand.java | 4 +- .../fr/hugman/dawn/command/ShapeCommand.java | 2 +- .../java/fr/hugman/dawn/debug/BlockData.java | 43 +--- .../hugman/dawn/entity/CustomTNTEntity.java | 12 +- .../hugman/dawn/entity/FlyingBlockEntity.java | 96 ++++----- .../dawn/entity/ai/goal/AnimalTemptGoal.java | 2 +- .../fr/hugman/dawn/item/ItemGroupHelper.java | 10 +- src/main/resources/fabric.mod.json | 132 ++++++------ 22 files changed, 505 insertions(+), 415 deletions(-) delete mode 100644 .github/workflows/publish_new_version.yml create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/sync.yml create mode 100644 crowdin.yml diff --git a/.github/workflows/check_build.yml b/.github/workflows/check_build.yml index e6ac202..746d8d1 100644 --- a/.github/workflows/check_build.yml +++ b/.github/workflows/check_build.yml @@ -4,7 +4,11 @@ # against bad commits. name: Check Build -on: [pull_request, push] +on: + pull_request: + types: [review_requested, ready_for_review] + push: + branches: [main, dev] jobs: build: @@ -12,23 +16,24 @@ jobs: matrix: java: [ 17 ] os: [ ubuntu-20.04 ] + name: Build the project (Java ${{ matrix.java }}, on ${{ matrix.os }})) runs-on: ${{ matrix.os }} steps: - - name: Checkout repository - uses: actions/checkout@v2 - - name: Validate Gradle wrapper - uses: gradle/wrapper-validation-action@v1 - - name: Setup JDK ${{ matrix.java }} - uses: actions/setup-java@v1 - with: - java-version: ${{ matrix.java }} - - name: Make Gradle wrapper executable - if: ${{ runner.os != 'Windows' }} - run: chmod +x ./gradlew - - name: Build - run: ./gradlew build - - name: Capture build artifacts - uses: actions/upload-artifact@v2 - with: - name: Artifacts - path: build/libs/ + + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Validate Gradle wrapper + uses: gradle/wrapper-validation-action@v1 + + - name: Setup JDK ${{ matrix.java }} + uses: actions/setup-java@v1 + with: + java-version: ${{ matrix.java }} + + - name: Make Gradle wrapper executable + if: ${{ runner.os != 'Windows' }} + run: chmod +x ./gradlew + + - name: Build + run: ./gradlew build \ No newline at end of file diff --git a/.github/workflows/publish_new_version.yml b/.github/workflows/publish_new_version.yml deleted file mode 100644 index de11248..0000000 --- a/.github/workflows/publish_new_version.yml +++ /dev/null @@ -1,56 +0,0 @@ -name: Publish New Version -on: - workflow_dispatch: - inputs: - version: - description: 'New version number' - required: true - previousVersion: - description: 'Last version number' - required: true -jobs: - build: - strategy: - matrix: - java: [ 17 ] - os: [ ubuntu-20.04 ] - runs-on: ${{ matrix.os }} - steps: - - name: Checkout repository - uses: actions/checkout@v2 - with: - fetch-depth: 0 - - name: Create version tag - uses: actions/github-script@v3 - with: - github-token: ${{ github.token }} - script: | - github.git.createRef({ - owner: context.repo.owner, - repo: context.repo.repo, - ref: "refs/tags/v${{ github.event.inputs.version }}", - sha: context.sha - }) - - name: Fetch tags - run: git fetch --tags - - name: Validate Gradle wrapper - uses: gradle/wrapper-validation-action@v1 - - name: Setup JDK ${{ matrix.java }} - uses: actions/setup-java@v1 - with: - java-version: ${{ matrix.java }} - - name: Make Gradle wrapper executable - if: ${{ runner.os != 'Windows' }} - run: chmod +x ./gradlew - - name: Build and release - run: ./gradlew downloadTranslations generateChangelog build curseforge github modrinth --stacktrace --parallel -PlastTag="v${{ github.event.inputs.previousVersion }}" -PcurrentTag="v${{ github.event.inputs.version }}" - env: - CURSEFORGE_TOKEN: ${{ secrets.CURSEFORGE_TOKEN }} - MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }} - GITHUB_TOKEN: ${{ secrets.GH_API_KEY }} - DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }} - - name: Capture build artifacts - uses: actions/upload-artifact@v2 - with: - name: Artifacts - path: build/libs/ \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..ae35d52 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,98 @@ +# Automatically builds and publishes the mod when a new release is created on GitHub. +# It uploads the mod to GitHub, CurseForge and Modrinth. + +name: Release + +on: + release: + types: [published] + +jobs: + publish: + name: Build & Publish + runs-on: ubuntu-latest + steps: + + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Download translations from Crowdin + uses: crowdin/github-action@v1 + with: + upload_sources: false + upload_translations: false + download_translations: true + create_pull_request: false + push_translations: false + env: + CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }} + + - name: Set up JDK 17 + uses: actions/setup-java@v1 + with: + java-version: '17' + + - name: Grant execute permission for gradlew + run: chmod +x ./gradlew + + - name: Build with Gradle + run: ./gradlew clean build -Pversion=${{ github.event.release.tag_name }} + + - name: Read Gradle properties + id: gradle_properties + uses: christian-draeger/read-properties@1.1.1 + with: + path: './gradle.properties' + properties: 'mod_id mod_name mod_logo mod_color loader_name loader_icon minecraft_version' + + - name: Publish mod to GitHub, CurseForge and Modrinth + id: publish + uses: Kir-Antipov/mc-publish@v3.3 + with: + curseforge-token: ${{ secrets.CURSEFORGE_TOKEN }} + modrinth-token: ${{ secrets.MODRINTH_TOKEN }} + github-token: ${{ secrets.GITHUB_TOKEN }} + + changelog: ${{ github.event.release.body }} + java: 17 + + modrinth-featured: false + + - name: Add job summary + run: | + echo "# Results" >> $GITHUB_STEP_SUMMARY + echo "- Mod ID: ${{ steps.gradle_properties.outputs.mod_id }}" >> $GITHUB_STEP_SUMMARY + echo "- Mod Name: ${{ steps.gradle_properties.outputs.mod_name }}" >> $GITHUB_STEP_SUMMARY + echo "- Mod Version: ${{ github.event.release.tag_name }}" >> $GITHUB_STEP_SUMMARY + echo "- Release Name: ${{ github.event.release.name }}" >> $GITHUB_STEP_SUMMARY + echo "- Minecraft Version: ${{ steps.gradle_properties.outputs.minecraft_version }}" >> $GITHUB_STEP_SUMMARY + echo "- [CurseForge Link](${{ steps.publish.outputs.curseforge-url }})" >> $GITHUB_STEP_SUMMARY + echo "- [Modrinth Link](${{ steps.publish.outputs.modrinth-url }})" >> $GITHUB_STEP_SUMMARY + echo "- [GitHub Link](${{ steps.publish.outputs.github-url }})" >> $GITHUB_STEP_SUMMARY + echo "# Changelog" >> $GITHUB_STEP_SUMMARY + echo "${{ github.event.release.body }}" >> $GITHUB_STEP_SUMMARY + + - name: Send Discord webhook + uses: Ilshidur/action-discord@0.3.2 + env: + DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }} + DISCORD_EMBEDS: | + [{ + "title": "${{ github.event.release.name }} for ${{ steps.gradle_properties.outputs.minecraft_version }} Released", + "color": ${{ steps.gradle_properties.outputs.mod_color }}, + "thumbnail": { + "url": "${{ steps.gradle_properties.outputs.mod_logo }}" + }, + "url": "${{ steps.publish.outputs.curseforge-url }}", + "fields": [ + { + "name": "Download now:", + "value": "[<:curseforge:805066577871110196> CurseForge](${{ steps.publish.outputs.curseforge-url }})\n[<:modrinth:805066578215043092> Modrinth](${{ steps.publish.outputs.modrinth-url }})\n[<:github:805066578164580392> GitHub](${{ steps.publish.outputs.github-url }})", + "inline": true + } + ], + "footer": { + "text": "A ${{ steps.gradle_properties.outputs.loader_name }} Mod", + "icon_url": "${{ steps.gradle_properties.outputs.loader_icon }}" + } + }] \ No newline at end of file diff --git a/.github/workflows/sync.yml b/.github/workflows/sync.yml new file mode 100644 index 0000000..d716ec3 --- /dev/null +++ b/.github/workflows/sync.yml @@ -0,0 +1,27 @@ +# Automatically upload translations to Crowdin for every push to the main or dev branch. +# This allows strings to be translated before a new version is released. + +name: Synchronize Project + +on: + push: + paths: + - 'src/main/resources/assets/dawn/lang/en_us.json' + branches: [main, dev] + +jobs: + crowdin: + runs-on: ubuntu-latest + steps: + + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Upload translations source file to Crowdin + uses: crowdin/github-action@v1 + with: + upload_sources: true + upload_translations: false + download_translations: false + env: + CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }} \ No newline at end of file diff --git a/build.gradle b/build.gradle index 99a210f..451e3e8 100644 --- a/build.gradle +++ b/build.gradle @@ -1,10 +1,8 @@ plugins { - id 'fabric-loom' version '1.1-SNAPSHOT' + id 'fabric-loom' version '1.2-SNAPSHOT' } apply from: 'https://dawnteammc.github.io/resources/gradle_scripts/fabric-mod/java-17.gradle' -apply from: 'https://dawnteammc.github.io/resources/gradle_scripts/fabric-publish.gradle' -apply from: 'https://dawnteammc.github.io/resources/gradle_scripts/fabric-translate.gradle' repositories { maven { url 'https://maven.terraformersmc.com/' } // Required for Mod Menu and Terraform APIs @@ -13,19 +11,16 @@ repositories { } dependencies { - modImplementation "com.terraformersmc.terraform-api:terraform-shapes-api-v1:${terraform_shapes_version}" - include "com.terraformersmc.terraform-api:terraform-shapes-api-v1:${terraform_shapes_version}" - modImplementation "com.terraformersmc.terraform-api:terraform-wood-api-v1:${terraform_wood_version}" - include "com.terraformersmc.terraform-api:terraform-wood-api-v1:${terraform_wood_version}" + includeMod "com.terraformersmc.terraform-api:terraform-shapes-api-v1:${terraform_shapes_version}" + includeMod "com.terraformersmc.terraform-api:terraform-wood-api-v1:${terraform_wood_version}" - modImplementation "me.shedaniel.cloth:cloth-config-fabric:${cloth_version}" - include "me.shedaniel.cloth:cloth-config-fabric:${cloth_version}" + includeMod "me.shedaniel.cloth:cloth-config-fabric:${cloth_version}" - modImplementation("com.terraformersmc:modmenu:${modmenu_version}") { + modApi("com.terraformersmc:modmenu:${modmenu_version}") { exclude(group: "net.fabricmc.fabric-api") } - modImplementation "squeek.appleskin:appleskin-fabric:mc1.19.4-${appleskin_version}:api" - modImplementation("squeek.appleskin:appleskin-fabric:mc1.19.4-${appleskin_version}") { + modApi "squeek.appleskin:appleskin-fabric:mc1.20-${appleskin_version}:api" + modApi("squeek.appleskin:appleskin-fabric:mc1.20-${appleskin_version}") { exclude module: 'modmenu' } } diff --git a/crowdin.yml b/crowdin.yml new file mode 100644 index 0000000..92d93ac --- /dev/null +++ b/crowdin.yml @@ -0,0 +1,8 @@ +project_id: "427504" +api_token_env: "CROWDIN_PERSONAL_TOKEN" +preserve_hierarchy: true + +files: + - source: "src/main/resources/assets/dawn/lang/en_us.json" + translation: "src/main/resources/assets/dawn/lang/%locale_with_underscore%.json" + dest: "dawn.json" \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 28a4e69..ff047d0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,47 +1,26 @@ org.gradle.jvmargs=-Xmx1G -# Mod Metadata +# Release Metadata mod_id=dawn mod_name=Dawn API mod_logo=https://dawnteammc.github.io/images/logo.png -mod_color=0x4159e7 -mod_default_release_type=stable - -# Loader Metadata +mod_color=4282855 loader_name=Fabric loader_icon=https://fabricmc.net/assets/logo.png -# GitHub Metadata -github_name=DawnAPI - -# CurseForge Metadata -curseforge_slug=dawn -curseforge_id=399309 -curseforge_game_versions=1.19.4, Java 17, Fabric, Quilt -curseforge_embedded_libraries=cloth-config -curseforge_required_dependencies=fabric-api - -# Modrinth Metadata -modrinth_slug=dawn -modrinth_id=meZK2DCX -modrinth_game_versions=1.19.4 -modrinth_mod_loaders=fabric, quilt -modrinth_embedded_dependencies=cloth-config -modrinth_required_dependencies=fabric-api - # https://fabricmc.net/develop/ -minecraft_version=1.19.4 -yarn_mappings=1.19.4+build.1 -loader_version=0.14.18 -fabric_version=0.76.0+1.19.4 +minecraft_version=1.20 +yarn_mappings=1.20+build.1 +loader_version=0.14.21 +fabric_version=0.83.0+1.20 # https://maven.shedaniel.me/me/shedaniel/cloth/cloth-config-fabric/ -cloth_version=10.0.96 +cloth_version=11.0.99 # https://maven.terraformersmc.com/releases/com/terraformersmc/terraform-api/terraform-shapes-api-v1 -terraform_shapes_version=6.1.0 +terraform_shapes_version=7.0.1 # https://maven.terraformersmc.com/releases/com/terraformersmc/terraform-api/terraform-wood-api-v1 -terraform_wood_version=6.1.0 +terraform_wood_version=7.0.1 # https://maven.terraformersmc.com/releases/com/terraformersmc/modmenu/ -modmenu_version=6.2.2 +modmenu_version=7.0.1 # https://maven.ryanliptak.com/squeek/appleskin/appleskin-fabric/ -appleskin_version=2.4.3 +appleskin_version=2.5.0 \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ffed3a2..fae0804 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.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/java/fr/hugman/dawn/DawnFactory.java b/src/main/java/fr/hugman/dawn/DawnFactory.java index c282066..c2277dc 100644 --- a/src/main/java/fr/hugman/dawn/DawnFactory.java +++ b/src/main/java/fr/hugman/dawn/DawnFactory.java @@ -18,6 +18,8 @@ import fr.hugman.dawn.shape.processor.ShapeProcessor; import fr.hugman.dawn.shape.processor.ShapeProcessorType; import net.minecraft.block.*; +import net.minecraft.block.enums.Instrument; +import net.minecraft.block.piston.PistonBehavior; import net.minecraft.block.sapling.SaplingGenerator; import net.minecraft.entity.EntityType; import net.minecraft.entity.mob.MobEntity; @@ -30,10 +32,7 @@ import net.minecraft.registry.RegistryKey; import net.minecraft.registry.RegistryKeys; import net.minecraft.registry.tag.TagKey; -import net.minecraft.resource.featuretoggle.FeatureFlags; import net.minecraft.sound.BlockSoundGroup; -import net.minecraft.sound.SoundEvent; -import net.minecraft.sound.SoundEvents; import net.minecraft.util.Identifier; import net.minecraft.util.math.Direction; import net.minecraft.world.biome.Biome; @@ -116,34 +115,40 @@ public static TagKey fluidTag(Identifier id) { /* WOOD */ /*==========*/ - public static Block planks(boolean isNether, MapColor color) { - return new Block(DawnFactory.planksSettings(isNether, color)); + public static Block planks(MapColor color, BlockSoundGroup sounds, boolean flammable) { + return new Block(DawnFactory.planksSettings(color, sounds, flammable)); } - public static DawnBlockSettings planksSettings(boolean isNether, MapColor color) { - DawnBlockSettings settings = DawnBlockSettings.of(isNether ? Material.NETHER_WOOD : Material.WOOD, color) + public static DawnBlockSettings planksSettings(MapColor color, BlockSoundGroup sounds, boolean flammable) { + DawnBlockSettings settings = DawnBlockSettings.create() + .mapColor(color) + .instrument(Instrument.BASS) .item() .strength(2.0f, 3.0f) - .sounds(isNether ? BlockSoundGroup.NETHER_WOOD : BlockSoundGroup.WOOD); - if(isNether) settings.flammability(5, 20); + .sounds(sounds); + if(flammable) settings.burnable(5, 20); return settings; } - public static DawnBlockSettings logSettings(boolean isNether, MapColor woodColor, MapColor barkColor) { - DawnBlockSettings settings = DawnBlockSettings.of(isNether ? Material.NETHER_WOOD : Material.WOOD, (state) -> state.get(PillarBlock.AXIS) == Direction.Axis.Y ? woodColor : barkColor) + public static DawnBlockSettings logSettings(MapColor woodColor, MapColor barkColor, BlockSoundGroup sounds, boolean flammable) { + DawnBlockSettings settings = DawnBlockSettings.create() + .mapColor((state) -> state.get(PillarBlock.AXIS) == Direction.Axis.Y ? woodColor : barkColor) + .instrument(Instrument.BASS) .item() .strength(2.0F) - .sounds(isNether ? BlockSoundGroup.NETHER_STEM : BlockSoundGroup.WOOD); - if(isNether) settings.flammability(5, 5); + .sounds(sounds); + if(flammable) settings.burnable(5, 5); return settings; } - public static DawnBlockSettings logSettings(boolean isNether, MapColor color) { - DawnBlockSettings settings = DawnBlockSettings.of(isNether ? Material.NETHER_WOOD : Material.WOOD, color) + public static DawnBlockSettings logSettings(MapColor color, BlockSoundGroup sounds, boolean flammable) { + DawnBlockSettings settings = DawnBlockSettings.create() + .mapColor(color) + .instrument(Instrument.BASS) .item() .strength(2.0F) - .sounds(isNether ? BlockSoundGroup.NETHER_STEM : BlockSoundGroup.WOOD); - if(isNether) settings.flammability(5, 5); + .sounds(sounds); + if(flammable) settings.burnable(5, 5); return settings; } @@ -155,49 +160,45 @@ public static SlabBlock slab(Block baseBlock) { return new SlabBlock(DawnBlockSettings.copy(baseBlock)); } - public static PressurePlateBlock pressurePlate(Block baseBlock, PressurePlateBlock.ActivationRule activationRule, BlockSetType setType) { + public static PressurePlateBlock pressurePlate(Block baseBlock, BlockSetType setType, PressurePlateBlock.ActivationRule activationRule) { DawnBlockSettings settings = DawnBlockSettings.copy(baseBlock) .strength(0.5f) + .pistonBehavior(PistonBehavior.DESTROY) + .requiresTool() .noCollision(); return new PressurePlateBlock(activationRule, settings, setType); } - public static PressurePlateBlock pressurePlate(Block baseBlock) { - return pressurePlate(baseBlock, PressurePlateBlock.ActivationRule.MOBS, BlockSetType.OAK); + public static PressurePlateBlock pressurePlate(Block baseBlock, BlockSetType setType) { + return pressurePlate(baseBlock, setType, PressurePlateBlock.ActivationRule.MOBS); } - public static ButtonBlock woodenButton(boolean isNether, BlockSetType setType) { - return new ButtonBlock(DawnBlockSettings.of(Material.DECORATION) + public static ButtonBlock woodenButton(Block baseBlock, BlockSetType setType) { + return new ButtonBlock(DawnBlockSettings.create() .item() .strength(0.5f) .noCollision() - .sounds(isNether ? BlockSoundGroup.NETHER_WOOD : BlockSoundGroup.WOOD), + .pistonBehavior(PistonBehavior.DESTROY) + .sounds(baseBlock.getDefaultState().getSoundGroup()), setType, 30, true); } - public static ButtonBlock woodenButton(boolean isNether) { - return woodenButton(isNether, BlockSetType.OAK); + public static FenceBlock fence(Block baseBlock) { + DawnBlockSettings settings = DawnBlockSettings.copy(baseBlock); + return new FenceBlock(settings + .solid() + .item(new DawnItemSettings().fuelTime(settings.getFlameBurn() > 0 ? 300 : 0)) + ); } - public static FenceBlock fence(boolean isNether, Block baseBlock) { - DawnBlockSettings settings = DawnBlockSettings.copy(baseBlock).item(new DawnItemSettings().fuelTime(isNether ? 0 : 300)); - if(isNether) settings.flammability(5, 20); - return new FenceBlock(settings); - } - - - public static FenceGateBlock fenceGate(boolean isNether, Block baseBlock, WoodType woodType) { - DawnBlockSettings settings = DawnBlockSettings.copy(baseBlock).item(new DawnItemSettings().fuelTime(isNether ? 0 : 300)); - if(isNether) settings.flammability(5, 20); - return new FenceGateBlock(settings, woodType); - } - - public static FenceGateBlock fenceGate(boolean isNether, Block baseBlock) { - return fenceGate(isNether, baseBlock, WoodType.OAK); + public static FenceGateBlock fenceGate(Block baseBlock, WoodType woodType) { + DawnBlockSettings settings = DawnBlockSettings.copy(baseBlock); + return new FenceGateBlock(settings.solid() + .item(new DawnItemSettings().fuelTime(settings.getFlameBurn() > 0 ? 300 : 0)), woodType); } public static WallBlock wall(Block baseBlock) { - return new WallBlock(DawnBlockSettings.copy(baseBlock)); + return new WallBlock(DawnBlockSettings.copy(baseBlock).solid()); } public static TrapdoorBlock trapdoor(Block baseBlock, BlockSetType setType) { @@ -208,55 +209,65 @@ public static TrapdoorBlock trapdoor(Block baseBlock, BlockSetType setType) { return new TrapdoorBlock(settings, setType); } - public static TrapdoorBlock woodenTrapdoor(Block baseBlock) { - return trapdoor(baseBlock, BlockSetType.OAK); - } - public static DoorBlock door(Block baseBlock, BlockSetType setType) { - return new DoorBlock(DawnBlockSettings.copy(baseBlock).strength(3.0f).nonOpaque(), setType); - } - - public static DoorBlock woodenDoor(Block baseBlock) { - return door(baseBlock, BlockSetType.OAK); + return new DoorBlock(DawnBlockSettings.copy(baseBlock) + .strength(3.0f) + .nonOpaque() + .pistonBehavior(PistonBehavior.DESTROY), setType); } - public static SaplingBlock sapling(SaplingGenerator generator) { - return new SaplingBlock(generator, DawnBlockSettings.of(Material.PLANT) + public static SaplingBlock sapling(MapColor mapColor, SaplingGenerator generator) { + return new SaplingBlock(generator, DawnBlockSettings.create() .item(new DawnItemSettings().compostingChance(0.3f)) + .mapColor(mapColor) .sounds(BlockSoundGroup.GRASS) .breakInstantly() .noCollision() - .ticksRandomly()); + .ticksRandomly() + .pistonBehavior(PistonBehavior.DESTROY)); } - public static DawnSaplingBlock sapling(SaplingGenerator generator, Predicate saplingSoilPredicate) { - return new DawnSaplingBlock(generator, saplingSoilPredicate, DawnBlockSettings.of(Material.PLANT) + public static DawnSaplingBlock sapling(MapColor mapColor, SaplingGenerator generator, Predicate saplingSoilPredicate) { + return new DawnSaplingBlock(generator, saplingSoilPredicate, DawnBlockSettings.create() .item(new DawnItemSettings().compostingChance(0.3f)) + .mapColor(mapColor) .sounds(BlockSoundGroup.GRASS) .breakInstantly() .noCollision() - .ticksRandomly()); + .ticksRandomly() + .pistonBehavior(PistonBehavior.DESTROY)); } - public static DawnFungusBlock fungus(RegistryKey> featureKey, TagKey canPlantOn, TagKey canGrowOn) { - return new DawnFungusBlock(featureKey, canPlantOn, canGrowOn, DawnBlockSettings.of(Material.PLANT) + public static DawnFungusBlock fungus(MapColor mapColor, RegistryKey> featureKey, TagKey canPlantOn, TagKey canGrowOn) { + return new DawnFungusBlock(featureKey, canPlantOn, canGrowOn, DawnBlockSettings.create() .item(new DawnItemSettings().compostingChance(0.65f)) + .mapColor(mapColor) .sounds(BlockSoundGroup.FUNGUS) + .pistonBehavior(PistonBehavior.DESTROY) .breakInstantly() .noCollision()); } public static FlowerPotBlock potted(Block content) { - return new FlowerPotBlock(content, DawnBlockSettings.of(Material.DECORATION).breakInstantly().nonOpaque().luminance(content.getDefaultState().getLuminance())); + return new FlowerPotBlock(content, DawnBlockSettings.create() + .breakInstantly() + .nonOpaque() + .luminance(content.getDefaultState().getLuminance()) + .pistonBehavior(PistonBehavior.DESTROY)); + } + + public static LeavesBlock leaves(MapColor mapColor) { + return leaves(mapColor, BlockSoundGroup.GRASS); } - public static LeavesBlock leaves() { - return leaves(BlockSoundGroup.GRASS); + public static LeavesBlock leaves(MapColor mapColor, BlockSoundGroup soundGroup) { + return new LeavesBlock(leavesSettings(mapColor, soundGroup)); } - public static LeavesBlock leaves(BlockSoundGroup soundGroup) { - return new LeavesBlock(DawnBlockSettings.of(Material.LEAVES) + public static DawnBlockSettings leavesSettings(MapColor mapColor, BlockSoundGroup soundGroup) { + return DawnBlockSettings.create() .item(new DawnItemSettings().compostingChance(0.3f)) + .mapColor(mapColor) .strength(0.2f) .ticksRandomly() .sounds(soundGroup) @@ -264,41 +275,51 @@ public static LeavesBlock leaves(BlockSoundGroup soundGroup) { .allowsSpawning((state, world, pos, type) -> type == EntityType.OCELOT || type == EntityType.PARROT) .suffocates((state, world, pos) -> false) .blockVision((state, world, pos) -> false) - .flammability(30, 60)); + .burnable(30, 60) + .pistonBehavior(PistonBehavior.DESTROY) + .solidBlock((state, world, pos) -> false); } public static SignBlocks signs(Identifier texturePath, Block basePlanks) { + BlockSoundGroup soundGroup = basePlanks.getDefaultState().getSoundGroup(); + BlockSoundGroup hangingSoundGroup = BlockSoundGroup.WOOD; + if(soundGroup == BlockSoundGroup.CHERRY_WOOD) { + hangingSoundGroup = BlockSoundGroup.CHERRY_WOOD_HANGING_SIGN; + } + else if(soundGroup == BlockSoundGroup.BAMBOO_WOOD) { + hangingSoundGroup = BlockSoundGroup.BAMBOO_WOOD_HANGING_SIGN; + } + else if(soundGroup == BlockSoundGroup.NETHER_WOOD) { + hangingSoundGroup = BlockSoundGroup.NETHER_WOOD_HANGING_SIGN; + } + + return signs(texturePath, basePlanks, soundGroup, hangingSoundGroup); + } + + public static SignBlocks signs(Identifier texturePath, Block basePlanks, BlockSoundGroup normalSounds, BlockSoundGroup hangingSounds) { var signTexture = Identifier.of(texturePath.getNamespace(), "entity/signs/" + texturePath.getPath()); var hangingSignTexture = Identifier.of(texturePath.getNamespace(), "entity/signs/hanging/" + texturePath.getPath()); var hangingSignGuiTexture = Identifier.of(texturePath.getNamespace(), "textures/gui/hanging_signs/" + texturePath.getPath()); - var sign = new TerraformSignBlock(signTexture, signSettings(basePlanks)); - var wallSign = new TerraformWallSignBlock(signTexture, signSettings(basePlanks)); - var hangingSign = new TerraformHangingSignBlock(hangingSignTexture, hangingSignGuiTexture, hangingSignSettings(basePlanks)); - var wallHangingSign = new TerraformWallHangingSignBlock(hangingSignTexture, hangingSignGuiTexture, hangingSignSettings(basePlanks)); + var sign = new TerraformSignBlock(signTexture, signSettings(basePlanks, normalSounds)); + var wallSign = new TerraformWallSignBlock(signTexture, signSettings(basePlanks, normalSounds)); + var hangingSign = new TerraformHangingSignBlock(hangingSignTexture, hangingSignGuiTexture, signSettings(basePlanks, hangingSounds)); + var wallHangingSign = new TerraformWallHangingSignBlock(hangingSignTexture, hangingSignGuiTexture, signSettings(basePlanks, hangingSounds)); var signItem = new SignItem(new DawnItemSettings().maxCount(16), sign, wallSign); - var hangingSignItem = new HangingSignItem(hangingSign, wallHangingSign, new DawnItemSettings().maxCount(16).requires(FeatureFlags.UPDATE_1_20)); + var hangingSignItem = new HangingSignItem(hangingSign, wallHangingSign, new DawnItemSettings().maxCount(16)); return new SignBlocks(sign, wallSign, hangingSign, wallHangingSign, signItem, hangingSignItem); } - public static DawnBlockSettings signSettings(Block basePlanks, boolean hanging) { - var settings = DawnBlockSettings.of(basePlanks.getDefaultState().getMaterial(), basePlanks.getDefaultMapColor()).noCollision().strength(1.0F); - if(hanging) { - settings.sounds(BlockSoundGroup.HANGING_SIGN).requires(FeatureFlags.UPDATE_1_20); - } - else { - settings.sounds(BlockSoundGroup.WOOD); - } - return settings; - } - - public static DawnBlockSettings signSettings(Block basePlanks) { - return signSettings(basePlanks, false); - } - - public static DawnBlockSettings hangingSignSettings(Block basePlanks) { - return signSettings(basePlanks, true); + public static DawnBlockSettings signSettings(Block basePlanks, BlockSoundGroup soundGroup) { + return DawnBlockSettings.create() + .sounds(soundGroup) + .mapColor(basePlanks.getDefaultMapColor()) + .solid() + .instrument(Instrument.BASS) + .noCollision() + .strength(1.0F) + .burnable(); } public static TerraformBoatType boat(Identifier id, ItemConvertible planks, boolean raft) { diff --git a/src/main/java/fr/hugman/dawn/block/DawnBlockSettings.java b/src/main/java/fr/hugman/dawn/block/DawnBlockSettings.java index c460d1c..00d865a 100644 --- a/src/main/java/fr/hugman/dawn/block/DawnBlockSettings.java +++ b/src/main/java/fr/hugman/dawn/block/DawnBlockSettings.java @@ -7,7 +7,8 @@ import net.minecraft.block.BlockState; import net.minecraft.block.FireBlock; import net.minecraft.block.MapColor; -import net.minecraft.block.Material; +import net.minecraft.block.enums.Instrument; +import net.minecraft.block.piston.PistonBehavior; import net.minecraft.entity.EntityType; import net.minecraft.item.AxeItem; import net.minecraft.item.Item; @@ -38,8 +39,8 @@ public class DawnBlockSettings extends FabricBlockSettings { @Nullable private Item.Settings itemSettings; - protected DawnBlockSettings(Material material, MapColor color) { - super(material, color); + protected DawnBlockSettings() { + super(); } protected DawnBlockSettings(AbstractBlock.Settings settings) { @@ -55,43 +56,31 @@ protected DawnBlockSettings(AbstractBlock.Settings settings) { // Getters public int getFlameBurn() { - return flameBurn; + return this.flameBurn; } public int getFlameSpread() { - return flameSpread; + return this.flameSpread; } @Nullable public Block getStripInto() { - return stripInto; + return this.stripInto; } @Nullable public Item.Settings getItemSettings() { - return itemSettings; + return this.itemSettings; } // Factory methods - public static DawnBlockSettings of(Material material) { - return of(material, material.getColor()); - } - - public static DawnBlockSettings of(Material material, MapColor color) { - return new DawnBlockSettings(material, color); - } - - public static DawnBlockSettings of(Material material, DyeColor color) { - return new DawnBlockSettings(material, color.getMapColor()); - } - - public static DawnBlockSettings of(Material material, Function mapColor) { - return new DawnBlockSettings(AbstractBlock.Settings.of(material, mapColor)); + public static DawnBlockSettings create() { + return new DawnBlockSettings(); } public static DawnBlockSettings copy(AbstractBlock block) { - return new DawnBlockSettings(((AbstractBlockAccessor) block).getSettings()); + return copyOf(((AbstractBlockAccessor) block).getSettings()); } public static DawnBlockSettings copyOf(AbstractBlock block) { @@ -105,13 +94,14 @@ public static DawnBlockSettings copyOf(AbstractBlock.Settings settings) { // New methods /** - * Sets the burning and spreading chances of this block. + * Makes the block burnable, sets the burning and spreading chances of this block. * * @see FireBlock#registerDefaultFlammables() Vanilla flammability values */ - public DawnBlockSettings flammability(int burn, int spread) { + public DawnBlockSettings burnable(int burn, int spread) { this.flameBurn = burn; this.flameSpread = spread; + this.burnable(); return this; } @@ -119,7 +109,7 @@ public DawnBlockSettings flammability(int burn, int spread) { * Sets the block that this block will be stripped into when using an axe. * @see AxeItem Vanilla axe stripping values */ - public DawnBlockSettings stripInto(Block block) { + public DawnBlockSettings stripsInto(Block block) { this.stripInto = block; return this; } @@ -214,7 +204,11 @@ public DawnBlockSettings dynamicBounds() { return this; } + /** + * @deprecated this evaluates the loot table (and therefore item registries) instantly, which is not possible in Dawn Team mods because we do not register anything at the same time as construction. + */ @Override + @Deprecated public DawnBlockSettings dropsLike(Block block) { super.dropsLike(block); return this; @@ -286,6 +280,55 @@ public DawnBlockSettings requires(FeatureFlag... features) { return this; } + @Override + public DawnBlockSettings mapColor(Function mapColorProvider) { + super.mapColor(mapColorProvider); + return this; + } + + //TODO: what is this? + @Override + public DawnBlockSettings burnable() { + super.burnable(); + return this; + } + + @Override + public DawnBlockSettings liquid() { + super.liquid(); + return this; + } + + @Override + public DawnBlockSettings solid() { + super.solid(); + return this; + } + + @Override + public DawnBlockSettings notSolid() { + super.notSolid(); + return this; + } + + @Override + public DawnBlockSettings pistonBehavior(PistonBehavior pistonBehavior) { + super.pistonBehavior(pistonBehavior); + return this; + } + + @Override + public DawnBlockSettings instrument(Instrument instrument) { + super.instrument(instrument); + return this; + } + + @Override + public DawnBlockSettings replaceable() { + super.replaceable(); + return this; + } + @Override public DawnBlockSettings luminance(int luminance) { super.luminance(luminance); diff --git a/src/main/java/fr/hugman/dawn/block/FlyingBlock.java b/src/main/java/fr/hugman/dawn/block/FlyingBlock.java index 18ef389..cf7a758 100644 --- a/src/main/java/fr/hugman/dawn/block/FlyingBlock.java +++ b/src/main/java/fr/hugman/dawn/block/FlyingBlock.java @@ -1,8 +1,9 @@ package fr.hugman.dawn.block; import fr.hugman.dawn.entity.FlyingBlockEntity; -import net.minecraft.block.*; -import net.minecraft.entity.FallingBlockEntity; +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.registry.tag.BlockTags; import net.minecraft.server.world.ServerWorld; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; @@ -18,9 +19,7 @@ public FlyingBlock(Settings builder) { } public static boolean canFlyThrough(BlockState state) { - Block block = state.getBlock(); - Material material = state.getMaterial(); - return block instanceof AirBlock || block == Blocks.FIRE || material.isLiquid() || material.isReplaceable(); + return state.isAir() || state.isIn(BlockTags.FIRE) || state.isLiquid() || state.isReplaceable(); } @Override diff --git a/src/main/java/fr/hugman/dawn/command/ExportCommand.java b/src/main/java/fr/hugman/dawn/command/ExportCommand.java index 396d487..200729a 100644 --- a/src/main/java/fr/hugman/dawn/command/ExportCommand.java +++ b/src/main/java/fr/hugman/dawn/command/ExportCommand.java @@ -56,14 +56,14 @@ public static int exportRegistries(ServerCommandSource source, boolean expanded) source.sendError(Text.translatable("commands." + NAME + ".fail.already_exists", exportFileComponent)); return 0; } - source.sendFeedback(Text.translatable("commands." + NAME + ".start"), true); + source.sendFeedback(() -> Text.translatable("commands." + NAME + ".start"), true); try { for(Registry registry : Registries.REGISTRIES) { exportRegistry(registry, expanded, exportPath); } // TODO: where are built-in registries? - source.sendFeedback(Text.translatable("commands." + NAME + ".success", exportFileComponent), true); + source.sendFeedback(() -> Text.translatable("commands." + NAME + ".success", exportFileComponent), true); } catch(IOException e) { source.sendError(Text.translatable("commands." + NAME + ".fail.unknown")); e.printStackTrace(); @@ -85,7 +85,7 @@ public static int exportDynamic(ServerCommandSource source, boolean builtin) { source.sendError(Text.translatable("commands." + NAME + ".fail.already_exists", exportFileComponent)); return 0; } - source.sendFeedback(Text.translatable("commands." + NAME + ".start"), true); + source.sendFeedback(() -> Text.translatable("commands." + NAME + ".start"), true); try { throw new UnsupportedOperationException("Not implemented yet"); diff --git a/src/main/java/fr/hugman/dawn/command/FoodBarCommand.java b/src/main/java/fr/hugman/dawn/command/FoodBarCommand.java index d3e30d2..ec748d4 100644 --- a/src/main/java/fr/hugman/dawn/command/FoodBarCommand.java +++ b/src/main/java/fr/hugman/dawn/command/FoodBarCommand.java @@ -55,13 +55,13 @@ public static void register(CommandDispatcher dispatcher) { private static int queryFood(ServerCommandSource source, ServerPlayerEntity target) { int foodLevel = target.getHungerManager().getFoodLevel(); - source.sendFeedback(Text.translatable("commands.foodbar.query.food", target.getDisplayName(), foodLevel), false); + source.sendFeedback(() -> Text.translatable("commands.foodbar.query.food", target.getDisplayName(), foodLevel), false); return foodLevel; } private static int querySaturation(ServerCommandSource source, ServerPlayerEntity target) { float saturationLevel = target.getHungerManager().getSaturationLevel(); - source.sendFeedback(Text.translatable("commands.foodbar.query.saturation", target.getDisplayName(), saturationLevel), false); + source.sendFeedback(() -> Text.translatable("commands.foodbar.query.saturation", target.getDisplayName(), saturationLevel), false); return (int) saturationLevel; } @@ -72,10 +72,10 @@ private static int setFood(ServerCommandSource source, Collection Text.translatable("commands.foodbar." + parameter + ".food.success.single", amount, targets.iterator().next().getDisplayName()), true); } else { - source.sendFeedback(Text.translatable("commands.foodbar." + parameter + ".food.success.multiple", amount, targets.size()), true); + source.sendFeedback(() -> Text.translatable("commands.foodbar." + parameter + ".food.success.multiple", amount, targets.size()), true); } return targets.size(); } @@ -87,10 +87,10 @@ private static int setSaturation(ServerCommandSource source, Collection Text.translatable("commands.foodbar." + parameter + ".saturation.success.single", amount, targets.iterator().next().getDisplayName()), true); } else { - source.sendFeedback(Text.translatable("commands.foodbar." + parameter + ".saturation.success.multiple", amount, targets.size()), true); + source.sendFeedback(() -> Text.translatable("commands.foodbar." + parameter + ".saturation.success.multiple", amount, targets.size()), true); } return targets.size(); } diff --git a/src/main/java/fr/hugman/dawn/command/HealthCommand.java b/src/main/java/fr/hugman/dawn/command/HealthCommand.java index ae9f2ef..48b041e 100644 --- a/src/main/java/fr/hugman/dawn/command/HealthCommand.java +++ b/src/main/java/fr/hugman/dawn/command/HealthCommand.java @@ -6,7 +6,6 @@ import net.minecraft.command.argument.EntityArgumentType; import net.minecraft.entity.Entity; import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.damage.DamageSource; import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.text.Text; @@ -45,11 +44,11 @@ public static void register(CommandDispatcher dispatcher) { private static int queryHealth(ServerCommandSource source, Entity target) { if(target instanceof LivingEntity livingEntity) { float health = livingEntity.getHealth(); - source.sendFeedback(Text.translatable("commands.health.query.success", target.getDisplayName(), health), false); + source.sendFeedback(() -> Text.translatable("commands.health.query.success", target.getDisplayName(), health), false); return (int) health; } else { - source.sendFeedback(Text.translatable("commands.health.query.failed"), false); + source.sendFeedback(() -> Text.translatable("commands.health.query.failed"), false); return 0; } } @@ -78,10 +77,11 @@ private static int setHealth(ServerCommandSource source, Collection Text.translatable("commands.health." + parameter + ".success.single", amount, targets.iterator().next().getDisplayName()), true); } else { - source.sendFeedback(Text.translatable("commands.health." + parameter + ".success.multiple", amount, finalTargetAmount), true); + int finalTargetAmount1 = finalTargetAmount; + source.sendFeedback(() -> Text.translatable("commands.health." + parameter + ".success.multiple", amount, finalTargetAmount1), true); } return finalTargetAmount; } diff --git a/src/main/java/fr/hugman/dawn/command/MotionCommand.java b/src/main/java/fr/hugman/dawn/command/MotionCommand.java index 7939f92..ed829d5 100644 --- a/src/main/java/fr/hugman/dawn/command/MotionCommand.java +++ b/src/main/java/fr/hugman/dawn/command/MotionCommand.java @@ -50,10 +50,10 @@ private static int setMotion(ServerCommandSource source, Collection Text.translatable("commands.motion." + parameter + ".success.single", x, y, z, targets.iterator().next().getDisplayName()), true); } else { - source.sendFeedback(Text.translatable("commands.motion." + parameter + ".success.multiple", x, y, z, targets.size()), true); + source.sendFeedback(() -> Text.translatable("commands.motion." + parameter + ".success.multiple", x, y, z, targets.size()), true); } return targets.size(); } diff --git a/src/main/java/fr/hugman/dawn/command/ShapeCommand.java b/src/main/java/fr/hugman/dawn/command/ShapeCommand.java index 4b24406..5c15aa4 100644 --- a/src/main/java/fr/hugman/dawn/command/ShapeCommand.java +++ b/src/main/java/fr/hugman/dawn/command/ShapeCommand.java @@ -78,7 +78,7 @@ private static int fillShape(ServerCommandSource source, Identifier identifier, stateArgument.setBlockState(world, blockPos, Block.NOTIFY_LISTENERS); } - source.sendFeedback(Text.translatable("commands.shape.fill.success", identifier, i, stateArgument.getBlockState().getBlock().getName()), true); + source.sendFeedback(() -> Text.translatable("commands.shape.fill.success", identifier, i, stateArgument.getBlockState().getBlock().getName()), true); return i; } } \ No newline at end of file diff --git a/src/main/java/fr/hugman/dawn/debug/BlockData.java b/src/main/java/fr/hugman/dawn/debug/BlockData.java index a0722bc..6d4f80e 100644 --- a/src/main/java/fr/hugman/dawn/debug/BlockData.java +++ b/src/main/java/fr/hugman/dawn/debug/BlockData.java @@ -5,8 +5,6 @@ import net.fabricmc.fabric.mixin.object.builder.AbstractBlockAccessor; import net.fabricmc.fabric.mixin.object.builder.AbstractBlockSettingsAccessor; import net.minecraft.block.Block; -import net.minecraft.block.Material; -import net.minecraft.block.piston.PistonBehavior; import net.minecraft.util.Identifier; public class BlockData { @@ -21,8 +19,6 @@ public BlockData(Identifier id, Block block) { } public static class Properties { - @Expose - protected Properties.MaterialProperties material; @Expose protected float hardness; @Expose @@ -50,7 +46,6 @@ public static class Properties { public Properties(Block block) { AbstractBlockSettingsAccessor settings = (AbstractBlockSettingsAccessor) ((AbstractBlockAccessor) block).getSettings(); - this.material = new Properties.MaterialProperties(settings.getMaterial()); this.hardness = settings.getHardness(); this.blastResistance = settings.getResistance(); this.randomlyTicks = settings.getRandomTicks(); @@ -60,43 +55,7 @@ public Properties(Block block) { this.opaque = settings.getOpaque(); this.isAir = settings.getIsAir(); this.isToolRequired = settings.isToolRequired(); - } - - public static class MaterialProperties { - @Expose - @SerializedName("is_liquid") - protected boolean isLiquid; - @Expose - @SerializedName("is_solid") - protected boolean isSolid; - @Expose - @SerializedName("blocks_movement") - protected boolean blocksMovement; - @Expose - @SerializedName("is_burnable") - protected boolean isBurnable; - @Expose - @SerializedName("is_replaceable") - protected boolean isReplaceable; - @Expose - @SerializedName("blocks_light") - protected boolean blocksLight; - @Expose - @SerializedName("piston_behavior") - protected PistonBehavior pistonBehavior; - @Expose - protected int color; - - public MaterialProperties(Material material) { - this.isLiquid = material.isLiquid(); - this.isSolid = material.isSolid(); - this.blocksMovement = material.blocksMovement(); - this.isBurnable = material.isBurnable(); - this.isReplaceable = material.isReplaceable(); - this.blocksLight = material.blocksLight(); - this.pistonBehavior = material.getPistonBehavior(); - this.color = material.getColor().color; - } + this.isToolRequired = settings.isToolRequired(); } } } \ No newline at end of file diff --git a/src/main/java/fr/hugman/dawn/entity/CustomTNTEntity.java b/src/main/java/fr/hugman/dawn/entity/CustomTNTEntity.java index 5320198..bff8baf 100644 --- a/src/main/java/fr/hugman/dawn/entity/CustomTNTEntity.java +++ b/src/main/java/fr/hugman/dawn/entity/CustomTNTEntity.java @@ -71,26 +71,26 @@ public void tick() { } this.move(MovementType.SELF, this.getVelocity()); this.setVelocity(this.getVelocity().multiply(0.98D)); - if(this.onGround) { + if(this.isOnGround()) { this.setVelocity(this.getVelocity().multiply(0.7D, -0.5D, 0.7D)); } --this.fuse; if(this.fuse <= 0) { this.discard(); - if(!this.world.isClient) { + if(!this.getWorld().isClient) { this.explode(); } } else { this.updateWaterState(); - if(this.world.isClient) { - this.world.addParticle(ParticleTypes.SMOKE, this.getX(), this.getY() + 0.5D, this.getZ(), 0.0D, 0.0D, 0.0D); + if(this.getWorld().isClient) { + this.getWorld().addParticle(ParticleTypes.SMOKE, this.getX(), this.getY() + 0.5D, this.getZ(), 0.0D, 0.0D, 0.0D); } } } private void explode() { - this.world.createExplosion(this, this.getX(), this.getBodyY(0.0625D), this.getZ(), this.strength, World.ExplosionSourceType.TNT); + this.getWorld().createExplosion(this, this.getX(), this.getBodyY(0.0625D), this.getZ(), this.strength, World.ExplosionSourceType.TNT); } @Override @@ -102,7 +102,7 @@ protected void writeCustomDataToNbt(NbtCompound compound) { @Override protected void readCustomDataFromNbt(NbtCompound nbt) { - this.state = NbtHelper.toBlockState(this.world.createCommandRegistryWrapper(RegistryKeys.BLOCK), nbt.getCompound("BlockState")); + this.state = NbtHelper.toBlockState(this.getWorld().createCommandRegistryWrapper(RegistryKeys.BLOCK), nbt.getCompound("BlockState")); if(this.state.getBlock() == Blocks.AIR) { this.state = Blocks.TNT.getDefaultState(); } diff --git a/src/main/java/fr/hugman/dawn/entity/FlyingBlockEntity.java b/src/main/java/fr/hugman/dawn/entity/FlyingBlockEntity.java index 1a8ddc7..3b22dfe 100644 --- a/src/main/java/fr/hugman/dawn/entity/FlyingBlockEntity.java +++ b/src/main/java/fr/hugman/dawn/entity/FlyingBlockEntity.java @@ -23,6 +23,7 @@ import net.minecraft.network.packet.Packet; import net.minecraft.network.packet.s2c.play.EntitySpawnS2CPacket; import net.minecraft.predicate.entity.EntityPredicates; +import net.minecraft.registry.RegistryKeys; import net.minecraft.registry.tag.BlockTags; import net.minecraft.registry.tag.FluidTags; import net.minecraft.state.property.Properties; @@ -33,7 +34,6 @@ import net.minecraft.util.math.Direction; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; -import net.minecraft.registry.RegistryKeys; import net.minecraft.world.GameRules; import net.minecraft.world.RaycastContext; import net.minecraft.world.RaycastContext.FluidHandling; @@ -74,7 +74,7 @@ public FlyingBlockEntity(World world, double x, double y, double z, BlockState s } public static FlyingBlockEntity spawnFromBlock(World world, BlockPos pos, BlockState state) { - FlyingBlockEntity flyingBlockEntity = new FlyingBlockEntity(world, (double)pos.getX() + 0.5, pos.getY(), (double)pos.getZ() + 0.5, state.contains(Properties.WATERLOGGED) ? state.with(Properties.WATERLOGGED, false) : state); + FlyingBlockEntity flyingBlockEntity = new FlyingBlockEntity(world, (double) pos.getX() + 0.5, pos.getY(), (double) pos.getZ() + 0.5, state.contains(Properties.WATERLOGGED) ? state.with(Properties.WATERLOGGED, false) : state); world.setBlockState(pos, state.getFluidState().getBlockState(), Block.NOTIFY_ALL); world.spawnEntity(flyingBlockEntity); return flyingBlockEntity; @@ -120,10 +120,10 @@ public void tick() { BlockPos blockPos2; if(this.timeFlying++ == 0) { blockPos2 = this.getBlockPos(); - if(this.world.getBlockState(blockPos2).isOf(block)) { - this.world.removeBlock(blockPos2, false); + if(this.getWorld().getBlockState(blockPos2).isOf(block)) { + this.getWorld().removeBlock(blockPos2, false); } - else if(!this.world.isClient) { + else if(!this.getWorld().isClient) { this.discard(); return; } @@ -132,44 +132,44 @@ else if(!this.world.isClient) { this.setVelocity(this.getVelocity().add(0.0D, 0.01D, 0.0D)); } this.move(MovementType.SELF, this.getVelocity()); - if(!this.world.isClient) { + if(!this.getWorld().isClient) { blockPos2 = this.getBlockPos(); boolean bl = this.state.getBlock() instanceof ConcretePowderBlock; - boolean bl2 = bl && this.world.getFluidState(blockPos2).isIn(FluidTags.WATER); + boolean bl2 = bl && this.getWorld().getFluidState(blockPos2).isIn(FluidTags.WATER); double d = this.getVelocity().lengthSquared(); if(bl && d > 1.0D) { - BlockHitResult blockHitResult = this.world.raycast(new RaycastContext(new Vec3d(this.prevX, this.prevY, this.prevZ), this.getPos(), ShapeType.COLLIDER, FluidHandling.SOURCE_ONLY, this)); - if(blockHitResult.getType() != Type.MISS && this.world.getFluidState(blockHitResult.getBlockPos()).isIn(FluidTags.WATER)) { + BlockHitResult blockHitResult = this.getWorld().raycast(new RaycastContext(new Vec3d(this.prevX, this.prevY, this.prevZ), this.getPos(), ShapeType.COLLIDER, FluidHandling.SOURCE_ONLY, this)); + if(blockHitResult.getType() != Type.MISS && this.getWorld().getFluidState(blockHitResult.getBlockPos()).isIn(FluidTags.WATER)) { blockPos2 = blockHitResult.getBlockPos(); bl2 = true; } } - if(FlyingBlock.canFlyThrough(this.world.getBlockState(blockPos2.up())) && !bl2) { - if(!this.world.isClient && (this.timeFlying > 100 && (blockPos2.getY() < 1 || blockPos2.getY() > 256) || this.timeFlying > 600)) { - if(this.dropItem && this.world.getGameRules().getBoolean(GameRules.DO_ENTITY_DROPS)) { + if(FlyingBlock.canFlyThrough(this.getWorld().getBlockState(blockPos2.up())) && !bl2) { + if(!this.getWorld().isClient && (this.timeFlying > 100 && (blockPos2.getY() < 1 || blockPos2.getY() > 256) || this.timeFlying > 600)) { + if(this.dropItem && this.getWorld().getGameRules().getBoolean(GameRules.DO_ENTITY_DROPS)) { this.dropItem(block); } this.discard(); } } else { - BlockState blockState = this.world.getBlockState(blockPos2); + BlockState blockState = this.getWorld().getBlockState(blockPos2); this.setVelocity(this.getVelocity().multiply(0.7D, 0.4D, 0.7D)); if(!blockState.isOf(Blocks.MOVING_PISTON)) { this.discard(); if(!this.destroyedOnLanding) { - boolean bl3 = blockState.canReplace(new AutomaticItemPlacementContext(this.world, blockPos2, Direction.UP, ItemStack.EMPTY, Direction.DOWN)); - boolean bl4 = this.state.canPlaceAt(this.world, blockPos2); + boolean bl3 = blockState.canReplace(new AutomaticItemPlacementContext(this.getWorld(), blockPos2, Direction.UP, ItemStack.EMPTY, Direction.DOWN)); + boolean bl4 = this.state.canPlaceAt(this.getWorld(), blockPos2); if(bl3 && bl4) { - if(this.state.contains(Properties.WATERLOGGED) && this.world.getFluidState(blockPos2).getFluid() == Fluids.WATER) { + if(this.state.contains(Properties.WATERLOGGED) && this.getWorld().getFluidState(blockPos2).getFluid() == Fluids.WATER) { this.state = this.state.with(Properties.WATERLOGGED, Boolean.valueOf(true)); } - if(this.world.setBlockState(blockPos2, this.state, 3)) { + if(this.getWorld().setBlockState(blockPos2, this.state, 3)) { if(block instanceof FlyingBlock) { - ((FlyingBlock) block).onLanding(this.world, blockPos2, this.state, blockState, this); + ((FlyingBlock) block).onLanding(this.getWorld(), blockPos2, this.state, blockState, this); } if(this.blockEntityData != null && block instanceof BlockEntityProvider) { - BlockEntity blockEntity = this.world.getBlockEntity(blockPos2); + BlockEntity blockEntity = this.getWorld().getBlockEntity(blockPos2); if(blockEntity != null) { NbtCompound nbtCompound = blockEntity.createNbt(); for(String string : this.blockEntityData.getKeys()) { @@ -183,16 +183,16 @@ else if(!this.world.isClient) { } } } - else if(this.dropItem && this.world.getGameRules().getBoolean(GameRules.DO_ENTITY_DROPS)) { + else if(this.dropItem && this.getWorld().getGameRules().getBoolean(GameRules.DO_ENTITY_DROPS)) { this.dropItem(block); } } - else if(this.dropItem && this.world.getGameRules().getBoolean(GameRules.DO_ENTITY_DROPS)) { + else if(this.dropItem && this.getWorld().getGameRules().getBoolean(GameRules.DO_ENTITY_DROPS)) { this.dropItem(block); } } else if(block instanceof FlyingBlock) { - ((FlyingBlock) block).onDestroyedOnLanding(this.world, blockPos2, this); + ((FlyingBlock) block).onDestroyedOnLanding(this.getWorld(), blockPos2, this); } } } @@ -203,41 +203,35 @@ else if(block instanceof FlyingBlock) { @Override public boolean handleFallDamage(float fallDistance, float damageMultiplier, DamageSource damageSource) { + DamageSource damageSource2; if(!this.hurtEntities) { return false; } + int i = MathHelper.ceil(fallDistance - 1.0F); + if(i < 0) { + return false; + } + Predicate predicate = EntityPredicates.EXCEPT_CREATIVE_OR_SPECTATOR.and(EntityPredicates.VALID_LIVING_ENTITY); + if(this.state.getBlock() instanceof LandingBlock landingBlock) { + damageSource2 = landingBlock.getDamageSource(this); + } else { - int i = MathHelper.ceil(fallDistance - 1.0F); - if(i < 0) { - return false; + damageSource2 = this.getDamageSources().fallingBlock(this); + } + + float f = (float) Math.min(MathHelper.floor((float) i * this.flyHurtAmount), this.flyHurtMax); + this.getWorld().getOtherEntities(this, this.getBoundingBox(), predicate).forEach((entity) -> entity.damage(damageSource2, f)); + boolean bl = this.state.isIn(BlockTags.ANVIL); + if(bl && this.random.nextFloat() < 0.05f + (float) i * 0.05f) { + BlockState blockState = AnvilBlock.getLandingState(this.state); + if(blockState == null) { + this.destroyedOnLanding = true; } else { - Predicate predicate2; - DamageSource damageSource3; - if(this.state.getBlock() instanceof LandingBlock landingBlock) { - predicate2 = landingBlock.getEntityPredicate(); - damageSource3 = landingBlock.getDamageSource(this); - } - else { - predicate2 = EntityPredicates.EXCEPT_SPECTATOR; - damageSource3 = this.getDamageSources().fallingBlock(this); - } - - float f = (float) Math.min(MathHelper.floor((float) i * this.flyHurtAmount), this.flyHurtMax); - this.world.getOtherEntities(this, this.getBoundingBox(), predicate2).forEach((entity) -> entity.damage(damageSource3, f)); - boolean bl = this.state.isIn(BlockTags.ANVIL); - if(bl && (double) this.random.nextFloat() < 0.05000000074505806D + (double) i * 0.05D) { - BlockState blockState = AnvilBlock.getLandingState(this.state); - if(blockState == null) { - this.destroyedOnLanding = true; - } - else { - this.state = blockState; - } - } - return false; + this.state = blockState; } } + return false; } @Override @@ -255,7 +249,7 @@ protected void writeCustomDataToNbt(NbtCompound tag) { @Override protected void readCustomDataFromNbt(NbtCompound tag) { - this.state = NbtHelper.toBlockState(this.world.createCommandRegistryWrapper(RegistryKeys.BLOCK), tag.getCompound("BlockState")); + this.state = NbtHelper.toBlockState(this.getWorld().createCommandRegistryWrapper(RegistryKeys.BLOCK), tag.getCompound("BlockState")); this.timeFlying = tag.getInt("Time"); if(tag.contains("HurtEntities", 99)) { this.hurtEntities = tag.getBoolean("HurtEntities"); @@ -277,7 +271,7 @@ else if(this.state.isIn(BlockTags.ANVIL)) { @Environment(EnvType.CLIENT) public World getWorldClient() { - return this.world; + return this.getWorld(); } public void setHurtEntities(boolean hurtEntitiesIn) { diff --git a/src/main/java/fr/hugman/dawn/entity/ai/goal/AnimalTemptGoal.java b/src/main/java/fr/hugman/dawn/entity/ai/goal/AnimalTemptGoal.java index a3c6c46..543622a 100644 --- a/src/main/java/fr/hugman/dawn/entity/ai/goal/AnimalTemptGoal.java +++ b/src/main/java/fr/hugman/dawn/entity/ai/goal/AnimalTemptGoal.java @@ -39,7 +39,7 @@ public boolean canStart() { return false; } else { - this.closestPlayer = this.entity.world.getClosestPlayer(this.predicate, this.entity); + this.closestPlayer = this.entity.getWorld().getClosestPlayer(this.predicate, this.entity); return this.closestPlayer != null; } } diff --git a/src/main/java/fr/hugman/dawn/item/ItemGroupHelper.java b/src/main/java/fr/hugman/dawn/item/ItemGroupHelper.java index 5dfbba9..522d5f5 100644 --- a/src/main/java/fr/hugman/dawn/item/ItemGroupHelper.java +++ b/src/main/java/fr/hugman/dawn/item/ItemGroupHelper.java @@ -6,21 +6,27 @@ import net.minecraft.item.ItemGroups; import net.minecraft.item.ItemStack; import net.minecraft.registry.Registries; +import net.minecraft.registry.RegistryKey; import java.util.Collections; import java.util.function.Predicate; public final class ItemGroupHelper { - public static void append(ItemGroup group, ItemGroupEvents.ModifyEntries modifier) { + public static void append(RegistryKey group, ItemGroupEvents.ModifyEntries modifier) { ItemGroupEvents.modifyEntriesEvent(group).register(modifier); } public static void appendSpawnEgg(Item spawnEgg) { + var itemGroup = Registries.ITEM_GROUP.get(ItemGroups.SPAWN_EGGS); String path = Registries.ITEM.getId(spawnEgg).getPath(); + if(itemGroup == null) { + return; + } + Predicate predicate = stack1 -> { String path1 = Registries.ITEM.getId(stack1.getItem()).getPath(); - for(ItemStack stack2 : ItemGroups.SPAWN_EGGS.getDisplayStacks()) { + for(ItemStack stack2 : itemGroup.getDisplayStacks()) { String path2 = Registries.ITEM.getId(stack2.getItem()).getPath(); if(path1.matches(".*_spawn_egg") && path2.matches(".*_spawn_egg")) { // check if path is lexicographically between path1 and path2 diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index b71945b..d5e13cb 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -1,62 +1,74 @@ { - "schemaVersion": 1, - "name": "${mod_name}", - "id": "${mod_id}", - "version": "${version}", - "icon": "assets/${mod_id}/textures/logo.png", - "authors": [ - "Hugman" - ], - "contributors": [ - "YanisBft" - ], - "contact": { - "homepage": "https://dawnteammc.github.io/", - "sources": "https://github.com/DawnTeamMC/${github_name}", - "issues": "https://github.com/DawnTeamMC/${github_name}/issues" - }, - "environment": "*", - "entrypoints": { - "main": [ - "fr.hugman.dawn.Dawn" - ], - "client": [ - "fr.hugman.dawn.DawnClient" - ], - "appleskin" : [ - "fr.hugman.dawn.compat.DawnASCompat" - ] - }, - "mixins": [ - "dawn.mixins.json" - ], - "accessWidener": "dawn.accesswidener", - "depends": { - "fabric": "*" - }, - "suggests": { - "appleskin": "*", - "modmenu": "*" - }, - "custom": { - "modmenu": { - "links": { - "modmenu.twitter": "https://twitter.com/DawnTeamMC", - "modmenu.discord": "https://discord.gg/8ksTVJu", - "modmenu.curseforge": "https://www.curseforge.com/minecraft/mc-mods/${curseforge_slug}", - "modmenu.modrinth": "https://modrinth.com/mod/${modrinth_slug}", - "modmenu.github_releases": "https://github.com/DawnTeamMC/${github_name}/releases/", - "modmenu.crowdin": "https://crowdin.com/project/dawnteam", - "modmenu.wiki": "https://github.com/DawnTeamMC/${github_name}/wiki/" - }, - "badges": [ - "library" - ] - }, - "modupdater": { - "strategy": "curseforge", - "projectID": 399309 - } - }, - "license": "LGPL v3.0" + "schemaVersion": 1, + "name": "Dawn API", + "id": "dawn", + "version": "${version}", + "icon": "assets/dawn/textures/logo.png", + "authors": [ + "Hugman" + ], + "contributors": [ + "YanisBft" + ], + "contact": { + "homepage": "https://dawnteammc.github.io/", + "sources": "https://github.com/DawnTeamMC/DawnAPI", + "issues": "https://github.com/DawnTeamMC/DawnAPI/issues" + }, + "environment": "*", + "entrypoints": { + "main": [ + "fr.hugman.dawn.Dawn" + ], + "client": [ + "fr.hugman.dawn.DawnClient" + ], + "appleskin": [ + "fr.hugman.dawn.compat.DawnASCompat" + ] + }, + "mixins": [ + "dawn.mixins.json" + ], + "accessWidener": "dawn.accesswidener", + "depends": { + "minecraft": "1.20.x", + "fabric-api": "*" + }, + "suggests": { + "appleskin": "*", + "modmenu": "*" + }, + "custom": { + "modmenu": { + "links": { + "modmenu.twitter": "https://twitter.com/DawnTeamMC", + "modmenu.discord": "https://discord.gg/8ksTVJu", + "modmenu.curseforge": "https://www.curseforge.com/minecraft/mc-mods/dawn", + "modmenu.modrinth": "https://modrinth.com/mod/dawn", + "modmenu.github_releases": "https://github.com/DawnTeamMC/DawnAPI/releases/", + "modmenu.crowdin": "https://crowdin.com/project/dawnteam", + "modmenu.wiki": "https://github.com/DawnTeamMC/DawnAPI/wiki/" + }, + "badges": [ + "library" + ] + }, + "modupdater": { + "strategy": "curseforge", + "projectID": 399309 + }, + "mc-publish": { + "curseforge": 399309, + "modrinth": "meZK2DCX", + "loaders": [ + "fabric", + "quilt" + ], + "dependencies": [ + "cloth-config(embedded)" + ] + } + }, + "license": "LGPL v3.0" }