diff --git a/.gitignore b/.gitignore index b7b163b6bb2..ef7cee249b3 100644 --- a/.gitignore +++ b/.gitignore @@ -36,4 +36,6 @@ build !.github/ # Explicit ignores -Thumbs.db \ No newline at end of file +Thumbs.db + +libs/markdown/bin/ \ No newline at end of file diff --git a/build.gradle b/build.gradle index e7d2500f5a5..32172866b52 100644 --- a/build.gradle +++ b/build.gradle @@ -19,7 +19,7 @@ plugins { id 'fabric-loom' version '1.0-SNAPSHOT' id 'maven-publish' - id "com.diffplug.spotless" version "5.12.4" + //id "com.diffplug.spotless" version "5.12.4" id "com.matthewprenger.cursegradle" version "1.4.0" id "com.modrinth.minotaur" version "1.2.1" id 'io.github.juuxel.loom-quiltflower' version '1.7.1' @@ -452,34 +452,34 @@ publishing { ///////////// // Spotless -spotless { - - java { - target 'src/*/java/appeng/**/*.java' - - endWithNewline() - indentWithSpaces() - removeUnusedImports() - toggleOffOn() - eclipse().configFile 'codeformat/codeformat.xml' - importOrderFile 'codeformat/ae2.importorder' - - // courtesy of diffplug/spotless#240 - // https://github.com/diffplug/spotless/issues/240#issuecomment-385206606 - custom 'noWildcardImports', { - if (it.contains('*;\n')) { - throw new Error('No wildcard imports allowed') - } - } - bumpThisNumberIfACustomStepChanges(1) - } - - format 'json', { - target 'src/*/resources/**/*.json' - targetExclude 'src/generated/resources/**' - prettier().config(['parser': 'json']) - } -} +//spotless { +// +// java { +// target 'src/*/java/appeng/**/*.java' +// +// endWithNewline() +// indentWithSpaces() +// removeUnusedImports() +// toggleOffOn() +// eclipse().configFile 'codeformat/codeformat.xml' +// importOrderFile 'codeformat/ae2.importorder' +// +// // courtesy of diffplug/spotless#240 +// // https://github.com/diffplug/spotless/issues/240#issuecomment-385206606 +// custom 'noWildcardImports', { +// if (it.contains('*;\n')) { +// throw new Error('No wildcard imports allowed') +// } +// } +// bumpThisNumberIfACustomStepChanges(1) +// } +// +// format 'json', { +// target 'src/*/resources/**/*.json' +// targetExclude 'src/generated/resources/**' +// prettier().config(['parser': 'json']) +// } +//} import com.modrinth.minotaur.TaskModrinthUpload diff --git a/src/main/java/appeng/api/behaviors/PickupStrategy.java b/src/main/java/appeng/api/behaviors/PickupStrategy.java deleted file mode 100644 index b76ff5ee790..00000000000 --- a/src/main/java/appeng/api/behaviors/PickupStrategy.java +++ /dev/null @@ -1,69 +0,0 @@ -package appeng.api.behaviors; - -import java.util.Map; - -import org.jetbrains.annotations.ApiStatus; - -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.item.enchantment.Enchantment; -import net.minecraft.world.level.block.entity.BlockEntity; - -import appeng.api.networking.energy.IEnergySource; -import appeng.api.stacks.AEKeyType; -import appeng.parts.automation.StackWorldBehaviors; - -/** - * Pickup strategies are used to pick up various types of game objects from within the world and convert them into a - * subtype of {@link appeng.api.stacks.AEKey}. - *

- * This is used by the annihilation plane to pick up in-world fluids, blocks or item entities. - */ -@ApiStatus.Experimental -public interface PickupStrategy { - /** - * Resets any lock-out caused by throttling of the pickup strategy. It is called at least once per tick by the - * annihilation plane to allow the strategy to reset its lockout timer. - */ - void reset(); - - /** - * Tests if this strategy can pick up the given entity. - */ - boolean canPickUpEntity(Entity entity); - - /** - * Pick up a given entity and place the result into the given pickup sink. Returns true if the entity was picked up - * successfully. The strategy has to handle removal or modification of the entity itself. - */ - boolean pickUpEntity(IEnergySource energySource, PickupSink sink, Entity entity); - - Result tryPickup(IEnergySource energySource, PickupSink sink); - - enum Result { - /** - * There is nothing this strategy can pick up. - */ - CANT_PICKUP, - /** - * There is something the strategy could pick up, but the storage is full. - */ - CANT_STORE, - /** - * The strategy picked something up successfully. - */ - PICKED_UP - } - - @FunctionalInterface - interface Factory { - PickupStrategy create(ServerLevel level, BlockPos fromPos, Direction fromSide, BlockEntity host, - Map enchantments); - } - - static void register(AEKeyType type, Factory factory) { - StackWorldBehaviors.registerPickupStrategy(type, factory); - } -} diff --git a/src/main/java/appeng/api/behaviors/PlacementStrategy.java b/src/main/java/appeng/api/behaviors/PlacementStrategy.java deleted file mode 100644 index ed71f2b0679..00000000000 --- a/src/main/java/appeng/api/behaviors/PlacementStrategy.java +++ /dev/null @@ -1,29 +0,0 @@ -package appeng.api.behaviors; - -import org.jetbrains.annotations.ApiStatus; - -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.world.level.block.entity.BlockEntity; - -import appeng.api.config.Actionable; -import appeng.api.stacks.AEKey; -import appeng.api.stacks.AEKeyType; -import appeng.parts.automation.StackWorldBehaviors; - -@ApiStatus.Experimental -public interface PlacementStrategy { - void clearBlocked(); - - long placeInWorld(AEKey what, long amount, Actionable type, boolean placeAsEntity); - - @FunctionalInterface - interface Factory { - PlacementStrategy create(ServerLevel level, BlockPos fromPos, Direction fromSide, BlockEntity host); - } - - static void register(AEKeyType type, Factory factory) { - StackWorldBehaviors.registerPlacementStrategy(type, factory); - } -} diff --git a/src/main/java/appeng/api/behaviors/StackTransferContext.java b/src/main/java/appeng/api/behaviors/StackTransferContext.java index c12a0d08346..794142092de 100644 --- a/src/main/java/appeng/api/behaviors/StackTransferContext.java +++ b/src/main/java/appeng/api/behaviors/StackTransferContext.java @@ -2,7 +2,6 @@ import org.jetbrains.annotations.ApiStatus; -import appeng.api.networking.energy.IEnergySource; import appeng.api.networking.security.IActionSource; import appeng.api.networking.storage.IStorageService; import appeng.api.stacks.AEItemKey; @@ -19,8 +18,6 @@ public interface StackTransferContext { IStorageService getInternalStorage(); - IEnergySource getEnergySource(); - IActionSource getActionSource(); int getOperationsRemaining(); diff --git a/src/main/java/appeng/api/config/CondenserOutput.java b/src/main/java/appeng/api/config/CondenserOutput.java deleted file mode 100644 index 17eab971f3b..00000000000 --- a/src/main/java/appeng/api/config/CondenserOutput.java +++ /dev/null @@ -1,36 +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.config; - -public enum CondenserOutput { - - TRASH, // 0 - - MATTER_BALLS, // 256 - - SINGULARITY; // 250,000 - - public int requiredPower = 0; - -} diff --git a/src/main/java/appeng/api/config/CpuSelectionMode.java b/src/main/java/appeng/api/config/CpuSelectionMode.java deleted file mode 100644 index 6ccd868d1c5..00000000000 --- a/src/main/java/appeng/api/config/CpuSelectionMode.java +++ /dev/null @@ -1,25 +0,0 @@ -package appeng.api.config; - -import appeng.api.networking.security.IActionSource; - -/** - * Controls for which types of crafting requests a crafting CPU is available to be automatically selected. - */ -public enum CpuSelectionMode { - /** - * Use for all types of auto-crafting requests. - */ - ANY, - /** - * Only use for auto-crafting initiated by players. - * - * @see IActionSource#player() - */ - PLAYER_ONLY, - /** - * Only use for auto-crafting initiated by machines. - * - * @see IActionSource#machine() - */ - MACHINE_ONLY -} diff --git a/src/main/java/appeng/api/config/LevelEmitterMode.java b/src/main/java/appeng/api/config/LevelEmitterMode.java deleted file mode 100644 index ab2c407a5f7..00000000000 --- a/src/main/java/appeng/api/config/LevelEmitterMode.java +++ /dev/null @@ -1,32 +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.config; - -public enum LevelEmitterMode { - - STORED_AMOUNT, - - STORABLE_AMOUNT - -} diff --git a/src/main/java/appeng/api/config/NetworkEmitterMode.java b/src/main/java/appeng/api/config/NetworkEmitterMode.java deleted file mode 100644 index c0b1b3a569f..00000000000 --- a/src/main/java/appeng/api/config/NetworkEmitterMode.java +++ /dev/null @@ -1,34 +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.config; - -public enum NetworkEmitterMode { - - POWER_LEVEL, - - BOOTING, - - CHANNEL_ERROR - -} diff --git a/src/main/java/appeng/api/config/PowerMultiplier.java b/src/main/java/appeng/api/config/PowerMultiplier.java deleted file mode 100644 index c615150d38e..00000000000 --- a/src/main/java/appeng/api/config/PowerMultiplier.java +++ /dev/null @@ -1,41 +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.config; - -public enum PowerMultiplier { - ONE, CONFIG; - - /** - * please do not edit this value, it is set when AE loads its config files. - */ - public double multiplier = 1.0; - - public double multiply(double in) { - return in * this.multiplier; - } - - public double divide(double in) { - return in / this.multiplier; - } -} diff --git a/src/main/java/appeng/api/config/PowerUnits.java b/src/main/java/appeng/api/config/PowerUnits.java deleted file mode 100644 index ebbf0e27c0e..00000000000 --- a/src/main/java/appeng/api/config/PowerUnits.java +++ /dev/null @@ -1,75 +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.config; - -import net.minecraft.network.chat.Component; - -public enum PowerUnits { - AE("gui.ae2.units.appliedenergistics", "AE"), // Native Units - AE Energy - TR("gui.ae2.units.tr", "E"); // TR - TechReborn energy - - /** - * unlocalized name for the power unit. - */ - public final String unlocalizedName; - - /** - * unlocalized name for the power unit's symbol used to display values. - */ - public final String symbolName; - /** - * please do not edit this value, it is set when AE loads its config files. - */ - public double conversionRatio = 1.0; - - PowerUnits(String un, String symbolName) { - this.unlocalizedName = un; - this.symbolName = symbolName; - } - - /** - * do power conversion using AE's conversion rates. - * - * Example: PowerUnits.EU.convertTo( PowerUnits.AE, 32 ); - * - * will normally returns 64, as it will convert the EU, to AE with AE's power settings. - * - * @param target target power unit - * @param value value - * - * @return value converted to target units, from this units. - */ - public double convertTo(PowerUnits target, double value) { - return value * this.conversionRatio / target.conversionRatio; - } - - public Component textComponent() { - return Component.translatable(unlocalizedName); - } - - public String getSymbolName() { - return symbolName; - } - -} diff --git a/src/main/java/appeng/api/config/RedstoneMode.java b/src/main/java/appeng/api/config/RedstoneMode.java deleted file mode 100644 index fc05205868f..00000000000 --- a/src/main/java/appeng/api/config/RedstoneMode.java +++ /dev/null @@ -1,28 +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.config; - -public enum RedstoneMode { - IGNORE, LOW_SIGNAL, HIGH_SIGNAL, SIGNAL_PULSE -} diff --git a/src/main/java/appeng/api/config/Settings.java b/src/main/java/appeng/api/config/Settings.java index a6700336a43..16b6843aa85 100644 --- a/src/main/java/appeng/api/config/Settings.java +++ b/src/main/java/appeng/api/config/Settings.java @@ -50,20 +50,11 @@ private synchronized static > Setting register(String name, return setting; } - public static final Setting LEVEL_EMITTER_MODE = register("level_emitter_mode", - LevelEmitterMode.class); - public static final Setting REDSTONE_EMITTER = register("redstone_emitter", RedstoneMode.HIGH_SIGNAL, - RedstoneMode.LOW_SIGNAL); - public static final Setting REDSTONE_CONTROLLED = register("redstone_controlled", RedstoneMode.class); - public static final Setting CONDENSER_OUTPUT = register("condenser_output", CondenserOutput.class); - public static final Setting POWER_UNITS = register("power_units", PowerUnits.class); public static final Setting ACCESS = register("access", AccessRestriction.READ_WRITE, AccessRestriction.READ, AccessRestriction.WRITE); public static final Setting SORT_DIRECTION = register("sort_direction", SortDir.class); public static final Setting SORT_BY = register("sort_by", SortOrder.class); public static final Setting SEARCH_TOOLTIPS = register("search_tooltips", YesNo.YES, YesNo.NO); - public static final Setting VIEW_MODE = register("view_mode", ViewItems.class); - public static final Setting TYPE_FILTER = register("filter_type", TypeFilter.class); public static final Setting IO_DIRECTION = register("io_direction", RelativeDirection.LEFT, RelativeDirection.RIGHT); public static final Setting BLOCKING_MODE = register("blocking_mode", YesNo.YES, YesNo.NO); @@ -75,20 +66,15 @@ private synchronized static > Setting register(String name, public static final Setting FUZZY_MODE = register("fuzzy_mode", FuzzyMode.class); public static final Setting TERMINAL_STYLE = register("terminal_style", TerminalStyle.SMALL, TerminalStyle.MEDIUM, TerminalStyle.TALL, TerminalStyle.FULL); - public static final Setting TERMINAL_SHOW_PATTERN_PROVIDERS = register( - "show_pattern_providers", ShowPatternProviders.class); public static final Setting COPY_MODE = register("copy_mode", CopyMode.class); public static final Setting PATTERN_ACCESS_TERMINAL = register("pattern_access_terminal", YesNo.YES, YesNo.NO); - public static final Setting CRAFT_VIA_REDSTONE = register("craft_via_redstone", YesNo.YES, YesNo.NO); public static final Setting STORAGE_FILTER = register("storage_filter", StorageFilter.class); public static final Setting PLACE_BLOCK = register("place_block", YesNo.YES, YesNo.NO); public static final Setting SCHEDULING_MODE = register("scheduling_mode", SchedulingMode.class); public static final Setting OVERLAY_MODE = register("overlay_mode", YesNo.YES, YesNo.NO); public static final Setting FILTER_ON_EXTRACT = register("filter_on_extract", YesNo.YES, YesNo.NO); - public static final Setting CPU_SELECTION_MODE = register("crafting_scheduling_mode", - CpuSelectionMode.class); public static Setting getOrThrow(String name) { var setting = SETTINGS.get(name); diff --git a/src/main/java/appeng/api/config/ShowPatternProviders.java b/src/main/java/appeng/api/config/ShowPatternProviders.java deleted file mode 100644 index 7a4833eb0b4..00000000000 --- a/src/main/java/appeng/api/config/ShowPatternProviders.java +++ /dev/null @@ -1,17 +0,0 @@ -package appeng.api.config; - -public enum ShowPatternProviders { - /** - * Show pattern providers that are not hidden in pattern access terminal. - */ - VISIBLE, - /** - * Show pattern providers that are not hidden in pattern access terminal, and that were not full when the terminal - * was opened / the setting was set. - */ - NOT_FULL, - /** - * Show all pattern providers. - */ - ALL -} diff --git a/src/main/java/appeng/api/config/TypeFilter.java b/src/main/java/appeng/api/config/TypeFilter.java deleted file mode 100644 index 188ccd1af04..00000000000 --- a/src/main/java/appeng/api/config/TypeFilter.java +++ /dev/null @@ -1,23 +0,0 @@ -package appeng.api.config; - -import appeng.api.stacks.AEKeyType; -import appeng.api.storage.AEKeyFilter; - -/** - * Configures a type-based filter for terminals and other views. - */ -public enum TypeFilter { - ALL(AEKeyFilter.none()), - ITEMS(AEKeyType.items().filter()), - FLUIDS(AEKeyType.fluids().filter()); - - private final AEKeyFilter filter; - - TypeFilter(AEKeyFilter filter) { - this.filter = filter; - } - - public AEKeyFilter getFilter() { - return filter; - } -} diff --git a/src/main/java/appeng/api/config/ViewItems.java b/src/main/java/appeng/api/config/ViewItems.java deleted file mode 100644 index 160543652d6..00000000000 --- a/src/main/java/appeng/api/config/ViewItems.java +++ /dev/null @@ -1,28 +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.config; - -public enum ViewItems { - ALL, STORED, CRAFTABLE -} diff --git a/src/main/java/appeng/api/crafting/IPatternDetails.java b/src/main/java/appeng/api/crafting/IPatternDetails.java deleted file mode 100644 index 781639f67cf..00000000000 --- a/src/main/java/appeng/api/crafting/IPatternDetails.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2021 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.Nullable; - -import net.minecraft.world.item.crafting.Recipe; -import net.minecraft.world.level.Level; - -import appeng.api.stacks.AEItemKey; -import appeng.api.stacks.AEKey; -import appeng.api.stacks.GenericStack; - -/** - * Information about a pattern for use by the autocrafting system. - *

- * Implementing classes need to properly implement equals/hashCode for crafting jobs to resume properly after - * world or chunk reloads. - */ -public interface IPatternDetails { - /** - * Return the type of the encoded item of this pattern, containing all the data to retrieve the pattern later from - * {@link PatternDetailsHelper#decodePattern}. - */ - AEItemKey getDefinition(); - - /** - * The inputs of this pattern. The return array must never be edited. - */ - IInput[] getInputs(); - - /** - * The primary output of this pattern. The pattern will only be used to craft the primary output; the others are - * just byproducts. - */ - default GenericStack getPrimaryOutput() { - return getOutputs()[0]; - } - - /** - * The outputs of this pattern. The return array or any of its stacks must never be edited. - */ - GenericStack[] getOutputs(); - - interface IInput { - /** - * A list of possible inputs for this pattern: the first input is the primary input, others are just substitutes - * that will be used if available but won't be autocrafted. For example you can return [1000 mb of water fluid, - * 1 bucket of water item] to use water if possible, but use stored buckets otherwise. - *

- * The return array or any of its stacks must never be edited. - */ - GenericStack[] getPossibleInputs(); - - /** - * Multiplier for the inputs: how many possible inputs are necessary to craft this pattern. - */ - long getMultiplier(); - - /** - * Check if the passed stack is a valid input. - */ - boolean isValid(AEKey input, Level level); - - /** - * Optionally return a remaining key. This will generally be null for processing patterns, and return the - * corresponding slot of {@link Recipe#getRemainingItems} for crafting patterns. - */ - @Nullable - AEKey getRemainingKey(AEKey template); - } -} diff --git a/src/main/java/appeng/api/crafting/IPatternDetailsDecoder.java b/src/main/java/appeng/api/crafting/IPatternDetailsDecoder.java deleted file mode 100644 index 0daf6d78d6e..00000000000 --- a/src/main/java/appeng/api/crafting/IPatternDetailsDecoder.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2021 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.Nullable; - -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.Level; - -import appeng.api.stacks.AEItemKey; - -/** - * Allows mod to decode their {@link IPatternDetails} from their item stacks. This is required for custom patterns, - * otherwise the crafting CPU can't properly persist them. Register a single instance to {@link PatternDetailsHelper}. - */ -public interface IPatternDetailsDecoder { - boolean isEncodedPattern(ItemStack stack); - - @Nullable - IPatternDetails decodePattern(AEItemKey what, Level level); - - /** - * Decodes a pattern stored in a stack. Can attempt to recover a pattern hat has broken by recipe IDs being changed - * by other mods. Recovery will modify the given item stack. - */ - @Nullable - IPatternDetails decodePattern(ItemStack what, Level level, boolean tryRecovery); -} diff --git a/src/main/java/appeng/api/crafting/PatternDetailsHelper.java b/src/main/java/appeng/api/crafting/PatternDetailsHelper.java deleted file mode 100644 index 62f61a282e7..00000000000 --- a/src/main/java/appeng/api/crafting/PatternDetailsHelper.java +++ /dev/null @@ -1,164 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2021 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 java.util.List; -import java.util.Objects; -import java.util.concurrent.CopyOnWriteArrayList; - -import javax.annotation.Nullable; - -import com.google.common.base.Preconditions; - -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.crafting.CraftingRecipe; -import net.minecraft.world.item.crafting.StonecutterRecipe; -import net.minecraft.world.item.crafting.UpgradeRecipe; -import net.minecraft.world.level.Level; - -import appeng.api.stacks.AEItemKey; -import appeng.api.stacks.GenericStack; -import appeng.core.definitions.AEItems; -import appeng.crafting.pattern.AEPatternDecoder; - -public final class PatternDetailsHelper { - private static final List DECODERS = new CopyOnWriteArrayList<>(); - - static { - // Register support for our own stacks. - registerDecoder(AEPatternDecoder.INSTANCE); - } - - public static void registerDecoder(IPatternDetailsDecoder decoder) { - Objects.requireNonNull(decoder); - DECODERS.add(decoder); - } - - public static boolean isEncodedPattern(ItemStack stack) { - for (var decoder : DECODERS) { - if (decoder.isEncodedPattern(stack)) { - return true; - } - } - return false; - } - - @Nullable - public static IPatternDetails decodePattern(ItemStack stack, Level level) { - return decodePattern(stack, level, false); - } - - @Nullable - public static IPatternDetails decodePattern(AEItemKey what, Level level) { - for (var decoder : DECODERS) { - var decoded = decoder.decodePattern(what, level); - if (decoded != null) { - return decoded; - } - } - return null; - } - - @Nullable - public static IPatternDetails decodePattern(ItemStack stack, Level level, boolean autoRecovery) { - for (var decoder : DECODERS) { - var decoded = decoder.decodePattern(stack, level, autoRecovery); - if (decoded != null) { - return decoded; - } - } - return null; - } - - /** - * 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 out The first element is considered the primary output and must be present - * @return A new encoded pattern. - * @throws IllegalArgumentException If either in or out contain only empty ItemStacks, or no primary output - */ - public static ItemStack encodeProcessingPattern(GenericStack[] in, GenericStack[] out) { - return AEItems.PROCESSING_PATTERN.asItem().encode(in, out); - } - - /** - * Encodes a crafting pattern which represents a Vanilla crafting recipe. - * - * @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. - * @param allowFluidSubstitutes Controls whether the ME system will allow the use of equivalent fluids. - * @throws IllegalArgumentException If either in or out contain only empty ItemStacks. - */ - public static ItemStack encodeCraftingPattern(CraftingRecipe recipe, ItemStack[] in, - ItemStack out, boolean allowSubstitutes, boolean allowFluidSubstitutes) { - return AEItems.CRAFTING_PATTERN.asItem().encode(recipe, in, out, allowSubstitutes, allowFluidSubstitutes); - } - - /** - * Encodes a stonecutting pattern which represents a Vanilla Stonecutter recipe. - * - * @param recipe The Vanilla stonecutter recipe to be encoded. - * @param in The input item for the stonecutter, which is used to determine which item is supplied - * from the ME system to craft using this pattern. - * @param out The selected output item from the stonecutter recipe. Used to restore the recipe if it is - * renamed later. - * @param allowSubstitutes Controls whether the ME system will allow the use of equivalent items to craft this - * recipe. - */ - public static ItemStack encodeStonecuttingPattern(StonecutterRecipe recipe, AEItemKey in, AEItemKey out, - boolean allowSubstitutes) { - Preconditions.checkNotNull(recipe, "recipe"); - Preconditions.checkNotNull(in, "in"); - Preconditions.checkNotNull(out, "out"); - return AEItems.STONECUTTING_PATTERN.asItem().encode(recipe, in, out, allowSubstitutes); - } - - /** - * Encodes a smithing table pattern which represents a Vanilla Smithing Table recipe. - * - * @param recipe The Vanilla smithing table recipe to be encoded. - * @param base The base item for the smithing table, which is used to determine which item is supplied - * from the ME system to craft using this pattern. - * @param addition The additional item for the smithing table, which is used to determine which item is - * supplied from the ME system to craft using this pattern. - * @param out The selected output item from the smithing table recipe. Used to restore the recipe if it - * is renamed later. - * @param allowSubstitutes Controls whether the ME system will allow the use of equivalent items to craft this - * recipe. - */ - public static ItemStack encodeSmithingTablePattern(UpgradeRecipe recipe, AEItemKey base, AEItemKey addition, - AEItemKey out, - boolean allowSubstitutes) { - Preconditions.checkNotNull(recipe, "recipe"); - Preconditions.checkNotNull(base, "base"); - Preconditions.checkNotNull(addition, "addition"); - Preconditions.checkNotNull(out, "out"); - return AEItems.SMITHING_TABLE_PATTERN.asItem().encode(recipe, base, addition, out, allowSubstitutes); - } -} diff --git a/src/main/java/appeng/api/features/P2PTunnelAttunement.java b/src/main/java/appeng/api/features/P2PTunnelAttunement.java deleted file mode 100644 index 07817c8af13..00000000000 --- a/src/main/java/appeng/api/features/P2PTunnelAttunement.java +++ /dev/null @@ -1,200 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2021 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.features; - -import java.util.ArrayList; -import java.util.IdentityHashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.function.Function; - -import javax.annotation.concurrent.ThreadSafe; - -import net.fabricmc.fabric.api.lookup.v1.item.ItemApiLookup; -import net.fabricmc.fabric.api.transfer.v1.context.ContainerItemContext; -import net.fabricmc.fabric.api.transfer.v1.item.base.SingleStackStorage; -import net.minecraft.core.Registry; -import net.minecraft.network.chat.Component; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.tags.TagKey; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.ItemLike; - -import appeng.core.definitions.AEParts; -import appeng.items.parts.PartItem; -import appeng.parts.p2p.P2PTunnelPart; - -/** - * A Registry for how p2p Tunnels are attuned - */ -@ThreadSafe -public final class P2PTunnelAttunement { - private static final int INITIAL_CAPACITY = 40; - - static final Map, Item> tagTunnels = new IdentityHashMap<>(INITIAL_CAPACITY); - static final List> apiAttunements = new ArrayList<>(INITIAL_CAPACITY); - - /** - * The default tunnel part for ME tunnels. Use this to register additional attunement options. - */ - public static final ItemLike ME_TUNNEL = AEParts.ME_P2P_TUNNEL; - - /** - * The default tunnel part for energy (i.e. Forge Energy) tunnels. Use this to register additional attunement - * options. - */ - public static final ItemLike ENERGY_TUNNEL = AEParts.FE_P2P_TUNNEL; - - /** - * The default tunnel part for redstone tunnels. Use this to register additional attunement options. - */ - public static final ItemLike REDSTONE_TUNNEL = AEParts.REDSTONE_P2P_TUNNEL; - - /** - * The default tunnel part for fluid tunnels. Use this to register additional attunement options. - */ - public static final ItemLike FLUID_TUNNEL = AEParts.FLUID_P2P_TUNNEL; - - /** - * The default tunnel part for item tunnels. Use this to register additional attunement options. - */ - public static final ItemLike ITEM_TUNNEL = AEParts.ITEM_P2P_TUNNEL; - - /** - * The default tunnel part for light tunnels. Use this to register additional attunement options. - */ - public static final ItemLike LIGHT_TUNNEL = AEParts.LIGHT_P2P_TUNNEL; - - private P2PTunnelAttunement() { - } - - public static TagKey getAttunementTag(ItemLike tunnel) { - Objects.requireNonNull(tunnel.asItem(), "tunnel.asItem()"); - var itemKey = Registry.ITEM.getKey(tunnel.asItem()); - if (itemKey.equals(Registry.ITEM.getDefaultKey())) { - throw new IllegalArgumentException("Tunnel item must be registered first."); - } - return TagKey.create(Registry.ITEM_REGISTRY, - new ResourceLocation(itemKey.getNamespace(), "p2p_attunements/" + itemKey.getPath())); - } - - /** - * Attunement based on the standard item tag: {@code :p2p_attunements/} - */ - public synchronized static void registerAttunementTag(ItemLike tunnel) { - Objects.requireNonNull(tunnel.asItem(), "tunnel.asItem()"); - tagTunnels.put(getAttunementTag(tunnel), validateTunnelPartItem(tunnel)); - } - - /** - * Attunement based on the ability of getting an API via Fabric API Lookup from the item. - * - * @param tunnelPart The P2P-tunnel part item. - * @param description Description for display in REI/JEI. - */ - public synchronized static void registerAttunementApi(ItemLike tunnelPart, ItemApiLookup api, - Function contextProvider, Component description) { - Objects.requireNonNull(api, "api"); - Objects.requireNonNull(contextProvider, "contextProvider"); - apiAttunements.add(new ApiAttunement<>(api, contextProvider, validateTunnelPartItem(tunnelPart), description)); - } - - /** - * Attunement based on the ability of getting a storage container API via Fabric API Lookup from the item. - * - * @param tunnelPart The P2P-tunnel part item. - * @param description Description for display in REI/JEI. - */ - public synchronized static void registerAttunementApi(ItemLike tunnelPart, - ItemApiLookup api, Component description) { - registerAttunementApi(tunnelPart, api, stack -> ContainerItemContext.ofSingleSlot(new SingleStackStorage() { - ItemStack buffer = stack; - - @Override - protected ItemStack getStack() { - return buffer; - } - - @Override - protected void setStack(ItemStack stack) { - buffer = stack; - } - }), description); - } - - /** - * @param trigger attunement trigger - * @return The part item for a P2P-Tunnel that should handle the given attunement, or an empty item stack. - */ - public synchronized static ItemStack getTunnelPartByTriggerItem(ItemStack trigger) { - if (trigger.isEmpty()) { - return ItemStack.EMPTY; - } - - // Tags first - for (var tag : trigger.getTags().toList()) { - var tagTunnelItem = tagTunnels.get(tag); - if (tagTunnelItem != null) { - return new ItemStack(tagTunnelItem); - } - } - - // Check provided APIs - for (var apiAttunement : apiAttunements) { - if (apiAttunement.hasApi(trigger)) { - return new ItemStack(apiAttunement.tunnelType()); - } - } - - return ItemStack.EMPTY; - } - - private static Item validateTunnelPartItem(ItemLike itemLike) { - Objects.requireNonNull(itemLike, "item"); - var item = itemLike.asItem(); - Objects.requireNonNull(item, "item"); - if (!(item instanceof PartItempartItem)) { - throw new IllegalArgumentException("Given tunnel part item is not a part"); - } - - if (!P2PTunnelPart.class.isAssignableFrom((partItem.getPartClass()))) { - throw new IllegalArgumentException("Given tunnel part item results in a part that is not a P2P tunnel: " - + partItem); - } - - return item; - } - - record ApiAttunement ( - ItemApiLookup api, - Function contextProvider, - Item tunnelType, - Component component) { - public boolean hasApi(ItemStack stack) { - return api.find(stack, contextProvider.apply(stack)) != null; - } - } -} diff --git a/src/main/java/appeng/api/features/P2PTunnelAttunementInternal.java b/src/main/java/appeng/api/features/P2PTunnelAttunementInternal.java deleted file mode 100644 index 86b3d73fac3..00000000000 --- a/src/main/java/appeng/api/features/P2PTunnelAttunementInternal.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * This file is part of Applied Energistics 2. - * Copyright (c) 2021, 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.api.features; - -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.function.Predicate; - -import net.fabricmc.fabric.api.lookup.v1.item.ItemApiLookup; -import net.minecraft.network.chat.Component; -import net.minecraft.tags.TagKey; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.ItemLike; - -/** - * Internal methods that complement {@link P2PTunnelAttunement} and which are not part of the public API. - */ -public final class P2PTunnelAttunementInternal { - - private P2PTunnelAttunementInternal() { - } - - /** - * Gets a report which sources of attunement exist for a given tunnel type. - */ - public static AttunementInfo getAttunementInfo(ItemLike tunnelType) { - var tunnelItem = tunnelType.asItem(); - - Set> apis = new HashSet<>(); - - for (var entry : P2PTunnelAttunement.apiAttunements) { - if (entry.tunnelType() == tunnelItem) { - apis.add(entry.api()); - } - } - - return new AttunementInfo(apis); - } - - public static List getApiTunnels() { - return P2PTunnelAttunement.apiAttunements.stream() - .map(info -> new Resultant(info.component(), info.tunnelType(), info::hasApi)).toList(); - } - - public static Map, Item> getTagTunnels() { - return P2PTunnelAttunement.tagTunnels; - } - - public record AttunementInfo(Set> apis) { - } - - public record Resultant(Component description, Item tunnelType, Predicate stackPredicate) { - } -} diff --git a/src/main/java/appeng/api/features/PlayerRegistryInternal.java b/src/main/java/appeng/api/features/PlayerRegistryInternal.java index 864cd59b95e..f082c868999 100644 --- a/src/main/java/appeng/api/features/PlayerRegistryInternal.java +++ b/src/main/java/appeng/api/features/PlayerRegistryInternal.java @@ -30,10 +30,10 @@ import net.minecraft.nbt.CompoundTag; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.saveddata.SavedData; import appeng.core.AELog; import appeng.core.AppEng; -import appeng.core.worlddata.AESavedData; /** * Handles the matching between UUIDs and internal IDs for security systems. This whole system could be replaced by @@ -43,7 +43,7 @@ * @version rv3 - 30.05.2015 * @since rv3 30.05.2015 */ -final class PlayerRegistryInternal extends AESavedData implements IPlayerRegistry { +final class PlayerRegistryInternal extends SavedData implements IPlayerRegistry { private static final String NAME = AppEng.MOD_ID + "_players"; private static final String TAG_PLAYER_IDS = "playerIds"; diff --git a/src/main/java/appeng/api/ids/AEBlockIds.java b/src/main/java/appeng/api/ids/AEBlockIds.java index 1d6262a7aa9..7fcfe9001bb 100644 --- a/src/main/java/appeng/api/ids/AEBlockIds.java +++ b/src/main/java/appeng/api/ids/AEBlockIds.java @@ -31,141 +31,11 @@ */ @SuppressWarnings("unused") public final class AEBlockIds { - - /// - /// WORLDGEN/MISC - /// - // Budding certus quartz - public static final ResourceLocation FLAWLESS_BUDDING_QUARTZ = id("flawless_budding_quartz"); - public static final ResourceLocation FLAWED_BUDDING_QUARTZ = id("flawed_budding_quartz"); - public static final ResourceLocation CHIPPED_BUDDING_QUARTZ = id("chipped_budding_quartz"); - public static final ResourceLocation DAMAGED_BUDDING_QUARTZ = id("damaged_budding_quartz"); - // Certus quartz clusters - public static final ResourceLocation SMALL_QUARTZ_BUD = id("small_quartz_bud"); - public static final ResourceLocation MEDIUM_QUARTZ_BUD = id("medium_quartz_bud"); - public static final ResourceLocation LARGE_QUARTZ_BUD = id("large_quartz_bud"); - public static final ResourceLocation QUARTZ_CLUSTER = id("quartz_cluster"); - - public static final ResourceLocation MYSTERIOUS_CUBE = id("mysterious_cube"); - public static final ResourceLocation NOT_SO_MYSTERIOUS_CUBE = id("not_so_mysterious_cube"); - public static final ResourceLocation QUARTZ_FIXTURE = id("quartz_fixture"); - public static final ResourceLocation SKY_STONE_CHEST = id("sky_stone_chest"); - public static final ResourceLocation SMOOTH_SKY_STONE_CHEST = id("smooth_sky_stone_chest"); - public static final ResourceLocation SKY_STONE_TANK = id("sky_stone_tank"); - public static final ResourceLocation LIGHT_DETECTOR = id("light_detector"); - public static final ResourceLocation PAINT = id("paint"); - - /// - /// ME NETWORK - /// - public static final ResourceLocation INSCRIBER = id("inscriber"); public static final ResourceLocation WIRELESS_ACCESS_POINT = id("wireless_access_point"); - public static final ResourceLocation CHARGER = id("charger"); public static final ResourceLocation SECURITY_STATION = id("security_station"); - public static final ResourceLocation QUANTUM_RING = id("quantum_ring"); - public static final ResourceLocation QUANTUM_LINK = id("quantum_link"); public static final ResourceLocation CONTROLLER = id("controller"); - public static final ResourceLocation DRIVE = id("drive"); - public static final ResourceLocation CHEST = id("chest"); - public static final ResourceLocation INTERFACE = id("interface"); - public static final ResourceLocation CELL_WORKBENCH = id("cell_workbench"); - public static final ResourceLocation IO_PORT = id("io_port"); - public static final ResourceLocation CONDENSER = id("condenser"); - public static final ResourceLocation ENERGY_ACCEPTOR = id("energy_acceptor"); - public static final ResourceLocation VIBRATION_CHAMBER = id("vibration_chamber"); - public static final ResourceLocation QUARTZ_GROWTH_ACCELERATOR = id("quartz_growth_accelerator"); - public static final ResourceLocation ENERGY_CELL = id("energy_cell"); - public static final ResourceLocation DENSE_ENERGY_CELL = id("dense_energy_cell"); public static final ResourceLocation CABLE_BUS = id("cable_bus"); - /// - /// SPATIAL - /// - public static final ResourceLocation MATRIX_FRAME = id("matrix_frame"); - public static final ResourceLocation TINY_TNT = id("tiny_tnt"); - public static final ResourceLocation SPATIAL_PYLON = id("spatial_pylon"); - public static final ResourceLocation SPATIAL_IO_PORT = id("spatial_io_port"); - public static final ResourceLocation SPATIAL_ANCHOR = id("spatial_anchor"); - - /// - /// AUTO CRAFTING - /// - public static final ResourceLocation CREATIVE_ENERGY_CELL = id("creative_energy_cell"); - public static final ResourceLocation CRAFTING_UNIT = id("crafting_unit"); - public static final ResourceLocation CRAFTING_ACCELERATOR = id("crafting_accelerator"); - public static final ResourceLocation CRAFTING_STORAGE_1K = id("1k_crafting_storage"); - public static final ResourceLocation CRAFTING_STORAGE_4K = id("4k_crafting_storage"); - public static final ResourceLocation CRAFTING_STORAGE_16K = id("16k_crafting_storage"); - public static final ResourceLocation CRAFTING_STORAGE_64K = id("64k_crafting_storage"); - public static final ResourceLocation CRAFTING_STORAGE_256K = id("256k_crafting_storage"); - public static final ResourceLocation CRAFTING_MONITOR = id("crafting_monitor"); - public static final ResourceLocation PATTERN_PROVIDER = id("pattern_provider"); - public static final ResourceLocation MOLECULAR_ASSEMBLER = id("molecular_assembler"); - - /// - /// DECORATIVE BLOCKS - /// - public static final ResourceLocation QUARTZ_BLOCK = id("quartz_block"); - public static final ResourceLocation CUT_QUARTZ_BLOCK = id("cut_quartz_block"); - public static final ResourceLocation SMOOTH_QUARTZ_BLOCK = id("smooth_quartz_block"); - public static final ResourceLocation QUARTZ_BRICKS = id("quartz_bricks"); - public static final ResourceLocation QUARTZ_PILLAR = id("quartz_pillar"); - public static final ResourceLocation CHISELED_QUARTZ_BLOCK = id("chiseled_quartz_block"); - public static final ResourceLocation FLUIX_BLOCK = id("fluix_block"); - public static final ResourceLocation SKY_STONE_BLOCK = id("sky_stone_block"); - public static final ResourceLocation SMOOTH_SKY_STONE_BLOCK = id("smooth_sky_stone_block"); - public static final ResourceLocation SKY_STONE_BRICK = id("sky_stone_brick"); - public static final ResourceLocation SKY_STONE_SMALL_BRICK = id("sky_stone_small_brick"); - public static final ResourceLocation QUARTZ_GLASS = id("quartz_glass"); - public static final ResourceLocation QUARTZ_VIBRANT_GLASS = id("quartz_vibrant_glass"); - - /// - /// STAIRS - /// - public static final ResourceLocation SKY_STONE_STAIRS = id("sky_stone_stairs"); - public static final ResourceLocation SMOOTH_SKY_STONE_STAIRS = id("smooth_sky_stone_stairs"); - public static final ResourceLocation SKY_STONE_BRICK_STAIRS = id("sky_stone_brick_stairs"); - public static final ResourceLocation SKY_STONE_SMALL_BRICK_STAIRS = id("sky_stone_small_brick_stairs"); - public static final ResourceLocation FLUIX_STAIRS = id("fluix_stairs"); - public static final ResourceLocation QUARTZ_STAIRS = id("quartz_stairs"); - public static final ResourceLocation CUT_QUARTZ_STAIRS = id("cut_quartz_stairs"); - public static final ResourceLocation SMOOTH_QUARTZ_STAIRS = id("smooth_quartz_stairs"); - public static final ResourceLocation QUARTZ_BRICK_STAIRS = id("quartz_brick_stairs"); - public static final ResourceLocation CHISELED_QUARTZ_STAIRS = id("chiseled_quartz_stairs"); - public static final ResourceLocation QUARTZ_PILLAR_STAIRS = id("quartz_pillar_stairs"); - - /// - /// WALLS - /// - public static final ResourceLocation SKY_STONE_WALL = id("sky_stone_wall"); - public static final ResourceLocation SMOOTH_SKY_STONE_WALL = id("smooth_sky_stone_wall"); - public static final ResourceLocation SKY_STONE_BRICK_WALL = id("sky_stone_brick_wall"); - public static final ResourceLocation SKY_STONE_SMALL_BRICK_WALL = id("sky_stone_small_brick_wall"); - public static final ResourceLocation FLUIX_WALL = id("fluix_wall"); - public static final ResourceLocation QUARTZ_WALL = id("quartz_wall"); - public static final ResourceLocation CUT_QUARTZ_WALL = id("cut_quartz_wall"); - public static final ResourceLocation SMOOTH_QUARTZ_WALL = id("smooth_quartz_wall"); - public static final ResourceLocation QUARTZ_BRICK_WALL = id("quartz_brick_wall"); - public static final ResourceLocation CHISELED_QUARTZ_WALL = id("chiseled_quartz_wall"); - public static final ResourceLocation QUARTZ_PILLAR_WALL = id("quartz_pillar_wall"); - - /// - /// SLABS - /// - public static final ResourceLocation SKY_STONE_SLAB = id("sky_stone_slab"); - public static final ResourceLocation SMOOTH_SKY_STONE_SLAB = id("smooth_sky_stone_slab"); - public static final ResourceLocation SKY_STONE_BRICK_SLAB = id("sky_stone_brick_slab"); - public static final ResourceLocation SKY_STONE_SMALL_BRICK_SLAB = id("sky_stone_small_brick_slab"); - public static final ResourceLocation FLUIX_SLAB = id("fluix_slab"); - public static final ResourceLocation QUARTZ_SLAB = id("quartz_slab"); - public static final ResourceLocation CUT_QUARTZ_SLAB = id("cut_quartz_slab"); - public static final ResourceLocation SMOOTH_QUARTZ_SLAB = id("smooth_quartz_slab"); - public static final ResourceLocation QUARTZ_BRICK_SLAB = id("quartz_brick_slab"); - public static final ResourceLocation CHISELED_QUARTZ_SLAB = id("chiseled_quartz_slab"); - public static final ResourceLocation QUARTZ_PILLAR_SLAB = id("quartz_pillar_slab"); - - public static final ResourceLocation CRANK = id("crank"); - private static ResourceLocation id(String id) { return new ResourceLocation(AEConstants.MOD_ID, id); } diff --git a/src/main/java/appeng/api/ids/AEItemIds.java b/src/main/java/appeng/api/ids/AEItemIds.java index e527c8e0a5d..7fe4d81c029 100644 --- a/src/main/java/appeng/api/ids/AEItemIds.java +++ b/src/main/java/appeng/api/ids/AEItemIds.java @@ -36,252 +36,15 @@ */ @SuppressWarnings("unused") public final class AEItemIds { - public static final ResourceLocation NETWORK_TOOL = id("network_tool"); - public static final ResourceLocation VIEW_CELL = id("view_cell"); - public static final ResourceLocation MEMORY_CARD = id("memory_card"); - - public static final ResourceLocation MEMORY_CARD_WHITE = id("memory_card_white"); - public static final ResourceLocation MEMORY_CARD_ORANGE = id("memory_card_orange"); - public static final ResourceLocation MEMORY_CARD_MAGENTA = id("memory_card_magenta"); - public static final ResourceLocation MEMORY_CARD_LIGHT_BLUE = id("memory_card_light_blue"); - public static final ResourceLocation MEMORY_CARD_YELLOW = id("memory_card_yellow"); - public static final ResourceLocation MEMORY_CARD_LIME = id("memory_card_lime"); - public static final ResourceLocation MEMORY_CARD_PINK = id("memory_card_pink"); - public static final ResourceLocation MEMORY_CARD_GRAY = id("memory_card_gray"); - public static final ResourceLocation MEMORY_CARD_LIGHT_GRAY = id("memory_card_light_gray"); - public static final ResourceLocation MEMORY_CARD_CYAN = id("memory_card_cyan"); - public static final ResourceLocation MEMORY_CARD_PURPLE = id("memory_card_purple"); - public static final ResourceLocation MEMORY_CARD_BLUE = id("memory_card_blue"); - public static final ResourceLocation MEMORY_CARD_BROWN = id("memory_card_brown"); - public static final ResourceLocation MEMORY_CARD_GREEN = id("memory_card_green"); - public static final ResourceLocation MEMORY_CARD_RED = id("memory_card_red"); - public static final ResourceLocation MEMORY_CARD_BLACK = id("memory_card_black"); - - public static final Map MEMORY_CARDS = ImmutableMap - .builder().put(AEColor.WHITE, MEMORY_CARD_WHITE) - .put(AEColor.ORANGE, MEMORY_CARD_ORANGE) - .put(AEColor.MAGENTA, MEMORY_CARD_MAGENTA) - .put(AEColor.LIGHT_BLUE, MEMORY_CARD_LIGHT_BLUE) - .put(AEColor.YELLOW, MEMORY_CARD_YELLOW) - .put(AEColor.LIME, MEMORY_CARD_LIME) - .put(AEColor.PINK, MEMORY_CARD_PINK) - .put(AEColor.GRAY, MEMORY_CARD_GRAY) - .put(AEColor.LIGHT_GRAY, MEMORY_CARD_LIGHT_GRAY) - .put(AEColor.CYAN, MEMORY_CARD_CYAN) - .put(AEColor.PURPLE, MEMORY_CARD_PURPLE) - .put(AEColor.BLUE, MEMORY_CARD_BLUE) - .put(AEColor.BROWN, MEMORY_CARD_BROWN) - .put(AEColor.GREEN, MEMORY_CARD_GREEN) - .put(AEColor.RED, MEMORY_CARD_RED) - .put(AEColor.BLACK, MEMORY_CARD_BLACK) - .put(AEColor.TRANSPARENT, MEMORY_CARD) - .build(); - - public static final ResourceLocation BLANK_PATTERN = id("blank_pattern"); - public static final ResourceLocation CRAFTING_PATTERN = id("crafting_pattern"); - public static final ResourceLocation PROCESSING_PATTERN = id("processing_pattern"); - public static final ResourceLocation SMITHING_TABLE_PATTERN = id("smithing_table_pattern"); - public static final ResourceLocation STONECUTTING_PATTERN = id("stonecutting_pattern"); public static final ResourceLocation BIOMETRIC_CARD = id("biometric_card"); - public static final ResourceLocation ENTROPY_MANIPULATOR = id("entropy_manipulator"); - public static final ResourceLocation MATTER_CANNON = id("matter_cannon"); - public static final ResourceLocation CHARGED_STAFF = id("charged_staff"); - public static final ResourceLocation COLOR_APPLICATOR = id("color_applicator"); public static final ResourceLocation WIRELESS_TERMINAL = id("wireless_terminal"); public static final ResourceLocation WIRELESS_CRAFTING_TERMINAL = id("wireless_crafting_terminal"); public static final ResourceLocation WRAPPED_GENERIC_STACK = id("wrapped_generic_stack"); - public static final ResourceLocation FACADE = id("facade"); - - /// - /// STORAGE CELLS - /// - public static final ResourceLocation STORAGE_CELL_1K = id("storage_cell_1k"); - public static final ResourceLocation STORAGE_CELL_4K = id("storage_cell_4k"); - public static final ResourceLocation STORAGE_CELL_16K = id("storage_cell_16k"); - public static final ResourceLocation STORAGE_CELL_64K = id("storage_cell_64k"); - public static final ResourceLocation STORAGE_CELL_256K = id("storage_cell_256k"); - public static final ResourceLocation ITEM_CELL_1K = id("item_storage_cell_1k"); - public static final ResourceLocation ITEM_CELL_4K = id("item_storage_cell_4k"); - public static final ResourceLocation ITEM_CELL_16K = id("item_storage_cell_16k"); - public static final ResourceLocation ITEM_CELL_64K = id("item_storage_cell_64k"); - public static final ResourceLocation ITEM_CELL_256K = id("item_storage_cell_256k"); - public static final ResourceLocation FLUID_CELL_1K = id("fluid_storage_cell_1k"); - public static final ResourceLocation FLUID_CELL_4K = id("fluid_storage_cell_4k"); - public static final ResourceLocation FLUID_CELL_16K = id("fluid_storage_cell_16k"); - public static final ResourceLocation FLUID_CELL_64K = id("fluid_storage_cell_64k"); - public static final ResourceLocation FLUID_CELL_256K = id("fluid_storage_cell_256k"); - public static final ResourceLocation SPATIAL_CELL_2 = id("spatial_storage_cell_2"); - public static final ResourceLocation SPATIAL_CELL_16 = id("spatial_storage_cell_16"); - public static final ResourceLocation SPATIAL_CELL_128 = id("spatial_storage_cell_128"); - public static final ResourceLocation ITEM_CELL_CREATIVE = id("creative_item_cell"); - public static final ResourceLocation FLUID_CELL_CREATIVE = id("creative_fluid_cell"); - public static final ResourceLocation PORTABLE_ITEM_CELL1K = id("portable_item_cell_1k"); - public static final ResourceLocation PORTABLE_ITEM_CELL4K = id("portable_item_cell_4k"); - public static final ResourceLocation PORTABLE_ITEM_CELL16K = id("portable_item_cell_16k"); - public static final ResourceLocation PORTABLE_ITEM_CELL64K = id("portable_item_cell_64k"); - public static final ResourceLocation PORTABLE_ITEM_CELL256K = id("portable_item_cell_256k"); - public static final ResourceLocation PORTABLE_FLUID_CELL1K = id("portable_fluid_cell_1k"); - public static final ResourceLocation PORTABLE_FLUID_CELL4K = id("portable_fluid_cell_4k"); - public static final ResourceLocation PORTABLE_FLUID_CELL16K = id("portable_fluid_cell_16k"); - public static final ResourceLocation PORTABLE_FLUID_CELL64K = id("portable_fluid_cell_64k"); - public static final ResourceLocation PORTABLE_FLUID_CELL256K = id("portable_fluid_cell_256k"); - - /// - /// PAINT BALLS - /// - public static final ResourceLocation COLORED_LUMEN_PAINT_BALL_WHITE = id("white_lumen_paint_ball"); - public static final ResourceLocation COLORED_LUMEN_PAINT_BALL_ORANGE = id("orange_lumen_paint_ball"); - public static final ResourceLocation COLORED_LUMEN_PAINT_BALL_MAGENTA = id("magenta_lumen_paint_ball"); - public static final ResourceLocation COLORED_LUMEN_PAINT_BALL_LIGHT_BLUE = id("light_blue_lumen_paint_ball"); - public static final ResourceLocation COLORED_LUMEN_PAINT_BALL_YELLOW = id("yellow_lumen_paint_ball"); - public static final ResourceLocation COLORED_LUMEN_PAINT_BALL_LIME = id("lime_lumen_paint_ball"); - public static final ResourceLocation COLORED_LUMEN_PAINT_BALL_PINK = id("pink_lumen_paint_ball"); - public static final ResourceLocation COLORED_LUMEN_PAINT_BALL_GRAY = id("gray_lumen_paint_ball"); - public static final ResourceLocation COLORED_LUMEN_PAINT_BALL_LIGHT_GRAY = id("light_gray_lumen_paint_ball"); - public static final ResourceLocation COLORED_LUMEN_PAINT_BALL_CYAN = id("cyan_lumen_paint_ball"); - public static final ResourceLocation COLORED_LUMEN_PAINT_BALL_PURPLE = id("purple_lumen_paint_ball"); - public static final ResourceLocation COLORED_LUMEN_PAINT_BALL_BLUE = id("blue_lumen_paint_ball"); - public static final ResourceLocation COLORED_LUMEN_PAINT_BALL_BROWN = id("brown_lumen_paint_ball"); - public static final ResourceLocation COLORED_LUMEN_PAINT_BALL_GREEN = id("green_lumen_paint_ball"); - public static final ResourceLocation COLORED_LUMEN_PAINT_BALL_RED = id("red_lumen_paint_ball"); - public static final ResourceLocation COLORED_LUMEN_PAINT_BALL_BLACK = id("black_lumen_paint_ball"); - public static final Map COLORED_LUMEN_PAINT_BALL = ImmutableMap - .builder().put(AEColor.WHITE, COLORED_LUMEN_PAINT_BALL_WHITE) - .put(AEColor.ORANGE, COLORED_LUMEN_PAINT_BALL_ORANGE) - .put(AEColor.MAGENTA, COLORED_LUMEN_PAINT_BALL_MAGENTA) - .put(AEColor.LIGHT_BLUE, COLORED_LUMEN_PAINT_BALL_LIGHT_BLUE) - .put(AEColor.YELLOW, COLORED_LUMEN_PAINT_BALL_YELLOW) - .put(AEColor.LIME, COLORED_LUMEN_PAINT_BALL_LIME) - .put(AEColor.PINK, COLORED_LUMEN_PAINT_BALL_PINK) - .put(AEColor.GRAY, COLORED_LUMEN_PAINT_BALL_GRAY) - .put(AEColor.LIGHT_GRAY, COLORED_LUMEN_PAINT_BALL_LIGHT_GRAY) - .put(AEColor.CYAN, COLORED_LUMEN_PAINT_BALL_CYAN) - .put(AEColor.PURPLE, COLORED_LUMEN_PAINT_BALL_PURPLE) - .put(AEColor.BLUE, COLORED_LUMEN_PAINT_BALL_BLUE) - .put(AEColor.BROWN, COLORED_LUMEN_PAINT_BALL_BROWN) - .put(AEColor.GREEN, COLORED_LUMEN_PAINT_BALL_GREEN) - .put(AEColor.RED, COLORED_LUMEN_PAINT_BALL_RED) - .put(AEColor.BLACK, COLORED_LUMEN_PAINT_BALL_BLACK) - .build(); - - public static final ResourceLocation COLORED_PAINT_BALL_WHITE = id("white_paint_ball"); - public static final ResourceLocation COLORED_PAINT_BALL_ORANGE = id("orange_paint_ball"); - public static final ResourceLocation COLORED_PAINT_BALL_MAGENTA = id("magenta_paint_ball"); - public static final ResourceLocation COLORED_PAINT_BALL_LIGHT_BLUE = id("light_blue_paint_ball"); - public static final ResourceLocation COLORED_PAINT_BALL_YELLOW = id("yellow_paint_ball"); - public static final ResourceLocation COLORED_PAINT_BALL_LIME = id("lime_paint_ball"); - public static final ResourceLocation COLORED_PAINT_BALL_PINK = id("pink_paint_ball"); - public static final ResourceLocation COLORED_PAINT_BALL_GRAY = id("gray_paint_ball"); - public static final ResourceLocation COLORED_PAINT_BALL_LIGHT_GRAY = id("light_gray_paint_ball"); - public static final ResourceLocation COLORED_PAINT_BALL_CYAN = id("cyan_paint_ball"); - public static final ResourceLocation COLORED_PAINT_BALL_PURPLE = id("purple_paint_ball"); - public static final ResourceLocation COLORED_PAINT_BALL_BLUE = id("blue_paint_ball"); - public static final ResourceLocation COLORED_PAINT_BALL_BROWN = id("brown_paint_ball"); - public static final ResourceLocation COLORED_PAINT_BALL_GREEN = id("green_paint_ball"); - public static final ResourceLocation COLORED_PAINT_BALL_RED = id("red_paint_ball"); - public static final ResourceLocation COLORED_PAINT_BALL_BLACK = id("black_paint_ball"); - public static final Map COLORED_PAINT_BALL = ImmutableMap - .builder().put(AEColor.WHITE, COLORED_PAINT_BALL_WHITE) - .put(AEColor.ORANGE, COLORED_PAINT_BALL_ORANGE) - .put(AEColor.MAGENTA, COLORED_PAINT_BALL_MAGENTA) - .put(AEColor.LIGHT_BLUE, COLORED_PAINT_BALL_LIGHT_BLUE) - .put(AEColor.YELLOW, COLORED_PAINT_BALL_YELLOW) - .put(AEColor.LIME, COLORED_PAINT_BALL_LIME) - .put(AEColor.PINK, COLORED_PAINT_BALL_PINK) - .put(AEColor.GRAY, COLORED_PAINT_BALL_GRAY) - .put(AEColor.LIGHT_GRAY, COLORED_PAINT_BALL_LIGHT_GRAY) - .put(AEColor.CYAN, COLORED_PAINT_BALL_CYAN) - .put(AEColor.PURPLE, COLORED_PAINT_BALL_PURPLE) - .put(AEColor.BLUE, COLORED_PAINT_BALL_BLUE) - .put(AEColor.BROWN, COLORED_PAINT_BALL_BROWN) - .put(AEColor.GREEN, COLORED_PAINT_BALL_GREEN) - .put(AEColor.RED, COLORED_PAINT_BALL_RED) - .put(AEColor.BLACK, COLORED_PAINT_BALL_BLACK) - .build(); - - /// - /// TOOLS - /// - public static final ResourceLocation CERTUS_QUARTZ_AXE = id("certus_quartz_axe"); - public static final ResourceLocation CERTUS_QUARTZ_HOE = id("certus_quartz_hoe"); - public static final ResourceLocation CERTUS_QUARTZ_SHOVEL = id("certus_quartz_shovel"); - public static final ResourceLocation CERTUS_QUARTZ_PICK = id("certus_quartz_pickaxe"); - public static final ResourceLocation CERTUS_QUARTZ_SWORD = id("certus_quartz_sword"); - public static final ResourceLocation CERTUS_QUARTZ_WRENCH = id("certus_quartz_wrench"); - public static final ResourceLocation CERTUS_QUARTZ_KNIFE = id("certus_quartz_cutting_knife"); - - public static final ResourceLocation NETHER_QUARTZ_AXE = id("nether_quartz_axe"); - public static final ResourceLocation NETHER_QUARTZ_HOE = id("nether_quartz_hoe"); - public static final ResourceLocation NETHER_QUARTZ_SHOVEL = id("nether_quartz_shovel"); - public static final ResourceLocation NETHER_QUARTZ_PICK = id("nether_quartz_pickaxe"); - public static final ResourceLocation NETHER_QUARTZ_SWORD = id("nether_quartz_sword"); public static final ResourceLocation NETHER_QUARTZ_WRENCH = id("nether_quartz_wrench"); - public static final ResourceLocation NETHER_QUARTZ_KNIFE = id("nether_quartz_cutting_knife"); - - public static final ResourceLocation FLUIX_AXE = id("fluix_axe"); - public static final ResourceLocation FLUIX_HOE = id("fluix_hoe"); - public static final ResourceLocation FLUIX_SHOVEL = id("fluix_shovel"); - public static final ResourceLocation FLUIX_PICK = id("fluix_pickaxe"); - public static final ResourceLocation FLUIX_SWORD = id("fluix_sword"); - public static final ResourceLocation METEORITE_COMPASS = id("meteorite_compass"); - - /// - /// The following items were previously part of ApiItems - /// - public static final ResourceLocation CERTUS_QUARTZ_CRYSTAL = id("certus_quartz_crystal"); - public static final ResourceLocation CERTUS_QUARTZ_CRYSTAL_CHARGED = id("charged_certus_quartz_crystal"); - public static final ResourceLocation CERTUS_QUARTZ_DUST = id("certus_quartz_dust"); - public static final ResourceLocation SILICON = id("silicon"); - public static final ResourceLocation MATTER_BALL = id("matter_ball"); - public static final ResourceLocation FLUIX_CRYSTAL = id("fluix_crystal"); - public static final ResourceLocation FLUIX_DUST = id("fluix_dust"); - public static final ResourceLocation FLUIX_PEARL = id("fluix_pearl"); - public static final ResourceLocation PURIFIED_CERTUS_QUARTZ_CRYSTAL = id("purified_certus_quartz_crystal"); - public static final ResourceLocation PURIFIED_NETHER_QUARTZ_CRYSTAL = id("purified_nether_quartz_crystal"); - public static final ResourceLocation PURIFIED_FLUIX_CRYSTAL = id("purified_fluix_crystal"); - public static final ResourceLocation CALCULATION_PROCESSOR_PRESS = id("calculation_processor_press"); - public static final ResourceLocation ENGINEERING_PROCESSOR_PRESS = id("engineering_processor_press"); - public static final ResourceLocation LOGIC_PROCESSOR_PRESS = id("logic_processor_press"); - public static final ResourceLocation CALCULATION_PROCESSOR_PRINT = id("printed_calculation_processor"); - public static final ResourceLocation ENGINEERING_PROCESSOR_PRINT = id("printed_engineering_processor"); - public static final ResourceLocation LOGIC_PROCESSOR_PRINT = id("printed_logic_processor"); - public static final ResourceLocation SILICON_PRESS = id("silicon_press"); - public static final ResourceLocation SILICON_PRINT = id("printed_silicon"); - public static final ResourceLocation NAME_PRESS = id("name_press"); - public static final ResourceLocation LOGIC_PROCESSOR = id("logic_processor"); - public static final ResourceLocation CALCULATION_PROCESSOR = id("calculation_processor"); - public static final ResourceLocation ENGINEERING_PROCESSOR = id("engineering_processor"); - public static final ResourceLocation BASIC_CARD = id("basic_card"); - public static final ResourceLocation REDSTONE_CARD = id("redstone_card"); + public static final ResourceLocation INVERTER_CARD = id("inverter_card"); public static final ResourceLocation CAPACITY_CARD = id("capacity_card"); - public static final ResourceLocation VOID_CARD = id("void_card"); - public static final ResourceLocation ADVANCED_CARD = id("advanced_card"); public static final ResourceLocation FUZZY_CARD = id("fuzzy_card"); - public static final ResourceLocation SPEED_CARD = id("speed_card"); - public static final ResourceLocation INVERTER_CARD = id("inverter_card"); - public static final ResourceLocation CRAFTING_CARD = id("crafting_card"); - public static final ResourceLocation ENERGY_CARD = id("energy_card"); - public static final ResourceLocation EQUAL_DISTRIBUTION_CARD = id("equal_distribution_card"); - public static final ResourceLocation SPATIAL_2_CELL_COMPONENT = id("spatial_cell_component_2"); - public static final ResourceLocation SPATIAL_16_CELL_COMPONENT = id("spatial_cell_component_16"); - public static final ResourceLocation SPATIAL_128_CELL_COMPONENT = id("spatial_cell_component_128"); - public static final ResourceLocation CELL_COMPONENT_1K = id("cell_component_1k"); - public static final ResourceLocation CELL_COMPONENT_4K = id("cell_component_4k"); - public static final ResourceLocation CELL_COMPONENT_16K = id("cell_component_16k"); - public static final ResourceLocation CELL_COMPONENT_64K = id("cell_component_64k"); - public static final ResourceLocation CELL_COMPONENT_256K = id("cell_component_256k"); - public static final ResourceLocation ITEM_CELL_HOUSING = id("item_cell_housing"); - public static final ResourceLocation FLUID_CELL_HOUSING = id("fluid_cell_housing"); - public static final ResourceLocation WIRELESS_RECEIVER = id("wireless_receiver"); - public static final ResourceLocation WIRELESS_BOOSTER = id("wireless_booster"); - public static final ResourceLocation FORMATION_CORE = id("formation_core"); - public static final ResourceLocation ANNIHILATION_CORE = id("annihilation_core"); - public static final ResourceLocation SKY_DUST = id("sky_dust"); - public static final ResourceLocation GUIDE = id("guide"); - public static final ResourceLocation ENDER_DUST = id("ender_dust"); - public static final ResourceLocation SINGULARITY = id("singularity"); - public static final ResourceLocation QUANTUM_ENTANGLED_SINGULARITY = id("quantum_entangled_singularity"); private static ResourceLocation id(String id) { return new ResourceLocation(AEConstants.MOD_ID, id); diff --git a/src/main/java/appeng/api/ids/AEPartIds.java b/src/main/java/appeng/api/ids/AEPartIds.java index a59ac6f5bd9..3b84d88052d 100644 --- a/src/main/java/appeng/api/ids/AEPartIds.java +++ b/src/main/java/appeng/api/ids/AEPartIds.java @@ -77,199 +77,9 @@ public final class AEPartIds { .put(AEColor.BLACK, CABLE_GLASS_BLACK) .put(AEColor.TRANSPARENT, CABLE_GLASS_TRANSPARENT) .build(); - - public static final ResourceLocation CABLE_COVERED_WHITE = id("white_covered_cable"); - public static final ResourceLocation CABLE_COVERED_ORANGE = id("orange_covered_cable"); - public static final ResourceLocation CABLE_COVERED_MAGENTA = id("magenta_covered_cable"); - public static final ResourceLocation CABLE_COVERED_LIGHT_BLUE = id("light_blue_covered_cable"); - public static final ResourceLocation CABLE_COVERED_YELLOW = id("yellow_covered_cable"); - public static final ResourceLocation CABLE_COVERED_LIME = id("lime_covered_cable"); - public static final ResourceLocation CABLE_COVERED_PINK = id("pink_covered_cable"); - public static final ResourceLocation CABLE_COVERED_GRAY = id("gray_covered_cable"); - public static final ResourceLocation CABLE_COVERED_LIGHT_GRAY = id("light_gray_covered_cable"); - public static final ResourceLocation CABLE_COVERED_CYAN = id("cyan_covered_cable"); - public static final ResourceLocation CABLE_COVERED_PURPLE = id("purple_covered_cable"); - public static final ResourceLocation CABLE_COVERED_BLUE = id("blue_covered_cable"); - public static final ResourceLocation CABLE_COVERED_BROWN = id("brown_covered_cable"); - public static final ResourceLocation CABLE_COVERED_GREEN = id("green_covered_cable"); - public static final ResourceLocation CABLE_COVERED_RED = id("red_covered_cable"); - public static final ResourceLocation CABLE_COVERED_BLACK = id("black_covered_cable"); - public static final ResourceLocation CABLE_COVERED_TRANSPARENT = id("fluix_covered_cable"); - public static final Map CABLE_COVERED = ImmutableMap.builder() - .put(AEColor.WHITE, CABLE_COVERED_WHITE) - .put(AEColor.ORANGE, CABLE_COVERED_ORANGE) - .put(AEColor.MAGENTA, CABLE_COVERED_MAGENTA) - .put(AEColor.LIGHT_BLUE, CABLE_COVERED_LIGHT_BLUE) - .put(AEColor.YELLOW, CABLE_COVERED_YELLOW) - .put(AEColor.LIME, CABLE_COVERED_LIME) - .put(AEColor.PINK, CABLE_COVERED_PINK) - .put(AEColor.GRAY, CABLE_COVERED_GRAY) - .put(AEColor.LIGHT_GRAY, CABLE_COVERED_LIGHT_GRAY) - .put(AEColor.CYAN, CABLE_COVERED_CYAN) - .put(AEColor.PURPLE, CABLE_COVERED_PURPLE) - .put(AEColor.BLUE, CABLE_COVERED_BLUE) - .put(AEColor.BROWN, CABLE_COVERED_BROWN) - .put(AEColor.GREEN, CABLE_COVERED_GREEN) - .put(AEColor.RED, CABLE_COVERED_RED) - .put(AEColor.BLACK, CABLE_COVERED_BLACK) - .put(AEColor.TRANSPARENT, CABLE_COVERED_TRANSPARENT) - .build(); - - public static final ResourceLocation CABLE_SMART_WHITE = id("white_smart_cable"); - public static final ResourceLocation CABLE_SMART_ORANGE = id("orange_smart_cable"); - public static final ResourceLocation CABLE_SMART_MAGENTA = id("magenta_smart_cable"); - public static final ResourceLocation CABLE_SMART_LIGHT_BLUE = id("light_blue_smart_cable"); - public static final ResourceLocation CABLE_SMART_YELLOW = id("yellow_smart_cable"); - public static final ResourceLocation CABLE_SMART_LIME = id("lime_smart_cable"); - public static final ResourceLocation CABLE_SMART_PINK = id("pink_smart_cable"); - public static final ResourceLocation CABLE_SMART_GRAY = id("gray_smart_cable"); - public static final ResourceLocation CABLE_SMART_LIGHT_GRAY = id("light_gray_smart_cable"); - public static final ResourceLocation CABLE_SMART_CYAN = id("cyan_smart_cable"); - public static final ResourceLocation CABLE_SMART_PURPLE = id("purple_smart_cable"); - public static final ResourceLocation CABLE_SMART_BLUE = id("blue_smart_cable"); - public static final ResourceLocation CABLE_SMART_BROWN = id("brown_smart_cable"); - public static final ResourceLocation CABLE_SMART_GREEN = id("green_smart_cable"); - public static final ResourceLocation CABLE_SMART_RED = id("red_smart_cable"); - public static final ResourceLocation CABLE_SMART_BLACK = id("black_smart_cable"); - public static final ResourceLocation CABLE_SMART_TRANSPARENT = id("fluix_smart_cable"); - public static final Map CABLE_SMART = ImmutableMap.builder() - .put(AEColor.WHITE, CABLE_SMART_WHITE) - .put(AEColor.ORANGE, CABLE_SMART_ORANGE) - .put(AEColor.MAGENTA, CABLE_SMART_MAGENTA) - .put(AEColor.LIGHT_BLUE, CABLE_SMART_LIGHT_BLUE) - .put(AEColor.YELLOW, CABLE_SMART_YELLOW) - .put(AEColor.LIME, CABLE_SMART_LIME) - .put(AEColor.PINK, CABLE_SMART_PINK) - .put(AEColor.GRAY, CABLE_SMART_GRAY) - .put(AEColor.LIGHT_GRAY, CABLE_SMART_LIGHT_GRAY) - .put(AEColor.CYAN, CABLE_SMART_CYAN) - .put(AEColor.PURPLE, CABLE_SMART_PURPLE) - .put(AEColor.BLUE, CABLE_SMART_BLUE) - .put(AEColor.BROWN, CABLE_SMART_BROWN) - .put(AEColor.GREEN, CABLE_SMART_GREEN) - .put(AEColor.RED, CABLE_SMART_RED) - .put(AEColor.BLACK, CABLE_SMART_BLACK) - .put(AEColor.TRANSPARENT, CABLE_SMART_TRANSPARENT) - .build(); - - public static final ResourceLocation CABLE_DENSE_COVERED_WHITE = id("white_covered_dense_cable"); - public static final ResourceLocation CABLE_DENSE_COVERED_ORANGE = id("orange_covered_dense_cable"); - public static final ResourceLocation CABLE_DENSE_COVERED_MAGENTA = id("magenta_covered_dense_cable"); - public static final ResourceLocation CABLE_DENSE_COVERED_LIGHT_BLUE = id("light_blue_covered_dense_cable"); - public static final ResourceLocation CABLE_DENSE_COVERED_YELLOW = id("yellow_covered_dense_cable"); - public static final ResourceLocation CABLE_DENSE_COVERED_LIME = id("lime_covered_dense_cable"); - public static final ResourceLocation CABLE_DENSE_COVERED_PINK = id("pink_covered_dense_cable"); - public static final ResourceLocation CABLE_DENSE_COVERED_GRAY = id("gray_covered_dense_cable"); - public static final ResourceLocation CABLE_DENSE_COVERED_LIGHT_GRAY = id("light_gray_covered_dense_cable"); - public static final ResourceLocation CABLE_DENSE_COVERED_CYAN = id("cyan_covered_dense_cable"); - public static final ResourceLocation CABLE_DENSE_COVERED_PURPLE = id("purple_covered_dense_cable"); - public static final ResourceLocation CABLE_DENSE_COVERED_BLUE = id("blue_covered_dense_cable"); - public static final ResourceLocation CABLE_DENSE_COVERED_BROWN = id("brown_covered_dense_cable"); - public static final ResourceLocation CABLE_DENSE_COVERED_GREEN = id("green_covered_dense_cable"); - public static final ResourceLocation CABLE_DENSE_COVERED_RED = id("red_covered_dense_cable"); - public static final ResourceLocation CABLE_DENSE_COVERED_BLACK = id("black_covered_dense_cable"); - public static final ResourceLocation CABLE_DENSE_COVERED_TRANSPARENT = id("fluix_covered_dense_cable"); - public static final Map CABLE_DENSE_COVERED = ImmutableMap - .builder().put(AEColor.WHITE, CABLE_DENSE_COVERED_WHITE) - .put(AEColor.ORANGE, CABLE_DENSE_COVERED_ORANGE) - .put(AEColor.MAGENTA, CABLE_DENSE_COVERED_MAGENTA) - .put(AEColor.LIGHT_BLUE, CABLE_DENSE_COVERED_LIGHT_BLUE) - .put(AEColor.YELLOW, CABLE_DENSE_COVERED_YELLOW) - .put(AEColor.LIME, CABLE_DENSE_COVERED_LIME) - .put(AEColor.PINK, CABLE_DENSE_COVERED_PINK) - .put(AEColor.GRAY, CABLE_DENSE_COVERED_GRAY) - .put(AEColor.LIGHT_GRAY, CABLE_DENSE_COVERED_LIGHT_GRAY) - .put(AEColor.CYAN, CABLE_DENSE_COVERED_CYAN) - .put(AEColor.PURPLE, CABLE_DENSE_COVERED_PURPLE) - .put(AEColor.BLUE, CABLE_DENSE_COVERED_BLUE) - .put(AEColor.BROWN, CABLE_DENSE_COVERED_BROWN) - .put(AEColor.GREEN, CABLE_DENSE_COVERED_GREEN) - .put(AEColor.RED, CABLE_DENSE_COVERED_RED) - .put(AEColor.BLACK, CABLE_DENSE_COVERED_BLACK) - .put(AEColor.TRANSPARENT, CABLE_DENSE_COVERED_TRANSPARENT) - .build(); - - public static final ResourceLocation CABLE_DENSE_SMART_WHITE = id("white_smart_dense_cable"); - public static final ResourceLocation CABLE_DENSE_SMART_ORANGE = id("orange_smart_dense_cable"); - public static final ResourceLocation CABLE_DENSE_SMART_MAGENTA = id("magenta_smart_dense_cable"); - public static final ResourceLocation CABLE_DENSE_SMART_LIGHT_BLUE = id("light_blue_smart_dense_cable"); - public static final ResourceLocation CABLE_DENSE_SMART_YELLOW = id("yellow_smart_dense_cable"); - public static final ResourceLocation CABLE_DENSE_SMART_LIME = id("lime_smart_dense_cable"); - public static final ResourceLocation CABLE_DENSE_SMART_PINK = id("pink_smart_dense_cable"); - public static final ResourceLocation CABLE_DENSE_SMART_GRAY = id("gray_smart_dense_cable"); - public static final ResourceLocation CABLE_DENSE_SMART_LIGHT_GRAY = id("light_gray_smart_dense_cable"); - public static final ResourceLocation CABLE_DENSE_SMART_CYAN = id("cyan_smart_dense_cable"); - public static final ResourceLocation CABLE_DENSE_SMART_PURPLE = id("purple_smart_dense_cable"); - public static final ResourceLocation CABLE_DENSE_SMART_BLUE = id("blue_smart_dense_cable"); - public static final ResourceLocation CABLE_DENSE_SMART_BROWN = id("brown_smart_dense_cable"); - public static final ResourceLocation CABLE_DENSE_SMART_GREEN = id("green_smart_dense_cable"); - public static final ResourceLocation CABLE_DENSE_SMART_RED = id("red_smart_dense_cable"); - public static final ResourceLocation CABLE_DENSE_SMART_BLACK = id("black_smart_dense_cable"); - public static final ResourceLocation CABLE_DENSE_SMART_TRANSPARENT = id("fluix_smart_dense_cable"); - public static final Map CABLE_DENSE_SMART = ImmutableMap - .builder().put(AEColor.WHITE, CABLE_DENSE_SMART_WHITE) - .put(AEColor.ORANGE, CABLE_DENSE_SMART_ORANGE) - .put(AEColor.MAGENTA, CABLE_DENSE_SMART_MAGENTA) - .put(AEColor.LIGHT_BLUE, CABLE_DENSE_SMART_LIGHT_BLUE) - .put(AEColor.YELLOW, CABLE_DENSE_SMART_YELLOW) - .put(AEColor.LIME, CABLE_DENSE_SMART_LIME) - .put(AEColor.PINK, CABLE_DENSE_SMART_PINK) - .put(AEColor.GRAY, CABLE_DENSE_SMART_GRAY) - .put(AEColor.LIGHT_GRAY, CABLE_DENSE_SMART_LIGHT_GRAY) - .put(AEColor.CYAN, CABLE_DENSE_SMART_CYAN) - .put(AEColor.PURPLE, CABLE_DENSE_SMART_PURPLE) - .put(AEColor.BLUE, CABLE_DENSE_SMART_BLUE) - .put(AEColor.BROWN, CABLE_DENSE_SMART_BROWN) - .put(AEColor.GREEN, CABLE_DENSE_SMART_GREEN) - .put(AEColor.RED, CABLE_DENSE_SMART_RED) - .put(AEColor.BLACK, CABLE_DENSE_SMART_BLACK) - .put(AEColor.TRANSPARENT, CABLE_DENSE_SMART_TRANSPARENT) - .build(); - - /// - /// Buses - /// - public static final ResourceLocation QUARTZ_FIBER = id("quartz_fiber"); - public static final ResourceLocation TOGGLE_BUS = id("toggle_bus"); - public static final ResourceLocation INVERTED_TOGGLE_BUS = id("inverted_toggle_bus"); - public static final ResourceLocation CABLE_ANCHOR = id("cable_anchor"); public static final ResourceLocation STORAGE_BUS = id("storage_bus"); - public static final ResourceLocation IMPORT_BUS = id("import_bus"); - public static final ResourceLocation EXPORT_BUS = id("export_bus"); - public static final ResourceLocation LEVEL_EMITTER = id("level_emitter"); - public static final ResourceLocation ENERGY_LEVEL_EMITTER = id("energy_level_emitter"); - public static final ResourceLocation PATTERN_PROVIDER = id("cable_pattern_provider"); - public static final ResourceLocation INTERFACE = id("cable_interface"); - public static final ResourceLocation CONVERSION_MONITOR = id("conversion_monitor"); - public static final ResourceLocation ENERGY_ACCEPTOR = id("cable_energy_acceptor"); - - /// - /// Monitors and terminals - /// - public static final ResourceLocation MONITOR = id("monitor"); - public static final ResourceLocation SEMI_DARK_MONITOR = id("semi_dark_monitor"); - public static final ResourceLocation DARK_MONITOR = id("dark_monitor"); public static final ResourceLocation TERMINAL = id("terminal"); public static final ResourceLocation CRAFTING_TERMINAL = id("crafting_terminal"); - public static final ResourceLocation PATTERN_ENCODING_TERMINAL = id("pattern_encoding_terminal"); - public static final ResourceLocation PATTERN_ACCESS_TERMINAL = id("pattern_access_terminal"); - public static final ResourceLocation STORAGE_MONITOR = id("storage_monitor"); - - /// - /// Planes - /// - public static final ResourceLocation FORMATION_PLANE = id("formation_plane"); - public static final ResourceLocation ANNIHILATION_PLANE = id("annihilation_plane"); - - /// - /// P2P - /// - public static final ResourceLocation ME_P2P_TUNNEL = id("me_p2p_tunnel"); - public static final ResourceLocation REDSTONE_P2P_TUNNEL = id("redstone_p2p_tunnel"); - public static final ResourceLocation ITEM_P2P_TUNNEL = id("item_p2p_tunnel"); - public static final ResourceLocation FLUID_P2P_TUNNEL = id("fluid_p2p_tunnel"); - public static final ResourceLocation FE_P2P_TUNNEL = id("fe_p2p_tunnel"); - public static final ResourceLocation LIGHT_P2P_TUNNEL = id("light_p2p_tunnel"); private static ResourceLocation id(String id) { return new ResourceLocation(AEConstants.MOD_ID, id); diff --git a/src/main/java/appeng/api/ids/AETags.java b/src/main/java/appeng/api/ids/AETags.java deleted file mode 100644 index 7f381a5c6e1..00000000000 --- a/src/main/java/appeng/api/ids/AETags.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2021 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.ids; - -import net.minecraft.core.Registry; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.tags.TagKey; -import net.minecraft.world.item.Item; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.material.Fluid; - -/** - * Tags that AE uses for functional purposes. For recipe tags that you may use in your recipe data generation, please - * see the non-api class ConventionTags. - */ -public final class AETags { - - private AETags() { - } - - /** - * Contains blocks that are blacklisted from being moved in and out of spatial storage. - *

- * To blacklist block entities from being moved, you need to add the hosting block to this tag. - */ - public static final TagKey SPATIAL_BLACKLIST = blockTag("ae2:blacklisted/spatial"); - - /** - * Contains blocks that are blacklisted from being picked up by an item annihilation plane. - */ - public static final TagKey ANNIHILATION_PLANE_BLOCK_BLACKLIST = blockTag( - "ae2:blacklisted/annihilation_plane"); - - /** - * Contains items that are blacklisted from being picked up by an item annihilation plane. - */ - public static final TagKey ANNIHILATION_PLANE_ITEM_BLACKLIST = itemTag( - "ae2:blacklisted/annihilation_plane"); - - /** - * Contains items that are blacklisted from being picked up by a fluid annihilation plane. - */ - public static final TagKey ANNIHILATION_PLANE_FLUID_BLACKLIST = fluidTag( - "ae2:blacklisted/annihilation_plane"); - - /** - * Used by the quartz knife to decide which ingots can be crafted into nameplates, as well as the crafting recipe - * for cable anchors. - */ - public static TagKey METAL_INGOTS = itemTag("ae2:metal_ingots"); - - /** - * Block tag used to explicitly whitelist blocks for use in facades, even if they don't meet the general criteria - * for being used in facades. - */ - public static final TagKey FACADE_BLOCK_WHITELIST = blockTag("ae2:whitelisted/facades"); - - /** - * Crystal growth accelerators will trigger additional random ticks for blocks in that tag, regardless of what the - * blocks are. By default, includes {@code c:budding_blocks} / {@code forge:budding} which includes budding amethyst - * and the various budding certus quartz blocks. - */ - public static final TagKey GROWTH_ACCELERATABLE = blockTag("ae2:growth_acceleratable"); - - private static TagKey itemTag(String name) { - return TagKey.create(Registry.ITEM_REGISTRY, new ResourceLocation(name)); - } - - private static TagKey fluidTag(String name) { - return TagKey.create(Registry.FLUID_REGISTRY, new ResourceLocation(name)); - } - - private static TagKey blockTag(String name) { - return TagKey.create(Registry.BLOCK_REGISTRY, new ResourceLocation(name)); - } - -} diff --git a/src/main/java/appeng/api/implementations/IPowerChannelState.java b/src/main/java/appeng/api/implementations/IChannelState.java similarity index 91% rename from src/main/java/appeng/api/implementations/IPowerChannelState.java rename to src/main/java/appeng/api/implementations/IChannelState.java index fc08ffcdc14..22214618110 100644 --- a/src/main/java/appeng/api/implementations/IPowerChannelState.java +++ b/src/main/java/appeng/api/implementations/IChannelState.java @@ -26,13 +26,7 @@ /** * This is intended for use on the client side to provide details to WAILA. */ -public interface IPowerChannelState { - - /** - * @return true if the part/block is powered. - */ - boolean isPowered(); - +public interface IChannelState { /** * @return true if the part/block isActive */ diff --git a/src/main/java/appeng/api/implementations/blockentities/IChestOrDrive.java b/src/main/java/appeng/api/implementations/blockentities/IChestOrDrive.java deleted file mode 100644 index 54265801850..00000000000 --- a/src/main/java/appeng/api/implementations/blockentities/IChestOrDrive.java +++ /dev/null @@ -1,66 +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.implementations.blockentities; - -import javax.annotation.Nullable; - -import net.minecraft.world.item.Item; - -import appeng.api.networking.security.IActionHost; -import appeng.api.storage.cells.CellState; -import appeng.api.util.IOrientable; - -public interface IChestOrDrive extends IOrientable, IActionHost { - - /** - * @return how many slots are available. Chest has 1, Drive has 10. - */ - int getCellCount(); - - /** - * @param slot slot index - * - * @return status of the slot, one of the above indices. - */ - CellState getCellStatus(int slot); - - /** - * @return if the device is online you should check this before providing any other information. - */ - boolean isPowered(); - - /** - * @param slot slot index - * - * @return is the cell currently blinking to show activity. - */ - boolean isCellBlinking(int slot); - - /** - * Returns the item of the cell in the given slot or null. - */ - @Nullable - Item getCellItem(int slot); - -} diff --git a/src/main/java/appeng/api/implementations/blockentities/ICraftingMachine.java b/src/main/java/appeng/api/implementations/blockentities/ICraftingMachine.java deleted file mode 100644 index 9150c018549..00000000000 --- a/src/main/java/appeng/api/implementations/blockentities/ICraftingMachine.java +++ /dev/null @@ -1,97 +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.implementations.blockentities; - -import java.util.Optional; - -import javax.annotation.Nullable; - -import net.fabricmc.fabric.api.lookup.v1.block.BlockApiLookup; -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.network.chat.Component; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.entity.BlockEntity; - -import appeng.api.crafting.IPatternDetails; -import appeng.api.ids.AEConstants; -import appeng.api.stacks.KeyCounter; - -/** - * Provides crafting services to adjacent pattern providers for automatic crafting. Can be provided via capability on - * your block entity. - */ -public interface ICraftingMachine { - - BlockApiLookup SIDED = BlockApiLookup.get( - new ResourceLocation(AEConstants.MOD_ID, "icraftingmachine"), ICraftingMachine.class, Direction.class); - - @Nullable - static ICraftingMachine of(@Nullable BlockEntity blockEntity, Direction side) { - if (blockEntity == null) { - return null; - } - - return of(blockEntity.getLevel(), blockEntity.getBlockPos(), side, blockEntity); - } - - @Nullable - static ICraftingMachine of(Level level, BlockPos pos, Direction side, - @org.jetbrains.annotations.Nullable BlockEntity blockEntity) { - return SIDED.find(level, pos, null, blockEntity, side); - } - - // TODO: 1.19.3+ Remove the default implementation. - @Nullable - default PatternContainerGroup getCraftingMachineInfo() { - return null; - } - - /** - * @return An optional name for this crafting machine, which can be shown in the pattern provider terminal for - * adjacent pattern providers that point to this crafting machine. - */ - @Deprecated(forRemoval = true) - default Optional getDisplayName() { - return Optional.empty(); - } - - /** - * inserts a crafting plan, and the necessary items into the crafting machine. - * - * @param inputs The crafting ingredients. The array layout corresponds to {@link IPatternDetails#getInputs()} of - * patternDetails. - * @return if it was accepted, all or nothing. - */ - boolean pushPattern(IPatternDetails patternDetails, KeyCounter[] inputs, Direction ejectionDirection); - - /** - * check if the crafting machine is accepting pushes via pushPattern, if this is false, all calls to push will fail, - * you can try inserting into the inventory instead. - * - * @return true, if pushPattern can complete, if its false push will always be false. - */ - boolean acceptsPlans(); -} diff --git a/src/main/java/appeng/api/implementations/blockentities/IMEChest.java b/src/main/java/appeng/api/implementations/blockentities/IMEChest.java deleted file mode 100644 index 0a9b4e13f46..00000000000 --- a/src/main/java/appeng/api/implementations/blockentities/IMEChest.java +++ /dev/null @@ -1,30 +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.implementations.blockentities; - -import appeng.api.networking.energy.IEnergySource; - -public interface IMEChest extends IChestOrDrive, IEnergySource { - -} diff --git a/src/main/java/appeng/api/implementations/blockentities/IViewCellStorage.java b/src/main/java/appeng/api/implementations/blockentities/IViewCellStorage.java deleted file mode 100644 index 1c42066e67d..00000000000 --- a/src/main/java/appeng/api/implementations/blockentities/IViewCellStorage.java +++ /dev/null @@ -1,36 +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.implementations.blockentities; - -import appeng.api.inventories.InternalInventory; - -public interface IViewCellStorage { - - /** - * should contains at least 5 slot, the first 5 - * - * @return inventory with at least 5 slot - */ - InternalInventory getViewCellStorage(); -} diff --git a/src/main/java/appeng/api/implementations/blockentities/IWirelessAccessPoint.java b/src/main/java/appeng/api/implementations/blockentities/IWirelessAccessPoint.java index 04450312a7e..feeb0e676bc 100644 --- a/src/main/java/appeng/api/implementations/blockentities/IWirelessAccessPoint.java +++ b/src/main/java/appeng/api/implementations/blockentities/IWirelessAccessPoint.java @@ -36,11 +36,6 @@ public interface IWirelessAccessPoint extends IActionHost { */ DimensionalBlockPos getLocation(); - /** - * @return max range for this WAP - */ - double getRange(); - /** * @return can you use this WAP? */ diff --git a/src/main/java/appeng/api/implementations/blockentities/PatternContainerGroup.java b/src/main/java/appeng/api/implementations/blockentities/PatternContainerGroup.java deleted file mode 100644 index 313f0b814c5..00000000000 --- a/src/main/java/appeng/api/implementations/blockentities/PatternContainerGroup.java +++ /dev/null @@ -1,132 +0,0 @@ -package appeng.api.implementations.blockentities; - -import java.util.ArrayList; -import java.util.List; - -import org.jetbrains.annotations.Nullable; - -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.network.chat.Component; -import net.minecraft.world.Nameable; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.Items; -import net.minecraft.world.level.Level; - -import appeng.api.inventories.InternalInventory; -import appeng.api.parts.IPartHost; -import appeng.api.stacks.AEItemKey; -import appeng.core.localization.GuiText; - -/** - * Provides both a key for grouping pattern providers, and displaying the group in the pattern access terminal. - *

- * The group can be the crafting container itself, for example if it is given a custom name by the player. It might - * default to the crafting machine it is adjacent otherwise. - * - * @param icon The icon to display when referring to the grouped containers. This stack will NEVER be modified. It - * will be used to show an icon, as well as compared to group similar containers. It may be - * {@link ItemStack#EMPTY} - * @param name The name to use to refer to the group. - * @param tooltip Additional tooltip lines to describe the group (i.e. installed upgrades). - */ -public record PatternContainerGroup( - @Nullable AEItemKey icon, - Component name, - List tooltip) { - - private static final PatternContainerGroup NOTHING = new PatternContainerGroup(AEItemKey.of(Items.AIR), - GuiText.Nothing.text(), List.of()); - - public static PatternContainerGroup nothing() { - return NOTHING; - } - - public void writeToPacket(FriendlyByteBuf buffer) { - buffer.writeBoolean(icon != null); - if (icon != null) { - icon.writeToPacket(buffer); - } - buffer.writeComponent(name); - buffer.writeVarInt(tooltip.size()); - for (var component : tooltip) { - buffer.writeComponent(component); - } - } - - public static PatternContainerGroup readFromPacket(FriendlyByteBuf buffer) { - var icon = buffer.readBoolean() ? AEItemKey.fromPacket(buffer) : null; - var name = buffer.readComponent(); - var lineCount = buffer.readVarInt(); - var lines = new ArrayList(lineCount); - for (int i = 0; i < lineCount; i++) { - lines.add(buffer.readComponent()); - } - return new PatternContainerGroup(icon, name, lines); - } - - @Nullable - public static PatternContainerGroup fromMachine(Level level, BlockPos pos, Direction side) { - var target = level.getBlockEntity(pos); - - // Check for first-class support - var craftingMachine = ICraftingMachine.of(level, pos, side, target); - if (craftingMachine != null) { - var info = craftingMachine.getCraftingMachineInfo(); - if (info != null) { - return info; - } - } - - // Anything else requires a block entity - if (target == null) { - return null; - } - - // Heuristic: If it doesn't allow any transfers, ignore it - var adaptor = InternalInventory.wrapExternal(target, side); - if (adaptor == null || !adaptor.mayAllowInsertion()) { - return null; - } - - AEItemKey icon; - Component name; - List tooltip = List.of(); - - // For scenarios like pattern providers against cable bus - if (target instanceof IPartHost partHost) { - var part = partHost.getPart(side); - if (part == null) { - // No part at side -> ignore, we don't interface with the cable - return null; - } - - icon = AEItemKey.of(part.getPartItem()); - if (part instanceof Nameable nameable && nameable.hasCustomName()) { - name = nameable.getCustomName(); - } else { - name = icon.getDisplayName(); - } - } else { - // Try to wrestle an item from the adjacent block entity - // TODO On Forge we can use pick block here - var targetBlock = target.getBlockState().getBlock(); - var targetItem = new ItemStack(targetBlock); - icon = AEItemKey.of(targetItem); - - if (target instanceof Nameable nameable && nameable.hasCustomName()) { - name = nameable.getCustomName(); - } else { - if (targetItem.isEmpty()) { - // If the object isn't named, and we didn't get an item from it, - // we can't show either icon nor name! - return null; - } - name = targetItem.getHoverName(); - } - } - - return new PatternContainerGroup(icon, name, tooltip); - } -} diff --git a/src/main/java/appeng/api/implementations/items/IAEItemPowerStorage.java b/src/main/java/appeng/api/implementations/items/IAEItemPowerStorage.java deleted file mode 100644 index 9233f1c4c6c..00000000000 --- a/src/main/java/appeng/api/implementations/items/IAEItemPowerStorage.java +++ /dev/null @@ -1,72 +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.implementations.items; - -import net.minecraft.world.item.ItemStack; - -import appeng.api.config.AccessRestriction; -import appeng.api.config.Actionable; -import appeng.api.networking.energy.IAEPowerStorage; - -/** - * Basically the same as {@link IAEPowerStorage}, but for items. - */ -public interface IAEItemPowerStorage { - /** - * Inject amt, power into the device, it will store what it can, and return the amount unable to be stored. - * - * @return amount unable to be stored - */ - double injectAEPower(ItemStack stack, double amount, Actionable mode); - - /** - * Attempt to extract power from the device, it will extract what it can and return it. - * - * @param amount to be extracted power from device - * @return what it could extract - */ - double extractAEPower(ItemStack stack, double amount, Actionable mode); - - /** - * @return the current maximum power ( this can change :P ) - */ - double getAEMaxPower(ItemStack stack); - - /** - * @return the current AE Power Level, this may exceed getMEMaxPower() - */ - double getAECurrentPower(ItemStack stack); - - /** - * Control the power flow by telling what the network can do, either add? or subtract? or both! - * - * @return access restriction of network - */ - AccessRestriction getPowerFlow(ItemStack stack); - - /** - * @return The amount of AE per tick that the AE charger will charge this item at. - */ - double getChargeRate(ItemStack stack); -} diff --git a/src/main/java/appeng/api/implementations/items/ISpatialStorageCell.java b/src/main/java/appeng/api/implementations/items/ISpatialStorageCell.java deleted file mode 100644 index c5ee58f1646..00000000000 --- a/src/main/java/appeng/api/implementations/items/ISpatialStorageCell.java +++ /dev/null @@ -1,71 +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.implementations.items; - -import net.minecraft.core.BlockPos; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.ItemStack; - -/** - * Implemented on a {@link Item} - */ -public interface ISpatialStorageCell { - - /** - * @param is spatial storage cell - * - * @return true if this item is a spatial storage cell - */ - boolean isSpatialStorage(ItemStack is); - - /** - * @param is spatial storage cell - * - * @return the maximum size of the spatial storage cell along any given axis - */ - int getMaxStoredDim(ItemStack is); - - /** - * get the currently stored spatial storage plot id. - * - * @param is spatial storage cell - * - * @return plot id or -1 - */ - int getAllocatedPlotId(ItemStack is); - - /** - * Perform a spatial swap with the contents of the cell, and the level. - * - * @param is spatial storage cell - * @param level level of spatial - * @param min min coord - * @param max max coord - * @param playerId owner of current grid or -1 - * - * @return success of transition - */ - boolean doSpatialTransition(ItemStack is, ServerLevel level, BlockPos min, BlockPos max, int playerId); -} diff --git a/src/main/java/appeng/api/implementations/menuobjects/IPortableTerminal.java b/src/main/java/appeng/api/implementations/menuobjects/IPortableTerminal.java index 3c96d5afd3c..b4290564b0b 100644 --- a/src/main/java/appeng/api/implementations/menuobjects/IPortableTerminal.java +++ b/src/main/java/appeng/api/implementations/menuobjects/IPortableTerminal.java @@ -23,12 +23,11 @@ package appeng.api.implementations.menuobjects; -import appeng.api.networking.energy.IEnergySource; import appeng.api.storage.ITerminalHost; /** * Obtained via {@link IMenuItem} getMenuHost */ -public interface IPortableTerminal extends ITerminalHost, IEnergySource { +public interface IPortableTerminal extends ITerminalHost { } diff --git a/src/main/java/appeng/api/implementations/menuobjects/ItemMenuHost.java b/src/main/java/appeng/api/implementations/menuobjects/ItemMenuHost.java index 2adeb9cee55..9814648d5a0 100644 --- a/src/main/java/appeng/api/implementations/menuobjects/ItemMenuHost.java +++ b/src/main/java/appeng/api/implementations/menuobjects/ItemMenuHost.java @@ -24,10 +24,6 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.item.ItemStack; - -import appeng.api.config.Actionable; -import appeng.api.config.PowerMultiplier; -import appeng.api.networking.energy.IEnergySource; import appeng.api.upgrades.IUpgradeInventory; import appeng.api.upgrades.IUpgradeableItem; import appeng.api.upgrades.IUpgradeableObject; @@ -43,8 +39,6 @@ public class ItemMenuHost implements IUpgradeableObject { private final Integer slot; private final ItemStack itemStack; private final IUpgradeInventory upgrades; - private int powerTicks = 0; - private double powerDrainPerTick = 0.5; public ItemMenuHost(Player player, @Nullable Integer slot, ItemStack itemStack) { this.player = player; @@ -125,28 +119,6 @@ protected boolean ensureItemStillInSlot() { return false; } - /** - * Can only be used with a host that implements {@link IEnergySource} only call once per broadcastChanges() - */ - public boolean drainPower() { - if (this instanceof IEnergySource energySource) { - this.powerTicks++; - if (this.powerTicks > 10) { - var amt = this.powerTicks * this.powerDrainPerTick; - this.powerTicks = 0; - return energySource.extractAEPower(amt, Actionable.MODULATE, PowerMultiplier.CONFIG) > 0; - } - } - return true; - } - - /** - * Sets how much AE is drained per tick. - */ - protected void setPowerDrainPerTick(double powerDrainPerTick) { - this.powerDrainPerTick = powerDrainPerTick; - } - @Override public final IUpgradeInventory getUpgrades() { return upgrades; diff --git a/src/main/java/appeng/api/implementations/parts/IMonitorPart.java b/src/main/java/appeng/api/implementations/parts/IMonitorPart.java deleted file mode 100644 index 7223160a74f..00000000000 --- a/src/main/java/appeng/api/implementations/parts/IMonitorPart.java +++ /dev/null @@ -1,37 +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.implementations.parts; - -import appeng.api.parts.IPart; - -/** - * Implemented by all screen like parts provided by AE. - */ -public interface IMonitorPart extends IPart { - - /** - * @return if the device is online you should check this before providing any other information. - */ - boolean isPowered(); -} diff --git a/src/main/java/appeng/api/implementations/parts/IStorageMonitorPart.java b/src/main/java/appeng/api/implementations/parts/IStorageMonitorPart.java index 25b929ce5b1..6a061d27fe4 100644 --- a/src/main/java/appeng/api/implementations/parts/IStorageMonitorPart.java +++ b/src/main/java/appeng/api/implementations/parts/IStorageMonitorPart.java @@ -32,7 +32,7 @@ /** * The Storage monitor is a {@link IPart} located on the sides of a IPartHost */ -public interface IStorageMonitorPart extends IMonitorPart, IPart, INetworkToolAware { +public interface IStorageMonitorPart extends IPart, INetworkToolAware { /** * @return what is being shown on the storage monitor diff --git a/src/main/java/appeng/api/networking/IGrid.java b/src/main/java/appeng/api/networking/IGrid.java index c1f7cd2e9e4..f157c365dd5 100644 --- a/src/main/java/appeng/api/networking/IGrid.java +++ b/src/main/java/appeng/api/networking/IGrid.java @@ -25,12 +25,9 @@ import java.util.Set; -import appeng.api.networking.crafting.ICraftingService; -import appeng.api.networking.energy.IEnergyService; import appeng.api.networking.events.GridEvent; import appeng.api.networking.pathing.IPathingService; import appeng.api.networking.security.ISecurityService; -import appeng.api.networking.spatial.ISpatialService; import appeng.api.networking.storage.IStorageService; import appeng.api.networking.ticking.ITickManager; @@ -139,26 +136,6 @@ default IStorageService getStorageService() { return getService(IStorageService.class); } - /** - * Get this grids {@link IEnergyService}. - * - * @see #getService(Class) - */ - - default IEnergyService getEnergyService() { - return getService(IEnergyService.class); - } - - /** - * Get this grids {@link ICraftingService}. - * - * @see #getService(Class) - */ - - default ICraftingService getCraftingService() { - return getService(ICraftingService.class); - } - /** * Get this grids {@link ISecurityService}. * @@ -178,14 +155,4 @@ default ISecurityService getSecurityService() { default IPathingService getPathingService() { return getService(IPathingService.class); } - - /** - * Get this grids {@link ISpatialService}. - * - * @see #getService(Class) - */ - - default ISpatialService getSpatialService() { - return getService(ISpatialService.class); - } } diff --git a/src/main/java/appeng/api/networking/IGridNode.java b/src/main/java/appeng/api/networking/IGridNode.java index e93b019b24c..31396e9bb99 100644 --- a/src/main/java/appeng/api/networking/IGridNode.java +++ b/src/main/java/appeng/api/networking/IGridNode.java @@ -35,7 +35,6 @@ import net.minecraft.server.level.ServerLevel; import net.minecraft.world.level.block.entity.BlockEntity; -import appeng.api.networking.crafting.ICraftingService; import appeng.api.networking.pathing.IPathingService; import appeng.api.stacks.AEItemKey; import appeng.api.util.AEColor; @@ -115,7 +114,7 @@ public interface IGridNode { * visual state display to avoid the device looking disabled while the grid is booting. */ default boolean isActive() { - return isPowered() && hasGridBooted() && meetsChannelRequirements(); + return hasGridBooted() && meetsChannelRequirements(); } /** @@ -126,7 +125,7 @@ default boolean isActive() { * as the channels might still be outdated. */ default boolean isOnline() { - return isPowered() && meetsChannelRequirements(); + return meetsChannelRequirements(); } /** @@ -135,13 +134,6 @@ default boolean isOnline() { */ boolean hasGridBooted(); - /** - * @return True if the node has power from it's connected grid. Can be used to show a machine being powered, even if - * the machine doesn't have it's required channel or the network is still booting. - * @see #isActive() - */ - boolean isPowered(); - /** * @return if the node's channel requirements are currently met, use this for display purposes, use isActive for * status. @@ -162,12 +154,6 @@ default boolean isOnline() { */ int getOwningPlayerId(); - /** - * @return The power in AE/t that will be drained by this node. - */ - @Nonnegative - double getIdlePowerUsage(); - /** * @return True if the grid node is accessible on the given side of the host. */ diff --git a/src/main/java/appeng/api/networking/IGridNodeListener.java b/src/main/java/appeng/api/networking/IGridNodeListener.java index 09cc3898ed5..12f8db17ef9 100644 --- a/src/main/java/appeng/api/networking/IGridNodeListener.java +++ b/src/main/java/appeng/api/networking/IGridNodeListener.java @@ -73,10 +73,6 @@ default void onStateChanged(T nodeOwner, IGridNode node, State state) { * Gives a reason for why the active state of the node might have changed. */ enum State { - /** - * The node's power status has changed (it either became powered or unpowered). - */ - POWER, /** * The node's assigned channels have changed. This might only be relevant for nodes that require channels. */ diff --git a/src/main/java/appeng/api/networking/IManagedGridNode.java b/src/main/java/appeng/api/networking/IManagedGridNode.java index 89fae6538e0..c6adb066abe 100644 --- a/src/main/java/appeng/api/networking/IManagedGridNode.java +++ b/src/main/java/appeng/api/networking/IManagedGridNode.java @@ -125,11 +125,6 @@ default IGrid getGrid() { */ IManagedGridNode setExposedOnSides(Set directions); - /** - * @param usagePerTick The power in AE/t that will be drained by this node. - */ - IManagedGridNode setIdlePowerUsage(@Nonnegative double usagePerTick); - /** * Sets an itemstack that will only be used to represent this grid node in user interfaces. Can be set to * null to hide the node from UIs. diff --git a/src/main/java/appeng/api/networking/IStackWatcher.java b/src/main/java/appeng/api/networking/IStackWatcher.java index 6e78543a512..9c3938395c5 100644 --- a/src/main/java/appeng/api/networking/IStackWatcher.java +++ b/src/main/java/appeng/api/networking/IStackWatcher.java @@ -2,7 +2,6 @@ import org.jetbrains.annotations.ApiStatus; -import appeng.api.networking.crafting.ICraftingWatcherNode; import appeng.api.networking.storage.IStorageWatcherNode; import appeng.api.stacks.AEKey; diff --git a/src/main/java/appeng/api/networking/crafting/CalculationStrategy.java b/src/main/java/appeng/api/networking/crafting/CalculationStrategy.java deleted file mode 100644 index f2805762e3d..00000000000 --- a/src/main/java/appeng/api/networking/crafting/CalculationStrategy.java +++ /dev/null @@ -1,13 +0,0 @@ -package appeng.api.networking.crafting; - -public enum CalculationStrategy { - /** - * If the exact requested amount cannot be crafted, create a {@link ICraftingPlan} containing the missing items. - */ - REPORT_MISSING_ITEMS, - /** - * Try to craft less items than requested. Will try to craft as many items as possible. If even {@code 1} cannot be - * crafted, fall back to {@link #REPORT_MISSING_ITEMS}. - */ - CRAFT_LESS, -} diff --git a/src/main/java/appeng/api/networking/crafting/CraftingJobStatus.java b/src/main/java/appeng/api/networking/crafting/CraftingJobStatus.java deleted file mode 100644 index 109e51e23c9..00000000000 --- a/src/main/java/appeng/api/networking/crafting/CraftingJobStatus.java +++ /dev/null @@ -1,6 +0,0 @@ -package appeng.api.networking.crafting; - -import appeng.api.stacks.GenericStack; - -public record CraftingJobStatus(GenericStack crafting, long totalItems, long progress, long elapsedTimeNanos) { -} diff --git a/src/main/java/appeng/api/networking/crafting/CraftingSubmitErrorCode.java b/src/main/java/appeng/api/networking/crafting/CraftingSubmitErrorCode.java deleted file mode 100644 index 4585c4ff7ce..00000000000 --- a/src/main/java/appeng/api/networking/crafting/CraftingSubmitErrorCode.java +++ /dev/null @@ -1,40 +0,0 @@ -package appeng.api.networking.crafting; - -import appeng.api.stacks.GenericStack; - -/** - * Gives a reason for why submitting the crafting job failed. - */ -public enum CraftingSubmitErrorCode { - /** - * Trying to submit a plan that is incomplete. Plans that return true for {@link ICraftingPlan#simulation()} are - * incomplete. - */ - INCOMPLETE_PLAN, - /** - * Couldn't find any CPUs to execute this job. - */ - NO_CPU_FOUND, - /** - * None of the available CPUs are suitable to execute this job. {@link ICraftingSubmitResult#errorDetail()} contains - * an instance of {@link UnsuitableCpus} giving details as to why available CPUs are unsuitable. - */ - NO_SUITABLE_CPU_FOUND, - /** - * The selected crafting CPU is already working on something else. - */ - CPU_BUSY, - /** - * The CPU is currently offline (no power or not enough channels). - */ - CPU_OFFLINE, - /** - * The CPU is too small to process the job. - */ - CPU_TOO_SMALL, - /** - * Could not obtain one of the ingredients needed for the job. {@link ICraftingSubmitResult#errorDetail()} is a - * {@link GenericStack} explaining what is missing. - */ - MISSING_INGREDIENT -} diff --git a/src/main/java/appeng/api/networking/crafting/ICraftingCPU.java b/src/main/java/appeng/api/networking/crafting/ICraftingCPU.java deleted file mode 100644 index 2d637b368ba..00000000000 --- a/src/main/java/appeng/api/networking/crafting/ICraftingCPU.java +++ /dev/null @@ -1,65 +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.networking.crafting; - -import javax.annotation.Nullable; - -import net.minecraft.network.chat.Component; - -import appeng.api.config.CpuSelectionMode; - -public interface ICraftingCPU { - - /** - * @return true if the CPU currently has a job. - */ - boolean isBusy(); - - /** - * @return The status of the current job (that is if {@link #isBusy()} was true). - */ - @Nullable - CraftingJobStatus getJobStatus(); - - /** - * @return the available storage in bytes - */ - long getAvailableStorage(); - - /** - * @return the number of co-processors in the CPU. - */ - int getCoProcessors(); - - /** - * @return a null or the name of the cpu. - */ - @Nullable - Component getName(); - - /** - * @return The mode used to select this CPU for crafting jobs when the CPU should be auto-selected. - */ - CpuSelectionMode getSelectionMode(); -} diff --git a/src/main/java/appeng/api/networking/crafting/ICraftingLink.java b/src/main/java/appeng/api/networking/crafting/ICraftingLink.java deleted file mode 100644 index b6533967ecf..00000000000 --- a/src/main/java/appeng/api/networking/crafting/ICraftingLink.java +++ /dev/null @@ -1,61 +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.networking.crafting; - -import net.minecraft.nbt.CompoundTag; - -public interface ICraftingLink { - - /** - * @return true if the job was canceled. - */ - boolean isCanceled(); - - /** - * @return true if the job was completed. - */ - boolean isDone(); - - /** - * cancels the job. - */ - void cancel(); - - /** - * @return true if this link was generated without a requesting machine, such as a player generated request. - */ - boolean isStandalone(); - - /** - * write the link to an NBT Tag - * - * @param tag to be written data - */ - void writeToNBT(CompoundTag tag); - - /** - * @return the crafting ID for this link. - */ - String getCraftingID(); -} diff --git a/src/main/java/appeng/api/networking/crafting/ICraftingPlan.java b/src/main/java/appeng/api/networking/crafting/ICraftingPlan.java deleted file mode 100644 index 1df89f7b656..00000000000 --- a/src/main/java/appeng/api/networking/crafting/ICraftingPlan.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2021 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.networking.crafting; - -import java.util.Map; - -import appeng.api.crafting.IPatternDetails; -import appeng.api.stacks.GenericStack; -import appeng.api.stacks.KeyCounter; - -/** - * Result of a {@linkplain ICraftingService#beginCraftingCalculation crafting job calculation}. Do not edit any of the - * map/lists, they are exposed directly! - */ -public interface ICraftingPlan { - /** - * Final output of the job. - */ - GenericStack finalOutput(); - - /** - * Total bytes used by the job. - */ - long bytes(); - - /** - * True if some things were missing and this is just a simulation. - */ - boolean simulation(); - - /** - * True there were multiple paths in the crafting tree, i.e. at least one item had multiple patterns that could - * produce it. - */ - boolean multiplePaths(); - - /** - * List of items that were used. (They would need to be extracted to start the job). - */ - KeyCounter usedItems(); - - /** - * List of items that need to be emitted for this job. - */ - KeyCounter emittedItems(); - - /** - * List of missing items if this is a simulation. - */ - KeyCounter missingItems(); - - /** - * Map of each pattern to the number of times it needs to be crafted. Can be used to retrieve the crafted items: - * outputs * times. - */ - Map patternTimes(); -} diff --git a/src/main/java/appeng/api/networking/crafting/ICraftingProvider.java b/src/main/java/appeng/api/networking/crafting/ICraftingProvider.java deleted file mode 100644 index 604a9eba1f8..00000000000 --- a/src/main/java/appeng/api/networking/crafting/ICraftingProvider.java +++ /dev/null @@ -1,85 +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.networking.crafting; - -import java.util.List; -import java.util.Set; - -import appeng.api.crafting.IPatternDetails; -import appeng.api.networking.IGridNodeService; -import appeng.api.networking.IManagedGridNode; -import appeng.api.stacks.AEKey; -import appeng.api.stacks.KeyCounter; - -/** - * Allows a node to provide crafting patterns and emitable items to the network. - */ -public interface ICraftingProvider extends IGridNodeService { - /** - * Return the patterns offered by this provider. {@link #pushPattern} will be called if they need to be crafted. - */ - List getAvailablePatterns(); - - /** - * Return the priority for the patterns offered by this provider. The crafting calculation will prioritize patterns - * with the highest priority. - */ - default int getPatternPriority() { - return 0; - } - - /** - * Instruct a provider to craft one of the patterns. - * - * @param patternDetails details - * @param inputHolder the requested stacks, for each input slot of the pattern - * - * @return if the pattern was successfully pushed. - */ - boolean pushPattern(IPatternDetails patternDetails, KeyCounter[] inputHolder); - - /** - * @return if this is true, the crafting engine will refuse to send patterns to this provider. - */ - boolean isBusy(); - - /** - * Return the emitable items offered by this provider. They should be crafted and inserted into the network when - * {@link ICraftingService#isRequesting} is true. - */ - default Set getEmitableItems() { - return Set.of(); - } - - /** - * This convenience method can be used when the crafting options or emitable items have changed to request an update - * of the crafting service's cache.This only works if the given managed grid node provides this service. - */ - static void requestUpdate(IManagedGridNode managedNode) { - var node = managedNode.getNode(); - if (node != null) { - node.getGrid().getCraftingService().refreshNodeCraftingProvider(node); - } - } -} diff --git a/src/main/java/appeng/api/networking/crafting/ICraftingRequester.java b/src/main/java/appeng/api/networking/crafting/ICraftingRequester.java deleted file mode 100644 index e75834ce7f4..00000000000 --- a/src/main/java/appeng/api/networking/crafting/ICraftingRequester.java +++ /dev/null @@ -1,56 +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.networking.crafting; - -import com.google.common.collect.ImmutableSet; - -import appeng.api.config.Actionable; -import appeng.api.networking.IGridNodeService; -import appeng.api.networking.security.IActionHost; -import appeng.api.stacks.AEKey; - -public interface ICraftingRequester extends IActionHost, IGridNodeService { - - /** - * called when the host is added to the grid, and should return all crafting links it poses so they can be connected - * with the cpu that hosts the job. - * - * @return set of jobs, or an empty list. - */ - ImmutableSet getRequestedJobs(); - - /** - * items are injected into the requester as they are completed. - * - * @return the number of items inserted. - */ - long insertCraftedItems(ICraftingLink link, AEKey what, long amount, Actionable mode); - - /** - * called when the job changes from in progress, to either complete, or canceled. - *

- * after this call the crafting link is "dead" and should be discarded. - */ - void jobStateChange(ICraftingLink link); -} diff --git a/src/main/java/appeng/api/networking/crafting/ICraftingService.java b/src/main/java/appeng/api/networking/crafting/ICraftingService.java deleted file mode 100644 index 8366047925e..00000000000 --- a/src/main/java/appeng/api/networking/crafting/ICraftingService.java +++ /dev/null @@ -1,154 +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.networking.crafting; - -import java.util.Collection; -import java.util.Set; -import java.util.concurrent.Future; - -import com.google.common.collect.ImmutableSet; - -import org.jetbrains.annotations.Nullable; - -import net.minecraft.world.level.Level; - -import appeng.api.crafting.IPatternDetails; -import appeng.api.networking.IGridNode; -import appeng.api.networking.IGridService; -import appeng.api.networking.security.IActionSource; -import appeng.api.stacks.AEKey; -import appeng.api.storage.AEKeyFilter; - -public interface ICraftingService extends IGridService { - - /** - * @param whatToCraft requested craft - * - * @return an unmodifiable collection of crafting patterns for the item in question. - */ - Collection getCraftingFor(AEKey whatToCraft); - - /** - * @return true if the grid knows how to craft the given key - */ - default boolean isCraftable(AEKey whatToCraft) { - return !getCraftingFor(whatToCraft).isEmpty(); - } - - /** - * Refreshes the crafting mounts provided by a {@link IGridNode node} through its {@link ICraftingProvider}. - * - * @throws IllegalArgumentException If the given node is not part of this grid, or did not provide - * {@link ICraftingProvider}. - */ - void refreshNodeCraftingProvider(IGridNode node); - - /** - * Important: Never mutate the passed or returned stacks. - * - * @return another fuzzy equals stack that can be crafted and matches the filter, or null if none exists - */ - @Nullable - AEKey getFuzzyCraftable(AEKey whatToCraft, AEKeyFilter filter); - - /** - * Begin calculating a crafting job. - * - * @param level crafting level - * @param simRequester source - * @param craftWhat result - * @param strategy usually {@link CalculationStrategy#REPORT_MISSING_ITEMS} for player requests - * - * @return a future which will at an undetermined point in the future get you the {@link ICraftingPlan} do not wait - * on this, your be waiting forever. - */ - Future beginCraftingCalculation(Level level, ICraftingSimulationRequester simRequester, - AEKey craftWhat, long amount, CalculationStrategy strategy); - - /** - * Submit the job to the Crafting system for processing. - *

- * If you send a requestingMachine you need to keep track of the resulting {@link ICraftingLink}, persist it to nbt, - * and expose it in {@link ICraftingRequester#getRequestedJobs()} so that the requester can be linked back to the - * CPU after a chunk unload / grid change. - * - * @param job - the crafting job from beginCraftingJob - * @param requestingMachine - a machine if its being requested via automation, may be null. - * @param target - can be null - * @param prioritizePower - if cpu is null, this determine if the system should prioritize power, or if it should - * find the lower end cpus. - * @param src - the action source to use when starting the job, this will be used for extracting - * items, should usually be the same as the one provided to beginCraftingJob. - * - * @return the success/failure state, and a crafting link in case if successful and there was a requestingMachine. - */ - ICraftingSubmitResult submitJob(ICraftingPlan job, @Nullable ICraftingRequester requestingMachine, - @Nullable ICraftingCPU target, - boolean prioritizePower, IActionSource src); - - /** - * @return list of all the crafting cpus on the grid - */ - ImmutableSet getCpus(); - - /** - * @param what to be requested item - * - * @return true if the item can be requested via a crafting emitter. - */ - boolean canEmitFor(AEKey what); - - /** - * Get the set of things that can be crafted for a given storage channel. - */ - Set getCraftables(AEKeyFilter filter); - - /** - * Returns true if what is currently being requested for a crafting job in this grid. - *

- * This means that its pattern was pushed to a provider and the result is now being awaited, or that more of the - * item is expected to be emitted. The final output of a job does not count as being requested. - * - * @param what item being crafted - * - * @return true if it is being crafting - */ - boolean isRequesting(AEKey what); - - /** - * Gets the total amount being requested across all crafting cpus of a grid. - * - * @param what the key for which the requested amount should be returned - * - * @return The total amount being requested. - */ - long getRequestedAmount(AEKey what); - - /** - * Returns true if anything is currently being requested as part of a crafting job in this grid. - * - * @see #isRequesting(AEKey) - */ - boolean isRequestingAny(); -} diff --git a/src/main/java/appeng/api/networking/crafting/ICraftingSimulationRequester.java b/src/main/java/appeng/api/networking/crafting/ICraftingSimulationRequester.java deleted file mode 100644 index 4a7a32580ea..00000000000 --- a/src/main/java/appeng/api/networking/crafting/ICraftingSimulationRequester.java +++ /dev/null @@ -1,34 +0,0 @@ -package appeng.api.networking.crafting; - -import javax.annotation.Nullable; - -import appeng.api.networking.IGridNode; -import appeng.api.networking.security.IActionHost; -import appeng.api.networking.security.IActionSource; - -/** - * The source of a crafting simulation request. This allows the crafting simulation to keep track of the current grid - * across multiple ticks to simulate item extraction or to explore more patterns. - * - * Returning null in one of the functions will just prevent extraction or exploration of patterns, likely leading to an - * unsuccessful {@link ICraftingPlan}. - */ -public interface ICraftingSimulationRequester { - /** - * Return the current action source, used to extract items. - */ - @Nullable - IActionSource getActionSource(); - - /** - * Return the current grid node, used to access the current grid state. - */ - @Nullable - default IGridNode getGridNode() { - var actionSource = getActionSource(); - if (actionSource != null) { - return actionSource.machine().map(IActionHost::getActionableNode).orElse(null); - } - return null; - } -} diff --git a/src/main/java/appeng/api/networking/crafting/ICraftingSubmitResult.java b/src/main/java/appeng/api/networking/crafting/ICraftingSubmitResult.java deleted file mode 100644 index ba0942cb410..00000000000 --- a/src/main/java/appeng/api/networking/crafting/ICraftingSubmitResult.java +++ /dev/null @@ -1,35 +0,0 @@ -package appeng.api.networking.crafting; - -import org.jetbrains.annotations.ApiStatus; -import org.jetbrains.annotations.Nullable; - -/** - * Result of {@linkplain ICraftingService#submitJob submitting a crafting job}. - */ -@ApiStatus.NonExtendable -public interface ICraftingSubmitResult { - default boolean successful() { - return errorCode() == null; - } - - /** - * @return A not-null error code if the auto-crafting request was not submitted succesfully. - */ - @Nullable - CraftingSubmitErrorCode errorCode(); - - /** - * If {@link #errorCode()} is not-null, this may optionally give additional error details. Type depends on the error - * code returned in {@link #errorCode()}. - */ - @Nullable - Object errorDetail(); - - /** - * The crafting link, only available for successful requests with a requester. Make sure to properly keep track of - * this object, save it to NBT, load it from NBT, and make it available to the network via - * {@link ICraftingRequester#getRequestedJobs()}. - */ - @Nullable - ICraftingLink link(); -} diff --git a/src/main/java/appeng/api/networking/crafting/ICraftingWatcherNode.java b/src/main/java/appeng/api/networking/crafting/ICraftingWatcherNode.java deleted file mode 100644 index 99de5182480..00000000000 --- a/src/main/java/appeng/api/networking/crafting/ICraftingWatcherNode.java +++ /dev/null @@ -1,51 +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.networking.crafting; - -import appeng.api.networking.IGridNodeService; -import appeng.api.networking.IStackWatcher; -import appeng.api.stacks.AEKey; - -/** - * A node that is notified of changes to the currently crafting items in the network. Implementors should store the - * watcher passed to {@link #updateWatcher} and use it to configure the watched stacks. - */ -public interface ICraftingWatcherNode extends IGridNodeService { - - /** - * provides the watcher for this host, for the current network, is called when the hot changes networks. You do not - * need to clear your old watcher, its already been removed by the time this gets called. - * - * @param newWatcher crafting watcher for this host - */ - void updateWatcher(IStackWatcher newWatcher); - - /** - * Called when a crafting status changes. - * - * @param craftingGrid current crafting grid - * @param what changed key - */ - void onRequestChange(ICraftingService craftingGrid, AEKey what); -} diff --git a/src/main/java/appeng/api/networking/crafting/UnsuitableCpus.java b/src/main/java/appeng/api/networking/crafting/UnsuitableCpus.java deleted file mode 100644 index 6d678d75d14..00000000000 --- a/src/main/java/appeng/api/networking/crafting/UnsuitableCpus.java +++ /dev/null @@ -1,8 +0,0 @@ -package appeng.api.networking.crafting; - -/** - * Details about unsuitable crafting CPUs unavailable for a job. Detail for - * {@link appeng.api.networking.crafting.CraftingSubmitErrorCode#NO_SUITABLE_CPU_FOUND}. - */ -public record UnsuitableCpus(int offline, int busy, int tooSmall, int excluded) { -} diff --git a/src/main/java/appeng/api/networking/energy/IAEPowerStorage.java b/src/main/java/appeng/api/networking/energy/IAEPowerStorage.java deleted file mode 100644 index a575e86fec3..00000000000 --- a/src/main/java/appeng/api/networking/energy/IAEPowerStorage.java +++ /dev/null @@ -1,87 +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.networking.energy; - -import appeng.api.config.AccessRestriction; -import appeng.api.config.Actionable; -import appeng.api.networking.IGrid; -import appeng.api.networking.IGridNodeService; - -/** - * Used to access information about AE's various power accepting blocks for monitoring purposes. - */ -public interface IAEPowerStorage extends IEnergySource, IGridNodeService { - - /** - * Inject amt, power into the device, it will store what it can, and return the amount unable to be stored. - * - * @param amt to be injected amount - * @param mode action mode - * - * @return amount of power which was unable to be stored - */ - double injectAEPower(double amt, Actionable mode); - - /** - * @return the current maximum power ( this can change :P ) - */ - double getAEMaxPower(); - - /** - * @return the current AE Power Level, this may exceed getMEMaxPower() - */ - double getAECurrentPower(); - - /** - * Checked on network reset to see if your block can be used as a public power storage ( use getPowerFlow to control - * the behavior ) - * - * @return true if it can be used as a public power storage - */ - boolean isAEPublicPowerStorage(); - - /** - * Control the power flow by telling what the network can do, either add? or subtract? or both! - * - * @return access restriction what the network can do - */ - - AccessRestriction getPowerFlow(); - - /** - * The priority to use this energy storage. - * - * A higher value means it is more likely to be extracted from first, and less likely to be inserted into first. - * - * The value needs to be constant once added to a {@link IGrid}. Should it ever need to be changed, it has to be - * removed from the grid, then update the value, and finally added back to the grid. - * - * This should never use {@link Integer#MIN_VALUE} or {@link Integer#MAX_VALUE}. - * - * @return the priority for this storage - */ - default int getPriority() { - return 0; - } -} diff --git a/src/main/java/appeng/api/networking/energy/IEnergyGridProvider.java b/src/main/java/appeng/api/networking/energy/IEnergyGridProvider.java deleted file mode 100644 index 8f503c611dc..00000000000 --- a/src/main/java/appeng/api/networking/energy/IEnergyGridProvider.java +++ /dev/null @@ -1,123 +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.networking.energy; - -import java.util.Collection; - -import javax.annotation.Nonnegative; - -import appeng.api.config.Actionable; -import appeng.api.networking.IGridNodeService; - -/** - * internal use only. - */ -public interface IEnergyGridProvider extends IGridNodeService { - /** - * internal use only - * - * Can return a list of providers behind the current. - * - * An example would be something acting as proxy between different {@link IEnergyService}s. - * - * This can contain duplicate entries, AE will ensure that each provider is only visited once. - * - * internal use only - */ - - Collection providers(); - - /** - * internal use only - * - * Extracts the requested amount from the provider. - * - * This should never forward a call to another {@link IEnergyGridProvider}, instead return them via - * {@link IEnergyGridProvider#providers()} - * - * @return the used amount - */ - @Nonnegative - double extractProviderPower(@Nonnegative double amt, Actionable mode); - - /** - * Injects the offered amount into the provider. - * - * This should never forward a call to another {@link IEnergyGridProvider}, instead return them via - * {@link IEnergyGridProvider#providers()} - * - * internal use only - * - * @return the leftover amount - */ - @Nonnegative - double injectProviderPower(@Nonnegative double amt, Actionable mode); - - /** - * internal use only - * - * Returns the current demand of an provider. - * - * This should never forward a call to another {@link IEnergyGridProvider}, instead return them via - * {@link IEnergyGridProvider#providers()} - * - * - * @param d the max amount offered, the demand should never exceed it. - * @return the total amount demanded - */ - @Nonnegative - double getProviderEnergyDemand(@Nonnegative double d); - - /** - * internal use only - * - * AE currently uses this to enqueue the next visited provider. - * - * There is no guarantee that this works on in a perfect way. It can be limited to the returns of the past - * {@link IEnergyGridProvider#providers()}, but not any future one discovered by visiting further providers. - * - * E.g. inject into the the lowest one first or extract from the highest one. - * - * @return the current stored amount. - * - * - */ - @Nonnegative - double getProviderStoredEnergy(); - - /** - * internal use only - * - * AE currently uses this to enqueue the next visited provider. - * - * There is no guarantee that this works on in a perfect way. It can be limited to the returns of the past - * {@link IEnergyGridProvider#providers()}, but not any future one discovered by visiting further providers. - * - * E.g. inject into the the lowest one first or extract from the highest one. - * - * @return the maximum amount stored. - */ - @Nonnegative - double getProviderMaxEnergy(); -} diff --git a/src/main/java/appeng/api/networking/energy/IEnergyService.java b/src/main/java/appeng/api/networking/energy/IEnergyService.java deleted file mode 100644 index cf3d769592a..00000000000 --- a/src/main/java/appeng/api/networking/energy/IEnergyService.java +++ /dev/null @@ -1,117 +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.networking.energy; - -import javax.annotation.Nonnegative; - -import appeng.api.config.Actionable; -import appeng.api.networking.IGridService; - -/** - * AE's Power system. - */ -public interface IEnergyService extends IGridService, IEnergySource { - - /** - * Return the current calculated idle energy drain each tick, is used internally to drain power for each tick. It's - * the sum of the {@linkplain #getChannelPowerUsage() idle channel power usage} and the idle usages of the machines - * in the network. - */ - @Nonnegative - double getIdlePowerUsage(); - - /** - * @return the current idle power usage of channels - */ - @Nonnegative - double getChannelPowerUsage(); - - /** - * @return the average power drain over the past 10 ticks, includes idle usage during this time, and all use of - * extractPower. - */ - @Nonnegative - double getAvgPowerUsage(); - - /** - * @return the average energy injected into the system per tick, for the last 10 ticks. - */ - @Nonnegative - double getAvgPowerInjection(); - - /** - * AE maintains an idle draw of power separate from active power draw, it condenses this into a single operation - * that determines the networks "powered state" if the network is considered off-line, your machines should not - * function. - *

- * Nodes are notified via {@link appeng.api.networking.IGridNodeListener#onStateChanged} when this value changes. - * Most machines can simply test the value when they are about to perform work, without listening to this event. - * - * @return if the network is powered or not. - */ - boolean isNetworkPowered(); - - /** - * AE will accept any power, and store it, to maintain sanity please don't send more then 10,000 at a time. - *

- * IMPORTANT: Network power knows no bounds, for less spamy power flow, networks can store more then their allotted - * storage, however, it should be kept to a minimum, to help with this, this method returns the networks current - * OVERFLOW, this is not energy you can store some where else, its already stored in the network, you can extract it - * if you want, however it it owned by the network, this is different then IAEEnergyStore - *

- * Another important note, is that if a network that had overflow is deleted, its power is gone, this is one of the - * reasons why keeping overflow to a minimum is important. - * - * @param amt power to inject into the network - * @param mode should the action be simulated or performed? - * @return the amount of power that the network has OVER the limit. - */ - @Nonnegative - double injectPower(@Nonnegative double amt, Actionable mode); - - /** - * this is should be considered an estimate, and not relied upon for real calculations. - * - * @return estimated available power. - */ - @Nonnegative - double getStoredPower(); - - /** - * this is should be considered an estimate, and not relied upon for real calculations. - * - * @return estimated available power. - */ - @Nonnegative - double getMaxStoredPower(); - - /** - * Calculation will be capped at maxRequired, this improves performance by limiting the number of nodes needed to - * calculate the demand. - * - * @return Amount of power required to charge the grid, in AE. - */ - @Nonnegative - double getEnergyDemand(@Nonnegative double maxRequired); -} diff --git a/src/main/java/appeng/api/networking/energy/IEnergySource.java b/src/main/java/appeng/api/networking/energy/IEnergySource.java deleted file mode 100644 index 3f919262bc8..00000000000 --- a/src/main/java/appeng/api/networking/energy/IEnergySource.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.networking.energy; - -import javax.annotation.Nonnegative; - -import appeng.api.config.Actionable; -import appeng.api.config.PowerMultiplier; - -public interface IEnergySource { - - /** - * Extract power from the network. - * - * @param amt extracted power - * @param mode should the action be simulated or performed? - * - * @return returns extracted power. - */ - @Nonnegative - double extractAEPower(@Nonnegative double amt, Actionable mode, - PowerMultiplier usePowerMultiplier); -} diff --git a/src/main/java/appeng/api/networking/energy/IEnergyWatcher.java b/src/main/java/appeng/api/networking/energy/IEnergyWatcher.java deleted file mode 100644 index bdb4189f5d6..00000000000 --- a/src/main/java/appeng/api/networking/energy/IEnergyWatcher.java +++ /dev/null @@ -1,57 +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.networking.energy; - -import javax.annotation.Nonnegative; - -/** - * DO NOT IMPLEMENT. - * - * Will be injected when adding an {@link IEnergyWatcherNode} to a grid. - */ -public interface IEnergyWatcher { - /** - * Add a specific threshold to watch. - * - * Supports multiple values, duplicate ones will not be added. - * - * @param amount - * @return true, if successfully added. - */ - boolean add(@Nonnegative double amount); - - /** - * Remove a specific threshold from the watcher. - * - * @param amount - * @return true, if successfully removed. - */ - boolean remove(@Nonnegative double amount); - - /** - * Removes all thresholds and resets the watcher to a clean state. - */ - void reset(); - -} diff --git a/src/main/java/appeng/api/networking/energy/IEnergyWatcherNode.java b/src/main/java/appeng/api/networking/energy/IEnergyWatcherNode.java deleted file mode 100644 index f4e9126a382..00000000000 --- a/src/main/java/appeng/api/networking/energy/IEnergyWatcherNode.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.networking.energy; - -import appeng.api.networking.IGridNodeService; - -public interface IEnergyWatcherNode extends IGridNodeService { - - /** - * provides the IEnergyWatcher for this host, for the current network, is called when the hot changes networks. You - * do not need to clear your old watcher, its already been removed by the time this gets called. - * - * @param newWatcher new watcher - */ - void updateWatcher(IEnergyWatcher newWatcher); - - /** - * Called when a threshold is crossed. - * - * @param energyGrid grid - */ - void onThresholdPass(IEnergyService energyGrid); -} diff --git a/src/main/java/appeng/api/networking/events/GridPowerIdleChange.java b/src/main/java/appeng/api/networking/events/GridPowerIdleChange.java deleted file mode 100644 index 4507deafe0e..00000000000 --- a/src/main/java/appeng/api/networking/events/GridPowerIdleChange.java +++ /dev/null @@ -1,41 +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.networking.events; - -import appeng.api.networking.IGridNode; - -/** - * Implementers of a IGridBlock must post this event when your getIdlePowerUsage starts returning a new value, if you do - * not post this event the network will not change the idle draw. - * - * you do not need to send this event when your node is added / removed from the grid. - */ -public class GridPowerIdleChange extends GridEvent { - - public final IGridNode node; - - public GridPowerIdleChange(IGridNode nodeThatChanged) { - this.node = nodeThatChanged; - } -} diff --git a/src/main/java/appeng/api/networking/events/GridPowerStatusChange.java b/src/main/java/appeng/api/networking/events/GridPowerStatusChange.java deleted file mode 100644 index 7dd1848314c..00000000000 --- a/src/main/java/appeng/api/networking/events/GridPowerStatusChange.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2021 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.networking.events; - -/** - * Posted when the Grid loses power or is powered again. - */ -public class GridPowerStatusChange extends GridEvent { -} diff --git a/src/main/java/appeng/api/networking/events/GridPowerStorageStateChanged.java b/src/main/java/appeng/api/networking/events/GridPowerStorageStateChanged.java deleted file mode 100644 index 3f5594a5777..00000000000 --- a/src/main/java/appeng/api/networking/events/GridPowerStorageStateChanged.java +++ /dev/null @@ -1,58 +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.networking.events; - -import appeng.api.networking.energy.IAEPowerStorage; - -/** - * informs the network, that a {@link IAEPowerStorage} block that had either run, out of power, or was full, is no - * longer in that state. - * - * failure to post this event when your {@link IAEPowerStorage} changes state will result in your block not charging, or - * not-discharging. - * - * you do not need to send this event when your node is added / removed from the grid. - */ -public class GridPowerStorageStateChanged extends GridEvent { - - public final IAEPowerStorage storage; - public final PowerEventType type; - - public GridPowerStorageStateChanged(IAEPowerStorage t, PowerEventType y) { - this.storage = t; - this.type = y; - } - - public enum PowerEventType { - /** - * informs the network this block entity is ready to receive power again. - */ - REQUEST_POWER, - - /** - * informs the network this block entity is ready to provide power again. - */ - PROVIDE_POWER - } -} diff --git a/src/main/java/appeng/api/networking/events/GridSpatialEvent.java b/src/main/java/appeng/api/networking/events/GridSpatialEvent.java deleted file mode 100644 index ea0166aab1b..00000000000 --- a/src/main/java/appeng/api/networking/events/GridSpatialEvent.java +++ /dev/null @@ -1,74 +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.networking.events; - -import net.minecraft.core.BlockPos; -import net.minecraft.world.level.Level; - -/** - * An event that is posted whenever a spatial IO is active. - */ -public class GridSpatialEvent extends GridEvent { - /** - * The level in which the Spatial I/O block entity triggering this transition is located. - */ - public final Level spatialIoLevel; - /** - * The block position at which the Spatial I/O block entity triggering this transition is located. - */ - public final BlockPos spatialIoPos; - /** - * The energy in AE units needed to perform this transition. - */ - public final double spatialEnergyUsage; - private boolean preventTransition; - - /** - * @param spatialIoLevel Level where the Spatial IO is located - * @param spatialIoPos Position where the Spatial IO is located - * @param EnergyUsage ( the amount of energy that the SpatialIO uses) - */ - public GridSpatialEvent(Level spatialIoLevel, - BlockPos spatialIoPos, - double EnergyUsage) { - this.spatialIoLevel = spatialIoLevel; - this.spatialIoPos = spatialIoPos; - this.spatialEnergyUsage = EnergyUsage; - } - - /** - * Prevent the Spatial IO transition from happening. - */ - public void preventTransition() { - this.preventTransition = true; - } - - /** - * @return True if the transition into the spatial IO should not be allowed. - */ - public boolean isTransitionPrevented() { - return preventTransition; - } - -} diff --git a/src/main/java/appeng/api/networking/spatial/ISpatialService.java b/src/main/java/appeng/api/networking/spatial/ISpatialService.java deleted file mode 100644 index 70db6313a56..00000000000 --- a/src/main/java/appeng/api/networking/spatial/ISpatialService.java +++ /dev/null @@ -1,68 +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.networking.spatial; - -import net.minecraft.core.BlockPos; -import net.minecraft.world.level.Level; - -import appeng.api.networking.IGridService; - -public interface ISpatialService extends IGridService { - - /** - * @return true if a region is defined at all, it doesn't have to be valid, but all points must be in the same - * level. - */ - boolean hasRegion(); - - /** - * @return true if the region defined is valid according to all rules. - */ - boolean isValidRegion(); - - /** - * @return The level that the spatial region is in. - */ - Level getLevel(); - - /** - * @return the minimum anchor point for the spatial region. - */ - BlockPos getMin(); - - /** - * @return the maximum anchor point for the spatial region. - */ - BlockPos getMax(); - - /** - * @return how many AE units are required to preform the activation - */ - long requiredPower(); - - /** - * @return current 100% - 0% efficiency. - */ - float currentEfficiency(); -} diff --git a/src/main/java/appeng/api/parts/IPartHost.java b/src/main/java/appeng/api/parts/IPartHost.java index 5c1415392c0..d271e7f7104 100644 --- a/src/main/java/appeng/api/parts/IPartHost.java +++ b/src/main/java/appeng/api/parts/IPartHost.java @@ -44,12 +44,6 @@ * Do Not Implement */ public interface IPartHost extends ICustomCableConnection { - - /** - * @return the facade container - */ - IFacadeContainer getFacadeContainer(); - /** * Get a part attached to the host based on the location it's attached to. * diff --git a/src/main/java/appeng/api/parts/SelectedPart.java b/src/main/java/appeng/api/parts/SelectedPart.java index ed254a6aaf9..04a263dfc89 100644 --- a/src/main/java/appeng/api/parts/SelectedPart.java +++ b/src/main/java/appeng/api/parts/SelectedPart.java @@ -38,11 +38,6 @@ public class SelectedPart { */ public final IPart part; - /** - * facade part. - */ - public final IFacadePart facade; - /** * side the part is mounted too, or null for cables. */ @@ -51,19 +46,11 @@ public class SelectedPart { public SelectedPart() { this.part = null; - this.facade = null; this.side = null; } public SelectedPart(IPart part, Direction side) { this.part = part; - this.facade = null; - this.side = side; - } - - public SelectedPart(IFacadePart facade, Direction side) { - this.part = null; - this.facade = facade; this.side = side; } } diff --git a/src/main/java/appeng/api/stacks/AEItemKey.java b/src/main/java/appeng/api/stacks/AEItemKey.java index 592697ed812..b38b4db988e 100644 --- a/src/main/java/appeng/api/stacks/AEItemKey.java +++ b/src/main/java/appeng/api/stacks/AEItemKey.java @@ -1,9 +1,7 @@ package appeng.api.stacks; -import java.lang.ref.WeakReference; import java.util.List; import java.util.Objects; -import java.util.WeakHashMap; import org.jetbrains.annotations.Nullable; @@ -26,16 +24,17 @@ public final class AEItemKey extends AEKey { private final Item item; - private final InternedTag internedTag; + @Nullable + private final CompoundTag tag; private final int hashCode; private final int cachedDamage; - private AEItemKey(Item item, InternedTag internedTag) { - super(Platform.getItemDisplayName(item, internedTag.tag)); + private AEItemKey(Item item, @Nullable CompoundTag tag) { + super(Platform.getItemDisplayName(item, tag)); this.item = item; - this.internedTag = internedTag; - this.hashCode = item.hashCode() * 31 + internedTag.hashCode; - if (internedTag.tag != null && internedTag.tag.get("Damage") instanceof NumericTag numericTag) { + this.tag = tag; + this.hashCode = Objects.hash(item, tag); + if (this.tag != null && tag.get("Damage") instanceof NumericTag numericTag) { this.cachedDamage = numericTag.getAsInt(); } else { this.cachedDamage = 0; @@ -44,6 +43,7 @@ private AEItemKey(Item item, InternedTag internedTag) { @Nullable public static AEItemKey of(ItemVariant variant) { + if (variant.isBlank()) { return null; } @@ -87,7 +87,8 @@ public boolean equals(Object o) { if (o == null || getClass() != o.getClass()) return false; AEItemKey aeItemKey = (AEItemKey) o; - return item == aeItemKey.item && internedTag == aeItemKey.internedTag; + // The hash code comparison is a fast-fail for two objects with different NBT or items + return hashCode == aeItemKey.hashCode && item == aeItemKey.item && Objects.equals(tag, aeItemKey.tag); } @Override @@ -100,11 +101,12 @@ public static AEItemKey of(ItemLike item) { } public static AEItemKey of(ItemLike item, @Nullable CompoundTag tag) { - return new AEItemKey(item.asItem(), InternedTag.of(tag, false)); + // Do a defensive copy of the tag if we're not sure that we can take ownership + return new AEItemKey(item.asItem(), tag != null ? tag.copy() : null); } public boolean matches(ItemStack stack) { - return !stack.isEmpty() && stack.is(item) && Objects.equals(stack.getTag(), internedTag.tag); + return !stack.isEmpty() && stack.is(item) && Objects.equals(stack.getTag(), tag); } public ItemStack toStack() { @@ -144,8 +146,8 @@ public CompoundTag toTag() { CompoundTag result = new CompoundTag(); result.putString("id", Registry.ITEM.getKey(item).toString()); - if (internedTag.tag != null) { - result.put("tag", internedTag.tag.copy()); + if (tag != null) { + result.put("tag", tag.copy()); } return result; @@ -178,7 +180,7 @@ public ResourceLocation getId() { } public ItemVariant toVariant() { - return ItemVariant.of(item, internedTag.tag); + return ItemVariant.of(item, tag); } /** @@ -186,16 +188,16 @@ public ItemVariant toVariant() { */ @Nullable public CompoundTag getTag() { - return internedTag.tag; + return tag; } @Nullable public CompoundTag copyTag() { - return internedTag.tag != null ? internedTag.tag.copy() : null; + return tag != null ? tag.copy() : null; } public boolean hasTag() { - return internedTag.tag != null; + return tag != null; } @Override @@ -228,7 +230,7 @@ public boolean isTagged(TagKey tag) { * @return True if the item represented by this key is damaged. */ public boolean isDamaged() { - return cachedDamage > 0; + return tag != null && tag.getInt(ItemStack.TAG_DAMAGE) > 0; } @Override @@ -236,7 +238,7 @@ public void writeToPacket(FriendlyByteBuf data) { data.writeVarInt(Item.getId(item)); CompoundTag compoundTag = null; if (item.canBeDepleted() || item.shouldOverrideMultiplayerNbt()) { - compoundTag = internedTag.tag; + compoundTag = tag; } data.writeNbt(compoundTag); } @@ -245,7 +247,7 @@ public static AEItemKey fromPacket(FriendlyByteBuf data) { int i = data.readVarInt(); var item = Item.byId(i); var tag = data.readNbt(); - return new AEItemKey(item, InternedTag.of(tag, true)); + return new AEItemKey(item, tag); } @Override @@ -253,63 +255,6 @@ public String toString() { var id = Registry.ITEM.getKey(item); String idString = id != Registry.ITEM.getDefaultKey() ? id.toString() : item.getClass().getName() + "(unregistered)"; - return internedTag.tag == null ? idString : idString + " (+tag)"; - } - - private static final class InternedTag { - private static final InternedTag EMPTY = new InternedTag(null); - - private static final WeakHashMap> INTERNED = new WeakHashMap<>(); - - private final CompoundTag tag; - private final int hashCode; - - InternedTag(CompoundTag tag) { - this.tag = tag; - this.hashCode = Objects.hashCode(tag); - } - - @Override - public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; - InternedTag internedTag = (InternedTag) o; - return Objects.equals(tag, internedTag.tag); - } - - @Override - public int hashCode() { - return hashCode; - } - - public static InternedTag of(@Nullable CompoundTag tag, boolean giveOwnership) { - if (tag == null) { - return EMPTY; - } - - synchronized (AEItemKey.class) { - var searchHolder = new InternedTag(tag); - var weakRef = INTERNED.get(searchHolder); - InternedTag ret = null; - - if (weakRef != null) { - ret = weakRef.get(); - } - - if (ret == null) { - // Copy the tag if we don't get to have ownership of it - if (giveOwnership) { - ret = searchHolder; - } else { - ret = new InternedTag(tag.copy()); - } - INTERNED.put(ret, new WeakReference<>(ret)); - } - - return ret; - } - } + return tag == null ? idString : idString + " (+tag)"; } } diff --git a/src/main/java/appeng/api/storage/StorageCells.java b/src/main/java/appeng/api/storage/StorageCells.java deleted file mode 100644 index a6c59f4fe8b..00000000000 --- a/src/main/java/appeng/api/storage/StorageCells.java +++ /dev/null @@ -1,162 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2021 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.storage; - -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; - -import javax.annotation.Nullable; -import javax.annotation.concurrent.ThreadSafe; - -import com.google.common.base.Preconditions; - -import net.minecraft.world.item.ItemStack; - -import appeng.api.storage.cells.IBasicCellItem; -import appeng.api.storage.cells.ICellGuiHandler; -import appeng.api.storage.cells.ICellHandler; -import appeng.api.storage.cells.ISaveProvider; -import appeng.api.storage.cells.StorageCell; - -/** - * Storage Cell Registry, used for specially implemented cells, if you just want to make a item act like a cell, or new - * cell with different bytes, you should probably consider implementing {@link IBasicCellItem} on your item instead. - */ -@ThreadSafe -public final class StorageCells { - - private static final List handlers = new ArrayList<>(); - private static final List guiHandlers = new ArrayList<>(); - - private StorageCells() { - } - - /** - * Register a new handler. - *

- * Never be call before {@link net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent} was handled by AE2. Will - * throw an exception otherwise. - * - * @param handler cell handler - */ - public static synchronized void addCellHandler(ICellHandler handler) { - Objects.requireNonNull(handler, "Called before FMLCommonSetupEvent."); - Preconditions.checkArgument(!handlers.contains(handler), - "Tried to register the same handler instance twice."); - - handlers.add(handler); - } - - /** - * Register a new handler - * - * @param handler cell gui handler - */ - public static synchronized void addCellGuiHandler(ICellGuiHandler handler) { - guiHandlers.add(handler); - } - - /** - * return true, if you can get a InventoryHandler for the item passed. - * - * @param is to be checked item - * @return true if the provided item, can be handled by a handler in AE, ( AE May choose to skip this and just get - * the handler instead. ) - */ - public static synchronized boolean isCellHandled(ItemStack is) { - if (is.isEmpty()) { - return false; - } - for (ICellHandler ch : handlers) { - if (ch.isCell(is)) { - return true; - } - } - return false; - } - - /** - * get the handler, for the requested item. - * - * @param is to be checked item - * @return the handler registered for this item type. - */ - @Nullable - public static synchronized ICellHandler getHandler(ItemStack is) { - if (is.isEmpty()) { - return null; - } - for (ICellHandler ch : handlers) { - if (ch.isCell(is)) { - return ch; - } - } - return null; - } - - /** - * get the handler, for the requested channel. - * - * @param is ItemStack - * @return the handler registered for this channel. - */ - @Nullable - public static synchronized ICellGuiHandler getGuiHandler(ItemStack is) { - ICellGuiHandler fallBack = null; - - for (ICellGuiHandler ch : guiHandlers) { - if (ch.isSpecializedFor(is)) { - return ch; - } - - if (fallBack == null) { - fallBack = ch; - } - } - return fallBack; - } - - /** - * Returns the inventory for the provided storage cell item by querying all registered handlers. - * - * @param is item with inventory handler - * @param host can be null. If provided, the host is responsible for persisting the cell content. - * @return The cell inventory, or null if there isn't one. - */ - @Nullable - public static synchronized StorageCell getCellInventory(ItemStack is, @Nullable ISaveProvider host) { - if (is.isEmpty()) { - return null; - } - for (var ch : handlers) { - var inventory = ch.getCellInventory(is, host); - if (inventory != null) { - return inventory; - } - } - return null; - } - -} diff --git a/src/main/java/appeng/api/storage/StorageHelper.java b/src/main/java/appeng/api/storage/StorageHelper.java index 659cbd8ec13..f4be5fe6487 100644 --- a/src/main/java/appeng/api/storage/StorageHelper.java +++ b/src/main/java/appeng/api/storage/StorageHelper.java @@ -27,78 +27,50 @@ import com.google.common.primitives.Ints; -import net.minecraft.nbt.CompoundTag; import appeng.api.config.Actionable; -import appeng.api.config.PowerMultiplier; -import appeng.api.networking.crafting.ICraftingLink; -import appeng.api.networking.crafting.ICraftingRequester; -import appeng.api.networking.energy.IEnergySource; import appeng.api.networking.security.IActionSource; import appeng.api.stacks.AEItemKey; import appeng.api.stacks.AEKey; import appeng.core.stats.AeStats; -import appeng.crafting.CraftingLink; public final class StorageHelper { private StorageHelper() { } /** - * load a crafting link from nbt data. + * Extracts items from a {@link MEStorage} * - * @param data to be loaded data - * @return crafting link - */ - public static ICraftingLink loadCraftingLink(CompoundTag data, ICraftingRequester req) { - Objects.requireNonNull(data); - Objects.requireNonNull(req); - - return new CraftingLink(data, req); - } - - /** - * Extracts items from a {@link MEStorage} respecting power requirements. - * - * @param energy Energy source. * @param inv Inventory to extract from. * @param request Requested item and count. * @param src Action source. * @return extracted items or {@code null} of nothing was extracted. */ - public static long poweredExtraction(IEnergySource energy, MEStorage inv, + public static long extract(MEStorage inv, AEKey request, long amount, IActionSource src) { - return poweredExtraction(energy, inv, request, amount, src, Actionable.MODULATE); + return extract(inv, request, amount, src, Actionable.MODULATE); } /** - * Extracts items from a {@link MEStorage} respecting power requirements. + * Extracts items from a {@link MEStorage} * - * @param energy Energy source. * @param inv Inventory to extract from. * @param request Requested item and count. * @param src Action source. * @param mode Simulate or modulate * @return extracted items or {@code null} of nothing was extracted. */ - public static long poweredExtraction(IEnergySource energy, MEStorage inv, + public static long extract(MEStorage inv, AEKey request, long amount, IActionSource src, Actionable mode) { - Objects.requireNonNull(energy, "energy"); Objects.requireNonNull(inv, "inv"); Objects.requireNonNull(request, "request"); Objects.requireNonNull(src, "src"); Objects.requireNonNull(mode, "mode"); - var retrieved = inv.extract(request, amount, Actionable.SIMULATE, src); - - var energyFactor = Math.max(1.0, request.getAmountPerOperation()); - var availablePower = energy.extractAEPower(retrieved / energyFactor, Actionable.SIMULATE, - PowerMultiplier.CONFIG); - var itemToExtract = Math.min((long) (availablePower * energyFactor + 0.9), retrieved); + var itemToExtract = inv.extract(request, amount, Actionable.SIMULATE, src); if (itemToExtract > 0) { if (mode == Actionable.MODULATE) { - energy.extractAEPower(retrieved / energyFactor, Actionable.MODULATE, PowerMultiplier.CONFIG); var ret = inv.extract(request, itemToExtract, Actionable.MODULATE, src); if (ret != 0 && request instanceof AEItemKey) { @@ -116,32 +88,29 @@ public static long poweredExtraction(IEnergySource energy, MEStorage inv, } /** - * Inserts items into a {@link MEStorage} respecting power requirements. + * Inserts items into a {@link MEStorage} * - * @param energy Energy source. * @param inv Inventory to insert into. * @param input Items to insert. * @param src Action source. * @return the number of items inserted. */ - public static long poweredInsert(IEnergySource energy, MEStorage inv, + public static long insert(MEStorage inv, AEKey input, long amount, IActionSource src) { - return poweredInsert(energy, inv, input, amount, src, Actionable.MODULATE); + return insert(inv, input, amount, src, Actionable.MODULATE); } /** - * Inserts items into a {@link MEStorage} respecting power requirements. + * Inserts items into a {@link MEStorage} * - * @param energy Energy source. * @param inv Inventory to insert into. * @param input Items to insert. * @param src Action source. * @param mode Simulate or modulate * @return the number of items inserted. */ - public static long poweredInsert(IEnergySource energy, MEStorage inv, AEKey input, long amount, + public static long insert(MEStorage inv, AEKey input, long amount, IActionSource src, Actionable mode) { - Objects.requireNonNull(energy); Objects.requireNonNull(inv); Objects.requireNonNull(input); Objects.requireNonNull(src); @@ -152,17 +121,7 @@ public static long poweredInsert(IEnergySource energy, MEStorage inv, AEKey inpu return 0; } - final double energyFactor = Math.max(1.0, input.getAmountPerOperation()); - final double availablePower = energy.extractAEPower(amount / energyFactor, Actionable.SIMULATE, - PowerMultiplier.CONFIG); - amount = Math.min((long) (availablePower * energyFactor + 0.9), amount); - - if (amount <= 0) { - return 0; - } - if (mode == Actionable.MODULATE) { - energy.extractAEPower(amount / energyFactor, Actionable.MODULATE, PowerMultiplier.CONFIG); var inserted = inv.insert(input, amount, Actionable.MODULATE, src); if (input instanceof AEItemKey) { diff --git a/src/main/java/appeng/api/storage/cells/CellState.java b/src/main/java/appeng/api/storage/cells/CellState.java deleted file mode 100644 index 21705ea6bb7..00000000000 --- a/src/main/java/appeng/api/storage/cells/CellState.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2020 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.storage.cells; - -/** - * @author yueh - */ -public enum CellState { - /** - * No cell at all - */ - ABSENT(0), - - /** - * A cell without anything stored - */ - EMPTY(0x00FF00), - - /** - * Stored something, but neither types nor totally full - */ - NOT_EMPTY(0x00AAFF), - - /** - * Available types exhausted - */ - TYPES_FULL(0xFFAA00), - - /** - * Full cell, technically could have free types - */ - FULL(0xFF0000); - - /** - * A color indicating this state. - */ - private final int stateColor; - - CellState(int stateColor) { - this.stateColor = stateColor; - } - - /** - * @return A color representative of this state. Used for the drive LEDs for example. - */ - public int getStateColor() { - return stateColor; - } -} diff --git a/src/main/java/appeng/api/storage/cells/IBasicCellItem.java b/src/main/java/appeng/api/storage/cells/IBasicCellItem.java deleted file mode 100644 index 1d100b5d7b2..00000000000 --- a/src/main/java/appeng/api/storage/cells/IBasicCellItem.java +++ /dev/null @@ -1,131 +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.storage.cells; - -import java.util.List; -import java.util.Optional; - -import com.google.common.base.Preconditions; - -import net.minecraft.network.chat.Component; -import net.minecraft.world.inventory.tooltip.TooltipComponent; -import net.minecraft.world.item.ItemStack; - -import appeng.api.stacks.AEKey; -import appeng.api.stacks.AEKeyType; -import appeng.me.cells.BasicCellHandler; - -/** - * Implement this on any item to register a "basic cell", which is a cell that works similarly to AE2's own item and - * fluid cells. There is no need to register an {@link ICellHandler} for such an item. AE2 automatically handles the - * internals and NBT data, which is both nice, and bad for you! - *

- * The standard AE implementation also only provides 1-63 Types. - */ -public interface IBasicCellItem extends ICellWorkbenchItem { - /** - * Basic cell items are limited to a single {@link AEKeyType}. - */ - AEKeyType getKeyType(); - - /** - * The number of bytes that can be stored on this type of storage cell. - *

- * It wont work if the return is not a multiple of 8. The limit is ({@link Integer#MAX_VALUE} + 1) / 8. - * - * @param cellItem item - * @return number of bytes - */ - int getBytes(ItemStack cellItem); - - /** - * Determines the number of bytes used for any type included on the cell. - * - * @param cellItem item - * @return number of bytes - */ - int getBytesPerType(ItemStack cellItem); - - /** - * Must be between 1 and 63, indicates how many types can be stored on this type of storage cell. - * - * @param cellItem item - * @return number of types - */ - int getTotalTypes(ItemStack cellItem); - - /** - * Allows you to fine tune which items are allowed on a given cell, if you don't care, just return false; As the - * handler for this type of cell is still the default cells, the normal AE black list is also applied. - * - * @param cellItem item - * @param requestedAddition requested addition - * @return true to preventAdditionOfItem - */ - default boolean isBlackListed(ItemStack cellItem, AEKey requestedAddition) { - return false; - } - - /** - * Allows you to specify if this storage cell can be stored inside other storage cells, only set this for special - * items like the matter cannon that are not general purpose storage. - * - * @return true if the storage cell can be stored inside other storage cells, this is generally false, except for - * certain situations such as the matter cannon. - */ - default boolean storableInStorageCell() { - return false; - } - - /** - * Allows an item to selectively enable or disable its status as a storage cell. - * - * @param i item - * @return if the ItemStack should currently be usable as a storage cell. - */ - default boolean isStorageCell(ItemStack i) { - return true; - } - - /** - * @return drain in ae/t this storage cell will use. - */ - double getIdleDrain(); - - /** - * Convenient helper to append useful tooltip information. - */ - default void addCellInformationToTooltip(ItemStack is, List lines) { - Preconditions.checkArgument(is.getItem() == this); - BasicCellHandler.INSTANCE.addCellInformationToTooltip(is, lines); - } - - /** - * Helper to get the additional tooltip image line showing the content/filter/upgrades. - */ - default Optional getCellTooltipImage(ItemStack is) { - Preconditions.checkArgument(is.getItem() == this); - return BasicCellHandler.INSTANCE.getTooltipImage(is); - } -} diff --git a/src/main/java/appeng/api/storage/cells/ICellGuiHandler.java b/src/main/java/appeng/api/storage/cells/ICellGuiHandler.java deleted file mode 100644 index f6ff42f0b44..00000000000 --- a/src/main/java/appeng/api/storage/cells/ICellGuiHandler.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2021 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.storage.cells; - -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemStack; - -import appeng.api.implementations.blockentities.IChestOrDrive; - -/** - * This interface is used by the ME Chest to open the appropriate GUI when a storage cell is inserted into the chest, - * and the player right-clicks the terminal screen on the chest. Since any storage cell may be inserted into the chest, - * this can potentially open a terminal screen provided by an addon, and this interface allows addons to facilitate - * that. - * - * @see appeng.api.storage.StorageCells - */ -public interface ICellGuiHandler { - /** - * Return true to prioritize this handler for the provided {@link ItemStack}. - * - * @param cell Cell ItemStack - * @return True, if specialized else false. - */ - boolean isSpecializedFor(ItemStack cell); - - /** - * Called when the storage cell is placed in an ME Chest and the user tries to open the terminal side, if your item - * is not available via ME Chests simply tell the user they can't use it, or something, otherwise you should open - * your gui and display the cell to the user. - * - * @param player player opening chest gui - * @param chest to be opened chest - * @param cellHandler cell handler - * @param cell the storage cell - */ - void openChestGui(Player player, IChestOrDrive chest, ICellHandler cellHandler, ItemStack cell); -} diff --git a/src/main/java/appeng/api/storage/cells/ICellHandler.java b/src/main/java/appeng/api/storage/cells/ICellHandler.java deleted file mode 100644 index 1b85b795852..00000000000 --- a/src/main/java/appeng/api/storage/cells/ICellHandler.java +++ /dev/null @@ -1,59 +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.storage.cells; - -import javax.annotation.Nullable; - -import net.minecraft.world.item.ItemStack; - -/** - * Implementations of this interface provide AE2 with a way to interact with storage cells that may be represented by - * arbitrary {@link ItemStack} - * - * @see appeng.api.storage.StorageCells - */ -public interface ICellHandler { - - /** - * return true if the provided item is handled by your cell handler. ( AE May choose to skip this method, and just - * request a handler ) - * - * @param is to be checked item - * @return return true, if getCellHandler will not return null. - */ - boolean isCell(ItemStack is); - - /** - * Returns the cell's inventory or null if the item stack is not handled by this handler, or it currently doesn't - * want to act as a storage cell. - * - * @param is a storage cell item. - * @param host anytime the contents of your storage cell changes it should use this to request a save, please note, - * this value can be null. If provided, the host is responsible for persisting the cell content. - * @return The cell inventory or null if the stack is not a cell supported by this handler. - */ - @Nullable - StorageCell getCellInventory(ItemStack is, @Nullable ISaveProvider host); - -} diff --git a/src/main/java/appeng/api/storage/cells/ICellWorkbenchItem.java b/src/main/java/appeng/api/storage/cells/ICellWorkbenchItem.java deleted file mode 100644 index 19b2a38da59..00000000000 --- a/src/main/java/appeng/api/storage/cells/ICellWorkbenchItem.java +++ /dev/null @@ -1,64 +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.storage.cells; - -import net.minecraft.world.item.ItemStack; - -import appeng.api.config.FuzzyMode; -import appeng.api.upgrades.IUpgradeableItem; -import appeng.util.ConfigInventory; - -public interface ICellWorkbenchItem extends IUpgradeableItem { - /** - * Determines whether or not the item should be treated as a cell and allow for configuration via a cell workbench. - * By default, any such item with either a filtering or upgrade inventory is thus assumed to be editable. - * - * @param is item - * @return true if the item should be editable in the cell workbench. - */ - default boolean isEditable(ItemStack is) { - return getConfigInventory(is).size() > 0 || getUpgrades(is).size() > 0; - } - - /** - * Used to extract, or mirror the contents of the work bench onto the cell. - *

- * This should not exceed 63 slots. Any more than that might cause issues. - *

- * onInventoryChange will be called when saving is needed. - */ - default ConfigInventory getConfigInventory(ItemStack is) { - return ConfigInventory.EMPTY_TYPES; - } - - /** - * @return the current fuzzy status. - */ - FuzzyMode getFuzzyMode(ItemStack is); - - /** - * sets the setting on the cell. - */ - void setFuzzyMode(ItemStack is, FuzzyMode fzMode); -} diff --git a/src/main/java/appeng/api/storage/cells/ISaveProvider.java b/src/main/java/appeng/api/storage/cells/ISaveProvider.java deleted file mode 100644 index 533093141a1..00000000000 --- a/src/main/java/appeng/api/storage/cells/ISaveProvider.java +++ /dev/null @@ -1,35 +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.storage.cells; - -/** - * Tells the cell provider that changes have been made and the cell must be persisted - */ -@FunctionalInterface -public interface ISaveProvider { - /** - * Cell has changed and needs to be persisted. - */ - void saveChanges(); -} diff --git a/src/main/java/appeng/api/storage/cells/StorageCell.java b/src/main/java/appeng/api/storage/cells/StorageCell.java deleted file mode 100644 index 61b71a78bd0..00000000000 --- a/src/main/java/appeng/api/storage/cells/StorageCell.java +++ /dev/null @@ -1,46 +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.storage.cells; - -import appeng.api.storage.MEStorage; - -/** - * Represents the most general possible cell inventory. Register a {@link ICellHandler} to provide custom subclasses. - */ -public interface StorageCell extends MEStorage { - /** - * Return the current status of the cell. - */ - CellState getStatus(); - - /** - * Return the idle drain of the cell: how many AE/t it uses passively. - */ - double getIdleDrain(); - - /** - * Tells the cell to persist to NBT. - */ - void persist(); -} diff --git a/src/main/java/appeng/api/upgrades/Upgrades.java b/src/main/java/appeng/api/upgrades/Upgrades.java index 95535663bdd..1d476976ccc 100644 --- a/src/main/java/appeng/api/upgrades/Upgrades.java +++ b/src/main/java/appeng/api/upgrades/Upgrades.java @@ -22,7 +22,6 @@ import appeng.core.localization.GuiText; import appeng.core.localization.Tooltips; -import appeng.items.materials.EnergyCardItem; import appeng.items.materials.UpgradeCardItem; /** @@ -90,20 +89,6 @@ public static synchronized int getMaxInstallable(ItemLike card, ItemLike upgrada return 0; } - /** - * Returns a cumulative energy multiplier based on the amount of "energy cards" fitted onto a tool. Returns 0 if no - * such cards exist within the tool's upgrade inventory. - */ - public static int getEnergyCardMultiplier(IUpgradeInventory upgrades) { - int multiplier = 0; - for (var card : upgrades) { - if (card.getItem() instanceof EnergyCardItem ec) { - multiplier += ec.getEnergyMultiplier(); - } - } - return multiplier; - } - /** * Creates a new upgrade item which can be used to receive automated tooltips and allow custom upgrades to be added * to AE2's toolbelt in the network tool. diff --git a/src/main/java/appeng/block/AEBaseBlockItem.java b/src/main/java/appeng/block/AEBaseBlockItem.java index 2fd0320d38b..aa613c93787 100644 --- a/src/main/java/appeng/block/AEBaseBlockItem.java +++ b/src/main/java/appeng/block/AEBaseBlockItem.java @@ -36,7 +36,6 @@ import appeng.api.util.IOrientable; import appeng.api.util.IOrientableBlock; -import appeng.block.misc.LightDetectorBlock; import appeng.block.networking.WirelessBlock; import appeng.blockentity.AEBaseBlockEntity; @@ -80,14 +79,7 @@ public InteractionResult place(BlockPlaceContext context) { Player player = context.getPlayer(); if (this.blockType instanceof AEBaseEntityBlock) { - if (this.blockType instanceof LightDetectorBlock) { - up = side; - if (up == Direction.UP || up == Direction.DOWN) { - forward = Direction.SOUTH; - } else { - forward = Direction.UP; - } - } else if (this.blockType instanceof WirelessBlock) { + if (this.blockType instanceof WirelessBlock) { forward = side; if (forward == Direction.UP || forward == Direction.DOWN) { up = Direction.SOUTH; @@ -129,7 +121,7 @@ public InteractionResult place(BlockPlaceContext context) { return result; } - if (this.blockType instanceof AEBaseEntityBlock && !(this.blockType instanceof LightDetectorBlock)) { + if (this.blockType instanceof AEBaseEntityBlock) { final AEBaseBlockEntity blockEntity = ((AEBaseEntityBlock) this.blockType).getBlockEntity( context.getLevel(), context.getClickedPos()); diff --git a/src/main/java/appeng/block/AEBaseEntityBlock.java b/src/main/java/appeng/block/AEBaseEntityBlock.java index a67f5ee0ddf..8eb8e541c2c 100644 --- a/src/main/java/appeng/block/AEBaseEntityBlock.java +++ b/src/main/java/appeng/block/AEBaseEntityBlock.java @@ -51,7 +51,6 @@ import appeng.block.networking.CableBusBlock; import appeng.blockentity.AEBaseBlockEntity; import appeng.blockentity.AEBaseInvBlockEntity; -import appeng.items.tools.MemoryCardItem; import appeng.util.InteractionUtil; import appeng.util.Platform; import appeng.util.SettingsFrom; @@ -193,37 +192,6 @@ public InteractionResult use(BlockState state, Level level, BlockPos pos, Player ItemStack heldItem; if (player != null && !player.getItemInHand(hand).isEmpty()) { heldItem = player.getItemInHand(hand); - - if (heldItem.getItem() instanceof IMemoryCard memoryCard && !(this instanceof CableBusBlock)) { - final AEBaseBlockEntity blockEntity = this.getBlockEntity(level, pos); - - if (blockEntity == null) { - return InteractionResult.FAIL; - } - - final String name = this.getDescriptionId(); - - if (InteractionUtil.isInAlternateUseMode(player)) { - var data = new CompoundTag(); - blockEntity.exportSettings(SettingsFrom.MEMORY_CARD, data, player); - if (!data.isEmpty()) { - memoryCard.setMemoryCardContents(heldItem, name, data); - memoryCard.notifyUser(player, MemoryCardMessages.SETTINGS_SAVED); - } - } else { - final String savedName = memoryCard.getSettingsName(heldItem); - final CompoundTag data = memoryCard.getData(heldItem); - - if (this.getDescriptionId().equals(savedName)) { - blockEntity.importSettings(SettingsFrom.MEMORY_CARD, data, player); - memoryCard.notifyUser(player, MemoryCardMessages.SETTINGS_LOADED); - } else { - MemoryCardItem.importGenericSettingsAndNotify(blockEntity, data, player); - } - } - - return InteractionResult.sidedSuccess(level.isClientSide()); - } } return this.onActivated(level, pos, player, hand, player.getItemInHand(hand), hit); diff --git a/src/main/java/appeng/block/crafting/AbstractCraftingUnitBlock.java b/src/main/java/appeng/block/crafting/AbstractCraftingUnitBlock.java deleted file mode 100644 index 28b1897a9df..00000000000 --- a/src/main/java/appeng/block/crafting/AbstractCraftingUnitBlock.java +++ /dev/null @@ -1,99 +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.crafting; - -import net.minecraft.core.BlockPos; -import net.minecraft.world.InteractionHand; -import net.minecraft.world.InteractionResult; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockBehaviour; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.state.StateDefinition.Builder; -import net.minecraft.world.level.block.state.properties.BooleanProperty; -import net.minecraft.world.phys.BlockHitResult; - -import appeng.block.AEBaseEntityBlock; -import appeng.blockentity.crafting.CraftingBlockEntity; -import appeng.menu.MenuOpener; -import appeng.menu.locator.MenuLocators; -import appeng.menu.me.crafting.CraftingCPUMenu; -import appeng.util.InteractionUtil; - -public abstract class AbstractCraftingUnitBlock extends AEBaseEntityBlock { - public static final BooleanProperty FORMED = BooleanProperty.create("formed"); - public static final BooleanProperty POWERED = BooleanProperty.create("powered"); - - public final ICraftingUnitType type; - - public AbstractCraftingUnitBlock(BlockBehaviour.Properties props, ICraftingUnitType type) { - super(props); - this.type = type; - this.registerDefaultState(defaultBlockState().setValue(FORMED, false).setValue(POWERED, false)); - } - - @Override - protected void createBlockStateDefinition(Builder builder) { - super.createBlockStateDefinition(builder); - builder.add(POWERED); - builder.add(FORMED); - } - - @Override - public void neighborChanged(BlockState state, Level level, BlockPos pos, Block blockIn, - BlockPos fromPos, boolean isMoving) { - final CraftingBlockEntity cp = this.getBlockEntity(level, pos); - if (cp != null) { - cp.updateMultiBlock(fromPos); - } - } - - @Override - public void onRemove(BlockState state, Level level, BlockPos pos, BlockState newState, boolean isMoving) { - if (newState.getBlock() == state.getBlock()) { - return; // Just a block state change - } - - final CraftingBlockEntity cp = this.getBlockEntity(level, pos); - if (cp != null) { - cp.breakCluster(); - } - - super.onRemove(state, level, pos, newState, isMoving); - } - - @Override - public InteractionResult use(BlockState state, Level level, BlockPos pos, Player p, InteractionHand hand, - BlockHitResult hit) { - final CraftingBlockEntity tg = this.getBlockEntity(level, pos); - - if (tg != null && !InteractionUtil.isInAlternateUseMode(p) && tg.isFormed() && tg.isActive()) { - if (!level.isClientSide()) { - hit.getDirection(); - MenuOpener.open(CraftingCPUMenu.TYPE, p, - MenuLocators.forBlockEntity(tg)); - } - - return InteractionResult.sidedSuccess(level.isClientSide()); - } - - return super.use(state, level, pos, p, hand, hit); - } -} diff --git a/src/main/java/appeng/block/crafting/CraftingBlockItem.java b/src/main/java/appeng/block/crafting/CraftingBlockItem.java deleted file mode 100644 index 59ce08a9800..00000000000 --- a/src/main/java/appeng/block/crafting/CraftingBlockItem.java +++ /dev/null @@ -1,67 +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.crafting; - -import java.util.function.Supplier; - -import net.minecraft.world.InteractionHand; -import net.minecraft.world.InteractionResultHolder; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.ItemLike; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.Block; - -import appeng.block.AEBaseBlockItem; -import appeng.core.AEConfig; -import appeng.core.definitions.AEBlocks; -import appeng.util.InteractionUtil; - -/** - * Item that allows uncrafting CPU parts by disassembling them back into the crafting unit and the extra item. - */ -public class CraftingBlockItem extends AEBaseBlockItem { - /** - * This can be retrieved when disassembling the crafting unit. - */ - protected final Supplier disassemblyExtra; - - public CraftingBlockItem(Block id, Item.Properties props, Supplier disassemblyExtra) { - super(id, props); - this.disassemblyExtra = disassemblyExtra; - } - - @Override - public InteractionResultHolder use(Level level, Player player, InteractionHand hand) { - if (AEConfig.instance().isDisassemblyCraftingEnabled() && InteractionUtil.isInAlternateUseMode(player)) { - int itemCount = player.getItemInHand(hand).getCount(); - player.setItemInHand(hand, ItemStack.EMPTY); - - player.getInventory().placeItemBackInInventory(AEBlocks.CRAFTING_UNIT.stack(itemCount)); - player.getInventory().placeItemBackInInventory(new ItemStack(disassemblyExtra.get(), itemCount)); - - return InteractionResultHolder.sidedSuccess(player.getItemInHand(hand), level.isClientSide()); - } - return super.use(level, player, hand); - } - - private void disassemble(ItemStack stack, Player player) { - } -} diff --git a/src/main/java/appeng/block/crafting/CraftingMonitorBlock.java b/src/main/java/appeng/block/crafting/CraftingMonitorBlock.java deleted file mode 100644 index b13c6f8eef7..00000000000 --- a/src/main/java/appeng/block/crafting/CraftingMonitorBlock.java +++ /dev/null @@ -1,29 +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.crafting; - -import net.minecraft.world.level.block.state.BlockBehaviour; - -import appeng.blockentity.crafting.CraftingMonitorBlockEntity; - -public class CraftingMonitorBlock extends AbstractCraftingUnitBlock { - public CraftingMonitorBlock(BlockBehaviour.Properties props, ICraftingUnitType type) { - super(props, type); - } -} diff --git a/src/main/java/appeng/block/crafting/CraftingUnitBlock.java b/src/main/java/appeng/block/crafting/CraftingUnitBlock.java deleted file mode 100644 index bd6c495ca1f..00000000000 --- a/src/main/java/appeng/block/crafting/CraftingUnitBlock.java +++ /dev/null @@ -1,31 +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.crafting; - -import net.minecraft.world.level.block.state.BlockBehaviour; - -import appeng.blockentity.crafting.CraftingBlockEntity; - -public class CraftingUnitBlock extends AbstractCraftingUnitBlock { - - public CraftingUnitBlock(BlockBehaviour.Properties props, ICraftingUnitType type) { - super(props, type); - } - -} diff --git a/src/main/java/appeng/block/crafting/CraftingUnitType.java b/src/main/java/appeng/block/crafting/CraftingUnitType.java deleted file mode 100644 index f526f3fedae..00000000000 --- a/src/main/java/appeng/block/crafting/CraftingUnitType.java +++ /dev/null @@ -1,47 +0,0 @@ -package appeng.block.crafting; - -import net.minecraft.world.item.Item; - -import appeng.core.definitions.AEBlocks; - -public enum CraftingUnitType implements ICraftingUnitType { - UNIT(0), - ACCELERATOR(0), - STORAGE_1K(1), - STORAGE_4K(4), - STORAGE_16K(16), - STORAGE_64K(64), - STORAGE_256K(256), - MONITOR(0); - - private final int storageKb; - - CraftingUnitType(int storageKb) { - this.storageKb = storageKb; - } - - @Override - public long getStorageBytes() { - return 1024L * this.storageKb; - } - - @Override - public int getAcceleratorThreads() { - return this == ACCELERATOR ? 1 : 0; - } - - @Override - public Item getItemFromType() { - var definition = switch (this) { - case UNIT -> AEBlocks.CRAFTING_UNIT; - case ACCELERATOR -> AEBlocks.CRAFTING_ACCELERATOR; - case STORAGE_1K -> AEBlocks.CRAFTING_STORAGE_1K; - case STORAGE_4K -> AEBlocks.CRAFTING_STORAGE_4K; - case STORAGE_16K -> AEBlocks.CRAFTING_STORAGE_16K; - case STORAGE_64K -> AEBlocks.CRAFTING_STORAGE_64K; - case STORAGE_256K -> AEBlocks.CRAFTING_STORAGE_256K; - case MONITOR -> AEBlocks.CRAFTING_MONITOR; - }; - return definition.asItem(); - } -} diff --git a/src/main/java/appeng/block/crafting/ICraftingUnitType.java b/src/main/java/appeng/block/crafting/ICraftingUnitType.java deleted file mode 100644 index 6fc4c542db6..00000000000 --- a/src/main/java/appeng/block/crafting/ICraftingUnitType.java +++ /dev/null @@ -1,25 +0,0 @@ -package appeng.block.crafting; - -import net.minecraft.world.item.Item; - -/** - * Implemented by classes/enums meant to provide their own types of crafting CPU blocks. - */ -public interface ICraftingUnitType { - - /** - * @return the capacity of a given crafting storage block in bytes (should be 0 if not storage). - */ - long getStorageBytes(); - - /** - * @return how many co-processors a crafting unit provides. For lag-mitigation purposes, a hard-coded limit has been - * set of 16 threads for any given co-processing unit block. - */ - int getAcceleratorThreads(); - - /** - * @return the BlockItem for the crafting storage block corresponding with its type for block-entity purposes. - */ - Item getItemFromType(); -} diff --git a/src/main/java/appeng/block/crafting/MolecularAssemblerBlock.java b/src/main/java/appeng/block/crafting/MolecularAssemblerBlock.java deleted file mode 100644 index 15407ba0177..00000000000 --- a/src/main/java/appeng/block/crafting/MolecularAssemblerBlock.java +++ /dev/null @@ -1,76 +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.crafting; - -import net.minecraft.core.BlockPos; -import net.minecraft.world.InteractionHand; -import net.minecraft.world.InteractionResult; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockBehaviour; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.state.StateDefinition.Builder; -import net.minecraft.world.level.block.state.properties.BooleanProperty; -import net.minecraft.world.phys.BlockHitResult; - -import appeng.block.AEBaseEntityBlock; -import appeng.blockentity.crafting.MolecularAssemblerBlockEntity; -import appeng.menu.MenuOpener; -import appeng.menu.implementations.MolecularAssemblerMenu; -import appeng.menu.locator.MenuLocators; -import appeng.util.InteractionUtil; - -public class MolecularAssemblerBlock extends AEBaseEntityBlock { - - public static final BooleanProperty POWERED = BooleanProperty.create("powered"); - - public MolecularAssemblerBlock(BlockBehaviour.Properties props) { - super(props); - registerDefaultState(defaultBlockState().setValue(POWERED, false)); - } - - @Override - protected void createBlockStateDefinition(Builder builder) { - super.createBlockStateDefinition(builder); - builder.add(POWERED); - } - - @Override - protected BlockState updateBlockStateFromBlockEntity(BlockState currentState, MolecularAssemblerBlockEntity be) { - return currentState.setValue(POWERED, be.isPowered()); - } - - @Override - public InteractionResult use(BlockState state, Level level, BlockPos pos, Player p, InteractionHand hand, - BlockHitResult hit) { - final MolecularAssemblerBlockEntity tg = this.getBlockEntity(level, pos); - if (tg != null && !InteractionUtil.isInAlternateUseMode(p)) { - if (!level.isClientSide()) { - hit.getDirection(); - MenuOpener.open(MolecularAssemblerMenu.TYPE, p, - MenuLocators.forBlockEntity(tg)); - } - return InteractionResult.sidedSuccess(level.isClientSide()); - } - - return super.use(state, level, pos, p, hand, hit); - } - -} diff --git a/src/main/java/appeng/block/crafting/PatternProviderBlock.java b/src/main/java/appeng/block/crafting/PatternProviderBlock.java deleted file mode 100644 index 10547841a41..00000000000 --- a/src/main/java/appeng/block/crafting/PatternProviderBlock.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * This file is part of Applied Energistics 2. - * Copyright (c) 2021, 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.block.crafting; - -import javax.annotation.Nullable; - -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.world.InteractionHand; -import net.minecraft.world.InteractionResult; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.state.StateDefinition; -import net.minecraft.world.level.block.state.properties.BooleanProperty; -import net.minecraft.world.level.material.Material; -import net.minecraft.world.phys.BlockHitResult; - -import appeng.api.util.IOrientable; -import appeng.block.AEBaseEntityBlock; -import appeng.blockentity.crafting.PatternProviderBlockEntity; -import appeng.menu.locator.MenuLocators; -import appeng.util.InteractionUtil; - -public class PatternProviderBlock extends AEBaseEntityBlock { - - private static final BooleanProperty OMNIDIRECTIONAL = BooleanProperty.create("omnidirectional"); - - public PatternProviderBlock() { - super(defaultProps(Material.METAL)); - registerDefaultState(defaultBlockState().setValue(OMNIDIRECTIONAL, true)); - } - - @Override - protected void createBlockStateDefinition(StateDefinition.Builder builder) { - super.createBlockStateDefinition(builder); - builder.add(OMNIDIRECTIONAL); - } - - @Override - protected BlockState updateBlockStateFromBlockEntity(BlockState currentState, PatternProviderBlockEntity be) { - return currentState.setValue(OMNIDIRECTIONAL, be.isOmniDirectional()); - } - - @Override - public void neighborChanged(BlockState state, Level level, BlockPos pos, Block block, BlockPos fromPos, - boolean isMoving) { - var be = this.getBlockEntity(level, pos); - if (be != null) { - be.getLogic().updateRedstoneState(); - } - } - - @Override - public InteractionResult onActivated(Level level, BlockPos pos, Player p, - InteractionHand hand, - @Nullable ItemStack heldItem, BlockHitResult hit) { - if (InteractionUtil.isInAlternateUseMode(p)) { - return InteractionResult.PASS; - } - - var be = this.getBlockEntity(level, pos); - if (be != null) { - if (!level.isClientSide()) { - be.openMenu(p, MenuLocators.forBlockEntity(be)); - } - return InteractionResult.sidedSuccess(level.isClientSide()); - } - return InteractionResult.PASS; - } - - @Override - protected boolean hasCustomRotation() { - return true; - } - - @Override - protected void customRotateBlock(IOrientable rotatable, Direction axis) { - if (rotatable instanceof PatternProviderBlockEntity patternProvider) { - patternProvider.setSide(axis); - } - } -} diff --git a/src/main/java/appeng/block/misc/CellWorkbenchBlock.java b/src/main/java/appeng/block/misc/CellWorkbenchBlock.java deleted file mode 100644 index d5e7709f372..00000000000 --- a/src/main/java/appeng/block/misc/CellWorkbenchBlock.java +++ /dev/null @@ -1,62 +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.misc; - -import javax.annotation.Nullable; - -import net.minecraft.core.BlockPos; -import net.minecraft.world.InteractionHand; -import net.minecraft.world.InteractionResult; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.material.Material; -import net.minecraft.world.phys.BlockHitResult; - -import appeng.block.AEBaseEntityBlock; -import appeng.blockentity.misc.CellWorkbenchBlockEntity; -import appeng.menu.MenuOpener; -import appeng.menu.implementations.CellWorkbenchMenu; -import appeng.menu.locator.MenuLocators; -import appeng.util.InteractionUtil; - -public class CellWorkbenchBlock extends AEBaseEntityBlock { - - public CellWorkbenchBlock() { - super(defaultProps(Material.METAL)); - } - - @Override - public InteractionResult onActivated(Level level, BlockPos pos, Player p, - InteractionHand hand, - @Nullable ItemStack heldItem, BlockHitResult hit) { - if (InteractionUtil.isInAlternateUseMode(p)) { - return InteractionResult.PASS; - } - - final CellWorkbenchBlockEntity tg = this.getBlockEntity(level, pos); - if (tg != null) { - if (!level.isClientSide()) { - MenuOpener.open(CellWorkbenchMenu.TYPE, p, MenuLocators.forBlockEntity(tg)); - } - return InteractionResult.sidedSuccess(level.isClientSide()); - } - return InteractionResult.PASS; - } -} diff --git a/src/main/java/appeng/block/misc/ChargerBlock.java b/src/main/java/appeng/block/misc/ChargerBlock.java deleted file mode 100644 index 66b0c8e7c05..00000000000 --- a/src/main/java/appeng/block/misc/ChargerBlock.java +++ /dev/null @@ -1,192 +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.misc; - -import javax.annotation.Nullable; - -import com.mojang.math.Vector3f; - -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.minecraft.client.Minecraft; -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.util.Mth; -import net.minecraft.util.RandomSource; -import net.minecraft.world.InteractionHand; -import net.minecraft.world.InteractionResult; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.BlockGetter; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.material.Material; -import net.minecraft.world.phys.AABB; -import net.minecraft.world.phys.BlockHitResult; -import net.minecraft.world.phys.Vec3; -import net.minecraft.world.phys.shapes.CollisionContext; -import net.minecraft.world.phys.shapes.Shapes; -import net.minecraft.world.phys.shapes.VoxelShape; - -import appeng.api.util.AEAxisAlignedBB; -import appeng.block.AEBaseEntityBlock; -import appeng.blockentity.misc.ChargerBlockEntity; -import appeng.client.render.FacingToRotation; -import appeng.client.render.effects.LightningArcParticleData; -import appeng.core.AEConfig; -import appeng.core.AppEngClient; -import appeng.util.InteractionUtil; - -public class ChargerBlock extends AEBaseEntityBlock { - - public ChargerBlock() { - super(defaultProps(Material.METAL).noOcclusion()); - } - - @Override - public int getLightBlock(BlockState state, BlockGetter level, BlockPos pos) { - return 2; // FIXME Double check this (esp. value range) - } - - @Override - public InteractionResult onActivated(Level level, BlockPos pos, Player player, - InteractionHand hand, - @Nullable ItemStack heldItem, BlockHitResult hit) { - if (InteractionUtil.isInAlternateUseMode(player)) { - return InteractionResult.PASS; - } - - if (!level.isClientSide()) { - final ChargerBlockEntity tc = this.getBlockEntity(level, pos); - if (tc != null) { - tc.activate(player); - } - } - - return InteractionResult.sidedSuccess(level.isClientSide()); - } - - @Override - @Environment(EnvType.CLIENT) - public void animateTick(BlockState state, Level level, BlockPos pos, RandomSource r) { - if (!AEConfig.instance().isEnableEffects()) { - return; - } - - var blockEntity = this.getBlockEntity(level, pos); - if (blockEntity != null && blockEntity.isWorking()) { - if (r.nextFloat() < 0.5) { - return; - } - - var rotation = FacingToRotation.get(blockEntity.getForward(), blockEntity.getUp()); - - for (int bolts = 0; bolts < 3; bolts++) { - // Slightly offset the lightning arc on the x/z plane - var xOff = Mth.randomBetween(r, -0.15f, 0.15f); - var zOff = Mth.randomBetween(r, -0.15f, 0.15f); - - // Compute two points in the charger block. One at the bottom, and one on the top. - // Account for the rotation while doing this. - var center = new Vector3f(pos.getX() + 0.5f, pos.getY() + 0.5f, pos.getZ() + 0.5f); - var origin = new Vector3f(xOff, -0.3f, zOff); - origin.transform(rotation.getRot()); - origin.add(center); - var target = new Vector3f(xOff, 0.3f, zOff); - target.transform(rotation.getRot()); - target.add(center); - - // Split the arcs between arc coming from the top/bottom of the charger since it's symmetrical - if (r.nextBoolean()) { - var tmp = target; - target = origin; - origin = tmp; - } - - if (AppEngClient.instance().shouldAddParticles(r)) { - Minecraft.getInstance().particleEngine.createParticle( - new LightningArcParticleData(new Vec3(target)), - origin.x(), - origin.y(), - origin.z(), - 0.0, 0.0, 0.0); - } - } - } - } - - @Override - public VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) { - - final ChargerBlockEntity blockEntity = this.getBlockEntity(level, pos); - if (blockEntity != null) { - final double twoPixels = 2.0 / 16.0; - final Direction up = blockEntity.getUp(); - final Direction forward = blockEntity.getForward(); - final AEAxisAlignedBB bb = new AEAxisAlignedBB(twoPixels, twoPixels, twoPixels, 1.0 - twoPixels, - 1.0 - twoPixels, 1.0 - twoPixels); - - if (up.getStepX() != 0) { - bb.minX = 0; - bb.maxX = 1; - } - if (up.getStepY() != 0) { - bb.minY = 0; - bb.maxY = 1; - } - if (up.getStepZ() != 0) { - bb.minZ = 0; - bb.maxZ = 1; - } - - switch (forward) { - case DOWN: - bb.maxY = 1; - break; - case UP: - bb.minY = 0; - break; - case NORTH: - bb.maxZ = 1; - break; - case SOUTH: - bb.minZ = 0; - break; - case EAST: - bb.minX = 0; - break; - case WEST: - bb.maxX = 1; - break; - default: - break; - } - - return Shapes.create(bb.getBoundingBox()); - } - return Shapes.create(new AABB(0.0, 0, 0.0, 1.0, 1.0, 1.0)); - } - - @Override - public VoxelShape getCollisionShape(BlockState state, BlockGetter level, BlockPos pos, - CollisionContext context) { - return Shapes.create(new AABB(0.0, 0.0, 0.0, 1.0, 1.0, 1.0)); - } - -} diff --git a/src/main/java/appeng/block/misc/CondenserBlock.java b/src/main/java/appeng/block/misc/CondenserBlock.java deleted file mode 100644 index e4e6dda288b..00000000000 --- a/src/main/java/appeng/block/misc/CondenserBlock.java +++ /dev/null @@ -1,64 +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.misc; - -import javax.annotation.Nullable; - -import net.minecraft.core.BlockPos; -import net.minecraft.world.InteractionHand; -import net.minecraft.world.InteractionResult; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.material.Material; -import net.minecraft.world.phys.BlockHitResult; - -import appeng.block.AEBaseEntityBlock; -import appeng.blockentity.misc.CondenserBlockEntity; -import appeng.menu.MenuOpener; -import appeng.menu.implementations.CondenserMenu; -import appeng.menu.locator.MenuLocators; -import appeng.util.InteractionUtil; - -public class CondenserBlock extends AEBaseEntityBlock { - - public CondenserBlock() { - super(defaultProps(Material.METAL)); - } - - @Override - public InteractionResult onActivated(Level level, BlockPos pos, Player player, - InteractionHand hand, - @Nullable ItemStack heldItem, BlockHitResult hit) { - if (InteractionUtil.isInAlternateUseMode(player)) { - return InteractionResult.PASS; - } - - if (!level.isClientSide()) { - final CondenserBlockEntity tc = this.getBlockEntity(level, pos); - if (tc != null && !InteractionUtil.isInAlternateUseMode(player)) { - hit.getDirection(); - MenuOpener.open(CondenserMenu.TYPE, player, - MenuLocators.forBlockEntity(tc)); - } - } - - return InteractionResult.sidedSuccess(level.isClientSide()); - } -} diff --git a/src/main/java/appeng/block/misc/CrankBlock.java b/src/main/java/appeng/block/misc/CrankBlock.java deleted file mode 100644 index 893ed7345a1..00000000000 --- a/src/main/java/appeng/block/misc/CrankBlock.java +++ /dev/null @@ -1,172 +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.misc; - -import org.jetbrains.annotations.Nullable; - -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.world.InteractionHand; -import net.minecraft.world.InteractionResult; -import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.BlockGetter; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.LevelAccessor; -import net.minecraft.world.level.LevelReader; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.RenderShape; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.phys.AABB; -import net.minecraft.world.phys.BlockHitResult; -import net.minecraft.world.phys.shapes.CollisionContext; -import net.minecraft.world.phys.shapes.Shapes; -import net.minecraft.world.phys.shapes.VoxelShape; - -import appeng.api.implementations.blockentities.ICrankable; -import appeng.api.util.IOrientableBlock; -import appeng.block.AEBaseEntityBlock; -import appeng.blockentity.misc.CrankBlockEntity; -import appeng.util.FakePlayer; - -public class CrankBlock extends AEBaseEntityBlock implements IOrientableBlock { - - public CrankBlock(Properties props) { - super(props); - } - - @Override - public InteractionResult onActivated(Level level, BlockPos pos, Player player, InteractionHand hand, - @Nullable ItemStack heldItem, BlockHitResult hit) { - if (player instanceof FakePlayer || player == null) { - this.dropCrank(level, pos); - return InteractionResult.sidedSuccess(level.isClientSide()); - } - - var crank = this.getBlockEntity(level, pos); - if (crank != null) { - crank.power(); - return InteractionResult.sidedSuccess(level.isClientSide()); - } - - return InteractionResult.PASS; - } - - private void dropCrank(Level level, BlockPos pos) { - level.destroyBlock(pos, true); - level.sendBlockUpdated(pos, defaultBlockState(), level.getBlockState(pos), 3); - } - - @Override - public void setPlacedBy(Level level, BlockPos pos, BlockState state, LivingEntity placer, ItemStack is) { - super.setPlacedBy(level, pos, state, placer, is); - - var be = getBlockEntity(level, pos); - if (be != null) { - var mnt = this.findCrankableDirection(level, pos); - if (mnt == null) { - dropCrank(level, pos); - return; - } - - Direction forward = Direction.UP; - if (mnt == Direction.UP || mnt == Direction.DOWN) { - forward = Direction.SOUTH; - } - be.setOrientation(forward, mnt.getOpposite()); - } else { - dropCrank(level, pos); - } - } - - @Override - protected boolean isValidOrientation(LevelAccessor levelAccessor, BlockPos pos, Direction forward, Direction up) { - if (levelAccessor instanceof Level level) { - var be = level.getBlockEntity(pos); - return !(be instanceof CrankBlockEntity) || isCrankable(level, pos, up.getOpposite()); - } else { - return true; - } - } - - private Direction findCrankableDirection(Level level, BlockPos pos) { - for (var dir : Direction.values()) { - if (isCrankable(level, pos, dir)) { - return dir; - } - } - return null; - } - - private boolean isCrankable(Level level, BlockPos pos, Direction offset) { - var o = pos.relative(offset); - return ICrankable.get(level, o, offset.getOpposite()) != null; - } - - @SuppressWarnings("deprecation") - @Override - public RenderShape getRenderShape(BlockState state) { - return RenderShape.ENTITYBLOCK_ANIMATED; - } - - @Override - public void neighborChanged(BlockState state, Level level, BlockPos pos, Block blockIn, BlockPos fromPos, - boolean isMoving) { - var be = this.getBlockEntity(level, pos); - if (be != null) { - if (!isCrankable(level, pos, be.getUp().getOpposite())) { - dropCrank(level, pos); - } - } else { - dropCrank(level, pos); - } - } - - @Override - public boolean canSurvive(BlockState state, LevelReader levelReader, BlockPos pos) { - if (levelReader instanceof Level level) { - return findCrankableDirection(level, pos) != null; - } else { - return true; - } - } - - private Direction getUp(BlockGetter level, BlockPos pos) { - var crank = getBlockEntity(level, pos); - return crank != null ? crank.getUp() : null; - } - - @Override - public VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) { - Direction up = getUp(level, pos); - - if (up == null) { - return Shapes.empty(); - } else { - // FIXME: Cache per direction, and build it 'precise', not just from AABB - final double xOff = -0.15 * up.getStepX(); - final double yOff = -0.15 * up.getStepY(); - final double zOff = -0.15 * up.getStepZ(); - return Shapes.create( - new AABB(xOff + 0.15, yOff + 0.15, zOff + 0.15, xOff + 0.85, yOff + 0.85, zOff + 0.85)); - } - - } -} diff --git a/src/main/java/appeng/block/misc/InscriberBlock.java b/src/main/java/appeng/block/misc/InscriberBlock.java deleted file mode 100644 index 68927b8c8cb..00000000000 --- a/src/main/java/appeng/block/misc/InscriberBlock.java +++ /dev/null @@ -1,119 +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.misc; - -import javax.annotation.Nullable; - -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.world.InteractionHand; -import net.minecraft.world.InteractionResult; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.context.BlockPlaceContext; -import net.minecraft.world.level.BlockGetter; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.LevelAccessor; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.SimpleWaterloggedBlock; -import net.minecraft.world.level.block.state.BlockBehaviour; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.state.StateDefinition; -import net.minecraft.world.level.block.state.properties.BlockStateProperties; -import net.minecraft.world.level.block.state.properties.BooleanProperty; -import net.minecraft.world.level.material.FluidState; -import net.minecraft.world.level.material.Fluids; -import net.minecraft.world.phys.BlockHitResult; - -import appeng.block.AEBaseEntityBlock; -import appeng.blockentity.misc.InscriberBlockEntity; -import appeng.menu.MenuOpener; -import appeng.menu.implementations.InscriberMenu; -import appeng.menu.locator.MenuLocators; -import appeng.util.InteractionUtil; - -public class InscriberBlock extends AEBaseEntityBlock implements SimpleWaterloggedBlock { - - private static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED; - - public InscriberBlock(BlockBehaviour.Properties props) { - super(props); - this.registerDefaultState(this.defaultBlockState().setValue(WATERLOGGED, false)); - } - - @Override - public int getLightBlock(BlockState state, BlockGetter level, BlockPos pos) { - return 2; // FIXME validate this. a) possibly not required because of getShape b) value - // range. was 2 in 1.10 - } - - @Override - public InteractionResult onActivated(Level level, BlockPos pos, Player p, - InteractionHand hand, - @Nullable ItemStack heldItem, BlockHitResult hit) { - if (!InteractionUtil.isInAlternateUseMode(p)) { - final InscriberBlockEntity tg = this.getBlockEntity(level, pos); - if (tg != null) { - if (!level.isClientSide()) { - hit.getDirection(); - MenuOpener.open(InscriberMenu.TYPE, p, - MenuLocators.forBlockEntity(tg)); - } - return InteractionResult.sidedSuccess(level.isClientSide()); - } - } - return InteractionResult.PASS; - - } - - @Override - protected void createBlockStateDefinition(StateDefinition.Builder builder) { - super.createBlockStateDefinition(builder); - builder.add(WATERLOGGED); - } - - @Override - @Nullable - public BlockState getStateForPlacement(BlockPlaceContext context) { - BlockPos pos = context.getClickedPos(); - FluidState fluidState = context.getLevel().getFluidState(pos); - BlockState blockState = this.defaultBlockState() - .setValue(WATERLOGGED, fluidState.getType() == Fluids.WATER); - - return blockState; - } - - @Override - public FluidState getFluidState(BlockState blockState) { - return blockState.getValue(WATERLOGGED).booleanValue() - ? Fluids.WATER.getSource(false) - : super.getFluidState(blockState); - } - - @Override - public BlockState updateShape(BlockState blockState, Direction facing, BlockState facingState, LevelAccessor level, - BlockPos currentPos, BlockPos facingPos) { - if (blockState.getValue(WATERLOGGED).booleanValue()) { - level.scheduleTick(currentPos, Fluids.WATER, Fluids.WATER.getTickDelay(level)); - } - - return super.updateShape(blockState, facing, facingState, level, currentPos, facingPos); - } - -} diff --git a/src/main/java/appeng/block/misc/InterfaceBlock.java b/src/main/java/appeng/block/misc/InterfaceBlock.java deleted file mode 100644 index 1d9e9a632f2..00000000000 --- a/src/main/java/appeng/block/misc/InterfaceBlock.java +++ /dev/null @@ -1,60 +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.misc; - -import javax.annotation.Nullable; - -import net.minecraft.core.BlockPos; -import net.minecraft.world.InteractionHand; -import net.minecraft.world.InteractionResult; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.material.Material; -import net.minecraft.world.phys.BlockHitResult; - -import appeng.block.AEBaseEntityBlock; -import appeng.blockentity.misc.InterfaceBlockEntity; -import appeng.menu.locator.MenuLocators; -import appeng.util.InteractionUtil; - -public class InterfaceBlock extends AEBaseEntityBlock { - public InterfaceBlock() { - super(defaultProps(Material.METAL)); - } - - @Override - public InteractionResult onActivated(Level level, BlockPos pos, Player p, - InteractionHand hand, - @Nullable ItemStack heldItem, BlockHitResult hit) { - if (InteractionUtil.isInAlternateUseMode(p)) { - return InteractionResult.PASS; - } - - var be = this.getBlockEntity(level, pos); - if (be != null) { - if (!level.isClientSide()) { - hit.getDirection(); - be.openMenu(p, MenuLocators.forBlockEntity(be)); - } - return InteractionResult.sidedSuccess(level.isClientSide()); - } - return InteractionResult.PASS; - } -} diff --git a/src/main/java/appeng/block/misc/LightDetectorBlock.java b/src/main/java/appeng/block/misc/LightDetectorBlock.java deleted file mode 100644 index dea3b2302c9..00000000000 --- a/src/main/java/appeng/block/misc/LightDetectorBlock.java +++ /dev/null @@ -1,185 +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.misc; - -import javax.annotation.Nullable; - -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.util.RandomSource; -import net.minecraft.world.item.context.BlockPlaceContext; -import net.minecraft.world.level.BlockGetter; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.LevelAccessor; -import net.minecraft.world.level.LevelReader; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.state.StateDefinition.Builder; -import net.minecraft.world.level.block.state.properties.BlockStateProperties; -import net.minecraft.world.level.block.state.properties.BooleanProperty; -import net.minecraft.world.level.material.FluidState; -import net.minecraft.world.level.material.Fluids; -import net.minecraft.world.phys.AABB; -import net.minecraft.world.phys.shapes.CollisionContext; -import net.minecraft.world.phys.shapes.Shapes; -import net.minecraft.world.phys.shapes.VoxelShape; - -import appeng.api.util.IOrientable; -import appeng.api.util.IOrientableBlock; -import appeng.block.AEBaseEntityBlock; -import appeng.blockentity.misc.LightDetectorBlockEntity; -import appeng.helpers.AEMaterials; -import appeng.helpers.MetaRotation; -import appeng.hooks.INeighborChangeSensitive; - -public class LightDetectorBlock extends AEBaseEntityBlock - implements IOrientableBlock, INeighborChangeSensitive { - - // Used to alternate between two variants of the fixture on adjacent blocks - public static final BooleanProperty ODD = BooleanProperty.create("odd"); - - public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED; - - public LightDetectorBlock() { - super(defaultProps(AEMaterials.FIXTURE).noCollission().noOcclusion()); - - this.registerDefaultState( - this.defaultBlockState().setValue(BlockStateProperties.FACING, Direction.UP).setValue(ODD, false) - .setValue(WATERLOGGED, false)); - } - - @Override - protected void createBlockStateDefinition(Builder builder) { - super.createBlockStateDefinition(builder); - builder.add(BlockStateProperties.FACING); - builder.add(ODD); - builder.add(WATERLOGGED); - } - - @Override - public int getSignal(BlockState state, BlockGetter level, BlockPos pos, Direction side) { - if (level instanceof Level && this.getBlockEntity(level, pos).isReady()) { - // FIXME: This is ... uhm... fishy - return ((Level) level).getMaxLocalRawBrightness(pos) - 6; - } - - return 0; - } - - @Override - public void onNeighborChange(BlockState state, LevelReader level, BlockPos pos, BlockPos neighbor) { - final LightDetectorBlockEntity tld = this.getBlockEntity(level, pos); - if (tld != null) { - tld.updateLight(); - } - } - - @Override - public void animateTick(BlockState state, Level level, BlockPos pos, RandomSource rand) { - // cancel out lightning - } - - @Override - public boolean isValidOrientation(LevelAccessor level, BlockPos pos, Direction forward, - Direction up) { - return this.canPlaceAt(level, pos, up.getOpposite()); - } - - private boolean canPlaceAt(LevelReader level, BlockPos pos, Direction dir) { - return canSupportCenter(level, pos.relative(dir), dir.getOpposite()); - } - - @Override - public VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) { - - // FIXME: We should / rather MUST use state here because at startup, this gets - // called without a level - - final Direction up = this.getOrientable(level, pos).getUp(); - final double xOff = -0.3 * up.getStepX(); - final double yOff = -0.3 * up.getStepY(); - final double zOff = -0.3 * up.getStepZ(); - return Shapes - .create(new AABB(xOff + 0.3, yOff + 0.3, zOff + 0.3, xOff + 0.7, yOff + 0.7, zOff + 0.7)); - } - - @Override - public VoxelShape getCollisionShape(BlockState state, BlockGetter level, BlockPos pos, - CollisionContext context) { - return Shapes.empty(); - } - - @Override - public void neighborChanged(BlockState state, Level level, BlockPos pos, Block blockIn, BlockPos fromPos, - boolean isMoving) { - final Direction up = this.getOrientable(level, pos).getUp(); - if (!this.canPlaceAt(level, pos, up.getOpposite())) { - this.dropTorch(level, pos); - } - } - - private void dropTorch(Level level, BlockPos pos) { - final BlockState prev = level.getBlockState(pos); - level.destroyBlock(pos, true); - level.sendBlockUpdated(pos, prev, level.getBlockState(pos), 3); - } - - @Override - public boolean canSurvive(BlockState state, LevelReader level, BlockPos pos) { - for (Direction dir : Direction.values()) { - if (this.canPlaceAt(level, pos, dir)) { - return true; - } - } - return false; - } - - @Override - public IOrientable getOrientable(BlockGetter level, BlockPos pos) { - return new MetaRotation(level, pos, BlockStateProperties.FACING); - } - - @Override - @Nullable - public BlockState getStateForPlacement(BlockPlaceContext context) { - BlockPos pos = context.getClickedPos(); - FluidState fluidState = context.getLevel().getFluidState(pos); - BlockState blockState = this.defaultBlockState() - .setValue(WATERLOGGED, fluidState.getType() == Fluids.WATER); - - return blockState; - } - - @Override - public FluidState getFluidState(BlockState blockState) { - return blockState.getValue(WATERLOGGED).booleanValue() - ? Fluids.WATER.getSource(false) - : super.getFluidState(blockState); - } - - @Override - public BlockState updateShape(BlockState blockState, Direction facing, BlockState facingState, LevelAccessor level, - BlockPos currentPos, BlockPos facingPos) { - if (blockState.getValue(WATERLOGGED).booleanValue()) { - level.scheduleTick(currentPos, Fluids.WATER, Fluids.WATER.getTickDelay(level)); - } - - return super.updateShape(blockState, facing, facingState, level, currentPos, facingPos); - } -} diff --git a/src/main/java/appeng/block/misc/MysteriousCubeBlock.java b/src/main/java/appeng/block/misc/MysteriousCubeBlock.java deleted file mode 100644 index 121be9051c3..00000000000 --- a/src/main/java/appeng/block/misc/MysteriousCubeBlock.java +++ /dev/null @@ -1,54 +0,0 @@ -package appeng.block.misc; - -import java.util.List; - -import org.jetbrains.annotations.Nullable; - -import net.minecraft.core.BlockPos; -import net.minecraft.network.chat.Component; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.TooltipFlag; -import net.minecraft.world.level.BlockGetter; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.material.Material; - -import appeng.block.AEBaseBlock; -import appeng.core.localization.GuiText; -import appeng.core.localization.Tooltips; -import appeng.server.services.compass.CompassService; - -public class MysteriousCubeBlock extends AEBaseBlock { - public static final Properties PROPERTIES = defaultProps(Material.METAL).strength(10, 1000); - - public MysteriousCubeBlock() { - super(PROPERTIES); - } - - @Override - public void onPlace(BlockState state, Level level, BlockPos pos, BlockState oldState, boolean isMoving) { - if (level instanceof ServerLevel serverLevel) { - CompassService.notifyBlockChange(serverLevel, pos); - } - } - - @Override - public void onRemove(BlockState state, Level level, BlockPos pos, BlockState newState, boolean isMoving) { - if (newState.getBlock() == state.getBlock()) { - return; // Just a block state change - } - - super.onRemove(state, level, pos, newState, isMoving); - - if (level instanceof ServerLevel serverLevel) { - CompassService.notifyBlockChange(serverLevel, pos); - } - } - - @Override - public void appendHoverText(ItemStack stack, @Nullable BlockGetter level, List tooltip, - TooltipFlag flag) { - tooltip.add(Tooltips.of(GuiText.MysteriousQuote, Tooltips.QUOTE_TEXT)); - } -} diff --git a/src/main/java/appeng/block/misc/QuartzFixtureBlock.java b/src/main/java/appeng/block/misc/QuartzFixtureBlock.java deleted file mode 100644 index d9bfaa6459b..00000000000 --- a/src/main/java/appeng/block/misc/QuartzFixtureBlock.java +++ /dev/null @@ -1,220 +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.misc; - -import java.util.EnumMap; -import java.util.Map; - -import javax.annotation.Nullable; - -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.util.RandomSource; -import net.minecraft.world.item.context.BlockPlaceContext; -import net.minecraft.world.level.BlockGetter; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.LevelAccessor; -import net.minecraft.world.level.LevelReader; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.SimpleWaterloggedBlock; -import net.minecraft.world.level.block.SoundType; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.state.StateDefinition.Builder; -import net.minecraft.world.level.block.state.properties.BlockStateProperties; -import net.minecraft.world.level.block.state.properties.BooleanProperty; -import net.minecraft.world.level.block.state.properties.DirectionProperty; -import net.minecraft.world.level.material.FluidState; -import net.minecraft.world.level.material.Fluids; -import net.minecraft.world.phys.AABB; -import net.minecraft.world.phys.shapes.CollisionContext; -import net.minecraft.world.phys.shapes.Shapes; -import net.minecraft.world.phys.shapes.VoxelShape; - -import appeng.api.util.IOrientable; -import appeng.api.util.IOrientableBlock; -import appeng.block.AEBaseBlock; -import appeng.client.render.effects.ParticleTypes; -import appeng.core.AEConfig; -import appeng.core.AppEngClient; -import appeng.helpers.AEMaterials; -import appeng.helpers.MetaRotation; - -public class QuartzFixtureBlock extends AEBaseBlock implements IOrientableBlock, SimpleWaterloggedBlock { - - // Cache VoxelShapes for each facing - private static final Map SHAPES; - - static { - SHAPES = new EnumMap<>(Direction.class); - - for (Direction facing : Direction.values()) { - final double xOff = -0.3 * facing.getStepX(); - final double yOff = -0.3 * facing.getStepY(); - final double zOff = -0.3 * facing.getStepZ(); - VoxelShape shape = Shapes - .create(new AABB(xOff + 0.3, yOff + 0.3, zOff + 0.3, xOff + 0.7, yOff + 0.7, zOff + 0.7)); - SHAPES.put(facing, shape); - } - } - - // Cannot use the vanilla FACING property here because it excludes facing DOWN - public static final DirectionProperty FACING = BlockStateProperties.FACING; - - // Used to alternate between two variants of the fixture on adjacent blocks - public static final BooleanProperty ODD = BooleanProperty.create("odd"); - - public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED; - - public QuartzFixtureBlock() { - super(defaultProps( - AEMaterials.FIXTURE).noCollission().noOcclusion().strength(0) - .lightLevel(b -> 14).sound(SoundType.GLASS)); - - this.registerDefaultState( - defaultBlockState().setValue(FACING, Direction.UP).setValue(ODD, false).setValue(WATERLOGGED, false)); - } - - @Override - protected void createBlockStateDefinition(Builder builder) { - builder.add(FACING, ODD, WATERLOGGED); - } - - // For reference, see WallTorchBlock - @Override - @Nullable - public BlockState getStateForPlacement(BlockPlaceContext context) { - BlockState blockstate = super.getStateForPlacement(context); - BlockPos pos = context.getClickedPos(); - FluidState fluidState = context.getLevel().getFluidState(pos); - - // Set the even/odd property - boolean oddPlacement = (pos.getX() + pos.getY() + pos.getZ()) % 2 != 0; - blockstate = blockstate.setValue(ODD, oddPlacement).setValue(WATERLOGGED, fluidState.getType() == Fluids.WATER); - - LevelReader levelReader = context.getLevel(); - Direction[] adirection = context.getNearestLookingDirections(); - - for (Direction direction : adirection) { - if (canPlaceAt(levelReader, pos, direction)) { - return blockstate.setValue(FACING, direction.getOpposite()); - } - } - - return null; - } - - // Break the fixture if the block it is attached to is changed so that it could - // no longer be placed - @Override - public BlockState updateShape(BlockState blockState, Direction facing, BlockState facingState, LevelAccessor level, - BlockPos currentPos, BlockPos facingPos) { - if (blockState.getValue(WATERLOGGED).booleanValue()) { - level.scheduleTick(currentPos, Fluids.WATER, Fluids.WATER.getTickDelay(level)); - } - - Direction fixtureFacing = blockState.getValue(FACING); - if (facing.getOpposite() == fixtureFacing && !canPlaceAt(level, currentPos, facing)) { - return Blocks.AIR.defaultBlockState(); - } - return blockState; - } - - @Override - public boolean isValidOrientation(LevelAccessor level, BlockPos pos, Direction forward, - Direction up) { - // FIXME: I think this entire method -> not required, but not sure... are quartz - // fixtures rotateable??? - return this.canPlaceAt(level, pos, up.getOpposite()); - } - - private boolean canPlaceAt(LevelReader level, BlockPos pos, Direction dir) { - return canSupportCenter(level, pos.relative(dir), dir.getOpposite()); - } - - @Override - public VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) { - Direction facing = state.getValue(FACING); - return SHAPES.get(facing); - } - - @Override - @Environment(EnvType.CLIENT) - public void animateTick(BlockState state, Level level, BlockPos pos, RandomSource r) { - if (!AEConfig.instance().isEnableEffects()) { - return; - } - - if (r.nextFloat() < 0.98) { - return; - } - - final Direction up = this.getOrientable(level, pos).getUp(); - final double xOff = -0.3 * up.getStepX(); - final double yOff = -0.3 * up.getStepY(); - final double zOff = -0.3 * up.getStepZ(); - for (int bolts = 0; bolts < 3; bolts++) { - if (AppEngClient.instance().shouldAddParticles(r)) { - level.addParticle(ParticleTypes.LIGHTNING, xOff + 0.5 + pos.getX(), yOff + 0.5 + pos.getY(), - zOff + 0.5 + pos.getZ(), 0, 0, 0); - } - } - } - - // FIXME: Replaced by the postPlaceupdate stuff above, but check item drops! - @Override - public void neighborChanged(BlockState state, Level level, BlockPos pos, Block blockIn, BlockPos fromPos, - boolean isMoving) { - final Direction up = this.getOrientable(level, pos).getUp(); - if (!this.canPlaceAt(level, pos, up.getOpposite())) { - this.dropTorch(level, pos); - } - } - - private void dropTorch(Level level, BlockPos pos) { - final BlockState prev = level.getBlockState(pos); - level.destroyBlock(pos, true); - level.sendBlockUpdated(pos, prev, level.getBlockState(pos), 3); - } - - @Override - public boolean canSurvive(BlockState state, LevelReader level, BlockPos pos) { - for (Direction dir : Direction.values()) { - if (this.canPlaceAt(level, pos, dir)) { - return true; - } - } - return false; - } - - @Override - public IOrientable getOrientable(BlockGetter level, BlockPos pos) { - return new MetaRotation(level, pos, FACING); - } - - @Override - public FluidState getFluidState(BlockState blockState) { - return blockState.getValue(WATERLOGGED).booleanValue() - ? Fluids.WATER.getSource(false) - : super.getFluidState(blockState); - } - -} diff --git a/src/main/java/appeng/block/misc/QuartzGrowthAcceleratorBlock.java b/src/main/java/appeng/block/misc/QuartzGrowthAcceleratorBlock.java deleted file mode 100644 index 41c5584119a..00000000000 --- a/src/main/java/appeng/block/misc/QuartzGrowthAcceleratorBlock.java +++ /dev/null @@ -1,138 +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.misc; - -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.minecraft.client.Minecraft; -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.util.RandomSource; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.SoundType; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.state.StateDefinition.Builder; -import net.minecraft.world.level.block.state.properties.BooleanProperty; -import net.minecraft.world.level.material.Material; - -import appeng.api.util.IOrientableBlock; -import appeng.block.AEBaseEntityBlock; -import appeng.blockentity.misc.QuartzGrowthAcceleratorBlockEntity; -import appeng.client.render.effects.ParticleTypes; -import appeng.core.AEConfig; -import appeng.core.AppEngClient; -import appeng.util.Platform; - -public class QuartzGrowthAcceleratorBlock extends AEBaseEntityBlock - implements IOrientableBlock { - - private static final BooleanProperty POWERED = BooleanProperty.create("powered"); - - public QuartzGrowthAcceleratorBlock() { - super(defaultProps(Material.STONE).sound(SoundType.METAL)); - this.registerDefaultState(this.defaultBlockState().setValue(POWERED, false)); - } - - @Override - protected BlockState updateBlockStateFromBlockEntity(BlockState currentState, - QuartzGrowthAcceleratorBlockEntity be) { - return currentState.setValue(POWERED, be.isPowered()); - } - - @Override - protected void createBlockStateDefinition(Builder builder) { - super.createBlockStateDefinition(builder); - builder.add(POWERED); - } - - @Environment(EnvType.CLIENT) - @Override - public void animateTick(BlockState state, Level level, BlockPos pos, RandomSource r) { - if (!AEConfig.instance().isEnableEffects()) { - return; - } - - final QuartzGrowthAcceleratorBlockEntity cga = this.getBlockEntity(level, pos); - - if (cga != null && cga.isPowered() && AppEngClient.instance().shouldAddParticles(r)) { - final double d0 = r.nextFloat() - 0.5F; - final double d1 = r.nextFloat() - 0.5F; - - final Direction up = cga.getUp(); - final Direction forward = cga.getForward(); - final Direction west = Platform.crossProduct(forward, up); - - double rx = 0.5 + pos.getX(); - double ry = 0.5 + pos.getY(); - double rz = 0.5 + pos.getZ(); - - rx += up.getStepX() * d0; - ry += up.getStepY() * d0; - rz += up.getStepZ() * d0; - - final int x = pos.getX(); - final int y = pos.getY(); - final int z = pos.getZ(); - - double dz = 0; - double dx = 0; - BlockPos pt = null; - - switch (r.nextInt(4)) { - case 0 -> { - dx = 0.6; - dz = d1; - pt = new BlockPos(x + west.getStepX(), y + west.getStepY(), z + west.getStepZ()); - } - case 1 -> { - dx = d1; - dz += 0.6; - pt = new BlockPos(x + forward.getStepX(), y + forward.getStepY(), z + forward.getStepZ()); - } - case 2 -> { - dx = d1; - dz = -0.6; - pt = new BlockPos(x - forward.getStepX(), y - forward.getStepY(), z - forward.getStepZ()); - } - case 3 -> { - dx = -0.6; - dz = d1; - pt = new BlockPos(x - west.getStepX(), y - west.getStepY(), z - west.getStepZ()); - } - } - - if (!level.getBlockState(pt).isAir()) { - return; - } - - rx += dx * west.getStepX(); - ry += dx * west.getStepY(); - rz += dx * west.getStepZ(); - - rx += dz * forward.getStepX(); - ry += dz * forward.getStepY(); - rz += dz * forward.getStepZ(); - - Minecraft.getInstance().particleEngine.createParticle(ParticleTypes.LIGHTNING, rx, ry, rz, 0.0D, 0.0D, - 0.0D); - } - } - -} diff --git a/src/main/java/appeng/block/misc/SecurityStationBlock.java b/src/main/java/appeng/block/misc/SecurityStationBlock.java index ba72d34cff0..80d39c3afe3 100644 --- a/src/main/java/appeng/block/misc/SecurityStationBlock.java +++ b/src/main/java/appeng/block/misc/SecurityStationBlock.java @@ -29,7 +29,6 @@ import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.StateDefinition.Builder; -import net.minecraft.world.level.block.state.properties.BooleanProperty; import net.minecraft.world.level.material.Material; import net.minecraft.world.phys.BlockHitResult; @@ -38,24 +37,13 @@ import appeng.util.InteractionUtil; public class SecurityStationBlock extends AEBaseEntityBlock { - - private static final BooleanProperty POWERED = BooleanProperty.create("powered"); - public SecurityStationBlock() { super(defaultProps(Material.METAL)); - - this.registerDefaultState(this.defaultBlockState().setValue(POWERED, false)); } @Override protected void createBlockStateDefinition(Builder builder) { super.createBlockStateDefinition(builder); - builder.add(POWERED); - } - - @Override - protected BlockState updateBlockStateFromBlockEntity(BlockState currentState, SecurityStationBlockEntity be) { - return currentState.setValue(POWERED, be.isActive()); } @Override diff --git a/src/main/java/appeng/block/misc/TinyTNTBlock.java b/src/main/java/appeng/block/misc/TinyTNTBlock.java deleted file mode 100644 index c3d00056c52..00000000000 --- a/src/main/java/appeng/block/misc/TinyTNTBlock.java +++ /dev/null @@ -1,146 +0,0 @@ -/* - * This file is part of Applied Energistics 2. - * Copyright (c) 2013 - 2015, 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.misc; - -import net.minecraft.core.BlockPos; -import net.minecraft.sounds.SoundEvents; -import net.minecraft.sounds.SoundSource; -import net.minecraft.world.InteractionHand; -import net.minecraft.world.InteractionResult; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.entity.projectile.AbstractArrow; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.Items; -import net.minecraft.world.level.BlockGetter; -import net.minecraft.world.level.Explosion; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockBehaviour; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.phys.AABB; -import net.minecraft.world.phys.BlockHitResult; -import net.minecraft.world.phys.shapes.CollisionContext; -import net.minecraft.world.phys.shapes.Shapes; -import net.minecraft.world.phys.shapes.VoxelShape; - -import appeng.block.AEBaseBlock; -import appeng.entity.TinyTNTPrimedEntity; - -public class TinyTNTBlock extends AEBaseBlock { - - private static final VoxelShape SHAPE = Shapes - .create(new AABB(0.25f, 0.0f, 0.25f, 0.75f, 0.5f, 0.75f)); - - public TinyTNTBlock(BlockBehaviour.Properties props) { - super(props); - } - - @Override - public int getLightBlock(BlockState state, BlockGetter level, BlockPos pos) { - return 2; // FIXME: Validate that this is the correct value range - } - - @Override - public VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) { - return SHAPE; - } - - @Override - public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, - InteractionHand handIn, BlockHitResult hit) { - ItemStack heldItem = player.getItemInHand(handIn); - if (!heldItem.isEmpty() && heldItem.getItem() == Items.FLINT_AND_STEEL) { - this.startFuse(level, pos, player); - level.removeBlock(pos, false); - heldItem.hurtAndBreak(1, player, p -> { - p.broadcastBreakEvent(handIn); - }); // FIXME Check if onBroken is equivalent - return InteractionResult.sidedSuccess(level.isClientSide()); - } else { - return super.use(state, level, pos, player, handIn, hit); - } - } - - public void startFuse(Level level, BlockPos pos, LivingEntity igniter) { - if (!level.isClientSide) { - final TinyTNTPrimedEntity primedTinyTNTEntity = new TinyTNTPrimedEntity(level, pos.getX() + 0.5F, - pos.getY() + 0.5F, pos.getZ() + 0.5F, igniter); - level.addFreshEntity(primedTinyTNTEntity); - level.playSound(null, primedTinyTNTEntity.getX(), primedTinyTNTEntity.getY(), - primedTinyTNTEntity.getZ(), SoundEvents.TNT_PRIMED, SoundSource.BLOCKS, 1, 1); - } - } - - @Override - public void neighborChanged(BlockState state, Level level, BlockPos pos, Block blockIn, BlockPos fromPos, - boolean isMoving) { - if (level.getBestNeighborSignal(pos) > 0) { - this.startFuse(level, pos, null); - level.removeBlock(pos, false); - } - } - - @Override - public void onPlace(BlockState state, Level level, BlockPos pos, BlockState oldState, boolean isMoving) { - super.onPlace(state, level, pos, oldState, isMoving); - - if (level.getBestNeighborSignal(pos) > 0) { - this.startFuse(level, pos, null); - level.removeBlock(pos, false); - } - } - - @Override - public void stepOn(Level level, BlockPos pos, BlockState state, Entity entity) { - if (!level.isClientSide && entity instanceof AbstractArrow arrow) { - - if (arrow.isOnFire()) { - LivingEntity igniter = null; - // Check if the shooter still exists - Entity shooter = arrow.getOwner(); - if (shooter instanceof LivingEntity) { - igniter = (LivingEntity) shooter; - } - this.startFuse(level, pos, igniter); - level.removeBlock(pos, false); - } - } - } - - @Override - public boolean dropFromExplosion(Explosion exp) { - return false; - } - - @Override - public void wasExploded(Level level, BlockPos pos, Explosion exp) { - super.wasExploded(level, pos, exp); - if (!level.isClientSide) { - final TinyTNTPrimedEntity primedTinyTNTEntity = new TinyTNTPrimedEntity(level, pos.getX() + 0.5F, - pos.getY() + 0.5F, pos.getZ() + 0.5F, exp.getSourceMob()); - primedTinyTNTEntity - .setFuse(level.random.nextInt(primedTinyTNTEntity.getFuse() / 4) - + primedTinyTNTEntity.getFuse() / 8); - level.addFreshEntity(primedTinyTNTEntity); - } - } - -} diff --git a/src/main/java/appeng/block/misc/VibrationChamberBlock.java b/src/main/java/appeng/block/misc/VibrationChamberBlock.java deleted file mode 100644 index f5c9e766578..00000000000 --- a/src/main/java/appeng/block/misc/VibrationChamberBlock.java +++ /dev/null @@ -1,127 +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.misc; - -import javax.annotation.Nullable; - -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.core.particles.ParticleTypes; -import net.minecraft.util.RandomSource; -import net.minecraft.world.InteractionHand; -import net.minecraft.world.InteractionResult; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.state.StateDefinition.Builder; -import net.minecraft.world.level.block.state.properties.BooleanProperty; -import net.minecraft.world.level.material.Material; -import net.minecraft.world.phys.BlockHitResult; - -import appeng.block.AEBaseEntityBlock; -import appeng.blockentity.misc.VibrationChamberBlockEntity; -import appeng.core.AEConfig; -import appeng.menu.MenuOpener; -import appeng.menu.implementations.VibrationChamberMenu; -import appeng.menu.locator.MenuLocators; -import appeng.util.InteractionUtil; - -public final class VibrationChamberBlock extends AEBaseEntityBlock { - - // Indicates that the vibration chamber is currently working - public static final BooleanProperty ACTIVE = BooleanProperty.create("active"); - - public VibrationChamberBlock() { - super(defaultProps(Material.METAL).strength(4.2F)); - this.registerDefaultState(this.defaultBlockState().setValue(ACTIVE, false)); - } - - @Override - protected BlockState updateBlockStateFromBlockEntity(BlockState currentState, VibrationChamberBlockEntity be) { - return currentState.setValue(ACTIVE, be.isOn); - } - - @Override - protected void createBlockStateDefinition(Builder builder) { - super.createBlockStateDefinition(builder); - builder.add(ACTIVE); - } - - @Override - public InteractionResult onActivated(Level level, BlockPos pos, Player player, - InteractionHand hand, - @Nullable ItemStack heldItem, BlockHitResult hit) { - if (InteractionUtil.isInAlternateUseMode(player)) { - return InteractionResult.PASS; - } - - if (!level.isClientSide()) { - final VibrationChamberBlockEntity tc = this.getBlockEntity(level, pos); - if (tc != null) { - hit.getDirection(); - MenuOpener.open(VibrationChamberMenu.TYPE, player, - MenuLocators.forBlockEntity(tc)); - } - } - - return InteractionResult.sidedSuccess(level.isClientSide()); - } - - @Override - public void animateTick(BlockState state, Level level, BlockPos pos, RandomSource r) { - if (!AEConfig.instance().isEnableEffects()) { - return; - } - - final VibrationChamberBlockEntity tc = this.getBlockEntity(level, pos); - if (tc != null && tc.isOn) { - double f1 = pos.getX() + 0.5F; - double f2 = pos.getY() + 0.5F; - double f3 = pos.getZ() + 0.5F; - - final Direction forward = tc.getForward(); - final Direction up = tc.getUp(); - - // Cross-Product of forward/up directional vector - final int west_x = forward.getStepY() * up.getStepZ() - forward.getStepZ() * up.getStepY(); - final int west_y = forward.getStepZ() * up.getStepX() - forward.getStepX() * up.getStepZ(); - final int west_z = forward.getStepX() * up.getStepY() - forward.getStepY() * up.getStepX(); - - f1 += forward.getStepX() * 0.6; - f2 += forward.getStepY() * 0.6; - f3 += forward.getStepZ() * 0.6; - - final double ox = r.nextDouble(); - final double oy = r.nextDouble() * 0.2f; - - f1 += up.getStepX() * (-0.3 + oy); - f2 += up.getStepY() * (-0.3 + oy); - f3 += up.getStepZ() * (-0.3 + oy); - - f1 += west_x * (0.3 * ox - 0.15); - f2 += west_y * (0.3 * ox - 0.15); - f3 += west_z * (0.3 * ox - 0.15); - - level.addParticle(ParticleTypes.SMOKE, f1, f2, f3, 0.0D, 0.0D, 0.0D); - level.addParticle(ParticleTypes.FLAME, f1, f2, f3, 0.0D, 0.0D, 0.0D); - } - } -} diff --git a/src/main/java/appeng/block/networking/CableBusBlock.java b/src/main/java/appeng/block/networking/CableBusBlock.java index 3f2d3ca7fe7..f0aec169479 100644 --- a/src/main/java/appeng/block/networking/CableBusBlock.java +++ b/src/main/java/appeng/block/networking/CableBusBlock.java @@ -84,12 +84,11 @@ import appeng.hooks.ICustomPickBlock; import appeng.hooks.IDynamicLadder; import appeng.hooks.INeighborChangeSensitive; -import appeng.integration.abstraction.IAEFacade; import appeng.parts.ICableBusContainer; import appeng.parts.NullCableBusContainer; import appeng.util.Platform; -public class CableBusBlock extends AEBaseEntityBlock implements IAEFacade, SimpleWaterloggedBlock, +public class CableBusBlock extends AEBaseEntityBlock implements SimpleWaterloggedBlock, ICustomBlockHitEffect, ICustomBlockDestroyEffect, INeighborChangeSensitive, IDynamicLadder, ICustomPickBlock { private static final ICableBusContainer NULL_CABLE_BUS = new NullCableBusContainer(); @@ -190,8 +189,6 @@ public ItemStack getPickBlock(BlockState state, HitResult target, BlockGetter le if (sp.part != null) { return new ItemStack(sp.part.getPartItem()); - } else if (sp.facade != null) { - return sp.facade.getItemStack(); } return ItemStack.EMPTY; @@ -216,18 +213,6 @@ private ICableBusContainer cb(BlockGetter level, BlockPos pos) { return out == null ? NULL_CABLE_BUS : out; } - @Nullable - private IFacadeContainer fc(BlockGetter level, BlockPos pos) { - final BlockEntity te = level.getBlockEntity(pos); - IFacadeContainer out = null; - - if (te instanceof CableBusBlockEntity) { - out = ((CableBusBlockEntity) te).getCableBus().getFacadeContainer(); - } - - return out; - } - @Override public InteractionResult onActivated(Level level, BlockPos pos, Player player, InteractionHand hand, @@ -255,20 +240,6 @@ public void fillItemCategory(CreativeModeTab group, NonNullList itemS // do nothing } - @Override - public BlockState getFacadeState(BlockGetter level, BlockPos pos, Direction side) { - if (side != null) { - IFacadeContainer container = this.fc(level, pos); - if (container != null) { - IFacadePart facade = container.getFacade(side); - if (facade != null) { - return facade.getBlockState(); - } - } - } - return level.getBlockState(pos); - } - @Override public VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) { CableBusBlockEntity te = getBlockEntity(level, pos); @@ -434,22 +405,6 @@ public boolean addDestroyEffects(BlockState state, Level level, BlockPos pos, @Override public BlockState getAppearance(BlockState state, BlockAndTintGetter renderView, BlockPos pos, Direction side, @Nullable BlockState sourceState, @Nullable BlockPos sourcePos) { - if (((RenderAttachedBlockView) renderView) - .getBlockEntityRenderAttachment(pos) instanceof CableBusRenderState cableBusRenderState) { - var renderingFacadeDir = RENDERING_FACADE_DIRECTION.get(); - var facades = cableBusRenderState.getFacades(); - - if (side.getOpposite() != renderingFacadeDir) { - var facadeState = facades.get(side); - if (facadeState != null) { - return facadeState.getSourceBlock(); - } - } - - if (renderingFacadeDir != null && facades.containsKey(renderingFacadeDir)) { - return facades.get(renderingFacadeDir).getSourceBlock(); - } - } return state; } } diff --git a/src/main/java/appeng/block/networking/ControllerBlock.java b/src/main/java/appeng/block/networking/ControllerBlock.java index 463205ed03b..ecb3da70f0b 100644 --- a/src/main/java/appeng/block/networking/ControllerBlock.java +++ b/src/main/java/appeng/block/networking/ControllerBlock.java @@ -41,7 +41,6 @@ import appeng.blockentity.networking.ControllerBlockEntity; import appeng.menu.MenuOpener; import appeng.menu.locator.MenuLocators; -import appeng.menu.me.networktool.NetworkStatusMenu; public class ControllerBlock extends AEBaseEntityBlock { @@ -149,9 +148,6 @@ public InteractionResult onActivated(Level level, BlockPos pos, Player player, I @org.jetbrains.annotations.Nullable ItemStack heldItem, BlockHitResult hit) { var controller = getBlockEntity(level, pos); if (controller != null) { - if (!level.isClientSide) { - MenuOpener.open(NetworkStatusMenu.CONTROLLER_TYPE, player, MenuLocators.forBlockEntity(controller)); - } return InteractionResult.sidedSuccess(level.isClientSide); } return InteractionResult.FAIL; diff --git a/src/main/java/appeng/block/networking/CreativeEnergyCellBlock.java b/src/main/java/appeng/block/networking/CreativeEnergyCellBlock.java deleted file mode 100644 index c84969b7049..00000000000 --- a/src/main/java/appeng/block/networking/CreativeEnergyCellBlock.java +++ /dev/null @@ -1,30 +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.networking; - -import appeng.block.AEBaseEntityBlock; -import appeng.blockentity.networking.CreativeEnergyCellBlockEntity; -import appeng.helpers.AEMaterials; - -public class CreativeEnergyCellBlock extends AEBaseEntityBlock { - - public CreativeEnergyCellBlock() { - super(defaultProps(AEMaterials.GLASS)); - } -} diff --git a/src/main/java/appeng/block/networking/EnergyAcceptorBlock.java b/src/main/java/appeng/block/networking/EnergyAcceptorBlock.java deleted file mode 100644 index 8ea636309eb..00000000000 --- a/src/main/java/appeng/block/networking/EnergyAcceptorBlock.java +++ /dev/null @@ -1,31 +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.networking; - -import net.minecraft.world.level.material.Material; - -import appeng.block.AEBaseEntityBlock; -import appeng.blockentity.networking.EnergyAcceptorBlockEntity; - -public class EnergyAcceptorBlock extends AEBaseEntityBlock { - - public EnergyAcceptorBlock() { - super(defaultProps(Material.METAL)); - } -} diff --git a/src/main/java/appeng/block/networking/EnergyCellBlock.java b/src/main/java/appeng/block/networking/EnergyCellBlock.java deleted file mode 100644 index 8b64453d27f..00000000000 --- a/src/main/java/appeng/block/networking/EnergyCellBlock.java +++ /dev/null @@ -1,103 +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.networking; - -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.minecraft.core.BlockPos; -import net.minecraft.core.NonNullList; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.util.Mth; -import net.minecraft.world.item.CreativeModeTab; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.state.StateDefinition.Builder; -import net.minecraft.world.level.block.state.properties.IntegerProperty; - -import appeng.block.AEBaseEntityBlock; -import appeng.blockentity.networking.EnergyCellBlockEntity; -import appeng.helpers.AEMaterials; - -public class EnergyCellBlock extends AEBaseEntityBlock { - - public static final int MAX_FULLNESS = 4; - - public static final IntegerProperty ENERGY_STORAGE = IntegerProperty.create("fullness", 0, MAX_FULLNESS); - - private final double maxPower; - private final double chargeRate; - private final int priority; - - public EnergyCellBlock(double maxPower, double chargeRate, int priority) { - super(defaultProps(AEMaterials.GLASS)); - this.maxPower = maxPower; - this.chargeRate = chargeRate; - this.priority = priority; - } - - @Override - @Environment(EnvType.CLIENT) - public void fillItemCategory(CreativeModeTab group, NonNullList itemStacks) { - super.fillItemCategory(group, itemStacks); - - final ItemStack charged = new ItemStack(this, 1); - final CompoundTag tag = charged.getOrCreateTag(); - tag.putDouble("internalCurrentPower", this.getMaxPower()); - tag.putDouble("internalMaxPower", this.getMaxPower()); - - itemStacks.add(charged); - } - - public double getMaxPower() { - return this.maxPower; - } - - public double getChargeRate() { - return this.chargeRate; - } - - public int getPriority() { - return this.priority; - } - - @Override - protected void createBlockStateDefinition(Builder builder) { - super.createBlockStateDefinition(builder); - builder.add(ENERGY_STORAGE); - } - - @Override - public boolean hasAnalogOutputSignal(BlockState state) { - return true; - } - - @Override - public int getAnalogOutputSignal(BlockState state, Level level, BlockPos pos) { - var cell = getBlockEntity(level, pos); - if (cell != null) { - var currentPower = cell.getAECurrentPower(); - var maxPower = cell.getAEMaxPower(); - var fillFactor = currentPower / maxPower; - return Mth.floor(fillFactor * 14.0F) + (currentPower > 0 ? 1 : 0); - } - return 0; - } -} diff --git a/src/main/java/appeng/block/networking/EnergyCellBlockItem.java b/src/main/java/appeng/block/networking/EnergyCellBlockItem.java deleted file mode 100644 index 3d12716b0d1..00000000000 --- a/src/main/java/appeng/block/networking/EnergyCellBlockItem.java +++ /dev/null @@ -1,128 +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.networking; - -import java.util.List; - -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.network.chat.Component; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.TooltipFlag; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.Block; - -import appeng.api.config.AccessRestriction; -import appeng.api.config.Actionable; -import appeng.api.implementations.items.IAEItemPowerStorage; -import appeng.block.AEBaseBlockItem; -import appeng.core.localization.Tooltips; - -public class EnergyCellBlockItem extends AEBaseBlockItem implements IAEItemPowerStorage { - - public EnergyCellBlockItem(Block block, Item.Properties props) { - super(block, props); - } - - @Override - @Environment(EnvType.CLIENT) - public void addCheckedInformation(ItemStack stack, Level level, List lines, - TooltipFlag advancedTooltips) { - double internalCurrentPower = 0; - final double internalMaxPower = this.getMaxEnergyCapacity(); - - if (internalMaxPower > 0) { - final CompoundTag tag = stack.getTag(); - if (tag != null) { - internalCurrentPower = tag.getDouble("internalCurrentPower"); - } - - lines.add( - Tooltips.energyStorageComponent(internalCurrentPower, internalMaxPower)); - } - } - - @Override - public double injectAEPower(ItemStack is, double amount, Actionable mode) { - final double internalCurrentPower = this.getInternal(is); - final double internalMaxPower = this.getAEMaxPower(is); - final double required = internalMaxPower - internalCurrentPower; - final double overflow = Math.max(0, Math.min(amount - required, amount)); - - if (mode == Actionable.MODULATE) { - final double toAdd = Math.min(required, amount); - final double newPowerStored = internalCurrentPower + toAdd; - - this.setInternal(is, newPowerStored); - } - - return overflow; - } - - @Override - public double extractAEPower(ItemStack is, double amount, Actionable mode) { - final double internalCurrentPower = this.getInternal(is); - final double fulfillable = Math.min(amount, internalCurrentPower); - - if (mode == Actionable.MODULATE) { - final double newPowerStored = internalCurrentPower - fulfillable; - - this.setInternal(is, newPowerStored); - } - - return fulfillable; - } - - @Override - public double getAEMaxPower(ItemStack is) { - return this.getMaxEnergyCapacity(); - } - - @Override - public double getAECurrentPower(ItemStack is) { - return this.getInternal(is); - } - - @Override - public AccessRestriction getPowerFlow(ItemStack is) { - return AccessRestriction.WRITE; - } - - @Override - public double getChargeRate(ItemStack stack) { - return ((EnergyCellBlock) getBlock()).getChargeRate(); - } - - private double getMaxEnergyCapacity() { - return ((EnergyCellBlock) getBlock()).getMaxPower(); - } - - private double getInternal(ItemStack is) { - final CompoundTag nbt = is.getOrCreateTag(); - return nbt.getDouble("internalCurrentPower"); - } - - private void setInternal(ItemStack is, double amt) { - final CompoundTag nbt = is.getOrCreateTag(); - nbt.putDouble("internalCurrentPower", amt); - } - -} diff --git a/src/main/java/appeng/block/networking/WirelessBlock.java b/src/main/java/appeng/block/networking/WirelessBlock.java index bf68d10641b..fa284a327c1 100644 --- a/src/main/java/appeng/block/networking/WirelessBlock.java +++ b/src/main/java/appeng/block/networking/WirelessBlock.java @@ -50,9 +50,6 @@ import appeng.block.AEBaseEntityBlock; import appeng.blockentity.networking.WirelessBlockEntity; import appeng.helpers.AEMaterials; -import appeng.menu.MenuOpener; -import appeng.menu.implementations.WirelessMenu; -import appeng.menu.locator.MenuLocators; import appeng.util.InteractionUtil; public class WirelessBlock extends AEBaseEntityBlock implements SimpleWaterloggedBlock { @@ -82,7 +79,7 @@ protected BlockState updateBlockStateFromBlockEntity(BlockState currentState, Wi if (be.isActive()) { teState = State.HAS_CHANNEL; - } else if (be.isPowered()) { + } else { teState = State.ON; } @@ -104,8 +101,6 @@ public InteractionResult use(BlockState state, Level level, BlockPos pos, Player if (tg != null && !InteractionUtil.isInAlternateUseMode(player)) { if (!level.isClientSide()) { hit.getDirection(); - MenuOpener.open(WirelessMenu.TYPE, player, - MenuLocators.forBlockEntity(tg)); } return InteractionResult.sidedSuccess(level.isClientSide()); } diff --git a/src/main/java/appeng/block/paint/PaintSplotches.java b/src/main/java/appeng/block/paint/PaintSplotches.java deleted file mode 100644 index 036ed76adf2..00000000000 --- a/src/main/java/appeng/block/paint/PaintSplotches.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * This file is part of Applied Energistics 2. - * Copyright (c) 2021, 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.block.paint; - -import java.util.Collection; -import java.util.List; - -import com.google.common.collect.ImmutableList; - -import appeng.helpers.Splotch; - -/** - * Used to transfer the state about paint splotches from the game thread to the render thread. - */ -public class PaintSplotches { - - private final List splotches; - - public PaintSplotches(Collection splotches) { - this.splotches = ImmutableList.copyOf(splotches); - } - - List getSplotches() { - return this.splotches; - } - -} diff --git a/src/main/java/appeng/block/paint/PaintSplotchesBakedModel.java b/src/main/java/appeng/block/paint/PaintSplotchesBakedModel.java deleted file mode 100644 index f87db0a13f8..00000000000 --- a/src/main/java/appeng/block/paint/PaintSplotchesBakedModel.java +++ /dev/null @@ -1,203 +0,0 @@ -/* - * This file is part of Applied Energistics 2. - * Copyright (c) 2021, 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.block.paint; - -import java.util.Collections; -import java.util.List; -import java.util.function.Function; -import java.util.function.Supplier; - -import javax.annotation.Nullable; - -import com.google.common.collect.ImmutableList; - -import net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel; -import net.fabricmc.fabric.api.renderer.v1.render.RenderContext; -import net.fabricmc.fabric.api.rendering.data.v1.RenderAttachedBlockView; -import net.minecraft.client.renderer.block.model.BakedQuad; -import net.minecraft.client.renderer.block.model.ItemOverrides; -import net.minecraft.client.renderer.block.model.ItemTransforms; -import net.minecraft.client.renderer.texture.TextureAtlas; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.client.resources.model.BakedModel; -import net.minecraft.client.resources.model.Material; -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.util.RandomSource; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.BlockAndTintGetter; -import net.minecraft.world.level.block.state.BlockState; - -import appeng.client.render.cablebus.CubeBuilder; -import appeng.core.AppEng; -import appeng.helpers.Splotch; - -/** - * Renders paint blocks, which render multiple "splotches" that have been applied to the sides of adjacent blocks using - * a matter cannon with paint balls. - */ -class PaintSplotchesBakedModel implements BakedModel, FabricBakedModel { - - private static final Material TEXTURE_PAINT1 = new Material(TextureAtlas.LOCATION_BLOCKS, - new ResourceLocation(AppEng.MOD_ID, "block/paint1")); - private static final Material TEXTURE_PAINT2 = new Material(TextureAtlas.LOCATION_BLOCKS, - new ResourceLocation(AppEng.MOD_ID, "block/paint2")); - private static final Material TEXTURE_PAINT3 = new Material(TextureAtlas.LOCATION_BLOCKS, - new ResourceLocation(AppEng.MOD_ID, "block/paint3")); - - private final TextureAtlasSprite[] textures; - - PaintSplotchesBakedModel(Function bakedTextureGetter) { - this.textures = new TextureAtlasSprite[] { bakedTextureGetter.apply(TEXTURE_PAINT1), - bakedTextureGetter.apply(TEXTURE_PAINT2), bakedTextureGetter.apply(TEXTURE_PAINT3) }; - } - - @Override - public boolean isVanillaAdapter() { - return false; - } - - @Override - public void emitBlockQuads(BlockAndTintGetter blockView, BlockState state, BlockPos pos, - Supplier randomSupplier, RenderContext context) { - - Object renderAttachment = ((RenderAttachedBlockView) blockView).getBlockEntityRenderAttachment(pos); - if (!(renderAttachment instanceof PaintSplotches)) { - return; - } - PaintSplotches splotchesState = (PaintSplotches) renderAttachment; - - List splotches = splotchesState.getSplotches(); - - CubeBuilder builder = new CubeBuilder(context.getEmitter()); - - float offsetConstant = 0.001f; - for (Splotch s : splotches) { - - if (s.isLumen()) { - builder.setColorRGB(s.getColor().whiteVariant); - builder.setEmissiveMaterial(true); - } else { - builder.setColorRGB(s.getColor().mediumVariant); - builder.setEmissiveMaterial(false); - } - - float offset = offsetConstant; - offsetConstant += 0.001f; - - final float buffer = 0.1f; - - float pos_x = s.x(); - float pos_y = s.y(); - - pos_x = Math.max(buffer, Math.min(1.0f - buffer, pos_x)); - pos_y = Math.max(buffer, Math.min(1.0f - buffer, pos_y)); - - TextureAtlasSprite ico = this.textures[s.getSeed() % this.textures.length]; - builder.setTexture(ico); - builder.setCustomUv(s.getSide().getOpposite(), 0, 0, 16, 16); - - switch (s.getSide()) { - case UP: - offset = 1.0f - offset; - builder.addQuad(Direction.DOWN, pos_x - buffer, offset, pos_y - buffer, pos_x + buffer, offset, - pos_y + buffer); - break; - - case DOWN: - builder.addQuad(Direction.UP, pos_x - buffer, offset, pos_y - buffer, pos_x + buffer, offset, - pos_y + buffer); - break; - - case EAST: - offset = 1.0f - offset; - builder.addQuad(Direction.WEST, offset, pos_x - buffer, pos_y - buffer, offset, pos_x + buffer, - pos_y + buffer); - break; - - case WEST: - builder.addQuad(Direction.EAST, offset, pos_x - buffer, pos_y - buffer, offset, pos_x + buffer, - pos_y + buffer); - break; - - case SOUTH: - offset = 1.0f - offset; - builder.addQuad(Direction.NORTH, pos_x - buffer, pos_y - buffer, offset, pos_x + buffer, - pos_y + buffer, offset); - break; - - case NORTH: - builder.addQuad(Direction.SOUTH, pos_x - buffer, pos_y - buffer, offset, pos_x + buffer, - pos_y + buffer, offset); - break; - - default: - } - } - } - - @Override - public void emitItemQuads(ItemStack stack, Supplier randomSupplier, RenderContext context) { - } - - @Override - public List getQuads(@Nullable BlockState state, @Nullable Direction face, RandomSource random) { - return Collections.emptyList(); - } - - @Override - public ItemTransforms getTransforms() { - return ItemTransforms.NO_TRANSFORMS; - } - - @Override - public boolean useAmbientOcclusion() { - return false; - } - - @Override - public boolean isGui3d() { - return true; - } - - @Override - public boolean isCustomRenderer() { - return false; - } - - @Override - public TextureAtlasSprite getParticleIcon() { - return this.textures[0]; - } - - @Override - public ItemOverrides getOverrides() { - return ItemOverrides.EMPTY; - } - - @Override - public boolean usesBlockLight() { - return false; - } - - static List getRequiredTextures() { - return ImmutableList.of(TEXTURE_PAINT1, TEXTURE_PAINT2, TEXTURE_PAINT3); - } -} diff --git a/src/main/java/appeng/block/paint/PaintSplotchesBlock.java b/src/main/java/appeng/block/paint/PaintSplotchesBlock.java deleted file mode 100644 index 8ed08996d19..00000000000 --- a/src/main/java/appeng/block/paint/PaintSplotchesBlock.java +++ /dev/null @@ -1,109 +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.paint; - -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.minecraft.core.BlockPos; -import net.minecraft.core.NonNullList; -import net.minecraft.world.item.CreativeModeTab; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.context.BlockPlaceContext; -import net.minecraft.world.level.BlockGetter; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.state.StateDefinition; -import net.minecraft.world.level.block.state.properties.IntegerProperty; -import net.minecraft.world.level.material.Fluid; -import net.minecraft.world.level.material.Material; -import net.minecraft.world.level.material.MaterialColor; -import net.minecraft.world.phys.shapes.CollisionContext; -import net.minecraft.world.phys.shapes.Shapes; -import net.minecraft.world.phys.shapes.VoxelShape; - -import appeng.block.AEBaseEntityBlock; -import appeng.blockentity.misc.PaintSplotchesBlockEntity; - -public class PaintSplotchesBlock extends AEBaseEntityBlock { - - /** - * Lumen paint splotches contribute light-level 12, two or more have light-level 15. We model this with 0 = 0, 1 = - * 12, 2 = 15. - */ - public static final IntegerProperty LIGHT_LEVEL = IntegerProperty.create("light_level", 0, 2); - - public PaintSplotchesBlock() { - super(defaultProps(Material.WATER, MaterialColor.NONE).noOcclusion().air().lightLevel(state -> { - var lightLevel = state.getValue(LIGHT_LEVEL); - return switch (lightLevel) { - default -> 0; - case 1 -> 12; - case 2 -> 15; - }; - })); - registerDefaultState(defaultBlockState().setValue(LIGHT_LEVEL, 0)); - } - - @Override - protected void createBlockStateDefinition(StateDefinition.Builder builder) { - super.createBlockStateDefinition(builder); - builder.add(LIGHT_LEVEL); - } - - @Override - @Environment(EnvType.CLIENT) - public void fillItemCategory(CreativeModeTab group, NonNullList itemStacks) { - // do nothing - } - - @Override - public VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) { - return Shapes.empty(); - } - - @Override - public void neighborChanged(BlockState state, Level level, BlockPos pos, Block blockIn, BlockPos fromPos, - boolean isMoving) { - final PaintSplotchesBlockEntity tp = this.getBlockEntity(level, pos); - - if (tp != null) { - tp.neighborChanged(); - } - } - - @Override - public void handlePrecipitation(BlockState state, Level level, BlockPos pos, Biome.Precipitation precipitation) { - if (!level.isClientSide() && precipitation == Biome.Precipitation.RAIN) { - level.removeBlock(pos, false); - } - } - - @Override - public boolean canBeReplaced(BlockState state, BlockPlaceContext useContext) { - return true; - } - - @Override - public boolean canBeReplaced(BlockState state, Fluid fluid) { - return true; - } - -} diff --git a/src/main/java/appeng/block/paint/PaintSplotchesModel.java b/src/main/java/appeng/block/paint/PaintSplotchesModel.java deleted file mode 100644 index d58689d9ffb..00000000000 --- a/src/main/java/appeng/block/paint/PaintSplotchesModel.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * This file is part of Applied Energistics 2. - * Copyright (c) 2021, 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.block.paint; - -import java.util.Collection; -import java.util.Collections; -import java.util.Set; -import java.util.function.Function; - -import com.mojang.datafixers.util.Pair; - -import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.client.resources.model.BakedModel; -import net.minecraft.client.resources.model.Material; -import net.minecraft.client.resources.model.ModelBakery; -import net.minecraft.client.resources.model.ModelState; -import net.minecraft.client.resources.model.UnbakedModel; -import net.minecraft.resources.ResourceLocation; - -public class PaintSplotchesModel implements UnbakedModel { - - @org.jetbrains.annotations.Nullable - @Override - public BakedModel bake(ModelBakery modelBakery, Function textureGetter, - ModelState modelState, ResourceLocation resourceLocation) { - return new PaintSplotchesBakedModel(textureGetter); - } - - @Override - public Collection getMaterials(Function function, - Set> set) { - return PaintSplotchesBakedModel.getRequiredTextures(); - } - - @Override - public Collection getDependencies() { - return Collections.emptyList(); - } - -} diff --git a/src/main/java/appeng/block/qnb/QnbFormedBakedModel.java b/src/main/java/appeng/block/qnb/QnbFormedBakedModel.java deleted file mode 100644 index f0f0eecf8d3..00000000000 --- a/src/main/java/appeng/block/qnb/QnbFormedBakedModel.java +++ /dev/null @@ -1,275 +0,0 @@ -/* - * This file is part of Applied Energistics 2. - * Copyright (c) 2021, 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.block.qnb; - -import java.util.EnumSet; -import java.util.List; -import java.util.Set; -import java.util.function.Function; -import java.util.function.Supplier; - -import javax.annotation.Nullable; - -import com.google.common.collect.ImmutableList; - -import net.fabricmc.fabric.api.renderer.v1.mesh.QuadEmitter; -import net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel; -import net.fabricmc.fabric.api.renderer.v1.render.RenderContext; -import net.fabricmc.fabric.api.rendering.data.v1.RenderAttachedBlockView; -import net.minecraft.client.renderer.block.model.BakedQuad; -import net.minecraft.client.renderer.block.model.ItemOverrides; -import net.minecraft.client.renderer.block.model.ItemTransforms; -import net.minecraft.client.renderer.texture.TextureAtlas; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.client.resources.model.BakedModel; -import net.minecraft.client.resources.model.Material; -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.util.RandomSource; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.BlockAndTintGetter; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; - -import appeng.client.render.cablebus.CubeBuilder; -import appeng.core.AppEng; -import appeng.core.definitions.AEBlocks; - -class QnbFormedBakedModel implements BakedModel, FabricBakedModel { - - private static final Material TEXTURE_LINK = new Material(TextureAtlas.LOCATION_BLOCKS, - new ResourceLocation(AppEng.MOD_ID, "block/quantum_link")); - private static final Material TEXTURE_RING = new Material(TextureAtlas.LOCATION_BLOCKS, - new ResourceLocation(AppEng.MOD_ID, "block/quantum_ring")); - private static final Material TEXTURE_RING_LIGHT = new Material(TextureAtlas.LOCATION_BLOCKS, - new ResourceLocation(AppEng.MOD_ID, "block/quantum_ring_light")); - private static final Material TEXTURE_RING_LIGHT_CORNER = new Material( - TextureAtlas.LOCATION_BLOCKS, - new ResourceLocation(AppEng.MOD_ID, "block/quantum_ring_light_corner")); - private static final Material TEXTURE_CABLE_GLASS = new Material(TextureAtlas.LOCATION_BLOCKS, - new ResourceLocation(AppEng.MOD_ID, "part/cable/glass/transparent")); - private static final Material TEXTURE_COVERED_CABLE = new Material(TextureAtlas.LOCATION_BLOCKS, - new ResourceLocation(AppEng.MOD_ID, "part/cable/covered/transparent")); - - private static final float DEFAULT_RENDER_MIN = 2.0f; - private static final float DEFAULT_RENDER_MAX = 14.0f; - - private static final float CORNER_POWERED_RENDER_MIN = 3.9f; - private static final float CORNER_POWERED_RENDER_MAX = 12.1f; - - private static final float CENTER_POWERED_RENDER_MIN = -0.01f; - private static final float CENTER_POWERED_RENDER_MAX = 16.01f; - - private final BakedModel baseModel; - - private final Block linkBlock; - - private final TextureAtlasSprite linkTexture; - private final TextureAtlasSprite ringTexture; - private final TextureAtlasSprite glassCableTexture; - private final TextureAtlasSprite coveredCableTexture; - private final TextureAtlasSprite lightTexture; - private final TextureAtlasSprite lightCornerTexture; - - public QnbFormedBakedModel(BakedModel baseModel, Function bakedTextureGetter) { - this.baseModel = baseModel; - this.linkTexture = bakedTextureGetter.apply(TEXTURE_LINK); - this.ringTexture = bakedTextureGetter.apply(TEXTURE_RING); - this.glassCableTexture = bakedTextureGetter.apply(TEXTURE_CABLE_GLASS); - this.coveredCableTexture = bakedTextureGetter.apply(TEXTURE_COVERED_CABLE); - this.lightTexture = bakedTextureGetter.apply(TEXTURE_RING_LIGHT); - this.lightCornerTexture = bakedTextureGetter.apply(TEXTURE_RING_LIGHT_CORNER); - this.linkBlock = AEBlocks.QUANTUM_LINK.block(); - } - - @Override - public boolean isVanillaAdapter() { - return false; - } - - @Override - public void emitItemQuads(ItemStack stack, Supplier randomSupplier, RenderContext context) { - - } - - @Override - public void emitBlockQuads(BlockAndTintGetter blockView, BlockState state, BlockPos pos, - Supplier randomSupplier, RenderContext context) { - QnbFormedState formedState = getState(blockView, pos); - - if (formedState == null) { - context.fallbackConsumer().accept(this.baseModel); - return; - } - - buildQuads(context.getEmitter(), formedState, state); - - } - - @Override - public List getQuads(@Nullable BlockState state, @Nullable Direction face, RandomSource random) { - return baseModel.getQuads(state, face, random); - } - - @Override - public ItemTransforms getTransforms() { - return ItemTransforms.NO_TRANSFORMS; - } - - private static QnbFormedState getState(BlockAndTintGetter view, BlockPos pos) { - if (view instanceof RenderAttachedBlockView renderAttachedBlockView) { - Object attachment = renderAttachedBlockView.getBlockEntityRenderAttachment(pos); - if (attachment instanceof QnbFormedState qnbFormedState) { - return qnbFormedState; - } - } - return null; - } - - private void buildQuads(QuadEmitter emitter, QnbFormedState formedState, BlockState state) { - CubeBuilder builder = new CubeBuilder(emitter); - - if (state.getBlock() == this.linkBlock) { - Set sides = formedState.getAdjacentQuantumBridges(); - - this.renderCableAt(builder, 0.11f * 16, this.glassCableTexture, 0.141f * 16, sides); - - this.renderCableAt(builder, 0.188f * 16, this.coveredCableTexture, 0.1875f * 16, sides); - - builder.setTexture(this.linkTexture); - builder.addCube(DEFAULT_RENDER_MIN, DEFAULT_RENDER_MIN, DEFAULT_RENDER_MIN, DEFAULT_RENDER_MAX, - DEFAULT_RENDER_MAX, DEFAULT_RENDER_MAX); - } else if (formedState.isCorner()) { - this.renderCableAt(builder, 0.188f * 16, this.coveredCableTexture, 0.05f * 16, - formedState.getAdjacentQuantumBridges()); - - builder.setTexture(this.ringTexture); - builder.addCube(DEFAULT_RENDER_MIN, DEFAULT_RENDER_MIN, DEFAULT_RENDER_MIN, DEFAULT_RENDER_MAX, - DEFAULT_RENDER_MAX, DEFAULT_RENDER_MAX); - - if (formedState.isPowered()) { - builder.setTexture(this.lightCornerTexture); - builder.setEmissiveMaterial(true); - for (Direction facing : Direction.values()) { - // Offset the face by a slight amount so that it is drawn over the already drawn - // ring texture - // (avoids z-fighting) - float xOffset = Math.abs(facing.getStepX() * 0.01f); - float yOffset = Math.abs(facing.getStepY() * 0.01f); - float zOffset = Math.abs(facing.getStepZ() * 0.01f); - - builder.setDrawFaces(EnumSet.of(facing)); - builder.addCube(DEFAULT_RENDER_MIN - xOffset, DEFAULT_RENDER_MIN - yOffset, - DEFAULT_RENDER_MIN - zOffset, DEFAULT_RENDER_MAX + xOffset, - DEFAULT_RENDER_MAX + yOffset, DEFAULT_RENDER_MAX + zOffset); - } - builder.setEmissiveMaterial(false); - } - } else { - builder.setTexture(this.ringTexture); - - builder.addCube(0, DEFAULT_RENDER_MIN, DEFAULT_RENDER_MIN, 16, DEFAULT_RENDER_MAX, DEFAULT_RENDER_MAX); - - builder.addCube(DEFAULT_RENDER_MIN, 0, DEFAULT_RENDER_MIN, DEFAULT_RENDER_MAX, 16, DEFAULT_RENDER_MAX); - - builder.addCube(DEFAULT_RENDER_MIN, DEFAULT_RENDER_MIN, 0, DEFAULT_RENDER_MAX, DEFAULT_RENDER_MAX, 16); - - if (formedState.isPowered()) { - builder.setTexture(this.lightTexture); - builder.setEmissiveMaterial(true); - for (Direction facing : Direction.values()) { - // Offset the face by a slight amount so that it is drawn over the already drawn - // ring texture - // (avoids z-fighting) - float xOffset = Math.abs(facing.getStepX() * 0.01f); - float yOffset = Math.abs(facing.getStepY() * 0.01f); - float zOffset = Math.abs(facing.getStepZ() * 0.01f); - - builder.setDrawFaces(EnumSet.of(facing)); - builder.addCube(-xOffset, -yOffset, -zOffset, 16 + xOffset, 16 + yOffset, 16 + zOffset); - } - } - } - } - - private void renderCableAt(CubeBuilder builder, float thickness, TextureAtlasSprite texture, float pull, - Set connections) { - builder.setTexture(texture); - - if (connections.contains(Direction.WEST)) { - builder.addCube(0, 8 - thickness, 8 - thickness, 8 - thickness - pull, 8 + thickness, 8 + thickness); - } - - if (connections.contains(Direction.EAST)) { - builder.addCube(8 + thickness + pull, 8 - thickness, 8 - thickness, 16, 8 + thickness, 8 + thickness); - } - - if (connections.contains(Direction.NORTH)) { - builder.addCube(8 - thickness, 8 - thickness, 0, 8 + thickness, 8 + thickness, 8 - thickness - pull); - } - - if (connections.contains(Direction.SOUTH)) { - builder.addCube(8 - thickness, 8 - thickness, 8 + thickness + pull, 8 + thickness, 8 + thickness, 16); - } - - if (connections.contains(Direction.DOWN)) { - builder.addCube(8 - thickness, 0, 8 - thickness, 8 + thickness, 8 - thickness - pull, 8 + thickness); - } - - if (connections.contains(Direction.UP)) { - builder.addCube(8 - thickness, 8 + thickness + pull, 8 - thickness, 8 + thickness, 16, 8 + thickness); - } - } - - @Override - public boolean useAmbientOcclusion() { - return this.baseModel.useAmbientOcclusion(); - } - - @Override - public boolean isGui3d() { - return true; - } - - @Override - public boolean usesBlockLight() { - return false; - } - - @Override - public boolean isCustomRenderer() { - return false; - } - - @Override - public TextureAtlasSprite getParticleIcon() { - return this.baseModel.getParticleIcon(); - } - - @Override - public ItemOverrides getOverrides() { - return this.baseModel.getOverrides(); - } - - public static List getRequiredTextures() { - return ImmutableList.of(TEXTURE_LINK, TEXTURE_RING, TEXTURE_CABLE_GLASS, TEXTURE_COVERED_CABLE, - TEXTURE_RING_LIGHT, TEXTURE_RING_LIGHT_CORNER); - } -} diff --git a/src/main/java/appeng/block/qnb/QnbFormedModel.java b/src/main/java/appeng/block/qnb/QnbFormedModel.java deleted file mode 100644 index 30d12cdd483..00000000000 --- a/src/main/java/appeng/block/qnb/QnbFormedModel.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * This file is part of Applied Energistics 2. - * Copyright (c) 2021, 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.block.qnb; - -import java.util.Collection; -import java.util.function.Function; -import java.util.stream.Stream; - -import com.google.common.collect.ImmutableSet; - -import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.client.resources.model.BakedModel; -import net.minecraft.client.resources.model.Material; -import net.minecraft.client.resources.model.ModelBakery; -import net.minecraft.client.resources.model.ModelState; -import net.minecraft.resources.ResourceLocation; - -import appeng.client.render.BasicUnbakedModel; -import appeng.core.AppEng; - -public class QnbFormedModel implements BasicUnbakedModel { - - private static final ResourceLocation MODEL_RING = new ResourceLocation(AppEng.MOD_ID, "block/qnb/ring"); - - @org.jetbrains.annotations.Nullable - @Override - public BakedModel bake(ModelBakery modelBakery, Function textureGetter, - ModelState modelState, ResourceLocation resourceLocation) { - BakedModel ringModel = modelBakery.bake(MODEL_RING, modelState); - return new QnbFormedBakedModel(ringModel, textureGetter); - } - - @Override - public Collection getDependencies() { - return ImmutableSet.of(MODEL_RING); - } - - @Override - public Stream getAdditionalTextures() { - return QnbFormedBakedModel.getRequiredTextures().stream(); - } - -} diff --git a/src/main/java/appeng/block/qnb/QnbFormedState.java b/src/main/java/appeng/block/qnb/QnbFormedState.java deleted file mode 100644 index d4cc38a6c32..00000000000 --- a/src/main/java/appeng/block/qnb/QnbFormedState.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * This file is part of Applied Energistics 2. - * Copyright (c) 2021, 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.block.qnb; - -import java.util.Set; - -import net.minecraft.core.Direction; - -public class QnbFormedState { - - private final Set adjacentQuantumBridges; - - private final boolean corner; - - private final boolean powered; - - public QnbFormedState(Set adjacentQuantumBridges, boolean corner, boolean powered) { - this.adjacentQuantumBridges = adjacentQuantumBridges; - this.corner = corner; - this.powered = powered; - } - - public Set getAdjacentQuantumBridges() { - return this.adjacentQuantumBridges; - } - - public boolean isCorner() { - return this.corner; - } - - public boolean isPowered() { - return this.powered; - } - -} diff --git a/src/main/java/appeng/block/qnb/QuantumBaseBlock.java b/src/main/java/appeng/block/qnb/QuantumBaseBlock.java deleted file mode 100644 index c0e40095dc9..00000000000 --- a/src/main/java/appeng/block/qnb/QuantumBaseBlock.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * This file is part of Applied Energistics 2. - * Copyright (c) 2013 - 2015, 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.qnb; - -import javax.annotation.Nullable; - -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.world.item.context.BlockPlaceContext; -import net.minecraft.world.level.BlockGetter; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.LevelAccessor; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.SimpleWaterloggedBlock; -import net.minecraft.world.level.block.state.BlockBehaviour; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.state.StateDefinition.Builder; -import net.minecraft.world.level.block.state.properties.BlockStateProperties; -import net.minecraft.world.level.block.state.properties.BooleanProperty; -import net.minecraft.world.level.material.FluidState; -import net.minecraft.world.level.material.Fluids; -import net.minecraft.world.phys.AABB; -import net.minecraft.world.phys.shapes.CollisionContext; -import net.minecraft.world.phys.shapes.Shapes; -import net.minecraft.world.phys.shapes.VoxelShape; - -import appeng.block.AEBaseEntityBlock; -import appeng.blockentity.qnb.QuantumBridgeBlockEntity; - -public abstract class QuantumBaseBlock extends AEBaseEntityBlock - implements SimpleWaterloggedBlock { - - public static final BooleanProperty FORMED = BooleanProperty.create("formed"); - private static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED; - - private static final VoxelShape SHAPE; - - static { - final float shave = 2.0f / 16.0f; - SHAPE = Shapes.create(new AABB(shave, shave, shave, 1.0f - shave, 1.0f - shave, 1.0f - shave)); - } - - public QuantumBaseBlock(BlockBehaviour.Properties props) { - super(props); - this.registerDefaultState(this.defaultBlockState().setValue(FORMED, false) - .setValue(WATERLOGGED, false)); - } - - @Override - public VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) { - return SHAPE; - } - - @Override - protected void createBlockStateDefinition(Builder builder) { - super.createBlockStateDefinition(builder); - builder.add(FORMED); - builder.add(WATERLOGGED); - } - - @Override - protected BlockState updateBlockStateFromBlockEntity(BlockState currentState, QuantumBridgeBlockEntity be) { - return currentState.setValue(FORMED, be.isFormed()); - } - - @Override - public void neighborChanged(BlockState state, Level level, BlockPos pos, Block blockIn, BlockPos fromPos, - boolean isMoving) { - final QuantumBridgeBlockEntity bridge = this.getBlockEntity(level, pos); - if (bridge != null) { - bridge.neighborUpdate(fromPos); - } - } - - @Override - public void onRemove(BlockState state, Level level, BlockPos pos, BlockState newState, boolean isMoving) { - if (newState.getBlock() == state.getBlock()) { - return; // Just a block state change - } - - final QuantumBridgeBlockEntity bridge = this.getBlockEntity(level, pos); - if (bridge != null) { - bridge.breakClusterOnRemove(); - } - - super.onRemove(state, level, pos, newState, isMoving); - } - - @Override - @Nullable - public BlockState getStateForPlacement(BlockPlaceContext context) { - BlockPos pos = context.getClickedPos(); - FluidState fluidState = context.getLevel().getFluidState(pos); - BlockState blockState = this.defaultBlockState() - .setValue(WATERLOGGED, fluidState.getType() == Fluids.WATER); - - return blockState; - } - - @Override - public FluidState getFluidState(BlockState blockState) { - return blockState.getValue(WATERLOGGED).booleanValue() - ? Fluids.WATER.getSource(false) - : super.getFluidState(blockState); - } - - @Override - public BlockState updateShape(BlockState blockState, Direction facing, BlockState facingState, LevelAccessor level, - BlockPos currentPos, BlockPos facingPos) { - if (blockState.getValue(WATERLOGGED).booleanValue()) { - level.scheduleTick(currentPos, Fluids.WATER, Fluids.WATER.getTickDelay(level)); - } - - return super.updateShape(blockState, facing, facingState, level, currentPos, facingPos); - } - -} diff --git a/src/main/java/appeng/block/qnb/QuantumLinkChamberBlock.java b/src/main/java/appeng/block/qnb/QuantumLinkChamberBlock.java deleted file mode 100644 index ee0bfa93349..00000000000 --- a/src/main/java/appeng/block/qnb/QuantumLinkChamberBlock.java +++ /dev/null @@ -1,99 +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.qnb; - -import javax.annotation.Nullable; - -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.minecraft.core.BlockPos; -import net.minecraft.util.RandomSource; -import net.minecraft.world.InteractionHand; -import net.minecraft.world.InteractionResult; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.BlockGetter; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.phys.AABB; -import net.minecraft.world.phys.BlockHitResult; -import net.minecraft.world.phys.shapes.CollisionContext; -import net.minecraft.world.phys.shapes.Shapes; -import net.minecraft.world.phys.shapes.VoxelShape; - -import appeng.blockentity.qnb.QuantumBridgeBlockEntity; -import appeng.client.EffectType; -import appeng.core.AppEng; -import appeng.core.AppEngClient; -import appeng.helpers.AEMaterials; -import appeng.menu.MenuOpener; -import appeng.menu.implementations.QNBMenu; -import appeng.menu.locator.MenuLocators; -import appeng.util.InteractionUtil; - -public class QuantumLinkChamberBlock extends QuantumBaseBlock { - - private static final VoxelShape SHAPE; - - static { - final double onePixel = 2.0 / 16.0; - SHAPE = Shapes.create( - new AABB(onePixel, onePixel, onePixel, 1.0 - onePixel, 1.0 - onePixel, 1.0 - onePixel)); - } - - public QuantumLinkChamberBlock() { - super(defaultProps(AEMaterials.GLASS)); - } - - @Override - @Environment(EnvType.CLIENT) - public void animateTick(BlockState state, Level level, BlockPos pos, RandomSource rand) { - final QuantumBridgeBlockEntity bridge = this.getBlockEntity(level, pos); - if (bridge != null && bridge.hasQES() && AppEngClient.instance().shouldAddParticles(rand)) { - AppEng.instance().spawnEffect(EffectType.Energy, level, pos.getX() + 0.5, pos.getY() + 0.5, - pos.getZ() + 0.5, - null); - } - } - - @Override - public InteractionResult onActivated(Level level, BlockPos pos, Player p, - InteractionHand hand, - @Nullable ItemStack heldItem, BlockHitResult hit) { - if (InteractionUtil.isInAlternateUseMode(p)) { - return InteractionResult.PASS; - } - - final QuantumBridgeBlockEntity tg = this.getBlockEntity(level, pos); - if (tg != null) { - if (!level.isClientSide()) { - MenuOpener.open(QNBMenu.TYPE, p, MenuLocators.forBlockEntity(tg)); - } - return InteractionResult.sidedSuccess(level.isClientSide()); - } - - return InteractionResult.PASS; - } - - @Override - public VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) { - return SHAPE; - } - -} diff --git a/src/main/java/appeng/block/qnb/QuantumRingBlock.java b/src/main/java/appeng/block/qnb/QuantumRingBlock.java deleted file mode 100644 index dcf1c9bb47f..00000000000 --- a/src/main/java/appeng/block/qnb/QuantumRingBlock.java +++ /dev/null @@ -1,79 +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.qnb; - -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.world.level.BlockGetter; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.material.Material; -import net.minecraft.world.phys.AABB; -import net.minecraft.world.phys.shapes.CollisionContext; -import net.minecraft.world.phys.shapes.Shapes; -import net.minecraft.world.phys.shapes.VoxelShape; - -import appeng.blockentity.qnb.QuantumBridgeBlockEntity; - -public class QuantumRingBlock extends QuantumBaseBlock { - - private static final VoxelShape SHAPE = createShape(2.0 / 16.0); - private static final VoxelShape SHAPE_CORNER = createShape(2.0 / 16.0); - private static final VoxelShape SHAPE_CENTER = createCenterShape(2.0 / 16.0); - - private static final double DEFAULT_MODEL_MIN = 2.0 / 16.0; - private static final double DEFAULT_MODEL_MAX = 14.0 / 16.0; - - public QuantumRingBlock() { - super(defaultProps(Material.METAL)); - } - - @Override - public VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) { - final QuantumBridgeBlockEntity bridge = this.getBlockEntity(level, pos); - if (bridge != null && bridge.isCorner()) { - return SHAPE_CORNER; - } else if (bridge != null && bridge.isFormed()) { - return SHAPE_CENTER; - } - return SHAPE; - } - - private static VoxelShape createShape(double onePixel) { - return Shapes.create( - new AABB(onePixel, onePixel, onePixel, 1.0 - onePixel, 1.0 - onePixel, 1.0 - onePixel)); - } - - private static VoxelShape createCenterShape(double offset) { - VoxelShape centerShape = SHAPE; - for (Direction facing : Direction.values()) { - double xOffset = Math.abs(facing.getStepX() * offset); - double yOffset = Math.abs(facing.getStepY() * offset); - double zOffset = Math.abs(facing.getStepZ() * offset); - - VoxelShape extrusion = Shapes.create( - new AABB(DEFAULT_MODEL_MIN - xOffset, DEFAULT_MODEL_MIN - yOffset, - DEFAULT_MODEL_MIN - zOffset, DEFAULT_MODEL_MAX + xOffset, - DEFAULT_MODEL_MAX + yOffset, DEFAULT_MODEL_MAX + zOffset)); - - centerShape = Shapes.or(centerShape, extrusion); - } - - return centerShape; - } -} diff --git a/src/main/java/appeng/block/spatial/MatrixFrameBlock.java b/src/main/java/appeng/block/spatial/MatrixFrameBlock.java deleted file mode 100644 index 3f4c624241c..00000000000 --- a/src/main/java/appeng/block/spatial/MatrixFrameBlock.java +++ /dev/null @@ -1,99 +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.spatial; - -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.minecraft.core.BlockPos; -import net.minecraft.core.NonNullList; -import net.minecraft.world.item.CreativeModeTab; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.BlockGetter; -import net.minecraft.world.level.Explosion; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.LevelReader; -import net.minecraft.world.level.block.RenderShape; -import net.minecraft.world.level.block.state.BlockBehaviour; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.material.Material; -import net.minecraft.world.level.material.MaterialColor; -import net.minecraft.world.level.material.PushReaction; -import net.minecraft.world.phys.shapes.CollisionContext; -import net.minecraft.world.phys.shapes.Shapes; -import net.minecraft.world.phys.shapes.VoxelShape; - -import appeng.block.AEBaseBlock; - -/** - * This block is used to fill empty space in spatial dimensions and delinates the border of a spatial dimensions's - * usable space. - */ -public class MatrixFrameBlock extends AEBaseBlock { - - private static final Material MATERIAL = new Material(MaterialColor.NONE, false, true, true, false, false, false, - PushReaction.PUSH_ONLY); - - public MatrixFrameBlock() { - super(BlockBehaviour.Properties.of(MATERIAL).strength(-1.0F, 6000000.0F).noOcclusion().noLootTable()); - } - - @Override - public RenderShape getRenderShape(BlockState state) { - return RenderShape.INVISIBLE; - } - - @Override - @Environment(EnvType.CLIENT) - public void fillItemCategory(CreativeModeTab group, NonNullList itemStacks) { - // do nothing - } - - @Override - public VoxelShape getCollisionShape(BlockState state, BlockGetter level, BlockPos pos, - CollisionContext context) { - return Shapes.block(); - } - - @Override - public VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) { - // This also prevents any blocks from being placed on this block! - return Shapes.empty(); - } - - @Override - public boolean canSurvive(BlockState state, LevelReader level, BlockPos pos) { - return false; - } - - @Override - public void wasExploded(Level level, BlockPos pos, Explosion explosion) { - // Don't explode. - } - - @Override - public boolean propagatesSkylightDown(BlockState state, BlockGetter reader, BlockPos pos) { - return true; - } - - @Override - public float getShadeBrightness(BlockState state, BlockGetter level, BlockPos pos) { - return 1.0f; - } - -} diff --git a/src/main/java/appeng/block/spatial/SpatialAnchorBlock.java b/src/main/java/appeng/block/spatial/SpatialAnchorBlock.java deleted file mode 100644 index c2c4442d237..00000000000 --- a/src/main/java/appeng/block/spatial/SpatialAnchorBlock.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * This file is part of Applied Energistics 2. - * Copyright (c) 2021, 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.block.spatial; - -import javax.annotation.Nullable; - -import net.minecraft.core.BlockPos; -import net.minecraft.world.InteractionHand; -import net.minecraft.world.InteractionResult; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.state.StateDefinition.Builder; -import net.minecraft.world.level.block.state.properties.BooleanProperty; -import net.minecraft.world.level.material.Material; -import net.minecraft.world.phys.BlockHitResult; - -import appeng.block.AEBaseEntityBlock; -import appeng.blockentity.spatial.SpatialAnchorBlockEntity; -import appeng.menu.MenuOpener; -import appeng.menu.implementations.SpatialAnchorMenu; -import appeng.menu.locator.MenuLocators; -import appeng.util.InteractionUtil; - -/** - * The block for our chunk loader - */ -public class SpatialAnchorBlock extends AEBaseEntityBlock { - - public static final BooleanProperty POWERED = BooleanProperty.create("powered"); - - public SpatialAnchorBlock() { - super(defaultProps(Material.METAL)); - this.registerDefaultState(this.defaultBlockState().setValue(POWERED, false)); - } - - @Override - protected void createBlockStateDefinition(Builder builder) { - super.createBlockStateDefinition(builder); - builder.add(POWERED); - } - - @Override - protected BlockState updateBlockStateFromBlockEntity(BlockState currentState, SpatialAnchorBlockEntity be) { - return currentState.setValue(POWERED, be.isActive()); - } - - @Override - public InteractionResult onActivated(Level level, BlockPos pos, Player p, - InteractionHand hand, - @Nullable ItemStack heldItem, BlockHitResult hit) { - if (InteractionUtil.isInAlternateUseMode(p)) { - return InteractionResult.PASS; - } - - final SpatialAnchorBlockEntity tg = this.getBlockEntity(level, pos); - if (tg != null) { - if (!level.isClientSide()) { - hit.getDirection(); - MenuOpener.open(SpatialAnchorMenu.TYPE, p, - MenuLocators.forBlockEntity(tg)); - } - return InteractionResult.sidedSuccess(level.isClientSide()); - } - return InteractionResult.PASS; - } - -} diff --git a/src/main/java/appeng/block/spatial/SpatialIOPortBlock.java b/src/main/java/appeng/block/spatial/SpatialIOPortBlock.java deleted file mode 100644 index 5273f72a91d..00000000000 --- a/src/main/java/appeng/block/spatial/SpatialIOPortBlock.java +++ /dev/null @@ -1,92 +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.spatial; - -import javax.annotation.Nullable; - -import net.minecraft.core.BlockPos; -import net.minecraft.world.InteractionHand; -import net.minecraft.world.InteractionResult; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.state.StateDefinition; -import net.minecraft.world.level.block.state.properties.BooleanProperty; -import net.minecraft.world.level.material.Material; -import net.minecraft.world.phys.BlockHitResult; - -import appeng.block.AEBaseEntityBlock; -import appeng.blockentity.spatial.SpatialIOPortBlockEntity; -import appeng.menu.MenuOpener; -import appeng.menu.implementations.SpatialIOPortMenu; -import appeng.menu.locator.MenuLocators; -import appeng.util.InteractionUtil; - -public class SpatialIOPortBlock extends AEBaseEntityBlock { - - public final static BooleanProperty POWERED = BooleanProperty.create("powered"); - - public SpatialIOPortBlock() { - super(defaultProps(Material.METAL)); - this.registerDefaultState(this.defaultBlockState().setValue(POWERED, false)); - } - - @SuppressWarnings("deprecation") - @Override - public void neighborChanged(BlockState state, Level level, BlockPos pos, Block blockIn, BlockPos fromPos, - boolean isMoving) { - final SpatialIOPortBlockEntity te = this.getBlockEntity(level, pos); - if (te != null) { - te.updateRedstoneState(); - } - } - - @Override - protected void createBlockStateDefinition(StateDefinition.Builder builder) { - super.createBlockStateDefinition(builder); - builder.add(POWERED); - } - - @Override - protected BlockState updateBlockStateFromBlockEntity(BlockState currentState, SpatialIOPortBlockEntity be) { - return currentState.setValue(POWERED, be.isActive()); - } - - @Override - public InteractionResult onActivated(Level level, BlockPos pos, Player p, - InteractionHand hand, - @Nullable ItemStack heldItem, BlockHitResult hit) { - if (InteractionUtil.isInAlternateUseMode(p)) { - return InteractionResult.PASS; - } - - final SpatialIOPortBlockEntity tg = this.getBlockEntity(level, pos); - if (tg != null) { - if (!level.isClientSide()) { - hit.getDirection(); - MenuOpener.open(SpatialIOPortMenu.TYPE, p, - MenuLocators.forBlockEntity(tg)); - } - return InteractionResult.sidedSuccess(level.isClientSide()); - } - return InteractionResult.PASS; - } -} diff --git a/src/main/java/appeng/block/spatial/SpatialPylonBlock.java b/src/main/java/appeng/block/spatial/SpatialPylonBlock.java deleted file mode 100644 index e3363dfc1de..00000000000 --- a/src/main/java/appeng/block/spatial/SpatialPylonBlock.java +++ /dev/null @@ -1,65 +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.spatial; - -import net.minecraft.core.BlockPos; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.state.StateDefinition; -import net.minecraft.world.level.block.state.properties.BooleanProperty; - -import appeng.block.AEBaseEntityBlock; -import appeng.blockentity.spatial.SpatialPylonBlockEntity; -import appeng.helpers.AEMaterials; - -public class SpatialPylonBlock extends AEBaseEntityBlock { - - public static final BooleanProperty POWERED_ON = BooleanProperty.create("powered_on"); - - public SpatialPylonBlock() { - super(defaultProps(AEMaterials.GLASS).lightLevel(state -> { - return state.getValue(POWERED_ON) ? 8 : 0; - })); - registerDefaultState(defaultBlockState().setValue(POWERED_ON, false)); - } - - @Override - protected void createBlockStateDefinition(StateDefinition.Builder builder) { - super.createBlockStateDefinition(builder); - builder.add(POWERED_ON); - } - - @Override - protected BlockState updateBlockStateFromBlockEntity(BlockState currentState, SpatialPylonBlockEntity be) { - var poweredOn = (be.getDisplayBits() & SpatialPylonBlockEntity.DISPLAY_POWERED_ENABLED) != 0; - return currentState.setValue(SpatialPylonBlock.POWERED_ON, poweredOn); - } - - @SuppressWarnings("deprecation") - @Override - public void neighborChanged(BlockState state, Level level, BlockPos pos, Block blockIn, BlockPos fromPos, - boolean isMoving) { - final SpatialPylonBlockEntity tsp = this.getBlockEntity(level, pos); - if (tsp != null) { - tsp.neighborChanged(fromPos); - } - } - -} diff --git a/src/main/java/appeng/block/storage/ChestBlock.java b/src/main/java/appeng/block/storage/ChestBlock.java deleted file mode 100644 index f2639da5ffa..00000000000 --- a/src/main/java/appeng/block/storage/ChestBlock.java +++ /dev/null @@ -1,89 +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 javax.annotation.Nullable; - -import net.minecraft.core.BlockPos; -import net.minecraft.world.InteractionHand; -import net.minecraft.world.InteractionResult; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.state.StateDefinition.Builder; -import net.minecraft.world.level.block.state.properties.BooleanProperty; -import net.minecraft.world.level.material.Material; -import net.minecraft.world.phys.BlockHitResult; - -import appeng.api.storage.cells.CellState; -import appeng.block.AEBaseEntityBlock; -import appeng.blockentity.storage.ChestBlockEntity; -import appeng.core.localization.PlayerMessages; -import appeng.util.InteractionUtil; - -public class ChestBlock extends AEBaseEntityBlock { - - private final static BooleanProperty LIGHTS_ON = BooleanProperty.create("lights_on"); - - public ChestBlock() { - super(defaultProps(Material.METAL)); - this.registerDefaultState(this.defaultBlockState().setValue(LIGHTS_ON, false)); - } - - @Override - protected void createBlockStateDefinition(Builder builder) { - super.createBlockStateDefinition(builder); - builder.add(LIGHTS_ON); - } - - @Override - protected BlockState updateBlockStateFromBlockEntity(BlockState currentState, ChestBlockEntity be) { - var cellState = CellState.ABSENT; - - if (be.getCellCount() >= 1) { - cellState = be.getCellStatus(0); - } - - return currentState.setValue(LIGHTS_ON, be.isPowered() && cellState != CellState.ABSENT); - } - - @Override - public InteractionResult onActivated(Level level, BlockPos pos, Player p, - InteractionHand hand, - @Nullable ItemStack heldItem, BlockHitResult hit) { - var be = this.getBlockEntity(level, pos); - if (be != null && !InteractionUtil.isInAlternateUseMode(p)) { - if (!level.isClientSide()) { - if (hit.getDirection() == be.getUp()) { - if (!be.openGui(p)) { - p.sendSystemMessage(PlayerMessages.ChestCannotReadStorageCell.text()); - } - } else { - be.openCellInventoryMenu(p); - } - } - - return InteractionResult.sidedSuccess(level.isClientSide()); - } - - return InteractionResult.PASS; - } -} diff --git a/src/main/java/appeng/block/storage/DriveBlock.java b/src/main/java/appeng/block/storage/DriveBlock.java deleted file mode 100644 index f28c6658013..00000000000 --- a/src/main/java/appeng/block/storage/DriveBlock.java +++ /dev/null @@ -1,59 +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 javax.annotation.Nullable; - -import net.minecraft.core.BlockPos; -import net.minecraft.world.InteractionHand; -import net.minecraft.world.InteractionResult; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.material.Material; -import net.minecraft.world.phys.BlockHitResult; - -import appeng.block.AEBaseEntityBlock; -import appeng.blockentity.storage.DriveBlockEntity; -import appeng.util.InteractionUtil; - -public class DriveBlock extends AEBaseEntityBlock { - - public DriveBlock() { - super(defaultProps(Material.METAL)); - } - - @Override - public InteractionResult onActivated(Level level, BlockPos pos, Player p, - InteractionHand hand, - @Nullable ItemStack heldItem, BlockHitResult hit) { - if (InteractionUtil.isInAlternateUseMode(p)) { - return InteractionResult.PASS; - } - - var be = this.getBlockEntity(level, pos); - if (be != null) { - if (!level.isClientSide()) { - be.openMenu(p); - } - return InteractionResult.sidedSuccess(level.isClientSide()); - } - return InteractionResult.PASS; - } -} diff --git a/src/main/java/appeng/block/storage/IOPortBlock.java b/src/main/java/appeng/block/storage/IOPortBlock.java deleted file mode 100644 index 5bfa6904769..00000000000 --- a/src/main/java/appeng/block/storage/IOPortBlock.java +++ /dev/null @@ -1,92 +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 javax.annotation.Nullable; - -import net.minecraft.core.BlockPos; -import net.minecraft.world.InteractionHand; -import net.minecraft.world.InteractionResult; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.state.StateDefinition; -import net.minecraft.world.level.block.state.properties.BooleanProperty; -import net.minecraft.world.level.material.Material; -import net.minecraft.world.phys.BlockHitResult; - -import appeng.block.AEBaseEntityBlock; -import appeng.blockentity.storage.IOPortBlockEntity; -import appeng.menu.MenuOpener; -import appeng.menu.implementations.IOPortMenu; -import appeng.menu.locator.MenuLocators; -import appeng.util.InteractionUtil; - -public class IOPortBlock extends AEBaseEntityBlock { - - public final static BooleanProperty POWERED = BooleanProperty.create("powered"); - - public IOPortBlock() { - super(defaultProps(Material.METAL)); - this.registerDefaultState(this.defaultBlockState().setValue(POWERED, false)); - } - - @SuppressWarnings("deprecation") - @Override - public void neighborChanged(BlockState state, Level level, BlockPos pos, Block blockIn, BlockPos fromPos, - boolean isMoving) { - final IOPortBlockEntity te = this.getBlockEntity(level, pos); - if (te != null) { - te.updateRedstoneState(); - } - } - - @Override - protected void createBlockStateDefinition(StateDefinition.Builder builder) { - super.createBlockStateDefinition(builder); - builder.add(POWERED); - } - - @Override - protected BlockState updateBlockStateFromBlockEntity(BlockState currentState, IOPortBlockEntity be) { - return currentState.setValue(POWERED, be.isActive()); - } - - @Override - public InteractionResult onActivated(Level level, BlockPos pos, Player p, - InteractionHand hand, - @Nullable ItemStack heldItem, BlockHitResult hit) { - if (InteractionUtil.isInAlternateUseMode(p)) { - return InteractionResult.PASS; - } - - final IOPortBlockEntity tg = this.getBlockEntity(level, pos); - if (tg != null) { - if (!level.isClientSide()) { - hit.getDirection(); - MenuOpener.open(IOPortMenu.TYPE, p, - MenuLocators.forBlockEntity(tg)); - } - return InteractionResult.sidedSuccess(level.isClientSide()); - } - return InteractionResult.PASS; - } -} diff --git a/src/main/java/appeng/block/storage/SkyChestBlock.java b/src/main/java/appeng/block/storage/SkyChestBlock.java deleted file mode 100644 index 856d3b4d19e..00000000000 --- a/src/main/java/appeng/block/storage/SkyChestBlock.java +++ /dev/null @@ -1,195 +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 java.util.EnumMap; -import java.util.Map; - -import javax.annotation.Nullable; - -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.util.RandomSource; -import net.minecraft.world.InteractionHand; -import net.minecraft.world.InteractionResult; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.context.BlockPlaceContext; -import net.minecraft.world.level.BlockGetter; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.LevelAccessor; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.RenderShape; -import net.minecraft.world.level.block.SimpleWaterloggedBlock; -import net.minecraft.world.level.block.state.BlockBehaviour; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.state.StateDefinition.Builder; -import net.minecraft.world.level.block.state.properties.BlockStateProperties; -import net.minecraft.world.level.block.state.properties.BooleanProperty; -import net.minecraft.world.level.material.FluidState; -import net.minecraft.world.level.material.Fluids; -import net.minecraft.world.phys.AABB; -import net.minecraft.world.phys.BlockHitResult; -import net.minecraft.world.phys.shapes.CollisionContext; -import net.minecraft.world.phys.shapes.Shapes; -import net.minecraft.world.phys.shapes.VoxelShape; - -import appeng.block.AEBaseEntityBlock; -import appeng.blockentity.storage.SkyChestBlockEntity; -import appeng.core.definitions.AEBlockEntities; -import appeng.menu.MenuOpener; -import appeng.menu.implementations.SkyChestMenu; -import appeng.menu.locator.MenuLocators; - -public class SkyChestBlock extends AEBaseEntityBlock implements SimpleWaterloggedBlock { - - private static final double AABB_OFFSET_BOTTOM = 0.00; - private static final double AABB_OFFSET_SIDES = 0.06; - private static final double AABB_OFFSET_TOP = 0.0625; - - // Precomputed bounding boxes of the chest, sorted into the map by the UP - // direction - private static final Map SHAPES = new EnumMap<>(Direction.class); - - private static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED; - - static { - for (Direction up : Direction.values()) { - AABB aabb = computeAABB(up); - SHAPES.put(up, Shapes.create(aabb)); - } - } - - public enum SkyChestType { - STONE, BLOCK - } - - public final SkyChestType type; - - public SkyChestBlock(SkyChestType type, BlockBehaviour.Properties props) { - super(props); - this.type = type; - registerDefaultState(defaultBlockState().setValue(WATERLOGGED, false)); - } - - @Override - protected void createBlockStateDefinition(Builder builder) { - super.createBlockStateDefinition(builder); - builder.add(WATERLOGGED); - } - - @SuppressWarnings("deprecation") - @Override - public RenderShape getRenderShape(BlockState state) { - return RenderShape.ENTITYBLOCK_ANIMATED; - } - - @Override - public boolean propagatesSkylightDown(BlockState state, BlockGetter reader, BlockPos pos) { - return true; - } - - @Override - public InteractionResult onActivated(Level level, BlockPos pos, Player player, - InteractionHand hand, - @Nullable ItemStack heldItem, BlockHitResult hit) { - if (!level.isClientSide()) { - SkyChestBlockEntity blockEntity = getBlockEntity(level, pos); - if (blockEntity != null) { - blockEntity.unpackLootTable(player); - MenuOpener.open(SkyChestMenu.TYPE, player, - MenuLocators.forBlockEntity(blockEntity)); - } - } - - return InteractionResult.sidedSuccess(level.isClientSide()); - } - - @Override - public void tick(BlockState state, ServerLevel level, BlockPos pos, RandomSource random) { - level.getBlockEntity(pos, AEBlockEntities.SKY_CHEST).ifPresent(SkyChestBlockEntity::recheckOpen); - - } - - @Override - public VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) { - final SkyChestBlockEntity sk = this.getBlockEntity(level, pos); - Direction up = sk != null ? sk.getUp() : Direction.UP; - return SHAPES.get(up); - } - - private static AABB computeAABB(Direction up) { - final double offsetX = up.getStepX() == 0 ? AABB_OFFSET_SIDES : 0.0; - final double offsetY = up.getStepY() == 0 ? AABB_OFFSET_SIDES : 0.0; - final double offsetZ = up.getStepZ() == 0 ? AABB_OFFSET_SIDES : 0.0; - - // for x/z top and bottom is swapped - final double minX = Math.max(0.0, - offsetX + (up.getStepX() < 0 ? AABB_OFFSET_BOTTOM : up.getStepX() * AABB_OFFSET_TOP)); - final double minY = Math.max(0.0, - offsetY + (up.getStepY() < 0 ? AABB_OFFSET_TOP : up.getStepY() * AABB_OFFSET_BOTTOM)); - final double minZ = Math.max(0.0, - offsetZ + (up.getStepZ() < 0 ? AABB_OFFSET_BOTTOM : up.getStepZ() * AABB_OFFSET_TOP)); - - final double maxX = Math.min(1.0, - 1.0 - offsetX - (up.getStepX() < 0 ? AABB_OFFSET_TOP : up.getStepX() * AABB_OFFSET_BOTTOM)); - final double maxY = Math.min(1.0, - 1.0 - offsetY - (up.getStepY() < 0 ? AABB_OFFSET_BOTTOM : up.getStepY() * AABB_OFFSET_TOP)); - final double maxZ = Math.min(1.0, - 1.0 - offsetZ - (up.getStepZ() < 0 ? AABB_OFFSET_TOP : up.getStepZ() * AABB_OFFSET_BOTTOM)); - - return new AABB(minX, minY, minZ, maxX, maxY, maxZ); - } - - @Override - @Nullable - public BlockState getStateForPlacement(BlockPlaceContext context) { - BlockPos pos = context.getClickedPos(); - FluidState fluidState = context.getLevel().getFluidState(pos); - BlockState blockState = this.defaultBlockState() - .setValue(WATERLOGGED, fluidState.getType() == Fluids.WATER); - - return blockState; - } - - @Override - public FluidState getFluidState(BlockState blockState) { - return blockState.getValue(WATERLOGGED).booleanValue() - ? Fluids.WATER.getSource(false) - : super.getFluidState(blockState); - } - - @Override - public BlockState updateShape(BlockState blockState, Direction facing, BlockState facingState, LevelAccessor level, - BlockPos currentPos, BlockPos facingPos) { - if (blockState.getValue(WATERLOGGED)) { - level.scheduleTick(currentPos, Fluids.WATER, Fluids.WATER.getTickDelay(level)); - } - - return super.updateShape(blockState, facing, facingState, level, currentPos, facingPos); - } - - @Override - public void playerWillDestroy(Level level, BlockPos blockPos, BlockState state, Player player) { - super.playerWillDestroy(level, blockPos, state, player); - // Spawn loot for player - level.getBlockEntity(blockPos, AEBlockEntities.SKY_CHEST).ifPresent(chest -> chest.unpackLootTable(player)); - } -} diff --git a/src/main/java/appeng/block/storage/SkyStoneTankBlock.java b/src/main/java/appeng/block/storage/SkyStoneTankBlock.java deleted file mode 100644 index cd4dc760a2e..00000000000 --- a/src/main/java/appeng/block/storage/SkyStoneTankBlock.java +++ /dev/null @@ -1,49 +0,0 @@ -package appeng.block.storage; - -import java.util.List; - -import org.jetbrains.annotations.Nullable; - -import net.minecraft.core.BlockPos; -import net.minecraft.network.chat.Component; -import net.minecraft.world.InteractionHand; -import net.minecraft.world.InteractionResult; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.TooltipFlag; -import net.minecraft.world.level.BlockGetter; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.phys.BlockHitResult; - -import appeng.block.AEBaseEntityBlock; -import appeng.blockentity.storage.SkyStoneTankBlockEntity; -import appeng.core.localization.GuiText; -import appeng.core.localization.Tooltips; - -public class SkyStoneTankBlock extends AEBaseEntityBlock { - - public SkyStoneTankBlock(Properties props) { - super(props); - } - - @Override - public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, - InteractionHand hand, BlockHitResult hit) { - if (super.use(state, level, pos, player, hand, hit) == InteractionResult.PASS) { - SkyStoneTankBlockEntity be = (SkyStoneTankBlockEntity) level.getBlockEntity(pos); - if (be != null && be.onPlayerUse(player, hand)) { - return InteractionResult.sidedSuccess(level.isClientSide()); - } - - } - return InteractionResult.PASS; - } - - @Override - public void appendHoverText(ItemStack stack, @Nullable BlockGetter level, List tooltip, - TooltipFlag flag) { - super.appendHoverText(stack, level, tooltip, flag); - tooltip.add(Tooltips.of(GuiText.TankBucketCapacity, SkyStoneTankBlockEntity.BUCKET_CAPACITY)); - } -} diff --git a/src/main/java/appeng/blockentity/AEBaseBlockEntity.java b/src/main/java/appeng/blockentity/AEBaseBlockEntity.java index eb89200faa0..0cfd825cbe7 100644 --- a/src/main/java/appeng/blockentity/AEBaseBlockEntity.java +++ b/src/main/java/appeng/blockentity/AEBaseBlockEntity.java @@ -66,7 +66,6 @@ import appeng.helpers.ICustomNameObject; import appeng.hooks.VisualStateSaving; import appeng.hooks.ticking.TickHandler; -import appeng.items.tools.MemoryCardItem; import appeng.util.CustomNameUtil; import appeng.util.Platform; import appeng.util.SettingsFrom; @@ -328,10 +327,6 @@ public void setOrientation(Direction inForward, Direction inUp) { @OverridingMethodsMustInvokeSuper public void exportSettings(SettingsFrom mode, CompoundTag output, @Nullable Player player) { CustomNameUtil.setCustomName(output, customName); - - if (mode == SettingsFrom.MEMORY_CARD) { - MemoryCardItem.exportGenericSettings(this, output); - } } /** @@ -346,8 +341,6 @@ public void importSettings(SettingsFrom mode, CompoundTag input, @Nullable Playe if (customName != null) { this.customName = customName.getString(); } - - MemoryCardItem.importGenericSettings(this, input, player); } /** diff --git a/src/main/java/appeng/blockentity/crafting/CraftingBlockEntity.java b/src/main/java/appeng/blockentity/crafting/CraftingBlockEntity.java deleted file mode 100644 index 20669ba4852..00000000000 --- a/src/main/java/appeng/blockentity/crafting/CraftingBlockEntity.java +++ /dev/null @@ -1,331 +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.blockentity.crafting; - -import java.util.ArrayList; -import java.util.EnumSet; -import java.util.Iterator; - -import com.google.common.collect.Iterators; - -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.Items; -import net.minecraft.world.level.BlockGetter; -import net.minecraft.world.level.block.entity.BlockEntityType; -import net.minecraft.world.level.block.state.BlockState; - -import appeng.api.implementations.IPowerChannelState; -import appeng.api.networking.GridFlags; -import appeng.api.networking.IGridMultiblock; -import appeng.api.networking.IGridNode; -import appeng.api.networking.IGridNodeListener; -import appeng.api.util.IConfigManager; -import appeng.api.util.IConfigurableObject; -import appeng.block.crafting.AbstractCraftingUnitBlock; -import appeng.blockentity.grid.AENetworkBlockEntity; -import appeng.core.definitions.AEBlocks; -import appeng.me.cluster.IAEMultiBlock; -import appeng.me.cluster.implementations.CraftingCPUCalculator; -import appeng.me.cluster.implementations.CraftingCPUCluster; -import appeng.util.NullConfigManager; -import appeng.util.Platform; -import appeng.util.iterators.ChainedIterator; - -public class CraftingBlockEntity extends AENetworkBlockEntity - implements IAEMultiBlock, IPowerChannelState, IConfigurableObject { - - private final CraftingCPUCalculator calc = new CraftingCPUCalculator(this); - private CompoundTag previousState = null; - private boolean isCoreBlock = false; - private CraftingCPUCluster cluster; - - public CraftingBlockEntity(BlockEntityType blockEntityType, BlockPos pos, BlockState blockState) { - super(blockEntityType, pos, blockState); - this.getMainNode().setFlags(GridFlags.MULTIBLOCK, GridFlags.REQUIRE_CHANNEL) - .setExposedOnSides(EnumSet.noneOf(Direction.class)) - .addService(IGridMultiblock.class, this::getMultiblockNodes); - } - - @Override - protected Item getItemFromBlockEntity() { - if (this.level == null) { - return Items.AIR; - } - return getUnitBlock().type.getItemFromType(); - } - - @Override - public boolean canBeRotated() { - return false; - } - - @Override - public void setName(String name) { - super.setName(name); - if (this.cluster != null) { - this.cluster.updateName(); - } - } - - public AbstractCraftingUnitBlock getUnitBlock() { - if (this.level == null || this.notLoaded() || this.isRemoved()) { - return AEBlocks.CRAFTING_UNIT.block(); - } - return (AbstractCraftingUnitBlock) this.level.getBlockState(this.worldPosition).getBlock(); - } - - public long getStorageBytes() { - return getUnitBlock().type.getStorageBytes(); - } - - public int getAcceleratorThreads() { - return getUnitBlock().type.getAcceleratorThreads(); - } - - @Override - public void onReady() { - super.onReady(); - this.getMainNode().setVisualRepresentation(this.getItemFromBlockEntity()); - if (level instanceof ServerLevel serverLevel) { - this.calc.calculateMultiblock(serverLevel, worldPosition); - } - } - - public void updateMultiBlock(BlockPos changedPos) { - if (level instanceof ServerLevel serverLevel) { - this.calc.updateMultiblockAfterNeighborUpdate(serverLevel, worldPosition, changedPos); - } - } - - public void updateStatus(CraftingCPUCluster c) { - if (this.cluster != null && this.cluster != c) { - this.cluster.breakCluster(); - } - - this.cluster = c; - this.updateSubType(true); - } - - public void updateSubType(boolean updateFormed) { - if (this.level == null || this.notLoaded() || this.isRemoved()) { - return; - } - - final boolean formed = this.isFormed(); - boolean power = this.getMainNode().isOnline(); - - final BlockState current = this.level.getBlockState(this.worldPosition); - - // The block entity might try to update while being destroyed - if (current.getBlock() instanceof AbstractCraftingUnitBlock) { - final BlockState newState = current.setValue(AbstractCraftingUnitBlock.POWERED, power) - .setValue(AbstractCraftingUnitBlock.FORMED, formed); - - if (current != newState) { - // Not using flag 2 here (only send to clients, prevent block update) will cause - // infinite loops - // In case there is an inconsistency in the crafting clusters. - this.level.setBlock(this.worldPosition, newState, 2); - } - } - - if (updateFormed) { - if (formed) { - this.getMainNode().setExposedOnSides(EnumSet.allOf(Direction.class)); - } else { - this.getMainNode().setExposedOnSides(EnumSet.noneOf(Direction.class)); - } - } - } - - public boolean isFormed() { - if (isClientSide()) { - return this.level.getBlockState(this.worldPosition).getValue(AbstractCraftingUnitBlock.FORMED); - } - return this.cluster != null; - } - - @Override - public void saveAdditional(CompoundTag data) { - super.saveAdditional(data); - data.putBoolean("core", this.isCoreBlock()); - if (this.isCoreBlock() && this.cluster != null) { - this.cluster.writeToNBT(data); - } - } - - @Override - public void loadTag(CompoundTag data) { - super.loadTag(data); - this.setCoreBlock(data.getBoolean("core")); - if (this.isCoreBlock()) { - if (this.cluster != null) { - this.cluster.readFromNBT(data); - } else { - this.setPreviousState(data.copy()); - } - } - } - - @Override - public void disconnect(boolean update) { - if (this.cluster != null) { - this.cluster.destroy(); - if (update) { - this.updateSubType(true); - } - } - } - - @Override - public CraftingCPUCluster getCluster() { - return this.cluster; - } - - @Override - public boolean isValid() { - return true; - } - - @Override - public void onMainNodeStateChanged(IGridNodeListener.State reason) { - if (reason != IGridNodeListener.State.GRID_BOOT) { - this.updateSubType(false); - } - } - - public void breakCluster() { - if (this.cluster != null) { - this.cluster.cancel(); - var inv = this.cluster.craftingLogic.getInventory(); - - // Drop stacks - var places = new ArrayList(); - - for (var blockEntity : (Iterable) this.cluster::getBlockEntities) { - if (this == blockEntity) { - places.add(worldPosition); - } else { - for (var d : Direction.values()) { - var p = blockEntity.worldPosition.relative(d); - - if (this.level.isEmptyBlock(p)) { - places.add(p); - } - } - } - } - - if (places.isEmpty()) { - throw new IllegalStateException( - this.cluster + " does not contain any kind of blocks, which were destroyed."); - } - - for (var entry : inv.list) { - var position = places.get(Platform.getRandomInt() % places.size()); - var stacks = new ArrayList(); - entry.getKey().addDrops(entry.getLongValue(), stacks, this.level, position); - Platform.spawnDrops(this.level, position, stacks); - } - - this.cluster.destroy(); - } - } - - @Override - public boolean isPowered() { - if (isClientSide()) { - return this.level.getBlockState(this.worldPosition).getValue(AbstractCraftingUnitBlock.POWERED); - } - return this.getMainNode().isActive(); - } - - @Override - public boolean isActive() { - if (!isClientSide()) { - return this.getMainNode().isActive(); - } - return this.isPowered() && this.isFormed(); - } - - public boolean isCoreBlock() { - return this.isCoreBlock; - } - - public void setCoreBlock(boolean isCoreBlock) { - this.isCoreBlock = isCoreBlock; - } - - public CompoundTag getPreviousState() { - return this.previousState; - } - - public void setPreviousState(CompoundTag previousState) { - this.previousState = previousState; - } - - @Override - public Object getRenderAttachmentData() { - return new CraftingCubeModelData(getUp(), getForward(), getConnections()); - } - - protected EnumSet getConnections() { - if (level == null) { - return EnumSet.noneOf(Direction.class); - } - - EnumSet connections = EnumSet.noneOf(Direction.class); - - for (Direction facing : Direction.values()) { - if (this.isConnected(level, worldPosition, facing)) { - connections.add(facing); - } - } - - return connections; - } - - private boolean isConnected(BlockGetter level, BlockPos pos, Direction side) { - BlockPos adjacentPos = pos.relative(side); - return level.getBlockState(adjacentPos).getBlock() instanceof AbstractCraftingUnitBlock; - } - - private Iterator getMultiblockNodes() { - if (this.getCluster() == null) { - return new ChainedIterator<>(); - } - return Iterators.transform(this.getCluster().getBlockEntities(), CraftingBlockEntity::getGridNode); - } - - @Override - public IConfigManager getConfigManager() { - var cluster = this.getCluster(); - - if (cluster != null) { - return this.getCluster().getConfigManager(); - } else { - return NullConfigManager.INSTANCE; - } - } -} diff --git a/src/main/java/appeng/blockentity/crafting/CraftingCubeModelData.java b/src/main/java/appeng/blockentity/crafting/CraftingCubeModelData.java deleted file mode 100644 index d554fdd862b..00000000000 --- a/src/main/java/appeng/blockentity/crafting/CraftingCubeModelData.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * This file is part of Applied Energistics 2. - * Copyright (c) 2021, 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.blockentity.crafting; - -import java.util.EnumSet; -import java.util.Objects; - -import net.minecraft.core.Direction; - -import appeng.client.render.model.AEModelData; - -public class CraftingCubeModelData extends AEModelData { - - // Contains information on which sides of the block are connected to other parts - // of a formed crafting cube - private final EnumSet connections; - - public CraftingCubeModelData(Direction up, Direction forward, EnumSet connections) { - super(up, forward); - this.connections = Objects.requireNonNull(connections); - } - - @Override - public boolean isCacheable() { - return false; // Too many variants - } - - public EnumSet getConnections() { - return connections; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - if (!super.equals(o)) { - return false; - } - CraftingCubeModelData that = (CraftingCubeModelData) o; - return connections.equals(that.connections); - } - - @Override - public int hashCode() { - return Objects.hash(super.hashCode(), connections); - } - -} diff --git a/src/main/java/appeng/blockentity/crafting/CraftingMonitorBlockEntity.java b/src/main/java/appeng/blockentity/crafting/CraftingMonitorBlockEntity.java deleted file mode 100644 index b6e2866a5c6..00000000000 --- a/src/main/java/appeng/blockentity/crafting/CraftingMonitorBlockEntity.java +++ /dev/null @@ -1,117 +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.blockentity.crafting; - -import java.util.Objects; - -import javax.annotation.Nullable; - -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.level.block.entity.BlockEntityType; -import net.minecraft.world.level.block.state.BlockState; - -import appeng.api.implementations.blockentities.IColorableBlockEntity; -import appeng.api.stacks.GenericStack; -import appeng.api.util.AEColor; - -public class CraftingMonitorBlockEntity extends CraftingBlockEntity implements IColorableBlockEntity { - - private GenericStack display; - private AEColor paintedColor = AEColor.TRANSPARENT; - - public CraftingMonitorBlockEntity(BlockEntityType blockEntityType, BlockPos pos, BlockState blockState) { - super(blockEntityType, pos, blockState); - } - - @Override - protected boolean readFromStream(FriendlyByteBuf data) { - final boolean c = super.readFromStream(data); - final AEColor oldPaintedColor = this.paintedColor; - this.paintedColor = AEColor.values()[data.readByte()]; - - this.display = GenericStack.readBuffer(data); - - return oldPaintedColor != this.paintedColor || c; // Block Entity Renderer takes care of display - } - - @Override - protected void writeToStream(FriendlyByteBuf data) { - super.writeToStream(data); - data.writeByte(this.paintedColor.ordinal()); - - GenericStack.writeBuffer(display, data); - } - - @Override - public void loadTag(CompoundTag data) { - super.loadTag(data); - if (data.contains("paintedColor")) { - this.paintedColor = AEColor.values()[data.getByte("paintedColor")]; - } - } - - @Override - public void saveAdditional(CompoundTag data) { - super.saveAdditional(data); - data.putByte("paintedColor", (byte) this.paintedColor.ordinal()); - } - - public void setJob(@Nullable GenericStack stack) { - if (!Objects.equals(this.display, stack)) { - this.display = stack; - this.markForUpdate(); - } - } - - @Nullable - public GenericStack getJobProgress() { - return this.display; - } - - @Override - public AEColor getColor() { - return this.paintedColor; - } - - @Override - public boolean recolourBlock(Direction side, AEColor newPaintedColor, Player who) { - if (this.paintedColor == newPaintedColor) { - return false; - } - - this.paintedColor = newPaintedColor; - this.saveChanges(); - this.markForUpdate(); - return true; - } - - @Override - public Object getRenderAttachmentData() { - return new CraftingMonitorModelData(getUp(), getForward(), getConnections(), getColor()); - } - - @Override - public boolean canBeRotated() { - return true; - } -} diff --git a/src/main/java/appeng/blockentity/crafting/CraftingMonitorModelData.java b/src/main/java/appeng/blockentity/crafting/CraftingMonitorModelData.java deleted file mode 100644 index 859ebffc29f..00000000000 --- a/src/main/java/appeng/blockentity/crafting/CraftingMonitorModelData.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * This file is part of Applied Energistics 2. - * Copyright (c) 2021, 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.blockentity.crafting; - -import java.util.EnumSet; -import java.util.Objects; - -import net.minecraft.core.Direction; - -import appeng.api.util.AEColor; - -public class CraftingMonitorModelData extends CraftingCubeModelData { - - private final AEColor color; - - public CraftingMonitorModelData(Direction up, Direction forward, EnumSet connections, AEColor color) { - super(up, forward, connections); - this.color = Objects.requireNonNull(color); - } - - public AEColor getColor() { - return color; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - if (!super.equals(o)) { - return false; - } - CraftingMonitorModelData that = (CraftingMonitorModelData) o; - return color == that.color; - } - - @Override - public int hashCode() { - return Objects.hash(super.hashCode(), color); - } - -} diff --git a/src/main/java/appeng/blockentity/crafting/IMolecularAssemblerSupportedPattern.java b/src/main/java/appeng/blockentity/crafting/IMolecularAssemblerSupportedPattern.java deleted file mode 100644 index f22dee82aee..00000000000 --- a/src/main/java/appeng/blockentity/crafting/IMolecularAssemblerSupportedPattern.java +++ /dev/null @@ -1,31 +0,0 @@ -package appeng.blockentity.crafting; - -import net.minecraft.core.NonNullList; -import net.minecraft.world.Container; -import net.minecraft.world.inventory.CraftingContainer; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.Level; - -import appeng.api.crafting.IPatternDetails; -import appeng.api.stacks.AEItemKey; -import appeng.api.stacks.KeyCounter; - -/** - * Implement this on pattern details that support being assembled in the {@link MolecularAssemblerBlockEntity}. - */ -public interface IMolecularAssemblerSupportedPattern extends IPatternDetails { - ItemStack assemble(Container container, Level level); - - boolean isItemValid(int slot, AEItemKey key, Level level); - - boolean isSlotEnabled(int slot); - - void fillCraftingGrid(KeyCounter[] table, CraftingGridAccessor gridAccessor); - - @FunctionalInterface - interface CraftingGridAccessor { - void set(int slot, ItemStack stack); - } - - NonNullList getRemainingItems(CraftingContainer container); -} diff --git a/src/main/java/appeng/blockentity/crafting/MolecularAssemblerBlockEntity.java b/src/main/java/appeng/blockentity/crafting/MolecularAssemblerBlockEntity.java deleted file mode 100644 index e0a8f09df66..00000000000 --- a/src/main/java/appeng/blockentity/crafting/MolecularAssemblerBlockEntity.java +++ /dev/null @@ -1,625 +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.blockentity.crafting; - -import java.util.List; -import java.util.Optional; - -import javax.annotation.Nullable; - -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.network.chat.Component; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.inventory.CraftingContainer; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraft.world.level.block.entity.BlockEntityType; -import net.minecraft.world.level.block.state.BlockState; - -import appeng.api.config.Actionable; -import appeng.api.config.PowerMultiplier; -import appeng.api.crafting.IPatternDetails; -import appeng.api.crafting.PatternDetailsHelper; -import appeng.api.implementations.IPowerChannelState; -import appeng.api.implementations.blockentities.ICraftingMachine; -import appeng.api.implementations.blockentities.PatternContainerGroup; -import appeng.api.inventories.ISegmentedInventory; -import appeng.api.inventories.InternalInventory; -import appeng.api.networking.IGridNode; -import appeng.api.networking.IGridNodeListener; -import appeng.api.networking.ticking.IGridTickable; -import appeng.api.networking.ticking.TickRateModulation; -import appeng.api.networking.ticking.TickingRequest; -import appeng.api.stacks.AEItemKey; -import appeng.api.stacks.KeyCounter; -import appeng.api.upgrades.IUpgradeInventory; -import appeng.api.upgrades.IUpgradeableObject; -import appeng.api.upgrades.UpgradeInventories; -import appeng.api.util.AECableType; -import appeng.blockentity.grid.AENetworkInvBlockEntity; -import appeng.client.render.crafting.AssemblerAnimationStatus; -import appeng.core.AELog; -import appeng.core.AppEng; -import appeng.core.definitions.AEBlocks; -import appeng.core.definitions.AEItems; -import appeng.core.localization.GuiText; -import appeng.core.localization.Tooltips; -import appeng.core.sync.network.NetworkHandler; -import appeng.core.sync.network.TargetPoint; -import appeng.core.sync.packets.AssemblerAnimationPacket; -import appeng.crafting.CraftingEvent; -import appeng.menu.AutoCraftingMenu; -import appeng.util.inv.AppEngInternalInventory; -import appeng.util.inv.CombinedInternalInventory; -import appeng.util.inv.FilteredInternalInventory; -import appeng.util.inv.filter.IAEItemFilter; - -public class MolecularAssemblerBlockEntity extends AENetworkInvBlockEntity - implements IUpgradeableObject, IGridTickable, ICraftingMachine, IPowerChannelState { - - /** - * Identifies the sub-inventory used by molecular assemblers to store the input items for the crafting process. - */ - public static final ResourceLocation INV_MAIN = AppEng.makeId("molecular_assembler"); - - private final CraftingContainer craftingInv; - private final AppEngInternalInventory gridInv = new AppEngInternalInventory(this, 9 + 1, 1); - private final AppEngInternalInventory patternInv = new AppEngInternalInventory(this, 1, 1); - private final InternalInventory gridInvExt = new FilteredInternalInventory(this.gridInv, new CraftingGridFilter()); - private final InternalInventory internalInv = new CombinedInternalInventory(this.gridInv, this.patternInv); - private final IUpgradeInventory upgrades; - private boolean isPowered = false; - private Direction pushDirection = null; - private ItemStack myPattern = ItemStack.EMPTY; - private IMolecularAssemblerSupportedPattern myPlan = null; - private double progress = 0; - private boolean isAwake = false; - private boolean forcePlan = false; - private boolean reboot = true; - - @Environment(EnvType.CLIENT) - private AssemblerAnimationStatus animationStatus; - - public MolecularAssemblerBlockEntity(BlockEntityType blockEntityType, BlockPos pos, BlockState blockState) { - super(blockEntityType, pos, blockState); - - this.getMainNode() - .setIdlePowerUsage(0.0) - .addService(IGridTickable.class, this); - this.upgrades = UpgradeInventories.forMachine(AEBlocks.MOLECULAR_ASSEMBLER, getUpgradeSlots(), - this::saveChanges); - this.craftingInv = new CraftingContainer(new AutoCraftingMenu(), 3, 3); - - } - - private int getUpgradeSlots() { - return 5; - } - - @org.jetbrains.annotations.Nullable - @Override - public PatternContainerGroup getCraftingMachineInfo() { - Component name; - if (hasCustomInventoryName()) { - name = getCustomInventoryName(); - } else { - name = AEBlocks.MOLECULAR_ASSEMBLER.asItem().getDescription(); - } - var icon = AEItemKey.of(AEBlocks.MOLECULAR_ASSEMBLER); - - // List installed upgrades as the tooltip to differentiate assemblers by upgrade count - List tooltip; - var accelerationCards = getInstalledUpgrades(AEItems.SPEED_CARD); - if (accelerationCards == 0) { - tooltip = List.of(); - } else { - tooltip = List.of( - GuiText.CompatibleUpgrade.text( - Tooltips.of(AEItems.SPEED_CARD.asItem().getDescription()), - Tooltips.ofUnformattedNumber(accelerationCards))); - } - - return new PatternContainerGroup(icon, name, tooltip); - } - - @Override - public Optional getDisplayName() { - if (hasCustomInventoryName()) { - return Optional.of(getCustomInventoryName()); - } else { - return Optional.of(getItemFromBlockEntity().getDescription()); - } - } - - @Override - public boolean pushPattern(IPatternDetails patternDetails, KeyCounter[] table, - Direction where) { - if (this.myPattern.isEmpty()) { - boolean isEmpty = this.gridInv.isEmpty() && this.patternInv.isEmpty(); - - // Only accept our own crafting patterns! - if (isEmpty && patternDetails instanceof IMolecularAssemblerSupportedPattern pattern) { - // We only support fluid and item stacks - - this.forcePlan = true; - this.myPlan = pattern; - this.pushDirection = where; - - this.fillGrid(table, pattern); - - this.updateSleepiness(); - this.saveChanges(); - return true; - } - } - return false; - } - - private void fillGrid(KeyCounter[] table, IMolecularAssemblerSupportedPattern adapter) { - adapter.fillCraftingGrid(table, this.gridInv::setItemDirect); - - // Sanity check - for (var list : table) { - list.removeZeros(); - if (!list.isEmpty()) { - throw new RuntimeException("Could not fill grid with some items, including " + list.iterator().next()); - } - } - } - - private void updateSleepiness() { - final boolean wasEnabled = this.isAwake; - this.isAwake = this.myPlan != null && this.hasMats() || this.canPush(); - if (wasEnabled != this.isAwake) { - getMainNode().ifPresent((grid, node) -> { - if (this.isAwake) { - grid.getTickManager().wakeDevice(node); - } else { - grid.getTickManager().sleepDevice(node); - } - }); - } - } - - private boolean canPush() { - return !this.gridInv.getStackInSlot(9).isEmpty(); - } - - private boolean hasMats() { - if (this.myPlan == null) { - return false; - } - - for (int x = 0; x < this.craftingInv.getContainerSize(); x++) { - this.craftingInv.setItem(x, this.gridInv.getStackInSlot(x)); - } - - return !this.myPlan.assemble(this.craftingInv, this.getLevel()).isEmpty(); - } - - @Override - public boolean acceptsPlans() { - return this.patternInv.isEmpty(); - } - - @Override - protected boolean readFromStream(FriendlyByteBuf data) { - final boolean c = super.readFromStream(data); - final boolean oldPower = this.isPowered; - this.isPowered = data.readBoolean(); - return this.isPowered != oldPower || c; - } - - @Override - protected void writeToStream(FriendlyByteBuf data) { - super.writeToStream(data); - data.writeBoolean(this.isPowered); - } - - @Override - public void saveAdditional(CompoundTag data) { - super.saveAdditional(data); - if (this.forcePlan) { - // If the plan is null it means the pattern previously loaded from NBT hasn't been decoded yet - var pattern = myPlan != null ? myPlan.getDefinition().toStack() : myPattern; - if (!pattern.isEmpty()) { - var compound = new CompoundTag(); - pattern.save(compound); - data.put("myPlan", compound); - data.putInt("pushDirection", this.pushDirection.ordinal()); - } - } - - this.upgrades.writeToNBT(data, "upgrades"); - } - - @Override - public void loadTag(CompoundTag data) { - super.loadTag(data); - - // Reset current state back to defaults - this.forcePlan = false; - this.myPattern = ItemStack.EMPTY; - this.myPlan = null; - - if (data.contains("myPlan")) { - var pattern = ItemStack.of(data.getCompound("myPlan")); - if (!pattern.isEmpty()) { - this.forcePlan = true; - this.myPattern = pattern; - this.pushDirection = Direction.values()[data.getInt("pushDirection")]; - } - } - - this.upgrades.readFromNBT(data, "upgrades"); - this.recalculatePlan(); - } - - private void recalculatePlan() { - this.reboot = true; - - if (this.forcePlan) { - // If we're in forced mode, and myPattern is not empty, but the plan is null, - // this indicates that we received an encoded pattern from NBT data, but - // didn't have a chance to decode it yet - if (getLevel() != null && myPlan == null) { - if (!myPattern.isEmpty()) { - if (PatternDetailsHelper.decodePattern(myPattern, getLevel(), - false) instanceof IMolecularAssemblerSupportedPattern supportedPlan) { - this.myPlan = supportedPlan; - } - } - - // Reset myPattern, so it will accept another job once this one finishes - this.myPattern = ItemStack.EMPTY; - - // If the plan is still null, reset back to non-forced mode - if (myPlan == null) { - AELog.warn("Unable to restore auto-crafting pattern after load: %s", myPattern.getTag()); - this.forcePlan = false; - } - } - - return; - } - - final ItemStack is = this.patternInv.getStackInSlot(0); - - boolean reset = true; - - if (!is.isEmpty()) { - if (ItemStack.isSame(is, this.myPattern)) { - reset = false; - } else if (PatternDetailsHelper.decodePattern(is, getLevel(), - false) instanceof IMolecularAssemblerSupportedPattern supportedPattern) { - reset = false; - this.progress = 0; - this.myPattern = is; - this.myPlan = supportedPattern; - } - } - - if (reset) { - this.progress = 0; - this.forcePlan = false; - this.myPlan = null; - this.myPattern = ItemStack.EMPTY; - this.pushDirection = null; - } - - this.updateSleepiness(); - } - - @Override - public AECableType getCableConnectionType(Direction dir) { - return AECableType.COVERED; - } - - @Override - public InternalInventory getSubInventory(ResourceLocation id) { - if (id.equals(ISegmentedInventory.UPGRADES)) { - return this.upgrades; - } else if (id.equals(INV_MAIN)) { - return this.internalInv; - } - - return super.getSubInventory(id); - } - - @Override - public InternalInventory getInternalInventory() { - return this.internalInv; - } - - @Override - public InternalInventory getExposedInventoryForSide(Direction side) { - return this.gridInvExt; - } - - @Override - public void onChangeInventory(InternalInventory inv, int slot) { - if (inv == this.gridInv || inv == this.patternInv) { - this.recalculatePlan(); - } - } - - public int getCraftingProgress() { - return (int) this.progress; - } - - @Override - public void addAdditionalDrops(Level level, BlockPos pos, List drops) { - super.addAdditionalDrops(level, pos, drops); - - for (var upgrade : upgrades) { - drops.add(upgrade); - } - } - - @Override - public TickingRequest getTickingRequest(IGridNode node) { - this.recalculatePlan(); - this.updateSleepiness(); - return new TickingRequest(1, 1, !this.isAwake, false); - } - - @Override - public TickRateModulation tickingRequest(IGridNode node, int ticksSinceLastCall) { - if (!this.gridInv.getStackInSlot(9).isEmpty()) { - this.pushOut(this.gridInv.getStackInSlot(9)); - - // did it eject? - if (this.gridInv.getStackInSlot(9).isEmpty()) { - this.saveChanges(); - } - - this.ejectHeldItems(); - this.updateSleepiness(); - this.progress = 0; - return this.isAwake ? TickRateModulation.IDLE : TickRateModulation.SLEEP; - } - - if (this.myPlan == null) { - this.updateSleepiness(); - return TickRateModulation.SLEEP; - } - - if (this.reboot) { - ticksSinceLastCall = 1; - } - - if (!this.isAwake) { - return TickRateModulation.SLEEP; - } - - this.reboot = false; - int speed = 10; - switch (this.upgrades.getInstalledUpgrades(AEItems.SPEED_CARD)) { - case 0 -> this.progress += this.userPower(ticksSinceLastCall, speed = 10, 1.0); - case 1 -> this.progress += this.userPower(ticksSinceLastCall, speed = 13, 1.3); - case 2 -> this.progress += this.userPower(ticksSinceLastCall, speed = 17, 1.7); - case 3 -> this.progress += this.userPower(ticksSinceLastCall, speed = 20, 2.0); - case 4 -> this.progress += this.userPower(ticksSinceLastCall, speed = 25, 2.5); - case 5 -> this.progress += this.userPower(ticksSinceLastCall, speed = 50, 5.0); - } - - if (this.progress >= 100) { - for (int x = 0; x < this.craftingInv.getContainerSize(); x++) { - this.craftingInv.setItem(x, this.gridInv.getStackInSlot(x)); - } - - this.progress = 0; - final ItemStack output = this.myPlan.assemble(this.craftingInv, this.getLevel()); - if (!output.isEmpty()) { - CraftingEvent.fireAutoCraftingEvent(getLevel(), this.myPlan, output, this.craftingInv); - - // pushOut might reset the plan back to null, so get the remaining items before - var craftingRemainders = this.myPlan.getRemainingItems(this.craftingInv); - - this.pushOut(output.copy()); - - for (int x = 0; x < this.craftingInv.getContainerSize(); x++) { - this.gridInv.setItemDirect(x, craftingRemainders.get(x)); - } - - if (this.patternInv.isEmpty()) { - this.forcePlan = false; - this.myPlan = null; - this.pushDirection = null; - } - - this.ejectHeldItems(); - - var item = AEItemKey.of(output); - if (item != null) { - final TargetPoint where = new TargetPoint(this.worldPosition.getX(), this.worldPosition.getY(), - this.worldPosition.getZ(), 32, - this.level); - NetworkHandler.instance() - .sendToAllAround(new AssemblerAnimationPacket(this.worldPosition, (byte) speed, item), - where); - } - - this.saveChanges(); - this.updateSleepiness(); - return this.isAwake ? TickRateModulation.IDLE : TickRateModulation.SLEEP; - } - } - - return TickRateModulation.FASTER; - } - - private void ejectHeldItems() { - if (this.gridInv.getStackInSlot(9).isEmpty()) { - for (int x = 0; x < 9; x++) { - final ItemStack is = this.gridInv.getStackInSlot(x); - if (!is.isEmpty() - && (this.myPlan == null || !this.myPlan.isItemValid(x, AEItemKey.of(is), this.level))) { - this.gridInv.setItemDirect(9, is); - this.gridInv.setItemDirect(x, ItemStack.EMPTY); - this.saveChanges(); - return; - } - } - } - } - - private int userPower(int ticksPassed, int bonusValue, double acceleratorTax) { - var grid = getMainNode().getGrid(); - if (grid != null) { - return (int) (grid.getEnergyService().extractAEPower(ticksPassed * bonusValue * acceleratorTax, - Actionable.MODULATE, PowerMultiplier.CONFIG) / acceleratorTax); - } else { - return 0; - } - } - - private void pushOut(ItemStack output) { - if (this.pushDirection == null) { - for (Direction d : Direction.values()) { - output = this.pushTo(output, d); - } - } else { - output = this.pushTo(output, this.pushDirection); - } - - if (output.isEmpty() && this.forcePlan) { - this.forcePlan = false; - this.recalculatePlan(); - } - - this.gridInv.setItemDirect(9, output); - } - - private ItemStack pushTo(ItemStack output, Direction d) { - if (output.isEmpty()) { - return output; - } - - final BlockEntity te = this.getLevel().getBlockEntity(this.worldPosition.relative(d)); - - if (te == null) { - return output; - } - - var adaptor = InternalInventory.wrapExternal(te, d.getOpposite()); - if (adaptor == null) { - return output; - } - - final int size = output.getCount(); - output = adaptor.addItems(output); - final int newSize = output.isEmpty() ? 0 : output.getCount(); - - if (size != newSize) { - this.saveChanges(); - } - - return output; - } - - @Override - public void onMainNodeStateChanged(IGridNodeListener.State reason) { - if (reason != IGridNodeListener.State.GRID_BOOT) { - boolean newState = false; - - var grid = getMainNode().getGrid(); - if (grid != null) { - newState = this.getMainNode().isPowered() && grid.getEnergyService().extractAEPower(1, - Actionable.SIMULATE, PowerMultiplier.CONFIG) > 0.0001; - } - - if (newState != this.isPowered) { - this.isPowered = newState; - this.markForUpdate(); - } - } - } - - @Override - public boolean isPowered() { - return this.isPowered; - } - - @Override - public boolean isActive() { - return this.isPowered; - } - - @Environment(EnvType.CLIENT) - public void setAnimationStatus(@Nullable AssemblerAnimationStatus status) { - this.animationStatus = status; - } - - @Environment(EnvType.CLIENT) - @Nullable - public AssemblerAnimationStatus getAnimationStatus() { - return this.animationStatus; - } - - @Override - public IUpgradeInventory getUpgrades() { - return upgrades; - } - - @Nullable - public IMolecularAssemblerSupportedPattern getCurrentPattern() { - if (isClientSide()) { - var patternItem = patternInv.getStackInSlot(0); - var pattern = PatternDetailsHelper.decodePattern(patternItem, level); - if (pattern instanceof IMolecularAssemblerSupportedPattern supportedPattern) { - return supportedPattern; - } - return null; - } else { - return myPlan; - } - } - - private class CraftingGridFilter implements IAEItemFilter { - private boolean hasPattern() { - return MolecularAssemblerBlockEntity.this.myPlan != null - && !MolecularAssemblerBlockEntity.this.patternInv.isEmpty(); - } - - @Override - public boolean allowExtract(InternalInventory inv, int slot, int amount) { - return slot == 9; - } - - @Override - public boolean allowInsert(InternalInventory inv, int slot, ItemStack stack) { - if (slot >= 9) { - return false; - } - - if (this.hasPattern()) { - return MolecularAssemblerBlockEntity.this.myPlan.isItemValid(slot, AEItemKey.of(stack), - MolecularAssemblerBlockEntity.this.getLevel()); - } - return false; - } - } -} diff --git a/src/main/java/appeng/blockentity/crafting/PatternProviderBlockEntity.java b/src/main/java/appeng/blockentity/crafting/PatternProviderBlockEntity.java deleted file mode 100644 index 84666d39534..00000000000 --- a/src/main/java/appeng/blockentity/crafting/PatternProviderBlockEntity.java +++ /dev/null @@ -1,200 +0,0 @@ -/* - * This file is part of Applied Energistics 2. - * Copyright (c) 2021, 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.blockentity.crafting; - -import java.util.EnumSet; -import java.util.List; - -import javax.annotation.Nullable; - -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.entity.BlockEntityType; -import net.minecraft.world.level.block.state.BlockState; - -import appeng.api.networking.IGridNodeListener; -import appeng.api.stacks.AEItemKey; -import appeng.api.util.AECableType; -import appeng.blockentity.grid.AENetworkBlockEntity; -import appeng.core.definitions.AEBlocks; -import appeng.helpers.iface.PatternProviderLogic; -import appeng.helpers.iface.PatternProviderLogicHost; -import appeng.util.Platform; -import appeng.util.SettingsFrom; - -public class PatternProviderBlockEntity extends AENetworkBlockEntity implements PatternProviderLogicHost { - protected final PatternProviderLogic logic = createLogic(); - private boolean omniDirectional = true; - - public PatternProviderBlockEntity(BlockEntityType blockEntityType, BlockPos pos, BlockState blockState) { - super(blockEntityType, pos, blockState); - } - - protected PatternProviderLogic createLogic() { - return new PatternProviderLogic(this.getMainNode(), this); - } - - @Override - public void onMainNodeStateChanged(IGridNodeListener.State reason) { - this.logic.onMainNodeStateChanged(); - } - - public void setSide(Direction facing) { - Direction newForward; - - if (!this.omniDirectional && this.getForward() == facing.getOpposite()) { - newForward = facing; - } else if (!this.omniDirectional - && (this.getForward() == facing || this.getForward() == facing.getOpposite())) { - newForward = null; - } else if (this.omniDirectional) { - newForward = facing.getOpposite(); - } else { - newForward = Platform.rotateAround(this.getForward(), facing); - } - - setPushDirection(newForward); - } - - public void setPushDirection(@Nullable Direction direction) { - this.omniDirectional = direction == null; - if (direction == null) { - direction = Direction.NORTH; - } - - Direction newUp = Direction.UP; - if (direction == Direction.UP || direction == Direction.DOWN) { - newUp = Direction.NORTH; - } - this.setOrientation(direction, newUp); - - if (!isClientSide()) { - this.configureNodeSides(); - this.markForUpdate(); - this.saveChanges(); - } - } - - private void configureNodeSides() { - if (this.omniDirectional) { - this.getMainNode().setExposedOnSides(EnumSet.allOf(Direction.class)); - } else { - this.getMainNode().setExposedOnSides(EnumSet.complementOf(EnumSet.of(this.getForward()))); - } - } - - @Override - public void addAdditionalDrops(Level level, BlockPos pos, List drops) { - this.logic.addDrops(drops); - } - - @Override - public void onReady() { - this.configureNodeSides(); - - super.onReady(); - this.logic.updatePatterns(); - } - - @Override - public void saveAdditional(CompoundTag data) { - super.saveAdditional(data); - data.putBoolean("omniDirectional", this.omniDirectional); - this.logic.writeToNBT(data); - } - - @Override - public void loadTag(CompoundTag data) { - super.loadTag(data); - this.omniDirectional = data.getBoolean("omniDirectional"); - - this.logic.readFromNBT(data); - } - - @Override - protected boolean readFromStream(FriendlyByteBuf data) { - final boolean c = super.readFromStream(data); - boolean oldOmniDirectional = this.omniDirectional; - this.omniDirectional = data.readBoolean(); - return oldOmniDirectional != this.omniDirectional || c; - } - - @Override - protected void writeToStream(FriendlyByteBuf data) { - super.writeToStream(data); - data.writeBoolean(this.omniDirectional); - } - - @Override - public AECableType getCableConnectionType(Direction dir) { - return AECableType.SMART; - } - - @Override - public PatternProviderLogic getLogic() { - return logic; - } - - @Override - public EnumSet getTargets() { - if (this.omniDirectional) { - return EnumSet.allOf(Direction.class); - } - return EnumSet.of(this.getForward()); - } - - @Override - public AEItemKey getTerminalIcon() { - return AEItemKey.of(AEBlocks.PATTERN_PROVIDER.stack()); - } - - @Override - public void exportSettings(SettingsFrom mode, CompoundTag output, - @org.jetbrains.annotations.Nullable Player player) { - super.exportSettings(mode, output, player); - - if (mode == SettingsFrom.MEMORY_CARD) { - logic.exportSettings(output); - } - } - - @Override - public void importSettings(SettingsFrom mode, CompoundTag input, - @org.jetbrains.annotations.Nullable Player player) { - super.importSettings(mode, input, player); - - if (mode == SettingsFrom.MEMORY_CARD) { - logic.importSettings(input, player); - } - } - - public boolean isOmniDirectional() { - return this.omniDirectional; - } - - @Override - public ItemStack getMainMenuIcon() { - return AEBlocks.PATTERN_PROVIDER.stack(); - } -} diff --git a/src/main/java/appeng/blockentity/grid/AENetworkPowerBlockEntity.java b/src/main/java/appeng/blockentity/grid/AENetworkPowerBlockEntity.java deleted file mode 100644 index d6ac19defc2..00000000000 --- a/src/main/java/appeng/blockentity/grid/AENetworkPowerBlockEntity.java +++ /dev/null @@ -1,118 +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.blockentity.grid; - -import javax.annotation.Nullable; - -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.world.level.block.entity.BlockEntityType; -import net.minecraft.world.level.block.state.BlockState; - -import appeng.api.networking.GridHelper; -import appeng.api.networking.IGridNode; -import appeng.api.networking.IInWorldGridNodeHost; -import appeng.api.networking.IManagedGridNode; -import appeng.api.networking.energy.IAEPowerStorage; -import appeng.api.util.AECableType; -import appeng.blockentity.powersink.AEBasePoweredBlockEntity; -import appeng.me.helpers.BlockEntityNodeListener; -import appeng.me.helpers.IGridConnectedBlockEntity; - -public abstract class AENetworkPowerBlockEntity extends AEBasePoweredBlockEntity - implements IInWorldGridNodeHost, IGridConnectedBlockEntity { - - private final IManagedGridNode mainNode = createMainNode() - .setVisualRepresentation(getItemFromBlockEntity()) - .addService(IAEPowerStorage.class, this) - .setInWorldNode(true) - .setTagName("proxy"); - - public AENetworkPowerBlockEntity(BlockEntityType blockEntityType, BlockPos pos, BlockState blockState) { - super(blockEntityType, pos, blockState); - } - - protected IManagedGridNode createMainNode() { - return GridHelper.createManagedNode(this, BlockEntityNodeListener.INSTANCE); - } - - @Override - public void loadTag(CompoundTag data) { - super.loadTag(data); - this.getMainNode().loadFromNBT(data); - } - - @Override - public void saveAdditional(CompoundTag data) { - super.saveAdditional(data); - this.getMainNode().saveToNBT(data); - } - - public final IManagedGridNode getMainNode() { - return this.mainNode; - } - - @Nullable - public IGridNode getGridNode() { - return this.mainNode.getNode(); - } - - @Override - public IGridNode getGridNode(Direction dir) { - var node = this.getMainNode().getNode(); - - // Check if the proxy exposes the node on this side - if (node != null && node.isExposedOnSide(dir)) { - return node; - } - - return null; - } - - @Override - public AECableType getCableConnectionType(Direction dir) { - return AECableType.SMART; - } - - @Override - public void clearRemoved() { - super.clearRemoved(); - scheduleInit(); // Required for onReady to be called - } - - @Override - public void setRemoved() { - super.setRemoved(); - this.getMainNode().destroy(); - } - - @Override - public void onChunkUnloaded() { - super.onChunkUnloaded(); - this.getMainNode().destroy(); - } - - @Override - public void onReady() { - super.onReady(); - this.getMainNode().create(getLevel(), getBlockEntity().getBlockPos()); - } - -} diff --git a/src/main/java/appeng/blockentity/inventory/AppEngCellInventory.java b/src/main/java/appeng/blockentity/inventory/AppEngCellInventory.java deleted file mode 100644 index 27b368d3076..00000000000 --- a/src/main/java/appeng/blockentity/inventory/AppEngCellInventory.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * This file is part of Applied Energistics 2. - * Copyright (c) 2021, 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.blockentity.inventory; - -import net.minecraft.world.item.ItemStack; - -import appeng.api.inventories.BaseInternalInventory; -import appeng.api.storage.cells.StorageCell; -import appeng.util.inv.AppEngInternalInventory; -import appeng.util.inv.InternalInventoryHost; -import appeng.util.inv.filter.IAEItemFilter; - -public class AppEngCellInventory extends BaseInternalInventory { - private final AppEngInternalInventory inv; - private final StorageCell[] handlerForSlot; - - public AppEngCellInventory(InternalInventoryHost host, int slots) { - this.inv = new AppEngInternalInventory(host, slots, 1); - this.handlerForSlot = new StorageCell[slots]; - } - - public void setHandler(int slot, StorageCell handler) { - this.handlerForSlot[slot] = handler; - } - - public void setFilter(IAEItemFilter filter) { - this.inv.setFilter(filter); - } - - @Override - public void setItemDirect(int slot, ItemStack stack) { - this.persist(slot); - this.inv.setItemDirect(slot, stack); - } - - @Override - public int size() { - return this.inv.size(); - } - - @Override - public ItemStack getStackInSlot(int slot) { - this.persist(slot); - return this.inv.getStackInSlot(slot); - } - - @Override - public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) { - this.persist(slot); - return this.inv.insertItem(slot, stack, simulate); - } - - @Override - public ItemStack extractItem(int slot, int amount, boolean simulate) { - this.persist(slot); - return this.inv.extractItem(slot, amount, simulate); - } - - @Override - public int getSlotLimit(int slot) { - return this.inv.getSlotLimit(slot); - } - - @Override - public boolean isItemValid(int slot, ItemStack stack) { - return this.inv.isItemValid(slot, stack); - } - - public void persist() { - for (int i = 0; i < this.size(); ++i) { - this.persist(i); - } - } - - private void persist(int slot) { - if (this.handlerForSlot[slot] != null) { - this.handlerForSlot[slot].persist(); - } - } - - @Override - public void sendChangeNotification(int slot) { - inv.sendChangeNotification(slot); - } -} diff --git a/src/main/java/appeng/blockentity/misc/CellWorkbenchBlockEntity.java b/src/main/java/appeng/blockentity/misc/CellWorkbenchBlockEntity.java deleted file mode 100644 index 0fdcbea4390..00000000000 --- a/src/main/java/appeng/blockentity/misc/CellWorkbenchBlockEntity.java +++ /dev/null @@ -1,226 +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.blockentity.misc; - -import java.util.List; - -import net.minecraft.core.BlockPos; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.entity.BlockEntityType; -import net.minecraft.world.level.block.state.BlockState; - -import appeng.api.config.CopyMode; -import appeng.api.config.Settings; -import appeng.api.inventories.ISegmentedInventory; -import appeng.api.inventories.InternalInventory; -import appeng.api.storage.cells.ICellWorkbenchItem; -import appeng.api.upgrades.IUpgradeInventory; -import appeng.api.upgrades.IUpgradeableObject; -import appeng.api.upgrades.UpgradeInventories; -import appeng.api.util.IConfigManager; -import appeng.api.util.IConfigurableObject; -import appeng.blockentity.AEBaseBlockEntity; -import appeng.helpers.IConfigInvHost; -import appeng.helpers.externalstorage.GenericStackInv; -import appeng.util.ConfigInventory; -import appeng.util.ConfigManager; -import appeng.util.inv.AppEngInternalInventory; -import appeng.util.inv.InternalInventoryHost; - -public class CellWorkbenchBlockEntity extends AEBaseBlockEntity - implements IConfigurableObject, IUpgradeableObject, InternalInventoryHost, IConfigInvHost { - - private final AppEngInternalInventory cell = new AppEngInternalInventory(this, 1); - private final GenericStackInv config = new GenericStackInv(this::configChanged, GenericStackInv.Mode.CONFIG_TYPES, - 63); - private final ConfigManager manager = new ConfigManager(this::saveChanges); - - private IUpgradeInventory cacheUpgrades = null; - private ConfigInventory cacheConfig = null; - private boolean locked = false; - - public CellWorkbenchBlockEntity(BlockEntityType blockEntityType, BlockPos pos, BlockState blockState) { - super(blockEntityType, pos, blockState); - this.manager.registerSetting(Settings.COPY_MODE, CopyMode.CLEAR_ON_REMOVE); - this.cell.setEnableClientEvents(true); - } - - public ICellWorkbenchItem getCell() { - if (this.cell.getStackInSlot(0).isEmpty()) { - return null; - } - - if (this.cell.getStackInSlot(0).getItem() instanceof ICellWorkbenchItem) { - return (ICellWorkbenchItem) this.cell.getStackInSlot(0).getItem(); - } - - return null; - } - - @Override - public void saveAdditional(CompoundTag data) { - super.saveAdditional(data); - this.cell.writeToNBT(data, "cell"); - this.config.writeToChildTag(data, "config"); - this.manager.writeToNBT(data); - } - - @Override - public void loadTag(CompoundTag data) { - super.loadTag(data); - this.cell.readFromNBT(data, "cell"); - this.config.readFromChildTag(data, "config"); - this.manager.readFromNBT(data); - } - - @Override - public InternalInventory getSubInventory(ResourceLocation id) { - if (id.equals(ISegmentedInventory.CELLS)) { - return this.cell; - } - - return super.getSubInventory(id); - } - - @Override - public void onChangeInventory(InternalInventory inv, int slot) { - if (inv == this.cell && !this.locked) { - this.locked = true; - try { - this.cacheUpgrades = null; - this.cacheConfig = null; - - var configInventory = this.getCellConfigInventory(); - if (configInventory != null) { - if (!configInventory.isEmpty()) { - // Copy cell -> config inventory - copy(configInventory, this.config); - } else { - // Copy config inventory -> cell, when cell's config is empty - copy(this.config, configInventory); - // Copy items back. The cell may change the items on insert, for example if a fluid tank gets - // turned - // into a dummy fluid item. - copy(configInventory, this.config); - } - } else if (this.manager.getSetting(Settings.COPY_MODE) == CopyMode.CLEAR_ON_REMOVE) { - this.config.clear(); - this.saveChanges(); - } - } finally { - this.locked = false; - } - } - } - - private void configChanged() { - if (locked) { - return; - } - - this.locked = true; - try { - var c = this.getCellConfigInventory(); - if (c != null) { - copy(this.config, c); - // Copy items back. The cell may change the items on insert, for example if a fluid tank gets turned - // into a dummy fluid item. - copy(c, this.config); - } - } finally { - this.locked = false; - } - } - - public static void copy(GenericStackInv from, GenericStackInv to) { - for (int i = 0; i < Math.min(from.size(), to.size()); ++i) { - to.setStack(i, from.getStack(i)); - } - for (int i = from.size(); i < to.size(); i++) { - to.setStack(i, null); - } - } - - private ConfigInventory getCellConfigInventory() { - if (this.cacheConfig == null) { - var cell = this.getCell(); - if (cell == null) { - return null; - } - - var is = this.cell.getStackInSlot(0); - if (is.isEmpty()) { - return null; - } - - var inv = cell.getConfigInventory(is); - if (inv == null) { - return null; - } - - this.cacheConfig = inv; - } - return this.cacheConfig; - } - - @Override - public void addAdditionalDrops(Level level, BlockPos pos, List drops) { - super.addAdditionalDrops(level, pos, drops); - - if (!this.cell.getStackInSlot(0).isEmpty()) { - drops.add(this.cell.getStackInSlot(0)); - } - } - - @Override - public IConfigManager getConfigManager() { - return this.manager; - } - - @Override - public GenericStackInv getConfig() { - return config; - } - - @Override - public IUpgradeInventory getUpgrades() { - if (this.cacheUpgrades == null) { - final ICellWorkbenchItem cell = this.getCell(); - if (cell == null) { - return UpgradeInventories.empty(); - } - - final ItemStack is = this.cell.getStackInSlot(0); - if (is.isEmpty()) { - return UpgradeInventories.empty(); - } - - var inv = cell.getUpgrades(is); - if (inv == null) { - return UpgradeInventories.empty(); - } - - return this.cacheUpgrades = inv; - } - return this.cacheUpgrades; - } -} diff --git a/src/main/java/appeng/blockentity/misc/ChargerBlockEntity.java b/src/main/java/appeng/blockentity/misc/ChargerBlockEntity.java deleted file mode 100644 index 2d9b2be26b4..00000000000 --- a/src/main/java/appeng/blockentity/misc/ChargerBlockEntity.java +++ /dev/null @@ -1,297 +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.blockentity.misc; - -import java.util.ArrayList; -import java.util.EnumSet; -import java.util.List; -import java.util.Objects; - -import org.jetbrains.annotations.Nullable; - -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.block.entity.BlockEntityType; -import net.minecraft.world.level.block.state.BlockState; - -import appeng.api.config.Actionable; -import appeng.api.config.PowerMultiplier; -import appeng.api.config.PowerUnits; -import appeng.api.implementations.blockentities.ICrankable; -import appeng.api.implementations.items.IAEItemPowerStorage; -import appeng.api.inventories.InternalInventory; -import appeng.api.networking.IGridNode; -import appeng.api.networking.ticking.IGridTickable; -import appeng.api.networking.ticking.TickRateModulation; -import appeng.api.networking.ticking.TickingRequest; -import appeng.api.stacks.AEItemKey; -import appeng.api.util.AECableType; -import appeng.api.util.DimensionalBlockPos; -import appeng.blockentity.grid.AENetworkPowerBlockEntity; -import appeng.core.AEConfig; -import appeng.core.settings.TickRates; -import appeng.util.Platform; -import appeng.util.inv.AppEngInternalInventory; -import appeng.util.inv.filter.IAEItemFilter; - -public class ChargerBlockEntity extends AENetworkPowerBlockEntity implements IGridTickable { - public static final int POWER_MAXIMUM_AMOUNT = 1600; - private static final int POWER_THRESHOLD = POWER_MAXIMUM_AMOUNT - 1; - private boolean working; - - private final AppEngInternalInventory inv = new AppEngInternalInventory(this, 1, 1, new ChargerInvFilter(this)); - - public ChargerBlockEntity(BlockEntityType blockEntityType, BlockPos pos, BlockState blockState) { - super(blockEntityType, pos, blockState); - this.getMainNode() - .setExposedOnSides(EnumSet.noneOf(Direction.class)) - .setFlags() - .setIdlePowerUsage(0) - .addService(IGridTickable.class, this); - this.setInternalMaxPower(POWER_MAXIMUM_AMOUNT); - } - - @Override - public AECableType getCableConnectionType(Direction dir) { - return AECableType.COVERED; - } - - @Override - public void onReady() { - var validSides = EnumSet.allOf(Direction.class); - validSides.remove(this.getForward()); - - this.getMainNode().setExposedOnSides(validSides); - super.onReady(); - } - - @Override - protected boolean readFromStream(FriendlyByteBuf data) { - var changed = super.readFromStream(data); - - this.working = data.readBoolean(); - - if (data.readBoolean()) { - var item = AEItemKey.fromPacket(data); - this.inv.setItemDirect(0, item.toStack()); - } else { - this.inv.setItemDirect(0, ItemStack.EMPTY); - } - - return changed; // TESR doesn't need updates! - } - - @Override - protected void writeToStream(FriendlyByteBuf data) { - super.writeToStream(data); - data.writeBoolean(working); - var is = AEItemKey.of(this.inv.getStackInSlot(0)); - data.writeBoolean(is != null); - if (is != null) { - is.writeToPacket(data); - } - } - - @Override - public void setOrientation(Direction inForward, Direction inUp) { - super.setOrientation(inForward, inUp); - - var validSides = EnumSet.allOf(Direction.class); - validSides.remove(this.getForward()); - - this.getMainNode().setExposedOnSides(validSides); - this.setPowerSides(validSides); - } - - @Override - public InternalInventory getInternalInventory() { - return this.inv; - } - - @Override - public void onChangeInventory(InternalInventory inv, int slot) { - getMainNode().ifPresent((grid, node) -> { - grid.getTickManager().wakeDevice(node); - }); - - this.markForUpdate(); - } - - public void activate(Player player) { - if (!Platform.hasPermissions(new DimensionalBlockPos(this), player)) { - return; - } - - final ItemStack myItem = this.inv.getStackInSlot(0); - if (myItem.isEmpty()) { - ItemStack held = player.getInventory().getSelected(); - - if (ChargerRecipes.findRecipe(level, held) != null || Platform.isChargeable(held)) { - held = player.getInventory().removeItem(player.getInventory().selected, 1); - this.inv.setItemDirect(0, held); - } - } else { - final List drops = new ArrayList<>(); - drops.add(myItem); - this.inv.setItemDirect(0, ItemStack.EMPTY); - Platform.spawnDrops(player.level, this.worldPosition.relative(this.getForward()), drops); - } - } - - @Override - public TickingRequest getTickingRequest(IGridNode node) { - return new TickingRequest(TickRates.Charger, false, true); - } - - @Override - public TickRateModulation tickingRequest(IGridNode node, int ticksSinceLastCall) { - doWork(ticksSinceLastCall); - return TickRateModulation.FASTER; - } - - private void doWork(int ticksSinceLastCall) { - var wasWorking = this.working; - this.working = false; - var changed = false; - - var myItem = this.inv.getStackInSlot(0); - - if (!myItem.isEmpty()) { - - if (Platform.isChargeable(myItem)) { - var ps = (IAEItemPowerStorage) myItem.getItem(); - - var currentPower = ps.getAECurrentPower(myItem); - var maxPower = ps.getAEMaxPower(myItem); - if (currentPower < maxPower) { - // Since we specify the charge rate in "per tick", calculate it per tick of the charger, - // which only ticks once every few actual game ticks. - var chargeRate = ps.getChargeRate(myItem) * ticksSinceLastCall - * AEConfig.instance().getChargerChargeRate(); - - // First charge from the local buffer - double extractedAmount = this.extractAEPower(chargeRate, Actionable.MODULATE, - PowerMultiplier.CONFIG); - - var missingChargeRate = chargeRate - extractedAmount; - var missingAEPower = maxPower - currentPower; - var toExtract = Math.min(missingChargeRate, missingAEPower); - - // Then directly extract from the grid - var grid = getMainNode().getGrid(); - if (grid != null) { - extractedAmount += grid.getEnergyService().extractAEPower(toExtract, Actionable.MODULATE, - PowerMultiplier.ONE); - } - - if (extractedAmount > 0) { - var adjustment = ps.injectAEPower(myItem, extractedAmount, Actionable.MODULATE); - - this.setInternalCurrentPower(this.getInternalCurrentPower() + adjustment); - - this.working = true; - changed = true; - } - } - } else if (this.getInternalCurrentPower() > POWER_THRESHOLD - && ChargerRecipes.findRecipe(level, myItem) != null) { - this.working = true; - if (Platform.getRandomFloat() > 0.8f) { - this.extractAEPower(this.getInternalMaxPower(), Actionable.MODULATE, PowerMultiplier.CONFIG); - - Item charged = Objects.requireNonNull(ChargerRecipes.findRecipe(level, myItem)).result; - this.inv.setItemDirect(0, new ItemStack(charged)); - - changed = true; - } - } - } - - // charge from the network! - if (this.getInternalCurrentPower() < POWER_THRESHOLD) { - getMainNode().ifPresent(grid -> { - double toExtract = Math.min(800.0, this.getInternalMaxPower() - this.getInternalCurrentPower()); - final double extracted = grid.getEnergyService().extractAEPower(toExtract, Actionable.MODULATE, - PowerMultiplier.ONE); - - this.injectExternalPower(PowerUnits.AE, extracted, Actionable.MODULATE); - }); - - changed = true; - } - - if (changed || this.working != wasWorking) { - this.markForUpdate(); - } - } - - public boolean isWorking() { - return working; - } - - /** - * Allow cranking from the top or bottom. - */ - @Nullable - public ICrankable getCrankable(Direction direction) { - var up = getUp(); - if (direction == up || direction == up.getOpposite()) { - return new Crankable(); - } - return null; - } - - private record ChargerInvFilter(ChargerBlockEntity chargerBlockEntity) implements IAEItemFilter { - - @Override - public boolean allowInsert(InternalInventory inv, int i, ItemStack itemstack) { - return Platform.isChargeable(itemstack) || ChargerRecipes.allowInsert(chargerBlockEntity.level, itemstack); - } - - @Override - public boolean allowExtract(InternalInventory inv, int slotIndex, int amount) { - ItemStack extractedItem = inv.getStackInSlot(slotIndex); - - if (Platform.isChargeable(extractedItem)) { - final IAEItemPowerStorage ips = (IAEItemPowerStorage) extractedItem.getItem(); - if (ips.getAECurrentPower(extractedItem) >= ips.getAEMaxPower(extractedItem)) { - return true; - } - } - - return ChargerRecipes.allowExtract(chargerBlockEntity.level, extractedItem); - } - } - - class Crankable implements ICrankable { - @Override - public boolean canTurn() { - return getInternalCurrentPower() < getInternalMaxPower(); - } - - @Override - public void applyTurn() { - injectExternalPower(PowerUnits.AE, CrankBlockEntity.POWER_PER_CRANK_TURN, Actionable.MODULATE); - } - } -} diff --git a/src/main/java/appeng/blockentity/misc/ChargerRecipes.java b/src/main/java/appeng/blockentity/misc/ChargerRecipes.java deleted file mode 100644 index 4d7c2295ac2..00000000000 --- a/src/main/java/appeng/blockentity/misc/ChargerRecipes.java +++ /dev/null @@ -1,35 +0,0 @@ -package appeng.blockentity.misc; - -import javax.annotation.Nullable; - -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.Level; - -import appeng.recipes.handlers.ChargerRecipe; - -public class ChargerRecipes { - - public static Iterable getRecipes(Level level) { - return level.getRecipeManager().byType(ChargerRecipe.TYPE).values(); - } - - @Nullable - public static ChargerRecipe findRecipe(Level level, ItemStack input) { - for (ChargerRecipe recipe : getRecipes(level)) { - if (recipe.ingredient.test(input)) { - return recipe; - } - } - - return null; - } - - public static boolean allowInsert(Level level, ItemStack stack) { - return findRecipe(level, stack) != null; - } - - public static boolean allowExtract(Level level, ItemStack stack) { - return findRecipe(level, stack) == null; - } - -} diff --git a/src/main/java/appeng/blockentity/misc/CondenserBlockEntity.java b/src/main/java/appeng/blockentity/misc/CondenserBlockEntity.java deleted file mode 100644 index a91907aebf9..00000000000 --- a/src/main/java/appeng/blockentity/misc/CondenserBlockEntity.java +++ /dev/null @@ -1,280 +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.blockentity.misc; - -import java.util.Collections; -import java.util.Iterator; - -import javax.annotation.Nullable; - -import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant; -import net.fabricmc.fabric.api.transfer.v1.storage.Storage; -import net.fabricmc.fabric.api.transfer.v1.storage.StorageView; -import net.fabricmc.fabric.api.transfer.v1.storage.base.InsertionOnlyStorage; -import net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext; -import net.fabricmc.fabric.api.transfer.v1.transaction.base.SnapshotParticipant; -import net.minecraft.core.BlockPos; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.block.entity.BlockEntityType; -import net.minecraft.world.level.block.state.BlockState; - -import appeng.api.config.CondenserOutput; -import appeng.api.config.Settings; -import appeng.api.implementations.items.IStorageComponent; -import appeng.api.inventories.BaseInternalInventory; -import appeng.api.inventories.InternalInventory; -import appeng.api.networking.security.IActionSource; -import appeng.api.stacks.AEFluidKey; -import appeng.api.stacks.AEKeyType; -import appeng.api.storage.IStorageMonitorableAccessor; -import appeng.api.storage.MEStorage; -import appeng.api.util.IConfigManager; -import appeng.api.util.IConfigurableObject; -import appeng.blockentity.AEBaseInvBlockEntity; -import appeng.core.definitions.AEItems; -import appeng.util.ConfigManager; -import appeng.util.inv.AppEngInternalInventory; -import appeng.util.inv.CombinedInternalInventory; -import appeng.util.inv.FilteredInternalInventory; -import appeng.util.inv.filter.AEItemFilters; - -public class CondenserBlockEntity extends AEBaseInvBlockEntity implements IConfigurableObject { - - public static final int BYTE_MULTIPLIER = 8; - - private final ConfigManager cm = new ConfigManager(() -> { - saveChanges(); - addPower(0); - }); - - private final AppEngInternalInventory outputSlot = new AppEngInternalInventory(this, 1); - private final AppEngInternalInventory storageSlot = new AppEngInternalInventory(this, 1); - private final InternalInventory inputSlot = new CondenseItemHandler(); - private final Storage fluidHandler = new FluidHandler(); - private final MEHandler meHandler = new MEHandler(); - - private final InternalInventory externalInv = new CombinedInternalInventory(this.inputSlot, - new FilteredInternalInventory(this.outputSlot, AEItemFilters.EXTRACT_ONLY)); - private final InternalInventory combinedInv = new CombinedInternalInventory(this.inputSlot, this.outputSlot, - this.storageSlot); - - private double storedPower = 0; - - public CondenserBlockEntity(BlockEntityType blockEntityType, BlockPos pos, BlockState blockState) { - super(blockEntityType, pos, blockState); - this.cm.registerSetting(Settings.CONDENSER_OUTPUT, CondenserOutput.TRASH); - } - - @Override - public void saveAdditional(CompoundTag data) { - super.saveAdditional(data); - this.cm.writeToNBT(data); - data.putDouble("storedPower", this.getStoredPower()); - } - - @Override - public void loadTag(CompoundTag data) { - super.loadTag(data); - this.cm.readFromNBT(data); - this.setStoredPower(data.getDouble("storedPower")); - } - - public double getStorage() { - final ItemStack is = this.storageSlot.getStackInSlot(0); - if (!is.isEmpty() && is.getItem() instanceof IStorageComponent sc) { - if (sc.isStorageComponent(is)) { - return sc.getBytes(is) * BYTE_MULTIPLIER; - } - } - return 0; - } - - public void addPower(double rawPower) { - this.setStoredPower(this.getStoredPower() + rawPower); - this.setStoredPower(Math.max(0.0, Math.min(this.getStorage(), this.getStoredPower()))); - fillOutput(); - } - - private void fillOutput() { - var requiredPower = this.getRequiredPower(); - var output = this.getOutput(); - while (requiredPower <= this.getStoredPower() && !output.isEmpty() && requiredPower > 0) { - if (this.canAddOutput(output)) { - this.setStoredPower(this.getStoredPower() - requiredPower); - this.addOutput(output); - } else { - break; - } - } - } - - private boolean canAddOutput(ItemStack output) { - return this.outputSlot.insertItem(0, output, true).isEmpty(); - } - - /** - * make sure you validate with canAddOutput prior to this. - * - * @param output to be added output - */ - private void addOutput(ItemStack output) { - this.outputSlot.insertItem(0, output, false); - } - - InternalInventory getOutputSlot() { - return this.outputSlot; - } - - private ItemStack getOutput() { - - return switch (this.cm.getSetting(Settings.CONDENSER_OUTPUT)) { - case MATTER_BALLS -> AEItems.MATTER_BALL.stack(); - case SINGULARITY -> AEItems.SINGULARITY.stack(); - default -> ItemStack.EMPTY; - }; - } - - public double getRequiredPower() { - return this.cm.getSetting(Settings.CONDENSER_OUTPUT).requiredPower; - } - - @Override - public InternalInventory getInternalInventory() { - return this.combinedInv; - } - - @Override - public void onChangeInventory(InternalInventory inv, int slot) { - if (inv == outputSlot) - fillOutput(); - } - - @Override - public IConfigManager getConfigManager() { - return this.cm; - } - - public double getStoredPower() { - return this.storedPower; - } - - private void setStoredPower(double storedPower) { - this.storedPower = storedPower; - } - - public InternalInventory getExternalInv() { - return externalInv; - } - - public Storage getFluidHandler() { - return fluidHandler; - } - - public MEHandler getMEHandler() { - return meHandler; - } - - private class CondenseItemHandler extends BaseInternalInventory { - @Override - public int size() { - // We only expose the void slot - return 1; - } - - @Override - public ItemStack getStackInSlot(int slot) { - // The void slot never has any content - return ItemStack.EMPTY; - } - - @Override - public void setItemDirect(int slotIndex, ItemStack stack) { - if (!stack.isEmpty()) { - CondenserBlockEntity.this.addPower(stack.getCount()); - } - } - - @Override - public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) { - if (!simulate && !stack.isEmpty()) { - CondenserBlockEntity.this.addPower(stack.getCount()); - } - return ItemStack.EMPTY; - } - - @Override - public ItemStack extractItem(int slot, int amount, boolean simulate) { - return ItemStack.EMPTY; - } - } - - /** - * A fluid handler that exposes a 1 bucket tank that can only be filled, and - when filled - will add power to this - * condenser. - */ - private class FluidHandler extends SnapshotParticipant implements InsertionOnlyStorage { - private double pendingEnergy = 0; - - @Override - public long insert(FluidVariant resource, long maxAmount, TransactionContext transaction) { - // We allow up to a bucket per insert - var amount = Math.min(AEFluidKey.AMOUNT_BUCKET, maxAmount); - updateSnapshots(transaction); - pendingEnergy += amount / AEKeyType.fluids().getAmountPerOperation(); - return amount; - } - - @Override - public Iterator> iterator() { - return Collections.emptyIterator(); - } - - @Override - protected Double createSnapshot() { - return pendingEnergy; - } - - @Override - protected void readSnapshot(Double snapshot) { - pendingEnergy = snapshot; - } - - @Override - protected void onFinalCommit() { - CondenserBlockEntity.this.addPower(pendingEnergy); - pendingEnergy = 0; - } - } - - /** - * This is used to expose a fake ME subnetwork that is only composed of this condenser. The purpose of this is to - * enable the condenser to override the {@link appeng.api.storage.MEStorage#isPreferredStorageFor} method to make - * sure a condenser is only ever used if an item can't go anywhere else. - */ - private class MEHandler implements IStorageMonitorableAccessor { - private final CondenserInventory itemInventory = new CondenserInventory(CondenserBlockEntity.this); - - @Nullable - @Override - public MEStorage getInventory(IActionSource src) { - return this.itemInventory; - } - } -} diff --git a/src/main/java/appeng/blockentity/misc/CondenserInventory.java b/src/main/java/appeng/blockentity/misc/CondenserInventory.java deleted file mode 100644 index d9fbe247ae2..00000000000 --- a/src/main/java/appeng/blockentity/misc/CondenserInventory.java +++ /dev/null @@ -1,72 +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.blockentity.misc; - -import net.minecraft.network.chat.Component; - -import appeng.api.config.Actionable; -import appeng.api.networking.security.IActionSource; -import appeng.api.stacks.AEItemKey; -import appeng.api.stacks.AEKey; -import appeng.api.stacks.KeyCounter; -import appeng.api.storage.MEStorage; - -class CondenserInventory implements MEStorage { - private final CondenserBlockEntity target; - - CondenserInventory(CondenserBlockEntity te) { - this.target = te; - } - - @Override - public long insert(AEKey what, long amount, Actionable mode, IActionSource source) { - MEStorage.checkPreconditions(what, amount, mode, source); - if (mode == Actionable.MODULATE) { - this.target.addPower(amount / what.getAmountPerOperation()); - } - return amount; - } - - @Override - public long extract(AEKey what, long amount, Actionable mode, IActionSource source) { - MEStorage.checkPreconditions(what, amount, mode, source); - var slotItem = this.target.getOutputSlot().getStackInSlot(0); - - if (what instanceof AEItemKey itemKey && itemKey.matches(slotItem)) { - int count = (int) Math.min(amount, Integer.MAX_VALUE); - return this.target.getOutputSlot().extractItem(0, count, mode == Actionable.SIMULATE) - .getCount(); - } - - return 0; - } - - @Override - public void getAvailableStacks(KeyCounter out) { - var stack = this.target.getOutputSlot().getStackInSlot(0); - if (!stack.isEmpty()) { - out.add(AEItemKey.of(stack), stack.getCount()); - } - } - - @Override - public Component getDescription() { - return target.getBlockState().getBlock().getName(); - } -} diff --git a/src/main/java/appeng/blockentity/misc/CrankBlockEntity.java b/src/main/java/appeng/blockentity/misc/CrankBlockEntity.java deleted file mode 100644 index 7ba8d47d5e4..00000000000 --- a/src/main/java/appeng/blockentity/misc/CrankBlockEntity.java +++ /dev/null @@ -1,143 +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.blockentity.misc; - -import org.jetbrains.annotations.Nullable; - -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.world.level.block.entity.BlockEntityType; -import net.minecraft.world.level.block.state.BlockState; - -import appeng.api.implementations.blockentities.ICrankable; -import appeng.blockentity.AEBaseBlockEntity; -import appeng.blockentity.ClientTickingBlockEntity; -import appeng.blockentity.ServerTickingBlockEntity; - -public class CrankBlockEntity extends AEBaseBlockEntity implements ServerTickingBlockEntity, ClientTickingBlockEntity { - - public static final int POWER_PER_CRANK_TURN = 160; - private final int ticksPerRotation = 18; - - // sided values.. - private float visibleRotation = 0; // This is in degrees - private int charge = 0; - - private int hits = 0; - private int rotation = 0; - - public CrankBlockEntity(BlockEntityType blockEntityType, BlockPos pos, BlockState blockState) { - super(blockEntityType, pos, blockState); - } - - @Nullable - private ICrankable getCrankable() { - if (isClientSide()) { - return null; - } - - var targetDir = this.getUp().getOpposite(); - var targetPos = getBlockPos().relative(targetDir); - return ICrankable.get(level, targetPos, targetDir.getOpposite()); - } - - @Override - protected boolean readFromStream(FriendlyByteBuf data) { - final boolean c = super.readFromStream(data); - this.rotation = data.readInt(); - return c; - } - - @Override - protected void writeToStream(FriendlyByteBuf data) { - super.writeToStream(data); - data.writeInt(this.rotation); - } - - @Override - public void setOrientation(Direction inForward, Direction inUp) { - super.setOrientation(inForward, inUp); - var pos = getBlockPos(); - var state = level.getBlockState(pos); - level.neighborChanged(state, pos, state.getBlock(), pos, false); - } - - /** - * return true if this should count towards stats. - */ - public boolean power() { - if (isClientSide()) { - return false; - } - - if (this.rotation < 3) { - var crankable = this.getCrankable(); - if (crankable != null) { - if (crankable.canTurn()) { - this.hits = 0; - this.rotation += this.ticksPerRotation; - this.markForUpdate(); - return true; - } else { - this.hits++; - if (this.hits > 10) { - level.destroyBlock(this.getBlockPos(), false); - } - } - } - } - - return false; - } - - public float getVisibleRotation() { - return this.visibleRotation; - } - - private void setVisibleRotation(float visibleRotation) { - this.visibleRotation = visibleRotation; - } - - @Override - public void clientTick() { - tick(); - } - - @Override - public void serverTick() { - tick(); - } - - private void tick() { - if (this.rotation > 0) { - this.setVisibleRotation(this.getVisibleRotation() - 360.0f / this.ticksPerRotation); - this.charge++; - if (this.charge >= this.ticksPerRotation) { - this.charge -= this.ticksPerRotation; - var g = this.getCrankable(); - if (g != null) { - g.applyTurn(); - } - } - - this.rotation--; - } - } -} diff --git a/src/main/java/appeng/blockentity/misc/InscriberBlockEntity.java b/src/main/java/appeng/blockentity/misc/InscriberBlockEntity.java deleted file mode 100644 index c9f73eb5238..00000000000 --- a/src/main/java/appeng/blockentity/misc/InscriberBlockEntity.java +++ /dev/null @@ -1,435 +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.blockentity.misc; - -import java.util.EnumSet; -import java.util.List; - -import javax.annotation.Nullable; - -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.entity.BlockEntityType; -import net.minecraft.world.level.block.state.BlockState; - -import appeng.api.config.Actionable; -import appeng.api.config.PowerMultiplier; -import appeng.api.config.PowerUnits; -import appeng.api.implementations.blockentities.ICrankable; -import appeng.api.inventories.ISegmentedInventory; -import appeng.api.inventories.InternalInventory; -import appeng.api.networking.IGridNode; -import appeng.api.networking.energy.IEnergyService; -import appeng.api.networking.energy.IEnergySource; -import appeng.api.networking.ticking.IGridTickable; -import appeng.api.networking.ticking.TickRateModulation; -import appeng.api.networking.ticking.TickingRequest; -import appeng.api.upgrades.IUpgradeInventory; -import appeng.api.upgrades.IUpgradeableObject; -import appeng.api.upgrades.UpgradeInventories; -import appeng.api.util.AECableType; -import appeng.blockentity.grid.AENetworkPowerBlockEntity; -import appeng.core.definitions.AEBlocks; -import appeng.core.definitions.AEItems; -import appeng.core.settings.TickRates; -import appeng.recipes.handlers.InscriberProcessType; -import appeng.recipes.handlers.InscriberRecipe; -import appeng.util.inv.AppEngInternalInventory; -import appeng.util.inv.CombinedInternalInventory; -import appeng.util.inv.FilteredInternalInventory; -import appeng.util.inv.filter.IAEItemFilter; - -/** - * @author AlgorithmX2 - * @author thatsIch - * @version rv2 - * @since rv0 - */ -public class InscriberBlockEntity extends AENetworkPowerBlockEntity implements IGridTickable, IUpgradeableObject { - private final int maxProcessingTime = 100; - - private final IUpgradeInventory upgrades; - private int processingTime = 0; - // cycles from 0 - 16, at 8 it preforms the action, at 16 it re-enables the - // normal routine. - private boolean smash; - private int finalStep; - private long clientStart; - private final AppEngInternalInventory topItemHandler = new AppEngInternalInventory(this, 1, 1); - private final AppEngInternalInventory bottomItemHandler = new AppEngInternalInventory(this, 1, 1); - private final AppEngInternalInventory sideItemHandler = new AppEngInternalInventory(this, 2, 1); - - // The externally visible inventories (with filters applied) - private final InternalInventory topItemHandlerExtern; - private final InternalInventory bottomItemHandlerExtern; - private final InternalInventory sideItemHandlerExtern; - - private InscriberRecipe cachedTask = null; - - private final InternalInventory inv = new CombinedInternalInventory(this.topItemHandler, - this.bottomItemHandler, this.sideItemHandler); - - public InscriberBlockEntity(BlockEntityType blockEntityType, BlockPos pos, BlockState blockState) { - super(blockEntityType, pos, blockState); - - this.getMainNode() - .setExposedOnSides(EnumSet.noneOf(Direction.class)) - .setIdlePowerUsage(0) - .addService(IGridTickable.class, this); - this.setInternalMaxPower(1600); - - this.upgrades = UpgradeInventories.forMachine(AEBlocks.INSCRIBER, 3, this::saveChanges); - - this.sideItemHandler.setMaxStackSize(1, 64); - - var filter = new ItemHandlerFilter(); - this.topItemHandlerExtern = new FilteredInternalInventory(this.topItemHandler, filter); - this.bottomItemHandlerExtern = new FilteredInternalInventory(this.bottomItemHandler, filter); - this.sideItemHandlerExtern = new FilteredInternalInventory(this.sideItemHandler, filter); - } - - @Override - public AECableType getCableConnectionType(Direction dir) { - return AECableType.COVERED; - } - - @Override - public void saveAdditional(CompoundTag data) { - super.saveAdditional(data); - this.upgrades.writeToNBT(data, "upgrades"); - } - - @Override - public void loadTag(CompoundTag data) { - super.loadTag(data); - this.upgrades.readFromNBT(data, "upgrades"); - } - - @Override - protected boolean readFromStream(FriendlyByteBuf data) { - var c = super.readFromStream(data); - - var oldSmash = isSmash(); - var newSmash = data.readBoolean(); - - if (oldSmash != newSmash && newSmash) { - setSmash(true); - } - - for (int i = 0; i < this.inv.size(); i++) { - this.inv.setItemDirect(i, data.readItem()); - } - this.cachedTask = null; - - return c; - } - - @Override - protected void writeToStream(FriendlyByteBuf data) { - super.writeToStream(data); - - data.writeBoolean(isSmash()); - for (int i = 0; i < this.inv.size(); i++) { - data.writeItem(inv.getStackInSlot(i)); - } - } - - @Override - protected void saveVisualState(CompoundTag data) { - super.saveVisualState(data); - - data.putBoolean("smash", isSmash()); - } - - @Override - protected void loadVisualState(CompoundTag data) { - super.loadVisualState(data); - - setSmash(data.getBoolean("smash")); - } - - @Override - public void onReady() { - this.getMainNode().setExposedOnSides(EnumSet.complementOf(EnumSet.of(this.getForward()))); - super.onReady(); - } - - @Override - public void setOrientation(Direction inForward, Direction inUp) { - super.setOrientation(inForward, inUp); - this.getMainNode().setExposedOnSides(EnumSet.complementOf(EnumSet.of(this.getForward()))); - this.setPowerSides(EnumSet.complementOf(EnumSet.of(this.getForward()))); - } - - @Override - public void addAdditionalDrops(Level level, BlockPos pos, List drops) { - super.addAdditionalDrops(level, pos, drops); - - for (var upgrade : upgrades) { - drops.add(upgrade); - } - } - - @Override - public InternalInventory getInternalInventory() { - return this.inv; - } - - @Override - public void onChangeInventory(InternalInventory inv, int slot) { - if (slot == 0) { - this.setProcessingTime(0); - } - - if (!this.isSmash()) { - this.markForUpdate(); - } - - this.cachedTask = null; - getMainNode().ifPresent((grid, node) -> grid.getTickManager().wakeDevice(node)); - } - - // - // @Override - @Override - public TickingRequest getTickingRequest(IGridNode node) { - return new TickingRequest(TickRates.Inscriber, !this.hasWork(), false); - } - - private boolean hasWork() { - if (this.getTask() != null) { - return true; - } - - this.setProcessingTime(0); - return this.isSmash(); - } - - @Nullable - public InscriberRecipe getTask() { - if (this.cachedTask == null && level != null) { - ItemStack input = this.sideItemHandler.getStackInSlot(0); - ItemStack plateA = this.topItemHandler.getStackInSlot(0); - ItemStack plateB = this.bottomItemHandler.getStackInSlot(0); - if (input.isEmpty()) { - return null; // No input to handle - } - - // If the player somehow managed to insert more than one item, we bail here - if (input.getCount() > 1 || plateA.getCount() > 1 || plateB.getCount() > 1) { - return null; - } - - this.cachedTask = InscriberRecipes.findRecipe(level, input, plateA, plateB, true); - } - return this.cachedTask; - } - - @Override - public TickRateModulation tickingRequest(IGridNode node, int ticksSinceLastCall) { - if (this.isSmash()) { - this.finalStep++; - if (this.finalStep == 8) { - final InscriberRecipe out = this.getTask(); - if (out != null) { - final ItemStack outputCopy = out.getResultItem().copy(); - - if (this.sideItemHandler.insertItem(1, outputCopy, false).isEmpty()) { - this.setProcessingTime(0); - if (out.getProcessType() == InscriberProcessType.PRESS) { - this.topItemHandler.setItemDirect(0, ItemStack.EMPTY); - this.bottomItemHandler.setItemDirect(0, ItemStack.EMPTY); - } - this.sideItemHandler.setItemDirect(0, ItemStack.EMPTY); - } - } - this.saveChanges(); - } else if (this.finalStep == 16) { - this.finalStep = 0; - this.setSmash(false); - this.markForUpdate(); - } - } else { - getMainNode().ifPresent(grid -> { - IEnergyService eg = grid.getEnergyService(); - IEnergySource src = this; - - // Base 1, increase by 1 for each card - final int speedFactor = 1 + this.upgrades.getInstalledUpgrades(AEItems.SPEED_CARD); - final int powerConsumption = 10 * speedFactor; - final double powerThreshold = powerConsumption - 0.01; - double powerReq = this.extractAEPower(powerConsumption, Actionable.SIMULATE, PowerMultiplier.CONFIG); - - if (powerReq <= powerThreshold) { - src = eg; - powerReq = eg.extractAEPower(powerConsumption, Actionable.SIMULATE, PowerMultiplier.CONFIG); - } - - if (powerReq > powerThreshold) { - src.extractAEPower(powerConsumption, Actionable.MODULATE, PowerMultiplier.CONFIG); - - if (this.getProcessingTime() == 0) { - this.setProcessingTime(this.getProcessingTime() + speedFactor); - } else { - this.setProcessingTime(this.getProcessingTime() + ticksSinceLastCall * speedFactor); - } - } - }); - - if (this.getProcessingTime() > this.getMaxProcessingTime()) { - this.setProcessingTime(this.getMaxProcessingTime()); - final InscriberRecipe out = this.getTask(); - if (out != null) { - final ItemStack outputCopy = out.getResultItem().copy(); - if (this.sideItemHandler.insertItem(1, outputCopy, true).isEmpty()) { - this.setSmash(true); - this.finalStep = 0; - this.markForUpdate(); - } - } - } - } - - return this.hasWork() ? TickRateModulation.URGENT : TickRateModulation.SLEEP; - } - - @Nullable - @Override - public InternalInventory getSubInventory(ResourceLocation id) { - if (id.equals(ISegmentedInventory.STORAGE)) { - return this.getInternalInventory(); - } else if (id.equals(ISegmentedInventory.UPGRADES)) { - return this.upgrades; - } - - return super.getSubInventory(id); - } - - @Override - public InternalInventory getExposedInventoryForSide(Direction facing) { - if (facing == this.getUp()) { - return this.topItemHandlerExtern; - } else if (facing == this.getUp().getOpposite()) { - return this.bottomItemHandlerExtern; - } else { - return this.sideItemHandlerExtern; - } - } - - @Override - public IUpgradeInventory getUpgrades() { - return upgrades; - } - - public long getClientStart() { - return this.clientStart; - } - - private void setClientStart(long clientStart) { - this.clientStart = clientStart; - } - - public boolean isSmash() { - return this.smash; - } - - public void setSmash(boolean smash) { - if (smash && !this.smash) { - setClientStart(System.currentTimeMillis()); - } - this.smash = smash; - } - - public int getMaxProcessingTime() { - return this.maxProcessingTime; - } - - public int getProcessingTime() { - return this.processingTime; - } - - private void setProcessingTime(int processingTime) { - this.processingTime = processingTime; - } - - /** - * Allow cranking from any side other than the front. - */ - @org.jetbrains.annotations.Nullable - public ICrankable getCrankable(Direction direction) { - if (direction != getForward()) { - return new Crankable(); - } - return null; - } - - /** - * This is an item handler that exposes the inscribers inventory while providing simulation capabilities that do not - * reset the progress if there's already an item in a slot. Previously, the progress of the inscriber was reset when - * another mod attempted insertion of items when there were already items in the slot. - */ - private class ItemHandlerFilter implements IAEItemFilter { - @Override - public boolean allowExtract(InternalInventory inv, int slot, int amount) { - if (InscriberBlockEntity.this.isSmash()) { - return false; - } - - return inv == InscriberBlockEntity.this.topItemHandler || inv == InscriberBlockEntity.this.bottomItemHandler - || slot == 1; - } - - @Override - public boolean allowInsert(InternalInventory inv, int slot, ItemStack stack) { - // output slot - if (slot == 1) { - return false; - } - - if (InscriberBlockEntity.this.isSmash()) { - return false; - } - - if (inv == InscriberBlockEntity.this.topItemHandler || inv == InscriberBlockEntity.this.bottomItemHandler) { - if (AEItems.NAME_PRESS.isSameAs(stack)) { - return true; - } - return InscriberRecipes.isValidOptionalIngredient(getLevel(), stack); - } - return true; - } - } - - class Crankable implements ICrankable { - @Override - public boolean canTurn() { - return getInternalCurrentPower() < getInternalMaxPower(); - } - - @Override - public void applyTurn() { - injectExternalPower(PowerUnits.AE, CrankBlockEntity.POWER_PER_CRANK_TURN, Actionable.MODULATE); - } - } -} diff --git a/src/main/java/appeng/blockentity/misc/InscriberRecipes.java b/src/main/java/appeng/blockentity/misc/InscriberRecipes.java deleted file mode 100644 index fd058b27058..00000000000 --- a/src/main/java/appeng/blockentity/misc/InscriberRecipes.java +++ /dev/null @@ -1,139 +0,0 @@ -/* - * This file is part of Applied Energistics 2. - * Copyright (c) 2021, 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.blockentity.misc; - -import javax.annotation.Nullable; - -import net.minecraft.nbt.CompoundTag; -import net.minecraft.network.chat.Component; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.crafting.Ingredient; -import net.minecraft.world.level.Level; - -import appeng.core.AppEng; -import appeng.core.definitions.AEItems; -import appeng.items.materials.NamePressItem; -import appeng.recipes.handlers.InscriberProcessType; -import appeng.recipes.handlers.InscriberRecipe; - -/** - * This class indexes all inscriber recipes to find valid inputs for the top and bottom optional slots. This speeds up - * checks whether inputs for those two slots are valid. - */ -public final class InscriberRecipes { - - public static final ResourceLocation NAMEPLATE_RECIPE_ID = new ResourceLocation(AppEng.MOD_ID, "nameplate"); - - private InscriberRecipes() { - } - - /** - * Returns an unmodifiable view of all registered inscriber recipes. - */ - public static Iterable getRecipes(Level level) { - return level.getRecipeManager().byType(InscriberRecipe.TYPE).values(); - } - - @Nullable - public static InscriberRecipe findRecipe(Level level, ItemStack input, ItemStack plateA, ItemStack plateB, - boolean supportNamePress) { - if (supportNamePress) { - boolean isNameA = AEItems.NAME_PRESS.isSameAs(plateA); - boolean isNameB = AEItems.NAME_PRESS.isSameAs(plateB); - - if (isNameA && isNameB || isNameA && plateB.isEmpty()) { - return makeNamePressRecipe(input, plateA, plateB); - } else if (plateA.isEmpty() && isNameB) { - return makeNamePressRecipe(input, plateB, plateA); - } - } - - for (InscriberRecipe recipe : getRecipes(level)) { - // The recipe can be flipped at will - final boolean matchA = recipe.getTopOptional().test(plateA) && recipe.getBottomOptional().test(plateB); - final boolean matchB = recipe.getTopOptional().test(plateB) && recipe.getBottomOptional().test(plateA); - - if ((matchA || matchB) && recipe.getMiddleInput().test(input)) { - return recipe; - } - } - - return null; - } - - private static InscriberRecipe makeNamePressRecipe(ItemStack input, ItemStack plateA, ItemStack plateB) { - String name = ""; - - if (!plateA.isEmpty()) { - final CompoundTag tag = plateA.getOrCreateTag(); - name += tag.getString(NamePressItem.TAG_INSCRIBE_NAME); - } - - if (!plateB.isEmpty()) { - final CompoundTag tag = plateB.getOrCreateTag(); - name += " " + tag.getString(NamePressItem.TAG_INSCRIBE_NAME); - } - - final Ingredient startingItem = Ingredient.of(input.copy()); - final ItemStack renamedItem = input.copy(); - - if (!name.isEmpty()) { - renamedItem.setHoverName(Component.literal(name)); - } else { - renamedItem.setHoverName(null); - } - - final InscriberProcessType type = InscriberProcessType.INSCRIBE; - - return new InscriberRecipe(NAMEPLATE_RECIPE_ID, startingItem, renamedItem, - plateA.isEmpty() ? Ingredient.EMPTY : Ingredient.of(plateA), - plateB.isEmpty() ? Ingredient.EMPTY : Ingredient.of(plateB), type); - } - - /** - * Checks if there is an inscriber recipe that supports the given combination of top/bottom presses. Both the given - * combination and the reverse will be searched. - */ - public static boolean isValidOptionalIngredientCombination(Level level, ItemStack pressA, ItemStack pressB) { - for (InscriberRecipe recipe : getRecipes(level)) { - if (recipe.getTopOptional().test(pressA) && recipe.getBottomOptional().test(pressB) - || recipe.getTopOptional().test(pressB) && recipe.getBottomOptional().test(pressA)) { - return true; - } - } - - return false; - } - - /** - * Checks if there is an inscriber recipe that would use the given item stack as an optional ingredient. Bottom and - * top can be used interchangeably here, because the inscriber will flip the recipe if needed. - */ - public static boolean isValidOptionalIngredient(Level level, ItemStack is) { - for (InscriberRecipe recipe : getRecipes(level)) { - if (recipe.getTopOptional().test(is) || recipe.getBottomOptional().test(is)) { - return true; - } - } - - return false; - } - -} diff --git a/src/main/java/appeng/blockentity/misc/InterfaceBlockEntity.java b/src/main/java/appeng/blockentity/misc/InterfaceBlockEntity.java deleted file mode 100644 index 6b8be5bba1e..00000000000 --- a/src/main/java/appeng/blockentity/misc/InterfaceBlockEntity.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * This file is part of Applied Energistics 2. - * Copyright (c) 2013 - 2015, 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.blockentity.misc; - -import java.util.List; - -import org.jetbrains.annotations.Nullable; - -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraft.world.level.block.entity.BlockEntityType; -import net.minecraft.world.level.block.state.BlockState; - -import appeng.api.inventories.InternalInventory; -import appeng.api.networking.GridHelper; -import appeng.api.networking.IGridNode; -import appeng.api.networking.IGridNodeListener; -import appeng.api.networking.IManagedGridNode; -import appeng.api.upgrades.IUpgradeableObject; -import appeng.api.util.AECableType; -import appeng.api.util.IConfigurableObject; -import appeng.blockentity.grid.AENetworkBlockEntity; -import appeng.core.definitions.AEBlocks; -import appeng.helpers.IPriorityHost; -import appeng.helpers.InterfaceLogic; -import appeng.helpers.InterfaceLogicHost; -import appeng.me.helpers.BlockEntityNodeListener; - -public class InterfaceBlockEntity extends AENetworkBlockEntity - implements IPriorityHost, IUpgradeableObject, IConfigurableObject, InterfaceLogicHost { - - private static final IGridNodeListener NODE_LISTENER = new BlockEntityNodeListener<>() { - @Override - public void onGridChanged(InterfaceBlockEntity nodeOwner, IGridNode node) { - nodeOwner.logic.gridChanged(); - } - }; - - private final InterfaceLogic logic = new InterfaceLogic(this.getMainNode(), this, - getItemFromBlockEntity().asItem()); - - public InterfaceBlockEntity(BlockEntityType blockEntityType, BlockPos pos, BlockState blockState) { - super(blockEntityType, pos, blockState); - } - - @Override - protected IManagedGridNode createMainNode() { - return GridHelper.createManagedNode(this, NODE_LISTENER); - } - - @Override - public void onMainNodeStateChanged(IGridNodeListener.State reason) { - if (getMainNode().hasGridBooted()) { - this.logic.notifyNeighbors(); - } - } - - @Override - public void addAdditionalDrops(Level level, BlockPos pos, List drops) { - this.logic.addDrops(drops); - } - - @Override - public void saveAdditional(CompoundTag data) { - super.saveAdditional(data); - this.logic.writeToNBT(data); - } - - @Override - public void loadTag(CompoundTag data) { - super.loadTag(data); - this.logic.readFromNBT(data); - } - - @Override - public AECableType getCableConnectionType(Direction dir) { - return this.logic.getCableConnectionType(dir); - } - - @Override - public InterfaceLogic getInterfaceLogic() { - return this.logic; - } - - @Override - public BlockEntity getBlockEntity() { - return this; - } - - @Override - public ItemStack getMainMenuIcon() { - return AEBlocks.INTERFACE.stack(); - } - - @Nullable - @Override - public InternalInventory getSubInventory(ResourceLocation id) { - if (id.equals(UPGRADES)) { - return logic.getUpgrades(); - } - return super.getSubInventory(id); - } -} diff --git a/src/main/java/appeng/blockentity/misc/LightDetectorBlockEntity.java b/src/main/java/appeng/blockentity/misc/LightDetectorBlockEntity.java deleted file mode 100644 index 93e7a7d2d43..00000000000 --- a/src/main/java/appeng/blockentity/misc/LightDetectorBlockEntity.java +++ /dev/null @@ -1,64 +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.blockentity.misc; - -import net.minecraft.core.BlockPos; -import net.minecraft.world.level.block.entity.BlockEntityType; -import net.minecraft.world.level.block.state.BlockState; - -import appeng.blockentity.AEBaseBlockEntity; -import appeng.blockentity.CommonTickingBlockEntity; -import appeng.util.Platform; - -public class LightDetectorBlockEntity extends AEBaseBlockEntity implements CommonTickingBlockEntity { - - private int lastCheck = 30; - private int lastLight = 0; - - public LightDetectorBlockEntity(BlockEntityType blockEntityType, BlockPos pos, BlockState blockState) { - super(blockEntityType, pos, blockState); - } - - public boolean isReady() { - return this.lastLight > 0; - } - - @Override - public void commonTick() { - this.lastCheck++; - if (this.lastCheck > 30) { - this.lastCheck = 0; - this.updateLight(); - } - } - - public void updateLight() { - final int val = this.level.getMaxLocalRawBrightness(this.worldPosition); - - if (this.lastLight != val) { - this.lastLight = val; - Platform.notifyBlocksOfNeighbors(this.level, this.worldPosition); - } - } - - @Override - public boolean canBeRotated() { - return false; - } -} diff --git a/src/main/java/appeng/blockentity/misc/PaintSplotchesBlockEntity.java b/src/main/java/appeng/blockentity/misc/PaintSplotchesBlockEntity.java deleted file mode 100644 index 56a642e8576..00000000000 --- a/src/main/java/appeng/blockentity/misc/PaintSplotchesBlockEntity.java +++ /dev/null @@ -1,212 +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.blockentity.misc; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -import io.netty.buffer.Unpooled; - -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.block.entity.BlockEntityType; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.phys.Vec3; - -import appeng.api.util.AEColor; -import appeng.block.paint.PaintSplotches; -import appeng.block.paint.PaintSplotchesBlock; -import appeng.blockentity.AEBaseBlockEntity; -import appeng.helpers.Splotch; -import appeng.items.misc.PaintBallItem; - -public class PaintSplotchesBlockEntity extends AEBaseBlockEntity { - - private List dots = null; - - public PaintSplotchesBlockEntity(BlockEntityType blockEntityType, BlockPos pos, BlockState blockState) { - super(blockEntityType, pos, blockState); - } - - @Override - public boolean canBeRotated() { - return false; - } - - @Override - public void saveAdditional(CompoundTag data) { - super.saveAdditional(data); - final FriendlyByteBuf myDat = new FriendlyByteBuf(Unpooled.buffer()); - this.writeBuffer(myDat); - if (myDat.hasArray()) { - data.putByteArray("dots", myDat.array()); - } - } - - private void writeBuffer(FriendlyByteBuf out) { - if (this.dots == null) { - out.writeByte(0); - return; - } - - out.writeByte(this.dots.size()); - - for (Splotch s : this.dots) { - s.writeToStream(out); - } - } - - @Override - public void loadTag(CompoundTag data) { - super.loadTag(data); - if (data.contains("dots")) { - this.readBuffer(new FriendlyByteBuf(Unpooled.copiedBuffer(data.getByteArray("dots")))); - } - } - - private void readBuffer(FriendlyByteBuf in) { - final byte howMany = in.readByte(); - - if (howMany == 0) { - this.dots = null; - return; - } - - this.dots = new ArrayList<>(howMany); - for (int x = 0; x < howMany; x++) { - this.dots.add(new Splotch(in)); - } - } - - @Override - protected void writeToStream(FriendlyByteBuf data) { - super.writeToStream(data); - this.writeBuffer(data); - } - - @Override - protected boolean readFromStream(FriendlyByteBuf data) { - super.readFromStream(data); - this.readBuffer(data); - return true; - } - - public void neighborChanged() { - if (this.dots == null) { - return; - } - - for (Direction side : Direction.values()) { - if (!this.isSideValid(side)) { - this.removeSide(side); - } - } - - this.updateData(); - } - - public boolean isSideValid(Direction side) { - final BlockPos p = this.worldPosition.relative(side); - final BlockState blk = this.level.getBlockState(p); - return blk.isFaceSturdy(level, p, side.getOpposite()); - } - - private void removeSide(Direction side) { - this.dots.removeIf(s -> s.getSide() == side); - - this.markForUpdate(); - this.saveChanges(); - } - - private void updateData() { - if (this.dots.isEmpty()) { - this.dots = null; - } - - if (this.dots == null) { - this.level.removeBlock(this.worldPosition, false); - } else { - var lumenCount = 0; - for (Splotch dot : dots) { - if (dot.isLumen()) { - lumenCount++; - if (lumenCount >= 2) { - break; - } - } - } - this.level.setBlockAndUpdate(getBlockPos(), - getBlockState().setValue(PaintSplotchesBlock.LIGHT_LEVEL, lumenCount)); - } - } - - public void cleanSide(Direction side) { - if (this.dots == null) { - return; - } - - this.removeSide(side); - this.updateData(); - } - - public void addBlot(ItemStack type, Direction side, Vec3 hitVec) { - final BlockPos p = this.worldPosition.relative(side); - - final BlockState blk = this.level.getBlockState(p); - if (blk.isFaceSturdy(this.level, p, side.getOpposite())) { - final PaintBallItem ipb = (PaintBallItem) type.getItem(); - - final AEColor col = ipb.getColor(); - final boolean lit = ipb.isLumen(); - - if (this.dots == null) { - this.dots = new ArrayList<>(); - } - - if (this.dots.size() > 20) { - this.dots.remove(0); - } - - this.dots.add(new Splotch(col, lit, side, hitVec)); - - updateData(); - this.markForUpdate(); - this.saveChanges(); - } - } - - public Collection getDots() { - if (this.dots == null) { - return Collections.emptyList(); - } - - return this.dots; - } - - @Override - public Object getRenderAttachmentData() { - return new PaintSplotches(getDots()); - } - -} diff --git a/src/main/java/appeng/blockentity/misc/QuartzGrowthAcceleratorBlockEntity.java b/src/main/java/appeng/blockentity/misc/QuartzGrowthAcceleratorBlockEntity.java deleted file mode 100644 index 4a74ef24827..00000000000 --- a/src/main/java/appeng/blockentity/misc/QuartzGrowthAcceleratorBlockEntity.java +++ /dev/null @@ -1,187 +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.blockentity.misc; - -import java.util.EnumSet; - -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.world.level.block.entity.BlockEntityType; -import net.minecraft.world.level.block.state.BlockState; - -import appeng.api.ids.AETags; -import appeng.api.implementations.IPowerChannelState; -import appeng.api.implementations.blockentities.ICrankable; -import appeng.api.networking.IGridNode; -import appeng.api.networking.IGridNodeListener; -import appeng.api.networking.ticking.IGridTickable; -import appeng.api.networking.ticking.TickRateModulation; -import appeng.api.networking.ticking.TickingRequest; -import appeng.api.util.AECableType; -import appeng.blockentity.grid.AENetworkBlockEntity; -import appeng.core.AEConfig; - -public class QuartzGrowthAcceleratorBlockEntity extends AENetworkBlockEntity implements IPowerChannelState { - - // Allow storage of up to 10 cranks - public static final int MAX_STORED_POWER = 10 * CrankBlockEntity.POWER_PER_CRANK_TURN; - private static final int POWER_PER_TICK = 8; - - private boolean hasPower = false; - - // For cranking! - private float storedPower; - - public QuartzGrowthAcceleratorBlockEntity(BlockEntityType blockEntityType, BlockPos pos, BlockState blockState) { - super(blockEntityType, pos, blockState); - this.getMainNode().setExposedOnSides(EnumSet.noneOf(Direction.class)); - this.getMainNode().setFlags(); - this.getMainNode().setIdlePowerUsage(POWER_PER_TICK); - this.getMainNode().addService(IGridTickable.class, new IGridTickable() { - @Override - public TickingRequest getTickingRequest(IGridNode node) { - int speed = AEConfig.instance().getGrowthAcceleratorSpeed(); - return new TickingRequest(speed, speed, false, false); - } - - @Override - public TickRateModulation tickingRequest(IGridNode node, int ticksSinceLastCall) { - onTick(ticksSinceLastCall); - return TickRateModulation.SAME; - } - }); - } - - private void onTick(int ticksSinceLastCall) { - // We drain local power in *addition* to network power, which is handled via idle power consumption - if (storedPower > 0) { - storedPower -= POWER_PER_TICK * Math.max(1, ticksSinceLastCall); - if (storedPower <= 0) { - storedPower = 0; - markForUpdate(); - } - } else if (!getMainNode().isPowered()) { - return; - } - - for (var direction : Direction.values()) { - var adjPos = getBlockPos().relative(direction); - var adjState = getLevel().getBlockState(adjPos); - - if (!adjState.is(AETags.GROWTH_ACCELERATABLE)) { - continue; - } - - adjState.randomTick((ServerLevel) getLevel(), adjPos, getLevel().getRandom()); - } - } - - @Override - public void onMainNodeStateChanged(IGridNodeListener.State reason) { - if (reason == IGridNodeListener.State.POWER) { - this.markForUpdate(); - } - } - - @Override - public AECableType getCableConnectionType(Direction dir) { - return AECableType.COVERED; - } - - @Override - public boolean readFromStream(FriendlyByteBuf data) { - final boolean c = super.readFromStream(data); - final boolean hadPower = this.isPowered(); - this.setPowered(data.readBoolean()); - return this.isPowered() != hadPower || c; - } - - @Override - public void writeToStream(FriendlyByteBuf data) { - super.writeToStream(data); - data.writeBoolean(this.getMainNode().isPowered()); - } - - @Override - public void setOrientation(Direction inForward, Direction inUp) { - super.setOrientation(inForward, inUp); - this.getMainNode().setExposedOnSides(EnumSet.of(this.getUp(), this.getUp().getOpposite())); - } - - @Override - public void onReady() { - this.getMainNode().setExposedOnSides(EnumSet.of(this.getUp(), this.getUp().getOpposite())); - super.onReady(); - } - - @Override - public boolean isPowered() { - if (!isClientSide()) { - return this.getMainNode().isPowered() || storedPower > 0; - } - - return this.hasPower; - } - - @Override - public boolean isActive() { - return this.isPowered(); - } - - private void setPowered(boolean hasPower) { - this.hasPower = hasPower; - } - - /** - * Allow cranking from the top or bottom. - */ - @org.jetbrains.annotations.Nullable - public ICrankable getCrankable(Direction direction) { - if (direction == getUp() || direction == getUp().getOpposite()) { - return new Crankable(); - } - return null; - } - - class Crankable implements ICrankable { - @Override - public boolean canTurn() { - return storedPower < MAX_STORED_POWER; - } - - @Override - public void applyTurn() { - if (isClientSide()) { - return; // Only apply crank-turns server-side - } - - // Cranking will always add enough power for at least one tick, - // so we should send a transition from unpowered to powered to clients. - boolean needsUpdate = !isPowered(); - - storedPower = Math.min(MAX_STORED_POWER, storedPower + CrankBlockEntity.POWER_PER_CRANK_TURN); - - if (needsUpdate) { - markForUpdate(); - } - } - } -} diff --git a/src/main/java/appeng/blockentity/misc/SecurityStationBlockEntity.java b/src/main/java/appeng/blockentity/misc/SecurityStationBlockEntity.java index c1f7eeaca4c..35b86c2639a 100644 --- a/src/main/java/appeng/blockentity/misc/SecurityStationBlockEntity.java +++ b/src/main/java/appeng/blockentity/misc/SecurityStationBlockEntity.java @@ -38,7 +38,6 @@ import appeng.api.config.Settings; import appeng.api.config.SortDir; import appeng.api.config.SortOrder; -import appeng.api.config.ViewItems; import appeng.api.features.IPlayerRegistry; import appeng.api.features.Locatables; import appeng.api.implementations.blockentities.IColorableBlockEntity; @@ -79,7 +78,6 @@ public SecurityStationBlockEntity(BlockEntityType blockEntityType, BlockPos p super(blockEntityType, pos, blockState); this.getMainNode() .setFlags(GridFlags.REQUIRE_CHANNEL) - .setIdlePowerUsage(2.0) .addService(ISecurityProvider.class, this); difference++; @@ -89,7 +87,6 @@ public SecurityStationBlockEntity(BlockEntityType blockEntityType, BlockPos p } this.cm.registerSetting(Settings.SORT_BY, SortOrder.NAME); - this.cm.registerSetting(Settings.VIEW_MODE, ViewItems.ALL); this.cm.registerSetting(Settings.SORT_DIRECTION, SortDir.ASCENDING); } diff --git a/src/main/java/appeng/blockentity/misc/VibrationChamberBlockEntity.java b/src/main/java/appeng/blockentity/misc/VibrationChamberBlockEntity.java deleted file mode 100644 index 9eec098fde2..00000000000 --- a/src/main/java/appeng/blockentity/misc/VibrationChamberBlockEntity.java +++ /dev/null @@ -1,315 +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.blockentity.misc; - -import net.fabricmc.fabric.api.registry.FuelRegistry; -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.util.Mth; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.block.entity.BlockEntityType; -import net.minecraft.world.level.block.state.BlockState; - -import appeng.api.config.Actionable; -import appeng.api.inventories.InternalInventory; -import appeng.api.networking.IGridNode; -import appeng.api.networking.ticking.IGridTickable; -import appeng.api.networking.ticking.TickRateModulation; -import appeng.api.networking.ticking.TickingRequest; -import appeng.api.util.AECableType; -import appeng.blockentity.grid.AENetworkInvBlockEntity; -import appeng.core.AEConfig; -import appeng.core.settings.TickRates; -import appeng.util.Platform; -import appeng.util.inv.AppEngInternalInventory; -import appeng.util.inv.FilteredInternalInventory; -import appeng.util.inv.filter.IAEItemFilter; - -public class VibrationChamberBlockEntity extends AENetworkInvBlockEntity implements IGridTickable { - private final AppEngInternalInventory inv = new AppEngInternalInventory(this, 1); - private final InternalInventory invExt = new FilteredInternalInventory(this.inv, new FuelSlotFilter()); - - private double currentFuelTicksPerTick; - private double remainingFuelTicks = 0; - private double fuelItemFuelTicks = 0; - - // client side.. (caches last sent state on server) - public boolean isOn; - - private final double minFuelTicksPerTick; - private final double maxFuelTicksPerTick; - private final double initialFuelTicksPerTick; - - public VibrationChamberBlockEntity(BlockEntityType blockEntityType, BlockPos pos, BlockState blockState) { - super(blockEntityType, pos, blockState); - this.getMainNode() - .setIdlePowerUsage(0) - .setFlags() - .addService(IGridTickable.class, this); - - // Compute the original burn rate parameters from the config - var minEnergyRate = AEConfig.instance().getVibrationChamberMinEnergyPerGameTick(); - var maxEnergyRate = AEConfig.instance().getVibrationChamberMaxEnergyPerGameTick(); - var initialEnergyRate = Mth.clamp( - AEConfig.instance().getVibrationChamberEnergyPerFuelTick(), - minEnergyRate, - maxEnergyRate); - - minFuelTicksPerTick = minEnergyRate / getEnergyPerFuelTick(); - maxFuelTicksPerTick = maxEnergyRate / getEnergyPerFuelTick(); - initialFuelTicksPerTick = initialEnergyRate / getEnergyPerFuelTick(); - currentFuelTicksPerTick = initialFuelTicksPerTick; - } - - @Override - public AECableType getCableConnectionType(Direction dir) { - return AECableType.COVERED; - } - - @Override - protected boolean readFromStream(FriendlyByteBuf data) { - final boolean c = super.readFromStream(data); - final boolean wasOn = this.isOn; - - this.isOn = data.readBoolean(); - - return wasOn != this.isOn || c; // TESR doesn't need updates! - } - - @Override - protected void writeToStream(FriendlyByteBuf data) { - super.writeToStream(data); - this.isOn = this.getRemainingFuelTicks() > 0; - data.writeBoolean(this.isOn); - } - - @Override - public void saveAdditional(CompoundTag data) { - super.saveAdditional(data); - data.putDouble("burnTime", this.getRemainingFuelTicks()); - data.putDouble("maxBurnTime", this.getFuelItemFuelTicks()); - // Save as percentage of max-speed - var speed = (int) (currentFuelTicksPerTick * 100 / maxFuelTicksPerTick); - data.putInt("burnSpeed", speed); - } - - @Override - public void loadTag(CompoundTag data) { - super.loadTag(data); - this.setRemainingFuelTicks(data.getDouble("burnTime")); - this.setFuelItemFuelTicks(data.getDouble("maxBurnTime")); - this.setCurrentFuelTicksPerTick(data.getInt("burnSpeed") * maxFuelTicksPerTick / 100.0); - } - - @Override - public InternalInventory getExposedInventoryForSide(Direction facing) { - return this.invExt; - } - - @Override - public InternalInventory getInternalInventory() { - return this.inv; - } - - @Override - public void onChangeInventory(InternalInventory inv, int slot) { - if (this.getRemainingFuelTicks() <= 0 && this.canEatFuel()) { - getMainNode().ifPresent((grid, node) -> { - grid.getTickManager().wakeDevice(node); - }); - } - } - - private boolean canEatFuel() { - final ItemStack is = this.inv.getStackInSlot(0); - if (!is.isEmpty()) { - final int newBurnTime = getBurnTime(is); - if (newBurnTime > 0 && is.getCount() > 0) { - return true; - } - } - return false; - } - - @Override - public TickingRequest getTickingRequest(IGridNode node) { - if (this.getRemainingFuelTicks() <= 0) { - this.eatFuel(); - } - - return new TickingRequest(TickRates.VibrationChamber, - this.getRemainingFuelTicks() <= 0, false); - } - - @Override - public TickRateModulation tickingRequest(IGridNode node, int ticksSinceLastCall) { - if (this.getRemainingFuelTicks() <= 0) { - this.eatFuel(); - - if (this.getRemainingFuelTicks() > 0) { - return TickRateModulation.URGENT; - } - - this.setCurrentFuelTicksPerTick(initialFuelTicksPerTick); - return TickRateModulation.SLEEP; - } - - double fuelTicksConsumed = ticksSinceLastCall * currentFuelTicksPerTick; - this.setRemainingFuelTicks(this.getRemainingFuelTicks() - fuelTicksConsumed); - if (this.getRemainingFuelTicks() < 0) { - fuelTicksConsumed += this.getRemainingFuelTicks(); - this.setRemainingFuelTicks(0); - } - - // The full range should scale in 5 seconds (=100 ticks) - var speedScalingPerTick = (maxFuelTicksPerTick - minFuelTicksPerTick) / 100; - int speedStep = (int) Math.max(1, ticksSinceLastCall * speedScalingPerTick); - - var grid = node.getGrid(); - var energy = grid.getEnergyService(); - - // If our burn rate is zero, check if the network would now accept any power - // And if it does, increase burn rate and tick faster - if (Math.abs(fuelTicksConsumed - 0) < 0.01) { - if (energy.injectPower(1, Actionable.SIMULATE) == 0) { - this.setCurrentFuelTicksPerTick(this.getCurrentFuelTicksPerTick() + speedStep); - return TickRateModulation.FASTER; - } - return TickRateModulation.IDLE; - } - - final double newPower = fuelTicksConsumed * getEnergyPerFuelTick(); - final double overFlow = energy.injectPower(newPower, Actionable.MODULATE); - - // Speed up or slow down the burn rate, the overflow is voided - if (overFlow > 0) { - this.setCurrentFuelTicksPerTick(this.getCurrentFuelTicksPerTick() - speedStep); - } else { - this.setCurrentFuelTicksPerTick(this.getCurrentFuelTicksPerTick() + speedStep); - } - - return overFlow > 0 ? TickRateModulation.SLOWER : TickRateModulation.FASTER; - } - - private void eatFuel() { - final ItemStack is = this.inv.getStackInSlot(0); - if (!is.isEmpty()) { - final int newBurnTime = getBurnTime(is); - if (newBurnTime > 0 && is.getCount() > 0) { - this.setRemainingFuelTicks(this.getRemainingFuelTicks() + newBurnTime); - this.setFuelItemFuelTicks(this.getRemainingFuelTicks()); - - final Item fuelItem = is.getItem(); - is.shrink(1); - - if (is.isEmpty()) { - this.inv.setItemDirect(0, new ItemStack(fuelItem.getCraftingRemainingItem())); - } else { - this.inv.setItemDirect(0, is); - } - this.saveChanges(); - } - } - - if (this.getRemainingFuelTicks() > 0) { - getMainNode().ifPresent((grid, node) -> { - grid.getTickManager().wakeDevice(node); - }); - } - - // state change - if (!this.isOn && this.getRemainingFuelTicks() > 0 || this.isOn && this.getRemainingFuelTicks() <= 0) { - this.isOn = this.getRemainingFuelTicks() > 0; - this.markForUpdate(); - - if (this.hasLevel()) { - Platform.notifyBlocksOfNeighbors(this.level, this.worldPosition); - } - } - } - - public static int getBurnTime(ItemStack is) { - var burnTime = FuelRegistry.INSTANCE.get(is.getItem()); - return burnTime != null ? burnTime : 0; - } - - public static boolean hasBurnTime(ItemStack is) { - return getBurnTime(is) > 0; - } - - public double getCurrentFuelTicksPerTick() { - return this.currentFuelTicksPerTick; - } - - private void setCurrentFuelTicksPerTick(double currentFuelTicksPerTick) { - this.currentFuelTicksPerTick = Mth.clamp(currentFuelTicksPerTick, minFuelTicksPerTick, maxFuelTicksPerTick); - } - - public double getFuelItemFuelTicks() { - return this.fuelItemFuelTicks; - } - - private void setFuelItemFuelTicks(double fuelItemFuelTicks) { - this.fuelItemFuelTicks = fuelItemFuelTicks; - } - - public double getRemainingFuelTicks() { - return this.remainingFuelTicks; - } - - private void setRemainingFuelTicks(double remainingFuelTicks) { - this.remainingFuelTicks = remainingFuelTicks; - } - - /** - * AE Power generated per consumed fuel-tick. - */ - public double getEnergyPerFuelTick() { - return AEConfig.instance().getVibrationChamberEnergyPerFuelTick(); - } - - /** - * Lowest fuel-ticks per game-tick when power is not being consumed fast enough. - */ - public double getMinFuelTicksPerTick() { - return minFuelTicksPerTick; - } - - /** - * Highest fuel-ticks per game-tick when all power is being consumed. - */ - public double getMaxFuelTicksPerTick() { - return maxFuelTicksPerTick; - } - - private static class FuelSlotFilter implements IAEItemFilter { - @Override - public boolean allowExtract(InternalInventory inv, int slot, int amount) { - return !hasBurnTime(inv.getStackInSlot(slot)); - } - - @Override - public boolean allowInsert(InternalInventory inv, int slot, ItemStack stack) { - return hasBurnTime(stack); - } - } -} diff --git a/src/main/java/appeng/blockentity/networking/CableBusBlockEntity.java b/src/main/java/appeng/blockentity/networking/CableBusBlockEntity.java index 79ce8ed4a53..7441e6c3451 100644 --- a/src/main/java/appeng/blockentity/networking/CableBusBlockEntity.java +++ b/src/main/java/appeng/blockentity/networking/CableBusBlockEntity.java @@ -175,11 +175,6 @@ public void onReady() { } } - @Override - public IFacadeContainer getFacadeContainer() { - return this.getCableBus().getFacadeContainer(); - } - @Nullable @Override public IPart getPart(@Nullable Direction side) { @@ -326,13 +321,6 @@ public InteractionResult disassembleWithWrench(Player player, Level level, Block var pos = getBlockPos(); - // A facade cannot exist without a cable part, no host cleanup needed. - if (sp.facade != null) { - is.add(sp.facade.getItemStack()); - cb.getFacadeContainer().removeFacade(cb, sp.side); - Platform.notifyBlocksOfNeighbors(level, pos); - } - if (!is.isEmpty()) { Platform.spawnDrops(level, pos, is); } diff --git a/src/main/java/appeng/blockentity/networking/ControllerBlockEntity.java b/src/main/java/appeng/blockentity/networking/ControllerBlockEntity.java index d99c917a1db..0bd1db68ba2 100644 --- a/src/main/java/appeng/blockentity/networking/ControllerBlockEntity.java +++ b/src/main/java/appeng/blockentity/networking/ControllerBlockEntity.java @@ -23,22 +23,19 @@ import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; -import appeng.api.config.Actionable; import appeng.api.inventories.InternalInventory; import appeng.api.networking.GridFlags; import appeng.api.networking.GridHelper; import appeng.api.networking.IGridNodeListener; import appeng.api.networking.events.GridControllerChange; -import appeng.api.networking.events.GridPowerStorageStateChanged; -import appeng.api.networking.events.GridPowerStorageStateChanged.PowerEventType; import appeng.api.networking.pathing.ControllerState; import appeng.api.util.AECableType; import appeng.block.networking.ControllerBlock; import appeng.block.networking.ControllerBlock.ControllerBlockState; -import appeng.blockentity.grid.AENetworkPowerBlockEntity; +import appeng.blockentity.grid.AENetworkInvBlockEntity; import appeng.util.Platform; -public class ControllerBlockEntity extends AENetworkPowerBlockEntity { +public class ControllerBlockEntity extends AENetworkInvBlockEntity { static { GridHelper.addNodeOwnerEventHandler( @@ -49,9 +46,6 @@ public class ControllerBlockEntity extends AENetworkPowerBlockEntity { public ControllerBlockEntity(BlockEntityType blockEntityType, BlockPos pos, BlockState blockState) { super(blockEntityType, pos, blockState); - this.setInternalMaxPower(8000); - this.setInternalPublicPowerStorage(true); - this.getMainNode().setIdlePowerUsage(3); this.getMainNode().setFlags(GridFlags.CANNOT_CARRY, GridFlags.DENSE_CAPACITY); } @@ -80,12 +74,10 @@ public void updateState() { var grid = getMainNode().getGrid(); if (grid != null) { - if (grid.getEnergyService().isNetworkPowered()) { - metaState = ControllerBlockState.online; + metaState = ControllerBlockState.online; - if (grid.getPathingService().getControllerState() == ControllerState.CONTROLLER_CONFLICT) { - metaState = ControllerBlockState.conflicted; - } + if (grid.getPathingService().getControllerState() == ControllerState.CONTROLLER_CONFLICT) { + metaState = ControllerBlockState.conflicted; } } else { metaState = ControllerBlockState.offline; @@ -100,33 +92,6 @@ public void updateState() { } - @Override - protected double getFunnelPowerDemand(double maxReceived) { - var grid = getMainNode().getGrid(); - if (grid != null) { - return grid.getEnergyService().getEnergyDemand(maxReceived); - } else { - // no grid? use local... - return super.getFunnelPowerDemand(maxReceived); - } - } - - @Override - protected double funnelPowerIntoStorage(double power, Actionable mode) { - var grid = getMainNode().getGrid(); - if (grid != null) { - return grid.getEnergyService().injectPower(power, mode); - } else { - // no grid? use local... - return super.funnelPowerIntoStorage(power, mode); - } - } - - @Override - protected void PowerEvent(PowerEventType x) { - getMainNode().ifPresent(grid -> grid.postEvent(new GridPowerStorageStateChanged(this, x))); - } - @Override public InternalInventory getInternalInventory() { return InternalInventory.empty(); diff --git a/src/main/java/appeng/blockentity/networking/CreativeEnergyCellBlockEntity.java b/src/main/java/appeng/blockentity/networking/CreativeEnergyCellBlockEntity.java deleted file mode 100644 index 9794811c83f..00000000000 --- a/src/main/java/appeng/blockentity/networking/CreativeEnergyCellBlockEntity.java +++ /dev/null @@ -1,82 +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.blockentity.networking; - -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.world.level.block.entity.BlockEntityType; -import net.minecraft.world.level.block.state.BlockState; - -import appeng.api.config.AccessRestriction; -import appeng.api.config.Actionable; -import appeng.api.config.PowerMultiplier; -import appeng.api.networking.energy.IAEPowerStorage; -import appeng.api.util.AECableType; -import appeng.blockentity.grid.AENetworkBlockEntity; - -public class CreativeEnergyCellBlockEntity extends AENetworkBlockEntity implements IAEPowerStorage { - - public CreativeEnergyCellBlockEntity(BlockEntityType blockEntityType, BlockPos pos, BlockState blockState) { - super(blockEntityType, pos, blockState); - this.getMainNode() - .setIdlePowerUsage(0) - .addService(IAEPowerStorage.class, this); - } - - @Override - public AECableType getCableConnectionType(Direction dir) { - return AECableType.COVERED; - } - - @Override - public double injectAEPower(double amt, Actionable mode) { - return 0; - } - - @Override - public double getAEMaxPower() { - return Long.MAX_VALUE / 10000; - } - - @Override - public double getAECurrentPower() { - return Long.MAX_VALUE / 10000; - } - - @Override - public boolean isAEPublicPowerStorage() { - return true; - } - - @Override - public AccessRestriction getPowerFlow() { - return AccessRestriction.READ_WRITE; - } - - @Override - public double extractAEPower(double amt, Actionable mode, PowerMultiplier pm) { - return amt; - } - - @Override - public int getPriority() { - // MAX_VALUE to move creative cells to the front. - return Integer.MAX_VALUE; - } -} diff --git a/src/main/java/appeng/blockentity/networking/EnergyAcceptorBlockEntity.java b/src/main/java/appeng/blockentity/networking/EnergyAcceptorBlockEntity.java deleted file mode 100644 index 214215ff70f..00000000000 --- a/src/main/java/appeng/blockentity/networking/EnergyAcceptorBlockEntity.java +++ /dev/null @@ -1,73 +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.blockentity.networking; - -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.world.level.block.entity.BlockEntityType; -import net.minecraft.world.level.block.state.BlockState; - -import appeng.api.config.Actionable; -import appeng.api.inventories.InternalInventory; -import appeng.api.util.AECableType; -import appeng.blockentity.grid.AENetworkPowerBlockEntity; - -public class EnergyAcceptorBlockEntity extends AENetworkPowerBlockEntity { - - public EnergyAcceptorBlockEntity(BlockEntityType blockEntityType, BlockPos pos, BlockState blockState) { - super(blockEntityType, pos, blockState); - this.getMainNode().setIdlePowerUsage(0.0); - this.setInternalMaxPower(0); - } - - @Override - public AECableType getCableConnectionType(Direction dir) { - return AECableType.COVERED; - } - - @Override - protected double getFunnelPowerDemand(double maxRequired) { - var grid = getMainNode().getGrid(); - if (grid != null) { - return grid.getEnergyService().getEnergyDemand(maxRequired); - } else { - return this.getInternalMaxPower(); - } - } - - @Override - protected double funnelPowerIntoStorage(double power, Actionable mode) { - var grid = getMainNode().getGrid(); - if (grid != null) { - return grid.getEnergyService().injectPower(power, mode); - } else { - return super.funnelPowerIntoStorage(power, mode); - } - } - - @Override - public InternalInventory getInternalInventory() { - return InternalInventory.empty(); - } - - @Override - public void onChangeInventory(InternalInventory inv, int slot) { - - } -} diff --git a/src/main/java/appeng/blockentity/networking/EnergyCellBlockEntity.java b/src/main/java/appeng/blockentity/networking/EnergyCellBlockEntity.java deleted file mode 100644 index 31a75f63f38..00000000000 --- a/src/main/java/appeng/blockentity/networking/EnergyCellBlockEntity.java +++ /dev/null @@ -1,240 +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.blockentity.networking; - -import javax.annotation.Nullable; - -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.util.Mth; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.level.block.entity.BlockEntityType; -import net.minecraft.world.level.block.state.BlockState; - -import appeng.api.config.AccessRestriction; -import appeng.api.config.Actionable; -import appeng.api.config.PowerMultiplier; -import appeng.api.networking.energy.IAEPowerStorage; -import appeng.api.networking.events.GridPowerStorageStateChanged; -import appeng.api.networking.events.GridPowerStorageStateChanged.PowerEventType; -import appeng.api.util.AECableType; -import appeng.block.networking.EnergyCellBlock; -import appeng.blockentity.grid.AENetworkBlockEntity; -import appeng.hooks.ticking.TickHandler; -import appeng.util.SettingsFrom; - -public class EnergyCellBlockEntity extends AENetworkBlockEntity implements IAEPowerStorage { - - private double internalCurrentPower = 0.0; - private final double internalMaxPower; - - private byte currentMeta = -1; - - private boolean neighborChangePending; - - public EnergyCellBlockEntity(BlockEntityType blockEntityType, BlockPos pos, BlockState blockState) { - super(blockEntityType, pos, blockState); - this.getMainNode() - .setIdlePowerUsage(0) - .addService(IAEPowerStorage.class, this); - - var cellBlock = (EnergyCellBlock) getBlockState().getBlock(); - this.internalMaxPower = cellBlock.getMaxPower(); - } - - @Override - public AECableType getCableConnectionType(Direction dir) { - return AECableType.COVERED; - } - - @Override - public void onReady() { - super.onReady(); - final int value = this.level.getBlockState(this.worldPosition).getValue(EnergyCellBlock.ENERGY_STORAGE); - this.currentMeta = (byte) value; - this.updateStateForPowerLevel(); - } - - /** - * Given a fill factor, return the storage level used for the state of the block. This is also used for determining - * the item model. - */ - public static int getStorageLevelFromFillFactor(double fillFactor) { - return (int) Math.floor(EnergyCellBlock.MAX_FULLNESS * Mth.clamp(fillFactor + 0.01, 0, 1)); - } - - /** - * Updates the block state of this cell so that it matches the power level. - */ - private void updateStateForPowerLevel() { - if (this.isRemoved()) { - return; - } - - int storageLevel = getStorageLevelFromFillFactor(this.internalCurrentPower / this.internalMaxPower); - - if (this.currentMeta != storageLevel) { - this.currentMeta = (byte) storageLevel; - this.level.setBlockAndUpdate(this.worldPosition, - this.level.getBlockState(this.worldPosition).setValue(EnergyCellBlock.ENERGY_STORAGE, - storageLevel)); - } - } - - private void onAmountChanged() { - // Delay the notification since this happens while energy is being extracted/injected from the grid - // During injection/extraction, the grid should not be modified - if (!neighborChangePending) { - neighborChangePending = true; - TickHandler.instance().addCallable(level, () -> { - if (!isRemoved() && neighborChangePending) { - neighborChangePending = false; - updateStateForPowerLevel(); - setChanged(); - } - }); - } - } - - @Override - public void saveAdditional(CompoundTag data) { - super.saveAdditional(data); - data.putDouble("internalCurrentPower", this.internalCurrentPower); - } - - @Override - public void loadTag(CompoundTag data) { - super.loadTag(data); - this.internalCurrentPower = data.getDouble("internalCurrentPower"); - } - - @Override - public boolean canBeRotated() { - return false; - } - - @Override - public void importSettings(SettingsFrom mode, CompoundTag input, @Nullable Player player) { - super.importSettings(mode, input, player); - - if (mode == SettingsFrom.DISMANTLE_ITEM) { - this.internalCurrentPower = input.getDouble("internalCurrentPower"); - } - } - - @Override - public void exportSettings(SettingsFrom from, CompoundTag data, @Nullable Player player) { - super.exportSettings(from, data, player); - - if (from == SettingsFrom.DISMANTLE_ITEM && this.internalCurrentPower > 0.0001) { - data.putDouble("internalCurrentPower", this.internalCurrentPower); - data.putDouble("internalMaxPower", this.internalMaxPower); // used for tool tip. - } - } - - @Override - public final double injectAEPower(double amt, Actionable mode) { - if (mode == Actionable.SIMULATE) { - final double fakeBattery = this.internalCurrentPower + amt; - if (fakeBattery > this.internalMaxPower) { - return fakeBattery - this.internalMaxPower; - } - - return 0; - } - - if (this.internalCurrentPower < 0.01 && amt > 0.01) { - this.getMainNode().getNode().getGrid() - .postEvent(new GridPowerStorageStateChanged(this, PowerEventType.PROVIDE_POWER)); - } - - this.internalCurrentPower += amt; - if (this.internalCurrentPower > this.internalMaxPower) { - amt = this.internalCurrentPower - this.internalMaxPower; - this.internalCurrentPower = this.internalMaxPower; - - this.onAmountChanged(); - return amt; - } - - this.onAmountChanged(); - return 0; - } - - @Override - public double getAEMaxPower() { - return this.internalMaxPower; - } - - @Override - public double getAECurrentPower() { - return this.internalCurrentPower; - } - - @Override - public boolean isAEPublicPowerStorage() { - return true; - } - - @Override - public AccessRestriction getPowerFlow() { - return AccessRestriction.READ_WRITE; - } - - @Override - public final double extractAEPower(double amt, Actionable mode, PowerMultiplier pm) { - return pm.divide(this.extractAEPower(pm.multiply(amt), mode)); - } - - @Override - public int getPriority() { - return ((EnergyCellBlock) getBlockState().getBlock()).getPriority(); - } - - private double extractAEPower(double amt, Actionable mode) { - if (mode == Actionable.SIMULATE) { - if (this.internalCurrentPower > amt) { - return amt; - } - return this.internalCurrentPower; - } - - final boolean wasFull = this.internalCurrentPower >= this.internalMaxPower - 0.001; - - if (wasFull && amt > 0.001) { - getMainNode().ifPresent( - grid -> grid.postEvent(new GridPowerStorageStateChanged(this, PowerEventType.REQUEST_POWER))); - } - - if (this.internalCurrentPower > amt) { - this.internalCurrentPower -= amt; - - this.onAmountChanged(); - return amt; - } - - amt = this.internalCurrentPower; - this.internalCurrentPower = 0; - - this.onAmountChanged(); - return amt; - } - -} diff --git a/src/main/java/appeng/blockentity/networking/WirelessBlockEntity.java b/src/main/java/appeng/blockentity/networking/WirelessBlockEntity.java index b1322c07fd0..566b14b02b8 100644 --- a/src/main/java/appeng/blockentity/networking/WirelessBlockEntity.java +++ b/src/main/java/appeng/blockentity/networking/WirelessBlockEntity.java @@ -27,7 +27,7 @@ import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; -import appeng.api.implementations.IPowerChannelState; +import appeng.api.implementations.IChannelState; import appeng.api.implementations.blockentities.IWirelessAccessPoint; import appeng.api.inventories.InternalInventory; import appeng.api.networking.GridFlags; @@ -36,23 +36,15 @@ import appeng.api.util.AECableType; import appeng.api.util.DimensionalBlockPos; import appeng.blockentity.grid.AENetworkInvBlockEntity; -import appeng.core.AEConfig; -import appeng.core.definitions.AEItems; -import appeng.util.inv.AppEngInternalInventory; -import appeng.util.inv.filter.AEItemDefinitionFilter; -public class WirelessBlockEntity extends AENetworkInvBlockEntity implements IWirelessAccessPoint, IPowerChannelState { +public class WirelessBlockEntity extends AENetworkInvBlockEntity implements IWirelessAccessPoint, IChannelState { - public static final int POWERED_FLAG = 1; public static final int CHANNEL_FLAG = 2; - private final AppEngInternalInventory inv = new AppEngInternalInventory(this, 1); - private int clientFlags = 0; public WirelessBlockEntity(BlockEntityType blockEntityType, BlockPos pos, BlockState blockState) { super(blockEntityType, pos, blockState); - this.inv.setFilter(new AEItemDefinitionFilter(AEItems.WIRELESS_BOOSTER)); this.getMainNode().setFlags(GridFlags.REQUIRE_CHANNEL); this.getMainNode().setExposedOnSides(EnumSet.noneOf(Direction.class)); } @@ -85,10 +77,6 @@ protected void writeToStream(FriendlyByteBuf data) { this.setClientFlags(0); getMainNode().ifPresent((grid, node) -> { - if (grid.getEnergyService().isNetworkPowered()) { - this.setClientFlags(this.getClientFlags() | POWERED_FLAG); - } - if (node.meetsChannelRequirements()) { this.setClientFlags(this.getClientFlags() | CHANNEL_FLAG); } @@ -107,11 +95,6 @@ public DimensionalBlockPos getLocation() { return new DimensionalBlockPos(this); } - @Override - public InternalInventory getInternalInventory() { - return this.inv; - } - @Override public void onChangeInventory(InternalInventory inv, int slot) { // :P @@ -120,34 +103,18 @@ public void onChangeInventory(InternalInventory inv, int slot) { @Override public void onReady() { this.getMainNode().setExposedOnSides(EnumSet.of(this.getForward().getOpposite())); - this.updatePower(); super.onReady(); } - private void updatePower() { - this.getMainNode().setIdlePowerUsage(AEConfig.instance().wireless_getPowerDrain(this.getBoosters())); - } - - private int getBoosters() { - final ItemStack boosters = this.inv.getStackInSlot(0); - return boosters == null ? 0 : boosters.getCount(); - } - @Override public void saveChanges() { - this.updatePower(); super.saveChanges(); } - @Override - public double getRange() { - return AEConfig.instance().wireless_getMaxRange(this.getBoosters()); - } - @Override public boolean isActive() { if (isClientSide()) { - return this.isPowered() && CHANNEL_FLAG == (this.getClientFlags() & CHANNEL_FLAG); + return CHANNEL_FLAG == (this.getClientFlags() & CHANNEL_FLAG); } return this.getMainNode().isOnline(); @@ -158,11 +125,6 @@ public IGrid getGrid() { return getMainNode().getGrid(); } - @Override - public boolean isPowered() { - return POWERED_FLAG == (this.getClientFlags() & POWERED_FLAG); - } - public int getClientFlags() { return this.clientFlags; } @@ -170,4 +132,9 @@ public int getClientFlags() { private void setClientFlags(int clientFlags) { this.clientFlags = clientFlags; } + + @Override + public InternalInventory getInternalInventory() { + return InternalInventory.empty(); + } } diff --git a/src/main/java/appeng/blockentity/powersink/AEBasePoweredBlockEntity.java b/src/main/java/appeng/blockentity/powersink/AEBasePoweredBlockEntity.java deleted file mode 100644 index f98e719907f..00000000000 --- a/src/main/java/appeng/blockentity/powersink/AEBasePoweredBlockEntity.java +++ /dev/null @@ -1,217 +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.blockentity.powersink; - -import java.util.EnumSet; -import java.util.Set; - -import javax.annotation.Nullable; - -import com.google.common.collect.ImmutableSet; - -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.world.level.block.entity.BlockEntityType; -import net.minecraft.world.level.block.state.BlockState; - -import team.reborn.energy.api.EnergyStorage; - -import appeng.api.config.AccessRestriction; -import appeng.api.config.Actionable; -import appeng.api.config.PowerMultiplier; -import appeng.api.config.PowerUnits; -import appeng.api.networking.energy.IAEPowerStorage; -import appeng.api.networking.events.GridPowerStorageStateChanged.PowerEventType; -import appeng.blockentity.AEBaseInvBlockEntity; -import appeng.helpers.ForgeEnergyAdapter; - -public abstract class AEBasePoweredBlockEntity extends AEBaseInvBlockEntity - implements IAEPowerStorage, IExternalPowerSink { - - // values that determine general function, are set by inheriting classes if - // needed. These should generally remain static. - private double internalMaxPower = 10000; - private boolean internalPublicPowerStorage = false; - private AccessRestriction internalPowerFlow = AccessRestriction.READ_WRITE; - // the current power buffer. - private double internalCurrentPower = 0; - private static final Set ALL_SIDES = ImmutableSet.copyOf(EnumSet.allOf(Direction.class)); - private Set internalPowerSides = ALL_SIDES; - private final EnergyStorage forgeEnergyAdapter; - // Cache the optional to not continuously re-allocate it or the supplier - - public AEBasePoweredBlockEntity(BlockEntityType blockEntityType, BlockPos pos, BlockState blockState) { - super(blockEntityType, pos, blockState); - this.forgeEnergyAdapter = new ForgeEnergyAdapter(this); - } - - protected final Set getPowerSides() { - return this.internalPowerSides; - } - - protected void setPowerSides(Set sides) { - this.internalPowerSides = ImmutableSet.copyOf(sides); - } - - @Override - public void saveAdditional(CompoundTag data) { - super.saveAdditional(data); - data.putDouble("internalCurrentPower", this.getInternalCurrentPower()); - } - - @Override - public void loadTag(CompoundTag data) { - super.loadTag(data); - this.setInternalCurrentPower(data.getDouble("internalCurrentPower")); - } - - @Override - public final double getExternalPowerDemand(PowerUnits externalUnit, double maxPowerRequired) { - return PowerUnits.AE.convertTo(externalUnit, - Math.max(0.0, this.getFunnelPowerDemand(externalUnit.convertTo(PowerUnits.AE, maxPowerRequired)))); - } - - protected double getFunnelPowerDemand(double maxRequired) { - return this.getInternalMaxPower() - this.getInternalCurrentPower(); - } - - @Override - public final double injectExternalPower(PowerUnits input, double amt, Actionable mode) { - return PowerUnits.AE.convertTo(input, this.funnelPowerIntoStorage(input.convertTo(PowerUnits.AE, amt), mode)); - } - - protected double funnelPowerIntoStorage(double power, Actionable mode) { - return this.injectAEPower(power, mode); - } - - @Override - public final double injectAEPower(double amt, Actionable mode) { - if (amt < 0.000001) { - return 0; - } - - final double required = this.getAEMaxPower() - this.getAECurrentPower(); - final double insertable = Math.min(required, amt); - - if (mode == Actionable.MODULATE) { - if (this.getInternalCurrentPower() < 0.01 && insertable > 0.01) { - this.PowerEvent(PowerEventType.PROVIDE_POWER); - } - - this.setInternalCurrentPower(this.getInternalCurrentPower() + insertable); - } - - return amt - insertable; - } - - protected void PowerEvent(PowerEventType x) { - // nothing. - } - - @Override - public final double getAEMaxPower() { - return this.getInternalMaxPower(); - } - - @Override - public final double getAECurrentPower() { - return this.getInternalCurrentPower(); - } - - @Override - public final boolean isAEPublicPowerStorage() { - return this.isInternalPublicPowerStorage(); - } - - @Override - public final AccessRestriction getPowerFlow() { - return this.getInternalPowerFlow(); - } - - @Override - public final double extractAEPower(double amt, Actionable mode, PowerMultiplier multiplier) { - return multiplier.divide(this.extractAEPower(multiplier.multiply(amt), mode)); - } - - protected double extractAEPower(double amt, Actionable mode) { - if (mode == Actionable.SIMULATE) { - if (this.getInternalCurrentPower() > amt) { - return amt; - } - return this.getInternalCurrentPower(); - } - - final boolean wasFull = this.getInternalCurrentPower() >= this.getInternalMaxPower() - 0.001; - if (wasFull && amt > 0.001) { - this.PowerEvent(PowerEventType.REQUEST_POWER); - } - - if (this.getInternalCurrentPower() > amt) { - this.setInternalCurrentPower(this.getInternalCurrentPower() - amt); - return amt; - } - - amt = this.getInternalCurrentPower(); - this.setInternalCurrentPower(0); - return amt; - } - - public double getInternalCurrentPower() { - return this.internalCurrentPower; - } - - public void setInternalCurrentPower(double internalCurrentPower) { - this.internalCurrentPower = internalCurrentPower; - } - - public double getInternalMaxPower() { - return this.internalMaxPower; - } - - public void setInternalMaxPower(double internalMaxPower) { - this.internalMaxPower = internalMaxPower; - } - - private boolean isInternalPublicPowerStorage() { - return this.internalPublicPowerStorage; - } - - public void setInternalPublicPowerStorage(boolean internalPublicPowerStorage) { - this.internalPublicPowerStorage = internalPublicPowerStorage; - } - - private AccessRestriction getInternalPowerFlow() { - return this.internalPowerFlow; - } - - public void setInternalPowerFlow(AccessRestriction internalPowerFlow) { - this.internalPowerFlow = internalPowerFlow; - } - - @Nullable - public EnergyStorage getEnergyStorage(Direction direction) { - if (getPowerSides().contains(direction)) { - return forgeEnergyAdapter; - } else { - return null; - } - } - -} diff --git a/src/main/java/appeng/blockentity/powersink/IExternalPowerSink.java b/src/main/java/appeng/blockentity/powersink/IExternalPowerSink.java deleted file mode 100644 index 65d27364783..00000000000 --- a/src/main/java/appeng/blockentity/powersink/IExternalPowerSink.java +++ /dev/null @@ -1,44 +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.blockentity.powersink; - -import appeng.api.config.Actionable; -import appeng.api.config.PowerUnits; -import appeng.api.networking.energy.IAEPowerStorage; - -public interface IExternalPowerSink extends IAEPowerStorage { - - /** - * Inject power into the network - * - * @param externalUnit The {@link PowerUnits} used by the input - * @param amount The amount offered to the sink. - * @param mode Modulate or simulate the operation. - * @return The unused amount, which could not be inserted into the sink. - */ - double injectExternalPower(PowerUnits externalUnit, double amount, Actionable mode); - - /** - * @param externalUnit The {@link PowerUnits} used by the input - * @param maxPowerRequired Limit the demand to this upper bound. - * @return The amount of power demanded by the sink. - */ - double getExternalPowerDemand(PowerUnits externalUnit, double maxPowerRequired); - -} diff --git a/src/main/java/appeng/blockentity/qnb/QuantumBridgeBlockEntity.java b/src/main/java/appeng/blockentity/qnb/QuantumBridgeBlockEntity.java deleted file mode 100644 index e583d1dfb1b..00000000000 --- a/src/main/java/appeng/blockentity/qnb/QuantumBridgeBlockEntity.java +++ /dev/null @@ -1,277 +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.blockentity.qnb; - -import java.util.EnumSet; - -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraft.world.level.block.entity.BlockEntityType; -import net.minecraft.world.level.block.state.BlockState; - -import appeng.api.inventories.InternalInventory; -import appeng.api.networking.GridFlags; -import appeng.api.networking.IGridNodeListener; -import appeng.api.util.AECableType; -import appeng.block.qnb.QnbFormedState; -import appeng.blockentity.ServerTickingBlockEntity; -import appeng.blockentity.grid.AENetworkInvBlockEntity; -import appeng.core.definitions.AEBlocks; -import appeng.me.cluster.IAEMultiBlock; -import appeng.me.cluster.implementations.QuantumCalculator; -import appeng.me.cluster.implementations.QuantumCluster; -import appeng.util.inv.AppEngInternalInventory; - -public class QuantumBridgeBlockEntity extends AENetworkInvBlockEntity - implements IAEMultiBlock, ServerTickingBlockEntity { - - private final byte corner = 16; - private final AppEngInternalInventory internalInventory = new AppEngInternalInventory(this, 1, 1); - private final byte hasSingularity = 32; - private final byte powered = 64; - - private final QuantumCalculator calc = new QuantumCalculator(this); - private byte constructed = -1; - private QuantumCluster cluster; - private boolean updateStatus = false; - - public QuantumBridgeBlockEntity(BlockEntityType blockEntityType, BlockPos pos, BlockState blockState) { - super(blockEntityType, pos, blockState); - this.getMainNode().setExposedOnSides(EnumSet.noneOf(Direction.class)); - this.getMainNode().setFlags(GridFlags.DENSE_CAPACITY); - this.getMainNode().setIdlePowerUsage(22); - } - - @Override - public void serverTick() { - if (this.updateStatus) { - this.updateStatus = false; - if (this.cluster != null) { - this.cluster.updateStatus(true); - } - this.markForUpdate(); - } - } - - @Override - protected void writeToStream(FriendlyByteBuf data) { - super.writeToStream(data); - int out = this.constructed; - - if (!this.internalInventory.getStackInSlot(0).isEmpty() && this.constructed != -1) { - out |= this.hasSingularity; - } - - if (this.getMainNode().isActive() && this.constructed != -1) { - out |= this.powered; - } - - data.writeByte((byte) out); - } - - @Override - protected boolean readFromStream(FriendlyByteBuf data) { - final boolean c = super.readFromStream(data); - final int oldValue = this.constructed; - this.constructed = data.readByte(); - return this.constructed != oldValue || c; - } - - @Override - public InternalInventory getInternalInventory() { - return this.internalInventory; - } - - @Override - public void onChangeInventory(InternalInventory inv, int slot) { - if (this.cluster != null) { - this.cluster.updateStatus(true); - } - } - - @Override - public InternalInventory getExposedInventoryForSide(Direction side) { - if (this.isCenter()) { - return this.internalInventory; - } - return InternalInventory.empty(); - } - - private boolean isCenter() { - return getBlockState().is(AEBlocks.QUANTUM_LINK.block()); - } - - @Override - public void onMainNodeStateChanged(IGridNodeListener.State reason) { - this.updateStatus = true; - } - - @Override - public void onChunkUnloaded() { - this.disconnect(false); - super.onChunkUnloaded(); - } - - @Override - public void onReady() { - super.onReady(); - - var quantumRing = AEBlocks.QUANTUM_RING; - - if (this.getBlockState().getBlock() == quantumRing.block()) { - this.getMainNode().setVisualRepresentation(quantumRing.stack()); - } - - this.updateStatus = true; - } - - @Override - public void setRemoved() { - this.disconnect(false); - super.setRemoved(); - } - - @Override - public void disconnect(boolean affectWorld) { - if (this.cluster != null) { - if (!affectWorld) { - this.cluster.setUpdateStatus(false); - } - - this.cluster.destroy(); - } - - this.cluster = null; - - if (affectWorld) { - this.getMainNode().setExposedOnSides(EnumSet.noneOf(Direction.class)); - } - } - - @Override - public QuantumCluster getCluster() { - return this.cluster; - } - - @Override - public boolean isValid() { - return !this.isRemoved(); - } - - public void updateStatus(QuantumCluster c, byte flags, boolean affectWorld) { - this.cluster = c; - - if (affectWorld) { - if (this.constructed != flags) { - this.constructed = flags; - this.markForUpdate(); - } - - if (this.isCorner() || this.isCenter()) { - EnumSet sides = EnumSet.copyOf(this.getAdjacentQuantumBridges()); - this.getMainNode().setExposedOnSides(sides); - } else { - this.getMainNode().setExposedOnSides(EnumSet.allOf(Direction.class)); - } - } - } - - public boolean isCorner() { - return (this.constructed & this.getCorner()) == this.getCorner() && this.constructed != -1; - } - - public EnumSet getAdjacentQuantumBridges() { - final EnumSet set = EnumSet.noneOf(Direction.class); - - for (Direction d : Direction.values()) { - final BlockEntity te = this.level.getBlockEntity(this.worldPosition.relative(d)); - if (te instanceof QuantumBridgeBlockEntity) { - set.add(d); - } - } - - return set; - } - - public long getQEFrequency() { - final ItemStack is = this.internalInventory.getStackInSlot(0); - if (!is.isEmpty()) { - final CompoundTag c = is.getTag(); - if (c != null) { - return c.getLong("freq"); - } - } - return 0; - } - - public boolean isPowered() { - if (isClientSide()) { - return (this.constructed & this.powered) == this.powered && this.constructed != -1; - } - - var node = getMainNode().getNode(); - return node != null && node.isPowered(); - } - - public boolean isFormed() { - return this.constructed != -1; - } - - @Override - public AECableType getCableConnectionType(Direction dir) { - return AECableType.DENSE_SMART; - } - - public void neighborUpdate(BlockPos fromPos) { - if (level instanceof ServerLevel serverLevel) { - this.calc.updateMultiblockAfterNeighborUpdate(serverLevel, this.worldPosition, fromPos); - } - } - - public boolean hasQES() { - if (this.constructed == -1) { - return false; - } - return (this.constructed & this.hasSingularity) == this.hasSingularity; - } - - public void breakClusterOnRemove() { - if (this.cluster != null) { - // Prevents cluster.destroy() from changing the block state back to an unformed QNB, - // because that would undo the removal. - this.remove = true; - this.cluster.destroy(); - } - } - - public byte getCorner() { - return this.corner; - } - - @Override - public QnbFormedState getRenderAttachmentData() { - return new QnbFormedState(getAdjacentQuantumBridges(), isCorner(), isPowered()); - } - -} diff --git a/src/main/java/appeng/blockentity/spatial/SpatialAnchorBlockEntity.java b/src/main/java/appeng/blockentity/spatial/SpatialAnchorBlockEntity.java deleted file mode 100644 index 87bebddc95d..00000000000 --- a/src/main/java/appeng/blockentity/spatial/SpatialAnchorBlockEntity.java +++ /dev/null @@ -1,391 +0,0 @@ -/* - * This file is part of Applied Energistics 2. - * Copyright (c) 2021, 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.blockentity.spatial; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; -import java.util.stream.Collectors; - -import com.google.common.collect.Multiset; - -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.world.level.ChunkPos; -import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraft.world.level.block.entity.BlockEntityType; -import net.minecraft.world.level.block.state.BlockState; - -import appeng.api.config.Setting; -import appeng.api.config.Settings; -import appeng.api.config.YesNo; -import appeng.api.networking.GridFlags; -import appeng.api.networking.GridHelper; -import appeng.api.networking.IGridNode; -import appeng.api.networking.IGridNodeListener; -import appeng.api.networking.events.statistics.GridChunkEvent.GridChunkAdded; -import appeng.api.networking.events.statistics.GridChunkEvent.GridChunkRemoved; -import appeng.api.networking.ticking.IGridTickable; -import appeng.api.networking.ticking.TickRateModulation; -import appeng.api.networking.ticking.TickingRequest; -import appeng.api.util.AECableType; -import appeng.api.util.AEColor; -import appeng.api.util.DimensionalBlockPos; -import appeng.api.util.IConfigManager; -import appeng.api.util.IConfigurableObject; -import appeng.blockentity.grid.AENetworkBlockEntity; -import appeng.client.render.overlay.IOverlayDataSource; -import appeng.client.render.overlay.OverlayManager; -import appeng.me.service.StatisticsService; -import appeng.server.services.ChunkLoadingService; -import appeng.util.ConfigManager; -import appeng.util.IConfigManagerListener; - -public class SpatialAnchorBlockEntity extends AENetworkBlockEntity - implements IGridTickable, IConfigManagerListener, IConfigurableObject, IOverlayDataSource { - - static { - GridHelper.addNodeOwnerEventHandler(GridChunkAdded.class, SpatialAnchorBlockEntity.class, - SpatialAnchorBlockEntity::chunkAdded); - GridHelper.addNodeOwnerEventHandler(GridChunkRemoved.class, SpatialAnchorBlockEntity.class, - SpatialAnchorBlockEntity::chunkRemoved); - } - - /** - * Loads this radius after being move via a spatial transfer. This accounts for the anchor not being placed in the - * center of the SCS, but not as much as trying to fully load a 128 cubic cell with 8x8 chunks. This would need to - * load a 17x17 square. - */ - private static final int SPATIAL_TRANSFER_TEMPORARY_CHUNK_RANGE = 4; - - private final ConfigManager manager = new ConfigManager(this); - private final Set chunks = new HashSet<>(); - private int powerlessTicks = 0; - private boolean initialized = false; - private boolean displayOverlay = false; - private boolean isActive = false; - - public SpatialAnchorBlockEntity(BlockEntityType blockEntityType, BlockPos pos, BlockState blockState) { - super(blockEntityType, pos, blockState); - getMainNode().setFlags(GridFlags.REQUIRE_CHANNEL) - .addService(IGridTickable.class, this); - this.manager.registerSetting(Settings.OVERLAY_MODE, YesNo.NO); - } - - @Override - public void saveAdditional(CompoundTag data) { - super.saveAdditional(data); - this.manager.writeToNBT(data); - } - - @Override - public void loadTag(CompoundTag data) { - super.loadTag(data); - this.manager.readFromNBT(data); - } - - @Override - protected void writeToStream(FriendlyByteBuf data) { - super.writeToStream(data); - data.writeBoolean(this.isActive()); - data.writeBoolean(displayOverlay); - if (this.displayOverlay) { - data.writeLongArray(chunks.stream().mapToLong(ChunkPos::toLong).toArray()); - } - } - - @Override - protected boolean readFromStream(FriendlyByteBuf data) { - boolean ret = super.readFromStream(data); - - final boolean isActive = data.readBoolean(); - ret = isActive != this.isActive || ret; - this.isActive = isActive; - - boolean newDisplayOverlay = data.readBoolean(); - ret = newDisplayOverlay != this.displayOverlay || ret; - this.displayOverlay = newDisplayOverlay; - - // Cleanup old data and remove it from the overlay manager as safeguard - this.chunks.clear(); - OverlayManager.getInstance().removeHandlers(this); - - if (this.displayOverlay) { - this.chunks.addAll(Arrays.stream(data.readLongArray(null)).mapToObj(ChunkPos::new) - .collect(Collectors.toSet())); - // Register it again to render the overlay - OverlayManager.getInstance().showArea(this); - } - - return ret; - } - - @Override - public AECableType getCableConnectionType(Direction dir) { - return AECableType.SMART; - } - - @Override - public Set getOverlayChunks() { - return this.chunks; - } - - @Override - public BlockEntity getOverlayBlockEntity() { - return this; - } - - @Override - public DimensionalBlockPos getOverlaySourceLocation() { - return new DimensionalBlockPos(this); - } - - @Override - public int getOverlayColor() { - return 0x80000000 | AEColor.TRANSPARENT.mediumVariant; - } - - public void chunkAdded(GridChunkAdded changed) { - if (changed.getLevel() == this.getServerLevel()) { - this.force(changed.getChunkPos()); - } - } - - public void chunkRemoved(GridChunkRemoved changed) { - if (changed.getLevel() == this.getServerLevel()) { - this.release(changed.getChunkPos(), true); - // Need to wake up the anchor to potentially perform another cleanup - this.wakeUp(); - } - } - - @Override - public void onMainNodeStateChanged(IGridNodeListener.State reason) { - if (reason != IGridNodeListener.State.GRID_BOOT) { - this.markForUpdate(); - } - - this.wakeUp(); - } - - @Override - public void onSettingChanged(IConfigManager manager, Setting setting) { - if (setting == Settings.OVERLAY_MODE) { - this.displayOverlay = manager.getSetting(setting) == YesNo.YES; - this.markForUpdate(); - } - this.saveChanges(); - } - - @Override - public void setRemoved() { - super.setRemoved(); - if (isClientSide()) { - OverlayManager.getInstance().removeHandlers(this); - } else { - this.releaseAll(); - } - } - - @Override - public IConfigManager getConfigManager() { - return this.manager; - } - - private void wakeUp() { - // Wake the anchor to allow for unloading chunks some time after power loss - getMainNode().ifPresent((grid, node) -> { - grid.getTickManager().alertDevice(node); - }); - } - - @Override - public TickingRequest getTickingRequest(IGridNode node) { - return new TickingRequest(20, 20, false, true); - } - - @Override - public TickRateModulation tickingRequest(IGridNode node, int ticksSinceLastCall) { - // Initialize once the network is ready and there are no entries marked as loaded. - if (!this.initialized) { - if (!this.getMainNode().hasGridBooted()) { - // Wait for the end of pathing to give time for the network to load the first time... - return TickRateModulation.SAME; - } else { - this.initialized = true; - } - } - - this.cleanUp(); - - // Be a bit lenient to not unload all chunks immediately upon power loss - if (this.powerlessTicks > 200) { - if (!this.getMainNode().isOnline()) { - this.releaseAll(); - } - this.powerlessTicks = 0; - - // Put anchor to sleep until another power change. - return TickRateModulation.SLEEP; - } - - // Count ticks without power - if (!this.getMainNode().isOnline()) { - this.powerlessTicks += ticksSinceLastCall; - return TickRateModulation.SAME; - } - - // Default to sleep - return TickRateModulation.SLEEP; - } - - public Set getLoadedChunks() { - return this.chunks; - } - - public int countLoadedChunks() { - return this.chunks.size(); - } - - public boolean isActive() { - if (level != null && !level.isClientSide) { - return this.getMainNode().isOnline(); - } else { - return this.isActive; - } - } - - /** - * Used to restore loaded chunks from {@link ForgeChunkManager} - */ - public void registerChunk(ChunkPos chunkPos) { - this.chunks.add(chunkPos); - this.updatePowerConsumption(); - } - - private void updatePowerConsumption() { - if (isRemoved()) { - // Don't try to update the power usage if the node was already removed, or it will crash. - return; - } - int energy = 80 + this.chunks.size() * (this.chunks.size() + 1) / 2; - this.getMainNode().setIdlePowerUsage(energy); - } - - /** - * Performs a cleanup of the loaded chunks and adds missing ones as well as removes any chunk no longer part of the - * network. - */ - private void cleanUp() { - var grid = getMainNode().getGrid(); - if (grid == null) { - return; - } - - Multiset requiredChunks = grid.getService(StatisticsService.class).getChunks() - .get(this.getServerLevel()); - - // Release all chunks, which are no longer part of the network.s - for (Iterator iterator = chunks.iterator(); iterator.hasNext();) { - ChunkPos chunkPos = iterator.next(); - - if (!requiredChunks.contains(chunkPos)) { - this.release(chunkPos, false); - iterator.remove(); - } - } - - // Force missing chunks - for (ChunkPos chunkPos : requiredChunks) { - if (!this.chunks.contains(chunkPos)) { - this.force(chunkPos); - } - } - - } - - /** - * Adds the chunk to the current loaded list. - */ - private boolean force(ChunkPos chunkPos) { - // Avoid loading chunks after the anchor is destroyed - if (this.isRemoved()) { - return false; - } - - ServerLevel level = this.getServerLevel(); - boolean forced = ChunkLoadingService.getInstance().forceChunk(level, this.getBlockPos(), chunkPos, true); - - if (forced) { - this.chunks.add(chunkPos); - } - - this.updatePowerConsumption(); - this.markForUpdate(); - - return forced; - } - - private boolean release(ChunkPos chunkPos, boolean remove) { - ServerLevel level = this.getServerLevel(); - boolean removed = ChunkLoadingService.getInstance().releaseChunk(level, this.getBlockPos(), chunkPos, true); - - if (removed && remove) { - this.chunks.remove(chunkPos); - } - - this.updatePowerConsumption(); - this.markForUpdate(); - - return removed; - } - - void releaseAll() { - for (ChunkPos chunk : this.chunks) { - this.release(chunk, false); - } - this.chunks.clear(); - } - - private ServerLevel getServerLevel() { - if (this.getLevel() instanceof ServerLevel) { - return (ServerLevel) this.getLevel(); - } - throw new IllegalStateException("Cannot be called on a client"); - } - - void doneMoving() { - // reset the init state to keep the temporary loaded area until the network is ready. - this.initialized = false; - - // Temporarily load an area after a spatial transfer until the network is constructed and cleanup is performed. - int d = SPATIAL_TRANSFER_TEMPORARY_CHUNK_RANGE; - ChunkPos center = new ChunkPos(this.getBlockPos()); - for (int x = center.x - d; x <= center.x + d; x++) { - for (int z = center.z - d; z <= center.z + d; z++) { - this.force(new ChunkPos(x, z)); - } - } - - } -} diff --git a/src/main/java/appeng/blockentity/spatial/SpatialAnchorMoveStrategy.java b/src/main/java/appeng/blockentity/spatial/SpatialAnchorMoveStrategy.java deleted file mode 100644 index 969d18d09b5..00000000000 --- a/src/main/java/appeng/blockentity/spatial/SpatialAnchorMoveStrategy.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * This file is part of Applied Energistics 2. - * Copyright (c) 2021, 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.blockentity.spatial; - -import javax.annotation.Nullable; - -import net.minecraft.core.BlockPos; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraft.world.level.block.entity.BlockEntityType; - -import appeng.api.movable.DefaultBlockEntityMoveStrategy; -import appeng.core.definitions.AEBlockEntities; - -/** - * When the spatial anchor is moved into spatial storage, it should briefly chunkload the area within the spatial - * storage cell to allow the grid there to initialize. - */ -public class SpatialAnchorMoveStrategy extends DefaultBlockEntityMoveStrategy { - @Override - public boolean canHandle(BlockEntityType type) { - return type == AEBlockEntities.SPATIAL_ANCHOR; - } - - @Nullable - @Override - public CompoundTag beginMove(BlockEntity blockEntity) { - var result = super.beginMove(blockEntity); - if (result != null && blockEntity instanceof SpatialAnchorBlockEntity spatialAnchor) { - // Just in case there are still some chunks left, as the level will change. - spatialAnchor.releaseAll(); - } - return result; - } - - @Override - public boolean completeMove(BlockEntity blockEntity, CompoundTag savedData, Level newLevel, BlockPos newPosition) { - if (!super.completeMove(blockEntity, savedData, newLevel, newPosition)) { - return false; - } - // Notify the new block entity - if (newLevel.getBlockEntity(newPosition) instanceof SpatialAnchorBlockEntity spatialAnchor) { - spatialAnchor.doneMoving(); - } - return true; - } -} diff --git a/src/main/java/appeng/blockentity/spatial/SpatialIOPortBlockEntity.java b/src/main/java/appeng/blockentity/spatial/SpatialIOPortBlockEntity.java deleted file mode 100644 index 812dc4c881f..00000000000 --- a/src/main/java/appeng/blockentity/spatial/SpatialIOPortBlockEntity.java +++ /dev/null @@ -1,223 +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.blockentity.spatial; - -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.block.entity.BlockEntityType; -import net.minecraft.world.level.block.state.BlockState; - -import appeng.api.config.Actionable; -import appeng.api.config.PowerMultiplier; -import appeng.api.config.YesNo; -import appeng.api.implementations.items.ISpatialStorageCell; -import appeng.api.inventories.InternalInventory; -import appeng.api.networking.GridFlags; -import appeng.api.networking.IGridNodeListener; -import appeng.api.networking.events.GridSpatialEvent; -import appeng.api.util.AECableType; -import appeng.blockentity.grid.AENetworkInvBlockEntity; -import appeng.hooks.ticking.TickHandler; -import appeng.util.ILevelRunnable; -import appeng.util.inv.AppEngInternalInventory; -import appeng.util.inv.FilteredInternalInventory; -import appeng.util.inv.filter.IAEItemFilter; - -public class SpatialIOPortBlockEntity extends AENetworkInvBlockEntity { - - private final AppEngInternalInventory inv = new AppEngInternalInventory(this, 2); - private final InternalInventory invExt = new FilteredInternalInventory(this.inv, new SpatialIOFilter()); - private YesNo lastRedstoneState = YesNo.UNDECIDED; - - private final ILevelRunnable transitionCallback = level -> transition(); - - private boolean isActive = false; - - public SpatialIOPortBlockEntity(BlockEntityType blockEntityType, BlockPos pos, BlockState blockState) { - super(blockEntityType, pos, blockState); - this.getMainNode().setFlags(GridFlags.REQUIRE_CHANNEL); - } - - @Override - public void saveAdditional(CompoundTag data) { - super.saveAdditional(data); - data.putInt("lastRedstoneState", this.lastRedstoneState.ordinal()); - } - - @Override - public void loadTag(CompoundTag data) { - super.loadTag(data); - if (data.contains("lastRedstoneState")) { - this.lastRedstoneState = YesNo.values()[data.getInt("lastRedstoneState")]; - } - } - - @Override - protected void writeToStream(FriendlyByteBuf data) { - super.writeToStream(data); - data.writeBoolean(this.isActive()); - } - - @Override - protected boolean readFromStream(FriendlyByteBuf data) { - boolean ret = super.readFromStream(data); - - final boolean isActive = data.readBoolean(); - ret = isActive != this.isActive || ret; - this.isActive = isActive; - - return ret; - } - - public boolean getRedstoneState() { - if (this.lastRedstoneState == YesNo.UNDECIDED) { - this.updateRedstoneState(); - } - - return this.lastRedstoneState == YesNo.YES; - } - - public void updateRedstoneState() { - final YesNo currentState = this.level.getBestNeighborSignal(this.worldPosition) != 0 ? YesNo.YES : YesNo.NO; - if (this.lastRedstoneState != currentState) { - this.lastRedstoneState = currentState; - if (this.lastRedstoneState == YesNo.YES) { - this.triggerTransition(); - } - } - } - - public boolean isActive() { - if (level != null && !level.isClientSide) { - return this.getMainNode().isOnline(); - } else { - return this.isActive; - } - } - - @Override - public void onMainNodeStateChanged(IGridNodeListener.State reason) { - if (reason != IGridNodeListener.State.GRID_BOOT) { - this.markForUpdate(); - } - } - - private void triggerTransition() { - if (!isClientSide()) { - final ItemStack cell = this.inv.getStackInSlot(0); - if (this.isSpatialCell(cell)) { - // this needs to be cross world synced. - TickHandler.instance().addCallable(null, transitionCallback); - } - } - } - - private boolean isSpatialCell(ItemStack cell) { - if (!cell.isEmpty() && cell.getItem() instanceof ISpatialStorageCell sc) { - return sc.isSpatialStorage(cell); - } - return false; - } - - private void transition() { - if (!(this.level instanceof ServerLevel serverLevel)) { - return; - } - - final ItemStack cell = this.inv.getStackInSlot(0); - if (!this.isSpatialCell(cell) || !this.inv.getStackInSlot(1).isEmpty()) { - return; - } - - final ISpatialStorageCell sc = (ISpatialStorageCell) cell.getItem(); - - if (!getMainNode().isActive()) { - return; - } - - getMainNode().ifPresent((grid, node) -> { - var spc = grid.getSpatialService(); - if (!spc.hasRegion() || !spc.isValidRegion()) { - return; - } - - var energy = grid.getEnergyService(); - final double req = spc.requiredPower(); - final double pr = energy.extractAEPower(req, Actionable.SIMULATE, PowerMultiplier.CONFIG); - if (Math.abs(pr - req) < req * 0.001) { - var evt = grid.postEvent(new GridSpatialEvent(getLevel(), getBlockPos(), req)); - if (!evt.isTransitionPrevented()) { - // Prefer player id from security system, but if unavailable, use the - // player who placed the grid node (if any) - int playerId; - if (grid.getSecurityService().isAvailable()) { - playerId = grid.getSecurityService().getOwner(); - } else { - playerId = node.getOwningPlayerId(); - } - - boolean success = sc.doSpatialTransition(cell, serverLevel, spc.getMin(), spc.getMax(), - playerId); - if (success) { - energy.extractAEPower(req, Actionable.MODULATE, PowerMultiplier.CONFIG); - this.inv.setItemDirect(0, ItemStack.EMPTY); - this.inv.setItemDirect(1, cell); - } - } - } - }); - } - - @Override - public AECableType getCableConnectionType(Direction dir) { - return AECableType.SMART; - } - - @Override - public InternalInventory getExposedInventoryForSide(Direction side) { - return this.invExt; - } - - @Override - public InternalInventory getInternalInventory() { - return this.inv; - } - - @Override - public void onChangeInventory(InternalInventory inv, int slot) { - - } - - private class SpatialIOFilter implements IAEItemFilter { - @Override - public boolean allowExtract(InternalInventory inv, int slot, int amount) { - return slot == 1; - } - - @Override - public boolean allowInsert(InternalInventory inv, int slot, ItemStack stack) { - return slot == 0 && SpatialIOPortBlockEntity.this.isSpatialCell(stack); - } - - } -} diff --git a/src/main/java/appeng/blockentity/spatial/SpatialPylonBlockEntity.java b/src/main/java/appeng/blockentity/spatial/SpatialPylonBlockEntity.java deleted file mode 100644 index ab22a3a0c9b..00000000000 --- a/src/main/java/appeng/blockentity/spatial/SpatialPylonBlockEntity.java +++ /dev/null @@ -1,204 +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.blockentity.spatial; - -import java.util.EnumSet; -import java.util.Iterator; - -import com.google.common.collect.Iterators; - -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.world.level.block.entity.BlockEntityType; -import net.minecraft.world.level.block.state.BlockState; - -import appeng.api.networking.GridFlags; -import appeng.api.networking.IGridMultiblock; -import appeng.api.networking.IGridNode; -import appeng.api.networking.IGridNodeListener; -import appeng.blockentity.grid.AENetworkBlockEntity; -import appeng.me.cluster.IAEMultiBlock; -import appeng.me.cluster.implementations.SpatialPylonCalculator; -import appeng.me.cluster.implementations.SpatialPylonCluster; -import appeng.util.iterators.ChainedIterator; - -public class SpatialPylonBlockEntity extends AENetworkBlockEntity implements IAEMultiBlock { - - public static final int DISPLAY_END_MIN = 0x01; - public static final int DISPLAY_END_MAX = 0x02; - public static final int DISPLAY_MIDDLE = 0x01 + 0x02; - public static final int DISPLAY_X = 0x04; - public static final int DISPLAY_Y = 0x08; - public static final int DISPLAY_Z = 0x04 + 0x08; - public static final int MB_STATUS = 0x01 + 0x02 + 0x04 + 0x08; - - public static final int DISPLAY_ENABLED = 0x10; - public static final int DISPLAY_POWERED_ENABLED = 0x20; - public static final int NET_STATUS = 0x10 + 0x20; - - private final SpatialPylonCalculator calc = new SpatialPylonCalculator(this); - private int displayBits = 0; - private SpatialPylonCluster cluster; - - public SpatialPylonBlockEntity(BlockEntityType blockEntityType, BlockPos pos, BlockState blockState) { - super(blockEntityType, pos, blockState); - this.getMainNode().setFlags(GridFlags.REQUIRE_CHANNEL, GridFlags.MULTIBLOCK) - .setIdlePowerUsage(0.5) - .addService(IGridMultiblock.class, this::getMultiblockNodes); - } - - @Override - public void onChunkUnloaded() { - this.disconnect(false); - super.onChunkUnloaded(); - } - - @Override - public void onReady() { - super.onReady(); - if (level instanceof ServerLevel serverLevel) { - this.calc.calculateMultiblock(serverLevel, worldPosition); - } - } - - @Override - public void setRemoved() { - super.setRemoved(); - // Ensure that this block entity is marked as removed before we try to dismantle the cluster, to prevent updates - // to the block state. - this.disconnect(false); - } - - public void neighborChanged(BlockPos changedPos) { - if (level instanceof ServerLevel serverLevel) { - this.calc.updateMultiblockAfterNeighborUpdate(serverLevel, worldPosition, changedPos); - } - } - - @Override - public void disconnect(boolean b) { - if (this.cluster != null) { - this.cluster.destroy(); - this.updateStatus(null); - } - } - - @Override - public SpatialPylonCluster getCluster() { - return this.cluster; - } - - @Override - public boolean isValid() { - return true; - } - - public void updateStatus(SpatialPylonCluster c) { - if (this.isRemoved()) { - // Prevent updating the display, the block state or the node if the block entity was removed. - // Otherwise, setting the block state will restore the block we just destroyed. - // Trying to update the node just causes a crash because the node has been removed by now. - return; - } - - this.cluster = c; - this.getMainNode() - .setExposedOnSides(c == null ? EnumSet.noneOf(Direction.class) : EnumSet.allOf(Direction.class)); - this.recalculateDisplay(); - } - - public void recalculateDisplay() { - final int oldBits = this.displayBits; - - this.displayBits = 0; - - if (this.cluster != null) { - if (this.cluster.getBoundsMin().equals(this.worldPosition)) { - this.displayBits = DISPLAY_END_MIN; - } else if (this.cluster.getBoundsMax().equals(this.worldPosition)) { - this.displayBits = DISPLAY_END_MAX; - } else { - this.displayBits = DISPLAY_MIDDLE; - } - - switch (this.cluster.getCurrentAxis()) { - case X -> this.displayBits |= DISPLAY_X; - case Y -> this.displayBits |= DISPLAY_Y; - case Z -> this.displayBits |= DISPLAY_Z; - default -> this.displayBits = 0; - } - - if (this.getMainNode().isPowered()) { - this.displayBits |= DISPLAY_POWERED_ENABLED; - } - - if (this.cluster.isValid() && this.getMainNode().isOnline()) { - this.displayBits |= DISPLAY_ENABLED; - } - } - - if (oldBits != this.displayBits) { - this.markForUpdate(); - } - } - - @Override - public boolean canBeRotated() { - return false; - } - - @Override - protected boolean readFromStream(FriendlyByteBuf data) { - final boolean c = super.readFromStream(data); - final int old = this.displayBits; - this.displayBits = data.readByte(); - return old != this.displayBits || c; - } - - @Override - protected void writeToStream(FriendlyByteBuf data) { - super.writeToStream(data); - data.writeByte(this.displayBits); - } - - @Override - public void onMainNodeStateChanged(IGridNodeListener.State reason) { - if (reason != IGridNodeListener.State.GRID_BOOT) { - this.recalculateDisplay(); - } - } - - public int getDisplayBits() { - return this.displayBits; - } - - @Override - public Object getRenderAttachmentData() { - return getDisplayBits(); - } - - private Iterator getMultiblockNodes() { - if (this.getCluster() == null) { - return new ChainedIterator<>(); - } - return Iterators.transform(this.getCluster().getBlockEntities(), SpatialPylonBlockEntity::getGridNode); - } -} diff --git a/src/main/java/appeng/blockentity/storage/ChestBlockEntity.java b/src/main/java/appeng/blockentity/storage/ChestBlockEntity.java deleted file mode 100644 index a8e1e70aad5..00000000000 --- a/src/main/java/appeng/blockentity/storage/ChestBlockEntity.java +++ /dev/null @@ -1,714 +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.blockentity.storage; - -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.Objects; - -import javax.annotation.Nullable; - -import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant; -import net.fabricmc.fabric.api.transfer.v1.storage.Storage; -import net.fabricmc.fabric.api.transfer.v1.storage.StoragePreconditions; -import net.fabricmc.fabric.api.transfer.v1.storage.StorageView; -import net.fabricmc.fabric.api.transfer.v1.storage.base.BlankVariantView; -import net.fabricmc.fabric.api.transfer.v1.storage.base.InsertionOnlyStorage; -import net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext; -import net.fabricmc.fabric.api.transfer.v1.transaction.base.SnapshotParticipant; -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.Items; -import net.minecraft.world.level.block.entity.BlockEntityType; -import net.minecraft.world.level.block.state.BlockState; - -import appeng.api.config.AccessRestriction; -import appeng.api.config.Actionable; -import appeng.api.config.PowerMultiplier; -import appeng.api.config.SecurityPermissions; -import appeng.api.config.Settings; -import appeng.api.config.SortDir; -import appeng.api.config.SortOrder; -import appeng.api.config.TypeFilter; -import appeng.api.config.ViewItems; -import appeng.api.implementations.blockentities.IColorableBlockEntity; -import appeng.api.implementations.blockentities.IMEChest; -import appeng.api.inventories.InternalInventory; -import appeng.api.networking.GridFlags; -import appeng.api.networking.IGridNodeListener; -import appeng.api.networking.events.GridPowerStorageStateChanged; -import appeng.api.networking.events.GridPowerStorageStateChanged.PowerEventType; -import appeng.api.networking.security.IActionSource; -import appeng.api.stacks.AEFluidKey; -import appeng.api.stacks.AEItemKey; -import appeng.api.stacks.AEKey; -import appeng.api.stacks.GenericStack; -import appeng.api.storage.IStorageMonitorableAccessor; -import appeng.api.storage.IStorageMounts; -import appeng.api.storage.IStorageProvider; -import appeng.api.storage.ITerminalHost; -import appeng.api.storage.MEStorage; -import appeng.api.storage.StorageCells; -import appeng.api.storage.StorageHelper; -import appeng.api.storage.cells.CellState; -import appeng.api.storage.cells.ICellHandler; -import appeng.api.storage.cells.StorageCell; -import appeng.api.util.AEColor; -import appeng.api.util.IConfigManager; -import appeng.blockentity.ServerTickingBlockEntity; -import appeng.blockentity.grid.AENetworkPowerBlockEntity; -import appeng.core.definitions.AEBlocks; -import appeng.helpers.IPriorityHost; -import appeng.me.helpers.MachineSource; -import appeng.me.storage.DelegatingMEInventory; -import appeng.menu.ISubMenu; -import appeng.menu.MenuOpener; -import appeng.menu.implementations.ChestMenu; -import appeng.menu.locator.MenuLocators; -import appeng.util.ConfigManager; -import appeng.util.Platform; -import appeng.util.inv.AppEngInternalInventory; -import appeng.util.inv.CombinedInternalInventory; -import appeng.util.inv.filter.IAEItemFilter; - -public class ChestBlockEntity extends AENetworkPowerBlockEntity - implements IMEChest, ITerminalHost, IPriorityHost, IColorableBlockEntity, - ServerTickingBlockEntity, IStorageProvider { - - private static final int BIT_POWER_MASK = Byte.MIN_VALUE; - private static final int BIT_STATE_MASK = 0b111; - - private static final int BIT_CELL_STATE_MASK = 0b111; - private static final int BIT_CELL_STATE_BITS = 3; - - private final AppEngInternalInventory inputInventory = new AppEngInternalInventory(this, 1); - private final AppEngInternalInventory cellInventory = new AppEngInternalInventory(this, 1); - private final InternalInventory internalInventory = new CombinedInternalInventory(this.inputInventory, - this.cellInventory); - - private final IActionSource mySrc = new MachineSource(this); - private final IConfigManager config = new ConfigManager(this::saveChanges); - private int priority = 0; - private int state = 0; - private boolean wasOnline = false; - private AEColor paintedColor = AEColor.TRANSPARENT; - private boolean isCached = false; - private ChestMonitorHandler cellHandler; - private Accessor accessor; - private Storage fluidHandler; - // 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; - private double idlePowerUsage; - - public ChestBlockEntity(BlockEntityType blockEntityType, BlockPos pos, BlockState blockState) { - super(blockEntityType, pos, blockState); - this.setInternalMaxPower(PowerMultiplier.CONFIG.multiply(500)); - this.getMainNode() - .addService(IStorageProvider.class, this) - .setFlags(GridFlags.REQUIRE_CHANNEL); - this.config.registerSetting(Settings.SORT_BY, SortOrder.NAME); - this.config.registerSetting(Settings.VIEW_MODE, ViewItems.ALL); - this.config.registerSetting(Settings.TYPE_FILTER, TypeFilter.ALL); - this.config.registerSetting(Settings.SORT_DIRECTION, SortDir.ASCENDING); - - this.setInternalPublicPowerStorage(true); - this.setInternalPowerFlow(AccessRestriction.WRITE); - - this.inputInventory.setFilter(new InputInventoryFilter()); - this.cellInventory.setFilter(new CellInventoryFilter()); - } - - public ItemStack getCell() { - return this.cellInventory.getStackInSlot(0); - } - - public void setCell(ItemStack stack) { - this.cellInventory.setItemDirect(0, Objects.requireNonNull(stack)); - } - - @Override - protected void PowerEvent(PowerEventType x) { - if (x == PowerEventType.REQUEST_POWER) { - this.getMainNode().ifPresent( - grid -> grid.postEvent(new GridPowerStorageStateChanged(this, PowerEventType.REQUEST_POWER))); - } else { - this.recalculateDisplay(); - } - } - - private void recalculateDisplay() { - var oldState = this.state; - - var state = 0; - - for (int x = 0; x < this.getCellCount(); x++) { - state |= this.getCellStatus(x).ordinal() << BIT_CELL_STATE_BITS * x; - } - - if (this.isPowered()) { - state |= BIT_POWER_MASK; - } - - if (oldState != state) { - this.state = state; - this.markForUpdate(); - } - } - - @Override - public int getCellCount() { - return 1; - } - - private void updateHandler() { - if (!this.isCached) { - this.cellHandler = null; - this.accessor = null; - this.fluidHandler = null; - - var is = this.getCell(); - if (!is.isEmpty()) { - this.isCached = true; - var newCell = StorageCells.getCellInventory(is, this::onCellContentChanged); - if (newCell != null) { - idlePowerUsage = 1.0 + newCell.getIdleDrain(); - this.cellHandler = this.wrap(newCell); - - this.getMainNode().setIdlePowerUsage(idlePowerUsage); - this.accessor = new Accessor(); - - if (this.cellHandler != null) { - this.fluidHandler = new FluidHandler(); - } - } - } - } - } - - private ChestMonitorHandler wrap(StorageCell cellInventory) { - if (cellInventory == null) { - return null; - } - - return new ChestMonitorHandler(cellInventory, cellInventory); - } - - @Override - public CellState getCellStatus(int slot) { - if (isClientSide()) { - return CellState.values()[this.state >> slot * BIT_CELL_STATE_BITS & BIT_CELL_STATE_MASK]; - } - - this.updateHandler(); - - final ItemStack cell = this.getCell(); - final ICellHandler ch = StorageCells.getHandler(cell); - - if (this.cellHandler != null && ch != null) { - return this.cellHandler.cellInventory.getStatus(); - } - - return CellState.ABSENT; - } - - @Nullable - @Override - public Item getCellItem(int slot) { - if (slot != 0) { - return null; - } - // Client-side we'll need to actually use the synced state - if (level == null || level.isClientSide) { - return cellItem; - } - ItemStack cell = getCell(); - return cell.isEmpty() ? null : cell.getItem(); - } - - @Override - public boolean isPowered() { - if (isClientSide()) { - return (this.state & BIT_POWER_MASK) == BIT_POWER_MASK; - } - - boolean gridPowered = this.getAECurrentPower() > 64; - - if (!gridPowered) { - gridPowered = this.getMainNode().isPowered(); - } - - return super.getAECurrentPower() > 1 || gridPowered; - } - - @Override - public boolean isCellBlinking(int slot) { - return false; - } - - @Override - protected double extractAEPower(double amt, Actionable mode) { - double stash = 0.0; - - var grid = getMainNode().getGrid(); - if (grid != null) { - var eg = grid.getEnergyService(); - stash = eg.extractAEPower(amt, mode, PowerMultiplier.ONE); - if (stash >= amt) { - return stash; - } - } - - // local battery! - return super.extractAEPower(amt - stash, mode) + stash; - } - - @Override - public void serverTick() { - var grid = getMainNode().getGrid(); - if (grid != null) { - if (!grid.getEnergyService().isNetworkPowered()) { - final double powerUsed = this.extractAEPower(idlePowerUsage, Actionable.MODULATE, - PowerMultiplier.CONFIG); // drain - if (powerUsed + 0.1 >= idlePowerUsage != (this.state & BIT_POWER_MASK) > 0) { - this.recalculateDisplay(); - } - } - } else { - final double powerUsed = this.extractAEPower(idlePowerUsage, Actionable.MODULATE, PowerMultiplier.CONFIG); // drain - if (powerUsed + 0.1 >= idlePowerUsage != (this.state & BIT_POWER_MASK) > 0) { - this.recalculateDisplay(); - } - } - - if (!this.inputInventory.isEmpty()) { - this.tryToStoreContents(); - } - } - - @Override - protected void writeToStream(FriendlyByteBuf data) { - super.writeToStream(data); - - this.state = 0; - - for (int x = 0; x < this.getCellCount(); x++) { - this.state |= this.getCellStatus(x).ordinal() << 3 * x; - } - - if (this.isPowered()) { - this.state |= BIT_POWER_MASK; - } - - 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.writeVarInt(Item.getId(getCell().getItem())); - } - - @Override - protected boolean readFromStream(FriendlyByteBuf data) { - final boolean c = super.readFromStream(data); - - final int oldState = this.state; - - this.state = data.readByte(); - final AEColor oldPaintedColor = this.paintedColor; - this.paintedColor = AEColor.values()[data.readByte()]; - this.cellItem = Item.byId(data.readVarInt()); - - return oldPaintedColor != this.paintedColor || (this.state & 0xDB6DB6DB) != (oldState & 0xDB6DB6DB) || c; - } - - @Override - public void loadTag(CompoundTag data) { - super.loadTag(data); - this.config.readFromNBT(data); - this.priority = data.getInt("priority"); - if (data.contains("paintedColor")) { - this.paintedColor = AEColor.values()[data.getByte("paintedColor")]; - } - } - - @Override - public void saveAdditional(CompoundTag data) { - super.saveAdditional(data); - this.config.writeToNBT(data); - data.putInt("priority", this.priority); - data.putByte("paintedColor", (byte) this.paintedColor.ordinal()); - } - - @Override - public void onMainNodeStateChanged(IGridNodeListener.State reason) { - var currentOnline = this.getMainNode().isOnline(); - if (this.wasOnline != currentOnline) { - this.wasOnline = currentOnline; - IStorageProvider.requestUpdate(getMainNode()); - recalculateDisplay(); - } - } - - @Override - public MEStorage getInventory() { - this.updateHandler(); - - if (this.cellHandler != null) { - return this.cellHandler; - } - return null; - } - - @Override - public InternalInventory getInternalInventory() { - return this.internalInventory; - } - - @Override - public void onChangeInventory(InternalInventory inv, int slot) { - if (inv == this.cellInventory) { - this.cellHandler = null; - this.isCached = false; // recalculate the storage cell. - - IStorageProvider.requestUpdate(getMainNode()); - - // update the neighbors - if (this.level != null) { - Platform.notifyBlocksOfNeighbors(this.level, this.worldPosition); - this.markForUpdate(); - } - } - if (inv == this.inputInventory && !inv.getStackInSlot(slot).isEmpty()) { - this.tryToStoreContents(); - } - } - - @Override - public InternalInventory getExposedInventoryForSide(Direction side) { - if (side == this.getForward()) { - return this.cellInventory; - } else { - return this.inputInventory; - } - } - - private void tryToStoreContents() { - - if (!this.inputInventory.isEmpty()) { - this.updateHandler(); - - if (this.cellHandler != null) { - var stack = this.inputInventory.getStackInSlot(0); - if (stack.isEmpty()) { - return; - } - - var inserted = StorageHelper.poweredInsert(this, this.cellHandler, - AEItemKey.of(stack), stack.getCount(), this.mySrc); - - if (inserted >= stack.getCount()) { - this.inputInventory.setItemDirect(0, ItemStack.EMPTY); - } else { - stack.shrink((int) inserted); - this.inputInventory.setItemDirect(0, stack); - } - } - } - } - - @Override - public void mountInventories(IStorageMounts storageMounts) { - if (this.getMainNode().isOnline()) { - this.updateHandler(); - - if (this.cellHandler != null) { - storageMounts.mount(this.cellHandler, priority); - } - } - } - - @Override - public int getPriority() { - return this.priority; - } - - @Override - public void setPriority(int newValue) { - this.priority = newValue; - this.cellHandler = null; - this.isCached = false; // recalculate the storage cell. - - IStorageProvider.requestUpdate(getMainNode()); - } - - private void blinkCell(int slot) { - this.recalculateDisplay(); - } - - @Override - public IConfigManager getConfigManager() { - return this.config; - } - - public boolean openGui(Player p) { - this.updateHandler(); - if (this.cellHandler != null) { - var ch = StorageCells.getHandler(this.getCell()); - - if (ch != null) { - var chg = StorageCells.getGuiHandler(this.getCell()); - if (chg != null) { - chg.openChestGui(p, this, ch, this.getCell()); - return true; - } - } - } - - return false; - } - - @Override - public AEColor getColor() { - return this.paintedColor; - } - - @Override - public boolean recolourBlock(Direction side, AEColor newPaintedColor, Player who) { - if (this.paintedColor == newPaintedColor) { - return false; - } - - this.paintedColor = newPaintedColor; - this.saveChanges(); - this.markForUpdate(); - return true; - } - - private void onCellContentChanged() { - if (cellHandler != null) { - cellHandler.cellInventory.persist(); - } - this.level.blockEntityChanged(this.worldPosition); - } - - public void openCellInventoryMenu(Player player) { - MenuOpener.open(ChestMenu.TYPE, player, MenuLocators.forBlockEntity(this)); - } - - private class ChestMonitorHandler extends DelegatingMEInventory { - private final StorageCell cellInventory; - - public ChestMonitorHandler(MEStorage inventory, StorageCell cellInventory) { - super(inventory); - this.cellInventory = cellInventory; - } - - @Override - public long insert(AEKey what, long amount, Actionable mode, IActionSource source) { - if (source.player().map(player -> !this.securityCheck(player, SecurityPermissions.INJECT)).orElse(false)) { - return 0; - } - var inserted = super.insert(what, amount, mode, source); - if (inserted > 0 && mode == Actionable.MODULATE) { - blinkCell(0); - } - return inserted; - } - - private boolean securityCheck(Player player, SecurityPermissions requiredPermission) { - return Platform.checkPermissions(player, ChestBlockEntity.this, requiredPermission, false, false); - } - - @Override - public long extract(AEKey what, long amount, Actionable mode, IActionSource source) { - if (source.player().map(player -> !this.securityCheck(player, SecurityPermissions.EXTRACT)).orElse(false)) { - return 0; - } - var extracted = super.extract(what, amount, mode, source); - if (extracted > 0 && mode == Actionable.MODULATE) { - blinkCell(0); - } - return extracted; - } - } - - @Nullable - public Storage getFluidHandler(Direction side) { - if (side != getForward()) { - return fluidHandler; - } else { - return null; - } - } - - @Nullable - public IStorageMonitorableAccessor getMEHandler(Direction side) { - if (side != getForward()) { - return accessor; - } else { - return null; - } - } - - private class Accessor implements IStorageMonitorableAccessor { - @Nullable - @Override - public MEStorage getInventory(IActionSource src) { - if (Platform.canAccess(ChestBlockEntity.this.getMainNode(), src)) { - return ChestBlockEntity.this.getInventory(); - } - return null; - } - } - - private class FluidHandler extends SnapshotParticipant - implements InsertionOnlyStorage { - private GenericStack queuedInsert; - - /** - * If we accept fluids, simulate that we have an empty tank with 1 bucket capacity at all times. - */ - private final List> fakeInputTanks = Collections.singletonList( - new BlankVariantView<>(FluidVariant.blank(), AEFluidKey.AMOUNT_BUCKET)); - - private boolean canAcceptLiquids() { - return ChestBlockEntity.this.cellHandler != null; - } - - @Override - public long insert(FluidVariant resource, long maxAmount, TransactionContext transaction) { - StoragePreconditions.notBlankNotNegative(resource, maxAmount); - - if (queuedInsert != null) { - return 0; // Can only insert once per action - } - - ChestBlockEntity.this.updateHandler(); - if (canAcceptLiquids()) { - var what = AEFluidKey.of(resource); - var inserted = pushToNetwork(what, maxAmount, Actionable.SIMULATE); - if (inserted > 0) { - updateSnapshots(transaction); - queuedInsert = new GenericStack(what, inserted); - } - return inserted; - } - return 0; - } - - @Override - public Iterator> iterator() { - if (canAcceptLiquids()) { - return fakeInputTanks.iterator(); - } else { - return Collections.emptyIterator(); - } - } - - @Override - protected final Boolean createSnapshot() { - // Null snapshots are not allowed even though this is what we really want, so we just use Boolean instead. - return Boolean.TRUE; - } - - @Override - protected final void readSnapshot(Boolean snapshot) { - queuedInsert = null; - } - - @Override - protected final void onFinalCommit() { - pushToNetwork(queuedInsert.what(), queuedInsert.amount(), Actionable.MODULATE); - queuedInsert = null; - } - - private long pushToNetwork(AEKey what, long amount, Actionable mode) { - ChestBlockEntity.this.updateHandler(); - if (canAcceptLiquids()) { - return StorageHelper.poweredInsert( - ChestBlockEntity.this, - ChestBlockEntity.this.cellHandler, - what, - amount, - ChestBlockEntity.this.mySrc, - mode); - } - return 0; - } - } - - private class InputInventoryFilter implements IAEItemFilter { - @Override - public boolean allowExtract(InternalInventory inv, int slot, int amount) { - return false; - } - - @Override - public boolean allowInsert(InternalInventory inv, int slot, ItemStack stack) { - if (isPowered()) { - updateHandler(); - if (cellHandler == null) { - return false; - } - - var what = AEItemKey.of(stack); - if (what == null) { - return false; - } - - return cellHandler.insert(what, stack.getCount(), Actionable.SIMULATE, mySrc) > 0; - } - return false; - } - } - - private static class CellInventoryFilter implements IAEItemFilter { - - @Override - public boolean allowExtract(InternalInventory inv, int slot, int amount) { - return true; - } - - @Override - public boolean allowInsert(InternalInventory inv, int slot, ItemStack stack) { - return StorageCells.getHandler(stack) != null; - } - - } - - @Override - public ItemStack getMainMenuIcon() { - return AEBlocks.CHEST.stack(); - } - - @Override - public void returnToMainMenu(Player player, ISubMenu subMenu) { - MenuOpener.returnTo(ChestMenu.TYPE, player, MenuLocators.forBlockEntity(this)); - } -} diff --git a/src/main/java/appeng/blockentity/storage/DriveBlockEntity.java b/src/main/java/appeng/blockentity/storage/DriveBlockEntity.java deleted file mode 100644 index 81c4ff0a79b..00000000000 --- a/src/main/java/appeng/blockentity/storage/DriveBlockEntity.java +++ /dev/null @@ -1,439 +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.blockentity.storage; - -import java.util.Arrays; -import java.util.EnumSet; -import java.util.Locale; - -import javax.annotation.Nullable; - -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.core.Registry; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.Tag; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.Items; -import net.minecraft.world.level.block.entity.BlockEntityType; -import net.minecraft.world.level.block.state.BlockState; - -import appeng.api.implementations.blockentities.IChestOrDrive; -import appeng.api.inventories.InternalInventory; -import appeng.api.networking.GridFlags; -import appeng.api.networking.IGridNodeListener; -import appeng.api.storage.IStorageMounts; -import appeng.api.storage.IStorageProvider; -import appeng.api.storage.StorageCells; -import appeng.api.storage.cells.CellState; -import appeng.api.util.AECableType; -import appeng.blockentity.grid.AENetworkInvBlockEntity; -import appeng.blockentity.inventory.AppEngCellInventory; -import appeng.client.render.model.DriveModelData; -import appeng.core.AELog; -import appeng.core.definitions.AEBlocks; -import appeng.helpers.IPriorityHost; -import appeng.me.storage.DriveWatcher; -import appeng.menu.ISubMenu; -import appeng.menu.MenuOpener; -import appeng.menu.implementations.DriveMenu; -import appeng.menu.locator.MenuLocators; -import appeng.util.inv.filter.IAEItemFilter; - -public class DriveBlockEntity extends AENetworkInvBlockEntity - implements IChestOrDrive, IPriorityHost, IStorageProvider { - - private final AppEngCellInventory inv = new AppEngCellInventory(this, getCellCount()); - private final DriveWatcher[] invBySlot = new DriveWatcher[getCellCount()]; - private boolean isCached = false; - private int priority = 0; - private boolean wasOnline = false; - // This is only used on the client - private final Item[] clientSideCellItems = new Item[getCellCount()]; - private final CellState[] clientSideCellState = new CellState[getCellCount()]; - private boolean clientSideOnline; - - public DriveBlockEntity(BlockEntityType blockEntityType, BlockPos pos, BlockState blockState) { - super(blockEntityType, pos, blockState); - this.getMainNode() - .addService(IStorageProvider.class, this) - .setFlags(GridFlags.REQUIRE_CHANNEL); - this.inv.setFilter(new CellValidInventoryFilter()); - - Arrays.fill(clientSideCellState, CellState.ABSENT); - } - - @Override - public void setOrientation(Direction inForward, Direction inUp) { - super.setOrientation(inForward, inUp); - this.getMainNode().setExposedOnSides(EnumSet.complementOf(EnumSet.of(inForward))); - } - - @Override - protected void writeToStream(FriendlyByteBuf data) { - super.writeToStream(data); - updateClientSideState(); - - // Pack the enums into an int of 3 bit per cell state, using 30 bits total - int packedState = 0; - for (int i = 0; i < getCellCount(); i++) { - packedState |= clientSideCellState[i].ordinal() << (i * 3); - } - // Then pack the online state into bit 31 - if (clientSideOnline) { - packedState |= 1 << 31; - } - data.writeInt(packedState); - - for (int i = 0; i < getCellCount(); i++) { - data.writeVarInt(Registry.ITEM.getId(getCellItem(i))); - } - } - - @Override - protected void saveVisualState(CompoundTag data) { - super.saveVisualState(data); - - data.putBoolean("online", isPowered()); - - for (int i = 0; i < getCellCount(); i++) { - var cellItem = getCellItem(i); - if (cellItem != null) { - var cellData = new CompoundTag(); - cellData.putString("id", Registry.ITEM.getKey(cellItem).toString()); - - var cellState = getCellStatus(i); - cellData.putString("state", cellState.name().toLowerCase(Locale.ROOT)); - data.put("cell" + i, cellData); - } - } - } - - @Override - protected boolean readFromStream(FriendlyByteBuf data) { - var changed = super.readFromStream(data); - - var packedState = data.readInt(); - for (int i = 0; i < getCellCount(); i++) { - var cellStateOrdinal = (packedState >> (i * 3)) & 0b111; - var cellState = CellState.values()[cellStateOrdinal]; - if (clientSideCellState[i] != cellState) { - clientSideCellState[i] = cellState; - changed = true; - } - } - - var online = (packedState & (1 << 31)) != 0; - if (clientSideOnline != online) { - clientSideOnline = online; - changed = true; - } - - for (int i = 0; i < getCellCount(); i++) { - var itemId = data.readVarInt(); - Item item = itemId == 0 ? null : Registry.ITEM.byId(itemId); - if (itemId != 0 && item == Items.AIR) { - AELog.warn("Received unknown item id from server for disk drive %s: %d", this, itemId); - } - if (clientSideCellItems[i] != item) { - clientSideCellItems[i] = item; - changed = true; - } - } - - return changed; - } - - @Override - protected void loadVisualState(CompoundTag data) { - super.loadVisualState(data); - - clientSideOnline = data.getBoolean("online"); - - for (int i = 0; i < getCellCount(); i++) { - this.clientSideCellItems[i] = null; - this.clientSideCellState[i] = CellState.ABSENT; - - var tagName = "cell" + i; - if (data.contains(tagName, Tag.TAG_COMPOUND)) { - var cellData = data.getCompound(tagName); - var id = new ResourceLocation(cellData.getString("id")); - var cellStateName = cellData.getString("state"); - - clientSideCellItems[i] = Registry.ITEM.getOptional(id).orElse(null); - try { - clientSideCellState[i] = CellState.valueOf(cellStateName.toUpperCase(Locale.ROOT)); - } catch (IllegalArgumentException e) { - AELog.warn("Cannot parse cell state for cell %d: %s", i, cellStateName); - } - } - } - } - - @Override - public int getCellCount() { - return 10; - } - - @Nullable - @Override - public Item getCellItem(int slot) { - // Client-side we'll need to actually use the synced state - if (level == null || level.isClientSide) { - return clientSideCellItems[slot]; - } - - ItemStack stackInSlot = inv.getStackInSlot(slot); - if (!stackInSlot.isEmpty()) { - return stackInSlot.getItem(); - } - return null; - } - - @Override - public CellState getCellStatus(int slot) { - if (isClientSide()) { - return this.clientSideCellState[slot]; - } - - var handler = this.invBySlot[slot]; - if (handler == null) { - return CellState.ABSENT; - } - - return handler.getStatus(); - } - - @Override - public boolean isPowered() { - if (isClientSide()) { - return clientSideOnline; - } - - return this.getMainNode().isOnline(); - } - - @Override - public boolean isCellBlinking(int slot) { - return false; - } - - @Override - public void loadTag(CompoundTag data) { - super.loadTag(data); - this.isCached = false; - this.priority = data.getInt("priority"); - } - - @Override - public void saveAdditional(CompoundTag data) { - super.saveAdditional(data); - data.putInt("priority", this.priority); - } - - private void updateVisualStateIfNeeded() { - if (updateClientSideState()) { - this.markForUpdate(); - } - } - - private boolean updateClientSideState() { - if (isClientSide()) { - return false; - } - - updateState(); // refresh cells - - var changed = false; - var online = getMainNode().isOnline(); - if (online != this.clientSideOnline) { - this.clientSideOnline = online; - changed = true; - } - - for (int x = 0; x < this.getCellCount(); x++) { - var cellItem = getCellItem(x); - if (cellItem != this.clientSideCellItems[x]) { - this.clientSideCellItems[x] = cellItem; - changed = true; - } - - var cellState = this.getCellStatus(x); - if (cellState != this.clientSideCellState[x]) { - this.clientSideCellState[x] = cellState; - changed = true; - } - } - return changed; - } - - @Override - public void onMainNodeStateChanged(IGridNodeListener.State reason) { - var currentOnline = getMainNode().isOnline(); - if (this.wasOnline != currentOnline) { - this.wasOnline = currentOnline; - IStorageProvider.requestUpdate(getMainNode()); - updateVisualStateIfNeeded(); - } - } - - @Override - public AECableType getCableConnectionType(Direction dir) { - return AECableType.SMART; - } - - @Override - public InternalInventory getInternalInventory() { - return this.inv; - } - - @Override - public void onChangeInventory(InternalInventory inv, int slot) { - if (this.isCached) { - this.isCached = false; // recalculate the storage cell. - this.updateState(); - } - - IStorageProvider.requestUpdate(getMainNode()); - - this.markForUpdate(); - } - - private void updateState() { - if (!this.isCached) { - double power = 2.0; - for (int slot = 0; slot < this.inv.size(); slot++) { - power += updateStateForSlot(slot); - } - this.getMainNode().setIdlePowerUsage(power); - - this.isCached = true; - } - } - - // Returns idle power draw of slot - private double updateStateForSlot(int slot) { - this.invBySlot[slot] = null; - this.inv.setHandler(slot, null); - - var is = this.inv.getStackInSlot(slot); - if (!is.isEmpty()) { - var cell = StorageCells.getCellInventory(is, this::onCellContentChanged); - - if (cell != null) { - this.inv.setHandler(slot, cell); - - var driveWatcher = new DriveWatcher(cell, () -> blinkCell(slot)); - this.invBySlot[slot] = driveWatcher; - - return cell.getIdleDrain(); - } - } - - return 0; - } - - @Override - public void onReady() { - super.onReady(); - this.updateState(); - } - - @Override - public void mountInventories(IStorageMounts storageMounts) { - if (this.getMainNode().isOnline()) { - this.updateState(); - for (var inventory : this.invBySlot) { - if (inventory != null) { - storageMounts.mount(inventory, priority); - } - } - } - } - - @Override - public int getPriority() { - return this.priority; - } - - @Override - public void setPriority(int newValue) { - this.priority = newValue; - this.saveChanges(); - - this.isCached = false; // recalculate the storage cell. - this.updateState(); - - IStorageProvider.requestUpdate(getMainNode()); - } - - private void blinkCell(int slot) { - this.updateVisualStateIfNeeded(); - } - - /** - * When the content of a storage cell changes, we need to persist it. But instead of taking the performance hit of - * serializing it to NBT right away, we just queue up a save for the entire BE. As part of saving the BE, the cell - * will then be serialized to NBT. - */ - private void onCellContentChanged() { - this.level.blockEntityChanged(this.worldPosition); - } - - private static class CellValidInventoryFilter implements IAEItemFilter { - - @Override - public boolean allowExtract(InternalInventory inv, int slot, int amount) { - return true; - } - - @Override - public boolean allowInsert(InternalInventory inv, int slot, ItemStack stack) { - return !stack.isEmpty() && StorageCells.isCellHandled(stack); - } - - } - - @Override - public DriveModelData getRenderAttachmentData() { - var cells = new Item[getCellCount()]; - for (int i = 0; i < getCellCount(); i++) { - cells[i] = getCellItem(i); - } - return new DriveModelData(getUp(), getForward(), cells); - } - - public void openMenu(Player player) { - MenuOpener.open(DriveMenu.TYPE, player, MenuLocators.forBlockEntity(this)); - } - - @Override - public void returnToMainMenu(Player player, ISubMenu subMenu) { - MenuOpener.returnTo(DriveMenu.TYPE, player, MenuLocators.forBlockEntity(this)); - } - - @Override - public ItemStack getMainMenuIcon() { - return AEBlocks.DRIVE.stack(); - } -} diff --git a/src/main/java/appeng/blockentity/storage/IOPortBlockEntity.java b/src/main/java/appeng/blockentity/storage/IOPortBlockEntity.java deleted file mode 100644 index bc62057b046..00000000000 --- a/src/main/java/appeng/blockentity/storage/IOPortBlockEntity.java +++ /dev/null @@ -1,401 +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.blockentity.storage; - -import java.util.List; - -import javax.annotation.Nullable; - -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.entity.BlockEntityType; -import net.minecraft.world.level.block.state.BlockState; - -import appeng.api.config.Actionable; -import appeng.api.config.FullnessMode; -import appeng.api.config.OperationMode; -import appeng.api.config.RedstoneMode; -import appeng.api.config.Settings; -import appeng.api.config.YesNo; -import appeng.api.inventories.ISegmentedInventory; -import appeng.api.inventories.InternalInventory; -import appeng.api.networking.GridFlags; -import appeng.api.networking.IGrid; -import appeng.api.networking.IGridNode; -import appeng.api.networking.IGridNodeListener; -import appeng.api.networking.security.IActionSource; -import appeng.api.networking.ticking.IGridTickable; -import appeng.api.networking.ticking.TickRateModulation; -import appeng.api.networking.ticking.TickingRequest; -import appeng.api.stacks.KeyCounter; -import appeng.api.storage.MEStorage; -import appeng.api.storage.StorageCells; -import appeng.api.storage.StorageHelper; -import appeng.api.storage.cells.CellState; -import appeng.api.storage.cells.StorageCell; -import appeng.api.upgrades.IUpgradeInventory; -import appeng.api.upgrades.IUpgradeableObject; -import appeng.api.upgrades.UpgradeInventories; -import appeng.api.util.AECableType; -import appeng.api.util.IConfigManager; -import appeng.api.util.IConfigurableObject; -import appeng.blockentity.grid.AENetworkInvBlockEntity; -import appeng.core.definitions.AEBlocks; -import appeng.core.definitions.AEItems; -import appeng.core.settings.TickRates; -import appeng.me.helpers.MachineSource; -import appeng.util.ConfigManager; -import appeng.util.inv.AppEngInternalInventory; -import appeng.util.inv.CombinedInternalInventory; -import appeng.util.inv.FilteredInternalInventory; -import appeng.util.inv.filter.AEItemFilters; - -public class IOPortBlockEntity extends AENetworkInvBlockEntity - implements IUpgradeableObject, IConfigurableObject, IGridTickable { - private static final int NUMBER_OF_CELL_SLOTS = 6; - private static final int NUMBER_OF_UPGRADE_SLOTS = 3; - - private final ConfigManager manager; - - private final AppEngInternalInventory inputCells = new AppEngInternalInventory(this, NUMBER_OF_CELL_SLOTS); - private final AppEngInternalInventory outputCells = new AppEngInternalInventory(this, NUMBER_OF_CELL_SLOTS); - private final InternalInventory combinedInventory = new CombinedInternalInventory(this.inputCells, - this.outputCells); - - private final InternalInventory inputCellsExt = new FilteredInternalInventory(this.inputCells, - AEItemFilters.INSERT_ONLY); - private final InternalInventory outputCellsExt = new FilteredInternalInventory(this.outputCells, - AEItemFilters.EXTRACT_ONLY); - - private final IUpgradeInventory upgrades; - private final IActionSource mySrc; - private YesNo lastRedstoneState; - - private boolean isActive = false; - - public IOPortBlockEntity(BlockEntityType blockEntityType, BlockPos pos, BlockState blockState) { - super(blockEntityType, pos, blockState); - this.getMainNode() - .setFlags(GridFlags.REQUIRE_CHANNEL) - .addService(IGridTickable.class, this); - this.manager = new ConfigManager(this::updateTask); - this.manager.registerSetting(Settings.REDSTONE_CONTROLLED, RedstoneMode.IGNORE); - this.manager.registerSetting(Settings.FULLNESS_MODE, FullnessMode.EMPTY); - this.manager.registerSetting(Settings.OPERATION_MODE, OperationMode.EMPTY); - this.mySrc = new MachineSource(this); - this.lastRedstoneState = YesNo.UNDECIDED; - - this.upgrades = UpgradeInventories.forMachine(AEBlocks.IO_PORT, NUMBER_OF_UPGRADE_SLOTS, this::saveChanges); - } - - @Override - public void saveAdditional(CompoundTag data) { - super.saveAdditional(data); - this.manager.writeToNBT(data); - this.upgrades.writeToNBT(data, "upgrades"); - data.putInt("lastRedstoneState", this.lastRedstoneState.ordinal()); - } - - @Override - public void loadTag(CompoundTag data) { - super.loadTag(data); - this.manager.readFromNBT(data); - this.upgrades.readFromNBT(data, "upgrades"); - if (data.contains("lastRedstoneState")) { - this.lastRedstoneState = YesNo.values()[data.getInt("lastRedstoneState")]; - } - } - - @Override - protected void writeToStream(FriendlyByteBuf data) { - super.writeToStream(data); - data.writeBoolean(this.isActive()); - } - - @Override - protected boolean readFromStream(FriendlyByteBuf data) { - boolean ret = super.readFromStream(data); - - final boolean isActive = data.readBoolean(); - ret = isActive != this.isActive || ret; - this.isActive = isActive; - - return ret; - } - - @Override - public AECableType getCableConnectionType(Direction dir) { - return AECableType.SMART; - } - - private void updateTask() { - getMainNode().ifPresent((grid, node) -> { - if (this.hasWork()) { - grid.getTickManager().wakeDevice(node); - } else { - grid.getTickManager().sleepDevice(node); - } - }); - } - - public void updateRedstoneState() { - final YesNo currentState = this.level.getBestNeighborSignal(this.worldPosition) != 0 ? YesNo.YES : YesNo.NO; - if (this.lastRedstoneState != currentState) { - this.lastRedstoneState = currentState; - this.updateTask(); - } - } - - private boolean getRedstoneState() { - if (this.lastRedstoneState == YesNo.UNDECIDED) { - this.updateRedstoneState(); - } - - return this.lastRedstoneState == YesNo.YES; - } - - private boolean isEnabled() { - if (!upgrades.isInstalled(AEItems.REDSTONE_CARD)) { - return true; - } - - final RedstoneMode rs = this.manager.getSetting(Settings.REDSTONE_CONTROLLED); - if (rs == RedstoneMode.HIGH_SIGNAL) { - return this.getRedstoneState(); - } - return !this.getRedstoneState(); - } - - public boolean isActive() { - if (level != null && !level.isClientSide) { - return this.getMainNode().isOnline(); - } else { - return this.isActive; - } - } - - @Override - public void onMainNodeStateChanged(IGridNodeListener.State reason) { - if (reason != IGridNodeListener.State.GRID_BOOT) { - this.markForUpdate(); - } - } - - @Override - public IConfigManager getConfigManager() { - return this.manager; - } - - @Override - public IUpgradeInventory getUpgrades() { - return this.upgrades; - } - - @Nullable - @Override - public InternalInventory getSubInventory(ResourceLocation id) { - if (id.equals(ISegmentedInventory.UPGRADES)) { - return this.upgrades; - } else if (id.equals(ISegmentedInventory.CELLS)) { - return this.combinedInventory; - } else { - return super.getSubInventory(id); - } - } - - private boolean hasWork() { - if (this.isEnabled()) { - - return !this.inputCells.isEmpty(); - } - - return false; - } - - @Override - public InternalInventory getInternalInventory() { - return this.combinedInventory; - } - - @Override - public void onChangeInventory(InternalInventory inv, int slot) { - if (this.inputCells == inv) { - this.updateTask(); - } - } - - @Override - public InternalInventory getExposedInventoryForSide(Direction facing) { - if (facing == this.getUp() || facing == this.getUp().getOpposite()) { - return this.inputCellsExt; - } else { - return this.outputCellsExt; - } - } - - @Override - public TickingRequest getTickingRequest(IGridNode node) { - return new TickingRequest(TickRates.IOPort, !this.hasWork(), false); - } - - @Override - public TickRateModulation tickingRequest(IGridNode node, int ticksSinceLastCall) { - if (!this.getMainNode().isActive()) { - return TickRateModulation.IDLE; - } - - TickRateModulation ret = TickRateModulation.SLEEP; - long itemsToMove = 256; - - switch (upgrades.getInstalledUpgrades(AEItems.SPEED_CARD)) { - case 1 -> itemsToMove *= 2; - case 2 -> itemsToMove *= 4; - case 3 -> itemsToMove *= 8; - } - - var grid = getMainNode().getGrid(); - if (grid == null) { - return TickRateModulation.IDLE; - } - - for (int x = 0; x < NUMBER_OF_CELL_SLOTS; x++) { - var cell = this.inputCells.getStackInSlot(x); - - var cellInv = StorageCells.getCellInventory(cell, null); - - if (cellInv == null) { - // This item is not a valid storage cell, try to move it to the output - moveSlot(x); - continue; - } - - if (itemsToMove > 0) { - itemsToMove = transferContents(grid, cellInv, itemsToMove); - - if (itemsToMove > 0) { - ret = TickRateModulation.IDLE; - } else { - ret = TickRateModulation.URGENT; - } - } - - if (itemsToMove > 0 && matchesFullnessMode(cellInv) && this.moveSlot(x)) { - ret = TickRateModulation.URGENT; - } - } - - return ret; - } - - /** - * Work is complete when the inventory has reached the desired end-state. - */ - public boolean matchesFullnessMode(StorageCell inv) { - return switch (manager.getSetting(Settings.FULLNESS_MODE)) { - // In this mode, work completes as soon as no more items are moved within one operation, - // independent of the actual inventory state - case HALF -> true; - case EMPTY -> inv.getStatus() == CellState.EMPTY; - case FULL -> inv.getStatus() == CellState.FULL; - }; - } - - private long transferContents(IGrid grid, StorageCell cellInv, long itemsToMove) { - - var networkInv = grid.getStorageService().getInventory(); - - KeyCounter srcList; - MEStorage src, destination; - if (this.manager.getSetting(Settings.OPERATION_MODE) == OperationMode.EMPTY) { - src = cellInv; - srcList = cellInv.getAvailableStacks(); - destination = networkInv; - } else { - src = networkInv; - srcList = grid.getStorageService().getCachedInventory(); - destination = cellInv; - } - - var energy = grid.getEnergyService(); - boolean didStuff; - - do { - didStuff = false; - - for (var srcEntry : srcList) { - var totalStackSize = srcEntry.getLongValue(); - if (totalStackSize > 0) { - var what = srcEntry.getKey(); - var possible = destination.insert(what, totalStackSize, Actionable.SIMULATE, this.mySrc); - - if (possible > 0) { - possible = Math.min(possible, itemsToMove * what.getAmountPerOperation()); - - possible = src.extract(what, possible, Actionable.MODULATE, this.mySrc); - if (possible > 0) { - var inserted = StorageHelper.poweredInsert(energy, destination, what, possible, this.mySrc); - - if (inserted < possible) { - src.insert(what, possible - inserted, Actionable.MODULATE, this.mySrc); - } - - if (inserted > 0) { - itemsToMove -= Math.max(1, inserted / what.getAmountPerOperation()); - didStuff = true; - } - - break; - } - } - } - } - } while (itemsToMove > 0 && didStuff); - - return itemsToMove; - } - - private boolean moveSlot(int x) { - if (this.outputCells.addItems(this.inputCells.getStackInSlot(x)).isEmpty()) { - this.inputCells.setItemDirect(x, ItemStack.EMPTY); - return true; - } - return false; - } - - /** - * Adds the items in the upgrade slots to the drop list. - * - * @param level level - * @param pos pos of block entity - * @param drops drops of block entity - */ - @Override - public void addAdditionalDrops(Level level, BlockPos pos, List drops) { - super.addAdditionalDrops(level, pos, drops); - - for (var upgrade : upgrades) { - drops.add(upgrade); - } - } -} diff --git a/src/main/java/appeng/blockentity/storage/SkyChestBlockEntity.java b/src/main/java/appeng/blockentity/storage/SkyChestBlockEntity.java deleted file mode 100644 index e98f36b8db5..00000000000 --- a/src/main/java/appeng/blockentity/storage/SkyChestBlockEntity.java +++ /dev/null @@ -1,226 +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.blockentity.storage; - -import static net.minecraft.world.level.block.entity.RandomizableContainerBlockEntity.LOOT_TABLE_SEED_TAG; -import static net.minecraft.world.level.block.entity.RandomizableContainerBlockEntity.LOOT_TABLE_TAG; - -import java.util.List; - -import javax.annotation.Nullable; - -import net.fabricmc.api.EnvType; -import net.fabricmc.api.EnvironmentInterface; -import net.minecraft.advancements.CriteriaTriggers; -import net.minecraft.core.BlockPos; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.Tag; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.sounds.SoundEvent; -import net.minecraft.sounds.SoundEvents; -import net.minecraft.sounds.SoundSource; -import net.minecraft.world.InteractionResult; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.entity.BlockEntityType; -import net.minecraft.world.level.block.entity.ChestLidController; -import net.minecraft.world.level.block.entity.ContainerOpenersCounter; -import net.minecraft.world.level.block.entity.LidBlockEntity; -import net.minecraft.world.level.block.entity.RandomizableContainerBlockEntity; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.storage.loot.LootContext; -import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets; -import net.minecraft.world.level.storage.loot.parameters.LootContextParams; -import net.minecraft.world.phys.BlockHitResult; -import net.minecraft.world.phys.Vec3; - -import appeng.api.inventories.InternalInventory; -import appeng.blockentity.AEBaseInvBlockEntity; -import appeng.blockentity.ClientTickingBlockEntity; -import appeng.menu.implementations.SkyChestMenu; -import appeng.util.inv.AppEngInternalInventory; - -@SuppressWarnings("JavadocReference") -@EnvironmentInterface(value = EnvType.CLIENT, itf = LidBlockEntity.class) -public class SkyChestBlockEntity extends AEBaseInvBlockEntity implements ClientTickingBlockEntity, LidBlockEntity { - - private final AppEngInternalInventory inv = new AppEngInternalInventory(this, 9 * 4); - - private final ChestLidController chestLidController = new ChestLidController(); - - // This reimplements RandomizableContainerBlockEntity, because we cannot inherit from it here - @Nullable - protected ResourceLocation lootTable; - protected long lootTableSeed; - - private final ContainerOpenersCounter openersCounter = new ContainerOpenersCounter() { - protected void onOpen(Level level, BlockPos pos, BlockState state) { - playSound(level, pos, SoundEvents.CHEST_OPEN); - } - - protected void onClose(Level level, BlockPos pos, BlockState state) { - playSound(level, pos, SoundEvents.CHEST_CLOSE); - } - - private void playSound(Level level, BlockPos pos, SoundEvent event) { - var x = pos.getX() + 0.5D; - var y = pos.getY() + 0.5D; - var z = pos.getZ() + 0.5D; - level.playSound(null, x, y, z, event, SoundSource.BLOCKS, - 0.5F, level.random.nextFloat() * 0.1F + 0.9F); - } - - protected void openerCountChanged(Level level, BlockPos pos, BlockState state, int p_155364_, int x) { - level.blockEvent(pos, state.getBlock(), 1, x); - } - - protected boolean isOwnContainer(Player player) { - if (player.containerMenu instanceof SkyChestMenu menu) { - return menu.getChest() == SkyChestBlockEntity.this; - } else { - return false; - } - } - }; - - public SkyChestBlockEntity(BlockEntityType type, BlockPos pos, - BlockState blockState) { - super(type, pos, blockState); - } - - @Override - public InternalInventory getInternalInventory() { - return this.inv; - } - - public void startOpen(Player player) { - if (!this.remove && !player.isSpectator()) { - this.openersCounter.incrementOpeners(player, this.getLevel(), this.getBlockPos(), this.getBlockState()); - } - } - - public void stopOpen(Player player) { - if (!this.remove && !player.isSpectator()) { - this.openersCounter.decrementOpeners(player, this.getLevel(), this.getBlockPos(), this.getBlockState()); - } - } - - @Override - public void clientTick() { - chestLidController.tickLid(); - } - - public boolean triggerEvent(int id, int type) { - if (id == 1) { - this.chestLidController.shouldBeOpen(type > 0); - return true; - } else { - return super.triggerEvent(id, type); - } - } - - @Override - public void onChangeInventory(InternalInventory inv, int slot) { - - } - - @Override - public float getOpenNess(float partialTicks) { - return this.chestLidController.getOpenness(partialTicks); - } - - public void recheckOpen() { - if (!this.remove) { - this.openersCounter.recheckOpeners(this.getLevel(), this.getBlockPos(), this.getBlockState()); - } - } - - /** - * @see RandomizableContainerBlockEntity#tryLoadLootTable(CompoundTag) - */ - @Override - public void loadTag(CompoundTag data) { - super.loadTag(data); - - if (data.contains(LOOT_TABLE_TAG, Tag.TAG_STRING)) { - this.lootTable = new ResourceLocation(data.getString(LOOT_TABLE_TAG)); - this.lootTableSeed = data.getLong(LOOT_TABLE_SEED_TAG); - } - } - - /** - * @see RandomizableContainerBlockEntity#trySaveLootTable(CompoundTag) - */ - @Override - public void saveAdditional(CompoundTag data) { - super.saveAdditional(data); - - if (this.lootTable != null) { - data.putString(LOOT_TABLE_TAG, this.lootTable.toString()); - if (this.lootTableSeed != 0L) { - data.putLong(LOOT_TABLE_SEED_TAG, this.lootTableSeed); - } - } - } - - /** - * @see RandomizableContainerBlockEntity#unpackLootTable(Player) - */ - public void unpackLootTable(@Nullable Player openingPlayer) { - if (this.lootTable != null && this.level instanceof ServerLevel serverLevel) { - var loottable = serverLevel.getServer().getLootTables().get(this.lootTable); - if (openingPlayer instanceof ServerPlayer serverPlayer) { - CriteriaTriggers.GENERATE_LOOT.trigger(serverPlayer, this.lootTable); - } - - this.lootTable = null; // Can only generate once - var lootBuilder = new LootContext.Builder(serverLevel) - .withParameter(LootContextParams.ORIGIN, Vec3.atCenterOf(this.worldPosition)) - .withOptionalRandomSeed(this.lootTableSeed); - if (openingPlayer != null) { - lootBuilder.withLuck(openingPlayer.getLuck()) - .withParameter(LootContextParams.THIS_ENTITY, openingPlayer); - } - - loottable.fill(this.inv.toContainer(), lootBuilder.create(LootContextParamSets.CHEST)); - } - } - - /** - * @see RandomizableContainerBlockEntity#setLootTable(ResourceLocation, long) - */ - public void setLootTable(ResourceLocation lootTable, long lootTableSeed) { - this.lootTable = lootTable; - this.lootTableSeed = lootTableSeed; - } - - @Override - public void addAdditionalDrops(Level level, BlockPos pos, List drops) { - unpackLootTable(null); - super.addAdditionalDrops(level, pos, drops); - } - - @Override - public InteractionResult disassembleWithWrench(Player player, Level level, BlockHitResult hitResult) { - return InteractionResult.FAIL; - } -} diff --git a/src/main/java/appeng/blockentity/storage/SkyStoneTankBlockEntity.java b/src/main/java/appeng/blockentity/storage/SkyStoneTankBlockEntity.java deleted file mode 100644 index b0be373c88f..00000000000 --- a/src/main/java/appeng/blockentity/storage/SkyStoneTankBlockEntity.java +++ /dev/null @@ -1,85 +0,0 @@ -package appeng.blockentity.storage; - -import net.fabricmc.fabric.api.transfer.v1.fluid.FluidConstants; -import net.fabricmc.fabric.api.transfer.v1.fluid.FluidStorageUtil; -import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant; -import net.fabricmc.fabric.api.transfer.v1.storage.Storage; -import net.fabricmc.fabric.api.transfer.v1.storage.base.SingleVariantStorage; -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.world.InteractionHand; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.level.block.entity.BlockEntityType; -import net.minecraft.world.level.block.state.BlockState; - -import appeng.blockentity.AEBaseBlockEntity; - -public class SkyStoneTankBlockEntity extends AEBaseBlockEntity { - - public static final int BUCKET_CAPACITY = 16; - - private final SingleVariantStorage storage = new SingleVariantStorage<>() { - - @Override - protected FluidVariant getBlankVariant() { - return FluidVariant.blank(); - } - - @Override - protected long getCapacity(FluidVariant variant) { - return FluidConstants.BUCKET * BUCKET_CAPACITY; - } - - @Override - protected void onFinalCommit() { - SkyStoneTankBlockEntity.this.markForUpdate(); - SkyStoneTankBlockEntity.this.setChanged(); - } - }; - - public SkyStoneTankBlockEntity(BlockEntityType blockEntityType, BlockPos pos, BlockState blockState) { - super(blockEntityType, pos, blockState); - } - - @Override - public void saveAdditional(CompoundTag data) { - super.saveAdditional(data); - data.put("variant", storage.variant.toNbt()); - data.putLong("amount", storage.amount); - } - - @Override - public void loadTag(CompoundTag data) { - super.loadTag(data); - storage.variant = FluidVariant.fromNbt(data.getCompound("variant")); - storage.amount = data.getLong("amount"); - } - - public boolean onPlayerUse(Player player, InteractionHand hand) { - return FluidStorageUtil.interactWithFluidStorage(storage, player, hand); - } - - public Storage getStorage(Direction direction) { - return storage; - } - - public SingleVariantStorage getStorage() { - return storage; - } - - protected boolean readFromStream(FriendlyByteBuf data) { - boolean ret = super.readFromStream(data); - storage.amount = data.readLong(); - storage.variant = FluidVariant.fromNbt(data.readNbt()); - return ret; - } - - protected void writeToStream(FriendlyByteBuf data) { - super.writeToStream(data); - data.writeLong(storage.amount); - data.writeNbt(storage.getResource().toNbt()); - - } -} diff --git a/src/main/java/appeng/client/commands/ClientCommands.java b/src/main/java/appeng/client/commands/ClientCommands.java index 2603f173ec3..6bd314df269 100644 --- a/src/main/java/appeng/client/commands/ClientCommands.java +++ b/src/main/java/appeng/client/commands/ClientCommands.java @@ -9,13 +9,11 @@ import net.minecraft.network.chat.Component; import appeng.core.AEConfig; -import appeng.siteexport.SiteExporter; public final class ClientCommands { public static final List DEBUG_COMMANDS = List.of( - ClientCommands::highlightGuiAreas, - ClientCommands::exportSiteData); + ClientCommands::highlightGuiAreas); private ClientCommands() { } @@ -25,12 +23,6 @@ public interface CommandBuilder { void build(LiteralArgumentBuilder builder); } - private static void exportSiteData(LiteralArgumentBuilder builder) { - builder.then(ClientCommandManager.literal("export_site_data").executes(context -> { - SiteExporter.export(context.getSource()); - return 0; - })); - } private static void highlightGuiAreas(LiteralArgumentBuilder builder) { builder.then(ClientCommandManager.literal("highlight_gui_areas").executes(context -> { diff --git a/src/main/java/appeng/client/gui/DashedRectangle.java b/src/main/java/appeng/client/gui/DashedRectangle.java deleted file mode 100644 index 6cbe4a3ebd5..00000000000 --- a/src/main/java/appeng/client/gui/DashedRectangle.java +++ /dev/null @@ -1,90 +0,0 @@ -package appeng.client.gui; - -import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.vertex.BufferBuilder; -import com.mojang.blaze3d.vertex.DefaultVertexFormat; -import com.mojang.blaze3d.vertex.PoseStack; -import com.mojang.blaze3d.vertex.Tesselator; -import com.mojang.blaze3d.vertex.VertexFormat; - -import net.minecraft.client.renderer.GameRenderer; -import net.minecraft.util.Mth; - -import appeng.client.guidebook.document.LytRect; - -/** - * Rendering helper for rendering a rectangle with a dashed outline. - */ -public final class DashedRectangle { - private DashedRectangle() { - } - - public static void render(PoseStack stack, LytRect bounds, DashPattern pattern, float z) { - - RenderSystem.disableTexture(); - RenderSystem.enableBlend(); - RenderSystem.defaultBlendFunc(); - RenderSystem.setShader(GameRenderer::getPositionColorShader); - Tesselator tesselator = Tesselator.getInstance(); - BufferBuilder builder = tesselator.getBuilder(); - builder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR); - - var t = 0f; - if (pattern.animationCycleMs() > 0) { - t = (System.currentTimeMillis() % (int) pattern.animationCycleMs()) / pattern.animationCycleMs(); - } - - buildHorizontalDashedLine(builder, stack, t, bounds.x(), bounds.right(), bounds.y(), z, pattern, false); - buildHorizontalDashedLine(builder, stack, t, bounds.x(), bounds.right(), bounds.bottom() - pattern.width(), z, - pattern, true); - - buildVerticalDashedLine(builder, stack, t, bounds.x(), bounds.y(), bounds.bottom(), z, pattern, true); - buildVerticalDashedLine(builder, stack, t, bounds.right() - pattern.width(), bounds.y(), bounds.bottom(), z, - pattern, false); - - tesselator.end(); - RenderSystem.disableBlend(); - RenderSystem.enableTexture(); - } - - private static void buildHorizontalDashedLine(BufferBuilder builder, PoseStack stack, - float t, float x1, float x2, float y, float z, - DashPattern pattern, boolean reverse) { - if (!reverse) { - t = 1 - t; - } - var phase = t * pattern.length(); - - var pose = stack.last().pose(); - var color = pattern.color(); - - for (float x = x1 - phase; x < x2; x += pattern.length()) { - builder.vertex(pose, Mth.clamp(x + pattern.onLength(), x1, x2), y, z).color(color).endVertex(); - builder.vertex(pose, Mth.clamp(x, x1, x2), y, z).color(color).endVertex(); - builder.vertex(pose, Mth.clamp(x, x1, x2), y + pattern.width(), z).color(color).endVertex(); - builder.vertex(pose, Mth.clamp(x + pattern.onLength(), x1, x2), y + pattern.width(), z).color(color) - .endVertex(); - } - } - - private static void buildVerticalDashedLine(BufferBuilder builder, PoseStack stack, - float t, float x, float y1, float y2, float z, - DashPattern pattern, boolean reverse) { - if (!reverse) { - t = 1 - t; - } - var phase = t * pattern.length(); - - var pose = stack.last().pose(); - var color = pattern.color(); - - for (float y = y1 - phase; y < y2; y += pattern.length()) { - builder.vertex(pose, x + pattern.width(), Mth.clamp(y, y1, y2), z).color(color).endVertex(); - builder.vertex(pose, x, Mth.clamp(y, y1, y2), z).color(color).endVertex(); - builder.vertex(pose, x, Mth.clamp(y + pattern.onLength(), y1, y2), z).color(color).endVertex(); - builder.vertex(pose, x + pattern.width(), Mth.clamp(y + pattern.onLength(), y1, y2), z).color(color) - .endVertex(); - } - } - -} diff --git a/src/main/java/appeng/client/gui/Icon.java b/src/main/java/appeng/client/gui/Icon.java index 9795f608fcc..fe01abd5265 100644 --- a/src/main/java/appeng/client/gui/Icon.java +++ b/src/main/java/appeng/client/gui/Icon.java @@ -53,9 +53,6 @@ public enum Icon { BLOCKING_MODE_YES(80, 16), TRANSPARENT_FACADES_OFF(96, 16), TRANSPARENT_FACADES_ON(112, 16), - TYPE_FILTER_ITEMS(128, 16), - TYPE_FILTER_FLUIDS(144, 16), - TYPE_FILTER_ALL(160, 16), BACKGROUND_ORE(240, 16), // ROW 2 @@ -116,7 +113,6 @@ public enum Icon { FUZZY_PERCENT_99(48, 96), FUZZY_IGNORE(64, 96), FIND_CONTAINED_FLUID(80, 96), - BACKGROUND_WIRELESS_BOOSTER(240, 96), // ROW 7 CONDENSER_OUTPUT_TRASH(0, 112), @@ -140,15 +136,6 @@ public enum Icon { ACCESS_READ_WRITE(32, 144), BACKGROUND_CHARGABLE(240, 144), - // ROW 10 - POWER_UNIT_AE(0, 160), - POWER_UNIT_EU(16, 160), - POWER_UNIT_J(32, 160), - POWER_UNIT_W(48, 160), - POWER_UNIT_RF(64, 160), - POWER_UNIT_TR(80, 160), - BACKGROUND_SINGULARITY(240, 160), - // ROW 11 PERMISSION_INJECT(0, 176), PERMISSION_EXTRACT(16, 176), diff --git a/src/main/java/appeng/client/gui/NumberEntryType.java b/src/main/java/appeng/client/gui/NumberEntryType.java index af55fbd4757..9b8f3d82ec4 100644 --- a/src/main/java/appeng/client/gui/NumberEntryType.java +++ b/src/main/java/appeng/client/gui/NumberEntryType.java @@ -20,11 +20,9 @@ import javax.annotation.Nullable; -import appeng.api.config.PowerUnits; import appeng.api.stacks.AEKey; public record NumberEntryType(int amountPerUnit, @Nullable String unit) { - public static final NumberEntryType ENERGY = new NumberEntryType(1, PowerUnits.AE.getSymbolName()); public static final NumberEntryType UNITLESS = new NumberEntryType(1, null); public static NumberEntryType of(@Nullable AEKey key) { diff --git a/src/main/java/appeng/client/gui/implementations/CellWorkbenchScreen.java b/src/main/java/appeng/client/gui/implementations/CellWorkbenchScreen.java deleted file mode 100644 index 6b96ef34563..00000000000 --- a/src/main/java/appeng/client/gui/implementations/CellWorkbenchScreen.java +++ /dev/null @@ -1,71 +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.client.gui.implementations; - -import net.minecraft.network.chat.Component; -import net.minecraft.world.entity.player.Inventory; - -import appeng.api.config.ActionItems; -import appeng.api.config.CopyMode; -import appeng.api.config.FuzzyMode; -import appeng.api.config.Settings; -import appeng.client.gui.Icon; -import appeng.client.gui.style.ScreenStyle; -import appeng.client.gui.widgets.ActionButton; -import appeng.client.gui.widgets.SettingToggleButton; -import appeng.client.gui.widgets.ToggleButton; -import appeng.core.definitions.AEItems; -import appeng.core.localization.GuiText; -import appeng.menu.implementations.CellWorkbenchMenu; - -public class CellWorkbenchScreen extends UpgradeableScreen { - - private final ToggleButton copyMode; - - private final SettingToggleButton fuzzyMode; - - public CellWorkbenchScreen(CellWorkbenchMenu menu, Inventory playerInventory, - Component title, ScreenStyle style) { - super(menu, playerInventory, title, style); - - this.fuzzyMode = addToLeftToolbar( - new SettingToggleButton<>(Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL, this::toggleFuzzyMode)); - this.addToLeftToolbar(new ActionButton(ActionItems.WRENCH, act -> menu.partition())); - this.addToLeftToolbar(new ActionButton(ActionItems.CLOSE, act -> menu.clear())); - this.copyMode = this.addToLeftToolbar(new ToggleButton(Icon.COPY_MODE_ON, Icon.COPY_MODE_OFF, - GuiText.CopyMode.text(), GuiText.CopyModeDesc.text(), act -> menu.nextWorkBenchCopyMode())); - } - - @Override - protected void updateBeforeRender() { - super.updateBeforeRender(); - - this.copyMode.setState(this.menu.getCopyMode() == CopyMode.CLEAR_ON_REMOVE); - - boolean hasFuzzy = menu.getUpgrades().isInstalled(AEItems.FUZZY_CARD); - this.fuzzyMode.set(menu.getFuzzyMode()); - this.fuzzyMode.setVisibility(hasFuzzy); - } - - private void toggleFuzzyMode(SettingToggleButton button, boolean backwards) { - var fz = button.getNextValue(backwards); - menu.setCellFuzzyMode(fz); - } - -} diff --git a/src/main/java/appeng/client/gui/implementations/ChestScreen.java b/src/main/java/appeng/client/gui/implementations/ChestScreen.java deleted file mode 100644 index 2ab5ffc43d1..00000000000 --- a/src/main/java/appeng/client/gui/implementations/ChestScreen.java +++ /dev/null @@ -1,47 +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.client.gui.implementations; - -import net.minecraft.network.chat.Component; -import net.minecraft.world.entity.player.Inventory; - -import appeng.client.gui.AEBaseScreen; -import appeng.client.gui.style.ScreenStyle; -import appeng.menu.implementations.ChestMenu; - -public class ChestScreen extends AEBaseScreen { - - public ChestScreen(ChestMenu menu, Inventory playerInventory, Component title, - ScreenStyle style) { - super(menu, playerInventory, title, style); - - widgets.addOpenPriorityButton(); - } - - @Override - protected void updateBeforeRender() { - super.updateBeforeRender(); - - // Show a custom name for the ME Chest on the screen - if (!this.title.getString().isEmpty()) { - setTextContent(TEXT_ID_DIALOG_TITLE, this.title); - } - } - -} diff --git a/src/main/java/appeng/client/gui/implementations/CondenserScreen.java b/src/main/java/appeng/client/gui/implementations/CondenserScreen.java deleted file mode 100644 index f49bb2a9470..00000000000 --- a/src/main/java/appeng/client/gui/implementations/CondenserScreen.java +++ /dev/null @@ -1,56 +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.client.gui.implementations; - -import net.minecraft.network.chat.Component; -import net.minecraft.world.entity.player.Inventory; - -import appeng.api.config.CondenserOutput; -import appeng.api.config.Settings; -import appeng.client.gui.AEBaseScreen; -import appeng.client.gui.style.ScreenStyle; -import appeng.client.gui.widgets.ProgressBar; -import appeng.client.gui.widgets.ProgressBar.Direction; -import appeng.client.gui.widgets.ServerSettingToggleButton; -import appeng.client.gui.widgets.SettingToggleButton; -import appeng.core.localization.GuiText; -import appeng.menu.implementations.CondenserMenu; - -public class CondenserScreen extends AEBaseScreen { - - private final SettingToggleButton mode; - - public CondenserScreen(CondenserMenu menu, Inventory playerInventory, Component title, - ScreenStyle style) { - super(menu, playerInventory, title, style); - - this.mode = new ServerSettingToggleButton<>(Settings.CONDENSER_OUTPUT, this.menu.getOutput()); - widgets.add("mode", this.mode); - widgets.add("progressBar", new ProgressBar(this.menu, style.getImage("progressBar"), - Direction.VERTICAL, GuiText.StoredEnergy.text())); - } - - @Override - protected void updateBeforeRender() { - super.updateBeforeRender(); - - this.mode.set(this.menu.getOutput()); - } - -} diff --git a/src/main/java/appeng/client/gui/implementations/DriveScreen.java b/src/main/java/appeng/client/gui/implementations/DriveScreen.java deleted file mode 100644 index e72bba236bb..00000000000 --- a/src/main/java/appeng/client/gui/implementations/DriveScreen.java +++ /dev/null @@ -1,37 +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.client.gui.implementations; - -import net.minecraft.network.chat.Component; -import net.minecraft.world.entity.player.Inventory; - -import appeng.client.gui.AEBaseScreen; -import appeng.client.gui.style.ScreenStyle; -import appeng.menu.implementations.DriveMenu; - -public class DriveScreen extends AEBaseScreen { - - public DriveScreen(DriveMenu menu, Inventory playerInventory, Component title, - ScreenStyle style) { - super(menu, playerInventory, title, style); - - widgets.addOpenPriorityButton(); - } - -} diff --git a/src/main/java/appeng/client/gui/implementations/EnergyLevelEmitterScreen.java b/src/main/java/appeng/client/gui/implementations/EnergyLevelEmitterScreen.java deleted file mode 100644 index 6f8fdb8fda0..00000000000 --- a/src/main/java/appeng/client/gui/implementations/EnergyLevelEmitterScreen.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * This file is part of Applied Energistics 2. - * Copyright (c) 2021, 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.client.gui.implementations; - -import net.minecraft.network.chat.Component; -import net.minecraft.world.entity.player.Inventory; - -import appeng.api.config.RedstoneMode; -import appeng.api.config.Settings; -import appeng.client.gui.NumberEntryType; -import appeng.client.gui.style.ScreenStyle; -import appeng.client.gui.widgets.NumberEntryWidget; -import appeng.client.gui.widgets.ServerSettingToggleButton; -import appeng.client.gui.widgets.SettingToggleButton; -import appeng.menu.implementations.EnergyLevelEmitterMenu; - -public class EnergyLevelEmitterScreen extends UpgradeableScreen { - - private final SettingToggleButton redstoneMode; - private final NumberEntryWidget level; - - public EnergyLevelEmitterScreen(EnergyLevelEmitterMenu menu, Inventory playerInventory, Component title, - ScreenStyle style) { - super(menu, playerInventory, title, style); - - this.redstoneMode = new ServerSettingToggleButton<>( - Settings.REDSTONE_EMITTER, RedstoneMode.LOW_SIGNAL); - this.addToLeftToolbar(this.redstoneMode); - - this.level = widgets.addNumberEntryWidget("level", NumberEntryType.ENERGY); - this.level.setTextFieldStyle(style.getWidget("levelInput")); - this.level.setLongValue(menu.getReportingValue()); - this.level.setOnChange(this::saveReportingValue); - this.level.setOnConfirm(this::onClose); - } - - @Override - protected void updateBeforeRender() { - super.updateBeforeRender(); - - this.redstoneMode.active = true; - this.redstoneMode.set(menu.getRedStoneMode()); - } - - private void saveReportingValue() { - this.level.getLongValue().ifPresent(menu::setReportingValue); - } - -} diff --git a/src/main/java/appeng/client/gui/implementations/FormationPlaneScreen.java b/src/main/java/appeng/client/gui/implementations/FormationPlaneScreen.java deleted file mode 100644 index 07035519f40..00000000000 --- a/src/main/java/appeng/client/gui/implementations/FormationPlaneScreen.java +++ /dev/null @@ -1,61 +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.client.gui.implementations; - -import net.minecraft.network.chat.Component; -import net.minecraft.world.entity.player.Inventory; - -import appeng.api.config.FuzzyMode; -import appeng.api.config.Settings; -import appeng.api.config.YesNo; -import appeng.client.gui.style.ScreenStyle; -import appeng.client.gui.widgets.ServerSettingToggleButton; -import appeng.client.gui.widgets.SettingToggleButton; -import appeng.menu.implementations.FormationPlaneMenu; - -public class FormationPlaneScreen extends UpgradeableScreen { - - private final SettingToggleButton fuzzyMode; - private final SettingToggleButton placeMode; - - public FormationPlaneScreen(FormationPlaneMenu menu, Inventory playerInventory, - Component title, ScreenStyle style) { - super(menu, playerInventory, title, style); - - this.placeMode = new ServerSettingToggleButton<>(Settings.PLACE_BLOCK, - YesNo.YES); - this.addToLeftToolbar(this.placeMode); - this.fuzzyMode = new ServerSettingToggleButton<>(Settings.FUZZY_MODE, - FuzzyMode.IGNORE_ALL); - this.addToLeftToolbar(this.fuzzyMode); - - widgets.addOpenPriorityButton(); - } - - @Override - protected void updateBeforeRender() { - super.updateBeforeRender(); - - this.fuzzyMode.set(this.menu.getFuzzyMode()); - this.fuzzyMode.setVisibility(menu.supportsFuzzyMode()); - this.placeMode.set(this.menu.getPlaceMode()); - this.placeMode.setVisibility(menu.supportsPlaceMode()); - } - -} diff --git a/src/main/java/appeng/client/gui/implementations/IOBusScreen.java b/src/main/java/appeng/client/gui/implementations/IOBusScreen.java deleted file mode 100644 index cff91d4618c..00000000000 --- a/src/main/java/appeng/client/gui/implementations/IOBusScreen.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * This file is part of Applied Energistics 2. - * Copyright (c) 2021, 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.client.gui.implementations; - -import net.minecraft.network.chat.Component; -import net.minecraft.world.entity.player.Inventory; - -import appeng.api.config.FuzzyMode; -import appeng.api.config.RedstoneMode; -import appeng.api.config.SchedulingMode; -import appeng.api.config.Settings; -import appeng.api.config.YesNo; -import appeng.client.gui.style.ScreenStyle; -import appeng.client.gui.widgets.ServerSettingToggleButton; -import appeng.client.gui.widgets.SettingToggleButton; -import appeng.core.definitions.AEItems; -import appeng.menu.implementations.IOBusMenu; - -public class IOBusScreen extends UpgradeableScreen { - - private final SettingToggleButton redstoneMode; - private final SettingToggleButton fuzzyMode; - private final SettingToggleButton craftMode; - private final SettingToggleButton schedulingMode; - - public IOBusScreen(IOBusMenu menu, Inventory playerInventory, Component title, - ScreenStyle style) { - super(menu, playerInventory, title, style); - - this.redstoneMode = new ServerSettingToggleButton<>(Settings.REDSTONE_CONTROLLED, RedstoneMode.IGNORE); - addToLeftToolbar(this.redstoneMode); - this.fuzzyMode = new ServerSettingToggleButton<>(Settings.FUZZY_MODE, - FuzzyMode.IGNORE_ALL); - addToLeftToolbar(this.fuzzyMode); - - if (menu.getHost().getConfigManager().hasSetting(Settings.CRAFT_ONLY)) { - this.craftMode = new ServerSettingToggleButton<>(Settings.CRAFT_ONLY, YesNo.NO); - addToLeftToolbar(this.craftMode); - } else { - this.craftMode = null; - } - - if (menu.getHost().getConfigManager().hasSetting(Settings.SCHEDULING_MODE)) { - this.schedulingMode = new ServerSettingToggleButton<>(Settings.SCHEDULING_MODE, SchedulingMode.DEFAULT); - addToLeftToolbar(this.schedulingMode); - } else { - this.schedulingMode = null; - } - } - - @Override - protected void updateBeforeRender() { - super.updateBeforeRender(); - - this.redstoneMode.set(menu.getRedStoneMode()); - this.redstoneMode.setVisibility(menu.hasUpgrade(AEItems.REDSTONE_CARD)); - this.fuzzyMode.set(menu.getFuzzyMode()); - this.fuzzyMode.setVisibility(menu.hasUpgrade(AEItems.FUZZY_CARD)); - if (this.craftMode != null) { - this.craftMode.set(menu.getCraftingMode()); - this.craftMode.setVisibility(menu.hasUpgrade(AEItems.CRAFTING_CARD)); - } - if (this.schedulingMode != null) { - this.schedulingMode.set(menu.getSchedulingMode()); - this.schedulingMode.setVisibility(menu.hasUpgrade(AEItems.CAPACITY_CARD)); - } - } - -} diff --git a/src/main/java/appeng/client/gui/implementations/IOPortScreen.java b/src/main/java/appeng/client/gui/implementations/IOPortScreen.java deleted file mode 100644 index 97aea9047d7..00000000000 --- a/src/main/java/appeng/client/gui/implementations/IOPortScreen.java +++ /dev/null @@ -1,77 +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.client.gui.implementations; - -import com.mojang.blaze3d.vertex.PoseStack; - -import net.minecraft.network.chat.Component; -import net.minecraft.world.entity.player.Inventory; - -import appeng.api.config.FullnessMode; -import appeng.api.config.OperationMode; -import appeng.api.config.RedstoneMode; -import appeng.api.config.Settings; -import appeng.client.gui.style.ScreenStyle; -import appeng.client.gui.widgets.ServerSettingToggleButton; -import appeng.client.gui.widgets.SettingToggleButton; -import appeng.core.definitions.AEBlocks; -import appeng.core.definitions.AEItems; -import appeng.menu.implementations.IOPortMenu; - -public class IOPortScreen extends UpgradeableScreen { - - private final SettingToggleButton fullMode; - private final SettingToggleButton operationMode; - private final SettingToggleButton redstoneMode; - - public IOPortScreen(IOPortMenu menu, Inventory playerInventory, Component title, - ScreenStyle style) { - super(menu, playerInventory, title, style); - - this.fullMode = new ServerSettingToggleButton<>(Settings.FULLNESS_MODE, - FullnessMode.EMPTY); - addToLeftToolbar(this.fullMode); - this.redstoneMode = new ServerSettingToggleButton<>( - Settings.REDSTONE_CONTROLLED, RedstoneMode.IGNORE); - addToLeftToolbar(this.redstoneMode); - - this.operationMode = new ServerSettingToggleButton<>(Settings.OPERATION_MODE, OperationMode.EMPTY); - widgets.add("operationMode", this.operationMode); - } - - @Override - protected void updateBeforeRender() { - super.updateBeforeRender(); - - this.redstoneMode.set(this.menu.getRedStoneMode()); - this.redstoneMode.setVisibility(menu.hasUpgrade(AEItems.REDSTONE_CARD)); - this.operationMode.set(this.menu.getOperationMode()); - this.fullMode.set(this.menu.getFullMode()); - } - - @Override - public void drawBG(PoseStack poseStack, int offsetX, int offsetY, int mouseX, - int mouseY, float partialTicks) { - super.drawBG(poseStack, offsetX, offsetY, mouseX, mouseY, partialTicks); - - this.drawItem(offsetX + 66 - 8, offsetY + 17, AEItems.ITEM_CELL_1K.stack()); - this.drawItem(offsetX + 94 + 8, offsetY + 17, AEBlocks.DRIVE.stack()); - } - -} diff --git a/src/main/java/appeng/client/gui/implementations/InscriberScreen.java b/src/main/java/appeng/client/gui/implementations/InscriberScreen.java deleted file mode 100644 index 1d906f24ce0..00000000000 --- a/src/main/java/appeng/client/gui/implementations/InscriberScreen.java +++ /dev/null @@ -1,49 +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.client.gui.implementations; - -import net.minecraft.network.chat.Component; -import net.minecraft.world.entity.player.Inventory; - -import appeng.client.gui.style.ScreenStyle; -import appeng.client.gui.widgets.ProgressBar; -import appeng.client.gui.widgets.ProgressBar.Direction; -import appeng.menu.implementations.InscriberMenu; - -public class InscriberScreen extends UpgradeableScreen { - - private final ProgressBar pb; - - public InscriberScreen(InscriberMenu menu, Inventory playerInventory, Component title, - ScreenStyle style) { - super(menu, playerInventory, title, style); - - this.pb = new ProgressBar(this.menu, style.getImage("progressBar"), Direction.VERTICAL); - widgets.add("progressBar", this.pb); - } - - @Override - protected void updateBeforeRender() { - super.updateBeforeRender(); - - int progress = this.menu.getCurrentProgress() * 100 / this.menu.getMaxProgress(); - this.pb.setFullMsg(Component.literal(progress + "%")); - } - -} diff --git a/src/main/java/appeng/client/gui/implementations/InterfaceScreen.java b/src/main/java/appeng/client/gui/implementations/InterfaceScreen.java deleted file mode 100644 index 43ec86e2887..00000000000 --- a/src/main/java/appeng/client/gui/implementations/InterfaceScreen.java +++ /dev/null @@ -1,93 +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.client.gui.implementations; - -import java.util.ArrayList; -import java.util.List; - -import net.minecraft.client.gui.components.Button; -import net.minecraft.network.chat.Component; -import net.minecraft.world.entity.player.Inventory; - -import appeng.api.config.FuzzyMode; -import appeng.api.config.Settings; -import appeng.client.gui.Icon; -import appeng.client.gui.style.ScreenStyle; -import appeng.client.gui.widgets.IconButton; -import appeng.client.gui.widgets.ServerSettingToggleButton; -import appeng.client.gui.widgets.SettingToggleButton; -import appeng.core.definitions.AEItems; -import appeng.core.localization.ButtonToolTips; -import appeng.menu.SlotSemantics; -import appeng.menu.implementations.InterfaceMenu; - -public class InterfaceScreen extends UpgradeableScreen { - - private final SettingToggleButton fuzzyMode; - private final List