-
Notifications
You must be signed in to change notification settings - Fork 361
Expand file tree
/
Copy pathGTCapabilityHelper.java
More file actions
129 lines (106 loc) · 5.35 KB
/
GTCapabilityHelper.java
File metadata and controls
129 lines (106 loc) · 5.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package com.gregtechceu.gtceu.api.capability;
import com.gregtechceu.gtceu.api.machine.feature.multiblock.IMaintenanceMachine;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.ForgeCapabilities;
import net.minecraftforge.energy.IEnergyStorage;
import net.minecraftforge.fluids.capability.IFluidHandler;
import net.minecraftforge.items.IItemHandler;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class GTCapabilityHelper {
@Nullable
public static IElectricItem getElectricItem(ItemStack itemStack) {
return itemStack.getCapability(GTCapability.CAPABILITY_ELECTRIC_ITEM).resolve().orElse(null);
}
@Nullable
public static IEnergyStorage getForgeEnergyItem(ItemStack itemStack) {
return itemStack.getCapability(ForgeCapabilities.ENERGY).resolve().orElse(null);
}
@Nullable
public static IItemHandler getItemHandler(Level level, BlockPos pos, @Nullable Direction side) {
return getBlockEntityCapability(ForgeCapabilities.ITEM_HANDLER, level, pos, side);
}
@Nullable
public static IFluidHandler getFluidHandler(Level level, BlockPos pos, @Nullable Direction side) {
return getBlockEntityCapability(ForgeCapabilities.FLUID_HANDLER, level, pos, side);
}
@Nullable
public static IEnergyContainer getEnergyContainer(Level level, BlockPos pos, @Nullable Direction side) {
return getBlockEntityCapability(GTCapability.CAPABILITY_ENERGY_CONTAINER, level, pos, side);
}
@Nullable
public static IEnergyInfoProvider getEnergyInfoProvider(Level level, BlockPos pos, @Nullable Direction side) {
return getBlockEntityCapability(GTCapability.CAPABILITY_ENERGY_INFO_PROVIDER, level, pos, side);
}
@Nullable
public static ICoverable getCoverable(Level level, BlockPos pos, @Nullable Direction side) {
return getBlockEntityCapability(GTCapability.CAPABILITY_COVERABLE, level, pos, side);
}
@Nullable
public static IToolable getToolable(Level level, BlockPos pos, @Nullable Direction side) {
return getBlockEntityCapability(GTCapability.CAPABILITY_TOOLABLE, level, pos, side);
}
@Nullable
public static IWorkable getWorkable(Level level, BlockPos pos, @Nullable Direction side) {
return getBlockEntityCapability(GTCapability.CAPABILITY_WORKABLE, level, pos, side);
}
@Nullable
public static IControllable getControllable(Level level, BlockPos pos, @Nullable Direction side) {
return getBlockEntityCapability(GTCapability.CAPABILITY_CONTROLLABLE, level, pos, side);
}
@Nullable
public static IEnergyStorage getForgeEnergy(Level level, BlockPos pos, @Nullable Direction side) {
if (level.getBlockState(pos).hasBlockEntity()) {
var blockEntity = level.getBlockEntity(pos);
if (blockEntity != null) {
return blockEntity.getCapability(ForgeCapabilities.ENERGY, side).orElse(null);
}
}
return null;
}
@Nullable
public static IMaintenanceMachine getMaintenanceMachine(Level level, BlockPos pos, @Nullable Direction side) {
return getBlockEntityCapability(GTCapability.CAPABILITY_MAINTENANCE_MACHINE, level, pos, side);
}
@Nullable
public static ILaserContainer getLaser(Level level, BlockPos pos, @Nullable Direction side) {
return getBlockEntityCapability(GTCapability.CAPABILITY_LASER, level, pos, side);
}
@Nullable
public static IOpticalComputationProvider getOpticalComputationProvider(Level level, BlockPos pos,
@Nullable Direction side) {
return getBlockEntityCapability(GTCapability.CAPABILITY_COMPUTATION_PROVIDER, level, pos, side);
}
@Nullable
public static IDataAccessHatch getDataAccess(Level level, BlockPos pos, @Nullable Direction side) {
return getBlockEntityCapability(GTCapability.CAPABILITY_DATA_ACCESS, level, pos, side);
}
@Nullable
public static IHazardParticleContainer getHazardContainer(Level level, BlockPos pos, @Nullable Direction side) {
return getBlockEntityCapability(GTCapability.CAPABILITY_HAZARD_CONTAINER, level, pos, side);
}
@Nullable
public static IMonitorComponent getMonitorComponent(Level level, BlockPos pos, @Nullable Direction side) {
return getBlockEntityCapability(GTCapability.CAPABILITY_MONITOR_COMPONENT, level, pos, side);
}
@Nullable
private static <T> T getBlockEntityCapability(Capability<T> capability, Level level, BlockPos pos,
@Nullable Direction side) {
if (level.getBlockState(pos).hasBlockEntity()) {
var blockEntity = level.getBlockEntity(pos);
if (blockEntity != null) {
return blockEntity.getCapability(capability, side).resolve().orElse(null);
}
}
return null;
}
@Nullable
public static IMedicalConditionTracker getMedicalConditionTracker(@NotNull Entity entity) {
return entity.getCapability(GTCapability.CAPABILITY_MEDICAL_CONDITION_TRACKER, null).resolve().orElse(null);
}
}