-
Notifications
You must be signed in to change notification settings - Fork 211
Expand file tree
/
Copy pathCoverFluidVoiding.java
More file actions
140 lines (121 loc) · 5.54 KB
/
Copy pathCoverFluidVoiding.java
File metadata and controls
140 lines (121 loc) · 5.54 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
130
131
132
133
134
135
136
137
138
139
140
package gregtech.common.covers;
import gregtech.api.capability.GregtechTileCapabilities;
import gregtech.api.cover.CoverDefinition;
import gregtech.api.cover.CoverableView;
import gregtech.api.util.GTTransferUtils;
import gregtech.client.renderer.texture.Textures;
import gregtech.common.covers.filter.FluidFilterContainer;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTank;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import net.minecraftforge.fluids.capability.IFluidHandler;
import codechicken.lib.raytracer.CuboidRayTraceResult;
import codechicken.lib.render.CCRenderState;
import codechicken.lib.render.pipeline.IVertexOperation;
import codechicken.lib.vec.Cuboid6;
import codechicken.lib.vec.Matrix4;
import com.cleanroommc.modularui.factory.GuiData;
import com.cleanroommc.modularui.factory.SidedPosGuiData;
import com.cleanroommc.modularui.screen.ModularPanel;
import com.cleanroommc.modularui.screen.UISettings;
import com.cleanroommc.modularui.utils.Color;
import com.cleanroommc.modularui.value.sync.BooleanSyncValue;
import com.cleanroommc.modularui.value.sync.PanelSyncManager;
import com.cleanroommc.modularui.widget.ParentWidget;
import com.cleanroommc.modularui.widgets.ToggleButton;
import com.cleanroommc.modularui.widgets.layout.Flow;
import org.jetbrains.annotations.NotNull;
public class CoverFluidVoiding extends CoverPump {
protected final NullFluidTank nullFluidTank = new NullFluidTank();
public CoverFluidVoiding(@NotNull CoverDefinition definition, @NotNull CoverableView coverableView,
@NotNull EnumFacing attachedSide) {
super(definition, coverableView, attachedSide, 0, Integer.MAX_VALUE);
this.isWorkingAllowed = false;
this.fluidFilterContainer = new FluidFilterContainer(this);
this.fluidFilterContainer.setMaxTransferSize(Integer.MAX_VALUE);
}
@Override
public void update() {
if (isWorkingAllowed && getOffsetTimer() % 20 == 0) {
doTransferFluids();
}
}
protected void doTransferFluids() {
IFluidHandler myFluidHandler = getCoverableView().getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY,
getAttachedSide());
if (myFluidHandler == null) {
return;
}
GTTransferUtils.transferFluids(myFluidHandler, nullFluidTank, Integer.MAX_VALUE,
fluidFilterContainer::test);
}
@Override
public void renderCover(@NotNull CCRenderState renderState, @NotNull Matrix4 translation,
IVertexOperation[] pipeline, @NotNull Cuboid6 plateBox, @NotNull BlockRenderLayer layer) {
Textures.FLUID_VOIDING.renderSided(getAttachedSide(), plateBox, renderState, pipeline, translation);
}
@Override
public ModularPanel buildUI(SidedPosGuiData guiData, PanelSyncManager guiSyncManager, UISettings settings) {
return super.buildUI(guiData, guiSyncManager, settings).height(192 - 22);
}
@Override
protected ParentWidget<?> createUI(GuiData data, PanelSyncManager syncManager) {
BooleanSyncValue isWorking = new BooleanSyncValue(this::isWorkingEnabled, this::setWorkingEnabled);
return super.createUI(data, syncManager)
.child(Flow.row().height(18).widthRel(1f)
.marginBottom(2)
.child(new ToggleButton()
.value(isWorking)
.overlay(createEnabledKey("behaviour.soft_hammer", () -> this.isWorkingAllowed)
.color(Color.WHITE.darker(1)))
.widthRel(0.6f)
.left(0)));
}
@Override
protected boolean createPumpModeRow() {
return false;
}
@Override
protected boolean createThroughputRow() {
return false;
}
@Override
public @NotNull EnumActionResult onSoftMalletClick(@NotNull EntityPlayer playerIn, @NotNull EnumHand hand,
@NotNull CuboidRayTraceResult hitResult) {
this.isWorkingAllowed = !this.isWorkingAllowed;
if (!playerIn.world.isRemote) {
playerIn.sendStatusMessage(new TextComponentTranslation(isWorkingEnabled() ?
"cover.voiding.message.enabled" : "cover.voiding.message.disabled"), true);
}
return EnumActionResult.SUCCESS;
}
@Override
public <T> T getCapability(@NotNull Capability<T> capability, T defaultValue) {
if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
return CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.cast(nullFluidTank);
}
if (capability == GregtechTileCapabilities.CAPABILITY_CONTROLLABLE) {
return GregtechTileCapabilities.CAPABILITY_CONTROLLABLE.cast(this);
}
return defaultValue;
}
class NullFluidTank extends FluidTank {
public NullFluidTank() {
super(Integer.MAX_VALUE);
}
@Override
public int fill(FluidStack resource, boolean doFill) {
if (fluidFilterContainer.test(resource)) {
return resource.amount;
}
return 0;
}
}
}