Skip to content

Commit

Permalink
Use list of registries
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexProgrammerDE committed Apr 3, 2024
1 parent da369a7 commit 9d572fd
Show file tree
Hide file tree
Showing 14 changed files with 504 additions and 330 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.soulfiremc.generator.generators.ItemsJavaGenerator;
import com.soulfiremc.generator.generators.LanguageDataGenerator;
import com.soulfiremc.generator.generators.MapColorJavaGenerator;
import com.soulfiremc.generator.generators.RegistryKeysDataGenerator;
import com.soulfiremc.generator.generators.TagsDataGenerator;
import com.soulfiremc.generator.generators.WorldExporterGenerator;
import java.io.IOException;
Expand All @@ -48,6 +49,7 @@
public class DataGenerators {
private static final List<IDataGenerator> GENERATORS =
List.of(
new RegistryKeysDataGenerator(),
new BlockCollisionShapesDataGenerator.BlockShapesGenerator(),
new BlockCollisionShapesDataGenerator.BlockStatesGenerator(),
new BlocksDataGenerator(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* SoulFire
* Copyright (C) 2024 AlexProgrammerDE
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.soulfiremc.generator.generators;

import com.soulfiremc.generator.util.GeneratorConstants;
import com.soulfiremc.generator.util.ResourceHelper;
import java.util.Locale;
import lombok.extern.slf4j.Slf4j;
import net.minecraft.core.registries.BuiltInRegistries;

@Slf4j
public class RegistryKeysDataGenerator implements IDataGenerator {
@Override
public String getDataName() {
return "RegistryKeys.java";
}

@Override
public String generateDataJson() {
var base = ResourceHelper.getResource("/templates/RegistryKeys.java");
return base.replace(
GeneratorConstants.VALUES_REPLACE,
String.join(
"\n ",
BuiltInRegistries.REGISTRY.stream().map(
s ->
"public static final ResourceKey "
+ s.key().location().getPath().toUpperCase(Locale.ROOT).replace("/", "_WITH_")
+ " = ResourceKey.fromString(\""
+ s.key().location()
+ "\");")
.toArray(String[]::new)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.List;
import java.util.Locale;
import lombok.extern.slf4j.Slf4j;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.BlockTags;
import net.minecraft.tags.EntityTypeTags;
import net.minecraft.tags.ItemTags;
Expand All @@ -32,12 +33,12 @@
public class TagsDataGenerator {
private TagsDataGenerator() {}

public static List<String> generateTag(Class<?> tagClass) {
var resultArray = new ArrayList<String>();
public static List<ResourceLocation> generateTag(Class<?> tagClass) {
var resultArray = new ArrayList<ResourceLocation>();
for (var field : tagClass.getDeclaredFields()) {
try {
var tag = (TagKey<?>) field.get(null);
resultArray.add(tag.location().getPath());
resultArray.add(tag.location());
} catch (IllegalAccessException e) {
log.error("Failed to generate tag", e);
}
Expand All @@ -61,11 +62,11 @@ public String generateDataJson() {
generateTag(BlockTags.class).stream()
.map(
s ->
"public static final String "
+ s.toUpperCase(Locale.ROOT).replace("/", "_WITH_")
+ " = \"minecraft:"
"public static final ResourceKey "
+ s.getPath().toUpperCase(Locale.ROOT).replace("/", "_WITH_")
+ " = ResourceKey.fromString(\""
+ s
+ "\";")
+ "\");")
.toArray(String[]::new)));
}
}
Expand All @@ -86,11 +87,11 @@ public String generateDataJson() {
generateTag(ItemTags.class).stream()
.map(
s ->
"public static final String "
+ s.toUpperCase(Locale.ROOT).replace("/", "_WITH_")
+ " = \"minecraft:"
"public static final ResourceKey "
+ s.getPath().toUpperCase(Locale.ROOT).replace("/", "_WITH_")
+ " = ResourceKey.fromString(\""
+ s
+ "\";")
+ "\");")
.toArray(String[]::new)));
}
}
Expand All @@ -111,11 +112,11 @@ public String generateDataJson() {
generateTag(EntityTypeTags.class).stream()
.map(
s ->
"public static final String "
+ s.toUpperCase(Locale.ROOT).replace("/", "_WITH_")
+ " = \"minecraft:"
"public static final ResourceKey "
+ s.getPath().toUpperCase(Locale.ROOT).replace("/", "_WITH_")
+ " = ResourceKey.fromString(\""
+ s
+ "\";")
+ "\");")
.toArray(String[]::new)));
}
}
Expand Down
25 changes: 25 additions & 0 deletions data-generator/src/main/resources/templates/RegistryKeys.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* SoulFire
* Copyright (C) 2024 AlexProgrammerDE
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.soulfiremc.data;

@SuppressWarnings("unused")
public class RegistryKeys {
// VALUES REPLACE

private RegistryKeys() {}
}
Loading

0 comments on commit 9d572fd

Please sign in to comment.