diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 20e0da7..f8d1d27 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,16 +1,16 @@ -name: Electric Advantage 1.13 CI +name: Electric 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: electricadvantage-1.13-${{ github.workflow }}-${{ github.ref }} + group: electricadvantage-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: ElectricAdvantage-1.13.2-${{ github.sha }} + name: ElectricAdvantage-1.14.4-${{ github.sha }} if-no-files-found: error retention-days: 30 path: | - build/libs/ElectricAdvantage-2.2.5.113021.jar - build/libs/ElectricAdvantage-2.2.5.113021-sources.jar - build/libs/ElectricAdvantage-2.2.5.113021-javadoc.jar + build/libs/ElectricAdvantage-2.2.6.114041.jar + build/libs/ElectricAdvantage-2.2.6.114041-sources.jar + build/libs/ElectricAdvantage-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: ElectricAdvantage-1.13.2-diagnostics-${{ github.sha }} + name: ElectricAdvantage-1.14.4-diagnostics-${{ github.sha }} if-no-files-found: ignore retention-days: 14 path: | @@ -108,3 +110,4 @@ jobs: build/*-run/logs/** build/problems/** .ci-dependencies/PowerAdvantage/build/reports/** + .ci-dependencies/PowerAdvantage/build/libs-dev/*.jar diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index a2f0ab8..8389dd9 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: '59 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 56a64fd..36af649 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,3 +1,18 @@ +Electric Advantage 2.2.6.114041 + +- Target Minecraft 1.14.4 and Forge 28.2.26 using native platform classes and Java 8 production bytecode. +- Adapt machine state callbacks, shapes, smelting lookup, food detection, entity registration and spawn packets. +- Retain the shared native container API and use blit and the 1.14 GlStateManager for GUI/rendering code. +- Replace removed villager careers with librarian trade events, preserving offer levels, base quantities and prices. +- Use native condition serializers without changing recipe-mode IDs or JSON inputs. +- Use native block-loot lookup for drills and crops, and provide ordinary machine/conduit item-drop tables. +- Preserve runtime IDs, legacy migration aliases, NBT keys, drill geometry/costs and OreSpawn provider names. +- Resolve native crop blocks through IPlantable and retain deferred growth/progress NBT before world attachment. +- Add focused persistence, direction, geometry, recipe-mode, trade and resource regression tests. +- Native production/test compilation, all 34 unit tests and the development-jar build passed locally; no tests were skipped. +- Pass 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. + Electric 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 965056c..15ea4e3 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,26 @@ # ElectricAdvantage -Electric Advantage adds electric machines, generation, storage, automation, and defence to Power Advantage for Minecraft 1.13.2. +**Minecraft 1.14.4 port, version 2.2.6.114041.** Native compilation and all 34 unit +tests pass, with no tests skipped. 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. + +Electric Advantage adds electric machines, generation, storage, automation, and defence to Power Advantage for Minecraft 1.14.4. Every crafting and vanilla smelting 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) and [manufacturing progression audit](https://github.com/MinecraftModDevelopmentMods/PowerAdvantage/blob/master-1.13.2/docs/1.13/MANUFACTURING-PROGRESSION.md). Regenerate unlock JSON after recipe changes with `node tools/generate-recipe-unlocks.js`; `check` audits recipe coverage and criteria. Custom machine and crushing recipes are not crafting-book entries. -## 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`, mappings `snapshot 20190719-1.14.3`, +and MCP `20190829.143755`, using 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 @@ -17,7 +28,13 @@ cd ..\..\PowerAdvantage gradlew.bat deobfJar ``` -Then build ElectricAdvantage: +For local development with the matching native jars, compile and run tests: + +```text +gradlew.bat classes test deobfJar +``` + +With the exact Power dependency pinned, run the complete release gates: ```text gradlew.bat clean check build javadoc verifyReleaseDependencies verifyReleaseArtifacts writeReleaseChecksums verifyEclipseProductionClasspath @@ -37,9 +54,14 @@ 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. +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. Resource checks do not replace gameplay testing. + +Automated coverage is bounded to the recorded scenarios. It does not establish every +in-world GUI, rendering, sound, control or weapon interaction, multiplayer behavior, +or compatibility with arbitrary third-party mods. Unit/resource tests alone are not +runtime or world-upgrade evidence. The implementation namespace is `zone.moddev.mc.electricadvantage`. Runtime identities, registries, tile/entity IDs, NBT, recipes, tags, OreSpawn provider IDs, and assets remain stable. Electric registers its legacy state, tile, and hydroturbine aliases with PowerAdvantage's shared migration hook. The RF- and Tech Reborn-labelled converters belong to Power Advantage and now use Forge Energy. -Read the [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 90bb6ad..61ea1c2 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 { electricadvantage { 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 ElectricAdvantage 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/electricadvantage/ElectricAdvantage.java').getText('UTF-8') if (!mainSource.contains('MODID = "electricadvantage"') - || !mainSource.contains('VERSION = "2.2.5.113021"')) { + || !mainSource.contains('VERSION = "2.2.6.114041"')) { throw new GradleException('ElectricAdvantage source identity changed') } String metadata = file('src/main/resources/META-INF/mods.toml').getText('UTF-8').replace('\r\n', '\n') ['modId="electricadvantage"', '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}") } @@ -415,14 +416,14 @@ tasks.register('verifyReleaseDependencies') { } } def manifest = new Manifest(zip.getInputStream(zip.getEntry('META-INF/MANIFEST.MF'))).mainAttributes - if (manifest.getValue('Implementation-Version') != project.poweradvantage_version) { + if (manifest.getValue('Implementation-Version') != project.poweradvantage_version + || manifest.getValue('Built-On') != '1.14.4-28.2.26') { throw new GradleException('PowerAdvantage dependency manifest has the wrong version') } } 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) } @@ -503,7 +504,11 @@ tasks.register('verifyReleaseArtifacts') { 'zone/moddev/mc/electricadvantage/machines/HydroelectricGeneratorTileEntity.class', 'zone/moddev/mc/electricadvantage/migration/ElectricLegacyMigrations.class', 'zone/moddev/mc/electricadvantage/init/OreSpawnWorldGen.class', + 'zone/moddev/mc/electricadvantage/init/Villages.class', + 'zone/moddev/mc/electricadvantage/recipe/RecipeConditions$ModeSerializer.class', 'assets/electricadvantage/lang/en_us.json', + 'data/electricadvantage/loot_tables/blocks/electric_drill.json', + 'data/electricadvantage/loot_tables/blocks/electric_conduit.json', 'data/electricadvantage/recipes/electric_conduit_plastic_ingot.json', 'data/electricadvantage/advancements/recipes/integrated_circuit_copper_normal.json', 'data/forge/tags/items/ores/lithium.json'].each { required -> diff --git a/gradle.properties b/gradle.properties index 5a58646..24cf92d 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=240985 mod_id=electricadvantage mod_name=Electric Advantage mod_license=GPL-3.0-only -mod_version=2.2.5.113021 +mod_version=2.2.6.114041 mod_group=zone.moddev.mc.electricadvantage mod_authors=DrCyano mod_description=Electric-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/electricadvantage/ElectricAdvantage.java b/src/main/java/zone/moddev/mc/electricadvantage/ElectricAdvantage.java index 3ce9fa2..4083a99 100644 --- a/src/main/java/zone/moddev/mc/electricadvantage/ElectricAdvantage.java +++ b/src/main/java/zone/moddev/mc/electricadvantage/ElectricAdvantage.java @@ -33,12 +33,12 @@ import zone.moddev.mc.electricadvantage.recipe.RecipeConditions; import zone.moddev.mc.electricadvantage.migration.ElectricLegacyMigrations; -/** Forge 1.13 entry point for Electric Advantage. */ +/** Forge 1.14 entry point for Electric Advantage. */ @Mod(ElectricAdvantage.MODID) public final class ElectricAdvantage { public static final String MODID = "electricadvantage"; public static final String NAME = "Electric 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 ElectricAdvantage INSTANCE; diff --git a/src/main/java/zone/moddev/mc/electricadvantage/blocks/ElectricScaffoldBlock.java b/src/main/java/zone/moddev/mc/electricadvantage/blocks/ElectricScaffoldBlock.java index 1c730f8..919dded 100644 --- a/src/main/java/zone/moddev/mc/electricadvantage/blocks/ElectricScaffoldBlock.java +++ b/src/main/java/zone/moddev/mc/electricadvantage/blocks/ElectricScaffoldBlock.java @@ -2,19 +2,20 @@ import net.minecraft.util.BlockRenderLayer; 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.util.math.shapes.VoxelShape; import net.minecraft.util.math.shapes.VoxelShapes; +import net.minecraft.util.math.shapes.ISelectionContext; import net.minecraft.world.IBlockReader; import zone.moddev.mc.electricadvantage.init.Power; /** Full-block electric track/scaffold with conduit behavior. */ public class ElectricScaffoldBlock extends cyano.poweradvantage.api.simple.BlockSimplePowerConduit { public ElectricScaffoldBlock() { super(Material.PISTON, 0.75F, 2.0F / 16.0F, Power.ELECTRIC_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; } @Override public BlockRenderLayer getRenderLayer() { return BlockRenderLayer.CUTOUT; } } diff --git a/src/main/java/zone/moddev/mc/electricadvantage/blocks/Ore.java b/src/main/java/zone/moddev/mc/electricadvantage/blocks/Ore.java index 7431924..ad8b067 100644 --- a/src/main/java/zone/moddev/mc/electricadvantage/blocks/Ore.java +++ b/src/main/java/zone/moddev/mc/electricadvantage/blocks/Ore.java @@ -1,12 +1,18 @@ package zone.moddev.mc.electricadvantage.blocks; import java.util.Random; +import java.util.Collections; +import java.util.List; import net.minecraft.block.Block; 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.item.ItemStack; +import net.minecraft.enchantment.EnchantmentHelper; +import net.minecraft.enchantment.Enchantments; +import net.minecraft.world.storage.loot.LootContext; +import net.minecraft.world.storage.loot.LootParameters; import net.minecraft.util.NonNullList; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -34,18 +40,19 @@ public Ore(int pickLevel) { harvestLevel = pickLevel; } - @Override public ToolType getHarvestTool(IBlockState state) { return ToolType.PICKAXE; } - @Override public int getHarvestLevel(IBlockState state) { return harvestLevel; } + @Override public ToolType getHarvestTool(BlockState state) { return ToolType.PICKAXE; } + @Override public int getHarvestLevel(BlockState state) { return harvestLevel; } @Override - public void getDrops(IBlockState state, NonNullList drops, World world, BlockPos pos, int fortune) { - if (dropItem.isEmpty()) { - drops.add(new ItemStack(this)); - return; + public List getDrops(BlockState state, LootContext.Builder context) { + ItemStack tool = context.get(LootParameters.TOOL); + if (dropItem.isEmpty() || (tool != null + && EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0)) { + return Collections.singletonList(new ItemStack(this)); } - Random random = world.rand; + Random random = context.getWorld().rand; ItemStack result = dropItem.copy(); result.setCount(dropItem.getCount() + (dropRange > 1 ? random.nextInt(dropRange) : 0)); - drops.add(result); + return Collections.singletonList(result); } } diff --git a/src/main/java/zone/moddev/mc/electricadvantage/blocks/PumpPipeBlock.java b/src/main/java/zone/moddev/mc/electricadvantage/blocks/PumpPipeBlock.java index e2a3934..5a476fe 100644 --- a/src/main/java/zone/moddev/mc/electricadvantage/blocks/PumpPipeBlock.java +++ b/src/main/java/zone/moddev/mc/electricadvantage/blocks/PumpPipeBlock.java @@ -2,12 +2,14 @@ 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 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; @@ -15,15 +17,15 @@ /** Hidden pump intake column. */ public class PumpPipeBlock extends Block { private static final VoxelShape SHAPE = VoxelShapes.create(0.25D, 0.0D, 0.25D, 0.75D, 1.0D, 0.75D); - public PumpPipeBlock() { super(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) {} + public PumpPipeBlock() { super(Properties.create(Material.IRON).hardnessAndResistance(5.0F, 10.0F).variableOpacity().noDrops()); } + @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 java.util.List getDrops(BlockState state, LootContext.Builder context) { return java.util.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()) destroyBelow(world, pos); super.onReplaced(state, world, pos, newState, moving); } @@ -37,7 +39,7 @@ private void destroyBelow(World world, BlockPos pos) { if (world.isRemote) return; BlockPos cursor = pos.down(); while (cursor.getY() > 0 && world.getBlockState(cursor).getBlock() == this) { - world.setBlockState(cursor, net.minecraft.init.Blocks.AIR.getDefaultState(), 3); + world.setBlockState(cursor, net.minecraft.block.Blocks.AIR.getDefaultState(), 3); cursor = cursor.down(); } } diff --git a/src/main/java/zone/moddev/mc/electricadvantage/compat/BaseMetalsCompat.java b/src/main/java/zone/moddev/mc/electricadvantage/compat/BaseMetalsCompat.java index b3fdd0c..6c1592c 100644 --- a/src/main/java/zone/moddev/mc/electricadvantage/compat/BaseMetalsCompat.java +++ b/src/main/java/zone/moddev/mc/electricadvantage/compat/BaseMetalsCompat.java @@ -1,13 +1,13 @@ package zone.moddev.mc.electricadvantage.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.ResourceLocation; -import net.minecraft.util.text.TextComponentString; +import net.minecraft.util.text.StringTextComponent; import net.minecraft.world.World; import net.minecraftforge.fml.ModList; import net.minecraftforge.registries.ForgeRegistries; @@ -34,10 +34,10 @@ 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("electric 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)) { + for (IRecipe candidate : world.getRecipeManager().getRecipes()) { + if (candidate instanceof CrushingRecipe && ((CrushingRecipe) candidate).matches(inventory, world)) { return candidate.getRecipeOutput().copy(); } } @@ -45,7 +45,7 @@ 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())); } diff --git a/src/main/java/zone/moddev/mc/electricadvantage/entities/HydroturbineEntity.java b/src/main/java/zone/moddev/mc/electricadvantage/entities/HydroturbineEntity.java index d9bad84..a8af37b 100644 --- a/src/main/java/zone/moddev/mc/electricadvantage/entities/HydroturbineEntity.java +++ b/src/main/java/zone/moddev/mc/electricadvantage/entities/HydroturbineEntity.java @@ -3,10 +3,12 @@ import zone.moddev.mc.electricadvantage.init.Power; import zone.moddev.mc.electricadvantage.machines.HydroelectricGeneratorTileEntity; import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.LivingEntity; import net.minecraft.entity.EntityType; import net.minecraft.fluid.IFluidState; -import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.network.IPacket; +import net.minecraftforge.fml.network.NetworkHooks; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; @@ -28,9 +30,6 @@ public class HydroturbineEntity extends net.minecraft.entity.Entity{ public HydroturbineEntity(EntityType type, World w) { super(type, w); - this.width = 0.9375F; - this.height = 0.9375F; - this.setSize(this.width, this.height); this.preventEntitySpawning = true; roffset = w.rand.nextInt(8); } @@ -50,6 +49,11 @@ protected void registerData() { // do nothing } + @Override + public IPacket createSpawnPacket() { + return NetworkHooks.getEntitySpawningPacket(this); + } + @Override public void tick(){ super.tick(); @@ -87,7 +91,7 @@ public void tick(){ } if(isSpinning && getEntityWorld().getGameTime() % 8 == roffset){ // slice-n-dice unfortunate souls caught in the blades - List victims = getEntityWorld().getEntitiesWithinAABB(EntityLivingBase.class, this.getBoundingBox()); + List victims = getEntityWorld().getEntitiesWithinAABB(LivingEntity.class, this.getBoundingBox()); for(Entity e : victims){ e.attackEntityFrom(Power.propeller_damage, PROPELLER_DAMAGE); } @@ -96,7 +100,7 @@ public void tick(){ } @Override - protected void readAdditional(NBTTagCompound root) { + protected void readAdditional(CompoundNBT root) { parent = null; parentCoord = null; if(root.contains("parentPos", 11)){ @@ -108,14 +112,14 @@ protected void readAdditional(NBTTagCompound root) { } @Override - protected void writeAdditional(NBTTagCompound root) { + protected void writeAdditional(CompoundNBT root) { BlockPos p = parent != null ? parent.getPos() : parentCoord; if(p != null){ int[] coords = new int[3]; coords[0] = p.getX(); coords[1] = p.getY(); coords[2] = p.getZ(); - root.setIntArray("parentPos", coords); + root.putIntArray("parentPos", coords); } } diff --git a/src/main/java/zone/moddev/mc/electricadvantage/graphics/HydroturbineRenderer.java b/src/main/java/zone/moddev/mc/electricadvantage/graphics/HydroturbineRenderer.java index 639e6ed..f025e78 100644 --- a/src/main/java/zone/moddev/mc/electricadvantage/graphics/HydroturbineRenderer.java +++ b/src/main/java/zone/moddev/mc/electricadvantage/graphics/HydroturbineRenderer.java @@ -2,11 +2,11 @@ import zone.moddev.mc.electricadvantage.ElectricAdvantage; import zone.moddev.mc.electricadvantage.entities.HydroturbineEntity; -import net.minecraft.client.renderer.GlStateManager; +import com.mojang.blaze3d.platform.GlStateManager; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.BufferBuilder; -import net.minecraft.client.renderer.entity.Render; -import net.minecraft.client.renderer.entity.RenderManager; +import net.minecraft.client.renderer.entity.EntityRenderer; +import net.minecraft.client.renderer.entity.EntityRendererManager; import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.entity.Entity; import net.minecraft.util.ResourceLocation; @@ -15,12 +15,12 @@ import net.minecraftforge.api.distmarker.OnlyIn; @OnlyIn(Dist.CLIENT) -public class HydroturbineRenderer extends Render{ +public class HydroturbineRenderer extends EntityRenderer{ private static final ResourceLocation texture = new ResourceLocation(ElectricAdvantage.MODID+":textures/entity/hydroturbine.png"); private static final float DEGREES_TO_RADIANS = (float)(Math.PI / 180); - public HydroturbineRenderer(final RenderManager rm) { + public HydroturbineRenderer(final EntityRendererManager rm) { super(rm); } diff --git a/src/main/java/zone/moddev/mc/electricadvantage/graphics/LaserDrillRenderer.java b/src/main/java/zone/moddev/mc/electricadvantage/graphics/LaserDrillRenderer.java index c11a628..b22bf95 100644 --- a/src/main/java/zone/moddev/mc/electricadvantage/graphics/LaserDrillRenderer.java +++ b/src/main/java/zone/moddev/mc/electricadvantage/graphics/LaserDrillRenderer.java @@ -2,13 +2,13 @@ import zone.moddev.mc.electricadvantage.ElectricAdvantage; import zone.moddev.mc.electricadvantage.machines.ElectricDrillTileEntity; -import net.minecraft.client.renderer.GlStateManager; +import com.mojang.blaze3d.platform.GlStateManager; 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.tileentity.TileEntity; -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; @@ -57,7 +57,7 @@ private void render(ElectricDrillTileEntity e, World world, BlockPos pos, float float tickRemainder = 1 - partialTick; - EnumFacing dir = e.getFacing(); + Direction dir = e.getFacing(); float rotY = 0, rotX = 0; switch(dir){ diff --git a/src/main/java/zone/moddev/mc/electricadvantage/graphics/LaserTurretRenderer.java b/src/main/java/zone/moddev/mc/electricadvantage/graphics/LaserTurretRenderer.java index c62a6ca..b4506ab 100644 --- a/src/main/java/zone/moddev/mc/electricadvantage/graphics/LaserTurretRenderer.java +++ b/src/main/java/zone/moddev/mc/electricadvantage/graphics/LaserTurretRenderer.java @@ -3,7 +3,7 @@ import zone.moddev.mc.electricadvantage.ElectricAdvantage; import zone.moddev.mc.electricadvantage.machines.LaserTurretTileEntity; 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; diff --git a/src/main/java/zone/moddev/mc/electricadvantage/gui/ArcFurnaceGUI.java b/src/main/java/zone/moddev/mc/electricadvantage/gui/ArcFurnaceGUI.java index e77502d..a6ae15a 100644 --- a/src/main/java/zone/moddev/mc/electricadvantage/gui/ArcFurnaceGUI.java +++ b/src/main/java/zone/moddev/mc/electricadvantage/gui/ArcFurnaceGUI.java @@ -4,8 +4,8 @@ import zone.moddev.mc.electricadvantage.machines.ElectricMachineTileEntity; import cyano.poweradvantage.api.simple.SimpleMachineGUI; import zone.moddev.mc.poweradvantage.math.Integer2D; -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; @@ -17,7 +17,7 @@ public ArcFurnaceGUI() { 124,45, 145,45, 124,66, 145,66, 124,87, 145,87)); for(int i = 4; i < 10; 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); @@ -37,8 +37,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.renderEngine.bindTexture(arrowTexture);
-guiContainer.drawTexturedModalRect(x+79, y+35, 0, 0, arrowLength, 17); // x, y, textureOffsetX, textureOffsetY, width, height)
+guiContainer.getMinecraft().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 diff --git a/src/main/java/zone/moddev/mc/electricadvantage/gui/BatteryArrayGUI.java b/src/main/java/zone/moddev/mc/electricadvantage/gui/BatteryArrayGUI.java index 1b0d002..eb7c0ef 100644 --- a/src/main/java/zone/moddev/mc/electricadvantage/gui/BatteryArrayGUI.java +++ b/src/main/java/zone/moddev/mc/electricadvantage/gui/BatteryArrayGUI.java @@ -33,8 +33,8 @@ public BatteryArrayGUI() { * @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.renderEngine.bindTexture(arrowTexture);
-guiContainer.drawTexturedModalRect(x+79, y+35, 0, 0, arrowLength, 17); // x, y, textureOffsetX, textureOffsetY, width, height)
+guiContainer.getMinecraft().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 diff --git a/src/main/java/zone/moddev/mc/electricadvantage/gui/ElectricDrillGUI.java b/src/main/java/zone/moddev/mc/electricadvantage/gui/ElectricDrillGUI.java index ab17995..3674f42 100644 --- a/src/main/java/zone/moddev/mc/electricadvantage/gui/ElectricDrillGUI.java +++ b/src/main/java/zone/moddev/mc/electricadvantage/gui/ElectricDrillGUI.java @@ -24,8 +24,8 @@ public ElectricDrillGUI() { * @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.renderEngine.bindTexture(arrowTexture);
-guiContainer.drawTexturedModalRect(x+79, y+35, 0, 0, arrowLength, 17); // x, y, textureOffsetX, textureOffsetY, width, height)
+guiContainer.getMinecraft().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 diff --git a/src/main/java/zone/moddev/mc/electricadvantage/gui/ElectricPumpGUI.java b/src/main/java/zone/moddev/mc/electricadvantage/gui/ElectricPumpGUI.java index 1759fc8..ae847b6 100644 --- a/src/main/java/zone/moddev/mc/electricadvantage/gui/ElectricPumpGUI.java +++ b/src/main/java/zone/moddev/mc/electricadvantage/gui/ElectricPumpGUI.java @@ -24,8 +24,8 @@ public ElectricPumpGUI() { * @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.renderEngine.bindTexture(arrowTexture);
-guiContainer.drawTexturedModalRect(x+79, y+35, 0, 0, arrowLength, 17); // x, y, textureOffsetX, textureOffsetY, width, height)
+guiContainer.getMinecraft().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 diff --git a/src/main/java/zone/moddev/mc/electricadvantage/gui/ElectricStillGUI.java b/src/main/java/zone/moddev/mc/electricadvantage/gui/ElectricStillGUI.java index 225fd65..59ab60c 100644 --- a/src/main/java/zone/moddev/mc/electricadvantage/gui/ElectricStillGUI.java +++ b/src/main/java/zone/moddev/mc/electricadvantage/gui/ElectricStillGUI.java @@ -24,8 +24,8 @@ public ElectricStillGUI() { * @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.renderEngine.bindTexture(arrowTexture);
-guiContainer.drawTexturedModalRect(x+79, y+35, 0, 0, arrowLength, 17); // x, y, textureOffsetX, textureOffsetY, width, height)
+guiContainer.getMinecraft().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 diff --git a/src/main/java/zone/moddev/mc/electricadvantage/gui/FabricatorGUI.java b/src/main/java/zone/moddev/mc/electricadvantage/gui/FabricatorGUI.java index 3144583..6897eff 100644 --- a/src/main/java/zone/moddev/mc/electricadvantage/gui/FabricatorGUI.java +++ b/src/main/java/zone/moddev/mc/electricadvantage/gui/FabricatorGUI.java @@ -4,8 +4,8 @@ import zone.moddev.mc.electricadvantage.machines.ElectricMachineTileEntity; import cyano.poweradvantage.api.simple.SimpleMachineGUI; import zone.moddev.mc.poweradvantage.math.Integer2D; -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; @@ -26,7 +26,7 @@ public FabricatorGUI() { for(int i = 12; i <= 13; 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 +46,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.renderEngine.bindTexture(arrowTexture);
-guiContainer.drawTexturedModalRect(x+79, y+35, 0, 0, arrowLength, 17); // x, y, textureOffsetX, textureOffsetY, width, height)
+guiContainer.getMinecraft().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 diff --git a/src/main/java/zone/moddev/mc/electricadvantage/gui/GUIHelper.java b/src/main/java/zone/moddev/mc/electricadvantage/gui/GUIHelper.java index d147aca..81a9761 100644 --- a/src/main/java/zone/moddev/mc/electricadvantage/gui/GUIHelper.java +++ b/src/main/java/zone/moddev/mc/electricadvantage/gui/GUIHelper.java @@ -1,6 +1,7 @@ package zone.moddev.mc.electricadvantage.gui; import cyano.poweradvantage.api.simple.SimpleMachineGUI.GUIContainer; + import zone.moddev.mc.poweradvantage.gui.FluidTankGUI; import net.minecraft.util.ResourceLocation; import cyano.poweradvantage.api.fluid.FluidStack; @@ -25,7 +26,7 @@ public class GUIHelper { public static void drawIndicatorLight(boolean on,GUIContainer gc, int xOffset, int yOffset){ if(on){ - gc.drawTexturedModalRect(8+xOffset, 8+yOffset, INDICATOR_LED_X, INDICATOR_LED_Y, INDICATOR_LED_W, INDICATOR_LED_H); + gc.blit(8+xOffset, 8+yOffset, INDICATOR_LED_X, INDICATOR_LED_Y, INDICATOR_LED_W, INDICATOR_LED_H); } } @@ -33,7 +34,7 @@ public static void drawProgressBar(int x, int y, float progress, GUIContainer gc int n = (int)(8 * (progress + 0.0625f) ); if(n <= 0) return; int w = 1 + (n * LED_BAR_W8); - gc.drawTexturedModalRect(x, y, LED_BAR_X, LED_BAR_Y, w, LED_BAR_H); + gc.blit(x, y, LED_BAR_X, LED_BAR_Y, w, LED_BAR_H); } diff --git a/src/main/java/zone/moddev/mc/electricadvantage/gui/GenericMachineGUI.java b/src/main/java/zone/moddev/mc/electricadvantage/gui/GenericMachineGUI.java index 33f854c..7812a17 100644 --- a/src/main/java/zone/moddev/mc/electricadvantage/gui/GenericMachineGUI.java +++ b/src/main/java/zone/moddev/mc/electricadvantage/gui/GenericMachineGUI.java @@ -22,8 +22,8 @@ public GenericMachineGUI() { * @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.renderEngine.bindTexture(arrowTexture);
-guiContainer.drawTexturedModalRect(x+79, y+35, 0, 0, arrowLength, 17); // x, y, textureOffsetX, textureOffsetY, width, height)
+guiContainer.getMinecraft().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 diff --git a/src/main/java/zone/moddev/mc/electricadvantage/gui/GrowthChamberControllerGUI.java b/src/main/java/zone/moddev/mc/electricadvantage/gui/GrowthChamberControllerGUI.java index 9e5eae6..47a20da 100644 --- a/src/main/java/zone/moddev/mc/electricadvantage/gui/GrowthChamberControllerGUI.java +++ b/src/main/java/zone/moddev/mc/electricadvantage/gui/GrowthChamberControllerGUI.java @@ -23,8 +23,8 @@ public GrowthChamberControllerGUI() { * @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.renderEngine.bindTexture(arrowTexture);
-guiContainer.drawTexturedModalRect(x+79, y+35, 0, 0, arrowLength, 17); // x, y, textureOffsetX, textureOffsetY, width, height)
+guiContainer.getMinecraft().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 diff --git a/src/main/java/zone/moddev/mc/electricadvantage/gui/GrowthChamberGUI.java b/src/main/java/zone/moddev/mc/electricadvantage/gui/GrowthChamberGUI.java index 8cdb6e9..33d4420 100644 --- a/src/main/java/zone/moddev/mc/electricadvantage/gui/GrowthChamberGUI.java +++ b/src/main/java/zone/moddev/mc/electricadvantage/gui/GrowthChamberGUI.java @@ -24,8 +24,8 @@ public GrowthChamberGUI() { * @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.renderEngine.bindTexture(arrowTexture);
-guiContainer.drawTexturedModalRect(x+79, y+35, 0, 0, arrowLength, 17); // x, y, textureOffsetX, textureOffsetY, width, height)
+guiContainer.getMinecraft().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 diff --git a/src/main/java/zone/moddev/mc/electricadvantage/gui/OvenGUI.java b/src/main/java/zone/moddev/mc/electricadvantage/gui/OvenGUI.java index c6c3dc2..015aa4f 100644 --- a/src/main/java/zone/moddev/mc/electricadvantage/gui/OvenGUI.java +++ b/src/main/java/zone/moddev/mc/electricadvantage/gui/OvenGUI.java @@ -4,8 +4,8 @@ import zone.moddev.mc.electricadvantage.machines.ElectricMachineTileEntity; import cyano.poweradvantage.api.simple.SimpleMachineGUI; import zone.moddev.mc.poweradvantage.math.Integer2D; -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; @@ -16,7 +16,7 @@ public OvenGUI() { Integer2D.fromCoordinates(27,67, 133,67)); super.specialSlots.put(1, (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); @@ -36,8 +36,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.renderEngine.bindTexture(arrowTexture);
-guiContainer.drawTexturedModalRect(x+79, y+35, 0, 0, arrowLength, 17); // x, y, textureOffsetX, textureOffsetY, width, height)
+guiContainer.getMinecraft().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 diff --git a/src/main/java/zone/moddev/mc/electricadvantage/gui/PlasticRefineryGUI.java b/src/main/java/zone/moddev/mc/electricadvantage/gui/PlasticRefineryGUI.java index 51059be..37afa95 100644 --- a/src/main/java/zone/moddev/mc/electricadvantage/gui/PlasticRefineryGUI.java +++ b/src/main/java/zone/moddev/mc/electricadvantage/gui/PlasticRefineryGUI.java @@ -24,8 +24,8 @@ public PlasticRefineryGUI() { * @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.renderEngine.bindTexture(arrowTexture);
-guiContainer.drawTexturedModalRect(x+79, y+35, 0, 0, arrowLength, 17); // x, y, textureOffsetX, textureOffsetY, width, height)
+guiContainer.getMinecraft().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 diff --git a/src/main/java/zone/moddev/mc/electricadvantage/gui/PowerGeneratorGUI.java b/src/main/java/zone/moddev/mc/electricadvantage/gui/PowerGeneratorGUI.java index 582d2ac..c611d80 100644 --- a/src/main/java/zone/moddev/mc/electricadvantage/gui/PowerGeneratorGUI.java +++ b/src/main/java/zone/moddev/mc/electricadvantage/gui/PowerGeneratorGUI.java @@ -22,8 +22,8 @@ public PowerGeneratorGUI() { * @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.renderEngine.bindTexture(arrowTexture);
-guiContainer.drawTexturedModalRect(x+79, y+35, 0, 0, arrowLength, 17); // x, y, textureOffsetX, textureOffsetY, width, height)
+guiContainer.getMinecraft().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 diff --git a/src/main/java/zone/moddev/mc/electricadvantage/gui/RockCrusherGUI.java b/src/main/java/zone/moddev/mc/electricadvantage/gui/RockCrusherGUI.java index 36ffa77..19cc321 100644 --- a/src/main/java/zone/moddev/mc/electricadvantage/gui/RockCrusherGUI.java +++ b/src/main/java/zone/moddev/mc/electricadvantage/gui/RockCrusherGUI.java @@ -24,8 +24,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.renderEngine.bindTexture(arrowTexture);
-guiContainer.drawTexturedModalRect(x+79, y+35, 0, 0, arrowLength, 17); // x, y, textureOffsetX, textureOffsetY, width, height)
+guiContainer.getMinecraft().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 diff --git a/src/main/java/zone/moddev/mc/electricadvantage/init/Blocks.java b/src/main/java/zone/moddev/mc/electricadvantage/init/Blocks.java index 1b6a15e..6e3fd0c 100644 --- a/src/main/java/zone/moddev/mc/electricadvantage/init/Blocks.java +++ b/src/main/java/zone/moddev/mc/electricadvantage/init/Blocks.java @@ -6,7 +6,7 @@ import cyano.poweradvantage.api.GUIBlock; import net.minecraft.block.Block; import net.minecraft.item.Item; -import net.minecraft.item.ItemBlock; +import net.minecraft.item.BlockItem; import net.minecraft.item.ItemStack; import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; @@ -115,7 +115,7 @@ private static Block add(Block block, String id) { if (!"pump_pipe_electric".equals(entry.getKey()) && !"laser_turret_evil".equals(entry.getKey())) { properties.group(ItemGroups.tab_powerAdvantage); } - ItemBlock item = new ItemBlock(entry.getValue(), properties); + BlockItem item = new BlockItem(entry.getValue(), properties); item.setRegistryName(ElectricAdvantage.MODID, entry.getKey()); event.getRegistry().register(item); } diff --git a/src/main/java/zone/moddev/mc/electricadvantage/init/Entities.java b/src/main/java/zone/moddev/mc/electricadvantage/init/Entities.java index 2c50387..8f62dfe 100644 --- a/src/main/java/zone/moddev/mc/electricadvantage/init/Entities.java +++ b/src/main/java/zone/moddev/mc/electricadvantage/init/Entities.java @@ -3,6 +3,7 @@ import java.util.function.Supplier; import net.minecraft.entity.EntityType; +import net.minecraft.entity.EntityClassification; import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityType; import net.minecraftforge.event.RegistryEvent; @@ -52,37 +53,41 @@ private Entities() {} public static void init() {} @SubscribeEvent public static void registerTiles(RegistryEvent.Register> event) { - ELECTRIC_FURNACE = tile(event, "electric_furnace", ElectricFurnaceTileEntity::new); - ELECTRIC_CRUSHER = tile(event, "electric_crusher", ElectricCrusherTileEntity::new); - ELECTRIC_DRILL = tile(event, "electric_drill", ElectricDrillTileEntity::new); - ELECTRIC_FABRICATOR = tile(event, "electric_fabricator", ElectricFabricatorTileEntity::new); - GROWTH_CHAMBER = tile(event, "growth_chamber", GrowthChamberTileEntity::new); - GROWTH_CHAMBER_CONTROLLER = tile(event, "growth_chamber_controller", GrowthChamberControllerTileEntity::new); - ELECTRIC_OVEN = tile(event, "electric_oven", ElectricOvenTileEntity::new); - LASER_TURRET = tile(event, "laser_turret", LaserTurretTileEntity::new); - LED = tile(event, "led", LEDTileEntity::new); - HYDROELECTRIC_GENERATOR = tile(event, "hydroelectric_generator", HydroelectricGeneratorTileEntity::new); - PHOTOVOLTAIC_GENERATOR = tile(event, "photovoltaic_generator", PhotovoltaicGeneratorTileEntity::new); - STEAM_POWERED_ELECTRIC_GENERATOR = tile(event, "steam_powered_electric_generator", SteamPoweredElectricGeneratorTileEntity::new); - ELECTRIC_BATTERY_ARRAY = tile(event, "electric_battery_array", ElectricBatteryArrayTileEntity::new); - ELECTRIC_PUMP = tile(event, "electric_pump", ElectricPumpTileEntity::new); - ELECTRIC_STILL = tile(event, "electric_still", ElectricStillTileEntity::new); - PLASTIC_REFINERY = tile(event, "plastic_refinery", PlasticRefineryTileEntity::new); + ELECTRIC_FURNACE = tile(event, "electric_furnace", ElectricFurnaceTileEntity::new, Blocks.arc_furnace); + ELECTRIC_CRUSHER = tile(event, "electric_crusher", ElectricCrusherTileEntity::new, Blocks.rock_crusher); + ELECTRIC_DRILL = tile(event, "electric_drill", ElectricDrillTileEntity::new, Blocks.laser_drill); + ELECTRIC_FABRICATOR = tile(event, "electric_fabricator", ElectricFabricatorTileEntity::new, Blocks.fabricator); + GROWTH_CHAMBER = tile(event, "growth_chamber", GrowthChamberTileEntity::new, Blocks.growth_chamber); + GROWTH_CHAMBER_CONTROLLER = tile(event, "growth_chamber_controller", GrowthChamberControllerTileEntity::new, Blocks.growth_chamber_controller); + ELECTRIC_OVEN = tile(event, "electric_oven", ElectricOvenTileEntity::new, Blocks.oven); + LASER_TURRET = tile(event, "laser_turret", LaserTurretTileEntity::new, Blocks.laser_turret, Blocks.laser_turret_evil); + LED = tile(event, "led", LEDTileEntity::new, Blocks.led_bar); + HYDROELECTRIC_GENERATOR = tile(event, "hydroelectric_generator", HydroelectricGeneratorTileEntity::new, Blocks.hydroelectric_generator); + PHOTOVOLTAIC_GENERATOR = tile(event, "photovoltaic_generator", PhotovoltaicGeneratorTileEntity::new, Blocks.photovoltaic_generator); + STEAM_POWERED_ELECTRIC_GENERATOR = tile(event, "steam_powered_electric_generator", SteamPoweredElectricGeneratorTileEntity::new, Blocks.steam_powered_generator); + ELECTRIC_BATTERY_ARRAY = tile(event, "electric_battery_array", ElectricBatteryArrayTileEntity::new, Blocks.battery_array); + ELECTRIC_PUMP = tile(event, "electric_pump", ElectricPumpTileEntity::new, Blocks.electric_pump); + ELECTRIC_STILL = tile(event, "electric_still", ElectricStillTileEntity::new, Blocks.electric_still); + PLASTIC_REFINERY = tile(event, "plastic_refinery", PlasticRefineryTileEntity::new, Blocks.plastic_refinery); } @SubscribeEvent public static void registerEntities(RegistryEvent.Register> event) { - HYDROTURBINE = EntityType.Builder.create(HydroturbineEntity.class, - world -> new HydroturbineEntity(HYDROTURBINE, world)) - .tracker(64, 1, true).build(ElectricAdvantage.MODID + ":hydroturbine"); + HYDROTURBINE = EntityType.Builder.create( + HydroturbineEntity::new, EntityClassification.MISC) + .size(0.9375F, 0.9375F) + .setTrackingRange(64).setUpdateInterval(1).setShouldReceiveVelocityUpdates(true) + .build(ElectricAdvantage.MODID + ":hydroturbine"); HYDROTURBINE.setRegistryName(ElectricAdvantage.MODID, "hydroturbine"); event.getRegistry().register(HYDROTURBINE); } private static TileEntityType tile( - RegistryEvent.Register> event, String id, Supplier factory) { - TileEntityType type = TileEntityType.Builder.create(factory).build(null); + RegistryEvent.Register> event, String id, Supplier factory, + net.minecraft.block.Block... blocks) { + TileEntityType type = TileEntityType.Builder.create(factory, blocks).build(null); type.setRegistryName(ElectricAdvantage.MODID, id); event.getRegistry().register(type); return type; } + } diff --git a/src/main/java/zone/moddev/mc/electricadvantage/init/Villages.java b/src/main/java/zone/moddev/mc/electricadvantage/init/Villages.java index 007a245..93318d4 100644 --- a/src/main/java/zone/moddev/mc/electricadvantage/init/Villages.java +++ b/src/main/java/zone/moddev/mc/electricadvantage/init/Villages.java @@ -1,55 +1,45 @@ package zone.moddev.mc.electricadvantage.init; -import zone.moddev.mc.electricadvantage.ElectricAdvantage; - -import net.minecraft.entity.passive.EntityVillager; +import java.util.List; +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.fml.common.registry.VillagerRegistry; -import net.minecraftforge.registries.ForgeRegistries; +import net.minecraft.item.ItemStack; +import net.minecraft.item.MerchantOffer; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.village.VillagerTradesEvent; -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") - }; +/** Adds the historical librarian offers through the native profession trade event. */ +public final class Villages { + private static boolean initialized; - private static boolean initDone = false; - public static void init(){ - if(initDone) return; + private Villages() {} - Entities.init(); - try { - insertTrades(1, 1, 2, new EntityVillager.ListItemForEmeralds( - Items.petrolplastic_ingot, new EntityVillager.PriceInfo(-8, -4))); - insertTrades(1, 1, 1, new EntityVillager.ListItemForEmeralds( - Item.getItemFromBlock(Blocks.electric_conduit), new EntityVillager.PriceInfo(-6, -3))); - insertTrades(1, 1, 1, new EntityVillager.ListItemForEmeralds( - Items.solder, new EntityVillager.PriceInfo(-10, -5))); - insertTrades(1, 1, 1, new EntityVillager.ListItemForEmeralds( - Items.integrated_circuit, new EntityVillager.PriceInfo(-6, -3))); - insertTrades(1, 1, 1, new EntityVillager.ListItemForEmeralds( - Items.blank_circuit_board, new EntityVillager.PriceInfo(-6, -3))); - insertTrades(1, 1, 2, new EntityVillager.ListItemForEmeralds( - Items.power_supply_unit, new EntityVillager.PriceInfo(1, 3))); - } catch (RuntimeException e) { - ElectricAdvantage.LOGGER.error("Failed to add trades to villagers", e); - } + public static synchronized void init() { + if (initialized) return; + MinecraftForge.EVENT_BUS.addListener(Villages::addTrades); + initialized = true; + } - - initDone = true; - } + public static void addTrades(VillagerTradesEvent event) { + if (event.getType() != VillagerProfession.LIBRARIAN) return; + List novice = event.getTrades().get(1); + List apprentice = event.getTrades().get(2); + novice.add(sell(Blocks.electric_conduit.asItem(), -6, -3)); + novice.add(sell(Items.solder, -10, -5)); + novice.add(sell(Items.integrated_circuit, -6, -3)); + novice.add(sell(Items.blank_circuit_board, -6, -3)); + apprentice.add(sell(Items.petrolplastic_ingot, -8, -4)); + apprentice.add(sell(Items.power_supply_unit, 1, 3)); + } - 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); - } + static VillagerTrades.ITrade sell(Item item, int minimumPrice, int maximumPrice) { + return (villager, random) -> { + int price = minimumPrice + random.nextInt(maximumPrice - minimumPrice + 1); + int emeralds = price < 0 ? 1 : price; + int count = price < 0 ? -price : 1; + return new MerchantOffer(new ItemStack(net.minecraft.item.Items.EMERALD, emeralds), + new ItemStack(item, count), 7, 1, 0.0F); + }; + } } diff --git a/src/main/java/zone/moddev/mc/electricadvantage/items/BatteryItem.java b/src/main/java/zone/moddev/mc/electricadvantage/items/BatteryItem.java index 4b2280f..633623c 100644 --- a/src/main/java/zone/moddev/mc/electricadvantage/items/BatteryItem.java +++ b/src/main/java/zone/moddev/mc/electricadvantage/items/BatteryItem.java @@ -6,10 +6,10 @@ import net.minecraft.client.util.ITooltipFlag; import net.minecraft.item.ItemStack; import net.minecraft.item.Item; -import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.CompoundNBT; import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.TextComponentString; -import net.minecraft.util.text.TextComponentTranslation; +import net.minecraft.util.text.StringTextComponent; +import net.minecraft.util.text.TranslationTextComponent; import net.minecraft.world.World; import java.text.NumberFormat; @@ -32,7 +32,7 @@ public BatteryItem(float capacity, Item.Properties properties){ public float getEnergy(ItemStack stack) { if(stack.getItem() instanceof IRechargeableItem){ BatteryItem battery = (BatteryItem)stack.getItem(); - NBTTagCompound dataTag; + CompoundNBT dataTag; if(!stack.hasTag()){ return battery.capacity; // new battery starts with 100% charge } else { @@ -50,9 +50,9 @@ public float getEnergy(ItemStack stack) { @Override public void setEnergy(ItemStack stack, float energy){ if(stack.getItem() instanceof BatteryItem){ - NBTTagCompound dataTag; + CompoundNBT dataTag; dataTag = stack.getOrCreateTag(); - dataTag.setFloat("energy", energy); + dataTag.putFloat("energy", energy); stack.setTag(dataTag); } } @@ -66,7 +66,7 @@ public void setEnergy(ItemStack stack, float energy){ public float addEnergy(ItemStack stack, float energy, ConduitType type){ if(ConduitType.areSameType(type, Power.ELECTRIC_POWER) && stack.getItem() instanceof BatteryItem){ BatteryItem battery = (BatteryItem)stack.getItem(); - NBTTagCompound dataTag; + CompoundNBT dataTag; dataTag = stack.getOrCreateTag(); float currentEnergy; if(dataTag.contains("energy", 99)){ @@ -75,7 +75,7 @@ public float addEnergy(ItemStack stack, float energy, ConduitType type){ currentEnergy = battery.capacity; } float newEnergy = Math.max(0, Math.min(currentEnergy+energy, battery.capacity)); - dataTag.setFloat("energy", newEnergy); + dataTag.putFloat("energy", newEnergy); stack.setTag(dataTag); return newEnergy - currentEnergy; } else { @@ -100,10 +100,10 @@ public void addInformation(ItemStack stack, World world, List li float max = getMaxEnergy(stack); if(max <= 0) return; // not a battery! float e = getEnergy(stack); - list.add(new TextComponentString(nf.format(100 * e / max) + "% ") - .appendSibling(new TextComponentTranslation("tooltip.battery.charge"))); - list.add(new TextComponentString("(" + nf.format(max) + "kJ ") - .appendSibling(new TextComponentTranslation("tooltip.battery.capacity")) + list.add(new StringTextComponent(nf.format(100 * e / max) + "% ") + .appendSibling(new TranslationTextComponent("tooltip.battery.charge"))); + list.add(new StringTextComponent("(" + nf.format(max) + "kJ ") + .appendSibling(new TranslationTextComponent("tooltip.battery.capacity")) .appendText(")")); } } diff --git a/src/main/java/zone/moddev/mc/electricadvantage/machines/ElectricBatteryArrayTileEntity.java b/src/main/java/zone/moddev/mc/electricadvantage/machines/ElectricBatteryArrayTileEntity.java index 5260ca7..855ffb2 100644 --- a/src/main/java/zone/moddev/mc/electricadvantage/machines/ElectricBatteryArrayTileEntity.java +++ b/src/main/java/zone/moddev/mc/electricadvantage/machines/ElectricBatteryArrayTileEntity.java @@ -6,7 +6,7 @@ import cyano.poweradvantage.api.PowerRequest; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.CompoundNBT; public class ElectricBatteryArrayTileEntity extends ElectricGeneratorTileEntity{ @@ -168,12 +168,12 @@ protected boolean isValidInputItem(ItemStack item) { } @Override - protected void saveTo(NBTTagCompound tagRoot) { + protected void saveTo(CompoundNBT tagRoot) { // do nothing (inventory already handled } @Override - protected void loadFrom(NBTTagCompound tagRoot) { + protected void loadFrom(CompoundNBT tagRoot) { // do nothing (inventory already handled } diff --git a/src/main/java/zone/moddev/mc/electricadvantage/machines/ElectricCrusherTileEntity.java b/src/main/java/zone/moddev/mc/electricadvantage/machines/ElectricCrusherTileEntity.java index b16e5de..16be176 100644 --- a/src/main/java/zone/moddev/mc/electricadvantage/machines/ElectricCrusherTileEntity.java +++ b/src/main/java/zone/moddev/mc/electricadvantage/machines/ElectricCrusherTileEntity.java @@ -2,11 +2,11 @@ import zone.moddev.mc.electricadvantage.compat.BaseMetalsCompat; import zone.moddev.mc.electricadvantage.init.Power; -import net.minecraft.init.SoundEvents; +import net.minecraft.util.SoundEvents; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import net.minecraft.nbt.NBTTagShort; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.nbt.ListNBT; +import net.minecraft.nbt.ShortNBT; import java.util.Arrays; @@ -100,19 +100,19 @@ public float[] getProgress() { @Override - protected void saveTo(NBTTagCompound tagRoot) { - NBTTagList times = new NBTTagList(); + protected void saveTo(CompoundNBT tagRoot) { + ListNBT times = new ListNBT(); for(int i = 0; i < numberOfInputSlots(); i++){ - times.add(new NBTTagShort(smashTime[i])); + times.add(new ShortNBT(smashTime[i])); } - tagRoot.setTag("smashTime", times); + tagRoot.put("smashTime", times); } @Override - protected void loadFrom(NBTTagCompound tagRoot) { - NBTTagList times = tagRoot.getList("smashTime", 2); + protected void loadFrom(CompoundNBT tagRoot) { + ListNBT times = tagRoot.getList("smashTime", 2); for(int i = 0; i < numberOfInputSlots() && i < times.size(); i++){ - smashTime[i] = ((NBTTagShort)times.get(i)).getShort(); + smashTime[i] = ((ShortNBT)times.get(i)).getShort(); } } diff --git a/src/main/java/zone/moddev/mc/electricadvantage/machines/ElectricDrillBlock.java b/src/main/java/zone/moddev/mc/electricadvantage/machines/ElectricDrillBlock.java index 3a6441b..bd1aac5 100644 --- a/src/main/java/zone/moddev/mc/electricadvantage/machines/ElectricDrillBlock.java +++ b/src/main/java/zone/moddev/mc/electricadvantage/machines/ElectricDrillBlock.java @@ -7,8 +7,8 @@ import cyano.poweradvantage.api.PoweredEntity; import net.minecraft.block.Block; import net.minecraft.block.material.Material; -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.BlockItemUseContext; @@ -18,7 +18,7 @@ import net.minecraft.state.StateContainer; import net.minecraft.state.properties.BlockStateProperties; 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.IBlockReader; @@ -33,15 +33,14 @@ public class ElectricDrillBlock extends GUIBlock implements ITypedConduit { private final ConduitType[] types = {Power.ELECTRIC_POWER}; public ElectricDrillBlock() { - super(Material.PISTON); - setPowerAdvantageHardness(0.75f); + super(Block.Properties.create(Material.PISTON).hardnessAndResistance(0.75F).variableOpacity()); setDefaultState(getStateContainer().getBaseState() .with(ACTIVE, false) - .with(FACING, EnumFacing.DOWN)); + .with(FACING, Direction.DOWN)); } @Override - protected void fillStateContainer(StateContainer.Builder builder) { + protected void fillStateContainer(StateContainer.Builder builder) { builder.add(ACTIVE, FACING); } @@ -51,14 +50,15 @@ public ElectricMachineTileEntity createNewTileEntity(IBlockReader world) { } @Override - public void onBlockAdded(IBlockState state, World world, BlockPos pos, IBlockState oldState) { - super.onBlockAdded(state, world, pos, oldState); + public void onBlockAdded(BlockState state, World world, BlockPos pos, BlockState oldState, boolean isMoving) { + super.onBlockAdded(state, world, pos, oldState, isMoving); + if (state.getBlock() == oldState.getBlock()) return; ConduitRegistry.getInstance().conduitBlockPlacedEvent( world, world.dimension.getType().getId(), pos, Power.ELECTRIC_POWER); } @Override - public void onReplaced(IBlockState state, World world, BlockPos pos, IBlockState newState, boolean isMoving) { + public void onReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean isMoving) { if (state.getBlock() != newState.getBlock()) { ConduitRegistry.getInstance().conduitBlockRemovedEvent( world, world.dimension.getType().getId(), pos, Power.ELECTRIC_POWER); @@ -99,13 +99,13 @@ public boolean canAcceptConnection(PowerConnectorContext connection) { } @Override - public IBlockState getStateForPlacement(BlockItemUseContext context) { + public BlockState getStateForPlacement(BlockItemUseContext context) { return getDefaultState().with(FACING, context.getFace().getOpposite()); } @Override - public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, - EntityLivingBase placer, ItemStack stack) { + public void onBlockPlacedBy(World world, BlockPos pos, BlockState state, + LivingEntity placer, ItemStack stack) { if (stack.hasDisplayName()) { TileEntity tile = world.getTileEntity(pos); if (tile instanceof PoweredEntity) { @@ -115,25 +115,25 @@ public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, } /** Decodes all six legacy facings; bit 3 is the active flag. */ - public IBlockState getStateFromLegacyMeta(int meta) { + public BlockState getStateFromLegacyMeta(int meta) { return getDefaultState() - .with(FACING, EnumFacing.byIndex(meta & 0x7)) + .with(FACING, Direction.byIndex(meta & 0x7)) .with(ACTIVE, (meta & 0x8) != 0); } - public int getLegacyMetaFromState(IBlockState state) { + public int getLegacyMetaFromState(BlockState state) { return state.get(FACING).getIndex() | (state.get(ACTIVE) ? 0x8 : 0); } @Override - public int getComparatorInputOverride(IBlockState state, World world, BlockPos pos) { + public int getComparatorInputOverride(BlockState state, World world, BlockPos pos) { TileEntity tile = world.getTileEntity(pos); return tile instanceof ElectricMachineTileEntity ? ((ElectricMachineTileEntity) tile).getComparatorOutput() : 0; } @Override - public boolean hasComparatorInputOverride(IBlockState state) { + public boolean hasComparatorInputOverride(BlockState state) { return true; } } diff --git a/src/main/java/zone/moddev/mc/electricadvantage/machines/ElectricDrillTileEntity.java b/src/main/java/zone/moddev/mc/electricadvantage/machines/ElectricDrillTileEntity.java index c474e3c..882c866 100644 --- a/src/main/java/zone/moddev/mc/electricadvantage/machines/ElectricDrillTileEntity.java +++ b/src/main/java/zone/moddev/mc/electricadvantage/machines/ElectricDrillTileEntity.java @@ -4,22 +4,23 @@ import zone.moddev.mc.electricadvantage.init.Power; import zone.moddev.mc.poweradvantage.util.InventoryWrapper; import net.minecraft.block.Block; -import net.minecraft.block.state.IBlockState; +import net.minecraft.block.BlockState; import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.init.SoundEvents; +import net.minecraft.entity.LivingEntity; +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.NBTTagList; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.nbt.ListNBT; import net.minecraft.nbt.NBTUtil; import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.EnumFacing; +import net.minecraft.util.Direction; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; import net.minecraft.world.World; +import net.minecraft.world.server.ServerWorld; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -41,7 +42,7 @@ public class ElectricDrillTileEntity extends ElectricMachineTileEntity{ private int progressGoal = 0; private BlockPos targetBlockCoord = null; private Block[] targetBlocks = null; - private NBTTagList savedTargetStates = null; + private ListNBT savedTargetStates = null; private List targetBlockItems = null; private int laserLength = 0; @@ -89,12 +90,12 @@ public void tickUpdate(boolean isServerWorld) { progress++; if(progress >= progressGoal){ // Mined it! - playSoundEffect(targetBlockCoord.getX()+0.5, targetBlockCoord.getY()+0.5, targetBlockCoord.getZ()+0.5, targetBlocks[0].getSoundType().getPlaceSound(), 0.5f, 1f); + playSoundEffect(targetBlockCoord.getX()+0.5, targetBlockCoord.getY()+0.5, targetBlockCoord.getZ()+0.5, getWorld().getBlockState(targetBlockCoord).getSoundType().getPlaceSound(), 0.5f, 1f); playSoundEffect(getPos().getX()+0.5, getPos().getY()+0.5, getPos().getZ()+0.5, SoundEvents.BLOCK_SAND_BREAK, 0.5f, 1f); BlockPos[] targets = this.getArea(targetBlockCoord); for(int i = 0; i < targets.length; i++) if(canMine(targets[i])){ - getWorld().setBlockState(targets[i], net.minecraft.init.Blocks.AIR.getDefaultState(), 3); + getWorld().setBlockState(targets[i], net.minecraft.block.Blocks.AIR.getDefaultState(), 3); } for(ItemStack item : targetBlockItems){ addItem(item); @@ -131,8 +132,8 @@ public ItemStack addItem(ItemStack in){ return super.insertItemToOutputSlots(in); } - private EnumFacing trackDirection(){ - for(EnumFacing dir : EnumFacing.values()){ + private Direction trackDirection(){ + for(Direction dir : Direction.values()){ if(getWorld().getBlockState(getPos().offset(dir)).getBlock() == Blocks.electric_track){ return dir; } @@ -142,7 +143,7 @@ private EnumFacing trackDirection(){ private boolean followTrack(){ if(this.getEnergy() < ENERGY_COST_MOVE) return false; - EnumFacing trackDir = trackDirection(); + Direction trackDir = trackDirection(); if(trackDir == null) return false; // clone this block into neighboring block @@ -151,7 +152,7 @@ private boolean followTrack(){ BlockPos nextPos = getPos().offset(trackDir); w.setBlockState(nextPos, w.getBlockState(getPos()), 2); ElectricDrillTileEntity te = (ElectricDrillTileEntity)w.getTileEntity(nextPos); - NBTTagCompound dataTransfer = new NBTTagCompound(); + CompoundNBT dataTransfer = new CompoundNBT(); this.write(dataTransfer); te.read(dataTransfer); te.setPos(nextPos); @@ -205,7 +206,7 @@ public void onDataFieldUpdate() { boolean redstone = hasRedstoneSignal(); - EnumFacing f = getFacing(); + Direction f = getFacing(); BlockPos n = getPos().offset(f); // manage drill bits and find next block @@ -288,7 +289,7 @@ public void onDataFieldUpdate() { BlockPos pos = getPos(); AxisAlignedBB beamArea = new AxisAlignedBB(targetBlockCoord.getX(),targetBlockCoord.getY(),targetBlockCoord.getZ(), pos.getX()+1,pos.getY()+1,pos.getZ()+1); - List victims = getWorld().getEntitiesWithinAABB(EntityLivingBase.class, beamArea); + List victims = getWorld().getEntitiesWithinAABB(LivingEntity.class, beamArea); for(Entity e : victims){ e.setFire(3); e.attackEntityFrom(Power.laser_damage, 2f); @@ -317,15 +318,14 @@ private void targetBlock (BlockPos pos){ targetBlockCoord = pos; progressGoal = 0; targetBlocks = new Block[targets.length]; - savedTargetStates = new NBTTagList(); + savedTargetStates = new ListNBT(); targetBlockItems = new ArrayList<>(targets.length); for(int i = 0; i < targets.length; i++){ targetBlocks[i] = getWorld().getBlockState(targets[i]).getBlock(); savedTargetStates.add(NBTUtil.writeBlockState(getWorld().getBlockState(targets[i]))); progressGoal += this.getBlockStrength(targets[i]); - net.minecraft.util.NonNullList drops = net.minecraft.util.NonNullList.create(); - targetBlocks[i].getDrops(getWorld().getBlockState(targets[i]), drops, getWorld(), targets[i], 0); - targetBlockItems.addAll(drops); + targetBlockItems.addAll(Block.getDrops(getWorld().getBlockState(targets[i]), + (ServerWorld) getWorld(), targets[i], getWorld().getTileEntity(targets[i]))); } deferred = false; } @@ -404,14 +404,14 @@ private void untargetBlock(){ targetBlockItems = null; } - private EnumFacing facingCache = null; - public EnumFacing getFacing(){ + private Direction facingCache = null; + public Direction getFacing(){ if(facingCache == null) updateFacing(); return facingCache; } private void updateFacing(){ - final EnumFacing old = facingCache; - facingCache = (EnumFacing)getWorld().getBlockState(getPos()).get(ElectricDrillBlock.FACING); + final Direction old = facingCache; + facingCache = (Direction)getWorld().getBlockState(getPos()).get(ElectricDrillBlock.FACING); if(old != null && old != facingCache){ untargetBlock(); this.sync(); @@ -420,7 +420,7 @@ private void updateFacing(){ private boolean canMine(BlockPos coord){ - IBlockState bs = getWorld().getBlockState(coord); + BlockState bs = getWorld().getBlockState(coord); Block b = bs.getBlock(); // indestructable blocks have negative hardness return !(b.getBlockHardness(bs, getWorld(), coord) < 0); @@ -430,14 +430,14 @@ private int getBlockStrength(BlockPos coord){ if(getWorld().isAirBlock(coord)){ return 0; } - IBlockState bs = getWorld().getBlockState(coord); + BlockState bs = getWorld().getBlockState(coord); Block block = bs.getBlock(); return (int)(Math.max(MINING_TIME_FACTOR * block.getBlockHardness(bs, getWorld(), coord),0.5f * MINING_TIME_FACTOR)); } - private void inventoryTransfer(BlockPos adj, EnumFacing otherFace) { + private void inventoryTransfer(BlockPos adj, Direction otherFace) { ItemStack[] inventory = this.getInventory(); TileEntity te = getWorld().getTileEntity(adj); if(te instanceof IInventory ){ @@ -489,18 +489,18 @@ public float getProgressLevel(){ @Override - protected void saveTo(NBTTagCompound tagRoot) { - tagRoot.setShort("progress",(short)progress); + protected void saveTo(CompoundNBT tagRoot) { + tagRoot.putShort("progress",(short)progress); if(targetBlockCoord != null){ - tagRoot.setInt("targetX", targetBlockCoord.getX()); - tagRoot.setInt("targetY", targetBlockCoord.getY()); - tagRoot.setInt("targetZ", targetBlockCoord.getZ()); - if(savedTargetStates != null) tagRoot.setTag("TargetStates", savedTargetStates.copy()); + tagRoot.putInt("targetX", targetBlockCoord.getX()); + tagRoot.putInt("targetY", targetBlockCoord.getY()); + tagRoot.putInt("targetZ", targetBlockCoord.getZ()); + if(savedTargetStates != null) tagRoot.put("TargetStates", savedTargetStates.copy()); } } @Override - protected void loadFrom(NBTTagCompound tagRoot) { + protected void loadFrom(CompoundNBT tagRoot) { untargetBlock(); if(tagRoot.contains("progress", 99)){ progress = tagRoot.getShort("progress"); @@ -527,19 +527,11 @@ protected boolean isValidInputItem(ItemStack item) { @Override protected void setActiveState(boolean active){ - IBlockState oldState = getWorld().getBlockState(getPos()); + BlockState oldState = getWorld().getBlockState(getPos()); if(oldState.getBlock() instanceof ElectricDrillBlock && (Boolean)oldState.get(ElectricDrillBlock.ACTIVE) != active ){ - final TileEntity save = this; - final World w = getWorld(); - final BlockPos pos = this.getPos(); - IBlockState newState = oldState.with(ElectricDrillBlock.ACTIVE, active); - w.setBlockState(pos, newState,3); - if(save != null){ - w.removeTileEntity(pos); - save.validate(); - w.setTileEntity(pos, save); - } + BlockState newState = oldState.with(ElectricDrillBlock.ACTIVE, active); + getWorld().setBlockState(getPos(), newState, 3); } } @Override diff --git a/src/main/java/zone/moddev/mc/electricadvantage/machines/ElectricFabricatorTileEntity.java b/src/main/java/zone/moddev/mc/electricadvantage/machines/ElectricFabricatorTileEntity.java index 961d8ab..c981b67 100644 --- a/src/main/java/zone/moddev/mc/electricadvantage/machines/ElectricFabricatorTileEntity.java +++ b/src/main/java/zone/moddev/mc/electricadvantage/machines/ElectricFabricatorTileEntity.java @@ -2,9 +2,9 @@ import zone.moddev.mc.electricadvantage.util.crafting.RecipeDeconstructor; import zone.moddev.mc.electricadvantage.util.crafting.SerializedInventory; -import net.minecraft.init.SoundEvents; +import net.minecraft.util.SoundEvents; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.CompoundNBT; import java.util.Arrays; import java.util.List; @@ -160,13 +160,13 @@ public float[] getProgress() { } @Override - protected void saveTo(NBTTagCompound tagRoot) { - tagRoot.setShort("progress", (short)progress); - tagRoot.setByte("FSM", (byte)state.ordinal()); + protected void saveTo(CompoundNBT tagRoot) { + tagRoot.putShort("progress", (short)progress); + tagRoot.putByte("FSM", (byte)state.ordinal()); } @Override - protected void loadFrom(NBTTagCompound tagRoot) { + protected void loadFrom(CompoundNBT tagRoot) { if(tagRoot.contains("progress", 99)){ this.progress = tagRoot.getShort("progress"); } diff --git a/src/main/java/zone/moddev/mc/electricadvantage/machines/ElectricFurnaceTileEntity.java b/src/main/java/zone/moddev/mc/electricadvantage/machines/ElectricFurnaceTileEntity.java index 6c2bb40..99f7146 100644 --- a/src/main/java/zone/moddev/mc/electricadvantage/machines/ElectricFurnaceTileEntity.java +++ b/src/main/java/zone/moddev/mc/electricadvantage/machines/ElectricFurnaceTileEntity.java @@ -4,9 +4,9 @@ import zone.moddev.mc.electricadvantage.init.Power; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import net.minecraft.nbt.NBTTagShort; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.nbt.ListNBT; +import net.minecraft.nbt.ShortNBT; public class ElectricFurnaceTileEntity extends ElectricMachineTileEntity{ @@ -96,19 +96,19 @@ public float[] getProgress() { @Override - protected void saveTo(NBTTagCompound tagRoot) { - NBTTagList burnTimes = new NBTTagList(); + protected void saveTo(CompoundNBT tagRoot) { + ListNBT burnTimes = new ListNBT(); for(int i = 0; i < numberOfInputSlots(); i++){ - burnTimes.add(new NBTTagShort(burnTime[i])); + burnTimes.add(new ShortNBT(burnTime[i])); } - tagRoot.setTag("cookTime", burnTimes); + tagRoot.put("cookTime", burnTimes); } @Override - protected void loadFrom(NBTTagCompound tagRoot) { - NBTTagList burnTimes = tagRoot.getList("cookTime", 2); + protected void loadFrom(CompoundNBT tagRoot) { + ListNBT burnTimes = tagRoot.getList("cookTime", 2); for(int i = 0; i < numberOfInputSlots() && i < burnTimes.size(); i++){ - burnTime[i] = ((NBTTagShort)burnTimes.get(i)).getShort(); + burnTime[i] = ((ShortNBT)burnTimes.get(i)).getShort(); } } diff --git a/src/main/java/zone/moddev/mc/electricadvantage/machines/ElectricGeneratorBlock.java b/src/main/java/zone/moddev/mc/electricadvantage/machines/ElectricGeneratorBlock.java index 868a97f..432df8c 100644 --- a/src/main/java/zone/moddev/mc/electricadvantage/machines/ElectricGeneratorBlock.java +++ b/src/main/java/zone/moddev/mc/electricadvantage/machines/ElectricGeneratorBlock.java @@ -4,13 +4,13 @@ import cyano.poweradvantage.api.simple.BlockSimplePowerMachine; 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.inventory.IInventory; import net.minecraft.inventory.InventoryHelper; import net.minecraft.state.BooleanProperty; import net.minecraft.state.StateContainer; 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.IBlockReader; import net.minecraft.world.World; @@ -36,22 +36,22 @@ protected ElectricGeneratorBlock(Block.Properties properties) { private void initializeDefaultState() { setDefaultState(getStateContainer().getBaseState() .with(ACTIVE, false) - .with(FACING, EnumFacing.NORTH)); + .with(FACING, Direction.NORTH)); } @Override - protected void fillStateContainer(StateContainer.Builder builder) { + protected void fillStateContainer(StateContainer.Builder builder) { builder.add(ACTIVE, FACING); } /** Decodes the 1.10/1.12 metadata used by world migration fixtures. */ - public IBlockState getStateFromLegacyMeta(int meta) { - EnumFacing facing = EnumFacing.byIndex(meta & 0x7); - if (facing.getAxis() == EnumFacing.Axis.Y) facing = EnumFacing.NORTH; + public BlockState getStateFromLegacyMeta(int meta) { + Direction facing = Direction.byIndex(meta & 0x7); + if (facing.getAxis() == Direction.Axis.Y) facing = Direction.NORTH; return getDefaultState().with(FACING, facing).with(ACTIVE, (meta & 0x8) != 0); } - public int getLegacyMetaFromState(IBlockState state) { + public int getLegacyMetaFromState(BlockState state) { return state.get(FACING).getIndex() | (state.get(ACTIVE) ? 0x8 : 0); } @@ -59,19 +59,19 @@ public int getLegacyMetaFromState(IBlockState state) { public abstract ElectricGeneratorTileEntity createNewTileEntity(IBlockReader world); @Override - public int getComparatorInputOverride(IBlockState state, World world, BlockPos pos) { + public int getComparatorInputOverride(BlockState state, World world, BlockPos pos) { TileEntity tile = world.getTileEntity(pos); return tile instanceof ElectricGeneratorTileEntity ? ((ElectricGeneratorTileEntity) tile).getComparatorOutput() : 0; } @Override - public boolean hasComparatorInputOverride(IBlockState state) { + public boolean hasComparatorInputOverride(BlockState state) { return true; } @Override - public void onReplaced(IBlockState state, World world, BlockPos pos, IBlockState newState, boolean isMoving) { + public void onReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean isMoving) { if (state.getBlock() != newState.getBlock()) { TileEntity tile = world.getTileEntity(pos); if (tile instanceof IInventory) { diff --git a/src/main/java/zone/moddev/mc/electricadvantage/machines/ElectricGeneratorTileEntity.java b/src/main/java/zone/moddev/mc/electricadvantage/machines/ElectricGeneratorTileEntity.java index e928dc3..90dcedc 100644 --- a/src/main/java/zone/moddev/mc/electricadvantage/machines/ElectricGeneratorTileEntity.java +++ b/src/main/java/zone/moddev/mc/electricadvantage/machines/ElectricGeneratorTileEntity.java @@ -2,13 +2,13 @@ import zone.moddev.mc.electricadvantage.init.Power; import cyano.poweradvantage.api.ConduitType; -import net.minecraft.block.state.IBlockState; -import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.block.BlockState; +import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.network.play.server.SPacketCustomSound; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.network.play.server.SPlaySoundPacket; import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.EnumFacing; +import net.minecraft.util.Direction; import net.minecraft.util.SoundCategory; import net.minecraft.util.SoundEvent; import net.minecraft.util.math.AxisAlignedBB; @@ -64,36 +64,21 @@ protected boolean hasRedstoneSignal(){ protected void setActive(boolean active){ - IBlockState old = getWorld().getBlockState(getPos()); + BlockState old = getWorld().getBlockState(getPos()); if(old.getBlock() instanceof ElectricGeneratorBlock && (Boolean)old.get(ElectricGeneratorBlock.ACTIVE) != active){ - final TileEntity save = this; - final World w = getWorld(); - final BlockPos pos = this.getPos(); - w.setBlockState(pos, old.with(ElectricGeneratorBlock.ACTIVE, active),3); - if(save != null){ - w.removeTileEntity(pos); - save.validate(); - w.setTileEntity(pos, save); - } + getWorld().setBlockState(getPos(), old.with(ElectricGeneratorBlock.ACTIVE, active), 3); } } - @Override - public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newSate) - { - // used to allow change in blockstate without interrupting the TileEntity or the GUI - return (oldState.getBlock() != newSate.getBlock()); - } - protected void playSoundEffect(double x, double y, double z, SoundEvent sound, float volume, float pitch){ if(getWorld().isRemote) return; final double range = 16; - List players = getWorld().getEntitiesWithinAABB(EntityPlayerMP.class, new AxisAlignedBB( + List players = getWorld().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(), SoundCategory.BLOCKS, + for(ServerPlayerEntity player : players){ + player.connection.sendPacket(new SPlaySoundPacket(sound.getRegistryName(), SoundCategory.BLOCKS, new net.minecraft.util.math.Vec3d(x, y, z), volume, pitch)); } } @@ -135,7 +120,7 @@ protected ItemStack[] getInventory() { @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 isValidInputItem(srcItem) && isInArray(slot,inputSlots); } @@ -183,20 +168,20 @@ public int getComparatorOutput(){ @Override - public NBTTagCompound write(NBTTagCompound tagRoot){ + public CompoundNBT write(CompoundNBT tagRoot){ super.write(tagRoot); saveTo(tagRoot); return tagRoot; } @Override - public void read(NBTTagCompound tagRoot){ + public void read(CompoundNBT tagRoot){ super.read(tagRoot); loadFrom(tagRoot); } - protected abstract void saveTo(NBTTagCompound tagRoot); - protected abstract void loadFrom(NBTTagCompound tagRoot); + protected abstract void saveTo(CompoundNBT tagRoot); + protected abstract void loadFrom(CompoundNBT tagRoot); @Override public int getInventoryStackLimit(){return 64;} } diff --git a/src/main/java/zone/moddev/mc/electricadvantage/machines/ElectricMachineBlock.java b/src/main/java/zone/moddev/mc/electricadvantage/machines/ElectricMachineBlock.java index cbb07cc..c8a7280 100644 --- a/src/main/java/zone/moddev/mc/electricadvantage/machines/ElectricMachineBlock.java +++ b/src/main/java/zone/moddev/mc/electricadvantage/machines/ElectricMachineBlock.java @@ -4,13 +4,13 @@ import cyano.poweradvantage.api.simple.BlockSimplePowerMachine; 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.inventory.IInventory; import net.minecraft.inventory.InventoryHelper; import net.minecraft.state.BooleanProperty; import net.minecraft.state.StateContainer; 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.IBlockReader; import net.minecraft.world.World; @@ -38,7 +38,7 @@ private void initializeDefaultState() { setDefaultState(getStateContainer().getBaseState() .with(ACTIVE, false) .with(POWERED, false) - .with(FACING, EnumFacing.NORTH)); + .with(FACING, Direction.NORTH)); } public ElectricMachineBlock(Material material) { @@ -46,12 +46,12 @@ public ElectricMachineBlock(Material material) { } @Override - protected void fillStateContainer(StateContainer.Builder builder) { + protected void fillStateContainer(StateContainer.Builder builder) { builder.add(ACTIVE, FACING, POWERED); } /** Decodes the 1.10/1.12 metadata used by world migration fixtures. */ - public IBlockState getStateFromLegacyMeta(int meta) { + public BlockState getStateFromLegacyMeta(int meta) { return getDefaultState() .with(FACING, metaToFacing(meta)) .with(ACTIVE, (meta & 0x4) != 0) @@ -59,14 +59,14 @@ public IBlockState getStateFromLegacyMeta(int meta) { } /** Encodes the legacy metadata layout for migration tests. */ - public int getLegacyMetaFromState(IBlockState state) { + public int getLegacyMetaFromState(BlockState state) { int meta = facingToMeta(state.get(FACING)); if (state.get(ACTIVE)) meta |= 0x4; if (state.get(POWERED)) meta |= 0x8; return meta; } - private static int facingToMeta(EnumFacing facing) { + private static int facingToMeta(Direction facing) { switch (facing) { case WEST: return 1; case SOUTH: return 2; @@ -75,12 +75,12 @@ private static int facingToMeta(EnumFacing facing) { } } - private static EnumFacing metaToFacing(int meta) { + private static Direction metaToFacing(int meta) { switch (meta & 0x3) { - case 1: return EnumFacing.WEST; - case 2: return EnumFacing.SOUTH; - case 3: return EnumFacing.EAST; - default: return EnumFacing.NORTH; + case 1: return Direction.WEST; + case 2: return Direction.SOUTH; + case 3: return Direction.EAST; + default: return Direction.NORTH; } } @@ -88,19 +88,19 @@ private static EnumFacing metaToFacing(int meta) { public abstract ElectricMachineTileEntity createNewTileEntity(IBlockReader world); @Override - public int getComparatorInputOverride(IBlockState state, World world, BlockPos pos) { + public int getComparatorInputOverride(BlockState state, World world, BlockPos pos) { TileEntity tile = world.getTileEntity(pos); return tile instanceof ElectricMachineTileEntity ? ((ElectricMachineTileEntity) tile).getComparatorOutput() : 0; } @Override - public boolean hasComparatorInputOverride(IBlockState state) { + public boolean hasComparatorInputOverride(BlockState state) { return true; } @Override - public void onReplaced(IBlockState state, World world, BlockPos pos, IBlockState newState, boolean isMoving) { + public void onReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean isMoving) { if (state.getBlock() != newState.getBlock()) { TileEntity tile = world.getTileEntity(pos); if (tile instanceof IInventory) { diff --git a/src/main/java/zone/moddev/mc/electricadvantage/machines/ElectricMachineTileEntity.java b/src/main/java/zone/moddev/mc/electricadvantage/machines/ElectricMachineTileEntity.java index 478d5c4..9677d1a 100644 --- a/src/main/java/zone/moddev/mc/electricadvantage/machines/ElectricMachineTileEntity.java +++ b/src/main/java/zone/moddev/mc/electricadvantage/machines/ElectricMachineTileEntity.java @@ -2,23 +2,23 @@ import zone.moddev.mc.electricadvantage.init.Power; import cyano.poweradvantage.api.ConduitType; -import net.minecraft.block.state.IBlockState; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.inventory.InventoryBasic; +import net.minecraft.block.BlockState; +import net.minecraft.entity.player.ServerPlayerEntity; +import net.minecraft.inventory.Inventory; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.IRecipe; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.network.play.server.SPacketCustomSound; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.network.play.server.SPlaySoundPacket; import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityType; -import net.minecraft.util.EnumFacing; +import net.minecraft.util.Direction; import net.minecraft.util.SoundCategory; import net.minecraft.util.SoundEvent; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; -import net.minecraft.util.text.TextComponentString; +import net.minecraft.util.text.StringTextComponent; import net.minecraft.world.World; -import net.minecraftforge.common.crafting.VanillaRecipeTypes; +import net.minecraft.item.crafting.IRecipeType; import zone.moddev.mc.electricadvantage.ElectricAdvantage; import java.util.Arrays; @@ -104,46 +104,23 @@ protected boolean hasRedstoneSignal(){ protected void setActiveState(boolean active){ - IBlockState oldState = getWorld().getBlockState(getPos()); + BlockState oldState = getWorld().getBlockState(getPos()); if(oldState.getBlock() instanceof ElectricMachineBlock && (Boolean)oldState.get(ElectricMachineBlock.ACTIVE) != active ){ - final TileEntity save = this; - final World w = getWorld(); - final BlockPos pos = this.getPos(); - IBlockState newState = oldState.with(ElectricMachineBlock.ACTIVE, active); - w.setBlockState(pos, newState,3); - if(save != null){ - w.removeTileEntity(pos); - save.validate(); - w.setTileEntity(pos, save); - } + BlockState newState = oldState.with(ElectricMachineBlock.ACTIVE, active); + getWorld().setBlockState(getPos(), newState, 3); } } protected void setPowerState(boolean powered){ - IBlockState oldState = getWorld().getBlockState(getPos()); + BlockState oldState = getWorld().getBlockState(getPos()); if(oldState.getBlock() instanceof ElectricMachineBlock && (Boolean)oldState.get(ElectricMachineBlock.POWERED) != powered ){ - final TileEntity save = this; - final World w = getWorld(); - final BlockPos pos = this.getPos(); - IBlockState newState = oldState.with(ElectricMachineBlock.POWERED, powered); - w.setBlockState(pos, newState, 3); - if(save != null){ - w.removeTileEntity(pos); - save.validate(); - w.setTileEntity(pos, save); - } + BlockState newState = oldState.with(ElectricMachineBlock.POWERED, powered); + getWorld().setBlockState(getPos(), newState, 3); } } - @Override - public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newState) - { - // used to allow change in blockstate without interrupting the TileEntity or the GUI - return (oldState.getBlock() != newState.getBlock()); - } - public boolean isActive(){ return isPowered() && (!this.hasRedstoneSignal() && (this.getEnergy(Power.ELECTRIC_POWER) > 0 || (Boolean)getWorld().getBlockState(getPos()).get(ElectricMachineBlock.ACTIVE))); } @@ -240,41 +217,41 @@ protected static boolean areItemStacksEqualNullable(ItemStack left, ItemStack ri protected ItemStack getSmeltingResult(ItemStack input) { if (isEmptyStack(input) || getWorld() == null) return ItemStack.EMPTY; - InventoryBasic inventory = new InventoryBasic(new TextComponentString("electricadvantage.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); } @Override - public NBTTagCompound write(NBTTagCompound tagRoot){ + public CompoundNBT write(CompoundNBT tagRoot){ super.write(tagRoot); saveTo(tagRoot); return tagRoot; } @Override - public NBTTagCompound getUpdateTag() { - return write(new NBTTagCompound()); + public CompoundNBT getUpdateTag() { + return write(new CompoundNBT()); } @Override - public void read(NBTTagCompound tagRoot){ + public void read(CompoundNBT tagRoot){ super.read(tagRoot); loadFrom(tagRoot); } - protected abstract void saveTo(NBTTagCompound tagRoot); - protected abstract void loadFrom(NBTTagCompound tagRoot); + protected abstract void saveTo(CompoundNBT tagRoot); + protected abstract void loadFrom(CompoundNBT tagRoot); @Override - public int[] getSlotsForFace(EnumFacing side) { + public int[] getSlotsForFace(Direction side) { return ioSlots; } @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 isInArray(slot,outputSlots); } @@ -319,7 +296,7 @@ public boolean hasSpaceForItemInInputSlots(ItemStack stack){ } @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 isValidInputItem(srcItem) && isInArray(slot,inputSlots); } @@ -366,11 +343,11 @@ public ItemStack insertItemToInputSlots(ItemStack itemStack){ protected void playSoundEffect(double x, double y, double z, SoundEvent sound, float volume, float pitch){ if(getWorld().isRemote) return; final double range = 16; - List players = getWorld().getEntitiesWithinAABB(EntityPlayerMP.class, new AxisAlignedBB( + List players = getWorld().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(), SoundCategory.BLOCKS, + for(ServerPlayerEntity player : players){ + player.connection.sendPacket(new SPlaySoundPacket(sound.getRegistryName(), SoundCategory.BLOCKS, new net.minecraft.util.math.Vec3d(x, y, z), volume, pitch)); } } diff --git a/src/main/java/zone/moddev/mc/electricadvantage/machines/ElectricOvenTileEntity.java b/src/main/java/zone/moddev/mc/electricadvantage/machines/ElectricOvenTileEntity.java index aefa1e8..e91c176 100644 --- a/src/main/java/zone/moddev/mc/electricadvantage/machines/ElectricOvenTileEntity.java +++ b/src/main/java/zone/moddev/mc/electricadvantage/machines/ElectricOvenTileEntity.java @@ -1,10 +1,10 @@ package zone.moddev.mc.electricadvantage.machines; import zone.moddev.mc.electricadvantage.init.Power; -import net.minecraft.init.SoundEvents; +import net.minecraft.util.SoundEvents; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.CompoundNBT; public class ElectricOvenTileEntity extends ElectricMachineTileEntity{ @@ -52,7 +52,7 @@ public void tickUpdate(boolean isServerWorld) { public static boolean isFoodItem(ItemStack item){ if(item == null) return false; Item i = item.getItem(); - return (i instanceof net.minecraft.item.ItemFood); + return !item.isEmpty() && i.isFood(); } public boolean becomesFoodItem(ItemStack item){ @@ -75,12 +75,12 @@ public float[] getProgress() { } @Override - protected void saveTo(NBTTagCompound tagRoot) { - tagRoot.setShort("cookTime", progress); + protected void saveTo(CompoundNBT tagRoot) { + tagRoot.putShort("cookTime", progress); } @Override - protected void loadFrom(NBTTagCompound tagRoot) { + protected void loadFrom(CompoundNBT tagRoot) { if(tagRoot.contains("cookTime", 99)){ progress = tagRoot.getShort("cookTime"); } diff --git a/src/main/java/zone/moddev/mc/electricadvantage/machines/ElectricPumpBlock.java b/src/main/java/zone/moddev/mc/electricadvantage/machines/ElectricPumpBlock.java index ce9e806..168ed04 100644 --- a/src/main/java/zone/moddev/mc/electricadvantage/machines/ElectricPumpBlock.java +++ b/src/main/java/zone/moddev/mc/electricadvantage/machines/ElectricPumpBlock.java @@ -6,7 +6,7 @@ import cyano.poweradvantage.api.PowerConnectorContext; import zone.moddev.mc.poweradvantage.conduitnetwork.ConduitRegistry; import zone.moddev.mc.poweradvantage.init.Fluids; -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; @@ -24,7 +24,7 @@ public ElectricMachineTileEntity createNewTileEntity(net.minecraft.world.IBlockR * This method is called whenever the block is placed into the world */ @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); } @@ -43,7 +43,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_electric){ - w.setBlockState(c, net.minecraft.init.Blocks.AIR.getDefaultState()); + w.setBlockState(c, net.minecraft.block.Blocks.AIR.getDefaultState()); c = c.down(); } } diff --git a/src/main/java/zone/moddev/mc/electricadvantage/machines/ElectricPumpTileEntity.java b/src/main/java/zone/moddev/mc/electricadvantage/machines/ElectricPumpTileEntity.java index fb5f954..710c41d 100644 --- a/src/main/java/zone/moddev/mc/electricadvantage/machines/ElectricPumpTileEntity.java +++ b/src/main/java/zone/moddev/mc/electricadvantage/machines/ElectricPumpTileEntity.java @@ -8,11 +8,11 @@ import zone.moddev.mc.poweradvantage.conduitnetwork.ConduitRegistry; import zone.moddev.mc.poweradvantage.init.Fluids; import zone.moddev.mc.poweradvantage.util.FluidIdHelper; -import net.minecraft.block.state.IBlockState; -import net.minecraft.init.SoundEvents; +import net.minecraft.block.BlockState; +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.math.BlockPos; import net.minecraft.world.World; import net.minecraft.fluid.Fluid; @@ -54,7 +54,6 @@ public ElectricPumpTileEntity() { public void tickUpdate(boolean isServerWorld) { if(isServerWorld){ // server-side logic - net.minecraft.tileentity.TileEntityPiston k; if(!hasRedstoneSignal()){ if(timeUntilNextPump > 0) timeUntilNextPump--; if(timeUntilNextPump == 0 && getTank().getFluidAmount() <= 0){ @@ -82,12 +81,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() >= cost){ this.getTank().fill(new FluidStack(f, FluidTank.BUCKET_VOLUME), true); this.subtractEnergy(cost, Power.ELECTRIC_POWER); - w.setBlockState(fluidSource, net.minecraft.init.Blocks.AIR.getDefaultState(), 3); + w.setBlockState(fluidSource, net.minecraft.block.Blocks.AIR.getDefaultState(), 3); success = true; } } @@ -130,7 +129,7 @@ protected boolean isValidInputItem(ItemStack item) { } - private Fluid getFluid(IBlockState blockstate) { + private Fluid getFluid(BlockState blockstate) { return blockstate.getFluidState().isEmpty() ? null : blockstate.getFluidState().getFluid(); } @@ -145,7 +144,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; @@ -237,7 +236,7 @@ public int[] getDataFieldArray() { public void prepareDataFieldsForSync() { dataSyncArray[0] = Float.floatToRawIntBits(this.getEnergy()); 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; } @@ -256,20 +255,20 @@ public void onDataFieldUpdate() { * @param tagRoot An NBT tag */ @Override - public void saveTo(final NBTTagCompound tagRoot) { - NBTTagCompound tankTag = new NBTTagCompound(); + public void saveTo(final CompoundNBT tagRoot) { + 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); } /** * Handles data saving and loading * @param tagRoot An NBT tag */ @Override - public void loadFrom(final NBTTagCompound tagRoot) { + public void loadFrom(final CompoundNBT tagRoot) { if (tagRoot.contains("Tank", 10)) { - NBTTagCompound tankTag = tagRoot.getCompound("Tank"); + CompoundNBT tankTag = tagRoot.getCompound("Tank"); getTank().readFromNBT(tankTag); if(tankTag.contains("Empty", 1)){ // empty the tank if NBT says its empty (not default behavior of Tank.readFromNBT(...) ) @@ -358,7 +357,7 @@ public boolean canAcceptConnection(PowerConnectorContext c){ * @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); @@ -372,7 +371,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(fluid == null) return null; if(getTank().getFluidAmount() > 0 && getTank().getFluid().getFluid().equals(fluid.getFluid())){ return getTank().drain(fluid.amount,forReal); @@ -387,7 +386,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(amount > 0 && getTank().getFluidAmount() > 0 ){ return getTank().drain(amount,forReal); } else { @@ -400,7 +399,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()); @@ -411,7 +410,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()); } @@ -422,7 +421,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/electricadvantage/machines/ElectricStillTileEntity.java b/src/main/java/zone/moddev/mc/electricadvantage/machines/ElectricStillTileEntity.java index 19914ad..b983f43 100644 --- a/src/main/java/zone/moddev/mc/electricadvantage/machines/ElectricStillTileEntity.java +++ b/src/main/java/zone/moddev/mc/electricadvantage/machines/ElectricStillTileEntity.java @@ -10,10 +10,10 @@ import zone.moddev.mc.poweradvantage.registry.still.recipe.DistillationRecipe; import zone.moddev.mc.poweradvantage.registry.still.recipe.DistillationRecipeRegistry; import zone.moddev.mc.poweradvantage.util.FluidIdHelper; -import net.minecraft.init.SoundEvents; +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.fluid.Fluid; import cyano.poweradvantage.api.fluid.FluidStack; import cyano.poweradvantage.api.fluid.FluidTank; @@ -152,9 +152,9 @@ public int[] getDataFieldArray() { public void prepareDataFieldsForSync() { dataSyncArray[0] = Float.floatToRawIntBits(this.getEnergy()); dataSyncArray[1] = this.getOutputTank().getFluidAmount(); - dataSyncArray[2] = (this.getOutputTank().getFluidAmount() > 0 ? FluidIdHelper.getFluidId(this.getOutputTank().getFluid().getFluid()) : FluidIdHelper.getFluidId(net.minecraft.init.Fluids.WATER)); + dataSyncArray[2] = (this.getOutputTank().getFluidAmount() > 0 ? FluidIdHelper.getFluidId(this.getOutputTank().getFluid().getFluid()) : FluidIdHelper.getFluidId(net.minecraft.fluid.Fluids.WATER)); dataSyncArray[3] = getInputTank().getFluidAmount(); - dataSyncArray[4] = (getInputTank().getFluidAmount() > 0 ? FluidIdHelper.getFluidId(getInputTank().getFluid().getFluid()) : FluidIdHelper.getFluidId(net.minecraft.init.Fluids.WATER)); + dataSyncArray[4] = (getInputTank().getFluidAmount() > 0 ? FluidIdHelper.getFluidId(getInputTank().getFluid().getFluid()) : FluidIdHelper.getFluidId(net.minecraft.fluid.Fluids.WATER)); } @Override @@ -171,22 +171,22 @@ public void onDataFieldUpdate() { * @param tagRoot An NBT tag */ @Override - public void saveTo(final NBTTagCompound tagRoot) { - NBTTagCompound tankTag = new NBTTagCompound(); + public void saveTo(final CompoundNBT tagRoot) { + 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); } /** * Handles data saving and loading * @param tagRoot An NBT tag */ @Override - public void loadFrom(final NBTTagCompound tagRoot) { + public void loadFrom(final CompoundNBT tagRoot) { if (tagRoot.contains("TankOut", 10)) { - NBTTagCompound tankTag = tagRoot.getCompound("TankOut"); + CompoundNBT tankTag = tagRoot.getCompound("TankOut"); getOutputTank().readFromNBT(tankTag); if(tankTag.contains("Empty", 1)){ // empty the tank if NBT says its empty (not default behavior of Tank.readFromNBT(...) ) @@ -195,7 +195,7 @@ public void loadFrom(final NBTTagCompound tagRoot) { } if (tagRoot.contains("TankIn", 10)) { - NBTTagCompound tankTag = tagRoot.getCompound("TankIn"); + CompoundNBT tankTag = tagRoot.getCompound("TankIn"); getInputTank().readFromNBT(tankTag); if(tankTag.contains("Empty", 1)){ // empty the tank if NBT says its empty (not default behavior of Tank.readFromNBT(...) ) @@ -321,7 +321,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(getInputTank().getFluidAmount() <= 0 || getInputTank().getFluid().getFluid().equals(fluid.getFluid())){ if(canDistill(fluid)){ @@ -337,7 +337,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(fluid == null) return null; if(getOutputTank().getFluidAmount() > 0 && getOutputTank().getFluid().getFluid().equals(fluid.getFluid())){ return getOutputTank().drain(fluid.amount,forReal); @@ -352,7 +352,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(amount > 0 && getOutputTank().getFluidAmount() > 0 ){ return getOutputTank().drain(amount,forReal); } else { @@ -365,7 +365,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; @@ -377,7 +377,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()); } @@ -388,7 +388,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(); diff --git a/src/main/java/zone/moddev/mc/electricadvantage/machines/GrowthChamberControllerBlock.java b/src/main/java/zone/moddev/mc/electricadvantage/machines/GrowthChamberControllerBlock.java index 9a28985..144c3c2 100644 --- a/src/main/java/zone/moddev/mc/electricadvantage/machines/GrowthChamberControllerBlock.java +++ b/src/main/java/zone/moddev/mc/electricadvantage/machines/GrowthChamberControllerBlock.java @@ -6,7 +6,7 @@ import cyano.poweradvantage.api.PoweredEntity; import zone.moddev.mc.poweradvantage.init.Fluids; 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; @@ -30,12 +30,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 GrowthChamberControllerTileEntity){ return ((GrowthChamberControllerTileEntity)world.getTileEntity(coord)).getComparatorOutput(); } diff --git a/src/main/java/zone/moddev/mc/electricadvantage/machines/GrowthChamberControllerTileEntity.java b/src/main/java/zone/moddev/mc/electricadvantage/machines/GrowthChamberControllerTileEntity.java index 9b46b71..006b994 100644 --- a/src/main/java/zone/moddev/mc/electricadvantage/machines/GrowthChamberControllerTileEntity.java +++ b/src/main/java/zone/moddev/mc/electricadvantage/machines/GrowthChamberControllerTileEntity.java @@ -8,8 +8,8 @@ import cyano.poweradvantage.api.fluid.FluidRequest; import zone.moddev.mc.poweradvantage.init.Fluids; 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.fluid.Fluid; import cyano.poweradvantage.api.fluid.FluidStack; import cyano.poweradvantage.api.fluid.FluidTank; @@ -79,7 +79,7 @@ public void tickUpdate(boolean isServerWorld) { private static boolean isDirt(ItemStack i){ return i != null && !i.isEmpty() - && (i.getItem() == net.minecraft.init.Blocks.DIRT.asItem() + && (i.getItem() == net.minecraft.block.Blocks.DIRT.asItem() || ItemTags.getCollection().getOrCreate(new ResourceLocation("forge", "dirt")).contains(i.getItem())); } @@ -177,7 +177,7 @@ public void prepareDataFieldsForSync() { @Override public void onDataFieldUpdate() { this.setEnergy(Float.intBitsToFloat(dataSyncArray[0]), Power.GROWTHCHAMBER_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.setSoil(Float.intBitsToFloat(dataSyncArray[2])); timeSinceLastPowerRequest = dataSyncArray[3]; } @@ -188,12 +188,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.setFloat("soil", soil); + tagRoot.put("Tank", tankTag); + tagRoot.putFloat("soil", soil); return tagRoot; } /** @@ -201,10 +201,10 @@ 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.contains("Tank", 10)) { - NBTTagCompound tankTag = tagRoot.getCompound("Tank"); + CompoundNBT tankTag = tagRoot.getCompound("Tank"); getTank().readFromNBT(tankTag); if(tankTag.contains("Empty", 1)){ // empty the tank if NBT says its empty (not default behavior of Tank.readFromNBT(...) ) @@ -217,7 +217,7 @@ public void read(final NBTTagCompound tagRoot) { } @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 isDirt(srcItem) && slot == 0; } @@ -227,7 +227,7 @@ public boolean isItemValidForSlot(final int slot, final ItemStack srcItem) { } @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 false; } @@ -303,7 +303,7 @@ public float subtractEnergy(float amount, ConduitType type){ @Override public PowerRequest getPowerRequest(ConduitType offer) { if(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, (getTank().getCapacity() - getTank().getFluidAmount()), this); @@ -337,7 +337,7 @@ public boolean canAcceptConnection(PowerConnectorContext c){ * @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); @@ -352,7 +352,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(fluid == null) return null; if(getTank().getFluidAmount() > 0 && getTank().getFluid().getFluid().equals(fluid.getFluid())){ return getTank().drain(fluid.amount,forReal); @@ -367,7 +367,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(amount > 0 && getTank().getFluidAmount() > 0 ){ return getTank().drain(amount,forReal); } else { @@ -380,8 +380,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()); } @@ -391,7 +391,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()); } @@ -402,7 +402,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/electricadvantage/machines/GrowthChamberTileEntity.java b/src/main/java/zone/moddev/mc/electricadvantage/machines/GrowthChamberTileEntity.java index 64c30a8..c990f71 100644 --- a/src/main/java/zone/moddev/mc/electricadvantage/machines/GrowthChamberTileEntity.java +++ b/src/main/java/zone/moddev/mc/electricadvantage/machines/GrowthChamberTileEntity.java @@ -5,10 +5,10 @@ import zone.moddev.mc.electricadvantage.util.farming.VirtualCrop; import cyano.poweradvantage.api.ConduitType; import cyano.poweradvantage.api.PowerRequest; -import net.minecraft.entity.item.EntityItem; -import net.minecraft.init.SoundEvents; +import net.minecraft.entity.item.ItemEntity; +import net.minecraft.util.SoundEvents; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.CompoundNBT; import java.util.Arrays; import java.util.List; @@ -21,6 +21,7 @@ public class GrowthChamberTileEntity extends ElectricMachineTileEntity { private final int[] progression = new int[GROWTH_AREA]; private final int[] progressionMax = new int[GROWTH_AREA]; private final VirtualCrop[] crops = new VirtualCrop[GROWTH_AREA]; + private byte[] pendingGrowth; public GrowthChamberTileEntity() { super(zone.moddev.mc.electricadvantage.init.Entities.GROWTH_CHAMBER, "tile.electricadvantage.growth_chamber.name",Power.GROWTHCHAMBER_POWER, ENERGY_PER_TICK*64, GROWTH_AREA, 6, 0); @@ -30,6 +31,7 @@ public GrowthChamberTileEntity() { @Override public void tickUpdate(boolean isServer) { if(isServer){ + restorePendingCrops(); boolean[] recalculate = inventoryChanged(); boolean active = false; boolean flagSync = false; @@ -70,8 +72,8 @@ public void tickUpdate(boolean isServer) { for(ItemStack i : harvest){ ItemStack remainder = this.insertItemToOutputSlots(i); if(remainder != null){ - getWorld().spawnEntity( - new EntityItem( + getWorld().addEntity( + new ItemEntity( getWorld(), 2*(getWorld().rand.nextDouble()-0.5), 2*(getWorld().rand.nextDouble()-0.5), @@ -156,33 +158,48 @@ public float[] getProgress() { @Override - protected void saveTo(NBTTagCompound tagRoot) { - byte[] growthStages = new byte[GROWTH_AREA]; + protected void saveTo(CompoundNBT tagRoot) { + byte[] growthStages = pendingGrowth == null ? new byte[GROWTH_AREA] + : Arrays.copyOf(pendingGrowth, GROWTH_AREA); for(int i = 0; i < growthStages.length; i++){ if(crops[i] != null) growthStages[i] = crops[i].getCurrentGrowth(); } - tagRoot.setByteArray("growth", growthStages); - tagRoot.setIntArray("prog", progression); + tagRoot.putByteArray("growth", growthStages); + tagRoot.putIntArray("prog", progression); } @Override - protected void loadFrom(NBTTagCompound tagRoot) { - if(tagRoot.contains("growth", 99)){ - byte[] growthStages = tagRoot.getByteArray("growth"); - for(int i = 0; i < growthStages.length && i < GROWTH_AREA; i++){ - if(crops[i] == null){ - crops[i] = getVirtualCrop(this.getInputSlot(i)); - } - if(crops[i] != null){ - crops[i].setCurrentGrowth(growthStages[i]); - } - } + protected void loadFrom(CompoundNBT tagRoot) { + Arrays.fill(crops, null); + Arrays.fill(progression, 0); + Arrays.fill(progressionMax, 0); + oldInventory = null; + pendingGrowth = tagRoot.contains("growth", 7) + ? Arrays.copyOf(tagRoot.getByteArray("growth"), GROWTH_AREA) : null; + if(tagRoot.contains("prog", 11)){ + int[] saved = tagRoot.getIntArray("prog"); + System.arraycopy(saved, 0, progression, 0, Math.min(saved.length, progression.length)); } - if(tagRoot.contains("prog", 99)){ - System.arraycopy(tagRoot.getIntArray("prog"), 0, progression, 0, progression.length); + } + + private void restorePendingCrops() { + if (pendingGrowth == null) return; + for (int i = 0; i < GROWTH_AREA; i++) { + crops[i] = getVirtualCrop(getInputSlot(i)); + if (crops[i] != null) { + crops[i].setCurrentGrowth(pendingGrowth[i]); + progressionMax[i] = crops[i].getMaxGrowth() * TICKS_PER_GROWTH; + } else { + progression[i] = 0; + } } + // Seed the comparison cache so the first tick does not discard restored work. + ItemStack[] inventory = getInventory(); + oldInventory = new ItemStack[inventory.length]; + for (int i = 0; i < inventory.length; i++) oldInventory[i] = copyStackOrNull(inventory[i]); + pendingGrowth = null; } diff --git a/src/main/java/zone/moddev/mc/electricadvantage/machines/HydroelectricGeneratorBlock.java b/src/main/java/zone/moddev/mc/electricadvantage/machines/HydroelectricGeneratorBlock.java index a0b9ae3..063a872 100644 --- a/src/main/java/zone/moddev/mc/electricadvantage/machines/HydroelectricGeneratorBlock.java +++ b/src/main/java/zone/moddev/mc/electricadvantage/machines/HydroelectricGeneratorBlock.java @@ -1,8 +1,8 @@ package zone.moddev.mc.electricadvantage.machines; -import net.minecraft.block.state.IBlockState; +import net.minecraft.block.BlockState; import net.minecraft.util.math.BlockPos; -import net.minecraft.world.IWorldReaderBase; +import net.minecraft.world.IWorldReader; public class HydroelectricGeneratorBlock extends ElectricGeneratorBlock { @@ -16,7 +16,7 @@ public ElectricGeneratorTileEntity createNewTileEntity(net.minecraft.world.IBloc } @Override - public boolean isValidPosition(IBlockState state, IWorldReaderBase worldIn, BlockPos pos) + public boolean isValidPosition(BlockState state, IWorldReader worldIn, BlockPos pos) { return super.isValidPosition(state, worldIn, pos) && !worldIn.getBlockState(pos.down()).getMaterial().isSolid(); diff --git a/src/main/java/zone/moddev/mc/electricadvantage/machines/HydroelectricGeneratorTileEntity.java b/src/main/java/zone/moddev/mc/electricadvantage/machines/HydroelectricGeneratorTileEntity.java index 143a22a..d8a8d91 100644 --- a/src/main/java/zone/moddev/mc/electricadvantage/machines/HydroelectricGeneratorTileEntity.java +++ b/src/main/java/zone/moddev/mc/electricadvantage/machines/HydroelectricGeneratorTileEntity.java @@ -2,7 +2,7 @@ import zone.moddev.mc.electricadvantage.entities.HydroturbineEntity; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.CompoundNBT; import net.minecraft.util.math.AxisAlignedBB; import java.util.List; @@ -46,7 +46,7 @@ public void tickUpdate(boolean isServer) { private void initialize() { isInitialized = true; if(getPos().getY() > 0){ - getWorld().spawnEntity(new HydroturbineEntity(getWorld(),this)); + getWorld().addEntity(new HydroturbineEntity(getWorld(),this)); } } @@ -65,12 +65,12 @@ protected boolean isValidInputItem(ItemStack item) { } @Override - protected void saveTo(NBTTagCompound tagRoot) { - tagRoot.setBoolean("initDone", this.isInitialized); + protected void saveTo(CompoundNBT tagRoot) { + tagRoot.putBoolean("initDone", this.isInitialized); } @Override - protected void loadFrom(NBTTagCompound tagRoot) { + protected void loadFrom(CompoundNBT tagRoot) { if(tagRoot.contains("initDone", 1)){ this.isInitialized = tagRoot.getBoolean("initDone"); } diff --git a/src/main/java/zone/moddev/mc/electricadvantage/machines/LEDBlock.java b/src/main/java/zone/moddev/mc/electricadvantage/machines/LEDBlock.java index 1d3afeb..2103662 100644 --- a/src/main/java/zone/moddev/mc/electricadvantage/machines/LEDBlock.java +++ b/src/main/java/zone/moddev/mc/electricadvantage/machines/LEDBlock.java @@ -3,7 +3,7 @@ import cyano.poweradvantage.api.ConduitType; import net.minecraft.block.Block; import net.minecraft.block.ITileEntityProvider; -import net.minecraft.block.state.IBlockState; +import net.minecraft.block.BlockState; import net.minecraft.state.BooleanProperty; import net.minecraft.state.StateContainer; import net.minecraft.tileentity.TileEntity; @@ -28,21 +28,21 @@ public TileEntity createNewTileEntity(IBlockReader world) { } @Override - public int getLightValue(IBlockState state) { + public int getLightValue(BlockState state) { return state.getBlock() == this && state.get(LIT) ? 15 : 0; } @Override - protected void fillStateContainer(StateContainer.Builder builder) { + protected void fillStateContainer(StateContainer.Builder builder) { super.fillStateContainer(builder); builder.add(LIT); } - public IBlockState getStateFromLegacyMeta(int meta) { + public BlockState getStateFromLegacyMeta(int meta) { return getDefaultState().with(LIT, (meta & 1) != 0); } - public int getLegacyMetaFromState(IBlockState state) { + public int getLegacyMetaFromState(BlockState state) { return state.get(LIT) ? 1 : 0; } diff --git a/src/main/java/zone/moddev/mc/electricadvantage/machines/LEDTileEntity.java b/src/main/java/zone/moddev/mc/electricadvantage/machines/LEDTileEntity.java index 84e4a14..ba6dfef 100644 --- a/src/main/java/zone/moddev/mc/electricadvantage/machines/LEDTileEntity.java +++ b/src/main/java/zone/moddev/mc/electricadvantage/machines/LEDTileEntity.java @@ -4,7 +4,7 @@ import cyano.poweradvantage.api.ConduitType; import cyano.poweradvantage.api.PowerRequest; import cyano.poweradvantage.api.simple.TileEntitySimplePowerMachine; -import net.minecraft.block.state.IBlockState; +import net.minecraft.block.BlockState; import net.minecraft.item.ItemStack; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -41,13 +41,6 @@ public void prepareDataFieldsForSync() { } - @Override - public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newState) - { - // used to allow change in blockstate without interrupting the TileEntity or the GUI - return (oldState.getBlock() != newState.getBlock()); - } - @Override public void tickUpdate(boolean arg0) { // do nothing @@ -57,7 +50,7 @@ public void tickUpdate(boolean arg0) { public void powerUpdate(){ super.powerUpdate(); boolean on = getEnergy(Power.ELECTRIC_POWER) > 0; - IBlockState bs = getWorld().getBlockState(getPos()); + BlockState bs = getWorld().getBlockState(getPos()); if(on){ this.subtractEnergy(ENERGY_COST, Power.ELECTRIC_POWER); } diff --git a/src/main/java/zone/moddev/mc/electricadvantage/machines/LaserTurretBlock.java b/src/main/java/zone/moddev/mc/electricadvantage/machines/LaserTurretBlock.java index 3674c62..d7809b8 100644 --- a/src/main/java/zone/moddev/mc/electricadvantage/machines/LaserTurretBlock.java +++ b/src/main/java/zone/moddev/mc/electricadvantage/machines/LaserTurretBlock.java @@ -2,15 +2,16 @@ 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.entity.Entity; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; 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.minecraft.world.World; @@ -37,21 +38,21 @@ public ElectricMachineTileEntity createNewTileEntity(net.minecraft.world.IBlockR @Override - public VoxelShape getShape(IBlockState state, IBlockReader world, BlockPos pos) { + public VoxelShape getShape(BlockState state, IBlockReader world, BlockPos pos, ISelectionContext context) { return SHAPE; } @Override - public VoxelShape getCollisionShape(IBlockState state, IBlockReader world, BlockPos pos) { + public VoxelShape getCollisionShape(BlockState state, IBlockReader world, BlockPos pos, ISelectionContext context) { return SHAPE; } @Override - public void onBlockPlacedBy(World w, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) { + public void onBlockPlacedBy(World w, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) { super.onBlockPlacedBy(w, pos, state, placer, stack); TileEntity te = w.getTileEntity(pos); - if(placer instanceof EntityPlayer && te instanceof LaserTurretTileEntity){ - ((LaserTurretTileEntity)te).setOwner((EntityPlayer)placer); + if(placer instanceof PlayerEntity && te instanceof LaserTurretTileEntity){ + ((LaserTurretTileEntity)te).setOwner((PlayerEntity)placer); } } diff --git a/src/main/java/zone/moddev/mc/electricadvantage/machines/LaserTurretTileEntity.java b/src/main/java/zone/moddev/mc/electricadvantage/machines/LaserTurretTileEntity.java index bf6af06..1fd55d8 100644 --- a/src/main/java/zone/moddev/mc/electricadvantage/machines/LaserTurretTileEntity.java +++ b/src/main/java/zone/moddev/mc/electricadvantage/machines/LaserTurretTileEntity.java @@ -4,17 +4,17 @@ import zone.moddev.mc.electricadvantage.init.Power; import net.minecraft.block.Block; import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.EnumCreatureType; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.Blocks; -import net.minecraft.init.SoundEvents; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.EntityClassification; +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.network.NetworkManager; -import net.minecraft.network.play.server.SPacketUpdateTileEntity; +import net.minecraft.network.play.server.SUpdateTileEntityPacket; import net.minecraft.scoreboard.Team; -import net.minecraft.util.ITickable; +import net.minecraft.tileentity.ITickableTileEntity; import net.minecraft.util.ResourceLocation; import net.minecraft.util.SoundEvent; import net.minecraft.util.math.*; @@ -26,7 +26,7 @@ import java.util.ArrayList; import java.util.List; -public class LaserTurretTileEntity extends ElectricMachineTileEntity implements ITickable{ +public class LaserTurretTileEntity extends ElectricMachineTileEntity implements ITickableTileEntity{ private final SoundEvent LASER_SOUND; @@ -152,13 +152,13 @@ public void tickUpdate(boolean b) { double x = this.getOpticPosition().x; double y = this.getOpticPosition().y; double z = this.getOpticPosition().z; - List entities = w.getEntitiesWithinAABB(EntityLivingBase.class, new AxisAlignedBB(x-TARGET_RANGE, y-TARGET_RANGE, z-TARGET_RANGE, x+TARGET_RANGE, y+TARGET_RANGE, z+TARGET_RANGE)); + List entities = w.getEntitiesWithinAABB(LivingEntity.class, new AxisAlignedBB(x-TARGET_RANGE, y-TARGET_RANGE, z-TARGET_RANGE, x+TARGET_RANGE, y+TARGET_RANGE, z+TARGET_RANGE)); final double maxRangeSquared = TARGET_RANGE * TARGET_RANGE; if(isEvil){ for (Entity e : entities) { if (!( - e.isCreatureType(EnumCreatureType.MONSTER, false) - || e.isCreatureType(EnumCreatureType.AMBIENT, false) + e.getType().getClassification() == EntityClassification.MONSTER + || e.getType().getClassification() == EntityClassification.AMBIENT ) ) { if (canSeeEntity(e)) { @@ -170,13 +170,13 @@ public void tickUpdate(boolean b) { } else { for (Entity e : entities) { if (e.getPositionVector().squareDistanceTo(getOpticPosition()) > maxRangeSquared) continue; - if (e instanceof EntityPlayer) { - if (isEnemy((EntityPlayer) e)) { + if (e instanceof PlayerEntity) { + if (isEnemy((PlayerEntity) e)) { setTarget(e); break; } } - if (e.isCreatureType(EnumCreatureType.MONSTER, false)) { + if (e.getType().getClassification() == EntityClassification.MONSTER) { if (canSeeEntity(e)) { setTarget(e); break; @@ -217,7 +217,7 @@ public void tickUpdate(boolean b) { } } - private boolean isEnemy(EntityPlayer player) { + private boolean isEnemy(PlayerEntity player) { if(player.isCreative()) return false; if(this.teamIdentity == null || this.teamIdentity.isEmpty()){ return false; @@ -240,14 +240,14 @@ private List getLaserAttackVictims(){ final World w = getWorld(); final Entity e = w.getEntityByID(targetID); if(e != null){ - dir = e.getPositionVector().add(0, 0.5*e.height, 0).subtract(origin).normalize(); + dir = e.getPositionVector().add(0, 0.5*e.getHeight(), 0).subtract(origin).normalize(); } else { dir = (new Vec3d(Math.cos(DEGREES_TO_RADIANS * rotYaw),Math.sin(rotPitch),Math.sin(rotYaw))).normalize(); } final Vec3d terminus = followRayToSolidBlock(origin,dir,ATTACK_RANGE); final double maxDistSqr = origin.squareDistanceTo(terminus); final double maxDist = Math.sqrt(maxDistSqr); - List potentialVictims = w.getEntitiesWithinAABB(EntityLivingBase.class, new AxisAlignedBB( + List potentialVictims = w.getEntitiesWithinAABB(LivingEntity.class, new AxisAlignedBB( origin.x - maxDist, origin.y - maxDist, origin.z - maxDist, origin.x + maxDist, origin.y + maxDist, origin.z + maxDist)); List victims = new ArrayList<>(); @@ -264,16 +264,18 @@ && rayIntersectsBoundingBox(origin,dir,v.getBoundingBox())){ private void hurtVictim(Entity e){ e.setFire(BURN_TIME); - if(e instanceof EntityLivingBase){ - ((EntityLivingBase)e).attackEntityFrom(Power.laser_damage, ATTACK_DAMAGE); + if(e instanceof LivingEntity){ + ((LivingEntity)e).attackEntityFrom(Power.laser_damage, ATTACK_DAMAGE); BlockPos bp = e.getPosition(); if(getWorld().isAirBlock(bp) && !getWorld().isAirBlock(bp.down())){ getWorld().setBlockState(bp, Blocks.FIRE.getDefaultState()); } if(playerOwner != null && !playerOwner.isEmpty()){ - EntityPlayer p = getWorld().getPlayerEntityByName(playerOwner); - if(p != null){ - ((EntityLivingBase) e).setRevengeTarget(p); + for (PlayerEntity player : getWorld().getPlayers()) { + if (playerOwner.equals(player.getName().getString())) { + ((LivingEntity) e).setRevengeTarget(player); + break; + } } } } @@ -284,7 +286,7 @@ private Vec3d calculateLaserTerminus(){ World w = getWorld(); Entity e = w.getEntityByID(targetID); if(e != null){ - dir = e.getPositionVector().add(0, 0.5*e.height, 0).subtract(this.getOpticPosition()).normalize(); + dir = e.getPositionVector().add(0, 0.5*e.getHeight(), 0).subtract(this.getOpticPosition()).normalize(); } else { dir = (new Vec3d(Math.cos(DEGREES_TO_RADIANS * rotYaw),Math.sin(rotPitch),Math.sin(rotYaw))).normalize(); } @@ -292,16 +294,10 @@ private Vec3d calculateLaserTerminus(){ } private Vec3d followRayToSolidBlock(Vec3d origin, Vec3d dir, double maxRange){ Vec3d max = origin.add(dir).add(maxRange * dir.x, maxRange * dir.y, maxRange * dir.z); - RayTraceResult impact = getWorld().rayTraceBlocks(origin, max, RayTraceFluidMode.SOURCE_ONLY, true, false); - if(impact != null && impact.type == RayTraceResult.Type.BLOCK){ - final Vec3d impactSite; - if(impact.hitVec != null){ - impactSite = impact.hitVec; - } else { - BlockPos bp = impact.getBlockPos(); - impactSite = new Vec3d(bp.getX(), bp.getY(), bp.getZ()); - } - return impactSite; + BlockRayTraceResult impact = getWorld().rayTraceBlocks(new RayTraceContext(origin, max, + RayTraceContext.BlockMode.COLLIDER, RayTraceContext.FluidMode.SOURCE_ONLY, null)); + if(impact.getType() == RayTraceResult.Type.BLOCK){ + return impact.getHitVec(); } else { return max; } @@ -381,8 +377,10 @@ private void validateTarget() { public boolean canSeeEntity(Entity e){ if(e == null) return false; Vec3d offsetOrigin = getOpticPosition().add(e.getPositionVector().subtract(getOpticPosition()).normalize()); - RayTraceResult collision = getWorld().rayTraceBlocks(offsetOrigin, e.getPositionVector().add(0, e.height*0.5, 0), RayTraceFluidMode.SOURCE_ONLY, true, false); - if(collision != null && collision.type == RayTraceResult.Type.BLOCK){ + BlockRayTraceResult collision = getWorld().rayTraceBlocks(new RayTraceContext(offsetOrigin, + e.getPositionVector().add(0, e.getHeight()*0.5, 0), RayTraceContext.BlockMode.COLLIDER, + RayTraceContext.FluidMode.SOURCE_ONLY, null)); + if(collision.getType() == RayTraceResult.Type.BLOCK){ return false; } return true; @@ -403,7 +401,7 @@ public void setTarget(Entity e){ } private void lookAt(Entity e) { - Vec3d pos = e.getPositionVector().add(0, e.height*0.5, 0); + Vec3d pos = e.getPositionVector().add(0, e.getHeight()*0.5, 0); targetPosition(pos); } @@ -412,7 +410,7 @@ private Vec3d getOpticPosition(){ return opticPosition; } - public void setOwner(EntityPlayer owner){ + public void setOwner(PlayerEntity owner){ this.setTeam(owner.getTeam()); playerOwner = owner.getName().getString(); } @@ -487,38 +485,38 @@ private void storeOld(){ * Turns the data field NBT into a network packet */ @Override - public SPacketUpdateTileEntity getUpdatePacket(){ - NBTTagCompound nbtTag = new NBTTagCompound(); + public SUpdateTileEntityPacket getUpdatePacket(){ + CompoundNBT nbtTag = new CompoundNBT(); writeRenderSync(nbtTag); - return new SPacketUpdateTileEntity(this.getPos(), 0, nbtTag); + return new SUpdateTileEntityPacket(this.getPos(), 0, nbtTag); } @Override - public NBTTagCompound getUpdateTag() { - NBTTagCompound nbtTag = write(new NBTTagCompound()); + public CompoundNBT getUpdateTag() { + CompoundNBT nbtTag = write(new CompoundNBT()); writeRenderSync(nbtTag); return nbtTag; } @Override - public void handleUpdateTag(NBTTagCompound tag) { + public void handleUpdateTag(CompoundNBT tag) { read(tag); readRenderSync(tag); } - private void writeRenderSync(NBTTagCompound nbtTag) { - nbtTag.setFloat("energy", getEnergy()); - nbtTag.setBoolean("lock", targetLocked); + private void writeRenderSync(CompoundNBT nbtTag) { + nbtTag.putFloat("energy", getEnergy()); + nbtTag.putBoolean("lock", targetLocked); if(targetLocked){ if(targetID != Integer.MIN_VALUE && getWorld().getEntityByID(targetID) != null){ Entity e = getWorld().getEntityByID(targetID); - Vec3d pos = e.getPositionVector().add(0, e.height*0.5, 0); - NBTTagCompound target = new NBTTagCompound(); - target.setInt("id", this.targetID); - target.setFloat("yaw", rotTargetYaw); - target.setFloat("pitch", rotTargetPitch); - target.setByte("attack", (byte)laserAttack); - nbtTag.setTag("target", target); + Vec3d pos = e.getPositionVector().add(0, e.getHeight()*0.5, 0); + CompoundNBT target = new CompoundNBT(); + target.putInt("id", this.targetID); + target.putFloat("yaw", rotTargetYaw); + target.putFloat("pitch", rotTargetPitch); + target.putByte("attack", (byte)laserAttack); + nbtTag.put("target", target); } } } @@ -527,15 +525,15 @@ private void writeRenderSync(NBTTagCompound nbtTag) { * Receives the network packet made by getDescriptionPacket() */ @Override - public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity packet) { + public void onDataPacket(NetworkManager net, SUpdateTileEntityPacket packet) { readRenderSync(packet.getNbtCompound()); } - private void readRenderSync(NBTTagCompound tag) { + private void readRenderSync(CompoundNBT tag) { if(tag.contains("lock", 1)){ this.targetLocked = tag.getBoolean("lock"); if(tag.contains("target", 10)){ - NBTTagCompound target = tag.getCompound("target"); + CompoundNBT target = tag.getCompound("target"); this.targetID = target.getInt("id"); Entity e = getWorld().getEntityByID(targetID); if(e != null){ @@ -559,24 +557,24 @@ public float[] getProgress() { } @Override - protected void saveTo(NBTTagCompound root) { - root.setFloat("pitch", rotPitch); - root.setFloat("yaw", rotYaw); - root.setBoolean("lock", targetLocked); + protected void saveTo(CompoundNBT root) { + root.putFloat("pitch", rotPitch); + root.putFloat("yaw", rotYaw); + root.putBoolean("lock", targetLocked); if(this.teamIdentity == null){ - root.setString("team", ""); + root.putString("team", ""); } else { - root.setString("team", teamIdentity); + root.putString("team", teamIdentity); } if(this.playerOwner == null){ - root.setString("player", ""); + root.putString("player", ""); } else { - root.setString("player", playerOwner); + root.putString("player", playerOwner); } } @Override - protected void loadFrom(NBTTagCompound root) { + protected void loadFrom(CompoundNBT root) { if(root.contains("pitch", 99)){ this.rotPitch = root.getFloat("pitch"); this.rotOldPitch = rotPitch; diff --git a/src/main/java/zone/moddev/mc/electricadvantage/machines/PhotovoltaicGeneratorBlock.java b/src/main/java/zone/moddev/mc/electricadvantage/machines/PhotovoltaicGeneratorBlock.java index 0d7bbdb..1f633f4 100644 --- a/src/main/java/zone/moddev/mc/electricadvantage/machines/PhotovoltaicGeneratorBlock.java +++ b/src/main/java/zone/moddev/mc/electricadvantage/machines/PhotovoltaicGeneratorBlock.java @@ -2,7 +2,7 @@ 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.world.World; public class PhotovoltaicGeneratorBlock extends ElectricGeneratorBlock{ @@ -19,13 +19,13 @@ public ElectricGeneratorTileEntity createNewTileEntity(net.minecraft.world.IBloc @Override - public boolean isFullCube(IBlockState bs) + public boolean isNormalCube(BlockState bs, net.minecraft.world.IBlockReader world, net.minecraft.util.math.BlockPos pos) { return true; } @Override - public boolean isOpaqueCube(IBlockState bs) + public boolean isSolid(BlockState bs) { return true; } diff --git a/src/main/java/zone/moddev/mc/electricadvantage/machines/PhotovoltaicGeneratorTileEntity.java b/src/main/java/zone/moddev/mc/electricadvantage/machines/PhotovoltaicGeneratorTileEntity.java index 0f36592..660b8bb 100644 --- a/src/main/java/zone/moddev/mc/electricadvantage/machines/PhotovoltaicGeneratorTileEntity.java +++ b/src/main/java/zone/moddev/mc/electricadvantage/machines/PhotovoltaicGeneratorTileEntity.java @@ -2,7 +2,7 @@ import zone.moddev.mc.electricadvantage.init.Power; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.CompoundNBT; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; import net.minecraft.world.World; @@ -42,12 +42,12 @@ protected boolean isValidInputItem(ItemStack item) { } @Override - protected void saveTo(NBTTagCompound tagRoot) { + protected void saveTo(CompoundNBT tagRoot) { // do nothing } @Override - protected void loadFrom(NBTTagCompound tagRoot) { + protected void loadFrom(CompoundNBT tagRoot) { // do nothing } @@ -93,7 +93,7 @@ public void powerUpdate(){ public static float getLightIntensityAt(BlockPos pos, World w){ float light; - if(w.canSeeSky(pos) && w.dimension.hasSkyLight()){ + if(w.isSkyLightMax(pos) && w.dimension.hasSkyLight()){ // outdoor light imposes no penalty light = MathHelper.sin((float)w.getDayTime() * 2.61799E-4f); // (worldTime * pi / 12000); // handle weather diff --git a/src/main/java/zone/moddev/mc/electricadvantage/machines/PlasticRefineryTileEntity.java b/src/main/java/zone/moddev/mc/electricadvantage/machines/PlasticRefineryTileEntity.java index 0eabe91..3a1f18c 100644 --- a/src/main/java/zone/moddev/mc/electricadvantage/machines/PlasticRefineryTileEntity.java +++ b/src/main/java/zone/moddev/mc/electricadvantage/machines/PlasticRefineryTileEntity.java @@ -10,17 +10,17 @@ import cyano.poweradvantage.api.fluid.FluidRequest; import zone.moddev.mc.poweradvantage.init.Fluids; import zone.moddev.mc.poweradvantage.util.FluidIdHelper; -import net.minecraft.init.SoundEvents; +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.fluid.Fluid; import cyano.poweradvantage.api.fluid.FluidStack; import cyano.poweradvantage.api.fluid.FluidTank; import cyano.poweradvantage.api.fluid.FluidTankInfo; import net.minecraft.tags.ItemTags; import net.minecraft.util.ResourceLocation; -import net.minecraft.util.registry.IRegistry; +import net.minecraft.util.registry.Registry; import java.util.List; @@ -103,20 +103,20 @@ public FluidTank getTank(){ } @Override - protected void saveTo(NBTTagCompound tagRoot) { - tagRoot.setShort("progress", fabTime); - NBTTagCompound tankTag = new NBTTagCompound(); + protected void saveTo(CompoundNBT tagRoot) { + tagRoot.putShort("progress", fabTime); + CompoundNBT tankTag = new CompoundNBT(); this.getTank().writeToNBT(tankTag); - tagRoot.setTag("Tank", tankTag); + tagRoot.put("Tank", tankTag); } @Override - protected void loadFrom(NBTTagCompound tagRoot) { + protected void loadFrom(CompoundNBT tagRoot) { if(tagRoot.contains("progress", 99)){ this.fabTime = tagRoot.getShort("progress"); } if (tagRoot.contains("Tank", 10)) { - NBTTagCompound tankTag = tagRoot.getCompound("Tank"); + CompoundNBT tankTag = tagRoot.getCompound("Tank"); getTank().readFromNBT(tankTag); if(tankTag.contains("Empty", 1)){ // empty the tank if NBT says its empty (not default behavior of Tank.readFromNBT(...) ) @@ -144,7 +144,7 @@ public void prepareDataFieldsForSync() { dataSyncArray[2] = this.getTank().getFluidAmount(); dataSyncArray[3] = (getTank().getFluid() != null && getTank().getFluid().getFluid() != null ? FluidIdHelper.getFluidId(getTank().getFluid().getFluid()) - : FluidIdHelper.getFluidId(net.minecraft.init.Fluids.WATER)); + : FluidIdHelper.getFluidId(net.minecraft.fluid.Fluids.WATER)); } @@ -158,7 +158,7 @@ public void onDataFieldUpdate() { private boolean isPlasticFluid(Fluid fluid) { if(fluid == null) return false; - ResourceLocation id = IRegistry.field_212619_h.getKey(fluid); + ResourceLocation id = net.minecraftforge.registries.ForgeRegistries.FLUIDS.getKey(fluid); return id != null && ElectricAdvantage.INSTANCE.PLASTIC_FLUID_MATERIALS.contains(id.toString()); } @@ -251,7 +251,7 @@ public boolean canAcceptConnection(PowerConnectorContext p){ * @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(isPlasticFluid(fluid.getFluid())){ if(getTank().getFluidAmount() <= 0 || getTank().getFluid().getFluid().equals(fluid.getFluid())){ @@ -267,7 +267,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(fluid == null) return null; if(getTank().getFluidAmount() > 0 && getTank().getFluid().getFluid().equals(fluid.getFluid())){ return getTank().drain(fluid.amount,forReal); @@ -282,7 +282,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(amount > 0 && getTank().getFluidAmount() > 0 ){ return getTank().drain(amount,forReal); } else { @@ -295,7 +295,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(isPlasticFluid(fluid)) { if(getTank().getFluidAmount() <= 0) return true; return getTank().getFluidAmount() <= getTank().getCapacity() && fluid.equals(getTank().getFluid().getFluid()); @@ -308,7 +308,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()); } @@ -319,7 +319,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/electricadvantage/machines/SteamPoweredElectricGeneratorTileEntity.java b/src/main/java/zone/moddev/mc/electricadvantage/machines/SteamPoweredElectricGeneratorTileEntity.java index f0a5bd5..a4133d9 100644 --- a/src/main/java/zone/moddev/mc/electricadvantage/machines/SteamPoweredElectricGeneratorTileEntity.java +++ b/src/main/java/zone/moddev/mc/electricadvantage/machines/SteamPoweredElectricGeneratorTileEntity.java @@ -4,10 +4,10 @@ import cyano.poweradvantage.api.ConduitType; import cyano.poweradvantage.api.PowerConnectorContext; import cyano.poweradvantage.api.PowerRequest; -import net.minecraft.init.SoundEvents; +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 static zone.moddev.mc.electricadvantage.machines.SteamPoweredElectricGeneratorBlock.STEAM_POWER; @@ -156,7 +156,7 @@ public PowerRequest getPowerRequest(ConduitType offer) { * @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(getEnergyType(), type) || ConduitType.areSameType(STEAM_POWER, type); } /** @@ -171,12 +171,12 @@ public boolean canAcceptType(ConduitType type){ ///// end multi-type overrides ///// @Override - protected void saveTo(NBTTagCompound tagRoot) { - tagRoot.setFloat("steam", steam); + protected void saveTo(CompoundNBT tagRoot) { + tagRoot.putFloat("steam", steam); } @Override - protected void loadFrom(NBTTagCompound tagRoot) { + protected void loadFrom(CompoundNBT tagRoot) { steam = tagRoot.getFloat("steam"); } diff --git a/src/main/java/zone/moddev/mc/electricadvantage/migration/ElectricLegacyMigrations.java b/src/main/java/zone/moddev/mc/electricadvantage/migration/ElectricLegacyMigrations.java index c76aa52..13aedea 100644 --- a/src/main/java/zone/moddev/mc/electricadvantage/migration/ElectricLegacyMigrations.java +++ b/src/main/java/zone/moddev/mc/electricadvantage/migration/ElectricLegacyMigrations.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.block.BlockState; import net.minecraft.util.ResourceLocation; -import net.minecraft.util.EnumFacing; +import net.minecraft.util.Direction; import zone.moddev.mc.electricadvantage.ElectricAdvantage; import zone.moddev.mc.electricadvantage.machines.ElectricDrillBlock; import zone.moddev.mc.electricadvantage.machines.ElectricGeneratorBlock; @@ -65,7 +65,7 @@ private static void registerTile(String path) { "minecraft:" + ElectricAdvantage.MODID + "." + path, current); } - private static IBlockState decodeState(Block block, int metadata) { + private static BlockState decodeState(Block block, int metadata) { if (block instanceof ElectricDrillBlock) { return block.getDefaultState() .with(ElectricDrillBlock.FACING, legacyDrillFacing(metadata)) @@ -89,8 +89,8 @@ private static IBlockState decodeState(Block block, int metadata) { return block.getDefaultState(); } - static EnumFacing legacyDrillFacing(int metadata) { - return EnumFacing.byIndex(metadata & 0x7); + static Direction legacyDrillFacing(int metadata) { + return Direction.byIndex(metadata & 0x7); } static boolean legacyDrillActive(int metadata) { diff --git a/src/main/java/zone/moddev/mc/electricadvantage/recipe/RecipeConditions.java b/src/main/java/zone/moddev/mc/electricadvantage/recipe/RecipeConditions.java index d2a2c95..c0ed0ad 100644 --- a/src/main/java/zone/moddev/mc/electricadvantage/recipe/RecipeConditions.java +++ b/src/main/java/zone/moddev/mc/electricadvantage/recipe/RecipeConditions.java @@ -1,8 +1,12 @@ package zone.moddev.mc.electricadvantage.recipe; -import net.minecraft.util.JsonUtils; +import java.util.Locale; +import com.google.gson.JsonObject; +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.electricadvantage.ElectricAdvantage; import zone.moddev.mc.poweradvantage.PowerAdvantage; import zone.moddev.mc.poweradvantage.RecipeMode; @@ -14,14 +18,49 @@ private RecipeConditions() {} public static synchronized void register() { if (registered) return; - CraftingHelper.register(new ResourceLocation(ElectricAdvantage.MODID, "recipe_mode"), json -> { - RecipeMode expected = RecipeMode.valueOf(JsonUtils.getString(json, "mode").toUpperCase()); - return () -> PowerAdvantage.recipeMode == expected; - }); - CraftingHelper.register(new ResourceLocation(ElectricAdvantage.MODID, "not_recipe_mode"), json -> { - RecipeMode excluded = RecipeMode.valueOf(JsonUtils.getString(json, "mode").toUpperCase()); - return () -> PowerAdvantage.recipeMode != excluded; - }); + CraftingHelper.register(new ModeSerializer(false)); + CraftingHelper.register(new ModeSerializer(true)); registered = true; } + + static final class ModeCondition implements ICondition { + private final RecipeMode mode; + private final boolean inverted; + + ModeCondition(RecipeMode mode, boolean inverted) { + this.mode = mode; + this.inverted = inverted; + } + + @Override public ResourceLocation getID() { + return new ResourceLocation(ElectricAdvantage.MODID, + inverted ? "not_recipe_mode" : "recipe_mode"); + } + + @Override public boolean test() { + return (PowerAdvantage.recipeMode == mode) != inverted; + } + } + + static final class ModeSerializer implements IConditionSerializer { + private final boolean inverted; + + ModeSerializer(boolean inverted) { + this.inverted = inverted; + } + + @Override public void write(JsonObject json, ModeCondition condition) { + json.addProperty("mode", condition.mode.name().toLowerCase(Locale.ROOT)); + } + + @Override public ModeCondition read(JsonObject json) { + return new ModeCondition(RecipeMode.valueOf( + JSONUtils.getString(json, "mode").toUpperCase(Locale.ROOT)), inverted); + } + + @Override public ResourceLocation getID() { + return new ResourceLocation(ElectricAdvantage.MODID, + inverted ? "not_recipe_mode" : "recipe_mode"); + } + } } diff --git a/src/main/java/zone/moddev/mc/electricadvantage/util/crafting/RecipeDeconstructor.java b/src/main/java/zone/moddev/mc/electricadvantage/util/crafting/RecipeDeconstructor.java index 48d1b49..ef3dcb7 100644 --- a/src/main/java/zone/moddev/mc/electricadvantage/util/crafting/RecipeDeconstructor.java +++ b/src/main/java/zone/moddev/mc/electricadvantage/util/crafting/RecipeDeconstructor.java @@ -19,7 +19,7 @@ public final class RecipeDeconstructor { private static final RecipeDeconstructor INSTANCE = new RecipeDeconstructor(); public static int RECURSION_LIMIT = 5; - private final Map> recipeCache = new HashMap<>(); + private final Map>> recipeCache = new HashMap<>(); private int cachedRecipeCount = -1; private RecipeDeconstructor() {} @@ -34,10 +34,10 @@ public void invalidateRecipeCache() { } private void initializeRecipeCache(World world) { - Collection recipes = world.getRecipeManager().getRecipes(); + Collection> recipes = world.getRecipeManager().getRecipes(); if (cachedRecipeCount == recipes.size() && !recipeCache.isEmpty()) return; recipeCache.clear(); - for (IRecipe recipe : recipes) { + for (IRecipe recipe : recipes) { ItemStack output = recipe.getRecipeOutput(); if (output == null || output.isEmpty()) continue; recipeCache.computeIfAbsent(new ItemRecord(output), ignored -> new ArrayList<>()).add(recipe); @@ -54,10 +54,10 @@ public SerializedInventory attemptToCraft(World world, ItemStack target, private SerializedInventory attemptToCraft(World world, ItemStack target, SerializedInventory inventory, AtomicReference output, int depth) { if (depth > RECURSION_LIMIT || target == null || target.isEmpty()) return null; - List recipes = recipeCache.get(new ItemRecord(target)); + List> recipes = recipeCache.get(new ItemRecord(target)); if (recipes == null || recipes.isEmpty()) return null; - for (IRecipe recipe : recipes) { + for (IRecipe recipe : recipes) { SerializedInventory candidate = inventory.copy(); boolean failed = false; for (Ingredient ingredient : recipe.getIngredients()) { diff --git a/src/main/java/zone/moddev/mc/electricadvantage/util/farming/VirtualCrop.java b/src/main/java/zone/moddev/mc/electricadvantage/util/farming/VirtualCrop.java index f52a651..31f1301 100644 --- a/src/main/java/zone/moddev/mc/electricadvantage/util/farming/VirtualCrop.java +++ b/src/main/java/zone/moddev/mc/electricadvantage/util/farming/VirtualCrop.java @@ -2,13 +2,13 @@ import zone.moddev.mc.electricadvantage.util.crafting.ItemRecord; import net.minecraft.block.Block; -import net.minecraft.block.BlockStem; +import net.minecraft.block.StemBlock; import net.minecraft.state.IProperty; import net.minecraft.state.IntegerProperty; -import net.minecraft.block.state.IBlockState; -import net.minecraft.init.Items; +import net.minecraft.block.BlockState; +import net.minecraft.item.Items; import net.minecraft.item.Item; -import net.minecraft.item.ItemBlock; +import net.minecraft.item.BlockItem; import net.minecraft.item.ItemStack; import net.minecraft.util.NonNullList; import net.minecraft.util.math.BlockPos; @@ -39,37 +39,38 @@ public static VirtualCrop createVirtualCrop(ItemStack stack, World w, BlockPos p seed.setCount(1); Item i = stack.getItem(); Block b; - if(i instanceof ItemBlock){ - b = ((ItemBlock)i).getBlock(); + if(i instanceof BlockItem){ + b = ((BlockItem)i).getBlock(); } else { b = null; } if(customRecipes.get(r) != null){ return customRecipes.get(r).copy(); - } else if(i == Item.getItemFromBlock(net.minecraft.init.Blocks.SUGAR_CANE) - || b instanceof net.minecraft.block.BlockMushroom - || b instanceof net.minecraft.block.BlockCactus - || b instanceof net.minecraft.block.BlockBush - || b instanceof net.minecraft.block.BlockGrass - || b instanceof net.minecraft.block.BlockVine - || b instanceof net.minecraft.block.BlockLilyPad){ + } else if(i == net.minecraft.block.Blocks.SUGAR_CANE.asItem() + || b instanceof net.minecraft.block.MushroomBlock + || b instanceof net.minecraft.block.CactusBlock + || (b instanceof net.minecraft.block.BushBlock + && !(b instanceof net.minecraft.block.CropsBlock) && !(b instanceof StemBlock)) + || b instanceof net.minecraft.block.GrassBlock + || b instanceof net.minecraft.block.VineBlock + || b instanceof net.minecraft.block.LilyPadBlock){ // duplicate ItemStack product = seed.copy(); product.setCount(2); return new VirtualCrop(seed,8,Arrays.asList(product)); - } else if(i instanceof IPlantable){ - IPlantable plantable = (IPlantable)i; - IBlockState startingState = plantable.getPlant(w, pos); + } else if(i instanceof IPlantable || b instanceof IPlantable){ + IPlantable plantable = i instanceof IPlantable ? (IPlantable)i : (IPlantable)b; + BlockState startingState = plantable.getPlant(w, pos); Block block = startingState.getBlock(); int numStages = getNumberOfGrowthStages(startingState); - if(block instanceof BlockStem){ - Block product = getBlockFieldByReflection(block); + if(block instanceof StemBlock){ + Block product = ((StemBlock)block).getCrop(); if(product == null) { return null; } return new VirtualCrop(seed,numStages,Arrays.asList(new ItemStack(product))); } else { - IBlockState agedState = ageToMax(startingState); + BlockState agedState = ageToMax(startingState); return new VirtualCrop(getDrops(startingState, w, pos), getNumberOfGrowthStages(startingState), getDrops(agedState, w, pos)); @@ -84,7 +85,7 @@ public VirtualCrop copy(){ } - private static int getNumberOfGrowthStages(IBlockState startingState) { + private static int getNumberOfGrowthStages(BlockState startingState) { for(IProperty property : startingState.getProperties()){ if(property instanceof IntegerProperty){ IntegerProperty prop = (IntegerProperty)property; @@ -97,7 +98,7 @@ private static int getNumberOfGrowthStages(IBlockState startingState) { } - private static IBlockState ageToMax(IBlockState startingState) { + private static BlockState ageToMax(BlockState startingState) { for(IProperty property : startingState.getProperties()){ if(property instanceof IntegerProperty){ IntegerProperty prop = (IntegerProperty)property; @@ -113,32 +114,11 @@ private static IBlockState ageToMax(IBlockState startingState) { return startingState; } - private static List getDrops(IBlockState state, World world, BlockPos pos) { - NonNullList drops = NonNullList.create(); - state.getBlock().getDrops(state, drops, world, pos, 0); - return drops; + private static List getDrops(BlockState state, World world, BlockPos pos) { + if (!(world instanceof net.minecraft.world.server.ServerWorld)) return Collections.emptyList(); + return Block.getDrops(state, (net.minecraft.world.server.ServerWorld) world, pos, null); } - private static Block getBlockFieldByReflection(Object target) { - Class type = Block.class; - Field[] fields = target.getClass().getDeclaredFields(); - try { - for (Field f : fields){ - if(type.isAssignableFrom(f.getType())){ - // found a block member variable, I hope it is the right one! - f.setAccessible(true); - Object got; - got = f.get(target); - return (Block)got; - } - } - } catch (IllegalArgumentException | IllegalAccessException e) { - return null; - } - // no block member variables found - return null; - } - private final byte numberOfStages; private byte stage = 0; private final List harvest; diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index 004f72b..3ffdfdc 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -30,13 +30,13 @@ side="BOTH" [[dependencies.electricadvantage]] 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.electricadvantage]] 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/electricadvantage/loot_tables/blocks/electric_battery_array.json b/src/main/resources/data/electricadvantage/loot_tables/blocks/electric_battery_array.json new file mode 100644 index 0000000..612335d --- /dev/null +++ b/src/main/resources/data/electricadvantage/loot_tables/blocks/electric_battery_array.json @@ -0,0 +1,19 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "rolls": 1, + "entries": [ + { + "type": "minecraft:item", + "name": "electricadvantage:electric_battery_array" + } + ], + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ] + } + ] +} diff --git a/src/main/resources/data/electricadvantage/loot_tables/blocks/electric_conduit.json b/src/main/resources/data/electricadvantage/loot_tables/blocks/electric_conduit.json new file mode 100644 index 0000000..b6a5470 --- /dev/null +++ b/src/main/resources/data/electricadvantage/loot_tables/blocks/electric_conduit.json @@ -0,0 +1,19 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "rolls": 1, + "entries": [ + { + "type": "minecraft:item", + "name": "electricadvantage:electric_conduit" + } + ], + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ] + } + ] +} diff --git a/src/main/resources/data/electricadvantage/loot_tables/blocks/electric_crusher.json b/src/main/resources/data/electricadvantage/loot_tables/blocks/electric_crusher.json new file mode 100644 index 0000000..2f6ba03 --- /dev/null +++ b/src/main/resources/data/electricadvantage/loot_tables/blocks/electric_crusher.json @@ -0,0 +1,19 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "rolls": 1, + "entries": [ + { + "type": "minecraft:item", + "name": "electricadvantage:electric_crusher" + } + ], + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ] + } + ] +} diff --git a/src/main/resources/data/electricadvantage/loot_tables/blocks/electric_drill.json b/src/main/resources/data/electricadvantage/loot_tables/blocks/electric_drill.json new file mode 100644 index 0000000..5082c42 --- /dev/null +++ b/src/main/resources/data/electricadvantage/loot_tables/blocks/electric_drill.json @@ -0,0 +1,19 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "rolls": 1, + "entries": [ + { + "type": "minecraft:item", + "name": "electricadvantage:electric_drill" + } + ], + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ] + } + ] +} diff --git a/src/main/resources/data/electricadvantage/loot_tables/blocks/electric_fabricator.json b/src/main/resources/data/electricadvantage/loot_tables/blocks/electric_fabricator.json new file mode 100644 index 0000000..9710bd3 --- /dev/null +++ b/src/main/resources/data/electricadvantage/loot_tables/blocks/electric_fabricator.json @@ -0,0 +1,19 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "rolls": 1, + "entries": [ + { + "type": "minecraft:item", + "name": "electricadvantage:electric_fabricator" + } + ], + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ] + } + ] +} diff --git a/src/main/resources/data/electricadvantage/loot_tables/blocks/electric_furnace.json b/src/main/resources/data/electricadvantage/loot_tables/blocks/electric_furnace.json new file mode 100644 index 0000000..93133a1 --- /dev/null +++ b/src/main/resources/data/electricadvantage/loot_tables/blocks/electric_furnace.json @@ -0,0 +1,19 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "rolls": 1, + "entries": [ + { + "type": "minecraft:item", + "name": "electricadvantage:electric_furnace" + } + ], + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ] + } + ] +} diff --git a/src/main/resources/data/electricadvantage/loot_tables/blocks/electric_oven.json b/src/main/resources/data/electricadvantage/loot_tables/blocks/electric_oven.json new file mode 100644 index 0000000..3dbf628 --- /dev/null +++ b/src/main/resources/data/electricadvantage/loot_tables/blocks/electric_oven.json @@ -0,0 +1,19 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "rolls": 1, + "entries": [ + { + "type": "minecraft:item", + "name": "electricadvantage:electric_oven" + } + ], + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ] + } + ] +} diff --git a/src/main/resources/data/electricadvantage/loot_tables/blocks/electric_pump.json b/src/main/resources/data/electricadvantage/loot_tables/blocks/electric_pump.json new file mode 100644 index 0000000..3035bfa --- /dev/null +++ b/src/main/resources/data/electricadvantage/loot_tables/blocks/electric_pump.json @@ -0,0 +1,19 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "rolls": 1, + "entries": [ + { + "type": "minecraft:item", + "name": "electricadvantage:electric_pump" + } + ], + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ] + } + ] +} diff --git a/src/main/resources/data/electricadvantage/loot_tables/blocks/electric_still.json b/src/main/resources/data/electricadvantage/loot_tables/blocks/electric_still.json new file mode 100644 index 0000000..3bf810f --- /dev/null +++ b/src/main/resources/data/electricadvantage/loot_tables/blocks/electric_still.json @@ -0,0 +1,19 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "rolls": 1, + "entries": [ + { + "type": "minecraft:item", + "name": "electricadvantage:electric_still" + } + ], + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ] + } + ] +} diff --git a/src/main/resources/data/electricadvantage/loot_tables/blocks/electric_switch.json b/src/main/resources/data/electricadvantage/loot_tables/blocks/electric_switch.json new file mode 100644 index 0000000..efe2f05 --- /dev/null +++ b/src/main/resources/data/electricadvantage/loot_tables/blocks/electric_switch.json @@ -0,0 +1,19 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "rolls": 1, + "entries": [ + { + "type": "minecraft:item", + "name": "electricadvantage:electric_switch" + } + ], + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ] + } + ] +} diff --git a/src/main/resources/data/electricadvantage/loot_tables/blocks/electric_track.json b/src/main/resources/data/electricadvantage/loot_tables/blocks/electric_track.json new file mode 100644 index 0000000..328b54e --- /dev/null +++ b/src/main/resources/data/electricadvantage/loot_tables/blocks/electric_track.json @@ -0,0 +1,19 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "rolls": 1, + "entries": [ + { + "type": "minecraft:item", + "name": "electricadvantage:electric_track" + } + ], + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ] + } + ] +} diff --git a/src/main/resources/data/electricadvantage/loot_tables/blocks/growth_chamber.json b/src/main/resources/data/electricadvantage/loot_tables/blocks/growth_chamber.json new file mode 100644 index 0000000..b9e4203 --- /dev/null +++ b/src/main/resources/data/electricadvantage/loot_tables/blocks/growth_chamber.json @@ -0,0 +1,19 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "rolls": 1, + "entries": [ + { + "type": "minecraft:item", + "name": "electricadvantage:growth_chamber" + } + ], + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ] + } + ] +} diff --git a/src/main/resources/data/electricadvantage/loot_tables/blocks/growth_chamber_controller.json b/src/main/resources/data/electricadvantage/loot_tables/blocks/growth_chamber_controller.json new file mode 100644 index 0000000..72c25f2 --- /dev/null +++ b/src/main/resources/data/electricadvantage/loot_tables/blocks/growth_chamber_controller.json @@ -0,0 +1,19 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "rolls": 1, + "entries": [ + { + "type": "minecraft:item", + "name": "electricadvantage:growth_chamber_controller" + } + ], + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ] + } + ] +} diff --git a/src/main/resources/data/electricadvantage/loot_tables/blocks/hydroelectric_generator.json b/src/main/resources/data/electricadvantage/loot_tables/blocks/hydroelectric_generator.json new file mode 100644 index 0000000..76ef045 --- /dev/null +++ b/src/main/resources/data/electricadvantage/loot_tables/blocks/hydroelectric_generator.json @@ -0,0 +1,19 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "rolls": 1, + "entries": [ + { + "type": "minecraft:item", + "name": "electricadvantage:hydroelectric_generator" + } + ], + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ] + } + ] +} diff --git a/src/main/resources/data/electricadvantage/loot_tables/blocks/laser_turret.json b/src/main/resources/data/electricadvantage/loot_tables/blocks/laser_turret.json new file mode 100644 index 0000000..9c40877 --- /dev/null +++ b/src/main/resources/data/electricadvantage/loot_tables/blocks/laser_turret.json @@ -0,0 +1,19 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "rolls": 1, + "entries": [ + { + "type": "minecraft:item", + "name": "electricadvantage:laser_turret" + } + ], + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ] + } + ] +} diff --git a/src/main/resources/data/electricadvantage/loot_tables/blocks/laser_turret_evil.json b/src/main/resources/data/electricadvantage/loot_tables/blocks/laser_turret_evil.json new file mode 100644 index 0000000..9d103f7 --- /dev/null +++ b/src/main/resources/data/electricadvantage/loot_tables/blocks/laser_turret_evil.json @@ -0,0 +1,19 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "rolls": 1, + "entries": [ + { + "type": "minecraft:item", + "name": "electricadvantage:laser_turret_evil" + } + ], + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ] + } + ] +} diff --git a/src/main/resources/data/electricadvantage/loot_tables/blocks/led_bar.json b/src/main/resources/data/electricadvantage/loot_tables/blocks/led_bar.json new file mode 100644 index 0000000..8ebeedd --- /dev/null +++ b/src/main/resources/data/electricadvantage/loot_tables/blocks/led_bar.json @@ -0,0 +1,19 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "rolls": 1, + "entries": [ + { + "type": "minecraft:item", + "name": "electricadvantage:led_bar" + } + ], + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ] + } + ] +} diff --git a/src/main/resources/data/electricadvantage/loot_tables/blocks/photovoltaic_generator.json b/src/main/resources/data/electricadvantage/loot_tables/blocks/photovoltaic_generator.json new file mode 100644 index 0000000..25732f9 --- /dev/null +++ b/src/main/resources/data/electricadvantage/loot_tables/blocks/photovoltaic_generator.json @@ -0,0 +1,19 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "rolls": 1, + "entries": [ + { + "type": "minecraft:item", + "name": "electricadvantage:photovoltaic_generator" + } + ], + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ] + } + ] +} diff --git a/src/main/resources/data/electricadvantage/loot_tables/blocks/plastic_refinery.json b/src/main/resources/data/electricadvantage/loot_tables/blocks/plastic_refinery.json new file mode 100644 index 0000000..ed71f92 --- /dev/null +++ b/src/main/resources/data/electricadvantage/loot_tables/blocks/plastic_refinery.json @@ -0,0 +1,19 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "rolls": 1, + "entries": [ + { + "type": "minecraft:item", + "name": "electricadvantage:plastic_refinery" + } + ], + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ] + } + ] +} diff --git a/src/main/resources/data/electricadvantage/loot_tables/blocks/steam_powered_generator.json b/src/main/resources/data/electricadvantage/loot_tables/blocks/steam_powered_generator.json new file mode 100644 index 0000000..4df7e1f --- /dev/null +++ b/src/main/resources/data/electricadvantage/loot_tables/blocks/steam_powered_generator.json @@ -0,0 +1,19 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "rolls": 1, + "entries": [ + { + "type": "minecraft:item", + "name": "electricadvantage:steam_powered_generator" + } + ], + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ] + } + ] +} diff --git a/src/main/resources/pack.mcmeta b/src/main/resources/pack.mcmeta index afe7419..146a2e4 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":"Electric Advantage" } } diff --git a/src/test/java/zone/moddev/mc/electricadvantage/entities/HydroturbinePersistenceTest.java b/src/test/java/zone/moddev/mc/electricadvantage/entities/HydroturbinePersistenceTest.java index b2a3d91..7d07da3 100644 --- a/src/test/java/zone/moddev/mc/electricadvantage/entities/HydroturbinePersistenceTest.java +++ b/src/test/java/zone/moddev/mc/electricadvantage/entities/HydroturbinePersistenceTest.java @@ -1,7 +1,9 @@ package zone.moddev.mc.electricadvantage.entities; import java.lang.reflect.Field; -import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.util.math.BlockPos; +import zone.moddev.mc.electricadvantage.machines.HydroelectricGeneratorTileEntity; import org.junit.Test; import sun.misc.Unsafe; @@ -9,12 +11,12 @@ public class HydroturbinePersistenceTest { @Test public void preservesPendingGeneratorAcrossRepeatedReadSaveWithoutTick() throws Exception { - NBTTagCompound source = new NBTTagCompound(); - source.setIntArray("parentPos", new int[] {164, 81, 8}); + CompoundNBT source = new CompoundNBT(); + source.putIntArray("parentPos", new int[] {164, 81, 8}); for (int pass = 0; pass < 3; pass++) { HydroturbineEntity turbine = withoutWorld(); turbine.readAdditional(source); - NBTTagCompound saved = new NBTTagCompound(); + CompoundNBT saved = new CompoundNBT(); turbine.writeAdditional(saved); assertArrayEquals(new int[] {164, 81, 8}, saved.getIntArray("parentPos")); source = saved; @@ -23,11 +25,31 @@ public class HydroturbinePersistenceTest { @Test public void readingUnlinkedEntityClearsPendingLink() throws Exception { HydroturbineEntity turbine = withoutWorld(); - NBTTagCompound source = new NBTTagCompound(); - source.setIntArray("parentPos", new int[] {164, 81, 8}); + CompoundNBT source = new CompoundNBT(); + source.putIntArray("parentPos", new int[] {164, 81, 8}); turbine.readAdditional(source); - turbine.readAdditional(new NBTTagCompound()); - NBTTagCompound saved = new NBTTagCompound(); + turbine.readAdditional(new CompoundNBT()); + CompoundNBT saved = new CompoundNBT(); + turbine.writeAdditional(saved); + assertFalse(saved.contains("parentPos", 11)); + } + + @Test public void savesAttachedGeneratorUsingTheSameLegacyCoordinateKey() throws Exception { + HydroturbineEntity turbine = withoutWorld(); + HydroelectricGeneratorTileEntity generator = new HydroelectricGeneratorTileEntity(); + generator.setPos(new BlockPos(31, 72, -18)); + turbine.parent = generator; + CompoundNBT saved = new CompoundNBT(); + turbine.writeAdditional(saved); + assertArrayEquals(new int[] {31, 72, -18}, saved.getIntArray("parentPos")); + } + + @Test public void malformedLegacyCoordinatesDoNotCreateAPartialParentLink() throws Exception { + HydroturbineEntity turbine = withoutWorld(); + CompoundNBT source = new CompoundNBT(); + source.putIntArray("parentPos", new int[] {31, 72}); + turbine.readAdditional(source); + CompoundNBT saved = new CompoundNBT(); turbine.writeAdditional(saved); assertFalse(saved.contains("parentPos", 11)); } diff --git a/src/test/java/zone/moddev/mc/electricadvantage/init/VillagesTest.java b/src/test/java/zone/moddev/mc/electricadvantage/init/VillagesTest.java new file mode 100644 index 0000000..396e834 --- /dev/null +++ b/src/test/java/zone/moddev/mc/electricadvantage/init/VillagesTest.java @@ -0,0 +1,44 @@ +package zone.moddev.mc.electricadvantage.init; + +import java.util.Random; +import net.minecraft.item.MerchantOffer; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.util.registry.Bootstrap; +import org.junit.BeforeClass; +import org.junit.Test; +import static org.junit.Assert.*; + +public class VillagesTest { + @BeforeClass public static void bootstrapVanillaItems() { + Bootstrap.register(); + } + + @Test public void nativeNegativePricesKeepBulkGoodsForOneEmerald() { + assertOffer(-8, -4, false, 1, 8); + assertOffer(-8, -4, true, 1, 4); + assertOffer(-6, -3, false, 1, 6); + assertOffer(-6, -3, true, 1, 3); + assertOffer(-10, -5, false, 1, 10); + assertOffer(-10, -5, true, 1, 5); + } + + @Test public void nativePositivePricesKeepOneGoodForOneToThreeEmeralds() { + assertOffer(1, 3, false, 1, 1); + assertOffer(1, 3, true, 3, 1); + } + + private static void assertOffer(int minimum, int maximum, boolean upper, int emeralds, int goods) { + Random random = new Random(0L) { + @Override public int nextInt(int bound) { return upper ? bound - 1 : 0; } + }; + MerchantOffer offer = Villages.sell(net.minecraft.item.Items.APPLE, minimum, maximum) + .getOffer(null, random); + CompoundNBT nbt = offer.func_222208_r(); + assertEquals("minecraft:emerald", nbt.getCompound("buy").getString("id")); + assertEquals(emeralds, nbt.getCompound("buy").getByte("Count")); + assertEquals("minecraft:apple", nbt.getCompound("sell").getString("id")); + assertEquals(goods, nbt.getCompound("sell").getByte("Count")); + assertEquals(7, nbt.getInt("maxUses")); + assertEquals(0.0F, nbt.getFloat("priceMultiplier"), 0.0F); + } +} diff --git a/src/test/java/zone/moddev/mc/electricadvantage/machines/ElectricDrillPersistenceTest.java b/src/test/java/zone/moddev/mc/electricadvantage/machines/ElectricDrillPersistenceTest.java index 4e1cb7e..c09b57f 100644 --- a/src/test/java/zone/moddev/mc/electricadvantage/machines/ElectricDrillPersistenceTest.java +++ b/src/test/java/zone/moddev/mc/electricadvantage/machines/ElectricDrillPersistenceTest.java @@ -1,6 +1,13 @@ package zone.moddev.mc.electricadvantage.machines; -import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.nbt.ListNBT; +import net.minecraft.util.Direction; +import net.minecraft.util.math.BlockPos; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.HashSet; +import java.util.Set; import org.junit.Test; import static org.junit.Assert.assertEquals; @@ -16,17 +23,68 @@ public class ElectricDrillPersistenceTest { @Test public void clearsPreviousProgressOnReadingAnUntargetedTile() { ElectricDrillTileEntity drill = new ElectricDrillTileEntity(); 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 preservesPendingTargetSnapshotAcrossRepeatedReadSave() { + CompoundNBT source = target(94); + CompoundNBT state = new CompoundNBT(); + state.putString("Name", "minecraft:stone"); + ListNBT states = new ListNBT(); + for (int i = 0; i < 9; i++) states.add(state.copy()); + source.put("TargetStates", states); + for (int pass = 0; pass < 3; pass++) { + ElectricDrillTileEntity drill = new ElectricDrillTileEntity(); + drill.loadFrom(source); + CompoundNBT saved = new CompoundNBT(); + drill.saveTo(saved); + assertEquals(source, saved); + source = saved; + } + } + + @Test public void targetPlaneRemainsNineUniqueBlocksForEveryDrillDirection() throws Exception { + ElectricDrillTileEntity drill = new ElectricDrillTileEntity(); + Field facing = ElectricDrillTileEntity.class.getDeclaredField("facingCache"); + facing.setAccessible(true); + Method area = ElectricDrillTileEntity.class.getDeclaredMethod("getArea", BlockPos.class); + area.setAccessible(true); + BlockPos center = new BlockPos(17, 80, 21); + for (Direction direction : Direction.values()) { + facing.set(drill, direction); + BlockPos[] targets = (BlockPos[]) area.invoke(drill, center); + Set unique = new HashSet<>(); + assertEquals(center, targets[0]); + for (BlockPos target : targets) { + unique.add(target); + assertEquals(0, (target.getX() - center.getX()) * direction.getXOffset() + + (target.getY() - center.getY()) * direction.getYOffset() + + (target.getZ() - center.getZ()) * direction.getZOffset()); + } + assertEquals(direction.toString(), 9, unique.size()); + } + } + + @Test public void nativeDataFieldsRetainEnergyAndMiningProgress() { + ElectricDrillTileEntity drill = new ElectricDrillTileEntity(); + drill.read(target(94)); + drill.setEnergy(416.0F, drill.getEnergyType()); + drill.prepareDataFieldsForSync(); + assertEquals(416.0F, Float.intBitsToFloat(drill.getDataFieldArray()[0]), 0.0F); + assertEquals(94, drill.getDataFieldArray()[1]); + assertEquals(250.0F, ElectricDrillTileEntity.ENERGY_COST_MOVE, 0.0F); + assertEquals(24.0F, ElectricDrillTileEntity.ENERGY_COST_PROGRESS_TICK, 0.0F); + assertEquals(6, drill.numberOfOutputSlots()); + } + + 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/electricadvantage/machines/GrowthChamberPersistenceTest.java b/src/test/java/zone/moddev/mc/electricadvantage/machines/GrowthChamberPersistenceTest.java new file mode 100644 index 0000000..759f079 --- /dev/null +++ b/src/test/java/zone/moddev/mc/electricadvantage/machines/GrowthChamberPersistenceTest.java @@ -0,0 +1,38 @@ +package zone.moddev.mc.electricadvantage.machines; + +import net.minecraft.nbt.CompoundNBT; +import org.junit.Test; +import static org.junit.Assert.*; + +public class GrowthChamberPersistenceTest { + @Test public void legacyGrowthAndProgressSurviveReadSaveBeforeWorldAttachment() { + CompoundNBT source = new CompoundNBT(); + source.putByteArray("growth", new byte[] {2, 4, 6}); + source.putIntArray("prog", new int[] {245, 468, 627}); + for (int pass = 0; pass < 3; pass++) { + GrowthChamberTileEntity chamber = new GrowthChamberTileEntity(); + chamber.loadFrom(source); + CompoundNBT saved = new CompoundNBT(); + chamber.saveTo(saved); + assertArrayEquals(new byte[] {2, 4, 6}, saved.getByteArray("growth")); + assertArrayEquals(new int[] {245, 468, 627}, saved.getIntArray("prog")); + source = saved; + } + } + + @Test public void shortArraysArePaddedAndNewNbtClearsOldPendingWork() { + GrowthChamberTileEntity chamber = new GrowthChamberTileEntity(); + CompoundNBT source = new CompoundNBT(); + source.putByteArray("growth", new byte[] {2}); + source.putIntArray("prog", new int[] {245}); + chamber.loadFrom(source); + CompoundNBT saved = new CompoundNBT(); + chamber.saveTo(saved); + assertArrayEquals(new byte[] {2, 0, 0}, saved.getByteArray("growth")); + assertArrayEquals(new int[] {245, 0, 0}, saved.getIntArray("prog")); + chamber.loadFrom(new CompoundNBT()); + chamber.saveTo(saved); + assertArrayEquals(new byte[] {0, 0, 0}, saved.getByteArray("growth")); + assertArrayEquals(new int[] {0, 0, 0}, saved.getIntArray("prog")); + } +} diff --git a/src/test/java/zone/moddev/mc/electricadvantage/machines/LaserTurretGeometryTest.java b/src/test/java/zone/moddev/mc/electricadvantage/machines/LaserTurretGeometryTest.java new file mode 100644 index 0000000..13a48e3 --- /dev/null +++ b/src/test/java/zone/moddev/mc/electricadvantage/machines/LaserTurretGeometryTest.java @@ -0,0 +1,29 @@ +package zone.moddev.mc.electricadvantage.machines; + +import net.minecraft.util.Direction; +import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.util.math.Vec3d; +import org.junit.Test; +import static org.junit.Assert.*; + +public class LaserTurretGeometryTest { + @Test public void nativeRayGeometryKeepsHitsInAllSixDirections() { + Vec3d origin = new Vec3d(0.5D, 0.5D, 0.5D); + for (Direction facing : Direction.values()) { + Vec3d direction = new Vec3d(facing.getXOffset(), facing.getYOffset(), facing.getZOffset()); + Vec3d center = origin.add(direction.scale(5.0D)); + AxisAlignedBB target = new AxisAlignedBB(center.x - 0.25D, center.y - 0.25D, center.z - 0.25D, + center.x + 0.25D, center.y + 0.25D, center.z + 0.25D); + assertTrue(facing.toString(), LaserTurretTileEntity.rayIntersectsBoundingBox(origin, direction, target)); + assertFalse(facing.toString(), LaserTurretTileEntity.rayIntersectsBoundingBox(origin, direction.scale(-1.0D), target)); + } + } + + @Test public void anOffsetTargetIsNotHitAndMissingBoundsAreIgnored() { + Vec3d origin = new Vec3d(0.5D, 0.5D, 0.5D); + Vec3d direction = new Vec3d(1.0D, 0.0D, 0.0D); + assertFalse(LaserTurretTileEntity.rayIntersectsBoundingBox(origin, direction, + new AxisAlignedBB(5.0D, 4.0D, 4.0D, 6.0D, 5.0D, 5.0D))); + assertFalse(LaserTurretTileEntity.rayIntersectsBoundingBox(origin, direction, null)); + } +} diff --git a/src/test/java/zone/moddev/mc/electricadvantage/migration/ElectricLegacyMigrationsTest.java b/src/test/java/zone/moddev/mc/electricadvantage/migration/ElectricLegacyMigrationsTest.java index 56cade8..0d34ccf 100644 --- a/src/test/java/zone/moddev/mc/electricadvantage/migration/ElectricLegacyMigrationsTest.java +++ b/src/test/java/zone/moddev/mc/electricadvantage/migration/ElectricLegacyMigrationsTest.java @@ -3,12 +3,12 @@ import static org.junit.Assert.assertEquals; import cyano.poweradvantage.api.migration.LegacyMigrationApi; -import net.minecraft.util.EnumFacing; +import net.minecraft.util.Direction; import org.junit.Test; public class ElectricLegacyMigrationsTest { @Test public void preservesAllSixDrillFacingsAndActiveFlag() { - for (EnumFacing facing : EnumFacing.values()) { + for (Direction facing : Direction.values()) { int metadata = facing.getIndex() | 8; assertEquals(facing, ElectricLegacyMigrations.legacyDrillFacing(metadata)); assertEquals(true, ElectricLegacyMigrations.legacyDrillActive(metadata)); diff --git a/src/test/java/zone/moddev/mc/electricadvantage/recipe/RecipeConditionsTest.java b/src/test/java/zone/moddev/mc/electricadvantage/recipe/RecipeConditionsTest.java new file mode 100644 index 0000000..7e7ffd6 --- /dev/null +++ b/src/test/java/zone/moddev/mc/electricadvantage/recipe/RecipeConditionsTest.java @@ -0,0 +1,46 @@ +package zone.moddev.mc.electricadvantage.recipe; + +import java.util.Locale; +import com.google.gson.JsonObject; +import org.junit.Test; +import zone.moddev.mc.poweradvantage.PowerAdvantage; +import zone.moddev.mc.poweradvantage.RecipeMode; +import static org.junit.Assert.*; + +public class RecipeConditionsTest { + @Test public void nativeConditionsRoundTripAndEvaluateEveryRecipeMode() { + RecipeMode original = PowerAdvantage.recipeMode; + try { + for (boolean inverted : new boolean[] {false, true}) { + RecipeConditions.ModeSerializer serializer = new RecipeConditions.ModeSerializer(inverted); + for (RecipeMode expected : RecipeMode.values()) { + JsonObject source = new JsonObject(); + source.addProperty("mode", expected.name().toLowerCase(Locale.ROOT)); + RecipeConditions.ModeCondition condition = serializer.read(source); + assertEquals(serializer.getID(), condition.getID()); + JsonObject saved = new JsonObject(); + serializer.write(saved, condition); + assertEquals(source, saved); + for (RecipeMode selected : RecipeMode.values()) { + PowerAdvantage.recipeMode = selected; + assertEquals((selected == expected) != inverted, condition.test()); + } + } + } + } finally { + PowerAdvantage.recipeMode = original; + } + } + + @Test public void modeNamesRemainCaseInsensitiveUnderTurkishLocale() { + Locale original = Locale.getDefault(); + try { + Locale.setDefault(new Locale("tr", "TR")); + JsonObject json = new JsonObject(); + json.addProperty("mode", "apocalyptic"); + new RecipeConditions.ModeSerializer(false).read(json); + } finally { + Locale.setDefault(original); + } + } +} diff --git a/src/test/java/zone/moddev/mc/electricadvantage/resources/BlockLootResourceTest.java b/src/test/java/zone/moddev/mc/electricadvantage/resources/BlockLootResourceTest.java new file mode 100644 index 0000000..367f230 --- /dev/null +++ b/src/test/java/zone/moddev/mc/electricadvantage/resources/BlockLootResourceTest.java @@ -0,0 +1,45 @@ +package zone.moddev.mc.electricadvantage.resources; + +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.stream.Stream; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import org.junit.Test; +import static org.junit.Assert.*; + +public class BlockLootResourceTest { + @Test public void everyOrdinaryBlockKeepsItsOwnNativeItemDrop() throws Exception { + Path root = Paths.get("src/main/resources/data/electricadvantage/loot_tables/blocks"); + try (Stream states = Files.list(Paths.get("src/main/resources/assets/electricadvantage/blockstates"))) { + for (Path state : (Iterable) states.filter(path -> path.toString().endsWith(".json"))::iterator) { + String id = state.getFileName().toString().replace(".json", ""); + // Two retained asset-only models are not registered blocks. + if ("electric_pcb_printer".equals(id) || "geothermal_generator".equals(id)) continue; + if ("li_ore".equals(id) || "sulfur_ore".equals(id) || "pump_pipe_electric".equals(id)) continue; + Path table = root.resolve(id + ".json"); + assertTrue("Missing native block drop for " + id, Files.isRegularFile(table)); + JsonObject json = read(table); + assertEquals("minecraft:block", json.get("type").getAsString()); + JsonObject pool = json.getAsJsonArray("pools").get(0).getAsJsonObject(); + assertEquals(1, pool.get("rolls").getAsInt()); + JsonObject entry = pool.getAsJsonArray("entries").get(0).getAsJsonObject(); + assertEquals("minecraft:item", entry.get("type").getAsString()); + assertEquals("electricadvantage:" + id, entry.get("name").getAsString()); + } + } + assertFalse(Files.exists(root.resolve("pump_pipe_electric.json"))); + } + + @Test public void resourcePackDeclaresTheNativeOneFourteenFormat() throws Exception { + assertEquals(4, read(Paths.get("src/main/resources/pack.mcmeta")) + .getAsJsonObject("pack").get("pack_format").getAsInt()); + } + + private static JsonObject read(Path path) throws Exception { + return new JsonParser().parse(new String(Files.readAllBytes(path), StandardCharsets.UTF_8)) + .getAsJsonObject(); + } +} diff --git a/src/test/java/zone/moddev/mc/electricadvantage/resources/RecipeResourceTest.java b/src/test/java/zone/moddev/mc/electricadvantage/resources/RecipeResourceTest.java index a65b3a7..34c012f 100644 --- a/src/test/java/zone/moddev/mc/electricadvantage/resources/RecipeResourceTest.java +++ b/src/test/java/zone/moddev/mc/electricadvantage/resources/RecipeResourceTest.java @@ -18,7 +18,7 @@ import org.junit.Test; public class RecipeResourceTest { - @Test public void allRecipesUseTheOneThirteenDataPackLocationAndSerializers() throws IOException { + @Test public void allRecipesUseTheNativeOneFourteenDataPackLocationAndSerializers() throws IOException { Path recipes = Paths.get("src/main/resources/data/electricadvantage/recipes"); List files; try (Stream stream = Files.list(recipes)) {