-
-
Notifications
You must be signed in to change notification settings - Fork 332
Expand file tree
/
Copy pathChunkAccess.java.patch
More file actions
95 lines (91 loc) · 4.59 KB
/
Copy pathChunkAccess.java.patch
File metadata and controls
95 lines (91 loc) · 4.59 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
--- a/net/minecraft/world/level/chunk/ChunkAccess.java
+++ b/net/minecraft/world/level/chunk/ChunkAccess.java
@@ -318,10 +_,14 @@
@Override
public final void findBlockLightSources(BiConsumer<BlockPos, BlockState> consumer) {
- this.findBlocks(state -> state.getLightEmission() != 0, consumer);
+ this.findBlocks(p_284897_ -> p_284897_.hasDynamicLightEmission() || p_284897_.getLightEmission(net.minecraft.world.level.EmptyBlockGetter.INSTANCE, BlockPos.ZERO) != 0, (p_284897_, pos) -> p_284897_.getLightEmission(this, pos) != 0, consumer);
}
public void findBlocks(Predicate<BlockState> predicate, BiConsumer<BlockPos, BlockState> consumer) {
+ findBlocks(predicate, (state, pos) -> predicate.test(state), consumer);
+ }
+
+ public void findBlocks(Predicate<BlockState> predicate, java.util.function.BiPredicate<BlockState, BlockPos> fineFilter, BiConsumer<BlockPos, BlockState> consumer) {
BlockPos.MutableBlockPos mutablePos = new BlockPos.MutableBlockPos();
for (int sectionY = this.getMinSectionY(); sectionY <= this.getMaxSectionY(); sectionY++) {
@@ -333,8 +_,9 @@
for (int z = 0; z < 16; z++) {
for (int x = 0; x < 16; x++) {
BlockState state = section.getBlockState(x, y, z);
- if (predicate.test(state)) {
- consumer.accept(mutablePos.setWithOffset(origin, x, y, z), state);
+ mutablePos.setWithOffset(origin, x, y, z);
+ if (fineFilter.test(state, mutablePos)) {
+ consumer.accept(mutablePos, state);
}
}
}
@@ -476,6 +_,64 @@
public ChunkSkyLightSources getSkyLightSources() {
return this.skyLightSources;
}
+
+ // Neo: Hook in AttachmentHolder to chunks for data storage and retrieval
+ @org.jetbrains.annotations.ApiStatus.Internal
+ protected final net.neoforged.neoforge.attachment.AttachmentHolder attachments = new net.neoforged.neoforge.attachment.AttachmentHolder();
+
+ @org.jetbrains.annotations.ApiStatus.Internal
+ public net.neoforged.neoforge.attachment.storage.AttachmentDataStorage attachmentDataStorage() {
+ return attachments;
+ }
+
+ @Override
+ @Nullable
+ public <T> T setData(net.neoforged.neoforge.attachment.AttachmentType<T> type, T data) {
+ markUnsaved();
+ return attachments.setData(type, data);
+ }
+
+ @Override
+ @Nullable
+ public <T> T removeData(net.neoforged.neoforge.attachment.AttachmentType<T> type) {
+ markUnsaved();
+ return attachments.removeData(type);
+ }
+
+ /**
+ * <strong>FOR INTERNAL USE ONLY</strong>
+ * <p>
+ * Only public for use in {@link net.minecraft.world.level.chunk.storage.SerializableChunkData}.
+ */
+ @org.jetbrains.annotations.ApiStatus.Internal
+ @Nullable
+ public final CompoundTag writeAttachmentsToNBT(HolderLookup.Provider provider) {
+ ProblemReporter.Collector reporter = new ProblemReporter.Collector();
+ var tag = net.minecraft.world.level.storage.TagValueOutput.createWithContext(reporter, provider);
+ attachments.serializeAttachments(tag);
+ if (!reporter.isEmpty()) throw new IllegalArgumentException("Attachments failed to serialise: " + reporter.getReport());
+ return tag.isEmpty() ? null : tag.buildResult();
+ }
+
+ /**
+ * <strong>FOR INTERNAL USE ONLY</strong>
+ * <p>
+ * Only public for use in {@link net.minecraft.world.level.chunk.storage.SerializableChunkData}.
+ *
+ */
+ @org.jetbrains.annotations.ApiStatus.Internal
+ public final void readAttachmentsFromNBT(HolderLookup.Provider provider, CompoundTag tag) {
+ ProblemReporter.Collector reporter = new ProblemReporter.Collector();
+ var input = net.minecraft.world.level.storage.TagValueInput.create(reporter, provider, tag);
+ if(attachments.attachmentPersistenceHandler() instanceof net.neoforged.neoforge.attachment.persistence.AttachmentHolderPersistenceHandler persist)
+ persist.deserialize(input);
+ if (!reporter.isEmpty()) {
+ throw new IllegalArgumentException("Attachments failed to deserialise: " + reporter.getReport());
+ }
+ }
+
+ // Neo: Allow for exposing the Level a chunk is tied to if available
+ public net.minecraft.world.level.@Nullable Level getLevel() { return null; }
public static ProblemReporter.PathElement problemPath(ChunkPos pos) {
return new ChunkAccess.ChunkPathElement(pos);