Skip to content

Commit 3d17ea2

Browse files
committed
Fix Travis build
1 parent 9dc1622 commit 3d17ea2

File tree

4 files changed

+115
-13
lines changed

4 files changed

+115
-13
lines changed

src/main/java/nova/core/component/fluid/FluidHandler.java

+51-1
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,26 @@
2222

2323
import nova.core.component.Component;
2424
import nova.core.component.SidedComponent;
25+
import nova.core.retention.Data;
26+
import nova.core.retention.Storable;
27+
import nova.core.retention.Store;
2528

2629
import java.util.Arrays;
2730
import java.util.HashSet;
2831
import java.util.Optional;
2932
import java.util.Set;
3033
import java.util.function.Predicate;
34+
import java.util.stream.Collectors;
3135

3236
/**
3337
* A sided component that provides a fluid container.
3438
* @author Calclavia
3539
*/
3640
@SidedComponent
37-
public class FluidHandler extends Component implements FluidConsumer, FluidProvider {
41+
public class FluidHandler extends Component implements FluidIO, Storable {
3842

3943
protected Set<Tank> tanks = new HashSet<>();
44+
@Store
4045
protected boolean resizable;
4146

4247
public static FluidHandler singleTank() {
@@ -154,4 +159,49 @@ public Optional<Fluid> removeFluid(int amount, boolean simulate) {
154159

155160
return Optional.of(f).filter(fl -> fl.amount() > 0);
156161
}
162+
163+
@Override
164+
public void save(Data data) {
165+
Storable.super.save(data);
166+
data.put("tanks", tanks.stream()
167+
.filter(t -> t instanceof Storable)
168+
.collect(Collectors.toSet()));
169+
}
170+
171+
@Override
172+
public void load(Data data) {
173+
Storable.super.load(data);
174+
tanks.removeIf(t -> t instanceof Storable);
175+
tanks.addAll(data.getCollection("tanks"));
176+
}
177+
178+
@Override
179+
public int getFluidAmount() {
180+
return tanks.stream().mapToInt(FluidIO::getFluidAmount).sum();
181+
}
182+
183+
@Override
184+
public boolean isEmpty() {
185+
return tanks.isEmpty() || tanks.stream().allMatch(FluidIO::isEmpty);
186+
}
187+
188+
@Override
189+
public boolean hasFluid() {
190+
return !tanks.isEmpty() && tanks.stream().anyMatch(FluidIO::hasFluid);
191+
}
192+
193+
@Override
194+
public boolean hasFluidType(String fluidID) {
195+
return !tanks.isEmpty() && tanks.stream().anyMatch(t -> t.hasFluidType(fluidID));
196+
}
197+
198+
@Override
199+
public boolean hasFluidType(Fluid sample) {
200+
return !tanks.isEmpty() && tanks.stream().anyMatch(t -> t.hasFluidType(sample));
201+
}
202+
203+
@Override
204+
public boolean hasFluidType(FluidFactory sample) {
205+
return !tanks.isEmpty() && tanks.stream().anyMatch(t -> t.hasFluidType(sample));
206+
}
157207
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright (c) 2017 NOVA, All rights reserved.
3+
* This library is free software, licensed under GNU Lesser General Public License version 3
4+
*
5+
* This file is part of NOVA.
6+
*
7+
* NOVA is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* NOVA is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with NOVA. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
21+
package nova.core.component.fluid;
22+
23+
/**
24+
* @author ExE Boss
25+
*/
26+
public interface FluidIO extends FluidProvider, FluidConsumer {
27+
28+
int getFluidAmount();
29+
30+
/**
31+
* @return Whether this container is empty
32+
*/
33+
boolean isEmpty();
34+
35+
/**
36+
* @return Whether this container is storing a fluid (is not empty)
37+
*/
38+
boolean hasFluid();
39+
40+
boolean hasFluidType(String id);
41+
42+
boolean hasFluidType(Fluid fluid);
43+
44+
boolean hasFluidType(FluidFactory fluid);
45+
}

src/main/java/nova/core/component/fluid/Tank.java

+9-8
Original file line numberDiff line numberDiff line change
@@ -21,42 +21,41 @@
2121
package nova.core.component.fluid;
2222

2323
import java.util.Optional;
24+
import java.util.OptionalInt;
2425

2526
/**
2627
* Classes with this interface declare ability to store fluids
2728
* @see FluidConsumer
2829
* @see Tank
2930
*/
30-
public interface Tank extends FluidConsumer, FluidProvider {
31+
public interface Tank extends FluidIO {
3132

3233
/**
3334
* @return Maximum capacity of this container
3435
*/
35-
int getFluidCapacity();
36+
OptionalInt getFluidCapacity();
3637

3738
/**
3839
* @return Fluid stored in this container
3940
*/
4041
Optional<Fluid> getFluid();
4142

43+
@Override
4244
default int getFluidAmount() {
4345
return hasFluid() ? getFluid().get().amount() : 0;
4446
}
4547

46-
/**
47-
* @return Whether this container is empty
48-
*/
48+
@Override
4949
default boolean isEmpty() {
5050
return !getFluid().isPresent();
5151
}
5252

53-
/**
54-
* @return Whether this container is storing a fluid (is not empty)
55-
*/
53+
@Override
5654
default boolean hasFluid() {
5755
return getFluid().isPresent();
5856
}
5957

58+
@Override
6059
default boolean hasFluidType(String fluidID) {
6160
if (hasFluid()) {
6261
return getFluid().get().getID().equals(fluidID);
@@ -65,6 +64,7 @@ default boolean hasFluidType(String fluidID) {
6564
return false;
6665
}
6766

67+
@Override
6868
default boolean hasFluidType(Fluid sample) {
6969
if (hasFluid()) {
7070
return getFluid().get().sameType(sample);
@@ -73,6 +73,7 @@ default boolean hasFluidType(Fluid sample) {
7373
return false;
7474
}
7575

76+
@Override
7677
default boolean hasFluidType(FluidFactory sample) {
7778
if (hasFluid()) {
7879
return getFluid().get().sameType(sample);

src/main/java/nova/core/component/fluid/TankSimple.java

+10-4
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ public Optional<Fluid> removeFluid(int amount, boolean simulate) {
117117
}
118118

119119
@Override
120-
public int getFluidCapacity() {
121-
return capacity.orElse(Integer.MAX_VALUE);
120+
public OptionalInt getFluidCapacity() {
121+
return capacity;
122122
}
123123

124124
@Override
@@ -138,7 +138,9 @@ public TankSimple setFluid(Optional<Fluid> fluid) {
138138

139139
@Override
140140
public void save(Data data) {
141-
data.put("capacity", capacity);
141+
if (capacity.isPresent()) {
142+
data.put("capacity", capacity.getAsInt());
143+
}
142144

143145
if (containedFluid.isPresent()) {
144146
data.put("fluid", containedFluid.get());
@@ -147,7 +149,11 @@ public void save(Data data) {
147149

148150
@Override
149151
public void load(Data data) {
150-
setCapacity(data.get("capacity"));
152+
if (data.containsKey("capactiy")) {
153+
setCapacity(data.get("capacity"));
154+
} else {
155+
removeCapacity();
156+
}
151157

152158
if (data.containsKey("fluid")) {
153159
containedFluid = Optional.of(data.getStorable("fluid"));

0 commit comments

Comments
 (0)