-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathWrappedEnergyHandler.java
More file actions
89 lines (72 loc) · 2.02 KB
/
Copy pathWrappedEnergyHandler.java
File metadata and controls
89 lines (72 loc) · 2.02 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
package io.github.cottonmc.component.compat.tr;
import io.github.cottonmc.component.api.ActionType;
import io.github.cottonmc.component.energy.CapacitorComponent;
import io.github.cottonmc.component.energy.type.EnergyType;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.math.Direction;
import team.reborn.energy.EnergyHandler;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
import java.util.function.Supplier;
public class WrappedEnergyHandler implements CapacitorComponent {
private Supplier<EnergyHandler> handler;
private Direction side = null;
public WrappedEnergyHandler(Supplier<EnergyHandler> handler) {
this.handler = handler;
}
public WrappedEnergyHandler(Supplier<EnergyHandler> handler, @Nullable Direction side) {
this.handler = handler;
this.side = side;
}
@Override
public int getMaxEnergy() {
return (int)handler.get().getMaxStored();
}
@Override
public int getCurrentEnergy() {
return (int)handler.get().getEnergy();
}
@Override
public boolean canInsertEnergy() {
return handler.get().getMaxInput() != 0;
}
@Override
public int insertEnergy(EnergyType type, int amount, ActionType action) {
EnergyHandler energy = handler.get();
energy.side(side);
if (!action.shouldPerform()) energy.simulate();
return (int)energy.insert(amount);
}
@Override
public boolean canExtractEnergy() {
return handler.get().getMaxOutput() != 0;
}
@Override
public int extractEnergy(EnergyType type, int amount, ActionType action) {
EnergyHandler energy = handler.get();
energy.side(side);
if (!action.shouldPerform()) energy.simulate();
return (int)energy.extract(amount);
}
@Nonnull
@Override
public EnergyType getPreferredType() {
//TODO: figure out how to impl
return RebornEnergyTypes.INFINITE_TIER;
}
@Override
public int getHarm() {
return 0;
}
@Override
public List<Runnable> getListeners() {
return null;
}
@Override
public void readFromNbt(NbtCompound tag) {
}
@Override
public void writeToNbt(NbtCompound tag) {
}
}