Skip to content

Commit

Permalink
Fix #5652: Replace remaining uses of grid.getService() with the conve…
Browse files Browse the repository at this point in the history
…nience methods
  • Loading branch information
Technici4n committed Nov 12, 2021
1 parent 8ae1bf6 commit 40c9a5b
Show file tree
Hide file tree
Showing 21 changed files with 46 additions and 50 deletions.
11 changes: 11 additions & 0 deletions src/main/java/appeng/api/networking/IGrid.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
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;

Expand Down Expand Up @@ -179,4 +180,14 @@ default ISecurityService getSecurityService() {
default IPathingService getPathingService() {
return getService(IPathingService.class);
}

/**
* Get this grids {@link ISpatialService}.
*
* @see #getService(Class)
*/
@Nonnull
default ISpatialService getSpatialService() {
return getService(ISpatialService.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import appeng.api.inventories.InternalInventory;
import appeng.api.networking.GridFlags;
import appeng.api.networking.events.GridSpatialEvent;
import appeng.api.networking.spatial.ISpatialService;
import appeng.api.util.AECableType;
import appeng.blockentity.grid.AENetworkInvBlockEntity;
import appeng.hooks.ticking.TickHandler;
Expand Down Expand Up @@ -120,7 +119,7 @@ private void transition() throws Exception {
final ISpatialStorageCell sc = (ISpatialStorageCell) cell.getItem();

getMainNode().ifPresent((grid, node) -> {
var spc = grid.getService(ISpatialService.class);
var spc = grid.getSpatialService();
if (!spc.hasRegion() || !spc.isValidRegion()) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -595,13 +595,13 @@ private boolean securityCheck(final Player player, final SecurityPermissions req
final IGrid g = gn.getGrid();
final boolean requirePower = false;
if (requirePower) {
final IEnergyService eg = g.getService(IEnergyService.class);
final IEnergyService eg = g.getEnergyService();
if (!eg.isNetworkPowered()) {
return false;
}
}

final ISecurityService sg = g.getService(ISecurityService.class);
final ISecurityService sg = g.getSecurityService();
if (sg.hasPermission(player, requiredPermission)) {
return true;
}
Expand Down
15 changes: 4 additions & 11 deletions src/main/java/appeng/core/sync/packets/JEIRecipePacket.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@
import appeng.api.config.Actionable;
import appeng.api.config.SecurityPermissions;
import appeng.api.networking.crafting.ICraftingService;
import appeng.api.networking.energy.IEnergyService;
import appeng.api.networking.security.ISecurityService;
import appeng.api.networking.storage.IStorageService;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.StorageChannels;
import appeng.api.storage.StorageHelper;
Expand Down Expand Up @@ -152,14 +149,10 @@ public void serverPacketData(final INetworkInfo manager, final ServerPlayer play
var grid = node.getGrid();
Preconditions.checkArgument(grid != null);

var inv = grid.getService(IStorageService.class);
Preconditions.checkArgument(inv != null);

var security = grid.getService(ISecurityService.class);
Preconditions.checkArgument(security != null);

var energy = grid.getService(IEnergyService.class);
var crafting = grid.getService(ICraftingService.class);
var inv = grid.getStorageService();
var security = grid.getSecurityService();
var energy = grid.getEnergyService();
var crafting = grid.getCraftingService();
var craftMatrix = cct.getCraftingMatrix();

var storage = inv.getInventory(StorageChannels.items());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ public void storeItems() {
if (g == null)
return;

final IStorageService sg = g.getService(IStorageService.class);
final IStorageService sg = g.getStorageService();

for (IAEStack is : this.inventory.list) {
this.postChange(is);
Expand Down
12 changes: 5 additions & 7 deletions src/main/java/appeng/debug/DebugCardItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@
import appeng.api.networking.energy.IAEPowerStorage;
import appeng.api.networking.energy.IEnergyService;
import appeng.api.networking.pathing.ControllerState;
import appeng.api.networking.pathing.IPathingService;
import appeng.api.networking.ticking.ITickManager;
import appeng.api.parts.IPart;
import appeng.api.parts.IPartHost;
import appeng.blockentity.networking.ControllerBlockEntity;
Expand Down Expand Up @@ -107,13 +105,13 @@ public InteractionResult onItemUseFirst(ItemStack stack, UseOnContext context) {
final Grid g = node.getInternalGrid();
final IGridNode center = g.getPivot();
this.outputPrimaryMessage(player, "Grid Powered",
String.valueOf(g.getService(IEnergyService.class).isNetworkPowered()));
String.valueOf(g.getEnergyService().isNetworkPowered()));
this.outputPrimaryMessage(player, "Grid Booted",
String.valueOf(!g.getService(IPathingService.class).isNetworkBooting()));
String.valueOf(!g.getPathingService().isNetworkBooting()));
this.outputPrimaryMessage(player, "Nodes in grid", String.valueOf(Iterables.size(g.getNodes())));
this.outputSecondaryMessage(player, "Grid Pivot Node", String.valueOf(center));

var tmc = (TickManagerService) g.getService(ITickManager.class);
var tmc = (TickManagerService) g.getTickManager();
for (var c : g.getMachineClasses()) {
int o = 0;
long totalAverageTime = 0;
Expand Down Expand Up @@ -143,7 +141,7 @@ public InteractionResult onItemUseFirst(ItemStack stack, UseOnContext context) {
this.outputPrimaryMessage(player, "This Node Active", String.valueOf(node.isActive()));
this.outputSecondaryMessage(player, "Node exposed on side", side.getName());

var pg = g.getService(IPathingService.class);
var pg = g.getPathingService();
if (pg.getControllerState() == ControllerState.CONTROLLER_ONLINE) {

Set<IGridNode> next = new HashSet<>();
Expand Down Expand Up @@ -208,7 +206,7 @@ public InteractionResult onItemUseFirst(ItemStack stack, UseOnContext context) {
if (gh != null) {
final IGridNode node = gh.getGridNode(side);
if (node != null && node.getGrid() != null) {
final IEnergyService eg = node.getGrid().getService(IEnergyService.class);
final IEnergyService eg = node.getGrid().getEnergyService();
this.outputSecondaryMessage(player,
"GridEnergy", +eg.getStoredPower() + " : " + eg.getEnergyDemand(Double.MAX_VALUE));
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/appeng/debug/ReplicatorCardItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public InteractionResult onItemUseFirst(ItemStack stack, UseOnContext context) {
final IGrid g = n.getGrid();

if (g != null) {
final ISpatialService sc = g.getService(ISpatialService.class);
final ISpatialService sc = g.getSpatialService();

if (sc.isValidRegion()) {
var min = sc.getMin();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public WirelessTerminalGuiObject(final IWirelessTerminalHandler wh, final ItemSt
if (n != null) {
this.targetGrid = n.getGrid();
if (this.targetGrid != null) {
this.sg = this.targetGrid.getService(IStorageService.class);
this.sg = this.targetGrid.getStorageService();
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/appeng/me/GridConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public Direction getDirection(final IGridNode side) {
@Override
public void destroy() {
// a connection was destroyed RE-PATH!!
final IPathingService p = this.sideA.getInternalGrid().getService(IPathingService.class);
final IPathingService p = this.sideA.getInternalGrid().getPathingService();
p.repath();

this.sideA.removeConnection(this);
Expand Down Expand Up @@ -232,7 +232,7 @@ public static GridConnection create(final IGridNode aNode, final IGridNode bNode
}

// a connection was destroyed RE-PATH!!
final IPathingService p = connection.sideA.getInternalGrid().getService(IPathingService.class);
final IPathingService p = connection.sideA.getInternalGrid().getPathingService();
p.repath();

connection.sideA.addConnection(connection);
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/appeng/me/GridNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@
import appeng.api.networking.IGridNodeListener;
import appeng.api.networking.IGridNodeService;
import appeng.api.networking.IGridVisitor;
import appeng.api.networking.energy.IEnergyService;
import appeng.api.networking.events.GridPowerIdleChange;
import appeng.api.networking.pathing.IPathingService;
import appeng.api.parts.IPart;
import appeng.api.util.AEColor;
import appeng.core.worlddata.IGridStorageData;
Expand Down Expand Up @@ -364,15 +362,15 @@ public boolean hasGridBooted() {
if (myGrid == null) {
return false;
}
return !myGrid.getService(IPathingService.class).isNetworkBooting();
return !myGrid.getPathingService().isNetworkBooting();
}

@Override
public boolean isPowered() {
if (myGrid == null) {
return false;
}
return myGrid.getService(IEnergyService.class).isNetworkPowered();
return myGrid.getEnergyService().isNetworkPowered();
}

public void loadFromNBT(final String name, final CompoundTag nodeData) {
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/appeng/me/service/P2PService.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import appeng.api.networking.IGridServiceProvider;
import appeng.api.networking.events.GridBootingStatusChange;
import appeng.api.networking.events.GridPowerStatusChange;
import appeng.api.networking.ticking.ITickManager;
import appeng.core.AELog;
import appeng.me.service.helpers.TunnelCollection;
import appeng.parts.p2p.MEP2PTunnelPart;
Expand Down Expand Up @@ -68,7 +67,7 @@ public P2PService(final IGrid g) {
}

public void wakeInputTunnels() {
var tm = this.myGrid.getService(ITickManager.class);
var tm = this.myGrid.getTickManager();
for (var tunnel : this.inputs.values()) {
if (tunnel instanceof MEP2PTunnelPart) {
tm.wakeDevice(tunnel.getGridNode());
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/appeng/me/storage/NetworkStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ private boolean testPermission(final IActionSource src, final SecurityPermission
final IGrid gn = n.getGrid();
if (gn != this.security.getGrid()) {

final ISecurityService sg = gn.getService(ISecurityService.class);
final ISecurityService sg = gn.getSecurityService();
final int playerID = sg.getOwner();

if (!this.security.hasPermission(playerID, permission)) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/appeng/menu/AEBaseMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,13 @@ protected boolean hasAccess(final SecurityPermissions perm, final boolean requir
final IGrid g = gn.getGrid();
if (g != null) {
if (requirePower) {
final IEnergyService eg = g.getService(IEnergyService.class);
final IEnergyService eg = g.getEnergyService();
if (!eg.isNetworkPowered()) {
return false;
}
}

final ISecurityService sg = g.getService(ISecurityService.class);
final ISecurityService sg = g.getSecurityService();
if (sg.hasPermission(this.getPlayerInventory().player, perm)) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import net.minecraft.world.inventory.MenuType;

import appeng.api.config.SecurityPermissions;
import appeng.api.networking.energy.IEnergyService;
import appeng.api.networking.spatial.ISpatialService;
import appeng.blockentity.spatial.SpatialIOPortBlockEntity;
import appeng.menu.AEBaseMenu;
import appeng.menu.SlotSemantic;
Expand Down Expand Up @@ -82,8 +80,8 @@ public void broadcastChanges() {
if (this.delay > 15 && grid != null) {
this.delay = 0;

var eg = grid.getService(IEnergyService.class);
var sc = grid.getService(ISpatialService.class);
var eg = grid.getEnergyService();
var sc = grid.getSpatialService();
this.setCurrentPower((long) (100.0 * eg.getStoredPower()));
this.setMaxPower((long) (100.0 * eg.getMaxStoredPower()));
this.setRequiredPower((long) (100.0 * sc.requiredPower()));
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/appeng/menu/me/common/MEMonitorableMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public MEMonitorableMenu(MenuType<?> menuType, int id, Inventory ip,
this.networkNode = node;
final IGrid g = node.getGrid();
if (g != null) {
powerSource = new ChannelPowerSrc(this.networkNode, g.getService(IEnergyService.class));
powerSource = new ChannelPowerSrc(this.networkNode, g.getEnergyService());
}
}
}
Expand Down Expand Up @@ -291,7 +291,7 @@ private void updateActiveCraftingJobs() {
}

int activeJobs = 0;
ICraftingService craftingGrid = grid.getService(ICraftingService.class);
ICraftingService craftingGrid = grid.getCraftingService();
for (ICraftingCPU cpus : craftingGrid.getCpus()) {
if (cpus.isBusy()) {
activeJobs++;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/appeng/menu/me/crafting/CraftAmountMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public void confirm(int amount, boolean autoStart) {

Future<ICraftingPlan> futureJob = null;
try {
final ICraftingService cg = g.getService(ICraftingService.class);
final ICraftingService cg = g.getCraftingService();
var actionSource = getActionSrc();
futureJob = cg.beginCraftingCalculation(getLevel(), () -> actionSource, this.itemToCreate);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public void startJob() {
}

if (this.result != null && !this.result.simulation()) {
final ICraftingService cc = this.getGrid().getService(ICraftingService.class);
final ICraftingService cc = this.getGrid().getCraftingService();
final ICraftingLink g = cc.submitJob(this.result, null, this.selectedCpu, true, this.getActionSrc());
this.setAutoStart(false);
if (g != null && originalGui != null && this.getLocator() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public CraftingCPUCycler(Predicate<ICraftingCPU> cpuFilter, ChangeListener chang
}

public void detectAndSendChanges(IGrid network) {
final ICraftingService cc = network.getService(ICraftingService.class);
final ICraftingService cc = network.getCraftingService();
final ImmutableSet<ICraftingCPU> cpuSet = cc.getCpus();

int matches = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public static CraftingPlanSummary fromJob(IGrid grid, IActionSource actionSource

ImmutableList.Builder<CraftingPlanSummaryEntry> entries = ImmutableList.builder();

final IStorageService sg = grid.getService(IStorageService.class);
final IStorageService sg = grid.getStorageService();

for (var out : plan) {
long missingAmount;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class NetworkStatus {
private List<MachineGroup> groupedMachines = Collections.emptyList();

public static NetworkStatus fromGrid(IGrid grid) {
IEnergyService eg = grid.getService(IEnergyService.class);
IEnergyService eg = grid.getEnergyService();

NetworkStatus status = new NetworkStatus();

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/appeng/util/Platform.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,14 @@ public static boolean checkPermissions(final Player player, final Object accessI
if (g != null) {
final boolean requirePower = false;
if (requirePower) {
final IEnergyService eg = g.getService(IEnergyService.class);
final IEnergyService eg = g.getEnergyService();
if (!eg.isNetworkPowered()) {
// FIXME trace logging?
return false;
}
}

final ISecurityService sg = g.getService(ISecurityService.class);
final ISecurityService sg = g.getSecurityService();
if (!sg.hasPermission(player, requiredPermission)) {
player.sendMessage(new TranslatableComponent("appliedenergistics2.permission_denied")
.withStyle(ChatFormatting.RED), Util.NIL_UUID);
Expand Down Expand Up @@ -561,7 +561,7 @@ private static boolean checkPlayerPermissions(final IGrid grid, final int player
return true;
}

final ISecurityService gs = grid.getService(ISecurityService.class);
final ISecurityService gs = grid.getSecurityService();

if (gs == null) {
return true;
Expand Down

0 comments on commit 40c9a5b

Please sign in to comment.