Skip to content

Commit 342e6b1

Browse files
AI: fix comments
1 parent 524dc0b commit 342e6b1

File tree

1 file changed

+40
-34
lines changed

1 file changed

+40
-34
lines changed

src/main/java/com/tcm/MineTale/block/entity/ChickenCoopEntity.java

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,10 @@ private void spawnFeatherParticles(ServerLevel level, BlockPos pos, int count) {
109109
@Override
110110
protected void saveAdditional(ValueOutput valueOutput) {
111111
super.saveAdditional(valueOutput);
112-
113-
// Save the simple primitives
114112
valueOutput.putInt("EggCount", this.eggCount);
113+
valueOutput.putInt("EggsLaidThisNight", this.eggsLaidThisNight); // Added
115114
valueOutput.putBoolean("IsNightMode", this.isNightMode);
116115

117-
// Save the list of chickens using your TypedOutputList logic
118-
// We use the CompoundTag.CODEC to store the raw NBT of each chicken
119116
ValueOutput.TypedOutputList<CompoundTag> chickenList = valueOutput.list("StoredChickens", CompoundTag.CODEC);
120117
for (CompoundTag chickenNbt : storedChickensNbt) {
121118
chickenList.add(chickenNbt);
@@ -125,16 +122,13 @@ protected void saveAdditional(ValueOutput valueOutput) {
125122
@Override
126123
protected void loadAdditional(ValueInput valueInput) {
127124
super.loadAdditional(valueInput);
128-
129125
this.eggCount = valueInput.getIntOr("EggCount", 0);
126+
this.eggsLaidThisNight = valueInput.getIntOr("EggsLaidThisNight", 0); // Added
130127
this.isNightMode = valueInput.getBooleanOr("IsNightMode", false);
131128

132-
// Clear current chickens
133129
this.storedChickensNbt.clear();
134-
135-
// Use map to transform the Optional<TypedInputList> into a Stream of NBT
136130
valueInput.list("StoredChickens", CompoundTag.CODEC)
137-
.map(ValueInput.TypedInputList::stream)
131+
.map(ValueInput.TypedInputList::stream)
138132
.ifPresent(stream -> stream.forEach(this.storedChickensNbt::add));
139133
}
140134

@@ -406,46 +400,58 @@ public ValueInput childOrEmpty(String key) {
406400

407401
@Override public HolderLookup.Provider lookup() { return registries; }
408402

403+
// Ensure the helper record implements stream()
404+
private record ChickenTypedInputList<T>(List<T> items) implements TypedInputList<T> {
405+
@Override public boolean isEmpty() { return items.isEmpty(); }
406+
@Override public Stream<T> stream() { return items.stream(); }
407+
@Override public java.util.Iterator<T> iterator() { return items.iterator(); }
408+
}
409+
409410
@Override
410411
public <T> Optional<TypedInputList<T>> list(String key, Codec<T> codec) {
411-
// Check if the key exists and is a List
412412
if (!tag.contains(key)) return Optional.empty();
413-
414-
// In modern mappings, getList only takes the Key.
415-
// It returns the list if found, or an empty one if not.
416-
Optional<ListTag> listTag = tag.getList(key);
417413

418-
// Map the NBT tags to objects using the codec
414+
Optional<ListTag> listTag = tag.getList(key);
419415
List<T> items = listTag.stream()
420416
.map(nbt -> codec.parse(registries.createSerializationContext(NbtOps.INSTANCE), nbt)
421417
.resultOrPartial(System.err::println))
422-
.flatMap(Optional::stream) // Flattens Optional<T> into the stream
418+
.flatMap(Optional::stream)
423419
.toList();
424420

425421
return Optional.of(new ChickenTypedInputList<>(items));
426422
}
427423

428-
// Ensure the helper record implements stream()
429-
private record ChickenTypedInputList<T>(List<T> items) implements TypedInputList<T> {
430-
@Override public boolean isEmpty() { return items.isEmpty(); }
431-
@Override public Stream<T> stream() { return items.stream(); }
432-
@Override public java.util.Iterator<T> iterator() { return items.iterator(); }
424+
@Override
425+
public <T> TypedInputList<T> listOrEmpty(String key, Codec<T> codec) {
426+
return list(key, codec).orElse(new ChickenTypedInputList<>(List.of()));
433427
}
434-
@Override public <T> TypedInputList<T> listOrEmpty(String key, Codec<T> codec) {
435-
return new TypedInputList<T>() {
436-
@Override public boolean isEmpty() { return true; }
437-
@Override public Stream<T> stream() { return Stream.empty(); }
438-
@Override public java.util.Iterator<T> iterator() { return Stream.<T>empty().iterator(); }
439-
};
428+
429+
@Override
430+
public Optional<ValueInputList> childrenList(String key) {
431+
// Check if the tag exists and is a List
432+
if (!(tag.get(key) instanceof ListTag listTag)) {
433+
return Optional.empty();
434+
}
435+
436+
// Map each element inside the ListTag (which should be CompoundTags) to ValueInputs
437+
List<ValueInput> children = listTag.stream()
438+
.filter(t -> t instanceof CompoundTag) // Ensure the entry is a CompoundTag
439+
.map(t -> (ValueInput) new ChickenValueInput((CompoundTag) t, registries))
440+
.toList();
441+
442+
return Optional.of(new ChickenValueInputListImpl(children));
443+
}
444+
445+
@Override
446+
public ValueInputList childrenListOrEmpty(String key) {
447+
return childrenList(key).orElse(new ChickenValueInputListImpl(List.of()));
440448
}
441449

442-
@Override public Optional<ValueInputList> childrenList(String string) { return Optional.empty(); }
443-
@Override public ValueInputList childrenListOrEmpty(String string) {
444-
return new ValueInputList() {
445-
@Override public boolean isEmpty() { return true; }
446-
@Override public Stream<ValueInput> stream() { return Stream.empty(); }
447-
@Override public java.util.Iterator<ValueInput> iterator() { return Stream.<ValueInput>empty().iterator(); }
448-
};
450+
// Support record for ValueInputList
451+
private record ChickenValueInputListImpl(List<ValueInput> children) implements ValueInputList {
452+
@Override public boolean isEmpty() { return children.isEmpty(); }
453+
@Override public Stream<ValueInput> stream() { return children.stream(); }
454+
@Override public java.util.Iterator<ValueInput> iterator() { return children.iterator(); }
449455
}
450456
}
451457
}

0 commit comments

Comments
 (0)