-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathMapTemplateMetadata.java
More file actions
127 lines (112 loc) · 4.11 KB
/
Copy pathMapTemplateMetadata.java
File metadata and controls
127 lines (112 loc) · 4.11 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
package xyz.nucleoid.map_templates;
import net.minecraft.nbt.NbtCompound;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.stream.Stream;
/**
* Represents the non-world data of a MapTemplate that can be used to control additional game logic, but has no impact
* in what blocks or entities are placed in the world.
*
* This includes {@link TemplateRegion} and arbitrary {@link NbtCompound} attached data
*/
public final class MapTemplateMetadata {
final List<TemplateRegion> regions = new ArrayList<>();
NbtCompound data = new NbtCompound();
/**
* Adds a region with the given marker tag and bounds.
* Note that markers are not unique: multiple regions can be assigned the same marker!
*
* @param marker the marker tag to index this region by
* @param bounds the area over which this region exists
* @return the added region
*/
public TemplateRegion addRegion(String marker, BlockBounds bounds) {
return this.addRegion(marker, bounds, new NbtCompound());
}
/**
* Adds a region with the given marker tag, bounds, and {@link NbtCompound} attached data.
* Note that markers are not unique: multiple regions can be assigned the same marker!
*
* @param marker the marker tag to index this region by
* @param bounds the area over which this region exists
* @param nbt arbitrary attached data
* @return the added region
*/
public TemplateRegion addRegion(String marker, BlockBounds bounds, NbtCompound nbt) {
TemplateRegion region = new TemplateRegion(marker, bounds, nbt);
this.regions.add(region);
return region;
}
public void addRegion(TemplateRegion region) {
this.regions.add(region);
}
/**
* Queries all regions within this map that match the given marker.
*
* @param marker the marker to query for
* @return a stream of regions that match the query
*/
public Stream<TemplateRegion> getRegions(String marker) {
return this.regions.stream()
.filter(region -> region.getMarker().equals(marker));
}
/**
* Queries all region bounds within this map that match the given marker.
*
* @param marker the marker to query for
* @return a stream of region bounds that match the query
*/
public Stream<BlockBounds> getRegionBounds(String marker) {
return this.getRegions(marker)
.map(TemplateRegion::getBounds);
}
/**
* Queries a single region within this map that matches the given marker.
* This method gives no guarantees around which will be returned in the case of duplicates.
*
* @param marker the marker to query for
* @return the region that matches the query
*/
@Nullable
public TemplateRegion getFirstRegion(String marker) {
return this.getRegions(marker).findFirst().orElse(null);
}
/**
* Queries a single region within this map that matches the given marker.
* This method gives no guarantees around which will be returned in the case of duplicates.
*
* @param marker the marker to query for
* @return the region bounds that matches the query
*/
@Nullable
public BlockBounds getFirstRegionBounds(String marker) {
return this.getRegionBounds(marker).findFirst().orElse(null);
}
public Collection<TemplateRegion> getRegions() {
return this.regions;
}
/**
* Sets the arbitrary data of the map.
*
* @param data the data as an NBT compound
*/
public void setData(NbtCompound data) {
this.data = data;
}
/**
* Gets the arbitrary data of the map.
*
* @return the data as an NBT compound
*/
public NbtCompound getData() {
return this.data;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof MapTemplateMetadata)) return false;
return this.data.equals(((MapTemplateMetadata) o).data) && this.regions.equals(((MapTemplateMetadata) o).regions);
}
}