diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 713bbe4..80c3d53 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,16 +1,16 @@ -name: Steam Advantage 1.13 CI +name: Steam Advantage 1.14 CI on: push: - branches: [master-1.13.2, 'feature/**'] + branches: [master-1.14.4, 'feature/**'] pull_request: - branches: [master-1.13.2] + branches: [master-1.14.4] permissions: contents: read concurrency: - group: steamadvantage-1.13-${{ github.workflow }}-${{ github.ref }} + group: steamadvantage-1.14-${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: @@ -25,22 +25,22 @@ jobs: uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 with: repository: MinecraftModDevelopmentMods/OreSpawn - ref: 6a7c2bb07b9a7771128812fcc07d185f7d9df58b + ref: 9c2488cba02d317e3f31e24441dcc58273d8d0e6 path: .ci-dependencies/OreSpawn - name: Use canonical LF dependency inputs - # Base Metals predates archive text normalization; its LF artifact is separately pinned. + # Use the same source bytes on hosted and local dependency builds. run: git config --global core.autocrlf false - name: Check out pinned Base Metals uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 with: repository: MinecraftModDevelopmentMods/BaseMetals - ref: 1376a20d7d5ba22d3abc77dc34b49a2c88943697 + ref: 713802f93f2d1f650e1593fa35c487ea43add4a5 path: .ci-dependencies/BaseMetals - - name: Check out PowerAdvantage 1.13.2 + - name: Check out PowerAdvantage 1.14.4 uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 with: repository: MinecraftModDevelopmentMods/PowerAdvantage - ref: 6a845ad68eb1e34dcdd793dceb9cb528be22cedf + ref: 1d498ca02b6795b16435f0ece35ac04c67ef6948 path: .ci-dependencies/PowerAdvantage - name: Install Java 8 toolchain uses: actions/setup-java@b6effb05e454b25005698d916606bdc6ffcbf961 # v5 @@ -54,7 +54,7 @@ jobs: java-version: '17' - name: Set up Gradle uses: gradle/actions/setup-gradle@9c971963bec38e04b3d30dcc455b5382be2fdbfb # v6 - - name: Build 1.13.2 dependency chain + - name: Build 1.14.4 dependency chain id: dependencies shell: bash run: | @@ -65,10 +65,12 @@ jobs: chmod +x "$orespawn/gradlew" "$basemetals/gradlew" "$power/gradlew" (cd "$orespawn" && ./gradlew jar --no-daemon --stacktrace) (cd "$basemetals" && ./gradlew jar --no-daemon --stacktrace) - osjar="$orespawn/build/libs-dev/OreSpawn-4.1.0.113021-deobf.jar" - bmjar="$basemetals/build/libs-dev/BaseMetals-3.0.1.113021-deobf.jar" - (cd "$power" && ./gradlew jar verifyReleaseDependencies -PbaseMetalsDeobfJar="$bmjar" -PoreSpawnDeobfJar="$osjar" --no-daemon --stacktrace) - powerjar="$power/build/libs-dev/PowerAdvantage-2.4.4.113021-deobf.jar" + osjar="$orespawn/build/libs-dev/OreSpawn-4.1.1.114041-deobf.jar" + bmjar="$basemetals/build/libs-dev/BaseMetals-3.0.1.114041-deobf.jar" + (cd "$power" && ./gradlew jar verifyReleaseDependencies \ + -PbaseMetalsDeobfJar="$bmjar" -PoreSpawnDeobfJar="$osjar" \ + --no-daemon --stacktrace) + powerjar="$power/build/libs-dev/PowerAdvantage-2.4.5.114041-deobf.jar" test -f "$osjar" && test -f "$bmjar" && test -f "$powerjar" echo "orespawn=$osjar" >> "$GITHUB_OUTPUT" echo "basemetals=$bmjar" >> "$GITHUB_OUTPUT" @@ -86,20 +88,20 @@ jobs: - name: Upload audited release candidate uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7 with: - name: SteamAdvantage-1.13.2-${{ github.sha }} + name: SteamAdvantage-1.14.4-${{ github.sha }} if-no-files-found: error retention-days: 30 path: | - build/libs/SteamAdvantage-2.2.5.113021.jar - build/libs/SteamAdvantage-2.2.5.113021-sources.jar - build/libs/SteamAdvantage-2.2.5.113021-javadoc.jar + build/libs/SteamAdvantage-2.2.6.114041.jar + build/libs/SteamAdvantage-2.2.6.114041-sources.jar + build/libs/SteamAdvantage-2.2.6.114041-javadoc.jar build/release/SHA256SUMS CHANGELOG.txt - name: Upload diagnostics on failure if: failure() uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7 with: - name: SteamAdvantage-1.13.2-diagnostics-${{ github.sha }} + name: SteamAdvantage-1.14.4-diagnostics-${{ github.sha }} if-no-files-found: ignore retention-days: 14 path: | diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 9d4462c..9bf204f 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -2,9 +2,9 @@ name: CodeQL on: push: - branches: [master-1.13.2, 'feature/**'] + branches: [master-1.14.4, 'feature/**'] pull_request: - branches: [master-1.13.2] + branches: [master-1.14.4] schedule: - cron: '53 7 * * 4' @@ -25,22 +25,22 @@ jobs: uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 with: repository: MinecraftModDevelopmentMods/OreSpawn - ref: 6a7c2bb07b9a7771128812fcc07d185f7d9df58b + ref: 9c2488cba02d317e3f31e24441dcc58273d8d0e6 path: .ci-dependencies/OreSpawn - name: Use canonical LF dependency inputs - # Base Metals predates archive text normalization; its LF artifact is separately pinned. + # Use the same source bytes on hosted and local dependency builds. run: git config --global core.autocrlf false - name: Check out pinned Base Metals uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 with: repository: MinecraftModDevelopmentMods/BaseMetals - ref: 1376a20d7d5ba22d3abc77dc34b49a2c88943697 + ref: 713802f93f2d1f650e1593fa35c487ea43add4a5 path: .ci-dependencies/BaseMetals - - name: Check out PowerAdvantage 1.13.2 + - name: Check out PowerAdvantage 1.14.4 uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 with: repository: MinecraftModDevelopmentMods/PowerAdvantage - ref: 6a845ad68eb1e34dcdd793dceb9cb528be22cedf + ref: 1d498ca02b6795b16435f0ece35ac04c67ef6948 path: .ci-dependencies/PowerAdvantage - name: Install Java 8 toolchain uses: actions/setup-java@b6effb05e454b25005698d916606bdc6ffcbf961 # v5 @@ -54,7 +54,7 @@ jobs: java-version: '17' - name: Set up Gradle uses: gradle/actions/setup-gradle@9c971963bec38e04b3d30dcc455b5382be2fdbfb # v6 - - name: Build 1.13.2 dependency chain + - name: Build 1.14.4 dependency chain id: dependencies shell: bash run: | @@ -65,10 +65,12 @@ jobs: chmod +x "$orespawn/gradlew" "$basemetals/gradlew" "$power/gradlew" (cd "$orespawn" && ./gradlew jar --no-daemon --stacktrace) (cd "$basemetals" && ./gradlew jar --no-daemon --stacktrace) - osjar="$orespawn/build/libs-dev/OreSpawn-4.1.0.113021-deobf.jar" - bmjar="$basemetals/build/libs-dev/BaseMetals-3.0.1.113021-deobf.jar" - (cd "$power" && ./gradlew jar verifyReleaseDependencies -PbaseMetalsDeobfJar="$bmjar" -PoreSpawnDeobfJar="$osjar" --no-daemon --stacktrace) - powerjar="$power/build/libs-dev/PowerAdvantage-2.4.4.113021-deobf.jar" + osjar="$orespawn/build/libs-dev/OreSpawn-4.1.1.114041-deobf.jar" + bmjar="$basemetals/build/libs-dev/BaseMetals-3.0.1.114041-deobf.jar" + (cd "$power" && ./gradlew jar verifyReleaseDependencies \ + -PbaseMetalsDeobfJar="$bmjar" -PoreSpawnDeobfJar="$osjar" \ + --no-daemon --stacktrace) + powerjar="$power/build/libs-dev/PowerAdvantage-2.4.5.114041-deobf.jar" test -f "$osjar" && test -f "$bmjar" && test -f "$powerjar" echo "orespawn=$osjar" >> "$GITHUB_OUTPUT" echo "basemetals=$bmjar" >> "$GITHUB_OUTPUT" diff --git a/.github/workflows/validate-gradle-build.yml b/.github/workflows/validate-gradle-build.yml index d4d55ba..c471b09 100644 --- a/.github/workflows/validate-gradle-build.yml +++ b/.github/workflows/validate-gradle-build.yml @@ -3,11 +3,11 @@ name: Validate Gradle Wrapper on: push: branches: - - master-1.13.2 + - master-1.14.4 - 'feature/**' pull_request: branches: - - master-1.13.2 + - master-1.14.4 permissions: contents: read diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 237ce55..20b90ac 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,3 +1,16 @@ +Steam Advantage 2.2.6.114041 + +- Save the drill's cached facing without reloading a chunk during its unload-save. +- Target Minecraft 1.14.4 / Forge 28.2.26 with snapshot 20190719-1.14.3 mappings and MCP 20190829.143755. +- Adapt native block callbacks, tile validity, loot, recipe conditions, furnace recipes, musket hits and enchantments. +- Keep native machine containers and client rendering on Power Advantage's shared API. +- Detach drill helpers before line-removal callbacks; defer saved target loot restoration until server world attachment. +- Preserve existing registry identities, NBT keys, recipes, machine costs, output quantities and migration codecs. +- Replace removed villager careers with native profession trade events at the same levels and price ranges. +- Add native block self-drop tables and focused direction, progress, inventory, energy, musket and resource tests. +- Pass 27 unit/resource tests and combined-mod automated machine, migration, lifecycle and restart checks. +- Keep coverage limited to the recorded scenarios; back up whole worlds and test upgrades on disposable copies. + Steam Advantage 2.2.5.113021 - Keep development archives identical in existing workspaces and fresh CI checkouts. diff --git a/README.md b/README.md index 1d6190c..095f45d 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,27 @@ # SteamAdvantage -Steam Advantage adds steam-powered machines and infrastructure to Power Advantage for Minecraft 1.13.2. +**Minecraft 1.14.4 port, version 2.2.6.114041.** Native compilation and 27 unit/resource tests pass. +The combined-mod automated checks also cover client resources, connected machinery, +drill movement, chunk lifecycle, restart persistence and disposable-copy migration. +The [1.14 test results](https://github.com/MinecraftModDevelopmentMods/PowerAdvantage/blob/master-1.14.4/docs/1.14/BROADER-QUALIFICATION.md) +describe the tested scenarios and remaining limits, not a guarantee for an entire modpack. + +Steam Advantage adds steam-powered machines and infrastructure to Power Advantage for Minecraft 1.14.4. Every crafting variant has an ingredient-triggered recipe-book discovery. See the [shared material checklist and discovery tests](https://github.com/MinecraftModDevelopmentMods/PowerAdvantage/blob/master-1.13.2/docs/1.13/RECIPE-DISCOVERY.md). Regenerate unlock JSON after recipe changes with `node tools/generate-recipe-unlocks.js`; `check` audits recipe coverage and criteria. Crushing recipes are deliberately excluded from the crafting book. -The [manufacturing progression audit](https://github.com/MinecraftModDevelopmentMods/PowerAdvantage/blob/master-1.13.2/docs/1.13/MANUFACTURING-PROGRESSION.md) checks raw-material, processing and loot acquisition paths in every mode, including restart persistence. +The historical [manufacturing progression protocol](https://github.com/MinecraftModDevelopmentMods/PowerAdvantage/blob/master-1.13.2/docs/1.13/MANUFACTURING-PROGRESSION.md) describes raw-material, processing and loot acquisition paths in every mode, including restart persistence. See the 1.14 test results above for this port's coverage. -## Building Minecraft 1.13.2 +## Building Minecraft 1.14.4 -The `master-1.13.2` build uses ForgeGradle 7.0.34 and Gradle 9.6.1. Run Gradle with Java 17; production code is compiled for Java 8. +The `master-1.14.4` build targets Forge 28.2.26, snapshot `20190719-1.14.3` mappings, +and MCP `20190829.143755`. It uses ForgeGradle 7.0.34 and Gradle 9.6.1. +Run Gradle with Java 17; production code is compiled for Java 8. -Build the pinned PowerAdvantage, Base Metals, and OreSpawn deobf jars first. -Exact source commits and checksums are recorded in `gradle.properties`; CI builds the same commits. +Build the matching 1.14 PowerAdvantage, Base Metals and OreSpawn deobf jars first. +Dependency versions, checksums and the exact Power source reference belong in +`gradle.properties`. Release audits reject missing or placeholder pins; do not +bypass those checks or substitute a 1.13 dependency. With the standard sibling layout: ```text @@ -19,7 +29,13 @@ cd ..\..\PowerAdvantage gradlew.bat deobfJar ``` -Then build SteamAdvantage: +For local development, compile and run tests in SteamAdvantage: + +```text +gradlew.bat compileJava test +``` + +With the exact Power dependency pinned, run the complete release gates: ```text gradlew.bat clean check build javadoc verifyReleaseDependencies verifyReleaseArtifacts writeReleaseChecksums verifyEclipseProductionClasspath @@ -39,8 +55,20 @@ The Eclipse resource root is `build/resources/main`, so its builder copies expan ## Compatibility -For an all-Advantage play-test, run `prepareCombinedEclipseLaunch` in the sibling PowerAdvantage checkout and select its `runClientAllAdvantage.launch`. The [native resource probe](https://github.com/MinecraftModDevelopmentMods/PowerAdvantage/blob/master-1.13.2/test-rig/client-resources/README.md) checks models, textures and names across all three mods. These resource checks do not replace gameplay testing. +The 1.14 source adaptations preserve machine callbacks, all six drill directions, native +helper-tile lifecycle, saved progress and target snapshots, energy/inventory NBT, legacy +fluid contracts, musket loaded-state bytes and migration codecs. Native villager professions +replace the removed smith careers (armorer, weaponsmith, toolsmith) and priest (cleric). +Trades retain their legacy level and price ranges; 1.14 restocking and profession selection +follow the native engine. + +Automated coverage is bounded to the recorded scenarios. It does not establish every +in-world GUI, rendering, sound, control or musket interaction, multiplayer behavior, +or compatibility with arbitrary third-party mods. Unit/resource tests alone are not +runtime or world-upgrade evidence. + +For an all-Advantage play-test, run `prepareCombinedEclipseLaunch` in the sibling PowerAdvantage checkout and select its `runClientAllAdvantage.launch`. The [native resource probe](https://github.com/MinecraftModDevelopmentMods/PowerAdvantage/blob/master-1.14.4/test-rig/client-resources/README.md) checks models, textures and names across all three mods. These resource checks do not replace gameplay testing. The implementation namespace is `zone.moddev.mc.steamadvantage`. Runtime identities, registries, tile IDs, saved NBT, recipes, and assets remain stable. Steam registers its legacy state and NBT codecs with PowerAdvantage's shared migration hook so 1.10 and 1.12 worlds can be converted before Minecraft flattens old numeric block states. -Read PowerAdvantage's [1.13 migration guide](https://github.com/MinecraftModDevelopmentMods/PowerAdvantage/blob/master-1.13.2/docs/1.13/MIGRATION.md) before upgrading, and always use a backup. The [qualification notes](https://github.com/MinecraftModDevelopmentMods/PowerAdvantage/blob/master-1.13.2/docs/1.13/CURRENT-QUALIFICATION.md) list the tested scenarios and remaining gaps. +The historical [1.13 migration guide](https://github.com/MinecraftModDevelopmentMods/PowerAdvantage/blob/master-1.13.2/docs/1.13/MIGRATION.md) explains the legacy conversion and backup process; the 1.14 test results above describe this port's coverage. Always make a whole-world backup before upgrading, keep the complete set of migration backups, and test only disposable copies. Check that every other mod supports the target version; these results do not qualify unrelated mods or an entire existing modpack. diff --git a/build.gradle b/build.gradle index 8e78218..23326f7 100644 --- a/build.gradle +++ b/build.gradle @@ -70,9 +70,9 @@ tasks.withType(Javadoc).configureEach { } tasks.withType(AbstractArchiveTask).configureEach { - includeEmptyDirs = false preserveFileTimestamps = false reproducibleFileOrder = true + includeEmptyDirs = false } def archiveTextSuffixes = [ @@ -94,7 +94,7 @@ minecraft { def forgeRunModClassesDirectory = layout.buildDirectory.dir('forge-run-mod-classes/main') def forgeMainOutputPath = forgeRunModClassesDirectory.get().asFile.absolutePath def mainModClasses = "${mod_id}%%${forgeMainOutputPath}${File.pathSeparator}${mod_id}%%${forgeMainOutputPath}" - def forge25RunTargets = [client: 'fmluserdevclient', server: 'fmluserdevserver', data: 'fmluserdevdata'] + def forge28RunTargets = [client: 'fmluserdevclient', server: 'fmluserdevserver', data: 'fmluserdevdata'] runs { configureEach { mainClass = 'net.minecraftforge.userdev.LaunchTesting' @@ -102,7 +102,7 @@ minecraft { systemProperty 'forge.logging.markers', 'REGISTRIES' systemProperty 'forge.logging.console.level', 'info' mods { steamadvantage { source sourceSets.main } } - environment 'target', forge25RunTargets[name] + environment 'target', forge28RunTargets[name] environment 'MCP_MAPPINGS', "${mapping_channel}_${mapping_version}" environment 'MCP_VERSION', mcp_version environment 'FORGE_VERSION', forge_version @@ -130,7 +130,7 @@ sourceSets.main.resources { def forgeRunModClassesDirectory = layout.buildDirectory.dir('forge-run-mod-classes/main') def prepareForgeRunModClasses = tasks.register('prepareForgeRunModClasses', Sync) { group = 'ide' - description = 'Merges classes and processed resources for Forge 1.13 launches.' + description = 'Merges classes and processed resources for Forge 1.14 launches.' dependsOn tasks.named('classes') from sourceSets.main.output into forgeRunModClassesDirectory @@ -178,18 +178,18 @@ if (!powerAdvantageDeobfJar.isFile()) { // These defaults follow the sibling MMD checkout layout. They are constants // here so another developer can override them without editing the script. def baseMetalsDeobfJar = file(providers.gradleProperty('baseMetalsDeobfJar') - .getOrElse('../../../../BaseMetals/BaseMetals 113/BaseMetals/build/libs-dev/' - + 'BaseMetals-3.0.1.113021-deobf.jar')) + .getOrElse('../../../../BaseMetals/BaseMetals 114/BaseMetals/build/libs-dev/' + + 'BaseMetals-3.0.1.114041-deobf.jar')) if (!baseMetalsDeobfJar.isFile()) { throw new GradleException("Missing Base Metals deobf jar at ${baseMetalsDeobfJar}. " - + "Build Base Metals 1.13 first, or pass -PbaseMetalsDeobfJar=.") + + "Build Base Metals 1.14 first, or pass -PbaseMetalsDeobfJar=.") } def oreSpawnDeobfJar = file(providers.gradleProperty('oreSpawnDeobfJar') - .getOrElse('../../../../MinecraftMineralogy/OS113/OreSpawn/build/libs-dev/' - + 'OreSpawn-4.1.0.113021-deobf.jar')) + .getOrElse('../../../../MinecraftMineralogy/OS114/OreSpawn/build/libs-dev/' + + 'OreSpawn-4.1.1.114041-deobf.jar')) if (!oreSpawnDeobfJar.isFile()) { throw new GradleException("Missing OreSpawn deobf jar at ${oreSpawnDeobfJar}. " - + "Build OreSpawn 1.13 first, or pass -PoreSpawnDeobfJar=.") + + "Build OreSpawn 1.14 first, or pass -PoreSpawnDeobfJar=.") } dependencies { @@ -341,13 +341,14 @@ tasks.register('verifyReleaseConfiguration') { group = 'verification' description = 'Validates release identity, target metadata, and dependency policy.' doLast { - if (project.mod_version != '2.2.5.113021') { + if (project.mod_version != '2.2.6.114041') { throw new GradleException("Unexpected SteamAdvantage release version: ${project.mod_version}") } - if (project.minecraft_version != '1.13.2' - || project.forge_version != '25.0.223' + if (project.minecraft_version != '1.14.4' + || project.forge_version != '28.2.26' || project.mapping_channel != 'snapshot' - || project.mapping_version != '20180921-1.13') { + || project.mapping_version != '20190719-1.14.3' + || project.mcp_version != '20190829.143755') { throw new GradleException('Unexpected Minecraft, Forge, or mappings target') } if (project.loader_name != 'forge' || project.loader_code != '1' @@ -365,10 +366,10 @@ tasks.register('verifyReleaseConfiguration') { } if (project.cf_requirements != 'power-advantage,base-metals' || project.cf_optionals != '' - || project.cf_versions != '1.13.2') { + || project.cf_versions != '1.14.4') { throw new GradleException('Unexpected CurseForge dependency or game-version metadata') } - if (project.poweradvantage_version != '2.4.4.113021' + if (project.poweradvantage_version != '2.4.5.114041' || project.poweradvantage_source_repository != 'MinecraftModDevelopmentMods/PowerAdvantage' || !(project.poweradvantage_source_ref ==~ /[a-f0-9]{40}/) || !(project.poweradvantage_deobf_sha256 ==~ /[A-F0-9]{64}/)) { @@ -377,12 +378,12 @@ tasks.register('verifyReleaseConfiguration') { String mainSource = file( 'src/main/java/zone/moddev/mc/steamadvantage/SteamAdvantage.java').getText('UTF-8') if (!mainSource.contains('MODID = "steamadvantage"') - || !mainSource.contains('VERSION = "2.2.5.113021"')) { + || !mainSource.contains('VERSION = "2.2.6.114041"')) { throw new GradleException('SteamAdvantage source identity changed') } String metadata = file('src/main/resources/META-INF/mods.toml').getText('UTF-8').replace('\r\n', '\n') ['modId="steamadvantage"', 'modId="poweradvantage"', 'modId="basemetals"', - 'versionRange="[2.4.4.113021,3.0.0)"'].each { marker -> + 'versionRange="[2.4.5.114041,3.0.0)"'].each { marker -> if (!metadata.contains(marker)) { throw new GradleException("Source mods.toml is missing ${marker}") } @@ -418,11 +419,14 @@ tasks.register('verifyReleaseDependencies') { if (manifest.getValue('Implementation-Version') != project.poweradvantage_version) { throw new GradleException('PowerAdvantage dependency manifest has the wrong version') } + if (manifest.getValue('Built-On') != '1.14.4-28.2.26' + || manifest.getValue('Built-On-Java') != '8') { + throw new GradleException('PowerAdvantage must be the native 1.14.4 Java 8 dependency') + } } String actualBaseMetalsHash = MessageDigest.getInstance('SHA-256') .digest(baseMetalsDeobfJar.bytes).encodeHex().toString().toUpperCase() - if (!(actualBaseMetalsHash in [project.basemetals_deobf_sha256, - project.basemetals_deobf_lf_sha256])) { + if (actualBaseMetalsHash != project.basemetals_deobf_sha256) { throw new GradleException("Base Metals SHA-256 is ${actualBaseMetalsHash}, expected " + project.basemetals_deobf_sha256) } @@ -508,6 +512,19 @@ tasks.register('verifyReleaseArtifacts') { throw new GradleException("Release jar is missing ${required}") } } + ['steam_pipe', 'steam_track', 'steam_boiler_coal', 'steam_boiler_electric', + 'steam_boiler_geothermal', 'steam_tank', 'steam_furnace', 'steam_crusher', + 'steam_drill', 'steam_elevator', 'steam_switch', 'steam_still', 'steam_pump', + 'steam_boiler_oil'].each { id -> + if (!names.contains("data/steamadvantage/loot_tables/blocks/${id}.json".toString())) { + throw new GradleException("Release jar is missing native block loot for ${id}") + } + } + def resourcePack = new JsonSlurper().parseText(zip.getInputStream(zip.getEntry('pack.mcmeta')) + .getText(StandardCharsets.UTF_8.name())) + if (resourcePack.pack.pack_format != 4) { + throw new GradleException('Packaged resources must use native 1.14 pack format 4') + } ['agent-notes/', '.codex/', 'src/test/', 'fernflower_abstract_parameter_names.txt', 'cyano/poweradvantage/', 'zone/moddev/mc/poweradvantage/', 'zone/moddev/mc/basemetals/', 'cyano/basemetals/', 'com/mcmoddev/lib/', diff --git a/gradle.properties b/gradle.properties index 6299d10..fd46c88 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,14 +5,14 @@ org.gradle.caching=true org.gradle.parallel=false net.minecraftforge.gradle.merge-source-sets=false -minecraft_version=1.13.2 -minecraft_version_range=[1.13.2] -forge_version=25.0.223 -forge_version_range=[25,) -loader_version_range=[25,) +minecraft_version=1.14.4 +minecraft_version_range=[1.14.4] +forge_version=28.2.26 +forge_version_range=[28,) +loader_version_range=[28,) mapping_channel=snapshot -mapping_version=20180921-1.13 -mcp_version=20190213.203750 +mapping_version=20190719-1.14.3 +mcp_version=20190829.143755 loader_name=forge loader_code=1 @@ -25,24 +25,23 @@ curseforge_project_id=240984 mod_id=steamadvantage mod_name=Steam Advantage mod_license=GPL-3.0-only -mod_version=2.2.5.113021 +mod_version=2.2.6.114041 mod_group=zone.moddev.mc.steamadvantage mod_authors=DrCyano mod_description=Steam-powered machines and infrastructure for the Power Advantage platform. cf_requirements=power-advantage,base-metals cf_optionals= -cf_versions=1.13.2 +cf_versions=1.14.4 -poweradvantage_version=2.4.4.113021 +poweradvantage_version=2.4.5.114041 poweradvantage_source_repository=MinecraftModDevelopmentMods/PowerAdvantage -poweradvantage_source_ref=6a845ad68eb1e34dcdd793dceb9cb528be22cedf -poweradvantage_deobf_sha256=160F29590913A2DA0637E710458DC8AEF8D4CC3883EA3B0E2E258C70240BDE02 +# Exact Power Advantage source and development jar used by local and CI builds. +poweradvantage_source_ref=1d498ca02b6795b16435f0ece35ac04c67ef6948 +poweradvantage_deobf_sha256=8D8831D54B700FBFB2B9C43EE3D8D70D2B7E57185A4DBDF12202C47D5E387B39 -basemetals_version=3.0.1.113021 -basemetals_deobf_sha256=2E4B0F619AD6B516A341DD332FABB66FE882A9DBA8E5C74F5BB52942302CFD18 -# Same pinned source and class bytes, with a clean LF checkout on Linux. -basemetals_deobf_lf_sha256=D1843CFAB23E7DB4B8A64ADB280D7EA51E3909B8E3490D4F5D471F0C94E1D0BF +basemetals_version=3.0.1.114041 +basemetals_deobf_sha256=A14A87E3BF30964F901E715A9B4EF2F1E7317ABE7F9ACEBE60D8E6A900CA6EB2 -orespawn_version=4.1.0.113021 -orespawn_deobf_sha256=F5A015584000CCEF0E94D8BB567E7B75603B37F10A88BFC5A129176D487BB038 +orespawn_version=4.1.1.114041 +orespawn_deobf_sha256=1807C3A43F6E854F4EC5741F75A52750B733CD81DC588CF0F666C6C3A489FBEF diff --git a/src/main/java/zone/moddev/mc/steamadvantage/SteamAdvantage.java b/src/main/java/zone/moddev/mc/steamadvantage/SteamAdvantage.java index a672ba9..c2aad97 100644 --- a/src/main/java/zone/moddev/mc/steamadvantage/SteamAdvantage.java +++ b/src/main/java/zone/moddev/mc/steamadvantage/SteamAdvantage.java @@ -30,12 +30,12 @@ import zone.moddev.mc.steamadvantage.migration.SteamLegacyMigrations; import zone.moddev.mc.steamadvantage.recipe.RecipeConditions; -/** Forge 1.13 entry point for Steam Advantage. */ +/** Forge 1.14 entry point for Steam Advantage. */ @Mod(SteamAdvantage.MODID) public final class SteamAdvantage { public static final String MODID = "steamadvantage"; public static final String NAME = "Steam Advantage"; - public static final String VERSION = "2.2.5.113021"; + public static final String VERSION = "2.2.6.114041"; public static final Logger LOGGER = LogManager.getLogger(MODID); public static float MUSKET_DAMAGE = 20.0F; diff --git a/src/main/java/zone/moddev/mc/steamadvantage/blocks/DrillBitBlock.java b/src/main/java/zone/moddev/mc/steamadvantage/blocks/DrillBitBlock.java index df8f4d0..03558dd 100644 --- a/src/main/java/zone/moddev/mc/steamadvantage/blocks/DrillBitBlock.java +++ b/src/main/java/zone/moddev/mc/steamadvantage/blocks/DrillBitBlock.java @@ -3,14 +3,17 @@ import net.minecraft.block.Block; import net.minecraft.block.ITileEntityProvider; import net.minecraft.block.material.Material; -import net.minecraft.block.state.IBlockState; +import net.minecraft.block.BlockState; import net.minecraft.entity.Entity; import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.NonNullList; +import net.minecraft.util.Direction; +import java.util.Collections; +import java.util.List; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.util.math.shapes.VoxelShapes; +import net.minecraft.util.math.shapes.ISelectionContext; +import net.minecraft.world.storage.loot.LootContext; import net.minecraft.world.Explosion; import net.minecraft.world.IBlockReader; import net.minecraft.world.World; @@ -26,20 +29,25 @@ public DrillBitBlock() { } @Override public TileEntity createNewTileEntity(IBlockReader world) { return new DrillBitTileEntity(); } - @Override public VoxelShape getShape(IBlockState state, IBlockReader world, BlockPos pos) { return SHAPE; } - @Override public VoxelShape getCollisionShape(IBlockState state, IBlockReader world, BlockPos pos) { return SHAPE; } - @Override public boolean isNormalCube(IBlockState state) { return false; } - @Override public boolean isSolid(IBlockState state) { return false; } - @Override public void getDrops(IBlockState state, NonNullList drops, World world, BlockPos pos, int fortune) {} + @Override public VoxelShape getShape(BlockState state, IBlockReader world, BlockPos pos, ISelectionContext context) { return SHAPE; } + @Override public VoxelShape getCollisionShape(BlockState state, IBlockReader world, BlockPos pos, ISelectionContext context) { return SHAPE; } + @Override public boolean isNormalCube(BlockState state, IBlockReader world, BlockPos pos) { return false; } + @Override public boolean isSolid(BlockState state) { return false; } + @Override public List getDrops(BlockState state, LootContext.Builder context) { return Collections.emptyList(); } @Override - public void onEntityCollision(IBlockState state, World world, BlockPos pos, Entity victim) { + public void onEntityCollision(BlockState state, World world, BlockPos pos, Entity victim) { victim.attackEntityFrom(Power.machine_damage, 2.0F); } @Override - public void onReplaced(IBlockState state, World world, BlockPos pos, IBlockState newState, boolean moving) { - if (state.getBlock() != newState.getBlock()) destroyNeighbors(world, pos); + public void onReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moving) { + if (state.getBlock() != newState.getBlock()) { + TileEntity tile = world.getTileEntity(pos); + if (!world.isRemote && tile instanceof DrillBitTileEntity) { + ((DrillBitTileEntity) tile).destroyLine(false); + } + } super.onReplaced(state, world, pos, newState, moving); } @@ -51,7 +59,7 @@ public void onExplosionDestroy(World world, BlockPos pos, Explosion explosion) { private void destroyNeighbors(World world, BlockPos pos) { if (world.isRemote) return; - for (EnumFacing side : EnumFacing.values()) { + for (Direction side : Direction.values()) { TileEntity tile = world.getTileEntity(pos.offset(side)); if (tile instanceof DrillBitTileEntity) ((DrillBitTileEntity) tile).destroyLine(); } diff --git a/src/main/java/zone/moddev/mc/steamadvantage/blocks/DrillBitTileEntity.java b/src/main/java/zone/moddev/mc/steamadvantage/blocks/DrillBitTileEntity.java index 1430ad4..9e8f89b 100644 --- a/src/main/java/zone/moddev/mc/steamadvantage/blocks/DrillBitTileEntity.java +++ b/src/main/java/zone/moddev/mc/steamadvantage/blocks/DrillBitTileEntity.java @@ -1,21 +1,23 @@ package zone.moddev.mc.steamadvantage.blocks; import zone.moddev.mc.steamadvantage.init.Blocks; -import net.minecraft.block.state.IBlockState; -import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.block.BlockState; +import net.minecraft.nbt.CompoundNBT; import net.minecraft.network.NetworkManager; -import net.minecraft.network.play.server.SPacketUpdateTileEntity; +import net.minecraft.network.play.server.SUpdateTileEntityPacket; import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.ITickable; +import net.minecraft.util.Direction; +import net.minecraft.tileentity.ITickableTileEntity; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; +import java.util.ArrayList; +import java.util.List; -public class DrillBitTileEntity extends TileEntity implements ITickable{ +public class DrillBitTileEntity extends TileEntity implements ITickableTileEntity{ public final static float ROTATION_PER_TICK = 360f / 20f; // in degrees, 20 ticks per revolution public float rotation = 0; - private EnumFacing direction = EnumFacing.DOWN; + private Direction direction = Direction.DOWN; public DrillBitTileEntity(){ super(zone.moddev.mc.steamadvantage.init.Entities.DRILLBIT); @@ -23,48 +25,58 @@ public DrillBitTileEntity(){ @Override public void tick(){ - if(getWorld().isRemote){ + if(hasWorld() && getWorld().isRemote){ rotation = ROTATION_PER_TICK * (getWorld().getGameTime() % 20); } } - public void setDirection(EnumFacing dir){ + public void setDirection(Direction dir){ if(dir == null || dir == this.direction) return; this.direction = dir; syncDirection(); } - public EnumFacing.Axis getDirection(){ + public Direction.Axis getDirection(){ return direction.getAxis(); } - public static void createDrillBitBlock(World w, BlockPos coord, EnumFacing dir){ + public static void createDrillBitBlock(World w, BlockPos coord, Direction dir){ w.setBlockState(coord, zone.moddev.mc.steamadvantage.init.Blocks.drillbit.getDefaultState()); - DrillBitTileEntity te = new DrillBitTileEntity(); - te.direction = dir; - w.setTileEntity(coord, te); + TileEntity tile = w.getTileEntity(coord); + if(tile instanceof DrillBitTileEntity) ((DrillBitTileEntity) tile).setDirection(dir); } /** * Destroys all drillbits connected to this one */ public void destroyLine(){ - this.destroy(this.direction); - this.destroy(this.direction.getOpposite()); - getWorld().removeBlock(getPos()); // redundant because this is being called on block destruction + destroyLine(true); + } + + public void destroyLine(boolean removeOrigin){ + if(!hasWorld() || getWorld().isRemote) return; + List line = new ArrayList<>(); + line.add(getPos()); + collectLine(line, direction); + collectLine(line, direction.getOpposite()); + // Detach all helpers before block replacement callbacks can re-enter this line. + for(BlockPos coord : line) getWorld().removeTileEntity(coord); + for(BlockPos coord : line) { + if(removeOrigin || !coord.equals(getPos())) getWorld().removeBlock(coord, false); + } } /** * destroys upstream drillbit */ - private void destroy(EnumFacing f){ + private void collectLine(List line, Direction f){ BlockPos coord = this.getPos().offset(f); - while(getWorld().getBlockState(coord).getBlock() == Blocks.drillbit){ - getWorld().removeBlock(coord); + while(getWorld().isBlockLoaded(coord) && getWorld().getBlockState(coord).getBlock() == Blocks.drillbit){ + line.add(coord); coord = coord.offset(f); } } @Override - public NBTTagCompound write(NBTTagCompound root){ + public CompoundNBT write(CompoundNBT root){ super.write(root); writeDirectionToNBT(root); return root; @@ -72,49 +84,53 @@ public NBTTagCompound write(NBTTagCompound root){ @Override - public void read(NBTTagCompound root){ + public void read(CompoundNBT root){ super.read(root); readDirectionFromNBT(root); } @Override - public NBTTagCompound getUpdateTag() { - return write(new NBTTagCompound()); + public CompoundNBT getUpdateTag() { + return write(new CompoundNBT()); } /** * Turns the data field NBT into a network packet */ @Override - public SPacketUpdateTileEntity getUpdatePacket(){ - NBTTagCompound nbtTag = new NBTTagCompound(); + public SUpdateTileEntityPacket getUpdatePacket(){ + CompoundNBT nbtTag = new CompoundNBT(); writeDirectionToNBT(nbtTag); - return new SPacketUpdateTileEntity(this.getPos(), 0, nbtTag); + return new SUpdateTileEntityPacket(this.getPos(), 0, nbtTag); } /** * Receives the network packet made by getDescriptionPacket() */ @Override - public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity packet) { + public void onDataPacket(NetworkManager net, SUpdateTileEntityPacket packet) { readDirectionFromNBT(packet.getNbtCompound()); } - private void writeDirectionToNBT(NBTTagCompound root) { - root.setByte("dir", (byte)direction.getIndex()); + private void writeDirectionToNBT(CompoundNBT root) { + root.putByte("dir", (byte)direction.getIndex()); } - private void readDirectionFromNBT(NBTTagCompound root) { - if(root.hasKey("dir")){ - this.direction = EnumFacing.byIndex(root.getByte("dir")); - } else if(root.hasKey("d")){ - this.direction = EnumFacing.byIndex(root.getByte("d")); + private void readDirectionFromNBT(CompoundNBT root) { + if(root.contains("dir")){ + this.direction = decodeDirection(root.getByte("dir")); + } else if(root.contains("d")){ + this.direction = decodeDirection(root.getByte("d")); } } + private static Direction decodeDirection(int index) { + return index >= 0 && index < Direction.values().length ? Direction.byIndex(index) : Direction.DOWN; + } + private void syncDirection() { if(hasWorld() && !getWorld().isRemote) { markDirty(); - IBlockState state = getWorld().getBlockState(getPos()); + BlockState state = getWorld().getBlockState(getPos()); getWorld().notifyBlockUpdate(getPos(), state, state, 3); } } diff --git a/src/main/java/zone/moddev/mc/steamadvantage/blocks/PlatformBlock.java b/src/main/java/zone/moddev/mc/steamadvantage/blocks/PlatformBlock.java index 990ecc3..ff9349b 100644 --- a/src/main/java/zone/moddev/mc/steamadvantage/blocks/PlatformBlock.java +++ b/src/main/java/zone/moddev/mc/steamadvantage/blocks/PlatformBlock.java @@ -2,14 +2,17 @@ import net.minecraft.block.Block; import net.minecraft.block.material.Material; -import net.minecraft.block.state.IBlockState; +import net.minecraft.block.BlockState; import net.minecraft.item.ItemStack; import net.minecraft.state.IntegerProperty; import net.minecraft.state.StateContainer; -import net.minecraft.util.NonNullList; +import java.util.Collections; +import java.util.List; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.util.math.shapes.VoxelShapes; +import net.minecraft.util.math.shapes.ISelectionContext; +import net.minecraft.world.storage.loot.LootContext; import net.minecraft.world.IBlockReader; import net.minecraft.world.World; import zone.moddev.mc.steamadvantage.init.Blocks; @@ -30,15 +33,15 @@ public PlatformBlock() { setDefaultState(getStateContainer().getBaseState().with(HEIGHT, 1)); } - @Override protected void fillStateContainer(StateContainer.Builder builder) { builder.add(HEIGHT); } - @Override public VoxelShape getShape(IBlockState state, IBlockReader world, BlockPos pos) { return SHAPES[state.get(HEIGHT)]; } - @Override public VoxelShape getCollisionShape(IBlockState state, IBlockReader world, BlockPos pos) { return SHAPES[state.get(HEIGHT)]; } - @Override public boolean isNormalCube(IBlockState state) { return false; } - @Override public boolean isSolid(IBlockState state) { return false; } - @Override public void getDrops(IBlockState state, NonNullList drops, World world, BlockPos pos, int fortune) {} + @Override protected void fillStateContainer(StateContainer.Builder builder) { builder.add(HEIGHT); } + @Override public VoxelShape getShape(BlockState state, IBlockReader world, BlockPos pos, ISelectionContext context) { return SHAPES[state.get(HEIGHT)]; } + @Override public VoxelShape getCollisionShape(BlockState state, IBlockReader world, BlockPos pos, ISelectionContext context) { return SHAPES[state.get(HEIGHT)]; } + @Override public boolean isNormalCube(BlockState state, IBlockReader world, BlockPos pos) { return false; } + @Override public boolean isSolid(BlockState state) { return false; } + @Override public List getDrops(BlockState state, LootContext.Builder context) { return Collections.emptyList(); } @Override - public void neighborChanged(IBlockState state, World world, BlockPos pos, Block block, BlockPos fromPos) { + public void neighborChanged(BlockState state, World world, BlockPos pos, Block block, BlockPos fromPos, boolean moving) { if (!canBlockStay(world, pos)) world.destroyBlock(pos, true); } diff --git a/src/main/java/zone/moddev/mc/steamadvantage/blocks/PumpPipeBlock.java b/src/main/java/zone/moddev/mc/steamadvantage/blocks/PumpPipeBlock.java index ccdeb58..496eb22 100644 --- a/src/main/java/zone/moddev/mc/steamadvantage/blocks/PumpPipeBlock.java +++ b/src/main/java/zone/moddev/mc/steamadvantage/blocks/PumpPipeBlock.java @@ -2,12 +2,15 @@ import net.minecraft.block.Block; import net.minecraft.block.material.Material; -import net.minecraft.block.state.IBlockState; +import net.minecraft.block.BlockState; import net.minecraft.item.ItemStack; -import net.minecraft.util.NonNullList; +import java.util.Collections; +import java.util.List; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.util.math.shapes.VoxelShapes; +import net.minecraft.util.math.shapes.ISelectionContext; +import net.minecraft.world.storage.loot.LootContext; import net.minecraft.world.Explosion; import net.minecraft.world.IBlockReader; import net.minecraft.world.World; @@ -20,14 +23,14 @@ public PumpPipeBlock() { super(Block.Properties.create(Material.IRON).hardnessAndResistance(5.0F, 10.0F)); } - @Override public VoxelShape getShape(IBlockState state, IBlockReader world, BlockPos pos) { return SHAPE; } - @Override public VoxelShape getCollisionShape(IBlockState state, IBlockReader world, BlockPos pos) { return SHAPE; } - @Override public boolean isNormalCube(IBlockState state) { return false; } - @Override public boolean isSolid(IBlockState state) { return false; } - @Override public void getDrops(IBlockState state, NonNullList drops, World world, BlockPos pos, int fortune) {} + @Override public VoxelShape getShape(BlockState state, IBlockReader world, BlockPos pos, ISelectionContext context) { return SHAPE; } + @Override public VoxelShape getCollisionShape(BlockState state, IBlockReader world, BlockPos pos, ISelectionContext context) { return SHAPE; } + @Override public boolean isNormalCube(BlockState state, IBlockReader world, BlockPos pos) { return false; } + @Override public boolean isSolid(BlockState state) { return false; } + @Override public List getDrops(BlockState state, LootContext.Builder context) { return Collections.emptyList(); } @Override - public void onReplaced(IBlockState state, World world, BlockPos pos, IBlockState newState, boolean moving) { + public void onReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moving) { if (state.getBlock() != newState.getBlock()) destroyShaft(world, pos); super.onReplaced(state, world, pos, newState, moving); } diff --git a/src/main/java/zone/moddev/mc/steamadvantage/blocks/SteamTrackBlock.java b/src/main/java/zone/moddev/mc/steamadvantage/blocks/SteamTrackBlock.java index 529a90c..a3cca5b 100644 --- a/src/main/java/zone/moddev/mc/steamadvantage/blocks/SteamTrackBlock.java +++ b/src/main/java/zone/moddev/mc/steamadvantage/blocks/SteamTrackBlock.java @@ -2,11 +2,12 @@ import cyano.poweradvantage.api.simple.BlockSimplePowerConduit; import net.minecraft.block.material.Material; -import net.minecraft.block.state.IBlockState; +import net.minecraft.block.BlockState; import net.minecraft.util.BlockRenderLayer; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.util.math.shapes.VoxelShapes; +import net.minecraft.util.math.shapes.ISelectionContext; import net.minecraft.world.IBlockReader; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -14,9 +15,9 @@ public class SteamTrackBlock extends BlockSimplePowerConduit { public SteamTrackBlock() { super(Material.PISTON, 0.75F, 2.0F / 16.0F, Power.steam_power); } - @Override public VoxelShape getShape(IBlockState state, IBlockReader world, BlockPos pos) { return VoxelShapes.fullCube(); } - @Override public VoxelShape getCollisionShape(IBlockState state, IBlockReader world, BlockPos pos) { return VoxelShapes.fullCube(); } - @Override public boolean isNormalCube(IBlockState state) { return false; } - @Override public boolean isSolid(IBlockState state) { return false; } + @Override public VoxelShape getShape(BlockState state, IBlockReader world, BlockPos pos, ISelectionContext context) { return VoxelShapes.fullCube(); } + @Override public VoxelShape getCollisionShape(BlockState state, IBlockReader world, BlockPos pos, ISelectionContext context) { return VoxelShapes.fullCube(); } + @Override public boolean isNormalCube(BlockState state, IBlockReader world, BlockPos pos) { return false; } + @Override public boolean isSolid(BlockState state) { return false; } @OnlyIn(Dist.CLIENT) @Override public BlockRenderLayer getRenderLayer() { return BlockRenderLayer.CUTOUT; } } diff --git a/src/main/java/zone/moddev/mc/steamadvantage/compat/BaseMetalsCompat.java b/src/main/java/zone/moddev/mc/steamadvantage/compat/BaseMetalsCompat.java index a750a77..af63216 100644 --- a/src/main/java/zone/moddev/mc/steamadvantage/compat/BaseMetalsCompat.java +++ b/src/main/java/zone/moddev/mc/steamadvantage/compat/BaseMetalsCompat.java @@ -1,12 +1,11 @@ package zone.moddev.mc.steamadvantage.compat; import net.minecraft.block.Block; -import net.minecraft.block.state.IBlockState; -import net.minecraft.inventory.InventoryBasic; +import net.minecraft.block.BlockState; +import net.minecraft.inventory.Inventory; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.IRecipe; -import net.minecraft.util.text.TextComponentString; import net.minecraft.world.World; import net.minecraftforge.fml.ModList; import zone.moddev.mc.basemetals.recipe.CrushingRecipe; @@ -29,7 +28,7 @@ public static boolean hasCrusherRecipe(World world, ItemStack input) { public static ItemStack getCrusherRecipeOutput(World world, ItemStack input) { if (world == null || input == null || input.isEmpty()) return null; if (isLoaded()) { - InventoryBasic inventory = new InventoryBasic(new TextComponentString("steam crusher"), 1); + Inventory inventory = new Inventory(1); inventory.setInventorySlotContents(0, input.copy()); for (IRecipe candidate : world.getRecipeManager().getRecipes()) { if (candidate instanceof CrushingRecipe && candidate.matches(inventory, world)) { @@ -40,22 +39,22 @@ public static ItemStack getCrusherRecipeOutput(World world, ItemStack input) { return getVanillaCrusherOutput(input); } - public static ItemStack getCrusherRecipeOutput(World world, IBlockState input) { + public static ItemStack getCrusherRecipeOutput(World world, BlockState input) { return input == null ? null : getCrusherRecipeOutput(world, new ItemStack(input.getBlock())); } private static ItemStack getVanillaCrusherOutput(ItemStack input) { Item item = input.getItem(); - if (item == net.minecraft.init.Blocks.STONE.asItem()) return new ItemStack(net.minecraft.init.Blocks.COBBLESTONE); - if (item == net.minecraft.init.Blocks.COBBLESTONE.asItem()) return new ItemStack(net.minecraft.init.Blocks.GRAVEL); - if (item == net.minecraft.init.Blocks.GRAVEL.asItem()) return new ItemStack(net.minecraft.init.Blocks.SAND); - if (item == net.minecraft.init.Blocks.SANDSTONE.asItem()) return new ItemStack(net.minecraft.init.Blocks.SAND, 4); - if (item == net.minecraft.init.Blocks.RED_SANDSTONE.asItem()) return new ItemStack(net.minecraft.init.Blocks.RED_SAND, 4); - if (item == net.minecraft.init.Blocks.GLASS.asItem()) return new ItemStack(net.minecraft.init.Blocks.SAND); - if (item == net.minecraft.init.Blocks.GLOWSTONE.asItem()) return new ItemStack(net.minecraft.init.Items.GLOWSTONE_DUST, 4); - if (item == net.minecraft.init.Blocks.SUGAR_CANE.asItem()) return new ItemStack(net.minecraft.init.Items.SUGAR, 2); - if (item == net.minecraft.init.Items.BONE) return new ItemStack(net.minecraft.init.Items.BONE_MEAL, 3); - if (item == net.minecraft.init.Items.BLAZE_ROD) return new ItemStack(net.minecraft.init.Items.BLAZE_POWDER, 2); + if (item == net.minecraft.block.Blocks.STONE.asItem()) return new ItemStack(net.minecraft.block.Blocks.COBBLESTONE); + if (item == net.minecraft.block.Blocks.COBBLESTONE.asItem()) return new ItemStack(net.minecraft.block.Blocks.GRAVEL); + if (item == net.minecraft.block.Blocks.GRAVEL.asItem()) return new ItemStack(net.minecraft.block.Blocks.SAND); + if (item == net.minecraft.block.Blocks.SANDSTONE.asItem()) return new ItemStack(net.minecraft.block.Blocks.SAND, 4); + if (item == net.minecraft.block.Blocks.RED_SANDSTONE.asItem()) return new ItemStack(net.minecraft.block.Blocks.RED_SAND, 4); + if (item == net.minecraft.block.Blocks.GLASS.asItem()) return new ItemStack(net.minecraft.block.Blocks.SAND); + if (item == net.minecraft.block.Blocks.GLOWSTONE.asItem()) return new ItemStack(net.minecraft.item.Items.GLOWSTONE_DUST, 4); + if (item == net.minecraft.block.Blocks.SUGAR_CANE.asItem()) return new ItemStack(net.minecraft.item.Items.SUGAR, 2); + if (item == net.minecraft.item.Items.BONE) return new ItemStack(net.minecraft.item.Items.BONE_MEAL, 3); + if (item == net.minecraft.item.Items.BLAZE_ROD) return new ItemStack(net.minecraft.item.Items.BLAZE_POWDER, 2); return null; } } diff --git a/src/main/java/zone/moddev/mc/steamadvantage/enchantments/HighExplosiveEnchantment.java b/src/main/java/zone/moddev/mc/steamadvantage/enchantments/HighExplosiveEnchantment.java index 2c42de6..6adee66 100644 --- a/src/main/java/zone/moddev/mc/steamadvantage/enchantments/HighExplosiveEnchantment.java +++ b/src/main/java/zone/moddev/mc/steamadvantage/enchantments/HighExplosiveEnchantment.java @@ -1,14 +1,14 @@ package zone.moddev.mc.steamadvantage.enchantments; import zone.moddev.mc.steamadvantage.init.Items; -import net.minecraft.enchantment.EnumEnchantmentType; -import net.minecraft.inventory.EntityEquipmentSlot; +import net.minecraft.enchantment.EnchantmentType; +import net.minecraft.inventory.EquipmentSlotType; import net.minecraft.item.ItemStack; public class HighExplosiveEnchantment extends net.minecraft.enchantment.Enchantment{ public HighExplosiveEnchantment() { - super(Rarity.UNCOMMON,EnumEnchantmentType.ALL,new EntityEquipmentSlot[]{EntityEquipmentSlot.MAINHAND}); + super(Rarity.UNCOMMON,EnchantmentType.ALL,new EquipmentSlotType[]{EquipmentSlotType.MAINHAND}); } diff --git a/src/main/java/zone/moddev/mc/steamadvantage/enchantments/PowderlessEnchantment.java b/src/main/java/zone/moddev/mc/steamadvantage/enchantments/PowderlessEnchantment.java index 8abc052..307e77a 100644 --- a/src/main/java/zone/moddev/mc/steamadvantage/enchantments/PowderlessEnchantment.java +++ b/src/main/java/zone/moddev/mc/steamadvantage/enchantments/PowderlessEnchantment.java @@ -1,14 +1,14 @@ package zone.moddev.mc.steamadvantage.enchantments; import zone.moddev.mc.steamadvantage.init.Items; -import net.minecraft.enchantment.EnumEnchantmentType; -import net.minecraft.inventory.EntityEquipmentSlot; +import net.minecraft.enchantment.EnchantmentType; +import net.minecraft.inventory.EquipmentSlotType; import net.minecraft.item.ItemStack; public class PowderlessEnchantment extends net.minecraft.enchantment.Enchantment{ public PowderlessEnchantment() { - super(Rarity.VERY_RARE,EnumEnchantmentType.ALL,new EntityEquipmentSlot[]{EntityEquipmentSlot.MAINHAND}); + super(Rarity.VERY_RARE,EnchantmentType.ALL,new EquipmentSlotType[]{EquipmentSlotType.MAINHAND}); } diff --git a/src/main/java/zone/moddev/mc/steamadvantage/enchantments/RapidReloadEnchantment.java b/src/main/java/zone/moddev/mc/steamadvantage/enchantments/RapidReloadEnchantment.java index fc101a8..7f0a89e 100644 --- a/src/main/java/zone/moddev/mc/steamadvantage/enchantments/RapidReloadEnchantment.java +++ b/src/main/java/zone/moddev/mc/steamadvantage/enchantments/RapidReloadEnchantment.java @@ -1,14 +1,14 @@ package zone.moddev.mc.steamadvantage.enchantments; import zone.moddev.mc.steamadvantage.init.Items; -import net.minecraft.enchantment.EnumEnchantmentType; -import net.minecraft.inventory.EntityEquipmentSlot; +import net.minecraft.enchantment.EnchantmentType; +import net.minecraft.inventory.EquipmentSlotType; import net.minecraft.item.ItemStack; public class RapidReloadEnchantment extends net.minecraft.enchantment.Enchantment{ public RapidReloadEnchantment() { - super(Rarity.RARE,EnumEnchantmentType.ALL,new EntityEquipmentSlot[]{EntityEquipmentSlot.MAINHAND}); + super(Rarity.RARE,EnchantmentType.ALL,new EquipmentSlotType[]{EquipmentSlotType.MAINHAND}); } diff --git a/src/main/java/zone/moddev/mc/steamadvantage/enchantments/RecoilEnchantment.java b/src/main/java/zone/moddev/mc/steamadvantage/enchantments/RecoilEnchantment.java index 1c6cc62..d0a2614 100644 --- a/src/main/java/zone/moddev/mc/steamadvantage/enchantments/RecoilEnchantment.java +++ b/src/main/java/zone/moddev/mc/steamadvantage/enchantments/RecoilEnchantment.java @@ -1,14 +1,14 @@ package zone.moddev.mc.steamadvantage.enchantments; import zone.moddev.mc.steamadvantage.init.Items; -import net.minecraft.enchantment.EnumEnchantmentType; -import net.minecraft.inventory.EntityEquipmentSlot; +import net.minecraft.enchantment.EnchantmentType; +import net.minecraft.inventory.EquipmentSlotType; import net.minecraft.item.ItemStack; public class RecoilEnchantment extends net.minecraft.enchantment.Enchantment{ public RecoilEnchantment() { - super(Rarity.COMMON,EnumEnchantmentType.ALL,new EntityEquipmentSlot[]{EntityEquipmentSlot.MAINHAND}); + super(Rarity.COMMON,EnchantmentType.ALL,new EquipmentSlotType[]{EquipmentSlotType.MAINHAND}); } diff --git a/src/main/java/zone/moddev/mc/steamadvantage/graphics/DrillBitRenderer.java b/src/main/java/zone/moddev/mc/steamadvantage/graphics/DrillBitRenderer.java index 448f8ce..6a95cee 100644 --- a/src/main/java/zone/moddev/mc/steamadvantage/graphics/DrillBitRenderer.java +++ b/src/main/java/zone/moddev/mc/steamadvantage/graphics/DrillBitRenderer.java @@ -3,13 +3,13 @@ import zone.moddev.mc.steamadvantage.SteamAdvantage; import zone.moddev.mc.steamadvantage.blocks.DrillBitTileEntity; import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.GlStateManager; +import com.mojang.blaze3d.platform.GlStateManager; import net.minecraft.client.renderer.RenderHelper; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.tileentity.TileEntityRenderer; import net.minecraft.client.renderer.vertex.DefaultVertexFormats; -import net.minecraft.util.EnumFacing; +import net.minecraft.util.Direction; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -29,9 +29,16 @@ public DrillBitRenderer() { @Override public void render(final DrillBitTileEntity te, final double x, final double y, final double z, final float partialTick, final int destroyStage) { GlStateManager.pushMatrix(); - GlStateManager.translated(x, y, z); - render(te,te.getWorld(),te.getPos(),partialTick); - GlStateManager.popMatrix(); + try { + GlStateManager.translated(x, y, z); + render(te,te.getWorld(),te.getPos(),partialTick); + } finally { + GlStateManager.enableCull(); + GlStateManager.disableBlend(); + GlStateManager.shadeModel(7424); + RenderHelper.enableStandardItemLighting(); + GlStateManager.popMatrix(); + } } private void render(DrillBitTileEntity e, World world, BlockPos pos, float partialTick){ @@ -66,9 +73,9 @@ private void render(DrillBitTileEntity e, World world, BlockPos pos, float parti final float radius = 0.25f; GlStateManager.translatef(0.5f, 0.5f, 0.5f); - if(e.getDirection() != EnumFacing.Axis.Y){ + if(e.getDirection() != Direction.Axis.Y){ GlStateManager.rotatef(90, 1.0f, 0.0f, 0.0f); - if(e.getDirection() != EnumFacing.Axis.Z){ + if(e.getDirection() != Direction.Axis.Z){ GlStateManager.rotatef(90, 0.0f, 0.0f, 1.0f); } } diff --git a/src/main/java/zone/moddev/mc/steamadvantage/gui/BlastFurnaceGUI.java b/src/main/java/zone/moddev/mc/steamadvantage/gui/BlastFurnaceGUI.java index 82a16de..24dd0ea 100644 --- a/src/main/java/zone/moddev/mc/steamadvantage/gui/BlastFurnaceGUI.java +++ b/src/main/java/zone/moddev/mc/steamadvantage/gui/BlastFurnaceGUI.java @@ -1,10 +1,11 @@ package zone.moddev.mc.steamadvantage.gui; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.Slot; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.inventory.container.Slot; import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; import cyano.poweradvantage.api.simple.SimpleMachineGUI; + import zone.moddev.mc.poweradvantage.math.Integer2D; import zone.moddev.mc.steamadvantage.SteamAdvantage; import zone.moddev.mc.steamadvantage.machines.BlastFurnaceTileEntity; @@ -18,7 +19,7 @@ public BlastFurnaceGUI() { ); for(int i = 4; i < 7; i++)super.specialSlots.put(i, (SlotContext c)->new Slot(c.machineInventory,c.slotIndex,c.screenPositionX,c.screenPositionY){ @Override - public ItemStack onTake(EntityPlayer player, ItemStack stack) + public ItemStack onTake(PlayerEntity player, ItemStack stack) { stack.onCrafting(player.getEntityWorld(), player, stack.getCount()); return super.onTake(player, stack); @@ -46,8 +47,8 @@ public ItemStack onTake(EntityPlayer player, ItemStack stack) * @param guiContainer This is the instance of GUIContainer that is drawing * the GUI. You need to use it to draw on the screen. For example:
-guiContainer.mc.getTextureManager().bindTexture(arrowTexture);
-guiContainer.drawTexturedModalRect(x+79, y+35, 0, 0, arrowLength, 17); // x, y, textureOffsetX, textureOffsetY, width, height)
+net.minecraft.client.Minecraft.getInstance().getTextureManager().bindTexture(arrowTexture);
+guiContainer.blit(x+79, y+35, 0, 0, arrowLength, 17); // x, y, textureOffsetX, textureOffsetY, width, height)
 	   
* @param x This is the x coordinate (in pixels) from the top-left corner of * the GUI @@ -55,6 +56,7 @@ public ItemStack onTake(EntityPlayer player, ItemStack stack) * the GUI * @param z This is the z coordinate (no units) into the depth of the screen */ + @net.minecraftforge.api.distmarker.OnlyIn(net.minecraftforge.api.distmarker.Dist.CLIENT) @Override public void drawGUIDecorations(Object srcEntity, GUIContainer guiContainer, int x, int y, float z){ diff --git a/src/main/java/zone/moddev/mc/steamadvantage/gui/CoalBoilerGUI.java b/src/main/java/zone/moddev/mc/steamadvantage/gui/CoalBoilerGUI.java index 84b5c74..6391db8 100644 --- a/src/main/java/zone/moddev/mc/steamadvantage/gui/CoalBoilerGUI.java +++ b/src/main/java/zone/moddev/mc/steamadvantage/gui/CoalBoilerGUI.java @@ -2,6 +2,7 @@ import net.minecraft.util.ResourceLocation; import cyano.poweradvantage.api.simple.SimpleMachineGUI; + import zone.moddev.mc.poweradvantage.math.Integer2D; import zone.moddev.mc.steamadvantage.SteamAdvantage; import zone.moddev.mc.steamadvantage.machines.CoalBoilerTileEntity; @@ -33,8 +34,8 @@ public CoalBoilerGUI() { * @param guiContainer This is the instance of GUIContainer that is drawing * the GUI. You need to use it to draw on the screen. For example:
-guiContainer.mc.getTextureManager().bindTexture(arrowTexture);
-guiContainer.drawTexturedModalRect(x+79, y+35, 0, 0, arrowLength, 17); // x, y, textureOffsetX, textureOffsetY, width, height)
+net.minecraft.client.Minecraft.getInstance().getTextureManager().bindTexture(arrowTexture);
+guiContainer.blit(x+79, y+35, 0, 0, arrowLength, 17); // x, y, textureOffsetX, textureOffsetY, width, height)
 	   
* @param x This is the x coordinate (in pixels) from the top-left corner of * the GUI @@ -42,6 +43,7 @@ public CoalBoilerGUI() { * the GUI * @param z This is the z coordinate (no units) into the depth of the screen */ + @net.minecraftforge.api.distmarker.OnlyIn(net.minecraftforge.api.distmarker.Dist.CLIENT) @Override public void drawGUIDecorations(Object srcEntity, GUIContainer guiContainer, int x, int y, float z){ diff --git a/src/main/java/zone/moddev/mc/steamadvantage/gui/ElectricBoilerGUI.java b/src/main/java/zone/moddev/mc/steamadvantage/gui/ElectricBoilerGUI.java index 2affaf7..2523589 100644 --- a/src/main/java/zone/moddev/mc/steamadvantage/gui/ElectricBoilerGUI.java +++ b/src/main/java/zone/moddev/mc/steamadvantage/gui/ElectricBoilerGUI.java @@ -2,6 +2,7 @@ import net.minecraft.util.ResourceLocation; import cyano.poweradvantage.api.simple.SimpleMachineGUI; + import zone.moddev.mc.poweradvantage.math.Integer2D; import zone.moddev.mc.steamadvantage.SteamAdvantage; import zone.moddev.mc.steamadvantage.machines.ElectricBoilerTileEntity; @@ -33,8 +34,8 @@ public ElectricBoilerGUI() { * @param guiContainer This is the instance of GUIContainer that is drawing * the GUI. You need to use it to draw on the screen. For example:
-guiContainer.mc.getTextureManager().bindTexture(arrowTexture);
-guiContainer.drawTexturedModalRect(x+79, y+35, 0, 0, arrowLength, 17); // x, y, textureOffsetX, textureOffsetY, width, height)
+net.minecraft.client.Minecraft.getInstance().getTextureManager().bindTexture(arrowTexture);
+guiContainer.blit(x+79, y+35, 0, 0, arrowLength, 17); // x, y, textureOffsetX, textureOffsetY, width, height)
 	   
* @param x This is the x coordinate (in pixels) from the top-left corner of * the GUI @@ -42,6 +43,7 @@ public ElectricBoilerGUI() { * the GUI * @param z This is the z coordinate (no units) into the depth of the screen */ + @net.minecraftforge.api.distmarker.OnlyIn(net.minecraftforge.api.distmarker.Dist.CLIENT) @Override public void drawGUIDecorations(Object srcEntity, GUIContainer guiContainer, int x, int y, float z){ diff --git a/src/main/java/zone/moddev/mc/steamadvantage/gui/GUIHelper.java b/src/main/java/zone/moddev/mc/steamadvantage/gui/GUIHelper.java index 697f3d3..81c9109 100644 --- a/src/main/java/zone/moddev/mc/steamadvantage/gui/GUIHelper.java +++ b/src/main/java/zone/moddev/mc/steamadvantage/gui/GUIHelper.java @@ -9,6 +9,7 @@ import net.minecraft.util.math.MathHelper; import cyano.poweradvantage.api.fluid.FluidStack; +@net.minecraftforge.api.distmarker.OnlyIn(net.minecraftforge.api.distmarker.Dist.CLIENT) public abstract class GUIHelper { @@ -92,7 +93,7 @@ public static void drawFlameProgress(int x, int y, float flameHeight, GUIContain int h = (int)(flameHeight*height); if(h == 0 ) h = 1; if(h > 0){ - gc.drawTexturedModalRect(x, y+h, flameTexX, flameTexY+h, width, height - h); + gc.blit(x, y+h, flameTexX, flameTexY+h, width, height - h); } } @@ -107,9 +108,9 @@ public static void drawFluidBar(FluidStack fs, float barHeight, int xPos, int yP if(barHeight > 0){ FluidTankGUI.drawFluidFilledRectangle(guiContainer,fs,x+xPos, y+yPos+barSlotHeight-h,w, h,z); } - guiContainer.mc.getTextureManager().bindTexture(displayImage); + net.minecraft.client.Minecraft.getInstance().getTextureManager().bindTexture(displayImage); - guiContainer.drawTexturedModalRect(x+xPos-texMarginW, y+yPos-texMarginH, texOverlayX, texOverlayY, texOverlayW, texOverlayH); // x, y, textureOffsetX, textureOffsetY, width, height) + guiContainer.blit(x+xPos-texMarginW, y+yPos-texMarginH, texOverlayX, texOverlayY, texOverlayW, texOverlayH); // x, y, textureOffsetX, textureOffsetY, width, height) } @@ -124,7 +125,7 @@ public static void drawDownArrowProgress(int x, int y, float progress, int h = (int)(progress*height); if(h == 0 ) h = 1; if(h > 0){ - gc.drawTexturedModalRect(x, y, arrowTexX, arrowTexY, width, h); + gc.blit(x, y, arrowTexX, arrowTexY, width, h); } } } diff --git a/src/main/java/zone/moddev/mc/steamadvantage/gui/GeothermalBoilerGUI.java b/src/main/java/zone/moddev/mc/steamadvantage/gui/GeothermalBoilerGUI.java index dfaf4de..e9a12d7 100644 --- a/src/main/java/zone/moddev/mc/steamadvantage/gui/GeothermalBoilerGUI.java +++ b/src/main/java/zone/moddev/mc/steamadvantage/gui/GeothermalBoilerGUI.java @@ -2,6 +2,7 @@ import net.minecraft.util.ResourceLocation; import cyano.poweradvantage.api.simple.SimpleMachineGUI; + import zone.moddev.mc.poweradvantage.math.Integer2D; import zone.moddev.mc.steamadvantage.SteamAdvantage; import zone.moddev.mc.steamadvantage.machines.GeothermalBoilerTileEntity; @@ -33,8 +34,8 @@ public GeothermalBoilerGUI() { * @param guiContainer This is the instance of GUIContainer that is drawing * the GUI. You need to use it to draw on the screen. For example:
-guiContainer.mc.getTextureManager().bindTexture(arrowTexture);
-guiContainer.drawTexturedModalRect(x+79, y+35, 0, 0, arrowLength, 17); // x, y, textureOffsetX, textureOffsetY, width, height)
+net.minecraft.client.Minecraft.getInstance().getTextureManager().bindTexture(arrowTexture);
+guiContainer.blit(x+79, y+35, 0, 0, arrowLength, 17); // x, y, textureOffsetX, textureOffsetY, width, height)
 	   
* @param x This is the x coordinate (in pixels) from the top-left corner of * the GUI @@ -42,6 +43,7 @@ public GeothermalBoilerGUI() { * the GUI * @param z This is the z coordinate (no units) into the depth of the screen */ + @net.minecraftforge.api.distmarker.OnlyIn(net.minecraftforge.api.distmarker.Dist.CLIENT) @Override public void drawGUIDecorations(Object srcEntity, GUIContainer guiContainer, int x, int y, float z){ diff --git a/src/main/java/zone/moddev/mc/steamadvantage/gui/OilBoilerGUI.java b/src/main/java/zone/moddev/mc/steamadvantage/gui/OilBoilerGUI.java index 7ab9de3..b31d60d 100644 --- a/src/main/java/zone/moddev/mc/steamadvantage/gui/OilBoilerGUI.java +++ b/src/main/java/zone/moddev/mc/steamadvantage/gui/OilBoilerGUI.java @@ -1,6 +1,7 @@ package zone.moddev.mc.steamadvantage.gui; import cyano.poweradvantage.api.simple.SimpleMachineGUI; + import zone.moddev.mc.poweradvantage.math.Integer2D; import zone.moddev.mc.steamadvantage.SteamAdvantage; import zone.moddev.mc.steamadvantage.machines.OilBoilerTileEntity; @@ -33,8 +34,8 @@ public OilBoilerGUI() { * @param guiContainer This is the instance of GUIContainer that is drawing * the GUI. You need to use it to draw on the screen. For example:
-guiContainer.mc.getTextureManager().bindTexture(arrowTexture);
-guiContainer.drawTexturedModalRect(x+79, y+35, 0, 0, arrowLength, 17); // x, y, textureOffsetX, textureOffsetY, width, height)
+net.minecraft.client.Minecraft.getInstance().getTextureManager().bindTexture(arrowTexture);
+guiContainer.blit(x+79, y+35, 0, 0, arrowLength, 17); // x, y, textureOffsetX, textureOffsetY, width, height)
 	   
* @param x This is the x coordinate (in pixels) from the top-left corner of * the GUI @@ -42,6 +43,7 @@ public OilBoilerGUI() { * the GUI * @param z This is the z coordinate (no units) into the depth of the screen */ + @net.minecraftforge.api.distmarker.OnlyIn(net.minecraftforge.api.distmarker.Dist.CLIENT) @Override public void drawGUIDecorations(Object srcEntity, GUIContainer guiContainer, int x, int y, float z){ diff --git a/src/main/java/zone/moddev/mc/steamadvantage/gui/RockCrusherGUI.java b/src/main/java/zone/moddev/mc/steamadvantage/gui/RockCrusherGUI.java index 64c72b2..aaf4521 100644 --- a/src/main/java/zone/moddev/mc/steamadvantage/gui/RockCrusherGUI.java +++ b/src/main/java/zone/moddev/mc/steamadvantage/gui/RockCrusherGUI.java @@ -2,6 +2,7 @@ import net.minecraft.util.ResourceLocation; import cyano.poweradvantage.api.simple.SimpleMachineGUI; + import zone.moddev.mc.poweradvantage.math.Integer2D; import zone.moddev.mc.steamadvantage.SteamAdvantage; import zone.moddev.mc.steamadvantage.machines.RockCrusherTileEntity; @@ -32,8 +33,8 @@ public RockCrusherGUI() { * @param guiContainer This is the instance of GUIContainer that is drawing * the GUI. You need to use it to draw on the screen. For example:
-guiContainer.mc.getTextureManager().bindTexture(arrowTexture);
-guiContainer.drawTexturedModalRect(x+79, y+35, 0, 0, arrowLength, 17); // x, y, textureOffsetX, textureOffsetY, width, height)
+net.minecraft.client.Minecraft.getInstance().getTextureManager().bindTexture(arrowTexture);
+guiContainer.blit(x+79, y+35, 0, 0, arrowLength, 17); // x, y, textureOffsetX, textureOffsetY, width, height)
 	   
* @param x This is the x coordinate (in pixels) from the top-left corner of * the GUI @@ -41,6 +42,7 @@ public RockCrusherGUI() { * the GUI * @param z This is the z coordinate (no units) into the depth of the screen */ + @net.minecraftforge.api.distmarker.OnlyIn(net.minecraftforge.api.distmarker.Dist.CLIENT) @Override public void drawGUIDecorations(Object srcEntity, GUIContainer guiContainer, int x, int y, float z){ diff --git a/src/main/java/zone/moddev/mc/steamadvantage/gui/SteamDrillGUI.java b/src/main/java/zone/moddev/mc/steamadvantage/gui/SteamDrillGUI.java index 41a9727..d2b819e 100644 --- a/src/main/java/zone/moddev/mc/steamadvantage/gui/SteamDrillGUI.java +++ b/src/main/java/zone/moddev/mc/steamadvantage/gui/SteamDrillGUI.java @@ -2,6 +2,7 @@ import net.minecraft.util.ResourceLocation; import cyano.poweradvantage.api.simple.SimpleMachineGUI; + import zone.moddev.mc.poweradvantage.math.Integer2D; import zone.moddev.mc.steamadvantage.SteamAdvantage; import zone.moddev.mc.steamadvantage.machines.SteamDrillTileEntity; @@ -32,8 +33,8 @@ public SteamDrillGUI() { * @param guiContainer This is the instance of GUIContainer that is drawing * the GUI. You need to use it to draw on the screen. For example:
-guiContainer.mc.getTextureManager().bindTexture(arrowTexture);
-guiContainer.drawTexturedModalRect(x+79, y+35, 0, 0, arrowLength, 17); // x, y, textureOffsetX, textureOffsetY, width, height)
+net.minecraft.client.Minecraft.getInstance().getTextureManager().bindTexture(arrowTexture);
+guiContainer.blit(x+79, y+35, 0, 0, arrowLength, 17); // x, y, textureOffsetX, textureOffsetY, width, height)
 	   
* @param x This is the x coordinate (in pixels) from the top-left corner of * the GUI @@ -41,6 +42,7 @@ public SteamDrillGUI() { * the GUI * @param z This is the z coordinate (no units) into the depth of the screen */ + @net.minecraftforge.api.distmarker.OnlyIn(net.minecraftforge.api.distmarker.Dist.CLIENT) @Override public void drawGUIDecorations(Object srcEntity, GUIContainer guiContainer, int x, int y, float z){ diff --git a/src/main/java/zone/moddev/mc/steamadvantage/gui/SteamPumpGUI.java b/src/main/java/zone/moddev/mc/steamadvantage/gui/SteamPumpGUI.java index 69ac50f..7cc893c 100644 --- a/src/main/java/zone/moddev/mc/steamadvantage/gui/SteamPumpGUI.java +++ b/src/main/java/zone/moddev/mc/steamadvantage/gui/SteamPumpGUI.java @@ -1,6 +1,7 @@ package zone.moddev.mc.steamadvantage.gui; import cyano.poweradvantage.api.simple.SimpleMachineGUI; + import zone.moddev.mc.poweradvantage.math.Integer2D; import zone.moddev.mc.steamadvantage.SteamAdvantage; import zone.moddev.mc.steamadvantage.machines.SteamPumpTileEntity; @@ -33,8 +34,8 @@ public SteamPumpGUI() { * @param guiContainer This is the instance of GUIContainer that is drawing * the GUI. You need to use it to draw on the screen. For example:
-guiContainer.mc.getTextureManager().bindTexture(arrowTexture);
-guiContainer.drawTexturedModalRect(x+79, y+35, 0, 0, arrowLength, 17); // x, y, textureOffsetX, textureOffsetY, width, height)
+net.minecraft.client.Minecraft.getInstance().getTextureManager().bindTexture(arrowTexture);
+guiContainer.blit(x+79, y+35, 0, 0, arrowLength, 17); // x, y, textureOffsetX, textureOffsetY, width, height)
 	   
* @param x This is the x coordinate (in pixels) from the top-left corner of * the GUI @@ -42,6 +43,7 @@ public SteamPumpGUI() { * the GUI * @param z This is the z coordinate (no units) into the depth of the screen */ + @net.minecraftforge.api.distmarker.OnlyIn(net.minecraftforge.api.distmarker.Dist.CLIENT) @Override public void drawGUIDecorations(Object srcEntity, GUIContainer guiContainer, int x, int y, float z){ diff --git a/src/main/java/zone/moddev/mc/steamadvantage/gui/SteamStillGUI.java b/src/main/java/zone/moddev/mc/steamadvantage/gui/SteamStillGUI.java index fb5bd8c..6a509c5 100644 --- a/src/main/java/zone/moddev/mc/steamadvantage/gui/SteamStillGUI.java +++ b/src/main/java/zone/moddev/mc/steamadvantage/gui/SteamStillGUI.java @@ -1,6 +1,7 @@ package zone.moddev.mc.steamadvantage.gui; import cyano.poweradvantage.api.simple.SimpleMachineGUI; + import zone.moddev.mc.poweradvantage.math.Integer2D; import zone.moddev.mc.steamadvantage.SteamAdvantage; import zone.moddev.mc.steamadvantage.machines.SteamStillTileEntity; @@ -33,8 +34,8 @@ public SteamStillGUI() { * @param guiContainer This is the instance of GUIContainer that is drawing * the GUI. You need to use it to draw on the screen. For example:
-guiContainer.mc.getTextureManager().bindTexture(arrowTexture);
-guiContainer.drawTexturedModalRect(x+79, y+35, 0, 0, arrowLength, 17); // x, y, textureOffsetX, textureOffsetY, width, height)
+net.minecraft.client.Minecraft.getInstance().getTextureManager().bindTexture(arrowTexture);
+guiContainer.blit(x+79, y+35, 0, 0, arrowLength, 17); // x, y, textureOffsetX, textureOffsetY, width, height)
 	   
* @param x This is the x coordinate (in pixels) from the top-left corner of * the GUI @@ -42,6 +43,7 @@ public SteamStillGUI() { * the GUI * @param z This is the z coordinate (no units) into the depth of the screen */ + @net.minecraftforge.api.distmarker.OnlyIn(net.minecraftforge.api.distmarker.Dist.CLIENT) @Override public void drawGUIDecorations(Object srcEntity, GUIContainer guiContainer, int x, int y, float z){ diff --git a/src/main/java/zone/moddev/mc/steamadvantage/gui/SteamTankGUI.java b/src/main/java/zone/moddev/mc/steamadvantage/gui/SteamTankGUI.java index 69e9cdc..0f36084 100644 --- a/src/main/java/zone/moddev/mc/steamadvantage/gui/SteamTankGUI.java +++ b/src/main/java/zone/moddev/mc/steamadvantage/gui/SteamTankGUI.java @@ -2,6 +2,7 @@ import net.minecraft.util.ResourceLocation; import cyano.poweradvantage.api.simple.SimpleMachineGUI; + import zone.moddev.mc.poweradvantage.math.Integer2D; import zone.moddev.mc.steamadvantage.SteamAdvantage; import zone.moddev.mc.steamadvantage.machines.SteamTankTileEntity; @@ -32,8 +33,8 @@ public SteamTankGUI() { * @param guiContainer This is the instance of GUIContainer that is drawing * the GUI. You need to use it to draw on the screen. For example:
-guiContainer.mc.getTextureManager().bindTexture(arrowTexture);
-guiContainer.drawTexturedModalRect(x+79, y+35, 0, 0, arrowLength, 17); // x, y, textureOffsetX, textureOffsetY, width, height)
+net.minecraft.client.Minecraft.getInstance().getTextureManager().bindTexture(arrowTexture);
+guiContainer.blit(x+79, y+35, 0, 0, arrowLength, 17); // x, y, textureOffsetX, textureOffsetY, width, height)
 	   
* @param x This is the x coordinate (in pixels) from the top-left corner of * the GUI @@ -41,6 +42,7 @@ public SteamTankGUI() { * the GUI * @param z This is the z coordinate (no units) into the depth of the screen */ + @net.minecraftforge.api.distmarker.OnlyIn(net.minecraftforge.api.distmarker.Dist.CLIENT) @Override public void drawGUIDecorations(Object srcEntity, GUIContainer guiContainer, int x, int y, float z){ diff --git a/src/main/java/zone/moddev/mc/steamadvantage/init/Blocks.java b/src/main/java/zone/moddev/mc/steamadvantage/init/Blocks.java index f2ce5f9..affa95d 100644 --- a/src/main/java/zone/moddev/mc/steamadvantage/init/Blocks.java +++ b/src/main/java/zone/moddev/mc/steamadvantage/init/Blocks.java @@ -5,9 +5,9 @@ import cyano.poweradvantage.api.GUIBlock; import net.minecraft.block.Block; -import net.minecraft.block.state.IBlockState; +import net.minecraft.block.BlockState; import net.minecraft.item.Item; -import net.minecraft.item.ItemBlock; +import net.minecraft.item.BlockItem; import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; @@ -44,7 +44,7 @@ public final class Blocks { public static GUIBlock steam_drill; public static GUIBlock steam_elevator; public static Block steam_elevator_platform; - public static IBlockState[] steam_elevator_platforms; + public static BlockState[] steam_elevator_platforms; public static Block steam_pipe; public static Block drillbit; public static Block steam_track; @@ -71,7 +71,7 @@ public static synchronized void init() { steam_drill = (GUIBlock) add(new SteamDrillBlock(), "steam_drill"); drillbit = add(new DrillBitBlock(), "drillbit"); steam_elevator_platform = add(new PlatformBlock(), "platform"); - steam_elevator_platforms = new IBlockState[5]; + steam_elevator_platforms = new BlockState[5]; for (int i = 0; i < steam_elevator_platforms.length; i++) { steam_elevator_platforms[i] = steam_elevator_platform.getDefaultState().with(PlatformBlock.HEIGHT, i); } @@ -104,7 +104,7 @@ public static void registerBlockItems(RegistryEvent.Register event) { if (!"pump_pipe_steam".equals(entry.getKey()) && !"drillbit".equals(entry.getKey())) { properties.group(ItemGroups.tab_powerAdvantage); } - ItemBlock item = new ItemBlock(entry.getValue(), properties); + BlockItem item = new BlockItem(entry.getValue(), properties); item.setRegistryName(SteamAdvantage.MODID, entry.getKey()); event.getRegistry().register(item); } diff --git a/src/main/java/zone/moddev/mc/steamadvantage/init/Entities.java b/src/main/java/zone/moddev/mc/steamadvantage/init/Entities.java index 046584f..1661127 100644 --- a/src/main/java/zone/moddev/mc/steamadvantage/init/Entities.java +++ b/src/main/java/zone/moddev/mc/steamadvantage/init/Entities.java @@ -4,6 +4,7 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityType; +import net.minecraft.block.Block; import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; @@ -42,23 +43,23 @@ public static void init() {} @SubscribeEvent public static void register(RegistryEvent.Register> event) { - STEAM_BOILER_COAL = register(event, "steam_boiler_coal", CoalBoilerTileEntity::new); - STEAM_BOILER_ELECTRIC = register(event, "steam_boiler_electric", ElectricBoilerTileEntity::new); - STEAM_BOILER_GEOTHERMAL = register(event, "steam_boiler_geothermal", GeothermalBoilerTileEntity::new); - STEAM_TANK = register(event, "steam_tank", SteamTankTileEntity::new); - STEAM_FURNACE = register(event, "steam_furnace", BlastFurnaceTileEntity::new); - STEAM_CRUSHER = register(event, "steam_crusher", RockCrusherTileEntity::new); - STEAM_DRILL = register(event, "steam_drill", SteamDrillTileEntity::new); - STEAM_ELEVATOR = register(event, "steam_elevator", SteamElevatorTileEntity::new); - DRILLBIT = register(event, "drillbit", DrillBitTileEntity::new); - STEAM_STILL = register(event, "steam_still", SteamStillTileEntity::new); - STEAM_PUMP = register(event, "steam_pump", SteamPumpTileEntity::new); - STEAM_BOILER_OIL = register(event, "steam_boiler_oil", OilBoilerTileEntity::new); + STEAM_BOILER_COAL = register(event, "steam_boiler_coal", CoalBoilerTileEntity::new, Blocks.steam_boiler_coal); + STEAM_BOILER_ELECTRIC = register(event, "steam_boiler_electric", ElectricBoilerTileEntity::new, Blocks.steam_boiler_electric); + STEAM_BOILER_GEOTHERMAL = register(event, "steam_boiler_geothermal", GeothermalBoilerTileEntity::new, Blocks.steam_boiler_geothermal); + STEAM_TANK = register(event, "steam_tank", SteamTankTileEntity::new, Blocks.steam_tank); + STEAM_FURNACE = register(event, "steam_furnace", BlastFurnaceTileEntity::new, Blocks.steam_furnace); + STEAM_CRUSHER = register(event, "steam_crusher", RockCrusherTileEntity::new, Blocks.steam_crusher); + STEAM_DRILL = register(event, "steam_drill", SteamDrillTileEntity::new, Blocks.steam_drill); + STEAM_ELEVATOR = register(event, "steam_elevator", SteamElevatorTileEntity::new, Blocks.steam_elevator); + DRILLBIT = register(event, "drillbit", DrillBitTileEntity::new, Blocks.drillbit); + STEAM_STILL = register(event, "steam_still", SteamStillTileEntity::new, Blocks.steam_still); + STEAM_PUMP = register(event, "steam_pump", SteamPumpTileEntity::new, Blocks.steam_pump); + STEAM_BOILER_OIL = register(event, "steam_boiler_oil", OilBoilerTileEntity::new, Blocks.steam_boiler_oil); } private static TileEntityType register( - RegistryEvent.Register> event, String id, Supplier factory) { - TileEntityType type = TileEntityType.Builder.create(factory).build(null); + RegistryEvent.Register> event, String id, Supplier factory, Block block) { + TileEntityType type = TileEntityType.Builder.create(factory, block).build(null); type.setRegistryName(SteamAdvantage.MODID, id); event.getRegistry().register(type); return type; diff --git a/src/main/java/zone/moddev/mc/steamadvantage/init/Villages.java b/src/main/java/zone/moddev/mc/steamadvantage/init/Villages.java index 7d52850..d17d8d8 100644 --- a/src/main/java/zone/moddev/mc/steamadvantage/init/Villages.java +++ b/src/main/java/zone/moddev/mc/steamadvantage/init/Villages.java @@ -1,53 +1,60 @@ package zone.moddev.mc.steamadvantage.init; -import net.minecraft.entity.passive.EntityVillager; +import java.util.List; +import java.util.Random; +import net.minecraft.enchantment.EnchantmentHelper; +import net.minecraft.entity.merchant.villager.VillagerProfession; +import net.minecraft.entity.merchant.villager.VillagerTrades; import net.minecraft.item.Item; -import net.minecraft.util.ResourceLocation; -import net.minecraftforge.registries.ForgeRegistries; -import net.minecraftforge.fml.common.registry.VillagerRegistry; +import net.minecraft.item.ItemStack; +import net.minecraft.item.MerchantOffer; +import net.minecraftforge.event.village.VillagerTradesEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod; import zone.moddev.mc.steamadvantage.SteamAdvantage; -public abstract class Villages { - // TODO: add machinist villager - private static final ResourceLocation[] PROFESSION_LIST = { - new ResourceLocation("minecraft:farmer"), - new ResourceLocation("minecraft:librarian"), - new ResourceLocation("minecraft:priest"), - new ResourceLocation("minecraft:smith"), - new ResourceLocation("minecraft:butcher") - }; +/** Legacy smith careers map to their native 1.14 professions; prices and levels are unchanged. */ +@Mod.EventBusSubscriber(modid = SteamAdvantage.MODID) +public final class Villages { + private Villages() {} + public static void init() {} - private static boolean initDone = false; - public static void init(){ - if(initDone) return; - - Entities.init(); + @SubscribeEvent + public static void addTrades(VillagerTradesEvent event) { + VillagerProfession profession = event.getType(); + List novice = event.getTrades().get(1); + if (profession == VillagerProfession.ARMORER || profession == VillagerProfession.TOOLSMITH + || profession == VillagerProfession.WEAPONSMITH || profession == VillagerProfession.LIBRARIAN) { + novice.add(sell(Items.steam_governor, -4, -1)); + } + if (profession == VillagerProfession.LIBRARIAN) novice.add(sell(Blocks.steam_pipe.asItem(), -8, -4)); + if (profession == VillagerProfession.WEAPONSMITH || profession == VillagerProfession.TOOLSMITH) { + novice.add(sell(Items.blackpowder_cartridge, -7, -5)); + novice.add(sell(Items.blackpowder_musket, 10, 15)); + } + if (profession == VillagerProfession.CLERIC) { + event.getTrades().get(3).add((trader, random) -> { + int enchantmentLevel = 5 + random.nextInt(15); + ItemStack musket = EnchantmentHelper.addRandomEnchantment(random, + new ItemStack(Items.blackpowder_musket), enchantmentLevel, false); + int price = Math.min(randomPrice(random, 15, 25) + enchantmentLevel, 64); + return offer(price, musket); + }); + } + } - try { - insertTrades(3, 3, 1, new EntityVillager.ListItemForEmeralds(Items.steam_governor, new EntityVillager.PriceInfo(-4,-1))); - insertTrades(3, 2, 1, new EntityVillager.ListItemForEmeralds(Items.steam_governor, new EntityVillager.PriceInfo(-4,-1))); - insertTrades(3, 1, 1, new EntityVillager.ListItemForEmeralds(Items.steam_governor, new EntityVillager.PriceInfo(-4,-1))); - insertTrades(1, 1, 1, new EntityVillager.ListItemForEmeralds(Items.steam_governor, new EntityVillager.PriceInfo(-4,-1))); - insertTrades(1, 1, 1, new EntityVillager.ListItemForEmeralds(Item.getItemFromBlock(Blocks.steam_pipe), new EntityVillager.PriceInfo(-8,-4))); - insertTrades(3, 2, 1, new EntityVillager.ListItemForEmeralds(Items.blackpowder_cartridge, new EntityVillager.PriceInfo(-7,-5))); - insertTrades(3, 2, 1, new EntityVillager.ListItemForEmeralds(Items.blackpowder_musket, new EntityVillager.PriceInfo(10,15))); - insertTrades(3, 3, 1, new EntityVillager.ListItemForEmeralds(Items.blackpowder_cartridge, new EntityVillager.PriceInfo(-7,-5))); - insertTrades(3, 3, 1, new EntityVillager.ListItemForEmeralds(Items.blackpowder_musket, new EntityVillager.PriceInfo(10,15))); - insertTrades(2, 1, 3, - new EntityVillager.ListEnchantedItemForEmeralds(Items.blackpowder_musket, new EntityVillager.PriceInfo(15, 25))); - } catch (RuntimeException e) { - SteamAdvantage.LOGGER.error("Failed to add trades to villagers", e); - } - - initDone = true; - } + private static VillagerTrades.ITrade sell(Item item, int min, int max) { + return (trader, random) -> { + int price = randomPrice(random, min, max); + return offer(price < 0 ? 1 : price, new ItemStack(item, price < 0 ? -price : 1)); + }; + } - private static void insertTrades(int professionID, int careerID, int tradeLevel, EntityVillager.ITradeList... trades) { - VillagerRegistry.VillagerProfession profession = ForgeRegistries.VILLAGER_PROFESSIONS.getValue(PROFESSION_LIST[professionID]); - if (profession == null) { - throw new IllegalStateException("No villager profession registered for " + PROFESSION_LIST[professionID]); - } - VillagerRegistry.VillagerCareer career = profession.getCareer(careerID - 1); - career.addTrade(tradeLevel, trades); - } + private static int randomPrice(Random random, int min, int max) { + return min + random.nextInt(max - min + 1); + } + + private static MerchantOffer offer(int emeralds, ItemStack output) { + return new MerchantOffer(new ItemStack(net.minecraft.item.Items.EMERALD, emeralds), output, 7, 1, 0.0F); + } } diff --git a/src/main/java/zone/moddev/mc/steamadvantage/items/MusketItem.java b/src/main/java/zone/moddev/mc/steamadvantage/items/MusketItem.java index 34b2780..7d437c8 100644 --- a/src/main/java/zone/moddev/mc/steamadvantage/items/MusketItem.java +++ b/src/main/java/zone/moddev/mc/steamadvantage/items/MusketItem.java @@ -11,29 +11,29 @@ import zone.moddev.mc.steamadvantage.SteamAdvantage; import zone.moddev.mc.steamadvantage.init.Enchantments; import zone.moddev.mc.steamadvantage.init.Power; -import net.minecraft.block.BlockTNT; +import net.minecraft.block.TNTBlock; import net.minecraft.block.SoundType; import net.minecraft.block.material.Material; -import net.minecraft.block.state.IBlockState; +import net.minecraft.block.BlockState; import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.LivingEntity; import net.minecraft.entity.SharedMonsterAttributes; import net.minecraft.entity.ai.attributes.AttributeModifier; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.init.SoundEvents; -import net.minecraft.inventory.EntityEquipmentSlot; -import net.minecraft.item.EnumAction; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.player.ServerPlayerEntity; +import net.minecraft.util.SoundEvents; +import net.minecraft.inventory.EquipmentSlotType; +import net.minecraft.item.UseAction; import net.minecraft.item.IItemPropertyGetter; import net.minecraft.item.ItemStack; import net.minecraft.item.Item; -import net.minecraft.init.Particles; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.network.play.server.SPacketEntityVelocity; +import net.minecraft.particles.ParticleTypes; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.network.play.server.SEntityVelocityPacket; import net.minecraft.util.ActionResult; -import net.minecraft.util.EnumActionResult; -import net.minecraft.util.EnumHand; +import net.minecraft.util.ActionResultType; +import net.minecraft.util.Hand; import net.minecraft.particles.IParticleData; import net.minecraft.util.ResourceLocation; import net.minecraft.util.SoundCategory; @@ -41,11 +41,15 @@ import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.RayTraceResult; -import net.minecraft.util.math.RayTraceFluidMode; +import net.minecraft.util.math.BlockRayTraceResult; +import net.minecraft.util.math.EntityRayTraceResult; +import net.minecraft.util.math.RayTraceContext; import net.minecraft.util.math.Vec3d; import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.TextComponentTranslation; +import net.minecraft.util.text.TranslationTextComponent; import net.minecraft.world.World; +import net.minecraft.world.Explosion; +import net.minecraft.world.server.ServerWorld; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraft.tags.ItemTags; @@ -66,7 +70,7 @@ public MusketItem(Item.Properties properties){ this.addPropertyOverride(new ResourceLocation("loaded"), new IItemPropertyGetter() { @OnlyIn(Dist.CLIENT) - public float call(ItemStack item, World w, EntityLivingBase e) + public float call(ItemStack item, World w, LivingEntity e) { return isLoaded(item) ? 1.0F : 0.0F; } @@ -74,7 +78,7 @@ public float call(ItemStack item, World w, EntityLivingBase e) this.addPropertyOverride(new ResourceLocation("loading"), new IItemPropertyGetter() { @OnlyIn(Dist.CLIENT) - public float call(ItemStack item, World w, EntityLivingBase e) + public float call(ItemStack item, World w, LivingEntity e) { return e != null && e.isHandActive() && e.getActiveItemStack() == item ? 1.0F : 0.0F; } @@ -98,33 +102,33 @@ public int getItemEnchantability(){ } @Override - public EnumAction getUseAction(ItemStack stack){ + public UseAction getUseAction(ItemStack stack){ if(isLoaded(stack)){ - return EnumAction.BOW; + return UseAction.BOW; } else { - return EnumAction.BLOCK; + return UseAction.BLOCK; } } @Override - public ActionResult onItemRightClick(World world, EntityPlayer playerEntity, EnumHand hand){ + public ActionResult onItemRightClick(World world, PlayerEntity playerEntity, Hand hand){ ItemStack srcItemStack = playerEntity.getHeldItem(hand); - if(hand != EnumHand.MAIN_HAND) return ActionResult.newResult(EnumActionResult.PASS,srcItemStack); - if(!hasAmmo(playerEntity, srcItemStack)) return ActionResult.newResult(EnumActionResult.FAIL,srcItemStack); + if(hand != Hand.MAIN_HAND) return ActionResult.newResult(ActionResultType.PASS,srcItemStack); + if(!hasAmmo(playerEntity, srcItemStack)) return ActionResult.newResult(ActionResultType.FAIL,srcItemStack); if(isNotLoaded(srcItemStack) && EnchantmentHelper.getEnchantmentLevel(Enchantments.rapid_reload, srcItemStack) > 0){ // instant reload decrementAmmo(playerEntity,srcItemStack); startLoad(srcItemStack); playSound(SoundEvents.BLOCK_LEVER_CLICK,world,playerEntity); finishLoad(srcItemStack); - return ActionResult.newResult(EnumActionResult.SUCCESS,srcItemStack); + return ActionResult.newResult(ActionResultType.SUCCESS,srcItemStack); } playerEntity.setActiveHand(hand); - return ActionResult.newResult(EnumActionResult.SUCCESS,srcItemStack); + return ActionResult.newResult(ActionResultType.SUCCESS,srcItemStack); } @Override - public void onUsingTick(ItemStack stack, EntityLivingBase player, int count){ + public void onUsingTick(ItemStack stack, LivingEntity player, int count){ if(player.world.isRemote && count % 7 == 3 && isNotLoaded(stack)){ // indicator to player that the gun is loading player.playSound(SoundType.STONE.getStepSound(), 0.5f, 1.0f); @@ -132,10 +136,10 @@ public void onUsingTick(ItemStack stack, EntityLivingBase player, int count){ } /** * This method is invoked after the item has been used for an amount of time equal to the duration - * provided to the EntityPlayer.setItemInUse(stack, duration). + * provided to the PlayerEntity.setItemInUse(stack, duration). */ @Override - public ItemStack onItemUseFinish (ItemStack srcItemStack, World world, EntityLivingBase playerEntity) + public ItemStack onItemUseFinish (ItemStack srcItemStack, World world, LivingEntity playerEntity) { // if(isNotLoaded(srcItemStack) && hasAmmo(playerEntity,srcItemStack)){ decrementAmmo(playerEntity,srcItemStack); @@ -146,7 +150,7 @@ public ItemStack onItemUseFinish (ItemStack srcItemStack, World world, EntityLiv } @Override - public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityLivingBase playerIn, int timeLeft) { + public void onPlayerStoppedUsing(ItemStack stack, World worldIn, LivingEntity playerIn, int timeLeft) { if(isAlmostLoaded(stack)){ finishLoad(stack); } else if(isLoaded(stack)){ @@ -154,15 +158,15 @@ public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityLivingBas } } - protected void fire(ItemStack srcItemStack, EntityLivingBase playerEntity, + protected void fire(ItemStack srcItemStack, LivingEntity playerEntity, World world) { - final boolean isPlayer = playerEntity instanceof EntityPlayer; + final boolean isPlayer = playerEntity instanceof PlayerEntity; unload(srcItemStack); - if(isPlayer && !((EntityPlayer)playerEntity).isCreative()){ - srcItemStack.damageItem(1, playerEntity); + if(isPlayer && !((PlayerEntity)playerEntity).isCreative()){ + srcItemStack.damageItem(1, playerEntity, entity -> entity.sendBreakAnimation(EquipmentSlotType.MAINHAND)); } Vec3d lookVector = playerEntity.getLookVec(); - spawnParticle(Particles.EXPLOSION_EMITTER, world, + spawnParticle(ParticleTypes.EXPLOSION_EMITTER, world, playerEntity.posX+lookVector.x, playerEntity.posY+playerEntity.getEyeHeight()+lookVector.y, playerEntity.posZ + lookVector.z); if(world.isRemote){ playerEntity.rotationPitch -= 15; @@ -179,60 +183,60 @@ protected void fire(ItemStack srcItemStack, EntityLivingBase playerEntity, return; } final float explodeFactor = 0.75f; - if(rayTrace.type == RayTraceResult.Type.ENTITY && rayTrace.entity != null){ - Entity e = rayTrace.entity; + if(rayTrace instanceof EntityRayTraceResult){ + Entity e = ((EntityRayTraceResult) rayTrace).getEntity(); e.attackEntityFrom(Power.musket_damage, getShotDamage()); if(EnchantmentHelper.getEnchantmentLevel(Enchantments.high_explosive, srcItemStack) > 0){ int lvl = EnchantmentHelper.getEnchantmentLevel(Enchantments.high_explosive, srcItemStack); world.createExplosion(playerEntity, e.posX, e.posY+0.5, e.posZ, explodeFactor * lvl, - true); + Explosion.Mode.BREAK); AxisAlignedBB fireArea = new AxisAlignedBB(e.posX-lvl, e.posY-lvl, e.posZ-lvl, e.posX+lvl, e.posY+lvl, e.posZ+lvl); - List collateralDamage = world.getEntitiesWithinAABB(EntityLivingBase.class, fireArea); - for(EntityLivingBase victim : collateralDamage){ + List collateralDamage = world.getEntitiesWithinAABB(LivingEntity.class, fireArea); + for(LivingEntity victim : collateralDamage){ victim.setFire(lvl); } } - } else if(rayTrace.type == RayTraceResult.Type.BLOCK){ - playSoundAtPosition(rayTrace.hitVec.x, rayTrace.hitVec.y, rayTrace.hitVec.z, + } else if(rayTrace.getType() == RayTraceResult.Type.BLOCK){ + playSoundAtPosition(rayTrace.getHitVec().x, rayTrace.getHitVec().y, rayTrace.getHitVec().z, SoundEvents.BLOCK_GRAVEL_HIT, SoundCategory.BLOCKS, 1f, 1f, world); - BlockPos coord = rayTrace.getBlockPos(); + BlockPos coord = ((BlockRayTraceResult) rayTrace).getPos(); if(coord.getY()>= 0 && coord.getY() <= 255 && !world.isAirBlock(coord)){ - IBlockState bs = world.getBlockState(coord); + BlockState bs = world.getBlockState(coord); Material blockMat = bs.getBlock().getMaterial(bs); if(blockMat == net.minecraft.block.material.Material.GLASS || blockMat == net.minecraft.block.material.Material.LEAVES - || blockMat == net.minecraft.block.material.Material.CIRCUITS + || blockMat == net.minecraft.block.material.Material.MISCELLANEOUS || blockMat == net.minecraft.block.material.Material.PLANTS - || blockMat == net.minecraft.block.material.Material.VINE + || blockMat == net.minecraft.block.material.Material.TALL_PLANTS || blockMat == net.minecraft.block.material.Material.WEB){ world.destroyBlock(coord, true); } else if (blockMat == net.minecraft.block.material.Material.TNT){ - if(world.getBlockState(coord).getBlock() instanceof BlockTNT){ - ((BlockTNT)world.getBlockState(coord).getBlock()).explode(world, coord); - world.removeBlock(coord); + if(world.getBlockState(coord).getBlock() instanceof TNTBlock){ + TNTBlock.explode(world, coord); + world.removeBlock(coord, false); } } } if(EnchantmentHelper.getEnchantmentLevel(Enchantments.high_explosive, srcItemStack) > 0){ int lvl = EnchantmentHelper.getEnchantmentLevel(Enchantments.high_explosive, srcItemStack); - world.createExplosion(playerEntity, rayTrace.hitVec.x, rayTrace.hitVec.y, rayTrace.hitVec.z, + world.createExplosion(playerEntity, rayTrace.getHitVec().x, rayTrace.getHitVec().y, rayTrace.getHitVec().z, explodeFactor * lvl, - true); - AxisAlignedBB fireArea = new AxisAlignedBB(rayTrace.hitVec.x-lvl, rayTrace.hitVec.y-lvl, rayTrace.hitVec.z-lvl, - rayTrace.hitVec.x+lvl, rayTrace.hitVec.y+lvl, rayTrace.hitVec.z+lvl); - List collateralDamage = world.getEntitiesWithinAABB(EntityLivingBase.class, fireArea); - for(EntityLivingBase victim : collateralDamage){ + Explosion.Mode.BREAK); + AxisAlignedBB fireArea = new AxisAlignedBB(rayTrace.getHitVec().x-lvl, rayTrace.getHitVec().y-lvl, rayTrace.getHitVec().z-lvl, + rayTrace.getHitVec().x+lvl, rayTrace.getHitVec().y+lvl, rayTrace.getHitVec().z+lvl); + List collateralDamage = world.getEntitiesWithinAABB(LivingEntity.class, fireArea); + for(LivingEntity victim : collateralDamage){ victim.setFire(lvl); } } } - if(rayTrace.type != RayTraceResult.Type.MISS && rayTrace.hitVec != null){ - spawnParticle(Particles.LARGE_SMOKE, world, - rayTrace.hitVec.x, rayTrace.hitVec.y, rayTrace.hitVec.z); - spawnParticle(Particles.EXPLOSION, world, - rayTrace.hitVec.x, rayTrace.hitVec.y, rayTrace.hitVec.z); + if(rayTrace.getType() != RayTraceResult.Type.MISS){ + spawnParticle(ParticleTypes.LARGE_SMOKE, world, + rayTrace.getHitVec().x, rayTrace.getHitVec().y, rayTrace.getHitVec().z); + spawnParticle(ParticleTypes.EXPLOSION, world, + rayTrace.getHitVec().x, rayTrace.getHitVec().y, rayTrace.getHitVec().z); } // recoil enchantment kicks you back @@ -243,24 +247,26 @@ protected void fire(ItemStack srcItemStack, EntityLivingBase playerEntity, playerEntity.addVelocity(c * recoil * lookVector.x * lateral, c * recoil * lookVector.y, c * recoil * lookVector.z * lateral); - if(!world.isRemote){ + if(playerEntity instanceof ServerPlayerEntity){ // send update packet from server - ((EntityPlayerMP) playerEntity).connection.sendPacket(new SPacketEntityVelocity(playerEntity)); + ((ServerPlayerEntity) playerEntity).connection.sendPacket(new SEntityVelocityPacket(playerEntity)); } } } private void spawnParticle(IParticleData p, World w, double x, double y, double z) { - w.spawnParticle(p, - x, y, z, - 0f, 0f, 0f); + if(w instanceof ServerWorld) { + ((ServerWorld) w).spawnParticle(p, x, y, z, 1, 0, 0, 0, 0); + } else { + w.addParticle(p, x, y, z, 0, 0, 0); + } } @Override - public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker) + public boolean hitEntity(ItemStack stack, LivingEntity target, LivingEntity attacker) { - stack.damageItem(1, attacker); + stack.damageItem(1, attacker, entity -> entity.sendBreakAnimation(EquipmentSlotType.MAINHAND)); return true; } @@ -273,63 +279,63 @@ protected void playSound(SoundEvent sound, World world, Entity e){ } public static void startLoad(ItemStack musket){ - NBTTagCompound data; + CompoundNBT data; if(musket.hasTag()){ data = musket.getTag(); } else { - data = new NBTTagCompound(); + data = new CompoundNBT(); } - data.setByte(NBT_DATA_KEY_LOADED, (byte)2); + data.putByte(NBT_DATA_KEY_LOADED, (byte)2); musket.setTag(data); } public static void finishLoad(ItemStack musket){ - NBTTagCompound data; + CompoundNBT data; if(musket.hasTag()){ data = musket.getTag(); } else { - data = new NBTTagCompound(); + data = new CompoundNBT(); } - data.setByte(NBT_DATA_KEY_LOADED, (byte)1); + data.putByte(NBT_DATA_KEY_LOADED, (byte)1); musket.setTag(data); } public static void unload(ItemStack musket){ - NBTTagCompound data; + CompoundNBT data; if(musket.hasTag()){ data = musket.getTag(); } else { - data = new NBTTagCompound(); + data = new CompoundNBT(); } - data.setByte(NBT_DATA_KEY_LOADED, (byte)0); + data.putByte(NBT_DATA_KEY_LOADED, (byte)0); musket.setTag(data); } public static boolean isLoaded(ItemStack musket){ - NBTTagCompound data = musket.getTag(); + CompoundNBT data = musket.getTag(); if(data == null) return false; - return data.hasKey(NBT_DATA_KEY_LOADED) && data.getByte(NBT_DATA_KEY_LOADED) == 1; + return data.contains(NBT_DATA_KEY_LOADED) && data.getByte(NBT_DATA_KEY_LOADED) == 1; } public static boolean isNotLoaded(ItemStack musket){ - NBTTagCompound data = musket.getTag(); - if(data == null || !data.hasKey(NBT_DATA_KEY_LOADED)) return true; - return data.hasKey(NBT_DATA_KEY_LOADED) && data.getByte(NBT_DATA_KEY_LOADED) == 0; + CompoundNBT data = musket.getTag(); + if(data == null || !data.contains(NBT_DATA_KEY_LOADED)) return true; + return data.contains(NBT_DATA_KEY_LOADED) && data.getByte(NBT_DATA_KEY_LOADED) == 0; } public static boolean isAlmostLoaded(ItemStack musket){ - NBTTagCompound data = musket.getTag(); + CompoundNBT data = musket.getTag(); if(data == null) return false; - return data.hasKey(NBT_DATA_KEY_LOADED) && data.getByte(NBT_DATA_KEY_LOADED) == 2; + return data.contains(NBT_DATA_KEY_LOADED) && data.getByte(NBT_DATA_KEY_LOADED) == 2; } - public static boolean hasAmmo(EntityLivingBase e, ItemStack musket) { - if(e instanceof EntityPlayer) { - EntityPlayer playerEntity = (EntityPlayer) e; + public static boolean hasAmmo(LivingEntity e, ItemStack musket) { + if(e instanceof PlayerEntity) { + PlayerEntity playerEntity = (PlayerEntity) e; if (playerEntity.isCreative() - || EnchantmentHelper.getEnchantmentLevel(net.minecraft.init.Enchantments.INFINITY, musket) > 0 + || EnchantmentHelper.getEnchantmentLevel(net.minecraft.enchantment.Enchantments.INFINITY, musket) > 0 || EnchantmentHelper.getEnchantmentLevel(Enchantments.powderless, musket) > 0) return true; for (int i = 0; i < playerEntity.inventory.mainInventory.size(); i++) { ItemStack inventoryStack = playerEntity.inventory.mainInventory.get(i); @@ -341,11 +347,11 @@ public static boolean hasAmmo(EntityLivingBase e, ItemStack musket) { } - public static void decrementAmmo(EntityLivingBase e, ItemStack musket) { - if(e instanceof EntityPlayer) { - EntityPlayer playerEntity = (EntityPlayer) e; + public static void decrementAmmo(LivingEntity e, ItemStack musket) { + if(e instanceof PlayerEntity) { + PlayerEntity playerEntity = (PlayerEntity) e; if (playerEntity.isCreative() - || EnchantmentHelper.getEnchantmentLevel(net.minecraft.init.Enchantments.INFINITY, musket) > 0 + || EnchantmentHelper.getEnchantmentLevel(net.minecraft.enchantment.Enchantments.INFINITY, musket) > 0 || EnchantmentHelper.getEnchantmentLevel(Enchantments.powderless, musket) > 0) return; for (int i = 0; i < playerEntity.inventory.mainInventory.size(); i++) { ItemStack inventoryStack = playerEntity.inventory.mainInventory.get(i); @@ -360,7 +366,7 @@ public static void decrementAmmo(EntityLivingBase e, ItemStack musket) { } - public static RayTraceResult rayTraceBlocksAndEntities(World w, double maxRange, EntityLivingBase source){ + public static RayTraceResult rayTraceBlocksAndEntities(World w, double maxRange, LivingEntity source){ double rangeSqr = maxRange * maxRange; Vec3d rayOrigin = new Vec3d(source.posX, source.posY + source.getEyeHeight(), source.posZ); Vec3d rayDirection = source.getLookVec(); @@ -386,10 +392,11 @@ public static RayTraceResult rayTraceBlocksAndEntities(World w, double maxRange, } } if(closestEntity == null) { - return w.rayTraceBlocks(rayOrigin, rayOrigin.add(mul(rayDirection, maxRange)), RayTraceFluidMode.SOURCE_ONLY, false, false); + return w.rayTraceBlocks(new RayTraceContext(rayOrigin, rayOrigin.add(mul(rayDirection, maxRange)), + RayTraceContext.BlockMode.COLLIDER, RayTraceContext.FluidMode.SOURCE_ONLY, source)); } else { Vec3d pos = new Vec3d(closestEntity.posX, closestEntity.posY+closestEntity.getEyeHeight(), closestEntity.posZ); - RayTraceResult entityCollision = new RayTraceResult(closestEntity, pos); + RayTraceResult entityCollision = new EntityRayTraceResult(closestEntity, pos); return entityCollision; } } @@ -446,22 +453,22 @@ private static double min(double a, double b){ @Override public void addInformation(ItemStack stack, World world, List list, net.minecraft.client.util.ITooltipFlag flag){ super.addInformation(stack,world,list,flag); - list.add(new TextComponentTranslation("tooltip.musket.damage", (int)MusketItem.getShotDamage())); + list.add(new TranslationTextComponent("tooltip.musket.damage", (int)MusketItem.getShotDamage())); if(isLoaded(stack)){ - list.add(new TextComponentTranslation("tooltip.musket.loaded")); + list.add(new TranslationTextComponent("tooltip.musket.loaded")); } else { - list.add(new TextComponentTranslation("tooltip.musket.unloaded")); - list.add(new TextComponentTranslation("tooltip.musket.ammo", new TextComponentTranslation("item.steamadvantage.blackpowder_cartridge"))); + list.add(new TranslationTextComponent("tooltip.musket.unloaded")); + list.add(new TranslationTextComponent("tooltip.musket.ammo", new TranslationTextComponent("item.steamadvantage.blackpowder_cartridge"))); } } /** Sets melee attack damage */ @Override - public Multimap getAttributeModifiers(EntityEquipmentSlot slot, ItemStack stack) + public Multimap getAttributeModifiers(EquipmentSlotType slot, ItemStack stack) { Multimap multimap = HashMultimap.create(); - if(slot != EntityEquipmentSlot.MAINHAND) return multimap; - multimap.put(SharedMonsterAttributes.ATTACK_DAMAGE.getName(), new AttributeModifier(ATTACK_DAMAGE_MODIFIER, "Weapon modifier", (double)getMeleeDamage(), 0)); + if(slot != EquipmentSlotType.MAINHAND) return multimap; + multimap.put(SharedMonsterAttributes.ATTACK_DAMAGE.getName(), new AttributeModifier(ATTACK_DAMAGE_MODIFIER, "Weapon modifier", (double)getMeleeDamage(), AttributeModifier.Operation.ADDITION)); return multimap; } diff --git a/src/main/java/zone/moddev/mc/steamadvantage/machines/BlastFurnaceBlock.java b/src/main/java/zone/moddev/mc/steamadvantage/machines/BlastFurnaceBlock.java index d049813..a25374d 100644 --- a/src/main/java/zone/moddev/mc/steamadvantage/machines/BlastFurnaceBlock.java +++ b/src/main/java/zone/moddev/mc/steamadvantage/machines/BlastFurnaceBlock.java @@ -4,7 +4,7 @@ import cyano.poweradvantage.api.PoweredEntity; import zone.moddev.mc.steamadvantage.init.Power; import net.minecraft.block.material.Material; -import net.minecraft.block.state.IBlockState; +import net.minecraft.block.BlockState; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -26,12 +26,12 @@ public PoweredEntity createNewTileEntity(net.minecraft.world.IBlockReader world) } @Override - public boolean hasComparatorInputOverride(IBlockState bs) { + public boolean hasComparatorInputOverride(BlockState bs) { return true; } @Override - public int getComparatorInputOverride(IBlockState bs, World world, BlockPos coord) { + public int getComparatorInputOverride(BlockState bs, World world, BlockPos coord) { if(world.getTileEntity(coord) instanceof BlastFurnaceTileEntity){ return ((BlastFurnaceTileEntity)world.getTileEntity(coord)).getComparatorOutput(); } diff --git a/src/main/java/zone/moddev/mc/steamadvantage/machines/BlastFurnaceTileEntity.java b/src/main/java/zone/moddev/mc/steamadvantage/machines/BlastFurnaceTileEntity.java index df77562..2ab9d80 100644 --- a/src/main/java/zone/moddev/mc/steamadvantage/machines/BlastFurnaceTileEntity.java +++ b/src/main/java/zone/moddev/mc/steamadvantage/machines/BlastFurnaceTileEntity.java @@ -2,16 +2,16 @@ import cyano.poweradvantage.api.ConduitType; import zone.moddev.mc.steamadvantage.init.Power; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.SoundEvents; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.util.SoundEvents; import net.minecraft.item.ItemStack; -import net.minecraft.inventory.InventoryBasic; +import net.minecraft.inventory.Inventory; import net.minecraft.item.crafting.IRecipe; -import net.minecraft.util.text.TextComponentString; -import net.minecraftforge.common.crafting.VanillaRecipeTypes; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntityFurnace; -import net.minecraft.util.EnumFacing; +import net.minecraft.util.text.StringTextComponent; +import net.minecraft.item.crafting.IRecipeType; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.tileentity.AbstractFurnaceTileEntity; +import net.minecraft.util.Direction; import net.minecraft.util.SoundCategory; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -252,17 +252,17 @@ public void onDataFieldUpdate() { @Override - public NBTTagCompound write(NBTTagCompound tagRoot){ + public CompoundNBT write(CompoundNBT tagRoot){ super.write(tagRoot); prepareDataFieldsForSync(); - tagRoot.setIntArray("Data", getDataFieldArray()); + tagRoot.putIntArray("Data", getDataFieldArray()); return tagRoot; } @Override - public void read(NBTTagCompound tagRoot){ + public void read(CompoundNBT tagRoot){ super.read(tagRoot); - if(tagRoot.hasKey("Data")){ + if(tagRoot.contains("Data")){ int[] data = tagRoot.getIntArray("Data"); System.arraycopy(data, 0, this.getDataFieldArray(), 0, Math.min(data.length,this.getDataFieldArray().length)); onDataFieldUpdate(); @@ -284,17 +284,17 @@ public int getComparatorOutput() { ///// Item Handling (for hoppers) ///// @Override - public int[] getSlotsForFace(EnumFacing side) { + public int[] getSlotsForFace(Direction side) { return allSlots; } @Override - public boolean canExtractItem(final int slot, final ItemStack targetItem, final EnumFacing side) { + public boolean canExtractItem(final int slot, final ItemStack targetItem, final Direction side) { return slot >= 4 && slot < this.getInventory().length; } @Override - public boolean canInsertItem(final int slot, final ItemStack srcItem, final EnumFacing side) { + public boolean canInsertItem(final int slot, final ItemStack srcItem, final Direction side) { return this.isItemValidForSlot(slot, srcItem) && slot <= 3; } @@ -318,10 +318,10 @@ public boolean isItemValidForSlot(final int slot, final ItemStack item) { private ItemStack getSmeltingResult(ItemStack input) { if (input == null || input.isEmpty() || getWorld() == null) return ItemStack.EMPTY; - InventoryBasic inventory = new InventoryBasic(new TextComponentString("steamadvantage.smelting"), 1); + Inventory inventory = new Inventory(1); inventory.setInventorySlotContents(0, input); - IRecipe recipe = getWorld().getRecipeManager().getRecipe(inventory, getWorld(), VanillaRecipeTypes.SMELTING); - return recipe == null ? ItemStack.EMPTY : recipe.getCraftingResult(inventory); + return getWorld().getRecipeManager().getRecipe(IRecipeType.SMELTING, inventory, getWorld()) + .map(recipe -> recipe.getCraftingResult(inventory)).orElse(ItemStack.EMPTY); } @@ -336,7 +336,7 @@ public boolean isPowerSource(ConduitType powerType) { } @Override - public boolean isUsableByPlayer(EntityPlayer player) { + public boolean isUsableByPlayer(PlayerEntity player) { return true; } } diff --git a/src/main/java/zone/moddev/mc/steamadvantage/machines/CoalBoilerBlock.java b/src/main/java/zone/moddev/mc/steamadvantage/machines/CoalBoilerBlock.java index aec3569..3369b94 100644 --- a/src/main/java/zone/moddev/mc/steamadvantage/machines/CoalBoilerBlock.java +++ b/src/main/java/zone/moddev/mc/steamadvantage/machines/CoalBoilerBlock.java @@ -6,7 +6,7 @@ import zone.moddev.mc.poweradvantage.init.Fluids; import zone.moddev.mc.steamadvantage.init.Power; import net.minecraft.block.material.Material; -import net.minecraft.block.state.IBlockState; +import net.minecraft.block.BlockState; import net.minecraft.util.math.BlockPos; import net.minecraft.world.Explosion; import net.minecraft.world.World; @@ -31,12 +31,12 @@ public PoweredEntity createNewTileEntity(net.minecraft.world.IBlockReader world) } @Override - public boolean hasComparatorInputOverride(IBlockState bs) { + public boolean hasComparatorInputOverride(BlockState bs) { return true; } @Override - public int getComparatorInputOverride(IBlockState bs, World world, BlockPos coord) { + public int getComparatorInputOverride(BlockState bs, World world, BlockPos coord) { if(world.getTileEntity(coord) instanceof CoalBoilerTileEntity){ return ((CoalBoilerTileEntity)world.getTileEntity(coord)).getComparatorOutput(); } diff --git a/src/main/java/zone/moddev/mc/steamadvantage/machines/CoalBoilerTileEntity.java b/src/main/java/zone/moddev/mc/steamadvantage/machines/CoalBoilerTileEntity.java index f94468a..04d835a 100644 --- a/src/main/java/zone/moddev/mc/steamadvantage/machines/CoalBoilerTileEntity.java +++ b/src/main/java/zone/moddev/mc/steamadvantage/machines/CoalBoilerTileEntity.java @@ -7,12 +7,12 @@ import cyano.poweradvantage.api.fluid.FluidRequest; import zone.moddev.mc.poweradvantage.init.Fluids; import zone.moddev.mc.steamadvantage.init.Power; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.SoundEvents; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.util.SoundEvents; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntityFurnace; -import net.minecraft.util.EnumFacing; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.tileentity.AbstractFurnaceTileEntity; +import net.minecraft.util.Direction; import net.minecraft.util.SoundCategory; import net.minecraft.fluid.Fluid; @@ -190,7 +190,7 @@ public void prepareDataFieldsForSync() { @Override public void onDataFieldUpdate() { this.setEnergy(Float.intBitsToFloat(dataSyncArray[0]), Power.steam_power); - this.getTank().setFluid(new FluidStack(net.minecraft.init.Fluids.WATER,dataSyncArray[1])); + this.getTank().setFluid(new FluidStack(net.minecraft.fluid.Fluids.WATER,dataSyncArray[1])); this.burnTime = dataSyncArray[2]; this.totalBurnTime = dataSyncArray[3]; } @@ -201,13 +201,13 @@ public void onDataFieldUpdate() { * @param tagRoot An NBT tag */ @Override - public NBTTagCompound write(final NBTTagCompound tagRoot) { + public CompoundNBT write(final CompoundNBT tagRoot) { super.write(tagRoot); - NBTTagCompound tankTag = new NBTTagCompound(); + CompoundNBT tankTag = new CompoundNBT(); this.getTank().writeToNBT(tankTag); - tagRoot.setTag("Tank", tankTag); - if(this.burnTime > 0)tagRoot.setInt("BurnTime", this.burnTime); - if(this.totalBurnTime > 0)tagRoot.setInt("BurnTimeTotal", this.totalBurnTime); + tagRoot.put("Tank", tankTag); + if(this.burnTime > 0)tagRoot.putInt("BurnTime", this.burnTime); + if(this.totalBurnTime > 0)tagRoot.putInt("BurnTimeTotal", this.totalBurnTime); return tagRoot; } /** @@ -215,22 +215,22 @@ public NBTTagCompound write(final NBTTagCompound tagRoot) { * @param tagRoot An NBT tag */ @Override - public void read(final NBTTagCompound tagRoot) { + public void read(final CompoundNBT tagRoot) { super.read(tagRoot); - if (tagRoot.hasKey("Tank")) { - NBTTagCompound tankTag = tagRoot.getCompound("Tank"); + if (tagRoot.contains("Tank")) { + CompoundNBT tankTag = tagRoot.getCompound("Tank"); getTank().readFromNBT(tankTag); - if(tankTag.hasKey("Empty")){ + if(tankTag.contains("Empty")){ // empty the tank if NBT says its empty (not default behavior of Tank.read(...) ) getTank().setFluid(null); } } - if(tagRoot.hasKey("BurnTime")){ + if(tagRoot.contains("BurnTime")){ this.burnTime = tagRoot.getInt("BurnTime"); } else { this.burnTime = 0; } - if(tagRoot.hasKey("BurnTimeTotal")){ + if(tagRoot.contains("BurnTimeTotal")){ this.totalBurnTime = tagRoot.getInt("BurnTimeTotal"); } else { this.totalBurnTime = 0; @@ -264,13 +264,13 @@ public boolean isPowerSource(ConduitType type){ @Override public float addEnergy(float amount, ConduitType type){ if(Fluids.isFluidType(type)){ - if(Fluids.conduitTypeToFluid(type) == net.minecraft.init.Fluids.WATER){ + if(Fluids.conduitTypeToFluid(type) == net.minecraft.fluid.Fluids.WATER){ if(this.canFill(null, Fluids.conduitTypeToFluid(type))){ return this.fill(null, new FluidStack(Fluids.conduitTypeToFluid(type),(int)amount), true); } else { return 0; } - } else if(Fluids.conduitTypeToFluid(type) == net.minecraft.init.Fluids.LAVA){ + } else if(Fluids.conduitTypeToFluid(type) == net.minecraft.fluid.Fluids.LAVA){ burnTime += (int)(amount * LAVA_TO_BURN_TICKS); totalBurnTime = (int)(LAVA_REQUEST_SIZE * LAVA_TO_BURN_TICKS); return amount; @@ -316,12 +316,12 @@ public float subtractEnergy(float amount, ConduitType type){ @Override public PowerRequest getPowerRequest(ConduitType offer) { - if(Fluids.conduitTypeToFluid(offer) == net.minecraft.init.Fluids.WATER){ + if(Fluids.conduitTypeToFluid(offer) == net.minecraft.fluid.Fluids.WATER){ PowerRequest request = new FluidRequest(FluidRequest.MEDIUM_PRIORITY+1, (getTank().getCapacity() - getTank().getFluidAmount()), this); return request; - } else if(Fluids.conduitTypeToFluid(offer) == net.minecraft.init.Fluids.LAVA + } else if(Fluids.conduitTypeToFluid(offer) == net.minecraft.fluid.Fluids.LAVA && burnTime <= 0 && getFuelBurnTime() <= 0 && getTank().getFluidAmount() > 0 && !redstone){ @@ -348,7 +348,7 @@ && getTank().getFluidAmount() > 0 * @param forReal if true, then the fluid in the tank will change */ @Override - public int fill(EnumFacing face, FluidStack fluid, boolean forReal) { + public int fill(Direction face, FluidStack fluid, boolean forReal) { if(getTank().getFluidAmount() <= 0 || getTank().getFluid().getFluid().equals(fluid.getFluid())){ return getTank().fill(fluid, forReal); } else { @@ -362,7 +362,7 @@ public int fill(EnumFacing face, FluidStack fluid, boolean forReal) { * @param forReal if true, then the fluid in the tank will change */ @Override - public FluidStack drain(EnumFacing face, FluidStack fluid, boolean forReal) { + public FluidStack drain(Direction face, FluidStack fluid, boolean forReal) { if(getTank().getFluidAmount() > 0 && getTank().getFluid().getFluid().equals(fluid.getFluid())){ return getTank().drain(fluid.amount,forReal); } else { @@ -376,7 +376,7 @@ public FluidStack drain(EnumFacing face, FluidStack fluid, boolean forReal) { * @param forReal if true, then the fluid in the tank will change */ @Override - public FluidStack drain(EnumFacing face, int amount, boolean forReal) { + public FluidStack drain(Direction face, int amount, boolean forReal) { if(getTank().getFluidAmount() > 0 ){ return getTank().drain(amount,forReal); } else { @@ -389,8 +389,8 @@ public FluidStack drain(EnumFacing face, int amount, boolean forReal) { * @param fluid The fluid being added/removed */ @Override - public boolean canFill(EnumFacing face, Fluid fluid) { - if(fluid != net.minecraft.init.Fluids.WATER) return false; + public boolean canFill(Direction face, Fluid fluid) { + if(fluid != net.minecraft.fluid.Fluids.WATER) return false; if(getTank().getFluid() == null) return true; return getTank().getFluidAmount() <= getTank().getCapacity() && fluid.equals(getTank().getFluid().getFluid()); } @@ -400,7 +400,7 @@ public boolean canFill(EnumFacing face, Fluid fluid) { * @param fluid The fluid being added/removed */ @Override - public boolean canDrain(EnumFacing face, Fluid fluid) { + public boolean canDrain(Direction face, Fluid fluid) { if(getTank().getFluid() == null) return false; return getTank().getFluidAmount() > 0 && fluid.equals(getTank().getFluid().getFluid()); } @@ -411,7 +411,7 @@ public boolean canDrain(EnumFacing face, Fluid fluid) { * @return array of FluidTankInfo describing all of the FluidTanks */ @Override - public FluidTankInfo[] getTankInfo(EnumFacing face) { + public FluidTankInfo[] getTankInfo(Direction face) { FluidTankInfo[] arr = new FluidTankInfo[1]; arr[0] = getTank().getInfo(); return arr; @@ -425,7 +425,7 @@ public boolean isItemValidForSlot(final int slot, final ItemStack item) { } @Override - public boolean isUsableByPlayer(EntityPlayer player) { + public boolean isUsableByPlayer(PlayerEntity player) { return true; } } diff --git a/src/main/java/zone/moddev/mc/steamadvantage/machines/ElectricBoilerBlock.java b/src/main/java/zone/moddev/mc/steamadvantage/machines/ElectricBoilerBlock.java index 3a80788..a892f61 100644 --- a/src/main/java/zone/moddev/mc/steamadvantage/machines/ElectricBoilerBlock.java +++ b/src/main/java/zone/moddev/mc/steamadvantage/machines/ElectricBoilerBlock.java @@ -6,7 +6,7 @@ import zone.moddev.mc.poweradvantage.init.Fluids; import zone.moddev.mc.steamadvantage.init.Power; import net.minecraft.block.material.Material; -import net.minecraft.block.state.IBlockState; +import net.minecraft.block.BlockState; import net.minecraft.util.math.BlockPos; import net.minecraft.world.Explosion; import net.minecraft.world.World; @@ -26,12 +26,12 @@ public PoweredEntity createNewTileEntity(net.minecraft.world.IBlockReader world) } @Override - public boolean hasComparatorInputOverride(IBlockState bs) { + public boolean hasComparatorInputOverride(BlockState bs) { return true; } @Override - public int getComparatorInputOverride(IBlockState bs, World world, BlockPos coord) { + public int getComparatorInputOverride(BlockState bs, World world, BlockPos coord) { if(world.getTileEntity(coord) instanceof ElectricBoilerTileEntity){ return ((ElectricBoilerTileEntity)world.getTileEntity(coord)).getComparatorOutput(); } diff --git a/src/main/java/zone/moddev/mc/steamadvantage/machines/ElectricBoilerTileEntity.java b/src/main/java/zone/moddev/mc/steamadvantage/machines/ElectricBoilerTileEntity.java index cfbfb33..a40d441 100644 --- a/src/main/java/zone/moddev/mc/steamadvantage/machines/ElectricBoilerTileEntity.java +++ b/src/main/java/zone/moddev/mc/steamadvantage/machines/ElectricBoilerTileEntity.java @@ -7,11 +7,11 @@ import cyano.poweradvantage.api.fluid.FluidRequest; import zone.moddev.mc.poweradvantage.init.Fluids; import zone.moddev.mc.steamadvantage.init.Power; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.SoundEvents; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.util.SoundEvents; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.EnumFacing; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.util.Direction; import net.minecraft.util.SoundCategory; import net.minecraft.fluid.Fluid; @@ -84,7 +84,7 @@ private void energyDecay() { } @Override - public boolean isUsableByPlayer(EntityPlayer player) { + public boolean isUsableByPlayer(PlayerEntity player) { return true; } @@ -164,7 +164,7 @@ public void prepareDataFieldsForSync() { @Override public void onDataFieldUpdate() { this.setEnergy(Float.intBitsToFloat(dataSyncArray[0]), Power.steam_power); - this.getTank().setFluid(new FluidStack(net.minecraft.init.Fluids.WATER,dataSyncArray[1])); + this.getTank().setFluid(new FluidStack(net.minecraft.fluid.Fluids.WATER,dataSyncArray[1])); this.setEnergy(Float.intBitsToFloat(dataSyncArray[2]),ELECTRIC_POWER); } @@ -174,12 +174,12 @@ public void onDataFieldUpdate() { * @param tagRoot An NBT tag */ @Override - public NBTTagCompound write(final NBTTagCompound tagRoot) { + public CompoundNBT write(final CompoundNBT tagRoot) { super.write(tagRoot); - NBTTagCompound tankTag = new NBTTagCompound(); + CompoundNBT tankTag = new CompoundNBT(); this.getTank().writeToNBT(tankTag); - tagRoot.setTag("Tank", tankTag); - if(getEnergy(ELECTRIC_POWER) > 0)tagRoot.setFloat("Electricity", getEnergy(ELECTRIC_POWER)); + tagRoot.put("Tank", tankTag); + if(getEnergy(ELECTRIC_POWER) > 0)tagRoot.putFloat("Electricity", getEnergy(ELECTRIC_POWER)); return tagRoot; } /** @@ -187,17 +187,17 @@ public NBTTagCompound write(final NBTTagCompound tagRoot) { * @param tagRoot An NBT tag */ @Override - public void read(final NBTTagCompound tagRoot) { + public void read(final CompoundNBT tagRoot) { super.read(tagRoot); - if (tagRoot.hasKey("Tank")) { - NBTTagCompound tankTag = tagRoot.getCompound("Tank"); + if (tagRoot.contains("Tank")) { + CompoundNBT tankTag = tagRoot.getCompound("Tank"); getTank().readFromNBT(tankTag); - if(tankTag.hasKey("Empty")){ + if(tankTag.contains("Empty")){ // empty the tank if NBT says its empty (not default behavior of Tank.read(...) ) getTank().setFluid(null); } } - if(tagRoot.hasKey("Electricity")){ + if(tagRoot.contains("Electricity")){ this.setEnergy(tagRoot.getFloat("Electricity"),ELECTRIC_POWER); } else { this.setEnergy(0,ELECTRIC_POWER); @@ -229,7 +229,7 @@ public boolean isPowerSource(ConduitType type){ @Override public float addEnergy(float amount, ConduitType type){ if(Fluids.isFluidType(type)){ - if(Fluids.conduitTypeToFluid(type) == net.minecraft.init.Fluids.WATER){ + if(Fluids.conduitTypeToFluid(type) == net.minecraft.fluid.Fluids.WATER){ if(this.canFill(null, Fluids.conduitTypeToFluid(type))){ return this.fill(null, new FluidStack(Fluids.conduitTypeToFluid(type),(int)amount), true); } else { @@ -277,7 +277,7 @@ public float subtractEnergy(float amount, ConduitType type){ @Override public PowerRequest getPowerRequest(ConduitType offer) { - if(Fluids.isFluidType(offer) && Fluids.conduitTypeToFluid(offer) == net.minecraft.init.Fluids.WATER){ + if(Fluids.isFluidType(offer) && Fluids.conduitTypeToFluid(offer) == net.minecraft.fluid.Fluids.WATER){ PowerRequest request = new FluidRequest(FluidRequest.MEDIUM_PRIORITY+1, (getTank().getCapacity() - getTank().getFluidAmount()), this); @@ -300,7 +300,7 @@ public PowerRequest getPowerRequest(ConduitType offer) { * @param forReal if true, then the fluid in the tank will change */ @Override - public int fill(EnumFacing face, FluidStack fluid, boolean forReal) { + public int fill(Direction face, FluidStack fluid, boolean forReal) { if(getTank().getFluidAmount() <= 0 || getTank().getFluid().getFluid().equals(fluid.getFluid())){ return getTank().fill(fluid, forReal); } else { @@ -314,7 +314,7 @@ public int fill(EnumFacing face, FluidStack fluid, boolean forReal) { * @param forReal if true, then the fluid in the tank will change */ @Override - public FluidStack drain(EnumFacing face, FluidStack fluid, boolean forReal) { + public FluidStack drain(Direction face, FluidStack fluid, boolean forReal) { if(getTank().getFluidAmount() > 0 && getTank().getFluid().getFluid().equals(fluid.getFluid())){ return getTank().drain(fluid.amount,forReal); } else { @@ -328,7 +328,7 @@ public FluidStack drain(EnumFacing face, FluidStack fluid, boolean forReal) { * @param forReal if true, then the fluid in the tank will change */ @Override - public FluidStack drain(EnumFacing face, int amount, boolean forReal) { + public FluidStack drain(Direction face, int amount, boolean forReal) { if(getTank().getFluidAmount() > 0 ){ return getTank().drain(amount,forReal); } else { @@ -341,8 +341,8 @@ public FluidStack drain(EnumFacing face, int amount, boolean forReal) { * @param fluid The fluid being added/removed */ @Override - public boolean canFill(EnumFacing face, Fluid fluid) { - if(fluid != net.minecraft.init.Fluids.WATER) return false; + public boolean canFill(Direction face, Fluid fluid) { + if(fluid != net.minecraft.fluid.Fluids.WATER) return false; if(getTank().getFluid() == null) return true; return getTank().getFluidAmount() <= getTank().getCapacity() && fluid.equals(getTank().getFluid().getFluid()); } @@ -352,7 +352,7 @@ public boolean canFill(EnumFacing face, Fluid fluid) { * @param fluid The fluid being added/removed */ @Override - public boolean canDrain(EnumFacing face, Fluid fluid) { + public boolean canDrain(Direction face, Fluid fluid) { if(getTank().getFluid() == null) return false; return getTank().getFluidAmount() > 0 && fluid.equals(getTank().getFluid().getFluid()); } @@ -363,7 +363,7 @@ public boolean canDrain(EnumFacing face, Fluid fluid) { * @return array of FluidTankInfo describing all of the FluidTanks */ @Override - public FluidTankInfo[] getTankInfo(EnumFacing face) { + public FluidTankInfo[] getTankInfo(Direction face) { FluidTankInfo[] arr = new FluidTankInfo[1]; arr[0] = getTank().getInfo(); return arr; diff --git a/src/main/java/zone/moddev/mc/steamadvantage/machines/GeothermalBoilerBlock.java b/src/main/java/zone/moddev/mc/steamadvantage/machines/GeothermalBoilerBlock.java index 9abde1d..488ae45 100644 --- a/src/main/java/zone/moddev/mc/steamadvantage/machines/GeothermalBoilerBlock.java +++ b/src/main/java/zone/moddev/mc/steamadvantage/machines/GeothermalBoilerBlock.java @@ -6,7 +6,7 @@ import zone.moddev.mc.poweradvantage.init.Fluids; import zone.moddev.mc.steamadvantage.init.Power; import net.minecraft.block.material.Material; -import net.minecraft.block.state.IBlockState; +import net.minecraft.block.BlockState; import net.minecraft.util.math.BlockPos; import net.minecraft.world.Explosion; import net.minecraft.world.World; @@ -23,12 +23,12 @@ public PoweredEntity createNewTileEntity(net.minecraft.world.IBlockReader world) } @Override - public boolean hasComparatorInputOverride(IBlockState bs) { + public boolean hasComparatorInputOverride(BlockState bs) { return true; } @Override - public int getComparatorInputOverride(IBlockState bs, World world, BlockPos coord) { + public int getComparatorInputOverride(BlockState bs, World world, BlockPos coord) { if(world.getTileEntity(coord) instanceof GeothermalBoilerTileEntity){ return ((GeothermalBoilerTileEntity)world.getTileEntity(coord)).getComparatorOutput(); } diff --git a/src/main/java/zone/moddev/mc/steamadvantage/machines/GeothermalBoilerTileEntity.java b/src/main/java/zone/moddev/mc/steamadvantage/machines/GeothermalBoilerTileEntity.java index 399b7f7..0f921f6 100644 --- a/src/main/java/zone/moddev/mc/steamadvantage/machines/GeothermalBoilerTileEntity.java +++ b/src/main/java/zone/moddev/mc/steamadvantage/machines/GeothermalBoilerTileEntity.java @@ -8,12 +8,12 @@ import zone.moddev.mc.poweradvantage.init.Fluids; import zone.moddev.mc.steamadvantage.init.Power; import net.minecraft.block.Block; -import net.minecraft.block.state.IBlockState; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.SoundEvents; +import net.minecraft.block.BlockState; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.util.SoundEvents; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.EnumFacing; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.util.Direction; import net.minecraft.util.SoundCategory; import net.minecraft.util.math.BlockPos; import net.minecraft.fluid.Fluid; @@ -48,7 +48,7 @@ public GeothermalBoilerTileEntity() { } @Override - public boolean isUsableByPlayer(EntityPlayer player) { + public boolean isUsableByPlayer(PlayerEntity player) { return true; } @@ -94,7 +94,7 @@ private void energyDecay() { private void updateTemperature(){ float themalInput = 0; - for(EnumFacing f : EnumFacing.values()){ + for(Direction f : Direction.values()){ BlockPos p = getPos().offset(f); if(p.getY() >= 0 && p.getY() < 256){ themalInput += thermalEnergy(getWorld().getBlockState(p)); @@ -105,11 +105,11 @@ private void updateTemperature(){ temperature = Math.max(0, Math.min(MAX_TEMPERATURE, temperature + delta) - 1); } - private static float thermalEnergy(IBlockState bs){ + private static float thermalEnergy(BlockState bs){ Block b = bs.getBlock(); - if(b == net.minecraft.init.Blocks.FIRE){ + if(b == net.minecraft.block.Blocks.FIRE){ return 200; - } else if(bs.getFluidState().getFluid().isEquivalentTo(net.minecraft.init.Fluids.LAVA)) { + } else if(bs.getFluidState().getFluid().isEquivalentTo(net.minecraft.fluid.Fluids.LAVA)) { // Forge 1.13 native fluids no longer expose the old temperature property. return (1300 - 372) * 0.5f; } else { @@ -198,7 +198,7 @@ public void prepareDataFieldsForSync() { @Override public void onDataFieldUpdate() { this.setEnergy(Float.intBitsToFloat(dataSyncArray[0]), Power.steam_power); - this.getTank().setFluid(new FluidStack(net.minecraft.init.Fluids.WATER,dataSyncArray[1])); + this.getTank().setFluid(new FluidStack(net.minecraft.fluid.Fluids.WATER,dataSyncArray[1])); this.temperature = Float.intBitsToFloat(dataSyncArray[2]); } @@ -208,12 +208,12 @@ public void onDataFieldUpdate() { * @param tagRoot An NBT tag */ @Override - public NBTTagCompound write(final NBTTagCompound tagRoot) { + public CompoundNBT write(final CompoundNBT tagRoot) { super.write(tagRoot); - NBTTagCompound tankTag = new NBTTagCompound(); + CompoundNBT tankTag = new CompoundNBT(); this.getTank().writeToNBT(tankTag); - tagRoot.setTag("Tank", tankTag); - if(this.temperature > 0)tagRoot.setFloat("Temperature", this.temperature); + tagRoot.put("Tank", tankTag); + if(this.temperature > 0)tagRoot.putFloat("Temperature", this.temperature); return tagRoot; } /** @@ -221,19 +221,19 @@ public NBTTagCompound write(final NBTTagCompound tagRoot) { * @param tagRoot An NBT tag */ @Override - public void read(final NBTTagCompound tagRoot) { + public void read(final CompoundNBT tagRoot) { super.read(tagRoot); - if (tagRoot.hasKey("Tank")) { - NBTTagCompound tankTag = tagRoot.getCompound("Tank"); + if (tagRoot.contains("Tank")) { + CompoundNBT tankTag = tagRoot.getCompound("Tank"); getTank().readFromNBT(tankTag); - if(tankTag.hasKey("Empty")){ + if(tankTag.contains("Empty")){ // empty the tank if NBT says its empty (not default behavior of Tank.read(...) ) getTank().setFluid(null); } } - if(tagRoot.hasKey("Temperature")){ + if(tagRoot.contains("Temperature")){ this.temperature = tagRoot.getFloat("Temperature"); - } else if(tagRoot.hasKey("Tempoerature")){ + } else if(tagRoot.contains("Tempoerature")){ this.temperature = tagRoot.getFloat("Tempoerature"); } else { this.temperature = 0; @@ -265,7 +265,7 @@ public boolean isPowerSource(ConduitType type){ @Override public float addEnergy(float amount, ConduitType type){ if(Fluids.isFluidType(type)){ - if(Fluids.conduitTypeToFluid(type) == net.minecraft.init.Fluids.WATER){ + if(Fluids.conduitTypeToFluid(type) == net.minecraft.fluid.Fluids.WATER){ if(this.canFill(null, Fluids.conduitTypeToFluid(type))){ return this.fill(null, new FluidStack(Fluids.conduitTypeToFluid(type),(int)amount), true); } else { @@ -313,7 +313,7 @@ public float subtractEnergy(float amount, ConduitType type){ @Override public PowerRequest getPowerRequest(ConduitType offer) { - if(Fluids.conduitTypeToFluid(offer) == net.minecraft.init.Fluids.WATER){ + if(Fluids.conduitTypeToFluid(offer) == net.minecraft.fluid.Fluids.WATER){ PowerRequest request = new FluidRequest(FluidRequest.MEDIUM_PRIORITY+1, (getTank().getCapacity() - getTank().getFluidAmount()), this); @@ -336,7 +336,7 @@ public PowerRequest getPowerRequest(ConduitType offer) { * @param forReal if true, then the fluid in the tank will change */ @Override - public int fill(EnumFacing face, FluidStack fluid, boolean forReal) { + public int fill(Direction face, FluidStack fluid, boolean forReal) { if(getTank().getFluidAmount() <= 0 || getTank().getFluid().getFluid().equals(fluid.getFluid())){ return getTank().fill(fluid, forReal); } else { @@ -350,7 +350,7 @@ public int fill(EnumFacing face, FluidStack fluid, boolean forReal) { * @param forReal if true, then the fluid in the tank will change */ @Override - public FluidStack drain(EnumFacing face, FluidStack fluid, boolean forReal) { + public FluidStack drain(Direction face, FluidStack fluid, boolean forReal) { if(getTank().getFluidAmount() > 0 && getTank().getFluid().getFluid().equals(fluid.getFluid())){ return getTank().drain(fluid.amount,forReal); } else { @@ -364,7 +364,7 @@ public FluidStack drain(EnumFacing face, FluidStack fluid, boolean forReal) { * @param forReal if true, then the fluid in the tank will change */ @Override - public FluidStack drain(EnumFacing face, int amount, boolean forReal) { + public FluidStack drain(Direction face, int amount, boolean forReal) { if(getTank().getFluidAmount() > 0 ){ return getTank().drain(amount,forReal); } else { @@ -377,8 +377,8 @@ public FluidStack drain(EnumFacing face, int amount, boolean forReal) { * @param fluid The fluid being added/removed */ @Override - public boolean canFill(EnumFacing face, Fluid fluid) { - if(fluid != net.minecraft.init.Fluids.WATER) return false; + public boolean canFill(Direction face, Fluid fluid) { + if(fluid != net.minecraft.fluid.Fluids.WATER) return false; if(getTank().getFluid() == null) return true; return getTank().getFluidAmount() <= getTank().getCapacity() && fluid.equals(getTank().getFluid().getFluid()); } @@ -388,7 +388,7 @@ public boolean canFill(EnumFacing face, Fluid fluid) { * @param fluid The fluid being added/removed */ @Override - public boolean canDrain(EnumFacing face, Fluid fluid) { + public boolean canDrain(Direction face, Fluid fluid) { if(getTank().getFluid() == null) return false; return getTank().getFluidAmount() > 0 && fluid.equals(getTank().getFluid().getFluid()); } @@ -399,7 +399,7 @@ public boolean canDrain(EnumFacing face, Fluid fluid) { * @return array of FluidTankInfo describing all of the FluidTanks */ @Override - public FluidTankInfo[] getTankInfo(EnumFacing face) { + public FluidTankInfo[] getTankInfo(Direction face) { FluidTankInfo[] arr = new FluidTankInfo[1]; arr[0] = getTank().getInfo(); return arr; diff --git a/src/main/java/zone/moddev/mc/steamadvantage/machines/OilBoilerBlock.java b/src/main/java/zone/moddev/mc/steamadvantage/machines/OilBoilerBlock.java index c614ddb..4d5de8f 100644 --- a/src/main/java/zone/moddev/mc/steamadvantage/machines/OilBoilerBlock.java +++ b/src/main/java/zone/moddev/mc/steamadvantage/machines/OilBoilerBlock.java @@ -6,7 +6,7 @@ import zone.moddev.mc.poweradvantage.init.Fluids; import zone.moddev.mc.steamadvantage.init.Power; import net.minecraft.block.material.Material; -import net.minecraft.block.state.IBlockState; +import net.minecraft.block.BlockState; import net.minecraft.util.math.BlockPos; import net.minecraft.world.Explosion; import net.minecraft.world.World; @@ -31,12 +31,12 @@ public PoweredEntity createNewTileEntity(net.minecraft.world.IBlockReader world) } @Override - public boolean hasComparatorInputOverride(IBlockState bs) { + public boolean hasComparatorInputOverride(BlockState bs) { return true; } @Override - public int getComparatorInputOverride(IBlockState bs, World world, BlockPos coord) { + public int getComparatorInputOverride(BlockState bs, World world, BlockPos coord) { if(world.getTileEntity(coord) instanceof OilBoilerTileEntity){ return ((OilBoilerTileEntity)world.getTileEntity(coord)).getComparatorOutput(); } diff --git a/src/main/java/zone/moddev/mc/steamadvantage/machines/OilBoilerTileEntity.java b/src/main/java/zone/moddev/mc/steamadvantage/machines/OilBoilerTileEntity.java index b3f8684..3905166 100644 --- a/src/main/java/zone/moddev/mc/steamadvantage/machines/OilBoilerTileEntity.java +++ b/src/main/java/zone/moddev/mc/steamadvantage/machines/OilBoilerTileEntity.java @@ -12,14 +12,14 @@ import zone.moddev.mc.poweradvantage.registry.FuelRegistry; import zone.moddev.mc.steamadvantage.SteamAdvantage; import zone.moddev.mc.steamadvantage.init.Power; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.SoundEvents; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.util.SoundEvents; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.EnumFacing; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.util.Direction; import net.minecraft.util.SoundCategory; import net.minecraft.util.ResourceLocation; -import net.minecraft.util.registry.IRegistry; +import net.minecraft.util.registry.Registry; import net.minecraft.fluid.Fluid; import cyano.poweradvantage.api.fluid.FluidStack; import cyano.poweradvantage.api.fluid.FluidTank; @@ -88,7 +88,7 @@ public void tickUpdate(boolean isServerWorld) { } @Override - public boolean isUsableByPlayer(EntityPlayer player) { + public boolean isUsableByPlayer(PlayerEntity player) { return true; } @@ -121,7 +121,7 @@ private static Float getBurnTimePerBucketFor(Fluid fluid){ } // second, check universal bucket fuel registry int vol = FluidTank.BUCKET_VOLUME; - ItemStack bucket = fluid.getFilledBucket() == net.minecraft.init.Items.AIR + ItemStack bucket = fluid.getFilledBucket() == net.minecraft.item.Items.AIR ? ItemStack.EMPTY : new ItemStack(fluid.getFilledBucket()); if(bucket.isEmpty()){ flammibilityCache.put(fluid,0f); @@ -143,7 +143,7 @@ private static Float getBurnTimePerBucketFor(Fluid fluid){ } private static Float getConfiguredBurnTimePerBucketFor(Fluid fluid) { - ResourceLocation id = IRegistry.field_212619_h.getKey(fluid); + ResourceLocation id = net.minecraftforge.registries.ForgeRegistries.FLUIDS.getKey(fluid); if (id != null) { if (SteamAdvantage.fluidBurnValues.containsKey(id.toString())) return SteamAdvantage.fluidBurnValues.get(id.toString()); if (SteamAdvantage.fluidBurnValues.containsKey(id.getPath())) return SteamAdvantage.fluidBurnValues.get(id.getPath()); @@ -241,13 +241,13 @@ public void prepareDataFieldsForSync() { dataSyncArray[4] = this.getFuelTank().getFluidAmount(); dataSyncArray[5] = (getFuelTank().getFluid() != null && getFuelTank().getFluid().getFluid() != null ? FluidIdHelper.getFluidId(getFuelTank().getFluid().getFluid()) - : FluidIdHelper.getFluidId(net.minecraft.init.Fluids.WATER)); + : FluidIdHelper.getFluidId(net.minecraft.fluid.Fluids.WATER)); } @Override public void onDataFieldUpdate() { this.setEnergy(Float.intBitsToFloat(dataSyncArray[0]), Power.steam_power); - this.getWaterTank().setFluid(new FluidStack(net.minecraft.init.Fluids.WATER,dataSyncArray[1])); + this.getWaterTank().setFluid(new FluidStack(net.minecraft.fluid.Fluids.WATER,dataSyncArray[1])); this.burnTime = dataSyncArray[2]; this.totalBurnTime = dataSyncArray[3]; this.getFuelTank().setFluid(new FluidStack(FluidIdHelper.getFluid(dataSyncArray[5]),dataSyncArray[4])); @@ -259,16 +259,16 @@ public void onDataFieldUpdate() { * @param tagRoot An NBT tag */ @Override - public NBTTagCompound write(final NBTTagCompound tagRoot) { + public CompoundNBT write(final CompoundNBT tagRoot) { super.write(tagRoot); - NBTTagCompound tankTag = new NBTTagCompound(); + CompoundNBT tankTag = new CompoundNBT(); this.getWaterTank().writeToNBT(tankTag); - tagRoot.setTag("WaterTank", tankTag); - NBTTagCompound tankTag2 = new NBTTagCompound(); + tagRoot.put("WaterTank", tankTag); + CompoundNBT tankTag2 = new CompoundNBT(); this.getFuelTank().writeToNBT(tankTag2); - tagRoot.setTag("FuelTank", tankTag2); - if(this.burnTime > 0)tagRoot.setInt("BurnTime", this.burnTime); - if(this.totalBurnTime > 0)tagRoot.setInt("BurnTimeTotal", this.totalBurnTime); + tagRoot.put("FuelTank", tankTag2); + if(this.burnTime > 0)tagRoot.putInt("BurnTime", this.burnTime); + if(this.totalBurnTime > 0)tagRoot.putInt("BurnTimeTotal", this.totalBurnTime); return tagRoot; } /** @@ -276,30 +276,30 @@ public NBTTagCompound write(final NBTTagCompound tagRoot) { * @param tagRoot An NBT tag */ @Override - public void read(final NBTTagCompound tagRoot) { + public void read(final CompoundNBT tagRoot) { super.read(tagRoot); - if (tagRoot.hasKey("WaterTank")) { - NBTTagCompound tankTag = tagRoot.getCompound("WaterTank"); + if (tagRoot.contains("WaterTank")) { + CompoundNBT tankTag = tagRoot.getCompound("WaterTank"); getWaterTank().readFromNBT(tankTag); - if(tankTag.hasKey("Empty")){ + if(tankTag.contains("Empty")){ // empty the tank if NBT says its empty (not default behavior of Tank.read(...) ) getWaterTank().setFluid(null); } } - if (tagRoot.hasKey("FuelTank")) { - NBTTagCompound tankTag = tagRoot.getCompound("FuelTank"); + if (tagRoot.contains("FuelTank")) { + CompoundNBT tankTag = tagRoot.getCompound("FuelTank"); getFuelTank().readFromNBT(tankTag); - if(tankTag.hasKey("Empty")){ + if(tankTag.contains("Empty")){ // empty the tank if NBT says its empty (not default behavior of Tank.read(...) ) getFuelTank().setFluid(null); } } - if(tagRoot.hasKey("BurnTime")){ + if(tagRoot.contains("BurnTime")){ this.burnTime = tagRoot.getInt("BurnTime"); } else { this.burnTime = 0; } - if(tagRoot.hasKey("BurnTimeTotal")){ + if(tagRoot.contains("BurnTimeTotal")){ this.totalBurnTime = tagRoot.getInt("BurnTimeTotal"); } else { this.totalBurnTime = 0; @@ -350,7 +350,7 @@ public float addEnergy(float amount, ConduitType type){ public void setEnergy(float amount,ConduitType type) { if(Fluids.isFluidType(type) && !ConduitType.areSameType(Fluids.fluidConduit_general,type)){ Fluid f = Fluids.conduitTypeToFluid(type); - if(f == net.minecraft.init.Fluids.WATER){ + if(f == net.minecraft.fluid.Fluids.WATER){ this.getWaterTank().setFluid(new FluidStack(f,(int)amount)); }else{ this.getFuelTank().setFluid(new FluidStack(f,(int)amount)); @@ -383,7 +383,7 @@ public float subtractEnergy(float amount, ConduitType type){ @Override public PowerRequest getPowerRequest(ConduitType offer) { if(this.redstone) return PowerRequest.REQUEST_NOTHING; - if(Fluids.conduitTypeToFluid(offer) == net.minecraft.init.Fluids.WATER){ + if(Fluids.conduitTypeToFluid(offer) == net.minecraft.fluid.Fluids.WATER){ PowerRequest request = new FluidRequest(FluidRequest.MEDIUM_PRIORITY+1, (getWaterTank().getCapacity() - getWaterTank().getFluidAmount()), this); @@ -412,9 +412,9 @@ public PowerRequest getPowerRequest(ConduitType offer) { * @param forReal if true, then the fluid in the tank will change */ @Override - public int fill(EnumFacing face, FluidStack fluid, boolean forReal) { + public int fill(Direction face, FluidStack fluid, boolean forReal) { if(fluid == null) return 0; - if(fluid.getFluid() == net.minecraft.init.Fluids.WATER){ + if(fluid.getFluid() == net.minecraft.fluid.Fluids.WATER){ if(getWaterTank().getFluidAmount() <= 0 || getWaterTank().getFluid().getFluid().equals(fluid.getFluid())){ return getWaterTank().fill(fluid, forReal); } @@ -432,9 +432,9 @@ public int fill(EnumFacing face, FluidStack fluid, boolean forReal) { * @param forReal if true, then the fluid in the tank will change */ @Override - public FluidStack drain(EnumFacing face, FluidStack fluid, boolean forReal) { + public FluidStack drain(Direction face, FluidStack fluid, boolean forReal) { if(fluid == null) return null; - if(fluid.getFluid() == net.minecraft.init.Fluids.WATER && getWaterTank().getFluidAmount() > 0 && getWaterTank().getFluid().getFluid().equals(net.minecraft.init.Fluids.WATER)){ + if(fluid.getFluid() == net.minecraft.fluid.Fluids.WATER && getWaterTank().getFluidAmount() > 0 && getWaterTank().getFluid().getFluid().equals(net.minecraft.fluid.Fluids.WATER)){ return getWaterTank().drain(fluid.amount,forReal); } else if(getFuelTank().getFluidAmount() > 0 && getFuelTank().getFluid().getFluid().equals(fluid.getFluid())){ return getFuelTank().drain(fluid.amount,forReal); @@ -449,7 +449,7 @@ public FluidStack drain(EnumFacing face, FluidStack fluid, boolean forReal) { * @param forReal if true, then the fluid in the tank will change */ @Override - public FluidStack drain(EnumFacing face, int amount, boolean forReal) { + public FluidStack drain(Direction face, int amount, boolean forReal) { if(getWaterTank().getFluidAmount() > 0 ){ return getWaterTank().drain(amount,forReal); } else if(getFuelTank().getFluidAmount() > 0 ){ @@ -464,8 +464,8 @@ public FluidStack drain(EnumFacing face, int amount, boolean forReal) { * @param fluid The fluid being added/removed */ @Override - public boolean canFill(EnumFacing face, Fluid fluid) { - if(fluid == net.minecraft.init.Fluids.WATER) { + public boolean canFill(Direction face, Fluid fluid) { + if(fluid == net.minecraft.fluid.Fluids.WATER) { if(getWaterTank().getFluidAmount() <= 0) return true; return getWaterTank().getFluidAmount() <= getWaterTank().getCapacity() && fluid.equals(getWaterTank().getFluid().getFluid()); } else if(getBurnTimePerBucketFor(fluid) > 0){ @@ -480,9 +480,9 @@ public boolean canFill(EnumFacing face, Fluid fluid) { * @param fluid The fluid being added/removed */ @Override - public boolean canDrain(EnumFacing face, Fluid fluid) { + public boolean canDrain(Direction face, Fluid fluid) { if(fluid == null) return false; - if(fluid == net.minecraft.init.Fluids.WATER) { + if(fluid == net.minecraft.fluid.Fluids.WATER) { return getWaterTank().getFluidAmount() > 0 && fluid.equals(getWaterTank().getFluid().getFluid()); } else { return getFuelTank().getFluidAmount() > 0 && fluid.equals(getFuelTank().getFluid().getFluid()); @@ -495,7 +495,7 @@ public boolean canDrain(EnumFacing face, Fluid fluid) { * @return array of FluidTankInfo describing all of the FluidTanks */ @Override - public FluidTankInfo[] getTankInfo(EnumFacing face) { + public FluidTankInfo[] getTankInfo(Direction face) { FluidTankInfo[] arr = new FluidTankInfo[2]; arr[0] = getWaterTank().getInfo(); arr[1] = getFuelTank().getInfo(); diff --git a/src/main/java/zone/moddev/mc/steamadvantage/machines/RockCrusherBlock.java b/src/main/java/zone/moddev/mc/steamadvantage/machines/RockCrusherBlock.java index d8b8079..cf87c1a 100644 --- a/src/main/java/zone/moddev/mc/steamadvantage/machines/RockCrusherBlock.java +++ b/src/main/java/zone/moddev/mc/steamadvantage/machines/RockCrusherBlock.java @@ -4,7 +4,7 @@ import cyano.poweradvantage.api.PoweredEntity; import zone.moddev.mc.steamadvantage.init.Power; import net.minecraft.block.material.Material; -import net.minecraft.block.state.IBlockState; +import net.minecraft.block.BlockState; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -26,12 +26,12 @@ public PoweredEntity createNewTileEntity(net.minecraft.world.IBlockReader world) } @Override - public boolean hasComparatorInputOverride(IBlockState bs) { + public boolean hasComparatorInputOverride(BlockState bs) { return true; } @Override - public int getComparatorInputOverride(IBlockState bs, World world, BlockPos coord) { + public int getComparatorInputOverride(BlockState bs, World world, BlockPos coord) { if(world.getTileEntity(coord) instanceof RockCrusherTileEntity){ return ((RockCrusherTileEntity)world.getTileEntity(coord)).getComparatorOutput(); } diff --git a/src/main/java/zone/moddev/mc/steamadvantage/machines/RockCrusherTileEntity.java b/src/main/java/zone/moddev/mc/steamadvantage/machines/RockCrusherTileEntity.java index 13f4598..daa0356 100644 --- a/src/main/java/zone/moddev/mc/steamadvantage/machines/RockCrusherTileEntity.java +++ b/src/main/java/zone/moddev/mc/steamadvantage/machines/RockCrusherTileEntity.java @@ -1,11 +1,11 @@ package zone.moddev.mc.steamadvantage.machines; import cyano.poweradvantage.api.ConduitType; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.SoundEvents; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.util.SoundEvents; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.EnumFacing; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.util.Direction; import zone.moddev.mc.steamadvantage.compat.BaseMetalsCompat; import zone.moddev.mc.steamadvantage.init.Power; import net.minecraft.util.SoundCategory; @@ -101,7 +101,7 @@ public void tickUpdate(boolean isServerWorld) { } @Override - public boolean isUsableByPlayer(EntityPlayer player) { + public boolean isUsableByPlayer(PlayerEntity player) { return true; } @@ -182,16 +182,16 @@ private int canAddToOutputInventory(ItemStack output) { } @Override - public NBTTagCompound write(NBTTagCompound tagRoot){ + public CompoundNBT write(CompoundNBT tagRoot){ super.write(tagRoot); - tagRoot.setShort("progress",(short)progress); + tagRoot.putShort("progress",(short)progress); return tagRoot; } @Override - public void read(NBTTagCompound tagRoot){ + public void read(CompoundNBT tagRoot){ super.read(tagRoot); - if(tagRoot.hasKey("progress")){ + if(tagRoot.contains("progress")){ progress = tagRoot.getShort("progress"); } } @@ -206,17 +206,17 @@ public int getComparatorOutput() { ///// Item Handling (for hoppers) ///// @Override - public int[] getSlotsForFace(EnumFacing side) { + public int[] getSlotsForFace(Direction side) { return allSlots; } @Override - public boolean canExtractItem(final int slot, final ItemStack targetItem, final EnumFacing side) { + public boolean canExtractItem(final int slot, final ItemStack targetItem, final Direction side) { return slot > 0 && slot < this.getInventory().length; } @Override - public boolean canInsertItem(final int slot, final ItemStack srcItem, final EnumFacing side) { + public boolean canInsertItem(final int slot, final ItemStack srcItem, final Direction side) { return this.isItemValidForSlot(slot, srcItem) && slot <= 0; } diff --git a/src/main/java/zone/moddev/mc/steamadvantage/machines/SteamDrillBlock.java b/src/main/java/zone/moddev/mc/steamadvantage/machines/SteamDrillBlock.java index 5ac1aea..f481e46 100644 --- a/src/main/java/zone/moddev/mc/steamadvantage/machines/SteamDrillBlock.java +++ b/src/main/java/zone/moddev/mc/steamadvantage/machines/SteamDrillBlock.java @@ -9,15 +9,15 @@ import net.minecraft.state.DirectionProperty; import net.minecraft.state.StateContainer; import net.minecraft.state.properties.BlockStateProperties; -import net.minecraft.block.state.IBlockState; -import net.minecraft.entity.EntityLivingBase; +import net.minecraft.block.BlockState; +import net.minecraft.entity.LivingEntity; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.InventoryHelper; import net.minecraft.item.Item; import net.minecraft.item.BlockItemUseContext; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.EnumFacing; +import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; import net.minecraft.world.Explosion; import net.minecraft.world.World; @@ -32,32 +32,26 @@ public class SteamDrillBlock extends GUIBlock implements ITypedConduit { public static final DirectionProperty FACING = BlockStateProperties.FACING; public SteamDrillBlock(){ - super(Material.PISTON); - this.setPowerAdvantageHardness(0.75f); - this.setDefaultState(getStateContainer().getBaseState().with(FACING, EnumFacing.DOWN)); + super(Material.PISTON, 0.75f); + this.setDefaultState(getStateContainer().getBaseState().with(FACING, Direction.DOWN)); } /** * Override of default block behavior */ @Override - public void onBlockAdded(final IBlockState state, final World world, final BlockPos coord, final IBlockState oldState) { - super.onBlockAdded(state, world, coord, oldState); + public void onBlockAdded(final BlockState state, final World world, final BlockPos coord, final BlockState oldState, final boolean moving) { + super.onBlockAdded(state, world, coord, oldState, moving); ConduitRegistry.getInstance().conduitBlockPlacedEvent(world, world.dimension.getType().getId(), coord, Power.steam_power); } /** * This method is called when the block is removed from the world by an entity. */ @Override - public void onReplaced(IBlockState state, World w, BlockPos coord, IBlockState newState, boolean isMoving){ + public void onReplaced(BlockState state, World w, BlockPos coord, BlockState newState, boolean isMoving){ if (state.getBlock() != newState.getBlock()) { destroyNeighbors(w, coord, state); ConduitRegistry.getInstance().conduitBlockRemovedEvent(w, w.dimension.getType().getId(), coord, Power.steam_power); - TileEntity tileEntity = w.getTileEntity(coord); - if (tileEntity instanceof TileEntitySimplePowerMachine) { - InventoryHelper.dropInventoryItems(w, coord, (IInventory) tileEntity); - w.updateComparatorOutputLevel(coord, this); - } } super.onReplaced(state, w, coord, newState, isMoving); } @@ -73,11 +67,11 @@ public void onExplosionDestroy(World w, BlockPos coord, Explosion boom){ - private void destroyNeighbors(World w, BlockPos coord, IBlockState state) { + private void destroyNeighbors(World w, BlockPos coord, BlockState state) { if(w.isRemote) return; // destroy connected drill bits for(int i = 0; i < 6; i++){ - BlockPos pos = coord.offset(EnumFacing.byIndex(i)); + BlockPos pos = coord.offset(Direction.byIndex(i)); if(w.getTileEntity(pos) instanceof DrillBitTileEntity){ DrillBitTileEntity te = (DrillBitTileEntity)w.getTileEntity(pos); te.destroyLine(); @@ -126,7 +120,7 @@ public boolean isPowerSource(ConduitType t){ * Creates the blockstate of this block when it is placed in the world */ @Override - public IBlockState getStateForPlacement(final BlockItemUseContext context) { + public BlockState getStateForPlacement(final BlockItemUseContext context) { return this.getDefaultState().with(FACING, context.getFace().getOpposite()); } @@ -134,8 +128,8 @@ public IBlockState getStateForPlacement(final BlockItemUseContext context) { * Creates the blockstate of this block when it is placed in the world */ @Override - public void onBlockPlacedBy(final World world, final BlockPos coord, final IBlockState bs, - final EntityLivingBase placer, final ItemStack srcItemStack) { + public void onBlockPlacedBy(final World world, final BlockPos coord, final BlockState bs, + final LivingEntity placer, final ItemStack srcItemStack) { if (srcItemStack.hasDisplayName()) { final TileEntity tileEntity = world.getTileEntity(coord); if (tileEntity instanceof PoweredEntity){ @@ -168,7 +162,7 @@ public void onBlockPlacedBy(final World world, final BlockPos coord, final IBloc * false otherwise */ @Override - public boolean hasComparatorInputOverride(IBlockState bs){ + public boolean hasComparatorInputOverride(BlockState bs){ return true; } @@ -189,7 +183,7 @@ public boolean hasComparatorInputOverride(IBlockState bs){ * @return a number from 0 to 15 */ @Override - public int getComparatorInputOverride(IBlockState bs, final World world, final BlockPos coord){ + public int getComparatorInputOverride(BlockState bs, final World world, final BlockPos coord){ TileEntity te = world.getTileEntity(coord); if(te instanceof SteamDrillTileEntity){ return ((SteamDrillTileEntity)te).getComparatorOutput(); @@ -202,7 +196,7 @@ public int getComparatorInputOverride(IBlockState bs, final World world, final B * Creates a blockstate */ @Override - protected void fillStateContainer(StateContainer.Builder builder) { + protected void fillStateContainer(StateContainer.Builder builder) { builder.add(FACING); } diff --git a/src/main/java/zone/moddev/mc/steamadvantage/machines/SteamDrillTileEntity.java b/src/main/java/zone/moddev/mc/steamadvantage/machines/SteamDrillTileEntity.java index a7fb1e5..16cb299 100644 --- a/src/main/java/zone/moddev/mc/steamadvantage/machines/SteamDrillTileEntity.java +++ b/src/main/java/zone/moddev/mc/steamadvantage/machines/SteamDrillTileEntity.java @@ -7,20 +7,21 @@ import zone.moddev.mc.steamadvantage.init.Blocks; import zone.moddev.mc.steamadvantage.init.Power; import net.minecraft.block.Block; -import net.minecraft.block.state.IBlockState; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.SoundEvents; +import net.minecraft.block.BlockState; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.util.SoundEvents; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.ISidedInventory; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.NBTUtil; import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.EnumFacing; +import net.minecraft.util.Direction; import net.minecraft.util.NonNullList; import net.minecraft.util.SoundCategory; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; +import net.minecraft.world.server.ServerWorld; import java.util.Arrays; import java.util.List; @@ -42,12 +43,12 @@ public class SteamDrillTileEntity extends cyano.poweradvantage.api.simple.TileEn private int progress = 0; private int progressGoal = 0; private BlockPos targetBlockCoord = null; - private IBlockState targetBlockState = null; - private NBTTagCompound savedTargetState = null; + private BlockState targetBlockState = null; + private CompoundNBT savedTargetState = null; private Block targetBlock = null; private List targetBlockItems = null; - private EnumFacing oldDir = null; - private EnumFacing savedFacing = null; + private Direction oldDir = null; + private Direction savedFacing = null; private boolean deferred = false; @@ -64,12 +65,12 @@ public void tickUpdate(boolean isServerWorld) { if(deferred){ restoreTargetBlock(); } - EnumFacing face = this.getFacing(); + Direction face = this.getFacing(); if(oldDir == null){ // oldDir becomes null on rotation and new TileEntity creation // destroy drillbits in all directions but the current one oldDir = face; - for(EnumFacing d : EnumFacing.values()){ + for(Direction d : Direction.values()){ if(d == face) continue; destroyDrillBit(d); } @@ -88,9 +89,9 @@ public void tickUpdate(boolean isServerWorld) { progress++; if(progress >= progressGoal){ // Mined it! - playSoundAtPosition(targetBlockCoord.getX()+0.5, targetBlockCoord.getY()+0.5, targetBlockCoord.getZ()+0.5, targetBlock.getSoundType().getPlaceSound(), SoundCategory.BLOCKS, 0.5f, 1f, this.powerAdvantageWorld()); + playSoundAtPosition(targetBlockCoord.getX()+0.5, targetBlockCoord.getY()+0.5, targetBlockCoord.getZ()+0.5, targetBlock.getSoundType(targetBlockState, powerAdvantageWorld(), targetBlockCoord, null).getPlaceSound(), SoundCategory.BLOCKS, 0.5f, 1f, this.powerAdvantageWorld()); playSoundAtTileEntity( SoundEvents.BLOCK_FIRE_EXTINGUISH, SoundCategory.AMBIENT, 0.5f, 1f, this); - powerAdvantageWorld().removeBlock(targetBlockCoord); + powerAdvantageWorld().removeBlock(targetBlockCoord, false); for(ItemStack item : targetBlockItems){ addItem(item); } @@ -154,8 +155,8 @@ public ItemStack addItem(ItemStack in){ return in; } - private EnumFacing trackDirection(EnumFacing drillDirection){ - for(EnumFacing dir : EnumFacing.values()){ + private Direction trackDirection(Direction drillDirection){ + for(Direction dir : Direction.values()){ if(dir == drillDirection) continue; if(powerAdvantageWorld().getBlockState(powerAdvantagePos().offset(dir)).getBlock() == Blocks.steam_track){ return dir; @@ -166,8 +167,8 @@ private EnumFacing trackDirection(EnumFacing drillDirection){ private boolean followTrack(){ if(this.getEnergy(Power.steam_power) < ENERGY_COST_MOVE) return false; - EnumFacing drillDirection = getFacing(); - EnumFacing trackDir = trackDirection(drillDirection); + Direction drillDirection = getFacing(); + Direction trackDir = trackDirection(drillDirection); if(trackDir == null) return false; // clone this block into neighboring block @@ -175,7 +176,7 @@ private boolean followTrack(){ World w = powerAdvantageWorld(); BlockPos currentPos = powerAdvantagePos(); BlockPos nextPos = currentPos.offset(trackDir); - IBlockState trackState = w.getBlockState(nextPos); + BlockState trackState = w.getBlockState(nextPos); w.setBlockState(nextPos, w.getBlockState(currentPos), 2); TileEntity movedTile = w.getTileEntity(nextPos); if(!(movedTile instanceof SteamDrillTileEntity)){ @@ -183,11 +184,11 @@ private boolean followTrack(){ return false; } SteamDrillTileEntity te = (SteamDrillTileEntity)movedTile; - NBTTagCompound dataTransfer = new NBTTagCompound(); + CompoundNBT dataTransfer = new CompoundNBT(); this.write(dataTransfer); - dataTransfer.setInt("x", nextPos.getX()); - dataTransfer.setInt("y", nextPos.getY()); - dataTransfer.setInt("z", nextPos.getZ()); + dataTransfer.putInt("x", nextPos.getX()); + dataTransfer.putInt("y", nextPos.getY()); + dataTransfer.putInt("z", nextPos.getZ()); te.read(dataTransfer); te.setPos(nextPos); te.validate(); @@ -239,7 +240,7 @@ public void onDataFieldUpdate() { redstone = hasRedstoneSignal(); - EnumFacing f = getFacing(); + Direction f = getFacing(); BlockPos n = powerAdvantagePos().offset(f); // manage drill bits and find next block @@ -314,10 +315,10 @@ public void onDataFieldUpdate() { } } - private void destroyDrillBit(EnumFacing f) { + private void destroyDrillBit(Direction f) { BlockPos n = powerAdvantagePos().offset(f); while(powerAdvantageWorld().getBlockState(n).getBlock() == zone.moddev.mc.steamadvantage.init.Blocks.drillbit){ - powerAdvantageWorld().removeBlock(n); + powerAdvantageWorld().removeBlock(n, false); n = n.offset(f); } } @@ -334,13 +335,16 @@ private void targetBlock (BlockPos n){ targetBlockItems = Arrays.asList(crusherOutput); } else { NonNullList drops = NonNullList.create(); - targetBlock.getDrops(powerAdvantageWorld().getBlockState(n), drops, powerAdvantageWorld(), n, 0); + drops.addAll(Block.getDrops(targetBlockState, (ServerWorld) powerAdvantageWorld(), n, + powerAdvantageWorld().getTileEntity(n))); targetBlockItems = drops; } deferred = false; } private void restoreTargetBlock(){ + if(powerAdvantageWorld() == null || powerAdvantageWorld().isRemote + || !powerAdvantageWorld().isBlockLoaded(targetBlockCoord)) return; int savedProgress = progress; if(savedTargetState != null && !savedTargetState.equals( NBTUtil.writeBlockState(powerAdvantageWorld().getBlockState(targetBlockCoord)))){ @@ -369,8 +373,8 @@ private void untargetBlock(){ targetBlockItems = null; } - private EnumFacing getFacing(){ - IBlockState state = powerAdvantageWorld().getBlockState(powerAdvantagePos()); + private Direction getFacing(){ + BlockState state = powerAdvantageWorld().getBlockState(powerAdvantagePos()); if(state.has(SteamDrillBlock.FACING)){ savedFacing = state.get(SteamDrillBlock.FACING); return savedFacing; @@ -379,21 +383,21 @@ private EnumFacing getFacing(){ return savedFacing; } - private EnumFacing inferFacing(){ + private Direction inferFacing(){ if(targetBlockCoord != null){ int dx = targetBlockCoord.getX() - powerAdvantagePos().getX(); int dy = targetBlockCoord.getY() - powerAdvantagePos().getY(); int dz = targetBlockCoord.getZ() - powerAdvantagePos().getZ(); - if(dx != 0 && dy == 0 && dz == 0) return dx > 0 ? EnumFacing.EAST : EnumFacing.WEST; - if(dy != 0 && dx == 0 && dz == 0) return dy > 0 ? EnumFacing.UP : EnumFacing.DOWN; - if(dz != 0 && dx == 0 && dy == 0) return dz > 0 ? EnumFacing.SOUTH : EnumFacing.NORTH; + if(dx != 0 && dy == 0 && dz == 0) return dx > 0 ? Direction.EAST : Direction.WEST; + if(dy != 0 && dx == 0 && dz == 0) return dy > 0 ? Direction.UP : Direction.DOWN; + if(dz != 0 && dx == 0 && dy == 0) return dz > 0 ? Direction.SOUTH : Direction.NORTH; } - for(EnumFacing dir : EnumFacing.values()){ + for(Direction dir : Direction.values()){ if(powerAdvantageWorld().getBlockState(powerAdvantagePos().offset(dir)).getBlock() == Blocks.drillbit){ return dir; } } - return oldDir == null ? EnumFacing.DOWN : oldDir; + return oldDir == null ? Direction.DOWN : oldDir; } private void energyDecay() { @@ -408,21 +412,21 @@ private boolean hasRedstoneSignal() { private boolean canMine(BlockPos coord){ Block b = powerAdvantageWorld().getBlockState(coord).getBlock(); - return !(b == net.minecraft.init.Blocks.BEDROCK || b == net.minecraft.init.Blocks.BARRIER); + return !(b == net.minecraft.block.Blocks.BEDROCK || b == net.minecraft.block.Blocks.BARRIER); } private int getBlockStrength(BlockPos coord){ if(powerAdvantageWorld().isAirBlock(coord)){ return 0; } - IBlockState bs = powerAdvantageWorld().getBlockState(coord); + BlockState bs = powerAdvantageWorld().getBlockState(coord); Block block = bs.getBlock(); return (int)(Math.max(MINING_TIME_FACTOR * block.getBlockHardness(bs,powerAdvantageWorld(), coord),0.5f * MINING_TIME_FACTOR)); } - private void inventoryTransfer(BlockPos adj, EnumFacing otherFace) { + private void inventoryTransfer(BlockPos adj, Direction otherFace) { TileEntity te = powerAdvantageWorld().getTileEntity(adj); if(te instanceof IInventory ){ ISidedInventory inv = InventoryWrapper.wrap((IInventory)te); @@ -462,45 +466,43 @@ private void inventoryTransfer(BlockPos adj, EnumFacing otherFace) { } @Override - public NBTTagCompound write(NBTTagCompound tagRoot){ + public CompoundNBT write(CompoundNBT tagRoot){ super.write(tagRoot); - tagRoot.setShort("progress",(short)progress); - if(powerAdvantageWorld() != null) savedFacing = getFacing(); - if(savedFacing != null) tagRoot.setByte("Facing", (byte)savedFacing.getIndex()); + tagRoot.putShort("progress",(short)progress); + // getFacing refreshes this during normal ticks. World lookups here can + // synchronously reload a chunk while its unload-save is in progress. + if(savedFacing != null) tagRoot.putByte("Facing", (byte)savedFacing.getIndex()); if(targetBlockCoord != null){ - tagRoot.setInt("targetX", targetBlockCoord.getX()); - tagRoot.setInt("targetY", targetBlockCoord.getY()); - tagRoot.setInt("targetZ", targetBlockCoord.getZ()); - if(savedTargetState != null) tagRoot.setTag("TargetState", savedTargetState.copy()); + tagRoot.putInt("targetX", targetBlockCoord.getX()); + tagRoot.putInt("targetY", targetBlockCoord.getY()); + tagRoot.putInt("targetZ", targetBlockCoord.getZ()); + if(savedTargetState != null) tagRoot.put("TargetState", savedTargetState.copy()); } return tagRoot; } @Override - public void read(NBTTagCompound tagRoot){ + public void read(CompoundNBT tagRoot){ super.read(tagRoot); untargetBlock(); - if(tagRoot.hasKey("Facing")){ + savedFacing = null; + oldDir = null; + if(tagRoot.contains("Facing")){ int facingIndex = tagRoot.getByte("Facing"); - if(facingIndex >= 0 && facingIndex < EnumFacing.values().length){ - savedFacing = EnumFacing.byIndex(facingIndex); + if(facingIndex >= 0 && facingIndex < Direction.values().length){ + savedFacing = Direction.byIndex(facingIndex); } } - if(tagRoot.hasKey("progress")){ + if(tagRoot.contains("progress")){ progress = tagRoot.getShort("progress"); } - if(tagRoot.hasKey("targetX") && tagRoot.hasKey("targetY") && tagRoot.hasKey("targetZ")){ + if(tagRoot.contains("targetX") && tagRoot.contains("targetY") && tagRoot.contains("targetZ")){ int x = tagRoot.getInt("targetX"); int y = tagRoot.getInt("targetY"); int z = tagRoot.getInt("targetZ"); savedTargetState = tagRoot.contains("TargetState", 10) ? tagRoot.getCompound("TargetState").copy() : null; - // Note: world object for tile entities is set AFTER loading them from NBT - if(powerAdvantageWorld() == null){ - this.deferredTargetBlock(new BlockPos(x,y,z)); - } else { - this.deferredTargetBlock(new BlockPos(x,y,z)); - this.restoreTargetBlock(); - } + // Loot and hardness are restored on the server after the world is attached. + this.deferredTargetBlock(new BlockPos(x,y,z)); } } @@ -538,7 +540,7 @@ public boolean isPowerSource(ConduitType conduitType) { } @Override - public boolean isUsableByPlayer(EntityPlayer player) { + public boolean isUsableByPlayer(PlayerEntity player) { return true; } } diff --git a/src/main/java/zone/moddev/mc/steamadvantage/machines/SteamElevatorBlock.java b/src/main/java/zone/moddev/mc/steamadvantage/machines/SteamElevatorBlock.java index bfc24fe..6bb7fb4 100644 --- a/src/main/java/zone/moddev/mc/steamadvantage/machines/SteamElevatorBlock.java +++ b/src/main/java/zone/moddev/mc/steamadvantage/machines/SteamElevatorBlock.java @@ -4,7 +4,7 @@ import cyano.poweradvantage.api.PoweredEntity; import zone.moddev.mc.steamadvantage.init.Power; import net.minecraft.block.material.Material; -import net.minecraft.block.state.IBlockState; +import net.minecraft.block.BlockState; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -26,12 +26,12 @@ public PoweredEntity createNewTileEntity(net.minecraft.world.IBlockReader world) } @Override - public boolean hasComparatorInputOverride(IBlockState bs) { + public boolean hasComparatorInputOverride(BlockState bs) { return true; } @Override - public int getComparatorInputOverride(IBlockState bs, World world, BlockPos coord) { + public int getComparatorInputOverride(BlockState bs, World world, BlockPos coord) { if(world.getTileEntity(coord) instanceof SteamElevatorTileEntity){ return ((SteamElevatorTileEntity)world.getTileEntity(coord)).getComparatorOutput(); } diff --git a/src/main/java/zone/moddev/mc/steamadvantage/machines/SteamElevatorTileEntity.java b/src/main/java/zone/moddev/mc/steamadvantage/machines/SteamElevatorTileEntity.java index d405b16..3390870 100644 --- a/src/main/java/zone/moddev/mc/steamadvantage/machines/SteamElevatorTileEntity.java +++ b/src/main/java/zone/moddev/mc/steamadvantage/machines/SteamElevatorTileEntity.java @@ -4,10 +4,10 @@ import zone.moddev.mc.steamadvantage.init.Blocks; import zone.moddev.mc.steamadvantage.init.Power; import net.minecraft.entity.Entity; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.SoundEvents; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.util.SoundEvents; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.CompoundNBT; import net.minecraft.util.SoundCategory; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; @@ -99,7 +99,7 @@ private boolean moveDown(){ // remove piston BlockPos i = p.down(); for(; i.getY() > getPos().getY(); i = i.down()){ - getWorld().removeBlock(i); + getWorld().removeBlock(i, false); } // move people List passengers = getWorld().getEntitiesWithinAABB(Entity.class, @@ -167,16 +167,16 @@ public void onDataFieldUpdate() { @Override - public NBTTagCompound write(NBTTagCompound tagRoot){ + public CompoundNBT write(CompoundNBT tagRoot){ super.write(tagRoot); - tagRoot.setBoolean("up",up); + tagRoot.putBoolean("up",up); return tagRoot; } @Override - public void read(NBTTagCompound tagRoot){ + public void read(CompoundNBT tagRoot){ super.read(tagRoot); - if(tagRoot.hasKey("up")){ + if(tagRoot.contains("up")){ up = tagRoot.getBoolean("up"); } } @@ -200,7 +200,7 @@ public boolean isPowerSource(ConduitType conduitType) { } @Override - public boolean isUsableByPlayer(EntityPlayer player) { + public boolean isUsableByPlayer(PlayerEntity player) { return true; } } diff --git a/src/main/java/zone/moddev/mc/steamadvantage/machines/SteamPumpBlock.java b/src/main/java/zone/moddev/mc/steamadvantage/machines/SteamPumpBlock.java index a9c08fd..e318960 100644 --- a/src/main/java/zone/moddev/mc/steamadvantage/machines/SteamPumpBlock.java +++ b/src/main/java/zone/moddev/mc/steamadvantage/machines/SteamPumpBlock.java @@ -7,7 +7,7 @@ import zone.moddev.mc.steamadvantage.init.Blocks; import zone.moddev.mc.steamadvantage.init.Power; import net.minecraft.block.material.Material; -import net.minecraft.block.state.IBlockState; +import net.minecraft.block.BlockState; import net.minecraft.util.math.BlockPos; import net.minecraft.world.Explosion; import net.minecraft.world.World; @@ -32,12 +32,12 @@ public PoweredEntity createNewTileEntity(net.minecraft.world.IBlockReader world) } @Override - public boolean hasComparatorInputOverride(IBlockState bs) { + public boolean hasComparatorInputOverride(BlockState bs) { return true; } @Override - public int getComparatorInputOverride(IBlockState bs, World world, BlockPos coord) { + public int getComparatorInputOverride(BlockState bs, World world, BlockPos coord) { if(world.getTileEntity(coord) instanceof SteamPumpTileEntity){ return ((SteamPumpTileEntity)world.getTileEntity(coord)).getComparatorOutput(); } @@ -57,7 +57,7 @@ public boolean isPowerSource(ConduitType type){ return !ConduitType.areSameType(Power.steam_power, type); } @Override - public void onReplaced(IBlockState state, World w, BlockPos coord, IBlockState newState, boolean isMoving) { + public void onReplaced(BlockState state, World w, BlockPos coord, BlockState newState, boolean isMoving) { if (state.getBlock() != newState.getBlock()) destroyPipe(w, coord); super.onReplaced(state, w, coord, newState, isMoving); } @@ -74,7 +74,7 @@ private void destroyPipe(World w, BlockPos coord) { // destroy connected drill bits BlockPos c = coord.down(); while(c.getY() > 0 && w.getBlockState(c).getBlock() == Blocks.pump_pipe_steam){ - w.removeBlock(c); + w.removeBlock(c, false); c = c.down(); } } diff --git a/src/main/java/zone/moddev/mc/steamadvantage/machines/SteamPumpTileEntity.java b/src/main/java/zone/moddev/mc/steamadvantage/machines/SteamPumpTileEntity.java index 448f3f1..850a189 100644 --- a/src/main/java/zone/moddev/mc/steamadvantage/machines/SteamPumpTileEntity.java +++ b/src/main/java/zone/moddev/mc/steamadvantage/machines/SteamPumpTileEntity.java @@ -10,14 +10,14 @@ import zone.moddev.mc.poweradvantage.init.Fluids; import zone.moddev.mc.poweradvantage.util.FluidHandlerHelper; import zone.moddev.mc.steamadvantage.init.Power; -import net.minecraft.block.state.IBlockState; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.Blocks; -import net.minecraft.init.SoundEvents; +import net.minecraft.block.BlockState; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.block.Blocks; +import net.minecraft.util.SoundEvents; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.CompoundNBT; import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.EnumFacing; +import net.minecraft.util.Direction; import net.minecraft.util.SoundCategory; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -87,12 +87,12 @@ public void tickUpdate(boolean isServerWorld) { if(fluidSource != null){ float cost = ENERGY_COST_PUMP+ENERGY_COST_VERTICAL*(getPos().getY()-fluidSource.getY()); // Found a fluid to suck-up! - IBlockState blockstate = w.getBlockState(fluidSource); + BlockState blockstate = w.getBlockState(fluidSource); Fluid f = getFluid(blockstate); if(f != null && getEnergy(Power.steam_power) >= cost){ this.getTank().fill(new FluidStack(f,FluidTank.BUCKET_VOLUME), true); this.subtractEnergy(cost, Power.steam_power); - w.removeBlock(fluidSource); + w.removeBlock(fluidSource, false); success = true; } } @@ -116,7 +116,7 @@ public void tickUpdate(boolean isServerWorld) { - private Fluid getFluid(IBlockState blockstate) { + private Fluid getFluid(BlockState blockstate) { return blockstate.getFluidState().isEmpty() ? null : blockstate.getFluidState().getFluid(); } @@ -131,7 +131,7 @@ private BlockPos scan(Set searchSpace, BlockPos coord, int limit) { searchSpace.add(coord); BlockPos next; boolean nomore = true; - for(EnumFacing dir : EnumFacing.values()){ + for(Direction dir : Direction.values()){ next = coord.offset(dir); if(!searchSpace.contains(next) && isFluidBlock(next)){ coord = next; @@ -189,9 +189,9 @@ public void powerUpdate(){ getTank().drain(Math.max((int)delta,1),true); // no free energy! } else { // try passing to a fluid handler - for(int i = 1; i < EnumFacing.values().length; i++){ + for(int i = 1; i < Direction.values().length; i++){ if(getTank().getFluidAmount() <= 0) break; - EnumFacing dir = EnumFacing.values()[i]; + Direction dir = Direction.values()[i]; BlockPos nPos = getPos().offset(dir); TileEntity neighbor = getWorld().getTileEntity(nPos); IAdvantageFluidHandler handler = FluidHandlerHelper.getHandler(neighbor, dir.getOpposite()); @@ -249,7 +249,7 @@ public int[] getDataFieldArray() { public void prepareDataFieldsForSync() { dataSyncArray[0] = Float.floatToRawIntBits(this.getEnergy(Power.steam_power)); dataSyncArray[1] = this.getTank().getFluidAmount(); - dataSyncArray[2] = (this.getTank().getFluidAmount() > 0 ? FluidIdHelper.getFluidId(this.getTank().getFluid().getFluid()) : FluidIdHelper.getFluidId(net.minecraft.init.Fluids.WATER)); + dataSyncArray[2] = (this.getTank().getFluidAmount() > 0 ? FluidIdHelper.getFluidId(this.getTank().getFluid().getFluid()) : FluidIdHelper.getFluidId(net.minecraft.fluid.Fluids.WATER)); dataSyncArray[3] = this.timeUntilNextPump; } @@ -266,12 +266,12 @@ public void onDataFieldUpdate() { * @param tagRoot An NBT tag */ @Override - public NBTTagCompound write(final NBTTagCompound tagRoot) { + public CompoundNBT write(final CompoundNBT tagRoot) { super.write(tagRoot); - NBTTagCompound tankTag = new NBTTagCompound(); + CompoundNBT tankTag = new CompoundNBT(); this.getTank().writeToNBT(tankTag); - tagRoot.setTag("Tank", tankTag); - tagRoot.setByte("NextPump", (byte)this.timeUntilNextPump); + tagRoot.put("Tank", tankTag); + tagRoot.putByte("NextPump", (byte)this.timeUntilNextPump); return tagRoot; } /** @@ -279,19 +279,19 @@ public NBTTagCompound write(final NBTTagCompound tagRoot) { * @param tagRoot An NBT tag */ @Override - public void read(final NBTTagCompound tagRoot) { + public void read(final CompoundNBT tagRoot) { super.read(tagRoot); - String tankKey = tagRoot.hasKey("Tank") ? "Tank" : "TankOut"; - if (tagRoot.hasKey(tankKey)) { - NBTTagCompound tankTag = tagRoot.getCompound(tankKey); + String tankKey = tagRoot.contains("Tank") ? "Tank" : "TankOut"; + if (tagRoot.contains(tankKey)) { + CompoundNBT tankTag = tagRoot.getCompound(tankKey); getTank().readFromNBT(tankTag); - if(tankTag.hasKey("Empty")){ + if(tankTag.contains("Empty")){ // empty the tank if NBT says its empty (not default behavior of Tank.read(...) ) getTank().setFluid(null); } } - if (tagRoot.hasKey("NextPump")) { + if (tagRoot.contains("NextPump")) { this.timeUntilNextPump = tagRoot.getByte("NextPump"); } } @@ -370,7 +370,7 @@ public PowerRequest getPowerRequest(ConduitType offer) { * @param forReal if true, then the fluid in the tank will change */ @Override - public int fill(EnumFacing face, FluidStack fluid, boolean forReal) { + public int fill(Direction face, FluidStack fluid, boolean forReal) { if(fluid == null) return 0; if(getTank().getFluidAmount() <= 0 || getTank().getFluid().getFluid().equals(fluid.getFluid())){ return getTank().fill(fluid, forReal); @@ -384,7 +384,7 @@ public int fill(EnumFacing face, FluidStack fluid, boolean forReal) { * @param forReal if true, then the fluid in the tank will change */ @Override - public FluidStack drain(EnumFacing face, FluidStack fluid, boolean forReal) { + public FluidStack drain(Direction face, FluidStack fluid, boolean forReal) { if(getTank().getFluidAmount() > 0 && getTank().getFluid().getFluid().equals(fluid.getFluid())){ return getTank().drain(fluid.amount,forReal); } else { @@ -398,7 +398,7 @@ public FluidStack drain(EnumFacing face, FluidStack fluid, boolean forReal) { * @param forReal if true, then the fluid in the tank will change */ @Override - public FluidStack drain(EnumFacing face, int amount, boolean forReal) { + public FluidStack drain(Direction face, int amount, boolean forReal) { if(getTank().getFluidAmount() > 0 ){ return getTank().drain(amount,forReal); } else { @@ -411,7 +411,7 @@ public FluidStack drain(EnumFacing face, int amount, boolean forReal) { * @param fluid The fluid being added/removed */ @Override - public boolean canFill(EnumFacing face, Fluid fluid) { + public boolean canFill(Direction face, Fluid fluid) { if(fluid == null) return false; if(getTank().getFluidAmount() <= 0) return true; return getTank().getFluidAmount() <= getTank().getCapacity() && fluid.equals(getTank().getFluid().getFluid()); @@ -422,7 +422,7 @@ public boolean canFill(EnumFacing face, Fluid fluid) { * @param fluid The fluid being added/removed */ @Override - public boolean canDrain(EnumFacing face, Fluid fluid) { + public boolean canDrain(Direction face, Fluid fluid) { if(fluid == null) return false; return getTank().getFluidAmount() > 0 && fluid.equals(getTank().getFluid().getFluid()); } @@ -433,7 +433,7 @@ public boolean canDrain(EnumFacing face, Fluid fluid) { * @return array of FluidTankInfo describing all of the FluidTanks */ @Override - public FluidTankInfo[] getTankInfo(EnumFacing face) { + public FluidTankInfo[] getTankInfo(Direction face) { FluidTankInfo[] arr = new FluidTankInfo[1]; arr[0] = getTank().getInfo(); return arr; @@ -449,7 +449,7 @@ public boolean isItemValidForSlot(final int slot, final ItemStack item) { @Override - public boolean isUsableByPlayer(EntityPlayer player) { + public boolean isUsableByPlayer(PlayerEntity player) { return true; } } diff --git a/src/main/java/zone/moddev/mc/steamadvantage/machines/SteamStillBlock.java b/src/main/java/zone/moddev/mc/steamadvantage/machines/SteamStillBlock.java index ddcd13d..2087cb5 100644 --- a/src/main/java/zone/moddev/mc/steamadvantage/machines/SteamStillBlock.java +++ b/src/main/java/zone/moddev/mc/steamadvantage/machines/SteamStillBlock.java @@ -6,7 +6,7 @@ import zone.moddev.mc.poweradvantage.init.Fluids; import zone.moddev.mc.steamadvantage.init.Power; import net.minecraft.block.material.Material; -import net.minecraft.block.state.IBlockState; +import net.minecraft.block.BlockState; import net.minecraft.util.math.BlockPos; import net.minecraft.world.Explosion; import net.minecraft.world.World; @@ -31,12 +31,12 @@ public PoweredEntity createNewTileEntity(net.minecraft.world.IBlockReader world) } @Override - public boolean hasComparatorInputOverride(IBlockState bs) { + public boolean hasComparatorInputOverride(BlockState bs) { return true; } @Override - public int getComparatorInputOverride(IBlockState bs, World world, BlockPos coord) { + public int getComparatorInputOverride(BlockState bs, World world, BlockPos coord) { if(world.getTileEntity(coord) instanceof SteamStillTileEntity){ return ((SteamStillTileEntity)world.getTileEntity(coord)).getComparatorOutput(); } diff --git a/src/main/java/zone/moddev/mc/steamadvantage/machines/SteamStillTileEntity.java b/src/main/java/zone/moddev/mc/steamadvantage/machines/SteamStillTileEntity.java index cbb4702..28ff12b 100644 --- a/src/main/java/zone/moddev/mc/steamadvantage/machines/SteamStillTileEntity.java +++ b/src/main/java/zone/moddev/mc/steamadvantage/machines/SteamStillTileEntity.java @@ -12,11 +12,11 @@ import zone.moddev.mc.poweradvantage.registry.still.recipe.DistillationRecipe; import zone.moddev.mc.poweradvantage.registry.still.recipe.DistillationRecipeRegistry; import zone.moddev.mc.steamadvantage.init.Power; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.SoundEvents; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.util.SoundEvents; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.EnumFacing; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.util.Direction; import net.minecraft.util.SoundCategory; import net.minecraft.fluid.Fluid; import cyano.poweradvantage.api.fluid.FluidStack; @@ -154,9 +154,9 @@ public int[] getDataFieldArray() { public void prepareDataFieldsForSync() { dataSyncArray[0] = Float.floatToRawIntBits(this.getEnergy(Power.steam_power)); dataSyncArray[1] = this.getOutputTank().getFluidAmount(); - dataSyncArray[2] = FluidIdHelper.getFluidId(this.getOutputTank().getFluidAmount() > 0 ? this.getOutputTank().getFluid().getFluid() : net.minecraft.init.Fluids.WATER); + dataSyncArray[2] = FluidIdHelper.getFluidId(this.getOutputTank().getFluidAmount() > 0 ? this.getOutputTank().getFluid().getFluid() : net.minecraft.fluid.Fluids.WATER); dataSyncArray[3] = inputTank.getFluidAmount(); - dataSyncArray[4] = FluidIdHelper.getFluidId(inputTank.getFluidAmount() > 0 ? inputTank.getFluid().getFluid() : net.minecraft.init.Fluids.WATER); + dataSyncArray[4] = FluidIdHelper.getFluidId(inputTank.getFluidAmount() > 0 ? inputTank.getFluid().getFluid() : net.minecraft.fluid.Fluids.WATER); } @Override @@ -172,14 +172,14 @@ public void onDataFieldUpdate() { * @param tagRoot An NBT tag */ @Override - public NBTTagCompound write(final NBTTagCompound tagRoot) { + public CompoundNBT write(final CompoundNBT tagRoot) { super.write(tagRoot); - NBTTagCompound tankTag = new NBTTagCompound(); + CompoundNBT tankTag = new CompoundNBT(); this.getOutputTank().writeToNBT(tankTag); - tagRoot.setTag("TankOut", tankTag); - NBTTagCompound tankTag2 = new NBTTagCompound(); + tagRoot.put("TankOut", tankTag); + CompoundNBT tankTag2 = new CompoundNBT(); this.getInputTank().writeToNBT(tankTag2); - tagRoot.setTag("TankIn", tankTag2); + tagRoot.put("TankIn", tankTag2); return tagRoot; } /** @@ -187,21 +187,21 @@ public NBTTagCompound write(final NBTTagCompound tagRoot) { * @param tagRoot An NBT tag */ @Override - public void read(final NBTTagCompound tagRoot) { + public void read(final CompoundNBT tagRoot) { super.read(tagRoot); - if (tagRoot.hasKey("TankOut")) { - NBTTagCompound tankTag = tagRoot.getCompound("TankOut"); + if (tagRoot.contains("TankOut")) { + CompoundNBT tankTag = tagRoot.getCompound("TankOut"); getOutputTank().readFromNBT(tankTag); - if(tankTag.hasKey("Empty")){ + if(tankTag.contains("Empty")){ // empty the tank if NBT says its empty (not default behavior of Tank.read(...) ) getOutputTank().setFluid(null); } } - if (tagRoot.hasKey("TankIn")) { - NBTTagCompound tankTag = tagRoot.getCompound("TankIn"); + if (tagRoot.contains("TankIn")) { + CompoundNBT tankTag = tagRoot.getCompound("TankIn"); getInputTank().readFromNBT(tankTag); - if(tankTag.hasKey("Empty")){ + if(tankTag.contains("Empty")){ // empty the tank if NBT says its empty (not default behavior of Tank.read(...) ) getInputTank().setFluid(null); } @@ -319,7 +319,7 @@ private void distill(){ * @return true if this conduit can flow the given energy type through the given face, false * otherwise */ - public boolean canAcceptType(ConduitType type, EnumFacing blockFace){ + public boolean canAcceptType(ConduitType type, Direction blockFace){ return ConduitType.areSameType(Power.steam_power, type) || ConduitType.areSameType(Fluids.fluidConduit_general, type); } /** @@ -344,7 +344,7 @@ public boolean canAcceptType(ConduitType type){ * @param forReal if true, then the fluid in the tank will change */ @Override - public int fill(EnumFacing face, FluidStack fluid, boolean forReal) { + public int fill(Direction face, FluidStack fluid, boolean forReal) { if(fluid == null) return 0; if(getInputTank().getFluidAmount() <= 0 || getInputTank().getFluid().getFluid().equals(fluid.getFluid())){ if(canDistill(fluid)){ @@ -360,7 +360,7 @@ public int fill(EnumFacing face, FluidStack fluid, boolean forReal) { * @param forReal if true, then the fluid in the tank will change */ @Override - public FluidStack drain(EnumFacing face, FluidStack fluid, boolean forReal) { + public FluidStack drain(Direction face, FluidStack fluid, boolean forReal) { if(getOutputTank().getFluidAmount() > 0 && getOutputTank().getFluid().getFluid().equals(fluid.getFluid())){ return getOutputTank().drain(fluid.amount,forReal); } else { @@ -374,7 +374,7 @@ public FluidStack drain(EnumFacing face, FluidStack fluid, boolean forReal) { * @param forReal if true, then the fluid in the tank will change */ @Override - public FluidStack drain(EnumFacing face, int amount, boolean forReal) { + public FluidStack drain(Direction face, int amount, boolean forReal) { if(getOutputTank().getFluidAmount() > 0 ){ return getOutputTank().drain(amount,forReal); } else { @@ -387,7 +387,7 @@ public FluidStack drain(EnumFacing face, int amount, boolean forReal) { * @param fluid The fluid being added/removed */ @Override - public boolean canFill(EnumFacing face, Fluid fluid) { + public boolean canFill(Direction face, Fluid fluid) { if(fluid == null) return false; if(canDistill(fluid) == false) return false; if(getInputTank().getFluidAmount() <= 0) return true; @@ -399,7 +399,7 @@ public boolean canFill(EnumFacing face, Fluid fluid) { * @param fluid The fluid being added/removed */ @Override - public boolean canDrain(EnumFacing face, Fluid fluid) { + public boolean canDrain(Direction face, Fluid fluid) { if(fluid == null) return false; return getOutputTank().getFluidAmount() > 0 && fluid.equals(getOutputTank().getFluid().getFluid()); } @@ -410,7 +410,7 @@ public boolean canDrain(EnumFacing face, Fluid fluid) { * @return array of FluidTankInfo describing all of the FluidTanks */ @Override - public FluidTankInfo[] getTankInfo(EnumFacing face) { + public FluidTankInfo[] getTankInfo(Direction face) { FluidTankInfo[] arr = new FluidTankInfo[2]; arr[0] = getInputTank().getInfo(); arr[1] = getOutputTank().getInfo(); @@ -425,7 +425,7 @@ public boolean isItemValidForSlot(final int slot, final ItemStack item) { } @Override - public boolean isUsableByPlayer(EntityPlayer player) { + public boolean isUsableByPlayer(PlayerEntity player) { return true; } } diff --git a/src/main/java/zone/moddev/mc/steamadvantage/machines/SteamTankBlock.java b/src/main/java/zone/moddev/mc/steamadvantage/machines/SteamTankBlock.java index 114196e..9c3f526 100644 --- a/src/main/java/zone/moddev/mc/steamadvantage/machines/SteamTankBlock.java +++ b/src/main/java/zone/moddev/mc/steamadvantage/machines/SteamTankBlock.java @@ -4,7 +4,7 @@ import cyano.poweradvantage.api.PoweredEntity; import zone.moddev.mc.steamadvantage.init.Power; import net.minecraft.block.material.Material; -import net.minecraft.block.state.IBlockState; +import net.minecraft.block.BlockState; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -21,12 +21,12 @@ public PoweredEntity createNewTileEntity(net.minecraft.world.IBlockReader world) } @Override - public boolean hasComparatorInputOverride(IBlockState bs) { + public boolean hasComparatorInputOverride(BlockState bs) { return true; } @Override - public int getComparatorInputOverride(IBlockState bs, World world, BlockPos coord) { + public int getComparatorInputOverride(BlockState bs, World world, BlockPos coord) { TileEntity te = world.getTileEntity(coord); if(te instanceof SteamTankTileEntity){ return (int)(15 * ((SteamTankTileEntity)te).getSteamLevel()); diff --git a/src/main/java/zone/moddev/mc/steamadvantage/machines/SteamTankTileEntity.java b/src/main/java/zone/moddev/mc/steamadvantage/machines/SteamTankTileEntity.java index 8ddcef0..565362b 100644 --- a/src/main/java/zone/moddev/mc/steamadvantage/machines/SteamTankTileEntity.java +++ b/src/main/java/zone/moddev/mc/steamadvantage/machines/SteamTankTileEntity.java @@ -4,7 +4,7 @@ import cyano.poweradvantage.api.PowerRequest; import cyano.poweradvantage.api.fluid.FluidTank; import zone.moddev.mc.steamadvantage.init.Power; -import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.fluid.Fluid; @@ -116,7 +116,7 @@ public float getSteamLevel(){ } @Override - public boolean isUsableByPlayer(EntityPlayer player) { + public boolean isUsableByPlayer(PlayerEntity player) { return true; } } diff --git a/src/main/java/zone/moddev/mc/steamadvantage/migration/SteamLegacyMigrations.java b/src/main/java/zone/moddev/mc/steamadvantage/migration/SteamLegacyMigrations.java index 41803e8..a7e1c02 100644 --- a/src/main/java/zone/moddev/mc/steamadvantage/migration/SteamLegacyMigrations.java +++ b/src/main/java/zone/moddev/mc/steamadvantage/migration/SteamLegacyMigrations.java @@ -3,9 +3,9 @@ import cyano.poweradvantage.api.migration.LegacyMigrationApi; import cyano.poweradvantage.api.simple.BlockSimplePowerMachine; import net.minecraft.block.Block; -import net.minecraft.block.state.IBlockState; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.EnumFacing; +import net.minecraft.block.BlockState; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.util.Direction; import net.minecraft.util.ResourceLocation; import zone.moddev.mc.poweradvantage.blocks.BlockPowerSwitch; import zone.moddev.mc.steamadvantage.SteamAdvantage; @@ -56,7 +56,7 @@ private static void registerTile(String path) { LegacyMigrationApi.registerTileEntityAlias("minecraft:" + SteamAdvantage.MODID + "." + path, current); } - private static IBlockState decodeState(Block block, int metadata) { + private static BlockState decodeState(Block block, int metadata) { if (block instanceof SteamDrillBlock) { return block.getDefaultState().with(SteamDrillBlock.FACING, legacyDrillFacing(metadata)); } @@ -73,24 +73,24 @@ private static IBlockState decodeState(Block block, int metadata) { return block.getDefaultState(); } - static EnumFacing legacyDrillFacing(int metadata) { - return EnumFacing.byIndex(metadata % EnumFacing.values().length); + static Direction legacyDrillFacing(int metadata) { + return Direction.byIndex(metadata % Direction.values().length); } static int legacyPlatformHeight(int metadata) { return Math.min(metadata & 15, 4); } - static boolean repairPersistenceKeys(NBTTagCompound compound) { + static boolean repairPersistenceKeys(CompoundNBT compound) { String id = compound.getString("id"); boolean changed = false; if (isTile(id, "steam_pump") && !compound.contains("Tank", 10) && compound.contains("TankOut", 10)) { - compound.setTag("Tank", compound.getCompound("TankOut").copy()); + compound.put("Tank", compound.getCompound("TankOut").copy()); changed = true; } if (isTile(id, "steam_boiler_geothermal") && !compound.contains("Temperature", 99) && compound.contains("Tempoerature", 99)) { - compound.setFloat("Temperature", compound.getFloat("Tempoerature")); + compound.putFloat("Temperature", compound.getFloat("Tempoerature")); changed = true; } return changed; diff --git a/src/main/java/zone/moddev/mc/steamadvantage/recipe/RecipeConditions.java b/src/main/java/zone/moddev/mc/steamadvantage/recipe/RecipeConditions.java index 0238fd2..056984d 100644 --- a/src/main/java/zone/moddev/mc/steamadvantage/recipe/RecipeConditions.java +++ b/src/main/java/zone/moddev/mc/steamadvantage/recipe/RecipeConditions.java @@ -1,8 +1,12 @@ package zone.moddev.mc.steamadvantage.recipe; -import net.minecraft.util.JsonUtils; +import com.google.gson.JsonObject; +import java.util.Locale; +import net.minecraft.util.JSONUtils; import net.minecraft.util.ResourceLocation; import net.minecraftforge.common.crafting.CraftingHelper; +import net.minecraftforge.common.crafting.conditions.ICondition; +import net.minecraftforge.common.crafting.conditions.IConditionSerializer; import zone.moddev.mc.poweradvantage.PowerAdvantage; import zone.moddev.mc.poweradvantage.RecipeMode; import zone.moddev.mc.steamadvantage.SteamAdvantage; @@ -15,12 +19,34 @@ private RecipeConditions() {} public static synchronized void register() { if (registered) return; - CraftingHelper.register(new ResourceLocation(SteamAdvantage.MODID, "recipe_mode"), json -> { - RecipeMode expected = RecipeMode.valueOf(JsonUtils.getString(json, "mode").toUpperCase()); - return () -> PowerAdvantage.recipeMode == expected; + CraftingHelper.register(new IConditionSerializer() { + @Override public ResourceLocation getID() { return ModeCondition.ID; } + @Override public ModeCondition read(JsonObject json) { + return new ModeCondition(RecipeMode.valueOf(JSONUtils.getString(json, "mode").toUpperCase(Locale.ROOT))); + } + @Override public void write(JsonObject json, ModeCondition condition) { + json.addProperty("mode", condition.mode.name()); + } + }); + CraftingHelper.register(new IConditionSerializer() { + @Override public ResourceLocation getID() { return MusketCondition.ID; } + @Override public MusketCondition read(JsonObject json) { return new MusketCondition(); } + @Override public void write(JsonObject json, MusketCondition condition) {} }); - CraftingHelper.register(new ResourceLocation(SteamAdvantage.MODID, "musket_enabled"), - json -> () -> SteamAdvantage.MUSKET_ENABLE); registered = true; } + + private static final class ModeCondition implements ICondition { + private static final ResourceLocation ID = new ResourceLocation(SteamAdvantage.MODID, "recipe_mode"); + private final RecipeMode mode; + private ModeCondition(RecipeMode mode) { this.mode = mode; } + @Override public ResourceLocation getID() { return ID; } + @Override public boolean test() { return PowerAdvantage.recipeMode == mode; } + } + + private static final class MusketCondition implements ICondition { + private static final ResourceLocation ID = new ResourceLocation(SteamAdvantage.MODID, "musket_enabled"); + @Override public ResourceLocation getID() { return ID; } + @Override public boolean test() { return SteamAdvantage.MUSKET_ENABLE; } + } } diff --git a/src/main/java/zone/moddev/mc/steamadvantage/util/FurnaceFuelHelper.java b/src/main/java/zone/moddev/mc/steamadvantage/util/FurnaceFuelHelper.java index 28b8cba..2920f87 100644 --- a/src/main/java/zone/moddev/mc/steamadvantage/util/FurnaceFuelHelper.java +++ b/src/main/java/zone/moddev/mc/steamadvantage/util/FurnaceFuelHelper.java @@ -2,7 +2,7 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntityFurnace; +import net.minecraft.tileentity.AbstractFurnaceTileEntity; import net.minecraftforge.event.ForgeEventFactory; /** Forge-aware access to the vanilla furnace fuel calculation. */ @@ -14,7 +14,7 @@ public static int getBurnTime(ItemStack stack) { Item item = stack.getItem(); int itemBurnTime = stack.getBurnTime(); int vanillaBurnTime = itemBurnTime == -1 - ? TileEntityFurnace.getBurnTimes().getOrDefault(item, 0) + ? AbstractFurnaceTileEntity.getBurnTimes().getOrDefault(item, 0) : itemBurnTime; return ForgeEventFactory.getItemBurnTime(stack, vanillaBurnTime); } diff --git a/src/main/java/zone/moddev/mc/steamadvantage/util/SoundHelper.java b/src/main/java/zone/moddev/mc/steamadvantage/util/SoundHelper.java index 4a1c4d1..59c8580 100644 --- a/src/main/java/zone/moddev/mc/steamadvantage/util/SoundHelper.java +++ b/src/main/java/zone/moddev/mc/steamadvantage/util/SoundHelper.java @@ -1,7 +1,7 @@ package zone.moddev.mc.steamadvantage.util; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.network.play.server.SPacketCustomSound; +import net.minecraft.entity.player.ServerPlayerEntity; +import net.minecraft.network.play.server.SPlaySoundPacket; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.SoundCategory; import net.minecraft.util.SoundEvent; @@ -23,11 +23,11 @@ public static void playSoundAtTileEntity(SoundEvent sound, SoundCategory soundTy public static void playSoundAtPosition(double x, double y, double z, SoundEvent sound, SoundCategory soundType, float volume, float pitch, World serverWorld){ if(serverWorld.isRemote) return; final double range = 16; - List players = serverWorld.getEntitiesWithinAABB(EntityPlayerMP.class, new AxisAlignedBB( + List players = serverWorld.getEntitiesWithinAABB(ServerPlayerEntity.class, new AxisAlignedBB( x - range, y - range, z - range, x + range, y + range, z + range)); - for(EntityPlayerMP player : players){ - player.connection.sendPacket(new SPacketCustomSound(sound.getRegistryName(), soundType, + for(ServerPlayerEntity player : players){ + player.connection.sendPacket(new SPlaySoundPacket(sound.getRegistryName(), soundType, new Vec3d(x, y, z), volume, pitch)); } } @@ -35,11 +35,11 @@ public static void playSoundAtPosition(double x, double y, double z, SoundEvent public static void playBigSoundAtPosition(double x, double y, double z, SoundEvent sound, SoundCategory soundType, float volume, float pitch, World serverWorld){ if(serverWorld.isRemote) return; final double range = 50; - List players = serverWorld.getEntitiesWithinAABB(EntityPlayerMP.class, new AxisAlignedBB( + List players = serverWorld.getEntitiesWithinAABB(ServerPlayerEntity.class, new AxisAlignedBB( x - range, y - range, z - range, x + range, y + range, z + range)); - for(EntityPlayerMP player : players){ - player.connection.sendPacket(new SPacketCustomSound(sound.getRegistryName(), soundType, + for(ServerPlayerEntity player : players){ + player.connection.sendPacket(new SPlaySoundPacket(sound.getRegistryName(), soundType, new Vec3d(x, y, z), volume, pitch)); } } diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index f035bd6..4aee25d 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -14,14 +14,14 @@ description='''Steam-powered machines and infrastructure for the Power Advantage [[dependencies.steamadvantage]] modId="poweradvantage" mandatory=true -versionRange="[2.4.4.113021,3.0.0)" +versionRange="[2.4.5.114041,3.0.0)" ordering="AFTER" side="BOTH" [[dependencies.steamadvantage]] modId="basemetals" mandatory=false -versionRange="[3.0.1.113021,4.0.0)" +versionRange="[3.0.1.114041,4.0.0)" ordering="AFTER" side="BOTH" diff --git a/src/main/resources/data/steamadvantage/loot_tables/blocks/steam_boiler_coal.json b/src/main/resources/data/steamadvantage/loot_tables/blocks/steam_boiler_coal.json new file mode 100644 index 0000000..52d3197 --- /dev/null +++ b/src/main/resources/data/steamadvantage/loot_tables/blocks/steam_boiler_coal.json @@ -0,0 +1,4 @@ +{ + "type": "minecraft:block", + "pools": [{"rolls": 1, "entries": [{"type": "minecraft:item", "name": "steamadvantage:steam_boiler_coal"}], "conditions": [{"condition": "minecraft:survives_explosion"}]}] +} diff --git a/src/main/resources/data/steamadvantage/loot_tables/blocks/steam_boiler_electric.json b/src/main/resources/data/steamadvantage/loot_tables/blocks/steam_boiler_electric.json new file mode 100644 index 0000000..31528b9 --- /dev/null +++ b/src/main/resources/data/steamadvantage/loot_tables/blocks/steam_boiler_electric.json @@ -0,0 +1,4 @@ +{ + "type": "minecraft:block", + "pools": [{"rolls": 1, "entries": [{"type": "minecraft:item", "name": "steamadvantage:steam_boiler_electric"}], "conditions": [{"condition": "minecraft:survives_explosion"}]}] +} diff --git a/src/main/resources/data/steamadvantage/loot_tables/blocks/steam_boiler_geothermal.json b/src/main/resources/data/steamadvantage/loot_tables/blocks/steam_boiler_geothermal.json new file mode 100644 index 0000000..087e912 --- /dev/null +++ b/src/main/resources/data/steamadvantage/loot_tables/blocks/steam_boiler_geothermal.json @@ -0,0 +1,4 @@ +{ + "type": "minecraft:block", + "pools": [{"rolls": 1, "entries": [{"type": "minecraft:item", "name": "steamadvantage:steam_boiler_geothermal"}], "conditions": [{"condition": "minecraft:survives_explosion"}]}] +} diff --git a/src/main/resources/data/steamadvantage/loot_tables/blocks/steam_boiler_oil.json b/src/main/resources/data/steamadvantage/loot_tables/blocks/steam_boiler_oil.json new file mode 100644 index 0000000..41f6305 --- /dev/null +++ b/src/main/resources/data/steamadvantage/loot_tables/blocks/steam_boiler_oil.json @@ -0,0 +1,4 @@ +{ + "type": "minecraft:block", + "pools": [{"rolls": 1, "entries": [{"type": "minecraft:item", "name": "steamadvantage:steam_boiler_oil"}], "conditions": [{"condition": "minecraft:survives_explosion"}]}] +} diff --git a/src/main/resources/data/steamadvantage/loot_tables/blocks/steam_crusher.json b/src/main/resources/data/steamadvantage/loot_tables/blocks/steam_crusher.json new file mode 100644 index 0000000..bbb3022 --- /dev/null +++ b/src/main/resources/data/steamadvantage/loot_tables/blocks/steam_crusher.json @@ -0,0 +1,4 @@ +{ + "type": "minecraft:block", + "pools": [{"rolls": 1, "entries": [{"type": "minecraft:item", "name": "steamadvantage:steam_crusher"}], "conditions": [{"condition": "minecraft:survives_explosion"}]}] +} diff --git a/src/main/resources/data/steamadvantage/loot_tables/blocks/steam_drill.json b/src/main/resources/data/steamadvantage/loot_tables/blocks/steam_drill.json new file mode 100644 index 0000000..24f06cc --- /dev/null +++ b/src/main/resources/data/steamadvantage/loot_tables/blocks/steam_drill.json @@ -0,0 +1,4 @@ +{ + "type": "minecraft:block", + "pools": [{"rolls": 1, "entries": [{"type": "minecraft:item", "name": "steamadvantage:steam_drill"}], "conditions": [{"condition": "minecraft:survives_explosion"}]}] +} diff --git a/src/main/resources/data/steamadvantage/loot_tables/blocks/steam_elevator.json b/src/main/resources/data/steamadvantage/loot_tables/blocks/steam_elevator.json new file mode 100644 index 0000000..5706289 --- /dev/null +++ b/src/main/resources/data/steamadvantage/loot_tables/blocks/steam_elevator.json @@ -0,0 +1,4 @@ +{ + "type": "minecraft:block", + "pools": [{"rolls": 1, "entries": [{"type": "minecraft:item", "name": "steamadvantage:steam_elevator"}], "conditions": [{"condition": "minecraft:survives_explosion"}]}] +} diff --git a/src/main/resources/data/steamadvantage/loot_tables/blocks/steam_furnace.json b/src/main/resources/data/steamadvantage/loot_tables/blocks/steam_furnace.json new file mode 100644 index 0000000..dcebd5b --- /dev/null +++ b/src/main/resources/data/steamadvantage/loot_tables/blocks/steam_furnace.json @@ -0,0 +1,4 @@ +{ + "type": "minecraft:block", + "pools": [{"rolls": 1, "entries": [{"type": "minecraft:item", "name": "steamadvantage:steam_furnace"}], "conditions": [{"condition": "minecraft:survives_explosion"}]}] +} diff --git a/src/main/resources/data/steamadvantage/loot_tables/blocks/steam_pipe.json b/src/main/resources/data/steamadvantage/loot_tables/blocks/steam_pipe.json new file mode 100644 index 0000000..ec6970d --- /dev/null +++ b/src/main/resources/data/steamadvantage/loot_tables/blocks/steam_pipe.json @@ -0,0 +1,4 @@ +{ + "type": "minecraft:block", + "pools": [{"rolls": 1, "entries": [{"type": "minecraft:item", "name": "steamadvantage:steam_pipe"}], "conditions": [{"condition": "minecraft:survives_explosion"}]}] +} diff --git a/src/main/resources/data/steamadvantage/loot_tables/blocks/steam_pump.json b/src/main/resources/data/steamadvantage/loot_tables/blocks/steam_pump.json new file mode 100644 index 0000000..668b722 --- /dev/null +++ b/src/main/resources/data/steamadvantage/loot_tables/blocks/steam_pump.json @@ -0,0 +1,4 @@ +{ + "type": "minecraft:block", + "pools": [{"rolls": 1, "entries": [{"type": "minecraft:item", "name": "steamadvantage:steam_pump"}], "conditions": [{"condition": "minecraft:survives_explosion"}]}] +} diff --git a/src/main/resources/data/steamadvantage/loot_tables/blocks/steam_still.json b/src/main/resources/data/steamadvantage/loot_tables/blocks/steam_still.json new file mode 100644 index 0000000..cc4a602 --- /dev/null +++ b/src/main/resources/data/steamadvantage/loot_tables/blocks/steam_still.json @@ -0,0 +1,4 @@ +{ + "type": "minecraft:block", + "pools": [{"rolls": 1, "entries": [{"type": "minecraft:item", "name": "steamadvantage:steam_still"}], "conditions": [{"condition": "minecraft:survives_explosion"}]}] +} diff --git a/src/main/resources/data/steamadvantage/loot_tables/blocks/steam_switch.json b/src/main/resources/data/steamadvantage/loot_tables/blocks/steam_switch.json new file mode 100644 index 0000000..f44009c --- /dev/null +++ b/src/main/resources/data/steamadvantage/loot_tables/blocks/steam_switch.json @@ -0,0 +1,4 @@ +{ + "type": "minecraft:block", + "pools": [{"rolls": 1, "entries": [{"type": "minecraft:item", "name": "steamadvantage:steam_switch"}], "conditions": [{"condition": "minecraft:survives_explosion"}]}] +} diff --git a/src/main/resources/data/steamadvantage/loot_tables/blocks/steam_tank.json b/src/main/resources/data/steamadvantage/loot_tables/blocks/steam_tank.json new file mode 100644 index 0000000..5aca3a2 --- /dev/null +++ b/src/main/resources/data/steamadvantage/loot_tables/blocks/steam_tank.json @@ -0,0 +1,4 @@ +{ + "type": "minecraft:block", + "pools": [{"rolls": 1, "entries": [{"type": "minecraft:item", "name": "steamadvantage:steam_tank"}], "conditions": [{"condition": "minecraft:survives_explosion"}]}] +} diff --git a/src/main/resources/data/steamadvantage/loot_tables/blocks/steam_track.json b/src/main/resources/data/steamadvantage/loot_tables/blocks/steam_track.json new file mode 100644 index 0000000..bf38f1f --- /dev/null +++ b/src/main/resources/data/steamadvantage/loot_tables/blocks/steam_track.json @@ -0,0 +1,4 @@ +{ + "type": "minecraft:block", + "pools": [{"rolls": 1, "entries": [{"type": "minecraft:item", "name": "steamadvantage:steam_track"}], "conditions": [{"condition": "minecraft:survives_explosion"}]}] +} diff --git a/src/main/resources/pack.mcmeta b/src/main/resources/pack.mcmeta index ef14101..8be9850 100644 --- a/src/main/resources/pack.mcmeta +++ b/src/main/resources/pack.mcmeta @@ -1,6 +1,6 @@ { "pack":{ - "pack_format":3, + "pack_format":4, "description":"Steam Advantage" } } diff --git a/src/test/java/zone/moddev/mc/steamadvantage/blocks/DrillBitPersistenceTest.java b/src/test/java/zone/moddev/mc/steamadvantage/blocks/DrillBitPersistenceTest.java new file mode 100644 index 0000000..5fa588d --- /dev/null +++ b/src/test/java/zone/moddev/mc/steamadvantage/blocks/DrillBitPersistenceTest.java @@ -0,0 +1,40 @@ +package zone.moddev.mc.steamadvantage.blocks; + +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.util.Direction; +import org.junit.Test; +import static org.junit.Assert.*; + +public class DrillBitPersistenceTest { + @Test public void allSixDirectionsSurviveNativeUpdatePackets() { + for (Direction direction : Direction.values()) { + DrillBitTileEntity tile = new DrillBitTileEntity(); + tile.setDirection(direction); + CompoundNBT packet = tile.getUpdatePacket().getNbtCompound(); + assertEquals(direction.getIndex(), packet.getByte("dir")); + DrillBitTileEntity restored = new DrillBitTileEntity(); + restored.onDataPacket(null, tile.getUpdatePacket()); + assertEquals(direction.getAxis(), restored.getDirection()); + assertEquals(direction.getIndex(), restored.getUpdatePacket().getNbtCompound().getByte("dir")); + } + } + + @Test public void oldDirectionKeyRemainsReadableAndCanonicalKeyWins() { + CompoundNBT tag = new CompoundNBT(); + tag.putByte("d", (byte) Direction.EAST.getIndex()); + DrillBitTileEntity tile = new DrillBitTileEntity(); + tile.read(tag); + assertEquals(Direction.Axis.X, tile.getDirection()); + tag.putByte("dir", (byte) Direction.NORTH.getIndex()); + tile.read(tag); + assertEquals(Direction.Axis.Z, tile.getDirection()); + } + + @Test public void invalidDirectionFallsBackToDown() { + CompoundNBT tag = new CompoundNBT(); + tag.putByte("dir", (byte) 127); + DrillBitTileEntity tile = new DrillBitTileEntity(); + tile.read(tag); + assertEquals(Direction.DOWN.getIndex(), tile.getUpdatePacket().getNbtCompound().getByte("dir")); + } +} diff --git a/src/test/java/zone/moddev/mc/steamadvantage/items/MusketPersistenceTest.java b/src/test/java/zone/moddev/mc/steamadvantage/items/MusketPersistenceTest.java new file mode 100644 index 0000000..8a491f5 --- /dev/null +++ b/src/test/java/zone/moddev/mc/steamadvantage/items/MusketPersistenceTest.java @@ -0,0 +1,45 @@ +package zone.moddev.mc.steamadvantage.items; + +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.util.math.Vec3d; +import org.junit.Test; +import org.junit.BeforeClass; +import static org.junit.Assert.*; + +public class MusketPersistenceTest { + @BeforeClass public static void bootstrapNativeRegistries() { + net.minecraft.util.registry.Bootstrap.register(); + } + + @Test public void loadingCycleKeepsLegacyByteValuesAndOtherNbt() { + ItemStack stack = new ItemStack(net.minecraft.item.Items.STICK); + CompoundNBT tag = new CompoundNBT(); + tag.putString("owner", "legacy"); + stack.setTag(tag); + assertTrue(MusketItem.isNotLoaded(stack)); + MusketItem.startLoad(stack); + assertEquals(2, stack.getTag().getByte("loaded")); + assertTrue(MusketItem.isAlmostLoaded(stack)); + MusketItem.finishLoad(stack); + assertEquals(1, stack.getTag().getByte("loaded")); + assertTrue(MusketItem.isLoaded(stack.copy())); + MusketItem.unload(stack); + assertEquals(0, stack.getTag().getByte("loaded")); + assertTrue(MusketItem.isNotLoaded(stack)); + assertEquals("legacy", stack.getTag().getString("owner")); + } + + @Test public void rayIntersectionSupportsEveryAxisAndRejectsTargetsBehind() { + Vec3d origin = new Vec3d(0, 0, 0); + for (net.minecraft.util.Direction direction : net.minecraft.util.Direction.values()) { + Vec3d ray = new Vec3d(direction.getXOffset(), direction.getYOffset(), direction.getZOffset()); + Vec3d center = ray.scale(5); + AxisAlignedBB ahead = new AxisAlignedBB(center.x - 0.5, center.y - 0.5, center.z - 0.5, + center.x + 0.5, center.y + 0.5, center.z + 0.5); + assertTrue(MusketItem.rayIntersectsBoundingBox(origin, ray, ahead)); + assertFalse(MusketItem.rayIntersectsBoundingBox(origin, ray.scale(-1), ahead)); + } + } +} diff --git a/src/test/java/zone/moddev/mc/steamadvantage/machines/SteamDrillPersistenceTest.java b/src/test/java/zone/moddev/mc/steamadvantage/machines/SteamDrillPersistenceTest.java index 84a850f..6fd6c4f 100644 --- a/src/test/java/zone/moddev/mc/steamadvantage/machines/SteamDrillPersistenceTest.java +++ b/src/test/java/zone/moddev/mc/steamadvantage/machines/SteamDrillPersistenceTest.java @@ -1,11 +1,33 @@ package zone.moddev.mc.steamadvantage.machines; -import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.nbt.ListNBT; +import net.minecraft.item.ItemStack; +import net.minecraft.util.Direction; +import net.minecraft.util.math.BlockPos; +import zone.moddev.mc.steamadvantage.init.Power; +import java.lang.reflect.Field; +import java.io.InputStream; +import java.lang.reflect.Method; import org.junit.Test; +import org.junit.BeforeClass; +import org.objectweb.asm.ClassReader; +import org.objectweb.asm.tree.AbstractInsnNode; +import org.objectweb.asm.tree.ClassNode; +import org.objectweb.asm.tree.FieldInsnNode; +import org.objectweb.asm.tree.MethodInsnNode; +import org.objectweb.asm.tree.MethodNode; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; public class SteamDrillPersistenceTest { + @BeforeClass public static void bootstrapNativeRegistries() { + net.minecraft.util.registry.Bootstrap.register(); + } + @Test public void retainsLegacyProgressUntilWorldIsAttached() { SteamDrillTileEntity drill = new SteamDrillTileEntity(); drill.read(target(94)); @@ -16,17 +38,112 @@ public class SteamDrillPersistenceTest { @Test public void clearsPreviousProgressOnReadingAnUntargetedTile() { SteamDrillTileEntity drill = new SteamDrillTileEntity(); drill.read(target(94)); - drill.read(new NBTTagCompound()); + drill.read(new CompoundNBT()); drill.prepareDataFieldsForSync(); assertEquals(0, drill.getDataFieldArray()[1]); } - private static NBTTagCompound target(int progress) { - NBTTagCompound tag = new NBTTagCompound(); - tag.setShort("progress", (short) progress); - tag.setInt("targetX", 2048); - tag.setInt("targetY", 80); - tag.setInt("targetZ", 2049); + @Test public void preservesAllSixFacingsTargetAndWorkUntilWorldIsAttached() throws Exception { + for (Direction facing : Direction.values()) { + CompoundNBT tag = target(94); + tag.putByte("Facing", (byte) facing.getIndex()); + CompoundNBT state = new CompoundNBT(); + state.putString("Name", "minecraft:stone"); + tag.put("TargetState", state); + SteamDrillTileEntity drill = new SteamDrillTileEntity(); + drill.read(tag); + assertEquals(facing, field(drill, "savedFacing")); + assertEquals(new BlockPos(2048, 80, 2049), field(drill, "targetBlockCoord")); + assertEquals(state, field(drill, "savedTargetState")); + assertTrue((Boolean) field(drill, "deferred")); + drill.prepareDataFieldsForSync(); + assertEquals(94, drill.getDataFieldArray()[1]); + } + } + + @Test public void loadingAnotherTileDoesNotKeepPreviousFacing() throws Exception { + SteamDrillTileEntity drill = new SteamDrillTileEntity(); + CompoundNBT tag = target(94); + tag.putByte("Facing", (byte) Direction.UP.getIndex()); + drill.read(tag); + drill.read(target(12)); + assertNull(field(drill, "savedFacing")); + tag.putByte("Facing", (byte) 127); + drill.read(tag); + assertNull(field(drill, "savedFacing")); + } + + @Test public void legacyEnergyAndOutputInventorySurviveDeferredRestore() { + CompoundNBT tag = target(94); + tag.putIntArray("Energy", new int[] { Float.floatToIntBits(37.5F) }); + ListNBT items = new ListNBT(); + CompoundNBT stack = new CompoundNBT(); + stack.putString("id", "minecraft:cobblestone"); + stack.putByte("Count", (byte) 23); + stack.putByte("Slot", (byte) 4); + items.add(stack); + tag.put("Items", items); + SteamDrillTileEntity drill = new SteamDrillTileEntity(); + drill.read(tag); + assertEquals(37.5F, drill.getEnergy(Power.steam_power), 0.0F); + ItemStack output = drill.getStackInSlot(4); + assertEquals(net.minecraft.item.Items.COBBLESTONE, output.getItem()); + assertEquals(23, output.getCount()); + } + + @Test public void serializationNeverLooksUpTheWorldOrInfersNeighbours() throws Exception { + ClassNode node = new ClassNode(); + try (InputStream input = SteamDrillTileEntity.class.getResourceAsStream("SteamDrillTileEntity.class")) { + new ClassReader(input).accept(node, 0); + } + int methods = 0, cachedFacingReads = 0; + for (MethodNode method : node.methods) { + if (!method.name.equals("write")) continue; + methods++; + for (AbstractInsnNode instruction : method.instructions.toArray()) { + if (instruction instanceof FieldInsnNode + && ((FieldInsnNode) instruction).name.equals("savedFacing")) cachedFacingReads++; + if (!(instruction instanceof MethodInsnNode)) continue; + MethodInsnNode call = (MethodInsnNode) instruction; + assertFalse("Serialization must not reacquire a saving chunk: " + call.name, + call.name.equals("getFacing") || call.name.equals("inferFacing") + || call.name.equals("powerAdvantageWorld") || call.owner.startsWith("net/minecraft/world/")); + } + } + assertEquals(1, methods); + assertTrue("Cached facing must still be serialized", cachedFacingReads > 0); + } + + @Test public void facinglessLegacyTargetsInferAllDirectionsWithoutAnAttachedWorld() throws Exception { + Method infer = SteamDrillTileEntity.class.getDeclaredMethod("inferFacing"); + infer.setAccessible(true); + BlockPos origin = new BlockPos(2048, 80, 2048); + for (Direction direction : Direction.values()) { + CompoundNBT tag = target(94); + BlockPos target = origin.offset(direction, 3); + tag.putInt("targetX", target.getX()); + tag.putInt("targetY", target.getY()); + tag.putInt("targetZ", target.getZ()); + SteamDrillTileEntity drill = new SteamDrillTileEntity(); + drill.read(tag); + drill.setPos(origin); + assertNull(field(drill, "savedFacing")); + assertEquals(direction, infer.invoke(drill)); + } + } + + private static Object field(SteamDrillTileEntity drill, String name) throws Exception { + Field field = SteamDrillTileEntity.class.getDeclaredField(name); + field.setAccessible(true); + return field.get(drill); + } + + private static CompoundNBT target(int progress) { + CompoundNBT tag = new CompoundNBT(); + tag.putShort("progress", (short) progress); + tag.putInt("targetX", 2048); + tag.putInt("targetY", 80); + tag.putInt("targetZ", 2049); return tag; } } diff --git a/src/test/java/zone/moddev/mc/steamadvantage/migration/SteamLegacyMigrationsTest.java b/src/test/java/zone/moddev/mc/steamadvantage/migration/SteamLegacyMigrationsTest.java index 5a82a4a..6df1471 100644 --- a/src/test/java/zone/moddev/mc/steamadvantage/migration/SteamLegacyMigrationsTest.java +++ b/src/test/java/zone/moddev/mc/steamadvantage/migration/SteamLegacyMigrationsTest.java @@ -5,13 +5,13 @@ import static org.junit.Assert.assertTrue; import cyano.poweradvantage.api.migration.LegacyMigrationApi; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.EnumFacing; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.util.Direction; import org.junit.Test; public class SteamLegacyMigrationsTest { @Test public void preservesAllSixDrillFacings() { - for (EnumFacing facing : EnumFacing.values()) { + for (Direction facing : Direction.values()) { assertEquals(facing, SteamLegacyMigrations.legacyDrillFacing(facing.getIndex())); } } @@ -23,24 +23,24 @@ public class SteamLegacyMigrationsTest { } @Test public void repairsLegacyPumpAndGeothermalKeysWithoutOverwritingCanonicalState() { - NBTTagCompound pump = new NBTTagCompound(); - pump.setString("id", "steamadvantage.steam_pump"); - NBTTagCompound oldTank = new NBTTagCompound(); - oldTank.setInt("Amount", 1250); - pump.setTag("TankOut", oldTank); + CompoundNBT pump = new CompoundNBT(); + pump.putString("id", "steamadvantage.steam_pump"); + CompoundNBT oldTank = new CompoundNBT(); + oldTank.putInt("Amount", 1250); + pump.put("TankOut", oldTank); assertTrue(SteamLegacyMigrations.repairPersistenceKeys(pump)); assertEquals(1250, pump.getCompound("Tank").getInt("Amount")); - NBTTagCompound boiler = new NBTTagCompound(); - boiler.setString("id", "steamadvantage:steam_boiler_geothermal"); - boiler.setFloat("Tempoerature", 412.5F); + CompoundNBT boiler = new CompoundNBT(); + boiler.putString("id", "steamadvantage:steam_boiler_geothermal"); + boiler.putFloat("Tempoerature", 412.5F); assertTrue(SteamLegacyMigrations.repairPersistenceKeys(boiler)); assertEquals(412.5F, boiler.getFloat("Temperature"), 0.0F); - NBTTagCompound canonical = new NBTTagCompound(); - canonical.setString("id", "steamadvantage:steam_boiler_geothermal"); - canonical.setFloat("Temperature", 500.0F); - canonical.setFloat("Tempoerature", 100.0F); + CompoundNBT canonical = new CompoundNBT(); + canonical.putString("id", "steamadvantage:steam_boiler_geothermal"); + canonical.putFloat("Temperature", 500.0F); + canonical.putFloat("Tempoerature", 100.0F); assertFalse(SteamLegacyMigrations.repairPersistenceKeys(canonical)); assertEquals(500.0F, canonical.getFloat("Temperature"), 0.0F); } diff --git a/src/test/java/zone/moddev/mc/steamadvantage/resources/NativeLootContractTest.java b/src/test/java/zone/moddev/mc/steamadvantage/resources/NativeLootContractTest.java new file mode 100644 index 0000000..b320881 --- /dev/null +++ b/src/test/java/zone/moddev/mc/steamadvantage/resources/NativeLootContractTest.java @@ -0,0 +1,51 @@ +package zone.moddev.mc.steamadvantage.resources; + +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import java.io.Reader; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import org.junit.Test; +import static org.junit.Assert.*; + +public class NativeLootContractTest { + private static final Path ROOT = Paths.get("src/main/resources"); + private static final Path TABLES = ROOT.resolve("data/steamadvantage/loot_tables/blocks"); + + @Test public void ordinaryBlocksKeepOneSelfDropWithExplosionSurvival() throws Exception { + for (String id : new String[] { "steam_pipe", "steam_track", "steam_boiler_coal", + "steam_boiler_electric", "steam_boiler_geothermal", "steam_tank", "steam_furnace", + "steam_crusher", "steam_drill", "steam_elevator", "steam_switch", "steam_still", + "steam_pump", "steam_boiler_oil" }) { + JsonObject table = read(TABLES.resolve(id + ".json")); + assertEquals("minecraft:block", table.get("type").getAsString()); + assertEquals(1, table.getAsJsonArray("pools").size()); + JsonObject pool = table.getAsJsonArray("pools").get(0).getAsJsonObject(); + assertEquals(1, pool.get("rolls").getAsInt()); + assertEquals(1, pool.getAsJsonArray("entries").size()); + JsonObject entry = pool.getAsJsonArray("entries").get(0).getAsJsonObject(); + assertEquals("minecraft:item", entry.get("type").getAsString()); + assertEquals("steamadvantage:" + id, entry.get("name").getAsString()); + assertEquals("minecraft:survives_explosion", pool.getAsJsonArray("conditions") + .get(0).getAsJsonObject().get("condition").getAsString()); + } + } + + @Test public void helpersHaveNoSelfDropTables() { + for (String id : new String[] { "drillbit", "platform", "pump_pipe_steam" }) { + assertFalse(id, Files.exists(TABLES.resolve(id + ".json"))); + } + } + + @Test public void packUsesNative114Format() throws Exception { + assertEquals(4, read(ROOT.resolve("pack.mcmeta")).getAsJsonObject("pack").get("pack_format").getAsInt()); + } + + private static JsonObject read(Path path) throws Exception { + try (Reader reader = Files.newBufferedReader(path, StandardCharsets.UTF_8)) { + return new JsonParser().parse(reader).getAsJsonObject(); + } + } +}