Skip to content

Commit

Permalink
Move AECapabilities to API (#7797)
Browse files Browse the repository at this point in the history
  • Loading branch information
Technici4n authored Mar 28, 2024
1 parent c29fe17 commit 467354b
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/

package appeng.capabilities;
package appeng.api;

import org.jetbrains.annotations.Nullable;

Expand All @@ -31,10 +31,10 @@
import appeng.core.AppEng;

/**
* Utility class that holds various capabilities, both by AE2 and other Mods.
* Utility class that holds the capabilities provided by AE2.
*/
public final class AppEngCapabilities {
private AppEngCapabilities() {
public final class AECapabilities {
private AECapabilities() {
}

public static BlockCapability<MEStorage, @Nullable Direction> ME_STORAGE = BlockCapability
Expand All @@ -46,6 +46,9 @@ private AppEngCapabilities() {
public static BlockCapability<GenericInternalInventory, @Nullable Direction> GENERIC_INTERNAL_INV = BlockCapability
.createSided(AppEng.makeId("generic_internal_inv"), GenericInternalInventory.class);

/**
* The {@link Direction} context is always {@code null}. TODO 1.20.5: Replace @Nullable Direction by Void context.
*/
public static BlockCapability<IInWorldGridNodeHost, @Nullable Direction> IN_WORLD_GRID_NODE_HOST = BlockCapability
.createSided(AppEng.makeId("inworld_gridnode_host"), IInWorldGridNodeHost.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;

import appeng.api.AECapabilities;
import appeng.api.crafting.IPatternDetails;
import appeng.api.stacks.KeyCounter;
import appeng.capabilities.AppEngCapabilities;

/**
* Provides crafting services to adjacent pattern providers for automatic crafting. Can be provided via capability on
Expand All @@ -47,13 +47,13 @@ static ICraftingMachine of(@Nullable BlockEntity blockEntity, Direction side) {
}

return blockEntity.getLevel().getCapability(
AppEngCapabilities.CRAFTING_MACHINE, blockEntity.getBlockPos(), blockEntity.getBlockState(),
AECapabilities.CRAFTING_MACHINE, blockEntity.getBlockPos(), blockEntity.getBlockState(),
blockEntity, side);
}

@Nullable
static ICraftingMachine of(Level level, BlockPos pos, Direction side) {
return level.getCapability(AppEngCapabilities.CRAFTING_MACHINE, pos, side);
return level.getCapability(AECapabilities.CRAFTING_MACHINE, pos, side);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import net.minecraft.core.Direction;
import net.minecraft.world.level.Level;

import appeng.capabilities.AppEngCapabilities;
import appeng.api.AECapabilities;

/**
* Crank/Crankable API,
Expand All @@ -54,6 +54,6 @@ public interface ICrankable {

@Nullable
static ICrankable get(Level level, BlockPos pos, Direction side) {
return level.getCapability(AppEngCapabilities.CRANKABLE, pos, side);
return level.getCapability(AECapabilities.CRANKABLE, pos, side);
}
}
4 changes: 2 additions & 2 deletions src/main/java/appeng/api/networking/GridHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;

import appeng.api.AECapabilities;
import appeng.api.networking.events.GridEvent;
import appeng.capabilities.AppEngCapabilities;
import appeng.hooks.ticking.TickHandler;
import appeng.me.GridConnection;
import appeng.me.GridEventBus;
Expand Down Expand Up @@ -130,7 +130,7 @@ public static <T extends GridEvent, C> void addNodeOwnerEventHandler(Class<T> ev
*/
@Nullable
public static IInWorldGridNodeHost getNodeHost(Level level, BlockPos pos) {
return level.getCapability(AppEngCapabilities.IN_WORLD_GRID_NODE_HOST, pos, null);
return level.getCapability(AECapabilities.IN_WORLD_GRID_NODE_HOST, pos, null);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* Implement to create a networked {@link BlockEntity}. Must be implemented for a block entity to be available for
* in-world connection attempts by adjacent grid nodes.
* <p>
* Can either be implemented by the block entity itself, or provided via a lookup/capability with null direction.
* Must be provided via the {@link appeng.api.AECapabilities#IN_WORLD_GRID_NODE_HOST} capability.
*/
public interface IInWorldGridNodeHost {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;

import appeng.api.AECapabilities;
import appeng.api.config.Actionable;
import appeng.api.networking.security.IActionSource;
import appeng.api.stacks.AEKey;
import appeng.api.stacks.AEKeyType;
import appeng.api.storage.MEStorage;
import appeng.capabilities.AppEngCapabilities;
import appeng.me.storage.CompositeStorage;
import appeng.parts.automation.StackWorldBehaviors;

Expand All @@ -51,9 +51,9 @@ static PatternProviderTarget get(Level l, BlockPos pos, @Nullable BlockEntity be
// our capability first: allows any storage channel
MEStorage storage;
if (be != null) {
storage = l.getCapability(AppEngCapabilities.ME_STORAGE, be.getBlockPos(), be.getBlockState(), be, side);
storage = l.getCapability(AECapabilities.ME_STORAGE, be.getBlockPos(), be.getBlockState(), be, side);
} else {
storage = l.getCapability(AppEngCapabilities.ME_STORAGE, pos, side);
storage = l.getCapability(AECapabilities.ME_STORAGE, pos, side);
}
if (storage != null) {
return wrapMeStorage(storage, src);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
import net.minecraft.server.level.ServerLevel;
import net.neoforged.neoforge.capabilities.BlockCapabilityCache;

import appeng.api.AECapabilities;
import appeng.api.behaviors.ExternalStorageStrategy;
import appeng.api.config.Actionable;
import appeng.api.networking.security.IActionSource;
import appeng.api.stacks.AEKey;
import appeng.api.stacks.AEKeyType;
import appeng.api.storage.MEStorage;
import appeng.capabilities.AppEngCapabilities;
import appeng.me.storage.CompositeStorage;
import appeng.parts.automation.StackWorldBehaviors;

Expand All @@ -27,7 +27,7 @@ class PatternProviderTargetCache {
private final Map<AEKeyType, ExternalStorageStrategy> strategies;

PatternProviderTargetCache(ServerLevel l, BlockPos pos, Direction direction, IActionSource src) {
this.cache = BlockCapabilityCache.create(AppEngCapabilities.ME_STORAGE, l, pos, direction);
this.cache = BlockCapabilityCache.create(AECapabilities.ME_STORAGE, l, pos, direction);
this.src = src;
this.strategies = StackWorldBehaviors.createExternalStorageStrategies(l, pos, direction);
}
Expand Down
32 changes: 16 additions & 16 deletions src/main/java/appeng/init/InitCapabilityProviders.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.neoforged.neoforge.capabilities.Capabilities;
import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent;

import appeng.api.AECapabilities;
import appeng.api.behaviors.GenericInternalInventory;
import appeng.api.implementations.items.IAEItemPowerStorage;
import appeng.api.networking.IInWorldGridNodeHost;
Expand All @@ -22,7 +23,6 @@
import appeng.blockentity.misc.InscriberBlockEntity;
import appeng.blockentity.powersink.AEBasePoweredBlockEntity;
import appeng.blockentity.storage.ChestBlockEntity;
import appeng.capabilities.AppEngCapabilities;
import appeng.core.definitions.AEBlockEntities;
import appeng.core.definitions.AEItems;
import appeng.core.definitions.ItemDefinition;
Expand Down Expand Up @@ -67,7 +67,7 @@ public static void register(RegisterCapabilitiesEvent event) {
AEBasePoweredBlockEntity::getEnergyStorage);
}
for (var type : AEBlockEntities.getImplementorsOf(IInWorldGridNodeHost.class)) {
event.registerBlockEntity(AppEngCapabilities.IN_WORLD_GRID_NODE_HOST, type,
event.registerBlockEntity(AECapabilities.IN_WORLD_GRID_NODE_HOST, type,
(object, context) -> (IInWorldGridNodeHost) object);
}
}
Expand All @@ -78,7 +78,7 @@ public static void register(RegisterCapabilitiesEvent event) {
public static void registerGenericAdapters(RegisterCapabilitiesEvent event) {

for (var block : BuiltInRegistries.BLOCK) {
if (event.isBlockRegistered(AppEngCapabilities.GENERIC_INTERNAL_INV, block)) {
if (event.isBlockRegistered(AECapabilities.GENERIC_INTERNAL_INV, block)) {
registerGenericInvAdapter(event, block, Capabilities.ItemHandler.BLOCK, GenericStackItemStorage::new);
registerGenericInvAdapter(event, block, Capabilities.FluidHandler.BLOCK, GenericStackFluidStorage::new);
}
Expand All @@ -93,7 +93,7 @@ private static <T> void registerGenericInvAdapter(RegisterCapabilitiesEvent even
event.registerBlock(
capability,
(level, pos, state, blockEntity, context) -> {
var genericInv = level.getCapability(AppEngCapabilities.GENERIC_INTERNAL_INV, pos, state,
var genericInv = level.getCapability(AECapabilities.GENERIC_INTERNAL_INV, pos, state,
blockEntity, context);
if (genericInv != null) {
return adapter.apply(genericInv);
Expand All @@ -105,12 +105,12 @@ private static <T> void registerGenericInvAdapter(RegisterCapabilitiesEvent even

private static void initInterface(RegisterCapabilitiesEvent event) {
event.registerBlockEntity(
AppEngCapabilities.GENERIC_INTERNAL_INV,
AECapabilities.GENERIC_INTERNAL_INV,
AEBlockEntities.INTERFACE,
(be, context) -> be.getInterfaceLogic().getStorage());

event.registerBlockEntity(
AppEngCapabilities.ME_STORAGE,
AECapabilities.ME_STORAGE,
AEBlockEntities.INTERFACE,
(blockEntity, context) -> {
return blockEntity.getInterfaceLogic().getInventory();
Expand All @@ -119,7 +119,7 @@ private static void initInterface(RegisterCapabilitiesEvent event) {

private static void initPatternProvider(RegisterCapabilitiesEvent event) {
event.registerBlockEntity(
AppEngCapabilities.GENERIC_INTERNAL_INV,
AECapabilities.GENERIC_INTERNAL_INV,
AEBlockEntities.PATTERN_PROVIDER,
(blockEntity, context) -> blockEntity.getLogic().getReturnInv());
}
Expand All @@ -134,20 +134,20 @@ private static void initCondenser(RegisterCapabilitiesEvent event) {
((blockEntity, context) -> {
return blockEntity.getFluidHandler();
}));
event.registerBlockEntity(AppEngCapabilities.ME_STORAGE, AEBlockEntities.CONDENSER, (blockEntity, context) -> {
event.registerBlockEntity(AECapabilities.ME_STORAGE, AEBlockEntities.CONDENSER, (blockEntity, context) -> {
return blockEntity.getMEStorage();
});
}

private static void initMEChest(RegisterCapabilitiesEvent event) {
event.registerBlockEntity(Capabilities.FluidHandler.BLOCK, AEBlockEntities.CHEST,
ChestBlockEntity::getFluidHandler);
event.registerBlockEntity(AppEngCapabilities.ME_STORAGE, AEBlockEntities.CHEST, ChestBlockEntity::getMEStorage);
event.registerBlockEntity(AECapabilities.ME_STORAGE, AEBlockEntities.CHEST, ChestBlockEntity::getMEStorage);
}

private static void initMisc(RegisterCapabilitiesEvent event) {
event.registerBlockEntity(
AppEngCapabilities.CRAFTING_MACHINE,
AECapabilities.CRAFTING_MACHINE,
AEBlockEntities.MOLECULAR_ASSEMBLER,
(object, context) -> object);
event.registerBlockEntity(
Expand Down Expand Up @@ -194,24 +194,24 @@ private static <T extends Item & IAEItemPowerStorage> void registerPowerStorageI
}

private static void initCrankable(RegisterCapabilitiesEvent event) {
event.registerBlockEntity(AppEngCapabilities.CRANKABLE, AEBlockEntities.CHARGER,
event.registerBlockEntity(AECapabilities.CRANKABLE, AEBlockEntities.CHARGER,
ChargerBlockEntity::getCrankable);
event.registerBlockEntity(AppEngCapabilities.CRANKABLE, AEBlockEntities.INSCRIBER,
event.registerBlockEntity(AECapabilities.CRANKABLE, AEBlockEntities.INSCRIBER,
InscriberBlockEntity::getCrankable);
event.registerBlockEntity(AppEngCapabilities.CRANKABLE, AEBlockEntities.GROWTH_ACCELERATOR,
event.registerBlockEntity(AECapabilities.CRANKABLE, AEBlockEntities.GROWTH_ACCELERATOR,
GrowthAcceleratorBlockEntity::getCrankable);
}

private static void registerPartCapabilities(RegisterPartCapabilitiesEvent event) {
event.register(Capabilities.ItemHandler.BLOCK,
(part, direction) -> part.getLogic().getBlankPatternInv().toItemHandler(),
PatternEncodingTerminalPart.class);
event.register(AppEngCapabilities.GENERIC_INTERNAL_INV, (part, context) -> part.getLogic().getReturnInv(),
event.register(AECapabilities.GENERIC_INTERNAL_INV, (part, context) -> part.getLogic().getReturnInv(),
PatternProviderPart.class);
event.register(AppEngCapabilities.GENERIC_INTERNAL_INV,
event.register(AECapabilities.GENERIC_INTERNAL_INV,
(part, context) -> part.getInterfaceLogic().getStorage(),
InterfacePart.class);
event.register(AppEngCapabilities.ME_STORAGE,
event.register(AECapabilities.ME_STORAGE,
(part, context) -> part.getInterfaceLogic().getInventory(), InterfacePart.class);

event.register(Capabilities.ItemHandler.BLOCK, (part, context) -> part.getExposedApi(),
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/appeng/parts/storagebus/StorageBusPart.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import net.minecraft.world.phys.Vec3;
import net.neoforged.neoforge.capabilities.ICapabilityInvalidationListener;

import appeng.api.AECapabilities;
import appeng.api.behaviors.ExternalStorageStrategy;
import appeng.api.config.AccessRestriction;
import appeng.api.config.FuzzyMode;
Expand All @@ -62,7 +63,6 @@
import appeng.api.storage.MEStorage;
import appeng.api.util.AECableType;
import appeng.api.util.IConfigManager;
import appeng.capabilities.AppEngCapabilities;
import appeng.core.AppEng;
import appeng.core.definitions.AEItems;
import appeng.core.settings.TickRates;
Expand Down Expand Up @@ -139,7 +139,7 @@ public class StorageBusPart extends UpgradeablePart

public StorageBusPart(IPartItem<?> partItem) {
super(partItem);
this.adjacentStorageAccessor = new PartAdjacentApi<>(this, AppEngCapabilities.ME_STORAGE);
this.adjacentStorageAccessor = new PartAdjacentApi<>(this, AECapabilities.ME_STORAGE);
this.getConfigManager().registerSetting(Settings.ACCESS, AccessRestriction.READ_WRITE);
this.getConfigManager().registerSetting(Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL);
this.getConfigManager().registerSetting(Settings.STORAGE_FILTER, StorageFilter.EXTRACTABLE_ONLY);
Expand Down

0 comments on commit 467354b

Please sign in to comment.