Skip to content

Commit 507c83d

Browse files
committed
Add javadocs to new API methods, and address some of the simpler TODOs in the API package
1 parent a8188bd commit 507c83d

File tree

64 files changed

+704
-484
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+704
-484
lines changed

src/api/java/mekanism/api/RelativeSide.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,23 @@ public enum RelativeSide implements IHasTranslationKey, StringRepresentable {
2323
TOP(APILang.TOP),
2424
BOTTOM(APILang.BOTTOM);
2525

26-
//TODO - 1.20.5: DOCS
26+
/**
27+
* Codec for serializing sides based on their name.
28+
*
29+
* @since 10.6.0
30+
*/
2731
public static final Codec<RelativeSide> CODEC = StringRepresentable.fromEnum(RelativeSide::values);
2832
/**
29-
* Gets a side by index.
33+
* Gets a side by index, wrapping for out of bounds indices.
3034
*
3135
* @since 10.6.0
3236
*/
3337
public static final IntFunction<RelativeSide> BY_ID = ByIdMap.continuous(RelativeSide::ordinal, values(), ByIdMap.OutOfBoundsStrategy.WRAP);
34-
//TODO - 1.20.5: DOCS
38+
/**
39+
* Stream codec for syncing sides by index.
40+
*
41+
* @since 10.6.0
42+
*/
3543
public static final StreamCodec<ByteBuf, RelativeSide> STREAM_CODEC = ByteBufCodecs.idMapper(BY_ID, RelativeSide::ordinal);
3644

3745
private final String serializedName;

src/api/java/mekanism/api/Upgrade.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,23 @@ public enum Upgrade implements IHasTranslationKey, StringRepresentable {
3232
ANCHOR("anchor", APILang.UPGRADE_ANCHOR, APILang.UPGRADE_ANCHOR_DESCRIPTION, 1, EnumColor.DARK_GREEN),
3333
STONE_GENERATOR("stone_generator", APILang.UPGRADE_STONE_GENERATOR, APILang.UPGRADE_STONE_GENERATOR_DESCRIPTION, 1, EnumColor.ORANGE);
3434

35-
//TODO - 1.20.5: DOCS
35+
/**
36+
* Codec for serializing upgrades based on their name.
37+
*
38+
* @since 10.6.0
39+
*/
3640
public static final Codec<Upgrade> CODEC = StringRepresentable.fromEnum(Upgrade::values);
3741
/**
38-
* Gets an upgrade by index.
42+
* Gets an upgrade by index, wrapping for out of bounds indices.
3943
*
4044
* @since 10.6.0
4145
*/
4246
public static final IntFunction<Upgrade> BY_ID = ByIdMap.continuous(Upgrade::ordinal, values(), ByIdMap.OutOfBoundsStrategy.WRAP);
43-
//TODO - 1.20.5: DOCS
47+
/**
48+
* Stream codec for syncing upgrades by index.
49+
*
50+
* @since 10.6.0
51+
*/
4452
public static final StreamCodec<ByteBuf, Upgrade> STREAM_CODEC = ByteBufCodecs.idMapper(BY_ID, Upgrade::ordinal);
4553

4654
private final String name;

src/api/java/mekanism/api/chemical/BasicChemicalTank.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ public CHEMICAL getType() {
232232
*/
233233
@Override
234234
public boolean isTypeEqual(STACK other) {
235-
return stored.isTypeEqual(other);
235+
return ChemicalStack.isSameChemical(stored, other);
236236
}
237237

238238
/**
@@ -276,16 +276,6 @@ public CompoundTag serializeNBT(HolderLookup.Provider provider) {
276276
return nbt;
277277
}
278278

279-
/**
280-
* {@inheritDoc}
281-
*
282-
* @implNote Overwritten so that if we decide to change to returning a cached/copy of our stack in {@link #getStack()}, we can optimize out the copying.
283-
*/
284-
@Override
285-
public boolean isCompatible(IChemicalTank<CHEMICAL, STACK> other) {
286-
return getClass() == other.getClass() && stored.equals(other.getStack());
287-
}
288-
289279
@Override
290280
public int getTanks() {
291281
return 1;

src/api/java/mekanism/api/chemical/ChemicalStack.java

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ protected static <CHEMICAL extends Chemical<CHEMICAL>> Codec<CHEMICAL> chemicalN
6262
*/
6363
protected static <CHEMICAL extends Chemical<CHEMICAL>, STACK extends ChemicalStack<CHEMICAL>> MapCodec<STACK> codec(Codec<CHEMICAL> nonEmptyCodec,
6464
BiFunction<CHEMICAL, Long, STACK> constructor) {
65-
//TODO - 1.20.%: Figure out if this needs to be lazily initialized. I don't think it does, but for fluids and items it is, probably because of components?
65+
//TODO - 1.20.5: Figure out if this needs to be lazily initialized. I don't think it does, but for fluids and items it is, probably because of components?
6666
return RecordCodecBuilder.mapCodec(instance -> instance.group(
6767
nonEmptyCodec.fieldOf(NBTConstants.ID).forGetter(ChemicalStack::getChemical),
6868
SerializerHelper.POSITIVE_LONG_CODEC.fieldOf(JsonConstants.AMOUNT).forGetter(ChemicalStack::getAmount)
@@ -78,7 +78,7 @@ protected static <CHEMICAL extends Chemical<CHEMICAL>, STACK extends ChemicalSta
7878
*/
7979
protected static <CHEMICAL extends Chemical<CHEMICAL>, STACK extends ChemicalStack<CHEMICAL>> Codec<STACK> fixedAmountCodec(
8080
Codec<CHEMICAL> chemicalNonEmptyCodec, BiFunction<CHEMICAL, Long, STACK> constructor, long amount) {
81-
//TODO - 1.20.%: Figure out if this needs to be lazily initialized. I don't think it does, but for fluids and items it is, probably because of components?
81+
//TODO - 1.20.5: Figure out if this needs to be lazily initialized. I don't think it does, but for fluids and items it is, probably because of components?
8282
return RecordCodecBuilder.create(instance -> instance.group(
8383
chemicalNonEmptyCodec.fieldOf(NBTConstants.ID).forGetter(ChemicalStack::getChemical)
8484
).apply(instance, holder -> constructor.apply(holder, amount)));
@@ -169,7 +169,7 @@ public void encode(RegistryFriendlyByteBuf buf, STACK stack) {
169169
* @see mekanism.api.chemical.merged.BoxedChemicalStack
170170
* @since 10.6.0
171171
*/
172-
//TODO - 1.20.5: Re-evaluate if we wan this defaulting to an empty gas stack or to try and get the same stack type as it was?
172+
//TODO - 1.20.5: Re-evaluate if we want this defaulting to an empty gas stack or to try and get the same stack type as it was?
173173
public static final Codec<ChemicalStack<?>> BOXED_OPTIONAL_CODEC = ExtraCodecs.optionalEmptyMap(BOXED_CODEC).xmap(optional -> optional.orElse(GasStack.EMPTY),
174174
stack -> stack.isEmpty() ? Optional.empty() : Optional.of(stack));
175175
/**
@@ -251,6 +251,8 @@ protected ChemicalStack(@Nullable Void unused) {
251251

252252
/**
253253
* Creates a copy of this stack with {@code 0} amount.
254+
*
255+
* @since 10.6.0
254256
*/
255257
public abstract ChemicalStack<CHEMICAL> copyAndClear();
256258

@@ -306,6 +308,8 @@ public boolean is(CHEMICAL chemical) {
306308
* @param predicate - Predicate to test
307309
*
308310
* @return if the ChemicalStack's type matches the given predicate
311+
*
312+
* @since 10.6.0
309313
*/
310314
public boolean is(Predicate<Holder<CHEMICAL>> predicate) {
311315
return predicate.test(getChemicalHolder());
@@ -317,6 +321,8 @@ public boolean is(Predicate<Holder<CHEMICAL>> predicate) {
317321
* @param holder - Chemical holder to check
318322
*
319323
* @return if the ChemicalStack's type is the same as the given holder's chemical
324+
*
325+
* @since 10.6.0
320326
*/
321327
public boolean is(Holder<CHEMICAL> holder) {
322328
return is(holder.value());
@@ -344,18 +350,6 @@ public Stream<TagKey<CHEMICAL>> getTags() {
344350
return getChemicalHolder().tags();
345351
}
346352

347-
/**
348-
* Whether this ChemicalStack's chemical type is equal to the other defined ChemicalStack.
349-
*
350-
* @param stack - ChemicalStack to check
351-
*
352-
* @return if the ChemicalStacks contain the same chemical type
353-
*/
354-
public boolean isTypeEqual(ChemicalStack<CHEMICAL> stack) {
355-
//TODO - 1.20.5: Should we replace this with the static method?
356-
return is(stack.getChemical());
357-
}
358-
359353
/**
360354
* Saves this stack to a tag, directly writing the keys into the passed tag.
361355
*
@@ -374,6 +368,8 @@ public boolean isTypeEqual(ChemicalStack<CHEMICAL> stack) {
374368

375369
/**
376370
* Saves this stack to a new tag. Empty stacks are supported and will be saved as an empty tag.
371+
*
372+
* @since 10.6.0
377373
*/
378374
public Tag saveOptional(HolderLookup.Provider lookupProvider) {
379375
return isEmpty() ? new CompoundTag() : save(lookupProvider);
@@ -548,6 +544,8 @@ public String getTranslationKey() {
548544
* Checks if the two chemical stacks have the same chemical type. Ignores amount.
549545
*
550546
* @return {@code true} if the two chemical stacks have the same chemical
547+
*
548+
* @since 10.6.0 Previously was isTypeEqual
551549
*/
552550
public static <CHEMICAL extends Chemical<CHEMICAL>> boolean isSameChemical(ChemicalStack<CHEMICAL> first, ChemicalStack<CHEMICAL> second) {
553551
return first.is(second.getChemical());

src/api/java/mekanism/api/chemical/ChemicalType.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,23 @@ public enum ChemicalType implements StringRepresentable {
5050
}
5151
}
5252

53-
//TODO - 1.20.5: Docs
53+
/**
54+
* Codec for serializing chemical types based on their name.
55+
*
56+
* @since 10.6.0
57+
*/
5458
public static final Codec<ChemicalType> CODEC = StringRepresentable.fromEnum(ChemicalType::values);
59+
/**
60+
* Gets a chemical type by index, wrapping for out of bounds indices.
61+
*
62+
* @since 10.6.0
63+
*/
5564
public static final IntFunction<ChemicalType> BY_ID = ByIdMap.continuous(ChemicalType::ordinal, values(), ByIdMap.OutOfBoundsStrategy.WRAP);
65+
/**
66+
* Stream codec for syncing chemical types by index.
67+
*
68+
* @since 10.6.0
69+
*/
5670
public static final StreamCodec<ByteBuf, ChemicalType> STREAM_CODEC = ByteBufCodecs.idMapper(BY_ID, ChemicalType::ordinal);
5771

5872
private final Predicate<Chemical<?>> instanceCheck;

src/api/java/mekanism/api/chemical/ChemicalUtils.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public static <CHEMICAL extends Chemical<CHEMICAL>, STACK extends ChemicalStack<
4545
STACK inTank = inTankGetter.getStored(tank, side);
4646
if (inTank.isEmpty()) {
4747
emptyTanks.add(tank);
48-
} else if (inTank.isTypeEqual(stack)) {
48+
} else if (ChemicalStack.isSameChemical(inTank, stack)) {
4949
STACK remainder = insertChemical.interact(tank, toInsert, side, action);
5050
if (remainder.isEmpty()) {
5151
//If we have no remaining chemical, return that we fit it all
@@ -131,7 +131,7 @@ public static <CHEMICAL extends Chemical<CHEMICAL>, STACK extends ChemicalStack<
131131
STACK extracted = empty;
132132
long toDrain = amount;
133133
for (int tank = 0; tank < tanks; tank++) {
134-
if (extracted.isEmpty() || extracted.isTypeEqual(inTankGetter.getStored(tank, side))) {
134+
if (extracted.isEmpty() || ChemicalStack.isSameChemical(extracted, inTankGetter.getStored(tank, side))) {
135135
//If there is chemical in the tank that matches the type we have started draining, or we haven't found a type yet
136136
STACK drained = extractChemical.interact(tank, toDrain, side, action);
137137
if (!drained.isEmpty()) {
@@ -211,15 +211,15 @@ public static <CHEMICAL extends Chemical<CHEMICAL>, STACK extends ChemicalStack<
211211
return empty;
212212
} else if (tanks == 1) {
213213
STACK inTank = inTankGetter.getStored(0, side);
214-
if (inTank.isEmpty() || !inTank.isTypeEqual(stack)) {
214+
if (inTank.isEmpty() || !ChemicalStack.isSameChemical(inTank, stack)) {
215215
return empty;
216216
}
217217
return extractChemical.interact(0, stack.getAmount(), side, action);
218218
}
219219
STACK extracted = empty;
220220
long toDrain = stack.getAmount();
221221
for (int tank = 0; tank < tanks; tank++) {
222-
if (stack.isTypeEqual(inTankGetter.getStored(tank, side))) {
222+
if (ChemicalStack.isSameChemical(stack, inTankGetter.getStored(tank, side))) {
223223
//If there is chemical in the tank that matches the type we are trying to drain, try to drain from it
224224
STACK drained = extractChemical.interact(tank, toDrain, side, action);
225225
if (!drained.isEmpty()) {

src/api/java/mekanism/api/chemical/IChemicalTank.java

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ default CHEMICAL getType() {
303303
* @implNote If your implementation of {@link #getStack()} returns a copy, this should be overridden to directly check against the internal stack.
304304
*/
305305
default boolean isTypeEqual(STACK other) {
306-
return getStack().isTypeEqual(other);
306+
return ChemicalStack.isSameChemical(getStack(), other);
307307
}
308308

309309
/**
@@ -336,17 +336,4 @@ default CompoundTag serializeNBT(HolderLookup.Provider provider) {
336336
}
337337
return nbt;
338338
}
339-
340-
/**
341-
* Checks if this chemical tank is equivalent to another one for the purposes of attachments.
342-
*
343-
* @param other Chemical tank to compare to.
344-
*
345-
* @return {@code true} If this chemical tank can be considered equivalent and compatible with the other tank.
346-
*
347-
* @since 10.5.0
348-
*/
349-
default boolean isCompatible(IChemicalTank<CHEMICAL, STACK> other) {
350-
return getClass() == other.getClass() && getStack().equals(other.getStack());
351-
}
352339
}

src/api/java/mekanism/api/chemical/merged/BoxedChemical.java

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import net.minecraft.network.codec.StreamCodec;
1919

2020
/**
21-
*
21+
* Helper class to keep track of chemicals and what specific type they are
2222
*/
2323
@NothingNullByDefault
2424
public class BoxedChemical implements IHasTextComponent {
@@ -27,10 +27,33 @@ public class BoxedChemical implements IHasTextComponent {
2727
* Empty Boxed Chemical instance.
2828
*/
2929
public static final BoxedChemical EMPTY = new BoxedChemical(ChemicalType.GAS, MekanismAPI.EMPTY_GAS);
30-
//TODO - 1.20.5: Docs
30+
/**
31+
* Codec to get any kind of chemical (that does not accept empty types) as a boxed chemical.
32+
*
33+
* @see Chemical#BOXED_CODEC
34+
* @since 10.6.0
35+
*/
3136
public static final Codec<BoxedChemical> CODEC = Chemical.BOXED_CODEC.xmap(BoxedChemical::box, BoxedChemical::getChemical);
37+
/**
38+
* Codec to get any kind of chemical as a boxed chemical.
39+
*
40+
* @see Chemical#BOXED_OPTIONAL_CODEC
41+
* @since 10.6.0
42+
*/
3243
public static final Codec<BoxedChemical> OPTIONAL_CODEC = Chemical.BOXED_OPTIONAL_CODEC.xmap(BoxedChemical::box, BoxedChemical::getChemical);
44+
/**
45+
* StreamCodec to get any kind of chemical (that does not accept the empty type) as a boxed chemical.
46+
*
47+
* @see Chemical#BOXED_STREAM_CODEC
48+
* @since 10.6.0
49+
*/
3350
public static final StreamCodec<RegistryFriendlyByteBuf, BoxedChemical> STREAM_CODEC = Chemical.BOXED_STREAM_CODEC.map(BoxedChemical::box, BoxedChemical::getChemical);
51+
/**
52+
* StreamCodec to get any kind of chemical as a boxed chemical.
53+
*
54+
* @see Chemical#BOXED_OPTIONAL_STREAM_CODEC
55+
* @since 10.6.0
56+
*/
3457
public static final StreamCodec<RegistryFriendlyByteBuf, BoxedChemical> OPTIONAL_STREAM_CODEC = Chemical.BOXED_OPTIONAL_STREAM_CODEC.map(BoxedChemical::box, BoxedChemical::getChemical);
3558

3659
/**
@@ -119,6 +142,8 @@ public Tag save(Provider lookupProvider) {
119142

120143
/**
121144
* Saves this boxed chemical to a new tag. Empty boxed chemical are supported and will be saved as an empty tag.
145+
*
146+
* @since 10.6.0
122147
*/
123148
public Tag saveOptional(HolderLookup.Provider lookupProvider) {
124149
return isEmpty() ? new CompoundTag() : save(lookupProvider);
@@ -140,8 +165,7 @@ public Component getTextComponent() {
140165
public boolean equals(Object o) {
141166
if (this == o) {
142167
return true;
143-
}
144-
if (o == null || getClass() != o.getClass()) {
168+
} else if (o == null || getClass() != o.getClass()) {
145169
return false;
146170
}
147171
BoxedChemical other = (BoxedChemical) o;

src/api/java/mekanism/api/chemical/merged/BoxedChemicalStack.java

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,43 @@
1818
import net.minecraft.network.codec.StreamCodec;
1919
import org.jetbrains.annotations.NotNull;
2020

21+
/**
22+
* Helper class to keep track of chemical stacks and what specific type they are
23+
*/
2124
public class BoxedChemicalStack implements IHasTextComponent {
2225

2326
/**
2427
* Empty Boxed Chemical Stack instance.
2528
*/
2629
public static final BoxedChemicalStack EMPTY = new BoxedChemicalStack(ChemicalType.GAS, GasStack.EMPTY);
2730

28-
//TODO - 1.20.5: Docs
29-
//TODO - 1.20.5: Do we want Codec variant of OPTIONAL_CODEC?
31+
/**
32+
* Codec to get any kind of chemical stack (that does not accept empty stacks) as a boxed chemical stack.
33+
*
34+
* @see ChemicalStack#BOXED_CODEC
35+
* @since 10.6.0
36+
*/
3037
public static final Codec<BoxedChemicalStack> CODEC = ChemicalStack.BOXED_CODEC.xmap(BoxedChemicalStack::box, BoxedChemicalStack::getChemicalStack);
38+
/**
39+
* Codec to get any kind of chemical stack as a boxed chemical stack.
40+
*
41+
* @see ChemicalStack#BOXED_OPTIONAL_CODEC
42+
* @since 10.6.0
43+
*/
44+
public static final Codec<BoxedChemicalStack> OPTIONAL_CODEC = ChemicalStack.BOXED_OPTIONAL_CODEC.xmap(BoxedChemicalStack::box, BoxedChemicalStack::getChemicalStack);
45+
/**
46+
* StreamCodec to get any kind of chemical stack (that does not accept empty stacks) as a boxed chemical stack.
47+
*
48+
* @see ChemicalStack#BOXED_STREAM_CODEC
49+
* @since 10.6.0
50+
*/
3151
public static final StreamCodec<RegistryFriendlyByteBuf, BoxedChemicalStack> STREAM_CODEC = ChemicalStack.BOXED_STREAM_CODEC.map(BoxedChemicalStack::box, BoxedChemicalStack::getChemicalStack);
52+
/**
53+
* StreamCodec to get any kind of chemical stack as a boxed chemical stack.
54+
*
55+
* @see ChemicalStack#BOXED_OPTIONAL_STREAM_CODEC
56+
* @since 10.6.0
57+
*/
3258
public static final StreamCodec<RegistryFriendlyByteBuf, BoxedChemicalStack> OPTIONAL_STREAM_CODEC = ChemicalStack.BOXED_OPTIONAL_STREAM_CODEC.map(BoxedChemicalStack::box, BoxedChemicalStack::getChemicalStack);
3359

3460
/**
@@ -127,6 +153,8 @@ public Tag save(Provider lookupProvider) {
127153

128154
/**
129155
* Saves this stack to a new tag. Empty stacks are supported and will be saved as an empty tag.
156+
*
157+
* @since 10.6.0
130158
*/
131159
public Tag saveOptional(HolderLookup.Provider lookupProvider) {
132160
return isEmpty() ? new CompoundTag() : save(lookupProvider);
@@ -156,8 +184,7 @@ public BoxedChemicalStack copy() {
156184
public boolean equals(Object o) {
157185
if (this == o) {
158186
return true;
159-
}
160-
if (o == null || getClass() != o.getClass()) {
187+
} else if (o == null || getClass() != o.getClass()) {
161188
return false;
162189
}
163190
BoxedChemicalStack other = (BoxedChemicalStack) o;

0 commit comments

Comments
 (0)