Skip to content

Commit

Permalink
Use a record for the data file
Browse files Browse the repository at this point in the history
  • Loading branch information
me4502 committed Apr 2, 2024
1 parent 825d5de commit 4d00e54
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 25 deletions.
Expand Up @@ -30,7 +30,7 @@ public class CLIBlockCategoryRegistry implements BlockCategoryRegistry {

@Override
public Set<BlockType> getCategorisedByName(String category) {
return CLIWorldEdit.inst.getFileRegistries().getDataFile().blocktags.getOrDefault(category, Collections.emptyList()).stream()
return CLIWorldEdit.inst.getFileRegistries().getDataFile().blocktags().getOrDefault(category, Collections.emptyList()).stream()
.map(BlockType.REGISTRY::get)
.collect(Collectors.toSet());
}
Expand Down
Expand Up @@ -52,9 +52,9 @@ private Property<?> createProperty(String type, String key, List<String> values)
@Override
public Map<String, ? extends Property<?>> getProperties(BlockType blockType) {
Map<String, DataFile.BlockProperty> properties =
CLIWorldEdit.inst.getFileRegistries().getDataFile().blocks.get(blockType.id()).properties;
CLIWorldEdit.inst.getFileRegistries().getDataFile().blocks().get(blockType.id()).properties();
Maps.EntryTransformer<String, DataFile.BlockProperty, Property<?>> entryTransform =
(key, value) -> createProperty(value.type, key, value.values);
(key, value) -> createProperty(value.type(), key, value.values());
return ImmutableMap.copyOf(Maps.transformEntries(properties, entryTransform));
}
}
Expand Up @@ -29,7 +29,7 @@ public class CLIItemCategoryRegistry implements ItemCategoryRegistry {

@Override
public Set<ItemType> getCategorisedByName(String category) {
return CLIWorldEdit.inst.getFileRegistries().getDataFile().itemtags.get(category).stream()
return CLIWorldEdit.inst.getFileRegistries().getDataFile().itemtags().get(category).stream()
.map(ItemType.REGISTRY::get)
.collect(Collectors.toSet());
}
Expand Down
Expand Up @@ -120,7 +120,7 @@ public void setupRegistries() {

// Blocks
BlockType.REGISTRY.clear();
for (Map.Entry<String, DataFile.BlockManifest> manifestEntry : fileRegistries.getDataFile().blocks.entrySet()) {
for (Map.Entry<String, DataFile.BlockManifest> manifestEntry : fileRegistries.getDataFile().blocks().entrySet()) {
if (BlockType.REGISTRY.get(manifestEntry.getKey()) == null) {
BlockType.REGISTRY.register(manifestEntry.getKey(), new BlockType(manifestEntry.getKey(), input -> {
ParserContext context = new ParserContext();
Expand All @@ -129,7 +129,7 @@ public void setupRegistries() {
context.setRestricted(false);
try {
FuzzyBlockState state = (FuzzyBlockState) WorldEdit.getInstance().getBlockFactory().parseFromInput(
manifestEntry.getValue().defaultstate,
manifestEntry.getValue().defaultstate(),
context
).toImmutableState();
BlockState defaultState = input.getBlockType().getAllStates().get(0);
Expand All @@ -148,34 +148,34 @@ public void setupRegistries() {
}
// Items
ItemType.REGISTRY.clear();
for (String name : fileRegistries.getDataFile().items) {
for (String name : fileRegistries.getDataFile().items()) {
if (ItemType.REGISTRY.get(name) == null) {
ItemType.REGISTRY.register(name, new ItemType(name));
}
}
// Entities
EntityType.REGISTRY.clear();
for (String name : fileRegistries.getDataFile().entities) {
for (String name : fileRegistries.getDataFile().entities()) {
if (EntityType.REGISTRY.get(name) == null) {
EntityType.REGISTRY.register(name, new EntityType(name));
}
}
// Biomes
BiomeType.REGISTRY.clear();
for (String name : fileRegistries.getDataFile().biomes) {
for (String name : fileRegistries.getDataFile().biomes()) {
if (BiomeType.REGISTRY.get(name) == null) {
BiomeType.REGISTRY.register(name, new BiomeType(name));
}
}
// Tags
BlockCategory.REGISTRY.clear();
for (String name : fileRegistries.getDataFile().blocktags.keySet()) {
for (String name : fileRegistries.getDataFile().blocktags().keySet()) {
if (BlockCategory.REGISTRY.get(name) == null) {
BlockCategory.REGISTRY.register(name, new BlockCategory(name));
}
}
ItemCategory.REGISTRY.clear();
for (String name : fileRegistries.getDataFile().itemtags.keySet()) {
for (String name : fileRegistries.getDataFile().itemtags().keySet()) {
if (ItemCategory.REGISTRY.get(name) == null) {
ItemCategory.REGISTRY.register(name, new ItemCategory(name));
}
Expand Down
Expand Up @@ -22,22 +22,17 @@
import java.util.List;
import java.util.Map;

public class DataFile {
public Map<String, List<String>> itemtags;
public Map<String, List<String>> blocktags;
public Map<String, List<String>> entitytags;
public List<String> items;
public List<String> entities;
public List<String> biomes;
public Map<String, BlockManifest> blocks;
public record DataFile(Map<String, List<String>> itemtags,
Map<String, List<String>> blocktags,
Map<String, List<String>> entitytags,
List<String> items,
List<String> entities,
List<String> biomes,
Map<String, BlockManifest> blocks) {

public static class BlockManifest {
public String defaultstate;
public Map<String, BlockProperty> properties;
public record BlockManifest(String defaultstate, Map<String, BlockProperty> properties) {
}

public static class BlockProperty {
public List<String> values;
public String type;
public record BlockProperty(List<String> values, String type) {
}
}

0 comments on commit 4d00e54

Please sign in to comment.