diff --git a/.github/workflows/branches.yml b/.github/workflows/branches.yml index ec8a64c04..1f9cc0224 100644 --- a/.github/workflows/branches.yml +++ b/.github/workflows/branches.yml @@ -21,10 +21,13 @@ jobs: with: path: ~/.gradle/caches key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} + - name: Validate no assets + run: test ! -d ./src/generated - name: Generate assets uses: GabrielBB/xvfb-action@v1.2 with: run: ./gradlew runData --no-daemon + - name: Validate assets + run: test -d ./src/generated - name: Build with Gradle run: ./gradlew build --no-daemon - \ No newline at end of file diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml index 6943a0e35..f53b0b928 100644 --- a/.github/workflows/master.yml +++ b/.github/workflows/master.yml @@ -21,9 +21,13 @@ jobs: with: path: ~/.gradle/caches key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} + - name: Validate no assets + run: test ! -d ./src/generated - name: Generate assets uses: GabrielBB/xvfb-action@v1.2 with: run: ./gradlew runData --no-daemon + - name: Validate assets + run: test -d ./src/generated - name: Build with Gradle run: ./gradlew build --no-daemon diff --git a/.github/workflows/pull_requests.yml b/.github/workflows/pull_requests.yml index 6eb200a4f..16847d1fc 100644 --- a/.github/workflows/pull_requests.yml +++ b/.github/workflows/pull_requests.yml @@ -21,10 +21,14 @@ jobs: with: path: ~/.gradle/caches key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} + - name: Validate no assets + run: test ! -d ./src/generated - name: Generate assets uses: GabrielBB/xvfb-action@v1.2 with: run: ./gradlew runData --no-daemon + - name: Validate assets + run: test -d ./src/generated - name: Build with Gradle env: PR_NUMBER: ${{ github.event.pull_request.number }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index cdcab17fb..b787cd4ee 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -2,7 +2,7 @@ name: 'Release' on: release: - types: [created] + types: [published] jobs: build: @@ -28,17 +28,36 @@ jobs: java-version: 1.8 - name: Grant execute permission for gradlew run: chmod +x gradlew + - name: Validate no assets + run: test ! -d ./src/generated - name: Generate assets uses: GabrielBB/xvfb-action@v1.2 with: run: ./gradlew runData --no-daemon - - name: Build, sign, and publish with Gradle + - name: Validate assets + run: test -d ./src/generated + - name: Build with Gradle env: KEY_STORE_PASS: ${{ secrets.KEY_STORE_PASS }} KEY_STORE_ALIAS: ${{ secrets.KEY_STORE_ALIAS }} KEY_STORE_KEY_PASS: ${{ secrets.KEY_STORE_KEY_PASS }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: ./gradlew build publish --no-daemon + run: ./gradlew build --no-daemon + - name: Upload to curseforge + env: + KEY_STORE_PASS: ${{ secrets.KEY_STORE_PASS }} + KEY_STORE_ALIAS: ${{ secrets.KEY_STORE_ALIAS }} + KEY_STORE_KEY_PASS: ${{ secrets.KEY_STORE_KEY_PASS }} + CHANGELOG: ${{ github.event.release.body }} + CURSEFORGE: ${{ secrets.CURSEFORGE }} + run: ./gradlew curseforge --no-daemon + - name: Publish to github packages + env: + KEY_STORE_PASS: ${{ secrets.KEY_STORE_PASS }} + KEY_STORE_ALIAS: ${{ secrets.KEY_STORE_ALIAS }} + KEY_STORE_KEY_PASS: ${{ secrets.KEY_STORE_KEY_PASS }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: ./gradlew publish --no-daemon - name: Prepare artifact metadata id: prepare_artifact_metadata run: | diff --git a/README.md b/README.md index 8d824f65d..270e9e5c8 100644 --- a/README.md +++ b/README.md @@ -12,10 +12,9 @@ * [Downloads](#downloads) * [Installation](#installation) * [Issues](#issues) +* [API](#applied-energistics-2-api) * [Building](#building) * [Contribution](#contribution) -* [API](#applied-energistics-2-api) -* [CraftTweaker](#applied-energistics-2-crafttweaker) * [Localization](#applied-energistics-2-localization) * [Credits](#credits) @@ -67,6 +66,38 @@ Providing as many details as possible does help us to find and resolve the issue Please note that we might close any issue not matching these requirements. +## Applied Energistics 2 API + +The API for Applied Energistics 2. It is open source to discuss changes, improve documentation, and provide better add-on support in general. + +### Maven + +We use Github Packages as maven repository now. You can use the following snippet as example on how to add a repository to your gradle build file. + + repositories { + maven { + name "AE2" + url "https://maven.pkg.github.com/AppliedEnergistics/Applied-Energistics-2" + } + } + +When compiling against the AE2 API you can use gradle dependencies, just add + + dependencies { + compileOnly "appeng:appliedenergistics2:VERSION:api" + } + +or add the `compileOnly` line to your existing dependencies task to your build.gradle. + +Replace `VERSION` with the desired one. With 1.15+ we switched to using [semver](https://semver.org/). +It is highly recommended following its specification and further considering an upper bound for the dependency version. +A change of the `MAJOR` version will be an API break and can lead to various crashes. Better to inform a player about the addon not supporting the new version until it could be tested or updated. + +An example string would be `appeng:appliedenergistics2:7.0.0-alpha.6:api` for the API only or `appeng:appliedenergistics2:7.0.0-alpha.6` for the whole mod. + +Builds obtained [here](https://github.com/AppliedEnergistics/Applied-Energistics-2/releases) or via [maven](https://github.com/AppliedEnergistics/Applied-Energistics-2/packages) should work in a development environment. +However the dependency might need to be wrapped in `fg.deobf()` like `runtimeOnly fg.deobf("appeng:appliedenergistics2:VERSION:api")` + ## Building 1. Clone this repository via @@ -110,66 +141,6 @@ Here are a few things to keep in mind that will help get your PR approved. If you are only doing single file pull requests, GitHub supports using a quick way without the need of cloning your fork. Also read up about [synching](https://help.github.com/articles/syncing-a-fork) if you plan to contribute on regular basis. -## Applied Energistics 2 API - -The API for Applied Energistics 2. It is open source to discuss changes, improve documentation, and provide better add-on support in general. - -Universal builds obtained [Here](http://ae2.ae-mod.info/Downloads/) should work in a development environment. - -### Maven - -When compiling against the AE2 API you can use gradle dependencies, just add - - dependencies { - compile "appeng:appliedenergistics2:rv_-_____-__:api" - } - -or add the compile line to your existing dependencies task to your build.gradle - -Where the __ are filled in with the correct version criteria; AE2 is available from the default forge maven so no additional repositories are necessary. - -An example string would be `appeng:appliedenergistics2:rv5-stable-1:api` for the API only or `appeng:appliedenergistics2:rv5-stable-1` for the whole mod. - -## Applied Energistics 2 CraftTweaker - -### Inscriber - -The inscriber uses the vanilla recipe system with a custom `type` of `appliedenergistics2:inscriber`. -See the [inscriber recipe folder](src/main/resources/data/appliedenergistics2/recipes/inscriber) for some examples. - -### Grindstone - -The grindstone uses the vanilla recipe system with a custom `type` of `appliedenergistics2:grinder`. -See the [grinder recipe folder](src/main/resources/data/appliedenergistics2/recipes/grinder) for some examples. - -### Spatial -Whitelist a TileEntity class for Spatial IO. - - mods.appliedenergistics2.Spatial.whitelistEntity( String fullEntityClassName ); - -### Attunement -Attune a ItemStack or ModID to a specific P2P-Tunnel type. ModID's are used as fallback when no ItemStack was found. - - mods.appliedenergistics2.Attunement.attuneME( ItemStack itemStack ); - mods.appliedenergistics2.Attunement.attuneME( String modID ); - mods.appliedenergistics2.Attunement.attuneItem( ItemStack itemStack ); - mods.appliedenergistics2.Attunement.attuneItem( String modID ); - mods.appliedenergistics2.Attunement.attuneFluid( ItemStack itemStack ); - mods.appliedenergistics2.Attunement.attuneFluid( String modID ); - mods.appliedenergistics2.Attunement.attuneRedstone( ItemStack itemStack ); - mods.appliedenergistics2.Attunement.attuneRedstone( String modID ); - mods.appliedenergistics2.Attunement.attuneRF( ItemStack itemStack ); - mods.appliedenergistics2.Attunement.attuneRF( String modID ); - mods.appliedenergistics2.Attunement.attuneIC2( ItemStack itemStack ); - mods.appliedenergistics2.Attunement.attuneIC2( String modID ); - mods.appliedenergistics2.Attunement.attuneLight( ItemStack itemStack ); - mods.appliedenergistics2.Attunement.attuneLight( String modID ); - -### Cannon -Add ammo types for the matter cannon. - - mods.appliedenergistics2.Cannon.registerAmmo( ItemStack itemStack, double weight ); - ## Applied Energistics 2 Localization ### English Text diff --git a/build.gradle b/build.gradle index df70078ca..74c7479ac 100644 --- a/build.gradle +++ b/build.gradle @@ -20,7 +20,7 @@ plugins { id 'java' id 'fabric-loom' id 'maven-publish' - id "org.jetbrains.kotlin.jvm" + id "com.matthewprenger.cursegradle" version "1.4.0" id "org.sonarqube" version "2.8" id "jacoco" } @@ -140,7 +140,8 @@ jar { from "LICENSE" } -compileKotlin.kotlinOptions.jvmTarget = "1.8" +apply from: 'gradle/scripts/artifacts.gradle' +apply from: 'gradle/scripts/curseforge.gradle' publishing { publications { diff --git a/gradle.properties b/gradle.properties index 25fe9f796..97e3272d3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -26,3 +26,10 @@ archives_base_name = fabric-example-mod # Kotlin kotlin_version=1.3.61 fabric_kotlin_version=1.3.61+build.1 + +######################################################### +# Deployment # +######################################################### +website_version=1.15.2 +curse_versions=1.15.2 +curseforge_project=223794 diff --git a/gradle/scripts/curseforge.gradle b/gradle/scripts/curseforge.gradle new file mode 100644 index 000000000..a925a4506 --- /dev/null +++ b/gradle/scripts/curseforge.gradle @@ -0,0 +1,39 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2020, TeamAppliedEnergistics, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + *g GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +def isAlpha = project.version.contains("alpha") +def isBeta = project.version.contains("beta") + +def cfReleaseType = "release" +if (isAlpha) { + cfReleaseType = "alpha" +} else if (isBeta) { + cfReleaseType = "beta" +} + +if (System.getenv("CURSEFORGE")) { + curseforge { + apiKey = System.getenv("CURSEFORGE") + project { + id = project.curseforge_project + changelogType = "markdown" + changelog = System.getenv("CHANGELOG") ?: "Please visit our [releases](https://github.com/AppliedEnergistics/Applied-Energistics-2/releases) for a changelog" + releaseType = cfReleaseType + } + } +} \ No newline at end of file diff --git a/src/api/java/appeng/api/AEPlugin.java b/src/api/java/appeng/api/AEAddon.java similarity index 77% rename from src/api/java/appeng/api/AEPlugin.java rename to src/api/java/appeng/api/AEAddon.java index 96186fff7..6722e75ac 100644 --- a/src/api/java/appeng/api/AEPlugin.java +++ b/src/api/java/appeng/api/AEAddon.java @@ -26,12 +26,16 @@ import java.lang.annotation.Target; /** * Use this annotation on a class in your Mod to have it instantiated during the - * initialization phase of Applied Energistics. AE expects your class to have a - * single constructor and can supply certain arguments to your constructor using - * dependency injection. + * initialization phase of Applied Energistics. + * + * The class also needs to implement {@link IAEAddon}. + * + * AE expects your class to have a single constructor without any parameters. + * + * This is the only way to get access to the public {@link IAppEngApi} instance. */ @Target(ElementType.TYPE) -@Retention(RetentionPolicy.RUNTIME) +@Retention(RetentionPolicy.CLASS) @Documented -public @interface AEPlugin { +public @interface AEAddon { } diff --git a/src/api/java/appeng/api/AEApi.java b/src/api/java/appeng/api/AEApi.java deleted file mode 100644 index 1ee908340..000000000 --- a/src/api/java/appeng/api/AEApi.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2013 AlgorithmX2 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package appeng.api; - -import java.lang.reflect.Field; - -import appeng.api.exceptions.CoreInaccessibleException; - -/** - * Entry point for api. - */ -public enum AEApi { - ; - - private static final String CORE_API_FQN = "appeng.core.Api"; - private static final String CORE_API_FIELD = "INSTANCE"; - private static final IAppEngApi HELD_API; - - static { - try { - final Class apiClass = Class.forName(CORE_API_FQN); - final Field apiField = apiClass.getField(CORE_API_FIELD); - - HELD_API = (IAppEngApi) apiField.get(apiClass); - } catch (final ClassNotFoundException e) { - throw new CoreInaccessibleException( - "AE2 API tried to access the " + CORE_API_FQN + " class, without it being declared."); - } catch (final NoSuchFieldException e) { - throw new CoreInaccessibleException("AE2 API tried to access the " + CORE_API_FIELD + " field in " - + CORE_API_FQN + " without it being declared."); - } catch (final IllegalAccessException e) { - throw new CoreInaccessibleException("AE2 API tried to access the " + CORE_API_FIELD + " field in " - + CORE_API_FQN + " without enough access permissions."); - } - } - - /** - * API Entry Point. - * - * @return the {@link IAppEngApi} - */ - public static IAppEngApi instance() { - return HELD_API; - } - -} diff --git a/src/api/java/appeng/api/AEInjectable.java b/src/api/java/appeng/api/AEInjectable.java deleted file mode 100644 index 7dded1cbe..000000000 --- a/src/api/java/appeng/api/AEInjectable.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * This file is part of Applied Energistics 2. - * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. - * - * Applied Energistics 2 is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Applied Energistics 2 is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Applied Energistics 2. If not, see . - */ - -package appeng.api; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Marks interfaces that can be used as injectable constructor arguments for an - * {@link AEPlugin}. - */ -@Target(ElementType.TYPE) -@Retention(RetentionPolicy.RUNTIME) -public @interface AEInjectable { -} diff --git a/src/api/java/appeng/api/implementations/ICraftingPatternItem.java b/src/api/java/appeng/api/IAEAddon.java similarity index 58% rename from src/api/java/appeng/api/implementations/ICraftingPatternItem.java rename to src/api/java/appeng/api/IAEAddon.java index 5b93bd7f6..4a7759370 100644 --- a/src/api/java/appeng/api/implementations/ICraftingPatternItem.java +++ b/src/api/java/appeng/api/IAEAddon.java @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2013 AlgorithmX2 + * Copyright (c) 2020 TeamAppliedEnergistics * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in @@ -21,26 +21,30 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package appeng.api.implementations; +package appeng.api; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.world.World; - -import appeng.api.networking.crafting.ICraftingPatternDetails; +import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; /** - * Implemented on {@link Item} + * Every AE2 addon requiring access to {@link IAppEngApi}, needs to provide at + * least one class implementing this interface. + * + * Further it requires the class to be annotated with {@link AEAddon}. + * */ -public interface ICraftingPatternItem { +public interface IAEAddon { /** - * Access Details about a pattern - * - * @param is pattern - * @param w crafting world - * - * @return details of pattern + * This gets called once the API is successfully constructed and ready to be + * used. + * + * For now this happens during {@link FMLCommonSetupEvent}. + * + * Each addon is responsible to maintain a reference to {@link IAppEngApi} for + * future use. Otherwise there is no alternative to access it later. + * + * @param api The API instance when ready. */ - ICraftingPatternDetails getPatternForItem(ItemStack is, World w); + void onAPIAvailable(IAppEngApi api); + } diff --git a/src/api/java/appeng/api/IAppEngApi.java b/src/api/java/appeng/api/IAppEngApi.java index e09400db3..6a3391f8c 100644 --- a/src/api/java/appeng/api/IAppEngApi.java +++ b/src/api/java/appeng/api/IAppEngApi.java @@ -23,16 +23,22 @@ package appeng.api; +import appeng.api.client.IClientHelper; +import appeng.api.crafting.ICraftingHelper; import appeng.api.definitions.IDefinitions; import appeng.api.features.IRegistryContainer; import appeng.api.networking.IGridHelper; import appeng.api.networking.IGridNode; import appeng.api.parts.IPartHelper; import appeng.api.storage.IStorageHelper; -import appeng.api.util.IClientHelper; -@AEInjectable public interface IAppEngApi { + + /** + * @return An accessible list of all AE definitions + */ + IDefinitions definitions(); + /** * @return Registry Container for the numerous registries in AE2. */ @@ -43,6 +49,11 @@ public interface IAppEngApi { */ IStorageHelper storage(); + /** + * @return A helper for working with crafting related tasks. + */ + ICraftingHelper crafting(); + /** * @return A helper to create {@link IGridNode} and other grid related objects. */ @@ -53,11 +64,6 @@ public interface IAppEngApi { */ IPartHelper partHelper(); - /** - * @return An accessible list of all AE definitions - */ - IDefinitions definitions(); - /** * @return Utility methods primarily useful for client side stuff */ diff --git a/src/api/java/appeng/api/client/ICellModelRegistry.java b/src/api/java/appeng/api/client/ICellModelRegistry.java new file mode 100644 index 000000000..0fbab4332 --- /dev/null +++ b/src/api/java/appeng/api/client/ICellModelRegistry.java @@ -0,0 +1,88 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2020 TeamAppliedEnergistics + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package appeng.api.client; + +import java.util.Map; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import net.minecraft.client.renderer.model.ModelBakery; +import net.minecraft.item.Item; +import net.minecraft.util.ResourceLocation; + +/** + * A registry for 3D models used to render storage cells in the world, when they + * are inserted into a drive or similar machines. + */ +public interface ICellModelRegistry { + + /** + * Register a new model for a storage cell item. + * + *

+ * You are responsible for ensuring that the given model is actually loaded by + * the game. See + * {@see net.minecraftforge.client.model.ModelLoader#addSpecialModel}. + * + * This method only maps an {@link Item} to a {@link ResourceLocation} which can + * be looked up from the {@link ModelBakery}. No validation about missing models + * will be done. + * + * Will throw an exception in case a model is already registered for an item. + * + * For examples look at our cell part models within the drive model directory. + * + * @param item The cell item + * @param model The {@link ResourceLocation} representing the model. + * @return + */ + void registerModel(@Nonnull Item item, @Nonnull ResourceLocation model); + + /** + * The {@link ResourceLocation} of the model used to render the given storage + * cell {@link Item} when inserted into a drive or similar. + * + * @param item + * @return null, if no model is registered. + */ + @Nullable + ResourceLocation model(@Nonnull Item item); + + /** + * An unmodifiable map of all registered mappings. + * + * @return + */ + @Nonnull + Map models(); + + /** + * Returns the default model, which can be used when no explicit model is + * registered. + */ + @Nonnull + ResourceLocation getDefaultModel(); + +} diff --git a/src/api/java/appeng/api/util/IClientHelper.java b/src/api/java/appeng/api/client/IClientHelper.java similarity index 90% rename from src/api/java/appeng/api/util/IClientHelper.java rename to src/api/java/appeng/api/client/IClientHelper.java index b73253111..63f4c5205 100644 --- a/src/api/java/appeng/api/util/IClientHelper.java +++ b/src/api/java/appeng/api/client/IClientHelper.java @@ -21,7 +21,7 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package appeng.api.util; +package appeng.api.client; import java.util.List; @@ -39,4 +39,11 @@ public interface IClientHelper { */ > void addCellInformation(ICellInventoryHandler handler, List lines); + /** + * A helper to work with clientside related tasks for cells. + * + * @return + */ + ICellModelRegistry cells(); + } diff --git a/src/api/java/appeng/api/config/Upgrades.java b/src/api/java/appeng/api/config/Upgrades.java index f754a25fd..9f6326248 100644 --- a/src/api/java/appeng/api/config/Upgrades.java +++ b/src/api/java/appeng/api/config/Upgrades.java @@ -23,7 +23,11 @@ package appeng.api.config; -import java.util.*; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.HashSet; +import java.util.List; +import java.util.Set; import javax.annotation.Nullable; @@ -36,6 +40,7 @@ import net.minecraft.item.BlockItem; import net.minecraft.item.Item; import net.minecraft.item.ItemConvertible; import net.minecraft.text.Text; +import net.minecraft.util.text.TranslationTextComponent; public enum Upgrades { /** @@ -74,11 +79,11 @@ public enum Upgrades { * @param item machine in which this upgrade can be installed * @param maxSupported amount how many upgrades can be installed * @param tooltipGroup If more than one item of the same group are supported, - * the tooltip will show this group name instead. If the - * items have different maxSupported values, the highest + * the tooltip will show this translation key instead. If + * the items have different maxSupported values, the highest * will be shown. */ - public void registerItem(final ItemConvertible item, final int maxSupported, @Nullable Text tooltipGroup) { + public void registerItem(final ItemConvertible item, final int maxSupported, @Nullable String tooltipGroup) { Preconditions.checkNotNull(item); this.supported.add(new Supported(item.asItem(), maxSupported, tooltipGroup)); supportedTooltipLines = null; // Reset tooltip @@ -98,17 +103,17 @@ public enum Upgrades { Text name = supported.item.getName(); // If the group was already added by a previous item, skip this - if (supported.tooltipGroup != null && namesAdded.contains(supported.tooltipGroup)) { + if (supported.getTooltipGroup() != null && namesAdded.contains(supported.getTooltipGroup())) { continue; } // If any of the following items would be of the same group, use the group name // instead - if (supported.tooltipGroup != null) { + if (supported.getTooltipGroup() != null) { for (int j = i + 1; j < this.supported.size(); j++) { - Text otherGroup = this.supported.get(j).tooltipGroup; - if (supported.tooltipGroup.equals(otherGroup)) { - name = supported.tooltipGroup; + Text otherGroup = this.supported.get(j).getTooltipGroup(); + if (supported.getTooltipGroup().equals(otherGroup)) { + name = supported.getTooltipGroup(); break; } } @@ -135,10 +140,11 @@ public enum Upgrades { private final Item item; private final Block block; private final int maxCount; + // Translation key of the tooltip group @Nullable - private final Text tooltipGroup; + private final String tooltipGroup; - public Supported(Item item, int maxCount, @Nullable Text tooltipGroup) { + public Supported(Item item, int maxCount, @Nullable String tooltipGroup) { this.item = item; if (item instanceof BlockItem) { this.block = ((BlockItem) item).getBlock(); @@ -161,6 +167,10 @@ public enum Upgrades { return item != null && this.item == item; } + public ITextComponent getTooltipGroup() { + return this.tooltipGroup != null ? new TranslationTextComponent(this.tooltipGroup) : null; + } + } } diff --git a/src/api/java/appeng/api/crafting/ICraftingHelper.java b/src/api/java/appeng/api/crafting/ICraftingHelper.java new file mode 100644 index 000000000..909f26353 --- /dev/null +++ b/src/api/java/appeng/api/crafting/ICraftingHelper.java @@ -0,0 +1,108 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2020 TeamAppliedEnergistics + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package appeng.api.crafting; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.ICraftingRecipe; +import net.minecraft.world.World; + +import appeng.api.networking.crafting.ICraftingPatternDetails; +import appeng.api.storage.data.IAEItemStack; + +public interface ICraftingHelper { + + /** + * Checks that the given item stack is an encoded pattern. + */ + boolean isEncodedPattern(@Nullable IAEItemStack item); + + /** + * Checks that the given item stack is an encoded pattern. + */ + boolean isEncodedPattern(ItemStack item); + + /** + * Encodes a processing pattern which represents the ability to convert the + * given inputs into the given outputs using some process external to the ME + * system. + * + * @param stack If null, a new item will be created to hold the encoded pattern. + * Otherwise the given item must already contains an encoded + * pattern that will be overwritten. + * @return A new encoded pattern, or the given stack with the pattern encoded in + * it. + */ + ItemStack encodeProcessingPattern(@Nullable ItemStack stack, ItemStack[] in, ItemStack[] out); + + /** + * Encodes a crafting pattern which represents a Vanilla crafting recipe. + * + * @param stack If null, a new item will be created to hold the + * encoded pattern. Otherwise the given item must + * already contains an encoded pattern that will be + * overwritten. + * @param recipe The Vanilla crafting recipe to be encoded. + * @param in The items in the crafting grid, which are used to + * determine what items are supplied from the ME system + * to craft using this pattern. + * @param out What is to be expected as the result of this crafting + * operation by the ME system. + * @param allowSubstitutes Controls whether the ME system will allow the use of + * equivalent items to craft this recipe. + */ + ItemStack encodeCraftingPattern(@Nullable ItemStack stack, ICraftingRecipe recipe, ItemStack[] in, ItemStack out, + boolean allowSubstitutes); + + /** + * Same as {@link #decodePattern(ItemStack, World, boolean)} with no auto + * recovery of changed recipe ids. + */ + @Nullable + default ICraftingPatternDetails decodePattern(@Nonnull ItemStack itemStack, @Nonnull World world) { + return decodePattern(itemStack, world, false); + } + + /** + * Decodes an encoded crafting pattern and returns the pattern details. + *

+ * The item backing the {@link ItemStack} needs to be an item returned by the + * encode methods of this class. + * + * @param itemStack pattern + * @param world world used to access the + * {@link net.minecraft.item.crafting.RecipeManager}. + * @param autoRecovery If true, the method will try to recover from changed + * recipe ids by searching the entire recipe manager for a + * recipe matching the inputs. If this is successful, the + * given item stack will be changed to reflect the new + * recipe id. + * @return The pattern details if the pattern could be decoded. Otherwise null. + */ + @Nullable + ICraftingPatternDetails decodePattern(@Nonnull ItemStack itemStack, @Nonnull World world, boolean autoRecovery); + +} diff --git a/src/api/java/appeng/api/features/IRegistryContainer.java b/src/api/java/appeng/api/features/IRegistryContainer.java index a64494a30..0819f8123 100644 --- a/src/api/java/appeng/api/features/IRegistryContainer.java +++ b/src/api/java/appeng/api/features/IRegistryContainer.java @@ -23,7 +23,6 @@ package appeng.api.features; -import appeng.api.AEInjectable; import appeng.api.movable.IMovableRegistry; import appeng.api.networking.IGridCacheRegistry; import appeng.api.parts.IPartModels; @@ -36,7 +35,6 @@ import appeng.api.storage.ICellRegistry; * @version 7 * @since rv0 */ -@AEInjectable public interface IRegistryContainer { /** diff --git a/src/api/java/appeng/api/implementations/items/IStorageCell.java b/src/api/java/appeng/api/implementations/items/IStorageCell.java index ce8c1d3b6..560d032fa 100644 --- a/src/api/java/appeng/api/implementations/items/IStorageCell.java +++ b/src/api/java/appeng/api/implementations/items/IStorageCell.java @@ -28,18 +28,25 @@ import javax.annotation.Nonnull; import net.minecraft.item.ItemStack; import appeng.api.storage.IStorageChannel; +import appeng.api.storage.cells.ICellHandler; +import appeng.api.storage.cells.ICellInventory; import appeng.api.storage.cells.ICellWorkbenchItem; import appeng.api.storage.data.IAEStack; /** * Any item which implements this can be treated as an IMEInventory via - * Util.getCell / Util.isCell It automatically handles the internals and NBT - * data, which is both nice, and bad for you! + * {@link ICellHandler#getCellInventory(ItemStack, appeng.api.storage.cells.ISaveProvider, IStorageChannel)} + * or {@link ICellHandler#isCell(ItemStack)}. It automatically handles the + * internals and NBT data, which is both nice, and bad for you! * * Good cause it means you don't have to do anything, bad because you have * little to no control over it. - * - * The standard AE implementation only provides 1-63 Types + * + * Limited to {@link Integer} internally for most calculations. E.g. if the used + * or remaining bytes would overflow {@link Integer#MAX_VALUE} the behaviour is + * no longer specified. Even if {@link ICellInventory} is using {@link Long}. + * + * The standard AE implementation also only provides 1-63 Types. */ public interface IStorageCell> extends ICellWorkbenchItem { diff --git a/src/api/java/appeng/api/networking/IGridBlock.java b/src/api/java/appeng/api/networking/IGridBlock.java index 5b7c026cf..2a500847b 100644 --- a/src/api/java/appeng/api/networking/IGridBlock.java +++ b/src/api/java/appeng/api/networking/IGridBlock.java @@ -91,16 +91,6 @@ public interface IGridBlock { */ void onGridNotification(@Nonnull GridNotification notification); - /** - * Update Blocks network/connection/booting status. grid, - * - * @param grid grid - * @param channelsInUse used channels - * @deprecated to be removed in rv7 - */ - @Deprecated - void setNetworkStatus(IGrid grid, int channelsInUse); - /** * Determine which sides of the block can be connected too, only used when * isWorldAccessible returns true, not used for {@link IPart} implementations. diff --git a/src/api/java/appeng/api/networking/crafting/ICraftingPatternDetails.java b/src/api/java/appeng/api/networking/crafting/ICraftingPatternDetails.java index 795c5830b..f2ac98821 100644 --- a/src/api/java/appeng/api/networking/crafting/ICraftingPatternDetails.java +++ b/src/api/java/appeng/api/networking/crafting/ICraftingPatternDetails.java @@ -27,18 +27,19 @@ import net.minecraft.inventory.CraftingInventory; import net.minecraft.item.ItemStack; import net.minecraft.world.World; -import appeng.api.implementations.ICraftingPatternItem; import appeng.api.storage.data.IAEItemStack; /** - * do not implement provided by {@link ICraftingPatternItem} - * - * caching this INSTANCE will increase performance of validation and checks. + * Describes a crafting or processing pattern decoded by + * {@link appeng.api.crafting.ICraftingHelper}. + *

+ * Do not cache instances of this class unless you handle recipe reloads on the + * server and client correctly. */ public interface ICraftingPatternDetails { /** - * @return source item. + * @return encodes this crafting pattern into a new item stack. */ ItemStack getPattern(); @@ -52,7 +53,9 @@ public interface ICraftingPatternDetails { boolean isValidItemForSlot(int slotIndex, ItemStack itemStack, World world); /** - * @return if this pattern is a crafting pattern ( work bench ) + * @return if this pattern is for a Vanilla + * {@link net.minecraft.item.crafting.IRecipeType#CRAFTING crafting + * recipe}. */ boolean isCraftable(); diff --git a/src/api/java/appeng/api/networking/crafting/ICraftingProviderHelper.java b/src/api/java/appeng/api/networking/crafting/ICraftingProviderHelper.java index 00efcc1ca..1c7e6c4cc 100644 --- a/src/api/java/appeng/api/networking/crafting/ICraftingProviderHelper.java +++ b/src/api/java/appeng/api/networking/crafting/ICraftingProviderHelper.java @@ -23,6 +23,7 @@ package appeng.api.networking.crafting; +import appeng.api.crafting.ICraftingHelper; import appeng.api.storage.data.IAEItemStack; /** @@ -33,6 +34,9 @@ public interface ICraftingProviderHelper { /** * Add new Pattern to AE's crafting cache. + * + * This will only accept instances created by + * {@link ICraftingHelper#decodePattern(net.minecraft.item.ItemStack, net.minecraft.world.World)} */ void addCraftingOption(ICraftingMedium medium, ICraftingPatternDetails api); diff --git a/src/api/java/appeng/api/networking/security/IActionHost.java b/src/api/java/appeng/api/networking/security/IActionHost.java index 425e46bff..7e29b463c 100644 --- a/src/api/java/appeng/api/networking/security/IActionHost.java +++ b/src/api/java/appeng/api/networking/security/IActionHost.java @@ -23,7 +23,6 @@ package appeng.api.networking.security; -import javax.annotation.Nonnull; import javax.annotation.Nullable; import appeng.api.networking.IGridNode; diff --git a/src/api/java/appeng/api/parts/ICustomCableConnection.java b/src/api/java/appeng/api/parts/ICustomCableConnection.java index 3c1eb2efa..b9d01a659 100644 --- a/src/api/java/appeng/api/parts/ICustomCableConnection.java +++ b/src/api/java/appeng/api/parts/ICustomCableConnection.java @@ -31,6 +31,6 @@ public interface ICustomCableConnection { * @return This controls the cable connection to the node. -1 to render * connection yourself. */ - public float getCableConnectionLength(AECableType cable); + float getCableConnectionLength(AECableType cable); } diff --git a/src/api/java/appeng/api/parts/IFacadePart.java b/src/api/java/appeng/api/parts/IFacadePart.java index 752606fb6..a3c60c113 100644 --- a/src/api/java/appeng/api/parts/IFacadePart.java +++ b/src/api/java/appeng/api/parts/IFacadePart.java @@ -24,7 +24,6 @@ package appeng.api.parts; import net.minecraft.block.BlockState; -import net.minecraft.entity.Entity; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; diff --git a/src/api/java/appeng/api/parts/IPart.java b/src/api/java/appeng/api/parts/IPart.java index 511371183..f7eb4696e 100644 --- a/src/api/java/appeng/api/parts/IPart.java +++ b/src/api/java/appeng/api/parts/IPart.java @@ -274,7 +274,7 @@ public interface IPart extends ICustomCableConnection { * the node. -1 to render connection yourself. */ @Override - public float getCableConnectionLength(AECableType cable); + float getCableConnectionLength(AECableType cable); /** * same as Block.randomDisplayTick, for but parts. diff --git a/src/api/java/appeng/api/parts/IPartModels.java b/src/api/java/appeng/api/parts/IPartModels.java index 67d0f9647..5e4cf2200 100644 --- a/src/api/java/appeng/api/parts/IPartModels.java +++ b/src/api/java/appeng/api/parts/IPartModels.java @@ -23,13 +23,10 @@ import java.util.Collection; import net.minecraft.util.Identifier; -import appeng.api.AEInjectable; - /** * Allows registration of part models that can then be used in * {@link IPart#getStaticModels()}. */ -@AEInjectable public interface IPartModels { /** diff --git a/src/api/java/appeng/api/recipes/ICraftHandler.java b/src/api/java/appeng/api/recipes/ICraftHandler.java deleted file mode 100644 index c8eaf8bbc..000000000 --- a/src/api/java/appeng/api/recipes/ICraftHandler.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2013 AlgorithmX2 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package appeng.api.recipes; - -import java.util.List; - -import appeng.api.exceptions.MissingIngredientException; -import appeng.api.exceptions.RecipeException; -import appeng.api.exceptions.RegistrationException; - -@Deprecated -public interface ICraftHandler { - - /** - * Called when your recipe handler receives a newly parsed list of - * inputs/outputs. - * - * @param input parsed inputs - * @param output parsed outputs - * - * @throws RecipeException - */ - void setup(List> input, List> output) throws RecipeException; - - /** - * called when all recipes are parsed, and your required to register your - * recipe. - * - * @throws RegistrationException - * @throws MissingIngredientException - */ - void register() throws RegistrationException, MissingIngredientException; -} diff --git a/src/api/java/appeng/api/recipes/IIngredient.java b/src/api/java/appeng/api/recipes/IIngredient.java deleted file mode 100644 index cddf05b26..000000000 --- a/src/api/java/appeng/api/recipes/IIngredient.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2013 AlgorithmX2 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package appeng.api.recipes; - -import net.minecraft.item.ItemStack; - -import appeng.api.exceptions.MissingIngredientException; -import appeng.api.exceptions.RegistrationException; - -@Deprecated -public interface IIngredient { - - /** - * Acquire a single input stack for the current recipe, if more then one - * ItemStack is possible a RegistrationError exception will be thrown, ignore - * these and let the system handle the error. - * - * @return a single ItemStack for the recipe handler. - * - * @throws RegistrationException - * @throws MissingIngredientException - */ - ItemStack getItemStack() throws RegistrationException, MissingIngredientException; - - /** - * Acquire a list of all the input stacks for the current recipe, this is for - * handlers that support multiple inputs per slot. - * - * @return an array of ItemStacks for the recipe handler. - * - * @throws RegistrationException - * @throws MissingIngredientException - */ - ItemStack[] getItemStackSet() throws RegistrationException, MissingIngredientException; - - /** - * If you wish to support air, you must test before getting the ItemStack, or - * ItemStackSet - * - * @return true if this slot contains no ItemStack, this is passed as "_" - */ - boolean isAir(); - - /** - * @return The Name Space of the item. Prefer getItemStack or getItemStackSet - */ - String getNameSpace(); - - /** - * @return The Name of the item. Prefer getItemStack or getItemStackSet - */ - String getItemName(); - - /** - * @return The Damage Value of the item. Prefer getItemStack or getItemStackSet - */ - int getDamageValue(); - - /** - * @return The Damage Value of the item. Prefer getItemStack or getItemStackSet - */ - int getQty(); - - /** - * Bakes the lists in for faster runtime look-ups. - * - * @throws MissingIngredientException - * @throws RegistrationException - */ - void bake() throws RegistrationException, MissingIngredientException; -} diff --git a/src/api/java/appeng/api/recipes/IRecipeHandler.java b/src/api/java/appeng/api/recipes/IRecipeHandler.java deleted file mode 100644 index 6cc66a7dc..000000000 --- a/src/api/java/appeng/api/recipes/IRecipeHandler.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2013 AlgorithmX2 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package appeng.api.recipes; - -/** - * Represents the AE2 Recipe Loading/Reading Class - */ -@Deprecated -public interface IRecipeHandler { - - /** - * Call when you want to read recipes in from a file based on a loader - * - * @param loader recipe loader - * @param path path of file - */ - void parseRecipes(IRecipeLoader loader, String path); - - /** - * this loads the read recipes into minecraft, should be called in Init. - */ - void injectRecipes(); -} diff --git a/src/api/java/appeng/api/recipes/IRecipeLoader.java b/src/api/java/appeng/api/recipes/IRecipeLoader.java deleted file mode 100644 index 96f1ef578..000000000 --- a/src/api/java/appeng/api/recipes/IRecipeLoader.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2013 - 2015 AlgorithmX2 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package appeng.api.recipes; - -import java.io.BufferedReader; - -import javax.annotation.Nonnull; - -@Deprecated -public interface IRecipeLoader { - /** - * @param filePath the path to the to be loaded file - * - * @return reader handler of the file - * - * @throws Exception if reading goes wrong - */ - BufferedReader getFile(@Nonnull String filePath) throws Exception; -} diff --git a/src/api/java/appeng/api/recipes/ResolverResult.java b/src/api/java/appeng/api/recipes/ResolverResult.java deleted file mode 100644 index c26cfac7c..000000000 --- a/src/api/java/appeng/api/recipes/ResolverResult.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2013 AlgorithmX2 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package appeng.api.recipes; - -import net.minecraft.nbt.CompoundTag; - -public class ResolverResult { - - public final String itemName; - public final int damageValue; - public final CompoundTag compound; - - public ResolverResult(final String name, final int damage) { - this.itemName = name; - this.damageValue = damage; - this.compound = null; - } - - public ResolverResult(final String name, final int damage, final CompoundTag data) { - this.itemName = name; - this.damageValue = damage; - this.compound = data; - } -} diff --git a/src/api/java/appeng/api/recipes/ResolverResultSet.java b/src/api/java/appeng/api/recipes/ResolverResultSet.java deleted file mode 100644 index 8750b2c55..000000000 --- a/src/api/java/appeng/api/recipes/ResolverResultSet.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2013 AlgorithmX2 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package appeng.api.recipes; - -import java.util.Arrays; -import java.util.List; - -import net.minecraft.item.ItemStack; - -public class ResolverResultSet { - - public final String name; - public final List results; - - public ResolverResultSet(final String myName, final ItemStack... set) { - this.results = Arrays.asList(set); - this.name = myName; - } -} diff --git a/src/api/java/appeng/api/storage/data/IAEItemStack.java b/src/api/java/appeng/api/storage/data/IAEItemStack.java index 0f5f9b298..eb676e413 100644 --- a/src/api/java/appeng/api/storage/data/IAEItemStack.java +++ b/src/api/java/appeng/api/storage/data/IAEItemStack.java @@ -106,4 +106,13 @@ public interface IAEItemStack extends IAEStack { * @return definition stack */ ItemStack getDefinition(); + + /** + * Compare this AE item stack to another item stack, but ignores the amount. It + * checks the item type, NBT and damage values. + * + * @param is An item stack + */ + boolean equals(ItemStack is); + } \ No newline at end of file diff --git a/src/api/java/appeng/api/storage/data/IAEStack.java b/src/api/java/appeng/api/storage/data/IAEStack.java index 66eafdc48..e589b99f6 100644 --- a/src/api/java/appeng/api/storage/data/IAEStack.java +++ b/src/api/java/appeng/api/storage/data/IAEStack.java @@ -179,17 +179,7 @@ public interface IAEStack> { T empty(); /** - * @return true if the stack is a {@link IAEItemStack} - */ - boolean isItem(); - - /** - * @return true if the stack is a {@link IAEFluidStack} - */ - boolean isFluid(); - - /** - * @return ITEM or FLUID + * @return The {@link IStorageChannel} backing this stack. */ IStorageChannel getChannel(); diff --git a/src/main/java/appeng/block/AEBaseBlockItemChargeable.java b/src/main/java/appeng/block/AEBaseBlockItemChargeable.java index e1248acac..7ed99ba84 100644 --- a/src/main/java/appeng/block/AEBaseBlockItemChargeable.java +++ b/src/main/java/appeng/block/AEBaseBlockItemChargeable.java @@ -18,7 +18,7 @@ package appeng.block; -import appeng.api.AEApi; +import appeng.core.Api; import appeng.api.config.AccessRestriction; import appeng.api.config.Actionable; import appeng.api.config.PowerUnits; @@ -129,7 +129,7 @@ public class AEBaseBlockItemChargeable extends AEBaseBlockItem implements IAEIte private double getMaxEnergyCapacity() { final Block blockID = Block.getBlockFromItem(this); - final IBlockDefinition energyCell = AEApi.instance().definitions().blocks().energyCell(); + final IBlockDefinition energyCell = Api.instance().definitions().blocks().energyCell(); return energyCell.maybeBlock().map(block -> { if (blockID == block) { diff --git a/src/main/java/appeng/block/crafting/CraftingStorageItem.java b/src/main/java/appeng/block/crafting/CraftingStorageItem.java index 71332c23d..51df53f32 100644 --- a/src/main/java/appeng/block/crafting/CraftingStorageItem.java +++ b/src/main/java/appeng/block/crafting/CraftingStorageItem.java @@ -22,10 +22,10 @@ import net.minecraft.block.Block; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import appeng.api.AEApi; import appeng.api.features.AEFeature; import appeng.block.AEBaseBlockItem; import appeng.core.AEConfig; +import appeng.core.Api; public class CraftingStorageItem extends AEBaseBlockItem { @@ -36,7 +36,7 @@ public class CraftingStorageItem extends AEBaseBlockItem { // FIXME FABRIC needs to move to disassembly crafting recipes // FIXME FABRIC @Override // FIXME FABRIC public Item getRecipeRemainder() { -// FIXME FABRIC return AEApi.instance().definitions().blocks().craftingUnit().item(); +// FIXME FABRIC return Api.instance().definitions().blocks().craftingUnit().item(); // FIXME FABRIC } // FIXME FABRIC // FIXME FABRIC @Override diff --git a/src/main/java/appeng/block/misc/ChargerBlock.java b/src/main/java/appeng/block/misc/ChargerBlock.java index 92eaae571..690116f76 100644 --- a/src/main/java/appeng/block/misc/ChargerBlock.java +++ b/src/main/java/appeng/block/misc/ChargerBlock.java @@ -50,13 +50,13 @@ import net.minecraft.util.shape.VoxelShapes; import net.minecraft.world.BlockView; import net.minecraft.world.World; -import appeng.api.AEApi; import appeng.api.util.AEAxisAlignedBB; import appeng.block.AEBaseTileBlock; import appeng.client.render.effects.ParticleTypes; import appeng.client.render.renderable.ItemRenderable; import appeng.client.render.tesr.ModularTESR; import appeng.core.AEConfig; +import appeng.core.Api; import appeng.core.AppEng; import appeng.tile.misc.ChargerBlockEntity; import appeng.util.Platform; @@ -102,7 +102,7 @@ public class ChargerBlock extends AEBaseTileBlock { final ChargerBlockEntity tile = this.getBlockEntity(w, pos); if (tile != null) { - if (AEApi.instance().definitions().materials().certusQuartzCrystalCharged() + if (Api.instance().definitions().materials().certusQuartzCrystalCharged() .isSameAs(tile.getInternalInventory().getInvStack(0))) { final double xOff = 0.0; final double yOff = 0.0; diff --git a/src/main/java/appeng/block/storage/ChestBlock.java b/src/main/java/appeng/block/storage/ChestBlock.java index 8923eb99a..c9bfbbee7 100644 --- a/src/main/java/appeng/block/storage/ChestBlock.java +++ b/src/main/java/appeng/block/storage/ChestBlock.java @@ -28,7 +28,7 @@ import net.minecraft.block.BlockState; import net.minecraft.block.Material; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; -import net.minecraft.state.property.EnumProperty; +import net.minecraft.state.property.BooleanProperty; import net.minecraft.state.StateManager; import net.minecraft.util.ActionResult; import net.minecraft.util.Hand; @@ -43,18 +43,17 @@ import appeng.tile.storage.ChestBlockEntity; public class ChestBlock extends AEBaseTileBlock { - private final static EnumProperty SLOT_STATE = EnumProperty.of("slot_state", - DriveSlotState.class); + private final static BooleanProperty LIGHTS_ON = BooleanProperty.of("lights_on"); public ChestBlock() { super(defaultProps(Material.METAL)); - this.setDefaultState(this.getDefaultState().with(SLOT_STATE, DriveSlotState.EMPTY)); + this.setDefaultState(this.getDefaultState().with(LIGHTS_ON, false)); } @Override protected void appendProperties(StateManager.Builder builder) { super.appendProperties(builder); - builder.add(SLOT_STATE); + builder.add(LIGHTS_ON); } @Override @@ -69,7 +68,7 @@ public class ChestBlock extends AEBaseTileBlock { slotState = DriveSlotState.OFFLINE; } - return currentState.with(SLOT_STATE, slotState); + return currentState.with(LIGHTS_ON, slotState != DriveSlotState.EMPTY && slotState != DriveSlotState.OFFLINE); } @Override diff --git a/src/main/java/appeng/block/storage/DriveSlotCellType.java b/src/main/java/appeng/block/storage/DriveSlotCellType.java deleted file mode 100644 index c49d05693..000000000 --- a/src/main/java/appeng/block/storage/DriveSlotCellType.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * This file is part of Applied Energistics 2. - * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. - * - * Applied Energistics 2 is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Applied Energistics 2 is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Applied Energistics 2. If not, see . - */ - -package appeng.block.storage; - -import net.minecraft.util.StringIdentifiable; - -/** - * Describes the type of cell present in a slot. - */ -public enum DriveSlotCellType implements StringIdentifiable { - - EMPTY("empty"), - - ITEM("item"), - - FLUID("fluid"); - - private final String name; - - DriveSlotCellType(String name) { - this.name = name; - } - - @Override - public String asString() { - return this.name; - } - -} diff --git a/src/main/java/appeng/client/gui/implementations/AESubScreen.java b/src/main/java/appeng/client/gui/implementations/AESubScreen.java index f7ddf6149..1d993a8e1 100644 --- a/src/main/java/appeng/client/gui/implementations/AESubScreen.java +++ b/src/main/java/appeng/client/gui/implementations/AESubScreen.java @@ -8,7 +8,6 @@ import net.minecraft.client.render.item.ItemRenderer; import net.minecraft.screen.ScreenHandlerType; import net.minecraft.item.ItemStack; -import appeng.api.AEApi; import appeng.api.definitions.IDefinitions; import appeng.api.definitions.IParts; import appeng.client.gui.AEBaseScreen; @@ -18,6 +17,7 @@ import appeng.container.implementations.CraftingTermContainer; import appeng.container.implementations.MEMonitorableContainer; import appeng.container.implementations.PatternTermContainer; import appeng.container.implementations.WirelessTermContainer; +import appeng.core.Api; import appeng.core.sync.network.NetworkHandler; import appeng.core.sync.packets.SwitchGuisPacket; import appeng.helpers.IPriorityHost; @@ -45,7 +45,7 @@ final class AESubScreen { public AESubScreen(AEBaseScreen gui, Object containerTarget) { this.gui = gui; - final IDefinitions definitions = AEApi.instance().definitions(); + final IDefinitions definitions = Api.instance().definitions(); final IParts parts = definitions.parts(); if (containerTarget instanceof ChestBlockEntity) { diff --git a/src/main/java/appeng/client/gui/implementations/CraftConfirmScreen.java b/src/main/java/appeng/client/gui/implementations/CraftConfirmScreen.java index 56bf5d46a..9efd63a43 100644 --- a/src/main/java/appeng/client/gui/implementations/CraftConfirmScreen.java +++ b/src/main/java/appeng/client/gui/implementations/CraftConfirmScreen.java @@ -34,13 +34,13 @@ import net.minecraft.text.LiteralText; import net.minecraft.text.Text; -import appeng.api.AEApi; import appeng.api.storage.channels.IItemStorageChannel; import appeng.api.storage.data.IAEItemStack; import appeng.api.storage.data.IItemList; import appeng.client.gui.AEBaseScreen; import appeng.client.gui.widgets.Scrollbar; import appeng.container.implementations.CraftConfirmContainer; +import appeng.core.Api; import appeng.core.localization.GuiText; import appeng.core.sync.network.NetworkHandler; import appeng.core.sync.packets.ConfigValuePacket; @@ -52,11 +52,11 @@ public class CraftConfirmScreen extends AEBaseScreen { private final int rows = 5; - private final IItemList storage = AEApi.instance().storage() + private final IItemList storage = Api.instance().storage() .getStorageChannel(IItemStorageChannel.class).createList(); - private final IItemList pending = AEApi.instance().storage() + private final IItemList pending = Api.instance().storage() .getStorageChannel(IItemStorageChannel.class).createList(); - private final IItemList missing = AEApi.instance().storage() + private final IItemList missing = Api.instance().storage() .getStorageChannel(IItemStorageChannel.class).createList(); private final List visual = new ArrayList<>(); diff --git a/src/main/java/appeng/client/gui/implementations/CraftingCPUScreen.java b/src/main/java/appeng/client/gui/implementations/CraftingCPUScreen.java index 2e389ddb4..2817a8ba0 100644 --- a/src/main/java/appeng/client/gui/implementations/CraftingCPUScreen.java +++ b/src/main/java/appeng/client/gui/implementations/CraftingCPUScreen.java @@ -35,7 +35,6 @@ import net.minecraft.item.ItemStack; import net.minecraft.text.Text; -import appeng.api.AEApi; import appeng.api.config.SortDir; import appeng.api.config.SortOrder; import appeng.api.config.ViewItems; @@ -48,6 +47,7 @@ import appeng.client.gui.widgets.ISortSource; import appeng.client.gui.widgets.Scrollbar; import appeng.container.implementations.CraftingCPUContainer; import appeng.core.AEConfig; +import appeng.core.Api; import appeng.core.localization.GuiText; import appeng.core.sync.network.NetworkHandler; import appeng.core.sync.packets.ConfigValuePacket; @@ -80,11 +80,11 @@ public class CraftingCPUScreen extends AEBaseScr private static final int ITEMSTACK_LEFT_OFFSET = 9; private static final int ITEMSTACK_TOP_OFFSET = 22; - private IItemList storage = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class) + private IItemList storage = Api.instance().storage().getStorageChannel(IItemStorageChannel.class) .createList(); - private IItemList active = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class) + private IItemList active = Api.instance().storage().getStorageChannel(IItemStorageChannel.class) .createList(); - private IItemList pending = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class) + private IItemList pending = Api.instance().storage().getStorageChannel(IItemStorageChannel.class) .createList(); private List visual = new ArrayList<>(); @@ -101,9 +101,9 @@ public class CraftingCPUScreen extends AEBaseScr } public void clearItems() { - this.storage = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList(); - this.active = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList(); - this.pending = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList(); + this.storage = Api.instance().storage().getStorageChannel(IItemStorageChannel.class).createList(); + this.active = Api.instance().storage().getStorageChannel(IItemStorageChannel.class).createList(); + this.pending = Api.instance().storage().getStorageChannel(IItemStorageChannel.class).createList(); this.visual = new ArrayList<>(); } diff --git a/src/main/java/appeng/client/gui/implementations/IOPortScreen.java b/src/main/java/appeng/client/gui/implementations/IOPortScreen.java index 206005b47..313994488 100644 --- a/src/main/java/appeng/client/gui/implementations/IOPortScreen.java +++ b/src/main/java/appeng/client/gui/implementations/IOPortScreen.java @@ -22,7 +22,6 @@ import net.minecraft.client.util.math.MatrixStack; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.text.Text; -import appeng.api.AEApi; import appeng.api.config.FullnessMode; import appeng.api.config.OperationMode; import appeng.api.config.RedstoneMode; @@ -31,6 +30,7 @@ import appeng.api.definitions.IDefinitions; import appeng.client.gui.widgets.ServerSettingToggleButton; import appeng.client.gui.widgets.SettingToggleButton; import appeng.container.implementations.IOPortContainer; +import appeng.core.Api; import appeng.core.localization.GuiText; public class IOPortScreen extends UpgradeableScreen { @@ -79,7 +79,7 @@ public class IOPortScreen extends UpgradeableScreen { public void drawBG(MatrixStack matrices, final int offsetX, final int offsetY, final int mouseX, final int mouseY, float partialTicks) { super.drawBG(matrices, offsetX, offsetY, mouseX, mouseY, partialTicks); - final IDefinitions definitions = AEApi.instance().definitions(); + final IDefinitions definitions = Api.instance().definitions(); definitions.items().cell1k().maybeStack(1) .ifPresent(cell1kStack -> this.drawItem(offsetX + 66 - 8, offsetY + 17, cell1kStack)); diff --git a/src/main/java/appeng/client/gui/implementations/InterfaceTerminalScreen.java b/src/main/java/appeng/client/gui/implementations/InterfaceTerminalScreen.java index bbcc32ad3..c7707c653 100644 --- a/src/main/java/appeng/client/gui/implementations/InterfaceTerminalScreen.java +++ b/src/main/java/appeng/client/gui/implementations/InterfaceTerminalScreen.java @@ -42,7 +42,6 @@ import net.minecraft.nbt.ListTag; import net.minecraft.text.Text; -import appeng.api.AEApi; import appeng.api.storage.channels.IItemStorageChannel; import appeng.client.ActionKey; import appeng.client.gui.AEBaseScreen; @@ -51,6 +50,7 @@ import appeng.client.gui.widgets.Scrollbar; import appeng.client.me.ClientDCInternalInv; import appeng.client.me.SlotDisconnected; import appeng.container.implementations.InterfaceTerminalContainer; +import appeng.core.Api; import appeng.core.AppEng; import appeng.core.localization.GuiText; import appeng.util.Platform; @@ -321,7 +321,7 @@ public class InterfaceTerminalScreen extends AEBaseScreen list = AEApi.instance().storage() - .getStorageChannel(IFluidStorageChannel.class).createList(); + private final IItemList list = Api.instance().storage().getStorageChannel(IFluidStorageChannel.class) + .createList(); private final ArrayList view = new ArrayList<>(); private final IScrollSource src; private final ISortSource sortSrc; diff --git a/src/main/java/appeng/client/me/ItemRepo.java b/src/main/java/appeng/client/me/ItemRepo.java index 2a259e7f2..ead053c20 100644 --- a/src/main/java/appeng/client/me/ItemRepo.java +++ b/src/main/java/appeng/client/me/ItemRepo.java @@ -28,7 +28,6 @@ import javax.annotation.Nonnull; import net.minecraft.item.ItemStack; import net.minecraft.text.Text; -import appeng.api.AEApi; import appeng.api.config.SearchBoxMode; import appeng.api.config.SortOrder; import appeng.api.config.ViewItems; @@ -39,6 +38,7 @@ import appeng.api.storage.data.IItemList; import appeng.client.gui.widgets.IScrollSource; import appeng.client.gui.widgets.ISortSource; import appeng.core.AEConfig; +import appeng.core.Api; import appeng.integration.abstraction.ReiFacade; import appeng.items.storage.ViewCellItem; import appeng.util.ItemSorters; @@ -47,7 +47,7 @@ import appeng.util.prioritylist.IPartitionList; public class ItemRepo { - private final IItemList list = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class) + private final IItemList list = Api.instance().storage().getStorageChannel(IItemStorageChannel.class) .createList(); private final ArrayList view = new ArrayList<>(); private final IScrollSource src; diff --git a/src/main/java/appeng/client/render/cablebus/FacadeBuilder.java b/src/main/java/appeng/client/render/cablebus/FacadeBuilder.java index dca499f4f..f5b4bb4a5 100644 --- a/src/main/java/appeng/client/render/cablebus/FacadeBuilder.java +++ b/src/main/java/appeng/client/render/cablebus/FacadeBuilder.java @@ -50,8 +50,8 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.BlockRenderView; -import appeng.api.AEApi; import appeng.api.util.AEAxisAlignedBB; +import appeng.core.Api; import appeng.parts.misc.CableAnchorPart; /** * The FacadeBuilder builds for facades.. @@ -99,7 +99,7 @@ public class FacadeBuilder { RenderContext context, Function modelLookup) { //FIXME BakedPipeline pipeline = this.pipelines.get(); //FIXME Quad collectorQuad = this.collectors.get(); - boolean transparent = AEApi.instance().partHelper().getCableRenderMode().transparentFacades; + boolean transparent = Api.instance().partHelper().getCableRenderMode().transparentFacades; Map facadeStates = renderState.getFacades(); List partBoxes = renderState.getBoundingBoxes(); Set sidesWithParts = renderState.getAttachments().keySet(); diff --git a/src/main/java/appeng/client/render/effects/EnergyFx.java b/src/main/java/appeng/client/render/effects/EnergyFx.java index 25a6367f7..1f7136cd0 100644 --- a/src/main/java/appeng/client/render/effects/EnergyFx.java +++ b/src/main/java/appeng/client/render/effects/EnergyFx.java @@ -22,7 +22,11 @@ import net.minecraft.client.render.VertexConsumer; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.client.particle.*; +import net.minecraft.client.particle.IAnimatedSprite; +import net.minecraft.client.particle.IParticleFactory; +import net.minecraft.client.particle.IParticleRenderType; +import net.minecraft.client.particle.Particle; +import net.minecraft.client.particle.SpriteTexturedParticle; import net.minecraft.client.render.Camera; import net.minecraft.client.world.ClientWorld; import net.minecraft.util.math.MathHelper; diff --git a/src/main/java/appeng/client/render/tesr/CellLedRenderer.java b/src/main/java/appeng/client/render/tesr/CellLedRenderer.java new file mode 100644 index 000000000..ab47d6332 --- /dev/null +++ b/src/main/java/appeng/client/render/tesr/CellLedRenderer.java @@ -0,0 +1,106 @@ +package appeng.client.render.tesr; + +import java.util.EnumMap; + +import com.mojang.blaze3d.matrix.MatrixStack; +import com.mojang.blaze3d.vertex.IVertexBuilder; + +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.Vector3f; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; + +import appeng.api.implementations.tiles.IChestOrDrive; +import appeng.block.storage.DriveSlotState; + +/** + * Utility class to render LEDs for storage cells from a Tile Entity Renderer. + */ +class CellLedRenderer { + + private static final EnumMap STATE_COLORS; + + // Color used for the cell indicator for blinking during recent activity + private static final Vector3f BLINK_COLOR = new Vector3f(1, 0.5f, 0.5f); + + static { + STATE_COLORS = new EnumMap<>(DriveSlotState.class); + STATE_COLORS.put(DriveSlotState.OFFLINE, new Vector3f(0, 0, 0)); + STATE_COLORS.put(DriveSlotState.ONLINE, new Vector3f(0, 1, 0)); + STATE_COLORS.put(DriveSlotState.NOT_EMPTY, new Vector3f(0f, 0.667f, 1)); + STATE_COLORS.put(DriveSlotState.TYPES_FULL, new Vector3f(1, 0.667f, 0)); + STATE_COLORS.put(DriveSlotState.FULL, new Vector3f(1, 0, 0)); + } + + // The positions are based on the upper left slot in a drive + private static final float L = 5 / 16.f; // left (x-axis) + private static final float R = 4 / 16.f; // right (x-axis) + private static final float T = 1 / 16.f; // top (y-axis) + private static final float B = -0.001f / 16.f; // bottom (y-axis) + private static final float FR = -0.001f / 16.f; // front (z-axis) + private static final float BA = 0.499f / 16.f; // back (z-axis) + + // Vertex data for the LED cuboid (has no back) + // Directions are when looking from the front onto the LED + private static final float[] LED_QUADS = { + // Front Face + R, T, FR, L, T, FR, L, B, FR, R, B, FR, + // Left Face + L, T, FR, L, T, BA, L, B, BA, L, B, FR, + // Right Face + R, T, BA, R, T, FR, R, B, FR, R, B, BA, + // Top Face + R, T, BA, L, T, BA, L, T, FR, R, T, FR, + // Bottom Face + R, B, FR, L, B, FR, L, B, BA, R, B, BA, }; + + public static final RenderType RENDER_LAYER = RenderType.makeType("ae_drive_leds", + DefaultVertexFormats.POSITION_COLOR, 7, 32565, false, true, RenderType.State.getBuilder().build(false)); + + public static void renderLed(IChestOrDrive drive, int slot, IVertexBuilder buffer, MatrixStack ms, + float partialTicks) { + + Vector3f color = getColorForSlot(drive, slot, partialTicks); + if (color == null) { + return; + } + + for (int i = 0; i < LED_QUADS.length; i += 3) { + float x = LED_QUADS[i]; + float y = LED_QUADS[i + 1]; + float z = LED_QUADS[i + 2]; + buffer.pos(ms.getLast().getMatrix(), x, y, z).color(color.getX(), color.getY(), color.getZ(), 1.f) + .endVertex(); + } + } + + private static Vector3f getColorForSlot(IChestOrDrive drive, int slot, float partialTicks) { + DriveSlotState state = DriveSlotState.fromCellStatus(drive.getCellStatus(slot)); + if (state == DriveSlotState.EMPTY) { + return null; + } + + if (!drive.isPowered()) { + return STATE_COLORS.get(DriveSlotState.OFFLINE); + } + + Vector3f col = STATE_COLORS.get(state); + if (drive.isCellBlinking(slot)) { + // 200 ms interval (100ms to get to red, then 100ms back) + long t = System.currentTimeMillis() % 200; + float f = (t - 100) / 200.0f + 0.5f; + f = easeInOutCubic(f); + col = col.copy(); + col.lerp(BLINK_COLOR, f); + } + + return col; + } + + private static float easeInOutCubic(float x) { + return x < 0.5f ? 4 * x * x * x : 1 - (float) Math.pow(-2 * x + 2, 3) / 2; + } + + private CellLedRenderer() { + } + +} diff --git a/src/main/java/appeng/client/render/tesr/ChestTileEntityRenderer.java b/src/main/java/appeng/client/render/tesr/ChestTileEntityRenderer.java new file mode 100644 index 000000000..667fe91ac --- /dev/null +++ b/src/main/java/appeng/client/render/tesr/ChestTileEntityRenderer.java @@ -0,0 +1,154 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +package appeng.client.render.tesr; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import com.mojang.blaze3d.matrix.MatrixStack; +import com.mojang.blaze3d.vertex.IVertexBuilder; + +import net.minecraft.block.BlockState; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.BlockModelRenderer; +import net.minecraft.client.renderer.IRenderTypeBuffer; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.model.BakedQuad; +import net.minecraft.client.renderer.model.IBakedModel; +import net.minecraft.client.renderer.model.ModelManager; +import net.minecraft.client.renderer.tileentity.TileEntityRenderer; +import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; +import net.minecraft.item.Item; +import net.minecraft.item.Items; +import net.minecraft.util.Direction; +import net.minecraft.util.ResourceLocation; +import net.minecraft.world.World; +import net.minecraftforge.client.model.data.EmptyModelData; +import net.minecraftforge.client.model.data.IModelData; + +import appeng.api.client.ICellModelRegistry; +import appeng.block.storage.DriveSlotsState; +import appeng.client.render.DelegateBakedModel; +import appeng.client.render.FacingToRotation; +import appeng.core.Api; +import appeng.tile.storage.ChestTileEntity; + +/** + * The tile entity renderer for ME chests takes care of rendering the right + * model for the inserted cell, as well as the LED. + */ +public class ChestTileEntityRenderer extends TileEntityRenderer { + + private final ICellModelRegistry cellModelRegistry = Api.instance().client().cells(); + + private final ModelManager modelManager; + + private final BlockModelRenderer blockRenderer; + + public ChestTileEntityRenderer(TileEntityRendererDispatcher rendererDispatcherIn) { + super(rendererDispatcherIn); + Minecraft client = Minecraft.getInstance(); + modelManager = client.getModelManager(); + blockRenderer = client.getBlockRendererDispatcher().getBlockModelRenderer(); + } + + @Override + public void render(ChestTileEntity chest, float partialTicks, MatrixStack matrices, IRenderTypeBuffer buffers, + int combinedLight, int combinedOverlay) { + + World world = chest.getWorld(); + if (world == null) { + return; + } + + DriveSlotsState driveSlotState = DriveSlotsState.fromChestOrDrive(chest); + + Item cellItem = driveSlotState.getCell(0); + if (cellItem == null || cellItem == Items.AIR) { + return; // No cell inserted into chest + } + + ResourceLocation cellModelLocation = cellModelRegistry.model(cellItem); + if (cellModelLocation == null) { + cellModelLocation = cellModelRegistry.getDefaultModel(); + } + + IBakedModel model = modelManager.getModel(cellModelLocation); + + matrices.push(); + matrices.translate(0.5, 0.5, 0.5); + FacingToRotation rotation = FacingToRotation.get(chest.getForward(), chest.getUp()); + rotation.push(matrices); + matrices.translate(-0.5, -0.5, -0.5); + + // The models are created for the top-left slot of the drive model, + // we need to move them into place for the slot on the ME chest + matrices.translate(5 / 16.0, 4 / 16.0, 0); + + // Render the cell model as-if it was a block model + IVertexBuilder buffer = buffers.getBuffer(RenderType.getCutout()); + // We "fake" the position here to make it use the light-value in front of the + // drive + FaceRotatingModel rotatedModel = new FaceRotatingModel(model, rotation); + blockRenderer.renderModel(world, rotatedModel, chest.getBlockState(), chest.getPos(), matrices, buffer, false, + new Random(), 0L, combinedOverlay, EmptyModelData.INSTANCE); + + IVertexBuilder ledBuffer = buffers.getBuffer(CellLedRenderer.RENDER_LAYER); + CellLedRenderer.renderLed(chest, 0, ledBuffer, matrices, partialTicks); + + matrices.pop(); + } + + /** + * The actual vertex data will be transformed using the matrix stack, but the + * faces will not be correctly rotated so the incorrect lighting data would be + * used to apply diffuse lighting and the lightmap texture. + */ + private static class FaceRotatingModel extends DelegateBakedModel { + private final FacingToRotation r; + + protected FaceRotatingModel(IBakedModel base, FacingToRotation r) { + super(base); + this.r = r; + } + + @Nonnull + @Override + public List getQuads(@Nullable BlockState state, @Nullable Direction side, @Nonnull Random rand, + @Nonnull IModelData extraData) { + if (side != null) { + side = r.rotate(side); // This fixes the incorrect lightmap position + } + List quads = new ArrayList<>(super.getQuads(state, side, rand, extraData)); + + for (int i = 0; i < quads.size(); i++) { + BakedQuad quad = quads.get(i); + quads.set(i, new BakedQuad(quad.getVertexData(), quad.getTintIndex(), r.rotate(quad.getFace()), + quad.func_187508_a(), quad.shouldApplyDiffuseLighting())); + } + + return quads; + } + } + +} diff --git a/src/main/java/appeng/client/render/tesr/DriveLedTileEntityRenderer.java b/src/main/java/appeng/client/render/tesr/DriveLedTileEntityRenderer.java index 2282f495f..b81fe6b19 100644 --- a/src/main/java/appeng/client/render/tesr/DriveLedTileEntityRenderer.java +++ b/src/main/java/appeng/client/render/tesr/DriveLedTileEntityRenderer.java @@ -1,7 +1,5 @@ package appeng.client.render.tesr; -import java.util.EnumMap; - import net.minecraft.client.render.RenderLayer; import net.minecraft.client.render.VertexConsumer; import net.minecraft.client.render.VertexFormats; @@ -14,8 +12,8 @@ import net.minecraft.client.util.math.Vector3f; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import appeng.block.storage.DriveSlotState; import appeng.client.render.FacingToRotation; +import appeng.client.render.model.DriveBakedModel; import appeng.tile.storage.DriveBlockEntity; /** @@ -24,46 +22,8 @@ import appeng.tile.storage.DriveBlockEntity; @Environment(EnvType.CLIENT) public class DriveLedTileEntityRenderer extends BlockEntityRenderer { - private static final EnumMap STATE_COLORS; - - // Color used for the cell indicator for blinking during recent activity - private static final Vector3f BLINK_COLOR = new Vector3f(1, 0.5f, 0.5f); - - static { - STATE_COLORS = new EnumMap<>(DriveSlotState.class); - STATE_COLORS.put(DriveSlotState.OFFLINE, new Vector3f(0, 0, 0)); - STATE_COLORS.put(DriveSlotState.ONLINE, new Vector3f(0, 1, 0)); - STATE_COLORS.put(DriveSlotState.NOT_EMPTY, new Vector3f(0f, 0.667f, 1)); - STATE_COLORS.put(DriveSlotState.TYPES_FULL, new Vector3f(1, 0.667f, 0)); - STATE_COLORS.put(DriveSlotState.FULL, new Vector3f(1, 0, 0)); - } - - private static final float L = 14 / 16.f; // left (x-axis) - private static final float R = 13 / 16.f; // right (x-axis) - private static final float T = 14 / 16.f; // top (x-axis) - private static final float B = 12.999f / 16.f; // bottom (x-axis) - private static final float FR = 0.999f / 16.f; // front (z-axis) - private static final float BA = 1.499f / 16.f; // back (z-axis) - - // Vertex data for the LED cuboid (has no back) - // Directions are when looking from the front onto the LED - private static final float[] LED_QUADS = { - // Front Face - R, T, FR, L, T, FR, L, B, FR, R, B, FR, - // Left Face - L, T, FR, L, T, BA, L, B, BA, L, B, FR, - // Right Face - R, T, BA, R, T, FR, R, B, FR, R, B, BA, - // Top Face - R, T, BA, L, T, BA, L, T, FR, R, T, FR, - // Bottom Face - R, B, FR, L, B, FR, L, B, BA, R, B, BA, }; - - private static final RenderLayer STATE = RenderLayer.of("ae_drive_leds", VertexFormats.POSITION_COLOR, 7, - 32565, false, true, RenderLayer.MultiPhaseParameters.builder().build(false)); - - public DriveLedTileEntityRenderer(BlockEntityRenderDispatcher rendererDispatcherIn) { - super(rendererDispatcherIn); + public DriveLedTileEntityRenderer(BlockEntityRendererDispatcher rendererDispatcher) { + super(rendererDispatcher); } @Override @@ -79,32 +39,18 @@ public class DriveLedTileEntityRenderer extends BlockEntityRenderer 0) { - IAEItemStack ais = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class) + IAEItemStack ais = Api.instance().storage().getStorageChannel(IItemStorageChannel.class) .createStack(isg); ais.setStackSize(1); final IAEItemStack extracted = ais.copy(); @@ -743,7 +743,7 @@ public abstract class AEBaseContainer extends ScreenHandler { this.updateHeld(player); } } else { - IAEItemStack ais = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class) + IAEItemStack ais = Api.instance().storage().getStorageChannel(IItemStorageChannel.class) .createStack(player.inventory.getCursorStack()); ais = Platform.poweredInsert(this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource()); @@ -783,7 +783,7 @@ public abstract class AEBaseContainer extends ScreenHandler { this.updateHeld(player); } } else { - IAEItemStack ais = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class) + IAEItemStack ais = Api.instance().storage().getStorageChannel(IItemStorageChannel.class) .createStack(player.inventory.getCursorStack()); ais.setStackSize(1); ais = Platform.poweredInsert(this.getPowerSource(), this.getCellInventory(), ais, @@ -861,7 +861,7 @@ public abstract class AEBaseContainer extends ScreenHandler { return input; } final IAEItemStack ais = Platform.poweredInsert(this.getPowerSource(), this.getCellInventory(), - AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createStack(input), + Api.instance().storage().getStorageChannel(IItemStorageChannel.class).createStack(input), this.getActionSource()); if (ais == null) { return ItemStack.EMPTY; diff --git a/src/main/java/appeng/container/implementations/CellWorkbenchContainer.java b/src/main/java/appeng/container/implementations/CellWorkbenchContainer.java index 41df58708..aec8ce7f5 100644 --- a/src/main/java/appeng/container/implementations/CellWorkbenchContainer.java +++ b/src/main/java/appeng/container/implementations/CellWorkbenchContainer.java @@ -31,7 +31,6 @@ import net.minecraft.item.ItemStack; import net.minecraft.network.PacketByteBuf; import alexiil.mc.lib.attributes.item.impl.EmptyFixedItemInv; -import appeng.api.AEApi; import appeng.api.config.CopyMode; import appeng.api.config.FuzzyMode; import appeng.api.config.Settings; @@ -47,6 +46,7 @@ import appeng.container.guisync.GuiSync; import appeng.container.slot.FakeTypeOnlySlot; import appeng.container.slot.OptionalRestrictedInputSlot; import appeng.container.slot.RestrictedInputSlot; +import appeng.core.Api; import appeng.tile.misc.CellWorkbenchBlockEntity; import appeng.util.EnumCycler; import appeng.util.Platform; @@ -208,9 +208,9 @@ public class CellWorkbenchContainer extends UpgradeableContainer { final ItemStack is = this.getUpgradeable().getInventoryByName("cell").getInvStack(0); final IStorageChannel channel = is.getItem() instanceof IStorageCell ? ((IStorageCell) is.getItem()).getChannel() - : AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class); + : Api.instance().storage().getStorageChannel(IItemStorageChannel.class); - final IMEInventory cellInv = AEApi.instance().registries().cell().getCellInventory(is, null, channel); + final IMEInventory cellInv = Api.instance().registries().cell().getCellInventory(is, null, channel); Iterator i = new NullIterator<>(); if (cellInv != null) { diff --git a/src/main/java/appeng/container/implementations/ContainerHelper.java b/src/main/java/appeng/container/implementations/ContainerHelper.java index b1af6764c..abd618903 100644 --- a/src/main/java/appeng/container/implementations/ContainerHelper.java +++ b/src/main/java/appeng/container/implementations/ContainerHelper.java @@ -14,7 +14,6 @@ import net.minecraft.text.LiteralText; import net.minecraft.text.TranslatableText; import net.minecraft.world.World; -import appeng.api.AEApi; import appeng.api.config.SecurityPermissions; import appeng.api.features.IWirelessTermHandler; import appeng.api.implementations.guiobjects.IGuiItem; @@ -24,6 +23,7 @@ import appeng.api.parts.IPartHost; import appeng.container.AEBaseContainer; import appeng.container.ContainerLocator; import appeng.core.AELog; +import appeng.core.Api; import appeng.helpers.ICustomNameObject; import appeng.helpers.WirelessTerminalGuiObject; import appeng.util.Platform; @@ -212,7 +212,7 @@ public final class ContainerHelper { } if (interfaceClass.isAssignableFrom(WirelessTerminalGuiObject.class)) { - final IWirelessTermHandler wh = AEApi.instance().registries().wireless().getWirelessTerminalHandler(it); + final IWirelessTermHandler wh = Api.instance().registries().wireless().getWirelessTerminalHandler(it); if (wh != null) { return interfaceClass.cast(new WirelessTerminalGuiObject(wh, it, player, locator.getItemIndex())); } diff --git a/src/main/java/appeng/container/implementations/CraftConfirmContainer.java b/src/main/java/appeng/container/implementations/CraftConfirmContainer.java index e3f9c7144..b4f5841a5 100644 --- a/src/main/java/appeng/container/implementations/CraftConfirmContainer.java +++ b/src/main/java/appeng/container/implementations/CraftConfirmContainer.java @@ -38,7 +38,6 @@ import net.minecraft.text.LiteralText; import net.minecraft.util.Util; import net.minecraft.world.World; -import appeng.api.AEApi; import appeng.api.config.Actionable; import appeng.api.config.SecurityPermissions; import appeng.api.networking.IGrid; @@ -59,6 +58,7 @@ import appeng.container.ContainerLocator; import appeng.container.ContainerOpener; import appeng.container.guisync.GuiSync; import appeng.core.AELog; +import appeng.core.Api; import appeng.core.sync.network.NetworkHandler; import appeng.core.sync.packets.MEInventoryUpdatePacket; import appeng.helpers.WirelessTerminalGuiObject; @@ -198,7 +198,7 @@ public class CraftConfirmContainer extends AEBaseContainer { final MEInventoryUpdatePacket c = this.result.isSimulation() ? new MEInventoryUpdatePacket((byte) 2) : null; - final IItemList plan = AEApi.instance().storage() + final IItemList plan = Api.instance().storage() .getStorageChannel(IItemStorageChannel.class).createList(); this.result.populatePlan(plan); @@ -216,7 +216,7 @@ public class CraftConfirmContainer extends AEBaseContainer { final IStorageGrid sg = this.getGrid().getCache(IStorageGrid.class); final IMEInventory items = sg - .getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)); + .getInventory(Api.instance().storage().getStorageChannel(IItemStorageChannel.class)); IAEItemStack m = null; if (c != null && this.result.isSimulation()) { diff --git a/src/main/java/appeng/container/implementations/CraftingCPUContainer.java b/src/main/java/appeng/container/implementations/CraftingCPUContainer.java index e7e97781f..4b14736fb 100644 --- a/src/main/java/appeng/container/implementations/CraftingCPUContainer.java +++ b/src/main/java/appeng/container/implementations/CraftingCPUContainer.java @@ -28,7 +28,6 @@ import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.network.PacketByteBuf; import net.minecraft.text.Text; -import appeng.api.AEApi; import appeng.api.config.SecurityPermissions; import appeng.api.networking.IGrid; import appeng.api.networking.crafting.CraftingItemList; @@ -43,6 +42,7 @@ import appeng.api.storage.data.IItemList; import appeng.container.AEBaseContainer; import appeng.container.ContainerLocator; import appeng.container.guisync.GuiSync; +import appeng.core.Api; import appeng.core.sync.network.NetworkHandler; import appeng.core.sync.packets.ConfigValuePacket; import appeng.core.sync.packets.MEInventoryUpdatePacket; @@ -60,7 +60,7 @@ public class CraftingCPUContainer extends AEBaseContainer private static final ContainerHelper helper = new ContainerHelper<>( CraftingCPUContainer::new, CraftingBlockEntity.class, SecurityPermissions.CRAFT); - private final IItemList list = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class) + private final IItemList list = Api.instance().storage().getStorageChannel(IItemStorageChannel.class) .createList(); private IGrid network; private CraftingCPUCluster monitor = null; diff --git a/src/main/java/appeng/container/implementations/InscriberContainer.java b/src/main/java/appeng/container/implementations/InscriberContainer.java index d33ce3e10..93261afe6 100644 --- a/src/main/java/appeng/container/implementations/InscriberContainer.java +++ b/src/main/java/appeng/container/implementations/InscriberContainer.java @@ -26,13 +26,13 @@ import net.minecraft.item.ItemStack; import net.minecraft.network.PacketByteBuf; import alexiil.mc.lib.attributes.item.FixedItemInv; -import appeng.api.AEApi; import appeng.api.definitions.IItemDefinition; import appeng.container.ContainerLocator; import appeng.container.guisync.GuiSync; import appeng.container.interfaces.IProgressProvider; import appeng.container.slot.OutputSlot; import appeng.container.slot.RestrictedInputSlot; +import appeng.core.Api; import appeng.tile.misc.InscriberRecipes; import appeng.tile.misc.InscriberBlockEntity; import appeng.util.Platform; @@ -131,7 +131,7 @@ public class InscriberContainer extends UpgradeableContainer implements IProgres final ItemStack bot = this.ti.getInternalInventory().getInvStack(1); if (s == this.middle) { - IItemDefinition press = AEApi.instance().definitions().materials().namePress(); + IItemDefinition press = Api.instance().definitions().materials().namePress(); if (press.isSameAs(top) || press.isSameAs(bot)) { return !press.isSameAs(is); } @@ -146,7 +146,7 @@ public class InscriberContainer extends UpgradeableContainer implements IProgres } // name presses - final IItemDefinition namePress = AEApi.instance().definitions().materials().namePress(); + final IItemDefinition namePress = Api.instance().definitions().materials().namePress(); if (namePress.isSameAs(otherSlot)) { return namePress.isSameAs(is); } diff --git a/src/main/java/appeng/container/implementations/MEMonitorableContainer.java b/src/main/java/appeng/container/implementations/MEMonitorableContainer.java index c439748e1..13a3cb9e8 100644 --- a/src/main/java/appeng/container/implementations/MEMonitorableContainer.java +++ b/src/main/java/appeng/container/implementations/MEMonitorableContainer.java @@ -32,7 +32,6 @@ import net.minecraft.item.ItemStack; import net.minecraft.network.PacketByteBuf; import net.minecraft.block.entity.BlockEntity; -import appeng.api.AEApi; import appeng.api.config.Actionable; import appeng.api.config.PowerMultiplier; import appeng.api.config.SecurityPermissions; @@ -67,6 +66,7 @@ import appeng.container.ContainerLocator; import appeng.container.guisync.GuiSync; import appeng.container.slot.RestrictedInputSlot; import appeng.core.AELog; +import appeng.core.Api; import appeng.core.sync.network.NetworkHandler; import appeng.core.sync.packets.ConfigValuePacket; import appeng.core.sync.packets.MEInventoryUpdatePacket; @@ -93,8 +93,8 @@ public class MEMonitorableContainer extends AEBaseContainer private final RestrictedInputSlot[] cellView = new RestrictedInputSlot[5]; private final IMEMonitor monitor; - private final IItemList items = AEApi.instance().storage() - .getStorageChannel(IItemStorageChannel.class).createList(); + private final IItemList items = Api.instance().storage().getStorageChannel(IItemStorageChannel.class) + .createList(); private final IConfigManager clientCM; private final ITerminalHost host; @GuiSync(99) @@ -126,7 +126,7 @@ public class MEMonitorableContainer extends AEBaseContainer this.serverCM = monitorable.getConfigManager(); this.monitor = monitorable - .getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)); + .getInventory(Api.instance().storage().getStorageChannel(IItemStorageChannel.class)); if (this.monitor != null) { this.monitor.addListener(this, null); @@ -185,7 +185,7 @@ public class MEMonitorableContainer extends AEBaseContainer public void sendContentUpdates() { if (Platform.isServer()) { if (this.monitor != this.host - .getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class))) { + .getInventory(Api.instance().storage().getStorageChannel(IItemStorageChannel.class))) { this.setValidContainer(false); } diff --git a/src/main/java/appeng/container/implementations/MolecularAssemblerContainer.java b/src/main/java/appeng/container/implementations/MolecularAssemblerContainer.java index 3bcbb6a0c..ca41d09ab 100644 --- a/src/main/java/appeng/container/implementations/MolecularAssemblerContainer.java +++ b/src/main/java/appeng/container/implementations/MolecularAssemblerContainer.java @@ -38,6 +38,7 @@ import appeng.container.slot.AppEngSlot; import appeng.container.slot.MolecularAssemblerPatternSlot; import appeng.container.slot.OutputSlot; import appeng.container.slot.RestrictedInputSlot; +import appeng.core.Api; import appeng.items.misc.EncodedPatternItem; import appeng.tile.crafting.MolecularAssemblerBlockEntity; import appeng.util.Platform; @@ -79,8 +80,7 @@ public class MolecularAssemblerContainer extends UpgradeableContainer implements if (is.getItem() instanceof EncodedPatternItem) { final World w = this.getBlockEntity().getWorld(); - final EncodedPatternItem iep = (EncodedPatternItem) is.getItem(); - final ICraftingPatternDetails ph = iep.getPatternForItem(is, w); + final ICraftingPatternDetails ph = Api.instance().crafting().decodePattern(is, w); if (ph.isCraftable()) { return ph.isValidItemForSlot(slotIndex, i, w); } diff --git a/src/main/java/appeng/container/implementations/NetworkStatusContainer.java b/src/main/java/appeng/container/implementations/NetworkStatusContainer.java index 46d00fe50..d1412a945 100644 --- a/src/main/java/appeng/container/implementations/NetworkStatusContainer.java +++ b/src/main/java/appeng/container/implementations/NetworkStatusContainer.java @@ -27,7 +27,6 @@ import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.network.PacketByteBuf; -import appeng.api.AEApi; import appeng.api.implementations.guiobjects.INetworkTool; import appeng.api.networking.IGrid; import appeng.api.networking.IGridBlock; @@ -41,6 +40,7 @@ import appeng.api.util.AEPartLocation; import appeng.container.AEBaseContainer; import appeng.container.ContainerLocator; import appeng.container.guisync.GuiSync; +import appeng.core.Api; import appeng.core.sync.network.NetworkHandler; import appeng.core.sync.packets.MEInventoryUpdatePacket; import appeng.util.Platform; @@ -115,7 +115,7 @@ public class NetworkStatusContainer extends AEBaseContainer { final MEInventoryUpdatePacket piu = new MEInventoryUpdatePacket(); for (final Class machineClass : this.network.getMachinesClasses()) { - final IItemList list = AEApi.instance().storage() + final IItemList list = Api.instance().storage() .getStorageChannel(IItemStorageChannel.class).createList(); for (final IGridNode machine : this.network.getMachines(machineClass)) { final IGridBlock blk = machine.getGridBlock(); diff --git a/src/main/java/appeng/container/implementations/PatternTermContainer.java b/src/main/java/appeng/container/implementations/PatternTermContainer.java index b949ed76d..4bb0ea76e 100644 --- a/src/main/java/appeng/container/implementations/PatternTermContainer.java +++ b/src/main/java/appeng/container/implementations/PatternTermContainer.java @@ -20,7 +20,6 @@ package appeng.container.implementations; import java.util.ArrayList; import java.util.List; -import java.util.Optional; import alexiil.mc.lib.attributes.item.FixedItemInv; import alexiil.mc.lib.attributes.item.compat.FixedInventoryVanillaWrapper; @@ -43,9 +42,9 @@ import net.minecraft.nbt.ListTag; import net.minecraft.network.PacketByteBuf; import net.minecraft.world.World; -import appeng.api.AEApi; import appeng.api.config.Actionable; import appeng.api.config.SecurityPermissions; +import appeng.api.crafting.ICraftingHelper; import appeng.api.definitions.IDefinitions; import appeng.api.storage.IMEMonitor; import appeng.api.storage.ITerminalHost; @@ -61,6 +60,7 @@ import appeng.container.slot.OptionalFakeSlot; import appeng.container.slot.PatternOutputsSlot; import appeng.container.slot.PatternTermSlot; import appeng.container.slot.RestrictedInputSlot; +import appeng.core.Api; import appeng.core.sync.packets.PatternSlotPacket; import appeng.helpers.IContainerCraftingPacket; import appeng.items.storage.ViewCellItem; @@ -99,6 +99,7 @@ public class PatternTermContainer extends MEMonitorableContainer private final PatternTermSlot craftSlot; private final RestrictedInputSlot patternSlotIN; private final RestrictedInputSlot patternSlotOUT; + private final ICraftingHelper craftingHelper = Api.INSTANCE.crafting(); private Recipe currentRecipe; @GuiSync(97) @@ -212,17 +213,17 @@ public class PatternTermContainer extends MEMonitorableContainer final ItemStack[] out = this.getOutputs(); // if there is no input, this would be silly. - if (in == null || out == null) { + if (in == null || out == null || isCraftingMode() && currentRecipe == null) { return; } // first check the output slots, should either be null, or a pattern - if (!output.isEmpty() && !this.isPattern(output)) { + if (!output.isEmpty() && !craftingHelper.isEncodedPattern(output)) { return; } // if nothing is there we should snag a new pattern. else if (output.isEmpty()) { output = this.patternSlotIN.getStack(); - if (output.isEmpty() || !this.isPattern(output)) { + if (output.isEmpty() || !isPattern(output)) { return; // no blanks. } @@ -232,34 +233,17 @@ public class PatternTermContainer extends MEMonitorableContainer this.patternSlotIN.setStack(ItemStack.EMPTY); } - // add a new encoded pattern. - Optional maybePattern = AEApi.instance().definitions().items().encodedPattern().maybeStack(1); - if (maybePattern.isPresent()) { - output = maybePattern.get(); - this.patternSlotOUT.setStack(output); - } + // let the crafting helper create a new encoded pattern + output = null; } - // encode the slot. - final CompoundTag encodedValue = new CompoundTag(); - - final ListTag tagIn = new ListTag(); - final ListTag tagOut = new ListTag(); - - for (final ItemStack i : in) { - tagIn.add(this.createItemTag(i)); + if (this.isCraftingMode()) { + output = craftingHelper.encodeCraftingPattern(output, this.currentRecipe, in, out[0], isSubstitute()); + } else { + output = craftingHelper.encodeProcessingPattern(output, in, out); } + this.patternSlotOUT.putStack(output); - for (final ItemStack i : out) { - tagOut.add(this.createItemTag(i)); - } - - encodedValue.put("in", tagIn); - encodedValue.put("out", tagOut); - encodedValue.putBoolean("crafting", this.isCraftingMode()); - encodedValue.putBoolean("substitute", this.isSubstitute()); - - output.setTag(encodedValue); } private ItemStack[] getInputs() { @@ -313,22 +297,8 @@ public class PatternTermContainer extends MEMonitorableContainer return false; } - final IDefinitions definitions = AEApi.instance().definitions(); - - boolean isPattern = definitions.items().encodedPattern().isSameAs(output); - isPattern |= definitions.materials().blankPattern().isSameAs(output); - - return isPattern; - } - - private Tag createItemTag(final ItemStack i) { - final CompoundTag c = new CompoundTag(); - - if (!i.isEmpty()) { - i.toTag(c); - } - - return c; + final IDefinitions definitions = Api.instance().definitions(); + return definitions.materials().blankPattern().isSameAs(output); } @Override @@ -386,7 +356,7 @@ public class PatternTermContainer extends MEMonitorableContainer } final IMEMonitor storage = this.getPatternTerminal() - .getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)); + .getInventory(Api.instance().storage().getStorageChannel(IItemStorageChannel.class)); final IItemList all = storage.getStorageList(); final ItemStack is = r.craft(ic); diff --git a/src/main/java/appeng/container/implementations/QuartzKnifeContainer.java b/src/main/java/appeng/container/implementations/QuartzKnifeContainer.java index ee0cff79b..b8dcebef1 100644 --- a/src/main/java/appeng/container/implementations/QuartzKnifeContainer.java +++ b/src/main/java/appeng/container/implementations/QuartzKnifeContainer.java @@ -28,11 +28,11 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.PacketByteBuf; -import appeng.api.AEApi; import appeng.container.AEBaseContainer; import appeng.container.ContainerLocator; import appeng.container.slot.OutputSlot; import appeng.container.slot.RestrictedInputSlot; +import appeng.core.Api; import appeng.items.contents.QuartzKnifeObj; import appeng.items.materials.MaterialItem; import appeng.tile.inventory.AppEngInternalInventory; @@ -113,7 +113,7 @@ public class QuartzKnifeContainer extends AEBaseContainer { if (RestrictedInputSlot.isMetalIngot(input)) { if (QuartzKnifeContainer.this.myName.length() > 0) { - return AEApi.instance().definitions().materials().namePress().maybeStack(1).map(namePressStack -> { + return Api.instance().definitions().materials().namePress().maybeStack(1).map(namePressStack -> { final CompoundTag compound = namePressStack.getOrCreateTag(); compound.putString(MaterialItem.TAG_INSCRIBE_NAME, QuartzKnifeContainer.this.myName); diff --git a/src/main/java/appeng/container/implementations/SecurityStationContainer.java b/src/main/java/appeng/container/implementations/SecurityStationContainer.java index f9c374b46..9d073632b 100644 --- a/src/main/java/appeng/container/implementations/SecurityStationContainer.java +++ b/src/main/java/appeng/container/implementations/SecurityStationContainer.java @@ -26,7 +26,6 @@ import net.minecraft.item.ItemStack; import net.minecraft.network.PacketByteBuf; import alexiil.mc.lib.attributes.item.FixedItemInv; -import appeng.api.AEApi; import appeng.api.config.SecurityPermissions; import appeng.api.features.INetworkEncodable; import appeng.api.features.IWirelessTermHandler; @@ -36,6 +35,7 @@ import appeng.container.ContainerLocator; import appeng.container.guisync.GuiSync; import appeng.container.slot.OutputSlot; import appeng.container.slot.RestrictedInputSlot; +import appeng.core.Api; import appeng.tile.inventory.AppEngInternalInventory; import appeng.tile.misc.SecurityStationBlockEntity; import appeng.util.inv.IAEAppEngInventory; @@ -150,7 +150,7 @@ public class SecurityStationContainer extends MEMonitorableContainer implements networkEncodable = (INetworkEncodable) term.getItem(); } - final IWirelessTermHandler wTermHandler = AEApi.instance().registries().wireless() + final IWirelessTermHandler wTermHandler = Api.instance().registries().wireless() .getWirelessTerminalHandler(term); if (wTermHandler != null) { networkEncodable = wTermHandler; diff --git a/src/main/java/appeng/container/implementations/StorageBusContainer.java b/src/main/java/appeng/container/implementations/StorageBusContainer.java index 67ed5830c..215a4a77a 100644 --- a/src/main/java/appeng/container/implementations/StorageBusContainer.java +++ b/src/main/java/appeng/container/implementations/StorageBusContainer.java @@ -27,7 +27,6 @@ import net.minecraft.screen.ScreenHandlerType; import net.minecraft.item.ItemStack; import net.minecraft.network.PacketByteBuf; -import appeng.api.AEApi; import appeng.api.config.AccessRestriction; import appeng.api.config.FuzzyMode; import appeng.api.config.SecurityPermissions; @@ -43,6 +42,7 @@ import appeng.container.guisync.GuiSync; import appeng.container.slot.FakeTypeOnlySlot; import appeng.container.slot.OptionalTypeOnlyFakeSlot; import appeng.container.slot.RestrictedInputSlot; +import appeng.core.Api; import appeng.parts.misc.StorageBusPart; import appeng.util.Platform; import appeng.util.helpers.ItemHandlerUtil; @@ -155,7 +155,7 @@ public class StorageBusContainer extends UpgradeableContainer { Iterator i = new NullIterator<>(); if (cellInv != null) { final IItemList list = cellInv.getAvailableItems( - AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList()); + Api.instance().storage().getStorageChannel(IItemStorageChannel.class).createList()); i = list.iterator(); } diff --git a/src/main/java/appeng/container/slot/CraftingTermSlot.java b/src/main/java/appeng/container/slot/CraftingTermSlot.java index add0f87d3..14d6adccd 100644 --- a/src/main/java/appeng/container/slot/CraftingTermSlot.java +++ b/src/main/java/appeng/container/slot/CraftingTermSlot.java @@ -33,7 +33,6 @@ import net.minecraft.util.collection.DefaultedList; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; -import appeng.api.AEApi; import appeng.api.config.Actionable; import appeng.api.networking.energy.IEnergySource; import appeng.api.networking.security.IActionSource; @@ -44,6 +43,7 @@ import appeng.api.storage.data.IAEItemStack; import appeng.api.storage.data.IItemList; import appeng.container.ContainerNull; import appeng.container.implementations.CraftingTermContainer; +import appeng.core.Api; import appeng.helpers.IContainerCraftingPacket; import appeng.helpers.InventoryAction; import appeng.items.storage.ViewCellItem; @@ -100,7 +100,7 @@ public class CraftingTermSlot extends AppEngCraftingSlot { } final IMEMonitor inv = this.storage - .getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)); + .getInventory(Api.instance().storage().getStorageChannel(IItemStorageChannel.class)); final int howManyPerCraft = this.getStack().getCount(); int maxTimesToCraft = 0; diff --git a/src/main/java/appeng/container/slot/PatternTermSlot.java b/src/main/java/appeng/container/slot/PatternTermSlot.java index 3311ee62c..25951bb15 100644 --- a/src/main/java/appeng/container/slot/PatternTermSlot.java +++ b/src/main/java/appeng/container/slot/PatternTermSlot.java @@ -22,11 +22,11 @@ import alexiil.mc.lib.attributes.item.FixedItemInv; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; -import appeng.api.AEApi; import appeng.api.networking.energy.IEnergySource; import appeng.api.networking.security.IActionSource; import appeng.api.storage.IStorageMonitorable; import appeng.api.storage.channels.IItemStorageChannel; +import appeng.core.Api; import appeng.core.sync.BasePacket; import appeng.core.sync.packets.PatternSlotPacket; import appeng.helpers.IContainerCraftingPacket; @@ -48,7 +48,7 @@ public class PatternTermSlot extends CraftingTermSlot { public BasePacket getRequest(final boolean shift) { return new PatternSlotPacket(this.getPattern(), - AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createStack(this.getStack()), + Api.instance().storage().getStorageChannel(IItemStorageChannel.class).createStack(this.getStack()), shift); } diff --git a/src/main/java/appeng/container/slot/RestrictedInputSlot.java b/src/main/java/appeng/container/slot/RestrictedInputSlot.java index 4b5d293b1..49bfaa68e 100644 --- a/src/main/java/appeng/container/slot/RestrictedInputSlot.java +++ b/src/main/java/appeng/container/slot/RestrictedInputSlot.java @@ -35,18 +35,18 @@ import net.minecraft.tag.Tag; import net.minecraft.util.Identifier; import net.minecraft.world.World; -import appeng.api.AEApi; +import appeng.api.crafting.ICraftingHelper; import appeng.api.definitions.IDefinitions; import appeng.api.definitions.IItems; import appeng.api.definitions.IMaterials; import appeng.api.features.INetworkEncodable; -import appeng.api.implementations.ICraftingPatternItem; import appeng.api.implementations.items.IBiometricCard; import appeng.api.implementations.items.ISpatialStorageCell; import appeng.api.implementations.items.IStorageComponent; import appeng.api.implementations.items.IUpgradeModule; import appeng.api.networking.crafting.ICraftingPatternDetails; import appeng.api.storage.cells.ICellWorkbenchItem; +import appeng.core.Api; import appeng.items.misc.EncodedPatternItem; import appeng.recipes.handlers.GrinderRecipes; import appeng.tile.misc.InscriberRecipes; @@ -90,10 +90,7 @@ public class RestrictedInputSlot extends AppEngSlot { public boolean isValid(final ItemStack is, final World theWorld) { if (this.which == PlacableItemType.VALID_ENCODED_PATTERN_W_OUTPUT) { - final ICraftingPatternDetails ap = is.getItem() instanceof ICraftingPatternItem - ? ((ICraftingPatternItem) is.getItem()).getPatternForItem(is, theWorld) - : null; - return ap != null; + return Api.instance().crafting().decodePattern(is, theWorld) != null; } return true; } @@ -125,42 +122,27 @@ public class RestrictedInputSlot extends AppEngSlot { return false; } - final IDefinitions definitions = AEApi.instance().definitions(); + final IDefinitions definitions = Api.instance().definitions(); final IMaterials materials = definitions.materials(); final IItems items = definitions.items(); + final ICraftingHelper crafting = Api.instance().crafting(); switch (this.which) { case ENCODED_CRAFTING_PATTERN: - if (i.getItem() instanceof ICraftingPatternItem) { - final ICraftingPatternItem b = (ICraftingPatternItem) i.getItem(); - final ICraftingPatternDetails de = b.getPatternForItem(i, this.p.player.world); - if (de != null) { - return de.isCraftable(); - } + final ICraftingPatternDetails de = crafting.decodePattern(i, this.p.player.world); + if (de != null) { + return de.isCraftable(); } return false; case VALID_ENCODED_PATTERN_W_OUTPUT: case ENCODED_PATTERN_W_OUTPUT: - case ENCODED_PATTERN: { - if (i.getItem() instanceof ICraftingPatternItem) { - return true; - } - // ICraftingPatternDetails pattern = i.getItem() instanceof ICraftingPatternItem - // ? - // ((ICraftingPatternItem) - // i.getItem()).getPatternForItem( i ) : null; - return false;// pattern != null; - } + case ENCODED_PATTERN: + return crafting.isEncodedPattern(i); case BLANK_PATTERN: return materials.blankPattern().isSameAs(i); case PATTERN: - - if (i.getItem() instanceof ICraftingPatternItem) { - return true; - } - - return materials.blankPattern().isSameAs(i); + return materials.blankPattern().isSameAs(i) || crafting.isEncodedPattern(i); case INSCRIBER_PLATE: if (materials.namePress().isSameAs(i)) { @@ -197,14 +179,14 @@ public class RestrictedInputSlot extends AppEngSlot { return i.getItem() instanceof ISpatialStorageCell && ((ISpatialStorageCell) i.getItem()).isSpatialStorage(i); case STORAGE_CELLS: - return AEApi.instance().registries().cell().isCellHandled(i); + return Api.instance().registries().cell().isCellHandled(i); case WORKBENCH_CELL: return i.getItem() instanceof ICellWorkbenchItem && ((ICellWorkbenchItem) i.getItem()).isEditable(i); case STORAGE_COMPONENT: return i.getItem() instanceof IStorageComponent && ((IStorageComponent) i.getItem()).isStorageComponent(i); case TRASH: - if (AEApi.instance().registries().cell().isCellHandled(i)) { + if (Api.instance().registries().cell().isCellHandled(i)) { return false; } @@ -212,7 +194,7 @@ public class RestrictedInputSlot extends AppEngSlot { && ((IStorageComponent) i.getItem()).isStorageComponent(i)); case ENCODABLE_ITEM: return i.getItem() instanceof INetworkEncodable - || AEApi.instance().registries().wireless().isWirelessTerminal(i); + || Api.instance().registries().wireless().isWirelessTerminal(i); case BIOMETRIC_CARD: return i.getItem() instanceof IBiometricCard; case UPGRADES: diff --git a/src/main/java/appeng/core/AEConfig.java b/src/main/java/appeng/core/AEConfig.java index 30a1cf535..d99f6a9f6 100644 --- a/src/main/java/appeng/core/AEConfig.java +++ b/src/main/java/appeng/core/AEConfig.java @@ -99,6 +99,7 @@ public final class AEConfig { // Spatial IO/Dimension private double spatialPowerExponent; private double spatialPowerMultiplier; + private boolean spatialBlockTags; // Grindstone private float oreDoublePercentage; @@ -191,6 +192,7 @@ public final class AEConfig { this.spatialPowerMultiplier = commonConfig.spatialPowerMultiplier.get(); this.spatialPowerExponent = commonConfig.spatialPowerExponent.get(); + this.spatialBlockTags = commonConfig.spatialBlockTags.get(); this.craftingCalculationTimePerTick = commonConfig.craftingCalculationTimePerTick.get(); @@ -311,6 +313,10 @@ public final class AEConfig { return this.spatialPowerMultiplier; } + public boolean getSpatialBlockTags() { + return this.spatialBlockTags; + } + public float getOreDoublePercentage() { return this.oreDoublePercentage; } @@ -428,6 +434,7 @@ public final class AEConfig { // Spatial IO/Dimension public final DoubleOption spatialPowerExponent; public final DoubleOption spatialPowerMultiplier; + public final BooleanOption spatialBlockTags; // Grindstone public final DoubleOption oreDoublePercentage; @@ -504,6 +511,8 @@ public final class AEConfig { ConfigSection spatialio = root.subsection("spatialio"); this.spatialPowerMultiplier = spatialio.addDouble("spatialPowerMultiplier", 1250.0); this.spatialPowerExponent = spatialio.addDouble("spatialPowerExponent", 1.35); + this.spatialBlockTags = spatialio + .addBoolean("spatialBlockTags", false, "BE CAREFUL, CAN CORRUPT YOUR WORLD! Will use #spatial/whitelist as whitelist."); ConfigSection grindStone = root.subsection("GrindStone"); this.oreDoublePercentage = grindStone.addDouble("oreDoublePercentage", 90.0, 0.0, 100.0, "Chance to actually get an output with stacksize > 1."); diff --git a/src/main/java/appeng/core/AddonLoader.java b/src/main/java/appeng/core/AddonLoader.java new file mode 100644 index 000000000..5b1bdd662 --- /dev/null +++ b/src/main/java/appeng/core/AddonLoader.java @@ -0,0 +1,61 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2020, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +package appeng.core; + +import java.util.Collection; +import java.util.Objects; +import java.util.Set; + +import org.objectweb.asm.Type; + +import net.minecraftforge.fml.ModList; +import net.minecraftforge.forgespi.language.ModFileScanData; +import net.minecraftforge.forgespi.language.ModFileScanData.AnnotationData; + +import appeng.api.AEAddon; +import appeng.api.IAEAddon; +import appeng.api.IAppEngApi; + +/** + * Loads AE addons on startup and provides them with an {@link IAppEngApi} + * instance. + */ +class AddonLoader { + + public static void loadAddons(IAppEngApi api) { + final Type annotationType = Type.getType(AEAddon.class); + final Collection allScanData = ModList.get().getAllScanData(); + + allScanData.stream().map(ModFileScanData::getAnnotations).flatMap(Set::stream) + .filter(a -> Objects.equals(a.getAnnotationType(), annotationType)).map(AnnotationData::getMemberName) + .forEach(className -> { + try { + final Class clazz = Class.forName(className); + final Class instanceClass = clazz.asSubclass(IAEAddon.class); + final IAEAddon instance = instanceClass.newInstance(); + + instance.onAPIAvailable(api); + } catch (ClassNotFoundException | InstantiationException | IllegalAccessException + | LinkageError e) { + AELog.error("Failed to load: %s", className, e); + throw new RuntimeException(e); + } + }); + } +} diff --git a/src/main/java/appeng/core/Api.java b/src/main/java/appeng/core/Api.java index 633522d84..030dd0041 100644 --- a/src/main/java/appeng/core/Api.java +++ b/src/main/java/appeng/core/Api.java @@ -18,12 +18,15 @@ package appeng.core; +import appeng.api.AEAddon; import appeng.api.IAppEngApi; +import appeng.api.client.IClientHelper; +import appeng.api.crafting.ICraftingHelper; import appeng.api.features.IRegistryContainer; import appeng.api.networking.IGridHelper; import appeng.api.storage.IStorageHelper; -import appeng.api.util.IClientHelper; import appeng.core.api.ApiClientHelper; +import appeng.core.api.ApiCrafting; import appeng.core.api.ApiGrid; import appeng.core.api.ApiPart; import appeng.core.api.ApiStorage; @@ -31,14 +34,33 @@ import appeng.core.features.registries.PartModels; import appeng.core.features.registries.RegistryContainer; public final class Api implements IAppEngApi { + + /** + * While permitting public access, directly using {@link Api#instance()} is not + * recommended except in very special cases. + */ public static Api INSTANCE; + /** + * Use primarily to access the API. + * + * Using {@link IAppEngApi} intentionally to avoid using functionality not + * exposed by accident. + * + * In some cases we might have to access the API before it is announced via + * {@link AEAddon}, otherwise we could just inject it into AE2 itself. + */ + public static IAppEngApi instance() { + return INSTANCE; + } + private final ApiPart partHelper; private final IRegistryContainer registryContainer; private final IStorageHelper storageHelper; private final IGridHelper networkHelper; private final ApiDefinitions definitions; + private final ICraftingHelper craftingHelper; private final IClientHelper client; public Api() { @@ -47,7 +69,8 @@ public final class Api implements IAppEngApi { this.registryContainer = new RegistryContainer(); this.partHelper = new ApiPart(); this.definitions = new ApiDefinitions((PartModels) this.registryContainer.partModels()); - this.client = new ApiClientHelper(); + this.craftingHelper = new ApiCrafting(this.definitions); + this.client = new ApiClientHelper(this.definitions); } public PartModels getPartModels() { @@ -64,6 +87,11 @@ public final class Api implements IAppEngApi { return this.storageHelper; } + @Override + public ICraftingHelper crafting() { + return this.craftingHelper; + } + @Override public IGridHelper grid() { return this.networkHelper; diff --git a/src/main/java/appeng/core/api/ApiClientHelper.java b/src/main/java/appeng/core/api/ApiClientHelper.java index 65d02b65e..503a4fbd1 100644 --- a/src/main/java/appeng/core/api/ApiClientHelper.java +++ b/src/main/java/appeng/core/api/ApiClientHelper.java @@ -1,5 +1,6 @@ /* * This file is part of Applied Energistics 2. + * * Copyright (c) 2013 - 2020, AlgorithmX2, All rights reserved. * * Applied Energistics 2 is free software: you can redistribute it and/or modify @@ -23,14 +24,24 @@ import java.util.List; import net.minecraft.text.LiteralText; import net.minecraft.text.Text; +import appeng.api.client.ICellModelRegistry; +import appeng.api.client.IClientHelper; import appeng.api.config.IncludeExclude; import appeng.api.storage.cells.ICellInventory; import appeng.api.storage.cells.ICellInventoryHandler; import appeng.api.storage.data.IAEStack; -import appeng.api.util.IClientHelper; +import appeng.core.ApiDefinitions; +import appeng.core.api.client.ApiCellModelRegistry; import appeng.core.localization.GuiText; public class ApiClientHelper implements IClientHelper { + + private final ICellModelRegistry cells; + + public ApiClientHelper(ApiDefinitions definitions) { + this.cells = new ApiCellModelRegistry(definitions); + } + @Override public > void addCellInformation(ICellInventoryHandler handler, List lines) { @@ -65,4 +76,9 @@ public class ApiClientHelper implements IClientHelper { } + @Override + public ICellModelRegistry cells() { + return this.cells; + } + } \ No newline at end of file diff --git a/src/main/java/appeng/core/api/ApiCrafting.java b/src/main/java/appeng/core/api/ApiCrafting.java new file mode 100644 index 000000000..e4f710bc2 --- /dev/null +++ b/src/main/java/appeng/core/api/ApiCrafting.java @@ -0,0 +1,167 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2020, TeamAppliedEnergistics, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +package appeng.core.api; + +import java.util.List; + +import javax.annotation.Nullable; + +import com.google.common.base.Preconditions; + +import net.minecraft.inventory.CraftingInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.ICraftingRecipe; +import net.minecraft.item.crafting.IRecipe; +import net.minecraft.item.crafting.IRecipeType; +import net.minecraft.item.crafting.RecipeManager; +import net.minecraft.util.ResourceLocation; +import net.minecraft.world.World; + +import appeng.api.crafting.ICraftingHelper; +import appeng.api.definitions.IItemDefinition; +import appeng.api.networking.crafting.ICraftingPatternDetails; +import appeng.api.storage.channels.IItemStorageChannel; +import appeng.api.storage.data.IAEItemStack; +import appeng.container.ContainerNull; +import appeng.core.AELog; +import appeng.core.Api; +import appeng.core.ApiDefinitions; +import appeng.helpers.CraftingPatternDetails; +import appeng.items.misc.EncodedPatternItem; + +public class ApiCrafting implements ICraftingHelper { + + private final IItemDefinition encodedPattern; + + public ApiCrafting(ApiDefinitions definitions) { + this.encodedPattern = definitions.items().encodedPattern(); + } + + @Override + public boolean isEncodedPattern(@Nullable IAEItemStack item) { + return item != null && item.getItem() instanceof EncodedPatternItem; + } + + @Override + public boolean isEncodedPattern(ItemStack item) { + return !item.isEmpty() && item.getItem() instanceof EncodedPatternItem; + } + + @Override + public ItemStack encodeCraftingPattern(@Nullable ItemStack stack, ICraftingRecipe recipe, ItemStack[] in, + ItemStack out, boolean allowSubstitutes) { + if (stack == null) { + stack = encodedPattern.stack(1); + } else { + Preconditions.checkArgument(isEncodedPattern(stack)); + } + + EncodedPatternItem.encodeCraftingPattern(stack, in, new ItemStack[] { out }, recipe.getId(), allowSubstitutes); + return stack; + } + + @Override + public ItemStack encodeProcessingPattern(@Nullable ItemStack stack, ItemStack[] in, ItemStack[] out) { + if (stack == null) { + stack = encodedPattern.stack(1); + } else { + Preconditions.checkArgument(isEncodedPattern(stack)); + } + + EncodedPatternItem.encodeProcessingPattern(stack, in, out); + return stack; + } + + @Override + public ICraftingPatternDetails decodePattern(final ItemStack is, final World world, boolean autoRecovery) { + if (is == null || world == null) { + return null; + } + + EncodedPatternItem patternItem = getPatternItem(is); + if (patternItem == null || !patternItem.isEncodedPattern(is)) { + return null; + } + + // The recipe ids encoded in a pattern can go stale. This code attempts to find + // the new id + // based on the stored inputs/outputs if that happens. + ResourceLocation recipeId = patternItem.getCraftingRecipeId(is); + if (recipeId != null) { + IRecipe recipe = world.getRecipeManager().getRecipes(IRecipeType.CRAFTING).get(recipeId); + if (!(recipe instanceof ICraftingRecipe)) { + if (!autoRecovery || !attemptRecovery(patternItem, is, world)) { + return null; + } + } + } + + // We use the shared itemstack for an identity lookup. + IAEItemStack ais = Api.instance().storage().getStorageChannel(IItemStorageChannel.class).createStack(is); + + return new CraftingPatternDetails(ais, world); + } + + private boolean attemptRecovery(EncodedPatternItem patternItem, ItemStack itemStack, World world) { + + RecipeManager recipeManager = world.getRecipeManager(); + + List ingredients = patternItem.getIngredients(itemStack); + List products = patternItem.getProducts(itemStack); + if (ingredients.size() < 9 || products.size() < 1) { + return false; + } + + ResourceLocation currentRecipeId = patternItem.getCraftingRecipeId(itemStack); + + // Fill a crafting inventory with the ingredients to find a suitable recipe + CraftingInventory testInventory = new CraftingInventory(new ContainerNull(), 3, 3); + for (int x = 0; x < 9; x++) { + final IAEItemStack ais = ingredients.get(x); + final ItemStack gs = ais != null ? ais.createItemStack() : ItemStack.EMPTY; + testInventory.setInventorySlotContents(x, gs); + } + + ICraftingRecipe potentialRecipe = recipeManager.getRecipe(IRecipeType.CRAFTING, testInventory, world) + .orElse(null); + + if (potentialRecipe != null) { + // Check that it matches the expected output + if (products.get(0).isSameType(potentialRecipe.getCraftingResult(testInventory))) { + // Yay we found a match, reencode the pattern + AELog.debug("Re-Encoding pattern from %s -> %s", currentRecipeId, potentialRecipe.getId()); + ItemStack[] in = ingredients.stream().map(ais -> ais != null ? ais.createItemStack() : ItemStack.EMPTY) + .toArray(ItemStack[]::new); + ItemStack out = products.get(0).createItemStack(); + encodeCraftingPattern(itemStack, potentialRecipe, in, out, patternItem.allowsSubstitution(itemStack)); + } + } + + AELog.debug("Failed to recover encoded crafting pattern for recipe %s", currentRecipeId); + return false; + } + + private static EncodedPatternItem getPatternItem(ItemStack itemStack) { + if (itemStack.getItem() instanceof EncodedPatternItem) { + return (EncodedPatternItem) itemStack.getItem(); + } + return null; + } + +} diff --git a/src/main/java/appeng/core/api/client/ApiCellModelRegistry.java b/src/main/java/appeng/core/api/client/ApiCellModelRegistry.java new file mode 100644 index 000000000..837b61970 --- /dev/null +++ b/src/main/java/appeng/core/api/client/ApiCellModelRegistry.java @@ -0,0 +1,119 @@ +/* + * This file is part of Applied Energistics 2. + * + * Copyright (c) 2020, TeamAppliedEnergistics, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +package appeng.core.api.client; + +import java.util.Arrays; +import java.util.Collections; +import java.util.IdentityHashMap; +import java.util.Map; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import com.google.common.base.Preconditions; + +import net.minecraft.item.Item; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.client.model.ModelLoader; + +import appeng.api.client.ICellModelRegistry; +import appeng.core.ApiDefinitions; + +public class ApiCellModelRegistry implements ICellModelRegistry { + + private static final ResourceLocation MODEL_BASE = new ResourceLocation( + "appliedenergistics2:block/drive/drive_base"); + private static final ResourceLocation MODEL_CELL_EMPTY = new ResourceLocation( + "appliedenergistics2:block/drive/drive_cell_empty"); + private static final ResourceLocation MODEL_CELL_DEFAULT = new ResourceLocation( + "appliedenergistics2:block/drive/drive_cell"); + private static final ResourceLocation MODEL_CELL_ITEMS_1K = new ResourceLocation( + "appliedenergistics2:block/drive/cells/1k_item_cell"); + private static final ResourceLocation MODEL_CELL_ITEMS_4K = new ResourceLocation( + "appliedenergistics2:block/drive/cells/4k_item_cell"); + private static final ResourceLocation MODEL_CELL_ITEMS_16K = new ResourceLocation( + "appliedenergistics2:block/drive/cells/16k_item_cell"); + private static final ResourceLocation MODEL_CELL_ITEMS_64K = new ResourceLocation( + "appliedenergistics2:block/drive/cells/64k_item_cell"); + private static final ResourceLocation MODEL_CELL_FLUIDS_1K = new ResourceLocation( + "appliedenergistics2:block/drive/cells/1k_fluid_cell"); + private static final ResourceLocation MODEL_CELL_FLUIDS_4K = new ResourceLocation( + "appliedenergistics2:block/drive/cells/4k_fluid_cell"); + private static final ResourceLocation MODEL_CELL_FLUIDS_16K = new ResourceLocation( + "appliedenergistics2:block/drive/cells/16k_fluid_cell"); + private static final ResourceLocation MODEL_CELL_FLUIDS_64K = new ResourceLocation( + "appliedenergistics2:block/drive/cells/64k_fluid_cell"); + private static final ResourceLocation MODEL_CELL_CREATIVE = new ResourceLocation( + "appliedenergistics2:block/drive/cells/creative_cell"); + + private static final ResourceLocation[] MODELS = { MODEL_BASE, MODEL_CELL_EMPTY, MODEL_CELL_DEFAULT, + MODEL_CELL_ITEMS_1K, MODEL_CELL_ITEMS_4K, MODEL_CELL_ITEMS_16K, MODEL_CELL_ITEMS_64K, MODEL_CELL_FLUIDS_1K, + MODEL_CELL_FLUIDS_4K, MODEL_CELL_FLUIDS_16K, MODEL_CELL_FLUIDS_64K, MODEL_CELL_CREATIVE }; + + public static void registerModels() { + Arrays.stream(MODELS).forEach(ModelLoader::addSpecialModel); + } + + private final Map registry; + + public ApiCellModelRegistry(ApiDefinitions definitions) { + this.registry = new IdentityHashMap<>(); + this.registry.put(definitions.items().cell1k().item(), MODEL_CELL_ITEMS_1K); + this.registry.put(definitions.items().cell4k().item(), MODEL_CELL_ITEMS_4K); + this.registry.put(definitions.items().cell16k().item(), MODEL_CELL_ITEMS_16K); + this.registry.put(definitions.items().cell64k().item(), MODEL_CELL_ITEMS_64K); + this.registry.put(definitions.items().fluidCell1k().item(), MODEL_CELL_FLUIDS_1K); + this.registry.put(definitions.items().fluidCell4k().item(), MODEL_CELL_FLUIDS_4K); + this.registry.put(definitions.items().fluidCell16k().item(), MODEL_CELL_FLUIDS_16K); + this.registry.put(definitions.items().fluidCell64k().item(), MODEL_CELL_FLUIDS_64K); + this.registry.put(definitions.items().fluidCell64k().item(), MODEL_CELL_FLUIDS_64K); + this.registry.put(definitions.items().cellCreative().item(), MODEL_CELL_CREATIVE); + } + + @Override + public void registerModel(Item item, ResourceLocation model) { + Preconditions.checkNotNull(item); + Preconditions.checkNotNull(model); + Preconditions.checkArgument(!this.registry.containsKey(item), "Cannot register an item twice."); + + this.registry.put(item, model); + } + + @Override + @Nullable + public ResourceLocation model(@Nonnull Item item) { + Preconditions.checkNotNull(item); + + return this.registry.get(item); + } + + @Override + @Nonnull + public Map models() { + return Collections.unmodifiableMap(this.registry); + } + + @Override + @Nonnull + public ResourceLocation getDefaultModel() { + return MODEL_CELL_DEFAULT; + } + +} diff --git a/src/main/java/appeng/core/api/definitions/ApiBlocks.java b/src/main/java/appeng/core/api/definitions/ApiBlocks.java index 29d455518..694f756bf 100644 --- a/src/main/java/appeng/core/api/definitions/ApiBlocks.java +++ b/src/main/java/appeng/core/api/definitions/ApiBlocks.java @@ -45,6 +45,7 @@ import appeng.bootstrap.definitions.TileEntityDefinition; import appeng.client.render.crafting.CraftingCubeRendering; import appeng.client.render.model.AutoRotatingBakedModel; import appeng.client.render.spatial.SpatialPylonRendering; +import appeng.client.render.tesr.ChestTileEntityRenderer; import appeng.client.render.tesr.CrankTESR; import appeng.client.render.tesr.DriveLedTileEntityRenderer; import appeng.client.render.tesr.SkyChestTESR; @@ -362,7 +363,14 @@ public final class ApiBlocks implements IBlocks { }).build()) .rendering(new DriveRendering()).build(); this.chest = registry.block("chest", ChestBlock::new).features(AEFeature.STORAGE_CELLS, AEFeature.ME_CHEST) - .tileEntity(registry.tileEntity("chest", ChestBlockEntity.class, ChestBlockEntity::new).build()) + .tileEntity(registry.tileEntity("chest", ChestBlockEntity.class, ChestBlockEntity::new) + .rendering(new TileEntityRenderingCustomizer() { + @Override + @OnlyIn(Dist.CLIENT) + public void customize(TileEntityRendering rendering) { + rendering.tileEntityRenderer(ChestTileEntityRenderer::new); + } + }).build()) .rendering(new ChestRendering()).build(); this.iface = registry.block("interface", InterfaceBlock::new).features(AEFeature.INTERFACE) .tileEntity( diff --git a/src/main/java/appeng/core/api/definitions/ApiParts.java b/src/main/java/appeng/core/api/definitions/ApiParts.java index 6dbb09604..625fd39f3 100644 --- a/src/main/java/appeng/core/api/definitions/ApiParts.java +++ b/src/main/java/appeng/core/api/definitions/ApiParts.java @@ -36,13 +36,50 @@ import appeng.core.features.ActivityState; import appeng.core.features.ColoredItemDefinition; import appeng.core.features.ItemStackSrc; import appeng.core.features.registries.PartModels; +import appeng.fluids.parts.FluidAnnihilationPlanePart; +import appeng.fluids.parts.FluidExportBusPart; +import appeng.fluids.parts.FluidFormationPlanePart; +import appeng.fluids.parts.FluidImportBusPart; +import appeng.fluids.parts.FluidInterfacePart; +import appeng.fluids.parts.FluidLevelEmitterPart; +import appeng.fluids.parts.FluidStorageBusPart; +import appeng.fluids.parts.FluidTerminalPart; import appeng.items.parts.ColoredPartItem; import appeng.items.parts.PartItem; import appeng.items.parts.PartItemRendering; import appeng.items.parts.PartModelsHelper; -import appeng.parts.misc.*; -import appeng.parts.networking.*; -import appeng.parts.reporting.*; +import appeng.parts.automation.AnnihilationPlanePart; +import appeng.parts.automation.ExportBusPart; +import appeng.parts.automation.FormationPlanePart; +import appeng.parts.automation.IdentityAnnihilationPlanePart; +import appeng.parts.automation.ImportBusPart; +import appeng.parts.automation.LevelEmitterPart; +import appeng.parts.misc.CableAnchorPart; +import appeng.parts.misc.InterfacePart; +import appeng.parts.misc.InvertedToggleBusPart; +import appeng.parts.misc.StorageBusPart; +import appeng.parts.misc.ToggleBusPart; +import appeng.parts.networking.CoveredCablePart; +import appeng.parts.networking.CoveredDenseCablePart; +import appeng.parts.networking.GlassCablePart; +import appeng.parts.networking.QuartzFiberPart; +import appeng.parts.networking.SmartCablePart; +import appeng.parts.networking.SmartDenseCablePart; +import appeng.parts.p2p.FEP2PTunnelPart; +import appeng.parts.p2p.FluidP2PTunnelPart; +import appeng.parts.p2p.ItemP2PTunnelPart; +import appeng.parts.p2p.LightP2PTunnelPart; +import appeng.parts.p2p.MEP2PTunnelPart; +import appeng.parts.p2p.RedstoneP2PTunnelPart; +import appeng.parts.reporting.ConversionMonitorPart; +import appeng.parts.reporting.CraftingTerminalPart; +import appeng.parts.reporting.DarkPanelPart; +import appeng.parts.reporting.InterfaceTerminalPart; +import appeng.parts.reporting.PanelPart; +import appeng.parts.reporting.PatternTerminalPart; +import appeng.parts.reporting.SemiDarkPanelPart; +import appeng.parts.reporting.StorageMonitorPart; +import appeng.parts.reporting.TerminalPart; /** * Internal implementation for the API parts diff --git a/src/main/java/appeng/core/features/registries/GridCacheRegistry.java b/src/main/java/appeng/core/features/registries/GridCacheRegistry.java index 520d06839..ead509589 100644 --- a/src/main/java/appeng/core/features/registries/GridCacheRegistry.java +++ b/src/main/java/appeng/core/features/registries/GridCacheRegistry.java @@ -29,7 +29,6 @@ import appeng.api.networking.IGrid; import appeng.api.networking.IGridCache; import appeng.api.networking.IGridCacheFactory; import appeng.api.networking.IGridCacheRegistry; -import appeng.core.AELog; public final class GridCacheRegistry implements IGridCacheRegistry { diff --git a/src/main/java/appeng/core/features/registries/MovableTileRegistry.java b/src/main/java/appeng/core/features/registries/MovableTileRegistry.java index 189159af5..1e81c015d 100644 --- a/src/main/java/appeng/core/features/registries/MovableTileRegistry.java +++ b/src/main/java/appeng/core/features/registries/MovableTileRegistry.java @@ -19,29 +19,45 @@ package appeng.core.features.registries; import java.util.ArrayList; -import java.util.HashMap; import java.util.HashSet; +import java.util.IdentityHashMap; import java.util.List; +import java.util.Map; +import java.util.Set; import net.minecraft.block.Block; +import net.minecraft.tags.BlockTags; +import net.minecraft.tags.Tag; import net.minecraft.block.entity.BlockEntity; +import net.minecraft.util.ResourceLocation; import appeng.api.exceptions.AppEngException; import appeng.api.movable.IMovableHandler; import appeng.api.movable.IMovableRegistry; import appeng.api.movable.IMovableTile; +import appeng.core.AEConfig; +import appeng.core.AppEng; import appeng.spatial.DefaultSpatialHandler; public class MovableTileRegistry implements IMovableRegistry { - private final HashSet blacklisted = new HashSet<>(); + private static final ResourceLocation TAG_WHITELIST = new ResourceLocation(AppEng.MOD_ID, "spatial/whitelist"); + private static final ResourceLocation TAG_BLACKLIST = new ResourceLocation(AppEng.MOD_ID, "spatial/blacklist"); - private final HashMap, IMovableHandler> Valid = new HashMap<>(); + private final Set blacklisted = new HashSet<>(); + + private final Map, IMovableHandler> valid = new IdentityHashMap<>(); private final List> test = new ArrayList<>(); private final List handlers = new ArrayList<>(); private final DefaultSpatialHandler dsh = new DefaultSpatialHandler(); - private final IMovableHandler nullHandler = new DefaultSpatialHandler(); + private final Tag blockTagWhiteList; + private final Tag blockTagBlackList; + + public MovableTileRegistry() { + this.blockTagWhiteList = BlockTags.getCollection().getOrCreate(TAG_WHITELIST); + this.blockTagBlackList = BlockTags.getCollection().getOrCreate(TAG_BLACKLIST); + } @Override public void blacklistBlock(final Block blk) { @@ -60,8 +76,8 @@ public class MovableTileRegistry implements IMovableRegistry { @Override public boolean askToMove(final BlockEntity te) { - final Class myClass = te.getClass(); - IMovableHandler canMove = this.Valid.get(myClass); + final Class myClass = te.getClass(); + IMovableHandler canMove = this.valid.get(myClass); if (canMove == null) { canMove = this.testClass(myClass, te); @@ -79,7 +95,7 @@ public class MovableTileRegistry implements IMovableRegistry { return false; } - private IMovableHandler testClass(final Class myClass, final BlockEntity te) { + private IMovableHandler testClass(final Class myClass, final BlockEntity te) { IMovableHandler handler = null; // ask handlers... @@ -92,25 +108,32 @@ public class MovableTileRegistry implements IMovableRegistry { // if you have a handler your opted in if (handler != null) { - this.Valid.put(myClass, handler); + this.valid.put(myClass, handler); return handler; } // if your movable our opted in if (te instanceof IMovableTile) { - this.Valid.put(myClass, this.dsh); + this.valid.put(myClass, this.dsh); + return this.dsh; + } + + // if the block itself is via block tags + if (AEConfig.instance().getSpatialBlockTags() + && this.blockTagWhiteList.contains(te.getBlockState().getBlock())) { + this.valid.put(myClass, this.dsh); return this.dsh; } // if you are on the white list your opted in. for (final Class testClass : this.test) { if (testClass.isAssignableFrom(myClass)) { - this.Valid.put(myClass, this.dsh); + this.valid.put(myClass, this.dsh); return this.dsh; } } - this.Valid.put(myClass, this.nullHandler); + this.valid.put(myClass, this.nullHandler); return this.nullHandler; } @@ -129,8 +152,8 @@ public class MovableTileRegistry implements IMovableRegistry { @Override public IMovableHandler getHandler(final BlockEntity te) { - final Class myClass = te.getClass(); - final IMovableHandler h = this.Valid.get(myClass); + final Class myClass = te.getClass(); + final IMovableHandler h = this.valid.get(myClass); return h == null ? this.dsh : h; } @@ -141,6 +164,6 @@ public class MovableTileRegistry implements IMovableRegistry { @Override public boolean isBlacklisted(final Block blk) { - return this.blacklisted.contains(blk); + return this.blacklisted.contains(blk) || this.blockTagBlackList.contains(blk); } } diff --git a/src/main/java/appeng/core/features/registries/P2PTunnelRegistry.java b/src/main/java/appeng/core/features/registries/P2PTunnelRegistry.java index 6f9be252c..6097dca89 100644 --- a/src/main/java/appeng/core/features/registries/P2PTunnelRegistry.java +++ b/src/main/java/appeng/core/features/registries/P2PTunnelRegistry.java @@ -34,7 +34,6 @@ import net.minecraft.item.Items; import net.minecraft.util.math.Direction; import net.minecraft.util.Identifier; -import appeng.api.AEApi; import appeng.api.config.TunnelType; import appeng.api.definitions.IBlocks; import appeng.api.definitions.IDefinitions; @@ -43,6 +42,7 @@ import appeng.api.definitions.IParts; import appeng.api.features.IP2PTunnelRegistry; import appeng.api.util.AEColor; import net.minecraft.util.registry.Registry; +import appeng.core.Api; public final class P2PTunnelRegistry implements IP2PTunnelRegistry { private static final int INITIAL_CAPACITY = 40; @@ -53,7 +53,7 @@ public final class P2PTunnelRegistry implements IP2PTunnelRegistry { public void configure() { - final IDefinitions definitions = AEApi.instance().definitions(); + final IDefinitions definitions = Api.instance().definitions(); final IBlocks blocks = definitions.blocks(); final IParts parts = definitions.parts(); diff --git a/src/main/java/appeng/core/features/registries/WirelessRegistry.java b/src/main/java/appeng/core/features/registries/WirelessRegistry.java index db8ecc95e..1485525e8 100644 --- a/src/main/java/appeng/core/features/registries/WirelessRegistry.java +++ b/src/main/java/appeng/core/features/registries/WirelessRegistry.java @@ -27,10 +27,13 @@ import net.minecraft.util.Hand; import net.minecraft.util.Util; import net.minecraft.world.BlockView; -import appeng.api.AEApi; import appeng.api.features.ILocatable; import appeng.api.features.IWirelessTermHandler; import appeng.api.features.IWirelessTermRegistry; +import appeng.container.ContainerLocator; +import appeng.container.ContainerOpener; +import appeng.container.implementations.WirelessTermContainer; +import appeng.core.Api; import appeng.core.localization.PlayerMessages; import appeng.util.Platform; @@ -87,7 +90,7 @@ public final class WirelessRegistry implements IWirelessTermRegistry { } final long parsedKey = Long.parseLong(unparsedKey); - final ILocatable securityStation = AEApi.instance().registries().locatable().getLocatableBy(parsedKey); + final ILocatable securityStation = Api.instance().registries().locatable().getLocatableBy(parsedKey); if (securityStation == null) { player.sendSystemMessage(PlayerMessages.StationCanNotBeLocated.get(), Util.NIL_UUID); return; diff --git a/src/main/java/appeng/core/features/registries/WorldGenRegistry.java b/src/main/java/appeng/core/features/registries/WorldGenRegistry.java index 79b8bbbcc..8fa3a85ab 100644 --- a/src/main/java/appeng/core/features/registries/WorldGenRegistry.java +++ b/src/main/java/appeng/core/features/registries/WorldGenRegistry.java @@ -18,6 +18,12 @@ package appeng.core.features.registries; +import java.util.HashSet; + +import net.minecraft.util.ResourceLocation; +import net.minecraft.world.IWorld; +import net.minecraft.world.dimension.Dimension; + import appeng.api.features.IWorldGen; import net.minecraft.server.world.ServerWorld; import net.minecraft.util.Identifier; diff --git a/src/main/java/appeng/core/features/registries/cell/BasicItemCellGuiHandler.java b/src/main/java/appeng/core/features/registries/cell/BasicItemCellGuiHandler.java index b5982b34c..7498db9b5 100644 --- a/src/main/java/appeng/core/features/registries/cell/BasicItemCellGuiHandler.java +++ b/src/main/java/appeng/core/features/registries/cell/BasicItemCellGuiHandler.java @@ -8,7 +8,6 @@ import net.minecraft.block.entity.BlockEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; -import appeng.api.AEApi; import appeng.api.implementations.tiles.IChestOrDrive; import appeng.api.storage.IMEInventoryHandler; import appeng.api.storage.IStorageChannel; @@ -16,11 +15,15 @@ import appeng.api.storage.cells.ICellGuiHandler; import appeng.api.storage.cells.ICellHandler; import appeng.api.storage.channels.IItemStorageChannel; import appeng.api.storage.data.IAEStack; +import appeng.container.ContainerLocator; +import appeng.container.ContainerOpener; +import appeng.container.implementations.MEMonitorableContainer; +import appeng.core.Api; public class BasicItemCellGuiHandler implements ICellGuiHandler { @Override public > boolean isHandlerFor(final IStorageChannel channel) { - return channel == AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class); + return channel == Api.instance().storage().getStorageChannel(IItemStorageChannel.class); } @Override diff --git a/src/main/java/appeng/core/features/registries/cell/CreativeCellHandler.java b/src/main/java/appeng/core/features/registries/cell/CreativeCellHandler.java index 4afa69047..50cbbe15e 100644 --- a/src/main/java/appeng/core/features/registries/cell/CreativeCellHandler.java +++ b/src/main/java/appeng/core/features/registries/cell/CreativeCellHandler.java @@ -20,13 +20,13 @@ package appeng.core.features.registries.cell; import net.minecraft.item.ItemStack; -import appeng.api.AEApi; import appeng.api.storage.IStorageChannel; import appeng.api.storage.cells.CellState; import appeng.api.storage.cells.ICellHandler; import appeng.api.storage.cells.ICellInventoryHandler; import appeng.api.storage.cells.ISaveProvider; import appeng.api.storage.channels.IItemStorageChannel; +import appeng.core.Api; import appeng.items.storage.CreativeStorageCellItem; import appeng.me.storage.CreativeCellInventory; @@ -40,7 +40,7 @@ public final class CreativeCellHandler implements ICellHandler { @Override public ICellInventoryHandler getCellInventory(final ItemStack is, final ISaveProvider container, final IStorageChannel channel) { - if (channel == AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class) && !is.isEmpty() + if (channel == Api.instance().storage().getStorageChannel(IItemStorageChannel.class) && !is.isEmpty() && is.getItem() instanceof CreativeStorageCellItem) { return CreativeCellInventory.getCell(is); } diff --git a/src/main/java/appeng/core/sync/packets/BlockTransitionEffectPacket.java b/src/main/java/appeng/core/sync/packets/BlockTransitionEffectPacket.java index 23068ee70..46861f89e 100644 --- a/src/main/java/appeng/core/sync/packets/BlockTransitionEffectPacket.java +++ b/src/main/java/appeng/core/sync/packets/BlockTransitionEffectPacket.java @@ -101,6 +101,7 @@ public class BlockTransitionEffectPacket extends BasePacket { playBreakOrPickupSound(); } + @OnlyIn(Dist.CLIENT) private void spawnParticles() { EnergyParticleData data = new EnergyParticleData(false, direction); @@ -119,6 +120,7 @@ public class BlockTransitionEffectPacket extends BasePacket { } } + @OnlyIn(Dist.CLIENT) private void playBreakOrPickupSound() { SoundEvent soundEvent; diff --git a/src/main/java/appeng/core/sync/packets/ClickPacket.java b/src/main/java/appeng/core/sync/packets/ClickPacket.java index a76771760..c598cbad8 100644 --- a/src/main/java/appeng/core/sync/packets/ClickPacket.java +++ b/src/main/java/appeng/core/sync/packets/ClickPacket.java @@ -31,7 +31,6 @@ import net.minecraft.util.Hand; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; -import appeng.api.AEApi; import appeng.api.definitions.IComparableDefinition; import appeng.api.definitions.IItems; import appeng.api.implementations.items.IMemoryCard; @@ -40,6 +39,7 @@ import appeng.block.networking.CableBusBlock; import appeng.container.ContainerLocator; import appeng.container.ContainerOpener; import appeng.container.implementations.NetworkToolContainer; +import appeng.core.Api; import appeng.core.sync.BasePacket; import appeng.core.sync.network.INetworkInfo; import appeng.items.tools.NetworkToolItem; @@ -123,7 +123,7 @@ public class ClickPacket extends BasePacket { final BlockPos pos = new BlockPos(this.x, this.y, this.z); final ItemStack is = player.getStackInHand(hand); - final IItems items = AEApi.instance().definitions().items(); + final IItems items = Api.instance().definitions().items(); final IComparableDefinition maybeMemoryCard = items.memoryCard(); final IComparableDefinition maybeColorApplicator = items.colorApplicator(); diff --git a/src/main/java/appeng/core/sync/packets/CraftRequestPacket.java b/src/main/java/appeng/core/sync/packets/CraftRequestPacket.java index e080297c3..c24579998 100644 --- a/src/main/java/appeng/core/sync/packets/CraftRequestPacket.java +++ b/src/main/java/appeng/core/sync/packets/CraftRequestPacket.java @@ -101,7 +101,7 @@ public class CraftRequestPacket extends BasePacket { if (futureJob != null) { futureJob.cancel(true); } - AELog.debug(e); + AELog.info(e); } } } diff --git a/src/main/java/appeng/core/sync/packets/JEIRecipePacket.java b/src/main/java/appeng/core/sync/packets/JEIRecipePacket.java index 0812797a4..85f424a72 100644 --- a/src/main/java/appeng/core/sync/packets/JEIRecipePacket.java +++ b/src/main/java/appeng/core/sync/packets/JEIRecipePacket.java @@ -29,7 +29,6 @@ import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; import net.minecraft.network.PacketByteBuf; -import appeng.api.AEApi; import appeng.api.config.Actionable; import appeng.api.config.SecurityPermissions; import appeng.api.networking.IGrid; @@ -41,6 +40,7 @@ import appeng.api.networking.storage.IStorageGrid; import appeng.api.storage.IMEMonitor; import appeng.api.storage.channels.IItemStorageChannel; import appeng.api.storage.data.IAEItemStack; +import appeng.core.Api; import appeng.core.sync.BasePacket; import appeng.core.sync.network.INetworkInfo; import appeng.helpers.IContainerCraftingPacket; @@ -113,7 +113,7 @@ public class JEIRecipePacket extends BasePacket { if (inv != null && this.recipe != null && security != null) { final IMEMonitor storage = inv - .getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)); + .getInventory(Api.instance().storage().getStorageChannel(IItemStorageChannel.class)); final IPartitionList filter = ViewCellItem.createFilter(cct.getViewCells()); for (int x = 0; x < craftMatrix.getSlotCount(); x++) { diff --git a/src/main/java/appeng/core/sync/packets/PatternSlotPacket.java b/src/main/java/appeng/core/sync/packets/PatternSlotPacket.java index 18ff39281..daf74751a 100644 --- a/src/main/java/appeng/core/sync/packets/PatternSlotPacket.java +++ b/src/main/java/appeng/core/sync/packets/PatternSlotPacket.java @@ -25,10 +25,10 @@ import net.minecraft.entity.player.PlayerEntity; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.network.PacketByteBuf; -import appeng.api.AEApi; import appeng.api.storage.channels.IItemStorageChannel; import appeng.api.storage.data.IAEItemStack; import appeng.container.implementations.PatternTermContainer; +import appeng.core.Api; import appeng.core.sync.BasePacket; import appeng.core.sync.network.INetworkInfo; import appeng.util.item.AEItemStack; @@ -76,7 +76,7 @@ public class PatternSlotPacket extends BasePacket { this.writeItem(slotItem, data); for (int x = 0; x < 9; x++) { - this.pattern[x] = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class) + this.pattern[x] = Api.instance().storage().getStorageChannel(IItemStorageChannel.class) .createStack(pat.getInvStack(x)); this.writeItem(this.pattern[x], data); } diff --git a/src/main/java/appeng/crafting/CraftingJob.java b/src/main/java/appeng/crafting/CraftingJob.java index 45fbf7da9..73d19abbf 100644 --- a/src/main/java/appeng/crafting/CraftingJob.java +++ b/src/main/java/appeng/crafting/CraftingJob.java @@ -27,7 +27,6 @@ import net.minecraft.entity.player.PlayerEntity; import net.minecraft.nbt.CompoundTag; import net.minecraft.world.World; -import appeng.api.AEApi; import appeng.api.config.Actionable; import appeng.api.networking.IGrid; import appeng.api.networking.IGridHost; @@ -44,6 +43,7 @@ import appeng.api.storage.data.IAEItemStack; import appeng.api.storage.data.IItemList; import appeng.api.util.DimensionalCoord; import appeng.core.AELog; +import appeng.core.Api; import appeng.hooks.TickHandler; public class CraftingJob implements Runnable, ICraftingJob { @@ -52,9 +52,9 @@ public class CraftingJob implements Runnable, ICraftingJob { private final MECraftingInventory original; private final World world; - private final IItemList crafting = AEApi.instance().storage() + private final IItemList crafting = Api.instance().storage() .getStorageChannel(IItemStorageChannel.class).createList(); - private final IItemList missing = AEApi.instance().storage() + private final IItemList missing = Api.instance().storage() .getStorageChannel(IItemStorageChannel.class).createList(); private final HashMap opsAndMultiplier = new HashMap<>(); private final Object monitor = new Object(); @@ -85,7 +85,7 @@ public class CraftingJob implements Runnable, ICraftingJob { final ICraftingGrid cc = grid.getCache(ICraftingGrid.class); final IStorageGrid sg = grid.getCache(IStorageGrid.class); this.original = new MECraftingInventory( - sg.getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)), actionSrc, + sg.getInventory(Api.instance().storage().getStorageChannel(IItemStorageChannel.class)), actionSrc, false, false, false); this.setTree(this.getCraftingTree(cc, what)); diff --git a/src/main/java/appeng/crafting/CraftingTreeNode.java b/src/main/java/appeng/crafting/CraftingTreeNode.java index 03c22dfa7..67b5382d1 100644 --- a/src/main/java/appeng/crafting/CraftingTreeNode.java +++ b/src/main/java/appeng/crafting/CraftingTreeNode.java @@ -26,7 +26,6 @@ import com.google.common.collect.Lists; import net.minecraft.world.World; -import appeng.api.AEApi; import appeng.api.config.Actionable; import appeng.api.config.FuzzyMode; import appeng.api.networking.crafting.ICraftingGrid; @@ -35,6 +34,7 @@ import appeng.api.networking.security.IActionSource; import appeng.api.storage.channels.IItemStorageChannel; import appeng.api.storage.data.IAEItemStack; import appeng.api.storage.data.IItemList; +import appeng.core.Api; import appeng.me.cluster.implementations.CraftingCPUCluster; public class CraftingTreeNode { @@ -42,7 +42,7 @@ public class CraftingTreeNode { // what slot! private final int slot; private final CraftingJob job; - private final IItemList used = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class) + private final IItemList used = Api.instance().storage().getStorageChannel(IItemStorageChannel.class) .createList(); // parent node. private final CraftingTreeProcess parent; diff --git a/src/main/java/appeng/crafting/CraftingTreeProcess.java b/src/main/java/appeng/crafting/CraftingTreeProcess.java index 9b8cc33a5..87495be59 100644 --- a/src/main/java/appeng/crafting/CraftingTreeProcess.java +++ b/src/main/java/appeng/crafting/CraftingTreeProcess.java @@ -27,6 +27,7 @@ import appeng.api.storage.channels.IItemStorageChannel; import appeng.api.storage.data.IAEItemStack; import appeng.api.storage.data.IItemList; import appeng.container.ContainerNull; +import appeng.core.Api; import appeng.me.cluster.implementations.CraftingCPUCluster; import appeng.util.Platform; import net.minecraft.inventory.CraftingInventory; @@ -179,7 +180,7 @@ public class CraftingTreeProcess { ItemStack is = ic.getStack(x); is = Platform.getRecipeRemainder(is); - final IAEItemStack o = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class) + final IAEItemStack o = Api.instance().storage().getStorageChannel(IItemStorageChannel.class) .createStack(is); if (o != null) { this.bytes++; @@ -194,7 +195,7 @@ public class CraftingTreeProcess { if (this.containerItems) { final ItemStack is = Platform.getRecipeRemainder(stack.createItemStack()); - final IAEItemStack o = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class) + final IAEItemStack o = Api.instance().storage().getStorageChannel(IItemStorageChannel.class) .createStack(is); if (o != null) { this.bytes++; diff --git a/src/main/java/appeng/crafting/MECraftingInventory.java b/src/main/java/appeng/crafting/MECraftingInventory.java index 87fe9db16..75ac570f0 100644 --- a/src/main/java/appeng/crafting/MECraftingInventory.java +++ b/src/main/java/appeng/crafting/MECraftingInventory.java @@ -18,7 +18,6 @@ package appeng.crafting; -import appeng.api.AEApi; import appeng.api.config.Actionable; import appeng.api.networking.security.IActionSource; import appeng.api.storage.IMEInventory; @@ -27,6 +26,7 @@ import appeng.api.storage.IStorageChannel; import appeng.api.storage.channels.IItemStorageChannel; import appeng.api.storage.data.IAEItemStack; import appeng.api.storage.data.IItemList; +import appeng.core.Api; import appeng.util.inv.ItemListIgnoreCrafting; public class MECraftingInventory implements IMEInventory { @@ -47,7 +47,7 @@ public class MECraftingInventory implements IMEInventory { public MECraftingInventory() { this.localCache = new ItemListIgnoreCrafting<>( - AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList()); + Api.instance().storage().getStorageChannel(IItemStorageChannel.class).createList()); this.extractedCache = null; this.injectedCache = null; this.missingCache = null; @@ -65,25 +65,25 @@ public class MECraftingInventory implements IMEInventory { this.logMissing = parent.logMissing; if (this.logMissing) { - this.missingCache = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList(); + this.missingCache = Api.instance().storage().getStorageChannel(IItemStorageChannel.class).createList(); } else { this.missingCache = null; } if (this.logExtracted) { - this.extractedCache = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList(); + this.extractedCache = Api.instance().storage().getStorageChannel(IItemStorageChannel.class).createList(); } else { this.extractedCache = null; } if (this.logInjections) { - this.injectedCache = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList(); + this.injectedCache = Api.instance().storage().getStorageChannel(IItemStorageChannel.class).createList(); } else { this.injectedCache = null; } this.localCache = this.target.getAvailableItems(new ItemListIgnoreCrafting<>( - AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList())); + Api.instance().storage().getStorageChannel(IItemStorageChannel.class).createList())); this.par = parent; } @@ -96,25 +96,25 @@ public class MECraftingInventory implements IMEInventory { this.logMissing = logMissing; if (logMissing) { - this.missingCache = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList(); + this.missingCache = Api.instance().storage().getStorageChannel(IItemStorageChannel.class).createList(); } else { this.missingCache = null; } if (logExtracted) { - this.extractedCache = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList(); + this.extractedCache = Api.instance().storage().getStorageChannel(IItemStorageChannel.class).createList(); } else { this.extractedCache = null; } if (logInjections) { - this.injectedCache = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList(); + this.injectedCache = Api.instance().storage().getStorageChannel(IItemStorageChannel.class).createList(); } else { this.injectedCache = null; } this.localCache = new ItemListIgnoreCrafting<>( - AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList()); + Api.instance().storage().getStorageChannel(IItemStorageChannel.class).createList()); for (final IAEItemStack is : target.getStorageList()) { this.localCache.add(target.extractItems(is, Actionable.SIMULATE, src)); } @@ -130,25 +130,25 @@ public class MECraftingInventory implements IMEInventory { this.logMissing = logMissing; if (logMissing) { - this.missingCache = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList(); + this.missingCache = Api.instance().storage().getStorageChannel(IItemStorageChannel.class).createList(); } else { this.missingCache = null; } if (logExtracted) { - this.extractedCache = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList(); + this.extractedCache = Api.instance().storage().getStorageChannel(IItemStorageChannel.class).createList(); } else { this.extractedCache = null; } if (logInjections) { - this.injectedCache = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList(); + this.injectedCache = Api.instance().storage().getStorageChannel(IItemStorageChannel.class).createList(); } else { this.injectedCache = null; } - this.localCache = target.getAvailableItems( - AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList()); + this.localCache = target + .getAvailableItems(Api.instance().storage().getStorageChannel(IItemStorageChannel.class).createList()); this.par = null; } @@ -214,7 +214,7 @@ public class MECraftingInventory implements IMEInventory { @Override public IStorageChannel getChannel() { - return AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class); + return Api.instance().storage().getStorageChannel(IItemStorageChannel.class); } public IItemList getItemList() { @@ -222,9 +222,9 @@ public class MECraftingInventory implements IMEInventory { } public boolean commit(final IActionSource src) { - final IItemList added = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class) + final IItemList added = Api.instance().storage().getStorageChannel(IItemStorageChannel.class) .createList(); - final IItemList pulled = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class) + final IItemList pulled = Api.instance().storage().getStorageChannel(IItemStorageChannel.class) .createList(); boolean failed = false; diff --git a/src/main/java/appeng/debug/ReplicatorCardItem.java b/src/main/java/appeng/debug/ReplicatorCardItem.java index 2a6887135..07fc51d8b 100644 --- a/src/main/java/appeng/debug/ReplicatorCardItem.java +++ b/src/main/java/appeng/debug/ReplicatorCardItem.java @@ -31,6 +31,7 @@ import net.minecraft.block.entity.BlockEntity; import net.minecraft.server.MinecraftServer; import net.minecraft.server.world.ServerWorld; import net.minecraft.util.ActionResult; +import net.minecraft.util.ActionResult; import net.minecraft.util.Identifier; import net.minecraft.util.Util; import net.minecraft.util.math.Direction; @@ -56,10 +57,31 @@ public class ReplicatorCardItem extends AEBaseItem implements AEToolItem { super(properties); } + @Override + public ActionResult onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) { + if (!worldIn.isRemote()) { + final CompoundNBT tag = playerIn.getHeldItem(handIn).getOrCreateTag(); + final int replications; + + if (tag.contains("r")) { + replications = (tag.getInt("r") + 1) % 4; + } else { + replications = 0; + } + + tag.putInt("r", replications); + + playerIn.sendMessage(new StringTextComponent((replications + 1) + "³ Replications")); + } + + return super.onItemRightClick(worldIn, playerIn, handIn); + } + @Override public ActionResult onItemUseFirst(ItemStack stack, ItemUsageContext context) { if (context.getWorld().isClient()) { - return ActionResult.PASS; + // Needed, otherwise client will trigger onItemRightClick also on server... + return ActionResult.SUCCESS; } PlayerEntity player = context.getPlayer(); @@ -78,13 +100,15 @@ public class ReplicatorCardItem extends AEBaseItem implements AEToolItem { if (player.isInSneakingPose()) { if (world.getBlockEntity(pos) instanceof IGridHost) { - final CompoundTag tag = new CompoundTag(); + final CompoundTag tag = player.getStackInHand(hand).getOrCreateTag(); tag.putInt("x", x); tag.putInt("y", y); tag.putInt("z", z); tag.putInt("side", side.ordinal()); tag.putString("w", world.getRegistryKey().getValue().toString()); - player.getStackInHand(hand).setTag(tag); + tag.putInt("r", 0); + + this.outputMsg(player, "Set replicator source"); } else { this.outputMsg(player, "This is not a Grid Tile."); } @@ -97,6 +121,7 @@ public class ReplicatorCardItem extends AEBaseItem implements AEToolItem { final int src_side = ish.getInt("side"); final String worldId = ish.getString("w"); final World src_w = world.getServer().getWorld(RegistryKey.of(Registry.DIMENSION, new Identifier(worldId))); + final int replications = ish.getInt("r") + 1; final BlockEntity te = src_w.getBlockEntity(new BlockPos(src_x, src_y, src_z)); if (te instanceof IGridHost) { @@ -104,50 +129,73 @@ public class ReplicatorCardItem extends AEBaseItem implements AEToolItem { final Direction sideOff = Direction.values()[src_side]; final Direction currentSideOff = side; final IGridNode n = gh.getGridNode(AEPartLocation.fromFacing(sideOff)); + if (n != null) { final IGrid g = n.getGrid(); + if (g != null) { final ISpatialCache sc = g.getCache(ISpatialCache.class); + if (sc.isValidRegion()) { final DimensionalCoord min = sc.getMin(); final DimensionalCoord max = sc.getMax(); - x += currentSideOff.getOffsetX(); - y += currentSideOff.getOffsetY(); - z += currentSideOff.getOffsetZ(); + // TODO: Why??? Places it one block up each time... + // x += currentSideOff.getOffsetX(); + // y += currentSideOff.getOffsetY(); + // z += currentSideOff.getOffsetZ(); + + final int sc_size_x = max.x - min.x; + final int sc_size_y = max.y - min.y; + final int sc_size_z = max.z - min.z; final int min_x = min.x; final int min_y = min.y; final int min_z = min.z; - final int rel_x = min.x - src_x + x; - final int rel_y = min.y - src_y + y; - final int rel_z = min.z - src_z + z; + // Invert to maintain correct sign for west/east + final int x_rot = (int) -Math.signum(MathHelper.wrapDegrees(player.rotationYaw)); + // Rotate by 90 degree, so north/south are negative/positive + final int z_rot = (int) Math.signum(MathHelper.wrapDegrees(player.rotationYaw + 90)); - final int scale_x = max.x - min.x; - final int scale_y = max.y - min.y; - final int scale_z = max.z - min.z; + // Loops for replication in each direction + for (int r_x = 0; r_x < replications; r_x++) { + for (int r_y = 0; r_y < replications; r_y++) { + for (int r_z = 0; r_z < replications; r_z++) { - for (int i = 1; i < scale_x; i++) { - for (int j = 1; j < scale_y; j++) { - for (int k = 1; k < scale_z; k++) { - final BlockPos p = new BlockPos(min_x + i, min_y + j, min_z + k); - final BlockPos d = new BlockPos(i + rel_x, j + rel_y, k + rel_z); - final BlockState state = src_w.getBlockState(p); - final Block blk = state.getBlock(); - final BlockState prev = world.getBlockState(d); + // Offset x/z by the rotation index. + // For sake of simplicity always grow upwards. + final int rel_x = min.x - src_x + x + (r_x * sc_size_x * x_rot); + final int rel_y = min.y - src_y + y + (r_y * sc_size_y); + final int rel_z = min.z - src_z + z + (r_z * sc_size_z * z_rot); - world.setBlockState(d, state); - if (blk instanceof BlockEntityProvider) { + // Copy a single SC instance completely + for (int i = 1; i < sc_size_x; i++) { + for (int j = 1; j < sc_size_y; j++) { + for (int k = 1; k < sc_size_z; k++) { + final BlockPos p = new BlockPos(min_x + i, min_y + j, + min_z + k); + final BlockPos d = new BlockPos(i + rel_x, j + rel_y, + k + rel_z); + + final BlockState state = src_w.getBlockState(p); + final Block blk = state.getBlock(); + final BlockState prev = world.getBlockState(d); + + world.setBlockState(d, state); + if (blk instanceof BlockEntityProvider) { BlockEntityProvider blkEntityProvider = (BlockEntityProvider)blk; - final BlockEntity ote = src_w.getBlockEntity(p); - final BlockEntity nte = blkEntityProvider.createBlockEntity(world); - final CompoundTag data = new CompoundTag(); - ote.toTag(data); - nte.fromTag(state, data.copy()); - world.setBlockEntity(d, nte); + final BlockEntity ote = src_w.getBlockEntity(p); + final BlockEntity nte = blkEntityProvider.createBlockEntity(world); + final CompoundTag data = new CompoundTag(); + ote.toTag(data); + nte.fromTag(state, data.copy()); + world.setBlockEntity(d, nte); + } + world.updateListeners(d, prev, state, 3); + } + } } - world.updateListeners(d, prev, state, 3); } } } diff --git a/src/main/java/appeng/entity/ChargedQuartzEntity.java b/src/main/java/appeng/entity/ChargedQuartzEntity.java index 10b4caf4c..930421f37 100644 --- a/src/main/java/appeng/entity/ChargedQuartzEntity.java +++ b/src/main/java/appeng/entity/ChargedQuartzEntity.java @@ -34,10 +34,11 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; import net.minecraft.world.World; -import appeng.api.AEApi; import appeng.api.definitions.IMaterials; import appeng.api.features.AEFeature; import appeng.core.AEConfig; +import appeng.core.Api; +import appeng.core.AppEng; import appeng.util.Platform; public final class ChargedQuartzEntity extends AEBaseItemEntity { @@ -92,7 +93,7 @@ public final class ChargedQuartzEntity extends AEBaseItemEntity { private boolean transform() { final ItemStack item = this.getStack(); - final IMaterials materials = AEApi.instance().definitions().materials(); + final IMaterials materials = Api.instance().definitions().materials(); if (materials.certusQuartzCrystalCharged().isSameAs(item)) { final Box region = new Box(this.getX() - 1, this.getY() - 1, this.getZ() - 1, diff --git a/src/main/java/appeng/entity/SingularityEntity.java b/src/main/java/appeng/entity/SingularityEntity.java index e4f173108..6cd54bbf0 100644 --- a/src/main/java/appeng/entity/SingularityEntity.java +++ b/src/main/java/appeng/entity/SingularityEntity.java @@ -27,17 +27,20 @@ import net.minecraft.entity.ItemEntity; import net.minecraft.entity.damage.DamageSource; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundTag; +import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.Box; import net.minecraft.world.World; -import appeng.api.AEApi; import appeng.api.definitions.IMaterials; import appeng.api.features.AEFeature; import appeng.core.AEConfig; +import appeng.core.Api; import appeng.util.Platform; public final class SingularityEntity extends AEBaseItemEntity { + private static final ResourceLocation TAG_ENDER_PEARL = new ResourceLocation("forge:ender_pearls"); + public static EntityType TYPE; private static int randTickSeed = 0; @@ -71,7 +74,7 @@ public final class SingularityEntity extends AEBaseItemEntity { final ItemStack item = this.getStack(); - final IMaterials materials = AEApi.instance().definitions().materials(); + final IMaterials materials = Api.instance().definitions().materials(); if (materials.singularity().isSameAs(item)) { final Box region = new Box(this.getX() - 4, this.getY() - 4, this.getZ() - 4, @@ -84,6 +87,17 @@ public final class SingularityEntity extends AEBaseItemEntity { if (!other.isEmpty()) { boolean matches = false; + if (materials.enderDust().isSameAs(other)) { + matches = true; + } + + // check... other name. + if (!matches) { + if (other.getItem().getTags().contains(TAG_ENDER_PEARL)) { + matches = true; + } + } + if (matches) { while (item.getCount() > 0 && other.getCount() > 0) { other.increment(-1); diff --git a/src/main/java/appeng/facade/FacadeContainer.java b/src/main/java/appeng/facade/FacadeContainer.java index 3c37ad005..0926dcace 100644 --- a/src/main/java/appeng/facade/FacadeContainer.java +++ b/src/main/java/appeng/facade/FacadeContainer.java @@ -26,11 +26,11 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.PacketByteBuf; -import appeng.api.AEApi; import appeng.api.parts.IFacadeContainer; import appeng.api.parts.IFacadePart; import appeng.api.parts.IPartHost; import appeng.api.util.AEPartLocation; +import appeng.core.Api; import appeng.items.parts.FacadeItem; import appeng.parts.CableBusStorage; @@ -110,7 +110,7 @@ public class FacadeContainer implements IFacadeContainer { if ((facadeSides & ix) == ix) { final int id = Math.abs(out.readInt()); - Optional maybeFacadeItem = AEApi.instance().definitions().items().facade() + Optional maybeFacadeItem = Api.instance().definitions().items().facade() .maybeItem(); if (maybeFacadeItem.isPresent()) { final FacadeItem ifa = (FacadeItem) maybeFacadeItem.get(); diff --git a/src/main/java/appeng/fluids/container/FluidStorageBusContainer.java b/src/main/java/appeng/fluids/container/FluidStorageBusContainer.java index 1384cade8..a0b55c5b1 100644 --- a/src/main/java/appeng/fluids/container/FluidStorageBusContainer.java +++ b/src/main/java/appeng/fluids/container/FluidStorageBusContainer.java @@ -26,7 +26,6 @@ import net.minecraft.screen.ScreenHandlerType; import net.minecraft.network.PacketByteBuf; import alexiil.mc.lib.attributes.item.FixedItemInv; -import appeng.api.AEApi; import appeng.api.config.AccessRestriction; import appeng.api.config.FuzzyMode; import appeng.api.config.SecurityPermissions; @@ -41,6 +40,7 @@ import appeng.container.ContainerLocator; import appeng.container.guisync.GuiSync; import appeng.container.implementations.ContainerHelper; import appeng.container.slot.RestrictedInputSlot; +import appeng.core.Api; import appeng.fluids.parts.FluidStorageBusPart; import appeng.fluids.util.IAEFluidTank; import appeng.util.Platform; @@ -162,7 +162,7 @@ public class FluidStorageBusContainer extends FluidConfigurableContainer { Iterator i = new NullIterator<>(); if (cellInv != null) { final IItemList list = cellInv.getAvailableItems( - AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class).createList()); + Api.instance().storage().getStorageChannel(IFluidStorageChannel.class).createList()); i = list.iterator(); } diff --git a/src/main/java/appeng/fluids/container/FluidTerminalContainer.java b/src/main/java/appeng/fluids/container/FluidTerminalContainer.java index ea903a5cd..e17808c2c 100644 --- a/src/main/java/appeng/fluids/container/FluidTerminalContainer.java +++ b/src/main/java/appeng/fluids/container/FluidTerminalContainer.java @@ -40,7 +40,6 @@ import net.minecraft.screen.ScreenHandlerType; import net.minecraft.item.ItemStack; import net.minecraft.network.PacketByteBuf; -import appeng.api.AEApi; import appeng.api.config.Actionable; import appeng.api.config.PowerMultiplier; import appeng.api.config.SecurityPermissions; @@ -70,6 +69,7 @@ import appeng.container.ContainerLocator; import appeng.container.guisync.GuiSync; import appeng.container.implementations.ContainerHelper; import appeng.core.AELog; +import appeng.core.Api; import appeng.core.sync.network.NetworkHandler; import appeng.core.sync.packets.ConfigValuePacket; import appeng.core.sync.packets.MEFluidInventoryUpdatePacket; @@ -104,7 +104,7 @@ public class FluidTerminalContainer extends AEBaseContainer private final IConfigManager clientCM; private final IMEMonitor monitor; - private final IItemList fluids = AEApi.instance().storage() + private final IItemList fluids = Api.instance().storage() .getStorageChannel(IFluidStorageChannel.class).createList(); @GuiSync(99) public boolean hasPower = false; @@ -126,7 +126,7 @@ public class FluidTerminalContainer extends AEBaseContainer if (Platform.isServer()) { this.serverCM = terminal.getConfigManager(); this.monitor = terminal - .getInventory(AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class)); + .getInventory(Api.instance().storage().getStorageChannel(IFluidStorageChannel.class)); if (this.monitor != null) { this.monitor.addListener(this, null); @@ -252,7 +252,7 @@ public class FluidTerminalContainer extends AEBaseContainer public void sendContentUpdates() { if (Platform.isServer()) { if (this.monitor != this.terminal - .getInventory(AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class))) { + .getInventory(Api.instance().storage().getStorageChannel(IFluidStorageChannel.class))) { this.setValidContainer(false); } diff --git a/src/main/java/appeng/fluids/helper/DualityFluidInterface.java b/src/main/java/appeng/fluids/helper/DualityFluidInterface.java index 3c3d6125c..56119f51b 100644 --- a/src/main/java/appeng/fluids/helper/DualityFluidInterface.java +++ b/src/main/java/appeng/fluids/helper/DualityFluidInterface.java @@ -26,7 +26,6 @@ import net.minecraft.nbt.CompoundTag; import net.minecraft.block.entity.BlockEntity; import alexiil.mc.lib.attributes.fluid.volume.FluidVolume; -import appeng.api.AEApi; import appeng.api.config.Actionable; import appeng.api.config.Settings; import appeng.api.config.Upgrades; @@ -53,6 +52,8 @@ import appeng.api.util.AECableType; import appeng.api.util.AEPartLocation; import appeng.api.util.DimensionalCoord; import appeng.api.util.IConfigManager; +import appeng.capabilities.Capabilities; +import appeng.core.Api; import appeng.core.settings.TickRates; import appeng.fluids.util.AEFluidInventory; import appeng.fluids.util.IAEFluidInventory; @@ -86,10 +87,9 @@ public class DualityFluidInterface private int priority; private final MEMonitorPassThrough items = new MEMonitorPassThrough<>( - new NullInventory(), AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)); + new NullInventory(), Api.instance().storage().getStorageChannel(IItemStorageChannel.class)); private final MEMonitorPassThrough fluids = new MEMonitorPassThrough<>( - new NullInventory(), - AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class)); + new NullInventory(), Api.instance().storage().getStorageChannel(IFluidStorageChannel.class)); public DualityFluidInterface(final AENetworkProxy networkProxy, final IFluidInterfaceHost ih) { this.gridProxy = networkProxy; @@ -120,13 +120,13 @@ public class DualityFluidInterface @Override public > IMEMonitor getInventory(IStorageChannel channel) { - if (channel == AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)) { + if (channel == Api.instance().storage().getStorageChannel(IItemStorageChannel.class)) { if (this.hasConfig()) { return null; } return (IMEMonitor) this.items; - } else if (channel == AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class)) { + } else if (channel == Api.instance().storage().getStorageChannel(IFluidStorageChannel.class)) { if (this.hasConfig()) { return (IMEMonitor) new InterfaceInventory(this); } @@ -180,9 +180,9 @@ public class DualityFluidInterface public void gridChanged() { try { this.items.setInternal(this.gridProxy.getStorage() - .getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class))); + .getInventory(Api.instance().storage().getStorageChannel(IItemStorageChannel.class))); this.fluids.setInternal(this.gridProxy.getStorage() - .getInventory(AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class))); + .getInventory(Api.instance().storage().getStorageChannel(IFluidStorageChannel.class))); } catch (final GridAccessException gae) { this.items.setInternal(new NullInventory()); this.fluids.setInternal(new NullInventory()); @@ -296,7 +296,7 @@ public class DualityFluidInterface boolean changed = false; try { final IMEInventory dest = this.gridProxy.getStorage() - .getInventory(AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class)); + .getInventory(Api.instance().storage().getStorageChannel(IFluidStorageChannel.class)); final IEnergySource src = this.gridProxy.getEnergy(); if (work.getStackSize() > 0) { diff --git a/src/main/java/appeng/fluids/helper/FluidCellConfig.java b/src/main/java/appeng/fluids/helper/FluidCellConfig.java index f3fa231b6..c0dfef9e4 100644 --- a/src/main/java/appeng/fluids/helper/FluidCellConfig.java +++ b/src/main/java/appeng/fluids/helper/FluidCellConfig.java @@ -24,7 +24,7 @@ import alexiil.mc.lib.attributes.fluid.FluidExtractable; import alexiil.mc.lib.attributes.fluid.amount.FluidAmount; import alexiil.mc.lib.attributes.fluid.volume.FluidVolume; import alexiil.mc.lib.attributes.item.filter.ItemFilter; -import appeng.api.AEApi; +import appeng.core.Api; import appeng.fluids.items.FluidDummyItem; import appeng.items.contents.CellConfig; import net.minecraft.item.ItemStack; @@ -57,7 +57,7 @@ public class FluidCellConfig extends CellConfig { fluid = fluid.withAmount(FluidAmount.BUCKET); - ItemStack is = AEApi.instance().definitions().items().dummyFluidItem().stack(1); + ItemStack is = Api.instance().definitions().items().dummyFluidItem().stack(1); FluidDummyItem item = (FluidDummyItem) is.getItem(); item.setFluidStack(is, fluid); return is; diff --git a/src/main/java/appeng/fluids/items/BasicFluidStorageCell.java b/src/main/java/appeng/fluids/items/BasicFluidStorageCell.java index 7aee0ec8a..8d2059b9d 100644 --- a/src/main/java/appeng/fluids/items/BasicFluidStorageCell.java +++ b/src/main/java/appeng/fluids/items/BasicFluidStorageCell.java @@ -22,10 +22,10 @@ import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import alexiil.mc.lib.attributes.item.FixedItemInv; -import appeng.api.AEApi; import appeng.api.storage.IStorageChannel; import appeng.api.storage.channels.IFluidStorageChannel; import appeng.api.storage.data.IAEFluidStack; +import appeng.core.Api; import appeng.fluids.helper.FluidCellConfig; import appeng.items.materials.MaterialType; import appeng.items.storage.AbstractStorageCell; @@ -79,7 +79,7 @@ public final class BasicFluidStorageCell extends AbstractStorageCell getChannel() { - return AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class); + return Api.instance().storage().getStorageChannel(IFluidStorageChannel.class); } @Override @@ -94,7 +94,7 @@ public final class BasicFluidStorageCell extends AbstractStorageCell { + Api.instance().definitions().materials().emptyStorageCell().maybeStack(1).ifPresent(is -> { final ItemStack extraA = ia.addItems(is); if (!extraA.isEmpty()) { player.dropItem(extraA, false); diff --git a/src/main/java/appeng/fluids/parts/FluidAnnihilationPlanePart.java b/src/main/java/appeng/fluids/parts/FluidAnnihilationPlanePart.java index 258ddffd8..1f4a99268 100644 --- a/src/main/java/appeng/fluids/parts/FluidAnnihilationPlanePart.java +++ b/src/main/java/appeng/fluids/parts/FluidAnnihilationPlanePart.java @@ -25,7 +25,6 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.BlockView; import net.minecraft.world.World; -import appeng.api.AEApi; import appeng.api.config.Actionable; import appeng.api.config.PowerMultiplier; import appeng.api.networking.IGridNode; @@ -47,6 +46,7 @@ import appeng.api.storage.channels.IFluidStorageChannel; import appeng.api.storage.data.IAEFluidStack; import appeng.api.util.AECableType; import appeng.api.util.AEPartLocation; +import appeng.core.Api; import appeng.core.AppEng; import appeng.core.settings.TickRates; import appeng.core.sync.packets.BlockTransitionEffectPacket; @@ -281,7 +281,7 @@ public class FluidAnnihilationPlanePart extends BasicStatePart implements IGridT try { final IStorageGrid storage = this.getProxy().getStorage(); final IMEInventory inv = storage - .getInventory(AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class)); + .getInventory(Api.instance().storage().getStorageChannel(IFluidStorageChannel.class)); if (modulate) { final IEnergyGrid energy = this.getProxy().getEnergy(); diff --git a/src/main/java/appeng/fluids/parts/FluidFormationPlanePart.java b/src/main/java/appeng/fluids/parts/FluidFormationPlanePart.java index ef56f9465..dd4f3cae3 100644 --- a/src/main/java/appeng/fluids/parts/FluidFormationPlanePart.java +++ b/src/main/java/appeng/fluids/parts/FluidFormationPlanePart.java @@ -23,6 +23,7 @@ import appeng.api.storage.data.IItemList; import appeng.api.util.AEPartLocation; import appeng.container.ContainerLocator; import appeng.container.ContainerOpener; +import appeng.core.Api; import appeng.fluids.container.FluidFormationPlaneContainer; import appeng.fluids.util.AEFluidInventory; import appeng.fluids.util.AEFluidStack; @@ -68,7 +69,7 @@ public class FluidFormationPlanePart extends AbstractFormationPlanePart myHandler = new MEInventoryHandler<>(this, - AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class)); + Api.instance().storage().getStorageChannel(IFluidStorageChannel.class)); private final AEFluidInventory config = new AEFluidInventory(this, 63); public FluidFormationPlanePart(final ItemStack is) { @@ -83,7 +84,7 @@ public class FluidFormationPlanePart extends AbstractFormationPlanePart 0 ? IncludeExclude.BLACKLIST : IncludeExclude.WHITELIST); this.myHandler.setPriority(this.getPriority()); - final IItemList priorityList = AEApi.instance().storage() + final IItemList priorityList = Api.instance().storage() .getStorageChannel(IFluidStorageChannel.class).createList(); final int slotsToUse = 18 + this.getInstalledUpgrades(Upgrades.CAPACITY) * 9; @@ -229,13 +230,13 @@ public class FluidFormationPlanePart extends AbstractFormationPlanePart getChannel() { - return AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class); + return Api.instance().storage().getStorageChannel(IFluidStorageChannel.class); } @Override public List getCellArray(final IStorageChannel channel) { if (this.getProxy().isActive() - && channel == AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class)) { + && channel == Api.instance().storage().getStorageChannel(IFluidStorageChannel.class)) { final List handler = new ArrayList<>(1); handler.add(this.myHandler); return handler; @@ -260,7 +261,7 @@ public class FluidFormationPlanePart extends AbstractFormationPlanePart, IBaseMo @Override public IStorageChannel getChannel() { - return AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class); + return Api.instance().storage().getStorageChannel(IFluidStorageChannel.class); } @Override diff --git a/src/main/java/appeng/fluids/parts/FluidInterfacePart.java b/src/main/java/appeng/fluids/parts/FluidInterfacePart.java index f0878a639..f8994a524 100644 --- a/src/main/java/appeng/fluids/parts/FluidInterfacePart.java +++ b/src/main/java/appeng/fluids/parts/FluidInterfacePart.java @@ -32,7 +32,6 @@ import net.minecraft.util.Identifier; import net.minecraft.util.math.Vec3d; import alexiil.mc.lib.attributes.item.FixedItemInv; -import appeng.api.AEApi; import appeng.api.config.Upgrades; import appeng.api.networking.IGridNode; import appeng.api.networking.events.MENetworkChannelsChanged; @@ -51,6 +50,7 @@ import appeng.api.util.AECableType; import appeng.api.util.IConfigManager; import appeng.container.ContainerLocator; import appeng.container.ContainerOpener; +import appeng.core.Api; import appeng.core.AppEng; import appeng.fluids.container.FluidInterfaceContainer; import appeng.fluids.helper.DualityFluidInterface; @@ -205,7 +205,7 @@ public class FluidInterfacePart extends BasicStatePart @Override public ItemStack getItemStackRepresentation() { - return AEApi.instance().definitions().parts().fluidIface().maybeStack(1).orElse(ItemStack.EMPTY); + return Api.instance().definitions().parts().fluidIface().maybeStack(1).orElse(ItemStack.EMPTY); } @Override diff --git a/src/main/java/appeng/fluids/parts/FluidLevelEmitterPart.java b/src/main/java/appeng/fluids/parts/FluidLevelEmitterPart.java index a87228ac2..ba3e67395 100644 --- a/src/main/java/appeng/fluids/parts/FluidLevelEmitterPart.java +++ b/src/main/java/appeng/fluids/parts/FluidLevelEmitterPart.java @@ -14,7 +14,6 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; -import appeng.api.AEApi; import appeng.api.config.RedstoneMode; import appeng.api.config.Settings; import appeng.api.networking.events.MENetworkChannelsChanged; @@ -38,6 +37,7 @@ import appeng.api.util.AEPartLocation; import appeng.api.util.IConfigManager; import appeng.container.ContainerLocator; import appeng.container.ContainerOpener; +import appeng.core.Api; import appeng.core.AppEng; import appeng.fluids.container.FluidLevelEmitterContainer; import appeng.fluids.util.AEFluidInventory; @@ -112,7 +112,7 @@ public class FluidLevelEmitterPart extends UpgradeablePart @Override public void onStackChange(IItemList o, IAEStack fullStack, IAEStack diffStack, IActionSource src, IStorageChannel chan) { - if (chan == AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class) + if (chan == Api.instance().storage().getStorageChannel(IFluidStorageChannel.class) && fullStack.equals(this.config.getFluidInSlot(0))) { this.lastReportedValue = fullStack.getStackSize(); this.updateState(); @@ -167,7 +167,7 @@ public class FluidLevelEmitterPart extends UpgradeablePart @Override public void onListUpdate() { try { - final IStorageChannel channel = AEApi.instance().storage() + final IStorageChannel channel = Api.instance().storage() .getStorageChannel(IFluidStorageChannel.class); final IMEMonitor inventory = this.getProxy().getStorage().getInventory(channel); @@ -189,7 +189,7 @@ public class FluidLevelEmitterPart extends UpgradeablePart } private void configureWatchers() { - final IFluidStorageChannel channel = AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class); + final IFluidStorageChannel channel = Api.instance().storage().getStorageChannel(IFluidStorageChannel.class); if (this.stackWatcher != null) { this.stackWatcher.reset(); diff --git a/src/main/java/appeng/fluids/parts/FluidStorageBusPart.java b/src/main/java/appeng/fluids/parts/FluidStorageBusPart.java index ea3f06cd3..4e886ac73 100644 --- a/src/main/java/appeng/fluids/parts/FluidStorageBusPart.java +++ b/src/main/java/appeng/fluids/parts/FluidStorageBusPart.java @@ -37,7 +37,6 @@ import net.minecraft.util.math.Direction; import net.minecraft.util.Hand; import net.minecraft.util.math.Vec3d; -import appeng.api.AEApi; import appeng.api.config.AccessRestriction; import appeng.api.config.FuzzyMode; import appeng.api.config.IncludeExclude; @@ -66,6 +65,7 @@ import appeng.api.util.AEPartLocation; import appeng.attributes.MEAttributes; import appeng.container.ContainerLocator; import appeng.container.ContainerOpener; +import appeng.core.Api; import appeng.core.AppEng; import appeng.core.settings.TickRates; import appeng.fluids.container.FluidStorageBusContainer; @@ -125,7 +125,7 @@ public class FluidStorageBusPart extends SharedStorageBusPart if (accessor != null) { IStorageMonitorable inventory = accessor.getInventory(this.source); if (inventory != null) { - return inventory.getInventory(AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class)); + return inventory.getInventory(Api.instance().storage().getStorageChannel(IFluidStorageChannel.class)); } // So this could / can be a design decision. If the tile does support our custom @@ -166,7 +166,7 @@ public class FluidStorageBusPart extends SharedStorageBusPart this.resetCacheLogic = 0; final IMEInventory in = this.getInternalHandler(); - IItemList before = AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class) + IItemList before = Api.instance().storage().getStorageChannel(IFluidStorageChannel.class) .createList(); if (in != null) { before = in.getAvailableItems(before); @@ -180,7 +180,7 @@ public class FluidStorageBusPart extends SharedStorageBusPart final IMEInventory out = this.getInternalHandler(); if (in != out) { - IItemList after = AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class) + IItemList after = Api.instance().storage().getStorageChannel(IFluidStorageChannel.class) .createList(); if (out != null) { after = out.getAvailableItems(after); @@ -247,7 +247,7 @@ public class FluidStorageBusPart extends SharedStorageBusPart try { if (this.getProxy().isActive()) { this.getProxy().getStorage().postAlterationOfStoredItems( - AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class), change, this.source); + Api.instance().storage().getStorageChannel(IFluidStorageChannel.class), change, this.source); } } catch (final GridAccessException e) { // :( @@ -284,14 +284,14 @@ public class FluidStorageBusPart extends SharedStorageBusPart this.checkInterfaceVsStorageBus(target, this.getSide().getOpposite()); this.handler = new MEInventoryHandler<>(inv, - AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class)); + Api.instance().storage().getStorageChannel(IFluidStorageChannel.class)); this.handler.setBaseAccess((AccessRestriction) this.getConfigManager().getSetting(Settings.ACCESS)); this.handler.setWhitelist(this.getInstalledUpgrades(Upgrades.INVERTER) > 0 ? IncludeExclude.BLACKLIST : IncludeExclude.WHITELIST); this.handler.setPriority(this.getPriority()); - final IItemList priorityList = AEApi.instance().storage() + final IItemList priorityList = Api.instance().storage() .getStorageChannel(IFluidStorageChannel.class).createList(); final int slotsToUse = 18 + this.getInstalledUpgrades(Upgrades.CAPACITY) * 9; @@ -407,7 +407,7 @@ public class FluidStorageBusPart extends SharedStorageBusPart @Override public IStorageChannel getStorageChannel() { - return AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class); + return Api.instance().storage().getStorageChannel(IFluidStorageChannel.class); } public IAEFluidTank getConfig() { @@ -428,7 +428,7 @@ public class FluidStorageBusPart extends SharedStorageBusPart @Override public ItemStack getItemStackRepresentation() { - return AEApi.instance().definitions().parts().fluidStorageBus().maybeStack(1).orElse(ItemStack.EMPTY); + return Api.instance().definitions().parts().fluidStorageBus().maybeStack(1).orElse(ItemStack.EMPTY); } @Override diff --git a/src/main/java/appeng/fluids/parts/SharedFluidBusPart.java b/src/main/java/appeng/fluids/parts/SharedFluidBusPart.java index be630bb7e..423865d2f 100644 --- a/src/main/java/appeng/fluids/parts/SharedFluidBusPart.java +++ b/src/main/java/appeng/fluids/parts/SharedFluidBusPart.java @@ -29,7 +29,6 @@ import net.minecraft.util.math.*; import net.minecraft.world.BlockView; import net.minecraft.world.World; -import appeng.api.AEApi; import appeng.api.config.RedstoneMode; import appeng.api.config.Upgrades; import appeng.api.networking.ticking.IGridTickable; @@ -39,6 +38,7 @@ import appeng.api.storage.channels.IFluidStorageChannel; import appeng.api.util.AECableType; import appeng.container.ContainerLocator; import appeng.container.ContainerOpener; +import appeng.core.Api; import appeng.fluids.container.FluidIOContainer; import appeng.fluids.util.AEFluidInventory; import appeng.fluids.util.IAEFluidTank; @@ -138,7 +138,7 @@ public abstract class SharedFluidBusPart extends UpgradeablePart implements IGri } protected IFluidStorageChannel getChannel() { - return AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class); + return Api.instance().storage().getStorageChannel(IFluidStorageChannel.class); } @Override diff --git a/src/main/java/appeng/fluids/registries/BasicFluidCellGuiHandler.java b/src/main/java/appeng/fluids/registries/BasicFluidCellGuiHandler.java index d84c4f203..999cf080f 100644 --- a/src/main/java/appeng/fluids/registries/BasicFluidCellGuiHandler.java +++ b/src/main/java/appeng/fluids/registries/BasicFluidCellGuiHandler.java @@ -22,7 +22,6 @@ import net.minecraft.block.entity.BlockEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; -import appeng.api.AEApi; import appeng.api.implementations.tiles.IChestOrDrive; import appeng.api.storage.IMEInventoryHandler; import appeng.api.storage.IStorageChannel; @@ -32,13 +31,14 @@ import appeng.api.storage.channels.IFluidStorageChannel; import appeng.api.storage.data.IAEStack; import appeng.container.ContainerLocator; import appeng.container.ContainerOpener; +import appeng.core.Api; import appeng.fluids.container.FluidTerminalContainer; public class BasicFluidCellGuiHandler implements ICellGuiHandler { @Override public > boolean isHandlerFor(final IStorageChannel channel) { - return channel == AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class); + return channel == Api.instance().storage().getStorageChannel(IFluidStorageChannel.class); } @Override diff --git a/src/main/java/appeng/fluids/tile/FluidInterfaceBlockEntity.java b/src/main/java/appeng/fluids/tile/FluidInterfaceBlockEntity.java index 2ee0e144e..634d976db 100644 --- a/src/main/java/appeng/fluids/tile/FluidInterfaceBlockEntity.java +++ b/src/main/java/appeng/fluids/tile/FluidInterfaceBlockEntity.java @@ -31,7 +31,6 @@ import net.minecraft.block.entity.BlockEntityType; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; -import appeng.api.AEApi; import appeng.api.config.Upgrades; import appeng.api.networking.IGridNode; import appeng.api.networking.events.MENetworkChannelsChanged; @@ -44,6 +43,7 @@ import appeng.api.util.AECableType; import appeng.api.util.AEPartLocation; import appeng.api.util.DimensionalCoord; import appeng.api.util.IConfigManager; +import appeng.core.Api; import appeng.fluids.container.FluidInterfaceContainer; import appeng.fluids.helper.DualityFluidInterface; import appeng.fluids.helper.IFluidInterfaceHost; @@ -155,7 +155,7 @@ public class FluidInterfaceBlockEntity extends AENetworkBlockEntity @Override public ItemStack getItemStackRepresentation() { - return AEApi.instance().definitions().blocks().fluidIface().maybeStack(1).orElse(ItemStack.EMPTY); + return Api.instance().definitions().blocks().fluidIface().maybeStack(1).orElse(ItemStack.EMPTY); } @Override diff --git a/src/main/java/appeng/fluids/util/AEFluidStack.java b/src/main/java/appeng/fluids/util/AEFluidStack.java index 739bb5ad0..bbf81e9b1 100644 --- a/src/main/java/appeng/fluids/util/AEFluidStack.java +++ b/src/main/java/appeng/fluids/util/AEFluidStack.java @@ -32,11 +32,11 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.PacketByteBuf; -import appeng.api.AEApi; import appeng.api.config.FuzzyMode; import appeng.api.storage.IStorageChannel; import appeng.api.storage.channels.IFluidStorageChannel; import appeng.api.storage.data.IAEFluidStack; +import appeng.core.Api; import appeng.fluids.items.FluidDummyItem; import appeng.util.Platform; import appeng.util.item.AEStack; @@ -152,19 +152,9 @@ public final class AEFluidStack extends AEStack implements IAEFlu return dup; } - @Override - public boolean isItem() { - return false; - } - - @Override - public boolean isFluid() { - return true; - } - @Override public IStorageChannel getChannel() { - return AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class); + return Api.instance().storage().getStorageChannel(IFluidStorageChannel.class); } @Override @@ -231,7 +221,7 @@ public final class AEFluidStack extends AEStack implements IAEFlu @Override public ItemStack asItemStackRepresentation() { - ItemStack is = AEApi.instance().definitions().items().dummyFluidItem().maybeStack(1).orElse(ItemStack.EMPTY); + ItemStack is = Api.instance().definitions().items().dummyFluidItem().maybeStack(1).orElse(ItemStack.EMPTY); if (!is.isEmpty()) { FluidDummyItem item = (FluidDummyItem) is.getItem(); item.setFluidStack(is, this.getFluidStack()); diff --git a/src/main/java/appeng/forge/data/providers/IAE2DataProvider.java b/src/main/java/appeng/forge/data/providers/IAE2DataProvider.java index 1be2c7878..9014ae257 100644 --- a/src/main/java/appeng/forge/data/providers/IAE2DataProvider.java +++ b/src/main/java/appeng/forge/data/providers/IAE2DataProvider.java @@ -2,13 +2,13 @@ package appeng.forge.data.providers; import net.minecraft.data.DataProvider; -import appeng.api.AEApi; import appeng.api.definitions.IBlocks; import appeng.api.definitions.IItems; import appeng.api.definitions.IMaterials; +import appeng.core.Api; public interface IAE2DataProvider extends DataProvider { - IBlocks BLOCKS = AEApi.instance().definitions().blocks(); - IItems ITEMS = AEApi.instance().definitions().items(); - IMaterials MATERIALS = AEApi.instance().definitions().materials(); + IBlocks BLOCKS = Api.instance().definitions().blocks(); + IItems ITEMS = Api.instance().definitions().items(); + IMaterials MATERIALS = Api.instance().definitions().materials(); } diff --git a/src/main/java/appeng/helpers/PatternHelper.java b/src/main/java/appeng/helpers/CraftingPatternDetails.java similarity index 79% rename from src/main/java/appeng/helpers/PatternHelper.java rename to src/main/java/appeng/helpers/CraftingPatternDetails.java index f36fad583..e1cc6ef8e 100644 --- a/src/main/java/appeng/helpers/PatternHelper.java +++ b/src/main/java/appeng/helpers/CraftingPatternDetails.java @@ -25,6 +25,8 @@ import java.util.List; import java.util.Map; import java.util.Set; +import com.google.common.base.Preconditions; + import net.minecraft.inventory.CraftingInventory; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -34,17 +36,16 @@ import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; import net.minecraft.world.World; -import appeng.api.AEApi; import appeng.api.networking.crafting.ICraftingPatternDetails; import appeng.api.storage.channels.IItemStorageChannel; import appeng.api.storage.data.IAEItemStack; import appeng.container.ContainerNull; +import appeng.core.Api; +import appeng.items.misc.EncodedPatternItem; import appeng.util.Platform; -import appeng.util.item.AEItemStack; -public class PatternHelper implements ICraftingPatternDetails, Comparable { +public class CraftingPatternDetails implements ICraftingPatternDetails, Comparable { - private final ItemStack patternItem; private final CraftingInventory crafting = new CraftingInventory(new ContainerNull(), 3, 3); private final CraftingInventory testFrame = new CraftingInventory(new ContainerNull(), 3, 3); private final ItemStack correctOutput; @@ -53,79 +54,73 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable failCache = new HashSet<>(); private final Set passCache = new HashSet<>(); private final IAEItemStack pattern; private int priority = 0; - public PatternHelper(final ItemStack is, final World w) { - final CompoundTag encodedValue = is.getTag(); + public CraftingPatternDetails(final IAEItemStack is, final World w) { + Preconditions.checkArgument(is.getItem() instanceof EncodedPatternItem, + "itemStack is not a ICraftingPatternItem"); - if (encodedValue == null) { - throw new IllegalArgumentException("No pattern here!"); - } + final EncodedPatternItem templateItem = (EncodedPatternItem) is.getItem(); + final ItemStack itemStack = is.createItemStack(); - final ListTag inTag = encodedValue.getList("in", 10); - final ListTag outTag = encodedValue.getList("out", 10); - this.isCrafting = encodedValue.getBoolean("crafting"); + final List ingredients = templateItem.getIngredients(itemStack); + final List products = templateItem.getProducts(itemStack); + final ResourceLocation recipeId = templateItem.getCraftingRecipeId(itemStack); - this.canSubstitute = this.isCrafting && encodedValue.getBoolean("substitute"); - this.patternItem = is; - this.pattern = AEItemStack.fromItemStack(is); + this.pattern = is.copy(); + this.isCraftable = recipeId != null; + this.canSubstitute = templateItem.allowsSubstitution(itemStack); final List in = new ArrayList<>(); final List out = new ArrayList<>(); - for (int x = 0; x < inTag.size(); x++) { - CompoundTag ingredient = inTag.getCompound(x); - final ItemStack gs = ItemStack.fromTag(ingredient); - - if (!ingredient.isEmpty() && gs.isEmpty()) { - throw new IllegalArgumentException("No pattern here!"); - } + for (int x = 0; x < 9; x++) { + final IAEItemStack ais = ingredients.get(x); + final ItemStack gs = ais != null ? ais.createItemStack() : ItemStack.EMPTY; this.crafting.setStack(x, gs); - if (!gs.isEmpty() && (!this.isCrafting || !gs.hasTag())) { + if (!gs.isEmpty() && (!this.isCraftable) || !gs.hasTag()) { this.markItemAs(x, gs, TestStatus.ACCEPT); } - in.add(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createStack(gs)); + in.add(ais != null ? ais.copy() : null); this.testFrame.setStack(x, gs); } - if (this.isCrafting) { - this.standardRecipe = w.getRecipeManager().getFirstMatch(RecipeType.CRAFTING, this.crafting, w).orElse(null); + if (this.isCraftable) { + IRecipe recipe = w.getRecipeManager().getRecipes(IRecipeType.CRAFTING).get(recipeId); - if (this.standardRecipe != null) { - this.correctOutput = this.standardRecipe.craft(this.crafting); - out.add(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class) - .createStack(this.correctOutput)); - } else { - throw new IllegalStateException("No pattern here!"); + if (recipe == null || recipe.getType() != IRecipeType.CRAFTING) { + throw new IllegalStateException("recipe id is not a crafting recipe"); } + + this.standardRecipe = (ICraftingRecipe) recipe; + this.correctOutput = this.standardRecipe.craft(this.crafting); + + out.add(Api.instance().storage().getStorageChannel(IItemStorageChannel.class) + .createStack(this.correctOutput)); } else { this.standardRecipe = null; this.correctOutput = ItemStack.EMPTY; - for (int x = 0; x < outTag.size(); x++) { - CompoundTag resultItemTag = outTag.getCompound(x); - final ItemStack gs = ItemStack.fromTag(resultItemTag); - - if (!resultItemTag.isEmpty() && gs.isEmpty()) { - throw new IllegalArgumentException("No pattern here!"); - } + for (int x = 0; x < 3; x++) { + final IAEItemStack ais = products.get(x); + final ItemStack gs = ais.createItemStack(); if (!gs.isEmpty()) { - out.add(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createStack(gs)); + out.add(ais.copy()); } } } - this.outputs = out.toArray(new IAEItemStack[0]); this.inputs = in.toArray(new IAEItemStack[0]); + this.outputs = out.toArray(new IAEItemStack[0]); final Map tmpOutputs = new HashMap<>(); @@ -190,12 +185,12 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable items = new MEMonitorPassThrough<>( - new NullInventory(), AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)); + new NullInventory(), Api.instance().storage().getStorageChannel(IItemStorageChannel.class)); private final MEMonitorPassThrough fluids = new MEMonitorPassThrough<>( - new NullInventory(), - AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class)); + new NullInventory(), Api.instance().storage().getStorageChannel(IFluidStorageChannel.class)); private final UpgradeInventory upgrades; private boolean hasConfig = false; private int priority; @@ -358,7 +357,7 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn final ItemStack stored = this.storage.getInvStack(slot); if (req == null && !stored.isEmpty()) { - final IAEItemStack work = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class) + final IAEItemStack work = Api.instance().storage().getStorageChannel(IItemStorageChannel.class) .createStack(stored); this.requireWork[slot] = work.setStackSize(-work.getStackSize()); return; @@ -377,7 +376,7 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn } else // Stored != null; dispose! { - final IAEItemStack work = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class) + final IAEItemStack work = Api.instance().storage().getStorageChannel(IItemStorageChannel.class) .createStack(stored); this.requireWork[slot] = work.setStackSize(-work.getStackSize()); return; @@ -406,21 +405,15 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn } private void addToCraftingList(final ItemStack is) { - if (is.isEmpty()) { - return; - } + final ICraftingPatternDetails details = Api.instance().crafting().decodePattern(is, + this.iHost.getBlockEntity().getWorld()); - if (is.getItem() instanceof ICraftingPatternItem) { - final ICraftingPatternItem cpi = (ICraftingPatternItem) is.getItem(); - final ICraftingPatternDetails details = cpi.getPatternForItem(is, this.iHost.getBlockEntity().getWorld()); - - if (details != null) { - if (this.craftingList == null) { - this.craftingList = new ArrayList<>(); - } - - this.craftingList.add(details); + if (details != null) { + if (this.craftingList == null) { + this.craftingList = new ArrayList<>(); } + + this.craftingList.add(details); } } @@ -431,7 +424,7 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn @Override public boolean canInsert(final ItemStack stack) { final IAEItemStack out = this.destination.injectItems( - AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createStack(stack), + Api.instance().storage().getStorageChannel(IItemStorageChannel.class).createStack(stack), Actionable.SIMULATE, null); if (out == null) { return true; @@ -454,9 +447,9 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn public void gridChanged() { try { this.items.setInternal(this.gridProxy.getStorage() - .getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class))); + .getInventory(Api.instance().storage().getStorageChannel(IItemStorageChannel.class))); this.fluids.setInternal(this.gridProxy.getStorage() - .getInventory(AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class))); + .getInventory(Api.instance().storage().getStorageChannel(IFluidStorageChannel.class))); } catch (final GridAccessException gae) { this.items.setInternal(new NullInventory()); this.fluids.setInternal(new NullInventory()); @@ -561,7 +554,7 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn boolean changed = false; try { this.destination = this.gridProxy.getStorage() - .getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)); + .getInventory(Api.instance().storage().getStorageChannel(IItemStorageChannel.class)); final IEnergySource src = this.gridProxy.getEnergy(); if (this.craftingTracker.isBusy(x)) { @@ -661,13 +654,13 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn @Override public > IMEMonitor getInventory(IStorageChannel channel) { - if (channel == AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)) { + if (channel == Api.instance().storage().getStorageChannel(IItemStorageChannel.class)) { if (this.hasConfig()) { return (IMEMonitor) new InterfaceInventory(this); } return (IMEMonitor) this.items; - } else if (channel == AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class)) { + } else if (channel == Api.instance().storage().getStorageChannel(IFluidStorageChannel.class)) { if (this.hasConfig()) { return null; } @@ -735,7 +728,7 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn @Override public > IMEMonitor getInventory(IStorageChannel channel) { - if (channel == AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)) { + if (channel == Api.instance().storage().getStorageChannel(IItemStorageChannel.class)) { return (IMEMonitor) new InterfaceInventory(di); } return null; diff --git a/src/main/java/appeng/helpers/MultiCraftingTracker.java b/src/main/java/appeng/helpers/MultiCraftingTracker.java index a00e769d7..5854bc392 100644 --- a/src/main/java/appeng/helpers/MultiCraftingTracker.java +++ b/src/main/java/appeng/helpers/MultiCraftingTracker.java @@ -26,7 +26,6 @@ import com.google.common.collect.ImmutableSet; import net.minecraft.nbt.CompoundTag; import net.minecraft.world.World; -import appeng.api.AEApi; import appeng.api.networking.IGrid; import appeng.api.networking.crafting.ICraftingGrid; import appeng.api.networking.crafting.ICraftingJob; @@ -34,6 +33,7 @@ import appeng.api.networking.crafting.ICraftingLink; import appeng.api.networking.crafting.ICraftingRequester; import appeng.api.networking.security.IActionSource; import appeng.api.storage.data.IAEItemStack; +import appeng.core.Api; import appeng.util.InventoryAdaptor; public class MultiCraftingTracker { @@ -54,7 +54,7 @@ public class MultiCraftingTracker { final CompoundTag link = extra.getCompound("links-" + x); if (link != null && !link.isEmpty()) { - this.setLink(x, AEApi.instance().storage().loadCraftingLink(link, this.owner)); + this.setLink(x, Api.instance().storage().loadCraftingLink(link, this.owner)); } } } diff --git a/src/main/java/appeng/helpers/WirelessTerminalGuiObject.java b/src/main/java/appeng/helpers/WirelessTerminalGuiObject.java index a00260a95..f5046e292 100644 --- a/src/main/java/appeng/helpers/WirelessTerminalGuiObject.java +++ b/src/main/java/appeng/helpers/WirelessTerminalGuiObject.java @@ -21,7 +21,6 @@ package appeng.helpers; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; -import appeng.api.AEApi; import appeng.api.config.AccessRestriction; import appeng.api.config.Actionable; import appeng.api.config.PowerMultiplier; @@ -45,6 +44,7 @@ import appeng.api.storage.data.IItemList; import appeng.api.util.DimensionalCoord; import appeng.api.util.IConfigManager; import appeng.container.interfaces.IInventorySlotAware; +import appeng.core.Api; import appeng.tile.networking.WirelessBlockEntity; public class WirelessTerminalGuiObject implements IPortableCell, IActionHost, IInventorySlotAware { @@ -73,7 +73,7 @@ public class WirelessTerminalGuiObject implements IPortableCell, IActionHost, II try { final long encKey = Long.parseLong(this.encryptionKey); - obj = AEApi.instance().registries().locatable().getLocatableBy(encKey); + obj = Api.instance().registries().locatable().getLocatableBy(encKey); } catch (final NumberFormatException err) { // :P } @@ -86,7 +86,7 @@ public class WirelessTerminalGuiObject implements IPortableCell, IActionHost, II this.sg = this.targetGrid.getCache(IStorageGrid.class); if (this.sg != null) { this.itemStorage = this.sg - .getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)); + .getInventory(Api.instance().storage().getStorageChannel(IItemStorageChannel.class)); } } } @@ -198,7 +198,7 @@ public class WirelessTerminalGuiObject implements IPortableCell, IActionHost, II if (this.itemStorage != null) { return this.itemStorage.getChannel(); } - return AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class); + return Api.instance().storage().getStorageChannel(IItemStorageChannel.class); } @Override diff --git a/src/main/java/appeng/items/contents/PortableCellViewer.java b/src/main/java/appeng/items/contents/PortableCellViewer.java index f2f034053..bbcfd28fe 100644 --- a/src/main/java/appeng/items/contents/PortableCellViewer.java +++ b/src/main/java/appeng/items/contents/PortableCellViewer.java @@ -21,7 +21,6 @@ package appeng.items.contents; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundTag; -import appeng.api.AEApi; import appeng.api.config.Actionable; import appeng.api.config.PowerMultiplier; import appeng.api.config.Settings; @@ -37,6 +36,7 @@ import appeng.api.storage.data.IAEItemStack; import appeng.api.storage.data.IAEStack; import appeng.api.util.IConfigManager; import appeng.container.interfaces.IInventorySlotAware; +import appeng.core.Api; import appeng.me.helpers.MEMonitorHandler; import appeng.util.ConfigManager; @@ -47,8 +47,8 @@ public class PortableCellViewer extends MEMonitorHandler implement private final int inventorySlot; public PortableCellViewer(final ItemStack is, final int slot) { - super(AEApi.instance().registries().cell().getCellInventory(is, null, - AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class))); + super(Api.instance().registries().cell().getCellInventory(is, null, + Api.instance().storage().getStorageChannel(IItemStorageChannel.class))); this.ips = (IAEItemPowerStorage) is.getItem(); this.target = is; this.inventorySlot = slot; @@ -77,7 +77,7 @@ public class PortableCellViewer extends MEMonitorHandler implement @Override public > IMEMonitor getInventory(IStorageChannel channel) { - if (channel == AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)) { + if (channel == Api.instance().storage().getStorageChannel(IItemStorageChannel.class)) { return (IMEMonitor) this; } return null; diff --git a/src/main/java/appeng/items/misc/EncodedPatternItem.java b/src/main/java/appeng/items/misc/EncodedPatternItem.java index e0bbd4e7c..c24b9ca55 100644 --- a/src/main/java/appeng/items/misc/EncodedPatternItem.java +++ b/src/main/java/appeng/items/misc/EncodedPatternItem.java @@ -18,12 +18,16 @@ package appeng.items.misc; +import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.WeakHashMap; import appeng.hooks.AEToolItem; import net.minecraft.client.item.TooltipContext; +import com.google.common.base.Preconditions; + +import net.minecraft.client.util.ITooltipFlag; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.item.ItemStack; @@ -31,25 +35,34 @@ import net.minecraft.item.ItemUsageContext; import net.minecraft.text.LiteralText; import net.minecraft.text.MutableText; import net.minecraft.util.TypedActionResult; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.nbt.INBT; +import net.minecraft.nbt.ListNBT; import net.minecraft.util.ActionResult; import net.minecraft.util.Hand; +import net.minecraft.util.ResourceLocation; import net.minecraft.text.Text; import net.minecraft.util.Formatting; import net.minecraft.world.World; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import net.minecraftforge.common.util.Constants; -import appeng.api.AEApi; -import appeng.api.implementations.ICraftingPatternItem; import appeng.api.networking.crafting.ICraftingPatternDetails; +import appeng.api.storage.channels.IItemStorageChannel; import appeng.api.storage.data.IAEItemStack; import appeng.core.localization.GuiText; import appeng.helpers.InvalidPatternHelper; -import appeng.helpers.PatternHelper; import appeng.items.AEBaseItem; import appeng.util.Platform; -public class EncodedPatternItem extends AEBaseItem implements ICraftingPatternItem, AEToolItem { +public class EncodedPatternItem extends AEBaseItem, AEToolItem { + + public static final String NBT_INGREDIENTS = "in"; + public static final String NBT_PRODUCTS = "out"; + public static final String NBT_SUBSITUTE = "substitute"; + public static final String NBT_RECIPE_ID = "recipe"; + // rather simple client side caching. private static final Map SIMPLE_CACHE = new WeakHashMap<>(); @@ -77,7 +90,7 @@ public class EncodedPatternItem extends AEBaseItem implements ICraftingPatternIt final PlayerInventory inv = player.inventory; - ItemStack is = AEApi.instance().definitions().materials().blankPattern().maybeStack(stack.getCount()) + ItemStack is = Api.instance().definitions().materials().blankPattern().maybeStack(stack.getCount()) .orElse(ItemStack.EMPTY); if (!is.isEmpty()) { for (int s = 0; s < player.inventory.size(); s++) { @@ -96,7 +109,7 @@ public class EncodedPatternItem extends AEBaseItem implements ICraftingPatternIt @Environment(EnvType.CLIENT) public void appendTooltip(final ItemStack stack, final World world, final List lines, final TooltipContext advancedTooltips) { - final ICraftingPatternDetails details = this.getPatternForItem(stack, world); + final ICraftingPatternDetails details = Api.instance().crafting().decodePattern(stack, world); if (details == null) { if (!stack.hasTag()) { @@ -182,15 +195,6 @@ public class EncodedPatternItem extends AEBaseItem implements ICraftingPatternIt } } - @Override - public ICraftingPatternDetails getPatternForItem(final ItemStack is, final World w) { - try { - return new PatternHelper(is, w); - } catch (final Throwable t) { - return null; - } - } - public ItemStack getOutput(World w, final ItemStack item) { ItemStack out = SIMPLE_CACHE.get(item); @@ -198,11 +202,127 @@ public class EncodedPatternItem extends AEBaseItem implements ICraftingPatternIt return out; } - final ICraftingPatternDetails details = this.getPatternForItem(item, w); + final ICraftingPatternDetails details = Api.instance().crafting().decodePattern(item, w); out = details != null ? details.getOutputs()[0].createItemStack() : ItemStack.EMPTY; SIMPLE_CACHE.put(item, out); return out; } + + public boolean isEncodedPattern(ItemStack itemStack) { + return itemStack != null && !itemStack.isEmpty() && itemStack.getItem() == this && itemStack.getTag() != null + && itemStack.getTag().contains(NBT_INGREDIENTS, Constants.NBT.TAG_LIST) + && itemStack.getTag().contains(NBT_PRODUCTS, Constants.NBT.TAG_LIST); + } + + public ResourceLocation getCraftingRecipeId(ItemStack itemStack) { + Preconditions.checkArgument(itemStack.getItem() == this, "Given item stack %s is not an encoded pattern.", + itemStack); + final CompoundNBT tag = itemStack.getTag(); + Preconditions.checkArgument(tag != null, "itemStack missing a NBT tag"); + + return new ResourceLocation(tag.getString(NBT_RECIPE_ID)); + } + + public List getIngredients(ItemStack itemStack) { + Preconditions.checkArgument(itemStack.getItem() == this, "Given item stack %s is not an encoded pattern.", + itemStack); + final CompoundNBT tag = itemStack.getTag(); + Preconditions.checkArgument(tag != null, "itemStack missing a NBT tag"); + + final ListNBT inTag = tag.getList(NBT_INGREDIENTS, 10); + Preconditions.checkArgument(inTag.size() < 10, "Cannot use more than 9 ingredients"); + + final List in = new ArrayList<>(inTag.size()); + for (int x = 0; x < inTag.size(); x++) { + CompoundNBT ingredient = inTag.getCompound(x); + final ItemStack gs = ItemStack.read(ingredient); + + Preconditions.checkArgument(!(!ingredient.isEmpty() && gs.isEmpty()), "invalid itemStack in slot", x); + + in.add(Api.instance().storage().getStorageChannel(IItemStorageChannel.class).createStack(gs)); + } + + return in; + } + + public List getProducts(ItemStack itemStack) { + Preconditions.checkArgument(itemStack.getItem() == this, "Given item stack %s is not an encoded pattern.", + itemStack); + final CompoundNBT tag = itemStack.getTag(); + Preconditions.checkArgument(tag != null, "itemStack missing a NBT tag"); + + final ListNBT outTag = tag.getList(NBT_PRODUCTS, 10); + Preconditions.checkArgument(outTag.size() < 4, "Cannot use more than 3 ingredients"); + + final List out = new ArrayList<>(outTag.size()); + for (int x = 0; x < outTag.size(); x++) { + CompoundNBT ingredient = outTag.getCompound(x); + final ItemStack gs = ItemStack.read(ingredient); + + Preconditions.checkArgument(!(!ingredient.isEmpty() && gs.isEmpty()), "invalid itemStack in slot", x); + + out.add(Api.instance().storage().getStorageChannel(IItemStorageChannel.class).createStack(gs)); + } + + return out; + + } + + public boolean allowsSubstitution(ItemStack itemStack) { + final CompoundNBT tag = itemStack.getTag(); + + Preconditions.checkArgument(tag != null, "itemStack missing a NBT tag"); + + return getCraftingRecipeId(itemStack) == null && tag.getBoolean(NBT_SUBSITUTE); + } + + /** + * Use the public API instead {@link appeng.core.api.ApiCrafting} + */ + public static void encodeCraftingPattern(ItemStack stack, ItemStack[] in, ItemStack[] out, + ResourceLocation recipeId, boolean allowSubstitutes) { + CompoundNBT encodedValue = encodeInputsAndOutputs(in, out); + encodedValue.putString(EncodedPatternItem.NBT_RECIPE_ID, recipeId.toString()); + encodedValue.putBoolean(EncodedPatternItem.NBT_SUBSITUTE, allowSubstitutes); + stack.setTag(encodedValue); + } + + /** + * Use the public API instead {@link appeng.core.api.ApiCrafting} + */ + public static void encodeProcessingPattern(ItemStack stack, ItemStack[] in, ItemStack[] out) { + stack.setTag(encodeInputsAndOutputs(in, out)); + } + + private static CompoundNBT encodeInputsAndOutputs(ItemStack[] in, ItemStack[] out) { + final CompoundNBT encodedValue = new CompoundNBT(); + + final ListNBT tagIn = new ListNBT(); + final ListNBT tagOut = new ListNBT(); + + for (final ItemStack i : in) { + tagIn.add(createItemTag(i)); + } + + for (final ItemStack i : out) { + tagOut.add(createItemTag(i)); + } + + encodedValue.put(EncodedPatternItem.NBT_INGREDIENTS, tagIn); + encodedValue.put(EncodedPatternItem.NBT_PRODUCTS, tagOut); + return encodedValue; + } + + private static INBT createItemTag(final ItemStack i) { + final CompoundNBT c = new CompoundNBT(); + + if (!i.isEmpty()) { + i.write(c); + } + + return c; + } + } diff --git a/src/main/java/appeng/items/parts/FacadeItem.java b/src/main/java/appeng/items/parts/FacadeItem.java index ade592555..fce701555 100644 --- a/src/main/java/appeng/items/parts/FacadeItem.java +++ b/src/main/java/appeng/items/parts/FacadeItem.java @@ -28,7 +28,12 @@ import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.client.render.RenderLayer; import net.minecraft.client.render.RenderLayers; -import net.minecraft.item.*; +import net.minecraft.item.BlockItem; +import net.minecraft.item.Item; +import net.minecraft.item.ItemGroup; +import net.minecraft.item.ItemStack; +import net.minecraft.item.ItemUseContext; +import net.minecraft.item.Items; import net.minecraft.nbt.CompoundTag; import net.minecraft.tag.BlockTags; import net.minecraft.tag.Tag; @@ -40,12 +45,12 @@ import net.minecraft.util.registry.Registry; import net.minecraft.text.Text; import net.minecraft.world.EmptyBlockView; -import appeng.api.AEApi; import appeng.api.exceptions.MissingDefinitionException; import appeng.api.features.AEFeature; import appeng.api.parts.IAlphaPassItem; import appeng.api.util.AEPartLocation; import appeng.core.AEConfig; +import appeng.core.Api; import appeng.core.AppEng; import appeng.facade.FacadePart; import appeng.facade.IFacadeItem; @@ -67,7 +72,7 @@ public class FacadeItem extends AEBaseItem implements IFacadeItem, IAlphaPassIte @Override public ActionResult onItemUseFirst(ItemStack stack, ItemUsageContext context) { - return AEApi.instance().partHelper().placeBus(stack, context.getBlockPos(), context.getSide(), context.getPlayer(), + return Api.instance().partHelper().placeBus(stack, context.getBlockPos(), context.getSide(), context.getPlayer(), context.getHand(), context.getWorld()); } @@ -176,7 +181,7 @@ public class FacadeItem extends AEBaseItem implements IFacadeItem, IAlphaPassIte } public ItemStack createFromID(final int id) { - ItemStack facadeStack = AEApi.instance().definitions().items().facade().maybeStack(1).orElseThrow( + ItemStack facadeStack = Api.instance().definitions().items().facade().maybeStack(1).orElseThrow( () -> new MissingDefinitionException("Tried to create a facade, while facades are being deactivated.")); // Convert back to a registry name... diff --git a/src/main/java/appeng/items/parts/PartItem.java b/src/main/java/appeng/items/parts/PartItem.java index 5e5b42dc9..fa60d5762 100644 --- a/src/main/java/appeng/items/parts/PartItem.java +++ b/src/main/java/appeng/items/parts/PartItem.java @@ -25,9 +25,9 @@ import net.minecraft.item.ItemStack; import net.minecraft.item.ItemUsageContext; import net.minecraft.util.ActionResult; -import appeng.api.AEApi; import appeng.api.parts.IPart; import appeng.api.parts.IPartItem; +import appeng.core.Api; import appeng.items.AEBaseItem; public class PartItem extends AEBaseItem implements IPartItem { @@ -47,7 +47,7 @@ public class PartItem extends AEBaseItem implements IPartItem> extends AEBaseI @Override public void appendTooltip(final ItemStack stack, final World world, final List lines, final TooltipContext advancedTooltips) { - AEApi.instance().client().addCellInformation( - AEApi.instance().registries().cell().getCellInventory(stack, null, this.getChannel()), lines); + Api.instance().client().addCellInformation( + Api.instance().registries().cell().getCellInventory(stack, null, this.getChannel()), lines); } @Override @@ -121,6 +119,9 @@ public abstract class AbstractStorageCell> extends AEBaseI @Override public FuzzyMode getFuzzyMode(final ItemStack is) { final String fz = is.getOrCreateTag().getString("FuzzyMode"); + if (fz.isEmpty()) { + return FuzzyMode.IGNORE_ALL; + } try { return FuzzyMode.valueOf(fz); } catch (final Throwable t) { @@ -146,7 +147,7 @@ public abstract class AbstractStorageCell> extends AEBaseI } final PlayerInventory playerInventory = player.inventory; - final IMEInventoryHandler inv = AEApi.instance().registries().cell().getCellInventory(stack, null, + final IMEInventoryHandler inv = Api.instance().registries().cell().getCellInventory(stack, null, this.getChannel()); if (inv != null && playerInventory.getMainHandStack() == stack) { final InventoryAdaptor ia = InventoryAdaptor.getAdaptor(player); @@ -195,7 +196,7 @@ public abstract class AbstractStorageCell> extends AEBaseI // FIXME FABRIC: Handle this in the disassemble recipe // FIXME FABRIC @Override // FIXME FABRIC public ItemStack getRecipeRemainder(final ItemStack itemStack) { -// FIXME FABRIC return AEApi.instance().definitions().materials().emptyStorageCell().maybeStack(1) +// FIXME FABRIC return Api.instance().definitions().materials().emptyStorageCell().maybeStack(1) // FIXME FABRIC .orElseThrow(() -> new MissingDefinitionException( // FIXME FABRIC "Tried to use empty storage cells while basic storage cells are defined.")); // FIXME FABRIC } diff --git a/src/main/java/appeng/items/storage/BasicStorageCellItem.java b/src/main/java/appeng/items/storage/BasicStorageCellItem.java index a7b1bc145..6c137aef8 100644 --- a/src/main/java/appeng/items/storage/BasicStorageCellItem.java +++ b/src/main/java/appeng/items/storage/BasicStorageCellItem.java @@ -21,10 +21,10 @@ package appeng.items.storage; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; -import appeng.api.AEApi; import appeng.api.storage.IStorageChannel; import appeng.api.storage.channels.IItemStorageChannel; import appeng.api.storage.data.IAEItemStack; +import appeng.core.Api; import appeng.items.materials.MaterialType; import appeng.util.InventoryAdaptor; @@ -71,12 +71,12 @@ public final class BasicStorageCellItem extends AbstractStorageCell getChannel() { - return AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class); + return Api.instance().storage().getStorageChannel(IItemStorageChannel.class); } @Override protected void dropEmptyStorageCellCase(final InventoryAdaptor ia, final PlayerEntity player) { - AEApi.instance().definitions().materials().emptyStorageCell().maybeStack(1).ifPresent(is -> { + Api.instance().definitions().materials().emptyStorageCell().maybeStack(1).ifPresent(is -> { final ItemStack extraA = ia.addItems(is); if (!extraA.isEmpty()) { player.dropItem(extraA, false); diff --git a/src/main/java/appeng/items/storage/CreativeStorageCellItem.java b/src/main/java/appeng/items/storage/CreativeStorageCellItem.java index 0481b9ab6..83937bd8e 100644 --- a/src/main/java/appeng/items/storage/CreativeStorageCellItem.java +++ b/src/main/java/appeng/items/storage/CreativeStorageCellItem.java @@ -28,12 +28,12 @@ import net.minecraft.item.ItemStack; import net.minecraft.text.Text; import net.minecraft.world.World; -import appeng.api.AEApi; import appeng.api.config.FuzzyMode; import appeng.api.storage.IMEInventoryHandler; import appeng.api.storage.cells.ICellInventoryHandler; import appeng.api.storage.cells.ICellWorkbenchItem; import appeng.api.storage.channels.IItemStorageChannel; +import appeng.core.Api; import appeng.items.AEBaseItem; import appeng.items.contents.CellConfig; @@ -72,8 +72,8 @@ public class CreativeStorageCellItem extends AEBaseItem implements ICellWorkbenc @Override public void appendTooltip(final ItemStack stack, final World world, final List lines, final TooltipContext advancedTooltips) { - final IMEInventoryHandler inventory = AEApi.instance().registries().cell().getCellInventory(stack, null, - AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)); + final IMEInventoryHandler inventory = Api.instance().registries().cell().getCellInventory(stack, null, + Api.instance().storage().getStorageChannel(IItemStorageChannel.class)); if (inventory instanceof ICellInventoryHandler) { final CellConfig cc = new CellConfig(stack); diff --git a/src/main/java/appeng/items/storage/ViewCellItem.java b/src/main/java/appeng/items/storage/ViewCellItem.java index ae6246805..4e923826b 100644 --- a/src/main/java/appeng/items/storage/ViewCellItem.java +++ b/src/main/java/appeng/items/storage/ViewCellItem.java @@ -21,7 +21,6 @@ package appeng.items.storage; import alexiil.mc.lib.attributes.item.FixedItemInv; import net.minecraft.item.ItemStack; -import appeng.api.AEApi; import appeng.api.config.FuzzyMode; import appeng.api.config.Upgrades; import appeng.api.implementations.items.IUpgradeModule; @@ -29,6 +28,7 @@ import appeng.api.storage.cells.ICellWorkbenchItem; import appeng.api.storage.channels.IItemStorageChannel; import appeng.api.storage.data.IAEItemStack; import appeng.api.storage.data.IItemList; +import appeng.core.Api; import appeng.items.AEBaseItem; import appeng.items.contents.CellConfig; import appeng.items.contents.CellUpgrades; @@ -55,7 +55,7 @@ public class ViewCellItem extends AEBaseItem implements ICellWorkbenchItem { } if ((currentViewCell.getItem() instanceof ViewCellItem)) { - final IItemList priorityList = AEApi.instance().storage() + final IItemList priorityList = Api.instance().storage() .getStorageChannel(IItemStorageChannel.class).createList(); final ICellWorkbenchItem vc = (ICellWorkbenchItem) currentViewCell.getItem(); diff --git a/src/main/java/appeng/items/tools/powered/ColorApplicatorItem.java b/src/main/java/appeng/items/tools/powered/ColorApplicatorItem.java index 992e8efc2..2f3ff1e5d 100644 --- a/src/main/java/appeng/items/tools/powered/ColorApplicatorItem.java +++ b/src/main/java/appeng/items/tools/powered/ColorApplicatorItem.java @@ -35,6 +35,7 @@ import appeng.api.util.DimensionalCoord; import appeng.block.networking.CableBusBlock; import appeng.block.paint.PaintSplotchesBlock; import appeng.core.AEConfig; +import appeng.core.Api; import appeng.core.AppEng; import appeng.core.localization.GuiText; import appeng.helpers.IMouseWheelItem; @@ -131,8 +132,8 @@ public class ColorApplicatorItem extends AEBasePoweredItem ItemStack paintBall = this.getColor(is); - final IMEInventory inv = AEApi.instance().registries().cell().getCellInventory(is, null, - AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)); + final IMEInventory inv = Api.instance().registries().cell().getCellInventory(is, null, + Api.instance().storage().getStorageChannel(IItemStorageChannel.class)); if (inv != null) { final IAEItemStack option = inv.extractItems(AEItemStack.fromItemStack(paintBall), Actionable.SIMULATE, new BaseActionSource()); @@ -252,11 +253,11 @@ public class ColorApplicatorItem extends AEBasePoweredItem private ItemStack findNextColor(final ItemStack is, final ItemStack anchor, final int scrollOffset) { ItemStack newColor = ItemStack.EMPTY; - final IMEInventory inv = AEApi.instance().registries().cell().getCellInventory(is, null, - AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)); + final IMEInventory inv = Api.instance().registries().cell().getCellInventory(is, null, + Api.instance().storage().getStorageChannel(IItemStorageChannel.class)); if (inv != null) { final IItemList itemList = inv.getAvailableItems( - AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList()); + Api.instance().storage().getStorageChannel(IItemStorageChannel.class).createList()); if (anchor.isEmpty()) { final IAEItemStack firstItem = itemList.getFirstItem(); if (firstItem != null) { @@ -373,10 +374,10 @@ public class ColorApplicatorItem extends AEBasePoweredItem final TooltipContext advancedTooltips) { super.appendTooltip(stack, world, lines, advancedTooltips); - final ICellInventoryHandler cdi = AEApi.instance().registries().cell().getCellInventory(stack, - null, AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)); + final ICellInventoryHandler cdi = Api.instance().registries().cell().getCellInventory(stack, null, + Api.instance().storage().getStorageChannel(IItemStorageChannel.class)); - AEApi.instance().client().addCellInformation(cdi, lines); + Api.instance().client().addCellInformation(cdi, lines); } @Override @@ -419,7 +420,7 @@ public class ColorApplicatorItem extends AEBasePoweredItem @Override public IStorageChannel getChannel() { - return AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class); + return Api.instance().storage().getStorageChannel(IItemStorageChannel.class); } @Override diff --git a/src/main/java/appeng/items/tools/powered/EntropyManipulatorItem.java b/src/main/java/appeng/items/tools/powered/EntropyManipulatorItem.java index 376e60b8a..141a23a37 100644 --- a/src/main/java/appeng/items/tools/powered/EntropyManipulatorItem.java +++ b/src/main/java/appeng/items/tools/powered/EntropyManipulatorItem.java @@ -18,7 +18,12 @@ package appeng.items.tools.powered; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; import appeng.mixins.TntAccessor; import appeng.util.FakePlayer; @@ -28,14 +33,23 @@ import net.minecraft.entity.player.PlayerEntity; import net.minecraft.fluid.Fluid; import net.minecraft.fluid.Fluids; import net.minecraft.inventory.CraftingInventory; -import net.minecraft.item.*; +import net.minecraft.item.BlockItem; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.item.ItemUseContext; +import net.minecraft.item.Items; import net.minecraft.recipe.RecipeType; import net.minecraft.particle.ParticleTypes; import net.minecraft.recipe.SmeltingRecipe; import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundEvents; import net.minecraft.state.property.Properties; -import net.minecraft.util.*; +import net.minecraft.util.ActionResult; +import net.minecraft.util.ActionResultType; +import net.minecraft.util.Direction; +import net.minecraft.util.Hand; +import net.minecraft.util.SoundCategory; +import net.minecraft.util.SoundEvents; import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; diff --git a/src/main/java/appeng/items/tools/powered/MatterCannonItem.java b/src/main/java/appeng/items/tools/powered/MatterCannonItem.java index 903e75c00..72e2549c8 100644 --- a/src/main/java/appeng/items/tools/powered/MatterCannonItem.java +++ b/src/main/java/appeng/items/tools/powered/MatterCannonItem.java @@ -52,7 +52,6 @@ import net.minecraft.text.Text; import net.minecraft.world.World; import net.fabricmc.api.Environment; -import appeng.api.AEApi; import appeng.api.config.Actionable; import appeng.api.config.FuzzyMode; import appeng.api.config.Upgrades; @@ -67,6 +66,7 @@ import appeng.api.util.AEColor; import appeng.api.util.DimensionalCoord; import appeng.core.AEConfig; import appeng.core.AELog; +import appeng.core.Api; import appeng.core.AppEng; import appeng.core.localization.PlayerMessages; import appeng.core.sync.network.NetworkHandler; @@ -99,10 +99,10 @@ public class MatterCannonItem extends AEBasePoweredItem implements IStorageCell< final TooltipContext advancedTooltips) { super.appendTooltip(stack, world, lines, advancedTooltips); - final ICellInventoryHandler cdi = AEApi.instance().registries().cell().getCellInventory(stack, - null, AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)); + final ICellInventoryHandler cdi = Api.instance().registries().cell().getCellInventory(stack, null, + Api.instance().storage().getStorageChannel(IItemStorageChannel.class)); - AEApi.instance().client().addCellInformation(cdi, lines); + Api.instance().client().addCellInformation(cdi, lines); } @Override @@ -115,11 +115,11 @@ public class MatterCannonItem extends AEBasePoweredItem implements IStorageCell< shots += cu.getInstalledUpgrades(Upgrades.SPEED); } - final ICellInventoryHandler inv = AEApi.instance().registries().cell().getCellInventory( - p.getStackInHand(hand), null, AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)); + final ICellInventoryHandler inv = Api.instance().registries().cell().getCellInventory( + p.getStackInHand(hand), null, Api.instance().storage().getStorageChannel(IItemStorageChannel.class)); if (inv != null) { final IItemList itemList = inv.getAvailableItems( - AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList()); + Api.instance().storage().getStorageChannel(IItemStorageChannel.class).createList()); IAEItemStack req = itemList.getFirstItem(); if (req instanceof IAEItemStack) { shots = Math.min(shots, (int) req.getStackSize()); @@ -153,7 +153,7 @@ public class MatterCannonItem extends AEBasePoweredItem implements IStorageCell< final double d1 = rayFrom.y; final double d2 = rayFrom.z; - final float penetration = AEApi.instance().registries().matterCannon().getPenetration(ammo); // 196.96655f; + final float penetration = Api.instance().registries().matterCannon().getPenetration(ammo); // 196.96655f; if (penetration <= 0) { final ItemStack type = aeAmmo.asItemStackRepresentation(); if (type.getItem() instanceof PaintBallItem) { @@ -189,26 +189,24 @@ public class MatterCannonItem extends AEBasePoweredItem implements IStorageCell< for (int l = 0; l < list.size(); ++l) { final Entity entity1 = (Entity) list.get(l); - if (!entity1.isAlive() && entity1 != p && !(entity1 instanceof ItemEntity)) { - if (entity1.isAlive()) { - // prevent killing / flying of mounts. - if (entity1.isConnectedThroughVehicle(p)) { - continue; - } + if (entity1.isAlive() && entity1 != p && !(entity1 instanceof ItemEntity)) { + // prevent killing / flying of mounts. + if (entity1.isConnectedThroughVehicle(p)) { + continue; + } - final float f1 = 0.3F; + final float f1 = 0.3F; - final Box boundingBox = entity1.getBoundingBox().expand(f1, f1, f1); - final Vec3d intersection = boundingBox.rayTrace(Vec3d, Vec3d1).orElse(null); + final Box boundingBox = entity1.getBoundingBox().expand(f1, f1, f1); + final Vec3d intersection = boundingBox.rayTrace(Vec3d, Vec3d1).orElse(null); - if (intersection != null) { - final double nd = Vec3d.squaredDistanceTo(intersection); + if (intersection != null) { + final double nd = Vec3d.squaredDistanceTo(intersection); - if (nd < closest) { - entity = entity1; - entityIntersection = intersection; - closest = nd; - } + if (nd < closest) { + entity = entity1; + entityIntersection = intersection; + closest = nd; } } } @@ -267,7 +265,7 @@ public class MatterCannonItem extends AEBasePoweredItem implements IStorageCell< final BlockState whatsThere = w.getBlockState(hitPos); if (whatsThere.getMaterial().isReplaceable() && w.isAir(hitPos)) { - AEApi.instance().definitions().blocks().paint().maybeBlock().ifPresent(paintBlock -> { + Api.instance().definitions().blocks().paint().maybeBlock().ifPresent(paintBlock -> { w.setBlockState(hitPos, paintBlock.getDefaultState(), 3); }); } @@ -438,7 +436,7 @@ public class MatterCannonItem extends AEBasePoweredItem implements IStorageCell< @Override public boolean isBlackListed(final ItemStack cellItem, final IAEItemStack requestedAddition) { - final float pen = AEApi.instance().registries().matterCannon() + final float pen = Api.instance().registries().matterCannon() .getPenetration(requestedAddition.createItemStack()); if (pen > 0) { return false; @@ -468,6 +466,6 @@ public class MatterCannonItem extends AEBasePoweredItem implements IStorageCell< @Override public IStorageChannel getChannel() { - return AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class); + return Api.instance().storage().getStorageChannel(IItemStorageChannel.class); } } diff --git a/src/main/java/appeng/items/tools/powered/PortableCellItem.java b/src/main/java/appeng/items/tools/powered/PortableCellItem.java index e4f06e212..e92207b5a 100644 --- a/src/main/java/appeng/items/tools/powered/PortableCellItem.java +++ b/src/main/java/appeng/items/tools/powered/PortableCellItem.java @@ -19,7 +19,6 @@ package appeng.items.tools.powered; import java.util.List; -import java.util.Set; import net.minecraft.client.item.TooltipContext; import net.minecraft.entity.player.PlayerEntity; @@ -35,7 +34,6 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import alexiil.mc.lib.attributes.item.FixedItemInv; -import appeng.api.AEApi; import appeng.api.config.FuzzyMode; import appeng.api.implementations.guiobjects.IGuiItem; import appeng.api.implementations.guiobjects.IGuiItemObject; @@ -48,7 +46,7 @@ import appeng.container.ContainerLocator; import appeng.container.ContainerOpener; import appeng.container.implementations.MEPortableCellContainer; import appeng.core.AEConfig; -import appeng.core.localization.GuiText; +import appeng.core.Api; import appeng.items.contents.CellConfig; import appeng.items.contents.CellUpgrades; import appeng.items.contents.PortableCellViewer; @@ -71,10 +69,10 @@ public class PortableCellItem extends AEBasePoweredItem implements IStorageCell< final TooltipContext advancedTooltips) { super.appendTooltip(stack, world, lines, advancedTooltips); - final ICellInventoryHandler cdi = AEApi.instance().registries().cell().getCellInventory(stack, - null, AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)); + final ICellInventoryHandler cdi = Api.instance().registries().cell().getCellInventory(stack, null, + Api.instance().storage().getStorageChannel(IItemStorageChannel.class)); - AEApi.instance().client().addCellInformation(cdi, lines); + Api.instance().client().addCellInformation(cdi, lines); } @Override @@ -114,7 +112,7 @@ public class PortableCellItem extends AEBasePoweredItem implements IStorageCell< @Override public IStorageChannel getChannel() { - return AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class); + return Api.instance().storage().getStorageChannel(IItemStorageChannel.class); } @Override diff --git a/src/main/java/appeng/items/tools/powered/WirelessTerminalItem.java b/src/main/java/appeng/items/tools/powered/WirelessTerminalItem.java index c6294484a..fd753d2ca 100644 --- a/src/main/java/appeng/items/tools/powered/WirelessTerminalItem.java +++ b/src/main/java/appeng/items/tools/powered/WirelessTerminalItem.java @@ -36,9 +36,15 @@ import net.minecraft.text.Text; import net.minecraft.world.World; import appeng.api.AEApi; +import appeng.api.config.Actionable; +import appeng.api.config.Settings; +import appeng.api.config.SortDir; +import appeng.api.config.SortOrder; +import appeng.api.config.ViewItems; import appeng.api.features.IWirelessTermHandler; import appeng.api.util.IConfigManager; import appeng.core.AEConfig; +import appeng.core.Api; import appeng.core.localization.GuiText; import appeng.items.tools.powered.powersink.AEBasePoweredItem; import appeng.util.ConfigManager; @@ -51,7 +57,7 @@ public class WirelessTerminalItem extends AEBasePoweredItem implements IWireless @Override public TypedActionResult use(final World w, final PlayerEntity player, final Hand hand) { - AEApi.instance().registries().wireless().openWirelessTerminalGui(player.getStackInHand(hand), w, player, hand); + Api.instance().registries().wireless().openWirelessTerminalGui(player.getStackInHand(hand), w, player, hand); return new TypedActionResult<>(ActionResult.SUCCESS, player.getStackInHand(hand)); } @@ -79,7 +85,7 @@ public class WirelessTerminalItem extends AEBasePoweredItem implements IWireless @Override public boolean canHandle(final ItemStack is) { - return AEApi.instance().definitions().items().wirelessTerminal().isSameAs(is); + return Api.instance().definitions().items().wirelessTerminal().isSameAs(is); } @Override diff --git a/src/main/java/appeng/me/Grid.java b/src/main/java/appeng/me/Grid.java index 40caef967..04d73e12f 100644 --- a/src/main/java/appeng/me/Grid.java +++ b/src/main/java/appeng/me/Grid.java @@ -25,7 +25,6 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Set; -import appeng.api.AEApi; import appeng.api.networking.IGrid; import appeng.api.networking.IGridCache; import appeng.api.networking.IGridHost; @@ -35,6 +34,7 @@ import appeng.api.networking.IMachineSet; import appeng.api.networking.events.MENetworkEvent; import appeng.api.networking.events.MENetworkPostCacheConstruction; import appeng.api.util.IReadOnlyCollection; +import appeng.core.Api; import appeng.core.worlddata.WorldData; import appeng.hooks.TickHandler; import appeng.util.ReadOnlyCollection; @@ -50,7 +50,7 @@ public class Grid implements IGrid { public Grid(final GridNode center) { this.pivot = center; - final Map, IGridCache> myCaches = AEApi.instance().registries().gridCache() + final Map, IGridCache> myCaches = Api.instance().registries().gridCache() .createCacheInstance(this); this.caches = new HashMap<>(myCaches.size()); for (final Entry, IGridCache> c : myCaches.entrySet()) { diff --git a/src/main/java/appeng/me/cache/CraftingGridCache.java b/src/main/java/appeng/me/cache/CraftingGridCache.java index 89ff53e2f..27f8c630a 100644 --- a/src/main/java/appeng/me/cache/CraftingGridCache.java +++ b/src/main/java/appeng/me/cache/CraftingGridCache.java @@ -35,6 +35,7 @@ import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.concurrent.ThreadFactory; +import com.google.common.base.Preconditions; import com.google.common.collect.HashMultimap; import com.google.common.collect.ImmutableCollection; import com.google.common.collect.ImmutableList; @@ -43,7 +44,6 @@ import com.google.common.collect.Multimap; import net.minecraft.world.World; -import appeng.api.AEApi; import appeng.api.config.AccessRestriction; import appeng.api.config.Actionable; import appeng.api.networking.IGrid; @@ -76,10 +76,12 @@ import appeng.api.storage.channels.IItemStorageChannel; import appeng.api.storage.data.IAEItemStack; import appeng.api.storage.data.IAEStack; import appeng.api.storage.data.IItemList; +import appeng.core.Api; import appeng.crafting.CraftingJob; import appeng.crafting.CraftingLink; import appeng.crafting.CraftingLinkNexus; import appeng.crafting.CraftingWatcher; +import appeng.helpers.CraftingPatternDetails; import appeng.me.cluster.implementations.CraftingCPUCluster; import appeng.me.helpers.BaseActionSource; import appeng.me.helpers.GenericInterestManager; @@ -224,7 +226,7 @@ public class CraftingGridCache // update the stuff that was in the list... this.storageGrid.postAlterationOfStoredItems( - AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class), oldItems.keySet(), + Api.instance().storage().getStorageChannel(IItemStorageChannel.class), oldItems.keySet(), new BaseActionSource()); // re-create list.. @@ -257,7 +259,7 @@ public class CraftingGridCache } this.storageGrid.postAlterationOfStoredItems( - AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class), this.craftableItems.keySet(), + Api.instance().storage().getStorageChannel(IItemStorageChannel.class), this.craftableItems.keySet(), new BaseActionSource()); } @@ -303,6 +305,8 @@ public class CraftingGridCache @Override public void addCraftingOption(final ICraftingMedium medium, final ICraftingPatternDetails api) { + Preconditions.checkArgument(api.getClass() == CraftingPatternDetails.class, + "Only supports internal ICraftingPatternDetails for now"); List details = this.craftingMethods.get(api); if (details == null) { details = new ArrayList<>(); @@ -322,7 +326,7 @@ public class CraftingGridCache public List getCellArray(final IStorageChannel channel) { final List list = new ArrayList<>(1); - if (channel == AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)) { + if (channel == Api.instance().storage().getStorageChannel(IItemStorageChannel.class)) { list.add(this); } @@ -395,7 +399,7 @@ public class CraftingGridCache @Override public IStorageChannel getChannel() { - return AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class); + return Api.instance().storage().getStorageChannel(IItemStorageChannel.class); } @Override diff --git a/src/main/java/appeng/me/cache/GridStorageCache.java b/src/main/java/appeng/me/cache/GridStorageCache.java index e143a0248..c1996d738 100644 --- a/src/main/java/appeng/me/cache/GridStorageCache.java +++ b/src/main/java/appeng/me/cache/GridStorageCache.java @@ -28,7 +28,6 @@ import java.util.Map; import com.google.common.collect.HashMultimap; import com.google.common.collect.SetMultimap; -import appeng.api.AEApi; import appeng.api.networking.IGrid; import appeng.api.networking.IGridHost; import appeng.api.networking.IGridNode; @@ -49,6 +48,7 @@ import appeng.api.storage.cells.ICellProvider; import appeng.api.storage.data.IAEItemStack; import appeng.api.storage.data.IAEStack; import appeng.api.storage.data.IItemList; +import appeng.core.Api; import appeng.me.helpers.BaseActionSource; import appeng.me.helpers.GenericInterestManager; import appeng.me.helpers.MachineSource; @@ -71,7 +71,7 @@ public class GridStorageCache implements IStorageGrid { this.storageNetworks = new IdentityHashMap<>(); this.storageMonitors = new IdentityHashMap<>(); - AEApi.instance().storage().storageChannels() + Api.instance().storage().storageChannels() .forEach(channel -> this.storageMonitors.put(channel, new NetworkMonitor<>(this, channel))); } diff --git a/src/main/java/appeng/me/cache/PathGridCache.java b/src/main/java/appeng/me/cache/PathGridCache.java index fe5445654..e2a131d7a 100644 --- a/src/main/java/appeng/me/cache/PathGridCache.java +++ b/src/main/java/appeng/me/cache/PathGridCache.java @@ -29,7 +29,6 @@ import appeng.tile.networking.ControllerBlockEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.server.network.ServerPlayerEntity; -import appeng.api.AEApi; import appeng.api.features.AEFeature; import appeng.api.networking.GridFlags; import appeng.api.networking.IGrid; @@ -48,6 +47,7 @@ import appeng.api.networking.pathing.IPathingGrid; import appeng.api.util.AEPartLocation; import appeng.api.util.DimensionalCoord; import appeng.core.AEConfig; +import appeng.core.Api; import appeng.core.AppEng; import appeng.core.stats.IAdvancementTrigger; import appeng.me.GridConnection; @@ -287,7 +287,7 @@ public class PathGridCache implements IPathingGrid { final IAdvancementTrigger lastBracket = this.getAchievementBracket(this.lastChannels); if (currentBracket != lastBracket && currentBracket != null) { for (final IGridNode n : this.requireChannels) { - PlayerEntity player = AEApi.instance().registries().players().findPlayer(n.getPlayerID()); + PlayerEntity player = Api.instance().registries().players().findPlayer(n.getPlayerID()); if (player instanceof ServerPlayerEntity) { currentBracket.trigger((ServerPlayerEntity) player); } diff --git a/src/main/java/appeng/me/cluster/implementations/CraftingCPUCluster.java b/src/main/java/appeng/me/cluster/implementations/CraftingCPUCluster.java index 36800eec0..d6d5c6a64 100644 --- a/src/main/java/appeng/me/cluster/implementations/CraftingCPUCluster.java +++ b/src/main/java/appeng/me/cluster/implementations/CraftingCPUCluster.java @@ -35,11 +35,10 @@ import net.minecraft.nbt.ListTag; import net.minecraft.text.Text; import net.minecraft.world.World; -import appeng.api.AEApi; import appeng.api.config.Actionable; import appeng.api.config.FuzzyMode; import appeng.api.config.PowerMultiplier; -import appeng.api.implementations.ICraftingPatternItem; +import appeng.api.crafting.ICraftingHelper; import appeng.api.networking.IGrid; import appeng.api.networking.IGridHost; import appeng.api.networking.IGridNode; @@ -63,6 +62,7 @@ import appeng.api.storage.data.IItemList; import appeng.api.util.WorldCoord; import appeng.container.ContainerNull; import appeng.core.AELog; +import appeng.core.Api; import appeng.crafting.CraftBranchFailure; import appeng.crafting.CraftingJob; import appeng.crafting.CraftingLink; @@ -98,7 +98,7 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU { private MECraftingInventory inventory = new MECraftingInventory(); private IAEItemStack finalOutput; private boolean waiting = false; - private IItemList waitingFor = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class) + private IItemList waitingFor = Api.instance().storage().getStorageChannel(IItemStorageChannel.class) .createList(); private long availableStorage = 0; private MachineSource machineSrc = null; @@ -464,7 +464,7 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU { } final IItemList list; - this.getListOfItem(list = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList(), + this.getListOfItem(list = Api.instance().storage().getStorageChannel(IItemStorageChannel.class).createList(), CraftingItemList.ALL); for (final IAEItemStack is : list) { this.postChange(is, this.machineSrc); @@ -714,7 +714,7 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU { final IStorageGrid sg = g.getCache(IStorageGrid.class); final IMEInventory ii = sg - .getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)); + .getInventory(Api.instance().storage().getStorageChannel(IItemStorageChannel.class)); for (IAEItemStack is : this.inventory.getItemList()) { is = this.inventory.extractItems(is.copy(), Actionable.MODULATE, this.machineSrc); @@ -752,7 +752,7 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU { final IStorageGrid sg = g.getCache(IStorageGrid.class); final IMEInventory storage = sg - .getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)); + .getInventory(Api.instance().storage().getStorageChannel(IItemStorageChannel.class)); final MECraftingInventory ci = new MECraftingInventory(storage, true, false, false); try { @@ -782,7 +782,7 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU { this.submitLink(this.myLastLink); this.submitLink(whatLink); - final IItemList list = AEApi.instance().storage() + final IItemList list = Api.instance().storage() .getStorageChannel(IItemStorageChannel.class).createList(); this.getListOfItem(list, CraftingItemList.ALL); for (final IAEItemStack ge : list) { @@ -1054,9 +1054,9 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU { for (int x = 0; x < list.size(); x++) { final CompoundTag item = list.getCompound(x); final IAEItemStack pattern = AEItemStack.fromNBT(item); - if (pattern != null && pattern.getItem() instanceof ICraftingPatternItem) { - final ICraftingPatternItem cpi = (ICraftingPatternItem) pattern.getItem(); - final ICraftingPatternDetails details = cpi.getPatternForItem(pattern.createItemStack(), + ICraftingHelper craftingHelper = Api.instance().crafting(); + if (craftingHelper.isEncodedPattern(pattern)) { + final ICraftingPatternDetails details = craftingHelper.decodePattern(pattern.createItemStack(), this.getWorld()); if (details != null) { final TaskProgress tp = new TaskProgress(); @@ -1092,7 +1092,7 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU { } private IItemList readList(final ListTag tag) { - final IItemList out = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class) + final IItemList out = Api.instance().storage().getStorageChannel(IItemStorageChannel.class) .createList(); if (tag == null) { @@ -1129,7 +1129,7 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU { this.lastTime = System.nanoTime(); this.elapsedTime = 0; - final IItemList list = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class) + final IItemList list = Api.instance().storage().getStorageChannel(IItemStorageChannel.class) .createList(); this.getListOfItem(list, CraftingItemList.ACTIVE); diff --git a/src/main/java/appeng/me/cluster/implementations/QuantumCalculator.java b/src/main/java/appeng/me/cluster/implementations/QuantumCalculator.java index 0760275be..162cfdc17 100644 --- a/src/main/java/appeng/me/cluster/implementations/QuantumCalculator.java +++ b/src/main/java/appeng/me/cluster/implementations/QuantumCalculator.java @@ -23,10 +23,10 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.BlockView; import net.minecraft.world.World; -import appeng.api.AEApi; import appeng.api.definitions.IBlockDefinition; import appeng.api.definitions.IBlocks; import appeng.api.util.WorldCoord; +import appeng.core.Api; import appeng.me.cluster.IAECluster; import appeng.me.cluster.IAEMultiBlock; import appeng.me.cluster.MBCalculator; @@ -77,7 +77,7 @@ public class QuantumCalculator extends MBCalculator { } num++; - final IBlocks blocks = AEApi.instance().definitions().blocks(); + final IBlocks blocks = Api.instance().definitions().blocks(); if (num == 5) { if (!this.isBlockAtLocation(w, p, blocks.quantumLink())) { return false; diff --git a/src/main/java/appeng/me/cluster/implementations/QuantumCluster.java b/src/main/java/appeng/me/cluster/implementations/QuantumCluster.java index 8d3781f6f..ac17c5187 100644 --- a/src/main/java/appeng/me/cluster/implementations/QuantumCluster.java +++ b/src/main/java/appeng/me/cluster/implementations/QuantumCluster.java @@ -24,7 +24,6 @@ import net.minecraft.block.entity.BlockEntity; import net.minecraft.util.math.ChunkPos; import net.minecraft.world.World; -import appeng.api.AEApi; import appeng.api.events.LocatableEventAnnounce; import appeng.api.events.LocatableEventAnnounce.LocatableEvent; import appeng.api.exceptions.FailedConnectionException; @@ -34,6 +33,7 @@ import appeng.api.networking.IGridNode; import appeng.api.util.AEPartLocation; import appeng.api.util.WorldCoord; import appeng.core.AELog; +import appeng.core.Api; import appeng.me.cache.helpers.ConnectionWrapper; import appeng.me.cluster.IAECluster; import appeng.tile.qnb.QuantumBridgeBlockEntity; @@ -96,7 +96,7 @@ public class QuantumCluster implements ILocatable, IAECluster { } final ILocatable myOtherSide = this.otherSide == 0 ? null - : AEApi.instance().registries().locatable().getLocatableBy(this.otherSide); + : Api.instance().registries().locatable().getLocatableBy(this.otherSide); boolean shutdown = false; @@ -131,7 +131,7 @@ public class QuantumCluster implements ILocatable, IAECluster { } sideA.connection = sideB.connection = new ConnectionWrapper( - AEApi.instance().grid().createGridConnection(sideA.getNode(), sideB.getNode())); + Api.instance().grid().createGridConnection(sideA.getNode(), sideB.getNode())); } catch (final FailedConnectionException e) { // :( AELog.debug(e); @@ -153,7 +153,7 @@ public class QuantumCluster implements ILocatable, IAECluster { } private boolean canUseNode(final long qe) { - final QuantumCluster qc = (QuantumCluster) AEApi.instance().registries().locatable().getLocatableBy(qe); + final QuantumCluster qc = (QuantumCluster) Api.instance().registries().locatable().getLocatableBy(qe); if (qc != null) { final World theWorld = qc.center.getWorld(); if (!qc.isDestroyed) { diff --git a/src/main/java/appeng/me/helpers/AENetworkProxy.java b/src/main/java/appeng/me/helpers/AENetworkProxy.java index 5b020c0f2..836047003 100644 --- a/src/main/java/appeng/me/helpers/AENetworkProxy.java +++ b/src/main/java/appeng/me/helpers/AENetworkProxy.java @@ -28,7 +28,6 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundTag; import net.minecraft.util.math.Direction; -import appeng.api.AEApi; import appeng.api.networking.GridFlags; import appeng.api.networking.GridNotification; import appeng.api.networking.IGrid; @@ -45,6 +44,7 @@ import appeng.api.networking.ticking.ITickManager; import appeng.api.util.AEColor; import appeng.api.util.DimensionalCoord; import appeng.api.util.IOrientable; +import appeng.core.Api; import appeng.core.worlddata.WorldData; import appeng.hooks.TickHandler; import appeng.me.GridAccessException; @@ -129,7 +129,7 @@ public class AENetworkProxy implements IGridBlock { public IGridNode getNode() { if (this.node == null && Platform.isServer() && this.isReady) { - this.node = AEApi.instance().grid().createGridNode(this); + this.node = Api.instance().grid().createGridNode(this); this.readFromNBT(this.data); this.node.updateState(); } @@ -285,11 +285,6 @@ public class AENetworkProxy implements IGridBlock { } } - @Override - public void setNetworkStatus(final IGrid grid, final int channelsInUse) { - - } - @Override public EnumSet getConnectableSides() { return this.validSides; diff --git a/src/main/java/appeng/me/storage/CreativeCellInventory.java b/src/main/java/appeng/me/storage/CreativeCellInventory.java index 741e24366..ac554d3f3 100644 --- a/src/main/java/appeng/me/storage/CreativeCellInventory.java +++ b/src/main/java/appeng/me/storage/CreativeCellInventory.java @@ -20,7 +20,6 @@ package appeng.me.storage; import net.minecraft.item.ItemStack; -import appeng.api.AEApi; import appeng.api.config.AccessRestriction; import appeng.api.config.Actionable; import appeng.api.networking.security.IActionSource; @@ -30,12 +29,13 @@ import appeng.api.storage.cells.ICellInventoryHandler; import appeng.api.storage.channels.IItemStorageChannel; import appeng.api.storage.data.IAEItemStack; import appeng.api.storage.data.IItemList; +import appeng.core.Api; import appeng.items.contents.CellConfig; import appeng.util.item.AEItemStack; public class CreativeCellInventory implements IMEInventoryHandler { - private final IItemList itemListCache = AEApi.instance().storage() + private final IItemList itemListCache = Api.instance().storage() .getStorageChannel(IItemStorageChannel.class).createList(); protected CreativeCellInventory(final ItemStack o) { @@ -51,7 +51,7 @@ public class CreativeCellInventory implements IMEInventoryHandler public static ICellInventoryHandler getCell(final ItemStack o) { return new BasicCellInventoryHandler(new CreativeCellInventory(o), - AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)); + Api.instance().storage().getStorageChannel(IItemStorageChannel.class)); } @Override @@ -84,7 +84,7 @@ public class CreativeCellInventory implements IMEInventoryHandler @Override public IStorageChannel getChannel() { - return AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class); + return Api.instance().storage().getStorageChannel(IItemStorageChannel.class); } @Override diff --git a/src/main/java/appeng/me/storage/MEMonitorIFluidHandler.java b/src/main/java/appeng/me/storage/MEMonitorIFluidHandler.java index 78d61a1db..5232fab68 100644 --- a/src/main/java/appeng/me/storage/MEMonitorIFluidHandler.java +++ b/src/main/java/appeng/me/storage/MEMonitorIFluidHandler.java @@ -42,11 +42,12 @@ import appeng.fluids.util.AEFluidStack; import java.math.RoundingMode; import java.util.*; import java.util.Map.Entry; +import appeng.core.Api; public class MEMonitorIFluidHandler implements IMEMonitor, ITickingMonitor { private final GroupedFluidInv handler; - private final IItemList list = AEApi.instance().storage() - .getStorageChannel(IFluidStorageChannel.class).createList(); + private final IItemList list = Api.instance().storage().getStorageChannel(IFluidStorageChannel.class) + .createList(); private final HashMap, Object> listeners = new HashMap<>(); private final Map memory; private IActionSource mySource; @@ -110,7 +111,7 @@ public class MEMonitorIFluidHandler implements IMEMonitor, ITicki @Override public IStorageChannel getChannel() { - return AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class); + return Api.instance().storage().getStorageChannel(IFluidStorageChannel.class); } private static final FluidAmount MIN_EXTRACTION_AMOUNT = FluidAmount.of(1, 1000); diff --git a/src/main/java/appeng/me/storage/MEMonitorIInventory.java b/src/main/java/appeng/me/storage/MEMonitorIInventory.java index e98f28a97..ed72ad647 100644 --- a/src/main/java/appeng/me/storage/MEMonitorIInventory.java +++ b/src/main/java/appeng/me/storage/MEMonitorIInventory.java @@ -28,7 +28,6 @@ import java.util.concurrent.ConcurrentSkipListMap; import net.minecraft.item.ItemStack; -import appeng.api.AEApi; import appeng.api.config.AccessRestriction; import appeng.api.config.Actionable; import appeng.api.config.StorageFilter; @@ -40,6 +39,7 @@ import appeng.api.storage.IStorageChannel; import appeng.api.storage.channels.IItemStorageChannel; import appeng.api.storage.data.IAEItemStack; import appeng.api.storage.data.IItemList; +import appeng.core.Api; import appeng.util.InventoryAdaptor; import appeng.util.Platform; import appeng.util.inv.ItemSlot; @@ -47,7 +47,7 @@ import appeng.util.inv.ItemSlot; public class MEMonitorIInventory implements IMEMonitor, ITickingMonitor { private final InventoryAdaptor adaptor; - private final IItemList list = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class) + private final IItemList list = Api.instance().storage().getStorageChannel(IItemStorageChannel.class) .createList(); private final HashMap, Object> listeners = new HashMap<>(); private final NavigableMap memory; @@ -120,7 +120,7 @@ public class MEMonitorIInventory implements IMEMonitor, ITickingMo @Override public IStorageChannel getChannel() { - return AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class); + return Api.instance().storage().getStorageChannel(IItemStorageChannel.class); } @Override @@ -160,7 +160,7 @@ public class MEMonitorIInventory implements IMEMonitor, ITickingMo final int diff = newSize - (oldIS.isEmpty() ? 0 : oldIS.getCount()); final IAEItemStack stack = (old == null || old.aeStack == null - ? AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createStack(newIS) + ? Api.instance().storage().getStorageChannel(IItemStorageChannel.class).createStack(newIS) : old.aeStack.copy()); if (stack != null) { stack.setStackSize(newSize); @@ -302,7 +302,7 @@ public class MEMonitorIInventory implements IMEMonitor, ITickingMo this.aeStack = null; } else { this.itemStack = is.copy(); - this.aeStack = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createStack(is); + this.aeStack = Api.instance().storage().getStorageChannel(IItemStorageChannel.class).createStack(is); } } } diff --git a/src/main/java/appeng/me/storage/NullInventory.java b/src/main/java/appeng/me/storage/NullInventory.java index 4010f04f1..121a5eedf 100644 --- a/src/main/java/appeng/me/storage/NullInventory.java +++ b/src/main/java/appeng/me/storage/NullInventory.java @@ -18,7 +18,6 @@ package appeng.me.storage; -import appeng.api.AEApi; import appeng.api.config.AccessRestriction; import appeng.api.config.Actionable; import appeng.api.networking.security.IActionSource; @@ -27,6 +26,7 @@ import appeng.api.storage.IStorageChannel; import appeng.api.storage.channels.IItemStorageChannel; import appeng.api.storage.data.IAEStack; import appeng.api.storage.data.IItemList; +import appeng.core.Api; public class NullInventory> implements IMEInventoryHandler { @@ -47,7 +47,7 @@ public class NullInventory> implements IMEInventoryHandler @Override public IStorageChannel getChannel() { - return AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class); + return Api.instance().storage().getStorageChannel(IItemStorageChannel.class); } @Override diff --git a/src/main/java/appeng/me/storage/SecurityStationInventory.java b/src/main/java/appeng/me/storage/SecurityStationInventory.java index 2f20548f5..743e46895 100644 --- a/src/main/java/appeng/me/storage/SecurityStationInventory.java +++ b/src/main/java/appeng/me/storage/SecurityStationInventory.java @@ -20,7 +20,6 @@ package appeng.me.storage; import com.mojang.authlib.GameProfile; -import appeng.api.AEApi; import appeng.api.config.AccessRestriction; import appeng.api.config.Actionable; import appeng.api.config.SecurityPermissions; @@ -31,12 +30,13 @@ import appeng.api.storage.IStorageChannel; import appeng.api.storage.channels.IItemStorageChannel; import appeng.api.storage.data.IAEItemStack; import appeng.api.storage.data.IItemList; +import appeng.core.Api; import appeng.me.GridAccessException; import appeng.tile.misc.SecurityStationBlockEntity; public class SecurityStationInventory implements IMEInventoryHandler { - private final IItemList storedItems = AEApi.instance().storage() + private final IItemList storedItems = Api.instance().storage() .getStorageChannel(IItemStorageChannel.class).createList(); private final SecurityStationBlockEntity securityTile; @@ -47,7 +47,7 @@ public class SecurityStationInventory implements IMEInventoryHandler iface = definitions.blocks().iface().maybeStack(1); if (iface.isPresent()) { diff --git a/src/main/java/appeng/parts/CableBusContainer.java b/src/main/java/appeng/parts/CableBusContainer.java index 416714f2a..a285bac06 100644 --- a/src/main/java/appeng/parts/CableBusContainer.java +++ b/src/main/java/appeng/parts/CableBusContainer.java @@ -19,7 +19,11 @@ package appeng.parts; import java.io.IOException; -import java.util.*; +import java.util.ArrayList; +import java.util.EnumSet; +import java.util.List; +import java.util.Random; +import java.util.Set; import javax.annotation.Nullable; @@ -44,13 +48,20 @@ import net.minecraft.util.shape.VoxelShapes; import net.minecraft.world.BlockView; import net.minecraft.world.World; -import appeng.api.AEApi; import appeng.api.config.YesNo; import appeng.api.exceptions.FailedConnectionException; import appeng.api.implementations.parts.ICablePart; import appeng.api.networking.IGridHost; import appeng.api.networking.IGridNode; -import appeng.api.parts.*; +import appeng.api.parts.IFacadeContainer; +import appeng.api.parts.IFacadePart; +import appeng.api.parts.IPart; +import appeng.api.parts.IPartCollisionHelper; +import appeng.api.parts.IPartHost; +import appeng.api.parts.IPartItem; +import appeng.api.parts.LayerFlags; +import appeng.api.parts.PartItemStack; +import appeng.api.parts.SelectedPart; import appeng.api.util.AECableType; import appeng.api.util.AEColor; import appeng.api.util.AEPartLocation; @@ -59,6 +70,7 @@ import appeng.client.render.cablebus.CableBusRenderState; import appeng.client.render.cablebus.CableCoreType; import appeng.client.render.cablebus.FacadeRenderState; import appeng.core.AELog; +import appeng.core.Api; import appeng.facade.FacadeContainer; import appeng.helpers.AEMultiTile; import appeng.me.GridConnection; @@ -360,7 +372,7 @@ public class CableBusContainer extends CableBusStorage implements AEMultiTile, I } } - if (AEApi.instance().partHelper().getCableRenderMode().opaqueFacades) { + if (Api.instance().partHelper().getCableRenderMode().opaqueFacades) { final IFacadeContainer fc = this.getFacadeContainer(); for (final AEPartLocation side : AEPartLocation.SIDE_LOCATIONS) { final IFacadePart p = fc.getFacade(side); @@ -525,7 +537,7 @@ public class CableBusContainer extends CableBusStorage implements AEMultiTile, I final IGridNode cn = center.getGridNode(); if (cn != null) { try { - AEApi.instance().grid().createGridConnection(cn, sn); + Api.instance().grid().createGridConnection(cn, sn); } catch (final FailedConnectionException e) { // ekk AELog.debug(e); @@ -1075,7 +1087,7 @@ public class CableBusContainer extends CableBusStorage implements AEMultiTile, I part.getBoxes(bch); } - if (AEApi.instance().partHelper().getCableRenderMode().opaqueFacades || forCollision) { + if (Api.instance().partHelper().getCableRenderMode().opaqueFacades || forCollision) { if (s != AEPartLocation.INTERNAL) { final IFacadePart fp = fc.getFacade(s); if (fp != null) { diff --git a/src/main/java/appeng/parts/PartPlacement.java b/src/main/java/appeng/parts/PartPlacement.java index 1327799c0..78747b900 100644 --- a/src/main/java/appeng/parts/PartPlacement.java +++ b/src/main/java/appeng/parts/PartPlacement.java @@ -23,6 +23,7 @@ import appeng.api.definitions.IBlockDefinition; import appeng.api.parts.*; import appeng.api.util.AEPartLocation; import appeng.api.util.DimensionalCoord; +import appeng.core.Api; import appeng.core.AppEng; import appeng.core.sync.network.NetworkHandler; import appeng.core.sync.packets.PartPlacementPacket; @@ -192,7 +193,7 @@ public class PartPlacement { BlockPos te_pos = pos; - final IBlockDefinition multiPart = AEApi.instance().definitions().blocks().multiPart(); + final IBlockDefinition multiPart = Api.instance().definitions().blocks().multiPart(); if (host == null && pass == PlaceType.PLACE_ITEM) { Direction offset = null; diff --git a/src/main/java/appeng/parts/automation/AnnihilationPlanePart.java b/src/main/java/appeng/parts/automation/AnnihilationPlanePart.java index ac323f11d..9d20f79b1 100644 --- a/src/main/java/appeng/parts/automation/AnnihilationPlanePart.java +++ b/src/main/java/appeng/parts/automation/AnnihilationPlanePart.java @@ -49,7 +49,6 @@ import net.minecraft.world.BlockView; import net.minecraft.world.World; import net.minecraft.server.world.ServerWorld; -import appeng.api.AEApi; import appeng.api.config.Actionable; import appeng.api.config.PowerMultiplier; import appeng.api.networking.IGridNode; @@ -70,6 +69,7 @@ import appeng.api.storage.channels.IItemStorageChannel; import appeng.api.storage.data.IAEItemStack; import appeng.api.util.AECableType; import appeng.api.util.AEPartLocation; +import appeng.core.Api; import appeng.core.AppEng; import appeng.core.settings.TickRates; import appeng.core.sync.packets.BlockTransitionEffectPacket; @@ -327,7 +327,7 @@ public class AnnihilationPlanePart extends BasicStatePart implements IGridTickab final IStorageGrid storage = this.getProxy().getStorage(); final IEnergyGrid energy = this.getProxy().getEnergy(); final IAEItemStack overflow = Platform.poweredInsert(energy, - storage.getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)), + storage.getInventory(Api.instance().storage().getStorageChannel(IItemStorageChannel.class)), itemToStore, this.mySrc); this.isAccepting = overflow == null; @@ -543,7 +543,7 @@ public class AnnihilationPlanePart extends BasicStatePart implements IGridTickab for (final ItemStack itemStack : itemStacks) { final IAEItemStack itemToTest = AEItemStack.fromItemStack(itemStack); final IAEItemStack overflow = storage - .getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)) + .getInventory(Api.instance().storage().getStorageChannel(IItemStorageChannel.class)) .injectItems(itemToTest, Actionable.SIMULATE, this.mySrc); if (overflow == null || itemToTest.getStackSize() > overflow.getStackSize()) { canStore = true; diff --git a/src/main/java/appeng/parts/automation/BlockUpgradeInventory.java b/src/main/java/appeng/parts/automation/BlockUpgradeInventory.java index d7e662ad2..71e887d95 100644 --- a/src/main/java/appeng/parts/automation/BlockUpgradeInventory.java +++ b/src/main/java/appeng/parts/automation/BlockUpgradeInventory.java @@ -19,9 +19,6 @@ package appeng.parts.automation; import net.minecraft.block.Block; -import net.minecraft.item.BlockItem; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; import appeng.api.config.Upgrades; import appeng.util.inv.IAEAppEngInventory; diff --git a/src/main/java/appeng/parts/automation/DefinitionUpgradeInventory.java b/src/main/java/appeng/parts/automation/DefinitionUpgradeInventory.java index 3b6ad729e..4ac3d2d75 100644 --- a/src/main/java/appeng/parts/automation/DefinitionUpgradeInventory.java +++ b/src/main/java/appeng/parts/automation/DefinitionUpgradeInventory.java @@ -18,8 +18,6 @@ package appeng.parts.automation; -import net.minecraft.item.ItemStack; - import appeng.api.config.Upgrades; import appeng.api.definitions.IItemDefinition; import appeng.util.inv.IAEAppEngInventory; diff --git a/src/main/java/appeng/parts/automation/ExportBusPart.java b/src/main/java/appeng/parts/automation/ExportBusPart.java index 9191ce2ad..699b939d5 100644 --- a/src/main/java/appeng/parts/automation/ExportBusPart.java +++ b/src/main/java/appeng/parts/automation/ExportBusPart.java @@ -28,7 +28,6 @@ import net.minecraft.util.Hand; import net.minecraft.util.Identifier; import net.minecraft.util.math.Vec3d; -import appeng.api.AEApi; import appeng.api.config.Actionable; import appeng.api.config.FuzzyMode; import appeng.api.config.PowerMultiplier; @@ -56,6 +55,7 @@ import appeng.container.ContainerLocator; import appeng.container.ContainerOpener; import appeng.container.implementations.UpgradeableContainer; import appeng.core.AELog; +import appeng.core.Api; import appeng.core.AppEng; import appeng.core.settings.TickRates; import appeng.helpers.MultiCraftingTracker; @@ -125,7 +125,7 @@ public class ExportBusPart extends SharedItemBusPart implements ICraftingRequest try { final InventoryAdaptor destination = this.getHandler(); final IMEMonitor inv = this.getProxy().getStorage() - .getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)); + .getInventory(Api.instance().storage().getStorageChannel(IItemStorageChannel.class)); final IEnergyGrid energy = this.getProxy().getEnergy(); final ICraftingGrid cg = this.getProxy().getCrafting(); final FuzzyMode fzMode = (FuzzyMode) this.getConfigManager().getSetting(Settings.FUZZY_MODE); diff --git a/src/main/java/appeng/parts/automation/FormationPlanePart.java b/src/main/java/appeng/parts/automation/FormationPlanePart.java index c968cafd6..04988b325 100644 --- a/src/main/java/appeng/parts/automation/FormationPlanePart.java +++ b/src/main/java/appeng/parts/automation/FormationPlanePart.java @@ -19,7 +19,6 @@ package appeng.parts.automation; import alexiil.mc.lib.attributes.item.FixedItemInv; -import appeng.api.AEApi; import appeng.api.config.*; import appeng.api.networking.events.MENetworkCellArrayUpdate; import appeng.api.networking.events.MENetworkChannelsChanged; @@ -38,6 +37,7 @@ import appeng.container.ContainerLocator; import appeng.container.ContainerOpener; import appeng.container.implementations.FormationPlaneContainer; import appeng.core.AEConfig; +import appeng.core.Api; import appeng.items.parts.PartModels; import appeng.me.GridAccessException; import appeng.me.storage.MEInventoryHandler; @@ -79,7 +79,7 @@ public class FormationPlanePart extends AbstractFormationPlanePart } private final MEInventoryHandler myHandler = new MEInventoryHandler<>(this, - AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)); + Api.instance().storage().getStorageChannel(IItemStorageChannel.class)); private final AppEngInternalAEInventory Config = new AppEngInternalAEInventory(this, 63); public FormationPlanePart(final ItemStack is) { @@ -97,7 +97,7 @@ public class FormationPlanePart extends AbstractFormationPlanePart this.getInstalledUpgrades(Upgrades.INVERTER) > 0 ? IncludeExclude.BLACKLIST : IncludeExclude.WHITELIST); this.myHandler.setPriority(this.getPriority()); - final IItemList priorityList = AEApi.instance().storage() + final IItemList priorityList = Api.instance().storage() .getStorageChannel(IItemStorageChannel.class).createList(); final int slotsToUse = 18 + this.getInstalledUpgrades(Upgrades.CAPACITY) * 9; @@ -176,7 +176,7 @@ public class FormationPlanePart extends AbstractFormationPlanePart @Override public List getCellArray(final IStorageChannel channel) { if (this.getProxy().isActive() - && channel == AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)) { + && channel == Api.instance().storage().getStorageChannel(IItemStorageChannel.class)) { final List handler = new ArrayList<>(1); handler.add(this.myHandler); return handler; @@ -317,7 +317,7 @@ public class FormationPlanePart extends AbstractFormationPlanePart @Override public IStorageChannel getChannel() { - return AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class); + return Api.instance().storage().getStorageChannel(IItemStorageChannel.class); } @Override @@ -332,7 +332,7 @@ public class FormationPlanePart extends AbstractFormationPlanePart @Override public ItemStack getItemStackRepresentation() { - return AEApi.instance().definitions().parts().formationPlane().maybeStack(1).orElse(ItemStack.EMPTY); + return Api.instance().definitions().parts().formationPlane().maybeStack(1).orElse(ItemStack.EMPTY); } @Override diff --git a/src/main/java/appeng/parts/automation/ImportBusPart.java b/src/main/java/appeng/parts/automation/ImportBusPart.java index be3f0c899..80ce2b6ed 100644 --- a/src/main/java/appeng/parts/automation/ImportBusPart.java +++ b/src/main/java/appeng/parts/automation/ImportBusPart.java @@ -25,7 +25,6 @@ import net.minecraft.util.Hand; import net.minecraft.util.Identifier; import net.minecraft.util.math.Vec3d; -import appeng.api.AEApi; import appeng.api.config.Actionable; import appeng.api.config.FuzzyMode; import appeng.api.config.RedstoneMode; @@ -46,6 +45,7 @@ import appeng.api.util.AECableType; import appeng.container.ContainerLocator; import appeng.container.ContainerOpener; import appeng.container.implementations.UpgradeableContainer; +import appeng.core.Api; import appeng.core.AppEng; import appeng.core.settings.TickRates; @@ -92,10 +92,10 @@ public class ImportBusPart extends SharedItemBusPart implements IInventoryDestin try { final IMEMonitor inv = this.getProxy().getStorage() - .getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)); + .getInventory(Api.instance().storage().getStorageChannel(IItemStorageChannel.class)); final IAEItemStack out = inv.injectItems( - AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createStack(stack), + Api.instance().storage().getStorageChannel(IItemStorageChannel.class).createStack(stack), Actionable.SIMULATE, this.source); if (out == null) { return true; @@ -152,7 +152,7 @@ public class ImportBusPart extends SharedItemBusPart implements IInventoryDestin this.itemsToSend = this.calculateItemsToSend(); final IMEMonitor inv = this.getProxy().getStorage() - .getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)); + .getInventory(Api.instance().storage().getStorageChannel(IItemStorageChannel.class)); final IEnergyGrid energy = this.getProxy().getEnergy(); boolean Configured = false; @@ -199,7 +199,7 @@ public class ImportBusPart extends SharedItemBusPart implements IInventoryDestin } if (!newItems.isEmpty()) { - final IAEItemStack aeStack = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class) + final IAEItemStack aeStack = Api.instance().storage().getStorageChannel(IItemStorageChannel.class) .createStack(newItems); final IAEItemStack failed = Platform.poweredInsert(energy, inv, aeStack, this.source); diff --git a/src/main/java/appeng/parts/automation/LevelEmitterPart.java b/src/main/java/appeng/parts/automation/LevelEmitterPart.java index 611864e22..19eda5151 100644 --- a/src/main/java/appeng/parts/automation/LevelEmitterPart.java +++ b/src/main/java/appeng/parts/automation/LevelEmitterPart.java @@ -34,7 +34,6 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; -import appeng.api.AEApi; import appeng.api.config.FuzzyMode; import appeng.api.config.LevelType; import appeng.api.config.RedstoneMode; @@ -73,6 +72,7 @@ import appeng.api.util.IConfigManager; import appeng.container.ContainerLocator; import appeng.container.ContainerOpener; import appeng.container.implementations.LevelEmitterContainer; +import appeng.core.Api; import appeng.core.AppEng; import appeng.items.parts.PartModels; import appeng.me.GridAccessException; @@ -250,7 +250,7 @@ public class LevelEmitterPart extends UpgradeablePart implements IEnergyWatcherH // no more item stuff.. this.getProxy().getStorage() - .getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)) + .getInventory(Api.instance().storage().getStorageChannel(IItemStorageChannel.class)) .removeListener(this); } catch (final GridAccessException e) { // :P @@ -262,11 +262,11 @@ public class LevelEmitterPart extends UpgradeablePart implements IEnergyWatcherH try { if (this.getInstalledUpgrades(Upgrades.FUZZY) > 0 || myStack == null) { this.getProxy().getStorage() - .getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)) + .getInventory(Api.instance().storage().getStorageChannel(IItemStorageChannel.class)) .addListener(this, this.getProxy().getGrid()); } else { this.getProxy().getStorage() - .getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)) + .getInventory(Api.instance().storage().getStorageChannel(IItemStorageChannel.class)) .removeListener(this); if (this.myWatcher != null) { @@ -275,7 +275,7 @@ public class LevelEmitterPart extends UpgradeablePart implements IEnergyWatcherH } this.updateReportingValue(this.getProxy().getStorage() - .getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class))); + .getInventory(Api.instance().storage().getStorageChannel(IItemStorageChannel.class))); } catch (final GridAccessException e) { // >.> } @@ -317,7 +317,7 @@ public class LevelEmitterPart extends UpgradeablePart implements IEnergyWatcherH @Override public void onStackChange(final IItemList o, final IAEStack fullStack, final IAEStack diffStack, final IActionSource src, final IStorageChannel chan) { - if (chan == AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class) + if (chan == Api.instance().storage().getStorageChannel(IItemStorageChannel.class) && fullStack.equals(this.config.getAEStackInSlot(0)) && this.getInstalledUpgrades(Upgrades.FUZZY) == 0) { this.lastReportedValue = fullStack.getStackSize(); @@ -356,7 +356,7 @@ public class LevelEmitterPart extends UpgradeablePart implements IEnergyWatcherH public void onListUpdate() { try { this.updateReportingValue(this.getProxy().getStorage() - .getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class))); + .getInventory(Api.instance().storage().getStorageChannel(IItemStorageChannel.class))); } catch (final GridAccessException e) { // ;P } diff --git a/src/main/java/appeng/parts/misc/InterfacePart.java b/src/main/java/appeng/parts/misc/InterfacePart.java index d3e7b9838..dc46cb96d 100644 --- a/src/main/java/appeng/parts/misc/InterfacePart.java +++ b/src/main/java/appeng/parts/misc/InterfacePart.java @@ -36,7 +36,6 @@ import net.minecraft.util.Hand; import net.minecraft.util.Identifier; import net.minecraft.util.math.Vec3d; -import appeng.api.AEApi; import appeng.api.config.Actionable; import appeng.api.config.Upgrades; import appeng.api.networking.IGridNode; @@ -61,6 +60,7 @@ import appeng.api.util.IConfigManager; import appeng.container.ContainerLocator; import appeng.container.ContainerOpener; import appeng.container.implementations.InterfaceContainer; +import appeng.core.Api; import appeng.core.AppEng; import appeng.helpers.DualityInterface; import appeng.helpers.IInterfaceHost; @@ -267,7 +267,7 @@ public class InterfacePart extends BasicStatePart implements IGridTickable, ISto @Override public ItemStack getItemStackRepresentation() { - return AEApi.instance().definitions().parts().iface().maybeStack(1).orElse(ItemStack.EMPTY); + return Api.instance().definitions().parts().iface().maybeStack(1).orElse(ItemStack.EMPTY); } @Override diff --git a/src/main/java/appeng/parts/misc/ItemHandlerAdapter.java b/src/main/java/appeng/parts/misc/ItemHandlerAdapter.java index 903b053c3..f94d1d498 100644 --- a/src/main/java/appeng/parts/misc/ItemHandlerAdapter.java +++ b/src/main/java/appeng/parts/misc/ItemHandlerAdapter.java @@ -29,7 +29,6 @@ import alexiil.mc.lib.attributes.Simulation; import alexiil.mc.lib.attributes.item.FixedItemInv; import net.minecraft.item.ItemStack; -import appeng.api.AEApi; import appeng.api.config.Actionable; import appeng.api.networking.security.IActionSource; import appeng.api.networking.storage.IBaseMonitor; @@ -40,6 +39,7 @@ import appeng.api.storage.channels.IItemStorageChannel; import appeng.api.storage.data.IAEItemStack; import appeng.api.storage.data.IItemList; import appeng.core.AELog; +import appeng.core.Api; import appeng.me.GridAccessException; import appeng.me.helpers.IGridProxyable; import appeng.me.storage.ITickingMonitor; @@ -193,7 +193,7 @@ class ItemHandlerAdapter implements IMEInventory, IBaseMonitor in = this.getInternalHandler(); - IItemList before = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class) + IItemList before = Api.instance().storage().getStorageChannel(IItemStorageChannel.class) .createList(); if (in != null) { before = in.getAvailableItems(before); @@ -319,7 +319,7 @@ public class StorageBusPart extends UpgradeablePart final IMEInventory out = this.getInternalHandler(); if (in != out) { - IItemList after = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class) + IItemList after = Api.instance().storage().getStorageChannel(IItemStorageChannel.class) .createList(); if (out != null) { after = out.getAvailableItems(after); @@ -338,7 +338,7 @@ public class StorageBusPart extends UpgradeablePart if (accessor != null) { IStorageMonitorable inventory = accessor.getInventory(this.mySrc); if (inventory != null) { - return inventory.getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)); + return inventory.getInventory(Api.instance().storage().getStorageChannel(IItemStorageChannel.class)); } // So this could / can be a design decision. If the tile does support our custom @@ -426,14 +426,14 @@ public class StorageBusPart extends UpgradeablePart this.checkInterfaceVsStorageBus(target, this.getSide().getOpposite()); this.handler = new MEInventoryHandler(inv, - AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)); + Api.instance().storage().getStorageChannel(IItemStorageChannel.class)); this.handler.setBaseAccess((AccessRestriction) this.getConfigManager().getSetting(Settings.ACCESS)); this.handler.setWhitelist(this.getInstalledUpgrades(Upgrades.INVERTER) > 0 ? IncludeExclude.BLACKLIST : IncludeExclude.WHITELIST); this.handler.setPriority(this.priority); - final IItemList priorityList = AEApi.instance().storage() + final IItemList priorityList = Api.instance().storage() .getStorageChannel(IItemStorageChannel.class).createList(); final int slotsToUse = 18 + this.getInstalledUpgrades(Upgrades.CAPACITY) * 9; @@ -506,7 +506,7 @@ public class StorageBusPart extends UpgradeablePart @Override public List getCellArray(final IStorageChannel channel) { - if (channel == AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)) { + if (channel == Api.instance().storage().getStorageChannel(IItemStorageChannel.class)) { final IMEInventoryHandler out = this.getProxy().isActive() ? this.getInternalHandler() : null; if (out != null) { return Collections.singletonList(out); @@ -558,7 +558,7 @@ public class StorageBusPart extends UpgradeablePart @Override public ItemStack getItemStackRepresentation() { - return AEApi.instance().definitions().parts().storageBus().maybeStack(1).orElse(ItemStack.EMPTY); + return Api.instance().definitions().parts().storageBus().maybeStack(1).orElse(ItemStack.EMPTY); } @Override diff --git a/src/main/java/appeng/parts/misc/ToggleBusPart.java b/src/main/java/appeng/parts/misc/ToggleBusPart.java index 97593d876..be99f9b5e 100644 --- a/src/main/java/appeng/parts/misc/ToggleBusPart.java +++ b/src/main/java/appeng/parts/misc/ToggleBusPart.java @@ -29,7 +29,6 @@ import net.minecraft.util.Identifier; import net.minecraft.util.math.BlockPos; import net.minecraft.world.BlockView; -import appeng.api.AEApi; import appeng.api.exceptions.FailedConnectionException; import appeng.api.networking.IGridConnection; import appeng.api.networking.IGridNode; @@ -39,6 +38,7 @@ import appeng.api.parts.IPartModel; import appeng.api.util.AECableType; import appeng.api.util.AEPartLocation; import appeng.core.AELog; +import appeng.core.Api; import appeng.core.AppEng; import appeng.items.parts.PartModels; import appeng.me.helpers.AENetworkProxy; @@ -166,7 +166,7 @@ public class ToggleBusPart extends BasicStatePart { if (this.getProxy().getNode() != null && this.getOuterProxy().getNode() != null) { if (intention) { try { - this.connection = AEApi.instance().grid().createGridConnection(this.getProxy().getNode(), + this.connection = Api.instance().grid().createGridConnection(this.getProxy().getNode(), this.getOuterProxy().getNode()); } catch (final FailedConnectionException e) { // :( diff --git a/src/main/java/appeng/parts/networking/CablePart.java b/src/main/java/appeng/parts/networking/CablePart.java index 4234b13b2..86a3aed97 100644 --- a/src/main/java/appeng/parts/networking/CablePart.java +++ b/src/main/java/appeng/parts/networking/CablePart.java @@ -27,7 +27,6 @@ import net.minecraft.nbt.CompoundTag; import net.minecraft.network.PacketByteBuf; import net.minecraft.util.math.Direction; -import appeng.api.AEApi; import appeng.api.config.SecurityPermissions; import appeng.api.definitions.IParts; import appeng.api.implementations.parts.ICablePart; @@ -43,6 +42,7 @@ import appeng.api.util.AECableType; import appeng.api.util.AEColor; import appeng.api.util.AEPartLocation; import appeng.api.util.IReadOnlyCollection; +import appeng.core.Api; import appeng.items.parts.ColoredPartItem; import appeng.me.GridAccessException; import appeng.parts.AEBasePart; @@ -96,7 +96,7 @@ public class CablePart extends AEBasePart implements ICablePart { if (this.getCableColor() != newColor) { ItemStack newPart = null; - final IParts parts = AEApi.instance().definitions().parts(); + final IParts parts = Api.instance().definitions().parts(); if (this.getCableConnectionType() == AECableType.GLASS) { newPart = parts.cableGlass().stack(newColor, 1); diff --git a/src/main/java/appeng/parts/p2p/MEP2PTunnelPart.java b/src/main/java/appeng/parts/p2p/MEP2PTunnelPart.java index ac526a1a6..4dfd22eac 100644 --- a/src/main/java/appeng/parts/p2p/MEP2PTunnelPart.java +++ b/src/main/java/appeng/parts/p2p/MEP2PTunnelPart.java @@ -29,7 +29,6 @@ import net.minecraft.nbt.CompoundTag; import net.minecraft.block.entity.BlockEntity; import net.minecraft.util.Hand; -import appeng.api.AEApi; import appeng.api.exceptions.FailedConnectionException; import appeng.api.networking.GridFlags; import appeng.api.networking.IGridNode; @@ -41,6 +40,7 @@ import appeng.api.parts.IPartModel; import appeng.api.util.AECableType; import appeng.api.util.AEPartLocation; import appeng.core.AELog; +import appeng.core.Api; import appeng.core.settings.TickRates; import appeng.hooks.TickHandler; import appeng.items.parts.PartModels; @@ -193,7 +193,7 @@ public class MEP2PTunnelPart extends P2PTunnelPart implements I for (final MEP2PTunnelPart me : newSides) { try { - connections.getConnections().put(me.getGridNode(), new TunnelConnection(me, AEApi.instance() + connections.getConnections().put(me.getGridNode(), new TunnelConnection(me, Api.instance() .grid().createGridConnection(this.outerProxy.getNode(), me.outerProxy.getNode()))); } catch (final FailedConnectionException e) { final BlockEntity start = this.getTile(); diff --git a/src/main/java/appeng/parts/p2p/P2PTunnelPart.java b/src/main/java/appeng/parts/p2p/P2PTunnelPart.java index 12640fd21..c9b7f528a 100644 --- a/src/main/java/appeng/parts/p2p/P2PTunnelPart.java +++ b/src/main/java/appeng/parts/p2p/P2PTunnelPart.java @@ -31,7 +31,6 @@ import net.minecraft.util.Hand; import net.minecraft.util.math.Vec3d; -import appeng.api.AEApi; import appeng.api.config.Actionable; import appeng.api.config.PowerMultiplier; import appeng.api.config.PowerUnits; @@ -47,6 +46,7 @@ import appeng.api.util.AECableType; import appeng.api.util.AEColor; import appeng.api.util.AEPartLocation; import appeng.core.AEConfig; +import appeng.core.Api; import appeng.me.GridAccessException; import appeng.me.cache.P2PCache; import appeng.me.cache.helpers.TunnelCollection; @@ -109,7 +109,7 @@ public abstract class P2PTunnelPart extends BasicStateP return super.getItemStack(type); } - final Optional maybeMEStack = AEApi.instance().definitions().parts().p2PTunnelME().maybeStack(1); + final Optional maybeMEStack = Api.instance().definitions().parts().p2PTunnelME().maybeStack(1); if (maybeMEStack.isPresent()) { return maybeMEStack.get(); } @@ -167,7 +167,7 @@ public abstract class P2PTunnelPart extends BasicStateP final ItemStack is = player.getStackInHand(hand); - final TunnelType tt = AEApi.instance().registries().p2pTunnel().getTunnelTypeByItem(is); + final TunnelType tt = Api.instance().registries().p2pTunnel().getTunnelTypeByItem(is); if (!is.isEmpty() && is.getItem() instanceof IMemoryCard) { final IMemoryCard mc = (IMemoryCard) is.getItem(); final CompoundTag data = mc.getData(is); @@ -207,7 +207,7 @@ public abstract class P2PTunnelPart extends BasicStateP { final ItemStack newType; - final IParts parts = AEApi.instance().definitions().parts(); + final IParts parts = Api.instance().definitions().parts(); switch (tt) { case LIGHT: diff --git a/src/main/java/appeng/parts/reporting/AbstractMonitorPart.java b/src/main/java/appeng/parts/reporting/AbstractMonitorPart.java index b5e16427b..02728ce3d 100644 --- a/src/main/java/appeng/parts/reporting/AbstractMonitorPart.java +++ b/src/main/java/appeng/parts/reporting/AbstractMonitorPart.java @@ -35,7 +35,6 @@ import net.minecraft.util.math.Vec3d; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import appeng.api.AEApi; import appeng.api.implementations.parts.IStorageMonitorPart; import appeng.api.networking.security.IActionSource; import appeng.api.networking.storage.IStackWatcher; @@ -48,6 +47,7 @@ import appeng.api.storage.data.IAEItemStack; import appeng.api.storage.data.IAEStack; import appeng.api.storage.data.IItemList; import appeng.client.render.TesrRenderHelper; +import appeng.core.Api; import appeng.core.localization.PlayerMessages; import appeng.me.GridAccessException; @@ -200,7 +200,7 @@ public abstract class AbstractMonitorPart extends AbstractDisplayPart } this.updateReportingValue(this.getProxy().getStorage() - .getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class))); + .getInventory(Api.instance().storage().getStorageChannel(IItemStorageChannel.class))); } } catch (final GridAccessException e) { // >.> diff --git a/src/main/java/appeng/parts/reporting/ConversionMonitorPart.java b/src/main/java/appeng/parts/reporting/ConversionMonitorPart.java index dabf23546..43e763bfa 100644 --- a/src/main/java/appeng/parts/reporting/ConversionMonitorPart.java +++ b/src/main/java/appeng/parts/reporting/ConversionMonitorPart.java @@ -32,12 +32,12 @@ import net.minecraft.util.Identifier; import net.minecraft.util.math.Vec3d; import alexiil.mc.lib.attributes.item.FixedItemInv; -import appeng.api.AEApi; import appeng.api.networking.energy.IEnergySource; import appeng.api.parts.IPartModel; import appeng.api.storage.IMEMonitor; import appeng.api.storage.channels.IItemStorageChannel; import appeng.api.storage.data.IAEItemStack; +import appeng.core.Api; import appeng.core.AppEng; import appeng.items.parts.PartModels; import appeng.me.GridAccessException; @@ -153,7 +153,7 @@ public class ConversionMonitorPart extends AbstractMonitorPart { try { final IEnergySource energy = this.getProxy().getEnergy(); final IMEMonitor cell = this.getProxy().getStorage() - .getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)); + .getInventory(Api.instance().storage().getStorageChannel(IItemStorageChannel.class)); if (allItems) { if (this.getDisplayed() != null) { @@ -196,7 +196,7 @@ public class ConversionMonitorPart extends AbstractMonitorPart { final IEnergySource energy = this.getProxy().getEnergy(); final IMEMonitor cell = this.getProxy().getStorage() - .getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)); + .getInventory(Api.instance().storage().getStorageChannel(IItemStorageChannel.class)); input.setStackSize(count); diff --git a/src/main/java/appeng/parts/reporting/PatternTerminalPart.java b/src/main/java/appeng/parts/reporting/PatternTerminalPart.java index 5e656e409..99a9d6b7c 100644 --- a/src/main/java/appeng/parts/reporting/PatternTerminalPart.java +++ b/src/main/java/appeng/parts/reporting/PatternTerminalPart.java @@ -28,12 +28,12 @@ import net.minecraft.util.Identifier; import alexiil.mc.lib.attributes.item.FixedItemInv; import appeng.api.config.SecurityPermissions; -import appeng.api.implementations.ICraftingPatternItem; import appeng.api.networking.crafting.ICraftingPatternDetails; import appeng.api.parts.IPartModel; import appeng.api.storage.data.IAEItemStack; import appeng.container.implementations.MEMonitorableContainer; import appeng.container.implementations.PatternTermContainer; +import appeng.core.Api; import appeng.core.AppEng; import appeng.items.parts.PartModels; import appeng.parts.PartModel; @@ -105,23 +105,20 @@ public class PatternTerminalPart extends AbstractTerminalPart { final ItemStack removedStack, final ItemStack newStack) { if (inv == this.pattern && slot == 1) { final ItemStack is = this.pattern.getInvStack(1); - if (!is.isEmpty() && is.getItem() instanceof ICraftingPatternItem) { - final ICraftingPatternItem pattern = (ICraftingPatternItem) is.getItem(); - final ICraftingPatternDetails details = pattern.getPatternForItem(is, - this.getHost().getTile().getWorld()); - if (details != null) { - this.setCraftingRecipe(details.isCraftable()); - this.setSubstitution(details.canSubstitute()); + final ICraftingPatternDetails details = Api.instance().crafting().decodePattern(is, + this.getHost().getTile().getWorld()); + if (details != null) { + this.setCraftingRecipe(details.isCraftable()); + this.setSubstitution(details.canSubstitute()); - for (int x = 0; x < this.crafting.getSlotCount() && x < details.getInputs().length; x++) { - final IAEItemStack item = details.getInputs()[x]; - this.crafting.forceSetInvStack(x, item == null ? ItemStack.EMPTY : item.createItemStack()); - } + for (int x = 0; x < this.crafting.getSlotCount() && x < details.getInputs().length; x++) { + final IAEItemStack item = details.getInputs()[x]; + this.crafting.forceSetInvStack(x, item == null ? ItemStack.EMPTY : item.createItemStack()); + } - for (int x = 0; x < this.output.getSlotCount() && x < details.getOutputs().length; x++) { - final IAEItemStack item = details.getOutputs()[x]; - this.output.forceSetInvStack(x, item == null ? ItemStack.EMPTY : item.createItemStack()); - } + for (int x = 0; x < this.output.getSlotCount() && x < details.getOutputs().length; x++) { + final IAEItemStack item = details.getOutputs()[x]; + this.output.forceSetInvStack(x, item == null ? ItemStack.EMPTY : item.createItemStack()); } } } else if (inv == this.crafting) { diff --git a/src/main/java/appeng/services/CompassService.java b/src/main/java/appeng/services/CompassService.java index d50d8d11b..d347fb4e6 100644 --- a/src/main/java/appeng/services/CompassService.java +++ b/src/main/java/appeng/services/CompassService.java @@ -38,8 +38,8 @@ import net.minecraft.world.chunk.Chunk; import net.minecraft.world.dimension.DimensionType; import net.minecraft.server.world.ServerWorld; -import appeng.api.AEApi; import appeng.api.util.DimensionalCoord; +import appeng.core.Api; import appeng.services.compass.CompassReader; import appeng.services.compass.ICompassCallback; @@ -133,7 +133,7 @@ public final class CompassService { int cx = c.getPos().x; int cz = c.getPos().z; - Block skyStoneBlock = AEApi.instance().definitions().blocks().skyStoneBlock().block(); + Block skyStoneBlock = Api.instance().definitions().blocks().skyStoneBlock().block(); BlockPos.Mutable pos = new BlockPos.Mutable(); for (int i = 0; i < CHUNK_SIZE; i++) { pos.setX(i); diff --git a/src/main/java/appeng/spatial/CachedPlane.java b/src/main/java/appeng/spatial/CachedPlane.java index 74c9a3e2f..9169f94b1 100644 --- a/src/main/java/appeng/spatial/CachedPlane.java +++ b/src/main/java/appeng/spatial/CachedPlane.java @@ -60,7 +60,7 @@ public class CachedPlane { private final List tiles = new ArrayList<>(); private final List> ticks = new ArrayList<>(); private final World world; - private final IMovableRegistry reg = AEApi.instance().registries().movable(); + private final IMovableRegistry reg = Api.instance().registries().movable(); private final List updates = new ArrayList<>(); private int verticalBits; private final BlockState matrixBlockState; @@ -68,7 +68,7 @@ public class CachedPlane { public CachedPlane(final World w, final int minX, final int minY, final int minZ, final int maxX, final int maxY, final int maxZ) { - Block matrixFrameBlock = AEApi.instance().definitions().blocks().matrixFrame().maybeBlock().orElse(null); + Block matrixFrameBlock = Api.instance().definitions().blocks().matrixFrame().maybeBlock().orElse(null); if (matrixFrameBlock != null) { this.matrixBlockState = matrixFrameBlock.getDefaultState(); } else { @@ -111,7 +111,7 @@ public class CachedPlane { } } - final IMovableRegistry mr = AEApi.instance().registries().movable(); + final IMovableRegistry mr = Api.instance().registries().movable(); for (int cx = 0; cx < this.cx_size; cx++) { for (int cz = 0; cz < this.cz_size; cz++) { @@ -180,12 +180,12 @@ public class CachedPlane { } private IMovableHandler getHandler(final BlockEntity te) { - final IMovableRegistry mr = AEApi.instance().registries().movable(); + final IMovableRegistry mr = Api.instance().registries().movable(); return mr.getHandler(te); } void swap(final CachedPlane dst) { - final IMovableRegistry mr = AEApi.instance().registries().movable(); + final IMovableRegistry mr = Api.instance().registries().movable(); if (dst.x_size == this.x_size && dst.y_size == this.y_size && dst.z_size == this.z_size) { AELog.info("Block Copy Scale: " + this.x_size + ", " + this.y_size + ", " + this.z_size); diff --git a/src/main/java/appeng/spatial/StorageChunkGenerator.java b/src/main/java/appeng/spatial/StorageChunkGenerator.java index f5912a816..a98f91527 100644 --- a/src/main/java/appeng/spatial/StorageChunkGenerator.java +++ b/src/main/java/appeng/spatial/StorageChunkGenerator.java @@ -54,7 +54,7 @@ public class StorageChunkGenerator extends ChunkGenerator { private StorageChunkGenerator() { super(createBiomeProvider(), createSettings()); - this.defaultBlockState = AEApi.instance().definitions().blocks().matrixFrame().block().getDefaultState(); + this.defaultBlockState = Api.instance().definitions().blocks().matrixFrame().block().getDefaultState(); // Vertical sample is mostly used for Feature generation, for those purposes we're all filled with matrix blocks BlockState[] columnSample = new BlockState[256]; @@ -74,7 +74,7 @@ public class StorageChunkGenerator extends ChunkGenerator { private static StructuresConfig createSettings() { return new StructuresConfig(Optional.empty(), Collections.emptyMap()); } - + @Override public void buildSurface(ChunkRegion region, Chunk chunk) { this.fillChunk(chunk); diff --git a/src/main/java/appeng/spatial/StorageHelper.java b/src/main/java/appeng/spatial/StorageHelper.java index 860903919..846cb27fb 100644 --- a/src/main/java/appeng/spatial/StorageHelper.java +++ b/src/main/java/appeng/spatial/StorageHelper.java @@ -38,6 +38,9 @@ import net.minecraft.world.dimension.DimensionType; import java.util.ArrayList; import java.util.List; +import appeng.api.util.WorldCoord; +import appeng.core.Api; +import appeng.core.AppEng; public class StorageHelper { @@ -143,7 +146,7 @@ public class StorageHelper { public void swapRegions(final ServerWorld srcWorld, final int srcX, final int srcY, final int srcZ, final ServerWorld dstWorld, final int dstX, final int dstY, final int dstZ, final int scaleX, final int scaleY, final int scaleZ) { - AEApi.instance().definitions().blocks().matrixFrame().maybeBlock() + Api.instance().definitions().blocks().matrixFrame().maybeBlock() .ifPresent(matrixFrameBlock -> this.transverseEdges(dstX - 1, dstY - 1, dstZ - 1, dstX + scaleX + 1, dstY + scaleY + 1, dstZ + scaleZ + 1, new WrapInMatrixFrame(matrixFrameBlock.getDefaultState(), dstWorld))); diff --git a/src/main/java/appeng/tile/crafting/CraftingBlockEntity.java b/src/main/java/appeng/tile/crafting/CraftingBlockEntity.java index 6762dd2d9..dda4e412b 100644 --- a/src/main/java/appeng/tile/crafting/CraftingBlockEntity.java +++ b/src/main/java/appeng/tile/crafting/CraftingBlockEntity.java @@ -34,7 +34,6 @@ import net.minecraft.util.math.Direction; import net.minecraft.util.math.BlockPos; import net.minecraft.world.BlockView; -import appeng.api.AEApi; import appeng.api.config.Actionable; import appeng.api.implementations.IPowerChannelState; import appeng.api.networking.GridFlags; @@ -49,6 +48,7 @@ import appeng.api.util.AEPartLocation; import appeng.api.util.WorldCoord; import appeng.block.crafting.AbstractCraftingUnitBlock; import appeng.block.crafting.AbstractCraftingUnitBlock.CraftingUnitType; +import appeng.core.Api; import appeng.me.cluster.IAECluster; import appeng.me.cluster.IAEMultiBlock; import appeng.me.cluster.implementations.CraftingCPUCalculator; @@ -81,9 +81,9 @@ public class CraftingBlockEntity extends AENetworkBlockEntity implements IAEMult Optional is; if (((CraftingBlockEntity) obj).isAccelerator()) { - is = AEApi.instance().definitions().blocks().craftingAccelerator().maybeStack(1); + is = Api.instance().definitions().blocks().craftingAccelerator().maybeStack(1); } else { - is = AEApi.instance().definitions().blocks().craftingUnit().maybeStack(1); + is = Api.instance().definitions().blocks().craftingUnit().maybeStack(1); } return is.orElseGet(() -> super.getItemFromTile(obj)); @@ -243,6 +243,11 @@ public class CraftingBlockEntity extends AENetworkBlockEntity implements IAEMult } public void breakCluster() { + // Since breaking the cluster will most likely also update the TE's state, + // it's essential that we're not working with outdated block-state information, + // since this particular TE's block might already have been removed (state=air) + updateContainingBlockInfo(); + if (this.cluster != null) { this.cluster.cancel(); final IMEInventory inv = this.cluster.getInventory(); @@ -275,7 +280,7 @@ public class CraftingBlockEntity extends AENetworkBlockEntity implements IAEMult } for (IAEItemStack ais : inv.getAvailableItems( - AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList())) { + Api.instance().storage().getStorageChannel(IItemStorageChannel.class).createList())) { ais = ais.copy(); ais.setStackSize(ais.getDefinition().getMaxCount()); while (true) { diff --git a/src/main/java/appeng/tile/crafting/CraftingMonitorBlockEntity.java b/src/main/java/appeng/tile/crafting/CraftingMonitorBlockEntity.java index 24d16e5c2..7c64fcd23 100644 --- a/src/main/java/appeng/tile/crafting/CraftingMonitorBlockEntity.java +++ b/src/main/java/appeng/tile/crafting/CraftingMonitorBlockEntity.java @@ -34,10 +34,10 @@ import net.minecraft.util.math.Direction; import net.fabricmc.api.EnvType; -import appeng.api.AEApi; import appeng.api.implementations.tiles.IColorableTile; import appeng.api.storage.data.IAEItemStack; import appeng.api.util.AEColor; +import appeng.core.Api; import appeng.util.item.AEItemStack; public class CraftingMonitorBlockEntity extends CraftingBlockEntity implements IColorableTile { @@ -162,7 +162,7 @@ public class CraftingMonitorBlockEntity extends CraftingBlockEntity implements I @Override protected ItemStack getItemFromTile(final Object obj) { - final Optional is = AEApi.instance().definitions().blocks().craftingMonitor().maybeStack(1); + final Optional is = Api.instance().definitions().blocks().craftingMonitor().maybeStack(1); return is.orElseGet(() -> super.getItemFromTile(obj)); } diff --git a/src/main/java/appeng/tile/crafting/CraftingStorageBlockEntity.java b/src/main/java/appeng/tile/crafting/CraftingStorageBlockEntity.java index 3b88ce3dc..c12fac140 100644 --- a/src/main/java/appeng/tile/crafting/CraftingStorageBlockEntity.java +++ b/src/main/java/appeng/tile/crafting/CraftingStorageBlockEntity.java @@ -23,9 +23,9 @@ import java.util.Optional; import net.minecraft.block.entity.BlockEntityType; import net.minecraft.item.ItemStack; -import appeng.api.AEApi; import appeng.api.definitions.IBlocks; import appeng.block.crafting.AbstractCraftingUnitBlock; +import appeng.core.Api; public class CraftingStorageBlockEntity extends CraftingBlockEntity { private static final int KILO_SCALAR = 1024; @@ -36,7 +36,7 @@ public class CraftingStorageBlockEntity extends CraftingBlockEntity { @Override protected ItemStack getItemFromTile(final Object obj) { - final IBlocks blocks = AEApi.instance().definitions().blocks(); + final IBlocks blocks = Api.instance().definitions().blocks(); final int storage = ((CraftingBlockEntity) obj).getStorageBytes() / KILO_SCALAR; Optional is; diff --git a/src/main/java/appeng/tile/crafting/MolecularAssemblerBlockEntity.java b/src/main/java/appeng/tile/crafting/MolecularAssemblerBlockEntity.java index 4c42babe0..64c2badf5 100644 --- a/src/main/java/appeng/tile/crafting/MolecularAssemblerBlockEntity.java +++ b/src/main/java/appeng/tile/crafting/MolecularAssemblerBlockEntity.java @@ -20,7 +20,6 @@ package appeng.tile.crafting; import alexiil.mc.lib.attributes.Simulation; import alexiil.mc.lib.attributes.item.FixedItemInv; -import appeng.api.AEApi; import appeng.api.config.*; import appeng.api.definitions.ITileDefinition; import appeng.api.implementations.IPowerChannelState; @@ -39,6 +38,7 @@ import appeng.api.util.AEPartLocation; import appeng.api.util.DimensionalCoord; import appeng.api.util.IConfigManager; import appeng.container.ContainerNull; +import appeng.core.Api; import appeng.core.sync.network.NetworkHandler; import appeng.core.sync.network.TargetPoint; import appeng.core.sync.packets.AssemblerAnimationPacket; @@ -101,7 +101,7 @@ public class MolecularAssemblerBlockEntity extends AENetworkInvBlockEntity public MolecularAssemblerBlockEntity(BlockEntityType tileEntityTypeIn) { super(tileEntityTypeIn); - final ITileDefinition assembler = AEApi.instance().definitions().blocks().molecularAssembler(); + final ITileDefinition assembler = Api.instance().definitions().blocks().molecularAssembler(); this.settings = new ConfigManager(this); this.settings.registerSetting(Settings.REDSTONE_CONTROLLED, RedstoneMode.IGNORE); @@ -220,8 +220,7 @@ public class MolecularAssemblerBlockEntity extends AENetworkInvBlockEntity if (!myPat.isEmpty() && myPat.getItem() instanceof EncodedPatternItem) { final World w = this.getWorld(); - final EncodedPatternItem iep = (EncodedPatternItem) myPat.getItem(); - final ICraftingPatternDetails ph = iep.getPatternForItem(myPat, w); + final ICraftingPatternDetails ph = Api.instance().crafting().decodePattern(myPat, w); if (ph != null && ph.isCraftable()) { this.forcePlan = true; this.myPlan = ph; @@ -247,8 +246,7 @@ public class MolecularAssemblerBlockEntity extends AENetworkInvBlockEntity if (!is.isEmpty() && is.getItem() instanceof EncodedPatternItem) { if (!ItemStack.areItemsEqual(is, this.myPattern)) { final World w = this.getWorld(); - final EncodedPatternItem iep = (EncodedPatternItem) is.getItem(); - final ICraftingPatternDetails ph = iep.getPatternForItem(is, w); + final ICraftingPatternDetails ph = Api.instance().crafting().decodePattern(is, w); if (ph != null && ph.isCraftable()) { this.progress = 0; diff --git a/src/main/java/appeng/tile/inventory/AppEngInternalAEInventory.java b/src/main/java/appeng/tile/inventory/AppEngInternalAEInventory.java index 56798aa71..4c8cf9388 100644 --- a/src/main/java/appeng/tile/inventory/AppEngInternalAEInventory.java +++ b/src/main/java/appeng/tile/inventory/AppEngInternalAEInventory.java @@ -31,10 +31,10 @@ import alexiil.mc.lib.attributes.item.InvMarkDirtyListener; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundTag; -import appeng.api.AEApi; import appeng.api.storage.channels.IItemStorageChannel; import appeng.api.storage.data.IAEItemStack; import appeng.core.AELog; +import appeng.core.Api; import appeng.util.Platform; import appeng.util.inv.IAEAppEngInventory; import appeng.util.inv.InvOperation; @@ -134,7 +134,7 @@ public class AppEngInternalAEInventory implements FixedItemInv, Iterable POWER_THRESHOLD) { - final IMaterials materials = AEApi.instance().definitions().materials(); + final IMaterials materials = Api.instance().definitions().materials(); if (materials.certusQuartzCrystal().isSameAs(myItem)) { this.extractAEPower(this.getInternalMaxPower(), Actionable.MODULATE, PowerMultiplier.CONFIG); @@ -158,7 +158,7 @@ public class ChargerBlockEntity extends AENetworkPowerBlockEntity implements ICr if (myItem.isEmpty()) { ItemStack held = player.inventory.getMainHandStack(); - if (AEApi.instance().definitions().materials().certusQuartzCrystal().isSameAs(held) + if (Api.instance().definitions().materials().certusQuartzCrystal().isSameAs(held) || Platform.isChargeable(held)) { held = player.inventory.removeStack(player.inventory.selectedSlot, 1); this.inv.setInvStack(0, held, Simulation.ACTION); @@ -186,13 +186,13 @@ public class ChargerBlockEntity extends AENetworkPowerBlockEntity implements ICr boolean changed = false; if (!myItem.isEmpty()) { - final IMaterials materials = AEApi.instance().definitions().materials(); + final IMaterials materials = Api.instance().definitions().materials(); if (Platform.isChargeable(myItem)) { final IAEItemPowerStorage ps = (IAEItemPowerStorage) myItem.getItem(); if (ps.getAEMaxPower(myItem) > ps.getAECurrentPower(myItem)) { - final double chargeRate = AEApi.instance().registries().charger().getChargeRate(myItem.getItem()); + final double chargeRate = Api.instance().registries().charger().getChargeRate(myItem.getItem()); double extractedAmount = this.extractAEPower(chargeRate, Actionable.MODULATE, PowerMultiplier.CONFIG); @@ -255,7 +255,7 @@ public class ChargerBlockEntity extends AENetworkPowerBlockEntity implements ICr private class ChargerInvFilter implements IAEItemFilter { @Override public boolean allowInsert(FixedItemInv inv, final int i, final ItemStack itemstack) { - final IItemDefinition cert = AEApi.instance().definitions().materials().certusQuartzCrystal(); + final IItemDefinition cert = Api.instance().definitions().materials().certusQuartzCrystal(); return Platform.isChargeable(itemstack) || cert.isSameAs(itemstack); } @@ -271,7 +271,7 @@ public class ChargerBlockEntity extends AENetworkPowerBlockEntity implements ICr } } - return AEApi.instance().definitions().materials().certusQuartzCrystalCharged().isSameAs(extractedItem); + return Api.instance().definitions().materials().certusQuartzCrystalCharged().isSameAs(extractedItem); } } } diff --git a/src/main/java/appeng/tile/misc/CondenserBlockEntity.java b/src/main/java/appeng/tile/misc/CondenserBlockEntity.java index 252f371df..723d22ca0 100644 --- a/src/main/java/appeng/tile/misc/CondenserBlockEntity.java +++ b/src/main/java/appeng/tile/misc/CondenserBlockEntity.java @@ -35,7 +35,6 @@ import net.minecraft.block.entity.BlockEntityType; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; -import appeng.api.AEApi; import appeng.api.config.CondenserOutput; import appeng.api.config.Settings; import appeng.api.definitions.IMaterials; @@ -51,6 +50,7 @@ import appeng.api.storage.data.IAEFluidStack; import appeng.api.storage.data.IAEStack; import appeng.api.util.IConfigManager; import appeng.api.util.IConfigurableObject; +import appeng.core.Api; import appeng.tile.AEBaseInvBlockEntity; import appeng.tile.inventory.AppEngInternalInventory; import appeng.util.ConfigManager; @@ -142,7 +142,7 @@ public class CondenserBlockEntity extends AEBaseInvBlockEntity implements IConfi } private ItemStack getOutput() { - final IMaterials materials = AEApi.instance().definitions().materials(); + final IMaterials materials = Api.instance().definitions().materials(); switch ((CondenserOutput) this.cm.getSetting(Settings.CONDENSER_OUTPUT)) { case MATTER_BALLS: @@ -223,7 +223,7 @@ public class CondenserBlockEntity extends AEBaseInvBlockEntity implements IConfi @Override public FluidVolume attemptInsertion(FluidVolume fluid, Simulation simulation) { if (simulation == Simulation.ACTION) { - final IStorageChannel chan = AEApi.instance().storage() + final IStorageChannel chan = Api.instance().storage() .getStorageChannel(IFluidStorageChannel.class); CondenserBlockEntity.this .addPower((fluid.isEmpty() ? 0.0 : fluid.getAmount_F().asInexactDouble() * 1000.0) / chan.transferFactor()); @@ -260,7 +260,7 @@ public class CondenserBlockEntity extends AEBaseInvBlockEntity implements IConfi @Override public > IMEMonitor getInventory(IStorageChannel channel) { - if (channel == AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)) { + if (channel == Api.instance().storage().getStorageChannel(IItemStorageChannel.class)) { return (IMEMonitor) this.itemInventory; } else { return new CondenserVoidInventory<>(CondenserBlockEntity.this, channel); diff --git a/src/main/java/appeng/tile/misc/CondenserItemInventory.java b/src/main/java/appeng/tile/misc/CondenserItemInventory.java index 7663ad7df..1953b9b86 100644 --- a/src/main/java/appeng/tile/misc/CondenserItemInventory.java +++ b/src/main/java/appeng/tile/misc/CondenserItemInventory.java @@ -26,7 +26,6 @@ import alexiil.mc.lib.attributes.Simulation; import alexiil.mc.lib.attributes.item.filter.ConstantItemFilter; import net.minecraft.item.ItemStack; -import appeng.api.AEApi; import appeng.api.config.AccessRestriction; import appeng.api.config.Actionable; import appeng.api.networking.security.IActionSource; @@ -37,6 +36,7 @@ import appeng.api.storage.IStorageChannel; import appeng.api.storage.channels.IItemStorageChannel; import appeng.api.storage.data.IAEItemStack; import appeng.api.storage.data.IItemList; +import appeng.core.Api; import appeng.me.helpers.BaseActionSource; import appeng.me.storage.ITickingMonitor; import appeng.util.item.AEItemStack; @@ -94,7 +94,7 @@ class CondenserItemInventory implements IMEMonitor, ITickingMonito @Override public IStorageChannel getChannel() { - return AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class); + return Api.instance().storage().getStorageChannel(IItemStorageChannel.class); } @Override diff --git a/src/main/java/appeng/tile/misc/InscriberBlockEntity.java b/src/main/java/appeng/tile/misc/InscriberBlockEntity.java index be2e9ca4a..131f1faf4 100644 --- a/src/main/java/appeng/tile/misc/InscriberBlockEntity.java +++ b/src/main/java/appeng/tile/misc/InscriberBlockEntity.java @@ -36,7 +36,6 @@ import net.minecraft.util.math.Direction; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; -import appeng.api.AEApi; import appeng.api.config.Actionable; import appeng.api.config.PowerMultiplier; import appeng.api.config.Settings; @@ -53,6 +52,7 @@ import appeng.api.networking.ticking.TickingRequest; import appeng.api.util.AECableType; import appeng.api.util.AEPartLocation; import appeng.api.util.IConfigManager; +import appeng.core.Api; import appeng.core.settings.TickRates; import appeng.me.GridAccessException; import appeng.parts.automation.DefinitionUpgradeInventory; @@ -107,7 +107,7 @@ public class InscriberBlockEntity extends AENetworkPowerBlockEntity this.getProxy().setIdlePowerUsage(0); this.settings = new ConfigManager(this); - final ITileDefinition inscriberDefinition = AEApi.instance().definitions().blocks().inscriber(); + final ITileDefinition inscriberDefinition = Api.instance().definitions().blocks().inscriber(); this.upgrades = new DefinitionUpgradeInventory(inscriberDefinition, this, this.getUpgradeSlots()); this.sideItemHandler.setMaxStackSize(1, 64); @@ -432,7 +432,7 @@ public class InscriberBlockEntity extends AENetworkPowerBlockEntity } if (inv == InscriberBlockEntity.this.topItemHandler || inv == InscriberBlockEntity.this.bottomItemHandler) { - if (AEApi.instance().definitions().materials().namePress().isSameAs(stack)) { + if (Api.instance().definitions().materials().namePress().isSameAs(stack)) { return true; } return InscriberRecipes.isValidOptionalIngredient(getWorld(), stack); diff --git a/src/main/java/appeng/tile/misc/InscriberRecipes.java b/src/main/java/appeng/tile/misc/InscriberRecipes.java index 02d5e1f6e..67f9a0f80 100644 --- a/src/main/java/appeng/tile/misc/InscriberRecipes.java +++ b/src/main/java/appeng/tile/misc/InscriberRecipes.java @@ -3,6 +3,7 @@ package appeng.tile.misc; import appeng.api.AEApi; import appeng.api.definitions.IComparableDefinition; import appeng.api.features.InscriberProcessType; +import appeng.core.Api; import appeng.core.AppEng; import appeng.items.materials.MaterialItem; import appeng.recipes.handlers.InscriberRecipe; @@ -38,7 +39,7 @@ public final class InscriberRecipes { public static InscriberRecipe findRecipe(World world, ItemStack input, ItemStack plateA, ItemStack plateB, boolean supportNamePress) { if (supportNamePress) { - IComparableDefinition namePress = AEApi.instance().definitions().materials().namePress(); + IComparableDefinition namePress = Api.instance().definitions().materials().namePress(); boolean isNameA = namePress.isSameAs(plateA); boolean isNameB = namePress.isSameAs(plateB); diff --git a/src/main/java/appeng/tile/misc/InterfaceBlockEntity.java b/src/main/java/appeng/tile/misc/InterfaceBlockEntity.java index 910164142..87bd18031 100644 --- a/src/main/java/appeng/tile/misc/InterfaceBlockEntity.java +++ b/src/main/java/appeng/tile/misc/InterfaceBlockEntity.java @@ -38,7 +38,6 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import alexiil.mc.lib.attributes.item.FixedItemInv; -import appeng.api.AEApi; import appeng.api.config.Actionable; import appeng.api.config.Upgrades; import appeng.api.networking.IGridNode; @@ -57,6 +56,7 @@ import appeng.api.util.AEPartLocation; import appeng.api.util.DimensionalCoord; import appeng.api.util.IConfigManager; import appeng.container.implementations.InterfaceContainer; +import appeng.core.Api; import appeng.helpers.DualityInterface; import appeng.helpers.IInterfaceHost; import appeng.helpers.IPriorityHost; @@ -302,7 +302,7 @@ public class InterfaceBlockEntity extends AENetworkInvBlockEntity @Override public ItemStack getItemStackRepresentation() { - return AEApi.instance().definitions().blocks().iface().maybeStack(1).orElse(ItemStack.EMPTY); + return Api.instance().definitions().blocks().iface().maybeStack(1).orElse(ItemStack.EMPTY); } @Override diff --git a/src/main/java/appeng/tile/misc/SecurityStationBlockEntity.java b/src/main/java/appeng/tile/misc/SecurityStationBlockEntity.java index 4faadfb60..509013849 100644 --- a/src/main/java/appeng/tile/misc/SecurityStationBlockEntity.java +++ b/src/main/java/appeng/tile/misc/SecurityStationBlockEntity.java @@ -36,7 +36,6 @@ import net.minecraft.util.math.Direction; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; -import appeng.api.AEApi; import appeng.api.config.SecurityPermissions; import appeng.api.config.Settings; import appeng.api.config.SortDir; @@ -66,6 +65,7 @@ import appeng.api.util.AEColor; import appeng.api.util.AEPartLocation; import appeng.api.util.DimensionalCoord; import appeng.api.util.IConfigManager; +import appeng.core.Api; import appeng.helpers.PlayerSecurityWrapper; import appeng.me.GridAccessException; import appeng.me.helpers.MEMonitorHandler; @@ -253,7 +253,7 @@ public class SecurityStationBlockEntity extends AENetworkBlockEntity implements @Override public > IMEMonitor getInventory(IStorageChannel channel) { - if (channel == AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)) { + if (channel == Api.instance().storage().getStorageChannel(IItemStorageChannel.class)) { return (IMEMonitor) this.securityMonitor; } return null; @@ -286,7 +286,7 @@ public class SecurityStationBlockEntity extends AENetworkBlockEntity implements @Override public void readPermissions(final Map> playerPerms) { - final IPlayerRegistry pr = AEApi.instance().registries().players(); + final IPlayerRegistry pr = Api.instance().registries().players(); // read permissions for (final IAEItemStack ais : this.inventory.getStoredItems()) { diff --git a/src/main/java/appeng/tile/networking/WirelessBlockEntity.java b/src/main/java/appeng/tile/networking/WirelessBlockEntity.java index afda632c2..92f143590 100644 --- a/src/main/java/appeng/tile/networking/WirelessBlockEntity.java +++ b/src/main/java/appeng/tile/networking/WirelessBlockEntity.java @@ -27,7 +27,6 @@ import net.minecraft.network.PacketByteBuf; import net.minecraft.block.entity.BlockEntityType; import net.minecraft.util.math.Direction; -import appeng.api.AEApi; import appeng.api.implementations.IPowerChannelState; import appeng.api.implementations.tiles.IWirelessAccessPoint; import appeng.api.networking.GridFlags; @@ -39,6 +38,7 @@ import appeng.api.util.AECableType; import appeng.api.util.AEPartLocation; import appeng.api.util.DimensionalCoord; import appeng.core.AEConfig; +import appeng.core.Api; import appeng.me.GridAccessException; import appeng.tile.grid.AENetworkInvBlockEntity; import appeng.tile.inventory.AppEngInternalInventory; @@ -56,7 +56,7 @@ public class WirelessBlockEntity extends AENetworkInvBlockEntity implements IWir public WirelessBlockEntity(BlockEntityType tileEntityTypeIn) { super(tileEntityTypeIn); - this.inv.setFilter(new AEItemDefinitionFilter(AEApi.instance().definitions().materials().wirelessBooster())); + this.inv.setFilter(new AEItemDefinitionFilter(Api.instance().definitions().materials().wirelessBooster())); this.getProxy().setFlags(GridFlags.REQUIRE_CHANNEL); this.getProxy().setValidSides(EnumSet.noneOf(Direction.class)); } diff --git a/src/main/java/appeng/tile/qnb/QuantumBridgeBlockEntity.java b/src/main/java/appeng/tile/qnb/QuantumBridgeBlockEntity.java index 7808f0305..27ef2ed87 100644 --- a/src/main/java/appeng/tile/qnb/QuantumBridgeBlockEntity.java +++ b/src/main/java/appeng/tile/qnb/QuantumBridgeBlockEntity.java @@ -34,7 +34,6 @@ import net.minecraft.util.math.Direction; import alexiil.mc.lib.attributes.item.impl.EmptyFixedItemInv; -import appeng.api.AEApi; import appeng.api.definitions.IBlockDefinition; import appeng.api.networking.GridFlags; import appeng.api.networking.events.MENetworkEventSubscribe; @@ -43,6 +42,7 @@ import appeng.api.util.AECableType; import appeng.api.util.AEPartLocation; import appeng.api.util.DimensionalCoord; import appeng.block.qnb.QnbFormedState; +import appeng.core.Api; import appeng.me.GridAccessException; import appeng.me.cluster.IAECluster; import appeng.me.cluster.IAEMultiBlock; @@ -128,7 +128,7 @@ public class QuantumBridgeBlockEntity extends AENetworkInvBlockEntity implements } private boolean isCenter() { - return AEApi.instance().definitions().blocks().quantumLink().maybeBlock() + return Api.instance().definitions().blocks().quantumLink().maybeBlock() .map(link -> getCachedState().getBlock() == link).orElse(false); } @@ -147,7 +147,7 @@ public class QuantumBridgeBlockEntity extends AENetworkInvBlockEntity implements public void onReady() { super.onReady(); - final IBlockDefinition quantumRing = AEApi.instance().definitions().blocks().quantumRing(); + final IBlockDefinition quantumRing = Api.instance().definitions().blocks().quantumRing(); final Optional maybeLinkBlock = quantumRing.maybeBlock(); final Optional maybeLinkStack = quantumRing.maybeStack(1); @@ -283,6 +283,11 @@ public class QuantumBridgeBlockEntity extends AENetworkInvBlockEntity implements } public void breakCluster() { + // Since breaking the cluster will most likely also update the TE's state, + // it's essential that we're not working with outdated block-state information, + // since this particular TE's block might already have been removed (state=air) + updateContainingBlockInfo(); + if (this.cluster != null) { this.cluster.destroy(); } diff --git a/src/main/java/appeng/tile/storage/ChestBlockEntity.java b/src/main/java/appeng/tile/storage/ChestBlockEntity.java index 283fc7dc1..d635ae2d9 100644 --- a/src/main/java/appeng/tile/storage/ChestBlockEntity.java +++ b/src/main/java/appeng/tile/storage/ChestBlockEntity.java @@ -52,6 +52,7 @@ import appeng.api.storage.data.IAEStack; import appeng.api.util.AEColor; import appeng.api.util.IConfigManager; import appeng.container.implementations.MEMonitorableContainer; +import appeng.core.Api; import appeng.fluids.util.AEFluidStack; import appeng.helpers.IPriorityHost; import appeng.me.GridAccessException; @@ -112,6 +113,10 @@ public class ChestBlockEntity extends AENetworkPowerBlockEntity private ChestMonitorHandler cellHandler; private Accessor accessor; private FluidInsertable fluidInsertable; + // This is only used on the client to display the right cell model without + // synchronizing the entire + // cell's inventory when a chest comes into view. + private Item cellItem = Items.AIR; public ChestBlockEntity(BlockEntityType tileEntityTypeIn) { super(tileEntityTypeIn); @@ -188,11 +193,11 @@ public class ChestBlockEntity extends AENetworkPowerBlockEntity final ItemStack is = this.getCell(); if (!is.isEmpty()) { this.isCached = true; - ICellHandler cellHandler = AEApi.instance().registries().cell().getHandler(is); + ICellHandler cellHandler = Api.instance().registries().cell().getHandler(is); if (cellHandler != null) { double power = 1.0; - for (IStorageChannel channel : AEApi.instance().storage().storageChannels()) { + for (IStorageChannel channel : Api.instance().storage().storageChannels()) { final ICellInventoryHandler newCell = cellHandler.getCellInventory(is, this, channel); if (newCell != null) { @@ -205,7 +210,7 @@ public class ChestBlockEntity extends AENetworkPowerBlockEntity this.getProxy().setIdlePowerUsage(power); this.accessor = new Accessor(); - if (this.cellHandler != null && this.cellHandler.getChannel() == AEApi.instance().storage() + if (this.cellHandler != null && this.cellHandler.getChannel() == Api.instance().storage() .getStorageChannel(IFluidStorageChannel.class)) { this.fluidInsertable = new FluidHandler(); } @@ -237,7 +242,7 @@ public class ChestBlockEntity extends AENetworkPowerBlockEntity this.updateHandler(); final ItemStack cell = this.getCell(); - final ICellHandler ch = AEApi.instance().registries().cell().getHandler(cell); + final ICellHandler ch = Api.instance().registries().cell().getHandler(cell); if (this.cellHandler != null && ch != null) { return ch.getStatusForCell(cell, this.cellHandler.getInternalHandler()); @@ -252,6 +257,10 @@ public class ChestBlockEntity extends AENetworkPowerBlockEntity if (slot != 0) { return null; } + // Client-side we'll need to actually use the synced state + if (world == null || world.isRemote) { + return cellItem; + } ItemStack cell = getCell(); return cell.isEmpty() ? null : cell.getItem(); } @@ -343,6 +352,12 @@ public class ChestBlockEntity extends AENetworkPowerBlockEntity data.writeByte(this.state); data.writeByte(this.paintedColor.ordinal()); + + // Note that we trust that the change detection in recalculateDisplay will trip + // when it changes from + // empty->non-empty, so when the cell is changed, it should re-send the state + // because of that + data.writeRegistryIdUnsafe(ForgeRegistries.ITEMS, getCell().getItem().getRegistryName()); } @Override @@ -354,6 +369,7 @@ public class ChestBlockEntity extends AENetworkPowerBlockEntity this.state = data.readByte(); final AEColor oldPaintedColor = this.paintedColor; this.paintedColor = AEColor.values()[data.readByte()]; + this.cellItem = data.readRegistryIdUnsafe(ForgeRegistries.ITEMS); this.lastStateChange = this.world.getTime(); @@ -444,7 +460,7 @@ public class ChestBlockEntity extends AENetworkPowerBlockEntity if (!ItemHandlerUtil.isEmpty(this.inputInventory)) { this.updateHandler(); - if (this.cellHandler != null && this.cellHandler.getChannel() == AEApi.instance().storage() + if (this.cellHandler != null && this.cellHandler.getChannel() == Api.instance().storage() .getStorageChannel(IItemStorageChannel.class)) { final IAEItemStack returns = Platform.poweredInsert(this, this.cellHandler, AEItemStack.fromItemStack(this.inputInventory.getInvStack(0)), this.mySrc); @@ -514,10 +530,10 @@ public class ChestBlockEntity extends AENetworkPowerBlockEntity public boolean openGui(final PlayerEntity p) { this.updateHandler(); if (this.cellHandler != null) { - final ICellHandler ch = AEApi.instance().registries().cell().getHandler(this.getCell()); + final ICellHandler ch = Api.instance().registries().cell().getHandler(this.getCell()); if (ch != null) { - final ICellGuiHandler chg = AEApi.instance().registries().cell() + final ICellGuiHandler chg = Api.instance().registries().cell() .getGuiHandler(this.cellHandler.getChannel(), this.getCell()); if (chg != null) { chg.openChestGui(p, this, ch, this.cellHandler, this.getCell(), this.cellHandler.getChannel()); @@ -679,7 +695,7 @@ public class ChestBlockEntity extends AENetworkPowerBlockEntity private class FluidHandler implements FluidInsertable { private boolean canAcceptLiquids() { - return ChestBlockEntity.this.cellHandler != null && ChestBlockEntity.this.cellHandler.getChannel() == AEApi + return ChestBlockEntity.this.cellHandler != null && ChestBlockEntity.this.cellHandler.getChannel() == Api .instance().storage().getStorageChannel(IFluidStorageChannel.class); } @@ -729,8 +745,8 @@ public class ChestBlockEntity extends AENetworkPowerBlockEntity public boolean allowInsert(FixedItemInv inv, int slot, ItemStack stack) { if (ChestBlockEntity.this.isPowered()) { ChestBlockEntity.this.updateHandler(); - return ChestBlockEntity.this.cellHandler != null && ChestBlockEntity.this.cellHandler - .getChannel() == AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class); + return ChestBlockEntity.this.cellHandler != null && ChestBlockEntity.this.cellHandler.getChannel() == Api + .instance().storage().getStorageChannel(IItemStorageChannel.class); } return false; } @@ -745,25 +761,25 @@ public class ChestBlockEntity extends AENetworkPowerBlockEntity @Override public boolean allowInsert(FixedItemInv inv, int slot, ItemStack stack) { - return AEApi.instance().registries().cell().getHandler(stack) != null; + return Api.instance().registries().cell().getHandler(stack) != null; } } @Override public ItemStack getItemStackRepresentation() { - return AEApi.instance().definitions().blocks().chest().maybeStack(1).orElse(ItemStack.EMPTY); + return Api.instance().definitions().blocks().chest().maybeStack(1).orElse(ItemStack.EMPTY); } @Override public ScreenHandlerType getContainerType() { this.updateHandler(); if (this.cellHandler != null) { - if (this.cellHandler.getChannel() == AEApi.instance().storage() + if (this.cellHandler.getChannel() == Api.instance().storage() .getStorageChannel(IItemStorageChannel.class)) { return MEMonitorableContainer.TYPE; } - if (this.cellHandler.getChannel() == AEApi.instance().storage() + if (this.cellHandler.getChannel() == Api.instance().storage() .getStorageChannel(IFluidStorageChannel.class)) { throw new IllegalStateException(); // FIXME FABRIC return FluidTerminalContainer.TYPE; diff --git a/src/main/java/appeng/tile/storage/DriveBlockEntity.java b/src/main/java/appeng/tile/storage/DriveBlockEntity.java index ca27ecea6..7e0cf71c7 100644 --- a/src/main/java/appeng/tile/storage/DriveBlockEntity.java +++ b/src/main/java/appeng/tile/storage/DriveBlockEntity.java @@ -39,7 +39,6 @@ import net.minecraft.nbt.CompoundTag; import net.minecraft.network.PacketByteBuf; import net.minecraft.util.Identifier; -import appeng.api.AEApi; import appeng.api.implementations.tiles.IChestOrDrive; import appeng.api.networking.GridFlags; import appeng.api.networking.events.MENetworkCellArrayUpdate; @@ -62,6 +61,7 @@ import appeng.api.util.DimensionalCoord; import appeng.block.storage.DriveSlotsState; import appeng.client.render.model.DriveModelData; import appeng.container.implementations.DriveContainer; +import appeng.core.Api; import appeng.helpers.IPriorityHost; import appeng.me.GridAccessException; import appeng.me.helpers.MachineSource; @@ -345,7 +345,7 @@ public class DriveBlockEntity extends AENetworkInvBlockEntity implements IChestO private void updateState() { if (!this.isCached) { - final Collection>> storageChannels = AEApi.instance().storage() + final Collection>> storageChannels = Api.instance().storage() .storageChannels(); storageChannels.forEach(channel -> this.inventoryHandlers.put(channel, new ArrayList<>(10))); @@ -357,7 +357,7 @@ public class DriveBlockEntity extends AENetworkInvBlockEntity implements IChestO this.handlersBySlot[x] = null; if (!is.isEmpty()) { - this.handlersBySlot[x] = AEApi.instance().registries().cell().getHandler(is); + this.handlersBySlot[x] = Api.instance().registries().cell().getHandler(is); if (this.handlersBySlot[x] != null) { for (IStorageChannel> channel : storageChannels) { @@ -435,7 +435,7 @@ public class DriveBlockEntity extends AENetworkInvBlockEntity implements IChestO @Override public ItemStack getItemStackRepresentation() { - return AEApi.instance().definitions().blocks().drive().maybeStack(1).orElse(ItemStack.EMPTY); + return Api.instance().definitions().blocks().drive().maybeStack(1).orElse(ItemStack.EMPTY); } @Override diff --git a/src/main/java/appeng/tile/storage/IOPortBlockEntity.java b/src/main/java/appeng/tile/storage/IOPortBlockEntity.java index b42992903..920fe4d41 100644 --- a/src/main/java/appeng/tile/storage/IOPortBlockEntity.java +++ b/src/main/java/appeng/tile/storage/IOPortBlockEntity.java @@ -33,7 +33,6 @@ import net.minecraft.util.math.Direction; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; -import appeng.api.AEApi; import appeng.api.config.Actionable; import appeng.api.config.FullnessMode; import appeng.api.config.OperationMode; @@ -58,6 +57,7 @@ import appeng.api.util.AECableType; import appeng.api.util.AEPartLocation; import appeng.api.util.DimensionalCoord; import appeng.api.util.IConfigManager; +import appeng.core.Api; import appeng.core.settings.TickRates; import appeng.me.GridAccessException; import appeng.me.helpers.MachineSource; @@ -108,7 +108,7 @@ public class IOPortBlockEntity extends AENetworkInvBlockEntity this.mySrc = new MachineSource(this); this.lastRedstoneState = YesNo.UNDECIDED; - final Block ioPortBlock = AEApi.instance().definitions().blocks().iOPort().maybeBlock().get(); + final Block ioPortBlock = Api.instance().definitions().blocks().iOPort().maybeBlock().get(); this.upgrades = new BlockUpgradeInventory(ioPortBlock, this, NUMBER_OF_UPGRADE_SLOTS); } @@ -267,7 +267,7 @@ public class IOPortBlockEntity extends AENetworkInvBlockEntity if (!is.isEmpty()) { boolean shouldMove = true; - for (IStorageChannel> c : AEApi.instance().storage().storageChannels()) { + for (IStorageChannel> c : Api.instance().storage().storageChannels()) { if (itemsToMove > 0) { final IMEMonitor> network = this.getProxy().getStorage() .getInventory(c); @@ -318,8 +318,8 @@ public class IOPortBlockEntity extends AENetworkInvBlockEntity this.currentCell = is; this.cachedInventories = new IdentityHashMap<>(); - for (IStorageChannel> c : AEApi.instance().storage().storageChannels()) { - this.cachedInventories.put(c, AEApi.instance().registries().cell().getCellInventory(is, null, c)); + for (IStorageChannel> c : Api.instance().storage().storageChannels()) { + this.cachedInventories.put(c, Api.instance().registries().cell().getCellInventory(is, null, c)); } } diff --git a/src/main/java/appeng/util/Platform.java b/src/main/java/appeng/util/Platform.java index beb9ed78c..594a1277c 100644 --- a/src/main/java/appeng/util/Platform.java +++ b/src/main/java/appeng/util/Platform.java @@ -46,6 +46,7 @@ import appeng.api.util.AEPartLocation; import appeng.api.util.DimensionalCoord; import appeng.core.AEConfig; import appeng.core.AELog; +import appeng.core.Api; import appeng.core.stats.AeStats; import appeng.fluids.util.AEFluidStack; import appeng.hooks.TickHandler; @@ -843,11 +844,11 @@ public class Platform { @SuppressWarnings({ "rawtypes", "unchecked" }) public static void postChanges(final IStorageGrid gs, final ItemStack removed, final ItemStack added, final IActionSource src) { - for (final IStorageChannel chan : AEApi.instance().storage().storageChannels()) { + for (final IStorageChannel chan : Api.instance().storage().storageChannels()) { final IItemList myChanges = chan.createList(); if (!removed.isEmpty()) { - final IMEInventory myInv = AEApi.instance().registries().cell().getCellInventory(removed, null, chan); + final IMEInventory myInv = Api.instance().registries().cell().getCellInventory(removed, null, chan); if (myInv != null) { myInv.getAvailableItems(myChanges); for (final IAEStack is : myChanges) { @@ -856,7 +857,7 @@ public class Platform { } } if (!added.isEmpty()) { - final IMEInventory myInv = AEApi.instance().registries().cell().getCellInventory(added, null, chan); + final IMEInventory myInv = Api.instance().registries().cell().getCellInventory(added, null, chan); if (myInv != null) { myInv.getAvailableItems(myChanges); } @@ -1106,8 +1107,7 @@ public class Platform { } if (type == AEFeature.CERTUS_QUARTZ_TOOLS) { - final IItemDefinition certusQuartzCrystal = AEApi.instance().definitions().materials() - .certusQuartzCrystal(); + final IItemDefinition certusQuartzCrystal = Api.instance().definitions().materials().certusQuartzCrystal(); return certusQuartzCrystal.isSameAs(b); } @@ -1126,7 +1126,7 @@ public class Platform { } public static boolean isRecipePrioritized(final ItemStack what) { - final IMaterials materials = AEApi.instance().definitions().materials(); + final IMaterials materials = Api.instance().definitions().materials(); boolean isPurified = materials.purifiedCertusQuartzCrystal().isSameAs(what); isPurified |= materials.purifiedFluixCrystal().isSameAs(what); diff --git a/src/main/java/appeng/util/inv/IMEAdaptor.java b/src/main/java/appeng/util/inv/IMEAdaptor.java index e6e4163a2..806b967a0 100644 --- a/src/main/java/appeng/util/inv/IMEAdaptor.java +++ b/src/main/java/appeng/util/inv/IMEAdaptor.java @@ -24,7 +24,6 @@ import com.google.common.collect.ImmutableList; import net.minecraft.item.ItemStack; -import appeng.api.AEApi; import appeng.api.config.Actionable; import appeng.api.config.FuzzyMode; import appeng.api.networking.security.IActionSource; @@ -32,6 +31,7 @@ import appeng.api.storage.IMEInventory; import appeng.api.storage.channels.IItemStorageChannel; import appeng.api.storage.data.IAEItemStack; import appeng.api.storage.data.IItemList; +import appeng.core.Api; import appeng.util.InventoryAdaptor; import appeng.util.item.AEItemStack; @@ -57,8 +57,8 @@ public class IMEAdaptor extends InventoryAdaptor { } private IItemList getList() { - return this.target.getAvailableItems( - AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList()); + return this.target + .getAvailableItems(Api.instance().storage().getStorageChannel(IItemStorageChannel.class).createList()); } @Override diff --git a/src/main/java/appeng/util/item/AEItemStack.java b/src/main/java/appeng/util/item/AEItemStack.java index 3fc7fa749..958354c24 100644 --- a/src/main/java/appeng/util/item/AEItemStack.java +++ b/src/main/java/appeng/util/item/AEItemStack.java @@ -32,11 +32,11 @@ import net.minecraft.network.PacketByteBuf; import net.minecraft.text.Text; import net.fabricmc.api.EnvType; -import appeng.api.AEApi; import appeng.api.config.FuzzyMode; import appeng.api.storage.IStorageChannel; import appeng.api.storage.channels.IItemStorageChannel; import appeng.api.storage.data.IAEItemStack; +import appeng.core.Api; import appeng.util.Platform; import net.minecraft.util.registry.Registry; @@ -152,19 +152,9 @@ public final class AEItemStack extends AEStack implements IAEItemS return new AEItemStack(this); } - @Override - public boolean isItem() { - return true; - } - - @Override - public boolean isFluid() { - return false; - } - @Override public IStorageChannel getChannel() { - return AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class); + return Api.instance().storage().getStorageChannel(IItemStorageChannel.class); } @Override @@ -216,11 +206,16 @@ public final class AEItemStack extends AEStack implements IAEItemS if (ia instanceof AEItemStack) { return this.isSameType((AEItemStack) ia); } else if (ia instanceof ItemStack) { - return this.isSameType((ItemStack) ia); + // this actually breaks the equals contract (being equals to unrelated classes) + return equals((ItemStack) ia); } return false; } + public boolean equals(final ItemStack is) { + return this.isSameType(is); + } + @Override public String toString() { return this.getStackSize() + "x" + Registry.ITEM.getId(this.getDefinition().getItem()); diff --git a/src/main/java/appeng/util/item/ItemModList.java b/src/main/java/appeng/util/item/ItemModList.java index 96d985e02..885cbd521 100644 --- a/src/main/java/appeng/util/item/ItemModList.java +++ b/src/main/java/appeng/util/item/ItemModList.java @@ -20,16 +20,16 @@ package appeng.util.item; import java.util.Collection; -import appeng.api.AEApi; import appeng.api.config.FuzzyMode; import appeng.api.storage.channels.IItemStorageChannel; import appeng.api.storage.data.IAEItemStack; import appeng.api.storage.data.IItemContainer; +import appeng.core.Api; public class ItemModList implements IItemContainer { private final IItemContainer backingStore; - private final IItemContainer overrides = AEApi.instance().storage() + private final IItemContainer overrides = Api.instance().storage() .getStorageChannel(IItemStorageChannel.class).createList(); public ItemModList(final IItemContainer backend) { diff --git a/src/main/java/appeng/worldgen/meteorite/MeteoritePlacer.java b/src/main/java/appeng/worldgen/meteorite/MeteoritePlacer.java index 23427474e..7ea78d38d 100644 --- a/src/main/java/appeng/worldgen/meteorite/MeteoritePlacer.java +++ b/src/main/java/appeng/worldgen/meteorite/MeteoritePlacer.java @@ -41,12 +41,12 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockBox; import net.minecraft.world.WorldAccess; -import appeng.api.AEApi; import appeng.api.definitions.IBlockDefinition; import appeng.api.definitions.IBlocks; import appeng.api.definitions.IMaterials; import appeng.api.features.AEFeature; import appeng.core.AEConfig; +import appeng.core.Api; import appeng.core.worlddata.WorldData; import appeng.util.InventoryAdaptor; import appeng.util.Platform; @@ -95,7 +95,7 @@ public final class MeteoritePlacer { this.squaredMeteoriteSize = this.meteoriteSize * this.meteoriteSize; this.crater = this.realCrater * this.realCrater; - final IBlocks blocks = AEApi.instance().definitions().blocks(); + final IBlocks blocks = Api.instance().definitions().blocks(); this.skyChestDefinition = blocks.skyStoneChest(); this.skyStone = blocks.skyStoneBlock().block().getDefaultState(); @@ -239,7 +239,7 @@ public final class MeteoritePlacer { } ItemStack toAdd = ItemStack.EMPTY; - final IMaterials materials = AEApi.instance().definitions().materials(); + final IMaterials materials = Api.instance().definitions().materials(); switch (r % 4) { case 0: diff --git a/src/main/java/team/chisel/ctm/api/IFacade.java b/src/main/java/team/chisel/ctm/api/IFacade.java index f7c11b6fc..c2e87ad21 100644 --- a/src/main/java/team/chisel/ctm/api/IFacade.java +++ b/src/main/java/team/chisel/ctm/api/IFacade.java @@ -1,21 +1,23 @@ package team.chisel.ctm.api; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + import net.minecraft.block.BlockState; import net.minecraft.util.math.Direction; import net.minecraft.util.math.BlockPos; import net.minecraft.world.BlockView; import net.minecraft.world.World; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - /** - * To be implemented on blocks that "hide" another block inside, so connected textures can still be accomplished. + * To be implemented on blocks that "hide" another block inside, so connected + * textures can still be accomplished. */ public interface IFacade { /** - * @deprecated Use {@link #getFacade(BlockView, BlockPos, Direction, BlockPos)} + * @deprecated Use + * {@link #getFacade(BlockView, BlockPos, Direction, BlockPos)} */ @Nonnull @Deprecated @@ -24,20 +26,18 @@ public interface IFacade { /** * Gets the blockstate this facade appears as. * - * @param world - * {@link World} - * @param pos - * The Blocks position - * @param side - * The side being rendered, NOT the side being connected from. - *

- * This value can be null if no side is specified. Please handle this appropriately. - * @param connection - * The position of the block being connected to. + * @param world {@link World} + * @param pos The Blocks position + * @param side The side being rendered, NOT the side being connected from. + *

+ * This value can be null if no side is specified. Please + * handle this appropriately. + * @param connection The position of the block being connected to. * @return The blockstate which your block appears as. */ @Nonnull - default BlockState getFacade(@Nonnull BlockView world, @Nonnull BlockPos pos, @Nullable Direction side, @Nonnull BlockPos connection) { + default BlockState getFacade(@Nonnull BlockView world, @Nonnull BlockPos pos, @Nullable Direction side, + @Nonnull BlockPos connection) { return getFacade(world, pos, side); } diff --git a/src/main/resources/assets/appliedenergistics2/blockstates/chest.json b/src/main/resources/assets/appliedenergistics2/blockstates/chest.json index b5a8459ea..d0cfbf744 100644 --- a/src/main/resources/assets/appliedenergistics2/blockstates/chest.json +++ b/src/main/resources/assets/appliedenergistics2/blockstates/chest.json @@ -7,7 +7,7 @@ }, { "when": { - "slot_state": "empty|offline" + "lights_on": false }, "apply": { "model": "appliedenergistics2:block/chest/lights_off" @@ -15,59 +15,11 @@ }, { "when": { - "slot_state": "online|not_empty|types_full|full" + "lights_on": true }, "apply": { "model": "appliedenergistics2:block/chest/lights_on" } - }, - { - "when": { - "slot_state": "empty" - }, - "apply": { - "model": "appliedenergistics2:block/chest/cell_state_empty" - } - }, - { - "when": { - "slot_state": "offline" - }, - "apply": { - "model": "appliedenergistics2:block/chest/cell_state_offline" - } - }, - { - "when": { - "slot_state": "online" - }, - "apply": { - "model": "appliedenergistics2:block/chest/cell_state_online" - } - }, - { - "when": { - "slot_state": "not_empty" - }, - "apply": { - "model": "appliedenergistics2:block/chest/cell_state_not_empty" - } - }, - { - "when": { - "slot_state": "types_full" - }, - "apply": { - "model": "appliedenergistics2:block/chest/cell_state_types_full" - } - }, - { - "when": { - "slot_state": "full" - }, - "apply": { - "model": "appliedenergistics2:block/chest/cell_state_full" - } } ] } diff --git a/src/main/resources/assets/appliedenergistics2/models/block/chest/base.json b/src/main/resources/assets/appliedenergistics2/models/block/chest/base.json index 1d5df6cb3..5af101397 100644 --- a/src/main/resources/assets/appliedenergistics2/models/block/chest/base.json +++ b/src/main/resources/assets/appliedenergistics2/models/block/chest/base.json @@ -1,25 +1,109 @@ { - "credit": "Made with Blockbench", - "parent": "block/cube", - "textures": { - "up": "appliedenergistics2:block/chest/top", - "down": "appliedenergistics2:block/chest/bottom", - "north": "appliedenergistics2:block/chest/front", - "particle": "appliedenergistics2:block/chest/side", - "east": "appliedenergistics2:block/chest/side" - }, - "elements": [ - { - "from": [0, 0, 0], - "to": [16, 16, 16], - "faces": { - "north": {"uv": [0, 0, 16, 16], "texture": "#north"}, - "east": {"uv": [0, 0, 16, 16], "texture": "#east"}, - "south": {"uv": [0, 0, 16, 16], "texture": "#east"}, - "west": {"uv": [0, 0, 16, 16], "texture": "#east"}, - "up": {"uv": [0, 0, 16, 16], "texture": "#up"}, - "down": {"uv": [0, 0, 16, 16], "texture": "#down"} - } - } - ] -} \ No newline at end of file + "credit": "Made with Blockbench", + "textures": { + "4": "appliedenergistics2:block/drive/drive_inside", + "up": "appliedenergistics2:block/chest/top", + "down": "appliedenergistics2:block/chest/bottom", + "north": "appliedenergistics2:block/chest/front", + "particle": "appliedenergistics2:block/chest/side", + "east": "appliedenergistics2:block/chest/side" + }, + "elements": [ + { + "from": [0, 0, 0], + "to": [16, 16, 16], + "faces": { + "north": { "uv": [0, 0, 16, 16], "texture": "#north" }, + "east": { "uv": [0, 0, 16, 16], "texture": "#east" }, + "south": { "uv": [0, 0, 16, 16], "texture": "#east" }, + "west": { "uv": [0, 0, 16, 16], "texture": "#east" }, + "up": { "uv": [0, 0, 16, 16], "texture": "#up" }, + "down": { "uv": [0, 0, 16, 16], "texture": "#down" } + } + }, + { + "name": "inside_back", + "from": [5, 4, 7], + "to": [11, 7, 10], + "rotation": { "angle": 0, "axis": "y", "origin": [19, 11, 8] }, + "faces": { + "north": { "uv": [4, 1, 16, 14], "texture": "#4" } + } + }, + { + "name": "inside_left", + "from": [11, 1, 1], + "to": [14, 12, 11], + "rotation": { "angle": 0, "axis": "y", "origin": [18, 11, 3] }, + "faces": { + "north": { "uv": [2, 5, 2, 5], "texture": "#4" }, + "west": { "uv": [5, 1, 14, 12], "texture": "#4" } + } + }, + { + "name": "inside_top", + "from": [5, 6, 1], + "to": [11, 9, 11], + "rotation": { "angle": 0, "axis": "y", "origin": [15, 16, 3] }, + "faces": { + "north": { "uv": [2, 7, 2, 7], "texture": "#4" }, + "down": { "uv": [6, 4, 6, 4], "texture": "#4" } + } + }, + { + "name": "inside_bottom", + "from": [5, 1, 1], + "to": [11, 4, 11], + "rotation": { "angle": 0, "axis": "y", "origin": [15, 11, 3] }, + "faces": { + "north": { "uv": [2, 7, 2, 7], "texture": "#4" }, + "up": { "uv": [6, 3, 6, 3], "texture": "#4" } + } + }, + { + "name": "inside_border_bottom", + "from": [4, 0, 0], + "to": [12, 3, 9], + "rotation": { "angle": 0, "axis": "y", "origin": [15, 10, 1] }, + "faces": { + "up": { "uv": [0, 4, 9, 13], "rotation": 90, "texture": "#4" } + } + }, + { + "name": "inside_border_top", + "from": [5, 7, 0], + "to": [12, 10, 9], + "rotation": { "angle": 0, "axis": "y", "origin": [15, 17, 1] }, + "faces": { + "down": { "uv": [0, 4, 9, 13], "rotation": 270, "texture": "#4" } + } + }, + { + "name": "inside_border_left", + "from": [11, 3, 0], + "to": [12, 8, 1], + "rotation": { "angle": 0, "axis": "y", "origin": [15, 13, 1] }, + "faces": { + "west": { "uv": [0, 8, 1, 13], "texture": "#4" } + } + }, + { + "name": "inside_border_right", + "from": [4, 3, 0], + "to": [5, 8, 1], + "rotation": { "angle": 0, "axis": "y", "origin": [8, 13, 1] }, + "faces": { + "east": { "uv": [0, 6, 1, 11], "rotation": 180, "texture": "#4" } + } + }, + { + "name": "inside_right", + "from": [2, 1, 1], + "to": [5, 12, 11], + "rotation": { "angle": 0, "axis": "y", "origin": [9, 11, 3] }, + "faces": { + "east": { "uv": [5, 2, 14, 13], "texture": "#4" } + } + } + ] +} diff --git a/src/main/resources/assets/appliedenergistics2/models/block/chest/cell_state_empty.json b/src/main/resources/assets/appliedenergistics2/models/block/chest/cell_state_empty.json deleted file mode 100644 index 72239d88d..000000000 --- a/src/main/resources/assets/appliedenergistics2/models/block/chest/cell_state_empty.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "textures": { - "state": "appliedenergistics2:block/chest/cell_state_empty" - }, - "elements": [ - { - "from": [0, 0, 0], - "to": [16, 16, 16], - "faces": { - "north": { - "texture": "#state" - } - } - } - ] -} diff --git a/src/main/resources/assets/appliedenergistics2/models/block/chest/cell_state_full.json b/src/main/resources/assets/appliedenergistics2/models/block/chest/cell_state_full.json deleted file mode 100644 index a5517ce02..000000000 --- a/src/main/resources/assets/appliedenergistics2/models/block/chest/cell_state_full.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "loader": "appliedenergistics2:uvlightmap", - "textures": { - "backdrop": "appliedenergistics2:block/chest/cell_state_backdrop", - "state": "appliedenergistics2:block/chest/cell_state_full" - }, - "elements": [ - { - "from": [0, 0, 0], - "to": [16, 16, 16], - "faces": { - "north": { - "texture": "#backdrop" - } - } - }, - { - "from": [0, 0, 0], - "to": [16, 16, 16], - "faces": { - "north": { - "texture": "#state", - "uvlightmap": { - "block": 0.007, - "sky": 0.007 - } - } - } - } - ] -} diff --git a/src/main/resources/assets/appliedenergistics2/models/block/chest/cell_state_not_empty.json b/src/main/resources/assets/appliedenergistics2/models/block/chest/cell_state_not_empty.json deleted file mode 100644 index cb3dcba8f..000000000 --- a/src/main/resources/assets/appliedenergistics2/models/block/chest/cell_state_not_empty.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "loader": "appliedenergistics2:uvlightmap", - "textures": { - "backdrop": "appliedenergistics2:block/chest/cell_state_backdrop", - "state": "appliedenergistics2:block/chest/cell_state_not_empty" - }, - "elements": [ - { - "from": [0, 0, 0], - "to": [16, 16, 16], - "faces": { - "north": { - "texture": "#backdrop" - } - } - }, - { - "from": [0, 0, 0], - "to": [16, 16, 16], - "faces": { - "north": { - "texture": "#state", - "uvlightmap": { - "block": 0.007, - "sky": 0.007 - } - } - } - } - ] -} diff --git a/src/main/resources/assets/appliedenergistics2/models/block/chest/cell_state_offline.json b/src/main/resources/assets/appliedenergistics2/models/block/chest/cell_state_offline.json deleted file mode 100644 index 800895391..000000000 --- a/src/main/resources/assets/appliedenergistics2/models/block/chest/cell_state_offline.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "textures": { - "state": "appliedenergistics2:block/chest/cell_state_offline" - }, - "elements": [ - { - "from": [0, 0, 0], - "to": [16, 16, 16], - "faces": { - "north": { - "texture": "#state" - } - } - } - ] -} diff --git a/src/main/resources/assets/appliedenergistics2/models/block/chest/cell_state_online.json b/src/main/resources/assets/appliedenergistics2/models/block/chest/cell_state_online.json deleted file mode 100644 index 5589251f0..000000000 --- a/src/main/resources/assets/appliedenergistics2/models/block/chest/cell_state_online.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "loader": "appliedenergistics2:uvlightmap", - "textures": { - "backdrop": "appliedenergistics2:block/chest/cell_state_backdrop", - "state": "appliedenergistics2:block/chest/cell_state_online" - }, - "elements": [ - { - "from": [0, 0, 0], - "to": [16, 16, 16], - "faces": { - "north": { - "texture": "#backdrop" - } - } - }, - { - "from": [0, 0, 0], - "to": [16, 16, 16], - "faces": { - "north": { - "texture": "#state", - "uvlightmap": { - "block": 0.007, - "sky": 0.007 - } - } - } - } - ] -} diff --git a/src/main/resources/assets/appliedenergistics2/models/block/chest/cell_state_types_full.json b/src/main/resources/assets/appliedenergistics2/models/block/chest/cell_state_types_full.json deleted file mode 100644 index fd0dd2185..000000000 --- a/src/main/resources/assets/appliedenergistics2/models/block/chest/cell_state_types_full.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "loader": "appliedenergistics2:uvlightmap", - "textures": { - "backdrop": "appliedenergistics2:block/chest/cell_state_backdrop", - "state": "appliedenergistics2:block/chest/cell_state_types_full" - }, - "elements": [ - { - "from": [0, 0, 0], - "to": [16, 16, 16], - "faces": { - "north": { - "texture": "#backdrop" - } - } - }, - { - "from": [0, 0, 0], - "to": [16, 16, 16], - "faces": { - "north": { - "texture": "#state", - "uvlightmap": { - "block": 0.007, - "sky": 0.007 - } - } - } - } - ] -} diff --git a/src/main/resources/assets/appliedenergistics2/models/block/drive/cells/16k_fluid_cell.json b/src/main/resources/assets/appliedenergistics2/models/block/drive/cells/16k_fluid_cell.json new file mode 100644 index 000000000..590869d5f --- /dev/null +++ b/src/main/resources/assets/appliedenergistics2/models/block/drive/cells/16k_fluid_cell.json @@ -0,0 +1,6 @@ +{ + "parent": "appliedenergistics2:block/drive/drive_cell", + "textures": { + "cell": "appliedenergistics2:block/drive/cells/16k_fluid_cell" + } +} diff --git a/src/main/resources/assets/appliedenergistics2/models/block/drive/cells/16k_item_cell.json b/src/main/resources/assets/appliedenergistics2/models/block/drive/cells/16k_item_cell.json new file mode 100644 index 000000000..92a0b85a7 --- /dev/null +++ b/src/main/resources/assets/appliedenergistics2/models/block/drive/cells/16k_item_cell.json @@ -0,0 +1,6 @@ +{ + "parent": "appliedenergistics2:block/drive/drive_cell", + "textures": { + "cell": "appliedenergistics2:block/drive/cells/16k_item_cell" + } +} diff --git a/src/main/resources/assets/appliedenergistics2/models/block/drive/cells/1k_fluid_cell.json b/src/main/resources/assets/appliedenergistics2/models/block/drive/cells/1k_fluid_cell.json new file mode 100644 index 000000000..a6e124c7a --- /dev/null +++ b/src/main/resources/assets/appliedenergistics2/models/block/drive/cells/1k_fluid_cell.json @@ -0,0 +1,6 @@ +{ + "parent": "appliedenergistics2:block/drive/drive_cell", + "textures": { + "cell": "appliedenergistics2:block/drive/cells/1k_fluid_cell" + } +} diff --git a/src/main/resources/assets/appliedenergistics2/models/block/drive/drive_cell_fluids.json b/src/main/resources/assets/appliedenergistics2/models/block/drive/cells/1k_item_cell.json similarity index 55% rename from src/main/resources/assets/appliedenergistics2/models/block/drive/drive_cell_fluids.json rename to src/main/resources/assets/appliedenergistics2/models/block/drive/cells/1k_item_cell.json index c1e46c708..335e0cc59 100644 --- a/src/main/resources/assets/appliedenergistics2/models/block/drive/drive_cell_fluids.json +++ b/src/main/resources/assets/appliedenergistics2/models/block/drive/cells/1k_item_cell.json @@ -1,6 +1,6 @@ { "parent": "appliedenergistics2:block/drive/drive_cell", "textures": { - "cell": "appliedenergistics2:block/drive/fluid_cell" + "cell": "appliedenergistics2:block/drive/cells/1k_item_cell" } } diff --git a/src/main/resources/assets/appliedenergistics2/models/block/drive/cells/4k_fluid_cell.json b/src/main/resources/assets/appliedenergistics2/models/block/drive/cells/4k_fluid_cell.json new file mode 100644 index 000000000..bf12ce6bf --- /dev/null +++ b/src/main/resources/assets/appliedenergistics2/models/block/drive/cells/4k_fluid_cell.json @@ -0,0 +1,6 @@ +{ + "parent": "appliedenergistics2:block/drive/drive_cell", + "textures": { + "cell": "appliedenergistics2:block/drive/cells/4k_fluid_cell" + } +} diff --git a/src/main/resources/assets/appliedenergistics2/models/block/drive/drive_cell_items.json b/src/main/resources/assets/appliedenergistics2/models/block/drive/cells/4k_item_cell.json similarity index 55% rename from src/main/resources/assets/appliedenergistics2/models/block/drive/drive_cell_items.json rename to src/main/resources/assets/appliedenergistics2/models/block/drive/cells/4k_item_cell.json index 5fcaa819c..518338801 100644 --- a/src/main/resources/assets/appliedenergistics2/models/block/drive/drive_cell_items.json +++ b/src/main/resources/assets/appliedenergistics2/models/block/drive/cells/4k_item_cell.json @@ -1,6 +1,6 @@ { "parent": "appliedenergistics2:block/drive/drive_cell", "textures": { - "cell": "appliedenergistics2:block/drive/item_cell" + "cell": "appliedenergistics2:block/drive/cells/4k_item_cell" } } diff --git a/src/main/resources/assets/appliedenergistics2/models/block/drive/cells/64k_fluid_cell.json b/src/main/resources/assets/appliedenergistics2/models/block/drive/cells/64k_fluid_cell.json new file mode 100644 index 000000000..190c69796 --- /dev/null +++ b/src/main/resources/assets/appliedenergistics2/models/block/drive/cells/64k_fluid_cell.json @@ -0,0 +1,6 @@ +{ + "parent": "appliedenergistics2:block/drive/drive_cell", + "textures": { + "cell": "appliedenergistics2:block/drive/cells/64k_fluid_cell" + } +} diff --git a/src/main/resources/assets/appliedenergistics2/models/block/drive/cells/64k_item_cell.json b/src/main/resources/assets/appliedenergistics2/models/block/drive/cells/64k_item_cell.json new file mode 100644 index 000000000..64bfb14cc --- /dev/null +++ b/src/main/resources/assets/appliedenergistics2/models/block/drive/cells/64k_item_cell.json @@ -0,0 +1,6 @@ +{ + "parent": "appliedenergistics2:block/drive/drive_cell", + "textures": { + "cell": "appliedenergistics2:block/drive/cells/64k_item_cell" + } +} diff --git a/src/main/resources/assets/appliedenergistics2/models/block/drive/cells/creative_cell.json b/src/main/resources/assets/appliedenergistics2/models/block/drive/cells/creative_cell.json new file mode 100644 index 000000000..a289cd039 --- /dev/null +++ b/src/main/resources/assets/appliedenergistics2/models/block/drive/cells/creative_cell.json @@ -0,0 +1,6 @@ +{ + "parent": "appliedenergistics2:block/drive/drive_cell", + "textures": { + "cell": "appliedenergistics2:block/drive/cells/creative_cell" + } +} diff --git a/src/main/resources/assets/appliedenergistics2/models/block/drive/drive_cell_led_base.json b/src/main/resources/assets/appliedenergistics2/models/block/drive/drive_cell_led_base.json deleted file mode 100644 index c3efcc340..000000000 --- a/src/main/resources/assets/appliedenergistics2/models/block/drive/drive_cell_led_base.json +++ /dev/null @@ -1,55 +0,0 @@ -{ - "loader": "appliedenergistics2:uvlightmap", - "textures": { - "front": "appliedenergistics2:block/drive/drive/cell_state_offline" - }, - "elements": [ - { - "name": "Cell Light", - "from": [9.0, 13.0, 0.0], - "to": [14.0, 15.0, 1.0], - "faces": { - "north": { - "texture": "#front", - "uv": [0, 0, 16, 16], - "uvlightmap": { - "sky": 0.007, - "block": 0.007 - } - }, - "up": { - "texture": "#front", - "uv": [0, 0, 16, 16], - "uvlightmap": { - "sky": 0.007, - "block": 0.007 - } - }, - "down": { - "texture": "#front", - "uv": [0, 0, 16, 16], - "uvlightmap": { - "sky": 0.007, - "block": 0.007 - } - }, - "west": { - "texture": "#front", - "uv": [0, 0, 16, 16], - "uvlightmap": { - "sky": 0.007, - "block": 0.007 - } - }, - "east": { - "texture": "#front", - "uv": [0, 0, 16, 16], - "uvlightmap": { - "sky": 0.007, - "block": 0.007 - } - } - } - } - ] -} diff --git a/src/main/resources/assets/appliedenergistics2/textures/block/chest/front.png b/src/main/resources/assets/appliedenergistics2/textures/block/chest/front.png index 4e4e034e9..81fecf6e8 100644 Binary files a/src/main/resources/assets/appliedenergistics2/textures/block/chest/front.png and b/src/main/resources/assets/appliedenergistics2/textures/block/chest/front.png differ diff --git a/src/main/resources/assets/appliedenergistics2/textures/block/drive/fluid_cell.png b/src/main/resources/assets/appliedenergistics2/textures/block/drive/cells/16k_fluid_cell.png similarity index 53% rename from src/main/resources/assets/appliedenergistics2/textures/block/drive/fluid_cell.png rename to src/main/resources/assets/appliedenergistics2/textures/block/drive/cells/16k_fluid_cell.png index d3abeda66..fa2693a04 100644 Binary files a/src/main/resources/assets/appliedenergistics2/textures/block/drive/fluid_cell.png and b/src/main/resources/assets/appliedenergistics2/textures/block/drive/cells/16k_fluid_cell.png differ diff --git a/src/main/resources/assets/appliedenergistics2/textures/block/drive/item_cell.png b/src/main/resources/assets/appliedenergistics2/textures/block/drive/cells/16k_item_cell.png similarity index 53% rename from src/main/resources/assets/appliedenergistics2/textures/block/drive/item_cell.png rename to src/main/resources/assets/appliedenergistics2/textures/block/drive/cells/16k_item_cell.png index 4c90c29d3..e4679422b 100644 Binary files a/src/main/resources/assets/appliedenergistics2/textures/block/drive/item_cell.png and b/src/main/resources/assets/appliedenergistics2/textures/block/drive/cells/16k_item_cell.png differ diff --git a/src/main/resources/assets/appliedenergistics2/textures/block/drive/cells/1k_fluid_cell.png b/src/main/resources/assets/appliedenergistics2/textures/block/drive/cells/1k_fluid_cell.png new file mode 100644 index 000000000..e0a03f24a Binary files /dev/null and b/src/main/resources/assets/appliedenergistics2/textures/block/drive/cells/1k_fluid_cell.png differ diff --git a/src/main/resources/assets/appliedenergistics2/textures/block/drive/cells/1k_item_cell.png b/src/main/resources/assets/appliedenergistics2/textures/block/drive/cells/1k_item_cell.png new file mode 100644 index 000000000..3cc05dfb6 Binary files /dev/null and b/src/main/resources/assets/appliedenergistics2/textures/block/drive/cells/1k_item_cell.png differ diff --git a/src/main/resources/assets/appliedenergistics2/textures/block/drive/cells/4k_fluid_cell.png b/src/main/resources/assets/appliedenergistics2/textures/block/drive/cells/4k_fluid_cell.png new file mode 100644 index 000000000..f6836271a Binary files /dev/null and b/src/main/resources/assets/appliedenergistics2/textures/block/drive/cells/4k_fluid_cell.png differ diff --git a/src/main/resources/assets/appliedenergistics2/textures/block/drive/cells/4k_item_cell.png b/src/main/resources/assets/appliedenergistics2/textures/block/drive/cells/4k_item_cell.png new file mode 100644 index 000000000..7668e0ea5 Binary files /dev/null and b/src/main/resources/assets/appliedenergistics2/textures/block/drive/cells/4k_item_cell.png differ diff --git a/src/main/resources/assets/appliedenergistics2/textures/block/drive/cells/64k_fluid_cell.png b/src/main/resources/assets/appliedenergistics2/textures/block/drive/cells/64k_fluid_cell.png new file mode 100644 index 000000000..0d4c7e2cc Binary files /dev/null and b/src/main/resources/assets/appliedenergistics2/textures/block/drive/cells/64k_fluid_cell.png differ diff --git a/src/main/resources/assets/appliedenergistics2/textures/block/drive/cells/64k_item_cell.png b/src/main/resources/assets/appliedenergistics2/textures/block/drive/cells/64k_item_cell.png new file mode 100644 index 000000000..816f526a2 Binary files /dev/null and b/src/main/resources/assets/appliedenergistics2/textures/block/drive/cells/64k_item_cell.png differ diff --git a/src/main/resources/assets/appliedenergistics2/textures/block/drive/cells/creative_cell.png b/src/main/resources/assets/appliedenergistics2/textures/block/drive/cells/creative_cell.png new file mode 100644 index 000000000..85fe9b851 Binary files /dev/null and b/src/main/resources/assets/appliedenergistics2/textures/block/drive/cells/creative_cell.png differ diff --git a/src/main/resources/assets/appliedenergistics2/textures/block/drive/cells/default_cell.png b/src/main/resources/assets/appliedenergistics2/textures/block/drive/cells/default_cell.png new file mode 100644 index 000000000..3a78b7800 Binary files /dev/null and b/src/main/resources/assets/appliedenergistics2/textures/block/drive/cells/default_cell.png differ diff --git a/src/main/resources/data/appliedenergistics2/tags/blocks/spatial/blacklist.json b/src/main/resources/data/appliedenergistics2/tags/blocks/spatial/blacklist.json new file mode 100644 index 000000000..86dde3df2 --- /dev/null +++ b/src/main/resources/data/appliedenergistics2/tags/blocks/spatial/blacklist.json @@ -0,0 +1,3 @@ +{ + "values": [] +} diff --git a/src/main/resources/data/appliedenergistics2/tags/blocks/spatial/whitelist.json b/src/main/resources/data/appliedenergistics2/tags/blocks/spatial/whitelist.json new file mode 100644 index 000000000..86dde3df2 --- /dev/null +++ b/src/main/resources/data/appliedenergistics2/tags/blocks/spatial/whitelist.json @@ -0,0 +1,3 @@ +{ + "values": [] +} diff --git a/src/unported/java/appeng/block/qnb/QnbFormedBakedModel.java b/src/unported/java/appeng/block/qnb/QnbFormedBakedModel.java index 200ea5593..a09475f02 100644 --- a/src/unported/java/appeng/block/qnb/QnbFormedBakedModel.java +++ b/src/unported/java/appeng/block/qnb/QnbFormedBakedModel.java @@ -23,8 +23,8 @@ import net.minecraft.client.texture.Sprite; import net.minecraft.util.Identifier; import net.minecraft.util.math.Direction; -import appeng.api.AEApi; import appeng.client.render.cablebus.CubeBuilder; +import appeng.core.Api; import appeng.core.AppEng; import appeng.tile.qnb.QuantumBridgeBlockEntity; @@ -71,7 +71,7 @@ class QnbFormedBakedModel implements IDynamicBakedModel { this.coveredCableTexture = bakedTextureGetter.apply(TEXTURE_COVERED_CABLE); this.lightTexture = bakedTextureGetter.apply(TEXTURE_RING_LIGHT); this.lightCornerTexture = bakedTextureGetter.apply(TEXTURE_RING_LIGHT_CORNER); - this.linkBlock = AEApi.instance().definitions().blocks().quantumLink().maybeBlock().orElse(null); + this.linkBlock = Api.instance().definitions().blocks().quantumLink().maybeBlock().orElse(null); } @Override diff --git a/src/unported/java/appeng/client/ClientHelper.java b/src/unported/java/appeng/client/ClientHelper.java index 7d54e5b40..993ba6c27 100644 --- a/src/unported/java/appeng/client/ClientHelper.java +++ b/src/unported/java/appeng/client/ClientHelper.java @@ -37,7 +37,10 @@ import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.client.registry.ClientRegistry; import appeng.block.AEBaseBlock; -import appeng.client.render.effects.*; +import appeng.client.render.effects.EnergyParticleData; +import appeng.client.render.effects.LightningArcFX; +import appeng.client.render.effects.LightningFX; +import appeng.client.render.effects.ParticleTypes; import appeng.core.AEConfig; import appeng.core.AppEng; import appeng.core.sync.network.NetworkHandler; diff --git a/src/unported/java/appeng/client/render/model/DriveBakedModel.java b/src/unported/java/appeng/client/render/model/DriveBakedModel.java index ad3d773b5..73f95f00b 100644 --- a/src/unported/java/appeng/client/render/model/DriveBakedModel.java +++ b/src/unported/java/appeng/client/render/model/DriveBakedModel.java @@ -28,26 +28,39 @@ import javax.annotation.Nullable; import net.minecraft.block.BlockState; import net.minecraft.client.render.model.BakedModel; +import net.minecraft.client.renderer.Vector3f; import net.minecraft.client.util.math.Vector3f; import net.minecraft.util.math.Matrix4f; import net.minecraft.client.render.model.BakedQuad; import net.minecraft.item.Item; +import net.minecraft.item.Items; import net.minecraft.util.math.Direction; - import net.minecraftforge.client.model.pipeline.BakedQuadBuilder; -import appeng.api.definitions.IItems; -import appeng.block.storage.DriveSlotCellType; import appeng.block.storage.DriveSlotsState; import appeng.client.render.DelegateBakedModel; -import appeng.core.Api; public class DriveBakedModel extends DelegateBakedModel { - private final Map bakedCells; + private final Map bakedCells; + private final IBakedModel defaultCell; - public DriveBakedModel(BakedModel bakedBase, Map bakedCells) { + public DriveBakedModel(BakedModel bakedBase, Map cellModels, IBakedModel defaultCell) { super(bakedBase); - this.bakedCells = bakedCells; + this.bakedCells = cellModels; + this.defaultCell = defaultCell; + } + + /** + * Calculates the origin of a drive slot for positioning a cell model into it. + */ + public static void getSlotOrigin(int row, int col, Vector3f translation) { + // Position this drive model copy at the correct slot. The transform is based on + // the cell-model being in slot 0,0,0 while the upper left slot's origin is at + // 9,13,1 + float xOffset = (9 - col * 8) / 16.0f; + float yOffset = (13 - row * 3) / 16.0f; + float zOffset = 1 / 16.0f; + translation.set(xOffset, yOffset, zOffset); } @Nonnull @@ -64,17 +77,14 @@ public class DriveBakedModel extends DelegateBakedModel { DriveSlotsState slotsState = driveModelData.getSlotsState(); + Vector3f slotTranslation = new Vector3f(); if (slotsState != null) { for (int row = 0; row < 5; row++) { for (int col = 0; col < 2; col++) { Matrix4f transform = new Matrix4f(); - // Position this drive model copy at the correct slot. The transform is based on - // the - // cell-model being in slot 0,0 at the top left of the drive. - float xOffset = -col * 8 / 16.0f; - float yOffset = -row * 3 / 16.0f; - transform.addToLastColumn(new Vector3f(xOffset, yOffset, 0)); + getSlotOrigin(row, col, slotTranslation); + transform.addToLastColumn(new Vector3f(slotTranslation.getX(), slotTranslation.getY(), slotTranslation.getZ())); int slot = row * 2 + col; @@ -93,23 +103,18 @@ public class DriveBakedModel extends DelegateBakedModel { public boolean useAmbientOcclusion() { // We have faces inside the chassis that are facing east, but should not receive // ambient occlusion from the east-side, but sadly this cannot be fine-tuned on - // a - // face-by-face basis. + // a face-by-face basis. return false; } // Determine which drive chassis to show based on the used cell private BakedModel getCellChassisModel(Item cell) { - IItems items = Api.INSTANCE.definitions().items(); if (cell == null) { - return bakedCells.get(DriveSlotCellType.EMPTY); - } else if (items.fluidCell1k().item() == cell || items.fluidCell4k().item() == cell - || items.fluidCell16k().item() == cell || items.fluidCell64k().item() == cell) { - return bakedCells.get(DriveSlotCellType.FLUID); - } else { - // Fall back to an item model - return bakedCells.get(DriveSlotCellType.ITEM); + return bakedCells.get(Items.AIR); } + final IBakedModel model = bakedCells.get(cell); + + return model != null ? model : defaultCell; } private static void addModel(@Nullable BlockState state, @Nonnull Random rand, @Nonnull IModelData extraData, diff --git a/src/unported/java/appeng/client/render/model/DriveModel.java b/src/unported/java/appeng/client/render/model/DriveModel.java index f1d796527..672870e86 100644 --- a/src/unported/java/appeng/client/render/model/DriveModel.java +++ b/src/unported/java/appeng/client/render/model/DriveModel.java @@ -20,13 +20,12 @@ package appeng.client.render.model; import java.util.Collection; import java.util.Collections; -import java.util.EnumMap; +import java.util.IdentityHashMap; import java.util.Map; +import java.util.Map.Entry; import java.util.Set; import java.util.function.Function; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; import com.mojang.datafixers.util.Pair; import net.minecraft.client.render.model.BakedModel; @@ -36,39 +35,41 @@ import net.minecraft.client.render.model.json.ModelOverrideList; import net.minecraft.client.util.SpriteIdentifier; import net.minecraft.client.render.model.ModelLoader; import net.minecraft.client.texture.Sprite; +import net.minecraft.item.Item; +import net.minecraft.item.Items; import net.minecraft.util.Identifier; import net.minecraftforge.client.model.IModelConfiguration; import net.minecraftforge.client.model.geometry.IModelGeometry; -import appeng.block.storage.DriveSlotCellType; +import appeng.api.client.ICellModelRegistry; +import appeng.core.Api; public class DriveModel implements IModelGeometry { private static final Identifier MODEL_BASE = new Identifier( "appliedenergistics2:block/drive/drive_base"); - - private static final Map MODELS_CELLS = ImmutableMap.of( - DriveSlotCellType.EMPTY, new Identifier("appliedenergistics2:block/drive/drive_cell_empty"), - DriveSlotCellType.ITEM, new Identifier("appliedenergistics2:block/drive/drive_cell_items"), - DriveSlotCellType.FLUID, new Identifier("appliedenergistics2:block/drive/drive_cell_fluids")); - - public static final Set DEPENDENCIES = ImmutableSet.builder() - .addAll(MODELS_CELLS.values()).add(MODEL_BASE).build(); + private static final ResourceLocation MODEL_CELL_EMPTY = new ResourceLocation( + "appliedenergistics2:block/drive/drive_cell_empty"); @Override public BakedModel bake(IModelConfiguration owner, ModelLoader bakery, Function spriteGetter, IModelTransform modelTransform, ModelOverrideList overrides, Identifier modelLocation) { - EnumMap cellModels = new EnumMap<>(DriveSlotCellType.class); + final ICellModelRegistry cellRegistry = Api.instance().client().cells(); + final Map cellModels = new IdentityHashMap<>(); - // Load the base model and the model for each cell state. - for (DriveSlotCellType cellType : MODELS_CELLS.keySet()) { - BakedModel cellModel = bakery.getBakedModel(MODELS_CELLS.get(cellType), modelTransform, spriteGetter); - cellModels.put(cellType, cellModel); + // Load the base model and the model for each cell model. + for (Entry entry : cellRegistry.models().entrySet()) { + BakedModel cellModel = bakery.getBakedModel(entry.getValue(), modelTransform, spriteGetter); + cellModels.put(entry.getKey(), cellModel); } - BakedModel baseModel = bakery.getBakedModel(MODEL_BASE, modelTransform, spriteGetter); - return new DriveBakedModel(baseModel, cellModels); + final BakedModel baseModel = bakery.getBakedModel(MODEL_BASE, modelTransform, spriteGetter); + final BakedModel defaultCell = bakery.getBakedModel(cellRegistry.getDefaultModel(), modelTransform, + spriteGetter); + cellModels.put(Items.AIR, bakery.getBakedModel(MODEL_CELL_EMPTY, modelTransform, spriteGetter)); + + return new DriveBakedModel(baseModel, cellModels, defaultCell); } @Override diff --git a/src/unported/java/appeng/core/PluginLoader.java b/src/unported/java/appeng/core/PluginLoader.java deleted file mode 100644 index c894266a2..000000000 --- a/src/unported/java/appeng/core/PluginLoader.java +++ /dev/null @@ -1,148 +0,0 @@ -/* - * This file is part of Applied Energistics 2. - * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. - * - * Applied Energistics 2 is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Applied Energistics 2 is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Applied Energistics 2. If not, see . - */ - -package appeng.core; - -import java.lang.annotation.ElementType; -import java.lang.reflect.Constructor; -import java.util.Collection; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import java.util.stream.Collectors; - -import com.google.common.collect.ImmutableMap; - -import org.objectweb.asm.Type; - -import net.minecraftforge.fml.ModList; -import net.minecraftforge.forgespi.language.ModFileScanData; - -import appeng.api.AEInjectable; -import appeng.api.AEPlugin; - -/** - * Loads AE plugins on startup and provides them with access to various - * components of the AE API. - */ -class PluginLoader { - - public void loadPlugins(Collection injectables) { - Map, Object> injectableMap = mapInjectables(injectables); - findAndInstantiatePlugins(injectableMap); - } - - private static void findAndInstantiatePlugins(Map, Object> injectableMap) { - Type aType = Type.getType(AEPlugin.class); - Set allAnnotated = ModList.get().getAllScanData().stream() - .map(ModFileScanData::getAnnotations).flatMap(Collection::stream) - .filter(a -> a.getAnnotationType().equals(aType)).filter(a -> a.getTargetType() == ElementType.TYPE) - .collect(Collectors.toSet()); - - for (ModFileScanData.AnnotationData candidate : allAnnotated) { - - String cName = candidate.getMemberName(); - Class aClass; - try { - aClass = Class.forName(cName); - } catch (ClassNotFoundException e) { - AELog.error(e, "Couldn't find annotated AE plugin class " + cName); - throw new RuntimeException("Couldn't find annotated AE plugin class " + cName, e); - } - - // Try instantiating the plugin - try { - Object plugin = instantiatePlugin(aClass, injectableMap); - AELog.info("Loaded AE2 Plugin {}", plugin.getClass()); - } catch (Exception e) { - AELog.error(e, "Unable to instantiate AE plugin " + cName); - throw new RuntimeException("Unable to instantiate AE plugin " + cName, e); - } - } - } - - private static Object instantiatePlugin(Class aClass, Map, Object> injectableMap) throws Exception { - - Constructor[] constructors = aClass.getDeclaredConstructors(); - - if (constructors.length == 0) { - // This is the default no-arg constructor, although it seems pointless to - // instantiate anything but not take - // any AE dependencies as parameters - return aClass.newInstance(); - } else if (constructors.length != 1) { - throw new IllegalArgumentException("Expected a single constructor, but found: " + constructors.length); - } - - Constructor constructor = constructors[0]; - constructor.setAccessible(true); - - Object[] args = findInjectables(constructor, injectableMap); - - return constructor.newInstance(args); - } - - private static Object[] findInjectables(Constructor constructor, Map, Object> injectableMap) { - - Class[] types = constructor.getParameterTypes(); - Object[] args = new Object[types.length]; - - for (int i = 0; i < types.length; i++) { - args[i] = injectableMap.get(types[i]); - if (args[i] == null) { - throw new IllegalArgumentException("Constructor has parameter of type " + types[i] - + " which is not an injectable type." + " Please see the documentation for @AEPlugin."); - } - } - - return args; - } - - private static Map, Object> mapInjectables(Collection injectables) { - ImmutableMap.Builder, Object> builder = ImmutableMap.builder(); - - for (Object injectable : injectables) { - // Get all super-interfaces that were annotated with @AEInjectable - Set> injectableIfs = getInjectableInterfaces(injectable.getClass()); - for (Class injectableIf : injectableIfs) { - builder.put(injectableIf, injectable); - } - } - - return builder.build(); - } - - private static Set> getInjectableInterfaces(Class aClass) { - Set> hierarchy = new HashSet<>(); - getFullHierarchy(aClass, hierarchy); - - return hierarchy.stream().filter(c -> c.getAnnotation(AEInjectable.class) != null).collect(Collectors.toSet()); - } - - // Recursively gather all superclasses and superinterfaces of the given class - // and put them into the given collection - private static void getFullHierarchy(Class aClass, Set> classes) { - classes.add(aClass); - for (Class anIf : aClass.getInterfaces()) { - getFullHierarchy(anIf, classes); - } - if (aClass.getSuperclass() != null) { - getFullHierarchy(aClass.getSuperclass(), classes); - } - } -} diff --git a/src/unported/java/appeng/debug/EnergyGeneratorBlockEntity.java b/src/unported/java/appeng/debug/EnergyGeneratorBlockEntity.java index 0fb67d5f7..662c0e3f9 100644 --- a/src/unported/java/appeng/debug/EnergyGeneratorBlockEntity.java +++ b/src/unported/java/appeng/debug/EnergyGeneratorBlockEntity.java @@ -48,7 +48,7 @@ public class EnergyGeneratorBlockEntity extends AEBaseBlockEntity implements Tic @Override public void tick() { World world = this.getWorld(); - if (world == null) { + if (world == null || world.isRemote) { return; } diff --git a/src/unported/java/appeng/hooks/AETrading.java b/src/unported/java/appeng/hooks/AETrading.java index e31913bfb..0a746bbb2 100644 --- a/src/unported/java/appeng/hooks/AETrading.java +++ b/src/unported/java/appeng/hooks/AETrading.java @@ -25,7 +25,7 @@ public class AETrading { /* * @Override public void manipulateTradesForVillager( EntityVillager villager, * MerchantRecipeList recipeList, Random random ) { final IMaterials materials = - * AEApi.instance().definitions().materials(); this.addMerchant( recipeList, + * Api.instance().definitions().materials(); this.addMerchant( recipeList, * materials.silicon(), 1, random, 2 ); this.addMerchant( recipeList, * materials.certusQuartzCrystal(), 2, random, 4 ); this.addMerchant( * recipeList, materials.certusQuartzDust(), 1, random, 3 ); this.addTrade( diff --git a/src/unported/java/appeng/recipes/game/DisassembleRecipe.java b/src/unported/java/appeng/recipes/game/DisassembleRecipe.java index cc0ee0d1f..bd03a3a9c 100644 --- a/src/unported/java/appeng/recipes/game/DisassembleRecipe.java +++ b/src/unported/java/appeng/recipes/game/DisassembleRecipe.java @@ -33,7 +33,6 @@ import net.minecraft.item.crafting.SpecialRecipeSerializer; import net.minecraft.util.Identifier; import net.minecraft.world.World; -import appeng.api.AEApi; import appeng.api.definitions.IBlocks; import appeng.api.definitions.IDefinitions; import appeng.api.definitions.IItemDefinition; @@ -43,6 +42,7 @@ import appeng.api.storage.IMEInventory; import appeng.api.storage.channels.IItemStorageChannel; import appeng.api.storage.data.IAEItemStack; import appeng.api.storage.data.IItemList; +import appeng.core.Api; import appeng.core.AppEng; public final class DisassembleRecipe extends SpecialRecipe { @@ -61,7 +61,7 @@ public final class DisassembleRecipe extends SpecialRecipe { public DisassembleRecipe(Identifier id) { super(id); - final IDefinitions definitions = AEApi.instance().definitions(); + final IDefinitions definitions = Api.instance().definitions(); final IBlocks blocks = definitions.blocks(); final IItems items = definitions.items(); final IMaterials mats = definitions.materials(); @@ -105,11 +105,11 @@ public final class DisassembleRecipe extends SpecialRecipe { if (maybeCellOutput.isPresent()) { ItemStack storageCellStack = maybeCellOutput.get(); // make sure the storage cell stackInSlot empty... - final IMEInventory cellInv = AEApi.instance().registries().cell().getCellInventory( - stackInSlot, null, AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)); + final IMEInventory cellInv = Api.instance().registries().cell().getCellInventory( + stackInSlot, null, Api.instance().storage().getStorageChannel(IItemStorageChannel.class)); if (cellInv != null) { final IItemList list = cellInv.getAvailableItems( - AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList()); + Api.instance().storage().getStorageChannel(IItemStorageChannel.class).createList()); if (!list.isEmpty()) { return ItemStack.EMPTY; } diff --git a/src/unported/java/appeng/recipes/game/FacadeRecipe.java b/src/unported/java/appeng/recipes/game/FacadeRecipe.java index 9bc33c31d..76e35b713 100644 --- a/src/unported/java/appeng/recipes/game/FacadeRecipe.java +++ b/src/unported/java/appeng/recipes/game/FacadeRecipe.java @@ -29,9 +29,9 @@ import net.minecraft.item.crafting.SpecialRecipeSerializer; import net.minecraft.util.Identifier; import net.minecraft.world.World; -import appeng.api.AEApi; import appeng.api.definitions.IComparableDefinition; import appeng.api.definitions.IDefinitions; +import appeng.core.Api; import appeng.core.AppEng; import appeng.items.parts.FacadeItem; @@ -44,7 +44,7 @@ public final class FacadeRecipe extends SpecialRecipe { public FacadeRecipe(Identifier id, FacadeItem facade) { super(id); this.facade = facade; - final IDefinitions definitions = AEApi.instance().definitions(); + final IDefinitions definitions = Api.instance().definitions(); this.anchor = definitions.parts().cableAnchor(); } diff --git a/src/unported/resources/META-INF/mods.toml b/src/unported/resources/META-INF/mods.toml index 27d6b05db..96143ca28 100644 --- a/src/unported/resources/META-INF/mods.toml +++ b/src/unported/resources/META-INF/mods.toml @@ -16,7 +16,7 @@ description="A Mod about Matter, Energy and using them to conquer the world.." [[dependencies.appliedenergistics2]] modId="forge" mandatory=true - versionRange="[31.0.0,)" + versionRange="[31.2.31,32.0.0)" ordering="NONE" side="BOTH" diff --git a/src/unported/resources/assets/appliedenergistics2/models/block/drive/drive_cell.json b/src/unported/resources/assets/appliedenergistics2/models/block/drive/drive_cell.json index fdeb22556..297a751d4 100644 --- a/src/unported/resources/assets/appliedenergistics2/models/block/drive/drive_cell.json +++ b/src/unported/resources/assets/appliedenergistics2/models/block/drive/drive_cell.json @@ -1,12 +1,13 @@ { + "ambientocclusion": false, "textures": { - "cell": "appliedenergistics2:block/drive/item_cell" + "cell": "appliedenergistics2:block/drive/cells/default_cell" }, "elements": [ { "name": "Cell Backdrop", - "from": [9, 13, 1], - "to": [15, 15, 3], + "from": [0, 0, 0], + "to": [6, 2, 2], "rotation": { "angle": 0, "axis": "y", "origin": [9, 8, 8] }, "faces": { "north": {